ryco-cli 0.1.10 → 0.1.11

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 (233) hide show
  1. package/dist/bin.cjs +1 -1
  2. package/dist/bin.mjs +1 -1
  3. package/dist/client/assets/AccountSettings-BUoiS8x1.js +1 -0
  4. package/dist/client/assets/AiFocusSettings-Cz1Uqn7a.js +1 -0
  5. package/dist/client/assets/AnimatedHeight-BIsV_Z3J.js +1 -0
  6. package/dist/client/assets/AppearanceSettings-CYbSApl4.js +1 -0
  7. package/dist/client/assets/{BranchToolbar.logic-C1Dh4xQW.js → BranchToolbar.logic-LIanCEVr.js} +1 -1
  8. package/dist/client/assets/ChatRightPanel-CKEjpQ_x.js +27 -0
  9. package/dist/client/assets/ChatThreadRouteView-D50onHY2.js +1 -0
  10. package/dist/client/assets/CommandPaletteDialog-DdRKgZ8m.js +1 -0
  11. package/dist/client/assets/{CompositeItem-D-K93PI3.js → CompositeItem-F3NGn6aG.js} +1 -1
  12. package/dist/client/assets/CompositeRoot-CmJGfRtc.js +1 -0
  13. package/dist/client/assets/ConnectionsSettings--CbTzkTn.js +7 -0
  14. package/dist/client/assets/DiagnosticsSettings-C74u3ce5.js +2 -0
  15. package/dist/client/assets/{DialogHandle-pL0RAsXa.js → DialogHandle-C4uSr9wX.js} +1 -1
  16. package/dist/client/assets/DialogPopup-Dck8r8Hn.js +1 -0
  17. package/dist/client/assets/DialogRoot-BpIvUdm7.js +1 -0
  18. package/dist/client/assets/{DialogTitle-BamZsRNz.js → DialogTitle-CCedPAjV.js} +1 -1
  19. package/dist/client/assets/{DialogTrigger-DR3vtVpa.js → DialogTrigger-CYJ7_YcV.js} +1 -1
  20. package/dist/client/assets/DialogViewport-D-CrTM-P.js +1 -0
  21. package/dist/client/assets/DraftChatThreadRouteView-RTmLGTl0.js +1 -0
  22. package/dist/client/assets/{GlassSurface-DTmaROoR.js → GlassSurface-C3IIWMu9.js} +1 -1
  23. package/dist/client/assets/HostedConnectionControls-CKiC01ju.js +1 -0
  24. package/dist/client/assets/HostedHubRoot-BS3rAYTy.js +1 -0
  25. package/dist/client/assets/HostedNativeAuthorizationRoute-BFTDyh4N.js +1 -0
  26. package/dist/client/assets/HostedRelayTrustNotice-eEOPKsBg.js +1 -0
  27. package/dist/client/assets/Icons-CT3nd2MA.js +1 -0
  28. package/dist/client/assets/IntegrationsSettingsPanel-Cg4eRHm_.js +1 -0
  29. package/dist/client/assets/KeybindingsSettings-CYj67N2D.js +7 -0
  30. package/dist/client/assets/McpServersSettings-Bc61hRUY.js +6 -0
  31. package/dist/client/assets/MobileSheet-CkeG6_SP.js +1 -0
  32. package/dist/client/assets/NewWorktreeDialog-CTlFjKa4.js +4 -0
  33. package/dist/client/assets/NoActiveThreadState-Dw9aoU2J.js +1 -0
  34. package/dist/client/assets/NodeSecuritySettings-DMkkTgfg.js +1 -0
  35. package/dist/client/assets/OpinionatedPluginsSettings-CeoSmZ90.js +1 -0
  36. package/dist/client/assets/PhoneGetAppInterstitial-7ZxxVbUB.js +1 -0
  37. package/dist/client/assets/PhoneGetAppInterstitialBackdrop-B8vfJdZd.js +1 -0
  38. package/dist/client/assets/PhoneHome-DRRoCd_y.js +1 -0
  39. package/dist/client/assets/PhoneSettingsSurface-LNEaPHQC.js +1 -0
  40. package/dist/client/assets/ProjectFavicon-BIMdZxK6.js +1 -0
  41. package/dist/client/assets/ProviderModelPicker-jd6GjQkO.js +1 -0
  42. package/dist/client/assets/ProvidersSettingsPanel-v2SvoEGx.js +1 -0
  43. package/dist/client/assets/RedactedSensitiveText-CxtaUiKH.js +1 -0
  44. package/dist/client/assets/RootAppShell-CFjrYjtn.js +6 -0
  45. package/dist/client/assets/RycoLetterMark-Bk0kvGJ_.js +1 -0
  46. package/dist/client/assets/SettingsDialog-CvGTsSV0.js +1 -0
  47. package/dist/client/assets/SettingsPanels-BmhZ8u4B.js +3 -0
  48. package/dist/client/assets/SettingsPanels.editor-B2x4U4rW.js +1 -0
  49. package/dist/client/assets/SourceControlSettings-DvPydmxX.js +1 -0
  50. package/dist/client/assets/StatisticsPage-Duk2cHVH.js +1 -0
  51. package/dist/client/assets/StatisticsPanel-D-uNJcdj.js +1 -0
  52. package/dist/client/assets/StatisticsSettingsLink-Cx43bOeo.js +1 -0
  53. package/dist/client/assets/ThreadStatusIndicators-D0xoATCw.js +0 -0
  54. package/dist/client/assets/{ThreadTerminalDrawer-BYQ6EMgr.js → ThreadTerminalDrawer-DjX8p7IH.js} +3 -3
  55. package/dist/client/assets/{ThreadWorkspacePanel-DuaQ9DMj.js → ThreadWorkspacePanel-DI0GXPBf.js} +18 -18
  56. package/dist/client/assets/{ToolbarRootContext-Cp1bgmpz.js → ToolbarRootContext-BgqqXVly.js} +1 -1
  57. package/dist/client/assets/{WorkItemsTab-BDfun24H.js → WorkItemsTab-ow45makA.js} +8 -8
  58. package/dist/client/assets/alert-LqMhbdE9.js +1 -0
  59. package/dist/client/assets/alert-dialog-DxoA6ky8.js +1 -0
  60. package/dist/client/assets/badge-CXw6fWrB.js +1 -0
  61. package/dist/client/assets/{branding-yW_ACj9l.js → branding-C8SLy6Af.js} +1 -1
  62. package/dist/client/assets/button-BAbJxRzt.js +1 -0
  63. package/dist/client/assets/{capabilities-j43xmCXg.js → capabilities-BQuqC7jg.js} +1 -1
  64. package/dist/client/assets/collapsible-dxy6kc2k.js +1 -0
  65. package/dist/client/assets/command-CGNKG_Oe.js +1 -0
  66. package/dist/client/assets/composerDraftStore-CdJJZe42.js +11 -0
  67. package/dist/client/assets/data-list-CYKBxN62.js +1 -0
  68. package/dist/client/assets/{desktopUpdateAtoms-Cy06xm8M.js → desktopUpdateAtoms-C82GmR67.js} +1 -1
  69. package/dist/client/assets/{desktopWorkspace-Cw4Fu0Dd.js → desktopWorkspace-G5Z_JRbm.js} +1 -1
  70. package/dist/client/assets/{device-hx7RX9fI.js → device-B56cBWWt.js} +12 -12
  71. package/dist/client/assets/dialog-DQsYchqu.js +1 -0
  72. package/dist/client/assets/draft-input-CkzOk8BY.js +1 -0
  73. package/dist/client/assets/{editorPreferences-C3i2Nkh2.js → editorPreferences-CTDEj79K.js} +1 -1
  74. package/dist/client/assets/empty-DwzqNgCP.js +1 -0
  75. package/dist/client/assets/{getPseudoElementBounds-NLvUMZyQ.js → getPseudoElementBounds-X62ElHN8.js} +1 -1
  76. package/dist/client/assets/group-D9ER9giz.js +1 -0
  77. package/dist/client/assets/{index-COc-h_V9.js → index-Bbz4fkK_.js} +1 -1
  78. package/dist/client/assets/input-CHEwW3oH.js +1 -0
  79. package/dist/client/assets/kbd-DCGQZk18.js +1 -0
  80. package/dist/client/assets/{keybindings-BCns_TPr.js → keybindings-CWJ7E9ZI.js} +1 -1
  81. package/dist/client/assets/label-CVFHsLFO.js +1 -0
  82. package/dist/client/assets/{lib-BBbQoz14.js → lib-qiiNMGgU.js} +1 -1
  83. package/dist/client/assets/{main-9Wu8G64Y.js → main-Dwu2cT6v.js} +3 -3
  84. package/dist/client/assets/menu-Dvxh8sD5.js +1 -0
  85. package/dist/client/assets/popover-CuH9Yrj3.js +1 -0
  86. package/dist/client/assets/{projectPaths-DSRhOXwD.js → projectPaths-lDhAE9o_.js} +1 -1
  87. package/dist/client/assets/{providerDriverMeta-DcAmgw5o.js → providerDriverMeta-I0TSo-QI.js} +1 -1
  88. package/dist/client/assets/providerIconUtils-DnSYUN9l.js +1 -0
  89. package/dist/client/assets/providerInstances-BJcfB_9E.js +1 -0
  90. package/dist/client/assets/providerModels-BJcfB_9E.js +1 -0
  91. package/dist/client/assets/qr-code-Bddq6K7S.js +1 -0
  92. package/dist/client/assets/radio-group-CBZFr4C8.js +2 -0
  93. package/dist/client/assets/resolveAriaLabelledBy-CD_ugzhJ.js +1 -0
  94. package/dist/client/assets/{rightPanelRouteSearch-DE_7uWlN.js → rightPanelRouteSearch-DB5gQGHK.js} +1 -1
  95. package/dist/client/assets/runtime-DKwoXpJv.js +1 -0
  96. package/dist/client/assets/scroll-area-Drsa8bNB.js +1 -0
  97. package/dist/client/assets/scrollEdges-B-cqxY4l.js +1 -0
  98. package/dist/client/assets/select-BYbVr-yg.js +1 -0
  99. package/dist/client/assets/separator-CdS5bi4Z.js +1 -0
  100. package/dist/client/assets/{session-logic-DOQPF0oN.js → session-logic-DElAta-Z.js} +1 -1
  101. package/dist/client/assets/settingsDialogStore-ygYoScKe.js +1 -0
  102. package/dist/client/assets/settingsLayout-D8glO7f1.js +1 -0
  103. package/dist/client/assets/sheet-BO78gIKZ.js +1 -0
  104. package/dist/client/assets/sidebar-Dm6l2GA6.js +1 -0
  105. package/dist/client/assets/sidebarProjectFolders-Cs13ZUN8.js +4 -0
  106. package/dist/client/assets/{sidebarStatusText-DaNVnBiR.js → sidebarStatusText-D0HT0fek.js} +1 -1
  107. package/dist/client/assets/skeleton-CvQSeJbw.js +1 -0
  108. package/dist/client/assets/spinner-ClF0jOcX.js +1 -0
  109. package/dist/client/assets/storeSelectors-Cq_JKyiF.js +1 -0
  110. package/dist/client/assets/switch-BTGo9Yip.js +1 -0
  111. package/dist/client/assets/{terminal-links-BaX-ICJT.js → terminal-links-CZ3c9AbA.js} +1 -1
  112. package/dist/client/assets/textarea-RFPODxWW.js +1 -0
  113. package/dist/client/assets/{threadPriorityRefreshRuntime-DqqfcbZE.js → threadPriorityRefreshRuntime-DJF5drVD.js} +1 -1
  114. package/dist/client/assets/toast-CcSCAm4B.js +1 -0
  115. package/dist/client/assets/toggle-I6h33Cu5.js +1 -0
  116. package/dist/client/assets/toggle-group-mLIkiJtU.js +1 -0
  117. package/dist/client/assets/tooltip-C8sAONBj.js +1 -0
  118. package/dist/client/assets/types-Cq_JKyiF.js +1 -0
  119. package/dist/client/assets/{uiStateStore-VVodpTkG.js → uiStateStore-B6pjzSjj.js} +1 -1
  120. package/dist/client/assets/{useAtlassian-DzQhYzCz.js → useAtlassian-Bx2ua3JV.js} +0 -0
  121. package/dist/client/assets/{useButton-CQaIys_r.js → useButton-D__1LqCF.js} +1 -1
  122. package/dist/client/assets/useCompositeListItem-Cmr_nuuG.js +1 -0
  123. package/dist/client/assets/{useDebouncedValue-Dl2JtWSe.js → useDebouncedValue-DHjoudTq.js} +1 -1
  124. package/dist/client/assets/{useFloatingRootContext-DKAeq7FI.js → useFloatingRootContext-D5EZmrCa.js} +1 -1
  125. package/dist/client/assets/{useHandleNewThread-CzfIpG9Y.js → useHandleNewThread-DHO0PWGZ.js} +1 -1
  126. package/dist/client/assets/{useLabelableId-C7EOshps.js → useLabelableId-DnQJ7amm.js} +1 -1
  127. package/dist/client/assets/useLocation-CDeYzWW6.js +1 -0
  128. package/dist/client/assets/{useOpenInteractionType-D9ngong8.js → useOpenInteractionType-CjtpACKR.js} +1 -1
  129. package/dist/client/assets/usePhoneThreadActions-OTf7yIbN.js +1 -0
  130. package/dist/client/assets/usePopupViewport-BuhsNdVy.js +1 -0
  131. package/dist/client/assets/useScrollLock-D3tMGsRk.js +1 -0
  132. package/dist/client/assets/{useStatistics-CP8uxvx6.js → useStatistics-DEtKeVPP.js} +14 -14
  133. package/dist/client/assets/{useSwipeDismiss-DESLmDpT.js → useSwipeDismiss-CbgDJvw1.js} +1 -1
  134. package/dist/client/assets/{useThreadActions-fOb3ApmL.js → useThreadActions-DLxhOMkz.js} +1 -1
  135. package/dist/client/assets/{useTriggerFocusGuards-DkAmJBLw.js → useTriggerFocusGuards-CrugmkhX.js} +1 -1
  136. package/dist/client/assets/{useValueChanged-CSGMZCwN.js → useValueChanged-MQtIzPIU.js} +1 -1
  137. package/dist/client/assets/utils-BofFIn5Y.js +1 -0
  138. package/dist/client/index.html +1 -1
  139. package/package.json +1 -1
  140. package/dist/client/assets/AccountSettings-CxbiGHT-.js +0 -1
  141. package/dist/client/assets/AiFocusSettings-Cx2vpGdu.js +0 -1
  142. package/dist/client/assets/AnimatedHeight-D5lUTPRn.js +0 -1
  143. package/dist/client/assets/AppearanceSettings-eWri4YVm.js +0 -1
  144. package/dist/client/assets/ChatRightPanel-DAVHrLN_.js +0 -27
  145. package/dist/client/assets/ChatThreadRouteView-D11uiGPL.js +0 -1
  146. package/dist/client/assets/CommandPaletteDialog-DDXuLFyX.js +0 -1
  147. package/dist/client/assets/CompositeRoot-Cee5L4T9.js +0 -1
  148. package/dist/client/assets/ConnectionsSettings-Cf1RRkcn.js +0 -7
  149. package/dist/client/assets/DiagnosticsSettings-R00QjM1b.js +0 -2
  150. package/dist/client/assets/DialogPopup-DqvvwMxX.js +0 -1
  151. package/dist/client/assets/DialogRoot-BZCu6XdB.js +0 -1
  152. package/dist/client/assets/DialogViewport-CuRGvCfw.js +0 -1
  153. package/dist/client/assets/DraftChatThreadRouteView-CGMtPPGt.js +0 -1
  154. package/dist/client/assets/HostedConnectionControls-CXiER4OL.js +0 -1
  155. package/dist/client/assets/HostedHubRoot-MbaWk1RQ.js +0 -1
  156. package/dist/client/assets/HostedNativeAuthorizationRoute-DQ71L_yc.js +0 -1
  157. package/dist/client/assets/HostedRelayTrustNotice-Cv7T3mW5.js +0 -1
  158. package/dist/client/assets/Icons-DjUJVKIP.js +0 -1
  159. package/dist/client/assets/IntegrationsSettingsPanel-BUDT_BAr.js +0 -1
  160. package/dist/client/assets/KeybindingsSettings-DpU1kPiV.js +0 -7
  161. package/dist/client/assets/McpServersSettings-DQqM_vIq.js +0 -6
  162. package/dist/client/assets/MobileSheet-PksVmYO6.js +0 -1
  163. package/dist/client/assets/NewWorktreeDialog-CAe3UUk5.js +0 -4
  164. package/dist/client/assets/NoActiveThreadState-B020r2KX.js +0 -1
  165. package/dist/client/assets/NodeSecuritySettings-DlVOOlej.js +0 -1
  166. package/dist/client/assets/OpinionatedPluginsSettings-DMshW6cD.js +0 -1
  167. package/dist/client/assets/PhoneGetAppInterstitial-BCO-RNVk.js +0 -1
  168. package/dist/client/assets/PhoneGetAppInterstitialBackdrop-CkHNzjRm.js +0 -1
  169. package/dist/client/assets/PhoneHome-DY2ItxYl.js +0 -1
  170. package/dist/client/assets/PhoneSettingsSurface-DTP9FXLL.js +0 -1
  171. package/dist/client/assets/ProjectFavicon-Dopa4Rxy.js +0 -1
  172. package/dist/client/assets/ProviderModelPicker-ChoxerzY.js +0 -1
  173. package/dist/client/assets/ProvidersSettingsPanel-Ubea3yAA.js +0 -1
  174. package/dist/client/assets/RedactedSensitiveText-CdVeknPX.js +0 -1
  175. package/dist/client/assets/RootAppShell-BkUPk443.js +0 -6
  176. package/dist/client/assets/RycoLetterMark-GW-n9UxM.js +0 -1
  177. package/dist/client/assets/SettingsDialog-DMPrhOeR.js +0 -1
  178. package/dist/client/assets/SettingsPanels-ChP1z6Bu.js +0 -3
  179. package/dist/client/assets/SettingsPanels.editor-CiyAxlms.js +0 -1
  180. package/dist/client/assets/SourceControlSettings-8w3XlkuZ.js +0 -1
  181. package/dist/client/assets/StatisticsPage-D4lU63rD.js +0 -1
  182. package/dist/client/assets/StatisticsPanel-C2yBieuM.js +0 -1
  183. package/dist/client/assets/StatisticsSettingsLink-DZwvRI-Y.js +0 -1
  184. package/dist/client/assets/ThreadStatusIndicators-B43wkv-s.js +0 -0
  185. package/dist/client/assets/alert-DdU9OGtC.js +0 -1
  186. package/dist/client/assets/alert-dialog-zAmnOpaF.js +0 -1
  187. package/dist/client/assets/badge-CNPL77i3.js +0 -1
  188. package/dist/client/assets/button-CXfaxtRp.js +0 -1
  189. package/dist/client/assets/collapsible-oJfDmFRs.js +0 -1
  190. package/dist/client/assets/command-DK1D8p4-.js +0 -1
  191. package/dist/client/assets/composerDraftStore-BaAeiPHc.js +0 -11
  192. package/dist/client/assets/data-list-BpzwKa1z.js +0 -1
  193. package/dist/client/assets/dialog-JVv-MNDj.js +0 -1
  194. package/dist/client/assets/draft-input-CxoGkZxM.js +0 -1
  195. package/dist/client/assets/empty-DhkXzm1N.js +0 -1
  196. package/dist/client/assets/group-CafmSbGU.js +0 -1
  197. package/dist/client/assets/input-Bz9pd_f3.js +0 -1
  198. package/dist/client/assets/kbd-qh5s29Yp.js +0 -1
  199. package/dist/client/assets/label-Ct6uH6qL.js +0 -1
  200. package/dist/client/assets/menu-DL-18Hfn.js +0 -1
  201. package/dist/client/assets/popover-C9y_0-ZN.js +0 -1
  202. package/dist/client/assets/providerIconUtils-DSXSWHwg.js +0 -1
  203. package/dist/client/assets/providerInstances-D5NRn-MS.js +0 -1
  204. package/dist/client/assets/providerModels-D5NRn-MS.js +0 -1
  205. package/dist/client/assets/qr-code-DsN9sWfN.js +0 -1
  206. package/dist/client/assets/radio-group-DGUZYMAN.js +0 -2
  207. package/dist/client/assets/resolveAriaLabelledBy-l3Wj7Mso.js +0 -1
  208. package/dist/client/assets/runtime-CqhG6EOG.js +0 -1
  209. package/dist/client/assets/scroll-area-gtur6NxN.js +0 -1
  210. package/dist/client/assets/scrollEdges-Ccq9Jqpk.js +0 -1
  211. package/dist/client/assets/select-BB7zCkpA.js +0 -1
  212. package/dist/client/assets/separator-DOGIr29S.js +0 -1
  213. package/dist/client/assets/settingsDialogStore-DM98Sea0.js +0 -1
  214. package/dist/client/assets/settingsLayout-CS7P71tz.js +0 -1
  215. package/dist/client/assets/sheet-DVALF6mw.js +0 -1
  216. package/dist/client/assets/sidebar-Dft4bIEi.js +0 -1
  217. package/dist/client/assets/sidebarProjectFolders-BOfJCYjK.js +0 -4
  218. package/dist/client/assets/skeleton-CBHDWLDX.js +0 -1
  219. package/dist/client/assets/spinner-JhkVC8d7.js +0 -1
  220. package/dist/client/assets/storeSelectors-CP3vrsGY.js +0 -1
  221. package/dist/client/assets/switch-vkC1QGDn.js +0 -1
  222. package/dist/client/assets/textarea-Cz_x76EQ.js +0 -1
  223. package/dist/client/assets/toast-Bnfw8LOb.js +0 -1
  224. package/dist/client/assets/toggle-DNtHlm45.js +0 -1
  225. package/dist/client/assets/toggle-group-BNtjyirT.js +0 -1
  226. package/dist/client/assets/tooltip-lYatfjuN.js +0 -1
  227. package/dist/client/assets/types-CP3vrsGY.js +0 -1
  228. package/dist/client/assets/useCompositeListItem-D_u_nlWz.js +0 -1
  229. package/dist/client/assets/useLocation-CvhfNIUj.js +0 -1
  230. package/dist/client/assets/usePhoneThreadActions-CiFBnOHD.js +0 -1
  231. package/dist/client/assets/usePopupViewport-CQTeg5Y-.js +0 -1
  232. package/dist/client/assets/useScrollLock-TdF-Iq8H.js +0 -1
  233. package/dist/client/assets/utils-BPUctpTG.js +0 -1
@@ -1,7 +1,7 @@
1
- import{i as e,t}from"./react-SIfiwpqq.js";import{t as n}from"./compiler-runtime-qmuS0Svy.js";import{_ as r,g as i,t as a,y as o}from"./env-B4arEvJg.js";import{ii as s}from"./src-Vf4LVnMX.js";import{$t as c,Et as l,In as u,Jn as d,Jt as f,Ot as p,Pt as m,Qt as h,Rn as g,Sn as _,St as v,Un as y,Zt as b,en as x,f as S,hn as C,mn as w,nn as T,tn as E,wt as D}from"./runtime-CqhG6EOG.js";import{Tt as O,_t as k,ht as A}from"./primary-OskAInOO.js";import{t as j}from"./useDebouncedValue-Dl2JtWSe.js";import{P as ee,_t as M,i as te,vt as N}from"./composerDraftStore-BaAeiPHc.js";import{f as P,l as ne,t as F}from"./utils-BPUctpTG.js";import{c as re,d as ie,l as ae}from"./useSwipeDismiss-DESLmDpT.js";import{t as oe}from"./useRouter-CcIDS3PN.js";import{_ as se,a as I,c as ce,d as le,f as ue,g as de,i as fe,l as pe,m as L,o as R,p as me,r as z,s as he,t as ge,u as _e}from"./rightPanelRouteSearch-DE_7uWlN.js";import{t as ve}from"./useNavigate-2tVq4iZ2.js";import{f as B}from"./useRenderElement-DchFnsR8.js";import{t as ye}from"./arrow-left-Dtj9PfsA.js";import{t as be}from"./bot-DJp0cuhK.js";import{n as xe,t as V}from"./loader-circle-CrtHFAvM.js";import{t as Se}from"./chevron-down-B7C6FKzM.js";import{c as Ce,o as we}from"./tabSwitchInstrumentation-CLDM7g1_.js";import{t as Te}from"./chevron-right-BWYGybX9.js";import{n as Ee}from"./useFloatingRootContext-DKAeq7FI.js";import{t as De}from"./circle-alert-BWvs6IOn.js";import{i as H}from"./toast-Bnfw8LOb.js";import{t as U}from"./clock-3-r12DkpRj.js";import{C as Oe}from"./lib-BBbQoz14.js";import{t as ke}from"./folder-closed-CsvKfC6X.js";import{t as W}from"./folder-open-GqwNTbSV.js";import{t as G}from"./folder-DtsQoI9_.js";import{$ as Ae,$t as je,A as Me,At as Ne,B as Pe,Bt as Fe,Ct as Ie,Dt as Le,Et as Re,F as ze,Ft as K,G as Be,Gt as Ve,H as He,Ht as Ue,I as We,It as Ge,J as Ke,Jt as qe,K as Je,Kt as Ye,L as Xe,Lt as Ze,M as Qe,Mt as $e,N as et,Nt as tt,Ot as nt,P as rt,Pt as it,Q as at,Qt as ot,R as st,Rt as ct,St as lt,Tt as ut,U as dt,Ut as ft,V as pt,Vt as mt,W as ht,Wt as gt,X as _t,Xt as vt,Y as yt,Yt as bt,Z as xt,Zt as St,_t as Ct,at as wt,bt as Tt,c as Et,ct as Dt,d as Ot,dt as kt,en as At,et as jt,ft as Mt,g as Nt,gt as Pt,h as Ft,ht as It,in as Lt,it as Rt,j as zt,jt as Bt,k as Vt,kt as Ht,l as Ut,lt as Wt,m as Gt,mt as Kt,n as qt,nn as Jt,nt as Yt,ot as Xt,p as Zt,pt as Qt,q as $t,qt as en,r as tn,rn as nn,rt as rn,s as an,st as on,t as sn,tn as cn,tt as ln,u as un,ut as dn,vt as fn,wt as pn,xt as q,yt as mn,z as hn,zt as gn}from"./device-hx7RX9fI.js";import{t as _n}from"./minimize-2-C33mL7LT.js";import{t as vn}from"./plus-B2h-VEqh.js";import{t as yn}from"./refresh-cw-DopCMrtR.js";import{t as bn}from"./save-Bh36JIv6.js";import{t as xn}from"./search-BGQsenCM.js";import{t as Sn}from"./smartphone-gNe1ynB8.js";import{t as Cn}from"./ThreadTerminalDrawer-BYQ6EMgr.js";import{i as wn}from"./terminal-links-BaX-ICJT.js";import{t as Tn}from"./terminal-C_CyIsDD.js";import{t as En}from"./triangle-alert-RL_T3KLo.js";import{t as Dn}from"./unplug-Cw8iawyX.js";import{t as On}from"./x-C1Cemsov.js";import{_ as kn,a as An,g as jn,m as Mn,n as Nn,t as Pn,v as Fn,y as In}from"./session-logic-DOQPF0oN.js";import"./storeSelectors-CP3vrsGY.js";import{o as Ln}from"./timestampFormat-8uPXS812.js";import{_ as Rn}from"./keybindings-BCns_TPr.js";import{i as zn,n as Bn,t as Vn}from"./tooltip-lYatfjuN.js";import{t as Hn}from"./scroll-area-gtur6NxN.js";import{t as Un}from"./button-CXfaxtRp.js";import{n as Wn}from"./composerHandleContext-BrQ6d8r9.js";import{i as Gn,r as Kn,t as qn}from"./alert-DdU9OGtC.js";import{n as Jn,t as Yn}from"./sidebarStatusText-DaNVnBiR.js";import{a as Xn,i as Zn,o as Qn,r as $n,s as er,t as tr}from"./alert-dialog-zAmnOpaF.js";import{n as nr}from"./editorPreferences-C3i2Nkh2.js";import{t as rr}from"./badge-CNPL77i3.js";import{t as ir}from"./useTheme-DiC-5xCb.js";import{n as ar,t as or}from"./toggle-group-BNtjyirT.js";import{t as sr}from"./toggle-DNtHlm45.js";var J=e(t(),1);function cr(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if(`shouldBlockFn`in e)return e;if(typeof e==`function`){let n=!!(t??!0);return{shouldBlockFn:async()=>n?await e():!1,enableBeforeUnload:n,withResolver:!1}}let n=!!(e.condition??!0),r=e.blockerFn;return{shouldBlockFn:async()=>n&&r!==void 0?await r():n,enableBeforeUnload:n,withResolver:r===void 0}}function lr(e,t){let{shouldBlockFn:n,enableBeforeUnload:r=!0,disabled:i=!1,withResolver:a=!1}=cr(e,t),o=oe(),{history:s}=o,[c,l]=J.useState({status:`idle`,current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return J.useEffect(()=>i?void 0:s.block({blockerFn:async e=>{function t(e){let t=o.parseLocation(e),[,n,r]=o.getMatchedRoutes(t.pathname);return r===void 0?{routeId:`__notFound__`,fullPath:t.pathname,pathname:t.pathname,params:n,search:o.options.parseSearch(e.search)}:{routeId:r.id,fullPath:r.fullPath,pathname:t.pathname,params:n,search:o.options.parseSearch(e.search)}}let r=t(e.currentLocation),i=t(e.nextLocation);if(r.routeId===`__notFound__`&&i.routeId!==`__notFound__`)return!1;let s=await n({action:e.action,current:r,next:i});if(!a)return s;if(!s)return!1;let c=await new Promise(t=>{l({status:`blocked`,current:r,next:i,action:e.action,proceed:()=>t(!1),reset:()=>t(!0)})});return l({status:`idle`,current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),c},enableBeforeUnload:r}),[n,r,i,a,s,o]),c}var ur=B(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),dr=B(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),fr=B(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),pr=B(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),mr=B(`disc-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M6 12c0-1.7.7-3.2 1.8-4.2`,key:`oqkarx`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`M18 12c0 1.7-.7 3.2-1.8 4.2`,key:`1eah9h`}]]),hr=B(`git-compare`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M13 6h3a2 2 0 0 1 2 2v7`,key:`1yeb86`}],[`path`,{d:`M11 18H8a2 2 0 0 1-2-2V9`,key:`19pyzm`}]]),gr=B(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),_r=B(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),vr=B(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),yr=B(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),br=B(`monitor-off`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M17 17H4a2 2 0 0 1-2-2V5a2 2 0 0 1 1.184-1.826`,key:`cv7jms`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`path`,{d:`M8.656 3H20a2 2 0 0 1 2 2v10a2 2 0 0 1-.293 1.042`,key:`z8ni2w`}]]),xr=B(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),Sr=B(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),Cr=B(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),wr=B(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Tr=B(`rows-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),Er=B(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),Dr=B(`volume-1`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}]]),Or=B(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),Y=n(),X=P(),kr={pending:{dotClass:`bg-info`,label:`Working`},running:{dotClass:`bg-info`,label:`Working`},waiting:{dotClass:`bg-info`,label:`Working`},idle:{dotClass:`bg-muted-foreground/50`,label:`Idle · resumable`},completed:{dotClass:`bg-success`,label:`Completed`},failed:{dotClass:`bg-destructive`,label:`Failed`},cancelled:{dotClass:`bg-muted-foreground/60`,label:`Stopped`},interrupted:{dotClass:`bg-muted-foreground/60`,label:`Stopped`}},Ar=(0,J.createContext)({identities:new Map,onOpenAgent:null});function jr(e){let t=(0,Y.c)(4),{status:n}=e,r=kr[n],i;t[0]===r.dotClass?i=t[1]:(i=F(`size-1.5 shrink-0 rounded-full`,r.dotClass),t[0]=r.dotClass,t[1]=i);let a;return t[2]===i?a=t[3]:(a=(0,X.jsx)(`span`,{"aria-hidden":!0,className:i}),t[2]=i,t[3]=a),a}function Mr(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60);if(n===0)return`${t}s`;let r=Math.floor(n/60);return r===0?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${r}h ${String(n%60).padStart(2,`0`)}m`}function Nr(e,t){let n=Date.parse(e),r=t?Date.parse(t):Date.now();return Number.isNaN(n)||Number.isNaN(r)?``:Mr((r-n)/1e3)}function Pr(e){return e.usage?.durationMs===void 0?e.startedAt&&e.completedAt?Nr(e.startedAt,e.completedAt):null:Mr(e.usage.durationMs/1e3)}function Fr(e){let t=(0,Y.c)(12),{agent:n}=e,r=(0,J.useRef)(null),i=n.status===`running`||n.status===`waiting`,a=n.startedAt,o,s;if(t[0]!==i||t[1]!==a?(o=()=>{if(!i||!a)return;let e=()=>{r.current&&(r.current.textContent=Nr(a,null))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},s=[i,a],t[0]=i,t[1]=a,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,J.useEffect)(o,s),!i){let e;t[4]===n?e=t[5]:(e=Pr(n),t[4]=n,t[5]=e);let r=e,i;return t[6]===r?i=t[7]:(i=r?(0,X.jsx)(`span`,{className:`tabular-nums`,children:r}):null,t[6]=r,t[7]=i),i}if(!a)return null;let c;t[8]===a?c=t[9]:(c=Nr(a,null),t[8]=a,t[9]=c);let l;return t[10]===c?l=t[11]:(l=(0,X.jsx)(`span`,{ref:r,className:`tabular-nums`,children:c}),t[10]=c,t[11]=l),l}function Ir(e,t){return/^structured[\s_-]?output$/i.test(e)?t?`Delivering result`:`Delivered result`:t?`Using ${e}`:e}function Lr(e){return e.status===`running`||e.status===`pending`||e.status===`waiting`?e.progress??(e.lastToolName?Ir(e.lastToolName,!0):null)??e.result??e.error:e.error??e.result??e.progress??(e.lastToolName?Ir(e.lastToolName,!1):null)}function Rr(e){let t=(0,Y.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,X.jsx)(`div`,{className:`divide-y divide-border/30`,children:n}),t[0]=n,t[1]=r),r}function zr(e){let t=(0,Y.c)(11),{title:n}=e,r=`${n} pending`,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,X.jsx)(`span`,{"aria-hidden":!0,className:`flex size-7 items-center justify-center rounded-lg border border-dashed border-border/60 bg-background/30 text-muted-foreground/55`,children:(0,X.jsx)(U,{className:`size-3.5`})}),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,X.jsx)(`span`,{className:`block truncate text-sm font-medium text-foreground/75`,children:n}),t[1]=n,t[2]=a);let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,X.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground/65`,children:`Waiting for this stage to start`}),t[3]=o):o=t[3];let s;t[4]===a?s=t[5]:(s=(0,X.jsxs)(`span`,{className:`min-w-0`,children:[a,o]}),t[4]=a,t[5]=s);let c;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-[.68rem] text-muted-foreground/65`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-muted-foreground/40`}),`Pending`]}),t[6]=c):c=t[6];let l;return t[7]!==r||t[8]!==s||t[9]!==n?(l=(0,X.jsxs)(`div`,{"data-workflow-pending-step":!0,"data-phase-title":n,"aria-label":r,className:`grid h-14 grid-cols-[1.75rem_minmax(0,1fr)_auto] items-center gap-x-2 rounded-md px-1.5 py-1 text-left`,children:[i,s,c]}),t[7]=r,t[8]=s,t[9]=n,t[10]=l):l=t[10],l}function Br(e){let t=(0,Y.c)(69),{agent:n}=e,{identities:r,onOpenAgent:i}=(0,J.use)(Ar),a=kr[n.status],o;t[0]===n?o=t[1]:(o=Lr(n),t[0]=n,t[1]=o);let s=o,c;t[2]!==n.effort||t[3]!==n.model?(c=jn(n.model,n.effort),t[2]=n.effort,t[3]=n.model,t[4]=c):c=t[4];let l=c,u,d,f;t[5]!==n.id||t[6]!==n.title||t[7]!==r?(d=r.get(n.id),u=d?.codename??n.title,f=d?.role&&!In(d.role,u)&&!In(d.role,n.title)?d.role:null,t[5]=n.id,t[6]=n.title,t[7]=r,t[8]=u,t[9]=d,t[10]=f):(u=t[8],d=t[9],f=t[10]);let p=f,m=d?.taskLabel??n.title,h;t[11]===n.usage?h=t[12]:(h=n.usage?`${kn(n.usage.totalTokens)} tok`:`— tok`,t[11]=n.usage,t[12]=h);let g=n.usage?.toolUses===void 0?null:`${n.usage.toolUses} tools`,_=n.activationCount>1?`run ${n.activationCount}`:null,v;t[13]!==l||t[14]!==h||t[15]!==g||t[16]!==_?(v=[l,h,g,_].filter(Vr),t[13]=l,t[14]=h,t[15]=g,t[16]=_,t[17]=v):v=t[17];let y=v,b=d?.avatarKey??n.id,x;t[18]===b?x=t[19]:(x=(0,X.jsx)(At,{name:b,className:`size-5`}),t[18]=b,t[19]=x);let S;t[20]===n.status?S=t[21]:(S=(0,X.jsx)(`span`,{className:`absolute -right-0.5 -bottom-0.5 grid size-2.5 place-items-center rounded-full bg-background ring-1 ring-background`,children:(0,X.jsx)(jr,{status:n.status})}),t[20]=n.status,t[21]=S);let C;t[22]!==S||t[23]!==x?(C=(0,X.jsxs)(`span`,{"aria-hidden":!0,className:`relative col-start-1 row-span-3 row-start-1 mt-0.5 flex size-7 items-center justify-center rounded-lg border border-border/45 bg-background/45`,children:[x,S]}),t[22]=S,t[23]=x,t[24]=C):C=t[24];let w;t[25]===u?w=t[26]:(w=(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold tracking-[-0.01em]`,children:u}),t[25]=u,t[26]=w);let T;t[27]===p?T=t[28]:(T=p?(0,X.jsx)(`span`,{className:`max-w-32 shrink-0 truncate rounded-sm border border-border/60 bg-background/40 px-1.5 py-px text-[10px] font-medium text-muted-foreground`,children:p}):null,t[27]=p,t[28]=T);let E;t[29]!==w||t[30]!==T?(E=(0,X.jsxs)(`span`,{className:`col-start-2 row-start-1 flex min-w-0 items-center gap-1.5`,children:[w,T]}),t[29]=w,t[30]=T,t[31]=E):E=t[31];let D;t[32]===n?D=t[33]:(D=(0,X.jsx)(Fr,{agent:n}),t[32]=n,t[33]=D);let O;t[34]===n.status?O=t[35]:(O=n.status===`completed`?(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3 text-success`}):null,t[34]=n.status,t[35]=O);let k;t[36]!==D||t[37]!==O?(k=(0,X.jsx)(`span`,{className:`col-start-3 row-start-1 min-w-14 text-right font-mono text-[.7rem] text-muted-foreground/80`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[D,O]})}),t[36]=D,t[37]=O,t[38]=k):k=t[38];let A;t[39]===m?A=t[40]:(A=(0,X.jsx)(`span`,{className:`col-start-2 col-end-4 row-start-2 block truncate text-[11px] text-foreground/65`,title:m,children:m}),t[39]=m,t[40]=A);let j=n.status===`failed`?`text-destructive-foreground`:`text-muted-foreground`,ee;t[41]===j?ee=t[42]:(ee=F(`col-start-2 row-start-3 block min-w-0 truncate text-xs`,j),t[41]=j,t[42]=ee);let M=s??a.label,te=s??a.label,N;t[43]!==ee||t[44]!==M||t[45]!==te?(N=(0,X.jsx)(`span`,{className:ee,title:M,children:te}),t[43]=ee,t[44]=M,t[45]=te,t[46]=N):N=t[46];let P=y.join(` · `),ne;t[47]===P?ne=t[48]:(ne=(0,X.jsx)(`span`,{className:`col-start-3 row-start-3 max-w-40 truncate text-right font-mono text-[.68rem] tabular-nums text-muted-foreground/65`,children:P}),t[47]=P,t[48]=ne);let re;t[49]===a.label?re=t[50]:(re=(0,X.jsx)(`span`,{className:`sr-only`,children:a.label}),t[49]=a.label,t[50]=re);let ie;t[51]!==C||t[52]!==E||t[53]!==k||t[54]!==A||t[55]!==N||t[56]!==ne||t[57]!==re?(ie=(0,X.jsxs)(X.Fragment,{children:[C,E,k,A,N,ne,re]}),t[51]=C,t[52]=E,t[53]=k,t[54]=A,t[55]=N,t[56]=ne,t[57]=re,t[58]=ie):ie=t[58];let ae=ie,oe=i&&`hover:bg-accent/35 focus-visible:ring-2 focus-visible:ring-ring/50`,se;t[59]===oe?se=t[60]:(se=F(`grid h-[4.5rem] w-full grid-cols-[1.75rem_minmax(0,1fr)_auto] grid-rows-[1.375rem_1.125rem_1rem] items-center gap-x-2 rounded-md px-1.5 py-1 text-left outline-none transition-colors`,oe),t[59]=oe,t[60]=se);let I=se,ce;return t[61]!==n.id||t[62]!==I||t[63]!==u||t[64]!==ae||t[65]!==i||t[66]!==p||t[67]!==a.label?(ce=i?(0,X.jsx)(`button`,{type:`button`,className:I,"data-agent-row":!0,"data-agent-id":n.id,onClick:()=>i(n.id),"aria-label":`Open ${u}${p?`, ${p}`:``} transcript. ${a.label}.`,children:ae}):(0,X.jsx)(`div`,{className:I,"data-agent-row":!0,"data-agent-id":n.id,children:ae}),t[61]=n.id,t[62]=I,t[63]=u,t[64]=ae,t[65]=i,t[66]=p,t[67]=a.label,t[68]=ce):ce=t[68],ce}function Vr(e){return e!==null}function Hr(e){let t=e.workflow.status;return t!==`completed`&&t!==`failed`&&t!==`cancelled`&&t!==`interrupted`}function Ur(e){return[...e.phases.flatMap(e=>e.members),...e.unphasedMembers]}function Wr(e){let t=(0,Y.c)(4),{group:n}=e;if(n.phases.length===0)return null;let r;t[0]===n.phases?r=t[1]:(r=n.phases.map(Gr),t[0]=n.phases,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1 px-1.5 pb-1 pt-1.5`,children:r}),t[2]=r,t[3]=i),i}function Gr(e,t){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,X.jsx)(Te,{"aria-hidden":!0,className:`size-3 text-muted-foreground/40`}):null,(0,X.jsxs)(`div`,{className:F(`flex items-center gap-1 rounded-sm border px-1.5 py-0.5`,e.state===`running`?`border-info/40`:e.state===`done`?`border-success/30`:`border-border/50`),children:[(0,X.jsxs)(`span`,{className:F(`font-mono text-[.65rem]`,e.state===`running`?`text-info-foreground`:e.state===`done`?`text-success-foreground`:`text-muted-foreground/70`),children:[e.state===`done`?`✓ `:``,e.title]}),(0,X.jsx)(`span`,{className:`flex items-center gap-0.5`,children:e.members.length===0?(0,X.jsx)(`span`,{className:`font-mono text-[.6rem] text-muted-foreground/50`,children:`–`}):e.members.map(Kr)})]})]},e.index)}function Kr(e){return(0,X.jsx)(jr,{status:e.status},e.id)}var qr=15e3;function Jr(e){let t=(0,Y.c)(28),{environmentId:n,threadId:r,scriptPath:i,onClose:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={state:`loading`},t[0]=o):o=t[0];let[s,c]=(0,J.useState)(o),[l,u]=(0,J.useState)(0),d;t[1]!==n||t[2]!==i||t[3]!==r?(d=()=>{let e=!1,t;c({state:`loading`});let a=C(n)?.orchestration.getWorkflowScript;if(!a){c({state:`failed`});return}let o=new Promise((e,n)=>{t=setTimeout(()=>n(Error(`workflow script fetch timed out`)),qr)});return Promise.race([a({threadId:r,scriptPath:i}),o]).then(t=>{e||c({state:`loaded`,contents:t.contents,truncated:t.truncated})}).catch(()=>{e||c({state:`failed`})}).finally(()=>{t!==void 0&&clearTimeout(t)}),()=>{e=!0,t!==void 0&&clearTimeout(t)}},t[1]=n,t[2]=i,t[3]=r,t[4]=d):d=t[4];let f;t[5]!==l||t[6]!==n||t[7]!==i||t[8]!==r?(f=[n,r,i,l],t[5]=l,t[6]=n,t[7]=i,t[8]=r,t[9]=f):f=t[9],(0,J.useEffect)(d,f);let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,X.jsx)(ur,{"aria-hidden":!0,className:`size-3 text-muted-foreground`}),t[10]=p):p=t[10];let m;t[11]===i?m=t[12]:(m=i.split(`/`).at(-1),t[11]=i,t[12]=m);let h;t[13]===m?h=t[14]:(h=(0,X.jsx)(`span`,{className:`truncate font-mono text-[.65rem] text-muted-foreground`,children:m}),t[13]=m,t[14]=h);let g;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,X.jsx)(On,{"aria-hidden":!0,className:`size-3`}),t[15]=g):g=t[15];let _;t[16]===a?_=t[17]:(_=(0,X.jsx)(`button`,{type:`button`,onClick:a,"aria-label":`Close script`,className:`ml-auto text-muted-foreground hover:text-foreground`,children:g}),t[16]=a,t[17]=_);let v;t[18]!==h||t[19]!==_?(v=(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 px-2 py-1`,children:[p,h,_]}),t[18]=h,t[19]=_,t[20]=v):v=t[20];let y;t[21]!==s.contents||t[22]!==s.state||t[23]!==s.truncated?(y=(0,X.jsx)(`div`,{className:`max-h-72 overflow-auto p-2`,children:s.state===`loaded`?(0,X.jsxs)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[.7rem] leading-relaxed text-foreground/90`,children:[s.contents,s.truncated?`
2
- … (truncated)`:``]}):s.state===`failed`?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`p`,{className:`text-xs text-destructive-foreground`,children:`Could not load the script.`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(Yr),className:`text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground`,children:`Retry`})]}):(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading…`})}),t[21]=s.contents,t[22]=s.state,t[23]=s.truncated,t[24]=y):y=t[24];let b;return t[25]!==y||t[26]!==v?(b=(0,X.jsxs)(`div`,{className:`mx-1.5 mb-1 rounded-md border border-border/60 bg-background/60`,children:[v,y]}),t[25]=y,t[26]=v,t[27]=b):b=t[27],b}function Yr(e){return e+1}function Xr(e){let t=(0,Y.c)(33),{phase:n,defaultOpen:r}=e,[i,a]=(0,J.useState)(r!==void 0&&r||n.state===`running`),o=(0,J.useRef)(n.state),s,c;t[0]===n.state?(s=t[1],c=t[2]):(s=()=>{o.current!==`running`&&n.state===`running`&&a(!0),o.current=n.state},c=[n.state],t[0]=n.state,t[1]=s,t[2]=c),(0,J.useEffect)(s,c);let l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>a($r),t[3]=l):l=t[3];let u=n.state===`done`?`text-success-foreground`:n.state===`running`?`text-info-foreground`:`text-muted-foreground/70`,d;t[4]===u?d=t[5]:(d=F(`mt-2 flex w-full items-center gap-1.5 rounded-sm px-1.5 text-left text-[.65rem] font-medium uppercase tracking-wider hover:bg-accent/40`,u),t[4]=u,t[5]=d);let f;t[6]===i?f=t[7]:(f=i?(0,X.jsx)(Se,{"aria-hidden":!0,className:`size-3 shrink-0`}):(0,X.jsx)(Te,{"aria-hidden":!0,className:`size-3 shrink-0`}),t[6]=i,t[7]=f);let p;t[8]===n.state?p=t[9]:(p=n.state===`done`?(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3`}):null,t[8]=n.state,t[9]=p);let m;t[10]===n.title?m=t[11]:(m=(0,X.jsx)(`span`,{children:n.title}),t[10]=n.title,t[11]=m);let h=n.state===`pending`&&n.members.length===0?`pending`:n.state===`done`?`${n.settledCount} done`:`${n.activeCount} active · ${n.settledCount} done`,g;t[12]===h?g=t[13]:(g=(0,X.jsx)(`span`,{className:`font-normal normal-case text-muted-foreground/70`,children:h}),t[12]=h,t[13]=g);let _;t[14]!==i||t[15]!==n.members?(_=!i&&n.members.length>0?(0,X.jsx)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:n.members.map(Qr)}):null,t[14]=i,t[15]=n.members,t[16]=_):_=t[16];let v;t[17]!==i||t[18]!==g||t[19]!==_||t[20]!==d||t[21]!==f||t[22]!==p||t[23]!==m?(v=(0,X.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":i,className:d,children:[f,p,m,g,_]}),t[17]=i,t[18]=g,t[19]=_,t[20]=d,t[21]=f,t[22]=p,t[23]=m,t[24]=v):v=t[24];let y;t[25]!==i||t[26]!==n.members||t[27]!==n.state||t[28]!==n.title?(y=i?(0,X.jsx)(Rr,{children:n.members.length===0&&n.state===`pending`?(0,X.jsx)(zr,{title:n.title}):n.members.map(Zr)}):null,t[25]=i,t[26]=n.members,t[27]=n.state,t[28]=n.title,t[29]=y):y=t[29];let b;return t[30]!==v||t[31]!==y?(b=(0,X.jsxs)(`div`,{children:[v,y]}),t[30]=v,t[31]=y,t[32]=b):b=t[32],b}function Zr(e){return(0,X.jsx)(Br,{agent:e},e.id)}function Qr(e){return(0,X.jsx)(jr,{status:e.status},e.id)}function $r(e){return!e}function ei(e){let t=(0,Y.c)(47),{group:n,environmentId:r,threadId:i,onCollapse:a}=e,[o,s]=(0,J.useState)(!1),c,l;t[0]===n?(c=t[1],l=t[2]):(c=Ur(n),l=c.filter(ii),t[0]=n,t[1]=c,t[2]=l);let u=l.length,d=n.workflow.runHandles?.scriptPath,f=d!==void 0&&r!==null&&i!==null,p;t[3]===n.workflow.status?p=t[4]:(p=(0,X.jsx)(jr,{status:n.workflow.status}),t[3]=n.workflow.status,t[4]=p);let m=n.workflow.workflowName??n.workflow.title,h;t[5]===m?h=t[6]:(h=(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:m}),t[5]=m,t[6]=h);let g;t[7]!==f||t[8]!==o?(g=f?(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(ri),className:F(`rounded-sm border border-border/60 px-1 font-mono normal-case hover:text-foreground`,o&&`text-foreground`),"aria-expanded":o,children:[`{}`,` script`]}):null,t[7]=f,t[8]=o,t[9]=g):g=t[9];let _;t[10]!==c.length||t[11]!==u?(_=(0,X.jsxs)(`span`,{className:`ml-auto font-mono normal-case text-muted-foreground/80`,children:[u,`/`,c.length,` settled`]}),t[10]=c.length,t[11]=u,t[12]=_):_=t[12];let v;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,X.jsx)(Se,{"aria-hidden":!0,className:`size-3`}),t[13]=v):v=t[13];let y;t[14]===a?y=t[15]:(y=(0,X.jsx)(`button`,{type:`button`,onClick:a,"aria-label":`Collapse workflow`,className:`rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50`,children:v}),t[14]=a,t[15]=y);let b;t[16]!==p||t[17]!==h||t[18]!==g||t[19]!==_||t[20]!==y?(b=(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5 pt-0.5 text-[.65rem] font-medium uppercase tracking-wider text-muted-foreground`,children:[p,h,g,_,y]}),t[16]=p,t[17]=h,t[18]=g,t[19]=_,t[20]=y,t[21]=b):b=t[21];let x;t[22]===n?x=t[23]:(x=(0,X.jsx)(Wr,{group:n}),t[22]=n,t[23]=x);let S;t[24]!==f||t[25]!==r||t[26]!==o||t[27]!==d||t[28]!==i?(S=o&&f?(0,X.jsx)(Jr,{environmentId:r,threadId:i,scriptPath:d,onClose:()=>s(!1)}):null,t[24]=f,t[25]=r,t[26]=o,t[27]=d,t[28]=i,t[29]=S):S=t[29];let C;t[30]===n.phases?C=t[31]:(C=n.phases.map(ni),t[30]=n.phases,t[31]=C);let w;t[32]===n.unphasedMembers?w=t[33]:(w=n.unphasedMembers.map(ti),t[32]=n.unphasedMembers,t[33]=w);let T;t[34]===w?T=t[35]:(T=(0,X.jsx)(Rr,{children:w}),t[34]=w,t[35]=T);let E;t[36]!==n.phases.length||t[37]!==n.unphasedMembers.length||t[38]!==n.workflow?(E=n.phases.length===0&&n.unphasedMembers.length===0?(0,X.jsx)(Br,{agent:n.workflow}):null,t[36]=n.phases.length,t[37]=n.unphasedMembers.length,t[38]=n.workflow,t[39]=E):E=t[39];let D;return t[40]!==x||t[41]!==S||t[42]!==C||t[43]!==T||t[44]!==E||t[45]!==b?(D=(0,X.jsxs)(`section`,{className:`rounded-lg border border-border/50 bg-card/30 p-1.5`,children:[b,x,S,C,T,E]}),t[40]=x,t[41]=S,t[42]=C,t[43]=T,t[44]=E,t[45]=b,t[46]=D):D=t[46],D}function ti(e){return(0,X.jsx)(Br,{agent:e},e.id)}function ni(e){return(0,X.jsx)(Xr,{phase:e,defaultOpen:!0},e.index)}function ri(e){return!e}function ii(e){return e.status===`completed`||e.status===`failed`||e.status===`cancelled`||e.status===`interrupted`}function ai(e){let t=(0,Y.c)(45),{group:n,onExpand:r}=e,i,a,o,s,c,l,u,d,f,p,m,h,g;if(t[0]!==n||t[1]!==r){let e=Ur(n),_=e.filter(si).length,v=e.reduce(oi,e.length===0?n.workflow.usage?.totalTokens??0:0),y;t[15]!==n.workflow.completedAt||t[16]!==n.workflow.startedAt?(y=n.workflow.startedAt&&n.workflow.completedAt?Nr(n.workflow.startedAt,n.workflow.completedAt):null,t[15]=n.workflow.completedAt,t[16]=n.workflow.startedAt,t[17]=y):y=t[17],i=y,m=`button`,h=r,g=`flex w-full items-center gap-2 rounded-md px-1.5 py-1 text-left outline-none hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring/50`,o=!1;let b=_>0?`failed`:n.workflow.status;t[18]===b?s=t[19]:(s=(0,X.jsx)(jr,{status:b}),t[18]=b,t[19]=s);let x=n.workflow.workflowName??n.workflow.title;t[20]===x?c=t[21]:(c=(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:x}),t[20]=x,t[21]=c),d=`flex shrink-0 items-center gap-1.5 font-mono text-[.7rem] text-muted-foreground/80`,t[22]===_?f=t[23]:(f=_>0?(0,X.jsxs)(`span`,{className:`text-destructive-foreground`,children:[_,` failed`]}):null,t[22]=_,t[23]=f),p=(0,X.jsxs)(`span`,{children:[e.length,` agents`]}),a=`tabular-nums`,l=`· `,u=kn(v),t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=g}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14];let _;t[24]!==a||t[25]!==l||t[26]!==u?(_=(0,X.jsxs)(`span`,{className:a,children:[l,u,` tok`]}),t[24]=a,t[25]=l,t[26]=u,t[27]=_):_=t[27];let v;t[28]===i?v=t[29]:(v=i?(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[`· `,i]}):null,t[28]=i,t[29]=v);let y;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,X.jsx)(Te,{"aria-hidden":!0,className:`size-3`}),t[30]=y):y=t[30];let b;t[31]!==_||t[32]!==v||t[33]!==d||t[34]!==f||t[35]!==p?(b=(0,X.jsxs)(`span`,{className:d,children:[f,p,_,v,y]}),t[31]=_,t[32]=v,t[33]=d,t[34]=f,t[35]=p,t[36]=b):b=t[36];let x;return t[37]!==o||t[38]!==s||t[39]!==c||t[40]!==b||t[41]!==m||t[42]!==h||t[43]!==g?(x=(0,X.jsx)(`section`,{children:(0,X.jsxs)(`button`,{type:m,onClick:h,className:g,"aria-expanded":o,children:[s,c,b]})}),t[37]=o,t[38]=s,t[39]=c,t[40]=b,t[41]=m,t[42]=h,t[43]=g,t[44]=x):x=t[44],x}function oi(e,t){return e+(t.usage?.totalTokens??0)}function si(e){return e.status===`failed`}function ci(e){let t=(0,Y.c)(7),{group:n,environmentId:r,threadId:i}=e,a;t[0]===n?a=t[1]:(a=()=>Hr(n),t[0]=n,t[1]=a);let[o,s]=(0,J.useState)(a),c;return t[2]!==r||t[3]!==n||t[4]!==o||t[5]!==i?(c=o?(0,X.jsx)(ei,{group:n,environmentId:r,threadId:i,onCollapse:()=>s(!1)}):(0,X.jsx)(ai,{group:n,onExpand:()=>s(!0)}),t[2]=r,t[3]=n,t[4]=o,t[5]=i,t[6]=c):c=t[6],c}function li(e){let t=(0,Y.c)(43),{model:n,environmentId:r,threadId:i,onOpenAgent:a}=e,o=r===void 0?null:r,s=i===void 0?null:i,c=a===void 0?null:a,l;if(t[0]!==n.directAgents||t[1]!==n.workflows){let e=new Map;for(let t of n.workflows){e.set(t.workflow.id,t.workflow);for(let n of Ur(t))e.set(n.id,n)}for(let t of n.directAgents)e.set(t.id,t);l=Fn([...e.values()].map(di)),t[0]=n.directAgents,t[1]=n.workflows,t[2]=l}else l=t[2];let u;t[3]!==c||t[4]!==l?(u={identities:l,onOpenAgent:c},t[3]=c,t[4]=l,t[5]=u):u=t[5];let d=u;if(!n.hasAgents){let e;return t[6]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center`,children:[(0,X.jsx)(be,{"aria-hidden":!0,className:`size-6 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,X.jsx)(`p`,{className:`max-w-56 text-xs text-muted-foreground`,children:`When this thread spawns subagents or runs a workflow, they show up here with live status, activity, and token usage.`})]}),t[6]=e):e=t[6],e}let f;if(t[7]!==o||t[8]!==n.workflows||t[9]!==s){let e;t[11]!==o||t[12]!==s?(e=e=>(0,X.jsx)(ci,{group:e,environmentId:o,threadId:s},e.workflow.id),t[11]=o,t[12]=s,t[13]=e):e=t[13],f=n.workflows.map(e),t[7]=o,t[8]=n.workflows,t[9]=s,t[10]=f}else f=t[10];let p;t[14]===n.directAgents?p=t[15]:(p=n.directAgents.length>0?(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`div`,{className:`px-1.5 pt-1 text-[.65rem] font-medium uppercase tracking-wider text-muted-foreground`,children:`Direct spawns`}),(0,X.jsx)(Rr,{children:n.directAgents.map(ui)})]}):null,t[14]=n.directAgents,t[15]=p);let m;t[16]!==f||t[17]!==p?(m=(0,X.jsx)(Hn,{className:`min-h-0 flex-1`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 p-2`,children:[f,p]})}),t[16]=f,t[17]=p,t[18]=m):m=t[18];let h;t[19]!==n.runningCount||t[20]!==n.waitingCount?(h=n.runningCount+n.waitingCount>0?(0,X.jsxs)(`span`,{className:`text-info-foreground`,children:[`● `,n.runningCount+n.waitingCount,` working`]}):null,t[19]=n.runningCount,t[20]=n.waitingCount,t[21]=h):h=t[21];let g;t[22]===n.idleCount?g=t[23]:(g=n.idleCount>0?(0,X.jsxs)(`span`,{children:[n.idleCount,` idle`]}):null,t[22]=n.idleCount,t[23]=g);let _;t[24]===n.settledCount?_=t[25]:(_=n.settledCount>0?(0,X.jsxs)(`span`,{children:[n.settledCount,` settled`]}):null,t[24]=n.settledCount,t[25]=_);let v;t[26]!==g||t[27]!==_||t[28]!==h?(v=(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[h,g,_]}),t[26]=g,t[27]=_,t[28]=h,t[29]=v):v=t[29];let y;t[30]===n.totalTokens?y=t[31]:(y=kn(n.totalTokens),t[30]=n.totalTokens,t[31]=y);let b;t[32]===y?b=t[33]:(b=(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[`Σ `,y,` tok`]}),t[32]=y,t[33]=b);let x;t[34]!==v||t[35]!==b?(x=(0,X.jsxs)(`footer`,{className:`flex items-center justify-between border-t border-border/60 px-3 py-1.5 font-mono text-[.7rem] text-muted-foreground`,children:[v,b]}),t[34]=v,t[35]=b,t[36]=x):x=t[36];let S;t[37]!==x||t[38]!==m?(S=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[m,x]}),t[37]=x,t[38]=m,t[39]=S):S=t[39];let C;return t[40]!==d||t[41]!==S?(C=(0,X.jsx)(Ar.Provider,{value:d,children:S}),t[40]=d,t[41]=S,t[42]=C):C=t[42],C}function ui(e){return(0,X.jsx)(Br,{agent:e},e.id)}function di(e){return{key:e.id,role:e.role,taskLabel:e.title}}function fi(e){let t=[],n=new Set(e.openedPanelModes);n.has(`files`)&&t.push({key:`files`,label:`Files`,mode:`files`}),n.has(`review`)&&t.push({key:`review`,label:`Review`,mode:`review`}),n.has(`terminal`)&&t.push({key:`terminal`,label:`Terminal`,mode:`terminal`}),n.has(`simulator`)&&t.push({key:`simulator`,label:`Simulator`,mode:`simulator`}),n.has(`agents`)&&t.push({key:`agents`,label:`Agents`,mode:`agents`});let r=[...new Set([...e.openedAgentKeys,...e.activeAgentKey?[e.activeAgentKey]:[]])];for(let n of r){let r=Nn(e.subagents,n)??{key:n,name:`Subagent`,status:`idle`,origin:null,capability:null,tool:null,detail:null,providerThreadIds:[],providerSessionIds:[],startedAt:``,updatedAt:``,entries:[],messages:[]};t.push({key:r.key,label:r.name,mode:`agent`,agentKey:r.key,status:r.status,avatarKey:r.avatarKey??r.key})}return t}var pi=new Set,mi=null;function hi(e){pi.add(e),mi??=requestAnimationFrame(_i)}function gi(e){pi.delete(e)&&pi.size===0&&mi!=null&&(cancelAnimationFrame(mi),mi=null)}function _i(e){let t=new Set(pi);pi.clear();for(let n of t)try{n(e)}catch(e){console.error(e)}mi=pi.size>0?requestAnimationFrame(_i):null}function vi(e,t,n){if(e===t||e==null||t==null)return e===t;let r=new Set(n),i=Object.keys(e),a=new Set(Object.keys(t));for(let n of i)if(a.delete(n),!r.has(n)&&(!(n in t)||e[n]!==t[n]))return!1;for(let e of Array.from(a))if(!r.has(e))return!1;return!0}function yi(e,t){let n=e?.theme??K,r=t?.theme??K,i=bi(e),a=bi(t);return Ht(n,r)&&vi(e,t,[`theme`,`parseDiffOptions`])&&vi(i,a)}function bi(e){if(e!=null&&`parseDiffOptions`in e)return e.parseDiffOptions}function xi(e,t){return e?.start===t?.start&&e?.end===t?.end&&e?.side===t?.side&&e?.endSide===t?.endSide}function Si({scrollTop:e,scrollHeight:t,height:n,fitPerfectly:r=!1,fitPerfectlyOverscroll:i=0,overscrollSize:a}){let o=n+a*2,s=r?n+i*2:o;if(t=Math.max(t,s),o>=t||r){let n=Math.max(e-i,0),r=Math.min(e+s,t);return{top:n,bottom:Math.max(r,n)}}let c=e+n/2-o/2,l=c+o;return c<0&&(c=0),l>t&&(l=t),c=Math.floor(Math.max(c,0)),{top:c,bottom:Math.ceil(Math.max(Math.min(l,t),c))}}var Ci=new TextEncoder,wi=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Ti=/[\uD800-\uDFFF]/,Ei=1024,Di=new Uint8Array(Ei);function Oi(){Di.length!==Ei&&(Di=new Uint8Array(Ei))}function ki(e){if(e.length===0)return e;if(Ti.test(e))return JSON.parse(JSON.stringify(e));let t=e.length*3;Di.length<t&&(Di=new Uint8Array(t));let{written:n}=Ci.encodeInto(e,Di);return wi.decode(Di.subarray(0,n))}var Ai=4096,ji=.5;function Mi(e){for(let t of e.hunks){for(let n=0;n<t.hunkContent.length;n++){let r=t.hunkContent[n];if(r.type!==`change`)continue;let i=Pi(e,r);i!=null&&(t.hunkContent.splice(n,1,...i),n+=i.length-1)}Ni(t,e)}}function Ni(e,t){let{hunkContent:n}=e;for(let e=1;e<n.length;e++){let r=n[e],i=n[e-1];if(r.type!==`change`||r.additions>0&&r.deletions>0||i.type!==`context`)continue;let a=r.additions>0,o=a?t.additionLines:t.deletionLines,s=a?r.additionLineIndex:r.deletionLineIndex,c=a?r.additions:r.deletions,l=o[s]??``;if(l.trim()!==``)continue;let u=!0;for(let e=1;e<c;e++)if(o[s+e]!==l){u=!1;break}if(!u)continue;let d=0;for(;d<i.lines&&t.additionLines[i.additionLineIndex+i.lines-1-d]===l;)d++;if(d===0||e===1&&d===i.lines)continue;r.additionLineIndex-=d,r.deletionLineIndex-=d;let f=r.additionLineIndex+r.additions,p=r.deletionLineIndex+r.deletions,m=n[e+1];m?.type===`context`?(m.lines+=d,m.additionLineIndex=f,m.deletionLineIndex=p):n.splice(e+1,0,{type:`context`,lines:d,additionLineIndex:f,deletionLineIndex:p}),i.lines-=d,i.lines===0&&(n.splice(e-1,1),e--)}}function Pi(e,t){let{deletions:n,additions:r,deletionLineIndex:i,additionLineIndex:a}=t,o=Math.min(n,r),s=Math.abs(r-n);if(o===0||s===0||o*(s+1)>Ai)return null;let c=[];for(let t=0;t<n;t++)c.push(Ii(e.deletionLines[i+t]??``));let l=[];for(let t=0;t<r;t++)l.push(Ii(e.additionLines[a+t]??``));let u=r>n,d=0,f=-1;for(let e=0;e<=s;e++){let t=0;for(let n=0;n<o;n++)t+=Li(c[n+(u?0:e)],l[n+(u?e:0)]);e===0?f=t+o*ji:t>f&&(f=t,d=e)}if(d===0)return null;let p=[],m=(e,t,n,r)=>{(e>0||t>0)&&p.push({type:`change`,deletions:e,additions:t,deletionLineIndex:n,additionLineIndex:r})};return u?(m(0,d,i,a),m(o,o,i,a+d),m(0,r-o-d,i+o,a+d+o)):(m(d,0,i,a),m(o,o,i+d,a),m(n-o-d,0,i+d+o,a+o)),p}var Fi=/\s+/g;function Ii(e){return e.replace(Fi,``)}function Li(e,t){if(e===t)return 1;let n=Math.max(e.length,t.length),r=Math.min(e.length,t.length);if(r===0)return 0;let i=0;for(;i<r&&e[i]===t[i];)i++;let a=0;for(;a<r-i&&e[e.length-1-a]===t[t.length-1-a];)a++;return(i+a)/n}function Ri(e,t,n){try{return zi(e,t,n)}finally{Oi()}}function zi(e,t,n=!1){let r=ra(e),i=r?Ki(e):qi(e),a,o=[];for(let e of i){if(r&&!gt.test(e)){if(a==null)a=ki(e);else if(n)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}if(!r&&!Ji(e)){if(a==null)a=ki(e);else if(n)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}let i=Vi(e,{cacheKey:t==null?void 0:`${t}-${o.length}`,isGitDiff:r,throwOnError:n});i!=null&&o.push(i)}return{patchMetadata:a,files:o}}function Bi(e,t){try{return Vi(e,t)}finally{Oi()}}function Vi(e,{cacheKey:t,isGitDiff:n=gt.test(e),oldFile:r,newFile:i,throwOnError:a=!1}={}){let o=0,s=ia(e,`@@ `),c,l=r==null||i==null,u=0,d=0;for(let e of s){let s=Gi(e),f=s[0];if(f==null){if(a)throw Error(`parsePatchContent: invalid hunk`);console.error(`parsePatchContent: invalid hunk`,e);continue}let p=ea(f),m=0,h=0;if(p==null||c==null){if(c!=null){if(a)throw Error(`parsePatchContent: Invalid hunk`);console.error(`parsePatchContent: Invalid hunk`,e);continue}c={name:``,type:`change`,hunks:[],splitLineCount:0,unifiedLineCount:0,isPartial:l,additionLines:!l&&r!=null&&i!=null?Wi(i.contents):[],deletionLines:!l&&r!=null&&i!=null?Wi(r.contents):[],cacheKey:oa(t)},c.additionLines.length===1&&i?.contents===``&&(c.additionLines.length=0),c.deletionLines.length===1&&r?.contents===``&&(c.deletionLines.length=0);for(let e of s){if(e.startsWith(`diff --git`)){let t=e.trim().match(Ne),n=t?.[1]??t?.[2],r=t?.[3]??t?.[4];if(n==null||r==null){if(a)throw Error(`parsePatchContent: invalid git diff header`);console.error(`parsePatchContent: invalid git diff header`,e);continue}c.name=ki(r.trim()),n!==r&&(c.prevName=ki(n.trim()));continue}let t=e.startsWith(`---`)||e.startsWith(`+++`)?e.match(n?ft:Ue):null;if(t!=null){let[,e,n]=t;if(e===`---`&&n!==`/dev/null`){let e=ki(n.trim());c.prevName=e,c.name=e}else e===`+++`&&n!==`/dev/null`&&(c.name=ki(n.trim()))}else if(n){if(e.startsWith(`new mode `)&&(c.mode=ki(e.slice(8).trim())),e.startsWith(`old mode `)&&(c.prevMode=ki(e.slice(8).trim())),e.startsWith(`new file mode`)&&(c.type=`new`,c.mode=ki(e.slice(13).trim())),e.startsWith(`deleted file mode`)&&(c.type=`deleted`,c.mode=ki(e.slice(17).trim())),e.startsWith(`similarity index`)&&(e.startsWith(`similarity index 100%`)?c.type=`rename-pure`:c.type=`rename-changed`),e.startsWith(`index `)){let[,t,n,r]=e.trim().match(qe)??[];t!=null&&(c.prevObjectId=ki(t)),n!=null&&(c.newObjectId=ki(n)),r!=null&&(c.mode=ki(r))}e.startsWith(`rename from `)&&(c.prevName=ki(e.slice(12).trim())),e.startsWith(`rename to `)&&(c.name=ki(e.slice(10).trim()))}}continue}let g,_;for(;s.length>0&&(s[s.length-1]===`
1
+ import{i as e,t}from"./react-SIfiwpqq.js";import{t as n}from"./compiler-runtime-qmuS0Svy.js";import{_ as r,g as i,t as a,y as o}from"./env-B4arEvJg.js";import{ii as s}from"./src-Vf4LVnMX.js";import{$t as c,Et as l,In as u,Jt as d,Ot as f,Pt as p,Qt as m,Rn as h,Sn as g,St as _,Un as v,Zn as y,Zt as b,en as x,f as S,hn as C,mn as w,nn as T,tn as E,wt as D}from"./runtime-DKwoXpJv.js";import{Tt as O,_t as k,ht as A}from"./primary-OskAInOO.js";import{t as j}from"./useDebouncedValue-DHjoudTq.js";import{It as M,P as ee,_t as N,i as te,vt as P}from"./composerDraftStore-CdJJZe42.js";import{c as ne,d as re,l as ie}from"./useSwipeDismiss-CbgDJvw1.js";import{t as ae}from"./useRouter-CcIDS3PN.js";import{_ as oe,a as se,c as F,d as ce,f as le,g as ue,i as de,l as I,m as fe,o as L,p as R,r as pe,s as z,t as me,u as he}from"./rightPanelRouteSearch-DB5gQGHK.js";import{t as ge}from"./useNavigate-2tVq4iZ2.js";import{f as B}from"./useRenderElement-DchFnsR8.js";import{t as _e}from"./arrow-left-Dtj9PfsA.js";import{t as ve}from"./bot-DJp0cuhK.js";import{n as ye,t as be}from"./loader-circle-CrtHFAvM.js";import{t as xe}from"./chevron-down-B7C6FKzM.js";import{c as Se,o as Ce}from"./tabSwitchInstrumentation-CLDM7g1_.js";import{t as we}from"./chevron-right-BWYGybX9.js";import{n as Te}from"./useFloatingRootContext-D5EZmrCa.js";import{t as Ee}from"./circle-alert-BWvs6IOn.js";import{i as De}from"./toast-CcSCAm4B.js";import{t as V}from"./clock-3-r12DkpRj.js";import{C as Oe}from"./lib-qiiNMGgU.js";import{t as ke}from"./folder-closed-CsvKfC6X.js";import{t as Ae}from"./folder-open-GqwNTbSV.js";import{t as H}from"./folder-DtsQoI9_.js";import{$ as U,$t as je,A as Me,At as Ne,B as Pe,Bt as Fe,Ct as Ie,Dt as Le,Et as Re,F as ze,Ft as W,G as Be,Gt as Ve,H as He,Ht as Ue,I as We,It as Ge,J as Ke,Jt as qe,K as Je,Kt as Ye,L as Xe,Lt as Ze,M as Qe,Mt as $e,N as et,Nt as tt,Ot as nt,P as rt,Pt as it,Q as at,Qt as ot,R as G,Rt as st,St as ct,Tt as lt,U as ut,Ut as dt,V as ft,Vt as pt,W as mt,Wt as ht,X as gt,Xt as _t,Y as vt,Yt as yt,Z as bt,Zt as xt,_t as St,at as Ct,bt as wt,c as Tt,ct as Et,d as Dt,dt as Ot,en as kt,et as At,ft as jt,g as Mt,gt as Nt,h as Pt,ht as Ft,in as It,it as Lt,j as Rt,jt as zt,k as Bt,kt as Vt,l as Ht,lt as Ut,m as Wt,mt as Gt,n as Kt,nn as qt,nt as Jt,ot as Yt,p as Xt,pt as Zt,q as Qt,qt as $t,r as en,rn as tn,rt as nn,s as rn,st as an,t as on,tn as sn,tt as cn,u as ln,ut as un,vt as dn,wt as fn,xt as K,yt as pn,z as mn,zt as hn}from"./device-B56cBWWt.js";import{t as gn}from"./minimize-2-C33mL7LT.js";import{t as _n}from"./plus-B2h-VEqh.js";import{t as vn}from"./refresh-cw-DopCMrtR.js";import{t as yn}from"./save-Bh36JIv6.js";import{t as bn}from"./search-BGQsenCM.js";import{t as xn}from"./smartphone-gNe1ynB8.js";import{t as Sn}from"./ThreadTerminalDrawer-DjX8p7IH.js";import{i as Cn}from"./terminal-links-CZ3c9AbA.js";import{t as wn}from"./terminal-C_CyIsDD.js";import{t as Tn}from"./triangle-alert-RL_T3KLo.js";import{t as En}from"./unplug-Cw8iawyX.js";import{t as Dn}from"./x-C1Cemsov.js";import{l as On,t as q}from"./utils-BofFIn5Y.js";import{_ as kn,a as An,g as jn,m as Mn,n as Nn,t as Pn,v as Fn,y as In}from"./session-logic-DElAta-Z.js";import"./storeSelectors-Cq_JKyiF.js";import{o as Ln}from"./timestampFormat-8uPXS812.js";import{_ as Rn}from"./keybindings-CWJ7E9ZI.js";import{i as zn,n as Bn,t as Vn}from"./tooltip-C8sAONBj.js";import{t as Hn}from"./scroll-area-Drsa8bNB.js";import{t as Un}from"./button-BAbJxRzt.js";import{n as Wn}from"./composerHandleContext-BrQ6d8r9.js";import{i as Gn,r as Kn,t as qn}from"./alert-LqMhbdE9.js";import{n as Jn,t as Yn}from"./sidebarStatusText-D0HT0fek.js";import{a as Xn,i as Zn,o as Qn,r as $n,s as er,t as tr}from"./alert-dialog-DxoA6ky8.js";import{n as nr}from"./editorPreferences-CTDEj79K.js";import{t as rr}from"./badge-CXw6fWrB.js";import{t as ir}from"./useTheme-DiC-5xCb.js";import{n as ar,t as or}from"./toggle-group-mLIkiJtU.js";import{t as sr}from"./toggle-I6h33Cu5.js";var J=e(t(),1);function cr(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if(`shouldBlockFn`in e)return e;if(typeof e==`function`){let n=!!(t??!0);return{shouldBlockFn:async()=>n?await e():!1,enableBeforeUnload:n,withResolver:!1}}let n=!!(e.condition??!0),r=e.blockerFn;return{shouldBlockFn:async()=>n&&r!==void 0?await r():n,enableBeforeUnload:n,withResolver:r===void 0}}function lr(e,t){let{shouldBlockFn:n,enableBeforeUnload:r=!0,disabled:i=!1,withResolver:a=!1}=cr(e,t),o=ae(),{history:s}=o,[c,l]=J.useState({status:`idle`,current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return J.useEffect(()=>i?void 0:s.block({blockerFn:async e=>{function t(e){let t=o.parseLocation(e),[,n,r]=o.getMatchedRoutes(t.pathname);return r===void 0?{routeId:`__notFound__`,fullPath:t.pathname,pathname:t.pathname,params:n,search:o.options.parseSearch(e.search)}:{routeId:r.id,fullPath:r.fullPath,pathname:t.pathname,params:n,search:o.options.parseSearch(e.search)}}let r=t(e.currentLocation),i=t(e.nextLocation);if(r.routeId===`__notFound__`&&i.routeId!==`__notFound__`)return!1;let s=await n({action:e.action,current:r,next:i});if(!a)return s;if(!s)return!1;let c=await new Promise(t=>{l({status:`blocked`,current:r,next:i,action:e.action,proceed:()=>t(!1),reset:()=>t(!0)})});return l({status:`idle`,current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),c},enableBeforeUnload:r}),[n,r,i,a,s,o]),c}var ur=B(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),dr=B(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),fr=B(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),pr=B(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),mr=B(`disc-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M6 12c0-1.7.7-3.2 1.8-4.2`,key:`oqkarx`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`M18 12c0 1.7-.7 3.2-1.8 4.2`,key:`1eah9h`}]]),hr=B(`git-compare`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M13 6h3a2 2 0 0 1 2 2v7`,key:`1yeb86`}],[`path`,{d:`M11 18H8a2 2 0 0 1-2-2V9`,key:`19pyzm`}]]),gr=B(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),_r=B(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),vr=B(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),yr=B(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),br=B(`monitor-off`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M17 17H4a2 2 0 0 1-2-2V5a2 2 0 0 1 1.184-1.826`,key:`cv7jms`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`path`,{d:`M8.656 3H20a2 2 0 0 1 2 2v10a2 2 0 0 1-.293 1.042`,key:`z8ni2w`}]]),xr=B(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),Sr=B(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),Cr=B(`pilcrow`,[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]),wr=B(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Tr=B(`rows-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),Er=B(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),Dr=B(`volume-1`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}]]),Or=B(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),Y=n(),X=M(),kr={pending:{dotClass:`bg-info`,label:`Working`},running:{dotClass:`bg-info`,label:`Working`},waiting:{dotClass:`bg-info`,label:`Working`},idle:{dotClass:`bg-muted-foreground/50`,label:`Idle · resumable`},completed:{dotClass:`bg-success`,label:`Completed`},failed:{dotClass:`bg-destructive`,label:`Failed`},cancelled:{dotClass:`bg-muted-foreground/60`,label:`Stopped`},interrupted:{dotClass:`bg-muted-foreground/60`,label:`Stopped`}},Ar=(0,J.createContext)({identities:new Map,onOpenAgent:null});function jr(e){let t=(0,Y.c)(4),{status:n}=e,r=kr[n],i;t[0]===r.dotClass?i=t[1]:(i=q(`size-1.5 shrink-0 rounded-full`,r.dotClass),t[0]=r.dotClass,t[1]=i);let a;return t[2]===i?a=t[3]:(a=(0,X.jsx)(`span`,{"aria-hidden":!0,className:i}),t[2]=i,t[3]=a),a}function Mr(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60);if(n===0)return`${t}s`;let r=Math.floor(n/60);return r===0?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${r}h ${String(n%60).padStart(2,`0`)}m`}function Nr(e,t){let n=Date.parse(e),r=t?Date.parse(t):Date.now();return Number.isNaN(n)||Number.isNaN(r)?``:Mr((r-n)/1e3)}function Pr(e){return e.usage?.durationMs===void 0?e.startedAt&&e.completedAt?Nr(e.startedAt,e.completedAt):null:Mr(e.usage.durationMs/1e3)}function Fr(e){let t=(0,Y.c)(12),{agent:n}=e,r=(0,J.useRef)(null),i=n.status===`running`||n.status===`waiting`,a=n.startedAt,o,s;if(t[0]!==i||t[1]!==a?(o=()=>{if(!i||!a)return;let e=()=>{r.current&&(r.current.textContent=Nr(a,null))};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},s=[i,a],t[0]=i,t[1]=a,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,J.useEffect)(o,s),!i){let e;t[4]===n?e=t[5]:(e=Pr(n),t[4]=n,t[5]=e);let r=e,i;return t[6]===r?i=t[7]:(i=r?(0,X.jsx)(`span`,{className:`tabular-nums`,children:r}):null,t[6]=r,t[7]=i),i}if(!a)return null;let c;t[8]===a?c=t[9]:(c=Nr(a,null),t[8]=a,t[9]=c);let l;return t[10]===c?l=t[11]:(l=(0,X.jsx)(`span`,{ref:r,className:`tabular-nums`,children:c}),t[10]=c,t[11]=l),l}function Ir(e,t){return/^structured[\s_-]?output$/i.test(e)?t?`Delivering result`:`Delivered result`:t?`Using ${e}`:e}function Lr(e){return e.status===`running`||e.status===`pending`||e.status===`waiting`?e.progress??(e.lastToolName?Ir(e.lastToolName,!0):null)??e.result??e.error:e.error??e.result??e.progress??(e.lastToolName?Ir(e.lastToolName,!1):null)}function Rr(e){let t=(0,Y.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,X.jsx)(`div`,{className:`divide-y divide-border/30`,children:n}),t[0]=n,t[1]=r),r}function zr(e){let t=(0,Y.c)(11),{title:n}=e,r=`${n} pending`,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,X.jsx)(`span`,{"aria-hidden":!0,className:`flex size-7 items-center justify-center rounded-lg border border-dashed border-border/60 bg-background/30 text-muted-foreground/55`,children:(0,X.jsx)(V,{className:`size-3.5`})}),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,X.jsx)(`span`,{className:`block truncate text-sm font-medium text-foreground/75`,children:n}),t[1]=n,t[2]=a);let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,X.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground/65`,children:`Waiting for this stage to start`}),t[3]=o):o=t[3];let s;t[4]===a?s=t[5]:(s=(0,X.jsxs)(`span`,{className:`min-w-0`,children:[a,o]}),t[4]=a,t[5]=s);let c;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-[.68rem] text-muted-foreground/65`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-muted-foreground/40`}),`Pending`]}),t[6]=c):c=t[6];let l;return t[7]!==r||t[8]!==s||t[9]!==n?(l=(0,X.jsxs)(`div`,{"data-workflow-pending-step":!0,"data-phase-title":n,"aria-label":r,className:`grid h-14 grid-cols-[1.75rem_minmax(0,1fr)_auto] items-center gap-x-2 rounded-md px-1.5 py-1 text-left`,children:[i,s,c]}),t[7]=r,t[8]=s,t[9]=n,t[10]=l):l=t[10],l}function Br(e){let t=(0,Y.c)(69),{agent:n}=e,{identities:r,onOpenAgent:i}=(0,J.use)(Ar),a=kr[n.status],o;t[0]===n?o=t[1]:(o=Lr(n),t[0]=n,t[1]=o);let s=o,c;t[2]!==n.effort||t[3]!==n.model?(c=jn(n.model,n.effort),t[2]=n.effort,t[3]=n.model,t[4]=c):c=t[4];let l=c,u,d,f;t[5]!==n.id||t[6]!==n.title||t[7]!==r?(d=r.get(n.id),u=d?.codename??n.title,f=d?.role&&!In(d.role,u)&&!In(d.role,n.title)?d.role:null,t[5]=n.id,t[6]=n.title,t[7]=r,t[8]=u,t[9]=d,t[10]=f):(u=t[8],d=t[9],f=t[10]);let p=f,m=d?.taskLabel??n.title,h;t[11]===n.usage?h=t[12]:(h=n.usage?`${kn(n.usage.totalTokens)} tok`:`— tok`,t[11]=n.usage,t[12]=h);let g=n.usage?.toolUses===void 0?null:`${n.usage.toolUses} tools`,_=n.activationCount>1?`run ${n.activationCount}`:null,v;t[13]!==l||t[14]!==h||t[15]!==g||t[16]!==_?(v=[l,h,g,_].filter(Vr),t[13]=l,t[14]=h,t[15]=g,t[16]=_,t[17]=v):v=t[17];let y=v,b=d?.avatarKey??n.id,x;t[18]===b?x=t[19]:(x=(0,X.jsx)(kt,{name:b,className:`size-5`}),t[18]=b,t[19]=x);let S;t[20]===n.status?S=t[21]:(S=(0,X.jsx)(`span`,{className:`absolute -right-0.5 -bottom-0.5 grid size-2.5 place-items-center rounded-full bg-background ring-1 ring-background`,children:(0,X.jsx)(jr,{status:n.status})}),t[20]=n.status,t[21]=S);let C;t[22]!==S||t[23]!==x?(C=(0,X.jsxs)(`span`,{"aria-hidden":!0,className:`relative col-start-1 row-span-3 row-start-1 mt-0.5 flex size-7 items-center justify-center rounded-lg border border-border/45 bg-background/45`,children:[x,S]}),t[22]=S,t[23]=x,t[24]=C):C=t[24];let w;t[25]===u?w=t[26]:(w=(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold tracking-[-0.01em]`,children:u}),t[25]=u,t[26]=w);let T;t[27]===p?T=t[28]:(T=p?(0,X.jsx)(`span`,{className:`max-w-32 shrink-0 truncate rounded-sm border border-border/60 bg-background/40 px-1.5 py-px text-[10px] font-medium text-muted-foreground`,children:p}):null,t[27]=p,t[28]=T);let E;t[29]!==w||t[30]!==T?(E=(0,X.jsxs)(`span`,{className:`col-start-2 row-start-1 flex min-w-0 items-center gap-1.5`,children:[w,T]}),t[29]=w,t[30]=T,t[31]=E):E=t[31];let D;t[32]===n?D=t[33]:(D=(0,X.jsx)(Fr,{agent:n}),t[32]=n,t[33]=D);let O;t[34]===n.status?O=t[35]:(O=n.status===`completed`?(0,X.jsx)(ye,{"aria-hidden":!0,className:`size-3 text-success`}):null,t[34]=n.status,t[35]=O);let k;t[36]!==D||t[37]!==O?(k=(0,X.jsx)(`span`,{className:`col-start-3 row-start-1 min-w-14 text-right font-mono text-[.7rem] text-muted-foreground/80`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[D,O]})}),t[36]=D,t[37]=O,t[38]=k):k=t[38];let A;t[39]===m?A=t[40]:(A=(0,X.jsx)(`span`,{className:`col-start-2 col-end-4 row-start-2 block truncate text-[11px] text-foreground/65`,title:m,children:m}),t[39]=m,t[40]=A);let j=n.status===`failed`?`text-destructive-foreground`:`text-muted-foreground`,M;t[41]===j?M=t[42]:(M=q(`col-start-2 row-start-3 block min-w-0 truncate text-xs`,j),t[41]=j,t[42]=M);let ee=s??a.label,N=s??a.label,te;t[43]!==M||t[44]!==ee||t[45]!==N?(te=(0,X.jsx)(`span`,{className:M,title:ee,children:N}),t[43]=M,t[44]=ee,t[45]=N,t[46]=te):te=t[46];let P=y.join(` · `),ne;t[47]===P?ne=t[48]:(ne=(0,X.jsx)(`span`,{className:`col-start-3 row-start-3 max-w-40 truncate text-right font-mono text-[.68rem] tabular-nums text-muted-foreground/65`,children:P}),t[47]=P,t[48]=ne);let re;t[49]===a.label?re=t[50]:(re=(0,X.jsx)(`span`,{className:`sr-only`,children:a.label}),t[49]=a.label,t[50]=re);let ie;t[51]!==C||t[52]!==E||t[53]!==k||t[54]!==A||t[55]!==te||t[56]!==ne||t[57]!==re?(ie=(0,X.jsxs)(X.Fragment,{children:[C,E,k,A,te,ne,re]}),t[51]=C,t[52]=E,t[53]=k,t[54]=A,t[55]=te,t[56]=ne,t[57]=re,t[58]=ie):ie=t[58];let ae=ie,oe=i&&`hover:bg-accent/35 focus-visible:ring-2 focus-visible:ring-ring/50`,se;t[59]===oe?se=t[60]:(se=q(`grid h-[4.5rem] w-full grid-cols-[1.75rem_minmax(0,1fr)_auto] grid-rows-[1.375rem_1.125rem_1rem] items-center gap-x-2 rounded-md px-1.5 py-1 text-left outline-none transition-colors`,oe),t[59]=oe,t[60]=se);let F=se,ce;return t[61]!==n.id||t[62]!==F||t[63]!==u||t[64]!==ae||t[65]!==i||t[66]!==p||t[67]!==a.label?(ce=i?(0,X.jsx)(`button`,{type:`button`,className:F,"data-agent-row":!0,"data-agent-id":n.id,onClick:()=>i(n.id),"aria-label":`Open ${u}${p?`, ${p}`:``} transcript. ${a.label}.`,children:ae}):(0,X.jsx)(`div`,{className:F,"data-agent-row":!0,"data-agent-id":n.id,children:ae}),t[61]=n.id,t[62]=F,t[63]=u,t[64]=ae,t[65]=i,t[66]=p,t[67]=a.label,t[68]=ce):ce=t[68],ce}function Vr(e){return e!==null}function Hr(e){let t=e.workflow.status;return t!==`completed`&&t!==`failed`&&t!==`cancelled`&&t!==`interrupted`}function Ur(e){return[...e.phases.flatMap(e=>e.members),...e.unphasedMembers]}function Wr(e){let t=(0,Y.c)(4),{group:n}=e;if(n.phases.length===0)return null;let r;t[0]===n.phases?r=t[1]:(r=n.phases.map(Gr),t[0]=n.phases,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-1 px-1.5 pb-1 pt-1.5`,children:r}),t[2]=r,t[3]=i),i}function Gr(e,t){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,X.jsx)(we,{"aria-hidden":!0,className:`size-3 text-muted-foreground/40`}):null,(0,X.jsxs)(`div`,{className:q(`flex items-center gap-1 rounded-sm border px-1.5 py-0.5`,e.state===`running`?`border-info/40`:e.state===`done`?`border-success/30`:`border-border/50`),children:[(0,X.jsxs)(`span`,{className:q(`font-mono text-[.65rem]`,e.state===`running`?`text-info-foreground`:e.state===`done`?`text-success-foreground`:`text-muted-foreground/70`),children:[e.state===`done`?`✓ `:``,e.title]}),(0,X.jsx)(`span`,{className:`flex items-center gap-0.5`,children:e.members.length===0?(0,X.jsx)(`span`,{className:`font-mono text-[.6rem] text-muted-foreground/50`,children:`–`}):e.members.map(Kr)})]})]},e.index)}function Kr(e){return(0,X.jsx)(jr,{status:e.status},e.id)}var qr=15e3;function Jr(e){let t=(0,Y.c)(28),{environmentId:n,threadId:r,scriptPath:i,onClose:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={state:`loading`},t[0]=o):o=t[0];let[s,c]=(0,J.useState)(o),[l,u]=(0,J.useState)(0),d;t[1]!==n||t[2]!==i||t[3]!==r?(d=()=>{let e=!1,t;c({state:`loading`});let a=C(n)?.orchestration.getWorkflowScript;if(!a){c({state:`failed`});return}let o=new Promise((e,n)=>{t=setTimeout(()=>n(Error(`workflow script fetch timed out`)),qr)});return Promise.race([a({threadId:r,scriptPath:i}),o]).then(t=>{e||c({state:`loaded`,contents:t.contents,truncated:t.truncated})}).catch(()=>{e||c({state:`failed`})}).finally(()=>{t!==void 0&&clearTimeout(t)}),()=>{e=!0,t!==void 0&&clearTimeout(t)}},t[1]=n,t[2]=i,t[3]=r,t[4]=d):d=t[4];let f;t[5]!==l||t[6]!==n||t[7]!==i||t[8]!==r?(f=[n,r,i,l],t[5]=l,t[6]=n,t[7]=i,t[8]=r,t[9]=f):f=t[9],(0,J.useEffect)(d,f);let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,X.jsx)(ur,{"aria-hidden":!0,className:`size-3 text-muted-foreground`}),t[10]=p):p=t[10];let m;t[11]===i?m=t[12]:(m=i.split(`/`).at(-1),t[11]=i,t[12]=m);let h;t[13]===m?h=t[14]:(h=(0,X.jsx)(`span`,{className:`truncate font-mono text-[.65rem] text-muted-foreground`,children:m}),t[13]=m,t[14]=h);let g;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,X.jsx)(Dn,{"aria-hidden":!0,className:`size-3`}),t[15]=g):g=t[15];let _;t[16]===a?_=t[17]:(_=(0,X.jsx)(`button`,{type:`button`,onClick:a,"aria-label":`Close script`,className:`ml-auto text-muted-foreground hover:text-foreground`,children:g}),t[16]=a,t[17]=_);let v;t[18]!==h||t[19]!==_?(v=(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/50 px-2 py-1`,children:[p,h,_]}),t[18]=h,t[19]=_,t[20]=v):v=t[20];let y;t[21]!==s.contents||t[22]!==s.state||t[23]!==s.truncated?(y=(0,X.jsx)(`div`,{className:`max-h-72 overflow-auto p-2`,children:s.state===`loaded`?(0,X.jsxs)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[.7rem] leading-relaxed text-foreground/90`,children:[s.contents,s.truncated?`
2
+ … (truncated)`:``]}):s.state===`failed`?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`p`,{className:`text-xs text-destructive-foreground`,children:`Could not load the script.`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(Yr),className:`text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground`,children:`Retry`})]}):(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading…`})}),t[21]=s.contents,t[22]=s.state,t[23]=s.truncated,t[24]=y):y=t[24];let b;return t[25]!==y||t[26]!==v?(b=(0,X.jsxs)(`div`,{className:`mx-1.5 mb-1 rounded-md border border-border/60 bg-background/60`,children:[v,y]}),t[25]=y,t[26]=v,t[27]=b):b=t[27],b}function Yr(e){return e+1}function Xr(e){let t=(0,Y.c)(33),{phase:n,defaultOpen:r}=e,[i,a]=(0,J.useState)(r!==void 0&&r||n.state===`running`),o=(0,J.useRef)(n.state),s,c;t[0]===n.state?(s=t[1],c=t[2]):(s=()=>{o.current!==`running`&&n.state===`running`&&a(!0),o.current=n.state},c=[n.state],t[0]=n.state,t[1]=s,t[2]=c),(0,J.useEffect)(s,c);let l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>a($r),t[3]=l):l=t[3];let u=n.state===`done`?`text-success-foreground`:n.state===`running`?`text-info-foreground`:`text-muted-foreground/70`,d;t[4]===u?d=t[5]:(d=q(`mt-2 flex w-full items-center gap-1.5 rounded-sm px-1.5 text-left text-[.65rem] font-medium uppercase tracking-wider hover:bg-accent/40`,u),t[4]=u,t[5]=d);let f;t[6]===i?f=t[7]:(f=i?(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3 shrink-0`}):(0,X.jsx)(we,{"aria-hidden":!0,className:`size-3 shrink-0`}),t[6]=i,t[7]=f);let p;t[8]===n.state?p=t[9]:(p=n.state===`done`?(0,X.jsx)(ye,{"aria-hidden":!0,className:`size-3`}):null,t[8]=n.state,t[9]=p);let m;t[10]===n.title?m=t[11]:(m=(0,X.jsx)(`span`,{children:n.title}),t[10]=n.title,t[11]=m);let h=n.state===`pending`&&n.members.length===0?`pending`:n.state===`done`?`${n.settledCount} done`:`${n.activeCount} active · ${n.settledCount} done`,g;t[12]===h?g=t[13]:(g=(0,X.jsx)(`span`,{className:`font-normal normal-case text-muted-foreground/70`,children:h}),t[12]=h,t[13]=g);let _;t[14]!==i||t[15]!==n.members?(_=!i&&n.members.length>0?(0,X.jsx)(`span`,{className:`ml-auto flex items-center gap-0.5`,children:n.members.map(Qr)}):null,t[14]=i,t[15]=n.members,t[16]=_):_=t[16];let v;t[17]!==i||t[18]!==g||t[19]!==_||t[20]!==d||t[21]!==f||t[22]!==p||t[23]!==m?(v=(0,X.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":i,className:d,children:[f,p,m,g,_]}),t[17]=i,t[18]=g,t[19]=_,t[20]=d,t[21]=f,t[22]=p,t[23]=m,t[24]=v):v=t[24];let y;t[25]!==i||t[26]!==n.members||t[27]!==n.state||t[28]!==n.title?(y=i?(0,X.jsx)(Rr,{children:n.members.length===0&&n.state===`pending`?(0,X.jsx)(zr,{title:n.title}):n.members.map(Zr)}):null,t[25]=i,t[26]=n.members,t[27]=n.state,t[28]=n.title,t[29]=y):y=t[29];let b;return t[30]!==v||t[31]!==y?(b=(0,X.jsxs)(`div`,{children:[v,y]}),t[30]=v,t[31]=y,t[32]=b):b=t[32],b}function Zr(e){return(0,X.jsx)(Br,{agent:e},e.id)}function Qr(e){return(0,X.jsx)(jr,{status:e.status},e.id)}function $r(e){return!e}function ei(e){let t=(0,Y.c)(47),{group:n,environmentId:r,threadId:i,onCollapse:a}=e,[o,s]=(0,J.useState)(!1),c,l;t[0]===n?(c=t[1],l=t[2]):(c=Ur(n),l=c.filter(ii),t[0]=n,t[1]=c,t[2]=l);let u=l.length,d=n.workflow.runHandles?.scriptPath,f=d!==void 0&&r!==null&&i!==null,p;t[3]===n.workflow.status?p=t[4]:(p=(0,X.jsx)(jr,{status:n.workflow.status}),t[3]=n.workflow.status,t[4]=p);let m=n.workflow.workflowName??n.workflow.title,h;t[5]===m?h=t[6]:(h=(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:m}),t[5]=m,t[6]=h);let g;t[7]!==f||t[8]!==o?(g=f?(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(ri),className:q(`rounded-sm border border-border/60 px-1 font-mono normal-case hover:text-foreground`,o&&`text-foreground`),"aria-expanded":o,children:[`{}`,` script`]}):null,t[7]=f,t[8]=o,t[9]=g):g=t[9];let _;t[10]!==c.length||t[11]!==u?(_=(0,X.jsxs)(`span`,{className:`ml-auto font-mono normal-case text-muted-foreground/80`,children:[u,`/`,c.length,` settled`]}),t[10]=c.length,t[11]=u,t[12]=_):_=t[12];let v;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3`}),t[13]=v):v=t[13];let y;t[14]===a?y=t[15]:(y=(0,X.jsx)(`button`,{type:`button`,onClick:a,"aria-label":`Collapse workflow`,className:`rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50`,children:v}),t[14]=a,t[15]=y);let b;t[16]!==p||t[17]!==h||t[18]!==g||t[19]!==_||t[20]!==y?(b=(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5 pt-0.5 text-[.65rem] font-medium uppercase tracking-wider text-muted-foreground`,children:[p,h,g,_,y]}),t[16]=p,t[17]=h,t[18]=g,t[19]=_,t[20]=y,t[21]=b):b=t[21];let x;t[22]===n?x=t[23]:(x=(0,X.jsx)(Wr,{group:n}),t[22]=n,t[23]=x);let S;t[24]!==f||t[25]!==r||t[26]!==o||t[27]!==d||t[28]!==i?(S=o&&f?(0,X.jsx)(Jr,{environmentId:r,threadId:i,scriptPath:d,onClose:()=>s(!1)}):null,t[24]=f,t[25]=r,t[26]=o,t[27]=d,t[28]=i,t[29]=S):S=t[29];let C;t[30]===n.phases?C=t[31]:(C=n.phases.map(ni),t[30]=n.phases,t[31]=C);let w;t[32]===n.unphasedMembers?w=t[33]:(w=n.unphasedMembers.map(ti),t[32]=n.unphasedMembers,t[33]=w);let T;t[34]===w?T=t[35]:(T=(0,X.jsx)(Rr,{children:w}),t[34]=w,t[35]=T);let E;t[36]!==n.phases.length||t[37]!==n.unphasedMembers.length||t[38]!==n.workflow?(E=n.phases.length===0&&n.unphasedMembers.length===0?(0,X.jsx)(Br,{agent:n.workflow}):null,t[36]=n.phases.length,t[37]=n.unphasedMembers.length,t[38]=n.workflow,t[39]=E):E=t[39];let D;return t[40]!==x||t[41]!==S||t[42]!==C||t[43]!==T||t[44]!==E||t[45]!==b?(D=(0,X.jsxs)(`section`,{className:`rounded-lg border border-border/50 bg-card/30 p-1.5`,children:[b,x,S,C,T,E]}),t[40]=x,t[41]=S,t[42]=C,t[43]=T,t[44]=E,t[45]=b,t[46]=D):D=t[46],D}function ti(e){return(0,X.jsx)(Br,{agent:e},e.id)}function ni(e){return(0,X.jsx)(Xr,{phase:e,defaultOpen:!0},e.index)}function ri(e){return!e}function ii(e){return e.status===`completed`||e.status===`failed`||e.status===`cancelled`||e.status===`interrupted`}function ai(e){let t=(0,Y.c)(45),{group:n,onExpand:r}=e,i,a,o,s,c,l,u,d,f,p,m,h,g;if(t[0]!==n||t[1]!==r){let e=Ur(n),_=e.filter(si).length,v=e.reduce(oi,e.length===0?n.workflow.usage?.totalTokens??0:0),y;t[15]!==n.workflow.completedAt||t[16]!==n.workflow.startedAt?(y=n.workflow.startedAt&&n.workflow.completedAt?Nr(n.workflow.startedAt,n.workflow.completedAt):null,t[15]=n.workflow.completedAt,t[16]=n.workflow.startedAt,t[17]=y):y=t[17],i=y,m=`button`,h=r,g=`flex w-full items-center gap-2 rounded-md px-1.5 py-1 text-left outline-none hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring/50`,o=!1;let b=_>0?`failed`:n.workflow.status;t[18]===b?s=t[19]:(s=(0,X.jsx)(jr,{status:b}),t[18]=b,t[19]=s);let x=n.workflow.workflowName??n.workflow.title;t[20]===x?c=t[21]:(c=(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:x}),t[20]=x,t[21]=c),d=`flex shrink-0 items-center gap-1.5 font-mono text-[.7rem] text-muted-foreground/80`,t[22]===_?f=t[23]:(f=_>0?(0,X.jsxs)(`span`,{className:`text-destructive-foreground`,children:[_,` failed`]}):null,t[22]=_,t[23]=f),p=(0,X.jsxs)(`span`,{children:[e.length,` agents`]}),a=`tabular-nums`,l=`· `,u=kn(v),t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=g}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14];let _;t[24]!==a||t[25]!==l||t[26]!==u?(_=(0,X.jsxs)(`span`,{className:a,children:[l,u,` tok`]}),t[24]=a,t[25]=l,t[26]=u,t[27]=_):_=t[27];let v;t[28]===i?v=t[29]:(v=i?(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[`· `,i]}):null,t[28]=i,t[29]=v);let y;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,X.jsx)(we,{"aria-hidden":!0,className:`size-3`}),t[30]=y):y=t[30];let b;t[31]!==_||t[32]!==v||t[33]!==d||t[34]!==f||t[35]!==p?(b=(0,X.jsxs)(`span`,{className:d,children:[f,p,_,v,y]}),t[31]=_,t[32]=v,t[33]=d,t[34]=f,t[35]=p,t[36]=b):b=t[36];let x;return t[37]!==o||t[38]!==s||t[39]!==c||t[40]!==b||t[41]!==m||t[42]!==h||t[43]!==g?(x=(0,X.jsx)(`section`,{children:(0,X.jsxs)(`button`,{type:m,onClick:h,className:g,"aria-expanded":o,children:[s,c,b]})}),t[37]=o,t[38]=s,t[39]=c,t[40]=b,t[41]=m,t[42]=h,t[43]=g,t[44]=x):x=t[44],x}function oi(e,t){return e+(t.usage?.totalTokens??0)}function si(e){return e.status===`failed`}function ci(e){let t=(0,Y.c)(7),{group:n,environmentId:r,threadId:i}=e,a;t[0]===n?a=t[1]:(a=()=>Hr(n),t[0]=n,t[1]=a);let[o,s]=(0,J.useState)(a),c;return t[2]!==r||t[3]!==n||t[4]!==o||t[5]!==i?(c=o?(0,X.jsx)(ei,{group:n,environmentId:r,threadId:i,onCollapse:()=>s(!1)}):(0,X.jsx)(ai,{group:n,onExpand:()=>s(!0)}),t[2]=r,t[3]=n,t[4]=o,t[5]=i,t[6]=c):c=t[6],c}function li(e){let t=(0,Y.c)(43),{model:n,environmentId:r,threadId:i,onOpenAgent:a}=e,o=r===void 0?null:r,s=i===void 0?null:i,c=a===void 0?null:a,l;if(t[0]!==n.directAgents||t[1]!==n.workflows){let e=new Map;for(let t of n.workflows){e.set(t.workflow.id,t.workflow);for(let n of Ur(t))e.set(n.id,n)}for(let t of n.directAgents)e.set(t.id,t);l=Fn([...e.values()].map(di)),t[0]=n.directAgents,t[1]=n.workflows,t[2]=l}else l=t[2];let u;t[3]!==c||t[4]!==l?(u={identities:l,onOpenAgent:c},t[3]=c,t[4]=l,t[5]=u):u=t[5];let d=u;if(!n.hasAgents){let e;return t[6]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center`,children:[(0,X.jsx)(ve,{"aria-hidden":!0,className:`size-6 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,X.jsx)(`p`,{className:`max-w-56 text-xs text-muted-foreground`,children:`When this thread spawns subagents or runs a workflow, they show up here with live status, activity, and token usage.`})]}),t[6]=e):e=t[6],e}let f;if(t[7]!==o||t[8]!==n.workflows||t[9]!==s){let e;t[11]!==o||t[12]!==s?(e=e=>(0,X.jsx)(ci,{group:e,environmentId:o,threadId:s},e.workflow.id),t[11]=o,t[12]=s,t[13]=e):e=t[13],f=n.workflows.map(e),t[7]=o,t[8]=n.workflows,t[9]=s,t[10]=f}else f=t[10];let p;t[14]===n.directAgents?p=t[15]:(p=n.directAgents.length>0?(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`div`,{className:`px-1.5 pt-1 text-[.65rem] font-medium uppercase tracking-wider text-muted-foreground`,children:`Direct spawns`}),(0,X.jsx)(Rr,{children:n.directAgents.map(ui)})]}):null,t[14]=n.directAgents,t[15]=p);let m;t[16]!==f||t[17]!==p?(m=(0,X.jsx)(Hn,{className:`min-h-0 flex-1`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 p-2`,children:[f,p]})}),t[16]=f,t[17]=p,t[18]=m):m=t[18];let h;t[19]!==n.runningCount||t[20]!==n.waitingCount?(h=n.runningCount+n.waitingCount>0?(0,X.jsxs)(`span`,{className:`text-info-foreground`,children:[`● `,n.runningCount+n.waitingCount,` working`]}):null,t[19]=n.runningCount,t[20]=n.waitingCount,t[21]=h):h=t[21];let g;t[22]===n.idleCount?g=t[23]:(g=n.idleCount>0?(0,X.jsxs)(`span`,{children:[n.idleCount,` idle`]}):null,t[22]=n.idleCount,t[23]=g);let _;t[24]===n.settledCount?_=t[25]:(_=n.settledCount>0?(0,X.jsxs)(`span`,{children:[n.settledCount,` settled`]}):null,t[24]=n.settledCount,t[25]=_);let v;t[26]!==g||t[27]!==_||t[28]!==h?(v=(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[h,g,_]}),t[26]=g,t[27]=_,t[28]=h,t[29]=v):v=t[29];let y;t[30]===n.totalTokens?y=t[31]:(y=kn(n.totalTokens),t[30]=n.totalTokens,t[31]=y);let b;t[32]===y?b=t[33]:(b=(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[`Σ `,y,` tok`]}),t[32]=y,t[33]=b);let x;t[34]!==v||t[35]!==b?(x=(0,X.jsxs)(`footer`,{className:`flex items-center justify-between border-t border-border/60 px-3 py-1.5 font-mono text-[.7rem] text-muted-foreground`,children:[v,b]}),t[34]=v,t[35]=b,t[36]=x):x=t[36];let S;t[37]!==x||t[38]!==m?(S=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[m,x]}),t[37]=x,t[38]=m,t[39]=S):S=t[39];let C;return t[40]!==d||t[41]!==S?(C=(0,X.jsx)(Ar.Provider,{value:d,children:S}),t[40]=d,t[41]=S,t[42]=C):C=t[42],C}function ui(e){return(0,X.jsx)(Br,{agent:e},e.id)}function di(e){return{key:e.id,role:e.role,taskLabel:e.title}}function fi(e){let t=[],n=new Set(e.openedPanelModes);n.has(`files`)&&t.push({key:`files`,label:`Files`,mode:`files`}),n.has(`review`)&&t.push({key:`review`,label:`Review`,mode:`review`}),n.has(`terminal`)&&t.push({key:`terminal`,label:`Terminal`,mode:`terminal`}),n.has(`simulator`)&&t.push({key:`simulator`,label:`Simulator`,mode:`simulator`}),n.has(`agents`)&&t.push({key:`agents`,label:`Agents`,mode:`agents`});let r=[...new Set([...e.openedAgentKeys,...e.activeAgentKey?[e.activeAgentKey]:[]])];for(let n of r){let r=Nn(e.subagents,n)??{key:n,name:`Subagent`,status:`idle`,origin:null,capability:null,tool:null,detail:null,providerThreadIds:[],providerSessionIds:[],startedAt:``,updatedAt:``,entries:[],messages:[]};t.push({key:r.key,label:r.name,mode:`agent`,agentKey:r.key,status:r.status,avatarKey:r.avatarKey??r.key})}return t}var pi=new Set,mi=null;function hi(e){pi.add(e),mi??=requestAnimationFrame(_i)}function gi(e){pi.delete(e)&&pi.size===0&&mi!=null&&(cancelAnimationFrame(mi),mi=null)}function _i(e){let t=new Set(pi);pi.clear();for(let n of t)try{n(e)}catch(e){console.error(e)}mi=pi.size>0?requestAnimationFrame(_i):null}function vi(e,t,n){if(e===t||e==null||t==null)return e===t;let r=new Set(n),i=Object.keys(e),a=new Set(Object.keys(t));for(let n of i)if(a.delete(n),!r.has(n)&&(!(n in t)||e[n]!==t[n]))return!1;for(let e of Array.from(a))if(!r.has(e))return!1;return!0}function yi(e,t){let n=e?.theme??W,r=t?.theme??W,i=bi(e),a=bi(t);return Vt(n,r)&&vi(e,t,[`theme`,`parseDiffOptions`])&&vi(i,a)}function bi(e){if(e!=null&&`parseDiffOptions`in e)return e.parseDiffOptions}function xi(e,t){return e?.start===t?.start&&e?.end===t?.end&&e?.side===t?.side&&e?.endSide===t?.endSide}function Si({scrollTop:e,scrollHeight:t,height:n,fitPerfectly:r=!1,fitPerfectlyOverscroll:i=0,overscrollSize:a}){let o=n+a*2,s=r?n+i*2:o;if(t=Math.max(t,s),o>=t||r){let n=Math.max(e-i,0),r=Math.min(e+s,t);return{top:n,bottom:Math.max(r,n)}}let c=e+n/2-o/2,l=c+o;return c<0&&(c=0),l>t&&(l=t),c=Math.floor(Math.max(c,0)),{top:c,bottom:Math.ceil(Math.max(Math.min(l,t),c))}}var Ci=new TextEncoder,wi=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Ti=/[\uD800-\uDFFF]/,Ei=1024,Di=new Uint8Array(Ei);function Oi(){Di.length!==Ei&&(Di=new Uint8Array(Ei))}function ki(e){if(e.length===0)return e;if(Ti.test(e))return JSON.parse(JSON.stringify(e));let t=e.length*3;Di.length<t&&(Di=new Uint8Array(t));let{written:n}=Ci.encodeInto(e,Di);return wi.decode(Di.subarray(0,n))}var Ai=4096,ji=.5;function Mi(e){for(let t of e.hunks){for(let n=0;n<t.hunkContent.length;n++){let r=t.hunkContent[n];if(r.type!==`change`)continue;let i=Pi(e,r);i!=null&&(t.hunkContent.splice(n,1,...i),n+=i.length-1)}Ni(t,e)}}function Ni(e,t){let{hunkContent:n}=e;for(let e=1;e<n.length;e++){let r=n[e],i=n[e-1];if(r.type!==`change`||r.additions>0&&r.deletions>0||i.type!==`context`)continue;let a=r.additions>0,o=a?t.additionLines:t.deletionLines,s=a?r.additionLineIndex:r.deletionLineIndex,c=a?r.additions:r.deletions,l=o[s]??``;if(l.trim()!==``)continue;let u=!0;for(let e=1;e<c;e++)if(o[s+e]!==l){u=!1;break}if(!u)continue;let d=0;for(;d<i.lines&&t.additionLines[i.additionLineIndex+i.lines-1-d]===l;)d++;if(d===0||e===1&&d===i.lines)continue;r.additionLineIndex-=d,r.deletionLineIndex-=d;let f=r.additionLineIndex+r.additions,p=r.deletionLineIndex+r.deletions,m=n[e+1];m?.type===`context`?(m.lines+=d,m.additionLineIndex=f,m.deletionLineIndex=p):n.splice(e+1,0,{type:`context`,lines:d,additionLineIndex:f,deletionLineIndex:p}),i.lines-=d,i.lines===0&&(n.splice(e-1,1),e--)}}function Pi(e,t){let{deletions:n,additions:r,deletionLineIndex:i,additionLineIndex:a}=t,o=Math.min(n,r),s=Math.abs(r-n);if(o===0||s===0||o*(s+1)>Ai)return null;let c=[];for(let t=0;t<n;t++)c.push(Ii(e.deletionLines[i+t]??``));let l=[];for(let t=0;t<r;t++)l.push(Ii(e.additionLines[a+t]??``));let u=r>n,d=0,f=-1;for(let e=0;e<=s;e++){let t=0;for(let n=0;n<o;n++)t+=Li(c[n+(u?0:e)],l[n+(u?e:0)]);e===0?f=t+o*ji:t>f&&(f=t,d=e)}if(d===0)return null;let p=[],m=(e,t,n,r)=>{(e>0||t>0)&&p.push({type:`change`,deletions:e,additions:t,deletionLineIndex:n,additionLineIndex:r})};return u?(m(0,d,i,a),m(o,o,i,a+d),m(0,r-o-d,i+o,a+d+o)):(m(d,0,i,a),m(o,o,i+d,a),m(n-o-d,0,i+d+o,a+o)),p}var Fi=/\s+/g;function Ii(e){return e.replace(Fi,``)}function Li(e,t){if(e===t)return 1;let n=Math.max(e.length,t.length),r=Math.min(e.length,t.length);if(r===0)return 0;let i=0;for(;i<r&&e[i]===t[i];)i++;let a=0;for(;a<r-i&&e[e.length-1-a]===t[t.length-1-a];)a++;return(i+a)/n}function Ri(e,t,n){try{return zi(e,t,n)}finally{Oi()}}function zi(e,t,n=!1){let r=ra(e),i=r?Ki(e):qi(e),a,o=[];for(let e of i){if(r&&!ht.test(e)){if(a==null)a=ki(e);else if(n)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}if(!r&&!Ji(e)){if(a==null)a=ki(e);else if(n)throw Error(`parsePatchContent: unknown file blob`);else console.error(`parsePatchContent: unknown file blob:`,e);continue}let i=Vi(e,{cacheKey:t==null?void 0:`${t}-${o.length}`,isGitDiff:r,throwOnError:n});i!=null&&o.push(i)}return{patchMetadata:a,files:o}}function Bi(e,t){try{return Vi(e,t)}finally{Oi()}}function Vi(e,{cacheKey:t,isGitDiff:n=ht.test(e),oldFile:r,newFile:i,throwOnError:a=!1}={}){let o=0,s=ia(e,`@@ `),c,l=r==null||i==null,u=0,d=0;for(let e of s){let s=Gi(e),f=s[0];if(f==null){if(a)throw Error(`parsePatchContent: invalid hunk`);console.error(`parsePatchContent: invalid hunk`,e);continue}let p=ea(f),m=0,h=0;if(p==null||c==null){if(c!=null){if(a)throw Error(`parsePatchContent: Invalid hunk`);console.error(`parsePatchContent: Invalid hunk`,e);continue}c={name:``,type:`change`,hunks:[],splitLineCount:0,unifiedLineCount:0,isPartial:l,additionLines:!l&&r!=null&&i!=null?Wi(i.contents):[],deletionLines:!l&&r!=null&&i!=null?Wi(r.contents):[],cacheKey:oa(t)},c.additionLines.length===1&&i?.contents===``&&(c.additionLines.length=0),c.deletionLines.length===1&&r?.contents===``&&(c.deletionLines.length=0);for(let e of s){if(e.startsWith(`diff --git`)){let t=e.trim().match(Ne),n=t?.[1]??t?.[2],r=t?.[3]??t?.[4];if(n==null||r==null){if(a)throw Error(`parsePatchContent: invalid git diff header`);console.error(`parsePatchContent: invalid git diff header`,e);continue}c.name=ki(r.trim()),n!==r&&(c.prevName=ki(n.trim()));continue}let t=e.startsWith(`---`)||e.startsWith(`+++`)?e.match(n?dt:Ue):null;if(t!=null){let[,e,n]=t;if(e===`---`&&n!==`/dev/null`){let e=ki(n.trim());c.prevName=e,c.name=e}else e===`+++`&&n!==`/dev/null`&&(c.name=ki(n.trim()))}else if(n){if(e.startsWith(`new mode `)&&(c.mode=ki(e.slice(8).trim())),e.startsWith(`old mode `)&&(c.prevMode=ki(e.slice(8).trim())),e.startsWith(`new file mode`)&&(c.type=`new`,c.mode=ki(e.slice(13).trim())),e.startsWith(`deleted file mode`)&&(c.type=`deleted`,c.mode=ki(e.slice(17).trim())),e.startsWith(`similarity index`)&&(e.startsWith(`similarity index 100%`)?c.type=`rename-pure`:c.type=`rename-changed`),e.startsWith(`index `)){let[,t,n,r]=e.trim().match(qe)??[];t!=null&&(c.prevObjectId=ki(t)),n!=null&&(c.newObjectId=ki(n)),r!=null&&(c.mode=ki(r))}e.startsWith(`rename from `)&&(c.prevName=ki(e.slice(12).trim())),e.startsWith(`rename to `)&&(c.name=ki(e.slice(10).trim()))}}continue}let g,_;for(;s.length>0&&(s[s.length-1]===`
3
3
  `||s[s.length-1]===`\r`||s[s.length-1]===`\r
4
- `||s[s.length-1]===``);)s.pop();let{additionStart:v,deletionStart:y}=p;u=l?u:y-1,d=l?d:v-1;let b={collapsedBefore:0,splitLineCount:0,splitLineStart:0,unifiedLineCount:0,unifiedLineStart:0,additionCount:p.additionCount,additionStart:v,additionLines:m,deletionCount:p.deletionCount,deletionStart:y,deletionLines:h,deletionLineIndex:u,additionLineIndex:d,hunkContent:[],hunkContext:oa(p.hunkContext),hunkSpecs:ki(f),noEOFCRAdditions:!1,noEOFCRDeletions:!1},x=0,S=0;for(let e=1;e<s.length;e++){let t=s[e];if(x>=b.additionCount&&S>=b.deletionCount&&!t.startsWith(`\\`)){if(a&&Qi(t)&&!$i(t))throw Error(`parsePatchContent: hunk has more lines than expected`);break}let n=t[0];if(n!==`+`&&n!==`-`&&n!==` `&&n!==`\\`){if(a)throw Error(`parsePatchContent: invalid hunk line`);console.error(`parseLineType: Invalid firstChar: "${n}", full line: "${t}"`),console.error(`processFile: invalid rawLine:`,t);continue}let r=sa(n);if(r===`addition`){if(a&&x>=b.additionCount)throw Error(`parsePatchContent: hunk has too many addition lines`);let e=ca(t);(g==null||g.type!==`change`)&&(g=la(`change`,u,d),b.hunkContent.push(g)),d++,x++,l&&c.additionLines.push(e),g.additions++,m++,_=`addition`}else if(r===`deletion`){if(a&&S>=b.deletionCount)throw Error(`parsePatchContent: hunk has too many deletion lines`);let e=ca(t);(g==null||g.type!==`change`)&&(g=la(`change`,u,d),b.hunkContent.push(g)),u++,S++,l&&c.deletionLines.push(e),g.deletions++,h++,_=`deletion`}else if(r===`context`){if(a&&(S>=b.deletionCount||x>=b.additionCount))throw Error(`parsePatchContent: hunk has too many context lines`);let e=ca(t);(g==null||g.type!==`context`)&&(g=la(`context`,u,d),b.hunkContent.push(g)),d++,u++,x++,S++,l&&(c.deletionLines.push(e),c.additionLines.push(e)),g.lines++,_=`context`}else if(r===`metadata`&&g!=null){if(g.type===`context`?(b.noEOFCRAdditions=!0,b.noEOFCRDeletions=!0):_===`deletion`?b.noEOFCRDeletions=!0:_===`addition`&&(b.noEOFCRAdditions=!0),l&&(_===`addition`||_===`context`)){let e=c.additionLines.length-1;e>=0&&(c.additionLines[e]=nt(c.additionLines[e]))}if(l&&(_===`deletion`||_===`context`)){let e=c.deletionLines.length-1;e>=0&&(c.deletionLines[e]=nt(c.deletionLines[e]))}}}if(a&&(x!==b.additionCount||S!==b.deletionCount))throw Error(`parsePatchContent: hunk line count mismatch`);b.additionLines=m,b.deletionLines=h,b.collapsedBefore=Math.max(Le(b.additionStart,b.additionCount)-o,0),c.hunks.push(b),o=Re(b.additionStart,b.additionCount);for(let e of b.hunkContent)e.type===`context`?(b.splitLineCount+=e.lines,b.unifiedLineCount+=e.lines):(b.splitLineCount+=Math.max(e.additions,e.deletions),b.unifiedLineCount+=e.deletions+e.additions);b.splitLineStart=c.splitLineCount+b.collapsedBefore,b.unifiedLineStart=c.unifiedLineCount+b.collapsedBefore,c.splitLineCount+=b.collapsedBefore+b.splitLineCount,c.unifiedLineCount+=b.collapsedBefore+b.unifiedLineCount}if(c!=null){if(a&&l&&!n&&c.hunks.length===0)throw Error(`parsePatchContent: unified file has no hunks`);if(c.hunks.length>0&&!l&&c.additionLines.length>0&&c.deletionLines.length>0){let e=c.hunks[c.hunks.length-1],t=Re(e.additionStart,e.additionCount),n=c.additionLines.length,r=Math.max(n-t,0);c.splitLineCount+=r,c.unifiedLineCount+=r}return n||(c.prevName!=null&&c.name!==c.prevName?c.hunks.length>0?c.type=`rename-changed`:c.type=`rename-pure`:(r==null||r.contents===``)&&i!=null&&i.contents!==``?c.type=`new`:r!=null&&r.contents!==``&&(i==null||i.contents===``)&&(c.type=`deleted`)),c.type!==`rename-pure`&&c.type!==`rename-changed`&&(c.prevName=void 0),Mi(c),c}}function Hi(e,t,n=!1){let r=[],i=Ui(e)?e.split(Bt):[e];for(let e of i)try{r.push(Ri(e,t==null?void 0:`${t}-${r.length}`,n))}catch(e){if(n)throw e;console.error(e)}return r}function Ui(e){return e.startsWith(`From `)||e.includes(`
4
+ `||s[s.length-1]===``);)s.pop();let{additionStart:v,deletionStart:y}=p;u=l?u:y-1,d=l?d:v-1;let b={collapsedBefore:0,splitLineCount:0,splitLineStart:0,unifiedLineCount:0,unifiedLineStart:0,additionCount:p.additionCount,additionStart:v,additionLines:m,deletionCount:p.deletionCount,deletionStart:y,deletionLines:h,deletionLineIndex:u,additionLineIndex:d,hunkContent:[],hunkContext:oa(p.hunkContext),hunkSpecs:ki(f),noEOFCRAdditions:!1,noEOFCRDeletions:!1},x=0,S=0;for(let e=1;e<s.length;e++){let t=s[e];if(x>=b.additionCount&&S>=b.deletionCount&&!t.startsWith(`\\`)){if(a&&Qi(t)&&!$i(t))throw Error(`parsePatchContent: hunk has more lines than expected`);break}let n=t[0];if(n!==`+`&&n!==`-`&&n!==` `&&n!==`\\`){if(a)throw Error(`parsePatchContent: invalid hunk line`);console.error(`parseLineType: Invalid firstChar: "${n}", full line: "${t}"`),console.error(`processFile: invalid rawLine:`,t);continue}let r=sa(n);if(r===`addition`){if(a&&x>=b.additionCount)throw Error(`parsePatchContent: hunk has too many addition lines`);let e=ca(t);(g==null||g.type!==`change`)&&(g=la(`change`,u,d),b.hunkContent.push(g)),d++,x++,l&&c.additionLines.push(e),g.additions++,m++,_=`addition`}else if(r===`deletion`){if(a&&S>=b.deletionCount)throw Error(`parsePatchContent: hunk has too many deletion lines`);let e=ca(t);(g==null||g.type!==`change`)&&(g=la(`change`,u,d),b.hunkContent.push(g)),u++,S++,l&&c.deletionLines.push(e),g.deletions++,h++,_=`deletion`}else if(r===`context`){if(a&&(S>=b.deletionCount||x>=b.additionCount))throw Error(`parsePatchContent: hunk has too many context lines`);let e=ca(t);(g==null||g.type!==`context`)&&(g=la(`context`,u,d),b.hunkContent.push(g)),d++,u++,x++,S++,l&&(c.deletionLines.push(e),c.additionLines.push(e)),g.lines++,_=`context`}else if(r===`metadata`&&g!=null){if(g.type===`context`?(b.noEOFCRAdditions=!0,b.noEOFCRDeletions=!0):_===`deletion`?b.noEOFCRDeletions=!0:_===`addition`&&(b.noEOFCRAdditions=!0),l&&(_===`addition`||_===`context`)){let e=c.additionLines.length-1;e>=0&&(c.additionLines[e]=nt(c.additionLines[e]))}if(l&&(_===`deletion`||_===`context`)){let e=c.deletionLines.length-1;e>=0&&(c.deletionLines[e]=nt(c.deletionLines[e]))}}}if(a&&(x!==b.additionCount||S!==b.deletionCount))throw Error(`parsePatchContent: hunk line count mismatch`);b.additionLines=m,b.deletionLines=h,b.collapsedBefore=Math.max(Le(b.additionStart,b.additionCount)-o,0),c.hunks.push(b),o=Re(b.additionStart,b.additionCount);for(let e of b.hunkContent)e.type===`context`?(b.splitLineCount+=e.lines,b.unifiedLineCount+=e.lines):(b.splitLineCount+=Math.max(e.additions,e.deletions),b.unifiedLineCount+=e.deletions+e.additions);b.splitLineStart=c.splitLineCount+b.collapsedBefore,b.unifiedLineStart=c.unifiedLineCount+b.collapsedBefore,c.splitLineCount+=b.collapsedBefore+b.splitLineCount,c.unifiedLineCount+=b.collapsedBefore+b.unifiedLineCount}if(c!=null){if(a&&l&&!n&&c.hunks.length===0)throw Error(`parsePatchContent: unified file has no hunks`);if(c.hunks.length>0&&!l&&c.additionLines.length>0&&c.deletionLines.length>0){let e=c.hunks[c.hunks.length-1],t=Re(e.additionStart,e.additionCount),n=c.additionLines.length,r=Math.max(n-t,0);c.splitLineCount+=r,c.unifiedLineCount+=r}return n||(c.prevName!=null&&c.name!==c.prevName?c.hunks.length>0?c.type=`rename-changed`:c.type=`rename-pure`:(r==null||r.contents===``)&&i!=null&&i.contents!==``?c.type=`new`:r!=null&&r.contents!==``&&(i==null||i.contents===``)&&(c.type=`deleted`)),c.type!==`rename-pure`&&c.type!==`rename-changed`&&(c.prevName=void 0),Mi(c),c}}function Hi(e,t,n=!1){let r=[],i=Ui(e)?e.split(zt):[e];for(let e of i)try{r.push(Ri(e,t==null?void 0:`${t}-${r.length}`,n))}catch(e){if(n)throw e;console.error(e)}return r}function Ui(e){return e.startsWith(`From `)||e.includes(`
5
5
  From `)}function Wi(e){let t=Gi(e);for(let e=0;e<t.length;e++)t[e]=ki(t[e]);return t}function Gi(e){if(e.length===0)return[``];let t=[],n=0;for(;;){let r=e.indexOf(`
6
6
  `,n);if(r===-1)break;t.push(e.slice(n,r+1)),n=r+1}return n<e.length&&t.push(e.slice(n)),t}function Ki(e){return ia(e,`diff --git`)}function qi(e){if(e.length===0)return[``];let t=[],n=0,r=0,i=0,a=0,o=!1;for(;r<e.length;){let s=Zi(e,r);if(i<=0&&a<=0){if(Yi(e,r)){r>n&&t.push(e.slice(n,r)),n=r,o=!0,r=Zi(e,s);continue}if(o&&e.startsWith(`@@ -`,r)){let t=ea(e.slice(r,s));t!=null&&(i=t.deletionCount,a=t.additionCount)}r=s;continue}let c=e[r];if(c===`\\`){r=s;continue}c===` `?(i=Math.max(i-1,0),a=Math.max(a-1,0)):c===`-`?i=Math.max(i-1,0):c===`+`&&(a=Math.max(a-1,0)),r=s}return t.push(e.slice(n)),t}function Ji(e){return Yi(e,0)}function Yi(e,t){let n=Zi(e,t);return Xi(e,t,`---`)&&Xi(e,n,`+++`)}function Xi(e,t,n){if(!e.startsWith(n,t))return!1;let r=e[t+n.length];if(r!==` `&&r!==` `)return!1;for(let r=t+n.length+1;r<e.length;r++){let t=e[r];if(t===`
7
7
  `||t===`\r`)break;if(t!==` `&&t!==` `)return!0}return!1}function Zi(e,t){let n=e.indexOf(`
@@ -10,11 +10,11 @@ From `)}function Wi(e){let t=Gi(e);for(let e=0;e<t.length;e++)t[e]=ki(t[e]);retu
10
10
  `)?e.slice(0,-2):e.endsWith(`
11
11
  `)?e.slice(0,-1):e}function ra(e){return e.startsWith(`diff --git`)||e.includes(`
12
12
  diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.startsWith(t)?0:aa(e,n,0);if(r===-1)return[e];let i=[];r>0&&i.push(e.slice(0,r));let a=r;for(;;){let t=aa(e,n,a+1);if(t===-1)break;i.push(e.slice(a,t)),a=t}return i.push(e.slice(a)),i}function aa(e,t,n){let r=e.indexOf(t,n);return r===-1?-1:r+1}function oa(e){return e==null?e:ki(e)}function sa(e){return e===` `?`context`:e===`\\`?`metadata`:e===`+`?`addition`:`deletion`}function ca(e){let t=e.slice(1);return ki(t===``?`
13
- `:t)}function la(e,t,n){return e===`change`?{type:`change`,additions:0,deletions:0,additionLineIndex:n,deletionLineIndex:t}:{type:`context`,lines:0,additionLineIndex:n,deletionLineIndex:t}}var ua=`/dev/null`;function da(e,t,n,r=!1){if(e===null&&t===null)throw Error(`parseDiffFromFile: You must pass oldFile, newFile, or both`);let i=e??fa(),a=t??fa(),o=Bi(ut(i.name,a.name,i.contents,a.contents,i.header,a.header,n),{cacheKey:(()=>{let n=e?.cacheKey??e?.name,r=t?.cacheKey??t?.name;return n!=null&&r!=null?n+`:`+r:n??r})(),oldFile:i,newFile:a,throwOnError:r});if(o==null)throw Error(`parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?`);e===null?(o.type=`new`,o.prevName=void 0):t===null&&(o.type=`deleted`,o.prevName=void 0);let s=t?.lang??(t===null?e?.lang:void 0);return s!=null&&(o.lang=s),o}function fa(){return{name:ua,contents:``}}function pa(){return q({tagName:`button`,properties:{"data-utility-button":``,type:`button`},children:[lt({name:`diffs-icon-plus`,properties:{"data-icon":``}})]})}function ma(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side}function ha(e){for(let t of e)if(t instanceof HTMLElement&&(t.hasAttribute(`data-utility-button`)||t.hasAttribute(`data-gutter-utility-slot`)||t.getAttribute(`slot`)===`gutter-utility-slot`||t.getAttribute(`name`)===`gutter-utility-slot`))return!0;return!1}var ga=class{mode;options;hoveredLine;hoveredToken;pre;gutterUtilityLine;gutterUtilityContainer;gutterUtilityButton;gutterUtilitySlot;interactiveLinesAttr=!1;interactiveLineNumbersAttr=!1;hasPointerListeners=!1;hasDocumentPointerListeners=!1;selectedRange=null;selectedRangeHighlightSide;selectedRangeLineNumberOnly=!1;editorActiveLine=null;editorActiveLineSide;editorLineNumberOnly=!1;proposedSelectedRange;renderedSelectedLinesState;renderedEditorActiveLineState;selectionAnchor;pointerSession={mode:`idle`};constructor(e,t){this.mode=e,this.options=t}setOptions(e){this.options=e}cleanUp(){this.pre?.removeEventListener(`click`,this.handlePointerClick),this.pre?.removeEventListener(`pointerdown`,this.handlePointerDown),this.pre?.removeEventListener(`pointermove`,this.handlePointerMove),this.pre?.removeEventListener(`pointerleave`,this.handlePointerLeave),this.pre?.removeAttribute(`data-interactive-lines`),this.pre?.removeAttribute(`data-interactive-line-numbers`),this.pre=void 0,this.gutterUtilityContainer?.remove(),this.gutterUtilityLine=void 0,this.gutterUtilityContainer=void 0,this.gutterUtilityButton=void 0,this.gutterUtilitySlot=void 0,this.clearHoveredLine(),this.clearHoveredToken(),this.detachDocumentPointerListeners(),this.clearPointerSession(),gi(this.renderSelection),this.interactiveLinesAttr=!1,this.interactiveLineNumbersAttr=!1,this.hasPointerListeners=!1,this.setSelectionDirty()}setup(e){this.setSelectionDirty();let{usesCustomGutterUtility:t=!1,enableGutterUtility:n=!1}=this.options;this.pre!==e&&(this.cleanUp(),this.pre=e),n?this.ensureGutterUtilityNode(t):this.gutterUtilityContainer!=null&&(this.gutterUtilityContainer.remove(),this.gutterUtilityLine=void 0,this.gutterUtilityContainer=void 0,this.gutterUtilityButton=void 0,this.gutterUtilitySlot=void 0,this.pointerSession.mode===`gutterSelecting`&&(this.clearPointerSession(),this.detachDocumentPointerListeners())),this.syncPointerListeners(e),this.updateInteractiveLineAttributes(),this.renderSelection(),this.placeUtility()}setSelectionDirty(){this.renderedSelectedLinesState=void 0,this.renderedEditorActiveLineState=void 0}isSelectionDirty(){return this.renderedSelectedLinesState===void 0||this.renderedEditorActiveLineState===void 0}setSelection(e,t){let n=!(e===this.selectedRange||xi(e??void 0,this.selectedRange??void 0)),r=t?.lineNumberOnly??!1,i=t?.activeLineSide!==this.selectedRangeHighlightSide||r!==this.selectedRangeLineNumberOnly;!this.isSelectionDirty()&&!n&&!i||(this.proposedSelectedRange=void 0,this.selectedRange=e,this.selectedRangeHighlightSide=t?.activeLineSide,this.selectedRangeLineNumberOnly=r,this.renderSelection(),this.placeUtility(),n&&t?.notify!==!1&&this.notifySelectionCommitted(e))}setEditorActiveLine(e,{lineNumberOnly:t=!1,side:n}={}){let r=e!==this.editorActiveLine,i=n!==this.editorActiveLineSide||t!==this.editorLineNumberOnly;!this.isSelectionDirty()&&!r&&!i||(this.editorActiveLine=e,this.editorActiveLineSide=n,this.editorLineNumberOnly=t,this.renderSelection())}getSelection(){return this.selectedRange}getHoveredLine=()=>{let e=this.gutterUtilityLine??this.hoveredLine;if(e!=null){if(this.mode===`diff`&&e.type===`diff-line`)return{lineNumber:e.lineNumber,side:e.annotationSide};if(this.mode===`file`&&e.type===`line`)return{lineNumber:e.lineNumber}}};handlePointerClick=e=>{let{onHunkExpand:t,onLineClick:n,onLineNumberClick:r,onTokenClick:i,onMergeConflictActionClick:a}=this.options;(t!=null||n!=null||r!=null||a!=null||i!=null)&&(this.options.onGutterUtilityClick!=null&&ha(e.composedPath())||(Fa(this.options.__debugPointerEvents,`click`,`FileDiff.DEBUG.handlePointerClick:`,e),this.handlePointerEvent({eventType:`click`,event:e})))};handlePointerMove=e=>{if(e.pointerType!==`mouse`)return;let{lineHoverHighlight:t=`disabled`,onLineEnter:n,onLineLeave:r,onTokenEnter:i,onTokenLeave:a,enableGutterUtility:o=!1}=this.options;t===`disabled`&&!o&&n==null&&r==null&&i==null&&a==null||(Fa(this.options.__debugPointerEvents,`move`,`FileDiff.DEBUG.handlePointerMove:`,e),this.handlePointerEvent({eventType:`move`,event:e}))};handlePointerLeave=e=>{let{__debugPointerEvents:t}=this.options;if(Fa(t,`move`,`FileDiff.DEBUG.handlePointerLeave: no event`),this.hoveredLine==null&&this.hoveredToken==null){Fa(t,`move`,`FileDiff.DEBUG.handlePointerLeave: returned early, no hovered line or token`);return}this.hoveredToken!=null&&(this.options.onTokenLeave?.(this.hoveredToken,e),this.clearHoveredToken()),this.hoveredLine!=null&&(this.options.onLineLeave?.({...this.hoveredLine,event:e}),this.clearHoveredLine()),this.placeUtility()};handlePointerEvent({eventType:e,event:t}){let{__debugPointerEvents:n}=this.options,r=t.composedPath();Fa(n,e,`FileDiff.DEBUG.handlePointerEvent:`,{eventType:e,composedPath:r});let i=this.resolvePointerTarget(r);Fa(n,e,`FileDiff.DEBUG.handlePointerEvent: resolvePointerTarget result:`,i);let{onLineClick:a,onLineNumberClick:o,onLineEnter:s,onLineLeave:c,onTokenClick:l,onTokenEnter:u,onTokenLeave:d,onHunkExpand:f,onMergeConflictActionClick:p}=this.options;switch(e){case`move`:{let e=xa(i)&&this.hoveredLine?.lineElement===i.lineElement;ba(i)&&this.hoveredToken?.tokenElement===i.tokenElement||(this.hoveredToken!=null&&(d?.(this.hoveredToken,t),this.clearHoveredToken()),ba(i)&&(this.setHoveredToken(this.toTokenEventBaseProps(i)),u?.(this.hoveredToken,t))),e||(this.hoveredLine!=null&&(c?.({...this.hoveredLine,event:t}),this.clearHoveredLine()),xa(i)?(this.setHoveredLine(this.toEventBaseProps(i)),this.placeUtility(),s?.({...this.hoveredLine,event:t})):this.placeUtility());break}case`click`:{if(i==null)break;if(Ca(i)&&p!=null){p(i);break}if(Sa(i)&&f!=null){f(i.hunkIndex,i.all||t.shiftKey?`both`:i.direction,i.all||t.shiftKey?1/0:void 0);break}if(!xa(i))break;ba(i)&&l!=null&&l(this.toTokenEventBaseProps(i),t);let e=this.toEventBaseProps(i);o!=null&&i.numberColumn?o({...e,event:t}):a?.({...e,event:t});break}}}syncPointerListeners(e){let{__debugPointerEvents:t,lineHoverHighlight:n=`disabled`,onLineClick:r,onLineNumberClick:i,onLineEnter:a,onLineLeave:o,onTokenClick:s,onTokenEnter:c,onTokenLeave:l,onHunkExpand:u,onMergeConflictActionClick:d,enableGutterUtility:f=!1,enableLineSelection:p=!1,onGutterUtilityClick:m}=this.options,h=m!=null,g=n!==`disabled`||r!=null||i!=null||a!=null||o!=null||s!=null||c!=null||l!=null||u!=null||d!=null||f||p||h;g&&!this.hasPointerListeners?(e.addEventListener(`click`,this.handlePointerClick),e.addEventListener(`pointerdown`,this.handlePointerDown),e.addEventListener(`pointermove`,this.handlePointerMove),e.addEventListener(`pointerleave`,this.handlePointerLeave),this.hasPointerListeners=!0,Fa(t,`click`,`FileDiff.DEBUG.attachEventListeners: Attaching click events for:`,(()=>{let e=[];return(t===`both`||t===`click`)&&(r!=null&&e.push(`onLineClick`),i!=null&&e.push(`onLineNumberClick`),u!=null&&e.push(`expandable hunk separators`),d!=null&&e.push(`merge conflict actions`)),e})()),Fa(t,`move`,`FileDiff.DEBUG.attachEventListeners: Attaching pointer move event`),Fa(t,`move`,`FileDiff.DEBUG.attachEventListeners: Attaching pointer leave event`)):!g&&this.hasPointerListeners&&(e.removeEventListener(`click`,this.handlePointerClick),e.removeEventListener(`pointerdown`,this.handlePointerDown),e.removeEventListener(`pointermove`,this.handlePointerMove),e.removeEventListener(`pointerleave`,this.handlePointerLeave),this.hasPointerListeners=!1);let _=this.pointerSession.mode===`selecting`||this.pointerSession.mode===`pendingSingleLineUnselect`,v=this.pointerSession.mode===`gutterSelecting`;(!p&&_||!h&&v)&&(this.clearPointerSession(),this.detachDocumentPointerListeners(),this.selectionAnchor=void 0,this.clearPendingSingleLineState())}updateInteractiveLineAttributes(){if(this.pre==null)return;let{onLineClick:e,onLineNumberClick:t,enableLineSelection:n=!1}=this.options,r=e!=null,i=t!=null||n;r&&!this.interactiveLinesAttr?(this.pre.setAttribute(`data-interactive-lines`,``),this.interactiveLinesAttr=!0):!r&&this.interactiveLinesAttr&&(this.pre.removeAttribute(`data-interactive-lines`),this.interactiveLinesAttr=!1),i&&!this.interactiveLineNumbersAttr?(this.pre.setAttribute(`data-interactive-line-numbers`,``),this.interactiveLineNumbersAttr=!0):!i&&this.interactiveLineNumbersAttr&&(this.pre.removeAttribute(`data-interactive-line-numbers`),this.interactiveLineNumbersAttr=!1)}handlePointerDown=e=>{if(e.pointerType===`mouse`&&e.button!==0||this.pre==null||this.pointerSession.mode!==`idle`)return;let t=e.composedPath();ha(t)&&this.options.onGutterUtilityClick!=null?this.startGutterSelectionFromPointerDown(e):(e.pointerType!==`mouse`&&this.revealUtilityFromGutterPath(t),this.startLineSelectionFromPointerDown(e))};startLineSelectionFromPointerDown(e){let{enableLineSelection:t=!1}=this.options;if(!t)return;let n=this.resolveSelectionInfo(e,{source:`event-path`,requireNumberColumn:!0});if(n==null)return;let{pre:r}=this;if(r==null)return;let{lineNumber:i,eventSide:a,lineIndex:o}=n;if(e.shiftKey&&this.selectedRange!=null){let t=this.getIndexesFromSelection(this.selectedRange,r.getAttribute(`data-diff-type`)===`split`);if(t==null)return;let n=t.start<=t.end?o>=t.start:o<=t.end;this.selectionAnchor={lineNumber:n?this.selectedRange.start:this.selectedRange.end,side:n?this.selectedRange.side:this.selectedRange.endSide??this.selectedRange.side},this.updateSelection(i,a,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.pointerSession={mode:`selecting`,pointerId:e.pointerId},this.attachDocumentPointerListeners();return}if(this.selectedRange?.start===i&&this.selectedRange?.end===i){let t={lineNumber:i,side:a};this.selectionAnchor=t,this.pointerSession={mode:`pendingSingleLineUnselect`,pointerId:e.pointerId,anchor:t,pending:t},this.attachDocumentPointerListeners();return}this.options.controlledSelection===!0?this.proposedSelectedRange=null:this.selectedRange=null,this.placeUtility(),this.selectionAnchor={lineNumber:i,side:a},this.updateSelection(i,a,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.pointerSession={mode:`selecting`,pointerId:e.pointerId},this.attachDocumentPointerListeners()}startGutterSelectionFromPointerDown(e){let{onGutterUtilityClick:t}=this.options;if(t==null)return;let n=this.currentSelectionEnds(),r=n?.bottom??this.resolveSelectionPoint(e,{source:`event-path`,excludeUtility:!1}),i=n?.top??r;r!=null&&i!=null&&(e.preventDefault(),e.stopPropagation(),this.pointerSession={mode:`gutterSelecting`,pointerId:e.pointerId,anchor:i,current:r},this.selectionAnchor={lineNumber:i.lineNumber,side:i.side},this.updateSelection(r.lineNumber,r.side,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.attachDocumentPointerListeners())}handleDocumentPointerMove=e=>{switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionPoint(e,{source:`coordinates-first`});if(t==null)return;this.pointerSession.current=t,this.updateSelection(t.lineNumber,t.side);return}case`selecting`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionInfo(e,{source:`coordinates-first`,requireNumberColumn:!1});if(t==null||this.selectionAnchor==null)return;this.updateSelection(t.lineNumber,t.eventSide);return}case`pendingSingleLineUnselect`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionInfo(e,{source:`coordinates-first`,requireNumberColumn:!1});if(t==null||this.selectionAnchor==null)return;let n={lineNumber:t.lineNumber,side:t.eventSide};if(ma(this.pointerSession.pending,n))return;this.updateSelection(t.lineNumber,t.eventSide,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.notifySelectionChangeDelta(),this.pointerSession={mode:`selecting`,pointerId:e.pointerId};return}}};handleDocumentPointerUp=e=>{let{onGutterUtilityClick:t}=this.options;switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:{let{pointerSession:n}=this;if(e.pointerId!==n.pointerId)return;e.preventDefault();let r=this.resolveSelectionPoint(e,{source:`coordinates-first`});r!=null&&(n.current=r,this.updateSelection(r.lineNumber,r.side));let i=this.buildSelectedLineRange(n.anchor,n.current);t?.({...i}),this.selectionAnchor=void 0,this.notifySelectionEnd(i),this.notifySelectionCommitted(i),this.clearProposedSelection(),this.clearPointerSession(),this.detachDocumentPointerListeners();return}case`pendingSingleLineUnselect`:if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault(),this.updateSelection(null,void 0,!1),this.selectionAnchor=void 0,this.clearPendingSingleLineState(),this.detachDocumentPointerListeners(),this.notifySelectionEnd(this.getCurrentSelectionRange()),this.notifySelectionCommitted(this.getCurrentSelectionRange()),this.clearProposedSelection();return;case`selecting`:if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault(),this.selectionAnchor=void 0,this.detachDocumentPointerListeners(),this.clearPointerSession(),this.notifySelectionEnd(this.getCurrentSelectionRange()),this.notifySelectionCommitted(this.getCurrentSelectionRange()),this.clearProposedSelection()}};handleDocumentPointerCancel=e=>{switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:case`selecting`:case`pendingSingleLineUnselect`:if(`pointerId`in this.pointerSession&&e.pointerId!==this.pointerSession.pointerId)return;this.selectionAnchor=void 0,this.clearProposedSelection(),this.clearPendingSingleLineState(),this.clearPointerSession(),this.detachDocumentPointerListeners()}};clearHoveredLine(){this.hoveredLine!=null&&(this.hoveredLine.lineElement.removeAttribute(`data-hovered`),this.hoveredLine.numberElement.removeAttribute(`data-hovered`),this.hoveredLine=void 0)}setHoveredLine(e){let{lineHoverHighlight:t=`disabled`}=this.options;this.hoveredLine!=null&&this.clearHoveredLine(),this.hoveredLine=e,t!==`disabled`&&((t===`both`||t===`line`)&&this.hoveredLine.lineElement.setAttribute(`data-hovered`,``),(t===`both`||t===`number`)&&this.hoveredLine.numberElement.setAttribute(`data-hovered`,``))}clearHoveredToken(){this.hoveredToken!=null&&(this.hoveredToken=void 0)}setHoveredToken(e){this.hoveredToken!=null&&this.clearHoveredToken(),this.hoveredToken=e}ensureGutterUtilityNode(e){if(this.gutterUtilityContainer??(this.gutterUtilityContainer=document.createElement(`div`),this.gutterUtilityContainer.setAttribute(`data-gutter-utility-slot`,``)),e)this.gutterUtilityButton!=null&&(this.gutterUtilityButton.remove(),this.gutterUtilityButton=void 0),this.gutterUtilitySlot??(this.gutterUtilitySlot=document.createElement(`slot`),this.gutterUtilitySlot.name=`gutter-utility-slot`),this.gutterUtilitySlot.parentNode!==this.gutterUtilityContainer&&this.gutterUtilityContainer.replaceChildren(this.gutterUtilitySlot);else{if(this.gutterUtilitySlot?.remove(),this.gutterUtilitySlot=void 0,this.gutterUtilityButton==null){let e=document.createElement(`div`);e.innerHTML=Ct(pa());let t=e.firstElementChild;if(!(t instanceof HTMLButtonElement))throw Error(`InteractionManager.ensureGutterUtilityNode: Node element should be a button`);t.remove(),this.gutterUtilityButton=t}this.gutterUtilityButton.parentNode!==this.gutterUtilityContainer&&this.gutterUtilityContainer.replaceChildren(this.gutterUtilityButton)}}revealUtilityFromGutterPath(e){if(this.placeUtilityFromSelection())return;let t=this.resolvePointerTarget(e);ya(t)&&t.numberColumn&&this.showUtilityOnLine(this.toEventBaseProps(t))}placeUtility(){if(!this.placeUtilityFromSelection()){if(this.hoveredLine!=null){this.showUtilityOnLine(this.hoveredLine);return}this.hideUtility()}}placeUtilityFromSelection(){let e=this.currentSelectionEnds();if(e==null)return!1;let t=this.targetForSelectionPoint(e.bottom);return t==null?this.hideUtility():this.showUtilityOnLine(this.toEventBaseProps(t)),!0}showUtilityOnLine(e){this.gutterUtilityContainer!=null&&(this.gutterUtilityLine=e,e.numberElement.appendChild(this.gutterUtilityContainer))}hideUtility(){this.gutterUtilityContainer?.remove(),this.gutterUtilityLine=void 0}currentSelectionEnds(){let e=this.getCurrentSelectionRange();return e==null?void 0:this.selectionEnds(e)}selectionEnds(e){let t={lineNumber:e.start,side:e.side},n={lineNumber:e.end,side:e.endSide??e.side},r=this.selectionPointRowIndex(t),i=this.selectionPointRowIndex(n);if(r!=null&&i!=null)return r>i?{top:n,bottom:t}:{top:t,bottom:n}}selectionPointRowIndex(e){let t=this.getLineIndex(e.lineNumber,e.side);if(t!=null)return this.isSplitDiff()?t[1]:t[0]}targetForSelectionPoint(e){if(this.pre==null)return;let t=this.getLineIndex(e.lineNumber,e.side);if(t==null)return;let n=this.mode===`diff`?`${t[0]},${t[1]}`:`${t[0]}`,r=this.pre.querySelectorAll(`[data-column-number="${e.lineNumber}"][data-line-index="${n}"]`);for(let t of r){if(!(t instanceof HTMLElement))continue;let n=this.resolvePointerTarget(Ea(t));if(ya(n)&&(this.mode!==`diff`||e.side==null||n.side===e.side))return n}}attachDocumentPointerListeners(){this.hasDocumentPointerListeners||=(document.addEventListener(`pointermove`,this.handleDocumentPointerMove),document.addEventListener(`pointerup`,this.handleDocumentPointerUp),document.addEventListener(`pointercancel`,this.handleDocumentPointerCancel),!0)}detachDocumentPointerListeners(){this.hasDocumentPointerListeners&&=(document.removeEventListener(`pointermove`,this.handleDocumentPointerMove),document.removeEventListener(`pointerup`,this.handleDocumentPointerUp),document.removeEventListener(`pointercancel`,this.handleDocumentPointerCancel),!1)}clearPointerSession(){this.pointerSession={mode:`idle`}}clearPendingSingleLineState(){this.pointerSession.mode===`pendingSingleLineUnselect`&&(this.pointerSession={mode:`idle`})}selectionInfoFromPath(e,t){let n=this.resolvePointerTarget(e);if(ya(n)&&!(t&&!n.numberColumn)&&n.splitLineIndex!=null)return{lineIndex:n.splitLineIndex,lineNumber:n.lineNumber,eventSide:this.mode===`diff`?n.side:void 0}}resolveSelectionInfo(e,t){let n=this.resolveSelectionPath(e,t);return n==null?void 0:this.selectionInfoFromPath(n,t.requireNumberColumn)}selectionPointFromPath(e){let t=this.resolvePointerTarget(e);if(ya(t))return{lineNumber:t.lineNumber,side:this.mode===`diff`?t.side:void 0}}resolveSelectionPoint(e,t){let n=this.resolveSelectionPath(e,t);return n==null?void 0:this.selectionPointFromPath(n)}resolveSelectionPath(e,t){let n=t.excludeUtility!==!1;switch(t.source){case`event-path`:return this.pathFromEventPath(e.composedPath(),n);case`coordinates-first`:{let t=this.pathFromCoordinates(e,n);return t===void 0?this.pathFromEventPath(e.composedPath(),n):t??void 0}}}pathFromCoordinates(e,t){let n=this.hitTest(e);if(n!==void 0)return n===null?null:this.pathFromElement(n,t)??null}pathFromEventPath(e,t){if(!(t&&ha(e))){for(let n of e)if(n instanceof Element)return this.pathFromElement(n,t)}}pathFromElement(e,t){let n=Ea(e);if(t&&ha(n))return;let r=Da(e);return r==null?this.pathFromAnnotationSlot(e):Ea(r)}pathFromAnnotationSlot(e){let t=ka(Oa(e));if(t==null)return;let n=this.targetForSelectionPoint(t);return n==null?void 0:Ea(n.lineElement)}hitTest(e){if(!Number.isFinite(e.clientX)||!Number.isFinite(e.clientY))return;let t=this.pre?.getRootNode(),n=Aa(t)?t:Aa(document)?document:void 0;if(n!=null)return n.elementFromPoint(e.clientX,e.clientY)}getLineIndex(e,t){let{getLineIndex:n}=this.options;return n==null?[e-1,e-1]:n(e,t)}getCurrentSelectionRange(){return this.proposedSelectedRange===void 0?this.selectedRange:this.proposedSelectedRange}clearProposedSelection(){this.proposedSelectedRange=void 0}updateSelection(e,t,n=!0){let r=this.getCurrentSelectionRange(),i;if(e==null)i=null;else{let n=this.selectionAnchor?.side??t,r=this.selectionAnchor?.lineNumber??e;i=this.buildSelectionRange(r,e,n,t)}xi(r??void 0,i??void 0)||(this.selectedRangeHighlightSide=void 0,this.selectedRangeLineNumberOnly=!1,this.options.controlledSelection===!0?this.proposedSelectedRange=i:(this.selectedRange=i,hi(this.renderSelection)),this.placeUtility(),n&&this.notifySelectionChangeDelta())}getIndexesFromSelection(e,t){if(this.pre==null)return;let n=this.getLineIndex(e.start,e.side),r=this.getLineIndex(e.end,e.endSide??e.side);return n!=null&&r!=null?{start:t?n[1]:n[0],end:t?r[1]:r[0]}:void 0}getSelectionRenderState(){return{selectedLines:{range:this.selectedRange,highlightSide:this.selectedRangeHighlightSide,lineNumberOnly:this.selectedRangeLineNumberOnly},editorActiveLine:{range:this.editorActiveLine==null?null:{start:this.editorActiveLine,end:this.editorActiveLine,side:this.editorActiveLineSide},highlightSide:this.editorActiveLineSide,lineNumberOnly:this.editorLineNumberOnly}}}resolveLineRenderRange(e,t,n){if(e.range==null)return;let r=this.getIndexesFromSelection(e.range,t);if(r==null)throw console.error({rowRange:r,range:e.range}),Error(`InteractionManager.renderSelection: No valid ${n} rowRange`);return r}getLineRenderColumns(e,t,n,r){if(this.pre==null||t==null&&r==null)return[];let{children:i}=this.pre;if(i.length>2)throw console.error(i),Error(`InteractionManager.renderSelection: Somehow there are more than 2 code elements...`);let a=[];for(let o of i){let i=o.hasAttribute(`data-deletions`)?`deletions`:o.hasAttribute(`data-additions`)?`additions`:void 0,s=e!=null&&t!=null&&(e.highlightSide==null||i==null||e.highlightSide===i),c=n!=null&&r!=null&&(n.highlightSide==null||i==null||n.highlightSide===i);if(!s&&!c)continue;let[l,u]=o.children;if(!(l instanceof HTMLElement)||!(u instanceof HTMLElement))throw Error(`InteractionManager.renderSelection: missing gutter or content element`);if(u.children.length!==l.children.length)throw Error(`InteractionManager.renderSelection: gutter and content children dont match, something is wrong`);a.push({content:u,gutter:l,renderEditorActiveLine:c,renderSelectedLines:s})}return a}renderSelection=()=>{gi(this.renderSelection);let e=this.getSelectionRenderState();if(this.pre==null)return;let{editorActiveLine:t,selectedLines:n}=e,r=!Ma(this.renderedSelectedLinesState,n),i=!Ma(this.renderedEditorActiveLineState,t);if(!r&&!i)return;r&&(this.renderedSelectedLinesState=void 0),i&&(this.renderedEditorActiveLineState=void 0);let a=this.pre.getAttribute(`data-diff-type`)===`split`,o=r?this.resolveLineRenderRange(n,a,`selected-lines`):void 0,s=i?this.resolveLineRenderRange(t,a,`editor-active-line`):void 0,c=this.getLineRenderColumns(r?n:void 0,o,i?t:void 0,s),l=n.range==null||c.some(e=>e.renderSelectedLines),u=t.range==null||c.some(e=>e.renderEditorActiveLine);if(r)for(let e of this.pre.querySelectorAll(`[data-selected-line]`))e.removeAttribute(`data-selected-line`);if(i)for(let e of this.pre.querySelectorAll(`[data-editor-active-line]`))e.removeAttribute(`data-editor-active-line`);let d=o==null?void 0:Math.min(o.start,o.end),f=o==null?void 0:Math.max(o.start,o.end),p=d===f,m=s?.start;for(let e of c){let{content:r,gutter:i,renderEditorActiveLine:o,renderSelectedLines:s}=e,c=Math.max(s?f??-1/0:-1/0,o?m??-1/0:-1/0),l=r.children.length;for(let e=0;e<l;e++){let l=r.children[e],u=i.children[e];if(!(l instanceof HTMLElement)||!(u instanceof HTMLElement))continue;let h=this.parseLineIndex(l,a);if((h??0)>c)break;if(h!=null){if(s&&d!=null&&f!=null&&h>=d&&h<=f){let e=p?`single`:h===d?`first`:h===f?`last`:``;u.setAttribute(`data-selected-line`,e),n.lineNumberOnly||(l.setAttribute(`data-selected-line`,e),u.nextSibling instanceof HTMLElement&&l.nextSibling instanceof HTMLElement&&(l.nextSibling.hasAttribute(`data-line-annotation`)||l.nextSibling.hasAttribute(`data-merge-conflict-actions`))&&(p?(e=`last`,l.setAttribute(`data-selected-line`,`first`)):h===d?e=``:h===f&&l.setAttribute(`data-selected-line`,``),l.nextSibling.setAttribute(`data-selected-line`,e),u.nextSibling.setAttribute(`data-selected-line`,e)))}o&&h===m&&(u.setAttribute(`data-editor-active-line`,``),t.lineNumberOnly||l.setAttribute(`data-editor-active-line`,``))}}}r&&l&&(this.renderedSelectedLinesState=n),i&&u&&(this.renderedEditorActiveLineState=t)};notifySelectionCommitted(e){this.options.onLineSelected?.(e)}notifySelectionChangeDelta(){this.options.onLineSelectionChange?.(this.getCurrentSelectionRange()??null)}notifySelectionStart(e){this.options.onLineSelectionStart?.(e)}notifySelectionEnd(e){this.options.onLineSelectionEnd?.(e)}toEventBaseProps(e){return this.mode===`file`?{type:`line`,lineElement:e.lineElement,lineNumber:e.lineNumber,numberColumn:e.numberColumn,numberElement:e.numberElement}:{type:`diff-line`,annotationSide:e.side,lineType:e.lineType,lineElement:e.lineElement,numberElement:e.numberElement,lineNumber:e.lineNumber,numberColumn:e.numberColumn}}toTokenEventBaseProps({lineCharEnd:e,lineCharStart:t,lineNumber:n,side:r,tokenElement:i,tokenText:a}){return this.mode===`file`?{type:`token`,lineCharEnd:e,lineCharStart:t,lineNumber:n,tokenElement:i,tokenText:a}:{type:`token`,lineCharEnd:e,lineCharStart:t,lineNumber:n,side:r,tokenElement:i,tokenText:a}}buildSelectedLineRange(e,t){return this.buildSelectionRange(e.lineNumber,t.lineNumber,e.side,t.side)}buildSelectionRange(e,t,n,r){return{start:e,end:t,...n==null?{}:{side:n},...n!==r&&r!=null?{endSide:r}:{}}}resolvePointerTarget(e){let t=!1,n,r,i,a,o,s,c,l,u,d;for(let f of e){if(!(f instanceof HTMLElement))continue;if(d==null&&f.hasAttribute(`data-merge-conflict-action`)){let e=f.getAttribute(`data-merge-conflict-action`)??void 0,t=f.getAttribute(`data-merge-conflict-conflict-index`)??void 0,n=t==null?NaN:Number.parseInt(t,10);wa(e)&&Number.isFinite(n)&&(d={kind:`merge-conflict-action`,resolution:e,conflictIndex:n})}if(s==null&&f.hasAttribute(`data-char`)){s=f;let e=f.getAttribute(`data-char`);if(e!=null){let t=Number.parseInt(e,10);if(!Number.isNaN(t)){let e=f.textContent??``,n=t+e.length;(e.trim()!==``||this.options.enableTokenInteractionsOnWhitespace===!0)&&(c={tokenElement:s,lineCharStart:t,lineCharEnd:n,tokenText:e});continue}}}let e=o==null?f.getAttribute(`data-column-number`)??void 0:void 0;if(e!=null){o=f,u=Number.parseInt(e,10),t=!0,n=Pa(f),a=f.getAttribute(`data-line-index`)??void 0;continue}let p=i==null?f.getAttribute(`data-line`)??void 0:void 0;if(p!=null){i=f,u=Number.parseInt(p,10),n=Pa(f),a=f.getAttribute(`data-line-index`)??void 0;continue}if(l==null&&(f.hasAttribute(`data-expand-button`)||f.hasAttribute(`data-unmodified-lines`))){l={hunkIndex:void 0,direction:f.hasAttribute(`data-expand-up`)?`up`:f.hasAttribute(`data-expand-down`)?`down`:`both`,all:f.hasAttribute(`data-expand-all-button`)};continue}let m=l==null?void 0:f.getAttribute(`data-expand-index`)??void 0;if(l!=null&&m!=null){let e=Number.parseInt(m,10);Number.isNaN(e)||(l.hunkIndex=e);continue}if(r==null&&f.hasAttribute(`data-code`)){r=f;break}}if(d!=null)return d;if(l?.hunkIndex!=null)return{type:`line-info`,hunkIndex:l.hunkIndex,direction:l.direction,all:l.all};if(i??=a==null?void 0:Ta(r,`[data-line][data-line-index="${a}"]`),o??=a==null?void 0:Ta(r,`[data-column-number][data-line-index="${a}"]`),r==null||i==null||o==null||n==null||u==null||Number.isNaN(u))return;let f=this.parseLineIndex(i,this.isSplitDiff());return c==null?this.mode===`file`?{kind:`line`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:void 0,splitLineIndex:f}:{kind:`line`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:Na(n,r),splitLineIndex:f}:this.mode===`file`?{kind:`token`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:void 0,splitLineIndex:f,...c}:{kind:`token`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:Na(n,r),splitLineIndex:f,...c}}isSplitDiff(){return this.pre?.getAttribute(`data-diff-type`)===`split`}parseLineIndex(e,t){let n=(e.getAttribute(`data-line-index`)??``).split(`,`).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e));if(t&&n.length===2)return n[1];if(!t)return n[0]}};function _a({enableTokenInteractionsOnWhitespace:e,enableGutterUtility:t,lineHoverHighlight:n,onGutterUtilityClick:r,onLineClick:i,onLineEnter:a,onLineLeave:o,onLineNumberClick:s,onTokenClick:c,onTokenEnter:l,onTokenLeave:u,renderGutterUtility:d,__debugPointerEvents:f,enableLineSelection:p,controlledSelection:m,onLineSelected:h,onLineSelectionStart:g,onLineSelectionChange:_,onLineSelectionEnd:v},y,b,x){return{enableTokenInteractionsOnWhitespace:e,enableGutterUtility:va({enableGutterUtility:t,renderGutterUtility:d,onGutterUtilityClick:r}),usesCustomGutterUtility:d!=null,lineHoverHighlight:n,onGutterUtilityClick:r,onHunkExpand:y,onMergeConflictActionClick:x,onLineClick:i,onLineEnter:a,onLineLeave:o,onLineNumberClick:s,onTokenClick:c,onTokenEnter:l,onTokenLeave:u,__debugPointerEvents:f,enableLineSelection:p,controlledSelection:m,onLineSelected:h,onLineSelectionStart:g,onLineSelectionChange:_,onLineSelectionEnd:v,getLineIndex:b}}function va({enableGutterUtility:e,renderGutterUtility:t,onGutterUtilityClick:n}){if(n!=null&&t!=null)throw Error(`Cannot use both 'onGutterUtilityClick' and 'renderGutterUtility'. Use only one gutter utility API.`);return e??!1}function ya(e){return e!=null&&`kind`in e&&e.kind===`line`}function ba(e){return e!=null&&`kind`in e&&e.kind===`token`}function xa(e){return ya(e)||ba(e)}function Sa(e){return`type`in e&&e.type===`line-info`}function Ca(e){return`kind`in e&&e.kind===`merge-conflict-action`}function wa(e){return e===`current`||e===`incoming`||e===`both`}function Ta(e,t){let n=e?.querySelector(t);return n instanceof HTMLElement?n:void 0}function Ea(e){let t=[],n=e;for(;n!=null;)t.push(n),n=n.parentNode;return t}function Da(e){let t=e.closest(`[data-line], [data-column-number]`);if(t instanceof HTMLElement)return t;let n=e.closest(`[data-line-annotation], [data-gutter-buffer="annotation"]`);if(!(n instanceof HTMLElement))return;let r=n.previousElementSibling;return r instanceof HTMLElement&&(r.hasAttribute(`data-line`)||r.hasAttribute(`data-column-number`))?r:void 0}function Oa(e){let t=e.closest(`[slot^="annotation-"]`);if(t instanceof HTMLElement)return t.getAttribute(`slot`)??void 0;if(e instanceof HTMLElement){let t=e.getAttribute(`name`)??void 0;return t!=null&&t.startsWith(`annotation-`)?t:void 0}}function ka(e){if(e==null)return;let t=/^annotation-(?:(additions|deletions)-)?(\d+)$/.exec(e);if(t==null)return;let n=Number.parseInt(t[2],10);if(!(!Number.isFinite(n)||n<=0))return{lineNumber:n,side:t[1]}}function Aa(e){return e!=null&&typeof e.elementFromPoint==`function`}function ja(e,t){return e===t||xi(e??void 0,t??void 0)}function Ma(e,t){return e?.highlightSide===t.highlightSide&&e?.lineNumberOnly===t.lineNumberOnly&&ja(e?.range??null,t.range)}function Na(e,t){switch(e){case`change-deletion`:return`deletions`;case`change-addition`:return`additions`;default:return t.hasAttribute(`data-deletions`)?`deletions`:`additions`}}function Pa(e){let t=e.getAttribute(`data-line-type`);if(t!=null)switch(t){case`change-deletion`:case`change-addition`:case`context`:case`context-expanded`:return t;default:return}}function Fa(e=`none`,t,...n){switch(e){case`none`:return;case`both`:break;case`click`:if(t!==`click`)return;break;case`move`:if(t!==`move`)return}console.log(...n)}var Ia=class e{static resizeObserver;static managersByElement=new Map;static getResizeObserver(){let t=e.resizeObserver??new ResizeObserver(e.handleSharedResizeEntries);return e.resizeObserver=t,t}static handleSharedResizeEntries(t){let n=new Map;for(let r of t){let t=e.managersByElement.get(r.target);if(t==null)continue;let i=n.get(t);i==null?n.set(t,[r]):i.push(r)}for(let[e,t]of n)e.handleResizeEntries(t)}observedNodes=new Map;setup(e,{disableAnnotations:t,columnVariables:n=`apply`}){let r=new Set,i=n===`apply`,a=0,o=new Map(this.observedNodes);this.observedNodes.clear();for(let t of e.children){if(a===2)break;let e=(()=>{if(t instanceof HTMLElement&&t.tagName===`CODE`)return t})();if(e==null)continue;a++;let n=o.get(e);if(n!=null&&n.type!==`code`)throw Error(`ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible`);let r=e.firstElementChild;r instanceof HTMLElement||(r=null),n==null?(n={type:`code`,codeElement:e,numberElement:r,codeWidth:`auto`,numberWidth:0,applyColumnVariables:i},this.observedNodes.set(e,n),this.observe(e),r!=null&&(this.observedNodes.set(r,n),this.observe(r))):(this.observedNodes.set(e,n),o.delete(e),n.numberElement===r?n.numberElement==null?n.numberWidth=0:(o.delete(n.numberElement),this.observedNodes.set(n.numberElement,n)):(n.numberElement!=null&&(this.unobserve(n.numberElement),o.delete(n.numberElement)),r!=null&&(this.observe(r),o.delete(r),this.observedNodes.set(r,n)),n.numberElement=r,n.numberWidth=0),za(n,i))}if(a>1&&!t){let t=e.querySelectorAll(`[data-line-annotation*=","]`),n=new Map;for(let e of t){if(!(e instanceof HTMLElement))continue;let t=e.getAttribute(`data-line-annotation`)??``;if(!/^-?\d+,-?\d+$/.test(t)){console.error(`DiffFileRenderer.setupResizeObserver: Invalid element or annotation`,{lineAnnotation:t,element:e});continue}let r=n.get(t);r??(r=[],n.set(t,r)),r.push(e)}for(let[e,t]of n){if(t.length!==2){console.error(`DiffFileRenderer.setupResizeObserver: Bad Pair`,e,t);continue}let[n,i]=t,a=n.firstElementChild,s=i.firstElementChild;if(!(n instanceof HTMLElement)||!(i instanceof HTMLElement)||!(a instanceof HTMLElement)||!(s instanceof HTMLElement))continue;let c=o.get(a);if(c!=null){this.observedNodes.set(a,c),this.observedNodes.set(s,c),o.delete(a),o.delete(s);continue}let l=a.getBoundingClientRect().height,u=s.getBoundingClientRect().height;c={type:`annotations`,column1:{container:n,child:a,childHeight:l},column2:{container:i,child:s,childHeight:u},currentHeight:`auto`},r.add({child1:a,child2:s,item:c,newHeight:Math.max(l,u)})}for(let e of r)this.applyNewHeight(e.item,e.newHeight),this.observedNodes.set(e.child1,e.item),this.observedNodes.set(e.child2,e.item),this.observe(e.child1),this.observe(e.child2);r.clear()}for(let[e,t]of o)this.unobserve(e),t.type===`code`?Ha(t):Ua(t);o.clear()}cleanUp(){for(let e of this.observedNodes.keys())this.unobserve(e);this.observedNodes.clear()}observe(t){let{managersByElement:n}=e,r=n.get(t);if(r!==this){if(r!=null&&r!==this)throw Error(`ResizeManager.observe: element is already owned by another ResizeManager`);n.set(t,this),e.getResizeObserver().observe(t)}}unobserve(t){let{managersByElement:n,resizeObserver:r}=e,i=n.get(t);if(i!=null){if(i!==this)throw Error(`ResizeManager.unobserve: element is owned by another ResizeManager`);n.delete(t),r?.unobserve(t),r!=null&&n.size===0&&(r.disconnect(),e.resizeObserver=void 0)}}handleResizeEntries(e){let t=new Map,n=new Set;for(let r of e){let{target:e,borderBoxSize:i,contentBoxSize:a}=r;if(!(e instanceof HTMLElement)){console.error(`ResizeManager.handleResizeEntries: Invalid element for ResizeObserver`,r);continue}let o=this.observedNodes.get(e);if(o==null){console.error(`ResizeManager.handleResizeEntries: Not a valid observed node`,r);continue}if(o.type===`annotations`){let t=(()=>{if(e===o.column1.child)return o.column1;if(e===o.column2.child)return o.column2})();if(t==null){console.error(`ResizeManager.handleResizeEntries: Couldn't find a column for`,{item:o,target:e});continue}t.childHeight=i[0].blockSize,n.add(o)}else if(o.type===`code`){let n=t.get(o)??{},r=a[0].inlineSize;e===o.codeElement?n.codeInlineSize=r:e===o.numberElement&&(n.numberInlineSize=r),t.set(o,n)}}this.applyAnnotationUpdates(n),n.clear(),this.applyColumnUpdates(t),t.clear()}applyAnnotationUpdates(e){for(let t of e)this.applyNewHeight(t,Math.max(t.column1.childHeight,t.column2.childHeight))}applyColumnUpdates=e=>{for(let[t,n]of e){let e=n.codeInlineSize==null?t.codeWidth:La(n.codeInlineSize),r=n.numberInlineSize==null?t.numberWidth:Ra(n.numberInlineSize),i=e!==t.codeWidth,a=r!==t.numberWidth;!i&&!a||(t.codeWidth=e,t.numberWidth=r,t.applyColumnVariables&&Ba(t,{codeWidthChanged:i,numberWidthChanged:a}))}};applyNewHeight(e,t){t!==e.currentHeight&&(e.currentHeight=Math.max(t,0),e.column1.container.style.setProperty(`--diffs-annotation-min-height`,`${e.currentHeight}px`),e.column2.container.style.setProperty(`--diffs-annotation-min-height`,`${e.currentHeight}px`))}};function La(e){let t=Math.max(Math.floor(e),0);return t===0?`auto`:t}function Ra(e){return Math.max(Math.ceil(e),0)}function za(e,t){e.applyColumnVariables!==t&&(e.applyColumnVariables=t,t?Ba(e,{codeWidthChanged:!0,numberWidthChanged:!0}):Va(e))}function Ba(e,{codeWidthChanged:t,numberWidthChanged:n}){let{codeElement:r,codeWidth:i,numberWidth:a}=e;if(t&&r.style.setProperty(`--diffs-column-width`,`${typeof i==`number`?`${i}px`:`auto`}`),n&&r.style.setProperty(`--diffs-column-number-width`,`${a===0?`auto`:`${a}px`}`),t||n&&i!==`auto`){let e=typeof i==`number`?Math.max(i-a,0):0;r.style.setProperty(`--diffs-column-content-width`,`${e>0?`${e}px`:`auto`}`)}}function Va(e){e.codeElement.style.removeProperty(`--diffs-column-content-width`),e.codeElement.style.removeProperty(`--diffs-column-number-width`),e.codeElement.style.removeProperty(`--diffs-column-width`)}function Ha(e){e.codeElement.isConnected&&Va(e)}function Ua(e){e.column1.container.isConnected&&e.column1.container.style.removeProperty(`--diffs-annotation-min-height`),e.column2.container.isConnected&&e.column2.container.style.removeProperty(`--diffs-annotation-min-height`)}function Wa(e){for(let t of Array.isArray(e)?e:[e])if(t!==`text`&&t!==`ansi`&&!Pt.has(t))return!1;return!0}function Ga(e){for(let t of dn(e))if(!Qt.has(t))return!1;return!0}function Ka(e,t){return e==null||t==null?e===t:e.startingLine===t.startingLine&&e.totalLines===t.totalLines&&e.bufferBefore===t.bufferBefore&&e.bufferAfter===t.bufferAfter}function qa(e){return q({tagName:`div`,children:[q({tagName:`div`,children:e.annotations?.map(e=>q({tagName:`slot`,properties:{name:e}})),properties:{"data-annotation-content":``}})],properties:{"data-line-annotation":`${e.hunkIndex},${e.lineIndex}`}})}function Ja(e){switch(e){case`file`:return`diffs-icon-file-code`;case`change`:return`diffs-icon-symbol-modified`;case`new`:return`diffs-icon-symbol-added`;case`deleted`:return`diffs-icon-symbol-deleted`;case`rename-pure`:case`rename-changed`:return`diffs-icon-symbol-moved`}}function Ya({fileOrDiff:e,mode:t,stickyHeader:n}){let r=`type`in e?e:void 0,i={"data-diffs-header":t,"data-change-type":r?.type,"data-sticky":n?``:void 0};return q({tagName:`div`,children:[t===`custom`?q({tagName:`slot`,properties:{name:$e}}):Xa({name:e.name,prevName:`prevName`in e?e.prevName:void 0,iconType:r?.type??`file`}),...t===`custom`?[]:[Za(r)]],properties:i})}function Xa({name:e,prevName:t,iconType:n}){let r=[q({tagName:`slot`,properties:{name:en}}),lt({name:Ja(n),properties:{"data-change-icon":n}})];return t!=null&&(r.push(q({tagName:`div`,children:[q({tagName:`bdi`,children:[Ie(t)]})],properties:{"data-prev-name":``}})),r.push(lt({name:`diffs-icon-arrow-right-short`,properties:{"data-rename-icon":``}}))),r.push(q({tagName:`div`,children:[q({tagName:`bdi`,children:[Ie(e)]})],properties:{"data-title":``}})),r.push(q({tagName:`slot`,properties:{name:Ve}})),q({tagName:`div`,children:r,properties:{"data-header-content":``}})}function Za(e){let t=[];if(e!=null){let n=0,r=0;for(let t of e.hunks)n+=t.additionLines,r+=t.deletionLines;(r>0||n===0)&&t.push(q({tagName:`span`,children:[Ie(`-${r}`)],properties:{"data-deletions-count":``}})),(n>0||r===0)&&t.push(q({tagName:`span`,children:[Ie(`+${n}`)],properties:{"data-additions-count":``}}))}return t.push(q({tagName:`slot`,properties:{name:Ye}})),q({tagName:`div`,children:t,properties:{"data-metadata":``}})}function Qa(e){return q({tagName:`pre`,properties:$a(e)})}function $a({diffIndicators:e,disableBackground:t,disableLineNumbers:n,overflow:r,split:i,totalLines:a,type:o,customProperties:s}){return{...s,"data-diff":o===`diff`?``:void 0,"data-file":o===`file`?``:void 0,"data-diff-type":o===`diff`?i?`split`:`single`:void 0,"data-overflow":r,"data-disable-line-numbers":n?``:void 0,"data-background":t?void 0:``,"data-indicators":e===`bars`||e===`classic`?e:void 0,style:`--diffs-min-number-column-width-default:${`${a}`.length}ch;`}}function eo(e,{theme:t,preferredHighlighter:n=`shiki-js`}){return{langs:[e??`text`],themes:dn(t),preferredHighlighter:n}}function to(e){return`annotation-${`side`in e?`${e.side}-`:``}${e.lineNumber}`}var no={compositeOverBg:at,contrastRatio:Ae,deriveMutedFg:jt,hoverWouldEraseText:ln,isDarkSurface:Yt,isFullyTransparent:rn,pickReadableForeground:Rt,relativeLuminance:wt,surfacesMatch:Xt},ro=`-1,-1`;function io(e){return e?.some(e=>e.lineNumber===0)??!1}function ao(e){let t=e[0];return t!=null&&t.length>0?t:void 0}function oo(e){return e.startingLine===0&&e.totalLines>0}function so(e,t){return e.endsWith(`\r
13
+ `:t)}function la(e,t,n){return e===`change`?{type:`change`,additions:0,deletions:0,additionLineIndex:n,deletionLineIndex:t}:{type:`context`,lines:0,additionLineIndex:n,deletionLineIndex:t}}var ua=`/dev/null`;function da(e,t,n,r=!1){if(e===null&&t===null)throw Error(`parseDiffFromFile: You must pass oldFile, newFile, or both`);let i=e??fa(),a=t??fa(),o=Bi(lt(i.name,a.name,i.contents,a.contents,i.header,a.header,n),{cacheKey:(()=>{let n=e?.cacheKey??e?.name,r=t?.cacheKey??t?.name;return n!=null&&r!=null?n+`:`+r:n??r})(),oldFile:i,newFile:a,throwOnError:r});if(o==null)throw Error(`parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?`);e===null?(o.type=`new`,o.prevName=void 0):t===null&&(o.type=`deleted`,o.prevName=void 0);let s=t?.lang??(t===null?e?.lang:void 0);return s!=null&&(o.lang=s),o}function fa(){return{name:ua,contents:``}}function pa(){return K({tagName:`button`,properties:{"data-utility-button":``,type:`button`},children:[ct({name:`diffs-icon-plus`,properties:{"data-icon":``}})]})}function ma(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side}function ha(e){for(let t of e)if(t instanceof HTMLElement&&(t.hasAttribute(`data-utility-button`)||t.hasAttribute(`data-gutter-utility-slot`)||t.getAttribute(`slot`)===`gutter-utility-slot`||t.getAttribute(`name`)===`gutter-utility-slot`))return!0;return!1}var ga=class{mode;options;hoveredLine;hoveredToken;pre;gutterUtilityLine;gutterUtilityContainer;gutterUtilityButton;gutterUtilitySlot;interactiveLinesAttr=!1;interactiveLineNumbersAttr=!1;hasPointerListeners=!1;hasDocumentPointerListeners=!1;selectedRange=null;selectedRangeHighlightSide;selectedRangeLineNumberOnly=!1;editorActiveLine=null;editorActiveLineSide;editorLineNumberOnly=!1;proposedSelectedRange;renderedSelectedLinesState;renderedEditorActiveLineState;selectionAnchor;pointerSession={mode:`idle`};constructor(e,t){this.mode=e,this.options=t}setOptions(e){this.options=e}cleanUp(){this.pre?.removeEventListener(`click`,this.handlePointerClick),this.pre?.removeEventListener(`pointerdown`,this.handlePointerDown),this.pre?.removeEventListener(`pointermove`,this.handlePointerMove),this.pre?.removeEventListener(`pointerleave`,this.handlePointerLeave),this.pre?.removeAttribute(`data-interactive-lines`),this.pre?.removeAttribute(`data-interactive-line-numbers`),this.pre=void 0,this.gutterUtilityContainer?.remove(),this.gutterUtilityLine=void 0,this.gutterUtilityContainer=void 0,this.gutterUtilityButton=void 0,this.gutterUtilitySlot=void 0,this.clearHoveredLine(),this.clearHoveredToken(),this.detachDocumentPointerListeners(),this.clearPointerSession(),gi(this.renderSelection),this.interactiveLinesAttr=!1,this.interactiveLineNumbersAttr=!1,this.hasPointerListeners=!1,this.setSelectionDirty()}setup(e){this.setSelectionDirty();let{usesCustomGutterUtility:t=!1,enableGutterUtility:n=!1}=this.options;this.pre!==e&&(this.cleanUp(),this.pre=e),n?this.ensureGutterUtilityNode(t):this.gutterUtilityContainer!=null&&(this.gutterUtilityContainer.remove(),this.gutterUtilityLine=void 0,this.gutterUtilityContainer=void 0,this.gutterUtilityButton=void 0,this.gutterUtilitySlot=void 0,this.pointerSession.mode===`gutterSelecting`&&(this.clearPointerSession(),this.detachDocumentPointerListeners())),this.syncPointerListeners(e),this.updateInteractiveLineAttributes(),this.renderSelection(),this.placeUtility()}setSelectionDirty(){this.renderedSelectedLinesState=void 0,this.renderedEditorActiveLineState=void 0}isSelectionDirty(){return this.renderedSelectedLinesState===void 0||this.renderedEditorActiveLineState===void 0}setSelection(e,t){let n=!(e===this.selectedRange||xi(e??void 0,this.selectedRange??void 0)),r=t?.lineNumberOnly??!1,i=t?.activeLineSide!==this.selectedRangeHighlightSide||r!==this.selectedRangeLineNumberOnly;!this.isSelectionDirty()&&!n&&!i||(this.proposedSelectedRange=void 0,this.selectedRange=e,this.selectedRangeHighlightSide=t?.activeLineSide,this.selectedRangeLineNumberOnly=r,this.renderSelection(),this.placeUtility(),n&&t?.notify!==!1&&this.notifySelectionCommitted(e))}setEditorActiveLine(e,{lineNumberOnly:t=!1,side:n}={}){let r=e!==this.editorActiveLine,i=n!==this.editorActiveLineSide||t!==this.editorLineNumberOnly;!this.isSelectionDirty()&&!r&&!i||(this.editorActiveLine=e,this.editorActiveLineSide=n,this.editorLineNumberOnly=t,this.renderSelection())}getSelection(){return this.selectedRange}getHoveredLine=()=>{let e=this.gutterUtilityLine??this.hoveredLine;if(e!=null){if(this.mode===`diff`&&e.type===`diff-line`)return{lineNumber:e.lineNumber,side:e.annotationSide};if(this.mode===`file`&&e.type===`line`)return{lineNumber:e.lineNumber}}};handlePointerClick=e=>{let{onHunkExpand:t,onLineClick:n,onLineNumberClick:r,onTokenClick:i,onMergeConflictActionClick:a}=this.options;(t!=null||n!=null||r!=null||a!=null||i!=null)&&(this.options.onGutterUtilityClick!=null&&ha(e.composedPath())||(Fa(this.options.__debugPointerEvents,`click`,`FileDiff.DEBUG.handlePointerClick:`,e),this.handlePointerEvent({eventType:`click`,event:e})))};handlePointerMove=e=>{if(e.pointerType!==`mouse`)return;let{lineHoverHighlight:t=`disabled`,onLineEnter:n,onLineLeave:r,onTokenEnter:i,onTokenLeave:a,enableGutterUtility:o=!1}=this.options;t===`disabled`&&!o&&n==null&&r==null&&i==null&&a==null||(Fa(this.options.__debugPointerEvents,`move`,`FileDiff.DEBUG.handlePointerMove:`,e),this.handlePointerEvent({eventType:`move`,event:e}))};handlePointerLeave=e=>{let{__debugPointerEvents:t}=this.options;if(Fa(t,`move`,`FileDiff.DEBUG.handlePointerLeave: no event`),this.hoveredLine==null&&this.hoveredToken==null){Fa(t,`move`,`FileDiff.DEBUG.handlePointerLeave: returned early, no hovered line or token`);return}this.hoveredToken!=null&&(this.options.onTokenLeave?.(this.hoveredToken,e),this.clearHoveredToken()),this.hoveredLine!=null&&(this.options.onLineLeave?.({...this.hoveredLine,event:e}),this.clearHoveredLine()),this.placeUtility()};handlePointerEvent({eventType:e,event:t}){let{__debugPointerEvents:n}=this.options,r=t.composedPath();Fa(n,e,`FileDiff.DEBUG.handlePointerEvent:`,{eventType:e,composedPath:r});let i=this.resolvePointerTarget(r);Fa(n,e,`FileDiff.DEBUG.handlePointerEvent: resolvePointerTarget result:`,i);let{onLineClick:a,onLineNumberClick:o,onLineEnter:s,onLineLeave:c,onTokenClick:l,onTokenEnter:u,onTokenLeave:d,onHunkExpand:f,onMergeConflictActionClick:p}=this.options;switch(e){case`move`:{let e=xa(i)&&this.hoveredLine?.lineElement===i.lineElement;ba(i)&&this.hoveredToken?.tokenElement===i.tokenElement||(this.hoveredToken!=null&&(d?.(this.hoveredToken,t),this.clearHoveredToken()),ba(i)&&(this.setHoveredToken(this.toTokenEventBaseProps(i)),u?.(this.hoveredToken,t))),e||(this.hoveredLine!=null&&(c?.({...this.hoveredLine,event:t}),this.clearHoveredLine()),xa(i)?(this.setHoveredLine(this.toEventBaseProps(i)),this.placeUtility(),s?.({...this.hoveredLine,event:t})):this.placeUtility());break}case`click`:{if(i==null)break;if(Ca(i)&&p!=null){p(i);break}if(Sa(i)&&f!=null){f(i.hunkIndex,i.all||t.shiftKey?`both`:i.direction,i.all||t.shiftKey?1/0:void 0);break}if(!xa(i))break;ba(i)&&l!=null&&l(this.toTokenEventBaseProps(i),t);let e=this.toEventBaseProps(i);o!=null&&i.numberColumn?o({...e,event:t}):a?.({...e,event:t});break}}}syncPointerListeners(e){let{__debugPointerEvents:t,lineHoverHighlight:n=`disabled`,onLineClick:r,onLineNumberClick:i,onLineEnter:a,onLineLeave:o,onTokenClick:s,onTokenEnter:c,onTokenLeave:l,onHunkExpand:u,onMergeConflictActionClick:d,enableGutterUtility:f=!1,enableLineSelection:p=!1,onGutterUtilityClick:m}=this.options,h=m!=null,g=n!==`disabled`||r!=null||i!=null||a!=null||o!=null||s!=null||c!=null||l!=null||u!=null||d!=null||f||p||h;g&&!this.hasPointerListeners?(e.addEventListener(`click`,this.handlePointerClick),e.addEventListener(`pointerdown`,this.handlePointerDown),e.addEventListener(`pointermove`,this.handlePointerMove),e.addEventListener(`pointerleave`,this.handlePointerLeave),this.hasPointerListeners=!0,Fa(t,`click`,`FileDiff.DEBUG.attachEventListeners: Attaching click events for:`,(()=>{let e=[];return(t===`both`||t===`click`)&&(r!=null&&e.push(`onLineClick`),i!=null&&e.push(`onLineNumberClick`),u!=null&&e.push(`expandable hunk separators`),d!=null&&e.push(`merge conflict actions`)),e})()),Fa(t,`move`,`FileDiff.DEBUG.attachEventListeners: Attaching pointer move event`),Fa(t,`move`,`FileDiff.DEBUG.attachEventListeners: Attaching pointer leave event`)):!g&&this.hasPointerListeners&&(e.removeEventListener(`click`,this.handlePointerClick),e.removeEventListener(`pointerdown`,this.handlePointerDown),e.removeEventListener(`pointermove`,this.handlePointerMove),e.removeEventListener(`pointerleave`,this.handlePointerLeave),this.hasPointerListeners=!1);let _=this.pointerSession.mode===`selecting`||this.pointerSession.mode===`pendingSingleLineUnselect`,v=this.pointerSession.mode===`gutterSelecting`;(!p&&_||!h&&v)&&(this.clearPointerSession(),this.detachDocumentPointerListeners(),this.selectionAnchor=void 0,this.clearPendingSingleLineState())}updateInteractiveLineAttributes(){if(this.pre==null)return;let{onLineClick:e,onLineNumberClick:t,enableLineSelection:n=!1}=this.options,r=e!=null,i=t!=null||n;r&&!this.interactiveLinesAttr?(this.pre.setAttribute(`data-interactive-lines`,``),this.interactiveLinesAttr=!0):!r&&this.interactiveLinesAttr&&(this.pre.removeAttribute(`data-interactive-lines`),this.interactiveLinesAttr=!1),i&&!this.interactiveLineNumbersAttr?(this.pre.setAttribute(`data-interactive-line-numbers`,``),this.interactiveLineNumbersAttr=!0):!i&&this.interactiveLineNumbersAttr&&(this.pre.removeAttribute(`data-interactive-line-numbers`),this.interactiveLineNumbersAttr=!1)}handlePointerDown=e=>{if(e.pointerType===`mouse`&&e.button!==0||this.pre==null||this.pointerSession.mode!==`idle`)return;let t=e.composedPath();ha(t)&&this.options.onGutterUtilityClick!=null?this.startGutterSelectionFromPointerDown(e):(e.pointerType!==`mouse`&&this.revealUtilityFromGutterPath(t),this.startLineSelectionFromPointerDown(e))};startLineSelectionFromPointerDown(e){let{enableLineSelection:t=!1}=this.options;if(!t)return;let n=this.resolveSelectionInfo(e,{source:`event-path`,requireNumberColumn:!0});if(n==null)return;let{pre:r}=this;if(r==null)return;let{lineNumber:i,eventSide:a,lineIndex:o}=n;if(e.shiftKey&&this.selectedRange!=null){let t=this.getIndexesFromSelection(this.selectedRange,r.getAttribute(`data-diff-type`)===`split`);if(t==null)return;let n=t.start<=t.end?o>=t.start:o<=t.end;this.selectionAnchor={lineNumber:n?this.selectedRange.start:this.selectedRange.end,side:n?this.selectedRange.side:this.selectedRange.endSide??this.selectedRange.side},this.updateSelection(i,a,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.pointerSession={mode:`selecting`,pointerId:e.pointerId},this.attachDocumentPointerListeners();return}if(this.selectedRange?.start===i&&this.selectedRange?.end===i){let t={lineNumber:i,side:a};this.selectionAnchor=t,this.pointerSession={mode:`pendingSingleLineUnselect`,pointerId:e.pointerId,anchor:t,pending:t},this.attachDocumentPointerListeners();return}this.options.controlledSelection===!0?this.proposedSelectedRange=null:this.selectedRange=null,this.placeUtility(),this.selectionAnchor={lineNumber:i,side:a},this.updateSelection(i,a,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.pointerSession={mode:`selecting`,pointerId:e.pointerId},this.attachDocumentPointerListeners()}startGutterSelectionFromPointerDown(e){let{onGutterUtilityClick:t}=this.options;if(t==null)return;let n=this.currentSelectionEnds(),r=n?.bottom??this.resolveSelectionPoint(e,{source:`event-path`,excludeUtility:!1}),i=n?.top??r;r!=null&&i!=null&&(e.preventDefault(),e.stopPropagation(),this.pointerSession={mode:`gutterSelecting`,pointerId:e.pointerId,anchor:i,current:r},this.selectionAnchor={lineNumber:i.lineNumber,side:i.side},this.updateSelection(r.lineNumber,r.side,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.attachDocumentPointerListeners())}handleDocumentPointerMove=e=>{switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionPoint(e,{source:`coordinates-first`});if(t==null)return;this.pointerSession.current=t,this.updateSelection(t.lineNumber,t.side);return}case`selecting`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionInfo(e,{source:`coordinates-first`,requireNumberColumn:!1});if(t==null||this.selectionAnchor==null)return;this.updateSelection(t.lineNumber,t.eventSide);return}case`pendingSingleLineUnselect`:{if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault();let t=this.resolveSelectionInfo(e,{source:`coordinates-first`,requireNumberColumn:!1});if(t==null||this.selectionAnchor==null)return;let n={lineNumber:t.lineNumber,side:t.eventSide};if(ma(this.pointerSession.pending,n))return;this.updateSelection(t.lineNumber,t.eventSide,!1),this.notifySelectionStart(this.getCurrentSelectionRange()),this.notifySelectionChangeDelta(),this.pointerSession={mode:`selecting`,pointerId:e.pointerId};return}}};handleDocumentPointerUp=e=>{let{onGutterUtilityClick:t}=this.options;switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:{let{pointerSession:n}=this;if(e.pointerId!==n.pointerId)return;e.preventDefault();let r=this.resolveSelectionPoint(e,{source:`coordinates-first`});r!=null&&(n.current=r,this.updateSelection(r.lineNumber,r.side));let i=this.buildSelectedLineRange(n.anchor,n.current);t?.({...i}),this.selectionAnchor=void 0,this.notifySelectionEnd(i),this.notifySelectionCommitted(i),this.clearProposedSelection(),this.clearPointerSession(),this.detachDocumentPointerListeners();return}case`pendingSingleLineUnselect`:if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault(),this.updateSelection(null,void 0,!1),this.selectionAnchor=void 0,this.clearPendingSingleLineState(),this.detachDocumentPointerListeners(),this.notifySelectionEnd(this.getCurrentSelectionRange()),this.notifySelectionCommitted(this.getCurrentSelectionRange()),this.clearProposedSelection();return;case`selecting`:if(e.pointerId!==this.pointerSession.pointerId)return;e.preventDefault(),this.selectionAnchor=void 0,this.detachDocumentPointerListeners(),this.clearPointerSession(),this.notifySelectionEnd(this.getCurrentSelectionRange()),this.notifySelectionCommitted(this.getCurrentSelectionRange()),this.clearProposedSelection()}};handleDocumentPointerCancel=e=>{switch(this.pointerSession.mode){case`idle`:return;case`gutterSelecting`:case`selecting`:case`pendingSingleLineUnselect`:if(`pointerId`in this.pointerSession&&e.pointerId!==this.pointerSession.pointerId)return;this.selectionAnchor=void 0,this.clearProposedSelection(),this.clearPendingSingleLineState(),this.clearPointerSession(),this.detachDocumentPointerListeners()}};clearHoveredLine(){this.hoveredLine!=null&&(this.hoveredLine.lineElement.removeAttribute(`data-hovered`),this.hoveredLine.numberElement.removeAttribute(`data-hovered`),this.hoveredLine=void 0)}setHoveredLine(e){let{lineHoverHighlight:t=`disabled`}=this.options;this.hoveredLine!=null&&this.clearHoveredLine(),this.hoveredLine=e,t!==`disabled`&&((t===`both`||t===`line`)&&this.hoveredLine.lineElement.setAttribute(`data-hovered`,``),(t===`both`||t===`number`)&&this.hoveredLine.numberElement.setAttribute(`data-hovered`,``))}clearHoveredToken(){this.hoveredToken!=null&&(this.hoveredToken=void 0)}setHoveredToken(e){this.hoveredToken!=null&&this.clearHoveredToken(),this.hoveredToken=e}ensureGutterUtilityNode(e){if(this.gutterUtilityContainer??(this.gutterUtilityContainer=document.createElement(`div`),this.gutterUtilityContainer.setAttribute(`data-gutter-utility-slot`,``)),e)this.gutterUtilityButton!=null&&(this.gutterUtilityButton.remove(),this.gutterUtilityButton=void 0),this.gutterUtilitySlot??(this.gutterUtilitySlot=document.createElement(`slot`),this.gutterUtilitySlot.name=`gutter-utility-slot`),this.gutterUtilitySlot.parentNode!==this.gutterUtilityContainer&&this.gutterUtilityContainer.replaceChildren(this.gutterUtilitySlot);else{if(this.gutterUtilitySlot?.remove(),this.gutterUtilitySlot=void 0,this.gutterUtilityButton==null){let e=document.createElement(`div`);e.innerHTML=St(pa());let t=e.firstElementChild;if(!(t instanceof HTMLButtonElement))throw Error(`InteractionManager.ensureGutterUtilityNode: Node element should be a button`);t.remove(),this.gutterUtilityButton=t}this.gutterUtilityButton.parentNode!==this.gutterUtilityContainer&&this.gutterUtilityContainer.replaceChildren(this.gutterUtilityButton)}}revealUtilityFromGutterPath(e){if(this.placeUtilityFromSelection())return;let t=this.resolvePointerTarget(e);ya(t)&&t.numberColumn&&this.showUtilityOnLine(this.toEventBaseProps(t))}placeUtility(){if(!this.placeUtilityFromSelection()){if(this.hoveredLine!=null){this.showUtilityOnLine(this.hoveredLine);return}this.hideUtility()}}placeUtilityFromSelection(){let e=this.currentSelectionEnds();if(e==null)return!1;let t=this.targetForSelectionPoint(e.bottom);return t==null?this.hideUtility():this.showUtilityOnLine(this.toEventBaseProps(t)),!0}showUtilityOnLine(e){this.gutterUtilityContainer!=null&&(this.gutterUtilityLine=e,e.numberElement.appendChild(this.gutterUtilityContainer))}hideUtility(){this.gutterUtilityContainer?.remove(),this.gutterUtilityLine=void 0}currentSelectionEnds(){let e=this.getCurrentSelectionRange();return e==null?void 0:this.selectionEnds(e)}selectionEnds(e){let t={lineNumber:e.start,side:e.side},n={lineNumber:e.end,side:e.endSide??e.side},r=this.selectionPointRowIndex(t),i=this.selectionPointRowIndex(n);if(r!=null&&i!=null)return r>i?{top:n,bottom:t}:{top:t,bottom:n}}selectionPointRowIndex(e){let t=this.getLineIndex(e.lineNumber,e.side);if(t!=null)return this.isSplitDiff()?t[1]:t[0]}targetForSelectionPoint(e){if(this.pre==null)return;let t=this.getLineIndex(e.lineNumber,e.side);if(t==null)return;let n=this.mode===`diff`?`${t[0]},${t[1]}`:`${t[0]}`,r=this.pre.querySelectorAll(`[data-column-number="${e.lineNumber}"][data-line-index="${n}"]`);for(let t of r){if(!(t instanceof HTMLElement))continue;let n=this.resolvePointerTarget(Ea(t));if(ya(n)&&(this.mode!==`diff`||e.side==null||n.side===e.side))return n}}attachDocumentPointerListeners(){this.hasDocumentPointerListeners||=(document.addEventListener(`pointermove`,this.handleDocumentPointerMove),document.addEventListener(`pointerup`,this.handleDocumentPointerUp),document.addEventListener(`pointercancel`,this.handleDocumentPointerCancel),!0)}detachDocumentPointerListeners(){this.hasDocumentPointerListeners&&=(document.removeEventListener(`pointermove`,this.handleDocumentPointerMove),document.removeEventListener(`pointerup`,this.handleDocumentPointerUp),document.removeEventListener(`pointercancel`,this.handleDocumentPointerCancel),!1)}clearPointerSession(){this.pointerSession={mode:`idle`}}clearPendingSingleLineState(){this.pointerSession.mode===`pendingSingleLineUnselect`&&(this.pointerSession={mode:`idle`})}selectionInfoFromPath(e,t){let n=this.resolvePointerTarget(e);if(ya(n)&&!(t&&!n.numberColumn)&&n.splitLineIndex!=null)return{lineIndex:n.splitLineIndex,lineNumber:n.lineNumber,eventSide:this.mode===`diff`?n.side:void 0}}resolveSelectionInfo(e,t){let n=this.resolveSelectionPath(e,t);return n==null?void 0:this.selectionInfoFromPath(n,t.requireNumberColumn)}selectionPointFromPath(e){let t=this.resolvePointerTarget(e);if(ya(t))return{lineNumber:t.lineNumber,side:this.mode===`diff`?t.side:void 0}}resolveSelectionPoint(e,t){let n=this.resolveSelectionPath(e,t);return n==null?void 0:this.selectionPointFromPath(n)}resolveSelectionPath(e,t){let n=t.excludeUtility!==!1;switch(t.source){case`event-path`:return this.pathFromEventPath(e.composedPath(),n);case`coordinates-first`:{let t=this.pathFromCoordinates(e,n);return t===void 0?this.pathFromEventPath(e.composedPath(),n):t??void 0}}}pathFromCoordinates(e,t){let n=this.hitTest(e);if(n!==void 0)return n===null?null:this.pathFromElement(n,t)??null}pathFromEventPath(e,t){if(!(t&&ha(e))){for(let n of e)if(n instanceof Element)return this.pathFromElement(n,t)}}pathFromElement(e,t){let n=Ea(e);if(t&&ha(n))return;let r=Da(e);return r==null?this.pathFromAnnotationSlot(e):Ea(r)}pathFromAnnotationSlot(e){let t=ka(Oa(e));if(t==null)return;let n=this.targetForSelectionPoint(t);return n==null?void 0:Ea(n.lineElement)}hitTest(e){if(!Number.isFinite(e.clientX)||!Number.isFinite(e.clientY))return;let t=this.pre?.getRootNode(),n=Aa(t)?t:Aa(document)?document:void 0;if(n!=null)return n.elementFromPoint(e.clientX,e.clientY)}getLineIndex(e,t){let{getLineIndex:n}=this.options;return n==null?[e-1,e-1]:n(e,t)}getCurrentSelectionRange(){return this.proposedSelectedRange===void 0?this.selectedRange:this.proposedSelectedRange}clearProposedSelection(){this.proposedSelectedRange=void 0}updateSelection(e,t,n=!0){let r=this.getCurrentSelectionRange(),i;if(e==null)i=null;else{let n=this.selectionAnchor?.side??t,r=this.selectionAnchor?.lineNumber??e;i=this.buildSelectionRange(r,e,n,t)}xi(r??void 0,i??void 0)||(this.selectedRangeHighlightSide=void 0,this.selectedRangeLineNumberOnly=!1,this.options.controlledSelection===!0?this.proposedSelectedRange=i:(this.selectedRange=i,hi(this.renderSelection)),this.placeUtility(),n&&this.notifySelectionChangeDelta())}getIndexesFromSelection(e,t){if(this.pre==null)return;let n=this.getLineIndex(e.start,e.side),r=this.getLineIndex(e.end,e.endSide??e.side);return n!=null&&r!=null?{start:t?n[1]:n[0],end:t?r[1]:r[0]}:void 0}getSelectionRenderState(){return{selectedLines:{range:this.selectedRange,highlightSide:this.selectedRangeHighlightSide,lineNumberOnly:this.selectedRangeLineNumberOnly},editorActiveLine:{range:this.editorActiveLine==null?null:{start:this.editorActiveLine,end:this.editorActiveLine,side:this.editorActiveLineSide},highlightSide:this.editorActiveLineSide,lineNumberOnly:this.editorLineNumberOnly}}}resolveLineRenderRange(e,t,n){if(e.range==null)return;let r=this.getIndexesFromSelection(e.range,t);if(r==null)throw console.error({rowRange:r,range:e.range}),Error(`InteractionManager.renderSelection: No valid ${n} rowRange`);return r}getLineRenderColumns(e,t,n,r){if(this.pre==null||t==null&&r==null)return[];let{children:i}=this.pre;if(i.length>2)throw console.error(i),Error(`InteractionManager.renderSelection: Somehow there are more than 2 code elements...`);let a=[];for(let o of i){let i=o.hasAttribute(`data-deletions`)?`deletions`:o.hasAttribute(`data-additions`)?`additions`:void 0,s=e!=null&&t!=null&&(e.highlightSide==null||i==null||e.highlightSide===i),c=n!=null&&r!=null&&(n.highlightSide==null||i==null||n.highlightSide===i);if(!s&&!c)continue;let[l,u]=o.children;if(!(l instanceof HTMLElement)||!(u instanceof HTMLElement))throw Error(`InteractionManager.renderSelection: missing gutter or content element`);if(u.children.length!==l.children.length)throw Error(`InteractionManager.renderSelection: gutter and content children dont match, something is wrong`);a.push({content:u,gutter:l,renderEditorActiveLine:c,renderSelectedLines:s})}return a}renderSelection=()=>{gi(this.renderSelection);let e=this.getSelectionRenderState();if(this.pre==null)return;let{editorActiveLine:t,selectedLines:n}=e,r=!Ma(this.renderedSelectedLinesState,n),i=!Ma(this.renderedEditorActiveLineState,t);if(!r&&!i)return;r&&(this.renderedSelectedLinesState=void 0),i&&(this.renderedEditorActiveLineState=void 0);let a=this.pre.getAttribute(`data-diff-type`)===`split`,o=r?this.resolveLineRenderRange(n,a,`selected-lines`):void 0,s=i?this.resolveLineRenderRange(t,a,`editor-active-line`):void 0,c=this.getLineRenderColumns(r?n:void 0,o,i?t:void 0,s),l=n.range==null||c.some(e=>e.renderSelectedLines),u=t.range==null||c.some(e=>e.renderEditorActiveLine);if(r)for(let e of this.pre.querySelectorAll(`[data-selected-line]`))e.removeAttribute(`data-selected-line`);if(i)for(let e of this.pre.querySelectorAll(`[data-editor-active-line]`))e.removeAttribute(`data-editor-active-line`);let d=o==null?void 0:Math.min(o.start,o.end),f=o==null?void 0:Math.max(o.start,o.end),p=d===f,m=s?.start;for(let e of c){let{content:r,gutter:i,renderEditorActiveLine:o,renderSelectedLines:s}=e,c=Math.max(s?f??-1/0:-1/0,o?m??-1/0:-1/0),l=r.children.length;for(let e=0;e<l;e++){let l=r.children[e],u=i.children[e];if(!(l instanceof HTMLElement)||!(u instanceof HTMLElement))continue;let h=this.parseLineIndex(l,a);if((h??0)>c)break;if(h!=null){if(s&&d!=null&&f!=null&&h>=d&&h<=f){let e=p?`single`:h===d?`first`:h===f?`last`:``;u.setAttribute(`data-selected-line`,e),n.lineNumberOnly||(l.setAttribute(`data-selected-line`,e),u.nextSibling instanceof HTMLElement&&l.nextSibling instanceof HTMLElement&&(l.nextSibling.hasAttribute(`data-line-annotation`)||l.nextSibling.hasAttribute(`data-merge-conflict-actions`))&&(p?(e=`last`,l.setAttribute(`data-selected-line`,`first`)):h===d?e=``:h===f&&l.setAttribute(`data-selected-line`,``),l.nextSibling.setAttribute(`data-selected-line`,e),u.nextSibling.setAttribute(`data-selected-line`,e)))}o&&h===m&&(u.setAttribute(`data-editor-active-line`,``),t.lineNumberOnly||l.setAttribute(`data-editor-active-line`,``))}}}r&&l&&(this.renderedSelectedLinesState=n),i&&u&&(this.renderedEditorActiveLineState=t)};notifySelectionCommitted(e){this.options.onLineSelected?.(e)}notifySelectionChangeDelta(){this.options.onLineSelectionChange?.(this.getCurrentSelectionRange()??null)}notifySelectionStart(e){this.options.onLineSelectionStart?.(e)}notifySelectionEnd(e){this.options.onLineSelectionEnd?.(e)}toEventBaseProps(e){return this.mode===`file`?{type:`line`,lineElement:e.lineElement,lineNumber:e.lineNumber,numberColumn:e.numberColumn,numberElement:e.numberElement}:{type:`diff-line`,annotationSide:e.side,lineType:e.lineType,lineElement:e.lineElement,numberElement:e.numberElement,lineNumber:e.lineNumber,numberColumn:e.numberColumn}}toTokenEventBaseProps({lineCharEnd:e,lineCharStart:t,lineNumber:n,side:r,tokenElement:i,tokenText:a}){return this.mode===`file`?{type:`token`,lineCharEnd:e,lineCharStart:t,lineNumber:n,tokenElement:i,tokenText:a}:{type:`token`,lineCharEnd:e,lineCharStart:t,lineNumber:n,side:r,tokenElement:i,tokenText:a}}buildSelectedLineRange(e,t){return this.buildSelectionRange(e.lineNumber,t.lineNumber,e.side,t.side)}buildSelectionRange(e,t,n,r){return{start:e,end:t,...n==null?{}:{side:n},...n!==r&&r!=null?{endSide:r}:{}}}resolvePointerTarget(e){let t=!1,n,r,i,a,o,s,c,l,u,d;for(let f of e){if(!(f instanceof HTMLElement))continue;if(d==null&&f.hasAttribute(`data-merge-conflict-action`)){let e=f.getAttribute(`data-merge-conflict-action`)??void 0,t=f.getAttribute(`data-merge-conflict-conflict-index`)??void 0,n=t==null?NaN:Number.parseInt(t,10);wa(e)&&Number.isFinite(n)&&(d={kind:`merge-conflict-action`,resolution:e,conflictIndex:n})}if(s==null&&f.hasAttribute(`data-char`)){s=f;let e=f.getAttribute(`data-char`);if(e!=null){let t=Number.parseInt(e,10);if(!Number.isNaN(t)){let e=f.textContent??``,n=t+e.length;(e.trim()!==``||this.options.enableTokenInteractionsOnWhitespace===!0)&&(c={tokenElement:s,lineCharStart:t,lineCharEnd:n,tokenText:e});continue}}}let e=o==null?f.getAttribute(`data-column-number`)??void 0:void 0;if(e!=null){o=f,u=Number.parseInt(e,10),t=!0,n=Pa(f),a=f.getAttribute(`data-line-index`)??void 0;continue}let p=i==null?f.getAttribute(`data-line`)??void 0:void 0;if(p!=null){i=f,u=Number.parseInt(p,10),n=Pa(f),a=f.getAttribute(`data-line-index`)??void 0;continue}if(l==null&&(f.hasAttribute(`data-expand-button`)||f.hasAttribute(`data-unmodified-lines`))){l={hunkIndex:void 0,direction:f.hasAttribute(`data-expand-up`)?`up`:f.hasAttribute(`data-expand-down`)?`down`:`both`,all:f.hasAttribute(`data-expand-all-button`)};continue}let m=l==null?void 0:f.getAttribute(`data-expand-index`)??void 0;if(l!=null&&m!=null){let e=Number.parseInt(m,10);Number.isNaN(e)||(l.hunkIndex=e);continue}if(r==null&&f.hasAttribute(`data-code`)){r=f;break}}if(d!=null)return d;if(l?.hunkIndex!=null)return{type:`line-info`,hunkIndex:l.hunkIndex,direction:l.direction,all:l.all};if(i??=a==null?void 0:Ta(r,`[data-line][data-line-index="${a}"]`),o??=a==null?void 0:Ta(r,`[data-column-number][data-line-index="${a}"]`),r==null||i==null||o==null||n==null||u==null||Number.isNaN(u))return;let f=this.parseLineIndex(i,this.isSplitDiff());return c==null?this.mode===`file`?{kind:`line`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:void 0,splitLineIndex:f}:{kind:`line`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:Na(n,r),splitLineIndex:f}:this.mode===`file`?{kind:`token`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:void 0,splitLineIndex:f,...c}:{kind:`token`,lineType:n,lineElement:i,lineNumber:u,numberColumn:t,numberElement:o,side:Na(n,r),splitLineIndex:f,...c}}isSplitDiff(){return this.pre?.getAttribute(`data-diff-type`)===`split`}parseLineIndex(e,t){let n=(e.getAttribute(`data-line-index`)??``).split(`,`).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e));if(t&&n.length===2)return n[1];if(!t)return n[0]}};function _a({enableTokenInteractionsOnWhitespace:e,enableGutterUtility:t,lineHoverHighlight:n,onGutterUtilityClick:r,onLineClick:i,onLineEnter:a,onLineLeave:o,onLineNumberClick:s,onTokenClick:c,onTokenEnter:l,onTokenLeave:u,renderGutterUtility:d,__debugPointerEvents:f,enableLineSelection:p,controlledSelection:m,onLineSelected:h,onLineSelectionStart:g,onLineSelectionChange:_,onLineSelectionEnd:v},y,b,x){return{enableTokenInteractionsOnWhitespace:e,enableGutterUtility:va({enableGutterUtility:t,renderGutterUtility:d,onGutterUtilityClick:r}),usesCustomGutterUtility:d!=null,lineHoverHighlight:n,onGutterUtilityClick:r,onHunkExpand:y,onMergeConflictActionClick:x,onLineClick:i,onLineEnter:a,onLineLeave:o,onLineNumberClick:s,onTokenClick:c,onTokenEnter:l,onTokenLeave:u,__debugPointerEvents:f,enableLineSelection:p,controlledSelection:m,onLineSelected:h,onLineSelectionStart:g,onLineSelectionChange:_,onLineSelectionEnd:v,getLineIndex:b}}function va({enableGutterUtility:e,renderGutterUtility:t,onGutterUtilityClick:n}){if(n!=null&&t!=null)throw Error(`Cannot use both 'onGutterUtilityClick' and 'renderGutterUtility'. Use only one gutter utility API.`);return e??!1}function ya(e){return e!=null&&`kind`in e&&e.kind===`line`}function ba(e){return e!=null&&`kind`in e&&e.kind===`token`}function xa(e){return ya(e)||ba(e)}function Sa(e){return`type`in e&&e.type===`line-info`}function Ca(e){return`kind`in e&&e.kind===`merge-conflict-action`}function wa(e){return e===`current`||e===`incoming`||e===`both`}function Ta(e,t){let n=e?.querySelector(t);return n instanceof HTMLElement?n:void 0}function Ea(e){let t=[],n=e;for(;n!=null;)t.push(n),n=n.parentNode;return t}function Da(e){let t=e.closest(`[data-line], [data-column-number]`);if(t instanceof HTMLElement)return t;let n=e.closest(`[data-line-annotation], [data-gutter-buffer="annotation"]`);if(!(n instanceof HTMLElement))return;let r=n.previousElementSibling;return r instanceof HTMLElement&&(r.hasAttribute(`data-line`)||r.hasAttribute(`data-column-number`))?r:void 0}function Oa(e){let t=e.closest(`[slot^="annotation-"]`);if(t instanceof HTMLElement)return t.getAttribute(`slot`)??void 0;if(e instanceof HTMLElement){let t=e.getAttribute(`name`)??void 0;return t!=null&&t.startsWith(`annotation-`)?t:void 0}}function ka(e){if(e==null)return;let t=/^annotation-(?:(additions|deletions)-)?(\d+)$/.exec(e);if(t==null)return;let n=Number.parseInt(t[2],10);if(!(!Number.isFinite(n)||n<=0))return{lineNumber:n,side:t[1]}}function Aa(e){return e!=null&&typeof e.elementFromPoint==`function`}function ja(e,t){return e===t||xi(e??void 0,t??void 0)}function Ma(e,t){return e?.highlightSide===t.highlightSide&&e?.lineNumberOnly===t.lineNumberOnly&&ja(e?.range??null,t.range)}function Na(e,t){switch(e){case`change-deletion`:return`deletions`;case`change-addition`:return`additions`;default:return t.hasAttribute(`data-deletions`)?`deletions`:`additions`}}function Pa(e){let t=e.getAttribute(`data-line-type`);if(t!=null)switch(t){case`change-deletion`:case`change-addition`:case`context`:case`context-expanded`:return t;default:return}}function Fa(e=`none`,t,...n){switch(e){case`none`:return;case`both`:break;case`click`:if(t!==`click`)return;break;case`move`:if(t!==`move`)return}console.log(...n)}var Ia=class e{static resizeObserver;static managersByElement=new Map;static getResizeObserver(){let t=e.resizeObserver??new ResizeObserver(e.handleSharedResizeEntries);return e.resizeObserver=t,t}static handleSharedResizeEntries(t){let n=new Map;for(let r of t){let t=e.managersByElement.get(r.target);if(t==null)continue;let i=n.get(t);i==null?n.set(t,[r]):i.push(r)}for(let[e,t]of n)e.handleResizeEntries(t)}observedNodes=new Map;setup(e,{disableAnnotations:t,columnVariables:n=`apply`}){let r=new Set,i=n===`apply`,a=0,o=new Map(this.observedNodes);this.observedNodes.clear();for(let t of e.children){if(a===2)break;let e=(()=>{if(t instanceof HTMLElement&&t.tagName===`CODE`)return t})();if(e==null)continue;a++;let n=o.get(e);if(n!=null&&n.type!==`code`)throw Error(`ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible`);let r=e.firstElementChild;r instanceof HTMLElement||(r=null),n==null?(n={type:`code`,codeElement:e,numberElement:r,codeWidth:`auto`,numberWidth:0,applyColumnVariables:i},this.observedNodes.set(e,n),this.observe(e),r!=null&&(this.observedNodes.set(r,n),this.observe(r))):(this.observedNodes.set(e,n),o.delete(e),n.numberElement===r?n.numberElement==null?n.numberWidth=0:(o.delete(n.numberElement),this.observedNodes.set(n.numberElement,n)):(n.numberElement!=null&&(this.unobserve(n.numberElement),o.delete(n.numberElement)),r!=null&&(this.observe(r),o.delete(r),this.observedNodes.set(r,n)),n.numberElement=r,n.numberWidth=0),za(n,i))}if(a>1&&!t){let t=e.querySelectorAll(`[data-line-annotation*=","]`),n=new Map;for(let e of t){if(!(e instanceof HTMLElement))continue;let t=e.getAttribute(`data-line-annotation`)??``;if(!/^-?\d+,-?\d+$/.test(t)){console.error(`DiffFileRenderer.setupResizeObserver: Invalid element or annotation`,{lineAnnotation:t,element:e});continue}let r=n.get(t);r??(r=[],n.set(t,r)),r.push(e)}for(let[e,t]of n){if(t.length!==2){console.error(`DiffFileRenderer.setupResizeObserver: Bad Pair`,e,t);continue}let[n,i]=t,a=n.firstElementChild,s=i.firstElementChild;if(!(n instanceof HTMLElement)||!(i instanceof HTMLElement)||!(a instanceof HTMLElement)||!(s instanceof HTMLElement))continue;let c=o.get(a);if(c!=null){this.observedNodes.set(a,c),this.observedNodes.set(s,c),o.delete(a),o.delete(s);continue}let l=a.getBoundingClientRect().height,u=s.getBoundingClientRect().height;c={type:`annotations`,column1:{container:n,child:a,childHeight:l},column2:{container:i,child:s,childHeight:u},currentHeight:`auto`},r.add({child1:a,child2:s,item:c,newHeight:Math.max(l,u)})}for(let e of r)this.applyNewHeight(e.item,e.newHeight),this.observedNodes.set(e.child1,e.item),this.observedNodes.set(e.child2,e.item),this.observe(e.child1),this.observe(e.child2);r.clear()}for(let[e,t]of o)this.unobserve(e),t.type===`code`?Ha(t):Ua(t);o.clear()}cleanUp(){for(let e of this.observedNodes.keys())this.unobserve(e);this.observedNodes.clear()}observe(t){let{managersByElement:n}=e,r=n.get(t);if(r!==this){if(r!=null&&r!==this)throw Error(`ResizeManager.observe: element is already owned by another ResizeManager`);n.set(t,this),e.getResizeObserver().observe(t)}}unobserve(t){let{managersByElement:n,resizeObserver:r}=e,i=n.get(t);if(i!=null){if(i!==this)throw Error(`ResizeManager.unobserve: element is owned by another ResizeManager`);n.delete(t),r?.unobserve(t),r!=null&&n.size===0&&(r.disconnect(),e.resizeObserver=void 0)}}handleResizeEntries(e){let t=new Map,n=new Set;for(let r of e){let{target:e,borderBoxSize:i,contentBoxSize:a}=r;if(!(e instanceof HTMLElement)){console.error(`ResizeManager.handleResizeEntries: Invalid element for ResizeObserver`,r);continue}let o=this.observedNodes.get(e);if(o==null){console.error(`ResizeManager.handleResizeEntries: Not a valid observed node`,r);continue}if(o.type===`annotations`){let t=(()=>{if(e===o.column1.child)return o.column1;if(e===o.column2.child)return o.column2})();if(t==null){console.error(`ResizeManager.handleResizeEntries: Couldn't find a column for`,{item:o,target:e});continue}t.childHeight=i[0].blockSize,n.add(o)}else if(o.type===`code`){let n=t.get(o)??{},r=a[0].inlineSize;e===o.codeElement?n.codeInlineSize=r:e===o.numberElement&&(n.numberInlineSize=r),t.set(o,n)}}this.applyAnnotationUpdates(n),n.clear(),this.applyColumnUpdates(t),t.clear()}applyAnnotationUpdates(e){for(let t of e)this.applyNewHeight(t,Math.max(t.column1.childHeight,t.column2.childHeight))}applyColumnUpdates=e=>{for(let[t,n]of e){let e=n.codeInlineSize==null?t.codeWidth:La(n.codeInlineSize),r=n.numberInlineSize==null?t.numberWidth:Ra(n.numberInlineSize),i=e!==t.codeWidth,a=r!==t.numberWidth;!i&&!a||(t.codeWidth=e,t.numberWidth=r,t.applyColumnVariables&&Ba(t,{codeWidthChanged:i,numberWidthChanged:a}))}};applyNewHeight(e,t){t!==e.currentHeight&&(e.currentHeight=Math.max(t,0),e.column1.container.style.setProperty(`--diffs-annotation-min-height`,`${e.currentHeight}px`),e.column2.container.style.setProperty(`--diffs-annotation-min-height`,`${e.currentHeight}px`))}};function La(e){let t=Math.max(Math.floor(e),0);return t===0?`auto`:t}function Ra(e){return Math.max(Math.ceil(e),0)}function za(e,t){e.applyColumnVariables!==t&&(e.applyColumnVariables=t,t?Ba(e,{codeWidthChanged:!0,numberWidthChanged:!0}):Va(e))}function Ba(e,{codeWidthChanged:t,numberWidthChanged:n}){let{codeElement:r,codeWidth:i,numberWidth:a}=e;if(t&&r.style.setProperty(`--diffs-column-width`,`${typeof i==`number`?`${i}px`:`auto`}`),n&&r.style.setProperty(`--diffs-column-number-width`,`${a===0?`auto`:`${a}px`}`),t||n&&i!==`auto`){let e=typeof i==`number`?Math.max(i-a,0):0;r.style.setProperty(`--diffs-column-content-width`,`${e>0?`${e}px`:`auto`}`)}}function Va(e){e.codeElement.style.removeProperty(`--diffs-column-content-width`),e.codeElement.style.removeProperty(`--diffs-column-number-width`),e.codeElement.style.removeProperty(`--diffs-column-width`)}function Ha(e){e.codeElement.isConnected&&Va(e)}function Ua(e){e.column1.container.isConnected&&e.column1.container.style.removeProperty(`--diffs-annotation-min-height`),e.column2.container.isConnected&&e.column2.container.style.removeProperty(`--diffs-annotation-min-height`)}function Wa(e){for(let t of Array.isArray(e)?e:[e])if(t!==`text`&&t!==`ansi`&&!Nt.has(t))return!1;return!0}function Ga(e){for(let t of un(e))if(!Zt.has(t))return!1;return!0}function Ka(e,t){return e==null||t==null?e===t:e.startingLine===t.startingLine&&e.totalLines===t.totalLines&&e.bufferBefore===t.bufferBefore&&e.bufferAfter===t.bufferAfter}function qa(e){return K({tagName:`div`,children:[K({tagName:`div`,children:e.annotations?.map(e=>K({tagName:`slot`,properties:{name:e}})),properties:{"data-annotation-content":``}})],properties:{"data-line-annotation":`${e.hunkIndex},${e.lineIndex}`}})}function Ja(e){switch(e){case`file`:return`diffs-icon-file-code`;case`change`:return`diffs-icon-symbol-modified`;case`new`:return`diffs-icon-symbol-added`;case`deleted`:return`diffs-icon-symbol-deleted`;case`rename-pure`:case`rename-changed`:return`diffs-icon-symbol-moved`}}function Ya({fileOrDiff:e,mode:t,stickyHeader:n}){let r=`type`in e?e:void 0,i={"data-diffs-header":t,"data-change-type":r?.type,"data-sticky":n?``:void 0};return K({tagName:`div`,children:[t===`custom`?K({tagName:`slot`,properties:{name:$e}}):Xa({name:e.name,prevName:`prevName`in e?e.prevName:void 0,iconType:r?.type??`file`}),...t===`custom`?[]:[Za(r)]],properties:i})}function Xa({name:e,prevName:t,iconType:n}){let r=[K({tagName:`slot`,properties:{name:$t}}),ct({name:Ja(n),properties:{"data-change-icon":n}})];return t!=null&&(r.push(K({tagName:`div`,children:[K({tagName:`bdi`,children:[Ie(t)]})],properties:{"data-prev-name":``}})),r.push(ct({name:`diffs-icon-arrow-right-short`,properties:{"data-rename-icon":``}}))),r.push(K({tagName:`div`,children:[K({tagName:`bdi`,children:[Ie(e)]})],properties:{"data-title":``}})),r.push(K({tagName:`slot`,properties:{name:Ve}})),K({tagName:`div`,children:r,properties:{"data-header-content":``}})}function Za(e){let t=[];if(e!=null){let n=0,r=0;for(let t of e.hunks)n+=t.additionLines,r+=t.deletionLines;(r>0||n===0)&&t.push(K({tagName:`span`,children:[Ie(`-${r}`)],properties:{"data-deletions-count":``}})),(n>0||r===0)&&t.push(K({tagName:`span`,children:[Ie(`+${n}`)],properties:{"data-additions-count":``}}))}return t.push(K({tagName:`slot`,properties:{name:Ye}})),K({tagName:`div`,children:t,properties:{"data-metadata":``}})}function Qa(e){return K({tagName:`pre`,properties:$a(e)})}function $a({diffIndicators:e,disableBackground:t,disableLineNumbers:n,overflow:r,split:i,totalLines:a,type:o,customProperties:s}){return{...s,"data-diff":o===`diff`?``:void 0,"data-file":o===`file`?``:void 0,"data-diff-type":o===`diff`?i?`split`:`single`:void 0,"data-overflow":r,"data-disable-line-numbers":n?``:void 0,"data-background":t?void 0:``,"data-indicators":e===`bars`||e===`classic`?e:void 0,style:`--diffs-min-number-column-width-default:${`${a}`.length}ch;`}}function eo(e,{theme:t,preferredHighlighter:n=`shiki-js`}){return{langs:[e??`text`],themes:un(t),preferredHighlighter:n}}function to(e){return`annotation-${`side`in e?`${e.side}-`:``}${e.lineNumber}`}var no={compositeOverBg:at,contrastRatio:U,deriveMutedFg:At,hoverWouldEraseText:cn,isDarkSurface:Jt,isFullyTransparent:nn,pickReadableForeground:Lt,relativeLuminance:Ct,surfacesMatch:Yt},ro=`-1,-1`;function io(e){return e?.some(e=>e.lineNumber===0)??!1}function ao(e){let t=e[0];return t!=null&&t.length>0?t:void 0}function oo(e){return e.startingLine===0&&e.totalLines>0}function so(e,t){return e.endsWith(`\r
14
14
  `)?t+`\r
15
15
  `:e.endsWith(`\r`)?t+`\r`:e.endsWith(`
16
16
  `)?t+`
17
- `:t}function co(e,t){return q({tagName:`div`,children:e,properties:{"data-content":``,style:`grid-row: span ${t}`}})}function lo(e,t){return t.cacheKey==null?e.file===t&&e.sourceContents===t.contents:e.cacheKey===t.cacheKey}var uo=-1,fo=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++uo}`;highlighter;renderCache;computedLang=`text`;lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;constructor(e={theme:K},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=Ga(e.theme??K)?kt():void 0)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}setLineAnnotations(e){this.lineAnnotations={};for(let t of e){let e=this.lineAnnotations[t.lineNumber]??[];this.lineAnnotations[t.lineNumber]=e,e.push(t)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(){this.editSessionActive=!0}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0,this.endEditSession(),this.textDocumentCache=new WeakMap}syncEditedContentsToFile(){let{renderCache:e,lineCache:t}=this;e?.isDirty!==!0||t==null||!lo(t,e.file)||(e.file.contents=t.lines.join(``))}hasUnkeyedFileContentsChanged(e){let{lineCache:t}=this;return e.cacheKey==null&&t!=null&&t.file===e&&t.sourceContents!==e.contents}invalidateChangedUnkeyedFile(e){this.hasUnkeyedFileContentsChanged(e)&&(this.workerManager?.cleanUpTasks(this),this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap)}clearRenderCache(){this.syncEditedContentsToFile(),this.pendingStructuralRows=void 0;let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(e.file.cacheKey)}hydrate(e){let{options:t}=this.getRenderOptions(e),n=po(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength()),r=this.workerManager?.getFileResultCache(e);r!=null&&!Dt(t,r.options)&&(r=void 0),this.renderCache??={file:e,options:t,highlighted:!n&&!$t(e),result:n?void 0:r?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightFileAST(this,e):this.highlighter??(this.computedLang=e.lang??on(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??K}getEffectiveCodeOptions(){let e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0){let e=this.workerManager.getFileRenderOptions();return this.editSessionActive&&e.useTokenTransformer!==!0?{...e,useTokenTransformer:!0}:e}let{tokenizeMaxLineLength:e=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:e}})(),{renderCache:n}=this;return n?.result==null||!pn(e,n.file)||!Dt(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getOrCreateLineCache(e){this.invalidateChangedUnkeyedFile(e);let{lineCache:t}=this;return(t==null||!lo(t,e))&&(t={cacheKey:e.cacheKey,file:e,sourceContents:e.contents,lines:xt(e.contents)}),this.lineCache=t,t.lines}getLineCount(e){let t=this.getOrCreateLineCache(e);return this.textDocumentCache.get(e)?.lineCount??t.length}updateRenderCache(e,t,n=!1){if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:r,result:i}=this.renderCache;if(i==null)return;let a=n?new Map:void 0;this.pendingStructuralRows=a;let o=this.lineCache!=null&&lo(this.lineCache,r)?this.lineCache:void 0;for(let[t,n]of e){if(a===void 0&&o!=null&&t<o.lines.length){let e=n.map(e=>e[2]).join(``);o.lines[t]=so(o.lines[t]??``,e)}let e={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:n.map(([e,t,n])=>e===0&&t===``?n===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:n}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`color:${t};`},children:[{type:`text`,value:n}]})};a===void 0?i.code[t]=e:a.set(t,e)}i.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){let t=this.pendingStructuralRows;if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:n,result:r}=this.renderCache;if(r==null)return;let i=this.lineCache!=null&&lo(this.lineCache,n)?this.lineCache.lines:xt(n.contents),a=xt(e.getText());if(i.length!==a.length){let n=Math.min(i.length,a.length),o=0;for(;o<n&&i[o]===a[o];)o++;let s=0;for(;s<n-o&&i[i.length-1-s]===a[a.length-1-s];)s++;let c=r.code;r.code=Array(a.length);for(let e=0;e<o;e++)r.code[e]=c[e];for(let e=0;e<s;e++)r.code[a.length-1-e]=c[i.length-1-e];if(t!==void 0)for(let[e,n]of t)e<a.length&&(r.code[e]=n);for(let t=o;t<a.length-s;t++)r.code[t]??={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:e.getLineText(t)}]}]};for(let e=0;e<r.code.length;e++){let t=r.code[e];t?.type===`element`&&(t.properties[`data-line`]=e+1,t.properties[`data-line-index`]=e)}this.renderCache.isDirty=!0}this.lineCache={cacheKey:n.cacheKey,file:n,sourceContents:n.contents,lines:a},this.textDocumentCache.set(n,e)}renderFile(e=this.renderCache?.file,t=it){if(e==null)return;this.invalidateChangedUnkeyedFile(e),this.renderCache?.isDirty===!0&&!pn(e,this.renderCache.file)&&(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap);let{options:n,forceHighlight:r}=this.getRenderOptions(e);this.renderCache?.isDirty===!0&&!Dt(n,this.renderCache.options)&&this.clearRenderCache();let i=this.getMatchingWorkerResultCache(e,n);i!=null&&!this.hasHighlightedRenderCache(e,n)&&(this.renderCache={file:e,highlighted:!0,renderRange:void 0,...i},r=!1),this.renderCache??={file:e,highlighted:!1,options:n,result:void 0,renderRange:void 0};let a=this.getOrCreateLineCache(e),o=e.contents.length>0,s=!o||$t(e)||po(a.length,this.getTokenizeMaxLength()),c=!pn(e,this.renderCache.file),l=!Ka(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0)(s||this.renderCache.result==null||!this.renderCache.highlighted&&(c||l))&&(this.renderCache.file=e,this.renderCache.options=n,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||l||r)&&(this.renderCache.result=this.workerManager.getPlainFileAST(e,t.startingLine,t.totalLines,a)),this.renderCache.renderRange=t),!s&&o&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightFileAST(this,e);else{this.computedLang=e.lang??on(e.name);let t=this.highlighter!=null&&Ga(n.theme),i=this.highlighter!=null&&Wa(this.computedLang),a=!s&&i;if(this.highlighter!=null&&t&&(r||s||!this.renderCache.highlighted&&a||this.renderCache.result==null)){let{result:t,options:n}=this.renderFileWithHighlighter(e,this.highlighter,s||!i);this.renderCache={file:e,options:n,highlighted:a,result:t,renderRange:void 0}}(!t||!s&&!i)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,t,n,!s)})}return this.renderCache.result==null?void 0:this.processFileResult(this.renderCache.file,t,this.renderCache.result)}async asyncRender(e,t=it){let{result:n}=await this.asyncHighlight(e);return this.processFileResult(e,t,n)}async asyncHighlight(e){let t=po(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??on(e.name);let n=this.highlighter!=null&&Wt(dn(this.getLocalHighlightTheme())),r=t||this.highlighter!=null&&Wa(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(e,this.highlighter,t)}renderFileWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e);return{result:Ke(e,t,r,{forcePlainText:n}),options:r}}processFileResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let a=this.getLineCount(e),{disableFileHeader:o=!1}=this.options,s=[],c=Tt(),l=Math.min(t.startingLine+t.totalLines,a),u=0,d=oo(t)?ao(this.lineAnnotations):void 0;d!=null&&(c.children.push(fn(`context`,`annotation`,1)),s.push(qa({type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:d.map(e=>to(e))})),u++);for(let r=t.startingLine;r<l;r++){let t=r+1,i=n[r];if(i==null){let n=`FileRenderer.processFileResult: Line doesnt exist`;throw console.error(n,{name:e.name,lineIndex:r,lineNumber:t}),Error(n)}c.children.push(mn(`context`,t,`${r}`)),s.push(i),u++;let a=this.lineAnnotations[t];a!=null&&(c.children.push(fn(`context`,`annotation`,1)),s.push(qa({type:`annotation`,hunkIndex:0,lineIndex:t,annotations:a.map(e=>to(e))})),u++)}return c.properties.style=`grid-row: span ${u}`,{gutterAST:c.children??[],contentAST:s,preAST:this.createPreElement(a),headerAST:o?void 0:this.renderHeader(e),totalLines:a,rowCount:u,themeStyles:r,baseThemeType:i,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderHeader(e){let{headerRenderMode:t=`default`,stickyHeader:n=!1}=this.options;return Ya({fileOrDiff:e,mode:t,stickyHeader:n})}renderFullHTML(e){return Ct(this.renderFullAST(e))}renderFullAST(e,t=[]){return t.push(q({tagName:`code`,children:this.renderCodeAST(e),properties:{"data-code":``}})),{...e.preAST,children:t}}renderCodeAST(e){let t=Tt();return t.children=e.gutterAST,t.properties.style=`grid-row: span ${e.rowCount}`,[t,co(e.contentAST,e.rowCount)]}renderPartialHTML(e,t=!1){return Ct(t?q({tagName:`code`,children:e,properties:{"data-code":``}}):e)}async initializeHighlighter(){return this.highlighter=await Mt(eo(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(e,t,n,r=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,r)}applyHighlightResult(e,t,n,r=!0){if(this.renderCache==null)return;let i=!pn(e,this.renderCache.file)||!this.renderCache.highlighted||!Dt(n,this.renderCache.options);this.renderCache={file:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;let n=this.workerManager?.getFileResultCache(e);if(!(n==null||!Dt(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&pn(e,n.file)&&Dt(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(e){let{disableLineNumbers:t=!1,overflow:n=`scroll`}=this.options;return Qa({type:`file`,diffIndicators:`none`,disableBackground:!0,disableLineNumbers:t,overflow:n,split:!1,totalLines:e})}};function po(e,t){return e>t}var mo=`<svg data-icon-sprite aria-hidden="true" width="0" height="0">
17
+ `:t}function co(e,t){return K({tagName:`div`,children:e,properties:{"data-content":``,style:`grid-row: span ${t}`}})}function lo(e,t){return t.cacheKey==null?e.file===t&&e.sourceContents===t.contents:e.cacheKey===t.cacheKey}var uo=-1,fo=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++uo}`;highlighter;renderCache;computedLang=`text`;lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;constructor(e={theme:W},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=Ga(e.theme??W)?Ot():void 0)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}setLineAnnotations(e){this.lineAnnotations={};for(let t of e){let e=this.lineAnnotations[t.lineNumber]??[];this.lineAnnotations[t.lineNumber]=e,e.push(t)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(){this.editSessionActive=!0}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0,this.endEditSession(),this.textDocumentCache=new WeakMap}syncEditedContentsToFile(){let{renderCache:e,lineCache:t}=this;e?.isDirty!==!0||t==null||!lo(t,e.file)||(e.file.contents=t.lines.join(``))}hasUnkeyedFileContentsChanged(e){let{lineCache:t}=this;return e.cacheKey==null&&t!=null&&t.file===e&&t.sourceContents!==e.contents}invalidateChangedUnkeyedFile(e){this.hasUnkeyedFileContentsChanged(e)&&(this.workerManager?.cleanUpTasks(this),this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap)}clearRenderCache(){this.syncEditedContentsToFile(),this.pendingStructuralRows=void 0;let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(e.file.cacheKey)}hydrate(e){let{options:t}=this.getRenderOptions(e),n=po(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength()),r=this.workerManager?.getFileResultCache(e);r!=null&&!Et(t,r.options)&&(r=void 0),this.renderCache??={file:e,options:t,highlighted:!n&&!Qt(e),result:n?void 0:r?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightFileAST(this,e):this.highlighter??(this.computedLang=e.lang??an(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??W}getEffectiveCodeOptions(){let e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0){let e=this.workerManager.getFileRenderOptions();return this.editSessionActive&&e.useTokenTransformer!==!0?{...e,useTokenTransformer:!0}:e}let{tokenizeMaxLineLength:e=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:e}})(),{renderCache:n}=this;return n?.result==null||!fn(e,n.file)||!Et(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getOrCreateLineCache(e){this.invalidateChangedUnkeyedFile(e);let{lineCache:t}=this;return(t==null||!lo(t,e))&&(t={cacheKey:e.cacheKey,file:e,sourceContents:e.contents,lines:bt(e.contents)}),this.lineCache=t,t.lines}getLineCount(e){let t=this.getOrCreateLineCache(e);return this.textDocumentCache.get(e)?.lineCount??t.length}updateRenderCache(e,t,n=!1){if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:r,result:i}=this.renderCache;if(i==null)return;let a=n?new Map:void 0;this.pendingStructuralRows=a;let o=this.lineCache!=null&&lo(this.lineCache,r)?this.lineCache:void 0;for(let[t,n]of e){if(a===void 0&&o!=null&&t<o.lines.length){let e=n.map(e=>e[2]).join(``);o.lines[t]=so(o.lines[t]??``,e)}let e={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:n.map(([e,t,n])=>e===0&&t===``?n===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:n}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`color:${t};`},children:[{type:`text`,value:n}]})};a===void 0?i.code[t]=e:a.set(t,e)}i.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){let t=this.pendingStructuralRows;if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:n,result:r}=this.renderCache;if(r==null)return;let i=this.lineCache!=null&&lo(this.lineCache,n)?this.lineCache.lines:bt(n.contents),a=bt(e.getText());if(i.length!==a.length){let n=Math.min(i.length,a.length),o=0;for(;o<n&&i[o]===a[o];)o++;let s=0;for(;s<n-o&&i[i.length-1-s]===a[a.length-1-s];)s++;let c=r.code;r.code=Array(a.length);for(let e=0;e<o;e++)r.code[e]=c[e];for(let e=0;e<s;e++)r.code[a.length-1-e]=c[i.length-1-e];if(t!==void 0)for(let[e,n]of t)e<a.length&&(r.code[e]=n);for(let t=o;t<a.length-s;t++)r.code[t]??={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:e.getLineText(t)}]}]};for(let e=0;e<r.code.length;e++){let t=r.code[e];t?.type===`element`&&(t.properties[`data-line`]=e+1,t.properties[`data-line-index`]=e)}this.renderCache.isDirty=!0}this.lineCache={cacheKey:n.cacheKey,file:n,sourceContents:n.contents,lines:a},this.textDocumentCache.set(n,e)}renderFile(e=this.renderCache?.file,t=it){if(e==null)return;this.invalidateChangedUnkeyedFile(e),this.renderCache?.isDirty===!0&&!fn(e,this.renderCache.file)&&(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap);let{options:n,forceHighlight:r}=this.getRenderOptions(e);this.renderCache?.isDirty===!0&&!Et(n,this.renderCache.options)&&this.clearRenderCache();let i=this.getMatchingWorkerResultCache(e,n);i!=null&&!this.hasHighlightedRenderCache(e,n)&&(this.renderCache={file:e,highlighted:!0,renderRange:void 0,...i},r=!1),this.renderCache??={file:e,highlighted:!1,options:n,result:void 0,renderRange:void 0};let a=this.getOrCreateLineCache(e),o=e.contents.length>0,s=!o||Qt(e)||po(a.length,this.getTokenizeMaxLength()),c=!fn(e,this.renderCache.file),l=!Ka(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0)(s||this.renderCache.result==null||!this.renderCache.highlighted&&(c||l))&&(this.renderCache.file=e,this.renderCache.options=n,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||l||r)&&(this.renderCache.result=this.workerManager.getPlainFileAST(e,t.startingLine,t.totalLines,a)),this.renderCache.renderRange=t),!s&&o&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightFileAST(this,e);else{this.computedLang=e.lang??an(e.name);let t=this.highlighter!=null&&Ga(n.theme),i=this.highlighter!=null&&Wa(this.computedLang),a=!s&&i;if(this.highlighter!=null&&t&&(r||s||!this.renderCache.highlighted&&a||this.renderCache.result==null)){let{result:t,options:n}=this.renderFileWithHighlighter(e,this.highlighter,s||!i);this.renderCache={file:e,options:n,highlighted:a,result:t,renderRange:void 0}}(!t||!s&&!i)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,t,n,!s)})}return this.renderCache.result==null?void 0:this.processFileResult(this.renderCache.file,t,this.renderCache.result)}async asyncRender(e,t=it){let{result:n}=await this.asyncHighlight(e);return this.processFileResult(e,t,n)}async asyncHighlight(e){let t=po(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??an(e.name);let n=this.highlighter!=null&&Ut(un(this.getLocalHighlightTheme())),r=t||this.highlighter!=null&&Wa(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(e,this.highlighter,t)}renderFileWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e);return{result:Ke(e,t,r,{forcePlainText:n}),options:r}}processFileResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let a=this.getLineCount(e),{disableFileHeader:o=!1}=this.options,s=[],c=wt(),l=Math.min(t.startingLine+t.totalLines,a),u=0,d=oo(t)?ao(this.lineAnnotations):void 0;d!=null&&(c.children.push(dn(`context`,`annotation`,1)),s.push(qa({type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:d.map(e=>to(e))})),u++);for(let r=t.startingLine;r<l;r++){let t=r+1,i=n[r];if(i==null){let n=`FileRenderer.processFileResult: Line doesnt exist`;throw console.error(n,{name:e.name,lineIndex:r,lineNumber:t}),Error(n)}c.children.push(pn(`context`,t,`${r}`)),s.push(i),u++;let a=this.lineAnnotations[t];a!=null&&(c.children.push(dn(`context`,`annotation`,1)),s.push(qa({type:`annotation`,hunkIndex:0,lineIndex:t,annotations:a.map(e=>to(e))})),u++)}return c.properties.style=`grid-row: span ${u}`,{gutterAST:c.children??[],contentAST:s,preAST:this.createPreElement(a),headerAST:o?void 0:this.renderHeader(e),totalLines:a,rowCount:u,themeStyles:r,baseThemeType:i,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderHeader(e){let{headerRenderMode:t=`default`,stickyHeader:n=!1}=this.options;return Ya({fileOrDiff:e,mode:t,stickyHeader:n})}renderFullHTML(e){return St(this.renderFullAST(e))}renderFullAST(e,t=[]){return t.push(K({tagName:`code`,children:this.renderCodeAST(e),properties:{"data-code":``}})),{...e.preAST,children:t}}renderCodeAST(e){let t=wt();return t.children=e.gutterAST,t.properties.style=`grid-row: span ${e.rowCount}`,[t,co(e.contentAST,e.rowCount)]}renderPartialHTML(e,t=!1){return St(t?K({tagName:`code`,children:e,properties:{"data-code":``}}):e)}async initializeHighlighter(){return this.highlighter=await jt(eo(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(e,t,n,r=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,r)}applyHighlightResult(e,t,n,r=!0){if(this.renderCache==null)return;let i=!fn(e,this.renderCache.file)||!this.renderCache.highlighted||!Et(n,this.renderCache.options);this.renderCache={file:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;let n=this.workerManager?.getFileResultCache(e);if(!(n==null||!Et(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&fn(e,n.file)&&Et(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(e){let{disableLineNumbers:t=!1,overflow:n=`scroll`}=this.options;return Qa({type:`file`,diffIndicators:`none`,disableBackground:!0,disableLineNumbers:t,overflow:n,split:!1,totalLines:e})}};function po(e,t){return e>t}var mo=`<svg data-icon-sprite aria-hidden="true" width="0" height="0">
18
18
  <symbol id="diffs-icon-arrow-right-short" viewBox="0 0 16 16">
19
19
  <path d="M8.47 4.22a.75.75 0 0 0 0 1.06l1.97 1.97H3.75a.75.75 0 0 0 0 1.5h6.69l-1.97 1.97a.75.75 0 1 0 1.06 1.06l3.25-3.25a.75.75 0 0 0 0-1.06L9.53 4.22a.75.75 0 0 0-1.06 0"/>
20
20
  </symbol>
@@ -66,7 +66,7 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
66
66
  <symbol id="diffs-icon-symbol-ref" viewBox="0 0 16 16">
67
67
  <path d="M1.5 8c0 1.613.088 2.806.288 3.704.196.88.478 1.381.802 1.706.286.286.71.54 1.41.73V1.86c-.7.19-1.124.444-1.41.73-.324.325-.606.826-.802 1.706C1.588 5.194 1.5 6.387 1.5 8m4 6.397c.697.07 1.522.103 2.5.103 1.613 0 2.806-.088 3.704-.288.88-.195 1.381-.478 1.706-.802s.607-.826.802-1.706c.2-.898.288-2.091.288-3.704s-.088-2.806-.288-3.704c-.195-.88-.478-1.381-.802-1.706s-.826-.606-1.706-.802C10.806 1.588 9.613 1.5 8 1.5c-.978 0-1.803.033-2.5.103zM0 8c0-6.588 1.412-8 8-8s8 1.412 8 8-1.412 8-8 8-8-1.412-8-8m7-2a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z"/>
68
68
  </symbol>
69
- </svg>`;function ho(e,t){return e.lineNumber===t.lineNumber&&e.metadata===t.metadata}function go(e,t){return e==null||t==null?e===t:vo(e.customProperties,t.customProperties)&&e.type===t.type&&e.diffIndicators===t.diffIndicators&&e.disableBackground===t.disableBackground&&e.disableLineNumbers===t.disableLineNumbers&&e.overflow===t.overflow&&e.split===t.split&&e.totalLines===t.totalLines}var _o={};function vo(e=_o,t=_o){if(e===t)return!0;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function yo(e){let t=document.createElement(`div`);return t.dataset.annotationSlot=``,t.slot=e,t.style.whiteSpace=`normal`,t}function bo(){let e=document.createElement(`div`);return e.slot=`gutter-utility-slot`,e.style.position=`absolute`,e.style.top=`0`,e.style.bottom=`0`,e.style.textAlign=`center`,e.style.whiteSpace=`normal`,e.style.touchAction=`none`,e}function xo(){let e=document.createElement(`style`);return e.setAttribute(St,``),e}var So=`@layer base {
69
+ </svg>`;function ho(e,t){return e.lineNumber===t.lineNumber&&e.metadata===t.metadata}function go(e,t){return e==null||t==null?e===t:vo(e.customProperties,t.customProperties)&&e.type===t.type&&e.diffIndicators===t.diffIndicators&&e.disableBackground===t.disableBackground&&e.disableLineNumbers===t.disableLineNumbers&&e.overflow===t.overflow&&e.split===t.split&&e.totalLines===t.totalLines}var _o={};function vo(e=_o,t=_o){if(e===t)return!0;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function yo(e){let t=document.createElement(`div`);return t.dataset.annotationSlot=``,t.slot=e,t.style.whiteSpace=`normal`,t}function bo(){let e=document.createElement(`div`);return e.slot=`gutter-utility-slot`,e.style.position=`absolute`,e.style.top=`0`,e.style.bottom=`0`,e.style.textAlign=`center`,e.style.whiteSpace=`normal`,e.style.touchAction=`none`,e}function xo(){let e=document.createElement(`style`);return e.setAttribute(xt,``),e}var So=`@layer base {
70
70
  :host {
71
71
  --diffs-font-fallback: "SF Mono", Monaco, Consolas, "Ubuntu Mono", "Liberation Mono",
72
72
  "Courier New", monospace;
@@ -1344,7 +1344,7 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
1344
1344
  }
1345
1345
 
1346
1346
  @layer theme, rendered, unsafe;
1347
- `,Co;function wo(e){if(Co!=null)return Co;let t=e.host;if(typeof HTMLElement<`u`&&t instanceof HTMLElement&&!t.isConnected)return;let n=document.createElement(`div`);n.setAttribute(`data-code`,``),n.setAttribute(gn,`true`);let r=document.createElement(`div`);return r.style.position=`relative`,r.style.width=`200%`,r.style.height=`200%`,n.appendChild(r),e.appendChild(n),Co=Math.max(n.offsetHeight-n.clientHeight,0),n.remove(),Co}function To(e){return`${ct}: ${e==null?`var(--diffs-scrollbar-gutter-fallback)`:`${e}px`};`}var Eo=`@layer base, theme, rendered, unsafe;`,Do=RegExp(`${jo(ct)}\\s*:\\s*[^;]+;`);function Oo(e){return`${Eo}
1347
+ `,Co;function wo(e){if(Co!=null)return Co;let t=e.host;if(typeof HTMLElement<`u`&&t instanceof HTMLElement&&!t.isConnected)return;let n=document.createElement(`div`);n.setAttribute(`data-code`,``),n.setAttribute(hn,`true`);let r=document.createElement(`div`);return r.style.position=`relative`,r.style.width=`200%`,r.style.height=`200%`,n.appendChild(r),e.appendChild(n),Co=Math.max(n.offsetHeight-n.clientHeight,0),n.remove(),Co}function To(e){return`${st}: ${e==null?`var(--diffs-scrollbar-gutter-fallback)`:`${e}px`};`}var Eo=`@layer base, theme, rendered, unsafe;`,Do=RegExp(`${jo(st)}\\s*:\\s*[^;]+;`);function Oo(e){return`${Eo}
1348
1348
  @layer unsafe {
1349
1349
  ${e}
1350
1350
  }`}function ko(e,t=`system`,n){return`${Eo}
@@ -1354,15 +1354,15 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
1354
1354
  ${To(n)}
1355
1355
  ${e}
1356
1356
  }
1357
- }`}function Ao(e,t){let n=To(t);return e.replace(Do,n)}function jo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Mo({code:e,pre:t,columnType:n,rowSpan:r,containerSize:i=!1}={}){return e??(e=document.createElement(`code`),e.setAttribute(`data-code`,``),n!=null&&e.setAttribute(`data-${n}`,``),t?.appendChild(e)),r==null?e.style.removeProperty(`grid-row`):e.style.setProperty(`grid-row`,`span ${r}`),i?e.setAttribute(`data-container-size`,``):e.removeAttribute(`data-container-size`),e}function No(e,t){if(t==null)return;let n=e.shadowRoot??e.attachShadow({mode:`open`});n.innerHTML===``&&(n.innerHTML=t)}function Po(e,{type:t,diffIndicators:n,disableBackground:r,disableLineNumbers:i,overflow:a,split:o,totalLines:s,customProperties:c}){if(c!=null)for(let t in c){let n=c[t];n!=null&&e.setAttribute(t,`${n}`)}switch(t===`diff`?(e.setAttribute(`data-diff`,``),e.removeAttribute(`data-file`)):(e.setAttribute(`data-file`,``),e.removeAttribute(`data-diff`)),n){case`bars`:case`classic`:e.setAttribute(`data-indicators`,n);break;case`none`:e.removeAttribute(`data-indicators`)}return i?e.setAttribute(`data-disable-line-numbers`,``):e.removeAttribute(`data-disable-line-numbers`),r?e.removeAttribute(`data-background`):e.setAttribute(`data-background`,``),t===`diff`?e.setAttribute(`data-diff-type`,o?`split`:`single`):e.removeAttribute(`data-diff-type`),e.setAttribute(`data-overflow`,a),e.style.setProperty(`--diffs-min-number-column-width-default`,`${`${s}`.length}ch`),e}function Fo(e){if(typeof HTMLStyleElement<`u`&&e instanceof HTMLStyleElement)return!0;let t=e.tagName??e.nodeName;return typeof t==`string`&&t.toLowerCase()===`style`}function Io(e){return e?.useTokenTransformer===!0||e?.onTokenClick!=null||e?.onTokenEnter!=null||e?.onTokenLeave!=null}function Lo(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,themeType:e?.themeType,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Io(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,unsafeCSS:e?.unsafeCSS,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Ro(e,t){let n=e?.offsetHeight??0;if(e==null||n===0){t();return}e.style.minHeight=`${n}px`;try{t(),e.offsetHeight}finally{e.style.minHeight=``}}function zo({shadowRoot:e,currentNode:t,themeCSS:n}){if(n.trim()===``){t?.remove();return}return t??=Bo(),t.textContent=n,t.parentNode!==e&&e.appendChild(t),t}function Bo(){let e=document.createElement(`style`);return e.setAttribute(vt,``),e}var Vo=void 0,Ho=void 0;function Uo(){return Vo??=/macOS|MacIntel|iPhone|iPad|iPod/i.test(Go())}function Wo(){return Ho??=`safari`in window&&`pushNotification`in window.safari||/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Go(){let e=globalThis.navigator;return e?.platform??e?.userAgentData?.platform??`unknown`}if(typeof HTMLElement<`u`&&customElements.get(`diffs-container`)==null){let e;class t extends HTMLElement{constructor(){if(super(),this.shadowRoot!=null)return;let t=this.attachShadow({mode:`open`});e??(e=new CSSStyleSheet,e.replaceSync(So)),t.adoptedStyleSheets=[e]}connectedCallback(){wo(this.shadowRoot??this.attachShadow({mode:`open`}))}}customElements.define(Fe,t)}var Ko=[``],qo=-1,Jo=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++qo}`;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:K},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new fo(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ia,this.interactionManager=new ga(`file`,_a(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}__getCurrentFile(){return this.file}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(_a(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;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType!==t&&(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Ht(this.appliedThemeCSS.theme,this.options.theme??K)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{overflow:e=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e===`wrap`,columnVariables:this.shouldApplyColumnVariables(e)?`apply`:`measure`}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e===`scroll`&&this.lineAnnotations.length>0}cleanUp(e=!1){this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 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.clearAuxiliaryNodes(),this.pre=void 0,this.code=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?.remove(),this.errorWrapper=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.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:i,lineAnnotations:a}=e;if(!this.enabled)throw Error(`File.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`File.hydrate: hydrate can only be called before the instance has rendered or hydrated`);this.hydrateElements(t,n),Yo(this.pre,i,this.options.collapsed)||Xo(this.headerElement,i,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:i,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),No(e,t);for(let t of Array.from(e.shadowRoot?.children??[])){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t,this.appliedPreAttributes=void 0;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}if(`diffsHeader`in t.dataset){this.headerElement=t,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(Lo(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?Ko:this.fileRenderer.getOrCreateLineCache(e)}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.file,r=this.lineAnnotations,i=this.renderRange;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.file!==n||e.__syncRenderView(a,t,n,r,i)})}attachEditor(e){this.editor?.cleanUp(),this.editor=e,this.fileRenderer.beginEditSession();let t=this.file==null?void 0:e.__prepareFile?.(this.file);return t!==void 0&&t!==this.file?this.renderPreparedFile({file:t,forceRender:!0,preventEmit:!0,renderRange:this.renderRange}):this.fileRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),()=>{this.editor=void 0,this.fileRenderer.endEditSession()}}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,n){this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render(e){if(!this.enabled)throw Error(`File.render: attempting to call render after cleaned up`);let t=this.editor?.__prepareFile?.(e.file)??e.file;return this.renderPreparedFile(t===e.file?e:{...e,file:t})}renderPreparedFile({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:i,deferManagers:a=!1,lineAnnotations:o,renderRange:s}){this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:c=!1,themeType:l=`system`}=this.options,u=c?void 0:s,d=this.renderRange,f=this.hasThemeChanged(),p=o!=null&&(o.length>0||this.lineAnnotations.length>0)&&o!==this.lineAnnotations,m=!pn(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e);if(!c&&!n&&Ka(u,this.renderRange)&&!m&&!p&&!f)return this.applyCachedThemeState(l);this.renderRange=u,m&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(Lo(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:h=!1,disableFileHeader:g=!1}=this.options;if(g&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,i),this.applyCachedThemeState(l),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let n=this.fileRenderer.renderFile(e,mt);n!=null&&this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n?.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.injectUnsafeCSS()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}try{let r=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,m||f)||!this.applyPartialRender(d,u)){let n=this.fileRenderer.renderFile(e,u);if(n==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.applyFullRender(n,r)}this.applyBuffers(r,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,a||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{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;let 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(let{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){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}async primeHighlightCache(e=this.file){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||$t(e))return;let n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.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.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(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${to(r)}`,a=this.annotationCache.get(i);if(a==null||!ho(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:yo(to(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=bo();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){let{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??=xo(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Oo(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??K,s=typeof o==`string`?o:{...o},c=wo(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=zo({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ko(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=Ao(this.themeCSSStyle.textContent??``,wo(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Wo()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);let n=this.code=Mo({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();let i=()=>{if(n.childElementCount>=2)for(let e=0;e<2;e++){let t=n.children[e],i=r[e];t.innerHTML=Ct(i.children),t.style.cssText=i.properties.style}else n.innerHTML=Ct(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?Ro(t,i):i(),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;let{file:n,code:r}=this,i=r==null?void 0:this.getColumns(r);if(n==null||r==null||i==null)return!1;let a=e.startingLine,o=t.startingLine,s=e.totalLines===1/0?1/0:a+e.totalLines,c=t.totalLines===1/0?1/0:o+t.totalLines,l=Math.max(a,o),u=Math.min(s,c);if(u<=l)return!1;if(!this.trimDOMToOverlap(i.gutter,l,u)||!this.trimDOMToOverlap(i.content,l,u))throw Error(`File.applyPartialRender: failed to trim to overlap`);let{length:d}=i.content.children,f=(e,t)=>{if(!(t<=0))return this.fileRenderer.renderFile(n,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},p=o<l?f(o,l-o):void 0;if(p===void 0&&o<l)return!1;let m=c===1/0?1/0:Math.max(0,c-u),h=c>u?f(u,m):void 0;return h===void 0&&c>u?!1:(this.cleanupErrorWrapper(),p!=null&&(i.gutter.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.gutterAST)),i.content.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.contentAST)),d+=p.rowCount),h!=null&&(i.gutter.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.gutterAST)),i.content.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.contentAST)),d+=h.rowCount),this.lastRowCount!==d&&(i.gutter.style.setProperty(`grid-row`,`span ${d}`),i.content.style.setProperty(`grid-row`,`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){let 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){let r=this.getDOMBoundaryIndices(e,[t,n]),i=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(i>a)return!1;for(let t=e.children.length-1;t>=a;--t)e.children[t]?.remove();for(let t=i-1;t>=0;--t)e.children[t]?.remove();return!0}getDOMBoundaryIndices(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=new Map;if(n.length===0)return r;let i=0,a=n[i],{children:o}=e;a===0&&(r.set(0,0),i+=1,a=n[i]);for(let e=0;e<o.length;e+=1){let t=o[e];if(!(t instanceof HTMLElement))continue;let s=this.getLineIndexFromDOMNode(t);if(s!=null){for(;a!=null&&s>=a;)r.set(a,e),i+=1,a=n[i];if(i>=n.length)break}}for(let e of n)r.has(e)||r.set(e,o.length);return r}getLineIndexFromDOMNode(e){let t=e.dataset.lineIndex;if(t==null)return;let 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??(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??(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){let{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let r=this.cachedHeaderHTML??Ct(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;let{renderHeaderPrefix:i,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:s}=this.options;if(o!=null){let e=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,$e,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{let e=i?.(n)??void 0,r=a?.(n)??void 0,o=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,en,e),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ve,r),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ye,o),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}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}getOrCreateFileContainerNode(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return n!=null&&i&&this.editor?.__captureFocusForDOMReplacement(),i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:Fo(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):Fo(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=mo;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let 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&&(this.editor?.__captureFocusForDOMReplacement(),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(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute(`data-code`)){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){let{overflow:n=`scroll`,disableLineNumbers:r=!1}=this.options,i={type:`file`,split:!1,overflow:n,disableLineNumbers:r,diffIndicators:`none`,disableBackground:!0,totalLines:t};go(i,this.appliedPreAttributes)||(Po(e,i),this.appliedPreAttributes=i)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Yo(e,t,n=!1){return!n&&e==null&&t!=null}function Xo(e,t,n=!1){return e==null&&t!=null&&!n}var Zo=5e3,Qo=-1;function $o(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS}var es=class extends Jo{virtualizer;metrics;__id=`virtualized-file:${++Qo}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,n=Ze,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=n}setMetrics(e,t=!1){let n=ht(e);!t&&vi(this.metrics,n)||(this.metrics=n,this.resetLayoutCache())}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache()}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}hasLineAnnotations(){return this.lineAnnotations.some(e=>e.lineNumber>0)}getLineHeight(e,t=!1){let n=this.cache.heights.get(e);if(n!=null)return n;let r=t?2:1;return this.metrics.lineHeight*r}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!yi(t,e),r=$o(t,e);super.setOptions(e),r&&this.resetLayoutCache(!0),n&&(this.forceRenderOverride=!0),n&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache(e=!1,t=!0){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&&t&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(e=!0),this.height=0,e;let{overflow:t=`scroll`}=this.options;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return e;let n=this.code.children[1];if(!(n instanceof HTMLElement))return e;let r=io(this.lineAnnotations);if(this.renderRange!=null&&r&&oo(this.renderRange)){let t=ts(n)??0;t!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=t,e=!0)}else!r&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,e=!0);for(let t of n.children){if(!(t instanceof HTMLElement))continue;let n=t.dataset.lineIndex;if(n==null)continue;let r=Number(n),i=t.getBoundingClientRect().height,a=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(a=!0),i+=t.nextElementSibling.getBoundingClientRect().height);let o=this.getLineHeight(r,a);i!==o&&(e=!0,i===this.metrics.lineHeight*(a?2:1)?this.cache.heights.delete(r):this.cache.heights.set(r,i))}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null||this.file==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(e,t,n,r){let i=this.syncLineAnnotations(r),a=!pn(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e),o=n?.resetFileLayoutCache===!0||a||i;n?.metrics!=null&&(this.metrics=n.metrics,o=!0);let{collapsed:s=!1}=this.options;return this.currentCollapsed!==s&&(this.currentCollapsed=s,o=!0),o&&this.resetLayoutCache(),this.file!==e&&(this.layoutDirty=!0),this.file=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e){if(this.file==null||e<1)return;let{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(this.file)-1,i=Be(this.metrics,t);if(n||r<0)return{top:i,height:0};let a=Math.min(Math.max(e-1,0),r),{overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics;if(i+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())return{top:i+a*s,height:s};let c=this.getLayoutCheckpointBeforeLineIndex(a);i=c?.top??i;for(let e=c?.lineIndex??0;e<a;e++)i+=this.getLineHeight(e,!1);return{top:i,height:this.getLineHeight(a,!1)}}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.file==null||this.renderRange==null)return;let{disableFileHeader:t=!1,collapsed:n=!1,overflow:r=`scroll`}=this.options;if(n||this.renderRange.totalLines<=0)return;let i=this.fileRenderer.getLineCount(this.file)-1;if(i<0)return;let a=Be(this.metrics,t),o=Math.min(this.renderRange.startingLine,i),s=Math.min(o+this.renderRange.totalLines-1,i);if(s<o)return;let{fileAnnotationHeight:c}=this.cache;if(r===`scroll`&&!this.hasLineAnnotations()){let{lineHeight:t}=this.metrics,n=a+(o===0?c:this.renderRange.bufferBefore),r=o+Math.max(Math.ceil((e-n)/t),0);return r>s?void 0:{lineNumber:r+1,top:a+c+r*t}}let l=a+(o===0?c:this.renderRange.bufferBefore);for(let t=o;t<=s;t++){if(l>=e)return{lineNumber:t+1,top:l};l+=this.getLineHeight(t)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.file,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(e)}computeApproximateSize(e=!1,t=this.file){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1,overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(t),l=Be(this.metrics,i),u=Je(this.metrics);if(this.height+=l,a){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())this.height+=c*s;else for(let e=0;e<c;e++)this.addLayoutCheckpoint(e,this.height),this.height+=this.getLineHeight(e,!1);if(c>0&&(this.height+=u),this.fileContainer!=null&&n&&!r){let e=this.fileContainer.getBoundingClientRect();e.height===this.height?console.log(`VirtualizedFile.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFile.computeApproximateSize: computed height doesnt match`,{name:t.name,elementHeight:e.height,computedHeight:this.height})}this.layoutDirty=!1}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{renderRange:r}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.file!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.file,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}renderPreparedFile({fileContainer:e,file:t,forceRender:n=!1,lineAnnotations:r,...i}){let a=this.file==null||!pn(this.file,t)||this.fileRenderer.hasUnkeyedFileContentsChanged(t),{forceRenderOverride:o,isSetup:s}=this;this.forceRenderOverride=void 0;let c=this.syncLineAnnotations(r);if(c&&this.resetLayoutCache(),e=this.getOrCreateFileContainerNode(e),t==null)return console.error(`VirtualizedFile.render: attempting to virtually render when we dont have file`),!1;if(s)this.top??=this.getVirtualizedTop(),a&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!1),this.computeApproximateSize(!1,t));else{this.computeApproximateSize(!1,t);let n=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(n==null)throw Error(`VirtualizedFile.render: simple virtualizer is not available`);n.connect(e,this),this.isVisible=n.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!a||!s))return this.file=t,a&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let l=this.virtualizer.getWindowSpecs(),u=this.top??0,d=this.computeRenderRangeFromWindow(t,u,l),f=super.renderPreparedFile({file:t,fileContainer:e,renderRange:d,lineAnnotations:r,forceRender:(o??n)||c||a,...i});return this.isSimpleMode()&&f&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),f}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}addLayoutCheckpoint(e,t){e%Zo===0&&this.cache.checkpoints.push({lineIndex:e,top:t})}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFile: invalid checkpoint index`);if(n.lineIndex%t===0)return n}}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type===`advanced`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,overflow:a=`scroll`}=this.options,{hunkLineCount:o,lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(e),l=this.height,u=Be(this.metrics,i),d=c>0?Je(this.metrics):0,{fileAnnotationHeight:f}=this.cache,p=u+f,m=Math.max(0,l-u-f-d),h=io(this.lineAnnotations),g=t+u,_=f>0&&h&&g<r&&g+f>n;if(t<n-l||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};if(c<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};let v=Math.ceil(Math.max(r-n,0)/s),y=Math.ceil(v/o)*o+o,b=y/o,x=(n+r)/2;if(a===`scroll`&&!this.hasLineAnnotations()){let e=t+p,i=e+m;if(!_&&!(e<r&&i>n))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};let a=Math.floor(_&&x<t+p?0:(x-(t+p))/s),h=Math.floor(a/o)-Math.floor(b/2),g=Math.ceil(c/o),v=Math.max(0,Math.min(h,g))*o,S=h<0?y+h*o:y,C=v===0?0:f+v*s,w=Math.min(S,c-v);return{startingLine:v,totalLines:S,bufferBefore:C,bufferAfter:Math.max(0,(c-v-w)*s)}}let S=b,C=[],w=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-y*s*2),o),T=t+(w?.top??p),E=w?.lineIndex??0,D,O,k,A=w?.lineIndex??0;for(let e=A;e<c;e++){let i=E%o===0,a=Math.floor(E/o);if(i&&(C[a]=T-(t+p),k!=null)){if(k<=0)break;k--}let s=this.getLineHeight(e,!1);T>n-s&&T<r&&(D??=a),T+s>x&&(O??=a),k==null&&T>=r&&i&&(k=S),E++,T+=s}if(D==null){if(_)D=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d}}O??=D;let j=Math.round(O-b/2),ee=Math.max(0,Math.ceil(c/o)-b),M=Math.max(0,Math.min(j,ee)),te=M*o,N=j<0?y+j*o:y,P=C[M]??0,ne=te===0?0:f+P,F=M+N/o,re=F<C.length?m-C[F]:m-(T-t-p);return{startingLine:te,totalLines:N,bufferBefore:ne,bufferAfter:Math.max(0,re)}}};function ts(e){let t;for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===ro&&(t=Math.max(t??0,n.getBoundingClientRect().height));return t}function ns(e){return{...e,hunks:e.hunks.map(e=>({...e,hunkContent:e.hunkContent.map(e=>({...e}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function rs(e){return e===``?[]:e.split(bt)}function is(e,t,n){let r=e===`clone`?ns(t):t;if(!r.isPartial)throw Error(`hydratePartialDiff: fileDiff must be partial`);switch(r.type){case`change`:case`rename-changed`:return as(r,ss(r,n),cs(r,n));case`rename-pure`:{let e=cs(r,n);ls(r,n);let t=rs(e.contents);return r.isPartial=!1,r.deletionLines=t,r.additionLines=t,ds(r,null,e),r}}throw Error(`hydratePartialDiff: ${r.type} diffs cannot be hydrated from loaded files`)}function as(e,t,n){let r=rs(t.contents),i=rs(n.contents),{hunks:a,splitLineCount:o,unifiedLineCount:s}=os(e.hunks,i.length);return e.hunks=a,e.splitLineCount=o,e.unifiedLineCount=s,e.isPartial=!1,e.deletionLines=r,e.additionLines=i,ds(e,t,n),e}function os(e,t){let n=0,r=0,i=0,a=[];for(let t of e){let e=Math.max(t.additionStart-1,0),o=Math.max(t.deletionStart-1,0),s=e,c=o,l=0,u=0,d=0,f=0,p=[];for(let e of t.hunkContent){if(e.type===`context`){p.push({...e,additionLineIndex:s,deletionLineIndex:c}),s+=e.lines,c+=e.lines,d+=e.lines,f+=e.lines;continue}p.push({...e,additionLineIndex:s,deletionLineIndex:c}),s+=e.additions,c+=e.deletions,l+=e.additions,u+=e.deletions,d+=Math.max(e.additions,e.deletions),f+=e.additions+e.deletions}let m=Math.max(Le(t.additionStart,t.additionCount)-i,0);a.push({...t,collapsedBefore:m,additionLineIndex:e,deletionLineIndex:o,additionLines:l,deletionLines:u,hunkContent:p,splitLineStart:n+m,unifiedLineStart:r+m,splitLineCount:d,unifiedLineCount:f}),n+=m+d,r+=m+f,i=Re(t.additionStart,t.additionCount)}if(a.length>0){let e=a[a.length-1],i=Re(e.additionStart,e.additionCount),o=Math.max(t-i,0);n+=o,r+=o}return{hunks:a,splitLineCount:n,unifiedLineCount:r}}function ss(e,t){if(t.oldFile==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function cs(e,t){if(t.newFile==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function ls(e,t){if(t.oldFile!==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function us(e,t,n){return e.cacheKey==null?fs(t,n):`${e.cacheKey}:hydrated`}function ds(e,t,n){let r=us(e,t,n);if(r==null){delete e.cacheKey;return}e.cacheKey=r}function fs(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?`${e.cacheKey}:${t.cacheKey}`:void 0:e?.cacheKey??t?.cacheKey}var ps=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&=(this.codeDeletions?.removeEventListener(`scroll`,this.handleDeletionsScroll),this.codeAdditions?.removeEventListener(`scroll`,this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,!1)}setup(e,t,n){if(t==null||n==null)for(let r of e.children??[])r instanceof HTMLElement&&(`deletions`in r.dataset?t=r:`additions`in r.dataset&&(n=r));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener(`scroll`,this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener(`scroll`,this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener(`scroll`,this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener(`scroll`,this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function ms(e){return q({tagName:`div`,properties:{"data-content-buffer":``,"data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function hs(e){return q({tagName:`div`,children:[q({tagName:`span`,children:[Ie(`No newline at end of file`)]})],properties:{"data-no-newline":``,"data-line-type":e,"data-column-content":``}})}function gs(e){return q({tagName:`div`,children:[lt({name:e===`both`?`diffs-icon-expand-all`:`diffs-icon-expand`,properties:{"data-icon":``}})],properties:{role:`button`,"data-expand-button":``,"data-expand-both":e===`both`?``:void 0,"data-expand-up":e===`up`?``:void 0,"data-expand-down":e===`down`?``:void 0}})}function _s({type:e,content:t,expandIndex:n,chunked:r=!1,slotName:i,isFirstHunk:a,isLastHunk:o}){let s=0,c=[];if(e===`metadata`&&t!=null&&c.push(q({tagName:`div`,children:[Ie(t)],properties:{"data-separator-wrapper":``}})),(e===`line-info`||e===`line-info-basic`)&&t!=null){let e=[];n!=null&&(r?(a||(e.push(gs(`up`)),s++),o||(e.push(gs(`down`)),s++)):(e.push(gs(!a&&!o?`both`:a?`down`:`up`)),s++)),e.push(q({tagName:`div`,children:[q({tagName:`span`,children:[Ie(t)],properties:{"data-unmodified-lines":``}})],properties:{"data-separator-content":``}})),r&&n!=null&&e.push(q({tagName:`div`,children:[Ie(`Expand all`)],properties:{role:`button`,"data-expand-button":``,"data-expand-all-button":``}})),c.push(q({tagName:`div`,children:e,properties:{"data-separator-wrapper":``,"data-separator-multi-button":s>1?``:void 0}}))}return e===`custom`&&i!=null&&c.push(q({tagName:`slot`,properties:{name:i}})),q({tagName:`div`,children:c,properties:{"data-separator":c.length===0?`simple`:e,"data-expand-index":n,"data-separator-first":a?``:void 0,"data-separator-last":o?``:void 0}})}function vs(e,t){return`hunk-separator-${e}-${t}`}function ys(e){let t=e.at(-1);return t==null?0:Math.max(Re(t.additionStart,t.additionCount),Re(t.deletionStart,t.deletionCount))}function bs(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function xs(e,t){let n=da({name:e.prevName??e.name,contents:e.deletionLines.join(``)},{name:e.name,contents:e.additionLines.join(``),lang:e.lang},t);return{hunks:n.hunks,splitLineCount:n.splitLineCount,unifiedLineCount:n.unifiedLineCount,additionLines:n.additionLines,deletionLines:n.deletionLines,type:n.type}}function Ss(e,t){let n=Math.max(e,1),r=Array.from({length:n},(e,t)=>`${` `.repeat(t+1)}\n`).join(``);return r===t&&(r=Array.from({length:n},(e,t)=>`\u0000${` `.repeat(t)}\n`).join(``)),r}function Cs(e){for(let t of e)if(t.trim().length>0)return!1;return!0}function ws(e,t){return t.length>0&&t.length<e.deletionLines.length&&Cs(t)}function Ts(e,t,n){let r=e.deletionLines.join(``),i=Ss(t.length,r),a=da({name:e.prevName??e.name,contents:r},{name:e.name,contents:i,lang:e.lang},n);return{hunks:a.hunks,splitLineCount:a.splitLineCount,unifiedLineCount:a.unifiedLineCount,additionLines:t,deletionLines:a.deletionLines,type:a.type}}function Es(e,t){return Ts(e,[``],t)}function Ds(e,t){if(e.additionLines.length===0)return Es(e,t);if(ws(e,e.additionLines))return Ts(e,e.additionLines,t);let n=e.additionLines,r=xs(e,t);return ks(r,n),r}function Os(e){return e.length>1&&e.at(-1)===``}function ks(e,t){if(!Os(t))return;let n=t.length-e.additionLines.length;if(n<=0)return;let r=e.additionLines.length,i=e.hunks.at(-1);if(i!=null&&Re(i.additionStart,i.additionCount)===r){for(let a of i.hunkContent)if(a.type===`change`&&a.additions<a.deletions&&a.additionLineIndex+a.additions===r){e.additionLines=t,a.additions+=n,i.additionCount+=n,i.additionLines+=n,zs(e);return}}}function As(e,t,n){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return js(e,xs(e,n));let r=Array.from(t);if(r.length===0)return js(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(let t of r){let r=e.additionLines[t],i=e.deletionLines[t];if(r==null||i==null||nt(r)===nt(i))return js(e,xs(e,n))}let i=Ms(e,r);if(i.size===0)return js(e,xs(e,n));for(let t of i)if(!Ps(e,t,n))return js(e,xs(e,n));return zs(e),Pe(e)?js(e,xs(e,n)):js(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function js(e,t){return Object.assign(e,t),t}function Ms(e,t){let n=new Set;for(let r of t){let t=Ns(e,r);if(t==null)return new Set;n.add(t)}return n}function Ns(e,t){for(let[n,r]of e.hunks.entries()){let e=r.additionLineIndex+r.additionCount;if(t>=r.additionLineIndex&&t<e)return n}}function Ps(e,t,n){let r=e.hunks[t];if(r==null)return!1;let i=e.deletionLines.slice(r.deletionLineIndex,r.deletionLineIndex+r.deletionCount),a=e.additionLines.slice(r.additionLineIndex,r.additionLineIndex+r.additionCount),o=da({name:e.prevName??e.name,contents:i.join(``)},{name:e.name,contents:a.join(``),lang:e.lang},{...n,context:0}),s=o.hunks[0];return s==null||o.hunks.length!==1?!1:(Is(r,s),Fs(e,t),!0)}function Fs(e,t){let n=e.hunks[t];if(n==null)return;if(t!==e.hunks.length-1){n.noEOFCRAdditions=!1,n.noEOFCRDeletions=!1;return}let r=e.additionLines.at(-1),i=e.deletionLines.at(-1);n.noEOFCRAdditions=r!=null&&r!==``&&!r.endsWith(`
1357
+ }`}function Ao(e,t){let n=To(t);return e.replace(Do,n)}function jo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Mo({code:e,pre:t,columnType:n,rowSpan:r,containerSize:i=!1}={}){return e??(e=document.createElement(`code`),e.setAttribute(`data-code`,``),n!=null&&e.setAttribute(`data-${n}`,``),t?.appendChild(e)),r==null?e.style.removeProperty(`grid-row`):e.style.setProperty(`grid-row`,`span ${r}`),i?e.setAttribute(`data-container-size`,``):e.removeAttribute(`data-container-size`),e}function No(e,t){if(t==null)return;let n=e.shadowRoot??e.attachShadow({mode:`open`});n.innerHTML===``&&(n.innerHTML=t)}function Po(e,{type:t,diffIndicators:n,disableBackground:r,disableLineNumbers:i,overflow:a,split:o,totalLines:s,customProperties:c}){if(c!=null)for(let t in c){let n=c[t];n!=null&&e.setAttribute(t,`${n}`)}switch(t===`diff`?(e.setAttribute(`data-diff`,``),e.removeAttribute(`data-file`)):(e.setAttribute(`data-file`,``),e.removeAttribute(`data-diff`)),n){case`bars`:case`classic`:e.setAttribute(`data-indicators`,n);break;case`none`:e.removeAttribute(`data-indicators`)}return i?e.setAttribute(`data-disable-line-numbers`,``):e.removeAttribute(`data-disable-line-numbers`),r?e.removeAttribute(`data-background`):e.setAttribute(`data-background`,``),t===`diff`?e.setAttribute(`data-diff-type`,o?`split`:`single`):e.removeAttribute(`data-diff-type`),e.setAttribute(`data-overflow`,a),e.style.setProperty(`--diffs-min-number-column-width-default`,`${`${s}`.length}ch`),e}function Fo(e){if(typeof HTMLStyleElement<`u`&&e instanceof HTMLStyleElement)return!0;let t=e.tagName??e.nodeName;return typeof t==`string`&&t.toLowerCase()===`style`}function Io(e){return e?.useTokenTransformer===!0||e?.onTokenClick!=null||e?.onTokenEnter!=null||e?.onTokenLeave!=null}function Lo(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,themeType:e?.themeType,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Io(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,unsafeCSS:e?.unsafeCSS,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Ro(e,t){let n=e?.offsetHeight??0;if(e==null||n===0){t();return}e.style.minHeight=`${n}px`;try{t(),e.offsetHeight}finally{e.style.minHeight=``}}function zo({shadowRoot:e,currentNode:t,themeCSS:n}){if(n.trim()===``){t?.remove();return}return t??=Bo(),t.textContent=n,t.parentNode!==e&&e.appendChild(t),t}function Bo(){let e=document.createElement(`style`);return e.setAttribute(_t,``),e}var Vo=void 0,Ho=void 0;function Uo(){return Vo??=/macOS|MacIntel|iPhone|iPad|iPod/i.test(Go())}function Wo(){return Ho??=`safari`in window&&`pushNotification`in window.safari||/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Go(){let e=globalThis.navigator;return e?.platform??e?.userAgentData?.platform??`unknown`}if(typeof HTMLElement<`u`&&customElements.get(`diffs-container`)==null){let e;class t extends HTMLElement{constructor(){if(super(),this.shadowRoot!=null)return;let t=this.attachShadow({mode:`open`});e??(e=new CSSStyleSheet,e.replaceSync(So)),t.adoptedStyleSheets=[e]}connectedCallback(){wo(this.shadowRoot??this.attachShadow({mode:`open`}))}}customElements.define(Fe,t)}var Ko=[``],qo=-1,Jo=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++qo}`;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:W},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new fo(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ia,this.interactionManager=new ga(`file`,_a(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}__getCurrentFile(){return this.file}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(_a(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;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType!==t&&(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Vt(this.appliedThemeCSS.theme,this.options.theme??W)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{overflow:e=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e===`wrap`,columnVariables:this.shouldApplyColumnVariables(e)?`apply`:`measure`}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e===`scroll`&&this.lineAnnotations.length>0}cleanUp(e=!1){this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 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.clearAuxiliaryNodes(),this.pre=void 0,this.code=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?.remove(),this.errorWrapper=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.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:i,lineAnnotations:a}=e;if(!this.enabled)throw Error(`File.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`File.hydrate: hydrate can only be called before the instance has rendered or hydrated`);this.hydrateElements(t,n),Yo(this.pre,i,this.options.collapsed)||Xo(this.headerElement,i,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:i,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),No(e,t);for(let t of Array.from(e.shadowRoot?.children??[])){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t,this.appliedPreAttributes=void 0;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}if(`diffsHeader`in t.dataset){this.headerElement=t,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(Lo(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?Ko:this.fileRenderer.getOrCreateLineCache(e)}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.file,r=this.lineAnnotations,i=this.renderRange;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.file!==n||e.__syncRenderView(a,t,n,r,i)})}attachEditor(e){this.editor?.cleanUp(),this.editor=e,this.fileRenderer.beginEditSession();let t=this.file==null?void 0:e.__prepareFile?.(this.file);return t!==void 0&&t!==this.file?this.renderPreparedFile({file:t,forceRender:!0,preventEmit:!0,renderRange:this.renderRange}):this.fileRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),()=>{this.editor=void 0,this.fileRenderer.endEditSession()}}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,n){this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render(e){if(!this.enabled)throw Error(`File.render: attempting to call render after cleaned up`);let t=this.editor?.__prepareFile?.(e.file)??e.file;return this.renderPreparedFile(t===e.file?e:{...e,file:t})}renderPreparedFile({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:i,deferManagers:a=!1,lineAnnotations:o,renderRange:s}){this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:c=!1,themeType:l=`system`}=this.options,u=c?void 0:s,d=this.renderRange,f=this.hasThemeChanged(),p=o!=null&&(o.length>0||this.lineAnnotations.length>0)&&o!==this.lineAnnotations,m=!fn(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e);if(!c&&!n&&Ka(u,this.renderRange)&&!m&&!p&&!f)return this.applyCachedThemeState(l);this.renderRange=u,m&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(Lo(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:h=!1,disableFileHeader:g=!1}=this.options;if(g&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,i),this.applyCachedThemeState(l),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let n=this.fileRenderer.renderFile(e,pt);n!=null&&this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n?.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.injectUnsafeCSS()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}try{let r=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,m||f)||!this.applyPartialRender(d,u)){let n=this.fileRenderer.renderFile(e,u);if(n==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.applyFullRender(n,r)}this.applyBuffers(r,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,a||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{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;let 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(let{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){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}async primeHighlightCache(e=this.file){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Qt(e))return;let n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.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.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(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${to(r)}`,a=this.annotationCache.get(i);if(a==null||!ho(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:yo(to(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=bo();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){let{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??=xo(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Oo(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??W,s=typeof o==`string`?o:{...o},c=wo(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=zo({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ko(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=Ao(this.themeCSSStyle.textContent??``,wo(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Wo()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);let n=this.code=Mo({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();let i=()=>{if(n.childElementCount>=2)for(let e=0;e<2;e++){let t=n.children[e],i=r[e];t.innerHTML=St(i.children),t.style.cssText=i.properties.style}else n.innerHTML=St(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?Ro(t,i):i(),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;let{file:n,code:r}=this,i=r==null?void 0:this.getColumns(r);if(n==null||r==null||i==null)return!1;let a=e.startingLine,o=t.startingLine,s=e.totalLines===1/0?1/0:a+e.totalLines,c=t.totalLines===1/0?1/0:o+t.totalLines,l=Math.max(a,o),u=Math.min(s,c);if(u<=l)return!1;if(!this.trimDOMToOverlap(i.gutter,l,u)||!this.trimDOMToOverlap(i.content,l,u))throw Error(`File.applyPartialRender: failed to trim to overlap`);let{length:d}=i.content.children,f=(e,t)=>{if(!(t<=0))return this.fileRenderer.renderFile(n,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},p=o<l?f(o,l-o):void 0;if(p===void 0&&o<l)return!1;let m=c===1/0?1/0:Math.max(0,c-u),h=c>u?f(u,m):void 0;return h===void 0&&c>u?!1:(this.cleanupErrorWrapper(),p!=null&&(i.gutter.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.gutterAST)),i.content.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.contentAST)),d+=p.rowCount),h!=null&&(i.gutter.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.gutterAST)),i.content.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.contentAST)),d+=h.rowCount),this.lastRowCount!==d&&(i.gutter.style.setProperty(`grid-row`,`span ${d}`),i.content.style.setProperty(`grid-row`,`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){let 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){let r=this.getDOMBoundaryIndices(e,[t,n]),i=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(i>a)return!1;for(let t=e.children.length-1;t>=a;--t)e.children[t]?.remove();for(let t=i-1;t>=0;--t)e.children[t]?.remove();return!0}getDOMBoundaryIndices(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=new Map;if(n.length===0)return r;let i=0,a=n[i],{children:o}=e;a===0&&(r.set(0,0),i+=1,a=n[i]);for(let e=0;e<o.length;e+=1){let t=o[e];if(!(t instanceof HTMLElement))continue;let s=this.getLineIndexFromDOMNode(t);if(s!=null){for(;a!=null&&s>=a;)r.set(a,e),i+=1,a=n[i];if(i>=n.length)break}}for(let e of n)r.has(e)||r.set(e,o.length);return r}getLineIndexFromDOMNode(e){let t=e.dataset.lineIndex;if(t==null)return;let 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??(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??(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){let{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let r=this.cachedHeaderHTML??St(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;let{renderHeaderPrefix:i,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:s}=this.options;if(o!=null){let e=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,$e,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{let e=i?.(n)??void 0,r=a?.(n)??void 0,o=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,$t,e),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ve,r),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ye,o),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}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}getOrCreateFileContainerNode(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return n!=null&&i&&this.editor?.__captureFocusForDOMReplacement(),i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:Fo(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):Fo(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=mo;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let 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&&(this.editor?.__captureFocusForDOMReplacement(),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(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute(`data-code`)){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){let{overflow:n=`scroll`,disableLineNumbers:r=!1}=this.options,i={type:`file`,split:!1,overflow:n,disableLineNumbers:r,diffIndicators:`none`,disableBackground:!0,totalLines:t};go(i,this.appliedPreAttributes)||(Po(e,i),this.appliedPreAttributes=i)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Yo(e,t,n=!1){return!n&&e==null&&t!=null}function Xo(e,t,n=!1){return e==null&&t!=null&&!n}var Zo=5e3,Qo=-1;function $o(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS}var es=class extends Jo{virtualizer;metrics;__id=`virtualized-file:${++Qo}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,n=Ze,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=n}setMetrics(e,t=!1){let n=mt(e);!t&&vi(this.metrics,n)||(this.metrics=n,this.resetLayoutCache())}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache()}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}hasLineAnnotations(){return this.lineAnnotations.some(e=>e.lineNumber>0)}getLineHeight(e,t=!1){let n=this.cache.heights.get(e);if(n!=null)return n;let r=t?2:1;return this.metrics.lineHeight*r}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!yi(t,e),r=$o(t,e);super.setOptions(e),r&&this.resetLayoutCache(!0),n&&(this.forceRenderOverride=!0),n&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache(e=!1,t=!0){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&&t&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(e=!0),this.height=0,e;let{overflow:t=`scroll`}=this.options;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return e;let n=this.code.children[1];if(!(n instanceof HTMLElement))return e;let r=io(this.lineAnnotations);if(this.renderRange!=null&&r&&oo(this.renderRange)){let t=ts(n)??0;t!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=t,e=!0)}else!r&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,e=!0);for(let t of n.children){if(!(t instanceof HTMLElement))continue;let n=t.dataset.lineIndex;if(n==null)continue;let r=Number(n),i=t.getBoundingClientRect().height,a=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(a=!0),i+=t.nextElementSibling.getBoundingClientRect().height);let o=this.getLineHeight(r,a);i!==o&&(e=!0,i===this.metrics.lineHeight*(a?2:1)?this.cache.heights.delete(r):this.cache.heights.set(r,i))}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null||this.file==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(e,t,n,r){let i=this.syncLineAnnotations(r),a=!fn(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e),o=n?.resetFileLayoutCache===!0||a||i;n?.metrics!=null&&(this.metrics=n.metrics,o=!0);let{collapsed:s=!1}=this.options;return this.currentCollapsed!==s&&(this.currentCollapsed=s,o=!0),o&&this.resetLayoutCache(),this.file!==e&&(this.layoutDirty=!0),this.file=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e){if(this.file==null||e<1)return;let{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(this.file)-1,i=Be(this.metrics,t);if(n||r<0)return{top:i,height:0};let a=Math.min(Math.max(e-1,0),r),{overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics;if(i+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())return{top:i+a*s,height:s};let c=this.getLayoutCheckpointBeforeLineIndex(a);i=c?.top??i;for(let e=c?.lineIndex??0;e<a;e++)i+=this.getLineHeight(e,!1);return{top:i,height:this.getLineHeight(a,!1)}}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.file==null||this.renderRange==null)return;let{disableFileHeader:t=!1,collapsed:n=!1,overflow:r=`scroll`}=this.options;if(n||this.renderRange.totalLines<=0)return;let i=this.fileRenderer.getLineCount(this.file)-1;if(i<0)return;let a=Be(this.metrics,t),o=Math.min(this.renderRange.startingLine,i),s=Math.min(o+this.renderRange.totalLines-1,i);if(s<o)return;let{fileAnnotationHeight:c}=this.cache;if(r===`scroll`&&!this.hasLineAnnotations()){let{lineHeight:t}=this.metrics,n=a+(o===0?c:this.renderRange.bufferBefore),r=o+Math.max(Math.ceil((e-n)/t),0);return r>s?void 0:{lineNumber:r+1,top:a+c+r*t}}let l=a+(o===0?c:this.renderRange.bufferBefore);for(let t=o;t<=s;t++){if(l>=e)return{lineNumber:t+1,top:l};l+=this.getLineHeight(t)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.file,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(e)}computeApproximateSize(e=!1,t=this.file){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1,overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(t),l=Be(this.metrics,i),u=Je(this.metrics);if(this.height+=l,a){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())this.height+=c*s;else for(let e=0;e<c;e++)this.addLayoutCheckpoint(e,this.height),this.height+=this.getLineHeight(e,!1);if(c>0&&(this.height+=u),this.fileContainer!=null&&n&&!r){let e=this.fileContainer.getBoundingClientRect();e.height===this.height?console.log(`VirtualizedFile.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFile.computeApproximateSize: computed height doesnt match`,{name:t.name,elementHeight:e.height,computedHeight:this.height})}this.layoutDirty=!1}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{renderRange:r}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.file!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.file,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}renderPreparedFile({fileContainer:e,file:t,forceRender:n=!1,lineAnnotations:r,...i}){let a=this.file==null||!fn(this.file,t)||this.fileRenderer.hasUnkeyedFileContentsChanged(t),{forceRenderOverride:o,isSetup:s}=this;this.forceRenderOverride=void 0;let c=this.syncLineAnnotations(r);if(c&&this.resetLayoutCache(),e=this.getOrCreateFileContainerNode(e),t==null)return console.error(`VirtualizedFile.render: attempting to virtually render when we dont have file`),!1;if(s)this.top??=this.getVirtualizedTop(),a&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!1),this.computeApproximateSize(!1,t));else{this.computeApproximateSize(!1,t);let n=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(n==null)throw Error(`VirtualizedFile.render: simple virtualizer is not available`);n.connect(e,this),this.isVisible=n.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!a||!s))return this.file=t,a&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let l=this.virtualizer.getWindowSpecs(),u=this.top??0,d=this.computeRenderRangeFromWindow(t,u,l),f=super.renderPreparedFile({file:t,fileContainer:e,renderRange:d,lineAnnotations:r,forceRender:(o??n)||c||a,...i});return this.isSimpleMode()&&f&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),f}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}addLayoutCheckpoint(e,t){e%Zo===0&&this.cache.checkpoints.push({lineIndex:e,top:t})}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFile: invalid checkpoint index`);if(n.lineIndex%t===0)return n}}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type===`advanced`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,overflow:a=`scroll`}=this.options,{hunkLineCount:o,lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(e),l=this.height,u=Be(this.metrics,i),d=c>0?Je(this.metrics):0,{fileAnnotationHeight:f}=this.cache,p=u+f,m=Math.max(0,l-u-f-d),h=io(this.lineAnnotations),g=t+u,_=f>0&&h&&g<r&&g+f>n;if(t<n-l||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};if(c<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};let v=Math.ceil(Math.max(r-n,0)/s),y=Math.ceil(v/o)*o+o,b=y/o,x=(n+r)/2;if(a===`scroll`&&!this.hasLineAnnotations()){let e=t+p,i=e+m;if(!_&&!(e<r&&i>n))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};let a=Math.floor(_&&x<t+p?0:(x-(t+p))/s),h=Math.floor(a/o)-Math.floor(b/2),g=Math.ceil(c/o),v=Math.max(0,Math.min(h,g))*o,S=h<0?y+h*o:y,C=v===0?0:f+v*s,w=Math.min(S,c-v);return{startingLine:v,totalLines:S,bufferBefore:C,bufferAfter:Math.max(0,(c-v-w)*s)}}let S=b,C=[],w=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-y*s*2),o),T=t+(w?.top??p),E=w?.lineIndex??0,D,O,k,A=w?.lineIndex??0;for(let e=A;e<c;e++){let i=E%o===0,a=Math.floor(E/o);if(i&&(C[a]=T-(t+p),k!=null)){if(k<=0)break;k--}let s=this.getLineHeight(e,!1);T>n-s&&T<r&&(D??=a),T+s>x&&(O??=a),k==null&&T>=r&&i&&(k=S),E++,T+=s}if(D==null){if(_)D=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d}}O??=D;let j=Math.round(O-b/2),M=Math.max(0,Math.ceil(c/o)-b),ee=Math.max(0,Math.min(j,M)),N=ee*o,te=j<0?y+j*o:y,P=C[ee]??0,ne=N===0?0:f+P,re=ee+te/o,ie=re<C.length?m-C[re]:m-(T-t-p);return{startingLine:N,totalLines:te,bufferBefore:ne,bufferAfter:Math.max(0,ie)}}};function ts(e){let t;for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===ro&&(t=Math.max(t??0,n.getBoundingClientRect().height));return t}function ns(e){return{...e,hunks:e.hunks.map(e=>({...e,hunkContent:e.hunkContent.map(e=>({...e}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function rs(e){return e===``?[]:e.split(yt)}function is(e,t,n){let r=e===`clone`?ns(t):t;if(!r.isPartial)throw Error(`hydratePartialDiff: fileDiff must be partial`);switch(r.type){case`change`:case`rename-changed`:return as(r,ss(r,n),cs(r,n));case`rename-pure`:{let e=cs(r,n);ls(r,n);let t=rs(e.contents);return r.isPartial=!1,r.deletionLines=t,r.additionLines=t,ds(r,null,e),r}}throw Error(`hydratePartialDiff: ${r.type} diffs cannot be hydrated from loaded files`)}function as(e,t,n){let r=rs(t.contents),i=rs(n.contents),{hunks:a,splitLineCount:o,unifiedLineCount:s}=os(e.hunks,i.length);return e.hunks=a,e.splitLineCount=o,e.unifiedLineCount=s,e.isPartial=!1,e.deletionLines=r,e.additionLines=i,ds(e,t,n),e}function os(e,t){let n=0,r=0,i=0,a=[];for(let t of e){let e=Math.max(t.additionStart-1,0),o=Math.max(t.deletionStart-1,0),s=e,c=o,l=0,u=0,d=0,f=0,p=[];for(let e of t.hunkContent){if(e.type===`context`){p.push({...e,additionLineIndex:s,deletionLineIndex:c}),s+=e.lines,c+=e.lines,d+=e.lines,f+=e.lines;continue}p.push({...e,additionLineIndex:s,deletionLineIndex:c}),s+=e.additions,c+=e.deletions,l+=e.additions,u+=e.deletions,d+=Math.max(e.additions,e.deletions),f+=e.additions+e.deletions}let m=Math.max(Le(t.additionStart,t.additionCount)-i,0);a.push({...t,collapsedBefore:m,additionLineIndex:e,deletionLineIndex:o,additionLines:l,deletionLines:u,hunkContent:p,splitLineStart:n+m,unifiedLineStart:r+m,splitLineCount:d,unifiedLineCount:f}),n+=m+d,r+=m+f,i=Re(t.additionStart,t.additionCount)}if(a.length>0){let e=a[a.length-1],i=Re(e.additionStart,e.additionCount),o=Math.max(t-i,0);n+=o,r+=o}return{hunks:a,splitLineCount:n,unifiedLineCount:r}}function ss(e,t){if(t.oldFile==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function cs(e,t){if(t.newFile==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function ls(e,t){if(t.oldFile!==null)throw Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function us(e,t,n){return e.cacheKey==null?fs(t,n):`${e.cacheKey}:hydrated`}function ds(e,t,n){let r=us(e,t,n);if(r==null){delete e.cacheKey;return}e.cacheKey=r}function fs(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?`${e.cacheKey}:${t.cacheKey}`:void 0:e?.cacheKey??t?.cacheKey}var ps=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&=(this.codeDeletions?.removeEventListener(`scroll`,this.handleDeletionsScroll),this.codeAdditions?.removeEventListener(`scroll`,this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,!1)}setup(e,t,n){if(t==null||n==null)for(let r of e.children??[])r instanceof HTMLElement&&(`deletions`in r.dataset?t=r:`additions`in r.dataset&&(n=r));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener(`scroll`,this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener(`scroll`,this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener(`scroll`,this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener(`scroll`,this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function ms(e){return K({tagName:`div`,properties:{"data-content-buffer":``,"data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function hs(e){return K({tagName:`div`,children:[K({tagName:`span`,children:[Ie(`No newline at end of file`)]})],properties:{"data-no-newline":``,"data-line-type":e,"data-column-content":``}})}function gs(e){return K({tagName:`div`,children:[ct({name:e===`both`?`diffs-icon-expand-all`:`diffs-icon-expand`,properties:{"data-icon":``}})],properties:{role:`button`,"data-expand-button":``,"data-expand-both":e===`both`?``:void 0,"data-expand-up":e===`up`?``:void 0,"data-expand-down":e===`down`?``:void 0}})}function _s({type:e,content:t,expandIndex:n,chunked:r=!1,slotName:i,isFirstHunk:a,isLastHunk:o}){let s=0,c=[];if(e===`metadata`&&t!=null&&c.push(K({tagName:`div`,children:[Ie(t)],properties:{"data-separator-wrapper":``}})),(e===`line-info`||e===`line-info-basic`)&&t!=null){let e=[];n!=null&&(r?(a||(e.push(gs(`up`)),s++),o||(e.push(gs(`down`)),s++)):(e.push(gs(!a&&!o?`both`:a?`down`:`up`)),s++)),e.push(K({tagName:`div`,children:[K({tagName:`span`,children:[Ie(t)],properties:{"data-unmodified-lines":``}})],properties:{"data-separator-content":``}})),r&&n!=null&&e.push(K({tagName:`div`,children:[Ie(`Expand all`)],properties:{role:`button`,"data-expand-button":``,"data-expand-all-button":``}})),c.push(K({tagName:`div`,children:e,properties:{"data-separator-wrapper":``,"data-separator-multi-button":s>1?``:void 0}}))}return e===`custom`&&i!=null&&c.push(K({tagName:`slot`,properties:{name:i}})),K({tagName:`div`,children:c,properties:{"data-separator":c.length===0?`simple`:e,"data-expand-index":n,"data-separator-first":a?``:void 0,"data-separator-last":o?``:void 0}})}function vs(e,t){return`hunk-separator-${e}-${t}`}function ys(e){let t=e.at(-1);return t==null?0:Math.max(Re(t.additionStart,t.additionCount),Re(t.deletionStart,t.deletionCount))}function bs(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function xs(e,t){let n=da({name:e.prevName??e.name,contents:e.deletionLines.join(``)},{name:e.name,contents:e.additionLines.join(``),lang:e.lang},t);return{hunks:n.hunks,splitLineCount:n.splitLineCount,unifiedLineCount:n.unifiedLineCount,additionLines:n.additionLines,deletionLines:n.deletionLines,type:n.type}}function Ss(e,t){let n=Math.max(e,1),r=Array.from({length:n},(e,t)=>`${` `.repeat(t+1)}\n`).join(``);return r===t&&(r=Array.from({length:n},(e,t)=>`\u0000${` `.repeat(t)}\n`).join(``)),r}function Cs(e){for(let t of e)if(t.trim().length>0)return!1;return!0}function ws(e,t){return t.length>0&&t.length<e.deletionLines.length&&Cs(t)}function Ts(e,t,n){let r=e.deletionLines.join(``),i=Ss(t.length,r),a=da({name:e.prevName??e.name,contents:r},{name:e.name,contents:i,lang:e.lang},n);return{hunks:a.hunks,splitLineCount:a.splitLineCount,unifiedLineCount:a.unifiedLineCount,additionLines:t,deletionLines:a.deletionLines,type:a.type}}function Es(e,t){return Ts(e,[``],t)}function Ds(e,t){if(e.additionLines.length===0)return Es(e,t);if(ws(e,e.additionLines))return Ts(e,e.additionLines,t);let n=e.additionLines,r=xs(e,t);return ks(r,n),r}function Os(e){return e.length>1&&e.at(-1)===``}function ks(e,t){if(!Os(t))return;let n=t.length-e.additionLines.length;if(n<=0)return;let r=e.additionLines.length,i=e.hunks.at(-1);if(i!=null&&Re(i.additionStart,i.additionCount)===r){for(let a of i.hunkContent)if(a.type===`change`&&a.additions<a.deletions&&a.additionLineIndex+a.additions===r){e.additionLines=t,a.additions+=n,i.additionCount+=n,i.additionLines+=n,zs(e);return}}}function As(e,t,n){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return js(e,xs(e,n));let r=Array.from(t);if(r.length===0)return js(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(let t of r){let r=e.additionLines[t],i=e.deletionLines[t];if(r==null||i==null||nt(r)===nt(i))return js(e,xs(e,n))}let i=Ms(e,r);if(i.size===0)return js(e,xs(e,n));for(let t of i)if(!Ps(e,t,n))return js(e,xs(e,n));return zs(e),Pe(e)?js(e,xs(e,n)):js(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function js(e,t){return Object.assign(e,t),t}function Ms(e,t){let n=new Set;for(let r of t){let t=Ns(e,r);if(t==null)return new Set;n.add(t)}return n}function Ns(e,t){for(let[n,r]of e.hunks.entries()){let e=r.additionLineIndex+r.additionCount;if(t>=r.additionLineIndex&&t<e)return n}}function Ps(e,t,n){let r=e.hunks[t];if(r==null)return!1;let i=e.deletionLines.slice(r.deletionLineIndex,r.deletionLineIndex+r.deletionCount),a=e.additionLines.slice(r.additionLineIndex,r.additionLineIndex+r.additionCount),o=da({name:e.prevName??e.name,contents:i.join(``)},{name:e.name,contents:a.join(``),lang:e.lang},{...n,context:0}),s=o.hunks[0];return s==null||o.hunks.length!==1?!1:(Is(r,s),Fs(e,t),!0)}function Fs(e,t){let n=e.hunks[t];if(n==null)return;if(t!==e.hunks.length-1){n.noEOFCRAdditions=!1,n.noEOFCRDeletions=!1;return}let r=e.additionLines.at(-1),i=e.deletionLines.at(-1);n.noEOFCRAdditions=r!=null&&r!==``&&!r.endsWith(`
1358
1358
  `),n.noEOFCRDeletions=i!=null&&i!==``&&!i.endsWith(`
1359
- `)}function Is(e,t){let n=e.additionLineIndex,r=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(e=>Ls(e,n,r)),e.additionLineIndex=n+t.additionLineIndex,e.additionStart+=t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=r+t.deletionLineIndex,e.deletionStart+=t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Rs(e)}function Ls(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function Rs(e){let t=0,n=0;for(let r of e.hunkContent)r.type===`context`?(t+=r.lines,n+=r.lines):(t+=Math.max(r.additions,r.deletions),n+=r.additions+r.deletions);e.splitLineCount=t,e.unifiedLineCount=n}function zs(e){let t=0,n=0,r=0;for(let i of e.hunks)i.collapsedBefore=Math.max(Le(i.additionStart,i.additionCount)-r,0),i.splitLineStart=t+i.collapsedBefore,i.unifiedLineStart=n+i.collapsedBefore,Rs(i),t+=i.collapsedBefore+i.splitLineCount,n+=i.collapsedBefore+i.unifiedLineCount,r=Re(i.additionStart,i.additionCount);if(e.hunks.length>0){let r=e.hunks[e.hunks.length-1],i=Math.max(e.additionLines.length-Re(r.additionStart,r.additionCount),0);t+=i,n+=i}e.splitLineCount=t,e.unifiedLineCount=n}var Bs=new WeakMap;function Vs(e){return e.length>1&&e[e.length-1]===``?e.slice(0,-1):e}function Hs(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;if(r!==i||r!==a)return{start:r,deletionEnd:i,additionEnd:a}}function Us(e,t){let n=e.hunks,r=e.additionLines,i=Vs(r),a=i===r?e:{...e,additionLines:i},o=$s(n,Qs(a,t),e.deletionLines.length),s=nc(a,o);if(e.additionLines=i,e.hunks=s,e.editSessionDirty=!0,fc(e),ks(e,r),ac(n,e.hunks))return{regions:o.map(e=>e.previousSpan)}}function Ws(e,t,n,r){let i=Array.from(new Set(t)).filter(t=>t>=0&&t<e.additionLines.length).sort((e,t)=>e-t);if(i.length===0)return;let{hunks:a}=e,o,s=0;for(let t of i){for(;s<a.length;){let e=a[s];if(t<cc(e)+e.additionCount)break;s++}let r=a[s],i=r==null?void 0:cc(r);if(i==null||t<i||o!=null&&o!==s)return Us(e,n);o=s}if(o!=null){if(Gs(e,i,o,r,n)){e.editSessionDirty=!0;return}return Us(e,n)}}function Gs(e,t,n,r,i){if(r==null||i?.ignoreWhitespace===!0||i?.stripTrailingCr===!0)return!1;let a=Ks(e),o=e.hunks[n];if(o.hunkContent.some(qs))return!1;for(let n of t){let t=r.get(n),i=e.additionLines[n];if(t==null||i==null||a.has(t)||a.has(i))return!1;let s=!1;for(let e of o.hunkContent)if(e.type===`change`&&e.additions===e.deletions&&n>=e.additionLineIndex&&n<e.additionLineIndex+e.additions){s=!0;break}if(!s)return!1}return!0}function Ks(e){let t=Bs.get(e);if(t?.lines===e.deletionLines)return t.set;let n=new Set(e.deletionLines);return Bs.set(e,{lines:e.deletionLines,set:n}),n}function qs(e){return e?.type===`change`&&(e.additions===0||e.deletions===0)}function Js(e,t){let n=new Map,{regions:r}=t;for(let t=0;t<=r.length;t++){let i=r[t-1],a=r[t],o=t===0?e.get(0):i==null?void 0:e.get(i.lastIndex+1),s=a==null?void 0:e.get(a.firstIndex),c=o?.fromStart??0,l=s?.fromEnd??0;(c>0||l>0)&&n.set(t,{fromStart:c,fromEnd:l})}return n}function Ys(e,t,n){let r=[];if(e.isPartial)return r;for(let[i,a]of e.hunks.entries()){let o=et({isPartial:e.isPartial,rangeSize:a.collapsedBefore,expandedHunks:t,hunkIndex:i,collapsedContextThreshold:n});if(o.rangeSize<=n)continue;let s=lc(a),c=s-o.rangeSize;o.fromStart>0&&r.push([c,c+o.fromStart]),o.fromEnd>0&&r.push([s-o.fromEnd,s])}let i=st({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:`captureExpansionAnchors`});if(i!=null&&i.fromStart>0&&i.rangeSize>n){let t=e.hunks[e.hunks.length-1],n=lc(t)+t.deletionCount;r.push([n,n+i.fromStart])}return r}function Xs(e,t){let n=new Map;if(t.length===0)return n;let r=(e,r,i)=>{if(i<=r)return;let a=0,o=0;for(let[e,n]of t)n<=r||e>=i||(e<=r&&(a=Math.max(a,Math.min(n,i)-r)),n>=i&&(o=Math.max(o,i-Math.max(e,r))));(a>0||o>0)&&n.set(e,{fromStart:a,fromEnd:o})};for(let[t,n]of e.hunks.entries()){let e=lc(n);r(t,e-Math.max(n.collapsedBefore,0),e)}let i=e.hunks[e.hunks.length-1];return i!=null&&!e.isPartial&&e.deletionLines.length>0&&r(e.hunks.length,lc(i)+i.deletionCount,e.deletionLines.length),n}function Zs(e,t){return e.editSessionDirty===!0&&(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join(``)===``?xs(e,t):Ds(e,t)),!0)}function Qs(e,t){if(Hs(e.deletionLines,e.additionLines)==null)return[];let n=da({name:e.prevName??e.name,contents:e.deletionLines.join(``)},{name:e.name,contents:e.additionLines.join(``),lang:e.lang},t),r=[],i=0,a=0;for(let e of n.hunks){let t=e.additionCount>0?e.additionLineIndex-i:e.deletionLineIndex-a;i+=t,a+=t;for(let t of e.hunkContent){if(t.type===`context`){i+=t.lines,a+=t.lines;continue}let e=Ls(t,0,0);e.additions===0&&(e.additionLineIndex=i),e.deletions===0&&(e.deletionLineIndex=a),r.push(e),i+=e.additions,a+=e.deletions}}return r}function $s(e,t,n){let r=e.map((e,t)=>{let n=lc(e);return{deletionStart:n,deletionEnd:n+e.deletionCount,blocks:[],previousSpan:{firstIndex:t,lastIndex:t}}}),i=[],a=0;for(let e of t){let t=e.deletionLineIndex,o=t+e.deletions;for(;a<r.length&&r[a].deletionEnd<t;)i.push(r[a]),a++;let s=i.length>0&&ec(t,o,i[i.length-1])?i.pop():void 0;for(;a<r.length&&r[a].deletionStart<=o;)s=tc(s,r[a]),a++;if(s==null){let c=t,l=o;if((e.deletions===0||e.additions===0)&&n>e.deletions){let e=i[i.length-1]?.deletionEnd??0,s=r[a]?.deletionStart??n;t>e?c--:o<s&&l++}s={deletionStart:c,deletionEnd:l,blocks:[],previousSpan:void 0}}s.deletionStart=Math.min(s.deletionStart,t),s.deletionEnd=Math.max(s.deletionEnd,o),s.blocks.push(e),i.push(s)}for(;a<r.length;)i.push(r[a]),a++;return i}function ec(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function tc(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function nc(e,t){let n=[],r=0,i=0;for(let a of t){let t=a.deletionStart-r;if(t<0)throw Error(`buildRegionHunks: overlapping old-side regions`);r+=t,i+=t;let o=i,s=[];for(let e of a.blocks){let t=e.deletionLineIndex-r,n=e.additionLineIndex-i;if(t<0||t!==n)throw Error(`buildRegionHunks: canonical block context mismatch`);ic(s,t,i,r),r+=t,i+=n,s.push({...e}),r+=e.deletions,i+=e.additions}let c=a.deletionEnd-r;if(c<0)throw Error(`buildRegionHunks: block exceeds its old-side region`);ic(s,c,i,r),r+=c,i+=c,n.push(rc(e,{additionStart:o,additionEnd:i,deletionStart:a.deletionStart,deletionEnd:a.deletionEnd},s))}if(e.deletionLines.length-r!==e.additionLines.length-i)throw Error(`buildRegionHunks: trailing context mismatch`);return n}function rc(e,t,n){let r=t.additionEnd-t.additionStart,i=t.deletionEnd-t.deletionStart,a=0,o=0;for(let e of n)e.type===`change`&&(a+=e.additions,o+=e.deletions);let s={collapsedBefore:0,additionStart:uc(t.additionStart,r),additionCount:r,additionLines:a,additionLineIndex:dc(t.additionStart,r),deletionStart:uc(t.deletionStart,i),deletionCount:i,deletionLines:o,deletionLineIndex:dc(t.deletionStart,i),hunkContent:n,hunkSpecs:`@@ -${uc(t.deletionStart,i)},${i} +${uc(t.additionStart,r)},${r} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return Rs(s),s}function ic(e,t,n,r){t>0&&e.push({type:`context`,lines:t,additionLineIndex:n,deletionLineIndex:r})}function ac(e,t){if(e.length!==t.length)return!0;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(lc(r)!==lc(i)||r.deletionCount!==i.deletionCount||cc(r)!==cc(i)||r.additionCount!==i.additionCount||r.splitLineCount!==i.splitLineCount||!oc(r,i))return!0}return!1}function oc(e,t){let n=sc(e),r=sc(t);for(;;){let e=n.next(),t=r.next();if(e.done===!0||t.done===!0)return e.done===t.done;if(e.value[0]!==t.value[0]||e.value[1]!==t.value[1])return!1}}function*sc(e){for(let t of e.hunkContent){if(t.type===`context`){for(let e=0;e<t.lines;e++)yield[t.deletionLineIndex+e,t.additionLineIndex+e];continue}let e=Math.max(t.deletions,t.additions);for(let n=0;n<e;n++)yield[n<t.deletions?t.deletionLineIndex+n:void 0,n<t.additions?t.additionLineIndex+n:void 0]}}function cc(e){return Le(e.additionStart,e.additionCount)}function lc(e){return Le(e.deletionStart,e.deletionCount)}function uc(e,t){return t===0?e:e+1}function dc(e,t){return t===0?e-1:e}function fc(e){zs(e);for(let t=0;t<e.hunks.length;t++)Fs(e,t)}var pc=-1,mc=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++pc}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang=`text`;renderCache;editSessionActive=!1;constructor(e={theme:K},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=Ga(e.theme??K)?kt():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this),this.endEditSession()}beginEditSession(){this.editSessionActive=!0;let e=this.diffCache;e!=null&&!e.isPartial&&e.additionLines.length===0&&(Object.assign(e,Es(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache())}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){let{renderCache:e}=this;if(e==null||Me(e.diff)||kc(e.diff,this.getTokenizeMaxLength()))return Promise.resolve();let{diff:t}=e,{workerManager:n}=this;return!this.editSessionActive&&n?.isWorkingPool()===!0&&t.cacheKey!=null?(n.evictDiffFromCache(t.cacheKey),n.primeDiffHighlightCache(t).then(()=>{this.applyRefreshedResult(t,n.getDiffResultCache(t))}).catch(e=>this.onHighlightError(e))):this.asyncHighlight(t).then(e=>this.applyRefreshedResult(t,e)).catch(e=>this.onHighlightError(e))}applyRefreshedResult(e,t){if(t==null||this.renderCache==null||this.renderCache.diff!==e||this.editSessionActive)return;let{options:n}=this.getRenderOptions(e);He(n,t.options)&&(this.renderCache={diff:e,options:t.options,highlighted:!0,result:t.result,renderRange:void 0},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,n=this.getOptionsWithDefaults().expansionLineCount){let r={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t===`up`||t===`both`)&&(r.fromStart+=n),(t===`down`||t===`both`)&&(r.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,r)}getExpandedHunk(e){return this.expandedHunks.get(e)??tt}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(let t of e){let e=(()=>{switch(t.side){case`deletions`:return this.deletionAnnotations;case`additions`:return this.additionAnnotations}})(),n=e[t.lineNumber]??[];e[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,n=!1){if(this.renderCache==null)return!1;let{result:r,diff:i}=this.renderCache;if(r==null)return!1;if(i.isPartial)throw Error(`Could not update render cache for partial diff`);let a=r.code.additionLines,o=[],s=new Map;for(let[t,n]of e){let e=a[t]?.properties??{},r=n.map(e=>e[2]).join(``),c=t<i.additionLines.length,l=c?i.additionLines[t]??``:``,u=nt(l);c&&(i.additionLines[t]=so(l,r),u!==r&&(o.push(t),s.set(t,l))),a[t]={type:`element`,tagName:`div`,properties:{"data-line":e[`data-line`]??t+1,"data-line-index":e[`data-line-index`]??t,"data-line-type":e[`data-line-type`]??`context`},children:n.map(([e,t,n])=>e===0&&t===``?n===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:n}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`color:${t};`},children:[{type:`text`,value:n}]})}}let c=!1;if(o.length>0){if(this.editSessionActive&&!i.isPartial){if(!n){if(i.additionLines.length<=1&&i.additionLines.join(``)===``)Object.assign(i,Es(i,this.options.parseDiffOptions)),this.markEditSessionPass(i),c=!0;else if(ws(i,i.additionLines))Object.assign(i,Ts(i,i.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(i),c=!0;else{let e=Ws(i,o,this.options.parseDiffOptions,s);this.applyExpansionRemap(e),c=e!=null}}}else Object.assign(i,As(i,o,this.options.parseDiffOptions))}return r.baseThemeType=t,this.renderCache.isDirty=!0,c}applyExpansionRemap(e){e!=null&&(this.expandedHunks=Js(this.expandedHunks,e))}applyDocumentChange(e){if(this.renderCache==null)return;let{diff:t,result:n}=this.renderCache;if(n==null)return;if(t.isPartial)throw Error(`Could not apply document change for partial diff`);let{additionLines:r}=t;t.additionLines=Ec(e,r),n.code.additionLines=wc(r,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join(``)===``?(Object.assign(t,Es(t,this.options.parseDiffOptions)),n.code.additionLines[0]=Tc(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,Ds(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){let{parseDiffOptions:t}=this.options,n=e.additionLines;if(ws(e,n)){Object.assign(e,Ts(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(Us(e,t))}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){let n=t===`change`?e===`deletions`?`change-deletion`:`change-addition`:t;return{gutterLineType:n,contentProperties:{"data-line-type":n}}}createAnnotationElement=e=>qa(e);getOptionsWithDefaults(){let{diffIndicators:e=`bars`,diffStyle:t=`split`,disableBackground:n=!1,disableFileHeader:r=!1,disableLineNumbers:i=!1,disableVirtualizationBuffers:a=!1,collapsed:o=!1,expandUnchanged:s=!1,collapsedContextThreshold:c=1,expansionLineCount:l=100,hunkSeparators:u=`line-info`,lineDiffType:d=`word-alt`,maxLineDiffLength:f=1e3,overflow:p=`scroll`,stickyHeader:m=!1,theme:h=K,headerRenderMode:g=`default`,tokenizeMaxLineLength:_=1e3,tokenizeMaxLength:v=Ge,useTokenTransformer:y=!1,useCSSClasses:b=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:r,disableLineNumbers:i,disableVirtualizationBuffers:a,collapsed:o,expandUnchanged:s,collapsedContextThreshold:c,expansionLineCount:l,hunkSeparators:u,lineDiffType:d,maxLineDiffLength:f,overflow:p,stickyHeader:m,theme:this.workerManager?.getDiffRenderOptions().theme??h,headerRenderMode:g,tokenizeMaxLineLength:_,tokenizeMaxLength:v,useTokenTransformer:y,useCSSClasses:b}}async initializeHighlighter(){return this.highlighter=await Mt(eo(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;let{options:t}=this.getRenderOptions(e),n=kc(e,this.getTokenizeMaxLength()),r=this.workerManager?.getDiffResultCache(e);r!=null&&!He(t,r.options)&&(r=void 0),this.renderCache??={diff:e,highlighted:!n&&!Me(e),options:t,result:n?void 0:r?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter??(this.computedLang=e.lang??on(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??K}getEffectiveCodeOptions(){let e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0){let e=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&e.useTokenTransformer!==!0?{...e,useTokenTransformer:!0}:e}let{theme:e,tokenizeMaxLineLength:t,lineDiffType:n,maxLineDiffLength:r}=this.getOptionsWithDefaults();return{theme:e,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:t,lineDiffType:n,maxLineDiffLength:r}})();this.getOptionsWithDefaults();let{renderCache:n}=this;return n?.result==null||!dt(e,n.diff)||!He(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=it){if(e==null)return;let{expandUnchanged:n,collapsedContextThreshold:r}=this.getOptionsWithDefaults(),{options:i,forceHighlight:a}=this.getRenderOptions(e),o=this.getMatchingWorkerResultCache(e,i);o!=null&&!this.hasHighlightedRenderCache(e,i)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},a=!1),this.renderCache??={diff:e,highlighted:!1,options:i,result:void 0,renderRange:void 0};let s=e.additionLines.length>0||e.deletionLines.length>0,c=!s||Me(e)||kc(e,this.getTokenizeMaxLength()),l=!dt(e,this.renderCache.diff),u=!Ka(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){let o=this.renderCache.result==null&&this.renderCache.highlighted&&!c&&!l&&bs(t);o&&(this.renderCache.highlightPending=!0),!o&&(c||this.renderCache.result==null||!this.renderCache.highlighted&&(l||u))&&(this.renderCache.diff=e,this.renderCache.options=i,this.renderCache.highlighted=!1,(this.renderCache.result==null||l||u||a)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,bs(t)||n?!0:this.expandedHunks,r)),this.renderCache.renderRange=t),!c&&s&&(!this.renderCache.highlighted||a)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLang=e.lang??on(e.name);let t=this.highlighter!=null&&Ga(i.theme),n=this.highlighter!=null&&Wa(this.computedLang),r=!c&&n;if(this.highlighter!=null&&t&&(a||c||!this.renderCache.highlighted&&r||this.renderCache.result==null)){let{result:t,options:i}=this.renderDiffWithHighlighter(e,this.highlighter,c||!n);this.renderCache={diff:e,options:i,highlighted:r,result:t,renderRange:void 0}}(!t||!c&&!n)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,t,n,!c)})}return this.renderCache.result==null?void 0:this.processDiffResult(this.renderCache.diff,t,this.renderCache.result)}async asyncRender(e,t=it){let{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){let{diffIndicators:r,disableBackground:i,disableLineNumbers:a,overflow:o}=this.getOptionsWithDefaults();return Qa({type:`diff`,diffIndicators:r,disableBackground:i,disableLineNumbers:a,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){let t=kc(e,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??on(e.name);let n=this.highlighter!=null&&Ga(this.getLocalHighlightTheme()),r=t||this.highlighter!=null&&Wa(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e),{collapsedContextThreshold:i}=this.getOptionsWithDefaults(),a=zt(e,t,r,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:i});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===``&&a.code.additionLines[0]==null){let t;if(Qe({diff:e,diffStyle:`both`,expandedHunks:n?!0:void 0,collapsedContextThreshold:i,callback:({additionLine:e})=>{if(e?.lineIndex===0)return t=e,!0}}),t==null)throw Error(`DiffHunksRenderer: missing empty addition line`);a.code.additionLines[0]=Tc(0,``,t.unifiedLineIndex,t.splitLineIndex)}return{result:a,options:r}}onHighlightSuccess(e,t,n,r=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,r)}applyHighlightResult(e,t,n,r=!0){if(this.renderCache==null)return;let i=this.renderCache.highlightPending===!0||!this.renderCache.highlighted||!He(this.renderCache.options,n)||!dt(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;let n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!He(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&dt(e,n.diff)&&He(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let{diffStyle:a,disableFileHeader:o,expandUnchanged:s,expansionLineCount:c,collapsedContextThreshold:l,hunkSeparators:u}=this.getOptionsWithDefaults(),d=this.renderCache?.isDirty??!1;this.diff=e;let f=a===`unified`,p=Ac(e,this.options.loadDiffFiles!=null),m=!e.isPartial||p,h=[],g=[],_=[],v=[],{additionLines:y,deletionLines:b}=n,x={rowCount:0,hunkSeparators:u,additionsContentAST:h,deletionsContentAST:g,unifiedContentAST:_,unifiedGutterAST:Tt(),deletionsGutterAST:Tt(),additionsGutterAST:Tt(),expansionLineCount:c,hunkData:v,incrementRowCount(e=1){x.rowCount+=e},pushToGutter(e,t){switch(e){case`unified`:x.unifiedGutterAST.children.push(t);break;case`deletions`:x.deletionsGutterAST.children.push(t);break;case`additions`:x.additionsGutterAST.children.push(t)}}},S=Xe({fileDiff:e,errorPrefix:`DiffHunksRenderer.processDiffResult`}),C={size:0,side:void 0,increment(){this.size+=1},flush(){if(a!==`unified`){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side===`additions`?(x.pushToGutter(`additions`,fn(void 0,`buffer`,this.size)),h?.push(ms(this.size))):(x.pushToGutter(`deletions`,fn(void 0,`buffer`,this.size)),g?.push(ms(this.size))),this.size=0,this.side=void 0}}},w=(e,t,n,r,i)=>{x.pushToGutter(e,mn(t,n,r,i))};function T(e){C.flush(),a===`unified`?xc(`unified`,e,x):(xc(`deletions`,e,x),xc(`additions`,e,x))}this.pushFileLevelAnnotations(e,a,t,x),Qe({diff:e,diffStyle:a,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:s?!0:this.expandedHunks,collapsedContextThreshold:l,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,additionLine:o,deletionLine:s,type:c})=>{let l=s==null?o.splitLineIndex:s.splitLineIndex,f=o==null?s.unifiedLineIndex:o.unifiedLineIndex;a===`split`&&c!==`change`&&C.flush(),r>0&&T({hunkIndex:t,collapsedLines:r,rangeSize:Math.max(n?.collapsedBefore??0,0),hunkSpecs:n?.hunkSpecs,isFirstHunk:t===0,isLastHunk:!1,isExpandable:m});let h=a===`unified`?f:l,g={type:c,hunkIndex:t,lineIndex:h,unifiedLineIndex:f,splitLineIndex:l,deletionLine:s,additionLine:o};if(a===`unified`){let n=this.getUnifiedInjectedRowsForLine?.(g);n?.before!=null&&vc(n.before,x);let r=s==null?void 0:b[s.lineIndex],i=o==null?void 0:y[o.lineIndex];if(r==null&&i==null){let t=`DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong`;throw console.error(t,{file:e.name}),Error(t)}let a=c===`change`?o==null?`change-deletion`:`change-addition`:c,u=this.getUnifiedLineDecoration({type:c,lineType:a,additionLineIndex:o?.lineIndex,deletionLineIndex:s?.lineIndex});w(`unified`,u.gutterLineType,o==null?s.lineNumber:o.lineNumber,`${f},${l}`,u.gutterProperties),i==null?r!=null&&(r=Sc(r,u.contentProperties,d&&s!=null?{"data-line":s.lineNumber,"data-line-index":`${f},${l}`}:void 0)):i=Sc(i,u.contentProperties,d&&o!=null?{"data-line":o.lineNumber,"data-line-index":`${f},${l}`}:void 0),bc({diffStyle:`unified`,type:c,deletionLine:r,additionLine:i,unifiedSpan:this.getAnnotations(`unified`,s?.lineNumber,o?.lineNumber,t,h),createAnnotationElement:e=>this.createAnnotationElement(e),context:x}),n?.after!=null&&vc(n.after,x)}else{let n=this.getSplitInjectedRowsForLine?.(g);n?.before!=null&&yc(n.before,x,C);let r=s==null?void 0:b[s.lineIndex],i=o==null?void 0:y[o.lineIndex],a=this.getSplitLineDecoration({side:`deletions`,type:c,lineIndex:s?.lineIndex}),u=this.getSplitLineDecoration({side:`additions`,type:c,lineIndex:o?.lineIndex});if(r==null&&i==null){let t=`DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong`;throw console.error(t,{file:e.name}),Error(t)}let f=(()=>{if(c===`change`){if(i==null)return`additions`;if(r==null)return`deletions`}})();f==null?c===`change`&&C.flush():(C.side!=null&&C.side!==f&&C.flush(),C.side=f,C.increment());let p=this.getAnnotations(`split`,s?.lineNumber,o?.lineNumber,t,h);if(p!=null&&C.size>0&&C.flush(),s!=null){let e=Sc(r,a.contentProperties,d?{"data-line":s.lineNumber,"data-line-index":`${s.unifiedLineIndex},${l}`}:void 0);w(`deletions`,a.gutterLineType,s.lineNumber,`${s.unifiedLineIndex},${l}`,a.gutterProperties),e!=null&&(r=e)}if(o!=null){let e=Sc(i,u.contentProperties,d?{"data-line":o.lineNumber,"data-line-index":`${o.unifiedLineIndex},${l}`}:void 0);w(`additions`,u.gutterLineType,o.lineNumber,`${o.unifiedLineIndex},${l}`,u.gutterProperties),e!=null&&(i=e)}bc({diffStyle:`split`,type:c,additionLine:i,deletionLine:r,...p,createAnnotationElement:e=>this.createAnnotationElement(e),context:x}),n?.after!=null&&yc(n.after,x,C)}let _=a===`split`&&n!=null&&l===n.splitLineStart+n.splitLineCount-1,v=t===e.hunks.length-1&&n!=null&&(a===`split`?l===n.splitLineStart+n.splitLineCount-1:f===n.unifiedLineStart+n.unifiedLineCount-1),E=_?n.noEOFCRDeletions:!1,D=_?n.noEOFCRAdditions:!1,O=(s?.noEOFCR??!1)||E,k=(o?.noEOFCR??!1)||D;if(k||O){if(a===`split`&&C.flush(),O){let e=c===`context`||c===`context-expanded`?c:`change-deletion`;a===`unified`?(x.unifiedContentAST.push(hs(e)),x.pushToGutter(`unified`,fn(e,`metadata`,1))):(x.deletionsContentAST.push(hs(e)),x.pushToGutter(`deletions`,fn(e,`metadata`,1)),k||(x.pushToGutter(`additions`,fn(void 0,`buffer`,1)),x.additionsContentAST.push(ms(1))))}if(k){let e=c===`context`||c===`context-expanded`?c:`change-addition`;a===`unified`?(x.unifiedContentAST.push(hs(e)),x.pushToGutter(`unified`,fn(e,`metadata`,1))):(x.additionsContentAST.push(hs(e)),x.pushToGutter(`additions`,fn(e,`metadata`,1)),O||(x.pushToGutter(`deletions`,fn(void 0,`buffer`,1)),x.deletionsContentAST.push(ms(1))))}x.incrementRowCount(1)}u!==`simple`&&u!==`metadata`&&(i>0||v&&p)&&T({hunkIndex:c===`context-expanded`?t:t+1,collapsedLines:v&&p?`unknown`:i,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:m}),x.incrementRowCount(1)}}),a===`split`&&C.flush();let E=Math.max(ys(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),D=t.bufferBefore>0||t.bufferAfter>0,O=!f&&e.type!==`deleted`,k=!f&&e.type!==`new`,A=x.rowCount>0||D;h=O&&A?h:void 0,g=k&&A?g:void 0,_=f&&A?_:void 0;let j=this.createPreElement(g!=null&&h!=null,E);return{unifiedGutterAST:f&&A?x.unifiedGutterAST.children:void 0,unifiedContentAST:_,deletionsGutterAST:k&&A?x.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:O&&A?x.additionsGutterAST.children:void 0,additionsContentAST:h,hunkData:v,preNode:j,themeStyles:r,baseThemeType:i,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:E,rowCount:x.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderCodeAST(e,t){let n=e===`unified`?t.unifiedGutterAST:e===`deletions`?t.deletionsGutterAST:t.additionsGutterAST,r=e===`unified`?t.unifiedContentAST:e===`deletions`?t.deletionsContentAST:t.additionsContentAST;if(n==null||r==null)return;let i=Tt(n);return i.properties.style=`grid-row: span ${t.rowCount}`,[i,co(r,t.rowCount)]}renderFullAST(e,t=[]){let n=this.getOptionsWithDefaults().hunkSeparators===`line-info`,r=this.renderCodeAST(`unified`,e);if(r!=null)return t.push(q({tagName:`code`,children:r,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-unified":``}})),{...e.preNode,children:t};let i=this.renderCodeAST(`deletions`,e);i!=null&&t.push(q({tagName:`code`,children:i,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-deletions":``}}));let a=this.renderCodeAST(`additions`,e);return a!=null&&t.push(q({tagName:`code`,children:a,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-additions":``}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return Ct(this.renderFullAST(e,t))}renderPartialHTML(e,t){return Ct(t==null?e:q({tagName:`code`,children:e,properties:{"data-code":``,"data-container-size":this.getOptionsWithDefaults().hunkSeparators===`line-info`?``:void 0,[`data-${t}`]:``}}))}pushFileLevelAnnotations(e,t,n,r){if(!oo(n))return;let i=e.type===`new`?[]:hc(ao(this.deletionAnnotations)),a=e.type===`deleted`?[]:hc(ao(this.additionAnnotations));if(i.length===0&&a.length===0)return;let{createAnnotationElement:o}=this;if(t===`unified`){bc({diffStyle:t,type:`context`,unifiedSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:i.concat(a)},createAnnotationElement:o,context:r});return}bc({diffStyle:t,type:`context`,deletionSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:i},additionSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:a},createAnnotationElement:o,context:r})}getAnnotations(e,t,n,r,i){let a={type:`annotation`,hunkIndex:r,lineIndex:i,annotations:[]};if(t!=null)for(let e of this.deletionAnnotations[t]??[])a.annotations.push(to(e));let o={type:`annotation`,hunkIndex:r,lineIndex:i,annotations:[]};if(n!=null)for(let t of this.additionAnnotations[n]??[])(e===`unified`?a:o).annotations.push(to(t));if(e===`unified`)return a.annotations.length>0?a:void 0;if(o.annotations.length!==0||a.annotations.length!==0)return{deletionSpan:a,additionSpan:o}}renderHeader(e){let{headerRenderMode:t,stickyHeader:n}=this.getOptionsWithDefaults();return Ya({fileOrDiff:e,mode:t,stickyHeader:n})}};function hc(e){return e?.map(e=>to(e))??[]}var gc=new Intl.PluralRules(`en-US`);function _c(e){return`${e} unmodified line${gc.select(e)===`one`?``:`s`}`}function vc(e,t){for(let n of e)t.unifiedContentAST.push(n.content),t.pushToGutter(`unified`,n.gutter),t.incrementRowCount(1)}function yc(e,t,n){for(let{deletion:r,addition:i}of e){if(r==null&&i==null)continue;let e=r!=null&&i!=null?void 0:r==null?`deletions`:`additions`;(e==null||n.side!==e)&&n.flush(),r!=null&&(t.deletionsContentAST.push(r.content),t.pushToGutter(`deletions`,r.gutter)),i!=null&&(t.additionsContentAST.push(i.content),t.pushToGutter(`additions`,i.gutter)),e!=null&&(n.side=e,n.increment()),t.incrementRowCount(1)}}function bc({diffStyle:e,type:t,deletionLine:n,additionLine:r,unifiedSpan:i,deletionSpan:a,additionSpan:o,createAnnotationElement:s,context:c}){let l=!1;if(e===`unified`){if(r==null?n!=null&&c.unifiedContentAST.push(n):c.unifiedContentAST.push(r),i!=null){let e=t===`change`?n==null?`change-addition`:`change-deletion`:t;c.unifiedContentAST.push(s(i)),c.pushToGutter(`unified`,fn(e,`annotation`,1)),l=!0}}else if(e===`split`){if(n!=null&&c.deletionsContentAST.push(n),r!=null&&c.additionsContentAST.push(r),a!=null){let e=t===`change`?n==null?`context`:`change-deletion`:t;c.deletionsContentAST.push(s(a)),c.pushToGutter(`deletions`,fn(e,`annotation`,1)),l=!0}if(o!=null){let e=t===`change`?r==null?`context`:`change-addition`:t;c.additionsContentAST.push(s(o)),c.pushToGutter(`additions`,fn(e,`annotation`,1)),l=!0}}l&&c.incrementRowCount(1)}function xc(e,{hunkIndex:t,collapsedLines:n,rangeSize:r,hunkSpecs:i,isFirstHunk:a,isLastHunk:o,isExpandable:s},c){if(typeof n==`number`&&n<=0)return;let l=e===`unified`?c.unifiedContentAST:e===`deletions`?c.deletionsContentAST:c.additionsContentAST;if(c.hunkSeparators===`metadata`){i!=null&&(c.pushToGutter(e,_s({type:`metadata`,content:i,isFirstHunk:a,isLastHunk:o})),l.push(_s({type:`metadata`,content:i,isFirstHunk:a,isLastHunk:o})),e!==`additions`&&c.incrementRowCount(1));return}if(c.hunkSeparators===`simple`){t>0&&(c.pushToGutter(e,_s({type:`simple`,isFirstHunk:a,isLastHunk:!1})),l.push(_s({type:`simple`,isFirstHunk:a,isLastHunk:!1})),e!==`additions`&&c.incrementRowCount(1));return}let u=vs(e,t),d=r>c.expansionLineCount,f=s?t:void 0,p=typeof n==`number`?_c(n):`More unchanged context may be available`;c.pushToGutter(e,_s({type:c.hunkSeparators,content:p,expandIndex:f,chunked:d,slotName:u,isFirstHunk:a,isLastHunk:o})),l.push(_s({type:c.hunkSeparators,content:p,expandIndex:f,chunked:d,slotName:u,isFirstHunk:a,isLastHunk:o})),e!==`additions`&&c.incrementRowCount(1),c.hunkData.push({slotName:u,hunkIndex:t,lines:typeof n==`number`?n:0,lineCountKnown:typeof n==`number`,type:e,expandable:s?{up:!a,down:!o,chunked:d}:void 0})}function Sc(e,t,n){return e==null||e.type!==`element`||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Cc(e){return e.length>0&&e[e.length-1]===``?e.length-1:e.length}function wc(e,t,n,r){let i=Cc(e),a=Cc(t),o=Math.min(i,a),s=0;for(;s<o&&e[s]===t[s];)s++;let c=0;for(;c<o-s&&e[i-1-c]===t[a-1-c];)c++;let l=Array(t.length);for(let e=0;e<s;e++)l[e]=n[e];for(let e=0;e<c;e++)l[a-1-e]=n[i-1-e];i<e.length&&a<t.length&&(l[t.length-1]=n[e.length-1]);for(let r=e.length;r<t.length;r++)l[r]??=n[r];for(let e=s;e<t.length;e++)l[e]??=Tc(e,r.getLineText(e));return l}function Tc(e,t,n=e,r=e){return{type:`element`,tagName:`div`,properties:{"data-line":e+1,"data-line-index":`${n},${r}`,"data-line-type":`context`},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:t}]}]}}function Ec(e,t){let n=[],r=Oc(t);for(let t=0;t<e.lineCount;t++){let i=e.getLineText(t,!0);n.push(t<e.lineCount-1&&!Dc(i)?i+r:i)}return n}function Dc(e){return e.endsWith(`
1359
+ `)}function Is(e,t){let n=e.additionLineIndex,r=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(e=>Ls(e,n,r)),e.additionLineIndex=n+t.additionLineIndex,e.additionStart+=t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=r+t.deletionLineIndex,e.deletionStart+=t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Rs(e)}function Ls(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function Rs(e){let t=0,n=0;for(let r of e.hunkContent)r.type===`context`?(t+=r.lines,n+=r.lines):(t+=Math.max(r.additions,r.deletions),n+=r.additions+r.deletions);e.splitLineCount=t,e.unifiedLineCount=n}function zs(e){let t=0,n=0,r=0;for(let i of e.hunks)i.collapsedBefore=Math.max(Le(i.additionStart,i.additionCount)-r,0),i.splitLineStart=t+i.collapsedBefore,i.unifiedLineStart=n+i.collapsedBefore,Rs(i),t+=i.collapsedBefore+i.splitLineCount,n+=i.collapsedBefore+i.unifiedLineCount,r=Re(i.additionStart,i.additionCount);if(e.hunks.length>0){let r=e.hunks[e.hunks.length-1],i=Math.max(e.additionLines.length-Re(r.additionStart,r.additionCount),0);t+=i,n+=i}e.splitLineCount=t,e.unifiedLineCount=n}var Bs=new WeakMap;function Vs(e){return e.length>1&&e[e.length-1]===``?e.slice(0,-1):e}function Hs(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;if(r!==i||r!==a)return{start:r,deletionEnd:i,additionEnd:a}}function Us(e,t){let n=e.hunks,r=e.additionLines,i=Vs(r),a=i===r?e:{...e,additionLines:i},o=$s(n,Qs(a,t),e.deletionLines.length),s=nc(a,o);if(e.additionLines=i,e.hunks=s,e.editSessionDirty=!0,fc(e),ks(e,r),ac(n,e.hunks))return{regions:o.map(e=>e.previousSpan)}}function Ws(e,t,n,r){let i=Array.from(new Set(t)).filter(t=>t>=0&&t<e.additionLines.length).sort((e,t)=>e-t);if(i.length===0)return;let{hunks:a}=e,o,s=0;for(let t of i){for(;s<a.length;){let e=a[s];if(t<cc(e)+e.additionCount)break;s++}let r=a[s],i=r==null?void 0:cc(r);if(i==null||t<i||o!=null&&o!==s)return Us(e,n);o=s}if(o!=null){if(Gs(e,i,o,r,n)){e.editSessionDirty=!0;return}return Us(e,n)}}function Gs(e,t,n,r,i){if(r==null||i?.ignoreWhitespace===!0||i?.stripTrailingCr===!0)return!1;let a=Ks(e),o=e.hunks[n];if(o.hunkContent.some(qs))return!1;for(let n of t){let t=r.get(n),i=e.additionLines[n];if(t==null||i==null||a.has(t)||a.has(i))return!1;let s=!1;for(let e of o.hunkContent)if(e.type===`change`&&e.additions===e.deletions&&n>=e.additionLineIndex&&n<e.additionLineIndex+e.additions){s=!0;break}if(!s)return!1}return!0}function Ks(e){let t=Bs.get(e);if(t?.lines===e.deletionLines)return t.set;let n=new Set(e.deletionLines);return Bs.set(e,{lines:e.deletionLines,set:n}),n}function qs(e){return e?.type===`change`&&(e.additions===0||e.deletions===0)}function Js(e,t){let n=new Map,{regions:r}=t;for(let t=0;t<=r.length;t++){let i=r[t-1],a=r[t],o=t===0?e.get(0):i==null?void 0:e.get(i.lastIndex+1),s=a==null?void 0:e.get(a.firstIndex),c=o?.fromStart??0,l=s?.fromEnd??0;(c>0||l>0)&&n.set(t,{fromStart:c,fromEnd:l})}return n}function Ys(e,t,n){let r=[];if(e.isPartial)return r;for(let[i,a]of e.hunks.entries()){let o=et({isPartial:e.isPartial,rangeSize:a.collapsedBefore,expandedHunks:t,hunkIndex:i,collapsedContextThreshold:n});if(o.rangeSize<=n)continue;let s=lc(a),c=s-o.rangeSize;o.fromStart>0&&r.push([c,c+o.fromStart]),o.fromEnd>0&&r.push([s-o.fromEnd,s])}let i=G({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:`captureExpansionAnchors`});if(i!=null&&i.fromStart>0&&i.rangeSize>n){let t=e.hunks[e.hunks.length-1],n=lc(t)+t.deletionCount;r.push([n,n+i.fromStart])}return r}function Xs(e,t){let n=new Map;if(t.length===0)return n;let r=(e,r,i)=>{if(i<=r)return;let a=0,o=0;for(let[e,n]of t)n<=r||e>=i||(e<=r&&(a=Math.max(a,Math.min(n,i)-r)),n>=i&&(o=Math.max(o,i-Math.max(e,r))));(a>0||o>0)&&n.set(e,{fromStart:a,fromEnd:o})};for(let[t,n]of e.hunks.entries()){let e=lc(n);r(t,e-Math.max(n.collapsedBefore,0),e)}let i=e.hunks[e.hunks.length-1];return i!=null&&!e.isPartial&&e.deletionLines.length>0&&r(e.hunks.length,lc(i)+i.deletionCount,e.deletionLines.length),n}function Zs(e,t){return e.editSessionDirty===!0&&(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join(``)===``?xs(e,t):Ds(e,t)),!0)}function Qs(e,t){if(Hs(e.deletionLines,e.additionLines)==null)return[];let n=da({name:e.prevName??e.name,contents:e.deletionLines.join(``)},{name:e.name,contents:e.additionLines.join(``),lang:e.lang},t),r=[],i=0,a=0;for(let e of n.hunks){let t=e.additionCount>0?e.additionLineIndex-i:e.deletionLineIndex-a;i+=t,a+=t;for(let t of e.hunkContent){if(t.type===`context`){i+=t.lines,a+=t.lines;continue}let e=Ls(t,0,0);e.additions===0&&(e.additionLineIndex=i),e.deletions===0&&(e.deletionLineIndex=a),r.push(e),i+=e.additions,a+=e.deletions}}return r}function $s(e,t,n){let r=e.map((e,t)=>{let n=lc(e);return{deletionStart:n,deletionEnd:n+e.deletionCount,blocks:[],previousSpan:{firstIndex:t,lastIndex:t}}}),i=[],a=0;for(let e of t){let t=e.deletionLineIndex,o=t+e.deletions;for(;a<r.length&&r[a].deletionEnd<t;)i.push(r[a]),a++;let s=i.length>0&&ec(t,o,i[i.length-1])?i.pop():void 0;for(;a<r.length&&r[a].deletionStart<=o;)s=tc(s,r[a]),a++;if(s==null){let c=t,l=o;if((e.deletions===0||e.additions===0)&&n>e.deletions){let e=i[i.length-1]?.deletionEnd??0,s=r[a]?.deletionStart??n;t>e?c--:o<s&&l++}s={deletionStart:c,deletionEnd:l,blocks:[],previousSpan:void 0}}s.deletionStart=Math.min(s.deletionStart,t),s.deletionEnd=Math.max(s.deletionEnd,o),s.blocks.push(e),i.push(s)}for(;a<r.length;)i.push(r[a]),a++;return i}function ec(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function tc(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function nc(e,t){let n=[],r=0,i=0;for(let a of t){let t=a.deletionStart-r;if(t<0)throw Error(`buildRegionHunks: overlapping old-side regions`);r+=t,i+=t;let o=i,s=[];for(let e of a.blocks){let t=e.deletionLineIndex-r,n=e.additionLineIndex-i;if(t<0||t!==n)throw Error(`buildRegionHunks: canonical block context mismatch`);ic(s,t,i,r),r+=t,i+=n,s.push({...e}),r+=e.deletions,i+=e.additions}let c=a.deletionEnd-r;if(c<0)throw Error(`buildRegionHunks: block exceeds its old-side region`);ic(s,c,i,r),r+=c,i+=c,n.push(rc(e,{additionStart:o,additionEnd:i,deletionStart:a.deletionStart,deletionEnd:a.deletionEnd},s))}if(e.deletionLines.length-r!==e.additionLines.length-i)throw Error(`buildRegionHunks: trailing context mismatch`);return n}function rc(e,t,n){let r=t.additionEnd-t.additionStart,i=t.deletionEnd-t.deletionStart,a=0,o=0;for(let e of n)e.type===`change`&&(a+=e.additions,o+=e.deletions);let s={collapsedBefore:0,additionStart:uc(t.additionStart,r),additionCount:r,additionLines:a,additionLineIndex:dc(t.additionStart,r),deletionStart:uc(t.deletionStart,i),deletionCount:i,deletionLines:o,deletionLineIndex:dc(t.deletionStart,i),hunkContent:n,hunkSpecs:`@@ -${uc(t.deletionStart,i)},${i} +${uc(t.additionStart,r)},${r} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return Rs(s),s}function ic(e,t,n,r){t>0&&e.push({type:`context`,lines:t,additionLineIndex:n,deletionLineIndex:r})}function ac(e,t){if(e.length!==t.length)return!0;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(lc(r)!==lc(i)||r.deletionCount!==i.deletionCount||cc(r)!==cc(i)||r.additionCount!==i.additionCount||r.splitLineCount!==i.splitLineCount||!oc(r,i))return!0}return!1}function oc(e,t){let n=sc(e),r=sc(t);for(;;){let e=n.next(),t=r.next();if(e.done===!0||t.done===!0)return e.done===t.done;if(e.value[0]!==t.value[0]||e.value[1]!==t.value[1])return!1}}function*sc(e){for(let t of e.hunkContent){if(t.type===`context`){for(let e=0;e<t.lines;e++)yield[t.deletionLineIndex+e,t.additionLineIndex+e];continue}let e=Math.max(t.deletions,t.additions);for(let n=0;n<e;n++)yield[n<t.deletions?t.deletionLineIndex+n:void 0,n<t.additions?t.additionLineIndex+n:void 0]}}function cc(e){return Le(e.additionStart,e.additionCount)}function lc(e){return Le(e.deletionStart,e.deletionCount)}function uc(e,t){return t===0?e:e+1}function dc(e,t){return t===0?e-1:e}function fc(e){zs(e);for(let t=0;t<e.hunks.length;t++)Fs(e,t)}var pc=-1,mc=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++pc}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang=`text`;renderCache;editSessionActive=!1;constructor(e={theme:W},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=Ga(e.theme??W)?Ot():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this),this.endEditSession()}beginEditSession(){this.editSessionActive=!0;let e=this.diffCache;e!=null&&!e.isPartial&&e.additionLines.length===0&&(Object.assign(e,Es(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache())}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){let{renderCache:e}=this;if(e==null||Me(e.diff)||kc(e.diff,this.getTokenizeMaxLength()))return Promise.resolve();let{diff:t}=e,{workerManager:n}=this;return!this.editSessionActive&&n?.isWorkingPool()===!0&&t.cacheKey!=null?(n.evictDiffFromCache(t.cacheKey),n.primeDiffHighlightCache(t).then(()=>{this.applyRefreshedResult(t,n.getDiffResultCache(t))}).catch(e=>this.onHighlightError(e))):this.asyncHighlight(t).then(e=>this.applyRefreshedResult(t,e)).catch(e=>this.onHighlightError(e))}applyRefreshedResult(e,t){if(t==null||this.renderCache==null||this.renderCache.diff!==e||this.editSessionActive)return;let{options:n}=this.getRenderOptions(e);He(n,t.options)&&(this.renderCache={diff:e,options:t.options,highlighted:!0,result:t.result,renderRange:void 0},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,n=this.getOptionsWithDefaults().expansionLineCount){let r={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t===`up`||t===`both`)&&(r.fromStart+=n),(t===`down`||t===`both`)&&(r.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,r)}getExpandedHunk(e){return this.expandedHunks.get(e)??tt}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(let t of e){let e=(()=>{switch(t.side){case`deletions`:return this.deletionAnnotations;case`additions`:return this.additionAnnotations}})(),n=e[t.lineNumber]??[];e[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,n=!1){if(this.renderCache==null)return!1;let{result:r,diff:i}=this.renderCache;if(r==null)return!1;if(i.isPartial)throw Error(`Could not update render cache for partial diff`);let a=r.code.additionLines,o=[],s=new Map;for(let[t,n]of e){let e=a[t]?.properties??{},r=n.map(e=>e[2]).join(``),c=t<i.additionLines.length,l=c?i.additionLines[t]??``:``,u=nt(l);c&&(i.additionLines[t]=so(l,r),u!==r&&(o.push(t),s.set(t,l))),a[t]={type:`element`,tagName:`div`,properties:{"data-line":e[`data-line`]??t+1,"data-line-index":e[`data-line-index`]??t,"data-line-type":e[`data-line-type`]??`context`},children:n.map(([e,t,n])=>e===0&&t===``?n===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:n}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`color:${t};`},children:[{type:`text`,value:n}]})}}let c=!1;if(o.length>0){if(this.editSessionActive&&!i.isPartial){if(!n){if(i.additionLines.length<=1&&i.additionLines.join(``)===``)Object.assign(i,Es(i,this.options.parseDiffOptions)),this.markEditSessionPass(i),c=!0;else if(ws(i,i.additionLines))Object.assign(i,Ts(i,i.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(i),c=!0;else{let e=Ws(i,o,this.options.parseDiffOptions,s);this.applyExpansionRemap(e),c=e!=null}}}else Object.assign(i,As(i,o,this.options.parseDiffOptions))}return r.baseThemeType=t,this.renderCache.isDirty=!0,c}applyExpansionRemap(e){e!=null&&(this.expandedHunks=Js(this.expandedHunks,e))}applyDocumentChange(e){if(this.renderCache==null)return;let{diff:t,result:n}=this.renderCache;if(n==null)return;if(t.isPartial)throw Error(`Could not apply document change for partial diff`);let{additionLines:r}=t;t.additionLines=Ec(e,r),n.code.additionLines=wc(r,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join(``)===``?(Object.assign(t,Es(t,this.options.parseDiffOptions)),n.code.additionLines[0]=Tc(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,Ds(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){let{parseDiffOptions:t}=this.options,n=e.additionLines;if(ws(e,n)){Object.assign(e,Ts(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(Us(e,t))}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){let n=t===`change`?e===`deletions`?`change-deletion`:`change-addition`:t;return{gutterLineType:n,contentProperties:{"data-line-type":n}}}createAnnotationElement=e=>qa(e);getOptionsWithDefaults(){let{diffIndicators:e=`bars`,diffStyle:t=`split`,disableBackground:n=!1,disableFileHeader:r=!1,disableLineNumbers:i=!1,disableVirtualizationBuffers:a=!1,collapsed:o=!1,expandUnchanged:s=!1,collapsedContextThreshold:c=1,expansionLineCount:l=100,hunkSeparators:u=`line-info`,lineDiffType:d=`word-alt`,maxLineDiffLength:f=1e3,overflow:p=`scroll`,stickyHeader:m=!1,theme:h=W,headerRenderMode:g=`default`,tokenizeMaxLineLength:_=1e3,tokenizeMaxLength:v=Ge,useTokenTransformer:y=!1,useCSSClasses:b=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:r,disableLineNumbers:i,disableVirtualizationBuffers:a,collapsed:o,expandUnchanged:s,collapsedContextThreshold:c,expansionLineCount:l,hunkSeparators:u,lineDiffType:d,maxLineDiffLength:f,overflow:p,stickyHeader:m,theme:this.workerManager?.getDiffRenderOptions().theme??h,headerRenderMode:g,tokenizeMaxLineLength:_,tokenizeMaxLength:v,useTokenTransformer:y,useCSSClasses:b}}async initializeHighlighter(){return this.highlighter=await jt(eo(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;let{options:t}=this.getRenderOptions(e),n=kc(e,this.getTokenizeMaxLength()),r=this.workerManager?.getDiffResultCache(e);r!=null&&!He(t,r.options)&&(r=void 0),this.renderCache??={diff:e,highlighted:!n&&!Me(e),options:t,result:n?void 0:r?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter??(this.computedLang=e.lang??an(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??W}getEffectiveCodeOptions(){let e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0){let e=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&e.useTokenTransformer!==!0?{...e,useTokenTransformer:!0}:e}let{theme:e,tokenizeMaxLineLength:t,lineDiffType:n,maxLineDiffLength:r}=this.getOptionsWithDefaults();return{theme:e,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:t,lineDiffType:n,maxLineDiffLength:r}})();this.getOptionsWithDefaults();let{renderCache:n}=this;return n?.result==null||!ut(e,n.diff)||!He(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=it){if(e==null)return;let{expandUnchanged:n,collapsedContextThreshold:r}=this.getOptionsWithDefaults(),{options:i,forceHighlight:a}=this.getRenderOptions(e),o=this.getMatchingWorkerResultCache(e,i);o!=null&&!this.hasHighlightedRenderCache(e,i)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},a=!1),this.renderCache??={diff:e,highlighted:!1,options:i,result:void 0,renderRange:void 0};let s=e.additionLines.length>0||e.deletionLines.length>0,c=!s||Me(e)||kc(e,this.getTokenizeMaxLength()),l=!ut(e,this.renderCache.diff),u=!Ka(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){let o=this.renderCache.result==null&&this.renderCache.highlighted&&!c&&!l&&bs(t);o&&(this.renderCache.highlightPending=!0),!o&&(c||this.renderCache.result==null||!this.renderCache.highlighted&&(l||u))&&(this.renderCache.diff=e,this.renderCache.options=i,this.renderCache.highlighted=!1,(this.renderCache.result==null||l||u||a)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,bs(t)||n?!0:this.expandedHunks,r)),this.renderCache.renderRange=t),!c&&s&&(!this.renderCache.highlighted||a)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLang=e.lang??an(e.name);let t=this.highlighter!=null&&Ga(i.theme),n=this.highlighter!=null&&Wa(this.computedLang),r=!c&&n;if(this.highlighter!=null&&t&&(a||c||!this.renderCache.highlighted&&r||this.renderCache.result==null)){let{result:t,options:i}=this.renderDiffWithHighlighter(e,this.highlighter,c||!n);this.renderCache={diff:e,options:i,highlighted:r,result:t,renderRange:void 0}}(!t||!c&&!n)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,t,n,!c)})}return this.renderCache.result==null?void 0:this.processDiffResult(this.renderCache.diff,t,this.renderCache.result)}async asyncRender(e,t=it){let{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){let{diffIndicators:r,disableBackground:i,disableLineNumbers:a,overflow:o}=this.getOptionsWithDefaults();return Qa({type:`diff`,diffIndicators:r,disableBackground:i,disableLineNumbers:a,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){let t=kc(e,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??an(e.name);let n=this.highlighter!=null&&Ga(this.getLocalHighlightTheme()),r=t||this.highlighter!=null&&Wa(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e),{collapsedContextThreshold:i}=this.getOptionsWithDefaults(),a=Rt(e,t,r,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:i});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===``&&a.code.additionLines[0]==null){let t;if(Qe({diff:e,diffStyle:`both`,expandedHunks:n?!0:void 0,collapsedContextThreshold:i,callback:({additionLine:e})=>{if(e?.lineIndex===0)return t=e,!0}}),t==null)throw Error(`DiffHunksRenderer: missing empty addition line`);a.code.additionLines[0]=Tc(0,``,t.unifiedLineIndex,t.splitLineIndex)}return{result:a,options:r}}onHighlightSuccess(e,t,n,r=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,r)}applyHighlightResult(e,t,n,r=!0){if(this.renderCache==null)return;let i=this.renderCache.highlightPending===!0||!this.renderCache.highlighted||!He(this.renderCache.options,n)||!ut(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;let n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!He(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&ut(e,n.diff)&&He(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let{diffStyle:a,disableFileHeader:o,expandUnchanged:s,expansionLineCount:c,collapsedContextThreshold:l,hunkSeparators:u}=this.getOptionsWithDefaults(),d=this.renderCache?.isDirty??!1;this.diff=e;let f=a===`unified`,p=Ac(e,this.options.loadDiffFiles!=null),m=!e.isPartial||p,h=[],g=[],_=[],v=[],{additionLines:y,deletionLines:b}=n,x={rowCount:0,hunkSeparators:u,additionsContentAST:h,deletionsContentAST:g,unifiedContentAST:_,unifiedGutterAST:wt(),deletionsGutterAST:wt(),additionsGutterAST:wt(),expansionLineCount:c,hunkData:v,incrementRowCount(e=1){x.rowCount+=e},pushToGutter(e,t){switch(e){case`unified`:x.unifiedGutterAST.children.push(t);break;case`deletions`:x.deletionsGutterAST.children.push(t);break;case`additions`:x.additionsGutterAST.children.push(t)}}},S=Xe({fileDiff:e,errorPrefix:`DiffHunksRenderer.processDiffResult`}),C={size:0,side:void 0,increment(){this.size+=1},flush(){if(a!==`unified`){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side===`additions`?(x.pushToGutter(`additions`,dn(void 0,`buffer`,this.size)),h?.push(ms(this.size))):(x.pushToGutter(`deletions`,dn(void 0,`buffer`,this.size)),g?.push(ms(this.size))),this.size=0,this.side=void 0}}},w=(e,t,n,r,i)=>{x.pushToGutter(e,pn(t,n,r,i))};function T(e){C.flush(),a===`unified`?xc(`unified`,e,x):(xc(`deletions`,e,x),xc(`additions`,e,x))}this.pushFileLevelAnnotations(e,a,t,x),Qe({diff:e,diffStyle:a,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:s?!0:this.expandedHunks,collapsedContextThreshold:l,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,additionLine:o,deletionLine:s,type:c})=>{let l=s==null?o.splitLineIndex:s.splitLineIndex,f=o==null?s.unifiedLineIndex:o.unifiedLineIndex;a===`split`&&c!==`change`&&C.flush(),r>0&&T({hunkIndex:t,collapsedLines:r,rangeSize:Math.max(n?.collapsedBefore??0,0),hunkSpecs:n?.hunkSpecs,isFirstHunk:t===0,isLastHunk:!1,isExpandable:m});let h=a===`unified`?f:l,g={type:c,hunkIndex:t,lineIndex:h,unifiedLineIndex:f,splitLineIndex:l,deletionLine:s,additionLine:o};if(a===`unified`){let n=this.getUnifiedInjectedRowsForLine?.(g);n?.before!=null&&vc(n.before,x);let r=s==null?void 0:b[s.lineIndex],i=o==null?void 0:y[o.lineIndex];if(r==null&&i==null){let t=`DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong`;throw console.error(t,{file:e.name}),Error(t)}let a=c===`change`?o==null?`change-deletion`:`change-addition`:c,u=this.getUnifiedLineDecoration({type:c,lineType:a,additionLineIndex:o?.lineIndex,deletionLineIndex:s?.lineIndex});w(`unified`,u.gutterLineType,o==null?s.lineNumber:o.lineNumber,`${f},${l}`,u.gutterProperties),i==null?r!=null&&(r=Sc(r,u.contentProperties,d&&s!=null?{"data-line":s.lineNumber,"data-line-index":`${f},${l}`}:void 0)):i=Sc(i,u.contentProperties,d&&o!=null?{"data-line":o.lineNumber,"data-line-index":`${f},${l}`}:void 0),bc({diffStyle:`unified`,type:c,deletionLine:r,additionLine:i,unifiedSpan:this.getAnnotations(`unified`,s?.lineNumber,o?.lineNumber,t,h),createAnnotationElement:e=>this.createAnnotationElement(e),context:x}),n?.after!=null&&vc(n.after,x)}else{let n=this.getSplitInjectedRowsForLine?.(g);n?.before!=null&&yc(n.before,x,C);let r=s==null?void 0:b[s.lineIndex],i=o==null?void 0:y[o.lineIndex],a=this.getSplitLineDecoration({side:`deletions`,type:c,lineIndex:s?.lineIndex}),u=this.getSplitLineDecoration({side:`additions`,type:c,lineIndex:o?.lineIndex});if(r==null&&i==null){let t=`DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong`;throw console.error(t,{file:e.name}),Error(t)}let f=(()=>{if(c===`change`){if(i==null)return`additions`;if(r==null)return`deletions`}})();f==null?c===`change`&&C.flush():(C.side!=null&&C.side!==f&&C.flush(),C.side=f,C.increment());let p=this.getAnnotations(`split`,s?.lineNumber,o?.lineNumber,t,h);if(p!=null&&C.size>0&&C.flush(),s!=null){let e=Sc(r,a.contentProperties,d?{"data-line":s.lineNumber,"data-line-index":`${s.unifiedLineIndex},${l}`}:void 0);w(`deletions`,a.gutterLineType,s.lineNumber,`${s.unifiedLineIndex},${l}`,a.gutterProperties),e!=null&&(r=e)}if(o!=null){let e=Sc(i,u.contentProperties,d?{"data-line":o.lineNumber,"data-line-index":`${o.unifiedLineIndex},${l}`}:void 0);w(`additions`,u.gutterLineType,o.lineNumber,`${o.unifiedLineIndex},${l}`,u.gutterProperties),e!=null&&(i=e)}bc({diffStyle:`split`,type:c,additionLine:i,deletionLine:r,...p,createAnnotationElement:e=>this.createAnnotationElement(e),context:x}),n?.after!=null&&yc(n.after,x,C)}let _=a===`split`&&n!=null&&l===n.splitLineStart+n.splitLineCount-1,v=t===e.hunks.length-1&&n!=null&&(a===`split`?l===n.splitLineStart+n.splitLineCount-1:f===n.unifiedLineStart+n.unifiedLineCount-1),E=_?n.noEOFCRDeletions:!1,D=_?n.noEOFCRAdditions:!1,O=(s?.noEOFCR??!1)||E,k=(o?.noEOFCR??!1)||D;if(k||O){if(a===`split`&&C.flush(),O){let e=c===`context`||c===`context-expanded`?c:`change-deletion`;a===`unified`?(x.unifiedContentAST.push(hs(e)),x.pushToGutter(`unified`,dn(e,`metadata`,1))):(x.deletionsContentAST.push(hs(e)),x.pushToGutter(`deletions`,dn(e,`metadata`,1)),k||(x.pushToGutter(`additions`,dn(void 0,`buffer`,1)),x.additionsContentAST.push(ms(1))))}if(k){let e=c===`context`||c===`context-expanded`?c:`change-addition`;a===`unified`?(x.unifiedContentAST.push(hs(e)),x.pushToGutter(`unified`,dn(e,`metadata`,1))):(x.additionsContentAST.push(hs(e)),x.pushToGutter(`additions`,dn(e,`metadata`,1)),O||(x.pushToGutter(`deletions`,dn(void 0,`buffer`,1)),x.deletionsContentAST.push(ms(1))))}x.incrementRowCount(1)}u!==`simple`&&u!==`metadata`&&(i>0||v&&p)&&T({hunkIndex:c===`context-expanded`?t:t+1,collapsedLines:v&&p?`unknown`:i,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:m}),x.incrementRowCount(1)}}),a===`split`&&C.flush();let E=Math.max(ys(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),D=t.bufferBefore>0||t.bufferAfter>0,O=!f&&e.type!==`deleted`,k=!f&&e.type!==`new`,A=x.rowCount>0||D;h=O&&A?h:void 0,g=k&&A?g:void 0,_=f&&A?_:void 0;let j=this.createPreElement(g!=null&&h!=null,E);return{unifiedGutterAST:f&&A?x.unifiedGutterAST.children:void 0,unifiedContentAST:_,deletionsGutterAST:k&&A?x.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:O&&A?x.additionsGutterAST.children:void 0,additionsContentAST:h,hunkData:v,preNode:j,themeStyles:r,baseThemeType:i,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:E,rowCount:x.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderCodeAST(e,t){let n=e===`unified`?t.unifiedGutterAST:e===`deletions`?t.deletionsGutterAST:t.additionsGutterAST,r=e===`unified`?t.unifiedContentAST:e===`deletions`?t.deletionsContentAST:t.additionsContentAST;if(n==null||r==null)return;let i=wt(n);return i.properties.style=`grid-row: span ${t.rowCount}`,[i,co(r,t.rowCount)]}renderFullAST(e,t=[]){let n=this.getOptionsWithDefaults().hunkSeparators===`line-info`,r=this.renderCodeAST(`unified`,e);if(r!=null)return t.push(K({tagName:`code`,children:r,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-unified":``}})),{...e.preNode,children:t};let i=this.renderCodeAST(`deletions`,e);i!=null&&t.push(K({tagName:`code`,children:i,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-deletions":``}}));let a=this.renderCodeAST(`additions`,e);return a!=null&&t.push(K({tagName:`code`,children:a,properties:{"data-code":``,"data-container-size":n?``:void 0,"data-additions":``}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return St(this.renderFullAST(e,t))}renderPartialHTML(e,t){return St(t==null?e:K({tagName:`code`,children:e,properties:{"data-code":``,"data-container-size":this.getOptionsWithDefaults().hunkSeparators===`line-info`?``:void 0,[`data-${t}`]:``}}))}pushFileLevelAnnotations(e,t,n,r){if(!oo(n))return;let i=e.type===`new`?[]:hc(ao(this.deletionAnnotations)),a=e.type===`deleted`?[]:hc(ao(this.additionAnnotations));if(i.length===0&&a.length===0)return;let{createAnnotationElement:o}=this;if(t===`unified`){bc({diffStyle:t,type:`context`,unifiedSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:i.concat(a)},createAnnotationElement:o,context:r});return}bc({diffStyle:t,type:`context`,deletionSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:i},additionSpan:{type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:a},createAnnotationElement:o,context:r})}getAnnotations(e,t,n,r,i){let a={type:`annotation`,hunkIndex:r,lineIndex:i,annotations:[]};if(t!=null)for(let e of this.deletionAnnotations[t]??[])a.annotations.push(to(e));let o={type:`annotation`,hunkIndex:r,lineIndex:i,annotations:[]};if(n!=null)for(let t of this.additionAnnotations[n]??[])(e===`unified`?a:o).annotations.push(to(t));if(e===`unified`)return a.annotations.length>0?a:void 0;if(o.annotations.length!==0||a.annotations.length!==0)return{deletionSpan:a,additionSpan:o}}renderHeader(e){let{headerRenderMode:t,stickyHeader:n}=this.getOptionsWithDefaults();return Ya({fileOrDiff:e,mode:t,stickyHeader:n})}};function hc(e){return e?.map(e=>to(e))??[]}var gc=new Intl.PluralRules(`en-US`);function _c(e){return`${e} unmodified line${gc.select(e)===`one`?``:`s`}`}function vc(e,t){for(let n of e)t.unifiedContentAST.push(n.content),t.pushToGutter(`unified`,n.gutter),t.incrementRowCount(1)}function yc(e,t,n){for(let{deletion:r,addition:i}of e){if(r==null&&i==null)continue;let e=r!=null&&i!=null?void 0:r==null?`deletions`:`additions`;(e==null||n.side!==e)&&n.flush(),r!=null&&(t.deletionsContentAST.push(r.content),t.pushToGutter(`deletions`,r.gutter)),i!=null&&(t.additionsContentAST.push(i.content),t.pushToGutter(`additions`,i.gutter)),e!=null&&(n.side=e,n.increment()),t.incrementRowCount(1)}}function bc({diffStyle:e,type:t,deletionLine:n,additionLine:r,unifiedSpan:i,deletionSpan:a,additionSpan:o,createAnnotationElement:s,context:c}){let l=!1;if(e===`unified`){if(r==null?n!=null&&c.unifiedContentAST.push(n):c.unifiedContentAST.push(r),i!=null){let e=t===`change`?n==null?`change-addition`:`change-deletion`:t;c.unifiedContentAST.push(s(i)),c.pushToGutter(`unified`,dn(e,`annotation`,1)),l=!0}}else if(e===`split`){if(n!=null&&c.deletionsContentAST.push(n),r!=null&&c.additionsContentAST.push(r),a!=null){let e=t===`change`?n==null?`context`:`change-deletion`:t;c.deletionsContentAST.push(s(a)),c.pushToGutter(`deletions`,dn(e,`annotation`,1)),l=!0}if(o!=null){let e=t===`change`?r==null?`context`:`change-addition`:t;c.additionsContentAST.push(s(o)),c.pushToGutter(`additions`,dn(e,`annotation`,1)),l=!0}}l&&c.incrementRowCount(1)}function xc(e,{hunkIndex:t,collapsedLines:n,rangeSize:r,hunkSpecs:i,isFirstHunk:a,isLastHunk:o,isExpandable:s},c){if(typeof n==`number`&&n<=0)return;let l=e===`unified`?c.unifiedContentAST:e===`deletions`?c.deletionsContentAST:c.additionsContentAST;if(c.hunkSeparators===`metadata`){i!=null&&(c.pushToGutter(e,_s({type:`metadata`,content:i,isFirstHunk:a,isLastHunk:o})),l.push(_s({type:`metadata`,content:i,isFirstHunk:a,isLastHunk:o})),e!==`additions`&&c.incrementRowCount(1));return}if(c.hunkSeparators===`simple`){t>0&&(c.pushToGutter(e,_s({type:`simple`,isFirstHunk:a,isLastHunk:!1})),l.push(_s({type:`simple`,isFirstHunk:a,isLastHunk:!1})),e!==`additions`&&c.incrementRowCount(1));return}let u=vs(e,t),d=r>c.expansionLineCount,f=s?t:void 0,p=typeof n==`number`?_c(n):`More unchanged context may be available`;c.pushToGutter(e,_s({type:c.hunkSeparators,content:p,expandIndex:f,chunked:d,slotName:u,isFirstHunk:a,isLastHunk:o})),l.push(_s({type:c.hunkSeparators,content:p,expandIndex:f,chunked:d,slotName:u,isFirstHunk:a,isLastHunk:o})),e!==`additions`&&c.incrementRowCount(1),c.hunkData.push({slotName:u,hunkIndex:t,lines:typeof n==`number`?n:0,lineCountKnown:typeof n==`number`,type:e,expandable:s?{up:!a,down:!o,chunked:d}:void 0})}function Sc(e,t,n){return e==null||e.type!==`element`||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Cc(e){return e.length>0&&e[e.length-1]===``?e.length-1:e.length}function wc(e,t,n,r){let i=Cc(e),a=Cc(t),o=Math.min(i,a),s=0;for(;s<o&&e[s]===t[s];)s++;let c=0;for(;c<o-s&&e[i-1-c]===t[a-1-c];)c++;let l=Array(t.length);for(let e=0;e<s;e++)l[e]=n[e];for(let e=0;e<c;e++)l[a-1-e]=n[i-1-e];i<e.length&&a<t.length&&(l[t.length-1]=n[e.length-1]);for(let r=e.length;r<t.length;r++)l[r]??=n[r];for(let e=s;e<t.length;e++)l[e]??=Tc(e,r.getLineText(e));return l}function Tc(e,t,n=e,r=e){return{type:`element`,tagName:`div`,properties:{"data-line":e+1,"data-line-index":`${n},${r}`,"data-line-type":`context`},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:t}]}]}}function Ec(e,t){let n=[],r=Oc(t);for(let t=0;t<e.lineCount;t++){let i=e.getLineText(t,!0);n.push(t<e.lineCount-1&&!Dc(i)?i+r:i)}return n}function Dc(e){return e.endsWith(`
1360
1360
  `)||e.endsWith(`\r`)}function Oc(e){for(let t of e){if(t.endsWith(`\r
1361
1361
  `))return`\r
1362
1362
  `;if(t.endsWith(`
1363
1363
  `))return`
1364
1364
  `;if(t.endsWith(`\r`))return`\r`}return`
1365
- `}function kc(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function Ac(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function jc(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Mc(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}async function Nc(e,t=300){let n;try{await Promise.race([e(),new Promise(e=>{n=setTimeout(e,t)})])}finally{n!=null&&clearTimeout(n)}}function Pc({oldFile:e,newFile:t},n){if(e!==void 0||t!==void 0){if(e===void 0||t===void 0)throw Error(`${n}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw Error(`${n}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return{oldFile:e,newFile:t}}}function Fc(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Io(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators==`function`?`custom`:e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Ic(e){return e.isPartial&&(e.type===`change`||e.type===`rename-changed`||e.type===`rename-pure`)}var Lc=-1,Rc=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Lc}`;type=`file-diff`;fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:K},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Ia,this.scrollSyncManager=new ps,this.interactionManager=new ga(`diff`,_a(e,typeof e.hunkSeparators==`function`||(e.hunkSeparators??`line-info`)===`line-info`||e.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return Fc(e)}createHunksRenderer(e){return new mc(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t=`additions`)=>{let n=this.fileDiffCache;if(n==null)return;let r=n.hunks.at(-1),i,a;hunkIterator:for(let o of n.hunks){let n=t===`deletions`?o.deletionStart:o.additionStart,s=t===`deletions`?o.deletionCount:o.additionCount,c=Le(n,s)+1,l=o.splitLineStart,u=o.unifiedLineStart;if(e<c){let t=c-e;i=Math.max(u-t,0),a=Math.max(l-t,0);break hunkIterator}if(e>=c+s){if(o===r){let t=e-(c+s);i=u+o.unifiedLineCount+t,a=l+o.splitLineCount+t;break hunkIterator}continue}for(let n of o.hunkContent)if(n.type===`context`){if(e<c+n.lines){let t=e-c;a=l+t,i=u+t;break hunkIterator}c+=n.lines,l+=n.lines,u+=n.lines}else{let r=t===`deletions`?n.deletions:n.additions;if(e<c+r){let r=e-c;i=u+(t===`additions`?n.deletions:0)+r,a=l+r;break hunkIterator}c+=r,l+=Math.max(n.deletions,n.additions),u+=n.deletions+n.additions}break hunkIterator}if(i!=null&&a!=null)return[i,a]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(_a(this.options,typeof this.options.hunkSeparators==`function`||(this.options.hunkSeparators??`line-info`)===`line-info`||this.options.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex))}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;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType!==t&&(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Ht(this.appliedThemeCSS.theme,this.options.theme??K)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators==`function`)}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}flushDeferredLineState(){let{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e=`split`,overflow:t=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t===`wrap`,columnVariables:this.shouldApplyColumnVariables(t)?`apply`:`measure`}),t===`scroll`&&e===`split`?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators==`function`||e===`scroll`&&(this.lineAnnotations.length>0||this.pre?.hasAttribute(`data-has-merge-conflict`)===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){gi(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:r,fileDiff:i,...a}){if(!this.enabled)throw Error(`FileDiff.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated`);let o=Pc(a,`FileDiff.hydrate`),s=o?.oldFile,c=o?.newFile;this.hydrateElements(e,t),Hc(this.pre,Bc({fileDiff:i,oldFile:s,newFile:c}),this.options.collapsed)||Uc(this.headerElement,Vc({fileDiff:i,oldFile:s,newFile:c}),this.options.disableFileHeader)?this.render({...a,fileContainer:e,lineAnnotations:r,fileDiff:i,preventEmit:!0}):this.hydrationSetup({fileDiff:i,lineAnnotations:r,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),No(e,t);for(let t of e.shadowRoot?.children??[]){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t;for(let e of t.children)!(e instanceof HTMLElement)||e.tagName.toLowerCase()!==`code`||(`deletions`in e.dataset&&(this.codeDeletions=e),`additions`in e.dataset&&(this.codeAdditions=e),`unified`in e.dataset&&(this.codeUnified=e));continue}if(`diffsHeader`in t.dataset){this.headerElement=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:r}){this.lineAnnotations=r??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?da(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){let{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Ic(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{let n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(e){if(this.options.disableErrorHandling===!0)throw e;console.error(e)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(is(`merge`,e,t),this.setHydratedState(t),await Nc(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:r=!1,lineAnnotations:i,fileContainer:a,containerWrapper:o,renderRange:s,...c}){let l=Pc(c,`FileDiff.render`),u=l?.oldFile,d=l?.newFile;if(!this.enabled)throw Error(`FileDiff.render: attempting to call render after cleaned up`);e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName==null?e.name:e.prevName+`:`+e.name),this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:f=!1,themeType:p=`system`,expandUnchanged:m=!1}=this.options,h=f?void 0:s,g=this.hasThemeChanged(),_=l!=null,v=_&&(!zc(u,this.deletionFile)||!zc(d,this.additionFile)),y=e!=null&&e!==this.fileDiff,b=i!=null&&(i.length>0||this.lineAnnotations.length>0)&&i!==this.lineAnnotations;if(!f&&Ka(h,this.renderRange)&&!n&&!b&&!g&&(e!=null&&e===this.fileDiff||e==null&&!v))return this.applyCachedThemeState(p);let x;e==null&&_&&(v||this.fileDiff==null)&&(x=da(l.oldFile,l.newFile,this.options.parseDiffOptions));let{renderRange:S}=this;if(this.renderRange=h,_?(this.deletionFile=u,this.additionFile=d):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e==null?x!=null&&(y=!0,this.fileDiff=x):this.fileDiff=e,y&&(this.cachedHeaderHTML=void 0),i!=null&&this.setLineAnnotations(i),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(Zs(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),m&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:C=!1,disableFileHeader:w=!1}=this.options;if(w&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,o),this.applyCachedThemeState(p),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let e=this.hunksRenderer.renderDiff(this.fileDiff,mt);e!=null&&this.applyThemeState(a,e.themeStyles,p,e.baseThemeType),e?.headerElement!=null&&this.applyHeaderToDOM(e.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}try{let e=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(n,b,v||y||g)&&this.applyPartialRender({previousRenderRange:S,renderRange:h}))){let t=this.hunksRenderer.renderDiff(this.fileDiff,h);if(t==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,t.themeStyles,p,t.baseThemeType),t.headerElement!=null&&this.applyHeaderToDOM(t.headerElement,a),t.additionsContentAST!=null||t.deletionsContentAST!=null||t.unifiedContentAST!=null?this.applyHunksToDOM(e,t):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(t.hunkData)}this.applyBuffers(e,h),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.fileDiffCache,r=this.lineAnnotations,i=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(a,t,n,r,i)})}computeEditorRenderRange(e){let t=this.fileDiffCache;if(e==null||t==null||bs(e))return e;let{diffStyle:n=`split`,expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a,o;return Qe({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({additionLine:e})=>{e!=null&&(a??=e.lineNumber,o=e.lineNumber)}}),a==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:a-1,totalLines:o-a+1}}attachEditor(e){if(this.type!==`file-diff`)throw Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),e=>{this.editor=void 0,e!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){let e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;let{collapsedContextThreshold:t=1}=this.options,n=Ys(e,this.hunksRenderer.getExpandedHunksMap(),t);return Zs(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(Xs(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);let n=this.hunksRenderer.diffCache;if(n!=null){let e=this.fileDiff?.cacheKey;e!=null&&n.cacheKey==null&&(n.cacheKey=e),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){let{shouldRefreshDiffsView:r,lineCountChangeInFlight:i}=n;if(this.hunksRenderer.updateRenderCache(e,t,i)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}r===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle===`split`?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){let t=this.fileDiffCache;if(t==null)return!0;let{expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options;return pt({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r})}getNearestRenderableLine(e,t){let n=this.fileDiffCache;if(n==null)return e;let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options;return We({fileDiff:n,lineNumber:e,direction:t,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}revealLine(e){let t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:r=1,expansionLineCount:i=100}=this.options;if(t==null||t.isPartial||n)return!1;let a=this.hunksRenderer.getExpandedHunksMap();for(let[n,o]of t.hunks.entries()){let[s,c]=rt(o);if(e<s){let c=et({isPartial:t.isPartial,rangeSize:o.collapsedBefore,expandedHunks:a,hunkIndex:n,collapsedContextThreshold:r}),l=s-c.rangeSize;if(c.renderAll||e<l+c.fromStart||e>=s-c.fromEnd)return!1;let u=e-(l+c.fromStart)+1,d=s-c.fromEnd-e;return u<=d?this.expandHunk(n,`up`,u+i):this.expandHunk(n,`down`,d+i),!0}if(e<c)return!1}let o=st({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:a,collapsedContextThreshold:r,errorPrefix:`FileDiff.revealLine`});if(o==null||o.renderAll)return!1;let s=t.hunks[t.hunks.length-1],[,c]=rt(s);return e<c+o.fromStart||e>=c+o.rangeSize?!1:(this.expandHunk(t.hunks.length,`up`,e-(c+o.fromStart)+1+i),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){hi(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}async primeHighlightCache(e=this.fileDiff){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Me(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.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.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=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}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!=`function`){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let r of e){let e=r.slotName,i=this.separatorCache.get(e);if(i==null||!Mc(r,i.hunkData)){i?.element.remove();let n=document.createElement(`div`);n.style.display=`contents`,n.slot=r.slotName;let a=t(r,this);a!=null&&n.appendChild(a),this.fileContainer.appendChild(n),i={element:n,hunkData:r},this.separatorCache.set(e,i)}n.delete(e)}for(let[e,{element:t}]of n.entries())this.separatorCache.delete(e),t.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${to(r)}`,a=this.annotationCache.get(i);if(a==null||!jc(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:yo(to(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=bo();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return n!=null&&i&&this.editor?.__captureFocusForDOMReplacement(),i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:Fo(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):Fo(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=mo;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});return this.pre==null?(this.pre=document.createElement(`pre`),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute(`data-unified`)?this.codeUnified=t:t.hasAttribute(`data-deletions`)?this.codeDeletions=t:t.hasAttribute(`data-additions`)&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,r=this.cachedHeaderHTML??Ct(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:i,renderHeaderPrefix:a,renderHeaderFilenameSuffix:o,renderHeaderMetadata:s}=this.options;if(i!=null){let e=i(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,$e,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}let c=a?.(n)??void 0,l=o?.(n)??void 0,u=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,en,c),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ve,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ye,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}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}injectUnsafeCSS(){let{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??=xo(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Oo(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??K,s=typeof o==`string`?o:{...o},c=wo(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=zo({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ko(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=Ao(this.themeCSSStyle.textContent??``,wo(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Wo()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?Ro(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){let r=this.getColumnPair(e);if(r==null)return!1;let i=Wc(t[0]),a=Wc(t[1]);return i==null||a==null?!1:(r.gutter.innerHTML=Ct(i),r.content.innerHTML=Ct(a),n!==this.lastRowCount&&(r.gutter.style.setProperty(`grid-row`,`span ${n}`),r.content.style.setProperty(`grid-row`,`span ${n}`)),!0)}replaceCodeColumns(e,t){let{overflow:n=`scroll`}=this.options,r=(this.options.hunkSeparators??`line-info`)===`line-info`,i=n===`wrap`?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let a=!1,o=[],s=this.hunksRenderer.renderCodeAST(`unified`,t),c=this.hunksRenderer.renderCodeAST(`deletions`,t),l=this.hunksRenderer.renderCodeAST(`additions`,t);this.editor?.__captureFocusForDOMReplacement(),s==null?c!=null||l!=null?(c==null?(this.codeDeletions?.remove(),this.codeDeletions=void 0):(a=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Mo({code:this.codeDeletions,columnType:`deletions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeDeletions,c,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(c)),o.push(this.codeDeletions)),l==null?(this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=a||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Mo({code:this.codeAdditions,columnType:`additions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeAdditions,l,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeAdditions))):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Mo({code:this.codeUnified,columnType:`unified`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeUnified,s,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s)),o.push(this.codeUnified)),o.length===0?e.textContent=``:a&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:r,codeAdditions:i,codeDeletions:a,options:{diffStyle:o=`split`}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(o,r,a,i);if(s==null)return!1;let c=e.startingLine,l=t.startingLine,u=c+e.totalLines,d=l+t.totalLines,f=Math.max(c,l),p=Math.min(u,d);if(p<=f)return!1;let m=Math.max(0,f-c),h=Math.max(0,u-p),g=this.trimColumns({columns:s,trimStart:m,trimEnd:h,previousStart:c,overlapStart:f,overlapEnd:p,diffStyle:o});if(g<0)throw Error(`FileDiff.applyPartialRender: failed to trim to overlap`);if(this.lastRowCount<g)throw Error(`FileDiff.applyPartialRender: trimmed beyond DOM row count`);let _=this.lastRowCount-g,v=(e,t)=>{if(!(t<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},y=v(l,Math.max(f-l,0));if(y==null&&l<f)return!1;let b=v(p,Math.max(d-p,0));if(b==null&&d>p)return!1;let x=(e,t)=>{if(e!=null){if(o===`unified`&&!Array.isArray(s))this.insertPartialHTML(o,s,e,t);else if(o===`split`&&Array.isArray(s))this.insertPartialHTML(o,s,e,t);else throw Error(`FileDiff.applyPartialRender.applyChunk: invalid chunk application`);_+=e.rowCount}};return this.cleanupErrorWrapper(),x(y,`afterbegin`),x(b,`beforeend`),this.lastRowCount!==_&&(this.applyRowSpan(o,s,_),this.lastRowCount=_),!0}insertPartialHTML(e,t,n,r){if(e===`unified`&&!Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`unified`,n);this.renderPartialColumn(t,e,r)}else if(e===`split`&&Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`deletions`,n),i=this.hunksRenderer.renderCodeAST(`additions`,n);this.renderPartialColumn(t[0],e,r),this.renderPartialColumn(t[1],i,r)}else throw Error(`FileDiff.insertPartialHTML: Invalid argument composition`)}refreshSplitDiffView(){if(this.options.diffStyle!==`split`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`split`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;let n=(t,n)=>{if(n==null)return;let r=this.hunksRenderer.renderCodeAST(t,e),i=Wc(r?.[0]),a=Wc(r?.[1]);for(let[e,t]of[[n.gutter,i],[n.content,a]])if(t!=null&&e.childElementCount===t.length)for(let n=0;n<t.length;n++){let r=e.children[n],i=t[n].properties[`data-line-type`];i!=null&&r.dataset.lineType!==i&&(r.dataset.lineType=i)}};n(`deletions`,t[0]),n(`additions`,t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!==`unified`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`unified`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;let n=this.hunksRenderer.renderCodeAST(`unified`,e),r=Wc(n?.[0]),i=Wc(n?.[1]),a=()=>{for(let[e,n]of[[t.gutter,r],[t.content,i]])n!=null&&(e.innerHTML=Ct(n));e.rowCount!==this.lastRowCount&&(this.applyRowSpan(`unified`,t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?Ro(this.pre,a):a(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;let r=Wc(t[0]),i=Wc(t[1]);if(r==null||i==null)throw Error(`FileDiff.insertPartialHTML: Unexpected AST structure`);let a=i.at(0);n===`beforeend`&&a?.type===`element`&&typeof a.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(a.properties[`data-buffer-size`],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],r,i,!0);let o=i.at(-1);n===`afterbegin`&&o?.type===`element`&&typeof o.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(o.properties[`data-buffer-size`],e.content.children[0],e.gutter.children[0],r,i,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(r)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i))}mergeBuffersIfNecessary(e,t,n,r,i,a){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let o=this.getBufferSize(t.dataset);o!=null&&(a?(r.shift(),i.shift()):(r.pop(),i.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){let r=e=>{e!=null&&(e.gutter.style.setProperty(`grid-row`,`span ${n}`),e.content.style.setProperty(`grid-row`,`span ${n}`))};if(e===`unified`&&!Array.isArray(t))r(t);else if(e===`split`&&Array.isArray(t))r(t[0]),r(t[1]);else throw Error(`dun fuuuuked up`)}trimColumnRows(e,t,n){let r=0,i=0,a=0,o=!1,s=n>=0;if(e==null)return 0;let c=Array.from(e.content.children),l=Array.from(e.gutter.children);if(c.length!==l.length)throw Error(`FileDiff.trimColumnRows: columns do not match`);for(;a<c.length&&!(t<=0&&!s&&!o);){let e=l[a],u=c[a];if(a++,!(e instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: invalid row elements`);if(o&&(o=!1,e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset||e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset)){e.remove(),u.remove(),i++;continue}if(`lineIndex`in e.dataset&&`lineIndex`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),i++),r++;continue}if(`separator`in e.dataset&&`separator`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`buffer`&&`contentBuffer`in u.dataset){let a=this.getBufferSize(u.dataset);if(a==null)throw Error(`FileDiff.trimColumnRows: invalid element`);if(t>0){let n=Math.min(t,a),r=a-n;r>0?(this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=n):(e.remove(),u.remove(),i+=a),t-=n,t===0&&r===0&&(o=!0)}else if(s){let t=r,o=r+a-1;if(n<=t)e.remove(),u.remove(),i+=a;else if(n<=o){let t=o-n+1,r=a-t;this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=t}}r+=a;continue}throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: unknown row elements`)}return i}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:r,previousStart:i,trimEnd:a,trimStart:o}){let s=Math.max(0,r-i),c=n-i;if(c<0)throw Error(`FileDiff.trimColumns: overlap ends before previous`);let l=o>0,u=a>0;if(!l&&!u)return 0;let d=l?s:0,f=u?c:-1;if(t===`unified`&&!Array.isArray(e))return this.trimColumnRows(e,d,f);if(t===`split`&&Array.isArray(e)){let t=this.trimColumnRows(e[0],d,f),n=this.trimColumnRows(e[1],d,f);if(e[0]!=null&&e[1]!=null&&t!==n)throw Error(`FileDiff.trimColumns: split columns out of sync`);return e[0]==null?n:t}throw console.error({diffStyle:t,columns:e}),Error(`FileDiff.trimColumns: Invalid columns for diffType`)}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??``,10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty(`grid-row`,`span ${t}`),e.style.setProperty(`min-height`,`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;let 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}}getCodeColumns(e,t,n,r){if(e===`unified`)return this.getColumnPair(t);{let e=this.getColumnPair(n),t=this.getColumnPair(r);return e!=null||t!=null?[e,t]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}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??(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??(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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:r},i){let{diffIndicators:a=`bars`,disableBackground:o=!1,disableLineNumbers:s=!1,overflow:c=`scroll`,diffStyle:l=`split`}=this.options,u={type:`diff`,diffIndicators:a,disableBackground:o,disableLineNumbers:s,overflow:c,split:l!==`unified`&&t!=null&&n!=null,totalLines:r,customProperties:i};go(u,this.appliedPreAttributes)||(Po(e,u),this.appliedPreAttributes=u)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function zc(e,t){return e==null||t==null?e==null&&t==null:pn(e,t)}function Bc({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Vc({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Hc(e,t,n=!1){return!n&&e==null&&t}function Uc(e,t,n=!1){return e==null&&t&&!n}function Wc(e){if(e!=null&&e.type===`element`)return e.children??[]}function Gc({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:r,expandUnchanged:i,expandedHunks:a,collapsedContextThreshold:o,canHydratePartialDiff:s}){let c=Be(t,n),l=c,u=i?!0:a,d=e.hunks.length-1;for(let n=0;n<e.hunks.length;n++){let i=e.hunks[n];if(i==null)throw Error(`computeEstimatedDiffHeights: invalid hunk index`);let a=et({isPartial:e.isPartial,rangeSize:i.collapsedBefore,expandedHunks:u,hunkIndex:n,collapsedContextThreshold:o}),f=(a.fromStart+a.fromEnd)*t.lineHeight;if(c+=f,l+=f,a.collapsedLines>0){let e=ze({type:r,metrics:t,hunkIndex:n,hunkSpecs:i.hunkSpecs})?.totalHeight??0;c+=e,l+=e}c+=i.splitLineCount*t.lineHeight,l+=i.unifiedLineCount*t.lineHeight;let p=Kc(i);c+=p.split*t.lineHeight,l+=p.unified*t.lineHeight;let m=n===d?st({fileDiff:e,hunkIndex:n,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:`computeEstimatedDiffHeights`}):void 0;if(m!=null){let e=(m.fromStart+m.fromEnd)*t.lineHeight;if(c+=e,l+=e,m.collapsedLines>0){let e=hn({type:r,metrics:t})?.totalHeight??0;c+=e,l+=e}}else if(n===d&&e.isPartial&&s){let e=hn({type:r,metrics:t})?.totalHeight??0;c+=e,l+=e}}if(e.hunks.length>0){let e=Je(t);c+=e,l+=e}return{splitHeight:c,unifiedHeight:l}}function Kc(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};let t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type===`context`){let e=+(t.lines>0);return{split:e,unified:e}}return qc(e,t)}function qc(e,t){let n=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),r=t.deletions>0&&e.noEOFCRDeletions,i=t.additions>0&&e.noEOFCRAdditions;return{split:r||i?1:0,unified:n}}var Jc=3e3,Yc=-1,Xc=class extends Rc{__id=`little-virtualized-file-diff:${++Yc}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=ht(n)}setMetrics(e,t=!1){let n=ht(e);!t&&vi(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){let t=this.cache.fileAnnotationHeight;return e!==t&&(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!io(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber===0?e.type===`new`?t.side===`additions`:e.type!==`deleted`||t.side===`deletions`:!1)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){let t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!yi(t,e),r=n&&il(t,e);super.setOptions(e),r&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:al(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1,{overflow:t=`scroll`}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;let n=this.getDiffStyle(),r=n===`split`?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],i=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&i&&oo(this.renderRange)){let t=Zc(r)??0;this.setFileAnnotationHeight(t)&&(e=!0)}else!i&&this.setFileAnnotationHeight(0)&&(e=!0);for(let t of r){if(t==null)continue;let r=t.children[1];if(r instanceof HTMLElement)for(let t of r.children){if(!(t instanceof HTMLElement))continue;let r=t.dataset.lineIndex;if(r==null)continue;let i=ll(r,n),a=t.getBoundingClientRect().height,o=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(o=!0),a+=t.nextElementSibling.getBoundingClientRect().height);let s=this.getEstimatedLineHeight(o),c=this.cache.heightDeltas.get(i)??0,l=a-s;l!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=l-c,l===0?this.cache.heightDeltas.delete(i):this.cache.heightDeltas.set(i,l))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer!=null&&(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,r){let i=!dt(this.fileDiff,e),a=this.syncLineAnnotations(r),o=n?.resetDiffLayoutCache===!0||i||a,s=i||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=ht(n.metrics),o=!0,s=!0);let{collapsed:c=!1,expandUnchanged:l=!1}=this.options;return this.currentCollapsed!==c&&(this.currentCollapsed=c,o=!0),this.currentExpandUnchanged!==l&&(this.currentExpandUnchanged=l,o=!0,s=!0),o&&this.resetLayoutCache({includeEstimatedHeights:s}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t=`additions`){if(this.fileDiff==null||e<1)return;let n=this.getLineIndex(e,t);if(n==null)return;let{disableFileHeader:r=!1,expandUnchanged:i=!1,collapsed:a=!1,collapsedContextThreshold:o=1}=this.options,s=this.getDiffStyle(),c=this.getHunkSeparatorType(),l=s===`split`?n[1]:n[0];this.approximateLayoutCheckpoints();let u=Be(this.metrics,r),d=this.getLayoutCheckpointBeforeLineIndex(l),f=d?.top??u+this.cache.fileAnnotationHeight;if(a)return{top:u,height:0};let p;return Qe({diff:this.fileDiff,diffStyle:s,startingLine:d?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:e,hunk:t,collapsedBefore:n,collapsedAfter:r,deletionLine:i,additionLine:a})=>{let o=s===`split`?a?.splitLineIndex??i?.splitLineIndex:a?.unifiedLineIndex??i?.unifiedLineIndex;if(o==null)throw Error(`VirtualizedFileDiff.getLinePosition: missing line index data`);if(n>0){let r=ze({type:c,metrics:this.metrics,hunkIndex:e,hunkSpecs:t?.hunkSpecs});if(r!=null){if(f+=r.gapBefore,l>=o-n&&l<o)return p={top:f,height:r.height},!0;f+=r.height+r.gapAfter}}let u=this.getLineHeight(o,(a?.noEOFCR??!1)||(i?.noEOFCR??!1));if(o===l)return p={top:f,height:u},!0;if(f+=u,r>0){let e=hn({type:c,metrics:this.metrics});if(e!=null){if(l>o&&l<=o+r)return p={top:f+e.gapBefore,height:e.height},!0;f+=e.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:r=!1,collapsedContextThreshold:i=1}=this.options;if(r)return;let a=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();let s=this.getLayoutCheckpointBeforeTop(e),c=s?.top??Be(this.metrics,t)+this.cache.fileAnnotationHeight,l;return Qe({diff:this.fileDiff,diffStyle:a,startingLine:s?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,deletionLine:s,additionLine:u})=>{let d=a===`split`?u?.splitLineIndex??s?.splitLineIndex:u?.unifiedLineIndex??s?.unifiedLineIndex;if(d==null)throw Error(`VirtualizedFileDiff.getNumericScrollAnchor: missing line index data`);if(r>0){let e=ze({type:o,metrics:this.metrics,hunkIndex:t,hunkSpecs:n?.hunkSpecs});e!=null&&(c+=e.totalHeight)}if(c>=e&&(s==null?u!=null&&(l={lineNumber:u.lineNumber,side:`additions`,top:c}):l={lineNumber:s.lineNumber,side:`deletions`,top:c},l!=null))return!0;let f=this.getLineHeight(d,(u?.noEOFCR??!1)||(s?.noEOFCR??!1));if(c+=f,i>0){let e=hn({type:o,metrics:this.metrics});e!=null&&(c+=e.totalHeight)}return!1}}),l}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.fileDiff,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){let n=is(`clone`,e,t);if(await Nc(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(is(`merge`,e,t),this.setHydratedState(t),await Nc(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n,{pendingExpansions:r,pendingHydratedDiff:i}=this;if(r!=null){this.pendingExpansions=void 0;for(let e of r)this.hunksRenderer.expandHunk(e.hunkIndex,e.direction,e.expansionLineCountOverride),t=!0}return i!=null&&(this.pendingHydratedDiff=void 0,i.expectedDiff===e&&(this.setHydratedState(i.files),n=i.nextDiff)),n==null?t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)):(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;let{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;let{expansionLineCount:r=100,collapsedContextThreshold:i=1}=this.options,a=new Map(this.hunksRenderer.getExpandedHunksMap());for(let e of t){let t={...a.get(e.hunkIndex)??{fromStart:0,fromEnd:0}},n=e.expansionLineCountOverride??r;(e.direction===`up`||e.direction===`both`)&&(t.fromStart+=n),(e.direction===`down`||e.direction===`both`)&&(t.fromEnd+=n),a.set(e.hunkIndex,t)}return pt({fileDiff:n,lineNumber:e,expandedHunks:a,collapsedContextThreshold:i})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{renderRange:r}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.fileDiff!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1}=this.options,o=Be(this.metrics,i);if(this.height+=o,a){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!r&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);let t=this.getDiffStyle()===`split`?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw Error(`VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height`);return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,{splitHeight:i,unifiedHeight:a}=Gc({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,canHydratePartialDiff:ol(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=i,this.cache.estimatedUnifiedHeight=a}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;let t=this.fileContainer.getBoundingClientRect();t.height===this.height?console.log(`VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFileDiff.computeApproximateSize: computed height doesnt match`,{name:e.name,elementHeight:t.height,computedHeight:this.height})}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:r,...i}={}){let a=Pc(i,`VirtualizedFileDiff.render`),o=a!=null,s=a?.oldFile,c=a?.newFile,l=o&&(!cl(s,this.deletionFile)||!cl(c,this.additionFile)),u=t??this.fileDiff;t==null&&o&&(l||this.fileDiff==null)&&(u=da(a.oldFile,a.newFile,this.options.parseDiffOptions));let{forceRenderOverride:d,isSetup:f}=this;this.forceRenderOverride=void 0;let p=this.syncLineAnnotations(r);p&&this.resetLayoutCache({includeEstimatedHeights:!1});let m=t!=null&&t!==this.fileDiff,h=u!=null&&!dt(this.fileDiff,u),g=m||l;if(h&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),u==null)return console.error(`VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data`),!1;if(f)this.top??=this.getVirtualizedTop(),h&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,u));else{this.computeApproximateSize(!1,u);let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFileDiff.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!g||!f))return this.fileDiff=u,a!=null&&(this.deletionFile=s,this.additionFile=c),h&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let _=this.virtualizer.getWindowSpecs(),v=this.top??0,y=this.computeRenderRangeFromWindow(u,v,_),b=super.render({fileDiff:u,fileContainer:e,renderRange:y,lineAnnotations:r,forceRender:(d??n)||p||h,...a,...i});return this.isSimpleMode()&&b&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),b}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type===`advanced`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??`split`}getHunkSeparatorType(){return sl(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,i=e.hunks.length-1,a=ol(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),s=this.getHunkSeparatorType(),c=n?!0:this.hunksRenderer.getExpandedHunksMap(),l=Qc(this.cache.heightDeltas),u=Be(this.metrics,t)+this.cache.fileAnnotationHeight,d=0,f=({rowCount:e,startLineIndex:t,preSeparatorHeight:n=0,postSeparatorHeight:r=0,metadataOffsets:i=[]})=>{if(e<=0)return;let a=d,o=d+e,s=tl(a);for(;s<o;){let e=s-a,r=u+(e>0?n:0)+e*this.metrics.lineHeight+nl(i,e)*this.metrics.lineHeight+$c(l,t,t+e);this.cache.checkpoints.push({renderedLineIndex:s,lineIndex:t+e,top:r}),s+=Jc}u+=n+e*this.metrics.lineHeight+i.length*this.metrics.lineHeight+$c(l,t,t+e)+r,d=o};for(let t=0;t<e.hunks.length;t++){let n=e.hunks[t];if(n==null)throw Error(`VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index`);let l=et({isPartial:e.isPartial,rangeSize:n.collapsedBefore,expandedHunks:c,hunkIndex:t,collapsedContextThreshold:r}),u=l.collapsedLines>0?ze({type:s,metrics:this.metrics,hunkIndex:t,hunkSpecs:n.hunkSpecs})?.totalHeight??0:0;f({rowCount:l.fromStart,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.rangeSize});let d=u;f({rowCount:l.fromEnd,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.fromEnd,preSeparatorHeight:d}),l.fromEnd>0&&(d=0);let p=t===i?st({fileDiff:e,hunkIndex:t,expandedHunks:c,collapsedContextThreshold:r,errorPrefix:`VirtualizedFileDiff`}):void 0,m=p!=null&&p.collapsedLines>0||t===i&&a?hn({type:s,metrics:this.metrics})?.totalHeight??0:0,h=p==null?0:p.fromStart+p.fromEnd,g=o===`split`?n.splitLineCount:n.unifiedLineCount,_=o===`split`?n.splitLineStart:n.unifiedLineStart;f({rowCount:g,startLineIndex:_,preSeparatorHeight:d,postSeparatorHeight:h===0?m:0,metadataOffsets:rl({diffStyle:o,hunk:n,rowCount:g})}),p!=null&&h>0&&f({rowCount:h,startLineIndex:_+g,postSeparatorHeight:m})}this.cache.totalLines=d}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);if(n.renderedLineIndex%t===0)return n}}getExpandedLineCount(e,t){let n=0;if(e.isPartial){for(let r of e.hunks)n+=t===`split`?r.splitLineCount:r.unifiedLineCount;return n}let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a=r?!0:this.hunksRenderer.getExpandedHunksMap();for(let[r,o]of e.hunks.entries()){let s=t===`split`?o.splitLineCount:o.unifiedLineCount;n+=s;let c=Math.max(o.collapsedBefore,0),{fromStart:l,fromEnd:u,renderAll:d}=et({isPartial:e.isPartial,rangeSize:c,expandedHunks:a,hunkIndex:r,collapsedContextThreshold:i});c>0&&(n+=d?c:l+u)}let o=st({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:`VirtualizedFileDiff`});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){let n=this.getExpandedLineCount(e,t),r=t===`split`?e.splitLineCount:e.unifiedLineCount;return Math.max(n,r,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,expandUnchanged:a=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:s,lineHeight:c}=this.metrics,l=this.getDiffStyle(),u=this.getHunkSeparatorType(),d=ol(e,this.options.loadDiffFiles!=null),f=this.height,p=this.getLayoutLineCount(e,l),m=Be(this.metrics,i),h=e.hunks.length>0?Je(this.metrics):0,{fileAnnotationHeight:g}=this.cache,_=m+g,v=Math.max(0,f-m-g-h),y=this.hasFileAnnotations(e),b=t+m,x=g>0&&y&&b<r&&b+g>n;if(t<n-f||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h};if(p<=s||e.hunks.length===0)return{startingLine:0,totalLines:s,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),p=this.getLayoutLineCount(e,l);let S=Math.ceil(Math.max(r-n,0)/c),C=Math.ceil(S/s)*s+s,w=C/s,T=w,E=[],D=(n+r)/2,O=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-C*c*2),s),k=t+(O?.top??_),A=O?.renderedLineIndex??0,j,ee,M;if(Qe({diff:e,diffStyle:l,startingLine:O?.renderedLineIndex??0,expandedHunks:a?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:i,hunk:a,collapsedBefore:o,collapsedAfter:c,deletionLine:f,additionLine:p})=>{let m=p==null?f.splitLineIndex:p.splitLineIndex,h=p==null?f.unifiedLineIndex:p.unifiedLineIndex,g=(p?.noEOFCR??!1)||(f?.noEOFCR??!1),v=i===e.hunks.length-1&&a!=null&&(l===`split`?m===a.splitLineStart+a.splitLineCount-1:h===a.unifiedLineStart+a.unifiedLineCount-1),y=(o>0?ze({type:u,metrics:this.metrics,hunkIndex:i,hunkSpecs:a?.hunkSpecs}):void 0)?.totalHeight??0;k+=y;let b=A%s===0,x=Math.floor(A/s);if(b&&(E[x]=k-(t+_+y),M!=null)){if(M<=0)return!0;M--}let S=this.getLineHeight(l===`split`?m:h,g);if(k>n-S&&k<r&&(j??=x),ee==null&&k+S>D&&(ee=x),M==null&&k>=r&&b&&(M=T),A++,k+=S,c>0||v&&d){let e=hn({type:u,metrics:this.metrics});e!=null&&(k<r&&k+e.totalHeight>n&&(j??=x),ee==null&&k+e.totalHeight>D&&(ee=x),k+=e.totalHeight)}return!1}}),j==null){if(x)j=0,ee=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h}}ee??=j;let te=Math.round(ee-w/2),N=Math.max(0,Math.ceil(p/s)-w),P=Math.max(0,Math.min(te,N)),ne=P*s,F=te<0?C+te*s:C,re=E[P]??0,ie=ne===0?0:g+re,ae=P+F/s,oe=ae<E.length?v-E[ae]:v-(k-t-_);return{startingLine:ne,totalLines:F,bufferBefore:ie,bufferAfter:Math.max(0,oe)}}};function Zc(e){let t;for(let n of e){if(n==null)continue;let e=n.children[1];if(e instanceof HTMLElement)for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===ro&&(t=Math.max(t??0,n.getBoundingClientRect().height))}return t}function Qc(e){let t=Array.from(e).sort((e,t)=>e[0]-t[0]),n=[],r=[0],i=0;for(let[e,a]of t)n.push(e),i+=a,r.push(i);return{lineIndexes:n,prefixTotals:r}}function $c({lineIndexes:e,prefixTotals:t},n,r){if(n>=r||e.length===0)return 0;let i=el(e,n);return(t[el(e,r)]??0)-(t[i]??0)}function el(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid prefix index`);a<t?n=i+1:r=i}return n}function tl(e){return Math.ceil(e/Jc)*Jc}function nl(e,t){let n=0;for(let r of e)r<t&&n++;return n}function rl({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];let r=t.hunkContent.at(-1);if(r==null)return[];if(r.type===`context`)return[n-1];let i=Math.max(r.deletions,r.additions),a=r.deletions+r.additions;if(e===`split`)return i>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];let o=[],s=n-a;return r.deletions>0&&t.noEOFCRDeletions&&o.push(s+r.deletions-1),r.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function il(e,t){return(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function al(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function ol(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function sl(e){return typeof e==`function`?`custom`:e??`line-info`}function cl(e,t){return e==null||t==null?e==null&&t==null:pn(e,t)}function ll(e,t){let[n,r]=e.split(`,`).map(Number);return t===`split`?r:n}function ul({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function dl(e,t){let n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:fl(n,e.startContentIndex)}}function fl(e,t){let n=e.unifiedLineStart;for(let r=0;r<t;r++){let t=e.hunkContent[r];n+=t.type===`context`?t.lines:t.deletions+t.additions}return n}function pl(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var ml=1e3,hl=ml*4,gl=[0,1e-6,.99999,1],_l={overscrollSize:ml,intersectionObserverMargin:hl,resizeDebugging:!1},vl=0,yl=-1,bl=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++yl}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={..._l,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:gl,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),hi(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),hi(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=Si({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-vl,newSize:e}),vl=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-vl,newSize:e}),vl=e))}t&&hi(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){gi(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+xl(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,hi(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{e.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=Si({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&pl(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),i=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&i.add(e);for(let e of this.instancesChanged)i.has(e)||e.onRender(t)&&i.add(e);this.scrollFix(r);for(let e of i)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&hi(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=xl(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=xl(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=xl(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=xl(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&hi(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function xl(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}function Sl(e){let t=(0,J.useRef)(e);return(0,J.useInsertionEffect)(()=>void(t.current=e)),(0,J.useCallback)((...e)=>t.current(...e),[])}var Cl=(0,J.createContext)(void 0);function wl({children:e,createEditor:t}){let n=(0,J.useRef)(new WeakMap),r=Sl(e=>{let r=n.current.get(e);if(r!=null)return r;let i=t(e);return n.current.set(e,i),i});return(0,X.jsx)(Cl.Provider,{value:r,children:e})}function Tl(){return(0,J.useContext)(Cl)}var El={position:`absolute`,top:0,bottom:0,textAlign:`center`,whiteSpace:`normal`,touchAction:`none`},Dl={display:`contents`};function Ol(){return null}function kl({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:r,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,renderGutterUtility:s,renderMergeConflictUtility:c,lineAnnotations:l,getHoveredLine:u,getInstance:d}){let f=n?.(e),p=r?.(e),m=i?.(e),h=a?.(e);return(0,X.jsxs)(X.Fragment,{children:[f==null?(0,X.jsxs)(X.Fragment,{children:[p!=null&&(0,X.jsx)(`div`,{slot:`header-prefix`,children:p}),m!=null&&(0,X.jsx)(`div`,{slot:`header-filename-suffix`,children:m}),h!=null&&(0,X.jsx)(`div`,{slot:`header-metadata`,children:h})]}):(0,X.jsx)(`div`,{slot:$e,children:f}),o!=null&&l?.map((e,t)=>(0,X.jsx)(`div`,{slot:to(e),children:o(e)},t)),t!=null&&c!=null&&d!=null&&t.map(t=>{if(t==null)return;let n=Al(t,e);return(0,X.jsx)(`div`,{slot:n,style:Dl,children:c(t,d)},n)}),s!=null&&(0,X.jsx)(`div`,{slot:`gutter-utility-slot`,style:El,children:s(u)})]})}function Al(e,t){let n=dl(e,t);return n==null?void 0:ul({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex})}function jl({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,lineAnnotations:o,renderGutterUtility:s,getHoveredLine:c}){let l=t?.(e),u=n?.(e),d=r?.(e),f=i?.(e);return(0,X.jsxs)(X.Fragment,{children:[l==null?(0,X.jsxs)(X.Fragment,{children:[u!=null&&(0,X.jsx)(`div`,{slot:`header-prefix`,children:u}),d!=null&&(0,X.jsx)(`div`,{slot:`header-filename-suffix`,children:d}),f!=null&&(0,X.jsx)(`div`,{slot:`header-metadata`,children:f})]}):(0,X.jsx)(`div`,{slot:$e,children:l}),a!=null&&o?.map((e,t)=>(0,X.jsx)(`div`,{slot:to(e),children:a(e)},t)),s!=null&&(0,X.jsx)(`div`,{slot:`gutter-utility-slot`,style:El,children:s(c)})]})}function Ml(e,t){return typeof window>`u`&&t!=null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,X.jsx)(X.Fragment,{children:e})}var Nl=(0,J.createContext)(void 0);function Pl({children:e,config:t,className:n,style:r,contentClassName:i,contentStyle:a}){let[o]=(0,J.useState)(()=>typeof window<`u`?new bl(t):void 0),s=(0,J.useCallback)(e=>{e==null?o?.cleanUp():o?.setup(e)},[o]);return(0,X.jsx)(Nl.Provider,{value:o,children:(0,X.jsx)(`div`,{className:n,style:r,ref:s,children:(0,X.jsx)(`div`,{className:i,style:a,children:e})})})}function Fl(){return(0,J.useContext)(Nl)}var Il=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Ll({file:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=Fl(),f=i!==void 0,p=(0,J.useContext)(un),m=Tl(),h=(0,J.useRef)(null),g=Sl(n=>{if(n!=null){if(h.current!=null)throw Error(`File: An instance should not already exist when a node is created`);d==null?h.current=new Jo(Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new es(Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({file:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`File: A File instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return Il(()=>{if(h.current==null)return;let n=Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),a=n!==void 0&&!yi(h.current.options,n);h.current.setOptions(n),h.current.render({file:e,lineAnnotations:r,forceRender:a}),i!==void 0&&h.current.setSelectedLines(i)}),Il(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`File: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`File: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,J.useCallback)(()=>h.current?.getHoveredLine(),[])}}function Rl({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Ol:e?.renderCustomHeader,renderGutterUtility:r?Ol:e?.renderGutterUtility}:e}function zl({file:e,lineAnnotations:t,selectedLines:n,options:r,editorOptions:i,metrics:a,className:o,style:s,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,prerenderedHTML:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:g=!1}){let{ref:_,getHoveredLine:v}=Ll({file:e,options:r,editorOptions:i,metrics:a,lineAnnotations:t,selectedLines:n,prerenderedHTML:p,hasGutterRenderUtility:m!=null,hasCustomHeader:l!=null,disableWorkerPool:h,edit:g});return(0,X.jsx)(Fe,{ref:_,className:o,style:s,children:Ml(jl({file:e,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,renderGutterUtility:m,lineAnnotations:t,getHoveredLine:v}),p)})}var Bl=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Vl({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=Fl(),f=i!==void 0,p=(0,J.useContext)(un),m=Tl(),h=(0,J.useRef)(null),g=Sl(n=>{if(n!=null){if(h.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?h.current=new Rc(Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new Xc(Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return Bl(()=>{let{current:n}=h;if(n==null)return;let a=Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!yi(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),Bl(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,J.useCallback)(()=>h.current?.getHoveredLine(),[])}}function Hl({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Ol:e?.renderCustomHeader,renderGutterUtility:r?Ol:e?.renderGutterUtility}:e}function Ul({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,className:o,style:s,prerenderedHTML:c,renderAnnotation:l,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:g=!1}){let{ref:_,getHoveredLine:v}=Vl({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,prerenderedHTML:c,hasGutterRenderUtility:m!=null,hasCustomHeader:u!=null,disableWorkerPool:h,edit:g});return(0,X.jsx)(Fe,{ref:_,className:o,style:s,children:Ml(kl({fileDiff:e,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderAnnotation:l,renderGutterUtility:m,lineAnnotations:i,getHoveredLine:v}),c)})}function Wl(e){let{environmentId:t,threadId:n,fromTurnCount:r,toTurnCount:i,ignoreWhitespace:a,cacheScope:o}=e,s=e.enabled,l=E(e)?c(e):null;(0,J.useEffect)(()=>{if(l!==null)return T({environmentId:t,threadId:n,fromTurnCount:r,toTurnCount:i,ignoreWhitespace:a,...o===void 0?{}:{cacheScope:o},...s===void 0?{}:{enabled:s}})},[l,t,n,r,i,a,o,s]);let u=d(l===null?b:x(l));return l===null?h:u}var Gl=`\0`,Kl=1/0,ql=1;function Jl(e){return`${e.turnId}${Gl}${e.filePath}${Gl}${e.blobSha}`}var Yl=class{#e;#t;constructor(e=50){if(!Number.isInteger(e)||e<=0)throw RangeError(`DiffParseCache maxEntries must be a positive integer, received ${String(e)}`);this.#t=e,this.#e=new Zt(e,Kl)}get maxEntries(){return this.#t}get(e){return this.#e.get(Jl(e))??void 0}set(e,t){this.#e.set(Jl(e),t,ql)}getOrCompute(e,t){let n=this.get(e);if(n!==void 0)return n;let r=t();return this.set(e,r),r}clear(){this.#e.clear()}};function Xl(e){let t=e.name??e.prevName??``;return t.startsWith(`a/`)||t.startsWith(`b/`)?t.slice(2):t}function Zl(e,t=!1){let n=e.trim();return t?n:n.toLowerCase()}function Ql(e,t){t.text!==void 0&&e.push({fileIndex:t.fileIndex,field:t.field,text:t.text,normalizedText:t.text.toLowerCase(),...t.lineIndex===void 0?{}:{lineIndex:t.lineIndex},...t.unifiedLineIndex===void 0?{}:{unifiedLineIndex:t.unifiedLineIndex},...t.splitLineIndex===void 0?{}:{splitLineIndex:t.splitLineIndex}})}function $l(e,t,n){t.additionLines.forEach((t,r)=>{Ql(e,{fileIndex:n,field:`addition`,lineIndex:r,text:t})}),t.deletionLines.forEach((t,r)=>{Ql(e,{fileIndex:n,field:`deletion`,lineIndex:r,text:t})})}function eu(e,t,n){if(!t.hunks||t.hunks.length===0)return!1;for(let r of t.hunks){let i=r.unifiedLineStart,a=r.splitLineStart;for(let o of r.hunkContent){if(o.type===`context`){for(let r=0;r<o.lines;r+=1){let s=o.additionLineIndex+r,c=o.deletionLineIndex+r;Ql(e,{fileIndex:n,field:`context`,lineIndex:s,unifiedLineIndex:i+r,splitLineIndex:a+r,text:t.additionLines[s]??t.deletionLines[c]})}i+=o.lines,a+=o.lines;continue}for(let r=0;r<o.deletions;r+=1){let s=o.deletionLineIndex+r;Ql(e,{fileIndex:n,field:`deletion`,lineIndex:s,unifiedLineIndex:i+r,splitLineIndex:a+r,text:t.deletionLines[s]})}for(let r=0;r<o.additions;r+=1){let s=o.additionLineIndex+r;Ql(e,{fileIndex:n,field:`addition`,lineIndex:s,unifiedLineIndex:i+o.deletions+r,splitLineIndex:a+r,text:t.additionLines[s]})}i+=o.deletions+o.additions,a+=Math.max(o.deletions,o.additions)}}return!0}function tu(e){let t=[];return e.forEach((e,n)=>{Ql(t,{text:Xl(e),fileIndex:n,field:`path`}),e.prevName&&Ql(t,{text:Xl({name:e.prevName}),fileIndex:n,field:`previousPath`}),eu(t,e,n)||$l(t,e,n)}),{records:t}}function nu(e){let t=e.caseSensitive?e.record.text:e.record.normalizedText,n=[],r=0;for(;;){let i=t.indexOf(e.needle,r);if(i===-1)return n;let a=i+e.needle.length;n.push({fileIndex:e.record.fileIndex,field:e.record.field,...e.record.lineIndex===void 0?{}:{lineIndex:e.record.lineIndex},...e.record.unifiedLineIndex===void 0?{}:{unifiedLineIndex:e.record.unifiedLineIndex},...e.record.splitLineIndex===void 0?{}:{splitLineIndex:e.record.splitLineIndex},start:i,end:a}),r=a>i?a:i+1}}function ru(e){return!Array.isArray(e)}function iu(e,t,n){let r=n?.caseSensitive??!1,i=Zl(t,r);if(!i)return[];let a=ru(e)?e:tu(e),o=[];for(let e of a.records)o.push(...nu({record:e,needle:i,caseSensitive:r}));return o}function au(e){return[...new Set(e.map(e=>e.fileIndex))]}function ou(e){let t=new Map;for(let n of e){let e=t.get(n.fileIndex);e?e.push(n):t.set(n.fileIndex,[n])}return t}function su(e,t,n){return t<=0?0:(e+n+t)%t}function cu(e,t){return e.field===`path`||e.field===`previousPath`?null:(t===`split`?e.splitLineIndex:e.unifiedLineIndex)??e.lineIndex??null}function lu(e){return e===`addition`||e===`deletion`||e===`context`}function uu(e){if(!e)return null;let[t,n]=e.split(`,`),r=Number.parseInt(t??``,10);if(!Number.isFinite(r))return null;let i=Number.parseInt(n??``,10);return{stacked:r,split:Number.isFinite(i)?i:r}}function du(e,t){if(!lu(e.field)||cu(e,t.renderMode)!==(t.renderMode===`split`?t.lineIndexes.split:t.lineIndexes.stacked))return!1;switch(e.field){case`addition`:return t.lineType===`change-addition`||t.lineType===`addition`;case`deletion`:return t.lineType===`change-deletion`||t.lineType===`deletion`;case`context`:return t.lineType===`context`||t.lineType===`context-expanded`}}function fu(e){let t=e.cwd?wn(e.filePath,e.cwd):e.filePath;return typeof e.lineNumber==`number`?`${t}:${e.lineNumber}`:t}var pu=`
1365
+ `}function kc(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function Ac(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function jc(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Mc(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}async function Nc(e,t=300){let n;try{await Promise.race([e(),new Promise(e=>{n=setTimeout(e,t)})])}finally{n!=null&&clearTimeout(n)}}function Pc({oldFile:e,newFile:t},n){if(e!==void 0||t!==void 0){if(e===void 0||t===void 0)throw Error(`${n}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw Error(`${n}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return{oldFile:e,newFile:t}}}function Fc(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:Io(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators==`function`?`custom`:e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Ic(e){return e.isPartial&&(e.type===`change`||e.type===`rename-changed`||e.type===`rename-pure`)}var Lc=-1,Rc=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Lc}`;type=`file-diff`;fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:W},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Ia,this.scrollSyncManager=new ps,this.interactionManager=new ga(`diff`,_a(e,typeof e.hunkSeparators==`function`||(e.hunkSeparators??`line-info`)===`line-info`||e.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return Fc(e)}createHunksRenderer(e){return new mc(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t=`additions`)=>{let n=this.fileDiffCache;if(n==null)return;let r=n.hunks.at(-1),i,a;hunkIterator:for(let o of n.hunks){let n=t===`deletions`?o.deletionStart:o.additionStart,s=t===`deletions`?o.deletionCount:o.additionCount,c=Le(n,s)+1,l=o.splitLineStart,u=o.unifiedLineStart;if(e<c){let t=c-e;i=Math.max(u-t,0),a=Math.max(l-t,0);break hunkIterator}if(e>=c+s){if(o===r){let t=e-(c+s);i=u+o.unifiedLineCount+t,a=l+o.splitLineCount+t;break hunkIterator}continue}for(let n of o.hunkContent)if(n.type===`context`){if(e<c+n.lines){let t=e-c;a=l+t,i=u+t;break hunkIterator}c+=n.lines,l+=n.lines,u+=n.lines}else{let r=t===`deletions`?n.deletions:n.additions;if(e<c+r){let r=e-c;i=u+(t===`additions`?n.deletions:0)+r,a=l+r;break hunkIterator}c+=r,l+=Math.max(n.deletions,n.additions),u+=n.deletions+n.additions}break hunkIterator}if(i!=null&&a!=null)return[i,a]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(_a(this.options,typeof this.options.hunkSeparators==`function`||(this.options.hunkSeparators??`line-info`)===`line-info`||this.options.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex))}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;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType!==t&&(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Vt(this.appliedThemeCSS.theme,this.options.theme??W)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators==`function`)}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}flushDeferredLineState(){let{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e=`split`,overflow:t=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t===`wrap`,columnVariables:this.shouldApplyColumnVariables(t)?`apply`:`measure`}),t===`scroll`&&e===`split`?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators==`function`||e===`scroll`&&(this.lineAnnotations.length>0||this.pre?.hasAttribute(`data-has-merge-conflict`)===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){gi(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:r,fileDiff:i,...a}){if(!this.enabled)throw Error(`FileDiff.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated`);let o=Pc(a,`FileDiff.hydrate`),s=o?.oldFile,c=o?.newFile;this.hydrateElements(e,t),Hc(this.pre,Bc({fileDiff:i,oldFile:s,newFile:c}),this.options.collapsed)||Uc(this.headerElement,Vc({fileDiff:i,oldFile:s,newFile:c}),this.options.disableFileHeader)?this.render({...a,fileContainer:e,lineAnnotations:r,fileDiff:i,preventEmit:!0}):this.hydrationSetup({fileDiff:i,lineAnnotations:r,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),No(e,t);for(let t of e.shadowRoot?.children??[]){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t;for(let e of t.children)!(e instanceof HTMLElement)||e.tagName.toLowerCase()!==`code`||(`deletions`in e.dataset&&(this.codeDeletions=e),`additions`in e.dataset&&(this.codeAdditions=e),`unified`in e.dataset&&(this.codeUnified=e));continue}if(`diffsHeader`in t.dataset){this.headerElement=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:r}){this.lineAnnotations=r??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?da(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){let{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Ic(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{let n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(e){if(this.options.disableErrorHandling===!0)throw e;console.error(e)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(is(`merge`,e,t),this.setHydratedState(t),await Nc(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:r=!1,lineAnnotations:i,fileContainer:a,containerWrapper:o,renderRange:s,...c}){let l=Pc(c,`FileDiff.render`),u=l?.oldFile,d=l?.newFile;if(!this.enabled)throw Error(`FileDiff.render: attempting to call render after cleaned up`);e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName==null?e.name:e.prevName+`:`+e.name),this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:f=!1,themeType:p=`system`,expandUnchanged:m=!1}=this.options,h=f?void 0:s,g=this.hasThemeChanged(),_=l!=null,v=_&&(!zc(u,this.deletionFile)||!zc(d,this.additionFile)),y=e!=null&&e!==this.fileDiff,b=i!=null&&(i.length>0||this.lineAnnotations.length>0)&&i!==this.lineAnnotations;if(!f&&Ka(h,this.renderRange)&&!n&&!b&&!g&&(e!=null&&e===this.fileDiff||e==null&&!v))return this.applyCachedThemeState(p);let x;e==null&&_&&(v||this.fileDiff==null)&&(x=da(l.oldFile,l.newFile,this.options.parseDiffOptions));let{renderRange:S}=this;if(this.renderRange=h,_?(this.deletionFile=u,this.additionFile=d):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e==null?x!=null&&(y=!0,this.fileDiff=x):this.fileDiff=e,y&&(this.cachedHeaderHTML=void 0),i!=null&&this.setLineAnnotations(i),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(Zs(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),m&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:C=!1,disableFileHeader:w=!1}=this.options;if(w&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,o),this.applyCachedThemeState(p),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let e=this.hunksRenderer.renderDiff(this.fileDiff,pt);e!=null&&this.applyThemeState(a,e.themeStyles,p,e.baseThemeType),e?.headerElement!=null&&this.applyHeaderToDOM(e.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}try{let e=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(n,b,v||y||g)&&this.applyPartialRender({previousRenderRange:S,renderRange:h}))){let t=this.hunksRenderer.renderDiff(this.fileDiff,h);if(t==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,t.themeStyles,p,t.baseThemeType),t.headerElement!=null&&this.applyHeaderToDOM(t.headerElement,a),t.additionsContentAST!=null||t.deletionsContentAST!=null||t.unifiedContentAST!=null?this.applyHunksToDOM(e,t):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(t.hunkData)}this.applyBuffers(e,h),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.fileDiffCache,r=this.lineAnnotations,i=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(a,t,n,r,i)})}computeEditorRenderRange(e){let t=this.fileDiffCache;if(e==null||t==null||bs(e))return e;let{diffStyle:n=`split`,expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a,o;return Qe({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({additionLine:e})=>{e!=null&&(a??=e.lineNumber,o=e.lineNumber)}}),a==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:a-1,totalLines:o-a+1}}attachEditor(e){if(this.type!==`file-diff`)throw Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),e=>{this.editor=void 0,e!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){let e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;let{collapsedContextThreshold:t=1}=this.options,n=Ys(e,this.hunksRenderer.getExpandedHunksMap(),t);return Zs(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(Xs(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);let n=this.hunksRenderer.diffCache;if(n!=null){let e=this.fileDiff?.cacheKey;e!=null&&n.cacheKey==null&&(n.cacheKey=e),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){let{shouldRefreshDiffsView:r,lineCountChangeInFlight:i}=n;if(this.hunksRenderer.updateRenderCache(e,t,i)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}r===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle===`split`?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){let t=this.fileDiffCache;if(t==null)return!0;let{expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options;return ft({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r})}getNearestRenderableLine(e,t){let n=this.fileDiffCache;if(n==null)return e;let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options;return We({fileDiff:n,lineNumber:e,direction:t,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}revealLine(e){let t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:r=1,expansionLineCount:i=100}=this.options;if(t==null||t.isPartial||n)return!1;let a=this.hunksRenderer.getExpandedHunksMap();for(let[n,o]of t.hunks.entries()){let[s,c]=rt(o);if(e<s){let c=et({isPartial:t.isPartial,rangeSize:o.collapsedBefore,expandedHunks:a,hunkIndex:n,collapsedContextThreshold:r}),l=s-c.rangeSize;if(c.renderAll||e<l+c.fromStart||e>=s-c.fromEnd)return!1;let u=e-(l+c.fromStart)+1,d=s-c.fromEnd-e;return u<=d?this.expandHunk(n,`up`,u+i):this.expandHunk(n,`down`,d+i),!0}if(e<c)return!1}let o=G({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:a,collapsedContextThreshold:r,errorPrefix:`FileDiff.revealLine`});if(o==null||o.renderAll)return!1;let s=t.hunks[t.hunks.length-1],[,c]=rt(s);return e<c+o.fromStart||e>=c+o.rangeSize?!1:(this.expandHunk(t.hunks.length,`up`,e-(c+o.fromStart)+1+i),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){hi(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}async primeHighlightCache(e=this.fileDiff){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Me(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.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.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=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}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!=`function`){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let r of e){let e=r.slotName,i=this.separatorCache.get(e);if(i==null||!Mc(r,i.hunkData)){i?.element.remove();let n=document.createElement(`div`);n.style.display=`contents`,n.slot=r.slotName;let a=t(r,this);a!=null&&n.appendChild(a),this.fileContainer.appendChild(n),i={element:n,hunkData:r},this.separatorCache.set(e,i)}n.delete(e)}for(let[e,{element:t}]of n.entries())this.separatorCache.delete(e),t.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${to(r)}`,a=this.annotationCache.get(i);if(a==null||!jc(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:yo(to(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=bo();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return n!=null&&i&&this.editor?.__captureFocusForDOMReplacement(),i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:Fo(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):Fo(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=mo;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});return this.pre==null?(this.pre=document.createElement(`pre`),this.appliedPreAttributes=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute(`data-unified`)?this.codeUnified=t:t.hasAttribute(`data-deletions`)?this.codeDeletions=t:t.hasAttribute(`data-additions`)&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,r=this.cachedHeaderHTML??St(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:i,renderHeaderPrefix:a,renderHeaderFilenameSuffix:o,renderHeaderMetadata:s}=this.options;if(i!=null){let e=i(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,$e,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}let c=a?.(n)??void 0,l=o?.(n)??void 0,u=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,$t,c),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ve,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Ye,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}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}injectUnsafeCSS(){let{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??=xo(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Oo(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??W,s=typeof o==`string`?o:{...o},c=wo(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=zo({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ko(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=Ao(this.themeCSSStyle.textContent??``,wo(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Wo()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?Ro(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){let r=this.getColumnPair(e);if(r==null)return!1;let i=Wc(t[0]),a=Wc(t[1]);return i==null||a==null?!1:(r.gutter.innerHTML=St(i),r.content.innerHTML=St(a),n!==this.lastRowCount&&(r.gutter.style.setProperty(`grid-row`,`span ${n}`),r.content.style.setProperty(`grid-row`,`span ${n}`)),!0)}replaceCodeColumns(e,t){let{overflow:n=`scroll`}=this.options,r=(this.options.hunkSeparators??`line-info`)===`line-info`,i=n===`wrap`?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let a=!1,o=[],s=this.hunksRenderer.renderCodeAST(`unified`,t),c=this.hunksRenderer.renderCodeAST(`deletions`,t),l=this.hunksRenderer.renderCodeAST(`additions`,t);this.editor?.__captureFocusForDOMReplacement(),s==null?c!=null||l!=null?(c==null?(this.codeDeletions?.remove(),this.codeDeletions=void 0):(a=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Mo({code:this.codeDeletions,columnType:`deletions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeDeletions,c,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(c)),o.push(this.codeDeletions)),l==null?(this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=a||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Mo({code:this.codeAdditions,columnType:`additions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeAdditions,l,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeAdditions))):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Mo({code:this.codeUnified,columnType:`unified`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeUnified,s,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s)),o.push(this.codeUnified)),o.length===0?e.textContent=``:a&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:r,codeAdditions:i,codeDeletions:a,options:{diffStyle:o=`split`}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(o,r,a,i);if(s==null)return!1;let c=e.startingLine,l=t.startingLine,u=c+e.totalLines,d=l+t.totalLines,f=Math.max(c,l),p=Math.min(u,d);if(p<=f)return!1;let m=Math.max(0,f-c),h=Math.max(0,u-p),g=this.trimColumns({columns:s,trimStart:m,trimEnd:h,previousStart:c,overlapStart:f,overlapEnd:p,diffStyle:o});if(g<0)throw Error(`FileDiff.applyPartialRender: failed to trim to overlap`);if(this.lastRowCount<g)throw Error(`FileDiff.applyPartialRender: trimmed beyond DOM row count`);let _=this.lastRowCount-g,v=(e,t)=>{if(!(t<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},y=v(l,Math.max(f-l,0));if(y==null&&l<f)return!1;let b=v(p,Math.max(d-p,0));if(b==null&&d>p)return!1;let x=(e,t)=>{if(e!=null){if(o===`unified`&&!Array.isArray(s))this.insertPartialHTML(o,s,e,t);else if(o===`split`&&Array.isArray(s))this.insertPartialHTML(o,s,e,t);else throw Error(`FileDiff.applyPartialRender.applyChunk: invalid chunk application`);_+=e.rowCount}};return this.cleanupErrorWrapper(),x(y,`afterbegin`),x(b,`beforeend`),this.lastRowCount!==_&&(this.applyRowSpan(o,s,_),this.lastRowCount=_),!0}insertPartialHTML(e,t,n,r){if(e===`unified`&&!Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`unified`,n);this.renderPartialColumn(t,e,r)}else if(e===`split`&&Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`deletions`,n),i=this.hunksRenderer.renderCodeAST(`additions`,n);this.renderPartialColumn(t[0],e,r),this.renderPartialColumn(t[1],i,r)}else throw Error(`FileDiff.insertPartialHTML: Invalid argument composition`)}refreshSplitDiffView(){if(this.options.diffStyle!==`split`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`split`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;let n=(t,n)=>{if(n==null)return;let r=this.hunksRenderer.renderCodeAST(t,e),i=Wc(r?.[0]),a=Wc(r?.[1]);for(let[e,t]of[[n.gutter,i],[n.content,a]])if(t!=null&&e.childElementCount===t.length)for(let n=0;n<t.length;n++){let r=e.children[n],i=t[n].properties[`data-line-type`];i!=null&&r.dataset.lineType!==i&&(r.dataset.lineType=i)}};n(`deletions`,t[0]),n(`additions`,t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!==`unified`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`unified`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;let n=this.hunksRenderer.renderCodeAST(`unified`,e),r=Wc(n?.[0]),i=Wc(n?.[1]),a=()=>{for(let[e,n]of[[t.gutter,r],[t.content,i]])n!=null&&(e.innerHTML=St(n));e.rowCount!==this.lastRowCount&&(this.applyRowSpan(`unified`,t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?Ro(this.pre,a):a(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;let r=Wc(t[0]),i=Wc(t[1]);if(r==null||i==null)throw Error(`FileDiff.insertPartialHTML: Unexpected AST structure`);let a=i.at(0);n===`beforeend`&&a?.type===`element`&&typeof a.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(a.properties[`data-buffer-size`],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],r,i,!0);let o=i.at(-1);n===`afterbegin`&&o?.type===`element`&&typeof o.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(o.properties[`data-buffer-size`],e.content.children[0],e.gutter.children[0],r,i,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(r)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i))}mergeBuffersIfNecessary(e,t,n,r,i,a){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let o=this.getBufferSize(t.dataset);o!=null&&(a?(r.shift(),i.shift()):(r.pop(),i.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){let r=e=>{e!=null&&(e.gutter.style.setProperty(`grid-row`,`span ${n}`),e.content.style.setProperty(`grid-row`,`span ${n}`))};if(e===`unified`&&!Array.isArray(t))r(t);else if(e===`split`&&Array.isArray(t))r(t[0]),r(t[1]);else throw Error(`dun fuuuuked up`)}trimColumnRows(e,t,n){let r=0,i=0,a=0,o=!1,s=n>=0;if(e==null)return 0;let c=Array.from(e.content.children),l=Array.from(e.gutter.children);if(c.length!==l.length)throw Error(`FileDiff.trimColumnRows: columns do not match`);for(;a<c.length&&!(t<=0&&!s&&!o);){let e=l[a],u=c[a];if(a++,!(e instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: invalid row elements`);if(o&&(o=!1,e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset||e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset)){e.remove(),u.remove(),i++;continue}if(`lineIndex`in e.dataset&&`lineIndex`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),i++),r++;continue}if(`separator`in e.dataset&&`separator`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`buffer`&&`contentBuffer`in u.dataset){let a=this.getBufferSize(u.dataset);if(a==null)throw Error(`FileDiff.trimColumnRows: invalid element`);if(t>0){let n=Math.min(t,a),r=a-n;r>0?(this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=n):(e.remove(),u.remove(),i+=a),t-=n,t===0&&r===0&&(o=!0)}else if(s){let t=r,o=r+a-1;if(n<=t)e.remove(),u.remove(),i+=a;else if(n<=o){let t=o-n+1,r=a-t;this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=t}}r+=a;continue}throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: unknown row elements`)}return i}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:r,previousStart:i,trimEnd:a,trimStart:o}){let s=Math.max(0,r-i),c=n-i;if(c<0)throw Error(`FileDiff.trimColumns: overlap ends before previous`);let l=o>0,u=a>0;if(!l&&!u)return 0;let d=l?s:0,f=u?c:-1;if(t===`unified`&&!Array.isArray(e))return this.trimColumnRows(e,d,f);if(t===`split`&&Array.isArray(e)){let t=this.trimColumnRows(e[0],d,f),n=this.trimColumnRows(e[1],d,f);if(e[0]!=null&&e[1]!=null&&t!==n)throw Error(`FileDiff.trimColumns: split columns out of sync`);return e[0]==null?n:t}throw console.error({diffStyle:t,columns:e}),Error(`FileDiff.trimColumns: Invalid columns for diffType`)}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??``,10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty(`grid-row`,`span ${t}`),e.style.setProperty(`min-height`,`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;let 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}}getCodeColumns(e,t,n,r){if(e===`unified`)return this.getColumnPair(t);{let e=this.getColumnPair(n),t=this.getColumnPair(r);return e!=null||t!=null?[e,t]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}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??(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??(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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:r},i){let{diffIndicators:a=`bars`,disableBackground:o=!1,disableLineNumbers:s=!1,overflow:c=`scroll`,diffStyle:l=`split`}=this.options,u={type:`diff`,diffIndicators:a,disableBackground:o,disableLineNumbers:s,overflow:c,split:l!==`unified`&&t!=null&&n!=null,totalLines:r,customProperties:i};go(u,this.appliedPreAttributes)||(Po(e,u),this.appliedPreAttributes=u)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function zc(e,t){return e==null||t==null?e==null&&t==null:fn(e,t)}function Bc({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Vc({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Hc(e,t,n=!1){return!n&&e==null&&t}function Uc(e,t,n=!1){return e==null&&t&&!n}function Wc(e){if(e!=null&&e.type===`element`)return e.children??[]}function Gc({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:r,expandUnchanged:i,expandedHunks:a,collapsedContextThreshold:o,canHydratePartialDiff:s}){let c=Be(t,n),l=c,u=i?!0:a,d=e.hunks.length-1;for(let n=0;n<e.hunks.length;n++){let i=e.hunks[n];if(i==null)throw Error(`computeEstimatedDiffHeights: invalid hunk index`);let a=et({isPartial:e.isPartial,rangeSize:i.collapsedBefore,expandedHunks:u,hunkIndex:n,collapsedContextThreshold:o}),f=(a.fromStart+a.fromEnd)*t.lineHeight;if(c+=f,l+=f,a.collapsedLines>0){let e=ze({type:r,metrics:t,hunkIndex:n,hunkSpecs:i.hunkSpecs})?.totalHeight??0;c+=e,l+=e}c+=i.splitLineCount*t.lineHeight,l+=i.unifiedLineCount*t.lineHeight;let p=Kc(i);c+=p.split*t.lineHeight,l+=p.unified*t.lineHeight;let m=n===d?G({fileDiff:e,hunkIndex:n,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:`computeEstimatedDiffHeights`}):void 0;if(m!=null){let e=(m.fromStart+m.fromEnd)*t.lineHeight;if(c+=e,l+=e,m.collapsedLines>0){let e=mn({type:r,metrics:t})?.totalHeight??0;c+=e,l+=e}}else if(n===d&&e.isPartial&&s){let e=mn({type:r,metrics:t})?.totalHeight??0;c+=e,l+=e}}if(e.hunks.length>0){let e=Je(t);c+=e,l+=e}return{splitHeight:c,unifiedHeight:l}}function Kc(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};let t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type===`context`){let e=+(t.lines>0);return{split:e,unified:e}}return qc(e,t)}function qc(e,t){let n=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),r=t.deletions>0&&e.noEOFCRDeletions,i=t.additions>0&&e.noEOFCRAdditions;return{split:r||i?1:0,unified:n}}var Jc=3e3,Yc=-1,Xc=class extends Rc{__id=`little-virtualized-file-diff:${++Yc}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=mt(n)}setMetrics(e,t=!1){let n=mt(e);!t&&vi(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){let t=this.cache.fileAnnotationHeight;return e!==t&&(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!io(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber===0?e.type===`new`?t.side===`additions`:e.type!==`deleted`||t.side===`deletions`:!1)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){let t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!yi(t,e),r=n&&il(t,e);super.setOptions(e),r&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:al(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1,{overflow:t=`scroll`}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;let n=this.getDiffStyle(),r=n===`split`?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],i=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&i&&oo(this.renderRange)){let t=Zc(r)??0;this.setFileAnnotationHeight(t)&&(e=!0)}else!i&&this.setFileAnnotationHeight(0)&&(e=!0);for(let t of r){if(t==null)continue;let r=t.children[1];if(r instanceof HTMLElement)for(let t of r.children){if(!(t instanceof HTMLElement))continue;let r=t.dataset.lineIndex;if(r==null)continue;let i=ll(r,n),a=t.getBoundingClientRect().height,o=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(o=!0),a+=t.nextElementSibling.getBoundingClientRect().height);let s=this.getEstimatedLineHeight(o),c=this.cache.heightDeltas.get(i)??0,l=a-s;l!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=l-c,l===0?this.cache.heightDeltas.delete(i):this.cache.heightDeltas.set(i,l))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer!=null&&(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,r){let i=!ut(this.fileDiff,e),a=this.syncLineAnnotations(r),o=n?.resetDiffLayoutCache===!0||i||a,s=i||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=mt(n.metrics),o=!0,s=!0);let{collapsed:c=!1,expandUnchanged:l=!1}=this.options;return this.currentCollapsed!==c&&(this.currentCollapsed=c,o=!0),this.currentExpandUnchanged!==l&&(this.currentExpandUnchanged=l,o=!0,s=!0),o&&this.resetLayoutCache({includeEstimatedHeights:s}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t=`additions`){if(this.fileDiff==null||e<1)return;let n=this.getLineIndex(e,t);if(n==null)return;let{disableFileHeader:r=!1,expandUnchanged:i=!1,collapsed:a=!1,collapsedContextThreshold:o=1}=this.options,s=this.getDiffStyle(),c=this.getHunkSeparatorType(),l=s===`split`?n[1]:n[0];this.approximateLayoutCheckpoints();let u=Be(this.metrics,r),d=this.getLayoutCheckpointBeforeLineIndex(l),f=d?.top??u+this.cache.fileAnnotationHeight;if(a)return{top:u,height:0};let p;return Qe({diff:this.fileDiff,diffStyle:s,startingLine:d?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:e,hunk:t,collapsedBefore:n,collapsedAfter:r,deletionLine:i,additionLine:a})=>{let o=s===`split`?a?.splitLineIndex??i?.splitLineIndex:a?.unifiedLineIndex??i?.unifiedLineIndex;if(o==null)throw Error(`VirtualizedFileDiff.getLinePosition: missing line index data`);if(n>0){let r=ze({type:c,metrics:this.metrics,hunkIndex:e,hunkSpecs:t?.hunkSpecs});if(r!=null){if(f+=r.gapBefore,l>=o-n&&l<o)return p={top:f,height:r.height},!0;f+=r.height+r.gapAfter}}let u=this.getLineHeight(o,(a?.noEOFCR??!1)||(i?.noEOFCR??!1));if(o===l)return p={top:f,height:u},!0;if(f+=u,r>0){let e=mn({type:c,metrics:this.metrics});if(e!=null){if(l>o&&l<=o+r)return p={top:f+e.gapBefore,height:e.height},!0;f+=e.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:r=!1,collapsedContextThreshold:i=1}=this.options;if(r)return;let a=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();let s=this.getLayoutCheckpointBeforeTop(e),c=s?.top??Be(this.metrics,t)+this.cache.fileAnnotationHeight,l;return Qe({diff:this.fileDiff,diffStyle:a,startingLine:s?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,deletionLine:s,additionLine:u})=>{let d=a===`split`?u?.splitLineIndex??s?.splitLineIndex:u?.unifiedLineIndex??s?.unifiedLineIndex;if(d==null)throw Error(`VirtualizedFileDiff.getNumericScrollAnchor: missing line index data`);if(r>0){let e=ze({type:o,metrics:this.metrics,hunkIndex:t,hunkSpecs:n?.hunkSpecs});e!=null&&(c+=e.totalHeight)}if(c>=e&&(s==null?u!=null&&(l={lineNumber:u.lineNumber,side:`additions`,top:c}):l={lineNumber:s.lineNumber,side:`deletions`,top:c},l!=null))return!0;let f=this.getLineHeight(d,(u?.noEOFCR??!1)||(s?.noEOFCR??!1));if(c+=f,i>0){let e=mn({type:o,metrics:this.metrics});e!=null&&(c+=e.totalHeight)}return!1}}),l}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.fileDiff,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){let n=is(`clone`,e,t);if(await Nc(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(is(`merge`,e,t),this.setHydratedState(t),await Nc(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n,{pendingExpansions:r,pendingHydratedDiff:i}=this;if(r!=null){this.pendingExpansions=void 0;for(let e of r)this.hunksRenderer.expandHunk(e.hunkIndex,e.direction,e.expansionLineCountOverride),t=!0}return i!=null&&(this.pendingHydratedDiff=void 0,i.expectedDiff===e&&(this.setHydratedState(i.files),n=i.nextDiff)),n==null?t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)):(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;let{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;let{expansionLineCount:r=100,collapsedContextThreshold:i=1}=this.options,a=new Map(this.hunksRenderer.getExpandedHunksMap());for(let e of t){let t={...a.get(e.hunkIndex)??{fromStart:0,fromEnd:0}},n=e.expansionLineCountOverride??r;(e.direction===`up`||e.direction===`both`)&&(t.fromStart+=n),(e.direction===`down`||e.direction===`both`)&&(t.fromEnd+=n),a.set(e.hunkIndex,t)}return ft({fileDiff:n,lineNumber:e,expandedHunks:a,collapsedContextThreshold:i})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{renderRange:r}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.fileDiff!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1}=this.options,o=Be(this.metrics,i);if(this.height+=o,a){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!r&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);let t=this.getDiffStyle()===`split`?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw Error(`VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height`);return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,{splitHeight:i,unifiedHeight:a}=Gc({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,canHydratePartialDiff:ol(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=i,this.cache.estimatedUnifiedHeight=a}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;let t=this.fileContainer.getBoundingClientRect();t.height===this.height?console.log(`VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFileDiff.computeApproximateSize: computed height doesnt match`,{name:e.name,elementHeight:t.height,computedHeight:this.height})}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:r,...i}={}){let a=Pc(i,`VirtualizedFileDiff.render`),o=a!=null,s=a?.oldFile,c=a?.newFile,l=o&&(!cl(s,this.deletionFile)||!cl(c,this.additionFile)),u=t??this.fileDiff;t==null&&o&&(l||this.fileDiff==null)&&(u=da(a.oldFile,a.newFile,this.options.parseDiffOptions));let{forceRenderOverride:d,isSetup:f}=this;this.forceRenderOverride=void 0;let p=this.syncLineAnnotations(r);p&&this.resetLayoutCache({includeEstimatedHeights:!1});let m=t!=null&&t!==this.fileDiff,h=u!=null&&!ut(this.fileDiff,u),g=m||l;if(h&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),u==null)return console.error(`VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data`),!1;if(f)this.top??=this.getVirtualizedTop(),h&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,u));else{this.computeApproximateSize(!1,u);let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFileDiff.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!g||!f))return this.fileDiff=u,a!=null&&(this.deletionFile=s,this.additionFile=c),h&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let _=this.virtualizer.getWindowSpecs(),v=this.top??0,y=this.computeRenderRangeFromWindow(u,v,_),b=super.render({fileDiff:u,fileContainer:e,renderRange:y,lineAnnotations:r,forceRender:(d??n)||p||h,...a,...i});return this.isSimpleMode()&&b&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),b}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type===`advanced`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??`split`}getHunkSeparatorType(){return sl(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,i=e.hunks.length-1,a=ol(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),s=this.getHunkSeparatorType(),c=n?!0:this.hunksRenderer.getExpandedHunksMap(),l=Qc(this.cache.heightDeltas),u=Be(this.metrics,t)+this.cache.fileAnnotationHeight,d=0,f=({rowCount:e,startLineIndex:t,preSeparatorHeight:n=0,postSeparatorHeight:r=0,metadataOffsets:i=[]})=>{if(e<=0)return;let a=d,o=d+e,s=tl(a);for(;s<o;){let e=s-a,r=u+(e>0?n:0)+e*this.metrics.lineHeight+nl(i,e)*this.metrics.lineHeight+$c(l,t,t+e);this.cache.checkpoints.push({renderedLineIndex:s,lineIndex:t+e,top:r}),s+=Jc}u+=n+e*this.metrics.lineHeight+i.length*this.metrics.lineHeight+$c(l,t,t+e)+r,d=o};for(let t=0;t<e.hunks.length;t++){let n=e.hunks[t];if(n==null)throw Error(`VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index`);let l=et({isPartial:e.isPartial,rangeSize:n.collapsedBefore,expandedHunks:c,hunkIndex:t,collapsedContextThreshold:r}),u=l.collapsedLines>0?ze({type:s,metrics:this.metrics,hunkIndex:t,hunkSpecs:n.hunkSpecs})?.totalHeight??0:0;f({rowCount:l.fromStart,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.rangeSize});let d=u;f({rowCount:l.fromEnd,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.fromEnd,preSeparatorHeight:d}),l.fromEnd>0&&(d=0);let p=t===i?G({fileDiff:e,hunkIndex:t,expandedHunks:c,collapsedContextThreshold:r,errorPrefix:`VirtualizedFileDiff`}):void 0,m=p!=null&&p.collapsedLines>0||t===i&&a?mn({type:s,metrics:this.metrics})?.totalHeight??0:0,h=p==null?0:p.fromStart+p.fromEnd,g=o===`split`?n.splitLineCount:n.unifiedLineCount,_=o===`split`?n.splitLineStart:n.unifiedLineStart;f({rowCount:g,startLineIndex:_,preSeparatorHeight:d,postSeparatorHeight:h===0?m:0,metadataOffsets:rl({diffStyle:o,hunk:n,rowCount:g})}),p!=null&&h>0&&f({rowCount:h,startLineIndex:_+g,postSeparatorHeight:m})}this.cache.totalLines=d}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFileDiff: invalid checkpoint index`);if(n.renderedLineIndex%t===0)return n}}getExpandedLineCount(e,t){let n=0;if(e.isPartial){for(let r of e.hunks)n+=t===`split`?r.splitLineCount:r.unifiedLineCount;return n}let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a=r?!0:this.hunksRenderer.getExpandedHunksMap();for(let[r,o]of e.hunks.entries()){let s=t===`split`?o.splitLineCount:o.unifiedLineCount;n+=s;let c=Math.max(o.collapsedBefore,0),{fromStart:l,fromEnd:u,renderAll:d}=et({isPartial:e.isPartial,rangeSize:c,expandedHunks:a,hunkIndex:r,collapsedContextThreshold:i});c>0&&(n+=d?c:l+u)}let o=G({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:`VirtualizedFileDiff`});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){let n=this.getExpandedLineCount(e,t),r=t===`split`?e.splitLineCount:e.unifiedLineCount;return Math.max(n,r,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,expandUnchanged:a=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:s,lineHeight:c}=this.metrics,l=this.getDiffStyle(),u=this.getHunkSeparatorType(),d=ol(e,this.options.loadDiffFiles!=null),f=this.height,p=this.getLayoutLineCount(e,l),m=Be(this.metrics,i),h=e.hunks.length>0?Je(this.metrics):0,{fileAnnotationHeight:g}=this.cache,_=m+g,v=Math.max(0,f-m-g-h),y=this.hasFileAnnotations(e),b=t+m,x=g>0&&y&&b<r&&b+g>n;if(t<n-f||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h};if(p<=s||e.hunks.length===0)return{startingLine:0,totalLines:s,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),p=this.getLayoutLineCount(e,l);let S=Math.ceil(Math.max(r-n,0)/c),C=Math.ceil(S/s)*s+s,w=C/s,T=w,E=[],D=(n+r)/2,O=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-C*c*2),s),k=t+(O?.top??_),A=O?.renderedLineIndex??0,j,M,ee;if(Qe({diff:e,diffStyle:l,startingLine:O?.renderedLineIndex??0,expandedHunks:a?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:i,hunk:a,collapsedBefore:o,collapsedAfter:c,deletionLine:f,additionLine:p})=>{let m=p==null?f.splitLineIndex:p.splitLineIndex,h=p==null?f.unifiedLineIndex:p.unifiedLineIndex,g=(p?.noEOFCR??!1)||(f?.noEOFCR??!1),v=i===e.hunks.length-1&&a!=null&&(l===`split`?m===a.splitLineStart+a.splitLineCount-1:h===a.unifiedLineStart+a.unifiedLineCount-1),y=(o>0?ze({type:u,metrics:this.metrics,hunkIndex:i,hunkSpecs:a?.hunkSpecs}):void 0)?.totalHeight??0;k+=y;let b=A%s===0,x=Math.floor(A/s);if(b&&(E[x]=k-(t+_+y),ee!=null)){if(ee<=0)return!0;ee--}let S=this.getLineHeight(l===`split`?m:h,g);if(k>n-S&&k<r&&(j??=x),M==null&&k+S>D&&(M=x),ee==null&&k>=r&&b&&(ee=T),A++,k+=S,c>0||v&&d){let e=mn({type:u,metrics:this.metrics});e!=null&&(k<r&&k+e.totalHeight>n&&(j??=x),M==null&&k+e.totalHeight>D&&(M=x),k+=e.totalHeight)}return!1}}),j==null){if(x)j=0,M=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h}}M??=j;let N=Math.round(M-w/2),te=Math.max(0,Math.ceil(p/s)-w),P=Math.max(0,Math.min(N,te)),ne=P*s,re=N<0?C+N*s:C,ie=E[P]??0,ae=ne===0?0:g+ie,oe=P+re/s,se=oe<E.length?v-E[oe]:v-(k-t-_);return{startingLine:ne,totalLines:re,bufferBefore:ae,bufferAfter:Math.max(0,se)}}};function Zc(e){let t;for(let n of e){if(n==null)continue;let e=n.children[1];if(e instanceof HTMLElement)for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===ro&&(t=Math.max(t??0,n.getBoundingClientRect().height))}return t}function Qc(e){let t=Array.from(e).sort((e,t)=>e[0]-t[0]),n=[],r=[0],i=0;for(let[e,a]of t)n.push(e),i+=a,r.push(i);return{lineIndexes:n,prefixTotals:r}}function $c({lineIndexes:e,prefixTotals:t},n,r){if(n>=r||e.length===0)return 0;let i=el(e,n);return(t[el(e,r)]??0)-(t[i]??0)}function el(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid prefix index`);a<t?n=i+1:r=i}return n}function tl(e){return Math.ceil(e/Jc)*Jc}function nl(e,t){let n=0;for(let r of e)r<t&&n++;return n}function rl({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];let r=t.hunkContent.at(-1);if(r==null)return[];if(r.type===`context`)return[n-1];let i=Math.max(r.deletions,r.additions),a=r.deletions+r.additions;if(e===`split`)return i>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];let o=[],s=n-a;return r.deletions>0&&t.noEOFCRDeletions&&o.push(s+r.deletions-1),r.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function il(e,t){return(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function al(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function ol(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function sl(e){return typeof e==`function`?`custom`:e??`line-info`}function cl(e,t){return e==null||t==null?e==null&&t==null:fn(e,t)}function ll(e,t){let[n,r]=e.split(`,`).map(Number);return t===`split`?r:n}function ul({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function dl(e,t){let n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:fl(n,e.startContentIndex)}}function fl(e,t){let n=e.unifiedLineStart;for(let r=0;r<t;r++){let t=e.hunkContent[r];n+=t.type===`context`?t.lines:t.deletions+t.additions}return n}function pl(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var ml=1e3,hl=ml*4,gl=[0,1e-6,.99999,1],_l={overscrollSize:ml,intersectionObserverMargin:hl,resizeDebugging:!1},vl=0,yl=-1,bl=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++yl}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={..._l,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:gl,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),hi(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),hi(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=Si({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-vl,newSize:e}),vl=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-vl,newSize:e}),vl=e))}t&&hi(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){gi(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+xl(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),hi(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,hi(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{e.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=Si({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&pl(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),i=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&i.add(e);for(let e of this.instancesChanged)i.has(e)||e.onRender(t)&&i.add(e);this.scrollFix(r);for(let e of i)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&hi(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=xl(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=xl(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=xl(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=xl(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&hi(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,hi(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function xl(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}function Sl(e){let t=(0,J.useRef)(e);return(0,J.useInsertionEffect)(()=>void(t.current=e)),(0,J.useCallback)((...e)=>t.current(...e),[])}var Cl=(0,J.createContext)(void 0);function wl({children:e,createEditor:t}){let n=(0,J.useRef)(new WeakMap),r=Sl(e=>{let r=n.current.get(e);if(r!=null)return r;let i=t(e);return n.current.set(e,i),i});return(0,X.jsx)(Cl.Provider,{value:r,children:e})}function Tl(){return(0,J.useContext)(Cl)}var El={position:`absolute`,top:0,bottom:0,textAlign:`center`,whiteSpace:`normal`,touchAction:`none`},Dl={display:`contents`};function Ol(){return null}function kl({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:r,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,renderGutterUtility:s,renderMergeConflictUtility:c,lineAnnotations:l,getHoveredLine:u,getInstance:d}){let f=n?.(e),p=r?.(e),m=i?.(e),h=a?.(e);return(0,X.jsxs)(X.Fragment,{children:[f==null?(0,X.jsxs)(X.Fragment,{children:[p!=null&&(0,X.jsx)(`div`,{slot:`header-prefix`,children:p}),m!=null&&(0,X.jsx)(`div`,{slot:`header-filename-suffix`,children:m}),h!=null&&(0,X.jsx)(`div`,{slot:`header-metadata`,children:h})]}):(0,X.jsx)(`div`,{slot:$e,children:f}),o!=null&&l?.map((e,t)=>(0,X.jsx)(`div`,{slot:to(e),children:o(e)},t)),t!=null&&c!=null&&d!=null&&t.map(t=>{if(t==null)return;let n=Al(t,e);return(0,X.jsx)(`div`,{slot:n,style:Dl,children:c(t,d)},n)}),s!=null&&(0,X.jsx)(`div`,{slot:`gutter-utility-slot`,style:El,children:s(u)})]})}function Al(e,t){let n=dl(e,t);return n==null?void 0:ul({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex})}function jl({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,lineAnnotations:o,renderGutterUtility:s,getHoveredLine:c}){let l=t?.(e),u=n?.(e),d=r?.(e),f=i?.(e);return(0,X.jsxs)(X.Fragment,{children:[l==null?(0,X.jsxs)(X.Fragment,{children:[u!=null&&(0,X.jsx)(`div`,{slot:`header-prefix`,children:u}),d!=null&&(0,X.jsx)(`div`,{slot:`header-filename-suffix`,children:d}),f!=null&&(0,X.jsx)(`div`,{slot:`header-metadata`,children:f})]}):(0,X.jsx)(`div`,{slot:$e,children:l}),a!=null&&o?.map((e,t)=>(0,X.jsx)(`div`,{slot:to(e),children:a(e)},t)),s!=null&&(0,X.jsx)(`div`,{slot:`gutter-utility-slot`,style:El,children:s(c)})]})}function Ml(e,t){return typeof window>`u`&&t!=null?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,X.jsx)(X.Fragment,{children:e})}var Nl=(0,J.createContext)(void 0);function Pl({children:e,config:t,className:n,style:r,contentClassName:i,contentStyle:a}){let[o]=(0,J.useState)(()=>typeof window<`u`?new bl(t):void 0),s=(0,J.useCallback)(e=>{e==null?o?.cleanUp():o?.setup(e)},[o]);return(0,X.jsx)(Nl.Provider,{value:o,children:(0,X.jsx)(`div`,{className:n,style:r,ref:s,children:(0,X.jsx)(`div`,{className:i,style:a,children:e})})})}function Fl(){return(0,J.useContext)(Nl)}var Il=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Ll({file:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=Fl(),f=i!==void 0,p=(0,J.useContext)(ln),m=Tl(),h=(0,J.useRef)(null),g=Sl(n=>{if(n!=null){if(h.current!=null)throw Error(`File: An instance should not already exist when a node is created`);d==null?h.current=new Jo(Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new es(Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({file:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`File: A File instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return Il(()=>{if(h.current==null)return;let n=Rl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),a=n!==void 0&&!yi(h.current.options,n);h.current.setOptions(n),h.current.render({file:e,lineAnnotations:r,forceRender:a}),i!==void 0&&h.current.setSelectedLines(i)}),Il(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`File: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`File: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,J.useCallback)(()=>h.current?.getHoveredLine(),[])}}function Rl({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Ol:e?.renderCustomHeader,renderGutterUtility:r?Ol:e?.renderGutterUtility}:e}function zl({file:e,lineAnnotations:t,selectedLines:n,options:r,editorOptions:i,metrics:a,className:o,style:s,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,prerenderedHTML:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:g=!1}){let{ref:_,getHoveredLine:v}=Ll({file:e,options:r,editorOptions:i,metrics:a,lineAnnotations:t,selectedLines:n,prerenderedHTML:p,hasGutterRenderUtility:m!=null,hasCustomHeader:l!=null,disableWorkerPool:h,edit:g});return(0,X.jsx)(Fe,{ref:_,className:o,style:s,children:Ml(jl({file:e,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,renderGutterUtility:m,lineAnnotations:t,getHoveredLine:v}),p)})}var Bl=typeof window>`u`?J.useEffect:J.useLayoutEffect;function Vl({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=Fl(),f=i!==void 0,p=(0,J.useContext)(ln),m=Tl(),h=(0,J.useRef)(null),g=Sl(n=>{if(n!=null){if(h.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?h.current=new Rc(Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new Xc(Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return Bl(()=>{let{current:n}=h;if(n==null)return;let a=Hl({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!yi(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),Bl(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,J.useCallback)(()=>h.current?.getHoveredLine(),[])}}function Hl({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Ol:e?.renderCustomHeader,renderGutterUtility:r?Ol:e?.renderGutterUtility}:e}function Ul({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,className:o,style:s,prerenderedHTML:c,renderAnnotation:l,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:g=!1}){let{ref:_,getHoveredLine:v}=Vl({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,prerenderedHTML:c,hasGutterRenderUtility:m!=null,hasCustomHeader:u!=null,disableWorkerPool:h,edit:g});return(0,X.jsx)(Fe,{ref:_,className:o,style:s,children:Ml(kl({fileDiff:e,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderAnnotation:l,renderGutterUtility:m,lineAnnotations:i,getHoveredLine:v}),c)})}function Wl(e){let{environmentId:t,threadId:n,fromTurnCount:r,toTurnCount:i,ignoreWhitespace:a,cacheScope:o}=e,s=e.enabled,l=E(e)?c(e):null;(0,J.useEffect)(()=>{if(l!==null)return T({environmentId:t,threadId:n,fromTurnCount:r,toTurnCount:i,ignoreWhitespace:a,...o===void 0?{}:{cacheScope:o},...s===void 0?{}:{enabled:s}})},[l,t,n,r,i,a,o,s]);let u=y(l===null?b:x(l));return l===null?m:u}var Gl=`\0`,Kl=1/0,ql=1;function Jl(e){return`${e.turnId}${Gl}${e.filePath}${Gl}${e.blobSha}`}var Yl=class{#e;#t;constructor(e=50){if(!Number.isInteger(e)||e<=0)throw RangeError(`DiffParseCache maxEntries must be a positive integer, received ${String(e)}`);this.#t=e,this.#e=new Xt(e,Kl)}get maxEntries(){return this.#t}get(e){return this.#e.get(Jl(e))??void 0}set(e,t){this.#e.set(Jl(e),t,ql)}getOrCompute(e,t){let n=this.get(e);if(n!==void 0)return n;let r=t();return this.set(e,r),r}clear(){this.#e.clear()}};function Xl(e){let t=e.name??e.prevName??``;return t.startsWith(`a/`)||t.startsWith(`b/`)?t.slice(2):t}function Zl(e,t=!1){let n=e.trim();return t?n:n.toLowerCase()}function Ql(e,t){t.text!==void 0&&e.push({fileIndex:t.fileIndex,field:t.field,text:t.text,normalizedText:t.text.toLowerCase(),...t.lineIndex===void 0?{}:{lineIndex:t.lineIndex},...t.unifiedLineIndex===void 0?{}:{unifiedLineIndex:t.unifiedLineIndex},...t.splitLineIndex===void 0?{}:{splitLineIndex:t.splitLineIndex}})}function $l(e,t,n){t.additionLines.forEach((t,r)=>{Ql(e,{fileIndex:n,field:`addition`,lineIndex:r,text:t})}),t.deletionLines.forEach((t,r)=>{Ql(e,{fileIndex:n,field:`deletion`,lineIndex:r,text:t})})}function eu(e,t,n){if(!t.hunks||t.hunks.length===0)return!1;for(let r of t.hunks){let i=r.unifiedLineStart,a=r.splitLineStart;for(let o of r.hunkContent){if(o.type===`context`){for(let r=0;r<o.lines;r+=1){let s=o.additionLineIndex+r,c=o.deletionLineIndex+r;Ql(e,{fileIndex:n,field:`context`,lineIndex:s,unifiedLineIndex:i+r,splitLineIndex:a+r,text:t.additionLines[s]??t.deletionLines[c]})}i+=o.lines,a+=o.lines;continue}for(let r=0;r<o.deletions;r+=1){let s=o.deletionLineIndex+r;Ql(e,{fileIndex:n,field:`deletion`,lineIndex:s,unifiedLineIndex:i+r,splitLineIndex:a+r,text:t.deletionLines[s]})}for(let r=0;r<o.additions;r+=1){let s=o.additionLineIndex+r;Ql(e,{fileIndex:n,field:`addition`,lineIndex:s,unifiedLineIndex:i+o.deletions+r,splitLineIndex:a+r,text:t.additionLines[s]})}i+=o.deletions+o.additions,a+=Math.max(o.deletions,o.additions)}}return!0}function tu(e){let t=[];return e.forEach((e,n)=>{Ql(t,{text:Xl(e),fileIndex:n,field:`path`}),e.prevName&&Ql(t,{text:Xl({name:e.prevName}),fileIndex:n,field:`previousPath`}),eu(t,e,n)||$l(t,e,n)}),{records:t}}function nu(e){let t=e.caseSensitive?e.record.text:e.record.normalizedText,n=[],r=0;for(;;){let i=t.indexOf(e.needle,r);if(i===-1)return n;let a=i+e.needle.length;n.push({fileIndex:e.record.fileIndex,field:e.record.field,...e.record.lineIndex===void 0?{}:{lineIndex:e.record.lineIndex},...e.record.unifiedLineIndex===void 0?{}:{unifiedLineIndex:e.record.unifiedLineIndex},...e.record.splitLineIndex===void 0?{}:{splitLineIndex:e.record.splitLineIndex},start:i,end:a}),r=a>i?a:i+1}}function ru(e){return!Array.isArray(e)}function iu(e,t,n){let r=n?.caseSensitive??!1,i=Zl(t,r);if(!i)return[];let a=ru(e)?e:tu(e),o=[];for(let e of a.records)o.push(...nu({record:e,needle:i,caseSensitive:r}));return o}function au(e){return[...new Set(e.map(e=>e.fileIndex))]}function ou(e){let t=new Map;for(let n of e){let e=t.get(n.fileIndex);e?e.push(n):t.set(n.fileIndex,[n])}return t}function su(e,t,n){return t<=0?0:(e+n+t)%t}function cu(e,t){return e.field===`path`||e.field===`previousPath`?null:(t===`split`?e.splitLineIndex:e.unifiedLineIndex)??e.lineIndex??null}function lu(e){return e===`addition`||e===`deletion`||e===`context`}function uu(e){if(!e)return null;let[t,n]=e.split(`,`),r=Number.parseInt(t??``,10);if(!Number.isFinite(r))return null;let i=Number.parseInt(n??``,10);return{stacked:r,split:Number.isFinite(i)?i:r}}function du(e,t){if(!lu(e.field)||cu(e,t.renderMode)!==(t.renderMode===`split`?t.lineIndexes.split:t.lineIndexes.stacked))return!1;switch(e.field){case`addition`:return t.lineType===`change-addition`||t.lineType===`addition`;case`deletion`:return t.lineType===`change-deletion`||t.lineType===`deletion`;case`context`:return t.lineType===`context`||t.lineType===`context-expanded`}}function fu(e){let t=e.cwd?Cn(e.filePath,e.cwd):e.filePath;return typeof e.lineNumber==`number`?`${t}:${e.lineNumber}`:t}var pu=`
1366
1366
  [data-diffs-header],
1367
1367
  [data-diff],
1368
1368
  [data-file],
@@ -1433,14 +1433,14 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
1433
1433
  background-color: color-mix(in srgb, var(--warning) 60%, transparent);
1434
1434
  color: var(--foreground);
1435
1435
  }
1436
- `,gu=`${pu}${mu}${hu}`,_u=`${pu}${hu}`;function vu(e,t=`diff-panel`){if(!e)return null;let n=e.trim();if(n.length===0)return null;try{let e=Hi(n,Gt(n,t)).flatMap(e=>e.files);return e.length>0?{kind:`files`,files:e}:{kind:`raw`,text:n,reason:`Unsupported diff format. Showing raw patch.`}}catch{return{kind:`raw`,text:n,reason:`Failed to parse patch. Showing raw patch.`}}}function yu(e){return Xl(e)}function bu(e){return!e||e.kind!==`files`?[]:e.files.toSorted((e,t)=>yu(e).localeCompare(yu(t),void 0,{numeric:!0,sensitivity:`base`}))}var xu=new Yl;function Su(e){return e.cacheKey??`${e.prevName??`none`}:${e.name}`}var Cu=`ryco-diff-search-match`,wu=150,Tu=80,Eu=1600;function Du(){return typeof CSS<`u`&&CSS.highlights!==void 0&&globalThis.Highlight!==void 0}function Ou(e,t,n=Eu){let r=e.getBoundingClientRect(),i=t.getBoundingClientRect();return r.bottom>=i.top-n&&r.top<=i.bottom+n&&r.right>=i.left-n&&r.left<=i.right+n}function ku(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return t&&t.closest(`[data-line-number-content]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode(),i=0;for(;r;){let e=r,a=i+e.data.length;t.push({node:e,start:i,end:a}),i=a,r=n.nextNode()}return{offsets:t,textLength:i}}function Au(e,t,n){for(let r of e)if(!(t<r.start||t>r.end)&&(t!==r.end||n!==`start`))return{node:r.node,offset:t-r.start};return null}function ju(e,t,n){let{offsets:r,textLength:i}=ku(e);if(r.length===0||t.start<0||t.end>i||t.start>=t.end)return;let a=Au(r,t.start,`start`),o=Au(r,t.end,`end`);if(!a||!o)return;let s=document.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset),n.push(s)}function Mu(e){let t=uu(e.lineIndexAttr);return t?e.matches.filter(n=>du(n,{renderMode:e.renderMode,lineIndexes:t,lineType:e.lineType})):[]}function Nu(e){if(cu(e.match,e.renderMode)===null)return null;let t=e.fileElement.querySelectorAll(`diffs-container`);for(let n of t){let t=n.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`);for(let n of t??[]){let t=uu(n.getAttribute(`data-line-index`));if(t&&du(e.match,{renderMode:e.renderMode,lineIndexes:t,lineType:n.getAttribute(`data-line-type`)}))return n}}return null}function Pu(e){let t=[],n=e.rootElement.querySelectorAll(`[data-diff-file-index]`);for(let r of n){if(!Ou(r,e.viewportElement))continue;let n=r.dataset.diffFileIndex,i=n?Number.parseInt(n,10):NaN;if(!Number.isFinite(i))continue;let a=e.matchesByFileIndex.get(i);if(!a||a.length===0)continue;let o=r.querySelectorAll(`diffs-container`);for(let n of o){let r=n.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`);for(let n of r??[]){if(!Ou(n,e.viewportElement))continue;let r=Mu({matches:a,renderMode:e.renderMode,lineIndexAttr:n.getAttribute(`data-line-index`),lineType:n.getAttribute(`data-line-type`)});for(let e of r)ju(n,e,t)}}}return t}function Fu(e){switch(e.type){case`new`:return`text-[var(--diffs-addition-base)]`;case`deleted`:return`text-[var(--diffs-deletion-base)]`;case`change`:case`rename-pure`:case`rename-changed`:return`text-[var(--diffs-modified-base)]`;default:return`text-muted-foreground/80`}}function Iu(e){let t=(0,Y.c)(219),{mode:n}=e,i=n===void 0?`inline`:n;we(`DiffPanel`);let a=ve(),{resolvedTheme:o}=ir(),s=g(),c=i===`phone`,[l,d]=(0,J.useState)(`stacked`),[h,v]=(0,J.useState)(c?!0:s.diffWordWrap),[y,b]=(0,J.useState)(s.diffIgnoreWhitespace),[x,S]=(0,J.useState)(Ku),[C,w]=(0,J.useState)(``),T;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(T={wait:wu},t[0]=T):T=t[0];let[E]=j(C,T),D;t[1]!==E||t[2]!==C?(D=C.trim().length===0?``:E,t[1]=E,t[2]=C,t[3]=D):D=t[3];let O=D,[k,A]=(0,J.useState)(0),ee=(0,J.useRef)(null),M=(0,J.useRef)(null),te=(0,J.useRef)(null),N=(0,J.useRef)(!1),[P,ne]=(0,J.useState)(!1),[ae,oe]=(0,J.useState)(!1),I;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(I={strict:!1,select:Gu},t[4]=I):I=t[4];let ce=ie(I),le;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(le={strict:!1,select:Wu},t[5]=le):le=t[5];let ue=se(le),de=ue.diff===`1`,fe=ce?.threadId??null,pe;t[6]===ce?pe=t[7]:(pe=p(ce),t[6]=ce,t[7]=pe);let R=f(pe),me=R?.projectId??null,z;t[8]!==me||t[9]!==R?(z=e=>R&&me?m(e,{environmentId:R.environmentId,projectId:me}):void 0,t[8]=me,t[9]=R,t[10]=z):z=t[10];let he=f(z),ge=R?.worktreePath??he?.cwd,_e=R?.environmentId??null,B=ge??null,ye;t[11]!==_e||t[12]!==B?(ye={environmentId:_e,cwd:B},t[11]=_e,t[12]=B,t[13]=ye):ye=t[13];let be=u(ye).data?.isRepo??!0,{turnDiffSummaries:xe,inferredCheckpointTurnCountByTurnId:V}=Ut(R),De;if(t[14]!==V||t[15]!==xe){let e;t[17]===V?e=t[18]:(e=(e,t)=>{let n=e.checkpointTurnCount??V[e.turnId]??0,r=t.checkpointTurnCount??V[t.turnId]??0;return n===r?t.completedAt.localeCompare(e.completedAt):r-n},t[17]=V,t[18]=e),De=[...xe].toSorted(e),t[14]=V,t[15]=xe,t[16]=De}else De=t[16];let H=De,U=ue.diffTurnId??null,Oe=U===null?null:ue.diffFilePath??null,ke;t[19]!==H||t[20]!==U?(ke=U===null?void 0:H.find(e=>e.turnId===U)??H[0],t[19]=H,t[20]=U,t[21]=ke):ke=t[21];let W=ke,G=W&&(W.checkpointTurnCount??V[W.turnId]),Ae;t[22]===G?Ae=t[23]:(Ae=typeof G==`number`?{fromTurnCount:Math.max(0,G-1),toTurnCount:G}:null,t[22]=G,t[23]=Ae);let je=Ae,Me;if(t[24]!==V||t[25]!==H){bb0:{let e;t[27]===V?e=t[28]:(e=e=>e.checkpointTurnCount??V[e.turnId],t[27]=V,t[28]=e);let n=H.map(e).filter(Uu);if(n.length===0){Me=void 0;break bb0}let r=Math.max(...n);Me=r>0?r:void 0}t[24]=V,t[25]=H,t[26]=Me}else Me=t[26];let Ne=Me,Pe;t[29]!==Ne||t[30]!==W?(Pe=!W&&typeof Ne==`number`?{fromTurnCount:0,toTurnCount:Ne}:null,t[29]=Ne,t[30]=W,t[31]=Pe):Pe=t[31];let Fe=W?je:Pe,Ie;bb1:{if(W||H.length===0){Ie=null;break bb1}let e;t[32]===H?e=t[33]:(e=H.map(Hu).join(`,`),t[32]=H,t[33]=e),Ie=`conversation:${e}`}let Le=Ie,Re=R?.environmentId??null,ze=Fe?.fromTurnCount??null,K=Fe?.toTurnCount??null,Be=W?`turn:${W.turnId}`:Le,Ve;t[34]!==fe||t[35]!==y||t[36]!==be||t[37]!==Re||t[38]!==ze||t[39]!==K||t[40]!==Be?(Ve={environmentId:Re,threadId:fe,fromTurnCount:ze,toTurnCount:K,ignoreWhitespace:y,cacheScope:Be,enabled:be},t[34]=fe,t[35]=y,t[36]=be,t[37]=Re,t[38]=ze,t[39]=K,t[40]=Be,t[41]=Ve):Ve=t[41];let He=Wl(Ve),Ue=W?He.data?.diff:void 0,We=W?void 0:He.data?.diff,Ge=He.isLoading,Ke=He.error instanceof Error?He.error.message:He.error?`Failed to load checkpoint diff.`:null,qe=W?Ue:We,Je=typeof qe==`string`,Ye;t[42]!==Je||t[43]!==qe?(Ye=Je&&qe.trim().length===0,t[42]=Je,t[43]=qe,t[44]=Ye):Ye=t[44];let Xe=Ye,Ze;if(t[45]!==Le||t[46]!==o||t[47]!==qe||t[48]!==W){bb2:{let e=`diff-panel:${o}`,n=typeof qe==`string`?qe.trim():``;if(n.length===0){let e;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(e={patch:null,files:[]},t[50]=e):e=t[50],Ze=e;break bb2}let r={turnId:W?`turn:${W.turnId}`:Le??`conversation`,filePath:e,blobSha:Gt(n)},i=xu.get(r);if(i){Ze=i;break bb2}let a=vu(qe,e),s={patch:a,files:bu(a)};a&&xu.set(r,s),Ze=s}t[45]=Le,t[46]=o,t[47]=qe,t[48]=W,t[49]=Ze}else Ze=t[49];let Qe=Ze,$e=Qe.patch,et=Qe.files,tt;t[51]===et?tt=t[52]:(tt=tu(et),t[51]=et,t[52]=tt);let nt=tt,rt;t[53]===O?rt=t[54]:(rt=Zl(O),t[53]=O,t[54]=rt);let it=rt,at;t[55]!==nt||t[56]!==O?(at=iu(nt,O),t[55]=nt,t[56]=O,t[57]=at):at=t[57];let ot=at,st;t[58]===ot?st=t[59]:(st=ou(ot),t[58]=ot,t[59]=st);let ct=st,lt;t[60]===et?lt=t[61]:(lt=et.map(Vu),t[60]=et,t[61]=lt);let ut=lt,dt;bb3:{if(!it){dt=ut;break bb3}let e;if(t[62]!==ot||t[63]!==et){let n;t[65]===et?n=t[66]:(n=e=>({fileDiff:et[e],fileIndex:e}),t[65]=et,t[66]=n),e=au(ot).map(n),t[62]=ot,t[63]=et,t[64]=e}else e=t[64];dt=e}let ft=dt,pt;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(pt=()=>{A(0)},t[67]=pt):pt=t[67];let mt;t[68]!==it||t[69]!==et?(mt=[it,et],t[68]=it,t[69]=et,t[70]=mt):mt=t[70],(0,J.useEffect)(pt,mt);let ht,gt;t[71]===ot.length?(ht=t[72],gt=t[73]):(ht=()=>{A(e=>ot.length===0?0:Math.min(e,ot.length-1))},gt=[ot.length],t[71]=ot.length,t[72]=ht,t[73]=gt),(0,J.useEffect)(ht,gt);let _t;t[74]!==k||t[75]!==l||t[76]!==ot?(_t=e=>{if(ot.length===0)return;let t=su(k,ot.length,e);A(t);let n=ot[t],r=M.current;if(!n||!r)return;let i=r.querySelector(`[data-diff-file-index="${n.fileIndex}"]`);if(!i)return;let a=Nu({fileElement:i,match:n,renderMode:l});(a??i).scrollIntoView({block:`center`,behavior:`smooth`}),!a&&cu(n,l)!==null&&window.requestAnimationFrame(()=>{Nu({fileElement:i,match:n,renderMode:l})?.scrollIntoView({block:`center`,behavior:`smooth`})})},t[74]=k,t[75]=l,t[76]=ot,t[77]=_t):_t=t[77];let vt=_t,yt,bt;t[78]!==l||t[79]!==ot.length||t[80]!==ct||t[81]!==it?(yt=()=>{if(!Du())return;let e=CSS.highlights,t=M.current;if(!t||!it||ot.length===0){e.delete(Cu);return}let n=0,r=0,i=new Map,a=t.querySelector(`.diff-render-surface`)??t.querySelector(`[data-virtualizer]`)??t,o=()=>{n=0,c();let r=Pu({rootElement:t,viewportElement:a,matchesByFileIndex:ct,renderMode:l});if(r.length===0){e.delete(Cu);return}e.set(Cu,new Highlight(...r))},s=()=>{n===0&&r===0&&(r=window.setTimeout(()=>{r=0,n=window.requestAnimationFrame(o)},Tu))},c=()=>{let e=t.querySelectorAll(`[data-diff-file-index]`);for(let t of e){if(!Ou(t,a))continue;let e=t.querySelectorAll(`diffs-container`);for(let t of e){let e=t.shadowRoot;if(!e||i.has(e))continue;let n=new MutationObserver(s);n.observe(e,{childList:!0,subtree:!0}),i.set(e,n)}}},u=new MutationObserver(s);u.observe(t,{childList:!0,subtree:!0}),a.addEventListener(`scroll`,s,{passive:!0});let d=new ResizeObserver(s);return d.observe(a),s(),()=>{u.disconnect(),a.removeEventListener(`scroll`,s),d.disconnect();for(let e of i.values())e.disconnect();i.clear(),r!==0&&window.clearTimeout(r),n!==0&&window.cancelAnimationFrame(n),e.delete(Cu)}},bt=[l,ot.length,ct,it],t[78]=l,t[79]=ot.length,t[80]=ct,t[81]=it,t[82]=yt,t[83]=bt):(yt=t[82],bt=t[83]),(0,J.useEffect)(yt,bt);let xt,St;t[84]===et?(xt=t[85],St=t[86]):(xt=()=>{if(et.length===0){S(Bu);return}let e=new Set(et.map(Su));S(t=>{let n=new Set([...t].filter(t=>e.has(t)));return n.size===t.size?t:n})},St=[et],t[84]=et,t[85]=xt,t[86]=St),(0,J.useEffect)(xt,St);let Ct,wt;t[87]!==de||t[88]!==c||t[89]!==s.diffIgnoreWhitespace||t[90]!==s.diffWordWrap?(Ct=()=>{de&&!N.current&&(v(c?!0:s.diffWordWrap),b(s.diffIgnoreWhitespace),w(``)),N.current=de},wt=[de,c,s.diffIgnoreWhitespace,s.diffWordWrap],t[87]=de,t[88]=c,t[89]=s.diffIgnoreWhitespace,t[90]=s.diffWordWrap,t[91]=Ct,t[92]=wt):(Ct=t[91],wt=t[92]),(0,J.useEffect)(Ct,wt);let Tt;t[93]===Symbol.for(`react.memo_cache_sentinel`)?(Tt=()=>{w(``)},t[93]=Tt):Tt=t[93];let Dt;t[94]===U?Dt=t[95]:(Dt=[U],t[94]=U,t[95]=Dt),(0,J.useEffect)(Tt,Dt);let Ot;t[96]===Oe?Ot=t[97]:(Ot=()=>{!Oe||!M.current||Array.from(M.current.querySelectorAll(`[data-diff-file-path]`)).find(e=>e.dataset.diffFilePath===Oe)?.scrollIntoView({block:`nearest`})},t[96]=Oe,t[97]=Ot);let kt;t[98]!==et||t[99]!==Oe?(kt=[Oe,et],t[98]=et,t[99]=Oe,t[100]=kt):kt=t[100],(0,J.useEffect)(Ot,kt);let At;t[101]===ge?At=t[102]:(At=(e,t)=>{let n=_();if(!n)return;let r=fu({cwd:ge,filePath:e,lineNumber:t});nr(n,r).catch(zu)},t[101]=ge,t[102]=At);let jt=At,Mt;t[103]===Symbol.for(`react.memo_cache_sentinel`)?(Mt=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},t[103]=Mt):Mt=t[103];let Pt=Mt,Ft;t[104]!==R||t[105]!==a?(Ft=e=>{R&&a({to:`/$environmentId/$threadId`,params:re(r(R.environmentId,R.id)),search:t=>({...L(t),diff:`1`,diffTurnId:e})})},t[104]=R,t[105]=a,t[106]=Ft):Ft=t[106];let It=Ft,Lt;t[107]!==R||t[108]!==a?(Lt=()=>{R&&a({to:`/$environmentId/$threadId`,params:re(r(R.environmentId,R.id)),search:Ru})},t[107]=R,t[108]=a,t[109]=Lt):Lt=t[109];let Rt=Lt,zt;t[110]===Symbol.for(`react.memo_cache_sentinel`)?(zt=()=>{let e=te.current;if(!e){ne(!1),oe(!1);return}let t=Math.max(0,e.scrollWidth-e.clientWidth);ne(e.scrollLeft>4),oe(e.scrollLeft<t-4)},t[110]=zt):zt=t[110];let Bt=zt,Vt;t[111]===Symbol.for(`react.memo_cache_sentinel`)?(Vt=e=>{let t=te.current;t&&t.scrollBy({left:e,behavior:`smooth`})},t[111]=Vt):Vt=t[111];let Ht=Vt,Wt;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Wt=e=>{let t=te.current;t&&(t.scrollWidth<=t.clientWidth+1||Math.abs(e.deltaY)<=Math.abs(e.deltaX)||(e.preventDefault(),t.scrollBy({left:e.deltaY,behavior:`auto`})))},t[112]=Wt):Wt=t[112];let Kt=Wt,qt,Jt;t[113]===Symbol.for(`react.memo_cache_sentinel`)?(qt=()=>{let e=te.current;if(!e)return;let t=window.requestAnimationFrame(()=>Bt()),n=()=>Bt();e.addEventListener(`scroll`,n,{passive:!0});let r=new ResizeObserver(()=>Bt());return r.observe(e),()=>{window.cancelAnimationFrame(t),e.removeEventListener(`scroll`,n),r.disconnect()}},Jt=[Bt],t[113]=qt,t[114]=Jt):(qt=t[113],Jt=t[114]),(0,J.useEffect)(qt,Jt);let Yt;t[115]===Symbol.for(`react.memo_cache_sentinel`)?(Yt=()=>{let e=window.requestAnimationFrame(()=>Bt());return()=>{window.cancelAnimationFrame(e)}},t[115]=Yt):Yt=t[115];let Xt;t[116]!==H||t[117]!==U?(Xt=[H,U,Bt],t[116]=H,t[117]=U,t[118]=Xt):Xt=t[118],(0,J.useEffect)(Yt,Xt);let Zt;t[119]===Symbol.for(`react.memo_cache_sentinel`)?(Zt=()=>{let e=te.current;e&&e.querySelector(`[data-turn-chip-selected='true']`)?.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`smooth`})},t[119]=Zt):Zt=t[119];let Qt=W?.turnId,$t;t[120]!==U||t[121]!==Qt?($t=[Qt,U],t[120]=U,t[121]=Qt,t[122]=$t):$t=t[122],(0,J.useEffect)(Zt,$t);let en;t[123]!==P||t[124]!==ae||t[125]!==c?(en=c?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:F(`absolute left-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors`,P?`border-border/70 hover:border-border hover:text-foreground`:`cursor-not-allowed border-border/40 text-muted-foreground/40`),onClick:()=>Ht(-180),disabled:!P,"aria-label":`Scroll turn list left`,children:(0,X.jsx)(Ce,{className:`size-3.5`})}),(0,X.jsx)(`button`,{type:`button`,className:F(`absolute right-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors`,ae?`border-border/70 hover:border-border hover:text-foreground`:`cursor-not-allowed border-border/40 text-muted-foreground/40`),onClick:()=>Ht(180),disabled:!ae,"aria-label":`Scroll turn list right`,children:(0,X.jsx)(Te,{className:`size-3.5`})})]}),t[123]=P,t[124]=ae,t[125]=c,t[126]=en):en=t[126];let tn=c?`px-1`:`px-8`,nn;t[127]===tn?nn=t[128]:(nn=F(`turn-chip-strip flex gap-1 overflow-x-auto py-0.5`,tn),t[127]=tn,t[128]=nn);let rn;t[129]!==P||t[130]!==ae||t[131]!==c?(rn=!c&&(P||ae)?{maskImage:`linear-gradient(to right, ${P?`transparent 24px, black 72px`:`black`}, ${ae?`black calc(100% - 72px), transparent calc(100% - 24px)`:`black`})`}:void 0,t[129]=P,t[130]=ae,t[131]=c,t[132]=rn):rn=t[132];let on=c&&`min-h-[44px]`,sn;t[133]===on?sn=t[134]:(sn=F(`shrink-0 rounded-md`,on),t[133]=on,t[134]=sn);let cn=U===null,ln=c&&`flex min-h-[44px] items-center`,un=U===null?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`,dn;t[135]!==ln||t[136]!==un?(dn=F(`rounded-md border px-2 py-1 text-left transition-colors`,ln,un),t[135]=ln,t[136]=un,t[137]=dn):dn=t[137];let fn;t[138]===Symbol.for(`react.memo_cache_sentinel`)?(fn=(0,X.jsx)(`div`,{className:`text-[10px] leading-tight font-medium`,children:`All turns`}),t[138]=fn):fn=t[138];let pn;t[139]===dn?pn=t[140]:(pn=(0,X.jsx)(`div`,{className:dn,children:fn}),t[139]=dn,t[140]=pn);let q;t[141]!==Rt||t[142]!==sn||t[143]!==cn||t[144]!==pn?(q=(0,X.jsx)(`button`,{type:`button`,className:sn,onClick:Rt,"data-turn-chip-selected":cn,children:pn}),t[141]=Rt,t[142]=sn,t[143]=cn,t[144]=pn,t[145]=q):q=t[145];let mn;if(t[146]!==V||t[147]!==c||t[148]!==H||t[149]!==It||t[150]!==W?.turnId||t[151]!==s.timestampFormat){let e;t[153]!==V||t[154]!==c||t[155]!==It||t[156]!==W?.turnId||t[157]!==s.timestampFormat?(e=e=>(0,X.jsx)(`button`,{type:`button`,className:F(`shrink-0 rounded-md`,c&&`min-h-[44px]`),onClick:()=>It(e.turnId),title:e.turnId,"data-turn-chip-selected":e.turnId===W?.turnId,children:(0,X.jsx)(`div`,{className:F(`rounded-md border px-2 py-1 text-left transition-colors`,c&&`flex min-h-[44px] items-center`,e.turnId===W?.turnId?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] leading-tight font-medium`,children:[`Turn`,` `,e.checkpointTurnCount??V[e.turnId]??`?`]}),(0,X.jsx)(`span`,{className:`text-[9px] leading-tight opacity-70`,children:Ln(e.completedAt,s.timestampFormat)})]})})},e.turnId),t[153]=V,t[154]=c,t[155]=It,t[156]=W?.turnId,t[157]=s.timestampFormat,t[158]=e):e=t[158],mn=H.map(e),t[146]=V,t[147]=c,t[148]=H,t[149]=It,t[150]=W?.turnId,t[151]=s.timestampFormat,t[152]=mn}else mn=t[152];let hn;t[159]!==nn||t[160]!==rn||t[161]!==q||t[162]!==mn?(hn=(0,X.jsxs)(`div`,{ref:te,className:nn,style:rn,onWheel:Kt,children:[q,mn]}),t[159]=nn,t[160]=rn,t[161]=q,t[162]=mn,t[163]=hn):hn=t[163];let gn;t[164]!==en||t[165]!==hn?(gn=(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1 [-webkit-app-region:no-drag]`,children:[en,hn]}),t[164]=en,t[165]=hn,t[166]=gn):gn=t[166];let _n;t[167]!==l||t[168]!==c?(_n=c?null:(0,X.jsxs)(ar,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[l],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&d(t)},children:[(0,X.jsx)(or,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,X.jsx)(Tr,{className:`size-3`})}),(0,X.jsx)(or,{"aria-label":`Split diff view`,value:`split`,children:(0,X.jsx)(pr,{className:`size-3`})})]}),t[167]=l,t[168]=c,t[169]=_n):_n=t[169];let vn=h?`Disable diff line wrapping`:`Enable diff line wrapping`,yn=h?`Disable line wrapping`:`Enable line wrapping`,bn=c&&`min-h-[44px] min-w-[44px]`,Sn;t[170]===bn?Sn=t[171]:(Sn=F(bn),t[170]=bn,t[171]=Sn);let Cn,wn;t[172]===Symbol.for(`react.memo_cache_sentinel`)?(Cn=e=>{v(!!e)},wn=(0,X.jsx)(Er,{className:`size-3`}),t[172]=Cn,t[173]=wn):(Cn=t[172],wn=t[173]);let Tn;t[174]!==h||t[175]!==vn||t[176]!==yn||t[177]!==Sn?(Tn=(0,X.jsx)(or,{"aria-label":vn,title:yn,variant:`outline`,size:`xs`,className:Sn,pressed:h,onPressedChange:Cn,children:wn}),t[174]=h,t[175]=vn,t[176]=yn,t[177]=Sn,t[178]=Tn):Tn=t[178];let En=y?`Show whitespace changes`:`Hide whitespace changes`,Dn=y?`Show whitespace changes`:`Hide whitespace changes`,kn=c&&`min-h-[44px] min-w-[44px]`,An;t[179]===kn?An=t[180]:(An=F(kn),t[179]=kn,t[180]=An);let jn,Mn;t[181]===Symbol.for(`react.memo_cache_sentinel`)?(jn=e=>{b(!!e)},Mn=(0,X.jsx)(Cr,{className:`size-3`}),t[181]=jn,t[182]=Mn):(jn=t[181],Mn=t[182]);let Nn;t[183]!==y||t[184]!==En||t[185]!==Dn||t[186]!==An?(Nn=(0,X.jsx)(or,{"aria-label":En,title:Dn,variant:`outline`,size:`xs`,className:An,pressed:y,onPressedChange:jn,children:Mn}),t[183]=y,t[184]=En,t[185]=Dn,t[186]=An,t[187]=Nn):Nn=t[187];let Pn;t[188]!==_n||t[189]!==Tn||t[190]!==Nn?(Pn=(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[_n,Tn,Nn]}),t[188]=_n,t[189]=Tn,t[190]=Nn,t[191]=Pn):Pn=t[191];let Fn;t[192]!==gn||t[193]!==Pn?(Fn=(0,X.jsxs)(X.Fragment,{children:[gn,Pn]}),t[192]=gn,t[193]=Pn,t[194]=Fn):Fn=t[194];let In=Fn,Rn;t[195]!==R||t[196]!==Ke||t[197]!==x||t[198]!==k||t[199]!==l||t[200]!==ot.length||t[201]!==C||t[202]!==h||t[203]!==ft||t[204]!==vt||t[205]!==Xe||t[206]!==be||t[207]!==Ge||t[208]!==c||t[209]!==it||t[210]!==jt||t[211]!==H.length||t[212]!==$e||t[213]!==o?(Rn=R?be?H.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No completed turns yet.`}):(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{ref:M,className:`diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[Ke&&!$e&&(0,X.jsx)(`div`,{className:`px-3`,children:(0,X.jsx)(`p`,{className:`mb-2 text-[11px] text-red-500/80`,children:Ke})}),$e?$e.kind===`files`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/50 bg-card/40 px-2.5 py-1.5 [-webkit-app-region:no-drag]`,children:[(0,X.jsx)(xn,{className:`size-3.5 shrink-0 text-muted-foreground/70`}),(0,X.jsx)(`input`,{ref:ee,type:`text`,value:C,onChange:e=>w(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){w(``),e.currentTarget.blur();return}e.key===`Enter`&&it&&(e.preventDefault(),vt(e.shiftKey?-1:1))},placeholder:`Search files or hunks...`,"aria-label":`Search diff`,className:F(`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground/55`,c&&`min-h-[44px]`)}),it&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] tabular-nums text-muted-foreground/70`,children:[ot.length===0?0:k+1,` of`,` `,ot.length]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>vt(-1),disabled:ot.length===0,className:F(`inline-flex size-5 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-muted-foreground/70`,c&&`size-[44px]`),"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,children:(0,X.jsx)(Ee,{className:`size-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>vt(1),disabled:ot.length===0,className:F(`inline-flex size-5 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-muted-foreground/70`,c&&`size-[44px]`),"aria-label":`Next match`,title:`Next match (Enter)`,children:(0,X.jsx)(Se,{className:`size-3.5`})})]})]}),C&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>{w(``),ee.current?.focus()},className:F(`inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground`,c&&`size-[44px]`),"aria-label":`Clear search`,title:`Clear search`,children:(0,X.jsx)(On,{className:`size-3`})})]}),ft.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,X.jsxs)(`p`,{children:[`No files match “`,C,`”.`]})}):(0,X.jsx)(Pl,{className:F(`diff-render-surface min-h-0 flex-1 overflow-auto px-2 pb-2`,c&&`overflow-x-hidden overflow-y-auto overscroll-x-contain`),config:{overscrollSize:600,intersectionObserverMargin:1200},children:ft.map(e=>{let{fileDiff:t,fileIndex:n}=e,r=yu(t),i=Su(t),a=`${i}:${o}`,s=x.has(i);return(0,X.jsx)(`div`,{"data-diff-file-path":r,"data-diff-file-index":n,className:`diff-render-file group/diff-file mb-2 rounded-md first:mt-2 last:mb-0`,onClickCapture:c?void 0:e=>{(e.nativeEvent.composedPath?.()??[]).some(Lu)&&jt(r)},children:(0,X.jsx)(Ul,{fileDiff:t,renderHeaderPrefix:()=>(0,X.jsx)(`button`,{type:`button`,className:F(`inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden`,c&&`size-[44px]`,Fu(t)),"aria-label":s?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!s,title:s?`Expand diff`:`Collapse diff`,onClick:e=>{e.stopPropagation(),Pt(i)},children:s?(0,X.jsx)(Te,{className:`size-4`}):(0,X.jsx)(Se,{className:`size-4`})}),options:{collapsed:s,diffStyle:l===`split`?`split`:`unified`,lineDiffType:`none`,overflow:h?`wrap`:`scroll`,theme:Nt(o),themeType:o,unsafeCSS:c?_u:gu,lineHoverHighlight:`number`,...c?{}:{onLineNumberClick:e=>{let{lineNumber:t}=e;jt(r,t)}}}})},a)})})]}):(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:$e.reason}),(0,X.jsx)(`pre`,{className:F(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,h?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:$e.text})]})}):Ge?(0,X.jsx)(an,{label:`Loading checkpoint diff...`}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,X.jsx)(`p`,{children:Xe?`No net changes in this selection.`:`No patch available for this selection.`})})]})}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Turn diffs are unavailable because this project is not a git repository.`}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to inspect turn diffs.`}),t[195]=R,t[196]=Ke,t[197]=x,t[198]=k,t[199]=l,t[200]=ot.length,t[201]=C,t[202]=h,t[203]=ft,t[204]=vt,t[205]=Xe,t[206]=be,t[207]=Ge,t[208]=c,t[209]=it,t[210]=jt,t[211]=H.length,t[212]=$e,t[213]=o,t[214]=Rn):Rn=t[214];let zn;return t[215]!==In||t[216]!==i||t[217]!==Rn?(zn=(0,X.jsx)(Et,{mode:i,header:In,children:Rn}),t[215]=In,t[216]=i,t[217]=Rn,t[218]=zn):zn=t[218],zn}function Lu(e){return e instanceof Element&&e.hasAttribute(`data-title`)}function Ru(e){return{...L(e),diff:`1`}}function zu(e){console.warn(`Failed to open diff in editor.`,e)}function Bu(e){return e.size===0?e:new Set}function Vu(e,t){return{fileDiff:e,fileIndex:t}}function Hu(e){return e.turnId}function Uu(e){return typeof e==`number`}function Wu(e){return me(e)}function Gu(e){return ae(e)}function Ku(){return new Set}var qu=0,Ju=0,Yu=1,Xu=6e4,Zu=Object.freeze({data:null,isLoading:!1,isFetching:!1,error:null}),Qu=A({labelPrefix:`project-preview`,initialState:Zu,gcTime:Xu,maxEntries:48,buildFetchingState:e=>({data:e.data,isLoading:e.data===null,isFetching:!0,error:null}),buildSuccessState:e=>({data:e,isLoading:!1,isFetching:!1,error:null}),buildErrorState:(e,t)=>({data:e.data,isLoading:!1,isFetching:!1,error:t})});function $u(e,t=Yu){return e().catch(n=>{if(t<=0)throw n;return $u(e,t-1)})}function ed(e){return k(Qu,{...e,createControllerFields:()=>({})},e=>!e.hasData||Date.now()-e.lastFetchedAt>=e.staleTime)}function td(e){return w(e).projects}var nd=ed({label:`listEntries`,staleTime:qu,isEnabled:e=>(e.enabled??!0)&&e.environmentId!==null&&e.cwd!==null,buildKey:e=>`${e.environmentId}${e.cwd}`,resolveEnvironmentId:e=>e.environmentId,run:e=>$u(()=>td(e.environmentId).listEntries({cwd:e.cwd}))}),rd=ed({label:`readFile`,staleTime:Ju,isEnabled:e=>(e.enabled??!0)&&e.environmentId!==null&&e.cwd!==null&&e.relativePath!==null,buildKey:e=>`${e.environmentId}${e.cwd}${e.relativePath}`,resolveEnvironmentId:e=>e.environmentId,run:e=>$u(()=>td(e.environmentId).readFile({cwd:e.cwd,relativePath:e.relativePath}))});function id(e,t){let n=rd.keyOf(e);if(n===null)return;let r=Qu.controllers.get(n);r&&(r.hasData=!0,r.lastFetchedAt=Date.now()),Qu.setQueryState(n,{data:t,isLoading:!1,isFetching:!1,error:null})}function ad(e){let t=(0,Y.c)(18),{environmentId:n,cwd:r,enabled:i}=e,a=nd.keyOf(e),o,s;t[0]!==r||t[1]!==i||t[2]!==n?(o=()=>nd.watch({environmentId:n,cwd:r,...i===void 0?{}:{enabled:i}}),s=[n,r,i],t[0]=r,t[1]=i,t[2]=n,t[3]=o,t[4]=s):(o=t[3],s=t[4]),(0,J.useEffect)(o,s);let c=d(nd.getAtom(a)),l;bb0:{if(!c.data){l=null;break bb0}let e=c.data,n;t[5]===c.data.entries?n=t[6]:(n=c.data.entries.toSorted(sd),t[5]=c.data.entries,t[6]=n);let r;t[7]!==c.data||t[8]!==n?(r={...e,entries:n},t[7]=c.data,t[8]=n,t[9]=r):r=t[9],l=r}let u=l,f;t[10]===a?f=t[11]:(f=async()=>{let e=await nd.refreshAsync(a);return{data:e.data===null?null:{...e.data,entries:e.data.entries.toSorted(od)}}},t[10]=a,t[11]=f);let p=f,m;return t[12]!==p||t[13]!==u||t[14]!==c.error||t[15]!==c.isFetching||t[16]!==c.isLoading?(m={data:u,isLoading:c.isLoading,isFetching:c.isFetching,error:c.error,refetch:p},t[12]=p,t[13]=u,t[14]=c.error,t[15]=c.isFetching,t[16]=c.isLoading,t[17]=m):m=t[17],m}function od(e,t){return e.path.localeCompare(t.path,void 0,{numeric:!0,sensitivity:`base`})}function sd(e,t){return e.path.localeCompare(t.path,void 0,{numeric:!0,sensitivity:`base`})}function cd(e){let t=(0,Y.c)(14),{environmentId:n,cwd:r,relativePath:i,enabled:a}=e,o=rd.keyOf(e),s,c;t[0]!==r||t[1]!==a||t[2]!==n||t[3]!==i?(s=()=>rd.watch({environmentId:n,cwd:r,relativePath:i,...a===void 0?{}:{enabled:a}}),c=[n,r,i,a],t[0]=r,t[1]=a,t[2]=n,t[3]=i,t[4]=s,t[5]=c):(s=t[4],c=t[5]),(0,J.useEffect)(s,c);let l=d(rd.getAtom(o)),u;t[6]===o?u=t[7]:(u=async()=>({data:(await rd.refreshAsync(o)).data}),t[6]=o,t[7]=u);let f=u,p;return t[8]!==f||t[9]!==l.data||t[10]!==l.error||t[11]!==l.isFetching||t[12]!==l.isLoading?(p={data:l.data,isLoading:l.isLoading,isFetching:l.isFetching,error:l.error,refetch:f},t[8]=f,t[9]=l.data,t[10]=l.error,t[11]=l.isFetching,t[12]=l.isLoading,t[13]=p):p=t[13],p}var ld={},ud=(0,J.memo)(function(e){let t=(0,Y.c)(22),{files:n,allDirectoriesExpanded:r,onSelectFile:i,resolvedTheme:a,selectedFilePath:o,showStats:s}=e,c=o===void 0?null:o,l=s===void 0||s,u;t[0]===n?u=t[1]:(u=tn(n),t[0]=n,t[1]=u);let d=u,f;t[2]===d?f=t[3]:(f=dd(d).join(`\0`),t[2]=d,t[3]=f);let p=`${r?`expanded`:`collapsed`}\u0000${f}`,m;t[4]===p?m=t[5]:(m=()=>({key:p,overrides:{}}),t[4]=p,t[5]=m);let[h,g]=(0,J.useState)(m),_=h.key===p?h.overrides:ld,v;t[6]!==r||t[7]!==p?(v=e=>{g(t=>{let n=t.key===p?t.overrides:{};return{key:p,overrides:{...n,[e]:!(n[e]??r)}}})},t[6]=r,t[7]=p,t[8]=v):v=t[8];let y=v,b,x;if(t[9]!==r||t[10]!==_||t[11]!==i||t[12]!==a||t[13]!==c||t[14]!==l||t[15]!==y||t[16]!==d){let e=(t,n)=>{let o=8+n*14;if(t.kind===`directory`){let i=_[t.path]??r;return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`button`,{type:`button`,"data-scroll-anchor-ignore":!0,className:`group/tree-row flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80 phone:min-h-11`,style:{paddingLeft:`${o}px`},onClick:()=>y(t.path),children:[(0,X.jsx)(Te,{"aria-hidden":`true`,className:F(`size-3.5 shrink-0 text-muted-foreground/70 transition-transform`,i&&`rotate-90`)}),i?(0,X.jsx)(G,{className:`size-3.5 shrink-0 text-muted-foreground/75`}):(0,X.jsx)(ke,{className:`size-3.5 shrink-0 text-muted-foreground/75`}),(0,X.jsx)(`span`,{"data-tree-label":!0,className:`truncate font-mono text-[11px] text-muted-foreground/90 group-hover/tree-row:text-foreground/90`,children:t.name}),l&&qt(t.stat)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[10px] tabular-nums`,children:(0,X.jsx)(sn,{additions:t.stat.additions,deletions:t.stat.deletions})})]}),i&&(0,X.jsx)(`div`,{className:`space-y-0.5`,children:t.children.map(t=>e(t,n+1))})]},`dir:${t.path}`)}return(0,X.jsxs)(`button`,{type:`button`,className:F(`group/tree-row flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80 phone:min-h-11`,c===t.path&&`bg-accent text-accent-foreground hover:bg-accent`),style:{paddingLeft:`${o}px`},onClick:()=>i(t.path),children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,X.jsx)(Vt,{pathValue:t.path,kind:`file`,theme:a,className:`size-3.5 text-muted-foreground/70`}),(0,X.jsx)(`span`,{"data-tree-label":!0,className:F(`truncate font-mono text-[11px] text-muted-foreground/80 group-hover/tree-row:text-foreground/90`,c===t.path&&`text-accent-foreground`),children:t.name}),l&&t.stat&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[10px] tabular-nums`,children:(0,X.jsx)(sn,{additions:t.stat.additions,deletions:t.stat.deletions})})]},`file:${t.path}`)};b=`space-y-0.5`,x=d.map(t=>e(t,0)),t[9]=r,t[10]=_,t[11]=i,t[12]=a,t[13]=c,t[14]=l,t[15]=y,t[16]=d,t[17]=b,t[18]=x}else b=t[17],x=t[18];let S;return t[19]!==b||t[20]!==x?(S=(0,X.jsx)(`div`,{className:b,children:x}),t[19]=b,t[20]=x,t[21]=S):S=t[21],S});function dd(e){let t=[];for(let n of e)n.kind===`directory`&&(t.push(n.path),t.push(...dd(n.children)));return t}var fd=100,pd=1,md=2,hd=3,gd=class{#e=[];#t=[];#n;#r=!1;constructor(e){this.#n=Math.max(1,e?.maxEntries??fd)}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}clear(){this.#e.length=0,this.#t.length=0,this.#r=!1}clearRedo(){this.#t.length=0}push(e){this.#e.push(e),this.clearRedo(),this.#r=!0,this.#e.length>this.#n&&this.#e.shift()}setLastUndoSelectionsAfter(e){let t=this.#e[this.#e.length-1];t!==void 0&&(t.selectionsAfter=e.map(e=>({...e})))}setLastUndoLineAnnotations(e,t){let n=this.#e[this.#e.length-1];n!==void 0&&(n.lineAnnotationsBefore=e.slice(),n.lineAnnotationsAfter=t.slice())}peekUndo(){return this.#e[this.#e.length-1]}peekUndoForCoalescing(){return this.#r?this.peekUndo():void 0}replaceLastUndo(e){if(this.#e.length===0){this.push(e);return}this.#e[this.#e.length-1]=e,this.clearRedo(),this.#r=!0}popUndoToRedo(){let e=this.#e.pop();if(e!==void 0)return this.#t.push(e),this.#r=!1,e}popRedoToUndo(){let e=this.#t.pop();if(e!==void 0)return this.#e.push(e),this.#r=!1,e}};function _d(e,t,n,r,i,a,o,s){let c=[...t].sort((e,t)=>e.start-t.start),l=[],u;if(i?.length===c.length){let t=[];for(let n of i){if(n.start.line!==n.end.line||n.start.character!==n.end.character)break;t.push(e.offsetAt(n.start))}if(t.length===c.length){t.sort((e,t)=>e-t);let e=!0,n=!0;for(let r=0;r<c.length;r++){let i=c[r];if(i.text.length>0||i.start===i.end){e=!1,n=!1;break}e&&=t[r]===i.end,n&&=t[r]===i.start}u=e?md:n?hd:void 0}}for(let t=0,n=0;t<c.length;t++){let r=c[t],i=e.getTextSlice(r.start,r.end),a=r.start+n;l.push({start:a,end:a+r.text.length,text:i}),n+=r.text.length-(r.end-r.start)}return{forwardEdits:c.map(e=>({...e})),inverseEdits:l,versionBefore:n,versionAfter:r,selectionsBefore:i?.map(e=>({...e})),selectionsAfter:a?.map(e=>({...e})),lineAnnotationsBefore:o?.slice(),lineAnnotationsAfter:s?.slice(),coalescingMode:u}}function vd(e,t){if(e===void 0||e.undoBoundary===!0||t.undoBoundary===!0||e.forwardEdits.length===0||e.forwardEdits.length!==e.inverseEdits.length||e.forwardEdits.length!==t.forwardEdits.length||t.forwardEdits.length!==t.inverseEdits.length)return!1;let n;for(let r=0;r<e.forwardEdits.length;r++){let i=e.forwardEdits[r],a=e.inverseEdits[r],o=t.forwardEdits[r],s=t.inverseEdits[r],c=xd(o.start,e.forwardEdits),l=i.start<=i.end&&i.text.length>0&&!i.text.includes(`
1436
+ `,gu=`${pu}${mu}${hu}`,_u=`${pu}${hu}`;function vu(e,t=`diff-panel`){if(!e)return null;let n=e.trim();if(n.length===0)return null;try{let e=Hi(n,Wt(n,t)).flatMap(e=>e.files);return e.length>0?{kind:`files`,files:e}:{kind:`raw`,text:n,reason:`Unsupported diff format. Showing raw patch.`}}catch{return{kind:`raw`,text:n,reason:`Failed to parse patch. Showing raw patch.`}}}function yu(e){return Xl(e)}function bu(e){return!e||e.kind!==`files`?[]:e.files.toSorted((e,t)=>yu(e).localeCompare(yu(t),void 0,{numeric:!0,sensitivity:`base`}))}var xu=new Yl;function Su(e){return e.cacheKey??`${e.prevName??`none`}:${e.name}`}var Cu=`ryco-diff-search-match`,wu=150,Tu=80,Eu=1600;function Du(){return typeof CSS<`u`&&CSS.highlights!==void 0&&globalThis.Highlight!==void 0}function Ou(e,t,n=Eu){let r=e.getBoundingClientRect(),i=t.getBoundingClientRect();return r.bottom>=i.top-n&&r.top<=i.bottom+n&&r.right>=i.left-n&&r.left<=i.right+n}function ku(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return t&&t.closest(`[data-line-number-content]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode(),i=0;for(;r;){let e=r,a=i+e.data.length;t.push({node:e,start:i,end:a}),i=a,r=n.nextNode()}return{offsets:t,textLength:i}}function Au(e,t,n){for(let r of e)if(!(t<r.start||t>r.end)&&(t!==r.end||n!==`start`))return{node:r.node,offset:t-r.start};return null}function ju(e,t,n){let{offsets:r,textLength:i}=ku(e);if(r.length===0||t.start<0||t.end>i||t.start>=t.end)return;let a=Au(r,t.start,`start`),o=Au(r,t.end,`end`);if(!a||!o)return;let s=document.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset),n.push(s)}function Mu(e){let t=uu(e.lineIndexAttr);return t?e.matches.filter(n=>du(n,{renderMode:e.renderMode,lineIndexes:t,lineType:e.lineType})):[]}function Nu(e){if(cu(e.match,e.renderMode)===null)return null;let t=e.fileElement.querySelectorAll(`diffs-container`);for(let n of t){let t=n.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`);for(let n of t??[]){let t=uu(n.getAttribute(`data-line-index`));if(t&&du(e.match,{renderMode:e.renderMode,lineIndexes:t,lineType:n.getAttribute(`data-line-type`)}))return n}}return null}function Pu(e){let t=[],n=e.rootElement.querySelectorAll(`[data-diff-file-index]`);for(let r of n){if(!Ou(r,e.viewportElement))continue;let n=r.dataset.diffFileIndex,i=n?Number.parseInt(n,10):NaN;if(!Number.isFinite(i))continue;let a=e.matchesByFileIndex.get(i);if(!a||a.length===0)continue;let o=r.querySelectorAll(`diffs-container`);for(let n of o){let r=n.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`);for(let n of r??[]){if(!Ou(n,e.viewportElement))continue;let r=Mu({matches:a,renderMode:e.renderMode,lineIndexAttr:n.getAttribute(`data-line-index`),lineType:n.getAttribute(`data-line-type`)});for(let e of r)ju(n,e,t)}}}return t}function Fu(e){switch(e.type){case`new`:return`text-[var(--diffs-addition-base)]`;case`deleted`:return`text-[var(--diffs-deletion-base)]`;case`change`:case`rename-pure`:case`rename-changed`:return`text-[var(--diffs-modified-base)]`;default:return`text-muted-foreground/80`}}function Iu(e){let t=(0,Y.c)(219),{mode:n}=e,i=n===void 0?`inline`:n;Ce(`DiffPanel`);let a=ge(),{resolvedTheme:o}=ir(),s=h(),c=i===`phone`,[l,m]=(0,J.useState)(`stacked`),[_,v]=(0,J.useState)(c?!0:s.diffWordWrap),[y,b]=(0,J.useState)(s.diffIgnoreWhitespace),[x,S]=(0,J.useState)(Ku),[C,w]=(0,J.useState)(``),T;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(T={wait:wu},t[0]=T):T=t[0];let[E]=j(C,T),D;t[1]!==E||t[2]!==C?(D=C.trim().length===0?``:E,t[1]=E,t[2]=C,t[3]=D):D=t[3];let O=D,[k,A]=(0,J.useState)(0),M=(0,J.useRef)(null),ee=(0,J.useRef)(null),N=(0,J.useRef)(null),te=(0,J.useRef)(!1),[P,ie]=(0,J.useState)(!1),[ae,se]=(0,J.useState)(!1),F;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(F={strict:!1,select:Gu},t[4]=F):F=t[4];let ce=re(F),le;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(le={strict:!1,select:Wu},t[5]=le):le=t[5];let ue=oe(le),de=ue.diff===`1`,I=ce?.threadId??null,L;t[6]===ce?L=t[7]:(L=f(ce),t[6]=ce,t[7]=L);let R=d(L),pe=R?.projectId??null,z;t[8]!==pe||t[9]!==R?(z=e=>R&&pe?p(e,{environmentId:R.environmentId,projectId:pe}):void 0,t[8]=pe,t[9]=R,t[10]=z):z=t[10];let me=d(z),he=R?.worktreePath??me?.cwd,B=R?.environmentId??null,_e=he??null,ve;t[11]!==B||t[12]!==_e?(ve={environmentId:B,cwd:_e},t[11]=B,t[12]=_e,t[13]=ve):ve=t[13];let ye=u(ve).data?.isRepo??!0,{turnDiffSummaries:be,inferredCheckpointTurnCountByTurnId:Ee}=Ht(R),De;if(t[14]!==Ee||t[15]!==be){let e;t[17]===Ee?e=t[18]:(e=(e,t)=>{let n=e.checkpointTurnCount??Ee[e.turnId]??0,r=t.checkpointTurnCount??Ee[t.turnId]??0;return n===r?t.completedAt.localeCompare(e.completedAt):r-n},t[17]=Ee,t[18]=e),De=[...be].toSorted(e),t[14]=Ee,t[15]=be,t[16]=De}else De=t[16];let V=De,Oe=ue.diffTurnId??null,ke=Oe===null?null:ue.diffFilePath??null,Ae;t[19]!==V||t[20]!==Oe?(Ae=Oe===null?void 0:V.find(e=>e.turnId===Oe)??V[0],t[19]=V,t[20]=Oe,t[21]=Ae):Ae=t[21];let H=Ae,U=H&&(H.checkpointTurnCount??Ee[H.turnId]),je;t[22]===U?je=t[23]:(je=typeof U==`number`?{fromTurnCount:Math.max(0,U-1),toTurnCount:U}:null,t[22]=U,t[23]=je);let Me=je,Ne;if(t[24]!==Ee||t[25]!==V){bb0:{let e;t[27]===Ee?e=t[28]:(e=e=>e.checkpointTurnCount??Ee[e.turnId],t[27]=Ee,t[28]=e);let n=V.map(e).filter(Uu);if(n.length===0){Ne=void 0;break bb0}let r=Math.max(...n);Ne=r>0?r:void 0}t[24]=Ee,t[25]=V,t[26]=Ne}else Ne=t[26];let Pe=Ne,Fe;t[29]!==Pe||t[30]!==H?(Fe=!H&&typeof Pe==`number`?{fromTurnCount:0,toTurnCount:Pe}:null,t[29]=Pe,t[30]=H,t[31]=Fe):Fe=t[31];let Ie=H?Me:Fe,Le;bb1:{if(H||V.length===0){Le=null;break bb1}let e;t[32]===V?e=t[33]:(e=V.map(Hu).join(`,`),t[32]=V,t[33]=e),Le=`conversation:${e}`}let Re=Le,ze=R?.environmentId??null,W=Ie?.fromTurnCount??null,Be=Ie?.toTurnCount??null,Ve=H?`turn:${H.turnId}`:Re,He;t[34]!==I||t[35]!==y||t[36]!==ye||t[37]!==ze||t[38]!==W||t[39]!==Be||t[40]!==Ve?(He={environmentId:ze,threadId:I,fromTurnCount:W,toTurnCount:Be,ignoreWhitespace:y,cacheScope:Ve,enabled:ye},t[34]=I,t[35]=y,t[36]=ye,t[37]=ze,t[38]=W,t[39]=Be,t[40]=Ve,t[41]=He):He=t[41];let Ue=Wl(He),We=H?Ue.data?.diff:void 0,Ge=H?void 0:Ue.data?.diff,Ke=Ue.isLoading,qe=Ue.error instanceof Error?Ue.error.message:Ue.error?`Failed to load checkpoint diff.`:null,Je=H?We:Ge,Ye=typeof Je==`string`,Xe;t[42]!==Ye||t[43]!==Je?(Xe=Ye&&Je.trim().length===0,t[42]=Ye,t[43]=Je,t[44]=Xe):Xe=t[44];let Ze=Xe,Qe;if(t[45]!==Re||t[46]!==o||t[47]!==Je||t[48]!==H){bb2:{let e=`diff-panel:${o}`,n=typeof Je==`string`?Je.trim():``;if(n.length===0){let e;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(e={patch:null,files:[]},t[50]=e):e=t[50],Qe=e;break bb2}let r={turnId:H?`turn:${H.turnId}`:Re??`conversation`,filePath:e,blobSha:Wt(n)},i=xu.get(r);if(i){Qe=i;break bb2}let a=vu(Je,e),s={patch:a,files:bu(a)};a&&xu.set(r,s),Qe=s}t[45]=Re,t[46]=o,t[47]=Je,t[48]=H,t[49]=Qe}else Qe=t[49];let $e=Qe,et=$e.patch,tt=$e.files,nt;t[51]===tt?nt=t[52]:(nt=tu(tt),t[51]=tt,t[52]=nt);let rt=nt,it;t[53]===O?it=t[54]:(it=Zl(O),t[53]=O,t[54]=it);let at=it,ot;t[55]!==rt||t[56]!==O?(ot=iu(rt,O),t[55]=rt,t[56]=O,t[57]=ot):ot=t[57];let G=ot,st;t[58]===G?st=t[59]:(st=ou(G),t[58]=G,t[59]=st);let ct=st,lt;t[60]===tt?lt=t[61]:(lt=tt.map(Vu),t[60]=tt,t[61]=lt);let ut=lt,dt;bb3:{if(!at){dt=ut;break bb3}let e;if(t[62]!==G||t[63]!==tt){let n;t[65]===tt?n=t[66]:(n=e=>({fileDiff:tt[e],fileIndex:e}),t[65]=tt,t[66]=n),e=au(G).map(n),t[62]=G,t[63]=tt,t[64]=e}else e=t[64];dt=e}let ft=dt,pt;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(pt=()=>{A(0)},t[67]=pt):pt=t[67];let mt;t[68]!==at||t[69]!==tt?(mt=[at,tt],t[68]=at,t[69]=tt,t[70]=mt):mt=t[70],(0,J.useEffect)(pt,mt);let ht,gt;t[71]===G.length?(ht=t[72],gt=t[73]):(ht=()=>{A(e=>G.length===0?0:Math.min(e,G.length-1))},gt=[G.length],t[71]=G.length,t[72]=ht,t[73]=gt),(0,J.useEffect)(ht,gt);let _t;t[74]!==k||t[75]!==l||t[76]!==G?(_t=e=>{if(G.length===0)return;let t=su(k,G.length,e);A(t);let n=G[t],r=ee.current;if(!n||!r)return;let i=r.querySelector(`[data-diff-file-index="${n.fileIndex}"]`);if(!i)return;let a=Nu({fileElement:i,match:n,renderMode:l});(a??i).scrollIntoView({block:`center`,behavior:`smooth`}),!a&&cu(n,l)!==null&&window.requestAnimationFrame(()=>{Nu({fileElement:i,match:n,renderMode:l})?.scrollIntoView({block:`center`,behavior:`smooth`})})},t[74]=k,t[75]=l,t[76]=G,t[77]=_t):_t=t[77];let vt=_t,yt,bt;t[78]!==l||t[79]!==G.length||t[80]!==ct||t[81]!==at?(yt=()=>{if(!Du())return;let e=CSS.highlights,t=ee.current;if(!t||!at||G.length===0){e.delete(Cu);return}let n=0,r=0,i=new Map,a=t.querySelector(`.diff-render-surface`)??t.querySelector(`[data-virtualizer]`)??t,o=()=>{n=0,c();let r=Pu({rootElement:t,viewportElement:a,matchesByFileIndex:ct,renderMode:l});if(r.length===0){e.delete(Cu);return}e.set(Cu,new Highlight(...r))},s=()=>{n===0&&r===0&&(r=window.setTimeout(()=>{r=0,n=window.requestAnimationFrame(o)},Tu))},c=()=>{let e=t.querySelectorAll(`[data-diff-file-index]`);for(let t of e){if(!Ou(t,a))continue;let e=t.querySelectorAll(`diffs-container`);for(let t of e){let e=t.shadowRoot;if(!e||i.has(e))continue;let n=new MutationObserver(s);n.observe(e,{childList:!0,subtree:!0}),i.set(e,n)}}},u=new MutationObserver(s);u.observe(t,{childList:!0,subtree:!0}),a.addEventListener(`scroll`,s,{passive:!0});let d=new ResizeObserver(s);return d.observe(a),s(),()=>{u.disconnect(),a.removeEventListener(`scroll`,s),d.disconnect();for(let e of i.values())e.disconnect();i.clear(),r!==0&&window.clearTimeout(r),n!==0&&window.cancelAnimationFrame(n),e.delete(Cu)}},bt=[l,G.length,ct,at],t[78]=l,t[79]=G.length,t[80]=ct,t[81]=at,t[82]=yt,t[83]=bt):(yt=t[82],bt=t[83]),(0,J.useEffect)(yt,bt);let xt,St;t[84]===tt?(xt=t[85],St=t[86]):(xt=()=>{if(tt.length===0){S(Bu);return}let e=new Set(tt.map(Su));S(t=>{let n=new Set([...t].filter(t=>e.has(t)));return n.size===t.size?t:n})},St=[tt],t[84]=tt,t[85]=xt,t[86]=St),(0,J.useEffect)(xt,St);let Ct,wt;t[87]!==de||t[88]!==c||t[89]!==s.diffIgnoreWhitespace||t[90]!==s.diffWordWrap?(Ct=()=>{de&&!te.current&&(v(c?!0:s.diffWordWrap),b(s.diffIgnoreWhitespace),w(``)),te.current=de},wt=[de,c,s.diffIgnoreWhitespace,s.diffWordWrap],t[87]=de,t[88]=c,t[89]=s.diffIgnoreWhitespace,t[90]=s.diffWordWrap,t[91]=Ct,t[92]=wt):(Ct=t[91],wt=t[92]),(0,J.useEffect)(Ct,wt);let Et;t[93]===Symbol.for(`react.memo_cache_sentinel`)?(Et=()=>{w(``)},t[93]=Et):Et=t[93];let Dt;t[94]===Oe?Dt=t[95]:(Dt=[Oe],t[94]=Oe,t[95]=Dt),(0,J.useEffect)(Et,Dt);let Ot;t[96]===ke?Ot=t[97]:(Ot=()=>{!ke||!ee.current||Array.from(ee.current.querySelectorAll(`[data-diff-file-path]`)).find(e=>e.dataset.diffFilePath===ke)?.scrollIntoView({block:`nearest`})},t[96]=ke,t[97]=Ot);let kt;t[98]!==tt||t[99]!==ke?(kt=[ke,tt],t[98]=tt,t[99]=ke,t[100]=kt):kt=t[100],(0,J.useEffect)(Ot,kt);let At;t[101]===he?At=t[102]:(At=(e,t)=>{let n=g();if(!n)return;let r=fu({cwd:he,filePath:e,lineNumber:t});nr(n,r).catch(zu)},t[101]=he,t[102]=At);let jt=At,Nt;t[103]===Symbol.for(`react.memo_cache_sentinel`)?(Nt=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},t[103]=Nt):Nt=t[103];let Pt=Nt,Ft;t[104]!==R||t[105]!==a?(Ft=e=>{R&&a({to:`/$environmentId/$threadId`,params:ne(r(R.environmentId,R.id)),search:t=>({...fe(t),diff:`1`,diffTurnId:e})})},t[104]=R,t[105]=a,t[106]=Ft):Ft=t[106];let It=Ft,Lt;t[107]!==R||t[108]!==a?(Lt=()=>{R&&a({to:`/$environmentId/$threadId`,params:ne(r(R.environmentId,R.id)),search:Ru})},t[107]=R,t[108]=a,t[109]=Lt):Lt=t[109];let Rt=Lt,zt;t[110]===Symbol.for(`react.memo_cache_sentinel`)?(zt=()=>{let e=N.current;if(!e){ie(!1),se(!1);return}let t=Math.max(0,e.scrollWidth-e.clientWidth);ie(e.scrollLeft>4),se(e.scrollLeft<t-4)},t[110]=zt):zt=t[110];let Bt=zt,Vt;t[111]===Symbol.for(`react.memo_cache_sentinel`)?(Vt=e=>{let t=N.current;t&&t.scrollBy({left:e,behavior:`smooth`})},t[111]=Vt):Vt=t[111];let Ut=Vt,Gt;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Gt=e=>{let t=N.current;t&&(t.scrollWidth<=t.clientWidth+1||Math.abs(e.deltaY)<=Math.abs(e.deltaX)||(e.preventDefault(),t.scrollBy({left:e.deltaY,behavior:`auto`})))},t[112]=Gt):Gt=t[112];let Kt=Gt,qt,Jt;t[113]===Symbol.for(`react.memo_cache_sentinel`)?(qt=()=>{let e=N.current;if(!e)return;let t=window.requestAnimationFrame(()=>Bt()),n=()=>Bt();e.addEventListener(`scroll`,n,{passive:!0});let r=new ResizeObserver(()=>Bt());return r.observe(e),()=>{window.cancelAnimationFrame(t),e.removeEventListener(`scroll`,n),r.disconnect()}},Jt=[Bt],t[113]=qt,t[114]=Jt):(qt=t[113],Jt=t[114]),(0,J.useEffect)(qt,Jt);let Yt;t[115]===Symbol.for(`react.memo_cache_sentinel`)?(Yt=()=>{let e=window.requestAnimationFrame(()=>Bt());return()=>{window.cancelAnimationFrame(e)}},t[115]=Yt):Yt=t[115];let Xt;t[116]!==V||t[117]!==Oe?(Xt=[V,Oe,Bt],t[116]=V,t[117]=Oe,t[118]=Xt):Xt=t[118],(0,J.useEffect)(Yt,Xt);let Zt;t[119]===Symbol.for(`react.memo_cache_sentinel`)?(Zt=()=>{let e=N.current;e&&e.querySelector(`[data-turn-chip-selected='true']`)?.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`smooth`})},t[119]=Zt):Zt=t[119];let Qt=H?.turnId,$t;t[120]!==Oe||t[121]!==Qt?($t=[Qt,Oe],t[120]=Oe,t[121]=Qt,t[122]=$t):$t=t[122],(0,J.useEffect)(Zt,$t);let en;t[123]!==P||t[124]!==ae||t[125]!==c?(en=c?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:q(`absolute left-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors`,P?`border-border/70 hover:border-border hover:text-foreground`:`cursor-not-allowed border-border/40 text-muted-foreground/40`),onClick:()=>Ut(-180),disabled:!P,"aria-label":`Scroll turn list left`,children:(0,X.jsx)(Se,{className:`size-3.5`})}),(0,X.jsx)(`button`,{type:`button`,className:q(`absolute right-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors`,ae?`border-border/70 hover:border-border hover:text-foreground`:`cursor-not-allowed border-border/40 text-muted-foreground/40`),onClick:()=>Ut(180),disabled:!ae,"aria-label":`Scroll turn list right`,children:(0,X.jsx)(we,{className:`size-3.5`})})]}),t[123]=P,t[124]=ae,t[125]=c,t[126]=en):en=t[126];let tn=c?`px-1`:`px-8`,nn;t[127]===tn?nn=t[128]:(nn=q(`turn-chip-strip flex gap-1 overflow-x-auto py-0.5`,tn),t[127]=tn,t[128]=nn);let an;t[129]!==P||t[130]!==ae||t[131]!==c?(an=!c&&(P||ae)?{maskImage:`linear-gradient(to right, ${P?`transparent 24px, black 72px`:`black`}, ${ae?`black calc(100% - 72px), transparent calc(100% - 24px)`:`black`})`}:void 0,t[129]=P,t[130]=ae,t[131]=c,t[132]=an):an=t[132];let on=c&&`min-h-[44px]`,sn;t[133]===on?sn=t[134]:(sn=q(`shrink-0 rounded-md`,on),t[133]=on,t[134]=sn);let cn=Oe===null,ln=c&&`flex min-h-[44px] items-center`,un=Oe===null?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`,dn;t[135]!==ln||t[136]!==un?(dn=q(`rounded-md border px-2 py-1 text-left transition-colors`,ln,un),t[135]=ln,t[136]=un,t[137]=dn):dn=t[137];let fn;t[138]===Symbol.for(`react.memo_cache_sentinel`)?(fn=(0,X.jsx)(`div`,{className:`text-[10px] leading-tight font-medium`,children:`All turns`}),t[138]=fn):fn=t[138];let K;t[139]===dn?K=t[140]:(K=(0,X.jsx)(`div`,{className:dn,children:fn}),t[139]=dn,t[140]=K);let pn;t[141]!==Rt||t[142]!==sn||t[143]!==cn||t[144]!==K?(pn=(0,X.jsx)(`button`,{type:`button`,className:sn,onClick:Rt,"data-turn-chip-selected":cn,children:K}),t[141]=Rt,t[142]=sn,t[143]=cn,t[144]=K,t[145]=pn):pn=t[145];let mn;if(t[146]!==Ee||t[147]!==c||t[148]!==V||t[149]!==It||t[150]!==H?.turnId||t[151]!==s.timestampFormat){let e;t[153]!==Ee||t[154]!==c||t[155]!==It||t[156]!==H?.turnId||t[157]!==s.timestampFormat?(e=e=>(0,X.jsx)(`button`,{type:`button`,className:q(`shrink-0 rounded-md`,c&&`min-h-[44px]`),onClick:()=>It(e.turnId),title:e.turnId,"data-turn-chip-selected":e.turnId===H?.turnId,children:(0,X.jsx)(`div`,{className:q(`rounded-md border px-2 py-1 text-left transition-colors`,c&&`flex min-h-[44px] items-center`,e.turnId===H?.turnId?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] leading-tight font-medium`,children:[`Turn`,` `,e.checkpointTurnCount??Ee[e.turnId]??`?`]}),(0,X.jsx)(`span`,{className:`text-[9px] leading-tight opacity-70`,children:Ln(e.completedAt,s.timestampFormat)})]})})},e.turnId),t[153]=Ee,t[154]=c,t[155]=It,t[156]=H?.turnId,t[157]=s.timestampFormat,t[158]=e):e=t[158],mn=V.map(e),t[146]=Ee,t[147]=c,t[148]=V,t[149]=It,t[150]=H?.turnId,t[151]=s.timestampFormat,t[152]=mn}else mn=t[152];let hn;t[159]!==nn||t[160]!==an||t[161]!==pn||t[162]!==mn?(hn=(0,X.jsxs)(`div`,{ref:N,className:nn,style:an,onWheel:Kt,children:[pn,mn]}),t[159]=nn,t[160]=an,t[161]=pn,t[162]=mn,t[163]=hn):hn=t[163];let gn;t[164]!==en||t[165]!==hn?(gn=(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1 [-webkit-app-region:no-drag]`,children:[en,hn]}),t[164]=en,t[165]=hn,t[166]=gn):gn=t[166];let _n;t[167]!==l||t[168]!==c?(_n=c?null:(0,X.jsxs)(ar,{className:`shrink-0`,variant:`outline`,size:`xs`,value:[l],onValueChange:e=>{let t=e[0];(t===`stacked`||t===`split`)&&m(t)},children:[(0,X.jsx)(or,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,X.jsx)(Tr,{className:`size-3`})}),(0,X.jsx)(or,{"aria-label":`Split diff view`,value:`split`,children:(0,X.jsx)(pr,{className:`size-3`})})]}),t[167]=l,t[168]=c,t[169]=_n):_n=t[169];let vn=_?`Disable diff line wrapping`:`Enable diff line wrapping`,yn=_?`Disable line wrapping`:`Enable line wrapping`,xn=c&&`min-h-[44px] min-w-[44px]`,Sn;t[170]===xn?Sn=t[171]:(Sn=q(xn),t[170]=xn,t[171]=Sn);let Cn,wn;t[172]===Symbol.for(`react.memo_cache_sentinel`)?(Cn=e=>{v(!!e)},wn=(0,X.jsx)(Er,{className:`size-3`}),t[172]=Cn,t[173]=wn):(Cn=t[172],wn=t[173]);let Tn;t[174]!==_||t[175]!==vn||t[176]!==yn||t[177]!==Sn?(Tn=(0,X.jsx)(or,{"aria-label":vn,title:yn,variant:`outline`,size:`xs`,className:Sn,pressed:_,onPressedChange:Cn,children:wn}),t[174]=_,t[175]=vn,t[176]=yn,t[177]=Sn,t[178]=Tn):Tn=t[178];let En=y?`Show whitespace changes`:`Hide whitespace changes`,On=y?`Show whitespace changes`:`Hide whitespace changes`,kn=c&&`min-h-[44px] min-w-[44px]`,An;t[179]===kn?An=t[180]:(An=q(kn),t[179]=kn,t[180]=An);let jn,Mn;t[181]===Symbol.for(`react.memo_cache_sentinel`)?(jn=e=>{b(!!e)},Mn=(0,X.jsx)(Cr,{className:`size-3`}),t[181]=jn,t[182]=Mn):(jn=t[181],Mn=t[182]);let Nn;t[183]!==y||t[184]!==En||t[185]!==On||t[186]!==An?(Nn=(0,X.jsx)(or,{"aria-label":En,title:On,variant:`outline`,size:`xs`,className:An,pressed:y,onPressedChange:jn,children:Mn}),t[183]=y,t[184]=En,t[185]=On,t[186]=An,t[187]=Nn):Nn=t[187];let Pn;t[188]!==_n||t[189]!==Tn||t[190]!==Nn?(Pn=(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[_n,Tn,Nn]}),t[188]=_n,t[189]=Tn,t[190]=Nn,t[191]=Pn):Pn=t[191];let Fn;t[192]!==gn||t[193]!==Pn?(Fn=(0,X.jsxs)(X.Fragment,{children:[gn,Pn]}),t[192]=gn,t[193]=Pn,t[194]=Fn):Fn=t[194];let In=Fn,Rn;t[195]!==R||t[196]!==qe||t[197]!==x||t[198]!==k||t[199]!==l||t[200]!==G.length||t[201]!==C||t[202]!==_||t[203]!==ft||t[204]!==vt||t[205]!==Ze||t[206]!==ye||t[207]!==Ke||t[208]!==c||t[209]!==at||t[210]!==jt||t[211]!==V.length||t[212]!==et||t[213]!==o?(Rn=R?ye?V.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No completed turns yet.`}):(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{ref:ee,className:`diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[qe&&!et&&(0,X.jsx)(`div`,{className:`px-3`,children:(0,X.jsx)(`p`,{className:`mb-2 text-[11px] text-red-500/80`,children:qe})}),et?et.kind===`files`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/50 bg-card/40 px-2.5 py-1.5 [-webkit-app-region:no-drag]`,children:[(0,X.jsx)(bn,{className:`size-3.5 shrink-0 text-muted-foreground/70`}),(0,X.jsx)(`input`,{ref:M,type:`text`,value:C,onChange:e=>w(e.target.value),onKeyDown:e=>{if(e.key===`Escape`){w(``),e.currentTarget.blur();return}e.key===`Enter`&&at&&(e.preventDefault(),vt(e.shiftKey?-1:1))},placeholder:`Search files or hunks...`,"aria-label":`Search diff`,className:q(`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground/55`,c&&`min-h-[44px]`)}),at&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`shrink-0 text-[10px] tabular-nums text-muted-foreground/70`,children:[G.length===0?0:k+1,` of`,` `,G.length]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>vt(-1),disabled:G.length===0,className:q(`inline-flex size-5 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-muted-foreground/70`,c&&`size-[44px]`),"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,children:(0,X.jsx)(Te,{className:`size-3.5`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>vt(1),disabled:G.length===0,className:q(`inline-flex size-5 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-muted-foreground/70`,c&&`size-[44px]`),"aria-label":`Next match`,title:`Next match (Enter)`,children:(0,X.jsx)(xe,{className:`size-3.5`})})]})]}),C&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>{w(``),M.current?.focus()},className:q(`inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground`,c&&`size-[44px]`),"aria-label":`Clear search`,title:`Clear search`,children:(0,X.jsx)(Dn,{className:`size-3`})})]}),ft.length===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,X.jsxs)(`p`,{children:[`No files match “`,C,`”.`]})}):(0,X.jsx)(Pl,{className:q(`diff-render-surface min-h-0 flex-1 overflow-auto px-2 pb-2`,c&&`overflow-x-hidden overflow-y-auto overscroll-x-contain`),config:{overscrollSize:600,intersectionObserverMargin:1200},children:ft.map(e=>{let{fileDiff:t,fileIndex:n}=e,r=yu(t),i=Su(t),a=`${i}:${o}`,s=x.has(i);return(0,X.jsx)(`div`,{"data-diff-file-path":r,"data-diff-file-index":n,className:`diff-render-file group/diff-file mb-2 rounded-md first:mt-2 last:mb-0`,onClickCapture:c?void 0:e=>{(e.nativeEvent.composedPath?.()??[]).some(Lu)&&jt(r)},children:(0,X.jsx)(Ul,{fileDiff:t,renderHeaderPrefix:()=>(0,X.jsx)(`button`,{type:`button`,className:q(`inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden`,c&&`size-[44px]`,Fu(t)),"aria-label":s?`Expand ${r}`:`Collapse ${r}`,"aria-expanded":!s,title:s?`Expand diff`:`Collapse diff`,onClick:e=>{e.stopPropagation(),Pt(i)},children:s?(0,X.jsx)(we,{className:`size-4`}):(0,X.jsx)(xe,{className:`size-4`})}),options:{collapsed:s,diffStyle:l===`split`?`split`:`unified`,lineDiffType:`none`,overflow:_?`wrap`:`scroll`,theme:Mt(o),themeType:o,unsafeCSS:c?_u:gu,lineHoverHighlight:`number`,...c?{}:{onLineNumberClick:e=>{let{lineNumber:t}=e;jt(r,t)}}}})},a)})})]}):(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:et.reason}),(0,X.jsx)(`pre`,{className:q(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,_?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:et.text})]})}):Ke?(0,X.jsx)(rn,{label:`Loading checkpoint diff...`}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-3 py-2 text-xs text-muted-foreground/70`,children:(0,X.jsx)(`p`,{children:Ze?`No net changes in this selection.`:`No patch available for this selection.`})})]})}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Turn diffs are unavailable because this project is not a git repository.`}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to inspect turn diffs.`}),t[195]=R,t[196]=qe,t[197]=x,t[198]=k,t[199]=l,t[200]=G.length,t[201]=C,t[202]=_,t[203]=ft,t[204]=vt,t[205]=Ze,t[206]=ye,t[207]=Ke,t[208]=c,t[209]=at,t[210]=jt,t[211]=V.length,t[212]=et,t[213]=o,t[214]=Rn):Rn=t[214];let zn;return t[215]!==In||t[216]!==i||t[217]!==Rn?(zn=(0,X.jsx)(Tt,{mode:i,header:In,children:Rn}),t[215]=In,t[216]=i,t[217]=Rn,t[218]=zn):zn=t[218],zn}function Lu(e){return e instanceof Element&&e.hasAttribute(`data-title`)}function Ru(e){return{...fe(e),diff:`1`}}function zu(e){console.warn(`Failed to open diff in editor.`,e)}function Bu(e){return e.size===0?e:new Set}function Vu(e,t){return{fileDiff:e,fileIndex:t}}function Hu(e){return e.turnId}function Uu(e){return typeof e==`number`}function Wu(e){return R(e)}function Gu(e){return ie(e)}function Ku(){return new Set}var qu=0,Ju=0,Yu=1,Xu=6e4,Zu=Object.freeze({data:null,isLoading:!1,isFetching:!1,error:null}),Qu=A({labelPrefix:`project-preview`,initialState:Zu,gcTime:Xu,maxEntries:48,buildFetchingState:e=>({data:e.data,isLoading:e.data===null,isFetching:!0,error:null}),buildSuccessState:e=>({data:e,isLoading:!1,isFetching:!1,error:null}),buildErrorState:(e,t)=>({data:e.data,isLoading:!1,isFetching:!1,error:t})});function $u(e,t=Yu){return e().catch(n=>{if(t<=0)throw n;return $u(e,t-1)})}function ed(e){return k(Qu,{...e,createControllerFields:()=>({})},e=>!e.hasData||Date.now()-e.lastFetchedAt>=e.staleTime)}function td(e){return w(e).projects}var nd=ed({label:`listEntries`,staleTime:qu,isEnabled:e=>(e.enabled??!0)&&e.environmentId!==null&&e.cwd!==null,buildKey:e=>`${e.environmentId}${e.cwd}`,resolveEnvironmentId:e=>e.environmentId,run:e=>$u(()=>td(e.environmentId).listEntries({cwd:e.cwd}))}),rd=ed({label:`readFile`,staleTime:Ju,isEnabled:e=>(e.enabled??!0)&&e.environmentId!==null&&e.cwd!==null&&e.relativePath!==null,buildKey:e=>`${e.environmentId}${e.cwd}${e.relativePath}`,resolveEnvironmentId:e=>e.environmentId,run:e=>$u(()=>td(e.environmentId).readFile({cwd:e.cwd,relativePath:e.relativePath}))});function id(e,t){let n=rd.keyOf(e);if(n===null)return;let r=Qu.controllers.get(n);r&&(r.hasData=!0,r.lastFetchedAt=Date.now()),Qu.setQueryState(n,{data:t,isLoading:!1,isFetching:!1,error:null})}function ad(e){let t=(0,Y.c)(18),{environmentId:n,cwd:r,enabled:i}=e,a=nd.keyOf(e),o,s;t[0]!==r||t[1]!==i||t[2]!==n?(o=()=>nd.watch({environmentId:n,cwd:r,...i===void 0?{}:{enabled:i}}),s=[n,r,i],t[0]=r,t[1]=i,t[2]=n,t[3]=o,t[4]=s):(o=t[3],s=t[4]),(0,J.useEffect)(o,s);let c=y(nd.getAtom(a)),l;bb0:{if(!c.data){l=null;break bb0}let e=c.data,n;t[5]===c.data.entries?n=t[6]:(n=c.data.entries.toSorted(sd),t[5]=c.data.entries,t[6]=n);let r;t[7]!==c.data||t[8]!==n?(r={...e,entries:n},t[7]=c.data,t[8]=n,t[9]=r):r=t[9],l=r}let u=l,d;t[10]===a?d=t[11]:(d=async()=>{let e=await nd.refreshAsync(a);return{data:e.data===null?null:{...e.data,entries:e.data.entries.toSorted(od)}}},t[10]=a,t[11]=d);let f=d,p;return t[12]!==f||t[13]!==u||t[14]!==c.error||t[15]!==c.isFetching||t[16]!==c.isLoading?(p={data:u,isLoading:c.isLoading,isFetching:c.isFetching,error:c.error,refetch:f},t[12]=f,t[13]=u,t[14]=c.error,t[15]=c.isFetching,t[16]=c.isLoading,t[17]=p):p=t[17],p}function od(e,t){return e.path.localeCompare(t.path,void 0,{numeric:!0,sensitivity:`base`})}function sd(e,t){return e.path.localeCompare(t.path,void 0,{numeric:!0,sensitivity:`base`})}function cd(e){let t=(0,Y.c)(14),{environmentId:n,cwd:r,relativePath:i,enabled:a}=e,o=rd.keyOf(e),s,c;t[0]!==r||t[1]!==a||t[2]!==n||t[3]!==i?(s=()=>rd.watch({environmentId:n,cwd:r,relativePath:i,...a===void 0?{}:{enabled:a}}),c=[n,r,i,a],t[0]=r,t[1]=a,t[2]=n,t[3]=i,t[4]=s,t[5]=c):(s=t[4],c=t[5]),(0,J.useEffect)(s,c);let l=y(rd.getAtom(o)),u;t[6]===o?u=t[7]:(u=async()=>({data:(await rd.refreshAsync(o)).data}),t[6]=o,t[7]=u);let d=u,f;return t[8]!==d||t[9]!==l.data||t[10]!==l.error||t[11]!==l.isFetching||t[12]!==l.isLoading?(f={data:l.data,isLoading:l.isLoading,isFetching:l.isFetching,error:l.error,refetch:d},t[8]=d,t[9]=l.data,t[10]=l.error,t[11]=l.isFetching,t[12]=l.isLoading,t[13]=f):f=t[13],f}var ld={},ud=(0,J.memo)(function(e){let t=(0,Y.c)(22),{files:n,allDirectoriesExpanded:r,onSelectFile:i,resolvedTheme:a,selectedFilePath:o,showStats:s}=e,c=o===void 0?null:o,l=s===void 0||s,u;t[0]===n?u=t[1]:(u=en(n),t[0]=n,t[1]=u);let d=u,f;t[2]===d?f=t[3]:(f=dd(d).join(`\0`),t[2]=d,t[3]=f);let p=`${r?`expanded`:`collapsed`}\u0000${f}`,m;t[4]===p?m=t[5]:(m=()=>({key:p,overrides:{}}),t[4]=p,t[5]=m);let[h,g]=(0,J.useState)(m),_=h.key===p?h.overrides:ld,v;t[6]!==r||t[7]!==p?(v=e=>{g(t=>{let n=t.key===p?t.overrides:{};return{key:p,overrides:{...n,[e]:!(n[e]??r)}}})},t[6]=r,t[7]=p,t[8]=v):v=t[8];let y=v,b,x;if(t[9]!==r||t[10]!==_||t[11]!==i||t[12]!==a||t[13]!==c||t[14]!==l||t[15]!==y||t[16]!==d){let e=(t,n)=>{let o=8+n*14;if(t.kind===`directory`){let i=_[t.path]??r;return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`button`,{type:`button`,"data-scroll-anchor-ignore":!0,className:`group/tree-row flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80 phone:min-h-11`,style:{paddingLeft:`${o}px`},onClick:()=>y(t.path),children:[(0,X.jsx)(we,{"aria-hidden":`true`,className:q(`size-3.5 shrink-0 text-muted-foreground/70 transition-transform`,i&&`rotate-90`)}),i?(0,X.jsx)(H,{className:`size-3.5 shrink-0 text-muted-foreground/75`}):(0,X.jsx)(ke,{className:`size-3.5 shrink-0 text-muted-foreground/75`}),(0,X.jsx)(`span`,{"data-tree-label":!0,className:`truncate font-mono text-[11px] text-muted-foreground/90 group-hover/tree-row:text-foreground/90`,children:t.name}),l&&Kt(t.stat)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[10px] tabular-nums`,children:(0,X.jsx)(on,{additions:t.stat.additions,deletions:t.stat.deletions})})]}),i&&(0,X.jsx)(`div`,{className:`space-y-0.5`,children:t.children.map(t=>e(t,n+1))})]},`dir:${t.path}`)}return(0,X.jsxs)(`button`,{type:`button`,className:q(`group/tree-row flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80 phone:min-h-11`,c===t.path&&`bg-accent text-accent-foreground hover:bg-accent`),style:{paddingLeft:`${o}px`},onClick:()=>i(t.path),children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`size-3.5 shrink-0`}),(0,X.jsx)(Bt,{pathValue:t.path,kind:`file`,theme:a,className:`size-3.5 text-muted-foreground/70`}),(0,X.jsx)(`span`,{"data-tree-label":!0,className:q(`truncate font-mono text-[11px] text-muted-foreground/80 group-hover/tree-row:text-foreground/90`,c===t.path&&`text-accent-foreground`),children:t.name}),l&&t.stat&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[10px] tabular-nums`,children:(0,X.jsx)(on,{additions:t.stat.additions,deletions:t.stat.deletions})})]},`file:${t.path}`)};b=`space-y-0.5`,x=d.map(t=>e(t,0)),t[9]=r,t[10]=_,t[11]=i,t[12]=a,t[13]=c,t[14]=l,t[15]=y,t[16]=d,t[17]=b,t[18]=x}else b=t[17],x=t[18];let S;return t[19]!==b||t[20]!==x?(S=(0,X.jsx)(`div`,{className:b,children:x}),t[19]=b,t[20]=x,t[21]=S):S=t[21],S});function dd(e){let t=[];for(let n of e)n.kind===`directory`&&(t.push(n.path),t.push(...dd(n.children)));return t}var fd=100,pd=1,md=2,hd=3,gd=class{#e=[];#t=[];#n;#r=!1;constructor(e){this.#n=Math.max(1,e?.maxEntries??fd)}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}clear(){this.#e.length=0,this.#t.length=0,this.#r=!1}clearRedo(){this.#t.length=0}push(e){this.#e.push(e),this.clearRedo(),this.#r=!0,this.#e.length>this.#n&&this.#e.shift()}setLastUndoSelectionsAfter(e){let t=this.#e[this.#e.length-1];t!==void 0&&(t.selectionsAfter=e.map(e=>({...e})))}setLastUndoLineAnnotations(e,t){let n=this.#e[this.#e.length-1];n!==void 0&&(n.lineAnnotationsBefore=e.slice(),n.lineAnnotationsAfter=t.slice())}peekUndo(){return this.#e[this.#e.length-1]}peekUndoForCoalescing(){return this.#r?this.peekUndo():void 0}replaceLastUndo(e){if(this.#e.length===0){this.push(e);return}this.#e[this.#e.length-1]=e,this.clearRedo(),this.#r=!0}popUndoToRedo(){let e=this.#e.pop();if(e!==void 0)return this.#t.push(e),this.#r=!1,e}popRedoToUndo(){let e=this.#t.pop();if(e!==void 0)return this.#e.push(e),this.#r=!1,e}};function _d(e,t,n,r,i,a,o,s){let c=[...t].sort((e,t)=>e.start-t.start),l=[],u;if(i?.length===c.length){let t=[];for(let n of i){if(n.start.line!==n.end.line||n.start.character!==n.end.character)break;t.push(e.offsetAt(n.start))}if(t.length===c.length){t.sort((e,t)=>e-t);let e=!0,n=!0;for(let r=0;r<c.length;r++){let i=c[r];if(i.text.length>0||i.start===i.end){e=!1,n=!1;break}e&&=t[r]===i.end,n&&=t[r]===i.start}u=e?md:n?hd:void 0}}for(let t=0,n=0;t<c.length;t++){let r=c[t],i=e.getTextSlice(r.start,r.end),a=r.start+n;l.push({start:a,end:a+r.text.length,text:i}),n+=r.text.length-(r.end-r.start)}return{forwardEdits:c.map(e=>({...e})),inverseEdits:l,versionBefore:n,versionAfter:r,selectionsBefore:i?.map(e=>({...e})),selectionsAfter:a?.map(e=>({...e})),lineAnnotationsBefore:o?.slice(),lineAnnotationsAfter:s?.slice(),coalescingMode:u}}function vd(e,t){if(e===void 0||e.undoBoundary===!0||t.undoBoundary===!0||e.forwardEdits.length===0||e.forwardEdits.length!==e.inverseEdits.length||e.forwardEdits.length!==t.forwardEdits.length||t.forwardEdits.length!==t.inverseEdits.length)return!1;let n;for(let r=0;r<e.forwardEdits.length;r++){let i=e.forwardEdits[r],a=e.inverseEdits[r],o=t.forwardEdits[r],s=t.inverseEdits[r],c=xd(o.start,e.forwardEdits),l=i.start<=i.end&&i.text.length>0&&!i.text.includes(`
1437
1437
  `)&&!a.text.includes(`
1438
1438
  `),u=o.start===o.end&&o.text.length>0&&!o.text.includes(`
1439
- `)&&s.text.length===0;if(l&&u){if(o.start!==a.end||(n??=pd,n!==pd||e.coalescingMode!==void 0&&e.coalescingMode!==pd||t.coalescingMode!==void 0&&t.coalescingMode!==pd))return!1;continue}let d=i.text.length===0&&i.end>i.start&&a.text.length>0,f=o.text.length===0&&o.end>o.start&&s.text.length>0;if(d&&f){let r;if(c===i.end)r=hd;else if(c+(o.end-o.start)!==i.start)return!1;else r=md;if(n??=r,n!==r||e.coalescingMode!==void 0&&e.coalescingMode!==r||t.coalescingMode!==void 0&&t.coalescingMode!==r)return!1;continue}return!1}return n!==void 0}function yd(e,t){let n=[],r=[],i;for(let a=0;a<e.forwardEdits.length;a++){let o=e.forwardEdits[a],s=e.inverseEdits[a],c=t.forwardEdits[a],l=t.inverseEdits[a],u=xd(c.start,e.forwardEdits);if(o.text.length>0){i??=pd,n.push({start:o.start,end:o.end,text:o.text+c.text}),r.push(s.text);continue}if(u===o.end){i??=hd,n.push({start:o.start,end:u+(c.end-c.start),text:``}),r.push(s.text+l.text);continue}i??=md,n.push({start:Math.min(o.start,u),end:o.end,text:``}),r.push(l.text+s.text)}return{forwardEdits:n,inverseEdits:bd(n,r),versionBefore:e.versionBefore,versionAfter:t.versionAfter,selectionsBefore:e.selectionsBefore?.slice(),selectionsAfter:t.selectionsAfter?.slice(),lineAnnotationsBefore:e.lineAnnotationsBefore?.slice(),lineAnnotationsAfter:t.lineAnnotationsAfter?.slice(),coalescingMode:i}}function bd(e,t){let n=[];for(let r=0,i=0;r<e.length;r++){let a=e[r],o=a.start+i;n.push({start:o,end:o+a.text.length,text:t[r]}),i+=a.text.length-(a.end-a.start)}return n}function xd(e,t){let n=e;for(let e of t){let t=e.end-e.start,r=e.text.length,i=r-t;if(!(n<e.start)){if(n>=e.start+r){n-=i;continue}n=e.start+Math.min(n-e.start,t)}}return n}var Sd=1e5,Cd=10,wd=13,Td=`\`~!@#$%^&*()-=+[{]}\\|;:'",.<>/?`,Ed=class{source;offset;length;lineOffsetStart;lineOffsetEnd;hasVirtualTrailingCRBreak;firstCharCode;lastCharCode;static Original=0;static Added=1;constructor(e,t,n,r,i,a,o,s){this.source=e,this.offset=t,this.length=n,this.lineOffsetStart=r,this.lineOffsetEnd=i,this.hasVirtualTrailingCRBreak=a,this.firstCharCode=o,this.lastCharCode=s}get lineBreakCount(){return this.lineOffsetEnd-this.lineOffsetStart+ +!!this.hasVirtualTrailingCRBreak}},Dd=class{text;lineOffsets;constructor(e){this.text=e,this.lineOffsets=yt(e)}append(e){let t=this.text.length;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r===Cd||r===wd)&&(r===wd&&e.charCodeAt(n+1)===Cd&&n++,this.lineOffsets.push(t+n+1))}return this.text+=e,t}},Od=class{piece;subtreeLength;subtreeLineBreakCount;subtreeFirstCharCode;subtreeLastCharCode;left=null;right=null;parent=null;priority=0;constructor(e,t=e.length,n=e.lineBreakCount,r=e.firstCharCode,i=e.lastCharCode){this.piece=e,this.subtreeLength=t,this.subtreeLineBreakCount=n,this.subtreeFirstCharCode=r,this.subtreeLastCharCode=i}updateSubtreeLength(){this.subtreeLength=(this.left?.subtreeLength??0)+this.piece.length+(this.right?.subtreeLength??0),this.subtreeLineBreakCount=(this.left?.subtreeLineBreakCount??0)+this.piece.lineBreakCount+(this.right?.subtreeLineBreakCount??0)-+!!Ld(this.left?.subtreeLastCharCode,this.piece.firstCharCode)-!!Ld(this.piece.lastCharCode,this.right?.subtreeFirstCharCode),this.subtreeFirstCharCode=this.left?.subtreeFirstCharCode??this.piece.firstCharCode,this.subtreeLastCharCode=this.right?.subtreeLastCharCode??this.piece.lastCharCode}},kd=class{#e;#t=new Dd(``);#n=null;#r=0;#i=0;#a=null;#o=null;#s=null;#c=2654435769;constructor(e){this.#e=new Dd(e);let t=this.#y(Ed.Original,0,e.length);this.#n=t.length>0?this.#C(t):null,this.#r=this.#n?.subtreeLength??0,this.#i=(this.#n?.subtreeLineBreakCount??0)+1}get lineCount(){return this.#i}getText(e){if(e===void 0)return this.#g();let t=this.offsetAt(e.start),n=this.offsetAt(e.end);return this.getTextSlice(t,n)}getLineText(e,t=!1){if(this.#a!==null&&this.#a[0]===e&&this.#a[1]===t)return this.#a[2];let n=this.#f(e);if(n===void 0)throw Error(`Line index out of range: ${e}`);let r=this.getTextSlice(n[0],n[1],!t);return this.#a=[e,t,r],this.#o=[e,t,r.length],r}getLineLength(e,t=!1){let n=this.#o,r=this.#a;if(n!==null&&n[0]===e&&n[1]===t)return n[2];if(r!==null&&r[0]===e&&r[1]===t){let n=r[2].length;return this.#o=[e,t,n],n}let i=this.#f(e);if(i===void 0)throw Error(`Line index out of range: ${e}`);let[a,o]=i,s=o-a;if(!t)for(;s>0&&Ad(this.charAt(a+s-1).charCodeAt(0));)s--;return this.#o=[e,t,s],s}getTextSlice(e,t,n=!1){if(e>=t)return``;let r=jd(e,0,this.#r),i=jd(t,r,this.#r);if(r>=i)return``;let a=this.#u(r);if(a===void 0)return``;let o=[],[s,c]=a,l=i-r;for(;s!==null&&l>0;){let e=Math.min(s.piece.length-c,l),t=this.#v(s.piece.source),r=s.piece.offset+c,i=r+e;if(n)for(;i>r&&Ad(t.text.charCodeAt(i-1));)i--;o.push(t.text.slice(r,i)),l-=e,c=0,s=this.#d(s)}return o.join(``)}charAt(e){let t=this.#u(e);if(t===void 0)return``;let[n,r]=t;return this.#v(n.piece.source).text.charAt(n.piece.offset+r)}includes(e){if(e.length===0)return!0;let t=Md(e),n=0,r=!1;return this.#_(i=>{for(let a=i.start;a<i.end;a++){let o=i.text.charCodeAt(a);for(;n>0&&o!==e.charCodeAt(n);)n=t[n-1];if(o===e.charCodeAt(n)&&n++,n===e.length)return r=!0,!1}return!0}),r}findNextNonOverlappingSubstring(e,t){if(e.length===0||e.length>this.#r)return;let n=Nd(t,this.#r),r=n.reduce((e,[,t])=>Math.max(e,t),0),i=Md(e),a=0,o=0,s,c;return this.#_(t=>{for(let l=t.start;l<t.end;l++){let u=t.text.charCodeAt(l);for(;a>0&&u!==e.charCodeAt(a);)a=i[a-1];if(u===e.charCodeAt(a)&&a++,a===e.length){let t=o-e.length+1;if(!Pd(n,t,t+e.length)){if(t>=r)return c=t,!1;s??=t}a=i[a-1]}o++}return!0}),c??s}search(e){if(e.text.length===0||this.#r===0||e.text.includes(`
1440
- `)||e.text.includes(`\r`)||e.regex&&(e.text.includes(`\\n`)||e.text.includes(`\\r`)))return[];let t;try{t=Hd(e.text,e.regex,e.caseSensitive)}catch{return[]}return this.#l(t,e.wholeWord,Sd)}#l(e,t,n){let r=[],i=this.#g(),a=i.length,o=yt(i);for(let s=0;s<o.length;s++){let c=o[s],l=o[s+1]??a;for(;l>c&&Ad(i.charCodeAt(l-1));)l--;let u=i.slice(c,l);e.lastIndex=0;let d;for(;(d=e.exec(u))!==null;){let a=d.index,o=d[0];if(o.length===0){e.lastIndex=Gd(u,a);continue}let s=c+a;if((!t||Vd(i,s,o.length))&&(r.push([s,s+o.length]),r.length>=n))return r;a===e.lastIndex&&(e.lastIndex=Gd(u,a))}}return r}insert(e,t){if(e.length===0)return;let n=jd(t,0,this.#r);this.#b(n,n,e),this.#x()}delete(e,t){if(t<=0||this.#r===0)return;let n=jd(e,0,this.#r),r=jd(n+t,n,this.#r);n!==r&&(this.#b(n,r,``),this.#x())}applyEdits(e){if(e.length!==0){for(let t=e.length-1;t>=0;t--){let n=e[t],r=jd(n.start,0,this.#r),i=jd(n.end,r,this.#r);this.#b(r,i,n.text)}this.#x()}}positionAt(e){let t=jd(e,0,this.#r);if(this.#r===0)return{line:0,character:0};let n=this.#p(t),r=t-(n===0?0:this.#m(n-1));return this.#s=[n,r,t],{line:n,character:r}}positionsAt(e){let t=Array.from({length:e.length});if(e.length===0)return t;if(this.#r===0)return t.fill({line:0,character:0});for(let n=0;n<e.length;n++)t[n]=this.positionAt(e[n]);return t}offsetAt(e){if(e.line<0||this.#r===0)return 0;if(e.line>=this.#i)throw Error(`Line index out of range: ${e.line}`);let t=this.#s;if(t!==null&&t[0]===e.line&&t[1]===e.character)return t[2];let n=this.#f(e.line);if(n===void 0)throw Error(`Line index out of range: ${e.line}`);let r=jd(e.character,0,n[1]-n[0]);return n[0]+r}#u(e){if(e<0||e>=this.#r)return;let t=this.#n,n=e;for(;t!==null;){let e=t.left?.subtreeLength??0;if(n<e){t=t.left;continue}if(n-=e,n<t.piece.length)return[t,n];n-=t.piece.length,t=t.right}}#d(e){if(e.right!==null){let t=e.right;for(;t.left!==null;)t=t.left;return t}let t=e;for(;t.parent!==null&&t===t.parent.right;)t=t.parent;return t.parent}#f(e){if(e<0)throw Error(`Line index out of range: ${e}`);if(this.#r===0){if(e===0)return[0,0];throw Error(`Line index out of range: ${e}`)}if(e>=this.#i)throw Error(`Line index out of range: ${e}`);return[e===0?0:this.#m(e-1),e<this.#i-1?this.#m(e):this.#r]}#p(e){let t=this.#n,n=jd(e,0,this.#r),r=0;for(;t!==null;){let e=t.left?.subtreeLength??0;if(n<e){t=t.left;continue}if(r+=(t.left?.subtreeLineBreakCount??0)-+!!Ld(t.left?.subtreeLastCharCode,t.piece.firstCharCode),n-=e,n<=t.piece.length){let e=this.#v(t.piece.source),i=Math.min(Rd(e.lineOffsets,t.piece.offset+n),t.piece.lineOffsetEnd);return r+=i-t.piece.lineOffsetStart,n===t.piece.length&&t.piece.hasVirtualTrailingCRBreak&&r++,n===t.piece.length&&Ld(t.piece.lastCharCode,this.#d(t)?.piece.firstCharCode)&&r--,r}r+=t.piece.lineBreakCount-+!!Ld(t.piece.lastCharCode,t.right?.subtreeFirstCharCode),n-=t.piece.length,t=t.right}return this.#i-1}#m(e){let t=this.#n,n=e,r=0,i;for(;t!==null;){let e=(t.left?.subtreeLineBreakCount??0)-+!!Ld(t.left?.subtreeLastCharCode,t.piece.firstCharCode);if(n<e){i=t.piece.firstCharCode,t=t.left;continue}let a=t.left?.subtreeLength??0;r+=a,n-=e;let o=t.right?.subtreeFirstCharCode??i,s=t.piece.lineBreakCount-+!!Ld(t.piece.lastCharCode,o);if(n<s)return r+this.#h(t.piece,n);r+=t.piece.length,n-=s,t=t.right}return this.#r}#h(e,t){return t<e.lineOffsetEnd-e.lineOffsetStart?this.#v(e.source).lineOffsets[e.lineOffsetStart+t]-e.offset:e.length}#g(){let e=[];return this.#_(t=>{e.push(t.text.slice(t.start,t.end))}),e.join(``)}#_(e){this.#j(this.#n,t=>{let n=this.#v(t.piece.source);return e({text:n.text,lineOffsets:n.lineOffsets,lineOffsetStart:t.piece.lineOffsetStart,lineOffsetEnd:t.piece.lineOffsetEnd,start:t.piece.offset,end:t.piece.offset+t.piece.length})})}#v(e){return e===Ed.Original?this.#e:this.#t}#y(e,t,n){let r=this.#v(e),i=t+n,a=Rd(r.lineOffsets,t),o=Rd(r.lineOffsets,i),s=r.text.charCodeAt(i-1);return new Ed(e,t,n,a,o,s===wd&&r.lineOffsets[o-1]!==i,r.text.charCodeAt(t),s)}#b(e,t,n){if(e===t&&n.length===0)return;let[r,i]=this.#E(this.#n,e),a=this.#D(i,t-e),o;if(n.length>0){let e=this.#y(Ed.Added,this.#t.append(n),n.length);o=this.#O(this.#k(r,e),a)}else{let[e,t]=this.#A(a);o=e===void 0?r:this.#O(this.#k(r,e),t)}o!==null&&(o.parent=null),this.#n=o,this.#r=o?.subtreeLength??0,this.#i=(o?.subtreeLineBreakCount??0)+1}#x(){this.#a=null,this.#o=null,this.#s=null}#S(){return this.#c=Math.imul(this.#c,1664525)+1013904223>>>0,this.#c}#C(e){let t=new Od(e);return t.priority=this.#S(),t}#w(e,t){e.left=t,t!==null&&(t.parent=e)}#T(e,t){e.right=t,t!==null&&(t.parent=e)}#E(e,t){if(e===null)return[null,null];if(t<=0)return[null,e];if(t>=e.subtreeLength)return[e,null];let n=e.left?.subtreeLength??0;if(t<=n){let[n,r]=this.#E(e.left,t);return this.#w(e,r),e.updateSubtreeLength(),[n,e]}let r=e.piece.length;if(t>=n+r){let[i,a]=this.#E(e.right,t-n-r);return this.#T(e,i),e.updateSubtreeLength(),[e,a]}let i=t-n,a=new Od(this.#y(e.piece.source,e.piece.offset,i)),o=new Od(this.#y(e.piece.source,e.piece.offset+i,r-i));return a.priority=e.priority,o.priority=e.priority,this.#w(a,e.left),this.#T(o,e.right),a.updateSubtreeLength(),o.updateSubtreeLength(),[a,o]}#D(e,t){if(e===null||t>=e.subtreeLength)return null;if(t<=0)return e;let n=e.left?.subtreeLength??0;if(t<=n)return this.#w(e,this.#D(e.left,t)),e.updateSubtreeLength(),e;let r=n+e.piece.length;if(t>=r)return this.#D(e.right,t-r);let i=t-n,a=new Od(this.#y(e.piece.source,e.piece.offset+i,e.piece.length-i));return a.priority=e.priority,this.#T(a,e.right),a.updateSubtreeLength(),a}#O(e,t){return e===null?t:t===null?e:e.priority>=t.priority?(this.#T(e,this.#O(e.right,t)),e.updateSubtreeLength(),e):(this.#w(t,this.#O(e,t.left)),t.updateSubtreeLength(),t)}#k(e,t){if(e===null)return this.#C(t);let n=e;for(;n.right!==null;)n=n.right;if(Fd(n.piece,t)){n.piece=Id(n.piece,t);for(let t=n;t!==null&&(t.updateSubtreeLength(),t!==e);)t=t.parent;return e}return this.#O(e,this.#C(t))}#A(e){if(e===null)return[void 0,null];if(e.left===null)return[e.piece,e.right];let[t,n]=this.#A(e.left);return this.#w(e,n),e.updateSubtreeLength(),[t,e]}#j(e,t){return e===null?!0:!this.#j(e.left,t)||t(e)===!1?!1:this.#j(e.right,t)}};function Ad(e){return e===10||e===13}function jd(e,t,n){return Math.min(Math.max(e,t),n)}function Md(e){let t=Array.from({length:e.length}).fill(0),n=0;for(let r=1;r<e.length;r++){let i=e.charCodeAt(r);for(;n>0&&i!==e.charCodeAt(n);)n=t[n-1];i===e.charCodeAt(n)&&n++,t[r]=n}return t}function Nd(e,t){let n=[];for(let[r,i]of e){let e=jd(r,0,t),a=jd(i,e,t);e<a&&n.push([e,a])}n.sort((e,t)=>e[0]-t[0]);let r=[];for(let e of n){let t=r[r.length-1];if(t!==void 0&&e[0]<=t[1]){t[1]=Math.max(t[1],e[1]);continue}r.push(e)}return r}function Pd(e,t,n){let r=0,i=e.length;for(;r<i;){let n=r+Math.floor((i-r)/2);e[n][1]<=t?r=n+1:i=n}let a=e[r];return a!==void 0&&a[0]<n}function Fd(e,t){return e.source===t.source&&e.offset+e.length===t.offset&&!Ld(e.lastCharCode,t.firstCharCode)}function Id(e,t){return new Ed(e.source,e.offset,e.length+t.length,e.lineOffsetStart,t.lineOffsetEnd,t.hasVirtualTrailingCRBreak,e.firstCharCode,t.lastCharCode)}function Ld(e,t){return e===wd&&t===Cd}function Rd(e,t){let n=0,r=e.length;for(;n<r;){let i=n+Math.floor((r-n)/2);e[i]<=t?n=i+1:r=i}return n}function zd(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Bd(e){if(e<=32||e===127)return!0;let t=String.fromCharCode(e);return Td.includes(t)}function Vd(e,t,n){let r=t<=0||Bd(e.charCodeAt(t-1)),i=t+n>=e.length||Bd(e.charCodeAt(t+n));return r&&i}function Hd(e,t,n){let r=t?e:zd(e);return new RegExp(r,`g${n?``:`i`}${t?`m`:``}`)}function Ud(e,t){return e.replace(/\$([$&]|\d+)/g,(e,n)=>n===`$`?`$`:n===`&`?t[0]??``:t[Number(n)]??``)}function Wd(e,t,n,r,i,a){if(!r.regex)return r.replaceText;let o=e(i),s=n(o.line),c=i-t({line:o.line,character:0}),l;try{l=Hd(r.text,!0,r.caseSensitive)}catch{return r.replaceText}l.lastIndex=c;let u=l.exec(s);return u===null||u.index!==c||u[0].length!==a-i?r.replaceText:Ud(r.replaceText,u)}function Gd(e,t){if(t+1<e.length){let n=e.charCodeAt(t),r=e.charCodeAt(t+1);if(n>=55296&&n<=56319&&r>=56320&&r<=57343)return t+2}return t+1}var Kd=class e{#e;#t;#n;#r;#i;#a;constructor(e,t,n=`text`,r=0,i=new gd){this.#e=new URL(e,`file://`).toString(),this.#t=n,this.#n=r,this.#r=new kd(t),this.#i=i;let a=this.#r.getLineText(0,!0);this.#a=a.endsWith(`\r
1439
+ `)&&s.text.length===0;if(l&&u){if(o.start!==a.end||(n??=pd,n!==pd||e.coalescingMode!==void 0&&e.coalescingMode!==pd||t.coalescingMode!==void 0&&t.coalescingMode!==pd))return!1;continue}let d=i.text.length===0&&i.end>i.start&&a.text.length>0,f=o.text.length===0&&o.end>o.start&&s.text.length>0;if(d&&f){let r;if(c===i.end)r=hd;else if(c+(o.end-o.start)!==i.start)return!1;else r=md;if(n??=r,n!==r||e.coalescingMode!==void 0&&e.coalescingMode!==r||t.coalescingMode!==void 0&&t.coalescingMode!==r)return!1;continue}return!1}return n!==void 0}function yd(e,t){let n=[],r=[],i;for(let a=0;a<e.forwardEdits.length;a++){let o=e.forwardEdits[a],s=e.inverseEdits[a],c=t.forwardEdits[a],l=t.inverseEdits[a],u=xd(c.start,e.forwardEdits);if(o.text.length>0){i??=pd,n.push({start:o.start,end:o.end,text:o.text+c.text}),r.push(s.text);continue}if(u===o.end){i??=hd,n.push({start:o.start,end:u+(c.end-c.start),text:``}),r.push(s.text+l.text);continue}i??=md,n.push({start:Math.min(o.start,u),end:o.end,text:``}),r.push(l.text+s.text)}return{forwardEdits:n,inverseEdits:bd(n,r),versionBefore:e.versionBefore,versionAfter:t.versionAfter,selectionsBefore:e.selectionsBefore?.slice(),selectionsAfter:t.selectionsAfter?.slice(),lineAnnotationsBefore:e.lineAnnotationsBefore?.slice(),lineAnnotationsAfter:t.lineAnnotationsAfter?.slice(),coalescingMode:i}}function bd(e,t){let n=[];for(let r=0,i=0;r<e.length;r++){let a=e[r],o=a.start+i;n.push({start:o,end:o+a.text.length,text:t[r]}),i+=a.text.length-(a.end-a.start)}return n}function xd(e,t){let n=e;for(let e of t){let t=e.end-e.start,r=e.text.length,i=r-t;if(!(n<e.start)){if(n>=e.start+r){n-=i;continue}n=e.start+Math.min(n-e.start,t)}}return n}var Sd=1e5,Cd=10,wd=13,Td=`\`~!@#$%^&*()-=+[{]}\\|;:'",.<>/?`,Ed=class{source;offset;length;lineOffsetStart;lineOffsetEnd;hasVirtualTrailingCRBreak;firstCharCode;lastCharCode;static Original=0;static Added=1;constructor(e,t,n,r,i,a,o,s){this.source=e,this.offset=t,this.length=n,this.lineOffsetStart=r,this.lineOffsetEnd=i,this.hasVirtualTrailingCRBreak=a,this.firstCharCode=o,this.lastCharCode=s}get lineBreakCount(){return this.lineOffsetEnd-this.lineOffsetStart+ +!!this.hasVirtualTrailingCRBreak}},Dd=class{text;lineOffsets;constructor(e){this.text=e,this.lineOffsets=vt(e)}append(e){let t=this.text.length;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r===Cd||r===wd)&&(r===wd&&e.charCodeAt(n+1)===Cd&&n++,this.lineOffsets.push(t+n+1))}return this.text+=e,t}},Od=class{piece;subtreeLength;subtreeLineBreakCount;subtreeFirstCharCode;subtreeLastCharCode;left=null;right=null;parent=null;priority=0;constructor(e,t=e.length,n=e.lineBreakCount,r=e.firstCharCode,i=e.lastCharCode){this.piece=e,this.subtreeLength=t,this.subtreeLineBreakCount=n,this.subtreeFirstCharCode=r,this.subtreeLastCharCode=i}updateSubtreeLength(){this.subtreeLength=(this.left?.subtreeLength??0)+this.piece.length+(this.right?.subtreeLength??0),this.subtreeLineBreakCount=(this.left?.subtreeLineBreakCount??0)+this.piece.lineBreakCount+(this.right?.subtreeLineBreakCount??0)-+!!Ld(this.left?.subtreeLastCharCode,this.piece.firstCharCode)-!!Ld(this.piece.lastCharCode,this.right?.subtreeFirstCharCode),this.subtreeFirstCharCode=this.left?.subtreeFirstCharCode??this.piece.firstCharCode,this.subtreeLastCharCode=this.right?.subtreeLastCharCode??this.piece.lastCharCode}},kd=class{#e;#t=new Dd(``);#n=null;#r=0;#i=0;#a=null;#o=null;#s=null;#c=2654435769;constructor(e){this.#e=new Dd(e);let t=this.#y(Ed.Original,0,e.length);this.#n=t.length>0?this.#C(t):null,this.#r=this.#n?.subtreeLength??0,this.#i=(this.#n?.subtreeLineBreakCount??0)+1}get lineCount(){return this.#i}getText(e){if(e===void 0)return this.#g();let t=this.offsetAt(e.start),n=this.offsetAt(e.end);return this.getTextSlice(t,n)}getLineText(e,t=!1){if(this.#a!==null&&this.#a[0]===e&&this.#a[1]===t)return this.#a[2];let n=this.#f(e);if(n===void 0)throw Error(`Line index out of range: ${e}`);let r=this.getTextSlice(n[0],n[1],!t);return this.#a=[e,t,r],this.#o=[e,t,r.length],r}getLineLength(e,t=!1){let n=this.#o,r=this.#a;if(n!==null&&n[0]===e&&n[1]===t)return n[2];if(r!==null&&r[0]===e&&r[1]===t){let n=r[2].length;return this.#o=[e,t,n],n}let i=this.#f(e);if(i===void 0)throw Error(`Line index out of range: ${e}`);let[a,o]=i,s=o-a;if(!t)for(;s>0&&Ad(this.charAt(a+s-1).charCodeAt(0));)s--;return this.#o=[e,t,s],s}getTextSlice(e,t,n=!1){if(e>=t)return``;let r=jd(e,0,this.#r),i=jd(t,r,this.#r);if(r>=i)return``;let a=this.#u(r);if(a===void 0)return``;let o=[],[s,c]=a,l=i-r;for(;s!==null&&l>0;){let e=Math.min(s.piece.length-c,l),t=this.#v(s.piece.source),r=s.piece.offset+c,i=r+e;if(n)for(;i>r&&Ad(t.text.charCodeAt(i-1));)i--;o.push(t.text.slice(r,i)),l-=e,c=0,s=this.#d(s)}return o.join(``)}charAt(e){let t=this.#u(e);if(t===void 0)return``;let[n,r]=t;return this.#v(n.piece.source).text.charAt(n.piece.offset+r)}includes(e){if(e.length===0)return!0;let t=Md(e),n=0,r=!1;return this.#_(i=>{for(let a=i.start;a<i.end;a++){let o=i.text.charCodeAt(a);for(;n>0&&o!==e.charCodeAt(n);)n=t[n-1];if(o===e.charCodeAt(n)&&n++,n===e.length)return r=!0,!1}return!0}),r}findNextNonOverlappingSubstring(e,t){if(e.length===0||e.length>this.#r)return;let n=Nd(t,this.#r),r=n.reduce((e,[,t])=>Math.max(e,t),0),i=Md(e),a=0,o=0,s,c;return this.#_(t=>{for(let l=t.start;l<t.end;l++){let u=t.text.charCodeAt(l);for(;a>0&&u!==e.charCodeAt(a);)a=i[a-1];if(u===e.charCodeAt(a)&&a++,a===e.length){let t=o-e.length+1;if(!Pd(n,t,t+e.length)){if(t>=r)return c=t,!1;s??=t}a=i[a-1]}o++}return!0}),c??s}search(e){if(e.text.length===0||this.#r===0||e.text.includes(`
1440
+ `)||e.text.includes(`\r`)||e.regex&&(e.text.includes(`\\n`)||e.text.includes(`\\r`)))return[];let t;try{t=Hd(e.text,e.regex,e.caseSensitive)}catch{return[]}return this.#l(t,e.wholeWord,Sd)}#l(e,t,n){let r=[],i=this.#g(),a=i.length,o=vt(i);for(let s=0;s<o.length;s++){let c=o[s],l=o[s+1]??a;for(;l>c&&Ad(i.charCodeAt(l-1));)l--;let u=i.slice(c,l);e.lastIndex=0;let d;for(;(d=e.exec(u))!==null;){let a=d.index,o=d[0];if(o.length===0){e.lastIndex=Gd(u,a);continue}let s=c+a;if((!t||Vd(i,s,o.length))&&(r.push([s,s+o.length]),r.length>=n))return r;a===e.lastIndex&&(e.lastIndex=Gd(u,a))}}return r}insert(e,t){if(e.length===0)return;let n=jd(t,0,this.#r);this.#b(n,n,e),this.#x()}delete(e,t){if(t<=0||this.#r===0)return;let n=jd(e,0,this.#r),r=jd(n+t,n,this.#r);n!==r&&(this.#b(n,r,``),this.#x())}applyEdits(e){if(e.length!==0){for(let t=e.length-1;t>=0;t--){let n=e[t],r=jd(n.start,0,this.#r),i=jd(n.end,r,this.#r);this.#b(r,i,n.text)}this.#x()}}positionAt(e){let t=jd(e,0,this.#r);if(this.#r===0)return{line:0,character:0};let n=this.#p(t),r=t-(n===0?0:this.#m(n-1));return this.#s=[n,r,t],{line:n,character:r}}positionsAt(e){let t=Array.from({length:e.length});if(e.length===0)return t;if(this.#r===0)return t.fill({line:0,character:0});for(let n=0;n<e.length;n++)t[n]=this.positionAt(e[n]);return t}offsetAt(e){if(e.line<0||this.#r===0)return 0;if(e.line>=this.#i)throw Error(`Line index out of range: ${e.line}`);let t=this.#s;if(t!==null&&t[0]===e.line&&t[1]===e.character)return t[2];let n=this.#f(e.line);if(n===void 0)throw Error(`Line index out of range: ${e.line}`);let r=jd(e.character,0,n[1]-n[0]);return n[0]+r}#u(e){if(e<0||e>=this.#r)return;let t=this.#n,n=e;for(;t!==null;){let e=t.left?.subtreeLength??0;if(n<e){t=t.left;continue}if(n-=e,n<t.piece.length)return[t,n];n-=t.piece.length,t=t.right}}#d(e){if(e.right!==null){let t=e.right;for(;t.left!==null;)t=t.left;return t}let t=e;for(;t.parent!==null&&t===t.parent.right;)t=t.parent;return t.parent}#f(e){if(e<0)throw Error(`Line index out of range: ${e}`);if(this.#r===0){if(e===0)return[0,0];throw Error(`Line index out of range: ${e}`)}if(e>=this.#i)throw Error(`Line index out of range: ${e}`);return[e===0?0:this.#m(e-1),e<this.#i-1?this.#m(e):this.#r]}#p(e){let t=this.#n,n=jd(e,0,this.#r),r=0;for(;t!==null;){let e=t.left?.subtreeLength??0;if(n<e){t=t.left;continue}if(r+=(t.left?.subtreeLineBreakCount??0)-+!!Ld(t.left?.subtreeLastCharCode,t.piece.firstCharCode),n-=e,n<=t.piece.length){let e=this.#v(t.piece.source),i=Math.min(Rd(e.lineOffsets,t.piece.offset+n),t.piece.lineOffsetEnd);return r+=i-t.piece.lineOffsetStart,n===t.piece.length&&t.piece.hasVirtualTrailingCRBreak&&r++,n===t.piece.length&&Ld(t.piece.lastCharCode,this.#d(t)?.piece.firstCharCode)&&r--,r}r+=t.piece.lineBreakCount-+!!Ld(t.piece.lastCharCode,t.right?.subtreeFirstCharCode),n-=t.piece.length,t=t.right}return this.#i-1}#m(e){let t=this.#n,n=e,r=0,i;for(;t!==null;){let e=(t.left?.subtreeLineBreakCount??0)-+!!Ld(t.left?.subtreeLastCharCode,t.piece.firstCharCode);if(n<e){i=t.piece.firstCharCode,t=t.left;continue}let a=t.left?.subtreeLength??0;r+=a,n-=e;let o=t.right?.subtreeFirstCharCode??i,s=t.piece.lineBreakCount-+!!Ld(t.piece.lastCharCode,o);if(n<s)return r+this.#h(t.piece,n);r+=t.piece.length,n-=s,t=t.right}return this.#r}#h(e,t){return t<e.lineOffsetEnd-e.lineOffsetStart?this.#v(e.source).lineOffsets[e.lineOffsetStart+t]-e.offset:e.length}#g(){let e=[];return this.#_(t=>{e.push(t.text.slice(t.start,t.end))}),e.join(``)}#_(e){this.#j(this.#n,t=>{let n=this.#v(t.piece.source);return e({text:n.text,lineOffsets:n.lineOffsets,lineOffsetStart:t.piece.lineOffsetStart,lineOffsetEnd:t.piece.lineOffsetEnd,start:t.piece.offset,end:t.piece.offset+t.piece.length})})}#v(e){return e===Ed.Original?this.#e:this.#t}#y(e,t,n){let r=this.#v(e),i=t+n,a=Rd(r.lineOffsets,t),o=Rd(r.lineOffsets,i),s=r.text.charCodeAt(i-1);return new Ed(e,t,n,a,o,s===wd&&r.lineOffsets[o-1]!==i,r.text.charCodeAt(t),s)}#b(e,t,n){if(e===t&&n.length===0)return;let[r,i]=this.#E(this.#n,e),a=this.#D(i,t-e),o;if(n.length>0){let e=this.#y(Ed.Added,this.#t.append(n),n.length);o=this.#O(this.#k(r,e),a)}else{let[e,t]=this.#A(a);o=e===void 0?r:this.#O(this.#k(r,e),t)}o!==null&&(o.parent=null),this.#n=o,this.#r=o?.subtreeLength??0,this.#i=(o?.subtreeLineBreakCount??0)+1}#x(){this.#a=null,this.#o=null,this.#s=null}#S(){return this.#c=Math.imul(this.#c,1664525)+1013904223>>>0,this.#c}#C(e){let t=new Od(e);return t.priority=this.#S(),t}#w(e,t){e.left=t,t!==null&&(t.parent=e)}#T(e,t){e.right=t,t!==null&&(t.parent=e)}#E(e,t){if(e===null)return[null,null];if(t<=0)return[null,e];if(t>=e.subtreeLength)return[e,null];let n=e.left?.subtreeLength??0;if(t<=n){let[n,r]=this.#E(e.left,t);return this.#w(e,r),e.updateSubtreeLength(),[n,e]}let r=e.piece.length;if(t>=n+r){let[i,a]=this.#E(e.right,t-n-r);return this.#T(e,i),e.updateSubtreeLength(),[e,a]}let i=t-n,a=new Od(this.#y(e.piece.source,e.piece.offset,i)),o=new Od(this.#y(e.piece.source,e.piece.offset+i,r-i));return a.priority=e.priority,o.priority=e.priority,this.#w(a,e.left),this.#T(o,e.right),a.updateSubtreeLength(),o.updateSubtreeLength(),[a,o]}#D(e,t){if(e===null||t>=e.subtreeLength)return null;if(t<=0)return e;let n=e.left?.subtreeLength??0;if(t<=n)return this.#w(e,this.#D(e.left,t)),e.updateSubtreeLength(),e;let r=n+e.piece.length;if(t>=r)return this.#D(e.right,t-r);let i=t-n,a=new Od(this.#y(e.piece.source,e.piece.offset+i,e.piece.length-i));return a.priority=e.priority,this.#T(a,e.right),a.updateSubtreeLength(),a}#O(e,t){return e===null?t:t===null?e:e.priority>=t.priority?(this.#T(e,this.#O(e.right,t)),e.updateSubtreeLength(),e):(this.#w(t,this.#O(e,t.left)),t.updateSubtreeLength(),t)}#k(e,t){if(e===null)return this.#C(t);let n=e;for(;n.right!==null;)n=n.right;if(Fd(n.piece,t)){n.piece=Id(n.piece,t);for(let t=n;t!==null&&(t.updateSubtreeLength(),t!==e);)t=t.parent;return e}return this.#O(e,this.#C(t))}#A(e){if(e===null)return[void 0,null];if(e.left===null)return[e.piece,e.right];let[t,n]=this.#A(e.left);return this.#w(e,n),e.updateSubtreeLength(),[t,e]}#j(e,t){return e===null?!0:!this.#j(e.left,t)||t(e)===!1?!1:this.#j(e.right,t)}};function Ad(e){return e===10||e===13}function jd(e,t,n){return Math.min(Math.max(e,t),n)}function Md(e){let t=Array.from({length:e.length}).fill(0),n=0;for(let r=1;r<e.length;r++){let i=e.charCodeAt(r);for(;n>0&&i!==e.charCodeAt(n);)n=t[n-1];i===e.charCodeAt(n)&&n++,t[r]=n}return t}function Nd(e,t){let n=[];for(let[r,i]of e){let e=jd(r,0,t),a=jd(i,e,t);e<a&&n.push([e,a])}n.sort((e,t)=>e[0]-t[0]);let r=[];for(let e of n){let t=r[r.length-1];if(t!==void 0&&e[0]<=t[1]){t[1]=Math.max(t[1],e[1]);continue}r.push(e)}return r}function Pd(e,t,n){let r=0,i=e.length;for(;r<i;){let n=r+Math.floor((i-r)/2);e[n][1]<=t?r=n+1:i=n}let a=e[r];return a!==void 0&&a[0]<n}function Fd(e,t){return e.source===t.source&&e.offset+e.length===t.offset&&!Ld(e.lastCharCode,t.firstCharCode)}function Id(e,t){return new Ed(e.source,e.offset,e.length+t.length,e.lineOffsetStart,t.lineOffsetEnd,t.hasVirtualTrailingCRBreak,e.firstCharCode,t.lastCharCode)}function Ld(e,t){return e===wd&&t===Cd}function Rd(e,t){let n=0,r=e.length;for(;n<r;){let i=n+Math.floor((r-n)/2);e[i]<=t?n=i+1:r=i}return n}function zd(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Bd(e){if(e<=32||e===127)return!0;let t=String.fromCharCode(e);return Td.includes(t)}function Vd(e,t,n){let r=t<=0||Bd(e.charCodeAt(t-1)),i=t+n>=e.length||Bd(e.charCodeAt(t+n));return r&&i}function Hd(e,t,n){let r=t?e:zd(e);return new RegExp(r,`g${n?``:`i`}${t?`m`:``}`)}function Ud(e,t){return e.replace(/\$([$&]|\d+)/g,(e,n)=>n===`$`?`$`:n===`&`?t[0]??``:t[Number(n)]??``)}function Wd(e,t,n,r,i,a){if(!r.regex)return r.replaceText;let o=e(i),s=n(o.line),c=i-t({line:o.line,character:0}),l;try{l=Hd(r.text,!0,r.caseSensitive)}catch{return r.replaceText}l.lastIndex=c;let u=l.exec(s);return u===null||u.index!==c||u[0].length!==a-i?r.replaceText:Ud(r.replaceText,u)}function Gd(e,t){if(t+1<e.length){let n=e.charCodeAt(t),r=e.charCodeAt(t+1);if(n>=55296&&n<=56319&&r>=56320&&r<=57343)return t+2}return t+1}var Kd=class e{#e;#t;#n;#r;#i;#a;constructor(e,t,n=`text`,r=0,i=new gd){this.#e=new URL(e,`file://`).toString(),this.#t=n,this.#n=r,this.#r=new kd(t),this.#i=i;let a=this.#r.getLineText(0,!0);this.#a=a.endsWith(`\r
1441
1441
  `)?`\r
1442
1442
  `:a.endsWith(`\r`)?`\r`:`
1443
- `}get uri(){return this.#e}get languageId(){return this.#t}get version(){return this.#n}get lineCount(){return this.#r.lineCount}get eol(){return this.#a}get canUndo(){return this.#i.canUndo}get canRedo(){return this.#i.canRedo}positionAt(e){return this.normalizePosition(this.#r.positionAt(e))}positionsAt(e){let t=this.#r.positionsAt(e);for(let e=0;e<t.length;e++)t[e]=this.normalizePosition(t[e]);return t}offsetAt(e){return this.#r.offsetAt(this.normalizePosition(e))}getText(e){return e===void 0?this.#r.getText():this.#r.getText({start:this.normalizePosition(e.start),end:this.normalizePosition(e.end)})}getLineText(e,t){return this.#r.getLineText(e,t)}normalizeEol(e){return e.replace(/\r\n|\r|\n/g,this.eol)}getLineLength(e,t){return this.#r.getLineLength(e,t)}charAt(e){return typeof e==`number`?this.#r.charAt(e):this.#r.charAt(this.offsetAt(e))}getTextSlice(e,t){return this.#r.getTextSlice(e,t)}findNextNonOverlappingSubstring(e,t){return this.#r.findNextNonOverlappingSubstring(e,t)}search(e){return this.#r.search(e)}applyEdits(e,t=!0,n,r,i=!1){if(e.length!==0)return this.#o(this.#d(this.resolveEdits(e)),t,n,r,i)}resolveEdits(e){return e.map(e=>this.#c(e))}applyResolvedEdits(e,t=!0,n,r,i=!1){if(e.length!==0)return this.#o(this.#d(e.map(e=>this.#l(e))),t,n,r,i)}#o(e,t,n,r,i){let a=_d(this,e,this.#n,this.#n+1,t?n:void 0,t?r:void 0);t&&i&&(a.undoBoundary=!0);let o=this.#i.peekUndoForCoalescing(),s=this.#f(e);return this.#n++,s.lineDelta===0&&vd(o,a)?this.#i.replaceLastUndo(yd(o,a)):this.#i.push(a),s}setLastUndoSelectionsAfter(e){this.#i.setLastUndoSelectionsAfter(e)}setLastUndoLineAnnotations(e,t){this.#i.setLastUndoLineAnnotations(e,t)}undo(){let e=this.#i.popUndoToRedo();if(e===void 0)return;let t=this.#f(e.inverseEdits);if(t===void 0)return;this.#n=e.versionBefore;let n=e.selectionsBefore?.slice();return[t,n,e.lineAnnotationsBefore?.slice(),n===void 0?e.inverseEdits.map(e=>({...e})):void 0]}redo(){let e=this.#i.popRedoToUndo();if(e===void 0)return;let t=this.#f(e.forwardEdits);if(t===void 0)return;this.#n=e.versionAfter;let n=e.selectionsAfter?.slice();return[t,n,e.lineAnnotationsAfter?.slice(),n===void 0?e.forwardEdits.map(e=>({...e})):void 0]}normalizePosition(t){let n=e.#s(t.line,this.lineCount-1);return{line:n,character:e.#s(t.character,this.getLineLength(n))}}static#s(e,t){return Number.isNaN(e)?0:Math.max(0,Math.min(Math.floor(e),t))}#c(e){let t=this.offsetAt(e.range.start),n=this.offsetAt(e.range.end);if(t>n){let e=t;t=n,n=e}return this.#l({start:t,end:n,text:e.newText})}#l(e){let{start:t,end:n}=e,r=t===n;return this.#u(t)&&t--,r?n=t:this.#u(n)&&n++,{start:t,end:n,text:e.text}}#u(e){let t=this.#r.charAt(e-1).charCodeAt(0),n=this.#r.charAt(e).charCodeAt(0);return t>=55296&&t<=56319&&n>=56320&&n<=57343}#d(e){let t=[...e].sort((e,t)=>{let n=e.start-t.start;return n===0?e.end-t.end:n});for(let e=0;e<t.length-1;e++)if(t[e].end>t[e+1].start)throw Error(`Overlapping text edits are not supported`);return t}#f(e){let t=this.#r.lineCount,n=this.positionsAt(e.flatMap(e=>[e.start,e.end])),r=this.#p(e,n),i=n[0],a=n[n.length-1],o=a.line===t-1&&a.character===this.#r.getLineLength(a.line);this.#r.applyEdits(e);let s=this.#r.lineCount;return{changes:e.map((e,t)=>({...e,range:{start:n[t*2],end:n[t*2+1]}})),startLine:r.startLine,startCharacter:i.character,endCharacter:a.character,endLine:Math.min(r.endLine,Math.max(0,s-1)),endedAtDocumentEnd:o,previousLineCount:t,lineCount:s,lineDelta:s-t,changedLineRanges:r.ranges,changedLineChanges:r.changes}}#p(e,t){let n=1/0,r=0,i=0,a=[],o=[],s=this.#r.lineCount-1,c=this.#r.getLineLength(s);for(let l=0;l<e.length;l++){let u=e[l],d=t[l*2],f=t[l*2+1],p=d.line,m=f.line,h=_t(u.text),g=p+i,_=g+h,v=h-(m-p);n=Math.min(n,p),r=Math.max(r,_);let y=a[a.length-1];y!==void 0&&g<=y[1]+1?a[a.length-1]=[y[0],Math.max(y[1],_)]:a.push([g,_]),o.push([g,_,v,d.character,f.character,m===s&&f.character===c]),i+=v}return n===1/0?{startLine:0,endLine:0,ranges:[[0,0]],changes:[[0,0,0,0,0,!1]]}:{startLine:n,endLine:r,ranges:a,changes:o}}};function qd({metaKey:e,ctrlKey:t},n=Uo()){return n?e&&!t:t&&!e}function Jd(e){if(Uo()&&e.ctrlKey&&!e.altKey&&!e.metaKey)switch(e.key){case`a`:return`start`;case`e`:return`end`;case`p`:return`up`;case`n`:return`down`;case`f`:return`right`;case`b`:return`left`}if(!e.altKey&&!e.ctrlKey&&!e.metaKey){if(e.key===`ArrowUp`)return`up`;if(e.key===`ArrowDown`)return`down`;if(e.key===`ArrowLeft`)return`left`;if(e.key===`ArrowRight`)return`right`;if(e.key===`Home`)return`start`;if(e.key===`End`)return`end`}if(qd(e)){if(e.key===`ArrowLeft`)return`textStart`;if(e.key===`ArrowRight`)return`end`}}var Yd=new WeakMap,Xd=Qd([{bindings:{Tab:`indent`,"shift+Tab":`outdent`,"cmdOrCtrl+[":`indentLess`,"cmdOrCtrl+]":`indentMore`,"cmdOrCtrl+z":`undo`,"cmdOrCtrl+shift+z":`redo`,"cmdOrCtrl+a":`selectAll`,"cmdOrCtrl+d":`findNextMatch`,"cmdOrCtrl+f":`openSearchPanel`,"cmdOrCtrl+alt+f":`openSearchReplacePanel`,"alt+ArrowUp":`moveLineUp`,"alt+ArrowDown":`moveLineDown`,"shift+alt+ArrowUp":`copyLineUp`,"shift+alt+ArrowDown":`copyLineDown`,Escape:`simplifySelection`,"cmdOrCtrl+Enter":`insertBlankLine`,"cmdOrCtrl+/":`toggleComment`,"shift+alt+a":`toggleBlockComment`,"cmdOrCtrl+Home":`moveCursorToDocStart`,"cmdOrCtrl+End":`moveCursorToDocEnd`,"cmdOrCtrl+shift+Home":`expandSelectionDocStart`,"cmdOrCtrl+shift+End":`expandSelectionDocEnd`}},{platform:`mac`,bindings:{"ctrl+k":`deleteHardLineForward`,"ctrl+alt+p":`moveLineUp`,"ctrl+alt+n":`moveLineDown`,"cmd+ArrowUp":`moveCursorToDocStart`,"cmd+ArrowDown":`moveCursorToDocEnd`,"cmd+shift+ArrowUp":`expandSelectionDocStart`,"cmd+shift+ArrowDown":`expandSelectionDocEnd`}},{platform:`windows`,bindings:{"ctrl+y":`redo`}},{platform:`linux`,bindings:{"ctrl+y":`redo`,"ctrl+alt+p":`moveLineUp`,"ctrl+alt+n":`moveLineDown`}}]),Zd={Backquote:"`",Minus:`-`,Equal:`=`,Comma:`,`,Period:`.`,Slash:`/`,Semicolon:`;`,Quote:`'`,BracketLeft:`[`,BracketRight:`]`,Backslash:`\\`,Space:`Space`};function Qd(e){let t=Yd.get(e);if(t===void 0){t={mac:new Map,windows:new Map,linux:new Map};for(let n of e)for(let e of Object.keys(n.bindings)){let r=n.bindings[e];if(r===void 0)continue;let i=e.split(`+`),a=i.pop();for(let e of[`mac`,`windows`,`linux`]){if(n.platform!==void 0&&n.platform!==e)continue;let o=0;for(let t of i)t===`alt`?o|=1:t===`ctrl`?o|=2:t===`cmd`?o|=4:t===`shift`?o|=8:t===`cmdOrCtrl`&&(o|=e===`mac`?4:2);let s=t[e].get(o);s===void 0&&(s=new Map,t[e].set(o,s)),s.set(a,r)}}Yd.set(e,t)}return t}function $d(e,t,n=Uo()){let r=e.key===` `?`Space`:e.key.length===1?e.key.toLowerCase():e.key,i=e.code??``,a=i.startsWith(`Key`)&&i.length===4?i.slice(3).toLowerCase():i.startsWith(`Digit`)&&i.length===6?i.slice(5):Zd[i],o=n?`mac`:globalThis.navigator?.platform.includes(`Linux`)===!0?`linux`:`windows`,s=!!e.altKey|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0);if(t!==void 0){let e=Qd(t)[o].get(s),n=e?.get(r)??(a===void 0?void 0:e?.get(a));if(n!==void 0)return n}let c=Xd[o].get(s);return c?.get(r)??(a===void 0?void 0:c?.get(a))}function ef(e,t=Uo()){if(!e.altKey&&qd(e,t)&&((e.key.length===1?e.key.toLowerCase():e.key)===`g`||e.code===`KeyG`))return e.shiftKey?`previous`:`next`}var tf=`::selection {
1443
+ `}get uri(){return this.#e}get languageId(){return this.#t}get version(){return this.#n}get lineCount(){return this.#r.lineCount}get eol(){return this.#a}get canUndo(){return this.#i.canUndo}get canRedo(){return this.#i.canRedo}positionAt(e){return this.normalizePosition(this.#r.positionAt(e))}positionsAt(e){let t=this.#r.positionsAt(e);for(let e=0;e<t.length;e++)t[e]=this.normalizePosition(t[e]);return t}offsetAt(e){return this.#r.offsetAt(this.normalizePosition(e))}getText(e){return e===void 0?this.#r.getText():this.#r.getText({start:this.normalizePosition(e.start),end:this.normalizePosition(e.end)})}getLineText(e,t){return this.#r.getLineText(e,t)}normalizeEol(e){return e.replace(/\r\n|\r|\n/g,this.eol)}getLineLength(e,t){return this.#r.getLineLength(e,t)}charAt(e){return typeof e==`number`?this.#r.charAt(e):this.#r.charAt(this.offsetAt(e))}getTextSlice(e,t){return this.#r.getTextSlice(e,t)}findNextNonOverlappingSubstring(e,t){return this.#r.findNextNonOverlappingSubstring(e,t)}search(e){return this.#r.search(e)}applyEdits(e,t=!0,n,r,i=!1){if(e.length!==0)return this.#o(this.#d(this.resolveEdits(e)),t,n,r,i)}resolveEdits(e){return e.map(e=>this.#c(e))}applyResolvedEdits(e,t=!0,n,r,i=!1){if(e.length!==0)return this.#o(this.#d(e.map(e=>this.#l(e))),t,n,r,i)}#o(e,t,n,r,i){let a=_d(this,e,this.#n,this.#n+1,t?n:void 0,t?r:void 0);t&&i&&(a.undoBoundary=!0);let o=this.#i.peekUndoForCoalescing(),s=this.#f(e);return this.#n++,s.lineDelta===0&&vd(o,a)?this.#i.replaceLastUndo(yd(o,a)):this.#i.push(a),s}setLastUndoSelectionsAfter(e){this.#i.setLastUndoSelectionsAfter(e)}setLastUndoLineAnnotations(e,t){this.#i.setLastUndoLineAnnotations(e,t)}undo(){let e=this.#i.popUndoToRedo();if(e===void 0)return;let t=this.#f(e.inverseEdits);if(t===void 0)return;this.#n=e.versionBefore;let n=e.selectionsBefore?.slice();return[t,n,e.lineAnnotationsBefore?.slice(),n===void 0?e.inverseEdits.map(e=>({...e})):void 0]}redo(){let e=this.#i.popRedoToUndo();if(e===void 0)return;let t=this.#f(e.forwardEdits);if(t===void 0)return;this.#n=e.versionAfter;let n=e.selectionsAfter?.slice();return[t,n,e.lineAnnotationsAfter?.slice(),n===void 0?e.forwardEdits.map(e=>({...e})):void 0]}normalizePosition(t){let n=e.#s(t.line,this.lineCount-1);return{line:n,character:e.#s(t.character,this.getLineLength(n))}}static#s(e,t){return Number.isNaN(e)?0:Math.max(0,Math.min(Math.floor(e),t))}#c(e){let t=this.offsetAt(e.range.start),n=this.offsetAt(e.range.end);if(t>n){let e=t;t=n,n=e}return this.#l({start:t,end:n,text:e.newText})}#l(e){let{start:t,end:n}=e,r=t===n;return this.#u(t)&&t--,r?n=t:this.#u(n)&&n++,{start:t,end:n,text:e.text}}#u(e){let t=this.#r.charAt(e-1).charCodeAt(0),n=this.#r.charAt(e).charCodeAt(0);return t>=55296&&t<=56319&&n>=56320&&n<=57343}#d(e){let t=[...e].sort((e,t)=>{let n=e.start-t.start;return n===0?e.end-t.end:n});for(let e=0;e<t.length-1;e++)if(t[e].end>t[e+1].start)throw Error(`Overlapping text edits are not supported`);return t}#f(e){let t=this.#r.lineCount,n=this.positionsAt(e.flatMap(e=>[e.start,e.end])),r=this.#p(e,n),i=n[0],a=n[n.length-1],o=a.line===t-1&&a.character===this.#r.getLineLength(a.line);this.#r.applyEdits(e);let s=this.#r.lineCount;return{changes:e.map((e,t)=>({...e,range:{start:n[t*2],end:n[t*2+1]}})),startLine:r.startLine,startCharacter:i.character,endCharacter:a.character,endLine:Math.min(r.endLine,Math.max(0,s-1)),endedAtDocumentEnd:o,previousLineCount:t,lineCount:s,lineDelta:s-t,changedLineRanges:r.ranges,changedLineChanges:r.changes}}#p(e,t){let n=1/0,r=0,i=0,a=[],o=[],s=this.#r.lineCount-1,c=this.#r.getLineLength(s);for(let l=0;l<e.length;l++){let u=e[l],d=t[l*2],f=t[l*2+1],p=d.line,m=f.line,h=gt(u.text),g=p+i,_=g+h,v=h-(m-p);n=Math.min(n,p),r=Math.max(r,_);let y=a[a.length-1];y!==void 0&&g<=y[1]+1?a[a.length-1]=[y[0],Math.max(y[1],_)]:a.push([g,_]),o.push([g,_,v,d.character,f.character,m===s&&f.character===c]),i+=v}return n===1/0?{startLine:0,endLine:0,ranges:[[0,0]],changes:[[0,0,0,0,0,!1]]}:{startLine:n,endLine:r,ranges:a,changes:o}}};function qd({metaKey:e,ctrlKey:t},n=Uo()){return n?e&&!t:t&&!e}function Jd(e){if(Uo()&&e.ctrlKey&&!e.altKey&&!e.metaKey)switch(e.key){case`a`:return`start`;case`e`:return`end`;case`p`:return`up`;case`n`:return`down`;case`f`:return`right`;case`b`:return`left`}if(!e.altKey&&!e.ctrlKey&&!e.metaKey){if(e.key===`ArrowUp`)return`up`;if(e.key===`ArrowDown`)return`down`;if(e.key===`ArrowLeft`)return`left`;if(e.key===`ArrowRight`)return`right`;if(e.key===`Home`)return`start`;if(e.key===`End`)return`end`}if(qd(e)){if(e.key===`ArrowLeft`)return`textStart`;if(e.key===`ArrowRight`)return`end`}}var Yd=new WeakMap,Xd=Qd([{bindings:{Tab:`indent`,"shift+Tab":`outdent`,"cmdOrCtrl+[":`indentLess`,"cmdOrCtrl+]":`indentMore`,"cmdOrCtrl+z":`undo`,"cmdOrCtrl+shift+z":`redo`,"cmdOrCtrl+a":`selectAll`,"cmdOrCtrl+d":`findNextMatch`,"cmdOrCtrl+f":`openSearchPanel`,"cmdOrCtrl+alt+f":`openSearchReplacePanel`,"alt+ArrowUp":`moveLineUp`,"alt+ArrowDown":`moveLineDown`,"shift+alt+ArrowUp":`copyLineUp`,"shift+alt+ArrowDown":`copyLineDown`,Escape:`simplifySelection`,"cmdOrCtrl+Enter":`insertBlankLine`,"cmdOrCtrl+/":`toggleComment`,"shift+alt+a":`toggleBlockComment`,"cmdOrCtrl+Home":`moveCursorToDocStart`,"cmdOrCtrl+End":`moveCursorToDocEnd`,"cmdOrCtrl+shift+Home":`expandSelectionDocStart`,"cmdOrCtrl+shift+End":`expandSelectionDocEnd`}},{platform:`mac`,bindings:{"ctrl+k":`deleteHardLineForward`,"ctrl+alt+p":`moveLineUp`,"ctrl+alt+n":`moveLineDown`,"cmd+ArrowUp":`moveCursorToDocStart`,"cmd+ArrowDown":`moveCursorToDocEnd`,"cmd+shift+ArrowUp":`expandSelectionDocStart`,"cmd+shift+ArrowDown":`expandSelectionDocEnd`}},{platform:`windows`,bindings:{"ctrl+y":`redo`}},{platform:`linux`,bindings:{"ctrl+y":`redo`,"ctrl+alt+p":`moveLineUp`,"ctrl+alt+n":`moveLineDown`}}]),Zd={Backquote:"`",Minus:`-`,Equal:`=`,Comma:`,`,Period:`.`,Slash:`/`,Semicolon:`;`,Quote:`'`,BracketLeft:`[`,BracketRight:`]`,Backslash:`\\`,Space:`Space`};function Qd(e){let t=Yd.get(e);if(t===void 0){t={mac:new Map,windows:new Map,linux:new Map};for(let n of e)for(let e of Object.keys(n.bindings)){let r=n.bindings[e];if(r===void 0)continue;let i=e.split(`+`),a=i.pop();for(let e of[`mac`,`windows`,`linux`]){if(n.platform!==void 0&&n.platform!==e)continue;let o=0;for(let t of i)t===`alt`?o|=1:t===`ctrl`?o|=2:t===`cmd`?o|=4:t===`shift`?o|=8:t===`cmdOrCtrl`&&(o|=e===`mac`?4:2);let s=t[e].get(o);s===void 0&&(s=new Map,t[e].set(o,s)),s.set(a,r)}}Yd.set(e,t)}return t}function $d(e,t,n=Uo()){let r=e.key===` `?`Space`:e.key.length===1?e.key.toLowerCase():e.key,i=e.code??``,a=i.startsWith(`Key`)&&i.length===4?i.slice(3).toLowerCase():i.startsWith(`Digit`)&&i.length===6?i.slice(5):Zd[i],o=n?`mac`:globalThis.navigator?.platform.includes(`Linux`)===!0?`linux`:`windows`,s=!!e.altKey|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0);if(t!==void 0){let e=Qd(t)[o].get(s),n=e?.get(r)??(a===void 0?void 0:e?.get(a));if(n!==void 0)return n}let c=Xd[o].get(s);return c?.get(r)??(a===void 0?void 0:c?.get(a))}function ef(e,t=Uo()){if(!e.altKey&&qd(e,t)&&((e.key.length===1?e.key.toLowerCase():e.key)===`g`||e.code===`KeyG`))return e.shiftKey?`previous`:`next`}var tf=`::selection {
1444
1444
  background-color: #0000;
1445
1445
  }
1446
1446
 
@@ -1929,7 +1929,7 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
1929
1929
  </symbol>
1930
1930
  </svg>`,Em=()=>{let e=document.createElement(`div`);e.innerHTML=Tm;let t=e.firstElementChild;if(t===null||!(t instanceof SVGSVGElement))throw Error(`Failed to create sprite element`);return t},Dm=(e,t=16)=>`<svg width="${t}" height="${t}" aria-hidden="true" focusable="false">
1931
1931
  <use href="#diffs-editor-icon-${e}"></use>
1932
- </svg>`,Om=class{#e;#t;#n;#r;#i;#a;constructor(e){let{textDocument:t,containerElement:n,defaultQuery:r,mode:i=`find`,initialMatch:a,scrollToMatch:o,applyReplace:s,onUpdate:c,onClose:l}=e,u={text:r,replaceText:``,caseSensitive:!1,wholeWord:!1,regex:!1},d={all:[],current:void 0},f=Z(`div`,{dataset:{matches:``,noMatches:``},textContent:`No results`}),p=e=>{d.all=u.text===``?[]:t.search(u);let n=d.all.length===0;if(j.disabled=n,ee.disabled=n,n){f.textContent=`No results`,f.dataset.noMatches=``,d.current=void 0,c([]);return}if(delete f.dataset.noMatches,e?.syncSelection===!1){m(c(d.all,{syncSelection:!1}));return}m(c(d.all))};this.#n=p;let m=e=>{if(e===void 0)f.textContent=`${d.all.length} results`;else{let[t,n]=e;f.textContent=`${d.all.findIndex(e=>e[0]===t&&e[1]===n)+1} of ${d.all.length}`}d.current=e},h=(e,t)=>{u[e]=t,p()},g=(e=!1,t=!1)=>{let n=d.all,r=n[0];if(n.length>0){if(e){let e=d.current?.[0]??0;r=n.at(-1);for(let t of n)if(t[1]<=e)r=t;else break}else{let e=d.current?.[1]??0;for(let t of n)if(t[0]>=e){r=t;break}}}r!==void 0&&(m(r),o(r,t)),d.current=r};this.#i=e=>g(e,!0);let _=(e,n)=>({start:e,end:n,text:Wd(e=>t.positionAt(e),e=>t.offsetAt(e),e=>t.getLineText(e),u,e,n)}),v=()=>{if(u.text===``||d.all.length===0)return;let e=d.current;if(e===void 0&&(g(!1,!0),e=d.current,e===void 0))return;let[t,n]=e,r=_(t,n);s([r]),o([t+r.text.length,t+r.text.length],!0),d.current=void 0,p()},y=()=>{u.text!==``&&d.all.length!==0&&(s(d.all.map(([e,t])=>_(e,t))),d.current=void 0,p())},b=()=>{this.cleanup(),l()};this.#a=b;let x=e=>Z(`button`,{type:`button`,title:e.label,ariaLabel:e.label,dataset:{searchIcon:``,...e.dataset},innerHTML:Dm(e.icon,e.size??16),onclick:e.onClick}),S=(e,t,n)=>{let r=x({icon:e,label:t,size:14,onClick:()=>{let e=!u[n];r.ariaPressed=String(e),h(n,e)}});return r.ariaPressed=String(u[n]),r},C=S(`case`,`Match Case`,`caseSensitive`),w=S(`whole-word`,`Whole Word`,`wholeWord`),T=S(`regex`,`Regexp`,`regex`),E=Z(`input`,{type:`text`,placeholder:`Replace`,dataset:`replace`,value:``,oninput:e=>{u.replaceText=e.target.value},onkeydown:e=>{if(e.isComposing)return;let t=ef(e);e.key===`Escape`?(e.preventDefault(),b()):e.key===`Enter`?(e.preventDefault(),v()):t!==void 0&&(e.preventDefault(),g(t===`previous`,!0))}});this.#t=Z(`input`,{type:`text`,placeholder:`Search`,dataset:`search`,value:r,oninput:e=>{u.text=e.target.value,d.current=void 0,p()},onkeydown:e=>{let t=ef(e);e.key===`Escape`?(e.preventDefault(),b()):e.key===`Enter`?(e.preventDefault(),g(e.shiftKey,!0)):t===void 0?qd(e)&&(e.key===`f`||e.code===`KeyF`)&&(e.preventDefault(),P(e.altKey?`replace`:`find`)):(e.preventDefault(),g(t===`previous`,!0))}});let D=Z(`div`,{dataset:`searchToggles`,children:[C,w,T]}),O=Z(`div`,{dataset:{inputBox:``,find:``},children:[this.#t,D]}),k=Z(`div`,{dataset:{inputBox:``,replace:``,replaceCell:``},children:[E]}),A=Z(`div`,{dataset:{replaceActions:``,replaceCell:``},children:[x({icon:`replace`,label:`Replace`,onClick:v}),x({icon:`replace-all`,label:`Replace All`,onClick:y})]}),j=x({icon:`arrow-up`,label:`Previous`,onClick:()=>{g(!0)}}),ee=x({icon:`arrow-down`,label:`Next`,onClick:()=>{g()}});j.disabled=!0,ee.disabled=!0;let M=Z(`div`,{dataset:`searchNav`,children:[j,ee]}),te=x({icon:`close`,label:`Close`,onClick:b,dataset:{searchClose:``}}),N=Z(`div`,{dataset:{searchGrid:``,mode:i},children:[O,k,A,f,M,te]}),P=e=>{N.dataset.mode=e,this.#t.focus(),this.#t.select()};this.#r=P,this.#e=Z(`div`,{dataset:`searchPanel`,children:[Z(`div`,{dataset:`editorWidget`,children:[N]})]}),d.current=a,n.before(this.#e),requestAnimationFrame(()=>{a===void 0?c([]):p(),this.#t.select()})}focus(){this.#t.focus()}navigate(e){this.#i?.(e)}updateMatches(e){this.#n?.(e)}setMode(e){this.#r?.(e)}close(){this.#a?.()}cleanup(){this.#e.remove()}},km=class{#e;#t;#n;constructor(e,t,n){this.#e=Z(`div`,{dataset:{editorWidget:``,selectionActionPopover:``},contentEditable:`false`,children:[e]},t),this.#t=this.#e.offsetHeight,this.#n=new ResizeObserver(()=>{let e=this.#e.offsetHeight;e!==this.#t&&(this.#t=e,n())}),this.#n.observe(this.#e)}reposition(e,t,n,r,i,a){this.#e.style.visibility=i?``:`hidden`,If(this.#e,{gutterWidth:n,placeAbove:r,viewport:a,x:e,y:t})}get height(){return this.#t}cleanup(){this.#n.disconnect(),this.#e.remove()}};function Am(e){return{selections:e.selections?.map(e=>({start:{...e.start},end:{...e.end},direction:e.direction})),view:e.view===void 0?void 0:{...e.view}}}function jm(e){return typeof e==`object`?e:e===`indexedDB`?new Im:new Mm}var Mm=class{#e=new Map;get(e){let t=this.#e.get(e);return t===void 0?void 0:Am(t)}set(e,t){this.#e.set(e,Am(t))}},Nm=`pierre-diffs-editor-state`,Pm=1,Fm=`states`,Im=class{#e=Lm();async get(e){let t=await this.#e;if(t===void 0)return;let n=await Rm(t.transaction(Fm,`readonly`).objectStore(Fm).get(e));return n===void 0?void 0:Am(n)}async set(e,t){let n=await this.#e;n!==void 0&&await Rm(n.transaction(Fm,`readwrite`).objectStore(Fm).put(Am(t),e))}};function Lm(){try{let e=globalThis.indexedDB;if(e===void 0)return Promise.resolve(void 0);let t=e.open(Nm,Pm);return t.onupgradeneeded=()=>{let e=t.result;e.objectStoreNames.contains(Fm)||e.createObjectStore(Fm)},Rm(t)}catch{return Promise.resolve(void 0)}}function Rm(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}var zm=4096,Bm=/\p{Mark}/u,Vm=class{#e;#t;#n;#r=new Map;ch=-1;tabSize=2;lineHeight=20;paddingTop=0;init(e){if(this.#e===e&&this.#t!==void 0&&this.ch!==-1)return;if(this.#e=e,this.#t??=document.createElement(`canvas`).getContext(`2d`)??void 0,this.#t===void 0)throw Error(`Could not get canvas context`);let t=e.parentElement;if(t!==null){let{paddingTop:e}=getComputedStyle(t);e.endsWith(`px`)&&(this.paddingTop=parseFloat(e.slice(0,-2)))}let{fontSize:n,fontFamily:r,tabSize:i,lineHeight:a}=getComputedStyle(e);a.endsWith(`px`)?this.lineHeight=parseFloat(a.slice(0,-2)):n.endsWith(`px`)&&(this.lineHeight=gf(parseFloat(n.slice(0,-2))*parseFloat(a)));let o=n+` `+r;(this.#n!==o||this.ch===-1)&&(this.#n=o,this.#t.font=o,this.ch=this.canvasMeasureTextWidth(`0`),this.clearTextWidthCache());let s=parseInt(i,10);Number.isNaN(s)||(this.tabSize=s)}remeasureCharacterWidth(){if(this.#t===void 0||this.#n===void 0)return!1;this.#t.font=this.#n;let e=this.canvasMeasureTextWidth(`0`),t=e!==this.ch;t&&(this.ch=e);let n=this.#a();return t||n}measureTextWidth(e){if(!e.includes(` `))return this.#i(e);if(this.#t===void 0)throw Error(`Metrics not initialized`);let t=Gm(e,this.tabSize);if(t!==-1)return t*this.ch;let n=0,r=0,i=this.tabSize*this.ch;for(let t=0;t<e.length;t++)if(e.charCodeAt(t)===9){if(t>r&&(n+=this.#i(e.slice(r,t))),i>0){let e=n%i;n+=e===0?i:i-e}r=t+1}return r<e.length&&(n+=this.#i(e.slice(r))),gf(n)}#i(e){return Hm(e)?this.domMeasureTextWidth(e):this.canvasMeasureTextWidth(e)}canvasMeasureTextWidth(e){if(this.#t===void 0)throw Error(`Metrics not initialized`);return gf(this.#t.measureText(e).width)}domMeasureTextWidth(e){if(this.#e===void 0)throw Error(`Metrics not initialized`);let t=e+`|`+this.#n,n=this.#r.get(t);if(n!==void 0)return n;let r=Z(`span`,{style:{position:`absolute`,top:`0`,left:`0`,visibility:`hidden`,pointerEvents:`none`,whiteSpace:`pre`,font:`inherit`},textContent:e},this.#e),i;try{i=gf(r.getBoundingClientRect().width)}finally{r.remove()}if(this.#r.size>=zm){let e=this.#r.keys().next().value;e!==void 0&&this.#r.delete(e)}return this.#r.set(t,i),i}clearTextWidthCache(){this.#a()}#a(){let e=this.#r.size>0;return this.#r.clear(),e}};function Hm(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=57343||n===8205||n===65038||n===65039||n>127&&Bm.test(e.charAt(t)))return!0}return!1}function Um(e,t){let n=Math.max(0,Math.min(t,e.length));if(n===0||n===e.length||!Hm(e))return n;let r=xf();if(r!==void 0){for(let t of r.segment(e)){let e=t.index,r=e+t.segment.length;if(n>e&&n<r)return r;if(n<=e)break}return n}let i=0;for(let t of e){let e=i+t.length;if(n>i&&n<e)return e;if(n<=i)break;i=e}return n}function Wm(e){if(!Hm(e))return;let t=[0],n=xf();if(n!==void 0){for(let r of n.segment(e))t.push(r.index+r.segment.length);return t}let r=0;for(let n of e)r+=n.length,t.push(r);return t}function Gm(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i>127)return-1;n+=i===9?t-n%t:1}return n}var Km=500,qm=0,Jm=class{#e;#t;#n;#r=`dark`;#i=``;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=!1;#h=[It];#g=[];#_=0;#v=[];#y=-1;#b=!0;#x=!1;#S=0;#C=++qm;#w=-1;#T=-1;#E;#D=0;#O=[];#k=!1;#A=hf(async e=>{if(this.#m)return;let{startingLine:t=0,totalLines:n=1/0}=e??{},r=Math.min(n===1/0?1/0:t+n,this.#o.lineCount);if(this.#t===void 0&&!Zm(this.#o.languageId)){if(await this.#e.loadLanguage(this.#o.languageId),this.#m)return;this.#t=this.#e.getLanguage(this.#o.languageId)}this.#F(),this.#V(r)},500);#j=({data:e})=>{if(typeof e!=`object`||!e)return;let{type:t,tokenizerId:n,jobId:r}=e;t===`tokenize`&&n===this.#C&&typeof r==`number`&&r===this.#S&&(this.#w>=0?this.#q(r):this.#J(r))};get themeType(){return this.#r}getStringCommentRegexpRangesInLine(e){if(!this.#d||e<0||e>=this.#o.lineCount||(this.#I(),this.#t===void 0))return null;if(this.#O[e]===void 0){this.#K(e);let t=this.#h[e]??It,n=this.#H(e,t);this.#h[e+1]=n.state}return this.#O[e]??null}constructor({codeOptions:e,highlighter:t,textDocument:n,matchBrackets:r,setStyle:i,onDeferTokenize:a,onThemeChange:o,__debug:s}){let{themeType:c=`system`,theme:l=K,tokenizeMaxLineLength:u=1e3}=e;this.#n=window.matchMedia(`(prefers-color-scheme: dark)`);let d;if(d=c===`system`?this.#N():c,typeof l!=`string`&&c===`system`){let e=new MutationObserver(e=>{for(let{type:t,attributeName:n}of e)if(t===`attributes`&&n!==null&&(n===`class`||n.startsWith(`data-`))){let e=this.#N();this.#M(l[e],e);break}});e.observe(document.documentElement,{attributes:!0}),e.observe(document.body,{attributes:!0}),this.#p=[Q(this.#n,`change`,()=>{let e=this.#N();this.#M(l[e],e)}),()=>e.disconnect()]}this.#e=t,this.#o=n,this.#s=u,this.#c=i,this.#l=a,this.#u=o,this.#d=r!==!1,this.#f=s??!1,this.#I(),this.#a=[],this.#P(typeof l==`string`?l:l[d],typeof l==`string`?void 0:d)}#M(e,t){(e!==this.#i||t!==this.#r)&&(this.#P(e,t),this.stopBackgroundTokenize(),this.#h=[It],this.#g=[],this.#_=0,this.#v=[],this.#t!==void 0&&this.#o.lineCount>0&&this.#B(0),this.#u?.())}#N(){try{if(typeof document<`u`&&typeof getComputedStyle==`function`&&document.body!=null){let e=getComputedStyle(document.body).colorScheme.split(/\s+/),t=e.includes(`dark`);if(t!==e.includes(`light`))return t?`dark`:`light`}}catch{}return this.#n.matches?`dark`:`light`}syncTheme(e){let{themeType:t=`system`,theme:n=K}=e;if(typeof n==`string`){let e=this.#e.getTheme(n).type;if(n===this.#i&&e===this.#r)return;this.#M(n,e);return}let r=t===`system`?this.#N():t,i=n[r];(r!==this.#r||i!==this.#i)&&this.#M(i,r)}#P(e,t){let{theme:n,colorMap:r}=this.#e.setTheme(e),{colors:i={}}=this.#e.getTheme(e),a=i[`editor.selectionBackground`],o=i[`editor.lineHighlightBackground`],s=o!=null&&o.trim()!==``&&!no.isFullyTransparent(o)?o:void 0,c=i[`editor.lineHighlightBorder`]??(s==null?`color-mix(in lab, var(--diffs-bg) 70%, var(--diffs-fg))`:`transparent`),l=s==null?`100%`:`85%`,u=i[`editorCursor.foreground`],d=i[`editor.findMatchBackground`],f=i[`editor.findMatchHighlightBackground`],p=i[`editorBracketMatch.background`],m=i[`editorBracketMatch.border`],h=i[`editorHint.foreground`],g=i[`editorInfo.foreground`],_=i[`editorWarning.foreground`],v=i[`editorError.foreground`];this.#c(`:host {
1932
+ </svg>`,Om=class{#e;#t;#n;#r;#i;#a;constructor(e){let{textDocument:t,containerElement:n,defaultQuery:r,mode:i=`find`,initialMatch:a,scrollToMatch:o,applyReplace:s,onUpdate:c,onClose:l}=e,u={text:r,replaceText:``,caseSensitive:!1,wholeWord:!1,regex:!1},d={all:[],current:void 0},f=Z(`div`,{dataset:{matches:``,noMatches:``},textContent:`No results`}),p=e=>{d.all=u.text===``?[]:t.search(u);let n=d.all.length===0;if(j.disabled=n,M.disabled=n,n){f.textContent=`No results`,f.dataset.noMatches=``,d.current=void 0,c([]);return}if(delete f.dataset.noMatches,e?.syncSelection===!1){m(c(d.all,{syncSelection:!1}));return}m(c(d.all))};this.#n=p;let m=e=>{if(e===void 0)f.textContent=`${d.all.length} results`;else{let[t,n]=e;f.textContent=`${d.all.findIndex(e=>e[0]===t&&e[1]===n)+1} of ${d.all.length}`}d.current=e},h=(e,t)=>{u[e]=t,p()},g=(e=!1,t=!1)=>{let n=d.all,r=n[0];if(n.length>0){if(e){let e=d.current?.[0]??0;r=n.at(-1);for(let t of n)if(t[1]<=e)r=t;else break}else{let e=d.current?.[1]??0;for(let t of n)if(t[0]>=e){r=t;break}}}r!==void 0&&(m(r),o(r,t)),d.current=r};this.#i=e=>g(e,!0);let _=(e,n)=>({start:e,end:n,text:Wd(e=>t.positionAt(e),e=>t.offsetAt(e),e=>t.getLineText(e),u,e,n)}),v=()=>{if(u.text===``||d.all.length===0)return;let e=d.current;if(e===void 0&&(g(!1,!0),e=d.current,e===void 0))return;let[t,n]=e,r=_(t,n);s([r]),o([t+r.text.length,t+r.text.length],!0),d.current=void 0,p()},y=()=>{u.text!==``&&d.all.length!==0&&(s(d.all.map(([e,t])=>_(e,t))),d.current=void 0,p())},b=()=>{this.cleanup(),l()};this.#a=b;let x=e=>Z(`button`,{type:`button`,title:e.label,ariaLabel:e.label,dataset:{searchIcon:``,...e.dataset},innerHTML:Dm(e.icon,e.size??16),onclick:e.onClick}),S=(e,t,n)=>{let r=x({icon:e,label:t,size:14,onClick:()=>{let e=!u[n];r.ariaPressed=String(e),h(n,e)}});return r.ariaPressed=String(u[n]),r},C=S(`case`,`Match Case`,`caseSensitive`),w=S(`whole-word`,`Whole Word`,`wholeWord`),T=S(`regex`,`Regexp`,`regex`),E=Z(`input`,{type:`text`,placeholder:`Replace`,dataset:`replace`,value:``,oninput:e=>{u.replaceText=e.target.value},onkeydown:e=>{if(e.isComposing)return;let t=ef(e);e.key===`Escape`?(e.preventDefault(),b()):e.key===`Enter`?(e.preventDefault(),v()):t!==void 0&&(e.preventDefault(),g(t===`previous`,!0))}});this.#t=Z(`input`,{type:`text`,placeholder:`Search`,dataset:`search`,value:r,oninput:e=>{u.text=e.target.value,d.current=void 0,p()},onkeydown:e=>{let t=ef(e);e.key===`Escape`?(e.preventDefault(),b()):e.key===`Enter`?(e.preventDefault(),g(e.shiftKey,!0)):t===void 0?qd(e)&&(e.key===`f`||e.code===`KeyF`)&&(e.preventDefault(),P(e.altKey?`replace`:`find`)):(e.preventDefault(),g(t===`previous`,!0))}});let D=Z(`div`,{dataset:`searchToggles`,children:[C,w,T]}),O=Z(`div`,{dataset:{inputBox:``,find:``},children:[this.#t,D]}),k=Z(`div`,{dataset:{inputBox:``,replace:``,replaceCell:``},children:[E]}),A=Z(`div`,{dataset:{replaceActions:``,replaceCell:``},children:[x({icon:`replace`,label:`Replace`,onClick:v}),x({icon:`replace-all`,label:`Replace All`,onClick:y})]}),j=x({icon:`arrow-up`,label:`Previous`,onClick:()=>{g(!0)}}),M=x({icon:`arrow-down`,label:`Next`,onClick:()=>{g()}});j.disabled=!0,M.disabled=!0;let ee=Z(`div`,{dataset:`searchNav`,children:[j,M]}),N=x({icon:`close`,label:`Close`,onClick:b,dataset:{searchClose:``}}),te=Z(`div`,{dataset:{searchGrid:``,mode:i},children:[O,k,A,f,ee,N]}),P=e=>{te.dataset.mode=e,this.#t.focus(),this.#t.select()};this.#r=P,this.#e=Z(`div`,{dataset:`searchPanel`,children:[Z(`div`,{dataset:`editorWidget`,children:[te]})]}),d.current=a,n.before(this.#e),requestAnimationFrame(()=>{a===void 0?c([]):p(),this.#t.select()})}focus(){this.#t.focus()}navigate(e){this.#i?.(e)}updateMatches(e){this.#n?.(e)}setMode(e){this.#r?.(e)}close(){this.#a?.()}cleanup(){this.#e.remove()}},km=class{#e;#t;#n;constructor(e,t,n){this.#e=Z(`div`,{dataset:{editorWidget:``,selectionActionPopover:``},contentEditable:`false`,children:[e]},t),this.#t=this.#e.offsetHeight,this.#n=new ResizeObserver(()=>{let e=this.#e.offsetHeight;e!==this.#t&&(this.#t=e,n())}),this.#n.observe(this.#e)}reposition(e,t,n,r,i,a){this.#e.style.visibility=i?``:`hidden`,If(this.#e,{gutterWidth:n,placeAbove:r,viewport:a,x:e,y:t})}get height(){return this.#t}cleanup(){this.#n.disconnect(),this.#e.remove()}};function Am(e){return{selections:e.selections?.map(e=>({start:{...e.start},end:{...e.end},direction:e.direction})),view:e.view===void 0?void 0:{...e.view}}}function jm(e){return typeof e==`object`?e:e===`indexedDB`?new Im:new Mm}var Mm=class{#e=new Map;get(e){let t=this.#e.get(e);return t===void 0?void 0:Am(t)}set(e,t){this.#e.set(e,Am(t))}},Nm=`pierre-diffs-editor-state`,Pm=1,Fm=`states`,Im=class{#e=Lm();async get(e){let t=await this.#e;if(t===void 0)return;let n=await Rm(t.transaction(Fm,`readonly`).objectStore(Fm).get(e));return n===void 0?void 0:Am(n)}async set(e,t){let n=await this.#e;n!==void 0&&await Rm(n.transaction(Fm,`readwrite`).objectStore(Fm).put(Am(t),e))}};function Lm(){try{let e=globalThis.indexedDB;if(e===void 0)return Promise.resolve(void 0);let t=e.open(Nm,Pm);return t.onupgradeneeded=()=>{let e=t.result;e.objectStoreNames.contains(Fm)||e.createObjectStore(Fm)},Rm(t)}catch{return Promise.resolve(void 0)}}function Rm(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}var zm=4096,Bm=/\p{Mark}/u,Vm=class{#e;#t;#n;#r=new Map;ch=-1;tabSize=2;lineHeight=20;paddingTop=0;init(e){if(this.#e===e&&this.#t!==void 0&&this.ch!==-1)return;if(this.#e=e,this.#t??=document.createElement(`canvas`).getContext(`2d`)??void 0,this.#t===void 0)throw Error(`Could not get canvas context`);let t=e.parentElement;if(t!==null){let{paddingTop:e}=getComputedStyle(t);e.endsWith(`px`)&&(this.paddingTop=parseFloat(e.slice(0,-2)))}let{fontSize:n,fontFamily:r,tabSize:i,lineHeight:a}=getComputedStyle(e);a.endsWith(`px`)?this.lineHeight=parseFloat(a.slice(0,-2)):n.endsWith(`px`)&&(this.lineHeight=gf(parseFloat(n.slice(0,-2))*parseFloat(a)));let o=n+` `+r;(this.#n!==o||this.ch===-1)&&(this.#n=o,this.#t.font=o,this.ch=this.canvasMeasureTextWidth(`0`),this.clearTextWidthCache());let s=parseInt(i,10);Number.isNaN(s)||(this.tabSize=s)}remeasureCharacterWidth(){if(this.#t===void 0||this.#n===void 0)return!1;this.#t.font=this.#n;let e=this.canvasMeasureTextWidth(`0`),t=e!==this.ch;t&&(this.ch=e);let n=this.#a();return t||n}measureTextWidth(e){if(!e.includes(` `))return this.#i(e);if(this.#t===void 0)throw Error(`Metrics not initialized`);let t=Gm(e,this.tabSize);if(t!==-1)return t*this.ch;let n=0,r=0,i=this.tabSize*this.ch;for(let t=0;t<e.length;t++)if(e.charCodeAt(t)===9){if(t>r&&(n+=this.#i(e.slice(r,t))),i>0){let e=n%i;n+=e===0?i:i-e}r=t+1}return r<e.length&&(n+=this.#i(e.slice(r))),gf(n)}#i(e){return Hm(e)?this.domMeasureTextWidth(e):this.canvasMeasureTextWidth(e)}canvasMeasureTextWidth(e){if(this.#t===void 0)throw Error(`Metrics not initialized`);return gf(this.#t.measureText(e).width)}domMeasureTextWidth(e){if(this.#e===void 0)throw Error(`Metrics not initialized`);let t=e+`|`+this.#n,n=this.#r.get(t);if(n!==void 0)return n;let r=Z(`span`,{style:{position:`absolute`,top:`0`,left:`0`,visibility:`hidden`,pointerEvents:`none`,whiteSpace:`pre`,font:`inherit`},textContent:e},this.#e),i;try{i=gf(r.getBoundingClientRect().width)}finally{r.remove()}if(this.#r.size>=zm){let e=this.#r.keys().next().value;e!==void 0&&this.#r.delete(e)}return this.#r.set(t,i),i}clearTextWidthCache(){this.#a()}#a(){let e=this.#r.size>0;return this.#r.clear(),e}};function Hm(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=57343||n===8205||n===65038||n===65039||n>127&&Bm.test(e.charAt(t)))return!0}return!1}function Um(e,t){let n=Math.max(0,Math.min(t,e.length));if(n===0||n===e.length||!Hm(e))return n;let r=xf();if(r!==void 0){for(let t of r.segment(e)){let e=t.index,r=e+t.segment.length;if(n>e&&n<r)return r;if(n<=e)break}return n}let i=0;for(let t of e){let e=i+t.length;if(n>i&&n<e)return e;if(n<=i)break;i=e}return n}function Wm(e){if(!Hm(e))return;let t=[0],n=xf();if(n!==void 0){for(let r of n.segment(e))t.push(r.index+r.segment.length);return t}let r=0;for(let n of e)r+=n.length,t.push(r);return t}function Gm(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i>127)return-1;n+=i===9?t-n%t:1}return n}var Km=500,qm=0,Jm=class{#e;#t;#n;#r=`dark`;#i=``;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=!1;#h=[Ft];#g=[];#_=0;#v=[];#y=-1;#b=!0;#x=!1;#S=0;#C=++qm;#w=-1;#T=-1;#E;#D=0;#O=[];#k=!1;#A=hf(async e=>{if(this.#m)return;let{startingLine:t=0,totalLines:n=1/0}=e??{},r=Math.min(n===1/0?1/0:t+n,this.#o.lineCount);if(this.#t===void 0&&!Zm(this.#o.languageId)){if(await this.#e.loadLanguage(this.#o.languageId),this.#m)return;this.#t=this.#e.getLanguage(this.#o.languageId)}this.#F(),this.#V(r)},500);#j=({data:e})=>{if(typeof e!=`object`||!e)return;let{type:t,tokenizerId:n,jobId:r}=e;t===`tokenize`&&n===this.#C&&typeof r==`number`&&r===this.#S&&(this.#w>=0?this.#q(r):this.#J(r))};get themeType(){return this.#r}getStringCommentRegexpRangesInLine(e){if(!this.#d||e<0||e>=this.#o.lineCount||(this.#I(),this.#t===void 0))return null;if(this.#O[e]===void 0){this.#K(e);let t=this.#h[e]??Ft,n=this.#H(e,t);this.#h[e+1]=n.state}return this.#O[e]??null}constructor({codeOptions:e,highlighter:t,textDocument:n,matchBrackets:r,setStyle:i,onDeferTokenize:a,onThemeChange:o,__debug:s}){let{themeType:c=`system`,theme:l=W,tokenizeMaxLineLength:u=1e3}=e;this.#n=window.matchMedia(`(prefers-color-scheme: dark)`);let d;if(d=c===`system`?this.#N():c,typeof l!=`string`&&c===`system`){let e=new MutationObserver(e=>{for(let{type:t,attributeName:n}of e)if(t===`attributes`&&n!==null&&(n===`class`||n.startsWith(`data-`))){let e=this.#N();this.#M(l[e],e);break}});e.observe(document.documentElement,{attributes:!0}),e.observe(document.body,{attributes:!0}),this.#p=[Q(this.#n,`change`,()=>{let e=this.#N();this.#M(l[e],e)}),()=>e.disconnect()]}this.#e=t,this.#o=n,this.#s=u,this.#c=i,this.#l=a,this.#u=o,this.#d=r!==!1,this.#f=s??!1,this.#I(),this.#a=[],this.#P(typeof l==`string`?l:l[d],typeof l==`string`?void 0:d)}#M(e,t){(e!==this.#i||t!==this.#r)&&(this.#P(e,t),this.stopBackgroundTokenize(),this.#h=[Ft],this.#g=[],this.#_=0,this.#v=[],this.#t!==void 0&&this.#o.lineCount>0&&this.#B(0),this.#u?.())}#N(){try{if(typeof document<`u`&&typeof getComputedStyle==`function`&&document.body!=null){let e=getComputedStyle(document.body).colorScheme.split(/\s+/),t=e.includes(`dark`);if(t!==e.includes(`light`))return t?`dark`:`light`}}catch{}return this.#n.matches?`dark`:`light`}syncTheme(e){let{themeType:t=`system`,theme:n=W}=e;if(typeof n==`string`){let e=this.#e.getTheme(n).type;if(n===this.#i&&e===this.#r)return;this.#M(n,e);return}let r=t===`system`?this.#N():t,i=n[r];(r!==this.#r||i!==this.#i)&&this.#M(i,r)}#P(e,t){let{theme:n,colorMap:r}=this.#e.setTheme(e),{colors:i={}}=this.#e.getTheme(e),a=i[`editor.selectionBackground`],o=i[`editor.lineHighlightBackground`],s=o!=null&&o.trim()!==``&&!no.isFullyTransparent(o)?o:void 0,c=i[`editor.lineHighlightBorder`]??(s==null?`color-mix(in lab, var(--diffs-bg) 70%, var(--diffs-fg))`:`transparent`),l=s==null?`100%`:`85%`,u=i[`editorCursor.foreground`],d=i[`editor.findMatchBackground`],f=i[`editor.findMatchHighlightBackground`],p=i[`editorBracketMatch.background`],m=i[`editorBracketMatch.border`],h=i[`editorHint.foreground`],g=i[`editorInfo.foreground`],_=i[`editorWarning.foreground`],v=i[`editorError.foreground`];this.#c(`:host {
1933
1933
  --diffs-editor-selection-bg: ${a??`var(--diffs-line-bg)`};
1934
1934
  --diffs-editor-line-highlight-border: ${c};
1935
1935
  --diffs-editor-active-line-source-mix: ${l};
@@ -1942,7 +1942,7 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
1942
1942
  --diffs-editor-info-fg: ${g??`initial`};
1943
1943
  --diffs-editor-warning-fg: ${_??`initial`};
1944
1944
  --diffs-editor-error-fg: ${v??`initial`};
1945
- }`),this.#i=e,this.#r=t??n.type,this.#a=r}#F(){if(this.#i===``)return;let{colorMap:e}=this.#e.setTheme(this.#i);this.#a=e}cleanUp(){this.#m=!0,this.stopBackgroundTokenize(),this.#R(),this.#p?.forEach(e=>e()),this.#p=void 0}tokenize(e,t,n=!1){if(this.#I(),this.#F(),this.#t===void 0&&!Zm(this.#o.languageId))throw Error(`Grammar for language "${this.#o.languageId}" not loaded`);this.#d&&(this.#O.length=Math.min(this.#O.length,e.startLine));let{lineCount:r}=this.#o,{startingLine:i=0,totalLines:a=1/0}=t??{},o=a===1/0?r:Math.min(i+a,r),s=e.startLine,c=Math.max(i,s),l=t!==void 0&&a!==1/0&&e.lineDelta>0&&s<o&&e.endLine>=o,u=e.lineDelta===0&&(e.changedLineChanges?.every(([,,e])=>e===0)??!0),d=n&&e.lineDelta!==0&&s>=i,f=u||t===void 0||s>=c,p=e.changedLineRanges??[[s,e.endLine]];this.#g=[],this.#_=0,this.#v=[];let m=-1;if(s<c)for(let[e,t]of p)e<c&&(m=Math.max(m,Math.min(t,c-1)));let h=m>=s&&(u||e.lineDelta<0);u?this.#K(s):(this.#W(e),(t===void 0||s>=c)&&this.#K(c));let g=0,_=p[g][1],v,y=0,b=u?p[g][0]:c,x=!1,S=new Map,C=h?new Map:void 0;if(C!==void 0&&!u){let e=Math.min(m+1,c,o);if(e>s){this.#K(e);let t=s,n=this.#h[t]??It;for(;t<e;t++){let e=this.#H(t,n);n=e.state,C.set(t,e.resolvedTokens)}this.#h[e]=n}}let w=this.#h[b]??It;for(;b<o;){let e=u?this.#h[b+1]:d?this.#G(b+1):void 0;f&&(this.#h[b]=w);let{resolvedTokens:t,state:n}=this.#H(b,w);if(w=n,b>=c?S.set(b,t):C?.set(b,t),f&&(this.#h[b+1]=w),x=b>=_&&(u||d)&&e!==void 0&&w.equals(e),x){g++;let e=p[g];if(e===void 0)break;if(e[0]>=o){v=e[0],y=g;break}let t=this.#h[e[0]];if(d)for(let n=b+2;n<=e[0]&&(t=this.#G(n),t!==void 0);n++)this.#h[n]=t;t===void 0?(_=e[1],b++):(b=e[0],w=t,_=e[1]),x=!1;continue}b++}if(f&&(b<o?this.#h[b+1]=w:this.#h[b]=w),x&&d&&v===void 0){for(let e=b+2;e<=r;e++){let t=this.#G(e);if(t===void 0)break;this.#h[e]=t}this.#g=[],this.#_=0,this.#v=[]}if(C!==void 0&&C.size>0&&this.#l(C,this.#r),v!==void 0)this.#B(v,p,y);else if(!x&&b<r){let e=l&&s>=c?o:s<c&&!u?s:b;this.#B(e,p,g)}return S}prebuildStateStack(e){this.#I(),this.#A(e)}stopBackgroundTokenize(){this.#T=-1,!this.#b&&(this.#b=!0,this.#x=!1,this.#y=-1,this.#w=-1,this.#E=void 0,this.#D=0,this.#g=[],this.#_=0,this.#v=[],this.#R())}pauseBackgroundTokenize(){this.#b||this.#x||(this.#f&&console.log(`[diffs/editor] background tokenization paused`,{jobId:this.#S}),this.#x=!0)}resumeBackgroundTokenize(){this.#b||!this.#x||this.#t===void 0||this.#y<0||(this.#f&&console.log(`[diffs/editor] background tokenization resumed`,{jobId:this.#S}),this.#x=!1,this.#z(this.#S))}#I(){this.#t===void 0&&!Zm(this.#o.languageId)&&this.#e.getLoadedLanguages().includes(this.#o.languageId)&&(this.#t=this.#e.getLanguage(this.#o.languageId))}#L(){this.#k||=(globalThis.addEventListener(`message`,this.#j),!0)}#R(){this.#k&&=(globalThis.removeEventListener(`message`,this.#j),!1)}#z(e){globalThis.postMessage({type:`tokenize`,tokenizerId:this.#C,jobId:e})}#B(e,t,n=0){if(Zm(this.#o.languageId))return;let r=++this.#S;this.#f&&console.log(`[diffs/editor] background tokenization scheduled`,{jobId:r,startLine:e,changedLineRanges:t,changedRangeIndex:n}),this.#b=!1,this.#x=!1,this.#y=e,this.#w>=0&&(this.#T=Math.max(this.#T,this.#w)),this.#w=-1,this.#E=t,this.#D=n,this.#L(),this.#z(r)}#V(e){if(this.#t===void 0||this.#h.length>e)return;if(!this.#b){this.#w>=0?this.#w=Math.max(this.#w,e):this.#T=Math.max(this.#T,e);return}let t=++this.#S;this.#b=!1,this.#x=!1,this.#y=this.#h.length-1,this.#w=e,this.#T=-1,this.#E=void 0,this.#D=0,this.#L(),this.#z(t)}#H(e,t){let n=this.#o.getLineText(e);if(n.length>this.#s)return console.warn(`[diffs] Line(${e}) too long to tokenize: ${n.length}`),this.#U(e,null),{resolvedTokens:[[0,``,n]],state:t};if(this.#t===void 0||n===``||n.trim()===``)return this.#U(e,null),{resolvedTokens:[[0,``,n]],state:t};let r=Ym(this.#t,this.#a,n,t,Km,this.#d);return this.#U(e,r.bracketIgnoredRanges),{resolvedTokens:r.resolvedTokens,state:r.ruleStack}}#U(e,t){this.#d&&(this.#O[e]=t)}#W(e){let t=e.changedLineChanges??[[e.startLine,e.endLine,e.lineDelta]],n=e.startLine+1;n<=this.#h.length-n?(this.#g=this.#h,this.#_=0,this.#h=this.#h.slice(0,n)):(this.#_=n,this.#g=this.#h.slice(n),this.#h.length=Math.min(this.#h.length,n)),this.#v=t}#G(e){let t=e;for(let n=this.#v.length-1;n>=0;n--){let[r,i,a]=this.#v[n];if(a!==0){if(t>i)t-=a;else if(t>r)return this.#h[e]}}return this.#g[t-this.#_]??this.#h[e]}#K(e,t){let n=Math.min(Math.max(0,e),this.#o.lineCount);if(this.#h.length>n||this.#t===void 0)return!0;let r=t===void 0?0:performance.now(),i=this.#h.length-1,a=this.#h[i]??It;for(;i<n;){this.#h[i]=a;let e=this.#o.getLineText(i);if(e.length<=this.#s&&e!==``&&e.trim()!==``){let t=Ym(this.#t,this.#a,e,a,Km,this.#d,!1);this.#U(i,t.bracketIgnoredRanges),a=t.ruleStack}else this.#U(i,null);if(i++,this.#h[i]=a,t!==void 0&&performance.now()-r>t)break}return i>=n}#q(e){if(this.#b||this.#x||this.#t===void 0||e!==this.#S)return;this.#F();let t=this.#K(this.#w,1);if(!(this.#b||this.#x||e!==this.#S)){if(t){this.stopBackgroundTokenize();return}this.#y=this.#h.length-1,this.#z(e)}}#J(e){if(this.#b||this.#x||this.#t===void 0||e!==this.#S)return;this.#F();let t=performance.now(),n=new Map,r=this.#o.lineCount,i=this.#E,a=this.#y,o=this.#h[a]??It,s=!1,c=this.#D,l=i?.[c]?.[1];for(;a<r;){this.#h[a]=o;let e=l===void 0?void 0:this.#G(a+1),r=this.#o.getLineText(a);if(r.length>this.#s)console.warn(`[diffs] Line(${a}) too long to tokenize: ${r.length}`),n.set(a,[[0,``,r]]),this.#U(a,null);else if(r===``||r.trim()===``)n.set(a,[[0,``,r]]),this.#U(a,null);else{let e=Ym(this.#t,this.#a,r,o,Km,this.#d);n.set(a,e.resolvedTokens),this.#U(a,e.bracketIgnoredRanges),o=e.ruleStack}if(this.#h[a+1]=o,s=l!==void 0&&a>=l&&e!==void 0&&o.equals(e),a++,s){c++;let e=i?.[c];if(e===void 0)break;if(l=e[1],this.#h[e[0]]===void 0)s=!1;else{a=e[0],o=this.#h[a]??o,s=!1;continue}}if(performance.now()-t>1)break}if(this.#l(n,this.#r),!(this.#b||this.#x||e!==this.#S)){if(s||a>=r){let e=this.#T;this.stopBackgroundTokenize(),e>=0&&this.#V(e);return}this.#y=a,this.#D=c,this.#z(e)}}};function Ym(e,t,n,r,i,a=!0,o=!0){let s=e.tokenizeLine2(n,r,i);s.stoppedEarly&&console.warn(`[diffs] Time limit reached when tokenizing line: ${n.substring(0,100)}`);let c=s.tokens,l=c.length/2,u=[],d=[];if(!o&&!a)return{ruleStack:s.ruleStack,resolvedTokens:u,bracketIgnoredRanges:d};for(let e=0;e<l;e++){let r=c[2*e],i=e+1<l?c[2*e+2]:n.length;if(r===i)continue;let s=c[2*e+1];if(o){let e=Kt.getForeground(s);u.push([r,t[e],n.slice(r,i)])}a&&Kt.getTokenType(s)>0&&d.push([r,i])}return{ruleStack:s.ruleStack,resolvedTokens:u,bracketIgnoredRanges:d}}function Xm(e){return e.map(([e,t,n])=>e===0&&t===``?n===``?Z(`br`):n:Z(`span`,{dataset:{char:e.toString()},style:`color:${t};`,textContent:n}))}function Zm(e){return e===`text`||e===`ansi`}function Qm(e){let t=e.getSelection?.();if(t==null||t.rangeCount===0)return;let n=t.getRangeAt(0);return{collapsed:n.collapsed,startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset}}function $m(e){if(typeof e.cacheKey!=`string`||e.cacheKey.length===0)throw Error(`Editor persistState requires a non-empty file.cacheKey for "${e.name}". Provide a unique, stable cacheKey for every editable file.`);return e.cacheKey}function eh(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}var th=2,nh=1e4,rh=`selection-action`,ih=`application/vnd.pierre.diffs-selections+json`,ah=class{#e;#t=new Vm;#n;#r;#i=new Map;#a;#o;#s=new Map;#c;#l=0;#u=!1;#d;#f;#p;#m;#h={generation:0,callback:void 0,delivered:!1};#g;#_;#v;#y=new Map;#b=new Map;#x=new Map;#S;#C;#w;#T;#E;#D;#O;#k;#A;#j;#M;#N;#P;#F;#I;#L;#R;#z;#B;#V;#H;#U=!0;#W=!1;#G=!1;#K=!1;#q;#J=!1;#Y=!1;#X=!1;#Z=!1;#Q;#$=``;#ee;#te;#ne;#re;#ie;#ae;#oe=!1;#se=!1;#ce=!1;#le=!1;#ue;#de=(e,t)=>{if(this.#P?.updateRenderCache(e,t),this.#R!==void 0&&this.#R.totalLines!==1/0){let{startingLine:t,totalLines:n}=this.#R,r=Math.min(t+n,this.#L?.lineCount??0);for(let[n,i]of e)if(n>=t&&n<r){let e=this.#zt(n);e!==void 0&&e.replaceChildren(...Xm(i))}}};constructor(e={}){this.#e=e}setOptions(e){let t=this.#e.persistStateStorage??`inMemory`,n={...this.#e,...e};if(n.persistState===!0&&this.#P?.type===`file`){let e=this.#P.__getCurrentFile?.()??this.#F;e!==void 0&&$m(e)}this.#e=n,this.#e.persistState!==!0&&(this.#i.clear(),this.#l++,this.#u=!1),(this.#e.persistStateStorage??`inMemory`)!==t&&(this.#l++,this.#a=void 0,this.#o=void 0,this.#s.clear())}edit(e){if(this.#e.persistState===!0&&e.type===`file`){let t=e.__getCurrentFile?.();t!==void 0&&$m(t)}return this.#Oe(),this.#P=e,this.#Ne(),this.#m=e.attachEditor(this),()=>this.cleanUp()}applyEdits(e,t=!0){let n=this.#L;if(n==null)throw Error(`Editor is not attached`);let r=this.#K,i=this.#ne,a=i?.map(e=>[n.offsetAt(e.start),n.offsetAt(e.end)]),o=i===void 0?void 0:n.resolveEdits(e).sort((e,t)=>e.start-t.start),s=n.applyEdits(e,t,i);if(s===void 0)return;let c;i!==void 0&&a!==void 0&&o!==void 0&&(c=pp(n,i,a,o),t&&n.setLastUndoSelectionsAfter(c)),this.#It(s,c,this.#Lt(s),{skipFocus:!r})}get canUndo(){return this.#L?.canUndo??!1}get canRedo(){return this.#L?.canRedo??!1}undo(){this.#Ve(`undo`)}redo(){this.#Ve(`redo`)}getFile(){let e=this.#F,t=this.#L;if(e===void 0||t===void 0)return;let n={...e};return Object.defineProperty(n,"contents",{enumerable:!0,get:()=>t.getText()}),n}getText(){return this.#L?.getText()??``}getState(){let e=this.#P;return{selections:this.#ne,view:e==null?void 0:{scrollLeft:e.getCodeScrollLeft(),scrollTop:this.#je()}}}setState({selections:e,view:t}){if(this.#P===void 0||this.#L===void 0)throw Error(`Editor is not attached`);if(this.#U=!1,this.#gt(e??[]),t!=null){this.#P.setCodeScrollLeft(t.scrollLeft),t.scrollTop!==void 0&&this.#Me(t.scrollTop);return}this.#rt()}setSelections(e){let t=this.#L;if(t===void 0)throw Error(`Text document is not initialized`);let n=e.map(e=>{let n=t.normalizePosition(e.start),r=t.normalizePosition(e.end),i=e.direction===`none`?0:e.direction===`backward`?-1:1;return $(n,r)>0&&([n,r]=[r,n],i!==0&&(i=i===1?-1:1)),{direction:i,start:n,end:r}});this.#U=!1,this.#gt(n);let r=n.at(-1);r!==void 0&&this.#xe(cp(r).line),this.#rt()}setMarkers(e){let t=this.#L;if(t===void 0)throw Error(`Text document is not initialized`);if(e.length===0){this.#B?.cleanup(),this.#B=void 0,this.#gt(this.#ne??[]);return}this.#B??=new am({popoverManager:this.#Te(),getLineHeight:()=>this.#t.lineHeight,getOverlayElement:()=>this.#A,getGutterWidth:()=>this.#Bt(),getCharX:(e,t)=>this.#Ut(e,t),getLineY:e=>this.#Ht(e),isMouseDown:()=>this.#X||this.#Y}),this.#B.setMarkers(e,t),this.#k!==void 0&&this.#B.listenHover(this.#k),this.#gt(this.#ne??[])}focus(e){let t=e?.preventScroll??!1,n=e?.lineNumber;if(n===`first-visible`||typeof n==`number`){let r=this.#L;if(r==null||this.#P==null)return;let i=n===`first-visible`?this.#et(e?.offset):n;if(i==null)return;let a=r.normalizePosition({line:i-1,character:n===`first-visible`?0:e?.character??0});this.#tt(a,t);return}let r=this.#ne?.at(-1);if(r!==void 0){let e=r.direction===-1?r.end:r.start;this.#Ze(e,t)}else this.#Ze(void 0,t)}blur(){this.#q=void 0,this.#K=!1,this.#W=!1,this.#k?.blur()}cleanUp(e=!1){this.#Oe(),e||(this.#h.delivered=!1);let t=this.#P!=null,n=this.#e.persistState===!0;this.#l++,this.#me(),t&&(this.#u=n),gi(this.#Re),this.#n?.cleanUp(),this.#n=void 0,e||(this.#L=void 0,this.#F=void 0),this.#f?.forEach(e=>e()),this.#f=void 0,this.#d?.forEach(e=>e()),this.#d=void 0,this.#p?.forEach(e=>e()),this.#p=void 0,this.#m?.(e),this.#m=void 0,this.#_=void 0,this.#v=void 0,this.#y.clear(),this.#b.clear(),this.#x.clear(),this.#S=void 0,this.#C?.remove(),this.#C=void 0,this.#w?.remove(),this.#w=void 0,this.#T?.remove(),this.#T=void 0,this.#E?.remove(),this.#E=void 0,this.#D=void 0,this.#r?.cleanUp(),this.#r=void 0,this.#O=void 0,this.#k?.removeAttribute(`contentEditable`),this.#k=void 0,this.#q=void 0,this.#K=!1,this.#A?.remove(),this.#A=void 0,this.#N?.disconnect(),this.#N=void 0,this.#le=!1,this.#ue!==void 0&&(cancelAnimationFrame(this.#ue),this.#ue=void 0),this.#De(),this.#P=void 0}__prepareFile(e){if(this.#e.persistState!==!0)return e;let t=$m(e),n=this.#F,r=e.lang??on(e.name);n!==void 0&&($m(n)!==t||n.name!==e.name||this.#L?.languageId!==r)&&(this.#l++,this.#me());let i=this.#fe(e,t);return i===void 0||i.getText()===e.contents?e:{...e,contents:i.getText()}}__postponeBgTokenizeToNextFrame(){let e=this.#n;e!==void 0&&(e.pauseBackgroundTokenize(),requestAnimationFrame(()=>{e.resumeBackgroundTokenize()}))}__captureFocusForDOMReplacement(){let e=this.#k,t=this.#D?.shadowRoot?.activeElement;e!=null&&(this.#K||t===e||t!=null&&e.contains(t))&&(this.#q={})}__syncRenderView=(e,t,n,r,i)=>{let a=this.#P;if(a==null)return;let o=t.shadowRoot;if(o==null){console.error(`[editor] Could not find the shadow root.`);return}let s,c,l;for(let e of o.querySelectorAll(`[data-code]`))if(e.dataset.deletions===void 0){s=e;for(let t of e.children){let e=t,{gutter:n,content:r}=e.dataset;n===void 0?r!==void 0&&(l=e):c=e}break}if(s===void 0||l===void 0){this.#q=void 0;return}this.#Te().setViewportElements(t,s),this.#D!==t&&(this.#D=t,this.#C!==void 0&&t.appendChild(this.#C),this.#w!==void 0&&o.appendChild(this.#w),this.#T!==void 0&&o.appendChild(this.#T),this.#E!==void 0&&o.prepend(this.#E));let u=this.#L===void 0||this.#F===void 0||this.#F.name!==n.name||this.#F.lang!==n.lang||this.#F.cacheKey!==n.cacheKey,d=this.#e.persistState===!0?$m(n):void 0,f;if(u){this.#Oe();let e=``;e=`contents`in n?n.contents:n.additionLines.join(``);let t=new gd({maxEntries:this.#e.historyMaxEntries}),{name:r,lang:i,cacheKey:o}=n,s=i??on(n.name),c=d===void 0?void 0:this.#fe(n,d),l=a.type===`file`||c?.getText()===e?c:void 0,u=l??new Kd(n.name,e,s,0,t);this.#F={name:r,lang:i,cacheKey:o},this.#L=u,d!==void 0&&(this.#i.set(d,u),f={cacheKey:d,textDocument:u}),this.#n?.cleanUp(),this.#n=void 0,this.#De(),this.#b.clear(),this.#ne=this.#te,this.#e.__debug===!0&&console.log(l===void 0?`[diffs/editor] text document rebuilt from`:`[diffs/editor] cached text document reused for`,n.name)}f===void 0&&this.#u&&d!==void 0&&this.#L!==void 0&&(f={cacheKey:d,textDocument:this.#L});let p=this.#L;if(this.#n==null&&p!=null&&(this.#n=new Jm({highlighter:e,textDocument:p,codeOptions:this.#P?.__getEffectiveCodeOptions()??{},matchBrackets:this.#e.matchBrackets,onDeferTokenize:this.#de,onThemeChange:()=>this.#ht(),setStyle:e=>{this.#T.textContent=e},__debug:this.#e.__debug})),this.#k!==l&&(this.#O=c,this.#k=mf(l,{contentEditable:`true`,role:`textbox`,ariaMultiLine:`true`,autocapitalize:`off`,writingSuggestions:`off`,autocorrect:!1,spellcheck:!1,translate:!1}),this.#A!==void 0&&l.after(this.#A),this.#t.init(l),this.#Je(),this.#Le(l,c),this.#k!==void 0&&this.#e.__debug===!0&&console.log(`[diffs/editor] full re-render triggered !!!`)),this.#q!=null&&(this.#q.target=l),l.ariaLabel!==n.name&&(l.ariaLabel=n.name),r!==void 0&&r.length>0||this.#Ce)for(let e of this.#k.children){let t=e,{lineAnnotation:n,lineType:r,separator:i}=t.dataset;(n!==void 0||i!==void 0||r===`change-deletion`)&&t.setAttribute(`contenteditable`,`false`)}if(this.#Ee(),this.#n?.syncTheme(this.#P?.__getEffectiveCodeOptions()??{}),this.#I=r,this.#R=i,this.#z=i?.totalLines,this.#n?.prebuildStateStack(i),this.#B?.removePopover(),(this.#ne!==void 0||this.#re!==void 0||this.#B!==void 0)&&this.#gt(this.#ne??[]),this.#te!==void 0&&this.#M!==void 0?(this.#te=void 0,this.#rt(!1,`center`)):this.#ie===void 0?this.#q===void 0?this.#ne!==void 0&&this.#ne.length>0&&this.#K&&!this.#ce&&this.focus({preventScroll:!0}):this.#Qe():this.#at(this.#ie,this.#ae,this.#se),this.#ce&&this.#V?.focus(),this.#e.__debug===!0&&i!==void 0){let{startingLine:e,totalLines:t}=i;console.log(`[diffs/editor] render file:`,n.name,`RenderRange:`,e+`-`+(e+t),`of`,this.#L?.lineCount,`lines`)}f!==void 0&&(this.#u=!1,this.#_e(f.cacheKey,f.textDocument)),this.#ke(a)};#fe(e,t){let n=this.#i.get(t),r=e.lang??on(e.name);return n?.languageId===r?n:void 0}#pe(){let e=this.#e.persistStateStorage??`inMemory`;return(this.#a===void 0||this.#o!==e)&&(this.#a=jm(e),this.#o=e),this.#a}#me(){let e=this.#F,t=this.#L;if(this.#e.persistState!==!0||this.#P===void 0||e===void 0||t===void 0)return;let n=$m(e);this.#i.set(n,t);let r;try{r=this.#pe()}catch{return}let i=Am(this.getState()),a=this.#c;if(a?.cacheKey===n&&a.textDocument===t){if(this.#c=void 0,t.version===a.documentVersion&&this.#ne===a.selections&&i.view?.scrollLeft===a.view?.scrollLeft&&i.view?.scrollTop===a.view?.scrollTop)return;this.#he(r,n,i,a.completion);return}this.#he(r,n,i)}#he(e,t,n,r){let i=this.#s.get(t);if(r!==void 0||i!==void 0){let a=r??Promise.resolve();i!==void 0&&(a=a.then(()=>i)),this.#ge(t,a.then(()=>e.set(t,n)));return}let a;try{a=e.set(t,n)}catch{return}eh(a)&&this.#ge(t,a)}#ge(e,t){let n=t.catch(()=>{});this.#s.set(e,n),n.finally(()=>{this.#s.get(e)===n&&this.#s.delete(e)})}#_e(e,t){let n=++this.#l,r=t.version,i=this.#ne,a=this.getState().view,o,s=s=>{let c=this.getState().view;if(n!==this.#l||this.#L!==t||t.version!==r||this.#ne!==i||c?.scrollLeft!==a?.scrollLeft||this.#F===void 0||$m(this.#F)!==e)return;let l=o?.userScrolled()===!0;if(s===void 0){this.#P?.setCodeScrollLeft(0),l||this.#Me(0);return}let u=Am(s);l&&u.view!==void 0&&(u.view={scrollLeft:u.view.scrollLeft}),this.setState(u)},c=()=>{let t;try{t=this.#pe().get(e)}catch{return}if(eh(t))return t.then(s).catch(()=>{});try{s(t)}catch{}},l=this.#s.get(e),u=l===void 0?c():l.then(c);if(eh(u)){o=this.#ve();let n={cacheKey:e,textDocument:t,documentVersion:r,selections:i,view:a,completion:u.catch(()=>{})};this.#c=n,n.completion.finally(()=>{o?.dispose(),this.#c===n&&(this.#c=void 0)})}}#ve(){let e=this.#Ae();if(!(e instanceof HTMLElement))return;let t=!1,n=[`wheel`,`touchstart`,`mousedown`],r=()=>{for(let t of n)e.removeEventListener(t,i,{capture:!0})},i=()=>{t=!0,r()};for(let t of n)e.addEventListener(t,i,{capture:!0,passive:!0});return{userScrolled:()=>t,dispose:r}}#ye(e){return this.#P?.isLineRenderable?.(e+1)??!0}get#be(){let e=this.#P;if(e?.getNearestRenderableLine!=null)return(t,n)=>{let r=e.getNearestRenderableLine(t+1,n);return r==null?void 0:r-1}}#xe(e){this.#ye(e)||this.#P?.revealLine?.(e+1)}get#Se(){return this.#P?.options.diffStyle??`split`}get#Ce(){return this.#P?.type===`file-diff`}get#we(){return this.#P?.options.overflow===`wrap`}#Te(){return this.#r??=new Ff({hasActivePopover:()=>this.#H!==void 0||this.#B?.isPopoverVisible()===!0,updateActivePopover:()=>{this.#St(),this.#B?.updatePopoverPosition()}})}#Ee(){this.#y.clear(),this.#x.clear(),this.#S=void 0}#De(){this.#mt(null),this.#_=void 0,this.#v=void 0,this.#W=!1,this.#G=!1,this.#j?.forEach(e=>e.remove()),this.#j=void 0,this.#ne=void 0,this.#ee=void 0,this.#ie=void 0,this.#B?.cleanup(),this.#B=void 0,this.#V?.cleanup(),this.#V=void 0,this.#H?.cleanup(),this.#H=void 0,this.#U=!0}#Oe(){let e=this.#h;e.generation++,e.callback!=null&&(gi(e.callback),e.callback=void 0)}#ke(e){let t=this.#h,n=this.#L;if(t.delivered||t.callback!=null||n==null)return;let{generation:r}=t,i=()=>{if(t.callback!==i||(t.callback=void 0,r!==t.generation||this.#P!==e||this.#L!==n))return;let a=this.#k,o=this.#D?.shadowRoot;a==null||o==null||!o.contains(a)||(t.delivered=!0,this.#e.onAttach?.(this,e))};t.callback=i,hi(i)}#Ae(){let e=this.#P?.getEditorViewport?.();if(e!==void 0)return e;let t=this.#D;if(this.#P!=null&&t!=null)return Sf(t)}#je(){let e=this.#Ae();return e instanceof HTMLElement?e.scrollTop:e?.defaultView?.scrollY??0}#Me(e){let t=this.#Ae();t instanceof HTMLElement?t.scrollTop=e:t instanceof Document&&t.defaultView?.scrollTo({top:e})}#Ne(){this.#C=Z(`style`,{dataset:`editorGlobalCss`,textContent:`
1945
+ }`),this.#i=e,this.#r=t??n.type,this.#a=r}#F(){if(this.#i===``)return;let{colorMap:e}=this.#e.setTheme(this.#i);this.#a=e}cleanUp(){this.#m=!0,this.stopBackgroundTokenize(),this.#R(),this.#p?.forEach(e=>e()),this.#p=void 0}tokenize(e,t,n=!1){if(this.#I(),this.#F(),this.#t===void 0&&!Zm(this.#o.languageId))throw Error(`Grammar for language "${this.#o.languageId}" not loaded`);this.#d&&(this.#O.length=Math.min(this.#O.length,e.startLine));let{lineCount:r}=this.#o,{startingLine:i=0,totalLines:a=1/0}=t??{},o=a===1/0?r:Math.min(i+a,r),s=e.startLine,c=Math.max(i,s),l=t!==void 0&&a!==1/0&&e.lineDelta>0&&s<o&&e.endLine>=o,u=e.lineDelta===0&&(e.changedLineChanges?.every(([,,e])=>e===0)??!0),d=n&&e.lineDelta!==0&&s>=i,f=u||t===void 0||s>=c,p=e.changedLineRanges??[[s,e.endLine]];this.#g=[],this.#_=0,this.#v=[];let m=-1;if(s<c)for(let[e,t]of p)e<c&&(m=Math.max(m,Math.min(t,c-1)));let h=m>=s&&(u||e.lineDelta<0);u?this.#K(s):(this.#W(e),(t===void 0||s>=c)&&this.#K(c));let g=0,_=p[g][1],v,y=0,b=u?p[g][0]:c,x=!1,S=new Map,C=h?new Map:void 0;if(C!==void 0&&!u){let e=Math.min(m+1,c,o);if(e>s){this.#K(e);let t=s,n=this.#h[t]??Ft;for(;t<e;t++){let e=this.#H(t,n);n=e.state,C.set(t,e.resolvedTokens)}this.#h[e]=n}}let w=this.#h[b]??Ft;for(;b<o;){let e=u?this.#h[b+1]:d?this.#G(b+1):void 0;f&&(this.#h[b]=w);let{resolvedTokens:t,state:n}=this.#H(b,w);if(w=n,b>=c?S.set(b,t):C?.set(b,t),f&&(this.#h[b+1]=w),x=b>=_&&(u||d)&&e!==void 0&&w.equals(e),x){g++;let e=p[g];if(e===void 0)break;if(e[0]>=o){v=e[0],y=g;break}let t=this.#h[e[0]];if(d)for(let n=b+2;n<=e[0]&&(t=this.#G(n),t!==void 0);n++)this.#h[n]=t;t===void 0?(_=e[1],b++):(b=e[0],w=t,_=e[1]),x=!1;continue}b++}if(f&&(b<o?this.#h[b+1]=w:this.#h[b]=w),x&&d&&v===void 0){for(let e=b+2;e<=r;e++){let t=this.#G(e);if(t===void 0)break;this.#h[e]=t}this.#g=[],this.#_=0,this.#v=[]}if(C!==void 0&&C.size>0&&this.#l(C,this.#r),v!==void 0)this.#B(v,p,y);else if(!x&&b<r){let e=l&&s>=c?o:s<c&&!u?s:b;this.#B(e,p,g)}return S}prebuildStateStack(e){this.#I(),this.#A(e)}stopBackgroundTokenize(){this.#T=-1,!this.#b&&(this.#b=!0,this.#x=!1,this.#y=-1,this.#w=-1,this.#E=void 0,this.#D=0,this.#g=[],this.#_=0,this.#v=[],this.#R())}pauseBackgroundTokenize(){this.#b||this.#x||(this.#f&&console.log(`[diffs/editor] background tokenization paused`,{jobId:this.#S}),this.#x=!0)}resumeBackgroundTokenize(){this.#b||!this.#x||this.#t===void 0||this.#y<0||(this.#f&&console.log(`[diffs/editor] background tokenization resumed`,{jobId:this.#S}),this.#x=!1,this.#z(this.#S))}#I(){this.#t===void 0&&!Zm(this.#o.languageId)&&this.#e.getLoadedLanguages().includes(this.#o.languageId)&&(this.#t=this.#e.getLanguage(this.#o.languageId))}#L(){this.#k||=(globalThis.addEventListener(`message`,this.#j),!0)}#R(){this.#k&&=(globalThis.removeEventListener(`message`,this.#j),!1)}#z(e){globalThis.postMessage({type:`tokenize`,tokenizerId:this.#C,jobId:e})}#B(e,t,n=0){if(Zm(this.#o.languageId))return;let r=++this.#S;this.#f&&console.log(`[diffs/editor] background tokenization scheduled`,{jobId:r,startLine:e,changedLineRanges:t,changedRangeIndex:n}),this.#b=!1,this.#x=!1,this.#y=e,this.#w>=0&&(this.#T=Math.max(this.#T,this.#w)),this.#w=-1,this.#E=t,this.#D=n,this.#L(),this.#z(r)}#V(e){if(this.#t===void 0||this.#h.length>e)return;if(!this.#b){this.#w>=0?this.#w=Math.max(this.#w,e):this.#T=Math.max(this.#T,e);return}let t=++this.#S;this.#b=!1,this.#x=!1,this.#y=this.#h.length-1,this.#w=e,this.#T=-1,this.#E=void 0,this.#D=0,this.#L(),this.#z(t)}#H(e,t){let n=this.#o.getLineText(e);if(n.length>this.#s)return console.warn(`[diffs] Line(${e}) too long to tokenize: ${n.length}`),this.#U(e,null),{resolvedTokens:[[0,``,n]],state:t};if(this.#t===void 0||n===``||n.trim()===``)return this.#U(e,null),{resolvedTokens:[[0,``,n]],state:t};let r=Ym(this.#t,this.#a,n,t,Km,this.#d);return this.#U(e,r.bracketIgnoredRanges),{resolvedTokens:r.resolvedTokens,state:r.ruleStack}}#U(e,t){this.#d&&(this.#O[e]=t)}#W(e){let t=e.changedLineChanges??[[e.startLine,e.endLine,e.lineDelta]],n=e.startLine+1;n<=this.#h.length-n?(this.#g=this.#h,this.#_=0,this.#h=this.#h.slice(0,n)):(this.#_=n,this.#g=this.#h.slice(n),this.#h.length=Math.min(this.#h.length,n)),this.#v=t}#G(e){let t=e;for(let n=this.#v.length-1;n>=0;n--){let[r,i,a]=this.#v[n];if(a!==0){if(t>i)t-=a;else if(t>r)return this.#h[e]}}return this.#g[t-this.#_]??this.#h[e]}#K(e,t){let n=Math.min(Math.max(0,e),this.#o.lineCount);if(this.#h.length>n||this.#t===void 0)return!0;let r=t===void 0?0:performance.now(),i=this.#h.length-1,a=this.#h[i]??Ft;for(;i<n;){this.#h[i]=a;let e=this.#o.getLineText(i);if(e.length<=this.#s&&e!==``&&e.trim()!==``){let t=Ym(this.#t,this.#a,e,a,Km,this.#d,!1);this.#U(i,t.bracketIgnoredRanges),a=t.ruleStack}else this.#U(i,null);if(i++,this.#h[i]=a,t!==void 0&&performance.now()-r>t)break}return i>=n}#q(e){if(this.#b||this.#x||this.#t===void 0||e!==this.#S)return;this.#F();let t=this.#K(this.#w,1);if(!(this.#b||this.#x||e!==this.#S)){if(t){this.stopBackgroundTokenize();return}this.#y=this.#h.length-1,this.#z(e)}}#J(e){if(this.#b||this.#x||this.#t===void 0||e!==this.#S)return;this.#F();let t=performance.now(),n=new Map,r=this.#o.lineCount,i=this.#E,a=this.#y,o=this.#h[a]??Ft,s=!1,c=this.#D,l=i?.[c]?.[1];for(;a<r;){this.#h[a]=o;let e=l===void 0?void 0:this.#G(a+1),r=this.#o.getLineText(a);if(r.length>this.#s)console.warn(`[diffs] Line(${a}) too long to tokenize: ${r.length}`),n.set(a,[[0,``,r]]),this.#U(a,null);else if(r===``||r.trim()===``)n.set(a,[[0,``,r]]),this.#U(a,null);else{let e=Ym(this.#t,this.#a,r,o,Km,this.#d);n.set(a,e.resolvedTokens),this.#U(a,e.bracketIgnoredRanges),o=e.ruleStack}if(this.#h[a+1]=o,s=l!==void 0&&a>=l&&e!==void 0&&o.equals(e),a++,s){c++;let e=i?.[c];if(e===void 0)break;if(l=e[1],this.#h[e[0]]===void 0)s=!1;else{a=e[0],o=this.#h[a]??o,s=!1;continue}}if(performance.now()-t>1)break}if(this.#l(n,this.#r),!(this.#b||this.#x||e!==this.#S)){if(s||a>=r){let e=this.#T;this.stopBackgroundTokenize(),e>=0&&this.#V(e);return}this.#y=a,this.#D=c,this.#z(e)}}};function Ym(e,t,n,r,i,a=!0,o=!0){let s=e.tokenizeLine2(n,r,i);s.stoppedEarly&&console.warn(`[diffs] Time limit reached when tokenizing line: ${n.substring(0,100)}`);let c=s.tokens,l=c.length/2,u=[],d=[];if(!o&&!a)return{ruleStack:s.ruleStack,resolvedTokens:u,bracketIgnoredRanges:d};for(let e=0;e<l;e++){let r=c[2*e],i=e+1<l?c[2*e+2]:n.length;if(r===i)continue;let s=c[2*e+1];if(o){let e=Gt.getForeground(s);u.push([r,t[e],n.slice(r,i)])}a&&Gt.getTokenType(s)>0&&d.push([r,i])}return{ruleStack:s.ruleStack,resolvedTokens:u,bracketIgnoredRanges:d}}function Xm(e){return e.map(([e,t,n])=>e===0&&t===``?n===``?Z(`br`):n:Z(`span`,{dataset:{char:e.toString()},style:`color:${t};`,textContent:n}))}function Zm(e){return e===`text`||e===`ansi`}function Qm(e){let t=e.getSelection?.();if(t==null||t.rangeCount===0)return;let n=t.getRangeAt(0);return{collapsed:n.collapsed,startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset}}function $m(e){if(typeof e.cacheKey!=`string`||e.cacheKey.length===0)throw Error(`Editor persistState requires a non-empty file.cacheKey for "${e.name}". Provide a unique, stable cacheKey for every editable file.`);return e.cacheKey}function eh(e){return typeof e==`object`&&!!e&&`then`in e&&typeof e.then==`function`}var th=2,nh=1e4,rh=`selection-action`,ih=`application/vnd.pierre.diffs-selections+json`,ah=class{#e;#t=new Vm;#n;#r;#i=new Map;#a;#o;#s=new Map;#c;#l=0;#u=!1;#d;#f;#p;#m;#h={generation:0,callback:void 0,delivered:!1};#g;#_;#v;#y=new Map;#b=new Map;#x=new Map;#S;#C;#w;#T;#E;#D;#O;#k;#A;#j;#M;#N;#P;#F;#I;#L;#R;#z;#B;#V;#H;#U=!0;#W=!1;#G=!1;#K=!1;#q;#J=!1;#Y=!1;#X=!1;#Z=!1;#Q;#$=``;#ee;#te;#ne;#re;#ie;#ae;#oe=!1;#se=!1;#ce=!1;#le=!1;#ue;#de=(e,t)=>{if(this.#P?.updateRenderCache(e,t),this.#R!==void 0&&this.#R.totalLines!==1/0){let{startingLine:t,totalLines:n}=this.#R,r=Math.min(t+n,this.#L?.lineCount??0);for(let[n,i]of e)if(n>=t&&n<r){let e=this.#zt(n);e!==void 0&&e.replaceChildren(...Xm(i))}}};constructor(e={}){this.#e=e}setOptions(e){let t=this.#e.persistStateStorage??`inMemory`,n={...this.#e,...e};if(n.persistState===!0&&this.#P?.type===`file`){let e=this.#P.__getCurrentFile?.()??this.#F;e!==void 0&&$m(e)}this.#e=n,this.#e.persistState!==!0&&(this.#i.clear(),this.#l++,this.#u=!1),(this.#e.persistStateStorage??`inMemory`)!==t&&(this.#l++,this.#a=void 0,this.#o=void 0,this.#s.clear())}edit(e){if(this.#e.persistState===!0&&e.type===`file`){let t=e.__getCurrentFile?.();t!==void 0&&$m(t)}return this.#Oe(),this.#P=e,this.#Ne(),this.#m=e.attachEditor(this),()=>this.cleanUp()}applyEdits(e,t=!0){let n=this.#L;if(n==null)throw Error(`Editor is not attached`);let r=this.#K,i=this.#ne,a=i?.map(e=>[n.offsetAt(e.start),n.offsetAt(e.end)]),o=i===void 0?void 0:n.resolveEdits(e).sort((e,t)=>e.start-t.start),s=n.applyEdits(e,t,i);if(s===void 0)return;let c;i!==void 0&&a!==void 0&&o!==void 0&&(c=pp(n,i,a,o),t&&n.setLastUndoSelectionsAfter(c)),this.#It(s,c,this.#Lt(s),{skipFocus:!r})}get canUndo(){return this.#L?.canUndo??!1}get canRedo(){return this.#L?.canRedo??!1}undo(){this.#Ve(`undo`)}redo(){this.#Ve(`redo`)}getFile(){let e=this.#F,t=this.#L;if(e===void 0||t===void 0)return;let n={...e};return Object.defineProperty(n,"contents",{enumerable:!0,get:()=>t.getText()}),n}getText(){return this.#L?.getText()??``}getState(){let e=this.#P;return{selections:this.#ne,view:e==null?void 0:{scrollLeft:e.getCodeScrollLeft(),scrollTop:this.#je()}}}setState({selections:e,view:t}){if(this.#P===void 0||this.#L===void 0)throw Error(`Editor is not attached`);if(this.#U=!1,this.#gt(e??[]),t!=null){this.#P.setCodeScrollLeft(t.scrollLeft),t.scrollTop!==void 0&&this.#Me(t.scrollTop);return}this.#rt()}setSelections(e){let t=this.#L;if(t===void 0)throw Error(`Text document is not initialized`);let n=e.map(e=>{let n=t.normalizePosition(e.start),r=t.normalizePosition(e.end),i=e.direction===`none`?0:e.direction===`backward`?-1:1;return $(n,r)>0&&([n,r]=[r,n],i!==0&&(i=i===1?-1:1)),{direction:i,start:n,end:r}});this.#U=!1,this.#gt(n);let r=n.at(-1);r!==void 0&&this.#xe(cp(r).line),this.#rt()}setMarkers(e){let t=this.#L;if(t===void 0)throw Error(`Text document is not initialized`);if(e.length===0){this.#B?.cleanup(),this.#B=void 0,this.#gt(this.#ne??[]);return}this.#B??=new am({popoverManager:this.#Te(),getLineHeight:()=>this.#t.lineHeight,getOverlayElement:()=>this.#A,getGutterWidth:()=>this.#Bt(),getCharX:(e,t)=>this.#Ut(e,t),getLineY:e=>this.#Ht(e),isMouseDown:()=>this.#X||this.#Y}),this.#B.setMarkers(e,t),this.#k!==void 0&&this.#B.listenHover(this.#k),this.#gt(this.#ne??[])}focus(e){let t=e?.preventScroll??!1,n=e?.lineNumber;if(n===`first-visible`||typeof n==`number`){let r=this.#L;if(r==null||this.#P==null)return;let i=n===`first-visible`?this.#et(e?.offset):n;if(i==null)return;let a=r.normalizePosition({line:i-1,character:n===`first-visible`?0:e?.character??0});this.#tt(a,t);return}let r=this.#ne?.at(-1);if(r!==void 0){let e=r.direction===-1?r.end:r.start;this.#Ze(e,t)}else this.#Ze(void 0,t)}blur(){this.#q=void 0,this.#K=!1,this.#W=!1,this.#k?.blur()}cleanUp(e=!1){this.#Oe(),e||(this.#h.delivered=!1);let t=this.#P!=null,n=this.#e.persistState===!0;this.#l++,this.#me(),t&&(this.#u=n),gi(this.#Re),this.#n?.cleanUp(),this.#n=void 0,e||(this.#L=void 0,this.#F=void 0),this.#f?.forEach(e=>e()),this.#f=void 0,this.#d?.forEach(e=>e()),this.#d=void 0,this.#p?.forEach(e=>e()),this.#p=void 0,this.#m?.(e),this.#m=void 0,this.#_=void 0,this.#v=void 0,this.#y.clear(),this.#b.clear(),this.#x.clear(),this.#S=void 0,this.#C?.remove(),this.#C=void 0,this.#w?.remove(),this.#w=void 0,this.#T?.remove(),this.#T=void 0,this.#E?.remove(),this.#E=void 0,this.#D=void 0,this.#r?.cleanUp(),this.#r=void 0,this.#O=void 0,this.#k?.removeAttribute(`contentEditable`),this.#k=void 0,this.#q=void 0,this.#K=!1,this.#A?.remove(),this.#A=void 0,this.#N?.disconnect(),this.#N=void 0,this.#le=!1,this.#ue!==void 0&&(cancelAnimationFrame(this.#ue),this.#ue=void 0),this.#De(),this.#P=void 0}__prepareFile(e){if(this.#e.persistState!==!0)return e;let t=$m(e),n=this.#F,r=e.lang??an(e.name);n!==void 0&&($m(n)!==t||n.name!==e.name||this.#L?.languageId!==r)&&(this.#l++,this.#me());let i=this.#fe(e,t);return i===void 0||i.getText()===e.contents?e:{...e,contents:i.getText()}}__postponeBgTokenizeToNextFrame(){let e=this.#n;e!==void 0&&(e.pauseBackgroundTokenize(),requestAnimationFrame(()=>{e.resumeBackgroundTokenize()}))}__captureFocusForDOMReplacement(){let e=this.#k,t=this.#D?.shadowRoot?.activeElement;e!=null&&(this.#K||t===e||t!=null&&e.contains(t))&&(this.#q={})}__syncRenderView=(e,t,n,r,i)=>{let a=this.#P;if(a==null)return;let o=t.shadowRoot;if(o==null){console.error(`[editor] Could not find the shadow root.`);return}let s,c,l;for(let e of o.querySelectorAll(`[data-code]`))if(e.dataset.deletions===void 0){s=e;for(let t of e.children){let e=t,{gutter:n,content:r}=e.dataset;n===void 0?r!==void 0&&(l=e):c=e}break}if(s===void 0||l===void 0){this.#q=void 0;return}this.#Te().setViewportElements(t,s),this.#D!==t&&(this.#D=t,this.#C!==void 0&&t.appendChild(this.#C),this.#w!==void 0&&o.appendChild(this.#w),this.#T!==void 0&&o.appendChild(this.#T),this.#E!==void 0&&o.prepend(this.#E));let u=this.#L===void 0||this.#F===void 0||this.#F.name!==n.name||this.#F.lang!==n.lang||this.#F.cacheKey!==n.cacheKey,d=this.#e.persistState===!0?$m(n):void 0,f;if(u){this.#Oe();let e=``;e=`contents`in n?n.contents:n.additionLines.join(``);let t=new gd({maxEntries:this.#e.historyMaxEntries}),{name:r,lang:i,cacheKey:o}=n,s=i??an(n.name),c=d===void 0?void 0:this.#fe(n,d),l=a.type===`file`||c?.getText()===e?c:void 0,u=l??new Kd(n.name,e,s,0,t);this.#F={name:r,lang:i,cacheKey:o},this.#L=u,d!==void 0&&(this.#i.set(d,u),f={cacheKey:d,textDocument:u}),this.#n?.cleanUp(),this.#n=void 0,this.#De(),this.#b.clear(),this.#ne=this.#te,this.#e.__debug===!0&&console.log(l===void 0?`[diffs/editor] text document rebuilt from`:`[diffs/editor] cached text document reused for`,n.name)}f===void 0&&this.#u&&d!==void 0&&this.#L!==void 0&&(f={cacheKey:d,textDocument:this.#L});let p=this.#L;if(this.#n==null&&p!=null&&(this.#n=new Jm({highlighter:e,textDocument:p,codeOptions:this.#P?.__getEffectiveCodeOptions()??{},matchBrackets:this.#e.matchBrackets,onDeferTokenize:this.#de,onThemeChange:()=>this.#ht(),setStyle:e=>{this.#T.textContent=e},__debug:this.#e.__debug})),this.#k!==l&&(this.#O=c,this.#k=mf(l,{contentEditable:`true`,role:`textbox`,ariaMultiLine:`true`,autocapitalize:`off`,writingSuggestions:`off`,autocorrect:!1,spellcheck:!1,translate:!1}),this.#A!==void 0&&l.after(this.#A),this.#t.init(l),this.#Je(),this.#Le(l,c),this.#k!==void 0&&this.#e.__debug===!0&&console.log(`[diffs/editor] full re-render triggered !!!`)),this.#q!=null&&(this.#q.target=l),l.ariaLabel!==n.name&&(l.ariaLabel=n.name),r!==void 0&&r.length>0||this.#Ce)for(let e of this.#k.children){let t=e,{lineAnnotation:n,lineType:r,separator:i}=t.dataset;(n!==void 0||i!==void 0||r===`change-deletion`)&&t.setAttribute(`contenteditable`,`false`)}if(this.#Ee(),this.#n?.syncTheme(this.#P?.__getEffectiveCodeOptions()??{}),this.#I=r,this.#R=i,this.#z=i?.totalLines,this.#n?.prebuildStateStack(i),this.#B?.removePopover(),(this.#ne!==void 0||this.#re!==void 0||this.#B!==void 0)&&this.#gt(this.#ne??[]),this.#te!==void 0&&this.#M!==void 0?(this.#te=void 0,this.#rt(!1,`center`)):this.#ie===void 0?this.#q===void 0?this.#ne!==void 0&&this.#ne.length>0&&this.#K&&!this.#ce&&this.focus({preventScroll:!0}):this.#Qe():this.#at(this.#ie,this.#ae,this.#se),this.#ce&&this.#V?.focus(),this.#e.__debug===!0&&i!==void 0){let{startingLine:e,totalLines:t}=i;console.log(`[diffs/editor] render file:`,n.name,`RenderRange:`,e+`-`+(e+t),`of`,this.#L?.lineCount,`lines`)}f!==void 0&&(this.#u=!1,this.#_e(f.cacheKey,f.textDocument)),this.#ke(a)};#fe(e,t){let n=this.#i.get(t),r=e.lang??an(e.name);return n?.languageId===r?n:void 0}#pe(){let e=this.#e.persistStateStorage??`inMemory`;return(this.#a===void 0||this.#o!==e)&&(this.#a=jm(e),this.#o=e),this.#a}#me(){let e=this.#F,t=this.#L;if(this.#e.persistState!==!0||this.#P===void 0||e===void 0||t===void 0)return;let n=$m(e);this.#i.set(n,t);let r;try{r=this.#pe()}catch{return}let i=Am(this.getState()),a=this.#c;if(a?.cacheKey===n&&a.textDocument===t){if(this.#c=void 0,t.version===a.documentVersion&&this.#ne===a.selections&&i.view?.scrollLeft===a.view?.scrollLeft&&i.view?.scrollTop===a.view?.scrollTop)return;this.#he(r,n,i,a.completion);return}this.#he(r,n,i)}#he(e,t,n,r){let i=this.#s.get(t);if(r!==void 0||i!==void 0){let a=r??Promise.resolve();i!==void 0&&(a=a.then(()=>i)),this.#ge(t,a.then(()=>e.set(t,n)));return}let a;try{a=e.set(t,n)}catch{return}eh(a)&&this.#ge(t,a)}#ge(e,t){let n=t.catch(()=>{});this.#s.set(e,n),n.finally(()=>{this.#s.get(e)===n&&this.#s.delete(e)})}#_e(e,t){let n=++this.#l,r=t.version,i=this.#ne,a=this.getState().view,o,s=s=>{let c=this.getState().view;if(n!==this.#l||this.#L!==t||t.version!==r||this.#ne!==i||c?.scrollLeft!==a?.scrollLeft||this.#F===void 0||$m(this.#F)!==e)return;let l=o?.userScrolled()===!0;if(s===void 0){this.#P?.setCodeScrollLeft(0),l||this.#Me(0);return}let u=Am(s);l&&u.view!==void 0&&(u.view={scrollLeft:u.view.scrollLeft}),this.setState(u)},c=()=>{let t;try{t=this.#pe().get(e)}catch{return}if(eh(t))return t.then(s).catch(()=>{});try{s(t)}catch{}},l=this.#s.get(e),u=l===void 0?c():l.then(c);if(eh(u)){o=this.#ve();let n={cacheKey:e,textDocument:t,documentVersion:r,selections:i,view:a,completion:u.catch(()=>{})};this.#c=n,n.completion.finally(()=>{o?.dispose(),this.#c===n&&(this.#c=void 0)})}}#ve(){let e=this.#Ae();if(!(e instanceof HTMLElement))return;let t=!1,n=[`wheel`,`touchstart`,`mousedown`],r=()=>{for(let t of n)e.removeEventListener(t,i,{capture:!0})},i=()=>{t=!0,r()};for(let t of n)e.addEventListener(t,i,{capture:!0,passive:!0});return{userScrolled:()=>t,dispose:r}}#ye(e){return this.#P?.isLineRenderable?.(e+1)??!0}get#be(){let e=this.#P;if(e?.getNearestRenderableLine!=null)return(t,n)=>{let r=e.getNearestRenderableLine(t+1,n);return r==null?void 0:r-1}}#xe(e){this.#ye(e)||this.#P?.revealLine?.(e+1)}get#Se(){return this.#P?.options.diffStyle??`split`}get#Ce(){return this.#P?.type===`file-diff`}get#we(){return this.#P?.options.overflow===`wrap`}#Te(){return this.#r??=new Ff({hasActivePopover:()=>this.#H!==void 0||this.#B?.isPopoverVisible()===!0,updateActivePopover:()=>{this.#St(),this.#B?.updatePopoverPosition()}})}#Ee(){this.#y.clear(),this.#x.clear(),this.#S=void 0}#De(){this.#mt(null),this.#_=void 0,this.#v=void 0,this.#W=!1,this.#G=!1,this.#j?.forEach(e=>e.remove()),this.#j=void 0,this.#ne=void 0,this.#ee=void 0,this.#ie=void 0,this.#B?.cleanup(),this.#B=void 0,this.#V?.cleanup(),this.#V=void 0,this.#H?.cleanup(),this.#H=void 0,this.#U=!0}#Oe(){let e=this.#h;e.generation++,e.callback!=null&&(gi(e.callback),e.callback=void 0)}#ke(e){let t=this.#h,n=this.#L;if(t.delivered||t.callback!=null||n==null)return;let{generation:r}=t,i=()=>{if(t.callback!==i||(t.callback=void 0,r!==t.generation||this.#P!==e||this.#L!==n))return;let a=this.#k,o=this.#D?.shadowRoot;a==null||o==null||!o.contains(a)||(t.delivered=!0,this.#e.onAttach?.(this,e))};t.callback=i,hi(i)}#Ae(){let e=this.#P?.getEditorViewport?.();if(e!==void 0)return e;let t=this.#D;if(this.#P!=null&&t!=null)return Sf(t)}#je(){let e=this.#Ae();return e instanceof HTMLElement?e.scrollTop:e?.defaultView?.scrollY??0}#Me(e){let t=this.#Ae();t instanceof HTMLElement?t.scrollTop=e:t instanceof Document&&t.defaultView?.scrollTo({top:e})}#Ne(){this.#C=Z(`style`,{dataset:`editorGlobalCss`,textContent:`
1946
1946
  [data-annotation-slot] {
1947
1947
  user-select: none;
1948
1948
  -webkit-user-select: none;
@@ -2005,5 +2005,5 @@ diff --git`)}function ia(e,t){if(e.length===0)return[``];let n=`\n${t}`,r=e.star
2005
2005
  margin-left: auto;
2006
2006
  }
2007
2007
  }
2008
- `;function zh(e,t){let n=Math.max(Fh,Math.floor(t*Lh));return Math.max(Fh,Math.min(e,n))}function Bh(e,t,n){let r=e.startX-n;return zh(e.startWidth+r,t)}function Vh(e){if(!e)return!1;let t=e.toLowerCase();return t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`file not found`)||t.includes(`cannot find the file`)}function Hh(e,t){return`preview:${e}:${t.length}:${Ft(t).toString(36)}`}var Uh=[];function Wh(e){let t=(0,Y.c)(24),[n,r]=(0,J.useState)(e.open),i,a;t[0]===e.open?(i=t[1],a=t[2]):(i=()=>{if(!e.open){r(!1);return}let t=window.requestAnimationFrame(()=>r(!0));return()=>window.cancelAnimationFrame(t)},a=[e.open],t[0]=e.open,t[1]=i,t[2]=a),(0,J.useEffect)(i,a);let o=e.open&&n,s=!e.open||void 0,c=!e.open||void 0,l=e.open?`border-l border-border/70`:`border-l-0`,u=e.resizing?`transition-none`:`transition-[width,opacity] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none`,d=e.open?`opacity-100`:`opacity-0`,f;t[3]!==l||t[4]!==u||t[5]!==d?(f=F(`min-h-0 shrink-0 overflow-hidden bg-card/20`,l,u,d),t[3]=l,t[4]=u,t[5]=d,t[6]=f):f=t[6];let p=e.open?`${e.width}px`:`0px`,m;t[7]===p?m=t[8]:(m={width:p,maxWidth:`55%`},t[7]=p,t[8]=m);let h=e.resizing?`transition-none`:null,g=o?`translate-x-0 opacity-100`:`translate-x-4 opacity-0`,_;t[9]!==h||t[10]!==g?(_=F(`h-full min-h-0 transition-[translate,opacity] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] will-change-transform motion-reduce:transition-none`,h,g),t[9]=h,t[10]=g,t[11]=_):_=t[11];let v=`${e.width}px`,y;t[12]===v?y=t[13]:(y={width:v,maxWidth:`100%`},t[12]=v,t[13]=y);let b;t[14]!==e.children||t[15]!==_||t[16]!==y?(b=(0,X.jsx)(`div`,{className:_,style:y,children:e.children}),t[14]=e.children,t[15]=_,t[16]=y,t[17]=b):b=t[17];let x;return t[18]!==b||t[19]!==s||t[20]!==c||t[21]!==f||t[22]!==m?(x=(0,X.jsx)(`div`,{"data-preview-file-rail":!0,"aria-hidden":s,inert:c,className:f,style:m,children:b}),t[18]=b,t[19]=s,t[20]=c,t[21]=f,t[22]=m,t[23]=x):x=t[23],x}function Gh(){let e=(0,Y.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(W,{className:`size-8 text-muted-foreground/65`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center`,children:(0,X.jsxs)(`div`,{className:`flex max-w-xs flex-col items-center gap-3`,children:[t,(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground`,children:`Open file`}),(0,X.jsx)(`div`,{className:`text-xs leading-5 text-muted-foreground/70`,children:`Select a file from the workspace tree.`})]})]})}),e[1]=n):n=e[1],n}function Kh({mode:e=`inline`}){let{resolvedTheme:t}=ir(),n=g(),r=e===`phone`,i=ie({strict:!1,select:e=>ae(e)}),a=ie({strict:!1,select:e=>typeof e.draftId==`string`?ee.make(e.draftId):null}),o=se({strict:!1,select:e=>ue(e)}),c=f((0,J.useMemo)(()=>p(i),[i])),l=te(e=>c?null:a?e.getDraftSession(a):i?e.getDraftThreadByRef(i):null),u=(0,J.useMemo)(()=>{if(c)return{id:c.id,environmentId:c.environmentId,projectId:c.projectId,worktreePath:c.worktreePath,turnDiffSummaries:c.turnDiffSummaries};if(l)return{id:l.threadId,environmentId:l.environmentId,projectId:l.projectId,worktreePath:l.worktreePath,turnDiffSummaries:Uh}},[c,l]),d=u?.projectId??null,h=f(e=>u&&d?m(e,{environmentId:u.environmentId,projectId:d}):void 0),_=u?.worktreePath??h?.cwd??null,[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),S=(0,J.useRef)(null),[C,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(``),[O,k]=(0,J.useState)(!0),[A,j]=(0,J.useState)(r?!0:n.diffWordWrap),P=(0,J.useRef)(null),[ne,re]=(0,J.useState)(()=>typeof window>`u`?Ih:M(Ph,s)??Ih),[oe,I]=(0,J.useState)(!1),ce=(0,J.useRef)(null),le=(0,J.useRef)(o.preview===`1`),de=(0,J.useRef)(null),fe=(0,J.useRef)(null),pe=(0,J.useRef)(null),L=(0,J.useCallback)(e=>{S.current=e,x(e)},[]);(0,J.useEffect)(()=>{j(r?!0:n.diffWordWrap)},[r,n.diffWordWrap]),(0,J.useEffect)(()=>{y(null),L(null),T(null),k(!0)},[u?.environmentId,u?.id,L]);let R=(0,J.useMemo)(()=>{let e=(u?.turnDiffSummaries??[]).toReversed().find(e=>e.files.length>0);return e?`${e.turnId}:${e.completedAt}`:null},[u?.turnDiffSummaries]),me=(0,J.useMemo)(()=>{if(!v)return null;let e=(u?.turnDiffSummaries??[]).toReversed().find(e=>e.files.some(e=>e.path===v));return e?`${e.turnId}:${e.completedAt}`:null},[u?.turnDiffSummaries,v]),z=ad({environmentId:u?.environmentId??null,cwd:_,enabled:!!(u?.environmentId&&_&&o.preview===`1`)}),he=z.error instanceof Error?z.error.message:z.error?`Failed to load the workspace tree.`:null,ge=z.data,_e=z.data?.truncated===!0,ve=z.isFetching,B=z.refetch,be=(0,J.useMemo)(()=>Nh(ge?.entries??[],E),[E,ge?.entries]),xe=E.trim().length>0;(0,J.useEffect)(()=>{if(ge){if(ge.entries.length===0){dh(S.current)||(y(null),L(null));return}v&&!ge.entries.some(e=>e.path===v)&&(dh(S.current)||(y(null),L(null)))}},[L,ge,v]),(0,J.useEffect)(()=>{if(o.preview!==`1`){de.current=R;return}if(de.current===null){de.current=R;return}de.current!==R&&(de.current=R,B())},[R,o.preview,B]),(0,J.useEffect)(()=>{let e=o.preview===`1`;e&&!le.current&&y(null),le.current=e},[o.preview]);let Se=v?ge?.entries.find(e=>e.path===v):void 0,Ce=typeof Se?.sizeBytes==`number`?Oh(Se.sizeBytes):null,we=cd({environmentId:u?.environmentId??null,cwd:_,relativePath:v,enabled:!!(u?.environmentId&&_&&v&&o.preview===`1`&&(Ce?.shouldFetch??!0))}),Te=we.data?.relativePath===v?we.data:null,Ee=Te,H=Ee?.mimeType??Se?.mimeType??null,U=v?Dh({filePath:v,mimeType:H}):`text`,Oe=we.error instanceof Error?we.error.message:we.error?`Failed to load file preview.`:null,ke=we.refetch;(0,J.useEffect)(()=>{if(!v||o.preview!==`1`){fe.current=me;return}if(fe.current===null){fe.current=me;return}fe.current!==me&&(fe.current=me,ke())},[me,o.preview,ke,v]),(0,J.useEffect)(()=>{if(!v||!Vh(Oe)){pe.current=null;return}let e=`${_??``}\u0000${v}\u0000${Oe}`;pe.current!==e&&(pe.current=e,B().then(e=>{if(!e.data?.entries.some(e=>e.path===v)){let e=S.current;e?.relativePath===v&&dh(e)?L(hh(e,{reason:`deleted`,message:`This file was removed from disk after it was opened. Explorer will not recreate it.`})):(y(e=>e===v?null:e),e?.relativePath===v&&L(null))}}).catch(()=>void 0))},[_,L,B,Oe,v]);let W=(0,J.useMemo)(()=>!u?.environmentId||!_||!Te||Te.relativePath!==v?null:lh({environmentId:u.environmentId,cwd:_},Te),[_,u?.environmentId,Te,v]);(0,J.useEffect)(()=>{W&&L(_h(S.current,W))},[L,W]);let G=W&&b?.key===W.key?b:null,Ae=dh(G),je=!!(!r&&U===`text`&&W&&W.lineEnding!==`mixed`),Me=lr({shouldBlockFn:(0,J.useCallback)(()=>Ae,[Ae]),disabled:!Ae,enableBeforeUnload:Ae,withResolver:!0}),Ne=(0,J.useCallback)(e=>{L(null),y(e)},[L]),Pe=(0,J.useCallback)(e=>{if(e!==v){if(dh(S.current)){T(e);return}Ne(e)}},[Ne,v]),Fe=(0,J.useCallback)(e=>{let t=S.current;!t||t.key!==W?.key||L(fh(t,e))},[L,W?.key]),Ie=(0,J.useCallback)(async()=>{if(!u?.environmentId||!_||!v)return!1;try{let e=await w(u.environmentId).projects.readFile({cwd:_,relativePath:v});return id({environmentId:u.environmentId,cwd:_,relativePath:v},e),L(uh(lh({environmentId:u.environmentId,cwd:_},e))),!0}catch(e){let t=S.current;return t&&L(hh(t,{reason:Vh(e instanceof Error?e.message:String(e))?`deleted`:`failed`,message:e instanceof Error?e.message:`Failed to reload this file.`})),!1}},[_,u?.environmentId,L,v]),Le=(0,J.useCallback)(()=>{let e=S.current;if(!(!e||e.key!==W?.key)){if(e.errorReason===`deleted`){L(null),y(null),B();return}if(e.saveStatus===`conflict`){Ie();return}L(gh(e))}},[L,B,Ie,W?.key]),Re=(0,J.useCallback)(async()=>{let e=S.current;if(!e||!u?.environmentId||!_||e.relativePath!==v||e.lineEnding===`mixed`||e.saveStatus===`saving`||e.saveStatus===`conflict`||!dh(e))return!1;let t=e.key,n=e.contents;L(ph(e));try{let r=await w(u.environmentId).projects.writeFile({cwd:_,relativePath:e.relativePath,contents:n,expectedVersion:e.version,encoding:e.encoding,lineEnding:e.lineEnding});id({environmentId:u.environmentId,cwd:_,relativePath:e.relativePath},{relativePath:e.relativePath,contents:n,version:r.version,encoding:e.encoding,lineEnding:e.lineEnding});let i=S.current;if(!i||i.key!==t)return!1;let a=mh(i,n,r.version);return L(a),!dh(a)}catch(e){let n=S.current;return n?.key===t&&L(hh(n,vh(e))),!1}},[_,u?.environmentId,L,v]),ze=G?.saveStatus===`conflict`||G?.errorReason===`unsupported`,K=!!(je&&Ae&&G?.saveStatus!==`saving`&&!ze);(0,J.useEffect)(()=>{if(!je||!Ae)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),K&&Re())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[K,Ae,je,Re]);let Be=(0,J.useMemo)(()=>{let e=Ee?.contents;return!v||U!==`text`||e===void 0?null:{name:v,contents:e,lang:Eh(v),cacheKey:Hh(v,e)}},[Ee?.contents,U,v]),Ve=(0,J.useMemo)(()=>({disableFileHeader:!0,overflow:A?`wrap`:`scroll`,theme:Nt(t),themeType:t,unsafeCSS:ch,tokenizeMaxLineLength:1e3}),[t,A]),He=(0,J.useCallback)(e=>{if(e.button!==0||!O)return;let t=P.current?.querySelector(`[data-preview-file-rail]`)?.getBoundingClientRect().width??ne;ce.current={pointerId:e.pointerId,startWidth:t,startX:e.clientX},e.currentTarget.setPointerCapture(e.pointerId),I(!0),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`},[O,ne]),Ue=(0,J.useCallback)(e=>{let t=ce.current,n=P.current;if(!t||!n||t.pointerId!==e.pointerId)return;e.preventDefault();let r=Bh(t,n.clientWidth,e.clientX);re(r)},[]),We=(0,J.useCallback)(e=>{let t=ce.current;if(!t||t.pointerId!==e.pointerId)return;let n=P.current,r=n?Bh(t,n.clientWidth,e.clientX):t.startWidth;ce.current=null,I(!1),re(r),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`),typeof window<`u`&&N(Ph,r,s)},[]);(0,J.useEffect)(()=>()=>{document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)},[]);let Ge=(0,J.useCallback)(()=>{B()},[B]),Ke=(0,J.useCallback)(()=>{O&&(ce.current=null,I(!1),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)),k(e=>!e)},[O]),qe=C!==null||Me.status===`blocked`,Je=(0,J.useCallback)(()=>{T(null),Me.status===`blocked`&&Me.reset()},[Me]),Ye=(0,J.useCallback)(()=>{let e=C;if(T(null),L(null),e){y(e);return}Me.status===`blocked`&&Me.proceed()},[L,Me,C]),Xe=(0,J.useCallback)(async()=>{await Re()&&Ye()},[Ye,Re]),Ze=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 px-1 [-webkit-app-region:no-drag]`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:`File Preview`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65`,children:[(0,X.jsx)(`span`,{children:`Workspace tree`}),_e?(0,X.jsx)(rr,{variant:`warning`,size:`sm`,className:`rounded-md px-1.5 py-0 text-[9px]`,children:`Truncated`}):null]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[r?null:(0,X.jsx)(Un,{"aria-label":O?`Hide workspace tree`:`Show workspace tree`,"aria-pressed":O,title:O?`Hide workspace tree`:`Show workspace tree`,variant:`outline`,size:`icon-xs`,className:`shrink-0`,onClick:Ke,children:O?(0,X.jsx)(xr,{className:`size-3`}):(0,X.jsx)(Sr,{className:`size-3`})}),(0,X.jsx)(Un,{"aria-label":`Refresh workspace tree`,title:`Refresh workspace tree`,variant:`outline`,size:`icon-xs`,className:`shrink-0`,disabled:!u?.environmentId||!_||ve,onClick:Ge,children:(0,X.jsx)(yn,{className:F(`size-3`,ve&&`animate-spin`)})}),(0,X.jsx)(sr,{"aria-label":A?`Disable preview line wrapping`:`Enable preview line wrapping`,title:A?`Disable line wrapping`:`Enable line wrapping`,variant:`outline`,size:`xs`,pressed:A,onPressedChange:e=>{j(!!e)},children:(0,X.jsx)(Er,{className:`size-3`})})]})]}),Qe=Ce?.state===`too-large`?(0,X.jsxs)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:[`File is too large to preview (`,Ce.sizeBytes,` bytes). Limit is`,` `,Ce.limitBytes,` bytes.`]}):we.isLoading&&!Te?(0,X.jsx)(an,{label:`Loading file preview...`}):Oe&&!Te?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:Oe}):(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 p-2`,children:[(0,X.jsx)(`style`,{children:Rh}),(0,X.jsxs)(`div`,{className:`preview-panel-file-card flex h-full min-h-0 flex-col overflow-hidden rounded-md border border-border/70 bg-[color:color-mix(in_srgb,var(--card)_90%,var(--background))]`,children:[(0,X.jsxs)(`div`,{className:`preview-panel-file-toolbar flex min-h-10 shrink-0 items-center gap-3 border-b border-border/70 bg-[color:color-mix(in_srgb,var(--card)_94%,var(--foreground))] px-3 py-1.5 text-foreground`,children:[(0,X.jsxs)(`div`,{className:`preview-panel-file-identity flex min-w-0 flex-1 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-[12px] font-medium`,children:v}),Ae?(0,X.jsx)(`span`,{"aria-label":`Unsaved changes`,className:`size-1.5 shrink-0 rounded-full bg-primary`,title:`Unsaved changes`}):null,G?.saveStatus===`saving`?(0,X.jsxs)(`span`,{"aria-live":`polite`,className:`flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(V,{className:`size-3 animate-spin`}),` Saving`]}):null,!r&&W?.lineEnding===`mixed`?(0,X.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:`Read-only · mixed line endings`}):null]}),je&&G?(0,X.jsxs)(`div`,{className:`preview-panel-file-actions flex shrink-0 items-center gap-1`,children:[(0,X.jsx)(Un,{"aria-label":`Discard file changes`,disabled:!Ae||G.saveStatus===`saving`,onClick:Le,size:`xs`,variant:`ghost`,children:`Discard`}),(0,X.jsxs)(Un,{"aria-label":`Save file`,disabled:!K,onClick:()=>void Re(),size:`xs`,title:`Save file (Ctrl/⌘ S)`,children:[G.saveStatus===`saving`?(0,X.jsx)(V,{className:`animate-spin`}):(0,X.jsx)(bn,{}),`Save`,(0,X.jsx)(`span`,{className:`ml-0.5 text-[9px] opacity-70`,children:`⌘S`})]})]}):null]}),G?.errorMessage?(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/60 p-2`,children:(0,X.jsxs)(qn,{variant:G.saveStatus===`conflict`?`warning`:`error`,className:`rounded-lg px-3 py-2 text-[11px]`,children:[G.saveStatus===`conflict`?(0,X.jsx)(En,{className:`size-3.5`}):(0,X.jsx)(De,{className:`size-3.5`}),(0,X.jsx)(Gn,{className:`text-[11px]`,children:G.errorReason===`deleted`?`File removed on disk`:G.saveStatus===`conflict`?`File changed on disk`:`Couldn’t save file`}),(0,X.jsxs)(Kn,{className:`gap-2 text-[11px] leading-4`,children:[(0,X.jsx)(`span`,{children:G.errorMessage}),G.saveStatus===`conflict`?(0,X.jsx)(Un,{className:`self-start`,onClick:G.errorReason===`deleted`?Le:()=>void Ie(),size:`xs`,variant:`outline`,children:G.errorReason===`deleted`?`Close file`:`Reload`}):null]})]})}):Oe?(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 px-3 py-2 text-[11px] text-destructive`,children:[`Refresh failed: `,Oe]}):null,U===`image`&&Ee?.base64?(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 justify-center overflow-auto bg-background/70 p-3`,children:(0,X.jsx)(`img`,{alt:v??void 0,className:`max-h-full max-w-full object-contain`,src:`data:${H??`image/png`};base64,${Ee.base64}`})}):je&&G?(0,X.jsx)(oh,{cacheKey:G.key,className:`preview-panel-diffs-file`,contents:G.contents,filePath:G.relativePath,language:Eh(G.relativePath),onChange:Fe,options:Ve}):Be?(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,X.jsx)(zl,{file:Be,className:`preview-panel-diffs-file`,options:Ve})}):(0,X.jsx)(`pre`,{className:F(`min-h-0 flex-1 bg-transparent p-3 font-mono text-[11px] leading-5 text-muted-foreground/90`,A?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:Ee?.contents??``})]})]}),$e=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/60 p-2`,children:(0,X.jsxs)(`label`,{className:`relative block`,children:[(0,X.jsx)(xn,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground/65`}),(0,X.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(D(``),e.currentTarget.blur())},placeholder:`Filter files...`,"aria-label":`Filter files`,className:`h-8 w-full rounded-md border border-border/70 bg-background/65 pl-8 pr-3 text-xs text-foreground outline-none transition-[border-color,background-color,box-shadow] placeholder:text-muted-foreground/55 focus:border-ring/60 focus:bg-background focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_18%,transparent)]`})]})}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[he||_e?(0,X.jsxs)(qn,{variant:he?`error`:`warning`,className:`mb-2 rounded-lg border-border/70 px-3 py-2 text-[11px]`,children:[he?(0,X.jsx)(De,{className:`size-3.5`}):(0,X.jsx)(En,{className:`size-3.5`}),(0,X.jsx)(Gn,{className:`text-[11px]`,children:he?`Workspace tree refresh failed`:`Workspace tree is truncated`}),(0,X.jsx)(Kn,{className:`gap-1 text-[11px] leading-4`,children:he?(0,X.jsx)(`span`,{children:he}):(0,X.jsx)(`span`,{children:`Only the first indexed workspace entries are shown here, so some files may be omitted from preview.`})})]}):null,be.length===0?(0,X.jsx)(`div`,{className:`px-2 py-6 text-center text-xs leading-5 text-muted-foreground/70`,children:`No files match this filter.`}):(0,X.jsx)(ud,{files:be,allDirectoriesExpanded:xe,resolvedTheme:t,onSelectFile:Pe,selectedFilePath:v,showStats:!1})]})]});return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Et,{mode:e,header:Ze,children:u?z.isLoading&&!z.data?(0,X.jsx)(an,{label:`Loading project tree...`}):he&&!z.data?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:he}):(z.data?.entries.length??0)===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No project files available yet.`}):r?(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:v?(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,X.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center gap-1 border-b border-border/60 px-1.5`,children:[(0,X.jsx)(Un,{size:`icon`,variant:`ghost`,"aria-label":`Back to workspace tree`,className:`shrink-0`,onClick:()=>y(null),children:(0,X.jsx)(ye,{})}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:v})]}),Qe]}):$e}):(0,X.jsxs)(`div`,{ref:P,className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(`div`,{"data-preview-content-panel":!0,className:`flex min-h-0 min-w-0 flex-1 flex-col transition-[min-width] duration-[320ms] ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none`,children:v?Qe:(0,X.jsx)(Gh,{})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":`Resize workspace tree`,"aria-hidden":!O||void 0,className:F(`group relative shrink-0 overflow-hidden bg-background transition-[width,opacity,background-color] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] hover:bg-accent/40 motion-reduce:transition-none`,O?`w-2 cursor-ew-resize opacity-100`:`w-0 opacity-0`),disabled:!O,onPointerDown:He,onPointerMove:Ue,onPointerUp:We,onPointerCancel:We,children:(0,X.jsx)(`span`,{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border/80 group-hover:bg-border`})}),(0,X.jsx)(Wh,{width:ne,open:O,resizing:oe,children:$e})]}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to preview files.`})}),(0,X.jsx)(tr,{open:qe,onOpenChange:e=>{e||Je()},children:(0,X.jsxs)(Qn,{children:[(0,X.jsxs)(Xn,{children:[(0,X.jsx)(er,{children:`Save changes before continuing?`}),(0,X.jsx)($n,{children:v?`${v} has unsaved changes.`:`This file has unsaved changes.`})]}),(0,X.jsxs)(Zn,{children:[(0,X.jsx)(Un,{onClick:Je,variant:`outline`,children:`Cancel`}),(0,X.jsx)(Un,{disabled:G?.saveStatus===`saving`,onClick:Ye,variant:`destructive-outline`,children:C?`Discard & Open`:`Discard & Continue`}),(0,X.jsxs)(Un,{disabled:!K,onClick:()=>void Xe(),children:[G?.saveStatus===`saving`?(0,X.jsx)(V,{className:`animate-spin`}):(0,X.jsx)(bn,{}),C?`Save & Open`:`Save & Continue`]})]})]})})]})}function qh(){return{phase:`awaiting-config`,lastSequence:null}}var Jh=2**32,Yh=1024;function Xh(e,t,n){if(t.deviceId!==n)return{state:e,action:{kind:`ignore`},requestKeyframe:!1};if(t.codecConfig)return{state:{phase:`awaiting-keyframe`,lastSequence:t.sequence},action:{kind:`configure`},requestKeyframe:!1};if(e.phase===`awaiting-config`)return{state:e,action:{kind:`drop`},requestKeyframe:!1};if(e.lastSequence!==null){let n=(t.sequence-e.lastSequence+Jh)%Jh;if(n===0||n>Yh)return{state:e,action:{kind:`drop`},requestKeyframe:!1};if(n>1&&!t.keyframe&&e.phase===`streaming`)return{state:{phase:`awaiting-keyframe`,lastSequence:t.sequence},action:{kind:`drop`},requestKeyframe:!0}}return e.phase===`awaiting-keyframe`&&!t.keyframe?{state:{...e,lastSequence:t.sequence},action:{kind:`drop`},requestKeyframe:!1}:{state:{phase:`streaming`,lastSequence:t.sequence},action:{kind:`decode`,keyframe:t.keyframe},requestKeyframe:!1}}function Zh(e,t,n){let r=Math.min(e.displayWidth/e.frameWidth,e.displayHeight/e.frameHeight);if(!Number.isFinite(r)||r<=0)return null;let i=e.frameWidth*r,a=e.frameHeight*r,o=t-(e.displayWidth-i)/2,s=n-(e.displayHeight-a)/2;return o<0||s<0||o>i||s>a?null:{x:Math.round(o/i*e.pointWidth),y:Math.round(s/a*e.pointHeight)}}function Qh(e){let t={Enter:40,Escape:41,Backspace:42,Tab:43," ":44,ArrowRight:79,ArrowLeft:80,ArrowDown:81,ArrowUp:82},n=e.toLowerCase();return n>=`a`&&n<=`z`&&n.length===1?4+n.charCodeAt(0)-97:n===`0`?39:n>=`1`&&n<=`9`&&n.length===1?30+n.charCodeAt(0)-49:t[e]??null}function $h(e){for(let t=0;t+7<e.byteLength;t+=1){let n=e[t]===0&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1,r=e[t]===0&&e[t+1]===0&&e[t+2]===1;if(!n&&!r)continue;let i=t+(n?4:3);if(((e[i]??0)&31)==7)return`avc1.${[e[i+1],e[i+2],e[i+3]].map(e=>(e??0).toString(16).padStart(2,`0`)).join(``)}`}return null}function eg(e){let{canvasRef:t,udid:n,openFrameSource:r}=e,[i,a]=(0,J.useState)(`idle`),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(null),u=(0,J.useRef)(0);return(0,J.useEffect)(()=>{if(!n||!r){a(`idle`),s(null);return}if(typeof globalThis.VideoDecoder!=`function`||typeof globalThis.EncodedVideoChunk!=`function`){a(`unsupported`);return}let e=++u.current,i=qh(),o=null,c=null,d=null,f=()=>e===u.current;a(`connecting`),s(null);let p=()=>{d=null;try{o?.state!==`closed`&&o?.close()}catch{}o=null},m=e=>{f()&&(p(),i=qh(),s(e),a(`error`))},h=e=>{let n=$h(e.payload);if(!n){m(`The simulator sent video parameters Ryco could not read.`),c?.requestResync();return}p();let r=new VideoDecoder({output:e=>{try{if(!f())return;let n=t.current;if(!n)return;(n.width!==e.displayWidth||n.height!==e.displayHeight)&&(n.width=e.displayWidth,n.height=e.displayHeight,l({width:e.displayWidth,height:e.displayHeight})),n.getContext(`2d`)?.drawImage(e,0,0),a(`streaming`),s(null)}finally{e.close()}},error:e=>{m(e.message||`The simulator video decoder failed.`),c?.requestResync()}});try{r.configure({codec:n,optimizeForLatency:!0}),o=r,d=e.payload.slice()}catch(e){m(e instanceof Error?e.message:`Video decoder setup failed.`)}},g=(e,t)=>{if(!o||o.state!==`configured`)return;let n=e.payload;if(t&&d){let e=new Uint8Array(d.byteLength+n.byteLength);e.set(d),e.set(n,d.byteLength),n=e,d=null}try{o.decode(new EncodedVideoChunk({type:t?`key`:`delta`,timestamp:Math.round(e.header.timestampMs*1e3),data:n}))}catch(e){m(e instanceof Error?e.message:`A simulator frame could not be decoded.`),c?.requestResync()}};return c=r(n,{onFrame:e=>{if(!f())return;let t=Xh(i,e.header,n);i=t.state,t.requestKeyframe&&c?.requestResync(),t.action.kind===`configure`&&h(e),t.action.kind===`decode`&&g(e,t.action.keyframe)},onReset:e=>{f()&&(p(),i=qh(),e===`decode-failed`&&s(`The simulator sent a malformed frame.`),a(`recovering`))}}),()=>{u.current+=1,c?.close(),p()}},[t,r,n]),{status:i,error:o,dimensions:c}}var tg=750,ng=524288,rg=15e3;function ig(e){let t=Math.ceil(Math.max(0,e)/ng*1e3);return Math.min(rg,Math.max(tg,t))}function ag(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n}function og(e){let t=ag(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}function sg(e){let{canvasRef:t,enabled:n,screenshot:r,udid:i}=e,[a,o]=(0,J.useState)(`idle`),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null);return(0,J.useEffect)(()=>{if(!n||!i||!r){o(`idle`),c(null);return}let e=!0,a=null,s=document.visibilityState!==`hidden`,l=!0,d=!1;o(`connecting`);let f=()=>{a!==null&&(clearTimeout(a),a=null)},p=()=>e&&s&&l,m=e=>{f(),!(!p()||d)&&(a=setTimeout(()=>{a=null,h()},e))},h=async()=>{if(!p()||d)return;d=!0;let n=tg;try{let e=await r({udid:i});if(n=ig(e.bytesBase64.length),!p())return;let a=await createImageBitmap(new Blob([og(e.bytesBase64)],{type:e.mimeType}));try{if(!p())return;let e=t.current;if(!e)return;(e.width!==a.width||e.height!==a.height)&&(e.width=a.width,e.height=a.height,u({width:a.width,height:a.height})),e.getContext(`2d`)?.drawImage(a,0,0),o(`streaming`),c(null)}finally{a.close()}}catch(t){if(!e)return;o(`recovering`),c(t instanceof Error?t.message:`The hosted simulator preview disconnected.`)}finally{d=!1,p()&&m(n)}},g=()=>{s=document.visibilityState!==`hidden`,s?m(0):f()};document.addEventListener(`visibilitychange`,g);let _=t.current,v=_&&typeof IntersectionObserver==`function`?new IntersectionObserver(e=>{l=e.some(e=>e.isIntersecting),l?m(0):f()}):null;return v?.observe(_),m(0),()=>{e=!1,f(),v?.disconnect(),document.removeEventListener(`visibilitychange`,g)}},[t,n,r,i]),{status:a,error:s,dimensions:l}}var cg=5e3;function lg(e,t){return e instanceof Error&&e.message.trim()?e.message:t}function ug(e){return e===`booted`?`Booted`:e===`booting`?`Booting`:e===`shutting-down`?`Shutting down`:`Shut down`}function dg(e,t){return t===`waiting-for-display`?`Waiting for the display…`:t===`connecting`?`Connecting the live screen…`:t===`booting`||e.state===`booting`?`Starting the simulator…`:`Connecting…`}function fg(e){let t=[];return e.metaKey&&t.push(`command`),e.shiftKey&&t.push(`shift`),e.altKey&&t.push(`option`),e.ctrlKey&&t.push(`control`),t}function pg(e){let t=(0,Y.c)(15),n=e.availability;if(!n){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,X.jsx)(V,{className:`size-5 animate-spin text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Checking simulator support…`})]}),t[0]=e):e=t[0],e}if(n.kind===`unsupported-platform`){let e,r;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsx)(br,{className:`size-7 text-muted-foreground`}),r=(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`iOS Simulator needs a Mac`}),t[1]=e,t[2]=r):(e=t[1],r=t[2]);let i;return t[3]===n.platform?i=t[4]:(i=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[e,r,(0,X.jsxs)(`p`,{className:`mt-1 max-w-sm text-xs leading-relaxed text-muted-foreground`,children:[`This environment runs on `,n.platform,`. Connect Ryco to a macOS environment with Xcode to use the simulator workspace.`]})]}),t[3]=n.platform,t[4]=i),i}if(n.kind===`helper-unavailable`){let e,r;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsx)(br,{className:`size-7 text-amber-500`}),r=(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Simulator helper could not start`}),t[5]=e,t[6]=r):(e=t[5],r=t[6]);let i;return t[7]===n.message?i=t[8]:(i=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[e,r,(0,X.jsx)(`p`,{className:`mt-1 max-w-sm text-xs leading-relaxed text-muted-foreground`,children:n.message})]}),t[7]=n.message,t[8]=i),i}if(n.kind!==`setup-required`||n.steps.filter(gg).every(hg))return null;let r,i;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`Set up the iOS Simulator`}),i=(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Ryco checks these steps automatically every few seconds.`}),t[9]=r,t[10]=i):(r=t[9],i=t[10]);let a;t[11]===n.steps?a=t[12]:(a=n.steps.map(mg),t[11]=n.steps,t[12]=a);let o;return t[13]===a?o=t[14]:(o=(0,X.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-md`,children:[r,i,(0,X.jsx)(`div`,{className:`mt-5 space-y-2`,children:a})]})}),t[13]=a,t[14]=o),o}function mg(e){return(0,X.jsxs)(`div`,{className:`flex gap-3 rounded-md border border-border/60 p-3`,children:[(0,X.jsx)(`span`,{className:F(`mt-0.5 size-2 shrink-0 rounded-full`,e.done?`bg-emerald-500`:`bg-amber-500`)}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:e.label}),e.detail?(0,X.jsx)(`p`,{className:`mt-1 break-words font-mono text-[10px] text-muted-foreground`,children:e.detail}):null]})]},e.id)}function hg(e){return e.id===`build-device-helper`}function gg(e){return!e.done}function _g(e){let{environmentId:t,threadId:n}=e,i=(0,J.useRef)(null),a=(0,J.useMemo)(()=>t&&n?o(r(t,n)):null,[t,n]),s=O(e=>t?e.environmentById[t]:void 0),c=O(e=>a?e.threadByKey[a]:void 0),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)({kind:`idle`}),[h,g]=(0,J.useState)(null),_=t?C(t)?.device:void 0,v=t?S(t)?.client.device:void 0,y=s?.generation??0,b=O(e=>e.applyThreadSnapshot),x=O(e=>e.applyInventory),w=(0,J.useCallback)(async()=>{if(!t||!n||!_)return;let[e,r]=await Promise.all([_.list({includeShutdown:!0}),_.getThreadState({threadId:n})]);x(t,y,e.devices,e.availability),b(t,y,r)},[_,x,b,t,y,n]),T=s?.availability?.kind===`setup-required`||s?.availability?.kind===`helper-unavailable`;(0,J.useEffect)(()=>{if(w().catch(()=>void 0),!T)return;let e=setInterval(()=>void w().catch(()=>void 0),cg);return()=>clearInterval(e)},[T,w]);let E=s?.devices??c?.devices??[],D=E.find(e=>e.udid===c?.attachedDeviceUdid)??E.find(e=>e.udid===d)??null;(0,J.useEffect)(()=>{d&&c?.attachedDeviceUdid===d&&f(null)},[d,c?.attachedDeviceUdid]);let k=(0,J.useCallback)(async(e,t)=>{u(!0);try{await e()}catch(e){H.add({type:`error`,title:t,description:lg(e,`The simulator did not respond.`)})}finally{u(!1)}},[]),A=(0,J.useCallback)(e=>{!_||!n||(f(e.udid),k(async()=>{if(e.state===`shutdown`){let t=await _.boot({udid:e.udid});if(t.kind===`boot-limit-reached`){f(null),g({requested:e,candidates:t.rycoBooted,limit:t.limit});return}}b(t,y,await _.attach({threadId:n,udid:e.udid}))},`Could not open that simulator`))},[_,b,t,y,k,n]),j=(0,J.useCallback)(e=>{if(!h||!_||!n||!t)return;let r=h;g(null),f(r.requested.udid),k(async()=>{await _.shutdown({udid:e.udid});let i=await _.boot({udid:r.requested.udid});if(i.kind===`boot-limit-reached`){f(null),g({...r,candidates:i.rycoBooted,limit:i.limit});return}b(t,y,await _.attach({threadId:n,udid:r.requested.udid}))},`Could not free a simulator slot`)},[_,b,h,t,y,k,n]),ee=eg({canvasRef:i,udid:D?.state===`booted`?D.udid:null,...v?.openFrameSource?{openFrameSource:v.openFrameSource}:{}}),M=sg({canvasRef:i,udid:D?.state===`booted`?D.udid:null,enabled:!v?.openFrameSource,screenshot:_?e=>_.screenshot(e):null}),te=v?.openFrameSource?ee.status:M.status,N=v?.openFrameSource?ee.error:M.error,P=v?.openFrameSource?ee.dimensions:M.dimensions,ne=(0,J.useRef)(null),re=(0,J.useCallback)(e=>{let t=i.current;if(!t||!P)return null;let n=t.getBoundingClientRect(),r=D?.geometry?.scale??(P.width>1400?2:3);return Zh({frameWidth:P.width,frameHeight:P.height,displayWidth:n.width,displayHeight:n.height,pointWidth:D?.geometry?.pointWidth??P.width/r,pointHeight:D?.geometry?.pointHeight??P.height/r},e.clientX-n.left,e.clientY-n.top)},[D?.geometry,P]),ie=(0,J.useCallback)(e=>{e.currentTarget.focus(),e.currentTarget.setPointerCapture(e.pointerId),ne.current={point:re(e),at:performance.now()}},[re]),ae=(0,J.useCallback)(e=>{let t=ne.current;if(ne.current=null,!t||!D||!_)return;let n=re(e);!t.point||!n||(Math.hypot(n.x-t.point.x,n.y-t.point.y)<=8?_.tap({udid:D.udid,x:n.x,y:n.y}):_.swipe({udid:D.udid,fromX:t.point.x,fromY:t.point.y,toX:n.x,toY:n.y,durationMs:Math.max(16,Math.round(performance.now()-t.at))})).catch(e=>H.add({type:`error`,title:`Simulator input failed`,description:lg(e,`The input could not be delivered.`)}))},[_,D,re]),oe=(0,J.useCallback)((e,t)=>{if(!D||!_||e.metaKey||e.ctrlKey)return;let n=Qh(e.key);n!==null&&(e.preventDefault(),_.keyEvent({udid:D.udid,keyCode:n,modifiers:fg(e),direction:t}).catch(()=>void 0))},[_,D]),se=(0,J.useCallback)(e=>{!D||!_||k(()=>_.pressButton({udid:D.udid,button:e}),`Simulator button failed`)},[_,D,k]),I=(0,J.useCallback)(()=>{!D||!_||k(async()=>{let e=await _.screenshot({udid:D.udid,save:!0});H.add({type:`success`,title:`Screenshot saved`,description:e.path??e.name})},`Could not save the screenshot`)},[_,D,k]),ce=(0,J.useCallback)(()=>{if(!(!D||!_||p.kind===`starting`||p.kind===`stopping`)){if(p.kind===`idle`){m({kind:`starting`}),_.startRecording({udid:D.udid}).then(e=>m({kind:`recording`,path:e.path}),e=>{m({kind:`idle`}),H.add({type:`error`,title:`Could not start recording`,description:lg(e,`Recording failed.`)})});return}m({kind:`stopping`}),_.stopRecording({udid:D.udid}).then(e=>{m({kind:`idle`}),H.add({type:`success`,title:`Recording saved`,description:e.path})},e=>{m({kind:`idle`}),H.add({type:`error`,title:`Could not stop recording`,description:lg(e,`The recording may be incomplete.`)})})}},[_,D,p]);if(!t||!n||!_)return(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[(0,X.jsx)(br,{className:`size-7 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Simulator unavailable`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`This thread has no device connection.`})]});let le=(0,X.jsx)(pg,{availability:s?.availability??null});if(!s?.availability||s.availability.kind===`unsupported-platform`||s.availability.kind===`helper-unavailable`||s.availability.kind===`setup-required`&&s.availability.steps.some(e=>!e.done&&e.id!==`build-device-helper`))return le;let ue=s.availability?.kind===`degraded`?s.availability.capabilities.filter(e=>!e.ok):[];return(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex min-h-11 shrink-0 items-center gap-2 border-b border-border/60 px-3`,children:[(0,X.jsx)(Sn,{className:`size-4 text-muted-foreground`}),(0,X.jsxs)(`select`,{"aria-label":`Choose an iOS Simulator`,className:`min-w-0 max-w-72 flex-1 bg-transparent text-xs font-medium outline-none`,disabled:l,value:D?.udid??``,onChange:e=>{let t=E.find(t=>t.udid===e.target.value);t&&A(t)},children:[(0,X.jsx)(`option`,{value:``,disabled:!0,children:`Choose a simulator`}),E.toSorted((e,t)=>Number(t.state===`booted`)-Number(e.state===`booted`)||e.name.localeCompare(t.name)).map(e=>(0,X.jsxs)(`option`,{value:e.udid,disabled:e.state===`booting`||e.state===`shutting-down`,children:[e.name,` — `,e.runtime,` · `,ug(e.state)]},e.udid))]}),c?.agentActive?(0,X.jsx)(`span`,{className:`rounded-full bg-sky-500/15 px-2 py-0.5 text-[10px] font-medium text-sky-500`,children:`Agent controlling`}):null,(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,"aria-label":`Refresh simulators`,onClick:()=>void w(),children:(0,X.jsx)(yn,{className:`size-3.5`})})]}),ue.length>0?(0,X.jsxs)(`div`,{className:`border-b border-amber-500/20 bg-amber-500/8 px-3 py-1.5 text-[10px] text-amber-700 dark:text-amber-300`,children:[`Limited by this Xcode: `,ue.map(e=>e.id).join(`, `),`.`]}):null,(0,X.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-muted/25 p-4 sm:p-6`,children:D?(0,X.jsxs)(`div`,{className:F(`relative flex max-h-full max-w-full overflow-hidden border-[7px] border-zinc-900 bg-black shadow-xl`,D.family===`tablet`||D.name.toLowerCase().includes(`ipad`)?`aspect-[4/3] w-[min(88%,52rem)] rounded-[1.8rem]`:`aspect-[9/19.5] h-full max-h-[min(100%,58rem)] rounded-[2.4rem]`),children:[(0,X.jsx)(`canvas`,{ref:i,tabIndex:0,"aria-label":`${D.name} screen`,className:`h-full w-full touch-none object-contain outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-sky-400`,onPointerDown:ie,onPointerUp:ae,onPointerCancel:()=>{ne.current=null},onKeyDown:e=>oe(e,`down`),onKeyUp:e=>oe(e,`up`)}),te===`streaming`?null:(0,X.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 flex flex-col items-center justify-center bg-black/75 p-6 text-center text-white`,children:[(0,X.jsx)(V,{className:`size-5 animate-spin text-white/60`}),(0,X.jsx)(`p`,{className:`mt-3 text-xs font-medium`,children:te===`unsupported`?`This browser does not support WebCodecs.`:te===`recovering`?`Reconnecting the live screen…`:dg(D,c?.attachPhase)}),N?(0,X.jsx)(`p`,{className:`mt-2 max-w-52 text-[10px] text-white/60`,children:N}):null]})]}):(0,X.jsxs)(`div`,{className:`max-w-xs text-center`,children:[(0,X.jsx)(Sn,{className:`mx-auto size-8 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Choose a simulator`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Boot a device or attach one that is already running. Its screen will stay beside your conversation.`})]})}),(0,X.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center justify-center gap-0.5 border-t border-border/60 bg-card/40 px-2`,children:[(0,X.jsx)(vg,{icon:gr,label:`Home`,disabled:!D||l,onClick:()=>se(`home`)}),(0,X.jsx)(vg,{icon:nn,label:`Lock`,disabled:!D||l,onClick:()=>se(`lock`)}),(0,X.jsx)(vg,{icon:Dr,label:`Volume down`,disabled:!D||l,onClick:()=>se(`volume-down`)}),(0,X.jsx)(vg,{icon:Or,label:`Volume up`,disabled:!D||l,onClick:()=>se(`volume-up`)}),(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),(0,X.jsx)(vg,{icon:dr,label:`Screenshot`,disabled:!D||l,onClick:I}),(0,X.jsx)(vg,{icon:p.kind===`recording`||p.kind===`stopping`?fr:mr,label:p.kind===`recording`?`Stop recording`:`Record screen`,active:p.kind!==`idle`,disabled:!D||p.kind===`starting`||p.kind===`stopping`,onClick:ce}),(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),(0,X.jsx)(vg,{icon:Dn,label:`Detach`,disabled:!D||l,onClick:()=>void k(async()=>b(t,y,await _.detach({threadId:n})),`Could not detach the simulator`)}),(0,X.jsx)(vg,{icon:wr,label:`Shut down`,disabled:!D||l,onClick:()=>{D&&k(()=>_.shutdown({udid:D.udid}),`Could not shut down the simulator`)}})]}),h?(0,X.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-center justify-center bg-background/75 p-6 backdrop-blur-sm`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-sm rounded-xl border border-border bg-card p-5 shadow-xl`,children:[(0,X.jsx)(`p`,{className:`text-sm font-semibold`,children:`Simulator boot limit reached`}),(0,X.jsxs)(`p`,{className:`mt-2 text-xs leading-relaxed text-muted-foreground`,children:[`Ryco keeps at most `,h.limit,` simulators it booted running. Shut down one to open `,h.requested.name,`.`]}),(0,X.jsx)(`div`,{className:`mt-4 space-y-2`,children:h.candidates.map(e=>(0,X.jsxs)(Un,{variant:`outline`,className:`w-full justify-between`,onClick:()=>j(e),children:[(0,X.jsxs)(`span`,{className:`truncate`,children:[`Shut down `,e.name]}),(0,X.jsx)(wr,{className:`size-3.5`})]},e.udid))}),(0,X.jsx)(Un,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>g(null),children:`Cancel`})]})}):null]})}function vg(e){let t=(0,Y.c)(11),n=e.icon,r=e.label,i=e.label,a=e.active,o=e.disabled,s=e.active&&`text-red-500`,c;t[0]===s?c=t[1]:(c=F(s),t[0]=s,t[1]=c);let l;t[2]===n?l=t[3]:(l=(0,X.jsx)(n,{className:`size-4`}),t[2]=n,t[3]=l);let u;return t[4]!==e.active||t[5]!==e.disabled||t[6]!==e.label||t[7]!==e.onClick||t[8]!==c||t[9]!==l?(u=(0,X.jsx)(Un,{size:`icon-sm`,variant:`ghost`,title:r,"aria-label":i,"aria-pressed":a,disabled:o,className:c,onClick:e.onClick,children:l}),t[4]=e.active,t[5]=e.disabled,t[6]=e.label,t[7]=e.onClick,t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function yg(e){return e===`running`?`in_progress`:e===`failed`?`review`:e===`finished`?`done`:`idle`}function bg(e){return e===`running`?`Working`:e===`failed`?`Needs review`:e===`finished`?`Finished`:e===`interrupted`?`Stopped`:`Idle`}function xg(e){return encodeURIComponent(e??`none`).replace(/%/g,`_`)}function Sg(e){return`thread-workspace-tab-${xg(e)}`}function Cg(e){return`thread-workspace-panel-${xg(e)}`}function wg(e){let t=(0,Y.c)(17),n=e.active?`text-foreground`:`text-muted-foreground`,r;t[0]===n?r=t[1]:(r=F(`size-3.5 shrink-0`,n),t[0]=n,t[1]=r);let i=r;if(e.tab.mode===`agent`){let n=e.tab.avatarKey??e.tab.agentKey,r=!e.active&&`opacity-70`,i;t[2]===r?i=t[3]:(i=F(`size-3.5 shrink-0`,r),t[2]=r,t[3]=i);let a;return t[4]!==n||t[5]!==i?(a=(0,X.jsx)(At,{name:n,className:i}),t[4]=n,t[5]=i,t[6]=a):a=t[6],a}if(e.tab.key===`review`){let e;return t[7]===i?e=t[8]:(e=(0,X.jsx)(hr,{className:i}),t[7]=i,t[8]=e),e}if(e.tab.key===`terminal`){let e;return t[9]===i?e=t[10]:(e=(0,X.jsx)(Tn,{className:i}),t[9]=i,t[10]=e),e}if(e.tab.key===`simulator`){let e;return t[11]===i?e=t[12]:(e=(0,X.jsx)(Sn,{className:i}),t[11]=i,t[12]=e),e}if(e.tab.key===`agents`){let e;return t[13]===i?e=t[14]:(e=(0,X.jsx)(be,{className:i}),t[13]=i,t[14]=e),e}let a;return t[15]===i?a=t[16]:(a=(0,X.jsx)(Oe,{className:i}),t[15]=i,t[16]=a),a}function Tg(e){let t=(0,Y.c)(8),n;if(t[0]!==e.agent.status){let r=yg(e.agent.status);n=Yn(r,`truncate`),t[0]=e.agent.status,t[1]=n}else n=t[1];let r;t[2]===e.agent.name?r=t[3]:(r=Jn(e.agent.name,{durationSeconds:2.2}),t[2]=e.agent.name,t[3]=r);let i;return t[4]!==e.agent.name||t[5]!==n||t[6]!==r?(i=(0,X.jsx)(`span`,{className:n,style:r,children:e.agent.name}),t[4]=e.agent.name,t[5]=n,t[6]=r,t[7]=i):i=t[7],i}function Eg(e){let t=(0,Y.c)(43);if(!e.subagent){let n,r,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`mx-auto flex size-10 items-center justify-center rounded-md border border-border/70 bg-card/60 text-muted-foreground`,children:(0,X.jsx)(yr,{className:`size-4`})}),r=(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:`Subagent unavailable`}),i=(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`This tab points to a subagent that is no longer present in the current thread activity.`}),t[0]=n,t[1]=r,t[2]=i):(n=t[0],r=t[1],i=t[2]);let a;t[3]===e.agentKey?a=t[4]:(a=e.agentKey?(0,X.jsx)(`p`,{className:`mt-2 truncate font-mono text-[11px] text-muted-foreground/60`,children:e.agentKey}):null,t[3]=e.agentKey,t[4]=a);let o;return t[5]===a?o=t[6]:(o=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center p-6 text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-72`,children:[n,r,i,a]})}),t[5]=a,t[6]=o),o}let n=e.subagent.avatarKey??e.subagent.key,r;t[7]===n?r=t[8]:(r=(0,X.jsx)(At,{name:n,className:`size-4`}),t[7]=n,t[8]=r);let i;t[9]===e.subagent?i=t[10]:(i=(0,X.jsx)(`p`,{className:`min-w-0 flex-1 text-sm font-medium`,children:(0,X.jsx)(Tg,{agent:e.subagent})}),t[9]=e.subagent,t[10]=i);let a;t[11]===e.subagent.role?a=t[12]:(a=e.subagent.role?(0,X.jsx)(`span`,{className:`max-w-36 shrink-0 truncate rounded-sm border border-border/60 bg-background/40 px-1.5 py-px text-[10px] font-medium text-muted-foreground`,children:e.subagent.role}):null,t[11]=e.subagent.role,t[12]=a);let o;t[13]===e.subagent.status?o=t[14]:(o=bg(e.subagent.status),t[13]=e.subagent.status,t[14]=o);let s;t[15]===o?s=t[16]:(s=(0,X.jsx)(`span`,{className:`shrink-0 rounded-md border border-border/70 px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:o}),t[15]=o,t[16]=s);let c;t[17]!==r||t[18]!==i||t[19]!==a||t[20]!==s?(c=(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[r,i,a,s]}),t[17]=r,t[18]=i,t[19]=a,t[20]=s,t[21]=c):c=t[21];let l;t[22]===e.subagent.detail?l=t[23]:(l=e.subagent.detail?(0,X.jsx)(`p`,{className:`mt-2 line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.subagent.detail}):null,t[22]=e.subagent.detail,t[23]=l);let u;t[24]!==e.subagent.providerThreadIds||t[25]!==e.subagent.tool?(u=e.subagent.tool||e.subagent.providerThreadIds.length>0?(0,X.jsxs)(`div`,{className:`mt-2 flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.subagent.tool?(0,X.jsx)(`span`,{className:`rounded-md border border-border/60 px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:e.subagent.tool}):null,e.subagent.providerThreadIds.slice(0,2).map(Og)]}):null,t[24]=e.subagent.providerThreadIds,t[25]=e.subagent.tool,t[26]=u):u=t[26];let d;t[27]!==c||t[28]!==l||t[29]!==u?(d=(0,X.jsxs)(`div`,{className:`border-b border-border/60 px-4 py-3`,children:[c,l,u]}),t[27]=c,t[28]=l,t[29]=u,t[30]=d):d=t[30];let f;t[31]===e.subagent.messages?f=t[32]:(f=e.subagent.messages.length>0?e.subagent.messages.map(Dg):null,t[31]=e.subagent.messages,t[32]=f);let p;t[33]!==e.subagent.entries||t[34]!==e.subagent.messages.length||t[35]!==e.subagent.status?(p=e.subagent.entries.length>0?e.subagent.entries.map(t=>(0,X.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-card/40 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:F(`size-2 shrink-0 rounded-full`,t.tone===`error`?`bg-destructive`:e.subagent?.status===`running`?`bg-sky-400`:e.subagent?.status===`interrupted`?`bg-muted-foreground/60`:`bg-emerald-400`)}),(0,X.jsx)(`p`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:t.toolTitle??t.label})]}),t.detail?(0,X.jsx)(`p`,{className:`mt-2 text-xs leading-relaxed text-muted-foreground`,children:t.detail}):null,t.output&&t.output!==t.detail?(0,X.jsx)(`div`,{className:`mt-3 rounded-md border border-border/50 bg-background/60 p-2`,children:(0,X.jsx)(Ot,{text:t.output,cwd:void 0,isStreaming:!1})}):null]},t.id)):e.subagent.messages.length===0?(0,X.jsxs)(`div`,{className:`flex min-h-48 flex-col items-center justify-center rounded-md border border-dashed border-border/70 bg-card/20 p-6 text-center`,children:[(0,X.jsx)(yr,{className:`size-5 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:`No transcript captured yet`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`The subagent is visible from lifecycle events. Detailed messages will appear here when the provider exposes them.`})]}):null,t[33]=e.subagent.entries,t[34]=e.subagent.messages.length,t[35]=e.subagent.status,t[36]=p):p=t[36];let m;t[37]!==f||t[38]!==p?(m=(0,X.jsx)(Hn,{className:`min-h-0 flex-1`,children:(0,X.jsxs)(`div`,{className:`space-y-3 p-4`,children:[f,p]})}),t[37]=f,t[38]=p,t[39]=m):m=t[39];let h;return t[40]!==m||t[41]!==d?(h=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col`,children:[d,m]}),t[40]=m,t[41]=d,t[42]=h):h=t[42],h}function Dg(e){return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-card/40 p-3`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex min-w-0 items-center justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`truncate text-xs font-medium text-foreground`,children:`Subagent`}),e.providerThreadId?(0,X.jsx)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground/55`,children:e.providerThreadId}):null]}),(0,X.jsx)(Ot,{text:e.text,cwd:void 0,isStreaming:!1})]},e.id)}function Og(e){return(0,X.jsx)(`span`,{className:`max-w-40 truncate rounded-md border border-border/60 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground/70`,children:e},e)}function kg(e){let t=(0,Y.c)(8),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`mx-auto flex size-10 items-center justify-center rounded-md border border-border/70 bg-card/60 text-muted-foreground`,children:(0,X.jsx)(Tn,{className:`size-4`})}),t[0]=n):n=t[0];let r;t[1]===e.title?r=t[2]:(r=(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:e.title}),t[1]=e.title,t[2]=r);let i;t[3]===e.description?i=t[4]:(i=(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:e.description}),t[3]=e.description,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center p-6 text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-72`,children:[n,r,i]})}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ag(){let e=(0,Y.c)(89),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={strict:!1},e[0]=t):t=e[0];let n=ie(t),a;e[1]===n?a=e[2]:(a=ae(n),e[1]=n,e[2]=a);let s=a,c;e[3]===n.draftId?c=e[4]:(c=n.draftId?ee.make(n.draftId):null,e[3]=n.draftId,e[4]=c);let u=c,d;e[5]===u?d=e[6]:(d=e=>u?e.getDraftSession(u):null,e[5]=u,e[6]=d);let m=te(d),h;bb0:{if(s){h=s;break bb0}if(!m){h=null;break bb0}let t;e[7]!==m.environmentId||e[8]!==m.threadId?(t=r(m.environmentId,m.threadId),e[7]=m.environmentId,e[8]=m.threadId,e[9]=t):t=e[9],h=t}let g=h,_;e[10]===g?_=e[11]:(_=p(g),e[10]=g,e[11]=_);let b=f(_),x;e[12]===g?x=e[13]:(x=e=>g?e.getDraftThreadByRef(g):null,e[12]=g,e[13]=x);let S=te(x),w;e[14]!==S||e[15]!==b?(w=b?i(b.environmentId,b.projectId):S?i(S.environmentId,S.projectId):null,e[14]=S,e[15]=b,e[16]=w):w=e[16];let T=w,E;e[17]===T?E=e[18]:(E=l(T),e[17]=T,e[18]=E);let O=f(E),k;e[19]===g?k=e[20]:(k=e=>D(e.terminalStateByThreadKey,g),e[19]=g,e[20]=k);let A=v(k),j;e[21]===g?j=e[22]:(j=e=>g?e.terminalLaunchContextByThreadKey[o(g)]??null:null,e[21]=g,e[22]=j);let M=v(j),N=v(zg),P=v(Rg),F=v(Lg),re=v(Ig),oe=v(Fg),se=v(Pg),I=y(),ce=Wn(),[le,ue]=(0,J.useState)(0),de=b?.worktreePath??S?.worktreePath??null,fe=M?.worktreePath??de;M?.cwd;let pe;e[23]!==fe||e[24]!==O||e[25]!==M?.cwd?(pe=M?.cwd??(O?cn({project:{cwd:O.cwd},worktreePath:fe}):null),e[23]=fe,e[24]=O,e[25]=M?.cwd,e[26]=pe):pe=e[26];let L=pe,R;e[27]!==fe||e[28]!==O?(R=O?Jt({project:{cwd:O.cwd},worktreePath:fe}):{},e[27]=fe,e[28]=O,e[29]=R):R=e[29];let me=R,z;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(z={context:{terminalFocus:!0,terminalOpen:!0}},e[30]=z):z=e[30];let he=z,ge;e[31]===I?ge=e[32]:(ge=Rn(I,`terminal.split`,he),e[31]=I,e[32]=ge);let _e=ge,ve;e[33]===I?ve=e[34]:(ve=Rn(I,`terminal.new`,he),e[33]=I,e[34]=ve);let B=ve,ye;e[35]===I?ye=e[36]:(ye=Rn(I,`terminal.close`,he),e[35]=I,e[36]=ye);let be=ye,xe,V;e[37]!==N||e[38]!==A.terminalOpen||e[39]!==g?(xe=()=>{!g||!A.terminalOpen||N(g,!1)},V=[N,A.terminalOpen,g],e[37]=N,e[38]=A.terminalOpen,e[39]=g,e[40]=xe,e[41]=V):(xe=e[40],V=e[41]),(0,J.useEffect)(xe,V);let Se;e[42]===Symbol.for(`react.memo_cache_sentinel`)?(Se=()=>{ue(Ng)},e[42]=Se):Se=e[42];let Ce=Se,we;e[43]!==N||e[44]!==F||e[45]!==g?(we=()=>{g&&(F(g,`terminal-${ne()}`),N(g,!1),Ce())},e[43]=N,e[44]=F,e[45]=g,e[46]=we):we=e[46];let Te=we,Ee;e[47]!==re||e[48]!==N||e[49]!==g?(Ee=()=>{g&&(re(g,`terminal-${ne()}`),N(g,!1),Ce())},e[47]=re,e[48]=N,e[49]=g,e[50]=Ee):Ee=e[50];let De=Ee,H;e[51]!==oe||e[52]!==g?(H=e=>{g&&(oe(g,e),Ce())},e[51]=oe,e[52]=g,e[53]=H):H=e[53];let U=H,Oe;e[54]!==P||e[55]!==g?(Oe=e=>{g&&P(g,e)},e[54]=P,e[55]=g,e[56]=Oe):Oe=e[56];let ke=Oe,W;e[57]!==se||e[58]!==N||e[59]!==A.terminalIds.length||e[60]!==g?(W=e=>{if(!g)return;let t=C(g.environmentId);if(!t)return;let n=A.terminalIds.length<=1,r=()=>t.terminal.write({threadId:g.threadId,terminalId:e,data:`exit
2009
- `}).catch(Mg);`close`in t.terminal&&typeof t.terminal.close==`function`?(async()=>{n&&await t.terminal.clear({threadId:g.threadId,terminalId:e}).catch(jg),await t.terminal.close({threadId:g.threadId,terminalId:e,deleteHistory:!0})})().catch(()=>r()):r(),se(g,e),N(g,!1),Ce()},e[57]=se,e[58]=N,e[59]=A.terminalIds.length,e[60]=g,e[61]=W):W=e[61];let G=W,Ae;e[62]===ce?Ae=e[63]:(Ae=e=>{ce?.current?.addTerminalContext(e)},e[62]=ce,e[63]=Ae);let je=Ae;if(!g){let t;return e[64]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(kg,{title:`Terminal unavailable`,description:`No active thread is available for this workspace terminal.`}),e[64]=t):t=e[64],t}if(!O||!L){let t;return e[65]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(kg,{title:`Terminal unavailable`,description:`This thread does not have a resolved project directory.`}),e[65]=t):t=e[65],t}let Me=g.threadId,Ne=_e??void 0,Pe=B??void 0,Fe=be??void 0,Ie;return e[66]!==U||e[67]!==je||e[68]!==G||e[69]!==De||e[70]!==L||e[71]!==fe||e[72]!==le||e[73]!==I||e[74]!==me||e[75]!==ke||e[76]!==Te||e[77]!==Me||e[78]!==Ne||e[79]!==Pe||e[80]!==Fe||e[81]!==A.activeTerminalGroupId||e[82]!==A.activeTerminalId||e[83]!==A.runningTerminalIds||e[84]!==A.terminalGroups||e[85]!==A.terminalHeight||e[86]!==A.terminalIds||e[87]!==g?(Ie=(0,X.jsx)(Cn,{threadRef:g,threadId:Me,cwd:L,worktreePath:fe,runtimeEnv:me,layout:`panel`,visible:!0,height:A.terminalHeight,terminalIds:A.terminalIds,runningTerminalIds:A.runningTerminalIds,activeTerminalId:A.activeTerminalId,terminalGroups:A.terminalGroups,activeTerminalGroupId:A.activeTerminalGroupId,focusRequestId:le,onSplitTerminal:Te,onNewTerminal:De,splitShortcutLabel:Ne,newShortcutLabel:Pe,closeShortcutLabel:Fe,keybindings:I,onActiveTerminalChange:U,onCloseTerminal:G,onHeightChange:ke,onAddTerminalContext:je}),e[66]=U,e[67]=je,e[68]=G,e[69]=De,e[70]=L,e[71]=fe,e[72]=le,e[73]=I,e[74]=me,e[75]=ke,e[76]=Te,e[77]=Me,e[78]=Ne,e[79]=Pe,e[80]=Fe,e[81]=A.activeTerminalGroupId,e[82]=A.activeTerminalId,e[83]=A.runningTerminalIds,e[84]=A.terminalGroups,e[85]=A.terminalHeight,e[86]=A.terminalIds,e[87]=g,e[88]=Ie):Ie=e[88],Ie}function jg(){}function Mg(){}function Ng(e){return e+1}function Pg(e){return e.closeTerminal}function Fg(e){return e.setActiveTerminal}function Ig(e){return e.newTerminal}function Lg(e){return e.splitTerminal}function Rg(e){return e.setTerminalHeight}function zg(e){return e.setTerminalOpen}function Bg(e){let t=(0,Y.c)(38),n=e.icon,r=e.disabled,i=e.onClick,a=e.compact?`min-h-0 px-1 py-1 @sm/workspace-launcher:px-4 @sm/workspace-launcher:py-3`:`min-h-32 px-5 py-6`,o=e.disabled?`cursor-not-allowed opacity-45`:`hover:border-border hover:bg-card/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,s;t[0]!==a||t[1]!==o?(s=F(`group flex w-full flex-col items-center justify-center rounded-lg border border-border/50 bg-card/35 text-center transition-colors`,a,o),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c=e.compact?`size-4 @sm/workspace-launcher:size-6`:`size-6`,l=!e.disabled&&`group-hover:text-foreground`,u;t[3]!==c||t[4]!==l?(u=F(`text-muted-foreground transition-colors`,c,l),t[3]=c,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==n||t[7]!==u?(d=(0,X.jsx)(n,{className:u}),t[6]=n,t[7]=u,t[8]=d):d=t[8];let f=e.badgeCount??0,p;t[9]===f?p=t[10]:(p=(0,X.jsx)(ot,{count:f,className:`-top-2 -right-3 h-4 min-w-4 px-1 text-[9px]`}),t[9]=f,t[10]=p);let m;t[11]!==p||t[12]!==d?(m=(0,X.jsxs)(`span`,{className:`relative inline-flex`,children:[d,p]}),t[11]=p,t[12]=d,t[13]=m):m=t[13];let h;t[14]===e.badgeCount?h=t[15]:(h=(e.badgeCount??0)>0?(0,X.jsx)(`span`,{className:`sr-only`,children:je(e.badgeCount??0)}):null,t[14]=e.badgeCount,t[15]=h);let g=e.compact?`mt-1 text-xs @sm/workspace-launcher:mt-3 @sm/workspace-launcher:text-base`:`mt-4 text-base`,_;t[16]===g?_=t[17]:(_=F(`font-semibold text-foreground`,g),t[16]=g,t[17]=_);let v;t[18]!==e.label||t[19]!==_?(v=(0,X.jsx)(`span`,{className:_,children:e.label}),t[18]=e.label,t[19]=_,t[20]=v):v=t[20];let y=e.compact?`mt-0.5 hidden text-xs @sm/workspace-launcher:block`:`mt-1 text-sm`,b;t[21]===y?b=t[22]:(b=F(`text-muted-foreground`,y),t[21]=y,t[22]=b);let x;t[23]!==e.description||t[24]!==b?(x=(0,X.jsx)(`span`,{className:b,children:e.description}),t[23]=e.description,t[24]=b,t[25]=x):x=t[25];let S;t[26]!==e.compact||t[27]!==e.shortcutLabel?(S=e.shortcutLabel?(0,X.jsx)(`span`,{className:F(`rounded-md bg-muted px-1.5 py-0.5 font-medium text-[11px] text-muted-foreground`,e.compact?`mt-2 hidden @sm/workspace-launcher:inline-flex`:`mt-3`),children:e.shortcutLabel}):null,t[26]=e.compact,t[27]=e.shortcutLabel,t[28]=S):S=t[28];let C;return t[29]!==e.disabled||t[30]!==e.onClick||t[31]!==m||t[32]!==h||t[33]!==v||t[34]!==x||t[35]!==S||t[36]!==s?(C=(0,X.jsxs)(`button`,{type:`button`,disabled:r,onClick:i,"data-slot":`workspace-launcher-card`,className:s,children:[m,h,v,x,S]}),t[29]=e.disabled,t[30]=e.onClick,t[31]=m,t[32]=h,t[33]=v,t[34]=x,t[35]=S,t[36]=s,t[37]=C):C=t[37],C}function Vg(e){let t=(0,Y.c)(60),n=y(),r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={key:`files`,label:`Files`,mode:`files`},t[0]=r):r=t[0];let i=r,a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a={key:`review`,label:`Review`,mode:`review`},t[1]=a):a=t[1];let o=a,s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s={key:`terminal`,label:`Terminal`,mode:`terminal`},t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l={key:`simulator`,label:`Simulator`,mode:`simulator`},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d={key:`agents`,label:`Agents`,mode:`agents`},t[4]=d):d=t[4];let f=d,p;t[5]===n?p=t[6]:(p=Rn(n,`workspace.files`),t[5]=n,t[6]=p);let m=p,h;t[7]===n?h=t[8]:(h=Rn(n,`workspace.review`),t[7]=n,t[8]=h);let g=h,_;t[9]===n?_=t[10]:(_=Rn(n,`workspace.terminal`),t[9]=n,t[10]=_);let v=_,b;t[11]===n?b=t[12]:(b=Rn(n,`workspace.simulator`),t[11]=n,t[12]=b);let x=b,S,C;if(t[13]!==m||t[14]!==e||t[15]!==g||t[16]!==x||t[17]!==v){let n=e.tabs.filter(Hg),r=!e.isPhoneSurface,a;t[20]===e?a=t[21]:(a=()=>e.onSelectTab(i),t[20]=e,t[21]=a);let s;t[22]!==r||t[23]!==m||t[24]!==a?(s=(0,X.jsx)(Bg,{label:`Files`,description:`Browse project files`,icon:G,shortcutLabel:m,compact:r,onClick:a}),t[22]=r,t[23]=m,t[24]=a,t[25]=s):s=t[25];let l,d;t[26]===r?(l=t[27],d=t[28]):(l=(0,X.jsx)(Bg,{label:`Side chat`,description:`Start a side conversation`,icon:vr,compact:r,disabled:!0}),d=(0,X.jsx)(Bg,{label:`Browser`,description:`Open a website`,icon:Lt,compact:r,disabled:!0}),t[26]=r,t[27]=l,t[28]=d);let p;t[29]===e?p=t[30]:(p=()=>e.onSelectTab(o),t[29]=e,t[30]=p);let h;t[31]!==r||t[32]!==g||t[33]!==p?(h=(0,X.jsx)(Bg,{label:`Review`,description:`View code changes`,icon:hr,shortcutLabel:g,compact:r,onClick:p}),t[31]=r,t[32]=g,t[33]=p,t[34]=h):h=t[34];let _;t[35]===e?_=t[36]:(_=()=>e.onSelectTab(c),t[35]=e,t[36]=_);let y;t[37]!==r||t[38]!==_||t[39]!==v?(y=(0,X.jsx)(Bg,{label:`Terminal`,description:`Start an interactive shell`,icon:Tn,shortcutLabel:v,compact:r,onClick:_}),t[37]=r,t[38]=_,t[39]=v,t[40]=y):y=t[40];let b;t[41]!==r||t[42]!==e||t[43]!==x?(b=e.showSimulator?(0,X.jsx)(Bg,{label:`Simulator`,description:`Run and control an iOS app`,icon:Sn,shortcutLabel:x,compact:r,onClick:()=>e.onSelectTab(u)}):null,t[41]=r,t[42]=e,t[43]=x,t[44]=b):b=t[44];let w;t[45]!==r||t[46]!==e?(w=e.showAgents?(0,X.jsx)(Bg,{label:`Agents`,description:`Watch subagents and workflows run`,icon:be,badgeCount:e.liveAgentCount,compact:r,onClick:()=>e.onSelectTab(f)}):null,t[45]=r,t[46]=e,t[47]=w):w=t[47];let T;t[48]!==s||t[49]!==l||t[50]!==d||t[51]!==h||t[52]!==y||t[53]!==b||t[54]!==w?(T=(0,X.jsxs)(X.Fragment,{children:[s,l,d,h,y,b,w]}),t[48]=s,t[49]=l,t[50]=d,t[51]=h,t[52]=y,t[53]=b,t[54]=w,t[55]=T):T=t[55],S=T,C=n.length>0?(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-lg space-y-2 pt-1`,children:n.map(t=>(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full min-w-0 items-center gap-3 rounded-lg border border-border/50 bg-card/35 px-4 py-3 text-left transition-colors hover:border-border hover:bg-card/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>e.onSelectTab(t),children:[(0,X.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg border border-border/50 bg-background/50 text-muted-foreground`,children:(0,X.jsx)(At,{name:t.avatarKey??t.agentKey,className:`size-5`})}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:F(`block truncate text-sm font-medium`,Yn(yg(t.status))),style:Jn(t.label,{durationSeconds:2.2}),children:t.label}),(0,X.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:bg(t.status)})]})]},t.key))}):null,t[13]=m,t[14]=e,t[15]=g,t[16]=x,t[17]=v,t[18]=S,t[19]=C}else S=t[18],C=t[19];let w=C,T;return t[56]!==w||t[57]!==S||t[58]!==e.isPhoneSurface?(T=(0,X.jsx)(Hn,{className:`h-full`,children:e.isPhoneSurface?(0,X.jsx)(`div`,{className:`flex min-h-full p-5 sm:p-6`,children:(0,X.jsxs)(`div`,{className:`m-auto w-full max-w-lg space-y-4`,children:[S,w]})}):(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3 p-4 sm:p-5`,"data-slot":`workspace-launcher`,children:[(0,X.jsx)(`div`,{className:`@container/workspace-launcher flex min-h-0 flex-1 items-center justify-center`,children:(0,X.jsx)(`div`,{className:`grid aspect-square grid-cols-3 grid-rows-3 gap-2 @sm/workspace-launcher:gap-3`,"data-slot":`workspace-launcher-grid`,style:{inlineSize:`min(100cqw, 100cqh, 32rem)`},children:S})}),w]})}),t[56]=w,t[57]=S,t[58]=e.isPhoneSurface,t[59]=T):T=t[59],T}function Hg(e){return e.mode===`agent`}function Ug(e){let t=(0,Y.c)(125),{onClosePanelTab:n,onToggleMaximized:i}=e,o=e.maximized??!1,s=e.mode===`phone`,c=ve(),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={strict:!1},t[0]=l):l=t[0];let u=ie(l),d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d={strict:!1,select:Qg},t[1]=d):d=t[1];let m=se(d),h;t[2]===u?h=t[3]:(h=ae(u),t[2]=u,t[3]=h);let g=h,_;t[4]===u.draftId?_=t[5]:(_=u.draftId?ee.make(u.draftId):null,t[4]=u.draftId,t[5]=_);let v=_,y;t[6]===v?y=t[7]:(y=e=>v?e.getDraftSession(v):null,t[6]=v,t[7]=y);let b=te(y),x;t[8]!==g||t[9]!==b?(x=g??(b?r(b.environmentId,b.threadId):null),t[8]=g,t[9]=b,t[10]=x):x=t[10];let S=x,w;t[11]===S?w=t[12]:(w=p(S),t[11]=S,t[12]=w);let T=f(w),E;t[13]===T?.session?E=t[14]:(E=An(T?.session??null)!==`disconnected`&&T?.session?.orchestrationStatus!==`stopped`&&T?.session?.orchestrationStatus!==`interrupted`&&T?.session?.orchestrationStatus!==`error`,t[13]=T?.session,t[14]=E);let D=E;T?.activities,T?.latestTurn?.state;let O;t[15]!==T?.activities||t[16]!==T?.latestTurn?.state||t[17]!==D?(O=Pn(T?.activities??[],{sessionLive:D,parentTurnState:T?.latestTurn?.state??null}),t[15]=T?.activities,t[16]=T?.latestTurn?.state,t[17]=D,t[18]=O):O=t[18];let k=O,A=m.workspaceTab===`agent`&&m.workspaceAgentKey?m.workspaceAgentKey:null,j;t[19]!==A||t[20]!==k?(j=Nn(k,A),t[19]=A,t[20]=k,t[21]=j):j=t[21];let M=j,N;t[22]!==e.panelMode||t[23]!==m?(N=ge(m)??e.panelMode,t[22]=e.panelMode,t[23]=m,t[24]=N):N=t[24];let P=N;T?.activities;let ne;t[25]!==T?.activities||t[26]!==D||t[27]!==k?(ne=Mn({activities:T?.activities??[],transcriptSubagents:k,sessionLive:D}),t[25]=T?.activities,t[26]=D,t[27]=k,t[28]=ne):ne=t[28];let oe=ne,I;bb0:{if(P===`files`||P===`review`||P===`terminal`||P===`simulator`||P===`agents`){let n;t[29]!==P||t[30]!==e.openedPanelModes?(n=e.openedPanelModes.includes(P)?e.openedPanelModes:[...e.openedPanelModes,P],t[29]=P,t[30]=e.openedPanelModes,t[31]=n):n=t[31],I=n;break bb0}I=e.openedPanelModes}let ce=I,le;if(t[32]!==A||t[33]!==s||t[34]!==ce||t[35]!==e.openedAgentKeys||t[36]!==k){let n=fi({subagents:k,activeAgentKey:A,openedAgentKeys:e.openedAgentKeys,openedPanelModes:ce});le=s?n.filter(Zg):n,t[32]=A,t[33]=s,t[34]=ce,t[35]=e.openedAgentKeys,t[36]=k,t[37]=le}else le=t[37];let ue=le,pe=P===`agent`?A:s&&P===`agents`?null:P,L;t[38]!==c||t[39]!==u.draftId||t[40]!==g?(L=e=>{if(u.draftId){c({to:`/draft/$draftId`,params:{draftId:ee.make(u.draftId)},replace:!0,search:e});return}g&&c({to:`/$environmentId/$threadId`,params:re(g),replace:!0,search:e})},t[38]=c,t[39]=u.draftId,t[40]=g,t[41]=L):L=t[41];let R=L,me;t[42]===R?me=t[43]:(me=e=>{if(e.mode===`review`){R(Xg);return}if(e.mode===`files`){R(Yg);return}if(e.mode===`terminal`){R(Jg);return}if(e.mode===`simulator`){R(qg);return}if(e.mode===`agents`){R(Kg);return}e.mode===`agent`&&R(t=>fe(t,e.agentKey))},t[42]=R,t[43]=me);let z=me,he;t[44]===R?he=t[45]:(he=()=>{R(Gg)},t[44]=R,t[45]=he);let _e=he,B;t[46]===R?B=t[47]:(B=e=>{let t=e.startsWith(`subagent:`)?e:`subagent:${e}`;R(e=>fe(e,t))},t[46]=R,t[47]=B);let be=B,xe;t[48]===n?xe=t[49]:(xe=e=>{n({mode:e.mode,...e.mode===`agent`?{agentKey:e.agentKey}:{}})},t[48]=n,t[49]=xe);let V=xe,Se;t[50]!==z||t[51]!==ue?(Se=(e,t)=>{let n=ue.findIndex(t=>t.key===e.key);if(n<0)return;let r=e=>{let t=ue[(e+ue.length)%ue.length];t&&z(t)};switch(t.key){case`ArrowRight`:case`ArrowDown`:t.preventDefault(),r(n+1);return;case`ArrowLeft`:case`ArrowUp`:t.preventDefault(),r(n-1);return;case`Home`:t.preventDefault(),r(0);return;case`End`:t.preventDefault(),r(ue.length-1);return}},t[50]=z,t[51]=ue,t[52]=Se):Se=t[52];let Ce=Se,we;t[53]===R?we=t[54]:(we=()=>{R(Wg)},t[53]=R,t[54]=we);let Te=we,Ee=s?`h-14`:`h-12`,De=!s&&`transition-[padding-left] duration-200 ease-linear motion-reduce:transition-none`,H=e.reserveChromeInset&&de,U=o&&a&&`drag-region wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]`,Oe;t[55]!==Ee||t[56]!==De||t[57]!==H||t[58]!==U?(Oe=F(`flex shrink-0 items-center gap-1 border-b border-border bg-card/40 px-2`,Ee,De,H,U),t[55]=Ee,t[56]=De,t[57]=H,t[58]=U,t[59]=Oe):Oe=t[59];let ke;t[60]!==Te||t[61]!==s?(ke=s?(0,X.jsx)(Un,{size:`icon`,variant:`ghost`,"aria-label":`Back to thread`,className:`shrink-0`,onClick:Te,children:(0,X.jsx)(ye,{})}):null,t[60]=Te,t[61]=s,t[62]=ke):ke=t[62];let W;if(t[63]!==pe||t[64]!==V||t[65]!==s||t[66]!==Ce||t[67]!==z||t[68]!==ue){let e;t[70]!==pe||t[71]!==V||t[72]!==s||t[73]!==Ce||t[74]!==z?(e=e=>{let t=pe===e.key;return(0,X.jsxs)(`div`,{className:F(`flex min-w-0 shrink-0 items-center rounded-md text-sm transition-colors`,s?`h-11`:`h-8`,t?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[(0,X.jsxs)(`button`,{type:`button`,id:Sg(e.key),role:`tab`,"aria-selected":t,"aria-controls":Cg(e.key),tabIndex:t?0:-1,className:F(`flex h-full min-w-0 items-center gap-1.5`,s?`pl-3 pr-1.5`:`pl-2.5 pr-1`),onClick:()=>z(e),onKeyDown:t=>Ce(e,t),children:[(0,X.jsx)(wg,{tab:e,active:t}),(0,X.jsx)(`span`,{className:F(`max-w-32 truncate`,e.mode===`agent`&&Yn(yg(e.status))),style:e.mode===`agent`?Jn(e.label,{durationSeconds:2.2}):void 0,children:e.label})]}),(0,X.jsx)(`button`,{type:`button`,className:F(`mr-1 flex size-5 shrink-0 items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-background/60 hover:text-foreground`,s&&`relative after:absolute after:top-1/2 after:left-1/2 after:size-11 after:-translate-x-1/2 after:-translate-y-1/2`),"aria-label":`Close ${e.label} tab`,onClick:()=>V(e),children:(0,X.jsx)(On,{className:`size-3`})})]},e.key)},t[70]=pe,t[71]=V,t[72]=s,t[73]=Ce,t[74]=z,t[75]=e):e=t[75],W=ue.map(e),t[63]=pe,t[64]=V,t[65]=s,t[66]=Ce,t[67]=z,t[68]=ue,t[69]=W}else W=t[69];let G=s?`size-11`:`size-6`,Ae=!P&&`bg-muted text-foreground`,je;t[76]!==G||t[77]!==Ae?(je=F(`flex shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-muted/60 hover:text-foreground`,G,Ae),t[76]=G,t[77]=Ae,t[78]=je):je=t[78];let Me=!P,Ne;t[79]!==_e||t[80]!==je||t[81]!==Me?(Ne=(0,X.jsx)(`button`,{type:`button`,className:je,"aria-label":`Workspace launcher`,"aria-pressed":Me,onClick:_e}),t[79]=_e,t[80]=je,t[81]=Me,t[82]=Ne):Ne=t[82];let Pe;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=(0,X.jsx)(vn,{className:`size-3.5`}),t[83]=Pe):Pe=t[83];let Fe;t[84]===Ne?Fe=t[85]:(Fe=(0,X.jsx)(zn,{render:Ne,children:Pe}),t[84]=Ne,t[85]=Fe);let Ie;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(Ie=(0,X.jsx)(Bn,{side:`bottom`,children:`Workspace launcher`}),t[86]=Ie):Ie=t[86];let Le;t[87]===Fe?Le=t[88]:(Le=(0,X.jsxs)(Vn,{children:[Fe,Ie]}),t[87]=Fe,t[88]=Le);let Re;t[89]!==W||t[90]!==Le?(Re=(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,role:`tablist`,"aria-label":`Workspace tabs`,children:[W,Le]}),t[89]=W,t[90]=Le,t[91]=Re):Re=t[91];let ze;t[92]!==Te||t[93]!==s||t[94]!==o||t[95]!==i?(ze=s?null:(0,X.jsxs)(X.Fragment,{children:[i?(0,X.jsxs)(Vn,{children:[(0,X.jsx)(zn,{render:(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,className:`shrink-0 text-muted-foreground/70 hover:text-foreground`,onClick:i,"aria-pressed":o,"aria-label":o?`Restore workspace panel`:`Maximize workspace panel`,children:o?(0,X.jsx)(_n,{className:`size-3.5`}):(0,X.jsx)(_r,{className:`size-3.5`})})}),(0,X.jsx)(Bn,{side:`bottom`,children:o?`Restore workspace panel`:`Maximize workspace panel`})]}):null,(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,className:`shrink-0 text-muted-foreground/70 hover:text-foreground`,onClick:Te,"aria-label":`Close workspace panel`,children:(0,X.jsx)(On,{className:`size-3.5`})})]}),t[92]=Te,t[93]=s,t[94]=o,t[95]=i,t[96]=ze):ze=t[96];let K;t[97]!==Oe||t[98]!==ke||t[99]!==Re||t[100]!==ze?(K=(0,X.jsxs)(`div`,{className:Oe,children:[ke,Re,ze]}),t[97]=Oe,t[98]=ke,t[99]=Re,t[100]=ze,t[101]=K):K=t[101];let Be;t[102]===pe?Be=t[103]:(Be=Cg(pe),t[102]=pe,t[103]=Be);let Ve;t[104]===pe?Ve=t[105]:(Ve=pe?Sg(pe):void 0,t[104]=pe,t[105]=Ve);let He;t[106]!==M||t[107]!==P||t[108]!==T||t[109]!==A||t[110]!==oe||t[111]!==s||t[112]!==be||t[113]!==e.mode||t[114]!==z||t[115]!==ue||t[116]!==S?(He=P===`review`?(0,X.jsx)(Iu,{mode:e.mode}):P===`files`?(0,X.jsx)(Kh,{mode:e.mode}):P===`terminal`?(0,X.jsx)(Ag,{}):P===`simulator`&&!s?(0,X.jsx)(_g,{environmentId:S?.environmentId??null,threadId:S?.threadId??null}):P===`agents`&&!s?(0,X.jsx)(li,{model:oe,environmentId:S?.environmentId??null,threadId:S?S.threadId:null,onOpenAgent:be}):P===`agent`?(0,X.jsx)(Eg,{subagent:M,agentKey:A}):(0,X.jsx)(Vg,{tabs:ue,activeThread:T,onSelectTab:z,showAgents:!s,showSimulator:!s&&!!(S&&C(S.environmentId)?.device),isPhoneSurface:s,liveAgentCount:oe.liveCount}),t[106]=M,t[107]=P,t[108]=T,t[109]=A,t[110]=oe,t[111]=s,t[112]=be,t[113]=e.mode,t[114]=z,t[115]=ue,t[116]=S,t[117]=He):He=t[117];let Ue;t[118]!==Be||t[119]!==Ve||t[120]!==He?(Ue=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,id:Be,role:`tabpanel`,"aria-labelledby":Ve,children:He}),t[118]=Be,t[119]=Ve,t[120]=He,t[121]=Ue):Ue=t[121];let We;return t[122]!==K||t[123]!==Ue?(We=(0,X.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col bg-background w-full`,children:[K,Ue]}),t[122]=K,t[123]=Ue,t[124]=We):We=t[124],We}function Wg(e){return{...le(e),diff:void 0,diffTurnId:void 0,diffFilePath:void 0,preview:void 0,workspaceOpen:void 0,workspaceTab:void 0,workspaceAgentKey:void 0}}function Gg(e){return _e(e)}function Kg(e){return I(e)}function qg(e){return ce(e)}function Jg(e){return pe(e)}function Yg(e){return R(e)}function Xg(e){return he(e)}function Zg(e){return e.mode!==`agents`&&e.mode!==`simulator`}function Qg(e){return z(e)}export{Eg as AgentThreadPanel,Ug as default};
2008
+ `;function zh(e,t){let n=Math.max(Fh,Math.floor(t*Lh));return Math.max(Fh,Math.min(e,n))}function Bh(e,t,n){let r=e.startX-n;return zh(e.startWidth+r,t)}function Vh(e){if(!e)return!1;let t=e.toLowerCase();return t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`file not found`)||t.includes(`cannot find the file`)}function Hh(e,t){return`preview:${e}:${t.length}:${Pt(t).toString(36)}`}var Uh=[];function Wh(e){let t=(0,Y.c)(24),[n,r]=(0,J.useState)(e.open),i,a;t[0]===e.open?(i=t[1],a=t[2]):(i=()=>{if(!e.open){r(!1);return}let t=window.requestAnimationFrame(()=>r(!0));return()=>window.cancelAnimationFrame(t)},a=[e.open],t[0]=e.open,t[1]=i,t[2]=a),(0,J.useEffect)(i,a);let o=e.open&&n,s=!e.open||void 0,c=!e.open||void 0,l=e.open?`border-l border-border/70`:`border-l-0`,u=e.resizing?`transition-none`:`transition-[width,opacity] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none`,d=e.open?`opacity-100`:`opacity-0`,f;t[3]!==l||t[4]!==u||t[5]!==d?(f=q(`min-h-0 shrink-0 overflow-hidden bg-card/20`,l,u,d),t[3]=l,t[4]=u,t[5]=d,t[6]=f):f=t[6];let p=e.open?`${e.width}px`:`0px`,m;t[7]===p?m=t[8]:(m={width:p,maxWidth:`55%`},t[7]=p,t[8]=m);let h=e.resizing?`transition-none`:null,g=o?`translate-x-0 opacity-100`:`translate-x-4 opacity-0`,_;t[9]!==h||t[10]!==g?(_=q(`h-full min-h-0 transition-[translate,opacity] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] will-change-transform motion-reduce:transition-none`,h,g),t[9]=h,t[10]=g,t[11]=_):_=t[11];let v=`${e.width}px`,y;t[12]===v?y=t[13]:(y={width:v,maxWidth:`100%`},t[12]=v,t[13]=y);let b;t[14]!==e.children||t[15]!==_||t[16]!==y?(b=(0,X.jsx)(`div`,{className:_,style:y,children:e.children}),t[14]=e.children,t[15]=_,t[16]=y,t[17]=b):b=t[17];let x;return t[18]!==b||t[19]!==s||t[20]!==c||t[21]!==f||t[22]!==m?(x=(0,X.jsx)(`div`,{"data-preview-file-rail":!0,"aria-hidden":s,inert:c,className:f,style:m,children:b}),t[18]=b,t[19]=s,t[20]=c,t[21]=f,t[22]=m,t[23]=x):x=t[23],x}function Gh(){let e=(0,Y.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(Ae,{className:`size-8 text-muted-foreground/65`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center`,children:(0,X.jsxs)(`div`,{className:`flex max-w-xs flex-col items-center gap-3`,children:[t,(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground`,children:`Open file`}),(0,X.jsx)(`div`,{className:`text-xs leading-5 text-muted-foreground/70`,children:`Select a file from the workspace tree.`})]})]})}),e[1]=n):n=e[1],n}function Kh({mode:e=`inline`}){let{resolvedTheme:t}=ir(),n=h(),r=e===`phone`,i=re({strict:!1,select:e=>ie(e)}),a=re({strict:!1,select:e=>typeof e.draftId==`string`?ee.make(e.draftId):null}),o=oe({strict:!1,select:e=>le(e)}),c=d((0,J.useMemo)(()=>f(i),[i])),l=te(e=>c?null:a?e.getDraftSession(a):i?e.getDraftThreadByRef(i):null),u=(0,J.useMemo)(()=>{if(c)return{id:c.id,environmentId:c.environmentId,projectId:c.projectId,worktreePath:c.worktreePath,turnDiffSummaries:c.turnDiffSummaries};if(l)return{id:l.threadId,environmentId:l.environmentId,projectId:l.projectId,worktreePath:l.worktreePath,turnDiffSummaries:Uh}},[c,l]),m=u?.projectId??null,g=d(e=>u&&m?p(e,{environmentId:u.environmentId,projectId:m}):void 0),_=u?.worktreePath??g?.cwd??null,[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),S=(0,J.useRef)(null),[C,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(``),[O,k]=(0,J.useState)(!0),[A,j]=(0,J.useState)(r?!0:n.diffWordWrap),M=(0,J.useRef)(null),[ne,ae]=(0,J.useState)(()=>typeof window>`u`?Ih:N(Ph,s)??Ih),[se,F]=(0,J.useState)(!1),ce=(0,J.useRef)(null),ue=(0,J.useRef)(o.preview===`1`),de=(0,J.useRef)(null),I=(0,J.useRef)(null),fe=(0,J.useRef)(null),L=(0,J.useCallback)(e=>{S.current=e,x(e)},[]);(0,J.useEffect)(()=>{j(r?!0:n.diffWordWrap)},[r,n.diffWordWrap]),(0,J.useEffect)(()=>{y(null),L(null),T(null),k(!0)},[u?.environmentId,u?.id,L]);let R=(0,J.useMemo)(()=>{let e=(u?.turnDiffSummaries??[]).toReversed().find(e=>e.files.length>0);return e?`${e.turnId}:${e.completedAt}`:null},[u?.turnDiffSummaries]),pe=(0,J.useMemo)(()=>{if(!v)return null;let e=(u?.turnDiffSummaries??[]).toReversed().find(e=>e.files.some(e=>e.path===v));return e?`${e.turnId}:${e.completedAt}`:null},[u?.turnDiffSummaries,v]),z=ad({environmentId:u?.environmentId??null,cwd:_,enabled:!!(u?.environmentId&&_&&o.preview===`1`)}),me=z.error instanceof Error?z.error.message:z.error?`Failed to load the workspace tree.`:null,he=z.data,ge=z.data?.truncated===!0,B=z.isFetching,ve=z.refetch,ye=(0,J.useMemo)(()=>Nh(he?.entries??[],E),[E,he?.entries]),xe=E.trim().length>0;(0,J.useEffect)(()=>{if(he){if(he.entries.length===0){dh(S.current)||(y(null),L(null));return}v&&!he.entries.some(e=>e.path===v)&&(dh(S.current)||(y(null),L(null)))}},[L,he,v]),(0,J.useEffect)(()=>{if(o.preview!==`1`){de.current=R;return}if(de.current===null){de.current=R;return}de.current!==R&&(de.current=R,ve())},[R,o.preview,ve]),(0,J.useEffect)(()=>{let e=o.preview===`1`;e&&!ue.current&&y(null),ue.current=e},[o.preview]);let Se=v?he?.entries.find(e=>e.path===v):void 0,Ce=typeof Se?.sizeBytes==`number`?Oh(Se.sizeBytes):null,we=cd({environmentId:u?.environmentId??null,cwd:_,relativePath:v,enabled:!!(u?.environmentId&&_&&v&&o.preview===`1`&&(Ce?.shouldFetch??!0))}),Te=we.data?.relativePath===v?we.data:null,De=Te,V=De?.mimeType??Se?.mimeType??null,Oe=v?Dh({filePath:v,mimeType:V}):`text`,ke=we.error instanceof Error?we.error.message:we.error?`Failed to load file preview.`:null,Ae=we.refetch;(0,J.useEffect)(()=>{if(!v||o.preview!==`1`){I.current=pe;return}if(I.current===null){I.current=pe;return}I.current!==pe&&(I.current=pe,Ae())},[pe,o.preview,Ae,v]),(0,J.useEffect)(()=>{if(!v||!Vh(ke)){fe.current=null;return}let e=`${_??``}\u0000${v}\u0000${ke}`;fe.current!==e&&(fe.current=e,ve().then(e=>{if(!e.data?.entries.some(e=>e.path===v)){let e=S.current;e?.relativePath===v&&dh(e)?L(hh(e,{reason:`deleted`,message:`This file was removed from disk after it was opened. Explorer will not recreate it.`})):(y(e=>e===v?null:e),e?.relativePath===v&&L(null))}}).catch(()=>void 0))},[_,L,ve,ke,v]);let H=(0,J.useMemo)(()=>!u?.environmentId||!_||!Te||Te.relativePath!==v?null:lh({environmentId:u.environmentId,cwd:_},Te),[_,u?.environmentId,Te,v]);(0,J.useEffect)(()=>{H&&L(_h(S.current,H))},[L,H]);let U=H&&b?.key===H.key?b:null,je=dh(U),Me=!!(!r&&Oe===`text`&&H&&H.lineEnding!==`mixed`),Ne=lr({shouldBlockFn:(0,J.useCallback)(()=>je,[je]),disabled:!je,enableBeforeUnload:je,withResolver:!0}),Pe=(0,J.useCallback)(e=>{L(null),y(e)},[L]),Fe=(0,J.useCallback)(e=>{if(e!==v){if(dh(S.current)){T(e);return}Pe(e)}},[Pe,v]),Ie=(0,J.useCallback)(e=>{let t=S.current;!t||t.key!==H?.key||L(fh(t,e))},[L,H?.key]),Le=(0,J.useCallback)(async()=>{if(!u?.environmentId||!_||!v)return!1;try{let e=await w(u.environmentId).projects.readFile({cwd:_,relativePath:v});return id({environmentId:u.environmentId,cwd:_,relativePath:v},e),L(uh(lh({environmentId:u.environmentId,cwd:_},e))),!0}catch(e){let t=S.current;return t&&L(hh(t,{reason:Vh(e instanceof Error?e.message:String(e))?`deleted`:`failed`,message:e instanceof Error?e.message:`Failed to reload this file.`})),!1}},[_,u?.environmentId,L,v]),Re=(0,J.useCallback)(()=>{let e=S.current;if(!(!e||e.key!==H?.key)){if(e.errorReason===`deleted`){L(null),y(null),ve();return}if(e.saveStatus===`conflict`){Le();return}L(gh(e))}},[L,ve,Le,H?.key]),ze=(0,J.useCallback)(async()=>{let e=S.current;if(!e||!u?.environmentId||!_||e.relativePath!==v||e.lineEnding===`mixed`||e.saveStatus===`saving`||e.saveStatus===`conflict`||!dh(e))return!1;let t=e.key,n=e.contents;L(ph(e));try{let r=await w(u.environmentId).projects.writeFile({cwd:_,relativePath:e.relativePath,contents:n,expectedVersion:e.version,encoding:e.encoding,lineEnding:e.lineEnding});id({environmentId:u.environmentId,cwd:_,relativePath:e.relativePath},{relativePath:e.relativePath,contents:n,version:r.version,encoding:e.encoding,lineEnding:e.lineEnding});let i=S.current;if(!i||i.key!==t)return!1;let a=mh(i,n,r.version);return L(a),!dh(a)}catch(e){let n=S.current;return n?.key===t&&L(hh(n,vh(e))),!1}},[_,u?.environmentId,L,v]),W=U?.saveStatus===`conflict`||U?.errorReason===`unsupported`,Be=!!(Me&&je&&U?.saveStatus!==`saving`&&!W);(0,J.useEffect)(()=>{if(!Me||!je)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),Be&&ze())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[Be,je,Me,ze]);let Ve=(0,J.useMemo)(()=>{let e=De?.contents;return!v||Oe!==`text`||e===void 0?null:{name:v,contents:e,lang:Eh(v),cacheKey:Hh(v,e)}},[De?.contents,Oe,v]),He=(0,J.useMemo)(()=>({disableFileHeader:!0,overflow:A?`wrap`:`scroll`,theme:Mt(t),themeType:t,unsafeCSS:ch,tokenizeMaxLineLength:1e3}),[t,A]),Ue=(0,J.useCallback)(e=>{if(e.button!==0||!O)return;let t=M.current?.querySelector(`[data-preview-file-rail]`)?.getBoundingClientRect().width??ne;ce.current={pointerId:e.pointerId,startWidth:t,startX:e.clientX},e.currentTarget.setPointerCapture(e.pointerId),F(!0),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`},[O,ne]),We=(0,J.useCallback)(e=>{let t=ce.current,n=M.current;if(!t||!n||t.pointerId!==e.pointerId)return;e.preventDefault();let r=Bh(t,n.clientWidth,e.clientX);ae(r)},[]),Ge=(0,J.useCallback)(e=>{let t=ce.current;if(!t||t.pointerId!==e.pointerId)return;let n=M.current,r=n?Bh(t,n.clientWidth,e.clientX):t.startWidth;ce.current=null,F(!1),ae(r),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`),typeof window<`u`&&P(Ph,r,s)},[]);(0,J.useEffect)(()=>()=>{document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)},[]);let Ke=(0,J.useCallback)(()=>{ve()},[ve]),qe=(0,J.useCallback)(()=>{O&&(ce.current=null,F(!1),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)),k(e=>!e)},[O]),Je=C!==null||Ne.status===`blocked`,Ye=(0,J.useCallback)(()=>{T(null),Ne.status===`blocked`&&Ne.reset()},[Ne]),Xe=(0,J.useCallback)(()=>{let e=C;if(T(null),L(null),e){y(e);return}Ne.status===`blocked`&&Ne.proceed()},[L,Ne,C]),Ze=(0,J.useCallback)(async()=>{await ze()&&Xe()},[Xe,ze]),Qe=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 px-1 [-webkit-app-region:no-drag]`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:`File Preview`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65`,children:[(0,X.jsx)(`span`,{children:`Workspace tree`}),ge?(0,X.jsx)(rr,{variant:`warning`,size:`sm`,className:`rounded-md px-1.5 py-0 text-[9px]`,children:`Truncated`}):null]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[r?null:(0,X.jsx)(Un,{"aria-label":O?`Hide workspace tree`:`Show workspace tree`,"aria-pressed":O,title:O?`Hide workspace tree`:`Show workspace tree`,variant:`outline`,size:`icon-xs`,className:`shrink-0`,onClick:qe,children:O?(0,X.jsx)(xr,{className:`size-3`}):(0,X.jsx)(Sr,{className:`size-3`})}),(0,X.jsx)(Un,{"aria-label":`Refresh workspace tree`,title:`Refresh workspace tree`,variant:`outline`,size:`icon-xs`,className:`shrink-0`,disabled:!u?.environmentId||!_||B,onClick:Ke,children:(0,X.jsx)(vn,{className:q(`size-3`,B&&`animate-spin`)})}),(0,X.jsx)(sr,{"aria-label":A?`Disable preview line wrapping`:`Enable preview line wrapping`,title:A?`Disable line wrapping`:`Enable line wrapping`,variant:`outline`,size:`xs`,pressed:A,onPressedChange:e=>{j(!!e)},children:(0,X.jsx)(Er,{className:`size-3`})})]})]}),$e=Ce?.state===`too-large`?(0,X.jsxs)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:[`File is too large to preview (`,Ce.sizeBytes,` bytes). Limit is`,` `,Ce.limitBytes,` bytes.`]}):we.isLoading&&!Te?(0,X.jsx)(rn,{label:`Loading file preview...`}):ke&&!Te?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:ke}):(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 p-2`,children:[(0,X.jsx)(`style`,{children:Rh}),(0,X.jsxs)(`div`,{className:`preview-panel-file-card flex h-full min-h-0 flex-col overflow-hidden rounded-md border border-border/70 bg-[color:color-mix(in_srgb,var(--card)_90%,var(--background))]`,children:[(0,X.jsxs)(`div`,{className:`preview-panel-file-toolbar flex min-h-10 shrink-0 items-center gap-3 border-b border-border/70 bg-[color:color-mix(in_srgb,var(--card)_94%,var(--foreground))] px-3 py-1.5 text-foreground`,children:[(0,X.jsxs)(`div`,{className:`preview-panel-file-identity flex min-w-0 flex-1 items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-[12px] font-medium`,children:v}),je?(0,X.jsx)(`span`,{"aria-label":`Unsaved changes`,className:`size-1.5 shrink-0 rounded-full bg-primary`,title:`Unsaved changes`}):null,U?.saveStatus===`saving`?(0,X.jsxs)(`span`,{"aria-live":`polite`,className:`flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(be,{className:`size-3 animate-spin`}),` Saving`]}):null,!r&&H?.lineEnding===`mixed`?(0,X.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:`Read-only · mixed line endings`}):null]}),Me&&U?(0,X.jsxs)(`div`,{className:`preview-panel-file-actions flex shrink-0 items-center gap-1`,children:[(0,X.jsx)(Un,{"aria-label":`Discard file changes`,disabled:!je||U.saveStatus===`saving`,onClick:Re,size:`xs`,variant:`ghost`,children:`Discard`}),(0,X.jsxs)(Un,{"aria-label":`Save file`,disabled:!Be,onClick:()=>void ze(),size:`xs`,title:`Save file (Ctrl/⌘ S)`,children:[U.saveStatus===`saving`?(0,X.jsx)(be,{className:`animate-spin`}):(0,X.jsx)(yn,{}),`Save`,(0,X.jsx)(`span`,{className:`ml-0.5 text-[9px] opacity-70`,children:`⌘S`})]})]}):null]}),U?.errorMessage?(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/60 p-2`,children:(0,X.jsxs)(qn,{variant:U.saveStatus===`conflict`?`warning`:`error`,className:`rounded-lg px-3 py-2 text-[11px]`,children:[U.saveStatus===`conflict`?(0,X.jsx)(Tn,{className:`size-3.5`}):(0,X.jsx)(Ee,{className:`size-3.5`}),(0,X.jsx)(Gn,{className:`text-[11px]`,children:U.errorReason===`deleted`?`File removed on disk`:U.saveStatus===`conflict`?`File changed on disk`:`Couldn’t save file`}),(0,X.jsxs)(Kn,{className:`gap-2 text-[11px] leading-4`,children:[(0,X.jsx)(`span`,{children:U.errorMessage}),U.saveStatus===`conflict`?(0,X.jsx)(Un,{className:`self-start`,onClick:U.errorReason===`deleted`?Re:()=>void Le(),size:`xs`,variant:`outline`,children:U.errorReason===`deleted`?`Close file`:`Reload`}):null]})]})}):ke?(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 px-3 py-2 text-[11px] text-destructive`,children:[`Refresh failed: `,ke]}):null,Oe===`image`&&De?.base64?(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 justify-center overflow-auto bg-background/70 p-3`,children:(0,X.jsx)(`img`,{alt:v??void 0,className:`max-h-full max-w-full object-contain`,src:`data:${V??`image/png`};base64,${De.base64}`})}):Me&&U?(0,X.jsx)(oh,{cacheKey:U.key,className:`preview-panel-diffs-file`,contents:U.contents,filePath:U.relativePath,language:Eh(U.relativePath),onChange:Ie,options:He}):Ve?(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,X.jsx)(zl,{file:Ve,className:`preview-panel-diffs-file`,options:He})}):(0,X.jsx)(`pre`,{className:q(`min-h-0 flex-1 bg-transparent p-3 font-mono text-[11px] leading-5 text-muted-foreground/90`,A?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:De?.contents??``})]})]}),et=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,X.jsx)(`div`,{className:`shrink-0 border-b border-border/60 p-2`,children:(0,X.jsxs)(`label`,{className:`relative block`,children:[(0,X.jsx)(bn,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground/65`}),(0,X.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(D(``),e.currentTarget.blur())},placeholder:`Filter files...`,"aria-label":`Filter files`,className:`h-8 w-full rounded-md border border-border/70 bg-background/65 pl-8 pr-3 text-xs text-foreground outline-none transition-[border-color,background-color,box-shadow] placeholder:text-muted-foreground/55 focus:border-ring/60 focus:bg-background focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_18%,transparent)]`})]})}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[me||ge?(0,X.jsxs)(qn,{variant:me?`error`:`warning`,className:`mb-2 rounded-lg border-border/70 px-3 py-2 text-[11px]`,children:[me?(0,X.jsx)(Ee,{className:`size-3.5`}):(0,X.jsx)(Tn,{className:`size-3.5`}),(0,X.jsx)(Gn,{className:`text-[11px]`,children:me?`Workspace tree refresh failed`:`Workspace tree is truncated`}),(0,X.jsx)(Kn,{className:`gap-1 text-[11px] leading-4`,children:me?(0,X.jsx)(`span`,{children:me}):(0,X.jsx)(`span`,{children:`Only the first indexed workspace entries are shown here, so some files may be omitted from preview.`})})]}):null,ye.length===0?(0,X.jsx)(`div`,{className:`px-2 py-6 text-center text-xs leading-5 text-muted-foreground/70`,children:`No files match this filter.`}):(0,X.jsx)(ud,{files:ye,allDirectoriesExpanded:xe,resolvedTheme:t,onSelectFile:Fe,selectedFilePath:v,showStats:!1})]})]});return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Tt,{mode:e,header:Qe,children:u?z.isLoading&&!z.data?(0,X.jsx)(rn,{label:`Loading project tree...`}):me&&!z.data?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:me}):(z.data?.entries.length??0)===0?(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`No project files available yet.`}):r?(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:v?(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,X.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center gap-1 border-b border-border/60 px-1.5`,children:[(0,X.jsx)(Un,{size:`icon`,variant:`ghost`,"aria-label":`Back to workspace tree`,className:`shrink-0`,onClick:()=>y(null),children:(0,X.jsx)(_e,{})}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:v})]}),$e]}):et}):(0,X.jsxs)(`div`,{ref:M,className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,X.jsx)(`div`,{"data-preview-content-panel":!0,className:`flex min-h-0 min-w-0 flex-1 flex-col transition-[min-width] duration-[320ms] ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none`,children:v?$e:(0,X.jsx)(Gh,{})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":`Resize workspace tree`,"aria-hidden":!O||void 0,className:q(`group relative shrink-0 overflow-hidden bg-background transition-[width,opacity,background-color] duration-[360ms] ease-[cubic-bezier(0.16,1,0.3,1)] hover:bg-accent/40 motion-reduce:transition-none`,O?`w-2 cursor-ew-resize opacity-100`:`w-0 opacity-0`),disabled:!O,onPointerDown:Ue,onPointerMove:We,onPointerUp:Ge,onPointerCancel:Ge,children:(0,X.jsx)(`span`,{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border/80 group-hover:bg-border`})}),(0,X.jsx)(Wh,{width:ne,open:O,resizing:se,children:et})]}):(0,X.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:`Select a thread to preview files.`})}),(0,X.jsx)(tr,{open:Je,onOpenChange:e=>{e||Ye()},children:(0,X.jsxs)(Qn,{children:[(0,X.jsxs)(Xn,{children:[(0,X.jsx)(er,{children:`Save changes before continuing?`}),(0,X.jsx)($n,{children:v?`${v} has unsaved changes.`:`This file has unsaved changes.`})]}),(0,X.jsxs)(Zn,{children:[(0,X.jsx)(Un,{onClick:Ye,variant:`outline`,children:`Cancel`}),(0,X.jsx)(Un,{disabled:U?.saveStatus===`saving`,onClick:Xe,variant:`destructive-outline`,children:C?`Discard & Open`:`Discard & Continue`}),(0,X.jsxs)(Un,{disabled:!Be,onClick:()=>void Ze(),children:[U?.saveStatus===`saving`?(0,X.jsx)(be,{className:`animate-spin`}):(0,X.jsx)(yn,{}),C?`Save & Open`:`Save & Continue`]})]})]})})]})}function qh(){return{phase:`awaiting-config`,lastSequence:null}}var Jh=2**32,Yh=1024;function Xh(e,t,n){if(t.deviceId!==n)return{state:e,action:{kind:`ignore`},requestKeyframe:!1};if(t.codecConfig)return{state:{phase:`awaiting-keyframe`,lastSequence:t.sequence},action:{kind:`configure`},requestKeyframe:!1};if(e.phase===`awaiting-config`)return{state:e,action:{kind:`drop`},requestKeyframe:!1};if(e.lastSequence!==null){let n=(t.sequence-e.lastSequence+Jh)%Jh;if(n===0||n>Yh)return{state:e,action:{kind:`drop`},requestKeyframe:!1};if(n>1&&!t.keyframe&&e.phase===`streaming`)return{state:{phase:`awaiting-keyframe`,lastSequence:t.sequence},action:{kind:`drop`},requestKeyframe:!0}}return e.phase===`awaiting-keyframe`&&!t.keyframe?{state:{...e,lastSequence:t.sequence},action:{kind:`drop`},requestKeyframe:!1}:{state:{phase:`streaming`,lastSequence:t.sequence},action:{kind:`decode`,keyframe:t.keyframe},requestKeyframe:!1}}function Zh(e,t,n){let r=Math.min(e.displayWidth/e.frameWidth,e.displayHeight/e.frameHeight);if(!Number.isFinite(r)||r<=0)return null;let i=e.frameWidth*r,a=e.frameHeight*r,o=t-(e.displayWidth-i)/2,s=n-(e.displayHeight-a)/2;return o<0||s<0||o>i||s>a?null:{x:Math.round(o/i*e.pointWidth),y:Math.round(s/a*e.pointHeight)}}function Qh(e){let t={Enter:40,Escape:41,Backspace:42,Tab:43," ":44,ArrowRight:79,ArrowLeft:80,ArrowDown:81,ArrowUp:82},n=e.toLowerCase();return n>=`a`&&n<=`z`&&n.length===1?4+n.charCodeAt(0)-97:n===`0`?39:n>=`1`&&n<=`9`&&n.length===1?30+n.charCodeAt(0)-49:t[e]??null}function $h(e){for(let t=0;t+7<e.byteLength;t+=1){let n=e[t]===0&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1,r=e[t]===0&&e[t+1]===0&&e[t+2]===1;if(!n&&!r)continue;let i=t+(n?4:3);if(((e[i]??0)&31)==7)return`avc1.${[e[i+1],e[i+2],e[i+3]].map(e=>(e??0).toString(16).padStart(2,`0`)).join(``)}`}return null}function eg(e){let{canvasRef:t,udid:n,openFrameSource:r}=e,[i,a]=(0,J.useState)(`idle`),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(null),u=(0,J.useRef)(0);return(0,J.useEffect)(()=>{if(!n||!r){a(`idle`),s(null);return}if(typeof globalThis.VideoDecoder!=`function`||typeof globalThis.EncodedVideoChunk!=`function`){a(`unsupported`);return}let e=++u.current,i=qh(),o=null,c=null,d=null,f=()=>e===u.current;a(`connecting`),s(null);let p=()=>{d=null;try{o?.state!==`closed`&&o?.close()}catch{}o=null},m=e=>{f()&&(p(),i=qh(),s(e),a(`error`))},h=e=>{let n=$h(e.payload);if(!n){m(`The simulator sent video parameters Ryco could not read.`),c?.requestResync();return}p();let r=new VideoDecoder({output:e=>{try{if(!f())return;let n=t.current;if(!n)return;(n.width!==e.displayWidth||n.height!==e.displayHeight)&&(n.width=e.displayWidth,n.height=e.displayHeight,l({width:e.displayWidth,height:e.displayHeight})),n.getContext(`2d`)?.drawImage(e,0,0),a(`streaming`),s(null)}finally{e.close()}},error:e=>{m(e.message||`The simulator video decoder failed.`),c?.requestResync()}});try{r.configure({codec:n,optimizeForLatency:!0}),o=r,d=e.payload.slice()}catch(e){m(e instanceof Error?e.message:`Video decoder setup failed.`)}},g=(e,t)=>{if(!o||o.state!==`configured`)return;let n=e.payload;if(t&&d){let e=new Uint8Array(d.byteLength+n.byteLength);e.set(d),e.set(n,d.byteLength),n=e,d=null}try{o.decode(new EncodedVideoChunk({type:t?`key`:`delta`,timestamp:Math.round(e.header.timestampMs*1e3),data:n}))}catch(e){m(e instanceof Error?e.message:`A simulator frame could not be decoded.`),c?.requestResync()}};return c=r(n,{onFrame:e=>{if(!f())return;let t=Xh(i,e.header,n);i=t.state,t.requestKeyframe&&c?.requestResync(),t.action.kind===`configure`&&h(e),t.action.kind===`decode`&&g(e,t.action.keyframe)},onReset:e=>{f()&&(p(),i=qh(),e===`decode-failed`&&s(`The simulator sent a malformed frame.`),a(`recovering`))}}),()=>{u.current+=1,c?.close(),p()}},[t,r,n]),{status:i,error:o,dimensions:c}}var tg=750,ng=524288,rg=15e3;function ig(e){let t=Math.ceil(Math.max(0,e)/ng*1e3);return Math.min(rg,Math.max(tg,t))}function ag(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n}function og(e){let t=ag(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}function sg(e){let{canvasRef:t,enabled:n,screenshot:r,udid:i}=e,[a,o]=(0,J.useState)(`idle`),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null);return(0,J.useEffect)(()=>{if(!n||!i||!r){o(`idle`),c(null);return}let e=!0,a=null,s=document.visibilityState!==`hidden`,l=!0,d=!1;o(`connecting`);let f=()=>{a!==null&&(clearTimeout(a),a=null)},p=()=>e&&s&&l,m=e=>{f(),!(!p()||d)&&(a=setTimeout(()=>{a=null,h()},e))},h=async()=>{if(!p()||d)return;d=!0;let n=tg;try{let e=await r({udid:i});if(n=ig(e.bytesBase64.length),!p())return;let a=await createImageBitmap(new Blob([og(e.bytesBase64)],{type:e.mimeType}));try{if(!p())return;let e=t.current;if(!e)return;(e.width!==a.width||e.height!==a.height)&&(e.width=a.width,e.height=a.height,u({width:a.width,height:a.height})),e.getContext(`2d`)?.drawImage(a,0,0),o(`streaming`),c(null)}finally{a.close()}}catch(t){if(!e)return;o(`recovering`),c(t instanceof Error?t.message:`The hosted simulator preview disconnected.`)}finally{d=!1,p()&&m(n)}},g=()=>{s=document.visibilityState!==`hidden`,s?m(0):f()};document.addEventListener(`visibilitychange`,g);let _=t.current,v=_&&typeof IntersectionObserver==`function`?new IntersectionObserver(e=>{l=e.some(e=>e.isIntersecting),l?m(0):f()}):null;return v?.observe(_),m(0),()=>{e=!1,f(),v?.disconnect(),document.removeEventListener(`visibilitychange`,g)}},[t,n,r,i]),{status:a,error:s,dimensions:l}}var cg=5e3;function lg(e,t){return e instanceof Error&&e.message.trim()?e.message:t}function ug(e){return e===`booted`?`Booted`:e===`booting`?`Booting`:e===`shutting-down`?`Shutting down`:`Shut down`}function dg(e,t){return t===`waiting-for-display`?`Waiting for the display…`:t===`connecting`?`Connecting the live screen…`:t===`booting`||e.state===`booting`?`Starting the simulator…`:`Connecting…`}function fg(e){let t=[];return e.metaKey&&t.push(`command`),e.shiftKey&&t.push(`shift`),e.altKey&&t.push(`option`),e.ctrlKey&&t.push(`control`),t}function pg(e){let t=(0,Y.c)(15),n=e.availability;if(!n){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center`,children:[(0,X.jsx)(be,{className:`size-5 animate-spin text-muted-foreground`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Checking simulator support…`})]}),t[0]=e):e=t[0],e}if(n.kind===`unsupported-platform`){let e,r;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsx)(br,{className:`size-7 text-muted-foreground`}),r=(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`iOS Simulator needs a Mac`}),t[1]=e,t[2]=r):(e=t[1],r=t[2]);let i;return t[3]===n.platform?i=t[4]:(i=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[e,r,(0,X.jsxs)(`p`,{className:`mt-1 max-w-sm text-xs leading-relaxed text-muted-foreground`,children:[`This environment runs on `,n.platform,`. Connect Ryco to a macOS environment with Xcode to use the simulator workspace.`]})]}),t[3]=n.platform,t[4]=i),i}if(n.kind===`helper-unavailable`){let e,r;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,X.jsx)(br,{className:`size-7 text-amber-500`}),r=(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Simulator helper could not start`}),t[5]=e,t[6]=r):(e=t[5],r=t[6]);let i;return t[7]===n.message?i=t[8]:(i=(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[e,r,(0,X.jsx)(`p`,{className:`mt-1 max-w-sm text-xs leading-relaxed text-muted-foreground`,children:n.message})]}),t[7]=n.message,t[8]=i),i}if(n.kind!==`setup-required`||n.steps.filter(gg).every(hg))return null;let r,i;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`Set up the iOS Simulator`}),i=(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Ryco checks these steps automatically every few seconds.`}),t[9]=r,t[10]=i):(r=t[9],i=t[10]);let a;t[11]===n.steps?a=t[12]:(a=n.steps.map(mg),t[11]=n.steps,t[12]=a);let o;return t[13]===a?o=t[14]:(o=(0,X.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-md`,children:[r,i,(0,X.jsx)(`div`,{className:`mt-5 space-y-2`,children:a})]})}),t[13]=a,t[14]=o),o}function mg(e){return(0,X.jsxs)(`div`,{className:`flex gap-3 rounded-md border border-border/60 p-3`,children:[(0,X.jsx)(`span`,{className:q(`mt-0.5 size-2 shrink-0 rounded-full`,e.done?`bg-emerald-500`:`bg-amber-500`)}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium`,children:e.label}),e.detail?(0,X.jsx)(`p`,{className:`mt-1 break-words font-mono text-[10px] text-muted-foreground`,children:e.detail}):null]})]},e.id)}function hg(e){return e.id===`build-device-helper`}function gg(e){return!e.done}function _g(e){let{environmentId:t,threadId:n}=e,i=(0,J.useRef)(null),a=(0,J.useMemo)(()=>t&&n?o(r(t,n)):null,[t,n]),s=O(e=>t?e.environmentById[t]:void 0),c=O(e=>a?e.threadByKey[a]:void 0),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)({kind:`idle`}),[h,g]=(0,J.useState)(null),_=t?C(t)?.device:void 0,v=t?S(t)?.client.device:void 0,y=s?.generation??0,b=O(e=>e.applyThreadSnapshot),x=O(e=>e.applyInventory),w=(0,J.useCallback)(async()=>{if(!t||!n||!_)return;let[e,r]=await Promise.all([_.list({includeShutdown:!0}),_.getThreadState({threadId:n})]);x(t,y,e.devices,e.availability),b(t,y,r)},[_,x,b,t,y,n]),T=s?.availability?.kind===`setup-required`||s?.availability?.kind===`helper-unavailable`;(0,J.useEffect)(()=>{if(w().catch(()=>void 0),!T)return;let e=setInterval(()=>void w().catch(()=>void 0),cg);return()=>clearInterval(e)},[T,w]);let E=s?.devices??c?.devices??[],D=E.find(e=>e.udid===c?.attachedDeviceUdid)??E.find(e=>e.udid===d)??null;(0,J.useEffect)(()=>{d&&c?.attachedDeviceUdid===d&&f(null)},[d,c?.attachedDeviceUdid]);let k=(0,J.useCallback)(async(e,t)=>{u(!0);try{await e()}catch(e){De.add({type:`error`,title:t,description:lg(e,`The simulator did not respond.`)})}finally{u(!1)}},[]),A=(0,J.useCallback)(e=>{!_||!n||(f(e.udid),k(async()=>{if(e.state===`shutdown`){let t=await _.boot({udid:e.udid});if(t.kind===`boot-limit-reached`){f(null),g({requested:e,candidates:t.rycoBooted,limit:t.limit});return}}b(t,y,await _.attach({threadId:n,udid:e.udid}))},`Could not open that simulator`))},[_,b,t,y,k,n]),j=(0,J.useCallback)(e=>{if(!h||!_||!n||!t)return;let r=h;g(null),f(r.requested.udid),k(async()=>{await _.shutdown({udid:e.udid});let i=await _.boot({udid:r.requested.udid});if(i.kind===`boot-limit-reached`){f(null),g({...r,candidates:i.rycoBooted,limit:i.limit});return}b(t,y,await _.attach({threadId:n,udid:r.requested.udid}))},`Could not free a simulator slot`)},[_,b,h,t,y,k,n]),M=eg({canvasRef:i,udid:D?.state===`booted`?D.udid:null,...v?.openFrameSource?{openFrameSource:v.openFrameSource}:{}}),ee=sg({canvasRef:i,udid:D?.state===`booted`?D.udid:null,enabled:!v?.openFrameSource,screenshot:_?e=>_.screenshot(e):null}),N=v?.openFrameSource?M.status:ee.status,te=v?.openFrameSource?M.error:ee.error,P=v?.openFrameSource?M.dimensions:ee.dimensions,ne=(0,J.useRef)(null),re=(0,J.useCallback)(e=>{let t=i.current;if(!t||!P)return null;let n=t.getBoundingClientRect(),r=D?.geometry?.scale??(P.width>1400?2:3);return Zh({frameWidth:P.width,frameHeight:P.height,displayWidth:n.width,displayHeight:n.height,pointWidth:D?.geometry?.pointWidth??P.width/r,pointHeight:D?.geometry?.pointHeight??P.height/r},e.clientX-n.left,e.clientY-n.top)},[D?.geometry,P]),ie=(0,J.useCallback)(e=>{e.currentTarget.focus(),e.currentTarget.setPointerCapture(e.pointerId),ne.current={point:re(e),at:performance.now()}},[re]),ae=(0,J.useCallback)(e=>{let t=ne.current;if(ne.current=null,!t||!D||!_)return;let n=re(e);!t.point||!n||(Math.hypot(n.x-t.point.x,n.y-t.point.y)<=8?_.tap({udid:D.udid,x:n.x,y:n.y}):_.swipe({udid:D.udid,fromX:t.point.x,fromY:t.point.y,toX:n.x,toY:n.y,durationMs:Math.max(16,Math.round(performance.now()-t.at))})).catch(e=>De.add({type:`error`,title:`Simulator input failed`,description:lg(e,`The input could not be delivered.`)}))},[_,D,re]),oe=(0,J.useCallback)((e,t)=>{if(!D||!_||e.metaKey||e.ctrlKey)return;let n=Qh(e.key);n!==null&&(e.preventDefault(),_.keyEvent({udid:D.udid,keyCode:n,modifiers:fg(e),direction:t}).catch(()=>void 0))},[_,D]),se=(0,J.useCallback)(e=>{!D||!_||k(()=>_.pressButton({udid:D.udid,button:e}),`Simulator button failed`)},[_,D,k]),F=(0,J.useCallback)(()=>{!D||!_||k(async()=>{let e=await _.screenshot({udid:D.udid,save:!0});De.add({type:`success`,title:`Screenshot saved`,description:e.path??e.name})},`Could not save the screenshot`)},[_,D,k]),ce=(0,J.useCallback)(()=>{if(!(!D||!_||p.kind===`starting`||p.kind===`stopping`)){if(p.kind===`idle`){m({kind:`starting`}),_.startRecording({udid:D.udid}).then(e=>m({kind:`recording`,path:e.path}),e=>{m({kind:`idle`}),De.add({type:`error`,title:`Could not start recording`,description:lg(e,`Recording failed.`)})});return}m({kind:`stopping`}),_.stopRecording({udid:D.udid}).then(e=>{m({kind:`idle`}),De.add({type:`success`,title:`Recording saved`,description:e.path})},e=>{m({kind:`idle`}),De.add({type:`error`,title:`Could not stop recording`,description:lg(e,`The recording may be incomplete.`)})})}},[_,D,p]);if(!t||!n||!_)return(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-8 text-center`,children:[(0,X.jsx)(br,{className:`size-7 text-muted-foreground`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Simulator unavailable`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`This thread has no device connection.`})]});let le=(0,X.jsx)(pg,{availability:s?.availability??null});if(!s?.availability||s.availability.kind===`unsupported-platform`||s.availability.kind===`helper-unavailable`||s.availability.kind===`setup-required`&&s.availability.steps.some(e=>!e.done&&e.id!==`build-device-helper`))return le;let ue=s.availability?.kind===`degraded`?s.availability.capabilities.filter(e=>!e.ok):[];return(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex min-h-11 shrink-0 items-center gap-2 border-b border-border/60 px-3`,children:[(0,X.jsx)(xn,{className:`size-4 text-muted-foreground`}),(0,X.jsxs)(`select`,{"aria-label":`Choose an iOS Simulator`,className:`min-w-0 max-w-72 flex-1 bg-transparent text-xs font-medium outline-none`,disabled:l,value:D?.udid??``,onChange:e=>{let t=E.find(t=>t.udid===e.target.value);t&&A(t)},children:[(0,X.jsx)(`option`,{value:``,disabled:!0,children:`Choose a simulator`}),E.toSorted((e,t)=>Number(t.state===`booted`)-Number(e.state===`booted`)||e.name.localeCompare(t.name)).map(e=>(0,X.jsxs)(`option`,{value:e.udid,disabled:e.state===`booting`||e.state===`shutting-down`,children:[e.name,` — `,e.runtime,` · `,ug(e.state)]},e.udid))]}),c?.agentActive?(0,X.jsx)(`span`,{className:`rounded-full bg-sky-500/15 px-2 py-0.5 text-[10px] font-medium text-sky-500`,children:`Agent controlling`}):null,(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,"aria-label":`Refresh simulators`,onClick:()=>void w(),children:(0,X.jsx)(vn,{className:`size-3.5`})})]}),ue.length>0?(0,X.jsxs)(`div`,{className:`border-b border-amber-500/20 bg-amber-500/8 px-3 py-1.5 text-[10px] text-amber-700 dark:text-amber-300`,children:[`Limited by this Xcode: `,ue.map(e=>e.id).join(`, `),`.`]}):null,(0,X.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-muted/25 p-4 sm:p-6`,children:D?(0,X.jsxs)(`div`,{className:q(`relative flex max-h-full max-w-full overflow-hidden border-[7px] border-zinc-900 bg-black shadow-xl`,D.family===`tablet`||D.name.toLowerCase().includes(`ipad`)?`aspect-[4/3] w-[min(88%,52rem)] rounded-[1.8rem]`:`aspect-[9/19.5] h-full max-h-[min(100%,58rem)] rounded-[2.4rem]`),children:[(0,X.jsx)(`canvas`,{ref:i,tabIndex:0,"aria-label":`${D.name} screen`,className:`h-full w-full touch-none object-contain outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-sky-400`,onPointerDown:ie,onPointerUp:ae,onPointerCancel:()=>{ne.current=null},onKeyDown:e=>oe(e,`down`),onKeyUp:e=>oe(e,`up`)}),N===`streaming`?null:(0,X.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 flex flex-col items-center justify-center bg-black/75 p-6 text-center text-white`,children:[(0,X.jsx)(be,{className:`size-5 animate-spin text-white/60`}),(0,X.jsx)(`p`,{className:`mt-3 text-xs font-medium`,children:N===`unsupported`?`This browser does not support WebCodecs.`:N===`recovering`?`Reconnecting the live screen…`:dg(D,c?.attachPhase)}),te?(0,X.jsx)(`p`,{className:`mt-2 max-w-52 text-[10px] text-white/60`,children:te}):null]})]}):(0,X.jsxs)(`div`,{className:`max-w-xs text-center`,children:[(0,X.jsx)(xn,{className:`mx-auto size-8 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm font-medium`,children:`Choose a simulator`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Boot a device or attach one that is already running. Its screen will stay beside your conversation.`})]})}),(0,X.jsxs)(`div`,{className:`flex min-h-12 shrink-0 items-center justify-center gap-0.5 border-t border-border/60 bg-card/40 px-2`,children:[(0,X.jsx)(vg,{icon:gr,label:`Home`,disabled:!D||l,onClick:()=>se(`home`)}),(0,X.jsx)(vg,{icon:tn,label:`Lock`,disabled:!D||l,onClick:()=>se(`lock`)}),(0,X.jsx)(vg,{icon:Dr,label:`Volume down`,disabled:!D||l,onClick:()=>se(`volume-down`)}),(0,X.jsx)(vg,{icon:Or,label:`Volume up`,disabled:!D||l,onClick:()=>se(`volume-up`)}),(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),(0,X.jsx)(vg,{icon:dr,label:`Screenshot`,disabled:!D||l,onClick:F}),(0,X.jsx)(vg,{icon:p.kind===`recording`||p.kind===`stopping`?fr:mr,label:p.kind===`recording`?`Stop recording`:`Record screen`,active:p.kind!==`idle`,disabled:!D||p.kind===`starting`||p.kind===`stopping`,onClick:ce}),(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`}),(0,X.jsx)(vg,{icon:En,label:`Detach`,disabled:!D||l,onClick:()=>void k(async()=>b(t,y,await _.detach({threadId:n})),`Could not detach the simulator`)}),(0,X.jsx)(vg,{icon:wr,label:`Shut down`,disabled:!D||l,onClick:()=>{D&&k(()=>_.shutdown({udid:D.udid}),`Could not shut down the simulator`)}})]}),h?(0,X.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-center justify-center bg-background/75 p-6 backdrop-blur-sm`,children:(0,X.jsxs)(`div`,{className:`w-full max-w-sm rounded-xl border border-border bg-card p-5 shadow-xl`,children:[(0,X.jsx)(`p`,{className:`text-sm font-semibold`,children:`Simulator boot limit reached`}),(0,X.jsxs)(`p`,{className:`mt-2 text-xs leading-relaxed text-muted-foreground`,children:[`Ryco keeps at most `,h.limit,` simulators it booted running. Shut down one to open `,h.requested.name,`.`]}),(0,X.jsx)(`div`,{className:`mt-4 space-y-2`,children:h.candidates.map(e=>(0,X.jsxs)(Un,{variant:`outline`,className:`w-full justify-between`,onClick:()=>j(e),children:[(0,X.jsxs)(`span`,{className:`truncate`,children:[`Shut down `,e.name]}),(0,X.jsx)(wr,{className:`size-3.5`})]},e.udid))}),(0,X.jsx)(Un,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>g(null),children:`Cancel`})]})}):null]})}function vg(e){let t=(0,Y.c)(11),n=e.icon,r=e.label,i=e.label,a=e.active,o=e.disabled,s=e.active&&`text-red-500`,c;t[0]===s?c=t[1]:(c=q(s),t[0]=s,t[1]=c);let l;t[2]===n?l=t[3]:(l=(0,X.jsx)(n,{className:`size-4`}),t[2]=n,t[3]=l);let u;return t[4]!==e.active||t[5]!==e.disabled||t[6]!==e.label||t[7]!==e.onClick||t[8]!==c||t[9]!==l?(u=(0,X.jsx)(Un,{size:`icon-sm`,variant:`ghost`,title:r,"aria-label":i,"aria-pressed":a,disabled:o,className:c,onClick:e.onClick,children:l}),t[4]=e.active,t[5]=e.disabled,t[6]=e.label,t[7]=e.onClick,t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function yg(e){return e===`running`?`in_progress`:e===`failed`?`review`:e===`finished`?`done`:`idle`}function bg(e){return e===`running`?`Working`:e===`failed`?`Needs review`:e===`finished`?`Finished`:e===`interrupted`?`Stopped`:`Idle`}function xg(e){return encodeURIComponent(e??`none`).replace(/%/g,`_`)}function Sg(e){return`thread-workspace-tab-${xg(e)}`}function Cg(e){return`thread-workspace-panel-${xg(e)}`}function wg(e){let t=(0,Y.c)(17),n=e.active?`text-foreground`:`text-muted-foreground`,r;t[0]===n?r=t[1]:(r=q(`size-3.5 shrink-0`,n),t[0]=n,t[1]=r);let i=r;if(e.tab.mode===`agent`){let n=e.tab.avatarKey??e.tab.agentKey,r=!e.active&&`opacity-70`,i;t[2]===r?i=t[3]:(i=q(`size-3.5 shrink-0`,r),t[2]=r,t[3]=i);let a;return t[4]!==n||t[5]!==i?(a=(0,X.jsx)(kt,{name:n,className:i}),t[4]=n,t[5]=i,t[6]=a):a=t[6],a}if(e.tab.key===`review`){let e;return t[7]===i?e=t[8]:(e=(0,X.jsx)(hr,{className:i}),t[7]=i,t[8]=e),e}if(e.tab.key===`terminal`){let e;return t[9]===i?e=t[10]:(e=(0,X.jsx)(wn,{className:i}),t[9]=i,t[10]=e),e}if(e.tab.key===`simulator`){let e;return t[11]===i?e=t[12]:(e=(0,X.jsx)(xn,{className:i}),t[11]=i,t[12]=e),e}if(e.tab.key===`agents`){let e;return t[13]===i?e=t[14]:(e=(0,X.jsx)(ve,{className:i}),t[13]=i,t[14]=e),e}let a;return t[15]===i?a=t[16]:(a=(0,X.jsx)(Oe,{className:i}),t[15]=i,t[16]=a),a}function Tg(e){let t=(0,Y.c)(8),n;if(t[0]!==e.agent.status){let r=yg(e.agent.status);n=Yn(r,`truncate`),t[0]=e.agent.status,t[1]=n}else n=t[1];let r;t[2]===e.agent.name?r=t[3]:(r=Jn(e.agent.name,{durationSeconds:2.2}),t[2]=e.agent.name,t[3]=r);let i;return t[4]!==e.agent.name||t[5]!==n||t[6]!==r?(i=(0,X.jsx)(`span`,{className:n,style:r,children:e.agent.name}),t[4]=e.agent.name,t[5]=n,t[6]=r,t[7]=i):i=t[7],i}function Eg(e){let t=(0,Y.c)(43);if(!e.subagent){let n,r,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`mx-auto flex size-10 items-center justify-center rounded-md border border-border/70 bg-card/60 text-muted-foreground`,children:(0,X.jsx)(yr,{className:`size-4`})}),r=(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:`Subagent unavailable`}),i=(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`This tab points to a subagent that is no longer present in the current thread activity.`}),t[0]=n,t[1]=r,t[2]=i):(n=t[0],r=t[1],i=t[2]);let a;t[3]===e.agentKey?a=t[4]:(a=e.agentKey?(0,X.jsx)(`p`,{className:`mt-2 truncate font-mono text-[11px] text-muted-foreground/60`,children:e.agentKey}):null,t[3]=e.agentKey,t[4]=a);let o;return t[5]===a?o=t[6]:(o=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center p-6 text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-72`,children:[n,r,i,a]})}),t[5]=a,t[6]=o),o}let n=e.subagent.avatarKey??e.subagent.key,r;t[7]===n?r=t[8]:(r=(0,X.jsx)(kt,{name:n,className:`size-4`}),t[7]=n,t[8]=r);let i;t[9]===e.subagent?i=t[10]:(i=(0,X.jsx)(`p`,{className:`min-w-0 flex-1 text-sm font-medium`,children:(0,X.jsx)(Tg,{agent:e.subagent})}),t[9]=e.subagent,t[10]=i);let a;t[11]===e.subagent.role?a=t[12]:(a=e.subagent.role?(0,X.jsx)(`span`,{className:`max-w-36 shrink-0 truncate rounded-sm border border-border/60 bg-background/40 px-1.5 py-px text-[10px] font-medium text-muted-foreground`,children:e.subagent.role}):null,t[11]=e.subagent.role,t[12]=a);let o;t[13]===e.subagent.status?o=t[14]:(o=bg(e.subagent.status),t[13]=e.subagent.status,t[14]=o);let s;t[15]===o?s=t[16]:(s=(0,X.jsx)(`span`,{className:`shrink-0 rounded-md border border-border/70 px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:o}),t[15]=o,t[16]=s);let c;t[17]!==r||t[18]!==i||t[19]!==a||t[20]!==s?(c=(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[r,i,a,s]}),t[17]=r,t[18]=i,t[19]=a,t[20]=s,t[21]=c):c=t[21];let l;t[22]===e.subagent.detail?l=t[23]:(l=e.subagent.detail?(0,X.jsx)(`p`,{className:`mt-2 line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.subagent.detail}):null,t[22]=e.subagent.detail,t[23]=l);let u;t[24]!==e.subagent.providerThreadIds||t[25]!==e.subagent.tool?(u=e.subagent.tool||e.subagent.providerThreadIds.length>0?(0,X.jsxs)(`div`,{className:`mt-2 flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.subagent.tool?(0,X.jsx)(`span`,{className:`rounded-md border border-border/60 px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:e.subagent.tool}):null,e.subagent.providerThreadIds.slice(0,2).map(Og)]}):null,t[24]=e.subagent.providerThreadIds,t[25]=e.subagent.tool,t[26]=u):u=t[26];let d;t[27]!==c||t[28]!==l||t[29]!==u?(d=(0,X.jsxs)(`div`,{className:`border-b border-border/60 px-4 py-3`,children:[c,l,u]}),t[27]=c,t[28]=l,t[29]=u,t[30]=d):d=t[30];let f;t[31]===e.subagent.messages?f=t[32]:(f=e.subagent.messages.length>0?e.subagent.messages.map(Dg):null,t[31]=e.subagent.messages,t[32]=f);let p;t[33]!==e.subagent.entries||t[34]!==e.subagent.messages.length||t[35]!==e.subagent.status?(p=e.subagent.entries.length>0?e.subagent.entries.map(t=>(0,X.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-card/40 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:q(`size-2 shrink-0 rounded-full`,t.tone===`error`?`bg-destructive`:e.subagent?.status===`running`?`bg-sky-400`:e.subagent?.status===`interrupted`?`bg-muted-foreground/60`:`bg-emerald-400`)}),(0,X.jsx)(`p`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:t.toolTitle??t.label})]}),t.detail?(0,X.jsx)(`p`,{className:`mt-2 text-xs leading-relaxed text-muted-foreground`,children:t.detail}):null,t.output&&t.output!==t.detail?(0,X.jsx)(`div`,{className:`mt-3 rounded-md border border-border/50 bg-background/60 p-2`,children:(0,X.jsx)(Dt,{text:t.output,cwd:void 0,isStreaming:!1})}):null]},t.id)):e.subagent.messages.length===0?(0,X.jsxs)(`div`,{className:`flex min-h-48 flex-col items-center justify-center rounded-md border border-dashed border-border/70 bg-card/20 p-6 text-center`,children:[(0,X.jsx)(yr,{className:`size-5 text-muted-foreground/60`}),(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:`No transcript captured yet`}),(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`The subagent is visible from lifecycle events. Detailed messages will appear here when the provider exposes them.`})]}):null,t[33]=e.subagent.entries,t[34]=e.subagent.messages.length,t[35]=e.subagent.status,t[36]=p):p=t[36];let m;t[37]!==f||t[38]!==p?(m=(0,X.jsx)(Hn,{className:`min-h-0 flex-1`,children:(0,X.jsxs)(`div`,{className:`space-y-3 p-4`,children:[f,p]})}),t[37]=f,t[38]=p,t[39]=m):m=t[39];let h;return t[40]!==m||t[41]!==d?(h=(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col`,children:[d,m]}),t[40]=m,t[41]=d,t[42]=h):h=t[42],h}function Dg(e){return(0,X.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-card/40 p-3`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex min-w-0 items-center justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`truncate text-xs font-medium text-foreground`,children:`Subagent`}),e.providerThreadId?(0,X.jsx)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground/55`,children:e.providerThreadId}):null]}),(0,X.jsx)(Dt,{text:e.text,cwd:void 0,isStreaming:!1})]},e.id)}function Og(e){return(0,X.jsx)(`span`,{className:`max-w-40 truncate rounded-md border border-border/60 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground/70`,children:e},e)}function kg(e){let t=(0,Y.c)(8),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,X.jsx)(`div`,{className:`mx-auto flex size-10 items-center justify-center rounded-md border border-border/70 bg-card/60 text-muted-foreground`,children:(0,X.jsx)(wn,{className:`size-4`})}),t[0]=n):n=t[0];let r;t[1]===e.title?r=t[2]:(r=(0,X.jsx)(`p`,{className:`mt-3 text-sm font-medium text-foreground`,children:e.title}),t[1]=e.title,t[2]=r);let i;t[3]===e.description?i=t[4]:(i=(0,X.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:e.description}),t[3]=e.description,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center p-6 text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-72`,children:[n,r,i]})}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ag(){let e=(0,Y.c)(89),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={strict:!1},e[0]=t):t=e[0];let n=re(t),a;e[1]===n?a=e[2]:(a=ie(n),e[1]=n,e[2]=a);let s=a,c;e[3]===n.draftId?c=e[4]:(c=n.draftId?ee.make(n.draftId):null,e[3]=n.draftId,e[4]=c);let u=c,p;e[5]===u?p=e[6]:(p=e=>u?e.getDraftSession(u):null,e[5]=u,e[6]=p);let m=te(p),h;bb0:{if(s){h=s;break bb0}if(!m){h=null;break bb0}let t;e[7]!==m.environmentId||e[8]!==m.threadId?(t=r(m.environmentId,m.threadId),e[7]=m.environmentId,e[8]=m.threadId,e[9]=t):t=e[9],h=t}let g=h,y;e[10]===g?y=e[11]:(y=f(g),e[10]=g,e[11]=y);let b=d(y),x;e[12]===g?x=e[13]:(x=e=>g?e.getDraftThreadByRef(g):null,e[12]=g,e[13]=x);let S=te(x),w;e[14]!==S||e[15]!==b?(w=b?i(b.environmentId,b.projectId):S?i(S.environmentId,S.projectId):null,e[14]=S,e[15]=b,e[16]=w):w=e[16];let T=w,E;e[17]===T?E=e[18]:(E=l(T),e[17]=T,e[18]=E);let O=d(E),k;e[19]===g?k=e[20]:(k=e=>D(e.terminalStateByThreadKey,g),e[19]=g,e[20]=k);let A=_(k),j;e[21]===g?j=e[22]:(j=e=>g?e.terminalLaunchContextByThreadKey[o(g)]??null:null,e[21]=g,e[22]=j);let M=_(j),N=_(zg),P=_(Rg),ne=_(Lg),ae=_(Ig),oe=_(Fg),se=_(Pg),F=v(),ce=Wn(),[le,ue]=(0,J.useState)(0),de=b?.worktreePath??S?.worktreePath??null,I=M?.worktreePath??de;M?.cwd;let fe;e[23]!==I||e[24]!==O||e[25]!==M?.cwd?(fe=M?.cwd??(O?sn({project:{cwd:O.cwd},worktreePath:I}):null),e[23]=I,e[24]=O,e[25]=M?.cwd,e[26]=fe):fe=e[26];let L=fe,R;e[27]!==I||e[28]!==O?(R=O?qt({project:{cwd:O.cwd},worktreePath:I}):{},e[27]=I,e[28]=O,e[29]=R):R=e[29];let pe=R,z;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(z={context:{terminalFocus:!0,terminalOpen:!0}},e[30]=z):z=e[30];let me=z,he;e[31]===F?he=e[32]:(he=Rn(F,`terminal.split`,me),e[31]=F,e[32]=he);let ge=he,B;e[33]===F?B=e[34]:(B=Rn(F,`terminal.new`,me),e[33]=F,e[34]=B);let _e=B,ve;e[35]===F?ve=e[36]:(ve=Rn(F,`terminal.close`,me),e[35]=F,e[36]=ve);let ye=ve,be,xe;e[37]!==N||e[38]!==A.terminalOpen||e[39]!==g?(be=()=>{!g||!A.terminalOpen||N(g,!1)},xe=[N,A.terminalOpen,g],e[37]=N,e[38]=A.terminalOpen,e[39]=g,e[40]=be,e[41]=xe):(be=e[40],xe=e[41]),(0,J.useEffect)(be,xe);let Se;e[42]===Symbol.for(`react.memo_cache_sentinel`)?(Se=()=>{ue(Ng)},e[42]=Se):Se=e[42];let Ce=Se,we;e[43]!==N||e[44]!==ne||e[45]!==g?(we=()=>{g&&(ne(g,`terminal-${On()}`),N(g,!1),Ce())},e[43]=N,e[44]=ne,e[45]=g,e[46]=we):we=e[46];let Te=we,Ee;e[47]!==ae||e[48]!==N||e[49]!==g?(Ee=()=>{g&&(ae(g,`terminal-${On()}`),N(g,!1),Ce())},e[47]=ae,e[48]=N,e[49]=g,e[50]=Ee):Ee=e[50];let De=Ee,V;e[51]!==oe||e[52]!==g?(V=e=>{g&&(oe(g,e),Ce())},e[51]=oe,e[52]=g,e[53]=V):V=e[53];let Oe=V,ke;e[54]!==P||e[55]!==g?(ke=e=>{g&&P(g,e)},e[54]=P,e[55]=g,e[56]=ke):ke=e[56];let Ae=ke,H;e[57]!==se||e[58]!==N||e[59]!==A.terminalIds.length||e[60]!==g?(H=e=>{if(!g)return;let t=C(g.environmentId);if(!t)return;let n=A.terminalIds.length<=1,r=()=>t.terminal.write({threadId:g.threadId,terminalId:e,data:`exit
2009
+ `}).catch(Mg);`close`in t.terminal&&typeof t.terminal.close==`function`?(async()=>{n&&await t.terminal.clear({threadId:g.threadId,terminalId:e}).catch(jg),await t.terminal.close({threadId:g.threadId,terminalId:e,deleteHistory:!0})})().catch(()=>r()):r(),se(g,e),N(g,!1),Ce()},e[57]=se,e[58]=N,e[59]=A.terminalIds.length,e[60]=g,e[61]=H):H=e[61];let U=H,je;e[62]===ce?je=e[63]:(je=e=>{ce?.current?.addTerminalContext(e)},e[62]=ce,e[63]=je);let Me=je;if(!g){let t;return e[64]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(kg,{title:`Terminal unavailable`,description:`No active thread is available for this workspace terminal.`}),e[64]=t):t=e[64],t}if(!O||!L){let t;return e[65]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,X.jsx)(kg,{title:`Terminal unavailable`,description:`This thread does not have a resolved project directory.`}),e[65]=t):t=e[65],t}let Ne=g.threadId,Pe=ge??void 0,Fe=_e??void 0,Ie=ye??void 0,Le;return e[66]!==Oe||e[67]!==Me||e[68]!==U||e[69]!==De||e[70]!==L||e[71]!==I||e[72]!==le||e[73]!==F||e[74]!==pe||e[75]!==Ae||e[76]!==Te||e[77]!==Ne||e[78]!==Pe||e[79]!==Fe||e[80]!==Ie||e[81]!==A.activeTerminalGroupId||e[82]!==A.activeTerminalId||e[83]!==A.runningTerminalIds||e[84]!==A.terminalGroups||e[85]!==A.terminalHeight||e[86]!==A.terminalIds||e[87]!==g?(Le=(0,X.jsx)(Sn,{threadRef:g,threadId:Ne,cwd:L,worktreePath:I,runtimeEnv:pe,layout:`panel`,visible:!0,height:A.terminalHeight,terminalIds:A.terminalIds,runningTerminalIds:A.runningTerminalIds,activeTerminalId:A.activeTerminalId,terminalGroups:A.terminalGroups,activeTerminalGroupId:A.activeTerminalGroupId,focusRequestId:le,onSplitTerminal:Te,onNewTerminal:De,splitShortcutLabel:Pe,newShortcutLabel:Fe,closeShortcutLabel:Ie,keybindings:F,onActiveTerminalChange:Oe,onCloseTerminal:U,onHeightChange:Ae,onAddTerminalContext:Me}),e[66]=Oe,e[67]=Me,e[68]=U,e[69]=De,e[70]=L,e[71]=I,e[72]=le,e[73]=F,e[74]=pe,e[75]=Ae,e[76]=Te,e[77]=Ne,e[78]=Pe,e[79]=Fe,e[80]=Ie,e[81]=A.activeTerminalGroupId,e[82]=A.activeTerminalId,e[83]=A.runningTerminalIds,e[84]=A.terminalGroups,e[85]=A.terminalHeight,e[86]=A.terminalIds,e[87]=g,e[88]=Le):Le=e[88],Le}function jg(){}function Mg(){}function Ng(e){return e+1}function Pg(e){return e.closeTerminal}function Fg(e){return e.setActiveTerminal}function Ig(e){return e.newTerminal}function Lg(e){return e.splitTerminal}function Rg(e){return e.setTerminalHeight}function zg(e){return e.setTerminalOpen}function Bg(e){let t=(0,Y.c)(38),n=e.icon,r=e.disabled,i=e.onClick,a=e.compact?`min-h-0 px-1 py-1 @sm/workspace-launcher:px-4 @sm/workspace-launcher:py-3`:`min-h-32 px-5 py-6`,o=e.disabled?`cursor-not-allowed opacity-45`:`hover:border-border hover:bg-card/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,s;t[0]!==a||t[1]!==o?(s=q(`group flex w-full flex-col items-center justify-center rounded-lg border border-border/50 bg-card/35 text-center transition-colors`,a,o),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c=e.compact?`size-4 @sm/workspace-launcher:size-6`:`size-6`,l=!e.disabled&&`group-hover:text-foreground`,u;t[3]!==c||t[4]!==l?(u=q(`text-muted-foreground transition-colors`,c,l),t[3]=c,t[4]=l,t[5]=u):u=t[5];let d;t[6]!==n||t[7]!==u?(d=(0,X.jsx)(n,{className:u}),t[6]=n,t[7]=u,t[8]=d):d=t[8];let f=e.badgeCount??0,p;t[9]===f?p=t[10]:(p=(0,X.jsx)(ot,{count:f,className:`-top-2 -right-3 h-4 min-w-4 px-1 text-[9px]`}),t[9]=f,t[10]=p);let m;t[11]!==p||t[12]!==d?(m=(0,X.jsxs)(`span`,{className:`relative inline-flex`,children:[d,p]}),t[11]=p,t[12]=d,t[13]=m):m=t[13];let h;t[14]===e.badgeCount?h=t[15]:(h=(e.badgeCount??0)>0?(0,X.jsx)(`span`,{className:`sr-only`,children:je(e.badgeCount??0)}):null,t[14]=e.badgeCount,t[15]=h);let g=e.compact?`mt-1 text-xs @sm/workspace-launcher:mt-3 @sm/workspace-launcher:text-base`:`mt-4 text-base`,_;t[16]===g?_=t[17]:(_=q(`font-semibold text-foreground`,g),t[16]=g,t[17]=_);let v;t[18]!==e.label||t[19]!==_?(v=(0,X.jsx)(`span`,{className:_,children:e.label}),t[18]=e.label,t[19]=_,t[20]=v):v=t[20];let y=e.compact?`mt-0.5 hidden text-xs @sm/workspace-launcher:block`:`mt-1 text-sm`,b;t[21]===y?b=t[22]:(b=q(`text-muted-foreground`,y),t[21]=y,t[22]=b);let x;t[23]!==e.description||t[24]!==b?(x=(0,X.jsx)(`span`,{className:b,children:e.description}),t[23]=e.description,t[24]=b,t[25]=x):x=t[25];let S;t[26]!==e.compact||t[27]!==e.shortcutLabel?(S=e.shortcutLabel?(0,X.jsx)(`span`,{className:q(`rounded-md bg-muted px-1.5 py-0.5 font-medium text-[11px] text-muted-foreground`,e.compact?`mt-2 hidden @sm/workspace-launcher:inline-flex`:`mt-3`),children:e.shortcutLabel}):null,t[26]=e.compact,t[27]=e.shortcutLabel,t[28]=S):S=t[28];let C;return t[29]!==e.disabled||t[30]!==e.onClick||t[31]!==m||t[32]!==h||t[33]!==v||t[34]!==x||t[35]!==S||t[36]!==s?(C=(0,X.jsxs)(`button`,{type:`button`,disabled:r,onClick:i,"data-slot":`workspace-launcher-card`,className:s,children:[m,h,v,x,S]}),t[29]=e.disabled,t[30]=e.onClick,t[31]=m,t[32]=h,t[33]=v,t[34]=x,t[35]=S,t[36]=s,t[37]=C):C=t[37],C}function Vg(e){let t=(0,Y.c)(60),n=v(),r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={key:`files`,label:`Files`,mode:`files`},t[0]=r):r=t[0];let i=r,a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a={key:`review`,label:`Review`,mode:`review`},t[1]=a):a=t[1];let o=a,s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s={key:`terminal`,label:`Terminal`,mode:`terminal`},t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l={key:`simulator`,label:`Simulator`,mode:`simulator`},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d={key:`agents`,label:`Agents`,mode:`agents`},t[4]=d):d=t[4];let f=d,p;t[5]===n?p=t[6]:(p=Rn(n,`workspace.files`),t[5]=n,t[6]=p);let m=p,h;t[7]===n?h=t[8]:(h=Rn(n,`workspace.review`),t[7]=n,t[8]=h);let g=h,_;t[9]===n?_=t[10]:(_=Rn(n,`workspace.terminal`),t[9]=n,t[10]=_);let y=_,b;t[11]===n?b=t[12]:(b=Rn(n,`workspace.simulator`),t[11]=n,t[12]=b);let x=b,S,C;if(t[13]!==m||t[14]!==e||t[15]!==g||t[16]!==x||t[17]!==y){let n=e.tabs.filter(Hg),r=!e.isPhoneSurface,a;t[20]===e?a=t[21]:(a=()=>e.onSelectTab(i),t[20]=e,t[21]=a);let s;t[22]!==r||t[23]!==m||t[24]!==a?(s=(0,X.jsx)(Bg,{label:`Files`,description:`Browse project files`,icon:H,shortcutLabel:m,compact:r,onClick:a}),t[22]=r,t[23]=m,t[24]=a,t[25]=s):s=t[25];let l,d;t[26]===r?(l=t[27],d=t[28]):(l=(0,X.jsx)(Bg,{label:`Side chat`,description:`Start a side conversation`,icon:vr,compact:r,disabled:!0}),d=(0,X.jsx)(Bg,{label:`Browser`,description:`Open a website`,icon:It,compact:r,disabled:!0}),t[26]=r,t[27]=l,t[28]=d);let p;t[29]===e?p=t[30]:(p=()=>e.onSelectTab(o),t[29]=e,t[30]=p);let h;t[31]!==r||t[32]!==g||t[33]!==p?(h=(0,X.jsx)(Bg,{label:`Review`,description:`View code changes`,icon:hr,shortcutLabel:g,compact:r,onClick:p}),t[31]=r,t[32]=g,t[33]=p,t[34]=h):h=t[34];let _;t[35]===e?_=t[36]:(_=()=>e.onSelectTab(c),t[35]=e,t[36]=_);let v;t[37]!==r||t[38]!==_||t[39]!==y?(v=(0,X.jsx)(Bg,{label:`Terminal`,description:`Start an interactive shell`,icon:wn,shortcutLabel:y,compact:r,onClick:_}),t[37]=r,t[38]=_,t[39]=y,t[40]=v):v=t[40];let b;t[41]!==r||t[42]!==e||t[43]!==x?(b=e.showSimulator?(0,X.jsx)(Bg,{label:`Simulator`,description:`Run and control an iOS app`,icon:xn,shortcutLabel:x,compact:r,onClick:()=>e.onSelectTab(u)}):null,t[41]=r,t[42]=e,t[43]=x,t[44]=b):b=t[44];let w;t[45]!==r||t[46]!==e?(w=e.showAgents?(0,X.jsx)(Bg,{label:`Agents`,description:`Watch subagents and workflows run`,icon:ve,badgeCount:e.liveAgentCount,compact:r,onClick:()=>e.onSelectTab(f)}):null,t[45]=r,t[46]=e,t[47]=w):w=t[47];let T;t[48]!==s||t[49]!==l||t[50]!==d||t[51]!==h||t[52]!==v||t[53]!==b||t[54]!==w?(T=(0,X.jsxs)(X.Fragment,{children:[s,l,d,h,v,b,w]}),t[48]=s,t[49]=l,t[50]=d,t[51]=h,t[52]=v,t[53]=b,t[54]=w,t[55]=T):T=t[55],S=T,C=n.length>0?(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-lg space-y-2 pt-1`,children:n.map(t=>(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full min-w-0 items-center gap-3 rounded-lg border border-border/50 bg-card/35 px-4 py-3 text-left transition-colors hover:border-border hover:bg-card/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>e.onSelectTab(t),children:[(0,X.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg border border-border/50 bg-background/50 text-muted-foreground`,children:(0,X.jsx)(kt,{name:t.avatarKey??t.agentKey,className:`size-5`})}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:q(`block truncate text-sm font-medium`,Yn(yg(t.status))),style:Jn(t.label,{durationSeconds:2.2}),children:t.label}),(0,X.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:bg(t.status)})]})]},t.key))}):null,t[13]=m,t[14]=e,t[15]=g,t[16]=x,t[17]=y,t[18]=S,t[19]=C}else S=t[18],C=t[19];let w=C,T;return t[56]!==w||t[57]!==S||t[58]!==e.isPhoneSurface?(T=(0,X.jsx)(Hn,{className:`h-full`,children:e.isPhoneSurface?(0,X.jsx)(`div`,{className:`flex min-h-full p-5 sm:p-6`,children:(0,X.jsxs)(`div`,{className:`m-auto w-full max-w-lg space-y-4`,children:[S,w]})}):(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3 p-4 sm:p-5`,"data-slot":`workspace-launcher`,children:[(0,X.jsx)(`div`,{className:`@container/workspace-launcher flex min-h-0 flex-1 items-center justify-center`,children:(0,X.jsx)(`div`,{className:`grid aspect-square grid-cols-3 grid-rows-3 gap-2 @sm/workspace-launcher:gap-3`,"data-slot":`workspace-launcher-grid`,style:{inlineSize:`min(100cqw, 100cqh, 32rem)`},children:S})}),w]})}),t[56]=w,t[57]=S,t[58]=e.isPhoneSurface,t[59]=T):T=t[59],T}function Hg(e){return e.mode===`agent`}function Ug(e){let t=(0,Y.c)(125),{onClosePanelTab:n,onToggleMaximized:i}=e,o=e.maximized??!1,s=e.mode===`phone`,c=ge(),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={strict:!1},t[0]=l):l=t[0];let u=re(l),p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p={strict:!1,select:Qg},t[1]=p):p=t[1];let m=oe(p),h;t[2]===u?h=t[3]:(h=ie(u),t[2]=u,t[3]=h);let g=h,_;t[4]===u.draftId?_=t[5]:(_=u.draftId?ee.make(u.draftId):null,t[4]=u.draftId,t[5]=_);let v=_,y;t[6]===v?y=t[7]:(y=e=>v?e.getDraftSession(v):null,t[6]=v,t[7]=y);let b=te(y),x;t[8]!==g||t[9]!==b?(x=g??(b?r(b.environmentId,b.threadId):null),t[8]=g,t[9]=b,t[10]=x):x=t[10];let S=x,w;t[11]===S?w=t[12]:(w=f(S),t[11]=S,t[12]=w);let T=d(w),E;t[13]===T?.session?E=t[14]:(E=An(T?.session??null)!==`disconnected`&&T?.session?.orchestrationStatus!==`stopped`&&T?.session?.orchestrationStatus!==`interrupted`&&T?.session?.orchestrationStatus!==`error`,t[13]=T?.session,t[14]=E);let D=E;T?.activities,T?.latestTurn?.state;let O;t[15]!==T?.activities||t[16]!==T?.latestTurn?.state||t[17]!==D?(O=Pn(T?.activities??[],{sessionLive:D,parentTurnState:T?.latestTurn?.state??null}),t[15]=T?.activities,t[16]=T?.latestTurn?.state,t[17]=D,t[18]=O):O=t[18];let k=O,A=m.workspaceTab===`agent`&&m.workspaceAgentKey?m.workspaceAgentKey:null,j;t[19]!==A||t[20]!==k?(j=Nn(k,A),t[19]=A,t[20]=k,t[21]=j):j=t[21];let M=j,N;t[22]!==e.panelMode||t[23]!==m?(N=me(m)??e.panelMode,t[22]=e.panelMode,t[23]=m,t[24]=N):N=t[24];let P=N;T?.activities;let ae;t[25]!==T?.activities||t[26]!==D||t[27]!==k?(ae=Mn({activities:T?.activities??[],transcriptSubagents:k,sessionLive:D}),t[25]=T?.activities,t[26]=D,t[27]=k,t[28]=ae):ae=t[28];let se=ae,F;bb0:{if(P===`files`||P===`review`||P===`terminal`||P===`simulator`||P===`agents`){let n;t[29]!==P||t[30]!==e.openedPanelModes?(n=e.openedPanelModes.includes(P)?e.openedPanelModes:[...e.openedPanelModes,P],t[29]=P,t[30]=e.openedPanelModes,t[31]=n):n=t[31],F=n;break bb0}F=e.openedPanelModes}let ce=F,le;if(t[32]!==A||t[33]!==s||t[34]!==ce||t[35]!==e.openedAgentKeys||t[36]!==k){let n=fi({subagents:k,activeAgentKey:A,openedAgentKeys:e.openedAgentKeys,openedPanelModes:ce});le=s?n.filter(Zg):n,t[32]=A,t[33]=s,t[34]=ce,t[35]=e.openedAgentKeys,t[36]=k,t[37]=le}else le=t[37];let I=le,fe=P===`agent`?A:s&&P===`agents`?null:P,L;t[38]!==c||t[39]!==u.draftId||t[40]!==g?(L=e=>{if(u.draftId){c({to:`/draft/$draftId`,params:{draftId:ee.make(u.draftId)},replace:!0,search:e});return}g&&c({to:`/$environmentId/$threadId`,params:ne(g),replace:!0,search:e})},t[38]=c,t[39]=u.draftId,t[40]=g,t[41]=L):L=t[41];let R=L,pe;t[42]===R?pe=t[43]:(pe=e=>{if(e.mode===`review`){R(Xg);return}if(e.mode===`files`){R(Yg);return}if(e.mode===`terminal`){R(Jg);return}if(e.mode===`simulator`){R(qg);return}if(e.mode===`agents`){R(Kg);return}e.mode===`agent`&&R(t=>de(t,e.agentKey))},t[42]=R,t[43]=pe);let z=pe,he;t[44]===R?he=t[45]:(he=()=>{R(Gg)},t[44]=R,t[45]=he);let B=he,ve;t[46]===R?ve=t[47]:(ve=e=>{let t=e.startsWith(`subagent:`)?e:`subagent:${e}`;R(e=>de(e,t))},t[46]=R,t[47]=ve);let ye=ve,be;t[48]===n?be=t[49]:(be=e=>{n({mode:e.mode,...e.mode===`agent`?{agentKey:e.agentKey}:{}})},t[48]=n,t[49]=be);let xe=be,Se;t[50]!==z||t[51]!==I?(Se=(e,t)=>{let n=I.findIndex(t=>t.key===e.key);if(n<0)return;let r=e=>{let t=I[(e+I.length)%I.length];t&&z(t)};switch(t.key){case`ArrowRight`:case`ArrowDown`:t.preventDefault(),r(n+1);return;case`ArrowLeft`:case`ArrowUp`:t.preventDefault(),r(n-1);return;case`Home`:t.preventDefault(),r(0);return;case`End`:t.preventDefault(),r(I.length-1);return}},t[50]=z,t[51]=I,t[52]=Se):Se=t[52];let Ce=Se,we;t[53]===R?we=t[54]:(we=()=>{R(Wg)},t[53]=R,t[54]=we);let Te=we,Ee=s?`h-14`:`h-12`,De=!s&&`transition-[padding-left] duration-200 ease-linear motion-reduce:transition-none`,V=e.reserveChromeInset&&ue,Oe=o&&a&&`drag-region wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]`,ke;t[55]!==Ee||t[56]!==De||t[57]!==V||t[58]!==Oe?(ke=q(`flex shrink-0 items-center gap-1 border-b border-border bg-card/40 px-2`,Ee,De,V,Oe),t[55]=Ee,t[56]=De,t[57]=V,t[58]=Oe,t[59]=ke):ke=t[59];let Ae;t[60]!==Te||t[61]!==s?(Ae=s?(0,X.jsx)(Un,{size:`icon`,variant:`ghost`,"aria-label":`Back to thread`,className:`shrink-0`,onClick:Te,children:(0,X.jsx)(_e,{})}):null,t[60]=Te,t[61]=s,t[62]=Ae):Ae=t[62];let H;if(t[63]!==fe||t[64]!==xe||t[65]!==s||t[66]!==Ce||t[67]!==z||t[68]!==I){let e;t[70]!==fe||t[71]!==xe||t[72]!==s||t[73]!==Ce||t[74]!==z?(e=e=>{let t=fe===e.key;return(0,X.jsxs)(`div`,{className:q(`flex min-w-0 shrink-0 items-center rounded-md text-sm transition-colors`,s?`h-11`:`h-8`,t?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[(0,X.jsxs)(`button`,{type:`button`,id:Sg(e.key),role:`tab`,"aria-selected":t,"aria-controls":Cg(e.key),tabIndex:t?0:-1,className:q(`flex h-full min-w-0 items-center gap-1.5`,s?`pl-3 pr-1.5`:`pl-2.5 pr-1`),onClick:()=>z(e),onKeyDown:t=>Ce(e,t),children:[(0,X.jsx)(wg,{tab:e,active:t}),(0,X.jsx)(`span`,{className:q(`max-w-32 truncate`,e.mode===`agent`&&Yn(yg(e.status))),style:e.mode===`agent`?Jn(e.label,{durationSeconds:2.2}):void 0,children:e.label})]}),(0,X.jsx)(`button`,{type:`button`,className:q(`mr-1 flex size-5 shrink-0 items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-background/60 hover:text-foreground`,s&&`relative after:absolute after:top-1/2 after:left-1/2 after:size-11 after:-translate-x-1/2 after:-translate-y-1/2`),"aria-label":`Close ${e.label} tab`,onClick:()=>xe(e),children:(0,X.jsx)(Dn,{className:`size-3`})})]},e.key)},t[70]=fe,t[71]=xe,t[72]=s,t[73]=Ce,t[74]=z,t[75]=e):e=t[75],H=I.map(e),t[63]=fe,t[64]=xe,t[65]=s,t[66]=Ce,t[67]=z,t[68]=I,t[69]=H}else H=t[69];let U=s?`size-11`:`size-6`,je=!P&&`bg-muted text-foreground`,Me;t[76]!==U||t[77]!==je?(Me=q(`flex shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-muted/60 hover:text-foreground`,U,je),t[76]=U,t[77]=je,t[78]=Me):Me=t[78];let Ne=!P,Pe;t[79]!==B||t[80]!==Me||t[81]!==Ne?(Pe=(0,X.jsx)(`button`,{type:`button`,className:Me,"aria-label":`Workspace launcher`,"aria-pressed":Ne,onClick:B}),t[79]=B,t[80]=Me,t[81]=Ne,t[82]=Pe):Pe=t[82];let Fe;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(Fe=(0,X.jsx)(_n,{className:`size-3.5`}),t[83]=Fe):Fe=t[83];let Ie;t[84]===Pe?Ie=t[85]:(Ie=(0,X.jsx)(zn,{render:Pe,children:Fe}),t[84]=Pe,t[85]=Ie);let Le;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(Le=(0,X.jsx)(Bn,{side:`bottom`,children:`Workspace launcher`}),t[86]=Le):Le=t[86];let Re;t[87]===Ie?Re=t[88]:(Re=(0,X.jsxs)(Vn,{children:[Ie,Le]}),t[87]=Ie,t[88]=Re);let ze;t[89]!==H||t[90]!==Re?(ze=(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,role:`tablist`,"aria-label":`Workspace tabs`,children:[H,Re]}),t[89]=H,t[90]=Re,t[91]=ze):ze=t[91];let W;t[92]!==Te||t[93]!==s||t[94]!==o||t[95]!==i?(W=s?null:(0,X.jsxs)(X.Fragment,{children:[i?(0,X.jsxs)(Vn,{children:[(0,X.jsx)(zn,{render:(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,className:`shrink-0 text-muted-foreground/70 hover:text-foreground`,onClick:i,"aria-pressed":o,"aria-label":o?`Restore workspace panel`:`Maximize workspace panel`,children:o?(0,X.jsx)(gn,{className:`size-3.5`}):(0,X.jsx)(_r,{className:`size-3.5`})})}),(0,X.jsx)(Bn,{side:`bottom`,children:o?`Restore workspace panel`:`Maximize workspace panel`})]}):null,(0,X.jsx)(Un,{size:`icon-xs`,variant:`ghost`,className:`shrink-0 text-muted-foreground/70 hover:text-foreground`,onClick:Te,"aria-label":`Close workspace panel`,children:(0,X.jsx)(Dn,{className:`size-3.5`})})]}),t[92]=Te,t[93]=s,t[94]=o,t[95]=i,t[96]=W):W=t[96];let Be;t[97]!==ke||t[98]!==Ae||t[99]!==ze||t[100]!==W?(Be=(0,X.jsxs)(`div`,{className:ke,children:[Ae,ze,W]}),t[97]=ke,t[98]=Ae,t[99]=ze,t[100]=W,t[101]=Be):Be=t[101];let Ve;t[102]===fe?Ve=t[103]:(Ve=Cg(fe),t[102]=fe,t[103]=Ve);let He;t[104]===fe?He=t[105]:(He=fe?Sg(fe):void 0,t[104]=fe,t[105]=He);let Ue;t[106]!==M||t[107]!==P||t[108]!==T||t[109]!==A||t[110]!==se||t[111]!==s||t[112]!==ye||t[113]!==e.mode||t[114]!==z||t[115]!==I||t[116]!==S?(Ue=P===`review`?(0,X.jsx)(Iu,{mode:e.mode}):P===`files`?(0,X.jsx)(Kh,{mode:e.mode}):P===`terminal`?(0,X.jsx)(Ag,{}):P===`simulator`&&!s?(0,X.jsx)(_g,{environmentId:S?.environmentId??null,threadId:S?.threadId??null}):P===`agents`&&!s?(0,X.jsx)(li,{model:se,environmentId:S?.environmentId??null,threadId:S?S.threadId:null,onOpenAgent:ye}):P===`agent`?(0,X.jsx)(Eg,{subagent:M,agentKey:A}):(0,X.jsx)(Vg,{tabs:I,activeThread:T,onSelectTab:z,showAgents:!s,showSimulator:!s&&!!(S&&C(S.environmentId)?.device),isPhoneSurface:s,liveAgentCount:se.liveCount}),t[106]=M,t[107]=P,t[108]=T,t[109]=A,t[110]=se,t[111]=s,t[112]=ye,t[113]=e.mode,t[114]=z,t[115]=I,t[116]=S,t[117]=Ue):Ue=t[117];let We;t[118]!==Ve||t[119]!==He||t[120]!==Ue?(We=(0,X.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,id:Ve,role:`tabpanel`,"aria-labelledby":He,children:Ue}),t[118]=Ve,t[119]=He,t[120]=Ue,t[121]=We):We=t[121];let Ge;return t[122]!==Be||t[123]!==We?(Ge=(0,X.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col bg-background w-full`,children:[Be,We]}),t[122]=Be,t[123]=We,t[124]=Ge):Ge=t[124],Ge}function Wg(e){return{...ce(e),diff:void 0,diffTurnId:void 0,diffFilePath:void 0,preview:void 0,workspaceOpen:void 0,workspaceTab:void 0,workspaceAgentKey:void 0}}function Gg(e){return he(e)}function Kg(e){return se(e)}function qg(e){return F(e)}function Jg(e){return I(e)}function Yg(e){return L(e)}function Xg(e){return z(e)}function Zg(e){return e.mode!==`agents`&&e.mode!==`simulator`}function Qg(e){return pe(e)}export{Eg as AgentThreadPanel,Ug as default};