@ensocode/server 0.3.13 → 0.3.15-beta.234
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/README.md +11 -1
- package/out/phone/assets/{EditDiff-B3HxLrbF.js → EditDiff-DlIQ0NvB.js} +1 -1
- package/out/phone/assets/{ReadFileView-BFpGH-kK.js → ReadFileView-hlSV-q1S.js} +1 -1
- package/out/phone/assets/{abnfDiagram-VCTEODGH-BNvyPGoF.js → abnfDiagram-VCTEODGH-cWLl_02_.js} +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-WvHUAPXe.js +1 -0
- package/out/phone/assets/{architectureDiagram-5GKGNRK7-1bhpTEFA.js → architectureDiagram-5GKGNRK7-QEXMUvv5.js} +1 -1
- package/out/phone/assets/{blockDiagram-I7D4REHJ-Bo9UMudu.js → blockDiagram-I7D4REHJ-FzQ3vEDv.js} +1 -1
- package/out/phone/assets/{c4Diagram-7LVT6UL2-YS11cig2.js → c4Diagram-7LVT6UL2-6iRtBvvT.js} +1 -1
- package/out/phone/assets/channel-t2MFK_dg.js +1 -0
- package/out/phone/assets/{chunk-4HAMMTFA-gA-CzNGD.js → chunk-4HAMMTFA-4eZjiClJ.js} +1 -1
- package/out/phone/assets/{chunk-75Z2AOVW-BL_5b1Dw.js → chunk-75Z2AOVW-BTVSMC3k.js} +1 -1
- package/out/phone/assets/{chunk-DU6HZSFF-BpNlAs9R.js → chunk-DU6HZSFF-Ca9U1rWL.js} +1 -1
- package/out/phone/assets/{chunk-F27PBJKO-lsKx96Nt.js → chunk-F27PBJKO-iUczI4_Q.js} +1 -1
- package/out/phone/assets/{chunk-GMAD6QVW-CxbljbtE.js → chunk-GMAD6QVW-DlbCwmvq.js} +1 -1
- package/out/phone/assets/{chunk-GVQU2GXP-CTO3kTOF.js → chunk-GVQU2GXP-DlijzCAw.js} +1 -1
- package/out/phone/assets/{chunk-IMKFNOWR-Cq8XlkcB.js → chunk-IMKFNOWR-B1BOj8O6.js} +1 -1
- package/out/phone/assets/{chunk-L3NEJ4N5-CvIm0JX7.js → chunk-L3NEJ4N5-Fr_w5bRg.js} +1 -1
- package/out/phone/assets/{chunk-OSK3NFVY-Cj3ilTL-.js → chunk-OSK3NFVY-CccDEhXi.js} +1 -1
- package/out/phone/assets/{chunk-P2QGCYS3-B-twI_Fz.js → chunk-P2QGCYS3-Dn46j2El.js} +1 -1
- package/out/phone/assets/{chunk-POPQ4Y6H-lPQttJ5s.js → chunk-POPQ4Y6H-BQchiHrQ.js} +1 -1
- package/out/phone/assets/{chunk-PWAF6VOD-DjwqZuIR.js → chunk-PWAF6VOD-BENw9N2v.js} +1 -1
- package/out/phone/assets/{chunk-SHT3W25Y-BWRVin1H.js → chunk-SHT3W25Y-C93BlEB0.js} +1 -1
- package/out/phone/assets/{chunk-SVP7TREG-CGLhvnsS.js → chunk-SVP7TREG-wfL37BUq.js} +1 -1
- package/out/phone/assets/{chunk-TICWLB2K-DkFUa03q.js → chunk-TICWLB2K-C9-wZ6kk.js} +1 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-CM29lfur.js +1 -0
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-CM29lfur.js +1 -0
- package/out/phone/assets/{codeHighlighter-jQti-W31.js → codeHighlighter-DQ-g-VWX.js} +1 -1
- package/out/phone/assets/{cynefin-OW5HDTMX-L8oWVu5S.js → cynefin-OW5HDTMX-DamvwfM9.js} +1 -1
- package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-DH8-4p4N.js → cynefinDiagram-5FMLGOSQ-Coz1le1N.js} +1 -1
- package/out/phone/assets/{dagre-GXQ25YYZ-HhLDmcu9.js → dagre-GXQ25YYZ-ByJC9Z6k.js} +1 -1
- package/out/phone/assets/desk-XkzvZXuU.js +70 -0
- package/out/phone/assets/{diagram-S7CK7UJ4-CeIbR3Ir.js → diagram-S7CK7UJ4-BabBefXt.js} +1 -1
- package/out/phone/assets/{diagram-UQ7AKVKN-BQ84Qnq6.js → diagram-UQ7AKVKN-DEX56Otl.js} +1 -1
- package/out/phone/assets/{diagram-VSXAHHWV-aF_J57fD.js → diagram-VSXAHHWV-GeNN1ZwW.js} +1 -1
- package/out/phone/assets/{diagram-VX7I27RA-Bg1ZqM4Y.js → diagram-VX7I27RA-DkclPqXj.js} +1 -1
- package/out/phone/assets/{diagram-Z3DM3KII-DjTkPAqa.js → diagram-Z3DM3KII-CDKrxb7_.js} +1 -1
- package/out/phone/assets/{ebnfDiagram-PWID7BFC-DPsH5Eky.js → ebnfDiagram-PWID7BFC-B-lRq0nU.js} +1 -1
- package/out/phone/assets/{erDiagram-RLTQ6QDP-ExvY7e6T.js → erDiagram-RLTQ6QDP-2PdYpZdI.js} +1 -1
- package/out/phone/assets/eventmodeling-NTZA5JFV-DBO84WXk.js +1 -0
- package/out/phone/assets/flowDiagram-HODETNUW-89Bcp6BV.js +1 -0
- package/out/phone/assets/{ganttDiagram-EL5Y4UJY-hCe06ucl.js → ganttDiagram-EL5Y4UJY-XG84VKNq.js} +1 -1
- package/out/phone/assets/{gitGraph-4MIJSDKK-BuZ6lDat.js → gitGraph-4MIJSDKK-BqrA_WVv.js} +1 -1
- package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-D-8aVxvj.js → gitGraphDiagram-WWUBYQGX-BAIxr-mN.js} +1 -1
- package/out/phone/assets/{info-A6RAGUB7-CrZtdoYs.js → info-A6RAGUB7-DE-jKSbG.js} +1 -1
- package/out/phone/assets/{infoDiagram-27XIBGKW-BLRFHxtO.js → infoDiagram-27XIBGKW-BSTxH5Al.js} +1 -1
- package/out/phone/assets/{ishikawaDiagram-5VMMS53U-D7SYWKoj.js → ishikawaDiagram-5VMMS53U-zOO97Npq.js} +1 -1
- package/out/phone/assets/{journeyDiagram-3NMN7TZE-BPsg7CQD.js → journeyDiagram-3NMN7TZE-dSMVlg_5.js} +1 -1
- package/out/phone/assets/{kanban-definition-UXKFOSKX-CbPuNr-E.js → kanban-definition-UXKFOSKX-DHok-qdM.js} +1 -1
- package/out/phone/assets/{line-CkpKMiqK.js → line-C5TJMvf6.js} +1 -1
- package/out/phone/assets/main-Bk2Gcz5l.css +2 -0
- package/out/phone/assets/main-DNK2uR8l.js +277 -0
- package/out/phone/assets/{mermaid-parser.core-RTq_mEm1.js → mermaid-parser.core-CrJ82mWd.js} +3 -3
- package/out/phone/assets/{mermaid.core-D9LtIKua.js → mermaid.core-CkfKqc8K.js} +4 -4
- package/out/phone/assets/{mindmap-definition-YA3MSWOX-8cGgRiRD.js → mindmap-definition-YA3MSWOX-DD-W0NPL.js} +1 -1
- package/out/phone/assets/{packet-AYTQ26CC-D9-eSn0v.js → packet-AYTQ26CC-DEZk6B2e.js} +1 -1
- package/out/phone/assets/{pegDiagram-XKGWAZYB-DztU_rIE.js → pegDiagram-XKGWAZYB-KND-JwT0.js} +1 -1
- package/out/phone/assets/{pie-WAS4IAKB-Bk2Tqaq_.js → pie-WAS4IAKB-DS5oCOdm.js} +1 -1
- package/out/phone/assets/{pieDiagram-E7YTZNPT-Dm_3mJ9_.js → pieDiagram-E7YTZNPT-CfWh8T4Z.js} +1 -1
- package/out/phone/assets/{quadrantDiagram-AXDQQJYC-lKskzjzu.js → quadrantDiagram-AXDQQJYC-CbquaKYM.js} +1 -1
- package/out/phone/assets/{radar-RG4KPBEZ-B2z8Txd8.js → radar-RG4KPBEZ-C0kqKhsd.js} +1 -1
- package/out/phone/assets/{railroad-74A4TZTK-11VmdALq.js → railroad-74A4TZTK-C5WV19mk.js} +1 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-BqkB5NuR.js +1 -0
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-DF9ncZF9.js +1 -0
- package/out/phone/assets/railroad-peg-WCYAUIDC-CrvTMEVw.js +1 -0
- package/out/phone/assets/{railroadDiagram-O6MQD6OU-Dr0NTIA6.js → railroadDiagram-O6MQD6OU-CmkCOdfu.js} +1 -1
- package/out/phone/assets/{requirementDiagram-BXWQKSXE-C0W6h_5I.js → requirementDiagram-BXWQKSXE-CrQKPUwx.js} +1 -1
- package/out/phone/assets/{sankeyDiagram-P5KCCOFB-CVJDathY.js → sankeyDiagram-P5KCCOFB-CBCG-Eyn.js} +1 -1
- package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-BxHQTG6x.js → sequenceDiagram-WJ2MYXX4-D9oVD380.js} +1 -1
- package/out/phone/assets/shellUpdate-2rxcUhg5.js +5 -0
- package/out/phone/assets/{stateDiagram-D77RDMKH-BO5MAjhs.js → stateDiagram-D77RDMKH-VNnCDAvS.js} +1 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Qadztnwb.js +1 -0
- package/out/phone/assets/{swimlanes-42K2YHIH-DnhDPyy6.js → swimlanes-42K2YHIH-DFtKlQwi.js} +1 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-BG4PsK7t.js +8 -0
- package/out/phone/assets/{timeline-definition-24CTP7MA-bLEjS7re.js → timeline-definition-24CTP7MA-BwrAy7Qu.js} +1 -1
- package/out/phone/assets/{treeView-Q6P3EWNA-Ci-sA9wK.js → treeView-Q6P3EWNA-BLyQtiYC.js} +1 -1
- package/out/phone/assets/{treemap-WGGIJYW6-BXCjzK65.js → treemap-WGGIJYW6-gub1bjDX.js} +1 -1
- package/out/phone/assets/{vennDiagram-4TSXK5OY-DHsj5dRx.js → vennDiagram-4TSXK5OY-DayfmvoI.js} +1 -1
- package/out/phone/assets/{wardley-WFR3VGLG-d8TdCu-H.js → wardley-WFR3VGLG-B5_pluIE.js} +1 -1
- package/out/phone/assets/{wardleyDiagram-VM6X3IG4-DQFVP9qu.js → wardleyDiagram-VM6X3IG4-CHS5ryk0.js} +1 -1
- package/out/phone/assets/{xychartDiagram-S5SC5T6Z-Dni2Y0ov.js → xychartDiagram-S5SC5T6Z-C21zSdz1.js} +1 -1
- package/out/phone/desk.html +3 -3
- package/out/phone/index.html +4 -4
- package/out/phone/sw.js +2 -2
- package/out/renderer/assets/EditDiff-DJaW24DH.js +1 -0
- package/out/renderer/assets/ReadFileView-B1RfgY1_.js +4 -0
- package/out/renderer/assets/SidePanel-CXOSOIj_.js +48 -0
- package/out/renderer/assets/{SidePanel-D0m4IYxS.css → SidePanel-DN2RL6QD.css} +1 -1
- package/out/renderer/assets/abnfDiagram-VCTEODGH-DteC7eOG.js +1 -0
- package/out/renderer/assets/{arc-B8im8n0O.js → arc-BafilblL.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-5GKGNRK7-BRSi5FBk.js → architectureDiagram-5GKGNRK7-BXxAIsNI.js} +2 -2
- package/out/renderer/assets/{blockDiagram-I7D4REHJ-CQ1wirIl.js → blockDiagram-I7D4REHJ-Bt4I5z76.js} +1 -1
- package/out/renderer/assets/{c4Diagram-7LVT6UL2-9HyLIioe.js → c4Diagram-7LVT6UL2-Dg1rhQSn.js} +1 -1
- package/out/renderer/assets/channel-CpN2DlDo.js +1 -0
- package/out/renderer/assets/{chunk-2Q5K7J3B-BwC9g3bx.js → chunk-2Q5K7J3B-Bea4O-pP.js} +1 -1
- package/out/renderer/assets/{chunk-5VM5RSS4-DMtgxPBL.js → chunk-5VM5RSS4-9g4O6TgX.js} +1 -1
- package/out/renderer/assets/{chunk-F27PBJKO-DSi_XV5v.js → chunk-F27PBJKO-CQFAhmZp.js} +1 -1
- package/out/renderer/assets/{chunk-IMKFNOWR-Dctc6Apj.js → chunk-IMKFNOWR-DZKvnXil.js} +1 -1
- package/out/renderer/assets/{chunk-JWPE2WC7-I2BD5qM7.js → chunk-JWPE2WC7-UkNkhirX.js} +1 -1
- package/out/renderer/assets/{chunk-POPQ4Y6H-k60pc4eT.js → chunk-POPQ4Y6H-D3CSUp94.js} +1 -1
- package/out/renderer/assets/{chunk-SVP7TREG-zCGemfqm.js → chunk-SVP7TREG-F3dgPzel.js} +1 -1
- package/out/renderer/assets/{chunk-TICWLB2K-CdDiHIq-.js → chunk-TICWLB2K-URu59zvj.js} +1 -1
- package/out/renderer/assets/{chunk-XXDRQBXY-GYVDxVfN.js → chunk-XXDRQBXY-DRFxCPER.js} +1 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-D-KG_eK-.js +1 -0
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-D-KG_eK-.js +1 -0
- package/out/renderer/assets/cose-bilkent-JH36ORCC-Bx5VqEhK.js +1 -0
- package/out/renderer/assets/{cynefin-OW5HDTMX-DnQaS9VN.js → cynefin-OW5HDTMX-YKYl0dFh.js} +1 -1
- package/out/renderer/assets/cynefinDiagram-5FMLGOSQ-DaHqCls4.js +62 -0
- package/out/renderer/assets/{dagre-GXQ25YYZ-fG1vMsyn.js → dagre-GXQ25YYZ-CRqSls6Q.js} +1 -1
- package/out/renderer/assets/{diagram-S7CK7UJ4-BcfAFVc2.js → diagram-S7CK7UJ4-_oJhPbvH.js} +1 -1
- package/out/renderer/assets/diagram-UQ7AKVKN-B7P-4UYL.js +41 -0
- package/out/renderer/assets/{diagram-VSXAHHWV-B-U9CIWt.js → diagram-VSXAHHWV--0uBugR7.js} +1 -1
- package/out/renderer/assets/diagram-VX7I27RA-IaMWXRBT.js +24 -0
- package/out/renderer/assets/diagram-Z3DM3KII-BLCY3C4h.js +24 -0
- package/out/renderer/assets/ebnfDiagram-PWID7BFC-CUYHhexz.js +1 -0
- package/out/renderer/assets/{erDiagram-RLTQ6QDP-CfMNvEoW.js → erDiagram-RLTQ6QDP-BIOsECZV.js} +1 -1
- package/out/renderer/assets/{flowDiagram-HODETNUW-C8XM3p4T.js → flowDiagram-HODETNUW-DjggEdce.js} +1 -1
- package/out/renderer/assets/ganttDiagram-EL5Y4UJY-Dik61bQB.js +292 -0
- package/out/renderer/assets/gitGraphDiagram-WWUBYQGX-BrPFNa7W.js +106 -0
- package/out/renderer/assets/index-CtOLwaEJ.css +1 -0
- package/out/renderer/assets/index-mVE4g58q.js +3003 -0
- package/out/renderer/assets/infoDiagram-27XIBGKW-ZfCvFQE5.js +2 -0
- package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-mUoXchkB.js → ishikawaDiagram-5VMMS53U-BhteuTmM.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-3NMN7TZE-zzLL0HFW.js → journeyDiagram-3NMN7TZE-BJyr-G3R.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UXKFOSKX-BJ_9aIhB.js → kanban-definition-UXKFOSKX-CJyl9IUl.js} +1 -1
- package/out/renderer/assets/{layout-3SRMHY7n.js → layout-oTkojEy1.js} +1 -1
- package/out/renderer/assets/{linear-CWpclK_R.js → linear-qICDecPr.js} +1 -1
- package/out/renderer/assets/{mermaid.core-DORpmVi3.js → mermaid.core-F0flUThf.js} +5 -5
- package/out/renderer/assets/{mindmap-definition-YA3MSWOX-CYBlCqIB.js → mindmap-definition-YA3MSWOX-pG7PXlKk.js} +1 -1
- package/out/renderer/assets/pegDiagram-XKGWAZYB-CwO9p66t.js +1 -0
- package/out/renderer/assets/{pieDiagram-E7YTZNPT-Bzpc57-A.js → pieDiagram-E7YTZNPT-BpqTKO7A.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-spKXEbds.js → quadrantDiagram-AXDQQJYC-Ci1QOcG6.js} +1 -1
- package/out/renderer/assets/railroadDiagram-O6MQD6OU-Be-ymk25.js +1 -0
- package/out/renderer/assets/{requirementDiagram-BXWQKSXE-CX-Dqij_.js → requirementDiagram-BXWQKSXE-Dotur23i.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-Bgx1W6B9.js → sankeyDiagram-P5KCCOFB-BlTTRpKU.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-CKQv6pcU.js → sequenceDiagram-WJ2MYXX4-C_llXVvH.js} +1 -1
- package/out/renderer/assets/{sessionChanges-BLzNhRuv.js → sessionChanges-BpPkx6v0.js} +5 -5
- package/out/renderer/assets/sizeCapture-INFHLROL-xhuCXQI9.js +1 -0
- package/out/renderer/assets/stateDiagram-D77RDMKH-BfESnkCR.js +1 -0
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-C7QWw0La.js +1 -0
- package/out/renderer/assets/swimlanes-42K2YHIH-DX8_KJTt.js +1 -0
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B7JGQCYf.js +8 -0
- package/out/renderer/assets/{timeline-definition-24CTP7MA-CsZAMmMZ.js → timeline-definition-24CTP7MA-DIoNEHAB.js} +1 -1
- package/out/renderer/assets/{vennDiagram-4TSXK5OY-COQ7L1f7.js → vennDiagram-4TSXK5OY-KrS4uyWo.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-dqMWLTCs.js → wardleyDiagram-VM6X3IG4-D4i6zXyf.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-DX4clIYP.js → xychartDiagram-S5SC5T6Z-DpCpSTPN.js} +1 -1
- package/out/renderer/index.html +2 -3
- package/out/renderer/web-preload.js +1 -51
- package/out/server/agent.js +1413 -307
- package/out/server/chunks/agentConstants-D4t7d6iS.js +9 -0
- package/out/server/chunks/builtinOccupancy-zo5-z-s5.js +93 -0
- package/out/server/chunks/dispatchModel-D7papgSj.js +76 -0
- package/out/server/chunks/{gpuBackendInstall-jAzoFq7U.js → gpuBackendInstall-xFEdr70P.js} +2 -2
- package/out/server/chunks/killTree-T-p6Lr3w.js +787 -0
- package/out/server/chunks/{loadProvider-NdOVbsHi.js → loadProvider-ChfeR5km.js} +2 -2
- package/out/server/chunks/{manifest-BPXFscqI.js → manifest-CmnE8RBt.js} +4 -2
- package/out/server/chunks/menuSkills-DC4qs2MC.js +54 -0
- package/out/server/chunks/projectCode-BAgpkYYS.js +112 -0
- package/out/server/chunks/{registry-BhoHPSKn.js → registry-G4AKEQtl.js} +98 -116
- package/out/server/chunks/sendImage-BmenO8Vx.js +646 -0
- package/out/server/chunks/{sendImage-BCNW9JRV.js → toolParams-0GakTs9V.js} +25 -234
- package/out/server/chunks/web-9MujZLkq.js +7787 -0
- package/out/server/chunks/{workflowPresets-C2T1BzA2.js → workflowPresets-CTv2r-Sh.js} +13659 -15598
- package/out/server/index.js +10281 -3781
- package/out/server/memory-service.js +205 -148
- package/out/server/plugin-host.js +44 -18
- package/package.json +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-Duql1LsL.js +0 -1
- package/out/phone/assets/channel-BPoIHov1.js +0 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-CIR76lHP.js +0 -1
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-CIR76lHP.js +0 -1
- package/out/phone/assets/desk-CixRGdTk.js +0 -52
- package/out/phone/assets/eventmodeling-NTZA5JFV-DYp-zWcL.js +0 -1
- package/out/phone/assets/flowDiagram-HODETNUW-CIU32By5.js +0 -1
- package/out/phone/assets/main-BCnf7dVM.js +0 -264
- package/out/phone/assets/main-nqB-uD3v.css +0 -2
- package/out/phone/assets/railroad-abnf-HS5TGJTU-BkSycwye.js +0 -1
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-BsPIU3iV.js +0 -1
- package/out/phone/assets/railroad-peg-WCYAUIDC-Cy8G7u5C.js +0 -1
- package/out/phone/assets/shellUpdate-DPSfgHG3.js +0 -36
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-B8IHc2bm.js +0 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-dmSDAN2F.js +0 -8
- package/out/renderer/assets/EditDiff-DxxLuCEI.js +0 -1
- package/out/renderer/assets/File-Tz3MUtN6.js +0 -1
- package/out/renderer/assets/ReadFileView-DFoLPU04.js +0 -4
- package/out/renderer/assets/SidePanel-CL40W2RY.js +0 -47
- package/out/renderer/assets/Virtualizer-B0uwx_XV.js +0 -1345
- package/out/renderer/assets/abnfDiagram-VCTEODGH-CJ9nn9eH.js +0 -1
- package/out/renderer/assets/channel-DjB0ww6b.js +0 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-6SiAw1np.js +0 -1
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-6SiAw1np.js +0 -1
- package/out/renderer/assets/cose-bilkent-JH36ORCC-BnSAtUh-.js +0 -1
- package/out/renderer/assets/cynefinDiagram-5FMLGOSQ-BNQdw0PV.js +0 -62
- package/out/renderer/assets/cytoscape-fcose-CzkrRInm.js +0 -1
- package/out/renderer/assets/cytoscape.esm-DzSz-X2X.js +0 -321
- package/out/renderer/assets/diagram-UQ7AKVKN-D8f3Tsx9.js +0 -41
- package/out/renderer/assets/diagram-VX7I27RA-CX6ifTkJ.js +0 -24
- package/out/renderer/assets/diagram-Z3DM3KII-49dS9s3L.js +0 -24
- package/out/renderer/assets/ebnfDiagram-PWID7BFC-CraGJRI7.js +0 -1
- package/out/renderer/assets/ganttDiagram-EL5Y4UJY-DlJBMKFX.js +0 -292
- package/out/renderer/assets/gitGraphDiagram-WWUBYQGX-DvEzDsKF.js +0 -106
- package/out/renderer/assets/globals-BFf1P-Y5.js +0 -715
- package/out/renderer/assets/globals-DUBhAVpU.css +0 -1
- package/out/renderer/assets/index-L4TTIP10.js +0 -89
- package/out/renderer/assets/infoDiagram-27XIBGKW-CckfBO-R.js +0 -2
- package/out/renderer/assets/manifest-DOzTaB8J.js +0 -525
- package/out/renderer/assets/pegDiagram-XKGWAZYB-DhWwLs4v.js +0 -1
- package/out/renderer/assets/railroadDiagram-O6MQD6OU-Br553px3.js +0 -1
- package/out/renderer/assets/settings-Bsrw4ERp.js +0 -25
- package/out/renderer/assets/sizeCapture-INFHLROL-DtRedfRe.js +0 -1
- package/out/renderer/assets/stateDiagram-D77RDMKH-CMP5owem.js +0 -1
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-6-731AqJ.js +0 -1
- package/out/renderer/assets/swimlanes-42K2YHIH-D30AvvmW.js +0 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B8KijqIT.js +0 -8
- package/out/renderer/settings.html +0 -23
- package/out/server/chunks/agent-BbNq8i9j.js +0 -4241
- package/out/server/chunks/dispatchModel-CsfmL396.js +0 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as
|
|
1
|
+
import{j as _,o as Vt,p as Le,q as Qt,G as en,s as tn,A as nn,v as sn,w as rn,I as on,x as ve,y as ye,z as J,B as an,H as ln,J as Ee,K as He,L as ge,N as ke,O as oe,P as Wt,S as dn,Q as z,R as Ne,T as hn,U as ae,V as Ge,X as un,Y as ze,Z as fe,_ as cn,$ as fn,a0 as pn,a1 as gn,a2 as mn,a3 as Cn,a4 as _e,a5 as me,a6 as ut,a7 as Gt,a8 as ct,a9 as Sn,aa as Ln,ab as Se,ac as yn,ad as $,ae as xn,af as le,ag as _t,ah as ft,ai as kn,aj as Ae,ak as vn,al as En,am as Hn,an as wn,ao as pt,ap as Rn,aq as An,ar as Tn,as as bn,at as $t,au as Dn,av as gt,aw as Mn,ax as In,ay as Fn,az as mt,aA as Pn,aB as Nn,aC as zn,aD as On,aE as Un,aF as Bn,aG as Ct,aH as Vn,aI as Wn,aJ as Gn,aK as St,aL as $e,aM as _n,aN as $n,aO as jn,aP as jt,aQ as je,aR as Kn,aS as qn,h as Xn,aT as Yn}from"./index-mVE4g58q.js";function Jn({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function Zn(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:Qn(n,e.startContentIndex)}}function Qn(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 Gs({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:i,renderHeaderFilenameSuffix:s,renderHeaderMetadata:r,renderAnnotation:o,renderGutterUtility:l,renderMergeConflictUtility:a,lineAnnotations:d,getHoveredLine:h,getInstance:u}){const c=n?.(e),f=i?.(e),p=s?.(e),g=r?.(e);return _.jsxs(_.Fragment,{children:[c!=null?_.jsx("div",{slot:Vt,children:c}):_.jsxs(_.Fragment,{children:[f!=null&&_.jsx("div",{slot:"header-prefix",children:f}),p!=null&&_.jsx("div",{slot:"header-filename-suffix",children:p}),g!=null&&_.jsx("div",{slot:"header-metadata",children:g})]}),o!=null&&d?.map((C,S)=>_.jsx("div",{slot:Le(C),children:o(C)},S)),t!=null&&a!=null&&u!=null&&t.map(C=>{if(C==null)return;const S=ei(C,e);return _.jsx("div",{slot:S,style:Qt,children:a(C,u)},S)}),l!=null&&_.jsx("div",{slot:"gutter-utility-slot",style:en,children:l(h)})]})}function ei(e,t){const n=Zn(e,t);return n!=null?Jn({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}class ti extends tn{constructor(){super(...arguments),this.tokenize=ii}equals(t,n,i){return i.ignoreWhitespace?((!i.newlineIsToken||!t.includes(`
|
|
2
2
|
`))&&(t=t.trim()),(!i.newlineIsToken||!n.includes(`
|
|
3
3
|
`))&&(n=n.trim())):i.ignoreNewlineAtEof&&!i.newlineIsToken&&(t.endsWith(`
|
|
4
4
|
`)&&(t=t.slice(0,-1)),n.endsWith(`
|
|
@@ -10,7 +10,7 @@ import{j as G,b as Vt,L as Qt,N as en,O as tn,P as nn,Q as sn,R as ve,S as ye,T
|
|
|
10
10
|
`}function ri(e,t,n,i,s,r,o){if(typeof o=="function"&&(o={callback:o}),o?.callback){const{callback:l}=o;xt(e,t,n,i,s,r,Object.assign(Object.assign({},o),{callback:a=>{l(a?Ze(a,o.headerOptions):void 0)}}))}else{const l=xt(e,t,n,i,s,r,o);return l?Ze(l,o?.headerOptions):void 0}}function oi(e){const t=e.endsWith(`
|
|
11
11
|
`),n=e.split(`
|
|
12
12
|
`).map(i=>i+`
|
|
13
|
-
`);return t?n.pop():n.push(n.pop().slice(0,-1)),n}const ai=new TextEncoder,li=new TextDecoder("utf-8",{ignoreBOM:!0}),di=/[\uD800-\uDFFF]/,Qe=1024;let Ce=new Uint8Array(Qe);function hi(){Ce.length!==Qe&&(Ce=new Uint8Array(Qe))}function P(e){if(e.length===0)return e;if(di.test(e))return JSON.parse(JSON.stringify(e));const t=e.length*3;Ce.length<t&&(Ce=new Uint8Array(t));const{written:n}=ai.encodeInto(e,Ce);return li.decode(Ce.subarray(0,n))}const ui=4096,ci=.5;function fi(e){for(const t of e.hunks){for(let n=0;n<t.hunkContent.length;n++){const i=t.hunkContent[n];if(i.type!=="change")continue;const s=gi(e,i);s!=null&&(t.hunkContent.splice(n,1,...s),n+=s.length-1)}pi(t,e)}}function pi(e,t){const{hunkContent:n}=e;for(let i=1;i<n.length;i++){const s=n[i],r=n[i-1];if(s.type!=="change"||s.additions>0&&s.deletions>0||r.type!=="context")continue;const o=s.additions>0,l=o?t.additionLines:t.deletionLines,a=o?s.additionLineIndex:s.deletionLineIndex,d=o?s.additions:s.deletions,h=l[a]??"";if(h.trim()!=="")continue;let u=!0;for(let C=1;C<d;C++)if(l[a+C]!==h){u=!1;break}if(!u)continue;let c=0;for(;c<r.lines&&t.additionLines[r.additionLineIndex+r.lines-1-c]===h;)c++;if(c===0||i===1&&c===r.lines)continue;s.additionLineIndex-=c,s.deletionLineIndex-=c;const f=s.additionLineIndex+s.additions,p=s.deletionLineIndex+s.deletions,g=n[i+1];g?.type==="context"?(g.lines+=c,g.additionLineIndex=f,g.deletionLineIndex=p):n.splice(i+1,0,{type:"context",lines:c,additionLineIndex:f,deletionLineIndex:p}),r.lines-=c,r.lines===0&&(n.splice(i-1,1),i--)}}function gi(e,t){const{deletions:n,additions:i,deletionLineIndex:s,additionLineIndex:r}=t,o=Math.min(n,i),l=Math.abs(i-n);if(o===0||l===0||o*(l+1)>ui)return null;const a=[];for(let g=0;g<n;g++)a.push(kt(e.deletionLines[s+g]??""));const d=[];for(let g=0;g<i;g++)d.push(kt(e.additionLines[r+g]??""));const h=i>n;let u=0,c=-1;for(let g=0;g<=l;g++){let C=0;for(let S=0;S<o;S++)C+=Ci(a[S+(h?0:g)],d[S+(h?g:0)]);g===0?c=C+o*ci:C>c&&(c=C,u=g)}if(u===0)return null;const f=[],p=(g,C,S,m)=>{(g>0||C>0)&&f.push({type:"change",deletions:g,additions:C,deletionLineIndex:S,additionLineIndex:m})};return h?(p(0,u,s,r),p(o,o,s,r+u),p(0,i-o-u,s+o,r+u+o)):(p(u,0,s,r),p(o,o,s+u,r),p(n-o-u,0,s+u+o,r+o)),f}const mi=/\s+/g;function kt(e){return e.replace(mi,"")}function Ci(e,t){if(e===t)return 1;const n=Math.max(e.length,t.length),i=Math.min(e.length,t.length);if(i===0)return 0;let s=0;for(;s<i&&e[s]===t[s];)s++;let r=0;for(;r<i-s&&e[e.length-1-r]===t[t.length-1-r];)r++;return(s+r)/n}function Si(e,t){try{return Li(e,t)}finally{hi()}}function Li(e,{cacheKey:t,isGitDiff:n=
|
|
13
|
+
`);return t?n.pop():n.push(n.pop().slice(0,-1)),n}const ai=new TextEncoder,li=new TextDecoder("utf-8",{ignoreBOM:!0}),di=/[\uD800-\uDFFF]/,Qe=1024;let Ce=new Uint8Array(Qe);function hi(){Ce.length!==Qe&&(Ce=new Uint8Array(Qe))}function P(e){if(e.length===0)return e;if(di.test(e))return JSON.parse(JSON.stringify(e));const t=e.length*3;Ce.length<t&&(Ce=new Uint8Array(t));const{written:n}=ai.encodeInto(e,Ce);return li.decode(Ce.subarray(0,n))}const ui=4096,ci=.5;function fi(e){for(const t of e.hunks){for(let n=0;n<t.hunkContent.length;n++){const i=t.hunkContent[n];if(i.type!=="change")continue;const s=gi(e,i);s!=null&&(t.hunkContent.splice(n,1,...s),n+=s.length-1)}pi(t,e)}}function pi(e,t){const{hunkContent:n}=e;for(let i=1;i<n.length;i++){const s=n[i],r=n[i-1];if(s.type!=="change"||s.additions>0&&s.deletions>0||r.type!=="context")continue;const o=s.additions>0,l=o?t.additionLines:t.deletionLines,a=o?s.additionLineIndex:s.deletionLineIndex,d=o?s.additions:s.deletions,h=l[a]??"";if(h.trim()!=="")continue;let u=!0;for(let C=1;C<d;C++)if(l[a+C]!==h){u=!1;break}if(!u)continue;let c=0;for(;c<r.lines&&t.additionLines[r.additionLineIndex+r.lines-1-c]===h;)c++;if(c===0||i===1&&c===r.lines)continue;s.additionLineIndex-=c,s.deletionLineIndex-=c;const f=s.additionLineIndex+s.additions,p=s.deletionLineIndex+s.deletions,g=n[i+1];g?.type==="context"?(g.lines+=c,g.additionLineIndex=f,g.deletionLineIndex=p):n.splice(i+1,0,{type:"context",lines:c,additionLineIndex:f,deletionLineIndex:p}),r.lines-=c,r.lines===0&&(n.splice(i-1,1),i--)}}function gi(e,t){const{deletions:n,additions:i,deletionLineIndex:s,additionLineIndex:r}=t,o=Math.min(n,i),l=Math.abs(i-n);if(o===0||l===0||o*(l+1)>ui)return null;const a=[];for(let g=0;g<n;g++)a.push(kt(e.deletionLines[s+g]??""));const d=[];for(let g=0;g<i;g++)d.push(kt(e.additionLines[r+g]??""));const h=i>n;let u=0,c=-1;for(let g=0;g<=l;g++){let C=0;for(let S=0;S<o;S++)C+=Ci(a[S+(h?0:g)],d[S+(h?g:0)]);g===0?c=C+o*ci:C>c&&(c=C,u=g)}if(u===0)return null;const f=[],p=(g,C,S,m)=>{(g>0||C>0)&&f.push({type:"change",deletions:g,additions:C,deletionLineIndex:S,additionLineIndex:m})};return h?(p(0,u,s,r),p(o,o,s,r+u),p(0,i-o-u,s+o,r+u+o)):(p(u,0,s,r),p(o,o,s+u,r),p(n-o-u,0,s+u+o,r+o)),f}const mi=/\s+/g;function kt(e){return e.replace(mi,"")}function Ci(e,t){if(e===t)return 1;const n=Math.max(e.length,t.length),i=Math.min(e.length,t.length);if(i===0)return 0;let s=0;for(;s<i&&e[s]===t[s];)s++;let r=0;for(;r<i-s&&e[e.length-1-r]===t[t.length-1-r];)r++;return(s+r)/n}function Si(e,t){try{return Li(e,t)}finally{hi()}}function Li(e,{cacheKey:t,isGitDiff:n=an.test(e),oldFile:i,newFile:s,throwOnError:r=!1}={}){let o=0;const l=Ei(e,"@@ ");let a;const d=i==null||s==null;let h=0,u=0;for(const c of l){const f=Kt(c),p=f[0];if(p==null){if(r)throw Error("parsePatchContent: invalid hunk");console.error("parsePatchContent: invalid hunk",c);continue}const g=ki(p);let C=0,S=0;if(g==null||a==null){if(a!=null){if(r)throw Error("parsePatchContent: Invalid hunk");console.error("parsePatchContent: Invalid hunk",c);continue}a={name:"",type:"change",hunks:[],splitLineCount:0,unifiedLineCount:0,isPartial:d,additionLines:!d&&i!=null&&s!=null?vt(s.contents):[],deletionLines:!d&&i!=null&&s!=null?vt(i.contents):[],cacheKey:Ht(t)},a.additionLines.length===1&&s?.contents===""&&(a.additionLines.length=0),a.deletionLines.length===1&&i?.contents===""&&(a.deletionLines.length=0);for(const x of f){if(x.startsWith("diff --git")){const M=x.trim().match(nn),D=M?.[1]??M?.[2],E=M?.[3]??M?.[4];if(D==null||E==null){if(r)throw Error("parsePatchContent: invalid git diff header");console.error("parsePatchContent: invalid git diff header",x);continue}a.name=P(E.trim()),D!==E&&(a.prevName=P(D.trim()));continue}const w=x.startsWith("---")||x.startsWith("+++")?x.match(n?sn:rn):null;if(w!=null){const[,M,D]=w;if(M==="---"&&D!=="/dev/null"){const E=P(D.trim());a.prevName=E,a.name=E}else M==="+++"&&D!=="/dev/null"&&(a.name=P(D.trim()))}else if(n){if(x.startsWith("new mode ")&&(a.mode=P(x.slice(8).trim())),x.startsWith("old mode ")&&(a.prevMode=P(x.slice(8).trim())),x.startsWith("new file mode")&&(a.type="new",a.mode=P(x.slice(13).trim())),x.startsWith("deleted file mode")&&(a.type="deleted",a.mode=P(x.slice(17).trim())),x.startsWith("similarity index")&&(x.startsWith("similarity index 100%")?a.type="rename-pure":a.type="rename-changed"),x.startsWith("index ")){const[,M,D,E]=x.trim().match(on)??[];M!=null&&(a.prevObjectId=P(M)),D!=null&&(a.newObjectId=P(D)),E!=null&&(a.mode=P(E))}x.startsWith("rename from ")&&(a.prevName=P(x.slice(12).trim())),x.startsWith("rename to ")&&(a.name=P(x.slice(10).trim()))}}continue}let m,k;for(;f.length>0&&(f[f.length-1]===`
|
|
14
14
|
`||f[f.length-1]==="\r"||f[f.length-1]===`\r
|
|
15
15
|
`||f[f.length-1]==="");)f.pop();const{additionStart:v,deletionStart:L}=g;h=d?h:L-1,u=d?u:v-1;const y={collapsedBefore:0,splitLineCount:0,splitLineStart:0,unifiedLineCount:0,unifiedLineStart:0,additionCount:g.additionCount,additionStart:v,additionLines:C,deletionCount:g.deletionCount,deletionStart:L,deletionLines:S,deletionLineIndex:h,additionLineIndex:u,hunkContent:[],hunkContext:Ht(g.hunkContext),hunkSpecs:P(p),noEOFCRAdditions:!1,noEOFCRDeletions:!1};let H=0,N=0;for(let x=1;x<f.length;x++){const w=f[x];if(H>=y.additionCount&&N>=y.deletionCount&&!w.startsWith("\\")){if(r&&yi(w)&&!xi(w))throw Error("parsePatchContent: hunk has more lines than expected");break}const M=w[0];if(M!=="+"&&M!=="-"&&M!==" "&&M!=="\\"){if(r)throw Error("parsePatchContent: invalid hunk line");console.error(`parseLineType: Invalid firstChar: "${M}", full line: "${w}"`),console.error("processFile: invalid rawLine:",w);continue}const D=Hi(M);if(D==="addition"){if(r&&H>=y.additionCount)throw Error("parsePatchContent: hunk has too many addition lines");const E=Ke(w);(m==null||m.type!=="change")&&(m=qe("change",h,u),y.hunkContent.push(m)),u++,H++,d&&a.additionLines.push(E),m.additions++,C++,k="addition"}else if(D==="deletion"){if(r&&N>=y.deletionCount)throw Error("parsePatchContent: hunk has too many deletion lines");const E=Ke(w);(m==null||m.type!=="change")&&(m=qe("change",h,u),y.hunkContent.push(m)),h++,N++,d&&a.deletionLines.push(E),m.deletions++,S++,k="deletion"}else if(D==="context"){if(r&&(N>=y.deletionCount||H>=y.additionCount))throw Error("parsePatchContent: hunk has too many context lines");const E=Ke(w);(m==null||m.type!=="context")&&(m=qe("context",h,u),y.hunkContent.push(m)),u++,h++,H++,N++,d&&(a.deletionLines.push(E),a.additionLines.push(E)),m.lines++,k="context"}else if(D==="metadata"&&m!=null){if(m.type==="context"?(y.noEOFCRAdditions=!0,y.noEOFCRDeletions=!0):k==="deletion"?y.noEOFCRDeletions=!0:k==="addition"&&(y.noEOFCRAdditions=!0),d&&(k==="addition"||k==="context")){const E=a.additionLines.length-1;E>=0&&(a.additionLines[E]=ve(a.additionLines[E]))}if(d&&(k==="deletion"||k==="context")){const E=a.deletionLines.length-1;E>=0&&(a.deletionLines[E]=ve(a.deletionLines[E]))}}}if(r&&(H!==y.additionCount||N!==y.deletionCount))throw Error("parsePatchContent: hunk line count mismatch");y.additionLines=C,y.deletionLines=S,y.collapsedBefore=Math.max(ye(y.additionStart,y.additionCount)-o,0),a.hunks.push(y),o=J(y.additionStart,y.additionCount);for(const x of y.hunkContent)x.type==="context"?(y.splitLineCount+=x.lines,y.unifiedLineCount+=x.lines):(y.splitLineCount+=Math.max(x.additions,x.deletions),y.unifiedLineCount+=x.deletions+x.additions);y.splitLineStart=a.splitLineCount+y.collapsedBefore,y.unifiedLineStart=a.unifiedLineCount+y.collapsedBefore,a.splitLineCount+=y.collapsedBefore+y.splitLineCount,a.unifiedLineCount+=y.collapsedBefore+y.unifiedLineCount}if(a!=null){if(r&&d&&!n&&a.hunks.length===0)throw Error("parsePatchContent: unified file has no hunks");if(a.hunks.length>0&&!d&&a.additionLines.length>0&&a.deletionLines.length>0){const c=a.hunks[a.hunks.length-1],f=J(c.additionStart,c.additionCount),p=a.additionLines.length,g=Math.max(p-f,0);a.splitLineCount+=g,a.unifiedLineCount+=g}return n||(a.prevName!=null&&a.name!==a.prevName?a.hunks.length>0?a.type="rename-changed":a.type="rename-pure":(i==null||i.contents==="")&&s!=null&&s.contents!==""?a.type="new":i!=null&&i.contents!==""&&(s==null||s.contents==="")&&(a.type="deleted")),a.type!=="rename-pure"&&a.type!=="rename-changed"&&(a.prevName=void 0),fi(a),a}}function vt(e){const t=Kt(e);for(let n=0;n<t.length;n++)t[n]=P(t[n]);return t}function Kt(e){if(e.length===0)return[""];const t=[];let n=0;for(;;){const i=e.indexOf(`
|
|
16
16
|
`,n);if(i===-1)break;t.push(e.slice(n,i+1)),n=i+1}return n<e.length&&t.push(e.slice(n)),t}function yi(e){const t=e[0];return t==="+"||t==="-"||t===" "}function xi(e){if(!e.startsWith("--"))return!1;for(let t=2;t<e.length;t++){const n=e[t];if(n!==" "&&n!==" "&&n!==`
|
|
@@ -20,12 +20,12 @@ import{j as G,b as Vt,L as Qt,N as en,O as tn,P as nn,Q as sn,R as ve,S as ye,T
|
|
|
20
20
|
${t}`,i=e.startsWith(t)?0:Et(e,n,0);if(i===-1)return[e];const s=[];i>0&&s.push(e.slice(0,i));let r=i;for(;;){const o=Et(e,n,r+1);if(o===-1)break;s.push(e.slice(r,o)),r=o}return s.push(e.slice(r)),s}function Et(e,t,n){const i=e.indexOf(t,n);return i===-1?-1:i+1}function Ht(e){return e==null?e:P(e)}function Hi(e){return e===" "?"context":e==="\\"?"metadata":e==="+"?"addition":"deletion"}function Ke(e){const t=e.slice(1);return P(t===""?`
|
|
21
21
|
`:t)}function qe(e,t,n){return e==="change"?{type:"change",additions:0,deletions:0,additionLineIndex:n,deletionLineIndex:t}:{type:"context",lines:0,additionLineIndex:n,deletionLineIndex:t}}const wi="/dev/null";function de(e,t,n,i=!1){if(e===null&&t===null)throw new Error("parseDiffFromFile: You must pass oldFile, newFile, or both");const s=e??wt(),r=t??wt(),o=Si(ri(s.name,r.name,s.contents,r.contents,s.header,r.header,n),{cacheKey:(()=>{const a=e?.cacheKey??e?.name,d=t?.cacheKey??t?.name;return a!=null&&d!=null?a+":"+d:a??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 l=t?.lang??(t===null?e?.lang:void 0);return l!=null&&(o.lang=l),o}function wt(){return{name:wi,contents:""}}function Y(e,t){const n=de({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 Ri(e,t){const n=Math.max(e,1);let i=Array.from({length:n},(s,r)=>`${" ".repeat(r+1)}
|
|
22
22
|
`).join("");return i===t&&(i=Array.from({length:n},(s,r)=>`\0${" ".repeat(r)}
|
|
23
|
-
`).join("")),i}function Ai(e){for(const t of e)if(t.trim().length>0)return!1;return!0}function et(e,t){return t.length>0&&t.length<e.deletionLines.length&&Ai(t)}function Ue(e,t,n){const i=e.deletionLines.join(""),s=Ri(t.length,i),r=de({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 Oe(e,t){return Ue(e,[""],t)}function qt(e,t){if(e.additionLines.length===0)return Oe(e,t);if(et(e,e.additionLines))return Ue(e,e.additionLines,t);const n=e.additionLines,i=Y(e,t);return Xt(i,n),i}function Ti(e){return e.length>1&&e.at(-1)===""}function Xt(e,t){if(!Ti(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&&J(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,ht(e);return}}}function bi(e,t,n){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return X(e,Y(e,n));const i=Array.from(t);if(i.length===0)return X(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of i){const o=e.additionLines[r],l=e.deletionLines[r];if(o==null||l==null||ve(o)===ve(l))return X(e,Y(e,n))}const s=Di(e,i);if(s.size===0)return X(e,Y(e,n));for(const r of s)if(!Ii(e,r,n))return X(e,Y(e,n));return ht(e),
|
|
23
|
+
`).join("")),i}function Ai(e){for(const t of e)if(t.trim().length>0)return!1;return!0}function et(e,t){return t.length>0&&t.length<e.deletionLines.length&&Ai(t)}function Ue(e,t,n){const i=e.deletionLines.join(""),s=Ri(t.length,i),r=de({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 Oe(e,t){return Ue(e,[""],t)}function qt(e,t){if(e.additionLines.length===0)return Oe(e,t);if(et(e,e.additionLines))return Ue(e,e.additionLines,t);const n=e.additionLines,i=Y(e,t);return Xt(i,n),i}function Ti(e){return e.length>1&&e.at(-1)===""}function Xt(e,t){if(!Ti(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&&J(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,ht(e);return}}}function bi(e,t,n){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return X(e,Y(e,n));const i=Array.from(t);if(i.length===0)return X(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of i){const o=e.additionLines[r],l=e.deletionLines[r];if(o==null||l==null||ve(o)===ve(l))return X(e,Y(e,n))}const s=Di(e,i);if(s.size===0)return X(e,Y(e,n));for(const r of s)if(!Ii(e,r,n))return X(e,Y(e,n));return ht(e),ln(e)?X(e,Y(e,n)):X(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function X(e,t){return Object.assign(e,t),t}function Di(e,t){const n=new Set;for(const i of t){const s=Mi(e,i);if(s==null)return new Set;n.add(s)}return n}function Mi(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 Ii(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=de({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...n,context:0}),l=o.hunks[0];return l==null||o.hunks.length!==1?!1:(Fi(i,l),Yt(e,t),!0)}function Yt(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(`
|
|
24
24
|
`),n.noEOFCRDeletions=s!=null&&s!==""&&!s.endsWith(`
|
|
25
|
-
`)}function Fi(e,t){const n=e.additionLineIndex,i=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Jt(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,dt(e)}function Jt(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function dt(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 ht(e){let t=0,n=0,i=0;for(const s of e.hunks)s.collapsedBefore=Math.max(ye(s.additionStart,s.additionCount)-i,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=n+s.collapsedBefore,dt(s),t+=s.collapsedBefore+s.splitLineCount,n+=s.collapsedBefore+s.unifiedLineCount,i=J(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-J(s.additionStart,s.additionCount),0);t+=r,n+=r}e.splitLineCount=t,e.unifiedLineCount=n}const Rt=new WeakMap;function Pi(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function Ni(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 tt(e,t){const n=e.hunks,i=e.additionLines,s=Pi(i),r=s===i?e:{...e,additionLines:s},o=$i(n,Gi(r,t),e.deletionLines.length),l=qi(r,o);if(e.additionLines=s,e.hunks=l,e.editSessionDirty=!0,Zi(e),Xt(e,i),!!Yi(n,e.hunks))return{regions:o.map(a=>a.previousSpan)}}function zi(e,t,n,i){const s=Array.from(new Set(t)).filter(a=>a>=0&&a<e.additionLines.length).sort((a,d)=>a-d);if(s.length===0)return;const{hunks:r}=e;let o,l=0;for(const a of s){for(;l<r.length;){const u=r[l];if(a<Be(u)+u.additionCount)break;l++}const d=r[l],h=d==null?void 0:Be(d);if(h==null||a<h||o!=null&&o!==l)return tt(e,n);o=l}if(o!=null){if(Oi(e,s,o,i,n)){e.editSessionDirty=!0;return}return tt(e,n)}}function Oi(e,t,n,i,s){if(i==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=Ui(e),o=e.hunks[n];if(o.hunkContent.some(Bi))return!1;for(const l of t){const a=i.get(l),d=e.additionLines[l];if(a==null||d==null||r.has(a)||r.has(d))return!1;let h=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&l>=u.additionLineIndex&&l<u.additionLineIndex+u.additions){h=!0;break}if(!h)return!1}return!0}function Ui(e){const t=Rt.get(e);if(t?.lines===e.deletionLines)return t.set;const n=new Set(e.deletionLines);return Rt.set(e,{lines:e.deletionLines,set:n}),n}function Bi(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function Vi(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],l=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),a=o==null?void 0:e.get(o.firstIndex),d=l?.fromStart??0,h=a?.fromEnd??0;(d>0||h>0)&&n.set(s,{fromStart:d,fromEnd:h})}return n}function Wi(e,t,n){const i=[];if(e.isPartial)return i;for(const[r,o]of e.hunks.entries()){const l=Ee({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:n});if(l.rangeSize<=n)continue;const a=he(o),d=a-l.rangeSize;l.fromStart>0&&i.push([d,d+l.fromStart]),l.fromEnd>0&&i.push([a-l.fromEnd,a])}const s=He({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=he(r)+r.deletionCount;i.push([o,o+s.fromStart])}return i}function _i(e,t){const n=new Map;if(t.length===0)return n;const i=(r,o,l)=>{if(l<=o)return;let a=0,d=0;for(const[h,u]of t)u<=o||h>=l||(h<=o&&(a=Math.max(a,Math.min(u,l)-o)),u>=l&&(d=Math.max(d,l-Math.max(h,o))));(a>0||d>0)&&n.set(r,{fromStart:a,fromEnd:d})};for(const[r,o]of e.hunks.entries()){const l=he(o);i(r,l-Math.max(o.collapsedBefore,0),l)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&i(e.hunks.length,he(s)+s.deletionCount,e.deletionLines.length),n}function At(e,t){return e.editSessionDirty!==!0?!1:(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?Y(e,t):qt(e,t)),!0)}function Gi(e,t){if(Ni(e.deletionLines,e.additionLines)==null)return[];const n=de({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 l=o.additionCount>0?o.additionLineIndex-s:o.deletionLineIndex-r;s+=l,r+=l;for(const a of o.hunkContent){if(a.type==="context"){s+=a.lines,r+=a.lines;continue}const d=Jt(a,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 $i(e,t,n){const i=e.map((o,l)=>{const a=he(o);return{deletionStart:a,deletionEnd:a+o.deletionCount,blocks:[],previousSpan:{firstIndex:l,lastIndex:l}}}),s=[];let r=0;for(const o of t){const l=o.deletionLineIndex,a=l+o.deletions;for(;r<i.length&&i[r].deletionEnd<l;)s.push(i[r]),r++;let d=s.length>0&&ji(l,a,s[s.length-1])?s.pop():void 0;for(;r<i.length&&i[r].deletionStart<=a;)d=Ki(d,i[r]),r++;if(d==null){let h=l,u=a;if((o.deletions===0||o.additions===0)&&n>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=i[r]?.deletionStart??n;l>c?h--:a<f&&u++}d={deletionStart:h,deletionEnd:u,blocks:[],previousSpan:void 0}}d.deletionStart=Math.min(d.deletionStart,l),d.deletionEnd=Math.max(d.deletionEnd,a),d.blocks.push(o),s.push(d)}for(;r<i.length;)s.push(i[r]),r++;return s}function ji(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function Ki(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 qi(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 l=s,a=[];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");Tt(a,u,s,i),i+=u,s+=c,a.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");Tt(a,d,s,i),i+=d,s+=d,n.push(Xi(e,{additionStart:l,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},a))}if(e.deletionLines.length-i!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return n}function Xi(e,t,n){const i=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const a of n)a.type==="change"&&(r+=a.additions,o+=a.deletions);const l={collapsedBefore:0,additionStart:be(t.additionStart,i),additionCount:i,additionLines:r,additionLineIndex:Dt(t.additionStart,i),deletionStart:be(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Dt(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 dt(l),l}function Tt(e,t,n,i){t>0&&e.push({type:"context",lines:t,additionLineIndex:n,deletionLineIndex:i})}function Yi(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(he(i)!==he(s)||i.deletionCount!==s.deletionCount||Be(i)!==Be(s)||i.additionCount!==s.additionCount||i.splitLineCount!==s.splitLineCount||!Ji(i,s))return!0}return!1}function Ji(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 Be(e){return ye(e.additionStart,e.additionCount)}function he(e){return ye(e.deletionStart,e.deletionCount)}function be(e,t){return t===0?e:e+1}function Dt(e,t){return t===0?e-1:e}function Zi(e){ht(e);for(let t=0;t<e.hunks.length;t++)Yt(e,t)}async function nt(e,t=300){let n;try{await Promise.race([e(),new Promise(i=>{n=setTimeout(i,t)})])}finally{n!=null&&clearTimeout(n)}}function Qi({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:i,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:l}){let a=ge(t,n),d=a;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=Ee({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:h,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(a+=g,d+=g,p.collapsedLines>0){const m=ke({type:i,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;a+=m,d+=m}a+=f.splitLineCount*t.lineHeight,d+=f.unifiedLineCount*t.lineHeight;const C=es(f);a+=C.split*t.lineHeight,d+=C.unified*t.lineHeight;const S=c===u?He({fileDiff:e,hunkIndex:c,expandedHunks:h,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(S!=null){const m=(S.fromStart+S.fromEnd)*t.lineHeight;if(a+=m,d+=m,S.collapsedLines>0){const k=oe({type:i,metrics:t})?.totalHeight??0;a+=k,d+=k}}else if(c===u&&e.isPartial&&l){const m=oe({type:i,metrics:t})?.totalHeight??0;a+=m,d+=m}}if(e.hunks.length>0){const c=Wt(t);a+=c,d+=c}return{splitHeight:a,unifiedHeight:d}}function es(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 ts(e,t)}function ts(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 it({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 ns(e){return{...e,hunks:e.hunks.map(t=>({...t,hunkContent:t.hunkContent.map(n=>({...n}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function st(e){return e!==""?e.split(an):[]}function rt(e,t,n){const i=e==="clone"?ns(t):t;if(!i.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(i.type){case"change":case"rename-changed":return is(i,rs(i,n),Mt(i,n));case"rename-pure":{const s=Mt(i,n);os(i,n);const r=st(s.contents);return i.isPartial=!1,i.deletionLines=r,i.additionLines=r,Zt(i,null,s),i}}throw new Error(`hydratePartialDiff: ${i.type} diffs cannot be hydrated from loaded files`)}function is(e,t,n){const i=st(t.contents),s=st(n.contents),{hunks:r,splitLineCount:o,unifiedLineCount:l}=ss(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=l,e.isPartial=!1,e.deletionLines=i,e.additionLines=s,Zt(e,t,n),e}function ss(e,t){let n=0,i=0,s=0;const r=[];for(const o of e){const l=Math.max(o.additionStart-1,0),a=Math.max(o.deletionStart-1,0);let d=l,h=a,u=0,c=0,f=0,p=0;const g=[];for(const S of o.hunkContent){if(S.type==="context"){g.push({...S,additionLineIndex:d,deletionLineIndex:h}),d+=S.lines,h+=S.lines,f+=S.lines,p+=S.lines;continue}g.push({...S,additionLineIndex:d,deletionLineIndex:h}),d+=S.additions,h+=S.deletions,u+=S.additions,c+=S.deletions,f+=Math.max(S.additions,S.deletions),p+=S.additions+S.deletions}const C=Math.max(ye(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:C,additionLineIndex:l,deletionLineIndex:a,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:n+C,unifiedLineStart:i+C,splitLineCount:f,unifiedLineCount:p}),n+=C+f,i+=C+p,s=J(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],l=J(o.additionStart,o.additionCount),a=Math.max(t-l,0);n+=a,i+=a}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 Mt(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function os(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function as(e,t,n){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:ls(t,n)}function Zt(e,t,n){const i=as(e,t,n);if(i==null){delete e.cacheKey;return}e.cacheKey=i}function ls(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 ot(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function De(e){return z({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function Me(e){return z({tagName:"div",children:[z({tagName:"span",children:[Ne("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Xe(e){return z({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 l=0;const a=[];if(e==="metadata"&&t!=null&&a.push(z({tagName:"div",children:[Ne(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const d=[];n!=null&&(i?(r||(d.push(Xe("up")),l++),o||(d.push(Xe("down")),l++)):(d.push(Xe(!r&&!o?"both":r?"down":"up")),l++)),d.push(z({tagName:"div",children:[z({tagName:"span",children:[Ne(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),i&&n!=null&&d.push(z({tagName:"div",children:[Ne("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),a.push(z({tagName:"div",children:d,properties:{"data-separator-wrapper":"","data-separator-multi-button":l>1?"":void 0}}))}return e==="custom"&&s!=null&&a.push(z({tagName:"slot",properties:{name:s}})),z({tagName:"div",children:a,properties:{"data-separator":a.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function hs(e,t){return`hunk-separator-${e}-${t}`}function us(e){const t=e.at(-1);return t==null?0:Math.max(J(t.additionStart,t.additionCount),J(t.deletionStart,t.deletionCount))}let cs=-1;var fs=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++cs}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;editSessionActive=!1;constructor(e={theme:ae},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=$e(e.theme??ae)?dn():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,Oe(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)||Pe(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);fe(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)??hn}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=[],l=new Map;for(const[d,h]of e){const u=r[d]?.properties??{},c=h.map(C=>C[2]).join(""),f=d<s.additionLines.length,p=f?s.additionLines[d]??"":"",g=ve(p);f&&(s.additionLines[d]=En(p,c),g!==c&&(o.push(d),l.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(([C,S,m])=>C===0&&S===""?m===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:m}:{type:"element",tagName:"span",properties:{"data-char":C,style:`color:${S};`},children:[{type:"text",value:m}]})}}let a=!1;if(o.length>0)if(this.editSessionActive&&!s.isPartial){if(!n)if(s.additionLines.length<=1&&s.additionLines.join("")==="")Object.assign(s,Oe(s,this.options.parseDiffOptions)),this.markEditSessionPass(s),a=!0;else if(et(s,s.additionLines))Object.assign(s,Ue(s,s.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(s),a=!0;else{const d=zi(s,o,this.options.parseDiffOptions,l);this.applyExpansionRemap(d),a=d!=null}}else Object.assign(s,bi(s,o,this.options.parseDiffOptions));return i.baseThemeType=t,this.renderCache.isDirty=!0,a}applyExpansionRemap(e){e!=null&&(this.expandedHunks=Vi(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=Cs(e,i),n.code.additionLines=ms(i,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join("")===""?(Object.assign(t,Oe(t,this.options.parseDiffOptions)),n.code.additionLines[0]=at(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,qt(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){const{parseDiffOptions:t}=this.options,n=e.additionLines;if(et(e,n)){Object.assign(e,Ue(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(tt(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=>Hn(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:l=!1,collapsedContextThreshold:a=1,expansionLineCount:d=100,hunkSeparators:h="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=ae,headerRenderMode:C="default",tokenizeMaxLineLength:S=1e3,tokenizeMaxLength:m=un,useTokenTransformer:k=!1,useCSSClasses:v=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:i,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:l,collapsedContextThreshold:a,expansionLineCount:d,hunkSeparators:h,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:C,tokenizeMaxLineLength:S,tokenizeMaxLength:m,useTokenTransformer:k,useCSSClasses:v}}async initializeHighlighter(){return this.highlighter=await cn(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=Pe(e,this.getTokenizeMaxLength());let i=this.workerManager?.getDiffResultCache(e);i!=null&&!fe(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??ae}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 l=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&l.useTokenTransformer!==!0?{...l,useTokenTransformer:!0}:l}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)||!fe(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=ut){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 l=e.additionLines.length>0||e.deletionLines.length>0,a=!l||ze(e)||Pe(e,this.getTokenizeMaxLength()),d=!me(e,this.renderCache.diff),h=!$t(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!a&&!d&&ot(t);u&&(this.renderCache.highlightPending=!0),!u&&(a||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,ot(t)||n?!0:this.expandedHunks,i)),this.renderCache.renderRange=t),!a&&l&&(!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&&ft(this.computedLang),f=!a&&c;if(this.highlighter!=null&&u&&(r||a||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderDiffWithHighlighter(e,this.highlighter,a||!c);this.renderCache={diff:e,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!a&&!c)&&this.asyncHighlight(e).then(({result:p,options:g})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,p,g,!a)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=ut){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 Rn({type:"diff",diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){const t=Pe(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&&ft(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=fn(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(Se({diff:e,diffStyle:"both",expandedHunks:n?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:l})=>{if(l?.lineIndex===0)return o=l,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=at(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||!fe(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||!fe(t,n.options)))return n}hasHighlightedRenderCache(e,t){const{renderCache:n}=this;return n?.result!=null&&n.highlighted&&me(e,n.diff)&&fe(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:l,expansionLineCount:a,collapsedContextThreshold:d,hunkSeparators:h}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1;this.diff=e;const c=r==="unified",f=ys(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],C=[],S=[];const m=[],{additionLines:k,deletionLines:v}=n,L={rowCount:0,hunkSeparators:h,additionsContentAST:g,deletionsContentAST:C,unifiedContentAST:S,unifiedGutterAST:Ae(),deletionsGutterAST:Ae(),additionsGutterAST:Ae(),expansionLineCount:a,hunkData:m,incrementRowCount(A=1){L.rowCount+=A},pushToGutter(A,T){switch(A){case"unified":L.unifiedGutterAST.children.push(T);break;case"deletions":L.deletionsGutterAST.children.push(T);break;case"additions":L.additionsGutterAST.children.push(T);break}}},y=pn({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"?(L.pushToGutter("additions",$(void 0,"buffer",this.size)),g?.push(De(this.size))):(L.pushToGutter("deletions",$(void 0,"buffer",this.size)),C?.push(De(this.size))),this.size=0,this.side=void 0}}},N=(A,T,Z,ue,R)=>{L.pushToGutter(A,gn(T,Z,ue,R))};function x(A){H.flush(),r==="unified"?Ye("unified",A,L):(Ye("deletions",A,L),Ye("additions",A,L))}this.pushFileLevelAnnotations(e,r,t,L),Se({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:l?!0:this.expandedHunks,collapsedContextThreshold:d,callback:({hunkIndex:A,hunk:T,collapsedBefore:Z,collapsedAfter:ue,additionLine:R,deletionLine:b,type:F})=>{const B=b!=null?b.splitLineIndex:R.splitLineIndex,Q=R!=null?R.unifiedLineIndex:b.unifiedLineIndex;r==="split"&&F!=="change"&&H.flush(),Z>0&&x({hunkIndex:A,collapsedLines:Z,rangeSize:Math.max(T?.collapsedBefore??0,0),hunkSpecs:T?.hunkSpecs,isFirstHunk:A===0,isLastHunk:!1,isExpandable:p});const ce=r==="unified"?Q:B,we={type:F,hunkIndex:A,lineIndex:ce,unifiedLineIndex:Q,splitLineIndex:B,deletionLine:b,additionLine:R};if(r==="unified"){const I=this.getUnifiedInjectedRowsForLine?.(we);I?.before!=null&&Ft(I.before,L);let O=b!=null?v[b.lineIndex]:void 0,V=R!=null?k[R.lineIndex]:void 0;if(O==null&&V==null){const _="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(_,{file:e.name}),new Error(_)}const re=F==="change"?R!=null?"change-addition":"change-deletion":F,W=this.getUnifiedLineDecoration({type:F,lineType:re,additionLineIndex:R?.lineIndex,deletionLineIndex:b?.lineIndex});N("unified",W.gutterLineType,R!=null?R.lineNumber:b.lineNumber,`${Q},${B}`,W.gutterProperties),V!=null?V=Fe(V,W.contentProperties,u&&R!=null?{"data-line":R.lineNumber,"data-line-index":`${Q},${B}`}:void 0):O!=null&&(O=Fe(O,W.contentProperties,u&&b!=null?{"data-line":b.lineNumber,"data-line-index":`${Q},${B}`}:void 0)),Ie({diffStyle:"unified",type:F,deletionLine:O,additionLine:V,unifiedSpan:this.getAnnotations("unified",b?.lineNumber,R?.lineNumber,A,ce),createAnnotationElement:_=>this.createAnnotationElement(_),context:L}),I?.after!=null&&Ft(I.after,L)}else{const I=this.getSplitInjectedRowsForLine?.(we);I?.before!=null&&Pt(I.before,L,H);let O=b!=null?v[b.lineIndex]:void 0,V=R!=null?k[R.lineIndex]:void 0;const re=this.getSplitLineDecoration({side:"deletions",type:F,lineIndex:b?.lineIndex}),W=this.getSplitLineDecoration({side:"additions",type:F,lineIndex:R?.lineIndex});if(O==null&&V==null){const U="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(U,{file:e.name}),new Error(U)}const _=(()=>{if(F==="change"){if(V==null)return"additions";if(O==null)return"deletions"}})();_!=null?(H.side!=null&&H.side!==_&&H.flush(),H.side=_,H.increment()):F==="change"&&H.flush();const ee=this.getAnnotations("split",b?.lineNumber,R?.lineNumber,A,ce);if(ee!=null&&H.size>0&&H.flush(),b!=null){const U=Fe(O,re.contentProperties,u?{"data-line":b.lineNumber,"data-line-index":`${b.unifiedLineIndex},${B}`}:void 0);N("deletions",re.gutterLineType,b.lineNumber,`${b.unifiedLineIndex},${B}`,re.gutterProperties),U!=null&&(O=U)}if(R!=null){const U=Fe(V,W.contentProperties,u?{"data-line":R.lineNumber,"data-line-index":`${R.unifiedLineIndex},${B}`}:void 0);N("additions",W.gutterLineType,R.lineNumber,`${R.unifiedLineIndex},${B}`,W.gutterProperties),U!=null&&(V=U)}Ie({diffStyle:"split",type:F,additionLine:V,deletionLine:O,...ee,createAnnotationElement:U=>this.createAnnotationElement(U),context:L}),I?.after!=null&&Pt(I.after,L,H)}const xe=r==="split"&&T!=null&&B===T.splitLineStart+T.splitLineCount-1,K=A===e.hunks.length-1&&T!=null&&(r==="split"?B===T.splitLineStart+T.splitLineCount-1:Q===T.unifiedLineStart+T.unifiedLineCount-1),Ve=xe?T.noEOFCRDeletions:!1,We=xe?T.noEOFCRAdditions:!1,se=(b?.noEOFCR??!1)||Ve,q=(R?.noEOFCR??!1)||We;if(q||se){if(r==="split"&&H.flush(),se){const I=F==="context"||F==="context-expanded"?F:"change-deletion";r==="unified"?(L.unifiedContentAST.push(Me(I)),L.pushToGutter("unified",$(I,"metadata",1))):(L.deletionsContentAST.push(Me(I)),L.pushToGutter("deletions",$(I,"metadata",1)),q||(L.pushToGutter("additions",$(void 0,"buffer",1)),L.additionsContentAST.push(De(1))))}if(q){const I=F==="context"||F==="context-expanded"?F:"change-addition";r==="unified"?(L.unifiedContentAST.push(Me(I)),L.pushToGutter("unified",$(I,"metadata",1))):(L.additionsContentAST.push(Me(I)),L.pushToGutter("additions",$(I,"metadata",1)),se||(L.pushToGutter("deletions",$(void 0,"buffer",1)),L.deletionsContentAST.push(De(1))))}L.incrementRowCount(1)}h!=="simple"&&h!=="metadata"&&(ue>0||K&&f)&&x({hunkIndex:F==="context-expanded"?A:A+1,collapsedLines:K&&f?"unknown":ue,rangeSize:y,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),L.incrementRowCount(1)}}),r==="split"&&H.flush();const w=Math.max(us(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),M=t.bufferBefore>0||t.bufferAfter>0,D=!c&&e.type!=="deleted",E=!c&&e.type!=="new",j=L.rowCount>0||M;g=D&&j?g:void 0,C=E&&j?C:void 0,S=c&&j?S:void 0;const ie=this.createPreElement(C!=null&&g!=null,w);return{unifiedGutterAST:c&&j?L.unifiedGutterAST.children:void 0,unifiedContentAST:S,deletionsGutterAST:E&&j?L.deletionsGutterAST.children:void 0,deletionsContentAST:C,additionsGutterAST:D&&j?L.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:m,preNode:ie,themeStyles:i,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:w,rowCount:L.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=Ae(n);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,An(i,t.rowCount)]}renderFullAST(e,t=[]){const n=this.getOptionsWithDefaults().hunkSeparators==="line-info",i=this.renderCodeAST("unified",e);if(i!=null)return t.push(z({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(z({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(z({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(z({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"?It(pt(this.deletionAnnotations)):[],r=e.type!=="deleted"?It(pt(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,l=-1,{createAnnotationElement:a}=this;if(t==="unified"){Ie({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:s.concat(r)},createAnnotationElement:a,context:i});return}Ie({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:r},createAnnotationElement:a,context:i})}getAnnotations(e,t,n,i,s){const r={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(t!=null)for(const l of this.deletionAnnotations[t]??[])r.annotations.push(Le(l));const o={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(n!=null)for(const l of this.additionAnnotations[n]??[])(e==="unified"?r:o).annotations.push(Le(l));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 It(e){return e?.map(t=>Le(t))??[]}const ps=new Intl.PluralRules("en-US");function gs(e){return`${e} unmodified line${ps.select(e)==="one"?"":"s"}`}function Ft(e,t){for(const n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function Pt(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 Ie({diffStyle:e,type:t,deletionLine:n,additionLine:i,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:l,context:a}){let d=!1;if(e==="unified"){if(i!=null?a.unifiedContentAST.push(i):n!=null&&a.unifiedContentAST.push(n),s!=null){const h=t==="change"?n!=null?"change-deletion":"change-addition":t;a.unifiedContentAST.push(l(s)),a.pushToGutter("unified",$(h,"annotation",1)),d=!0}}else if(e==="split"){if(n!=null&&a.deletionsContentAST.push(n),i!=null&&a.additionsContentAST.push(i),r!=null){const h=t==="change"?n!=null?"change-deletion":"context":t;a.deletionsContentAST.push(l(r)),a.pushToGutter("deletions",$(h,"annotation",1)),d=!0}if(o!=null){const h=t==="change"?i!=null?"change-addition":"context":t;a.additionsContentAST.push(l(o)),a.pushToGutter("additions",$(h,"annotation",1)),d=!0}}d&&a.incrementRowCount(1)}function Ye(e,{hunkIndex:t,collapsedLines:n,rangeSize:i,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:l},a){if(typeof n=="number"&&n<=0)return;const d=e==="unified"?a.unifiedContentAST:e==="deletions"?a.deletionsContentAST:a.additionsContentAST;if(a.hunkSeparators==="metadata"){s!=null&&(a.pushToGutter(e,pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&a.incrementRowCount(1));return}if(a.hunkSeparators==="simple"){t>0&&(a.pushToGutter(e,pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),d.push(pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&a.incrementRowCount(1));return}const h=hs(e,t),u=i>a.expansionLineCount,c=l?t:void 0,f=typeof n=="number"?gs(n):"More unchanged context may be available";a.pushToGutter(e,pe({type:a.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:a.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&a.incrementRowCount(1),a.hunkData.push({slotName:h,hunkIndex:t,lines:typeof n=="number"?n:0,lineCountKnown:typeof n=="number",type:e,expandable:l?{up:!r,down:!o,chunked:u}:void 0})}function Fe(e,t,n){return e==null||e.type!=="element"||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Nt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function ms(e,t,n,i){const s=Nt(e),r=Nt(t),o=Math.min(s,r);let l=0;for(;l<o&&e[l]===t[l];)l++;let a=0;for(;a<o-l&&e[s-1-a]===t[r-1-a];)a++;const d=new Array(t.length);for(let h=0;h<l;h++)d[h]=n[h];for(let h=0;h<a;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=l;h<t.length;h++)d[h]??=at(h,i.getLineText(h));return d}function at(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 Cs(e,t){const n=[],i=Ls(t);for(let s=0;s<e.lineCount;s++){const r=e.getLineText(s,!0);n.push(s<e.lineCount-1&&!Ss(r)?r+i:r)}return n}function Ss(e){return e.endsWith(`
|
|
25
|
+
`)}function Fi(e,t){const n=e.additionLineIndex,i=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Jt(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,dt(e)}function Jt(e,t,n){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+n}}function dt(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 ht(e){let t=0,n=0,i=0;for(const s of e.hunks)s.collapsedBefore=Math.max(ye(s.additionStart,s.additionCount)-i,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=n+s.collapsedBefore,dt(s),t+=s.collapsedBefore+s.splitLineCount,n+=s.collapsedBefore+s.unifiedLineCount,i=J(s.additionStart,s.additionCount);if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-J(s.additionStart,s.additionCount),0);t+=r,n+=r}e.splitLineCount=t,e.unifiedLineCount=n}const Rt=new WeakMap;function Pi(e){return e.length>1&&e[e.length-1]===""?e.slice(0,-1):e}function Ni(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 tt(e,t){const n=e.hunks,i=e.additionLines,s=Pi(i),r=s===i?e:{...e,additionLines:s},o=$i(n,_i(r,t),e.deletionLines.length),l=qi(r,o);if(e.additionLines=s,e.hunks=l,e.editSessionDirty=!0,Zi(e),Xt(e,i),!!Yi(n,e.hunks))return{regions:o.map(a=>a.previousSpan)}}function zi(e,t,n,i){const s=Array.from(new Set(t)).filter(a=>a>=0&&a<e.additionLines.length).sort((a,d)=>a-d);if(s.length===0)return;const{hunks:r}=e;let o,l=0;for(const a of s){for(;l<r.length;){const u=r[l];if(a<Be(u)+u.additionCount)break;l++}const d=r[l],h=d==null?void 0:Be(d);if(h==null||a<h||o!=null&&o!==l)return tt(e,n);o=l}if(o!=null){if(Oi(e,s,o,i,n)){e.editSessionDirty=!0;return}return tt(e,n)}}function Oi(e,t,n,i,s){if(i==null||s?.ignoreWhitespace===!0||s?.stripTrailingCr===!0)return!1;const r=Ui(e),o=e.hunks[n];if(o.hunkContent.some(Bi))return!1;for(const l of t){const a=i.get(l),d=e.additionLines[l];if(a==null||d==null||r.has(a)||r.has(d))return!1;let h=!1;for(const u of o.hunkContent)if(u.type==="change"&&u.additions===u.deletions&&l>=u.additionLineIndex&&l<u.additionLineIndex+u.additions){h=!0;break}if(!h)return!1}return!0}function Ui(e){const t=Rt.get(e);if(t?.lines===e.deletionLines)return t.set;const n=new Set(e.deletionLines);return Rt.set(e,{lines:e.deletionLines,set:n}),n}function Bi(e){return e?.type==="change"&&(e.additions===0||e.deletions===0)}function Vi(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],l=s===0?e.get(0):r==null?void 0:e.get(r.lastIndex+1),a=o==null?void 0:e.get(o.firstIndex),d=l?.fromStart??0,h=a?.fromEnd??0;(d>0||h>0)&&n.set(s,{fromStart:d,fromEnd:h})}return n}function Wi(e,t,n){const i=[];if(e.isPartial)return i;for(const[r,o]of e.hunks.entries()){const l=Ee({isPartial:e.isPartial,rangeSize:o.collapsedBefore,expandedHunks:t,hunkIndex:r,collapsedContextThreshold:n});if(l.rangeSize<=n)continue;const a=he(o),d=a-l.rangeSize;l.fromStart>0&&i.push([d,d+l.fromStart]),l.fromEnd>0&&i.push([a-l.fromEnd,a])}const s=He({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=he(r)+r.deletionCount;i.push([o,o+s.fromStart])}return i}function Gi(e,t){const n=new Map;if(t.length===0)return n;const i=(r,o,l)=>{if(l<=o)return;let a=0,d=0;for(const[h,u]of t)u<=o||h>=l||(h<=o&&(a=Math.max(a,Math.min(u,l)-o)),u>=l&&(d=Math.max(d,l-Math.max(h,o))));(a>0||d>0)&&n.set(r,{fromStart:a,fromEnd:d})};for(const[r,o]of e.hunks.entries()){const l=he(o);i(r,l-Math.max(o.collapsedBefore,0),l)}const s=e.hunks[e.hunks.length-1];return s!=null&&!e.isPartial&&e.deletionLines.length>0&&i(e.hunks.length,he(s)+s.deletionCount,e.deletionLines.length),n}function At(e,t){return e.editSessionDirty!==!0?!1:(e.editSessionDirty=void 0,Object.assign(e,e.additionLines.length<=1&&e.additionLines.join("")===""?Y(e,t):qt(e,t)),!0)}function _i(e,t){if(Ni(e.deletionLines,e.additionLines)==null)return[];const n=de({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 l=o.additionCount>0?o.additionLineIndex-s:o.deletionLineIndex-r;s+=l,r+=l;for(const a of o.hunkContent){if(a.type==="context"){s+=a.lines,r+=a.lines;continue}const d=Jt(a,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 $i(e,t,n){const i=e.map((o,l)=>{const a=he(o);return{deletionStart:a,deletionEnd:a+o.deletionCount,blocks:[],previousSpan:{firstIndex:l,lastIndex:l}}}),s=[];let r=0;for(const o of t){const l=o.deletionLineIndex,a=l+o.deletions;for(;r<i.length&&i[r].deletionEnd<l;)s.push(i[r]),r++;let d=s.length>0&&ji(l,a,s[s.length-1])?s.pop():void 0;for(;r<i.length&&i[r].deletionStart<=a;)d=Ki(d,i[r]),r++;if(d==null){let h=l,u=a;if((o.deletions===0||o.additions===0)&&n>o.deletions){const c=s[s.length-1]?.deletionEnd??0,f=i[r]?.deletionStart??n;l>c?h--:a<f&&u++}d={deletionStart:h,deletionEnd:u,blocks:[],previousSpan:void 0}}d.deletionStart=Math.min(d.deletionStart,l),d.deletionEnd=Math.max(d.deletionEnd,a),d.blocks.push(o),s.push(d)}for(;r<i.length;)s.push(i[r]),r++;return s}function ji(e,t,n){return e<=n.deletionEnd&&t>=n.deletionStart}function Ki(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 qi(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 l=s,a=[];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");Tt(a,u,s,i),i+=u,s+=c,a.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");Tt(a,d,s,i),i+=d,s+=d,n.push(Xi(e,{additionStart:l,additionEnd:s,deletionStart:r.deletionStart,deletionEnd:r.deletionEnd},a))}if(e.deletionLines.length-i!==e.additionLines.length-s)throw new Error("buildRegionHunks: trailing context mismatch");return n}function Xi(e,t,n){const i=t.additionEnd-t.additionStart,s=t.deletionEnd-t.deletionStart;let r=0,o=0;for(const a of n)a.type==="change"&&(r+=a.additions,o+=a.deletions);const l={collapsedBefore:0,additionStart:be(t.additionStart,i),additionCount:i,additionLines:r,additionLineIndex:Dt(t.additionStart,i),deletionStart:be(t.deletionStart,s),deletionCount:s,deletionLines:o,deletionLineIndex:Dt(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 dt(l),l}function Tt(e,t,n,i){t>0&&e.push({type:"context",lines:t,additionLineIndex:n,deletionLineIndex:i})}function Yi(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(he(i)!==he(s)||i.deletionCount!==s.deletionCount||Be(i)!==Be(s)||i.additionCount!==s.additionCount||i.splitLineCount!==s.splitLineCount||!Ji(i,s))return!0}return!1}function Ji(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 Be(e){return ye(e.additionStart,e.additionCount)}function he(e){return ye(e.deletionStart,e.deletionCount)}function be(e,t){return t===0?e:e+1}function Dt(e,t){return t===0?e-1:e}function Zi(e){ht(e);for(let t=0;t<e.hunks.length;t++)Yt(e,t)}async function nt(e,t=300){let n;try{await Promise.race([e(),new Promise(i=>{n=setTimeout(i,t)})])}finally{n!=null&&clearTimeout(n)}}function Qi({fileDiff:e,metrics:t,disableFileHeader:n,hunkSeparators:i,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o,canHydratePartialDiff:l}){let a=ge(t,n),d=a;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=Ee({isPartial:e.isPartial,rangeSize:f.collapsedBefore,expandedHunks:h,hunkIndex:c,collapsedContextThreshold:o}),g=(p.fromStart+p.fromEnd)*t.lineHeight;if(a+=g,d+=g,p.collapsedLines>0){const m=ke({type:i,metrics:t,hunkIndex:c,hunkSpecs:f.hunkSpecs})?.totalHeight??0;a+=m,d+=m}a+=f.splitLineCount*t.lineHeight,d+=f.unifiedLineCount*t.lineHeight;const C=es(f);a+=C.split*t.lineHeight,d+=C.unified*t.lineHeight;const S=c===u?He({fileDiff:e,hunkIndex:c,expandedHunks:h,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(S!=null){const m=(S.fromStart+S.fromEnd)*t.lineHeight;if(a+=m,d+=m,S.collapsedLines>0){const k=oe({type:i,metrics:t})?.totalHeight??0;a+=k,d+=k}}else if(c===u&&e.isPartial&&l){const m=oe({type:i,metrics:t})?.totalHeight??0;a+=m,d+=m}}if(e.hunks.length>0){const c=Wt(t);a+=c,d+=c}return{splitHeight:a,unifiedHeight:d}}function es(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 ts(e,t)}function ts(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 it({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 ns(e){return{...e,hunks:e.hunks.map(t=>({...t,hunkContent:t.hunkContent.map(n=>({...n}))})),deletionLines:[...e.deletionLines],additionLines:[...e.additionLines]}}function st(e){return e!==""?e.split(dn):[]}function rt(e,t,n){const i=e==="clone"?ns(t):t;if(!i.isPartial)throw new Error("hydratePartialDiff: fileDiff must be partial");switch(i.type){case"change":case"rename-changed":return is(i,rs(i,n),Mt(i,n));case"rename-pure":{const s=Mt(i,n);os(i,n);const r=st(s.contents);return i.isPartial=!1,i.deletionLines=r,i.additionLines=r,Zt(i,null,s),i}}throw new Error(`hydratePartialDiff: ${i.type} diffs cannot be hydrated from loaded files`)}function is(e,t,n){const i=st(t.contents),s=st(n.contents),{hunks:r,splitLineCount:o,unifiedLineCount:l}=ss(e.hunks,s.length);return e.hunks=r,e.splitLineCount=o,e.unifiedLineCount=l,e.isPartial=!1,e.deletionLines=i,e.additionLines=s,Zt(e,t,n),e}function ss(e,t){let n=0,i=0,s=0;const r=[];for(const o of e){const l=Math.max(o.additionStart-1,0),a=Math.max(o.deletionStart-1,0);let d=l,h=a,u=0,c=0,f=0,p=0;const g=[];for(const S of o.hunkContent){if(S.type==="context"){g.push({...S,additionLineIndex:d,deletionLineIndex:h}),d+=S.lines,h+=S.lines,f+=S.lines,p+=S.lines;continue}g.push({...S,additionLineIndex:d,deletionLineIndex:h}),d+=S.additions,h+=S.deletions,u+=S.additions,c+=S.deletions,f+=Math.max(S.additions,S.deletions),p+=S.additions+S.deletions}const C=Math.max(ye(o.additionStart,o.additionCount)-s,0);r.push({...o,collapsedBefore:C,additionLineIndex:l,deletionLineIndex:a,additionLines:u,deletionLines:c,hunkContent:g,splitLineStart:n+C,unifiedLineStart:i+C,splitLineCount:f,unifiedLineCount:p}),n+=C+f,i+=C+p,s=J(o.additionStart,o.additionCount)}if(r.length>0){const o=r[r.length-1],l=J(o.additionStart,o.additionCount),a=Math.max(t-l,0);n+=a,i+=a}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 Mt(e,t){if(t.newFile==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires newFile`);return t.newFile}function os(e,t){if(t.oldFile!==null)throw new Error(`hydratePartialDiff: ${e.type} diff for ${e.name} requires oldFile to be null`)}function as(e,t,n){return e.cacheKey!=null?`${e.cacheKey}:hydrated`:ls(t,n)}function Zt(e,t,n){const i=as(e,t,n);if(i==null){delete e.cacheKey;return}e.cacheKey=i}function ls(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 ot(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function De(e){return z({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function Me(e){return z({tagName:"div",children:[z({tagName:"span",children:[Ne("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function Xe(e){return z({tagName:"div",children:[hn({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 l=0;const a=[];if(e==="metadata"&&t!=null&&a.push(z({tagName:"div",children:[Ne(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const d=[];n!=null&&(i?(r||(d.push(Xe("up")),l++),o||(d.push(Xe("down")),l++)):(d.push(Xe(!r&&!o?"both":r?"down":"up")),l++)),d.push(z({tagName:"div",children:[z({tagName:"span",children:[Ne(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),i&&n!=null&&d.push(z({tagName:"div",children:[Ne("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),a.push(z({tagName:"div",children:d,properties:{"data-separator-wrapper":"","data-separator-multi-button":l>1?"":void 0}}))}return e==="custom"&&s!=null&&a.push(z({tagName:"slot",properties:{name:s}})),z({tagName:"div",children:a,properties:{"data-separator":a.length===0?"simple":e,"data-expand-index":n,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function hs(e,t){return`hunk-separator-${e}-${t}`}function us(e){const t=e.at(-1);return t==null?0:Math.max(J(t.additionStart,t.additionCount),J(t.deletionStart,t.deletionCount))}let cs=-1;var fs=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++cs}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;editSessionActive=!1;constructor(e={theme:ae},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=Ge(e.theme??ae)?un():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,Oe(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)||Pe(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);fe(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)??cn}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=[],l=new Map;for(const[d,h]of e){const u=r[d]?.properties??{},c=h.map(C=>C[2]).join(""),f=d<s.additionLines.length,p=f?s.additionLines[d]??"":"",g=ve(p);f&&(s.additionLines[d]=fn(p,c),g!==c&&(o.push(d),l.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(([C,S,m])=>C===0&&S===""?m===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:m}:{type:"element",tagName:"span",properties:{"data-char":C,style:`color:${S};`},children:[{type:"text",value:m}]})}}let a=!1;if(o.length>0)if(this.editSessionActive&&!s.isPartial){if(!n)if(s.additionLines.length<=1&&s.additionLines.join("")==="")Object.assign(s,Oe(s,this.options.parseDiffOptions)),this.markEditSessionPass(s),a=!0;else if(et(s,s.additionLines))Object.assign(s,Ue(s,s.additionLines,this.options.parseDiffOptions)),this.markEditSessionPass(s),a=!0;else{const d=zi(s,o,this.options.parseDiffOptions,l);this.applyExpansionRemap(d),a=d!=null}}else Object.assign(s,bi(s,o,this.options.parseDiffOptions));return i.baseThemeType=t,this.renderCache.isDirty=!0,a}applyExpansionRemap(e){e!=null&&(this.expandedHunks=Vi(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=Cs(e,i),n.code.additionLines=ms(i,t.additionLines,n.code.additionLines,e),t.additionLines.length<=1&&t.additionLines.join("")===""?(Object.assign(t,Oe(t,this.options.parseDiffOptions)),n.code.additionLines[0]=at(0,e.getLineText(0)),this.markEditSessionPass(t)):this.editSessionActive?this.applySessionDocumentChange(t):Object.assign(t,qt(t,this.options.parseDiffOptions)),this.renderCache.isDirty=!0}applySessionDocumentChange(e){const{parseDiffOptions:t}=this.options,n=e.additionLines;if(et(e,n)){Object.assign(e,Ue(e,n,t)),this.markEditSessionPass(e);return}this.applyExpansionRemap(tt(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=>pn(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:l=!1,collapsedContextThreshold:a=1,expansionLineCount:d=100,hunkSeparators:h="line-info",lineDiffType:u="word-alt",maxLineDiffLength:c=1e3,overflow:f="scroll",stickyHeader:p=!1,theme:g=ae,headerRenderMode:C="default",tokenizeMaxLineLength:S=1e3,tokenizeMaxLength:m=gn,useTokenTransformer:k=!1,useCSSClasses:v=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:n,disableFileHeader:i,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:l,collapsedContextThreshold:a,expansionLineCount:d,hunkSeparators:h,lineDiffType:u,maxLineDiffLength:c,overflow:f,stickyHeader:p,theme:this.workerManager?.getDiffRenderOptions().theme??g,headerRenderMode:C,tokenizeMaxLineLength:S,tokenizeMaxLength:m,useTokenTransformer:k,useCSSClasses:v}}async initializeHighlighter(){return this.highlighter=await mn(Cn(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=Pe(e,this.getTokenizeMaxLength());let i=this.workerManager?.getDiffResultCache(e);i!=null&&!fe(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??ae}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 l=this.workerManager.getDiffRenderOptions();return this.editSessionActive&&l.useTokenTransformer!==!0?{...l,useTokenTransformer:!0}:l}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)||!fe(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=ut){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 l=e.additionLines.length>0||e.deletionLines.length>0,a=!l||ze(e)||Pe(e,this.getTokenizeMaxLength()),d=!me(e,this.renderCache.diff),h=!Gt(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0){const u=this.renderCache.result==null&&this.renderCache.highlighted&&!a&&!d&&ot(t);u&&(this.renderCache.highlightPending=!0),!u&&(a||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,ot(t)||n?!0:this.expandedHunks,i)),this.renderCache.renderRange=t),!a&&l&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e)}else{this.computedLang=e.lang??_e(e.name);const u=this.highlighter!=null&&Ge(s.theme),c=this.highlighter!=null&&ct(this.computedLang),f=!a&&c;if(this.highlighter!=null&&u&&(r||a||!this.renderCache.highlighted&&f||this.renderCache.result==null)){const{result:p,options:g}=this.renderDiffWithHighlighter(e,this.highlighter,a||!c);this.renderCache={diff:e,options:g,highlighted:f,result:p,renderRange:void 0}}(!u||!a&&!c)&&this.asyncHighlight(e).then(({result:p,options:g})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,p,g,!a)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=ut){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 Sn({type:"diff",diffIndicators:i,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:n})}async asyncHighlight(e){const t=Pe(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??_e(e.name);const n=this.highlighter!=null&&Ge(this.getLocalHighlightTheme()),i=t||this.highlighter!=null&&ct(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=Ln(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(Se({diff:e,diffStyle:"both",expandedHunks:n?!0:void 0,collapsedContextThreshold:s,callback:({additionLine:l})=>{if(l?.lineIndex===0)return o=l,!0}}),o==null)throw new Error("DiffHunksRenderer: missing empty addition line");r.code.additionLines[0]=at(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||!fe(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||!fe(t,n.options)))return n}hasHighlightedRenderCache(e,t){const{renderCache:n}=this;return n?.result!=null&&n.highlighted&&me(e,n.diff)&&fe(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:l,expansionLineCount:a,collapsedContextThreshold:d,hunkSeparators:h}=this.getOptionsWithDefaults(),u=this.renderCache?.isDirty??!1;this.diff=e;const c=r==="unified",f=ys(e,this.options.loadDiffFiles!=null),p=!e.isPartial||f;let g=[],C=[],S=[];const m=[],{additionLines:k,deletionLines:v}=n,L={rowCount:0,hunkSeparators:h,additionsContentAST:g,deletionsContentAST:C,unifiedContentAST:S,unifiedGutterAST:Ae(),deletionsGutterAST:Ae(),additionsGutterAST:Ae(),expansionLineCount:a,hunkData:m,incrementRowCount(A=1){L.rowCount+=A},pushToGutter(A,T){switch(A){case"unified":L.unifiedGutterAST.children.push(T);break;case"deletions":L.deletionsGutterAST.children.push(T);break;case"additions":L.additionsGutterAST.children.push(T);break}}},y=yn({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"?(L.pushToGutter("additions",$(void 0,"buffer",this.size)),g?.push(De(this.size))):(L.pushToGutter("deletions",$(void 0,"buffer",this.size)),C?.push(De(this.size))),this.size=0,this.side=void 0}}},N=(A,T,Z,ue,R)=>{L.pushToGutter(A,vn(T,Z,ue,R))};function x(A){H.flush(),r==="unified"?Ye("unified",A,L):(Ye("deletions",A,L),Ye("additions",A,L))}this.pushFileLevelAnnotations(e,r,t,L),Se({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:l?!0:this.expandedHunks,collapsedContextThreshold:d,callback:({hunkIndex:A,hunk:T,collapsedBefore:Z,collapsedAfter:ue,additionLine:R,deletionLine:b,type:F})=>{const B=b!=null?b.splitLineIndex:R.splitLineIndex,Q=R!=null?R.unifiedLineIndex:b.unifiedLineIndex;r==="split"&&F!=="change"&&H.flush(),Z>0&&x({hunkIndex:A,collapsedLines:Z,rangeSize:Math.max(T?.collapsedBefore??0,0),hunkSpecs:T?.hunkSpecs,isFirstHunk:A===0,isLastHunk:!1,isExpandable:p});const ce=r==="unified"?Q:B,we={type:F,hunkIndex:A,lineIndex:ce,unifiedLineIndex:Q,splitLineIndex:B,deletionLine:b,additionLine:R};if(r==="unified"){const I=this.getUnifiedInjectedRowsForLine?.(we);I?.before!=null&&Ft(I.before,L);let O=b!=null?v[b.lineIndex]:void 0,V=R!=null?k[R.lineIndex]:void 0;if(O==null&&V==null){const G="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(G,{file:e.name}),new Error(G)}const re=F==="change"?R!=null?"change-addition":"change-deletion":F,W=this.getUnifiedLineDecoration({type:F,lineType:re,additionLineIndex:R?.lineIndex,deletionLineIndex:b?.lineIndex});N("unified",W.gutterLineType,R!=null?R.lineNumber:b.lineNumber,`${Q},${B}`,W.gutterProperties),V!=null?V=Fe(V,W.contentProperties,u&&R!=null?{"data-line":R.lineNumber,"data-line-index":`${Q},${B}`}:void 0):O!=null&&(O=Fe(O,W.contentProperties,u&&b!=null?{"data-line":b.lineNumber,"data-line-index":`${Q},${B}`}:void 0)),Ie({diffStyle:"unified",type:F,deletionLine:O,additionLine:V,unifiedSpan:this.getAnnotations("unified",b?.lineNumber,R?.lineNumber,A,ce),createAnnotationElement:G=>this.createAnnotationElement(G),context:L}),I?.after!=null&&Ft(I.after,L)}else{const I=this.getSplitInjectedRowsForLine?.(we);I?.before!=null&&Pt(I.before,L,H);let O=b!=null?v[b.lineIndex]:void 0,V=R!=null?k[R.lineIndex]:void 0;const re=this.getSplitLineDecoration({side:"deletions",type:F,lineIndex:b?.lineIndex}),W=this.getSplitLineDecoration({side:"additions",type:F,lineIndex:R?.lineIndex});if(O==null&&V==null){const U="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(U,{file:e.name}),new Error(U)}const G=(()=>{if(F==="change"){if(V==null)return"additions";if(O==null)return"deletions"}})();G!=null?(H.side!=null&&H.side!==G&&H.flush(),H.side=G,H.increment()):F==="change"&&H.flush();const ee=this.getAnnotations("split",b?.lineNumber,R?.lineNumber,A,ce);if(ee!=null&&H.size>0&&H.flush(),b!=null){const U=Fe(O,re.contentProperties,u?{"data-line":b.lineNumber,"data-line-index":`${b.unifiedLineIndex},${B}`}:void 0);N("deletions",re.gutterLineType,b.lineNumber,`${b.unifiedLineIndex},${B}`,re.gutterProperties),U!=null&&(O=U)}if(R!=null){const U=Fe(V,W.contentProperties,u?{"data-line":R.lineNumber,"data-line-index":`${R.unifiedLineIndex},${B}`}:void 0);N("additions",W.gutterLineType,R.lineNumber,`${R.unifiedLineIndex},${B}`,W.gutterProperties),U!=null&&(V=U)}Ie({diffStyle:"split",type:F,additionLine:V,deletionLine:O,...ee,createAnnotationElement:U=>this.createAnnotationElement(U),context:L}),I?.after!=null&&Pt(I.after,L,H)}const xe=r==="split"&&T!=null&&B===T.splitLineStart+T.splitLineCount-1,K=A===e.hunks.length-1&&T!=null&&(r==="split"?B===T.splitLineStart+T.splitLineCount-1:Q===T.unifiedLineStart+T.unifiedLineCount-1),Ve=xe?T.noEOFCRDeletions:!1,We=xe?T.noEOFCRAdditions:!1,se=(b?.noEOFCR??!1)||Ve,q=(R?.noEOFCR??!1)||We;if(q||se){if(r==="split"&&H.flush(),se){const I=F==="context"||F==="context-expanded"?F:"change-deletion";r==="unified"?(L.unifiedContentAST.push(Me(I)),L.pushToGutter("unified",$(I,"metadata",1))):(L.deletionsContentAST.push(Me(I)),L.pushToGutter("deletions",$(I,"metadata",1)),q||(L.pushToGutter("additions",$(void 0,"buffer",1)),L.additionsContentAST.push(De(1))))}if(q){const I=F==="context"||F==="context-expanded"?F:"change-addition";r==="unified"?(L.unifiedContentAST.push(Me(I)),L.pushToGutter("unified",$(I,"metadata",1))):(L.additionsContentAST.push(Me(I)),L.pushToGutter("additions",$(I,"metadata",1)),se||(L.pushToGutter("deletions",$(void 0,"buffer",1)),L.deletionsContentAST.push(De(1))))}L.incrementRowCount(1)}h!=="simple"&&h!=="metadata"&&(ue>0||K&&f)&&x({hunkIndex:F==="context-expanded"?A:A+1,collapsedLines:K&&f?"unknown":ue,rangeSize:y,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:p}),L.incrementRowCount(1)}}),r==="split"&&H.flush();const w=Math.max(us(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),M=t.bufferBefore>0||t.bufferAfter>0,D=!c&&e.type!=="deleted",E=!c&&e.type!=="new",j=L.rowCount>0||M;g=D&&j?g:void 0,C=E&&j?C:void 0,S=c&&j?S:void 0;const ie=this.createPreElement(C!=null&&g!=null,w);return{unifiedGutterAST:c&&j?L.unifiedGutterAST.children:void 0,unifiedContentAST:S,deletionsGutterAST:E&&j?L.deletionsGutterAST.children:void 0,deletionsContentAST:C,additionsGutterAST:D&&j?L.additionsGutterAST.children:void 0,additionsContentAST:g,hunkData:m,preNode:ie,themeStyles:i,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:w,rowCount:L.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=Ae(n);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,xn(i,t.rowCount)]}renderFullAST(e,t=[]){const n=this.getOptionsWithDefaults().hunkSeparators==="line-info",i=this.renderCodeAST("unified",e);if(i!=null)return t.push(z({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(z({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(z({tagName:"code",children:r,properties:{"data-code":"","data-container-size":n?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(z({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(!_t(n))return;const s=e.type!=="new"?It(ft(this.deletionAnnotations)):[],r=e.type!=="deleted"?It(ft(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,l=-1,{createAnnotationElement:a}=this;if(t==="unified"){Ie({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:s.concat(r)},createAnnotationElement:a,context:i});return}Ie({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:l,annotations:r},createAnnotationElement:a,context:i})}getAnnotations(e,t,n,i,s){const r={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(t!=null)for(const l of this.deletionAnnotations[t]??[])r.annotations.push(Le(l));const o={type:"annotation",hunkIndex:i,lineIndex:s,annotations:[]};if(n!=null)for(const l of this.additionAnnotations[n]??[])(e==="unified"?r:o).annotations.push(Le(l));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 kn({fileOrDiff:e,mode:t,stickyHeader:n})}};function It(e){return e?.map(t=>Le(t))??[]}const ps=new Intl.PluralRules("en-US");function gs(e){return`${e} unmodified line${ps.select(e)==="one"?"":"s"}`}function Ft(e,t){for(const n of e)t.unifiedContentAST.push(n.content),t.pushToGutter("unified",n.gutter),t.incrementRowCount(1)}function Pt(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 Ie({diffStyle:e,type:t,deletionLine:n,additionLine:i,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:l,context:a}){let d=!1;if(e==="unified"){if(i!=null?a.unifiedContentAST.push(i):n!=null&&a.unifiedContentAST.push(n),s!=null){const h=t==="change"?n!=null?"change-deletion":"change-addition":t;a.unifiedContentAST.push(l(s)),a.pushToGutter("unified",$(h,"annotation",1)),d=!0}}else if(e==="split"){if(n!=null&&a.deletionsContentAST.push(n),i!=null&&a.additionsContentAST.push(i),r!=null){const h=t==="change"?n!=null?"change-deletion":"context":t;a.deletionsContentAST.push(l(r)),a.pushToGutter("deletions",$(h,"annotation",1)),d=!0}if(o!=null){const h=t==="change"?i!=null?"change-addition":"context":t;a.additionsContentAST.push(l(o)),a.pushToGutter("additions",$(h,"annotation",1)),d=!0}}d&&a.incrementRowCount(1)}function Ye(e,{hunkIndex:t,collapsedLines:n,rangeSize:i,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:l},a){if(typeof n=="number"&&n<=0)return;const d=e==="unified"?a.unifiedContentAST:e==="deletions"?a.deletionsContentAST:a.additionsContentAST;if(a.hunkSeparators==="metadata"){s!=null&&(a.pushToGutter(e,pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&a.incrementRowCount(1));return}if(a.hunkSeparators==="simple"){t>0&&(a.pushToGutter(e,pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),d.push(pe({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&a.incrementRowCount(1));return}const h=hs(e,t),u=i>a.expansionLineCount,c=l?t:void 0,f=typeof n=="number"?gs(n):"More unchanged context may be available";a.pushToGutter(e,pe({type:a.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),d.push(pe({type:a.hunkSeparators,content:f,expandIndex:c,chunked:u,slotName:h,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&a.incrementRowCount(1),a.hunkData.push({slotName:h,hunkIndex:t,lines:typeof n=="number"?n:0,lineCountKnown:typeof n=="number",type:e,expandable:l?{up:!r,down:!o,chunked:u}:void 0})}function Fe(e,t,n){return e==null||e.type!=="element"||t==null&&n==null?e:{...e,properties:{...e.properties,...t,...n}}}function Nt(e){return e.length>0&&e[e.length-1]===""?e.length-1:e.length}function ms(e,t,n,i){const s=Nt(e),r=Nt(t),o=Math.min(s,r);let l=0;for(;l<o&&e[l]===t[l];)l++;let a=0;for(;a<o-l&&e[s-1-a]===t[r-1-a];)a++;const d=new Array(t.length);for(let h=0;h<l;h++)d[h]=n[h];for(let h=0;h<a;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=l;h<t.length;h++)d[h]??=at(h,i.getLineText(h));return d}function at(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 Cs(e,t){const n=[],i=Ls(t);for(let s=0;s<e.lineCount;s++){const r=e.getLineText(s,!0);n.push(s<e.lineCount-1&&!Ss(r)?r+i:r)}return n}function Ss(e){return e.endsWith(`
|
|
26
26
|
`)||e.endsWith("\r")}function Ls(e){for(const t of e){if(t.endsWith(`\r
|
|
27
27
|
`))return`\r
|
|
28
28
|
`;if(t.endsWith(`
|
|
29
29
|
`))return`
|
|
30
30
|
`;if(t.endsWith("\r"))return"\r"}return`
|
|
31
|
-
`}function Pe(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function ys(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function xs(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ks(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 vs(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:bn(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 Es(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}let Hs=-1;var ws=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Hs}`;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:ae},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Dn,this.scrollSyncManager=new ds,this.interactionManager=new Mn("diff",gt(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 vs(e)}createHunksRenderer(e){return new fs(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 l=t==="deletions"?o.deletionStart:o.additionStart,a=t==="deletions"?o.deletionCount:o.additionCount;let d=ye(l,a)+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+a){if(o===i){const c=e-(d+a);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(gt(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&&!mn(this.appliedThemeCSS.theme,this.options.theme??ae)}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){In(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=it(r,"FileDiff.hydrate"),l=o?.oldFile,a=o?.newFile;this.hydrateElements(e,t),Ts(this.pre,Rs({fileDiff:s,oldFile:l,newFile:a}),this.options.collapsed)||bs(this.headerElement,As({fileDiff:s,oldFile:l,newFile:a}),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),Fn(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?de(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||!Es(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||(rt("merge",e,t),this.setHydratedState(t),await nt(()=>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:l,...a}){const d=it(a,"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:l,C=this.hasThemeChanged(),S=d!=null,m=S&&(!zt(h,this.deletionFile)||!zt(u,this.additionFile));let k=e!=null&&e!==this.fileDiff;const v=s!=null&&(s.length>0||this.lineAnnotations.length>0)?s!==this.lineAnnotations:!1;if(!c&&$t(g,this.renderRange)&&!n&&!v&&!C&&(e!=null&&e===this.fileDiff||e==null&&!m))return this.applyCachedThemeState(f);let L;e==null&&S&&(m||this.fileDiff==null)&&(L=de(d.oldFile,d.newFile,this.options.parseDiffOptions));const{renderRange:y}=this;if(this.renderRange=g,S?(this.deletionFile=h,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null?this.fileDiff=e:L!=null&&(k=!0,this.fileDiff=L),k&&(this.cachedHeaderHTML=void 0),s!=null&&this.setLineAnnotations(s),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(At(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:N=!1}=this.options;if(N&&(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 x=this.hunksRenderer.renderDiff(this.fileDiff,Cn);x!=null&&this.applyThemeState(r,x.themeStyles,f,x.baseThemeType),x?.headerElement!=null&&this.applyHeaderToDOM(x.headerElement,r),this.renderSeparators([]),this.injectUnsafeCSS()}catch(x){if(H)throw x;console.error(x),x instanceof Error&&this.applyErrorToDOM(x,r)}return i||this.emitPostRender(),!0}try{const x=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(n,v,m||k||C)&&this.applyPartialRender({previousRenderRange:y,renderRange:g}))){const w=this.hunksRenderer.renderDiff(this.fileDiff,g);if(w==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(r,w.themeStyles,f,w.baseThemeType),w.headerElement!=null&&this.applyHeaderToDOM(w.headerElement,r),w.additionsContentAST!=null||w.deletionsContentAST!=null||w.unifiedContentAST!=null?this.applyHunksToDOM(x,w):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(w.hunkData)}this.applyBuffers(x,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(x){if(H)throw x;console.error(x),x instanceof Error&&this.applyErrorToDOM(x,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||ot(e))return e;const{diffStyle:n="split",expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return Se({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:l})=>{l!=null&&(r??=l.lineNumber,o=l.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=Wi(e,this.hunksRenderer.getExpandedHunksMap(),t);return At(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(_i(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 _t({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 Sn({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=Ee({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,C=u-f.fromEnd-e;return g<=C?this.expandHunk(d,"up",g+s):this.expandHunk(d,"down",C+s),!0}if(e<c)return!1}const o=He({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:i,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const l=t.hunks[t.hunks.length-1],[,a]=ct(l);return e<a+o.fromStart||e>=a+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(a+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){Pn(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||!ks(i,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=i.slotName;const l=t(i,this);l!=null&&o.appendChild(l),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}-${Le(i)}`;let r=this.annotationCache.get(s);if(r==null||!xs(i,r.annotation)){r?.element.remove();const o=t(i);if(o==null)continue;r={element:Nn(Le(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=zn();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:mt(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):mt(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=On;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??le(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:l}=this.options;if(s!=null){const u=s(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Vt,u),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const a=r?.(n)??void 0,d=o?.(n)??void 0,h=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Ln,a),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,yn,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,xn,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??=Un(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Bn(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,i){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=i??n,o=this.options.theme??ae,l=typeof o=="string"?o:{...o},a=Ct(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===a){this.appliedThemeCSS.theme=l;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:l,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:a};return}this.themeCSSStyle=Vn({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:jn(t,r,a)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:l,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:a}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Wn(this.themeCSSStyle.textContent??"",Ct(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&_n()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?St(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=ne(t[0]),r=ne(t[1]);return s==null||r==null?!1:(i.gutter.innerHTML=le(s),i.content.innerHTML=le(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=[],l=this.hunksRenderer.renderCodeAST("unified",t),a=this.hunksRenderer.renderCodeAST("deletions",t),d=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),l!=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=je({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeUnified,l,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeUnified)):a!=null||d!=null?(a!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=je({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeDeletions,a,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(a)),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=je({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 l=this.getCodeColumns(o,i,r,s);if(l==null)return!1;const a=e.startingLine,d=t.startingLine,h=a+e.totalLines,u=d+t.totalLines,c=Math.max(a,d),f=Math.min(h,u);if(f<=c)return!1;const p=Math.max(0,c-a),g=Math.max(0,h-f),C=this.trimColumns({columns:l,trimStart:p,trimEnd:g,previousStart:a,overlapStart:c,overlapEnd:f,diffStyle:o});if(C<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let S=this.lastRowCount-C;const m=(y,H)=>{if(!(H<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:y,totalLines:H,bufferBefore:0,bufferAfter:0})},k=m(d,Math.max(c-d,0));if(k==null&&d<c)return!1;const v=m(f,Math.max(u-f,0));if(v==null&&u>f)return!1;const L=(y,H)=>{if(y!=null){if(o==="unified"&&!Array.isArray(l))this.insertPartialHTML(o,l,y,H);else if(o==="split"&&Array.isArray(l))this.insertPartialHTML(o,l,y,H);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");S+=y.rowCount}};return this.cleanupErrorWrapper(),L(k,"afterbegin"),L(v,"beforeend"),this.lastRowCount!==S&&(this.applyRowSpan(o,l,S),this.lastRowCount=S),!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=ne(r?.[0]),l=ne(r?.[1]);for(const[a,d]of[[s.gutter,o],[s.content,l]])if(d!=null&&a.childElementCount===d.length)for(let h=0;h<d.length;h++){const u=a.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=ne(n?.[0]),s=ne(n?.[1]),r=()=>{for(const[o,l]of[[t.gutter,i],[t.content,s]])l!=null&&(o.innerHTML=le(l));e.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?St(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=ne(t[0]),s=ne(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 l=n>=0;if(e==null)return 0;const a=Array.from(e.content.children),d=Array.from(e.gutter.children);if(a.length!==d.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<a.length&&!(t<=0&&!l&&!o);){const h=d[r],u=a[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||l&&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||l&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||l&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||l&&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(l){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,C=c-g;this.updateBufferSize(h,C),this.updateBufferSize(u,C),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 l=Math.max(0,i-s),a=n-s;if(a<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?l:0,c=h?a:-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:l=!1,overflow:a="scroll",diffStyle:d="split"}=this.options,h={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:l,overflow:a,split:d==="unified"?!1:t!=null&&n!=null,totalLines:i,customProperties:s};Gn(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 zt(e,t){return e==null||t==null?e==null&&t==null:Gt(e,t)}function Rs({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function As({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Ts(e,t,n=!1){return!n&&e==null&&t}function bs(e,t,n=!1){return e==null&&t&&!n}function ne(e){if(!(e==null||e.type!=="element"))return e.children??[]}const lt=3e3;let Ds=-1;var $s=class extends ws{__id=`little-virtualized-file-diff:${++Ds}`;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=Ge(n)}setMetrics(e,t=!1){const n=Ge(e);!t&&Kn(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||!qn(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=!Xn(t,e),i=n&&zs(t,e);super.setOptions(e),i&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Os(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=Ms(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 l of o.children){if(!(l instanceof HTMLElement))continue;const a=l.dataset.lineIndex;if(a==null)continue;const d=Bs(a,n);let h=l.getBoundingClientRect().height,u=!1;l.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in l.nextElementSibling.dataset||"noNewline"in l.nextElementSibling.dataset)&&("noNewline"in l.nextElementSibling.dataset&&(u=!0),h+=l.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,l=s||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=Ge(n.metrics),o=!0,l=!0);const{collapsed:a=!1,expandUnchanged:d=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,o=!0),this.currentExpandUnchanged!==d&&(this.currentExpandUnchanged=d,o=!0,l=!0),o&&this.resetLayoutCache({includeEstimatedHeights:l}),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,l=this.getDiffStyle(),a=this.getHunkSeparatorType(),d=l==="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 Se({diff:this.fileDiff,diffStyle:l,startingLine:u?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:p,hunk:g,collapsedBefore:C,collapsedAfter:S,deletionLine:m,additionLine:k})=>{const v=l==="split"?k?.splitLineIndex??m?.splitLineIndex:k?.unifiedLineIndex??m?.unifiedLineIndex;if(v==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const y=ke({type:a,metrics:this.metrics,hunkIndex:p,hunkSpecs:g?.hunkSpecs});if(y!=null){if(c+=y.gapBefore,d>=v-C&&d<v)return f={top:c,height:y.height},!0;c+=y.height+y.gapAfter}}const L=this.getLineHeight(v,(k?.noEOFCR??!1)||(m?.noEOFCR??!1));if(v===d)return f={top:c,height:L},!0;if(c+=L,S>0){const y=oe({type:a,metrics:this.metrics});if(y!=null){if(d>v&&d<=v+S)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 l=this.getLayoutCheckpointBeforeTop(e);let a=l?.top??ge(this.metrics,t)+this.cache.fileAnnotationHeight,d;return Se({diff:this.fileDiff,diffStyle:r,startingLine:l?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:h,hunk:u,collapsedBefore:c,collapsedAfter:f,deletionLine:p,additionLine:g})=>{const C=r==="split"?g?.splitLineIndex??p?.splitLineIndex:g?.unifiedLineIndex??p?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(c>0){const m=ke({type:o,metrics:this.metrics,hunkIndex:h,hunkSpecs:u?.hunkSpecs});m!=null&&(a+=m.totalHeight)}if(a>=e&&(p!=null?d={lineNumber:p.lineNumber,side:"deletions",top:a}:g!=null&&(d={lineNumber:g.lineNumber,side:"additions",top:a}),d!=null))return!0;const S=this.getLineHeight(C,(g?.noEOFCR??!1)||(p?.noEOFCR??!1));if(a+=S,f>0){const m=oe({type:o,metrics:this.metrics});m!=null&&(a+=m.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=rt("clone",e,t);if(await nt(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(rt("merge",e,t),this.setHydratedState(t),await nt(()=>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 l={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},a=o.expansionLineCountOverride??i;(o.direction==="up"||o.direction==="both")&&(l.fromStart+=a),(o.direction==="down"||o.direction==="both")&&(l.fromEnd+=a),r.set(o.hunkIndex,l)}return _t({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}=Qi({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,canHydratePartialDiff:Je(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=it(s,"VirtualizedFileDiff.render"),o=r!=null,l=r?.oldFile,a=r?.newFile,d=o&&(!Bt(l,this.deletionFile)||!Bt(a,this.additionFile));let h=t??this.fileDiff;t==null&&o&&(d||this.fileDiff==null)&&(h=de(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),C=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 L=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(L==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");L.connect(e,this),this.isVisible=L.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!C||!c))return this.fileDiff=h,r!=null&&(this.deletionFile=l,this.additionFile=a),g&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const S=this.virtualizer.getWindowSpecs(),m=this.top??0,k=this.computeRenderRangeFromWindow(h,m,S),v=super.render({fileDiff:h,fileContainer:e,renderRange:k,lineAnnotations:i,forceRender:(u??n)||f||g,...r,...s});return this.isSimpleMode()&&v&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),v}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 Us(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=Je(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),l=this.getHunkSeparatorType(),a=n?!0:this.hunksRenderer.getExpandedHunksMap(),d=Is(this.cache.heightDeltas);let h=ge(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:C=0,metadataOffsets:S=[]})=>{if(f<=0)return;const m=u,k=u+f;let v=Fs(m);for(;v<k;){const L=v-m,y=h+(L>0?g:0)+L*this.metrics.lineHeight+Ps(S,L)*this.metrics.lineHeight+Ot(d,p,p+L);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:p+L,top:y}),v+=lt}h+=g+f*this.metrics.lineHeight+S.length*this.metrics.lineHeight+Ot(d,p,p+f)+C,u=k};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=Ee({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:a,hunkIndex:f,collapsedContextThreshold:i}),C=g.collapsedLines>0?ke({type:l,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 S=C;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:S}),g.fromEnd>0&&(S=0);const m=f===s?He({fileDiff:e,hunkIndex:f,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,k=m!=null&&m.collapsedLines>0?oe({type:l,metrics:this.metrics})?.totalHeight??0:f===s&&r?oe({type:l,metrics:this.metrics})?.totalHeight??0:0,v=m!=null?m.fromStart+m.fromEnd:0,L=o==="split"?p.splitLineCount:p.unifiedLineCount,y=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:L,startLineIndex:y,preSeparatorHeight:S,postSeparatorHeight:v===0?k:0,metadataOffsets:Ns({diffStyle:o,hunk:p,rowCount:L})}),m!=null&&v>0&&c({rowCount:v,startLineIndex:y+L,postSeparatorHeight:k})}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 l of e.hunks)n+=t==="split"?l.splitLineCount:l.unifiedLineCount;return n}const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options,r=i?!0:this.hunksRenderer.getExpandedHunksMap();for(const[l,a]of e.hunks.entries()){const d=t==="split"?a.splitLineCount:a.unifiedLineCount;n+=d;const h=Math.max(a.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=Ee({isPartial:e.isPartial,rangeSize:h,expandedHunks:r,hunkIndex:l,collapsedContextThreshold:s});h>0&&(n+=f?h:u+c)}const o=He({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:l,lineHeight:a}=this.metrics,d=this.getDiffStyle(),h=this.getHunkSeparatorType(),u=Je(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?Wt(this.metrics):0,{fileAnnotationHeight:C}=this.cache,S=p+C,m=Math.max(0,c-p-C-g),k=this.hasFileAnnotations(e),v=t+p,L=C>0&&k&&v<i&&v+C>n;if(t<n-c||t>i)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=l||e.hunks.length===0)return{startingLine:0,totalLines:l,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,d);const y=Math.ceil(Math.max(i-n,0)/a),H=Math.ceil(y/l)*l+l,N=H/l,x=N,w=[],M=(n+i)/2,D=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-H*a*2),l);let E=t+(D?.top??S),j=D?.renderedLineIndex??0,ie,A,T;if(Se({diff:e,diffStyle:d,startingLine:D?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:xe,hunk:K,collapsedBefore:Ve,collapsedAfter:We,deletionLine:se,additionLine:q})=>{const I=q!=null?q.splitLineIndex:se.splitLineIndex,O=q!=null?q.unifiedLineIndex:se.unifiedLineIndex,V=(q?.noEOFCR??!1)||(se?.noEOFCR??!1),re=xe===e.hunks.length-1&&K!=null&&(d==="split"?I===K.splitLineStart+K.splitLineCount-1:O===K.unifiedLineStart+K.unifiedLineCount-1),W=(Ve>0?ke({type:h,metrics:this.metrics,hunkIndex:xe,hunkSpecs:K?.hunkSpecs}):void 0)?.totalHeight??0;E+=W;const _=j%l===0,ee=Math.floor(j/l);if(_&&(w[ee]=E-(t+S+W),T!=null)){if(T<=0)return!0;T--}const U=this.getLineHeight(d==="split"?I:O,V);if(E>n-U&&E<i&&(ie??=ee),A==null&&E+U>M&&(A=ee),T==null&&E>=i&&_&&(T=x),j++,E+=U,We>0||re&&u){const Re=oe({type:h,metrics:this.metrics});Re!=null&&(E<i&&E+Re.totalHeight>n&&(ie??=ee),A==null&&E+Re.totalHeight>M&&(A=ee),E+=Re.totalHeight)}return!1}}),ie==null)if(L)ie=0,A=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};A??=ie;const Z=Math.round(A-N/2),ue=Math.max(0,Math.ceil(f/l)-N),R=Math.max(0,Math.min(Z,ue)),b=R*l,F=Z<0?H+Z*l:H,B=w[R]??0,Q=b===0?0:C+B,ce=R+F/l,we=ce<w.length?m-w[ce]:m-(E-t-S);return{startingLine:b,totalLines:F,bufferBefore:Q,bufferAfter:Math.max(0,we)}}};function Ms(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 Is(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 Ot({lineIndexes:e,prefixTotals:t},n,i){if(n>=i||e.length===0)return 0;const s=Ut(e,n);return(t[Ut(e,i)]??0)-(t[s]??0)}function Ut(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 Fs(e){return Math.ceil(e/lt)*lt}function Ps(e,t){let n=0;for(const i of e)i<t&&n++;return n}function Ns({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=[],l=n-r;return i.deletions>0&&t.noEOFCRDeletions&&o.push(l+i.deletions-1),i.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function zs(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 Os(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 Je(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Us(e){return typeof e=="function"?"custom":e??"line-info"}function Bt(e,t){return e==null||t==null?e==null&&t==null:Gt(e,t)}function Bs(e,t){const[n,i]=e.split(",").map(Number);return t==="split"?i:n}function js(e,t){return e.length===t.length&&e.every((n,i)=>n.path===t[i].path&&n.edits===t[i].edits&&n.writeContent===t[i].writeContent&&n.fileChange===t[i].fileChange)}function Ks(e,t){const n=Object.keys(t);return n.length===Object.keys(e).length&&n.every(i=>e[i]===t[i])}function Vs(e,t){let n=e;for(let i=t.length-1;i>=0;i--){const{oldText:s,newText:r}=t[i];if(r===""&&n!=="")return null;const o=n.indexOf(r);if(o===-1)return null;n=n.slice(0,o)+s+n.slice(o+r.length)}return n}function qs(e){const t=new Map;for(const r of e.tools){if(!r.path)continue;const o=t.get(r.path)??[];o.push(r),t.set(r.path,o)}const n=[],i=new Set(Object.entries(e.snapshots).flatMap(([r,o])=>o===null?[r]:[])),s={...e.snapshots};for(const[r,o]of t){const l=e.currentByPath[r],a=o.flatMap(m=>m.edits??[]),d=o.flatMap(m=>m.fileChange&&m.fileChange.truncated!==!0?[m.fileChange]:[]),h=[...o].reverse().find(m=>m.writeContent!=null)?.writeContent,u=o.find(m=>m.fileChange)?.fileChange,c=[...o].reverse().find(m=>m.fileChange||m.writeContent!=null||m.edits?.length),f=c?.fileChange?c.fileChange.truncated===!0?null:c.fileChange.newText:c?.writeContent??null,p=Object.hasOwn(s,r),g=s[r];if(!p&&u?.truncated===!0){s[r]=null,i.add(r);continue}if(p&&g===null){i.add(r);continue}let C=typeof g=="string"?g:d[0]?.oldText??null;const S=typeof l=="string"?l:f;C==null&&(a.length>0&&typeof l=="string"?C=Vs(l,a):h!=null&&a.length===0&&(C="")),S==null&&c?.fileChange?.truncated===!0&&i.add(r),!(C==null||S==null)&&(C===S&&d.length===0||(s[r]=C,n.push({path:r,oldText:C,newText:S})))}return{files:n,snapshots:s,...i.size>0?{incompletePaths:[...i]}:{}}}export{ws as F,$s as V,Vs as a,Ks as b,qs as c,At as f,de as p,Gs as r,js as s};
|
|
31
|
+
`}function Pe(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function ys(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function xs(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ks(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 vs(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:En(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 Es(e){return e.isPartial&&(e.type==="change"||e.type==="rename-changed"||e.type==="rename-pure")}let Hs=-1;var ws=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Hs}`;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:ae},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new Hn,this.scrollSyncManager=new ds,this.interactionManager=new wn("diff",pt(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 vs(e)}createHunksRenderer(e){return new fs(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 l=t==="deletions"?o.deletionStart:o.additionStart,a=t==="deletions"?o.deletionCount:o.additionCount;let d=ye(l,a)+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+a){if(o===i){const c=e-(d+a);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(pt(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&&!Rn(this.appliedThemeCSS.theme,this.options.theme??ae)}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){An(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=it(r,"FileDiff.hydrate"),l=o?.oldFile,a=o?.newFile;this.hydrateElements(e,t),Ts(this.pre,Rs({fileDiff:s,oldFile:l,newFile:a}),this.options.collapsed)||bs(this.headerElement,As({fileDiff:s,oldFile:l,newFile:a}),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),Tn(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?de(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||!Es(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||(rt("merge",e,t),this.setHydratedState(t),await nt(()=>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:l,...a}){const d=it(a,"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:l,C=this.hasThemeChanged(),S=d!=null,m=S&&(!zt(h,this.deletionFile)||!zt(u,this.additionFile));let k=e!=null&&e!==this.fileDiff;const v=s!=null&&(s.length>0||this.lineAnnotations.length>0)?s!==this.lineAnnotations:!1;if(!c&&Gt(g,this.renderRange)&&!n&&!v&&!C&&(e!=null&&e===this.fileDiff||e==null&&!m))return this.applyCachedThemeState(f);let L;e==null&&S&&(m||this.fileDiff==null)&&(L=de(d.oldFile,d.newFile,this.options.parseDiffOptions));const{renderRange:y}=this;if(this.renderRange=g,S?(this.deletionFile=h,this.additionFile=u):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e!=null?this.fileDiff=e:L!=null&&(k=!0,this.fileDiff=L),k&&(this.cachedHeaderHTML=void 0),s!=null&&this.setLineAnnotations(s),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(At(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:N=!1}=this.options;if(N&&(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 x=this.hunksRenderer.renderDiff(this.fileDiff,bn);x!=null&&this.applyThemeState(r,x.themeStyles,f,x.baseThemeType),x?.headerElement!=null&&this.applyHeaderToDOM(x.headerElement,r),this.renderSeparators([]),this.injectUnsafeCSS()}catch(x){if(H)throw x;console.error(x),x instanceof Error&&this.applyErrorToDOM(x,r)}return i||this.emitPostRender(),!0}try{const x=this.getOrCreatePreNode(r);if(!(this.canPartiallyRender(n,v,m||k||C)&&this.applyPartialRender({previousRenderRange:y,renderRange:g}))){const w=this.hunksRenderer.renderDiff(this.fileDiff,g);if(w==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(r,w.themeStyles,f,w.baseThemeType),w.headerElement!=null&&this.applyHeaderToDOM(w.headerElement,r),w.additionsContentAST!=null||w.deletionsContentAST!=null||w.unifiedContentAST!=null?this.applyHunksToDOM(x,w):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(w.hunkData)}this.applyBuffers(x,g),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(x){if(H)throw x;console.error(x),x instanceof Error&&this.applyErrorToDOM(x,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||ot(e))return e;const{diffStyle:n="split",expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options;let r,o;return Se({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({additionLine:l})=>{l!=null&&(r??=l.lineNumber,o=l.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=Wi(e,this.hunksRenderer.getExpandedHunksMap(),t);return At(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(Gi(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 $t({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 Dn({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]=gt(h);if(e<u){const f=Ee({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,C=u-f.fromEnd-e;return g<=C?this.expandHunk(d,"up",g+s):this.expandHunk(d,"down",C+s),!0}if(e<c)return!1}const o=He({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:r,collapsedContextThreshold:i,errorPrefix:"FileDiff.revealLine"});if(o==null||o.renderAll)return!1;const l=t.hunks[t.hunks.length-1],[,a]=gt(l);return e<a+o.fromStart||e>=a+o.rangeSize?!1:(this.expandHunk(t.hunks.length,"up",e-(a+o.fromStart)+1+s),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){Mn(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||!ks(i,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=i.slotName;const l=t(i,this);l!=null&&o.appendChild(l),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}-${Le(i)}`;let r=this.annotationCache.get(s);if(r==null||!xs(i,r.annotation)){r?.element.remove();const o=t(i);if(o==null)continue;r={element:In(Le(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=Fn();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:mt(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):mt(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=Pn;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??le(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:l}=this.options;if(s!=null){const u=s(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Vt,u),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const a=r?.(n)??void 0,d=o?.(n)??void 0,h=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Nn,a),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,zn,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,On,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??=Un(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Bn(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,i){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=i??n,o=this.options.theme??ae,l=typeof o=="string"?o:{...o},a=Ct(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===a){this.appliedThemeCSS.theme=l;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:l,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:a};return}this.themeCSSStyle=Vn({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:jn(t,r,a)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:l,themeStyles:t,themeType:r,baseThemeType:i,scrollbarGutter:a}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Wn(this.themeCSSStyle.textContent??"",Ct(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Gn()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?St(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=ne(t[0]),r=ne(t[1]);return s==null||r==null?!1:(i.gutter.innerHTML=le(s),i.content.innerHTML=le(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=[],l=this.hunksRenderer.renderCodeAST("unified",t),a=this.hunksRenderer.renderCodeAST("deletions",t),d=this.hunksRenderer.renderCodeAST("additions",t);this.editor?.__captureFocusForDOMReplacement(),l!=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=$e({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeUnified,l,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeUnified)):a!=null||d!=null?(a!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=$e({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:i}),this.applyCodeColumnsInPlace(this.codeDeletions,a,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(a)),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=$e({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 l=this.getCodeColumns(o,i,r,s);if(l==null)return!1;const a=e.startingLine,d=t.startingLine,h=a+e.totalLines,u=d+t.totalLines,c=Math.max(a,d),f=Math.min(h,u);if(f<=c)return!1;const p=Math.max(0,c-a),g=Math.max(0,h-f),C=this.trimColumns({columns:l,trimStart:p,trimEnd:g,previousStart:a,overlapStart:c,overlapEnd:f,diffStyle:o});if(C<0)throw new Error("FileDiff.applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");let S=this.lastRowCount-C;const m=(y,H)=>{if(!(H<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:y,totalLines:H,bufferBefore:0,bufferAfter:0})},k=m(d,Math.max(c-d,0));if(k==null&&d<c)return!1;const v=m(f,Math.max(u-f,0));if(v==null&&u>f)return!1;const L=(y,H)=>{if(y!=null){if(o==="unified"&&!Array.isArray(l))this.insertPartialHTML(o,l,y,H);else if(o==="split"&&Array.isArray(l))this.insertPartialHTML(o,l,y,H);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");S+=y.rowCount}};return this.cleanupErrorWrapper(),L(k,"afterbegin"),L(v,"beforeend"),this.lastRowCount!==S&&(this.applyRowSpan(o,l,S),this.lastRowCount=S),!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=ne(r?.[0]),l=ne(r?.[1]);for(const[a,d]of[[s.gutter,o],[s.content,l]])if(d!=null&&a.childElementCount===d.length)for(let h=0;h<d.length;h++){const u=a.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=ne(n?.[0]),s=ne(n?.[1]),r=()=>{for(const[o,l]of[[t.gutter,i],[t.content,s]])l!=null&&(o.innerHTML=le(l));e.rowCount!==this.lastRowCount&&(this.applyRowSpan("unified",t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?St(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=ne(t[0]),s=ne(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 l=n>=0;if(e==null)return 0;const a=Array.from(e.content.children),d=Array.from(e.gutter.children);if(a.length!==d.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<a.length&&!(t<=0&&!l&&!o);){const h=d[r],u=a[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||l&&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||l&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in u.dataset){(t>0||l&&i>=n)&&(h.remove(),u.remove(),s++);continue}if(h.dataset.gutterBuffer==="metadata"&&"noNewline"in u.dataset){(t>0||l&&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(l){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,C=c-g;this.updateBufferSize(h,C),this.updateBufferSize(u,C),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 l=Math.max(0,i-s),a=n-s;if(a<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?l:0,c=h?a:-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:l=!1,overflow:a="scroll",diffStyle:d="split"}=this.options,h={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:l,overflow:a,split:d==="unified"?!1:t!=null&&n!=null,totalLines:i,customProperties:s};_n(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 zt(e,t){return e==null||t==null?e==null&&t==null:jt(e,t)}function Rs({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function As({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Ts(e,t,n=!1){return!n&&e==null&&t}function bs(e,t,n=!1){return e==null&&t&&!n}function ne(e){if(!(e==null||e.type!=="element"))return e.children??[]}const lt=3e3;let Ds=-1;var _s=class extends ws{__id=`little-virtualized-file-diff:${++Ds}`;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=je(n)}setMetrics(e,t=!1){const n=je(e);!t&&Kn(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||!qn(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=!Xn(t,e),i=n&&zs(t,e);super.setOptions(e),i&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Os(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&&_t(this.renderRange)){const r=Ms(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 l of o.children){if(!(l instanceof HTMLElement))continue;const a=l.dataset.lineIndex;if(a==null)continue;const d=Bs(a,n);let h=l.getBoundingClientRect().height,u=!1;l.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in l.nextElementSibling.dataset||"noNewline"in l.nextElementSibling.dataset)&&("noNewline"in l.nextElementSibling.dataset&&(u=!0),h+=l.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,l=s||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=je(n.metrics),o=!0,l=!0);const{collapsed:a=!1,expandUnchanged:d=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,o=!0),this.currentExpandUnchanged!==d&&(this.currentExpandUnchanged=d,o=!0,l=!0),o&&this.resetLayoutCache({includeEstimatedHeights:l}),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,l=this.getDiffStyle(),a=this.getHunkSeparatorType(),d=l==="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 Se({diff:this.fileDiff,diffStyle:l,startingLine:u?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:p,hunk:g,collapsedBefore:C,collapsedAfter:S,deletionLine:m,additionLine:k})=>{const v=l==="split"?k?.splitLineIndex??m?.splitLineIndex:k?.unifiedLineIndex??m?.unifiedLineIndex;if(v==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const y=ke({type:a,metrics:this.metrics,hunkIndex:p,hunkSpecs:g?.hunkSpecs});if(y!=null){if(c+=y.gapBefore,d>=v-C&&d<v)return f={top:c,height:y.height},!0;c+=y.height+y.gapAfter}}const L=this.getLineHeight(v,(k?.noEOFCR??!1)||(m?.noEOFCR??!1));if(v===d)return f={top:c,height:L},!0;if(c+=L,S>0){const y=oe({type:a,metrics:this.metrics});if(y!=null){if(d>v&&d<=v+S)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 l=this.getLayoutCheckpointBeforeTop(e);let a=l?.top??ge(this.metrics,t)+this.cache.fileAnnotationHeight,d;return Se({diff:this.fileDiff,diffStyle:r,startingLine:l?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:h,hunk:u,collapsedBefore:c,collapsedAfter:f,deletionLine:p,additionLine:g})=>{const C=r==="split"?g?.splitLineIndex??p?.splitLineIndex:g?.unifiedLineIndex??p?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(c>0){const m=ke({type:o,metrics:this.metrics,hunkIndex:h,hunkSpecs:u?.hunkSpecs});m!=null&&(a+=m.totalHeight)}if(a>=e&&(p!=null?d={lineNumber:p.lineNumber,side:"deletions",top:a}:g!=null&&(d={lineNumber:g.lineNumber,side:"additions",top:a}),d!=null))return!0;const S=this.getLineHeight(C,(g?.noEOFCR??!1)||(p?.noEOFCR??!1));if(a+=S,f>0){const m=oe({type:o,metrics:this.metrics});m!=null&&(a+=m.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=rt("clone",e,t);if(await nt(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(rt("merge",e,t),this.setHydratedState(t),await nt(()=>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 l={...r.get(o.hunkIndex)??{fromStart:0,fromEnd:0}},a=o.expansionLineCountOverride??i;(o.direction==="up"||o.direction==="both")&&(l.fromStart+=a),(o.direction==="down"||o.direction==="both")&&(l.fromEnd+=a),r.set(o.hunkIndex,l)}return $t({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}=Qi({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,canHydratePartialDiff:Je(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=it(s,"VirtualizedFileDiff.render"),o=r!=null,l=r?.oldFile,a=r?.newFile,d=o&&(!Bt(l,this.deletionFile)||!Bt(a,this.additionFile));let h=t??this.fileDiff;t==null&&o&&(d||this.fileDiff==null)&&(h=de(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),C=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 L=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(L==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");L.connect(e,this),this.isVisible=L.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!C||!c))return this.fileDiff=h,r!=null&&(this.deletionFile=l,this.additionFile=a),g&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const S=this.virtualizer.getWindowSpecs(),m=this.top??0,k=this.computeRenderRangeFromWindow(h,m,S),v=super.render({fileDiff:h,fileContainer:e,renderRange:k,lineAnnotations:i,forceRender:(u??n)||f||g,...r,...s});return this.isSimpleMode()&&v&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),v}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 Us(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=Je(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),l=this.getHunkSeparatorType(),a=n?!0:this.hunksRenderer.getExpandedHunksMap(),d=Is(this.cache.heightDeltas);let h=ge(this.metrics,t)+this.cache.fileAnnotationHeight,u=0;const c=({rowCount:f,startLineIndex:p,preSeparatorHeight:g=0,postSeparatorHeight:C=0,metadataOffsets:S=[]})=>{if(f<=0)return;const m=u,k=u+f;let v=Fs(m);for(;v<k;){const L=v-m,y=h+(L>0?g:0)+L*this.metrics.lineHeight+Ps(S,L)*this.metrics.lineHeight+Ot(d,p,p+L);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:p+L,top:y}),v+=lt}h+=g+f*this.metrics.lineHeight+S.length*this.metrics.lineHeight+Ot(d,p,p+f)+C,u=k};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=Ee({isPartial:e.isPartial,rangeSize:p.collapsedBefore,expandedHunks:a,hunkIndex:f,collapsedContextThreshold:i}),C=g.collapsedLines>0?ke({type:l,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 S=C;c({rowCount:g.fromEnd,startLineIndex:(o==="split"?p.splitLineStart:p.unifiedLineStart)-g.fromEnd,preSeparatorHeight:S}),g.fromEnd>0&&(S=0);const m=f===s?He({fileDiff:e,hunkIndex:f,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,k=m!=null&&m.collapsedLines>0?oe({type:l,metrics:this.metrics})?.totalHeight??0:f===s&&r?oe({type:l,metrics:this.metrics})?.totalHeight??0:0,v=m!=null?m.fromStart+m.fromEnd:0,L=o==="split"?p.splitLineCount:p.unifiedLineCount,y=o==="split"?p.splitLineStart:p.unifiedLineStart;c({rowCount:L,startLineIndex:y,preSeparatorHeight:S,postSeparatorHeight:v===0?k:0,metadataOffsets:Ns({diffStyle:o,hunk:p,rowCount:L})}),m!=null&&v>0&&c({rowCount:v,startLineIndex:y+L,postSeparatorHeight:k})}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 l of e.hunks)n+=t==="split"?l.splitLineCount:l.unifiedLineCount;return n}const{expandUnchanged:i=!1,collapsedContextThreshold:s=1}=this.options,r=i?!0:this.hunksRenderer.getExpandedHunksMap();for(const[l,a]of e.hunks.entries()){const d=t==="split"?a.splitLineCount:a.unifiedLineCount;n+=d;const h=Math.max(a.collapsedBefore,0),{fromStart:u,fromEnd:c,renderAll:f}=Ee({isPartial:e.isPartial,rangeSize:h,expandedHunks:r,hunkIndex:l,collapsedContextThreshold:s});h>0&&(n+=f?h:u+c)}const o=He({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:l,lineHeight:a}=this.metrics,d=this.getDiffStyle(),h=this.getHunkSeparatorType(),u=Je(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?Wt(this.metrics):0,{fileAnnotationHeight:C}=this.cache,S=p+C,m=Math.max(0,c-p-C-g),k=this.hasFileAnnotations(e),v=t+p,L=C>0&&k&&v<i&&v+C>n;if(t<n-c||t>i)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};if(f<=l||e.hunks.length===0)return{startingLine:0,totalLines:l,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),f=this.getLayoutLineCount(e,d);const y=Math.ceil(Math.max(i-n,0)/a),H=Math.ceil(y/l)*l+l,N=H/l,x=N,w=[],M=(n+i)/2,D=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-H*a*2),l);let E=t+(D?.top??S),j=D?.renderedLineIndex??0,ie,A,T;if(Se({diff:e,diffStyle:d,startingLine:D?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:xe,hunk:K,collapsedBefore:Ve,collapsedAfter:We,deletionLine:se,additionLine:q})=>{const I=q!=null?q.splitLineIndex:se.splitLineIndex,O=q!=null?q.unifiedLineIndex:se.unifiedLineIndex,V=(q?.noEOFCR??!1)||(se?.noEOFCR??!1),re=xe===e.hunks.length-1&&K!=null&&(d==="split"?I===K.splitLineStart+K.splitLineCount-1:O===K.unifiedLineStart+K.unifiedLineCount-1),W=(Ve>0?ke({type:h,metrics:this.metrics,hunkIndex:xe,hunkSpecs:K?.hunkSpecs}):void 0)?.totalHeight??0;E+=W;const G=j%l===0,ee=Math.floor(j/l);if(G&&(w[ee]=E-(t+S+W),T!=null)){if(T<=0)return!0;T--}const U=this.getLineHeight(d==="split"?I:O,V);if(E>n-U&&E<i&&(ie??=ee),A==null&&E+U>M&&(A=ee),T==null&&E>=i&&G&&(T=x),j++,E+=U,We>0||re&&u){const Re=oe({type:h,metrics:this.metrics});Re!=null&&(E<i&&E+Re.totalHeight>n&&(ie??=ee),A==null&&E+Re.totalHeight>M&&(A=ee),E+=Re.totalHeight)}return!1}}),ie==null)if(L)ie=0,A=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:c-p-g};A??=ie;const Z=Math.round(A-N/2),ue=Math.max(0,Math.ceil(f/l)-N),R=Math.max(0,Math.min(Z,ue)),b=R*l,F=Z<0?H+Z*l:H,B=w[R]??0,Q=b===0?0:C+B,ce=R+F/l,we=ce<w.length?m-w[ce]:m-(E-t-S);return{startingLine:b,totalLines:F,bufferBefore:Q,bufferAfter:Math.max(0,we)}}};function Ms(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 Is(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 Ot({lineIndexes:e,prefixTotals:t},n,i){if(n>=i||e.length===0)return 0;const s=Ut(e,n);return(t[Ut(e,i)]??0)-(t[s]??0)}function Ut(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 Fs(e){return Math.ceil(e/lt)*lt}function Ps(e,t){let n=0;for(const i of e)i<t&&n++;return n}function Ns({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=[],l=n-r;return i.deletions>0&&t.noEOFCRDeletions&&o.push(l+i.deletions-1),i.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function zs(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 Os(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 Je(e,t){return e.isPartial&&t&&(e.type==="change"||e.type==="rename-changed")}function Us(e){return typeof e=="function"?"custom":e??"line-info"}function Bt(e,t){return e==null||t==null?e==null&&t==null:jt(e,t)}function Bs(e,t){const[n,i]=e.split(",").map(Number);return t==="split"?i:n}function $s(e,t){return e.length===t.length&&e.every((n,i)=>n.path===t[i].path&&n.edits===t[i].edits&&n.writeContent===t[i].writeContent&&n.fileChange===t[i].fileChange)}function js(e,t){const n=Object.keys(t);return n.length===Object.keys(e).length&&n.every(i=>e[i]===t[i])}function Vs(e,t){let n=e;for(let i=t.length-1;i>=0;i--){const{oldText:s,newText:r}=t[i];if(r===""&&n!=="")return null;const o=n.indexOf(r);if(o===-1)return null;n=n.slice(0,o)+s+n.slice(o+r.length)}return n}function Ks(e){const t=new Map;for(const r of e.tools){if(!r.path)continue;const o=t.get(r.path)??[];o.push(r),t.set(r.path,o)}const n=[],i=new Set(Object.entries(e.snapshots).flatMap(([r,o])=>o===null?[r]:[])),s={...e.snapshots};for(const[r,o]of t){const l=e.currentByPath[r],a=o.flatMap(m=>m.edits??[]),d=o.flatMap(m=>m.fileChange&&m.fileChange.truncated!==!0?[m.fileChange]:[]),h=[...o].reverse().find(m=>m.writeContent!=null)?.writeContent,u=o.find(m=>m.fileChange)?.fileChange,c=[...o].reverse().find(m=>m.fileChange||m.writeContent!=null||m.edits?.length),f=c?.fileChange?c.fileChange.truncated===!0?null:c.fileChange.newText:c?.writeContent??null,p=Object.hasOwn(s,r),g=s[r];if(!p&&u?.truncated===!0){s[r]=null,i.add(r);continue}if(p&&g===null){i.add(r);continue}let C=typeof g=="string"?g:d[0]?.oldText??null;const S=typeof l=="string"?l:f;C==null&&(a.length>0&&typeof l=="string"?C=Vs(l,a):h!=null&&a.length===0&&(C="")),S==null&&c?.fileChange?.truncated===!0&&i.add(r),!(C==null||S==null)&&(C===S&&d.length===0||(s[r]=C,n.push({path:r,oldText:C,newText:S})))}return{files:n,snapshots:s,...i.size>0?{incompletePaths:[...i]}:{}}}export{ws as F,_s as V,Vs as a,js as b,Ks as c,At as f,de as p,Gs as r,$s as s};
|