@openchamber/web 1.18.3 → 1.18.4

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 (60) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-4qZbrEXU.js} +1 -1
  2. package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-MJmntVPJ.js} +1 -1
  3. package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-jnG3Hbxg.js} +1 -1
  4. package/dist/assets/{DiagramView-CndEcZNu.js → DiagramView-CFXxgg_a.js} +1 -1
  5. package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-DZIoOnV7.js} +1 -1
  6. package/dist/assets/{FilesView-CzUgIvUm.js → FilesView-BKL6YlKG.js} +1 -1
  7. package/dist/assets/{GitView-C-n17voy.js → GitView-DBFrDDBv.js} +1 -1
  8. package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-DLW2Wy1g.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +12 -0
  11. package/dist/assets/{OnboardingScreen-BmN0lhk4.js → OnboardingScreen-D2Y6djMw.js} +1 -1
  12. package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-BuLPx7AN.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-BHm4Yr0X.js} +1 -1
  14. package/dist/assets/{PlanView-CWM0iyFk.js → PlanView-ZYEJn8A_.js} +1 -1
  15. package/dist/assets/{SessionSwitcherDropdown-Cez-9xRh.js → SessionSwitcherDropdown-rro-SsaO.js} +1 -1
  16. package/dist/assets/{SettingsView-Bl1drwPw.js → SettingsView-5RmswFZe.js} +1 -1
  17. package/dist/assets/{SettingsWindow-DL5axjDZ.js → SettingsWindow-BZhAYFdS.js} +1 -1
  18. package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-Za6V4VMJ.js} +1 -1
  19. package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-BL-9ixyC.js} +1 -1
  20. package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-CwGocYQd.js} +1 -1
  21. package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-5DyvN03T.js} +1 -1
  22. package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-Da00Jg7M.js} +1 -1
  23. package/dist/assets/{contextPanelEmbeddedChat-tQekJUAF.js → contextPanelEmbeddedChat-B-bSg3P5.js} +1 -1
  24. package/dist/assets/index-BzIpNlNE.css +1 -0
  25. package/dist/assets/{index-Crz1YOFl.js → index-C0yNhuZw.js} +1 -1
  26. package/dist/assets/{index-iFY_N5aO.js → index-DRpChWux.js} +1 -1
  27. package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-D9YpoLrV.js} +1 -1
  28. package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-gTibdNIe.js} +1 -1
  29. package/dist/assets/{main-C0DyIwTb.js → main-D7UcL3VQ.js} +2 -2
  30. package/dist/assets/{main-CAxX6DAN.js → main-DPMd2iKS.js} +4 -4
  31. package/dist/assets/markdownCore-DDrHVneM.js +2 -0
  32. package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-O_GVoEbc.js} +2 -2
  33. package/dist/assets/{mobile-DEmhwNcV.js → mobile-Br4TtAqc.js} +2 -2
  34. package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-KNkxM1C1.js} +1 -1
  35. package/dist/assets/{renderElectronMiniChatApp-Dpbswpom.js → renderElectronMiniChatApp-CJpdxTT1.js} +2 -2
  36. package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-toj9cXoh.js} +4 -4
  37. package/dist/assets/{runtimeEndpointReset-cbahJ3hD.js → runtimeEndpointReset-BVmispdD.js} +2 -2
  38. package/dist/assets/{scheduledTasksApi-BxgGWTL8.js → scheduledTasksApi-ByKya3Un.js} +1 -1
  39. package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-C7LTbwFx.js} +1 -1
  40. package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-BikB6enL.js} +131 -131
  41. package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CYPvYJDt.js} +1 -1
  42. package/dist/assets/{vendor-codemirror-language-data-Dihw9MtL.js → vendor-codemirror-language-data-CLHw8NWn.js} +2 -2
  43. package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-GMc3oR3i.js} +1 -1
  44. package/dist/index.html +4 -4
  45. package/dist/mini-chat.html +3 -3
  46. package/dist/mobile.html +3 -3
  47. package/package.json +1 -1
  48. package/server/lib/dev-tunnel/client.js +20 -1
  49. package/server/lib/dev-tunnel/tunnel.test.js +9 -0
  50. package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
  51. package/server/lib/markdown-image-grants/routes.js +340 -0
  52. package/server/lib/markdown-image-grants/routes.test.js +221 -0
  53. package/server/lib/opencode/feature-routes-runtime.js +11 -0
  54. package/server/lib/opencode/server-startup-runtime.js +22 -1
  55. package/server/lib/opencode/server-startup-runtime.test.js +44 -0
  56. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
  57. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
  58. package/dist/assets/index-CVNuER6G.css +0 -1
  59. package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
  60. package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
@@ -1,4 +1,4 @@
1
- import{R as l,r as Te,j as t,f as jt}from"./vendor-react-BUCujlKS.js";import{f as et,y as Ze,h4 as In,cR as Ht,c5 as Wt,t as b,I as D,aU as Vs,aR as Is,cP as wr,aT as Ps,cl as Fs,cm as Rs,cn as Ms,co as Bs,ch as Ut,ci as Kt,B as W,h5 as Pn,h6 as Fn,bs as ut,bt as mt,bu as ht,bv as gt,bw as wt,S as nr,aX as Jt,aY as qt,aZ as Yt,h7 as Rn,h as Re,h8 as Mn,h9 as Bn,ha as Tn,hb as Dn,aQ as En,aa as Ln,bH as An,hc as On,hd as zn,he as Gn,hf as _n,hg as $n,hh as Hn,hi as Wn,bU as yr,bK as Un,bL as Kn,bM as Jn,bN as qn,bO as Yn,hj as Qn,bR as Xn,bx as ks,ew as Zn,V as ea,a0 as ta,a2 as sa,a1 as ra,bk as na,hk as aa,bS as ia,hl as oa,hm as la,a3 as ca,hn as da,a4 as ua,bF as ma,ho as ha,l as ga,bT as fa,g as pa,cq as xa,a9 as wa,Z as ya,hp as ba,hq as Cs}from"./useAppFontEffects-sHmU5b8u.js";import{u as va,a as ja,d as Ca}from"./main-CAxX6DAN.js";import{s as Na,v as Sa,q as ka,J as Va,X as Ia}from"./runtimeEndpointReset-cbahJ3hD.js";import{u as ar}from"./vendor-zustand-BAGL70zf.js";import{r as Pa,u as xt}from"./index-iFY_N5aO.js";import{C as Fa,a as Ra}from"./CommitSection-Jc2_hNPE.js";import{P as Ma}from"./PierreDiffViewer-D1fWvrUn.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-tQekJUAF.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dihw9MtL.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionSwitcherDropdown-Cez-9xRh.js";import"./scheduledTasksApi-BxgGWTL8.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-BL-Ur2Tb.js";import"./computeVirtualFileMetrics-xPena3W2.js";import"./vendor-shiki-Bbf2GEcE.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";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-DkcusvMa.js";import"./isDiffPlainText-Dudf-dWx.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-gt56WkxJ.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const br="gitmojiCache",Ba=1e3*60*60*24*7,vr="1",Ta="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",jr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ns=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(br);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==vr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(jr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Da=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:vr};window.localStorage.setItem(br,JSON.stringify(e))}catch{return}},ir=i=>Date.now()-i.fetchedAt<Ba;let _t=null;const It=new Set,or=async()=>{if(_t)return _t;const i=(async()=>{try{const e=await fetch(Ta);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(jr):[];return Da(r),It.forEach(v=>v(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return It.forEach(r=>r(n)),n}finally{_t=null}})();return _t=i,i},Ea=i=>{const[e,n]=l.useState(()=>i?Ns()?.gitmojis??[]:[]),[r,v]=l.useState(!1),f=l.useRef(i);f.current=i,l.useEffect(()=>{if(!i){It.delete(n),n([]),v(!1);return}const p=Ns();if(p&&(n(p.gitmojis),ir(p)))return;It.add(n),v(!0);let m=!1;return or().finally(()=>{!m&&f.current&&v(!1)}),()=>{m=!0,It.delete(n)}},[i]);const x=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const p=Ns();return p&&ir(p)?p.gitmojis:or()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:x}},Ct=async(i,e)=>{const n=await Pa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Vt(i){return Ct("plan",i)}async function La(i){return Ct("conflict-details",{tempWorktreePath:i})}async function Aa(i){return(await Ct("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function Oa(i){return Ct("run",{plan:i})}async function za(i){await Ct("abort",{state:i})}async function Ga(i){return Ct("continue",{state:i})}const _a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:v,refreshKey:f,onRefresh:x,showHeader:p=!0})=>{const{t:m}=et(),w=Ze(h=>h.currentSessionId),B=xt(h=>h.setActiveMainTab),[y,C]=Te.useState(!1),k=Te.useRef(null),[V,A]=Te.useState(v);Te.useEffect(()=>{A(v)},[v]),Te.useEffect(()=>{if(y){const h=setTimeout(()=>{k.current?.focus()},0);return()=>clearTimeout(h)}},[y]);const I=!!(i&&e&&V&&V!=="HEAD"&&e!==V),[d,E]=Te.useState({kind:"idle"}),[R,O]=Te.useState(!1),[N,P]=Te.useState([]),g=Te.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);Te.useEffect(()=>{if(!g||typeof window>"u")return;const h=window.localStorage.getItem(g);if(!h)return;let L=!1;try{const T=JSON.parse(h);if(!T?.tempWorktreePath||T.repoRoot!==i){window.localStorage.removeItem(g);return}(async()=>{const u=await Aa(T.tempWorktreePath).catch(()=>!1);if(L)return;if(!u){window.localStorage.removeItem(g);return}const M=await La(T.tempWorktreePath).catch(()=>null);L||M&&E({kind:"conflict",state:T,details:M})})()}catch{window.localStorage.removeItem(g)}return()=>{L=!0}},[g,i]),Te.useEffect(()=>{if(!I){E({kind:"idle"});return}let h=!1;return E({kind:"loading"}),(async()=>{try{const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V});if(h)return;if(E({kind:"ready",plan:L}),L.commits.length>0){const u=L.commits.slice(-50).reverse(),M=await In(i,u);h||(P(M),O(!1))}else h||(P([]),O(!1))}catch{h||E({kind:"idle"})}})(),()=>{h=!0}},[I,i,e,V,f]);const U=Te.useCallback(h=>{w&&Ze.getState().setWorktreeMetadata(w,{...n,createdFromBranch:h})},[w,n]),Y=Ze(h=>h.openNewSessionDraft),S=Te.useCallback(async h=>{const L=await Ht("git.integrate.cherrypick.resolve.visible",{current_commit:h.state.currentCommit,target_branch:h.state.targetBranch}),T=await Ht("git.integrate.cherrypick.resolve.instructions",{repo_root:h.state.repoRoot,temp_worktree_path:h.state.tempWorktreePath,source_branch:h.state.sourceBranch,target_branch:h.state.targetBranch,current_commit:h.state.currentCommit}),u=`Cherry-pick conflict context (JSON)
1
+ import{R as l,r as Te,j as t,f as jt}from"./vendor-react-BUCujlKS.js";import{f as et,y as Ze,h4 as In,cR as Ht,c5 as Wt,t as b,I as D,aU as Vs,aR as Is,cP as wr,aT as Ps,cl as Fs,cm as Rs,cn as Ms,co as Bs,ch as Ut,ci as Kt,B as W,h5 as Pn,h6 as Fn,bs as ut,bt as mt,bu as ht,bv as gt,bw as wt,S as nr,aX as Jt,aY as qt,aZ as Yt,h7 as Rn,h as Re,h8 as Mn,h9 as Bn,ha as Tn,hb as Dn,aQ as En,aa as Ln,bH as An,hc as On,hd as zn,he as Gn,hf as _n,hg as $n,hh as Hn,hi as Wn,bU as yr,bK as Un,bL as Kn,bM as Jn,bN as qn,bO as Yn,hj as Qn,bR as Xn,bx as ks,ew as Zn,V as ea,a0 as ta,a2 as sa,a1 as ra,bk as na,hk as aa,bS as ia,hl as oa,hm as la,a3 as ca,hn as da,a4 as ua,bF as ma,ho as ha,l as ga,bT as fa,g as pa,cq as xa,a9 as wa,Z as ya,hp as ba,hq as Cs}from"./useAppFontEffects-BikB6enL.js";import{u as va,a as ja,d as Ca}from"./main-DPMd2iKS.js";import{s as Na,v as Sa,q as ka,J as Va,X as Ia}from"./runtimeEndpointReset-BVmispdD.js";import{u as ar}from"./vendor-zustand-BAGL70zf.js";import{r as Pa,u as xt}from"./index-DRpChWux.js";import{C as Fa,a as Ra}from"./CommitSection-MJmntVPJ.js";import{P as Ma}from"./PierreDiffViewer-BHm4Yr0X.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./SessionSwitcherDropdown-rro-SsaO.js";import"./scheduledTasksApi-ByKya3Un.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-GMc3oR3i.js";import"./computeVirtualFileMetrics-Da00Jg7M.js";import"./vendor-shiki-Bbf2GEcE.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";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-CwGocYQd.js";import"./isDiffPlainText-D9YpoLrV.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-CYPvYJDt.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const br="gitmojiCache",Ba=1e3*60*60*24*7,vr="1",Ta="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",jr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ns=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(br);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==vr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(jr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Da=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:vr};window.localStorage.setItem(br,JSON.stringify(e))}catch{return}},ir=i=>Date.now()-i.fetchedAt<Ba;let _t=null;const It=new Set,or=async()=>{if(_t)return _t;const i=(async()=>{try{const e=await fetch(Ta);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(jr):[];return Da(r),It.forEach(v=>v(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return It.forEach(r=>r(n)),n}finally{_t=null}})();return _t=i,i},Ea=i=>{const[e,n]=l.useState(()=>i?Ns()?.gitmojis??[]:[]),[r,v]=l.useState(!1),f=l.useRef(i);f.current=i,l.useEffect(()=>{if(!i){It.delete(n),n([]),v(!1);return}const p=Ns();if(p&&(n(p.gitmojis),ir(p)))return;It.add(n),v(!0);let m=!1;return or().finally(()=>{!m&&f.current&&v(!1)}),()=>{m=!0,It.delete(n)}},[i]);const x=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const p=Ns();return p&&ir(p)?p.gitmojis:or()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:x}},Ct=async(i,e)=>{const n=await Pa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Vt(i){return Ct("plan",i)}async function La(i){return Ct("conflict-details",{tempWorktreePath:i})}async function Aa(i){return(await Ct("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function Oa(i){return Ct("run",{plan:i})}async function za(i){await Ct("abort",{state:i})}async function Ga(i){return Ct("continue",{state:i})}const _a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:v,refreshKey:f,onRefresh:x,showHeader:p=!0})=>{const{t:m}=et(),w=Ze(h=>h.currentSessionId),B=xt(h=>h.setActiveMainTab),[y,C]=Te.useState(!1),k=Te.useRef(null),[V,A]=Te.useState(v);Te.useEffect(()=>{A(v)},[v]),Te.useEffect(()=>{if(y){const h=setTimeout(()=>{k.current?.focus()},0);return()=>clearTimeout(h)}},[y]);const I=!!(i&&e&&V&&V!=="HEAD"&&e!==V),[d,E]=Te.useState({kind:"idle"}),[R,O]=Te.useState(!1),[N,P]=Te.useState([]),g=Te.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);Te.useEffect(()=>{if(!g||typeof window>"u")return;const h=window.localStorage.getItem(g);if(!h)return;let L=!1;try{const T=JSON.parse(h);if(!T?.tempWorktreePath||T.repoRoot!==i){window.localStorage.removeItem(g);return}(async()=>{const u=await Aa(T.tempWorktreePath).catch(()=>!1);if(L)return;if(!u){window.localStorage.removeItem(g);return}const M=await La(T.tempWorktreePath).catch(()=>null);L||M&&E({kind:"conflict",state:T,details:M})})()}catch{window.localStorage.removeItem(g)}return()=>{L=!0}},[g,i]),Te.useEffect(()=>{if(!I){E({kind:"idle"});return}let h=!1;return E({kind:"loading"}),(async()=>{try{const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V});if(h)return;if(E({kind:"ready",plan:L}),L.commits.length>0){const u=L.commits.slice(-50).reverse(),M=await In(i,u);h||(P(M),O(!1))}else h||(P([]),O(!1))}catch{h||E({kind:"idle"})}})(),()=>{h=!0}},[I,i,e,V,f]);const U=Te.useCallback(h=>{w&&Ze.getState().setWorktreeMetadata(w,{...n,createdFromBranch:h})},[w,n]),Y=Ze(h=>h.openNewSessionDraft),S=Te.useCallback(async h=>{const L=await Ht("git.integrate.cherrypick.resolve.visible",{current_commit:h.state.currentCommit,target_branch:h.state.targetBranch}),T=await Ht("git.integrate.cherrypick.resolve.instructions",{repo_root:h.state.repoRoot,temp_worktree_path:h.state.tempWorktreePath,source_branch:h.state.sourceBranch,target_branch:h.state.targetBranch,current_commit:h.state.currentCommit}),u=`Cherry-pick conflict context (JSON)
2
2
  ${JSON.stringify({repoRoot:h.state.repoRoot,tempWorktreePath:h.state.tempWorktreePath,sourceBranch:h.state.sourceBranch,targetBranch:h.state.targetBranch,currentCommit:h.state.currentCommit,remainingCommits:h.state.remainingCommits,statusPorcelain:h.details.statusPorcelain,unmergedFiles:h.details.unmergedFiles,currentPatchMeta:h.details.currentPatchMeta,currentPatch:h.details.currentPatch,diff:h.details.diff},null,2)}`;return{visibleText:L,instructionsText:T,payloadText:u}},[]),F=Wt(h=>h.setPendingInputText),J=Wt(h=>h.setPendingSyntheticParts),H=Te.useCallback(async(h,L)=>{const T=await S(h);if(L){Y({directoryOverride:h.state.tempWorktreePath,initialPrompt:T.visibleText,syntheticParts:[{text:T.instructionsText,synthetic:!0},{text:T.payloadText,synthetic:!0}]}),B("chat");return}if(!w){b.error(m("gitView.integrate.noActiveSession"),{description:m("gitView.integrate.noActiveSessionDescription")});return}F(T.visibleText,"replace"),J([{text:T.instructionsText,synthetic:!0},{text:T.payloadText,synthetic:!0}]),B("chat")},[w,B,S,Y,F,J,m]),G=Te.useCallback(async()=>{if(d.kind==="ready"){if(d.plan.commits.length===0){b.message(m("gitView.integrate.noCommitsToMoveToast"));return}E({kind:"running",plan:d.plan});try{const h=await Oa(d.plan);if(h.kind==="success"){b.success(m("gitView.integrate.commitsMovedToast"),{description:h.moved===1?m("gitView.integrate.commitsMovedDescriptionSingle",{count:h.moved,branch:d.plan.targetBranch}):m("gitView.integrate.commitsMovedDescriptionPlural",{count:h.moved,branch:d.plan.targetBranch})});const L=await Vt(d.plan);E({kind:"ready",plan:L}),x?.();return}h.kind==="conflict"&&(b.error(m("gitView.integrate.cherryPickConflictToast"),{description:m("gitView.integrate.cherryPickConflictDescription")}),E({kind:"conflict",state:h.state,details:h.details}),g&&typeof window<"u"&&window.localStorage.setItem(g,JSON.stringify(h.state)))}catch(h){const L=h instanceof Error?h.message:String(h);b.error(m("gitView.integrate.failedToMoveToast"),{description:L});const T=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(T?{kind:"ready",plan:T}:{kind:"idle"})}}},[d,x,i,e,V,g,m]),Z=Te.useCallback(async()=>{if(d.kind==="conflict")try{await za(d.state),b.message(m("gitView.integrate.cherryPickAbortedToast")),g&&typeof window<"u"&&window.localStorage.removeItem(g)}finally{const h=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(h?{kind:"ready",plan:h}:{kind:"idle"})}},[d,i,e,V,g,m]),Q=Te.useCallback(async()=>{if(d.kind==="conflict")try{const h=await Ga(d.state);if(h.kind==="success"){b.success(m("gitView.integrate.cherryPickFinishedToast"));const L=await Vt({repoRoot:i,sourceBranch:e,targetBranch:V}).catch(()=>null);E(L?{kind:"ready",plan:L}:{kind:"idle"}),g&&typeof window<"u"&&window.localStorage.removeItem(g),x?.();return}h.kind==="conflict"&&(E({kind:"conflict",state:h.state,details:h.details}),g&&typeof window<"u"&&window.localStorage.setItem(g,JSON.stringify(h.state)))}catch(h){const L=h instanceof Error?h.message:String(h);b.error(m("gitView.integrate.cherryPickContinueFailedToast"),{description:L})}},[d,i,e,V,x,g,m]);return!i||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[p?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(D,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:m("gitView.integrate.title")}),d.kind==="ready"&&d.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m("gitView.integrate.toMoveCount",{count:d.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:d.kind==="loading"||d.kind==="running"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:m("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",V]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Vs,{open:y,onOpenChange:C,children:[t.jsx(Is,{asChild:!0,children:t.jsxs("button",{type:"button",className:wr({size:"default"}),children:[m("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:V}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Ps,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Fs,{className:"h-full min-h-0",children:[t.jsx(Rs,{ref:k,placeholder:m("gitView.branch.searchPlaceholder"),onKeyDown:h=>h.stopPropagation()}),t.jsxs(Ms,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Bs,{children:m("gitView.branch.empty")}),t.jsx(Ut,{heading:m("gitView.branch.localBranches"),children:r.map(h=>t.jsx(Kt,{value:h,onSelect:()=>{A(h),U(h),C(!1)},children:h},h))})]})]})})]}),d.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{G()},disabled:!I||d.plan.commits.length===0,children:m("gitView.integrate.move")}):d.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.checking")}):d.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.moving")}):null]}),d.kind==="ready"&&d.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.noCommitsToMove")}),d.kind==="ready"&&d.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[m("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",d.plan.commits.length,")"]})]}),N.length>0&&d.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>O(h=>!h),className:"typography-micro text-muted-foreground hover:text-foreground",children:m(R?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(R?N:N.slice(0,5)).map(h=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:h.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.subject||h.sha})]},h.sha)),N.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.previewUnavailable")}),d.plan.commits.length>N.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:m("gitView.integrate.showingFirstCommits",{count:N.length})})]})]}),d.kind==="conflict"&&t.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:m("gitView.integrate.conflictsInFiles",{count:d.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[m("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:d.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[d.details.unmergedFiles.slice(0,6).map(h=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:h},h)),d.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:m("gitView.integrate.moreFiles",{count:d.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{Z()},children:m("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{H({state:d.state,details:d.details},!1)},children:[t.jsx(D,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{H({state:d.state,details:d.details},!0)},children:[t.jsx(D,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{Q()},children:m("gitView.operation.continue")})]})]})]})]})},$a=({open:i,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:v=!1,uncommittedFileCount:f,onChanged:x})=>{const{t:p}=et(),[m,w]=l.useState([]),[B,y]=l.useState(!1),[C,k]=l.useState(""),[V,A]=l.useState(""),[I,d]=l.useState(null),[E,R]=l.useState({}),O=l.useCallback(async()=>{if(n){y(!0);try{const S=await Pn(n);w(S.stashes),R({})}catch(S){b.error(S instanceof Error?S.message:p("gitView.stashes.toast.loadFailed"))}finally{y(!1)}}},[n,p]);l.useEffect(()=>{i&&O()},[O,i]),l.useEffect(()=>{if(!i||!n||m.length===0)return;let S=!1;const F=m.map(J=>J.ref);return Fn(n,F).then(J=>{S||R(J.counts)}).catch(()=>{}),()=>{S=!0}},[n,i,m]);const N=l.useMemo(()=>{const S=C.trim().toLowerCase();return S?m.filter(F=>`${F.ref} ${F.message} ${F.relativeTime}`.toLowerCase().includes(S)):m},[C,m]),P=l.useCallback(async S=>{await O(),await x?.(S)},[O,x]),g=async()=>{if(!(!n||I)){d("create");try{const S=await Rn(n,{message:V.trim()||void 0});S.created?(b.success(p("gitView.stashes.toast.created")),A("")):b.info(p("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(S.created&&v)})}catch(S){b.error(S instanceof Error?S.message:p("gitView.stashes.toast.createFailed"))}finally{d(null)}}},U=async(S,F)=>{if(!(!n||I)&&!(F==="drop"&&!window.confirm(p("gitView.stashes.confirm.drop",{ref:S.ref})))){d(`${F}:${S.ref}`);try{F==="apply"&&await Mn(n,{ref:S.ref}),F==="pop"&&await Bn(n,{ref:S.ref}),F==="drop"&&await Tn(n,{ref:S.ref});const J=F==="apply"?"gitView.stashes.toast.applySuccess":F==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(p(J)),await P({affectsIndex:F!=="drop"})}catch(J){const H=F==="apply"?"gitView.stashes.toast.applyFailed":F==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(J instanceof Error?J.message:p(H)),await P({affectsIndex:F!=="drop"})}finally{d(null)}}},Y=I!==null;return t.jsx(ut,{open:i,onOpenChange:e,children:t.jsxs(mt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ht,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(D,{name:"archive-stack",className:"h-5 w-5"}),p("gitView.stashes.title")]}),t.jsx(wt,{children:p("gitView.stashes.description")})]}),t.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(nr,{value:V,onChange:S=>A(S.target.value),placeholder:p("gitView.stashes.messagePlaceholder"),disabled:Y||!r,className:"flex-1"}),t.jsxs(W,{onClick:g,disabled:!r||Y||!n,children:[I==="create"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"inbox-archive",className:"size-4"}),p("gitView.stashes.actions.stashCurrentWithCount",{count:f})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:p("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(D,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(nr,{value:C,onChange:S=>k(S.target.value),placeholder:p("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:B?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(D,{name:"loader-4",className:"size-5 animate-spin"})}):N.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:p(C?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):N.map((S,F)=>t.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[t.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[t.jsx("p",{className:"typography-small truncate text-foreground",children:S.message||p("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Jt,{children:[t.jsx(qt,{asChild:!0,children:t.jsx("span",{children:F===0&&!C.trim()?p("gitView.stashes.latestLabel"):p("gitView.stashes.itemNumber",{number:F+1})})}),t.jsx(Yt,{sideOffset:6,children:S.ref})]})," · ",S.relativeTime," · ",typeof E[S.ref]=="number"?p("gitView.stashes.fileCount",{count:E[S.ref]}):p("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Ss,{label:p("gitView.stashes.actions.apply"),loading:I===`apply:${S.ref}`,onClick:()=>U(S,"apply"),disabled:Y,children:t.jsx(D,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Ss,{label:p("gitView.stashes.actions.pop"),loading:I===`pop:${S.ref}`,onClick:()=>U(S,"pop"),disabled:Y,children:t.jsx(D,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Ss,{label:p("gitView.stashes.actions.drop"),loading:I===`drop:${S.ref}`,onClick:()=>U(S,"drop"),disabled:Y,destructive:!0,children:t.jsx(D,{name:"delete-bin",className:"size-4"})})]})]},S.ref))})]})})},Ss=i=>{const e=jt.c(17),{label:n,loading:r,disabled:v,destructive:f,onClick:x,children:p}=i,m=r||void 0,w=f?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let B;e[0]!==w?(B=Re("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",w),e[0]=w,e[1]=B):B=e[1];let y;e[2]!==p||e[3]!==r?(y=r?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):p,e[2]=p,e[3]=r,e[4]=y):y=e[4];let C;e[5]!==v||e[6]!==n||e[7]!==x||e[8]!==m||e[9]!==B||e[10]!==y?(C=t.jsx(qt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":m,className:B,onClick:x,disabled:v,children:y})}),e[5]=v,e[6]=n,e[7]=x,e[8]=m,e[9]=B,e[10]=y,e[11]=C):C=e[11];let k;e[12]!==n?(k=t.jsx(Yt,{sideOffset:6,children:n}),e[12]=n,e[13]=k):k=e[13];let V;return e[14]!==C||e[15]!==k?(V=t.jsxs(Jt,{children:[C,k]}),e[14]=C,e[15]=k,e[16]=V):V=e[16],V},Ha=i=>{const e=jt.c(16),{onOpenStashes:n}=i,{t:r}=et();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(D,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=v):v=e[0];let f;e[1]!==r?(f=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=f):f=e[2];let x;e[3]!==f?(x=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:f}),e[3]=f,e[4]=x):x=e[4];let p;e[5]!==r?(p=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=p):p=e[6];let m;e[7]!==p?(m=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:p}),e[7]=p,e[8]=m):m=e[8];let w;e[9]!==n||e[10]!==r?(w=n?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(D,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=w):w=e[11];let B;return e[12]!==x||e[13]!==m||e[14]!==w?(B=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[v,x,m,w]}),e[12]=x,e[13]=m,e[14]=w,e[15]=B):B=e[15],B},dt=8,Wa=i=>{const e=jt.c(18),{laned:n,totalLanes:r,isExpanded:v}=i,{lane:f,color:x,connectors:p}=n,w=Math.max(r,f+1)*dt+dt/2,B=l.useRef(null),y=l.useRef(null);let C;e[0]!==x||e[1]!==p||e[2]!==f||e[3]!==w?(C=()=>{const d=B.current,E=y.current;if(!d||!E)return;const R=d.offsetHeight;if(R===0)return;const O=window.devicePixelRatio||1;E.width=w*O,E.height=R*O;const N=E.getContext("2d");if(!N)return;N.scale(O,O),N.clearRect(0,0,w,R);const P=R/2,g=f*dt+dt/2,U=getComputedStyle(E),Y=U.getPropertyValue("--surface-muted-foreground").trim()||U.color,S=H=>{if(!H.startsWith("var("))return H;const G=H.slice(4,-1).trim();return U.getPropertyValue(G).trim()||Y},F=[...p].sort(Ka);for(const H of F){const G=H.fromLane*dt+dt/2,Z=H.toLane*dt+dt/2,Q=H.type==="passing"?.72:H.type==="branch-out"||H.type==="merge-in"?.95:1;N.beginPath(),N.strokeStyle=S(H.color),N.globalAlpha=Q,N.lineWidth=1.25,N.lineCap="round";e:switch(H.type){case"passing":case"commit-lane":{N.moveTo(G,0),N.lineTo(G,R);break e}case"top-stub":{N.moveTo(G,0),N.lineTo(G,P);break e}case"bottom-stub":{N.moveTo(G,P),N.lineTo(G,R);break e}case"branch-out":{const se=(P+R)/2;N.moveTo(g,P),N.bezierCurveTo(g,se,Z,se,Z,R);break e}case"merge-in":{const se=P/2;N.moveTo(G,0),N.bezierCurveTo(G,se,g,se,g,P);break e}default:continue}N.stroke(),N.globalAlpha=1}const J=U.getPropertyValue("--background").trim()||U.getPropertyValue("--surface-background").trim();N.beginPath(),N.arc(g,P,4,0,Math.PI*2),N.fillStyle=S(x),N.fill(),N.beginPath(),N.arc(g,P,5,0,Math.PI*2),N.strokeStyle=J||Y,N.lineWidth=2,N.stroke()},e[0]=x,e[1]=p,e[2]=f,e[3]=w,e[4]=C):C=e[4];let k;e[5]!==x||e[6]!==p||e[7]!==v||e[8]!==f||e[9]!==n||e[10]!==r||e[11]!==w?(k=[n,f,x,p,r,v,w],e[5]=x,e[6]=p,e[7]=v,e[8]=f,e[9]=n,e[10]=r,e[11]=w,e[12]=k):k=e[12],l.useLayoutEffect(C,k);let V;e[13]!==w?(V={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=V):V=e[14];let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=A):A=e[15];let I;return e[16]!==V?(I=t.jsx("div",{ref:B,style:V,children:A}),e[16]=V,e[17]=I):I=e[17],I};function Ua(i){return i==="branch-out"||i==="merge-in"}function Ka(i,e){const n=Ua;return(n(i.type)?1:0)-(n(e.type)?1:0)}const lr=15e3,cr=500,dr=12,ur=8*1024*1024,mr=i=>typeof i=="string"?0:(i.original?.length??0)+(i.modified?.length??0),hr=i=>{if(i.size<=dr){let v=0;for(const f of i.values())v+=mr(f);if(v<=ur)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let r=0;for(const[v,f]of e){if(n.size>=dr)continue;const x=mr(f);r+x>ur&&n.size>0||(n.set(v,f),r+=x)}return new Map(Array.from(n.entries()).reverse())};function gr(i,e){const n=new Date(i);return Number.isNaN(n.getTime())?i:An(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ja(i){switch(i){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function qa(i){return i?i.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const Ya=l.memo(({entry:i,mode:e="history",laned:n,totalLanes:r,isExpanded:v,onToggle:f,files:x,isLoadingFiles:p,onCopyHash:m,directory:w,onConflict:B,onActionSuccess:y})=>{const{t:C}=et(),k=xt(u=>u.timeFormatPreference),V=e==="graph",[A,I]=l.useState(null),[d,E]=l.useState(!1),[R,O]=l.useState(""),[N,P]=l.useState(null),[g,U]=l.useState(new Set),[Y,S]=l.useState(new Map),[F,J]=l.useState(new Set),H=async()=>{if(w){I("checkout");try{await Wn(w,i.hash),b.success(C("gitView.history.actions.detachedHead")),y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},G=async()=>{if(!(!w||!R.trim())){I("createBranch");try{await On(w,R.trim(),i.hash),E(!1),O(""),y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},Z=async()=>{if(w){I("cherryPick");try{const u=await Hn(w,i.hash);u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"cherry-pick"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},Q=async()=>{if(w){I("revert");try{const u=await $n(w,i.hash);u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"revert"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},se=async(u,M=!1)=>{if(!(!w||A!==null)){I("reset");try{await zn(w,i.hash,u,M),y?.()}catch($){b.error(String($.message))}finally{I(null)}}},ce=async()=>{if(!N)return;const u=N;switch(P(null),u){case"checkout":return H();case"cherryPick":return Z();case"revert":return Q();case"merge":return oe();case"rebase":return h();case"resetSoft":return se("soft");case"resetMixed":return se("mixed");case"resetHard":return se("hard",!0)}},oe=async()=>{if(w){I("merge");try{const u=await _n(w,{branch:i.hash});u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"merge"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},h=async()=>{if(w){I("rebase");try{const u=await Gn(w,{onto:i.hash});u.conflict?B?.({conflict:!0,conflictFiles:u.conflictFiles,operation:"rebase"}):y?.()}catch(u){b.error(String(u.message))}finally{I(null)}}},L=l.useCallback(async u=>{const M=u.path;if(!w){S($=>new Map($).set(M,"error"));return}S($=>hr(new Map($).set(M,"loading")));try{const $=Dn(w,i.hash,u.path,!1),ae=new Promise((ee,_)=>{setTimeout(()=>_(new Error(`Timed out after ${lr}ms`)),lr)}),ie=await Promise.race([$,ae]);S(ee=>hr(new Map(ee).set(M,ie)))}catch{S($=>new Map($).set(M,"error"))}},[w,i.hash]),T=l.useCallback(async u=>{const M=u.path;if(u.changeType==="R"||u.isBinary){U(ee=>{const _=new Set(ee);return _.has(M)?_.delete(M):_.add(M),_});return}const $=Y.get(M);if(g.has(M)&&$&&$!=="error"){U(ee=>{const _=new Set(ee);return _.delete(M),_});return}U(ee=>{const _=new Set(ee);return _.add(M),_}),!($&&$!=="error"||u.insertions+u.deletions>cr&&!F.has(M))&&await L(u)},[Y,F,L,g]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:f,className:Re("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",V?"hover:bg-[var(--interactive-hover)]/40":v?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[V&&n&&r!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Wa,{laned:n,totalLanes:r,isExpanded:v})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[V?(()=>{const u=qa(i.refs);return u.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:u.map(M=>t.jsx("span",{className:Re("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",M.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":M.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:M.label},M.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:i.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:i.author_name,children:i.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:gr(i.date,k),children:gr(i.date,k)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:i.hash.slice(0,8)}),t.jsxs(Jt,{children:[t.jsx(qt,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:u=>{u.stopPropagation(),m(i.hash)},children:t.jsx(D,{name:"file-copy",className:"size-3"})})}),t.jsx(Yt,{sideOffset:8,children:C("gitView.history.copySha")})]})]})]})]}),v&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[V&&N?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:C(`gitView.history.actions.${N}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:A!==null,onClick:u=>{u.stopPropagation(),ce()},children:[A!==null?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:A!==null,onClick:u=>{u.stopPropagation(),P(null)},children:C("gitView.history.actions.cancelButton")})]}):V?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("checkout")},children:C("gitView.history.actions.checkout")}),d?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:R,onChange:u=>O(u.target.value),onKeyDown:u=>{u.key==="Enter"&&G(),u.key==="Escape"&&(E(!1),O(""))},placeholder:C("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:!R.trim()||A!==null,onClick:u=>{u.stopPropagation(),G()},children:[A==="createBranch"?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:u=>{u.stopPropagation(),E(!0)},children:C("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("cherryPick")},children:C("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("revert")},children:C("gitView.history.actions.revert")}),t.jsxs(Vs,{children:[t.jsx(Is,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>u.stopPropagation(),children:[A==="reset"?t.jsx(D,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,C("gitView.history.actions.reset")]})}),t.jsx(Ps,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(u=>t.jsx(En,{disabled:A!==null,onSelect:M=>{M.stopPropagation(),P(`reset${u.charAt(0).toUpperCase()+u.slice(1)}`)},children:C(`gitView.history.actions.reset${u.charAt(0).toUpperCase()+u.slice(1)}`)},u))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("merge")},children:C("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:A!==null,onClick:u=>{u.stopPropagation(),P("rebase")},children:C("gitView.history.actions.rebase")})]}):null,p?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:C("gitView.history.loadingFiles")})]}):x.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:C("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:x.map(u=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>T(u),className:Re("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",g.has(u.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Re("font-semibold w-3 text-center shrink-0",Ja(u.changeType)),children:u.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:u.path,children:u.path}),!u.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",u.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",u.deletions]})]}),u.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:C("gitView.history.binary")}),t.jsx(D,{name:g.has(u.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),g.has(u.path)&&t.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:u.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.renamedNoDiff")}):u.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.binaryNoDiff")}):(()=>{const M=u.insertions+u.deletions;if(!F.has(u.path)&&M>cr)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:C("gitView.history.largeDiffTitle",{count:M})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:C("gitView.history.largeDiffDescription")}),t.jsx(W,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{J(ae=>new Set(ae).add(u.path)),L(u)},children:C("gitView.history.renderDiffAnyway")})]});const $=Y.get(u.path);return $==="loading"||$===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.loadingDiff")}):$==="error"?t.jsx("button",{type:"button",onClick:()=>T(u),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:C("gitView.history.diffError")}):t.jsx(Ma,{original:$.original,modified:$.modified,language:Ln(u.path)||"",fileName:u.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},u.path))})]})]})}),fr=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function $t(i){return fr[i%fr.length]}function Qa(i){if(i.length===0)return[];const e=[],n=[];for(let r=0;r<i.length;r++){const v=i[r],f=[];for(let k=0;k<e.length;k++)e[k]===v.hash&&f.push(k);let x=f.length>0?f[0]:-1;if(x===-1){const k=e.indexOf(null);k!==-1?x=k:(x=e.length,e.push(null))}const p=f.slice(1),m=$t(x),w=e[x]===v.hash,B=v.parents.length>0;B?e[x]=v.parents[0]:e[x]=null;const y=[];for(let k=1;k<v.parents.length;k++){const V=v.parents[k],A=e.indexOf(V);if(A!==-1)y.push(A);else{const I=e.indexOf(null),d=I!==-1?I:e.length;e[d]=V,d===e.length&&e.push(V),y.push(d)}}const C=[];w&&B?C.push({fromLane:x,toLane:x,color:m,type:"commit-lane"}):w&&!B?C.push({fromLane:x,toLane:x,color:m,type:"top-stub"}):!w&&B&&C.push({fromLane:x,toLane:x,color:m,type:"bottom-stub"});for(const k of p)C.push({fromLane:k,toLane:x,color:$t(k),type:"merge-in"}),e[k]=null;for(const k of y)C.push({fromLane:x,toLane:k,color:$t(k),type:"branch-out"});for(let k=0;k<e.length;k++)e[k]!==null&&k!==x&&(y.includes(k)||C.push({fromLane:k,toLane:k,color:$t(k),type:"passing"}));n.push({commit:v,lane:x,color:m,connectors:C})}return n}const Xa=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Za=i=>{const e=jt.c(84),{mode:n,log:r,isLogLoading:v,logMaxCount:f,onLogMaxCountChange:x,expandedCommitHashes:p,onToggleCommit:m,commitFilesMap:w,loadingCommitHashes:B,onCopyHash:y,directory:C,showHeader:k,contentMaxHeightClassName:V,branchDivider:A,onConflict:I,onActionSuccess:d}=i,E=n===void 0?"history":n,R=k===void 0?!0:k,O=V===void 0?"max-h-[50vh]":V,N=A===void 0?null:A,{t:P}=et(),[g,U]=l.useState(!0),Y=E==="graph";let S;e[0]!==Y||e[1]!==r?(S=Y&&r?Qa(r.all):[],e[0]=Y,e[1]=r,e[2]=S):S=e[2];const F=S;let J;e[3]!==F?(J=Math.max(1,...F.map(ei)),e[3]=F,e[4]=J):J=e[4];const H=J;let G;e[5]!==F?(G=new Map(F.map(ti)),e[5]=F,e[6]=G):G=e[6];const Z=G;if(!r)return null;const Q=N!==null&&N.insertBeforeIndex>0&&N.insertBeforeIndex<r.all.length,se=N!==null&&N.insertBeforeIndex===r.all.length,ce=Q||se;let oe;e[7]!==N||e[8]!==Q||e[9]!==se||e[10]!==r.all?(oe=Q?r.all.slice(0,N.insertBeforeIndex):se?r.all:[],e[7]=N,e[8]=Q,e[9]=se,e[10]=r.all,e[11]=oe):oe=e[11];const h=oe;let L;if(e[12]!==N||e[13]!==w||e[14]!==O||e[15]!==C||e[16]!==p||e[17]!==Q||e[18]!==ce||e[19]!==Y||e[20]!==v||e[21]!==Z||e[22]!==B||e[23]!==r.all||e[24]!==f||e[25]!==H||e[26]!==E||e[27]!==d||e[28]!==I||e[29]!==y||e[30]!==x||e[31]!==m||e[32]!==P||e[33]!==h){const te=Q?r.all.slice(N.insertBeforeIndex):[];let de;e[35]!==N?.direction?(de=N?.direction==="down"?t.jsx(D,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(D,{name:"arrow-up",className:"size-3.5"}),e[35]=N?.direction,e[36]=de):de=e[36];const ve=de;let ue;e[37]!==w||e[38]!==C||e[39]!==p||e[40]!==Y||e[41]!==Z||e[42]!==B||e[43]!==H||e[44]!==E||e[45]!==d||e[46]!==I||e[47]!==y||e[48]!==m?(ue=De=>t.jsx("ul",{className:"divide-y divide-border/60",children:De.map(je=>t.jsx(Ya,{entry:je,mode:E,laned:Y?Z.get(je.hash):void 0,totalLanes:Y?H:void 0,isExpanded:p.has(je.hash),onToggle:()=>m(je.hash),files:w.get(je.hash)??[],isLoadingFiles:B.has(je.hash),onCopyHash:y,directory:C,onConflict:I,onActionSuccess:d},je.hash))}),e[37]=w,e[38]=C,e[39]=p,e[40]=Y,e[41]=Z,e[42]=B,e[43]=H,e[44]=E,e[45]=d,e[46]=I,e[47]=y,e[48]=m,e[49]=ue):ue=e[49];const he=ue;let me;e[50]!==v||e[51]!==r.all.length||e[52]!==f||e[53]!==x||e[54]!==P?(me=r.all.length>=f?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(W,{type:"button",variant:"ghost",size:"xs",onClick:()=>x(f+25),disabled:v,className:"px-3 text-muted-foreground hover:text-foreground",children:v?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(D,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=v,e[51]=r.all.length,e[52]=f,e[53]=x,e[54]=P,e[55]=me):me=e[55];const le=me;L=t.jsx(yr,{outerClassName:`min-h-0 ${O}`,className:"h-full w-full",children:r.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):ce&&N?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[h.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:he(h)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:N.branchName,children:N.branchName}),ve]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),te.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:he(te)}):null]}),le]}):t.jsxs(t.Fragment,{children:[he(r.all),le]})}),e[12]=N,e[13]=w,e[14]=O,e[15]=C,e[16]=p,e[17]=Q,e[18]=ce,e[19]=Y,e[20]=v,e[21]=Z,e[22]=B,e[23]=r.all,e[24]=f,e[25]=H,e[26]=E,e[27]=d,e[28]=I,e[29]=y,e[30]=x,e[31]=m,e[32]=P,e[33]=h,e[34]=L}else L=e[34];const T=L;if(!R){if(ce){let de;return e[56]!==T?(de=t.jsx("section",{className:"h-full min-h-0",children:T}),e[56]=T,e[57]=de):de=e[57],de}let te;return e[58]!==T?(te=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:T}),e[58]=T,e[59]=te):te=e[59],te}let u;e[60]!==P?(u=P("gitView.history.title"),e[60]=P,e[61]=u):u=e[61];let M;e[62]!==u?(M=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:u}),e[62]=u,e[63]=M):M=e[63];let $;e[64]!==v||e[65]!==g||e[66]!==f||e[67]!==x||e[68]!==P?($=g&&t.jsx("div",{onClick:si,onPointerDown:ri,children:t.jsxs(Un,{value:String(f),onValueChange:te=>x(Number(te)),disabled:v,children:[t.jsx(Kn,{size:"sm",className:"w-auto",disabled:v,children:t.jsx(Jn,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(qn,{children:Xa.map(te=>t.jsx(Yn,{value:String(te.value),children:P(te.labelKey)},te.value))})]})}),e[64]=v,e[65]=g,e[66]=f,e[67]=x,e[68]=P,e[69]=$):$=e[69];let ae;e[70]!==g?(ae=g?t.jsx(D,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(D,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=g,e[71]=ae):ae=e[71];let ie;e[72]!==$||e[73]!==ae?(ie=t.jsxs("div",{className:"flex items-center gap-2",children:[$,ae]}),e[72]=$,e[73]=ae,e[74]=ie):ie=e[74];let ee;e[75]!==M||e[76]!==ie?(ee=t.jsxs(Na,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[M,ie]}),e[75]=M,e[76]=ie,e[77]=ee):ee=e[77];let _;e[78]!==T?(_=t.jsx(Sa,{children:T}),e[78]=T,e[79]=_):_=e[79];let be;return e[80]!==g||e[81]!==ee||e[82]!==_?(be=t.jsxs(ka,{open:g,onOpenChange:U,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[ee,_]}),e[80]=g,e[81]=ee,e[82]=_,e[83]=be):be=e[83],be};function ei(i){return i.lane+1}function ti(i){return[i.commit.hash,i]}function si(i){return i.stopPropagation()}function ri(i){return i.stopPropagation()}const ni=i=>{const e=jt.c(150),{open:n,onOpenChange:r,conflictFiles:v,directory:f,operation:x,onAbort:p,onClearState:m}=i;let w;e[0]!==v?(w=v===void 0?[]:v,e[0]=v,e[1]=w):w=e[1];const B=w,{t:y}=et(),C=Ze(ai),k=Ze(ii),V=Wt(oi),A=Wt(li),I=xt(ci),[d,E]=l.useState(!1),[R,O]=l.useState(null),[N,P]=l.useState(null);let g,U;e[2]!==f||e[3]!==n||e[4]!==y?(g=()=>{!n||!f||(E(!0),P(null),O(null),Qn(f).then(X=>{O(X)}).catch(X=>{const Pe=X instanceof Error?X.message:y("gitView.conflict.loadFailed");P(Pe)}).finally(()=>{E(!1)}))},U=[n,f,y],e[2]=f,e[3]=n,e[4]=y,e[5]=g,e[6]=U):(g=e[5],U=e[6]),l.useEffect(g,U);let Y;e[7]!==R||e[8]!==f||e[9]!==x?(Y=async()=>{if(!R)return null;const X=x==="merge"?"merge":"rebase",Pe=R.headInfo||(x==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Oe=x==="merge"?"git commit --no-edit":"git rebase --continue",ze=await Ht("git.conflict.resolve.visible",{operation_label:X,head_ref:Pe}),Fe=await Ht("git.conflict.resolve.instructions",{operation_label:X,directory:f,operation:x,head_info:R.headInfo||"N/A",continue_cmd:Oe}),pe=`${X} conflict context (JSON)
3
3
  ${JSON.stringify({directory:f,operation:R.operation,headInfo:R.headInfo,statusPorcelain:R.statusPorcelain,unmergedFiles:R.unmergedFiles,diff:R.diff},null,2)}`;return{visibleText:ze,instructionsText:Fe,payloadText:pe}},e[7]=R,e[8]=f,e[9]=x,e[10]=Y):Y=e[10];const S=Y;let F;e[11]!==p||e[12]!==r?(F=()=>{p(),r(!1)},e[11]=p,e[12]=r,e[13]=F):F=e[13];const J=F;let H;e[14]!==m||e[15]!==r?(H=()=>{m?.(),r(!1)},e[14]=m,e[15]=r,e[16]=H):H=e[16];const G=H;let Z;e[17]!==S||e[18]!==k||e[19]!==m||e[20]!==r||e[21]!==I||e[22]!==V||e[23]!==A||e[24]!==y?(Z=async()=>{const X=await S();if(!X){b.error(y("gitView.conflict.noDetailsAvailable"));return}if(!k){b.error(y("gitView.conflict.noActiveSession"),{description:y("gitView.conflict.noActiveSessionDescription")});return}V(X.visibleText,"replace"),A([{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]),I("chat"),m?.(),r(!1)},e[17]=S,e[18]=k,e[19]=m,e[20]=r,e[21]=I,e[22]=V,e[23]=A,e[24]=y,e[25]=Z):Z=e[25];const Q=Z;let se;e[26]!==S||e[27]!==f||e[28]!==m||e[29]!==r||e[30]!==C||e[31]!==I||e[32]!==y?(se=async()=>{const X=await S();if(!X){b.error(y("gitView.conflict.noDetailsAvailable"));return}C({directoryOverride:f,initialPrompt:X.visibleText,syntheticParts:[{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]}),I("chat"),m?.(),r(!1)},e[26]=S,e[27]=f,e[28]=m,e[29]=r,e[30]=C,e[31]=I,e[32]=y,e[33]=se):se=e[33];const ce=se;let oe,h,L,T,u,M,$,ae,ie,ee,_,be,te,de,ve,ue,he,me,le,De,je,ge;if(e[34]!==R||e[35]!==B||e[36]!==k||e[37]!==J||e[38]!==G||e[39]!==Q||e[40]!==ce||e[41]!==d||e[42]!==N||e[43]!==r||e[44]!==n||e[45]!==x||e[46]!==y){const X=y(x==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),Pe=R?.unmergedFiles||B;L=ut,je=n,ge=r,h=mt,De="max-w-md w-[calc(100vw-2rem)]",de="flex flex-col gap-4 overflow-hidden";let Oe;e[69]===Symbol.for("react.memo_cache_sentinel")?(Oe=t.jsx(D,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=Oe):Oe=e[69];const ze=t.jsxs("div",{className:"flex items-center gap-2",children:[Oe,t.jsx(gt,{children:y("gitView.conflict.detectedTitle",{operation:X})})]});let Fe;e[70]!==x||e[71]!==y?(Fe=y("gitView.conflict.detectedDescription",{operation:x}),e[70]=x,e[71]=y,e[72]=Fe):Fe=e[72];let pe;e[73]!==Fe?(pe=t.jsx(wt,{children:Fe}),e[73]=Fe,e[74]=pe):pe=e[74],e[75]!==ze||e[76]!==pe?(ve=t.jsxs(ht,{children:[ze,pe]}),e[75]=ze,e[76]=pe,e[77]=ve):ve=e[77],e[78]!==d||e[79]!==y?(ue=d&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:y("gitView.conflict.loading")})]}),e[78]=d,e[79]=y,e[80]=ue):ue=e[80],e[81]!==N||e[82]!==y?(he=N&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:y("gitView.conflict.errorLoadingDetails",{message:N})}),e[81]=N,e[82]=y,e[83]=he):he=e[83],e[84]!==Pe||e[85]!==y?(me=Pe.length>0&&t.jsxs("div",{className:"space-y-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.conflictedFiles")}),t.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:Pe.length})]}),t.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:t.jsx("ul",{className:"space-y-1",children:Pe.map(di)})})]}),e[84]=Pe,e[85]=y,e[86]=me):me=e[86],e[87]!==R||e[88]!==y?(le=R?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.headInfo")}),t.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:R.headInfo})]}),e[87]=R,e[88]=y,e[89]=le):le=e[89],_="flex flex-col gap-2 pt-2";let Ce;e[90]!==ce?(Ce=()=>{ce()},e[90]=ce,e[91]=Ce):Ce=e[91];const Ge=d||!R;let Ne;e[92]!==d?(Ne=d?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"add",className:"size-4"}),e[92]=d,e[93]=Ne):Ne=e[93];let Be;e[94]!==y?(Be=y("gitView.conflict.resolveNewSession"),e[94]=y,e[95]=Be):Be=e[95],e[96]!==Ce||e[97]!==Ge||e[98]!==Ne||e[99]!==Be?(be=t.jsxs(W,{variant:"default",onClick:Ce,disabled:Ge,className:"w-full gap-2",children:[Ne,Be]}),e[96]=Ce,e[97]=Ge,e[98]=Ne,e[99]=Be,e[100]=be):be=e[100];let q;e[101]!==Q?(q=()=>{Q()},e[101]=Q,e[102]=q):q=e[102];const xe=d||!R||!k;let Se;e[103]!==d?(Se=d?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"chat-1",className:"size-4"}),e[103]=d,e[104]=Se):Se=e[104];let we;e[105]!==y?(we=y("gitView.conflict.resolveCurrentSession"),e[105]=y,e[106]=we):we=e[106],e[107]!==q||e[108]!==xe||e[109]!==Se||e[110]!==we?(te=t.jsxs(W,{variant:"outline",onClick:q,disabled:xe,className:"w-full gap-2",children:[Se,we]}),e[107]=q,e[108]=xe,e[109]=Se,e[110]=we,e[111]=te):te=e[111],ie="flex gap-2 pt-1";let ye;e[112]!==y?(ye=y("gitView.conflict.continueLater"),e[112]=y,e[113]=ye):ye=e[113],e[114]!==G||e[115]!==ye?(ee=t.jsx(W,{variant:"ghost",size:"sm",onClick:G,className:"flex-1",children:ye}),e[114]=G,e[115]=ye,e[116]=ee):ee=e[116],oe=W,T="destructive",u="sm",M=J,$="flex-1",ae=y("gitView.conflict.abortOperation",{operation:X}),e[34]=R,e[35]=B,e[36]=k,e[37]=J,e[38]=G,e[39]=Q,e[40]=ce,e[41]=d,e[42]=N,e[43]=r,e[44]=n,e[45]=x,e[46]=y,e[47]=oe,e[48]=h,e[49]=L,e[50]=T,e[51]=u,e[52]=M,e[53]=$,e[54]=ae,e[55]=ie,e[56]=ee,e[57]=_,e[58]=be,e[59]=te,e[60]=de,e[61]=ve,e[62]=ue,e[63]=he,e[64]=me,e[65]=le,e[66]=De,e[67]=je,e[68]=ge}else oe=e[47],h=e[48],L=e[49],T=e[50],u=e[51],M=e[52],$=e[53],ae=e[54],ie=e[55],ee=e[56],_=e[57],be=e[58],te=e[59],de=e[60],ve=e[61],ue=e[62],he=e[63],me=e[64],le=e[65],De=e[66],je=e[67],ge=e[68];let Ve;e[117]!==oe||e[118]!==T||e[119]!==u||e[120]!==M||e[121]!==$||e[122]!==ae?(Ve=t.jsx(oe,{variant:T,size:u,onClick:M,className:$,children:ae}),e[117]=oe,e[118]=T,e[119]=u,e[120]=M,e[121]=$,e[122]=ae,e[123]=Ve):Ve=e[123];let Me;e[124]!==ie||e[125]!==ee||e[126]!==Ve?(Me=t.jsxs("div",{className:ie,children:[ee,Ve]}),e[124]=ie,e[125]=ee,e[126]=Ve,e[127]=Me):Me=e[127];let Ee;e[128]!==_||e[129]!==be||e[130]!==te||e[131]!==Me?(Ee=t.jsxs("div",{className:_,children:[be,te,Me]}),e[128]=_,e[129]=be,e[130]=te,e[131]=Me,e[132]=Ee):Ee=e[132];let Ie;e[133]!==de||e[134]!==ve||e[135]!==ue||e[136]!==he||e[137]!==me||e[138]!==le||e[139]!==Ee?(Ie=t.jsxs("div",{className:de,children:[ve,ue,he,me,le,Ee]}),e[133]=de,e[134]=ve,e[135]=ue,e[136]=he,e[137]=me,e[138]=le,e[139]=Ee,e[140]=Ie):Ie=e[140];let Le;e[141]!==h||e[142]!==De||e[143]!==Ie?(Le=t.jsx(h,{className:De,children:Ie}),e[141]=h,e[142]=De,e[143]=Ie,e[144]=Le):Le=e[144];let fe;return e[145]!==L||e[146]!==je||e[147]!==ge||e[148]!==Le?(fe=t.jsx(L,{open:je,onOpenChange:ge,children:Le}),e[145]=L,e[146]=je,e[147]=ge,e[148]=Le,e[149]=fe):fe=e[149],fe};function ai(i){return i.openNewSessionDraft}function ii(i){return i.currentSessionId}function oi(i){return i.setPendingInputText}function li(i){return i.setPendingSyntheticParts}function ci(i){return i.setActiveMainTab}function di(i){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:i,children:i},i)}const ui=({open:i,onOpenChange:e,operation:n,targetBranch:r,onConfirm:v})=>{const{t:f}=et(),[x,p]=l.useState(!0),[m,w]=l.useState(!1),B=f(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),y=async()=>{w(!0);try{await v(x),e(!1)}catch(k){const V=k instanceof Error?k.message:`Failed to ${n}`;b.error(V)}finally{w(!1)}},C=()=>{m||e(!1)};return t.jsx(ut,{open:i,onOpenChange:m?void 0:e,children:t.jsxs(mt,{className:"max-w-md",children:[t.jsxs(ht,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:f("gitView.stash.title")})]}),t.jsx(wt,{children:f("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:f("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:f("gitView.stash.stepStash")}),t.jsxs("li",{children:[f(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",f(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:r})]}),x&&t.jsx("li",{children:f("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(Xn,{checked:x,onChange:p,disabled:m,ariaLabel:f("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!m&&p(!x),children:f("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(ks,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:C,disabled:m,children:f("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:y,disabled:m,className:"gap-1.5",children:m?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),f("gitView.common.processing")]}):f("gitView.stash.confirmButton",{operation:B})})]})]})})},mi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:v,conflictCount:f=0,isLoading:x=!1})=>{const{t:p}=et(),[m,w]=l.useState(null),B=i&&i.head,y=e&&(e.headName||e.onto),C=B?"merge":y?"rebase":null;if(!C)return null;const k=async()=>{w("continue");try{await n()}finally{w(null)}},V=async()=>{w("abort");try{await r()}finally{w(null)}},A=m!==null,I=f>0,d=p(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let E="";i?E=i.message?p("gitView.operation.mergingMessage",{message:i.message}):p("gitView.operation.mergeInProgressWithHead",{head:i.head}):e&&(E=e.headName?p("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):p("gitView.operation.rebaseInProgress"));const R=I?f===1?p("gitView.operation.inProgressTitleOneConflict",{operation:d,count:f}):p("gitView.operation.inProgressTitleManyConflicts",{operation:d,count:f}):p("gitView.operation.inProgressTitle",{operation:d}),O=p(I?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return t.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:t.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:R}),E&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:E})]}),t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:O}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:V,disabled:A||x,className:"gap-1.5",children:[m==="abort"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"close",className:"size-4"}),p("gitView.operation.abort")]}),I?v&&t.jsx(W,{variant:"default",size:"sm",onClick:v,disabled:A||x,children:p("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:k,disabled:A||x,className:"gap-1.5",children:[m==="continue"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"check",className:"size-4"}),p("gitView.operation.continue")]})]})]})]})})},hi=i=>{const e=jt.c(104),{currentBranch:n,localBranches:r,remoteBranches:v,onMerge:f,onRebase:x,disabled:p,isOperating:m,operationLogs:w,onOperationComplete:B,mode:y,defaultTargetBranch:C}=i,k=p===void 0?!1:p,V=m===void 0?!1:m,A=w===void 0?[]:w,I=y===void 0?"dialog":y,{t:d}=et(),[E,R]=l.useState(!1),[O,N]=l.useState("merge"),[P,g]=l.useState(null),[U,Y]=l.useState(!1),[S,F]=l.useState(""),J=l.useRef(null),H=l.useRef(null),G=k||V,Z=n||d("gitView.branch.currentBranchFallback"),Q=A.length>0&&A.every(gi),se=A.some(fi);let ce;e[0]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{H.current&&(H.current.scrollTop=H.current.scrollHeight)},e[0]=ce):ce=e[0],l.useEffect(ce,[A]);let oe;if(e[1]!==S||e[2]!==n||e[3]!==r||e[4]!==v){e:{const q=S.toLowerCase();let xe;e[6]!==v?(xe=new Set(v.map(pi).filter(Boolean)),e[6]=v,e[7]=xe):xe=e[7];const Se=xe;let we;e[8]!==n||e[9]!==Se?(we=_e=>_e!==n&&!Se.has(_e),e[8]=n,e[9]=Se,e[10]=we):we=e[10];const ye=r.filter(we);if(!q){oe=ye;break e}oe=ye.filter(_e=>_e.toLowerCase().includes(q))}e[1]=S,e[2]=n,e[3]=r,e[4]=v,e[5]=oe}else oe=e[5];const h=oe;let L;if(e[11]!==S||e[12]!==v){e:{const q=S.toLowerCase();if(!q){L=v;break e}L=v.filter(xe=>xe.toLowerCase().includes(q))}e[11]=S,e[12]=v,e[13]=L}else L=e[13];const T=L;let u;e[14]!==C||e[15]!==r||e[16]!==v?(u=()=>C&&(v.includes(C)||r.includes(C))?C:null,e[14]=C,e[15]=r,e[16]=v,e[17]=u):u=e[17];const M=u;let $;e[18]!==M||e[19]!==R?($=()=>{R(!0),g(M()),N("merge"),F("")},e[18]=M,e[19]=R,e[20]=$):$=e[20];const ae=$;let ie;e[21]===Symbol.for("react.memo_cache_sentinel")?(ie=q=>{g(q),Y(!1),F("")},e[21]=ie):ie=e[21];const ee=ie;let _;e[22]!==f||e[23]!==x||e[24]!==O||e[25]!==P?(_=()=>{P&&(O==="merge"?f(P):x(P))},e[22]=f,e[23]=x,e[24]=O,e[25]=P,e[26]=_):_=e[26];const be=_;let te;e[27]!==V||e[28]!==R?(te=()=>{V||(g(null),N("merge"),F(""),R(!1))},e[27]=V,e[28]=R,e[29]=te):te=e[29];const de=te,ve=()=>{V&&!Q||(Q&&B?.(),g(null),N("merge"),F(""),R(!1))};let ue,he;e[30]!==U?(ue=()=>{U||F("")},he=[U],e[30]=U,e[31]=ue,e[32]=he):(ue=e[31],he=e[32]),l.useEffect(ue,he);let me,le;e[33]!==I||e[34]!==M||e[35]!==P?(me=()=>{I==="dialog"||P||g(M())},le=[I,M,P],e[33]=I,e[34]=M,e[35]=P,e[36]=me,e[37]=le):(me=e[36],le=e[37]),l.useEffect(me,le);const ge=V?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:H,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:A.map(xi)})}),Q?I==="dialog"?t.jsx(ks,{children:t.jsx(W,{variant:"default",size:"sm",onClick:ve,children:d(se?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:ve,children:d(se?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>N("merge"),className:Re("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",O==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"git-merge",className:Re("size-4",O==="merge"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Re("typography-ui-label",O==="merge"?"text-foreground":"text-muted-foreground"),children:d("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:d("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>N("rebase"),className:Re("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",O==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"git-branch",className:Re("size-4",O==="rebase"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Re("typography-ui-label",O==="rebase"?"text-foreground":"text-muted-foreground"),children:d("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:d("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:O==="merge"?d("gitView.branch.branchToMergeInto",{branch:Z}):d("gitView.branch.branchToRebaseOnto")}),t.jsxs(Vs,{open:U,onOpenChange:Y,modal:!1,children:[t.jsx(Is,{asChild:!0,children:t.jsxs("button",{type:"button",className:Re(wr({size:"default"}),"w-full"),children:[t.jsx("span",{className:Re("truncate",!P&&"text-muted-foreground"),children:P||d("gitView.branch.selectBranch")}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Ps,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Fs,{className:"h-full min-h-0",children:[t.jsx(Rs,{ref:J,placeholder:d("gitView.branch.searchPlaceholder"),value:S,onValueChange:F,onKeyDown:wi}),t.jsxs(Ms,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Bs,{children:d("gitView.branch.empty")}),h.length>0&&t.jsx(Ut,{heading:d("gitView.branch.localBranches"),children:h.map(q=>t.jsx(Kt,{onSelect:()=>ee(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`local-${q}`))}),h.length>0&&T.length>0?t.jsx(Zn,{}):null,T.length>0&&t.jsx(Ut,{heading:d("gitView.branch.remoteBranches"),children:T.map(q=>t.jsx(Kt,{onSelect:()=>ee(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`remote-${q}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:O==="merge"?t.jsxs(t.Fragment,{children:[d("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})," ",d("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z})]}):t.jsxs(t.Fragment,{children:[d("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z})," ",d("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})]})})}):null,I==="dialog"?t.jsxs(ks,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:de,children:d("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:be,disabled:!P,className:"gap-1.5",children:O==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"git-merge",className:"size-4"}),d("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"git-branch",className:"size-4"}),d("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:de,disabled:G,children:d("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:be,disabled:G||!P,children:d(O==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(I==="bare")return ge;if(I==="inline"){let q;e[38]!==d?(q=d("gitView.branch.updateTitle"),e[38]=d,e[39]=q):q=e[39];let xe;e[40]!==q?(xe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:q}),e[40]=q,e[41]=xe):xe=e[41];let Se;e[42]!==d?(Se=d("gitView.branch.updateDescriptionPrefix"),e[42]=d,e[43]=Se):Se=e[43];let we;e[44]!==Z?(we=t.jsx("span",{className:"font-mono text-foreground",children:Z}),e[44]=Z,e[45]=we):we=e[45];let ye;e[46]!==Se||e[47]!==we?(ye=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Se," ",we,"."]}),e[46]=Se,e[47]=we,e[48]=ye):ye=e[48];let _e;e[49]!==xe||e[50]!==ye?(_e=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[xe,ye]})}),e[49]=xe,e[50]=ye,e[51]=_e):_e=e[51];let tt;e[52]!==ge?(tt=t.jsx("div",{className:"pt-3",children:ge}),e[52]=ge,e[53]=tt):tt=e[53];let st;return e[54]!==_e||e[55]!==tt?(st=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[_e,tt]}),e[54]=_e,e[55]=tt,e[56]=st):st=e[56],st}let Ve;e[57]!==V?(Ve=V?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"git-merge",className:"size-4"}),e[57]=V,e[58]=Ve):Ve=e[58];let Me;e[59]!==d?(Me=d("gitView.branch.mergeRebase"),e[59]=d,e[60]=Me):Me=e[60];let Ee;e[61]!==Me?(Ee=t.jsx("span",{children:Me}),e[61]=Me,e[62]=Ee):Ee=e[62];let Ie;e[63]!==ae||e[64]!==G||e[65]!==Ve||e[66]!==Ee?(Ie=t.jsx(qt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ae,disabled:G,children:[Ve,Ee]})}),e[63]=ae,e[64]=G,e[65]=Ve,e[66]=Ee,e[67]=Ie):Ie=e[67];let Le;e[68]!==d?(Le=d("gitView.branch.mergeRebaseTooltip"),e[68]=d,e[69]=Le):Le=e[69];let fe;e[70]!==Le?(fe=t.jsx(Yt,{sideOffset:8,children:Le}),e[70]=Le,e[71]=fe):fe=e[71];let X;e[72]!==Ie||e[73]!==fe?(X=t.jsxs(Jt,{children:[Ie,fe]}),e[72]=Ie,e[73]=fe,e[74]=X):X=e[74];let Pe;e[75]!==ve||e[76]!==R?(Pe=q=>{q?R(!0):ve()},e[75]=ve,e[76]=R,e[77]=Pe):Pe=e[77];let Oe;e[78]!==d?(Oe=d("gitView.branch.updateTitle"),e[78]=d,e[79]=Oe):Oe=e[79];let ze;e[80]!==Oe?(ze=t.jsx(gt,{children:Oe}),e[80]=Oe,e[81]=ze):ze=e[81];let Fe;e[82]!==se||e[83]!==V||e[84]!==O||e[85]!==Q||e[86]!==d||e[87]!==Z?(Fe=V?d(Q?se?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":O==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[d("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Z}),"."]}),e[82]=se,e[83]=V,e[84]=O,e[85]=Q,e[86]=d,e[87]=Z,e[88]=Fe):Fe=e[88];let pe;e[89]!==Fe?(pe=t.jsx(wt,{children:Fe}),e[89]=Fe,e[90]=pe):pe=e[90];let Ce;e[91]!==ze||e[92]!==pe?(Ce=t.jsxs(ht,{children:[ze,pe]}),e[91]=ze,e[92]=pe,e[93]=Ce):Ce=e[93];let Ge;e[94]!==ge||e[95]!==Ce?(Ge=t.jsxs(mt,{className:"max-w-md",children:[Ce,ge]}),e[94]=ge,e[95]=Ce,e[96]=Ge):Ge=e[96];let Ne;e[97]!==E||e[98]!==Pe||e[99]!==Ge?(Ne=t.jsx(ut,{open:E,onOpenChange:Pe,children:Ge}),e[97]=E,e[98]=Pe,e[99]=Ge,e[100]=Ne):Ne=e[100];let Be;return e[101]!==X||e[102]!==Ne?(Be=t.jsxs(t.Fragment,{children:[X,Ne]}),e[101]=X,e[102]=Ne,e[103]=Be):Be=e[103],Be};function gi(i){return i.status==="done"||i.status==="error"}function fi(i){return i.status==="error"}function pi(i){return i.slice(i.indexOf("/")+1)}function xi(i,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[i.status==="running"&&t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),i.status==="done"&&t.jsx(D,{name:"check",className:"size-3.5 text-success"}),i.status==="error"&&t.jsx(D,{name:"close",className:"size-3.5 text-destructive"}),i.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:Re("typography-micro",i.status==="error"&&"text-destructive",i.status==="done"&&"text-muted-foreground",i.status==="running"&&"text-foreground",i.status==="pending"&&"text-muted-foreground/60"),children:i.message})]},e)}function wi(i){return i.stopPropagation()}const yi=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:v})=>{const f=[];let x=!1;return{enqueue:m=>{const w=f[f.length-1];if(w?.directory===m.directory&&w.direction===m.direction){m.paths.forEach(B=>w.paths.add(B));return}f.push(m)},flush:()=>{if(x)return;const m=f.shift();if(!m)return;x=!0;const w={directory:m.directory,direction:m.direction,paths:Array.from(m.paths),rollback:m.rollback};(async()=>{try{await i(w),e(w)}catch(B){n(w,B)}finally{r(w.paths),x=!1,f.length>0&&v()}})()},clear:()=>{f.length=0},size:()=>f.length,isRunning:()=>x}},bi=15e3,vi=40,ji=20,pr={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Ci=(i,e)=>{const n=i.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,v=n.match(r);if(v){const p=v[1],m=pr[p];if(m)return e.find(w=>w.code===m)||null}const f=n.split(" ")[0],x=pr[f];return x&&e.find(p=>p.code===x)||null},Ni=20,vt=new Map,Si=(i,e)=>{if(vt.delete(i),vt.set(i,e),vt.size>Ni){const n=vt.keys().next().value;n!==void 0&&vt.delete(n)}},nt=i=>(i||"").replace(/\\/g,"/").replace(/\/+$/,""),xr=i=>{const e=i.index?.trim();return!!(e&&e!=="?")},ki=i=>{const e=i.working_dir?.trim(),n=i.index?.trim();return!!(e||n==="?")},zl=({isActive:i})=>{const{t:e}=et(),{git:n}=ea(),r=ta(),[v,f]=l.useState(null),[x,p]=l.useState(!1),m=Ze(s=>s.currentSessionId),w=Ze(s=>s.newSessionDraft),B=Ze(s=>s.setDraftBootstrapPendingDirectory),y=Ze(s=>s.worktreeMetadata),C=Ze(s=>s.availableWorktrees),k=nt(r),V=l.useMemo(()=>{if(!k)return;const s=C.find(a=>nt(a.path)===k);if(s)return s;for(const a of y.values())if(nt(a.path)===k)return a},[C,k,y]),A=l.useMemo(()=>{if(m)return y.get(m)??V;if(w?.open)return V},[m,V,w?.open,y]),{profiles:I,globalIdentity:d,defaultGitIdentityId:E,loadProfiles:R,loadGlobalIdentity:O,loadDefaultGitIdentityId:N}=Va(ar(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),P=sa(r??null),g=ra(r??null),U=na(s=>m?s.getAttachment(m):void 0),Y=U?aa(U):[],S=U&&!U.degraded&&!U.legacy?U.worktreeRoot??void 0:void 0,F=va(r,A,g?.current??void 0),J=ia(r??null),H=oa(r??null),G=la(r??null),Z=ca(r??null),Q=da(r??null),{setActiveDirectory:se,fetchAll:ce,ensureAll:oe,fetchStatus:h,fetchBranches:L,fetchLog:T,setLogMaxCount:u,fetchIdentity:M,prefetchDiffs:$,clearDiffCache:ae,moveStatusPathsOptimistically:ie,restoreStatus:ee,bumpIndexRevision:_}=ua(ar(s=>({setActiveDirectory:s.setActiveDirectory,fetchAll:s.fetchAll,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision}))),be=xt(s=>s.isMobile),te=xt(s=>s.openContextDiff),de=xt(s=>s.openContextSurface),ve=g?.current??null,ue=ma(s=>!r||!ve?null:ha(s.entries,r,ve)),he=xt(s=>s.navigateToDiff),me=l.useRef(null),le=l.useRef(null),De=l.useRef(null),je=l.useRef(null),ge=l.useRef(!0);l.useEffect(()=>()=>{ge.current=!1},[]);const Ve=l.useCallback(()=>{le.current!==null&&(window.clearTimeout(le.current),le.current=null)},[]),Me=l.useCallback(s=>{Ve(),le.current=window.setTimeout(()=>{le.current=null,nt(s)===nt(r)&&h(s,n,{silent:!0})},bi)},[Ve,r,h,n]);l.useEffect(()=>Ve,[Ve]);const Ee=l.useCallback(()=>{De.current!==null&&(window.clearTimeout(De.current),De.current=null)},[]),Ie=l.useCallback(()=>{De.current===null&&(De.current=window.setTimeout(()=>{De.current=null,je.current?.()},0))},[]),Le=l.useCallback(async(s,a,o)=>{if(a==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,o);return}await Promise.all(o.map(c=>n.stageGitFile(s,c)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,o);return}await Promise.all(o.map(c=>n.unstageGitFile(s,c)))},[n]),fe=l.useMemo(()=>yi({runMutation:({directory:s,direction:a,paths:o})=>Le(s,a,o),onMutationComplete:({directory:s})=>{_(s),Me(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),_(s),Me(s);const j=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:j)},onPathsComplete:s=>{As(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ie}),[_,Le,Ie,Me,e]);l.useEffect(()=>(je.current=fe.flush,()=>{je.current=null}),[fe]),l.useEffect(()=>()=>fe.clear(),[fe]),l.useEffect(()=>Ee,[Ee]),l.useEffect(()=>{if(!i)return;if(!r){f(null),p(!1);return}let s=!1,a=null;const o=async()=>{try{const c=await ba(r);if(s)return;f(c.status),c.status==="pending"&&(a=window.setTimeout(()=>{o()},500))}catch{s||f(null)}};return o(),()=>{s=!0,a!==null&&window.clearTimeout(a)}},[i,r]),l.useEffect(()=>{const s=me.current;me.current=v,!(!r||!n)&&(s==="pending"&&v==="ready"&&(p(!0),ce(r,n).finally(()=>{window.setTimeout(()=>{p(!1)},1200)})),v==="failed"&&(B(null),p(!1)))},[r,ce,n,B,v]);const X=nt(w?.bootstrapPendingDirectory??null),Pe=!!(r&&X&&X===nt(r)),ze=!!(r&&(v==="pending"||Pe))||x,Fe=l.useMemo(()=>r?vt.get(r)??null:null,[r]),pe=ga(s=>s.settingsGitmojiEnabled),[Ce,Ge]=l.useState(null),{gitmojis:Ne}=Ea(pe);l.useEffect(()=>{const s=S||F?.projectDirectory;if(!s){Ge(null);return}let a=!1;return fa(s).then(o=>{if(a)return;const c=o.trim();Ge(c&&c!=="HEAD"?c:null)}).catch(()=>{a||Ge(null)}),()=>{a=!0}},[S,F?.projectDirectory]);const[Be,q]=l.useState(Fe?.commitMessage??""),[xe,Se]=l.useState([]),[we,ye]=l.useState(!1),_e=l.useRef(null),[tt,st]=l.useState(null),[Cr,Qt]=l.useState(!1),[Ts,Ds]=l.useState(null),[Je,Nr]=l.useState(25),[Sr,Es]=l.useState(!1),{triggerFireworks:kr}=ja(),Ls=l.useRef(new Map),Pt=l.useRef(0),Xt=l.useCallback(()=>{Pt.current+=1,ge.current&&Es(!0)},[]),Zt=l.useCallback(()=>{Pt.current=Math.max(0,Pt.current-1),ge.current&&Pt.current===0&&Es(!1)},[]),[es,Ft]=l.useState(new Set),[Vr,As]=l.useState(new Set),[ts,Os]=l.useState(!1),[Ir,Pr]=l.useState(0),[Fr,zs]=l.useState(!1),[ss,Gs]=l.useState(Fe?.generatedHighlights??[]),Rr=Vr.size>0||fe.size()>0||fe.isRunning(),_s=l.useCallback(()=>{const s=_e.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),rs=S||F?.projectDirectory||null,ns=g?.current||null,Mr=l.useMemo(()=>{const s=g?.tracking;return s?s.startsWith("origin/"):!0},[g?.tracking]),$s=l.useMemo(()=>{const s=F?.createdFromBranch,a=typeof s=="string"?s.trim():"",o=typeof g?.current=="string"?g.current.trim():"",c=typeof Ce=="string"?Ce.trim():"";return a?a===o&&a.startsWith("opencode/")&&c.length>0&&c!==a?c:a:c||o||"HEAD"},[F?.createdFromBranch,g,Ce]),Rt=l.useCallback(()=>{Gs([])},[]),[as,Br]=l.useState(new Set),[Mt,Tr]=l.useState(new Map),[Bt,is]=l.useState(new Set),os=l.useRef(Mt),Nt=l.useRef(Bt),[Dr,yt]=l.useState(null),[ft,ls]=l.useState(null),[Hs,Ws]=l.useState(""),[Ae,Tt]=l.useState(null),[Er,Us]=l.useState(!1),[Lr,Ks]=l.useState(!1),[cs,ds]=l.useState([]),[Ar,Js]=l.useState(null),[qs,us]=l.useState(null),[Or,Dt]=l.useState([]),[zr,qe]=l.useState(!1),[Gr,Qe]=l.useState([]),[Et,Xe]=l.useState("merge"),[_r,ms]=l.useState(null),[hs,Ys]=l.useState(!1),[gs,$r]=l.useState(100),[Hr,Wr]=l.useState(0),Ye=l.useMemo(()=>m?`openchamber.conflict:${m}`:null,[m]),rt=l.useCallback((s,a,o)=>{if(!Ye||typeof window>"u")return;const c={directory:s,conflictFiles:a,operation:o};window.localStorage.setItem(Ye,JSON.stringify(c))},[Ye]),We=l.useCallback(()=>{!Ye||typeof window>"u"||window.localStorage.removeItem(Ye)},[Ye]);l.useEffect(()=>{if(!Ye||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Ye);if(s)try{const a=JSON.parse(s);if(a.directory!==r){window.localStorage.removeItem(Ye);return}Qe(a.conflictFiles??[]),Xe(a.operation??"merge"),qe(!0)}catch{window.localStorage.removeItem(Ye)}},[Ye,r]);const[Ur,fs]=l.useState(!1),[ps,Qs]=l.useState("merge"),[xs,Xs]=l.useState(""),Kr=l.useCallback(s=>{pa(s).then(a=>{if(a.ok){b.success(e("gitView.toast.commitHashCopied"));return}b.error(e("gitView.toast.copyFailed"))})},[e]),Jr=l.useCallback(s=>{Br(a=>{const o=new Set(a);return o.has(s)?o.delete(s):o.add(s),o})},[]);l.useEffect(()=>{os.current=Mt},[Mt]),l.useEffect(()=>{Nt.current=Bt},[Bt]),l.useEffect(()=>{if(!r||!n)return;const s=Array.from(as).filter(o=>!os.current.has(o)&&!Nt.current.has(o));if(s.length===0)return;let a=!1;return is(o=>{const c=new Set(o);for(const j of s)c.add(j);return Nt.current=c,c}),Promise.all(s.map(o=>n.getCommitFiles(r,o).then(c=>({hash:o,files:c.files})).catch(c=>(console.error("Failed to fetch commit files:",c),{hash:o,files:[]})))).then(o=>{a||(Tr(c=>{const j=new Map(c);for(const{hash:z,files:ne}of o)j.set(z,ne);return os.current=j,j}),is(c=>{const j=new Set(c);for(const{hash:z}of o)j.delete(z);return Nt.current=j,j}))}),()=>{a=!0,is(o=>{let c=!1;const j=new Set(o);for(const z of s)j.delete(z)&&(c=!0);return c?(Nt.current=j,j):o})}},[as,r,n]),l.useEffect(()=>{r&&Si(r,{directory:r,commitMessage:Be,generatedHighlights:ss})},[Be,r,ss]),l.useEffect(()=>{i&&(R(),O(),N())},[i,R,O,N]),l.useEffect(()=>{if(!i)return;if(!r||!n?.getRemoteUrl){ls(null);return}let s=!1;return n.getRemoteUrl(r).then(a=>{s||ls(a)}).catch(()=>{s||ls(null)}),()=>{s=!0}},[i,r,n]);const Lt=l.useCallback(async()=>{if(!r||!n?.getRemotes){ds([]);return}try{const s=await n.getRemotes(r);ge.current&&ds(s)}catch{ge.current&&ds([])}},[r,n]);l.useEffect(()=>{i&&Lt()},[i,Lt]),l.useEffect(()=>{i&&r&&(se(r),oe(r,n))},[i,r,se,oe,n]),l.useEffect(()=>{if(i&&r)return xa.onGitRefreshHint(s=>{nt(s.directory)===nt(r)&&(s.paths?.length&&ae(r,s.paths),h(r,n,{silent:!0}))})},[i,ae,r,h,n]);const re=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([h(r,n),L(r,n)])}catch(a){if(s){const o=a instanceof Error?a.message:e("gitView.toast.refreshRepositoryFailed");b.error(o)}}},[r,n,h,L,e]),ke=l.useCallback(async()=>{r&&await T(r,n,Je)},[r,n,T,Je]),ws=l.useCallback(async()=>{r&&await M(r,n)},[r,n,M]);l.useEffect(()=>{if(!i||!r||!n?.hasLocalIdentity||P!==!0)return;const s=typeof E=="string"?E.trim():"";if(!s||s==="global"||Ls.current.get(r)===s)return;let o=!1;return(async()=>{try{const j=await n.hasLocalIdentity?.(r);if(o||j===!0)return;Xt(),await n.setGitIdentity(r,s),Ls.current.set(r,s),await ws()}catch(j){console.warn("Failed to auto-apply default git identity:",j)}finally{o||Zt()}})(),()=>{o=!0}},[i,Xt,r,E,Zt,n,P,ws]);const at=l.useMemo(()=>g?[...g.files??[]].sort((a,o)=>a.path.localeCompare(o.path)):[],[g]),Ue=l.useMemo(()=>at.filter(xr),[at]),ys=l.useMemo(()=>at.filter(ki),[at]);l.useEffect(()=>{if(!r||at.length===0)return;const s=[],a=new Set,o=j=>{!j||a.has(j)||(a.add(j),s.push(j))};if(Ue.forEach(j=>o(j.path)),xe.forEach(o),at.slice(0,ji).forEach(j=>o(j.path)),s.length===0)return;const c=window.setTimeout(()=>{$(r,n,s,{maxFiles:vi})},120);return()=>{window.clearTimeout(c)}},[at,r,n,$,Ue,xe]);const Zs=s=>s?.pushed[0]?.remote||g?.tracking?.split("/")[0]||Ke.find(a=>a.name==="origin")?.name||Ke[0]?.name||"origin",er=async(s,a)=>{if(r){st(s);try{const o=c=>{const j=`${c.name}/`,z=g?.tracking?.startsWith(j)?g.tracking.slice(j.length):void 0;return{remote:c.name,branch:z,rebase:!0}};if(s==="fetch"){if(!a)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:a.name}),b.success(e("gitView.toast.fetchedFromRemote",{name:a.name}))}else if(s==="pull"){if(!a)throw new Error("No remote available for pull");const c=await n.gitPull(r,o(a));b.success(c.files.length===1?e("gitView.toast.pulledFilesSingle",{count:c.files.length,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c.files.length,name:a.name}))}else if(s==="push"){const c=await n.gitPush(r);b.success(e("gitView.toast.pushedToUpstream",{name:Zs(c)}))}else if(s==="sync"){if(!a)throw new Error("No remote available for sync");let c=0,j=!1;await n.gitFetch(r,{remote:a.name});const z=await n.getGitStatus(r);if((z.behind??0)>0){if((z.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync"));return}c=(await n.gitPull(r,o(a))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),j=!0),c>0&&j?b.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:a.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:a.name})):c>0?b.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:a.name})):j?b.success(e("gitView.toast.pushedToUpstream",{name:a.name})):b.success(e("gitView.toast.alreadyUpToDate"))}await re(!1),await ke()}catch(o){const c=o instanceof Error?o.message:e("gitView.toast.syncActionFailed",{action:s==="sync"?e("gitView.sync.syncChanges"):s==="pull"?e("gitView.sync.pull"):s});b.error(c)}finally{st(null)}}},qr=l.useCallback(async s=>{if(!r)return;const a=s.name.trim();if(!a){b.error(e("gitView.toast.remoteNameRequired"));return}if(a==="origin"){b.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Js(a);try{await n.removeRemote(r,{remote:a}),b.success(e("gitView.toast.removedRemote",{name:a})),await Promise.all([re(!1),Lt()])}catch(o){const c=o instanceof Error?o.message:`Failed to remove ${a}`;b.error(c)}finally{Js(null)}},[r,n,Lt,re,e]),tr=async(s={})=>{if(!r)return;if(!Be.trim()){b.error(e("gitView.toast.enterCommitMessage"));return}const a=Ue.map(c=>c.path).sort();if(a.length===0){b.error(e("gitView.toast.stageFileToCommit"));return}const o=s.pushAfter?"commitAndPush":"commit";Ds(o);try{if(await n.createGitCommit(r,Be.trim(),{files:a,stageFiles:[]}),_(r),b.success(e("gitView.toast.commitCreated")),q(""),Rt(),await re(),s.pushAfter){const c=g?.tracking?.split("/")[0],j=Ke.find(Vn=>Vn.name===c)??Ke[0];if(!j)throw new Error(e("mobile.changes.noRemote"));st("sync");const z=`${j.name}/`,ne=g?.tracking?.startsWith(z)?g.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:j.name});const K=await n.getGitStatus(r);if((K.behind??0)>0){if((K.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await re(!1);return}await n.gitPull(r,{remote:j.name,branch:ne,rebase:!0})}const He=await n.getGitStatus(r);let bt;(He.ahead??0)>0&&(bt=await n.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:Zs(bt)})),kr(),await re(!1)}else await re(!1);await ke(),Pr(c=>c+1)}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(j)}finally{Ds(null),s.pushAfter&&st(null)}},Yr=l.useCallback(async()=>{if(!r)return;const s=Ue.map(a=>a.path).sort();if(s.length===0){b.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),zs(!0);try{const{message:a}=await wa(r,s),o=a.subject?.trim()??"",c=Array.isArray(a.highlights)?a.highlights:[];if(o){let j=o;if(pe&&Ne.length>0){const z=Ci(o,Ne);if(z){const{code:ne,emoji:K}=z;!o.startsWith(ne)&&!o.startsWith(K)&&(j=`${ne} ${o}`)}}q(j)}Gs(c),_s()}catch(a){console.error("[git-generation][browser] GitView generate handler failed",{message:a instanceof Error?a.message:String(a),error:a});const o=a instanceof Error?a.message:e("gitView.toast.generateCommitMessageFailed");b.error(o)}finally{zs(!1)}},[r,Ue,pe,Ne,_s,e]),bs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Qr=async(s,a)=>{if(!r||!g)return;const o=Cs(U);if(o.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:bs(o[0])}));return}const c=g.current??null,j=a?.name??"origin";try{await n.createBranch(r,s,c??"HEAD"),b.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(r,s);let z=!1;try{await n.gitPush(r,{remote:j,branch:s,options:["--set-upstream"]}),z=!0}catch(ne){const K=ne instanceof Error?ne.message:`Unable to push new branch to ${j}.`;b.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",K]})})}await re(),await ke(),z&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:j}))}catch(z){const ne=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw b.error(ne),z}},Xr=async(s,a)=>{if(!r)return;const o=Cs(U);if(o.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:bs(o[0])}));return}try{await n.renameBranch(r,s,a),b.success(e("gitView.toast.renamedBranch",{oldName:s,newName:a})),await re(),await ke()}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});b.error(j)}},Zr=async s=>{if(!r)return;const a=Cs(U);if(a.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:bs(a[0])}));return}const o=s.replace(/^remotes\//,"");if(g?.current!==o)try{await n.checkoutBranch(r,o),b.success(e("gitView.toast.checkedOut",{name:o})),await re(),await ke()}catch(c){const j=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});b.error(j)}},en=async s=>{if(r){Xt();try{await n.setGitIdentity(r,s.id),b.success(e("gitView.toast.appliedIdentity",{name:s.name})),await ws()}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.applyIdentityFailed");b.error(o)}finally{Zt()}}},St=l.useMemo(()=>J?.all?J.all.filter(s=>!s.startsWith("remotes/")).sort():[],[J]),it=l.useMemo(()=>J?.all?J.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[J]),Ke=l.useMemo(()=>{if(cs.length>0)return cs;const s=new Set,a=g?.tracking?.trim();a&&a.includes("/")&&s.add(a.split("/")[0]);for(const o of it){const c=o.indexOf("/");c>0&&s.add(o.slice(0,c))}return s.size===0&&ft&&s.add("origin"),Array.from(s).map(o=>({name:o,fetchUrl:ft??"",pushUrl:ft??""}))},[cs,it,ft,g?.tracking]),ot=g?.current??null,sr=l.useMemo(()=>{const s=g?.tracking?.trim().split("/")[0];return(s&&J?.defaultBranches?.[s])??J?.defaultBranches?.origin},[J,g?.tracking]),pt=l.useMemo(()=>Ca({remoteNames:new Set(Ke.map(s=>s.name)),localBranches:St,worktreeCreatedFromBranch:F?.createdFromBranch,rootBranchHint:Ce,defaultBranch:sr,headBranch:ot}),[ot,sr,Ke,St,Ce,F?.createdFromBranch]),tn=l.useMemo(()=>Ke.map(o=>o.name).map(o=>`${o}/${pt}`).find(o=>it.includes(o))??pt,[pt,Ke,it]),sn=l.useMemo(()=>{const s=new Map;d&&s.set(d.id,d);let a=null;if(ft)try{let o=ft.trim();o.startsWith("git@")&&(o=`https://${o.slice(4).replace(":","/")}`),o.endsWith(".git")&&(o=o.slice(0,-4));const c=new URL(o);a=c.hostname+c.pathname}catch{}for(const o of I){if(o.authType!=="token"){s.set(o.id,o);continue}const c=o.host;if(!c){s.set(o.id,o);continue}if(!c.includes("/")){s.set(o.id,o);continue}a&&a===c&&s.set(o.id,o)}return Array.from(s.values())},[I,d,ft]),rn=l.useMemo(()=>{if(G?.userName&&G?.userEmail){const s=I.find(a=>a.userName===G.userName&&a.userEmail===G.userEmail);return s||(d&&d.userName===G.userName&&d.userEmail===G.userEmail?d:{id:"local-config",name:G.userName,userName:G.userName,userEmail:G.userEmail,sshKey:G.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return d??null},[G,I,d]),nn=Ue.length,an=Z||tt!==null||Ts!==null,on=!!(F&&rs&&ns&&Mr),rr=!!ot,lt=on&&rs&&ns&&F?{repoRoot:rs,sourceBranch:ns,worktreeMetadata:F}:null;l.useEffect(()=>{if(!r||!n||!H?.all?.length||!ot||!pt||ot===pt){yt(null);return}let s=!1;return(async()=>{try{const o=await n.getGitLog(r,{from:pt,to:"HEAD",maxCount:Je});if(s)return;const c=new Set((o?.all??[]).map(z=>z.hash).filter(z=>typeof z=="string"&&z.length>0));if(c.size===0){yt(null);return}const j=H.all.findIndex(z=>!c.has(z.hash));if(j===0){yt(null);return}if(j===-1){yt({insertBeforeIndex:H.all.length,branchName:ot,direction:"up"});return}yt({insertBeforeIndex:j,branchName:ot,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[pt,ot,r,n,H,Je]),l.useEffect(()=>{ms(null)},[r]),l.useEffect(()=>{if(Ae!=="graph"||!r){Ae!=="graph"&&ms(null);return}let s=!1;return Ys(!0),n.getGitLog(r,{maxCount:gs,all:!0}).then(a=>{s||ms(a)}).catch(a=>{console.error("Failed to fetch graph log:",a)}).finally(()=>{s||Ys(!1)}),()=>{s=!0}},[Ae,r,gs,Hr,n]);const kt=l.useCallback((s,a)=>{if(!r||s.length===0)return;const o=Array.from(new Set(s));As(j=>{const z=new Set(j);return o.forEach(ne=>z.add(ne)),z});const c=ie(r,o,a);fe.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>ee(r,c)}),Ie()},[r,fe,ie,ee,Ie]),vs=l.useCallback(async s=>{if(r){Ft(a=>{const o=new Set(a);return o.add(s),o});try{await n.revertGitFile(r,s,{scope:"working"}),b.success(e("gitView.toast.revertedFile",{path:s})),await re(!1)}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.revertFailed");b.error(o)}finally{Ft(a=>{const o=new Set(a);return o.delete(s),o})}}},[r,re,n,e]),At=l.useCallback(async(s,a,o="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(ts||c.some(K=>es.has(K)))return;const j=new Set(Ue.map(K=>K.path)),z=o==="all"&&c.some(K=>j.has(K));a&&Os(!0),Ft(K=>{const He=new Set(K);return c.forEach(bt=>He.add(bt)),He});const ne=[];try{if(await Promise.all(c.map(async K=>{try{await n.revertGitFile(r,K,{scope:o})}catch(He){ne.push({path:K,message:He instanceof Error?He.message:e("gitView.toast.revertFailed")})}})),z&&ne.length<c.length&&_(r),await re(!1),ne.length===0)b.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(ne.length===c.length)b.error(ne[0]?.message||e("gitView.toast.revertFailed"));else{const K=c.length-ne.length;b.warning(K===1?e("gitView.toast.revertedSomeSingle",{success:K,failed:ne.length}):e("gitView.toast.revertedSomePlural",{success:K,failed:ne.length}))}}finally{Ft(K=>{const He=new Set(K);return c.forEach(bt=>He.delete(bt)),He}),a&&Os(!1)}},[_,r,n,ts,re,es,Ue,e]),ln=l.useCallback(async s=>{await At(s,!0)},[At]),cn=l.useCallback(async s=>{await At(s,!1,"working")},[At]),js=l.useCallback((s,a)=>{if(r&&!be){te(r,s,a);return}he(s,a)},[r,be,he,te]),dn=l.useCallback(()=>Qt(!0),[]),un=l.useMemo(()=>{const s=[];return Ue.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ue,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:a=>e("gitView.changes.unstageFileAria",{path:a}),onActionFile:a=>{kt([a],"unstage")},onActionAll:a=>{kt(a,"unstage")},onViewDiff:a=>js(a,!0),onRevertFile:vs,showRevertActions:!1,accent:!0}),ys.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:ys,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:a=>e("gitView.changes.stageFileAria",{path:a}),onActionFile:a=>{kt([a],"stage")},onActionAll:a=>{kt(a,"stage")},onViewDiff:a=>js(a,!1),onRevertFile:vs}),s},[vs,js,kt,Ue,e,ys]),mn=l.useCallback(s=>{if(s.length===0)return;const a=s.map(o=>o.trim()).filter(Boolean);if(a.length===0){Rt();return}q(o=>{const c=o.trim(),j=c.length>0?`
4
4
 
@@ -1 +1 @@
1
- import{eY as M,gI as Z,gJ as Fe,gt as Ce,gu as ke,gv as Ie,gw as ze,gC as Ne,gB as Ve,f as Oe,B as ee,I as te,gT as Pe}from"./useAppFontEffects-sHmU5b8u.js";import{b as ie,s as Be,d as Se,e as ne,i as ve,j as De,c as re,k as I,l as Ue,h as _e,g as We,f as je,R as Ge,I as $e,p as se,m as qe,n as Ke,o as Je,r as Ye,w as Xe,t as ae,u as Qe,A as Ze,v as et,x as tt,q as oe,S as it,y as nt,z as rt,B as st,a as ye,C as he,F as at}from"./web-components-BL-Ur2Tb.js";import{G as ot,u as ht,W as lt,a as dt,b as ct,n as le,t as ut}from"./Virtualizer-X_7XPoTH.js";import{j as C,r as k,R as L}from"./vendor-react-BUCujlKS.js";import{n as ft,i as G,f as A,a as pt,o as de,s as gt,j as ce,d as mt,q as ue,b as Ct,t as B,u as fe}from"./computeVirtualFileMetrics-xPena3W2.js";import{a as F,i as K,l as pe,h as St,r as vt}from"./isFilePlainText-DS4QV1dd.js";import{t as H}from"./vendor-hast-util-to-html-BKBhbTDb.js";let yt=-1;var Tt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++yt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:M},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??M)?ft():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&&!K(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??G(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=M,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Be(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||K(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),l=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||l))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||l||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??G(i.name);const d=this.highlighter!=null&&ie(t.theme),u=this.highlighter!=null&&ne(this.computedLang),c=!o&&u;if(this.highlighter!=null&&d&&(n||o||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!u);this.renderCache={file:i,options:f,highlighted:c,result:p,renderRange:void 0}}(!d||!o&&!u)&&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??G(i.name);const t=this.highlighter!=null&&St(pt(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:vt(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(),l=Math.min(e.startingLine+e.totalLines,s);let d=0;const u=ve(e)?De(this.lineAnnotations):void 0;u!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:u.map(c=>I(c))})),d++);for(let c=e.startingLine;c<l;c++){const p=c+1,f=t[c];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:c,lineNumber:p}),new Error(g)}h.children.push(gt("context",p,`${c}`)),o.push(f),d++;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))})),d++)}return h.properties.style=`grid-row: span ${d}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:d,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return Ue({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return H(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,_e(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?H(ce({tagName:"code",children:i,properties:{"data-code":""}})):H(i)}async initializeHighlighter(){return this.highlighter=await mt(We(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 je({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function bt(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 Rt=[""];let Lt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Lt}`;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:M},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Tt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new $e("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&&!Ct(this.appliedThemeCSS.theme,this.options.theme??M)}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),At(this.pre,s,this.options.collapsed)||Mt(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),qe(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):Rt}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:l=!1,themeType:d="system"}=this.options,u=l?void 0:h,c=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(!l&&!n&&Se(u,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(d);this.renderRange=u,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(d),l){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,d,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(c,u)){const v=this.fileRenderer.renderFile(e,u);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,d,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,u),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||K(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||!bt(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=Je();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??=Ye(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Xe(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??M,h=typeof o=="string"?o:{...o},l=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===l){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:l};return}this.themeCSSStyle=Qe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ze(t,a,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=et(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=tt({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=H(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=H(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,l=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,d=Math.max(a,o),u=Math.min(h,l);if(u<=d||!this.trimDOMToOverlap(s.gutter,d,u)||!this.trimDOMToOverlap(s.content,d,u))return!1;let{length:c}=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<d?p(o,d-o):void 0;if(f===void 0&&o<d)return!1;const S=l===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,l-u),g=l>u?p(u,S):void 0;return g===void 0&&l>u?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),c+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),c+=g.rowCount),this.lastRowCount!==c&&(s.gutter.style.setProperty("grid-row",`span ${c}`),s.content.style.setProperty("grid-row",`span ${c}`),this.lastRowCount=c),!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,l)=>h-l),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 l=o[h];if(!(l instanceof HTMLElement))continue;const d=this.getLineIndexFromDOMNode(l);if(d!=null){for(;a!=null&&d>=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??H(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const l=document.createElement("div");l.innerHTML=r;const d=l.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const l=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,l),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const l=s?.(n)??void 0,d=a?.(n)??void 0,u=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,u),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=it;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};nt(s,this.appliedPreAttributes)||(rt(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 At(i,e,t=!1){return!t&&i==null&&e!=null}function Mt(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let xt=-1;function wt(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 Et=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++xt}`;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&&st(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=wt(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=Ft(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 l=this.getLineHeight(a,h);o!==l&&(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 l=h?.lineIndex??0;l<s;l++)r+=this.getLineHeight(l,!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:d}=this.metrics,u=s+(a===0?h:this.renderRange.bufferBefore),c=a+Math.max(Math.ceil((i-u)/d),0);return c>o?void 0:{lineNumber:c+1,top:s+h+c*d}}let l=s+(a===0?h:this.renderRange.bufferBefore);for(let d=a;d<=o;d++){if(l>=i)return{lineNumber:d+1,top:l};l+=this.getLineHeight(d)}}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),l=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 d=0;d<o;d++)this.addLayoutCheckpoint(d,this.height),this.height+=this.getLineHeight(d,!1);if(o>0&&(this.height+=l),this.fileContainer!=null&&e&&!t){const d=this.fileContainer.getBoundingClientRect();d.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:d.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 c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");c.connect(i,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const l=this.virtualizer.getWindowSpecs(),d=this.top??0,u=this.computeRenderRangeFromWindow(this.file,d,l);return super.render({file:this.file,fileContainer:i,renderRange:u,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),l=this.height,d=B(this.metrics,r),u=h>0?fe(this.metrics):0,{fileAnnotationHeight:c}=this.cache,p=d+c,f=Math.max(0,l-d-c-u),S=he(this.lineAnnotations),g=e+d,y=c>0&&S&&g<n&&g+c>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};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:l-d-u};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:c+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,V,O,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&&(V??=w),T+b>D&&(O??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(V==null)if(y)V=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};O??=V;const W=Math.round(O-z/2),Le=Math.max(0,Math.ceil(h/a)-z),j=Math.max(0,Math.min(W,Le)),J=j*a,Y=W<0?v+W*a:v,Ae=N[j]??0,Me=J===0?0:c+Ae,X=j+Y/a,He=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:Me,bufferAfter:Math.max(0,He)}}};function Ft(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===at&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function kt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const l=e?.(i),d=t?.(i),u=n?.(i),c=r?.(i);return C.jsxs(C.Fragment,{children:[l!=null?C.jsx("div",{slot:Ce,children:l}):C.jsxs(C.Fragment,{children:[d!=null&&C.jsx("div",{slot:"header-prefix",children:d}),u!=null&&C.jsx("div",{slot:"header-filename-suffix",children:u}),c!=null&&C.jsx("div",{slot:"header-metadata",children:c})]}),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:ot,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function It({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:l}){const d=ht(),u=n!==void 0,c=k.useContext(lt),p=dt(),f=k.useRef(null),S=ct(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");d!=null?f.current=new Et(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),d,s,h?void 0:c,!0):f.current=new Te(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:c,!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=q({controlledSelection:u,contentEditable:l,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(l&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[l,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function q({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:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,prerenderedHTML:c,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=It({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:c,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Ve,{ref:g,className:s,style:a,children:ut(kt({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),c)})}const Wt=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const{t:s}=Oe(),a=L.useRef(null),[o,h]=L.useState(null),l=L.useMemo(()=>{try{const c=e.trim();if(!c)return h(s("jsonTreeView.error.emptyJson")),null;const p=JSON.parse(c);return h(null),p}catch(c){return h(c instanceof Error?c.message:s("jsonTreeView.error.invalidJson")),null}},[e,s]),d=L.useCallback(()=>{a.current?.expandAll()},[]),u=L.useCallback(()=>{a.current?.collapseAll()},[]);return o?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:s("jsonTreeView.error.invalidJsonTitle")}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:o})]})}):l===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"}),s("jsonTreeView.actions.expandAll")]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:u,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),s("jsonTreeView.actions.collapseAll")]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Pe,{ref:a,data:l,maxHeight:n,initiallyExpandedDepth:r})})]})});export{_t as F,Wt as J};
1
+ import{eY as M,gI as Z,gJ as Fe,gt as Ce,gu as ke,gv as Ie,gw as ze,gC as Ne,gB as Ve,f as Oe,B as ee,I as te,gT as Pe}from"./useAppFontEffects-BikB6enL.js";import{b as ie,s as Be,d as Se,e as ne,i as ve,j as De,c as re,k as I,l as Ue,h as _e,g as We,f as je,R as Ge,I as $e,p as se,m as qe,n as Ke,o as Je,r as Ye,w as Xe,t as ae,u as Qe,A as Ze,v as et,x as tt,q as oe,S as it,y as nt,z as rt,B as st,a as ye,C as he,F as at}from"./web-components-GMc3oR3i.js";import{G as ot,u as ht,W as lt,a as dt,b as ct,n as le,t as ut}from"./Virtualizer-X_7XPoTH.js";import{j as C,r as k,R as L}from"./vendor-react-BUCujlKS.js";import{n as ft,i as G,f as A,a as pt,o as de,s as gt,j as ce,d as mt,q as ue,b as Ct,t as B,u as fe}from"./computeVirtualFileMetrics-Da00Jg7M.js";import{a as F,i as K,l as pe,h as St,r as vt}from"./isFilePlainText-gTibdNIe.js";import{t as H}from"./vendor-hast-util-to-html-BKBhbTDb.js";let yt=-1;var Tt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++yt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:M},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??M)?ft():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&&!K(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??G(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=M,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Be(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||K(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),l=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||l))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||l||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??G(i.name);const d=this.highlighter!=null&&ie(t.theme),u=this.highlighter!=null&&ne(this.computedLang),c=!o&&u;if(this.highlighter!=null&&d&&(n||o||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!u);this.renderCache={file:i,options:f,highlighted:c,result:p,renderRange:void 0}}(!d||!o&&!u)&&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??G(i.name);const t=this.highlighter!=null&&St(pt(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:vt(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(),l=Math.min(e.startingLine+e.totalLines,s);let d=0;const u=ve(e)?De(this.lineAnnotations):void 0;u!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:u.map(c=>I(c))})),d++);for(let c=e.startingLine;c<l;c++){const p=c+1,f=t[c];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:c,lineNumber:p}),new Error(g)}h.children.push(gt("context",p,`${c}`)),o.push(f),d++;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))})),d++)}return h.properties.style=`grid-row: span ${d}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:d,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return Ue({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return H(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,_e(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?H(ce({tagName:"code",children:i,properties:{"data-code":""}})):H(i)}async initializeHighlighter(){return this.highlighter=await mt(We(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 je({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function bt(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 Rt=[""];let Lt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Lt}`;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:M},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Tt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new $e("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&&!Ct(this.appliedThemeCSS.theme,this.options.theme??M)}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),At(this.pre,s,this.options.collapsed)||Mt(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),qe(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):Rt}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:l=!1,themeType:d="system"}=this.options,u=l?void 0:h,c=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(!l&&!n&&Se(u,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(d);this.renderRange=u,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(d),l){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,d,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(c,u)){const v=this.fileRenderer.renderFile(e,u);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,d,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,u),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||K(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||!bt(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=Je();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??=Ye(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Xe(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??M,h=typeof o=="string"?o:{...o},l=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===l){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:l};return}this.themeCSSStyle=Qe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ze(t,a,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=et(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=tt({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=H(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=H(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,l=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,d=Math.max(a,o),u=Math.min(h,l);if(u<=d||!this.trimDOMToOverlap(s.gutter,d,u)||!this.trimDOMToOverlap(s.content,d,u))return!1;let{length:c}=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<d?p(o,d-o):void 0;if(f===void 0&&o<d)return!1;const S=l===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,l-u),g=l>u?p(u,S):void 0;return g===void 0&&l>u?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),c+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),c+=g.rowCount),this.lastRowCount!==c&&(s.gutter.style.setProperty("grid-row",`span ${c}`),s.content.style.setProperty("grid-row",`span ${c}`),this.lastRowCount=c),!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,l)=>h-l),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 l=o[h];if(!(l instanceof HTMLElement))continue;const d=this.getLineIndexFromDOMNode(l);if(d!=null){for(;a!=null&&d>=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??H(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const l=document.createElement("div");l.innerHTML=r;const d=l.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const l=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,l),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const l=s?.(n)??void 0,d=a?.(n)??void 0,u=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,u),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=it;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};nt(s,this.appliedPreAttributes)||(rt(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 At(i,e,t=!1){return!t&&i==null&&e!=null}function Mt(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let xt=-1;function wt(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 Et=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++xt}`;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&&st(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=wt(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=Ft(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 l=this.getLineHeight(a,h);o!==l&&(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 l=h?.lineIndex??0;l<s;l++)r+=this.getLineHeight(l,!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:d}=this.metrics,u=s+(a===0?h:this.renderRange.bufferBefore),c=a+Math.max(Math.ceil((i-u)/d),0);return c>o?void 0:{lineNumber:c+1,top:s+h+c*d}}let l=s+(a===0?h:this.renderRange.bufferBefore);for(let d=a;d<=o;d++){if(l>=i)return{lineNumber:d+1,top:l};l+=this.getLineHeight(d)}}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),l=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 d=0;d<o;d++)this.addLayoutCheckpoint(d,this.height),this.height+=this.getLineHeight(d,!1);if(o>0&&(this.height+=l),this.fileContainer!=null&&e&&!t){const d=this.fileContainer.getBoundingClientRect();d.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:d.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 c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");c.connect(i,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const l=this.virtualizer.getWindowSpecs(),d=this.top??0,u=this.computeRenderRangeFromWindow(this.file,d,l);return super.render({file:this.file,fileContainer:i,renderRange:u,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),l=this.height,d=B(this.metrics,r),u=h>0?fe(this.metrics):0,{fileAnnotationHeight:c}=this.cache,p=d+c,f=Math.max(0,l-d-c-u),S=he(this.lineAnnotations),g=e+d,y=c>0&&S&&g<n&&g+c>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};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:l-d-u};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:c+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,V,O,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&&(V??=w),T+b>D&&(O??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(V==null)if(y)V=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};O??=V;const W=Math.round(O-z/2),Le=Math.max(0,Math.ceil(h/a)-z),j=Math.max(0,Math.min(W,Le)),J=j*a,Y=W<0?v+W*a:v,Ae=N[j]??0,Me=J===0?0:c+Ae,X=j+Y/a,He=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:Me,bufferAfter:Math.max(0,He)}}};function Ft(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===at&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function kt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const l=e?.(i),d=t?.(i),u=n?.(i),c=r?.(i);return C.jsxs(C.Fragment,{children:[l!=null?C.jsx("div",{slot:Ce,children:l}):C.jsxs(C.Fragment,{children:[d!=null&&C.jsx("div",{slot:"header-prefix",children:d}),u!=null&&C.jsx("div",{slot:"header-filename-suffix",children:u}),c!=null&&C.jsx("div",{slot:"header-metadata",children:c})]}),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:ot,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function It({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:l}){const d=ht(),u=n!==void 0,c=k.useContext(lt),p=dt(),f=k.useRef(null),S=ct(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");d!=null?f.current=new Et(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),d,s,h?void 0:c,!0):f.current=new Te(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:c,!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=q({controlledSelection:u,contentEditable:l,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(l&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[l,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function q({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:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,prerenderedHTML:c,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=It({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:c,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Ve,{ref:g,className:s,style:a,children:ut(kt({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),c)})}const Wt=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const{t:s}=Oe(),a=L.useRef(null),[o,h]=L.useState(null),l=L.useMemo(()=>{try{const c=e.trim();if(!c)return h(s("jsonTreeView.error.emptyJson")),null;const p=JSON.parse(c);return h(null),p}catch(c){return h(c instanceof Error?c.message:s("jsonTreeView.error.invalidJson")),null}},[e,s]),d=L.useCallback(()=>{a.current?.expandAll()},[]),u=L.useCallback(()=>{a.current?.collapseAll()},[]);return o?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:s("jsonTreeView.error.invalidJsonTitle")}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:o})]})}):l===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"}),s("jsonTreeView.actions.expandAll")]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:u,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),s("jsonTreeView.actions.collapseAll")]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Pe,{ref:a,data:l,maxHeight:n,initiallyExpandedDepth:r})})]})});export{_t as F,Wt as J};
@@ -0,0 +1 @@
1
+ import{f as B,R as h,j as P}from"./vendor-react-BUCujlKS.js";import{toast as H}from"./vendor-sonner-DFyL3AvE.js";import{f7 as K,f4 as J,a0 as Q,f as Z,I as W}from"./useAppFontEffects-BikB6enL.js";import{r as G,T as Y,C as ee,e as te,cQ as re,cR as oe,aG as ae}from"./index-DRpChWux.js";import{extractMarkdownImageCandidates as se,MAX_MARKDOWN_IMAGE_COUNT as ne}from"./markdownCore-DDrHVneM.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-B-bSg3P5.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CLHw8NWn.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const L=10*1024*1024,ie=1024,le=3e4,ce=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,$=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},me=r=>{let e=r;if(/^file:\/\//i.test(e))try{const o=new URL(e);if(o.protocol!=="file:")return"";e=o.host&&o.host!=="localhost"?`//${o.host}${o.pathname}`:o.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const t=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(t)}catch{return t}},ue=r=>new Promise((e,t)=>{const o=new FileReader;o.onload=()=>{typeof o.result=="string"?e(o.result):t(new Error("Unable to encode image"))},o.onerror=()=>t(o.error??new Error("Unable to encode image")),o.readAsDataURL(r)}),pe=async(r,e)=>{const t=new Uint8Array(await r.slice(0,12).arrayBuffer()),o=(n,u)=>String.fromCharCode(...t.slice(n,u));switch(e){case"image/png":return t[0]===137&&o(1,4)==="PNG"&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10;case"image/jpeg":return t[0]===255&&t[1]===216&&t[2]===255;case"image/gif":{const n=o(0,6);return n==="GIF87a"||n==="GIF89a"}case"image/webp":return o(0,4)==="RIFF"&&o(8,12)==="WEBP";default:return!1}},V=async(r,e)=>{if(!ce.has(e))throw new Error("Unsupported image type");if(r.size>L)throw new Error("Image is too large");if(!await pe(r,e))throw new Error("Unsupported image data")},fe=async r=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(r);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil(L*4/3)+4)throw new Error("Image is too large");let t;try{t=atob(e[2])}catch{throw new Error("Invalid image data URL")}const o=Uint8Array.from(t,n=>n.charCodeAt(0));await V(new Blob([o]),e[1].toLowerCase())},q=r=>!/^(?:https?:)?\/\//i.test(r)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r),de=async({sources:r,directory:e,sessionId:t,messageId:o,signal:n})=>{const u=Y();let s=z.get(u);s||(s=new Map,z.set(u,s));const c=`${t}\0${o}\0${e}\0${r.join("\0")}`,i=s.get(c);if(i&&i.expiresAt>Date.now())return s.delete(c),s.set(c,i),i.result;i&&s.delete(c);const p=await G(`/api/openchamber/sessions/${encodeURIComponent(t)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:o,sources:r}),signal:n});if(!p.ok)throw new Error(`Unable to prepare images (${p.status})`);const m=await p.json(),l=new Map;for(const a of m.results??[])a.source&&(a.status==="ready"&&a.path?l.set(a.source,{status:"ready",path:a.path,outsideFileGrant:a.outsideFileGrant,expiresAt:a.expiresAt}):a.status==="missing"?l.set(a.source,{status:"missing"}):l.set(a.source,{status:"error"}));for(const a of r)l.has(a)||l.set(a,{status:"error"});for(;s.size>=ie;)s.delete(s.keys().next().value);const w=[...l.values()].every(a=>a.status==="ready"),y=Math.min(...[...l.values()].filter(a=>a.status==="ready").map(a=>a.expiresAt??Number.POSITIVE_INFINITY));return s.set(c,{result:l,expiresAt:w?y:Date.now()+le}),l},ge=async(r,e)=>{if($(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await fe(r),$(e),r;throw new Error("Local image has not been prepared")},he=async(r,e,t)=>{$(t);const o=me(r),n=K(e,o);if(!e||!o||!J(n,e))throw new Error("Image path is outside the active workspace");const u=await G("/api/fs/stat",{query:{path:n,directory:e,optional:"true"},signal:t});if(!u.ok)throw new Error(`Unable to inspect image (${u.status})`);const s=await u.json();if(!s.isFile)throw new Error("Image path is not a file");if(typeof s.size=="number"&&s.size>L)throw new Error("Image is too large");const c=await G("/api/fs/raw",{query:{path:n,directory:e},signal:t});if(!c.ok)throw new Error(`Unable to load image (${c.status})`);const i=(c.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",p=Number(c.headers.get("content-length"));if(Number.isFinite(p)&&p>L)throw new Error("Image is too large");const m=await c.blob();return await V(m,i),$(t),ue(m)},we=(r,e)=>Y().authenticatedAsset("/api/fs/raw",{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),be=r=>{const e=B.c(7),[t,o]=h.useState(!1),[n,u]=h.useState(0);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=te(),e[0]=s):s=e[0];const c=s;let i,p;e[1]!==r?(i=()=>{if(!r){o(!1);return}let w=!1,y;const a=re(c),g=oe(()=>{w||u(Ie)}),I=()=>{ae(c).then(()=>{w||o(!0)}).catch(()=>{w||(y=setTimeout(I,1e3))})};return I(),()=>{w=!0,y&&clearTimeout(y),a(),g()}},p=[c,r],e[1]=r,e[2]=i,e[3]=p):(i=e[2],p=e[3]),h.useEffect(i,p);const m=!r||t;let l;return e[4]!==n||e[5]!==m?(l={ready:m,nonce:n},e[4]=n,e[5]=m,e[6]=l):l=e[6],l},ye=r=>{const e=B.c(46),{candidate:t,preparation:o,directory:n,assetAuthReady:u,assetAuthNonce:s,useWorkspaceFsBridge:c,onShowPopup:i}=r,{t:p}=Z(),m=h.useRef(null),[l,w]=h.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={url:"",status:"loading"},e[0]=y):y=e[0];const[a,g]=h.useState(y);let I;e[1]!==t.source?(I=q(t.source),e[1]=t.source,e[2]=I):I=e[2];const b=I;let x,f;e[3]!==l?(x=()=>{const N=m.current;if(!N||l)return;if(typeof IntersectionObserver>"u"){w(!0);return}const E=new IntersectionObserver(T=>{T.some(Ee)&&(w(!0),E.disconnect())},{rootMargin:"200px"});return E.observe(N),()=>E.disconnect()},f=[l],e[3]=l,e[4]=x,e[5]=f):(x=e[4],f=e[5]),h.useEffect(x,f);let v;e[6]!==u||e[7]!==t.source||e[8]!==n||e[9]!==b||e[10]!==o||e[11]!==l||e[12]!==c?(v=()=>{if(!l||b&&!c&&!o)return;if(b&&c){const E=new AbortController;return g({url:"",status:"loading"}),he(t.source,n,E.signal).then(T=>{E.signal.aborted||g({url:T,status:"loading"})}).catch(()=>{E.signal.aborted||g({url:"",status:"error"})}),()=>E.abort()}if(b){if(o?.status!=="ready"){g({url:"",status:"error"});return}if(!u)return;g({url:we(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),ge(t.source,N.signal).then(E=>{N.signal.aborted||g({url:E,status:"loading"})}).catch(()=>{N.signal.aborted||g({url:"",status:"error"})}),()=>N.abort()},e[6]=u,e[7]=t.source,e[8]=n,e[9]=b,e[10]=o,e[11]=l,e[12]=c,e[13]=v):v=e[13];let R;e[14]!==s||e[15]!==u||e[16]!==t.source||e[17]!==n||e[18]!==b||e[19]!==o||e[20]!==l||e[21]!==c?(R=[s,u,t.source,n,b,o,l,c],e[14]=s,e[15]=u,e[16]=t.source,e[17]=n,e[18]=b,e[19]=o,e[20]=l,e[21]=c,e[22]=R):R=e[22],h.useEffect(v,R);let k;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(k=()=>{if(a.status==="error"){H.error(p("filesView.error.previewUnavailable"));return}a.status!=="ready"||!i||i({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:a.url,filename:t.filename}})},e[23]=t.filename,e[24]=a.status,e[25]=a.url,e[26]=i,e[27]=p,e[28]=k):k=e[28];const U=k,j=a.status==="loading";let A;e[29]!==t.filename||e[30]!==a.status||e[31]!==a.url?(A=P.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:a.url&&a.status!=="error"?P.jsx("img",{src:a.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>g(Ae),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(W,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=A):A=e[32];let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=P.jsx(W,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=_):_=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let C;e[36]!==t.filename||e[37]!==S?(C=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[_,S]}),e[36]=t.filename,e[37]=S,e[38]=C):C=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==C||e[43]!==j||e[44]!==A?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:j,onClick:U,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[A,C]}),e[39]=t.filename,e[40]=t.source,e[41]=U,e[42]=C,e[43]=j,e[44]=A,e[45]=M):M=e[45],M},ir=r=>{const e=B.c(34),{sessionId:t,messageId:o,contents:n,onShowPopup:u}=r,s=Q()??"",c=h.useRef(null),[i,p]=h.useState(!1),[m,l]=h.useState(null),[w,y]=h.useState(0);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ee(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=se(n,ne),e[1]=n,e[2]=I):I=e[2];const b=I;let x;e[3]!==b?(x=g?[]:b.filter(xe).map(ve),e[3]=b,e[4]=x):x=e[4];const f=x;let v,R;e[5]!==f.length||e[6]!==i?(v=()=>{if(f.length===0||i)return;const d=c.current;if(!d||typeof IntersectionObserver>"u"){p(!0);return}const F=new IntersectionObserver(X=>{X.some(Re)&&(p(!0),F.disconnect())},{rootMargin:"200px"});return F.observe(d),()=>F.disconnect()},R=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=R):(v=e[7],R=e[8]),h.useEffect(v,R);let k;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(k=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return de({sources:f,directory:s,sessionId:t,messageId:o,signal:d.signal}).then(F=>{d.signal.aborted||l(F)}).catch(()=>{d.signal.aborted||l(new Map(f.map(ke)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=k):k=e[14];let U;e[15]!==s||e[16]!==o||e[17]!==w||e[18]!==f||e[19]!==t||e[20]!==i?(U=[s,o,w,f,t,i],e[15]=s,e[16]=o,e[17]=w,e[18]=f,e[19]=t,e[20]=i,e[21]=U):U=e[21],h.useEffect(k,U);let j,A;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(_e).map(Se));if(!Number.isFinite(d))return;const F=setTimeout(()=>y(Me),Math.max(0,d-Date.now()));return()=>clearTimeout(F)},A=[m],e[22]=m,e[23]=j,e[24]=A):(j=e[23],A=e[24]),h.useEffect(j,A);let _;e[25]!==m?(_=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=_):_=e[26];const S=b.filter(_),C=[...m?.values()??[]].some(Ne),M=be(C);if(S.length===0)return null;const N="mt-3 flex max-w-full gap-2 overflow-x-auto pb-1",E="true";let T;e[27]!==M||e[28]!==s||e[29]!==u||e[30]!==m?(T=d=>P.jsx(ye,{candidate:d,preparation:m?.get(d.source),directory:s,assetAuthReady:M.ready,assetAuthNonce:M.nonce,useWorkspaceFsBridge:g,onShowPopup:u},d.source),e[27]=M,e[28]=s,e[29]=u,e[30]=m,e[31]=T):T=e[31];const D=S.map(T);let O;return e[32]!==D?(O=P.jsx("div",{ref:c,className:N,"data-openchamber-markdown-image-gallery":E,children:D}),e[32]=D,e[33]=O):O=e[33],O};function Ie(r){return r+1}function Ee(r){return r.isIntersecting}function Ae(r){return{...r,status:"ready"}}function xe(r){return q(r.source)}function ve(r){return r.source}function Re(r){return r.isIntersecting}function ke(r){return[r,{status:"error"}]}function _e(r){return r.status==="ready"}function Se(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Me(r){return r+1}function Ne(r){return r.status==="ready"}export{ir as MarkdownImageGallery};