@openchamber/web 2.3.0 → 2.3.1

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 (250) hide show
  1. package/dist/assets/AboutDialog-C1ulAXh5.js +1 -0
  2. package/dist/assets/ArchiveView-DJo1Bpw_.js +1 -0
  3. package/dist/assets/{CommandPalette-1VlA7PbL.js → CommandPalette-B6r6DPF9.js} +2 -2
  4. package/dist/assets/{DiffView-SHdJJ6tl.js → DiffView-mJuVm7Z4.js} +2 -2
  5. package/dist/assets/{FilePreviewCommentMenu-DlVgwRsr.js → FilePreviewCommentMenu-Ca4ziuof.js} +1 -1
  6. package/dist/assets/{FilesView-BeMtsSlV.js → FilesView-BBFbfDp9.js} +3 -3
  7. package/dist/assets/{GitView-npRGKKx8.js → GitView-WL1wkRFF.js} +3 -3
  8. package/dist/assets/GuestSurfacePane-peVDY5gW.js +1 -0
  9. package/dist/assets/HelpDialog-Dxc2yneu.js +1 -0
  10. package/dist/assets/{InProgressOperationBanner-B6iO22_7.js → InProgressOperationBanner-Dy0RiPsD.js} +1 -1
  11. package/dist/assets/JsonTreeView-BKUmh7Iw.js +1 -0
  12. package/dist/assets/MarkdownImageGallery-Cd6hLNmi.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-C-3B3mBt.js +1 -0
  14. package/dist/assets/MemoryDebugPanel-b116r1SF.js +1 -0
  15. package/dist/assets/OnboardingScreen-vBEhpU3q.js +1 -0
  16. package/dist/assets/OpenCodeStatusDialog-DH7dJ6MH.js +1 -0
  17. package/dist/assets/{PatchDiff-Du2s7T3U.js → PatchDiff-yM7vgQgi.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-B9K0gBvV.js → PierreDiffViewer-DnHKbYGl.js} +1 -1
  19. package/dist/assets/{PlanView-IkTcPrbw.js → PlanView-j0hLJmto.js} +2 -2
  20. package/dist/assets/RunOverview-ZuFZvDcu.js +2 -0
  21. package/dist/assets/ScheduledTasksDialog-UKXFFI91.js +5 -0
  22. package/dist/assets/{SettingsView-DIy5ZL4-.js → SettingsView-gB_NvyX4.js} +8 -8
  23. package/dist/assets/SettingsWindow-Dfb_RFpD.js +1 -0
  24. package/dist/assets/SourceBoardView-BjaL0nKs.js +1 -0
  25. package/dist/assets/SpaceAccessDialog-XzHRmIdT.js +1 -0
  26. package/dist/assets/SpaceApplyDialog-CxX9mrzT.js +1 -0
  27. package/dist/assets/{SpaceRow-YPmKQKeD.js → SpaceRow-vCpOCANO.js} +1 -1
  28. package/dist/assets/SpaceSetupOutput-CDZvJCf_.js +1 -0
  29. package/dist/assets/SpacesView-D3a9bCzn.js +1 -0
  30. package/dist/assets/{SubmoduleDiffSummary-RDY5md3p.js → SubmoduleDiffSummary-CQyRcvDZ.js} +1 -1
  31. package/dist/assets/{ToolOutputDialog-Dx85XZJs.js → ToolOutputDialog-judR_5mS.js} +2 -2
  32. package/dist/assets/{ToolPartDiffPreview-Dtv0xF9O.js → ToolPartDiffPreview-Ca9ISxfg.js} +1 -1
  33. package/dist/assets/UsageStatsView-C63Emjfj.js +1 -0
  34. package/dist/assets/{Virtualizer-DL535kyR.js → Virtualizer-DNgIEKcx.js} +1 -1
  35. package/dist/assets/{WalkthroughView-DcxbT5tc.js → WalkthroughView-D74b_7sC.js} +2 -2
  36. package/dist/assets/WorktreesView-hcm8Eb_C.js +1 -0
  37. package/dist/assets/appThemeRegistry-COeayQaQ.js +1 -0
  38. package/dist/assets/{ar-lP51qqz9.js → ar-1_zdYVV5.js} +2 -2
  39. package/dist/assets/computeVirtualFileMetrics-MZqvCQy0.js +3 -0
  40. package/dist/assets/{de-CpROAvTV.js → de-Ci7SGEQP.js} +3 -3
  41. package/dist/assets/{decorate-BNB7jeKg.js → decorate-CZeRRVC7.js} +1 -1
  42. package/dist/assets/{es-Bb8LKRhE.js → es-ZJii-6Tt.js} +2 -2
  43. package/dist/assets/{fr-BlNN9FC2.js → fr-C-hK8mvI.js} +2 -2
  44. package/dist/assets/{he-r546pCuc.js → he-t07CylP8.js} +2 -2
  45. package/dist/assets/index-D2tPUss-.js +1 -0
  46. package/dist/assets/{initializeSharedPreferences-dCHO04bl.js → initializeSharedPreferences-FxFkTjgn.js} +1 -1
  47. package/dist/assets/{isDiffPlainText-BwicHPpI.js → isDiffPlainText-C1F9opE5.js} +1 -1
  48. package/dist/assets/{isFilePlainText-Dk2R7BJo.js → isFilePlainText-B4SyJ-ni.js} +1 -1
  49. package/dist/assets/{ja-evNvJAHz.js → ja-iJr8aONy.js} +2 -2
  50. package/dist/assets/{katex-CMY-1eWf.css → katex-BEX7X_K8.css} +1 -1
  51. package/dist/assets/{katex.min-Iw9WSgM9.js → katex.min-C-51hS9A.js} +18 -18
  52. package/dist/assets/{ko-BPQP7lXe.js → ko-D5ow_yz-.js} +2 -2
  53. package/dist/assets/main-BtGnuno4.js +1048 -0
  54. package/dist/assets/main-uj5954n5.js +2 -0
  55. package/dist/assets/markdownCore-rBXCnAJp.js +9 -0
  56. package/dist/assets/miniChat-yWQmT2OS.js +2 -0
  57. package/dist/assets/mobile-NDAeGtzL.js +2 -0
  58. package/dist/assets/{moveWorkspacePath-B31RGdgu.js → moveWorkspacePath-BINgpJ9S.js} +1 -1
  59. package/dist/assets/{nl-CkQXd1nU.js → nl-CfqYrSVe.js} +2 -2
  60. package/dist/assets/{parseDiffFromFile-DcsKSY0J.js → parseDiffFromFile--DE4eHIp.js} +2 -2
  61. package/dist/assets/{patchFileDiff-Cx-HpjyI.js → patchFileDiff-BfFUmWgS.js} +1 -1
  62. package/dist/assets/pierreDiffTint-D9K6_CVD.js +29 -0
  63. package/dist/assets/{pl-C4i9Aizi.js → pl-Bn2_jAhL.js} +4 -4
  64. package/dist/assets/{pt-BR-CoYnG1CH.js → pt-BR-ZSDgn6cI.js} +2 -2
  65. package/dist/assets/relocateRestoredSession-C85Tk2y9.js +1 -0
  66. package/dist/assets/renderElectronMiniChatApp-BvAEmWhZ.js +2 -0
  67. package/dist/assets/{renderMobileApp-gDKxRJQi.js → renderMobileApp-T20l8ise.js} +7 -7
  68. package/dist/assets/{restartOpenCode-dq-SGun3.js → restartOpenCode-VEmIrLer.js} +1 -1
  69. package/dist/assets/runtimeEndpointReset-ExJsaWzA.js +55 -0
  70. package/dist/assets/scheduledTasksApi-NSyxVfHu.js +1 -0
  71. package/dist/assets/{selectionMarkdown-sDTBbKLh.js → selectionMarkdown-BJ2RhTXc.js} +2 -2
  72. package/dist/assets/{sessionOwnership-kZAtwMQd.js → sessionOwnership-BAX1xEJC.js} +1 -1
  73. package/dist/assets/{shikiHighlight-BRNXPlF-.js → shikiHighlight-DOzrE7BE.js} +1 -1
  74. package/dist/assets/{space-apply-CCOKLfrX.js → space-apply-DB_ZfJBW.js} +1 -1
  75. package/dist/assets/space-close-1kNlTkW1.js +1 -0
  76. package/dist/assets/{spaceNetwork-DUxJClu3.js → spaceNetwork-DA16ov_y.js} +1 -1
  77. package/dist/assets/{textMateThemeFromAppTheme-B6UJwdZz.js → textMateThemeFromAppTheme-BfIrjFAU.js} +1 -1
  78. package/dist/assets/{tr-D-_lz-lC.js → tr-C89uz1hs.js} +2 -2
  79. package/dist/assets/{uk-B49PGMYB.js → uk-uTYVPFrO.js} +2 -2
  80. package/dist/assets/{useAppFontEffects-3EN8Ava3.js → useAppFontEffects-C1ceAD51.js} +185 -185
  81. package/dist/assets/useCallableModelProviders-BkLsgs6y.js +1 -0
  82. package/dist/assets/{useInlineCommentController-l9cWyfuR.js → useInlineCommentController-ynkUsoVA.js} +1 -1
  83. package/dist/assets/{useRootScrollLock-UAQn24Y8.js → useRootScrollLock-DnoKH1HE.js} +2 -2
  84. package/dist/assets/{vendor-codemirror-autocomplete-C8FBSI9t.js → vendor-codemirror-autocomplete-BRKmCSiY.js} +1 -1
  85. package/dist/assets/{vendor-codemirror-commands-BhRb6jns.js → vendor-codemirror-commands-MmBpgSOc.js} +1 -1
  86. package/dist/assets/vendor-codemirror-lang-angular-Bj5Pk8sp.js +1 -0
  87. package/dist/assets/vendor-codemirror-lang-cpp-tZt-BOgi.js +1 -0
  88. package/dist/assets/vendor-codemirror-lang-css-DfdrZ848.js +1 -0
  89. package/dist/assets/{vendor-codemirror-lang-go-BHJEONih.js → vendor-codemirror-lang-go-C9OcoXdP.js} +2 -2
  90. package/dist/assets/vendor-codemirror-lang-html-C5kFuJzc.js +1 -0
  91. package/dist/assets/vendor-codemirror-lang-java-Divn2dnj.js +1 -0
  92. package/dist/assets/{vendor-codemirror-lang-javascript-CUmSxayT.js → vendor-codemirror-lang-javascript-DmPuKUEa.js} +2 -2
  93. package/dist/assets/vendor-codemirror-lang-jinja-B-8miA-Q.js +1 -0
  94. package/dist/assets/vendor-codemirror-lang-json-L0wsFFxi.js +1 -0
  95. package/dist/assets/vendor-codemirror-lang-less-CWlCIxCI.js +1 -0
  96. package/dist/assets/vendor-codemirror-lang-liquid-Dm8xthAW.js +1 -0
  97. package/dist/assets/vendor-codemirror-lang-markdown-CPn-qinN.js +1 -0
  98. package/dist/assets/vendor-codemirror-lang-php-DKIOifjN.js +1 -0
  99. package/dist/assets/vendor-codemirror-lang-python-BAVa3Hg5.js +3 -0
  100. package/dist/assets/vendor-codemirror-lang-rust-Dab90hdg.js +1 -0
  101. package/dist/assets/vendor-codemirror-lang-sass-eezaHFBZ.js +1 -0
  102. package/dist/assets/{vendor-codemirror-lang-sql-C1Jj9uuJ.js → vendor-codemirror-lang-sql-Vu-PR7cv.js} +2 -2
  103. package/dist/assets/vendor-codemirror-lang-vue-BthRGZHy.js +1 -0
  104. package/dist/assets/vendor-codemirror-lang-wast-Db6KSic0.js +1 -0
  105. package/dist/assets/vendor-codemirror-lang-xml-DQkh4sc1.js +1 -0
  106. package/dist/assets/vendor-codemirror-lang-yaml-Bt2N__AW.js +1 -0
  107. package/dist/assets/vendor-codemirror-language-DkBxRck3.js +3 -0
  108. package/dist/assets/vendor-codemirror-language-data-CTYHXywt.js +2 -0
  109. package/dist/assets/{vendor-codemirror-search-CvXM_pZg.js → vendor-codemirror-search-BKAwkhkm.js} +1 -1
  110. package/dist/assets/vendor-codemirror-streamparser-CmlTsbN2.js +1 -0
  111. package/dist/assets/vendor-codemirror-view-B66jUSmE.js +4 -0
  112. package/dist/assets/{vendor-replit-codemirror-vim-Ck2X_WZC.js → vendor-replit-codemirror-vim-D0bqFa1D.js} +5 -5
  113. package/dist/assets/{worker-DdhrXE7g.js → worker-BbEdJ2Oi.js} +18 -18
  114. package/dist/assets/workerFactory-Bw5qLmrM.js +1 -0
  115. package/dist/assets/{zh-CN-CS-9Os9n.js → zh-CN-DdTNG52a.js} +2 -2
  116. package/dist/assets/{zh-TW-D0XYVdcl.js → zh-TW-DPm_33Fi.js} +2 -2
  117. package/dist/index.html +3 -3
  118. package/dist/mini-chat.html +3 -3
  119. package/dist/mobile.html +3 -3
  120. package/package.json +2 -2
  121. package/server/index.js +4 -0
  122. package/server/lib/environment/store.js +3 -4
  123. package/server/lib/environment/store.test.js +17 -0
  124. package/server/lib/fs/DOCUMENTATION.md +4 -2
  125. package/server/lib/fs/routes.js +48 -13
  126. package/server/lib/fs/routes.test.js +118 -5
  127. package/server/lib/git/DOCUMENTATION.md +3 -1
  128. package/server/lib/git/contributor-remote.js +4 -0
  129. package/server/lib/git/contributor-remote.test.js +21 -0
  130. package/server/lib/git/service.js +20 -25
  131. package/server/lib/git/service.test.js +99 -0
  132. package/server/lib/git/worktree-creation.js +4 -5
  133. package/server/lib/github/DOCUMENTATION.md +1 -1
  134. package/server/lib/github/routes.auth.test.js +14 -0
  135. package/server/lib/github/routes.js +13 -5
  136. package/server/lib/github/routes.mutations.test.js +18 -2
  137. package/server/lib/message-queue/DOCUMENTATION.md +8 -2
  138. package/server/lib/message-queue/runtime.js +3 -2
  139. package/server/lib/message-queue/runtime.test.js +64 -2
  140. package/server/lib/openchamber-control/service.js +48 -13
  141. package/server/lib/openchamber-control/service.test.js +42 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +3 -1
  143. package/server/lib/opencode/project-start-command.d.ts +11 -0
  144. package/server/lib/opencode/project-start-command.js +56 -0
  145. package/server/lib/opencode/project-start-command.test.js +80 -0
  146. package/server/lib/opencode/session-activity.js +43 -3
  147. package/server/lib/opencode/session-activity.test.js +97 -0
  148. package/server/lib/opencode/settings-runtime.js +19 -1
  149. package/server/lib/opencode/settings-runtime.test.js +23 -0
  150. package/server/lib/opencode/skill-routes.js +34 -1
  151. package/server/lib/opencode/skill-routes.test.js +99 -0
  152. package/server/lib/quota/DOCUMENTATION.md +13 -1
  153. package/server/lib/quota/providers/antigravity/api.js +104 -0
  154. package/server/lib/quota/providers/antigravity/auth.js +45 -0
  155. package/server/lib/quota/providers/antigravity/index.js +76 -0
  156. package/server/lib/quota/providers/antigravity/transforms.js +168 -0
  157. package/server/lib/quota/providers/antigravity/transforms.test.js +162 -0
  158. package/server/lib/quota/providers/codex.js +28 -4
  159. package/server/lib/quota/providers/codex.test.js +29 -0
  160. package/server/lib/quota/providers/google/auth.js +4 -49
  161. package/server/lib/quota/providers/google/transforms.js +3 -22
  162. package/server/lib/quota/providers/index.js +8 -0
  163. package/server/lib/quota/providers/opencode-go.js +3 -1
  164. package/server/lib/quota/providers/opencode-go.test.js +12 -0
  165. package/server/lib/routing/DOCUMENTATION.md +3 -1
  166. package/server/lib/routing/runtime.js +34 -1
  167. package/server/lib/routing/runtime.test.js +43 -1
  168. package/server/lib/scheduled-tasks/DOCUMENTATION.md +11 -0
  169. package/server/lib/scheduled-tasks/existing-session.js +52 -8
  170. package/server/lib/scheduled-tasks/existing-session.test.js +121 -0
  171. package/server/lib/scheduled-tasks/routes.js +26 -0
  172. package/server/lib/scheduled-tasks/runtime.js +1 -0
  173. package/server/lib/session-assist/runtime.js +3 -0
  174. package/server/lib/session-assist/runtime.test.js +47 -0
  175. package/server/lib/skills-catalog/DOCUMENTATION.md +10 -1
  176. package/server/lib/skills-catalog/install.js +1 -1
  177. package/server/lib/skills-catalog/installed-sources.d.ts +17 -0
  178. package/server/lib/skills-catalog/installed-sources.js +112 -0
  179. package/server/lib/skills-catalog/installed-sources.test.js +94 -0
  180. package/server/lib/small-model/DOCUMENTATION.md +12 -5
  181. package/server/lib/small-model/index.js +6 -4
  182. package/server/lib/small-model/index.test.js +40 -0
  183. package/server/lib/small-model/routes.js +3 -2
  184. package/server/lib/source-control/change-request-worktree.js +2 -6
  185. package/server/lib/source-control/mutation-storage.js +4 -1
  186. package/server/lib/source-control/mutation-storage.test.js +21 -0
  187. package/server/lib/spaces/DOCUMENTATION.md +1 -1
  188. package/server/lib/spaces/journey.js +10 -3
  189. package/server/lib/spaces/journey.test.js +13 -1
  190. package/server/lib/terminal/history.js +22 -2
  191. package/server/lib/terminal/history.test.js +23 -0
  192. package/server/lib/terminal/theme-response.js +14 -0
  193. package/server/lib/terminal/theme-response.test.js +10 -0
  194. package/dist/assets/AboutDialog-e8ek_kPI.js +0 -1
  195. package/dist/assets/ArchiveView-CjF4_TFg.js +0 -1
  196. package/dist/assets/GuestSurfacePane-4kmEXPLD.js +0 -1
  197. package/dist/assets/HelpDialog-CITMqPDK.js +0 -1
  198. package/dist/assets/JsonTreeView-xGikhCtL.js +0 -1
  199. package/dist/assets/MarkdownImageGallery-D0FJyr7C.js +0 -1
  200. package/dist/assets/MarkdownRendererImpl-BIM7Pjwk.js +0 -1
  201. package/dist/assets/MemoryDebugPanel-CBk8QW-M.js +0 -1
  202. package/dist/assets/OnboardingScreen-Cy6ARiMS.js +0 -1
  203. package/dist/assets/OpenCodeStatusDialog-YMHuJzwt.js +0 -1
  204. package/dist/assets/RunOverview-CHkGSW1x.js +0 -2
  205. package/dist/assets/ScheduledTasksDialog-77SO8zdJ.js +0 -4
  206. package/dist/assets/SettingsWindow-X74FIkdo.js +0 -1
  207. package/dist/assets/SourceBoardView-Cff2ejOW.js +0 -1
  208. package/dist/assets/SpaceAccessDialog-BXMZNRei.js +0 -1
  209. package/dist/assets/SpaceApplyDialog-BEJd2ryu.js +0 -1
  210. package/dist/assets/SpaceSetupOutput-Cb3XcIII.js +0 -1
  211. package/dist/assets/SpacesView-I3HaRKtW.js +0 -1
  212. package/dist/assets/UsageStatsView-DwTt9zIz.js +0 -1
  213. package/dist/assets/WorktreesView-Bh7GLvrR.js +0 -1
  214. package/dist/assets/appThemeRegistry-Bzb67M9O.js +0 -1
  215. package/dist/assets/computeVirtualFileMetrics-WAp98Bb7.js +0 -3
  216. package/dist/assets/index-BsupKM40.js +0 -1
  217. package/dist/assets/main-C_QGhDBL.js +0 -1048
  218. package/dist/assets/main-pWZ7F_hy.js +0 -2
  219. package/dist/assets/markdownCore-6gz4uJDQ.js +0 -9
  220. package/dist/assets/miniChat-DnaTfdYh.js +0 -2
  221. package/dist/assets/mobile-C7DIJqP8.js +0 -2
  222. package/dist/assets/pierreDiffTint-B297eqF0.js +0 -28
  223. package/dist/assets/relocateRestoredSession-D3lujODj.js +0 -1
  224. package/dist/assets/renderElectronMiniChatApp-BF4hNe69.js +0 -2
  225. package/dist/assets/runtimeEndpointReset-D6Lxhk0S.js +0 -55
  226. package/dist/assets/scheduledTasksApi-DUbAMrjW.js +0 -1
  227. package/dist/assets/space-close-CWcWwH4_.js +0 -1
  228. package/dist/assets/useCallableModelProviders-BB9xkUzM.js +0 -1
  229. package/dist/assets/vendor-codemirror-lang-angular-BpYCRJSk.js +0 -1
  230. package/dist/assets/vendor-codemirror-lang-cpp-BI3uPyjT.js +0 -1
  231. package/dist/assets/vendor-codemirror-lang-css-B2_PZTBl.js +0 -1
  232. package/dist/assets/vendor-codemirror-lang-html-BpvvTxbZ.js +0 -1
  233. package/dist/assets/vendor-codemirror-lang-java-BM5LQZ4u.js +0 -1
  234. package/dist/assets/vendor-codemirror-lang-jinja-D8nLZQPK.js +0 -1
  235. package/dist/assets/vendor-codemirror-lang-json-VDxF27mO.js +0 -1
  236. package/dist/assets/vendor-codemirror-lang-less-BecU2BJP.js +0 -1
  237. package/dist/assets/vendor-codemirror-lang-liquid-DCw83Anh.js +0 -1
  238. package/dist/assets/vendor-codemirror-lang-markdown-CimQAQbQ.js +0 -1
  239. package/dist/assets/vendor-codemirror-lang-php-C5Kpnpyb.js +0 -1
  240. package/dist/assets/vendor-codemirror-lang-python-BFE1OJNx.js +0 -3
  241. package/dist/assets/vendor-codemirror-lang-rust-hqZDyGIJ.js +0 -1
  242. package/dist/assets/vendor-codemirror-lang-sass-CAZML-Jl.js +0 -1
  243. package/dist/assets/vendor-codemirror-lang-vue-BHOTXcKp.js +0 -1
  244. package/dist/assets/vendor-codemirror-lang-wast-DcCHfPUI.js +0 -1
  245. package/dist/assets/vendor-codemirror-lang-xml-BO_V-1wZ.js +0 -1
  246. package/dist/assets/vendor-codemirror-lang-yaml-CPimap_N.js +0 -1
  247. package/dist/assets/vendor-codemirror-language-BBADuAkg.js +0 -3
  248. package/dist/assets/vendor-codemirror-language-data-Cu5ZbrPm.js +0 -2
  249. package/dist/assets/vendor-codemirror-view-1e0FQ6Wn.js +0 -4
  250. package/dist/assets/workerFactory-De9YXIdE.js +0 -1
@@ -25,8 +25,21 @@ const findEscapeEnd = (input, start) => {
25
25
  return input.charCodeAt(cursor) >= 0x30 && input.charCodeAt(cursor) <= 0x7e ? cursor + 1 : start + 1;
26
26
  };
27
27
 
28
+ // All six control-string introducers: ESC, DCS, CSI, OSC, PM, and APC. Replay
29
+ // history has to notice every one, or a C1 query byte leaks into the replay.
30
+ const isControlIntroducer = (code) => code === 0x1b || code === 0x90 || code === 0x9b || code === 0x9d || code === 0x9e || code === 0x9f;
31
+ const findControlIntroducer = (input, start) => {
32
+ for (let cursor = start; cursor < input.length; cursor += 1) {
33
+ if (isControlIntroducer(input.charCodeAt(cursor))) return cursor;
34
+ }
35
+ return -1;
36
+ };
37
+
28
38
  export const sanitizeTerminalHistoryChunk = (pending, data) => {
29
39
  const input = `${pending}${data}`;
40
+ // With no carried state and no introducer anywhere, the chunk is ordinary
41
+ // text and replay-safe as it stands; hand it back instead of rebuilding it.
42
+ if (!pending && findControlIntroducer(input, 0) === -1) return { visible: input, pending: '' };
30
43
  let visible = '';
31
44
  let index = 0;
32
45
  while (index < input.length) {
@@ -76,8 +89,15 @@ export const sanitizeTerminalHistoryChunk = (pending, data) => {
76
89
  index = end;
77
90
  continue;
78
91
  }
79
- visible += input[index];
80
- index += 1;
92
+ // Ordinary text: copy the whole run up to the next introducer in one
93
+ // slice instead of appending one character at a time.
94
+ const runEnd = findControlIntroducer(input, index + 1);
95
+ if (runEnd === -1) {
96
+ visible += input.slice(index);
97
+ break;
98
+ }
99
+ visible += input.slice(index, runEnd);
100
+ index = runEnd;
81
101
  }
82
102
  return { visible, pending: '' };
83
103
  };
@@ -16,4 +16,27 @@ describe('terminal replay history', () => {
16
16
  it('preserves ordinary OSC titles and split UTF-16 text', () => {
17
17
  expect(sanitizeTerminalHistoryChunk('', '\u001b]0;title\u0007ok')).toEqual({ visible: '\u001b]0;title\u0007ok', pending: '' });
18
18
  });
19
+
20
+ it('passes a clean chunk of ordinary text through unchanged', () => {
21
+ const line = 'build result source/file.ts 0123456789\r\n';
22
+ expect(sanitizeTerminalHistoryChunk('', line)).toEqual({ visible: line, pending: '' });
23
+ });
24
+
25
+ it('keeps ordinary runs between display controls in one piece', () => {
26
+ const input = 'line1\r\n\u001b[1mbold\u001b[0m\r\nline2 tail';
27
+ expect(sanitizeTerminalHistoryChunk('', input)).toEqual({ visible: input, pending: '' });
28
+ });
29
+
30
+ it('strips C1 device queries and keeps C1 string controls', () => {
31
+ expect(sanitizeTerminalHistoryChunk('', 'a\u009b6nb')).toEqual({ visible: 'ab', pending: '' });
32
+ expect(sanitizeTerminalHistoryChunk('', 'x\u009d10;?\u009cy\u009d0;title\u009cz')).toEqual({
33
+ visible: 'xy\u009d0;title\u009cz',
34
+ pending: '',
35
+ });
36
+ });
37
+
38
+ it('keeps DCS and APC string controls in the replay text', () => {
39
+ const input = 'a\u00901;2|data\u009cb\u001b[_apc\u0007c';
40
+ expect(sanitizeTerminalHistoryChunk('', input)).toEqual({ visible: input, pending: '' });
41
+ });
19
42
  });
@@ -38,6 +38,13 @@ const colorReport = (code, color) => {
38
38
 
39
39
  export const terminalThemeModeReport = (themeMode) => `\u001b[?997;${themeMode === 'light' ? 2 : 1}n`;
40
40
 
41
+ const findEscape = (input, start) => {
42
+ for (let cursor = start; cursor < input.length; cursor += 1) {
43
+ if (input.charCodeAt(cursor) === 0x1b) return cursor;
44
+ }
45
+ return -1;
46
+ };
47
+
41
48
  export const consumeTerminalThemeQueries = (
42
49
  pending,
43
50
  data,
@@ -50,6 +57,13 @@ export const consumeTerminalThemeQueries = (
50
57
  let modeEnabled = appearance.modeEnabled === true;
51
58
 
52
59
  for (let index = 0; index < input.length; index += 1) {
60
+ // Every recognized query begins with ESC, so ordinary text between
61
+ // escapes is skipped in one scan instead of tested per character.
62
+ if (input.charCodeAt(index) !== 0x1b) {
63
+ const nextEscape = findEscape(input, index);
64
+ if (nextEscape === -1) break;
65
+ index = nextEscape;
66
+ }
53
67
  if (input.startsWith(MODE_SET, index)) {
54
68
  modeEnabled = true;
55
69
  index += MODE_SET.length - 1;
@@ -67,4 +67,14 @@ describe('terminal theme responses', () => {
67
67
  expect(first.pending).toBe('\u001b[0');
68
68
  expect(second.responses).toEqual(['\u001b[?1;2c']);
69
69
  });
70
+
71
+ test('answers no query inside ordinary colored log text', () => {
72
+ const result = consumeTerminalThemeQueries('', 'log \u001b[32mgreen\u001b[0m done', lightAppearance);
73
+ expect(result).toEqual({ pending: '', responses: [], modeEnabled: false });
74
+ });
75
+
76
+ test('finds a query that follows ordinary text', () => {
77
+ const result = consumeTerminalThemeQueries('', 'ordinary output \u001b[?996n trailing text', lightAppearance);
78
+ expect(result).toEqual({ pending: '', responses: ['\u001b[?997;2n'], modeEnabled: false });
79
+ });
70
80
  });
@@ -1 +0,0 @@
1
- import{R as t,j as e}from"./vendor-react-BUCujlKS.js";import{u as w,t as v,q as D,a7 as C,I as m,a8 as k}from"./useAppFontEffects-3EN8Ava3.js";import{l as h}from"./katex.min-Iw9WSgM9.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-CVhJ1Zpv.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.js";const f="\0",it=({open:s,onOpenChange:u})=>{const{t:a}=w(),c=!1,[g,l]=t.useState(void 0),[x,j]=t.useState(void 0),[b,S]=t.useState(!1),[_,R]=t.useState(!1),[y,N]=t.useState(null),[O,V]=t.useState(!1);t.useCallback(async()=>{},[y,b,c,a]),t.useEffect(()=>{if(!s)return;let r=!1;return(async()=>{try{const o=await h("/api/system/info");if(o.ok){const n=await o.json();if(typeof n.openchamberVersion=="string"&&n.openchamberVersion.trim()){r||l(n.openchamberVersion);return}}}catch{}const i=await k().catch(()=>null);r||l(i)})(),()=>{r=!0}},[s]),t.useEffect(()=>{if(!s)return;let r=!1;return(async()=>{let i="";try{const o=await h("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(o.ok){const n=await o.json().catch(()=>null);i=typeof n?.currentVersion=="string"?n.currentVersion.trim():""}}catch{}r||j(i||null)})(),()=>{r=!0}},[s]),t.useEffect(()=>{{N(null),V(!1);return}},[s,c]);const d=(r,p)=>{if(p!==void 0)return e.jsx("p",{children:a(r,{version:p??a("settings.openchamber.about.state.unknown")})});const[i,o=""]=a(r,{version:f}).split(f);return e.jsxs("p",{className:"flex items-center justify-center",children:[e.jsx("span",{className:"whitespace-pre",children:i}),e.jsx(m,{name:"loader",className:"size-3.5 animate-spin"}),e.jsx("span",{className:"whitespace-pre",children:o})]})};return e.jsx(v,{open:s,onOpenChange:u,children:e.jsx(D,{className:"max-w-xs p-6",children:e.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[e.jsx(C,{width:64,height:64}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),e.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[d("aboutDialog.openChamberVersionLabel",g),d("aboutDialog.openCodeVersionLabel",x)]})]}),c,e.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-center gap-4",children:[e.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(m,{name:"github-fill",className:"h-4 w-4"}),e.jsx("span",{children:"GitHub"})]}),e.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(m,{name:"discord-fill",className:"h-4 w-4"}),e.jsx("span",{children:"Discord"})]})]}),e.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(m,{name:"twitter-xfill",className:"h-4 w-4"}),e.jsx("span",{children:"@openchamber_dev"})]})]}),e.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:a("aboutDialog.footerNote")})]})})})};export{it as AboutDialog};
@@ -1 +0,0 @@
1
- import{f as Me,R as ge,j as s}from"./vendor-react-BUCujlKS.js";import{u as qe,F as Oe,G as Qe,H as Ue,J as ye,K as Ke,L as ze,N as Te,B as $e,I as ee,O as Be,P as He,Q as Je,z as Ge,T as We,U as Ze,V as Fe}from"./useAppFontEffects-3EN8Ava3.js";import{e as Xe,n as be,u as je}from"./katex.min-Iw9WSgM9.js";import{u as Ye}from"./vendor-zustand-BAGL70zf.js";import{S as et}from"./runtimeEndpointReset-D6Lxhk0S.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-CVhJ1Zpv.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.js";const Se=100;function tt(i){const e=Me.c(133),{layout:h,onLeave:g,initialQuery:_}=i,A=_===void 0?"":_,{t}=qe(),x=Oe(dt),F=Oe(ft),Ne=Xe(ut),we=Qe(Ye(pt)),y=Qe(mt),[S,Re]=ge.useState(A),[m,Ve]=ge.useState(null),[Pe,De]=ge.useState(Se),v=Ue(ct);let te;e[0]===Symbol.for("react.memo_cache_sentinel")?(te=[],e[0]=te):te=e[0],ge.useEffect(lt,te);let se;e[1]!==Ne||e[2]!==v||e[3]!==t?(se=l=>{const a=v?.get(l);return a?a.name:l?Je(l,Ne)||l:t("sessions.archivePage.otherProjects")},e[1]=Ne,e[2]=v,e[3]=t,e[4]=se):se=e[4];const k=se;let ie;e[5]!==S?(ie=S.trim().toLowerCase(),e[5]=S,e[6]=ie):ie=e[6];const c=ie;let re;e[7]!==we?(re=we.filter(nt).sort(ot),e[7]=we,e[8]=re):re=e[8];const p=re;let oe;if(e[9]!==k||e[10]!==p||e[11]!==v){const l=new Map;for(const a of p){const n=be(ye(a))??"",u=l.get(n);if(u){u.sessions.push(a);continue}l.set(n,{directory:n,label:k(n),sessions:[a],fromDeletedSpace:v?.has(n)??!1})}oe=[...l.values()].sort(rt),e[9]=k,e[10]=p,e[11]=v,e[12]=oe}else oe=e[12];const N=oe;let X;e:{if(c){if(c.startsWith("ses_")){let n;if(e[13]!==c||e[14]!==p){let u;e[16]!==c?(u=le=>le.id.toLowerCase()===c,e[16]=c,e[17]=u):u=e[17],n=p.filter(u),e[13]=c,e[14]=p,e[15]=n}else n=e[15];X=n;break e}let a;e[18]!==c||e[19]!==p?(a=Ke(p,c,it),e[18]=c,e[19]=p,e[20]=a):a=e[20],X=a;break e}if(m===null){X=p;break e}let l;e[21]!==N||e[22]!==m?(l=N.find(a=>a.directory===m)?.sessions??[],e[21]=N,e[22]=m,e[23]=l):l=e[23],X=l}const b=X;let C,I,L,w,E,P,O,Q,z,T;if(e[24]!==N||e[25]!==b||e[26]!==k||e[27]!==h||e[28]!==c||e[29]!==g||e[30]!==S||e[31]!==m||e[32]!==y||e[33]!==x||e[34]!==p.length||e[35]!==v||e[36]!==t||e[37]!==F||e[38]!==Pe){Q=Symbol.for("react.early_return_sentinel");e:{const l=b.slice(0,Pe),a=b.length-l.length,n=p.length;let u;e[49]===Symbol.for("react.memo_cache_sentinel")?(u=r=>{Ve(r),De(Se)},e[49]=u):u=e[49];const le=u;let ae;e[50]!==g||e[51]!==x?(ae=r=>{const o=be(ye(r));x(r.id,o??void 0),g()},e[50]=g,e[51]=x,e[52]=ae):ae=e[52];const ke=ae;let ce;e[53]!==t||e[54]!==F?(ce=r=>{F(r.id).then(o=>{o?Ge.success(t("sessions.sidebar.session.restore.success")):Ge.error(t("sessions.sidebar.session.restore.error"))})},e[53]=t,e[54]=F,e[55]=ce):ce=e[55];const Ae=ce;let me;e[56]===Symbol.for("react.memo_cache_sentinel")?(me=r=>{Re(r),De(Se)},e[56]=me):me=e[56];const Ce=h==="mobile";let V;e[57]!==t?(V=t("sessions.archivePage.searchPlaceholder"),e[57]=t,e[58]=V):V=e[58];let q;e[59]!==t?(q=t("sessions.sidebar.header.search.clear"),e[59]=t,e[60]=q):q=e[60];let pe;e[61]!==S||e[62]!==Ce||e[63]!==V||e[64]!==q?(pe=s.jsx(et,{value:S,onSearch:me,mobile:Ce,placeholder:V,clearLabel:q}),e[61]=S,e[62]=Ce,e[63]=V,e[64]=q,e[65]=pe):pe=e[65];const U=pe;let ue;e[66]!==b.length||e[67]!==t?(ue=b.length===1?t("sessions.archivePage.countSingle",{count:b.length}):t("sessions.archivePage.countPlural",{count:b.length}),e[66]=b.length,e[67]=t,e[68]=ue):ue=e[68];const K=ue;let fe;e[69]!==c||e[70]!==y||e[71]!==t||e[72]!==n?(fe=()=>t(n===0&&y==="error"?"sessions.sidebar.group.empty.loadFailed":n===0&&y!=="ready"?"sessions.sidebar.group.empty.loadingSessions":c?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived"),e[69]=c,e[70]=y,e[71]=t,e[72]=n,e[73]=fe):fe=e[73];const _e=fe;let $;e[74]!==_e?($=_e(),e[74]=_e,e[75]=$):$=e[75];let de;e[76]!==$?(de=s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:$})}),e[76]=$,e[77]=de):de=e[77];const Ie=de;let he;if(e[78]!==h||e[79]!==a||e[80]!==t?(he=a>0?s.jsx("button",{type:"button",onClick:()=>De(st),className:ze("flex items-center justify-start rounded-md text-start text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",h==="mobile"?"min-h-10 px-3 typography-micro":"mt-1 px-2 py-1 text-xs"),children:t("sessions.sidebar.group.showMore")}):null,e[78]=h,e[79]=a,e[80]=t,e[81]=he):he=e[81],C=he,h==="mobile"){let r;e[82]!==K||e[83]!==y||e[84]!==n?(r=n>0||y==="ready"?s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:K}):null,e[82]=K,e[83]=y,e[84]=n,e[85]=r):r=e[85];let o;e[86]!==U||e[87]!==r?(o=s.jsxs("div",{className:"shrink-0 space-y-1.5 px-3 pt-3",children:[U,r]}),e[86]=U,e[87]=r,e[88]=o):o=e[88];let j;e[89]===Symbol.for("react.memo_cache_sentinel")?(j={paddingBottom:"calc(0.5rem + var(--oc-safe-area-bottom, 0px))"},e[89]=j):j=e[89],Q=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[o,s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pt-1",style:j,children:[l.length===0?Ie:l.map(f=>{const d=be(ye(f))??"",ve=f.title||t("sessions.sidebar.session.untitled"),Y=!(v?.has(d)??!1);return s.jsxs("div",{className:"flex items-center pe-1.5",children:[s.jsx("button",{type:"button",className:"flex min-h-10 min-w-0 flex-1 items-center py-1 ps-4 pe-2 text-start focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:{touchAction:"manipulation"},onClick:()=>ke(f),children:s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{dir:"auto",className:"block truncate oc-ui-start-align typography-ui-label text-foreground",children:ve}),s.jsxs("span",{className:"flex items-center gap-2.5 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"block min-w-0 flex-1 truncate",children:k(d)}),s.jsx("span",{className:"shrink-0 tabular-nums",children:Te(f.time?.archived??f.time?.updated??f.time?.created??Date.now())})]})]})}),Y?s.jsx($e,{type:"button",variant:"ghost",size:"lg",className:"w-10 shrink-0 px-0 text-muted-foreground",onClick:()=>Ae(f),"aria-label":t("sessions.archivePage.restoreSessionAria",{title:ve}),style:{touchAction:"manipulation"},children:s.jsx(ee,{name:"inbox-unarchive",className:"size-5"})}):null]},f.id)}),C]})]});break e}let xe;e[90]!==t?(xe=(r,o,j,f,d,ve,Y,Le)=>{const Ee=Le===void 0?!1:Le;return s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:d,title:Ee?t("spaces.archive.groupTitle",{name:o}):ve,className:ze("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-start typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Y?"group-hover/dir:pe-8 group-focus-within/dir:pe-8":"",f?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[Ee?s.jsx(ee,{name:"box-3",className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:"min-w-0 flex-1 truncate",children:o}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:j})]}),Y?s.jsxs(We,{children:[s.jsx(Ze,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Be.requestDelete({sessions:Y,mode:"session"}),className:"absolute inset-e-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":t("sessions.archivePage.deleteProjectAria",{label:o}),children:s.jsx(ee,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(Fe,{side:"bottom",sideOffset:4,children:t("sessions.archivePage.deleteProject")})]}):null]},r)},e[90]=t,e[91]=xe):xe=e[91];const D=xe;O="absolute inset-0 z-10 flex flex-col bg-background",E="flex min-h-0 flex-1";let H;if(e[92]!==D||e[93]!==m||e[94]!==t||e[95]!==n){let r;e[97]===Symbol.for("react.memo_cache_sentinel")?(r=()=>le(null),e[97]=r):r=e[97],H=D("__all__",t("sessions.archivePage.allDirectories"),n,m===null,r),e[92]=D,e[93]=m,e[94]=t,e[95]=n,e[96]=H}else H=e[96];let J;if(e[98]!==N||e[99]!==D||e[100]!==m){let r;e[102]!==D||e[103]!==m?(r=o=>D(o.directory||"__none__",o.label,o.sessions.length,m===o.directory,()=>le(o.directory),o.directory||void 0,o.sessions,o.fromDeletedSpace),e[102]=D,e[103]=m,e[104]=r):r=e[104],J=N.map(r),e[98]=N,e[99]=D,e[100]=m,e[101]=J}else J=e[101];e[105]!==H||e[106]!==J?(P=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-e border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[H,J]})}),e[105]=H,e[106]=J,e[107]=P):P=e[107],L="flex min-w-0 flex-1 flex-col";let W;e[108]!==U?(W=s.jsx("div",{className:"min-w-0 flex-1",children:U}),e[108]=U,e[109]=W):W=e[109];let Z;e[110]!==K?(Z=s.jsx("span",{className:"flex h-8 flex-shrink-0 items-center self-start typography-micro text-muted-foreground",children:K}),e[110]=K,e[111]=Z):Z=e[111],e[112]!==W||e[113]!==Z?(w=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[W,Z]}),e[112]=W,e[113]=Z,e[114]=w):w=e[114],I="min-h-0 flex-1 overflow-y-auto px-6 py-3",z="mx-auto w-full max-w-3xl space-y-0.5",T=l.length===0?Ie:l.map(r=>{const o=be(ye(r))??"",j=o?k(o):null,f=!(v?.has(o)??!1);return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 ps-2 pe-2 transition-[padding] hover:bg-interactive-hover/40 hover:pe-14 focus-within:pe-14",onClick:()=>ke(r),role:"button",tabIndex:0,onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),ke(r))},children:[s.jsx("span",{dir:"auto",className:"min-w-0 flex-1 truncate oc-ui-start-align typography-ui-label text-foreground",children:r.title||t("sessions.sidebar.session.untitled")}),c&&j?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:o,children:j}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Te(r.time?.archived??r.time?.updated??r.time?.created??Date.now())}),f?s.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),Ae(r)},className:"absolute inset-e-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":t("sessions.archivePage.restoreSessionAria",{title:r.title||t("sessions.sidebar.session.untitled")}),children:s.jsx(ee,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}):null,s.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),Be.requestDelete({sessions:[r],mode:"session"})},className:"absolute inset-e-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":t("sessions.archivePage.deleteSessionAria",{title:r.title||t("sessions.sidebar.session.untitled")}),children:s.jsx(ee,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},r.id)})}e[24]=N,e[25]=b,e[26]=k,e[27]=h,e[28]=c,e[29]=g,e[30]=S,e[31]=m,e[32]=y,e[33]=x,e[34]=p.length,e[35]=v,e[36]=t,e[37]=F,e[38]=Pe,e[39]=C,e[40]=I,e[41]=L,e[42]=w,e[43]=E,e[44]=P,e[45]=O,e[46]=Q,e[47]=z,e[48]=T}else C=e[39],I=e[40],L=e[41],w=e[42],E=e[43],P=e[44],O=e[45],Q=e[46],z=e[47],T=e[48];if(Q!==Symbol.for("react.early_return_sentinel"))return Q;let B;e[115]!==C||e[116]!==z||e[117]!==T?(B=s.jsxs("div",{className:z,children:[T,C]}),e[115]=C,e[116]=z,e[117]=T,e[118]=B):B=e[118];let G;e[119]!==I||e[120]!==B?(G=s.jsx("div",{className:I,children:B}),e[119]=I,e[120]=B,e[121]=G):G=e[121];let M;e[122]!==L||e[123]!==w||e[124]!==G?(M=s.jsxs("div",{className:L,children:[w,G]}),e[122]=L,e[123]=w,e[124]=G,e[125]=M):M=e[125];let R;e[126]!==E||e[127]!==P||e[128]!==M?(R=s.jsxs("div",{className:E,children:[P,M]}),e[126]=E,e[127]=P,e[128]=M,e[129]=R):R=e[129];let ne;return e[130]!==O||e[131]!==R?(ne=s.jsx("div",{className:O,children:R}),e[130]=O,e[131]=R,e[132]=ne):ne=e[132],ne}function st(i){return i+Se}function it(i){return[i.title]}function rt(i,e){return e.sessions.length-i.sessions.length}function ot(i,e){return(e.time?.archived??0)-(i.time?.archived??0)}function nt(i){return!i.parentID}function lt(){He().catch(at)}function at(){}function ct(i){return i.byDirectory}function mt(i){return i.status}function pt(i){return i.archivedSessions}function ut(i){return i.homeDirectory}function ft(i){return i.unarchiveSession}function dt(i){return i.setCurrentSession}function Hs(){const i=Me.c(6),e=je(gt),h=je(vt),g=je(xt),_=je(ht);let A;i[0]!==_?(A=()=>_(!1),i[0]=_,i[1]=A):A=i[1];const t=A;if(!e)return null;let x;return i[2]!==h||i[3]!==t||i[4]!==g?(x=s.jsx(tt,{layout:"page",onLeave:t,initialQuery:h},g),i[2]=h,i[3]=t,i[4]=g,i[5]=x):x=i[5],x}function ht(i){return i.setArchivePageOpen}function xt(i){return i.archivePageOpenCount}function vt(i){return i.archivePageSearch}function gt(i){return i.isArchivePageOpen}export{tt as ArchiveSessionsView,Hs as ArchiveView};
@@ -1 +0,0 @@
1
- import{R as i,j as u}from"./vendor-react-BUCujlKS.js";import{bc as Q,u as _,bd as ee,be as te,L as S,B as L,ak as ne,bf as re,bg as q}from"./useAppFontEffects-3EN8Ava3.js";import{a6 as se,a5 as ie,a7 as oe,a0 as ce,a8 as ae}from"./katex.min-Iw9WSgM9.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-CVhJ1Zpv.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.js";const ue=1,le=8e3,de=6e4,he={refreshAuth:ie,clearUrlAuthToken:se,openSocket:s=>oe(ce().websocket(`/api/guests/${s}/surface/ws`)),isPaused:()=>document.visibilityState==="hidden"||!navigator.onLine,onWake:s=>(window.addEventListener("online",s),document.addEventListener("visibilitychange",s),()=>{window.removeEventListener("online",s),document.removeEventListener("visibilitychange",s)})};class pe{constructor(r,n,c=he){this.guestId=r,this.handlers=n,this.dependencies=c}socket=null;pendingFrame=null;reconnectTimer=null;wakeCleanup=null;failures=0;generation=0;disposed=!1;ended=!1;start(){this.handlers.onConnection({status:"connecting"}),this.connect()}dispose(){this.disposed=!0,this.generation+=1,this.cancelReconnect();const r=this.socket;if(this.socket=null,r)try{r.close()}catch{}}ack(r){this.send({type:"ack",seq:r})}sendInput(r){return r.length===0?!1:this.send({type:"input",events:r})}release(){this.send({type:"release"})}resize(r,n){this.send({type:"resize",width:r,height:n})}requestClipboard(r){this.send({type:"clipboard-read",id:r})}send(r){const n=this.socket;if(!n||n.readyState!==ue)return!1;try{return n.send(JSON.stringify(r)),!0}catch{return!1}}async connect(){if(this.disposed||this.ended)return;const r=this.generation;try{await this.dependencies.refreshAuth()}catch{this.scheduleReconnect();return}if(r!==this.generation||this.disposed)return;let n;try{n=this.dependencies.openSocket(this.guestId)}catch{this.scheduleReconnect();return}n.binaryType="arraybuffer",this.socket=n;let c=!1;n.onopen=()=>{this.socket===n&&(c=!0,this.failures=0,this.pendingFrame=null,this.handlers.onConnection({status:"open"}))},n.onmessage=p=>{this.socket===n&&this.handleMessage(p.data)},n.onerror=()=>{},n.onclose=()=>{this.socket===n&&(this.socket=null,this.pendingFrame=null,!(this.disposed||this.ended)&&(c||this.dependencies.clearUrlAuthToken(),this.scheduleReconnect()))}}handleMessage(r){if(r instanceof ArrayBuffer){const c=this.pendingFrame;if(this.pendingFrame=null,!c)return;this.handlers.onFrame({...c,bytes:r});return}let n;try{const c=Q.safeParse(JSON.parse(r));if(!c.success)return;n=c.data}catch{return}switch(n.type){case"hello":this.handlers.onViewer?.(n.viewerId);return;case"frame":this.pendingFrame={seq:n.seq,width:n.width,height:n.height,mime:n.mime,agentActive:n.agentActive},n.title&&(this.pendingFrame.title=n.title);return;case"control":this.handlers.onControl({controller:n.controller,mine:n.mine});return;case"resized":this.handlers.onResized?.({width:n.width,height:n.height});return;case"clipboard":this.handlers.onClipboard?.(n.id,n.text);return;case"error":this.handlers.onError?.(n.code,n.message);return;case"ended":this.ended=!0,this.cancelReconnect(),this.handlers.onConnection({status:"ended",reason:n.reason});return}}retry(){this.disposed||(this.ended=!1,this.failures=0,this.handlers.onConnection({status:"connecting"}),this.connect())}scheduleReconnect(){if(this.reconnectTimer||this.disposed||this.ended)return;this.failures+=1;const r=this.dependencies.isPaused()?de:Math.min(500*2**Math.min(this.failures-1,10),le);this.handlers.onConnection({status:"reconnecting",attempt:this.failures});const n=()=>{this.dependencies.isPaused()||(this.cancelReconnect(),this.connect())};this.wakeCleanup=this.dependencies.onWake(n),this.reconnectTimer=setTimeout(n,r)}cancelReconnect(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.wakeCleanup?.(),this.wakeCleanup=null}}const me=250,F=s=>({alt:s.altKey,ctrl:s.ctrlKey,meta:s.metaKey,shift:s.shiftKey}),fe=s=>(s.metaKey||s.ctrlKey)&&!s.altKey&&s.key.toLowerCase()==="c",ge=s=>(s.metaKey||s.ctrlKey)&&!s.altKey&&s.key.toLowerCase()==="v",$t=({mode:s})=>{const{t:r}=_(),n=ae(s),c=ee(t=>t.guests.find(e=>e.id===n)??null),p=c!==null&&te(c)&&c.service?.surface===!0,w=i.useRef(null),b=i.useRef(null),l=i.useRef(null),k=i.useRef(null),y=i.useRef([]),m=i.useRef(null),T=i.useRef(0),C=i.useRef(!1),R=i.useRef({controller:"none",mine:!1}),[d,U]=i.useState({status:"connecting"}),[h,W]=i.useState({controller:"none",mine:!1}),A=i.useCallback(t=>{R.current=t,W(t)},[]),[I,$]=i.useState(""),[V,X]=i.useState(!1),[f,K]=i.useState(!1),[M,j]=i.useState(!1),E=i.useCallback(async t=>{const e=b.current,o=l.current;if(!(!e||!o))try{const a=await createImageBitmap(new Blob([t.bytes],{type:t.mime}));(e.width!==t.width||e.height!==t.height)&&(e.width=t.width,e.height=t.height),e.getContext("2d")?.drawImage(a,0,0,t.width,t.height),a.close(),k.current={width:t.width,height:t.height},K(!0),$(t.title??""),X(t.agentActive)}catch{}finally{o.ack(t.seq)}},[]);i.useEffect(()=>{if(!p)return;let t=null;const e=new pe(n,{onViewer:o=>{t&&q(n,t),t=o,re(n,o)},onFrame:o=>{E(o)},onControl:A,onConnection:U,onClipboard:(o,a)=>{ne(a)}});return l.current=e,e.start(),()=>{t&&q(n,t),e.dispose(),l.current===e&&(l.current=null),m.current!==null&&cancelAnimationFrame(m.current),m.current=null,y.current=[],k.current=null,K(!1)}},[p,E,n,A]),i.useEffect(()=>{const t=w.current;if(!t||!p)return;let e=null;const o=new ResizeObserver(a=>{const g=a[0];if(!g)return;const{width:v,height:Z}=g.contentRect;e&&clearTimeout(e),e=setTimeout(()=>{e=null;const D=window.devicePixelRatio||1,z=Math.round(v*D),O=Math.round(Z*D);z>0&&O>0&&l.current?.resize(z,O)},me)});return o.observe(t),()=>{o.disconnect(),e&&clearTimeout(e)}},[p]);const x=i.useCallback(t=>{y.current.push(t),m.current===null&&(m.current=requestAnimationFrame(()=>{m.current=null;const e=y.current;y.current=[],l.current?.sendInput(e),C.current&&(C.current=!1,T.current+=1,l.current?.requestClipboard(`copy-${T.current}`))}))},[]),N=i.useCallback(t=>{const e=b.current,o=k.current;if(!e||!o)return null;const a=e.getBoundingClientRect();if(a.width===0||a.height===0)return null;const g=(t.clientX-a.left)/a.width*o.width,v=(t.clientY-a.top)/a.height*o.height;return{x:Math.round(g),y:Math.round(v)}},[]),P=t=>e=>{if(!f||t==="move"&&e.buttons===0&&!(R.current.controller==="user"&&R.current.mine))return;const o=N(e);o&&(t==="down"?(w.current?.focus(),e.currentTarget.setPointerCapture(e.pointerId)):t==="up"&&e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),e.preventDefault(),x({type:"pointer",action:t,x:o.x,y:o.y,button:t==="move"?-1:e.button,buttons:e.buttons,modifiers:F(e)}))},G=t=>{if(!f)return;const e=N(t);e&&(t.preventDefault(),x({type:"wheel",x:e.x,y:e.y,deltaX:t.deltaX,deltaY:t.deltaY,modifiers:F(t)}))},B=t=>e=>{f&&(ge(e)||(e.preventDefault(),e.stopPropagation(),t==="down"&&fe(e)&&(C.current=!0),x({type:"key",action:t,key:e.key,code:e.code,modifiers:F(e)})))},Y=t=>{if(!f)return;const e=t.clipboardData.getData("text/plain");t.preventDefault(),e&&x({type:"text",text:e})},H=()=>{l.current?.release()};if(!c)return null;if(!p)return u.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:r("contextPanel.surface.unavailable")});const J=d.status==="connecting"?"contextPanel.surface.status.connecting":d.status==="reconnecting"?"contextPanel.surface.status.reconnecting":d.status==="ended"?`contextPanel.surface.ended.${d.reason}`:h.controller==="user"?h.mine?"contextPanel.surface.status.youControl":"contextPanel.surface.status.otherControls":h.controller==="agent"||V?"contextPanel.surface.status.agentWorking":M?"contextPanel.surface.status.readyFocused":"contextPanel.surface.status.ready";return u.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-background)]",children:[u.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 border-b border-border px-3",children:[u.jsx("span",{className:"typography-meta min-w-0 flex-1 truncate text-foreground",title:I||c.name,children:I||c.name}),u.jsx("span",{className:S("typography-meta shrink-0 truncate",h.controller==="user"&&h.mine?"text-foreground":"text-muted-foreground"),"aria-live":"polite",children:r(J)}),h.controller==="user"&&h.mine?u.jsx(L,{size:"xs",variant:"outline",onClick:H,children:r("contextPanel.surface.handBack")}):null,d.status==="ended"?u.jsx(L,{size:"xs",variant:"outline",onClick:()=>l.current?.retry(),children:r("contextPanel.surface.retry")}):null]}),u.jsxs("div",{ref:w,tabIndex:0,role:"application","aria-label":r("contextPanel.surface.canvasAria",{name:c.name}),"data-terminal-owner":`surface:${n}`,className:S("relative flex min-h-0 flex-1 items-center justify-center overflow-hidden outline-none",M?"ring-1 ring-inset ring-[var(--interactive-selection-border)]":""),onFocus:()=>j(!0),onBlur:()=>j(!1),onKeyDown:B("down"),onKeyUp:B("up"),onPaste:Y,children:[u.jsx("canvas",{ref:b,className:S("max-h-full max-w-full",f?"block":"hidden",h.controller==="user"&&!h.mine?"cursor-not-allowed":"cursor-default"),onPointerDown:P("down"),onPointerMove:P("move"),onPointerUp:P("up"),onWheel:G,onContextMenu:t=>t.preventDefault()}),!f||d.status!=="open"?u.jsx("div",{className:"absolute inset-0 flex items-center justify-center px-6 text-center text-sm text-muted-foreground",children:r(d.status==="ended"?`contextPanel.surface.ended.${d.reason}`:d.status==="reconnecting"?"contextPanel.surface.status.reconnecting":"contextPanel.surface.status.connecting")}):null]})]})};export{$t as GuestSurfacePane};
@@ -1 +0,0 @@
1
- import{f as F,j as i,R as W}from"./vendor-react-BUCujlKS.js";import{u as B,ag as N,ah as M,ai as L,aj as P,I as R,t as U,q as V,l as G,E as J,D as Q,n as X}from"./useAppFontEffects-3EN8Ava3.js";import{u as A}from"./katex.min-Iw9WSgM9.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-CVhJ1Zpv.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.js";const $=(e,t,w)=>N(P(e,t),w),Ni=()=>{const e=F.c(47),{t}=B(),w=A(Y),T=A(Z),s=A(ee);let l,a,p,c,m,d,g,y,h,r,u,f;if(e[0]!==w||e[1]!==T||e[2]!==s||e[3]!==t){const q=[{categoryKey:"helpDialog.section.navigationCommands",column:"left",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[N("mod+shift+alt+n")],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",column:"right",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"open_draft_project_picker",icon:"folder",keys:""},{id:"open_draft_worktree_picker",icon:"git-branch",keys:""},{id:"open_session_list",icon:"list-unordered",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""},{id:"background_session_work",icon:"arrow-up-double",keys:""}]},{categoryKey:"helpDialog.section.panels",column:"right",items:[{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{keys:[`${N(M("switch_context_surface",s))} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"},{keys:[`${N(M("switch_session_tab",s))} + 1...9`],descriptionKey:"helpDialog.item.switchSessionTab",icon:"layout-right"}]},{categoryKey:"helpDialog.section.interface",column:"left",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"toggle_source_board",descriptionKey:"helpDialog.item.toggleSourceBoard",icon:"todo",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}],z=n=>i.jsxs("div",{children:[i.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:t(n.categoryKey)}),i.jsx("div",{className:"space-y-1",children:n.items.map(o=>{const H=o.id?L(o.id):void 0,C=o.descriptionKey??(H?.customizable?H.settingsLabelKey:void 0);if(!C||o.id&&!P(o.id,s))return null;const O=o.id?$(o.id,s,t("settings.openchamber.keyboardShortcuts.unassigned")):Array.isArray(o.keys)?o.keys:o.keys.split(" / ");return i.jsxs("div",{className:"flex items-center gap-3 py-1 px-2",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.icon&&i.jsx(R,{name:o.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"typography-meta",children:t(C)})]}),i.jsx("div",{"aria-hidden":!0,className:"min-w-4 flex-1 border-b border-dotted border-border"}),i.jsx("div",{className:"flex shrink-0 items-center gap-1",children:(Array.isArray(O)?O:[O]).map((E,I)=>i.jsxs(W.Fragment,{children:[I>0&&i.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:t("helpDialog.keyCombiner.or")}),i.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta bg-muted rounded border border-border/20",children:E})]},`${E}-${I}`))})]},o.id||C)})})]},n.categoryKey);p=U,u=w,f=T,a=V,h="max-w-6xl w-[min(72rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let S;e[16]===Symbol.for("react.memo_cache_sentinel")?(S=i.jsx(R,{name:"command",className:"h-5 w-5"}),e[16]=S):S=e[16];let D;e[17]!==t?(D=t("helpDialog.title"),e[17]=t,e[18]=D):D=e[18];let b;e[19]!==D?(b=i.jsxs(G,{className:"flex items-center gap-2",children:[S,D]}),e[19]=D,e[20]=b):b=e[20];let K;e[21]!==t?(K=t("helpDialog.description"),e[21]=t,e[22]=K):K=e[22];let j;e[23]!==K?(j=i.jsx(J,{children:K}),e[23]=K,e[24]=j):j=e[24],e[25]!==b||e[26]!==j?(r=i.jsxs(Q,{children:[b,j]}),e[25]=b,e[26]=j,e[27]=r):r=e[27],l=X,d="flex-1 min-h-0 mt-3",g="pe-1",y=!0,c="grid grid-cols-1 gap-x-12 gap-y-4 lg:grid-cols-2",m=["left","right"].map(n=>i.jsxs("div",{className:"space-y-4",children:[q.filter(o=>o.column===n).map(z),n==="right"&&i.jsxs("ul",{className:"space-y-0.5 px-2 typography-meta text-muted-foreground",children:[i.jsxs("li",{children:["• ",t("helpDialog.proTips.commandPalette",{shortcut:$("open_command_palette",s,t("settings.openchamber.keyboardShortcuts.unassigned"))})]}),i.jsxs("li",{children:["• ",t("helpDialog.proTips.recentSessions")]}),i.jsxs("li",{children:["• ",t("helpDialog.proTips.leaderSequences")]})]})]},n)),e[0]=w,e[1]=T,e[2]=s,e[3]=t,e[4]=l,e[5]=a,e[6]=p,e[7]=c,e[8]=m,e[9]=d,e[10]=g,e[11]=y,e[12]=h,e[13]=r,e[14]=u,e[15]=f}else l=e[4],a=e[5],p=e[6],c=e[7],m=e[8],d=e[9],g=e[10],y=e[11],h=e[12],r=e[13],u=e[14],f=e[15];let x;e[28]!==c||e[29]!==m?(x=i.jsx("div",{className:c,children:m}),e[28]=c,e[29]=m,e[30]=x):x=e[30];let _;e[31]!==l||e[32]!==d||e[33]!==g||e[34]!==y||e[35]!==x?(_=i.jsx(l,{outerClassName:d,className:g,disableHorizontal:y,children:x}),e[31]=l,e[32]=d,e[33]=g,e[34]=y,e[35]=x,e[36]=_):_=e[36];let k;e[37]!==a||e[38]!==_||e[39]!==h||e[40]!==r?(k=i.jsxs(a,{className:h,children:[r,_]}),e[37]=a,e[38]=_,e[39]=h,e[40]=r,e[41]=k):k=e[41];let v;return e[42]!==p||e[43]!==k||e[44]!==u||e[45]!==f?(v=i.jsx(p,{open:u,onOpenChange:f,children:k}),e[42]=p,e[43]=k,e[44]=u,e[45]=f,e[46]=v):v=e[46],v};function Y(e){return e.isHelpDialogOpen}function Z(e){return e.setHelpDialogOpen}function ee(e){return e.shortcutOverrides}export{Ni as HelpDialog};
@@ -1 +0,0 @@
1
- import{e6 as B,eD as ae,eE as Ie,dW as Te,eF as Ve,eG as Pe,eH as De,eI as _e,dX as Be,u as Ue,B as le,I as he,eJ as We}from"./useAppFontEffects-3EN8Ava3.js";import{g as F,b as Ge,c as Ae,i as je,s as we,e as Ke,f as de,h as $e,j as qe,k as Je,l as Ye,m as Xe,R as Qe,I as Ze,n as ce,r as et,o as ue,w as tt,t as it,u as nt,v as st,x as rt,y as ot,z as fe,A as at,B as lt,C as ht,D as dt,E as ct,F as ut,G as ge,S as ft,H as gt,J as pt,K as mt,a as He,L as St,M as Ct}from"./parseDiffFromFile-DcsKSY0J.js";import{c as R,G as vt,u as Rt,W as yt,a as Lt,b as W,n as pe,t as Tt}from"./Virtualizer-BP6uuKe_.js";import{j as v,r as b,R as I}from"./vendor-react-BUCujlKS.js";import{q as G,s as ie,g as Y,l as me,i as Ee,t as Se,u as At,w as Ce,k as xe,x as ve,a as wt,y as Ht,z as j,A as Re}from"./computeVirtualFileMetrics-WAp98Bb7.js";import{a as x,i as X,l as K,h as Et,r as xt}from"./isFilePlainText-Dk2R7BJo.js";import{t as V}from"./vendor-hast-util-to-html-BKBhbTDb.js";import"./katex.min-Iw9WSgM9.js";function $(i,e){return e.cacheKey==null?i.file===e&&i.sourceContents===e.contents:i.cacheKey===e.cacheKey}let bt=-1;var Mt=class{options;annotationSlotName;onRenderUpdate;workerManager;__id=`file-renderer:${++bt}`;highlighter;file;renderCache;pendingHighlightResult;computedLang="text";lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;get fileCache(){return this.renderCache?.file}constructor(i={theme:B},e=F,t,n){this.options=i,this.annotationSlotName=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=G(i.theme??B)?ie():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.endEditSession(),this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(i,e){const{editSessionActive:t,renderCache:n}=this;if(this.editSessionActive=!0,t||(this.pendingHighlightResult=void 0),this.file=i,n==null||t&&n.file===i)return;if(t){this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap;return}const{options:r}=this.getRenderOptions(i),s=n.file===i,o=e!=null&&R(n.file,e),{result:a}=n;if(!n.highlighted||a==null||!x(n.options,r)||!s&&!o){this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap;return}if(s)return;this.renderCache={...n,file:i,result:{...a,code:[...a.code]}};const{lineCache:l}=this;l!=null&&e!=null&&$(l,e)?this.lineCache={cacheKey:void 0,file:i,sourceContents:i.contents,lines:l.lines}:this.lineCache=void 0}endEditSession(i){if(this.editSessionActive=!1,this.pendingHighlightResult=void 0,this.file==null){this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap;return}const{renderCache:e}=this;i==null||e==null||e.file===i||!R(e.file,i)||(e.file=i)}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.editSessionActive?(this.renderCache!=null&&(this.renderCache.renderRange=void 0),this.pendingHighlightResult=void 0,this.pendingStructuralRows=void 0):(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.file=void 0}clearRenderCache(){this.pendingStructuralRows=void 0,this.renderCache=void 0,this.pendingHighlightResult=void 0}hydrate(i){this.file=i;const{options:e}=this.getRenderOptions(i),t=q(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!x(e,n.options)&&(n=void 0),this.renderCache??={file:i,hydrated:!0,options:e,highlighted:!t&&!X(i),result:t?void 0:n?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??Y(i.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??B}getEffectiveCodeOptions(){const i=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:i?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0){const r=this.workerManager.getFileRenderOptions();return this.editSessionActive&&r.useTokenTransformer!==!0?{...r,useTokenTransformer:!0}:r}const{tokenizeMaxLineLength:n=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:n}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!R(i,t.file)||!x(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getFileForNextRender(i){const{options:e}=this.getRenderOptions(i);if(this.getReadyRenderResult(i,e)!=null)return i;const{renderCache:t}=this;if(t==null)return i;if(R(t.file,i))return t.file;const n=K(i.contents),r=i.contents.length===0||X(i)||q(n.length,this.getTokenizeMaxLength());return this.canRenderFile(i,e,r)?i:t.file}canRenderFile(i,e,t){const{renderCache:n}=this;return n==null||R(n.file,i)?!0:t?n.result==null&&n.hydrated!==!0||this.workerManager?.isWorkingPool()===!0||this.highlighter!=null&&G(e.theme):n.result==null&&n.hydrated!==!0?!0:!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?!n.highlighted:this.highlighter!=null&&G(e.theme)}getOrCreateLineCache(i){let{lineCache:e}=this;return(e==null||!$(e,i))&&(e={cacheKey:i.cacheKey,file:i,sourceContents:i.contents,lines:K(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){const e=this.getOrCreateLineCache(i);return this.textDocumentCache.get(i)?.lineCount??e.length}updateRenderCache(i,e,t=!1){this.pendingStructuralRows=void 0;const{renderCache:n}=this;if(n==null)return;const{file:r,result:s}=n;if(s==null)return;const o=t?new Map:void 0;this.pendingStructuralRows=o;const a=this.lineCache!=null&&$(this.lineCache,r)?this.lineCache:void 0;for(const[l,h]of i){if(o==null&&a!=null&&l<a.lines.length){const u=h.map(d=>d[2]).join("");a.lines[l]=Ge(a.lines[l]??"",u)}const c={type:"element",tagName:"div",properties:{"data-line":l+1,"data-line-type":"context","data-line-index":l},children:h.map(([u,d,f])=>u===0&&d===""?f===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:f}:{type:"element",tagName:"span",properties:{"data-char":u,style:`color:${d};`},children:[{type:"text",value:f}]})};o!=null?o.set(l,c):s.code[l]=c}s.baseThemeType=e,n.isDirty=!0,o==null&&a!=null&&(r.contents=a.lines.join(""),a.sourceContents=r.contents)}applyDocumentChange(i){const{pendingStructuralRows:e,renderCache:t}=this;this.pendingStructuralRows=void 0;const n=this.file??t?.file;if(n==null)return;const r=t?.result,s=this.lineCache!=null&&$(this.lineCache,n)?this.lineCache.lines:K(n.contents),o=K(i.getText());if(r!=null&&s.length!==o.length){const l=Math.min(s.length,o.length);let h=0;for(;h<l&&s[h]===o[h];)h++;let c=0;for(;c<l-h&&s[s.length-1-c]===o[o.length-1-c];)c++;const u=r.code;r.code=new Array(o.length);for(let d=0;d<h;d++)r.code[d]=u[d];for(let d=0;d<c;d++)r.code[o.length-1-d]=u[s.length-1-d];if(e!==void 0)for(const[d,f]of e)d<o.length&&(r.code[d]=f);for(let d=h;d<o.length-c;d++)r.code[d]??={type:"element",tagName:"div",properties:{"data-line":d+1,"data-line-type":"context","data-line-index":d},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(d)}]}]};for(let d=0;d<r.code.length;d++){const f=r.code[d];f?.type==="element"&&(f.properties["data-line"]=d+1,f.properties["data-line-index"]=d)}t!=null&&(t.isDirty=!0)}const a=i.getText();this.lineCache={cacheKey:n.cacheKey,file:n,sourceContents:a,lines:o},this.textDocumentCache.set(n,i),n.contents=a}renderFile(i=this.file,e=ae){if(this.file=i,i==null){this.pendingHighlightResult=void 0;return}let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getReadyRenderResult(i,t);this.pendingHighlightResult=void 0,r!=null&&(this.renderCache={...r,file:i,renderRange:void 0},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),o=i.contents.length>0,a=!o||X(i)||q(s.length,this.getTokenizeMaxLength()),l=this.canRenderFile(i,t,a),h=!R(i,this.renderCache.file),c=!Ae(this.renderCache.renderRange,e);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!a&&!h&&je(e);l&&!u&&(a||this.renderCache.result==null||!this.renderCache.highlighted&&(h||c))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||c||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!a&&o&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i)}else{this.computedLang=i.lang??Y(i.name),this.highlighter??=ie();const u=this.highlighter!=null&&G(t.theme),d=this.highlighter!=null&&me(this.computedLang),f=!a&&d;if(l&&this.highlighter!=null&&u&&(n||a||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:m,options:g}=this.renderFileWithHighlighter(i,this.highlighter,a||!d);this.renderCache={file:i,options:g,highlighted:f,result:m,renderRange:void 0}}(!u||!a&&!d)&&this.asyncHighlight(i).then(({result:m,options:g})=>{this.applyHighlightResult(i,m,g,!a)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=ae){this.file=i;const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=q(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??Y(i.name);const t=this.highlighter!=null&&Et(Ee(this.getLocalHighlightTheme())),n=e||this.highlighter!=null&&me(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:xt(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:o=!1}=this.options,a=[],l=ve(),h=Math.min(e.startingLine+e.totalLines,s);let c=0;const u=we(e)?Ke(this.lineAnnotations):void 0;u!=null&&(l.children.push(Se("context","annotation",1)),a.push(de({hunkIndex:-1,lineIndex:-1,annotations:u.map(d=>this.annotationSlotName(d))})),c++);for(let d=e.startingLine;d<h;d++){const f=d+1,m=t[d];if(m==null){const S="FileRenderer.processFileResult: Line doesnt exist";throw console.error(S,{name:i.name,lineIndex:d,lineNumber:f}),new Error(S)}l.children.push(At("context",f,`${d}`)),a.push(m),c++;const g=this.lineAnnotations[f];g!=null&&(l.children.push(Se("context","annotation",1)),a.push(de({hunkIndex:0,lineIndex:f,annotations:g.map(S=>this.annotationSlotName(S))})),c++)}return l.properties.style=`grid-row: span ${c}`,{file:i,gutterAST:l.children??[],contentAST:a,preAST:this.createPreElement(s),headerAST:o?void 0:this.renderHeader(i),totalLines:s,rowCount:c,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return $e({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return V(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(Ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ve();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,qe(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?V(Ce({tagName:"code",children:i,properties:{"data-code":""}})):V(i)}async initializeHighlighter(){return this.highlighter=await xe(Je(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(i,e,t,n=!0){this.editSessionActive||this.applyHighlightResult(i,e,t,n)}applyHighlightResult(i,e,t,n=!0){const{file:r,renderCache:s}=this;r==null||s==null||!R(i,r)||!x(t,this.getRenderOptions(r).options)||(s.result==null||!s.highlighted||!x(s.options,t)||!R(s.file,r))&&(this.pendingHighlightResult={file:r,options:t,highlighted:n,result:e},this.onRenderUpdate?.())}getMatchingWorkerResultCache(i,e){if(this.editSessionActive)return;const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!x(e,t.options)))return t}getReadyRenderResult(i,e){const{pendingHighlightResult:t}=this;if(t!=null&&R(t.file,i)&&x(t.options,e))return t;const n=this.getMatchingWorkerResultCache(i,e);if(!(n==null||this.hasHighlightedRenderCache(i,e)))return{file:i,highlighted:!0,...n}}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&R(i,t.file)&&x(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return Ye({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function q(i,e){return i>e}function Ft(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ye(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:Xe(i),tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const kt=[""];function zt(i){const e={...i};return delete e.cacheKey,e}let Nt=-1;var be=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Nt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;editSession;renderedFile;renderRange;enabled=!0;editor;constructor(e={theme:B},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Mt(e,this.getAnnotationSlotName,this.handleHighlightRender,this.workerManager),this.resizeManager=new Qe,this.interactionManager=new Ze("file",ce(e)),this.workerManager?.subscribeToThemeChanges(this)}getAnnotationSlotName=e=>et(this.editSession?.annotations,e,F);handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}getTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??B}getLatestFile(e=this.file){return this.editSession?.file??e}getRenderedFile(){return this.renderedFile}getLatestAnnotations(){return this.editSession?.annotations?.current??this.lineAnnotations}isNewAnnotations(e){const t=this.editSession?.annotations;return e===this.lineAnnotations?!1:t==null||e!==t.provided&&e!==t.current}updateExternalFile(e,t){if(R(this.file,e))return!1;const n=this.editSession!=null;return this.file=e,n||this.editor!=null?this.installEditSession(e,n?void 0:this.editor?.__getDocumentContents(e),!0):this.editSession=void 0,this.editSession?.annotations!=null&&t!=null&&(this.lineAnnotations=t,this.editSession.annotations=ue(t,F,this.editSession.annotations)),!0}installEditSession(e,t,n=!1){const r=t==null||t.name===e.name&&t.lang===e.lang&&t.contents===e.contents,s=zt(t??e);this.editSession={file:s,externalReplacement:n&&r,annotations:this.editSession?.annotations??ue(this.lineAnnotations,F)},this.fileRenderer.beginEditSession(s,r?e:void 0)}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(ce(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!wt(this.appliedThemeCSS.theme,this.getTheme())}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){const t=this.editSession?.annotations;if(t==null){this.lineAnnotations=e;return}this.isNewAnnotations(e)&&(this.lineAnnotations=e,tt(t,e,F))}syncEditSessionAnnotationsFromEditor(e){const t=this.editSession?.annotations;return t==null||e===t.current?!1:(t.current=e,this.fileRenderer.setLineAnnotations(e),this.renderAnnotations(),!0)}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e==="wrap",columnVariables:this.shouldApplyColumnVariables(e)?"apply":"measure"}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e==="scroll"&&this.getLatestAnnotations().length>0}cleanUp(e=!1){const t=this.editor;this.emitPostRender(!0),t?.cleanUp(e?"recycle":"discard"),e||(this.editor=void 0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.pre=void 0,this.code=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0,this.editSession=void 0,this.renderedFile=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:o}=e;if(!this.enabled)throw new Error("File.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("File.hydrate: hydrate can only be called before the instance has rendered or hydrated");this.hydrateElements(t,n);const a=this.editor!=null;a||Ot(this.pre,s,this.options.collapsed)||It(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,forceRender:a||e.forceRender,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:o}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),it(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ye(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderedFile=e,this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.getLatestFile()){return e!=null?this.fileRenderer.getOrCreateLineCache(e):kt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const{editor:e,fileContainer:t,renderRange:n}=this,r=this.getLatestAnnotations(),s=this.getLatestFile();if(e==null||t==null||s==null)return;const o=c=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.getLatestFile()!==s||e.__syncRenderView({highlighter:c,fileContainer:t,file:s,lineAnnotations:r,renderRange:n,externalDocument:this.editSession?.externalReplacement===!0})},a=this.getTheme(),l=s.lang??Y(s.name),h=ie({theme:a,lang:l});h!=null?o(h):xe({themes:Ee(a),langs:Array.from(new Set(["text",l])),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter}).then(o)}__acknowledgeDocumentUpdate(){this.editSession!=null&&(this.editSession.externalReplacement=!1)}__acceptEditorChange(e){const{lineAnnotations:t}=e;t!=null&&this.syncEditSessionAnnotationsFromEditor(t)}emitEditChange(e){const{onEditChange:t}=this.options;t?.(e)}__captureDocumentSessionState(){}__attachEditor(e){if(this.editor!=null)throw new Error("File.__attachEditor: an editor is already attached");this.editor=e;const t=()=>{this.editor=void 0,this.fileRenderer.endEditSession()};try{return this.resumeEditorRendering(e),t}catch(n){throw t(),n}}__resumeEditor(e){if(this.editor!==e)throw new Error("File.__resumeEditor: editor association changed");this.resumeEditorRendering(e)}resumeEditorRendering(e){this.editSession!=null?this.fileRenderer.beginEditSession(this.editSession.file):this.file!=null&&this.installEditSession(this.file,e.__getDocumentContents(this.file));const t=this.editSession?.file;this.fileRenderer.editorRenderReady()?(this.fileRenderer.fileCache===t&&(this.renderedFile=t),this.syncRenderViewToEditor()):this.rerender()}__completeEditSession(e,t){this.settleEditSession(t==="install",e)}settleEditSession(e,t){const{editSession:n,file:r,lineAnnotations:s}=this;if(n==null||r==null)return;const{file:o,annotations:a}=n;if(this.editor!=null)throw new Error("File.__completeEditSession: detach the editor before completing the session");const l=a?.current;let h,c=!1,u;if(t==null)throw new Error("File.__completeEditSession: editor is required for completion");const d={...o},f={file:d,editor:t,originalFile:r,lineAnnotations:l,originalLineAnnotations:s};Object.freeze(f);try{if(t.__emitEditComplete(f),this.options.onEditComplete?.(f)==="accept"){if(d.cacheKey!=null&&d.cacheKey===r.cacheKey)throw new Error("File.__completeEditSession: an accepted file must not reuse the replaced file cacheKey");h=d}}catch(S){c=!0,u=S}e&&h!=null&&(this.file=h,l!=null&&(this.lineAnnotations=l)),this.editSession=void 0;const{renderedFile:m,file:g}=this;if(this.fileRenderer.endEditSession(g),m!=null&&g!=null&&m!==g&&R(m,g)&&(this.renderedFile=g),e&&this.fileContainer!=null&&this.rerender(),c)throw u}applyDocumentChange(e,t){const n=this.editSession?.file;if(n==null)throw new Error("File.applyDocumentChange: requires an active edit session");this.fileRenderer.beginEditSession(n),this.fileRenderer.applyDocumentChange(e),t!=null&&this.syncEditSessionAnnotationsFromEditor(t)}applySuspendedDocumentChange(e,t){this.editSession!=null&&(this.applyDocumentChange(e,t),this.fileRenderer.clearRenderCache())}updateRenderCache(e,t,n){const r=this.editSession?.file;if(r==null)throw new Error("File.updateRenderCache: requires an active edit session");this.fileRenderer.beginEditSession(r),this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:o=!1,lineAnnotations:a,renderRange:l}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:h=!1,themeType:c="system"}=this.options,u=h?void 0:l,d=this.renderRange,f=this.hasThemeChanged(),m=a!=null&&(a.length>0||this.getLatestAnnotations().length>0)?this.isNewAnnotations(a):!1,g=!R(this.file,e);g&&this.updateExternalFile(e,a);const S=this.getLatestFile(e)??e;if(!h&&!n&&Ae(u,this.renderRange)&&!g&&!m&&!f){const p=this.applyCachedThemeState(c);return p&&this.finalizeRender(),p}this.renderRange=u,g&&(this.cachedHeaderHTML=void 0),this.fileRenderer.setOptions(ye(this.options)),this.syncInteractionOptions(),a!=null&&this.setLineAnnotations(a),this.fileRenderer.setLineAnnotations(this.getLatestAnnotations());const{disableErrorHandling:H=!1,disableFileHeader:A=!1}=this.options;if(A&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(c),h){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const p=this.fileRenderer.renderFile(S,Ie);p!=null&&this.applyThemeState(t,p.themeStyles,c,p.baseThemeType),p?.headerAST!=null&&this.applyHeaderToDOM(p.headerAST,t,p.file),this.renderedFile=p?.file??S,this.injectUnsafeCSS()}catch(p){if(H)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return this.finalizeRender(),r||this.emitPostRender(),!0}try{const p=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,m,g||f||!R(this.renderedFile,S))||!this.applyPartialRender(S,d,u)){const y=this.fileRenderer.renderFile(S,u);if(y==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.isWorkingPool()&&this.workerManager.initialize().catch(()=>{}).then(()=>this.rerender()),!1;this.applyThemeState(t,y.themeStyles,c,y.baseThemeType),y.headerAST!=null&&this.applyHeaderToDOM(y.headerAST,t,y.file),this.applyFullRender(y,p),this.renderedFile=y.file}this.applyBuffers(p,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,o||this.flushManagers(),this.finalizeRender(),this.editor!=null&&this.syncRenderViewToEditor()}catch(p){if(H)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return r||this.emitPostRender(),!0}finalizeRender(){}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.setPlaceholderHeight(e)}setPlaceholderHeight(e){return this.placeHolder==null?!1:(this.placeHolder.style.setProperty("height",`${e}px`),!0)}async primeHighlightCache(e=this.file){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||X(e))return;const n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(r=>{console.error(r)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:r}of this.annotationCache.values())r.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options,n=this.getLatestAnnotations();if(t!=null&&n.length>0)for(const[r,s]of n.entries()){const o=this.getAnnotationSlotName(s),a=`${r}-${o}`;let l=this.annotationCache.get(a);if(l==null||!Ft(s,l.annotation)){l?.element.remove();const h=t(s);if(h==null)continue;l={element:nt(o),annotation:s},l.element.appendChild(h),this.fileContainer.appendChild(l.element),this.annotationCache.set(a,l)}e.delete(a)}for(const[r,{element:s}]of e.entries())this.annotationCache.delete(r),s.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=st();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=rt(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ot(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),o=r??n,a=this.getTheme(),l=typeof a=="string"?a:{...a},h=fe(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===o&&this.appliedThemeCSS.scrollbarGutter===h){this.appliedThemeCSS.theme=l;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:h};return}this.themeCSSStyle=at({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:lt(t,o,h)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:h}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=ht(this.themeCSSStyle.textContent??"",fe(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&dt()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);const n=this.code=ct({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();const s=()=>{if(n.childElementCount>=2)for(let o=0;o<2;o++){const a=n.children[o],l=r[o];a.innerHTML=V(l.children),a.style.cssText=l.properties.style}else n.innerHTML=V(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?ut(t,s):s(),this.lastRowCount=e.rowCount}applyPartialRender(e,t,n){if(t==null||n==null)return!1;const{code:r}=this,s=r!=null?this.getColumns(r):void 0;if(r==null||s==null)return!1;const o=t.startingLine,a=n.startingLine,l=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,h=n.totalLines===1/0?Number.POSITIVE_INFINITY:a+n.totalLines,c=Math.max(o,a),u=Math.min(l,h);if(u<=c)return!1;if(!this.trimDOMToOverlap(s.gutter,c,u)||!this.trimDOMToOverlap(s.content,c,u))throw new Error("File.applyPartialRender: failed to trim to overlap");let{length:d}=s.content.children;const f=(H,A)=>{if(!(A<=0))return this.fileRenderer.renderFile(e,{startingLine:H,totalLines:A,bufferBefore:0,bufferAfter:0})},m=a<c?f(a,c-a):void 0;if(m===void 0&&a<c)return!1;const g=h===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,h-u),S=h>u?f(u,g):void 0;return S===void 0&&h>u?!1:(this.cleanupErrorWrapper(),m!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.contentAST)),d+=m.rowCount),S!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.contentAST)),d+=S.rowCount),this.lastRowCount!==d&&(s.gutter.style.setProperty("grid-row",`span ${d}`),s.content.style.setProperty("grid-row",`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,o=r.get(n)??e.children.length;if(s>o)return!1;for(let a=e.children.length-1;a>=o;a-=1)e.children[a]?.remove();for(let a=s-1;a>=0;a-=1)e.children[a]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((l,h)=>l-h),r=new Map;if(n.length===0)return r;let s=0,o=n[s];const{children:a}=e;o===0&&(r.set(0,0),s+=1,o=n[s]);for(let l=0;l<a.length;l+=1){const h=a[l];if(!(h instanceof HTMLElement))continue;const c=this.getLineIndexFromDOMNode(h);if(c!=null){for(;o!=null&&c>=o;)r.set(o,l),s+=1,o=n[s];if(s>=n.length)break}}for(const l of n)r.has(l)||r.set(l,a.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t,n){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??V(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const h=document.createElement("div");h.innerHTML=r;const c=h.firstElementChild;if(!(c instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(c,this.headerElement):t.shadowRoot?.prepend(c),this.headerElement=c,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:o,renderCustomHeader:a,renderHeaderMetadata:l}=this.options;if(a!=null){const h=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Te,h),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const h=s?.(n)??void 0,c=o?.(n)??void 0,u=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Ve,h),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Pe,c),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,De,u),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return n!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:ge(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):ge(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=ft;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};gt(s,this.appliedPreAttributes)||(pt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Ot(i,e,t=!1){return!t&&i==null&&e!=null}function It(i,e,t=!1){return i==null&&e!=null&&!t}const Vt=5e3,J=new Map;let Pt=-1;function Dt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var _t=class extends be{virtualizer;metrics;__id=`virtualized-file:${++Pt}`;renderType="virtualized";top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0,ghostTextRows:J};pendingRender;isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=_e,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){const t=Ht(i);!e&&mt(this.metrics,t)||(this.metrics=t,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&(this.forceRenderOverride=!0)}syncLineAnnotations(i){return i==null||!this.isNewAnnotations(i)||i.length===0&&this.getLatestAnnotations().length===0?!1:(super.setLineAnnotations(i),!0)}syncEditSessionAnnotationsFromEditor(i){return super.syncEditSessionAnnotationsFromEditor(i)?(this.forceRenderOverride=!0,!0):!1}hasLineAnnotations(){return this.getLatestAnnotations().some(i=>i.lineNumber>0)}hasUniformLineHeights(){const{overflow:i="scroll"}=this.options;return i==="scroll"&&!this.hasLineAnnotations()&&this.cache.heights.size===0}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!He(e,i),n=Dt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1,e=!0){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.ghostTextRows=J,this.renderRange!=null&&e&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}applyGhostTextRows(i){const{heights:e,ghostTextRows:t}=this.cache;if(t===i)return!1;const{lineHeight:n}=this.metrics;let r=!1;for(const s of new Set([...t.keys(),...i.keys()])){const o=t.get(s)??0,a=i.get(s)??0;if(a===o)continue;const l=(e.get(s)??n)-o*n+a*n;l===n?e.delete(s):e.set(s,l),r=!0}return this.cache.ghostTextRows=i,r}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.getLayoutFile()==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;this.top=this.getVirtualizedTop();const t=this.editor?.__getGhostTextRows()??J;i=this.applyGhostTextRows(t);const n=e!=="scroll"||this.getLatestAnnotations().length>0||this.isResizeDebuggingEnabled();if(this.placeHolder!=null||!n&&this.cache.heights.size===0&&this.cache.fileAnnotationHeight===0)return i&&(this.computeApproximateSize(!0),this.setPlaceholderHeight(this.height)),i;const{lineHeight:r}=this.metrics;if(this.code==null)return i;const s=this.code.children[1];if(!(s instanceof HTMLElement))return i;if(this.renderRange!=null&&we(this.renderRange)){const o=Bt(s)??0;o!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=o,i=!0)}for(const o of s.children){if(!(o instanceof HTMLElement))continue;const a=o.dataset.lineIndex;if(a==null)continue;const l=Number(a),h=(t.get(l)??0)*r,c=this.cache.heights.get(l);if(!n&&(c==null||c===r+h))continue;let u=o.getBoundingClientRect().height+h,d=!1;o.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in o.nextElementSibling.dataset||"noNewline"in o.nextElementSibling.dataset)&&("noNewline"in o.nextElementSibling.dataset&&(d=!0),u+=o.nextElementSibling.getBoundingClientRect().height);const f=this.getLineHeight(l,d);u!==f&&(i=!0,u===this.metrics.lineHeight*(d?2:1)?this.cache.heights.delete(l):this.cache.heights.set(l,u))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));updateCodeViewLayout(i,e,t,n){const r=!R(this.file,i);r&&this.updateExternalFile(i,n);const{pendingRenderFile:s,layoutFileChanged:o,renderedFileChanged:a,annotationsChanged:l}=this.updatePendingRender(i,n);let h=t?.resetFileLayoutCache===!0||o;t?.metrics!=null&&(this.metrics=t.metrics,h=!0);const{collapsed:c=!1}=this.options;return this.currentCollapsed!==c&&(this.currentCollapsed=c,h=!0),h&&this.resetLayoutCache(),r&&(this.layoutDirty=!0),!this.forceRenderOverride&&(r||a||l)&&(this.forceRenderOverride=!0),this.top=e,this.computeApproximateSize(!1,s),this.height}getLayoutFile(){return this.pendingRender?.file??this.getRenderedFile()}getLinePosition(i){const e=this.getLayoutFile();if(e==null||i<1)return;const{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(e)-1;let s=j(this.metrics,t);if(n||r<0)return{top:s,height:0};const o=Math.min(Math.max(i-1,0),r),{lineHeight:a}=this.metrics;if(s+=this.cache.fileAnnotationHeight,this.hasUniformLineHeights())return{top:s+o*a,height:a};const l=this.getLayoutCheckpointBeforeLineIndex(o);s=l?.top??s;for(let h=l?.lineIndex??0;h<o;h++)s+=this.getLineHeight(h,!1);return{top:s,height:this.getLineHeight(o,!1)}}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(i){const e=this.getLayoutFile();if(e==null||this.renderRange==null)return;const{disableFileHeader:t=!1,collapsed:n=!1}=this.options;if(n||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(e)-1;if(r<0)return;const s=j(this.metrics,t),o=Math.min(this.renderRange.startingLine,r),a=Math.min(o+this.renderRange.totalLines-1,r);if(a<o)return;const{fileAnnotationHeight:l}=this.cache;if(this.hasUniformLineHeights()){const{lineHeight:c}=this.metrics,u=s+(o===0?l:this.renderRange.bufferBefore),d=o+Math.max(Math.ceil((i-u)/c),0);return d>a?void 0:{lineNumber:d+1,top:s+l+d*c}}let h=s+(o===0?l:this.renderRange.bufferBefore);for(let c=o;c<=a;c++){if(h>=i)return{lineNumber:c+1,top:h};h+=this.getLineHeight(c)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){const e=this.getLayoutFile();if(this.top==null||e==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const t=i!=null?this.computeRenderRangeFromWindow(e,this.top,i):this.renderRange;if(t==null)return;const{bufferBefore:n,bufferAfter:r,totalLines:s}=t;let o=0;if(s===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(o=r)}return{topOffset:this.top+n+o,height:this.height-(n+r)}}cleanUp(i=!1){const e=this.cache.ghostTextRows.size>0;e&&(this.layoutDirty=!0);const t=i&&this.isAdvancedMode()&&this.fileContainer!=null&&(e||!R(this.getRenderedFile(),this.getLatestFile()));this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.pendingRender=void 0,this.isSetup=!1,super.cleanUp(i),t&&this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(i=!1,e=this.getLayoutFile()){const t=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!t)return;const n=this.height===0;if(this.height=0,this.cache.checkpoints=[],e==null){this.layoutDirty=!1;return}this.applyGhostTextRows(this.editor?.__getGhostTextRows()??J);const{disableFileHeader:r=!1,collapsed:s=!1}=this.options,{lineHeight:o}=this.metrics,a=this.fileRenderer.getLineCount(e),l=j(this.metrics,r),h=Re(this.metrics);if(this.height+=l,s){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,this.hasUniformLineHeights())this.height+=a*o;else for(let c=0;c<a;c++)this.addLayoutCheckpoint(c,this.height),this.height+=this.getLineHeight(c,!1);if(a>0&&(this.height+=h),this.fileContainer!=null&&t&&!n){const c=this.fileContainer.getBoundingClientRect();c.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:c.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){if(!this.enabled||this.file==null)return;const i=this.getLatestFile(),e=i==null?void 0:this.fileRenderer.getFileForNextRender(i);this.isSimpleMode()&&(this.pendingRender=void 0),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!R(this.getRenderedFile(),e))}syncGhostTextRows(){const i=this.getAdvancedVirtualizer();i!=null?(i.capturePendingLayoutAnchor(),this.layoutDirty=!0,i.instanceChanged(this,!0)):this.getSimpleVirtualizer()?.requestHeightReconcile(this)}applyDocumentChange(i,e,t=!1){const{renderRange:n}=this;this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1);const r=this.getRenderedFile();if(!this.isSimpleMode())this.computeApproximateSize(!0);else if(t&&n!=null&&r!=null){const s=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(r,this.top??0,s);o.bufferAfter!==n.bufferAfter&&this.updateBuffers(o)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=!R(this.file,e);s&&(this.updateExternalFile(e,n),this.cachedHeaderHTML=void 0);const{pendingRenderFile:o,layoutFileChanged:a,renderedFileChanged:l,annotationsChanged:h}=this.pendingRender!=null&&this.pendingRender.latestFile===(this.getLatestFile(e)??e)?{pendingRenderFile:this.pendingRender.file,layoutFileChanged:!1,renderedFileChanged:!1,annotationsChanged:this.syncLineAnnotations(n)}:this.updatePendingRender(e,n),{forceRenderOverride:c,isSetup:u}=this;if(this.forceRenderOverride=void 0,a&&this.resetLayoutCache(),i=this.getOrCreateFileContainerNode(i),u)this.top??=this.getVirtualizedTop(),this.layoutDirty&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,o));else{this.computeApproximateSize(!1,o);const g=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(g==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");g.connect(i,this),this.isVisible=g.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!s||!u))return this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),f=this.top??0,m=this.computeRenderRangeFromWindow(o,f,d);return super.render({file:e,fileContainer:i,renderRange:m,lineAnnotations:n,forceRender:(c??t)||h||l||s,...r})}finalizeRender(){if(this.getRenderedFile()!==this.pendingRender?.file)throw new Error("VirtualizedFile.render: rendered a different file than its prepared layout");this.pendingRender=void 0,this.isSimpleMode()&&this.getSimpleVirtualizer()?.requestHeightReconcile(this)}updatePendingRender(i,e){const t=this.getLatestFile(i)??i,n=this.getRenderedFile(),r=this.pendingRender?.file??n,s=this.fileRenderer.getFileForNextRender(t);return this.pendingRender={latestFile:t,file:s},{pendingRenderFile:s,annotationsChanged:this.syncLineAnnotations(e),layoutFileChanged:!R(r,s),renderedFileChanged:!R(n,s)}}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Vt===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");o.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(o.lineIndex%e===0)return o}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1}=this.options,{hunkLineCount:s,lineHeight:o}=this.metrics,a=this.fileRenderer.getLineCount(i),l=this.height,h=j(this.metrics,r),c=a>0?Re(this.metrics):0,{fileAnnotationHeight:u}=this.cache,d=h+u,f=Math.max(0,l-h-u-c),m=St(this.getLatestAnnotations()),g=e+h,S=u>0&&m&&g<n&&g+u>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-c};if(a<=s)return{startingLine:0,totalLines:s,bufferBefore:0,bufferAfter:0};const H=Math.ceil(Math.max(n-t,0)/o),A=Math.ceil(H/s)*s+s,p=A/s,y=(t+n)/2;if(this.hasUniformLineHeights()){const O=e+d,U=O+f;if(!S&&!(O<n&&U>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-c};const D=Math.floor(S&&y<e+d?0:(y-(e+d))/o),M=Math.floor(D/s)-Math.floor(p/2),ze=Math.ceil(a/s),_=Math.max(0,Math.min(M,ze))*s,oe=M<0?A+M*s:A,Ne=_===0?0:u+_*o,Oe=Math.min(oe,a-_);return{startingLine:_,totalLines:oe,bufferBefore:Ne,bufferAfter:Math.max(0,(a-_-Oe)*o)}}const P=p,E=[],L=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-A*o*2),s);let T=e+(L?.top??d),k=L?.lineIndex??0,z,C,w;const Q=L?.lineIndex??0;for(let O=Q;O<a;O++){const U=k%s===0,D=Math.floor(k/s);if(U&&(E[D]=T-(e+d),w!=null)){if(w<=0)break;w--}const M=this.getLineHeight(O,!1);T>t-M&&T<n&&(z??=D),T+M>y&&(C??=D),w==null&&T>=n&&U&&(w=P),k++,T+=M}if(z==null)if(S)z=0,C=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-c};C??=z;const N=Math.round(C-p/2),Z=Math.max(0,Math.ceil(a/s)-p),ee=Math.max(0,Math.min(N,Z)),ne=ee*s,se=N<0?A+N*s:A,Me=E[ee]??0,Fe=ne===0?0:u+Me,re=ee+se/s,ke=re<E.length?f-E[re]:f-(T-e-d);return{startingLine:ne,totalLines:se,bufferBefore:Fe,bufferAfter:Math.max(0,ke)}}};function Bt(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===Ct&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function Ut({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:o,renderGutterUtility:a,getHoveredLine:l,getAnnotationSlotName:h=F}){const c=e?.(i),u=t?.(i),d=n?.(i),f=r?.(i);return v.jsxs(v.Fragment,{children:[c!=null?v.jsx("div",{slot:Te,children:c}):v.jsxs(v.Fragment,{children:[u!=null&&v.jsx("div",{slot:"header-prefix",children:u}),d!=null&&v.jsx("div",{slot:"header-filename-suffix",children:d}),f!=null&&v.jsx("div",{slot:"header-metadata",children:f})]}),s!=null&&o?.map((m,g)=>v.jsx("div",{slot:h(m),children:s(m)},g)),a!=null&&v.jsx("div",{slot:"gutter-utility-slot",style:vt,children:a(l)})]})}const Wt=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Gt({file:i,options:e,editorOptions:t,editStateKey:n,lineAnnotations:r,selectedLines:s,prerenderedHTML:o,metrics:a,hasGutterRenderUtility:l,hasCustomHeader:h,disableWorkerPool:c,edit:u,onEditChange:d,onEditComplete:f}){const m=Rt(),g=s!==void 0,S=b.useContext(yt),H=Lt(),A=W(C=>d?.(C)),p=d!=null?A:void 0,y=b.useRef(null),P=W(C=>{const w=f?.(C)??"reject";return w==="accept"&&(y.current={file:{installed:C.file,stale:C.originalFile},annotations:{installed:C.lineAnnotations,stale:C.originalLineAnnotations}}),w}),E=f!=null?P:void 0,L=b.useRef(null),T=b.useRef(null),k=W(()=>{if(H==null)throw new Error("File: EditContext is not attached");return H("file",t??{},n)}),z=W(C=>{if(C!=null){if(L.current!=null)throw new Error("File: An instance should not already exist when a node is created");m!=null?L.current=new _t(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:p,onEditComplete:E,options:e}),m,a,c?void 0:S,!0):L.current=new be(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:p,onEditComplete:E,options:e}),c?void 0:S,!0),u&&T.current==null&&(T.current=Le(L.current,k)),L.current.hydrate({file:i,fileContainer:C,lineAnnotations:r,prerenderedHTML:o})}else{if(L.current==null)throw new Error("File: A File instance should exist when unmounting");L.current.cleanUp(),L.current=null,T.current=null}});return Wt(()=>{const{current:C}=L;if(C==null)return;const w=te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:p,onEditComplete:E,options:e}),Q=w!==void 0&&!He(C.options,w);if(C.setOptions(w),!u&&T.current!=null){const{current:Z}=T;T.current=null,Z()}const N=jt(i,r,y);C.render({file:N.file,lineAnnotations:N.lineAnnotations,forceRender:Q}),s!==void 0&&C.setSelectedLines(s),u&&T.current==null&&(T.current=Le(C,k))}),{ref:z,getHoveredLine:b.useCallback(()=>L.current?.getHoveredLine(),[]),getAnnotationSlotName:b.useCallback(C=>L.current?.getAnnotationSlotName(C)??F(C),[])}}function jt(i,e,t){const{current:n}=t;if(n==null)return{file:i,lineAnnotations:e};const{file:r,annotations:s}=n;let o=i;r!=null&&(R(i,r.stale)?o=r.installed:n.file=null);let a=e;return s!=null&&(e===s.stale?a=s.installed:n.annotations=null),n.file==null&&n.annotations==null&&(t.current=null),{file:o,lineAnnotations:a}}function te({options:i,controlledSelection:e,hasCustomHeader:t,hasGutterRenderUtility:n,onEditChange:r,onEditComplete:s}){return e||n||t||r!=null||s!=null?{...i,controlledSelection:e,renderCustomHeader:t?pe:i?.renderCustomHeader,renderGutterUtility:n?pe:i?.renderGutterUtility,onEditChange:r,onEditComplete:s}:i}function Le(i,e){const t=e();try{return t.edit(i)}catch(n){throw t.cleanUp(),n}}function ti({file:i,lineAnnotations:e,selectedLines:t,options:n,editorOptions:r,editStateKey:s,metrics:o,className:a,style:l,renderAnnotation:h,renderCustomHeader:c,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,prerenderedHTML:m,renderGutterUtility:g,disableWorkerPool:S=!1,edit:H=!1,onEditChange:A,onEditComplete:p}){const{ref:y,getHoveredLine:P,getAnnotationSlotName:E}=Gt({file:i,options:n,editorOptions:r,editStateKey:s,metrics:o,lineAnnotations:e,selectedLines:t,prerenderedHTML:m,hasGutterRenderUtility:g!=null,hasCustomHeader:c!=null,disableWorkerPool:S,edit:H,onEditChange:A,onEditComplete:p}),L=Ut({file:i,renderAnnotation:h,renderCustomHeader:c,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,renderGutterUtility:g,lineAnnotations:e,getHoveredLine:P,getAnnotationSlotName:E});return v.jsx(Be,{ref:y,className:a,style:l,children:Tt(L,m)})}const ii=I.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const{t:s}=Ue(),o=I.useRef(null),[a,l]=I.useState(null),h=I.useMemo(()=>{try{const d=e.trim();if(!d)return l(s("jsonTreeView.error.emptyJson")),null;const f=JSON.parse(d);return l(null),f}catch(d){return l(d instanceof Error?d.message:s("jsonTreeView.error.invalidJson")),null}},[e,s]),c=I.useCallback(()=>{o.current?.expandAll()},[]),u=I.useCallback(()=>{o.current?.collapseAll()},[]);return a?v.jsx("div",{className:t,children:v.jsxs("div",{className:"oc-surface-code rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-background)] p-4",children:[v.jsx("div",{className:"mb-1 font-medium text-foreground",children:s("jsonTreeView.error.invalidJsonTitle")}),v.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:a})]})}):h===null?null:v.jsxs("div",{className:t,children:[v.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[v.jsxs(le,{variant:"ghost",size:"xs",onClick:c,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-down-s",className:"h-3 w-3"}),s("jsonTreeView.actions.expandAll")]}),v.jsxs(le,{variant:"ghost",size:"xs",onClick:u,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-up-s",className:"h-3 w-3"}),s("jsonTreeView.actions.collapseAll")]})]}),v.jsx("div",{className:"oc-surface-code bg-[var(--syntax-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:v.jsx(We,{ref:o,data:h,maxHeight:n,initiallyExpandedDepth:r})})]})});export{ti as F,ii as J,_t as V};
@@ -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{ba as K,bb as J,ap as Z,u as Q,I as W}from"./useAppFontEffects-3EN8Ava3.js";import{l as G,a0 as Y,a1 as ee,m as te,a2 as re,a3 as oe,a4 as ae,a5 as se}from"./katex.min-Iw9WSgM9.js";import{extractMarkdownImageCandidates as ne,isRemoteMarkdownImageSource as ie,MAX_MARKDOWN_IMAGE_COUNT as le}from"./markdownCore-6gz4uJDQ.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-CVhJ1Zpv.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.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-DcBOpbSu.js";import"./vendor-katex-CBXxfSPY.js";import"./vendor-dompurify-r8glNMJW.js";import"./openFenceIncremental-7wgnc2ZL.js";const L=10*1024*1024,ce=1024,me=3e4,ue=new Set(["image/png","image/jpeg","image/gif","image/webp"]),z=new WeakMap,$=r=>{if(r.aborted)throw new DOMException("Image load aborted","AbortError")},pe=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}},fe=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)}),de=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(!ue.has(e))throw new Error("Unsupported image type");if(r.size>L)throw new Error("Image is too large");if(!await de(r,e))throw new Error("Unsupported image data")},ge=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),he=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}),directory:e,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>=ce;)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()+me}),l},we=async(r,e)=>{if($(e),/^(?:https?:)?\/\//i.test(r))return r;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(r))return await ge(r),$(e),r;throw new Error("Local image has not been prepared")},be=async(r,e,t)=>{$(t);const o=pe(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),fe(m)},ye=(r,e)=>Y().authenticatedAsset(ee("/api/fs/raw",e),{path:r.path,directory:e,allowOutsideWorkspace:r.outsideFileGrant?"true":void 0,outsideFileGrant:r.outsideFileGrant}),Ie=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=re(),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=oe(c),g=ae(()=>{w||u(Ae)}),I=()=>{se(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},Ee=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(xe)&&(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"}),be(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:ye(o,n),status:"loading"});return}const N=new AbortController;return g({url:"",status:"loading"}),we(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 k;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?(k=[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]=k):k=e[22],h.useEffect(v,k);let R;e[23]!==t.filename||e[24]!==a.status||e[25]!==a.url||e[26]!==i||e[27]!==p?(R=()=>{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]=R):R=e[28];const U=R,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(ve),onError:()=>g({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":a.status}):P.jsx(W,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[29]=t.filename,e[30]=a.status,e[31]=a.url,e[32]=A):A=e[32];let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=P.jsx(W,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[33]=_):_=e[33];let S;e[34]!==t.filename?(S=P.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[34]=t.filename,e[35]=S):S=e[35];let C;e[36]!==t.filename||e[37]!==S?(C=P.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[_,S]}),e[36]=t.filename,e[37]=S,e[38]=C):C=e[38];let M;return e[39]!==t.filename||e[40]!==t.source||e[41]!==U||e[42]!==C||e[43]!==j||e[44]!==A?(M=P.jsxs("button",{ref:m,type:"button",className:"w-[100px] shrink-0 text-start 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},hr=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=te(),e[0]=a):a=e[0];const g=a;let I;e[1]!==n?(I=ne(n,le).filter(ke),e[1]=n,e[2]=I):I=e[2];const b=I;let x;e[3]!==b?(x=g?[]:b.filter(Re).map(_e),e[3]=b,e[4]=x):x=e[4];const f=x;let v,k;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(Se)&&(p(!0),T.disconnect())},{rootMargin:"200px"});return T.observe(d),()=>T.disconnect()},k=[f.length,i],e[5]=f.length,e[6]=i,e[7]=v,e[8]=k):(v=e[7],k=e[8]),h.useEffect(v,k);let R;e[9]!==s||e[10]!==o||e[11]!==f||e[12]!==t||e[13]!==i?(R=()=>{if(!i||!t||f.length===0)return;const d=new AbortController;return he({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(Me)))}),()=>d.abort()},e[9]=s,e[10]=o,e[11]=f,e[12]=t,e[13]=i,e[14]=R):R=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(R,U);let j,A;e[22]!==m?(j=()=>{const d=Math.min(...[...m?.values()??[]].filter(Ne).map(Pe));if(!Number.isFinite(d))return;const T=setTimeout(()=>y(Ue),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 _;e[25]!==m?(_=d=>m?.get(d.source)?.status!=="missing",e[25]=m,e[26]=_):_=e[26];const S=b.filter(_),C=[...m?.values()??[]].some(je),M=Ie(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(Ee,{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 Ae(r){return r+1}function xe(r){return r.isIntersecting}function ve(r){return{...r,status:"ready"}}function ke(r){return!ie(r.source)}function Re(r){return q(r.source)}function _e(r){return r.source}function Se(r){return r.isIntersecting}function Me(r){return[r,{status:"error"}]}function Ne(r){return r.status==="ready"}function Pe(r){return r.expiresAt??Number.POSITIVE_INFINITY}function Ue(r){return r+1}function je(r){return r.status==="ready"}export{hr as MarkdownImageGallery};
@@ -1 +0,0 @@
1
- import{R as E,f as ie,j as re}from"./vendor-react-BUCujlKS.js";import{m as dt}from"./vendor-morphdom-B7dS_VPB.js";import{r as ut,a as mt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{b4 as De,eL as ft,aZ as Le,aP as pt,eM as ht,eN as bt,eO as kt,eP as wt,aq as Be,ap as $e,bm as Ke,u as He,L as qe,a4 as gt,a5 as Te,bb as At,eQ as Et,ba as yt,eR as Ct,eS as St,cb as Rt,cU as Lt}from"./useAppFontEffects-3EN8Ava3.js";import{m as ke,l as ze,aV as oe,aW as Mt,u as z,Y as vt,aX as Tt,aY as Nt,aZ as _t,a2 as Pt}from"./katex.min-Iw9WSgM9.js";import{renderMarkdownBlocksSync as Ft,getCachedMarkdownBlocks as It,renderMarkdownBlocks as xt}from"./markdownCore-6gz4uJDQ.js";import{a as Ot,r as Wt}from"./textMateThemeFromAppTheme-B6UJwdZz.js";import{s as K,c as Dt,a as Bt,b as $t,d as Kt,e as Ae,f as Ht,M as Ee}from"./decorate-BNB7jeKg.js";import{o as qt,a as zt,s as Ut}from"./vendor-zod-CVhJ1Zpv.js";import{a as Vt}from"./openFenceIncremental-7wgnc2ZL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-base-ui-CXFyogip.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-tanstack-react-virtual-CvuLsk7D.js";import"./vendor-tanstack-virtual-core-DPaNcJcT.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-BhRb6jns.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-1e0FQ6Wn.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-BBADuAkg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CUmSxayT.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-C8FBSI9t.js";import"./vendor-codemirror-lang-json-VDxF27mO.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-B2_PZTBl.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-BpvvTxbZ.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CimQAQbQ.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cu5ZbrPm.js";import"./vendor-codemirror-lang-python-BFE1OJNx.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.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-legendapp-list-BCBzRcfK.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-opencode-client-DgOf1DP0.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-DcBOpbSu.js";import"./vendor-katex-CBXxfSPY.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./selectionMarkdown-sDTBbKLh.js";const Me=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},ye=(t,e)=>{if(t.defaultPrevented)return!1;const r=Me(t)?.getAttribute("href")??"";return Le(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},Ue=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,Zt=(t,e)=>{const n=e.openSessionLink;if(!n||t.defaultPrevented)return!1;const r=Me(t)?.getAttribute("href")??"",o=ft(r,e.ownOrigins??[]);return!o||De(r)&&!Ue(t)?!1:(t.preventDefault(),t.stopPropagation(),n(o),!0)},jt=(t,e)=>{const n=i=>{if(Zt(i,e)||ye(i,e.openAppLink)||!e.allowExternalHttp||i.defaultPrevented||!Ue(i))return;const s=Me(i)?.getAttribute("href")??"";De(s)&&(i.preventDefault(),i.stopPropagation(),e.openExternalHttp(s))},r=i=>{i.button===1&&ye(i,e.openAppLink)},o=i=>{ye(i)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",o),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",o)}},Ve='[data-openchamber-file-link="true"]',Xt=t=>{if(!(t instanceof Element))return null;const e=t.closest(Ve);return e instanceof HTMLElement?e:null},Gt=(t,e)=>{if(!(t instanceof Element))return null;const n=t.closest("a[href]");if(!(n instanceof HTMLAnchorElement))return null;const r=e.hrefCandidate(n);return!r||!e.isResolvable(r)?null:n},Yt=(t,e)=>{const n=r=>{const o=Xt(r.target)??Gt(r.target,e);if(!o)return;r.preventDefault(),r.stopPropagation();const i=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform);e.openFileReference(o,{external:i?r.metaKey:r.ctrlKey})};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},Ze="openchamber-md",pe={background:"transparent",foreground:"var(--md-syntax-foreground)",comment:"var(--md-syntax-comment)",keyword:"var(--md-syntax-keyword)",string:"var(--md-syntax-string)",number:"var(--md-syntax-number)",function:"var(--md-syntax-function)",variable:"var(--md-syntax-variable)",type:"var(--md-syntax-type)",operator:"var(--md-syntax-operator)"},Qt=Object.fromEntries(Object.keys(pt({base:pe})).map(t=>[t,`var(--md-token-${t})`])),Jt={name:Ze,colors:{"editor.background":"transparent","editor.foreground":pe.foreground},tokenColors:[...Ot({base:pe,tokens:Qt}),{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:pe.keyword,fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted","invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let Ne=!1;const en=()=>{Ne||(Ne=!0,Wt(Ze,()=>Promise.resolve(Jt)))},te=new Map;let ne=null;const tn=()=>{if(ne)return ne;const t=globalThis.ResizeObserver;return t?(ne=new t(e=>{for(const n of e){const r=te.get(n.target);if(!r)continue;const{width:o}=n.contentRect;if(o===r.width)continue;const i=r.width===null;r.width=o,i||bt(r.onWidthChange)}}),ne):null},nn=(t,e)=>{const n=tn();return n?(te.set(t,{width:null,onWidthChange:e}),n.observe(t),()=>{const r=te.get(t);r&&(te.delete(t),ht(r.onWidthChange),n.unobserve(t),!(te.size>0)&&(n.disconnect(),ne=null))}):()=>{}},_e=(t,e,n)=>{let r=0;for(const i of t){const s=r+i.data.length;if(e<s||e===s&&n==="left")return{node:i,offset:Math.max(0,e-r)};r=s}const o=t.at(-1);return o?{node:o,offset:o.data.length}:null},rn=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Pe=Array.from(rn).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),je=t=>wt(t),on=t=>kt(t),Xe=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}},he=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):""},me=t=>{let e=he(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 o=Pe.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Pe})):.*$`,"i")):null;return o&&(e=o[1]??e),he(e)},Ge=t=>{const e=he(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?he(e.slice(0,n)):e;if(!r)return null;const o=r.match(/^(.*?):(\d+)-(\d+)$/);if(o){const b=me(o[1]??""),u=Number.parseInt(o[2]??"",10),p=Number.parseInt(o[3]??"",10);return!b||!Number.isFinite(u)||!Number.isFinite(p)||p<u?null:{path:b,line:u,endLine:p}}const i=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(i){const b=me(i[1]??""),u=Number.parseInt(i[2]??"",10),p=i[3]?Number.parseInt(i[3],10):void 0;return!b||!Number.isFinite(u)?null:{path:b,line:u,column:Number.isFinite(p??Number.NaN)?p:void 0}}const s=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const b=me(s[1]??""),u=Number.parseInt(s[2]??"",10),p=s[3]?Number.parseInt(s[3],10):void 0;return!b||!Number.isFinite(u)?null:{path:b,line:u,column:Number.isFinite(p??Number.NaN)?p:void 0}}const c=me(r);return c?{path:c}:null},sn=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,an=4,ln=1e3,cn=200,U=new Map;let fe=0;const Fe=[],dn=()=>ke()?cn:ln,Ye=(t,e)=>`${t}\0${e}`,un=(t,e)=>{const n=je(t);if(!n)return Promise.resolve(!1);const r=Ye(e,n),o=U.get(r);if(o)return U.delete(r),U.set(r,o),o;const i=new Promise(c=>{const b=()=>{fe+=1,ze(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async u=>{if(!u.ok){c(!1);return}const p=await u.json().catch(()=>null);c(p?.exists!==!1)}).catch(()=>c(!1)).finally(()=>{fe=Math.max(0,fe-1),Fe.shift()?.()})};if(fe<an){b();return}Fe.push(b)}),s=dn();for(;U.size>=s;){const c=U.keys().next().value;if(typeof c!="string")break;U.delete(c)}return U.set(r,i),i},mn=qt({paths:zt(Ut())}),J=new Map,fn=200,pn=(t,e)=>{if(!t||!e||ke())return Promise.resolve(null);const n=Ye(e,t),r=J.get(n);if(r)return r;const o=ze(`/api/fs/find-by-name?name=${encodeURIComponent(t)}`,{method:"GET",cache:"no-store",headers:{"x-opencode-directory":e}}).then(async i=>{if(!i.ok)return null;const s=mn.safeParse(await i.json().catch(()=>null)),c=s.success?s.data.paths:[];return c.length===1?c[0]:null}).catch(()=>null);for(;J.size>=fn;){const i=J.keys().next();if(i.done)break;J.delete(i.value)}return J.set(n,o),o},hn={maxSessions:8,maxEntriesPerSession:4};class bn{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=hn){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let o=this.sessions.get(n);for(o===void 0?(o=new Map,this.sessions.set(n,o)):this.refreshSession(n,o),o.delete(r),o.set(r,e);o.size>this.maxEntriesPerSession;)this.removeOldestEntry(o);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const o=e.id;this.refreshSession(n,r);const i=r.get(o);return i===void 0||i.locale!==e.locale||i.directory!==e.directory?null:(r.delete(o),r.size===0&&this.sessions.delete(n),i.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 Ie=new bn,Qe=()=>{const t=ie.c(4),e=gt();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=Te(!1),t[0]=n):n=t[0];const r=n;let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o=Te(!0),t[1]=o):o=t[1];const i=o;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?i:r),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},kn=()=>{if(typeof window>"u")return[];const t=[window.location.origin];try{const e=new URL(Pt()||window.location.href,window.location.href).origin;t.includes(e)||t.push(e)}catch{}return t},Je=t=>{const e=ie.c(4),{containerRef:n,enabled:r}=t;let o,i;e[0]!==n||e[1]!==r?(o=()=>{const s=n.current;if(!s)return;const c=!ke();return jt(s,{allowExternalHttp:r!==!1,openAppLink:Hn,openExternalHttp:qn,openSessionLink:c?zn:void 0,ownOrigins:kn()})},i=[n,r],e[0]=n,e[1]=r,e[2]=o,e[3]=i):(o=e[2],i=e[3]),E.useEffect(o,i)},Y={download:!0,copy:!0,showPanZoomControls:!0},et=!0,wn=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-block-path-token",nt=`[${tt}]`,se="data-openchamber-block-paths-scanned",gn=2e5,An=80,En=40,xe=160,yn=()=>ke()?En:An,Cn=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),rt=t=>je(t),Sn=t=>on(t),Rn=(t,e)=>yt(t,e),Ln=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},ot=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=rt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return Cn.has(r)||r.startsWith(".")&&r.length>1?!0:Ln(e)},ve=t=>{const e=Ge(t);return e?ot(e.path):!1},Mn=t=>{const e=t.querySelectorAll(nt);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${se}]`);for(const r of Array.from(n))r.removeAttribute(se),r.normalize()},Ce=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim();if(e&&Le(e))return"";const n=e?Xe(e):null;if(n)return n;if(e&&ve(e))return e}return(t.textContent||"").trim()},vn=t=>{const e=t.getAttribute("href")?.trim();if(!e||Le(e))return null;const n=Xe(e);return n||(ve(e)?e:null)},Tn=t=>{const e=[];for(const n of Array.from(t.querySelectorAll("pre code"))){if(n.hasAttribute(se))continue;const r=[],o=n.textContent??"",i=o.length>gn?"":o;if(i.includes("."))for(const s of i.matchAll(sn)){const c=s[0];c&&ve(c)&&r.push({start:s.index,end:s.index+c.length,raw:c})}e.push({codeBlock:n,tokens:r})}return e},Nn=(t,e)=>{const n=t.ownerDocument;if(e.length>0){const r=n.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=[];for(let s=r.nextNode();s;s=r.nextNode())s instanceof Text&&o.push(s);const i=t.textContent??"";for(const{start:s,end:c,raw:b,decorate:u}of[...e].sort((p,R)=>R.start-p.start)){if(i.slice(s,c)!==b)continue;const p=_e(o,s,"right"),R=_e(o,c,"left");if(!p||!R)continue;const w=n.createRange();w.setStart(p.node,p.offset),w.setEnd(R.node,R.offset);const y=n.createElement("span");y.setAttribute(tt,"true"),y.textContent=b,u(y),w.deleteContents(),w.insertNode(y)}}t.setAttribute(se,"true")},ee=(t,e)=>{const n=Ge(t);if(!n||!ot(n.path))return null;const r=Sn(n.path)?rt(n.path):Rn(e,n.path);return r?{...n,resolvedPath:r}:null},_n=(t,e)=>t||Et(t,e),st=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:o})=>{const i=E.useRef(null);E.useEffect(()=>{const s=t.current;if(!s||o&&!e)return;let c=!1;const b=yn(),u=o&&!Tt(),p=a=>{a.removeAttribute("data-openchamber-file-link"),a.removeAttribute("data-openchamber-file-ref"),a.removeAttribute("data-openchamber-file-path"),a.getAttribute("title")==="Open file"&&a.removeAttribute("title"),a.tagName.toLowerCase()!=="a"&&(a.removeAttribute("role"),a.removeAttribute("tabindex"))},R=()=>{const a=s.querySelectorAll(Ve);for(const m of Array.from(a))p(m);Mn(s)},w=async(a,m)=>{const k=a.getAttribute("data-openchamber-file-ref")||Ce(a),_=ee(k,e);if(!_)return;const I=a.getAttribute("data-openchamber-file-path"),f=I?{..._,resolvedPath:I}:_;if(m?.external&&Nt()&&await _t(f.resolvedPath))return;const M=_n(e,f.resolvedPath);if(r&&n){n.openFile(f.resolvedPath,Number.isFinite(f.line??Number.NaN)?Math.max(1,Math.trunc(f.line)):void 0,Number.isFinite(f.column??Number.NaN)?Math.max(1,Math.trunc(f.column)):void 0);return}const C=z.getState();Number.isFinite(f.line??Number.NaN)?C.openContextFileAtLine(M,f.resolvedPath,Math.max(1,Math.trunc(f.line)),Number.isFinite(f.column??Number.NaN)?Math.max(1,Math.trunc(f.column)):1):C.openContextFile(M,f.resolvedPath)},y=()=>Yt(s,{hrefCandidate:vn,isResolvable:a=>ee(a,e)!==null,openFileReference:w});if(!u)return R(),o?y():void 0;const g=(a=0)=>{if(i.current!==null&&typeof window<"u"&&window.clearTimeout(i.current),typeof window>"u"){B();return}i.current=window.setTimeout(()=>{i.current=null,window.requestAnimationFrame(()=>{c||B()})},a)},O=a=>{l+=1;try{a()}finally{queueMicrotask(()=>{l-=1})}},L=(a,m,k)=>{a.getAttribute(m)!==k&&a.setAttribute(m,k)},N=(a,m,k)=>{L(a,"data-openchamber-file-link","true"),L(a,"data-openchamber-file-ref",m),L(a,"data-openchamber-file-path",k),L(a,"title","Open file"),a.tagName.toLowerCase()!=="a"&&(L(a,"role","button"),L(a,"tabindex","0"))},F=a=>{if(!At(a.resolvedPath,e))return Promise.resolve(a.resolvedPath);const m=!a.path.includes("/")&&!a.path.includes("\\");return un(a.resolvedPath,e).then(k=>k?a.resolvedPath:m?pn(a.path,e):null)},B=()=>{const a=s.querySelectorAll(`[data-markdown="inline-code"], a, ${nt}`);let m=0;const k=[],_=[];for(const f of Array.from(a)){const M=ee(Ce(f),e);if(!M||m>=b){_.push(f);continue}m+=1,k.push({candidate:f,resolvedPath:M.resolvedPath,target:F(M)})}const I=Tn(s).map(({codeBlock:f,tokens:M})=>({codeBlock:f,tokens:M.flatMap(C=>{const A=ee(C.raw,e);return!A||m>=b?[]:(m+=1,[{...C,target:F(A)}])})}));O(()=>{for(const f of _)p(f)}),!(k.length===0&&I.length===0)&&Promise.all([Promise.all(k.map(f=>f.target.then(M=>({...f,targetPath:M})))),Promise.all(I.map(async({codeBlock:f,tokens:M})=>({codeBlock:f,tokens:await Promise.all(M.map(C=>C.target.then(A=>({...C,targetPath:A}))))})))]).then(([f,M])=>{c||O(()=>{for(const{candidate:C,resolvedPath:A,targetPath:T}of f){if(!s.contains(C))continue;const h=Ce(C);ee(h,e)?.resolvedPath===A&&(T?N(C,h,T):p(C))}for(const{codeBlock:C,tokens:A}of M)!s.contains(C)||C.hasAttribute(se)||Nn(C,A.flatMap(({start:T,end:h,raw:x,targetPath:H})=>H?[{start:T,end:h,raw:x,decorate:W=>N(W,x,H)}]:[]))})})},d=a=>{if(a.key!=="Enter"&&a.key!==" ")return;const m=a.target;!(m instanceof HTMLElement)||m.getAttribute("data-openchamber-file-link")!=="true"||(a.preventDefault(),a.stopPropagation(),w(m))};g(xe);let l=0;const S=new MutationObserver(()=>{l>0||g(xe)});S.observe(s,{childList:!0,subtree:!0}),s.addEventListener("keydown",d);const v=y();return()=>{c=!0,i.current!==null&&typeof window<"u"&&window.clearTimeout(i.current),i.current=null,S.disconnect(),v(),s.removeEventListener("keydown",d)}},[t,n,e,r,o])},it=t=>{const e=ie.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:o,enablePanZoom:i,allowMermaidWheelEvents:s}=t;let c,b;e[0]!==s||e[1]!==n||e[2]!==o||e[3]!==i||e[4]!==r?(c=()=>{const u=n.current;if(!u)return;const p=w=>{if(!o||!r)return;const y=w.target;if(!(y instanceof Element)||y.closest('button, a, [role="button"]'))return;const g=y.closest(Ee);if(!g)return;if(g instanceof HTMLElement&&g.hasAttribute("data-mermaid-suppress-click")){g.removeAttribute("data-mermaid-suppress-click");return}const L=Array.from(u.querySelectorAll(Ee)).indexOf(g);if(L<0)return;const N=g instanceof HTMLElement?g.getAttribute("data-md-source"):null;if(!N||N.trim().length===0)return;const F=`Diagram ${L+1}`;r({open:!0,title:F,content:"",metadata:{tool:"mermaid-preview",filename:F},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(N)}`,source:N,filename:F}})},R=w=>{if(s||(w.ctrlKey||w.metaKey)&&i)return;const y=w.target;!(y instanceof Element)||!y.closest(Ee)||w.stopPropagation()};return u.addEventListener("click",p),u.addEventListener("wheel",R,{capture:!0,passive:!0}),()=>{u.removeEventListener("click",p),u.removeEventListener("wheel",R,!0)}},b=[s,n,o,i,r],e[0]=s,e[1]=n,e[2]=o,e[3]=i,e[4]=r,e[5]=c,e[6]=b):(c=e[5],b=e[6]),E.useEffect(c,b)},V=new Map,Pn=100,Z="data-md-decoration-id",Se=t=>{const e=t.lastElementChild;for(const n of Array.from(t.children))n!==e&&n.hasAttribute("data-md-last")&&n.removeAttribute("data-md-last");e?.hasAttribute("data-md-block")&&!e.hasAttribute("data-md-last")&&e.setAttribute("data-md-last","")},be="oc-md-block-enter",Fn=t=>{for(const e of Array.from(t.querySelectorAll(`.${be}`)))e.classList.remove(be),e.style.removeProperty("--oc-md-enter-delay")},In=t=>{for(const e of Array.from(t.children))!(e instanceof HTMLElement)||!e.classList.contains(be)||(e.classList.remove(be),e.style.removeProperty("--oc-md-enter-delay"),e.getAttribute("style")||e.removeAttribute("style"))},xn=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let o=0;o<e.length;o+=1){const i=r[o];if(!i||i.getAttribute("data-md-id")!==e[o]?.id||i.getAttribute(Z)!==n)return!1}return!0},Oe=new WeakMap;let We=0;const On=2e5,Re=t=>{const e=Oe.get(t);if(e)return e;const n=`decoration-${We}`;return We+=1,Oe.set(t,n),n},Wn=(t,e)=>{const n=V.get(t);if(n)return V.delete(t),V.set(t,n),n;const r=e();if(V.set(t,r),V.size>Pn){const o=V.keys().next().value;o&&V.delete(o)}return r},Dn=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"}),Bn=()=>z.getState().copyMessagesAsPlainText?"plain":"markdown",at=(t,e,n=Y)=>{const{t:r}=He(),o=E.useMemo(()=>({copy:r("markdownRenderer.code.actions.copyTitle"),copied:r("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:r("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:r("markdownRenderer.code.actions.disableWrapTitle"),enableTableWrap:r("markdownRenderer.table.actions.enableWrapTitle"),disableTableWrap:r("markdownRenderer.table.actions.disableWrapTitle"),copyTable:r("markdownRenderer.table.actions.copyTitle"),downloadTable:r("markdownRenderer.table.actions.downloadTitle"),copyDiagram:r("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:r("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:r("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:r("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:r("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:r("terminalView.preview.open"),previewTitle:r("terminalView.preview.openTitle")}),[r]),i=z(w=>w.codeBlockLineWrap),s=z(w=>w.setCodeBlockLineWrap),c=E.useCallback(()=>{s(!z.getState().codeBlockLineWrap)},[s]),b=z(w=>w.tableCellWrap),u=z(w=>w.setTableCellWrap),p=E.useCallback(()=>{u(!z.getState().tableCellWrap)},[u]);return E.useMemo(()=>{const w=Dn(t),y=z.getState().mermaidRenderingMode,g=t.metadata?.id??"theme";return{labels:o,mermaidControls:n,codeBlockLineWrap:i,onToggleCodeBlockLineWrap:c,tableCellWrap:b,onToggleTableCellWrap:p,renderMermaid:L=>Wn(`${g}:${y}:${L}`,()=>{try{return y==="ascii"?{ascii:ut(L)}:{svg:mt(L,w)}}catch{return{}}}),onPreviewLoopback:e,getCopyFormat:Bn}},[t,o,n,i,c,b,p,e])},lt=({containerRef:t,text:e,streaming:n,imageMode:r="inline",rawHtml:o="escape",syntaxVars:i,ctx:s,domCacheKey:c,tableLayoutSettled:b})=>{E.useEffect(()=>{en()},[]);const u=E.useRef(null),p=E.useRef(0),R=E.useRef(null),w=E.useRef(null),y=E.useRef(null),g=E.useCallback(()=>{const d=t.current;if(d){if(!u.current){if(!K(d))return;u.current=Dt(d);return}u.current.refresh()}},[t]),{tableCellWrap:O}=s,L=E.useCallback(()=>{const d=t.current,l=d?.querySelector("[data-markdown-content]")??d;l&&(Bt(l,O),!w.current&&l.querySelector('table[data-markdown="table"]')&&(w.current=nn(l,()=>B.current())))},[t,O]),N=E.useCallback(()=>{if(!b)return;const d=R.current;d!==null&&window.cancelAnimationFrame(d);const l=p.current,S=window.requestAnimationFrame(()=>{R.current===S&&(R.current=null,p.current===l&&L())});R.current=S},[L,b]),F=E.useCallback(()=>{const d=R.current;d!==null&&window.cancelAnimationFrame(d),R.current=null,L()},[L]),B=E.useRef(N);E.useEffect(()=>{B.current=N},[N]),E.useEffect(()=>()=>{w.current?.(),w.current=null;const d=R.current;d!==null&&(window.cancelAnimationFrame(d),R.current=null)},[]),E.useLayoutEffect(()=>{const d=t.current,l=d?.querySelector("[data-markdown-content]")??d;if(l)for(const[S,v]of Object.entries(i))l.style.setProperty(S,v)},[t,i]),E.useLayoutEffect(()=>{p.current+=1,y.current=null},[s,r,o,n,e]),E.useLayoutEffect(()=>{if(!c)return;const d=t.current,l=d?.querySelector("[data-markdown-content]")??d;if(!l||l.childNodes.length>0)return;const S=Ie.take(c);if(S){l.appendChild(S),Se(l);const v=Re(s);for(const a of Array.from(l.children))a.setAttribute(Z,v);$t(l,s.codeBlockLineWrap,s.labels),Kt(l,s.tableCellWrap,s.labels),y.current={key:c,copiedLabel:s.labels.copied},oe("ui.markdown_renderer.dom_cache.hit")}},[t,s,c,e.length]),E.useLayoutEffect(()=>{const d=t.current,l=d?.querySelector("[data-markdown-content]")??d;if(l)return()=>{const S=y.current;if(!S||l.childNodes.length===0||K(l)||Array.from(l.children).some(_=>!_.hasAttribute("data-md-id"))||l.querySelector("[data-md-copy-pending]"))return;const v=window.getSelection();if(v?.rangeCount&&!v.isCollapsed&&v.getRangeAt(0).intersectsNode(l))return;const a=l.querySelector("[data-md-menu]:not(.hidden)"),m=Array.from(l.querySelectorAll("[data-md-action]")).some(_=>_.getAttribute("title")===S.copiedLabel);if(a||m)return;Fn(l);const k=document.createDocumentFragment();k.append(...Array.from(l.childNodes)),Ie.store({...S.key,fragment:k}),oe("ui.markdown_renderer.dom_cache.capture")}},[t]),E.useLayoutEffect(()=>{const d=t.current,l=d?.querySelector("[data-markdown-content]")??d;if(!l)return;const S=Re(s);if(e&&l.childNodes.length===0){const v=Ft(e,n,r,o);let a=!1;for(const m of v){const k=document.createElement("div");k.setAttribute("data-md-block",""),k.style.display="contents",k.innerHTML=m.html,Ae(k,s),k.setAttribute("data-md-id",m.id),k.setAttribute(Z,S),a||=K(k),l.appendChild(k)}a&&g(),Se(l),b&&F()}else!u.current&&K(l)&&g()},[t,e,n,r,o,s,g,b,F]),E.useEffect(()=>()=>{u.current?.cleanup(),u.current=null},[]),E.useEffect(()=>{const d=t.current;if(!d)return;const l=d.querySelector("[data-markdown-content]")??d;let S=!0;const v=p.current,a=Re(s);if(!n){const m=It(e,r,o);if(m&&xn(l,m,a)){y.current=c?{key:c,copiedLabel:s.labels.copied}:null,oe("ui.markdown_renderer.settled_paint.reused"),N();return}}return xt(e,n,r,o).then(m=>{if(!S||p.current!==v)return;const k=Array.from(l.children),_=b&&l.querySelector('table[data-md-table-layout="fixed"]')!==null,I=Array.from(l.querySelectorAll("details[data-md-details]")).map(A=>({summary:A.querySelector("summary")?.textContent,open:A.open}));let f=0;m.forEach((A,T)=>{let h=k[T],x=!1;if(h||(h=document.createElement("div"),h.setAttribute("data-md-block",""),h.style.display="contents",l.appendChild(h),x=!0),h.getAttribute("data-md-id")===A.id){if(h.getAttribute(Z)!==a){const D=K(h);D&&(u.current?.cleanup(),u.current=null);const P=document.createElement("div");P.setAttribute("data-md-block",""),P.style.display="contents",P.innerHTML=A.html,Ae(P,s),P.setAttribute("data-md-id",A.id),P.setAttribute(Z,a),h.replaceWith(P),(D||K(P))&&g()}!u.current&&K(h)&&g();return}const H=h.getAttribute("data-md-id"),W=H&&h.getAttribute(Z)===a?A.patchFrom?.(H):null;if(W&&Vt(h,W)){In(h),h.setAttribute("data-md-id",A.id);return}const $=document.createElement("div");if($.innerHTML=A.html,Ae($,s),x&&n&&T>0){const D=Math.min(f,4)*55;f+=1;for(const P of Array.from($.children))P.classList.add("oc-md-block-enter"),D>0&&P instanceof HTMLElement&&P.style.setProperty("--oc-md-enter-delay",`${D}ms`)}const ae=K(h),Q=K($);dt(h,$,{childrenOnly:!0,onBeforeElUpdated:(D,P)=>(D.matches("details[data-md-details]")&&P.matches("details[data-md-details]")&&D.querySelector("summary")?.textContent===P.querySelector("summary")?.textContent&&P.toggleAttribute("open",D.hasAttribute("open")),!D.isEqualNode(P))}),h.setAttribute("data-md-id",A.id),h.setAttribute(Z,a),(ae||Q||K(h))&&g()});const M=K(l);let C=!1;for(let A=k.length-1;A>=m.length;A-=1){const T=k[A];T&&K(T)&&(C=!0),T?.remove()}Se(l),(C||k.length>m.length&&M)&&g(),I.length>0&&l.querySelectorAll("details[data-md-details]").forEach((A,T)=>{const h=I[T];h&&h.summary===A.querySelector("summary")?.textContent&&(A.open=h.open)}),y.current=c?{key:c,copiedLabel:s.labels.copied}:null,_?F():N()}),()=>{S=!1}},[t,s,c,r,o,g,F,N,n,b,e]),E.useEffect(()=>{const d=t.current;if(d)return Ht(d,s)},[t,s])},ct=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",$n=t=>{const e=ie.c(40),{content:n,part:r,messageId:o,isAnimated:i,skipFadeIn:s,className:c,isStreaming:b,variant:u,onShowPopup:p,enableFileReferences:R}=t,w=i===void 0?!0:i,y=s===void 0?!1:s,g=b===void 0?!1:b,O=u===void 0?"assistant":u,L=R===void 0?!0:R;oe("ui.markdown_renderer.render"),g&&oe("ui.markdown_renderer.render.streaming"),Mt("ui.markdown_renderer.content_len",n.length);const N=Qe(),{editor:F,runtime:B}=Be(),d=E.useRef(null),l=$e()??"",S=z(Un);let v;e[0]!==l||e[1]!==S?(v=q=>{l&&S(l,q)},e[0]=l,e[1]=S,e[2]=v):v=e[2];const a=v;let m;e[3]!==p?(m={containerRef:d,onShowPopup:p,enableFullscreen:et,enablePanZoom:Y.showPanZoomControls},e[3]=p,e[4]=m):m=e[4],it(m);const k=L&&!g;let _;e[5]!==F||e[6]!==l||e[7]!==B.isVSCode||e[8]!==k?(_={containerRef:d,effectiveDirectory:l,editor:F,preferRuntimeEditor:B.isVSCode,enabled:k},e[5]=F,e[6]=l,e[7]=B.isVSCode,e[8]=k,e[9]=_):_=e[9],st(_);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I={containerRef:d},e[10]=I):I=e[10],Je(I);let f;e[11]!==N?(f=Ke(N),e[11]=N,e[12]=f):f=e[12];const M=f,C=at(N,l?a:void 0,Y),{locale:A}=He(),T=O==="assistant"?"label":"local",h=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let x;e[13]===Symbol.for("react.memo_cache_sentinel")?(x=vt(),e[13]=x):x=e[13];const H=x,W=h?.sessionID,$=h?.messageID,ae=h?.id;let Q;e:{if(g||!W||!$||!ae||n.length===0||n.length>On){Q=null;break e}const q=`${H}\0${W}`,ge=`${$}\0${ae}\0${T}\0${n.length}`;let ue;e[14]!==l||e[15]!==A||e[16]!==q||e[17]!==ge?(ue={scope:q,id:ge,locale:A,directory:l},e[14]=l,e[15]=A,e[16]=q,e[17]=ge,e[18]=ue):ue=e[18],Q=ue}const D=Q,P=`markdown-${r?.id?`part-${r.id}`:`message-${o}`}`,we=!g;let le;e[19]!==n||e[20]!==C||e[21]!==D||e[22]!==T||e[23]!==g||e[24]!==M||e[25]!==we?(le={containerRef:d,text:n,streaming:g,imageMode:T,syntaxVars:M,ctx:C,domCacheKey:D,tableLayoutSettled:we},e[19]=n,e[20]=C,e[21]=D,e[22]=T,e[23]=g,e[24]=M,e[25]=we,e[26]=le):le=e[26],lt(le);let j;e[27]!==c?(j=qe("break-words w-full min-w-0",c),e[27]=c,e[28]=j):j=e[28];let X;e[29]!==O?(X=ct(O),e[29]=O,e[30]=X):X=e[30];let G;e[31]!==X?(G=re.jsx("div",{className:X,"data-markdown-content":!0}),e[31]=X,e[32]=G):G=e[32];let ce;e[33]!==j||e[34]!==G?(ce=re.jsx("div",{className:j,ref:d,children:G}),e[33]=j,e[34]=G,e[35]=ce):ce=e[35];const de=ce;if(w){let q;return e[36]!==P||e[37]!==de||e[38]!==y?(q=re.jsx(Ct,{skipAnimation:y,children:de},P),e[36]=P,e[37]=de,e[38]=y,e[39]=q):q=e[39],q}return de},Qo=E.memo($n,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&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),Kn=t=>{const e=ie.c(31),{content:n,className:r,variant:o,disableLinkSafety:i,stripFrontmatter:s,onShowPopup:c,mermaidControls:b,allowMermaidWheelEvents:u,enableFileReferences:p,allowRawHtml:R}=t,w=o===void 0?"assistant":o,y=s===void 0?!1:s,g=b===void 0?Y:b,O=u===void 0?!1:u,L=p===void 0?!0:p,N=R===void 0?!1:R,{editor:F,runtime:B}=Be(),d=Qe(),l=E.useRef(null),S=$e()??"";let v;e[0]!==n||e[1]!==y?(v=y?wn(n):n,e[0]=n,e[1]=y,e[2]=v):v=e[2];const a=v;let m;e[3]!==O||e[4]!==g.showPanZoomControls||e[5]!==c?(m={containerRef:l,onShowPopup:c,enableFullscreen:et,enablePanZoom:g.showPanZoomControls,allowMermaidWheelEvents:O},e[3]=O,e[4]=g.showPanZoomControls,e[5]=c,e[6]=m):m=e[6],it(m);let k;e[7]!==F||e[8]!==S||e[9]!==L||e[10]!==B.isVSCode?(k={containerRef:l,effectiveDirectory:S,editor:F,preferRuntimeEditor:B.isVSCode,enabled:L},e[7]=F,e[8]=S,e[9]=L,e[10]=B.isVSCode,e[11]=k):k=e[11],st(k);const _=!i;let I;e[12]!==_?(I={containerRef:l,enabled:_},e[12]=_,e[13]=I):I=e[13],Je(I);let f;e[14]!==d?(f=Ke(d),e[14]=d,e[15]=f):f=e[15];const M=f,C=at(d,void 0,g),A=N?"sanitize":"escape";let T;e[16]!==C||e[17]!==a||e[18]!==M||e[19]!==A?(T={containerRef:l,text:a,streaming:!1,imageMode:"local",rawHtml:A,syntaxVars:M,ctx:C,tableLayoutSettled:!0},e[16]=C,e[17]=a,e[18]=M,e[19]=A,e[20]=T):T=e[20],lt(T);let h;e[21]!==r?(h=qe("break-words w-full min-w-0",r),e[21]=r,e[22]=h):h=e[22];let x;e[23]!==w?(x=ct(w),e[23]=w,e[24]=x):x=e[24];const H=N?"":void 0;let W;e[25]!==x||e[26]!==H?(W=re.jsx("div",{className:x,"data-markdown-content":!0,"data-markdown-html":H}),e[25]=x,e[26]=H,e[27]=W):W=e[27];let $;return e[28]!==h||e[29]!==W?($=re.jsx("div",{className:h,ref:l,children:W}),e[28]=h,e[29]=W,e[30]=$):$=e[30],$},Jo=E.memo(Kn,(t,e)=>{const n=t.mermaidControls??Y,r=e.mermaidControls??Y;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&&t.allowRawHtml===e.allowRawHtml});function Hn(t){St(t)}function qn(t){Rt(t)}function zn(t){Lt(t.sessionId,t.messageId)}function Un(t){return t.openContextPreview}export{Qo as MarkdownRenderer,Jo as SimpleMarkdownRenderer};