@openchamber/web 2.3.2 → 2.3.3
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.
- package/dist/assets/{AboutDialog-MZbHWRua.js → AboutDialog-Ctk2zvrv.js} +1 -1
- package/dist/assets/{ArchiveView-CkeSWPcI.js → ArchiveView-sbNreasJ.js} +1 -1
- package/dist/assets/{CommandPalette-CtKzNzwW.js → CommandPalette-BICwnwAZ.js} +2 -2
- package/dist/assets/{DiffView-DaXjHTAq.js → DiffView-B5yeuxv8.js} +1 -1
- package/dist/assets/{FilesView-DMNYEydF.js → FilesView-ni2zfAwL.js} +7 -7
- package/dist/assets/{GitView-HXttTpUw.js → GitView-C0QgeC9O.js} +3 -3
- package/dist/assets/{GuestSurfacePane-KzguENQG.js → GuestSurfacePane-D1gLktSj.js} +1 -1
- package/dist/assets/{HelpDialog-9YZGhBgT.js → HelpDialog-CxC6qTaS.js} +1 -1
- package/dist/assets/{InProgressOperationBanner-DzGIwGH2.js → InProgressOperationBanner-JFV70YFh.js} +1 -1
- package/dist/assets/{JsonTreeView-D9rP8jM8.js → JsonTreeView-RsbV4Usa.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-CZK5DoOX.js +1 -0
- package/dist/assets/{MemoryDebugPanel-Ct0h3RWh.js → MemoryDebugPanel-caUWOKiz.js} +1 -1
- package/dist/assets/{OnboardingScreen-B5Zzb1Mp.js → OnboardingScreen-BDT-J2JP.js} +1 -1
- package/dist/assets/{OpenCodeStatusDialog-CXBWWRh8.js → OpenCodeStatusDialog-Cxa2yqOB.js} +1 -1
- package/dist/assets/{PatchDiff-DhDAQ5em.js → PatchDiff-C1pnbAsJ.js} +1 -1
- package/dist/assets/{PierreDiffViewer-DPa08AmN.js → PierreDiffViewer-D0zX2Msu.js} +1 -1
- package/dist/assets/PlanView-BxRCMuGe.js +5 -0
- package/dist/assets/{ProjectActionsDialog-DATu0aBc.js → ProjectActionsDialog-D660By4K.js} +1 -1
- package/dist/assets/{RunOverview-D6xy_vME.js → RunOverview-C1uTMnQS.js} +2 -2
- package/dist/assets/{ScheduledTasksDialog-BWXVnfrf.js → ScheduledTasksDialog-S-gAgo7Z.js} +5 -5
- package/dist/assets/SettingsView-CVpfbdob.js +30 -0
- package/dist/assets/{SettingsWindow-Cx6TrtY0.js → SettingsWindow-Dd1hHvgh.js} +1 -1
- package/dist/assets/SourceBoardView-DbGWAxtS.js +1 -0
- package/dist/assets/SpaceAccessDialog-muTSsEJ9.js +1 -0
- package/dist/assets/{SpaceApplyDialog-BtuwtlaG.js → SpaceApplyDialog-Dsf6MNGm.js} +1 -1
- package/dist/assets/{SpaceRow-MXqvd-dr.js → SpaceRow-7Z6ebRtm.js} +1 -1
- package/dist/assets/{SpaceSetupOutput-Uo5LS7Jy.js → SpaceSetupOutput-BytPfCOC.js} +1 -1
- package/dist/assets/{SpacesView-DvoOh4sM.js → SpacesView-CYCrlp0D.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CyMwDeoP.js → SubmoduleDiffSummary-VrNUbIqF.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BaUZIVzc.js → ToolOutputDialog-DHORjBND.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-DmMwdcF4.js → ToolPartDiffPreview-BLAXe7C5.js} +1 -1
- package/dist/assets/{UsageStatsView-D7WrDBTC.js → UsageStatsView-BxtYEAa0.js} +1 -1
- package/dist/assets/{Virtualizer-CnU8pYMb.js → Virtualizer-Bl4Cf-H-.js} +1 -1
- package/dist/assets/{WalkthroughView-r0Ho9F4Z.js → WalkthroughView-B2BJJ4u5.js} +2 -2
- package/dist/assets/{WorktreesView-C-t7uxq1.js → WorktreesView-Dv0AO9dF.js} +1 -1
- package/dist/assets/{appThemeRegistry-BUY7Ge9i.js → appThemeRegistry-xm_W0svA.js} +1 -1
- package/dist/assets/{ar-HauNhDvN.js → ar-Cj8UF12m.js} +4 -4
- package/dist/assets/{computeVirtualFileMetrics-CUof18z3.js → computeVirtualFileMetrics-Cx05cmWI.js} +2 -2
- package/dist/assets/{de-fEoJ_Yyp.js → de-fSQ1ho01.js} +4 -4
- package/dist/assets/{decorate-BkTSGAlD.js → decorate-jpF7GA6t.js} +2 -2
- package/dist/assets/{es-CKNTBsZW.js → es-DrdzhSlK.js} +5 -5
- package/dist/assets/{fileContentPoller-BJWgy1fX.js → fileContentPoller-C0f20jNG.js} +3 -3
- package/dist/assets/{flexokiTheme-BArobfXV.js → flexokiTheme-DKNCYSqL.js} +1 -1
- package/dist/assets/{fr-C23655Pi.js → fr-Cmz6Da4q.js} +4 -4
- package/dist/assets/{he-CphXS_Fv.js → he-COJRUNy4.js} +4 -4
- package/dist/assets/{index-B27cSA9V.js → index-C8Mw8uvl.js} +1 -1
- package/dist/assets/{initializeSharedPreferences-CucsmDMw.js → initializeSharedPreferences-U9-v9mfq.js} +1 -1
- package/dist/assets/{isDiffPlainText-DSCjvV0m.js → isDiffPlainText-DW43IghW.js} +1 -1
- package/dist/assets/{isFilePlainText-C7g4UPox.js → isFilePlainText-Duq5CiuG.js} +1 -1
- package/dist/assets/{ja-BmsU2iQe.js → ja-Ce0NvDHZ.js} +4 -4
- package/dist/assets/katex-BZNCT55U.css +1 -0
- package/dist/assets/katex.min-EZjpSwGK.js +65 -0
- package/dist/assets/{ko-CxISpkje.js → ko-BGFcCLLq.js} +4 -4
- package/dist/assets/main-BUetg9hg.js +1048 -0
- package/dist/assets/{main-CGPiw9fS.js → main-Be_jmIlF.js} +2 -2
- package/dist/assets/markdownCore-BkTeS4gA.js +10 -0
- package/dist/assets/{miniChat-DVEKVYKe.js → miniChat-g1RgiLLS.js} +2 -2
- package/dist/assets/{mobile-Q_FVBe4I.js → mobile-DBli3U-T.js} +2 -2
- package/dist/assets/{moveWorkspacePath-CyZJ-2aD.js → moveWorkspacePath-CnYc96Xo.js} +1 -1
- package/dist/assets/{nl-jnTBQ_gU.js → nl-Cu1nxo5t.js} +4 -4
- package/dist/assets/{parseDiffFromFile-OHXXXyzL.js → parseDiffFromFile-DEjkjYod.js} +3 -3
- package/dist/assets/{patchFileDiff-BZrb6h2u.js → patchFileDiff-D__42sau.js} +5 -5
- package/dist/assets/{pierreDiffTint-DHf2xvyt.js → pierreDiffTint-3oatL635.js} +4 -4
- package/dist/assets/pl-4LdEMgWI.js +20 -0
- package/dist/assets/{pt-BR-BfpsFrHv.js → pt-BR-2UbEBNgC.js} +5 -5
- package/dist/assets/{relocateRestoredSession-DInneXVI.js → relocateRestoredSession-pkxyd_lV.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-D0tKJFBB.js +2 -0
- package/dist/assets/renderMobileApp-D6bOYHuP.js +25 -0
- package/dist/assets/{restartOpenCode-DwBaMPJK.js → restartOpenCode-FYqjpaWc.js} +1 -1
- package/dist/assets/runtimeEndpointReset-6CNNzem4.js +74 -0
- package/dist/assets/{scheduledTasksApi-ClJplEhR.js → scheduledTasksApi-BbnQ4W-W.js} +1 -1
- package/dist/assets/{selectionMarkdown-BuveYuup.js → selectionMarkdown-D8QAxC44.js} +1 -1
- package/dist/assets/sessionOwnership-BBuf0UCB.js +1 -0
- package/dist/assets/{shikiHighlight-DJAESrna.js → shikiHighlight-CweIj1cL.js} +1 -1
- package/dist/assets/{space-apply-DWFLwXbI.js → space-apply-CEi013sa.js} +1 -1
- package/dist/assets/{space-close-BYDbwdWc.js → space-close-BuStkLrZ.js} +1 -1
- package/dist/assets/{spaceNetwork-DHrhfbKM.js → spaceNetwork-tH2d5Mgs.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-DcAZmUlv.js → textMateThemeFromAppTheme-DLJBL6al.js} +1 -1
- package/dist/assets/tr-Bg0Qt-mG.js +11 -0
- package/dist/assets/{uk-C82aEtvs.js → uk-vcnOugr0.js} +5 -5
- package/dist/assets/useAppFontEffects-Cs6k0JKv.js +773 -0
- package/dist/assets/{useCallableModelProviders-BU_455MN.js → useCallableModelProviders-BsGEzsl2.js} +1 -1
- package/dist/assets/{useInlineCommentController-AuUrVz9U.js → useInlineCommentController-CVYaPzfO.js} +2 -2
- package/dist/assets/{useRootScrollLock-Cpk7NmBa.js → useRootScrollLock-Dov-44ov.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-BYGweLoh.js → vendor-codemirror-language-data-DBekkZIx.js} +2 -2
- package/dist/assets/vendor-tanstack-react-virtual-Dozz-7fb.js +1 -0
- package/dist/assets/vendor-tanstack-virtual-core-DKBj55Em.js +1 -0
- package/dist/assets/{vendor-yaml-3778uTud.js → vendor-yaml-CE-D_49-.js} +1 -1
- package/dist/assets/{zh-CN-DEq7j9I5.js → zh-CN-C3UhwFsk.js} +5 -5
- package/dist/assets/{zh-TW-DgCN99T-.js → zh-TW-D0CmmMvp.js} +5 -5
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +5 -5
- package/server/index.js +13 -1
- package/server/lib/agent-memory/actions.js +22 -9
- package/server/lib/agent-memory/actions.test.js +57 -0
- package/server/lib/agent-memory/runtime.js +8 -5
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -1
- package/server/lib/agent-tool/runtime.js +41 -7
- package/server/lib/agent-tool/runtime.test.js +11 -0
- package/server/lib/git/DOCUMENTATION.md +17 -5
- package/server/lib/git/lfs-discovery.js +7 -4
- package/server/lib/git/lfs-discovery.test.js +60 -0
- package/server/lib/git/network-operations.js +9 -3
- package/server/lib/git/network-operations.test.js +31 -2
- package/server/lib/git/service.js +72 -12
- package/server/lib/git/service.test.js +65 -0
- package/server/lib/github/DOCUMENTATION.md +1 -0
- package/server/lib/github/reference-search.js +49 -18
- package/server/lib/github/reference-search.test.js +28 -6
- package/server/lib/github/routes.js +87 -1
- package/server/lib/github/routes.mutations.test.js +38 -0
- package/server/lib/github/routes.test.js +1 -0
- package/server/lib/gitlab/DOCUMENTATION.md +4 -0
- package/server/lib/gitlab/client.js +23 -0
- package/server/lib/gitlab/client.test.js +28 -1
- package/server/lib/gitlab/mappers.js +9 -0
- package/server/lib/gitlab/resources.js +153 -4
- package/server/lib/gitlab/resources.test.js +107 -0
- package/server/lib/gitlab/routes.js +120 -1
- package/server/lib/gitlab/routes.test.js +59 -0
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +14 -2
- package/server/lib/markdown-image-grants/routes.test.js +23 -0
- package/server/lib/notifications/APNS.md +24 -23
- package/server/lib/notifications/DOCUMENTATION.md +2 -2
- package/server/lib/notifications/apns-runtime.js +8 -5
- package/server/lib/notifications/apns-runtime.test.js +26 -0
- package/server/lib/notifications/message.js +5 -3
- package/server/lib/notifications/message.test.js +9 -0
- package/server/lib/notifications/runtime.js +44 -9
- package/server/lib/notifications/trigger-runtime.test.js +84 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +18 -2
- package/server/lib/openchamber-control/project-knowledge.js +17 -3
- package/server/lib/openchamber-control/project-knowledge.test.js +14 -0
- package/server/lib/openchamber-control/render-page.js +58 -0
- package/server/lib/openchamber-control/service.js +9 -0
- package/server/lib/openchamber-control/service.test.js +43 -0
- package/server/lib/openchamber-sessions/routes.js +1 -0
- package/server/lib/openchamber-sessions/worktree-move.js +26 -10
- package/server/lib/openchamber-sessions/worktree-move.test.js +36 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/managed-config-file.js +3 -2
- package/server/lib/opencode/managed-config-file.test.js +20 -6
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/plan-progress.js +69 -0
- package/server/lib/project-context/plan-progress.test.js +58 -0
- package/server/lib/project-context/routes.http.test.js +22 -0
- package/server/lib/project-context/routes.js +20 -0
- package/server/lib/project-context/runtime.js +132 -18
- package/server/lib/project-context/runtime.test.js +58 -0
- package/server/lib/provider-read-cache/index.js +7 -1
- package/server/lib/provider-read-cache/index.test.js +12 -0
- package/server/lib/relay/DOCUMENTATION.md +17 -1
- package/server/lib/session-knowledge/DOCUMENTATION.md +17 -0
- package/server/lib/session-knowledge/runtime.js +29 -6
- package/server/lib/session-knowledge/runtime.test.js +26 -1
- package/server/lib/source-control/audit-storage.js +1 -0
- package/server/lib/source-control/mutation-storage.js +3 -0
- package/server/lib/spaces/DOCUMENTATION.md +14 -9
- package/server/lib/spaces/code-out.js +13 -4
- package/server/lib/spaces/code-out.test.js +5 -3
- package/server/lib/spaces/dispatcher.js +12 -5
- package/server/lib/spaces/dispatcher.test.js +19 -1
- package/server/lib/spaces/gatekeeper-channel.js +8 -7
- package/server/lib/spaces/gatekeeper-channel.test.js +10 -0
- package/server/lib/spaces/gatekeeper-program.cjs +38 -3
- package/server/lib/spaces/gatekeeper-program.test.js +20 -0
- package/server/lib/spaces/hardening.js +14 -1
- package/server/lib/spaces/hardening.test.js +5 -0
- package/server/lib/spaces/host-providers.js +165 -0
- package/server/lib/spaces/host-providers.test.js +100 -0
- package/server/lib/spaces/host.js +16 -4
- package/server/lib/spaces/journey.js +87 -17
- package/server/lib/spaces/journey.test.js +90 -2
- package/server/lib/spaces/layout.js +15 -5
- package/server/lib/spaces/places/docker-live-support.js +2 -0
- package/server/lib/spaces/places/docker.test.js +2 -0
- package/server/lib/spaces/places/fake-docker.js +3 -0
- package/server/lib/spaces/places/grants.docker.live.test.js +71 -7
- package/server/lib/spaces/routes.js +9 -0
- package/server/lib/spaces/routes.test.js +4 -2
- package/server/lib/spaces/space-opencode.js +31 -14
- package/server/lib/spaces/space-opencode.test.js +15 -2
- package/server/lib/spaces/space-records.js +8 -0
- package/server/lib/spaces/space-records.test.js +7 -3
- package/server/lib/spaces/websocket.test.js +13 -1
- package/server/lib/ui-auth/ui-auth.js +28 -3
- package/server/lib/ui-auth/ui-auth.test.js +31 -0
- package/dist/assets/MarkdownRendererImpl-B2LsA09C.js +0 -1
- package/dist/assets/PlanView-Dt5EN_JK.js +0 -5
- package/dist/assets/SettingsView-BolP_tuu.js +0 -30
- package/dist/assets/SourceBoardView-yca1qvgB.js +0 -1
- package/dist/assets/SpaceAccessDialog-CZ-u75py.js +0 -1
- package/dist/assets/katex-rNcbfUj4.css +0 -1
- package/dist/assets/katex.min-DQ8qF6NR.js +0 -65
- package/dist/assets/main-CVHM3_8W.js +0 -1048
- package/dist/assets/markdownCore-D5ZOJXeO.js +0 -9
- package/dist/assets/pl-Bj-Hy0X5.js +0 -20
- package/dist/assets/renderElectronMiniChatApp-B_5BeSF6.js +0 -2
- package/dist/assets/renderMobileApp-DGEXUTk-.js +0 -25
- package/dist/assets/runtimeEndpointReset-CIpvn8QG.js +0 -59
- package/dist/assets/sessionOwnership-BZoGed9N.js +0 -1
- package/dist/assets/tr-qMRMBQ8r.js +0 -11
- package/dist/assets/useAppFontEffects-Bih1DxXi.js +0 -745
- package/dist/assets/vendor-tanstack-react-virtual-CvuLsk7D.js +0 -1
- package/dist/assets/vendor-tanstack-virtual-core-DPaNcJcT.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ea as B,eG as ae,eH as Ve,dZ as Ae,eI as Pe,eJ as De,eK as _e,eL as Be,d_ as Ue,u as We,B as le,I as he,eM as Ge}from"./useAppFontEffects-Bih1DxXi.js";import{g as F,b as je,c as we,i as Ke,s as He,e as $e,f as de,h as qe,j as Je,k as Ye,l as Xe,m as Ze,R as Qe,I as et,n as ce,r as tt,o as ue,w as it,t as nt,u as st,v as rt,x as ot,y as at,z as fe,A as lt,B as ht,C as dt,D as ct,E as ut,F as ft,G as ge,S as gt,H as pt,J as mt,K as St,a as Ee,L as Ct,M as vt}from"./parseDiffFromFile-OHXXXyzL.js";import{c as R,G as Rt,u as yt,W as Lt,a as Tt,b as W,n as pe,t as At}from"./Virtualizer-BP6uuKe_.js";import{j as v,r as M,R as I}from"./vendor-react-BUCujlKS.js";import{x as G,y as ie,g as Y,n as me,i as xe,z as Se,A as wt,B as Ce,k as Me,C as ve,a as Ht,l as Et,D as xt,E as Re,F as j,G as ye}from"./computeVirtualFileMetrics-CUof18z3.js";import{a as x,i as X,l as K,h as Mt,r as bt}from"./isFilePlainText-C7g4UPox.js";import{t as V}from"./vendor-hast-util-to-html-BKBhbTDb.js";import{s as Ft}from"./vendor-strip-json-comments-5dJlOkP1.js";import"./katex.min-DQ8qF6NR.js";function $(i,e){return e.cacheKey==null?i.file===e&&i.sourceContents===e.contents:i.cacheKey===e.cacheKey}let kt=-1;var zt=class{options;annotationSlotName;onRenderUpdate;workerManager;__id=`file-renderer:${++kt}`;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(c=>c[2]).join("");a.lines[l]=je(a.lines[l]??"",u)}const d={type:"element",tagName:"div",properties:{"data-line":l+1,"data-line-type":"context","data-line-index":l},children:h.map(([u,c,f])=>u===0&&c===""?f===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:f}:{type:"element",tagName:"span",properties:{"data-char":u,style:`color:${c};`},children:[{type:"text",value:f}]})};o!=null?o.set(l,d):s.code[l]=d}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 d=0;for(;d<l-h&&s[s.length-1-d]===o[o.length-1-d];)d++;const u=r.code;r.code=new Array(o.length);for(let c=0;c<h;c++)r.code[c]=u[c];for(let c=0;c<d;c++)r.code[o.length-1-c]=u[s.length-1-c];if(e!==void 0)for(const[c,f]of e)c<o.length&&(r.code[c]=f);for(let c=h;c<o.length-d;c++)r.code[c]??={type:"element",tagName:"div",properties:{"data-line":c+1,"data-line-type":"context","data-line-index":c},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(c)}]}]};for(let c=0;c<r.code.length;c++){const f=r.code[c];f?.type==="element"&&(f.properties["data-line"]=c+1,f.properties["data-line-index"]=c)}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),d=!we(this.renderCache.renderRange,e);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!a&&!h&&Ke(e);l&&!u&&(a||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||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),c=this.highlighter!=null&&me(this.computedLang),f=!a&&c;if(l&&this.highlighter!=null&&u&&(n||a||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderFileWithHighlighter(i,this.highlighter,a||!c);this.renderCache={file:i,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!a&&!c)&&this.asyncHighlight(i).then(({result:p,options:g})=>{this.applyHighlightResult(i,p,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&&Mt(xe(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:bt(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 d=0;const u=He(e)?$e(this.lineAnnotations):void 0;u!=null&&(l.children.push(Se("context","annotation",1)),a.push(de({hunkIndex:-1,lineIndex:-1,annotations:u.map(c=>this.annotationSlotName(c))})),d++);for(let c=e.startingLine;c<h;c++){const f=c+1,p=t[c];if(p==null){const S="FileRenderer.processFileResult: Line doesnt exist";throw console.error(S,{name:i.name,lineIndex:c,lineNumber:f}),new Error(S)}l.children.push(wt("context",f,`${c}`)),a.push(p),d++;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))})),d++)}return l.properties.style=`grid-row: span ${d}`,{file:i,gutterAST:l.children??[],contentAST:a,preAST:this.createPreElement(s),headerAST:o?void 0:this.renderHeader(i),totalLines:s,rowCount:d,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return qe({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,Je(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 Me(Ye(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 Xe({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function q(i,e){return i>e}function Nt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function Le(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:Ze(i),tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const Ot=[""];function It(i){const e={...i};return delete e.cacheKey,e}let Vt=-1;var be=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Vt}`;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 zt(e,this.getAnnotationSlotName,this.handleHighlightRender,this.workerManager),this.resizeManager=new Qe,this.interactionManager=new et("file",ce(e)),this.workerManager?.subscribeToThemeChanges(this)}getAnnotationSlotName=e=>tt(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=It(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&&!Ht(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,it(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||Pt(this.pre,s,this.options.collapsed)||Dt(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),nt(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(Le(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):Ot}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=d=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.getLatestFile()!==s||e.__syncRenderView({highlighter:d,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):Me({themes:xe(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,d=!1,u;if(t==null)throw new Error("File.__completeEditSession: editor is required for completion");const c={...o},f={file:c,editor:t,originalFile:r,lineAnnotations:l,originalLineAnnotations:s};Object.freeze(f);try{if(t.__emitEditComplete(f),this.options.onEditComplete?.(f)==="accept"){if(c.cacheKey!=null&&c.cacheKey===r.cacheKey)throw new Error("File.__completeEditSession: an accepted file must not reuse the replaced file cacheKey");h=c}}catch(S){d=!0,u=S}e&&h!=null&&(this.file=h,l!=null&&(this.lineAnnotations=l)),this.editSession=void 0;const{renderedFile:p,file:g}=this;if(this.fileRenderer.endEditSession(g),p!=null&&g!=null&&p!==g&&R(p,g)&&(this.renderedFile=g),e&&this.fileContainer!=null&&this.rerender(),d)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:d="system"}=this.options,u=h?void 0:l,c=this.renderRange,f=this.hasThemeChanged(),p=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&&we(u,this.renderRange)&&!g&&!p&&!f){const m=this.applyCachedThemeState(d);return m&&this.finalizeRender(),m}this.renderRange=u,g&&(this.cachedHeaderHTML=void 0),this.fileRenderer.setOptions(Le(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(d),h){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(S,Ve);m!=null&&this.applyThemeState(t,m.themeStyles,d,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t,m.file),this.renderedFile=m?.file??S,this.injectUnsafeCSS()}catch(m){if(H)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return this.finalizeRender(),r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,g||f||!R(this.renderedFile,S))||!this.applyPartialRender(S,c,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,d,y.baseThemeType),y.headerAST!=null&&this.applyHeaderToDOM(y.headerAST,t,y.file),this.applyFullRender(y,m),this.renderedFile=y.file}this.applyBuffers(m,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,o||this.flushManagers(),this.finalizeRender(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(H)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,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=>{Et(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||!Nt(s,l.annotation)){l?.element.remove();const h=t(s);if(h==null)continue;l={element:st(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=rt();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??=ot(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=at(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=lt({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ht(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=dt(this.themeCSSStyle.textContent??"",fe(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&ct()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);const n=this.code=ut({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()?ft(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,d=Math.max(o,a),u=Math.min(l,h);if(u<=d)return!1;if(!this.trimDOMToOverlap(s.gutter,d,u)||!this.trimDOMToOverlap(s.content,d,u))throw new Error("File.applyPartialRender: failed to trim to overlap");let{length:c}=s.content.children;const f=(H,A)=>{if(!(A<=0))return this.fileRenderer.renderFile(e,{startingLine:H,totalLines:A,bufferBefore:0,bufferAfter:0})},p=a<d?f(a,d-a):void 0;if(p===void 0&&a<d)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(),p!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(p.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(p.contentAST)),c+=p.rowCount),S!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.contentAST)),c+=S.rowCount),this.lastRowCount!==c&&(s.gutter.style.setProperty("grid-row",`span ${c}`),s.content.style.setProperty("grid-row",`span ${c}`),this.lastRowCount=c),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,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 d=this.getLineIndexFromDOMNode(h);if(d!=null){for(;o!=null&&d>=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 d=h.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:o,renderCustomHeader:a,renderHeaderMetadata:l}=this.options;if(a!=null){const h=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ae,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,d=o?.(n)??void 0,u=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Pe,h),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,De,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,_e,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=gt;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};pt(s,this.appliedPreAttributes)||(mt(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 Pt(i,e,t=!1){return!t&&i==null&&e!=null}function Dt(i,e,t=!1){return i==null&&e!=null&&!t}const _t=5e3,J=new Map;let Bt=-1;function Ut(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 Wt=class extends be{virtualizer;metrics;__id=`virtualized-file:${++Bt}`;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=Be,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){const t=xt(i);!e&&St(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=!Ee(e,i),n=Ut(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&&He(this.renderRange)){const o=Gt(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,d=this.cache.heights.get(l);if(!n&&(d==null||d===r+h))continue;let u=o.getBoundingClientRect().height+h,c=!1;o.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in o.nextElementSibling.dataset||"noNewline"in o.nextElementSibling.dataset)&&("noNewline"in o.nextElementSibling.dataset&&(c=!0),u+=o.nextElementSibling.getBoundingClientRect().height);const f=this.getLineHeight(l,c);u!==f&&(i=!0,u===this.metrics.lineHeight*(c?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:d=!1}=this.options;return this.currentCollapsed!==d&&(this.currentCollapsed=d,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;if(n)return{top:Re(this.metrics,t),height:0};let s=j(this.metrics,t);if(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:d}=this.metrics,u=s+(o===0?l:this.renderRange.bufferBefore),c=o+Math.max(Math.ceil((i-u)/d),0);return c>a?void 0:{lineNumber:c+1,top:s+l+c*d}}let h=s+(o===0?l:this.renderRange.bufferBefore);for(let d=o;d<=a;d++){if(h>=i)return{lineNumber:d+1,top:h};h+=this.getLineHeight(d)}}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);if(s){this.height+=Re(this.metrics,r),this.layoutDirty=!1;return}const l=j(this.metrics,r),h=ye(this.metrics);if(this.height+=l,this.height+=this.cache.fileAnnotationHeight,this.hasUniformLineHeights())this.height+=a*o;else for(let d=0;d<a;d++)this.addLayoutCheckpoint(d,this.height),this.height+=this.getLineHeight(d,!1);if(a>0&&(this.height+=h),this.fileContainer!=null&&t&&!n){const d=this.fileContainer.getBoundingClientRect();d.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:d.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(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:d,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 c=this.virtualizer.getWindowSpecs(),f=this.top??0,p=this.computeRenderRangeFromWindow(o,f,c);return super.render({file:e,fileContainer:i,renderRange:p,lineAnnotations:n,forceRender:(d??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%_t===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),d=a>0?ye(this.metrics):0,{fileAnnotationHeight:u}=this.cache,c=h+u,f=Math.max(0,l-h-u-d),p=Ct(this.getLatestAnnotations()),g=e+h,S=u>0&&p&&g<n&&g+u>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};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,m=A/s,y=(t+n)/2;if(this.hasUniformLineHeights()){const O=e+c,U=O+f;if(!S&&!(O<n&&U>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};const D=Math.floor(S&&y<e+c?0:(y-(e+c))/o),b=Math.floor(D/s)-Math.floor(m/2),Ne=Math.ceil(a/s),_=Math.max(0,Math.min(b,Ne))*s,oe=b<0?A+b*s:A,Oe=_===0?0:u+_*o,Ie=Math.min(oe,a-_);return{startingLine:_,totalLines:oe,bufferBefore:Oe,bufferAfter:Math.max(0,(a-_-Ie)*o)}}const P=m,E=[],L=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-A*o*2),s);let T=e+(L?.top??c),k=L?.lineIndex??0,z,C,w;const Z=L?.lineIndex??0;for(let O=Z;O<a;O++){const U=k%s===0,D=Math.floor(k/s);if(U&&(E[D]=T-(e+c),w!=null)){if(w<=0)break;w--}const b=this.getLineHeight(O,!1);T>t-b&&T<n&&(z??=D),T+b>y&&(C??=D),w==null&&T>=n&&U&&(w=P),k++,T+=b}if(z==null)if(S)z=0,C=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};C??=z;const N=Math.round(C-m/2),Q=Math.max(0,Math.ceil(a/s)-m),ee=Math.max(0,Math.min(N,Q)),ne=ee*s,se=N<0?A+N*s:A,Fe=E[ee]??0,ke=ne===0?0:u+Fe,re=ee+se/s,ze=re<E.length?f-E[re]:f-(T-e-c);return{startingLine:ne,totalLines:se,bufferBefore:ke,bufferAfter:Math.max(0,ze)}}};function Gt(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===vt&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function jt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:o,renderGutterUtility:a,getHoveredLine:l,getAnnotationSlotName:h=F}){const d=e?.(i),u=t?.(i),c=n?.(i),f=r?.(i);return v.jsxs(v.Fragment,{children:[d!=null?v.jsx("div",{slot:Ae,children:d}):v.jsxs(v.Fragment,{children:[u!=null&&v.jsx("div",{slot:"header-prefix",children:u}),c!=null&&v.jsx("div",{slot:"header-filename-suffix",children:c}),f!=null&&v.jsx("div",{slot:"header-metadata",children:f})]}),s!=null&&o?.map((p,g)=>v.jsx("div",{slot:h(p),children:s(p)},g)),a!=null&&v.jsx("div",{slot:"gutter-utility-slot",style:Rt,children:a(l)})]})}const Kt=typeof window>"u"?M.useEffect:M.useLayoutEffect;function $t({file:i,options:e,editorOptions:t,editStateKey:n,lineAnnotations:r,selectedLines:s,prerenderedHTML:o,metrics:a,hasGutterRenderUtility:l,hasCustomHeader:h,disableWorkerPool:d,edit:u,onEditChange:c,onEditComplete:f}){const p=yt(),g=s!==void 0,S=M.useContext(Lt),H=Tt(),A=W(C=>c?.(C)),m=c!=null?A:void 0,y=M.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=M.useRef(null),T=M.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");p!=null?L.current=new Wt(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),p,a,d?void 0:S,!0):L.current=new be(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),d?void 0:S,!0),u&&T.current==null&&(T.current=Te(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 Kt(()=>{const{current:C}=L;if(C==null)return;const w=te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),Z=w!==void 0&&!Ee(C.options,w);if(C.setOptions(w),!u&&T.current!=null){const{current:Q}=T;T.current=null,Q()}const N=qt(i,r,y);C.render({file:N.file,lineAnnotations:N.lineAnnotations,forceRender:Z}),s!==void 0&&C.setSelectedLines(s),u&&T.current==null&&(T.current=Te(C,k))}),{ref:z,getHoveredLine:M.useCallback(()=>L.current?.getHoveredLine(),[]),getAnnotationSlotName:M.useCallback(C=>L.current?.getAnnotationSlotName(C)??F(C),[])}}function qt(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 Te(i,e){const t=e();try{return t.edit(i)}catch(n){throw t.cleanUp(),n}}function ri({file:i,lineAnnotations:e,selectedLines:t,options:n,editorOptions:r,editStateKey:s,metrics:o,className:a,style:l,renderAnnotation:h,renderCustomHeader:d,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,prerenderedHTML:p,renderGutterUtility:g,disableWorkerPool:S=!1,edit:H=!1,onEditChange:A,onEditComplete:m}){const{ref:y,getHoveredLine:P,getAnnotationSlotName:E}=$t({file:i,options:n,editorOptions:r,editStateKey:s,metrics:o,lineAnnotations:e,selectedLines:t,prerenderedHTML:p,hasGutterRenderUtility:g!=null,hasCustomHeader:d!=null,disableWorkerPool:S,edit:H,onEditChange:A,onEditComplete:m}),L=jt({file:i,renderAnnotation:h,renderCustomHeader:d,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderGutterUtility:g,lineAnnotations:e,getHoveredLine:P,getAnnotationSlotName:E});return v.jsx(Ue,{ref:y,className:a,style:l,children:At(L,p)})}const oi=I.memo(function({jsonString:e,format:t="json",className:n,maxHeight:r="100%",initiallyExpandedDepth:s=2}){const{t:o}=We(),a=I.useRef(null),[l,h]=I.useState(null),d=I.useMemo(()=>{try{const f=e.trim();if(!f)return h(o("jsonTreeView.error.emptyJson")),null;const p=t==="jsonc"?Ft(f,{trailingCommas:!0}):f,g=JSON.parse(p);return h(null),g}catch(f){return h(f instanceof Error?f.message:o("jsonTreeView.error.invalidJson")),null}},[e,t,o]),u=I.useCallback(()=>{a.current?.expandAll()},[]),c=I.useCallback(()=>{a.current?.collapseAll()},[]);return l?v.jsx("div",{className:n,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:o("jsonTreeView.error.invalidJsonTitle")}),v.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:l})]})}):d===null?null:v.jsxs("div",{className:n,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:u,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-down-s",className:"h-3 w-3"}),o("jsonTreeView.actions.expandAll")]}),v.jsxs(le,{variant:"ghost",size:"xs",onClick:c,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-up-s",className:"h-3 w-3"}),o("jsonTreeView.actions.collapseAll")]})]}),v.jsx("div",{className:"oc-surface-code bg-[var(--syntax-background)] py-1",style:{maxHeight:r,overflow:"auto"},children:v.jsx(Ge,{ref:a,data:d,maxHeight:r,initiallyExpandedDepth:s})})]})});export{ri as F,oi as J,Wt as V};
|
|
1
|
+
import{ed as B,eJ as ae,eK as Ve,e0 as Ae,eL as Pe,eM as De,eN as _e,eO as Be,e1 as Ue,u as We,B as le,I as he,eP as Ge}from"./useAppFontEffects-Cs6k0JKv.js";import{g as F,b as je,c as we,i as Ke,s as He,e as $e,f as de,h as qe,j as Je,k as Ye,l as Xe,m as Qe,R as Ze,I as et,n as ce,r as tt,o as ue,w as it,t as nt,u as st,v as rt,x as ot,y as at,z as fe,A as lt,B as ht,C as dt,D as ct,E as ut,F as ft,G as ge,S as gt,H as pt,J as mt,K as St,a as Ee,L as Ct,M as vt}from"./parseDiffFromFile-DEjkjYod.js";import{c as R,G as Rt,u as yt,W as Lt,a as Tt,b as W,n as pe,t as At}from"./Virtualizer-BP6uuKe_.js";import{j as v,r as M,R as I}from"./vendor-react-BUCujlKS.js";import{x as G,y as ie,g as Y,n as me,i as xe,z as Se,A as wt,B as Ce,k as Me,C as ve,a as Ht,l as Et,D as xt,E as Re,F as j,G as ye}from"./computeVirtualFileMetrics-Cx05cmWI.js";import{a as x,i as X,l as K,h as Mt,r as bt}from"./isFilePlainText-Duq5CiuG.js";import{t as V}from"./vendor-hast-util-to-html-BKBhbTDb.js";import{s as Ft}from"./vendor-strip-json-comments-5dJlOkP1.js";import"./katex.min-EZjpSwGK.js";function $(i,e){return e.cacheKey==null?i.file===e&&i.sourceContents===e.contents:i.cacheKey===e.cacheKey}let kt=-1;var zt=class{options;annotationSlotName;onRenderUpdate;workerManager;__id=`file-renderer:${++kt}`;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(c=>c[2]).join("");a.lines[l]=je(a.lines[l]??"",u)}const d={type:"element",tagName:"div",properties:{"data-line":l+1,"data-line-type":"context","data-line-index":l},children:h.map(([u,c,f])=>u===0&&c===""?f===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:f}:{type:"element",tagName:"span",properties:{"data-char":u,style:`color:${c};`},children:[{type:"text",value:f}]})};o!=null?o.set(l,d):s.code[l]=d}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 d=0;for(;d<l-h&&s[s.length-1-d]===o[o.length-1-d];)d++;const u=r.code;r.code=new Array(o.length);for(let c=0;c<h;c++)r.code[c]=u[c];for(let c=0;c<d;c++)r.code[o.length-1-c]=u[s.length-1-c];if(e!==void 0)for(const[c,f]of e)c<o.length&&(r.code[c]=f);for(let c=h;c<o.length-d;c++)r.code[c]??={type:"element",tagName:"div",properties:{"data-line":c+1,"data-line-type":"context","data-line-index":c},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(c)}]}]};for(let c=0;c<r.code.length;c++){const f=r.code[c];f?.type==="element"&&(f.properties["data-line"]=c+1,f.properties["data-line-index"]=c)}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),d=!we(this.renderCache.renderRange,e);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!a&&!h&&Ke(e);l&&!u&&(a||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||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),c=this.highlighter!=null&&me(this.computedLang),f=!a&&c;if(l&&this.highlighter!=null&&u&&(n||a||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderFileWithHighlighter(i,this.highlighter,a||!c);this.renderCache={file:i,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!a&&!c)&&this.asyncHighlight(i).then(({result:p,options:g})=>{this.applyHighlightResult(i,p,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&&Mt(xe(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:bt(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 d=0;const u=He(e)?$e(this.lineAnnotations):void 0;u!=null&&(l.children.push(Se("context","annotation",1)),a.push(de({hunkIndex:-1,lineIndex:-1,annotations:u.map(c=>this.annotationSlotName(c))})),d++);for(let c=e.startingLine;c<h;c++){const f=c+1,p=t[c];if(p==null){const S="FileRenderer.processFileResult: Line doesnt exist";throw console.error(S,{name:i.name,lineIndex:c,lineNumber:f}),new Error(S)}l.children.push(wt("context",f,`${c}`)),a.push(p),d++;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))})),d++)}return l.properties.style=`grid-row: span ${d}`,{file:i,gutterAST:l.children??[],contentAST:a,preAST:this.createPreElement(s),headerAST:o?void 0:this.renderHeader(i),totalLines:s,rowCount:d,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return qe({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,Je(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 Me(Ye(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 Xe({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function q(i,e){return i>e}function Nt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function Le(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:Qe(i),tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const Ot=[""];function It(i){const e={...i};return delete e.cacheKey,e}let Vt=-1;var be=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Vt}`;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 zt(e,this.getAnnotationSlotName,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ze,this.interactionManager=new et("file",ce(e)),this.workerManager?.subscribeToThemeChanges(this)}getAnnotationSlotName=e=>tt(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=It(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&&!Ht(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,it(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||Pt(this.pre,s,this.options.collapsed)||Dt(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),nt(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(Le(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):Ot}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=d=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.getLatestFile()!==s||e.__syncRenderView({highlighter:d,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):Me({themes:xe(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,d=!1,u;if(t==null)throw new Error("File.__completeEditSession: editor is required for completion");const c={...o},f={file:c,editor:t,originalFile:r,lineAnnotations:l,originalLineAnnotations:s};Object.freeze(f);try{if(t.__emitEditComplete(f),this.options.onEditComplete?.(f)==="accept"){if(c.cacheKey!=null&&c.cacheKey===r.cacheKey)throw new Error("File.__completeEditSession: an accepted file must not reuse the replaced file cacheKey");h=c}}catch(S){d=!0,u=S}e&&h!=null&&(this.file=h,l!=null&&(this.lineAnnotations=l)),this.editSession=void 0;const{renderedFile:p,file:g}=this;if(this.fileRenderer.endEditSession(g),p!=null&&g!=null&&p!==g&&R(p,g)&&(this.renderedFile=g),e&&this.fileContainer!=null&&this.rerender(),d)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:d="system"}=this.options,u=h?void 0:l,c=this.renderRange,f=this.hasThemeChanged(),p=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&&we(u,this.renderRange)&&!g&&!p&&!f){const m=this.applyCachedThemeState(d);return m&&this.finalizeRender(),m}this.renderRange=u,g&&(this.cachedHeaderHTML=void 0),this.fileRenderer.setOptions(Le(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(d),h){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(S,Ve);m!=null&&this.applyThemeState(t,m.themeStyles,d,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t,m.file),this.renderedFile=m?.file??S,this.injectUnsafeCSS()}catch(m){if(H)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return this.finalizeRender(),r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,g||f||!R(this.renderedFile,S))||!this.applyPartialRender(S,c,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,d,y.baseThemeType),y.headerAST!=null&&this.applyHeaderToDOM(y.headerAST,t,y.file),this.applyFullRender(y,m),this.renderedFile=y.file}this.applyBuffers(m,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,o||this.flushManagers(),this.finalizeRender(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(H)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,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=>{Et(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||!Nt(s,l.annotation)){l?.element.remove();const h=t(s);if(h==null)continue;l={element:st(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=rt();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??=ot(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=at(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=lt({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ht(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=dt(this.themeCSSStyle.textContent??"",fe(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&ct()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);const n=this.code=ut({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()?ft(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,d=Math.max(o,a),u=Math.min(l,h);if(u<=d)return!1;if(!this.trimDOMToOverlap(s.gutter,d,u)||!this.trimDOMToOverlap(s.content,d,u))throw new Error("File.applyPartialRender: failed to trim to overlap");let{length:c}=s.content.children;const f=(H,A)=>{if(!(A<=0))return this.fileRenderer.renderFile(e,{startingLine:H,totalLines:A,bufferBefore:0,bufferAfter:0})},p=a<d?f(a,d-a):void 0;if(p===void 0&&a<d)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(),p!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(p.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(p.contentAST)),c+=p.rowCount),S!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(S.contentAST)),c+=S.rowCount),this.lastRowCount!==c&&(s.gutter.style.setProperty("grid-row",`span ${c}`),s.content.style.setProperty("grid-row",`span ${c}`),this.lastRowCount=c),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,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 d=this.getLineIndexFromDOMNode(h);if(d!=null){for(;o!=null&&d>=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 d=h.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:o,renderCustomHeader:a,renderHeaderMetadata:l}=this.options;if(a!=null){const h=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ae,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,d=o?.(n)??void 0,u=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Pe,h),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,De,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,_e,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=gt;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};pt(s,this.appliedPreAttributes)||(mt(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 Pt(i,e,t=!1){return!t&&i==null&&e!=null}function Dt(i,e,t=!1){return i==null&&e!=null&&!t}const _t=5e3,J=new Map;let Bt=-1;function Ut(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 Wt=class extends be{virtualizer;metrics;__id=`virtualized-file:${++Bt}`;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=Be,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){const t=xt(i);!e&&St(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=!Ee(e,i),n=Ut(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&&He(this.renderRange)){const o=Gt(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,d=this.cache.heights.get(l);if(!n&&(d==null||d===r+h))continue;let u=o.getBoundingClientRect().height+h,c=!1;o.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in o.nextElementSibling.dataset||"noNewline"in o.nextElementSibling.dataset)&&("noNewline"in o.nextElementSibling.dataset&&(c=!0),u+=o.nextElementSibling.getBoundingClientRect().height);const f=this.getLineHeight(l,c);u!==f&&(i=!0,u===this.metrics.lineHeight*(c?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:d=!1}=this.options;return this.currentCollapsed!==d&&(this.currentCollapsed=d,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;if(n)return{top:Re(this.metrics,t),height:0};let s=j(this.metrics,t);if(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:d}=this.metrics,u=s+(o===0?l:this.renderRange.bufferBefore),c=o+Math.max(Math.ceil((i-u)/d),0);return c>a?void 0:{lineNumber:c+1,top:s+l+c*d}}let h=s+(o===0?l:this.renderRange.bufferBefore);for(let d=o;d<=a;d++){if(h>=i)return{lineNumber:d+1,top:h};h+=this.getLineHeight(d)}}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);if(s){this.height+=Re(this.metrics,r),this.layoutDirty=!1;return}const l=j(this.metrics,r),h=ye(this.metrics);if(this.height+=l,this.height+=this.cache.fileAnnotationHeight,this.hasUniformLineHeights())this.height+=a*o;else for(let d=0;d<a;d++)this.addLayoutCheckpoint(d,this.height),this.height+=this.getLineHeight(d,!1);if(a>0&&(this.height+=h),this.fileContainer!=null&&t&&!n){const d=this.fileContainer.getBoundingClientRect();d.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:d.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(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:d,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 c=this.virtualizer.getWindowSpecs(),f=this.top??0,p=this.computeRenderRangeFromWindow(o,f,c);return super.render({file:e,fileContainer:i,renderRange:p,lineAnnotations:n,forceRender:(d??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%_t===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),d=a>0?ye(this.metrics):0,{fileAnnotationHeight:u}=this.cache,c=h+u,f=Math.max(0,l-h-u-d),p=Ct(this.getLatestAnnotations()),g=e+h,S=u>0&&p&&g<n&&g+u>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};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,m=A/s,y=(t+n)/2;if(this.hasUniformLineHeights()){const O=e+c,U=O+f;if(!S&&!(O<n&&U>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};const D=Math.floor(S&&y<e+c?0:(y-(e+c))/o),b=Math.floor(D/s)-Math.floor(m/2),Ne=Math.ceil(a/s),_=Math.max(0,Math.min(b,Ne))*s,oe=b<0?A+b*s:A,Oe=_===0?0:u+_*o,Ie=Math.min(oe,a-_);return{startingLine:_,totalLines:oe,bufferBefore:Oe,bufferAfter:Math.max(0,(a-_-Ie)*o)}}const P=m,E=[],L=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-A*o*2),s);let T=e+(L?.top??c),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+c),w!=null)){if(w<=0)break;w--}const b=this.getLineHeight(O,!1);T>t-b&&T<n&&(z??=D),T+b>y&&(C??=D),w==null&&T>=n&&U&&(w=P),k++,T+=b}if(z==null)if(S)z=0,C=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-h-d};C??=z;const N=Math.round(C-m/2),Z=Math.max(0,Math.ceil(a/s)-m),ee=Math.max(0,Math.min(N,Z)),ne=ee*s,se=N<0?A+N*s:A,Fe=E[ee]??0,ke=ne===0?0:u+Fe,re=ee+se/s,ze=re<E.length?f-E[re]:f-(T-e-c);return{startingLine:ne,totalLines:se,bufferBefore:ke,bufferAfter:Math.max(0,ze)}}};function Gt(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===vt&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function jt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:o,renderGutterUtility:a,getHoveredLine:l,getAnnotationSlotName:h=F}){const d=e?.(i),u=t?.(i),c=n?.(i),f=r?.(i);return v.jsxs(v.Fragment,{children:[d!=null?v.jsx("div",{slot:Ae,children:d}):v.jsxs(v.Fragment,{children:[u!=null&&v.jsx("div",{slot:"header-prefix",children:u}),c!=null&&v.jsx("div",{slot:"header-filename-suffix",children:c}),f!=null&&v.jsx("div",{slot:"header-metadata",children:f})]}),s!=null&&o?.map((p,g)=>v.jsx("div",{slot:h(p),children:s(p)},g)),a!=null&&v.jsx("div",{slot:"gutter-utility-slot",style:Rt,children:a(l)})]})}const Kt=typeof window>"u"?M.useEffect:M.useLayoutEffect;function $t({file:i,options:e,editorOptions:t,editStateKey:n,lineAnnotations:r,selectedLines:s,prerenderedHTML:o,metrics:a,hasGutterRenderUtility:l,hasCustomHeader:h,disableWorkerPool:d,edit:u,onEditChange:c,onEditComplete:f}){const p=yt(),g=s!==void 0,S=M.useContext(Lt),H=Tt(),A=W(C=>c?.(C)),m=c!=null?A:void 0,y=M.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=M.useRef(null),T=M.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");p!=null?L.current=new Wt(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),p,a,d?void 0:S,!0):L.current=new be(te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),d?void 0:S,!0),u&&T.current==null&&(T.current=Te(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 Kt(()=>{const{current:C}=L;if(C==null)return;const w=te({controlledSelection:g,hasCustomHeader:h,hasGutterRenderUtility:l,onEditChange:m,onEditComplete:E,options:e}),Q=w!==void 0&&!Ee(C.options,w);if(C.setOptions(w),!u&&T.current!=null){const{current:Z}=T;T.current=null,Z()}const N=qt(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=Te(C,k))}),{ref:z,getHoveredLine:M.useCallback(()=>L.current?.getHoveredLine(),[]),getAnnotationSlotName:M.useCallback(C=>L.current?.getAnnotationSlotName(C)??F(C),[])}}function qt(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 Te(i,e){const t=e();try{return t.edit(i)}catch(n){throw t.cleanUp(),n}}function ri({file:i,lineAnnotations:e,selectedLines:t,options:n,editorOptions:r,editStateKey:s,metrics:o,className:a,style:l,renderAnnotation:h,renderCustomHeader:d,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,prerenderedHTML:p,renderGutterUtility:g,disableWorkerPool:S=!1,edit:H=!1,onEditChange:A,onEditComplete:m}){const{ref:y,getHoveredLine:P,getAnnotationSlotName:E}=$t({file:i,options:n,editorOptions:r,editStateKey:s,metrics:o,lineAnnotations:e,selectedLines:t,prerenderedHTML:p,hasGutterRenderUtility:g!=null,hasCustomHeader:d!=null,disableWorkerPool:S,edit:H,onEditChange:A,onEditComplete:m}),L=jt({file:i,renderAnnotation:h,renderCustomHeader:d,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderGutterUtility:g,lineAnnotations:e,getHoveredLine:P,getAnnotationSlotName:E});return v.jsx(Ue,{ref:y,className:a,style:l,children:At(L,p)})}const oi=I.memo(function({jsonString:e,format:t="json",className:n,maxHeight:r="100%",initiallyExpandedDepth:s=2}){const{t:o}=We(),a=I.useRef(null),[l,h]=I.useState(null),d=I.useMemo(()=>{try{const f=e.trim();if(!f)return h(o("jsonTreeView.error.emptyJson")),null;const p=t==="jsonc"?Ft(f,{trailingCommas:!0}):f,g=JSON.parse(p);return h(null),g}catch(f){return h(f instanceof Error?f.message:o("jsonTreeView.error.invalidJson")),null}},[e,t,o]),u=I.useCallback(()=>{a.current?.expandAll()},[]),c=I.useCallback(()=>{a.current?.collapseAll()},[]);return l?v.jsx("div",{className:n,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:o("jsonTreeView.error.invalidJsonTitle")}),v.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:l})]})}):d===null?null:v.jsxs("div",{className:n,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:u,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-down-s",className:"h-3 w-3"}),o("jsonTreeView.actions.expandAll")]}),v.jsxs(le,{variant:"ghost",size:"xs",onClick:c,className:"gap-1 text-xs text-muted-foreground",children:[v.jsx(he,{name:"arrow-up-s",className:"h-3 w-3"}),o("jsonTreeView.actions.collapseAll")]})]}),v.jsx("div",{className:"oc-surface-code bg-[var(--syntax-background)] py-1",style:{maxHeight:r,overflow:"auto"},children:v.jsx(Ge,{ref:a,data:d,maxHeight:r,initiallyExpandedDepth:s})})]})});export{ri as F,oi as J,Wt as V};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as V,j as B,R as S}from"./vendor-react-BUCujlKS.js";import{m as $t}from"./vendor-morphdom-B7dS_VPB.js";import{r as Dt,a as Bt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{aU as nt,f7 as Ut,bl as De,aT as Ht,ec as rt,f8 as ot,f9 as qt,fa as Kt,fb as zt,fc as jt,ci as st,az as at,bs as it,u as lt,L as ct,a5 as Vt,a6 as He,fd as Gt,fe as Zt,ff as Xt,fg as Yt,cv as Jt}from"./useAppFontEffects-Cs6k0JKv.js";import{l as ie,a5 as dt,aW as Qt,a3 as en,m as ce,aX as ae,aY as tn,u as K,ao as nn,$ as rn,aZ as on,a_ as ut,a$ as sn,b0 as an}from"./katex.min-EZjpSwGK.js";import{L as Oe,c as ln,s as cn,i as dn,r as un,g as mn,a as fn,b as pn}from"./markdownCore-BkTeS4gA.js";import{a as hn,r as wn}from"./textMateThemeFromAppTheme-DLJBL6al.js";import{s as q,c as bn,a as gn,b as kn,d as En,e as _e,f as yn,M as Ne}from"./decorate-jpF7GA6t.js";import{p as An,i as vn,a as We,b as Sn,s as mt}from"./vendor-yaml-CE-D_49-.js";import{o as Cn,a as Ln,s as Mn}from"./vendor-zod-CVhJ1Zpv.js";import{a as Rn}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-Dozz-7fb.js";import"./vendor-tanstack-virtual-core-DKBj55Em.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-dar6chwA.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-B66jUSmE.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DyL0aCoH.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-streamparser-CmlTsbN2.js";import"./vendor-codemirror-lang-javascript-Cem6LjJ8.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CIqXJolH.js";import"./vendor-codemirror-lang-json-C9rLLO0q.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-9qjxcVkg.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-D7VQUxeE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-Cikh4w2I.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DBekkZIx.js";import"./vendor-codemirror-lang-python-DVl8-2Op.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-CkSbCoiw.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-D8QAxC44.js";const Be=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},Te=(t,e)=>{if(t.defaultPrevented)return!1;const r=Be(t)?.getAttribute("href")??"";return De(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},ft=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,In=(t,e)=>{const n=e.openSessionLink;if(!n||t.defaultPrevented)return!1;const r=Be(t)?.getAttribute("href")??"",o=Ut(r,e.ownOrigins??[]);return!o||nt(r)&&!ft(t)?!1:(t.preventDefault(),t.stopPropagation(),n(o),!0)},_n=(t,e)=>{const n=s=>{if(In(s,e)||Te(s,e.openAppLink)||!e.allowExternalHttp||s.defaultPrevented||!ft(s))return;const a=Be(s)?.getAttribute("href")??"";nt(a)&&(s.preventDefault(),s.stopPropagation(),e.openExternalHttp(a))},r=s=>{s.button===1&&Te(s,e.openAppLink)},o=s=>{Te(s)};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)}},pt='[data-openchamber-file-link="true"]',Nn=t=>{if(!(t instanceof Element))return null;const e=t.closest(pt);return e instanceof HTMLElement?e:null},Tn=(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},Pn=(t,e)=>{const n=r=>{const o=Nn(r.target)??Tn(r.target,e);if(!o)return;r.preventDefault(),r.stopPropagation();const s=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform);e.openFileReference(o,{external:s?r.metaKey:r.ctrlKey})};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},ht="openchamber-md",ge={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)"},xn=Object.fromEntries(Object.keys(Ht({base:ge})).map(t=>[t,`var(--md-token-${t})`])),Fn={name:ht,colors:{"editor.background":"transparent","editor.foreground":ge.foreground},tokenColors:[...hn({base:ge,tokens:xn}),{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:ge.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 qe=!1;const On=()=>{qe||(qe=!0,wn(ht,()=>Promise.resolve(Fn)))},ye=10*1024*1024,Wn=1024,$n=3e4,Dn=new Set(["image/png","image/jpeg","image/gif","image/webp"]),Ke=new WeakMap,Ae=t=>{if(t.aborted)throw new DOMException("Image load aborted","AbortError")},Bn=t=>{let e=t;if(/^file:\/\//i.test(e))try{const r=new URL(e);if(r.protocol!=="file:")return"";e=r.host&&r.host!=="localhost"?`//${r.host}${r.pathname}`:r.pathname,/^\/[A-Za-z]:\//.test(e)&&(e=e.slice(1))}catch{return""}const n=e.split(/[?#]/,1)[0]??"";try{return decodeURIComponent(n)}catch{return n}},Un=t=>new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{typeof r.result=="string"?e(r.result):n(new Error("Unable to encode image"))},r.onerror=()=>n(r.error??new Error("Unable to encode image")),r.readAsDataURL(t)}),Hn=async(t,e)=>{const n=new Uint8Array(await t.slice(0,12).arrayBuffer()),r=(o,s)=>String.fromCharCode(...n.slice(o,s));switch(e){case"image/png":return n[0]===137&&r(1,4)==="PNG"&&n[4]===13&&n[5]===10&&n[6]===26&&n[7]===10;case"image/jpeg":return n[0]===255&&n[1]===216&&n[2]===255;case"image/gif":{const o=r(0,6);return o==="GIF87a"||o==="GIF89a"}case"image/webp":return r(0,4)==="RIFF"&&r(8,12)==="WEBP";default:return!1}},wt=async(t,e)=>{if(!Dn.has(e))throw new Error("Unsupported image type");if(t.size>ye)throw new Error("Image is too large");if(!await Hn(t,e))throw new Error("Unsupported image data")},qn=async t=>{const e=/^data:(image\/(?:png|jpeg|gif|webp));base64,([\s\S]*)$/i.exec(t);if(!e?.[1]||e[2]===void 0)throw new Error("Invalid image data URL");if(e[2].length>Math.ceil(ye*4/3)+4)throw new Error("Image is too large");let n;try{n=atob(e[2])}catch{throw new Error("Invalid image data URL")}const r=Uint8Array.from(n,o=>o.charCodeAt(0));await wt(new Blob([r]),e[1].toLowerCase())},ze=t=>!/^(?:https?:)?\/\//i.test(t)&&!/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(t),Kn=async({sources:t,directory:e,sessionId:n,messageId:r,signal:o})=>{const s=dt();let a=Ke.get(s);a||(a=new Map,Ke.set(s,a));const d=`${n}\0${r}\0${e}\0${t.join("\0")}`,p=a.get(d);if(p&&p.expiresAt>Date.now())return a.delete(d),a.set(d,p),p.result;p&&a.delete(d);const l=await ie(`/api/openchamber/sessions/${encodeURIComponent(n)}/markdown-image-grants`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({directory:e,messageId:r,sources:t}),directory:e,signal:o});if(!l.ok)throw new Error(`Unable to prepare images (${l.status})`);const f=await l.json(),g=new Map;for(const h of f.results??[])h.source&&(h.status==="ready"&&h.path?g.set(h.source,{status:"ready",path:h.path,outsideFileGrant:h.outsideFileGrant,expiresAt:h.expiresAt}):h.status==="missing"?g.set(h.source,{status:"missing"}):g.set(h.source,{status:"error"}));for(const h of t)g.has(h)||g.set(h,{status:"error"});for(;a.size>=Wn;)a.delete(a.keys().next().value);const b=[...g.values()].every(h=>h.status==="ready"),y=Math.min(...[...g.values()].filter(h=>h.status==="ready").map(h=>h.expiresAt??Number.POSITIVE_INFINITY));return a.set(d,{result:g,expiresAt:b?y:Date.now()+$n}),g},zn=async(t,e)=>{if(Ae(e),/^(?:https?:)?\/\//i.test(t))return t;if(/^data:image\/(?:png|jpeg|gif|webp);base64,/i.test(t))return await qn(t),Ae(e),t;throw new Error("Local image has not been prepared")},jn=async(t,e,n)=>{Ae(n);const r=Bn(t),o=rt(e,r);if(!e||!r||!ot(o,e))throw new Error("Image path is outside the active workspace");const s=await ie("/api/fs/stat",{query:{path:o,directory:e,optional:"true"},signal:n});if(!s.ok)throw new Error(`Unable to inspect image (${s.status})`);const a=await s.json();if(!a.isFile)throw new Error("Image path is not a file");if(typeof a.size=="number"&&a.size>ye)throw new Error("Image is too large");const d=await ie("/api/fs/raw",{query:{path:o,directory:e},signal:n});if(!d.ok)throw new Error(`Unable to load image (${d.status})`);const p=(d.headers.get("content-type")??"").split(";",1)[0]?.toLowerCase()??"",l=Number(d.headers.get("content-length"));if(Number.isFinite(l)&&l>ye)throw new Error("Image is too large");const f=await d.blob();return await wt(f,p),Ae(n),Un(f)},Vn=(t,e)=>dt().authenticatedAsset(Qt("/api/fs/raw",e),{path:t.path,directory:e,allowOutsideWorkspace:t.outsideFileGrant?"true":void 0,outsideFileGrant:t.outsideFileGrant}),ve="[data-openchamber-markdown-image-source]",bt="data-openchamber-markdown-inline-image",ke=`[${bt}]`,Gn="[data-message-id]",gt=12,kt="inline-block max-w-[min(100%,30rem)] align-top my-1 me-1",Zn="block max-w-full cursor-zoom-in overflow-hidden rounded-lg border border-border/40 bg-muted/10 outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",Xn="block h-auto max-h-[30rem] w-auto max-w-full object-contain",Ee=new WeakMap,je=new WeakMap,ee=t=>t.getAttribute("data-openchamber-markdown-image-source")??"",Yn=t=>t.textContent?.trim()||"image",Jn=t=>{const e=[];for(const n of Array.from(t.querySelectorAll(ve))){const r=ee(n);if(r&&!e.includes(r)&&e.push(r),e.length>=gt)break}return e},Qn=async(t,e)=>{const n=document.createElement("img");return n.alt=e,n.decoding="async",n.referrerPolicy="no-referrer",n.draggable=!1,n.className=Xn,n.src=t,await n.decode(),n},er=(t,e,n)=>new Promise((r,o)=>{const s=document.createElement("video");s.controls=!0,s.preload="metadata",s.playsInline=!0,s.title=e,s.setAttribute(Oe,"true");const a=()=>{s.removeEventListener("loadedmetadata",d),s.removeEventListener("error",p),n.removeEventListener("abort",p)},d=()=>{a(),r(s)},p=()=>{a(),s.removeAttribute("src"),o(new Error("Video is not available"))};s.addEventListener("loadedmetadata",d),s.addEventListener("error",p),n.addEventListener("abort",p),s.src=t}),tr=(t,e,n)=>{const r=document.createElement("button");r.type="button",r.className=Zn,r.setAttribute(bt,"true"),r.setAttribute("aria-label",n.filename),r.appendChild(e),Ee.set(r,n),t.className=kt,t.replaceChildren(r)},nr=8,Ve=.5,rr=t=>t.querySelector(ke)?.querySelector("img")??null,Ge=t=>{if(!(t instanceof HTMLElement)||t.tagName!=="P")return;const e=[];for(const l of Array.from(t.childNodes))if(!(l.nodeType===3&&!l.textContent?.trim())){if(!(l instanceof HTMLElement)||!l.matches(ve))return;e.push(l)}if(e.length<2)return;const n=e.map(rr),r=n.map(l=>l&&l.naturalWidth>0&&l.naturalHeight>0?{width:l.naturalWidth,height:l.naturalHeight}:null);if(r.some(l=>l===null))return;const o=r.filter(l=>l!==null),s=o.map(({width:l,height:f})=>l/f),a=s.reduce((l,f)=>l+f,0),d=Math.min(...o.map(({height:l})=>l)),p=(e.length-1)*Ve;t.setAttribute("data-openchamber-markdown-image-row","true"),Object.assign(t.style,{display:"flex",flexWrap:"wrap",alignItems:"flex-start",gap:`${Ve}rem`,maxWidth:`calc(min(30rem, ${d}px) * ${a} + ${p}rem)`}),e.forEach((l,f)=>{const g=s[f]??1,b=o[f];Object.assign(l.style,{flex:`${g} 1 0px`,minWidth:`${nr*g}rem`,maxWidth:`min(${b?.width??0}px, ${30*g}rem)`,margin:"0"});const y=n[f];y&&(y.style.width="100%")})},or=t=>{const{container:e,sessionId:n,messageId:r,directory:o,apiBaseUrl:s,useWorkspaceFsBridge:a,onShowPopup:d}=t,p=new AbortController,{signal:l}=p,f=new WeakSet,g=new Set;let b=null;const y=i=>{const c=Jn(e).filter(ze),m=c.join("\0");return(!b||b.sources!==m||i)&&(b={sources:m,result:Kn({sources:c,directory:o,sessionId:n,messageId:r,signal:l})}),b.result},h=async(i,c)=>{if(!ze(i))return zn(i,l);if(a)return jn(i,o,l);const m=(await y(c)).get(i);if(m?.status!=="ready")throw new Error("Image is not available");return await en(s),Vn(m,o)},x=async i=>{const c=ee(i),m=Yn(i);f.add(i);try{if(dn(c)){if(a)throw new Error("Video is not available");const R=await er(await h(c,!1),m,l);if(l.aborted||!i.isConnected||ee(i)!==c)return;je.set(i,i.className),i.className=kt,i.replaceChildren(R);return}const C=await Qn(await h(c,!1),m);if(l.aborted||!i.isConnected||ee(i)!==c)return;tr(i,C,{filename:m,resolveUrl:()=>h(c,!0)}),Ge(i.parentElement)}catch{l.aborted||g.add(c)}finally{f.delete(i)}},_=i=>{const c=i.target;if(!(c instanceof HTMLVideoElement)||!c.hasAttribute(Oe))return;const m=c.closest(ve);if(!m||!e.contains(m))return;const C=ee(m),R=()=>{g.add(C),m.className=je.get(m)??"",m.textContent=c.title||C};if(!ln(c)){R();return}h(C,!0).then(k=>{c.isConnected&&cn(c,k)},()=>{!l.aborted&&c.isConnected&&R()})};e.addEventListener("error",_,!0);const I=typeof IntersectionObserver>"u"?null:new IntersectionObserver(i=>{for(const c of i)!c.isIntersecting||!(c.target instanceof HTMLElement)||(I?.unobserve(c.target),x(c.target))},{rootMargin:"200px"}),P=()=>{const i=new Set;for(const c of Array.from(e.querySelectorAll(ve))){const m=ee(c);if(i.add(m),i.size>gt)break;if(c.querySelector(`[${Oe}]`))continue;const C=c.querySelector(ke);if(C){const R=Ee.get(C)?.filename??C.getAttribute("aria-label")??"image";Ee.set(C,{filename:R,resolveUrl:()=>h(m,!0)}),Ge(c.parentElement);continue}!m||g.has(m)||f.has(c)||c.closest("a")||(I?(f.add(c),I.observe(c)):x(c))}};let O=null;const w=()=>{O===null&&(O=window.requestAnimationFrame(()=>{O=null,l.aborted||P()}))},u=new MutationObserver(w);u.observe(e,{childList:!0,subtree:!0});const L=async i=>{const c=e.closest(Gn)??e,m=Array.from(c.querySelectorAll(ke)).flatMap(v=>{const A=Ee.get(v);return A?[{button:v,entry:A}]:[]});if(!m.some(v=>v.button===i))return;const C=await Promise.allSettled(m.map(({entry:v})=>v.resolveUrl()));if(l.aborted)return;const R=m.flatMap(({button:v,entry:A},T)=>{const E=C[T];return E?.status!=="fulfilled"?[]:[{url:E.value,filename:A.filename,button:v}]}),k=R.findIndex(v=>v.button===i),M=R[k];M&&d({open:!0,title:M.filename,content:"",metadata:{tool:"markdown-image-preview",filename:M.filename},image:{url:M.url,filename:M.filename,gallery:R.map(({url:v,filename:A})=>({url:v,filename:A})),index:k}})},N=i=>{const c=i.target;if(!(c instanceof Element))return;const m=c.closest(ke);!m||!e.contains(m)||(i.preventDefault(),L(m))};return e.addEventListener("click",N),P(),()=>{p.abort(),O!==null&&window.cancelAnimationFrame(O),u.disconnect(),I?.disconnect(),e.removeEventListener("click",N),e.removeEventListener("error",_,!0)}},oe=new Map;let se=null;const sr=()=>{if(se)return se;const t=globalThis.ResizeObserver;return t?(se=new t(e=>{for(const n of e){const r=oe.get(n.target);if(!r)continue;const{width:o}=n.contentRect;if(o===r.width)continue;const s=r.width===null;r.width=o,s||Kt(r.onWidthChange)}}),se):null},ar=(t,e)=>{const n=sr();return n?(oe.set(t,{width:null,onWidthChange:e}),n.observe(t),()=>{const r=oe.get(t);r&&(oe.delete(t),qt(r.onWidthChange),n.unobserve(t),!(oe.size>0)&&(n.disconnect(),se=null))}):()=>{}},Ze=(t,e,n)=>{let r=0;for(const s of t){const a=r+s.data.length;if(e<a||e===a&&n==="left")return{node:s,offset:Math.max(0,e-r)};r=a}const o=t.at(-1);return o?{node:o,offset:o.data.length}:null},ir=/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n([\s\S]*?)\r?\n\1[^\S\r\n]*(?:\r?\n|$)/,$e=t=>We(t)?String(t.value??""):mt(t).trimEnd(),lr=t=>t?We(t)?{kind:"text",text:$e(t)}:Sn(t)&&t.items.every(e=>We(e))?{kind:"list",items:t.items.map(e=>$e(e))}:{kind:"code",text:mt(t).trimEnd()}:{kind:"text",text:""},cr=(t,e)=>{if(t!=="---")return{kind:"raw",text:e};const n=An(e);return n.errors.length>0?{kind:"raw",text:e}:n.contents===null?null:vn(n.contents)?{kind:"properties",properties:n.contents.items.map(r=>({key:r.key?$e(r.key):"",value:lr(r.value)}))}:{kind:"raw",text:e}},dr=t=>{const e=t.match(ir);return e?{frontmatter:cr(e[1],e[2]),body:t.slice(e[0].length)}:{frontmatter:null,body:t}},Et="oc-surface-code m-0 whitespace-pre-wrap break-words font-mono text-[0.95em]",ur=t=>{const e=V.c(8),{value:n}=t;if(n.kind==="list"){let o;e[0]!==n.items?(o=n.items.map(fr),e[0]=n.items,e[1]=o):o=e[1];let s;return e[2]!==o?(s=B.jsx("span",{className:"flex flex-wrap gap-1",children:o}),e[2]=o,e[3]=s):s=e[3],s}if(n.kind==="code"){let o;return e[4]!==n.text?(o=B.jsx("pre",{dir:"ltr",className:Et,children:n.text}),e[4]=n.text,e[5]=o):o=e[5],o}let r;return e[6]!==n.text?(r=B.jsx("span",{dir:"auto",className:"whitespace-pre-wrap",children:n.text}),e[6]=n.text,e[7]=r):r=e[7],r},mr=t=>{const e=V.c(6),{frontmatter:n}=t;if(n.kind==="raw"){let s;return e[0]!==n.text?(s=B.jsx("pre",{dir:"ltr",className:`${Et} mb-4 rounded-lg border border-[var(--interactive-border)] bg-[var(--syntax-background)] px-3 py-2.5 typography-meta`,children:n.text}),e[0]=n.text,e[1]=s):s=e[1],s}let r;e[2]!==n.properties?(r=n.properties.map(pr),e[2]=n.properties,e[3]=r):r=e[3];let o;return e[4]!==r?(o=B.jsx("dl",{className:"mb-4 grid grid-cols-[fit-content(40%)_minmax(0,1fr)] items-baseline gap-x-4 gap-y-1.5 rounded-lg border border-[var(--interactive-border)] px-3 py-2.5 typography-meta",children:r}),e[4]=r,e[5]=o):o=e[5],o};function fr(t,e){return B.jsx("span",{dir:"auto",className:"rounded-full bg-[var(--surface-subtle)] px-2 py-px",children:t},e)}function pr(t,e){const{key:n,value:r}=t;return B.jsxs("div",{className:"contents",children:[B.jsx("dt",{dir:"auto",className:"oc-ui-start-align break-words text-muted-foreground",children:n}),B.jsx("dd",{className:"m-0 min-w-0 break-words text-foreground",children:B.jsx(ur,{value:r})})]},e)}const hr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Xe=Array.from(hr).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),yt=t=>jt(t),wr=t=>zt(t),At=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}},Se=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):""},we=t=>{let e=Se(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=Xe.length>0?e.match(new RegExp(`^(.*(?:/|^)(${Xe})):.*$`,"i")):null;return o&&(e=o[1]??e),Se(e)},vt=t=>{const e=Se(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?Se(e.slice(0,n)):e;if(!r)return null;const o=r.match(/^(.*?):(\d+)-(\d+)$/);if(o){const p=we(o[1]??""),l=Number.parseInt(o[2]??"",10),f=Number.parseInt(o[3]??"",10);return!p||!Number.isFinite(l)||!Number.isFinite(f)||f<l?null:{path:p,line:l,endLine:f}}const s=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(s){const p=we(s[1]??""),l=Number.parseInt(s[2]??"",10),f=s[3]?Number.parseInt(s[3],10):void 0;return!p||!Number.isFinite(l)?null:{path:p,line:l,column:Number.isFinite(f??Number.NaN)?f:void 0}}const a=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(a){const p=we(a[1]??""),l=Number.parseInt(a[2]??"",10),f=a[3]?Number.parseInt(a[3],10):void 0;return!p||!Number.isFinite(l)?null:{path:p,line:l,column:Number.isFinite(f??Number.NaN)?f:void 0}}const d=we(r);return d?{path:d}:null},br=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,gr=4,kr=1e3,Er=200,G=new Map;let be=0;const Ye=[],yr=()=>ce()?Er:kr,St=(t,e)=>`${t}\0${e}`,Ar=(t,e)=>{const n=yt(t);if(!n)return Promise.resolve(!1);const r=St(e,n),o=G.get(r);if(o)return G.delete(r),G.set(r,o),o;const s=new Promise(d=>{const p=()=>{be+=1,ie(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async l=>{if(!l.ok){d(!1);return}const f=await l.json().catch(()=>null);d(f?.exists!==!1)}).catch(()=>d(!1)).finally(()=>{be=Math.max(0,be-1),Ye.shift()?.()})};if(be<gr){p();return}Ye.push(p)}),a=yr();for(;G.size>=a;){const d=G.keys().next().value;if(typeof d!="string")break;G.delete(d)}return G.set(r,s),s},vr=Cn({paths:Ln(Mn())}),ne=new Map,Sr=200,Cr=(t,e)=>{if(!t||!e||ce())return Promise.resolve(null);const n=St(e,t),r=ne.get(n);if(r)return r;const o=ie(`/api/fs/find-by-name?name=${encodeURIComponent(t)}`,{method:"GET",cache:"no-store",headers:{"x-opencode-directory":e}}).then(async s=>{if(!s.ok)return null;const a=vr.safeParse(await s.json().catch(()=>null)),d=a.success?a.data.paths:[];return d.length===1?d[0]:null}).catch(()=>null);for(;ne.size>=Sr;){const s=ne.keys().next();if(s.done)break;ne.delete(s.value)}return ne.set(n,o),o},Lr={maxSessions:8,maxEntriesPerSession:4};class Mr{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=Lr){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 s=r.get(o);return s===void 0||s.locale!==e.locale||s.directory!==e.directory?null:(r.delete(o),r.size===0&&this.sessions.delete(n),s.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 Je=new Mr,Ct=()=>{const t=V.c(4),e=Vt();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=He(!1),t[0]=n):n=t[0];const r=n;let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o=He(!0),t[1]=o):o=t[1];const s=o;let a;return t[2]!==e?.currentTheme?(a=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?s:r),t[2]=e?.currentTheme,t[3]=a):a=t[3],a},Rr=()=>{if(typeof window>"u")return[];const t=[window.location.origin];try{const e=new URL(ut()||window.location.href,window.location.href).origin;t.includes(e)||t.push(e)}catch{}return t},Lt=t=>{const e=V.c(3);let n,r;e[0]!==t?(n=()=>{const o=t.current;return o?pn(o):void 0},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),S.useEffect(n,r)},Mt=t=>{const e=V.c(5),{containerRef:n,enabled:r,directory:o}=t,s=Gt(o);let a,d;e[0]!==n||e[1]!==r||e[2]!==s?(a=()=>{const p=n.current;if(!p)return;const l=!ce();return _n(p,{allowExternalHttp:r!==!1,openAppLink:Qr,openExternalHttp:s,openSessionLink:l?eo:void 0,ownOrigins:Rr()})},d=[n,r,s],e[0]=n,e[1]=r,e[2]=s,e[3]=a,e[4]=d):(a=e[3],d=e[4]),S.useEffect(a,d)},te={download:!0,copy:!0,showPanZoomControls:!0},Rt=!0,It="data-openchamber-block-path-token",_t=`[${It}]`,le="data-openchamber-block-paths-scanned",Ir=2e5,_r=80,Nr=40,Qe=160,Tr=()=>ce()?Nr:_r,Pr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Nt=t=>yt(t),xr=t=>wr(t),Fr=(t,e)=>rt(t,e),Or=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},Tt=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Nt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return Pr.has(r)||r.startsWith(".")&&r.length>1?!0:Or(e)},Ue=t=>{const e=vt(t);return e?Tt(e.path):!1},Wr=t=>{const e=t.querySelectorAll(_t);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${le}]`);for(const r of Array.from(n))r.removeAttribute(le),r.normalize()},Pe=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim();if(e&&De(e))return"";const n=e?At(e):null;if(n)return n;if(e&&Ue(e))return e}return(t.textContent||"").trim()},$r=t=>{const e=t.getAttribute("href")?.trim();if(!e||De(e))return null;const n=At(e);return n||(Ue(e)?e:null)},Dr=t=>{const e=[];for(const n of Array.from(t.querySelectorAll("pre code"))){if(n.hasAttribute(le))continue;const r=[],o=n.textContent??"",s=o.length>Ir?"":o;if(s.includes("."))for(const a of s.matchAll(br)){const d=a[0];d&&Ue(d)&&r.push({start:a.index,end:a.index+d.length,raw:d})}e.push({codeBlock:n,tokens:r})}return e},Br=(t,e)=>{const n=t.ownerDocument;if(e.length>0){const r=n.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=[];for(let a=r.nextNode();a;a=r.nextNode())a instanceof Text&&o.push(a);const s=t.textContent??"";for(const{start:a,end:d,raw:p,decorate:l}of[...e].sort((f,g)=>g.start-f.start)){if(s.slice(a,d)!==p)continue;const f=Ze(o,a,"right"),g=Ze(o,d,"left");if(!f||!g)continue;const b=n.createRange();b.setStart(f.node,f.offset),b.setEnd(g.node,g.offset);const y=n.createElement("span");y.setAttribute(It,"true"),y.textContent=p,l(y),b.deleteContents(),b.insertNode(y)}}t.setAttribute(le,"true")},re=(t,e)=>{const n=vt(t);if(!n||!Tt(n.path))return null;const r=xr(n.path)?Nt(n.path):Fr(e,n.path);return r?{...n,resolvedPath:r}:null},Ur=(t,e)=>t||Zt(t,e),Pt=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:o})=>{const s=S.useRef(null);S.useEffect(()=>{const a=t.current;if(!a||o&&!e)return;let d=!1;const p=Tr(),l=o&&!on(),f=i=>{i.removeAttribute("data-openchamber-file-link"),i.removeAttribute("data-openchamber-file-ref"),i.removeAttribute("data-openchamber-file-path"),i.getAttribute("title")==="Open file"&&i.removeAttribute("title"),i.tagName.toLowerCase()!=="a"&&(i.removeAttribute("role"),i.removeAttribute("tabindex"))},g=()=>{const i=a.querySelectorAll(pt);for(const c of Array.from(i))f(c);Wr(a)},b=async(i,c)=>{const m=i.getAttribute("data-openchamber-file-ref")||Pe(i),C=re(m,e);if(!C)return;const R=i.getAttribute("data-openchamber-file-path"),k=R?{...C,resolvedPath:R}:C;if(c?.external&&sn()&&await an(k.resolvedPath))return;const M=Ur(e,k.resolvedPath);if(r&&n){n.openFile(k.resolvedPath,Number.isFinite(k.line??Number.NaN)?Math.max(1,Math.trunc(k.line)):void 0,Number.isFinite(k.column??Number.NaN)?Math.max(1,Math.trunc(k.column)):void 0);return}const v=K.getState();Number.isFinite(k.line??Number.NaN)?v.openContextFileAtLine(M,k.resolvedPath,Math.max(1,Math.trunc(k.line)),Number.isFinite(k.column??Number.NaN)?Math.max(1,Math.trunc(k.column)):1):v.openContextFile(M,k.resolvedPath)},y=()=>Pn(a,{hrefCandidate:$r,isResolvable:i=>re(i,e)!==null,openFileReference:b});if(!l)return g(),o?y():void 0;const h=(i=0)=>{if(s.current!==null&&typeof window<"u"&&window.clearTimeout(s.current),typeof window>"u"){O();return}s.current=window.setTimeout(()=>{s.current=null,window.requestAnimationFrame(()=>{d||O()})},i)},x=i=>{u+=1;try{i()}finally{queueMicrotask(()=>{u-=1})}},_=(i,c,m)=>{i.getAttribute(c)!==m&&i.setAttribute(c,m)},I=(i,c,m)=>{_(i,"data-openchamber-file-link","true"),_(i,"data-openchamber-file-ref",c),_(i,"data-openchamber-file-path",m),_(i,"title","Open file"),i.tagName.toLowerCase()!=="a"&&(_(i,"role","button"),_(i,"tabindex","0"))},P=i=>{if(!ot(i.resolvedPath,e))return Promise.resolve(i.resolvedPath);const c=!i.path.includes("/")&&!i.path.includes("\\");return Ar(i.resolvedPath,e).then(m=>m?i.resolvedPath:c?Cr(i.path,e):null)},O=()=>{const i=a.querySelectorAll(`[data-markdown="inline-code"], a, ${_t}`);let c=0;const m=[],C=[];for(const k of Array.from(i)){const M=re(Pe(k),e);if(!M||c>=p){C.push(k);continue}c+=1,m.push({candidate:k,resolvedPath:M.resolvedPath,target:P(M)})}const R=Dr(a).map(({codeBlock:k,tokens:M})=>({codeBlock:k,tokens:M.flatMap(v=>{const A=re(v.raw,e);return!A||c>=p?[]:(c+=1,[{...v,target:P(A)}])})}));x(()=>{for(const k of C)f(k)}),!(m.length===0&&R.length===0)&&Promise.all([Promise.all(m.map(k=>k.target.then(M=>({...k,targetPath:M})))),Promise.all(R.map(async({codeBlock:k,tokens:M})=>({codeBlock:k,tokens:await Promise.all(M.map(v=>v.target.then(A=>({...v,targetPath:A}))))})))]).then(([k,M])=>{d||x(()=>{for(const{candidate:v,resolvedPath:A,targetPath:T}of k){if(!a.contains(v))continue;const E=Pe(v);re(E,e)?.resolvedPath===A&&(T?I(v,E,T):f(v))}for(const{codeBlock:v,tokens:A}of M)!a.contains(v)||v.hasAttribute(le)||Br(v,A.flatMap(({start:T,end:E,raw:$,targetPath:W})=>W?[{start:T,end:E,raw:$,decorate:z=>I(z,$,W)}]:[]))})})},w=i=>{if(i.key!=="Enter"&&i.key!==" ")return;const c=i.target;!(c instanceof HTMLElement)||c.getAttribute("data-openchamber-file-link")!=="true"||(i.preventDefault(),i.stopPropagation(),b(c))};h(Qe);let u=0;const L=new MutationObserver(()=>{u>0||h(Qe)});L.observe(a,{childList:!0,subtree:!0}),a.addEventListener("keydown",w);const N=y();return()=>{d=!0,s.current!==null&&typeof window<"u"&&window.clearTimeout(s.current),s.current=null,L.disconnect(),N(),a.removeEventListener("keydown",w)}},[t,n,e,r,o])},Hr=t=>{const e=V.c(10),{containerRef:n,sessionId:r,messageId:o,directory:s,onShowPopup:a}=t,d=S.useRef(a);let p,l;e[0]!==a?(p=()=>{d.current=a},l=[a],e[0]=a,e[1]=p,e[2]=l):(p=e[1],l=e[2]),S.useEffect(p,l);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=ut(),e[3]=f):f=e[3];const g=f;let b,y;e[4]!==n||e[5]!==s||e[6]!==o||e[7]!==r?(b=()=>{const h=n.current;if(!(!h||!r||!o))return or({container:h,sessionId:r,messageId:o,directory:s,apiBaseUrl:g,useWorkspaceFsBridge:ce(),onShowPopup:x=>d.current?.(x)})},y=[g,n,s,o,r],e[4]=n,e[5]=s,e[6]=o,e[7]=r,e[8]=b,e[9]=y):(b=e[8],y=e[9]),S.useEffect(b,y)},xt=t=>{const e=V.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:o,enablePanZoom:s,allowMermaidWheelEvents:a}=t;let d,p;e[0]!==a||e[1]!==n||e[2]!==o||e[3]!==s||e[4]!==r?(d=()=>{const l=n.current;if(!l)return;const f=b=>{if(!o||!r)return;const y=b.target;if(!(y instanceof Element)||y.closest('button, a, [role="button"]'))return;const h=y.closest(Ne);if(!h)return;if(h instanceof HTMLElement&&h.hasAttribute("data-mermaid-suppress-click")){h.removeAttribute("data-mermaid-suppress-click");return}const _=Array.from(l.querySelectorAll(Ne)).indexOf(h);if(_<0)return;const I=h instanceof HTMLElement?h.getAttribute("data-md-source"):null;if(!I||I.trim().length===0)return;const P=`Diagram ${_+1}`;r({open:!0,title:P,content:"",metadata:{tool:"mermaid-preview",filename:P},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(I)}`,source:I,filename:P}})},g=b=>{if(a||(b.ctrlKey||b.metaKey)&&s)return;const y=b.target;!(y instanceof Element)||!y.closest(Ne)||b.stopPropagation()};return l.addEventListener("click",f),l.addEventListener("wheel",g,{capture:!0,passive:!0}),()=>{l.removeEventListener("click",f),l.removeEventListener("wheel",g,!0)}},p=[a,n,o,s,r],e[0]=a,e[1]=n,e[2]=o,e[3]=s,e[4]=r,e[5]=d,e[6]=p):(d=e[5],p=e[6]),S.useEffect(d,p)},Z=new Map,qr=100,X="data-md-decoration-id",xe=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","")},Ce="oc-md-block-enter",Kr=t=>{for(const e of Array.from(t.querySelectorAll(`.${Ce}`)))e.classList.remove(Ce),e.style.removeProperty("--oc-md-enter-delay")},zr=t=>{for(const e of Array.from(t.children))!(e instanceof HTMLElement)||!e.classList.contains(Ce)||(e.classList.remove(Ce),e.style.removeProperty("--oc-md-enter-delay"),e.getAttribute("style")||e.removeAttribute("style"))},jr=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let o=0;o<e.length;o+=1){const s=r[o];if(!s||s.getAttribute("data-md-id")!==e[o]?.id||s.getAttribute(X)!==n)return!1}return!0},et=new WeakMap;let tt=0;const Vr=2e5,Fe=t=>{const e=et.get(t);if(e)return e;const n=`decoration-${tt}`;return tt+=1,et.set(t,n),n},Gr=(t,e)=>{const n=Z.get(t);if(n)return Z.delete(t),Z.set(t,n),n;const r=e();if(Z.set(t,r),Z.size>qr){const o=Z.keys().next().value;o&&Z.delete(o)}return r},Zr=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"}),Xr=()=>K.getState().copyMessagesAsPlainText?"plain":"markdown",Ft=(t,e,n=te)=>{const{t:r}=lt(),o=S.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]),s=K(b=>b.codeBlockLineWrap),a=K(b=>b.setCodeBlockLineWrap),d=S.useCallback(()=>{a(!K.getState().codeBlockLineWrap)},[a]),p=K(b=>b.tableCellWrap),l=K(b=>b.setTableCellWrap),f=S.useCallback(()=>{l(!K.getState().tableCellWrap)},[l]);return S.useMemo(()=>{const b=Zr(t),y=K.getState().mermaidRenderingMode,h=t.metadata?.id??"theme";return{labels:o,mermaidControls:n,codeBlockLineWrap:s,onToggleCodeBlockLineWrap:d,tableCellWrap:p,onToggleTableCellWrap:f,renderMermaid:_=>Gr(`${h}:${y}:${_}`,()=>{try{return y==="ascii"?{ascii:Dt(_)}:{svg:Bt(_,b)}}catch{return{}}}),onPreviewLoopback:e,getCopyFormat:Xr}},[t,o,n,s,d,p,f,e])},Ot=({containerRef:t,text:e,streaming:n,imageMode:r="inline",rawHtml:o="escape",syntaxVars:s,ctx:a,domCacheKey:d,tableLayoutSettled:p})=>{S.useEffect(()=>{On()},[]);const l=S.useRef(null),f=S.useRef(0),g=S.useRef(null),b=S.useRef(null),y=S.useRef(null),h=S.useCallback(()=>{const w=t.current;if(w){if(!l.current){if(!q(w))return;l.current=bn(w);return}l.current.refresh()}},[t]),{tableCellWrap:x}=a,_=S.useCallback(()=>{const w=t.current,u=w?.querySelector("[data-markdown-content]")??w;u&&(gn(u,x),!b.current&&u.querySelector('table[data-markdown="table"]')&&(b.current=ar(u,()=>O.current())))},[t,x]),I=S.useCallback(()=>{if(!p)return;const w=g.current;w!==null&&window.cancelAnimationFrame(w);const u=f.current,L=window.requestAnimationFrame(()=>{g.current===L&&(g.current=null,f.current===u&&_())});g.current=L},[_,p]),P=S.useCallback(()=>{const w=g.current;w!==null&&window.cancelAnimationFrame(w),g.current=null,_()},[_]),O=S.useRef(I);S.useEffect(()=>{O.current=I},[I]),S.useEffect(()=>()=>{b.current?.(),b.current=null;const w=g.current;w!==null&&(window.cancelAnimationFrame(w),g.current=null)},[]),S.useLayoutEffect(()=>{const w=t.current,u=w?.querySelector("[data-markdown-content]")??w;if(u)for(const[L,N]of Object.entries(s))u.style.setProperty(L,N)},[t,s]),S.useLayoutEffect(()=>{f.current+=1,y.current=null},[a,r,o,n,e]),S.useLayoutEffect(()=>{if(!d)return;const w=t.current,u=w?.querySelector("[data-markdown-content]")??w;if(!u||u.childNodes.length>0)return;const L=Je.take(d);if(L){u.appendChild(L),xe(u);const N=Fe(a);for(const i of Array.from(u.children))i.setAttribute(X,N);kn(u,a.codeBlockLineWrap,a.labels),En(u,a.tableCellWrap,a.labels),y.current={key:d,copiedLabel:a.labels.copied},ae("ui.markdown_renderer.dom_cache.hit")}},[t,a,d,e.length]),S.useLayoutEffect(()=>{const w=t.current,u=w?.querySelector("[data-markdown-content]")??w;if(u)return()=>{const L=y.current;if(!L||u.childNodes.length===0||q(u)||Array.from(u.children).some(C=>!C.hasAttribute("data-md-id"))||u.querySelector("[data-md-copy-pending]"))return;const N=window.getSelection();if(N?.rangeCount&&!N.isCollapsed&&N.getRangeAt(0).intersectsNode(u))return;const i=u.querySelector("[data-md-menu]:not(.hidden)"),c=Array.from(u.querySelectorAll("[data-md-action]")).some(C=>C.getAttribute("title")===L.copiedLabel);if(i||c)return;Kr(u);const m=document.createDocumentFragment();m.append(...Array.from(u.childNodes)),Je.store({...L.key,fragment:m}),ae("ui.markdown_renderer.dom_cache.capture")}},[t]),S.useLayoutEffect(()=>{const w=t.current,u=w?.querySelector("[data-markdown-content]")??w;if(!u)return;const L=Fe(a);if(e&&u.childNodes.length===0){const N=un(e,n,r,o);let i=!1;for(const c of N){const m=document.createElement("div");m.setAttribute("data-md-block",""),m.style.display="contents",m.innerHTML=c.html,_e(m,a),m.setAttribute("data-md-id",c.id),m.setAttribute(X,L),i||=q(m),u.appendChild(m)}i&&h(),xe(u),p&&P()}else!l.current&&q(u)&&h()},[t,e,n,r,o,a,h,p,P]),S.useEffect(()=>()=>{l.current?.cleanup(),l.current=null},[]),S.useEffect(()=>{const w=t.current;if(!w)return;const u=w.querySelector("[data-markdown-content]")??w;let L=!0;const N=f.current,i=Fe(a);if(!n){const c=mn(e,r,o);if(c&&jr(u,c,i)){y.current=d?{key:d,copiedLabel:a.labels.copied}:null,ae("ui.markdown_renderer.settled_paint.reused"),I();return}}return fn(e,n,r,o).then(c=>{if(!L||f.current!==N)return;const m=Array.from(u.children),C=p&&u.querySelector('table[data-md-table-layout="fixed"]')!==null,R=Array.from(u.querySelectorAll("details[data-md-details]")).map(A=>({summary:A.querySelector("summary")?.textContent,open:A.open}));let k=0;c.forEach((A,T)=>{let E=m[T],$=!1;if(E||(E=document.createElement("div"),E.setAttribute("data-md-block",""),E.style.display="contents",u.appendChild(E),$=!0),E.getAttribute("data-md-id")===A.id){if(E.getAttribute(X)!==i){const U=q(E);U&&(l.current?.cleanup(),l.current=null);const F=document.createElement("div");F.setAttribute("data-md-block",""),F.style.display="contents",F.innerHTML=A.html,_e(F,a),F.setAttribute("data-md-id",A.id),F.setAttribute(X,i),E.replaceWith(F),(U||q(F))&&h()}!l.current&&q(E)&&h();return}const W=E.getAttribute("data-md-id"),z=W&&E.getAttribute(X)===i?A.patchFrom?.(W):null;if(z&&Rn(E,z)){zr(E),E.setAttribute("data-md-id",A.id);return}const D=document.createElement("div");if(D.innerHTML=A.html,_e(D,a),$&&n&&T>0){const U=Math.min(k,4)*55;k+=1;for(const F of Array.from(D.children))F.classList.add("oc-md-block-enter"),U>0&&F instanceof HTMLElement&&F.style.setProperty("--oc-md-enter-delay",`${U}ms`)}const H=q(E),de=q(D);$t(E,D,{childrenOnly:!0,onBeforeElUpdated:(U,F)=>(U.matches("details[data-md-details]")&&F.matches("details[data-md-details]")&&U.querySelector("summary")?.textContent===F.querySelector("summary")?.textContent&&F.toggleAttribute("open",U.hasAttribute("open")),!U.isEqualNode(F))}),E.setAttribute("data-md-id",A.id),E.setAttribute(X,i),(H||de||q(E))&&h()});const M=q(u);let v=!1;for(let A=m.length-1;A>=c.length;A-=1){const T=m[A];T&&q(T)&&(v=!0),T?.remove()}xe(u),(v||m.length>c.length&&M)&&h(),R.length>0&&u.querySelectorAll("details[data-md-details]").forEach((A,T)=>{const E=R[T];E&&E.summary===A.querySelector("summary")?.textContent&&(A.open=E.open)}),y.current=d?{key:d,copiedLabel:a.labels.copied}:null,C?P():I()}),()=>{L=!1}},[t,a,d,r,o,h,P,I,n,p,e]),S.useEffect(()=>{const w=t.current;if(w)return yn(w,a)},[t,a])},Wt=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Yr=t=>{const e=V.c(46),{content:n,part:r,messageId:o,isAnimated:s,skipFadeIn:a,className:d,isStreaming:p,variant:l,onShowPopup:f,enableFileReferences:g}=t,b=s===void 0?!0:s,y=a===void 0?!1:a,h=p===void 0?!1:p,x=l===void 0?"assistant":l,_=g===void 0?!0:g;ae("ui.markdown_renderer.render"),h&&ae("ui.markdown_renderer.render.streaming"),tn("ui.markdown_renderer.content_len",n.length);const I=Ct(),{editor:P,runtime:O}=st(),w=S.useRef(null),u=at()??"",L=K(to);let N;e[0]!==u||e[1]!==L?(N=j=>{u&&L(u,j)},e[0]=u,e[1]=L,e[2]=N):N=e[2];const i=N;let c;e[3]!==f?(c={containerRef:w,onShowPopup:f,enableFullscreen:Rt,enablePanZoom:te.showPanZoomControls},e[3]=f,e[4]=c):c=e[4],xt(c);const m=_&&!h;let C;e[5]!==P||e[6]!==u||e[7]!==O.isVSCode||e[8]!==m?(C={containerRef:w,effectiveDirectory:u,editor:P,preferRuntimeEditor:O.isVSCode,enabled:m},e[5]=P,e[6]=u,e[7]=O.isVSCode,e[8]=m,e[9]=C):C=e[9],Pt(C);let R;e[10]!==u?(R={containerRef:w,directory:u},e[10]=u,e[11]=R):R=e[11],Mt(R),Lt(w);let k;e[12]!==I?(k=it(I),e[12]=I,e[13]=k):k=e[13];const M=k,v=K(no)&&nn(),A=Ft(I,u&&!v?i:void 0,te),{locale:T}=lt(),E=x==="assistant"?"label":"local",$=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let W;e[14]===Symbol.for("react.memo_cache_sentinel")?(W=rn(),e[14]=W):W=e[14];const z=W,D=$?.sessionID,H=$?.messageID,de=$?.id;let U;e:{if(h||!D||!H||!de||n.length===0||n.length>Vr){U=null;break e}const j=`${z}\0${D}`,Ie=`${H}\0${de}\0${E}\0${n.length}`;let he;e[15]!==u||e[16]!==T||e[17]!==j||e[18]!==Ie?(he={scope:j,id:Ie,locale:T,directory:u},e[15]=u,e[16]=T,e[17]=j,e[18]=Ie,e[19]=he):he=e[19],U=he}const F=U,Le=`markdown-${r?.id?`part-${r.id}`:`message-${o}`}`,Me=!h;let ue;e[20]!==n||e[21]!==A||e[22]!==F||e[23]!==E||e[24]!==h||e[25]!==M||e[26]!==Me?(ue={containerRef:w,text:n,streaming:h,imageMode:E,syntaxVars:M,ctx:A,domCacheKey:F,tableLayoutSettled:Me},e[20]=n,e[21]=A,e[22]=F,e[23]=E,e[24]=h,e[25]=M,e[26]=Me,e[27]=ue):ue=e[27],Ot(ue);const Re=E==="label"&&!h?D:void 0;let me;e[28]!==u||e[29]!==f||e[30]!==H||e[31]!==Re?(me={containerRef:w,sessionId:Re,messageId:H,directory:u,onShowPopup:f},e[28]=u,e[29]=f,e[30]=H,e[31]=Re,e[32]=me):me=e[32],Hr(me);let Y;e[33]!==d?(Y=ct("break-words w-full min-w-0",d),e[33]=d,e[34]=Y):Y=e[34];let J;e[35]!==x?(J=Wt(x),e[35]=x,e[36]=J):J=e[36];let Q;e[37]!==J?(Q=B.jsx("div",{className:J,"data-markdown-content":!0}),e[37]=J,e[38]=Q):Q=e[38];let fe;e[39]!==Y||e[40]!==Q?(fe=B.jsx("div",{className:Y,ref:w,children:Q}),e[39]=Y,e[40]=Q,e[41]=fe):fe=e[41];const pe=fe;if(b){let j;return e[42]!==Le||e[43]!==pe||e[44]!==y?(j=B.jsx(Xt,{skipAnimation:y,children:pe},Le),e[42]=Le,e[43]=pe,e[44]=y,e[45]=j):j=e[45],j}return pe},ua=S.memo(Yr,(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),Jr=t=>{const e=V.c(36),{content:n,className:r,variant:o,disableLinkSafety:s,frontmatter:a,onShowPopup:d,mermaidControls:p,allowMermaidWheelEvents:l,enableFileReferences:f,allowRawHtml:g}=t,b=o===void 0?"assistant":o,y=p===void 0?te:p,h=l===void 0?!1:l,x=f===void 0?!0:f,_=g===void 0?!1:g,{editor:I,runtime:P}=st(),O=Ct(),w=S.useRef(null),u=at()??"";let L;e[0]!==n||e[1]!==a?(L=a?dr(n):{frontmatter:null,body:n},e[0]=n,e[1]=a,e[2]=L):L=e[2];const{frontmatter:N,body:i}=L;let c;e[3]!==h||e[4]!==y.showPanZoomControls||e[5]!==d?(c={containerRef:w,onShowPopup:d,enableFullscreen:Rt,enablePanZoom:y.showPanZoomControls,allowMermaidWheelEvents:h},e[3]=h,e[4]=y.showPanZoomControls,e[5]=d,e[6]=c):c=e[6],xt(c);let m;e[7]!==I||e[8]!==u||e[9]!==x||e[10]!==P.isVSCode?(m={containerRef:w,effectiveDirectory:u,editor:I,preferRuntimeEditor:P.isVSCode,enabled:x},e[7]=I,e[8]=u,e[9]=x,e[10]=P.isVSCode,e[11]=m):m=e[11],Pt(m);const C=!s;let R;e[12]!==u||e[13]!==C?(R={containerRef:w,enabled:C,directory:u},e[12]=u,e[13]=C,e[14]=R):R=e[14],Mt(R),Lt(w);let k;e[15]!==O?(k=it(O),e[15]=O,e[16]=k):k=e[16];const M=k,v=Ft(O,void 0,y),A=_?"sanitize":"escape";let T;e[17]!==v||e[18]!==i||e[19]!==M||e[20]!==A?(T={containerRef:w,text:i,streaming:!1,imageMode:"local",rawHtml:A,syntaxVars:M,ctx:v,tableLayoutSettled:!0},e[17]=v,e[18]=i,e[19]=M,e[20]=A,e[21]=T):T=e[21],Ot(T);let E;e[22]!==r?(E=ct("break-words w-full min-w-0",r),e[22]=r,e[23]=E):E=e[23];let $;e[24]!==N||e[25]!==a?($=a==="properties"&&N?B.jsx(mr,{frontmatter:N}):null,e[24]=N,e[25]=a,e[26]=$):$=e[26];let W;e[27]!==b?(W=Wt(b),e[27]=b,e[28]=W):W=e[28];const z=_?"":void 0;let D;e[29]!==W||e[30]!==z?(D=B.jsx("div",{className:W,"data-markdown-content":!0,"data-markdown-html":z}),e[29]=W,e[30]=z,e[31]=D):D=e[31];let H;return e[32]!==E||e[33]!==$||e[34]!==D?(H=B.jsxs("div",{className:E,ref:w,children:[$,D]}),e[32]=E,e[33]=$,e[34]=D,e[35]=H):H=e[35],H},ma=S.memo(Jr,(t,e)=>{const n=t.mermaidControls??te,r=e.mermaidControls??te;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.frontmatter===e.frontmatter&&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 Qr(t){Yt(t)}function eo(t){Jt(t.sessionId,t.messageId)}function to(t){return t.openContextPreview}function no(t){return t.openLinksInBrowserPanel}export{ua as MarkdownRenderer,ma as SimpleMarkdownRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as De,R as A,j as t}from"./vendor-react-BUCujlKS.js";import{u as Ve,F as Ze,aa as He,ab as We,ac as Ge,ad as Je,ae as Te,af as Xe,n as Fe,I as te,T as Ye,U as Ke,B as k,V as Qe,ag as et}from"./useAppFontEffects-Bih1DxXi.js";import{w as Se,x as Ne,y as tt}from"./katex.min-DQ8qF6NR.js";import{g as Le,r as st}from"./main-CVHM3_8W.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-dar6chwA.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-B66jUSmE.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DyL0aCoH.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-streamparser-CmlTsbN2.js";import"./vendor-codemirror-lang-javascript-Cem6LjJ8.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CIqXJolH.js";import"./vendor-codemirror-lang-json-C9rLLO0q.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-9qjxcVkg.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-D7VQUxeE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-Cikh4w2I.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BYGweLoh.js";import"./vendor-codemirror-lang-python-DVl8-2Op.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"./runtimeEndpointReset-CIpvn8QG.js";import"./useRootScrollLock-Cpk7NmBa.js";import"./moveWorkspacePath-CyZJ-2aD.js";import"./sessionOwnership-BZoGed9N.js";function rt(r){switch(r){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const ze=r=>{if(r<1e3)return`${Math.round(r)}ms`;const e=r/1e3;if(e<60)return`${e.toFixed(1)}s`;const u=Math.floor(e/60),s=Math.round(e%60);return`${u}m ${s}s`},Ae=r=>`${(r/1e3).toFixed(2)} s`,g=r=>{const e=De.c(8),{label:u,value:s}=r;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let n;e[1]!==u?(n=t.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[1]=u,e[2]=n):n=e[2];let c;e[3]!==s?(c=t.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:s}),e[3]=s,e[4]=c):c=e[4];let p;return e[5]!==n||e[6]!==c?(p=t.jsxs("div",{className:"rounded-md p-2",style:i,children:[n,c]}),e[5]=n,e[6]=c,e[7]=p):p=e[7],p},Oe=r=>{const e=De.c(43),{title:u,snapshot:s,emptyLabel:i}=r,{t:n}=Ve();let c;if(e[0]!==i||e[1]!==s.durationMs||e[2]!==s.entries||e[3]!==s.lastUpdatedAt||e[4]!==s.startedAt||e[5]!==n||e[6]!==u){const p=s.entries.slice(0,12);let v;e[8]!==s.entries?(v=s.entries.reduce(nt,0),e[8]=s.entries,e[9]=v):v=e[9];const S=v;let f;e[10]!==u?(f=t.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:u}),e[10]=u,e[11]=f):f=e[11];let l;e[12]!==s.durationMs||e[13]!==s.startedAt||e[14]!==n?(l=s.startedAt?ze(s.durationMs):n("memoryDebugPanel.common.idle"),e[12]=s.durationMs,e[13]=s.startedAt,e[14]=n,e[15]=l):l=e[15];let D;e[16]!==l?(D=t.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:l}),e[16]=l,e[17]=D):D=e[17];let x;e[18]!==f||e[19]!==D?(x=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[f,D]}),e[18]=f,e[19]=D,e[20]=x):x=e[20];let h;e[21]!==n?(h=n("memoryDebugPanel.metric.metrics"),e[21]=n,e[22]=h):h=e[22];let N;e[23]!==s.entries.length||e[24]!==h?(N=t.jsx(g,{label:h,value:s.entries.length}),e[23]=s.entries.length,e[24]=h,e[25]=N):N=e[25];let b;e[26]!==n?(b=n("memoryDebugPanel.metric.samples"),e[26]=n,e[27]=b):b=e[27];let a;e[28]!==b||e[29]!==S?(a=t.jsx(g,{label:b,value:S}),e[28]=b,e[29]=S,e[30]=a):a=e[30];let y;e[31]!==n?(y=n("memoryDebugPanel.metric.lastUpdate"),e[31]=n,e[32]=y):y=e[32];let j;e[33]!==s.lastUpdatedAt||e[34]!==n?(j=s.lastUpdatedAt?n("memoryDebugPanel.common.live"):n("memoryDebugPanel.common.notAvailable"),e[33]=s.lastUpdatedAt,e[34]=n,e[35]=j):j=e[35];let d;e[36]!==y||e[37]!==j?(d=t.jsx(g,{label:y,value:j}),e[36]=y,e[37]=j,e[38]=d):d=e[38];let P;e[39]!==a||e[40]!==d||e[41]!==N?(P=t.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[N,a,d]}),e[39]=a,e[40]=d,e[41]=N,e[42]=P):P=e[42],c=t.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,P,p.length===0?t.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):t.jsx(Fe,{outerClassName:"max-h-64",className:"pe-1",children:t.jsx("div",{className:"space-y-1",children:p.map(w=>t.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[t.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:w.metric}),t.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:n("memoryDebugPanel.metric.countValue",{value:w.count})}),t.jsx("span",{children:n("memoryDebugPanel.metric.avgValue",{value:w.avg})}),t.jsx("span",{children:n("memoryDebugPanel.metric.maxValue",{value:w.max})}),t.jsx("span",{children:n("memoryDebugPanel.metric.totalValue",{value:w.total})})]})]},w.metric))})})]}),e[0]=i,e[1]=s.durationMs,e[2]=s.entries,e[3]=s.lastUpdatedAt,e[4]=s.startedAt,e[5]=n,e[6]=u,e[7]=c}else c=e[7];return c},Ee=r=>{const e=De.c(24),{series:u,peak:s,windowSeconds:i,ariaLabel:n,maxLabel:c}=r,p=i,v=u.reduce(ot,0),S=s>0?52/s:0;let f;e[0]!==v||e[1]!==p?(f=d=>p-v+d,e[0]=v,e[1]=p,e[2]=f):f=e[2];const l=f;let D;e[3]!==S?(D=d=>56-d*S,e[3]=S,e[4]=D):D=e[4];const x=D;let h;e[5]!==c?(h=t.jsx("span",{className:"pointer-events-none absolute inset-s-0 top-0 typography-meta text-[var(--surface-muted-foreground)]",children:c}),e[5]=c,e[6]=h):h=e[6];const N=`0 0 ${p} 56`;let b;e[7]!==p?(b=t.jsx("line",{x1:0,y1:56,x2:p,y2:56,stroke:"var(--interactive-border)",strokeWidth:1,vectorEffect:"non-scaling-stroke"}),e[7]=p,e[8]=b):b=e[8];let a;if(e[9]!==u||e[10]!==l||e[11]!==x){let d;e[13]!==l||e[14]!==x?(d=(P,w)=>{const m=P.samples.length;if(m===0)return null;const C=P.samples.map((R,L)=>`${l(L)},${x(R).toFixed(2)}`),_=`M ${C.join(" L ")}`;return t.jsxs(A.Fragment,{children:[P.filled?t.jsx("path",{d:`M ${l(0)},56 L ${C.join(" L ")} L ${l(m-1)},56 Z`,fill:`color-mix(in srgb, ${P.color} 18%, transparent)`,stroke:"none"}):null,t.jsx("path",{d:_,fill:"none",stroke:P.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},w)},e[13]=l,e[14]=x,e[15]=d):d=e[15],a=u.map(d),e[9]=u,e[10]=l,e[11]=x,e[12]=a}else a=e[12];let y;e[16]!==n||e[17]!==N||e[18]!==b||e[19]!==a?(y=t.jsxs("svg",{viewBox:N,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":n,children:[b,a]}),e[16]=n,e[17]=N,e[18]=b,e[19]=a,e[20]=y):y=e[20];let j;return e[21]!==h||e[22]!==y?(j=t.jsxs("div",{className:"relative w-full",children:[h,y]}),e[21]=h,e[22]=y,e[23]=j):j=e[23],j},at=r=>{const e=De.c(100),{onClose:u}=r,{t:s}=Ve(),[i,n]=A.useState("memory"),[c,p]=A.useState("idle"),v=Ze(lt),S=He(it),f=We(),l=Ge(mt),D=Je(ct),[x,h]=A.useState(ut),[N,b]=A.useState(dt),[a,y]=A.useState(pt),j=[{label:"p50",current:a.ageP50,samples:a.p50Samples,color:"var(--status-success)"},{label:"p90",current:a.ageP90,samples:a.p90Samples,color:"var(--status-info)"},{label:"p99",current:a.ageP99,samples:a.p99Samples,color:"var(--status-warning)"},{label:"max",current:a.ageMax,samples:a.maxSamples,color:"var(--status-error)"}];let d;e[0]!==a.samples?(d=a.samples.reduce(gt,0),e[0]=a.samples,e[1]=d):d=e[1];const P=d,w=j.reduce(xt,0);let m;e[2]!==x.entries?(m=new Map,x.entries.forEach(o=>{m.set(o.metric,o.count)}),e[2]=x.entries,e[3]=m):m=e[3];let C;e[4]!==m?(C=m.get("ui.message_list.render")??0,e[4]=m,e[5]=C):C=e[5];let _;e[6]!==m?(_=m.get("ui.message_list.render.streaming")??0,e[6]=m,e[7]=_):_=e[7];let R;e[8]!==m?(R=m.get("ui.chat_message.render")??0,e[8]=m,e[9]=R):R=e[9];let L;e[10]!==m?(L=m.get("ui.chat_message.render.streaming")??0,e[10]=m,e[11]=L):L=e[11];let $;e[12]!==m?($=m.get("ui.chat_message.render.static_during_stream")??0,e[12]=m,e[13]=$):$=e[13];let q;e[14]!==m?(q=m.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=m,e[15]=q):q=e[15];let oe;e[16]!==C||e[17]!==_||e[18]!==R||e[19]!==L||e[20]!==$||e[21]!==q?(oe={messageListRender:C,messageListRenderStreaming:_,chatMessageRender:R,chatMessageRenderStreaming:L,chatMessageRenderStaticDuringStream:$,chatMessageRenderStaticOutsideActiveTurnDuringStream:q},e[16]=C,e[17]=_,e[18]=R,e[19]=L,e[20]=$,e[21]=q,e[22]=oe):oe=e[22];const I=oe;let le,ie;e[23]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>{const o=()=>{h(Se()),b(Ne()),y(Le())};o();const M=window.setInterval(o,500);return()=>window.clearInterval(M)},le=[],e[23]=le,e[24]=ie):(le=e[23],ie=e[24]),A.useEffect(ie,le);let me,ce;e[25]!==c?(me=()=>{if(c==="idle")return;const o=window.setTimeout(()=>{p("idle")},1500);return()=>window.clearTimeout(o)},ce=[c],e[25]=c,e[26]=me,e[27]=ce):(me=e[26],ce=e[27]),A.useEffect(me,ce);let se=0,re=0,ae=0;for(const o of Object.keys(l)){const M=l[o]??[];re=re+M.length;for(const ne of M)ne.role==="user"?ae=ae+1:ne.role==="assistant"&&(se=se+1)}let ue;e[28]!==se||e[29]!==re||e[30]!==ae?(ue={assistant:se,total:re,user:ae},e[28]=se,e[29]=re,e[30]=ae,e[31]=ue):ue=e[31];const de=ue;let pe;if(e[32]!==v||e[33]!==l||e[34]!==S||e[35]!==f||e[36]!==s){let o;e[38]!==v||e[39]!==l||e[40]!==S||e[41]!==s?(o=M=>{const ne=l[M.id]??[];let _e=0,Re=0;for(const Ie of ne)Ie.role==="user"?Re=Re+1:Ie.role==="assistant"&&(_e=_e+1);const je=S.get(M.id);return{id:M.id,title:M.title||s("memoryDebugPanel.common.untitled"),assistantMessageCount:_e,messageCount:ne.length,userMessageCount:Re,isStreaming:je?.isStreaming||!1,isZombie:je?.isZombie||!1,backgroundCount:je?.backgroundMessageCount||0,lastAccessed:je?.lastAccessedAt||0,isCurrent:M.id===v}},e[38]=v,e[39]=l,e[40]=S,e[41]=s,e[42]=o):o=e[42],pe=f.map(o).sort(ht),e[32]=v,e[33]=l,e[34]=S,e[35]=f,e[36]=s,e[37]=pe}else pe=e[37];const $e=pe;let ge;e[43]!==l?(ge=Object.keys(l),e[43]=l,e[44]=ge):ge=e[44];const Ue=ge.length;let fe;e[45]===Symbol.for("react.memo_cache_sentinel")?(fe=async()=>{try{const o={generatedAt:new Date().toISOString(),ui:Se(),vscode:Ne()};await navigator.clipboard.writeText(JSON.stringify(o,null,2)),p("copied")}catch{p("error")}},e[45]=fe):fe=e[45];const qe=fe,Pe=et,Be="fixed bottom-4 inset-e-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let T;e[46]===Symbol.for("react.memo_cache_sentinel")?(T={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=T):T=e[46];let O;e[47]!==i?(O=rt(i),e[47]=i,e[48]=O):O=e[48];let E;e[49]!==O?(E=t.jsx(te,{name:O,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=O,e[50]=E):E=e[50];let V;e[51]!==s?(V=s("memoryDebugPanel.title"),e[51]=s,e[52]=V):V=e[52];let F;e[53]!==V?(F=t.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:V}),e[53]=V,e[54]=F):F=e[54];let z;e[55]!==E||e[56]!==F?(z=t.jsxs("div",{className:"flex items-center gap-2",children:[E,F]}),e[55]=E,e[56]=F,e[57]=z):z=e[57];let U;e[58]!==i?(U=i==="streaming"?t.jsxs(t.Fragment,{children:[t.jsx(k,{size:"xs",variant:"ghost",onClick:qe,children:t.jsx(te,{name:"file-copy",className:"h-3.5 w-3.5"})}),t.jsx(k,{size:"xs",variant:"ghost",onClick:()=>{tt(),h(Se()),b(Ne())},children:t.jsx(te,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=U):U=e[59];let B;e[60]!==i?(B=i==="requests"?t.jsx(k,{size:"xs",variant:"ghost",onClick:()=>{st(),y(Le())},children:t.jsx(te,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=B):B=e[61];let Z;e[62]!==u?(Z=u?t.jsx(k,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:u,children:t.jsx(te,{name:"close",className:"h-4 w-4"})}):null,e[62]=u,e[63]=Z):Z=e[63];let H;e[64]!==U||e[65]!==B||e[66]!==Z?(H=t.jsxs("div",{className:"flex items-center gap-1",children:[U,B,Z]}),e[64]=U,e[65]=B,e[66]=Z,e[67]=H):H=e[67];let W;e[68]!==z||e[69]!==H?(W=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[z,H]}),e[68]=z,e[69]=H,e[70]=W):W=e[70];let xe;e[71]===Symbol.for("react.memo_cache_sentinel")?(xe={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=xe):xe=e[71];const we=i==="memory"?"secondary":"ghost";let he;e[72]===Symbol.for("react.memo_cache_sentinel")?(he=()=>n("memory"),e[72]=he):he=e[72];let G;e[73]!==s?(G=s("memoryDebugPanel.tabs.memory"),e[73]=s,e[74]=G):G=e[74];let J;e[75]!==we||e[76]!==G?(J=t.jsx(k,{size:"sm",variant:we,className:"flex-1",onClick:he,children:G}),e[75]=we,e[76]=G,e[77]=J):J=e[77];const Me=i==="streaming"?"secondary":"ghost";let be;e[78]===Symbol.for("react.memo_cache_sentinel")?(be=()=>n("streaming"),e[78]=be):be=e[78];let X;e[79]!==s?(X=s("memoryDebugPanel.tabs.streaming"),e[79]=s,e[80]=X):X=e[80];let Y;e[81]!==Me||e[82]!==X?(Y=t.jsx(k,{size:"sm",variant:Me,className:"flex-1",onClick:be,children:X}),e[81]=Me,e[82]=X,e[83]=Y):Y=e[83];const Ce=i==="requests"?"secondary":"ghost";let ye;e[84]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>n("requests"),e[84]=ye):ye=e[84];let K;e[85]!==s?(K=s("memoryDebugPanel.tabs.requests"),e[85]=s,e[86]=K):K=e[86];let Q;e[87]!==Ce||e[88]!==K?(Q=t.jsx(k,{size:"sm",variant:Ce,className:"flex-1",onClick:ye,children:K}),e[87]=Ce,e[88]=K,e[89]=Q):Q=e[89];let ee;e[90]!==J||e[91]!==Y||e[92]!==Q?(ee=t.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:xe,children:[J,Y,Q]}),e[90]=J,e[91]=Y,e[92]=Q,e[93]=ee):ee=e[93];const ke=i==="memory"?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[t.jsx(g,{label:s("memoryDebugPanel.metric.totalMessages"),value:de.total}),t.jsx(g,{label:s("memoryDebugPanel.metric.cachedSessions"),value:`${Ue} / ${Te.MAX_SESSIONS}`}),t.jsx(g,{label:s("memoryDebugPanel.metric.userMessages"),value:de.user}),t.jsx(g,{label:s("memoryDebugPanel.metric.assistantMessages"),value:de.assistant})]}),t.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.viewportWindow")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.messagesValue",{count:Xe()})})]}),t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.zombieTimeout")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.minutesValue",{count:Te.ZOMBIE_TIMEOUT/1e3/60})})]}),t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.githubTotalRequests")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:D})]})]}),t.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[t.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:s("memoryDebugPanel.section.sessionsInMemory")}),t.jsx(Fe,{outerClassName:"max-h-48",className:"space-y-1 pe-1",children:$e.map(o=>t.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:o.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:o.title}),o.isStreaming?t.jsx(te,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,o.isZombie?t.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.roleMsgsValue",{assistant:o.assistantMessageCount,user:o.userMessageCount})}),t.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.msgsValue",{count:o.messageCount})}),o.backgroundCount>0?t.jsxs("span",{className:"text-[var(--status-info)]",children:["+",o.backgroundCount]}):null]})]},o.id))})]}),t.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:t.jsxs(Ye,{children:[t.jsx(Ke,{asChild:!0,children:t.jsx(k,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:f.map(bt),currentSessionId:v,cachedSessions:Object.keys(l),messageRoleCounts:de,sessionMessageRoleCounts:$e.map(yt),memoryStates:Object.fromEntries(S)})},children:s("memoryDebugPanel.actions.logState")})}),t.jsx(Qe,{side:"top",children:s("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):i==="streaming"?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:s(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),t.jsx(k,{size:"xs",variant:"outline",onClick:qe,children:s("memoryDebugPanel.actions.copyJson")})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(g,{label:s("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),t.jsx(g,{label:s("memoryDebugPanel.metric.vscodeMetrics"),value:N.entries.length}),t.jsx(g,{label:s("memoryDebugPanel.metric.messageListRenders"),value:I.messageListRender}),t.jsx(g,{label:s("memoryDebugPanel.metric.messageListStreamRenders"),value:I.messageListRenderStreaming}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageRenders"),value:I.chatMessageRender}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStreamRenders"),value:I.chatMessageRenderStreaming}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:I.chatMessageRenderStaticDuringStream}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:I.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),t.jsx(Oe,{title:s("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:s("memoryDebugPanel.section.noUiSamples")}),N.entries.length>0?t.jsx(Oe,{title:s("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:N,emptyLabel:s("memoryDebugPanel.section.noVscodeSamples")}):null]}):t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[t.jsx(g,{label:s("memoryDebugPanel.requests.totalRequests"),value:`${a.totalSettled} / ${a.totalStarted}`}),t.jsx(g,{label:s("memoryDebugPanel.requests.tracking"),value:a.startedAt?ze(a.durationMs):s("memoryDebugPanel.common.idle")})]}),a.samples.length===0?t.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:s("memoryDebugPanel.requests.noSamples")}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.requests.inFlight")}),t.jsxs("span",{children:[t.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:a.inFlight}),t.jsxs("span",{className:"text-[var(--surface-muted-foreground)]",children:[" · ",s("memoryDebugPanel.requests.peak")," "]}),t.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:a.peak})]})]}),t.jsx(Ee,{series:[{samples:a.samples,color:"var(--status-info)",filled:!0}],peak:P,windowSeconds:a.windowSeconds,ariaLabel:s("memoryDebugPanel.requests.chartLabel",{peak:a.peak}),maxLabel:`${P}`}),t.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.requests.duration")}),t.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:Ae(a.peakAgeMs)})]}),t.jsx(Ee,{series:j.map(vt),peak:w,windowSeconds:a.windowSeconds,ariaLabel:s("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:Ae(w)}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:j.map(jt)}),t.jsxs("div",{className:"flex items-center justify-between typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:s("memoryDebugPanel.requests.windowHint",{seconds:a.windowSeconds})}),t.jsx("span",{children:s("memoryDebugPanel.requests.now")})]})]})]});let ve;return e[94]!==Pe||e[95]!==T||e[96]!==W||e[97]!==ee||e[98]!==ke?(ve=t.jsxs(Pe,{className:Be,style:T,children:[W,ee,ke]}),e[94]=Pe,e[95]=T,e[96]=W,e[97]=ee,e[98]=ke,e[99]=ve):ve=e[99],ve},tr=at;function nt(r,e){return r+e.count}function ot(r,e){return Math.max(r,e.samples.length)}function lt(r){return r.currentSessionId}function it(r){return r.sessionMemoryState}function mt(r){return r.message}function ct(r){return r.totalRequestCount}function ut(){return Se()}function dt(){return Ne()}function pt(){return Le()}function gt(r,e){return Math.max(r,e)}function ft(r,e){return Math.max(r,e)}function xt(r,e){return e.samples.reduce(ft,r)}function ht(r,e){return e.lastAccessed-r.lastAccessed}function bt(r){return{id:r.id,title:r.title}}function yt(r){return{id:r.id,title:r.title,total:r.messageCount,user:r.userMessageCount,assistant:r.assistantMessageCount}}function vt(r){return{samples:r.samples,color:r.color}}function jt(r){return t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:r.color}}),t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r.label}),t.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:Ae(r.current)})]},r.label)}export{tr as MemoryDebugPanel};
|
|
1
|
+
import{f as De,R as A,j as t}from"./vendor-react-BUCujlKS.js";import{u as Ve,F as Ze,aa as He,ab as We,ac as Ge,ad as Je,ae as Te,af as Xe,n as Fe,I as te,T as Ye,U as Ke,B as k,V as Qe,ag as et}from"./useAppFontEffects-Cs6k0JKv.js";import{w as Se,x as Ne,y as tt}from"./katex.min-EZjpSwGK.js";import{g as Le,r as st}from"./main-BUetg9hg.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-Dozz-7fb.js";import"./vendor-tanstack-virtual-core-DKBj55Em.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-dar6chwA.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-B66jUSmE.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DyL0aCoH.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-streamparser-CmlTsbN2.js";import"./vendor-codemirror-lang-javascript-Cem6LjJ8.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CIqXJolH.js";import"./vendor-codemirror-lang-json-C9rLLO0q.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-9qjxcVkg.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-D7VQUxeE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-Cikh4w2I.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DBekkZIx.js";import"./vendor-codemirror-lang-python-DVl8-2Op.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"./runtimeEndpointReset-6CNNzem4.js";import"./useRootScrollLock-Dov-44ov.js";import"./moveWorkspacePath-CnYc96Xo.js";import"./sessionOwnership-BBuf0UCB.js";function rt(r){switch(r){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const ze=r=>{if(r<1e3)return`${Math.round(r)}ms`;const e=r/1e3;if(e<60)return`${e.toFixed(1)}s`;const u=Math.floor(e/60),s=Math.round(e%60);return`${u}m ${s}s`},Ae=r=>`${(r/1e3).toFixed(2)} s`,g=r=>{const e=De.c(8),{label:u,value:s}=r;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let n;e[1]!==u?(n=t.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[1]=u,e[2]=n):n=e[2];let c;e[3]!==s?(c=t.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:s}),e[3]=s,e[4]=c):c=e[4];let p;return e[5]!==n||e[6]!==c?(p=t.jsxs("div",{className:"rounded-md p-2",style:i,children:[n,c]}),e[5]=n,e[6]=c,e[7]=p):p=e[7],p},Oe=r=>{const e=De.c(43),{title:u,snapshot:s,emptyLabel:i}=r,{t:n}=Ve();let c;if(e[0]!==i||e[1]!==s.durationMs||e[2]!==s.entries||e[3]!==s.lastUpdatedAt||e[4]!==s.startedAt||e[5]!==n||e[6]!==u){const p=s.entries.slice(0,12);let v;e[8]!==s.entries?(v=s.entries.reduce(nt,0),e[8]=s.entries,e[9]=v):v=e[9];const S=v;let f;e[10]!==u?(f=t.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:u}),e[10]=u,e[11]=f):f=e[11];let l;e[12]!==s.durationMs||e[13]!==s.startedAt||e[14]!==n?(l=s.startedAt?ze(s.durationMs):n("memoryDebugPanel.common.idle"),e[12]=s.durationMs,e[13]=s.startedAt,e[14]=n,e[15]=l):l=e[15];let D;e[16]!==l?(D=t.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:l}),e[16]=l,e[17]=D):D=e[17];let x;e[18]!==f||e[19]!==D?(x=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[f,D]}),e[18]=f,e[19]=D,e[20]=x):x=e[20];let h;e[21]!==n?(h=n("memoryDebugPanel.metric.metrics"),e[21]=n,e[22]=h):h=e[22];let N;e[23]!==s.entries.length||e[24]!==h?(N=t.jsx(g,{label:h,value:s.entries.length}),e[23]=s.entries.length,e[24]=h,e[25]=N):N=e[25];let b;e[26]!==n?(b=n("memoryDebugPanel.metric.samples"),e[26]=n,e[27]=b):b=e[27];let a;e[28]!==b||e[29]!==S?(a=t.jsx(g,{label:b,value:S}),e[28]=b,e[29]=S,e[30]=a):a=e[30];let y;e[31]!==n?(y=n("memoryDebugPanel.metric.lastUpdate"),e[31]=n,e[32]=y):y=e[32];let j;e[33]!==s.lastUpdatedAt||e[34]!==n?(j=s.lastUpdatedAt?n("memoryDebugPanel.common.live"):n("memoryDebugPanel.common.notAvailable"),e[33]=s.lastUpdatedAt,e[34]=n,e[35]=j):j=e[35];let d;e[36]!==y||e[37]!==j?(d=t.jsx(g,{label:y,value:j}),e[36]=y,e[37]=j,e[38]=d):d=e[38];let P;e[39]!==a||e[40]!==d||e[41]!==N?(P=t.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[N,a,d]}),e[39]=a,e[40]=d,e[41]=N,e[42]=P):P=e[42],c=t.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,P,p.length===0?t.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):t.jsx(Fe,{outerClassName:"max-h-64",className:"pe-1",children:t.jsx("div",{className:"space-y-1",children:p.map(w=>t.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[t.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:w.metric}),t.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:n("memoryDebugPanel.metric.countValue",{value:w.count})}),t.jsx("span",{children:n("memoryDebugPanel.metric.avgValue",{value:w.avg})}),t.jsx("span",{children:n("memoryDebugPanel.metric.maxValue",{value:w.max})}),t.jsx("span",{children:n("memoryDebugPanel.metric.totalValue",{value:w.total})})]})]},w.metric))})})]}),e[0]=i,e[1]=s.durationMs,e[2]=s.entries,e[3]=s.lastUpdatedAt,e[4]=s.startedAt,e[5]=n,e[6]=u,e[7]=c}else c=e[7];return c},Ee=r=>{const e=De.c(24),{series:u,peak:s,windowSeconds:i,ariaLabel:n,maxLabel:c}=r,p=i,v=u.reduce(ot,0),S=s>0?52/s:0;let f;e[0]!==v||e[1]!==p?(f=d=>p-v+d,e[0]=v,e[1]=p,e[2]=f):f=e[2];const l=f;let D;e[3]!==S?(D=d=>56-d*S,e[3]=S,e[4]=D):D=e[4];const x=D;let h;e[5]!==c?(h=t.jsx("span",{className:"pointer-events-none absolute inset-s-0 top-0 typography-meta text-[var(--surface-muted-foreground)]",children:c}),e[5]=c,e[6]=h):h=e[6];const N=`0 0 ${p} 56`;let b;e[7]!==p?(b=t.jsx("line",{x1:0,y1:56,x2:p,y2:56,stroke:"var(--interactive-border)",strokeWidth:1,vectorEffect:"non-scaling-stroke"}),e[7]=p,e[8]=b):b=e[8];let a;if(e[9]!==u||e[10]!==l||e[11]!==x){let d;e[13]!==l||e[14]!==x?(d=(P,w)=>{const m=P.samples.length;if(m===0)return null;const C=P.samples.map((R,L)=>`${l(L)},${x(R).toFixed(2)}`),_=`M ${C.join(" L ")}`;return t.jsxs(A.Fragment,{children:[P.filled?t.jsx("path",{d:`M ${l(0)},56 L ${C.join(" L ")} L ${l(m-1)},56 Z`,fill:`color-mix(in srgb, ${P.color} 18%, transparent)`,stroke:"none"}):null,t.jsx("path",{d:_,fill:"none",stroke:P.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},w)},e[13]=l,e[14]=x,e[15]=d):d=e[15],a=u.map(d),e[9]=u,e[10]=l,e[11]=x,e[12]=a}else a=e[12];let y;e[16]!==n||e[17]!==N||e[18]!==b||e[19]!==a?(y=t.jsxs("svg",{viewBox:N,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":n,children:[b,a]}),e[16]=n,e[17]=N,e[18]=b,e[19]=a,e[20]=y):y=e[20];let j;return e[21]!==h||e[22]!==y?(j=t.jsxs("div",{className:"relative w-full",children:[h,y]}),e[21]=h,e[22]=y,e[23]=j):j=e[23],j},at=r=>{const e=De.c(100),{onClose:u}=r,{t:s}=Ve(),[i,n]=A.useState("memory"),[c,p]=A.useState("idle"),v=Ze(lt),S=He(it),f=We(),l=Ge(mt),D=Je(ct),[x,h]=A.useState(ut),[N,b]=A.useState(dt),[a,y]=A.useState(pt),j=[{label:"p50",current:a.ageP50,samples:a.p50Samples,color:"var(--status-success)"},{label:"p90",current:a.ageP90,samples:a.p90Samples,color:"var(--status-info)"},{label:"p99",current:a.ageP99,samples:a.p99Samples,color:"var(--status-warning)"},{label:"max",current:a.ageMax,samples:a.maxSamples,color:"var(--status-error)"}];let d;e[0]!==a.samples?(d=a.samples.reduce(gt,0),e[0]=a.samples,e[1]=d):d=e[1];const P=d,w=j.reduce(xt,0);let m;e[2]!==x.entries?(m=new Map,x.entries.forEach(o=>{m.set(o.metric,o.count)}),e[2]=x.entries,e[3]=m):m=e[3];let C;e[4]!==m?(C=m.get("ui.message_list.render")??0,e[4]=m,e[5]=C):C=e[5];let _;e[6]!==m?(_=m.get("ui.message_list.render.streaming")??0,e[6]=m,e[7]=_):_=e[7];let R;e[8]!==m?(R=m.get("ui.chat_message.render")??0,e[8]=m,e[9]=R):R=e[9];let L;e[10]!==m?(L=m.get("ui.chat_message.render.streaming")??0,e[10]=m,e[11]=L):L=e[11];let $;e[12]!==m?($=m.get("ui.chat_message.render.static_during_stream")??0,e[12]=m,e[13]=$):$=e[13];let q;e[14]!==m?(q=m.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=m,e[15]=q):q=e[15];let oe;e[16]!==C||e[17]!==_||e[18]!==R||e[19]!==L||e[20]!==$||e[21]!==q?(oe={messageListRender:C,messageListRenderStreaming:_,chatMessageRender:R,chatMessageRenderStreaming:L,chatMessageRenderStaticDuringStream:$,chatMessageRenderStaticOutsideActiveTurnDuringStream:q},e[16]=C,e[17]=_,e[18]=R,e[19]=L,e[20]=$,e[21]=q,e[22]=oe):oe=e[22];const I=oe;let le,ie;e[23]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>{const o=()=>{h(Se()),b(Ne()),y(Le())};o();const M=window.setInterval(o,500);return()=>window.clearInterval(M)},le=[],e[23]=le,e[24]=ie):(le=e[23],ie=e[24]),A.useEffect(ie,le);let me,ce;e[25]!==c?(me=()=>{if(c==="idle")return;const o=window.setTimeout(()=>{p("idle")},1500);return()=>window.clearTimeout(o)},ce=[c],e[25]=c,e[26]=me,e[27]=ce):(me=e[26],ce=e[27]),A.useEffect(me,ce);let se=0,re=0,ae=0;for(const o of Object.keys(l)){const M=l[o]??[];re=re+M.length;for(const ne of M)ne.role==="user"?ae=ae+1:ne.role==="assistant"&&(se=se+1)}let ue;e[28]!==se||e[29]!==re||e[30]!==ae?(ue={assistant:se,total:re,user:ae},e[28]=se,e[29]=re,e[30]=ae,e[31]=ue):ue=e[31];const de=ue;let pe;if(e[32]!==v||e[33]!==l||e[34]!==S||e[35]!==f||e[36]!==s){let o;e[38]!==v||e[39]!==l||e[40]!==S||e[41]!==s?(o=M=>{const ne=l[M.id]??[];let _e=0,Re=0;for(const Ie of ne)Ie.role==="user"?Re=Re+1:Ie.role==="assistant"&&(_e=_e+1);const je=S.get(M.id);return{id:M.id,title:M.title||s("memoryDebugPanel.common.untitled"),assistantMessageCount:_e,messageCount:ne.length,userMessageCount:Re,isStreaming:je?.isStreaming||!1,isZombie:je?.isZombie||!1,backgroundCount:je?.backgroundMessageCount||0,lastAccessed:je?.lastAccessedAt||0,isCurrent:M.id===v}},e[38]=v,e[39]=l,e[40]=S,e[41]=s,e[42]=o):o=e[42],pe=f.map(o).sort(ht),e[32]=v,e[33]=l,e[34]=S,e[35]=f,e[36]=s,e[37]=pe}else pe=e[37];const $e=pe;let ge;e[43]!==l?(ge=Object.keys(l),e[43]=l,e[44]=ge):ge=e[44];const Ue=ge.length;let fe;e[45]===Symbol.for("react.memo_cache_sentinel")?(fe=async()=>{try{const o={generatedAt:new Date().toISOString(),ui:Se(),vscode:Ne()};await navigator.clipboard.writeText(JSON.stringify(o,null,2)),p("copied")}catch{p("error")}},e[45]=fe):fe=e[45];const qe=fe,Pe=et,Be="fixed bottom-4 inset-e-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let T;e[46]===Symbol.for("react.memo_cache_sentinel")?(T={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=T):T=e[46];let O;e[47]!==i?(O=rt(i),e[47]=i,e[48]=O):O=e[48];let E;e[49]!==O?(E=t.jsx(te,{name:O,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=O,e[50]=E):E=e[50];let V;e[51]!==s?(V=s("memoryDebugPanel.title"),e[51]=s,e[52]=V):V=e[52];let F;e[53]!==V?(F=t.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:V}),e[53]=V,e[54]=F):F=e[54];let z;e[55]!==E||e[56]!==F?(z=t.jsxs("div",{className:"flex items-center gap-2",children:[E,F]}),e[55]=E,e[56]=F,e[57]=z):z=e[57];let U;e[58]!==i?(U=i==="streaming"?t.jsxs(t.Fragment,{children:[t.jsx(k,{size:"xs",variant:"ghost",onClick:qe,children:t.jsx(te,{name:"file-copy",className:"h-3.5 w-3.5"})}),t.jsx(k,{size:"xs",variant:"ghost",onClick:()=>{tt(),h(Se()),b(Ne())},children:t.jsx(te,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=U):U=e[59];let B;e[60]!==i?(B=i==="requests"?t.jsx(k,{size:"xs",variant:"ghost",onClick:()=>{st(),y(Le())},children:t.jsx(te,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=B):B=e[61];let Z;e[62]!==u?(Z=u?t.jsx(k,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:u,children:t.jsx(te,{name:"close",className:"h-4 w-4"})}):null,e[62]=u,e[63]=Z):Z=e[63];let H;e[64]!==U||e[65]!==B||e[66]!==Z?(H=t.jsxs("div",{className:"flex items-center gap-1",children:[U,B,Z]}),e[64]=U,e[65]=B,e[66]=Z,e[67]=H):H=e[67];let W;e[68]!==z||e[69]!==H?(W=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[z,H]}),e[68]=z,e[69]=H,e[70]=W):W=e[70];let xe;e[71]===Symbol.for("react.memo_cache_sentinel")?(xe={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=xe):xe=e[71];const we=i==="memory"?"secondary":"ghost";let he;e[72]===Symbol.for("react.memo_cache_sentinel")?(he=()=>n("memory"),e[72]=he):he=e[72];let G;e[73]!==s?(G=s("memoryDebugPanel.tabs.memory"),e[73]=s,e[74]=G):G=e[74];let J;e[75]!==we||e[76]!==G?(J=t.jsx(k,{size:"sm",variant:we,className:"flex-1",onClick:he,children:G}),e[75]=we,e[76]=G,e[77]=J):J=e[77];const Me=i==="streaming"?"secondary":"ghost";let be;e[78]===Symbol.for("react.memo_cache_sentinel")?(be=()=>n("streaming"),e[78]=be):be=e[78];let X;e[79]!==s?(X=s("memoryDebugPanel.tabs.streaming"),e[79]=s,e[80]=X):X=e[80];let Y;e[81]!==Me||e[82]!==X?(Y=t.jsx(k,{size:"sm",variant:Me,className:"flex-1",onClick:be,children:X}),e[81]=Me,e[82]=X,e[83]=Y):Y=e[83];const Ce=i==="requests"?"secondary":"ghost";let ye;e[84]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>n("requests"),e[84]=ye):ye=e[84];let K;e[85]!==s?(K=s("memoryDebugPanel.tabs.requests"),e[85]=s,e[86]=K):K=e[86];let Q;e[87]!==Ce||e[88]!==K?(Q=t.jsx(k,{size:"sm",variant:Ce,className:"flex-1",onClick:ye,children:K}),e[87]=Ce,e[88]=K,e[89]=Q):Q=e[89];let ee;e[90]!==J||e[91]!==Y||e[92]!==Q?(ee=t.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:xe,children:[J,Y,Q]}),e[90]=J,e[91]=Y,e[92]=Q,e[93]=ee):ee=e[93];const ke=i==="memory"?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[t.jsx(g,{label:s("memoryDebugPanel.metric.totalMessages"),value:de.total}),t.jsx(g,{label:s("memoryDebugPanel.metric.cachedSessions"),value:`${Ue} / ${Te.MAX_SESSIONS}`}),t.jsx(g,{label:s("memoryDebugPanel.metric.userMessages"),value:de.user}),t.jsx(g,{label:s("memoryDebugPanel.metric.assistantMessages"),value:de.assistant})]}),t.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.viewportWindow")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.messagesValue",{count:Xe()})})]}),t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.zombieTimeout")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.minutesValue",{count:Te.ZOMBIE_TIMEOUT/1e3/60})})]}),t.jsxs("div",{className:"flex justify-between gap-2",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.githubTotalRequests")}),t.jsx("span",{className:"text-[var(--surface-foreground)]",children:D})]})]}),t.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[t.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:s("memoryDebugPanel.section.sessionsInMemory")}),t.jsx(Fe,{outerClassName:"max-h-48",className:"space-y-1 pe-1",children:$e.map(o=>t.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:o.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:o.title}),o.isStreaming?t.jsx(te,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,o.isZombie?t.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.metric.roleMsgsValue",{assistant:o.assistantMessageCount,user:o.userMessageCount})}),t.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:s("memoryDebugPanel.metric.msgsValue",{count:o.messageCount})}),o.backgroundCount>0?t.jsxs("span",{className:"text-[var(--status-info)]",children:["+",o.backgroundCount]}):null]})]},o.id))})]}),t.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:t.jsxs(Ye,{children:[t.jsx(Ke,{asChild:!0,children:t.jsx(k,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:f.map(bt),currentSessionId:v,cachedSessions:Object.keys(l),messageRoleCounts:de,sessionMessageRoleCounts:$e.map(yt),memoryStates:Object.fromEntries(S)})},children:s("memoryDebugPanel.actions.logState")})}),t.jsx(Qe,{side:"top",children:s("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):i==="streaming"?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:s(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),t.jsx(k,{size:"xs",variant:"outline",onClick:qe,children:s("memoryDebugPanel.actions.copyJson")})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(g,{label:s("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),t.jsx(g,{label:s("memoryDebugPanel.metric.vscodeMetrics"),value:N.entries.length}),t.jsx(g,{label:s("memoryDebugPanel.metric.messageListRenders"),value:I.messageListRender}),t.jsx(g,{label:s("memoryDebugPanel.metric.messageListStreamRenders"),value:I.messageListRenderStreaming}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageRenders"),value:I.chatMessageRender}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStreamRenders"),value:I.chatMessageRenderStreaming}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:I.chatMessageRenderStaticDuringStream}),t.jsx(g,{label:s("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:I.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),t.jsx(Oe,{title:s("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:s("memoryDebugPanel.section.noUiSamples")}),N.entries.length>0?t.jsx(Oe,{title:s("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:N,emptyLabel:s("memoryDebugPanel.section.noVscodeSamples")}):null]}):t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[t.jsx(g,{label:s("memoryDebugPanel.requests.totalRequests"),value:`${a.totalSettled} / ${a.totalStarted}`}),t.jsx(g,{label:s("memoryDebugPanel.requests.tracking"),value:a.startedAt?ze(a.durationMs):s("memoryDebugPanel.common.idle")})]}),a.samples.length===0?t.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:s("memoryDebugPanel.requests.noSamples")}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.requests.inFlight")}),t.jsxs("span",{children:[t.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:a.inFlight}),t.jsxs("span",{className:"text-[var(--surface-muted-foreground)]",children:[" · ",s("memoryDebugPanel.requests.peak")," "]}),t.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:a.peak})]})]}),t.jsx(Ee,{series:[{samples:a.samples,color:"var(--status-info)",filled:!0}],peak:P,windowSeconds:a.windowSeconds,ariaLabel:s("memoryDebugPanel.requests.chartLabel",{peak:a.peak}),maxLabel:`${P}`}),t.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:s("memoryDebugPanel.requests.duration")}),t.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:Ae(a.peakAgeMs)})]}),t.jsx(Ee,{series:j.map(vt),peak:w,windowSeconds:a.windowSeconds,ariaLabel:s("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:Ae(w)}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:j.map(jt)}),t.jsxs("div",{className:"flex items-center justify-between typography-meta text-[var(--surface-muted-foreground)]",children:[t.jsx("span",{children:s("memoryDebugPanel.requests.windowHint",{seconds:a.windowSeconds})}),t.jsx("span",{children:s("memoryDebugPanel.requests.now")})]})]})]});let ve;return e[94]!==Pe||e[95]!==T||e[96]!==W||e[97]!==ee||e[98]!==ke?(ve=t.jsxs(Pe,{className:Be,style:T,children:[W,ee,ke]}),e[94]=Pe,e[95]=T,e[96]=W,e[97]=ee,e[98]=ke,e[99]=ve):ve=e[99],ve},tr=at;function nt(r,e){return r+e.count}function ot(r,e){return Math.max(r,e.samples.length)}function lt(r){return r.currentSessionId}function it(r){return r.sessionMemoryState}function mt(r){return r.message}function ct(r){return r.totalRequestCount}function ut(){return Se()}function dt(){return Ne()}function pt(){return Le()}function gt(r,e){return Math.max(r,e)}function ft(r,e){return Math.max(r,e)}function xt(r,e){return e.samples.reduce(ft,r)}function ht(r,e){return e.lastAccessed-r.lastAccessed}function bt(r){return{id:r.id,title:r.title}}function yt(r){return{id:r.id,title:r.title,total:r.messageCount,user:r.userMessageCount,assistant:r.assistantMessageCount}}function vt(r){return{samples:r.samples,color:r.color}}function jt(r){return t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:r.color}}),t.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r.label}),t.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:Ae(r.current)})]},r.label)}export{tr as MemoryDebugPanel};
|