@openchamber/web 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
  8. package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
  9. package/dist/assets/DiffView-6xGdyI0n.js +4 -0
  10. package/dist/assets/FilesView-Bm3vT63N.js +17 -0
  11. package/dist/assets/GitView-B6y1Y69c.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-rwHz84MX.js} +1 -1
  13. package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
  14. package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
  16. package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
  17. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
  19. package/dist/assets/PlanView-BFMsnHk3.js +5 -0
  20. package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
  21. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
  22. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
  23. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
  24. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
  25. package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
  26. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
  27. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
  28. package/dist/assets/de-C3luvSd_.js +9 -0
  29. package/dist/assets/es-CmU4HLv9.js +15 -0
  30. package/dist/assets/fr-Bgyni40l.js +13 -0
  31. package/dist/assets/index-C57jT0Sa.css +1 -0
  32. package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
  33. package/dist/assets/index-b0zDkWyg.js +7 -0
  34. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
  35. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
  36. package/dist/assets/ja-C1ImKinT.js +15 -0
  37. package/dist/assets/ko-CP7OdxYH.js +15 -0
  38. package/dist/assets/main-D4rd8Hy5.js +928 -0
  39. package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
  40. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  41. package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
  42. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
  43. package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
  44. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
  45. package/dist/assets/pl-DQYSiGYX.js +15 -0
  46. package/dist/assets/pt-BR-DytpsW4M.js +15 -0
  47. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
  48. package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
  49. package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
  50. package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
  51. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
  52. package/dist/assets/tr-aizaUvft.js +6 -0
  53. package/dist/assets/uk-DwnRxJZd.js +15 -0
  54. package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
  55. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
  56. package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
  57. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
  59. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  62. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  63. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  64. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  65. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  66. package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
  67. package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
  68. package/dist/assets/zh-TW-BsswdYL-.js +15 -0
  69. package/dist/index.html +5 -5
  70. package/dist/mini-chat.html +3 -3
  71. package/dist/mobile.html +3 -3
  72. package/dist/site.webmanifest +1 -1
  73. package/dist/sw.js +1 -1
  74. package/package.json +2 -2
  75. package/public/site.webmanifest +1 -1
  76. package/server/index.js +6 -2
  77. package/server/lib/cloudflare-tunnel.js +1 -1
  78. package/server/lib/dictation/DOCUMENTATION.md +19 -6
  79. package/server/lib/dictation/local/model-catalog.js +220 -0
  80. package/server/lib/dictation/local/model-catalog.test.js +42 -0
  81. package/server/lib/dictation/local/sherpa-tts.js +41 -20
  82. package/server/lib/dictation/local/worker-process.js +2 -0
  83. package/server/lib/dictation/runtime.js +4 -0
  84. package/server/lib/dictation/service.js +27 -4
  85. package/server/lib/fs/DOCUMENTATION.md +5 -0
  86. package/server/lib/fs/routes.js +150 -0
  87. package/server/lib/fs/routes.test.js +308 -3
  88. package/server/lib/git/DOCUMENTATION.md +4 -3
  89. package/server/lib/git/service.js +128 -6
  90. package/server/lib/git/service.test.js +191 -1
  91. package/server/lib/linear/DOCUMENTATION.md +97 -0
  92. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
  93. package/server/lib/linear/auth.js +436 -0
  94. package/server/lib/linear/auth.test.js +242 -0
  95. package/server/lib/linear/client.js +191 -0
  96. package/server/lib/linear/index.js +61 -0
  97. package/server/lib/linear/issues.js +499 -0
  98. package/server/lib/linear/issues.test.js +512 -0
  99. package/server/lib/linear/mapping.js +188 -0
  100. package/server/lib/linear/mapping.test.js +147 -0
  101. package/server/lib/linear/oauth.js +345 -0
  102. package/server/lib/linear/oauth.test.js +166 -0
  103. package/server/lib/linear/parse.js +23 -0
  104. package/server/lib/linear/routes.js +432 -0
  105. package/server/lib/linear/routes.test.js +661 -0
  106. package/server/lib/linear/status-runtime.js +64 -0
  107. package/server/lib/linear/status-runtime.test.js +167 -0
  108. package/server/lib/linear/status.js +280 -0
  109. package/server/lib/linear/status.test.js +271 -0
  110. package/server/lib/linear/teams.js +72 -0
  111. package/server/lib/linear/teams.test.js +94 -0
  112. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  113. package/server/lib/markdown-image-grants/routes.js +3 -1
  114. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  115. package/server/lib/openchamber-sessions/routes.js +4 -1
  116. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  117. package/server/lib/opencode/env-runtime.js +17 -1
  118. package/server/lib/opencode/env-runtime.test.js +56 -0
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  120. package/server/lib/opencode/lifecycle.js +48 -9
  121. package/server/lib/opencode/lifecycle.test.js +125 -1
  122. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  123. package/server/lib/opencode/managed-process-registry.js +213 -163
  124. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  125. package/server/lib/opencode/project-directory-runtime.js +16 -11
  126. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  127. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  128. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  129. package/server/lib/opencode/routes.js +53 -5
  130. package/server/lib/opencode/settings-helpers.js +3 -0
  131. package/server/lib/opencode/settings-helpers.test.js +10 -0
  132. package/server/lib/opencode/static-routes-runtime.js +3 -3
  133. package/server/lib/opencode/theme-runtime.js +1 -1
  134. package/server/lib/opencode/theme-runtime.test.js +129 -0
  135. package/server/lib/projects/project-config.js +33 -5
  136. package/server/lib/projects/project-config.test.js +85 -0
  137. package/server/lib/quota/DOCUMENTATION.md +19 -0
  138. package/server/lib/quota/providers/copilot.js +26 -10
  139. package/server/lib/quota/providers/copilot.test.js +78 -0
  140. package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
  141. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  142. package/server/lib/small-model/call.js +64 -20
  143. package/server/lib/small-model/call.test.js +184 -2
  144. package/server/lib/tts/DOCUMENTATION.md +1 -0
  145. package/server/lib/tts/language-detect.js +210 -0
  146. package/server/lib/tts/language-detect.test.js +76 -0
  147. package/server/lib/tts/routes.js +23 -1
  148. package/server/lib/tts/routes.test.js +26 -0
  149. package/server/lib/tunnels/install-help.js +2 -2
  150. package/server/lib/tunnels/install-help.test.js +9 -0
  151. package/server/lib/walkthrough/languages.js +1 -0
  152. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  153. package/dist/assets/DiffView-D5cvbEPb.js +0 -4
  154. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  155. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  156. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  157. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  158. package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
  159. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  160. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  161. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  162. package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
  163. package/dist/assets/de-B_LdJwEM.js +0 -9
  164. package/dist/assets/es-CubfsAYV.js +0 -15
  165. package/dist/assets/fr-5qJM0nFS.js +0 -13
  166. package/dist/assets/index-BW82eK5v.css +0 -1
  167. package/dist/assets/index-rlLjZUM5.js +0 -7
  168. package/dist/assets/ja-DJYIBUlH.js +0 -15
  169. package/dist/assets/ko-DcUBkB7y.js +0 -15
  170. package/dist/assets/main-DLBxKIoX.js +0 -926
  171. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  172. package/dist/assets/pl-rB6BLcio.js +0 -15
  173. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  174. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  175. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  176. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
  177. package/dist/assets/uk-INZlFD9A.js +0 -15
  178. package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
  179. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  180. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
@@ -0,0 +1,6 @@
1
+ import{R as l,r as be,j as t,f as Ct}from"./vendor-react-BUCujlKS.js";import{f as et,y as Ze,a0 as Rt,hV as Mn,cU as Jt,cf as qt,t as v,I as A,b4 as Bs,b1 as Ds,cS as Nr,b3 as Ms,cx as Es,cy as Ts,cz as As,cA as Ls,cs as Yt,ct as Qt,B as W,hW as En,hX as Tn,bG as ht,bH as gt,bI as ft,bJ as pt,bK as bt,S as dr,a6 as Xt,a7 as Zt,a8 as es,hY as An,h as Ce,hZ as Ln,h_ as On,h$ as zn,i0 as Gn,b0 as _n,am as Hn,bR as $n,i1 as Wn,i2 as Un,i3 as Kn,i4 as Jn,i5 as qn,i6 as Yn,i7 as Qn,c2 as Sr,bU as Xn,bV as Zn,bW as ea,bX as ta,bY as sa,i8 as ra,b$ as na,bL as Rs,eN as aa,V as ia,ab as oa,ac as la,ae as ca,ad as da,bw as ua,i9 as ma,c0 as ha,ia as ga,ib as fa,af as pa,ic as xa,ag as wa,bP as ya,hO as ba,l as va,c1 as ja,g as Ca,cC as Na,al as Sa,a1 as ka,id as Va,ie as Is}from"./useAppFontEffects-DWXGRUPZ.js";import{a as Ia,b as Pa,d as Fa}from"./main-D4rd8Hy5.js";import{x as Ra,w as Ba,v as Da,X as Ma,c as Ea,a0 as Ta}from"./runtimeEndpointReset-HlRmXFGW.js";import{u as ur}from"./vendor-zustand-BAGL70zf.js";import{r as Aa,u as Pt}from"./index-b0zDkWyg.js";import{C as La,a as Oa}from"./CommitSection-CC5mFzO2.js";import{P as za}from"./PierreDiffViewer-Cvz9Z-io.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-BK78t3M_.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-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.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-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.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-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BGFszm8n.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-BLfBSgBh.js";import"./useRootScrollLock-BFZtfciC.js";import"./scheduledTasksApi-BPvxrynl.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-CD-GFayc.js";import"./computeVirtualFileMetrics-DmpLWhll.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-DT5MDv-u.js";import"./isDiffPlainText-BO_q5ezD.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-Cc0OCXr0.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const kr="gitmojiCache",Ga=1e3*60*60*24*7,Vr="1",_a="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Ir=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Ps=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(kr);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(Ir),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Ha=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:Vr};window.localStorage.setItem(kr,JSON.stringify(e))}catch{return}},mr=i=>Date.now()-i.fetchedAt<Ga;let Ut=null;const Ft=new Set,hr=async()=>{if(Ut)return Ut;const i=(async()=>{try{const e=await fetch(_a);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),u=Array.isArray(n.gitmojis)?n.gitmojis.filter(Ir):[];return Ha(u),Ft.forEach(j=>j(u)),u}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Ft.forEach(u=>u(n)),n}finally{Ut=null}})();return Ut=i,i},$a=i=>{const[e,n]=l.useState(()=>i?Ps()?.gitmojis??[]:[]),[u,j]=l.useState(!1),f=l.useRef(i);f.current=i,l.useEffect(()=>{if(!i){Ft.delete(n),n([]),j(!1);return}const p=Ps();if(p&&(n(p.gitmojis),mr(p)))return;Ft.add(n),j(!0);let h=!1;return hr().finally(()=>{!h&&f.current&&j(!1)}),()=>{h=!0,Ft.delete(n)}},[i]);const x=l.useCallback(async()=>{if(!f.current)return[];if(e.length>0)return e;const p=Ps();return p&&mr(p)?p.gitmojis:hr()},[e]);return{gitmojis:e,isLoading:u,ensureLoaded:x}},Nt=async(i,e)=>{const n=await Aa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const u=await n.json().catch(()=>null);throw new Error(u?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function It(i){return Nt("plan",i)}async function Wa(i){return Nt("conflict-details",{tempWorktreePath:i})}async function Ua(i){return(await Nt("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function Ka(i){return Nt("run",{plan:i})}async function Ja(i){await Nt("abort",{state:i})}async function qa(i){return Nt("continue",{state:i})}const Ya=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:u,defaultTargetBranch:j,refreshKey:f,onRefresh:x,showHeader:p=!0})=>{const{t:h}=et(),w=Ze(g=>g.currentSessionId),[E,b]=be.useState(!1),[V,L]=be.useState(""),S=be.useRef(null),O=be.useMemo(()=>Rt(u,V,g=>[g]),[u,V]),[C,y]=be.useState(j);be.useEffect(()=>{y(j)},[j]),be.useEffect(()=>{if(E){const g=setTimeout(()=>{S.current?.focus()},0);return()=>clearTimeout(g)}},[E]);const D=!!(i&&e&&C&&C!=="HEAD"&&e!==C),[k,R]=be.useState({kind:"idle"}),[I,F]=be.useState(!1),[r,Y]=be.useState([]),B=be.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);be.useEffect(()=>{if(!B||typeof window>"u")return;const g=window.localStorage.getItem(B);if(!g)return;let d=!1;try{const P=JSON.parse(g);if(!P?.tempWorktreePath||P.repoRoot!==i){window.localStorage.removeItem(B);return}(async()=>{const M=await Ua(P.tempWorktreePath).catch(()=>!1);if(d)return;if(!M){window.localStorage.removeItem(B);return}const J=await Wa(P.tempWorktreePath).catch(()=>null);d||J&&R({kind:"conflict",state:P,details:J})})()}catch{window.localStorage.removeItem(B)}return()=>{d=!0}},[B,i]),be.useEffect(()=>{if(!D){R({kind:"idle"});return}let g=!1;return R({kind:"loading"}),(async()=>{try{const d=await It({repoRoot:i,sourceBranch:e,targetBranch:C});if(g)return;if(R({kind:"ready",plan:d}),d.commits.length>0){const M=d.commits.slice(-50).reverse(),J=await Mn(i,M);g||(Y(J),F(!1))}else g||(Y([]),F(!1))}catch{g||R({kind:"idle"})}})(),()=>{g=!0}},[D,i,e,C,f]);const m=be.useCallback(g=>{w&&Ze.getState().setWorktreeMetadata(w,{...n,createdFromBranch:g})},[w,n]),T=Ze(g=>g.openNewSessionDraft),ee=be.useCallback(async g=>{const d=await Jt("git.integrate.cherrypick.resolve.visible",{current_commit:g.state.currentCommit,target_branch:g.state.targetBranch}),P=await Jt("git.integrate.cherrypick.resolve.instructions",{repo_root:g.state.repoRoot,temp_worktree_path:g.state.tempWorktreePath,source_branch:g.state.sourceBranch,target_branch:g.state.targetBranch,current_commit:g.state.currentCommit}),M=`Cherry-pick conflict context (JSON)
2
+ ${JSON.stringify({repoRoot:g.state.repoRoot,tempWorktreePath:g.state.tempWorktreePath,sourceBranch:g.state.sourceBranch,targetBranch:g.state.targetBranch,currentCommit:g.state.currentCommit,remainingCommits:g.state.remainingCommits,statusPorcelain:g.details.statusPorcelain,unmergedFiles:g.details.unmergedFiles,currentPatchMeta:g.details.currentPatchMeta,currentPatch:g.details.currentPatch,diff:g.details.diff},null,2)}`;return{visibleText:d,instructionsText:P,payloadText:M}},[]),$=qt(g=>g.setPendingInputText),G=qt(g=>g.setPendingSyntheticParts),_=be.useCallback(async(g,d)=>{const P=await ee(g);if(d){T({directoryOverride:g.state.tempWorktreePath,initialPrompt:P.visibleText,syntheticParts:[{text:P.instructionsText,synthetic:!0},{text:P.payloadText,synthetic:!0}]});return}if(!w){v.error(h("gitView.integrate.noActiveSession"),{description:h("gitView.integrate.noActiveSessionDescription")});return}$(P.visibleText,"replace"),G([{text:P.instructionsText,synthetic:!0},{text:P.payloadText,synthetic:!0}])},[w,ee,T,$,G,h]),Z=be.useCallback(async()=>{if(k.kind==="ready"){if(k.plan.commits.length===0){v.message(h("gitView.integrate.noCommitsToMoveToast"));return}R({kind:"running",plan:k.plan});try{const g=await Ka(k.plan);if(g.kind==="success"){v.success(h("gitView.integrate.commitsMovedToast"),{description:g.moved===1?h("gitView.integrate.commitsMovedDescriptionSingle",{count:g.moved,branch:k.plan.targetBranch}):h("gitView.integrate.commitsMovedDescriptionPlural",{count:g.moved,branch:k.plan.targetBranch})});const d=await It(k.plan);R({kind:"ready",plan:d}),x?.();return}g.kind==="conflict"&&(v.error(h("gitView.integrate.cherryPickConflictToast"),{description:h("gitView.integrate.cherryPickConflictDescription")}),R({kind:"conflict",state:g.state,details:g.details}),B&&typeof window<"u"&&window.localStorage.setItem(B,JSON.stringify(g.state)))}catch(g){const d=g instanceof Error?g.message:String(g);v.error(h("gitView.integrate.failedToMoveToast"),{description:d});const P=await It({repoRoot:i,sourceBranch:e,targetBranch:C}).catch(()=>null);R(P?{kind:"ready",plan:P}:{kind:"idle"})}}},[k,x,i,e,C,B,h]),H=be.useCallback(async()=>{if(k.kind==="conflict")try{await Ja(k.state),v.message(h("gitView.integrate.cherryPickAbortedToast")),B&&typeof window<"u"&&window.localStorage.removeItem(B)}finally{const g=await It({repoRoot:i,sourceBranch:e,targetBranch:C}).catch(()=>null);R(g?{kind:"ready",plan:g}:{kind:"idle"})}},[k,i,e,C,B,h]),ce=be.useCallback(async()=>{if(k.kind==="conflict")try{const g=await qa(k.state);if(g.kind==="success"){v.success(h("gitView.integrate.cherryPickFinishedToast"));const d=await It({repoRoot:i,sourceBranch:e,targetBranch:C}).catch(()=>null);R(d?{kind:"ready",plan:d}:{kind:"idle"}),B&&typeof window<"u"&&window.localStorage.removeItem(B),x?.();return}g.kind==="conflict"&&(R({kind:"conflict",state:g.state,details:g.details}),B&&typeof window<"u"&&window.localStorage.setItem(B,JSON.stringify(g.state)))}catch(g){const d=g instanceof Error?g.message:String(g);v.error(h("gitView.integrate.cherryPickContinueFailedToast"),{description:d})}},[k,i,e,C,x,B,h]);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(A,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:h("gitView.integrate.title")}),k.kind==="ready"&&k.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h("gitView.integrate.toMoveCount",{count:k.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:k.kind==="loading"||k.kind==="running"?t.jsx(A,{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:h("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",C]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Bs,{open:E,onOpenChange:b,children:[t.jsx(Ds,{asChild:!0,children:t.jsxs("button",{type:"button",className:Nr({size:"default"}),children:[h("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:C}),t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Ms,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Es,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ts,{ref:S,placeholder:h("gitView.branch.searchPlaceholder"),value:V,onValueChange:L,onKeyDown:g=>g.stopPropagation()}),t.jsxs(As,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Ls,{children:h("gitView.branch.empty")}),t.jsx(Yt,{heading:h("gitView.branch.localBranches"),children:O.map(g=>t.jsx(Qt,{value:g,onSelect:()=>{y(g),m(g),b(!1),L("")},children:g},g))})]})]})})]}),k.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{Z()},disabled:!D||k.plan.commits.length===0,children:h("gitView.integrate.move")}):k.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.checking")}):k.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:h("gitView.integrate.moving")}):null]}),k.kind==="ready"&&k.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.noCommitsToMove")}),k.kind==="ready"&&k.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:[h("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",k.plan.commits.length,")"]})]}),r.length>0&&k.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>F(g=>!g),className:"typography-micro text-muted-foreground hover:text-foreground",children:h(I?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(I?r:r.slice(0,5)).map(g=>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:g.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:g.subject||g.sha})]},g.sha)),r.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:h("gitView.integrate.previewUnavailable")}),k.plan.commits.length>r.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:h("gitView.integrate.showingFirstCommits",{count:r.length})})]})]}),k.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:h("gitView.integrate.conflictsInFiles",{count:k.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[h("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:k.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[k.details.unmergedFiles.slice(0,6).map(g=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:g},g)),k.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:h("gitView.integrate.moreFiles",{count:k.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:()=>{H()},children:h("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{_({state:k.state,details:k.details},!1)},children:[t.jsx(A,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{_({state:k.state,details:k.details},!0)},children:[t.jsx(A,{name:"sparkling",className:"size-3.5"}),h("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{ce()},children:h("gitView.operation.continue")})]})]})]})]})},Qa=({open:i,onOpenChange:e,directory:n,hasUncommittedChanges:u,hasStagedChanges:j=!1,uncommittedFileCount:f,onChanged:x})=>{const{t:p}=et(),[h,w]=l.useState([]),[E,b]=l.useState(!1),[V,L]=l.useState(""),[S,O]=l.useState(""),[C,y]=l.useState(null),[D,k]=l.useState({}),R=l.useCallback(async()=>{if(n){b(!0);try{const m=await En(n);w(m.stashes),k({})}catch(m){v.error(m instanceof Error?m.message:p("gitView.stashes.toast.loadFailed"))}finally{b(!1)}}},[n,p]);l.useEffect(()=>{i&&R()},[R,i]),l.useEffect(()=>{if(!i||!n||h.length===0)return;let m=!1;const T=h.map(ee=>ee.ref);return Tn(n,T).then(ee=>{m||k(ee.counts)}).catch(()=>{}),()=>{m=!0}},[n,i,h]);const I=l.useMemo(()=>Rt(h,V,m=>[m.message,m.ref,m.relativeTime]),[V,h]),F=l.useCallback(async m=>{await R(),await x?.(m)},[R,x]),r=async()=>{if(!(!n||C)){y("create");try{const m=await An(n,{message:S.trim()||void 0});m.created?(v.success(p("gitView.stashes.toast.created")),O("")):v.info(p("gitView.stashes.toast.noChanges")),await F({affectsIndex:!!(m.created&&j)})}catch(m){v.error(m instanceof Error?m.message:p("gitView.stashes.toast.createFailed"))}finally{y(null)}}},Y=async(m,T)=>{if(!(!n||C)&&!(T==="drop"&&!window.confirm(p("gitView.stashes.confirm.drop",{ref:m.ref})))){y(`${T}:${m.ref}`);try{T==="apply"&&await Ln(n,{ref:m.ref}),T==="pop"&&await On(n,{ref:m.ref}),T==="drop"&&await zn(n,{ref:m.ref});const ee=T==="apply"?"gitView.stashes.toast.applySuccess":T==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";v.success(p(ee)),await F({affectsIndex:T!=="drop"})}catch(ee){const $=T==="apply"?"gitView.stashes.toast.applyFailed":T==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";v.error(ee instanceof Error?ee.message:p($)),await F({affectsIndex:T!=="drop"})}finally{y(null)}}},B=C!==null;return t.jsx(ht,{open:i,onOpenChange:e,children:t.jsxs(gt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ft,{children:[t.jsxs(pt,{className:"flex items-center gap-2",children:[t.jsx(A,{name:"archive-stack",className:"h-5 w-5"}),p("gitView.stashes.title")]}),t.jsx(bt,{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(dr,{value:S,onChange:m=>O(m.target.value),placeholder:p("gitView.stashes.messagePlaceholder"),disabled:B||!u,className:"flex-1"}),t.jsxs(W,{onClick:r,disabled:!u||B||!n,children:[C==="create"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{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(A,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(dr,{value:V,onChange:m=>L(m.target.value),placeholder:p("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:E?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(A,{name:"loader-4",className:"size-5 animate-spin"})}):I.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:p(V?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):I.map((m,T)=>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:m.message||p("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Xt,{children:[t.jsx(Zt,{asChild:!0,children:t.jsx("span",{children:T===0&&!V.trim()?p("gitView.stashes.latestLabel"):p("gitView.stashes.itemNumber",{number:T+1})})}),t.jsx(es,{sideOffset:6,children:m.ref})]})," · ",m.relativeTime," · ",typeof D[m.ref]=="number"?p("gitView.stashes.fileCount",{count:D[m.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(Fs,{label:p("gitView.stashes.actions.apply"),loading:C===`apply:${m.ref}`,onClick:()=>Y(m,"apply"),disabled:B,children:t.jsx(A,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Fs,{label:p("gitView.stashes.actions.pop"),loading:C===`pop:${m.ref}`,onClick:()=>Y(m,"pop"),disabled:B,children:t.jsx(A,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Fs,{label:p("gitView.stashes.actions.drop"),loading:C===`drop:${m.ref}`,onClick:()=>Y(m,"drop"),disabled:B,destructive:!0,children:t.jsx(A,{name:"delete-bin",className:"size-4"})})]})]},m.ref))})]})})},Fs=i=>{const e=Ct.c(17),{label:n,loading:u,disabled:j,destructive:f,onClick:x,children:p}=i,h=u||void 0,w=f?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let E;e[0]!==w?(E=Ce("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",w),e[0]=w,e[1]=E):E=e[1];let b;e[2]!==p||e[3]!==u?(b=u?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):p,e[2]=p,e[3]=u,e[4]=b):b=e[4];let V;e[5]!==j||e[6]!==n||e[7]!==x||e[8]!==h||e[9]!==E||e[10]!==b?(V=t.jsx(Zt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":h,className:E,onClick:x,disabled:j,children:b})}),e[5]=j,e[6]=n,e[7]=x,e[8]=h,e[9]=E,e[10]=b,e[11]=V):V=e[11];let L;e[12]!==n?(L=t.jsx(es,{sideOffset:6,children:n}),e[12]=n,e[13]=L):L=e[13];let S;return e[14]!==V||e[15]!==L?(S=t.jsxs(Xt,{children:[V,L]}),e[14]=V,e[15]=L,e[16]=S):S=e[16],S},Xa=i=>{const e=Ct.c(16),{onOpenStashes:n}=i,{t:u}=et();let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(A,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=j):j=e[0];let f;e[1]!==u?(f=u("gitView.empty.cleanTitle"),e[1]=u,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]!==u?(p=u("gitView.empty.cleanDescription"),e[5]=u,e[6]=p):p=e[6];let h;e[7]!==p?(h=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:p}),e[7]=p,e[8]=h):h=e[8];let w;e[9]!==n||e[10]!==u?(w=n?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(A,{name:"archive-stack",className:"size-4"}),u("gitView.stashes.title")]}):null,e[9]=n,e[10]=u,e[11]=w):w=e[11];let E;return e[12]!==x||e[13]!==h||e[14]!==w?(E=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[j,x,h,w]}),e[12]=x,e[13]=h,e[14]=w,e[15]=E):E=e[15],E},mt=8,Za=i=>{const e=Ct.c(18),{laned:n,totalLanes:u,isExpanded:j}=i,{lane:f,color:x,connectors:p}=n,w=Math.max(u,f+1)*mt+mt/2,E=l.useRef(null),b=l.useRef(null);let V;e[0]!==x||e[1]!==p||e[2]!==f||e[3]!==w?(V=()=>{const y=E.current,D=b.current;if(!y||!D)return;const k=y.offsetHeight;if(k===0)return;const R=window.devicePixelRatio||1;D.width=w*R,D.height=k*R;const I=D.getContext("2d");if(!I)return;I.scale(R,R),I.clearRect(0,0,w,k);const F=k/2,r=f*mt+mt/2,Y=getComputedStyle(D),B=Y.getPropertyValue("--surface-muted-foreground").trim()||Y.color,m=$=>{if(!$.startsWith("var("))return $;const G=$.slice(4,-1).trim();return Y.getPropertyValue(G).trim()||B},T=[...p].sort(ti);for(const $ of T){const G=$.fromLane*mt+mt/2,_=$.toLane*mt+mt/2,Z=$.type==="passing"?.72:$.type==="branch-out"||$.type==="merge-in"?.95:1;I.beginPath(),I.strokeStyle=m($.color),I.globalAlpha=Z,I.lineWidth=1.25,I.lineCap="round";e:switch($.type){case"passing":case"commit-lane":{I.moveTo(G,0),I.lineTo(G,k);break e}case"top-stub":{I.moveTo(G,0),I.lineTo(G,F);break e}case"bottom-stub":{I.moveTo(G,F),I.lineTo(G,k);break e}case"branch-out":{const H=(F+k)/2;I.moveTo(r,F),I.bezierCurveTo(r,H,_,H,_,k);break e}case"merge-in":{const H=F/2;I.moveTo(G,0),I.bezierCurveTo(G,H,r,H,r,F);break e}default:continue}I.stroke(),I.globalAlpha=1}const ee=Y.getPropertyValue("--background").trim()||Y.getPropertyValue("--surface-background").trim();I.beginPath(),I.arc(r,F,4,0,Math.PI*2),I.fillStyle=m(x),I.fill(),I.beginPath(),I.arc(r,F,5,0,Math.PI*2),I.strokeStyle=ee||B,I.lineWidth=2,I.stroke()},e[0]=x,e[1]=p,e[2]=f,e[3]=w,e[4]=V):V=e[4];let L;e[5]!==x||e[6]!==p||e[7]!==j||e[8]!==f||e[9]!==n||e[10]!==u||e[11]!==w?(L=[n,f,x,p,u,j,w],e[5]=x,e[6]=p,e[7]=j,e[8]=f,e[9]=n,e[10]=u,e[11]=w,e[12]=L):L=e[12],l.useLayoutEffect(V,L);let S;e[13]!==w?(S={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=S):S=e[14];let O;e[15]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx("canvas",{ref:b,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=O):O=e[15];let C;return e[16]!==S?(C=t.jsx("div",{ref:E,style:S,children:O}),e[16]=S,e[17]=C):C=e[17],C};function ei(i){return i==="branch-out"||i==="merge-in"}function ti(i,e){const n=ei;return(n(i.type)?1:0)-(n(e.type)?1:0)}const gr=15e3,fr=500,pr=12,xr=8*1024*1024,wr=i=>typeof i=="string"?0:(i.original?.length??0)+(i.modified?.length??0),yr=i=>{if(i.size<=pr){let j=0;for(const f of i.values())j+=wr(f);if(j<=xr)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let u=0;for(const[j,f]of e){if(n.size>=pr)continue;const x=wr(f);u+x>xr&&n.size>0||(n.set(j,f),u+=x)}return new Map(Array.from(n.entries()).reverse())};function br(i,e){const n=new Date(i);return Number.isNaN(n.getTime())?i:$n(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function si(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 ri(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 ni=l.memo(({entry:i,mode:e="history",laned:n,totalLanes:u,isExpanded:j,onToggle:f,files:x,isLoadingFiles:p,onCopyHash:h,directory:w,onConflict:E,onActionSuccess:b})=>{const{t:V}=et(),L=Pt(d=>d.timeFormatPreference),S=e==="graph",[O,C]=l.useState(null),[y,D]=l.useState(!1),[k,R]=l.useState(""),[I,F]=l.useState(null),[r,Y]=l.useState(new Set),[B,m]=l.useState(new Map),[T,ee]=l.useState(new Set),$=async()=>{if(w){C("checkout");try{await Qn(w,i.hash),v.success(V("gitView.history.actions.detachedHead")),b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},G=async()=>{if(!(!w||!k.trim())){C("createBranch");try{await Wn(w,k.trim(),i.hash),D(!1),R(""),b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},_=async()=>{if(w){C("cherryPick");try{const d=await Yn(w,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"cherry-pick"}):b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},Z=async()=>{if(w){C("revert");try{const d=await qn(w,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"revert"}):b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},H=async(d,P=!1)=>{if(!(!w||O!==null)){C("reset");try{await Un(w,i.hash,d,P),b?.()}catch(M){v.error(String(M.message))}finally{C(null)}}},ce=async()=>{if(!I)return;const d=I;switch(F(null),d){case"checkout":return $();case"cherryPick":return _();case"revert":return Z();case"merge":return ie();case"rebase":return de();case"resetSoft":return H("soft");case"resetMixed":return H("mixed");case"resetHard":return H("hard",!0)}},ie=async()=>{if(w){C("merge");try{const d=await Jn(w,{branch:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"merge"}):b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},de=async()=>{if(w){C("rebase");try{const d=await Kn(w,{onto:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"rebase"}):b?.()}catch(d){v.error(String(d.message))}finally{C(null)}}},oe=l.useCallback(async d=>{const P=d.path;if(!w){m(M=>new Map(M).set(P,"error"));return}m(M=>yr(new Map(M).set(P,"loading")));try{const M=Gn(w,i.hash,d.path,!1),J=new Promise((te,K)=>{setTimeout(()=>K(new Error(`Timed out after ${gr}ms`)),gr)}),ae=await Promise.race([M,J]);m(te=>yr(new Map(te).set(P,ae)))}catch{m(M=>new Map(M).set(P,"error"))}},[w,i.hash]),g=l.useCallback(async d=>{const P=d.path;if(d.changeType==="R"||d.isBinary){Y(te=>{const K=new Set(te);return K.has(P)?K.delete(P):K.add(P),K});return}const M=B.get(P);if(r.has(P)&&M&&M!=="error"){Y(te=>{const K=new Set(te);return K.delete(P),K});return}Y(te=>{const K=new Set(te);return K.add(P),K}),!(M&&M!=="error"||d.insertions+d.deletions>fr&&!T.has(P))&&await oe(d)},[B,T,oe,r]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:f,className:Ce("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S?"hover:bg-[var(--interactive-hover)]/40":j?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[S&&n&&u!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Za,{laned:n,totalLanes:u,isExpanded:j})}):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:[S?(()=>{const d=ri(i.refs);return d.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:d.map(P=>t.jsx("span",{className:Ce("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",P.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":P.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:P.label},P.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:br(i.date,L),children:br(i.date,L)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:i.hash.slice(0,8)}),t.jsxs(Xt,{children:[t.jsx(Zt,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:d=>{d.stopPropagation(),h(i.hash)},children:t.jsx(A,{name:"file-copy",className:"size-3"})})}),t.jsx(es,{sideOffset:8,children:V("gitView.history.copySha")})]})]})]})]}),j&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[S&&I?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:V(`gitView.history.actions.${I}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),ce()},children:[O!==null?t.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),F(null)},children:V("gitView.history.actions.cancelButton")})]}):S?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:O!==null,onClick:d=>{d.stopPropagation(),F("checkout")},children:V("gitView.history.actions.checkout")}),y?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:k,onChange:d=>R(d.target.value),onKeyDown:d=>{d.key==="Enter"&&G(),d.key==="Escape"&&(D(!1),R(""))},placeholder:V("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:!k.trim()||O!==null,onClick:d=>{d.stopPropagation(),G()},children:[O==="createBranch"?t.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:d=>{d.stopPropagation(),D(!0)},children:V("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),F("cherryPick")},children:V("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),F("revert")},children:V("gitView.history.actions.revert")}),t.jsxs(Bs,{children:[t.jsx(Ds,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>d.stopPropagation(),children:[O==="reset"?t.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,V("gitView.history.actions.reset")]})}),t.jsx(Ms,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(d=>t.jsx(_n,{disabled:O!==null,onSelect:P=>{P.stopPropagation(),F(`reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},children:V(`gitView.history.actions.reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},d))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),F("merge")},children:V("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),F("rebase")},children:V("gitView.history.actions.rebase")})]}):null,p?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:V("gitView.history.loadingFiles")})]}):x.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:V("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:x.map(d=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>g(d),className:Ce("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",r.has(d.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Ce("font-semibold w-3 text-center shrink-0",si(d.changeType)),children:d.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:d.path,children:d.path}),!d.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d.deletions]})]}),d.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:V("gitView.history.binary")}),t.jsx(A,{name:r.has(d.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),r.has(d.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:d.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.renamedNoDiff")}):d.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.binaryNoDiff")}):(()=>{const P=d.insertions+d.deletions;if(!T.has(d.path)&&P>fr)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:V("gitView.history.largeDiffTitle",{count:P})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:V("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:()=>{ee(J=>new Set(J).add(d.path)),oe(d)},children:V("gitView.history.renderDiffAnyway")})]});const M=B.get(d.path);return M==="loading"||M===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:V("gitView.history.loadingDiff")}):M==="error"?t.jsx("button",{type:"button",onClick:()=>g(d),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:V("gitView.history.diffError")}):t.jsx(za,{original:M.original,modified:M.modified,language:Hn(d.path)||"",fileName:d.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},d.path))})]})]})}),vr=["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 Kt(i){return vr[i%vr.length]}function ai(i){if(i.length===0)return[];const e=[],n=[];for(let u=0;u<i.length;u++){const j=i[u],f=[];for(let S=0;S<e.length;S++)e[S]===j.hash&&f.push(S);let x=f.length>0?f[0]:-1;if(x===-1){const S=e.indexOf(null);S!==-1?x=S:(x=e.length,e.push(null))}const p=f.slice(1),h=Kt(x),w=e[x]===j.hash,E=j.parents.length>0;E?e[x]=j.parents[0]:e[x]=null;const b=[],V=new Set;for(let S=1;S<j.parents.length;S++){const O=j.parents[S],C=e.indexOf(O);if(C!==-1)b.push(C);else{const y=e.indexOf(null);if(y!==-1)e[y]=O,b.push(y),V.add(y);else{const D=e.length;e.push(O),b.push(D),V.add(D)}}}const L=[];w&&E?L.push({fromLane:x,toLane:x,color:h,type:"commit-lane"}):w&&!E?L.push({fromLane:x,toLane:x,color:h,type:"top-stub"}):!w&&E&&L.push({fromLane:x,toLane:x,color:h,type:"bottom-stub"});for(const S of p)L.push({fromLane:S,toLane:x,color:Kt(S),type:"merge-in"}),e[S]=null;for(const S of b)L.push({fromLane:x,toLane:S,color:Kt(S),type:"branch-out"});for(let S=0;S<e.length;S++)e[S]!==null&&S!==x&&(V.has(S)||L.push({fromLane:S,toLane:S,color:Kt(S),type:"passing"}));n.push({commit:j,lane:x,color:h,connectors:L})}return n}const ii=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],oi=i=>{const e=Ct.c(84),{mode:n,log:u,isLogLoading:j,logMaxCount:f,onLogMaxCountChange:x,expandedCommitHashes:p,onToggleCommit:h,commitFilesMap:w,loadingCommitHashes:E,onCopyHash:b,directory:V,showHeader:L,contentMaxHeightClassName:S,branchDivider:O,onConflict:C,onActionSuccess:y}=i,D=n===void 0?"history":n,k=L===void 0?!0:L,R=S===void 0?"max-h-[50vh]":S,I=O===void 0?null:O,{t:F}=et(),[r,Y]=l.useState(!0),B=D==="graph";let m;e[0]!==B||e[1]!==u?(m=B&&u?ai(u.all):[],e[0]=B,e[1]=u,e[2]=m):m=e[2];const T=m;let ee;e[3]!==T?(ee=Math.max(1,...T.map(li)),e[3]=T,e[4]=ee):ee=e[4];const $=ee;let G;e[5]!==T?(G=new Map(T.map(ci)),e[5]=T,e[6]=G):G=e[6];const _=G;if(!u)return null;const Z=I!==null&&I.insertBeforeIndex>0&&I.insertBeforeIndex<u.all.length,H=I!==null&&I.insertBeforeIndex===u.all.length,ce=Z||H;let ie;e[7]!==I||e[8]!==Z||e[9]!==H||e[10]!==u.all?(ie=Z?u.all.slice(0,I.insertBeforeIndex):H?u.all:[],e[7]=I,e[8]=Z,e[9]=H,e[10]=u.all,e[11]=ie):ie=e[11];const de=ie;let oe;if(e[12]!==I||e[13]!==w||e[14]!==R||e[15]!==V||e[16]!==p||e[17]!==Z||e[18]!==ce||e[19]!==B||e[20]!==j||e[21]!==_||e[22]!==E||e[23]!==u.all||e[24]!==f||e[25]!==$||e[26]!==D||e[27]!==y||e[28]!==C||e[29]!==b||e[30]!==x||e[31]!==h||e[32]!==F||e[33]!==de){const se=Z?u.all.slice(I.insertBeforeIndex):[];let Q;e[35]!==I?.direction?(Q=I?.direction==="down"?t.jsx(A,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(A,{name:"arrow-up",className:"size-3.5"}),e[35]=I?.direction,e[36]=Q):Q=e[36];const Ne=Q;let ve;e[37]!==w||e[38]!==V||e[39]!==p||e[40]!==B||e[41]!==_||e[42]!==E||e[43]!==$||e[44]!==D||e[45]!==y||e[46]!==C||e[47]!==b||e[48]!==h?(ve=Fe=>t.jsx("ul",{className:"divide-y divide-border/60",children:Fe.map(ue=>t.jsx(ni,{entry:ue,mode:D,laned:B?_.get(ue.hash):void 0,totalLanes:B?$:void 0,isExpanded:p.has(ue.hash),onToggle:()=>h(ue.hash),files:w.get(ue.hash)??[],isLoadingFiles:E.has(ue.hash),onCopyHash:b,directory:V,onConflict:C,onActionSuccess:y},ue.hash))}),e[37]=w,e[38]=V,e[39]=p,e[40]=B,e[41]=_,e[42]=E,e[43]=$,e[44]=D,e[45]=y,e[46]=C,e[47]=b,e[48]=h,e[49]=ve):ve=e[49];const me=ve;let he;e[50]!==j||e[51]!==u.all.length||e[52]!==f||e[53]!==x||e[54]!==F?(he=u.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:j,className:"px-3 text-muted-foreground hover:text-foreground",children:j?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(A,{name:"loader-4",className:"size-3 animate-spin"}),F("gitView.history.loadingMore")]}):F("gitView.history.loadMore")})}):null,e[50]=j,e[51]=u.all.length,e[52]=f,e[53]=x,e[54]=F,e[55]=he):he=e[55];const Pe=he;oe=t.jsx(Sr,{outerClassName:`min-h-0 ${R}`,className:"h-full w-full",children:u.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:F("gitView.history.noCommits")})}):ce&&I?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[de.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(de)}):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:I.branchName,children:I.branchName}),Ne]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),se.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:me(se)}):null]}),Pe]}):t.jsxs(t.Fragment,{children:[me(u.all),Pe]})}),e[12]=I,e[13]=w,e[14]=R,e[15]=V,e[16]=p,e[17]=Z,e[18]=ce,e[19]=B,e[20]=j,e[21]=_,e[22]=E,e[23]=u.all,e[24]=f,e[25]=$,e[26]=D,e[27]=y,e[28]=C,e[29]=b,e[30]=x,e[31]=h,e[32]=F,e[33]=de,e[34]=oe}else oe=e[34];const g=oe;if(!k){if(ce){let Q;return e[56]!==g?(Q=t.jsx("section",{className:"h-full min-h-0",children:g}),e[56]=g,e[57]=Q):Q=e[57],Q}let se;return e[58]!==g?(se=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:g}),e[58]=g,e[59]=se):se=e[59],se}let d;e[60]!==F?(d=F("gitView.history.title"),e[60]=F,e[61]=d):d=e[61];let P;e[62]!==d?(P=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:d}),e[62]=d,e[63]=P):P=e[63];let M;e[64]!==j||e[65]!==r||e[66]!==f||e[67]!==x||e[68]!==F?(M=r&&t.jsx("div",{onClick:di,onPointerDown:ui,children:t.jsxs(Xn,{value:String(f),onValueChange:se=>x(Number(se)),disabled:j,children:[t.jsx(Zn,{size:"sm",className:"w-auto",disabled:j,children:t.jsx(ea,{placeholder:F("gitView.history.commitsPlaceholder")})}),t.jsx(ta,{children:ii.map(se=>t.jsx(sa,{value:String(se.value),children:F(se.labelKey)},se.value))})]})}),e[64]=j,e[65]=r,e[66]=f,e[67]=x,e[68]=F,e[69]=M):M=e[69];let J;e[70]!==r?(J=r?t.jsx(A,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(A,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=r,e[71]=J):J=e[71];let ae;e[72]!==M||e[73]!==J?(ae=t.jsxs("div",{className:"flex items-center gap-2",children:[M,J]}),e[72]=M,e[73]=J,e[74]=ae):ae=e[74];let te;e[75]!==P||e[76]!==ae?(te=t.jsxs(Ra,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[P,ae]}),e[75]=P,e[76]=ae,e[77]=te):te=e[77];let K;e[78]!==g?(K=t.jsx(Ba,{children:g}),e[78]=g,e[79]=K):K=e[79];let we;return e[80]!==r||e[81]!==te||e[82]!==K?(we=t.jsxs(Da,{open:r,onOpenChange:Y,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[te,K]}),e[80]=r,e[81]=te,e[82]=K,e[83]=we):we=e[83],we};function li(i){return i.lane+1}function ci(i){return[i.commit.hash,i]}function di(i){return i.stopPropagation()}function ui(i){return i.stopPropagation()}const mi=i=>{const e=Ct.c(148),{open:n,onOpenChange:u,conflictFiles:j,directory:f,operation:x,onAbort:p,onClearState:h}=i;let w;e[0]!==j?(w=j===void 0?[]:j,e[0]=j,e[1]=w):w=e[1];const E=w,{t:b}=et(),V=Ze(hi),L=Ze(gi),S=qt(fi),O=qt(pi),[C,y]=l.useState(!1),[D,k]=l.useState(null),[R,I]=l.useState(null);let F,r;e[2]!==f||e[3]!==n||e[4]!==b?(F=()=>{!n||!f||(y(!0),I(null),k(null),ra(f).then(X=>{k(X)}).catch(X=>{const pe=X instanceof Error?X.message:b("gitView.conflict.loadFailed");I(pe)}).finally(()=>{y(!1)}))},r=[n,f,b],e[2]=f,e[3]=n,e[4]=b,e[5]=F,e[6]=r):(F=e[5],r=e[6]),l.useEffect(F,r);let Y;e[7]!==D||e[8]!==f||e[9]!==x?(Y=async()=>{if(!D)return null;const X=x==="merge"?"merge":"rebase",pe=D.headInfo||(x==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Re=x==="merge"?"git commit --no-edit":"git rebase --continue",Ve=await Jt("git.conflict.resolve.visible",{operation_label:X,head_ref:pe}),je=await Jt("git.conflict.resolve.instructions",{operation_label:X,directory:f,operation:x,head_info:D.headInfo||"N/A",continue_cmd:Re}),le=`${X} conflict context (JSON)
3
+ ${JSON.stringify({directory:f,operation:D.operation,headInfo:D.headInfo,statusPorcelain:D.statusPorcelain,unmergedFiles:D.unmergedFiles,diff:D.diff},null,2)}`;return{visibleText:Ve,instructionsText:je,payloadText:le}},e[7]=D,e[8]=f,e[9]=x,e[10]=Y):Y=e[10];const B=Y;let m;e[11]!==p||e[12]!==u?(m=()=>{p(),u(!1)},e[11]=p,e[12]=u,e[13]=m):m=e[13];const T=m;let ee;e[14]!==h||e[15]!==u?(ee=()=>{h?.(),u(!1)},e[14]=h,e[15]=u,e[16]=ee):ee=e[16];const $=ee;let G;e[17]!==B||e[18]!==L||e[19]!==h||e[20]!==u||e[21]!==S||e[22]!==O||e[23]!==b?(G=async()=>{const X=await B();if(!X){v.error(b("gitView.conflict.noDetailsAvailable"));return}if(!L){v.error(b("gitView.conflict.noActiveSession"),{description:b("gitView.conflict.noActiveSessionDescription")});return}S(X.visibleText,"replace"),O([{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]),h?.(),u(!1)},e[17]=B,e[18]=L,e[19]=h,e[20]=u,e[21]=S,e[22]=O,e[23]=b,e[24]=G):G=e[24];const _=G;let Z;e[25]!==B||e[26]!==f||e[27]!==h||e[28]!==u||e[29]!==V||e[30]!==b?(Z=async()=>{const X=await B();if(!X){v.error(b("gitView.conflict.noDetailsAvailable"));return}V({directoryOverride:f,initialPrompt:X.visibleText,syntheticParts:[{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]}),h?.(),u(!1)},e[25]=B,e[26]=f,e[27]=h,e[28]=u,e[29]=V,e[30]=b,e[31]=Z):Z=e[31];const H=Z;let ce,ie,de,oe,g,d,P,M,J,ae,te,K,we,se,Q,Ne,ve,me,he,Pe,Fe,ue;if(e[32]!==D||e[33]!==E||e[34]!==L||e[35]!==T||e[36]!==$||e[37]!==_||e[38]!==H||e[39]!==C||e[40]!==R||e[41]!==u||e[42]!==n||e[43]!==x||e[44]!==b){const X=b(x==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),pe=D?.unmergedFiles||E;de=ht,Fe=n,ue=u,ie=gt,Pe="max-w-md w-[calc(100vw-2rem)]",se="flex flex-col gap-4 overflow-hidden";let Re;e[67]===Symbol.for("react.memo_cache_sentinel")?(Re=t.jsx(A,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[67]=Re):Re=e[67];const Ve=t.jsxs("div",{className:"flex items-center gap-2",children:[Re,t.jsx(pt,{children:b("gitView.conflict.detectedTitle",{operation:X})})]});let je;e[68]!==x||e[69]!==b?(je=b("gitView.conflict.detectedDescription",{operation:x}),e[68]=x,e[69]=b,e[70]=je):je=e[70];let le;e[71]!==je?(le=t.jsx(bt,{children:je}),e[71]=je,e[72]=le):le=e[72],e[73]!==Ve||e[74]!==le?(Q=t.jsxs(ft,{children:[Ve,le]}),e[73]=Ve,e[74]=le,e[75]=Q):Q=e[75],e[76]!==C||e[77]!==b?(Ne=C&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:b("gitView.conflict.loading")})]}),e[76]=C,e[77]=b,e[78]=Ne):Ne=e[78],e[79]!==R||e[80]!==b?(ve=R&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:b("gitView.conflict.errorLoadingDetails",{message:R})}),e[79]=R,e[80]=b,e[81]=ve):ve=e[81],e[82]!==pe||e[83]!==b?(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:b("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(xi)})})]}),e[82]=pe,e[83]=b,e[84]=me):me=e[84],e[85]!==D||e[86]!==b?(he=D?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:b("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:D.headInfo})]}),e[85]=D,e[86]=b,e[87]=he):he=e[87],te="flex flex-col gap-2 pt-2";let Be;e[88]!==H?(Be=()=>{H()},e[88]=H,e[89]=Be):Be=e[89];const _e=C||!D;let Le;e[90]!==C?(Le=C?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"add",className:"size-4"}),e[90]=C,e[91]=Le):Le=e[91];let Ee;e[92]!==b?(Ee=b("gitView.conflict.resolveNewSession"),e[92]=b,e[93]=Ee):Ee=e[93],e[94]!==Be||e[95]!==_e||e[96]!==Le||e[97]!==Ee?(K=t.jsxs(W,{variant:"default",onClick:Be,disabled:_e,className:"w-full gap-2",children:[Le,Ee]}),e[94]=Be,e[95]=_e,e[96]=Le,e[97]=Ee,e[98]=K):K=e[98];let De;e[99]!==_?(De=()=>{_()},e[99]=_,e[100]=De):De=e[100];const Te=C||!D||!L;let Ie;e[101]!==C?(Ie=C?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"chat-1",className:"size-4"}),e[101]=C,e[102]=Ie):Ie=e[102];let q;e[103]!==b?(q=b("gitView.conflict.resolveCurrentSession"),e[103]=b,e[104]=q):q=e[104],e[105]!==De||e[106]!==Te||e[107]!==Ie||e[108]!==q?(we=t.jsxs(W,{variant:"outline",onClick:De,disabled:Te,className:"w-full gap-2",children:[Ie,q]}),e[105]=De,e[106]=Te,e[107]=Ie,e[108]=q,e[109]=we):we=e[109],J="flex gap-2 pt-1";let xe;e[110]!==b?(xe=b("gitView.conflict.continueLater"),e[110]=b,e[111]=xe):xe=e[111],e[112]!==$||e[113]!==xe?(ae=t.jsx(W,{variant:"ghost",size:"sm",onClick:$,className:"flex-1",children:xe}),e[112]=$,e[113]=xe,e[114]=ae):ae=e[114],ce=W,oe="destructive",g="sm",d=T,P="flex-1",M=b("gitView.conflict.abortOperation",{operation:X}),e[32]=D,e[33]=E,e[34]=L,e[35]=T,e[36]=$,e[37]=_,e[38]=H,e[39]=C,e[40]=R,e[41]=u,e[42]=n,e[43]=x,e[44]=b,e[45]=ce,e[46]=ie,e[47]=de,e[48]=oe,e[49]=g,e[50]=d,e[51]=P,e[52]=M,e[53]=J,e[54]=ae,e[55]=te,e[56]=K,e[57]=we,e[58]=se,e[59]=Q,e[60]=Ne,e[61]=ve,e[62]=me,e[63]=he,e[64]=Pe,e[65]=Fe,e[66]=ue}else ce=e[45],ie=e[46],de=e[47],oe=e[48],g=e[49],d=e[50],P=e[51],M=e[52],J=e[53],ae=e[54],te=e[55],K=e[56],we=e[57],se=e[58],Q=e[59],Ne=e[60],ve=e[61],me=e[62],he=e[63],Pe=e[64],Fe=e[65],ue=e[66];let qe;e[115]!==ce||e[116]!==oe||e[117]!==g||e[118]!==d||e[119]!==P||e[120]!==M?(qe=t.jsx(ce,{variant:oe,size:g,onClick:d,className:P,children:M}),e[115]=ce,e[116]=oe,e[117]=g,e[118]=d,e[119]=P,e[120]=M,e[121]=qe):qe=e[121];let Ye;e[122]!==J||e[123]!==ae||e[124]!==qe?(Ye=t.jsxs("div",{className:J,children:[ae,qe]}),e[122]=J,e[123]=ae,e[124]=qe,e[125]=Ye):Ye=e[125];let ge;e[126]!==te||e[127]!==K||e[128]!==we||e[129]!==Ye?(ge=t.jsxs("div",{className:te,children:[K,we,Ye]}),e[126]=te,e[127]=K,e[128]=we,e[129]=Ye,e[130]=ge):ge=e[130];let fe;e[131]!==se||e[132]!==Q||e[133]!==Ne||e[134]!==ve||e[135]!==me||e[136]!==he||e[137]!==ge?(fe=t.jsxs("div",{className:se,children:[Q,Ne,ve,me,he,ge]}),e[131]=se,e[132]=Q,e[133]=Ne,e[134]=ve,e[135]=me,e[136]=he,e[137]=ge,e[138]=fe):fe=e[138];let Se;e[139]!==ie||e[140]!==Pe||e[141]!==fe?(Se=t.jsx(ie,{className:Pe,children:fe}),e[139]=ie,e[140]=Pe,e[141]=fe,e[142]=Se):Se=e[142];let ke;return e[143]!==de||e[144]!==Fe||e[145]!==ue||e[146]!==Se?(ke=t.jsx(de,{open:Fe,onOpenChange:ue,children:Se}),e[143]=de,e[144]=Fe,e[145]=ue,e[146]=Se,e[147]=ke):ke=e[147],ke};function hi(i){return i.openNewSessionDraft}function gi(i){return i.currentSessionId}function fi(i){return i.setPendingInputText}function pi(i){return i.setPendingSyntheticParts}function xi(i){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:i,children:i},i)}const wi=({open:i,onOpenChange:e,operation:n,targetBranch:u,onConfirm:j})=>{const{t:f}=et(),[x,p]=l.useState(!0),[h,w]=l.useState(!1),E=f(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),b=async()=>{w(!0);try{await j(x),e(!1)}catch(L){const S=L instanceof Error?L.message:`Failed to ${n}`;v.error(S)}finally{w(!1)}},V=()=>{h||e(!1)};return t.jsx(ht,{open:i,onOpenChange:h?void 0:e,children:t.jsxs(gt,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(pt,{children:f("gitView.stash.title")})]}),t.jsx(bt,{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:u})]}),x&&t.jsx("li",{children:f("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(na,{checked:x,onChange:p,disabled:h,ariaLabel:f("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!h&&p(!x),children:f("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(Rs,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:V,disabled:h,children:f("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:b,disabled:h,className:"gap-1.5",children:h?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("gitView.common.processing")]}):f("gitView.stash.confirmButton",{operation:E})})]})]})})},yi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:u,onResolveWithAI:j,conflictCount:f=0,isLoading:x=!1})=>{const{t:p}=et(),[h,w]=l.useState(null),E=i&&i.head,b=e&&(e.headName||e.onto),V=E?"merge":b?"rebase":null;if(!V)return null;const L=async()=>{w("continue");try{await n()}finally{w(null)}},S=async()=>{w("abort");try{await u()}finally{w(null)}},O=h!==null,C=f>0,y=p(V==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let D="";i?D=i.message?p("gitView.operation.mergingMessage",{message:i.message}):p("gitView.operation.mergeInProgressWithHead",{head:i.head}):e&&(D=e.headName?p("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):p("gitView.operation.rebaseInProgress"));const k=C?f===1?p("gitView.operation.inProgressTitleOneConflict",{operation:y,count:f}):p("gitView.operation.inProgressTitleManyConflicts",{operation:y,count:f}):p("gitView.operation.inProgressTitle",{operation:y}),R=p(C?"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:k}),D&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:D})]}),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:R}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:S,disabled:O||x,className:"gap-1.5",children:[h==="abort"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"close",className:"size-4"}),p("gitView.operation.abort")]}),C?j&&t.jsx(W,{variant:"default",size:"sm",onClick:j,disabled:O||x,children:p("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:L,disabled:O||x,className:"gap-1.5",children:[h==="continue"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"check",className:"size-4"}),p("gitView.operation.continue")]})]})]})]})})},bi=i=>{const e=Ct.c(104),{currentBranch:n,localBranches:u,remoteBranches:j,onMerge:f,onRebase:x,disabled:p,isOperating:h,operationLogs:w,onOperationComplete:E,mode:b,defaultTargetBranch:V}=i,L=p===void 0?!1:p,S=h===void 0?!1:h,O=w===void 0?[]:w,C=b===void 0?"dialog":b,{t:y}=et(),[D,k]=l.useState(!1),[R,I]=l.useState("merge"),[F,r]=l.useState(null),[Y,B]=l.useState(!1),[m,T]=l.useState(""),ee=l.useRef(null),$=l.useRef(null),G=L||S,_=n||y("gitView.branch.currentBranchFallback"),Z=O.length>0&&O.every(vi),H=O.some(ji);let ce;e[0]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{$.current&&($.current.scrollTop=$.current.scrollHeight)},e[0]=ce):ce=e[0],l.useEffect(ce,[O]);let ie;e[1]!==j?(ie=new Set(j.map(Ci).filter(Boolean)),e[1]=j,e[2]=ie):ie=e[2];const de=ie;let oe;if(e[3]!==m||e[4]!==n||e[5]!==u||e[6]!==de){let q;e[8]!==n||e[9]!==de?(q=Ae=>Ae!==n&&!de.has(Ae),e[8]=n,e[9]=de,e[10]=q):q=e[10];const xe=u.filter(q);oe=Rt(xe,m,Ni),e[3]=m,e[4]=n,e[5]=u,e[6]=de,e[7]=oe}else oe=e[7];const g=oe;let d;e[11]!==m||e[12]!==j?(d=Rt(j,m,Si),e[11]=m,e[12]=j,e[13]=d):d=e[13];const P=d;let M;e[14]!==V||e[15]!==u||e[16]!==j?(M=()=>V&&(j.includes(V)||u.includes(V))?V:null,e[14]=V,e[15]=u,e[16]=j,e[17]=M):M=e[17];const J=M;let ae;e[18]!==J||e[19]!==k?(ae=()=>{k(!0),r(J()),I("merge"),T("")},e[18]=J,e[19]=k,e[20]=ae):ae=e[20];const te=ae;let K;e[21]===Symbol.for("react.memo_cache_sentinel")?(K=q=>{r(q),B(!1),T("")},e[21]=K):K=e[21];const we=K;let se;e[22]!==f||e[23]!==x||e[24]!==R||e[25]!==F?(se=()=>{F&&(R==="merge"?f(F):x(F))},e[22]=f,e[23]=x,e[24]=R,e[25]=F,e[26]=se):se=e[26];const Q=se;let Ne;e[27]!==S||e[28]!==k?(Ne=()=>{S||(r(null),I("merge"),T(""),k(!1))},e[27]=S,e[28]=k,e[29]=Ne):Ne=e[29];const ve=Ne,me=()=>{S&&!Z||(Z&&E?.(),r(null),I("merge"),T(""),k(!1))};let he,Pe;e[30]!==Y?(he=()=>{Y||T("")},Pe=[Y],e[30]=Y,e[31]=he,e[32]=Pe):(he=e[31],Pe=e[32]),l.useEffect(he,Pe);let Fe,ue;e[33]!==C||e[34]!==J||e[35]!==F?(Fe=()=>{C==="dialog"||F||r(J())},ue=[C,J,F],e[33]=C,e[34]=J,e[35]=F,e[36]=Fe,e[37]=ue):(Fe=e[36],ue=e[37]),l.useEffect(Fe,ue);const ge=S?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:$,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:O.map(ki)})}),Z?C==="dialog"?t.jsx(Rs,{children:t.jsx(W,{variant:"default",size:"sm",onClick:me,children:y(H?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:me,children:y(H?"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:y("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>I("merge"),className:Ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="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(A,{name:"git-merge",className:Ce("size-4",R==="merge"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ce("typography-ui-label",R==="merge"?"text-foreground":"text-muted-foreground"),children:y("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:y("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>I("rebase"),className:Ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="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(A,{name:"git-branch",className:Ce("size-4",R==="rebase"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ce("typography-ui-label",R==="rebase"?"text-foreground":"text-muted-foreground"),children:y("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:y("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?y("gitView.branch.branchToMergeInto",{branch:_}):y("gitView.branch.branchToRebaseOnto")}),t.jsxs(Bs,{open:Y,onOpenChange:B,modal:!1,children:[t.jsx(Ds,{asChild:!0,children:t.jsxs("button",{type:"button",className:Ce(Nr({size:"default"}),"w-full"),children:[t.jsx("span",{className:Ce("truncate",!F&&"text-muted-foreground"),children:F||y("gitView.branch.selectBranch")}),t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Ms,{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(Es,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ts,{ref:ee,placeholder:y("gitView.branch.searchPlaceholder"),value:m,onValueChange:T,onKeyDown:Vi}),t.jsxs(As,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Ls,{children:y("gitView.branch.empty")}),g.length>0&&t.jsx(Yt,{heading:y("gitView.branch.localBranches"),children:g.map(q=>t.jsx(Qt,{onSelect:()=>we(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`local-${q}`))}),g.length>0&&P.length>0?t.jsx(aa,{}):null,P.length>0&&t.jsx(Yt,{heading:y("gitView.branch.remoteBranches"),children:P.map(q=>t.jsx(Qt,{onSelect:()=>we(q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q})},`remote-${q}`))})]})]})})]})]}),F?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?t.jsxs(t.Fragment,{children:[y("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F})," ",y("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_})]}):t.jsxs(t.Fragment,{children:[y("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_})," ",y("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F})]})})}):null,C==="dialog"?t.jsxs(Rs,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:ve,children:y("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:Q,disabled:!F,className:"gap-1.5",children:R==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"git-merge",className:"size-4"}),y("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"git-branch",className:"size-4"}),y("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:ve,disabled:G,children:y("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:Q,disabled:G||!F,children:y(R==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(C==="bare")return ge;if(C==="inline"){let q;e[38]!==y?(q=y("gitView.branch.updateTitle"),e[38]=y,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 Ae;e[42]!==y?(Ae=y("gitView.branch.updateDescriptionPrefix"),e[42]=y,e[43]=Ae):Ae=e[43];let Ge;e[44]!==_?(Ge=t.jsx("span",{className:"font-mono text-foreground",children:_}),e[44]=_,e[45]=Ge):Ge=e[45];let tt;e[46]!==Ae||e[47]!==Ge?(tt=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ae," ",Ge,"."]}),e[46]=Ae,e[47]=Ge,e[48]=tt):tt=e[48];let nt;e[49]!==xe||e[50]!==tt?(nt=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[xe,tt]})}),e[49]=xe,e[50]=tt,e[51]=nt):nt=e[51];let at;e[52]!==ge?(at=t.jsx("div",{className:"pt-3",children:ge}),e[52]=ge,e[53]=at):at=e[53];let it;return e[54]!==nt||e[55]!==at?(it=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[nt,at]}),e[54]=nt,e[55]=at,e[56]=it):it=e[56],it}let fe;e[57]!==S?(fe=S?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"git-merge",className:"size-4"}),e[57]=S,e[58]=fe):fe=e[58];let Se;e[59]!==y?(Se=y("gitView.branch.mergeRebase"),e[59]=y,e[60]=Se):Se=e[60];let ke;e[61]!==Se?(ke=t.jsx("span",{children:Se}),e[61]=Se,e[62]=ke):ke=e[62];let X;e[63]!==te||e[64]!==G||e[65]!==fe||e[66]!==ke?(X=t.jsx(Zt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:te,disabled:G,children:[fe,ke]})}),e[63]=te,e[64]=G,e[65]=fe,e[66]=ke,e[67]=X):X=e[67];let pe;e[68]!==y?(pe=y("gitView.branch.mergeRebaseTooltip"),e[68]=y,e[69]=pe):pe=e[69];let Re;e[70]!==pe?(Re=t.jsx(es,{sideOffset:8,children:pe}),e[70]=pe,e[71]=Re):Re=e[71];let Ve;e[72]!==X||e[73]!==Re?(Ve=t.jsxs(Xt,{children:[X,Re]}),e[72]=X,e[73]=Re,e[74]=Ve):Ve=e[74];let je;e[75]!==me||e[76]!==k?(je=q=>{q?k(!0):me()},e[75]=me,e[76]=k,e[77]=je):je=e[77];let le;e[78]!==y?(le=y("gitView.branch.updateTitle"),e[78]=y,e[79]=le):le=e[79];let Be;e[80]!==le?(Be=t.jsx(pt,{children:le}),e[80]=le,e[81]=Be):Be=e[81];let _e;e[82]!==H||e[83]!==S||e[84]!==R||e[85]!==Z||e[86]!==y||e[87]!==_?(_e=S?y(Z?H?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":R==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[y("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:_}),"."]}),e[82]=H,e[83]=S,e[84]=R,e[85]=Z,e[86]=y,e[87]=_,e[88]=_e):_e=e[88];let Le;e[89]!==_e?(Le=t.jsx(bt,{children:_e}),e[89]=_e,e[90]=Le):Le=e[90];let Ee;e[91]!==Be||e[92]!==Le?(Ee=t.jsxs(ft,{children:[Be,Le]}),e[91]=Be,e[92]=Le,e[93]=Ee):Ee=e[93];let De;e[94]!==ge||e[95]!==Ee?(De=t.jsxs(gt,{className:"max-w-md",children:[Ee,ge]}),e[94]=ge,e[95]=Ee,e[96]=De):De=e[96];let Te;e[97]!==D||e[98]!==je||e[99]!==De?(Te=t.jsx(ht,{open:D,onOpenChange:je,children:De}),e[97]=D,e[98]=je,e[99]=De,e[100]=Te):Te=e[100];let Ie;return e[101]!==Ve||e[102]!==Te?(Ie=t.jsxs(t.Fragment,{children:[Ve,Te]}),e[101]=Ve,e[102]=Te,e[103]=Ie):Ie=e[103],Ie};function vi(i){return i.status==="done"||i.status==="error"}function ji(i){return i.status==="error"}function Ci(i){return i.slice(i.indexOf("/")+1)}function Ni(i){return[i]}function Si(i){return[i]}function ki(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(A,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),i.status==="done"&&t.jsx(A,{name:"check",className:"size-3.5 text-success"}),i.status==="error"&&t.jsx(A,{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:Ce("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 Vi(i){return i.stopPropagation()}const Ii=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:u,scheduleFlush:j})=>{const f=[];let x=!1;return{enqueue:h=>{const w=f[f.length-1];if(w?.directory===h.directory&&w.direction===h.direction){h.paths.forEach(E=>w.paths.add(E));return}f.push(h)},flush:()=>{if(x)return;const h=f.shift();if(!h)return;x=!0;const w={directory:h.directory,direction:h.direction,paths:Array.from(h.paths),rollback:h.rollback};(async()=>{try{await i(w),e(w)}catch(E){n(w,E)}finally{u(w.paths),x=!1,f.length>0&&j()}})()},clear:()=>{f.length=0},size:()=>f.length,isRunning:()=>x}},Pi=15e3,Fi=40,Ri=20,jr={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:"},Bi=(i,e)=>{const n=i.toLowerCase(),u=/^([a-z]+)(?:\(.*\))?!?:/,j=n.match(u);if(j){const p=j[1],h=jr[p];if(h)return e.find(w=>w.code===h)||null}const f=n.split(" ")[0],x=jr[f];return x&&e.find(p=>p.code===x)||null},Di=20,yt=new Map,Mi=(i,e)=>{if(yt.delete(i),yt.set(i,e),yt.size>Di){const n=yt.keys().next().value;n!==void 0&&yt.delete(n)}},rt=i=>(i||"").replace(/\\/g,"/").replace(/\/+$/,""),Cr=i=>{const e=i.index?.trim();return!!(e&&e!=="?")},Ei=i=>{const e=i.working_dir?.trim(),n=i.index?.trim();return!!(e||n==="?")},Xl=({isActive:i})=>{const{t:e}=et(),{git:n}=ia(),u=oa(),[j,f]=l.useState(null),[x,p]=l.useState(!1),h=Ze(s=>s.currentSessionId),w=Ze(s=>s.newSessionDraft),E=Ze(s=>s.setDraftBootstrapPendingDirectory),b=Ze(s=>s.worktreeMetadata),V=Ze(s=>s.availableWorktrees),L=rt(u),S=l.useMemo(()=>{if(!L)return;const s=V.find(a=>rt(a.path)===L);if(s)return s;for(const a of b.values())if(rt(a.path)===L)return a},[V,L,b]),O=l.useMemo(()=>{if(h)return b.get(h)??S;if(w?.open)return S},[h,S,w?.open,b]),{profiles:C,globalIdentity:y,defaultGitIdentityId:D,loadProfiles:k,loadGlobalIdentity:R,loadDefaultGitIdentityId:I}=Ma(ur(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:F,gitDirectory:r,nestedRepos:Y}=la(u??null,{enabled:i}),B=ca(r??null),m=da(r??null),T=ua(s=>h?s.getAttachment(h):void 0),ee=T?ma(T):[],$=T&&!T.degraded&&!T.legacy?T.worktreeRoot??void 0:void 0,G=Ia(u,O,m?.current??void 0),_=ha(r??null),Z=ga(r??null),H=fa(r??null),ce=pa(r??null),ie=xa(r??null),{setActiveDirectory:de,fetchAll:oe,ensureAll:g,fetchStatus:d,fetchBranches:P,fetchLog:M,setLogMaxCount:J,fetchIdentity:ae,prefetchDiffs:te,clearDiffCache:K,moveStatusPathsOptimistically:we,restoreStatus:se,bumpIndexRevision:Q,ensureNestedRepos:Ne,selectNestedRepo:ve}=wa(ur(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,ensureNestedRepos:s.ensureNestedRepos,selectNestedRepo:s.selectNestedRepo}))),me=Pt(s=>s.isMobile),he=Pt(s=>s.openContextDiff),Pe=Pt(s=>s.openContextSurface),Fe=m?.current??null,ue=ya(s=>!r||!Fe?null:ba(s.entries,r,Fe)),qe=Pt(s=>s.navigateToDiff),Ye=l.useRef(null),ge=l.useRef(null),fe=l.useRef(null),Se=l.useRef(null),ke=l.useRef(!0);l.useEffect(()=>()=>{ke.current=!1},[]);const X=l.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null)},[]),pe=l.useCallback(s=>{X(),ge.current=window.setTimeout(()=>{ge.current=null,rt(s)===rt(r)&&d(s,n,{silent:!0})},Pi)},[X,r,d,n]);l.useEffect(()=>X,[X]);const Re=l.useCallback(()=>{fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)},[]),Ve=l.useCallback(()=>{fe.current===null&&(fe.current=window.setTimeout(()=>{fe.current=null,Se.current?.()},0))},[]),je=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]),le=l.useMemo(()=>Ii({runMutation:({directory:s,direction:a,paths:o})=>je(s,a,o),onMutationComplete:({directory:s})=>{Q(s),pe(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),Q(s),pe(s);const N=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");v.error(c instanceof Error?c.message:N)},onPathsComplete:s=>{Ws(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ve}),[Q,je,Ve,pe,e]);l.useEffect(()=>(Se.current=le.flush,()=>{Se.current=null}),[le]),l.useEffect(()=>()=>le.clear(),[le]),l.useEffect(()=>Re,[Re]),l.useEffect(()=>{if(!i)return;if(!u){f(null),p(!1);return}let s=!1,a=null;const o=async()=>{try{const c=await Va(u);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,u]),l.useEffect(()=>{const s=Ye.current;Ye.current=j,!(!u||!n)&&(s==="pending"&&j==="ready"&&(p(!0),oe(u,n).finally(()=>{window.setTimeout(()=>{p(!1)},1200)})),j==="failed"&&(E(null),p(!1)))},[u,oe,n,E,j]);const Be=rt(w?.bootstrapPendingDirectory??null),_e=!!(u&&Be&&Be===rt(u)),Ee=!!(u&&(j==="pending"||_e))||x,De=l.useMemo(()=>r?yt.get(r)??null:null,[r]),Te=va(s=>s.settingsGitmojiEnabled),[Ie,q]=l.useState(null),{gitmojis:xe}=$a(Te);l.useEffect(()=>{const s=$||G?.projectDirectory;if(!s){q(null);return}let a=!1;return ja(s).then(o=>{if(a)return;const c=o.trim();q(c&&c!=="HEAD"?c:null)}).catch(()=>{a||q(null)}),()=>{a=!0}},[$,G?.projectDirectory]);const[Ae,Ge]=l.useState(De?.commitMessage??""),[tt,nt]=l.useState([]),[at,it]=l.useState(!1),Os=l.useRef(null),[zs,Bt]=l.useState(null),[Pr,ts]=l.useState(!1),[Gs,_s]=l.useState(null),[Ue,Fr]=l.useState(25),[Rr,Hs]=l.useState(!1),{triggerFireworks:Br}=Pa(),$s=l.useRef(new Map),Dt=l.useRef(0),ss=l.useCallback(()=>{Dt.current+=1,ke.current&&Hs(!0)},[]),rs=l.useCallback(()=>{Dt.current=Math.max(0,Dt.current-1),ke.current&&Dt.current===0&&Hs(!1)},[]),[ns,Mt]=l.useState(new Set),[Dr,Ws]=l.useState(new Set),[as,Us]=l.useState(!1),[Mr,Er]=l.useState(0),[Tr,Ks]=l.useState(!1),[is,os]=l.useState(De?.generatedHighlights??[]),Ar=Dr.size>0||le.size()>0||le.isRunning(),Js=l.useCallback(()=>{const s=Os.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),ls=$||G?.projectDirectory||null,cs=m?.current||null,Lr=l.useMemo(()=>{const s=m?.tracking;return s?s.startsWith("origin/"):!0},[m?.tracking]),qs=l.useMemo(()=>{const s=G?.createdFromBranch,a=typeof s=="string"?s.trim():"",o=typeof m?.current=="string"?m.current.trim():"",c=typeof Ie=="string"?Ie.trim():"";return a?a===o&&a.startsWith("opencode/")&&c.length>0&&c!==a?c:a:c||o||"HEAD"},[G?.createdFromBranch,m,Ie]),Et=l.useCallback(()=>{os([])},[]),[ds,Or]=l.useState(new Set),[Tt,zr]=l.useState(new Map),[At,us]=l.useState(new Set),ms=l.useRef(Tt),St=l.useRef(At),[Gr,vt]=l.useState(null),[xt,hs]=l.useState(null),[Ys,Qs]=l.useState(""),[Me,Lt]=l.useState(null),[_r,Xs]=l.useState(!1),[Hr,Zs]=l.useState(!1),[gs,fs]=l.useState([]),[$r,er]=l.useState(null),[tr,ps]=l.useState(null),[Wr,Ot]=l.useState([]),[Ur,Ke]=l.useState(!1),[Kr,Qe]=l.useState([]),[zt,Xe]=l.useState("merge"),[Jr,xs]=l.useState(null),[ws,sr]=l.useState(!1),[ys,qr]=l.useState(100),[Yr,Qr]=l.useState(0),Je=l.useMemo(()=>h?`openchamber.conflict:${h}`:null,[h]),st=l.useCallback((s,a,o)=>{if(!Je||typeof window>"u")return;const c={directory:s,conflictFiles:a,operation:o};window.localStorage.setItem(Je,JSON.stringify(c))},[Je]),He=l.useCallback(()=>{!Je||typeof window>"u"||window.localStorage.removeItem(Je)},[Je]);l.useEffect(()=>{if(!Je||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Je);if(s)try{const a=JSON.parse(s);if(a.directory!==r){window.localStorage.removeItem(Je);return}Qe(a.conflictFiles??[]),Xe(a.operation??"merge"),Ke(!0)}catch{window.localStorage.removeItem(Je)}},[Je,r]);const[Xr,bs]=l.useState(!1),[vs,rr]=l.useState("merge"),[js,nr]=l.useState(""),Zr=l.useCallback(s=>{Ca(s).then(a=>{if(a.ok){v.success(e("gitView.toast.commitHashCopied"));return}v.error(e("gitView.toast.copyFailed"))})},[e]),en=l.useCallback(s=>{Or(a=>{const o=new Set(a);return o.has(s)?o.delete(s):o.add(s),o})},[]);l.useEffect(()=>{ms.current=Tt},[Tt]),l.useEffect(()=>{St.current=At},[At]),l.useEffect(()=>{if(!r||!n)return;const s=Array.from(ds).filter(o=>!ms.current.has(o)&&!St.current.has(o));if(s.length===0)return;let a=!1;return us(o=>{const c=new Set(o);for(const N of s)c.add(N);return St.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||(zr(c=>{const N=new Map(c);for(const{hash:z,files:ne}of o)N.set(z,ne);return ms.current=N,N}),us(c=>{const N=new Set(c);for(const{hash:z}of o)N.delete(z);return St.current=N,N}))}),()=>{a=!0,us(o=>{let c=!1;const N=new Set(o);for(const z of s)N.delete(z)&&(c=!0);return c?(St.current=N,N):o})}},[ds,r,n]),l.useEffect(()=>{if(!r)return;const s=yt.get(r)??null;Ge(s?.commitMessage??""),os(s?.generatedHighlights??[])},[r]),l.useEffect(()=>{r&&Mi(r,{directory:r,commitMessage:Ae,generatedHighlights:is})},[Ae,r,is]),l.useEffect(()=>{i&&(k(),R(),I())},[i,k,R,I]),l.useEffect(()=>{if(!i)return;if(!r||!n?.getRemoteUrl||B!==!0){hs(null);return}let s=!1;return n.getRemoteUrl(r).then(a=>{s||hs(a)}).catch(()=>{s||hs(null)}),()=>{s=!0}},[i,r,n,B]);const Gt=l.useCallback(async()=>{if(!r||!n?.getRemotes||B!==!0){fs([]);return}try{const s=await n.getRemotes(r);ke.current&&fs(s)}catch{ke.current&&fs([])}},[r,n,B]);l.useEffect(()=>{i&&Gt()},[i,Gt]),l.useEffect(()=>{i&&u&&r&&(de(u),g(r,n))},[i,u,r,de,g,n]),l.useEffect(()=>{if(i&&r)return Na.onGitRefreshHint(s=>{rt(s.directory)===rt(r)&&(s.paths?.length&&K(r,s.paths),d(r,n,{silent:!0}))})},[i,K,r,d,n]);const re=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([d(r,n),P(r,n)])}catch(a){if(s){const o=a instanceof Error?a.message:e("gitView.toast.refreshRepositoryFailed");v.error(o)}}},[r,n,d,P,e]),ye=l.useCallback(async()=>{r&&await M(r,n,Ue)},[r,n,M,Ue]),Cs=l.useCallback(async()=>{r&&await ae(r,n)},[r,n,ae]);l.useEffect(()=>{if(!i||!r||!n?.hasLocalIdentity||B!==!0)return;const s=typeof D=="string"?D.trim():"";if(!s||s==="global"||$s.current.get(r)===s)return;let o=!1;return(async()=>{try{const N=await n.hasLocalIdentity?.(r);if(o||N===!0)return;ss(),await n.setGitIdentity(r,s),$s.current.set(r,s),await Cs()}catch(N){console.warn("Failed to auto-apply default git identity:",N)}finally{o||rs()}})(),()=>{o=!0}},[i,ss,r,D,rs,n,B,Cs]);const ot=l.useMemo(()=>m?[...m.files??[]].sort((a,o)=>a.path.localeCompare(o.path)):[],[m]),$e=l.useMemo(()=>ot.filter(Cr),[ot]),Ns=l.useMemo(()=>ot.filter(Ei),[ot]);l.useEffect(()=>{if(!r||ot.length===0)return;const s=[],a=new Set,o=N=>{!N||a.has(N)||(a.add(N),s.push(N))};if($e.forEach(N=>o(N.path)),tt.forEach(o),ot.slice(0,Ri).forEach(N=>o(N.path)),s.length===0)return;const c=window.setTimeout(()=>{te(r,n,s,{maxFiles:Fi})},120);return()=>{window.clearTimeout(c)}},[ot,r,n,te,$e,tt]);const ar=s=>s?.pushed[0]?.remote||m?.tracking?.split("/")[0]||We.find(a=>a.name==="origin")?.name||We[0]?.name||"origin",ir=async(s,a)=>{if(r){Bt(s);try{const o=c=>{const N=`${c.name}/`,z=m?.tracking?.startsWith(N)?m.tracking.slice(N.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}),v.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));v.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);v.success(e("gitView.toast.pushedToUpstream",{name:ar(c)}))}else if(s==="sync"){if(!a)throw new Error("No remote available for sync");let c=0,N=!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){v.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),N=!0),c>0&&N?v.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:a.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:a.name})):c>0?v.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:a.name})):N?v.success(e("gitView.toast.pushedToUpstream",{name:a.name})):v.success(e("gitView.toast.alreadyUpToDate"))}await re(!1),await ye()}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});v.error(c)}finally{Bt(null)}}},tn=l.useCallback(async s=>{if(!r)return;const a=s.name.trim();if(!a){v.error(e("gitView.toast.remoteNameRequired"));return}if(a==="origin"){v.error(e("gitView.toast.cannotRemoveOriginRemote"));return}er(a);try{await n.removeRemote(r,{remote:a}),v.success(e("gitView.toast.removedRemote",{name:a})),await Promise.all([re(!1),Gt()])}catch(o){const c=o instanceof Error?o.message:`Failed to remove ${a}`;v.error(c)}finally{er(null)}},[r,n,Gt,re,e]),or=async(s={})=>{if(!r)return;if(!Ae.trim()){v.error(e("gitView.toast.enterCommitMessage"));return}const a=$e.map(c=>c.path).sort();if(a.length===0){v.error(e("gitView.toast.stageFileToCommit"));return}const o=s.pushAfter?"commitAndPush":"commit";_s(o);try{if(await n.createGitCommit(r,Ae.trim(),{files:a,stageFiles:[]}),Q(r),v.success(e("gitView.toast.commitCreated")),Ge(""),Et(),await re(),s.pushAfter){const c=m?.tracking?.split("/")[0],N=We.find(Dn=>Dn.name===c)??We[0];if(!N)throw new Error(e("mobile.changes.noRemote"));Bt("sync");const z=`${N.name}/`,ne=m?.tracking?.startsWith(z)?m.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:N.name});const U=await n.getGitStatus(r);if((U.behind??0)>0){if((U.files?.length??0)>0){v.error(e("gitView.toast.commitOrStashBeforeSync")),await re(!1);return}await n.gitPull(r,{remote:N.name,branch:ne,rebase:!0})}const ze=await n.getGitStatus(r);let jt;(ze.ahead??0)>0&&(jt=await n.gitPush(r)),v.success(e("gitView.toast.pushedToUpstream",{name:ar(jt)})),Br(),await re(!1)}else await re(!1);await ye(),Er(c=>c+1)}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");v.error(N)}finally{_s(null),s.pushAfter&&Bt(null)}},sn=l.useCallback(async()=>{if(!r)return;const s=$e.map(a=>a.path).sort();if(s.length===0){v.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),Ks(!0);try{const{message:a}=await Sa(r,s),o=a.subject?.trim()??"",c=Array.isArray(a.highlights)?a.highlights:[];if(o){let N=o;if(Te&&xe.length>0){const z=Bi(o,xe);if(z){const{code:ne,emoji:U}=z;!o.startsWith(ne)&&!o.startsWith(U)&&(N=`${ne} ${o}`)}}Ge(N)}os(c),Js()}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");v.error(o)}finally{Ks(!1)}},[r,$e,Te,xe,Js,e]),Ss=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",rn=async(s,a)=>{if(!r||!m)return;const o=Is(T);if(o.length>0){v.error(e("gitView.toast.cannotCreateBranch",{reason:Ss(o[0])}));return}const c=m.current??null,N=a?.name??"origin";try{await n.createBranch(r,s,c??"HEAD"),v.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(r,s);let z=!1;try{await n.gitPush(r,{remote:N,branch:s,options:["--set-upstream"]}),z=!0}catch(ne){const U=ne instanceof Error?ne.message:`Unable to push new branch to ${N}.`;v.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",U]})})}await re(),await ye(),z&&v.success(e("gitView.toast.upstreamSet",{branch:s,remote:N}))}catch(z){const ne=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw v.error(ne),z}},nn=async(s,a)=>{if(!r)return;const o=Is(T);if(o.length>0){v.error(e("gitView.toast.cannotRenameBranch",{reason:Ss(o[0])}));return}try{await n.renameBranch(r,s,a),v.success(e("gitView.toast.renamedBranch",{oldName:s,newName:a})),await re(),await ye()}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});v.error(N)}},an=async s=>{if(!r)return;const a=Is(T);if(a.length>0){v.error(e("gitView.toast.cannotCheckout",{reason:Ss(a[0])}));return}const o=s.replace(/^remotes\//,"");if(m?.current!==o)try{const c=await n.checkoutBranch(r,o);v.success(e("gitView.toast.checkedOut",{name:c?.branch||o})),await re(),await ye()}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});v.error(N)}},on=async s=>{if(r){ss();try{await n.setGitIdentity(r,s.id),v.success(e("gitView.toast.appliedIdentity",{name:s.name})),await Cs()}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.applyIdentityFailed");v.error(o)}finally{rs()}}},kt=l.useMemo(()=>_?.all?_.all.filter(s=>!s.startsWith("remotes/")).sort():[],[_]),lt=l.useMemo(()=>_?.all?_.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[_]),We=l.useMemo(()=>{if(gs.length>0)return gs;const s=new Set,a=m?.tracking?.trim();a&&a.includes("/")&&s.add(a.split("/")[0]);for(const o of lt){const c=o.indexOf("/");c>0&&s.add(o.slice(0,c))}return s.size===0&&xt&&s.add("origin"),Array.from(s).map(o=>({name:o,fetchUrl:xt??"",pushUrl:xt??""}))},[gs,lt,xt,m?.tracking]),ct=m?.current??null,lr=l.useMemo(()=>{const s=m?.tracking?.trim().split("/")[0];return(s&&_?.defaultBranches?.[s])??_?.defaultBranches?.origin},[_,m?.tracking]),wt=l.useMemo(()=>Fa({remoteNames:new Set(We.map(s=>s.name)),localBranches:kt,worktreeCreatedFromBranch:G?.createdFromBranch,rootBranchHint:Ie,defaultBranch:lr,headBranch:ct}),[ct,lr,We,kt,Ie,G?.createdFromBranch]),ln=l.useMemo(()=>We.map(o=>o.name).map(o=>`${o}/${wt}`).find(o=>lt.includes(o))??wt,[wt,We,lt]),cn=l.useMemo(()=>{const s=new Map;y&&s.set(y.id,y);let a=null;if(xt)try{let o=xt.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 C){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())},[C,y,xt]),dn=l.useMemo(()=>{if(H?.userName&&H?.userEmail){const s=C.find(a=>a.userName===H.userName&&a.userEmail===H.userEmail);return s||(y&&y.userName===H.userName&&y.userEmail===H.userEmail?y:{id:"local-config",name:H.userName,userName:H.userName,userEmail:H.userEmail,sshKey:H.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return y??null},[H,C,y]),un=$e.length,mn=ce||zs!==null||Gs!==null,hn=!!(G&&ls&&cs&&Lr),cr=!!ct,dt=hn&&ls&&cs&&G?{repoRoot:ls,sourceBranch:cs,worktreeMetadata:G}:null;l.useEffect(()=>{if(!r||!n||!Z?.all?.length||!ct||!wt||ct===wt){vt(null);return}let s=!1;return(async()=>{try{const o=await n.getGitLog(r,{from:wt,to:"HEAD",maxCount:Ue});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){vt(null);return}const N=Z.all.findIndex(z=>!c.has(z.hash));if(N===0){vt(null);return}if(N===-1){vt({insertBeforeIndex:Z.all.length,branchName:ct,direction:"up"});return}vt({insertBeforeIndex:N,branchName:ct,direction:"up"})}catch{s||vt(null)}})(),()=>{s=!0}},[wt,ct,r,n,Z,Ue]),l.useEffect(()=>{xs(null)},[r]),l.useEffect(()=>{if(Me!=="graph"||!r){Me!=="graph"&&xs(null);return}let s=!1;return sr(!0),n.getGitLog(r,{maxCount:ys,all:!0}).then(a=>{s||xs(a)}).catch(a=>{console.error("Failed to fetch graph log:",a)}).finally(()=>{s||sr(!1)}),()=>{s=!0}},[Me,r,ys,Yr,n]);const Vt=l.useCallback((s,a)=>{if(!r||s.length===0)return;const o=Array.from(new Set(s));Ws(N=>{const z=new Set(N);return o.forEach(ne=>z.add(ne)),z});const c=we(r,o,a);le.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>se(r,c)}),Ve()},[r,le,we,se,Ve]),ks=l.useCallback(async s=>{if(r){Mt(a=>{const o=new Set(a);return o.add(s),o});try{await n.revertGitFile(r,s,{scope:"working"}),v.success(e("gitView.toast.revertedFile",{path:s})),await re(!1)}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.revertFailed");v.error(o)}finally{Mt(a=>{const o=new Set(a);return o.delete(s),o})}}},[r,re,n,e]),_t=l.useCallback(async(s,a,o="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(as||c.some(U=>ns.has(U)))return;const N=new Set($e.map(U=>U.path)),z=o==="all"&&c.some(U=>N.has(U));a&&Us(!0),Mt(U=>{const ze=new Set(U);return c.forEach(jt=>ze.add(jt)),ze});const ne=[];try{if(await Promise.all(c.map(async U=>{try{await n.revertGitFile(r,U,{scope:o})}catch(ze){ne.push({path:U,message:ze instanceof Error?ze.message:e("gitView.toast.revertFailed")})}})),z&&ne.length<c.length&&Q(r),await re(!1),ne.length===0)v.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(ne.length===c.length)v.error(ne[0]?.message||e("gitView.toast.revertFailed"));else{const U=c.length-ne.length;v.warning(U===1?e("gitView.toast.revertedSomeSingle",{success:U,failed:ne.length}):e("gitView.toast.revertedSomePlural",{success:U,failed:ne.length}))}}finally{Mt(U=>{const ze=new Set(U);return c.forEach(jt=>ze.delete(jt)),ze}),a&&Us(!1)}},[Q,r,n,as,re,ns,$e,e]),gn=l.useCallback(async s=>{await _t(s,!0)},[_t]),fn=l.useCallback(async s=>{await _t(s,!1,"working")},[_t]),Vs=l.useCallback((s,a)=>{if(u&&!me){he(u,s,a);return}qe(s,a)},[u,me,qe,he]),pn=l.useCallback(()=>ts(!0),[]),xn=l.useMemo(()=>{const s=[];return $e.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:$e,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:a=>e("gitView.changes.unstageFileAria",{path:a}),onActionFile:a=>{Vt([a],"unstage")},onActionAll:a=>{Vt(a,"unstage")},onViewDiff:a=>Vs(a,!0),onRevertFile:ks,showRevertActions:!1,accent:!0}),Ns.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ns,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:a=>e("gitView.changes.stageFileAria",{path:a}),onActionFile:a=>{Vt([a],"stage")},onActionAll:a=>{Vt(a,"stage")},onViewDiff:a=>Vs(a,!1),onRevertFile:ks}),s},[ks,Vs,Vt,$e,e,Ns]),wn=l.useCallback(s=>{if(s.length===0)return;const a=s.map(o=>o.trim()).filter(Boolean);if(a.length===0){Et();return}Ge(o=>{const c=o.trim(),N=c.length>0?`
4
+
5
+ `:"";return`${c}${N}${a.join(`
6
+ `)}`.trim()}),Et()},[Et]),yn=l.useCallback((s,a)=>{const o=a||s;Ge(c=>{const N=c.trimStart();return N.startsWith(s)||a&&N.startsWith(a)?c:`${o.endsWith(" ")?o:`${o} `}${c}`.trimStart()}),Qs(""),it(!1)},[]),Ht=l.useCallback(s=>{const a=s instanceof Error?s.message.toLowerCase():"";return a.includes("uncommitted changes")||a.includes("local changes")||a.includes("your local changes would be overwritten")||a.includes("please commit your changes or stash them")||a.includes("cannot rebase: you have unstaged changes")||a.includes("error: cannot pull with rebase")},[]),ut=l.useCallback((s,a)=>{Ot(o=>[...o,{message:s,status:a,timestamp:Date.now()}])},[]),Oe=l.useCallback((s,a)=>{Ot(o=>{if(o.length===0)return o;const c=[...o];return c[c.length-1]={...c[c.length-1],status:s,...a?{message:a}:{}},c})},[]),$t=l.useCallback(()=>{Ot([])},[]),bn=l.useCallback(()=>{Ot([]),ps(null)},[]),Wt=l.useCallback(s=>{const a=s.trim(),o=new Set(We.map(N=>N.name)),c=a.indexOf("/");if(c>0){const N=a.slice(0,c),z=a.slice(c+1);if(o.has(N)&&z)return{branch:a,remote:N,remoteBranch:z}}for(const N of We){const z=`${N.name}/${a}`;if(lt.includes(z))return{branch:z,remote:N.name,remoteBranch:a}}return{branch:a,remote:null,remoteBranch:null}},[We,lt]),vn=l.useCallback(async s=>{if(!r)return;ps("merge"),$t();const a=m?.current,o=Wt(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Oe("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Merging ${o.branch} into ${a}...`,"running");const c=await n.merge(r,{branch:o.branch});c.conflict?(Oe("error","Merge conflicts detected"),Qe(c.conflictFiles??[]),Xe("merge"),Ke(!0),st(r,c.conflictFiles??[],"merge")):(Oe("done",`Merged ${o.branch} into ${a}`),He(),ut("Refreshing repository status...","running"),await re(),await ye(),Oe("done","Repository status updated"))}catch(c){if(Ht(c))Oe("error","Uncommitted changes detected"),rr("merge"),nr(o.branch),bs(!0);else{const N=c instanceof Error?c.message:`Failed to merge ${o.branch}`;Oe("error",N)}}},[r,n,m,Wt,re,ye,Ht,st,He,ut,Oe,$t]),jn=l.useCallback(async s=>{if(!r)return;ps("rebase"),$t();const a=m?.current,o=Wt(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Oe("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Rebasing ${a} onto ${o.branch}...`,"running");const c=await n.rebase(r,{onto:o.branch});c.conflict?(Oe("error","Rebase conflicts detected"),Qe(c.conflictFiles??[]),Xe("rebase"),Ke(!0),st(r,c.conflictFiles??[],"rebase")):(Oe("done",`Rebased ${a} onto ${o.branch}`),He(),ut("Refreshing repository status...","running"),await re(),await ye(),Oe("done","Repository status updated"))}catch(c){if(Ht(c))Oe("error","Uncommitted changes detected"),rr("rebase"),nr(o.branch),bs(!0);else{const N=c instanceof Error?c.message:`Failed to rebase onto ${o.branch}`;Oe("error",N)}}},[r,n,m,Wt,re,ye,Ht,st,He,ut,Oe,$t]),Cn=l.useCallback(async()=>{if(r)try{zt==="merge"?(await n.abortMerge(r),v.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),v.success(e("gitView.toast.rebaseAborted"))),He(),await re(),await ye()}catch(s){const a=s instanceof Error?s.message:`Failed to abort ${zt}`;v.error(a)}},[r,n,zt,re,ye,He,e]),Nn=l.useMemo(()=>m?.files?m.files.filter(s=>s.index==="U"||s.working_dir==="U"||s.index==="A"&&s.working_dir==="A"||s.index==="D"&&s.working_dir==="D").length:0,[m?.files]),Sn=l.useCallback(async()=>{if(r)try{const s=!!m?.mergeInProgress?.head,a=!!(m?.rebaseInProgress?.headName||m?.rebaseInProgress?.onto);if(s){const o=await n.continueMerge(r);o.conflict?(Qe(o.conflictFiles??[]),Xe("merge"),Ke(!0),st(r,o.conflictFiles??[],"merge"),v.error(e("gitView.toast.mergeConflictsDetected"))):(He(),v.success(e("gitView.toast.mergeCompleted")),await re(),await ye())}else if(a){const o=await n.continueRebase(r);o.conflict?(Qe(o.conflictFiles??[]),Xe("rebase"),Ke(!0),st(r,o.conflictFiles??[],"rebase"),v.error(e("gitView.toast.rebaseConflictsDetected"))):(He(),v.success(e("gitView.toast.rebaseStepCompleted")),await re(),await ye())}}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");v.error(a)}},[r,n,m,re,ye,st,He,e]),kn=l.useCallback(async()=>{if(r)try{!!m?.mergeInProgress?.head?(await n.abortMerge(r),v.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),v.success(e("gitView.toast.rebaseAborted"))),He(),await re(),await ye()}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");v.error(a)}},[r,n,m,re,ye,He,e]),Vn=l.useCallback(()=>{if(!r)return;const a=!!m?.mergeInProgress?.head?"merge":"rebase",o=m?.files?.filter(c=>c.index==="U"||c.working_dir==="U").map(c=>c.path)??[];o.length>0&&Qe(o),Xe(a),Ke(!0)},[r,m]),In=l.useCallback(async s=>{if(!r)return;const a=m?.current,o=vs,c=js,N=(m?.files??[]).some(Cr);try{await n.stash(r,{message:`Auto-stash before ${o} with ${c}`,includeUntracked:!0}),N&&Q(r)}catch(U){const ze=U instanceof Error?U.message:"Failed to stash changes";v.error(ze);return}let z=!1,ne=!1;try{if(o==="merge"){const U=await n.merge(r,{branch:c});U.conflict?(ne=!0,Qe(U.conflictFiles??[]),Xe("merge"),Ke(!0)):(z=!0,v.success(e("gitView.toast.mergedIntoBranch",{branch:c,currentBranch:a||""})))}else{const U=await n.rebase(r,{onto:c});U.conflict?(ne=!0,Qe(U.conflictFiles??[]),Xe("rebase"),Ke(!0)):(z=!0,v.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:a||"",branch:c})))}if(s&&z)try{await n.stashPop(r),Q(r),v.success(e("gitView.toast.stashedRestored"))}catch(U){const ze=U instanceof Error?U.message:e("gitView.toast.restoreStashFailed");v.error(ze)}else s&&ne&&v.info(e("gitView.toast.restoreStashManually"));await re(),await ye()}catch(U){if(s)try{await n.stashPop(r),Q(r)}catch{}throw U}},[Q,r,n,m,vs,js,re,ye,e]),Pn=l.useCallback(s=>{Fr(s),r&&(J(r,s),M(r,n,s))},[r,M,n,J]),Fn=l.useCallback(s=>{qr(s)},[]),Rn=l.useCallback(()=>{Lt(null),r&&(d(r,n),P(r,n),M(r,n,Ue))},[r,d,P,M,Ue,n]),Bn=l.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){v.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(d(r,n),P(r,n),M(r,n,Ue));return}Qe(s.conflictFiles??[]),Xe(s.operation),Ke(!0),r&&st(r,s.conflictFiles??[],s.operation)}},[e,Qe,Xe,Ke,st,r,d,P,M,Ue,n]);return u?B===null||B===!0&&!m?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):B===!1?Ee?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[t.jsx(A,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):t.jsx(Ea,{rootIsGitRepo:F,resolvedIsGitRepo:B,nestedRepos:Y,onRetryDiscovery:()=>{u&&Ne(u,{force:!0})},emptyStateFooter:ee.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):void 0}):t.jsxs("div",{className:Ce("flex h-full flex-col overflow-hidden"),children:[t.jsx(Ta,{status:m,localBranches:kt,remoteBranches:lt,branchInfo:_?.branches,syncAction:zs,remotes:We,onFetch:s=>ir("fetch",s),onSync:s=>ir("sync",s),onRemoveRemote:tn,removingRemoteName:$r,onCheckoutBranch:an,onCreateBranch:rn,onRenameBranch:nn,activeIdentityProfile:dn,availableIdentities:cn,onSelectIdentity:on,isApplyingIdentity:Rr,isWorktreeMode:!!G,onOpenHistory:()=>Lt("history"),onOpenGraph:()=>Lt("graph"),onOpenStashes:pn,onOpenUpdateBranch:cr?()=>Xs(!0):void 0,onOpenReintegrateCommits:dt?()=>Zs(!0):void 0,pullRequest:ue?.pr??null,prChecks:ue?.checks??null,onOpenPullRequest:r?()=>Pe(r,"pr"):void 0,repositoryOptions:r!==u&&Array.isArray(Y)?Y:void 0,selectedRepository:r!==u?r:null,onSelectRepository:r!==u&&u?s=>ve(u,s):void 0,repositoryRoot:r!==u?u:void 0}),u&&(m?.mergeInProgress?.head||m?.rebaseInProgress?.headName||m?.rebaseInProgress?.onto)&&t.jsx(yi,{mergeInProgress:m?.mergeInProgress,rebaseInProgress:m?.rebaseInProgress,onContinue:Sn,onAbort:kn,onResolveWithAI:Vn,conflictCount:Nn,isLoading:ce}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:Ce("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(Sr,{as:ka,ref:Os,outerClassName:"flex-1 min-h-0",className:Ce("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(ot?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(La,{groups:xn,diffStats:m?.diffStats,revertingPaths:ns,isRevertingAll:as,onVisiblePathsChange:nt,onRevertAll:gn,onRevertDirectory:fn,headerBackgroundClassName:"bg-background"})}),t.jsx(Oa,{stagedCount:un,commitMessage:Ae,onCommitMessageChange:Ge,generatedHighlights:is,onInsertHighlights:wn,onGenerateMessage:sn,isGeneratingMessage:Tr,onCommit:()=>or({pushAfter:!1}),onCommitAndPush:()=>or({pushAfter:!0}),commitAction:Gs,hasPendingIndexMutation:Ar,gitmojiEnabled:Te,onOpenGitmojiPicker:()=>it(!0)})]}):t.jsx(Xa,{onOpenStashes:()=>ts(!0)})})})})})}),t.jsx(ht,{open:_r,onOpenChange:s=>{!s&&tr!==null||Xs(s)},children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.branch.updateTitle")}),t.jsxs(bt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:m?.current??""}),"."]})]}),cr?t.jsx(bi,{mode:"bare",currentBranch:m?.current,localBranches:kt,remoteBranches:lt,defaultTargetBranch:ln,onMerge:vn,onRebase:jn,disabled:mn,isOperating:tr!==null,operationLogs:Wr,onOperationComplete:bn}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(ht,{open:Hr,onOpenChange:Zs,children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.integrate.title")}),t.jsx(bt,{children:dt?t.jsxs("span",{className:"font-mono text-foreground",children:[dt.sourceBranch," → ",qs]}):null})]}),dt?t.jsx(Ya,{repoRoot:dt.repoRoot,sourceBranch:dt.sourceBranch,worktreeMetadata:dt.worktreeMetadata,localBranches:kt,defaultTargetBranch:qs,refreshKey:Mr,showHeader:!1,onRefresh:()=>{r&&(d(r,n),P(r,n),M(r,n,Ue))}},dt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:Me!==null,onOpenChange:s=>{s||Lt(null)},children:t.jsxs(gt,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(pt,{children:e(Me==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(Me==="graph"){Qr(s=>s+1);return}r&&M(r,n,Ue)},disabled:Me==="graph"?ws:ie,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(A,{name:"refresh",className:Ce("size-4",(Me==="graph"?ws:ie)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(bt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(oi,{mode:Me==="graph"?"graph":"history",log:Me==="graph"?Jr??Z:Z,isLogLoading:Me==="graph"&&ws||ie,logMaxCount:Me==="graph"?ys:Ue,onLogMaxCountChange:Me==="graph"?Fn:Pn,expandedCommitHashes:ds,onToggleCommit:en,commitFilesMap:Tt,loadingCommitHashes:At,onCopyHash:Zr,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Me==="graph"?null:Gr,onConflict:Me==="graph"?Bn:void 0,onActionSuccess:Me==="graph"?Rn:void 0})})]})}),t.jsx(Qa,{open:Pr,onOpenChange:ts,directory:r,hasUncommittedChanges:(m?.files?.length??0)>0,hasStagedChanges:$e.length>0,uncommittedFileCount:m?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&Q(r),await re(!1),await ye()}}),t.jsx(ht,{open:at,onOpenChange:it,children:t.jsxs(gt,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(pt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Es,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(Ts,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:Ys,onValueChange:Qs}),t.jsxs(As,{children:[t.jsx(Ls,{children:e("gitView.gitmoji.empty")}),t.jsx(Yt,{children:Rt(xe,Ys,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(Qt,{onSelect:()=>yn(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),r&&t.jsx(mi,{open:Ur,onOpenChange:Ke,conflictFiles:Kr,directory:r,operation:zt,onAbort:Cn,onClearState:He}),t.jsx(wi,{open:Xr,onOpenChange:bs,operation:vs,targetBranch:js,onConfirm:In})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{Xl as GitView};
@@ -1 +1 @@
1
- import{fd as M,h5 as Z,h6 as Fe,gS as Ce,gT as ke,gU as Ie,gV as ze,g$ as Ne,g_ as Ve,f as Oe,B as ee,I as te,hm as Pe}from"./useAppFontEffects-Cll4gnsh.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-DLnGY4fs.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-CZlLSacm.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-Gi1d5eU1.js";import{a as F,i as K,l as pe,h as St,r as vt}from"./isFilePlainText-CVKy_dgB.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{fn as M,hk as Z,hl as Fe,h5 as Ce,h6 as ke,h7 as Ie,h8 as ze,he as Ne,hd as Ve,f as Oe,B as ee,I as te,hB as Pe}from"./useAppFontEffects-DWXGRUPZ.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-CD-GFayc.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-CZlLSacm.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-DmpLWhll.js";import{a as F,i as K,l as pe,h as St,r as vt}from"./isFilePlainText-D8qPqUAf.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};