@opentig/cli 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +58 -7
- package/dist/chunks/{cli-bEPXlEpH.mjs → cli-DaYybBfs.mjs} +234 -170
- package/dist/chunks/cli-service-CDd3ZvGV.mjs +237 -0
- package/dist/client/assets/App-C7Yf3r-l.js +118 -0
- package/dist/client/assets/{CreatePullRequestDialog-NPqtWmYL.js → CreatePullRequestDialog-CGnY6nrw.js} +2 -2
- package/dist/client/assets/{DiffWorkspace-CZH8jCtn.js → DiffWorkspace-1ZAh7eFX.js} +6 -6
- package/dist/client/assets/EditableFileViewer-DOnxE6ty.js +1 -0
- package/dist/client/assets/{File-C25AAfq1.js → File-DM0fcPqi.js} +1 -1
- package/dist/client/assets/{FilesView-C6qX7ixR.js → FilesView-BuTZiUd4.js} +1 -1
- package/dist/client/assets/{GitHubAvatar-DV6lI4Jh.js → GitHubAvatar-BIZ8KlZ9.js} +1 -1
- package/dist/client/assets/HistoryView-BTo2h2ee.js +1 -0
- package/dist/client/assets/{HtmlFileViewer-CiPZFmIx.js → HtmlFileViewer-tEtrcHdG.js} +1 -1
- package/dist/client/assets/{IconEdit-DZPhGn6H.js → IconEdit-DtVD7NDP.js} +1 -1
- package/dist/client/assets/{IconFolderPlus-CE1ATVt-.js → IconFolderPlus-D5cPTAyD.js} +1 -1
- package/dist/client/assets/ImageFileViewer-C56bQ88S.js +1 -0
- package/dist/client/assets/{LocalRefsDialog-DIFaZUiQ.js → LocalRefsDialog-DwhpiSyu.js} +1 -1
- package/dist/client/assets/{MarkdownFileViewer-Y9tvTC3N.js → MarkdownFileViewer-BxQfoNnS.js} +2 -2
- package/dist/client/assets/{PairingPage-rJKAimg3.js → PairingPage-Cu1KraeJ.js} +1 -1
- package/dist/client/assets/{PierreDiffViewer-BRQK_cuH.js → PierreDiffViewer-B9IrAdjM.js} +1 -1
- package/dist/client/assets/PierreEditBoundary-DDJlRbaP.js +2 -0
- package/dist/client/assets/{PierreWorkerPool-CRVJ90kq.js → PierreWorkerPool-BJhmuZSy.js} +1 -1
- package/dist/client/assets/PullRequestDiff-Di1_Wv1o.js +1 -0
- package/dist/client/assets/PullRequestViewer-CuH0Ze12.js +2 -0
- package/dist/client/assets/PullRequestsView-DRKuy94k.js +1 -0
- package/dist/client/assets/{QuickOpenDialog-CciIWIcs.js → QuickOpenDialog-DSdrgS2H.js} +1 -1
- package/dist/client/assets/RepositoryProjectsDialog-CWcakQRC.js +1 -0
- package/dist/client/assets/SearchView-Btqv-BZZ.js +1 -0
- package/dist/client/assets/{SettingsDialog-B0XwVWYT.js → SettingsDialog-CV7hRbtK.js} +2 -2
- package/dist/client/assets/Viewer-bchsRyMu.js +3 -0
- package/dist/client/assets/{abnfDiagram-N423BO3Z-DRTxjQR7.js → abnfDiagram-N423BO3Z-D6JAOs-X.js} +1 -1
- package/dist/client/assets/{arc-DlZI_By6.js → arc-YncG-7Bc.js} +1 -1
- package/dist/client/assets/{architectureDiagram-T3A2C74G-BpcQblyb.js → architectureDiagram-T3A2C74G-Ckf8dhax.js} +1 -1
- package/dist/client/assets/base-ui-D4MeJpa3.js +1 -0
- package/dist/client/assets/{blockDiagram-VBNYF7ZC-BF55JK7V.js → blockDiagram-VBNYF7ZC-CGQa9zHO.js} +1 -1
- package/dist/client/assets/{c4Diagram-5PPSVZJV-CkQ8c1Fd.js → c4Diagram-5PPSVZJV-Ctgat2YZ.js} +1 -1
- package/dist/client/assets/channel-B31JCSE_.js +1 -0
- package/dist/client/assets/checkbox-D5IGxs1d.js +1 -0
- package/dist/client/assets/{chunk-2GRJ4B5K-BsVfgXSJ.js → chunk-2GRJ4B5K-CyDC0FQq.js} +1 -1
- package/dist/client/assets/{chunk-2Q5K7J3B-hYvR7LDf.js → chunk-2Q5K7J3B-DqYRVN1X.js} +1 -1
- package/dist/client/assets/{chunk-5RXB4S5H-B2TcxiXR.js → chunk-5RXB4S5H-BtrE-Jqe.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-TDJFncVJ.js → chunk-5VM5RSS4-CEVyxEEH.js} +1 -1
- package/dist/client/assets/{chunk-6Q2QTUOP-BDdSa8Zj.js → chunk-6Q2QTUOP-CR_RRfTb.js} +1 -1
- package/dist/client/assets/{chunk-GF5L2VYU-CUHPmM86.js → chunk-GF5L2VYU-Uoc_Vpub.js} +1 -1
- package/dist/client/assets/{chunk-JWPE2WC7-Pq05eTDs.js → chunk-JWPE2WC7-BAhDzsCx.js} +1 -1
- package/dist/client/assets/{chunk-KBJHAD2P-QSlaIrVy.js → chunk-KBJHAD2P-DkGEUlle.js} +1 -1
- package/dist/client/assets/{chunk-RYQCIY6F-C0P7HEQg.js → chunk-RYQCIY6F-doFXXAJb.js} +1 -1
- package/dist/client/assets/{chunk-XXDRQBXY-C_oHIOR7.js → chunk-XXDRQBXY-B44pCuJx.js} +1 -1
- package/dist/client/assets/classDiagram-JCYQIIEL-C6tU-sLq.js +1 -0
- package/dist/client/assets/classDiagram-v2-OCEON4UE-C6tU-sLq.js +1 -0
- package/dist/client/assets/{cose-bilkent-JH36ORCC-Du6jXfCO.js → cose-bilkent-JH36ORCC-CymnJ1xN.js} +1 -1
- package/dist/client/assets/{cynefin-VYW2F7L2-CTUvB8CJ.js → cynefin-VYW2F7L2-BT5dARHp.js} +1 -1
- package/dist/client/assets/{cynefinDiagram-MW4NZA55-BLRqmW6C.js → cynefinDiagram-MW4NZA55-DVrhZ1A4.js} +1 -1
- package/dist/client/assets/{dagre-VZM6K2ZE-DTAlXx2k.js → dagre-VZM6K2ZE-BET0T1KQ.js} +1 -1
- package/dist/client/assets/{diagram-7IWD3JNH-Coh1c4kx.js → diagram-7IWD3JNH-mIl4bvgD.js} +1 -1
- package/dist/client/assets/{diagram-B4RE2ZJO-TahBzLDX.js → diagram-B4RE2ZJO-DKSi3zok.js} +1 -1
- package/dist/client/assets/{diagram-LBJQPF4R-2uwXPdqa.js → diagram-LBJQPF4R-DFzvqR_V.js} +1 -1
- package/dist/client/assets/{diagram-Q27KOJAE-Bm4UNuoF.js → diagram-Q27KOJAE-C8UUiNSc.js} +1 -1
- package/dist/client/assets/{diagram-UB23O5K3-dWga-ccy.js → diagram-UB23O5K3-CYuQnggB.js} +1 -1
- package/dist/client/assets/{ebnfDiagram-BXEA7PRR-D0IK6JUi.js → ebnfDiagram-BXEA7PRR-orsOZEt3.js} +1 -1
- package/dist/client/assets/edit-ready-context-D77R8XU8.js +1 -0
- package/dist/client/assets/{erDiagram-JOGREHBK-DouKd_mX.js → erDiagram-JOGREHBK-BPxNY3Or.js} +1 -1
- package/dist/client/assets/{flowDiagram-UKHOOZJN-DQQX82AJ.js → flowDiagram-UKHOOZJN-Dj_tbpt_.js} +1 -1
- package/dist/client/assets/{ganttDiagram-PKOTCBZU-CbvAYRQc.js → ganttDiagram-PKOTCBZU-BhG_1m3O.js} +1 -1
- package/dist/client/assets/{gh-utils-XOjL-WGw.js → gh-utils-CR5JRkW2.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-DS77QQ5N-D7cqbpF-.js → gitGraphDiagram-DS77QQ5N-B6i118FC.js} +1 -1
- package/dist/client/assets/{index-Bm8fY0Qs.css → index-CE9Jcx4e.css} +1 -1
- package/dist/client/assets/index-C_D1kOlX.js +3 -0
- package/dist/client/assets/{infoDiagram-6WML65LV-C0NfpA-J.js → infoDiagram-6WML65LV-DhHBZSVb.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-WSZJBQD7-DhIW58so.js → ishikawaDiagram-WSZJBQD7-6Vd6XOG_.js} +1 -1
- package/dist/client/assets/{journeyDiagram-NVQOT4AX-DqZZm_oH.js → journeyDiagram-NVQOT4AX-uH71A9mr.js} +1 -1
- package/dist/client/assets/{kanban-definition-27J2QSJJ-DpSYxBwt.js → kanban-definition-27J2QSJJ-DbxRwp0h.js} +1 -1
- package/dist/client/assets/{linear-DRxvRS4v.js → linear-CFzmLtpp.js} +1 -1
- package/dist/client/assets/{markdown-ChhkSSkz.css → markdown-BpzjXclZ.css} +1 -1
- package/dist/client/assets/{mermaid.core-Bz1ouG4e.js → mermaid.core-B_Mv_eHi.js} +4 -4
- package/dist/client/assets/{mindmap-definition-FAOFIHXS-ohtsO4nF.js → mindmap-definition-FAOFIHXS-DQf1s9U3.js} +1 -1
- package/dist/client/assets/{pegDiagram-VL7TDLO6-BmDfUXjC.js → pegDiagram-VL7TDLO6-BxFVTcDJ.js} +1 -1
- package/dist/client/assets/{pieDiagram-7S7Q4E2Y-CUADuvir.js → pieDiagram-7S7Q4E2Y-CCNbxGSk.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-CIZ2JOQS-BGGXYgGq.js → quadrantDiagram-CIZ2JOQS-BVhzcmm1.js} +1 -1
- package/dist/client/assets/{railroadDiagram-AXF67PYL-CuQocJeb.js → railroadDiagram-AXF67PYL-D3R2-3Og.js} +1 -1
- package/dist/client/assets/{render-markdown-BnNqckxy.js → render-markdown-DcHo7ihS.js} +6 -6
- package/dist/client/assets/{requirementDiagram-LRYGKXZP-7w9ufPrL.js → requirementDiagram-LRYGKXZP-B-NkzvnF.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-W5VNT64P-DWDWhnZJ.js → sankeyDiagram-W5VNT64P-BRpIzFiP.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-SI44F4Z6-BQAnExHF.js → sequenceDiagram-SI44F4Z6-B7cBRL6x.js} +1 -1
- package/dist/client/assets/{sizeCapture-X5ZJPWSS-BC2GpN9p.js → sizeCapture-X5ZJPWSS-BZ6DbjJ6.js} +1 -1
- package/dist/client/assets/{stateDiagram-OKZ733FA-vXwPDk5C.js → stateDiagram-OKZ733FA-x8ChPNdG.js} +1 -1
- package/dist/client/assets/stateDiagram-v2-UEYNNEHI-BlYlvm69.js +1 -0
- package/dist/client/assets/{swimlanes-SLNWSIFB-DdBBGgwS.js → swimlanes-SLNWSIFB-DR21moSS.js} +2 -2
- package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-DbXYPHRv.js +8 -0
- package/dist/client/assets/{tanstack-BEeM5REq.js → tanstack-Bsd5UOY4.js} +1 -1
- package/dist/client/assets/{timeline-definition-Z64GVDOM-CcXzq7ZH.js → timeline-definition-Z64GVDOM-UlAkswoH.js} +1 -1
- package/dist/client/assets/{vennDiagram-T6HMQDX7-PiBQGztV.js → vennDiagram-T6HMQDX7-91kBYEFr.js} +1 -1
- package/dist/client/assets/viewer-tabs-BHvOJKLx.js +1 -0
- package/dist/client/assets/{wardleyDiagram-T6FBY63Y-R9-CuOPS.js → wardleyDiagram-T6FBY63Y-CqAHibOn.js} +1 -1
- package/dist/client/assets/{xychartDiagram-ELKLHX3M-CrK1rvFm.js → xychartDiagram-ELKLHX3M-BMFs9l78.js} +1 -1
- package/dist/client/index.html +4 -4
- package/dist/dev.mjs +4 -3
- package/dist/manifest.json +1 -1
- package/dist/server.mjs +59 -3
- package/dist/service-update.mjs +77 -0
- package/package.json +1 -1
- package/dist/client/assets/App-1nMyZ0Eq.js +0 -118
- package/dist/client/assets/EditableFileViewer-4ap_dRdR.js +0 -1
- package/dist/client/assets/HistoryView-CgKY4Sjl.js +0 -1
- package/dist/client/assets/ImageFileViewer-RAXxHOBt.js +0 -1
- package/dist/client/assets/PierreEditBoundary-YYf1awXS.js +0 -2
- package/dist/client/assets/PullRequestDiff-BWdKV4LM.js +0 -1
- package/dist/client/assets/PullRequestViewer-6MhtdrJc.js +0 -2
- package/dist/client/assets/PullRequestsView-CJy2RRm7.js +0 -1
- package/dist/client/assets/RepositoryProjectsDialog-c_ZJ0g3C.js +0 -1
- package/dist/client/assets/SearchView-D5NpA3kT.js +0 -1
- package/dist/client/assets/Viewer-u1esMhLs.js +0 -3
- package/dist/client/assets/base-ui-BxmCGIFY.js +0 -1
- package/dist/client/assets/channel-D-dDbEF9.js +0 -1
- package/dist/client/assets/checkbox-vpy6b6Uq.js +0 -1
- package/dist/client/assets/classDiagram-JCYQIIEL-DHG_NsyB.js +0 -1
- package/dist/client/assets/classDiagram-v2-OCEON4UE-DHG_NsyB.js +0 -1
- package/dist/client/assets/index-DwuduZw_.js +0 -3
- package/dist/client/assets/stateDiagram-v2-UEYNNEHI-BA-7Q81g.js +0 -1
- package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-BSDBQ9JF.js +0 -8
- package/dist/client/assets/viewer-tabs-B_boC13j.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as k,r as ee}from"./react-rd22PHbN.js";import{a7 as q,a6 as xe,a8 as gn,G as mn,a9 as Cn,aa as Sn,ab as
|
|
1
|
+
import{j as k,r as ee}from"./react-rd22PHbN.js";import{a7 as q,a6 as xe,a8 as gn,G as mn,a9 as Cn,aa as Sn,ab as Ze,ac as xn,ad as ve,ae as ye,$ as ge,af as ke,ag as se,a0 as Zt,q as F,a5 as Pe,ah as Ln,b as $e,g as kn,ai as ze,aj as ce,e as vn,n as yn,v as Hn,w as wn,ak as me,f as Qt,h as pt,x as En,al as An,am as Ce,an as Rn,m as V,t as bn,s as Jt,l as gt,p as Tn,y as Re,o as Mn,z as Dn,R as In,I as Fn,A as mt,B as Nn,C as Pn,ao as en,ap as zn,aq as Ct,D as Bn,E as On,Q as St,S as Un,F as Vn,H as jn,J as xt,K as $n,L as Gn,N as Lt,M as Ge,T as Wn,U as _n,d as tn,W as Kn,X as We,Y as qn,_ as Xn,Z as nn,a1 as Yn,u as Zn,a2 as Qn,a3 as kt,a4 as Jn,ar as ei,as as ti,a as ni,V as ii,O as si}from"./PierreWorkerPool-BJhmuZSy.js";import{C as sn,g as Se,S as ri,D as re,y as oi,z as ai,a as _e,b as vt,v as li,E as di,w as hi,H as ui,c as ci,d as fi,i as pi,f as gi}from"./platform-BMNQ8V5r.js";import{t as oe}from"./one-light-CoLDteqg.js";import{u as mi,a as Ci}from"./EditContext-CvJWfVl1.js";import{c as He,T as Qe,a as Je,b as et,B as Si}from"./index-C_D1kOlX.js";import{T as yt,P as xi,a7 as Li,I as ki}from"./App-C7Yf3r-l.js";const vi=[["path",{d:"M16 4l4 0l0 4",key:"svg-0"}],["path",{d:"M14 10l6 -6",key:"svg-1"}],["path",{d:"M8 20l-4 0l0 -4",key:"svg-2"}],["path",{d:"M4 20l6 -6",key:"svg-3"}],["path",{d:"M16 20l4 0l0 -4",key:"svg-4"}],["path",{d:"M14 14l6 6",key:"svg-5"}],["path",{d:"M8 4l-4 0l0 4",key:"svg-6"}],["path",{d:"M4 4l6 6",key:"svg-7"}]],yi=He("outline","arrows-maximize","ArrowsMaximize",vi);const Hi=[["path",{d:"M5 9l4 0l0 -4",key:"svg-0"}],["path",{d:"M3 3l6 6",key:"svg-1"}],["path",{d:"M5 15l4 0l0 4",key:"svg-2"}],["path",{d:"M3 21l6 -6",key:"svg-3"}],["path",{d:"M19 9l-4 0l0 -4",key:"svg-4"}],["path",{d:"M15 9l6 -6",key:"svg-5"}],["path",{d:"M19 15l-4 0l0 4",key:"svg-6"}],["path",{d:"M15 15l6 6",key:"svg-7"}]],wi=He("outline","arrows-minimize","ArrowsMinimize",Hi);const Ei=[["path",{d:"M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12",key:"svg-0"}],["path",{d:"M12 4l0 16",key:"svg-1"}]],Ai=He("outline","layout-columns","LayoutColumns",Ei);const Ri=[["path",{d:"M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12",key:"svg-0"}],["path",{d:"M4 12l16 0",key:"svg-1"}]],bi=He("outline","layout-rows","LayoutRows",Ri);const Ti=[["path",{d:"M4 6l16 0",key:"svg-0"}],["path",{d:"M4 18l5 0",key:"svg-1"}],["path",{d:"M4 12h13a3 3 0 0 1 0 6h-4l2 -2m0 4l-2 -2",key:"svg-2"}]],Mi=He("outline","text-wrap","TextWrap",Ti);function Di({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function Ii(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:Ui(n,e.startContentIndex)}}function kr(e,t=6){t=Math.max(t,1);const n={deletionLines:[],additionLines:[],conflictStack:[],conflictBuilders:[],actions:[],hunks:[],nextConflictIndex:0,splitLineCount:0,unifiedLineCount:0,lastHunkEnd:0,activeHunk:void 0,maxContextLines:t,maxContextLines2:t*2},i=e.contents,s=i.length;if(s>0){let u=0,c=0,f=i.indexOf(`
|
|
2
2
|
`,u);for(;f!==-1;)Ht(n,i.slice(u,f+1),c),u=f+1,c++,f=i.indexOf(`
|
|
3
3
|
`,u);u<s&&Ht(n,i.slice(u),c)}if(n.conflictStack.length>0)throw new Error("parseMergeConflictDiffFromFile: unfinished merge conflict marker stack");n.activeHunk!=null&&n.activeHunk.hunkContent.length>0&&(ut(n,n.activeHunk,"trailing"),an(n));for(let u=0;u<n.conflictBuilders.length;u++){const c=n.conflictBuilders[u];if(c==null||!c.completed)throw new Error(`parseMergeConflictDiffFromFile: failed to build merge conflict action ${u}`)}if(n.hunks.length>0&&n.additionLines.length>0&&n.deletionLines.length>0){const u=n.hunks[n.hunks.length-1],c=Math.max(n.additionLines.length-q(u.additionStart,u.additionCount),0);n.splitLineCount+=c,n.unifiedLineCount+=c}const r=n.deletionLines.join(""),o=n.additionLines.join(""),a=Tt(e,"current",r),l=Tt(e,"incoming",o);let d="change";o===""?d="deleted":r===""&&(d="new");const h={name:e.name,prevName:void 0,type:d,hunks:n.hunks,splitLineCount:n.splitLineCount,unifiedLineCount:n.unifiedLineCount,isPartial:!1,deletionLines:n.deletionLines,additionLines:n.additionLines,cacheKey:e.cacheKey!=null?`${e.cacheKey}:merge-conflict-diff`:void 0};return{fileDiff:h,currentFile:a,incomingFile:l,actions:n.actions,markerRows:Oi(h,n.actions)}}function Ht(e,t,n){const i=e.conflictStack[e.conflictStack.length-1];if(i==null){if(t.length>=7&&t.charCodeAt(0)===60&&bt(t)==="start"){At(e,t,n);return}wt(e,t);return}const s=bt(t);if(s==="start"){At(e,t,n);return}if(s==="base"){i.stage="base",i.baseMarkerLineIndex=n,i.markerLines.base=t;return}if(s==="separator"){i.stage="incoming",i.separatorLineIndex=n,i.markerLines.separator=t;return}if(s==="end"){const r=e.conflictStack.pop();if(r==null)throw new Error("parseMergeConflictDiffFromFile: encountered end marker before start marker");Pi(e,r,n,t);return}i.stage==="current"?Et(e,"deletion",t,i.conflictIndex,"current"):i.stage==="base"?wt(e,t,i.conflictIndex):Et(e,"addition",t,i.conflictIndex,"incoming")}function rn(e){return e.activeHunk??=ln(e.additionLines.length+1,e.deletionLines.length+1),e.activeHunk}function on(e,t,n,i){const s=e.conflictBuilders[t];if(s==null)throw new Error(`parseMergeConflictDiffFromFile: failed to locate conflict action ${t}`);const r=s.action,o=e.hunks.length;if(r.hunkIndex<0)r.hunkIndex=o;else if(r.hunkIndex!==o)throw new Error(`parseMergeConflictDiffFromFile: conflict ${t} spans multiple hunks and cannot be anchored`);if(r.startContentIndex<0&&(r.startContentIndex=i),r.endContentIndex=i,r.endMarkerContentIndex=i,n==="current"){r.currentContentIndex??=i;return}if(n==="base"){r.baseContentIndex??=i;return}r.incomingContentIndex=i}function Fi(e,t,n,i){const s=e.hunkContent,r=s[s.length-1];return r?.type==="change"?(t==="addition"?r.additions++:r.deletions++,s.length-1):(s.push({type:"change",additions:t==="addition"?1:0,deletions:t==="deletion"?1:0,additionLineIndex:n,deletionLineIndex:i}),s.length-1)}function ut(e,t,n){let i=t.contextBufferCount,s=t.contextBufferAdditionStart,r=t.contextBufferDeletionStart;if(n==="leading"&&i>e.maxContextLines){const h=i-e.maxContextLines;s+=h,r+=h,i=e.maxContextLines,t.additionStart+=h,t.deletionStart+=h,t.additionLineIndex+=h,t.deletionLineIndex+=h}if(n==="trailing"&&i>e.maxContextLines&&(i=e.maxContextLines),i===0){t.contextBufferCount=0,t.contextBufferBaseConflicts=void 0;return}const o=t.hunkContent,a=o[o.length-1];let l;a?.type==="context"?(a.lines+=i,l=o.length-1):(o.push({type:"context",lines:i,additionLineIndex:s,deletionLineIndex:r}),l=o.length-1),t.additionCount+=i,t.deletionCount+=i;const d=t.contextBufferBaseConflicts;if(d!=null){const h=s-t.contextBufferAdditionStart;for(const[u,c]of d)u>=h&&u<h+i&&on(e,c,"base",l)}t.contextBufferCount=0,t.contextBufferBaseConflicts=void 0}function an(e){if(e.activeHunk==null)return;const t=e.activeHunk;if(e.activeHunk=void 0,t.hunkContent.length===0)return;let n=0,i=0;for(const l of t.hunkContent)l.type==="context"?(n+=l.lines,i+=l.lines):(n+=Math.max(l.additions,l.deletions),i+=l.additions+l.deletions);const s=t.additionCount===0?t.additionStart-1:t.additionStart,r=t.deletionCount===0?t.deletionStart-1:t.deletionStart,o=Math.max(xe(s,t.additionCount)-e.lastHunkEnd,0),a={collapsedBefore:o,additionStart:s,additionCount:t.additionCount,additionLines:t.additionLines,additionLineIndex:t.additionLineIndex,deletionStart:r,deletionCount:t.deletionCount,deletionLines:t.deletionLines,deletionLineIndex:t.deletionLineIndex,hunkContent:t.hunkContent,hunkContext:void 0,hunkSpecs:`@@ -${Rt(r,t.deletionCount)} +${Rt(s,t.additionCount)} @@
|
|
4
4
|
`,splitLineStart:e.splitLineCount+o,splitLineCount:n,unifiedLineStart:e.unifiedLineCount+o,unifiedLineCount:i,noEOFCRAdditions:!1,noEOFCRDeletions:!1};e.hunks.push(a),e.splitLineCount+=o+n,e.unifiedLineCount+=o+i,e.lastHunkEnd=q(s,t.additionCount)}function Ni(e){if(e.activeHunk==null)return;const t=e.activeHunk,n=t.contextBufferCount,i=n-e.maxContextLines2,s=t.contextBufferAdditionStart+n-e.maxContextLines,r=t.contextBufferDeletionStart+n-e.maxContextLines;let o;if(t.contextBufferBaseConflicts!=null){const d=n-e.maxContextLines;for(const[h,u]of t.contextBufferBaseConflicts)h>=d&&(o??=new Map,o.set(h-d,u))}ut(e,t,"trailing");const a=t.additionCount,l=t.deletionCount;an(e),e.activeHunk=ln(t.additionStart+a+i,t.deletionStart+l+i),e.activeHunk.contextBufferAdditionStart=s,e.activeHunk.contextBufferDeletionStart=r,e.activeHunk.contextBufferCount=e.maxContextLines,e.activeHunk.contextBufferBaseConflicts=o}function wt(e,t,n=-1){const i=rn(e);i.contextBufferCount===0&&(i.contextBufferAdditionStart=e.additionLines.length,i.contextBufferDeletionStart=e.deletionLines.length),e.additionLines.push(t),e.deletionLines.push(t),n>=0&&(i.contextBufferBaseConflicts??=new Map,i.contextBufferBaseConflicts.set(i.contextBufferCount,n)),i.contextBufferCount++}function Et(e,t,n,i,s){let r=rn(e);r.hunkContent.length>0&&r.contextBufferCount>e.maxContextLines2&&(Ni(e),r=e.activeHunk),ut(e,r,r.hunkContent.length===0?"leading":"before-change");const o=e.additionLines.length,a=e.deletionLines.length;t==="addition"?e.additionLines.push(n):e.deletionLines.push(n);const l=Fi(r,t,o,a);t==="addition"?(r.additionCount++,r.additionLines++):(r.deletionCount++,r.deletionLines++),on(e,i,s,l)}function Pi(e,t,n,i){if(t.separatorLineIndex==null||t.markerLines.separator==null)throw new Error(`parseMergeConflictDiffFromFile: conflict ${t.conflictIndex} is missing a separator marker`);const s=e.conflictBuilders[t.conflictIndex];if(s==null)throw new Error(`parseMergeConflictDiffFromFile: failed to finalize conflict ${t.conflictIndex}`);const r=s.action;r.markerLines.separator=t.markerLines.separator,r.markerLines.end=i,t.markerLines.base!=null&&(r.markerLines.base=t.markerLines.base),r.conflict={conflictIndex:t.conflictIndex,startLineIndex:t.startLineIndex,startLineNumber:t.startLineIndex+1,separatorLineIndex:t.separatorLineIndex,separatorLineNumber:t.separatorLineIndex+1,endLineIndex:n,endLineNumber:n+1,baseMarkerLineIndex:t.baseMarkerLineIndex,baseMarkerLineNumber:t.baseMarkerLineIndex!=null?t.baseMarkerLineIndex+1:void 0};const o=r.currentContentIndex??r.incomingContentIndex;if(r.currentContentIndex??=o,r.incomingContentIndex??=o,r.startContentIndex<0&&o!=null&&(r.startContentIndex=o),r.endContentIndex<0&&o!=null&&(r.endContentIndex=o),r.endMarkerContentIndex<0&&o!=null&&(r.endMarkerContentIndex=o),r.hunkIndex<0||r.startContentIndex<0||r.endContentIndex<0||r.endMarkerContentIndex<0)throw new Error(`parseMergeConflictDiffFromFile: failed to anchor merge conflict ${t.conflictIndex}`);e.actions[r.conflictIndex]=r,s.completed=!0}function At(e,t,n){const i=e.nextConflictIndex;e.nextConflictIndex++,e.conflictStack.push({conflictIndex:i,stage:"current",startLineIndex:n,markerLines:{start:t}}),e.conflictBuilders[i]={completed:!1,action:{conflict:{conflictIndex:i,startLineIndex:n,startLineNumber:n+1,separatorLineIndex:n,separatorLineNumber:n+1,endLineIndex:n,endLineNumber:n+1,baseMarkerLineIndex:void 0,baseMarkerLineNumber:void 0},conflictIndex:i,hunkIndex:-1,startContentIndex:-1,endContentIndex:-1,endMarkerContentIndex:-1,markerLines:{start:t,separator:"",end:""}}}}function ln(e,t){return{additionStart:e,deletionStart:t,additionCount:0,deletionCount:0,additionLines:0,deletionLines:0,additionLineIndex:Math.max(e-1,0),deletionLineIndex:Math.max(t-1,0),hunkContent:[],contextBufferAdditionStart:Math.max(e-1,0),contextBufferDeletionStart:Math.max(t-1,0),contextBufferCount:0,contextBufferBaseConflicts:void 0}}function Rt(e,t){return t===1?`${e}`:`${e},${t}`}function bt(e){if(e.length<7)return;const t=e.charCodeAt(0);if(t!==60&&t!==62&&t!==61&&t!==124)return;const n=zi(e);if(n<7)return;let i=1;for(;i<n&&e.charCodeAt(i)===t;)i++;if(!(i<7)){if(t===61)return i===n?"separator":void 0;if(!(i!==n&&!Bi(e.charCodeAt(i))))return t===60?"start":t===62?"end":"base"}}function zi(e){let t=e.length;return t>0&&e.charCodeAt(t-1)===10&&t--,t>0&&e.charCodeAt(t-1)===13&&t--,t}function Bi(e){return e===9||e===10||e===11||e===12||e===13||e===32}function Tt(e,t,n){return{...e,contents:n,cacheKey:e.cacheKey!=null?`${e.cacheKey}:merge-conflict-${t}`:void 0}}function Oi(e,t){const n=[],i=new Array(e.hunks.length),s=(o,a)=>{const l=e.hunks[o];if(l==null)return 0;let d=i[o];if(d==null){d=new Array(l.hunkContent.length+1);let h=l.unifiedLineStart;d[0]=h;for(let u=0;u<l.hunkContent.length;u++){const c=l.hunkContent[u];h+=c.type==="context"?c.lines:c.deletions+c.additions,d[u+1]=h}i[o]=d}return d[Math.max(a,0)]??l.unifiedLineStart},r=(o,a)=>{const l=s(o,a),d=i[o]?.[Math.max(a+1,0)]??s(o,a+1);return Math.max(l,d-1)};for(const o of t){if(o==null)continue;const a=e.hunks[o.hunkIndex];if(a==null)continue;const l=s(o.hunkIndex,o.startContentIndex);if(n.push(fe(o,"marker-start",o.startContentIndex,o.markerLines.start,l)),o.baseContentIndex!=null){const f=o.currentContentIndex,p=o.incomingContentIndex;if(f==null||p==null)continue;const g=o.markerLines.base;if(g==null)continue;const x=a.hunkContent[f],m=a.hunkContent[o.baseContentIndex],L=a.hunkContent[p];if(x?.type!=="change"||m?.type!=="context"||L?.type!=="change")continue;const v=s(o.hunkIndex,f),C=s(o.hunkIndex,p);n.push(fe(o,"marker-base",o.baseContentIndex,g,v+x.deletions)),n.push(fe(o,"marker-separator",o.baseContentIndex,o.markerLines.separator,C),fe(o,"marker-end",o.endMarkerContentIndex,o.markerLines.end,r(o.hunkIndex,o.endMarkerContentIndex)));continue}const d=o.currentContentIndex;if(d==null)continue;const h=a.hunkContent[d];if(h?.type!=="change")continue;const u=s(o.hunkIndex,d),c=h.deletions>0?u+h.deletions:l;n.push(fe(o,"marker-separator",d,o.markerLines.separator,c),fe(o,"marker-end",o.endMarkerContentIndex,o.markerLines.end,r(o.hunkIndex,o.endMarkerContentIndex)))}return n}function fe(e,t,n,i,s){return{type:t,hunkIndex:e.hunkIndex,contentIndex:n,conflictIndex:e.conflictIndex,lineText:i,lineIndex:s}}function Ui(e,t){let n=e.unifiedLineStart;for(let i=0;i<t;i++){const s=e.hunkContent[i];n+=s.type==="context"?s.lines:s.deletions+s.additions}return n}function Vi({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:i,renderHeaderFilenameSuffix:s,renderHeaderMetadata:r,renderAnnotation:o,renderGutterUtility:a,renderMergeConflictUtility:l,lineAnnotations:d,getHoveredLine:h,getInstance:u}){const c=n?.(e),f=i?.(e),p=s?.(e),g=r?.(e);return k.jsxs(k.Fragment,{children:[c!=null?k.jsx("div",{slot:sn,children:c}):k.jsxs(k.Fragment,{children:[f!=null&&k.jsx("div",{slot:"header-prefix",children:f}),p!=null&&k.jsx("div",{slot:"header-filename-suffix",children:p}),g!=null&&k.jsx("div",{slot:"header-metadata",children:g})]}),o!=null&&d?.map((x,m)=>k.jsx("div",{slot:Se(x),children:o(x)},m)),t!=null&&l!=null&&u!=null&&t.map(x=>{if(x==null)return;const m=ji(x,e);return k.jsx("div",{slot:m,style:gn,children:l(x,u)},m)}),a!=null&&k.jsx("div",{slot:"gutter-utility-slot",style:mn,children:a(h)})]})}function ji(e,t){const n=Ii(e,t);return n!=null?Di({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}class $i extends Cn{constructor(){super(...arguments),this.tokenize=Wi}equals(t,n,i){return i.ignoreWhitespace?((!i.newlineIsToken||!t.includes(`
|
|
@@ -6,21 +6,21 @@ import{j as k,r as ee}from"./react-rd22PHbN.js";import{a7 as q,a6 as xe,a8 as gn
|
|
|
6
6
|
`))&&(n=n.trim())):i.ignoreNewlineAtEof&&!i.newlineIsToken&&(t.endsWith(`
|
|
7
7
|
`)&&(t=t.slice(0,-1)),n.endsWith(`
|
|
8
8
|
`)&&(n=n.slice(0,-1))),super.equals(t,n,i)}}const Gi=new $i;function Mt(e,t,n){return Gi.diff(e,t,n)}function Wi(e,t){t.stripTrailingCr&&(e=e.replace(/\r\n/g,`
|
|
9
|
-
`));const n=[],i=e.split(/(\n|\r\n)/);i[i.length-1]||i.pop();for(let s=0;s<i.length;s++){const r=i[s];s%2&&!t.newlineIsToken?n[n.length-1]+=r:n.push(r)}return n}function _i(e){for(let t=0;t<e.length;t++)if(e[t]<" "||e[t]>"~"||e[t]==='"'||e[t]==="\\")return!0;return!1}function
|
|
9
|
+
`));const n=[],i=e.split(/(\n|\r\n)/);i[i.length-1]||i.pop();for(let s=0;s<i.length;s++){const r=i[s];s%2&&!t.newlineIsToken?n[n.length-1]+=r:n.push(r)}return n}function _i(e){for(let t=0;t<e.length;t++)if(e[t]<" "||e[t]>"~"||e[t]==='"'||e[t]==="\\")return!0;return!1}function Q(e){if(!_i(e))return e;let t='"';const n=new TextEncoder().encode(e);let i=0;for(;i<n.length;){const s=n[i];s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===34?t+='\\"':s===92?t+="\\\\":s>=32&&s<=126?t+=String.fromCharCode(s):t+="\\"+s.toString(8).padStart(3,"0"),i++}return t+='"',t}const Dt={includeIndex:!0,includeUnderline:!0,includeFileHeaders:!0};function It(e,t,n,i,s,r,o){let a;o?typeof o=="function"?a={callback:o}:a=o:a={},typeof a.context>"u"&&(a.context=4);const l=a.context;if(a.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(a.callback){const{callback:h}=a;Mt(n,i,Object.assign(Object.assign({},a),{callback:u=>{const c=d(u);h(c)}}))}else return d(Mt(n,i,a));function d(h){if(!h)return;h.push({value:"",lines:[]});function u(L){return L.map(function(v){return" "+v})}const c=[];let f=0,p=0,g=[],x=1,m=1;for(let L=0;L<h.length;L++){const v=h[L],C=v.lines||qi(v.value);if(v.lines=C,v.added||v.removed){if(!f){const S=h[L-1];f=x,p=m,S&&(g=l>0?u(S.lines.slice(-l)):[],f-=g.length,p-=g.length)}for(const S of C)g.push((v.added?"+":"-")+S);v.added?m+=C.length:x+=C.length}else{if(f)if(C.length<=l*2&&L<h.length-2)for(const S of u(C))g.push(S);else{const S=Math.min(C.length,l);for(const H of u(C.slice(0,S)))g.push(H);const y={oldStart:f,oldLines:x-f+S,newStart:p,newLines:m-p+S,lines:g};c.push(y),f=0,p=0,g=[]}x+=C.length,m+=C.length}}for(const L of c)for(let v=0;v<L.lines.length;v++)L.lines[v].endsWith(`
|
|
10
10
|
`)?L.lines[v]=L.lines[v].slice(0,-1):(L.lines.splice(v+1,0,"\"),v++);return{oldFileName:e,newFileName:t,oldHeader:s,newHeader:r,hunks:c}}}function tt(e,t){var n,i,s,r,o,a;if(t||(t=Dt),Array.isArray(e)){if(e.length>1&&!t.includeFileHeaders&&!e.every(h=>h.isGit))throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");return e.map(h=>tt(h,t)).join(`
|
|
11
|
-
`)}const l=[];if(e.isGit){if(t=Dt,!e.oldFileName)throw new Error("oldFileName must be specified for Git patches");if(!e.newFileName)throw new Error("newFileName must be specified for Git patches");let h=e.oldFileName,u=e.newFileName;e.isCreate&&h==="/dev/null"?h=u.replace(/^b\//,"a/"):e.isDelete&&u==="/dev/null"&&(u=h.replace(/^a\//,"b/")),l.push("diff --git "+
|
|
11
|
+
`)}const l=[];if(e.isGit){if(t=Dt,!e.oldFileName)throw new Error("oldFileName must be specified for Git patches");if(!e.newFileName)throw new Error("newFileName must be specified for Git patches");let h=e.oldFileName,u=e.newFileName;e.isCreate&&h==="/dev/null"?h=u.replace(/^b\//,"a/"):e.isDelete&&u==="/dev/null"&&(u=h.replace(/^a\//,"b/")),l.push("diff --git "+Q(h)+" "+Q(u)),e.isDelete&&l.push("deleted file mode "+((n=e.oldMode)!==null&&n!==void 0?n:"100644")),e.isCreate&&l.push("new file mode "+((i=e.newMode)!==null&&i!==void 0?i:"100644")),e.oldMode&&e.newMode&&!e.isDelete&&!e.isCreate&&(l.push("old mode "+e.oldMode),l.push("new mode "+e.newMode)),e.isRename&&(l.push("rename from "+Q(((s=e.oldFileName)!==null&&s!==void 0?s:"").replace(/^a\//,""))),l.push("rename to "+Q(((r=e.newFileName)!==null&&r!==void 0?r:"").replace(/^b\//,"")))),e.isCopy&&(l.push("copy from "+Q(((o=e.oldFileName)!==null&&o!==void 0?o:"").replace(/^a\//,""))),l.push("copy to "+Q(((a=e.newFileName)!==null&&a!==void 0?a:"").replace(/^b\//,""))))}else t.includeIndex&&e.oldFileName==e.newFileName&&e.oldFileName!==void 0&&l.push("Index: "+e.oldFileName),t.includeUnderline&&l.push("===================================================================");const d=e.hunks.length>0;t.includeFileHeaders&&e.oldFileName!==void 0&&e.newFileName!==void 0&&(!e.isGit||d)&&(l.push("--- "+Q(e.oldFileName)+(e.oldHeader?" "+e.oldHeader:"")),l.push("+++ "+Q(e.newFileName)+(e.newHeader?" "+e.newHeader:"")));for(let h=0;h<e.hunks.length;h++){const u=e.hunks[h],c=u.oldLines===0?u.oldStart-1:u.oldStart,f=u.newLines===0?u.newStart-1:u.newStart;l.push("@@ -"+c+","+u.oldLines+" +"+f+","+u.newLines+" @@");for(const p of u.lines)l.push(p)}return l.join(`
|
|
12
12
|
`)+`
|
|
13
13
|
`}function Ki(e,t,n,i,s,r,o){if(typeof o=="function"&&(o={callback:o}),o?.callback){const{callback:a}=o;It(e,t,n,i,s,r,Object.assign(Object.assign({},o),{callback:l=>{a(l?tt(l,o.headerOptions):void 0)}}))}else{const a=It(e,t,n,i,s,r,o);return a?tt(a,o?.headerOptions):void 0}}function qi(e){const t=e.endsWith(`
|
|
14
14
|
`),n=e.split(`
|
|
15
15
|
`).map(i=>i+`
|
|
16
16
|
`);return t?n.pop():n.push(n.pop().slice(0,-1)),n}const Xi="/dev/null";function ae(e,t,n,i=!1){if(e===null&&t===null)throw new Error("parseDiffFromFile: You must pass oldFile, newFile, or both");const s=e??Ft(),r=t??Ft(),o=Sn(Ki(s.name,r.name,s.contents,r.contents,s.header,r.header,n),{cacheKey:(()=>{const l=e?.cacheKey??e?.name,d=t?.cacheKey??t?.name;return l!=null&&d!=null?l+":"+d:l??d})(),oldFile:s,newFile:r,throwOnError:i});if(o==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");e===null?(o.type="new",o.prevName=void 0):t===null&&(o.type="deleted",o.prevName=void 0);const a=t?.lang??(t===null?e?.lang:void 0);return a!=null&&(o.lang=a),o}function Ft(){return{name:Xi,contents:""}}function K(e,t){const n=ae({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:n.hunks,splitLineCount:n.splitLineCount,unifiedLineCount:n.unifiedLineCount,additionLines:n.additionLines,deletionLines:n.deletionLines,type:n.type}}function Yi(e,t){const n=Math.max(e,1);let i=Array.from({length:n},(s,r)=>`${" ".repeat(r+1)}
|
|
17
17
|
`).join("");return i===t&&(i=Array.from({length:n},(s,r)=>`\0${" ".repeat(r)}
|
|
18
|
-
`).join("")),i}function
|
|
18
|
+
`).join("")),i}function Zi(e){for(const t of e)if(t.trim().length>0)return!1;return!0}function nt(e,t){return t.length>0&&t.length<e.deletionLines.length&&Zi(t)}function Oe(e,t,n){const i=e.deletionLines.join(""),s=Yi(t.length,i),r=ae({name:e.prevName??e.name,contents:i},{name:e.name,contents:s,lang:e.lang},n);return{hunks:r.hunks,splitLineCount:r.splitLineCount,unifiedLineCount:r.unifiedLineCount,additionLines:t,deletionLines:r.deletionLines,type:r.type}}function Be(e,t){return Oe(e,[""],t)}function dn(e,t){if(e.additionLines.length===0)return Be(e,t);if(nt(e,e.additionLines))return Oe(e,e.additionLines,t);const n=e.additionLines,i=K(e,t);return hn(i,n),i}function Qi(e){return e.length>1&&e.at(-1)===""}function hn(e,t){if(!Qi(t))return;const n=t.length-e.additionLines.length;if(n<=0)return;const i=e.additionLines.length,s=e.hunks.at(-1);if(s!=null&&q(s.additionStart,s.additionCount)===i){for(const r of s.hunkContent)if(r.type==="change"&&r.additions<r.deletions&&r.additionLineIndex+r.additions===i){e.additionLines=t,r.additions+=n,s.additionCount+=n,s.additionLines+=n,ft(e);return}}}function Ji(e,t,n){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return _(e,K(e,n));const i=Array.from(t);if(i.length===0)return _(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of i){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Ze(o)===Ze(a))return _(e,K(e,n))}const s=es(e,i);if(s.size===0)return _(e,K(e,n));for(const r of s)if(!ns(e,r,n))return _(e,K(e,n));return ft(e),xn(e)?_(e,K(e,n)):_(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function _(e,t){return Object.assign(e,t),t}function es(e,t){const n=new Set;for(const i of t){const s=ts(e,i);if(s==null)return new Set;n.add(s)}return n}function ts(e,t){for(const[n,i]of e.hunks.entries()){const s=i.additionLineIndex+i.additionCount;if(t>=i.additionLineIndex&&t<s)return n}}function ns(e,t,n){const i=e.hunks[t];if(i==null)return!1;const s=e.deletionLines.slice(i.deletionLineIndex,i.deletionLineIndex+i.deletionCount),r=e.additionLines.slice(i.additionLineIndex,i.additionLineIndex+i.additionCount),o=ae({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...n,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(is(i,a),un(e,t),!0)}function un(e,t){const n=e.hunks[t];if(n==null)return;if(t!==e.hunks.length-1){n.noEOFCRAdditions=!1,n.noEOFCRDeletions=!1;return}const i=e.additionLines.at(-1),s=e.deletionLines.at(-1);n.noEOFCRAdditions=i!=null&&i!==""&&!i.endsWith(`
|
|
19
19
|
`),n.noEOFCRDeletions=s!=null&&s!==""&&!s.endsWith(`
|
|
20
|
-
`)}function is(e,t){const n=e.additionLineIndex,i=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>cn(s,n,i)),e.additionLineIndex=n+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=i+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,ct(e)}function cn(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function ct(e){let t=0,n=0;for(const i of e.hunkContent)i.type==="context"?(t+=i.lines,n+=i.lines):(t+=Math.max(i.additions,i.deletions),n+=i.additions+i.deletions);e.splitLineCount=t,e.unifiedLineCount=n}function ft(e){let t=0,n=0,i=0;for(const s of e.hunks)s.collapsedBefore=Math.max(xe(s.additionStart,s.additionCount)-i,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=n+s.collapsedBefore,ct(s),t+=s.collapsedBefore+s.splitLineCount,n+=s.collapsedBefore+s.unifiedLineCount,i=q(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-q(s.additionStart,s.additionCount),0);t+=r,n+=r}e.splitLineCount=t,e.unifiedLineCount=n}const Nt=new WeakMap;function ss(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function rs(e,t){const n=Math.min(e.length,t.length);let i=0;for(;i<n&&e[i]===t[i];)i++;let s=e.length,r=t.length;for(;s>i&&r>i&&e[s-1]===t[r-1];)s--,r--;if(!(i===s&&i===r))return{start:i,deletionEnd:s,additionEnd:r}}function it(e,t){const n=e.hunks,i=e.additionLines,s=ss(i),r=s===i?e:{...e,additionLines:s},o=ps(n,fs(r,t),e.deletionLines.length),a=Cs(r,o);if(e.additionLines=s,e.hunks=a,e.editSessionDirty=!0,ks(e),hn(e,i),!!xs(n,e.hunks))return{regions:o.map(l=>l.previousSpan)}}function os(e,t,n,i){const s=Array.from(new Set(t)).filter(l=>l>=0&&l<e.additionLines.length).sort((l,d)=>l-d);if(s.length===0)return;const{hunks:r}=e;let o,a=0;for(const l of s){for(;a<r.length;){const u=r[a];if(l<Ue(u)+u.additionCount)break;a++}const d=r[a],h=d==null?void 0:Ue(d);if(h==null||l<h||o!=null&&o!==a)return it(e,n);o=a}if(o!=null){if(as(e,s,o,i,n)){e.editSessionDirty=!0;return}return it(e,n)}}function as(e,t,n,i,s){if(i==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=ls(e),o=e.hunks[n];if(o.hunkContent.some(ds))return!1;for(const a of t){const l=i.get(a),d=e.additionLines[a];if(l==null||d==null||r.has(l)||r.has(d))return!1;let h=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&a>=u.additionLineIndex&&a<u.additionLineIndex+u.additions){h=!0;break}if(!h)return!1}return!0}function ls(e){const t=Nt.get(e);if(t?.lines===e.deletionLines)return t.set;const n=new Set(e.deletionLines);return Nt.set(e,{lines:e.deletionLines,set:n}),n}function ds(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function hs(e,t){const n=new Map,{regions:i}=t;for(let s=0;s<=i.length;s++){const r=i[s-1],o=i[s],a=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),l=o==null?void 0:e.get(o.firstIndex),d=a?.fromStart??0,h=l?.fromEnd??0;(d>0||h>0)&&n.set(s,{fromStart:d,fromEnd:h})}return n}function us(e,t,n){const i=[];if(e.isPartial)return i;for(const[r,o]of e.hunks.entries()){const a=ve({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:n});if(a.rangeSize<=n)continue;const l=le(o),d=l-a.rangeSize;a.fromStart>0&&i.push([d,d+a.fromStart]),a.fromEnd>0&&i.push([l-a.fromEnd,l])}const s=ye({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:"captureExpansionAnchors"});if(s!=null&&s.fromStart>0&&s.rangeSize>n){const r=e.hunks[e.hunks.length-1],o=le(r)+r.deletionCount;i.push([o,o+s.fromStart])}return i}function cs(e,t){const n=new Map;if(t.length===0)return n;const i=(r,o,a)=>{if(a<=o)return;let l=0,d=0;for(const[h,u]of t)u<=o||h>=a||(h<=o&&(l=Math.max(l,Math.min(u,a)-o)),u>=a&&(d=Math.max(d,a-Math.max(h,o))));(l>0||d>0)&&n.set(r,{fromStart:l,fromEnd:d})};for(const[r,o]of e.hunks.entries()){const a=le(o);i(r,a-Math.max(o.collapsedBefore,0),a)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&i(e.hunks.length,le(s)+s.deletionCount,e.deletionLines.length),n}function Pt(e,t){return e.editSessionDirty!==!0?!1:(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?K(e,t):dn(e,t)),!0)}function fs(e,t){if(rs(e.deletionLines,e.additionLines)==null)return[];const n=ae({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t),i=[];let s=0,r=0;for(const o of n.hunks){const a=o.additionCount>0?o.additionLineIndex-s:o.deletionLineIndex-r;s+=a,r+=a;for(const l of o.hunkContent){if(l.type==="context"){s+=l.lines,r+=l.lines;continue}const d=cn(l,0,0);d.additions===0&&(d.additionLineIndex=s),d.deletions===0&&(d.deletionLineIndex=r),i.push(d),s+=d.additions,r+=d.deletions}}return i}function ps(e,t,n){const i=e.map((o,a)=>{const l=le(o);return{deletionStart:l,deletionEnd:l+o.deletionCount,blocks:[],previousSpan:{firstIndex:a,lastIndex:a}}}),s=[];let r=0;for(const o of t){const a=o.deletionLineIndex,l=a+o.deletions;for(;r<i.length&&i[r].deletionEnd<a;)s.push(i[r]),r++;let d=s.length>0&&gs(a,l,s[s.length-1])?s.pop():void 0;for(;r<i.length&&i[r].deletionStart<=l;)d=ms(d,i[r]),r++;if(d==null){let h=a,u=l;if((o.deletions===0||o.additions===0)&&n>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=i[r]?.deletionStart??n;a>c?h--:l<f&&u++}d={deletionStart:h,deletionEnd:u,blocks:[],previousSpan:void 0}}d.deletionStart=Math.min(d.deletionStart,a),d.deletionEnd=Math.max(d.deletionEnd,l),d.blocks.push(o),s.push(d)}for(;r<i.length;)s.push(i[r]),r++;return s}function gs(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function ms(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function Cs(e,t){const n=[];let i=0,s=0;for(const r of t){const o=r.deletionStart-i;if(o<0)throw new Error("buildRegionHunks: overlapping old-side regions");i+=o,s+=o;const a=s,l=[];for(const h of r.blocks){const u=h.deletionLineIndex-i,c=h.additionLineIndex-s;if(u<0||u!==c)throw new Error("buildRegionHunks: canonical block context mismatch");zt(l,u,s,i),i+=u,s+=c,l.push({...h}),i+=h.deletions,s+=h.additions}const d=r.deletionEnd-i;if(d<0)throw new Error("buildRegionHunks: block exceeds its old-side region");zt(l,d,s,i),i+=d,s+=d,n.push(Ss(e,{additionStart:a,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},l))}if(e.deletionLines.length-i!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return n}function Ss(e,t,n){const i=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const l of n)l.type==="change"&&(r+=l.additions,o+=l.deletions);const a={collapsedBefore:0,additionStart:be(t.additionStart,i),additionCount:i,additionLines:r,additionLineIndex:Ot(t.additionStart,i),deletionStart:be(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Ot(t.deletionStart,s),hunkContent:n,hunkSpecs:`@@ -${be(t.deletionStart,s)},${s} +${be(t.additionStart,i)},${i} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return ct(a),a}function zt(e,t,n,i){t>0&&e.push({type:"context",lines:t,additionLineIndex:n,deletionLineIndex:i})}function xs(e,t){if(e.length!==t.length)return!0;for(let n=0;n<e.length;n++){const i=e[n],s=t[n];if(le(i)!==le(s)||i.deletionCount!==s.deletionCount||Ue(i)!==Ue(s)||i.additionCount!==s.additionCount||i.splitLineCount!==s.splitLineCount||!Ls(i,s))return!0}return!1}function Ls(e,t){const n=Bt(e),i=Bt(t);for(;;){const s=n.next(),r=i.next();if(s.done===!0||r.done===!0)return s.done===r.done;if(s.value[0]!==r.value[0]||s.value[1]!==r.value[1])return!1}}function*Bt(e){for(const t of e.hunkContent){if(t.type==="context"){for(let i=0;i<t.lines;i++)yield[t.deletionLineIndex+i,t.additionLineIndex+i];continue}const n=Math.max(t.deletions,t.additions);for(let i=0;i<n;i++)yield[i<t.deletions?t.deletionLineIndex+i:void 0,i<t.additions?t.additionLineIndex+i:void 0]}}function Ue(e){return xe(e.additionStart,e.additionCount)}function le(e){return xe(e.deletionStart,e.deletionCount)}function be(e,t){return t===0?e:e+1}function Ot(e,t){return t===0?e-1:e}function ks(e){ft(e);for(let t=0;t<e.hunks.length;t++)un(e,t)}async function st(e,t=300){let n;try{await Promise.race([e(),new Promise(i=>{n=setTimeout(i,t)})])}finally{n!=null&&clearTimeout(n)}}function vs({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:i,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:a}){let l=ge(t,n),d=l;const h=s?!0:r,u=e.hunks.length-1;for(let c=0;c<e.hunks.length;c++){const f=e.hunks[c];if(f==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const p=ve({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:h,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(l+=g,d+=g,p.collapsedLines>0){const L=ke({type:i,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;l+=L,d+=L}l+=f.splitLineCount*t.lineHeight,d+=f.unifiedLineCount*t.lineHeight;const x=ys(f);l+=x.split*t.lineHeight,d+=x.unified*t.lineHeight;const m=c===u?ye({fileDiff:e,hunkIndex:c,expandedHunks:h,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(m!=null){const L=(m.fromStart+m.fromEnd)*t.lineHeight;if(l+=L,d+=L,m.collapsedLines>0){const v=se({type:i,metrics:t})?.totalHeight??0;l+=v,d+=v}}else if(c===u&&e.isPartial&&a){const L=se({type:i,metrics:t})?.totalHeight??0;l+=L,d+=L}}if(e.hunks.length>0){const c=Qt(t);l+=c,d+=c}return{splitHeight:l,unifiedHeight:d}}function ys(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 n=t.lines>0?1:0;return{split:n,unified:n}}return Hs(e,t)}function Hs(e,t){const n=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),i=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:i||s?1:0,unified:n}}function rt({oldFile:e,newFile:t},n){if(!(e===void 0&&t===void 0)){if(e===void 0||t===void 0)throw new Error(`${n}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw new Error(`${n}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return t===null?{oldFile:e,newFile:t}:{oldFile:e,newFile:t}}}function ws(e){return{...e,hunks:e.hunks.map(t=>({...t,hunkContent:t.hunkContent.map(n=>({...n}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function ot(e){return e!==""?e.split(ri):[]}function at(e,t,n){const i=e==="clone"?ws(t):t;if(!i.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(i.type){case"change":case"rename-changed":return Es(i,Rs(i,n),Ut(i,n));case"rename-pure":{const s=Ut(i,n);bs(i,n);const r=ot(s.contents);return i.isPartial=!1,i.deletionLines=r,i.additionLines=r,fn(i,null,s),i}}throw new Error(`hydratePartialDiff: ${i.type} diffs cannot be hydrated from loaded files`)}function Es(e,t,n){const i=ot(t.contents),s=ot(n.contents),{hunks:r,splitLineCount:o,unifiedLineCount:a}=As(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=a,e.isPartial=!1,e.deletionLines=i,e.additionLines=s,fn(e,t,n),e}function As(e,t){let n=0,i=0,s=0;const r=[];for(const o of e){const a=Math.max(o.additionStart-1,0),l=Math.max(o.deletionStart-1,0);let d=a,h=l,u=0,c=0,f=0,p=0;const g=[];for(const m of o.hunkContent){if(m.type==="context"){g.push({...m,additionLineIndex:d,deletionLineIndex:h}),d+=m.lines,h+=m.lines,f+=m.lines,p+=m.lines;continue}g.push({...m,additionLineIndex:d,deletionLineIndex:h}),d+=m.additions,h+=m.deletions,u+=m.additions,c+=m.deletions,f+=Math.max(m.additions,m.deletions),p+=m.additions+m.deletions}const x=Math.max(xe(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:x,additionLineIndex:a,deletionLineIndex:l,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:n+x,unifiedLineStart:i+x,splitLineCount:f,unifiedLineCount:p}),n+=x+f,i+=x+p,s=q(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],a=q(o.additionStart,o.additionCount),l=Math.max(t-a,0);n+=l,i+=l}return{hunks:r,splitLineCount:n,unifiedLineCount:i}}function Rs(e,t){if(t.oldFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function Ut(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function bs(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function Ts(e,t,n){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:Ms(t,n)}function fn(e,t,n){const i=Ts(e,t,n);if(i==null){delete e.cacheKey;return}e.cacheKey=i}function Ms(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?`${e.cacheKey}:${t.cacheKey}`:void 0:e?.cacheKey??t?.cacheKey}var Ds=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,n){if(t==null||n==null)for(const i of e.children??[])i instanceof HTMLElement&&("deletions"in i.dataset?t=i:"additions"in i.dataset&&(n=i));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function lt(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function Te(e){return F({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function Me(e){return F({tagName:"div",children:[F({tagName:"span",children:[Pe("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Ke(e){return F({tagName:"div",children:[Ln({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 pe({type:e,content:t,expandIndex:n,chunked:i=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(F({tagName:"div",children:[Pe(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const d=[];n!=null&&(i?(r||(d.push(Ke("up")),a++),o||(d.push(Ke("down")),a++)):(d.push(Ke(!r&&!o?"both":r?"down":"up")),a++)),d.push(F({tagName:"div",children:[F({tagName:"span",children:[Pe(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),i&&n!=null&&d.push(F({tagName:"div",children:[Pe("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(F({tagName:"div",children:d,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(F({tagName:"slot",properties:{name:s}})),F({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function Is(e,t){return`hunk-separator-${e}-${t}`}function Fs(e){const t=e.at(-1);return t==null?0:Math.max(q(t.additionStart,t.additionCount),q(t.deletionStart,t.deletionCount))}let Ns=-1;var Ps=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++Ns}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;editSessionActive=!1;constructor(e={theme:re},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=$e(e.theme??re)?kn():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this),this.endEditSession()}beginEditSession(){this.editSessionActive=!0;const e=this.diffCache;e!=null&&!e.isPartial&&e.additionLines.length===0&&(Object.assign(e,Be(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache())}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){const{renderCache:e}=this;if(e==null||ze(e.diff)||Fe(e.diff,this.getTokenizeMaxLength()))return Promise.resolve();const{diff:t}=e,{workerManager:n}=this;return!this.editSessionActive&&n?.isWorkingPool()===!0&&t.cacheKey!=null?(n.evictDiffFromCache(t.cacheKey),n.primeDiffHighlightCache(t).then(()=>{this.applyRefreshedResult(t,n.getDiffResultCache(t))}).catch(i=>this.onHighlightError(i))):this.asyncHighlight(t).then(i=>this.applyRefreshedResult(t,i)).catch(i=>this.onHighlightError(i))}applyRefreshedResult(e,t){if(t==null||this.renderCache==null||this.renderCache.diff!==e||this.editSessionActive)return;const{options:n}=this.getRenderOptions(e);ce(n,t.options)&&(this.renderCache={diff:e,options:t.options,highlighted:!0,result:t.result,renderRange:void 0},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){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,n=this.getOptionsWithDefaults().expansionLineCount){const i={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(i.fromStart+=n),(t==="down"||t==="both")&&(i.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,i)}getExpandedHunk(e){return this.expandedHunks.get(e)??oi}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const n=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),i=n[t.lineNumber]??[];n[t.lineNumber]=i,i.push(t)}}updateRenderCache(e,t,n=!1){if(this.renderCache==null)return!1;const{result:i,diff:s}=this.renderCache;if(i==null)return!1;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=i.code.additionLines,o=[],a=new Map;for(const[d,h]of e){const u=r[d]?.properties??{},c=h.map(x=>x[2]).join(""),f=d<s.additionLines.length,p=f?s.additionLines[d]??"":"",g=Qe(p);f&&(s.additionLines[d]=vn(p,c),g!==c&&(o.push(d),a.set(d,p))),r[d]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??d+1,"data-line-index":u["data-line-index"]??d,"data-line-type":u["data-line-type"]??"context"},children:h.map(([x,m,L])=>x===0&&m===""?L===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:L}:{type:"element",tagName:"span",properties:{"data-char":x,style:`color:${m};`},children:[{type:"text",value:L}]})}}let l=!1;if(o.length>0)if(this.editSessionActive&&!s.isPartial){if(!n)if(s.additionLines.length<=1&&s.additionLines.join("")==="")Object.assign(s,Be(s,this.options.parseDiffOptions)),this.markEditSessionPass(s),l=!0;else if(nt(s,s.additionLines))Object.assign(s,Oe(s,s.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(s),l=!0;else{const d=os(s,o,this.options.parseDiffOptions,a);this.applyExpansionRemap(d),l=d!=null}}else Object.assign(s,Ji(s,o,this.options.parseDiffOptions));return i.baseThemeType=t,this.renderCache.isDirty=!0,l}applyExpansionRemap(e){e!=null&&(this.expandedHunks=hs(this.expandedHunks,e))}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:n}=this.renderCache;if(n==null)return;if(t.isPartial)throw new Error("Could not apply document change for partial diff");const{additionLines:i}=t;t.additionLines=Us(e,i),n.code.additionLines=Os(i,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join("")===""?(Object.assign(t,Be(t,this.options.parseDiffOptions)),n.code.additionLines[0]=dt(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,dn(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){const{parseDiffOptions:t}=this.options,n=e.additionLines;if(nt(e,n)){Object.assign(e,Oe(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(it(e,t))}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const n=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:n,contentProperties:{"data-line-type":n}}}createAnnotationElement=e=>yn(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:n=!1,disableFileHeader:i=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:d=100,hunkSeparators:h="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=re,headerRenderMode:x="default",tokenizeMaxLineLength:m=1e3,tokenizeMaxLength:L=ai,useTokenTransformer:v=!1,useCSSClasses:C=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:i,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:d,hunkSeparators:h,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:x,tokenizeMaxLineLength:m,tokenizeMaxLength:L,useTokenTransformer:v,useCSSClasses:C}}async initializeHighlighter(){return this.highlighter=await Hn(wn(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),n=Fe(e,this.getTokenizeMaxLength());let i=this.workerManager?.getDiffResultCache(e);i!=null&&!ce(t,i.options)&&(i=void 0),this.renderCache??={diff:e,highlighted:!n&&!ze(e),options:t,result:n?void 0:i?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??_e(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??re}getEffectiveCodeOptions(){const e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0){const a=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&a.useTokenTransformer!==!0?{...a,useTokenTransformer:!0}:a}const{theme:i,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:i,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:n}=this;return n?.result==null?{options:t,forceHighlight:!0}:!me(e,n.diff)||!ce(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=vt){if(e==null)return;const{expandUnchanged:n,collapsedContextThreshold:i}=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||ze(e)||Fe(e,this.getTokenizeMaxLength()),d=!me(e,this.renderCache.diff),h=!Zt(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!l&&!d&<(t);u&&(this.renderCache.highlightPending=!0),!u&&(l||this.renderCache.result==null||!this.renderCache.highlighted&&(d||h))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||d||h||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,lt(t)||n?!0:this.expandedHunks,i)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLang=e.lang??_e(e.name);const u=this.highlighter!=null&&$e(s.theme),c=this.highlighter!=null&&pt(this.computedLang),f=!l&&c;if(this.highlighter!=null&&u&&(r||l||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderDiffWithHighlighter(e,this.highlighter,l||!c);this.renderCache={diff:e,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!l&&!c)&&this.asyncHighlight(e).then(({result:p,options:g})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,p,g,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=vt){const{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){const{diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return En({type:"diff",diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){const t=Fe(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??_e(e.name);const n=this.highlighter!=null&&$e(this.getLocalHighlightTheme()),i=t||this.highlighter!=null&&pt(this.computedLang);return(this.highlighter==null||!n||!i)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){const{options:i}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults(),r=An(e,t,i,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:s});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===""&&r.code.additionLines[0]==null){let o;if(Ce({diff:e,diffStyle:"both",expandedHunks:n?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:a})=>{if(a?.lineIndex===0)return o=a,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=dt(0,"",o.unifiedLineIndex,o.splitLineIndex)}return{result:r,options:i}}onHighlightSuccess(e,t,n,i=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,i)}applyHighlightResult(e,t,n,i=!0){if(this.renderCache==null)return;const s=this.renderCache.highlightPending===!0||!this.renderCache.highlighted||!ce(this.renderCache.options,n)||!me(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:i,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;const n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!ce(t,n.options)))return n}hasHighlightedRenderCache(e,t){const{renderCache:n}=this;return n?.result!=null&&n.highlighted&&me(e,n.diff)&&ce(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:i,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:d,hunkSeparators:h}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1;this.diff=e;const c=r==="unified",f=$s(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],x=[],m=[];const L=[],{additionLines:v,deletionLines:C}=n,S={rowCount:0,hunkSeparators:h,additionsContentAST:g,deletionsContentAST:x,unifiedContentAST:m,unifiedGutterAST:Re(),deletionsGutterAST:Re(),additionsGutterAST:Re(),expansionLineCount:l,hunkData:L,incrementRowCount(E=1){S.rowCount+=E},pushToGutter(E,A){switch(E){case"unified":S.unifiedGutterAST.children.push(A);break;case"deletions":S.deletionsGutterAST.children.push(A);break;case"additions":S.additionsGutterAST.children.push(A);break}}},y=Rn({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"?(S.pushToGutter("additions",V(void 0,"buffer",this.size)),g?.push(Te(this.size))):(S.pushToGutter("deletions",V(void 0,"buffer",this.size)),x?.push(Te(this.size))),this.size=0,this.side=void 0}}},$=(E,A,X,he,w)=>{S.pushToGutter(E,Mn(A,X,he,w))};function b(E){H.flush(),r==="unified"?qe("unified",E,S):(qe("deletions",E,S),qe("additions",E,S))}this.pushFileLevelAnnotations(e,r,t,S),Ce({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:d,callback:({hunkIndex:E,hunk:A,collapsedBefore:X,collapsedAfter:he,additionLine:w,deletionLine:R,type:M})=>{const z=R!=null?R.splitLineIndex:w.splitLineIndex,Y=w!=null?w.unifiedLineIndex:R.unifiedLineIndex;r==="split"&&M!=="change"&&H.flush(),X>0&&b({hunkIndex:E,collapsedLines:X,rangeSize:Math.max(A?.collapsedBefore??0,0),hunkSpecs:A?.hunkSpecs,isFirstHunk:E===0,isLastHunk:!1,isExpandable:p});const ue=r==="unified"?Y:z,Ee={type:M,hunkIndex:E,lineIndex:ue,unifiedLineIndex:Y,splitLineIndex:z,deletionLine:R,additionLine:w};if(r==="unified"){const T=this.getUnifiedInjectedRowsForLine?.(Ee);T?.before!=null&&jt(T.before,S);let N=R!=null?C[R.lineIndex]:void 0,B=w!=null?v[w.lineIndex]:void 0;if(N==null&&B==null){const U="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(U,{file:e.name}),new Error(U)}const ie=M==="change"?w!=null?"change-addition":"change-deletion":M,O=this.getUnifiedLineDecoration({type:M,lineType:ie,additionLineIndex:w?.lineIndex,deletionLineIndex:R?.lineIndex});$("unified",O.gutterLineType,w!=null?w.lineNumber:R.lineNumber,`${Y},${z}`,O.gutterProperties),B!=null?B=Ie(B,O.contentProperties,u&&w!=null?{"data-line":w.lineNumber,"data-line-index":`${Y},${z}`}:void 0):N!=null&&(N=Ie(N,O.contentProperties,u&&R!=null?{"data-line":R.lineNumber,"data-line-index":`${Y},${z}`}:void 0)),De({diffStyle:"unified",type:M,deletionLine:N,additionLine:B,unifiedSpan:this.getAnnotations("unified",R?.lineNumber,w?.lineNumber,E,ue),createAnnotationElement:U=>this.createAnnotationElement(U),context:S}),T?.after!=null&&jt(T.after,S)}else{const T=this.getSplitInjectedRowsForLine?.(Ee);T?.before!=null&&$t(T.before,S,H);let N=R!=null?C[R.lineIndex]:void 0,B=w!=null?v[w.lineIndex]:void 0;const ie=this.getSplitLineDecoration({side:"deletions",type:M,lineIndex:R?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:M,lineIndex:w?.lineIndex});if(N==null&&B==null){const P="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(P,{file:e.name}),new Error(P)}const U=(()=>{if(M==="change"){if(B==null)return"additions";if(N==null)return"deletions"}})();U!=null?(H.side!=null&&H.side!==U&&H.flush(),H.side=U,H.increment()):M==="change"&&H.flush();const Q=this.getAnnotations("split",R?.lineNumber,w?.lineNumber,E,ue);if(Q!=null&&H.size>0&&H.flush(),R!=null){const P=Ie(N,ie.contentProperties,u?{"data-line":R.lineNumber,"data-line-index":`${R.unifiedLineIndex},${z}`}:void 0);$("deletions",ie.gutterLineType,R.lineNumber,`${R.unifiedLineIndex},${z}`,ie.gutterProperties),P!=null&&(N=P)}if(w!=null){const P=Ie(B,O.contentProperties,u?{"data-line":w.lineNumber,"data-line-index":`${w.unifiedLineIndex},${z}`}:void 0);$("additions",O.gutterLineType,w.lineNumber,`${w.unifiedLineIndex},${z}`,O.gutterProperties),P!=null&&(B=P)}De({diffStyle:"split",type:M,additionLine:B,deletionLine:N,...Q,createAnnotationElement:P=>this.createAnnotationElement(P),context:S}),T?.after!=null&&$t(T.after,S,H)}const Le=r==="split"&&A!=null&&z===A.splitLineStart+A.splitLineCount-1,G=E===e.hunks.length-1&&A!=null&&(r==="split"?z===A.splitLineStart+A.splitLineCount-1:Y===A.unifiedLineStart+A.unifiedLineCount-1),Ve=Le?A.noEOFCRDeletions:!1,je=Le?A.noEOFCRAdditions:!1,ne=(R?.noEOFCR??!1)||Ve,W=(w?.noEOFCR??!1)||je;if(W||ne){if(r==="split"&&H.flush(),ne){const T=M==="context"||M==="context-expanded"?M:"change-deletion";r==="unified"?(S.unifiedContentAST.push(Me(T)),S.pushToGutter("unified",V(T,"metadata",1))):(S.deletionsContentAST.push(Me(T)),S.pushToGutter("deletions",V(T,"metadata",1)),W||(S.pushToGutter("additions",V(void 0,"buffer",1)),S.additionsContentAST.push(Te(1))))}if(W){const T=M==="context"||M==="context-expanded"?M:"change-addition";r==="unified"?(S.unifiedContentAST.push(Me(T)),S.pushToGutter("unified",V(T,"metadata",1))):(S.additionsContentAST.push(Me(T)),S.pushToGutter("additions",V(T,"metadata",1)),ne||(S.pushToGutter("deletions",V(void 0,"buffer",1)),S.deletionsContentAST.push(Te(1))))}S.incrementRowCount(1)}h!=="simple"&&h!=="metadata"&&(he>0||G&&f)&&b({hunkIndex:M==="context-expanded"?E:E+1,collapsedLines:G&&f?"unknown":he,rangeSize:y,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),S.incrementRowCount(1)}}),r==="split"&&H.flush();const D=Math.max(Fs(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),we=t.bufferBefore>0||t.bufferAfter>0,de=!c&&e.type!=="deleted",I=!c&&e.type!=="new",j=S.rowCount>0||we;g=de&&j?g:void 0,x=I&&j?x:void 0,m=c&&j?m:void 0;const te=this.createPreElement(x!=null&&g!=null,D);return{unifiedGutterAST:c&&j?S.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:I&&j?S.deletionsGutterAST.children:void 0,deletionsContentAST:x,additionsGutterAST:de&&j?S.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:L,preNode:te,themeStyles:i,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:D,rowCount:S.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const n=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,i=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(n==null||i==null)return;const s=Re(n);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,bn(i,t.rowCount)]}renderFullAST(e,t=[]){const n=this.getOptionsWithDefaults().hunkSeparators==="line-info",i=this.renderCodeAST("unified",e);if(i!=null)return t.push(F({tagName:"code",children:i,properties:{"data-code":"","data-container-size":n?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(F({tagName:"code",children:s,properties:{"data-code":"","data-container-size":n?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(F({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return oe(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?oe(e):oe(F({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,n,i){if(!Jt(n))return;const s=e.type!=="new"?Vt(gt(this.deletionAnnotations)):[],r=e.type!=="deleted"?Vt(gt(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){De({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:i});return}De({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:i})}getAnnotations(e,t,n,i,s){const r={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(Se(a));const o={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(n!=null)for(const a of this.additionAnnotations[n]??[])(e==="unified"?r:o).annotations.push(Se(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:n}=this.getOptionsWithDefaults();return Tn({fileOrDiff:e,mode:t,stickyHeader:n})}};function Vt(e){return e?.map(t=>Se(t))??[]}const zs=new Intl.PluralRules("en-US");function Bs(e){return`${e} unmodified line${zs.select(e)==="one"?"":"s"}`}function jt(e,t){for(const n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function $t(e,t,n){for(const{deletion:i,addition:s}of e){if(i==null&&s==null)continue;const r=i!=null&&s!=null?void 0:i==null?"deletions":"additions";(r==null||n.side!==r)&&n.flush(),i!=null&&(t.deletionsContentAST.push(i.content),t.pushToGutter("deletions",i.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(n.side=r,n.increment()),t.incrementRowCount(1)}}function De({diffStyle:e,type:t,deletionLine:n,additionLine:i,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let d=!1;if(e==="unified"){if(i!=null?l.unifiedContentAST.push(i):n!=null&&l.unifiedContentAST.push(n),s!=null){const h=t==="change"?n!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",V(h,"annotation",1)),d=!0}}else if(e==="split"){if(n!=null&&l.deletionsContentAST.push(n),i!=null&&l.additionsContentAST.push(i),r!=null){const h=t==="change"?n!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",V(h,"annotation",1)),d=!0}if(o!=null){const h=t==="change"?i!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",V(h,"annotation",1)),d=!0}}d&&l.incrementRowCount(1)}function qe(e,{hunkIndex:t,collapsedLines:n,rangeSize:i,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(typeof n=="number"&&n<=0)return;const d=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),d.push(pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const h=Is(e,t),u=i>l.expansionLineCount,c=a?t:void 0,f=typeof n=="number"?Bs(n):"More unchanged context may be available";l.pushToGutter(e,pe({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:h,hunkIndex:t,lines:typeof n=="number"?n:0,lineCountKnown:typeof n=="number",type:e,expandable:a?{up:!r,down:!o,chunked:u}:void 0})}function Ie(e,t,n){return e==null||e.type!=="element"||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Gt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function Os(e,t,n,i){const s=Gt(e),r=Gt(t),o=Math.min(s,r);let a=0;for(;a<o&&e[a]===t[a];)a++;let l=0;for(;l<o-a&&e[s-1-l]===t[r-1-l];)l++;const d=new Array(t.length);for(let h=0;h<a;h++)d[h]=n[h];for(let h=0;h<l;h++)d[r-1-h]=n[s-1-h];s<e.length&&r<t.length&&(d[t.length-1]=n[e.length-1]);for(let h=e.length;h<t.length;h++)d[h]??=n[h];for(let h=a;h<t.length;h++)d[h]??=dt(h,i.getLineText(h));return d}function dt(e,t,n=e,i=e){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${n},${i}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t}]}]}}function Us(e,t){const n=[],i=js(t);for(let s=0;s<e.lineCount;s++){const r=e.getLineText(s,!0);n.push(s<e.lineCount-1&&!Vs(r)?r+i:r)}return n}function Vs(e){return e.endsWith(`
|
|
20
|
+
`)}function is(e,t){const n=e.additionLineIndex,i=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>cn(s,n,i)),e.additionLineIndex=n+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=i+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,ct(e)}function cn(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function ct(e){let t=0,n=0;for(const i of e.hunkContent)i.type==="context"?(t+=i.lines,n+=i.lines):(t+=Math.max(i.additions,i.deletions),n+=i.additions+i.deletions);e.splitLineCount=t,e.unifiedLineCount=n}function ft(e){let t=0,n=0,i=0;for(const s of e.hunks)s.collapsedBefore=Math.max(xe(s.additionStart,s.additionCount)-i,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=n+s.collapsedBefore,ct(s),t+=s.collapsedBefore+s.splitLineCount,n+=s.collapsedBefore+s.unifiedLineCount,i=q(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-q(s.additionStart,s.additionCount),0);t+=r,n+=r}e.splitLineCount=t,e.unifiedLineCount=n}const Nt=new WeakMap;function ss(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function rs(e,t){const n=Math.min(e.length,t.length);let i=0;for(;i<n&&e[i]===t[i];)i++;let s=e.length,r=t.length;for(;s>i&&r>i&&e[s-1]===t[r-1];)s--,r--;if(!(i===s&&i===r))return{start:i,deletionEnd:s,additionEnd:r}}function it(e,t){const n=e.hunks,i=e.additionLines,s=ss(i),r=s===i?e:{...e,additionLines:s},o=ps(n,fs(r,t),e.deletionLines.length),a=Cs(r,o);if(e.additionLines=s,e.hunks=a,e.editSessionDirty=!0,ks(e),hn(e,i),!!xs(n,e.hunks))return{regions:o.map(l=>l.previousSpan)}}function os(e,t,n,i){const s=Array.from(new Set(t)).filter(l=>l>=0&&l<e.additionLines.length).sort((l,d)=>l-d);if(s.length===0)return;const{hunks:r}=e;let o,a=0;for(const l of s){for(;a<r.length;){const u=r[a];if(l<Ue(u)+u.additionCount)break;a++}const d=r[a],h=d==null?void 0:Ue(d);if(h==null||l<h||o!=null&&o!==a)return it(e,n);o=a}if(o!=null){if(as(e,s,o,i,n)){e.editSessionDirty=!0;return}return it(e,n)}}function as(e,t,n,i,s){if(i==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=ls(e),o=e.hunks[n];if(o.hunkContent.some(ds))return!1;for(const a of t){const l=i.get(a),d=e.additionLines[a];if(l==null||d==null||r.has(l)||r.has(d))return!1;let h=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&a>=u.additionLineIndex&&a<u.additionLineIndex+u.additions){h=!0;break}if(!h)return!1}return!0}function ls(e){const t=Nt.get(e);if(t?.lines===e.deletionLines)return t.set;const n=new Set(e.deletionLines);return Nt.set(e,{lines:e.deletionLines,set:n}),n}function ds(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function hs(e,t){const n=new Map,{regions:i}=t;for(let s=0;s<=i.length;s++){const r=i[s-1],o=i[s],a=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),l=o==null?void 0:e.get(o.firstIndex),d=a?.fromStart??0,h=l?.fromEnd??0;(d>0||h>0)&&n.set(s,{fromStart:d,fromEnd:h})}return n}function us(e,t,n){const i=[];if(e.isPartial)return i;for(const[r,o]of e.hunks.entries()){const a=ve({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:n});if(a.rangeSize<=n)continue;const l=le(o),d=l-a.rangeSize;a.fromStart>0&&i.push([d,d+a.fromStart]),a.fromEnd>0&&i.push([l-a.fromEnd,l])}const s=ye({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:t,collapsedContextThreshold:n,errorPrefix:"captureExpansionAnchors"});if(s!=null&&s.fromStart>0&&s.rangeSize>n){const r=e.hunks[e.hunks.length-1],o=le(r)+r.deletionCount;i.push([o,o+s.fromStart])}return i}function cs(e,t){const n=new Map;if(t.length===0)return n;const i=(r,o,a)=>{if(a<=o)return;let l=0,d=0;for(const[h,u]of t)u<=o||h>=a||(h<=o&&(l=Math.max(l,Math.min(u,a)-o)),u>=a&&(d=Math.max(d,a-Math.max(h,o))));(l>0||d>0)&&n.set(r,{fromStart:l,fromEnd:d})};for(const[r,o]of e.hunks.entries()){const a=le(o);i(r,a-Math.max(o.collapsedBefore,0),a)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&i(e.hunks.length,le(s)+s.deletionCount,e.deletionLines.length),n}function Pt(e,t){return e.editSessionDirty!==!0?!1:(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?K(e,t):dn(e,t)),!0)}function fs(e,t){if(rs(e.deletionLines,e.additionLines)==null)return[];const n=ae({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t),i=[];let s=0,r=0;for(const o of n.hunks){const a=o.additionCount>0?o.additionLineIndex-s:o.deletionLineIndex-r;s+=a,r+=a;for(const l of o.hunkContent){if(l.type==="context"){s+=l.lines,r+=l.lines;continue}const d=cn(l,0,0);d.additions===0&&(d.additionLineIndex=s),d.deletions===0&&(d.deletionLineIndex=r),i.push(d),s+=d.additions,r+=d.deletions}}return i}function ps(e,t,n){const i=e.map((o,a)=>{const l=le(o);return{deletionStart:l,deletionEnd:l+o.deletionCount,blocks:[],previousSpan:{firstIndex:a,lastIndex:a}}}),s=[];let r=0;for(const o of t){const a=o.deletionLineIndex,l=a+o.deletions;for(;r<i.length&&i[r].deletionEnd<a;)s.push(i[r]),r++;let d=s.length>0&&gs(a,l,s[s.length-1])?s.pop():void 0;for(;r<i.length&&i[r].deletionStart<=l;)d=ms(d,i[r]),r++;if(d==null){let h=a,u=l;if((o.deletions===0||o.additions===0)&&n>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=i[r]?.deletionStart??n;a>c?h--:l<f&&u++}d={deletionStart:h,deletionEnd:u,blocks:[],previousSpan:void 0}}d.deletionStart=Math.min(d.deletionStart,a),d.deletionEnd=Math.max(d.deletionEnd,l),d.blocks.push(o),s.push(d)}for(;r<i.length;)s.push(i[r]),r++;return s}function gs(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function ms(e,t){return e==null?t:(e.deletionStart=Math.min(e.deletionStart,t.deletionStart),e.deletionEnd=Math.max(e.deletionEnd,t.deletionEnd),e.blocks.push(...t.blocks),t.previousSpan!=null&&(e.previousSpan??={...t.previousSpan},e.previousSpan.firstIndex=Math.min(e.previousSpan.firstIndex,t.previousSpan.firstIndex),e.previousSpan.lastIndex=Math.max(e.previousSpan.lastIndex,t.previousSpan.lastIndex)),e)}function Cs(e,t){const n=[];let i=0,s=0;for(const r of t){const o=r.deletionStart-i;if(o<0)throw new Error("buildRegionHunks: overlapping old-side regions");i+=o,s+=o;const a=s,l=[];for(const h of r.blocks){const u=h.deletionLineIndex-i,c=h.additionLineIndex-s;if(u<0||u!==c)throw new Error("buildRegionHunks: canonical block context mismatch");zt(l,u,s,i),i+=u,s+=c,l.push({...h}),i+=h.deletions,s+=h.additions}const d=r.deletionEnd-i;if(d<0)throw new Error("buildRegionHunks: block exceeds its old-side region");zt(l,d,s,i),i+=d,s+=d,n.push(Ss(e,{additionStart:a,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},l))}if(e.deletionLines.length-i!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return n}function Ss(e,t,n){const i=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const l of n)l.type==="change"&&(r+=l.additions,o+=l.deletions);const a={collapsedBefore:0,additionStart:be(t.additionStart,i),additionCount:i,additionLines:r,additionLineIndex:Ot(t.additionStart,i),deletionStart:be(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Ot(t.deletionStart,s),hunkContent:n,hunkSpecs:`@@ -${be(t.deletionStart,s)},${s} +${be(t.additionStart,i)},${i} @@`,splitLineStart:0,splitLineCount:0,unifiedLineStart:0,unifiedLineCount:0,noEOFCRAdditions:!1,noEOFCRDeletions:!1};return ct(a),a}function zt(e,t,n,i){t>0&&e.push({type:"context",lines:t,additionLineIndex:n,deletionLineIndex:i})}function xs(e,t){if(e.length!==t.length)return!0;for(let n=0;n<e.length;n++){const i=e[n],s=t[n];if(le(i)!==le(s)||i.deletionCount!==s.deletionCount||Ue(i)!==Ue(s)||i.additionCount!==s.additionCount||i.splitLineCount!==s.splitLineCount||!Ls(i,s))return!0}return!1}function Ls(e,t){const n=Bt(e),i=Bt(t);for(;;){const s=n.next(),r=i.next();if(s.done===!0||r.done===!0)return s.done===r.done;if(s.value[0]!==r.value[0]||s.value[1]!==r.value[1])return!1}}function*Bt(e){for(const t of e.hunkContent){if(t.type==="context"){for(let i=0;i<t.lines;i++)yield[t.deletionLineIndex+i,t.additionLineIndex+i];continue}const n=Math.max(t.deletions,t.additions);for(let i=0;i<n;i++)yield[i<t.deletions?t.deletionLineIndex+i:void 0,i<t.additions?t.additionLineIndex+i:void 0]}}function Ue(e){return xe(e.additionStart,e.additionCount)}function le(e){return xe(e.deletionStart,e.deletionCount)}function be(e,t){return t===0?e:e+1}function Ot(e,t){return t===0?e-1:e}function ks(e){ft(e);for(let t=0;t<e.hunks.length;t++)un(e,t)}async function st(e,t=300){let n;try{await Promise.race([e(),new Promise(i=>{n=setTimeout(i,t)})])}finally{n!=null&&clearTimeout(n)}}function vs({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:i,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:a}){let l=ge(t,n),d=l;const h=s?!0:r,u=e.hunks.length-1;for(let c=0;c<e.hunks.length;c++){const f=e.hunks[c];if(f==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const p=ve({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:h,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(l+=g,d+=g,p.collapsedLines>0){const L=ke({type:i,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;l+=L,d+=L}l+=f.splitLineCount*t.lineHeight,d+=f.unifiedLineCount*t.lineHeight;const x=ys(f);l+=x.split*t.lineHeight,d+=x.unified*t.lineHeight;const m=c===u?ye({fileDiff:e,hunkIndex:c,expandedHunks:h,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(m!=null){const L=(m.fromStart+m.fromEnd)*t.lineHeight;if(l+=L,d+=L,m.collapsedLines>0){const v=se({type:i,metrics:t})?.totalHeight??0;l+=v,d+=v}}else if(c===u&&e.isPartial&&a){const L=se({type:i,metrics:t})?.totalHeight??0;l+=L,d+=L}}if(e.hunks.length>0){const c=Zt(t);l+=c,d+=c}return{splitHeight:l,unifiedHeight:d}}function ys(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 n=t.lines>0?1:0;return{split:n,unified:n}}return Hs(e,t)}function Hs(e,t){const n=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),i=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:i||s?1:0,unified:n}}function rt({oldFile:e,newFile:t},n){if(!(e===void 0&&t===void 0)){if(e===void 0||t===void 0)throw new Error(`${n}: Pass null for an intentionally missing oldFile or newFile side`);if(e===null){if(t===null)throw new Error(`${n}: You must pass oldFile, newFile, or both`);return{oldFile:e,newFile:t}}return t===null?{oldFile:e,newFile:t}:{oldFile:e,newFile:t}}}function ws(e){return{...e,hunks:e.hunks.map(t=>({...t,hunkContent:t.hunkContent.map(n=>({...n}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function ot(e){return e!==""?e.split(ri):[]}function at(e,t,n){const i=e==="clone"?ws(t):t;if(!i.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(i.type){case"change":case"rename-changed":return Es(i,Rs(i,n),Ut(i,n));case"rename-pure":{const s=Ut(i,n);bs(i,n);const r=ot(s.contents);return i.isPartial=!1,i.deletionLines=r,i.additionLines=r,fn(i,null,s),i}}throw new Error(`hydratePartialDiff: ${i.type} diffs cannot be hydrated from loaded files`)}function Es(e,t,n){const i=ot(t.contents),s=ot(n.contents),{hunks:r,splitLineCount:o,unifiedLineCount:a}=As(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=a,e.isPartial=!1,e.deletionLines=i,e.additionLines=s,fn(e,t,n),e}function As(e,t){let n=0,i=0,s=0;const r=[];for(const o of e){const a=Math.max(o.additionStart-1,0),l=Math.max(o.deletionStart-1,0);let d=a,h=l,u=0,c=0,f=0,p=0;const g=[];for(const m of o.hunkContent){if(m.type==="context"){g.push({...m,additionLineIndex:d,deletionLineIndex:h}),d+=m.lines,h+=m.lines,f+=m.lines,p+=m.lines;continue}g.push({...m,additionLineIndex:d,deletionLineIndex:h}),d+=m.additions,h+=m.deletions,u+=m.additions,c+=m.deletions,f+=Math.max(m.additions,m.deletions),p+=m.additions+m.deletions}const x=Math.max(xe(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:x,additionLineIndex:a,deletionLineIndex:l,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:n+x,unifiedLineStart:i+x,splitLineCount:f,unifiedLineCount:p}),n+=x+f,i+=x+p,s=q(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],a=q(o.additionStart,o.additionCount),l=Math.max(t-a,0);n+=l,i+=l}return{hunks:r,splitLineCount:n,unifiedLineCount:i}}function Rs(e,t){if(t.oldFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile`);return t.oldFile}function Ut(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function bs(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function Ts(e,t,n){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:Ms(t,n)}function fn(e,t,n){const i=Ts(e,t,n);if(i==null){delete e.cacheKey;return}e.cacheKey=i}function Ms(e,t){return e!=null&&t!=null?e.cacheKey!=null&&t.cacheKey!=null?`${e.cacheKey}:${t.cacheKey}`:void 0:e?.cacheKey??t?.cacheKey}var Ds=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,n){if(t==null||n==null)for(const i of e.children??[])i instanceof HTMLElement&&("deletions"in i.dataset?t=i:"additions"in i.dataset&&(n=i));if(n==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==n&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=n,n.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function lt(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function Te(e){return F({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function Me(e){return F({tagName:"div",children:[F({tagName:"span",children:[Pe("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Ke(e){return F({tagName:"div",children:[Ln({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 pe({type:e,content:t,expandIndex:n,chunked:i=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(F({tagName:"div",children:[Pe(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const d=[];n!=null&&(i?(r||(d.push(Ke("up")),a++),o||(d.push(Ke("down")),a++)):(d.push(Ke(!r&&!o?"both":r?"down":"up")),a++)),d.push(F({tagName:"div",children:[F({tagName:"span",children:[Pe(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),i&&n!=null&&d.push(F({tagName:"div",children:[Pe("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(F({tagName:"div",children:d,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(F({tagName:"slot",properties:{name:s}})),F({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function Is(e,t){return`hunk-separator-${e}-${t}`}function Fs(e){const t=e.at(-1);return t==null?0:Math.max(q(t.additionStart,t.additionCount),q(t.deletionStart,t.deletionCount))}let Ns=-1;var Ps=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++Ns}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;editSessionActive=!1;constructor(e={theme:re},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=$e(e.theme??re)?kn():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this),this.endEditSession()}beginEditSession(){this.editSessionActive=!0;const e=this.diffCache;e!=null&&!e.isPartial&&e.additionLines.length===0&&(Object.assign(e,Be(e,this.options.parseDiffOptions)),this.markEditSessionPass(e),this.clearRenderCache())}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}refreshHighlightedResult(){const{renderCache:e}=this;if(e==null||ze(e.diff)||Fe(e.diff,this.getTokenizeMaxLength()))return Promise.resolve();const{diff:t}=e,{workerManager:n}=this;return!this.editSessionActive&&n?.isWorkingPool()===!0&&t.cacheKey!=null?(n.evictDiffFromCache(t.cacheKey),n.primeDiffHighlightCache(t).then(()=>{this.applyRefreshedResult(t,n.getDiffResultCache(t))}).catch(i=>this.onHighlightError(i))):this.asyncHighlight(t).then(i=>this.applyRefreshedResult(t,i)).catch(i=>this.onHighlightError(i))}applyRefreshedResult(e,t){if(t==null||this.renderCache==null||this.renderCache.diff!==e||this.editSessionActive)return;const{options:n}=this.getRenderOptions(e);ce(n,t.options)&&(this.renderCache={diff:e,options:t.options,highlighted:!0,result:t.result,renderRange:void 0},this.onRenderUpdate?.())}get diffCache(){return this.renderCache?.diff??this.diff}clearRenderCache(){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,n=this.getOptionsWithDefaults().expansionLineCount){const i={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(i.fromStart+=n),(t==="down"||t==="both")&&(i.fromEnd+=n),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,i)}getExpandedHunk(e){return this.expandedHunks.get(e)??oi}getExpandedHunksMap(){return this.expandedHunks}setExpandedHunksMap(e){this.expandedHunks=e}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const n=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),i=n[t.lineNumber]??[];n[t.lineNumber]=i,i.push(t)}}updateRenderCache(e,t,n=!1){if(this.renderCache==null)return!1;const{result:i,diff:s}=this.renderCache;if(i==null)return!1;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=i.code.additionLines,o=[],a=new Map;for(const[d,h]of e){const u=r[d]?.properties??{},c=h.map(x=>x[2]).join(""),f=d<s.additionLines.length,p=f?s.additionLines[d]??"":"",g=Ze(p);f&&(s.additionLines[d]=vn(p,c),g!==c&&(o.push(d),a.set(d,p))),r[d]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??d+1,"data-line-index":u["data-line-index"]??d,"data-line-type":u["data-line-type"]??"context"},children:h.map(([x,m,L])=>x===0&&m===""?L===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:L}:{type:"element",tagName:"span",properties:{"data-char":x,style:`color:${m};`},children:[{type:"text",value:L}]})}}let l=!1;if(o.length>0)if(this.editSessionActive&&!s.isPartial){if(!n)if(s.additionLines.length<=1&&s.additionLines.join("")==="")Object.assign(s,Be(s,this.options.parseDiffOptions)),this.markEditSessionPass(s),l=!0;else if(nt(s,s.additionLines))Object.assign(s,Oe(s,s.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(s),l=!0;else{const d=os(s,o,this.options.parseDiffOptions,a);this.applyExpansionRemap(d),l=d!=null}}else Object.assign(s,Ji(s,o,this.options.parseDiffOptions));return i.baseThemeType=t,this.renderCache.isDirty=!0,l}applyExpansionRemap(e){e!=null&&(this.expandedHunks=hs(this.expandedHunks,e))}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:n}=this.renderCache;if(n==null)return;if(t.isPartial)throw new Error("Could not apply document change for partial diff");const{additionLines:i}=t;t.additionLines=Us(e,i),n.code.additionLines=Os(i,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join("")===""?(Object.assign(t,Be(t,this.options.parseDiffOptions)),n.code.additionLines[0]=dt(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,dn(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){const{parseDiffOptions:t}=this.options,n=e.additionLines;if(nt(e,n)){Object.assign(e,Oe(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(it(e,t))}markEditSessionPass(e){this.editSessionActive&&(e.editSessionDirty=!0)}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const n=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:n,contentProperties:{"data-line-type":n}}}createAnnotationElement=e=>yn(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:n=!1,disableFileHeader:i=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:d=100,hunkSeparators:h="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=re,headerRenderMode:x="default",tokenizeMaxLineLength:m=1e3,tokenizeMaxLength:L=ai,useTokenTransformer:v=!1,useCSSClasses:C=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:i,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:d,hunkSeparators:h,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:x,tokenizeMaxLineLength:m,tokenizeMaxLength:L,useTokenTransformer:v,useCSSClasses:C}}async initializeHighlighter(){return this.highlighter=await Hn(wn(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),n=Fe(e,this.getTokenizeMaxLength());let i=this.workerManager?.getDiffResultCache(e);i!=null&&!ce(t,i.options)&&(i=void 0),this.renderCache??={diff:e,highlighted:!n&&!ze(e),options:t,result:n?void 0:i?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??_e(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getDiffRenderOptions().theme??this.options.theme??re}getEffectiveCodeOptions(){const e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getDiffRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0){const a=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&a.useTokenTransformer!==!0?{...a,useTokenTransformer:!0}:a}const{theme:i,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:i,useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:n}=this;return n?.result==null?{options:t,forceHighlight:!0}:!me(e,n.diff)||!ce(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=vt){if(e==null)return;const{expandUnchanged:n,collapsedContextThreshold:i}=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||ze(e)||Fe(e,this.getTokenizeMaxLength()),d=!me(e,this.renderCache.diff),h=!Qt(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!l&&!d&<(t);u&&(this.renderCache.highlightPending=!0),!u&&(l||this.renderCache.result==null||!this.renderCache.highlighted&&(d||h))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||d||h||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,lt(t)||n?!0:this.expandedHunks,i)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLang=e.lang??_e(e.name);const u=this.highlighter!=null&&$e(s.theme),c=this.highlighter!=null&&pt(this.computedLang),f=!l&&c;if(this.highlighter!=null&&u&&(r||l||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderDiffWithHighlighter(e,this.highlighter,l||!c);this.renderCache={diff:e,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!l&&!c)&&this.asyncHighlight(e).then(({result:p,options:g})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,p,g,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=vt){const{result:n}=await this.asyncHighlight(e);return this.processDiffResult(e,t,n)}createPreElement(e,t,n){const{diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return En({type:"diff",diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){const t=Fe(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??_e(e.name);const n=this.highlighter!=null&&$e(this.getLocalHighlightTheme()),i=t||this.highlighter!=null&&pt(this.computedLang);return(this.highlighter==null||!n||!i)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,n=!1){const{options:i}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults(),r=An(e,t,i,{forcePlainText:n,expandedHunks:n?!0:void 0,collapsedContextThreshold:s});if(this.editSessionActive&&e.additionLines.length===1&&e.additionLines[0]===""&&r.code.additionLines[0]==null){let o;if(Ce({diff:e,diffStyle:"both",expandedHunks:n?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:a})=>{if(a?.lineIndex===0)return o=a,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=dt(0,"",o.unifiedLineIndex,o.splitLineIndex)}return{result:r,options:i}}onHighlightSuccess(e,t,n,i=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,i)}applyHighlightResult(e,t,n,i=!0){if(this.renderCache==null)return;const s=this.renderCache.highlightPending===!0||!this.renderCache.highlighted||!ce(this.renderCache.options,n)||!me(this.renderCache.diff,e);this.renderCache={diff:e,options:n,highlighted:i,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;const n=this.workerManager?.getDiffResultCache(e);if(!(n==null||!ce(t,n.options)))return n}hasHighlightedRenderCache(e,t){const{renderCache:n}=this;return n?.result!=null&&n.highlighted&&me(e,n.diff)&&ce(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:n,themeStyles:i,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:d,hunkSeparators:h}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1;this.diff=e;const c=r==="unified",f=$s(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],x=[],m=[];const L=[],{additionLines:v,deletionLines:C}=n,S={rowCount:0,hunkSeparators:h,additionsContentAST:g,deletionsContentAST:x,unifiedContentAST:m,unifiedGutterAST:Re(),deletionsGutterAST:Re(),additionsGutterAST:Re(),expansionLineCount:l,hunkData:L,incrementRowCount(E=1){S.rowCount+=E},pushToGutter(E,A){switch(E){case"unified":S.unifiedGutterAST.children.push(A);break;case"deletions":S.deletionsGutterAST.children.push(A);break;case"additions":S.additionsGutterAST.children.push(A);break}}},y=Rn({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"?(S.pushToGutter("additions",V(void 0,"buffer",this.size)),g?.push(Te(this.size))):(S.pushToGutter("deletions",V(void 0,"buffer",this.size)),x?.push(Te(this.size))),this.size=0,this.side=void 0}}},$=(E,A,X,he,w)=>{S.pushToGutter(E,Mn(A,X,he,w))};function b(E){H.flush(),r==="unified"?qe("unified",E,S):(qe("deletions",E,S),qe("additions",E,S))}this.pushFileLevelAnnotations(e,r,t,S),Ce({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:d,callback:({hunkIndex:E,hunk:A,collapsedBefore:X,collapsedAfter:he,additionLine:w,deletionLine:R,type:M})=>{const z=R!=null?R.splitLineIndex:w.splitLineIndex,Y=w!=null?w.unifiedLineIndex:R.unifiedLineIndex;r==="split"&&M!=="change"&&H.flush(),X>0&&b({hunkIndex:E,collapsedLines:X,rangeSize:Math.max(A?.collapsedBefore??0,0),hunkSpecs:A?.hunkSpecs,isFirstHunk:E===0,isLastHunk:!1,isExpandable:p});const ue=r==="unified"?Y:z,Ee={type:M,hunkIndex:E,lineIndex:ue,unifiedLineIndex:Y,splitLineIndex:z,deletionLine:R,additionLine:w};if(r==="unified"){const T=this.getUnifiedInjectedRowsForLine?.(Ee);T?.before!=null&&jt(T.before,S);let N=R!=null?C[R.lineIndex]:void 0,B=w!=null?v[w.lineIndex]:void 0;if(N==null&&B==null){const U="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(U,{file:e.name}),new Error(U)}const ie=M==="change"?w!=null?"change-addition":"change-deletion":M,O=this.getUnifiedLineDecoration({type:M,lineType:ie,additionLineIndex:w?.lineIndex,deletionLineIndex:R?.lineIndex});$("unified",O.gutterLineType,w!=null?w.lineNumber:R.lineNumber,`${Y},${z}`,O.gutterProperties),B!=null?B=Ie(B,O.contentProperties,u&&w!=null?{"data-line":w.lineNumber,"data-line-index":`${Y},${z}`}:void 0):N!=null&&(N=Ie(N,O.contentProperties,u&&R!=null?{"data-line":R.lineNumber,"data-line-index":`${Y},${z}`}:void 0)),De({diffStyle:"unified",type:M,deletionLine:N,additionLine:B,unifiedSpan:this.getAnnotations("unified",R?.lineNumber,w?.lineNumber,E,ue),createAnnotationElement:U=>this.createAnnotationElement(U),context:S}),T?.after!=null&&jt(T.after,S)}else{const T=this.getSplitInjectedRowsForLine?.(Ee);T?.before!=null&&$t(T.before,S,H);let N=R!=null?C[R.lineIndex]:void 0,B=w!=null?v[w.lineIndex]:void 0;const ie=this.getSplitLineDecoration({side:"deletions",type:M,lineIndex:R?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:M,lineIndex:w?.lineIndex});if(N==null&&B==null){const P="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(P,{file:e.name}),new Error(P)}const U=(()=>{if(M==="change"){if(B==null)return"additions";if(N==null)return"deletions"}})();U!=null?(H.side!=null&&H.side!==U&&H.flush(),H.side=U,H.increment()):M==="change"&&H.flush();const Z=this.getAnnotations("split",R?.lineNumber,w?.lineNumber,E,ue);if(Z!=null&&H.size>0&&H.flush(),R!=null){const P=Ie(N,ie.contentProperties,u?{"data-line":R.lineNumber,"data-line-index":`${R.unifiedLineIndex},${z}`}:void 0);$("deletions",ie.gutterLineType,R.lineNumber,`${R.unifiedLineIndex},${z}`,ie.gutterProperties),P!=null&&(N=P)}if(w!=null){const P=Ie(B,O.contentProperties,u?{"data-line":w.lineNumber,"data-line-index":`${w.unifiedLineIndex},${z}`}:void 0);$("additions",O.gutterLineType,w.lineNumber,`${w.unifiedLineIndex},${z}`,O.gutterProperties),P!=null&&(B=P)}De({diffStyle:"split",type:M,additionLine:B,deletionLine:N,...Z,createAnnotationElement:P=>this.createAnnotationElement(P),context:S}),T?.after!=null&&$t(T.after,S,H)}const Le=r==="split"&&A!=null&&z===A.splitLineStart+A.splitLineCount-1,G=E===e.hunks.length-1&&A!=null&&(r==="split"?z===A.splitLineStart+A.splitLineCount-1:Y===A.unifiedLineStart+A.unifiedLineCount-1),Ve=Le?A.noEOFCRDeletions:!1,je=Le?A.noEOFCRAdditions:!1,ne=(R?.noEOFCR??!1)||Ve,W=(w?.noEOFCR??!1)||je;if(W||ne){if(r==="split"&&H.flush(),ne){const T=M==="context"||M==="context-expanded"?M:"change-deletion";r==="unified"?(S.unifiedContentAST.push(Me(T)),S.pushToGutter("unified",V(T,"metadata",1))):(S.deletionsContentAST.push(Me(T)),S.pushToGutter("deletions",V(T,"metadata",1)),W||(S.pushToGutter("additions",V(void 0,"buffer",1)),S.additionsContentAST.push(Te(1))))}if(W){const T=M==="context"||M==="context-expanded"?M:"change-addition";r==="unified"?(S.unifiedContentAST.push(Me(T)),S.pushToGutter("unified",V(T,"metadata",1))):(S.additionsContentAST.push(Me(T)),S.pushToGutter("additions",V(T,"metadata",1)),ne||(S.pushToGutter("deletions",V(void 0,"buffer",1)),S.deletionsContentAST.push(Te(1))))}S.incrementRowCount(1)}h!=="simple"&&h!=="metadata"&&(he>0||G&&f)&&b({hunkIndex:M==="context-expanded"?E:E+1,collapsedLines:G&&f?"unknown":he,rangeSize:y,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),S.incrementRowCount(1)}}),r==="split"&&H.flush();const D=Math.max(Fs(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),we=t.bufferBefore>0||t.bufferAfter>0,de=!c&&e.type!=="deleted",I=!c&&e.type!=="new",j=S.rowCount>0||we;g=de&&j?g:void 0,x=I&&j?x:void 0,m=c&&j?m:void 0;const te=this.createPreElement(x!=null&&g!=null,D);return{unifiedGutterAST:c&&j?S.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:I&&j?S.deletionsGutterAST.children:void 0,deletionsContentAST:x,additionsGutterAST:de&&j?S.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:L,preNode:te,themeStyles:i,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:D,rowCount:S.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const n=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,i=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(n==null||i==null)return;const s=Re(n);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,bn(i,t.rowCount)]}renderFullAST(e,t=[]){const n=this.getOptionsWithDefaults().hunkSeparators==="line-info",i=this.renderCodeAST("unified",e);if(i!=null)return t.push(F({tagName:"code",children:i,properties:{"data-code":"","data-container-size":n?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(F({tagName:"code",children:s,properties:{"data-code":"","data-container-size":n?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(F({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return oe(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?oe(e):oe(F({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,n,i){if(!Jt(n))return;const s=e.type!=="new"?Vt(gt(this.deletionAnnotations)):[],r=e.type!=="deleted"?Vt(gt(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){De({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:i});return}De({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:i})}getAnnotations(e,t,n,i,s){const r={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(Se(a));const o={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(n!=null)for(const a of this.additionAnnotations[n]??[])(e==="unified"?r:o).annotations.push(Se(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:n}=this.getOptionsWithDefaults();return Tn({fileOrDiff:e,mode:t,stickyHeader:n})}};function Vt(e){return e?.map(t=>Se(t))??[]}const zs=new Intl.PluralRules("en-US");function Bs(e){return`${e} unmodified line${zs.select(e)==="one"?"":"s"}`}function jt(e,t){for(const n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function $t(e,t,n){for(const{deletion:i,addition:s}of e){if(i==null&&s==null)continue;const r=i!=null&&s!=null?void 0:i==null?"deletions":"additions";(r==null||n.side!==r)&&n.flush(),i!=null&&(t.deletionsContentAST.push(i.content),t.pushToGutter("deletions",i.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(n.side=r,n.increment()),t.incrementRowCount(1)}}function De({diffStyle:e,type:t,deletionLine:n,additionLine:i,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let d=!1;if(e==="unified"){if(i!=null?l.unifiedContentAST.push(i):n!=null&&l.unifiedContentAST.push(n),s!=null){const h=t==="change"?n!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",V(h,"annotation",1)),d=!0}}else if(e==="split"){if(n!=null&&l.deletionsContentAST.push(n),i!=null&&l.additionsContentAST.push(i),r!=null){const h=t==="change"?n!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",V(h,"annotation",1)),d=!0}if(o!=null){const h=t==="change"?i!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",V(h,"annotation",1)),d=!0}}d&&l.incrementRowCount(1)}function qe(e,{hunkIndex:t,collapsedLines:n,rangeSize:i,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(typeof n=="number"&&n<=0)return;const d=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),d.push(pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const h=Is(e,t),u=i>l.expansionLineCount,c=a?t:void 0,f=typeof n=="number"?Bs(n):"More unchanged context may be available";l.pushToGutter(e,pe({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:l.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:h,hunkIndex:t,lines:typeof n=="number"?n:0,lineCountKnown:typeof n=="number",type:e,expandable:a?{up:!r,down:!o,chunked:u}:void 0})}function Ie(e,t,n){return e==null||e.type!=="element"||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Gt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function Os(e,t,n,i){const s=Gt(e),r=Gt(t),o=Math.min(s,r);let a=0;for(;a<o&&e[a]===t[a];)a++;let l=0;for(;l<o-a&&e[s-1-l]===t[r-1-l];)l++;const d=new Array(t.length);for(let h=0;h<a;h++)d[h]=n[h];for(let h=0;h<l;h++)d[r-1-h]=n[s-1-h];s<e.length&&r<t.length&&(d[t.length-1]=n[e.length-1]);for(let h=e.length;h<t.length;h++)d[h]??=n[h];for(let h=a;h<t.length;h++)d[h]??=dt(h,i.getLineText(h));return d}function dt(e,t,n=e,i=e){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${n},${i}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t}]}]}}function Us(e,t){const n=[],i=js(t);for(let s=0;s<e.lineCount;s++){const r=e.getLineText(s,!0);n.push(s<e.lineCount-1&&!Vs(r)?r+i:r)}return n}function Vs(e){return e.endsWith(`
|
|
21
21
|
`)||e.endsWith("\r")}function js(e){for(const t of e){if(t.endsWith(`\r
|
|
22
22
|
`))return`\r
|
|
23
23
|
`;if(t.endsWith(`
|
|
24
24
|
`))return`
|
|
25
25
|
`;if(t.endsWith("\r"))return"\r"}return`
|
|
26
|
-
`}function Fe(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function $s(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Gs(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Ws(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function _s(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:Dn(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}function Ks(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}let qs=-1;var pn=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++qs}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:re},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new In,this.scrollSyncManager=new Ds,this.interactionManager=new Fn("diff",mt(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 _s(e)}createHunksRenderer(e){return new Ps(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const n=this.fileDiffCache;if(n==null)return;const i=n.hunks.at(-1);let s,r;e:for(const o of n.hunks){const a=t==="deletions"?o.deletionStart:o.additionStart,l=t==="deletions"?o.deletionCount:o.additionCount;let d=xe(a,l)+1,h=o.splitLineStart,u=o.unifiedLineStart;if(e<d){const c=d-e;s=Math.max(u-c,0),r=Math.max(h-c,0);break e}if(e>=d+l){if(o===i){const c=e-(d+l);s=u+o.unifiedLineCount+c,r=h+o.splitLineCount+c;break e}continue}for(const c of o.hunkContent)if(c.type==="context")if(e<d+c.lines){const f=e-d;r=h+f,s=u+f;break e}else d+=c.lines,h+=c.lines,u+=c.lines;else{const f=t==="deletions"?c.deletions:c.additions;if(e<d+f){const p=e-d;s=u+(t==="additions"?c.deletions:0)+p,r=h+p;break e}else d+=f,h+=Math.max(c.deletions,c.additions),u+=c.deletions+c.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(mt(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&&!Nn(this.appliedThemeCSS.theme,this.options.theme??re)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}flushDeferredLineState(){const{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t==="wrap",columnVariables:this.shouldApplyColumnVariables(t)?"apply":"measure"}),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators=="function"?!0:e==="scroll"&&(this.lineAnnotations.length>0||this.pre?.hasAttribute("data-has-merge-conflict")===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){li(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:i,fileDiff:s,...r}){if(!this.enabled)throw new Error("FileDiff.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated");const o=rt(r,"FileDiff.hydrate"),a=o?.oldFile,l=o?.newFile;this.hydrateElements(e,t),Qs(this.pre,Xs({fileDiff:s,oldFile:a,newFile:l}),this.options.collapsed)||Zs(this.headerElement,Ys({fileDiff:s,oldFile:a,newFile:l}),this.options.disableFileHeader)?this.render({...r,fileContainer:e,lineAnnotations:i,fileDiff:s,preventEmit:!0}):this.hydrationSetup({fileDiff:s,lineAnnotations:i,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Pn(e,t);for(const n of e.shadowRoot?.children??[]){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n;for(const i of n.children)!(i instanceof HTMLElement)||i.tagName.toLowerCase()!=="code"||("deletions"in i.dataset&&(this.codeDeletions=i),"additions"in i.dataset&&(this.codeAdditions=i),"unified"in i.dataset&&(this.codeUnified=i));continue}if("diffsHeader"in n.dataset){this.headerElement=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:i}){this.lineAnnotations=i??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?ae(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){const{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Ks(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{const n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(n){if(this.options.disableErrorHandling===!0)throw n;console.error(n)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(at("merge",e,t),this.setHydratedState(t),await st(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:i=!1,lineAnnotations:s,fileContainer:r,containerWrapper:o,renderRange:a,...l}){const d=rt(l,"FileDiff.render"),h=d?.oldFile,u=d?.newFile;if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName!=null?e.prevName+":"+e.name:e.name),this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:c=!1,themeType:f="system",expandUnchanged:p=!1}=this.options,g=c?void 0:a,x=this.hasThemeChanged(),m=d!=null,L=m&&(!Wt(h,this.deletionFile)||!Wt(u,this.additionFile));let v=e!=null&&e!==this.fileDiff;const C=s!=null&&(s.length>0||this.lineAnnotations.length>0)?s!==this.lineAnnotations:!1;if(!c&&Zt(g,this.renderRange)&&!n&&!C&&!x&&(e!=null&&e===this.fileDiff||e==null&&!L))return this.applyCachedThemeState(f);let S;e==null&&m&&(L||this.fileDiff==null)&&(S=ae(d.oldFile,d.newFile,this.options.parseDiffOptions));const{renderRange:y}=this;if(this.renderRange=g,m?(this.deletionFile=h,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null?this.fileDiff=e:S!=null&&(v=!0,this.fileDiff=S),v&&(this.cachedHeaderHTML=void 0),s!=null&&this.setLineAnnotations(s),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(Pt(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),p&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:H=!1,disableFileHeader:$=!1}=this.options;if($&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),r=this.getOrCreateFileContainer(r,o),this.applyCachedThemeState(f),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const b=this.hunksRenderer.renderDiff(this.fileDiff,di);b!=null&&this.applyThemeState(r,b.themeStyles,f,b.baseThemeType),b?.headerElement!=null&&this.applyHeaderToDOM(b.headerElement,r),this.renderSeparators([]),this.injectUnsafeCSS()}catch(b){if(H)throw b;console.error(b),b instanceof Error&&this.applyErrorToDOM(b,r)}return i||this.emitPostRender(),!0}try{const b=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(n,C,L||v||x)&&this.applyPartialRender({previousRenderRange:y,renderRange:g}))){const D=this.hunksRenderer.renderDiff(this.fileDiff,g);if(D==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(r,D.themeStyles,f,D.baseThemeType),D.headerElement!=null&&this.applyHeaderToDOM(D.headerElement,r),D.additionsContentAST!=null||D.deletionsContentAST!=null||D.unifiedContentAST!=null?this.applyHunksToDOM(b,D):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(D.hunkData)}this.applyBuffers(b,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(b){if(H)throw b;console.error(b),b instanceof Error&&this.applyErrorToDOM(b,r)}return i||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const i=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,i)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.fileDiffCache,i=this.lineAnnotations,s=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(r=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(r,t,n,i,s)})}computeEditorRenderRange(e){const t=this.fileDiffCache;if(e==null||t==null||lt(e))return e;const{diffStyle:n="split",expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return Ce({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:a})=>{a!=null&&(r??=a.lineNumber,o=a.lineNumber)}}),r==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:r-1,totalLines:o-r+1}}attachEditor(e){if(this.type!=="file-diff")throw new Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),t=>{this.editor=void 0,t!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){const e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;const{collapsedContextThreshold:t=1}=this.options,n=us(e,this.hunksRenderer.getExpandedHunksMap(),t);return Pt(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(cs(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);const n=this.hunksRenderer.diffCache;if(n!=null){const i=this.fileDiff?.cacheKey;i!=null&&n.cacheKey==null&&(n.cacheKey=i),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){const{shouldRefreshDiffsView:i,lineCountChangeInFlight:s}=n;if(this.hunksRenderer.updateRenderCache(e,t,s)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}i===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle==="split"?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){const t=this.fileDiffCache;if(t==null)return!0;const{expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options;return en({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}getNearestRenderableLine(e,t){const n=this.fileDiffCache;if(n==null)return e;const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;return zn({fileDiff:n,lineNumber:e,direction:t,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s})}revealLine(e){const t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:i=1,expansionLineCount:s=100}=this.options;if(t==null||t.isPartial||n)return!1;const r=this.hunksRenderer.getExpandedHunksMap();for(const[d,h]of t.hunks.entries()){const[u,c]=Ct(h);if(e<u){const f=ve({isPartial:t.isPartial,rangeSize:h.collapsedBefore,expandedHunks:r,hunkIndex:d,collapsedContextThreshold:i}),p=u-f.rangeSize;if(f.renderAll||e<p+f.fromStart||e>=u-f.fromEnd)return!1;const g=e-(p+f.fromStart)+1,x=u-f.fromEnd-e;return g<=x?this.expandHunk(d,"up",g+s):this.expandHunk(d,"down",x+s),!0}if(e<c)return!1}const o=ye({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:i,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const a=t.hunks[t.hunks.length-1],[,l]=Ct(a);return e<l+o.fromStart||e>=l+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(l+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){hi(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(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}async primeHighlightCache(e=this.fileDiff){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||ze(e))return;const n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(i=>{console.error(i)})}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:i}of this.separatorCache.values())i.remove();this.separatorCache.clear();return}const n=new Map(this.separatorCache);for(const i of e){const s=i.slotName;let r=this.separatorCache.get(s);if(r==null||!Ws(i,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=i.slotName;const a=t(i,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:i},this.separatorCache.set(s,r)}n.delete(s)}for(const[i,{element:s}]of n.entries())this.separatorCache.delete(i),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,i]of this.lineAnnotations.entries()){const s=`${n}-${Se(i)}`;let r=this.annotationCache.get(s);if(r==null||!Gs(i,r.annotation)){r?.element.remove();const o=t(i);if(o==null)continue;r={element:Bn(Se(i)),annotation:i},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[n,{element:i}]of e.entries())this.annotationCache.delete(n),i.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=On();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){const{fileContainer:n}=this,i=e??n??document.createElement("diffs-container"),s=n!==i;return n!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=i,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:St(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):St(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=Un;const i=n.firstChild;i instanceof SVGElement&&(this.spriteSVG=i)}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&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(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:n}=this,i=this.cachedHeaderHTML??oe(e);if(this.cachedHeaderHTML=i,i!==this.lastRenderedHeaderHTML){const u=document.createElement("div");u.innerHTML=i;const c=u.firstElementChild;if(!(c instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(c,this.headerElement):t.shadowRoot?.prepend(c),this.headerElement=c,this.lastRenderedHeaderHTML=i}if(this.isContainerManaged||n==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const u=s(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,sn,u),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?.(n)??void 0,d=o?.(n)??void 0,h=a?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ui,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,ci,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,fi,h),this.headerCustom?.remove(),this.headerCustom=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,i){if(i==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,i),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??=Vn(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=jn(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,i){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=i??n,o=this.options.theme??re,a=typeof o=="string"?o:{...o},l=xt(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:i,scrollbarGutter:l};return}this.themeCSSStyle=$n({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Kn(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Gn(this.themeCSSStyle.textContent??"",xt(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&pi()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?Lt(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){const i=this.getColumnPair(e);if(i==null)return!1;const s=J(t[0]),r=J(t[1]);return s==null||r==null?!1:(i.gutter.innerHTML=oe(s),i.content.innerHTML=oe(r),n!==this.lastRowCount&&(i.gutter.style.setProperty("grid-row",`span ${n}`),i.content.style.setProperty("grid-row",`span ${n}`)),!0)}replaceCodeColumns(e,t){const{overflow:n="scroll"}=this.options,i=(this.options.hunkSeparators??"line-info")==="line-info",s=n==="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),d=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),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=Ge({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeUnified,a,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a)),o.push(this.codeUnified)):l!=null||d!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ge({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeDeletions,l,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),d!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ge({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeAdditions,d,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(d)),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:n,codeUnified:i,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,i,r,s);if(a==null)return!1;const l=e.startingLine,d=t.startingLine,h=l+e.totalLines,u=d+t.totalLines,c=Math.max(l,d),f=Math.min(h,u);if(f<=c)return!1;const p=Math.max(0,c-l),g=Math.max(0,h-f),x=this.trimColumns({columns:a,trimStart:p,trimEnd:g,previousStart:l,overlapStart:c,overlapEnd:f,diffStyle:o});if(x<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<x)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let m=this.lastRowCount-x;const L=(y,H)=>{if(!(H<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:y,totalLines:H,bufferBefore:0,bufferAfter:0})},v=L(d,Math.max(c-d,0));if(v==null&&d<c)return!1;const C=L(f,Math.max(u-f,0));if(C==null&&u>f)return!1;const S=(y,H)=>{if(y!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,y,H);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,y,H);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");m+=y.rowCount}};return this.cleanupErrorWrapper(),S(v,"afterbegin"),S(C,"beforeend"),this.lastRowCount!==m&&(this.applyRowSpan(o,a,m),this.lastRowCount=m),!0}insertPartialHTML(e,t,n,i){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",n);this.renderPartialColumn(t,s,i)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",n),r=this.hunksRenderer.renderCodeAST("additions",n);this.renderPartialColumn(t[0],s,i),this.renderPartialColumn(t[1],r,i)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}refreshSplitDiffView(){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 n=(i,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(i,e),o=J(r?.[0]),a=J(r?.[1]);for(const[l,d]of[[s.gutter,o],[s.content,a]])if(d!=null&&l.childElementCount===d.length)for(let h=0;h<d.length;h++){const u=l.children[h],c=d[h].properties["data-line-type"];c!=null&&u.dataset.lineType!==c&&(u.dataset.lineType=c)}};n("deletions",t[0]),n("additions",t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!=="unified")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("unified",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;const n=this.hunksRenderer.renderCodeAST("unified",e),i=J(n?.[0]),s=J(n?.[1]),r=()=>{for(const[o,a]of[[t.gutter,i],[t.content,s]])a!=null&&(o.innerHTML=oe(a));e.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?Lt(this.pre,r):r(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;const i=J(t[0]),s=J(t[1]);if(i==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);n==="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],i,s,!0);const o=s.at(-1);n==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],i,s,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,n,i,s,r){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(i.shift(),s.shift()):(i.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){const i=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${n}`),s.content.style.setProperty("grid-row",`span ${n}`))};if(e==="unified"&&!Array.isArray(t))i(t);else if(e==="split"&&Array.isArray(t))i(t[0]),i(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,n){let i=0,s=0,r=0,o=!1;const a=n>=0;if(e==null)return 0;const l=Array.from(e.content.children),d=Array.from(e.gutter.children);if(l.length!==d.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const h=d[r],u=l[r];if(r++,!(h instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:h,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){h.remove(),u.remove(),s++;continue}if("lineIndex"in h.dataset&&"lineIndex"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),s++),i++;continue}if("separator"in h.dataset&&"separator"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){const c=this.getBufferSize(u.dataset);if(c==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const f=Math.min(t,c),p=c-f;p>0?(this.updateBufferSize(h,p),this.updateBufferSize(u,p),s+=f):(h.remove(),u.remove(),s+=c),t-=f,t===0&&p===0&&(o=!0)}else if(a){const f=i,p=i+c-1;if(n<=f)h.remove(),u.remove(),s+=c;else if(n<=p){const g=p-n+1,x=c-g;this.updateBufferSize(h,x),this.updateBufferSize(u,x),s+=g}}i+=c;continue}throw console.error({gutterElement:h,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:i,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,i-s),l=n-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const d=o>0,h=r>0;if(!d&&!h)return 0;const u=d?a:0,c=h?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,c);if(t==="split"&&Array.isArray(e)){const f=this.trimColumnRows(e[0],u,c),p=this.trimColumnRows(e[1],u,c);if(e[0]!=null&&e[1]!=null&&f!==p)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?f:p}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)`)}getColumnPair(e){if(e==null)return;const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}getCodeColumns(e,t,n,i){if(e==="unified")return this.getColumnPair(t);{const s=this.getColumnPair(n),r=this.getColumnPair(i);return s!=null||r!=null?[s,r]: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:n,totalLines:i},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:d="split"}=this.options,h={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:d==="unified"?!1:t!=null&&n!=null,totalLines:i,customProperties:s};Wn(h,this.appliedPreAttributes)||(_n(e,h),this.appliedPreAttributes=h)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const i=document.createElement("div");i.dataset.errorMessage="",i.innerText=e.message,this.errorWrapper.appendChild(i);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 Wt(e,t){return e==null||t==null?e==null&&t==null:tn(e,t)}function Xs({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Ys({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Qs(e,t,n=!1){return!n&&e==null&&t}function Zs(e,t,n=!1){return e==null&&t&&!n}function J(e){if(!(e==null||e.type!=="element"))return e.children??[]}const ht=3e3;let Js=-1;var er=class extends pn{__id=`little-virtualized-file-diff:${++Js}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,i,s=!1){super(e,i,s),this.virtualizer=t,this.metrics=We(n)}setMetrics(e,t=!1){const n=We(e);!t&&qn(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){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||!Xn(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,n=!nn(t,e),i=n&&or(t,e);super.setOptions(e),i&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:ar(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,i)}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,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1;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 n=this.getDiffStyle(),i=n==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Jt(this.renderRange)){const r=tr(i)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of i){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 d=dr(l,n);let h=a.getBoundingClientRect().height,u=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(u=!0),h+=a.nextElementSibling.getBoundingClientRect().height);const c=this.getEstimatedLineHeight(u),f=this.cache.heightDeltas.get(d)??0,p=h-c;p!==f&&(e=!0,this.cache.measuredHeightDeltaTotal+=p-f,p===0?this.cache.heightDeltas.delete(d):this.cache.heightDeltas.set(d,p))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,i){const s=!me(this.fileDiff,e),r=this.syncLineAnnotations(i);let o=n?.resetDiffLayoutCache===!0||s||r,a=s||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=We(n.metrics),o=!0,a=!0);const{collapsed:l=!1,expandUnchanged:d=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),this.currentExpandUnchanged!==d&&(this.currentExpandUnchanged=d,o=!0,a=!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 n=this.getLineIndex(e,t);if(n==null)return;const{disableFileHeader:i=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),d=a==="split"?n[1]:n[0];this.approximateLayoutCheckpoints();const h=ge(this.metrics,i),u=this.getLayoutCheckpointBeforeLineIndex(d);let c=u?.top??h+this.cache.fileAnnotationHeight;if(r)return{top:h,height:0};let f;return Ce({diff:this.fileDiff,diffStyle:a,startingLine:u?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:p,hunk:g,collapsedBefore:x,collapsedAfter:m,deletionLine:L,additionLine:v})=>{const C=a==="split"?v?.splitLineIndex??L?.splitLineIndex:v?.unifiedLineIndex??L?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(x>0){const y=ke({type:l,metrics:this.metrics,hunkIndex:p,hunkSpecs:g?.hunkSpecs});if(y!=null){if(c+=y.gapBefore,d>=C-x&&d<C)return f={top:c,height:y.height},!0;c+=y.height+y.gapAfter}}const S=this.getLineHeight(C,(v?.noEOFCR??!1)||(L?.noEOFCR??!1));if(C===d)return f={top:c,height:S},!0;if(c+=S,m>0){const y=se({type:l,metrics:this.metrics});if(y!=null){if(d>C&&d<=C+m)return f={top:c+y.gapBefore,height:y.height},!0;c+=y.totalHeight}}return!1}}),f}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:i=!1,collapsedContextThreshold:s=1}=this.options;if(i)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??ge(this.metrics,t)+this.cache.fileAnnotationHeight,d;return Ce({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:h,hunk:u,collapsedBefore:c,collapsedAfter:f,deletionLine:p,additionLine:g})=>{const x=r==="split"?g?.splitLineIndex??p?.splitLineIndex:g?.unifiedLineIndex??p?.unifiedLineIndex;if(x==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(c>0){const L=ke({type:o,metrics:this.metrics,hunkIndex:h,hunkSpecs:u?.hunkSpecs});L!=null&&(l+=L.totalHeight)}if(l>=e&&(p!=null?d={lineNumber:p.lineNumber,side:"deletions",top:l}:g!=null&&(d={lineNumber:g.lineNumber,side:"additions",top:l}),d!=null))return!0;const m=this.getLineHeight(x,(g?.noEOFCR??!1)||(p?.noEOFCR??!1));if(l+=m,f>0){const L=se({type:o,metrics:this.metrics});L!=null&&(l+=L.totalHeight)}return!1}}),d}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:n,bufferAfter:i,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=i)}return{topOffset:this.top+n+r,height:this.height-(n+i)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){const n=at("clone",e,t);if(await st(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(at("merge",e,t),this.setHydratedState(t),await st(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n;const{pendingExpansions:i,pendingHydratedDiff:s}=this;if(i!=null){this.pendingExpansions=void 0;for(const r of i)this.hunksRenderer.expandHunk(r.hunkIndex,r.direction,r.expansionLineCountOverride),t=!0}return s!=null&&(this.pendingHydratedDiff=void 0,s.expectedDiff===e&&(this.setHydratedState(s.files),n=s.nextDiff)),n!=null?(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})):t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;const{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;const{expansionLineCount:i=100,collapsedContextThreshold:s=1}=this.options,r=new Map(this.hunksRenderer.getExpandedHunksMap());for(const o of t){const a={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},l=o.expansionLineCountOverride??i;(o.direction==="up"||o.direction==="both")&&(a.fromStart+=l),(o.direction==="down"||o.direction==="both")&&(a.fromEnd+=l),r.set(o.hunkIndex,a)}return en({fileDiff:n,lineNumber:e,expandedHunks:r,collapsedContextThreshold:s})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){const{renderRange:i}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&i!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==i.bufferAfter&&this.updateBuffers(r)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){const n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}const{disableFileHeader:s=!1,collapsed:r=!1}=this.options,o=ge(this.metrics,s);if(this.height+=o,r){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!i&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);const t=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:s,unifiedHeight:r}=vs({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,canHydratePartialDiff:Xe(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=s,this.cache.estimatedUnifiedHeight=r}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;const t=this.fileContainer.getBoundingClientRect();t.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:t.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:i,...s}={}){const r=rt(s,"VirtualizedFileDiff.render"),o=r!=null,a=r?.oldFile,l=r?.newFile,d=o&&(!qt(a,this.deletionFile)||!qt(l,this.additionFile));let h=t??this.fileDiff;t==null&&o&&(d||this.fileDiff==null)&&(h=ae(r.oldFile,r.newFile,this.options.parseDiffOptions));const{forceRenderOverride:u,isSetup:c}=this;this.forceRenderOverride=void 0;const f=this.syncLineAnnotations(i);f&&this.resetLayoutCache({includeEstimatedHeights:!1});const p=t!=null&&t!==this.fileDiff,g=h!=null&&!me(this.fileDiff,h),x=p||d;if(g&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),h==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(c)this.top??=this.getVirtualizedTop(),g&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,h));else{this.computeApproximateSize(!1,h);const S=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(S==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");S.connect(e,this),this.isVisible=S.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!x||!c))return this.fileDiff=h,r!=null&&(this.deletionFile=a,this.additionFile=l),g&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const m=this.virtualizer.getWindowSpecs(),L=this.top??0,v=this.computeRenderRangeFromWindow(h,L,m),C=super.render({fileDiff:h,fileContainer:e,renderRange:v,lineAnnotations:i,forceRender:(u??n)||f||g,...r,...s});return this.isSimpleMode()&&C&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),C}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return lr(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options,s=e.hunks.length-1,r=Xe(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),a=this.getHunkSeparatorType(),l=n?!0:this.hunksRenderer.getExpandedHunksMap(),d=nr(this.cache.heightDeltas);let h=ge(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:x=0,metadataOffsets:m=[]})=>{if(f<=0)return;const L=u,v=u+f;let C=ir(L);for(;C<v;){const S=C-L,y=h+(S>0?g:0)+S*this.metrics.lineHeight+sr(m,S)*this.metrics.lineHeight+_t(d,p,p+S);this.cache.checkpoints.push({renderedLineIndex:C,lineIndex:p+S,top:y}),C+=ht}h+=g+f*this.metrics.lineHeight+m.length*this.metrics.lineHeight+_t(d,p,p+f)+x,u=v};for(let f=0;f<e.hunks.length;f++){const p=e.hunks[f];if(p==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const g=ve({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:l,hunkIndex:f,collapsedContextThreshold:i}),x=g.collapsedLines>0?ke({type:a,metrics:this.metrics,hunkIndex:f,hunkSpecs:p.hunkSpecs})?.totalHeight??0:0;c({rowCount:g.fromStart,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.rangeSize});let m=x;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:m}),g.fromEnd>0&&(m=0);const L=f===s?ye({fileDiff:e,hunkIndex:f,expandedHunks:l,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,v=L!=null&&L.collapsedLines>0?se({type:a,metrics:this.metrics})?.totalHeight??0:f===s&&r?se({type:a,metrics:this.metrics})?.totalHeight??0:0,C=L!=null?L.fromStart+L.fromEnd:0,S=o==="split"?p.splitLineCount:p.unifiedLineCount,y=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:S,startLineIndex:y,preSeparatorHeight:m,postSeparatorHeight:C===0?v:0,metadataOffsets:rr({diffStyle:o,hunk:p,rowCount:S})}),L!=null&&C>0&&c({rowCount:C,startLineIndex:y+S,postSeparatorHeight:v})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,i;for(;t<=n;){const s=t+n>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(i=r,t=s+1):n=s-1}return i}getLayoutCheckpointBeforeTop(e,t){let n=0,i=this.cache.checkpoints.length-1,s=-1;for(;n<=i;){const r=n+i>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,n=r+1):i=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 n=0;if(e.isPartial){for(const a of e.hunks)n+=t==="split"?a.splitLineCount:a.unifiedLineCount;return n}const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options,r=i?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const d=t==="split"?l.splitLineCount:l.unifiedLineCount;n+=d;const h=Math.max(l.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=ve({isPartial:e.isPartial,rangeSize:h,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});h>0&&(n+=f?h:u+c)}const o=ye({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){const n=this.getExpandedLineCount(e,t),i=t==="split"?e.splitLineCount:e.unifiedLineCount;return Math.max(n,i,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:i}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,d=this.getDiffStyle(),h=this.getHunkSeparatorType(),u=Xe(e,this.options.loadDiffFiles!=null),c=this.height;let f=this.getLayoutLineCount(e,d);const p=ge(this.metrics,s),g=e.hunks.length>0?Qt(this.metrics):0,{fileAnnotationHeight:x}=this.cache,m=p+x,L=Math.max(0,c-p-x-g),v=this.hasFileAnnotations(e),C=t+p,S=x>0&&v&&C<i&&C+x>n;if(t<n-c||t>i)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,d);const y=Math.ceil(Math.max(i-n,0)/l),H=Math.ceil(y/a)*a+a,$=H/a,b=$,D=[],we=(n+i)/2,de=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-H*l*2),a);let I=t+(de?.top??m),j=de?.renderedLineIndex??0,te,E,A;if(Ce({diff:e,diffStyle:d,startingLine:de?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:Le,hunk:G,collapsedBefore:Ve,collapsedAfter:je,deletionLine:ne,additionLine:W})=>{const T=W!=null?W.splitLineIndex:ne.splitLineIndex,N=W!=null?W.unifiedLineIndex:ne.unifiedLineIndex,B=(W?.noEOFCR??!1)||(ne?.noEOFCR??!1),ie=Le===e.hunks.length-1&&G!=null&&(d==="split"?T===G.splitLineStart+G.splitLineCount-1:N===G.unifiedLineStart+G.unifiedLineCount-1),O=(Ve>0?ke({type:h,metrics:this.metrics,hunkIndex:Le,hunkSpecs:G?.hunkSpecs}):void 0)?.totalHeight??0;I+=O;const U=j%a===0,Q=Math.floor(j/a);if(U&&(D[Q]=I-(t+m+O),A!=null)){if(A<=0)return!0;A--}const P=this.getLineHeight(d==="split"?T:N,B);if(I>n-P&&I<i&&(te??=Q),E==null&&I+P>we&&(E=Q),A==null&&I>=i&&U&&(A=b),j++,I+=P,je>0||ie&&u){const Ae=se({type:h,metrics:this.metrics});Ae!=null&&(I<i&&I+Ae.totalHeight>n&&(te??=Q),E==null&&I+Ae.totalHeight>we&&(E=Q),I+=Ae.totalHeight)}return!1}}),te==null)if(S)te=0,E=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};E??=te;const X=Math.round(E-$/2),he=Math.max(0,Math.ceil(f/a)-$),w=Math.max(0,Math.min(X,he)),R=w*a,M=X<0?H+X*a:H,z=D[w]??0,Y=R===0?0:x+z,ue=w+M/a,Ee=ue<D.length?L-D[ue]:L-(I-t-m);return{startingLine:R,totalLines:M,bufferBefore:Y,bufferAfter:Math.max(0,Ee)}}};function tr(e){let t;for(const n of e){if(n==null)continue;const i=n.children[1];if(i instanceof HTMLElement)for(const s of i.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Yn&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function nr(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),n=[],i=[0];let s=0;for(const[r,o]of t)n.push(r),s+=o,i.push(s);return{lineIndexes:n,prefixTotals:i}}function _t({lineIndexes:e,prefixTotals:t},n,i){if(n>=i||e.length===0)return 0;const s=Kt(e,n);return(t[Kt(e,i)]??0)-(t[s]??0)}function Kt(e,t){let n=0,i=e.length;for(;n<i;){const s=n+i>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?n=s+1:i=s}return n}function ir(e){return Math.ceil(e/ht)*ht}function sr(e,t){let n=0;for(const i of e)i<t&&n++;return n}function rr({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const i=t.hunkContent.at(-1);if(i==null)return[];if(i.type==="context")return[n-1];const s=Math.max(i.deletions,i.additions),r=i.deletions+i.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];const o=[],a=n-r;return i.deletions>0&&t.noEOFCRDeletions&&o.push(a+i.deletions-1),i.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function or(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function ar(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Xe(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function lr(e){return typeof e=="function"?"custom":e??"line-info"}function qt(e,t){return e==null||t==null?e==null&&t==null:tn(e,t)}function dr(e,t){const[n,i]=e.split(",").map(Number);return t==="split"?i:n}const Xt=typeof window>"u"?ee.useEffect:ee.useLayoutEffect;function hr({fileDiff:e,options:t,editorOptions:n,lineAnnotations:i,selectedLines:s,prerenderedHTML:r,metrics:o,hasGutterRenderUtility:a,hasCustomHeader:l,disableWorkerPool:d,edit:h}){const u=Qn(),c=s!==void 0,f=ee.useContext(Zn),p=mi(),g=ee.useRef(null),x=Ci(m=>{if(m!=null){if(g.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");u!=null?g.current=new er(Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),u,o,d?void 0:f,!0):g.current=new pn(Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),d?void 0:f,!0),g.current.hydrate({fileDiff:e,fileContainer:m,lineAnnotations:i,prerenderedHTML:r})}else{if(g.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");g.current.cleanUp(),g.current=null}});return Xt(()=>{const{current:m}=g;if(m==null)return;const L=Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),v=L!==void 0&&!nn(m.options,L);m.setOptions(L),m.render({forceRender:v,fileDiff:e,lineAnnotations:i}),s!==void 0&&m.setSelectedLines(s)}),Xt(()=>{if(h&&g.current!=null){if(p===void 0)throw new Error("FileDiff: EditContext is not attached");const m=p(n??{});if(m==null)throw new Error("FileDiff: EditProvider.createEditor must return an editor instance");try{return m.edit(g.current)}catch(L){throw m.cleanUp(),L}}},[h]),{ref:x,getHoveredLine:ee.useCallback(()=>g.current?.getHoveredLine(),[])}}function Ye({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:i}){return t||i||n?{...e,controlledSelection:t,renderCustomHeader:n?kt:e?.renderCustomHeader,renderGutterUtility:i?kt:e?.renderGutterUtility}:e}function ur({patch:e,options:t,editorOptions:n,metrics:i,lineAnnotations:s,selectedLines:r,className:o,style:a,prerenderedHTML:l,renderAnnotation:d,renderCustomHeader:h,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderGutterUtility:p,disableWorkerPool:g=!1,edit:x=!1}){const m=cr(e),{ref:L,getHoveredLine:v}=hr({fileDiff:m,options:t,editorOptions:n,metrics:i,lineAnnotations:s,selectedLines:r,prerenderedHTML:l,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:g,edit:x});return k.jsx(gi,{ref:L,className:o,style:a,children:Jn(Vi({fileDiff:m,renderCustomHeader:h,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderAnnotation:d,lineAnnotations:s,renderGutterUtility:p,getHoveredLine:v}),l)})}function cr(e){return ee.useMemo(()=>ei(e),[e])}function vr({contentKey:e,diff:t,diffView:n,themeType:i,wrapLines:s,initiallyCollapsed:r=!1,compact:o=!1,scopeControl:a,onDiffViewChange:l,onWrapLinesChange:d,onClose:h}){const u=ee.useMemo(()=>ti(t.patch),[t.patch]),[c,f]=ee.useState(()=>new Set(r?u.map(C=>C.key):[])),p=u.length>0&&u.every(C=>c.has(C.key)),g=u.reduce((C,S)=>C+S.additions,0),x=u.reduce((C,S)=>C+S.deletions,0),m=C=>{f(S=>{const y=new Set(S);return y.has(C)?y.delete(C):y.add(C),y})},L=()=>f(p?new Set:new Set(u.map(C=>C.key))),v=C=>k.jsxs("div",{className:"diff-workspace-actions",children:[C&&k.jsx(Ne,{label:p?"Expand all files":"Collapse all files",onClick:L,children:p?k.jsx(yi,{}):k.jsx(wi,{})}),k.jsx(Ne,{label:n==="unified"?"Use split diff":"Use unified diff",pressed:n==="split",onClick:()=>l?.(n==="unified"?"split":"unified"),children:n==="unified"?k.jsx(Ai,{}):k.jsx(bi,{})}),k.jsx(Ne,{label:s?"Disable line wrapping":"Wrap long lines",pressed:s,onClick:()=>d?.(!s),children:k.jsx(Mi,{})}),h&&k.jsx(Ne,{label:"Close diff",onClick:h,children:k.jsx(ki,{})})]});return k.jsxs("div",{className:`diff-workspace${o?" compact":""}`,children:[!o&&k.jsxs("div",{className:"diff-workspace-toolbar",children:[a&&k.jsx("div",{className:"diff-workspace-scope",children:a}),k.jsxs("span",{className:"diff-file-count",children:[u.length," ",u.length===1?"file":"files"]}),k.jsxs("span",{className:"diff-total-stats","aria-label":`${g} additions and ${x} deletions`,children:[k.jsxs("span",{className:"add",children:["+",g]}),k.jsxs("span",{className:"del",children:["−",x]})]}),v(!0)]}),k.jsx(ni,{className:"diff-workspace-scroll",contentClassName:"diff-workspace-content",children:u.map(C=>{const S=!o&&c.has(C.key);return k.jsxs("section",{className:"diff-file-section",children:[o?k.jsxs("div",{className:"diff-file-header diff-file-header-compact",children:[k.jsx("img",{src:yt(C.path),className:"diff-file-icon",alt:""}),k.jsxs(Ze,{children:[k.jsx(Je,{render:k.jsx("span",{className:"diff-file-path"}),children:k.jsx(Yt,{path:C.path})}),k.jsx(et,{children:C.path})]}),C.previousPath&&C.previousPath!==C.path&&k.jsxs("span",{className:"diff-file-previous",children:["from ",C.previousPath]}),k.jsxs("span",{className:"diff-file-stats",children:[k.jsxs("span",{className:"add",children:["+",C.additions]}),k.jsxs("span",{className:"del",children:["−",C.deletions]})]}),v(!1)]}):k.jsxs(Ze,{children:[k.jsxs(Je,{render:k.jsx("button",{type:"button",className:"diff-file-header","aria-expanded":!S,onClick:()=>m(C.key)}),children:[S?k.jsx(xi,{className:"diff-file-chevron"}):k.jsx(Li,{className:"diff-file-chevron"}),k.jsx("img",{src:yt(C.path),className:"diff-file-icon",alt:""}),k.jsx("span",{className:"diff-file-path",children:k.jsx(Yt,{path:C.path})}),C.previousPath&&C.previousPath!==C.path&&k.jsxs("span",{className:"diff-file-previous",children:["from ",C.previousPath]}),k.jsxs("span",{className:"diff-file-stats",children:[k.jsxs("span",{className:"add",children:["+",C.additions]}),k.jsxs("span",{className:"del",children:["−",C.deletions]})]})]}),k.jsx(et,{children:C.path})]}),!S&&k.jsx(ur,{patch:C.patch,disableWorkerPool:t.lineCount>1e4,options:{diffStyle:n,diffIndicators:"classic",themeType:i,theme:si,overflow:s?"wrap":"scroll",disableFileHeader:!0,hunkSeparators:"line-info-basic",unsafeCSS:ii}},`${e}:${C.key}:${n}:${s}`)]},C.key)})})]},e)}function fr(e){const t=e.replaceAll("\\","/"),n=t.lastIndexOf("/");return n<0?{name:t,directory:""}:{name:t.slice(n+1),directory:t.slice(0,n)}}function Yt({path:e}){const{name:t,directory:n}=fr(e);return k.jsxs(k.Fragment,{children:[k.jsx("span",{className:"diff-file-name",children:t}),n?k.jsx("small",{className:"diff-file-directory",children:n}):null]})}function Ne({label:e,pressed:t,onClick:n,children:i}){return k.jsxs(Ze,{children:[k.jsx(Je,{render:k.jsx(Si,{type:"button",variant:t?"secondary":"ghost",size:"icon-sm","aria-label":e,"aria-pressed":t,onClick:n}),children:i}),k.jsx(et,{children:e})]})}export{vr as D,pn as F,Ps as a,Di as b,Oi as c,Ii as g,kr as p,Vi as r,ot as s};
|
|
26
|
+
`}function Fe(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function $s(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Gs(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Ws(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function _s(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:Dn(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}function Ks(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}let qs=-1;var pn=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++qs}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:re},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new In,this.scrollSyncManager=new Ds,this.interactionManager=new Fn("diff",mt(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 _s(e)}createHunksRenderer(e){return new Ps(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const n=this.fileDiffCache;if(n==null)return;const i=n.hunks.at(-1);let s,r;e:for(const o of n.hunks){const a=t==="deletions"?o.deletionStart:o.additionStart,l=t==="deletions"?o.deletionCount:o.additionCount;let d=xe(a,l)+1,h=o.splitLineStart,u=o.unifiedLineStart;if(e<d){const c=d-e;s=Math.max(u-c,0),r=Math.max(h-c,0);break e}if(e>=d+l){if(o===i){const c=e-(d+l);s=u+o.unifiedLineCount+c,r=h+o.splitLineCount+c;break e}continue}for(const c of o.hunkContent)if(c.type==="context")if(e<d+c.lines){const f=e-d;r=h+f,s=u+f;break e}else d+=c.lines,h+=c.lines,u+=c.lines;else{const f=t==="deletions"?c.deletions:c.additions;if(e<d+f){const p=e-d;s=u+(t==="additions"?c.deletions:0)+p,r=h+p;break e}else d+=f,h+=Math.max(c.deletions,c.additions),u+=c.deletions+c.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(mt(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&&!Nn(this.appliedThemeCSS.theme,this.options.theme??re)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}flushDeferredLineState(){const{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t==="wrap",columnVariables:this.shouldApplyColumnVariables(t)?"apply":"measure"}),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators=="function"?!0:e==="scroll"&&(this.lineAnnotations.length>0||this.pre?.hasAttribute("data-has-merge-conflict")===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){li(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:i,fileDiff:s,...r}){if(!this.enabled)throw new Error("FileDiff.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated");const o=rt(r,"FileDiff.hydrate"),a=o?.oldFile,l=o?.newFile;this.hydrateElements(e,t),Zs(this.pre,Xs({fileDiff:s,oldFile:a,newFile:l}),this.options.collapsed)||Qs(this.headerElement,Ys({fileDiff:s,oldFile:a,newFile:l}),this.options.disableFileHeader)?this.render({...r,fileContainer:e,lineAnnotations:i,fileDiff:s,preventEmit:!0}):this.hydrationSetup({fileDiff:s,lineAnnotations:i,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Pn(e,t);for(const n of e.shadowRoot?.children??[]){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n;for(const i of n.children)!(i instanceof HTMLElement)||i.tagName.toLowerCase()!=="code"||("deletions"in i.dataset&&(this.codeDeletions=i),"additions"in i.dataset&&(this.codeAdditions=i),"unified"in i.dataset&&(this.codeUnified=i));continue}if("diffsHeader"in n.dataset){this.headerElement=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:i}){this.lineAnnotations=i??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?ae(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){const{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Ks(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{const n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(n){if(this.options.disableErrorHandling===!0)throw n;console.error(n)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(at("merge",e,t),this.setHydratedState(t),await st(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:i=!1,lineAnnotations:s,fileContainer:r,containerWrapper:o,renderRange:a,...l}){const d=rt(l,"FileDiff.render"),h=d?.oldFile,u=d?.newFile;if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName!=null?e.prevName+":"+e.name:e.name),this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:c=!1,themeType:f="system",expandUnchanged:p=!1}=this.options,g=c?void 0:a,x=this.hasThemeChanged(),m=d!=null,L=m&&(!Wt(h,this.deletionFile)||!Wt(u,this.additionFile));let v=e!=null&&e!==this.fileDiff;const C=s!=null&&(s.length>0||this.lineAnnotations.length>0)?s!==this.lineAnnotations:!1;if(!c&&Qt(g,this.renderRange)&&!n&&!C&&!x&&(e!=null&&e===this.fileDiff||e==null&&!L))return this.applyCachedThemeState(f);let S;e==null&&m&&(L||this.fileDiff==null)&&(S=ae(d.oldFile,d.newFile,this.options.parseDiffOptions));const{renderRange:y}=this;if(this.renderRange=g,m?(this.deletionFile=h,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null?this.fileDiff=e:S!=null&&(v=!0,this.fileDiff=S),v&&(this.cachedHeaderHTML=void 0),s!=null&&this.setLineAnnotations(s),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(Pt(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),p&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:H=!1,disableFileHeader:$=!1}=this.options;if($&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),r=this.getOrCreateFileContainer(r,o),this.applyCachedThemeState(f),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const b=this.hunksRenderer.renderDiff(this.fileDiff,di);b!=null&&this.applyThemeState(r,b.themeStyles,f,b.baseThemeType),b?.headerElement!=null&&this.applyHeaderToDOM(b.headerElement,r),this.renderSeparators([]),this.injectUnsafeCSS()}catch(b){if(H)throw b;console.error(b),b instanceof Error&&this.applyErrorToDOM(b,r)}return i||this.emitPostRender(),!0}try{const b=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(n,C,L||v||x)&&this.applyPartialRender({previousRenderRange:y,renderRange:g}))){const D=this.hunksRenderer.renderDiff(this.fileDiff,g);if(D==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(r,D.themeStyles,f,D.baseThemeType),D.headerElement!=null&&this.applyHeaderToDOM(D.headerElement,r),D.additionsContentAST!=null||D.deletionsContentAST!=null||D.unifiedContentAST!=null?this.applyHunksToDOM(b,D):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(D.hunkData)}this.applyBuffers(b,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(b){if(H)throw b;console.error(b),b instanceof Error&&this.applyErrorToDOM(b,r)}return i||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const i=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,i)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.fileDiffCache,i=this.lineAnnotations,s=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(r=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(r,t,n,i,s)})}computeEditorRenderRange(e){const t=this.fileDiffCache;if(e==null||t==null||lt(e))return e;const{diffStyle:n="split",expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return Ce({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:a})=>{a!=null&&(r??=a.lineNumber,o=a.lineNumber)}}),r==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:r-1,totalLines:o-r+1}}attachEditor(e){if(this.type!=="file-diff")throw new Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),t=>{this.editor=void 0,t!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){const e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;const{collapsedContextThreshold:t=1}=this.options,n=us(e,this.hunksRenderer.getExpandedHunksMap(),t);return Pt(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(cs(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);const n=this.hunksRenderer.diffCache;if(n!=null){const i=this.fileDiff?.cacheKey;i!=null&&n.cacheKey==null&&(n.cacheKey=i),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){const{shouldRefreshDiffsView:i,lineCountChangeInFlight:s}=n;if(this.hunksRenderer.updateRenderCache(e,t,s)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}i===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle==="split"?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){const t=this.fileDiffCache;if(t==null)return!0;const{expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options;return en({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}getNearestRenderableLine(e,t){const n=this.fileDiffCache;if(n==null)return e;const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;return zn({fileDiff:n,lineNumber:e,direction:t,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s})}revealLine(e){const t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:i=1,expansionLineCount:s=100}=this.options;if(t==null||t.isPartial||n)return!1;const r=this.hunksRenderer.getExpandedHunksMap();for(const[d,h]of t.hunks.entries()){const[u,c]=Ct(h);if(e<u){const f=ve({isPartial:t.isPartial,rangeSize:h.collapsedBefore,expandedHunks:r,hunkIndex:d,collapsedContextThreshold:i}),p=u-f.rangeSize;if(f.renderAll||e<p+f.fromStart||e>=u-f.fromEnd)return!1;const g=e-(p+f.fromStart)+1,x=u-f.fromEnd-e;return g<=x?this.expandHunk(d,"up",g+s):this.expandHunk(d,"down",x+s),!0}if(e<c)return!1}const o=ye({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:i,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const a=t.hunks[t.hunks.length-1],[,l]=Ct(a);return e<l+o.fromStart||e>=l+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(l+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){hi(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(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}async primeHighlightCache(e=this.fileDiff){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||ze(e))return;const n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(i=>{console.error(i)})}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:i}of this.separatorCache.values())i.remove();this.separatorCache.clear();return}const n=new Map(this.separatorCache);for(const i of e){const s=i.slotName;let r=this.separatorCache.get(s);if(r==null||!Ws(i,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=i.slotName;const a=t(i,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:i},this.separatorCache.set(s,r)}n.delete(s)}for(const[i,{element:s}]of n.entries())this.separatorCache.delete(i),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,i]of this.lineAnnotations.entries()){const s=`${n}-${Se(i)}`;let r=this.annotationCache.get(s);if(r==null||!Gs(i,r.annotation)){r?.element.remove();const o=t(i);if(o==null)continue;r={element:Bn(Se(i)),annotation:i},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[n,{element:i}]of e.entries())this.annotationCache.delete(n),i.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=On();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(e,t){const{fileContainer:n}=this,i=e??n??document.createElement("diffs-container"),s=n!==i;return n!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=i,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:St(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):St(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=Un;const i=n.firstChild;i instanceof SVGElement&&(this.spriteSVG=i)}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&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(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:n}=this,i=this.cachedHeaderHTML??oe(e);if(this.cachedHeaderHTML=i,i!==this.lastRenderedHeaderHTML){const u=document.createElement("div");u.innerHTML=i;const c=u.firstElementChild;if(!(c instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(c,this.headerElement):t.shadowRoot?.prepend(c),this.headerElement=c,this.lastRenderedHeaderHTML=i}if(this.isContainerManaged||n==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const u=s(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,sn,u),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?.(n)??void 0,d=o?.(n)??void 0,h=a?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ui,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,ci,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,fi,h),this.headerCustom?.remove(),this.headerCustom=void 0}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,i){if(i==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,i),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??=Vn(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=jn(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,i){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=i??n,o=this.options.theme??re,a=typeof o=="string"?o:{...o},l=xt(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:i,scrollbarGutter:l};return}this.themeCSSStyle=$n({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Kn(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Gn(this.themeCSSStyle.textContent??"",xt(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&pi()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?Lt(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){const i=this.getColumnPair(e);if(i==null)return!1;const s=J(t[0]),r=J(t[1]);return s==null||r==null?!1:(i.gutter.innerHTML=oe(s),i.content.innerHTML=oe(r),n!==this.lastRowCount&&(i.gutter.style.setProperty("grid-row",`span ${n}`),i.content.style.setProperty("grid-row",`span ${n}`)),!0)}replaceCodeColumns(e,t){const{overflow:n="scroll"}=this.options,i=(this.options.hunkSeparators??"line-info")==="line-info",s=n==="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),d=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),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=Ge({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeUnified,a,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a)),o.push(this.codeUnified)):l!=null||d!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ge({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeDeletions,l,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),d!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ge({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeAdditions,d,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(d)),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:n,codeUnified:i,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,i,r,s);if(a==null)return!1;const l=e.startingLine,d=t.startingLine,h=l+e.totalLines,u=d+t.totalLines,c=Math.max(l,d),f=Math.min(h,u);if(f<=c)return!1;const p=Math.max(0,c-l),g=Math.max(0,h-f),x=this.trimColumns({columns:a,trimStart:p,trimEnd:g,previousStart:l,overlapStart:c,overlapEnd:f,diffStyle:o});if(x<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<x)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let m=this.lastRowCount-x;const L=(y,H)=>{if(!(H<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:y,totalLines:H,bufferBefore:0,bufferAfter:0})},v=L(d,Math.max(c-d,0));if(v==null&&d<c)return!1;const C=L(f,Math.max(u-f,0));if(C==null&&u>f)return!1;const S=(y,H)=>{if(y!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,y,H);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,y,H);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");m+=y.rowCount}};return this.cleanupErrorWrapper(),S(v,"afterbegin"),S(C,"beforeend"),this.lastRowCount!==m&&(this.applyRowSpan(o,a,m),this.lastRowCount=m),!0}insertPartialHTML(e,t,n,i){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",n);this.renderPartialColumn(t,s,i)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",n),r=this.hunksRenderer.renderCodeAST("additions",n);this.renderPartialColumn(t[0],s,i),this.renderPartialColumn(t[1],r,i)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}refreshSplitDiffView(){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 n=(i,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(i,e),o=J(r?.[0]),a=J(r?.[1]);for(const[l,d]of[[s.gutter,o],[s.content,a]])if(d!=null&&l.childElementCount===d.length)for(let h=0;h<d.length;h++){const u=l.children[h],c=d[h].properties["data-line-type"];c!=null&&u.dataset.lineType!==c&&(u.dataset.lineType=c)}};n("deletions",t[0]),n("additions",t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!=="unified")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("unified",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;const n=this.hunksRenderer.renderCodeAST("unified",e),i=J(n?.[0]),s=J(n?.[1]),r=()=>{for(const[o,a]of[[t.gutter,i],[t.content,s]])a!=null&&(o.innerHTML=oe(a));e.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?Lt(this.pre,r):r(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;const i=J(t[0]),s=J(t[1]);if(i==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);n==="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],i,s,!0);const o=s.at(-1);n==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],i,s,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,n,i,s,r){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(i.shift(),s.shift()):(i.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){const i=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${n}`),s.content.style.setProperty("grid-row",`span ${n}`))};if(e==="unified"&&!Array.isArray(t))i(t);else if(e==="split"&&Array.isArray(t))i(t[0]),i(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,n){let i=0,s=0,r=0,o=!1;const a=n>=0;if(e==null)return 0;const l=Array.from(e.content.children),d=Array.from(e.gutter.children);if(l.length!==d.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const h=d[r],u=l[r];if(r++,!(h instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:h,contentElement:u}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset||h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset)){h.remove(),u.remove(),s++;continue}if("lineIndex"in h.dataset&&"lineIndex"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),s++),i++;continue}if("separator"in h.dataset&&"separator"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||a&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="buffer"&&"contentBuffer"in u.dataset){const c=this.getBufferSize(u.dataset);if(c==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const f=Math.min(t,c),p=c-f;p>0?(this.updateBufferSize(h,p),this.updateBufferSize(u,p),s+=f):(h.remove(),u.remove(),s+=c),t-=f,t===0&&p===0&&(o=!0)}else if(a){const f=i,p=i+c-1;if(n<=f)h.remove(),u.remove(),s+=c;else if(n<=p){const g=p-n+1,x=c-g;this.updateBufferSize(h,x),this.updateBufferSize(u,x),s+=g}}i+=c;continue}throw console.error({gutterElement:h,contentElement:u}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:i,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,i-s),l=n-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const d=o>0,h=r>0;if(!d&&!h)return 0;const u=d?a:0,c=h?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,u,c);if(t==="split"&&Array.isArray(e)){const f=this.trimColumnRows(e[0],u,c),p=this.trimColumnRows(e[1],u,c);if(e[0]!=null&&e[1]!=null&&f!==p)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?f:p}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)`)}getColumnPair(e){if(e==null)return;const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}getCodeColumns(e,t,n,i){if(e==="unified")return this.getColumnPair(t);{const s=this.getColumnPair(n),r=this.getColumnPair(i);return s!=null||r!=null?[s,r]: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:n,totalLines:i},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:d="split"}=this.options,h={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:d==="unified"?!1:t!=null&&n!=null,totalLines:i,customProperties:s};Wn(h,this.appliedPreAttributes)||(_n(e,h),this.appliedPreAttributes=h)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const i=document.createElement("div");i.dataset.errorMessage="",i.innerText=e.message,this.errorWrapper.appendChild(i);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 Wt(e,t){return e==null||t==null?e==null&&t==null:tn(e,t)}function Xs({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Ys({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Zs(e,t,n=!1){return!n&&e==null&&t}function Qs(e,t,n=!1){return e==null&&t&&!n}function J(e){if(!(e==null||e.type!=="element"))return e.children??[]}const ht=3e3;let Js=-1;var er=class extends pn{__id=`little-virtualized-file-diff:${++Js}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,i,s=!1){super(e,i,s),this.virtualizer=t,this.metrics=We(n)}setMetrics(e,t=!1){const n=We(e);!t&&qn(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){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||!Xn(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,n=!nn(t,e),i=n&&or(t,e);super.setOptions(e),i&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:ar(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,i)}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,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1;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 n=this.getDiffStyle(),i=n==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Jt(this.renderRange)){const r=tr(i)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of i){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 d=dr(l,n);let h=a.getBoundingClientRect().height,u=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(u=!0),h+=a.nextElementSibling.getBoundingClientRect().height);const c=this.getEstimatedLineHeight(u),f=this.cache.heightDeltas.get(d)??0,p=h-c;p!==f&&(e=!0,this.cache.measuredHeightDeltaTotal+=p-f,p===0?this.cache.heightDeltas.delete(d):this.cache.heightDeltas.set(d,p))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,i){const s=!me(this.fileDiff,e),r=this.syncLineAnnotations(i);let o=n?.resetDiffLayoutCache===!0||s||r,a=s||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=We(n.metrics),o=!0,a=!0);const{collapsed:l=!1,expandUnchanged:d=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),this.currentExpandUnchanged!==d&&(this.currentExpandUnchanged=d,o=!0,a=!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 n=this.getLineIndex(e,t);if(n==null)return;const{disableFileHeader:i=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),d=a==="split"?n[1]:n[0];this.approximateLayoutCheckpoints();const h=ge(this.metrics,i),u=this.getLayoutCheckpointBeforeLineIndex(d);let c=u?.top??h+this.cache.fileAnnotationHeight;if(r)return{top:h,height:0};let f;return Ce({diff:this.fileDiff,diffStyle:a,startingLine:u?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:p,hunk:g,collapsedBefore:x,collapsedAfter:m,deletionLine:L,additionLine:v})=>{const C=a==="split"?v?.splitLineIndex??L?.splitLineIndex:v?.unifiedLineIndex??L?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(x>0){const y=ke({type:l,metrics:this.metrics,hunkIndex:p,hunkSpecs:g?.hunkSpecs});if(y!=null){if(c+=y.gapBefore,d>=C-x&&d<C)return f={top:c,height:y.height},!0;c+=y.height+y.gapAfter}}const S=this.getLineHeight(C,(v?.noEOFCR??!1)||(L?.noEOFCR??!1));if(C===d)return f={top:c,height:S},!0;if(c+=S,m>0){const y=se({type:l,metrics:this.metrics});if(y!=null){if(d>C&&d<=C+m)return f={top:c+y.gapBefore,height:y.height},!0;c+=y.totalHeight}}return!1}}),f}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:i=!1,collapsedContextThreshold:s=1}=this.options;if(i)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??ge(this.metrics,t)+this.cache.fileAnnotationHeight,d;return Ce({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:h,hunk:u,collapsedBefore:c,collapsedAfter:f,deletionLine:p,additionLine:g})=>{const x=r==="split"?g?.splitLineIndex??p?.splitLineIndex:g?.unifiedLineIndex??p?.unifiedLineIndex;if(x==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(c>0){const L=ke({type:o,metrics:this.metrics,hunkIndex:h,hunkSpecs:u?.hunkSpecs});L!=null&&(l+=L.totalHeight)}if(l>=e&&(p!=null?d={lineNumber:p.lineNumber,side:"deletions",top:l}:g!=null&&(d={lineNumber:g.lineNumber,side:"additions",top:l}),d!=null))return!0;const m=this.getLineHeight(x,(g?.noEOFCR??!1)||(p?.noEOFCR??!1));if(l+=m,f>0){const L=se({type:o,metrics:this.metrics});L!=null&&(l+=L.totalHeight)}return!1}}),d}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:n,bufferAfter:i,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=i)}return{topOffset:this.top+n+r,height:this.height-(n+i)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||(this.resetLayoutCache({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){const n=at("clone",e,t);if(await st(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(at("merge",e,t),this.setHydratedState(t),await st(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n;const{pendingExpansions:i,pendingHydratedDiff:s}=this;if(i!=null){this.pendingExpansions=void 0;for(const r of i)this.hunksRenderer.expandHunk(r.hunkIndex,r.direction,r.expansionLineCountOverride),t=!0}return s!=null&&(this.pendingHydratedDiff=void 0,s.expectedDiff===e&&(this.setHydratedState(s.files),n=s.nextDiff)),n!=null?(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})):t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;const{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;const{expansionLineCount:i=100,collapsedContextThreshold:s=1}=this.options,r=new Map(this.hunksRenderer.getExpandedHunksMap());for(const o of t){const a={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},l=o.expansionLineCountOverride??i;(o.direction==="up"||o.direction==="both")&&(a.fromStart+=l),(o.direction==="down"||o.direction==="both")&&(a.fromEnd+=l),r.set(o.hunkIndex,a)}return en({fileDiff:n,lineNumber:e,expandedHunks:r,collapsedContextThreshold:s})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){const{renderRange:i}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&i!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==i.bufferAfter&&this.updateBuffers(r)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){const n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}const{disableFileHeader:s=!1,collapsed:r=!1}=this.options,o=ge(this.metrics,s);if(this.height+=o,r){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!i&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);const t=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:s,unifiedHeight:r}=vs({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,canHydratePartialDiff:Xe(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=s,this.cache.estimatedUnifiedHeight=r}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;const t=this.fileContainer.getBoundingClientRect();t.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:t.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:i,...s}={}){const r=rt(s,"VirtualizedFileDiff.render"),o=r!=null,a=r?.oldFile,l=r?.newFile,d=o&&(!qt(a,this.deletionFile)||!qt(l,this.additionFile));let h=t??this.fileDiff;t==null&&o&&(d||this.fileDiff==null)&&(h=ae(r.oldFile,r.newFile,this.options.parseDiffOptions));const{forceRenderOverride:u,isSetup:c}=this;this.forceRenderOverride=void 0;const f=this.syncLineAnnotations(i);f&&this.resetLayoutCache({includeEstimatedHeights:!1});const p=t!=null&&t!==this.fileDiff,g=h!=null&&!me(this.fileDiff,h),x=p||d;if(g&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),h==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(c)this.top??=this.getVirtualizedTop(),g&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,h));else{this.computeApproximateSize(!1,h);const S=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(S==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");S.connect(e,this),this.isVisible=S.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!x||!c))return this.fileDiff=h,r!=null&&(this.deletionFile=a,this.additionFile=l),g&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const m=this.virtualizer.getWindowSpecs(),L=this.top??0,v=this.computeRenderRangeFromWindow(h,L,m),C=super.render({fileDiff:h,fileContainer:e,renderRange:v,lineAnnotations:i,forceRender:(u??n)||f||g,...r,...s});return this.isSimpleMode()&&C&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),C}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return lr(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:i=1}=this.options,s=e.hunks.length-1,r=Xe(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),a=this.getHunkSeparatorType(),l=n?!0:this.hunksRenderer.getExpandedHunksMap(),d=nr(this.cache.heightDeltas);let h=ge(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:x=0,metadataOffsets:m=[]})=>{if(f<=0)return;const L=u,v=u+f;let C=ir(L);for(;C<v;){const S=C-L,y=h+(S>0?g:0)+S*this.metrics.lineHeight+sr(m,S)*this.metrics.lineHeight+_t(d,p,p+S);this.cache.checkpoints.push({renderedLineIndex:C,lineIndex:p+S,top:y}),C+=ht}h+=g+f*this.metrics.lineHeight+m.length*this.metrics.lineHeight+_t(d,p,p+f)+x,u=v};for(let f=0;f<e.hunks.length;f++){const p=e.hunks[f];if(p==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const g=ve({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:l,hunkIndex:f,collapsedContextThreshold:i}),x=g.collapsedLines>0?ke({type:a,metrics:this.metrics,hunkIndex:f,hunkSpecs:p.hunkSpecs})?.totalHeight??0:0;c({rowCount:g.fromStart,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.rangeSize});let m=x;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:m}),g.fromEnd>0&&(m=0);const L=f===s?ye({fileDiff:e,hunkIndex:f,expandedHunks:l,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,v=L!=null&&L.collapsedLines>0?se({type:a,metrics:this.metrics})?.totalHeight??0:f===s&&r?se({type:a,metrics:this.metrics})?.totalHeight??0:0,C=L!=null?L.fromStart+L.fromEnd:0,S=o==="split"?p.splitLineCount:p.unifiedLineCount,y=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:S,startLineIndex:y,preSeparatorHeight:m,postSeparatorHeight:C===0?v:0,metadataOffsets:rr({diffStyle:o,hunk:p,rowCount:S})}),L!=null&&C>0&&c({rowCount:C,startLineIndex:y+S,postSeparatorHeight:v})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,i;for(;t<=n;){const s=t+n>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(i=r,t=s+1):n=s-1}return i}getLayoutCheckpointBeforeTop(e,t){let n=0,i=this.cache.checkpoints.length-1,s=-1;for(;n<=i;){const r=n+i>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,n=r+1):i=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 n=0;if(e.isPartial){for(const a of e.hunks)n+=t==="split"?a.splitLineCount:a.unifiedLineCount;return n}const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options,r=i?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const d=t==="split"?l.splitLineCount:l.unifiedLineCount;n+=d;const h=Math.max(l.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=ve({isPartial:e.isPartial,rangeSize:h,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});h>0&&(n+=f?h:u+c)}const o=ye({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){const n=this.getExpandedLineCount(e,t),i=t==="split"?e.splitLineCount:e.unifiedLineCount;return Math.max(n,i,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:i}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,d=this.getDiffStyle(),h=this.getHunkSeparatorType(),u=Xe(e,this.options.loadDiffFiles!=null),c=this.height;let f=this.getLayoutLineCount(e,d);const p=ge(this.metrics,s),g=e.hunks.length>0?Zt(this.metrics):0,{fileAnnotationHeight:x}=this.cache,m=p+x,L=Math.max(0,c-p-x-g),v=this.hasFileAnnotations(e),C=t+p,S=x>0&&v&&C<i&&C+x>n;if(t<n-c||t>i)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,d);const y=Math.ceil(Math.max(i-n,0)/l),H=Math.ceil(y/a)*a+a,$=H/a,b=$,D=[],we=(n+i)/2,de=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-H*l*2),a);let I=t+(de?.top??m),j=de?.renderedLineIndex??0,te,E,A;if(Ce({diff:e,diffStyle:d,startingLine:de?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:Le,hunk:G,collapsedBefore:Ve,collapsedAfter:je,deletionLine:ne,additionLine:W})=>{const T=W!=null?W.splitLineIndex:ne.splitLineIndex,N=W!=null?W.unifiedLineIndex:ne.unifiedLineIndex,B=(W?.noEOFCR??!1)||(ne?.noEOFCR??!1),ie=Le===e.hunks.length-1&&G!=null&&(d==="split"?T===G.splitLineStart+G.splitLineCount-1:N===G.unifiedLineStart+G.unifiedLineCount-1),O=(Ve>0?ke({type:h,metrics:this.metrics,hunkIndex:Le,hunkSpecs:G?.hunkSpecs}):void 0)?.totalHeight??0;I+=O;const U=j%a===0,Z=Math.floor(j/a);if(U&&(D[Z]=I-(t+m+O),A!=null)){if(A<=0)return!0;A--}const P=this.getLineHeight(d==="split"?T:N,B);if(I>n-P&&I<i&&(te??=Z),E==null&&I+P>we&&(E=Z),A==null&&I>=i&&U&&(A=b),j++,I+=P,je>0||ie&&u){const Ae=se({type:h,metrics:this.metrics});Ae!=null&&(I<i&&I+Ae.totalHeight>n&&(te??=Z),E==null&&I+Ae.totalHeight>we&&(E=Z),I+=Ae.totalHeight)}return!1}}),te==null)if(S)te=0,E=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};E??=te;const X=Math.round(E-$/2),he=Math.max(0,Math.ceil(f/a)-$),w=Math.max(0,Math.min(X,he)),R=w*a,M=X<0?H+X*a:H,z=D[w]??0,Y=R===0?0:x+z,ue=w+M/a,Ee=ue<D.length?L-D[ue]:L-(I-t-m);return{startingLine:R,totalLines:M,bufferBefore:Y,bufferAfter:Math.max(0,Ee)}}};function tr(e){let t;for(const n of e){if(n==null)continue;const i=n.children[1];if(i instanceof HTMLElement)for(const s of i.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Yn&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function nr(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),n=[],i=[0];let s=0;for(const[r,o]of t)n.push(r),s+=o,i.push(s);return{lineIndexes:n,prefixTotals:i}}function _t({lineIndexes:e,prefixTotals:t},n,i){if(n>=i||e.length===0)return 0;const s=Kt(e,n);return(t[Kt(e,i)]??0)-(t[s]??0)}function Kt(e,t){let n=0,i=e.length;for(;n<i;){const s=n+i>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?n=s+1:i=s}return n}function ir(e){return Math.ceil(e/ht)*ht}function sr(e,t){let n=0;for(const i of e)i<t&&n++;return n}function rr({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const i=t.hunkContent.at(-1);if(i==null)return[];if(i.type==="context")return[n-1];const s=Math.max(i.deletions,i.additions),r=i.deletions+i.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];const o=[],a=n-r;return i.deletions>0&&t.noEOFCRDeletions&&o.push(a+i.deletions-1),i.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function or(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function ar(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Xe(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function lr(e){return typeof e=="function"?"custom":e??"line-info"}function qt(e,t){return e==null||t==null?e==null&&t==null:tn(e,t)}function dr(e,t){const[n,i]=e.split(",").map(Number);return t==="split"?i:n}const Xt=typeof window>"u"?ee.useEffect:ee.useLayoutEffect;function hr({fileDiff:e,options:t,editorOptions:n,lineAnnotations:i,selectedLines:s,prerenderedHTML:r,metrics:o,hasGutterRenderUtility:a,hasCustomHeader:l,disableWorkerPool:d,edit:h}){const u=Zn(),c=s!==void 0,f=ee.useContext(Qn),p=mi(),g=ee.useRef(null),x=Ci(m=>{if(m!=null){if(g.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");u!=null?g.current=new er(Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),u,o,d?void 0:f,!0):g.current=new pn(Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),d?void 0:f,!0),g.current.hydrate({fileDiff:e,fileContainer:m,lineAnnotations:i,prerenderedHTML:r})}else{if(g.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");g.current.cleanUp(),g.current=null}});return Xt(()=>{const{current:m}=g;if(m==null)return;const L=Ye({controlledSelection:c,hasCustomHeader:l,hasGutterRenderUtility:a,options:t}),v=L!==void 0&&!nn(m.options,L);m.setOptions(L),m.render({forceRender:v,fileDiff:e,lineAnnotations:i}),s!==void 0&&m.setSelectedLines(s)}),Xt(()=>{if(h&&g.current!=null){if(p===void 0)throw new Error("FileDiff: EditContext is not attached");const m=p(n??{});if(m==null)throw new Error("FileDiff: EditProvider.createEditor must return an editor instance");try{return m.edit(g.current)}catch(L){throw m.cleanUp(),L}}},[h]),{ref:x,getHoveredLine:ee.useCallback(()=>g.current?.getHoveredLine(),[])}}function Ye({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:i}){return t||i||n?{...e,controlledSelection:t,renderCustomHeader:n?kt:e?.renderCustomHeader,renderGutterUtility:i?kt:e?.renderGutterUtility}:e}function ur({patch:e,options:t,editorOptions:n,metrics:i,lineAnnotations:s,selectedLines:r,className:o,style:a,prerenderedHTML:l,renderAnnotation:d,renderCustomHeader:h,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderGutterUtility:p,disableWorkerPool:g=!1,edit:x=!1}){const m=cr(e),{ref:L,getHoveredLine:v}=hr({fileDiff:m,options:t,editorOptions:n,metrics:i,lineAnnotations:s,selectedLines:r,prerenderedHTML:l,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:g,edit:x});return k.jsx(gi,{ref:L,className:o,style:a,children:Jn(Vi({fileDiff:m,renderCustomHeader:h,renderHeaderPrefix:u,renderHeaderFilenameSuffix:c,renderHeaderMetadata:f,renderAnnotation:d,lineAnnotations:s,renderGutterUtility:p,getHoveredLine:v}),l)})}function cr(e){return ee.useMemo(()=>ei(e),[e])}function vr({contentKey:e,diff:t,diffView:n,themeType:i,wrapLines:s,initiallyCollapsed:r=!1,compact:o=!1,scopeControl:a,onDiffViewChange:l,onWrapLinesChange:d,onClose:h}){const u=ee.useMemo(()=>ti(t.patch),[t.patch]),[c,f]=ee.useState(()=>new Set(r?u.map(C=>C.key):[])),p=u.length>0&&u.every(C=>c.has(C.key)),g=u.reduce((C,S)=>C+S.additions,0),x=u.reduce((C,S)=>C+S.deletions,0),m=C=>{f(S=>{const y=new Set(S);return y.has(C)?y.delete(C):y.add(C),y})},L=()=>f(p?new Set:new Set(u.map(C=>C.key))),v=C=>k.jsxs("div",{className:"diff-workspace-actions",children:[C&&k.jsx(Ne,{label:p?"Expand all files":"Collapse all files",onClick:L,children:p?k.jsx(yi,{}):k.jsx(wi,{})}),k.jsx(Ne,{label:n==="unified"?"Use split diff":"Use unified diff",pressed:n==="split",onClick:()=>l?.(n==="unified"?"split":"unified"),children:n==="unified"?k.jsx(Ai,{}):k.jsx(bi,{})}),k.jsx(Ne,{label:s?"Disable line wrapping":"Wrap long lines",pressed:s,onClick:()=>d?.(!s),children:k.jsx(Mi,{})}),h&&k.jsx(Ne,{label:"Close diff",onClick:h,children:k.jsx(ki,{})})]});return k.jsxs("div",{className:`diff-workspace${o?" compact":""}`,children:[!o&&k.jsxs("div",{className:"diff-workspace-toolbar",children:[a&&k.jsx("div",{className:"diff-workspace-scope",children:a}),k.jsxs("span",{className:"diff-file-count",children:[u.length," ",u.length===1?"file":"files"]}),k.jsxs("span",{className:"diff-total-stats","aria-label":`${g} additions and ${x} deletions`,children:[k.jsxs("span",{className:"add",children:["+",g]}),k.jsxs("span",{className:"del",children:["−",x]})]}),v(!0)]}),k.jsx(ni,{className:"diff-workspace-scroll",contentClassName:"diff-workspace-content",children:u.map(C=>{const S=!o&&c.has(C.key);return k.jsxs("section",{className:"diff-file-section",children:[o?k.jsxs("div",{className:"diff-file-header diff-file-header-compact",children:[k.jsx("img",{src:yt(C.path),className:"diff-file-icon",alt:""}),k.jsxs(Qe,{children:[k.jsx(Je,{render:k.jsx("span",{className:"diff-file-path"}),children:k.jsx(Yt,{path:C.path})}),k.jsx(et,{children:C.path})]}),C.previousPath&&C.previousPath!==C.path&&k.jsxs("span",{className:"diff-file-previous",children:["from ",C.previousPath]}),k.jsxs("span",{className:"diff-file-stats",children:[k.jsxs("span",{className:"add",children:["+",C.additions]}),k.jsxs("span",{className:"del",children:["−",C.deletions]})]}),v(!1)]}):k.jsxs(Qe,{children:[k.jsxs(Je,{render:k.jsx("button",{type:"button",className:"diff-file-header","aria-expanded":!S,onClick:()=>m(C.key)}),children:[S?k.jsx(xi,{className:"diff-file-chevron"}):k.jsx(Li,{className:"diff-file-chevron"}),k.jsx("img",{src:yt(C.path),className:"diff-file-icon",alt:""}),k.jsx("span",{className:"diff-file-path",children:k.jsx(Yt,{path:C.path})}),C.previousPath&&C.previousPath!==C.path&&k.jsxs("span",{className:"diff-file-previous",children:["from ",C.previousPath]}),k.jsxs("span",{className:"diff-file-stats",children:[k.jsxs("span",{className:"add",children:["+",C.additions]}),k.jsxs("span",{className:"del",children:["−",C.deletions]})]})]}),k.jsx(et,{children:C.path})]}),!S&&k.jsx(ur,{patch:C.patch,disableWorkerPool:t.lineCount>1e4,options:{diffStyle:n,diffIndicators:"classic",themeType:i,theme:si,overflow:s?"wrap":"scroll",disableFileHeader:!0,hunkSeparators:"line-info-basic",unsafeCSS:ii}},`${e}:${C.key}:${n}:${s}`)]},C.key)})})]},e)}function fr(e){const t=e.replaceAll("\\","/"),n=t.lastIndexOf("/");return n<0?{name:t,directory:""}:{name:t.slice(n+1),directory:t.slice(0,n)}}function Yt({path:e}){const{name:t,directory:n}=fr(e);return k.jsxs(k.Fragment,{children:[k.jsx("span",{className:"diff-file-name",children:t}),n?k.jsx("small",{className:"diff-file-directory",children:n}):null]})}function Ne({label:e,pressed:t,onClick:n,children:i}){return k.jsxs(Qe,{children:[k.jsx(Je,{render:k.jsx(Si,{type:"button",variant:t?"secondary":"ghost",size:"icon-sm","aria-label":e,"aria-pressed":t,onClick:n}),children:i}),k.jsx(et,{children:e})]})}export{vr as D,pn as F,Ps as a,Di as b,Oi as c,Ii as g,kr as p,Vi as r,ot as s};
|