@aiworker/web 1.23.0 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-B1Gizi3a.js → CodeMirrorCommentWidgets-teB3HmBT.js} +1 -1
- package/dist/assets/DiffView-DC9RX3MF.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-aig6zJjg.js → DirtyBranchSwitchDialog-DwPkzXsS.js} +1 -1
- package/dist/assets/FilesView-BFZkuu4O.js +13 -0
- package/dist/assets/{GitView-BXsS3jG6.js → GitView-B_x52MHY.js} +4 -4
- package/dist/assets/{JsonTreeView-D_hpXBnF.js → JsonTreeView-cmAzUTiw.js} +1 -1
- package/dist/assets/{LinearIssuesView-BoUiLQG1.js → LinearIssuesView-Dehh5afm.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-B_B_a9KS.js → MarkdownImageGallery-DgNOqqhE.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-xgyyLiBM.js → MarkdownRendererImpl-DusmMZ_p.js} +2 -2
- package/dist/assets/{OnboardingScreen-DIp84OWt.js → OnboardingScreen-B8fm1H4m.js} +1 -1
- package/dist/assets/{PatchDiff-8p6nLJaU.js → PatchDiff-BVr7gJU0.js} +1 -1
- package/dist/assets/{PierreDiffViewer-DjC8nTk9.js → PierreDiffViewer-DzLt-nel.js} +1 -1
- package/dist/assets/PlanView-BmQUYT_z.js +5 -0
- package/dist/assets/SettingsView-ChWmAcZT.js +28 -0
- package/dist/assets/{SettingsWindow-Cpb4hM6q.js → SettingsWindow-Dy3M6ZB9.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DfaKZXNU.js → ToolOutputDialog-cTl_eLIH.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-DtZLzrSK.js → ToolPartDiffPreview-C_3iYNJQ.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-C8i9HpTB.js → VirtualizedFileDiff-CAWthkoy.js} +4 -4
- package/dist/assets/WalkthroughView-C7AHOpCA.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-BBI7ZwrC.js → computeVirtualFileMetrics-BkiDSlTW.js} +2 -2
- package/dist/assets/de-DJsQr-p7.js +10 -0
- package/dist/assets/es-BuYMlA9g.js +16 -0
- package/dist/assets/fr-ePDay33C.js +14 -0
- package/dist/assets/index-BD8ILbxF.js +40 -0
- package/dist/assets/{index-jXSK5RrB.js → index-n6O3hklM.js} +1 -1
- package/dist/assets/index-zhgg-SDz.css +1 -0
- package/dist/assets/{isDiffPlainText-B_x_rVon.js → isDiffPlainText-GMdPz-71.js} +1 -1
- package/dist/assets/{isFilePlainText-DW_xMer1.js → isFilePlainText-BVuH1zH9.js} +1 -1
- package/dist/assets/ja-BzR9xOY_.js +16 -0
- package/dist/assets/{ko-idhXGF8j.js → ko-BEjHAm14.js} +3 -3
- package/dist/assets/main-BydQ1tr_.js +930 -0
- package/dist/assets/{main-CzdPuL0s.js → main-D3ZDQglc.js} +2 -2
- package/dist/assets/{markdownCore-Cn4Tyejo.js → markdownCore-Cb2MdZnV.js} +3 -3
- package/dist/assets/{miniChat-CCkqKOLp.js → miniChat-d01k801U.js} +2 -2
- package/dist/assets/{mobile-mvxTo055.js → mobile-D7VV-Ufz.js} +2 -2
- package/dist/assets/patchFileDiff-CdztVMz0.js +13 -0
- package/dist/assets/{pl-CGZWUqZJ.js → pl-rQmpxNIF.js} +3 -3
- package/dist/assets/pt-BR-CorbsSW-.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BGG9UIlh.js +2 -0
- package/dist/assets/renderMobileApp-BRP3J1iv.js +25 -0
- package/dist/assets/runtimeEndpointReset-BhT_-c52.js +41 -0
- package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
- package/dist/assets/{shikiHighlight-CRl0SUC9.js → shikiHighlight-BzXUjlby.js} +1 -1
- package/dist/assets/surface-COKb77Ua.js +1 -0
- package/dist/assets/tr-CoAMXPtI.js +7 -0
- package/dist/assets/uk-YlAX0rRU.js +16 -0
- package/dist/assets/{useAppFontEffects-CPKeOpUo.js → useAppFontEffects-Cwyhjfl5.js} +153 -155
- package/dist/assets/useGitComparison-BCZVefdE.js +1 -0
- package/dist/assets/{useInlineCommentController-BiWz4AVb.js → useInlineCommentController-DDkpBEU8.js} +2 -2
- package/dist/assets/{useRootScrollLock-BS4-kr7P.js → useRootScrollLock-CwjoWuC4.js} +1 -1
- package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Bg4AEeCr.js → vendor-codemirror-language-data-Cb1YnICj.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
- package/dist/assets/{web-components-z7hfnS8n.js → web-components-LV3vjTxy.js} +1 -1
- package/dist/assets/zh-CN-DDYg0Jl7.js +16 -0
- package/dist/assets/zh-TW-CQKaCayr.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +1 -1
- package/server/index.js +3 -13
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/agent-memory/runtime.test.js +22 -0
- package/server/lib/event-stream/DOCUMENTATION.md +3 -0
- package/server/lib/event-stream/global-hub.js +29 -4
- package/server/lib/event-stream/global-hub.test.js +22 -0
- package/server/lib/event-stream/global-ws-bridge.js +15 -18
- package/server/lib/event-stream/protocol.js +21 -7
- package/server/lib/event-stream/runtime.js +9 -6
- package/server/lib/event-stream/runtime.test.js +60 -0
- package/server/lib/git/DOCUMENTATION.md +10 -1
- package/server/lib/git/routes.js +21 -8
- package/server/lib/git/routes.test.js +78 -0
- package/server/lib/git/service.js +159 -4
- package/server/lib/git/service.test.js +74 -0
- package/server/lib/github/DOCUMENTATION.md +5 -0
- package/server/lib/github/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +7 -0
- package/server/lib/message-queue/runtime.js +13 -0
- package/server/lib/message-queue/runtime.test.js +31 -1
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/emitter-runtime.js +4 -3
- package/server/lib/opencode/DOCUMENTATION.md +18 -4
- package/server/lib/opencode/env-runtime.js +5 -1
- package/server/lib/opencode/env-runtime.test.js +72 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -1
- package/server/lib/opencode/lifecycle.js +4 -3
- package/server/lib/opencode/lifecycle.test.js +29 -0
- package/server/lib/opencode/managed-plugin-config.js +1 -1
- package/server/lib/opencode/proxy.js +33 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +11 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/settings-runtime.js +36 -9
- package/server/lib/opencode/settings-runtime.test.js +158 -2
- package/server/lib/project-context/DOCUMENTATION.md +13 -3
- package/server/lib/project-context/runtime.js +8 -2
- package/server/lib/project-context/runtime.test.js +54 -0
- package/server/lib/projects/DOCUMENTATION.md +2 -1
- package/server/lib/projects/project-config.js +38 -9
- package/server/lib/projects/project-config.test.js +97 -0
- package/server/lib/projects/project-id.js +26 -0
- package/server/lib/relay/DOCUMENTATION.md +20 -0
- package/server/lib/relay/host-client.js +7 -0
- package/server/lib/relay/host-client.test.js +14 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
- package/server/lib/scheduled-tasks/runtime.js +12 -2
- package/server/lib/scheduled-tasks/runtime.test.js +53 -0
- package/server/lib/session-assist/DOCUMENTATION.md +131 -66
- package/server/lib/session-assist/context.js +127 -0
- package/server/lib/session-assist/context.test.js +132 -0
- package/server/lib/session-assist/prompt.js +54 -0
- package/server/lib/session-assist/runtime.js +111 -257
- package/server/lib/session-assist/runtime.test.js +203 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
- package/server/lib/walkthrough/pr-source.test.js +21 -0
- package/server/lib/walkthrough/pull-request.js +7 -4
- package/server/lib/walkthrough/pull-request.test.js +16 -0
- package/server/lib/walkthrough/routes.js +19 -0
- package/server/lib/walkthrough/routes.test.js +26 -0
- package/server/lib/walkthrough/sources.js +13 -2
- package/server/opencode-worktree-readiness.test.js +130 -0
- package/dist/assets/DiffView-DXjVsEOw.js +0 -4
- package/dist/assets/FilesView-CJdG0-wk.js +0 -17
- package/dist/assets/PlanView-CJTmOF6I.js +0 -5
- package/dist/assets/SettingsView-DD-JqIJx.js +0 -28
- package/dist/assets/WalkthroughView-DeKMvZlL.js +0 -4
- package/dist/assets/de-DCrsQ5zS.js +0 -10
- package/dist/assets/es-Dwv4YfH6.js +0 -16
- package/dist/assets/fr-BCWg4Cnx.js +0 -14
- package/dist/assets/index-B68h5S5B.css +0 -1
- package/dist/assets/index-DVwMarHI.js +0 -39
- package/dist/assets/ja-Bruw3RYC.js +0 -16
- package/dist/assets/main-BkyaQhJX.js +0 -930
- package/dist/assets/patchFileDiff-Csk4iNUi.js +0 -13
- package/dist/assets/pt-BR-B8V7u7tA.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +0 -2
- package/dist/assets/renderMobileApp-B48CsP4r.js +0 -25
- package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +0 -17
- package/dist/assets/scheduledTasksApi-BW0Etzwz.js +0 -1
- package/dist/assets/surface-oMvhsog3.js +0 -1
- package/dist/assets/tr-BK_KiO2V.js +0 -7
- package/dist/assets/uk-CG74xV8N.js +0 -16
- package/dist/assets/useGitComparison-DH220WmO.js +0 -1
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/zh-CN-T4AXofZI.js +0 -16
- package/dist/assets/zh-TW-Dte40sxp.js +0 -16
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
- package/server/lib/mcp-reconnect/runtime.js +0 -122
- package/server/lib/mcp-reconnect/runtime.test.js +0 -140
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{b as Te,c as Qe,g as et,s as tt,d as Xe,e as Fe,f as it,h as nt,i as Ye,j as Ne,k as he,l as st,R as rt,I as ot,p as Ue,m as at,n as lt,o as ht,q as Pe,S as dt,r as ut,w as ft,t as Oe,u as ct,v as pt,x as Ae,y as gt,z as mt,A as Ct,B as St,C as vt,a as yt,F as
|
|
1
|
+
import{b as Te,c as Qe,g as et,s as tt,d as Xe,e as Fe,f as it,h as nt,i as Ye,j as Ne,k as he,l as st,R as rt,I as ot,p as Ue,m as at,n as lt,o as ht,q as Pe,S as dt,r as ut,w as ft,t as Oe,u as ct,v as pt,x as Ae,y as gt,z as mt,A as Ct,B as St,C as vt,a as yt,F as Lt}from"./web-components-LV3vjTxy.js";import{j as w,m as Se,k as Ht,n as Tt,d as At,i as ke,o as U,q as ce,s as kt,b as Rt,f as Be,t as Y,u as Je,w as Re}from"./computeVirtualFileMetrics-BkiDSlTW.js";import{h as xt,a as se,i as be,b as re,r as Dt,g as Et,c as ve,d as we,e as oe,f as Me,j as ae}from"./isDiffPlainText-GMdPz-71.js";import{hr as bt,hH as wt,hI as Ie,fL as _,hJ as Mt,hK as It,hL as Ve,hM as zt,hx as Ft,hy as Nt,hz as Ut,hA as Pt}from"./useAppFontEffects-Cwyhjfl5.js";import{c as Ot}from"./vendor-diff-C3JhlQdm.js";import{t as le}from"./vendor-hast-util-to-html-BKBhbTDb.js";function J(e,t,i,n=!1){const s=bt(Ot(e.name,t.name,e.contents,t.contents,e.header,t.header,i),{cacheKey:(()=>{if(e.cacheKey!=null&&t.cacheKey!=null)return`${e.cacheKey}:${t.cacheKey}`})(),oldFile:e,newFile:t,throwOnError:n});if(s==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");return t.lang!=null&&(s.lang=t.lang),s}var Bt=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,i){if(t==null||i==null)for(const n of e.children??[])n instanceof HTMLElement&&("deletions"in n.dataset?t=n:"additions"in n.dataset&&(i=n));if(i==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==i&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=i,i.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function pe(e){return w({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function ge(e){return w({tagName:"div",children:[w({tagName:"span",children:[Se("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function xe(e){return w({tagName:"div",children:[Ht({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function K({type:e,content:t,expandIndex:i,chunked:n=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(w({tagName:"div",children:[Se(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const u=[];i!=null&&(n?(r||(u.push(xe("up")),a++),o||(u.push(xe("down")),a++)):(u.push(xe(!r&&!o?"both":r?"down":"up")),a++)),u.push(w({tagName:"div",children:[w({tagName:"span",children:[Se(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),n&&i!=null&&u.push(w({tagName:"div",children:[Se("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(w({tagName:"div",children:u,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(w({tagName:"slot",properties:{name:s}})),w({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":i,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function Vt(e,t){return`hunk-separator-${e}-${t}`}function Gt(e){const t=e.at(-1);return t==null?0:Math.max(t.additionStart+t.additionCount,t.deletionStart+t.deletionCount)}function Wt(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function $t(e){return e!==""?e.split(wt):[]}function G(e,t){const i=J({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:i.hunks,splitLineCount:i.splitLineCount,unifiedLineCount:i.unifiedLineCount,additionLines:i.additionLines,deletionLines:i.deletionLines,type:i.type}}function _t(e,t){const i=e.deletionLines.join(""),n=i===`
|
|
2
2
|
`?`
|
|
3
3
|
`:`
|
|
4
|
-
`,s=
|
|
4
|
+
`,s=J({name:e.prevName??e.name,contents:i},{name:e.name,contents:n,lang:e.lang},t);return{hunks:s.hunks,splitLineCount:s.splitLineCount,unifiedLineCount:s.unifiedLineCount,additionLines:[""],deletionLines:s.deletionLines,type:s.type}}function jt(e,t,i){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return B(e,G(e,i));const n=Array.from(t);if(n.length===0)return B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of n){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Ie(o)===Ie(a))return B(e,G(e,i))}const s=qt(e,n);if(s.size===0)return B(e,G(e,i));for(const r of s)if(!Xt(e,r,i))return B(e,G(e,i));return Qt(e),xt(e)?B(e,G(e,i)):B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function B(e,t){return Object.assign(e,t),t}function qt(e,t){const i=new Set;for(const n of t){const s=Kt(e,n);if(s==null)return new Set;i.add(s)}return i}function Kt(e,t){for(const[i,n]of e.hunks.entries()){const s=n.additionLineIndex+n.additionCount;if(t>=n.additionLineIndex&&t<s)return i}}function Xt(e,t,i){const n=e.hunks[t];if(n==null)return!1;const s=e.deletionLines.slice(n.deletionLineIndex,n.deletionLineIndex+n.deletionCount),r=e.additionLines.slice(n.additionLineIndex,n.additionLineIndex+n.additionCount),o=J({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...i,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(Jt(n,a),Yt(e,t),!0)}function Yt(e,t){const i=e.hunks[t];if(i==null)return;if(t!==e.hunks.length-1){i.noEOFCRAdditions=!1,i.noEOFCRDeletions=!1;return}const n=e.additionLines.at(-1),s=e.deletionLines.at(-1);i.noEOFCRAdditions=n!=null&&n!==""&&!n.endsWith(`
|
|
5
5
|
`),i.noEOFCRDeletions=s!=null&&s!==""&&!s.endsWith(`
|
|
6
|
-
`)}function Zt(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Jt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Je(e)}function Jt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function Je(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Qt(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(s.additionStart-1-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,Je(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=s.additionStart+s.additionCount-1;if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-(s.additionLineIndex+s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}let ei=-1;var ti=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++ei}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;constructor(e={theme:_},t,i){this.options=e,this.onRenderUpdate=t,this.workerManager=i,i?.isWorkingPool()!==!0&&(this.highlighter=Te(e.theme??_)?Tt():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}getRenderDiff(){return this.renderCache?.diff??this.diff}clearRenderCache(){const e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Mt}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){if(this.renderCache==null)return;const{result:n,diff:s}=this.renderCache;if(n==null)return;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=n.code.additionLines,o=[];for(const[a,l]of e){const u=r[a]?.properties??{},f=l.map(g=>g[2]).join(""),h=a<s.additionLines.length,d=h?s.additionLines[a]??"":"",c=Ie(d);h&&(s.additionLines[a]=ni(d,f),c!==f&&o.push(a)),r[a]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??a+1,"data-line-index":u["data-line-index"]??a,"data-line-type":u["data-line-type"]??"context"},children:l.map(([g,m,C])=>g===0&&m===""?C===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:C}:{type:"element",tagName:"span",properties:{"data-char":g,style:`--diffs-token-${t}:${m};`},children:[{type:"text",value:C}]})}}!i&&o.length>0&&Object.assign(s,jt(s,o,this.options.parseDiffOptions)),n.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:i}=this.renderCache;if(i==null)return;t.additionLines=$t(e.getText());const n=t.additionLines.length,s=i.code.additionLines,r=s.length;n<r&&(s.length=n);for(let o=r;o<n;o++)s[o]??=je(o,e);t.isPartial||(n===0?(Object.assign(t,_t(t,this.options.parseDiffOptions)),s[0]=je(0,e)):Object.assign(t,G(t,this.options.parseDiffOptions))),this.renderCache.isDirty=!0}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Qe(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:u=100,hunkSeparators:f="line-info",lineDiffType:h="word-alt",maxLineDiffLength:d=1e3,overflow:c="scroll",stickyHeader:g=!1,theme:m=_,headerRenderMode:C="default",tokenizeMaxLineLength:y=1e3,tokenizeMaxLength:v=It,useTokenTransformer:p=!1,useCSSClasses:S=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:u,hunkSeparators:f,lineDiffType:h,maxLineDiffLength:d,overflow:c,stickyHeader:g,theme:this.workerManager?.getDiffRenderOptions().theme??m,headerRenderMode:C,tokenizeMaxLineLength:y,tokenizeMaxLength:v,useTokenTransformer:p,useCSSClasses:S}}async initializeHighlighter(){return this.highlighter=await At(et(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Ee(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!se(t,n.options)&&(n=void 0),this.renderCache??={diff:e,highlighted:!i&&!be(e),options:t,result:i?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??ke(e.name),this.initializeHighlighter())}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:tt(this.options),tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!re(e,i.diff)||!se(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=Ve){if(e==null)return;const{expandUnchanged:i=!1,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getMatchingWorkerResultCache(e,s);o!=null&&!this.hasHighlightedRenderCache(e,s)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||be(e)||Ee(e,this.getTokenizeMaxLength()),u=!re(e,this.renderCache.diff),f=!Xe(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(l||this.renderCache.result==null||!this.renderCache.highlighted&&(u||f))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||u||f||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Wt(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??ke(e.name);const h=this.highlighter!=null&&Te(s.theme),d=this.highlighter!=null&&Fe(this.computedLang),c=!l&&d;if(this.highlighter!=null&&h&&(r||l||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:g,options:m}=this.renderDiffWithHighlighter(e,this.highlighter,l||!d);this.renderCache={diff:e,options:m,highlighted:c,result:g,renderRange:void 0}}(!h||!l&&!d)&&this.asyncHighlight(e).then(({result:g,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,g,m,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=Ve){const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return it({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Ee(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??ke(e.name);const i=this.highlighter!=null&&Te(this.options.theme??_),n=t||this.highlighter!=null&&Fe(this.computedLang);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults();return{result:Dt(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s}),options:n}}onHighlightSuccess(e,t,i,n=!0){if(this.renderCache==null)return;const s=!this.renderCache.highlighted||!se(this.renderCache.options,i)||!re(this.renderCache.diff,e);this.renderCache={diff:e,options:i,highlighted:n,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!se(t,i.options)))return i}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&re(e,i.diff)&&se(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:u,hunkSeparators:f}=this.getOptionsWithDefaults(),h=this.renderCache?.isDirty??!1;this.diff=e;const d=r==="unified";let c=[],g=[],m=[];const C=[],{additionLines:y,deletionLines:v}=i,p={rowCount:0,hunkSeparators:f,additionsContentAST:c,deletionsContentAST:g,unifiedContentAST:m,unifiedGutterAST:ce(),deletionsGutterAST:ce(),additionsGutterAST:ce(),expansionLineCount:l,hunkData:C,incrementRowCount(R=1){p.rowCount+=R},pushToGutter(R,D){switch(R){case"unified":p.unifiedGutterAST.children.push(D);break;case"deletions":p.deletionsGutterAST.children.push(D);break;case"additions":p.additionsGutterAST.children.push(D);break}}},S=Et({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),H={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(p.pushToGutter("additions",U(void 0,"buffer",this.size)),c?.push(pe(this.size))):(p.pushToGutter("deletions",U(void 0,"buffer",this.size)),g?.push(pe(this.size))),this.size=0,this.side=void 0}}},T=(R,D,P,V,L)=>{p.pushToGutter(R,kt(D,P,V,L))};function F(R){H.flush(),r==="unified"?De("unified",R,p):(De("deletions",R,p),De("additions",R,p))}this.pushFileLevelAnnotations(e,r,t,p),ve({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:u,callback:({hunkIndex:R,hunk:D,collapsedBefore:P,collapsedAfter:V,additionLine:L,deletionLine:A,type:x})=>{const I=A!=null?A.splitLineIndex:L.splitLineIndex,W=L!=null?L.unifiedLineIndex:A.unifiedLineIndex;r==="split"&&x!=="change"&&H.flush(),P>0&&F({hunkIndex:R,collapsedLines:P,rangeSize:Math.max(D?.collapsedBefore??0,0),hunkSpecs:D?.hunkSpecs,isFirstHunk:R===0,isLastHunk:!1,isExpandable:!e.isPartial});const Q=r==="unified"?W:I,ee={type:x,hunkIndex:R,lineIndex:Q,unifiedLineIndex:W,splitLineIndex:I,deletionLine:A,additionLine:L};if(r==="unified"){const k=this.getUnifiedInjectedRowsForLine?.(ee);k?.before!=null&&$e(k.before,p);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;if(E==null&&z==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const $=x==="change"?L!=null?"change-addition":"change-deletion":x,O=this.getUnifiedLineDecoration({type:x,lineType:$,additionLineIndex:L?.lineIndex,deletionLineIndex:A?.lineIndex});T("unified",O.gutterLineType,L!=null?L.lineNumber:A.lineNumber,`${W},${I}`,O.gutterProperties),z!=null?z=Ce(z,O.contentProperties,h&&L!=null?{"data-line":L.lineNumber,"data-line-index":`${W},${I}`}:void 0):E!=null&&(E=Ce(E,O.contentProperties,h&&A!=null?{"data-line":A.lineNumber,"data-line-index":`${W},${I}`}:void 0)),me({diffStyle:"unified",type:x,deletionLine:E,additionLine:z,unifiedSpan:this.getAnnotations("unified",A?.lineNumber,L?.lineNumber,R,Q),createAnnotationElement:N=>this.createAnnotationElement(N),context:p}),k?.after!=null&&$e(k.after,p)}else{const k=this.getSplitInjectedRowsForLine?.(ee);k?.before!=null&&_e(k.before,p,H);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;const $=this.getSplitLineDecoration({side:"deletions",type:x,lineIndex:A?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:x,lineIndex:L?.lineIndex});if(E==null&&z==null){const M="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(M,{file:e.name}),new Error(M)}const N=(()=>{if(x==="change"){if(z==null)return"additions";if(E==null)return"deletions"}})();if(N!=null){if(H.side!=null&&H.side!==N)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");H.side=N,H.increment()}const ne=this.getAnnotations("split",A?.lineNumber,L?.lineNumber,R,Q);if(ne!=null&&H.size>0&&H.flush(),A!=null){const M=Ce(E,$.contentProperties,h?{"data-line":A.lineNumber,"data-line-index":`${A.unifiedLineIndex},${I}`}:void 0);T("deletions",$.gutterLineType,A.lineNumber,`${A.unifiedLineIndex},${I}`,$.gutterProperties),M!=null&&(E=M)}if(L!=null){const M=Ce(z,O.contentProperties,h?{"data-line":L.lineNumber,"data-line-index":`${L.unifiedLineIndex},${I}`}:void 0);T("additions",O.gutterLineType,L.lineNumber,`${L.unifiedLineIndex},${I}`,O.gutterProperties),M!=null&&(z=M)}me({diffStyle:"split",type:x,additionLine:z,deletionLine:E,...ne,createAnnotationElement:M=>this.createAnnotationElement(M),context:p}),k?.after!=null&&_e(k.after,p,H)}const fe=r==="split"&&D!=null&&I===D.splitLineStart+D.splitLineCount-1,ye=fe?D.noEOFCRDeletions:!1,He=fe?D.noEOFCRAdditions:!1,te=(A?.noEOFCR??!1)||ye,ie=(L?.noEOFCR??!1)||He;if(ie||te){if(r==="split"&&H.flush(),te){const k=x==="context"||x==="context-expanded"?x:"change-deletion";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.deletionsContentAST.push(ge(k)),p.pushToGutter("deletions",U(k,"metadata",1)),ie||(p.pushToGutter("additions",U(void 0,"buffer",1)),p.additionsContentAST.push(pe(1))))}if(ie){const k=x==="context"||x==="context-expanded"?x:"change-addition";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.additionsContentAST.push(ge(k)),p.pushToGutter("additions",U(k,"metadata",1)),te||(p.pushToGutter("deletions",U(void 0,"buffer",1)),p.deletionsContentAST.push(pe(1))))}p.incrementRowCount(1)}V>0&&f!=="simple"&&F({hunkIndex:x==="context-expanded"?R:R+1,collapsedLines:V,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),p.incrementRowCount(1)}}),r==="split"&&H.flush();const de=Math.max(Gt(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),j=t.bufferBefore>0||t.bufferAfter>0,ue=!d&&e.type!=="deleted",q=!d&&e.type!=="new",b=p.rowCount>0||j;c=ue&&b?c:void 0,g=q&&b?g:void 0,m=d&&b?m:void 0;const J=this.createPreElement(g!=null&&c!=null,de);return{unifiedGutterAST:d&&b?p.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:q&&b?p.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:ue&&b?p.additionsGutterAST.children:void 0,additionsContentAST:c,hunkData:C,preNode:J,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:de,rowCount:p.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=ce(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,nt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(w({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(w({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(w({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(w({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Ye(i))return;const s=e.type!=="new"?Ge(Ne(this.deletionAnnotations)):[],r=e.type!=="deleted"?Ge(Ne(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){me({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}me({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(he(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(he(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return st({fileOrDiff:e,mode:t,stickyHeader:i})}};function Ge(e){return e?.map(t=>he(t))??[]}const ii=new Intl.PluralRules("en-US");function We(e){return`${e} unmodified line${ii.select(e)==="one"?"":"s"}`}function $e(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function _e(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function me({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let u=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const f=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",U(f,"annotation",1)),u=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const f=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",U(f,"annotation",1)),u=!0}if(o!=null){const f=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",U(f,"annotation",1)),u=!0}}u&&l.incrementRowCount(1)}function De(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(i<=0)return;const u=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),u.push(K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,K({type:"simple",isFirstHunk:r,isLastHunk:!1})),u.push(K({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const f=Vt(e,t),h=n>l.expansionLineCount,d=a?t:void 0;l.pushToGutter(e,K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),u.push(K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:f,hunkIndex:t,lines:i,type:e,expandable:a?{up:!r,down:!o,chunked:h}:void 0})}function Ce(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function je(e,t){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${e},${e}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t.getLineText(e)}]}]}}function ni(e,t){return e.endsWith(`\r
|
|
6
|
+
`)}function Jt(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Zt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Ze(e)}function Zt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function Ze(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Qt(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(s.additionStart-1-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,Ze(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=s.additionStart+s.additionCount-1;if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-(s.additionLineIndex+s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}let ei=-1;var ti=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++ei}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;constructor(e={theme:_},t,i){this.options=e,this.onRenderUpdate=t,this.workerManager=i,i?.isWorkingPool()!==!0&&(this.highlighter=Te(e.theme??_)?Tt():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}getRenderDiff(){return this.renderCache?.diff??this.diff}clearRenderCache(){const e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Mt}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){if(this.renderCache==null)return;const{result:n,diff:s}=this.renderCache;if(n==null)return;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=n.code.additionLines,o=[];for(const[a,l]of e){const u=r[a]?.properties??{},f=l.map(g=>g[2]).join(""),h=a<s.additionLines.length,d=h?s.additionLines[a]??"":"",c=Ie(d);h&&(s.additionLines[a]=ni(d,f),c!==f&&o.push(a)),r[a]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??a+1,"data-line-index":u["data-line-index"]??a,"data-line-type":u["data-line-type"]??"context"},children:l.map(([g,m,C])=>g===0&&m===""?C===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:C}:{type:"element",tagName:"span",properties:{"data-char":g,style:`--diffs-token-${t}:${m};`},children:[{type:"text",value:C}]})}}!i&&o.length>0&&Object.assign(s,jt(s,o,this.options.parseDiffOptions)),n.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:i}=this.renderCache;if(i==null)return;t.additionLines=$t(e.getText());const n=t.additionLines.length,s=i.code.additionLines,r=s.length;n<r&&(s.length=n);for(let o=r;o<n;o++)s[o]??=je(o,e);t.isPartial||(n===0?(Object.assign(t,_t(t,this.options.parseDiffOptions)),s[0]=je(0,e)):Object.assign(t,G(t,this.options.parseDiffOptions))),this.renderCache.isDirty=!0}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Qe(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:u=100,hunkSeparators:f="line-info",lineDiffType:h="word-alt",maxLineDiffLength:d=1e3,overflow:c="scroll",stickyHeader:g=!1,theme:m=_,headerRenderMode:C="default",tokenizeMaxLineLength:y=1e3,tokenizeMaxLength:v=It,useTokenTransformer:p=!1,useCSSClasses:S=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:u,hunkSeparators:f,lineDiffType:h,maxLineDiffLength:d,overflow:c,stickyHeader:g,theme:this.workerManager?.getDiffRenderOptions().theme??m,headerRenderMode:C,tokenizeMaxLineLength:y,tokenizeMaxLength:v,useTokenTransformer:p,useCSSClasses:S}}async initializeHighlighter(){return this.highlighter=await At(et(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Ee(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!se(t,n.options)&&(n=void 0),this.renderCache??={diff:e,highlighted:!i&&!be(e),options:t,result:i?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??ke(e.name),this.initializeHighlighter())}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:tt(this.options),tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!re(e,i.diff)||!se(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=Ve){if(e==null)return;const{expandUnchanged:i=!1,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getMatchingWorkerResultCache(e,s);o!=null&&!this.hasHighlightedRenderCache(e,s)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||be(e)||Ee(e,this.getTokenizeMaxLength()),u=!re(e,this.renderCache.diff),f=!Xe(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(l||this.renderCache.result==null||!this.renderCache.highlighted&&(u||f))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||u||f||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Wt(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??ke(e.name);const h=this.highlighter!=null&&Te(s.theme),d=this.highlighter!=null&&Fe(this.computedLang),c=!l&&d;if(this.highlighter!=null&&h&&(r||l||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:g,options:m}=this.renderDiffWithHighlighter(e,this.highlighter,l||!d);this.renderCache={diff:e,options:m,highlighted:c,result:g,renderRange:void 0}}(!h||!l&&!d)&&this.asyncHighlight(e).then(({result:g,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,g,m,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=Ve){const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return it({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Ee(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??ke(e.name);const i=this.highlighter!=null&&Te(this.options.theme??_),n=t||this.highlighter!=null&&Fe(this.computedLang);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults();return{result:Dt(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s}),options:n}}onHighlightSuccess(e,t,i,n=!0){if(this.renderCache==null)return;const s=!this.renderCache.highlighted||!se(this.renderCache.options,i)||!re(this.renderCache.diff,e);this.renderCache={diff:e,options:i,highlighted:n,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!se(t,i.options)))return i}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&re(e,i.diff)&&se(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:u,hunkSeparators:f}=this.getOptionsWithDefaults(),h=this.renderCache?.isDirty??!1;this.diff=e;const d=r==="unified";let c=[],g=[],m=[];const C=[],{additionLines:y,deletionLines:v}=i,p={rowCount:0,hunkSeparators:f,additionsContentAST:c,deletionsContentAST:g,unifiedContentAST:m,unifiedGutterAST:ce(),deletionsGutterAST:ce(),additionsGutterAST:ce(),expansionLineCount:l,hunkData:C,incrementRowCount(R=1){p.rowCount+=R},pushToGutter(R,D){switch(R){case"unified":p.unifiedGutterAST.children.push(D);break;case"deletions":p.deletionsGutterAST.children.push(D);break;case"additions":p.additionsGutterAST.children.push(D);break}}},S=Et({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),L={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(p.pushToGutter("additions",U(void 0,"buffer",this.size)),c?.push(pe(this.size))):(p.pushToGutter("deletions",U(void 0,"buffer",this.size)),g?.push(pe(this.size))),this.size=0,this.side=void 0}}},T=(R,D,P,V,H)=>{p.pushToGutter(R,kt(D,P,V,H))};function F(R){L.flush(),r==="unified"?De("unified",R,p):(De("deletions",R,p),De("additions",R,p))}this.pushFileLevelAnnotations(e,r,t,p),ve({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:u,callback:({hunkIndex:R,hunk:D,collapsedBefore:P,collapsedAfter:V,additionLine:H,deletionLine:A,type:x})=>{const I=A!=null?A.splitLineIndex:H.splitLineIndex,W=H!=null?H.unifiedLineIndex:A.unifiedLineIndex;r==="split"&&x!=="change"&&L.flush(),P>0&&F({hunkIndex:R,collapsedLines:P,rangeSize:Math.max(D?.collapsedBefore??0,0),hunkSpecs:D?.hunkSpecs,isFirstHunk:R===0,isLastHunk:!1,isExpandable:!e.isPartial});const Q=r==="unified"?W:I,ee={type:x,hunkIndex:R,lineIndex:Q,unifiedLineIndex:W,splitLineIndex:I,deletionLine:A,additionLine:H};if(r==="unified"){const k=this.getUnifiedInjectedRowsForLine?.(ee);k?.before!=null&&$e(k.before,p);let E=A!=null?v[A.lineIndex]:void 0,z=H!=null?y[H.lineIndex]:void 0;if(E==null&&z==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const $=x==="change"?H!=null?"change-addition":"change-deletion":x,O=this.getUnifiedLineDecoration({type:x,lineType:$,additionLineIndex:H?.lineIndex,deletionLineIndex:A?.lineIndex});T("unified",O.gutterLineType,H!=null?H.lineNumber:A.lineNumber,`${W},${I}`,O.gutterProperties),z!=null?z=Ce(z,O.contentProperties,h&&H!=null?{"data-line":H.lineNumber,"data-line-index":`${W},${I}`}:void 0):E!=null&&(E=Ce(E,O.contentProperties,h&&A!=null?{"data-line":A.lineNumber,"data-line-index":`${W},${I}`}:void 0)),me({diffStyle:"unified",type:x,deletionLine:E,additionLine:z,unifiedSpan:this.getAnnotations("unified",A?.lineNumber,H?.lineNumber,R,Q),createAnnotationElement:N=>this.createAnnotationElement(N),context:p}),k?.after!=null&&$e(k.after,p)}else{const k=this.getSplitInjectedRowsForLine?.(ee);k?.before!=null&&_e(k.before,p,L);let E=A!=null?v[A.lineIndex]:void 0,z=H!=null?y[H.lineIndex]:void 0;const $=this.getSplitLineDecoration({side:"deletions",type:x,lineIndex:A?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:x,lineIndex:H?.lineIndex});if(E==null&&z==null){const M="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(M,{file:e.name}),new Error(M)}const N=(()=>{if(x==="change"){if(z==null)return"additions";if(E==null)return"deletions"}})();if(N!=null){if(L.side!=null&&L.side!==N)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");L.side=N,L.increment()}const ne=this.getAnnotations("split",A?.lineNumber,H?.lineNumber,R,Q);if(ne!=null&&L.size>0&&L.flush(),A!=null){const M=Ce(E,$.contentProperties,h?{"data-line":A.lineNumber,"data-line-index":`${A.unifiedLineIndex},${I}`}:void 0);T("deletions",$.gutterLineType,A.lineNumber,`${A.unifiedLineIndex},${I}`,$.gutterProperties),M!=null&&(E=M)}if(H!=null){const M=Ce(z,O.contentProperties,h?{"data-line":H.lineNumber,"data-line-index":`${H.unifiedLineIndex},${I}`}:void 0);T("additions",O.gutterLineType,H.lineNumber,`${H.unifiedLineIndex},${I}`,O.gutterProperties),M!=null&&(z=M)}me({diffStyle:"split",type:x,additionLine:z,deletionLine:E,...ne,createAnnotationElement:M=>this.createAnnotationElement(M),context:p}),k?.after!=null&&_e(k.after,p,L)}const fe=r==="split"&&D!=null&&I===D.splitLineStart+D.splitLineCount-1,ye=fe?D.noEOFCRDeletions:!1,Le=fe?D.noEOFCRAdditions:!1,te=(A?.noEOFCR??!1)||ye,ie=(H?.noEOFCR??!1)||Le;if(ie||te){if(r==="split"&&L.flush(),te){const k=x==="context"||x==="context-expanded"?x:"change-deletion";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.deletionsContentAST.push(ge(k)),p.pushToGutter("deletions",U(k,"metadata",1)),ie||(p.pushToGutter("additions",U(void 0,"buffer",1)),p.additionsContentAST.push(pe(1))))}if(ie){const k=x==="context"||x==="context-expanded"?x:"change-addition";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.additionsContentAST.push(ge(k)),p.pushToGutter("additions",U(k,"metadata",1)),te||(p.pushToGutter("deletions",U(void 0,"buffer",1)),p.deletionsContentAST.push(pe(1))))}p.incrementRowCount(1)}V>0&&f!=="simple"&&F({hunkIndex:x==="context-expanded"?R:R+1,collapsedLines:V,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),p.incrementRowCount(1)}}),r==="split"&&L.flush();const de=Math.max(Gt(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),j=t.bufferBefore>0||t.bufferAfter>0,ue=!d&&e.type!=="deleted",q=!d&&e.type!=="new",b=p.rowCount>0||j;c=ue&&b?c:void 0,g=q&&b?g:void 0,m=d&&b?m:void 0;const Z=this.createPreElement(g!=null&&c!=null,de);return{unifiedGutterAST:d&&b?p.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:q&&b?p.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:ue&&b?p.additionsGutterAST.children:void 0,additionsContentAST:c,hunkData:C,preNode:Z,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:de,rowCount:p.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=ce(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,nt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(w({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(w({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(w({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(w({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Ye(i))return;const s=e.type!=="new"?Ge(Ne(this.deletionAnnotations)):[],r=e.type!=="deleted"?Ge(Ne(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){me({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}me({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(he(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(he(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return st({fileOrDiff:e,mode:t,stickyHeader:i})}};function Ge(e){return e?.map(t=>he(t))??[]}const ii=new Intl.PluralRules("en-US");function We(e){return`${e} unmodified line${ii.select(e)==="one"?"":"s"}`}function $e(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function _e(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function me({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let u=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const f=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",U(f,"annotation",1)),u=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const f=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",U(f,"annotation",1)),u=!0}if(o!=null){const f=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",U(f,"annotation",1)),u=!0}}u&&l.incrementRowCount(1)}function De(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(i<=0)return;const u=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),u.push(K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,K({type:"simple",isFirstHunk:r,isLastHunk:!1})),u.push(K({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const f=Vt(e,t),h=n>l.expansionLineCount,d=a?t:void 0;l.pushToGutter(e,K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),u.push(K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:f,hunkIndex:t,lines:i,type:e,expandable:a?{up:!r,down:!o,chunked:h}:void 0})}function Ce(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function je(e,t){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${e},${e}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t.getLineText(e)}]}]}}function ni(e,t){return e.endsWith(`\r
|
|
7
7
|
`)?t+`\r
|
|
8
8
|
`:e.endsWith("\r")?t+"\r":e.endsWith(`
|
|
9
9
|
`)?t+`
|
|
10
|
-
`:t}function Ee(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function si(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ri(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function oi(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}let ai=-1;var li=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++ai}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;fastRefreshTimeout;constructor(e={theme:_},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new rt,this.scrollSyncManager=new Bt,this.interactionManager=new ot("diff",Ue(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return oi(e)}createHunksRenderer(e){return new ti(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const i=this.hunksRenderer.getRenderDiff()??this.fileDiff;if(i==null)return;const n=i.hunks.at(-1);let s,r;e:for(const o of i.hunks){let a=t==="deletions"?o.deletionStart:o.additionStart;const l=t==="deletions"?o.deletionCount:o.additionCount;let u=o.splitLineStart,f=o.unifiedLineStart;if(e<a){const h=a-e;s=Math.max(f-h,0),r=Math.max(u-h,0);break e}if(e>=a+l){if(o===n){const h=e-(a+l);s=f+o.unifiedLineCount+h,r=u+o.splitLineCount+h;break e}continue}for(const h of o.hunkContent)if(h.type==="context")if(e<a+h.lines){const d=e-a;r=u+d,s=f+d;break e}else a+=h.lines,u+=h.lines,f+=h.lines;else{const d=t==="deletions"?h.deletions:h.additions;if(e<a+d){const c=e-a;s=f+(t==="additions"?h.deletions:0)+c,r=u+c;break e}else a+=d,u+=Math.max(h.deletions,h.additions),f+=h.deletions+h.additions}break e}if(!(s==null||r==null))return[s,r]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Ue(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;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&&!Rt(this.appliedThemeCSS.theme,this.options.theme??_)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.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.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0,this.fastRefreshTimeout!=null&&(clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=void 0)}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:i,preventEmit:n=!1,lineAnnotations:s,oldFile:r,newFile:o,fileDiff:a}=e;this.hydrateElements(t,i),ui(this.pre,hi({fileDiff:a,oldFile:r,newFile:o}),this.options.collapsed)||fi(this.headerElement,di({fileDiff:a,oldFile:r,newFile:o}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:a,oldFile:r,newFile:o,lineAnnotations:s}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),at(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!=null&&i!=null?Z(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.rerender()};render({oldFile:e,newFile:t,fileDiff:i,deferManagers:n=!1,forceRender:s=!1,preventEmit:r=!1,lineAnnotations:o,fileContainer:a,containerWrapper:l,renderRange:u}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:f=!1,themeType:h="system"}=this.options,d=f?void 0:u,c=this.hasThemeChanged(),g=e!=null&&t!=null&&(!Be(e,this.deletionFile)||!Be(t,this.additionFile));let m=i!=null&&i!==this.fileDiff;const C=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1;if(!f&&Xe(d,this.renderRange)&&!s&&!C&&!c&&(i!=null&&i===this.fileDiff||i==null&&!g))return this.applyCachedThemeState(h);const{renderRange:y}=this;if(this.renderRange=d,this.deletionFile=e,this.additionFile=t,i!=null?this.fileDiff=i:e!=null&&t!=null&&g&&(m=!0,this.fileDiff=Z(e,t,this.options.parseDiffOptions)),m&&(this.cachedHeaderHTML=void 0),o!=null&&this.setLineAnnotations(o),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:v=!1,disableFileHeader:p=!1}=this.options;if(p&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,l),this.applyCachedThemeState(h),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const S=this.hunksRenderer.renderDiff(this.fileDiff,zt);S!=null&&this.applyThemeState(a,S.themeStyles,h,S.baseThemeType),S?.headerElement!=null&&this.applyHeaderToDOM(S.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}try{const S=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(s,C,g||m||c)&&this.applyPartialRender({previousRenderRange:y,renderRange:d}))){const H=this.hunksRenderer.renderDiff(this.fileDiff,d);if(H==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,H.themeStyles,h,H.baseThemeType),H.headerElement!=null&&this.applyHeaderToDOM(H.headerElement,a),H.additionsContentAST!=null||H.deletionsContentAST!=null||H.unifiedContentAST!=null?this.applyHunksToDOM(S,H):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(H.hunkData)}this.applyBuffers(S,d),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,n||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,i=this.fileDiff;e!=null&&t!=null&&i!=null&&!i.isPartial&&this.hunksRenderer.initializeHighlighter().then(n=>{e.__syncRenderView(n,t,i,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);const i=this.hunksRenderer.getRenderDiff();i!=null&&(this.fileDiff=i),this.rerender(),this.interactionManager.setSelectionDirty(),t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}rerenderFromDocument(e){this.hunksRenderer.applyDocumentChange(e);const t=this.hunksRenderer.getRenderDiff();t!=null&&(this.fileDiff=t),this.hunksRenderer.clearRenderCache(),this.rerender()}updateRenderCache(e,t,i,n){this.hunksRenderer.updateRenderCache(e,t,n),i===!0&&(this.options.diffStyle==="split"?(this.fastRefreshTimeout!=null&&clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=setTimeout(()=>{this.fastRefreshTimeout=void 0,this.fastRefreshDiffView()},100)):this.refreshDiffView())}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{fileDiff:e,workerManager:t}=this;if(e==null||t==null||be(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!ri(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:i}of this.annotationCache.values())i.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[i,n]of this.lineAnnotations.entries()){const s=`${i}-${he(n)}`;let r=this.annotationCache.get(s);if(r==null||!si(n,r.annotation)){r?.element.remove();const o=t(n);if(o==null)continue;r={element:lt(he(n)),annotation:n},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[i,{element:n}]of e.entries())this.annotationCache.delete(i),n.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 i=ht();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return s&&this.emitPostRender(!0),this.fileContainer=n,i!=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 i of t.children)i instanceof SVGElement?this.spriteSVG??=i:Pe(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):Pe(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=dt;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{fileDiff:i}=this,n=this.cachedHeaderHTML??le(e);if(this.cachedHeaderHTML=n,n!==this.lastRenderedHeaderHTML){const h=document.createElement("div");h.innerHTML=n;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=n}if(this.isContainerManaged||i==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const h=s(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ft,h),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const l=r?.(i)??void 0,u=o?.(i)??void 0,f=a?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Nt,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ut,u),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Pt,f),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,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),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}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??=ut(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ft(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.options.theme??_,a=typeof o=="string"?o:{...o},l=Oe(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=ct({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ct(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=pt(this.themeCSSStyle.textContent??"",Oe(e)))}applyHunksToDOM(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),u=this.hunksRenderer.renderCodeAST("additions",t);a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Ae({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a),o.push(this.codeUnified)):l!=null||u!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ae({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),u!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ae({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(u),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){const{pre:i,codeUnified:n,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(i==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,n,r,s);if(a==null)return!1;const l=e.startingLine,u=t.startingLine,f=l+e.totalLines,h=u+t.totalLines,d=Math.max(l,u),c=Math.min(f,h);if(c<=d)return!1;const g=Math.max(0,d-l),m=Math.max(0,f-c),C=this.trimColumns({columns:a,trimStart:g,trimEnd:m,previousStart:l,overlapStart:d,overlapEnd:c,diffStyle:o});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(T,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:T,totalLines:F,bufferBefore:0,bufferAfter:0})},p=v(u,Math.max(d-u,0));if(p==null&&u<d)return!1;const S=v(c,Math.max(h-c,0));if(S==null&&h>c)return!1;const H=(T,F)=>{if(T!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,T,F);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,T,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=T.rowCount}};return this.cleanupErrorWrapper(),H(p,"afterbegin"),H(S,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(o,a,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}fastRefreshDiffView(){if(this.options.diffStyle!=="split")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])if(u!=null&&l.childElementCount===u.length)for(let f=0;f<u.length;f++){const h=l.children[f],d=u[f].properties["data-line-type"];d!=null&&h.dataset.lineType!==d&&(h.dataset.lineType=d)}};i("deletions",t[0]),i("additions",t[1])}refreshDiffView(){const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns(this.options.diffStyle??"split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null)return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])u!=null&&(l.innerHTML=le(u))};Array.isArray(t)?(i("deletions",t[0]),i("additions",t[1])):i("unified",t),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=X(t[0]),s=X(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),u=Array.from(e.gutter.children);if(l.length!==u.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const f=u[r],h=l[r];if(r++,!(f instanceof HTMLElement)||!(h instanceof HTMLElement))throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset||f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset)){f.remove(),h.remove(),s++;continue}if("lineIndex"in f.dataset&&"lineIndex"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in f.dataset&&"separator"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="buffer"&&"contentBuffer"in h.dataset){const d=this.getBufferSize(h.dataset);if(d==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const c=Math.min(t,d),g=d-c;g>0?(this.updateBufferSize(f,g),this.updateBufferSize(h,g),s+=c):(f.remove(),h.remove(),s+=d),t-=c,t===0&&g===0&&(o=!0)}else if(a){const c=n,g=n+d-1;if(i<=c)f.remove(),h.remove(),s+=d;else if(i<=g){const m=g-i+1,C=d-m;this.updateBufferSize(f,C),this.updateBufferSize(h,C),s+=m}}n+=d;continue}throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const u=o>0,f=r>0;if(!u&&!f)return 0;const h=u?a:0,d=f?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,h,d);if(t==="split"&&Array.isArray(e)){const c=this.trimColumnRows(e[0],h,d),g=this.trimColumnRows(e[1],h,d);if(e[0]!=null&&e[1]!=null&&c!==g)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?c:g}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,i,n){function s(r){if(r==null)return;const o=r.children[0],a=r.children[1];if(!(!(o instanceof HTMLElement)||!(a instanceof HTMLElement)||o.dataset.gutter==null||a.dataset.content==null))return{gutter:o,content:a}}if(e==="unified")return s(t);{const r=s(i),o=s(n);return r!=null||o!=null?[r,o]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:u="split"}=this.options,f={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:u==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};gt(f,this.appliedPreAttributes)||(mt(e,f),this.appliedPreAttributes=f)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);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 hi({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function di({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function ui(e,t,i=!1){return!i&&e==null&&t}function fi(e,t,i=!1){return e==null&&t&&!i}function X(e){if(!(e==null||e.type!=="element"))return e.children??[]}function ci({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o}){let a=Y(t,i),l=a;const u=s?!0:r,f=e.hunks.length-1;for(let h=0;h<e.hunks.length;h++){const d=e.hunks[h];if(d==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const c=we({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:u,hunkIndex:h,collapsedContextThreshold:o}),g=(c.fromStart+c.fromEnd)*t.lineHeight;if(a+=g,l+=g,c.collapsedLines>0){const y=oe({type:n,metrics:t,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0;a+=y,l+=y}a+=d.splitLineCount*t.lineHeight,l+=d.unifiedLineCount*t.lineHeight;const m=pi(d);a+=m.split*t.lineHeight,l+=m.unified*t.lineHeight;const C=h===f?Me({fileDiff:e,hunkIndex:h,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(a+=y,l+=y,C.collapsedLines>0){const v=ae({type:n,metrics:t})?.totalHeight??0;a+=v,l+=v}}}if(e.hunks.length>0){const h=Ze(t);a+=h,l+=h}return{splitHeight:a,unifiedHeight:l}}function pi(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return gi(e,t)}function gi(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const ze=5e3;let mi=-1;var Mi=class extends li{__id=`little-virtualized-file-diff:${++mi}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Re(i)}setMetrics(e,t=!1){const i=Re(e);!t&&St(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!vt(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber!==0?!1:e.type==="new"?t.side==="additions":e.type==="deleted"?t.side==="deletions":!0)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!yt(t,e),n=i&&Li(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Ti(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),t&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;const{overflow:t="scroll"}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;const i=this.getDiffStyle(),n=i==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Ye(this.renderRange)){const r=Ci(n)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of n){if(r==null)continue;const o=r.children[1];if(o instanceof HTMLElement)for(const a of o.children){if(!(a instanceof HTMLElement))continue;const l=a.dataset.lineIndex;if(l==null)continue;const u=ki(l,i);let f=a.getBoundingClientRect().height,h=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(h=!0),f+=a.nextElementSibling.getBoundingClientRect().height);const d=this.getEstimatedLineHeight(h),c=this.cache.heightDeltas.get(u)??0,g=f-d;g!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=g-c,g===0?this.cache.heightDeltas.delete(u):this.cache.heightDeltas.set(u,g))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());prepareCodeViewItem(e,t,i,n){const s=!re(this.fileDiff,e),r=this.syncLineAnnotations(n);let o=i?.resetDiffLayoutCache===!0||s||r,a=s||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights;i?.metrics!=null&&(this.metrics=Re(i.metrics),o=!0,a=!0);const{collapsed:l=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),o&&this.resetLayoutCache({includeEstimatedHeights:a}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t="additions"){if(this.fileDiff==null||e<1)return;const i=this.getLineIndex(e,t);if(i==null)return;const{disableFileHeader:n=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),u=a==="split"?i[1]:i[0];this.approximateLayoutCheckpoints();const f=Y(this.metrics,n),h=this.getLayoutCheckpointBeforeLineIndex(u);let d=h?.top??f+this.cache.fileAnnotationHeight;if(r)return{top:f,height:0};let c;return ve({diff:this.fileDiff,diffStyle:a,startingLine:h?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:g,hunk:m,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:p})=>{const S=a==="split"?p?.splitLineIndex??v?.splitLineIndex:p?.unifiedLineIndex??v?.unifiedLineIndex;if(S==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const T=oe({type:l,metrics:this.metrics,hunkIndex:g,hunkSpecs:m?.hunkSpecs});if(T!=null){if(d+=T.gapBefore,u>=S-C&&u<S)return c={top:d,height:T.height},!0;d+=T.height+T.gapAfter}}const H=this.getLineHeight(S,(p?.noEOFCR??!1)||(v?.noEOFCR??!1));if(S===u)return c={top:d,height:H},!0;if(d+=H,y>0){const T=ae({type:l,metrics:this.metrics});if(T!=null){if(u>S&&u<=S+y)return c={top:d+T.gapBefore,height:T.height},!0;d+=T.totalHeight}}return!1}}),c}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsed:n=!1,collapsedContextThreshold:s=1}=this.options;if(n)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??Y(this.metrics,t)+this.cache.fileAnnotationHeight,u;return ve({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:f,hunk:h,collapsedBefore:d,collapsedAfter:c,deletionLine:g,additionLine:m})=>{const C=r==="split"?m?.splitLineIndex??g?.splitLineIndex:m?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(d>0){const v=oe({type:o,metrics:this.metrics,hunkIndex:f,hunkSpecs:h?.hunkSpecs});v!=null&&(l+=v.totalHeight)}if(l>=e&&(g!=null?u={lineNumber:g.lineNumber,side:"deletions",top:l}:m!=null&&(u={lineNumber:m.lineNumber,side:"additions",top:l}),u!=null))return!0;const y=this.getLineHeight(C,(m?.noEOFCR??!1)||(g?.noEOFCR??!1));if(l+=y,c>0){const v=ae({type:o,metrics:this.metrics});v!=null&&(l+=v.totalHeight)}return!1}}),u}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const t=e!=null?this.computeRenderRangeFromWindow(this.fileDiff,this.top,e):this.renderRange;if(t==null)return;const{bufferBefore:i,bufferAfter:n,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=n)}return{topOffset:this.top+i+r,height:this.height-(i+n)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSimpleMode()&&this.computeApproximateSize(),this.virtualizer.instanceChanged(this,!0)};setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,i=!1){const n=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0}),i&&n!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==n.bufferAfter&&this.updateBuffers(r)}}computeApproximateSize(e=!1){const t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,this.fileDiff==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:s=!1}=this.options,r=Y(this.metrics,n);if(this.height+=r,s){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight()+this.cache.measuredHeightDeltaTotal,t&&!i&&this.validateComputedHeight(),this.layoutDirty=!1}getActiveEstimatedHeight(){this.ensureEstimatedDiffHeights();const e=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(e==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return e}ensureEstimatedDiffHeights(){if(this.fileDiff==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:n,unifiedHeight:s}=ci({fileDiff:this.fileDiff,metrics:this.metrics,disableFileHeader:e,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:t,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i});this.cache.estimatedSplitHeight=n,this.cache.estimatedUnifiedHeight=s}validateComputedHeight(){if(this.fileContainer==null||this.fileDiff==null)return;const e=this.fileContainer.getBoundingClientRect();e.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:this.fileDiff.name,elementHeight:e.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,oldFile:t,newFile:i,fileDiff:n,forceRender:s=!1,lineAnnotations:r,...o}={}){const{forceRenderOverride:a,isSetup:l}=this;this.forceRenderOverride=void 0;const u=this.syncLineAnnotations(r);if(u&&this.resetLayoutCache({includeEstimatedHeights:!1}),this.fileDiff??=n??(t!=null&&i!=null?Z(t,i,this.options.parseDiffOptions):void 0),e=this.getOrCreateFileContainer(e),this.fileDiff==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(l)this.top??=this.getVirtualizedTop();else{this.computeApproximateSize();const c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");c.connect(e,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const f=this.virtualizer.getWindowSpecs(),h=this.top??0,d=this.computeRenderRangeFromWindow(this.fileDiff,h,f);return super.render({fileDiff:this.fileDiff,fileContainer:e,renderRange:d,oldFile:t,newFile:i,lineAnnotations:r,forceRender:(a??s)||u,...o})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Ai(this.options.hunkSeparators)}approximateLayoutCheckpoints(){if(this.cache.checkpoints.length>0||this.fileDiff==null||this.fileDiff.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,n=this.fileDiff.hunks.length-1,s=this.getDiffStyle(),r=this.getHunkSeparatorType(),o=t?!0:this.hunksRenderer.getExpandedHunksMap(),a=Si(this.cache.heightDeltas);let l=Y(this.metrics,e)+this.cache.fileAnnotationHeight,u=0;const f=({rowCount:h,startLineIndex:d,preSeparatorHeight:c=0,postSeparatorHeight:g=0,metadataOffsets:m=[]})=>{if(h<=0)return;const C=u,y=u+h;let v=vi(C);for(;v<y;){const p=v-C,S=l+(p>0?c:0)+p*this.metrics.lineHeight+yi(m,p)*this.metrics.lineHeight+qe(a,d,d+p);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:d+p,top:S}),v+=ze}l+=c+h*this.metrics.lineHeight+m.length*this.metrics.lineHeight+qe(a,d,d+h)+g,u=y};for(let h=0;h<this.fileDiff.hunks.length;h++){const d=this.fileDiff.hunks[h];if(d==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const c=we({isPartial:this.fileDiff.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:h,collapsedContextThreshold:i}),g=c.collapsedLines>0?oe({type:r,metrics:this.metrics,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0:0;f({rowCount:c.fromStart,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.rangeSize});let m=g;f({rowCount:c.fromEnd,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.fromEnd,preSeparatorHeight:m}),c.fromEnd>0&&(m=0);const C=h===n?Me({fileDiff:this.fileDiff,hunkIndex:h,expandedHunks:o,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,y=C!=null&&C.collapsedLines>0?ae({type:r,metrics:this.metrics})?.totalHeight??0:0,v=C!=null?C.fromStart+C.fromEnd:0,p=s==="split"?d.splitLineCount:d.unifiedLineCount,S=s==="split"?d.splitLineStart:d.unifiedLineStart;f({rowCount:p,startLineIndex:S,preSeparatorHeight:m,postSeparatorHeight:v===0?y:0,metadataOffsets:Hi({diffStyle:s,hunk:d,rowCount:p})}),C!=null&&v>0&&f({rowCount:v,startLineIndex:S+p,postSeparatorHeight:y})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const u=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=u;const f=Math.max(l.collapsedBefore,0),{fromStart:h,fromEnd:d,renderAll:c}=we({isPartial:e.isPartial,rangeSize:f,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});f>0&&(i+=c?f:h+d)}const o=Me({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,u=this.getDiffStyle(),f=this.getHunkSeparatorType(),h=this.height;let d=this.cache.totalLines>0?this.cache.totalLines:this.getExpandedLineCount(e,u);const c=Y(this.metrics,s),g=e.hunks.length>0?Ze(this.metrics):0,{fileAnnotationHeight:m}=this.cache,C=c+m,y=Math.max(0,h-c-m-g),v=this.hasFileAnnotations(e),p=t+c,S=m>0&&v&&p<n&&p+m>i;if(t<i-h||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};if(d<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(),d=this.cache.totalLines>0?this.cache.totalLines:d;const H=Math.ceil(Math.max(n-i,0)/l),T=Math.ceil(H/a)*a+a,F=T/a,de=F,j=[],ue=(i+n)/2,q=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-T*l*2),a);let b=t+(q?.top??C),J=q?.renderedLineIndex??0,R,D,P;if(ve({diff:e,diffStyle:u,startingLine:q?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ye,hunk:He,collapsedBefore:te,collapsedAfter:ie,deletionLine:k,additionLine:E})=>{const z=E!=null?E.splitLineIndex:k.splitLineIndex,$=E!=null?E.unifiedLineIndex:k.unifiedLineIndex,O=(E?.noEOFCR??!1)||(k?.noEOFCR??!1),N=(te>0?oe({type:f,metrics:this.metrics,hunkIndex:ye,hunkSpecs:He?.hunkSpecs}):void 0)?.totalHeight??0;b+=N;const ne=J%a===0,M=Math.floor(J/a);if(ne&&(j[M]=b-(t+C+N),P!=null)){if(P<=0)return!0;P--}const Le=this.getLineHeight(u==="split"?z:$,O);return b>i-Le&&b<n&&(R??=M),D==null&&b+Le>ue&&(D=M),P==null&&b>=n&&ne&&(P=de),J++,b+=Le,ie>0&&(b+=ae({type:f,metrics:this.metrics})?.totalHeight??0),!1}}),R==null)if(S)R=0,D=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};D??=R;const V=Math.round(D-F/2),L=Math.max(0,Math.ceil(d/a)-F),A=Math.max(0,Math.min(V,L)),x=A*a,I=V<0?T+V*a:T,W=j[A]??0,Q=x===0?0:m+W,ee=A+I/a,fe=ee<j.length?y-j[ee]:y-(b-t-C);return{startingLine:x,totalLines:I,bufferBefore:Q,bufferAfter:Math.max(0,fe)}}};function Ci(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Ht&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Si(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function qe({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=Ke(e,i);return(t[Ke(e,n)]??0)-(t[s]??0)}function Ke(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function vi(e){return Math.ceil(e/ze)*ze}function yi(e,t){let i=0;for(const n of e)n<t&&i++;return i}function Hi({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function Li(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function Ti(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Ai(e){return typeof e=="function"?"custom":e??"line-info"}function ki(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{li as F,Mi as V,Z as p};
|
|
10
|
+
`:t}function Ee(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function si(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ri(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function oi(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}let ai=-1;var li=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++ai}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;fastRefreshTimeout;constructor(e={theme:_},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new rt,this.scrollSyncManager=new Bt,this.interactionManager=new ot("diff",Ue(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return oi(e)}createHunksRenderer(e){return new ti(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const i=this.hunksRenderer.getRenderDiff()??this.fileDiff;if(i==null)return;const n=i.hunks.at(-1);let s,r;e:for(const o of i.hunks){let a=t==="deletions"?o.deletionStart:o.additionStart;const l=t==="deletions"?o.deletionCount:o.additionCount;let u=o.splitLineStart,f=o.unifiedLineStart;if(e<a){const h=a-e;s=Math.max(f-h,0),r=Math.max(u-h,0);break e}if(e>=a+l){if(o===n){const h=e-(a+l);s=f+o.unifiedLineCount+h,r=u+o.splitLineCount+h;break e}continue}for(const h of o.hunkContent)if(h.type==="context")if(e<a+h.lines){const d=e-a;r=u+d,s=f+d;break e}else a+=h.lines,u+=h.lines,f+=h.lines;else{const d=t==="deletions"?h.deletions:h.additions;if(e<a+d){const c=e-a;s=f+(t==="additions"?h.deletions:0)+c,r=u+c;break e}else a+=d,u+=Math.max(h.deletions,h.additions),f+=h.deletions+h.additions}break e}if(!(s==null||r==null))return[s,r]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Ue(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;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&&!Rt(this.appliedThemeCSS.theme,this.options.theme??_)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.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.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0,this.fastRefreshTimeout!=null&&(clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=void 0)}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:i,preventEmit:n=!1,lineAnnotations:s,oldFile:r,newFile:o,fileDiff:a}=e;this.hydrateElements(t,i),ui(this.pre,hi({fileDiff:a,oldFile:r,newFile:o}),this.options.collapsed)||fi(this.headerElement,di({fileDiff:a,oldFile:r,newFile:o}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:a,oldFile:r,newFile:o,lineAnnotations:s}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),at(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!=null&&i!=null?J(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.rerender()};render({oldFile:e,newFile:t,fileDiff:i,deferManagers:n=!1,forceRender:s=!1,preventEmit:r=!1,lineAnnotations:o,fileContainer:a,containerWrapper:l,renderRange:u}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:f=!1,themeType:h="system"}=this.options,d=f?void 0:u,c=this.hasThemeChanged(),g=e!=null&&t!=null&&(!Be(e,this.deletionFile)||!Be(t,this.additionFile));let m=i!=null&&i!==this.fileDiff;const C=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1;if(!f&&Xe(d,this.renderRange)&&!s&&!C&&!c&&(i!=null&&i===this.fileDiff||i==null&&!g))return this.applyCachedThemeState(h);const{renderRange:y}=this;if(this.renderRange=d,this.deletionFile=e,this.additionFile=t,i!=null?this.fileDiff=i:e!=null&&t!=null&&g&&(m=!0,this.fileDiff=J(e,t,this.options.parseDiffOptions)),m&&(this.cachedHeaderHTML=void 0),o!=null&&this.setLineAnnotations(o),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:v=!1,disableFileHeader:p=!1}=this.options;if(p&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,l),this.applyCachedThemeState(h),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const S=this.hunksRenderer.renderDiff(this.fileDiff,zt);S!=null&&this.applyThemeState(a,S.themeStyles,h,S.baseThemeType),S?.headerElement!=null&&this.applyHeaderToDOM(S.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}try{const S=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(s,C,g||m||c)&&this.applyPartialRender({previousRenderRange:y,renderRange:d}))){const L=this.hunksRenderer.renderDiff(this.fileDiff,d);if(L==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,L.themeStyles,h,L.baseThemeType),L.headerElement!=null&&this.applyHeaderToDOM(L.headerElement,a),L.additionsContentAST!=null||L.deletionsContentAST!=null||L.unifiedContentAST!=null?this.applyHunksToDOM(S,L):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(L.hunkData)}this.applyBuffers(S,d),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,n||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,i=this.fileDiff;e!=null&&t!=null&&i!=null&&!i.isPartial&&this.hunksRenderer.initializeHighlighter().then(n=>{e.__syncRenderView(n,t,i,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);const i=this.hunksRenderer.getRenderDiff();i!=null&&(this.fileDiff=i),this.rerender(),this.interactionManager.setSelectionDirty(),t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}rerenderFromDocument(e){this.hunksRenderer.applyDocumentChange(e);const t=this.hunksRenderer.getRenderDiff();t!=null&&(this.fileDiff=t),this.hunksRenderer.clearRenderCache(),this.rerender()}updateRenderCache(e,t,i,n){this.hunksRenderer.updateRenderCache(e,t,n),i===!0&&(this.options.diffStyle==="split"?(this.fastRefreshTimeout!=null&&clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=setTimeout(()=>{this.fastRefreshTimeout=void 0,this.fastRefreshDiffView()},100)):this.refreshDiffView())}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{fileDiff:e,workerManager:t}=this;if(e==null||t==null||be(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!ri(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:i}of this.annotationCache.values())i.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[i,n]of this.lineAnnotations.entries()){const s=`${i}-${he(n)}`;let r=this.annotationCache.get(s);if(r==null||!si(n,r.annotation)){r?.element.remove();const o=t(n);if(o==null)continue;r={element:lt(he(n)),annotation:n},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[i,{element:n}]of e.entries())this.annotationCache.delete(i),n.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 i=ht();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return s&&this.emitPostRender(!0),this.fileContainer=n,i!=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 i of t.children)i instanceof SVGElement?this.spriteSVG??=i:Pe(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):Pe(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=dt;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{fileDiff:i}=this,n=this.cachedHeaderHTML??le(e);if(this.cachedHeaderHTML=n,n!==this.lastRenderedHeaderHTML){const h=document.createElement("div");h.innerHTML=n;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=n}if(this.isContainerManaged||i==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const h=s(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ft,h),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const l=r?.(i)??void 0,u=o?.(i)??void 0,f=a?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Nt,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ut,u),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Pt,f),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,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),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}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??=ut(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ft(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.options.theme??_,a=typeof o=="string"?o:{...o},l=Oe(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=ct({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ct(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=pt(this.themeCSSStyle.textContent??"",Oe(e)))}applyHunksToDOM(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),u=this.hunksRenderer.renderCodeAST("additions",t);a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Ae({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a),o.push(this.codeUnified)):l!=null||u!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ae({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),u!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ae({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(u),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){const{pre:i,codeUnified:n,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(i==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,n,r,s);if(a==null)return!1;const l=e.startingLine,u=t.startingLine,f=l+e.totalLines,h=u+t.totalLines,d=Math.max(l,u),c=Math.min(f,h);if(c<=d)return!1;const g=Math.max(0,d-l),m=Math.max(0,f-c),C=this.trimColumns({columns:a,trimStart:g,trimEnd:m,previousStart:l,overlapStart:d,overlapEnd:c,diffStyle:o});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(T,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:T,totalLines:F,bufferBefore:0,bufferAfter:0})},p=v(u,Math.max(d-u,0));if(p==null&&u<d)return!1;const S=v(c,Math.max(h-c,0));if(S==null&&h>c)return!1;const L=(T,F)=>{if(T!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,T,F);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,T,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=T.rowCount}};return this.cleanupErrorWrapper(),L(p,"afterbegin"),L(S,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(o,a,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}fastRefreshDiffView(){if(this.options.diffStyle!=="split")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])if(u!=null&&l.childElementCount===u.length)for(let f=0;f<u.length;f++){const h=l.children[f],d=u[f].properties["data-line-type"];d!=null&&h.dataset.lineType!==d&&(h.dataset.lineType=d)}};i("deletions",t[0]),i("additions",t[1])}refreshDiffView(){const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns(this.options.diffStyle??"split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null)return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])u!=null&&(l.innerHTML=le(u))};Array.isArray(t)?(i("deletions",t[0]),i("additions",t[1])):i("unified",t),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=X(t[0]),s=X(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),u=Array.from(e.gutter.children);if(l.length!==u.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const f=u[r],h=l[r];if(r++,!(f instanceof HTMLElement)||!(h instanceof HTMLElement))throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset||f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset)){f.remove(),h.remove(),s++;continue}if("lineIndex"in f.dataset&&"lineIndex"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in f.dataset&&"separator"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="buffer"&&"contentBuffer"in h.dataset){const d=this.getBufferSize(h.dataset);if(d==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const c=Math.min(t,d),g=d-c;g>0?(this.updateBufferSize(f,g),this.updateBufferSize(h,g),s+=c):(f.remove(),h.remove(),s+=d),t-=c,t===0&&g===0&&(o=!0)}else if(a){const c=n,g=n+d-1;if(i<=c)f.remove(),h.remove(),s+=d;else if(i<=g){const m=g-i+1,C=d-m;this.updateBufferSize(f,C),this.updateBufferSize(h,C),s+=m}}n+=d;continue}throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const u=o>0,f=r>0;if(!u&&!f)return 0;const h=u?a:0,d=f?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,h,d);if(t==="split"&&Array.isArray(e)){const c=this.trimColumnRows(e[0],h,d),g=this.trimColumnRows(e[1],h,d);if(e[0]!=null&&e[1]!=null&&c!==g)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?c:g}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,i,n){function s(r){if(r==null)return;const o=r.children[0],a=r.children[1];if(!(!(o instanceof HTMLElement)||!(a instanceof HTMLElement)||o.dataset.gutter==null||a.dataset.content==null))return{gutter:o,content:a}}if(e==="unified")return s(t);{const r=s(i),o=s(n);return r!=null||o!=null?[r,o]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:u="split"}=this.options,f={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:u==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};gt(f,this.appliedPreAttributes)||(mt(e,f),this.appliedPreAttributes=f)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);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 hi({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function di({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function ui(e,t,i=!1){return!i&&e==null&&t}function fi(e,t,i=!1){return e==null&&t&&!i}function X(e){if(!(e==null||e.type!=="element"))return e.children??[]}function ci({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o}){let a=Y(t,i),l=a;const u=s?!0:r,f=e.hunks.length-1;for(let h=0;h<e.hunks.length;h++){const d=e.hunks[h];if(d==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const c=we({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:u,hunkIndex:h,collapsedContextThreshold:o}),g=(c.fromStart+c.fromEnd)*t.lineHeight;if(a+=g,l+=g,c.collapsedLines>0){const y=oe({type:n,metrics:t,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0;a+=y,l+=y}a+=d.splitLineCount*t.lineHeight,l+=d.unifiedLineCount*t.lineHeight;const m=pi(d);a+=m.split*t.lineHeight,l+=m.unified*t.lineHeight;const C=h===f?Me({fileDiff:e,hunkIndex:h,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(a+=y,l+=y,C.collapsedLines>0){const v=ae({type:n,metrics:t})?.totalHeight??0;a+=v,l+=v}}}if(e.hunks.length>0){const h=Je(t);a+=h,l+=h}return{splitHeight:a,unifiedHeight:l}}function pi(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return gi(e,t)}function gi(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const ze=5e3;let mi=-1;var Mi=class extends li{__id=`little-virtualized-file-diff:${++mi}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Re(i)}setMetrics(e,t=!1){const i=Re(e);!t&&St(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!vt(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber!==0?!1:e.type==="new"?t.side==="additions":e.type==="deleted"?t.side==="deletions":!0)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!yt(t,e),n=i&&Hi(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Ti(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),t&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;const{overflow:t="scroll"}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;const i=this.getDiffStyle(),n=i==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Ye(this.renderRange)){const r=Ci(n)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of n){if(r==null)continue;const o=r.children[1];if(o instanceof HTMLElement)for(const a of o.children){if(!(a instanceof HTMLElement))continue;const l=a.dataset.lineIndex;if(l==null)continue;const u=ki(l,i);let f=a.getBoundingClientRect().height,h=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(h=!0),f+=a.nextElementSibling.getBoundingClientRect().height);const d=this.getEstimatedLineHeight(h),c=this.cache.heightDeltas.get(u)??0,g=f-d;g!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=g-c,g===0?this.cache.heightDeltas.delete(u):this.cache.heightDeltas.set(u,g))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());prepareCodeViewItem(e,t,i,n){const s=!re(this.fileDiff,e),r=this.syncLineAnnotations(n);let o=i?.resetDiffLayoutCache===!0||s||r,a=s||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights;i?.metrics!=null&&(this.metrics=Re(i.metrics),o=!0,a=!0);const{collapsed:l=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),o&&this.resetLayoutCache({includeEstimatedHeights:a}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t="additions"){if(this.fileDiff==null||e<1)return;const i=this.getLineIndex(e,t);if(i==null)return;const{disableFileHeader:n=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),u=a==="split"?i[1]:i[0];this.approximateLayoutCheckpoints();const f=Y(this.metrics,n),h=this.getLayoutCheckpointBeforeLineIndex(u);let d=h?.top??f+this.cache.fileAnnotationHeight;if(r)return{top:f,height:0};let c;return ve({diff:this.fileDiff,diffStyle:a,startingLine:h?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:g,hunk:m,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:p})=>{const S=a==="split"?p?.splitLineIndex??v?.splitLineIndex:p?.unifiedLineIndex??v?.unifiedLineIndex;if(S==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const T=oe({type:l,metrics:this.metrics,hunkIndex:g,hunkSpecs:m?.hunkSpecs});if(T!=null){if(d+=T.gapBefore,u>=S-C&&u<S)return c={top:d,height:T.height},!0;d+=T.height+T.gapAfter}}const L=this.getLineHeight(S,(p?.noEOFCR??!1)||(v?.noEOFCR??!1));if(S===u)return c={top:d,height:L},!0;if(d+=L,y>0){const T=ae({type:l,metrics:this.metrics});if(T!=null){if(u>S&&u<=S+y)return c={top:d+T.gapBefore,height:T.height},!0;d+=T.totalHeight}}return!1}}),c}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsed:n=!1,collapsedContextThreshold:s=1}=this.options;if(n)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??Y(this.metrics,t)+this.cache.fileAnnotationHeight,u;return ve({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:f,hunk:h,collapsedBefore:d,collapsedAfter:c,deletionLine:g,additionLine:m})=>{const C=r==="split"?m?.splitLineIndex??g?.splitLineIndex:m?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(d>0){const v=oe({type:o,metrics:this.metrics,hunkIndex:f,hunkSpecs:h?.hunkSpecs});v!=null&&(l+=v.totalHeight)}if(l>=e&&(g!=null?u={lineNumber:g.lineNumber,side:"deletions",top:l}:m!=null&&(u={lineNumber:m.lineNumber,side:"additions",top:l}),u!=null))return!0;const y=this.getLineHeight(C,(m?.noEOFCR??!1)||(g?.noEOFCR??!1));if(l+=y,c>0){const v=ae({type:o,metrics:this.metrics});v!=null&&(l+=v.totalHeight)}return!1}}),u}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const t=e!=null?this.computeRenderRangeFromWindow(this.fileDiff,this.top,e):this.renderRange;if(t==null)return;const{bufferBefore:i,bufferAfter:n,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=n)}return{topOffset:this.top+i+r,height:this.height-(i+n)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSimpleMode()&&this.computeApproximateSize(),this.virtualizer.instanceChanged(this,!0)};setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,i=!1){const n=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0}),i&&n!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==n.bufferAfter&&this.updateBuffers(r)}}computeApproximateSize(e=!1){const t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,this.fileDiff==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:s=!1}=this.options,r=Y(this.metrics,n);if(this.height+=r,s){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight()+this.cache.measuredHeightDeltaTotal,t&&!i&&this.validateComputedHeight(),this.layoutDirty=!1}getActiveEstimatedHeight(){this.ensureEstimatedDiffHeights();const e=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(e==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return e}ensureEstimatedDiffHeights(){if(this.fileDiff==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:n,unifiedHeight:s}=ci({fileDiff:this.fileDiff,metrics:this.metrics,disableFileHeader:e,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:t,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i});this.cache.estimatedSplitHeight=n,this.cache.estimatedUnifiedHeight=s}validateComputedHeight(){if(this.fileContainer==null||this.fileDiff==null)return;const e=this.fileContainer.getBoundingClientRect();e.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:this.fileDiff.name,elementHeight:e.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,oldFile:t,newFile:i,fileDiff:n,forceRender:s=!1,lineAnnotations:r,...o}={}){const{forceRenderOverride:a,isSetup:l}=this;this.forceRenderOverride=void 0;const u=this.syncLineAnnotations(r);if(u&&this.resetLayoutCache({includeEstimatedHeights:!1}),this.fileDiff??=n??(t!=null&&i!=null?J(t,i,this.options.parseDiffOptions):void 0),e=this.getOrCreateFileContainer(e),this.fileDiff==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(l)this.top??=this.getVirtualizedTop();else{this.computeApproximateSize();const c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");c.connect(e,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const f=this.virtualizer.getWindowSpecs(),h=this.top??0,d=this.computeRenderRangeFromWindow(this.fileDiff,h,f);return super.render({fileDiff:this.fileDiff,fileContainer:e,renderRange:d,oldFile:t,newFile:i,lineAnnotations:r,forceRender:(a??s)||u,...o})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Ai(this.options.hunkSeparators)}approximateLayoutCheckpoints(){if(this.cache.checkpoints.length>0||this.fileDiff==null||this.fileDiff.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,n=this.fileDiff.hunks.length-1,s=this.getDiffStyle(),r=this.getHunkSeparatorType(),o=t?!0:this.hunksRenderer.getExpandedHunksMap(),a=Si(this.cache.heightDeltas);let l=Y(this.metrics,e)+this.cache.fileAnnotationHeight,u=0;const f=({rowCount:h,startLineIndex:d,preSeparatorHeight:c=0,postSeparatorHeight:g=0,metadataOffsets:m=[]})=>{if(h<=0)return;const C=u,y=u+h;let v=vi(C);for(;v<y;){const p=v-C,S=l+(p>0?c:0)+p*this.metrics.lineHeight+yi(m,p)*this.metrics.lineHeight+qe(a,d,d+p);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:d+p,top:S}),v+=ze}l+=c+h*this.metrics.lineHeight+m.length*this.metrics.lineHeight+qe(a,d,d+h)+g,u=y};for(let h=0;h<this.fileDiff.hunks.length;h++){const d=this.fileDiff.hunks[h];if(d==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const c=we({isPartial:this.fileDiff.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:h,collapsedContextThreshold:i}),g=c.collapsedLines>0?oe({type:r,metrics:this.metrics,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0:0;f({rowCount:c.fromStart,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.rangeSize});let m=g;f({rowCount:c.fromEnd,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.fromEnd,preSeparatorHeight:m}),c.fromEnd>0&&(m=0);const C=h===n?Me({fileDiff:this.fileDiff,hunkIndex:h,expandedHunks:o,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,y=C!=null&&C.collapsedLines>0?ae({type:r,metrics:this.metrics})?.totalHeight??0:0,v=C!=null?C.fromStart+C.fromEnd:0,p=s==="split"?d.splitLineCount:d.unifiedLineCount,S=s==="split"?d.splitLineStart:d.unifiedLineStart;f({rowCount:p,startLineIndex:S,preSeparatorHeight:m,postSeparatorHeight:v===0?y:0,metadataOffsets:Li({diffStyle:s,hunk:d,rowCount:p})}),C!=null&&v>0&&f({rowCount:v,startLineIndex:S+p,postSeparatorHeight:y})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const u=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=u;const f=Math.max(l.collapsedBefore,0),{fromStart:h,fromEnd:d,renderAll:c}=we({isPartial:e.isPartial,rangeSize:f,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});f>0&&(i+=c?f:h+d)}const o=Me({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,u=this.getDiffStyle(),f=this.getHunkSeparatorType(),h=this.height;let d=this.cache.totalLines>0?this.cache.totalLines:this.getExpandedLineCount(e,u);const c=Y(this.metrics,s),g=e.hunks.length>0?Je(this.metrics):0,{fileAnnotationHeight:m}=this.cache,C=c+m,y=Math.max(0,h-c-m-g),v=this.hasFileAnnotations(e),p=t+c,S=m>0&&v&&p<n&&p+m>i;if(t<i-h||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};if(d<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(),d=this.cache.totalLines>0?this.cache.totalLines:d;const L=Math.ceil(Math.max(n-i,0)/l),T=Math.ceil(L/a)*a+a,F=T/a,de=F,j=[],ue=(i+n)/2,q=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-T*l*2),a);let b=t+(q?.top??C),Z=q?.renderedLineIndex??0,R,D,P;if(ve({diff:e,diffStyle:u,startingLine:q?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ye,hunk:Le,collapsedBefore:te,collapsedAfter:ie,deletionLine:k,additionLine:E})=>{const z=E!=null?E.splitLineIndex:k.splitLineIndex,$=E!=null?E.unifiedLineIndex:k.unifiedLineIndex,O=(E?.noEOFCR??!1)||(k?.noEOFCR??!1),N=(te>0?oe({type:f,metrics:this.metrics,hunkIndex:ye,hunkSpecs:Le?.hunkSpecs}):void 0)?.totalHeight??0;b+=N;const ne=Z%a===0,M=Math.floor(Z/a);if(ne&&(j[M]=b-(t+C+N),P!=null)){if(P<=0)return!0;P--}const He=this.getLineHeight(u==="split"?z:$,O);return b>i-He&&b<n&&(R??=M),D==null&&b+He>ue&&(D=M),P==null&&b>=n&&ne&&(P=de),Z++,b+=He,ie>0&&(b+=ae({type:f,metrics:this.metrics})?.totalHeight??0),!1}}),R==null)if(S)R=0,D=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};D??=R;const V=Math.round(D-F/2),H=Math.max(0,Math.ceil(d/a)-F),A=Math.max(0,Math.min(V,H)),x=A*a,I=V<0?T+V*a:T,W=j[A]??0,Q=x===0?0:m+W,ee=A+I/a,fe=ee<j.length?y-j[ee]:y-(b-t-C);return{startingLine:x,totalLines:I,bufferBefore:Q,bufferAfter:Math.max(0,fe)}}};function Ci(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Lt&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Si(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function qe({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=Ke(e,i);return(t[Ke(e,n)]??0)-(t[s]??0)}function Ke(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function vi(e){return Math.ceil(e/ze)*ze}function yi(e,t){let i=0;for(const n of e)n<t&&i++;return i}function Li({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function Hi(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function Ti(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Ai(e){return typeof e=="function"?"custom":e??"line-info"}function ki(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{li as F,Mi as V,J as p};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{r as u,j as s,f as G}from"./vendor-react-BUCujlKS.js";import{f as ee,l as ft,I as j,dG as xt,B,h as J,au as rs,a9 as kt,aa as bt,ab as wt,aw as ns,af as as,ag as is,J as we,ah as ls,Y as cs,H as us,ao as it,ap as lt,ar as ct,as as ut,bW as dt,at as he,bc as pt,o as ds}from"./useAppFontEffects-Cwyhjfl5.js";import{f as ps,u as hs,b as ms,a as gs,c as fs,B as xs,C as ks,P as ht}from"./patchFileDiff-CdztVMz0.js";import{h as vt,q as bs,u as me,dz as ws,dy as vs}from"./index-BD8ILbxF.js";import{u as L,W as ys}from"./main-BydQ1tr_.js";import{P as js}from"./PierreDiffViewer-DzLt-nel.js";import{e as Ss,d as Ns}from"./runtimeEndpointReset-BhT_-c52.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-BY_5qla_.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./contextPanelEmbeddedChat-BdA6bdky.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Cb1YnICj.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-zod-B6551dwG.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./VirtualizedFileDiff-CAWthkoy.js";import"./web-components-LV3vjTxy.js";import"./computeVirtualFileMetrics-BkiDSlTW.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isDiffPlainText-GMdPz-71.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./useRootScrollLock-CwjoWuC4.js";import"./scheduledTasksApi-BEuUF_cj.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-DDkpBEU8.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const Cs=n=>{if(!n?.walkthrough)return null;const t=new Map(n.hunks.map(a=>[a.id,a])),e=new Set,o=[],l=[];for(const[a,h]of n.walkthrough.chapters.entries()){const c=[];for(const g of h.stops){const m=[],p=[];for(const i of g.hunkIds){const v=t.get(i);v?(m.push(v),e.add(i)):p.push(i)}const f={stop:g,chapter:h,chapterIndex:a,position:o.length+1,hunks:m,missingHunkIds:p,isStale:p.length>0};o.push(f),c.push(f)}l.push({chapter:h,stops:c})}return{walkthrough:n.walkthrough,stops:o,chapters:l,uncoveredHunks:n.hunks.filter(a=>!e.has(a.id)),staleStopCount:o.filter(a=>a.isStale).length,isStale:o.some(a=>a.isStale)}},Rs=n=>{const t=new Map;for(const e of n){const o=t.get(e.path);if(o){o.added+=e.added,o.deleted+=e.deleted;continue}t.set(e.path,{path:e.path,added:e.added,deleted:e.deleted})}return[...t.values()]},yt=n=>{const t=[];for(const e of n){const o=t.at(-1);if(o&&o.path===e.path){o.hunks.push(e);continue}t.push({path:e.path,hunks:[e]})}return t},Ms=n=>{if(n.length===0)return"";if(n.length===1)return n[0].patch;const t=n[0].patch,e=t.indexOf(`
|
|
2
|
+
@@`);if(e===-1)return t;const o=t.slice(0,e),l=n.map(a=>{const h=a.patch.indexOf(`
|
|
3
|
+
@@`);return h===-1?"":a.patch.slice(h+1)});return`${o}
|
|
4
|
+
${l.join("")}`},Is=n=>n?`${n.providerID}/${n.modelID}`:"",Ts=({reason:n,model:t,requiredChars:e,availableChars:o,onRetry:l})=>{const{t:a}=ee(),h=ft(k=>k.modelsMetadata),[c,g]=u.useState(void 0),[m,p]=u.useState(!1),f=n==="context-too-small"||n==="structured-output-unsupported"||n==="output-exhausted";u.useEffect(()=>{if(!f||c!==void 0)return;let k=!1;return(async()=>{try{const x=await vt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!x.ok)return;const M=await x.json().catch(()=>null);!k&&Array.isArray(M?.authenticatedProviders)&&g(M.authenticatedProviders.filter(I=>typeof I=="string"))}catch{}})(),()=>{k=!0}},[f,c]);const i=u.useCallback(async(k,x)=>{if(!k||!x||m)return;const M=`${k}/${x}`;p(!0);try{await bs({walkthroughModelOverride:M}),l()}catch(I){console.warn("Failed to save small model override:",I)}finally{p(!1)}},[l,m]),v=u.useCallback((k,x)=>h.get(`${k}/${x}`)?.structured_output!==!1,[h]),b=Is(t),w=()=>{if(n==="no-model")return a("walkthrough.blocked.noModel.description");if(n==="empty-diff")return a("walkthrough.blocked.emptyDiff.description");if(n==="only-generated")return a("walkthrough.blocked.onlyGenerated.description");if(n==="server-unsupported")return a("walkthrough.blocked.serverUnsupported.description");if(n==="output-exhausted")return b?a("walkthrough.blocked.outputExhausted.description",{model:b}):a("walkthrough.blocked.outputExhausted.descriptionUnknownModel");if(n==="structured-output-unsupported")return b?a("walkthrough.blocked.structuredOutput.description",{model:b}):a("walkthrough.blocked.structuredOutput.descriptionUnknownModel");const k=Math.ceil((e??0)/1e3),x=Math.ceil((o??0)/1e3);return b?a("walkthrough.blocked.contextTooSmall.description",{model:b,required:k,available:x}):a("walkthrough.blocked.contextTooSmall.descriptionUnknownModel",{required:k,available:x})},y=()=>a(n==="no-model"?"walkthrough.blocked.noModel.title":n==="empty-diff"?"walkthrough.blocked.emptyDiff.title":n==="only-generated"?"walkthrough.blocked.onlyGenerated.title":n==="server-unsupported"?"walkthrough.blocked.serverUnsupported.title":n==="output-exhausted"?"walkthrough.blocked.outputExhausted.title":n==="structured-output-unsupported"?"walkthrough.blocked.structuredOutput.title":"walkthrough.blocked.contextTooSmall.title");return s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[s.jsx(j,{name:n==="empty-diff"||n==="only-generated"?"information":"error-warning",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:y()}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:w()}),f&&s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("walkthrough.blocked.chooseModel")}),s.jsx(xt,{providerId:t?.providerID??"",modelId:t?.modelID??"",onChange:(k,x)=>{i(k,x)},allowedProviderIds:c??[],isModelAllowed:v})]}),(n==="empty-diff"||n==="only-generated"||n==="server-unsupported")&&s.jsx(B,{type:"button",variant:"outline",size:"sm",onClick:l,children:a("walkthrough.action.refresh")})]})},Ps=[{labelKey:"walkthrough.stage.collecting"},{labelKey:"walkthrough.stage.asking"},{labelKey:"walkthrough.stage.assembling"}],Es=n=>{const t=G.c(6),{progress:e}=n,{t:o}=ee(),{completedCount:l,activeIndex:a}=e;let h;t[0]!==a||t[1]!==l||t[2]!==o?(h=Ps.map((g,m)=>{const p=m<l,f=a===m;return s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:p?s.jsx(j,{name:"check",className:"size-3.5 text-status-success"}):f?s.jsx(j,{name:"loader-4",className:"size-3.5 animate-spin text-[var(--status-info)]"}):s.jsx("span",{className:"size-1.5 rounded-full bg-surface-muted"})}),s.jsx("span",{className:J("typography-meta",f?"text-foreground":p?"text-muted-foreground":"text-muted-foreground/60"),children:o(g.labelKey)})]},g.labelKey)}),t[0]=a,t[1]=l,t[2]=o,t[3]=h):h=t[3];let c;return t[4]!==h?(c=s.jsx("ul",{className:"flex flex-col gap-2 text-left",children:h}),t[4]=h,t[5]=c):c=t[5],c},ae=["collecting","asking","assembling"],Oe=450,As=n=>n==="retrying"?ae.indexOf("asking"):n?ae.indexOf(n):-1,zs=(n,t)=>Math.min(n+1,t),Os=(n,t)=>{const e=G.c(17),[o,l]=u.useState(-1),a=u.useRef(0);let h;e[0]!==t||e[1]!==o||e[2]!==n?(h=t?Math.max(As(n),0):o<0?-1:ae.length,e[0]=t,e[1]=o,e[2]=n,e[3]=h):h=e[3];const c=h;let g,m;e[4]!==t||e[5]!==o||e[6]!==c?(g=()=>{if(c<=o){c<o&&t&&(l(c),a.current=Date.now());return}const k=Date.now()-a.current,x=()=>{a.current=Date.now(),l(I=>zs(I,c))};if(o<0||k>=Oe){x();return}const M=setTimeout(x,Oe-k);return()=>clearTimeout(M)},m=[t,o,c],e[4]=t,e[5]=o,e[6]=c,e[7]=g,e[8]=m):(g=e[7],m=e[8]),u.useEffect(g,m);let p,f;e[9]!==t||e[10]!==o?(p=()=>{if(t||o<ae.length)return;const k=setTimeout(()=>l(-1),Oe);return()=>clearTimeout(k)},f=[t,o],e[9]=t,e[10]=o,e[11]=p,e[12]=f):(p=e[11],f=e[12]),u.useEffect(p,f);const i=o>=ae.length,v=Math.max(0,Math.min(o,ae.length)),b=i||o<0?null:o,w=!t&&o>=0;let y;return e[13]!==v||e[14]!==b||e[15]!==w?(y={completedCount:v,activeIndex:b,holding:w},e[13]=v,e[14]=b,e[15]=w,e[16]=y):y=e[16],y},jt=u.memo(function(t){const e=G.c(11),{path:o,hunks:l,renderSideBySide:a,wrapLines:h}=t;let c;if(e[0]!==l||e[1]!==o){const f=Ms(l);c=f?ps(o,f):void 0,e[0]=l,e[1]=o,e[2]=c}else c=e[2];const g=c;if(!g)return null;let m;e[3]!==o?(m=rs(o)||"",e[3]=o,e[4]=m):m=e[4];let p;return e[5]!==g||e[6]!==o||e[7]!==a||e[8]!==m||e[9]!==h?(p=s.jsx(js,{original:"",modified:"",fileDiff:g,language:m,fileName:o,renderSideBySide:a,wrapLines:h,layout:"inline"}),e[5]=g,e[6]=o,e[7]=a,e[8]=m,e[9]=h,e[10]=p):p=e[10],p}),He=n=>`walkthrough-stop-${n}`,Hs={critical:"border border-[var(--interactive-border)] font-medium text-foreground",normal:"bg-surface-muted text-muted-foreground",context:"bg-surface-muted text-muted-foreground"},Ls=n=>{const t=G.c(22),{stopView:e}=n,{t:o}=ee(),{stop:l}=e;let a;t[0]!==e.position?(a=s.jsx("span",{className:"typography-micro flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-surface-muted px-1.5 tabular-nums text-muted-foreground",children:e.position}),t[0]=e.position,t[1]=a):a=t[1];let h;t[2]!==l.title?(h=s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:l.title}),t[2]=l.title,t[3]=h):h=t[3];let c;t[4]!==l.importance||t[5]!==o?(c=l.importance!=="normal"&&s.jsxs(kt,{children:[s.jsx(bt,{className:J("typography-micro flex h-5 items-center rounded px-1.5 leading-none",Hs[l.importance]),children:l.importance==="critical"?o("walkthrough.importance.critical"):o("walkthrough.importance.context")}),s.jsx(wt,{className:"max-w-64",children:s.jsx("p",{className:"typography-micro leading-tight",children:l.importance==="critical"?o("walkthrough.importance.criticalHint"):o("walkthrough.importance.contextHint")})})]}),t[4]=l.importance,t[5]=o,t[6]=c):c=t[6];let g;t[7]!==a||t[8]!==h||t[9]!==c?(g=s.jsxs("div",{className:"flex items-center gap-2",children:[a,h,c]}),t[7]=a,t[8]=h,t[9]=c,t[10]=g):g=t[10];let m;t[11]!==l.prose?(m=s.jsx("p",{className:"typography-body text-muted-foreground",children:l.prose}),t[11]=l.prose,t[12]=m):m=t[12];let p;t[13]!==e.hunks||t[14]!==e.isStale||t[15]!==e.missingHunkIds||t[16]!==o?(p=e.isStale&&s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-status-warning",children:[s.jsx(j,{name:"error-warning",className:"size-3.5 shrink-0"}),e.hunks.length===0?o("walkthrough.stop.staleAll"):o("walkthrough.stop.stalePartial",{count:e.missingHunkIds.length})]}),t[13]=e.hunks,t[14]=e.isStale,t[15]=e.missingHunkIds,t[16]=o,t[17]=p):p=t[17];let f;return t[18]!==g||t[19]!==m||t[20]!==p?(f=s.jsxs("header",{className:"flex flex-col gap-2 px-4 pt-5 pb-3",children:[g,m,p]}),t[18]=g,t[19]=m,t[20]=p,t[21]=f):f=t[21],f},St=n=>{const t=G.c(2),{path:e}=n;let o;return t[0]!==e?(o=s.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-1.5 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 px-4 py-1.5 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:[s.jsx(ns,{filePath:e,className:"size-3.5 shrink-0"}),s.jsx("span",{className:"typography-meta truncate font-mono text-foreground",children:e})]}),t[0]=e,t[1]=o):o=t[1],o},Ds=n=>{const t=G.c(11),{hunks:e,renderSideBySide:o,wrapLines:l}=n;let a;t[0]!==e?(a=yt(e),t[0]=e,t[1]=a):a=t[1];const h=a;let c;if(t[2]!==o||t[3]!==h||t[4]!==l){let m;t[6]!==o||t[7]!==l?(m=(p,f)=>s.jsxs("div",{children:[s.jsx(St,{path:p.path}),s.jsx(jt,{path:p.path,hunks:p.hunks,renderSideBySide:o,wrapLines:l})]},`${p.path}-${f}`),t[6]=o,t[7]=l,t[8]=m):m=t[8],c=h.map(m),t[2]=o,t[3]=h,t[4]=l,t[5]=c}else c=t[5];let g;return t[9]!==c?(g=s.jsx(s.Fragment,{children:c}),t[9]=c,t[10]=g):g=t[10],g},Bs=u.memo(function(t){const e=G.c(35),{view:o,activeStopId:l,scrollToStopId:a,onActiveStopChange:h,onScrollHandled:c,renderSideBySide:g,wrapLines:m}=t,{t:p}=ee(),f=u.useRef(null),[i,v]=u.useState(!1),b=u.useRef(null),w=u.useRef(null);let y,k;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{w.current!==null&&window.clearTimeout(w.current)},k=[],e[0]=y,e[1]=k):(y=e[0],k=e[1]),u.useEffect(y,k);let x,M;e[2]!==c||e[3]!==a?(x=()=>{if(!a)return;const R=document.getElementById(He(a));R&&(b.current=a,R.scrollIntoView({behavior:"auto",block:"start"}),w.current!==null&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>{b.current=null,w.current=null},250)),c()},M=[a,c],e[2]=c,e[3]=a,e[4]=x,e[5]=M):(x=e[4],M=e[5]),u.useEffect(x,M);let I;e[6]!==h?(I=R=>{const T=R.filter(Ws).sort($s)[0];if(!T)return;const q=T.target.getAttribute("data-stop-id");if(!q)return;const X=b.current;if(X){q===X&&(b.current=null);return}h(q)},e[6]=h,e[7]=I):I=e[7];const te=I;let W,se;e[8]!==te||e[9]!==o.stops?(W=()=>{const R=f.current;if(!R)return;const T=new IntersectionObserver(te,{root:R,rootMargin:"0px 0px -70% 0px",threshold:0});for(const q of o.stops){const X=document.getElementById(He(q.stop.id));X&&T.observe(X)}return()=>T.disconnect()},se=[te,o.stops],e[8]=te,e[9]=o.stops,e[10]=W,e[11]=se):(W=e[10],se=e[11]),u.useEffect(W,se);let O;e[12]!==o.uncoveredHunks?(O=yt(o.uncoveredHunks),e[12]=o.uncoveredHunks,e[13]=O):O=e[13];const z=O;let H;if(e[14]!==l||e[15]!==g||e[16]!==p||e[17]!==o.stops||e[18]!==m){let R;e[20]!==l||e[21]!==g||e[22]!==p||e[23]!==m?(R=T=>s.jsxs("section",{id:He(T.stop.id),"data-stop-id":T.stop.id,className:J("border-b border-border/60",l===T.stop.id&&"bg-interactive-selection/5"),children:[s.jsx(Ls,{stopView:T}),T.hunks.length>0?s.jsx(Ds,{hunks:T.hunks,renderSideBySide:g,wrapLines:m}):s.jsx("p",{className:"typography-meta px-4 pb-4 text-muted-foreground",children:p("walkthrough.stop.noCode")})]},T.stop.id),e[20]=l,e[21]=g,e[22]=p,e[23]=m,e[24]=R):R=e[24],H=o.stops.map(R),e[14]=l,e[15]=g,e[16]=p,e[17]=o.stops,e[18]=m,e[19]=H}else H=e[19];let $;e[25]!==g||e[26]!==p||e[27]!==i||e[28]!==z||e[29]!==o.uncoveredHunks.length||e[30]!==m?($=o.uncoveredHunks.length>0&&s.jsxs("section",{className:"border-b border-border/60",children:[s.jsxs(B,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-4 py-3",onClick:()=>v(Gs),"aria-expanded":i,children:[s.jsx(j,{name:i?"arrow-down-s":"arrow-right-s",className:"size-4 shrink-0"}),s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:p("walkthrough.uncovered.title",{count:o.uncoveredHunks.length})})]}),!i&&s.jsx("p",{className:"typography-meta px-4 pb-3 pl-10 text-muted-foreground",children:p("walkthrough.uncovered.description")}),i&&z.map((R,T)=>s.jsxs("div",{children:[s.jsx(St,{path:R.path}),s.jsx(jt,{path:R.path,hunks:R.hunks,renderSideBySide:g,wrapLines:m})]},`${R.path}-${T}`))]}),e[25]=g,e[26]=p,e[27]=i,e[28]=z,e[29]=o.uncoveredHunks.length,e[30]=m,e[31]=$):$=e[31];let oe;return e[32]!==$||e[33]!==H?(oe=s.jsxs("div",{ref:f,className:"min-h-0 flex-1 overflow-y-auto","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[H,$]}),e[32]=$,e[33]=H,e[34]=oe):oe=e[34],oe});function Ws(n){return n.isIntersecting}function $s(n,t){return n.boundingClientRect.top-t.boundingClientRect.top}function Gs(n){return!n}const qs={bug:"bug",wrench:"tools",path:"compass-3",flask:"flask",doc:"file-text",gear:"settings-3"},Fs=n=>{const t=G.c(30),{stopView:e,isActive:o,isVisited:l,onSelect:a,activeRef:h}=n,{t:c}=ee();let g;if(t[0]!==h||t[1]!==o||t[2]!==l||t[3]!==a||t[4]!==e.hunks||t[5]!==e.isStale||t[6]!==e.position||t[7]!==e.stop.title||t[8]!==c){const m=Rs(e.hunks),p=o&&"bg-interactive-selection text-interactive-selection-foreground";let f;t[10]!==p?(f=J("flex w-full flex-col gap-1 rounded px-2 py-1.5 text-left transition-colors","hover:bg-interactive-hover",p),t[10]=p,t[11]=f):f=t[11];const i=o?"bg-interactive-selection-foreground/20":l?"bg-status-success/15 text-status-success":"bg-surface-muted text-muted-foreground";let v;t[12]!==i?(v=J("typography-micro flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full px-1 tabular-nums",i),t[12]=i,t[13]=v):v=t[13];let b;t[14]!==o||t[15]!==l||t[16]!==e.position?(b=l&&!o?s.jsx(j,{name:"check",className:"size-2.5"}):e.position,t[14]=o,t[15]=l,t[16]=e.position,t[17]=b):b=t[17];let w;t[18]!==v||t[19]!==b?(w=s.jsx("span",{className:v,children:b}),t[18]=v,t[19]=b,t[20]=w):w=t[20];let y;t[21]!==e.stop.title?(y=s.jsx("span",{className:"typography-meta truncate font-medium",children:e.stop.title}),t[21]=e.stop.title,t[22]=y):y=t[22];let k;t[23]!==e.isStale||t[24]!==c?(k=e.isStale&&s.jsx(j,{name:"error-warning",className:"size-3 shrink-0 text-status-warning","aria-label":c("walkthrough.stop.staleShort")}),t[23]=e.isStale,t[24]=c,t[25]=k):k=t[25];let x;t[26]!==w||t[27]!==y||t[28]!==k?(x=s.jsxs("span",{className:"flex items-center gap-2",children:[w,y,k]}),t[26]=w,t[27]=y,t[28]=k,t[29]=x):x=t[29],g=s.jsx("li",{children:s.jsxs("button",{ref:o?h:void 0,type:"button",onClick:a,"aria-current":o?"step":void 0,className:f,children:[x,m.length>0&&s.jsxs("span",{className:"typography-micro flex flex-col gap-0.5 pl-6 text-muted-foreground",children:[m.slice(0,3).map(_s),m.length>3&&s.jsx("span",{children:c("walkthrough.toc.moreFiles",{count:m.length-3})})]})]})}),t[0]=h,t[1]=o,t[2]=l,t[3]=a,t[4]=e.hunks,t[5]=e.isStale,t[6]=e.position,t[7]=e.stop.title,t[8]=c,t[9]=g}else g=t[9];return g},Us=u.memo(function(t){const e=G.c(20),{view:o,activeStopId:l,visitedStopIds:a,onSelectStop:h,width:c}=t,{t:g}=ee(),m=u.useRef(null);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{m.current?.scrollIntoView({block:"nearest"})},e[0]=p):p=e[0];let f;e[1]!==l?(f=[l],e[1]=l,e[2]=f):f=e[2],u.useEffect(p,f);let i;e[3]!==c?(i={width:c},e[3]=c,e[4]=i):i=e[4];let v;e[5]!==o.walkthrough.focus?(v=o.walkthrough.focus&&s.jsx("p",{className:"typography-meta px-2 pb-3 pt-1 text-muted-foreground",children:o.walkthrough.focus}),e[5]=o.walkthrough.focus,e[6]=v):v=e[6];let b;e[7]!==l||e[8]!==h||e[9]!==o.chapters||e[10]!==a?(b=o.chapters.map(k=>{const{chapter:x,stops:M}=k;return s.jsxs("section",{className:"pb-3",children:[s.jsxs("h4",{className:"typography-micro flex items-center gap-1.5 px-2 py-1 font-semibold uppercase tracking-wide text-muted-foreground",children:[s.jsx(j,{name:qs[x.icon]??"file-text",className:"size-3 shrink-0"}),s.jsx("span",{className:"truncate",children:x.title})]}),s.jsx("ul",{className:"flex flex-col gap-0.5",children:M.map(I=>s.jsx(Fs,{stopView:I,isActive:l===I.stop.id,isVisited:a.has(I.stop.id),onSelect:()=>h(I.stop.id),activeRef:m},I.stop.id))})]},x.id)}),e[7]=l,e[8]=h,e[9]=o.chapters,e[10]=a,e[11]=b):b=e[11];let w;e[12]!==g||e[13]!==o.uncoveredHunks.length?(w=o.uncoveredHunks.length>0&&s.jsx("p",{className:"typography-micro mt-auto px-2 pt-3 text-muted-foreground",children:g("walkthrough.toc.uncovered",{count:o.uncoveredHunks.length})}),e[12]=g,e[13]=o.uncoveredHunks.length,e[14]=w):w=e[14];let y;return e[15]!==i||e[16]!==v||e[17]!==b||e[18]!==w?(y=s.jsxs("nav",{className:"flex shrink-0 flex-col overflow-y-auto border-r border-border/60 p-2",style:i,children:[v,b,w]}),e[15]=i,e[16]=v,e[17]=b,e[18]=w,e[19]=y):y=e[19],y});function _s(n){return s.jsx("span",{className:"truncate font-mono",children:n.path},n.path)}const Ks=["all","staged","working"],Vs="https://docs.aiworker.dev/walkthrough/",mt="typography-meta font-normal text-muted-foreground",gt=720,ne=180,Le=.5,Js=680,mn=({directory:n,visible:t=!0})=>{const{t:e,locale:o,locales:l,label:a}=ee(),h=u.useRef(null),[c,g]=u.useState(0),{rootIsGitRepo:m,gitDirectory:p,nestedRepos:f}=as(n||null,{enabled:t}),i=p??n;u.useEffect(()=>{const r=h.current;if(!r||typeof ResizeObserver>"u")return;const N=new ResizeObserver(A=>{g(A[0]?.contentRect.width??0)});return N.observe(r),()=>N.disconnect()},[]);const v=me(r=>r.walkthroughTocWidth),b=me(r=>r.setWalkthroughTocWidth),[w,y]=u.useState(!1),k=c===0||c>=gt,x=c>0&&c<Js,M=Math.min(Math.max(v,ne),Math.max(ne,(c||gt)*Le)),I=u.useCallback(r=>{r.preventDefault();const N=r.clientX,A=M,Z=Math.max(ne,(h.current?.clientWidth??0)*Le);y(!0);const at=ss=>{const os=Math.min(Z,Math.max(ne,A+ss.clientX-N));b(os)},be=()=>{y(!1),window.removeEventListener("pointermove",at),window.removeEventListener("pointerup",be),window.removeEventListener("pointercancel",be)};window.addEventListener("pointermove",at),window.addEventListener("pointerup",be),window.addEventListener("pointercancel",be)},[b,M]),te=u.useCallback(r=>{const N=r.shiftKey?40:10,A=r.key==="ArrowLeft"?-N:r.key==="ArrowRight"?N:0;if(A===0)return;r.preventDefault();const Z=Math.max(ne,(h.current?.clientWidth??0)*Le);b(Math.min(Z,Math.max(ne,M+A)))},[b,M]),[W,se]=u.useState("all"),[O,z]=u.useState(null),[H,$]=u.useState(null),[oe,R]=u.useState(null),[T,q]=u.useState(()=>new Set),X=me(r=>r.diffLayoutPreference),Nt=me(r=>r.diffWrapLines),Ct=X==="side-by-side",P=L(r=>r.requestedSource[i]),ie=L(r=>r.clearRequestedSource),Rt=me(r=>r.openContextPanelTab),Mt=is(i||null),ge=we(r=>r.runtimeKey),[It,Tt]=u.useState(0);u.useEffect(()=>ws(r=>{r===vs(i,ge)&&Tt(N=>N+1)}),[i,ge]);const Pt=ls(i||null),Et=hs(r=>r.setOverride),De=we(r=>r.ensureAll),{git:Be}=cs();u.useEffect(()=>{t&&i&&De(i,Be)},[i,De,Be,t]);const E=Mt?.current??null,fe=O?.directory===i&&O.kind==="commit"&&!P,Y=fe||P?.kind==="commit",F=ms(i||null,E,t&&Y,P?.kind==="commit"?P.hash:void 0),U=F.selectedCommit?.hash??(P?.kind==="commit"?P.hash:null),{base:le,resolved:At,revision:zt}=gs(i||null,E,t),_=u.useMemo(()=>!E||!le||le===E?null:{kind:"branch",baseRef:le,headRef:E},[le,E]),ve=O?.directory===i&&O.kind==="pr"&&!P,K=ve||P?.kind==="pr",re=fs(i||null,E,t&&K,P?.kind==="pr"?P:void 0),V=re.selectedSource,C=u.useMemo(()=>K&&V?V:Y&&U?{kind:"commit",hash:U}:P?.kind==="branch"?_??P:P??{kind:"working-tree",scope:W},[_,Y,K,P,W,U,V]),xe=O?.directory===i&&O.kind==="branch"&&!P,ye=xe||C.kind==="branch",We=xe||C.kind==="branch"&&!_,$e=fe||Y&&!U,Ge=K&&!V,ce=We||$e||Ge,Ot=u.useCallback(r=>{z(null),ie(i),se(r)},[ie,i]),d=L(r=>r.getEntry(i,C)),je=L(r=>r.load),qe=L(r=>r.generate),Ht=L(r=>r.cancel),Q=L(r=>r.requestSource);u.useEffect(()=>{!ve||!V||(Q(i,V),z(null))},[ve,i,Q,V]),u.useEffect(()=>{!xe||!_||(Q(i,_),z(null))},[_,xe,i,Q]),u.useEffect(()=>{!fe||!U||(Q(i,{kind:"commit",hash:U}),z(null))},[fe,i,Q,U]);const Lt=L(r=>r.selectModel),ue=L(r=>r.getSelectedModel(i,C)),Dt=L(r=>r.selectLanguage),Se=L(r=>r.getSelectedLanguage(i,C)),Ne=d.result?.language,D=Se&&l.includes(Se)?Se:Ne&&l.includes(Ne)?Ne:o,Bt=C.kind==="branch"?zt:"",Fe=C.kind==="pr"?It:0,Ue=u.useRef(null);u.useEffect(()=>{if(!(!t||ce)){if(C.kind==="pr"){const r=JSON.stringify([ge,i,C,D,ue,Fe]);if(Ue.current===r)return;Ue.current=r}je(i,C,{language:D})}},[D,ce,i,je,C,ue,Bt,t,ge,Fe]);const S=u.useMemo(()=>ce?null:Cs(d.result),[ce,d.result]),Ce=d.result?.generatedAt,_e=u.useRef(void 0);u.useEffect(()=>{_e.current!==Ce&&(_e.current=Ce,q(new Set),$(S?.stops[0]?.stop.id??null))},[Ce,S]);const Re=u.useCallback(r=>{$(r),q(N=>{if(N.has(r))return N;const A=new Set(N);return A.add(r),A})},[]),Me=u.useCallback(r=>{Re(r),R(r)},[Re]),Ke=u.useCallback(r=>{if(!S||S.stops.length===0)return;const N=S.stops.findIndex(Z=>Z.stop.id===H),A=Math.min(S.stops.length-1,Math.max(0,(N<0?0:N)+r));Me(S.stops[A].stop.id)},[H,Me,S]),[Wt,Ve]=u.useState(!1),[$t,Je]=u.useState(!1),Gt=K?"pr":Y?"commit":ye?"branch":C.kind==="working-tree"?C.scope:C.kind,qt=K?e("session.githubIntegration.tabs.pullRequests"):Y?e("commitComparison.mode"):ye?e("walkthrough.scope.branch"):C.kind==="pr"?e("walkthrough.scope.pullRequest",{number:C.number}):e(W==="all"?"walkthrough.scope.all":W==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working"),Xe=ft(r=>r.modelsMetadata),[de,Ft]=u.useState(void 0),Ie=r=>!r||de===void 0?!1:de.includes(r),Ut=d.readiness?.model&&d.readiness.model.hasLogin!==!1&&Ie(d.readiness.model.providerID)?`${d.readiness.model.providerID}/${d.readiness.model.modelID}`:void 0,_t=d.result?.model&&Ie(d.result.model.providerID)?`${d.result.model.providerID}/${d.result.model.modelID}`:void 0,ke=(ue&&Ie(ue.split("/")[0])?ue:void 0)??_t??Ut,[Kt,...Vt]=(ke??"").split("/"),Ye=Vt.join("/");u.useEffect(()=>{if(de!==void 0)return;let r=!1;return(async()=>{try{const N=await vt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const A=await N.json().catch(()=>null);!r&&Array.isArray(A?.authenticatedProviders)&&Ft(A.authenticatedProviders.filter(Z=>typeof Z=="string"))}catch{}})(),()=>{r=!0}},[de]);const Jt=u.useCallback((r,N)=>Xe.get(`${r}/${N}`)?.structured_output!==!1,[Xe]),Qe=d.status==="generating",Ze=d.result?.model?`${d.result.model.providerID}/${d.result.model.modelID}`:void 0,Te=d.result?.language,Pe=Te&&l.includes(Te)?Te:void 0,et=d.status==="ready"&&!!S,Ee=et&&!!Pe&&Pe!==D,tt=et&&!!Ze&&!!ke&&Ze!==ke,st=Os(d.stage,d.status==="generating"),ot=u.useRef(!1),rt=u.useRef(d.status);u.useEffect(()=>{rt.current!=="generating"&&d.status==="generating"&&(ot.current=!S),rt.current=d.status},[d.status,S]);const Xt=ot.current&&(d.status==="generating"||st.holding),Ae=d.error?.code==="context-too-small"||d.error?.code==="structured-output-unsupported"||d.error?.code==="no-model"||d.error?.code==="empty-diff"||d.error?.code==="only-generated"||d.error?.code==="output-exhausted"||d.error?.code==="server-unsupported"?d.error.code:d.readiness&&!d.readiness.ready&&!S&&d.readiness.reason!=="no-provider-login"?d.readiness.reason:void 0,Yt=d.error?.model??d.readiness?.model,Qt=d.error?.requiredChars??d.readiness?.requiredChars,Zt=d.error?.availableChars??d.readiness?.availableChars,pe=ce||!ke||!!(d.readiness&&!d.readiness.ready),ze=u.useCallback(r=>{pe||qe(i,C,{force:r,language:D})},[D,i,qe,pe,C]),nt=us(p||null),es=we(r=>r.ensureNestedRepos),ts=we(r=>r.selectNestedRepo);return m===!1&&nt!==!0?s.jsx(Ss,{rootIsGitRepo:m,resolvedIsGitRepo:nt,nestedRepos:f,onRetryDiscovery:()=>{n&&es(n,{force:!0})}}):s.jsxs("div",{ref:h,className:"flex h-full min-h-0 flex-col",children:[s.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[m===!1&&Array.isArray(f)&&f.length>0?s.jsx(Ns,{repositories:f,selectedRepository:p??null,onSelectRepository:r=>{n&&ts(n,r)},repositoryRoot:n??void 0}):null,s.jsxs(it,{open:Wt,onOpenChange:Ve,children:[s.jsx(lt,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.scope.selectorAria"),children:[s.jsx("span",{className:"whitespace-nowrap",children:qt}),s.jsx(j,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})}),s.jsx(ct,{align:"start",className:"w-48",children:s.jsxs(ut,{value:Gt,onValueChange:r=>{if(Ve(!1),r==="commit"){ie(i),z({directory:i,kind:"commit"});return}if(r==="branch"){_?(z(null),Q(i,_)):(ie(i),z({directory:i,kind:"branch"}));return}if(r==="pr"){ie(i),z({directory:i,kind:"pr"});return}Ot(r)},children:[s.jsx(dt,{className:mt,children:e("walkthrough.scope.group.workingTree")}),Ks.map(r=>s.jsx(he,{value:r,children:e(r==="all"?"walkthrough.scope.all":r==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working")},r)),E&&s.jsxs(s.Fragment,{children:[s.jsx(pt,{}),s.jsx(he,{value:"branch",children:e("walkthrough.scope.branch")})]}),s.jsx(pt,{}),s.jsx(he,{value:"commit",children:e("commitComparison.mode")}),s.jsx(he,{value:"pr",children:e("session.githubIntegration.tabs.pullRequests")})]})})]}),ye&&s.jsx(xs,{branches:Pt?.all??[],currentBranch:E,base:le,onSelect:r=>{i&&E&&Et(i,E,r)}},JSON.stringify([i,E])),Y&&s.jsx(ks,{commits:F.commits,selectedHash:U,loading:F.loading,error:F.error,onSelect:F.select,onRefresh:()=>{F.refresh()}},JSON.stringify([i,E])),K&&s.jsx(ht,{comparison:re},JSON.stringify([i,E])),s.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-1",children:[K&&V&&s.jsxs(B,{variant:"ghost",size:"sm","aria-label":e("contextPanel.mode.diff"),title:e("contextPanel.mode.diff"),onClick:()=>Rt(n,{mode:"diff",diffScope:"pr"}),children:[s.jsx(j,{name:"arrow-left-right",className:"size-4"}),!x&&e("contextPanel.mode.diff")]}),s.jsxs(kt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(B,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.help.guide"),onClick:()=>{ds(Vs)},children:s.jsx(j,{name:"question",className:"size-4"})})}),s.jsx(wt,{children:s.jsx("p",{className:"typography-micro leading-tight",children:e("walkthrough.help.guide")})})]}),s.jsxs(it,{open:$t,onOpenChange:Je,children:[s.jsx(lt,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 min-w-0 flex-shrink items-center gap-1.5 rounded-md px-2 typography-ui-label text-muted-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.language.selectorAria"),title:x?a(D):void 0,children:[s.jsx(j,{name:"global",className:"size-4 flex-shrink-0 opacity-70"}),!x&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"truncate",children:a(D)}),s.jsx(j,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})]})}),s.jsxs(ct,{align:"end",className:"w-48",children:[s.jsx(dt,{className:mt,children:e("walkthrough.language.menuLabel")}),s.jsx(ut,{value:D,onValueChange:r=>{Je(!1),Dt(i,C,r)},children:l.map(r=>s.jsx(he,{value:r,children:a(r)},r))})]})]}),s.jsx(xt,{providerId:Kt??"",modelId:Ye,onChange:(r,N)=>{Lt(i,C,r&&N?`${r}/${N}`:null)},allowedProviderIds:de??[],isModelAllowed:Jt,tooltipsEnabled:!1,dropdownPortalToBody:!0,compact:x,className:J("h-8 min-w-0",!x&&"max-w-48")}),S&&s.jsxs(s.Fragment,{children:[s.jsx(B,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.previous"),onClick:()=>Ke(-1),children:s.jsx(j,{name:"arrow-right-s",className:"size-4 rotate-180"})}),s.jsx(B,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.next"),onClick:()=>Ke(1),children:s.jsx(j,{name:"arrow-right-s",className:"size-4"})})]}),Qe?s.jsx(B,{type:"button",variant:"outline",size:"sm","aria-label":x?e("walkthrough.action.cancel"):void 0,title:x?e("walkthrough.action.cancel"):void 0,onClick:()=>Ht(i,C),children:x?s.jsx(j,{name:"stop",className:"size-3.5"}):e("walkthrough.action.cancel")}):s.jsxs(B,{type:"button",variant:"outline",size:"sm",className:pe?"border-border text-muted-foreground":ys,disabled:pe,"aria-label":x?e(S?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,title:x?e(S?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,onClick:()=>ze(!!S),children:[s.jsx(j,{name:S?"refresh":"route",className:"size-3.5"}),!x&&e(S?"walkthrough.action.regenerate":"walkthrough.action.generate")]})]})]}),d.status==="generating"&&S&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(j,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:d.stage==="collecting"?e("walkthrough.stage.collecting"):d.stage==="assembling"?e("walkthrough.stage.assembling"):e("walkthrough.stage.asking")})]}),(Ee||tt)&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(j,{name:"information",className:"size-4 shrink-0 text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:Ee&&tt?e("walkthrough.missing.languageAndModel"):Ee?e("walkthrough.missing.language",{requested:a(D),shown:a(Pe)}):e("walkthrough.missing.model",{model:Ye})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",disabled:pe,onClick:()=>ze(!1),children:e("walkthrough.action.generate")})]}),S?.isStale&&d.status!=="generating"&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-status-warning/10 px-3 py-2",children:[s.jsx(j,{name:"error-warning",className:"size-4 shrink-0 text-status-warning"}),s.jsx("span",{className:"typography-meta text-foreground",children:e("walkthrough.stale.banner",{count:S.staleStopCount})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",disabled:Qe,onClick:()=>ze(!0),children:e("walkthrough.action.regenerate")})]}),d.error&&!Ae&&d.error.code!=="no-provider-login"&&s.jsxs("div",{className:"flex shrink-0 items-start gap-2 border-b border-border/60 bg-status-error/10 px-3 py-2",children:[s.jsx(j,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-status-error"}),s.jsx("span",{className:"typography-meta line-clamp-2 text-foreground",title:d.error.message,children:d.error.message})]}),s.jsx("div",{className:J("flex min-h-0 flex-1",k?"flex-row":"flex-col"),children:Ge?s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:re.error??(re.loading?e("session.githubPrPicker.loading.pullRequests"):e("pullRequestComparison.select"))}),!re.loading&&s.jsx(ht,{comparison:re})]}):$e?s.jsx("div",{className:"flex flex-1 items-center justify-center gap-2 p-8 typography-meta text-muted-foreground",children:F.loading?s.jsx(j,{name:"loader-4",className:"size-6 animate-spin"}):F.error??e("commitComparison.noCommits")}):We?s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:!At&&E?s.jsx(j,{name:"loader-4",className:"size-6 animate-spin text-muted-foreground"}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.pr.toast.baseBranchRequired")})}):Ae?s.jsx(Ts,{reason:Ae,model:Yt,requiredChars:Qt,availableChars:Zt,onRetry:()=>{je(i,C)}}):Xt?s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8",children:s.jsx(Es,{progress:st})}):S?s.jsxs(s.Fragment,{children:[k&&s.jsxs(s.Fragment,{children:[s.jsx(Us,{view:S,activeStopId:H,visitedStopIds:T,onSelectStop:Me,width:M}),s.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":e("walkthrough.toc.resize"),tabIndex:0,onPointerDown:I,onKeyDown:te,className:J("group relative w-1 shrink-0 cursor-col-resize","before:absolute before:inset-y-0 before:-left-1 before:-right-1 before:content-['']","hover:bg-interactive-selection focus-visible:bg-interactive-selection focus-visible:outline-none",w&&"bg-interactive-selection")})]}),s.jsx(Bs,{view:S,activeStopId:H,scrollToStopId:oe,onActiveStopChange:Re,onScrollHandled:()=>R(null),renderSideBySide:Ct,wrapLines:Nt})]}):s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:d.status==="loading"?s.jsx(j,{name:"loader-4",className:"size-6 animate-spin text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(j,{name:"route",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:e("walkthrough.empty.title")}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:e("walkthrough.empty.description")})]})})})]})};export{mn as WalkthroughView};
|