@openchamber/web 1.22.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/bin/cli.js +11 -1
  2. package/bin/cli.test.js +92 -0
  3. package/bin/lib/cli-startup.js +49 -0
  4. package/bin/lib/commands-startup.js +41 -6
  5. package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-DbcnxAfY.js} +1 -1
  6. package/dist/assets/DiffView-Dp1tomqK.js +4 -0
  7. package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-DE2sKIYv.js} +1 -1
  8. package/dist/assets/FilesView-C_of2nIT.js +17 -0
  9. package/dist/assets/{GitView-Cv2xH-S6.js → GitView-CKgUkb5Z.js} +4 -4
  10. package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-Bce2ettZ.js} +1 -1
  11. package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BZVWM2zw.js} +1 -1
  12. package/dist/assets/MarkdownImageGallery-DdROVz29.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-CenrzmMN.js +12 -0
  14. package/dist/assets/OnboardingScreen-DyqYG_NP.js +1 -0
  15. package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CR3RVO5I.js} +1 -1
  16. package/dist/assets/PierreDiffViewer-KihzO94X.js +161 -0
  17. package/dist/assets/PlanView-jcQAfr2A.js +5 -0
  18. package/dist/assets/SettingsView-Buvom5A2.js +28 -0
  19. package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-CV_hzB5v.js} +1 -1
  20. package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
  21. package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-llKecK_Z.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-ZDMTdCGn.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-ClvqQ4j0.js} +1 -1
  24. package/dist/assets/WalkthroughView-BgpSnSlU.js +4 -0
  25. package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-Nm5_wabb.js} +2 -2
  26. package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
  27. package/dist/assets/de-DTQDjaiv.js +10 -0
  28. package/dist/assets/es-SOCFd_r-.js +16 -0
  29. package/dist/assets/fr-CP6jqIzw.js +14 -0
  30. package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
  31. package/dist/assets/index-B68h5S5B.css +1 -0
  32. package/dist/assets/index-CRf2xk51.js +39 -0
  33. package/dist/assets/{index-DLiD86ge.js → index-Du9sZhDb.js} +1 -1
  34. package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-EQERIius.js} +1 -1
  35. package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-BCoVpkQy.js} +1 -1
  36. package/dist/assets/ja-BKfafwsD.js +16 -0
  37. package/dist/assets/ko-BA5xgCYp.js +16 -0
  38. package/dist/assets/main-BNiPEont.js +930 -0
  39. package/dist/assets/{main-DCB4JgVe.js → main-DPf32fO6.js} +2 -2
  40. package/dist/assets/markdownCore-CQ7CAuuV.js +5 -0
  41. package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CHqVTsgj.js} +2 -2
  42. package/dist/assets/{mobile-DZV_sfX7.js → mobile-BQmgHA57.js} +2 -2
  43. package/dist/assets/patchFileDiff-C4X_trug.js +13 -0
  44. package/dist/assets/pl-B215pG1Y.js +16 -0
  45. package/dist/assets/pt-BR-Bo2pnlEa.js +16 -0
  46. package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +2 -0
  47. package/dist/assets/renderMobileApp-BvTmuRE-.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +17 -0
  49. package/dist/assets/scheduledTasksApi-BAScWwt3.js +1 -0
  50. package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-BTObuQCR.js} +1 -1
  51. package/dist/assets/surface-BvRzS58U.js +1 -0
  52. package/dist/assets/tr-CUaxHc8X.js +7 -0
  53. package/dist/assets/uk-YTJgyqAZ.js +16 -0
  54. package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-theH_IJL.js} +143 -137
  55. package/dist/assets/useGitComparison-B94I6kOI.js +1 -0
  56. package/dist/assets/useInlineCommentController-Bs3PgeA8.js +2 -0
  57. package/dist/assets/useRootScrollLock-hSYwnxZs.js +1 -0
  58. package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-Cxgr01md.js} +2 -2
  60. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  61. package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
  62. package/dist/assets/{web-components-B6QgbmTo.js → web-components-CaS0ksnZ.js} +1 -1
  63. package/dist/assets/zh-CN-CZ2BxZS6.js +16 -0
  64. package/dist/assets/zh-TW-BsUrPdXz.js +16 -0
  65. package/dist/index.html +5 -43
  66. package/dist/mini-chat.html +4 -4
  67. package/dist/mobile.html +4 -4
  68. package/package.json +3 -4
  69. package/server/index.d.ts +15 -0
  70. package/server/index.js +52 -10
  71. package/server/lib/changelog/update-notes.js +82 -0
  72. package/server/lib/changelog/update-notes.test.js +59 -0
  73. package/server/lib/data-dir-migration.js +40 -0
  74. package/server/lib/data-dir-migration.test.js +59 -0
  75. package/server/lib/event-stream/runtime.test.js +12 -12
  76. package/server/lib/fs/DOCUMENTATION.md +5 -0
  77. package/server/lib/fs/routes.js +63 -21
  78. package/server/lib/fs/routes.test.js +187 -1
  79. package/server/lib/git/DOCUMENTATION.md +29 -5
  80. package/server/lib/git/routes.js +24 -4
  81. package/server/lib/git/service.js +194 -198
  82. package/server/lib/git/service.test.js +440 -25
  83. package/server/lib/inherited-env.js +16 -9
  84. package/server/lib/inherited-env.test.js +8 -9
  85. package/server/lib/message-queue/DOCUMENTATION.md +20 -7
  86. package/server/lib/message-queue/runtime.js +59 -7
  87. package/server/lib/message-queue/runtime.test.js +59 -3
  88. package/server/lib/network-defaults.js +23 -0
  89. package/server/lib/network-defaults.test.js +52 -0
  90. package/server/lib/opencode/DOCUMENTATION.md +25 -5
  91. package/server/lib/opencode/bootstrap-runtime.js +2 -0
  92. package/server/lib/opencode/config-paths.test.js +116 -0
  93. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  94. package/server/lib/opencode/input-history-scope.js +14 -0
  95. package/server/lib/opencode/openchamber-routes.js +64 -4
  96. package/server/lib/opencode/openchamber-routes.test.js +128 -1
  97. package/server/lib/opencode/plugins.js +2 -2
  98. package/server/lib/opencode/providers.js +44 -2
  99. package/server/lib/opencode/providers.test.js +131 -4
  100. package/server/lib/opencode/routes.js +9 -7
  101. package/server/lib/opencode/server-startup-runtime.js +1 -1
  102. package/server/lib/opencode/settings-files.js +214 -0
  103. package/server/lib/opencode/settings-helpers.js +113 -41
  104. package/server/lib/opencode/settings-helpers.test.js +342 -0
  105. package/server/lib/opencode/settings-registry.json +747 -0
  106. package/server/lib/opencode/settings-runtime.js +139 -18
  107. package/server/lib/opencode/settings-runtime.test.js +163 -5
  108. package/server/lib/opencode/shared.js +4 -1
  109. package/server/lib/opencode/skill-routes.js +2 -1
  110. package/server/lib/opencode/snippets.js +1 -2
  111. package/server/lib/package-manager.js +3 -28
  112. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  113. package/server/lib/project-context/routes.http.test.js +18 -0
  114. package/server/lib/project-context/routes.js +15 -0
  115. package/server/lib/project-context/runtime.js +248 -23
  116. package/server/lib/project-context/runtime.test.js +106 -3
  117. package/server/lib/projects/DOCUMENTATION.md +76 -0
  118. package/server/lib/projects/project-config.js +142 -9
  119. package/server/lib/projects/project-id.js +17 -0
  120. package/server/lib/projects/project-setup.js +409 -0
  121. package/server/lib/projects/project-setup.test.js +557 -0
  122. package/server/lib/projects/routes.js +59 -0
  123. package/server/lib/quota/DOCUMENTATION.md +38 -1
  124. package/server/lib/quota/index.js +1 -0
  125. package/server/lib/quota/providers/cline-pass.js +125 -0
  126. package/server/lib/quota/providers/cline-pass.test.js +103 -0
  127. package/server/lib/quota/providers/hyper.js +118 -0
  128. package/server/lib/quota/providers/hyper.test.js +126 -0
  129. package/server/lib/quota/providers/index.js +15 -0
  130. package/server/lib/quota/providers/neuralwatt.js +3 -6
  131. package/server/lib/quota/providers/neuralwatt.test.js +7 -7
  132. package/server/lib/quota/providers/ollama-cloud.js +31 -0
  133. package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
  134. package/server/lib/quota/providers/opencode-go.js +1 -1
  135. package/server/lib/quota/providers/opencode-go.test.js +26 -1
  136. package/server/lib/quota/providers/openrouter.js +119 -24
  137. package/server/lib/quota/providers/openrouter.test.js +330 -0
  138. package/server/lib/quota/utils/auth.js +1 -1
  139. package/server/lib/relay/DOCUMENTATION.md +55 -0
  140. package/server/lib/relay/cross-compat.test.js +26 -0
  141. package/server/lib/relay/downstream-scheduler.js +154 -0
  142. package/server/lib/relay/downstream-scheduler.test.js +162 -0
  143. package/server/lib/relay/e2ee.js +10 -8
  144. package/server/lib/relay/flow-control.test.js +177 -0
  145. package/server/lib/relay/host-client.js +37 -8
  146. package/server/lib/relay/host-client.test.js +9 -1
  147. package/server/lib/relay/tunnel-codec.js +9 -0
  148. package/server/lib/relay/tunnel-host.js +66 -17
  149. package/server/lib/session-assist/runtime.js +6 -10
  150. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  151. package/server/lib/session-goal/runtime.js +80 -20
  152. package/server/lib/session-goal/runtime.test.js +426 -0
  153. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  154. package/server/lib/skills-catalog/install.js +3 -2
  155. package/server/lib/small-model/DOCUMENTATION.md +3 -2
  156. package/server/lib/small-model/call.js +9 -4
  157. package/server/lib/small-model/call.test.js +29 -0
  158. package/server/lib/small-model/index.js +5 -10
  159. package/server/lib/small-model/runtime-providers.js +15 -7
  160. package/server/lib/small-model/runtime-providers.test.js +7 -1
  161. package/server/lib/terminal/DOCUMENTATION.md +14 -10
  162. package/server/lib/terminal/runtime.js +160 -24
  163. package/server/lib/terminal/runtime.test.js +571 -37
  164. package/server/lib/terminal/shells.js +17 -0
  165. package/server/lib/terminal/shells.test.js +32 -1
  166. package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
  167. package/server/lib/walkthrough/model-settings.js +8 -12
  168. package/server/lib/walkthrough/prompt.js +3 -1
  169. package/server/lib/walkthrough/routes.test.js +26 -5
  170. package/server/lib/walkthrough/sources.js +23 -2
  171. package/dist/assets/DiffView-CNnDxRmO.js +0 -4
  172. package/dist/assets/FilesView-8wdiG2mj.js +0 -17
  173. package/dist/assets/MarkdownImageGallery-DffjmciG.js +0 -1
  174. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
  175. package/dist/assets/OnboardingScreen-CTZe6HZn.js +0 -1
  176. package/dist/assets/PierreDiffViewer-BvwtCxW4.js +0 -157
  177. package/dist/assets/PlanView-C1qvAm7m.js +0 -5
  178. package/dist/assets/SettingsView-xGONHFGS.js +0 -28
  179. package/dist/assets/WalkthroughView-D-HFgdmM.js +0 -4
  180. package/dist/assets/contextPanelEmbeddedChat-CV-DwAiX.js +0 -1
  181. package/dist/assets/de-Cv_4FoXm.js +0 -10
  182. package/dist/assets/es-BIWNEbnS.js +0 -16
  183. package/dist/assets/fr-SD3OfMHJ.js +0 -14
  184. package/dist/assets/index-CHUT_bDS.css +0 -1
  185. package/dist/assets/index-DDInLQDd.js +0 -40
  186. package/dist/assets/ja-D7I9HofF.js +0 -16
  187. package/dist/assets/ko-BsVJM_PQ.js +0 -16
  188. package/dist/assets/main-De8Z5w49.js +0 -928
  189. package/dist/assets/markdownCore-BoQVG5-a.js +0 -3
  190. package/dist/assets/patchFileDiff-Chmiz6hq.js +0 -10
  191. package/dist/assets/pl-XR9Bs8Be.js +0 -16
  192. package/dist/assets/pt-BR-Due4be8g.js +0 -16
  193. package/dist/assets/renderElectronMiniChatApp-8tXADjfl.js +0 -2
  194. package/dist/assets/renderMobileApp-Cji7Hma5.js +0 -25
  195. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
  196. package/dist/assets/scheduledTasksApi-9e-UX6im.js +0 -1
  197. package/dist/assets/tr-DBJcAv4y.js +0 -7
  198. package/dist/assets/uk-COYh2BaN.js +0 -16
  199. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
  200. package/dist/assets/useRootScrollLock-KzOUytpn.js +0 -1
  201. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
  202. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  203. package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
  204. package/dist/assets/zh-CN-Cjk6lzhc.js +0 -16
  205. package/dist/assets/zh-TW-Dk0dOg03.js +0 -16
@@ -1,17 +0,0 @@
1
- import{f as gt,R as n,c as Sn,j as s,r as ir}from"./vendor-react-BUCujlKS.js";import{V as la,W as ca,X as ua,Y as da,n as He,u as ht,dk as fa,C as kn,w as ma,r as Rn,_ as Tn,e as pa,di as ha,a1 as ga,dj as xa,a as va}from"./index-DDInLQDd.js";import{f as Bt,y as Vn,ac as Qn,bQ as wa,h as G,hr as ba,fj as ya,T as ss,B as z,I as b,W as ja,N as Fa,b7 as Na,ae as Ca,c5 as Sa,e9 as En,hs as Dn,ht as ka,gY as Ra,fk as Ta,t as Y,l as Pn,ao as ar,c0 as Cs,cB as Va,b as Ea,hu as or,bD as Da,ap as Mn,hv as zn,c1 as An,c2 as Pa,gb as Ma,hw as za,hx as Aa,hy as La,bE as Zn,bF as ei,bG as ti,bH as si,bI as ri,bJ as ni,b6 as mr,b3 as pr,ar as ks,b5 as hr,b2 as Rs,b$ as lr,aq as cr,bY as Ln,a7 as zt,a8 as At,a9 as Lt,bB as Ia,bC as Oa,g as Vs,b4 as Ba,be as $a}from"./useAppFontEffects-CCgvcQ6u.js";import{a0 as Wa,y as _a,z as Ua,A as Ka,E as Ha,F as qa}from"./runtimeEndpointReset-gWt3Lb5D.js";import{c as In,s as Ga,C as On,P as ur}from"./shikiHighlight-CRpCl7UT.js";import{a as Xa}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as Ja,F as Ya}from"./JsonTreeView-DUiIpERC.js";import{ensurePierreThemeRegistered as Bn,getResolvedShikiTheme as Qa}from"./appThemeRegistry-BK0dHKa6.js";import{V as Za,W as eo}from"./Virtualizer-CZlLSacm.js";import{V as to}from"./Virtualizer-D_a8gKmg.js";import{u as Ss,c as so,e as ro}from"./scheduledTasksApi-9e-UX6im.js";import{D as no}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as io,u as ao,n as oo}from"./useInlineCommentController-BkfXnjNZ.js";import{b as lo}from"./CodeMirrorCommentWidgets-BO_2OW4E.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-DVWEh-IS.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CV-DwAiX.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BxpoC5Fp.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-B6QgbmTo.js";import"./computeVirtualFileMetrics-DUnyszhW.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isFilePlainText-JPmZOYSp.js";import"./registerCustomTheme-BBXUCRnG.js";function $n(a){const e=gt.c(41),{containerRef:r,filePath:d,fileContent:v}=a,{t:g}=Bt(),x=Vn(xo),w=Vn(go),f=Qn(),C=wa(ho),[h,F]=n.useState(null),[N,k]=n.useState(""),[j,T]=n.useState(!1),o=n.useRef(!1),L=n.useRef(null),I=n.useRef(null),[W,A]=n.useState(null);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{F(null),k(""),T(!1),o.current=!1,I.current=null,A(null)},e[0]=E):E=e[0];const V=E;let S,M;e[1]!==r?(S=()=>{const B=r.current;if(!B)return;const q=()=>{if(o.current)return;const re=window.getSelection(),Se=re?.toString().trim()??"";if(!re||!Se||re.rangeCount===0){V();return}const ie=re.getRangeAt(0);if(!B.contains(ie.commonAncestorContainer)){V();return}const ae=ie.getBoundingClientRect();I.current=ie.cloneRange(),k(Se),F({x:ae.left+ae.width/2,y:ae.top-10})},se=re=>{L.current?.contains(re.target)||o.current&&V()};return document.addEventListener("selectionchange",q),document.addEventListener("pointerdown",se),()=>{document.removeEventListener("selectionchange",q),document.removeEventListener("pointerdown",se)}},M=[r,V],e[1]=r,e[2]=S,e[3]=M):(S=e[2],M=e[3]),n.useEffect(S,M);let $;e[4]!==v?($=B=>{const q=de=>v.slice(0,de).split(`
2
- `).length,se=mo,re=(de,Ve)=>{for(const Ee of se(de)){const ke=v.indexOf(Ee,Ve);if(ke>=0)return ke}return-1},Se=B.length>=8?v.indexOf(B):-1;if(Se>=0){const de=q(Se);return{start:de,end:de+B.split(`
3
- `).length-1}}const ie=B.split(`
4
- `).map(fo).filter(Boolean);if(ie.length===0)return null;const ae=re(ie[0],0);if(ae<0)return null;const ye=q(ae);if(ie.length===1)return{start:ye,end:ye};const Te=re(ie[ie.length-1],ae);return Te<0?null:{start:ye,end:Math.max(ye,q(Te))}},e[4]=v,e[5]=$):$=e[5];const P=$;let J;e[6]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{const B=I.current;if(!B){A(null);return}A(ba(B))},e[6]=J):J=e[6];const Ne=J;let _,Q;e[7]!==j?(_=()=>{if(!j)return;let B=null;const q=()=>{B===null&&(B=window.requestAnimationFrame(()=>{B=null,Ne()}))};return document.addEventListener("scroll",q,{capture:!0,passive:!0}),window.addEventListener("resize",q),()=>{B!==null&&window.cancelAnimationFrame(B),document.removeEventListener("scroll",q,{capture:!0}),window.removeEventListener("resize",q)}},Q=[j,Ne],e[7]=j,e[8]=_,e[9]=Q):(_=e[8],Q=e[9]),n.useEffect(_,Q);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==C||e[13]!==x||e[14]!==f||e[15]!==d||e[16]!==w||e[17]!==P||e[18]!==N?(te=B=>{const q=x??(w?"draft":null);if(!N||!q||!f){V();return}const se=P(N);C({directory:f,sessionKey:q},{source:"file-quote",fileLabel:d,startLine:se?.start??0,endLine:se?.end??0,code:N,language:"",text:B.trim()}),V(),queueMicrotask(uo)},e[12]=C,e[13]=x,e[14]=f,e[15]=d,e[16]=w,e[17]=P,e[18]=N,e[19]=te):te=e[19];const Ce=te;if(!h)return null;let O;e[20]!==j||e[21]!==P||e[22]!==N?(O=j?P(N):null,e[20]=j,e[21]=P,e[22]=N,e[23]=O):O=e[23];const ve=O;let we;e[24]!==h.x||e[25]!==h.y?(we={left:h.x,top:h.y,transform:"translate(-50%, -100%)"},e[24]=h.x,e[25]=h.y,e[26]=we):we=e[26];let ce;e[27]!==j||e[28]!==W?(ce=j&&W&&W.length>0?Sn.createPortal(s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:W.map(co)}),document.body):null,e[27]=j,e[28]=W,e[29]=ce):ce=e[29];let ue;e[30]!==j||e[31]!==d||e[32]!==ve||e[33]!==le||e[34]!==Ce||e[35]!==g?(ue=j?s.jsx("div",{className:"w-[min(420px,80vw)]",children:s.jsx(io,{fileLabel:d,lineRange:ve?{start:ve.start,end:ve.end}:void 0,onSave:Ce,onCancel:V})}):s.jsx("div",{className:G("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:s.jsx("button",{type:"button",onClick:le,className:G("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=ve,e[33]=le,e[34]=Ce,e[35]=g,e[36]=ue):ue=e[36];let be;return e[37]!==we||e[38]!==ce||e[39]!==ue?(be=Sn.createPortal(s.jsxs("div",{ref:L,className:"fixed z-50",style:we,children:[ce,ue]}),document.body),e[37]=we,e[38]=ce,e[39]=ue,e[40]=be):be=e[40],be}function co(a,e){return s.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function uo(){ya()}function fo(a){return a.trim()}function mo(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(po)}function po(a){return a.length>=8}function ho(a){return a.addDraft}function go(a){return a.newSessionDraft?.open}function xo(a){return a.currentSessionId}const vo=(a,e)=>{if(!e)return null;const r=Number.parseInt(a.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Wn=(a,e)=>{const r=a.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},_n=(a,e,r)=>{const d=a.state.doc.line(e),v=Math.max(1,Math.min(r,d.length+1)),g=d.from+v-1;a.dispatch({selection:Xa.cursor(g),effects:jt.scrollIntoView(g,{y:"center"})})};function wo({open:a,onOpenChange:e,view:r,variant:d="overlay"}){const{t:v}=Bt(),[g,x]=n.useState(""),w=n.useRef(null),f=n.useRef(!1),C=n.useRef(null),h=n.useRef(null),F=n.useMemo(()=>vo(g,r),[g,r]);n.useEffect(()=>{!a||!r||(f.current=!1,w.current=Wn(r,r.state.selection),x(""))},[a,r]),n.useEffect(()=>{a&&window.requestAnimationFrame(()=>{h.current?.focus(),h.current?.select()})},[a]),n.useEffect(()=>{if(!(!a||!r||!w.current)){if(F===null){const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}_n(r,F,w.current.character)}},[F,a,r]);const N=n.useCallback(()=>{if(!r||f.current||!w.current)return;const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[r]),k=n.useCallback(o=>{o||N(),e(o)},[e,N]),j=n.useCallback(()=>{!r||F===null||!w.current||(f.current=!0,_n(r,F,w.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!a)return;const o=I=>{const W=C.current,A=I.target;!W||!(A instanceof Node)||W.contains(A)||k(!1)},L=I=>{I.key==="Escape"&&(I.preventDefault(),k(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",L,!0)}},[k,a,d]);const T=n.useMemo(()=>{if(!r)return v("goToLineDialog.helper.editorUnavailable");if(F===null){const o=w.current??Wn(r,r.state.selection);return v("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:r.state.doc.lines})}return v("goToLineDialog.helper.goToLine",{line:F})},[F,v,r]);return d==="inline"?a?s.jsxs("div",{ref:C,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(z,{variant:"outline",size:"xs",onClick:j,disabled:!r||F===null,className:"h-6 px-2",children:v("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:C,className:G("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const bo=(a,e)=>{const r=e.trim().toLowerCase(),d=[];if(!r)return d;const v=a.toLowerCase();let g=0;for(;;){const x=v.indexOf(r,g);if(x===-1)break;d.push({start:x,end:x+r.length}),g=x+r.length}return d},Ds="data-md-find",dr="data-md-find-current",ii="rounded-[2px] bg-status-warning/30 text-foreground",yo="rounded-[2px] bg-status-warning/60 text-foreground",jo=120,Fo=a=>a instanceof Element&&a.hasAttribute(Ds),No=a=>a.target instanceof Element&&a.target.hasAttribute(Ds)?!0:[...a.addedNodes].some(e=>Fo(e)),ai=a=>{const e=new Set;a.querySelectorAll(`mark[${Ds}]`).forEach(r=>{const d=r.parentNode;d&&(d.replaceChild(document.createTextNode(r.textContent??""),r),e.add(d))}),e.forEach(r=>r.normalize())},Co=(a,e)=>{ai(a);const r=e.trim().toLowerCase();if(!r)return[];const d=[],v=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(x){const w=x.parentElement;return!w||w.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;v.nextNode();){const x=v.currentNode;x instanceof Text&&g.push(x)}for(const x of g){const w=x.nodeValue??"";if(!w)continue;const f=bo(w,r);if(f.length===0)continue;const C=x.parentNode;if(!C)continue;const h=document.createDocumentFragment();let F=0;for(const N of f){N.start>F&&h.appendChild(document.createTextNode(w.slice(F,N.start)));const k=document.createElement("mark");k.setAttribute(Ds,""),k.className=ii,k.textContent=w.slice(N.start,N.end),h.appendChild(k),d.push(k),F=N.end}F<w.length&&h.appendChild(document.createTextNode(w.slice(F))),C.replaceChild(h,x)}return d},Un=({containerRef:a,open:e,onOpenChange:r,focusNonce:d,className:v})=>{const{t:g}=Bt(),[x,w]=n.useState(""),[f,C]=n.useState(0),[h,F]=n.useState(0),N=n.useRef(null),k=n.useRef([]),j=n.useRef(x);j.current=x;const T=n.useRef(null),o=n.useRef(null),L=n.useCallback((S,M=!1)=>{const $=a.current;if(!$){k.current=[],C(0),F(0);return}k.current=Co($,S);const P=k.current.length;C(P),F(J=>!M||P===0?0:Math.min(J,P-1))},[a]),I=n.useCallback((S,M=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,L(S,M)},jo)},[L]);n.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const W=n.useCallback(()=>{r(!1);const S=o.current;o.current=null,S?.isConnected&&S.focus()},[r]);n.useEffect(()=>{const S=a.current;if(!e||!S)return;const M=new MutationObserver($=>{!j.current.trim()||!$.some(J=>!No(J))||I(j.current,!0)});return M.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>{M.disconnect(),ai(S)}},[a,e,I]),n.useEffect(()=>{if(!e)return;const S=document.activeElement;S instanceof HTMLElement&&!o.current&&(o.current=S),N.current?.focus()},[e]),n.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),n.useEffect(()=>{const S=a.current;if(!S||(S.querySelectorAll(`mark[${dr}]`).forEach($=>{$.removeAttribute(dr),$.className=ii}),f===0))return;const M=k.current[Math.min(Math.max(h,0),f-1)];M&&(M.setAttribute(dr,""),M.className=yo,M.scrollIntoView({block:"nearest"}))},[a,h,f]);const A=n.useCallback(()=>{F(S=>f===0?0:(S+1)%f)},[f]),E=n.useCallback(()=>{F(S=>f===0?0:(S-1+f)%f)},[f]),V=n.useCallback(S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?E():A()):S.key==="Escape"&&(S.preventDefault(),W())},[W,A,E]);return e?s.jsxs("div",{className:G("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",v),children:[s.jsx(b,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),s.jsx(ss,{ref:N,value:x,onChange:S=>{w(S.target.value),I(S.target.value)},onKeyDown:V,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),s.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:h+1,total:f}):g("filesView.preview.find.noMatches"),children:x.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${h+1}/${f}`:""}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:E,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-up",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:A,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-down",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:W,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:s.jsx(b,{name:"close",className:"size-3.5"})})]}):null};function Kn(){const a=gt.c(8),[e]=ir.useState(So),r=ir.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),r.current=!1;return}r.current||(r.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const v=d;let g,x;a[2]!==e?(g=()=>()=>{r.current=!1,e.cleanUp()},x=[e],a[2]=e,a[3]=g,a[4]=x):(g=a[3],x=a[4]),ir.useLayoutEffect(g,x);let w;return a[5]!==v||a[6]!==e?(w={virtualizer:e,setScroller:v},a[5]=v,a[6]=e,a[7]=w):w=a[7],w}function So(){return new to}function ko(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function Ro(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const To='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function Hn(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const Vo=n.forwardRef(function({xml:e,readOnly:r,className:d,onChange:v},g){const x=n.useRef(e),w=n.useRef(null),f=n.useRef(!1),[C,h]=n.useState(Hn),F=n.useRef(e),N=n.useRef(e);N.current!==e&&(N.current=e,F.current=e,x.current=e);const k=n.useRef(C);k.current!==C&&(k.current=C,F.current=x.current);const j=n.useRef(null);n.useEffect(()=>{const L=()=>h(Hn());L();const I=new MutationObserver(L);return I.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>I.disconnect()},[]),n.useEffect(()=>{const L=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(L)},[]),n.useImperativeHandle(g,()=>({getXml:()=>x.current}));const T=n.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{w.current?.template({})},500))},[e]),o=n.useCallback(L=>{x.current=L.xml,v?.(L.xml)},[v]);return s.jsx("div",{ref:j,className:G("h-full w-full",d),children:s.jsx(no,{ref:w,xml:F.current||To,autosave:!0,urlParameters:{ui:r?"simple":C?"dark":"kennedy",spin:!0,libraries:!r,chrome:r,nav:r,layers:r,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},C?"dark":"light")})}),Eo=a=>{const e=H(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const d=e.slice(0,r);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},Do=a=>{const e=gt.c(8),{label:r,iconDataUrl:d}=a,[v,g]=n.useState(!1);let x;e[0]!==r?(x=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=x):x=e[1];const w=x;if(d&&!v){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>g(!0),e[2]=h):h=e[2];let F;return e[3]!==d?(F=s.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:h}),e[3]=d,e[4]=F):F=e[4],F}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=G("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let C;return e[6]!==w?(C=s.jsx("span",{className:f,children:w}),e[6]=w,e[7]=C):C=e[7],C},Po=a=>a.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),H=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),r=e.startsWith("//");let d=e.replace(/\/+/g,"/");r&&!d.startsWith("//")&&(d=`/${d}`);const v=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!v&&!g&&(d=d.replace(/\/+$/,"")),d},Mo=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Ot=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,Es=(a,e)=>{const r=H(e),d=H(a);if(!r||!d)return!1;const v=Ot(r),g=Ot(d);return g===v||g.startsWith(`${v}/`)},qn=(a,e)=>{const r=H(e),d=H(a);if(!Es(d,r))return[];const g=d.slice(r.length).replace(/^\//,"").split("/"),x=[];let w=r;for(let f=0;f<g.length-1;f++)w=w?`${w}/${g[f]}`:g[f],x.push(w);return x},Ts=(a,e)=>{if(!e)return"";const r=H(e);if(!a||!Es(r,a))return r;const d=r.slice(a.length);return d.startsWith("/")?d.slice(1):d},zo=new Set(["node_modules"]),Ao=a=>{const e=gt.c(3),{status:r}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=d):d=e[0];const v=d[r];let g;return e[1]!==v?(g=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:v}}),e[1]=v,e[2]=g):g=e[2],g},Gn=a=>{const e=gt.c(11),{name:r}=a,d=n.useRef(null),v=n.useRef(null),[g,x]=n.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const N=d.current,k=v.current;if(!N||!k)return;const j=()=>{x(k.scrollWidth>N.clientWidth+1)};j();const T=new ResizeObserver(j);return T.observe(N),T.observe(k),()=>{T.disconnect()}},e[0]=w):w=e[0];let f;e[1]!==r?(f=[r],e[1]=r,e[2]=f):f=e[2],n.useLayoutEffect(w,f);let C;e[3]!==r?(C=s.jsx("span",{ref:v,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=C):C=e[4];let h;e[5]!==r||e[6]!==g?(h=g?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=g,e[7]=h):h=e[7];let F;return e[8]!==C||e[9]!==h?(F=s.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,h]}),e[8]=C,e[9]=h,e[10]=F):F=e[10],F},Lo=a=>zo.has(a),Io=a=>{const e=H(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Oo=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Xn=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},It=2e5;function Bo(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let r=2166136261;for(let d=0;d<e.length;d+=1)r^=e.charCodeAt(d),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return`${a.length}:${r.toString(16)}`}const $o=a=>{let e=0,r=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:r+=1);return e>r?`\r
5
- `:`
6
- `},oi=a=>a.replace(/\r\n/g,`
7
- `).replace(/\r/g,`
8
- `),Wo=(a,e)=>{const r=oi(a);return e===`\r
9
- `?r.replace(/\n/g,`\r
10
- `):r},li=(a,e)=>s.jsx(ks,{filePath:a,extension:e}),Jn=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},_o=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},fr=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Uo=a=>{const e=gt.c(76),{node:r,root:d,isExpanded:v,isActive:g,isMobile:x,isBrowserClient:w,alwaysShowActions:f,status:C,badge:h,permissions:F,downloadFile:N,contextMenuPath:k,setContextMenuPath:j,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:L,onToggle:I,onRevealPath:W,onOpenDialog:A}=a,{t:E}=Bt(),V=r.type==="directory",{canRename:S,canCreateFile:M,canCreateFolder:$,canDelete:P,canReveal:J}=F,Ne=!V&&!!N,_=J&&!w,Q=S||M||$||P||Ne||_;let ee;e[0]!==Q||e[1]!==r.path||e[2]!==o?(ee=fe=>{Q&&(fe?.preventDefault(),o(r.path))},e[0]=Q,e[1]=r.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==V||e[5]!==r||e[6]!==L||e[7]!==I?(te=()=>{V?I(r.path):L(r)},e[4]=V,e[5]=r,e[6]=L,e[7]=I,e[8]=te):te=e[8];const Ce=te;let O;e[9]!==r.path||e[10]!==j||e[11]!==o?(O=fe=>{fe.stopPropagation(),o(null),j(r.path)},e[9]=r.path,e[10]=j,e[11]=o,e[12]=O):O=e[12];const ve=O;let we;e[13]!==M||e[14]!==$||e[15]!==P||e[16]!==S||e[17]!==_||e[18]!==N||e[19]!==w||e[20]!==V||e[21]!==r||e[22]!==A||e[23]!==W||e[24]!==d||e[25]!==E?(we=fe=>{const{Item:he,Separator:et}=fe;return s.jsxs(s.Fragment,{children:[S&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("rename",r)},children:[s.jsx(b,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),Vs(r.path).then(at=>{if(at.ok){Y.success(E("sidebarFilesTree.toast.pathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation();const at=Ts(d,r.path)||r.path;Vs(at).then(me=>{if(me.ok){Y.success(E("filesView.toast.relativePathCopied"));return}Y.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!V&&N&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),N(r.path).catch(at=>{console.error("Download failed:",at),Y.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"})," ",E(w?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),_&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),W(r.path)},children:[s.jsx(b,{name:"folder-received",className:"mr-2 size-4"})," ",E($a())]}),V&&(M||$)&&s.jsxs(s.Fragment,{children:[s.jsx(et,{}),M&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFile",r)},children:[s.jsx(b,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),$&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFolder",r)},children:[s.jsx(b,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(et,{}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(b,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=M,e[14]=$,e[15]=P,e[16]=S,e[17]=_,e[18]=N,e[19]=w,e[20]=V,e[21]=r,e[22]=A,e[23]=W,e[24]=d,e[25]=E,e[26]=we):we=e[26];const ce=we,ue=T===r.path;let be;e[27]!==r.path||e[28]!==o?(be=fe=>o(fe?r.path:null),e[27]=r.path,e[28]=o,e[29]=be):be=e[29];const B=x?void 0:le;let q;e[30]!==B?(q=s.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[30]=B,e[31]=q):q=e[31];const se=x?void 0:le,re=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==re?(Se=G("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",re),e[32]=re,e[33]=Se):Se=e[33];let ie;e[34]!==V||e[35]!==v||e[36]!==r.extension||e[37]!==r.path?(ie=V?v?s.jsx(b,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(b,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):li(r.path,r.extension),e[34]=V,e[35]=v,e[36]=r.extension,e[37]=r.path,e[38]=ie):ie=e[38];let ae;e[39]!==r.name||e[40]!==r.path?(ae=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ae):ae=e[41];let ye;e[42]!==V||e[43]!==C?(ye=!V&&C&&s.jsx(Ao,{status:C}),e[42]=V,e[43]=C,e[44]=ye):ye=e[44];let Te;e[45]!==h||e[46]!==V?(Te=V&&h&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[h.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",h.modified]}),h.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",h.added]})]}),e[45]=h,e[46]=V,e[47]=Te):Te=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ie||e[51]!==ae||e[52]!==ye||e[53]!==Te||e[54]!==se?(de=s.jsxs("button",{type:"button",onClick:Ce,onContextMenu:se,className:Se,children:[ie,ae,ye,Te]}),e[48]=Ce,e[49]=Se,e[50]=ie,e[51]=ae,e[52]=ye,e[53]=Te,e[54]=se,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==k||e[58]!==ve||e[59]!==Q||e[60]!==x||e[61]!==r.path||e[62]!==ce||e[63]!==j?(Ve=Q&&s.jsx("div",{className:G("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(mr,{open:k===r.path,onOpenChange:fe=>j(fe?r.path:null),children:[s.jsx(pr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:ve,children:s.jsx(b,{name:"more-2-fill",className:"size-4"})})}),s.jsx(hr,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Rs,Separator:Ba})})]})}),e[56]=f,e[57]=k,e[58]=ve,e[59]=Q,e[60]=x,e[61]=r.path,e[62]=ce,e[63]=j,e[64]=Ve):Ve=e[64];let Ee;e[65]!==de||e[66]!==Ve||e[67]!==q?(Ee=s.jsxs(Ha,{render:q,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=q,e[68]=Ee):Ee=e[68];let ke;e[69]!==ce?(ke=s.jsx(_a,{className:"min-w-[180px]",children:ce({Item:Ka,Separator:Ua})}),e[69]=ce,e[70]=ke):ke=e[70];let Z;return e[71]!==Ee||e[72]!==ke||e[73]!==ue||e[74]!==be?(Z=s.jsxs(qa,{open:ue,onOpenChange:be,children:[Ee,ke]}),e[71]=Ee,e[72]=ke,e[73]=ue,e[74]=be,e[75]=Z):Z=e[75],Z},Ko=a=>{const e=gt.c(83),{activeDialog:r,dialogData:d,dialogInputValue:v,onDialogInputChange:g,isDialogSubmitting:x,onDialogSubmit:w,onClose:f,inputRef:C}=a,{t:h}=Bt(),F=!!r;let N;e[0]!==f?(N=O=>!O&&f(),e[0]=f,e[1]=N):N=e[1];let k;e[2]!==r||e[3]!==h?(k=r==="createFile"&&h("filesView.dialog.createFile.title"),e[2]=r,e[3]=h,e[4]=k):k=e[4];let j;e[5]!==r||e[6]!==h?(j=r==="createFolder"&&h("filesView.dialog.createFolder.title"),e[5]=r,e[6]=h,e[7]=j):j=e[7];let T;e[8]!==r||e[9]!==h?(T=r==="rename"&&h("filesView.dialog.rename.title"),e[8]=r,e[9]=h,e[10]=T):T=e[10];let o;e[11]!==r||e[12]!==h?(o=r==="delete"&&h("filesView.dialog.delete.title"),e[11]=r,e[12]=h,e[13]=o):o=e[13];let L;e[14]!==k||e[15]!==j||e[16]!==T||e[17]!==o?(L=s.jsxs(si,{children:[k,j,T,o]}),e[14]=k,e[15]=j,e[16]=T,e[17]=o,e[18]=L):L=e[18];let I;e[19]!==r||e[20]!==d?.path||e[21]!==h?(I=r==="createFile"&&h("filesView.dialog.createFile.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[19]=r,e[20]=d?.path,e[21]=h,e[22]=I):I=e[22];let W;e[23]!==r||e[24]!==d?.path||e[25]!==h?(W=r==="createFolder"&&h("filesView.dialog.createFolder.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[23]=r,e[24]=d?.path,e[25]=h,e[26]=W):W=e[26];let A;e[27]!==r||e[28]!==d?.name||e[29]!==h?(A=r==="rename"&&h("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=r,e[28]=d?.name,e[29]=h,e[30]=A):A=e[30];let E;e[31]!==r||e[32]!==d?.name||e[33]!==h?(E=r==="delete"&&h("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=r,e[32]=d?.name,e[33]=h,e[34]=E):E=e[34];let V;e[35]!==A||e[36]!==E||e[37]!==I||e[38]!==W?(V=s.jsxs(ri,{children:[I,W,A,E]}),e[35]=A,e[36]=E,e[37]=I,e[38]=W,e[39]=V):V=e[39];let S;e[40]!==V||e[41]!==L?(S=s.jsxs(ti,{children:[L,V]}),e[40]=V,e[41]=L,e[42]=S):S=e[42];let M;e[43]!==r||e[44]!==v||e[45]!==C||e[46]!==g||e[47]!==w||e[48]!==h?(M=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ss,{value:v,onChange:O=>g(O.target.value),placeholder:h(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&w()},ref:C})}),e[43]=r,e[44]=v,e[45]=C,e[46]=g,e[47]=w,e[48]=h,e[49]=M):M=e[49];let $;e[50]!==h?($=h("filesView.dialog.cancel"),e[50]=h,e[51]=$):$=e[51];let P;e[52]!==x||e[53]!==f||e[54]!==$?(P=s.jsx(z,{variant:"outline",onClick:f,disabled:x,children:$}),e[52]=x,e[53]=f,e[54]=$,e[55]=P):P=e[55];const J=r==="delete"?"destructive":"default";let Ne;e[56]!==w?(Ne=()=>{w()},e[56]=w,e[57]=Ne):Ne=e[57];let _;e[58]!==r||e[59]!==v||e[60]!==x?(_=x||r!=="delete"&&!v.trim(),e[58]=r,e[59]=v,e[60]=x,e[61]=_):_=e[61];let Q;e[62]!==r||e[63]!==x||e[64]!==h?(Q=x?s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}):h(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=x,e[64]=h,e[65]=Q):Q=e[65];let ee;e[66]!==J||e[67]!==Ne||e[68]!==_||e[69]!==Q?(ee=s.jsx(z,{variant:J,onClick:Ne,disabled:_,children:Q}),e[66]=J,e[67]=Ne,e[68]=_,e[69]=Q,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=s.jsxs(ni,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==C||e[75]!==S||e[76]!==M||e[77]!==le?(te=s.jsxs(ei,{initialFocus:C,children:[S,M,le]}),e[74]=C,e[75]=S,e[76]=M,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==F||e[80]!==N||e[81]!==te?(Ce=s.jsx(Zn,{open:F,onOpenChange:N,children:te}),e[79]=F,e[80]=N,e[81]=te,e[82]=Ce):Ce=e[82],Ce},Yn=(a,e,r)=>{const d=gt.c(8),[v,g]=n.useState(""),[x,w]=n.useState(0);let f,C;d[0]!==a||d[1]!==r||d[2]!==e?(f=()=>{if(!a){g("");return}let F=!1;g("");const N=pa(),k=ha(N);ga(N).then(T=>{F||!T||(g(a),e(null))}).catch(T=>{F||(e(T instanceof Error?T.message:r),g(a))});const j=xa(()=>{F||(g(a),w(Ho),e(null))});return()=>{F=!0,k(),j()}},C=[a,e,r],d[0]=a,d[1]=r,d[2]=e,d[3]=f,d[4]=C):(f=d[3],C=d[4]),n.useEffect(f,C);let h;return d[5]!==x||d[6]!==v?(h={readyKey:v,nonce:x},d[5]=x,d[6]=v,d[7]=h):h=d[7],h},mu=({mode:a="full"})=>{const{t:e}=Bt(),{files:r,runtime:d}=ja(),{currentTheme:v,availableThemes:g,lightThemeId:x,darkThemeId:w}=Fa(),{isMobile:f,isTablet:C,screenWidth:h}=Na(),F=la(d.platform),N=f||C,k=ca(),j=ua(),T=Qn()??"",o=H(T.trim()),L=a!=="editor-only",I=a==="editor-only"&&!f,W=da(t=>t.searchFiles),A=Ca(T),[E,V]=n.useState(""),S=Sa(E,200),M=n.useRef(null),[$,P]=n.useState(!1),[J,Ne]=n.useState(!0),[_,Q]=n.useState(!1),[ee,le]=n.useState(!1),te=n.useRef(0),Ce=n.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[O,ve]=n.useState("edit"),[we,ce]=n.useState("edit"),[ue,be]=n.useState("tree"),[B,q]=n.useState("edit"),[se,re]=n.useState("preview"),[Se,ie]=n.useState(0),ae=n.useRef({}),ye=n.useRef({}),Te=n.useRef({}),de=n.useRef({}),Ve=n.useMemo(()=>g.find(t=>t.metadata.id===x)??En(!1),[g,x]),Ee=n.useMemo(()=>g.find(t=>t.metadata.id===w)??En(!0),[g,w]);n.useEffect(()=>{Bn(Ve),Bn(Ee)},[Ve,Ee]);const ke=n.useMemo(()=>[],[]),Z=He(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=He(t=>o?t.byRoot[o]?.selectedPath??null:null),he=He(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),et=He(t=>t.removeOpenPath),X=He(t=>t.removeOpenPathsByPrefix),at=He(t=>t.removeExpandedPathsByPrefix),me=He(t=>t.setSelectedPath),gr=He(t=>t.toggleExpandedPath),rs=He(t=>t.expandPaths),Ft=n.useCallback(t=>{const i=H(t),l=i.split("/"),u=l[l.length-1]||i,p=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:p}},[]),Nt=n.useMemo(()=>Z.map(Ft),[Z,Ft]),Ps=n.useMemo(()=>{if(fe){const t=Ot(fe);if(Z.some(i=>Ot(i)===t))return fe}return Z[0]??null},[Z,fe]),c=n.useMemo(()=>Ps?Ft(Ps):null,[Ps,Ft]),qe=c?.path??"",[,ci]=n.useState(0);n.useEffect(()=>{if(!o||!fe)return;const t=Ot(fe);Z.some(l=>Ot(l)===t)||me(o,Z[0]??null)},[Z,o,fe,me]);const ns=!!(o&&qe&&!Es(qe,o)),xr=ns?Dn(qe):void 0,xt=n.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ns,outsideFileGrant:xr,directory:o||void 0}),[a,ns,xr,o]),Ge=n.useCallback(async t=>{const i=Dn(t),l=await ka(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&ci(u=>u+1),l},[a,o]),Ms=n.useRef(null),[vr,ui]=n.useState({left:!1,right:!1}),wr=n.useCallback(()=>{const t=Ms.current;t&&ui({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),br=n.useRef(wr);br.current=wr,n.useEffect(()=>{const t=Ms.current;if(!t)return;const i=()=>br.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Nt.length]);const[yr,zs]=n.useState({}),[is,$t]=n.useState({}),ze=n.useRef(new Set),Ae=n.useRef(new Set),tt=n.useRef(new Map),jr=n.useRef(0),[Fr,as]=n.useState([]),[di,os]=n.useState(!1),[D,pe]=n.useState(""),{isPlaying:ls,play:fi,stop:mi}=Ra(),[Le,ot]=n.useState(!1),[st,ge]=n.useState(null),[pi,Ie]=n.useState(""),[De,oe]=n.useState(null),[ne,xe]=n.useState(""),[Wt,As]=n.useState(!1),[Nr,hi]=n.useState(`
11
- `),gi=n.useRef(null),Xe=n.useRef(null),Pe=n.useRef(null),lt=n.useRef(""),_t=n.useRef(""),rt=n.useRef(null),Cr=n.useRef(null),Je=n.useRef(null),Ut=n.useRef(0),Ct=n.useRef(null),[cs,xi]=n.useState(0),[vi,St]=n.useState("idle"),[wi,us]=n.useState(!1),[Kt,Sr]=n.useState(!1),je=ht(t=>t.autoSaveEnabled),bi=ht(t=>t.setAutoSaveEnabled),[Ls,Ht]=n.useState(!1),kt=n.useRef(null),qt=n.useRef(null),Gt=n.useRef(!1),Xt=n.useRef(null),Jt=n.useRef(null),We=n.useRef(null),ds=n.useRef(null),[yi,Is]=n.useState(0),Rt=n.useRef(null),vt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[wt,Os]=n.useState(null),[bt,ji]=n.useState(null),[ct,kr]=n.useState(""),[Fi,Bs]=n.useState(!1),[Ni,Ci]=n.useState(null),[Si,ki]=n.useState(null),[Ri,Rr]=n.useState(!1),[Ti,Tr]=n.useState(!1),[Vi,$s]=n.useState(!1),[Vr,fs]=n.useState(!1),[Er,Dr]=n.useState(0),ms=n.useRef(null),ps=n.useCallback(t=>{const i=t?.currentTarget??ms.current;if(!i)return;const l=document.activeElement;l&&l!==document.body&&l!==i&&(Ta(l)||i.contains(l))||i.focus({preventScroll:!0})},[]),Ws=n.useRef(null),Pr=!!r.writeFile,Mr=!!r.createDirectory,zr=!!r.rename,Ar=!!r.delete,Lr=!!r.revealPath,Ei=Ss(t=>t.availableApps),Di=Ss(t=>t.isCacheStale),Ir=Ss(t=>t.initialize),Pi=Ss(t=>t.loadInstalledApps);n.useEffect(()=>{Ir()},[Ir]);const Mi=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{Y.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),zi=n.useCallback(async t=>{if(!c?.path||await fa(c.path,t.id,t.appName)||await kn(c.path,t.appName))return;const u=Eo(c.path)||o;u&&await kn(u,t.appName)||Y.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),_s=n.useCallback((t,i)=>{Os(t),ji(i),kr(t==="rename"&&i.name||""),Bs(!1)},[]),[U,_e]=n.useState(null),Tt=n.useRef(!1),ut=n.useRef(null),[Or,Vt]=n.useState(!1),Ye=ht(t=>t.pendingFileNavigation),hs=ht(t=>t.setPendingFileNavigation),Us=ht(t=>t.pendingFileFocusPath),Ks=ht(t=>t.setPendingFileFocusPath),Br=ht(t=>t.fileEditorKeymap),Yt=Pn(t=>t.settingsDefaultFileViewerPreview),Ai=Pn(t=>t.showMessageTTSButtons);n.useEffect(()=>{const t=()=>{Tt.current=!1,ut.current=null,Vt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Xt.current!==null&&window.clearTimeout(Xt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);const Li=n.useCallback((t,i)=>{const l=t.split(`
12
- `),u=Math.max(1,i.start),p=Math.min(l.length,i.end);return u>p?"":l.slice(u-1,p).join(`
13
- `)},[]),gs=n.useRef(null),Ii=ao({source:"file",fileLabel:c?.path??null,language:c?.path&&ar(c.path)||"text",getCodeForRange:t=>Li(D,oo(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:$r,commentText:xs,setCommentText:Wr,editingDraftId:vs,setSelection:_r,saveComment:Ur,cancel:Qt,reset:Kr,startEdit:Hr,deleteDraft:qr}=Ii;n.useEffect(()=>{_e(null),Kr(),xe(""),As(!1)},[c?.path,Kr]),n.useEffect(()=>{_r(U)},[U,_r]),n.useEffect(()=>{if(!U&&!vs)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||xs.trim()||(_e(null),Qt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Qt,xs,vs,U]);const Gr=n.useCallback((t,i)=>{const l=i??U??void 0;i&&_e(i),Ur(t,l),_e(null)},[U,Ur]),Xr=n.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!k&&u.name.startsWith(".")||!j&&Lo(u.name))continue;const p=u.name,m=H(u.path||""),y=m?Mo(m)?m:H(`${t}/${m}`):H(`${t}/${p}`),R=u.isDirectory?"directory":"file",K=R==="file"&&p.includes(".")?p.split(".").pop()?.toLowerCase():void 0;l.push({name:p,path:y,type:R,extension:K})}return Po(l)},[j,k]),Oe=n.useCallback(async t=>{const i=H(t.trim());if(!i||ze.current.has(i)||Ae.current.has(i))return;Ae.current=new Set(Ae.current),Ae.current.add(i);const l=jr.current+1;jr.current=l,tt.current=new Map(tt.current),tt.current.set(i,l);const u=()=>tt.current.get(i)===l;await(r.listDirectory?r.listDirectory(i).then(m=>m.entries.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory}))):ma.listLocalDirectory(i).then(m=>m.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory})))).then(m=>{if(!u())return;const y=Xr(i,m);ze.current=new Set(ze.current),ze.current.add(i),$t(R=>{if(!R[i])return R;const K={...R};return delete K[i],K}),zs(R=>({...R,[i]:y}))}).catch(m=>{if(!u())return;const y=m instanceof Error?m.message:String(m??"");if(y==="Directory not found"&&o&&i!==o){at(o,i),$t(R=>{if(!R[i])return R;const K={...R};return delete K[i],K});return}console.error("Failed to load files directory:",m),$t(R=>({...R,[i]:y}))}).finally(()=>{u()&&(tt.current=new Map(tt.current),tt.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i))})},[r,Xr,at,o]),ws=n.useCallback(async()=>{o&&(ze.current=new Set,Ae.current=new Set,tt.current=new Map,$t({}),zs(t=>Object.keys(t).length===0?t:{}),await Oe(o))},[Oe,o]),Qe=n.useCallback(async t=>{if(!t){await ws();return}const i=H(t);ze.current=new Set(ze.current),ze.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i),await Oe(i)},[Oe,ws]),Jr=n.useRef(""),Yr=n.useRef("");n.useEffect(()=>{if(!o)return;const t=`${o}|h${k?"1":"0"}|g${j?"1":"0"}`,i=Jr.current!==o,l=Yr.current!==t;!i&&!l||(i&&(Jr.current=o,pe(""),ge(null),Ie(""),oe(null),P(!1)),l&&(Yr.current=t,ze.current=new Set,Ae.current=new Set,tt.current=new Map,$t({}),zs(u=>Object.keys(u).length===0?u:{}),Oe(o)))},[Oe,o,j,k]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&he.length>0)for(const i of he)Qe(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[he,r.listDirectory,Qe]),n.useEffect(()=>{if(!r.listDirectory||he.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of he)Qe(i)},8e3);return()=>clearInterval(t)},[he,r.listDirectory,Qe]);const Oi=n.useCallback(async t=>{if(t?.preventDefault(),!bt||!wt)return;Bs(!0);const i=()=>{Os(null)},l=p=>{Y.error(p)},u=()=>{Bs(!1)};if(wt==="createFile"){if(!ct.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!r.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const p=bt.path,m=p?`${p}/`:"",y=H(`${m}${ct.trim()}`);await r.writeFile(y,"").then(async R=>{R.success&&(Y.success(e("sidebarFilesTree.toast.fileCreated")),await Qe(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="createFolder"){if(!ct.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const p=bt.path,m=p?`${p}/`:"",y=H(`${m}${ct.trim()}`);await r.createDirectory(y).then(async R=>{R.success&&(Y.success(e("sidebarFilesTree.toast.folderCreated")),await Qe(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="rename"){if(!ct.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!r.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/"),y=m?`${m}/`:"",R=H(`${y}${ct.trim()}`);await r.rename(p,R).then(async K=>{K.success&&(Y.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Qe(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Ie(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="delete"){if(!r.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/");await r.delete(p).then(async y=>{y.success&&(Y.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Qe(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Ie(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[wt,bt,ct,r,Qe,f,X,o,c?.path,me,e]);n.useEffect(()=>{if(!T){as([]),os(!1);return}const t=S.trim();if(!t){as([]),os(!1);return}let i=!1;return os(!0),W(T,t,150,{includeHidden:k,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const p=l.filter(m=>j||!Io(m.path)).map(m=>({name:m.name,path:H(m.path),type:"file",extension:m.extension,relativePath:m.relativePath}));as(p)}).catch(()=>{i||as([])}).finally(()=>{i||os(!1)}),()=>{i=!0}},[T,S,W,k,j]);const Qr=n.useCallback(async t=>{const i=await Ge(t);if(r.readFile)return(await r.readFile(t,{...i,directory:o||void 0})).content??"";const l=new URLSearchParams({path:t});i.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),i.outsideFileGrant&&l.set("outsideFileGrant",i.outsideFileGrant),o&&l.set("directory",o);const u=await Rn(`/api/fs/read?${l.toString()}`);if(!u.ok){const p=await u.json().catch(()=>({error:u.statusText}));throw new Error(p.error||e("filesView.error.readFileFailed"))}return u.text()},[r,Ge,o,e]),dt=n.useCallback(async t=>{if(r.statFile){const i=await Ge(t),l=await r.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[r,Ge,o]);n.useEffect(()=>{if(!o||!r.statFile||Z.length===0)return;let t=!1;const i=[...Z];return Promise.all(i.map(async l=>{try{const u=await Ge(l),p=await r.statFile?.(l,{...u,directory:o||void 0});!t&&p&&!p.isFile&&X(o,l)}catch(u){!t&&Xn(u)&&X(o,l)}})),()=>{t=!0}},[r,Z,X,Ge,o]);const Hs=n.useMemo(()=>D.length>It?`${D.slice(0,It)}
14
-
15
- … truncated …`:D,[D]),Me=ne!==Hs,Et=n.useCallback(async()=>{if(!c||!r.writeFile)return Y.error(e("filesView.toast.savingNotSupported")),!1;const t=Cs(c.path)||Kt;if(!Ro({selectedFilePath:c.path,loadedFilePath:De,fileLoading:Le,isDirty:Me,draftContent:ne,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ne===""&&D!==""&&De!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${D.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!Me)return!0;As(!0);try{const i=Wo(ne,Nr);if(!(await r.writeFile(c.path,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;if(pe(ne),o&&Es(c.path,o)){const u=Ts(o,c.path);u&&Va.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(H(c.path))){const u=Ea.getState().projects.find(p=>H(p.path)===H(o));if(u)try{await so(u.id)}catch{Y.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&or(c.path)&&(lt.current=ne,_t.current=ne),dt(c.path).then(u=>{u&&(Je.current=u)}).catch(()=>{}),!0}catch(i){return Y.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{As(!1)}},[Kt,ne,D,Le,r,Me,Nr,De,dt,o,c,e]);n.useEffect(()=>{je||(St("idle"),Xe.current&&(clearTimeout(Xe.current),Xe.current=null))},[je]);const Zr=1500;n.useEffect(()=>{const t=!!(c&&r.writeFile),i=!!(c?.path&&(Cs(c.path)||Kt));if(ko({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:Wt,fileLoading:Le,selectedFilePath:c?.path,loadedFilePath:De,isNonEditableBinary:i}))return Xe.current=setTimeout(()=>{Et().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},Zr),()=>{Xe.current&&(clearTimeout(Xe.current),Xe.current=null)}},[je,Kt,ne,Le,Me,De,c,r.writeFile,Wt,Et]),n.useEffect(()=>{St("idle")},[c?.path]),Da({save_file:t=>{if(!(t.target instanceof Node)||!ds.current?.contains(t.target))return!1;Xe.current&&(clearTimeout(Xe.current),Xe.current=null),Wt||Et().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(Ze&&$e()==="preview"){if(f||!(_?Ws.current:ms.current)?.contains(t.target))return!1;fs(!0),Dr(l=>l+1);return}if(!ds.current?.contains(t.target))return!1;le(!0)}});const en=n.useCallback(async t=>{const i=Ut.current+1;Ut.current=i;const l=()=>{if(!o)return!1;const R=He.getState().byRoot[o],K=R?.selectedPath??R?.openPaths[0]??null;return Ut.current===i&&K===t.path};if(ge(null),Ie(""),oe(null),Sr(!1),ot(!0),await Ge(t.path),!l())return;const u=Mn(t.path),p=zn(t.path),m=An(t.path),y=Cs(t.path);if(f&&P(!0),d.isDesktop&&u&&!p){pe(""),xe("");return}if(!d.isDesktop&&u&&!p){pe(""),xe(""),oe(t.path),ot(!1);return}if(m){pe(""),xe(""),oe(t.path),ot(!1);return}if(y){pe(""),xe(""),oe(t.path),ot(!1);return}await Qr(t.path).then(R=>{if(!l())return;if(Pa(R)){Sr(!0),pe(""),xe(""),oe(t.path);return}const K=oi(R);hi($o(R)),pe(K),lt.current=K,_t.current=K,xe(K.length>It?`${K.slice(0,It)}
16
-
17
- … truncated …`:K),oe(t.path),dt(t.path).then(mt=>{mt&&l()&&(Je.current=mt)}).catch(()=>{})}).catch(R=>{if(l()){if(Oo(R)){if(ot(!1),o&&me(o,null),ge(null),pe(""),xe(""),oe(null),Je.current=null,E.trim().length>0&&V(""),f&&P(!1),o){const mt=[...qn(t.path,o),t.path];mt.length>0&&rs(o,mt);for(const pt of mt)ze.current.has(pt)||Oe(pt)}return}if(Xn(R)){o&&X(o,t.path),pe(""),xe(""),ge(null),Je.current=null,f&&P(!1);return}pe(""),xe(""),ge(R instanceof Error?R.message:e("filesView.error.readFileFailed")),Je.current=null}}).finally(()=>{l()&&ot(!1)})},[rs,f,Oe,Qr,dt,X,Ge,o,d.isDesktop,E,me,e]),bs=n.useCallback(async(t,i)=>{if(!o)return;const l=qn(t,o),u=i?[...l,t]:l;u.length>0&&rs(o,u);const p=u.map(m=>{if(!ze.current.has(m))return Oe(m)}).filter(Boolean);await Promise.all(p)},[rs,Oe,o]),tn=n.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Re=n.useCallback(async t=>{if(Gt.current)Gt.current=!1;else if(Me){Ht(!0),kt.current=t;return}o&&(me(o,t.path),bs(t.path,!1)),ge(null),Ie(""),pe(""),lt.current="",_t.current="",xe(""),oe(null),f&&P(!0)},[bs,Me,f,o,me]);n.useEffect(()=>{c?.path&&bs(c.path,!1)},[bs,c?.path]),n.useEffect(()=>{if(!c){Ut.current+=1,Ct.current=null,ot(!1);return}if(De===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,en(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[cs,en,De,c]);const qs=n.useRef(Me);qs.current=Me,n.useEffect(()=>ro(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==va()||!l||qs.current||!i.includes(H(l))||(Ut.current+=1,Ct.current=null,Je.current=null,Ie(""),ge(null),oe(null),xi(u=>u+1))}),[c?.path]),n.useEffect(()=>{if(!c?.path||De!==c.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||dt(c.path).then(l=>{if(t||!l)return;const u=Je.current;if(!u||u.path!==c.path){Je.current=l;return}const p=l.mtimeMs!==void 0&&u.mtimeMs!==void 0&&l.mtimeMs!==u.mtimeMs,m=l.size!==u.size;!p&&!m||qs.current||(Je.current=l,oe(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[De,dt,c?.path]);const Bi=n.useCallback(()=>{const t=kt.current,i=qt.current;if(kt.current=null,qt.current=null,Gt.current=!0,Ht(!1),xe(Hs),i){o&&et(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),pe(""),ge(null),Ie(""),oe(null),f&&P(!1)));return}if(t){Re(t);return}},[Hs,Re,f,et,o,c?.path,me]),$i=n.useCallback(async()=>{const t=kt.current,i=qt.current;if(!await Et()){Gt.current=!1;return}if(kt.current=null,qt.current=null,Gt.current=!0,Ht(!1),i){o&&et(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),pe(""),ge(null),Ie(""),oe(null),f&&P(!1)));return}if(t){await Re(t);return}},[Re,f,et,o,Et,c?.path,me]),sn=n.useCallback(t=>{const i=c?.path===t,l=tn(t,Nt);if(i&&Me){Ht(!0),kt.current=l,qt.current=t;return}if(o&&et(o,t),!!i){if(l){Re(l);return}o&&me(o,null),pe(""),ge(null),Ie(""),oe(null),f&&P(!1)}},[tn,Re,Me,f,Nt,et,o,c?.path,me]),Wi=n.useCallback(t=>{if(Z.includes(t))return"open";if(A?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=A.files.find(u=>u.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[Z,A,o]),_i=n.useCallback(t=>{if(!A?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,p=0;for(const m of A.files)m.path.startsWith(l)&&((m.index==="M"||m.working_dir==="M")&&u++,(m.index==="A"||m.working_dir==="?")&&p++);return u+p>0?{modified:u,added:p}:null},[A,o]),Ui=n.useCallback(async t=>{const i=H(t);o&&(gr(o,i),ze.current.has(i)||await Oe(i))},[Oe,o,gr]),Ki=n.useMemo(()=>({canRename:zr,canCreateFile:Pr,canCreateFolder:Mr,canDelete:Ar,canReveal:Lr}),[zr,Pr,Mr,Ar,Lr]);function rn(t,i){const l=yr[t]??[];return l.map((u,p)=>{const m=u.type==="directory",y=m&&he.includes(u.path),R=c?.path===u.path,K=p===l.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),K&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(Uo,{node:u,root:o,isExpanded:y,isActive:R,isMobile:f,isBrowserClient:F,alwaysShowActions:N,status:m?void 0:Wi(u.path),badge:m?_i(u.path):void 0,permissions:Ki,downloadFile:r.downloadFile,contextMenuPath:Ni,setContextMenuPath:Ci,rightClickMenuPath:Si,setRightClickMenuPath:ki,onSelect:Re,onToggle:Ui,onRevealPath:Mi,onOpenDialog:_s}),m&&y&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[is[u.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:is[u.path],children:is[u.path]}),s.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Qe(u.path)},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,rn(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&Mn(c.path)),ys=!!(c?.path&&zn(c.path)),Be=!!(c?.path&&An(c.path)),Gs=!!(c?.path&&(Cs(c.path)||Kt)),nt=Gs&&!Fe&&!Be,nn=n.useMemo(()=>H(Ye?.path??""),[Ye?.path]),Dt=!!(Ye&&nn&&qe&&qe===nn&&!Le&&!st&&!Fe&&!Be&&!nt),ft=n.useMemo(()=>Ts(o,qe),[qe,o]),Hi=!!(c&&(!Fe||ys)&&!Be&&!nt&&D.length>0),qi=!!(c&&ft.length>0),Ue=!!(c&&!ns&&!Gs&&!Fe&&r.writeFile&&D.length<=It),Ze=!!(c?.path&&Jn(c.path)),Zt=!!(c?.path&&_o(c.path)),Pt=!!(c?.path&&fr(c.path)),es=!!(c?.path&&or(c.path)),Xs=!!(c&&!Gs&&!Fe)&&!Ze&&!es&&!(Pt&&B==="preview"),Gi=Ze&&we==="edit"||Pt&&B==="edit"||Zt&&ue==="text"||!Ze&&!Pt&&!Zt&&O==="edit",js=n.useMemo(()=>qe?Ma(qe):null,[qe]),[an,Js]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||js){Js(null);return}return Js(null),za(i).then(l=>{t||Js(l)}),()=>{t=!0}},[c?.path,js]),n.useEffect(()=>{!Ue&&O==="edit"&&ve("view")},[Ue,O]);const Ys="openchamber:files:md-viewer-mode",Qs="openchamber:files:html-viewer-mode",Zs="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;ve(ae.current[t]??"edit");let i=Yt?"preview":"edit";try{const p=localStorage.getItem(Ys);(p==="preview"||p==="edit")&&(i=p)}catch{}ce(ye.current[t]??i);let l=Yt?"preview":"edit";try{const p=localStorage.getItem(Qs);(p==="preview"||p==="edit")&&(l=p)}catch{}q(Te.current[t]??l),re(de.current[t]??(Yt?"preview":"edit"));let u=Yt?"tree":"text";try{const p=localStorage.getItem(Zs);(p==="tree"||p==="text")&&(u=p)}catch{}be(u)},[c?.path,Yt]);const Xi=n.useCallback(t=>{const i=c?.path;i&&(ae.current[i]=t),ve(t)},[c?.path]),Ji=n.useCallback(t=>{const i=c?.path;i&&(ye.current[i]=t),ce(t);try{localStorage.setItem(Ys,t)}catch{}},[c?.path]),$e=n.useCallback(()=>we,[we]),on=c&&Ze&&$e()==="preview"&&!Le?c.path:null;n.useEffect(()=>{!on||f||ps()},[ps,_,f,on]);const Yi=n.useCallback(t=>{be(t);try{localStorage.setItem(Zs,t)}catch{}},[]),Qi=n.useCallback(t=>{const i=c?.path;i&&(Te.current[i]=t),q(t);try{localStorage.setItem(Qs,t)}catch{}},[c?.path]),Zi=n.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Pe.current&&(clearTimeout(Pe.current),Pe.current=null),rt.current!==null&&(cancelAnimationFrame(rt.current),rt.current=null),t==="edit")xe(lt.current||D),re(t);else{lt.current=ne;const l=i;re("edit"),rt.current=requestAnimationFrame(()=>{rt.current=requestAnimationFrame(()=>{rt.current=null,!(o&&l&&He.getState().byRoot[o]?.selectedPath!==l)&&(ie(u=>u+1),re("preview"))})});return}},[ne,D,o,c?.path]),er=n.useCallback(async(t,i)=>{if(!r.writeFile||i===_t.current)return!1;if(!(await r.writeFile(t,i))?.success)return Y.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,_t.current=i,xe(i);const u=await dt(t).catch(()=>null);return u&&(Je.current=u),!0},[r,dt,e]);n.useEffect(()=>()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null),rt.current!==null&&(cancelAnimationFrame(rt.current),rt.current=null)},[se,c?.path]);const ea=n.useCallback(t=>{if(lt.current=t,!je||!c?.path||se!=="preview"||!r.writeFile)return;Pe.current&&clearTimeout(Pe.current);const i=c.path;Pe.current=setTimeout(()=>{Pe.current=null,er(i,t).then(l=>{l&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(l=>{Y.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},Zr)},[je,se,r.writeFile,er,c?.path,e]),ta=n.useMemo(()=>es&&(lt.current||ne)||D,[ne,D,es]),ln=n.useCallback(()=>B,[B]);n.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",p=l?"tree":"text";for(const m of Z)ae.current[m]="edit",Jn(m)&&(ye.current[m]=u),fr(m)&&(Te.current[m]=u),or(m)&&(de.current[m]=u);ve("edit"),ce(u),q(u),re(u),be(p);try{localStorage.setItem(Ys,u),localStorage.setItem(Qs,u),localStorage.setItem(Zs,p)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[Z]),n.useEffect(()=>{if(!Ye||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,Is(it=>it+1)}))},i=(it,yt)=>{if(it.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const nr=Math.min(128,yt.length);if(it.state.sliceDoc(0,nr)!==yt.slice(0,nr))return!1;const Cn=Math.max(0,yt.length-nr);return it.state.sliceDoc(Cn,yt.length)===yt.slice(Cn)},l=H(Ye.path);if(!l){hs(null),vt.current={key:"",attempts:0};return}const u=`${l}:${Ye.line}:${Ye.column??1}`;if(vt.current.key!==u&&(vt.current={key:u,attempts:0}),c?.path!==l){if(Ls)return;Re(Ft(l));return}if(Le||De!==l)return;if(st||Fe||Be||nt){hs(null),vt.current={key:"",attempts:0};return}if(!Ue)return;if(O!=="edit"){ve("edit");return}const p=We.current;if(!p){t();return}if(!i(p,ne)){t();return}const m=Math.max(1,Math.min(Ye.line,p.state.doc.lines)),y=p.state.doc.line(m),R=Math.max(1,Ye.column||1),K=Math.max(0,y.to-y.from),mt=Math.min(K,R-1),pt=y.from+mt;if(!(p.state.selection.main.head===pt)||vt.current.attempts===0){vt.current.attempts+=1,p.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),p.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=We.current;it&&(it.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),it.focus())}),hs(null),vt.current={key:"",attempts:0}},[Ue,Ls,ne,yi,st,Le,Fe,Be,nt,De,Re,Ye,o,c?.path,hs,O,Ft]),n.useEffect(()=>{if(!Us||!o)return;const t=H(Us);if(!t){Ks(null);return}c?.path===t&&(Le||De!==t||(!st&&!Fe&&!Be&&!nt&&Ue&&O==="edit"&&We.current?.focus(),Ks(null)))},[Ue,st,Le,Fe,Be,nt,De,Us,o,c?.path,Ks,O]);const Mt=n.useCallback(t=>{if(!f||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const p=t.state.selection.main.head,m=t.coordsAtPos(p);if(!m)return;const y=Math.round(i.offsetTop+i.height),K=m.bottom+20-y;K<=0||(t.scrollDOM.scrollTop+=K)},[f]);n.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{Mt(We.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[f,Mt]),Aa("open_go_to_line",t=>{if(!Ue||O!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!ds.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;$s(!0)});const Fs=ht(t=>t.editorFontSize),cn=n.useMemo(()=>{if(!c?.path)return[In(v,{fontSize:Fs})];const t=ar(c.path),i=[In(v,t?{syntaxColors:!1,fontSize:Fs}:{fontSize:Fs})],l=js??an;return l&&i.push(l),t&&i.push(Ga({language:t,themeName:v.metadata.id,theme:Qa(v)})),J&&i.push(jt.lineWrapping),f&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{Mt(u.view)})})),i},[v,c?.path,js,an,J,f,Mt,Fs]),un=n.useMemo(()=>({light:Ve.metadata.id,dark:Ee.metadata.id}),[Ve.metadata.id,Ee.metadata.id]),ts=c?.path&&Be&&(!xt.allowOutsideWorkspace||xt.outsideFileGrant)?`${c.path}|${xt.allowOutsideWorkspace?"outside":"workspace"}|${xt.outsideFileGrant??""}|${cs}`:"",Ns=c?.path&&Pt&&B==="preview"&&!d.isVSCode?`${c.path}|${cs}`:"",dn=e("filesView.error.readFileFailed"),{readyKey:fn,nonce:sa}=Yn(Ns,ge,dn),{readyKey:mn,nonce:pn}=Yn(ts,ge,dn),ra=!!(Ns&&fn!==Ns),hn=!!(ts&&mn!==ts),gn=c?.path&&Fe?ys?`data:${La(c.path)};utf8,${encodeURIComponent(D)}`:pi:"",xn=c?.path&&Be&&ts&&mn===ts?Tn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:xt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:xt.outsideFileGrant,directory:o||void 0}):"",vn=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:xn,className:"h-full w-full border-0",title:t.name},pn)}),[xn,pn]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||ys){Ie("");return}ge(null);const u=await Ge(c.path);if(t)return;await(r.readFileBinary?r.readFileBinary(c.path,u).then(m=>m.dataUrl):(async()=>{const m=await Rn("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!m.ok)throw new Error(e("filesView.error.readFileFailed"));const y=await m.blob();return i=URL.createObjectURL(y),t?(URL.revokeObjectURL(i),i="",""):i})()).then(m=>{t||(Ie(m),oe(c.path))}).catch(m=>{t||(Ie(""),ge(m instanceof Error?m.message:e("filesView.error.readFileFailed")),oe(null))}).finally(()=>{t||ot(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[cs,r,Fe,ys,Ge,o,c?.path,xt,e]);const na=n.useCallback(()=>Os(null),[]),ia=n.useMemo(()=>lo({drafts:$r,editingDraftId:vs,commentText:xs,onTextChange:Wr,selection:U,isDragging:Or,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Gr,onCancel:()=>{_e(null),Qt()},onEdit:t=>{Hr(t),_e({start:t.startLine,end:t.endLine})},onDelete:qr}),[Qt,xs,qr,vs,$r,Gr,Or,U,c?.path,Wr,Hr]),wn=Kn(),bn=Kn(),tr=Wa("unified"),Ke=D.length>It,sr=n.useMemo(()=>Ke?Bo(D):void 0,[D,Ke]),yn=n.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:ar(t.path)||void 0},p=m=>s.jsx(Ya,{file:Ke&&sr?{...u,cacheKey:`${t.path}:${sr}`}:u,options:{disableFileHeader:!0,overflow:J?"wrap":"scroll",theme:un,themeType:v.metadata.variant==="dark"?"dark":"light"},className:Ke?"block w-full":"block h-full w-full",style:Ke?void 0:{height:"100%"}},m);return Ke?s.jsx("div",{className:"h-full",children:s.jsx(Za.Provider,{value:l.virtualizer,children:s.jsx(eo.Provider,{value:tr,children:p(`${t.path}:${tr?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:p(t.path)})},[v.metadata.variant,Ke,sr,un,tr,J]),jn=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=Ia(Oa("save_file")),p=l?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",m=(y,R)=>s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:R})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:y})]});return s.jsxs("div",{className:p,children:[Ue&&Gi&&s.jsxs(s.Fragment,{children:[Wt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(b,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&vi==="saved"&&!Me?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(b,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?m(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Et()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:s.jsx(b,{name:"save-3",className:"size-4"})})):null,m(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>bi(!je),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",je?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:je?s.jsx(b,{name:"file-check-fill",className:"size-4"}):s.jsx(b,{name:"file-check",className:"size-4"})}))]}),s.jsxs(mr,{onOpenChange:Ce,children:[s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(pr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(b,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(hr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ei.map(y=>s.jsxs(Rs,{className:"flex items-center gap-2",onClick:()=>{zi(y)},children:[s.jsx(Do,{label:y.label,iconDataUrl:y.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:y.label})]},y.id)),Di?s.jsxs(Rs,{className:"flex items-center gap-2",onClick:()=>{Pi(!0)},children:[s.jsx(b,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Be&&!nt&&s.jsxs(s.Fragment,{children:[m(e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!J),className:G("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",J?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(b,{name:"text-wrap",className:"size-4"})})),O==="edit"&&s.jsxs(s.Fragment,{children:[m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{le(!ee),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),m(e("filesView.editor.goToLine"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{$s(R=>!R),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(b,{name:"menu-fold-2",className:"size-4"})})),s.jsx(wo,{open:Vi,onOpenChange:$s,view:We.current,variant:"inline"})]})]}),Xs&&Ue&&!Zt&&!Pt&&s.jsx(ur,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Xi(O==="view"?"edit":"view")}}),Ze&&m(e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ji($e()==="preview"?"edit":"preview"),className:G("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",$e()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(b,{name:$e()==="preview"?"eye":"eye-off",className:"size-4"})})),fr(c?.path??"")&&s.jsx(ur,{currentMode:ln(),onToggle:()=>{Qi(ln()==="preview"?"edit":"preview")}}),Ze&&$e()==="preview"&&m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{fs(!0),Dr(y=>y+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),Ze&&$e()==="preview"&&Ai&&s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{ls?mi():D.trim()&&fi(D)},children:ls?s.jsx(b,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"volume-up",className:"size-4"})})}),s.jsx(Lt,{sideOffset:8,children:e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),es&&s.jsxs(s.Fragment,{children:[s.jsx(ur,{currentMode:se,onToggle:()=>Zi(se==="preview"?"edit":"preview")}),se==="preview"&&s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const y=Cr.current?.getXml();if(Pe.current&&(clearTimeout(Pe.current),Pe.current=null),c?.path&&y){if(!await er(c.path,y))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:wi?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"save-3",className:"size-4"})})]}),Zt&&m(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Yi(ue==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?s.jsx(b,{name:"code-sslash",className:"size-4"}):s.jsx(b,{name:"node-tree",className:"size-4"})})),Hi&&m(e("filesView.editor.copyFileContents"),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Vs(D)).ok?(Rr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Rr(!1)},1200)):Y.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Ri?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"clipboard",className:"size-4"})})),qi&&m(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Vs(ft)).ok?(Tr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Tr(!1)},1200)):Y.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:Ti?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&m(e("filesView.editor.saveFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const y=r.downloadFile;y&&y(c.path).catch(R=>{console.error("Download failed:",R),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(b,{name:"download",className:"size-4"})})),t?m(e("filesView.editor.exitFullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Q(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(b,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&m(e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Q(!_),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(_?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:_?s.jsx(b,{name:"fullscreen-exit",className:"size-4"}):s.jsx(b,{name:"fullscreen",className:"size-4"})}))]})},rr=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Zn,{open:Ls,onOpenChange:t=>{t||Ht(!0)},children:s.jsxs(ei,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(ti,{children:[s.jsx(si,{children:e("filesView.unsaved.title")}),s.jsx(ri,{children:e("filesView.unsaved.description")})]}),s.jsxs(ni,{children:[s.jsx(z,{variant:"outline",onClick:()=>{$i()},disabled:Wt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(z,{variant:"destructive",onClick:Bi,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:G("flex flex-col flex-shrink-0",L&&"border-b border-border/40"),children:[L?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&$&&s.jsx("button",{type:"button",onClick:()=>P(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(b,{name:"arrow-left-s",className:"size-5"})}),f?c?s.jsxs(mr,{children:[s.jsx(pr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(ks,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Gn,{name:c.name}),s.jsx(b,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(hr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs(Rs,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:G("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(ks,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Gn,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),sn(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Nt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[vr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),vr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Ms,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs("div",{title:Ts(o,t.path),className:G("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(ks,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||Re(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),sn(t.path)},className:G("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!f?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:jn({layout:"docked"})})]}):null]}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(lr,{ref:wn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:c?Le||hn?I?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):st?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:st}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:gn,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Be?vn(c):nt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&es&&se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(Vo,{ref:Cr,xml:ta,onChange:ea},`${c.path}:${Se}`)}):c&&Zt&&ue==="tree"?s.jsx(cr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ja,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&Ze&&$e()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:ps,ref:t=>{gs.current=t,ms.current=t},children:[s.jsx($n,{containerRef:gs,filePath:c.path,fileContent:D}),D.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(cr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ln,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!_&&s.jsx(Un,{containerRef:ms,open:Vr,onOpenChange:fs,focusNonce:Er})]}):c&&Pt&&B==="preview"?ra?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!d.isVSCode&&fn===Ns?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return Tn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},sa)}):c&&Xs&&O==="view"?yn(c,Ke?D:ne,wn):s.jsxs("div",{className:G("relative h-full",Dt&&"overflow-hidden"),ref:ds,children:[s.jsx("div",{className:G("h-full",Dt&&"invisible"),children:s.jsx(On,{value:ne,onChange:xe,readOnly:!Ue,vimMode:Br==="vim",extensions:cn,className:"h-full",blockWidgets:ia,onViewReady:t=>{We.current=t,Is(i=>i+1),window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{We.current&&(We.current=null),Is(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:U?{start:Math.min(U.start,U.end),end:Math.max(U.start,U.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(U&&!l.shiftKey&&Math.min(U.start,U.end)===u&&Math.max(U.start,U.end)===u)return _e(null),Qt(),Tt.current=!1,ut.current=null,Vt(!1),!0;if(f&&U&&!l.shiftKey){const p=Math.min(U.start,U.end,u),m=Math.max(U.start,U.end,u);return _e({start:p,end:m}),Tt.current=!1,ut.current=null,Vt(!1),!0}if(Tt.current=!0,ut.current=u,Vt(!0),U&&l.shiftKey){const p=Math.min(U.start,u),m=Math.max(U.end,u);_e({start:p,end:m})}else _e({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Tt.current||ut.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,p=Math.min(ut.current,u),m=Math.max(ut.current,u);return _e({start:p,end:m}),Vt(!0),!1},mouseup:()=>(Tt.current=!1,ut.current=null,Vt(!1),!1)}}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),aa=!!(o&&yr[o]),Fn=o?is[o]:null,Nn=s.jsxs("section",{className:G("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:G("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(b,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ss,{ref:M,value:E,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),M.current?.focus()},children:s.jsx(b,{name:"close",className:"size-4"})})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>_s("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(b,{name:"file-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>_s("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(b,{name:"folder-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{ws()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(b,{name:"refresh",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(lr,{outerClassName:"flex-1 min-h-0",className:G("py-2",f?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:di?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Fr.length>0?Fr.map(t=>{const i=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:G("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[li(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):Fn?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:Fn}),s.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ws()},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):aa?rn(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),oa=a==="full"&&_&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:jn({exitFullscreenOnly:!0})}),s.jsx(lr,{ref:bn.setScroller,outerClassName:"h-full min-w-0",className:G("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:Le||hn?I?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):st?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:st}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:gn,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Be?vn(c):nt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Y.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):Ze&&$e()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:ps,ref:t=>{gs.current=t,Ws.current=t},children:[c?s.jsx($n,{containerRef:gs,filePath:c.path,fileContent:D}):null,D.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(cr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ln,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),s.jsx(Un,{containerRef:Ws,open:Vr,onOpenChange:fs,focusNonce:Er,className:"right-4 top-16"})]}):Xs&&O==="view"?yn(c,Ke?D:ne,bn):s.jsxs("div",{className:G("relative h-full",Dt&&"overflow-hidden"),children:[s.jsx("div",{className:G("h-full",Dt&&"invisible"),children:s.jsx(On,{value:ne,onChange:xe,readOnly:!Ue,vimMode:Br==="vim",extensions:cn,className:"h-full",onViewReady:t=>{We.current=t,window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{We.current&&(We.current=null)}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Ko,{activeDialog:wt,dialogData:bt,dialogInputValue:ct,onDialogInputChange:kr,isDialogSubmitting:Fi,onDialogSubmit:Oi,onClose:na,inputRef:gi}),oa,f?$?rr:Nn:a==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:rr})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[h>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Nn}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:rr})]})]})};function Ho(a){return a+1}export{mu as FilesView};
@@ -1 +0,0 @@
1
- import{f as B,R as h,j as P}from"./vendor-react-BUCujlKS.js";import{toast as H}from"./vendor-sonner-DFyL3AvE.js";import{fC as K,fz as J,ac as Z,f as Q,I as W}from"./useAppFontEffects-CCgvcQ6u.js";import{r as G,_ as Y,F as ee,e as te,di as re,dj as oe,a1 as ae}from"./index-DDInLQDd.js";import{extractMarkdownImageCandidates as se,MAX_MARKDOWN_IMAGE_COUNT as ne}from"./markdownCore-BoQVG5-a.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CV-DwAiX.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BxpoC5Fp.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-DVWEh-IS.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-marked-linkify-it-CXI_LHIE.js";import"./vendor-linkify-it-DZCzzDkK.js";import"./vendor-uc.micro-BAd0H0z4.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const L=10*1024*1024,ie=1024,le=3e4,ce=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,$=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},me=r=>{let e=r;if(/^file:\/\//i.test(e))try{const o=new URL(e);if(o.protocol!=="file:")return"";e=o.host&&o.host!=="localhost"?`//${o.host}${o.pathname}`:o.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const t=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(t)}catch{return t}},ue=r=>new Promise((e,t)=>{const o=new FileReader;o.onload=()=>{typeof o.result=="string"?e(o.result):t(new Error("Unable to encode image"))},o.onerror=()=>t(o.error??new Error("Unable to encode image")),o.readAsDataURL(r)}),pe=async(r,e)=>{const t=new Uint8Array(await r.slice(0,12).arrayBuffer()),o=(n,u)=>String.fromCharCode(...t.slice(n,u));switch(e){case"image/png":return t[0]===137&&o(1,4)==="PNG"&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10;case"image/jpeg":return t[0]===255&&t[1]===216&&t[2]===255;case"image/gif":{const n=o(0,6);return n==="GIF87a"||n==="GIF89a"}case"image/webp":return o(0,4)==="RIFF"&&o(8,12)==="WEBP";default:return!1}},V=async(r,e)=>{if(!ce.has(e))throw new Error("Unsupported image type");if(r.size>L)throw new Error("Image is too large");if(!await pe(r,e))throw new Error("Unsupported image data")},fe=async r=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(r);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil(L*4/3)+4)throw new Error("Image is too large");let t;try{t=atob(e[2])}catch{throw new Error("Invalid image data URL")}const o=Uint8Array.from(t,n=>n.charCodeAt(0));await V(new Blob([o]),e[1].toLowerCase())},q=r=>!/^(?:https?:)?\/\//i.test(r)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r),de=async({sources:r,directory:e,sessionId:t,messageId:o,signal:n})=>{const u=Y();let s=z.get(u);s||(s=new Map,z.set(u,s));const c=`${t}\0${o}\0${e}\0${r.join("\0")}`,i=s.get(c);if(i&&i.expiresAt>Date.now())return s.delete(c),s.set(c,i),i.result;i&&s.delete(c);const p=await G(`/api/openchamber/sessions/${encodeURIComponent(t)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:o,sources:r}),signal:n});if(!p.ok)throw new Error(`Unable to prepare images (${p.status})`);const m=await p.json(),l=new Map;for(const a of m.results??[])a.source&&(a.status==="ready"&&a.path?l.set(a.source,{status:"ready",path:a.path,outsideFileGrant:a.outsideFileGrant,expiresAt:a.expiresAt}):a.status==="missing"?l.set(a.source,{status:"missing"}):l.set(a.source,{status:"error"}));for(const a of r)l.has(a)||l.set(a,{status:"error"});for(;s.size>=ie;)s.delete(s.keys().next().value);const w=[...l.values()].every(a=>a.status==="ready"),y=Math.min(...[...l.values()].filter(a=>a.status==="ready").map(a=>a.expiresAt??Number.POSITIVE_INFINITY));return s.set(c,{result:l,expiresAt:w?y:Date.now()+le}),l},ge=async(r,e)=>{if($(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await fe(r),$(e),r;throw new Error("Local image has not been prepared")},he=async(r,e,t)=>{$(t);const o=me(r),n=K(e,o);if(!e||!o||!J(n,e))throw new Error("Image path is outside the active workspace");const u=await G("/api/fs/stat",{query:{path:n,directory:e,optional:"true"},signal:t});if(!u.ok)throw new Error(`Unable to inspect image (${u.status})`);const s=await u.json();if(!s.isFile)throw new Error("Image path is not a file");if(typeof s.size=="number"&&s.size>L)throw new Error("Image is too large");const c=await G("/api/fs/raw",{query:{path:n,directory:e},signal:t});if(!c.ok)throw new Error(`Unable to load image (${c.status})`);const i=(c.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",p=Number(c.headers.get("content-length"));if(Number.isFinite(p)&&p>L)throw new Error("Image is too large");const m=await c.blob();return await V(m,i),$(t),ue(m)},we=(r,e)=>Y().authenticatedAsset("/api/fs/raw",{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),be=r=>{const e=B.c(7),[t,o]=h.useState(!1),[n,u]=h.useState(0);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=te(),e[0]=s):s=e[0];const c=s;let i,p;e[1]!==r?(i=()=>{if(!r){o(!1);return}let w=!1,y;const a=re(c),g=oe(()=>{w||u(Ie)}),I=()=>{ae(c).then(()=>{w||o(!0)}).catch(()=>{w||(y=setTimeout(I,1e3))})};return I(),()=>{w=!0,y&&clearTimeout(y),a(),g()}},p=[c,r],e[1]=r,e[2]=i,e[3]=p):(i=e[2],p=e[3]),h.useEffect(i,p);const m=!r||t;let l;return e[4]!==n||e[5]!==m?(l={ready:m,nonce:n},e[4]=n,e[5]=m,e[6]=l):l=e[6],l},ye=r=>{const e=B.c(46),{candidate:t,preparation:o,directory:n,assetAuthReady:u,assetAuthNonce:s,useWorkspaceFsBridge:c,onShowPopup:i}=r,{t:p}=Q(),m=h.useRef(null),[l,w]=h.useState(!1);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={url:"",status:"loading"},e[0]=y):y=e[0];const[a,g]=h.useState(y);let I;e[1]!==t.source?(I=q(t.source),e[1]=t.source,e[2]=I):I=e[2];const b=I;let x,f;e[3]!==l?(x=()=>{const N=m.current;if(!N||l)return;if(typeof IntersectionObserver>"u"){w(!0);return}const E=new IntersectionObserver(F=>{F.some(Ee)&&(w(!0),E.disconnect())},{rootMargin:"200px"});return E.observe(N),()=>E.disconnect()},f=[l],e[3]=l,e[4]=x,e[5]=f):(x=e[4],f=e[5]),h.useEffect(x,f);let v;e[6]!==u||e[7]!==t.source||e[8]!==n||e[9]!==b||e[10]!==o||e[11]!==l||e[12]!==c?(v=()=>{if(!l||b&&!c&&!o)return;if(b&&c){const E=new AbortController;return g({url:"",status:"loading"}),he(t.source,n,E.signal).then(F=>{E.signal.aborted||g({url:F,status:"loading"})}).catch(()=>{E.signal.aborted||g({url:"",status:"error"})}),()=>E.abort()}if(b){if(o?.status!=="ready"){g({url:"",status:"error"});return}if(!u)return;g({url:we(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),ge(t.source,N.signal).then(E=>{N.signal.aborted||g({url:E,status:"loading"})}).catch(()=>{N.signal.aborted||g({url:"",status:"error"})}),()=>N.abort()},e[6]=u,e[7]=t.source,e[8]=n,e[9]=b,e[10]=o,e[11]=l,e[12]=c,e[13]=v):v=e[13];let _;e[14]!==s||e[15]!==u||e[16]!==t.source||e[17]!==n||e[18]!==b||e[19]!==o||e[20]!==l||e[21]!==c?(_=[s,u,t.source,n,b,o,l,c],e[14]=s,e[15]=u,e[16]=t.source,e[17]=n,e[18]=b,e[19]=o,e[20]=l,e[21]=c,e[22]=_):_=e[22],h.useEffect(v,_);let k;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(k=()=>{if(a.status==="error"){H.error(p("filesView.error.previewUnavailable"));return}a.status!=="ready"||!i||i({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:a.url,filename:t.filename}})},e[23]=t.filename,e[24]=a.status,e[25]=a.url,e[26]=i,e[27]=p,e[28]=k):k=e[28];const U=k,j=a.status==="loading";let A;e[29]!==t.filename||e[30]!==a.status||e[31]!==a.url?(A=P.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:a.url&&a.status!=="error"?P.jsx("img",{src:a.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>g(Ae),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(W,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=A):A=e[32];let R;e[33]===Symbol.for("react.memo_cache_sentinel")?(R=P.jsx(W,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=R):R=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let C;e[36]!==t.filename||e[37]!==S?(C=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[R,S]}),e[36]=t.filename,e[37]=S,e[38]=C):C=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==C||e[43]!==j||e[44]!==A?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:j,onClick:U,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[A,C]}),e[39]=t.filename,e[40]=t.source,e[41]=U,e[42]=C,e[43]=j,e[44]=A,e[45]=M):M=e[45],M},pr=r=>{const e=B.c(34),{sessionId:t,messageId:o,contents:n,onShowPopup:u}=r,s=Z()??"",c=h.useRef(null),[i,p]=h.useState(!1),[m,l]=h.useState(null),[w,y]=h.useState(0);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ee(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=se(n,ne),e[1]=n,e[2]=I):I=e[2];const b=I;let x;e[3]!==b?(x=g?[]:b.filter(xe).map(ve),e[3]=b,e[4]=x):x=e[4];const f=x;let v,_;e[5]!==f.length||e[6]!==i?(v=()=>{if(f.length===0||i)return;const d=c.current;if(!d||typeof IntersectionObserver>"u"){p(!0);return}const T=new IntersectionObserver(X=>{X.some(_e)&&(p(!0),T.disconnect())},{rootMargin:"200px"});return T.observe(d),()=>T.disconnect()},_=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=_):(v=e[7],_=e[8]),h.useEffect(v,_);let k;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(k=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return de({sources:f,directory:s,sessionId:t,messageId:o,signal:d.signal}).then(T=>{d.signal.aborted||l(T)}).catch(()=>{d.signal.aborted||l(new Map(f.map(ke)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=k):k=e[14];let U;e[15]!==s||e[16]!==o||e[17]!==w||e[18]!==f||e[19]!==t||e[20]!==i?(U=[s,o,w,f,t,i],e[15]=s,e[16]=o,e[17]=w,e[18]=f,e[19]=t,e[20]=i,e[21]=U):U=e[21],h.useEffect(k,U);let j,A;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(Re).map(Se));if(!Number.isFinite(d))return;const T=setTimeout(()=>y(Me),Math.max(0,d-Date.now()));return()=>clearTimeout(T)},A=[m],e[22]=m,e[23]=j,e[24]=A):(j=e[23],A=e[24]),h.useEffect(j,A);let R;e[25]!==m?(R=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=R):R=e[26];const S=b.filter(R),C=[...m?.values()??[]].some(Ne),M=be(C);if(S.length===0)return null;const N="mt-3 flex max-w-full gap-2 overflow-x-auto pb-1",E="true";let F;e[27]!==M||e[28]!==s||e[29]!==u||e[30]!==m?(F=d=>P.jsx(ye,{candidate:d,preparation:m?.get(d.source),directory:s,assetAuthReady:M.ready,assetAuthNonce:M.nonce,useWorkspaceFsBridge:g,onShowPopup:u},d.source),e[27]=M,e[28]=s,e[29]=u,e[30]=m,e[31]=F):F=e[31];const D=S.map(F);let O;return e[32]!==D?(O=P.jsx("div",{ref:c,className:N,"data-openchamber-markdown-image-gallery":E,children:D}),e[32]=D,e[33]=O):O=e[33],O};function Ie(r){return r+1}function Ee(r){return r.isIntersecting}function Ae(r){return{...r,status:"ready"}}function xe(r){return q(r.source)}function ve(r){return r.source}function _e(r){return r.isIntersecting}function ke(r){return[r,{status:"error"}]}function Re(r){return r.status==="ready"}function Se(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Me(r){return r+1}function Ne(r){return r.status==="ready"}export{pr as MarkdownImageGallery};
@@ -1,12 +0,0 @@
1
- import{R as E,f as ie,j as ee}from"./vendor-react-BUCujlKS.js";import{m as zt}from"./vendor-morphdom-B7dS_VPB.js";import{r as Bt,a as $t}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{fr as it,fs as Ht,ft as Vt,fu as Kt,g as be,ba as jt,bd as Ut,fv as Zt,fw as Xt,W as st,ac as at,fx as lt,f as ct,h as dt,e8 as Gt,e9 as De,fy as Yt,fz as Oe,fA as Jt,fB as Qt,fC as en,fD as tn,fE as nn,o as rn}from"./useAppFontEffects-CCgvcQ6u.js";import{r as on,F as ut,I as te,ct as sn,u as X,a as an,z as ln,A as cn}from"./index-DDInLQDd.js";import{h as dn}from"./contextPanelEmbeddedChat-CV-DwAiX.js";import{getCachedMarkdownBlocks as We,renderMarkdownSync as un,renderMarkdownBlocks as mn}from"./markdownCore-BoQVG5-a.js";import{r as pn}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BxpoC5Fp.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-DVWEh-IS.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-marked-linkify-it-CXI_LHIE.js";import"./vendor-linkify-it-DZCzzDkK.js";import"./vendor-uc.micro-BAd0H0z4.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const mt=t=>{const e=t.target;if(!(e instanceof Element))return null;const n=e.closest("a[href]");return!(n instanceof HTMLAnchorElement)||n.getAttribute("data-openchamber-file-link")==="true"?null:n},Le=(t,e)=>{if(t.defaultPrevented)return!1;const r=mt(t)?.getAttribute("href")??"";return Ht(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},fn=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,hn=(t,e)=>{const n=o=>{if(Le(o,e.openAppLink)||!e.allowExternalHttp||o.defaultPrevented||!fn(o))return;const s=mt(o)?.getAttribute("href")??"";it(s)&&(o.preventDefault(),o.stopPropagation(),e.openExternalHttp(s))},r=o=>{o.button===1&&Le(o,e.openAppLink)},i=o=>{Le(o)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",i),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",i)}},pt="openchamber-md",gn={name:pt,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let qe=!1;const bn=()=>{qe||(qe=!0,pn(pt,()=>Promise.resolve(gn)))},R=t=>Number.isFinite(t)&&t>0,ze=t=>{if(t==null)return null;const e=String(t).trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const n=Number(e[1]);return R(n)?n:null},Me=(t,e,n)=>Math.min(n,Math.max(e,t)),wn=6,Be=1.25,yn=1.0015,An=.5,vn=12,$e=3,kn=400,ne='[data-markdown="mermaid-block"]',I=t=>t.querySelector(ne)!==null,En=t=>[t.x,t.y,t.width,t.height].map(e=>{const n=Number(e.toFixed(wn));return Object.is(n,-0)?"0":String(n)}).join(" "),Cn=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(i=>Number.parseFloat(i));if(e?.length===4){const[i,o,s,a]=e;if(Number.isFinite(i)&&Number.isFinite(o)&&R(s)&&R(a))return{x:i,y:o,width:s,height:a}}const n=ze(t.width),r=ze(t.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},Sn=t=>{let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Ln=t=>{const e=t.renderMode||"unknown",n=t.svgMarkup??"";if(!n){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(i=>i!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,Sn(n)].join(":")},ft=(t,e)=>{if(!R(e.width)||!R(e.height))return t;const n=t.width/t.height,r=e.width/e.height;if(n>r){const o=t.width/r;return{x:t.x,y:t.y-(o-t.height)/2,width:t.width,height:o}}const i=t.height*r;return{x:t.x-(i-t.width)/2,y:t.y,width:i,height:t.height}},Mn=({currentBox:t,viewport:e,delta:n})=>!R(e.width)||!R(e.height)||!R(t.width)||!R(t.height)?t:{x:t.x-n.x/e.width*t.width,y:t.y-n.y/e.height*t.height,width:t.width,height:t.height},Nn=(t,e)=>{const n=e.x-t.x,r=e.y-t.y;return n*n+r*r>$e*$e},Rn=({currentBox:t,contentBox:e,viewport:n,pointer:r,zoomFactor:i,minScale:o,maxScale:s})=>{if(!R(n.width)||!R(n.height)||!R(i)||!R(t.width)||!R(t.height)||!R(e.width)||!R(e.height)||!R(o)||!R(s))return t;const a=Math.min(o,s),l=Math.max(o,s),c=ft(e,n),u=c.width/t.width,g=Me(u*i,a,l),p=c.width/g,h=p/(t.width/t.height),m=Me(r.x/n.width,0,1),f=Me(r.y/n.height,0,1),A=t.x+m*t.width,v=t.y+f*t.height;return{x:A-m*p,y:v-f*h,width:p,height:h}},we=new WeakMap,xe=new WeakMap,V=new Set,re=new Set;let H=null,Q=null,Y=null;const _n=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),ht=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),n=t.querySelector('[data-markdown="mermaid"]');return Ln({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},Z=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Tn=(t,e)=>{const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},xn=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),gt=t=>{const e=t.map(n=>Z(n.viewport));t.forEach((n,r)=>{const i=e[r];i&&n.fitToViewport(i)})},bt=()=>{Y!==null||V.size===0||(Y=window.requestAnimationFrame(()=>{Y=null,gt(Array.from(V))}))},Pn=()=>{if(H)return H;const t=globalThis.ResizeObserver;return t?(H=new t(e=>{for(const n of e)n.target instanceof HTMLElement&&xe.get(n.target)?.fitToViewport({width:n.contentRect.width,height:n.contentRect.height})}),H):null},In=t=>{if(V.has(t))return;const e=V.size===0;V.add(t),xe.set(t.viewport,t),Pn()?.observe(t.viewport),e&&window.addEventListener("resize",bt)},Fn=t=>{V.delete(t)&&(H?.unobserve(t.viewport),xe.delete(t.viewport),!(V.size>0)&&(H?.disconnect(),H=null,window.removeEventListener("resize",bt),Y!==null&&(window.cancelAnimationFrame(Y),Y=null)))},Dn=t=>{const e=_n(t),n=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!n)return null;const r=Cn({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let i=r,o=null,s=null,a=null,l=null;const c=d=>{i=d,n.setAttribute("viewBox",En(d)),n.removeAttribute("width"),n.removeAttribute("height")},u=d=>{c(ft(r,d))},g=()=>{u(Z(e))},p=(d,y)=>{c(Rn({currentBox:i,contentBox:r,viewport:Z(e),pointer:d,zoomFactor:y,minScale:An,maxScale:vn}))},h=()=>{const d=Z(e);p({x:d.width/2,y:d.height/2},Be)},m=()=>{const d=Z(e);p({x:d.width/2,y:d.height/2},1/Be)},f=d=>{!d.ctrlKey&&!d.metaKey||(d.preventDefault(),d.stopPropagation(),p(Tn(d,e),Math.pow(yn,-d.deltaY)))},A=d=>{d.button!==0||xn(d.target)||(o=d.pointerId,s={x:d.clientX,y:d.clientY},a=s,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(d.pointerId),t.setAttribute("data-mermaid-panning","true"),d.preventDefault())},v=d=>{if(o!==d.pointerId||!a)return;const y={x:d.clientX,y:d.clientY};c(Mn({currentBox:i,viewport:Z(e),delta:{x:y.x-a.x,y:y.y-a.y}})),a=y,s&&Nn(s,y)&&t.setAttribute("data-mermaid-suppress-click","true"),d.preventDefault()},w=d=>{o===d.pointerId&&(e.releasePointerCapture?.(d.pointerId),o=null,s=null,a=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},kn)))};e.addEventListener("wheel",f,{passive:!1}),e.addEventListener("pointerdown",A),e.addEventListener("pointermove",v),e.addEventListener("pointerup",w),e.addEventListener("pointercancel",w);const k={viewport:e,zoomIn:h,zoomOut:m,fit:g,fitToViewport:u,cleanup:()=>{Fn(k),e.removeEventListener("wheel",f),e.removeEventListener("pointerdown",A),e.removeEventListener("pointermove",v),e.removeEventListener("pointerup",w),e.removeEventListener("pointercancel",w),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),we.delete(t)}};return k},wt=t=>{for(const[e,n]of t.controllers){const r=ht(e);(!t.container.contains(e)||r!==t.signatures.get(e))&&(n.cleanup(),t.controllers.delete(e),t.signatures.delete(e))}},On=t=>{if(t.disposed)return[];const e=[];for(const n of Array.from(t.container.querySelectorAll(ne))){if(t.controllers.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const r=Dn(n);r&&(t.controllers.set(n,r),t.signatures.set(n,ht(n)),we.set(n,r),e.push(r))}return e},yt=()=>{const t=Array.from(re);re.clear();const e=[];for(const n of t)n.disposed||(wt(n),e.push(...On(n)));gt(e);for(const n of e)In(n)},Wn=()=>{Q===null&&(Q=window.requestAnimationFrame(()=>{Q=null,Q=window.requestAnimationFrame(()=>{Q=null,yt()})}))},qn=t=>{t.disposed||(wt(t),re.add(t),Wn())},zn=t=>{if(!(t instanceof HTMLElement))return null;const e=we.get(t);if(e)return e;for(const n of re)if(n.container.contains(t))return yt(),we.get(t)??null;return null},Bn=t=>{const e={container:t,controllers:new Map,signatures:new Map,disposed:!1},n=()=>qn(e),r=()=>{e.disposed=!0,re.delete(e);for(const i of e.controllers.values())i.cleanup();e.controllers.clear(),e.signatures.clear()};return n(),{refresh:n,cleanup:r}},$n={copy:"file-copy",check:"check",download:"download",zoomIn:"add",zoomOut:"subtract",fit:"refresh",textWrap:"text-wrap",image:"file-image"},At="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",oe=(t,e)=>{const n=$n[e],r=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("class","remixicon size-3.5"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true");const i=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","use");i.setAttribute("href",`#oc-${n}`),r.appendChild(i),t.replaceChildren(r)},Hn=t=>{for(const e of Array.from(t.querySelectorAll('[data-openchamber-markdown-image-label="true"]'))){if(e.querySelector("[data-openchamber-markdown-image-label-icon]"))continue;const n=document.createElement("span");n.className="inline-flex shrink-0",n.setAttribute("aria-hidden","true"),n.setAttribute("data-openchamber-markdown-image-label-icon","true"),oe(n,"image"),e.prepend(n)}},W=(t,e,n)=>{const r=document.createElement("button");return r.type="button",r.className=At,r.setAttribute("data-md-action",n),r.setAttribute("title",e),r.setAttribute("aria-label",e),oe(r,t),r},vt=(t,e,n)=>{const r=t.querySelector("[data-md-code-body]"),i=t.querySelector("pre"),o=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),a=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal"),o&&(o.style.whiteSpace=e?"pre-wrap":"pre",o.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(s))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(a){const l=e?n.disableCodeWrap:n.enableCodeWrap;a.setAttribute("title",l),a.setAttribute("aria-label",l),a.classList.toggle("text-foreground",e),a.classList.toggle("opacity-100",e),a.classList.toggle("text-muted-foreground",!e),a.classList.toggle("opacity-65",!e),a.setAttribute("aria-pressed",e?"true":"false")}},kt=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;t.removeAttribute("data-md-gutter-reserved");const n=e.textContent??"",r=n.endsWith(`
2
- `),i=r?n.slice(0,-1).split(`
3
- `):n.split(`
4
- `),o=i.length>0?i:[""],s=Array.from(e.children).filter(c=>c.classList.contains("line"));r&&s.length===o.length+1&&s.at(-1)?.textContent===""&&s.pop();const a=s.length===o.length,l=document.createDocumentFragment();o.forEach((c,u)=>{const g=document.createElement("span");g.setAttribute("data-md-code-line","");const p=document.createElement("span");p.setAttribute("data-md-code-line-number",String(u+1)),p.setAttribute("aria-hidden","true");const h=document.createElement("span");if(h.setAttribute("data-md-code-line-content",""),a){const m=s[u];m&&h.append(...Array.from(m.childNodes))}else h.textContent=c;if(g.append(p,h),l.appendChild(g),u<o.length-1||r){const m=document.createElement("span");m.setAttribute("data-md-code-line-break",""),m.textContent=`
5
- `,l.appendChild(m)}}),e.replaceChildren(l),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",r)},Et=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const n=e.map(r=>r.textContent??"").join(`
6
- `);return t.hasAttribute("data-md-code-trailing-newline")?`${n}
7
- `:n},He=(t,e,n)=>{const r=t.querySelectorAll('[data-component="markdown-code"]');for(const i of Array.from(r)){const o=i.querySelector("pre");o&&kt(o),vt(i,e,n)}},Ve=(t,e,n,r)=>{oe(t,"check"),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{oe(t,n),t.setAttribute("title",r),t.setAttribute("aria-label",r)},2e3)},Vn=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const n of Array.from(e))n.getAttribute("data-markdown")!=="inline-code"&&n.setAttribute("data-markdown","inline-code")},Kn=(t,e)=>{const n=t.querySelectorAll("pre");for(const r of Array.from(n)){if(r.querySelector("code.language-mermaid"))continue;const i=r.parentElement;if(!i||i.closest('[data-component="markdown-code"]'))continue;const o=r.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=r.getAttribute("data-md-lang")??o??"text",a=document.createElement("div");a.setAttribute("data-component","markdown-code"),a.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const l=document.createElement("div");l.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const c=document.createElement("span");c.className="font-mono text-[13px] text-muted-foreground",c.textContent=s;const u=W("copy",e.labels.copy,"copy-code"),g=W("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");l.appendChild(c);const p=document.createElement("div");p.className="flex items-center gap-1",p.setAttribute("data-md-code-actions",""),p.appendChild(g),p.appendChild(u),l.appendChild(p);const h=document.createElement("div");h.setAttribute("data-md-code-body",""),h.className="px-3 py-2.5 overflow-x-auto",i.replaceChild(a,r),r.style.margin="0",r.style.background="transparent",r.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync?r.setAttribute("data-md-gutter-reserved",""):kt(r),h.appendChild(r),a.appendChild(l),a.appendChild(h),vt(a,e.codeBlockLineWrap,e.labels)}},Ke=t=>{const e=[],n=[],r=t.querySelectorAll("thead th");for(const o of Array.from(r))e.push((o.textContent??"").trim());const i=t.querySelectorAll("tbody tr");for(const o of Array.from(i)){const s=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());s.length>0&&n.push(s)}return{headers:e,rows:n}},jn=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,je=({headers:t,rows:e})=>[t,...e].map(n=>n.map(jn).join(",")).join(`
8
- `),Un=({headers:t,rows:e})=>[t,...e].map(n=>n.join(" ")).join(`
9
- `),Ue=({headers:t,rows:e})=>{const n=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,i=e.map(o=>`| ${o.join(" | ")} |`).join(`
10
- `);return`${n}
11
- ${r}
12
- ${i}`},Ze=(t,e)=>{const n=document.createElement("div");n.className=`absolute top-full right-0 mt-1 hidden ${jt}`,n.style.backgroundColor="var(--surface-elevated)",n.style.color="var(--surface-elevated-foreground)",n.setAttribute("data-md-menu",t);for(const r of e){const i=document.createElement("button");i.type="button",i.className=`w-full text-left ${Ut}`,i.setAttribute("data-md-action",`${t}-${r.key}`),i.textContent=r.label,n.appendChild(i)}return n},Zn=(t,e)=>{const n=t.querySelectorAll("table");for(const r of Array.from(n)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const o=document.createElement("div");o.className="group my-4 flex flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const a=document.createElement("div");a.className="relative",a.appendChild(W("copy",e.copyTable,"table-copy-toggle")),a.appendChild(Ze("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(W("download",e.downloadTable,"table-download-toggle")),l.appendChild(Ze("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(a),s.appendChild(l);const c=document.createElement("div");c.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const u=r.parentElement;if(!u)continue;u.replaceChild(o,r),r.setAttribute("data-markdown","table"),r.classList.add("w-full","border-collapse","text-sm");for(const p of Array.from(r.querySelectorAll("tr")))p.classList.add("border-b","border-border/60");const g=r.querySelector("tbody tr:last-child");g?.classList.remove("border-b"),g?.classList.add("border-0");for(const p of Array.from(r.querySelectorAll("th")))p.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const p of Array.from(r.querySelectorAll("td")))p.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");c.appendChild(r),o.appendChild(s),o.appendChild(c)}},Xn=(t,e)=>{const n=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(n)){const i=r.parentElement;if(!i)continue;const o=(r.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(o),a=document.createElement("div");a.setAttribute("data-markdown","mermaid-block"),a.setAttribute("data-md-source",o),a.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const c=document.createElement("div");if(c.setAttribute("data-markdown","mermaid-toolbar"),c.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",s.svg){a.setAttribute("data-mermaid-render","svg");const g=document.createElement("div");g.setAttribute("data-markdown","mermaid-viewport");const p=document.createElement("div");if(p.setAttribute("data-markdown","mermaid"),p.setAttribute("data-md-original-svg",s.svg),p.innerHTML=s.svg,g.appendChild(p),l.appendChild(g),e.mermaidControls.showPanZoomControls&&(c.appendChild(W("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),c.appendChild(W("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),c.appendChild(W("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const h=W("copy",e.labels.copyDiagram,"mermaid-copy");h.setAttribute("data-md-source",o),c.appendChild(h)}if(e.mermaidControls.download){const h=W("download",e.labels.downloadDiagram,"mermaid-download");h.setAttribute("data-md-svg","1"),c.appendChild(h)}}else{a.setAttribute("data-mermaid-render","ascii");const g=document.createElement("pre");if(g.setAttribute("data-markdown","mermaid-ascii"),g.textContent=s.ascii||o,l.appendChild(g),e.mermaidControls.copy){const p=W("copy",e.labels.copyDiagram,"mermaid-copy");p.setAttribute("data-md-source",s.ascii||o),c.appendChild(p)}}a.appendChild(l),a.appendChild(c);const u=i.parentElement;u&&u.replaceChild(a,i)}},Gn=(t,e)=>{const n=t.querySelectorAll("a[href]");for(const r of Array.from(n)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-openchamber-file-link")==="true")continue;const i=r.getAttribute("href")??"";if(!it(i))continue;r.setAttribute("data-md-link-decorated","true");const o=Vt(i);if(o){const s=document.createElement("span");s.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const a=document.createElement("img");a.src=o,a.alt="",a.setAttribute("aria-hidden","true"),a.loading="lazy",a.decoding="async",a.className="size-3.5 rounded-sm",a.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(a),r.parentNode?.insertBefore(s,r)}if(e.onPreviewLoopback&&Kt(i)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${At}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",i),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),oe(s,"download"),r.parentNode?.insertBefore(s,r.nextSibling)}}},me=(t,e)=>{Hn(t),Vn(t),Xn(t,e),Kn(t,e),Zn(t,e.labels),Gn(t,e)},Xe=(t,e,n)=>{const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},pe=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Ge=t=>(t.nodeType===1?t:t.parentElement)?.closest("pre code[data-md-code-lines]")??null,Yn=t=>{const e=Ge(t.startContainer);return!e||e!==Ge(t.endContainer)?null:t.toString()},fe=new WeakMap,Jn=t=>{let e=fe.get(t);if(!e){const n=()=>{const o=t.getSelection();return!o||o.rangeCount!==1||o.isCollapsed?null:Yn(o.getRangeAt(0))},r=o=>{if(!o.clipboardData)return;const s=n();s!==null&&(o.preventDefault(),o.stopPropagation(),o.clipboardData.setData("text/plain",s))},i=o=>{const s=n();s!==null&&(o.preventDefault(),be(s))};e={registrations:0,handler:r,menuHandler:i},fe.set(t,e),t.addEventListener("copy",r,!0),t.defaultView?.addEventListener("openchamber:copy",i)}return e.registrations+=1,()=>{const n=fe.get(t);n&&(n.registrations-=1,!(n.registrations>0)&&(t.removeEventListener("copy",n.handler,!0),t.defaultView?.removeEventListener("openchamber:copy",n.menuHandler),fe.delete(t)))}},Qn=(t,e)=>{const n=Jn(t.ownerDocument),r=i=>{const o=i.target;if(!(o instanceof Element))return;const s=o.closest("[data-md-action]");if(!s){pe(t);return}const a=s.getAttribute("data-md-action")??"";if(a==="copy-code"){const l=s.closest('[data-component="markdown-code"]')?.querySelector("code"),c=l?Et(l):"";c&&(s.setAttribute("data-md-copy-pending",""),be(c).then(()=>Ve(s,e.labels.copied,"copy",e.labels.copy)).finally(()=>s.removeAttribute("data-md-copy-pending")));return}if(a==="toggle-code-wrap"){i.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){i.preventDefault();const l=s.parentElement?.querySelector("[data-md-menu]")??null,c=l?.classList.contains("hidden")??!1;pe(t),l&&c&&l.classList.remove("hidden");return}if(a.startsWith("table-copy-")){const l=a.replace("table-copy-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ke(c),g=l==="csv"?je(u):l==="tsv"?Un(u):Ue(u);be(g)}pe(t);return}if(a.startsWith("table-download-")){const l=a.replace("table-download-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ke(c),g=l==="csv"?je(u):Ue(u);Xe(l==="csv"?"table.csv":"table.md",g,l==="csv"?"text/csv":"text/markdown")}pe(t);return}if(a==="mermaid-copy"){const l=s.getAttribute("data-md-source")??"";l&&be(l).then(()=>Ve(s,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){i.preventDefault();const l=s.closest('[data-markdown="mermaid-block"]'),c=zn(l);a==="mermaid-zoom-in"?c?.zoomIn():a==="mermaid-zoom-out"?c?.zoomOut():c?.fit();return}if(a==="mermaid-download"){const l=s.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),c=l?.getAttribute("data-md-original-svg")??l?.innerHTML??"";c&&Xe("diagram.svg",c,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){i.preventDefault();const l=s.getAttribute("data-md-url")??"";l&&e.onPreviewLoopback?.(l);return}};return t.addEventListener("click",r),()=>{n(),t.removeEventListener("click",r)}},Ye=(t,e,n)=>{let r=0;for(const o of t){const s=r+o.data.length;if(e<s||e===s&&n==="left")return{node:o,offset:Math.max(0,e-r)};r=s}const i=t.at(-1);return i?{node:i,offset:i.data.length}:null},er=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Je=Array.from(er).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Ct=t=>Zt(t),tr=t=>Xt(t),nr=t=>{let e;try{e=new URL(t.trim())}catch{return null}if(e.protocol!=="file:"||e.hostname&&e.hostname!=="localhost")return null;try{const n=decodeURIComponent(e.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n.startsWith("/")?n:null}catch{return null}},ye=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},he=t=>{let e=ye(t);if(!e)return"";const n=e.indexOf(";");n>=0&&(e=e.slice(0,n)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const i=Je.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Je})):.*$`,"i")):null;return i&&(e=i[1]??e),ye(e)},St=t=>{const e=ye(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?ye(e.slice(0,n)):e;if(!r)return null;const i=r.match(/^(.*?):(\d+)-(\d+)$/);if(i){const l=he(i[1]??""),c=Number.parseInt(i[2]??"",10),u=Number.parseInt(i[3]??"",10);return!l||!Number.isFinite(c)||!Number.isFinite(u)||u<c?null:{path:l,line:c,endLine:u}}const o=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(o){const l=he(o[1]??""),c=Number.parseInt(o[2]??"",10),u=o[3]?Number.parseInt(o[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const s=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const l=he(s[1]??""),c=Number.parseInt(s[2]??"",10),u=s[3]?Number.parseInt(s[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const a=he(r);return a?{path:a}:null},Ne=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,rr=4,or=1e3,ir=200,z=new Map;let ge=0;const Qe=[],sr=()=>ut()?ir:or,ar=(t,e)=>`${t}\0${e}`,lr=(t,e)=>{const n=Ct(t);if(!n)return Promise.resolve(!1);const r=ar(e,n),i=z.get(r);if(i)return z.delete(r),z.set(r,i),i;const o=new Promise(a=>{const l=()=>{ge+=1,on(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async c=>{if(!c.ok){a(!1);return}const u=await c.json().catch(()=>null);a(u?.exists!==!1)}).catch(()=>a(!1)).finally(()=>{ge=Math.max(0,ge-1),Qe.shift()?.()})};if(ge<rr){l();return}Qe.push(l)}),s=sr();for(;z.size>=s;){const a=z.keys().next().value;if(typeof a!="string")break;z.delete(a)}return z.set(r,o),o},cr={maxSessions:8,maxEntriesPerSession:4};class dr{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=cr){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let i=this.sessions.get(n);for(i===void 0?(i=new Map,this.sessions.set(n,i)):this.refreshSession(n,i),i.delete(r),i.set(r,e);i.size>this.maxEntriesPerSession;)this.removeOldestEntry(i);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const i=e.id;this.refreshSession(n,r);const o=r.get(i);return o===void 0||o.locale!==e.locale||o.directory!==e.directory?null:(r.delete(i),r.size===0&&this.sessions.delete(n),o.fragment)}clear(){this.sessions.clear()}stats(){let e=0;for(const n of this.sessions.values())e+=n.size;return{sessions:this.sessions.size,entries:e}}refreshSession(e,n){this.sessions.delete(e),this.sessions.set(e,n)}removeOldestEntry(e){const n=e.keys().next().value;n!==void 0&&e.delete(n)}removeOldestSession(){const e=this.sessions.keys().next().value;e!==void 0&&this.sessions.delete(e)}}const et=new dr,Lt=()=>{const t=ie.c(4),e=Gt();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=De(!1),t[0]=n):n=t[0];const r=n;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=De(!0),t[1]=i):i=t[1];const o=i;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:r),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Mt=t=>{const e=ie.c(4),{containerRef:n,enabled:r}=t;let i,o;e[0]!==n||e[1]!==r?(i=()=>{const s=n.current;if(s)return hn(s,{allowExternalHttp:r!==!1,openAppLink:_r,openExternalHttp:Tr})},o=[n,r],e[0]=n,e[1]=r,e[2]=i,e[3]=o):(i=e[2],o=e[3]),E.useEffect(i,o)},J={download:!0,copy:!0,showPanZoomControls:!0},Nt=!0,ur=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},tt='[data-openchamber-file-link="true"]',Rt="data-openchamber-block-path-token",_t=`[${Rt}]`,G="data-openchamber-block-paths-scanned",mr=2e5,pr=80,fr=40,nt=160,hr=()=>ut()?fr:pr,gr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Tt=t=>Ct(t),br=t=>tr(t),wr=(t,e)=>en(t,e),yr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},xt=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Tt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return gr.has(r)||r.startsWith(".")&&r.length>1?!0:yr(e)},Pt=t=>{const e=St(t);return e?xt(e.path):!1},Ar=t=>{const e=t.querySelectorAll(_t);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${G}]`);for(const r of Array.from(n))r.removeAttribute(G),r.normalize()},Re=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),n=e?nr(e):null;if(n)return n;if(e&&Pt(e))return e}return(t.textContent||"").trim()},vr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const n=t.ownerDocument;if(n)for(const r of Array.from(e)){if(r.getAttribute(G)==="true")continue;if((r.textContent??"").length>mr){r.setAttribute(G,"true");continue}const i=n.createTreeWalker(r,NodeFilter.SHOW_TEXT),o=[];let s=i.nextNode();for(;s;){const u=s;u.parentElement?.closest("[data-md-code-line-number]")||o.push(u),s=i.nextNode()}const a=Et(r);if(!a.includes(".")){r.setAttribute(G,"true");continue}Ne.lastIndex=0;const l=[];let c=Ne.exec(a);for(;c;){const u=c[0];u&&Pt(u)&&l.push({start:c.index,end:c.index+u.length,raw:u}),c=Ne.exec(a)}for(const{start:u,end:g,raw:p}of l.reverse()){const h=Ye(o,u,"right"),m=Ye(o,g,"left");if(!h||!m)continue;const f=n.createRange();f.setStart(h.node,h.offset),f.setEnd(m.node,m.offset);const A=n.createElement("span");A.setAttribute(Rt,"true"),A.textContent=p,f.deleteContents(),f.insertNode(A)}r.setAttribute(G,"true")}},_e=(t,e)=>{const n=St(t);if(!n||!xt(n.path))return null;const r=br(n.path)?Tt(n.path):wr(e,n.path);return r?{...n,resolvedPath:r}:null},kr=(t,e)=>t||Qt(t,e),It=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:i})=>{const o=E.useRef(null);E.useEffect(()=>{const s=t.current;if(!s||i&&!e)return;let a=!1;const l=hr(),c=i&&!dn(),u=d=>{d.removeAttribute("data-openchamber-file-link"),d.removeAttribute("data-openchamber-file-ref"),d.removeAttribute("data-openchamber-file-path"),d.getAttribute("title")==="Open file"&&d.removeAttribute("title"),d.tagName.toLowerCase()!=="a"&&(d.removeAttribute("role"),d.removeAttribute("tabindex"))},g=()=>{const d=s.querySelectorAll(tt);for(const y of Array.from(d))u(y);Ar(s)};if(!c){g();return}const p=(d=0)=>{if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){h();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{a||h()})},d)},h=()=>{w+=1;try{m()}finally{queueMicrotask(()=>{w-=1})}},m=()=>{c&&vr(s);const d=s.querySelectorAll(`[data-markdown="inline-code"], a, ${_t}`);let y=0;for(const b of Array.from(d)){const L=Re(b),C=_e(L,e);if(u(b),!C||y>=l)continue;y+=1,(ln()&&cn()&&!Oe(C.resolvedPath,e)?Promise.resolve(!0):lr(C.resolvedPath,e)).then(x=>{if(a||!x||!s.contains(b))return;const _=Re(b),P=_e(_,e);!P||P.resolvedPath!==C.resolvedPath||(b.setAttribute("data-openchamber-file-link","true"),b.setAttribute("data-openchamber-file-ref",_),b.setAttribute("data-openchamber-file-path",P.resolvedPath),b.setAttribute("title","Open file"),b.tagName.toLowerCase()!=="a"&&(b.setAttribute("role","button"),b.setAttribute("tabindex","0")))})}},f=async d=>{const y=d.getAttribute("data-openchamber-file-ref")||Re(d),b=_e(y,e);if(!b)return;const L=kr(e,b.resolvedPath);if(r&&n){n.openFile(b.resolvedPath,Number.isFinite(b.line??Number.NaN)?Math.max(1,Math.trunc(b.line)):void 0,Number.isFinite(b.column??Number.NaN)?Math.max(1,Math.trunc(b.column)):void 0);return}Oe(b.resolvedPath,e)||await Jt(b.resolvedPath,e);const C=X.getState();Number.isFinite(b.line??Number.NaN)?C.openContextFileAtLine(L,b.resolvedPath,Math.max(1,Math.trunc(b.line)),Number.isFinite(b.column??Number.NaN)?Math.max(1,Math.trunc(b.column)):1):C.openContextFile(L,b.resolvedPath)},A=d=>{const y=d.target;if(!(y instanceof Element))return;const b=y.closest(tt);b instanceof HTMLElement&&(d.preventDefault(),d.stopPropagation(),f(b))},v=d=>{if(d.key!=="Enter"&&d.key!==" ")return;const y=d.target;!(y instanceof HTMLElement)||y.getAttribute("data-openchamber-file-link")!=="true"||(d.preventDefault(),d.stopPropagation(),f(y))};p(nt);let w=0;const k=new MutationObserver(()=>{w>0||p(nt)});return k.observe(s,{childList:!0,subtree:!0}),s.addEventListener("click",A),s.addEventListener("keydown",v),()=>{a=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,k.disconnect(),s.removeEventListener("click",A),s.removeEventListener("keydown",v)}},[t,n,e,r,i])},Ft=t=>{const e=ie.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:i,enablePanZoom:o,allowMermaidWheelEvents:s}=t;let a,l;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==o||e[4]!==r?(a=()=>{const c=n.current;if(!c)return;const u=p=>{if(!i||!r)return;const h=p.target;if(!(h instanceof Element)||h.closest('button, a, [role="button"]'))return;const m=h.closest(ne);if(!m)return;if(m instanceof HTMLElement&&m.hasAttribute("data-mermaid-suppress-click")){m.removeAttribute("data-mermaid-suppress-click");return}const A=Array.from(c.querySelectorAll(ne)).indexOf(m);if(A<0)return;const v=m instanceof HTMLElement?m.getAttribute("data-md-source"):null;if(!v||v.trim().length===0)return;const w=`Diagram ${A+1}`;r({open:!0,title:w,content:"",metadata:{tool:"mermaid-preview",filename:w},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(v)}`,source:v,filename:w}})},g=p=>{if(s||(p.ctrlKey||p.metaKey)&&o)return;const h=p.target;!(h instanceof Element)||!h.closest(ne)||p.stopPropagation()};return c.addEventListener("click",u),c.addEventListener("wheel",g,{capture:!0,passive:!0}),()=>{c.removeEventListener("click",u),c.removeEventListener("wheel",g,!0)}},l=[s,n,i,o,r],e[0]=s,e[1]=n,e[2]=i,e[3]=o,e[4]=r,e[5]=a,e[6]=l):(a=e[5],l=e[6]),E.useEffect(a,l)},B=new Map,Er=100,$="data-md-decoration-id",Cr=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let i=0;i<e.length;i+=1){const o=r[i];if(!o||o.getAttribute("data-md-id")!==e[i]?.id||o.getAttribute($)!==n)return!1}return!0},rt=new WeakMap;let ot=0;const Sr=2e5,Te=t=>{const e=rt.get(t);if(e)return e;const n=`decoration-${ot}`;return ot+=1,rt.set(t,n),n},Lr=(t,e)=>{const n=B.get(t);if(n)return B.delete(t),B.set(t,n),n;const r=e();if(B.set(t,r),B.size>Er){const i=B.keys().next().value;i&&B.delete(i)}return r},Mr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),Dt=(t,e,n,r=J)=>{const{t:i}=ct(),o=E.useMemo(()=>({copy:i("markdownRenderer.code.actions.copyTitle"),copied:i("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:i("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:i("markdownRenderer.code.actions.disableWrapTitle"),copyTable:i("markdownRenderer.table.actions.copyTitle"),downloadTable:i("markdownRenderer.table.actions.downloadTitle"),copyDiagram:i("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:i("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:i("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:i("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:i("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:i("terminalView.preview.open"),previewTitle:i("terminalView.preview.openTitle")}),[i]),s=X(c=>c.codeBlockLineWrap),a=X(c=>c.setCodeBlockLineWrap),l=E.useCallback(()=>{a(!X.getState().codeBlockLineWrap)},[a]);return E.useMemo(()=>{const c=Mr(t),u=X.getState().mermaidRenderingMode,g=t.metadata?.id??"theme";return{labels:o,mermaidControls:r,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:h=>Lr(`${g}:${u}:${h}`,()=>{try{return u==="ascii"?{ascii:Bt(h)}:{svg:$t(h,c)}}catch{return{}}}),onPreviewLoopback:n}},[t,o,r,s,e,l,n])},Ot=({containerRef:t,text:e,streaming:n,imageMode:r="inline",syntaxVars:i,ctx:o,domCacheKey:s})=>{E.useEffect(()=>{bn()},[]);const a=E.useRef(null),l=E.useRef(0),c=E.useContext(Yt),u=E.useRef(null),g=E.useCallback(()=>{u.current?.(),u.current=null},[]);E.useEffect(()=>g,[g]);const p=E.useRef(null),h=E.useCallback(()=>{const m=t.current;if(m){if(!a.current){if(!I(m))return;a.current=Bn(m);return}a.current.refresh()}},[t]);E.useLayoutEffect(()=>{l.current+=1,p.current=null},[o,r,n,e]),E.useLayoutEffect(()=>{if(!s)return;const m=t.current,f=m?.querySelector("[data-markdown-content]")??m;if(!f||f.childNodes.length>0)return;const A=et.take(s);if(A){f.appendChild(A);const v=Te(o);for(const w of Array.from(f.children))w.setAttribute($,v);for(const[w,k]of Object.entries(i))f.style.setProperty(w,k);He(f,o.codeBlockLineWrap,o.labels),p.current={key:s,copiedLabel:o.labels.copied},te("ui.markdown_renderer.dom_cache.hit")}},[t,o,s,i,e.length]),E.useLayoutEffect(()=>{const m=t.current,f=m?.querySelector("[data-markdown-content]")??m;if(f)return()=>{const A=p.current;if(!A||f.childNodes.length===0||I(f)||Array.from(f.children).some(y=>!y.hasAttribute("data-md-id"))||f.querySelector("[data-md-copy-pending]"))return;const v=window.getSelection();if(v?.rangeCount&&!v.isCollapsed&&v.getRangeAt(0).intersectsNode(f))return;const w=f.querySelector("[data-md-menu]:not(.hidden)"),k=Array.from(f.querySelectorAll("[data-md-action]")).some(y=>y.getAttribute("title")===A.copiedLabel);if(w||k)return;const d=document.createDocumentFragment();d.append(...Array.from(f.childNodes)),et.store({...A.key,fragment:d}),te("ui.markdown_renderer.dom_cache.capture")}},[t]),E.useLayoutEffect(()=>{const m=t.current,f=m?.querySelector("[data-markdown-content]")??m;if(!f)return;const A=Te(o);if(e&&f.childNodes.length===0){const v=n?null:We(e,r);if(v){let w=!1;for(const k of v){const d=document.createElement("div");d.setAttribute("data-md-block",""),d.style.display="contents",d.innerHTML=k.html,me(d,o),d.setAttribute("data-md-id",k.id),d.setAttribute($,A),w||=I(d),f.appendChild(d)}w&&h()}else{!n&&!u.current&&(u.current=c?.hold()??null);const w=document.createElement("div");w.setAttribute("data-md-block",""),w.style.display="contents",w.innerHTML=un(e,r),me(w,o),w.setAttribute($,A),f.appendChild(w),I(w)&&h()}}else!a.current&&I(f)&&h()},[t,e,n,r,o,h,c]),E.useEffect(()=>()=>{a.current?.cleanup(),a.current=null},[]),E.useEffect(()=>{const m=t.current;if(!m)return;const f=m.querySelector("[data-markdown-content]")??m;let A=!0;const v=l.current,w=Te(o);if(!n){const k=We(e,r);if(k&&Cr(f,k,w)){p.current=s?{key:s,copiedLabel:o.labels.copied}:null,te("ui.markdown_renderer.settled_paint.reused"),g();return}}return mn(e,n,r).then(k=>{if(!A||l.current!==v)return;const d=Array.from(f.children);let y=0;k.forEach((C,T)=>{let M=d[T],x=!1;if(M||(M=document.createElement("div"),M.setAttribute("data-md-block",""),M.style.display="contents",f.appendChild(M),x=!0),M.getAttribute("data-md-id")===C.id){if(M.getAttribute($)!==w){const N=I(M);N&&(a.current?.cleanup(),a.current=null);const S=document.createElement("div");S.setAttribute("data-md-block",""),S.style.display="contents",S.innerHTML=C.html,me(S,o),S.setAttribute("data-md-id",C.id),S.setAttribute($,w),M.replaceWith(S),(N||I(S))&&h()}!a.current&&I(M)&&h();return}const _=document.createElement("div");if(_.innerHTML=C.html,me(_,o),x&&n&&T>0){const N=Math.min(y,4)*55;y+=1;for(const S of Array.from(_.children))S.classList.add("oc-md-block-enter"),N>0&&S instanceof HTMLElement&&S.style.setProperty("--oc-md-enter-delay",`${N}ms`)}const P=I(M),F=I(_);zt(M,_,{childrenOnly:!0,onBeforeElUpdated:(N,S)=>!N.isEqualNode(S)}),M.setAttribute("data-md-id",C.id),M.setAttribute($,w),(P||F||I(M))&&h()});const b=I(f);let L=!1;for(let C=d.length-1;C>=k.length;C-=1){const T=d[C];T&&I(T)&&(L=!0),T?.remove()}(L||d.length>k.length&&b)&&h(),p.current=s?{key:s,copiedLabel:o.labels.copied}:null,g()}),()=>{A=!1}},[t,o,s,r,h,g,n,e]),E.useEffect(()=>{const m=t.current;if(m)return Qn(m,o)},[t,o]),E.useEffect(()=>{const m=t.current,f=m?.querySelector("[data-markdown-content]")??m;if(f)for(const[A,v]of Object.entries(i))f.style.setProperty(A,v)},[t,i]),E.useEffect(()=>{const m=t.current,f=m?.querySelector("[data-markdown-content]")??m;f&&(o.deferCodeLineNumberSync||He(f,o.codeBlockLineWrap,o.labels))},[t,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels])},Wt=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Nr=t=>{const e=ie.c(39),{content:n,part:r,messageId:i,isAnimated:o,skipFadeIn:s,className:a,isStreaming:l,disableStreamAnimation:c,variant:u,onShowPopup:g,enableFileReferences:p}=t,h=o===void 0?!0:o,m=s===void 0?!1:s,f=l===void 0?!1:l,A=c===void 0?!1:c,v=u===void 0?"assistant":u,w=p===void 0?!0:p;te("ui.markdown_renderer.render"),f&&te("ui.markdown_renderer.render.streaming"),sn("ui.markdown_renderer.content_len",n.length);const k=Lt(),{editor:d,runtime:y}=st(),b=E.useRef(null),L=at()??"",C=X(xr);let T;e[0]!==L||e[1]!==C?(T=O=>{L&&C(L,O)},e[0]=L,e[1]=C,e[2]=T):T=e[2];const M=T,x=f&&!A;let _;e[3]!==g?(_={containerRef:b,onShowPopup:g,enableFullscreen:Nt,enablePanZoom:J.showPanZoomControls},e[3]=g,e[4]=_):_=e[4],Ft(_);const P=w&&!f;let F;e[5]!==d||e[6]!==L||e[7]!==y.isVSCode||e[8]!==P?(F={containerRef:b,effectiveDirectory:L,editor:d,preferRuntimeEditor:y.isVSCode,enabled:P},e[5]=d,e[6]=L,e[7]=y.isVSCode,e[8]=P,e[9]=F):F=e[9],It(F);let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N={containerRef:b},e[10]=N):N=e[10],Mt(N);let S;e[11]!==k?(S=lt(k),e[11]=k,e[12]=S):S=e[12];const D=S,q=Dt(k,x,L?M:void 0,J),{locale:Ae}=ct(),se=v==="assistant"?"label":"inline",ve=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let ae;e[13]===Symbol.for("react.memo_cache_sentinel")?(ae=an(),e[13]=ae):ae=e[13];const qt=ae,Pe=ve?.sessionID,Ie=ve?.messageID,Fe=ve?.id;let ke;e:{if(f||!Pe||!Ie||!Fe||n.length===0||n.length>Sr){ke=null;break e}const O=`${qt}\0${Pe}`,Se=`${Ie}\0${Fe}\0${se}\0${n.length}`;let ue;e[14]!==L||e[15]!==Ae||e[16]!==O||e[17]!==Se?(ue={scope:O,id:Se,locale:Ae,directory:L},e[14]=L,e[15]=Ae,e[16]=O,e[17]=Se,e[18]=ue):ue=e[18],ke=ue}const Ee=ke,Ce=`markdown-${r?.id?`part-${r.id}`:`message-${i}`}`;let le;e[19]!==n||e[20]!==q||e[21]!==Ee||e[22]!==se||e[23]!==x||e[24]!==D?(le={containerRef:b,text:n,streaming:x,imageMode:se,syntaxVars:D,ctx:q,domCacheKey:Ee},e[19]=n,e[20]=q,e[21]=Ee,e[22]=se,e[23]=x,e[24]=D,e[25]=le):le=e[25],Ot(le);let K;e[26]!==a?(K=dt("break-words w-full min-w-0",a),e[26]=a,e[27]=K):K=e[27];let j;e[28]!==v?(j=Wt(v),e[28]=v,e[29]=j):j=e[29];let U;e[30]!==j?(U=ee.jsx("div",{className:j,"data-markdown-content":!0}),e[30]=j,e[31]=U):U=e[31];let ce;e[32]!==K||e[33]!==U?(ce=ee.jsx("div",{className:K,ref:b,children:U}),e[32]=K,e[33]=U,e[34]=ce):ce=e[34];const de=ce;if(h){let O;return e[35]!==Ce||e[36]!==de||e[37]!==m?(O=ee.jsx(tn,{skipAnimation:m,children:de},Ce),e[35]=Ce,e[36]=de,e[37]=m,e[38]=O):O=e[38],O}return de},Di=E.memo(Nr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),Rr=t=>{const e=ie.c(29),{content:n,className:r,variant:i,disableLinkSafety:o,stripFrontmatter:s,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:c,enableFileReferences:u}=t,g=i===void 0?"assistant":i,p=s===void 0?!1:s,h=l===void 0?J:l,m=c===void 0?!1:c,f=u===void 0?!0:u,{editor:A,runtime:v}=st(),w=Lt(),k=E.useRef(null),d=at()??"";let y;e[0]!==n||e[1]!==p?(y=p?ur(n):n,e[0]=n,e[1]=p,e[2]=y):y=e[2];const b=y;let L;e[3]!==m||e[4]!==h.showPanZoomControls||e[5]!==a?(L={containerRef:k,onShowPopup:a,enableFullscreen:Nt,enablePanZoom:h.showPanZoomControls,allowMermaidWheelEvents:m},e[3]=m,e[4]=h.showPanZoomControls,e[5]=a,e[6]=L):L=e[6],Ft(L);let C;e[7]!==A||e[8]!==d||e[9]!==f||e[10]!==v.isVSCode?(C={containerRef:k,effectiveDirectory:d,editor:A,preferRuntimeEditor:v.isVSCode,enabled:f},e[7]=A,e[8]=d,e[9]=f,e[10]=v.isVSCode,e[11]=C):C=e[11],It(C);const T=!o;let M;e[12]!==T?(M={containerRef:k,enabled:T},e[12]=T,e[13]=M):M=e[13],Mt(M);let x;e[14]!==w?(x=lt(w),e[14]=w,e[15]=x):x=e[15];const _=x,P=Dt(w,!1,void 0,h);let F;e[16]!==P||e[17]!==b||e[18]!==_?(F={containerRef:k,text:b,streaming:!1,syntaxVars:_,ctx:P},e[16]=P,e[17]=b,e[18]=_,e[19]=F):F=e[19],Ot(F);let N;e[20]!==r?(N=dt("break-words w-full min-w-0",r),e[20]=r,e[21]=N):N=e[21];let S;e[22]!==g?(S=Wt(g),e[22]=g,e[23]=S):S=e[23];let D;e[24]!==S?(D=ee.jsx("div",{className:S,"data-markdown-content":!0}),e[24]=S,e[25]=D):D=e[25];let q;return e[26]!==N||e[27]!==D?(q=ee.jsx("div",{className:N,ref:k,children:D}),e[26]=N,e[27]=D,e[28]=q):q=e[28],q},Oi=E.memo(Rr,(t,e)=>{const n=t.mermaidControls??J,r=e.mermaidControls??J;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&n.download===r.download&&n.copy===r.copy&&n.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function _r(t){nn(t)}function Tr(t){rn(t)}function xr(t){return t.openContextPreview}export{Di as MarkdownRenderer,Oi as SimpleMarkdownRenderer};