termdock 1.4.189 → 1.4.190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/App-BkcaQXGe.js +155 -0
- package/dist/client/assets/App-BkcaQXGe.js.br +0 -0
- package/dist/client/assets/App-BkcaQXGe.js.gz +0 -0
- package/dist/client/assets/{ChangeWalkthroughPanel-CtZKX2AS.js → ChangeWalkthroughPanel-BkTM7zQ0.js} +2 -2
- package/dist/client/assets/ChangeWalkthroughPanel-BkTM7zQ0.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-BkTM7zQ0.js.gz +0 -0
- package/dist/client/assets/{DagPlayground-B9ly2Wta.js → DagPlayground-7UxLIhH5.js} +1 -1
- package/dist/client/assets/DagPlayground-7UxLIhH5.js.br +0 -0
- package/dist/client/assets/DagPlayground-7UxLIhH5.js.gz +0 -0
- package/dist/client/assets/{DiffLab-Bkzvr6Ys.js → DiffLab-Cn2bPbbB.js} +1 -1
- package/dist/client/assets/DiffLab-Cn2bPbbB.js.br +0 -0
- package/dist/client/assets/DiffLab-Cn2bPbbB.js.gz +0 -0
- package/dist/client/assets/{DiffReview-B5AC89kp.js → DiffReview-Bax7DQmN.js} +1 -1
- package/dist/client/assets/DiffReview-Bax7DQmN.js.br +0 -0
- package/dist/client/assets/DiffReview-Bax7DQmN.js.gz +0 -0
- package/dist/client/assets/{DiffReviewLab--K2fE9B_.js → DiffReviewLab-TG4kjagX.js} +2 -2
- package/dist/client/assets/DiffReviewLab-TG4kjagX.js.br +0 -0
- package/dist/client/assets/DiffReviewLab-TG4kjagX.js.gz +0 -0
- package/dist/client/assets/{DiffViewer-YO7X8DnR.js → DiffViewer-3MezBn_a.js} +1 -1
- package/dist/client/assets/DiffViewer-3MezBn_a.js.br +0 -0
- package/dist/client/assets/DiffViewer-3MezBn_a.js.gz +0 -0
- package/dist/client/assets/{ModelPreview-B0942mh0.js → ModelPreview-BV_0H-Ls.js} +1 -1
- package/dist/client/assets/ModelPreview-BV_0H-Ls.js.br +0 -0
- package/dist/client/assets/ModelPreview-BV_0H-Ls.js.gz +0 -0
- package/dist/client/assets/{RightSidebar-Dvo-tMYw.js → RightSidebar-BHlwv3gW.js} +30 -30
- package/dist/client/assets/RightSidebar-BHlwv3gW.js.br +0 -0
- package/dist/client/assets/RightSidebar-BHlwv3gW.js.gz +0 -0
- package/dist/client/assets/{abnfDiagram-VCTEODGH-DR1DwZvG.js → abnfDiagram-VCTEODGH-DOk0otQq.js} +1 -1
- package/dist/client/assets/abnfDiagram-VCTEODGH-DOk0otQq.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-DOk0otQq.js.gz +0 -0
- package/dist/client/assets/{app-CSjqfJEX.js → app-B0az5Yz6.js} +12 -12
- package/dist/client/assets/app-B0az5Yz6.js.br +0 -0
- package/dist/client/assets/app-B0az5Yz6.js.gz +0 -0
- package/dist/client/assets/{arc-BiK-hDRQ.js → arc-CfeOYtSi.js} +1 -1
- package/dist/client/assets/arc-CfeOYtSi.js.br +0 -0
- package/dist/client/assets/arc-CfeOYtSi.js.gz +0 -0
- package/dist/client/assets/{architectureDiagram-5GKGNRK7-BRoIiPdr.js → architectureDiagram-5GKGNRK7-Dys1Wr-I.js} +1 -1
- package/dist/client/assets/architectureDiagram-5GKGNRK7-Dys1Wr-I.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-Dys1Wr-I.js.gz +0 -0
- package/dist/client/assets/{blockDiagram-I7D4REHJ--oR7UeK0.js → blockDiagram-I7D4REHJ-D8DbjMtS.js} +1 -1
- package/dist/client/assets/blockDiagram-I7D4REHJ-D8DbjMtS.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-D8DbjMtS.js.gz +0 -0
- package/dist/client/assets/{c4Diagram-7LVT6UL2-DWZqhfmV.js → c4Diagram-7LVT6UL2-DJcMUQXb.js} +1 -1
- package/dist/client/assets/c4Diagram-7LVT6UL2-DJcMUQXb.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-DJcMUQXb.js.gz +0 -0
- package/dist/client/assets/channel-SwcBL8jW.js +1 -0
- package/dist/client/assets/{chunk-2Q5K7J3B-CDds2Uuw.js → chunk-2Q5K7J3B-BPmsHIzM.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-C6tFNdRP.js → chunk-5VM5RSS4-BTxB35XY.js} +1 -1
- package/dist/client/assets/{chunk-F27PBJKO-Byjlqrbp.js → chunk-F27PBJKO-BiUpuqFN.js} +1 -1
- package/dist/client/assets/chunk-F27PBJKO-BiUpuqFN.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-BiUpuqFN.js.gz +0 -0
- package/dist/client/assets/{chunk-IMKFNOWR--FcxAC6S.js → chunk-IMKFNOWR-Bvca4yZA.js} +1 -1
- package/dist/client/assets/chunk-IMKFNOWR-Bvca4yZA.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-Bvca4yZA.js.gz +0 -0
- package/dist/client/assets/{chunk-JWPE2WC7-DXF5NaP8.js → chunk-JWPE2WC7-CxCNQSVG.js} +1 -1
- package/dist/client/assets/{chunk-POPQ4Y6H-BX-3HMDv.js → chunk-POPQ4Y6H-C9E5B9o7.js} +1 -1
- package/dist/client/assets/{chunk-SVP7TREG-BOiT609f.js → chunk-SVP7TREG-D4Qm28xz.js} +1 -1
- package/dist/client/assets/chunk-SVP7TREG-D4Qm28xz.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-D4Qm28xz.js.gz +0 -0
- package/dist/client/assets/{chunk-TICWLB2K-e4h0BXa_.js → chunk-TICWLB2K-CS0AERD9.js} +1 -1
- package/dist/client/assets/chunk-TICWLB2K-CS0AERD9.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-CS0AERD9.js.gz +0 -0
- package/dist/client/assets/{chunk-XXDRQBXY-CGDPxIY9.js → chunk-XXDRQBXY-C1vCDgbp.js} +1 -1
- package/dist/client/assets/classDiagram-ZZMXUADV-BOSTHjwM.js +1 -0
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-BOSTHjwM.js +1 -0
- package/dist/client/assets/{cose-bilkent-JH36ORCC-BI_vxPbJ.js → cose-bilkent-JH36ORCC-D0-yuoIn.js} +1 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-D0-yuoIn.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-D0-yuoIn.js.gz +0 -0
- package/dist/client/assets/{cynefin-OW5HDTMX-Do00pWzR.js → cynefin-OW5HDTMX-C9ZqMdi9.js} +1 -1
- package/dist/client/assets/{cynefin-OW5HDTMX-Do00pWzR.js.br → cynefin-OW5HDTMX-C9ZqMdi9.js.br} +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-C9ZqMdi9.js.gz +0 -0
- package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-1WmUYFxF.js → cynefinDiagram-5FMLGOSQ-Drvx9Dke.js} +1 -1
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-Drvx9Dke.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-Drvx9Dke.js.gz +0 -0
- package/dist/client/assets/{dagre-GXQ25YYZ-DuPIdG-w.js → dagre-GXQ25YYZ-mUXNFR_H.js} +1 -1
- package/dist/client/assets/dagre-GXQ25YYZ-mUXNFR_H.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-mUXNFR_H.js.gz +0 -0
- package/dist/client/assets/{diagram-S7CK7UJ4-umWopOc1.js → diagram-S7CK7UJ4-CKJgF0VS.js} +1 -1
- package/dist/client/assets/diagram-S7CK7UJ4-CKJgF0VS.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-CKJgF0VS.js.gz +0 -0
- package/dist/client/assets/{diagram-UQ7AKVKN-BZGG-JMX.js → diagram-UQ7AKVKN-Cp9NE2Gc.js} +1 -1
- package/dist/client/assets/diagram-UQ7AKVKN-Cp9NE2Gc.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-Cp9NE2Gc.js.gz +0 -0
- package/dist/client/assets/{diagram-VSXAHHWV-3yFnWBx7.js → diagram-VSXAHHWV-mnyDXn4l.js} +1 -1
- package/dist/client/assets/diagram-VSXAHHWV-mnyDXn4l.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-mnyDXn4l.js.gz +0 -0
- package/dist/client/assets/{diagram-VX7I27RA-zH56mQpP.js → diagram-VX7I27RA-6lyjUw6O.js} +1 -1
- package/dist/client/assets/diagram-VX7I27RA-6lyjUw6O.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-6lyjUw6O.js.gz +0 -0
- package/dist/client/assets/{diagram-Z3DM3KII-gXKs8FAs.js → diagram-Z3DM3KII-3K_Dhn1t.js} +1 -1
- package/dist/client/assets/diagram-Z3DM3KII-3K_Dhn1t.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-3K_Dhn1t.js.gz +0 -0
- package/dist/client/assets/{ebnfDiagram-PWID7BFC-S-Aae0-1.js → ebnfDiagram-PWID7BFC-B2mHkMsE.js} +1 -1
- package/dist/client/assets/ebnfDiagram-PWID7BFC-B2mHkMsE.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-B2mHkMsE.js.gz +0 -0
- package/dist/client/assets/{erDiagram-RLTQ6QDP-xdgylvRj.js → erDiagram-RLTQ6QDP-Brfc7YEf.js} +1 -1
- package/dist/client/assets/erDiagram-RLTQ6QDP-Brfc7YEf.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-Brfc7YEf.js.gz +0 -0
- package/dist/client/assets/{flowDiagram-HODETNUW-B6UrhCh4.js → flowDiagram-HODETNUW-UGHsvQMc.js} +1 -1
- package/dist/client/assets/flowDiagram-HODETNUW-UGHsvQMc.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-UGHsvQMc.js.gz +0 -0
- package/dist/client/assets/{ganttDiagram-EL5Y4UJY-C3TlLmkc.js → ganttDiagram-EL5Y4UJY-CC30lZuL.js} +1 -1
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-CC30lZuL.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-CC30lZuL.js.gz +0 -0
- package/dist/client/assets/{gestureArbiter-BVBarnU9.js → gestureArbiter-DIYXjBYY.js} +1 -1
- package/dist/client/assets/gestureArbiter-DIYXjBYY.js.br +0 -0
- package/dist/client/assets/gestureArbiter-DIYXjBYY.js.gz +0 -0
- package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-wwc8lPj0.js → gitGraphDiagram-WWUBYQGX-CiwHG61R.js} +1 -1
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CiwHG61R.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CiwHG61R.js.gz +0 -0
- package/dist/client/assets/{index-CreRkeNE.css → index-TEmneMvF.css} +1 -1
- package/dist/client/assets/index-TEmneMvF.css.br +0 -0
- package/dist/client/assets/{index-CreRkeNE.css.gz → index-TEmneMvF.css.gz} +0 -0
- package/dist/client/assets/{infoDiagram-27XIBGKW-CuWcAjaO.js → infoDiagram-27XIBGKW-CcAeYa6X.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-5VMMS53U-ixH6dlqa.js → ishikawaDiagram-5VMMS53U-COFtLTBs.js} +1 -1
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-COFtLTBs.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-COFtLTBs.js.gz +0 -0
- package/dist/client/assets/{journeyDiagram-3NMN7TZE-jsf7IH_2.js → journeyDiagram-3NMN7TZE-D0iXlEDw.js} +1 -1
- package/dist/client/assets/journeyDiagram-3NMN7TZE-D0iXlEDw.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-D0iXlEDw.js.gz +0 -0
- package/dist/client/assets/{kanban-definition-UXKFOSKX-BjqjHq8B.js → kanban-definition-UXKFOSKX-Dr2EVP3G.js} +1 -1
- package/dist/client/assets/kanban-definition-UXKFOSKX-Dr2EVP3G.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-Dr2EVP3G.js.gz +0 -0
- package/dist/client/assets/{layout-DJhyTq7J.js → layout-CCzGp_3m.js} +1 -1
- package/dist/client/assets/layout-CCzGp_3m.js.br +0 -0
- package/dist/client/assets/layout-CCzGp_3m.js.gz +0 -0
- package/dist/client/assets/{linear-Cuf3UwJO.js → linear-B-AlDkuD.js} +1 -1
- package/dist/client/assets/linear-B-AlDkuD.js.br +0 -0
- package/dist/client/assets/linear-B-AlDkuD.js.gz +0 -0
- package/dist/client/assets/{mermaid.core-q_70PIqZ.js → mermaid.core-C8GTgQvN.js} +5 -5
- package/dist/client/assets/mermaid.core-C8GTgQvN.js.br +0 -0
- package/dist/client/assets/mermaid.core-C8GTgQvN.js.gz +0 -0
- package/dist/client/assets/{mindmap-definition-YA3MSWOX-Dk3Drgrh.js → mindmap-definition-YA3MSWOX-B1_AIM7r.js} +1 -1
- package/dist/client/assets/mindmap-definition-YA3MSWOX-B1_AIM7r.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-B1_AIM7r.js.gz +0 -0
- package/dist/client/assets/{passwordBootstrap-CQsYwRFF.js → passwordBootstrap-DUJCjLgA.js} +1 -1
- package/dist/client/assets/passwordBootstrap-DUJCjLgA.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-DUJCjLgA.js.gz +0 -0
- package/dist/client/assets/{pegDiagram-XKGWAZYB-Cx2kpJ53.js → pegDiagram-XKGWAZYB-BGri_6xk.js} +1 -1
- package/dist/client/assets/pegDiagram-XKGWAZYB-BGri_6xk.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-BGri_6xk.js.gz +0 -0
- package/dist/client/assets/{pieDiagram-E7YTZNPT-CAECgOHT.js → pieDiagram-E7YTZNPT-DyJUIUtO.js} +1 -1
- package/dist/client/assets/pieDiagram-E7YTZNPT-DyJUIUtO.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-DyJUIUtO.js.gz +0 -0
- package/dist/client/assets/{quadrantDiagram-AXDQQJYC-BYb3yLp6.js → quadrantDiagram-AXDQQJYC-ChYx832r.js} +1 -1
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-ChYx832r.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-ChYx832r.js.gz +0 -0
- package/dist/client/assets/{railroadDiagram-O6MQD6OU-9NFnMkmP.js → railroadDiagram-O6MQD6OU-Ll7CEGCv.js} +1 -1
- package/dist/client/assets/railroadDiagram-O6MQD6OU-Ll7CEGCv.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-Ll7CEGCv.js.gz +0 -0
- package/dist/client/assets/{referenceLongPress-B-A_CKaJ.js → referenceLongPress-DhODL_ZR.js} +1 -1
- package/dist/client/assets/referenceLongPress-DhODL_ZR.js.br +0 -0
- package/dist/client/assets/referenceLongPress-DhODL_ZR.js.gz +0 -0
- package/dist/client/assets/{requirementDiagram-BXWQKSXE-ClYJW_kx.js → requirementDiagram-BXWQKSXE-WAFfi6wC.js} +1 -1
- package/dist/client/assets/requirementDiagram-BXWQKSXE-WAFfi6wC.js.br +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-WAFfi6wC.js.gz +0 -0
- package/dist/client/assets/{sankeyDiagram-P5KCCOFB-BVKU1OEs.js → sankeyDiagram-P5KCCOFB-Bmk9JzLH.js} +1 -1
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-Bmk9JzLH.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-Bmk9JzLH.js.gz +0 -0
- package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-BphaQddV.js → sequenceDiagram-WJ2MYXX4-CQLp4wz7.js} +1 -1
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-CQLp4wz7.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-CQLp4wz7.js.gz +0 -0
- package/dist/client/assets/{sizeCapture-INFHLROL-B7SoOz1O.js → sizeCapture-INFHLROL-7biER85h.js} +1 -1
- package/dist/client/assets/sizeCapture-INFHLROL-7biER85h.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-7biER85h.js.gz +0 -0
- package/dist/client/assets/{sparkles-B3lcHnSJ.js → sparkles-Bdif6oju.js} +1 -1
- package/dist/client/assets/{stateDiagram-D77RDMKH-CrvEfGMj.js → stateDiagram-D77RDMKH-Cy9r_YvI.js} +1 -1
- package/dist/client/assets/stateDiagram-D77RDMKH-Cy9r_YvI.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-Cy9r_YvI.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-DOly_YL3.js +1 -0
- package/dist/client/assets/{swimlanes-42K2YHIH-BTV61yEQ.js → swimlanes-42K2YHIH-DeAGlPA-.js} +1 -1
- package/dist/client/assets/swimlanes-42K2YHIH-DeAGlPA-.js.br +0 -0
- package/dist/client/assets/swimlanes-42K2YHIH-DeAGlPA-.js.gz +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-DxYgGhLH.js +8 -0
- package/dist/client/assets/{timeline-definition-24CTP7MA-CO2JWGKo.js → timeline-definition-24CTP7MA-BRAobv6g.js} +1 -1
- package/dist/client/assets/timeline-definition-24CTP7MA-BRAobv6g.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-BRAobv6g.js.gz +0 -0
- package/dist/client/assets/{triangle-alert-eoJEloNw.js → triangle-alert-Bllwcw-n.js} +1 -1
- package/dist/client/assets/{vennDiagram-4TSXK5OY-CH1q34kT.js → vennDiagram-4TSXK5OY-B4uz7tHn.js} +1 -1
- package/dist/client/assets/vennDiagram-4TSXK5OY-B4uz7tHn.js.br +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-B4uz7tHn.js.gz +0 -0
- package/dist/client/assets/{wardleyDiagram-VM6X3IG4-DiU2pGsi.js → wardleyDiagram-VM6X3IG4-uRNjWdqL.js} +1 -1
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-uRNjWdqL.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-uRNjWdqL.js.gz +0 -0
- package/dist/client/assets/{xychartDiagram-S5SC5T6Z-CIufUBWj.js → xychartDiagram-S5SC5T6Z-DCT4HGtL.js} +1 -1
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DCT4HGtL.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DCT4HGtL.js.gz +0 -0
- package/dist/client/index.html +2 -2
- package/dist/client/index.html.br +0 -0
- package/dist/client/index.html.gz +0 -0
- package/dist/client/sw.js +1 -1
- package/dist/client/sw.js.br +0 -0
- package/dist/client/sw.js.gz +0 -0
- package/dist/server/agent/collaborationPrompt.js +22 -50
- package/package.json +1 -1
- package/runtime-manifest.json +3 -3
- package/dist/client/assets/App-CqPSkz_g.js +0 -150
- package/dist/client/assets/App-CqPSkz_g.js.br +0 -0
- package/dist/client/assets/App-CqPSkz_g.js.gz +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-CtZKX2AS.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-CtZKX2AS.js.gz +0 -0
- package/dist/client/assets/DagPlayground-B9ly2Wta.js.br +0 -0
- package/dist/client/assets/DagPlayground-B9ly2Wta.js.gz +0 -0
- package/dist/client/assets/DiffLab-Bkzvr6Ys.js.br +0 -0
- package/dist/client/assets/DiffLab-Bkzvr6Ys.js.gz +0 -0
- package/dist/client/assets/DiffReview-B5AC89kp.js.br +0 -0
- package/dist/client/assets/DiffReview-B5AC89kp.js.gz +0 -0
- package/dist/client/assets/DiffReviewLab--K2fE9B_.js.br +0 -0
- package/dist/client/assets/DiffReviewLab--K2fE9B_.js.gz +0 -0
- package/dist/client/assets/DiffViewer-YO7X8DnR.js.br +0 -0
- package/dist/client/assets/DiffViewer-YO7X8DnR.js.gz +0 -0
- package/dist/client/assets/ModelPreview-B0942mh0.js.br +0 -0
- package/dist/client/assets/ModelPreview-B0942mh0.js.gz +0 -0
- package/dist/client/assets/RightSidebar-Dvo-tMYw.js.br +0 -0
- package/dist/client/assets/RightSidebar-Dvo-tMYw.js.gz +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-DR1DwZvG.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-DR1DwZvG.js.gz +0 -0
- package/dist/client/assets/app-CSjqfJEX.js.br +0 -0
- package/dist/client/assets/app-CSjqfJEX.js.gz +0 -0
- package/dist/client/assets/arc-BiK-hDRQ.js.br +0 -0
- package/dist/client/assets/arc-BiK-hDRQ.js.gz +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-BRoIiPdr.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-BRoIiPdr.js.gz +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ--oR7UeK0.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ--oR7UeK0.js.gz +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-DWZqhfmV.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-DWZqhfmV.js.gz +0 -0
- package/dist/client/assets/channel-CC0QyaPQ.js +0 -1
- package/dist/client/assets/chunk-F27PBJKO-Byjlqrbp.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-Byjlqrbp.js.gz +0 -0
- package/dist/client/assets/chunk-IMKFNOWR--FcxAC6S.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR--FcxAC6S.js.gz +0 -0
- package/dist/client/assets/chunk-SVP7TREG-BOiT609f.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-BOiT609f.js.gz +0 -0
- package/dist/client/assets/chunk-TICWLB2K-e4h0BXa_.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-e4h0BXa_.js.gz +0 -0
- package/dist/client/assets/classDiagram-ZZMXUADV-C5HydkJF.js +0 -1
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-C5HydkJF.js +0 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-BI_vxPbJ.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-BI_vxPbJ.js.gz +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-Do00pWzR.js.gz +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-1WmUYFxF.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-1WmUYFxF.js.gz +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-DuPIdG-w.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-DuPIdG-w.js.gz +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-umWopOc1.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-umWopOc1.js.gz +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-BZGG-JMX.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-BZGG-JMX.js.gz +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-3yFnWBx7.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-3yFnWBx7.js.gz +0 -0
- package/dist/client/assets/diagram-VX7I27RA-zH56mQpP.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-zH56mQpP.js.gz +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-gXKs8FAs.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-gXKs8FAs.js.gz +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-S-Aae0-1.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-S-Aae0-1.js.gz +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-xdgylvRj.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-xdgylvRj.js.gz +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-B6UrhCh4.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-B6UrhCh4.js.gz +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-C3TlLmkc.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-C3TlLmkc.js.gz +0 -0
- package/dist/client/assets/gestureArbiter-BVBarnU9.js.br +0 -0
- package/dist/client/assets/gestureArbiter-BVBarnU9.js.gz +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-wwc8lPj0.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-wwc8lPj0.js.gz +0 -0
- package/dist/client/assets/index-CreRkeNE.css.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-ixH6dlqa.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-ixH6dlqa.js.gz +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-jsf7IH_2.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-jsf7IH_2.js.gz +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-BjqjHq8B.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-BjqjHq8B.js.gz +0 -0
- package/dist/client/assets/layout-DJhyTq7J.js.br +0 -0
- package/dist/client/assets/layout-DJhyTq7J.js.gz +0 -0
- package/dist/client/assets/linear-Cuf3UwJO.js.br +0 -0
- package/dist/client/assets/linear-Cuf3UwJO.js.gz +0 -0
- package/dist/client/assets/mermaid.core-q_70PIqZ.js.br +0 -0
- package/dist/client/assets/mermaid.core-q_70PIqZ.js.gz +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-Dk3Drgrh.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-Dk3Drgrh.js.gz +0 -0
- package/dist/client/assets/passwordBootstrap-CQsYwRFF.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-CQsYwRFF.js.gz +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-Cx2kpJ53.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-Cx2kpJ53.js.gz +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-CAECgOHT.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-CAECgOHT.js.gz +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-BYb3yLp6.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-BYb3yLp6.js.gz +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-9NFnMkmP.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-9NFnMkmP.js.gz +0 -0
- package/dist/client/assets/referenceLongPress-B-A_CKaJ.js.br +0 -0
- package/dist/client/assets/referenceLongPress-B-A_CKaJ.js.gz +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-ClYJW_kx.js.br +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-ClYJW_kx.js.gz +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-BVKU1OEs.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-BVKU1OEs.js.gz +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BphaQddV.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BphaQddV.js.gz +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-B7SoOz1O.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-B7SoOz1O.js.gz +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-CrvEfGMj.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-CrvEfGMj.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-u1T2HR3l.js +0 -1
- package/dist/client/assets/swimlanes-42K2YHIH-BTV61yEQ.js.br +0 -0
- package/dist/client/assets/swimlanes-42K2YHIH-BTV61yEQ.js.gz +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-DFZ62Fin.js +0 -8
- package/dist/client/assets/timeline-definition-24CTP7MA-CO2JWGKo.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-CO2JWGKo.js.gz +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-CH1q34kT.js.br +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-CH1q34kT.js.gz +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DiU2pGsi.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DiU2pGsi.js.gz +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-CIufUBWj.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-CIufUBWj.js.gz +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-
|
|
2
|
-
import{Z as bt,R as qf,
|
|
3
|
-
`)}function
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-BV_0H-Ls.js","assets/app-B0az5Yz6.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-TEmneMvF.css","assets/App-BkcaQXGe.js","assets/gestureArbiter-DIYXjBYY.js","assets/gestureArbiter-C2J0D0kV.css","assets/referenceLongPress-DhODL_ZR.js","assets/triangle-alert-Bllwcw-n.js","assets/DiffReview-Bax7DQmN.js","assets/sparkles-Bdif6oju.js","assets/DiffViewer-3MezBn_a.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-BkTM7zQ0.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-C8GTgQvN.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{Z as bt,R as qf,aS as e,c4 as xt,ca as gt,b6 as Ze,a as ks,av as Kf,C as di,c as Ss,X as Dt,c2 as Vf,aI as Yf,u as us,ab as Xf,c6 as oe,aM as Jf,aO as xd,aP as Qf,aQ as Zf,aN as fs,al as eh,E as th,M as rh,aL as nh,b7 as sh,b9 as ah,ba as oh,aD as ih,b8 as Rc,t as Ct,e as lh,L as nt,q as ch,b as dh,aC as Cc,ai as Nc,ag as uh,ap as ya,aq as Mc,cb as vs,a9 as hs,ar as fh,c3 as Ho,b1 as hh,ak as mh,c0 as ph,by as gh,at as bh,G as $c,F as xh,ah as vh,aj as yh,an as Ec,bA as wh,o as kh,d as wa,f as ui,r as Sh,a5 as jh,_ as js,bs as Rh,c9 as Ch,aZ as Nh,a7 as Mh}from"./app-B0az5Yz6.js";import{b as o,r as zr}from"./dnd-BCFAPC0L.js";import{w as $h,f as Eh,n as Pa,d as Lh,P as Ah,i as Ph,R as fi,o as vd,p as Th,S as zn,D as Ih,c as yd,a as _h,v as wd,t as Lc,s as ka,q as Dh,r as Fh,u as Bh,T as Ac,C as Pc,h as zo,g as Sa,b as Oh,k as Uh,e as Hh,l as zh,F as Tc}from"./App-BkcaQXGe.js";import{a as Wh,S as Gh,b as kd,c as hi,F as qh}from"./gestureArbiter-DIYXjBYY.js";import{D as mi,C as ys,L as Sd,f as Kh,n as Vh}from"./DiffReview-Bax7DQmN.js";import{T as Yh,L as Da}from"./triangle-alert-Bllwcw-n.js";import{S as Rs}from"./sparkles-Bdif6oju.js";import{C as jd,a as Rd,M as Cd,G as Rr}from"./ChangeWalkthroughPanel-BkTM7zQ0.js";import{r as Nd,s as Md,l as $d,u as Xh,G as Ed,h as Ld}from"./DiffViewer-3MezBn_a.js";import{u as Ad}from"./referenceLongPress-DhODL_ZR.js";const Jh=[["path",{d:"m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16",key:"d5nyq2"}],["path",{d:"M22 9v7",key:"pvm9v3"}],["path",{d:"M3.304 13h6.392",key:"1q3zxz"}],["circle",{cx:"18.5",cy:"12.5",r:"3.5",key:"z97x68"}]],Qh=bt("case-sensitive",Jh);const Zh=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],em=bt("eye-off",Zh);const tm=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],pi=bt("eye",tm);const rm=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],gi=bt("file-text",rm);const nm=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],Ic=bt("house",nm);const sm=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],am=bt("image-plus",sm);const om=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]],im=bt("maximize",om);const lm=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]],cm=bt("minimize",lm);const dm=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],um=bt("pencil-line",dm);const fm=[["path",{d:"M17 3v10",key:"15fgeh"}],["path",{d:"m12.67 5.5 8.66 5",key:"1gpheq"}],["path",{d:"m12.67 10.5 8.66-5",key:"1dkfa6"}],["path",{d:"M9 17a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2v-2z",key:"swwfx4"}]],hm=bt("regex",fm);const mm=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],pm=bt("rotate-cw",mm);const gm=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],bm=bt("scan",gm);const xm=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],_c=bt("send",xm);const vm=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],ym=bt("upload",vm);const wm=[["circle",{cx:"7",cy:"12",r:"3",key:"12clwm"}],["path",{d:"M10 9v6",key:"17i7lo"}],["circle",{cx:"17",cy:"12",r:"3",key:"gl7c2s"}],["path",{d:"M14 7v8",key:"dl84cr"}],["path",{d:"M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1",key:"lt2kga"}]],km=bt("whole-word",wm);function Sm(t,n,s){try{const l=t instanceof HTMLImageElement?t.naturalWidth:t.width,c=t instanceof HTMLImageElement?t.naturalHeight:t.height;if(!l||!c)return Promise.resolve(null);const d=t instanceof HTMLImageElement?1400/Math.max(l,c):Math.min(1,1400/Math.max(l,c)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*d)),h.height=Math.max(1,Math.round(c*d));const m=h.getContext("2d");if(!m)return Promise.resolve(null);const p=getComputedStyle(document.documentElement);if(m.fillStyle=p.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,h.height),m.drawImage(t,0,0,h.width,h.height),s){const g=Math.max(10,Math.min(16,h.width/35));m.font=`${g}px sans-serif`;const u=[];let w="";for(const y of s.split(" "))w&&m.measureText(`${w} ${y}`).width>h.width-20?(u.push(w),w=y):w=w?`${w} ${y}`:y;w&&u.push(w),m.fillStyle=p.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,u.length*(g+4)+12),m.fillStyle=p.getPropertyValue("--foreground").trim()||"black",u.forEach((y,E)=>m.fillText(y,10,8+g+E*(g+4)))}if(n){const g=n.xPercent*h.width/100,u=n.yPercent*h.height/100,w=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=w*1.6;m.strokeStyle=p.getPropertyValue("--primary").trim()||"black",m.lineWidth=Math.max(1,w/3),m.beginPath(),m.arc(g,u,w,0,Math.PI*2),m.stroke(),m.beginPath(),m.moveTo(g-y,u),m.lineTo(g+y,u),m.moveTo(g,u-y),m.lineTo(g,u+y),m.stroke()}return new Promise(g=>h.toBlob(g,"image/png"))}catch{return Promise.resolve(null)}}function jm(t,n,s,l){return[t.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
|
|
3
|
+
`)}function mb(t,n,s){const l=n*Math.PI/360,c=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(t,1e-6)/Math.sin(c)*1.15}async function Rm(t,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(t,n);return}const c=new Date().toISOString(),d=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const p=await s.snapshot;if(!(!p||d.signal.aborted||!l.isCurrent()))return l.upload(new File([p],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),d.signal)})(),new Promise(p=>{h=setTimeout(()=>{d.abort(),p(void 0)},3e3)})])}catch{}finally{clearTimeout(h),d.abort()}l.isCurrent()&&l.insert(m?jm(t,"",c,m):t,n)}function Cm(t){let n=1,s="terminal";for(;;){let l=!1;for(const c of t.values())if(c.name===s){l=!0;break}if(!l)break;s=`terminal-${n}`,n++}return s}const Dc=qf((t,n)=>({sessions:new Map,activeSessionId:null,nextSessionNumber:1,createSession:s=>{const l=$h(),c=Date.now(),d=n().sessions,h=Cm(d),m={id:l,cwd:s,sessionId:null,name:h,customName:!1,createdAt:c,lastActivity:c};return t(p=>{const g=new Map(p.sessions);return g.set(l,m),{sessions:g,activeSessionId:p.activeSessionId??l,nextSessionNumber:p.nextSessionNumber+1}}),l},closeSession:s=>{t(l=>{const c=new Map(l.sessions),d=l.activeSessionId===s;c.delete(s);let h=l.activeSessionId;if(d){const m=Array.from(c.keys());h=m.length>0?m[0]:null}return{sessions:c,activeSessionId:h}})},switchSession:s=>{t(l=>l.sessions.has(s)?{activeSessionId:s}:l)},updateSession:(s,l)=>{t(c=>{const d=c.sessions.get(s);if(!d)return c;const h=new Map(c.sessions);return h.set(s,{...d,...l,lastActivity:Date.now()}),{sessions:h}})},setTerminalSession:(s,l)=>{n().updateSession(s,{sessionId:l.sessionId})},getActiveSession:()=>{const s=n();if(s.activeSessionId)return s.sessions.get(s.activeSessionId)},getSessionCount:()=>n().sessions.size,clearAllSessions:()=>{t({sessions:new Map,activeSessionId:null,nextSessionNumber:1})}}));function Nm(t,n){return t===n||n.endsWith(`/${t}`)||t.endsWith(`/${n}`)}function Fc(t,n){return`${t??""}\0${n}`}function Mm(t,n,s){if(!t||t.length===0||!s)return{explained:0,stale:0};const l=Fc(n,s);let c=0,d=0;for(const h of t){const m=[h.filePath,h.newPath,h.oldPath].filter(g=>typeof g=="string"&&g.length>0);(m.some(g=>Fc(h.repoRoot,g)===l)||m.some(g=>Nm(g,s)))&&(c+=1)}return{explained:c,stale:d}}function $m({status:t}){if(!t)return null;const n=t.stale>0&&t.explained===0;if(!(t.explained>0||t.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(Yh,{size:10}):e.jsx(Rs,{size:10})})}function bi({changeStatus:t,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(t),e.jsx($m,{status:n})]})}const Pd="termdock:right-sidebar:diff-change-list-mode:v1";function Em(t){return t==="list"||t==="tree"}function Lm(){return Ze(Pd,Em)??"tree"}function Am(t){for(const l of t){const c=l.hunk;if(c.oldPath&&c.newPath&&c.oldPath!==c.newPath)return"renamed";if(!c.oldPath&&c.newPath)return"added";if(c.oldPath&&!c.newPath)return"deleted"}const n=t.some(l=>l.hunk.additions>0),s=t.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function Pm(t){const n=new Map;for(const l of t){const c=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};c.items.push(l),c.additions+=l.hunk.additions,c.deletions+=l.hunk.deletions,l.current&&(c.explained+=1),l.stale&&(c.stale+=1),n.set(l.hunk.filePath,c)}const s=Array.from(n.values()).sort((l,c)=>l.filePath.localeCompare(c.filePath));for(const l of s)l.changeType=Am(l.items);return s}function Tm(t){const n=t.filePath.split("/").pop()??t.filePath;return{key:t.key,path:t.filePath,displayName:n,displayDir:t.filePath.includes("/")?t.filePath.slice(0,-n.length-1):"",status:t.changeType,title:t.filePath}}function Im(t,n){const s=t.filter(d=>d.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],c=new Set;for(const[d,h]of s.entries()){const m=h.split(`
|
|
4
4
|
`),p=m.findIndex(w=>w.startsWith("@@ "));if(p<0){l.push(...m);continue}d===0&&l.push(...m.slice(0,p));const g=n[d];let u=p;for(;u>=0&&u<m.length;){const w=m.findIndex((R,M)=>M>u&&R.startsWith("@@ ")),y=w>=0?w:m.length,E=m.slice(u,y),T=E[0]??"",_=g?T===g:!0,U=T||g||E.join(`
|
|
5
5
|
`);_&&!c.has(U)&&(l.push(...E),c.add(U)),u=w}}return l.join(`
|
|
6
|
-
`)}function
|
|
7
|
-
`)[0]??"",Y=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";o.useEffect(()=>()=>{A.current!==null&&window.clearTimeout(A.current),z.current!==null&&window.clearTimeout(z.current)},[]),o.useEffect(()=>{let N=!1;const Z=
|
|
6
|
+
`)}function _m({groups:t,onInsertDiffReference:n}){return t.map(s=>{const l=Im(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),c=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),d=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-d.length-1):"";return{key:s.key,path:s.filePath,absolutePath:c[0]?.repoRoot?`${c[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:c[0]?.repoRoot??null,displayName:d,displayDir:h,diffOverride:l,auditRecords:c,onInsertDiffReference:n}})}function Dm(t,n,s){const l=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const d=t.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const g of l){const u=g.getBoundingClientRect();if(u.bottom<d)continue;const w=Math.abs(u.top-d);w<m&&(h=g,m=w)}const p=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!p||p===n||s(p),p}function Bc({items:t,selectedKey:n,onSelect:s,emptyText:l,mobile:c=!1,backLabel:d="Back",headerTitle:h,headerMeta:m,onClose:p,closeLabel:g="Back",wrap:u=!0,onToggleWrap:w,wrapTitle:y,wrapOnLabel:E="Wrap on",wrapOffLabel:T="Wrap off",desktopLayout:_="split",onInsertDiffReference:U,onReferenceCopied:R,insertedReferenceKey:M,copiedReferenceKey:L,onClearAuditRecord:A,walkthroughs:z=[],onWalkthroughNavigate:D,initialDetailScrollTop:a,onDetailScrollPositionChange:k,scrollToKey:B,scrollToKeyNonce:j,externalSwiperRef:Y,onMobileSlideChange:re}){const{t:se}=xt(),he=o.useMemo(()=>Pm(t),[t]),G=o.useMemo(()=>new Map(he.map(ce=>[ce.key,ce])),[he]),[J,$]=o.useState(()=>Lm()),[F,V]=o.useState(()=>new Set),[te,ie]=o.useState({key:null,nonce:0}),me=he.find(ce=>ce.explained>0||ce.stale>0)?.key??he[0]?.key??null,pe=n&&he.some(ce=>ce.key===n)?n:me,je=o.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:he.map(Tm)}],[he]),N=o.useMemo(()=>_m({groups:he,onInsertDiffReference:U}),[he,U]),Z=o.useRef(me),de=o.useRef(s);Z.current=me,de.current=s,o.useEffect(()=>{!n&&Z.current&&de.current(Z.current)},[n]);const Ee=w?e.jsxs("button",{type:"button",onClick:w,"aria-pressed":u,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:u?E:T})]}):null,ze=ce=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),m&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:m})]}),p&&e.jsxs("button",{type:"button",onClick:p,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[e.jsx(ks,{size:14}),g]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ce,Ee]})]});if(t.length===0){const ce=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!p?ce:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[ze(null),ce]})}const Pe=w?({slideToList:ce})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:ce,children:[e.jsx(ks,{size:14}),d]}),e.jsxs("button",{type:"button",onClick:w,"aria-pressed":u,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:u?E:T})]})]}):void 0;return e.jsx(mi,{mobile:c,desktopLayout:_,backLabel:d,groups:je,selectedKey:pe,mode:J,onModeChange:ce=>{$(ce),ce!=="ai"&>(Pd,ce)},compact:c,collapsedDirectoryKeys:F,onToggleDirectory:ce=>{V(ne=>{const S=new Set(ne);return S.has(ce)?S.delete(ce):S.add(ce),S})},onSelectFile:ce=>{s(ce.key),ie(ne=>({key:ce.key,nonce:ne.nonce+1}))},renderLeading:ce=>{const ne=G.get(ce.key);return e.jsx(bi,{changeStatus:ce.status,auditStatus:ne,renderChangeBadge:S=>e.jsx(ys,{status:S})})},renderTrailing:ce=>{const ne=G.get(ce.key);return ne?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",ne.additions," -",ne.deletions]}):null},renderListHeader:ze,aiContent:({slideToDetail:ce,fullscreen:ne,toggleFullscreen:S})=>z.length>0&&D?e.jsx(jd,{walkthroughs:z,repoRoot:z[0]?.repoRoot,fullscreen:ne,onToggleFullscreen:S,onNavigate:X=>{c&&window.requestAnimationFrame(ce),D(X)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:se("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Pe,externalSwiperRef:Y,onMobileSlideChange:re,detailContainerClassName:c?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:a,scrollToKey:B??te.key,scrollToKeyNonce:B==null?te.nonce:j,onDetailScroll:ce=>{Dm(ce,pe,s),k?.(ce.scrollTop)},files:N,activePane:!0,wrap:u,showScrollHint:!u,renderStreamBadge:(ce,ne)=>{const S=G.get(ne.key);return e.jsx(bi,{changeStatus:ce,auditStatus:S,renderChangeBadge:X=>e.jsx(ys,{status:X})})},onInsertDiffReference:U,onReferenceCopied:R,insertedReferenceKey:M,copiedReferenceKey:L,onClearAuditRecord:A,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function Fm(t){return t.replace(/\/+$/,"")||"/"}function Bm(t){return[...new Set(Array.from(t,Fm))].sort((n,s)=>n.localeCompare(s))}function Om(t){return t==="event-storm"||t==="reconnected"||t==="directory-rescan"||t==="polling-fallback"}function Um(t){let n=null;return{applicableEvents:t.filter(l=>{const c=l.type==="rescan-required"&&!Om(l.reason);return c&&l.reason&&!n&&(n=l.reason),!c}),unavailableReason:n}}const Hm=1400,zm=1200,Td=44,Wm=.7;function Wo(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function xi(t){return`termdock:right-sidebar:context-draft-height:${t}:v1`}function Gm(t){try{const n=window.localStorage.getItem(xi(t)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Td?s:null}catch{return null}}function Oc(t,n){try{n===null?window.localStorage.removeItem(xi(t)):window.localStorage.setItem(xi(t),String(n))}catch{}}function ja(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function qm({value:t,collapsed:n,labels:s,focusRequest:l,insertError:c,autoCollapseAfterSend:d,onChange:h,onCollapsedChange:m,onAutoCollapseAfterSendChange:p,onDisable:g,onClear:u,onInsert:w,onInsertAndSend:y}){const[E,T]=o.useState(null),[_,U]=o.useState(!1),[R,M]=o.useState(()=>Gm(Wo())),L=o.useRef(R),A=o.useRef(null),z=o.useRef(null),D=o.useRef(t),a=o.useRef(null),k=o.useRef(null),B=!!t.trim(),j=t.trim().split(`
|
|
7
|
+
`)[0]??"",Y=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";o.useEffect(()=>()=>{A.current!==null&&window.clearTimeout(A.current),z.current!==null&&window.clearTimeout(z.current)},[]),o.useEffect(()=>{let N=!1;const Z=Wo();return Kf().then(de=>{if(N)return;const Ee=de.contextDraftHeight?.[Z]??null;Oc(Z,Ee),L.current=Ee,M(Ee)}).catch(()=>{}),()=>{N=!0}},[]),o.useEffect(()=>{if(l!==void 0&&l>0){const N=a.current;if(!N)return;ja()||N.focus(),N.setSelectionRange(N.value.length,N.value.length),N.scrollTop=N.scrollHeight}},[l]),o.useEffect(()=>{const N=D.current;D.current=t,!(!n||t.length<=N.length)&&(U(!0),z.current!==null&&window.clearTimeout(z.current),z.current=window.setTimeout(()=>{z.current=null,U(!1)},zm))},[t,n]),o.useEffect(()=>{if(n)return;const N=a.current;N&&(N.style.height=R!==null?`${R}px`:"")},[t,n,R]),o.useEffect(()=>{if(n)return;const N=a.current;!N||document.activeElement===N||(N.scrollTop=N.scrollHeight)},[t,n]),o.useEffect(()=>{if(n||ja())return;const N=a.current;!N||document.activeElement===N||(N.focus(),N.setSelectionRange(N.value.length,N.value.length))},[n]);const re=o.useRef(null);o.useLayoutEffect(()=>{if(!ja())return;const N=window.visualViewport;if(!N)return;const Z=()=>{const de=re.current;if(!de)return;if(N.height>=window.innerHeight*.75){de.style.transform="";return}const Ee=de.getBoundingClientRect(),ze=Math.round(N.height-Ee.bottom);de.style.transform=ze!==0?`translateY(${ze}px)`:""};return Z(),N.addEventListener("resize",Z),N.addEventListener("scroll",Z),()=>{N.removeEventListener("resize",Z),N.removeEventListener("scroll",Z),re.current&&(re.current.style.transform="")}},[n]);const se=N=>{T(N),A.current!==null&&window.clearTimeout(A.current),A.current=window.setTimeout(()=>{A.current=null,T(null)},Hm)},he=N=>{m(!1),ja()&&window.requestAnimationFrame(()=>{const Z=a.current;if(!Z)return;Z.focus();const de=Z.value.length;Z.setSelectionRange(de,de),window.requestAnimationFrame(()=>{Z.setSelectionRange(de,de)})})},G=()=>{w(),se("inserted")},J=()=>{B&&(y(),se("sent"))},$=N=>{if(N.key==="Escape"){N.preventDefault(),m(!0);return}N.key!=="Enter"||!N.metaKey&&!N.ctrlKey||(N.preventDefault(),J())},F=N=>{N.preventDefault()},V=N=>{N.preventDefault();const Z=a.current;Z&&(k.current={startY:N.clientY,startHeight:Z.getBoundingClientRect().height},N.currentTarget.setPointerCapture?.(N.pointerId))},te=N=>{const Z=k.current;if(!Z)return;const de=window.visualViewport?.height??window.innerHeight,Ee=Math.round(Math.min(Math.max(Z.startHeight+(Z.startY-N.clientY),Td),de*Wm));L.current=Ee,M(Ee)},ie=N=>{const Z=Wo();Oc(Z,N),Vf({contextDraftHeight:{[Z]:N}}).catch(()=>{})},me=()=>{k.current&&(k.current=null,L.current!==null&&ie(L.current))},pe=()=>{L.current=null,M(null),ie(null)},je=t.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(t.length)});return n?e.jsx("section",{ref:re,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:e.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[e.jsxs("button",{type:"button",onClick:()=>he(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":s.expand,title:s.expand,children:[e.jsx(Eh,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${c?"text-destructive":_?"text-primary":B?"text-foreground/80":"text-muted-foreground/50"}`,children:c??(_?s.appended:B?j:s.title)})]}),je,e.jsx("button",{type:"button",onClick:J,disabled:!B,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${B?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:E==="sent"?e.jsx(di,{size:12}):e.jsx(_c,{size:12})})]})}):e.jsxs("section",{ref:re,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:V,onPointerMove:te,onPointerUp:me,onPointerCancel:me,onDoubleClick:pe,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:F,onClick:()=>m(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Ss,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:s.title}),je]}),e.jsx("button",{type:"button",role:"switch","aria-checked":d,onPointerDown:F,onClick:()=>p(!d),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${d?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${d?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:F,onClick:g,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Dt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:a,value:t,onChange:N=>h(N.target.value),onKeyDown:$,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:F,onClick:u,disabled:!B,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(Pa,{size:11})}),c?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:c}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:G,disabled:!B,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(Lh,{size:11}),e.jsx("span",{children:E==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:J,disabled:!B,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${s.insertAndSend} · ${Y}`,children:[E==="sent"?e.jsx(di,{size:11}):e.jsx(_c,{size:11}),e.jsx("span",{children:E==="sent"?s.sent:s.send})]})]})]})})]})}function Km(t,n){const s=n.trim();if(!s)return t;if(!t.trim())return s;const l=t.endsWith(`
|
|
8
8
|
|
|
9
9
|
`)?"":t.endsWith(`
|
|
10
10
|
`)?`
|
|
11
11
|
`:`
|
|
12
12
|
|
|
13
|
-
`;return`${t}${l}${s}`}function Km(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const xi="termdock:right-sidebar:html-view-mode-by-file:v1";function Vm(t){return t==="preview"||t==="source"}function Id(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(Vm)}function _d(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Uc(t,n){const s=_d(t,n);return s?Ze(xi,Id)?.[s]??"source":"source"}function Ym(t,n,s){const l=_d(t,n);if(!l)return;const c=Ze(xi,Id)??{};gt(xi,{...c,[l]:s})}function Hc(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}function Ai(t,n){const[s,l]=o.useState(()=>!!navigator.serviceWorker?.controller);return o.useEffect(()=>{if(!Hc(t)||s)return;const c=navigator.serviceWorker,d=()=>l(!!c?.controller);c?.addEventListener("controllerchange",d),d();const h=window.setTimeout(()=>{c?.controller||n?.()},1e4);return()=>{c?.removeEventListener("controllerchange",d),window.clearTimeout(h)}},[t,s,n]),Hc(t)&&!s?void 0:t}function Wo(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),c=n%60,d=String(l).padStart(2,"0"),h=String(c).padStart(2,"0");return s>0?`${s}:${d}:${h}`:`${d}:${h}`}function Xm(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const Jm=350,Qm=12,Zm=90;function ep({url:t,onLoadError:n}){const s=Ai(t,n),{t:l}=xt(),c=o.useRef(null),d=o.useRef(null),h=o.useRef(null),m=o.useRef(null),p=o.useRef(!1),g=o.useRef(null),u=o.useRef(null),w=o.useRef(0),y=o.useRef(!1),E=o.useRef(!1),T=o.useRef(!1),_=o.useRef(null),U=o.useRef(null),R=o.useRef(!1),M=o.useRef(1),L=o.useRef(!1),[A,z]=o.useState(0),[D,a]=o.useState(0),[k,B]=o.useState(!1),[j,Y]=o.useState(!1),[re,se]=o.useState(null),[he,G]=o.useState(!1),[J,$]=o.useState(0),[F,V]=o.useState(!1),[te,ie]=o.useState({width:0,height:0}),me=o.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),pe=o.useCallback(()=>{if(me(),U.current=null,!R.current)return!1;const W=h.current;return W&&(W.playbackRate=M.current),R.current=!1,G(!1),!0},[me]);o.useEffect(()=>()=>{g.current!==null&&cancelAnimationFrame(g.current),u.current!==null&&clearTimeout(u.current),me();const W=h.current;W&&R.current&&(W.playbackRate=M.current)},[me]),o.useEffect(()=>{const W=d.current;if(!W||typeof ResizeObserver>"u")return;const K=new ResizeObserver(([Se])=>{Se&&ie({width:Se.contentRect.width,height:Se.contentRect.height})});return K.observe(W),()=>K.disconnect()},[]),o.useEffect(()=>{const W=()=>V(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",W),()=>document.removeEventListener("fullscreenchange",W)},[]);const je=o.useCallback((W,K=!1)=>{const Se=h.current;if(!Se)return!1;const Re=Number.isFinite(Se.duration)?Se.duration:W,ot=Math.min(Math.max(W,0),Re);if(a(ot),Math.abs(Se.currentTime-ot)<1/120)return!1;const Ke=Se.fastSeek;return K&&typeof Ke=="function"?Ke.call(Se,ot):Se.currentTime=ot,!0},[]),N=o.useCallback(()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null;const W=h.current;if(!W||!y.current||E.current||W.seeking)return;const K=T.current;T.current=!1,E.current=je(w.current,!K)}))},[je]),Z=o.useCallback(W=>{const K=m.current,Se=h.current;if(!K||!Se)return;const Re=K.getBoundingClientRect(),ot=Xm(W,Re,Se.duration);w.current=ot,se(ot),T.current=!1,N(),u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,T.current=!0,N()},Zm)},[N]),de=o.useCallback(()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),u.current!==null&&(clearTimeout(u.current),u.current=null),T.current=!1,E.current=!1,je(w.current)},[je]),Ee=o.useCallback(W=>{const K=h.current;if(!(!K||!Number.isFinite(K.duration)||K.duration<=0)){p.current=!K.paused,K.pause(),y.current=!0,Y(!0);try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}Z(W.clientX)}},[Z]),ze=o.useCallback(()=>{y.current=!1,de(),Y(!1),se(null);const W=h.current;W&&p.current&&!W.ended&&W.play().catch(()=>{}),p.current=!1},[de]),Pe=o.useCallback(()=>{const W=h.current;if(W){if(L.current){L.current=!1;return}W.paused?W.play().catch(()=>{}):W.pause()}},[]),ce=o.useCallback(W=>{const K=h.current;!K||K.paused||W.button!==0||(me(),U.current={id:W.pointerId,x:W.clientX,y:W.clientY},_.current=setTimeout(()=>{_.current=null,M.current=K.playbackRate,K.playbackRate=2,R.current=!0,G(!0)},Jm))},[me]),ne=o.useCallback(W=>{const K=U.current;!K||K.id!==W.pointerId||R.current||Math.hypot(W.clientX-K.x,W.clientY-K.y)>Qm&&(me(),U.current=null)},[me]),S=o.useCallback(()=>{pe()&&(L.current=!0)},[pe]);o.useEffect(()=>(window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S),window.addEventListener("blur",S),()=>{window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),window.removeEventListener("blur",S)}),[S]);const X=o.useCallback(async()=>{const W=c.current,K=h.current;if(!(!W||!K))try{document.fullscreenElement===W?await document.exitFullscreen():W.requestFullscreen?await W.requestFullscreen():K.webkitEnterFullscreen?.()}catch{K.webkitEnterFullscreen?.()}},[]),ke=o.useCallback(()=>$(W=>(W+90)%360),[]),xe=o.useCallback(W=>{const K=h.current;if(!K||!Number.isFinite(K.duration))return;const Se=W.shiftKey?10:5;let Re=null;W.key==="ArrowLeft"?Re=K.currentTime-Se:W.key==="ArrowRight"?Re=K.currentTime+Se:W.key==="Home"?Re=0:W.key==="End"&&(Re=K.duration),Re!==null&&(W.preventDefault(),je(Re))},[je]),De=j&&re!==null?re:D,ue=A>0?Math.min(1,Math.max(0,De/A)):0,Le=(J===90||J===270)&&te.width>0&&te.height>0?{width:`${te.height}px`,height:`${te.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:c,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":J,children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...Le,transform:`translate(-50%, -50%) rotate(${J}deg)`},src:s,preload:"auto",playsInline:!0,onClick:Pe,onPointerDown:ce,onPointerMove:ne,onPointerUp:S,onPointerCancel:S,onContextMenu:W=>{R.current&&W.preventDefault()},onPlay:()=>B(!0),onPause:()=>B(!1),onTimeUpdate:W=>a(W.currentTarget.currentTime),onSeeked:W=>{const K=W.currentTarget;if(a(K.currentTime),E.current=!1,!y.current)return;const Se=K.requestVideoFrameCallback;typeof Se=="function"?Se.call(K,()=>{y.current&&N()}):requestAnimationFrame(()=>{y.current&&N()})},onLoadedMetadata:W=>z(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onDurationChange:W=>z(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),he&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed")}),j&&re!==null&&e.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${ue*100}%`},"data-testid":"file-preview-video-scrub-time",children:Wo(re)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${zh}`,[Wh]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Pe,"aria-label":l(k?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(k?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:k?e.jsx(Lh,{size:14}):e.jsx(Ah,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(A),"aria-valuenow":Math.floor(De),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:Ee,onPointerMove:W=>{j&&Z(W.clientX)},onPointerUp:ze,onPointerCancel:ze,onKeyDown:xe,children:[e.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),e.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${ue*100}%`}}),e.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${ue*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Wo(De)," / ",Wo(A)]}),e.jsx("button",{type:"button",onClick:ke,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(mm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{X()},"aria-label":l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:F?e.jsx(lm,{size:14}):e.jsx(om,{size:14})})]})})]})}function tp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function Ga({anchor:t,children:n,disabled:s=!1,onClick:l,title:c}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:d=>{d.stopPropagation(),l()},title:c,style:tp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Da,{size:11}),n]})}function rp(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const c=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(c)||c<=0)return null;const d=l.width*c,h=l.height*c,m=s.left+(s.width-d)/2,p=s.top+(s.height-h)/2,g=t-m,u=n-p;if(g<0||u<0||g>d||u>h)return null;const w=g/d*100,y=u/h*100;return{x:l.x+l.width*w/100,y:l.y+l.height*y/100,xPercent:w,yPercent:y}}function np(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function sp(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const c of Array.from(l.attributes)){const d=c.name.toLowerCase(),h=c.value.trim();(d.startsWith("on")||(d==="href"||d.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(c.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function ap(t,n,s){let l=null;for(const c of Array.from(t.querySelectorAll("text"))){const d=(c.textContent??"").replace(/\s+/g," ").trim();if(!d)continue;const h=Number(c.getAttribute("x")),m=Number(c.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const p=Math.hypot(h-n,m-s);(!l||p<l.distance)&&(l={text:d,distance:p})}return l?.text.slice(0,120)}function Dd({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const c=o.useRef(null),d=o.useRef(null),[h,m]=o.useState(null),[p,g]=o.useState(null),[u,w]=o.useState(1),[y,E]=o.useState(!1),[T,_]=o.useState(null),U=o.useRef(new Map),R=o.useRef(null),M=o.useRef(!1),L=o.useRef(null),A=o.useRef(u);A.current=u,o.useEffect(()=>{const $=new AbortController;return m(null),g(null),_(null),w(1),fetch(t,{signal:$.signal}).then(F=>F.text()).then(F=>m(sp(F))).catch(F=>{$.signal.aborted||g(F instanceof Error?F.message:"SVG preview failed")}),()=>$.abort()},[t]),o.useEffect(()=>{if(!y)return;const $=F=>{F.key==="Escape"&&E(!1)};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[y]),o.useLayoutEffect(()=>{const $=d.current,F=$?.querySelector("[data-svg-document] > svg");if(!$||!F)return;let V;try{V=F.getBBox()}catch{return}if(!V.width||!V.height)return;const te=Math.max(2,Math.min(V.width,V.height)*.025);F.setAttribute("viewBox",`${V.x-te} ${V.y-te} ${V.width+2*te} ${V.height+2*te}`),F.style.width=`${u*100}%`,F.style.height=`${u*100}%`,F.style.minWidth=`${u*100}%`,F.style.minHeight=`${u*100}%`,F.style.display="block"},[h,u]);const z=o.useMemo(()=>T?np(n,s,T):null,[n,T,s]),D=$=>{if(M.current){M.current=!1;return}const F=d.current,V=F?.querySelector("[data-svg-document] > svg"),te=c.current;if(!F||!V||!te)return;const ie=V.viewBox.baseVal,me=rp($.clientX,$.clientY,V.getBoundingClientRect(),ie);if(!me)return;const pe=te.getBoundingClientRect();_({...me,nearestText:ap(V,me.x,me.y),stageX:$.clientX-pe.left,stageY:$.clientY-pe.top,stageXPercent:($.clientX-pe.left)/pe.width*100,stageYPercent:($.clientY-pe.top)/pe.height*100})},a=$=>Math.max(1,Math.min(12,$)),k=($,F)=>{const V=a(F),te=$.querySelector("[data-svg-document] > svg");if(!te)return V;const ie=`${V*100}%`;return te.style.width=ie,te.style.height=ie,te.style.minWidth=ie,te.style.minHeight=ie,A.current=V,V},B=($,F,V,te)=>{const ie=A.current,me=$.getBoundingClientRect(),pe=V-me.left,je=te-me.top,N=($.scrollLeft+pe)/ie,Z=($.scrollTop+je)/ie,de=k($,F);return $.scrollLeft=N*de-pe,$.scrollTop=Z*de-je,de},j=()=>{const $=Array.from(U.current.values());return $.length>=2?Math.hypot($[0].x-$[1].x,$[0].y-$[1].y):0},Y=$=>{if($.pointerType==="mouse"&&$.button!==0)return;const F=d.current;F&&(U.current.set($.pointerId,{x:$.clientX,y:$.clientY}),F.setPointerCapture?.($.pointerId),U.current.size>=2?(R.current={kind:"pinch",startX:$.clientX,startY:$.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startDistance:j(),startZoom:A.current,moved:!1},M.current=!0):A.current>1&&(R.current={kind:"pan",startX:$.clientX,startY:$.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:A.current,moved:!1}))},re=$=>{if(!U.current.has($.pointerId))return;U.current.set($.pointerId,{x:$.clientX,y:$.clientY});const F=d.current,V=R.current;if(!(!F||!V)){if(U.current.size>=2&&V.kind==="pinch"){const te=j();if(!V.startDistance||!te)return;const ie=a(V.startZoom*te/V.startDistance);if(Math.abs(ie-A.current)<.01)return;const me=Array.from(U.current.values()),pe=(me[0].x+me[1].x)/2,je=(me[0].y+me[1].y)/2;V.moved=!0,M.current=!0,B(F,ie,pe,je),$.preventDefault();return}if(V.kind==="pan"&&U.current.size===1){const te=$.clientX-V.startX,ie=$.clientY-V.startY;if(!V.moved&&Math.hypot(te,ie)<6)return;V.moved=!0,M.current=!0,F.scrollLeft=V.startScrollLeft-te,F.scrollTop=V.startScrollTop-ie,$.preventDefault()}}},se=$=>{const F=d.current,V=R.current,te=U.current.size===1&&!V?.moved;U.current.delete($.pointerId);try{F?.releasePointerCapture?.($.pointerId)}catch{}if(U.current.size===1&&V?.kind==="pinch"){const pe=Array.from(U.current.values())[0];R.current=F?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:A.current,moved:!1}:null;return}if(U.current.size>0||(R.current=null,V?.kind==="pinch"&&w(A.current),!te||M.current))return;const ie=Date.now(),me=L.current;me&&ie-me.time<350&&Math.hypot($.clientX-me.x,$.clientY-me.y)<24?(L.current=null,M.current=!0,w(pe=>pe>1?1:2.5)):L.current={time:ie,x:$.clientX,y:$.clientY}},he=$=>{if(!$.ctrlKey&&!$.metaKey)return;const F=d.current;if(!F)return;$.preventDefault();const V=B(F,A.current*Math.exp(-$.deltaY*.01),$.clientX,$.clientY);w(V)},G=()=>{w(1),A.current=1,d.current&&(d.current.scrollLeft=0,d.current.scrollTop=0)},J=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:d,role:"button",tabIndex:0,onClick:D,onDoubleClick:$=>{$.preventDefault(),w(F=>F>1?1:2.5)},onPointerDown:Y,onPointerMove:re,onPointerUp:se,onPointerCancel:se,onWheel:he,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:p?e.jsx("div",{className:"p-4 text-sm text-destructive",children:p}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),T&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:T.stageX,top:T.stageY}}),T&&z&&e.jsx(Ga,{anchor:{xPercent:T.stageXPercent,yPercent:T.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(z,`svg:${T.x.toFixed(2)}:${T.y.toFixed(2)}`),_(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[u>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:$=>{$.stopPropagation(),G()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(gm,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:$=>{$.stopPropagation(),E(F=>!F)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(Rd,{size:14}):e.jsx(Cd,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:T?`SVG (${T.x.toFixed(2)}, ${T.y.toFixed(2)}) · ${T.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?zr.createPortal(J,document.body):J}function Ta(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function op(t,n,s,l){const c=[`电子标注: ${t}`,`视图: ${Ta(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(c.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&c.push(`显示层: ${l.layer}`),l.nearest)){const d=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");c.push(`最近对象: ${l.nearest.label}${d?`(${d})`:""}`)}return`"${c.join(" / ")}"`}function ip({blobUrl:t,filePath:n,view:s,board:l,onViewChange:c,onInsertAnnotation:d,onRefresh:h,interactive3d:m}){const{t:p}=xt(),g=o.useRef(null),u=o.useRef(null),w=o.useRef(null),[y,E]=o.useState(null),[T,_]=o.useState(!1);o.useEffect(()=>(w.current?.abort(),E(null),_(!1),()=>w.current?.abort()),[t,s]);const U=o.useMemo(()=>y?op(n,s,y,y.inspection):null,[n,y,s]),R=L=>{const A=g.current,z=u.current;if(!A||!z||!z.naturalWidth||!z.naturalHeight)return;const D=A.getBoundingClientRect(),a=z.getBoundingClientRect(),k=Math.min(a.width/z.naturalWidth,a.height/z.naturalHeight),B=z.naturalWidth*k,j=z.naturalHeight*k,Y=a.left+(a.width-B)/2,re=a.top+(a.height-j)/2,se=L.clientX-Y,he=L.clientY-re;if(se<0||he<0||se>B||he>j)return;const G={xPercent:Math.max(0,Math.min(100,se/B*100)),yPercent:Math.max(0,Math.min(100,he/j*100)),stageXPercent:(L.clientX-D.left)/D.width*100,stageYPercent:(L.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(E(G),w.current?.abort(),!G.inspecting)return;const J=new AbortController;w.current=J,Yf(n,s,G.xPercent,G.yPercent,J.signal).then($=>E(F=>F===G?{...F,inspection:$,inspecting:!1}:F)).catch(()=>{J.signal.aborted||E($=>$===G?{...$,inspection:{available:!1},inspecting:!1}:$)})},M=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:M.map(L=>e.jsx("button",{type:"button",onClick:()=>c(L),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${L===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ta(L)},L))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:p("rightSidebar.edaRefresh"),"aria-label":p("rightSidebar.edaRefresh"),children:e.jsx(ui,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:g,role:"button",tabIndex:0,onClick:R,onKeyDown:L=>{L.key!=="Enter"&&L.key!==" "||(L.preventDefault(),E({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:p("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:u,src:t,alt:`${n} ${Ta(s)}`,onLoad:()=>_(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${T?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&U&&e.jsx(Ga,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:p("rightSidebar.edaInsertAnnotation"),onClick:()=>{d?.(U,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:u.current?km(u.current,y):Promise.resolve(null)}),E(null)},children:p("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?p("rightSidebar.edaInspecting"):y.inspection?.available?p("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??p("rightSidebar.edaNoNearbyObject")}):p("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):p("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Dd,{blobUrl:t,filePath:n,viewLabel:Ta(s),onInsertAnnotation:d})})]})}function lp(t){const n=[];let s=[],l="",c=!1;for(let d=0;d<t.length;d+=1){const h=t[d];c?h==='"'&&t[d+1]==='"'?(l+='"',d+=1):h==='"'?c=!1:l+=h:h==='"'?c=!0:h===","?(s.push(l),l=""):h===`
|
|
14
|
-
`?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function
|
|
13
|
+
`;return`${t}${l}${s}`}function Vm(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const vi="termdock:right-sidebar:html-view-mode-by-file:v1";function Ym(t){return t==="preview"||t==="source"}function Id(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(Ym)}function _d(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Uc(t,n){const s=_d(t,n);return s?Ze(vi,Id)?.[s]??"source":"source"}function Xm(t,n,s){const l=_d(t,n);if(!l)return;const c=Ze(vi,Id)??{};gt(vi,{...c,[l]:s})}function Hc(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}function Pi(t,n){const[s,l]=o.useState(()=>!!navigator.serviceWorker?.controller);return o.useEffect(()=>{if(!Hc(t)||s)return;const c=navigator.serviceWorker,d=()=>l(!!c?.controller);c?.addEventListener("controllerchange",d),d();const h=window.setTimeout(()=>{c?.controller||n?.()},1e4);return()=>{c?.removeEventListener("controllerchange",d),window.clearTimeout(h)}},[t,s,n]),Hc(t)&&!s?void 0:t}function Go(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),c=n%60,d=String(l).padStart(2,"0"),h=String(c).padStart(2,"0");return s>0?`${s}:${d}:${h}`:`${d}:${h}`}function Jm(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const Qm=350,Zm=12,ep=90;function tp({url:t,onLoadError:n}){const s=Pi(t,n),{t:l}=xt(),c=o.useRef(null),d=o.useRef(null),h=o.useRef(null),m=o.useRef(null),p=o.useRef(!1),g=o.useRef(null),u=o.useRef(null),w=o.useRef(0),y=o.useRef(!1),E=o.useRef(!1),T=o.useRef(!1),_=o.useRef(null),U=o.useRef(null),R=o.useRef(!1),M=o.useRef(1),L=o.useRef(!1),[A,z]=o.useState(0),[D,a]=o.useState(0),[k,B]=o.useState(!1),[j,Y]=o.useState(!1),[re,se]=o.useState(null),[he,G]=o.useState(!1),[J,$]=o.useState(0),[F,V]=o.useState(!1),[te,ie]=o.useState({width:0,height:0}),me=o.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),pe=o.useCallback(()=>{if(me(),U.current=null,!R.current)return!1;const W=h.current;return W&&(W.playbackRate=M.current),R.current=!1,G(!1),!0},[me]);o.useEffect(()=>()=>{g.current!==null&&cancelAnimationFrame(g.current),u.current!==null&&clearTimeout(u.current),me();const W=h.current;W&&R.current&&(W.playbackRate=M.current)},[me]),o.useEffect(()=>{const W=d.current;if(!W||typeof ResizeObserver>"u")return;const K=new ResizeObserver(([Se])=>{Se&&ie({width:Se.contentRect.width,height:Se.contentRect.height})});return K.observe(W),()=>K.disconnect()},[]),o.useEffect(()=>{const W=()=>V(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",W),()=>document.removeEventListener("fullscreenchange",W)},[]);const je=o.useCallback((W,K=!1)=>{const Se=h.current;if(!Se)return!1;const Re=Number.isFinite(Se.duration)?Se.duration:W,ot=Math.min(Math.max(W,0),Re);if(a(ot),Math.abs(Se.currentTime-ot)<1/120)return!1;const Ke=Se.fastSeek;return K&&typeof Ke=="function"?Ke.call(Se,ot):Se.currentTime=ot,!0},[]),N=o.useCallback(()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null;const W=h.current;if(!W||!y.current||E.current||W.seeking)return;const K=T.current;T.current=!1,E.current=je(w.current,!K)}))},[je]),Z=o.useCallback(W=>{const K=m.current,Se=h.current;if(!K||!Se)return;const Re=K.getBoundingClientRect(),ot=Jm(W,Re,Se.duration);w.current=ot,se(ot),T.current=!1,N(),u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,T.current=!0,N()},ep)},[N]),de=o.useCallback(()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),u.current!==null&&(clearTimeout(u.current),u.current=null),T.current=!1,E.current=!1,je(w.current)},[je]),Ee=o.useCallback(W=>{const K=h.current;if(!(!K||!Number.isFinite(K.duration)||K.duration<=0)){p.current=!K.paused,K.pause(),y.current=!0,Y(!0);try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}Z(W.clientX)}},[Z]),ze=o.useCallback(()=>{y.current=!1,de(),Y(!1),se(null);const W=h.current;W&&p.current&&!W.ended&&W.play().catch(()=>{}),p.current=!1},[de]),Pe=o.useCallback(()=>{const W=h.current;if(W){if(L.current){L.current=!1;return}W.paused?W.play().catch(()=>{}):W.pause()}},[]),ce=o.useCallback(W=>{const K=h.current;!K||K.paused||W.button!==0||(me(),U.current={id:W.pointerId,x:W.clientX,y:W.clientY},_.current=setTimeout(()=>{_.current=null,M.current=K.playbackRate,K.playbackRate=2,R.current=!0,G(!0)},Qm))},[me]),ne=o.useCallback(W=>{const K=U.current;!K||K.id!==W.pointerId||R.current||Math.hypot(W.clientX-K.x,W.clientY-K.y)>Zm&&(me(),U.current=null)},[me]),S=o.useCallback(()=>{pe()&&(L.current=!0)},[pe]);o.useEffect(()=>(window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S),window.addEventListener("blur",S),()=>{window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),window.removeEventListener("blur",S)}),[S]);const X=o.useCallback(async()=>{const W=c.current,K=h.current;if(!(!W||!K))try{document.fullscreenElement===W?await document.exitFullscreen():W.requestFullscreen?await W.requestFullscreen():K.webkitEnterFullscreen?.()}catch{K.webkitEnterFullscreen?.()}},[]),ke=o.useCallback(()=>$(W=>(W+90)%360),[]),xe=o.useCallback(W=>{const K=h.current;if(!K||!Number.isFinite(K.duration))return;const Se=W.shiftKey?10:5;let Re=null;W.key==="ArrowLeft"?Re=K.currentTime-Se:W.key==="ArrowRight"?Re=K.currentTime+Se:W.key==="Home"?Re=0:W.key==="End"&&(Re=K.duration),Re!==null&&(W.preventDefault(),je(Re))},[je]),De=j&&re!==null?re:D,ue=A>0?Math.min(1,Math.max(0,De/A)):0,Le=(J===90||J===270)&&te.width>0&&te.height>0?{width:`${te.height}px`,height:`${te.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:c,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":J,children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...Le,transform:`translate(-50%, -50%) rotate(${J}deg)`},src:s,preload:"auto",playsInline:!0,onClick:Pe,onPointerDown:ce,onPointerMove:ne,onPointerUp:S,onPointerCancel:S,onContextMenu:W=>{R.current&&W.preventDefault()},onPlay:()=>B(!0),onPause:()=>B(!1),onTimeUpdate:W=>a(W.currentTarget.currentTime),onSeeked:W=>{const K=W.currentTarget;if(a(K.currentTime),E.current=!1,!y.current)return;const Se=K.requestVideoFrameCallback;typeof Se=="function"?Se.call(K,()=>{y.current&&N()}):requestAnimationFrame(()=>{y.current&&N()})},onLoadedMetadata:W=>z(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onDurationChange:W=>z(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),he&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed")}),j&&re!==null&&e.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${ue*100}%`},"data-testid":"file-preview-video-scrub-time",children:Go(re)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Wh}`,[Gh]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Pe,"aria-label":l(k?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(k?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:k?e.jsx(Ah,{size:14}):e.jsx(Ph,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(A),"aria-valuenow":Math.floor(De),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:Ee,onPointerMove:W=>{j&&Z(W.clientX)},onPointerUp:ze,onPointerCancel:ze,onKeyDown:xe,children:[e.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),e.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${ue*100}%`}}),e.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${ue*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Go(De)," / ",Go(A)]}),e.jsx("button",{type:"button",onClick:ke,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(pm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{X()},"aria-label":l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:F?e.jsx(cm,{size:14}):e.jsx(im,{size:14})})]})})]})}function rp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function Ga({anchor:t,children:n,disabled:s=!1,onClick:l,title:c}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:d=>{d.stopPropagation(),l()},title:c,style:rp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Da,{size:11}),n]})}function np(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const c=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(c)||c<=0)return null;const d=l.width*c,h=l.height*c,m=s.left+(s.width-d)/2,p=s.top+(s.height-h)/2,g=t-m,u=n-p;if(g<0||u<0||g>d||u>h)return null;const w=g/d*100,y=u/h*100;return{x:l.x+l.width*w/100,y:l.y+l.height*y/100,xPercent:w,yPercent:y}}function sp(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function ap(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const c of Array.from(l.attributes)){const d=c.name.toLowerCase(),h=c.value.trim();(d.startsWith("on")||(d==="href"||d.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(c.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function op(t,n,s){let l=null;for(const c of Array.from(t.querySelectorAll("text"))){const d=(c.textContent??"").replace(/\s+/g," ").trim();if(!d)continue;const h=Number(c.getAttribute("x")),m=Number(c.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const p=Math.hypot(h-n,m-s);(!l||p<l.distance)&&(l={text:d,distance:p})}return l?.text.slice(0,120)}function Dd({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const c=o.useRef(null),d=o.useRef(null),[h,m]=o.useState(null),[p,g]=o.useState(null),[u,w]=o.useState(1),[y,E]=o.useState(!1),[T,_]=o.useState(null),U=o.useRef(new Map),R=o.useRef(null),M=o.useRef(!1),L=o.useRef(null),A=o.useRef(u);A.current=u,o.useEffect(()=>{const $=new AbortController;return m(null),g(null),_(null),w(1),fetch(t,{signal:$.signal}).then(F=>F.text()).then(F=>m(ap(F))).catch(F=>{$.signal.aborted||g(F instanceof Error?F.message:"SVG preview failed")}),()=>$.abort()},[t]),o.useEffect(()=>{if(!y)return;const $=F=>{F.key==="Escape"&&E(!1)};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[y]),o.useLayoutEffect(()=>{const $=d.current,F=$?.querySelector("[data-svg-document] > svg");if(!$||!F)return;let V;try{V=F.getBBox()}catch{return}if(!V.width||!V.height)return;const te=Math.max(2,Math.min(V.width,V.height)*.025);F.setAttribute("viewBox",`${V.x-te} ${V.y-te} ${V.width+2*te} ${V.height+2*te}`),F.style.width=`${u*100}%`,F.style.height=`${u*100}%`,F.style.minWidth=`${u*100}%`,F.style.minHeight=`${u*100}%`,F.style.display="block"},[h,u]);const z=o.useMemo(()=>T?sp(n,s,T):null,[n,T,s]),D=$=>{if(M.current){M.current=!1;return}const F=d.current,V=F?.querySelector("[data-svg-document] > svg"),te=c.current;if(!F||!V||!te)return;const ie=V.viewBox.baseVal,me=np($.clientX,$.clientY,V.getBoundingClientRect(),ie);if(!me)return;const pe=te.getBoundingClientRect();_({...me,nearestText:op(V,me.x,me.y),stageX:$.clientX-pe.left,stageY:$.clientY-pe.top,stageXPercent:($.clientX-pe.left)/pe.width*100,stageYPercent:($.clientY-pe.top)/pe.height*100})},a=$=>Math.max(1,Math.min(12,$)),k=($,F)=>{const V=a(F),te=$.querySelector("[data-svg-document] > svg");if(!te)return V;const ie=`${V*100}%`;return te.style.width=ie,te.style.height=ie,te.style.minWidth=ie,te.style.minHeight=ie,A.current=V,V},B=($,F,V,te)=>{const ie=A.current,me=$.getBoundingClientRect(),pe=V-me.left,je=te-me.top,N=($.scrollLeft+pe)/ie,Z=($.scrollTop+je)/ie,de=k($,F);return $.scrollLeft=N*de-pe,$.scrollTop=Z*de-je,de},j=()=>{const $=Array.from(U.current.values());return $.length>=2?Math.hypot($[0].x-$[1].x,$[0].y-$[1].y):0},Y=$=>{if($.pointerType==="mouse"&&$.button!==0)return;const F=d.current;F&&(U.current.set($.pointerId,{x:$.clientX,y:$.clientY}),F.setPointerCapture?.($.pointerId),U.current.size>=2?(R.current={kind:"pinch",startX:$.clientX,startY:$.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startDistance:j(),startZoom:A.current,moved:!1},M.current=!0):A.current>1&&(R.current={kind:"pan",startX:$.clientX,startY:$.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:A.current,moved:!1}))},re=$=>{if(!U.current.has($.pointerId))return;U.current.set($.pointerId,{x:$.clientX,y:$.clientY});const F=d.current,V=R.current;if(!(!F||!V)){if(U.current.size>=2&&V.kind==="pinch"){const te=j();if(!V.startDistance||!te)return;const ie=a(V.startZoom*te/V.startDistance);if(Math.abs(ie-A.current)<.01)return;const me=Array.from(U.current.values()),pe=(me[0].x+me[1].x)/2,je=(me[0].y+me[1].y)/2;V.moved=!0,M.current=!0,B(F,ie,pe,je),$.preventDefault();return}if(V.kind==="pan"&&U.current.size===1){const te=$.clientX-V.startX,ie=$.clientY-V.startY;if(!V.moved&&Math.hypot(te,ie)<6)return;V.moved=!0,M.current=!0,F.scrollLeft=V.startScrollLeft-te,F.scrollTop=V.startScrollTop-ie,$.preventDefault()}}},se=$=>{const F=d.current,V=R.current,te=U.current.size===1&&!V?.moved;U.current.delete($.pointerId);try{F?.releasePointerCapture?.($.pointerId)}catch{}if(U.current.size===1&&V?.kind==="pinch"){const pe=Array.from(U.current.values())[0];R.current=F?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:A.current,moved:!1}:null;return}if(U.current.size>0||(R.current=null,V?.kind==="pinch"&&w(A.current),!te||M.current))return;const ie=Date.now(),me=L.current;me&&ie-me.time<350&&Math.hypot($.clientX-me.x,$.clientY-me.y)<24?(L.current=null,M.current=!0,w(pe=>pe>1?1:2.5)):L.current={time:ie,x:$.clientX,y:$.clientY}},he=$=>{if(!$.ctrlKey&&!$.metaKey)return;const F=d.current;if(!F)return;$.preventDefault();const V=B(F,A.current*Math.exp(-$.deltaY*.01),$.clientX,$.clientY);w(V)},G=()=>{w(1),A.current=1,d.current&&(d.current.scrollLeft=0,d.current.scrollTop=0)},J=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:d,role:"button",tabIndex:0,onClick:D,onDoubleClick:$=>{$.preventDefault(),w(F=>F>1?1:2.5)},onPointerDown:Y,onPointerMove:re,onPointerUp:se,onPointerCancel:se,onWheel:he,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:p?e.jsx("div",{className:"p-4 text-sm text-destructive",children:p}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),T&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:T.stageX,top:T.stageY}}),T&&z&&e.jsx(Ga,{anchor:{xPercent:T.stageXPercent,yPercent:T.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(z,`svg:${T.x.toFixed(2)}:${T.y.toFixed(2)}`),_(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[u>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:$=>{$.stopPropagation(),G()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(bm,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:$=>{$.stopPropagation(),E(F=>!F)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(Rd,{size:14}):e.jsx(Cd,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:T?`SVG (${T.x.toFixed(2)}, ${T.y.toFixed(2)}) · ${T.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?zr.createPortal(J,document.body):J}function Ta(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function ip(t,n,s,l){const c=[`电子标注: ${t}`,`视图: ${Ta(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(c.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&c.push(`显示层: ${l.layer}`),l.nearest)){const d=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");c.push(`最近对象: ${l.nearest.label}${d?`(${d})`:""}`)}return`"${c.join(" / ")}"`}function lp({blobUrl:t,filePath:n,view:s,board:l,onViewChange:c,onInsertAnnotation:d,onRefresh:h,interactive3d:m}){const{t:p}=xt(),g=o.useRef(null),u=o.useRef(null),w=o.useRef(null),[y,E]=o.useState(null),[T,_]=o.useState(!1);o.useEffect(()=>(w.current?.abort(),E(null),_(!1),()=>w.current?.abort()),[t,s]);const U=o.useMemo(()=>y?ip(n,s,y,y.inspection):null,[n,y,s]),R=L=>{const A=g.current,z=u.current;if(!A||!z||!z.naturalWidth||!z.naturalHeight)return;const D=A.getBoundingClientRect(),a=z.getBoundingClientRect(),k=Math.min(a.width/z.naturalWidth,a.height/z.naturalHeight),B=z.naturalWidth*k,j=z.naturalHeight*k,Y=a.left+(a.width-B)/2,re=a.top+(a.height-j)/2,se=L.clientX-Y,he=L.clientY-re;if(se<0||he<0||se>B||he>j)return;const G={xPercent:Math.max(0,Math.min(100,se/B*100)),yPercent:Math.max(0,Math.min(100,he/j*100)),stageXPercent:(L.clientX-D.left)/D.width*100,stageYPercent:(L.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(E(G),w.current?.abort(),!G.inspecting)return;const J=new AbortController;w.current=J,Yf(n,s,G.xPercent,G.yPercent,J.signal).then($=>E(F=>F===G?{...F,inspection:$,inspecting:!1}:F)).catch(()=>{J.signal.aborted||E($=>$===G?{...$,inspection:{available:!1},inspecting:!1}:$)})},M=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:M.map(L=>e.jsx("button",{type:"button",onClick:()=>c(L),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${L===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ta(L)},L))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:p("rightSidebar.edaRefresh"),"aria-label":p("rightSidebar.edaRefresh"),children:e.jsx(fi,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:g,role:"button",tabIndex:0,onClick:R,onKeyDown:L=>{L.key!=="Enter"&&L.key!==" "||(L.preventDefault(),E({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:p("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:u,src:t,alt:`${n} ${Ta(s)}`,onLoad:()=>_(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${T?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&U&&e.jsx(Ga,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:p("rightSidebar.edaInsertAnnotation"),onClick:()=>{d?.(U,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:u.current?Sm(u.current,y):Promise.resolve(null)}),E(null)},children:p("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?p("rightSidebar.edaInspecting"):y.inspection?.available?p("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??p("rightSidebar.edaNoNearbyObject")}):p("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):p("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Dd,{blobUrl:t,filePath:n,viewLabel:Ta(s),onInsertAnnotation:d})})]})}function cp(t){const n=[];let s=[],l="",c=!1;for(let d=0;d<t.length;d+=1){const h=t[d];c?h==='"'&&t[d+1]==='"'?(l+='"',d+=1):h==='"'?c=!1:l+=h:h==='"'?c=!0:h===","?(s.push(l),l=""):h===`
|
|
14
|
+
`?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function dp(t,n,s,l,c){const d=n[c]||`第${c+1}列`,h=s[c]??"",m=n.map((p,g)=>`${p||`第${g+1}列`}=${s[g]??""}`).join(";");return`"表格标注: ${t} / 数据行: ${l+1} / 列: ${d} / 值: ${h} / 记录: ${m}"`}function up({content:t,filePath:n,onInsertAnnotation:s}){const{t:l}=xt(),c=o.useMemo(()=>cp(t),[t]),d=c[0]??[],h=c.slice(1),m=o.useRef(null),[p,g]=o.useState(null),u=p?h[p.row]:null,w=p&&u?dp(n,d,u,p.row+1,p.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:m,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),d.map((y,E)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||l("rightSidebar.csvUnnamedColumn",{index:E+1})},`${y}:${E}`))]})}),e.jsx("tbody",{children:h.map((y,E)=>e.jsxs("tr",{className:"hover:bg-surface-2",children:[e.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:E+1}),d.map((T,_)=>{const U=p?.row===E&&p.column===_;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${U?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:R=>{const M=m.current?.getBoundingClientRect(),L=R.currentTarget.getBoundingClientRect();if(!M?.width||!M.height)return;const A=R.clientX||L.left+L.width/2,z=R.clientY||L.top+L.height/2;g({row:E,column:_,xPercent:(A-M.left)/M.width*100,yPercent:(z-M.top)/M.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[_]||" "})},`cell:${E}:${_}`)})]},`row:${E}`))})]})}),p&&w&&e.jsx(Ga,{anchor:{xPercent:p.xPercent,yPercent:p.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(w,`csv:${n}:${p.row+1}:${p.column+1}`),g(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:p&&u?l("rightSidebar.csvSelectedCell",{row:p.row+1,column:d[p.column]||p.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:d.length})})})]})}function On(t,n){let s=t;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function fp(t,n){const s=JSON.parse(t),l=On(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(On(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(On(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:On(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const c=On(s,["net_settings","classes"]),d=Array.isArray(c)?c.find(m=>m&&typeof m=="object"&&m.name==="Default"):void 0,h=On(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(c)?c.length:0)},{label:"默认间距",value:d?.clearance!==void 0?`${d.clearance} mm`:"未设置"},{label:"默认线宽",value:d?.track_width!==void 0?`${d.track_width} mm`:"未设置"},{label:"默认过孔",value:d?.via_diameter!==void 0?`${d.via_diameter} / ${d.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function hp(t,n){return`"KiCad项目标注: ${t} / 项: ${n.label} / 值: ${n.value}"`}function mp({content:t,filePath:n,localState:s,onInsertAnnotation:l}){const{t:c}=xt(),d=o.useRef(null),[h,m]=o.useState(null),p=o.useMemo(()=>{try{return{items:fp(t,s),error:null}}catch(u){return{items:[],error:u instanceof Error?u.message:String(u)}}},[t,s]),g=h===null?null:p.items[h.index];return p.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:t}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:c("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:p.items.map((u,w)=>e.jsxs("button",{type:"button",onClick:y=>{const E=d.current?.getBoundingClientRect(),T=y.currentTarget.getBoundingClientRect();if(!E?.width||!E.height)return;const _=y.clientX||T.left+T.width/2,U=y.clientY||T.top+T.height/2;m({index:w,xPercent:(_-E.left)/E.width*100,yPercent:(U-E.top)/E.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${h?.index===w?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:u.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:u.value})]},u.label))}),e.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:c("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:t})]})]}),g&&h&&e.jsx(Ga,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:c("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(hp(n,g),`kicad-project:${n}:${g.label}`),m(null)},children:c("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:g?`${g.label}: ${g.value}`:c("rightSidebar.kicadProjectPickHint")})})]})}const pp=`/** ES Module Shims Wasm @version 2.8.4 */
|
|
15
15
|
(function () {
|
|
16
16
|
|
|
17
17
|
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
@@ -1497,7 +1497,7 @@ import{Z as bt,R as qf,aR as e,c1 as xt,c7 as gt,b5 as Ze,a as ks,au as Kf,C as
|
|
|
1497
1497
|
};
|
|
1498
1498
|
|
|
1499
1499
|
})();
|
|
1500
|
-
`,
|
|
1500
|
+
`,gp=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
|
|
1501
1501
|
function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
|
|
1502
1502
|
const external = new Set(externalOrigins);
|
|
1503
1503
|
const report = () => parent.postMessage({ type: 'preview-error', capability }, '*');
|
|
@@ -1632,47 +1632,47 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
|
|
|
1632
1632
|
window.addEventListener('error', report, true);
|
|
1633
1633
|
window.addEventListener('unhandledrejection', report);
|
|
1634
1634
|
}
|
|
1635
|
-
`,Ra="/api/terminal/fs/preview/",
|
|
1636
|
-
installPreviewRuntime(`+[c,d,[...u],J].map(
|
|
1637
|
-
`+$.documentElement.outerHTML;return{html:je,shellUrl:`/preview-shell.html#${c}`,errors:h,attach(N,Z){const de=new Set,Ee=Pe=>{if(Pe.source!==N.contentWindow||Pe.data?.capability!==c)return;if(Pe.data.type==="preview-ready"){N.contentWindow?.postMessage({type:"preview-init",capability:c,html:je,resources:g},"*");return}if(Pe.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(Pe.data.type==="preview-navigate"){(async()=>{const ne=j(String(Pe.data.url)),S=await Fd(ne.pathname+ne.search,n);if(T){S.dispose();return}const X=S.attach(N,Z);_.add(()=>{X(),S.dispose()}),N.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(ne=>Z(ne instanceof Error?ne.message:"无法打开预览页面"));return}if(Pe.data.type==="preview-external"){try{const ne=new URL(String(Pe.data.url));ne.protocol==="https:"&&u.has(ne.origin)&&window.open(ne.href,"_blank","noopener,noreferrer")}catch{}return}if(Pe.data.type!=="preview-fetch"||Pe.ports.length!==1)return;const ce=Pe.ports[0];if(de.size>=8||!["GET","HEAD"].includes(Pe.data.method)){ce.postMessage({error:"预览仅允许读取已授权目录资源"}),ce.close();return}de.add(ce),(async()=>{const ne=j(String(Pe.data.url)),S=await Y(ne);if(!de.has(ce)||T)return;const X=Pe.data.method==="HEAD"?new Uint8Array:S.bytes.slice();ce.postMessage({status:S.status,headers:{"content-type":S.type},data:X.buffer},[X.buffer])})().catch(()=>{ce.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{de.delete(ce),ce.close()})};window.addEventListener("message",Ee);const ze=()=>{window.removeEventListener("message",Ee);for(const Pe of de)Pe.close();de.clear(),_.delete(ze)};return _.add(ze),ze},dispose:U}}catch(G){throw U(),G}}const
|
|
1638
|
-
`);const y=c.length;c+=u.data,l.push({node:u,start:y,end:c.length,group:w}),d=w}const m=c.toLocaleLowerCase(),p=[];let g=0;for(;g<=m.length-s.length;){const u=m.indexOf(s,g);if(u<0)break;const w=u+s.length,y=l.find(T=>T.start<=u&&T.end>u),E=l.find(T=>T.start<w&&T.end>=w);if(y&&E&&y.group===E.group){const T=document.createRange();T.setStart(y.node,u-y.start),T.setEnd(E.node,w-E.start),p.push(T)}g=u+Math.max(s.length,1)}return p}function Od(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Ca(){const t=Od();t?.delete(Bd),t?.delete(vi)}function Wc(t,n){const s=Od();if(!s||typeof Highlight>"u")return;s.set(Bd,new Highlight(...t));const l=t[n];l?s.set(vi,new Highlight(l)):s.delete(vi)}function Gc(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Rp(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Cp(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Np(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function Ud(t,n,s){return n?t:zr.createPortal(t,s)}const Pi="termdock:right-sidebar:file-tree-scroll:v1",Ti="termdock:right-sidebar:file-preview-reading-state:v1",bs="termdock:right-sidebar:file-tree-width:v1",Hd="termdock:right-sidebar:markdown-view-mode:v1",zd="termdock:right-sidebar:diff-change-list-mode:v1",Wd="termdock:right-sidebar:diff-wrap:v1",Gd="termdock:diff-viewer:view-type:v1",qd="termdock:right-sidebar:file-search-mode:v1",Go="termdock:right-sidebar:collapsed-git-repo-groups:v1",qc="termdock:right-sidebar:collapsed-diff-directories:v1",qo="termdock:right-sidebar:branch-audit-module-open:v1",Kd="termdock:right-sidebar:branch-audit-module:v1",Mp=150,Vd="termdock:right-sidebar:active-git-repo:v1",Kc="termdock:right-sidebar:context-draft-enabled:v1",Vc="termdock:right-sidebar:context-draft-collapsed:v1",Yc="termdock:right-sidebar:context-draft-auto-collapse:v1",Ko="termdock:right-sidebar:context-draft-text:v1",$p=300,Ep=20,Lp=120,Ap=250,Pp=250,Tp=120,Ip=700,Vo=600,Xc=[2e3,5e3,15e3,3e4],_p=320,Dp=500,Fp=20,Bp=12e3,yi=300,Jc=240,Op=560,Yd="border-r px-2 py-1.5 sm:px-3 sm:py-2",Fa="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Xd=`${Yd} border-b border-border/15 font-semibold last:border-r-0`,Jd=`${Yd} border-border/10 align-top text-muted-foreground last:border-r-0`,Ii="termdock-file-preview-horizontal-scroll",Qc=o.lazy(()=>js(()=>import("./ModelPreview-B0942mh0.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Qd=`${Ii} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Zd(t,n,s){return t&&!n?"unified":s}const Up=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Hp(t){return t==="preview"||t==="source"}function zp(t){return t==="list"||t==="tree"||t==="ai"}function Zc(){return Ze(Hd,Hp)??"preview"}function Wp(){return Ze(zd,zp)??"tree"}function xs(t){return typeof t=="boolean"}function Gp(t){return typeof t=="string"}function qp(){return Ze(Wd,xs)??!0}function Kp(t){return t==="unified"||t==="split"}function Vp(){return Ze(Gd,Kp)??"unified"}function Yp(t){return t==="name"||t==="content"||t==="regex"}function Xp(){return Ze(qd,Yp)??"name"}function eu(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:ut(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function Jp(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function tu(){return Ze(Vd,Jp)??{}}function ed(t){if(!t)return;const n=tu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function Yo(t,n){t&>(Vd,{...tu(),[t]:n})}function Qp(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function wi(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function td(t){const n=Ze(t,wi);return n?new Set(n):new Set}function Xo(t,n){gt(t,[...n])}function Zp(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function eg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||wi(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Zp))&&(n.commits===void 0||wi(n.commits))&&(n.commitCount===void 0||typeof n.commitCount=="number")&&(n.diff===void 0||typeof n.diff=="string")&&(n.truncated===void 0||typeof n.truncated=="boolean")&&(n.error===void 0||typeof n.error=="string")}function tg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&eg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function rg(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(tg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function rd(){return Ze(Kd,rg)??{}}function nd(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function sd(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function ru(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||sd(s)===sd(l)}function ad(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!ru(l,n))??""}function ki(t,n){const s=Math.max(Jc,n-320),l=Math.min(Op,s);return Math.min(l,Math.max(Jc,t))}function ng(t){return typeof t=="number"&&Number.isFinite(t)}function sg(t){return ki(Ze(bs,ng)??yi,t)}function nu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function ms(t){return Up.has(nu(t))}function su(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Si(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||su(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function ag(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const au=o.createContext(null);function Ia(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function ou(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function iu(t){return t.replace(/\s+#+\s*$/,"").trim()}function ji(t,n){const l=ou(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",c=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,c+1),c===0?l:`${l}-${c}`}function od(t){return ou(t)||t.trim()}function Ba(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ci(n[2]);return s?{id:Ia(n[1]),definition:{href:s.href,title:s.title}}:null}function og(t){const n=new Map;for(const s of t){const l=Ba(s);l&&n.set(l.id,l.definition)}return n}function lu(t){return t.trim().toLowerCase()}function cu(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:lu(n[1]),text:n[2]}:null}function ig(t){const n=new Map;let s=null;for(const l of t){const c=cu(l);if(c){s=c.id,n.set(c.id,{id:c.id,text:c.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const d=n.get(s);d&&(d.text=`${d.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function du(t){const n=new Set;let s=!1;return t.forEach((l,c)=>{if(cu(l)){n.add(c),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(c);return}l.trim()&&(s=!1)}),n}function lg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const c=t[s].trim();if(c.startsWith("<!--")){if(n[s]="",!c.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function uu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function ws(t){const n=t.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const d of n.split("/"))if(!(!d||d===".")){if(d===".."){l.length>0&&l.pop();continue}l.push(d)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function fu(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const c=l.indexOf("#"),d=c>=0?l.slice(0,c):l,h=c>=0?l.slice(c+1):"",m=d.split("?",1)[0];if(!m)return null;let p,g=null;try{p=decodeURIComponent(m),g=h?decodeURIComponent(h):null}catch{return null}const u=s?ws(s):null;let w;if(p.startsWith("/")){const y=u&&(p===u||p.startsWith(`${u}/`));w=ws(u&&!y?`${u}/${p.slice(1)}`:p)}else{if(!n)return null;w=ws(`${uu(n)}/${p}`)}return u&&w!==u&&!w.startsWith(`${u}/`)?null:{path:w,fragment:g,directory:/\/$/.test(m)}}function cg(t,n,s){const l=t.trim();if(!l||/^(?:javascript|data):/i.test(l))return null;if(/^https?:\/\//i.test(l))return l;if(!xd(l.split(/[?#]/,1)[0]))return null;let c;if(l.startsWith("/")){const d=s&&(l===s||l.startsWith(`${s}/`));c=ws(s&&!d?`${s}/${l.slice(1)}`:l)}else{if(!n)return null;c=ws(`${uu(n)}/${l}`)}return`/api/terminal/fs/blob?path=${encodeURIComponent(c)}`}const Ri=128,dg=360,Jo=480;function qa(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function hu(t,n,s,l){if(!n||!s)return null;let c,d;return qa(t)?(d=Math.min(Math.max(s,Ri),dg),c=n*d/s):(c=n,d=s),l>0&&c>l&&(d=d*l/c,c=l),d>Jo&&(c=c*Jo/d,d=Jo),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(d))}}function ug(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function mu(t){const n=ug(t),s=oe(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function fg({src:t,alt:n,title:s}){const l=qa(t),c=mu(t),d=Ai(c),h=o.useRef(null),[m,p]=o.useState(!1),[g,u]=o.useState(0),[w,y]=o.useState({status:"loading"}),[E,T]=o.useState(null);o.useLayoutEffect(()=>{const R=h.current,M=R?.parentElement?.parentElement??R?.parentElement;if(!M)return;const L=()=>u(M.clientWidth);if(L(),typeof ResizeObserver>"u")return;const A=new ResizeObserver(L);return A.observe(M),()=>A.disconnect()},[]),o.useEffect(()=>{if(m)return;const R=h.current;if(!R||typeof IntersectionObserver>"u"){p(!0);return}const M=new IntersectionObserver(L=>{L.some(A=>A.isIntersecting)&&(p(!0),M.disconnect())},{rootMargin:"400px"});return M.observe(R),()=>M.disconnect()},[m]),o.useEffect(()=>{if(!m)return;const R=new AbortController;let M=null;y({status:"loading"});const L=window.setTimeout(()=>{R.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Nh(c,{signal:R.signal}).then(async A=>{if(!A.ok)throw new Error(`HTTP ${A.status}`);const z=Number(A.headers.get("X-Image-Width"))||0,D=Number(A.headers.get("X-Image-Height"))||0;return{blob:await A.blob(),width:z,height:D}}).then(({blob:A,width:z,height:D})=>{R.signal.aborted||(M=URL.createObjectURL(A),z>0&&D>0&&T({width:z,height:D}),y({status:"ready",objectUrl:M}))}).catch(()=>{const A=R.signal.reason;R.signal.aborted&&!(A instanceof DOMException&&A.name==="TimeoutError")||y({status:"fallback"})}).finally(()=>{window.clearTimeout(L)}),()=>{window.clearTimeout(L),R.abort(),M&&URL.revokeObjectURL(M)}},[m,c]);const _=hu(t,E?.width??0,E?.height??0,g),U=_??{width:Ri*2,height:Ri};return e.jsx("div",{ref:h,className:"block max-w-full",style:_?{width:_.width,height:_.height}:void 0,children:w.status==="ready"?e.jsx("img",{src:w.objectUrl,alt:n,title:s,decoding:"async",className:`${l?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:_?{width:_.width,height:_.height}:void 0,onLoad:R=>{if(E)return;const M=R.currentTarget;M.naturalWidth>0&&M.naturalHeight>0&&T({width:M.naturalWidth,height:M.naturalHeight})}}):w.status==="fallback"?e.jsx("img",{src:d,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:_?{width:_.width,height:_.height}:void 0,onLoad:R=>{if(E)return;const M=R.currentTarget;M.naturalWidth>0&&M.naturalHeight>0&&T({width:M.naturalWidth,height:M.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:U.width,height:U.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function Qo(t,n,s,l,c){const d=cg(s,c.markdownFilePath,c.rootPath);if(!d)return``;const h=c.images.length;c.images.push({kind:"image",src:d,alt:n,title:l});const m=e.jsx(fg,{src:d,alt:n,title:l});return c.onImageOpen?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:p=>{p.stopPropagation(),c.onImageOpen?.(h)},children:m},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:m},t)}function Zo(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function id(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Ci(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const pu="",hg=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function mg(t){return t.replace(hg,(n,s)=>`${pu}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ld(t){return t.replace(new RegExp(`${pu}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function pg(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const gu={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Na=null;function bu(){return Na||(Na=js(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw Na=null,t})),Na}function xu({html:t}){const{t:n}=xt(),[s,l]=o.useState(null);return o.useEffect(()=>{let c=!1;return l(null),bu().then(d=>{c||l(d.sanitize(t,gu))}).catch(()=>{c||l("")}),()=>{c=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function gg({html:t}){const[n,s]=o.useState(null);return o.useEffect(()=>{let l=!1;return s(null),bu().then(c=>{l||s(c.sanitize(t,gu))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function vu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Ma=null;function bg(){return Ma||(Ma=Promise.all([js(()=>import("./katex-DnlPpQZa.js"),[]),js(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Ma=null,t})),Ma}function Cs({tex:t,display:n=!1}){const[s,l]=o.useState(null),[c,d]=o.useState(!1);if(o.useEffect(()=>{let m=!1;return l(null),d(!1),bg().then(p=>{m||l(p.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||d(!0)}),()=>{m=!0}},[n,t]),c)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function xg(t,n,s){if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(gg,{html:t},n):null;const c=l[1].toLowerCase(),d=et(l[2],`${n}-${c}`,!0,s);return c==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:d},n):c==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:d},n):c==="sub"?e.jsx("sub",{children:d},n):e.jsx("sup",{children:d},n)}function et(t,n,s=!0,l){const c=mg(t),d=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let m=0,p;for(;(p=d.exec(c))!==null;){p.index>m&&h.push(ld(c.slice(m,p.index)));const g=p[0],u=`${n}-${p.index}`,w=g.startsWith("<")?xg(g,u,l):null;if(w)h.push(w);else if(g.startsWith("\\(")&&g.endsWith("\\)"))h.push(e.jsx(Cs,{tex:g.slice(2,-2)},u));else if(g.startsWith("$")&&g.endsWith("$"))h.push(e.jsx(Cs,{tex:g.slice(1,-1)},u));else if(g.startsWith("`")){const y=g.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:pg(g.slice(y,-y))},u))}else if(g.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:et(g.slice(2,-2),`${u}-del`,s,l)},u));else if(g.startsWith("**")||g.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:et(g.slice(2,-2),`${u}-strong`,s,l)},u));else if(g.startsWith("*")||g.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:et(g.slice(1,-1),`${u}-em`,s,l)},u));else if(g.startsWith("![")){const y=g.match(/^!\[([^\]]*)\]\((.*)\)$/),E=g.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),T=g.match(/^!\[([^\]]+)\]$/);if(y){const _=Ci(y[2]);h.push(_?Qo(u,y[1],_.href,_.title,l):g)}else if(E){const _=E[2]||E[1],U=l.referenceDefinitions.get(Ia(_));h.push(U?Qo(u,E[1],U.href,U.title,l):g)}else if(T){const _=l.referenceDefinitions.get(Ia(T[1]));h.push(_?Qo(u,T[1],_.href,_.title,l):g)}else h.push(g)}else if(g.startsWith("[^")){const y=lu(g.slice(2,-1)),E=l.footnoteDefinitions.get(y);h.push(E?e.jsx("sup",{id:`fnref-${E.id}`,title:E.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${E.id}`,className:"text-primary no-underline",children:E.index})},u):g)}else if(g.startsWith("<http")){const y=g.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u))}else if(g.startsWith("<")&&g.endsWith(">")&&id(g.slice(1,-1))){const y=g.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u))}else if(id(Zo(g).linkText)){const{linkText:y,suffix:E}=Zo(g);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u)),E&&h.push(E)}else if(g.startsWith("http")||g.startsWith("www.")){const{linkText:y,suffix:E}=Zo(g),T=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:T,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u)),E&&h.push(E)}else{const y=g.match(/^\[([^\]]+)\]\((.*)\)$/),E=g.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),T=g.match(/^\[([^\]]+)\]$/),_=E?E[2]||E[1]:T?.[1]??null,U=_?l.referenceDefinitions.get(Ia(_)):null,R=y?Ci(y[2]):null,M=R?.href??U?.href??null,L=M?ag(M):null,A=y?.[1]??E?.[1]??T?.[1]??"";h.push(L?e.jsx("a",{href:L,title:R?.title??U?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:et(A,`${u}-link`,s,l)},u):g)}m=d.lastIndex}return m<c.length&&h.push(ld(c.slice(m))),h.length>0?h:[t]}function yu(t){return/(?: {2,}|\\)$/.test(t)}function wu(t){return t.replace(/(?: {2,}|\\)$/,"")}function Oa(t){return/^(?: {4}|\t)/.test(t)}function ku(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function Su(t,n,s){const l=[];return t.forEach((c,d)=>{const h=yu(c);l.push(...et(wu(c),`${n}-${d}`,!0,s)),d<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${d}-br`):" ")}),l}function Ni(t,n,s){const l=[],c=[];return t.forEach((d,h)=>{c.push(yu(d)),l.push(et(wu(d),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:c}}function Mi(t,n,s,l,c){const d=[];return t.forEach((h,m)=>{const p=s[m]??0,g=!!(c&&p>=c.start&&p<=c.end);d.push(e.jsx("span",{"data-md-ref-start":p,"data-md-ref-end":p,"data-selected":g?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&d.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),d}function Ns(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",c=!1,d=0,h=0;for(let m=0;m<n.length;m+=1){const p=n[m];if(c){l+=p,c=!1;continue}if(p==="\\"){c=!0;continue}if(p==="`"){const g=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const u=m-g+1;l+="`".repeat(u),d===0?d=u:d===u&&(d=0);continue}if(d===0&&p==="["?h+=1:d===0&&p==="]"&&h>0&&(h-=1),p==="|"&&d===0&&h===0){s.push(l.trim()),l="";continue}l+=p}return c&&(l+="\\"),s.push(l.trim()),s}function ju(t){return Ns(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Ua(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Ha(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function Ru(t,n){return t>96||t>44&&n>.35}function Ka(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Ms(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function _i(t,n,s,l,c,d=new Set){const h=[],m=[];let p=n;for(;p<t.length;){const g=t[p];if(c&&(Ba(g)||d.has(p))){p+=1;continue}const u=Ms(g),w=Ka(g);if(!u){if(w>s&&m.length>0){([...m].reverse().find(_=>_.indent<w)?.item??m[m.length-1].item).paragraphs.push(g.trim());for(const _ of m)_.item.lineEnd=p+1;p+=1;continue}break}if(w<s||w===s&&u.ordered!==l)break;const y={content:u.content,ordered:u.ordered,start:u.start,children:[],paragraphs:[],lineStart:p+1,lineEnd:p+1};for(;m.length>0&&m[m.length-1].indent>=w;)m.pop();const E=m[m.length-1]?.item??null;E?E.children.push(y):h.push(y),m.push({indent:w,item:y});for(const T of m)T.item.lineEnd=p+1;p+=1}return{items:h,nextIndex:p}}function vg(t){const n=t.find(l=>Ms(l));if(!n)return[];const s=Ms(n);return s?_i(t,0,Ka(n),s.ordered,!0,du(t)).items:[]}function Di(t,n,s,l=0){return t.map((c,d)=>{const h=c.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${d}`,taskItem:!!h,refStart:c.lineStart+l,refEnd:c.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,et(h?.[2]??c.content,`li-${n}-${d}`,!0,s),c.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:c.paragraphs.map((m,p)=>e.jsx("p",{children:et(m,`li-${n}-${d}-p-${p}`,!0,s)},`paragraph-${p}`))})]}),groups:yg(c.children,`${n}-${d}`,s,l)}})}function yg(t,n,s,l=0){const c=[];for(const d of t){const h=c[c.length-1];h&&h.ordered===d.ordered?h.items.push(d):c.push({ordered:d.ordered,items:[d]})}return c.map((d,h)=>({ordered:d.ordered,start:d.ordered?d.items[0]?.start:void 0,items:Di(d.items,`${n}-g${h}`,s,l)}))}function Fi(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&wg(s.groups,n)]},s.key)})}function wg(t,n){return t.map((s,l)=>{const c=s.ordered?"ol":"ul";return e.jsx(c,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Fi(s.items,n)},`nested-${l}`)})}function kg(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[et(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Sg(t,n,s,l){const c=[];let d=0;const h=m=>l?.[m]??m+1;for(;d<t.length;){const m=t[d],p=m.trim();if(!p){d+=1;continue}if(/^<details>\s*$/i.test(p)){const R=d;let M="Details";const L=[];for(d+=1;d<t.length&&!/^<\/details>\s*$/i.test(t[d].trim());){const A=t[d].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);A?M=A[1].trim()||M:L.push(t[d].trimStart()),d+=1}d<t.length&&(d+=1),c.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:et(M,`${n}-details-${R}-summary`,!0,s)}),L.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Su(L,`${n}-details-${R}`,s)})]},`${n}-details-${R}`)});continue}const g=vu(m);if(g){const R=[m],M=d;for(d+=1;d<t.length&&!g.selfContained&&!new RegExp(`</${g.tag}>`,"i").test(t[d]);)R.push(t[d]),d+=1;d<t.length&&!g.selfContained&&(R.push(t[d]),d+=1),c.push({kind:"static",node:e.jsx(xu,{html:R.join(`
|
|
1635
|
+
`,Ra="/api/terminal/fs/preview/",bp=8*1024*1024,xp=32*1024*1024,vp=128,yp="data:,";function Rt(t){throw new Error(t)}function wp(t){return JSON.stringify(t).replace(/</g,"\\u003c")}async function zc(t,n,s){let l="",c=0;for(const d of t.matchAll(n))l+=t.slice(c,d.index)+await s(d),c=d.index+d[0].length;return l+t.slice(c)}async function Fd(t,n){const s=n.origin??location.origin,l=new URL(t,s);(l.origin!==s||!us(l.pathname)?.startsWith(Ra))&&Rt("预览地址不是有效的本地文件入口");const c=crypto.randomUUID(),d=`https://termdock-preview.invalid/${c}/`,h=[],m=G=>{!h.includes(G)&&h.length<20&&h.push(G)},p=new Set,g=[],u=new Set,w=new Map,y=new Map;let E=0,T=!1;const _=new Set,U=()=>{T=!0;for(const G of[..._])G();p.clear(),g.length=0};async function R(G){G.ok||Rt(`预览资源读取失败(${G.status})`);const J=G.body?.getReader(),$=[];let F=0;try{if(J)for(;;){const ie=await J.read();if(ie.done)break;F+=ie.value.byteLength,E+=ie.value.byteLength,(F>bp||E>xp)&&Rt("预览资源超出大小限制"),$.push(ie.value)}}catch(ie){throw await J?.cancel().catch(()=>{}),ie}finally{J?.releaseLock()}const V=new Uint8Array(F);let te=0;for(const ie of $)V.set(ie,te),te+=ie.length;return{bytes:V,type:G.headers.get("content-type")??"application/octet-stream",status:G.status}}let M=l,L;for(let G=0;G<4;G++){const J=await n.fetch(M.pathname+M.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(J.status)){L=J;break}const $=J.headers.get("location");await J.body?.cancel(),$||Rt("预览重定向缺少目标");const F=new URL($,M);(F.origin!==s||!us(F.pathname)?.startsWith(Ra))&&Rt("预览重定向越出文件范围"),M=F}L||Rt("预览重定向次数过多");const A=us(M.pathname),z=A.slice(Ra.length).split("/");/^[a-f0-9]{32}$/.test(z[0])||Rt("服务未提供有效的预览资源授权");const D=us(l.pathname).slice(Ra.length).split("/");/^[a-f0-9]{32}$/.test(D[0])&&D.shift(),D.join("/").replace(/\/$/,"")!==z.slice(1).join("/").replace(/\/$/,"")&&Rt("预览重定向改变了文件范围");const a=A.endsWith("/")?A:A.slice(0,A.lastIndexOf("/")+1),k=new URL(M.pathname.endsWith("/")?M.pathname:M.pathname.slice(0,M.pathname.lastIndexOf("/")+1),s);function B(G,J){const $=new URL(G,J);return $.origin!==s?null:(us($.pathname)?.startsWith(a)||Rt("已阻止预览访问目录之外的资源"),$)}function j(G){const J=new URL(G,d);(J.origin!==new URL(d).origin||!J.pathname.startsWith(new URL(d).pathname))&&Rt("已阻止预览访问服务接口或目录之外的资源");const $=J.pathname.slice(new URL(d).pathname.length)+J.search;return B($,k)??Rt("预览资源无效")}function Y(G){const J=G.pathname+G.search,$=w.get(J);if($)return $;if(T||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(w.size>=vp)return Promise.reject(new Error("预览资源数量超出限制"));const F=n.fetch(J,{signal:n.signal,redirect:"manual"}).then(R);return w.set(J,F),F}function re(G,J){T&&Rt("预览已关闭");const $=`termdock-resource-${c}-${g.length}`;return g.push({token:$,data:G,type:J}),p.add($),$}async function se(G,J,$,F=new Set){if(!G||G.startsWith("#")||/^data:(?:image|font)\//i.test(G)&&$==="resource")return G;try{const V=B(G,J);if(!V){const je=new URL(G,J);return(je.protocol!=="https:"||je.username||je.password||je.origin===new URL(d).origin)&&Rt("已阻止不安全的外部资源"),u.add(je.origin),je.href}const te=`${$}:${V.href}`;(F.has(te)||F.size>=8)&&Rt("预览资源存在循环或过深引用");const ie=y.get(te);if(ie)return ie;const me=new Set(F);me.add(te);const pe=(async()=>{const je=await Y(V);return $==="css"?re(await he(new TextDecoder().decode(je.bytes),V,me),"text/css"):$==="script"?re(je.bytes,"text/javascript"):re(je.bytes,je.type)})();return y.set(te,pe),await pe}catch(V){return m(V instanceof Error?V.message:"部分预览资源未能加载"),yp}}async function he(G,J,$){return G=await zc(G,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async F=>`@import url("${await se(F[1],J,"css",$)}")${F[2]};`),zc(G,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async F=>{const V=(F[1]??F[2]??F[3]).trim();return p.has(V)?F[0]:`url("${await se(V,J,"resource",$)}")`})}try{const G=await R(L),J=re(pp,"text/javascript"),$=new DOMParser().parseFromString(new TextDecoder().decode(G.bytes),"text/html");$.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(N=>N.remove());for(const N of $.querySelectorAll("*")){if(N.removeAttribute("ping"),N.removeAttribute("srcdoc"),N.hasAttribute("style")&&N.setAttribute("style",await he(N.getAttribute("style"),M,new Set)),N.tagName==="STYLE"&&(N.textContent=await he(N.textContent??"",M,new Set)),N.tagName==="A"||N.tagName==="AREA"){const Z=N.getAttribute("href");try{if(Z&&!Z.startsWith("#")){const de=B(Z,M);if(de)N.setAttribute("href",new URL(de.pathname.slice(k.pathname.length)+de.search+de.hash,d).href);else{const Ee=new URL(Z,M);if(Ee.protocol!=="https:"){N.removeAttribute("href");continue}u.add(Ee.origin),N.setAttribute("href",Ee.href)}}}catch(de){N.removeAttribute("href"),m(de instanceof Error?de.message:"预览链接无法加载")}}for(const Z of["data","manifest"])N.removeAttribute(Z);if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="module"){N.setAttribute("type","module-shim");const Z=N.getAttribute("src");if(Z){const de=B(Z,M);if(de)N.setAttribute("src",new URL(de.pathname.slice(k.pathname.length)+de.search,d).href);else{const Ee=new URL(Z,M);if(Ee.protocol!=="https:"){N.remove();continue}u.add(Ee.origin),N.setAttribute("src",Ee.href)}}continue}if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="importmap"){N.setAttribute("type","importmap-shim");continue}if(N.tagName==="LINK"){const Z=(N.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Z)){N.remove();continue}const de=N.getAttribute("href");de&&N.setAttribute("href",await se(de,M,Z==="stylesheet"?"css":"resource"))}if(N.hasAttribute("src")&&N.setAttribute("src",await se(N.getAttribute("src"),M,N.tagName==="SCRIPT"?"script":"resource")),N.hasAttribute("poster")&&N.setAttribute("poster",await se(N.getAttribute("poster"),M,"resource")),N.hasAttribute("srcset")){const Z=N.getAttribute("srcset");/data:/i.test(Z)?(N.removeAttribute("srcset"),m("混合内嵌图片候选暂不支持安全预览")):N.setAttribute("srcset",(await Promise.all(Z.split(",").map(async de=>{const[Ee,...ze]=de.trim().split(/\s+/);return`${await se(Ee,M,"resource")} ${ze.join(" ")}`}))).join(", "))}N.setAttribute("referrerpolicy","no-referrer"),N.removeAttribute("integrity"),N.removeAttribute("crossorigin")}const F=[...u].join(" "),V=$.createElement("meta");V.httpEquiv="Content-Security-Policy",V.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${F}; style-src 'unsafe-inline' blob: ${F}; img-src blob: data: ${F}; font-src blob: data: ${F}; media-src blob: data: ${F}; connect-src blob: ${F} ${[...u].map(N=>N.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const te=$.createElement("base");te.href=d;const ie=$.createElement("meta");ie.name="referrer",ie.content="no-referrer";const me=$.createElement("script");me.textContent=gp+`
|
|
1636
|
+
installPreviewRuntime(`+[c,d,[...u],J].map(wp).join(",")+");";const pe=$.createElement("script");pe.src=J,$.head.prepend(V,ie,te,me,pe);const je=`<!doctype html>
|
|
1637
|
+
`+$.documentElement.outerHTML;return{html:je,shellUrl:`/preview-shell.html#${c}`,errors:h,attach(N,Z){const de=new Set,Ee=Pe=>{if(Pe.source!==N.contentWindow||Pe.data?.capability!==c)return;if(Pe.data.type==="preview-ready"){N.contentWindow?.postMessage({type:"preview-init",capability:c,html:je,resources:g},"*");return}if(Pe.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(Pe.data.type==="preview-navigate"){(async()=>{const ne=j(String(Pe.data.url)),S=await Fd(ne.pathname+ne.search,n);if(T){S.dispose();return}const X=S.attach(N,Z);_.add(()=>{X(),S.dispose()}),N.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(ne=>Z(ne instanceof Error?ne.message:"无法打开预览页面"));return}if(Pe.data.type==="preview-external"){try{const ne=new URL(String(Pe.data.url));ne.protocol==="https:"&&u.has(ne.origin)&&window.open(ne.href,"_blank","noopener,noreferrer")}catch{}return}if(Pe.data.type!=="preview-fetch"||Pe.ports.length!==1)return;const ce=Pe.ports[0];if(de.size>=8||!["GET","HEAD"].includes(Pe.data.method)){ce.postMessage({error:"预览仅允许读取已授权目录资源"}),ce.close();return}de.add(ce),(async()=>{const ne=j(String(Pe.data.url)),S=await Y(ne);if(!de.has(ce)||T)return;const X=Pe.data.method==="HEAD"?new Uint8Array:S.bytes.slice();ce.postMessage({status:S.status,headers:{"content-type":S.type},data:X.buffer},[X.buffer])})().catch(()=>{ce.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{de.delete(ce),ce.close()})};window.addEventListener("message",Ee);const ze=()=>{window.removeEventListener("message",Ee);for(const Pe of de)Pe.close();de.clear(),_.delete(ze)};return _.add(ze),ze},dispose:U}}catch(G){throw U(),G}}const kp=o.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:c},d){const h=o.useRef(null),m=o.useRef(null),[p,g]=o.useState(),[u,w]=o.useState("");o.useEffect(()=>{const L=new AbortController;let A;return g(void 0),w(""),(async()=>{const z=await Xf();if(A=await Fd(n,{fetch:(D,a)=>z.fetch(D,a),signal:L.signal}),L.signal.aborted){A.dispose();return}g(A),A.errors.length&&w(A.errors.join(";"))})().catch(z=>{L.signal.aborted||w(z instanceof Error?z.message:"安全预览加载失败")}),()=>{L.abort(),A?.dispose()}},[n]),o.useEffect(()=>{if(!(!p||!m.current))return p.attach(m.current,w)},[p]);const[y,E]=o.useState(!1),[T,_]=o.useState(!1),U=y||T;o.useEffect(()=>{c?.(U)},[U,c]),o.useEffect(()=>{const L=()=>{E(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",L),()=>document.removeEventListener("fullscreenchange",L)},[]),o.useEffect(()=>{if(!T)return;const L=A=>{A.key==="Escape"&&_(!1)};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[T]);const R=o.useCallback(async()=>{const L=h.current;if(L){if(T){_(!1);return}if(document.fullscreenElement===L){await document.exitFullscreen();return}if(L.requestFullscreen&&document.fullscreenEnabled!==!1)try{await L.requestFullscreen();return}catch{}_(!0)}},[T]);o.useImperativeHandle(d,()=>({toggleFullscreen:R}),[R]);const M=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:U?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[U&&e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[e.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:s}),e.jsx("button",{type:"button",onClick:()=>{R()},"aria-label":l,title:`${l} (Esc)`,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:e.jsx(Rd,{size:15})})]}),u&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:u}),!p&&!u&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:m,src:p?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return T?zr.createPortal(M,document.body):M}),Bd="termdock-file-search-match",yi="termdock-file-search-current";function Sp(t){const n=t.metaKey||t.ctrlKey,s=t.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||t.key==="F3"?t.shiftKey?"previous":"next":t.key==="Escape"?"close":null}function jp(t){return t.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Rp(t,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let c="",d=null;const h=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let u=h.nextNode();u;u=h.nextNode()){if(!(u instanceof Text)||!u.data)continue;const w=jp(u);if(!w)continue;d&&d!==w&&(c+=`
|
|
1638
|
+
`);const y=c.length;c+=u.data,l.push({node:u,start:y,end:c.length,group:w}),d=w}const m=c.toLocaleLowerCase(),p=[];let g=0;for(;g<=m.length-s.length;){const u=m.indexOf(s,g);if(u<0)break;const w=u+s.length,y=l.find(T=>T.start<=u&&T.end>u),E=l.find(T=>T.start<w&&T.end>=w);if(y&&E&&y.group===E.group){const T=document.createRange();T.setStart(y.node,u-y.start),T.setEnd(E.node,w-E.start),p.push(T)}g=u+Math.max(s.length,1)}return p}function Od(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Ca(){const t=Od();t?.delete(Bd),t?.delete(yi)}function Wc(t,n){const s=Od();if(!s||typeof Highlight>"u")return;s.set(Bd,new Highlight(...t));const l=t[n];l?s.set(yi,new Highlight(l)):s.delete(yi)}function Gc(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Cp(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Np(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Mp(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function Ud(t,n,s){return n?t:zr.createPortal(t,s)}const Ti="termdock:right-sidebar:file-tree-scroll:v1",Ii="termdock:right-sidebar:file-preview-reading-state:v1",bs="termdock:right-sidebar:file-tree-width:v1",Hd="termdock:right-sidebar:markdown-view-mode:v1",zd="termdock:right-sidebar:diff-change-list-mode:v1",Wd="termdock:right-sidebar:diff-wrap:v1",Gd="termdock:diff-viewer:view-type:v1",qd="termdock:right-sidebar:file-search-mode:v1",qo="termdock:right-sidebar:collapsed-git-repo-groups:v1",qc="termdock:right-sidebar:collapsed-diff-directories:v1",Ko="termdock:right-sidebar:branch-audit-module-open:v1",Kd="termdock:right-sidebar:branch-audit-module:v1",$p=150,Vd="termdock:right-sidebar:active-git-repo:v1",Kc="termdock:right-sidebar:context-draft-enabled:v1",Vc="termdock:right-sidebar:context-draft-collapsed:v1",Yc="termdock:right-sidebar:context-draft-auto-collapse:v1",Vo="termdock:right-sidebar:context-draft-text:v1",Ep=300,Lp=20,Ap=120,Pp=250,Tp=250,Ip=120,_p=700,Yo=600,Xc=[2e3,5e3,15e3,3e4],Dp=320,Fp=500,Bp=20,Op=12e3,wi=300,Jc=240,Up=560,Yd="border-r px-2 py-1.5 sm:px-3 sm:py-2",Fa="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Xd=`${Yd} border-b border-border/15 font-semibold last:border-r-0`,Jd=`${Yd} border-border/10 align-top text-muted-foreground last:border-r-0`,_i="termdock-file-preview-horizontal-scroll",Qc=o.lazy(()=>js(()=>import("./ModelPreview-BV_0H-Ls.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Qd=`${_i} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Zd(t,n,s){return t&&!n?"unified":s}const Hp=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function zp(t){return t==="preview"||t==="source"}function Wp(t){return t==="list"||t==="tree"||t==="ai"}function Zc(){return Ze(Hd,zp)??"preview"}function Gp(){return Ze(zd,Wp)??"tree"}function xs(t){return typeof t=="boolean"}function qp(t){return typeof t=="string"}function Kp(){return Ze(Wd,xs)??!0}function Vp(t){return t==="unified"||t==="split"}function Yp(){return Ze(Gd,Vp)??"unified"}function Xp(t){return t==="name"||t==="content"||t==="regex"}function Jp(){return Ze(qd,Xp)??"name"}function eu(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:ut(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function Qp(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function tu(){return Ze(Vd,Qp)??{}}function ed(t){if(!t)return;const n=tu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function Xo(t,n){t&>(Vd,{...tu(),[t]:n})}function Zp(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function ki(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function td(t){const n=Ze(t,ki);return n?new Set(n):new Set}function Jo(t,n){gt(t,[...n])}function eg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function tg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||ki(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(eg))&&(n.commits===void 0||ki(n.commits))&&(n.commitCount===void 0||typeof n.commitCount=="number")&&(n.diff===void 0||typeof n.diff=="string")&&(n.truncated===void 0||typeof n.truncated=="boolean")&&(n.error===void 0||typeof n.error=="string")}function rg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&tg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function ng(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(rg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function rd(){return Ze(Kd,ng)??{}}function nd(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function sd(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function ru(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||sd(s)===sd(l)}function ad(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!ru(l,n))??""}function Si(t,n){const s=Math.max(Jc,n-320),l=Math.min(Up,s);return Math.min(l,Math.max(Jc,t))}function sg(t){return typeof t=="number"&&Number.isFinite(t)}function ag(t){return Si(Ze(bs,sg)??wi,t)}function nu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function ms(t){return Hp.has(nu(t))}function su(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function ji(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||su(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function og(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const au=o.createContext(null);function Ia(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function ou(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function iu(t){return t.replace(/\s+#+\s*$/,"").trim()}function Ri(t,n){const l=ou(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",c=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,c+1),c===0?l:`${l}-${c}`}function od(t){return ou(t)||t.trim()}function Ba(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ni(n[2]);return s?{id:Ia(n[1]),definition:{href:s.href,title:s.title}}:null}function ig(t){const n=new Map;for(const s of t){const l=Ba(s);l&&n.set(l.id,l.definition)}return n}function lu(t){return t.trim().toLowerCase()}function cu(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:lu(n[1]),text:n[2]}:null}function lg(t){const n=new Map;let s=null;for(const l of t){const c=cu(l);if(c){s=c.id,n.set(c.id,{id:c.id,text:c.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const d=n.get(s);d&&(d.text=`${d.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function du(t){const n=new Set;let s=!1;return t.forEach((l,c)=>{if(cu(l)){n.add(c),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(c);return}l.trim()&&(s=!1)}),n}function cg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const c=t[s].trim();if(c.startsWith("<!--")){if(n[s]="",!c.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function uu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function ws(t){const n=t.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const d of n.split("/"))if(!(!d||d===".")){if(d===".."){l.length>0&&l.pop();continue}l.push(d)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function fu(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const c=l.indexOf("#"),d=c>=0?l.slice(0,c):l,h=c>=0?l.slice(c+1):"",m=d.split("?",1)[0];if(!m)return null;let p,g=null;try{p=decodeURIComponent(m),g=h?decodeURIComponent(h):null}catch{return null}const u=s?ws(s):null;let w;if(p.startsWith("/")){const y=u&&(p===u||p.startsWith(`${u}/`));w=ws(u&&!y?`${u}/${p.slice(1)}`:p)}else{if(!n)return null;w=ws(`${uu(n)}/${p}`)}return u&&w!==u&&!w.startsWith(`${u}/`)?null:{path:w,fragment:g,directory:/\/$/.test(m)}}function dg(t,n,s){const l=t.trim();if(!l||/^(?:javascript|data):/i.test(l))return null;if(/^https?:\/\//i.test(l))return l;if(!xd(l.split(/[?#]/,1)[0]))return null;let c;if(l.startsWith("/")){const d=s&&(l===s||l.startsWith(`${s}/`));c=ws(s&&!d?`${s}/${l.slice(1)}`:l)}else{if(!n)return null;c=ws(`${uu(n)}/${l}`)}return`/api/terminal/fs/blob?path=${encodeURIComponent(c)}`}const Ci=128,ug=360,Qo=480;function qa(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function hu(t,n,s,l){if(!n||!s)return null;let c,d;return qa(t)?(d=Math.min(Math.max(s,Ci),ug),c=n*d/s):(c=n,d=s),l>0&&c>l&&(d=d*l/c,c=l),d>Qo&&(c=c*Qo/d,d=Qo),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(d))}}function fg(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function mu(t){const n=fg(t),s=oe(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function hg({src:t,alt:n,title:s}){const l=qa(t),c=mu(t),d=Pi(c),h=o.useRef(null),[m,p]=o.useState(!1),[g,u]=o.useState(0),[w,y]=o.useState({status:"loading"}),[E,T]=o.useState(null);o.useLayoutEffect(()=>{const R=h.current,M=R?.parentElement?.parentElement??R?.parentElement;if(!M)return;const L=()=>u(M.clientWidth);if(L(),typeof ResizeObserver>"u")return;const A=new ResizeObserver(L);return A.observe(M),()=>A.disconnect()},[]),o.useEffect(()=>{if(m)return;const R=h.current;if(!R||typeof IntersectionObserver>"u"){p(!0);return}const M=new IntersectionObserver(L=>{L.some(A=>A.isIntersecting)&&(p(!0),M.disconnect())},{rootMargin:"400px"});return M.observe(R),()=>M.disconnect()},[m]),o.useEffect(()=>{if(!m)return;const R=new AbortController;let M=null;y({status:"loading"});const L=window.setTimeout(()=>{R.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Mh(c,{signal:R.signal}).then(async A=>{if(!A.ok)throw new Error(`HTTP ${A.status}`);const z=Number(A.headers.get("X-Image-Width"))||0,D=Number(A.headers.get("X-Image-Height"))||0;return{blob:await A.blob(),width:z,height:D}}).then(({blob:A,width:z,height:D})=>{R.signal.aborted||(M=URL.createObjectURL(A),z>0&&D>0&&T({width:z,height:D}),y({status:"ready",objectUrl:M}))}).catch(()=>{const A=R.signal.reason;R.signal.aborted&&!(A instanceof DOMException&&A.name==="TimeoutError")||y({status:"fallback"})}).finally(()=>{window.clearTimeout(L)}),()=>{window.clearTimeout(L),R.abort(),M&&URL.revokeObjectURL(M)}},[m,c]);const _=hu(t,E?.width??0,E?.height??0,g),U=_??{width:Ci*2,height:Ci};return e.jsx("div",{ref:h,className:"block max-w-full",style:_?{width:_.width,height:_.height}:void 0,children:w.status==="ready"?e.jsx("img",{src:w.objectUrl,alt:n,title:s,decoding:"async",className:`${l?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:_?{width:_.width,height:_.height}:void 0,onLoad:R=>{if(E)return;const M=R.currentTarget;M.naturalWidth>0&&M.naturalHeight>0&&T({width:M.naturalWidth,height:M.naturalHeight})}}):w.status==="fallback"?e.jsx("img",{src:d,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:_?{width:_.width,height:_.height}:void 0,onLoad:R=>{if(E)return;const M=R.currentTarget;M.naturalWidth>0&&M.naturalHeight>0&&T({width:M.naturalWidth,height:M.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:U.width,height:U.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function Zo(t,n,s,l,c){const d=dg(s,c.markdownFilePath,c.rootPath);if(!d)return``;const h=c.images.length;c.images.push({kind:"image",src:d,alt:n,title:l});const m=e.jsx(hg,{src:d,alt:n,title:l});return c.onImageOpen?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:p=>{p.stopPropagation(),c.onImageOpen?.(h)},children:m},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:m},t)}function ei(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function id(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Ni(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const pu="",mg=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function pg(t){return t.replace(mg,(n,s)=>`${pu}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ld(t){return t.replace(new RegExp(`${pu}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function gg(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const gu={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Na=null;function bu(){return Na||(Na=js(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw Na=null,t})),Na}function xu({html:t}){const{t:n}=xt(),[s,l]=o.useState(null);return o.useEffect(()=>{let c=!1;return l(null),bu().then(d=>{c||l(d.sanitize(t,gu))}).catch(()=>{c||l("")}),()=>{c=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function bg({html:t}){const[n,s]=o.useState(null);return o.useEffect(()=>{let l=!1;return s(null),bu().then(c=>{l||s(c.sanitize(t,gu))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function vu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Ma=null;function xg(){return Ma||(Ma=Promise.all([js(()=>import("./katex-DnlPpQZa.js"),[]),js(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Ma=null,t})),Ma}function Cs({tex:t,display:n=!1}){const[s,l]=o.useState(null),[c,d]=o.useState(!1);if(o.useEffect(()=>{let m=!1;return l(null),d(!1),xg().then(p=>{m||l(p.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||d(!0)}),()=>{m=!0}},[n,t]),c)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function vg(t,n,s){if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(bg,{html:t},n):null;const c=l[1].toLowerCase(),d=et(l[2],`${n}-${c}`,!0,s);return c==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:d},n):c==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:d},n):c==="sub"?e.jsx("sub",{children:d},n):e.jsx("sup",{children:d},n)}function et(t,n,s=!0,l){const c=pg(t),d=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let m=0,p;for(;(p=d.exec(c))!==null;){p.index>m&&h.push(ld(c.slice(m,p.index)));const g=p[0],u=`${n}-${p.index}`,w=g.startsWith("<")?vg(g,u,l):null;if(w)h.push(w);else if(g.startsWith("\\(")&&g.endsWith("\\)"))h.push(e.jsx(Cs,{tex:g.slice(2,-2)},u));else if(g.startsWith("$")&&g.endsWith("$"))h.push(e.jsx(Cs,{tex:g.slice(1,-1)},u));else if(g.startsWith("`")){const y=g.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:gg(g.slice(y,-y))},u))}else if(g.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:et(g.slice(2,-2),`${u}-del`,s,l)},u));else if(g.startsWith("**")||g.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:et(g.slice(2,-2),`${u}-strong`,s,l)},u));else if(g.startsWith("*")||g.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:et(g.slice(1,-1),`${u}-em`,s,l)},u));else if(g.startsWith("![")){const y=g.match(/^!\[([^\]]*)\]\((.*)\)$/),E=g.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),T=g.match(/^!\[([^\]]+)\]$/);if(y){const _=Ni(y[2]);h.push(_?Zo(u,y[1],_.href,_.title,l):g)}else if(E){const _=E[2]||E[1],U=l.referenceDefinitions.get(Ia(_));h.push(U?Zo(u,E[1],U.href,U.title,l):g)}else if(T){const _=l.referenceDefinitions.get(Ia(T[1]));h.push(_?Zo(u,T[1],_.href,_.title,l):g)}else h.push(g)}else if(g.startsWith("[^")){const y=lu(g.slice(2,-1)),E=l.footnoteDefinitions.get(y);h.push(E?e.jsx("sup",{id:`fnref-${E.id}`,title:E.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${E.id}`,className:"text-primary no-underline",children:E.index})},u):g)}else if(g.startsWith("<http")){const y=g.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u))}else if(g.startsWith("<")&&g.endsWith(">")&&id(g.slice(1,-1))){const y=g.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u))}else if(id(ei(g).linkText)){const{linkText:y,suffix:E}=ei(g);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u)),E&&h.push(E)}else if(g.startsWith("http")||g.startsWith("www.")){const{linkText:y,suffix:E}=ei(g),T=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:T,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},u)),E&&h.push(E)}else{const y=g.match(/^\[([^\]]+)\]\((.*)\)$/),E=g.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),T=g.match(/^\[([^\]]+)\]$/),_=E?E[2]||E[1]:T?.[1]??null,U=_?l.referenceDefinitions.get(Ia(_)):null,R=y?Ni(y[2]):null,M=R?.href??U?.href??null,L=M?og(M):null,A=y?.[1]??E?.[1]??T?.[1]??"";h.push(L?e.jsx("a",{href:L,title:R?.title??U?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:et(A,`${u}-link`,s,l)},u):g)}m=d.lastIndex}return m<c.length&&h.push(ld(c.slice(m))),h.length>0?h:[t]}function yu(t){return/(?: {2,}|\\)$/.test(t)}function wu(t){return t.replace(/(?: {2,}|\\)$/,"")}function Oa(t){return/^(?: {4}|\t)/.test(t)}function ku(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function Su(t,n,s){const l=[];return t.forEach((c,d)=>{const h=yu(c);l.push(...et(wu(c),`${n}-${d}`,!0,s)),d<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${d}-br`):" ")}),l}function Mi(t,n,s){const l=[],c=[];return t.forEach((d,h)=>{c.push(yu(d)),l.push(et(wu(d),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:c}}function $i(t,n,s,l,c){const d=[];return t.forEach((h,m)=>{const p=s[m]??0,g=!!(c&&p>=c.start&&p<=c.end);d.push(e.jsx("span",{"data-md-ref-start":p,"data-md-ref-end":p,"data-selected":g?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&d.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),d}function Ns(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",c=!1,d=0,h=0;for(let m=0;m<n.length;m+=1){const p=n[m];if(c){l+=p,c=!1;continue}if(p==="\\"){c=!0;continue}if(p==="`"){const g=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const u=m-g+1;l+="`".repeat(u),d===0?d=u:d===u&&(d=0);continue}if(d===0&&p==="["?h+=1:d===0&&p==="]"&&h>0&&(h-=1),p==="|"&&d===0&&h===0){s.push(l.trim()),l="";continue}l+=p}return c&&(l+="\\"),s.push(l.trim()),s}function ju(t){return Ns(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Ua(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Ha(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function Ru(t,n){return t>96||t>44&&n>.35}function Ka(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Ms(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function Di(t,n,s,l,c,d=new Set){const h=[],m=[];let p=n;for(;p<t.length;){const g=t[p];if(c&&(Ba(g)||d.has(p))){p+=1;continue}const u=Ms(g),w=Ka(g);if(!u){if(w>s&&m.length>0){([...m].reverse().find(_=>_.indent<w)?.item??m[m.length-1].item).paragraphs.push(g.trim());for(const _ of m)_.item.lineEnd=p+1;p+=1;continue}break}if(w<s||w===s&&u.ordered!==l)break;const y={content:u.content,ordered:u.ordered,start:u.start,children:[],paragraphs:[],lineStart:p+1,lineEnd:p+1};for(;m.length>0&&m[m.length-1].indent>=w;)m.pop();const E=m[m.length-1]?.item??null;E?E.children.push(y):h.push(y),m.push({indent:w,item:y});for(const T of m)T.item.lineEnd=p+1;p+=1}return{items:h,nextIndex:p}}function yg(t){const n=t.find(l=>Ms(l));if(!n)return[];const s=Ms(n);return s?Di(t,0,Ka(n),s.ordered,!0,du(t)).items:[]}function Fi(t,n,s,l=0){return t.map((c,d)=>{const h=c.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${d}`,taskItem:!!h,refStart:c.lineStart+l,refEnd:c.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,et(h?.[2]??c.content,`li-${n}-${d}`,!0,s),c.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:c.paragraphs.map((m,p)=>e.jsx("p",{children:et(m,`li-${n}-${d}-p-${p}`,!0,s)},`paragraph-${p}`))})]}),groups:wg(c.children,`${n}-${d}`,s,l)}})}function wg(t,n,s,l=0){const c=[];for(const d of t){const h=c[c.length-1];h&&h.ordered===d.ordered?h.items.push(d):c.push({ordered:d.ordered,items:[d]})}return c.map((d,h)=>({ordered:d.ordered,start:d.ordered?d.items[0]?.start:void 0,items:Fi(d.items,`${n}-g${h}`,s,l)}))}function Bi(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&kg(s.groups,n)]},s.key)})}function kg(t,n){return t.map((s,l)=>{const c=s.ordered?"ol":"ul";return e.jsx(c,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Bi(s.items,n)},`nested-${l}`)})}function Sg(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[et(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function jg(t,n,s,l){const c=[];let d=0;const h=m=>l?.[m]??m+1;for(;d<t.length;){const m=t[d],p=m.trim();if(!p){d+=1;continue}if(/^<details>\s*$/i.test(p)){const R=d;let M="Details";const L=[];for(d+=1;d<t.length&&!/^<\/details>\s*$/i.test(t[d].trim());){const A=t[d].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);A?M=A[1].trim()||M:L.push(t[d].trimStart()),d+=1}d<t.length&&(d+=1),c.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:et(M,`${n}-details-${R}-summary`,!0,s)}),L.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Su(L,`${n}-details-${R}`,s)})]},`${n}-details-${R}`)});continue}const g=vu(m);if(g){const R=[m],M=d;for(d+=1;d<t.length&&!g.selfContained&&!new RegExp(`</${g.tag}>`,"i").test(t[d]);)R.push(t[d]),d+=1;d<t.length&&!g.selfContained&&(R.push(t[d]),d+=1),c.push({kind:"static",node:e.jsx(xu,{html:R.join(`
|
|
1639
1639
|
`)},`${n}-html-${M}`)});continue}const u=p.match(/^(```|~~~)\s*(.*)$/);if(u){const R=[],M=u[1],L=u[2]?.trim(),A=d;for(d+=1;d<t.length&&!t[d].trim().startsWith(M);)R.push(t[d]),d+=1;d<t.length&&(d+=1),L.toLowerCase()==="mermaid"?c.push({kind:"static",node:e.jsx(Nu,{code:R.join(`
|
|
1640
1640
|
`),blockKey:`${n}-code-${A}`},`${n}-code-${A}`)}):["math","latex","tex"].includes(L.toLowerCase())?c.push({kind:"static",node:e.jsx(Cs,{tex:R.join(`
|
|
1641
1641
|
`),display:!0},`${n}-code-${A}`)}):c.push({kind:"code",key:`${n}-code-${A}`,code:R.join(`
|
|
1642
1642
|
`),lang:L,blockKey:`${n}-code-${A}`,codeStartLine:h(A)+1});continue}if(Oa(m)){const R=[],M=d;for(;d<t.length&&(Oa(t[d])||!t[d].trim());)R.push(t[d].trim()?ku(t[d]):""),d+=1;c.push({kind:"code",key:`${n}-indented-code-${M}`,code:R.join(`
|
|
1643
|
-
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${M}`,codeStartLine:h(M)});continue}const w=p.match(/^(#{1,6})\s+(.+)$/);if(w){const M=`h${Math.min(6,w[1].length+1)}`,L=iu(w[2]),A=
|
|
1644
|
-
`).map(g=>[g||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${
|
|
1645
|
-
`:null]},`${s}-line-${u}`)})})})]})}function
|
|
1643
|
+
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${M}`,codeStartLine:h(M)});continue}const w=p.match(/^(#{1,6})\s+(.+)$/);if(w){const M=`h${Math.min(6,w[1].length+1)}`,L=iu(w[2]),A=Ri(L,s);c.push({kind:"static",node:e.jsx(M,{id:A,className:"scroll-mt-16 font-semibold text-foreground",children:et(L,`${n}-heading-${d}`,!0,s)},`${n}-heading-${d}`)}),d+=1;continue}if(d+1<t.length&&m.includes("|")&&Ha(t[d+1])){const R=Ns(m),M=ju(t[d+1]),L=[],A=d;for(d+=2;d<t.length&&t[d].includes("|")&&t[d].trim();)L.push(Ns(t[d])),d+=1;c.push({kind:"static",node:e.jsx("div",{className:Qd,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{children:R.map((z,D)=>e.jsx("th",{className:`${Xd} ${Ua(M[D]??null)}`,children:e.jsx("div",{className:Fa,children:et(z,`${n}-th-${A}-${D}`,!0,s)})},`h-${D}`))})}),e.jsx("tbody",{children:L.map((z,D)=>e.jsx("tr",{className:"border-t border-border/10",children:R.map((a,k)=>e.jsx("td",{className:`${Jd} ${Ua(M[k]??null)}`,children:e.jsx("div",{className:Fa,children:et(z[k]??"",`${n}-td-${A}-${D}-${k}`,!0,s)})},`c-${k}`))},`r-${D}`))})]})},`${n}-table-${A}`)});continue}const y=Ms(m);if(y){const R=y.ordered,M=Ka(m),L=y.start,A=d,z=Di(t,d,M,R,!1);d=z.nextIndex,c.push({kind:"list",keyPrefix:`${n}-list-${A}`,ordered:R,start:R?L:void 0,renders:Fi(z.items,`${n}-list-${A}`,s,h(0)-1)});continue}const E=[m.trimStart()],T=[h(d)],_=d;for(d+=1;d<t.length&&t[d].trim()&&!ji(t[d])&&!(d+1<t.length&&t[d].includes("|")&&Ha(t[d+1]));)E.push(t[d].trimStart()),T.push(h(d)),d+=1;const U=Mi(E,`${n}-p-${_}`,s);c.push({kind:"paragraph",keyPrefix:`${n}-p-${_}`,perLine:U.perLine,hardBreaks:U.hardBreaks,lineNums:T})}return c}function Rg(t,n){return t.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:$i(s.perLine,s.hardBreaks,s.lineNums,s.keyPrefix,n)},s.keyPrefix);case"list":{const l=s.ordered?"ol":"ul";return e.jsx(l,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} space-y-0.5 pl-4 marker:text-muted-foreground/70`,children:Bi(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(za,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let $a=null,cd=!1;const Ea=16,Cu=192;function Cg(){return $a||($a=js(()=>import("./mermaid.core-C8GTgQvN.js").then(t=>t.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(t=>t.default??t).catch(t=>{throw $a=null,t})),$a}function Ng(t){cd||(t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),cd=!0)}function Mg(t){const n=t.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return t;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,c,d]=l;if(!Number.isFinite(c)||!Number.isFinite(d)||c<=0||d<=0)return t;const h=Math.max(Cu,Math.ceil(c)),m=Math.ceil(h/c*d);return t.replace(/<svg\b([^>]*)>/i,(p,g)=>`<svg${g.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${m}">`)}function $g(t){const n=t?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-Ea,c=s.y-Ea,d=s.width+Ea*2,h=s.height+Ea*2,m=Math.max(Cu,Math.ceil(d)),p=Math.ceil(m/d*h);n.setAttribute("viewBox",`${l} ${c} ${d} ${h}`),n.setAttribute("width",String(m)),n.setAttribute("height",String(p)),n.removeAttribute("style")}function Eg(t){const n=t.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return Nd(`code.${s}`)??s}function Nu({code:t,blockKey:n}){const{t:s}=xt(),[l,c]=o.useState(null),[d,h]=o.useState(!1),m=o.useRef(null),p=o.useContext(au);o.useEffect(()=>{let u=!1;return c(null),h(!1),Cg().then(async w=>{Ng(w);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:E}=await w.render(y,t);u||c(Mg(E))}).catch(()=>{u||h(!0)}),()=>{u=!0}},[n,t]),o.useLayoutEffect(()=>{l&&$g(m.current)},[l]);const g=o.useCallback(()=>{const u=m.current?.querySelector("svg")?.outerHTML??l;u&&p?.(u)},[p,l]);return d?e.jsx(za,{code:t,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:u=>{u.stopPropagation(),g()},children:e.jsx("span",{ref:m,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function za({code:t,lang:n,blockKey:s,codeStartLine:l,lineRange:c}){const d=Eg(n),[h,m]=o.useState(null);o.useEffect(()=>{if(!d||!Md(t)){m(null);return}let g=!1;return $d().then(u=>{if(g||!u.registered(d)){g||m(null);return}try{m(Ld(u,t,d))}catch{g||m(null)}}).catch(()=>{g||m(null)}),()=>{g=!0}},[s,t,d]);const p=h??(t||" ").split(`
|
|
1644
|
+
`).map(g=>[g||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${_i} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:p.map((g,u)=>{const w=l!=null?l+u:null,y=!!(c&&w!=null&&w>=c.start&&w<=c.end);return e.jsxs("span",{"data-md-ref-start":w??void 0,"data-md-ref-end":w??void 0,"data-selected":y?"true":void 0,children:[g,u<p.length-1?`
|
|
1645
|
+
`:null]},`${s}-line-${u}`)})})})]})}function Oi(t,n,s,l,c){t=cg(t);const d=ig(t),h=du(t),m=[],p={markdownFilePath:n,rootPath:s,referenceDefinitions:d,footnoteDefinitions:lg(t),headingSlugCounts:new Map,images:m,onImageOpen:l,footnotesLabel:c?.footnotes??"Footnotes",backToFootnoteLabel:c?.backToFootnote??(y=>`Back to footnote ${y}`)},g=[];let u=0;for(;u<t.length;){const y=t[u],E=y.trim();if(Ba(y)||h.has(u)){u+=1;continue}if(!E){u+=1;continue}if(/^<details>\s*$/i.test(E)){const D=u;let a="Details";const k=[];for(u+=1;u<t.length&&!/^<\/details>\s*$/i.test(t[u].trim());){const B=t[u].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);B?a=B[1].trim()||a:k.push(t[u].trimStart()),u+=1}u<t.length&&(u+=1),g.push({key:`details-${D}`,startLine:D+1,endLine:u,content:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:et(a,`details-${D}-summary`,!0,p)}),k.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Su(k,`details-${D}`,p)})]})});continue}const T=vu(y);if(T){const D=[y],a=u;for(u+=1;u<t.length&&!T.selfContained&&!new RegExp(`</${T.tag}>`,"i").test(t[u]);)D.push(t[u]),u+=1;u<t.length&&!T.selfContained&&(D.push(t[u]),u+=1),g.push({key:`html-${a}`,startLine:a+1,endLine:u,content:e.jsx(xu,{html:D.join(`
|
|
1646
1646
|
`)})});continue}const _=E.match(/^(```|~~~)\s*(.*)$/);if(_){const D=[],a=_[1],k=_[2]?.trim(),B=u;for(u+=1;u<t.length&&!t[u].trim().startsWith(a);)D.push(t[u]),u+=1;u<t.length&&(u+=1),g.push({key:`code-${B}`,startLine:B+1,endLine:u,fineGrained:k.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(k.toLowerCase()),content:k.toLowerCase()==="mermaid"?e.jsx(Nu,{code:D.join(`
|
|
1647
1647
|
`),blockKey:`code-${B}`}):["math","latex","tex"].includes(k.toLowerCase())?e.jsx(Cs,{tex:D.join(`
|
|
1648
1648
|
`),display:!0}):j=>e.jsx(za,{code:D.join(`
|
|
1649
1649
|
`),lang:k,blockKey:`code-${B}`,codeStartLine:B+2,lineRange:j})});continue}if(Oa(y)){const D=[],a=u;for(u+=0;u<t.length&&(Oa(t[u])||!t[u].trim());)D.push(t[u].trim()?ku(t[u]):""),u+=1;g.push({key:`indented-code-${a}`,startLine:a+1,endLine:u,fineGrained:!0,content:k=>e.jsx(za,{code:D.join(`
|
|
1650
1650
|
`).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${a}`,codeStartLine:a+1,lineRange:k})});continue}if(E.startsWith("$$")){const D=[],a=u,k=E.replace(/^\$\$\s*/,"");if(k.endsWith("$$")&&k.length>2)D.push(k.replace(/\s*\$\$$/,"")),u+=1;else{for(k&&D.push(k),u+=1;u<t.length&&!t[u].trim().endsWith("$$");)D.push(t[u]),u+=1;if(u<t.length){const B=t[u].trim().replace(/\s*\$\$$/,"");B&&D.push(B),u+=1}}g.push({key:`math-${a}`,startLine:a+1,endLine:u,content:e.jsx(Cs,{tex:D.join(`
|
|
1651
|
-
`),display:!0})});continue}if(u+1<t.length&&E&&!Si(y)&&/^(=+|-+)\s*$/.test(t[u+1].trim())){const D=t[u+1].trim().startsWith("=")?1:2,a=`h${D}`,k=ji(E,p),B={level:D,text:od(E),id:k};g.push({key:`setext-heading-${u}`,startLine:u+1,endLine:u+2,heading:B,content:e.jsx(a,{id:k,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:et(E,`setext-heading-${u}`,!0,p)})}),u+=2;continue}const U=E.match(/^(#{1,6})\s+(.+)$/);if(U){const D=U[1].length,a=iu(U[2]),k={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},B=`h${D}`,j=ji(a,p),Y={level:D,text:od(a),id:j};g.push({key:`heading-${u}`,startLine:u+1,endLine:u+1,heading:Y,content:e.jsx(B,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${k[D]}`,children:et(a,`heading-${u}`,!0,p)})}),u+=1;continue}if(su(y)){g.push({key:`hr-${u}`,startLine:u+1,endLine:u+1,content:e.jsx("hr",{className:"border-border/20"})}),u+=1;continue}if(E.startsWith(">")){const D=[],a=[],k=u;for(;u<t.length&&/^>\s?/.test(t[u].trim());)D.push(t[u].trim().replace(/^>\s?/,"")),a.push(u+1),u+=1;const B=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(B){const Y=B[1].toUpperCase(),re=B[2]?.trim(),se=[...re?[re]:[],...D.slice(1)],he=[...re?[a[0]]:[],...a.slice(1)],G=Ni(se,`callout-${k}`,p);g.push({key:`callout-${k}`,startLine:k+1,endLine:u,fineGrained:!0,content:J=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:Y}),se.length>0&&e.jsx("div",{children:Mi(G.perLine,G.hardBreaks,he,`callout-${k}`,J)})]})});continue}const j=Sg(D,`quote-${k}`,p,a);g.push({key:`quote-${k}`,startLine:k+1,endLine:u,fineGrained:!0,content:Y=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:jg(j,Y)})});continue}if(u+1<t.length&&y.includes("|")&&Ha(t[u+1])){const D=Ns(y),a=ju(t[u+1]),k=[],B=u;for(u+=2;u<t.length&&t[u].includes("|")&&t[u].trim();)k.push(Ns(t[u])),u+=1;const j=D.map((re,se)=>et(re,`th-${B}-${se}`,!0,p)),Y=k.map((re,se)=>D.map((he,G)=>et(re[G]??"",`td-${B}-${se}-${G}`,!0,p)));g.push({key:`table-${B}`,startLine:B+1,endLine:u,interactive:!1,kind:"table",content:re=>{const se=he=>!!(re&&he>=re.start&&he<=re.end);return e.jsx("div",{className:Qd,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":B+1,"data-md-ref-start":B+1,"data-md-ref-end":B+1,"data-selected":se(B+1)?"true":void 0,children:j.map((he,G)=>e.jsx("th",{className:`${Xd} ${Ua(a[G]??null)}`,children:e.jsx("div",{className:Fa,children:he})},`h-${G}`))})}),e.jsx("tbody",{children:Y.map((he,G)=>{const J=B+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":J,"data-md-ref-start":J,"data-md-ref-end":J,"data-selected":se(J)?"true":void 0,children:D.map(($,F)=>e.jsx("td",{className:`${Jd} ${Ua(a[F]??null)}`,children:e.jsx("div",{className:Fa,children:he[F]})},`c-${F}`))},`r-${G}`)})})]})})}});continue}const R=Ms(y);if(R){const D=R.ordered,a=Ka(y),k=R.start,B=u,j=_i(t,u,a,D,!0,h);u=j.nextIndex;const Y=D?"ol":"ul",re=Di(j.items,`list-${B}`,p);g.push({key:`list-${B}`,startLine:B+1,endLine:u,fineGrained:!0,content:se=>e.jsx(Y,{start:D?k:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:Fi(re,se)})});continue}const M=[y.trimStart()],L=[u+1],A=u;for(u+=1;u<t.length&&t[u].trim()&&!Si(t[u])&&!(u+1<t.length&&t[u].includes("|")&&Ha(t[u+1]));){if(Ba(t[u])||h.has(u)){u+=1;continue}M.push(t[u].trimStart()),L.push(u+1),u+=1}const z=Ni(M,`p-${A}`,p);g.push({key:`p-${A}`,startLine:A+1,endLine:u,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:Mi(z.perLine,z.hardBreaks,L,`p-${A}`,D)})})}const w=kg(p);return w&&g.push({key:"footnotes",startLine:t.length,endLine:t.length,content:w}),{blocks:g,images:m}}function Eg(t,n,s){return Bi(t,n,s).blocks}function Mu(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function $u(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Lg({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const c=mu(t);return e.jsx(Hu,{src:c,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Eu({images:t,index:n,onChange:s,onClose:l}){const{t:c}=xt(),d=t[n],h=t.length>1,m=o.useRef(null),p=o.useRef(null),g=o.useRef(null),u=o.useRef(0),[w,y]=o.useState(!1),[E,T]=o.useState(0),[_,U]=o.useState(!1),R=o.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),M=o.useCallback(()=>{w||Date.now()<u.current||(R(),g.current=window.setTimeout(()=>{g.current=null,l()},450))},[R,w,l]),L=o.useCallback(a=>{if(t.length===0)return;const k=(a+t.length)%t.length;m.current?.slideTo(k),s(k)},[t.length,s]),A=o.useCallback(()=>L(n-1),[L,n]),z=o.useCallback(()=>L(n+1),[L,n]);if(o.useEffect(()=>{R(),T(0),U(!1),y(!1)},[R,n]),o.useEffect(()=>{const a=m.current;a&&(a.allowTouchMove=h&&!w)},[h,w]),o.useEffect(()=>{const a=m.current;!a||a.activeIndex===n||a.slideTo(n,0)},[n]),o.useEffect(()=>R,[R]),o.useEffect(()=>{const a=k=>{if(k.key==="Escape"){k.preventDefault(),l();return}h&&(k.key==="ArrowLeft"?(k.preventDefault(),A()):k.key==="ArrowRight"&&(k.preventDefault(),z()))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[h,z,A,l]),wd({onDrag:({movement:[a,k],pinching:B})=>{B||w||Math.abs(k)<Math.abs(a)*1.15&&E===0||(U(!0),Math.abs(k)>8&&(u.current=Date.now()+300),T(Math.max(0,k)))},onDragEnd:({movement:[,a],velocity:[,k]})=>{if(!w){if(U(!1),Math.abs(a)>8&&(u.current=Date.now()+300),Ru(a,k)){l();return}T(0)}}},{target:p,drag:{filterTaps:!0,pointer:{touch:!0}}}),!d)return null;const D=d.title||d.alt||(d.kind==="mermaid"?c("rightSidebar.mermaidDiagram"):c("rightSidebar.image"));return typeof document>"u"?null:zr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:A,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":c("rightSidebar.previousImage"),title:c("common.previous"),children:e.jsx(ks,{size:17})}),e.jsx("button",{type:"button",onClick:z,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":c("rightSidebar.nextImage"),title:c("common.next"),children:e.jsx(dh,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":c("rightSidebar.closeImagePreview"),title:c("common.close"),children:e.jsx(Dt,{size:18})})]})]}),e.jsx("div",{ref:p,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onPointerDown:a=>a.stopPropagation(),onPointerMove:a=>a.stopPropagation(),onTouchStart:a=>a.stopPropagation(),onTouchMove:a=>a.stopPropagation(),onClick:M,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${E}px, 0) scale(${Math.max(.86,1-E/900)})`,opacity:Math.max(.35,1-E/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(kd,{onSwiper:a=>{m.current=a,a.allowTouchMove=h&&!w},onSlideChange:a=>{a.activeIndex!==n&&s(a.activeIndex)},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:t.map((a,k)=>e.jsx(fi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:a.kind==="image"?e.jsx(Lg,{src:a.src,alt:a.alt||a.title||c("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:R}):e.jsx(Kg,{svg:a.svg,title:a.title||a.alt||c("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:R})})},`${a.kind}-${k}-${a.alt}`))})})})]})]}),document.body)}function Lu({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:c,onLineRangeDrag:d,scrollTop:h,outlineOpen:m,outlineCloseSignal:p,onOutlineOpen:g,onOutlineClose:u,lightboxOpen:w,lightboxCloseSignal:y,onLightboxOpen:E,onLightboxClose:T,onLocalLinkOpen:_}){const{t:U}=xt(),[R,M]=o.useState(null),[L,A]=o.useState(null),[z,D]=o.useState(1),[a,k]=o.useState(null),B=o.useRef(null),j=o.useRef(null),{blocks:Y,images:re}=o.useMemo(()=>Bi(t.split(`
|
|
1651
|
+
`),display:!0})});continue}if(u+1<t.length&&E&&!ji(y)&&/^(=+|-+)\s*$/.test(t[u+1].trim())){const D=t[u+1].trim().startsWith("=")?1:2,a=`h${D}`,k=Ri(E,p),B={level:D,text:od(E),id:k};g.push({key:`setext-heading-${u}`,startLine:u+1,endLine:u+2,heading:B,content:e.jsx(a,{id:k,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:et(E,`setext-heading-${u}`,!0,p)})}),u+=2;continue}const U=E.match(/^(#{1,6})\s+(.+)$/);if(U){const D=U[1].length,a=iu(U[2]),k={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},B=`h${D}`,j=Ri(a,p),Y={level:D,text:od(a),id:j};g.push({key:`heading-${u}`,startLine:u+1,endLine:u+1,heading:Y,content:e.jsx(B,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${k[D]}`,children:et(a,`heading-${u}`,!0,p)})}),u+=1;continue}if(su(y)){g.push({key:`hr-${u}`,startLine:u+1,endLine:u+1,content:e.jsx("hr",{className:"border-border/20"})}),u+=1;continue}if(E.startsWith(">")){const D=[],a=[],k=u;for(;u<t.length&&/^>\s?/.test(t[u].trim());)D.push(t[u].trim().replace(/^>\s?/,"")),a.push(u+1),u+=1;const B=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(B){const Y=B[1].toUpperCase(),re=B[2]?.trim(),se=[...re?[re]:[],...D.slice(1)],he=[...re?[a[0]]:[],...a.slice(1)],G=Mi(se,`callout-${k}`,p);g.push({key:`callout-${k}`,startLine:k+1,endLine:u,fineGrained:!0,content:J=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:Y}),se.length>0&&e.jsx("div",{children:$i(G.perLine,G.hardBreaks,he,`callout-${k}`,J)})]})});continue}const j=jg(D,`quote-${k}`,p,a);g.push({key:`quote-${k}`,startLine:k+1,endLine:u,fineGrained:!0,content:Y=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Rg(j,Y)})});continue}if(u+1<t.length&&y.includes("|")&&Ha(t[u+1])){const D=Ns(y),a=ju(t[u+1]),k=[],B=u;for(u+=2;u<t.length&&t[u].includes("|")&&t[u].trim();)k.push(Ns(t[u])),u+=1;const j=D.map((re,se)=>et(re,`th-${B}-${se}`,!0,p)),Y=k.map((re,se)=>D.map((he,G)=>et(re[G]??"",`td-${B}-${se}-${G}`,!0,p)));g.push({key:`table-${B}`,startLine:B+1,endLine:u,interactive:!1,kind:"table",content:re=>{const se=he=>!!(re&&he>=re.start&&he<=re.end);return e.jsx("div",{className:Qd,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":B+1,"data-md-ref-start":B+1,"data-md-ref-end":B+1,"data-selected":se(B+1)?"true":void 0,children:j.map((he,G)=>e.jsx("th",{className:`${Xd} ${Ua(a[G]??null)}`,children:e.jsx("div",{className:Fa,children:he})},`h-${G}`))})}),e.jsx("tbody",{children:Y.map((he,G)=>{const J=B+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":J,"data-md-ref-start":J,"data-md-ref-end":J,"data-selected":se(J)?"true":void 0,children:D.map(($,F)=>e.jsx("td",{className:`${Jd} ${Ua(a[F]??null)}`,children:e.jsx("div",{className:Fa,children:he[F]})},`c-${F}`))},`r-${G}`)})})]})})}});continue}const R=Ms(y);if(R){const D=R.ordered,a=Ka(y),k=R.start,B=u,j=Di(t,u,a,D,!0,h);u=j.nextIndex;const Y=D?"ol":"ul",re=Fi(j.items,`list-${B}`,p);g.push({key:`list-${B}`,startLine:B+1,endLine:u,fineGrained:!0,content:se=>e.jsx(Y,{start:D?k:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:Bi(re,se)})});continue}const M=[y.trimStart()],L=[u+1],A=u;for(u+=1;u<t.length&&t[u].trim()&&!ji(t[u])&&!(u+1<t.length&&t[u].includes("|")&&Ha(t[u+1]));){if(Ba(t[u])||h.has(u)){u+=1;continue}M.push(t[u].trimStart()),L.push(u+1),u+=1}const z=Mi(M,`p-${A}`,p);g.push({key:`p-${A}`,startLine:A+1,endLine:u,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:$i(z.perLine,z.hardBreaks,L,`p-${A}`,D)})})}const w=Sg(p);return w&&g.push({key:"footnotes",startLine:t.length,endLine:t.length,content:w}),{blocks:g,images:m}}function Lg(t,n,s){return Oi(t,n,s).blocks}function Mu(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function $u(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Ag({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const c=mu(t);return e.jsx(Hu,{src:c,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Eu({images:t,index:n,onChange:s,onClose:l}){const{t:c}=xt(),d=t[n],h=t.length>1,m=o.useRef(null),p=o.useRef(null),g=o.useRef(null),u=o.useRef(0),[w,y]=o.useState(!1),[E,T]=o.useState(0),[_,U]=o.useState(!1),R=o.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),M=o.useCallback(()=>{w||Date.now()<u.current||(R(),g.current=window.setTimeout(()=>{g.current=null,l()},450))},[R,w,l]),L=o.useCallback(a=>{if(t.length===0)return;const k=(a+t.length)%t.length;m.current?.slideTo(k),s(k)},[t.length,s]),A=o.useCallback(()=>L(n-1),[L,n]),z=o.useCallback(()=>L(n+1),[L,n]);if(o.useEffect(()=>{R(),T(0),U(!1),y(!1)},[R,n]),o.useEffect(()=>{const a=m.current;a&&(a.allowTouchMove=h&&!w)},[h,w]),o.useEffect(()=>{const a=m.current;!a||a.activeIndex===n||a.slideTo(n,0)},[n]),o.useEffect(()=>R,[R]),o.useEffect(()=>{const a=k=>{if(k.key==="Escape"){k.preventDefault(),l();return}h&&(k.key==="ArrowLeft"?(k.preventDefault(),A()):k.key==="ArrowRight"&&(k.preventDefault(),z()))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[h,z,A,l]),wd({onDrag:({movement:[a,k],pinching:B})=>{B||w||Math.abs(k)<Math.abs(a)*1.15&&E===0||(U(!0),Math.abs(k)>8&&(u.current=Date.now()+300),T(Math.max(0,k)))},onDragEnd:({movement:[,a],velocity:[,k]})=>{if(!w){if(U(!1),Math.abs(a)>8&&(u.current=Date.now()+300),Ru(a,k)){l();return}T(0)}}},{target:p,drag:{filterTaps:!0,pointer:{touch:!0}}}),!d)return null;const D=d.title||d.alt||(d.kind==="mermaid"?c("rightSidebar.mermaidDiagram"):c("rightSidebar.image"));return typeof document>"u"?null:zr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:A,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":c("rightSidebar.previousImage"),title:c("common.previous"),children:e.jsx(ks,{size:17})}),e.jsx("button",{type:"button",onClick:z,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":c("rightSidebar.nextImage"),title:c("common.next"),children:e.jsx(dh,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":c("rightSidebar.closeImagePreview"),title:c("common.close"),children:e.jsx(Dt,{size:18})})]})]}),e.jsx("div",{ref:p,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onPointerDown:a=>a.stopPropagation(),onPointerMove:a=>a.stopPropagation(),onTouchStart:a=>a.stopPropagation(),onTouchMove:a=>a.stopPropagation(),onClick:M,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${E}px, 0) scale(${Math.max(.86,1-E/900)})`,opacity:Math.max(.35,1-E/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(kd,{onSwiper:a=>{m.current=a,a.allowTouchMove=h&&!w},onSlideChange:a=>{a.activeIndex!==n&&s(a.activeIndex)},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:t.map((a,k)=>e.jsx(hi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:a.kind==="image"?e.jsx(Ag,{src:a.src,alt:a.alt||a.title||c("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:R}):e.jsx(Vg,{svg:a.svg,title:a.title||a.alt||c("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:R})})},`${a.kind}-${k}-${a.alt}`))})})})]})]}),document.body)}function Lu({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:c,onLineRangeDrag:d,scrollTop:h,outlineOpen:m,outlineCloseSignal:p,onOutlineOpen:g,onOutlineClose:u,lightboxOpen:w,lightboxCloseSignal:y,onLightboxOpen:E,onLightboxClose:T,onLocalLinkOpen:_}){const{t:U}=xt(),[R,M]=o.useState(null),[L,A]=o.useState(null),[z,D]=o.useState(1),[a,k]=o.useState(null),B=o.useRef(null),j=o.useRef(null),{blocks:Y,images:re}=o.useMemo(()=>Oi(t.split(`
|
|
1652
1652
|
`),n,s,S=>{A(null),M(S),E?.()},{footnotes:U("rightSidebar.footnotes"),backToFootnote:S=>U("rightSidebar.backToFootnote",{index:S})}),[t,n,s,E,U]),se=o.useMemo(()=>L?[...re,L]:re,[re,L]),he=o.useCallback(S=>{A({kind:"mermaid",svg:S,alt:"Mermaid diagram",title:"Mermaid diagram"}),M(re.length),E?.()},[re.length,E]);o.useEffect(()=>{M(null),A(null)},[t,n]),o.useEffect(()=>{M(null),A(null)},[y]),o.useEffect(()=>{w||(M(null),A(null))},[w]),o.useEffect(()=>{D(1)},[t,n]),o.useLayoutEffect(()=>{const S=B.current;if(!S||Y.length===0)return;const X=Array.from(S.querySelectorAll("[data-markdown-preview-block-start]"));let ke=1;const xe=28;for(const De of X)if(De.offsetTop-h<=xe)ke=Number(De.dataset.markdownPreviewBlockStart)||ke;else break;D(De=>De===ke?De:ke)},[Y,h]);const G=o.useMemo(()=>Mu(Y,z),[z,Y]),J=o.useMemo(()=>$u(Y),[Y]),$=`${n??""}
|
|
1653
|
-
${t}`,F=o.useRef($),V=o.useRef(null),te=o.useRef(null),ie=o.useRef(!1);o.useEffect(()=>{F.current!==$&&(F.current=$,u?.())},[u,$]),o.useEffect(()=>{p!==void 0&&k(null)},[p]),o.useLayoutEffect(()=>{if(!m){k(null);return}const S=()=>{const X=j.current;if(!X)return;const ke=X.getBoundingClientRect(),xe=window.innerWidth;k({top:ke.bottom+6,right:Math.max(8,xe-ke.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[m,h,G]);const me=o.useCallback(S=>{const X=B.current,ke=X?.closest("[data-markdown-preview-scroller]"),xe=X?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!ke||!xe)return;const De=ke.getBoundingClientRect(),ue=xe.getBoundingClientRect(),Le=X?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,W=ue.top-De.top+ke.scrollTop;ke.scrollTo({top:Math.max(0,W-Le-8),behavior:"smooth"}),D(S.startLine),u?.()},[u]),pe=o.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||oi(S.target)||(V.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),je=o.useCallback((S,X,ke)=>{const xe=V.current;if(V.current=null,!xe||xe.pointerId!==S.pointerId)return;const De=Math.abs(S.clientX-xe.startX),ue=Math.abs(S.clientY-xe.startY);if(De>8||ue>8)return;const qe=S.target;if(oi(qe)||Ei())return;const Le=bd(qe,X,ke);c(S,Le.start,Le.end)},[c]),N=o.useCallback(S=>{V.current?.pointerId===S.pointerId&&(V.current=null)},[]),Z=o.useCallback((S,X)=>{const ke=B.current;if(!ke||typeof document.elementFromPoint!="function")return null;const xe=document.elementFromPoint(S,X);if(!(xe instanceof HTMLElement)||!ke.contains(xe))return null;const De=xe.closest("[data-md-ref-start]");if(De){const Se=Number(De.dataset.mdRefStart);if(Number.isFinite(Se)&&Se>0)return Se}const ue=xe.closest("[data-markdown-preview-block-start]");if(!ue)return null;const qe=Number(ue.dataset.markdownPreviewBlockStart),Le=Y.find(Se=>Se.startLine===qe);if(!Le)return Number.isFinite(qe)&&qe>0?qe:null;if(Le.endLine<=Le.startLine)return Le.startLine;const W=ue.getBoundingClientRect(),K=W.height>0?Math.min(1,Math.max(0,(X-W.top)/W.height)):0;return Math.round(Le.startLine+K*(Le.endLine-Le.startLine))},[Y]),de=o.useCallback(S=>{if(!d||S.pointerType==="mouse"&&S.button!==0)return;const X=Z(S.clientX+24,S.clientY);if(X!=null){te.current={pointerId:S.pointerId,anchorLine:X,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[d,Z]),Ee=o.useCallback(S=>{const X=te.current;if(!X||X.pointerId!==S.pointerId||!d)return;const ke=Z(S.clientX+16,S.clientY);ke!=null&&(!X.moved&&ke===X.anchorLine||(X.moved=!0,ie.current=!0,d(S,Math.min(X.anchorLine,ke),Math.max(X.anchorLine,ke),"move")))},[d,Z]),ze=o.useCallback(S=>{const X=te.current;if(te.current=null,!X||X.pointerId!==S.pointerId||!d||!X.moved)return;const ke=Z(S.clientX+16,S.clientY)??X.anchorLine;d(S,Math.min(X.anchorLine,ke),Math.max(X.anchorLine,ke),"end")},[d,Z]),Pe=o.useCallback(S=>{te.current?.pointerId===S.pointerId&&(te.current=null)},[]),ce={onPointerDown:de,onPointerMove:Ee,onPointerUp:ze,onPointerCancel:Pe},ne=()=>ie.current?(ie.current=!1,!0):!1;return Y.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:U("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:B,className:"relative min-w-0 max-w-full",onClickCapture:S=>{const X=S.target instanceof Element?S.target.closest("a[href]"):null;if(!X||!_)return;const ke=X.getAttribute("href");if(!ke)return;const xe=fu(ke,n,s);xe&&(S.preventDefault(),_(xe))},children:[G.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:G.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:G[G.length-1].text}),J.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?u?.():g?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":U("rightSidebar.markdownOutline"),title:U("rightSidebar.markdownOutline"),children:[e.jsx(Sd,{size:12}),e.jsx("span",{children:U("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&zr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:u}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:a?{top:`${a.top}px`,right:`${a.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:J.map(S=>{const X=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>me(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${X?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:U("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":U("rightSidebar.closeMarkdownOutline"),title:U("common.close"),children:e.jsx(Dt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:J.map(S=>{const X=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>me(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${X?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(au.Provider,{value:he,children:Y.map(S=>{const X=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),ke=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),xe=S.kind==="table"?!1:S.fineGrained?ke:X,De=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let ue=null;if(S.kind!=="table"&&S.fineGrained&&X&&!ke&&l){const K=S.endLine-S.startLine+1,Se=Math.max(l.start,S.startLine),Re=Math.min(l.end,S.endLine),ot=(Se-S.startLine)/K,Ke=(Re-Se+1)/K;ue=e.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${ot})`,height:`calc((100% - 0.5rem) * ${Ke})`}})}const qe=typeof S.content=="function"?S.content(l):S.content,Le=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,W=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:ni(xe),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:si(xe)}),ue]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:qe})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${xe?"bg-primary/10":""}`,title:`Line ${Le}`,"aria-label":`Line ${Le}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:ni(De,"self"),onClick:K=>{K.preventDefault(),!ne()&&c(K,S.startLine,S.endLine)},title:`Reference table lines ${Le}`,"aria-label":`Reference table lines ${Le}`,...ce,children:e.jsx("span",{className:si(De,"self")})}):e.jsxs("span",{className:ni(xe,"none"),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:si(xe,"none")}),ue]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:K=>je(K,S.startLine,S.endLine),onPointerCancel:N,onKeyDown:K=>{K.key!=="Enter"&&K.key!==" "||(K.preventDefault(),c(K,S.startLine,S.endLine))},title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:qe})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:K=>{const Se=K.target;if(oi(Se)||Ei()||ne())return;const Re=bd(Se,S.startLine,S.endLine);c(K,Re.start,Re.end)},onKeyDown:K=>{K.key!=="Enter"&&K.key!==" "||(K.preventDefault(),c(K,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${xe?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:W},S.key)})})})]}),w&&R!==null&&se[R]&&e.jsx(Eu,{images:se,index:R,onChange:M,onClose:()=>{M(null),A(null),T?.()}})]})}function Un({label:t,value:n,options:s,placeholder:l,searchPlaceholder:c,emptyText:d,disabled:h,onChange:m}){const{t:p}=xt(),[g,u]=o.useState(!1),[w,y]=o.useState(""),[E,T]=o.useState(null),_=o.useRef(null),U=o.useRef(null),R=w.trim().toLowerCase(),M=o.useMemo(()=>R?s.filter(a=>`${a.label} ${a.meta??""}`.toLowerCase().includes(R)):s,[R,s]),L=s.find(a=>a.value===n),A=()=>{const a=w.trim();a&&(m(a),u(!1),y(""))},z=o.useCallback(()=>{const a=_.current?.getBoundingClientRect();if(!a)return!1;const k=12,B=Math.max(220,Math.min(a.width,window.innerWidth-k*2)),j=Math.min(Math.max(k,a.left),window.innerWidth-B-k),Y=window.innerHeight-a.bottom-k,re=a.top-k,se=Y>=180||Y>=re,he=Math.max(96,(se?Y:re)-4),G=Math.min(320,he);return T({left:j,top:se?a.bottom+4:Math.max(k,a.top-G-4),width:B,maxHeight:G}),!0},[]),D=()=>{z(),u(!0)};return o.useEffect(()=>{if(!g)return;let a=0;const k=()=>{a||(a=window.requestAnimationFrame(()=>{a=0,z()}))},B=j=>{const Y=j.target;Y instanceof Node&&(_.current?.contains(Y)||U.current?.contains(Y)||(u(!1),y("")))};return window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),document.addEventListener("pointerdown",B,!0),()=>{a&&window.cancelAnimationFrame(a),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("pointerdown",B,!0)}},[g,z]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),g){u(!1);return}D()}},className:"group flex w-full items-center justify-between gap-2 rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-left transition hover:bg-surface-elevated disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("span",{className:`block truncate text-[12px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:L?.label??(n||l)})]}),e.jsx(Ss,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${g?"rotate-180":""}`})]}),g&&!h&&typeof document<"u"&&zr.createPortal(e.jsxs("div",{ref:U,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:a=>a.stopPropagation(),style:{left:E?.left??12,top:E?.top??12,width:E?.width??260,maxHeight:E?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(zn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:w,onChange:a=>y(a.target.value),onKeyDown:a=>{if(a.key==="Escape"){a.preventDefault(),u(!1),y("");return}a.key==="Enter"&&(a.preventDefault(),A())},onBlur:()=>{w.trim()&&M.length===0&&A()},placeholder:c,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(E?.maxHeight??320)-46)},children:[w.trim()&&!s.some(a=>a.value===w.trim())&&e.jsxs("button",{type:"button",onMouseDown:a=>a.preventDefault(),onClick:A,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:w.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:p("common.use")})]}),M.length>0?M.map(a=>e.jsxs("button",{type:"button",onClick:()=>{m(a.value),u(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${a.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:a.label}),a.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:a.meta})]},a.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:d})]})]}),document.body)]})}function dd({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:c,selectedRoots:d,onToggleRepo:h,onGenerate:m,onSecondaryAction:p,disabled:g,generateDisabled:u,secondaryDisabled:w,inserted:y,buttonLabel:E,insertedLabel:T,title:_,ariaLabel:U,scopeTitle:R,scopeLabel:M,allLabel:L,generateLabel:A,secondaryLabel:z,secondaryTitle:D,secondaryLoading:a,loading:k,error:B,statusTitle:j,extraContent:Y,renderRepoExtra:re}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):u||m()},disabled:g,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${B?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":U,title:j??(s?`${R}: ${M}`:_),children:[k?e.jsx(nt,{size:13,className:"animate-spin"}):e.jsx(Rs,{size:13}),e.jsx("span",{children:y?T:E}),s&&e.jsx(Ss,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),B&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&zr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>n(!1),children:e.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:se=>se.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:R}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:M})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Dt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[Y,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:L}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),c.map(se=>{const he=d.includes(se.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${he?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(se.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${he?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:se.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:se.label}),se.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:se.branch})]}),he&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),re&&(l||he)&&e.jsx("div",{className:"px-2 pb-2",children:re(se)})]},se.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${p&&z?"sm:grid-cols-2":""}`,children:[p&&z&&e.jsxs("button",{type:"button",onClick:()=>{w||(n(!1),p())},disabled:w,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[a?e.jsx(nt,{size:12,className:"animate-spin"}):e.jsx(Ed,{size:12}),z]}),e.jsxs("button",{type:"button",onClick:()=>{u||(n(!1),m())},disabled:u,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Rs,{size:12}),A]})]})]})}),document.body)]})}function Ag(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Au(){return Ze(Pi,Ag)??{}}function Pg(t,n){const s=Au(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,c],[,d])=>d.updatedAt-c.updatedAt).slice(0,Ep);vs(Pi,Object.fromEntries(l),Ap)}function Tg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function Ig(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!Tg(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Oi(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Pu(){return Ze(Ti,Ig)??{}}function ud(t,n){const s=Oi(t,n);return s?Pu()[s]??null:null}function ei(t,n,s){const l=Oi(t,n);if(!l)return;const c=Pu(),d=c[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...c,[l]:{...d,...s,updatedAt:Date.now()}}).sort(([,m],[,p])=>p.updatedAt-m.updatedAt).slice(0,Lp);vs(Ti,Object.fromEntries(h),Pp)}function ti({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function ps({slow:t}){const{t:n}=xt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:[e.jsx(nt,{size:20,className:"mx-auto mb-2 animate-spin text-muted-foreground/80"}),e.jsx("div",{children:n("rightSidebar.loadingGitChanges")}),t&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground/75",children:n("rightSidebar.loadingGitChangesSlow")})]})}function La({message:t,onRetry:n}){const{t:s}=xt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function _a(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function ut(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function ri(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function $i(t,n,s){const l=Math.min(n,s),c=Math.max(n,s);return t?.start===l&&t.end===c?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,c)}:{start:l,end:c}}function _g(t,n,s){return $i(t,n,s)}function ni(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function si(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function fd(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function Tu(t){const n=new Map;for(const s of t)n.set(Ui(s),s);return n}function Iu(t,n){const s=new Map(t);for(const l of n)s.set(Ui(l),l);return s}function hd(t,n){let s=0;for(const l of t){const c=pt(l,n);c&&n&&c!==n&&(s+=1)}return s}function Dg(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function Fg(t,n){return Array.from(Iu(Tu(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Bg(t,n){const s=t.relativeRoot==="."?ut(n??t.root)||t.name||t.root:t.relativeRoot||t.name||ut(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:Dg(t.files)}}function _u(t,n){const s=ut(n??"")||n||"";return t.map(l=>Bg(l,n)).sort((l,c)=>s&&l.label===s?-1:s&&c.label===s?1:l.label.localeCompare(c.label))}function Du(t,n,s,l,c){const d=eu(s),h=d.find(_=>_.root===l)??d[0]??null,m=n.find(_=>_.root===l)??null,p=m?.relativeRoot??h?.relativeRoot??".",g=m?.name??h?.name??(ut(l)||l),u=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:p,repoName:g})),w=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:p,name:g,depth:0,nested:!!(c&&l!==c),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:p,name:g,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(c&&l!==c),available:h?.available??s.available,files:u,context:w?{...w,root:l,changedFiles:u.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},E=m?n.map(_=>_.root===l?y:_):[...n,y];return{files:Array.from(t).filter(_=>pt(_,c)!==l).concat(u),repositories:E,repoFilters:_u(E,c)}}function pt(t,n){return t.repoRoot??n}function Ui(t){return`${t.repoRoot??""}\0${t.path}`}function dt(t){return t.absolutePath||t.path}function ai(t){return Ui(t)}function Og(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function md(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function pd(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Hn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function gs(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function or(t){return t instanceof DOMException&&t.name==="AbortError"}function Ug(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function gd(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function Ei(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function oi(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function bd(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,c=Number(l?.dataset.mdRefStart),d=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(c)&&c>0&&Number.isFinite(d)&&d>0?{start:Math.min(c,d),end:Math.max(c,d)}:{start:n,end:s}}function Hg({actions:t,running:n,completed:s}){const{t:l}=xt(),[c,d]=o.useState(!1),h=o.useRef(null),m=t.find(g=>n?.action===g.key),p=t.find(g=>s?.action===g.key);return t.length===0?null:(o.useEffect(()=>{if(!c)return;const g=w=>{const y=w.target;y instanceof Node&&h.current?.contains(y)||d(!1)},u=w=>{w.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",g),document.addEventListener("keydown",u),()=>{document.removeEventListener("pointerdown",g),document.removeEventListener("keydown",u)}},[c]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:g=>{g.stopPropagation(),d(u=>!u)},disabled:t.every(g=>g.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50 ${c?"bg-surface-elevated text-foreground":p?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??p?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(nt,{size:13,className:"animate-spin"}):p?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(di,{size:14})}),c&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(g=>{const u=n?.action===g.key,w=s?.action===g.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),g.onClick(),d(!1)},disabled:g.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${w?"bg-accent/10 text-accent":g.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:u?e.jsx(nt,{size:13,className:"animate-spin"}):w?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:g.label})]},g.key)})})]}))}function zg(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function Fu(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&zg(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Wn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const ii=new WeakMap;function Wa(t){const n=ii.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),ii.delete(t)},1700);ii.set(t,s)}function Wg(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let c=null;for(const m of l){if(!Wn(m))continue;const p=m.querySelector(s);if(p&&Wn(p)){c=p;break}}if(c??=Array.from(document.querySelectorAll(s)).find(Wn)??null,!c)return;const d=Fu(c);if(!d){c.scrollIntoView({block:"start",behavior:"smooth"}),Wa(c);return}const h=c.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop;d.scrollTo({top:Math.max(0,h),behavior:"instant"}),Wa(c)}function mn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,c=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,d=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&c?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${c}"]`:null,s!==null&&c?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${c}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&d?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${d}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(T=>!!T),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let p=null;for(const T of m)if(Wn(T)){for(const _ of h){const U=T.querySelector(_);if(U&&Wn(U)){p=U;break}}if(p)break}if(p??=h.flatMap(T=>Array.from(document.querySelectorAll(T))).find(Wn)??null,!p){Wg(t.filePath);return}const g=Fu(p);if(!g){p.scrollIntoView({block:"center",behavior:"smooth"}),Wa(p);return}const u=p.getBoundingClientRect(),w=g.getBoundingClientRect(),E=u.top-w.top+g.scrollTop-Math.max(24,(g.clientHeight-u.height)/2);g.scrollTo({top:Math.max(0,E),behavior:"instant"}),Wa(p)}const Bu=1,Ou=8;function Gg(t){return Math.min(Ou,Math.max(Bu,t))}function Uu({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const c=o.useRef(null),[d,h]=o.useState({scale:1,x:0,y:0}),[m,p]=o.useState(!1),g=o.useRef(null),u=o.useRef(new Set),w=o.useRef(!1),y=o.useRef(null),E=o.useRef(0),T=o.useRef(d);T.current=d,o.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const _=o.useCallback((L,A,z)=>{const D=c.current;if(!D)return{x:A,y:z};const a=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,k=a?.clientWidth||D.clientWidth,B=a?.clientHeight||D.clientHeight,j=Math.max(0,(k*L-D.clientWidth)/2),Y=Math.max(0,(B*L-D.clientHeight)/2);return{x:Math.min(j,Math.max(-j,A)),y:Math.min(Y,Math.max(-Y,z))}},[]),U=o.useCallback((L,A,z)=>{h(D=>{const a=Gg(L),k=c.current;if(!k||a===1)return{scale:a,x:0,y:0};const B=k.getBoundingClientRect(),j=(A??B.left+B.width/2)-B.left-B.width/2,Y=(z??B.top+B.height/2)-B.top-B.height/2,re=a/D.scale,se=j-(j-D.x)*re,he=Y-(Y-D.y)*re;return{scale:a,..._(a,se,he)}})},[_]),R=o.useCallback((L,A)=>{p(!0),T.current.scale>1?h({scale:1,x:0,y:0}):U(2.5,L,A),window.setTimeout(()=>p(!1),220)},[U]);o.useEffect(()=>{const L=c.current;if(!L)return;const A=a=>{if(a.pointerType==="mouse"&&a.button!==0)return;const k=u.current.size===0;if(u.current.add(a.pointerId),k){const B=Date.now(),j=y.current;if(j&&B-j.time<350&&Math.hypot(a.clientX-j.x,a.clientY-j.y)<24){y.current=null,E.current=B,s?.(),R(a.clientX,a.clientY);return}}if(u.current.size>1){w.current=!0,g.current=null;return}if(!(T.current.scale<=1)){a.preventDefault(),g.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,originX:T.current.x,originY:T.current.y,moved:!1};try{L.setPointerCapture?.(a.pointerId)}catch{}p(!1)}},z=a=>{const k=g.current;if(!k||k.pointerId!==a.pointerId)return;const B=a.clientX-k.startX,j=a.clientY-k.startY;if(!k.moved){if(Math.hypot(B,j)<6)return;k.moved=!0}a.stopPropagation(),a.preventDefault(),h(Y=>({...Y,..._(Y.scale,k.originX+B,k.originY+j)}))},D=a=>{const k=g.current,B=k?.pointerId===a.pointerId&&k.moved;if(k?.pointerId===a.pointerId){k.moved&&a.stopPropagation(),g.current=null;try{L.releasePointerCapture?.(a.pointerId)}catch{}}u.current.delete(a.pointerId)&&u.current.size===0&&(!w.current&&!B&&(y.current={time:Date.now(),x:a.clientX,y:a.clientY}),w.current=!1)};return L.addEventListener("pointerdown",A,{capture:!0,passive:!1}),window.addEventListener("pointermove",z,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{L.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("pointermove",z,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[_,s,R]),wd({onPinch:({offset:[L],origin:[A,z]})=>{p(!1),U(L,A,z)},onWheel:({event:L,delta:[A,z],ctrlKey:D})=>{if(D){L.preventDefault(),L.stopPropagation(),p(!1),U(T.current.scale*(1-z*.01),L.clientX,L.clientY);return}T.current.scale<=1||(L.preventDefault(),L.stopPropagation(),p(!1),h(a=>({...a,..._(a.scale,a.x-A,a.y-z)})))}},{target:c,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Bu,max:Ou},from:()=>[T.current.scale,0],rubberband:!0}});const M=d.scale>1;return o.useEffect(()=>{n?.(M)},[n,M]),e.jsx("div",{ref:c,"data-sidebar-gesture-ignore":M?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:M?"grab":"zoom-in"},onDoubleClick:L=>{L.stopPropagation(),!(Date.now()-E.current<500)&&(s?.(),R(L.clientX,L.clientY))},children:l({scale:d.scale,zoomed:M,animateTransform:m,transformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0) scale(${d.scale})`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0)`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Hu({src:t,alt:n,vector:s,onLoad:l,onError:c,onZoomChange:d,onDoubleTap:h}){const m=Ai(t,c),[p,g]=o.useState(null),u=s??qa(t);return o.useEffect(()=>{g(null)},[t]),e.jsx(Uu,{resetKey:t,onZoomChange:d,onDoubleTap:h,children:({transformStyle:w,vectorTransformStyle:y,scale:E,animateTransform:T})=>{const _=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:u&&p?{position:"absolute",left:"50%",top:"50%",width:p.width*E,height:p.height*E,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:T?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:p?{...w,width:p.width,height:p.height}:u?y:w,onLoad:U=>{const R=U.currentTarget,M=R.parentElement;if(M&&R.naturalWidth>0&&R.naturalHeight>0){const L=Math.max(1,M.clientWidth-2),A=Math.max(1,M.clientHeight-2),z=Math.min(L/R.naturalWidth,A/R.naturalHeight),D=u?z:Math.min(z,1);g({width:Math.max(1,Math.round(R.naturalWidth*D)),height:Math.max(1,Math.round(R.naturalHeight*D))})}l(U)},onError:c});return!u||!p?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:p.width,height:p.height},children:_})}})}function qg({svg:t,title:n,scale:s,vectorTransformStyle:l}){const c=o.useRef(null);return o.useLayoutEffect(()=>{const d=c.current,h=d?.querySelector("svg");if(!d||!h)return;const m=()=>{const u=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let w=u[2],y=u[3];if((!Number.isFinite(w)||!Number.isFinite(y)||w<=0||y<=0)&&(w=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(w)||!Number.isFinite(y)||w<=0||y<=0)return;const E=Math.max(1,d.clientWidth-24),T=Math.max(1,d.clientHeight-24),_=Math.min(E/w,T/y,1);h.style.width=`${Math.max(1,Math.floor(w*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};m();const p=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return p?.observe(d),()=>p?.disconnect()},[s,t,l]),e.jsx("div",{ref:c,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function Kg({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(Uu,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:c,scale:d})=>e.jsx(qg,{svg:t,title:n,scale:d,vectorTransformStyle:c})})}let Vg=0,Yg=0,Xg=0,Jg=0,Qg=0;function li(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Je(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++Yg,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Aa(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++Jg,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Zg(){return`diff-ui-${Date.now().toString(36)}-${(++Qg).toString(36)}`}function eb(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function tb(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Li({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:c,onReferenceCopied:d,onClose:h,onDirectoryLinkOpen:m,isMobile:p,markdownOutlineOpen:g,markdownOutlineCloseSignal:u,onOpenMarkdownOutline:w,onCloseMarkdownOutline:y,markdownImageLightboxOpen:E,markdownImageLightboxCloseSignal:T,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:U,lineRange:R,onLineRangeChange:M,insertedReferenceKey:L,copiedReferenceKey:A,scrollToLine:z,onScrollToLineHandled:D}){const{t:a}=xt(),k=oe(P=>P.rootPath),B=oe(P=>P.selectFile),[j,Y]=o.useState({kind:"idle"}),[re,se]=o.useState("schematic"),[he,G]=o.useState(null),J=o.useRef(null),[$,F]=o.useState(null),V=o.useRef(new Map),te=o.useRef(null),[ie,me]=o.useState(null),[pe,je]=o.useState(()=>Zc()),[N,Z]=o.useState(()=>Uc(k,n)),de=o.useRef(null),[Ee,ze]=o.useState(!1),[Pe,ce]=o.useState(null),[ne,S]=o.useState(0),[X,ke]=o.useState([]),[xe,De]=o.useState(null),ue=o.useRef(null),qe=o.useRef(n),[Le,W]=o.useState(null),[K,Se]=o.useState({status:"idle"}),[Re,ot]=o.useState(!1),[Ke,pn]=o.useState(""),[ft,ir]=o.useState([]),[Gt,gn]=o.useState(0),vt=o.useRef(null),Ft=Ad(d),Wr=Oi(k,n);o.useEffect(()=>{if(qe.current===n)return;qe.current=n;const P=n&&k&&!n.startsWith("/")?`${k}/${n}`:n;if(ue.current===P){ue.current=null;return}ue.current=null,ke([]),De(null),ot(!1),pn("")},[n,k]);const lr=n?k&&!n.startsWith("/")?`${k}/${n}`:n:null,qt=oe(P=>lr?(P.fileChangeVersions.get(lr)??0)+P.fileWatchEpoch:P.fileWatchEpoch),Lt=o.useRef(null),cr=o.useRef(null),[Bt,$s]=o.useState(0),bn=o.useCallback(()=>$s(P=>P+1),[]);o.useEffect(()=>{const P=J.current;return J.current=null,G(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const H=J.current;J.current=null,H&&URL.revokeObjectURL(H.objectUrl)}},[lr,qt,Bt]),o.useEffect(()=>{if(!n){Lt.current=null,Y({kind:"idle"});return}const P=k&&!n.startsWith("/")?`${k}/${n}`:n,H=new AbortController,le=++Vg,be=`right-sidebar-file-preview:${le}`,Fe=performance.now();let $e=!1;const Ue=(Q,_e={})=>{$e||($e=!0,li("end",{loadingId:le,reason:Q,durationMs:Math.round(performance.now()-Fe),filePath:n,fullPath:P,rootPath:k,..._e}))};let Ie=null;const tt=Jf(P),st=tt?P.toLowerCase().endsWith(".kicad_pcb")?re==="schematic"?"pcb-front":re:"schematic":re,Xt=!tt&&xd(P),pr=!tt&&!Xt&&Qf(P),kn=!tt&&!Xt&&!pr&&Zf(P),Jr=ms(P),Xn=fs(P),Jt=tt?"eda":Xt?"image":pr?"model3d":kn?"video":"text",Qt=Lt.current!==P;if(Lt.current=P,Qt){li("start",{loadingId:le,filePath:n,fullPath:P,rootPath:k,mode:Jt,externalVersion:qt}),Se({status:"idle"}),Y({kind:"loading",mode:Jt}),cr.current=null;const Q=ud(k,n);M(Q?.lineRange??null),je(Jr?Zc():"source"),Z(Xn?Uc(k,n):"source"),tt&&se(eh(P))}Qt||Y(Q=>Q.kind==="error"?{kind:"loading",mode:Jt}:Q);const Sn=window.setTimeout(()=>{$e||H.signal.aborted||li("still_active",{loadingId:le,filePath:n,fullPath:P,rootPath:k,mode:Jt,durationMs:Math.round(performance.now()-Fe),isPathChange:Qt})},3e3),Qr=window.setTimeout(()=>{if($e||H.signal.aborted)return;const Q=tt?a("rightSidebar.edaTimeout"):pr?a("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";H.abort(new DOMException(Q,"TimeoutError")),Y({kind:"error",message:Q}),Ue("stuck_timeout",{error:Q})},tt?th+5e3:pr?rh+5e3:nh(P)?35e3:Bp);if(tt){const Q=st==="pcb-3d"?J.current:null;Q?(Y(Q),Ue("eda_3d_client_cache_hit",{bytes:Q.meta.size,view:Q.view,mimeType:Q.meta.mimeType})):sh(P,st,H.signal,"view_file",be).then(_e=>{if(H.signal.aborted)return;Ie=URL.createObjectURL(_e.blob);const Zt={kind:"eda",sourcePath:_e.path||P,objectUrl:Ie,view:_e.view,meta:{size:_e.size,mimeType:_e.mimeType,modified:_e.modified}};if(_e.view==="pcb-3d"){const er=J.current;er&&er.objectUrl!==Ie&&URL.revokeObjectURL(er.objectUrl),J.current=Zt,G(Zt),Ie=null}Y(Zt),Ue("eda_loaded",{bytes:_e.size,view:_e.view,mimeType:_e.mimeType})}).catch(_e=>{H.signal.aborted||(Y({kind:"error",message:_e instanceof Error&&/timed out/i.test(_e.message)?a("rightSidebar.edaTimeout"):_e instanceof Error?_e.message:a("rightSidebar.edaLoadFailed")}),Ue("error",{error:_e instanceof Error?_e.message:String(_e)}))})}else if(Xt)ah(P,H.signal,"view_file",be).then(Q=>{Ie=URL.createObjectURL(Q.blob),Y({kind:"image",objectUrl:Ie,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ue("image_loaded",{bytes:Q.size,mimeType:Q.mimeType})}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:a("rightSidebar.imageLoadFailed")}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(pr)oh(P,H.signal,"view_file",be).then(Q=>{H.signal.aborted||(Ie=URL.createObjectURL(Q.blob),Y({kind:"model3d",sourcePath:Q.path||P,objectUrl:Ie,ext:Q.ext,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ue("model3d_loaded",{bytes:Q.size,ext:Q.ext}))}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error&&(Q.name==="TimeoutError"||/timed out/i.test(Q.message))?a("rightSidebar.model3dTimeout"):Q instanceof Error?Q.message:a("rightSidebar.model3dLoadFailed")}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(kn){const Q=ih(P)??"",_e=kh(P);Y(Zt=>Zt.kind==="video"&&Zt.url===_e?Zt:{kind:"video",url:_e,meta:{size:null,mimeType:Q,modified:null}}),Ue("video_ready",{mimeType:Q})}else Rc(P,H.signal,"view_file",be).then(Q=>{if(!H.signal.aborted){if(Q.binary){Y({kind:"binary"});return}Y({kind:"text",content:Q.content,sourcePath:Q.path||P,meta:{size:Q.size,truncated:Q.truncated}}),Ue("text_loaded",{bytes:Q.size,truncated:!!Q.truncated})}}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:"Failed to read file"}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});return()=>{H.abort(),Ct(be),window.clearTimeout(Sn),window.clearTimeout(Qr),Ie&&URL.revokeObjectURL(Ie),Ue("cleanup")}},[n,k,qt,Bt,M,a,re]),o.useEffect(()=>{if(j.kind!=="model3d"||!n){F(null);return}let P=!1;const H=n.lastIndexOf("/"),le=H>=0?n.slice(H+1):n,be=H>=0?n.slice(0,H):"",Fe=be.lastIndexOf("/"),$e=Fe>=0?be.slice(0,Fe):"",Ue=le.replace(/\.(stl|glb|gltf)$/i,""),Ie=`${$e?`${$e}/`:""}features/${Ue}.json`;return Rc(Ie).then(tt=>{if(!P)try{const st=JSON.parse(tt.content);F(st.version===1&&Array.isArray(st.features)&&st.features.length>0?st.features:null)}catch{F(null)}}).catch(()=>{P||F(null)}),()=>{P=!0}},[j,n]),o.useEffect(()=>{if(j.kind!=="text"){W(null);return}const P=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,H=Nd(P),le=j.content,be=ms(P??"")&&pe==="preview",Fe=fs(P??"")&&N==="preview";if(!H||be||Fe||!Md(le)){W(null);return}let $e=!1;const Ue=Ie=>{if($e||!Ie.registered(H)){$e||W(null);return}try{W(Ld(Ie,le,H))}catch{W(null)}};return Pe?Ue(Pe):(W(null),$d().then(Ie=>{$e||(ce(Ie),Ue(Ie))}).catch(()=>{})),()=>{$e=!0}},[j,Pe,n,k,pe,N]),o.useLayoutEffect(()=>{if(!Wr||j.kind!=="text")return;const P=`${Wr}:${pe}:${N}`;if(cr.current===P)return;const H=ud(k,n);if(cr.current=P,!H)return;const le=requestAnimationFrame(()=>{const be=te.current;if(!be)return;const Fe=pe==="preview"?H.markdownTop??H.top:H.top;be.scrollTo({top:Math.max(0,Fe??0),left:Math.max(0,H.left??0)}),S(pe==="preview"?Math.max(0,Fe??0):0)});return()=>cancelAnimationFrame(le)},[n,pe,N,j.kind,Wr,k]),o.useEffect(()=>{Wr&&ei(k,n,{lineRange:R})},[n,R,Wr,k]),o.useEffect(()=>{if(z==null||j.kind!=="text")return;me(null),M({start:z,end:z});const P=z,H=requestAnimationFrame(()=>{const le=V.current.get(P);le&&le.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(H)},[z,j,M,D]);const Gn=o.useCallback(P=>{const H=te.current;if(!H)return!1;const le=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),be=H.querySelector(`#${le}`);return be?(be.scrollIntoView({block:"start"}),!0):!1},[]);o.useEffect(()=>{const P=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,H=j.kind==="text"&&ms(P??"")&&pe==="preview";if(!xe||!H)return;const le=requestAnimationFrame(()=>{Gn(xe)&&De(null)});return()=>cancelAnimationFrame(le)},[n,Gn,pe,xe,j,k]),o.useLayoutEffect(()=>{const P=te.current;if(!P||!R){me(null);return}if(ie)return;const H=j.kind==="image"||j.kind==="loading"&&j.mode==="image",le=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,be=j.kind==="text"&&ms(le??"")&&pe==="preview",Fe=j.kind==="text"&&fs(le??"")&&N==="preview";if(j.kind!=="text"||H||be||Fe){me(null);return}const $e=()=>{const Ie=V.current.get(R.end);if(!Ie||!P){me(null);return}const tt=Ie.offsetTop+Ie.offsetHeight/2,st=P.scrollLeft+Math.max(8,P.clientWidth-120);me({top:tt,left:st})};$e();const Ue=new ResizeObserver(()=>$e());return Ue.observe(P),()=>Ue.disconnect()},[R,ie,j,pe,N,n,k,Le]);const Ot=j.kind==="text"&&!(fs(lr??"")&&N==="preview")&&!lr?.toLowerCase().endsWith(".csv")&&!lr?.toLowerCase().endsWith(".kicad_pro")&&!lr?.toLowerCase().endsWith(".kicad_prl"),Gr=o.useCallback(()=>{ot(!1),pn(""),ir([]),gn(0),Ca()},[]),yt=o.useCallback(()=>{Ot&&(ot(!0),requestAnimationFrame(()=>{vt.current?.focus(),vt.current?.select()}))},[Ot]),Cr=o.useCallback(P=>{gn(H=>ft.length===0?0:(H+P+ft.length)%ft.length)},[ft.length]);if(o.useEffect(()=>{const P=H=>{const le=kp(H);if(le==="open"&&Ot){H.preventDefault(),yt();return}Re&&(le==="close"?(H.preventDefault(),Gr()):(le==="next"||le==="previous")&&(H.preventDefault(),Cr(le==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[Gr,Re,Cr,yt,Ot]),o.useLayoutEffect(()=>{if(Ca(),!Re||!Ke.trim()||!te.current){ir([]),gn(0);return}const P=jp(te.current,Ke);return ir(P),gn(0),Wc(P,0),Gc(P[0]),Ca},[Re,Ke,Le,pe,j]),o.useEffect(()=>{Re&&(Wc(ft,Gt),Gc(ft[Gt]))},[Gt,ft,Re]),o.useEffect(()=>Ca,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.selectFilePrompt")});const Te=k&&!n.startsWith("/")?`${k}/${n}`:n,Ut=_a(Te,k),Nr=vd(Te,k),dr=j.kind==="text"&&j.content?j.content.split(`
|
|
1654
|
-
`):[],Va=Math.max(2,String(dr.length).length)+1,wt=j.kind==="text"||j.kind==="image"||j.kind==="model3d"||j.kind==="video"||j.kind==="eda"?j.meta:null,Es=ms(Te),At=Te.toLowerCase().endsWith(".csv"),Ls=Te.toLowerCase().endsWith(".kicad_pro"),Kt=Te.toLowerCase().endsWith(".kicad_prl"),qr=j.kind==="text"&&Es&&pe==="preview",qn=fs(Te),ur=j.kind==="text"&&qn&&N==="preview",Ya=j.kind==="image"||j.kind==="loading"&&j.mode==="image",kt=j.kind==="model3d"||j.kind==="loading"&&j.mode==="model3d",Kr=j.kind==="video"||j.kind==="loading"&&j.mode==="video",Kn=j.kind==="eda"||j.kind==="loading"&&j.mode==="eda",Vn=j.kind==="text"?j.sourcePath:Te,Mr=
|
|
1653
|
+
${t}`,F=o.useRef($),V=o.useRef(null),te=o.useRef(null),ie=o.useRef(!1);o.useEffect(()=>{F.current!==$&&(F.current=$,u?.())},[u,$]),o.useEffect(()=>{p!==void 0&&k(null)},[p]),o.useLayoutEffect(()=>{if(!m){k(null);return}const S=()=>{const X=j.current;if(!X)return;const ke=X.getBoundingClientRect(),xe=window.innerWidth;k({top:ke.bottom+6,right:Math.max(8,xe-ke.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[m,h,G]);const me=o.useCallback(S=>{const X=B.current,ke=X?.closest("[data-markdown-preview-scroller]"),xe=X?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!ke||!xe)return;const De=ke.getBoundingClientRect(),ue=xe.getBoundingClientRect(),Le=X?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,W=ue.top-De.top+ke.scrollTop;ke.scrollTo({top:Math.max(0,W-Le-8),behavior:"smooth"}),D(S.startLine),u?.()},[u]),pe=o.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||ii(S.target)||(V.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),je=o.useCallback((S,X,ke)=>{const xe=V.current;if(V.current=null,!xe||xe.pointerId!==S.pointerId)return;const De=Math.abs(S.clientX-xe.startX),ue=Math.abs(S.clientY-xe.startY);if(De>8||ue>8)return;const qe=S.target;if(ii(qe)||Li())return;const Le=bd(qe,X,ke);c(S,Le.start,Le.end)},[c]),N=o.useCallback(S=>{V.current?.pointerId===S.pointerId&&(V.current=null)},[]),Z=o.useCallback((S,X)=>{const ke=B.current;if(!ke||typeof document.elementFromPoint!="function")return null;const xe=document.elementFromPoint(S,X);if(!(xe instanceof HTMLElement)||!ke.contains(xe))return null;const De=xe.closest("[data-md-ref-start]");if(De){const Se=Number(De.dataset.mdRefStart);if(Number.isFinite(Se)&&Se>0)return Se}const ue=xe.closest("[data-markdown-preview-block-start]");if(!ue)return null;const qe=Number(ue.dataset.markdownPreviewBlockStart),Le=Y.find(Se=>Se.startLine===qe);if(!Le)return Number.isFinite(qe)&&qe>0?qe:null;if(Le.endLine<=Le.startLine)return Le.startLine;const W=ue.getBoundingClientRect(),K=W.height>0?Math.min(1,Math.max(0,(X-W.top)/W.height)):0;return Math.round(Le.startLine+K*(Le.endLine-Le.startLine))},[Y]),de=o.useCallback(S=>{if(!d||S.pointerType==="mouse"&&S.button!==0)return;const X=Z(S.clientX+24,S.clientY);if(X!=null){te.current={pointerId:S.pointerId,anchorLine:X,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[d,Z]),Ee=o.useCallback(S=>{const X=te.current;if(!X||X.pointerId!==S.pointerId||!d)return;const ke=Z(S.clientX+16,S.clientY);ke!=null&&(!X.moved&&ke===X.anchorLine||(X.moved=!0,ie.current=!0,d(S,Math.min(X.anchorLine,ke),Math.max(X.anchorLine,ke),"move")))},[d,Z]),ze=o.useCallback(S=>{const X=te.current;if(te.current=null,!X||X.pointerId!==S.pointerId||!d||!X.moved)return;const ke=Z(S.clientX+16,S.clientY)??X.anchorLine;d(S,Math.min(X.anchorLine,ke),Math.max(X.anchorLine,ke),"end")},[d,Z]),Pe=o.useCallback(S=>{te.current?.pointerId===S.pointerId&&(te.current=null)},[]),ce={onPointerDown:de,onPointerMove:Ee,onPointerUp:ze,onPointerCancel:Pe},ne=()=>ie.current?(ie.current=!1,!0):!1;return Y.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:U("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:B,className:"relative min-w-0 max-w-full",onClickCapture:S=>{const X=S.target instanceof Element?S.target.closest("a[href]"):null;if(!X||!_)return;const ke=X.getAttribute("href");if(!ke)return;const xe=fu(ke,n,s);xe&&(S.preventDefault(),_(xe))},children:[G.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:G.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:G[G.length-1].text}),J.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?u?.():g?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":U("rightSidebar.markdownOutline"),title:U("rightSidebar.markdownOutline"),children:[e.jsx(Sd,{size:12}),e.jsx("span",{children:U("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&zr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:u}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:a?{top:`${a.top}px`,right:`${a.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:J.map(S=>{const X=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>me(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${X?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:U("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":U("rightSidebar.closeMarkdownOutline"),title:U("common.close"),children:e.jsx(Dt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:J.map(S=>{const X=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>me(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${X?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(au.Provider,{value:he,children:Y.map(S=>{const X=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),ke=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),xe=S.kind==="table"?!1:S.fineGrained?ke:X,De=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let ue=null;if(S.kind!=="table"&&S.fineGrained&&X&&!ke&&l){const K=S.endLine-S.startLine+1,Se=Math.max(l.start,S.startLine),Re=Math.min(l.end,S.endLine),ot=(Se-S.startLine)/K,Ke=(Re-Se+1)/K;ue=e.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${ot})`,height:`calc((100% - 0.5rem) * ${Ke})`}})}const qe=typeof S.content=="function"?S.content(l):S.content,Le=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,W=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:si(xe),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:ai(xe)}),ue]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:qe})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${xe?"bg-primary/10":""}`,title:`Line ${Le}`,"aria-label":`Line ${Le}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:si(De,"self"),onClick:K=>{K.preventDefault(),!ne()&&c(K,S.startLine,S.endLine)},title:`Reference table lines ${Le}`,"aria-label":`Reference table lines ${Le}`,...ce,children:e.jsx("span",{className:ai(De,"self")})}):e.jsxs("span",{className:si(xe,"none"),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:ai(xe,"none")}),ue]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:K=>je(K,S.startLine,S.endLine),onPointerCancel:N,onKeyDown:K=>{K.key!=="Enter"&&K.key!==" "||(K.preventDefault(),c(K,S.startLine,S.endLine))},title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:qe})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:K=>{const Se=K.target;if(ii(Se)||Li()||ne())return;const Re=bd(Se,S.startLine,S.endLine);c(K,Re.start,Re.end)},onKeyDown:K=>{K.key!=="Enter"&&K.key!==" "||(K.preventDefault(),c(K,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${xe?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:W},S.key)})})})]}),w&&R!==null&&se[R]&&e.jsx(Eu,{images:se,index:R,onChange:M,onClose:()=>{M(null),A(null),T?.()}})]})}function Un({label:t,value:n,options:s,placeholder:l,searchPlaceholder:c,emptyText:d,disabled:h,onChange:m}){const{t:p}=xt(),[g,u]=o.useState(!1),[w,y]=o.useState(""),[E,T]=o.useState(null),_=o.useRef(null),U=o.useRef(null),R=w.trim().toLowerCase(),M=o.useMemo(()=>R?s.filter(a=>`${a.label} ${a.meta??""}`.toLowerCase().includes(R)):s,[R,s]),L=s.find(a=>a.value===n),A=()=>{const a=w.trim();a&&(m(a),u(!1),y(""))},z=o.useCallback(()=>{const a=_.current?.getBoundingClientRect();if(!a)return!1;const k=12,B=Math.max(220,Math.min(a.width,window.innerWidth-k*2)),j=Math.min(Math.max(k,a.left),window.innerWidth-B-k),Y=window.innerHeight-a.bottom-k,re=a.top-k,se=Y>=180||Y>=re,he=Math.max(96,(se?Y:re)-4),G=Math.min(320,he);return T({left:j,top:se?a.bottom+4:Math.max(k,a.top-G-4),width:B,maxHeight:G}),!0},[]),D=()=>{z(),u(!0)};return o.useEffect(()=>{if(!g)return;let a=0;const k=()=>{a||(a=window.requestAnimationFrame(()=>{a=0,z()}))},B=j=>{const Y=j.target;Y instanceof Node&&(_.current?.contains(Y)||U.current?.contains(Y)||(u(!1),y("")))};return window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),document.addEventListener("pointerdown",B,!0),()=>{a&&window.cancelAnimationFrame(a),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("pointerdown",B,!0)}},[g,z]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),g){u(!1);return}D()}},className:"group flex w-full items-center justify-between gap-2 rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-left transition hover:bg-surface-elevated disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("span",{className:`block truncate text-[12px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:L?.label??(n||l)})]}),e.jsx(Ss,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${g?"rotate-180":""}`})]}),g&&!h&&typeof document<"u"&&zr.createPortal(e.jsxs("div",{ref:U,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:a=>a.stopPropagation(),style:{left:E?.left??12,top:E?.top??12,width:E?.width??260,maxHeight:E?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(zn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:w,onChange:a=>y(a.target.value),onKeyDown:a=>{if(a.key==="Escape"){a.preventDefault(),u(!1),y("");return}a.key==="Enter"&&(a.preventDefault(),A())},onBlur:()=>{w.trim()&&M.length===0&&A()},placeholder:c,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(E?.maxHeight??320)-46)},children:[w.trim()&&!s.some(a=>a.value===w.trim())&&e.jsxs("button",{type:"button",onMouseDown:a=>a.preventDefault(),onClick:A,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:w.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:p("common.use")})]}),M.length>0?M.map(a=>e.jsxs("button",{type:"button",onClick:()=>{m(a.value),u(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${a.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:a.label}),a.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:a.meta})]},a.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:d})]})]}),document.body)]})}function dd({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:c,selectedRoots:d,onToggleRepo:h,onGenerate:m,onSecondaryAction:p,disabled:g,generateDisabled:u,secondaryDisabled:w,inserted:y,buttonLabel:E,insertedLabel:T,title:_,ariaLabel:U,scopeTitle:R,scopeLabel:M,allLabel:L,generateLabel:A,secondaryLabel:z,secondaryTitle:D,secondaryLoading:a,loading:k,error:B,statusTitle:j,extraContent:Y,renderRepoExtra:re}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):u||m()},disabled:g,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${B?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":U,title:j??(s?`${R}: ${M}`:_),children:[k?e.jsx(nt,{size:13,className:"animate-spin"}):e.jsx(Rs,{size:13}),e.jsx("span",{children:y?T:E}),s&&e.jsx(Ss,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),B&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&zr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>n(!1),children:e.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:se=>se.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:R}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:M})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Dt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[Y,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:L}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),c.map(se=>{const he=d.includes(se.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${he?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(se.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${he?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:se.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:se.label}),se.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:se.branch})]}),he&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),re&&(l||he)&&e.jsx("div",{className:"px-2 pb-2",children:re(se)})]},se.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${p&&z?"sm:grid-cols-2":""}`,children:[p&&z&&e.jsxs("button",{type:"button",onClick:()=>{w||(n(!1),p())},disabled:w,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[a?e.jsx(nt,{size:12,className:"animate-spin"}):e.jsx(Ed,{size:12}),z]}),e.jsxs("button",{type:"button",onClick:()=>{u||(n(!1),m())},disabled:u,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Rs,{size:12}),A]})]})]})}),document.body)]})}function Pg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Au(){return Ze(Ti,Pg)??{}}function Tg(t,n){const s=Au(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,c],[,d])=>d.updatedAt-c.updatedAt).slice(0,Lp);vs(Ti,Object.fromEntries(l),Pp)}function Ig(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function _g(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!Ig(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Ui(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Pu(){return Ze(Ii,_g)??{}}function ud(t,n){const s=Ui(t,n);return s?Pu()[s]??null:null}function ti(t,n,s){const l=Ui(t,n);if(!l)return;const c=Pu(),d=c[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...c,[l]:{...d,...s,updatedAt:Date.now()}}).sort(([,m],[,p])=>p.updatedAt-m.updatedAt).slice(0,Ap);vs(Ii,Object.fromEntries(h),Tp)}function ri({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function ps({slow:t}){const{t:n}=xt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:[e.jsx(nt,{size:20,className:"mx-auto mb-2 animate-spin text-muted-foreground/80"}),e.jsx("div",{children:n("rightSidebar.loadingGitChanges")}),t&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground/75",children:n("rightSidebar.loadingGitChangesSlow")})]})}function La({message:t,onRetry:n}){const{t:s}=xt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function _a(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function ut(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function ni(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Ei(t,n,s){const l=Math.min(n,s),c=Math.max(n,s);return t?.start===l&&t.end===c?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,c)}:{start:l,end:c}}function Dg(t,n,s){return Ei(t,n,s)}function si(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function ai(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function fd(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function Tu(t){const n=new Map;for(const s of t)n.set(Hi(s),s);return n}function Iu(t,n){const s=new Map(t);for(const l of n)s.set(Hi(l),l);return s}function hd(t,n){let s=0;for(const l of t){const c=pt(l,n);c&&n&&c!==n&&(s+=1)}return s}function Fg(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function Bg(t,n){return Array.from(Iu(Tu(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Og(t,n){const s=t.relativeRoot==="."?ut(n??t.root)||t.name||t.root:t.relativeRoot||t.name||ut(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:Fg(t.files)}}function _u(t,n){const s=ut(n??"")||n||"";return t.map(l=>Og(l,n)).sort((l,c)=>s&&l.label===s?-1:s&&c.label===s?1:l.label.localeCompare(c.label))}function Du(t,n,s,l,c){const d=eu(s),h=d.find(_=>_.root===l)??d[0]??null,m=n.find(_=>_.root===l)??null,p=m?.relativeRoot??h?.relativeRoot??".",g=m?.name??h?.name??(ut(l)||l),u=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:p,repoName:g})),w=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:p,name:g,depth:0,nested:!!(c&&l!==c),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:p,name:g,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(c&&l!==c),available:h?.available??s.available,files:u,context:w?{...w,root:l,changedFiles:u.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},E=m?n.map(_=>_.root===l?y:_):[...n,y];return{files:Array.from(t).filter(_=>pt(_,c)!==l).concat(u),repositories:E,repoFilters:_u(E,c)}}function pt(t,n){return t.repoRoot??n}function Hi(t){return`${t.repoRoot??""}\0${t.path}`}function dt(t){return t.absolutePath||t.path}function oi(t){return Hi(t)}function Ug(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function md(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function pd(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Hn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function gs(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function or(t){return t instanceof DOMException&&t.name==="AbortError"}function Hg(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function gd(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function Li(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function ii(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function bd(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,c=Number(l?.dataset.mdRefStart),d=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(c)&&c>0&&Number.isFinite(d)&&d>0?{start:Math.min(c,d),end:Math.max(c,d)}:{start:n,end:s}}function zg({actions:t,running:n,completed:s}){const{t:l}=xt(),[c,d]=o.useState(!1),h=o.useRef(null),m=t.find(g=>n?.action===g.key),p=t.find(g=>s?.action===g.key);return t.length===0?null:(o.useEffect(()=>{if(!c)return;const g=w=>{const y=w.target;y instanceof Node&&h.current?.contains(y)||d(!1)},u=w=>{w.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",g),document.addEventListener("keydown",u),()=>{document.removeEventListener("pointerdown",g),document.removeEventListener("keydown",u)}},[c]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:g=>{g.stopPropagation(),d(u=>!u)},disabled:t.every(g=>g.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50 ${c?"bg-surface-elevated text-foreground":p?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??p?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(nt,{size:13,className:"animate-spin"}):p?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(ui,{size:14})}),c&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(g=>{const u=n?.action===g.key,w=s?.action===g.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),g.onClick(),d(!1)},disabled:g.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${w?"bg-accent/10 text-accent":g.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:u?e.jsx(nt,{size:13,className:"animate-spin"}):w?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:g.label})]},g.key)})})]}))}function Wg(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function Fu(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Wg(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Wn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const li=new WeakMap;function Wa(t){const n=li.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),li.delete(t)},1700);li.set(t,s)}function Gg(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let c=null;for(const m of l){if(!Wn(m))continue;const p=m.querySelector(s);if(p&&Wn(p)){c=p;break}}if(c??=Array.from(document.querySelectorAll(s)).find(Wn)??null,!c)return;const d=Fu(c);if(!d){c.scrollIntoView({block:"start",behavior:"smooth"}),Wa(c);return}const h=c.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop;d.scrollTo({top:Math.max(0,h),behavior:"instant"}),Wa(c)}function mn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,c=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,d=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&c?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${c}"]`:null,s!==null&&c?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${c}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&d?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${d}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(T=>!!T),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let p=null;for(const T of m)if(Wn(T)){for(const _ of h){const U=T.querySelector(_);if(U&&Wn(U)){p=U;break}}if(p)break}if(p??=h.flatMap(T=>Array.from(document.querySelectorAll(T))).find(Wn)??null,!p){Gg(t.filePath);return}const g=Fu(p);if(!g){p.scrollIntoView({block:"center",behavior:"smooth"}),Wa(p);return}const u=p.getBoundingClientRect(),w=g.getBoundingClientRect(),E=u.top-w.top+g.scrollTop-Math.max(24,(g.clientHeight-u.height)/2);g.scrollTo({top:Math.max(0,E),behavior:"instant"}),Wa(p)}const Bu=1,Ou=8;function qg(t){return Math.min(Ou,Math.max(Bu,t))}function Uu({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const c=o.useRef(null),[d,h]=o.useState({scale:1,x:0,y:0}),[m,p]=o.useState(!1),g=o.useRef(null),u=o.useRef(new Set),w=o.useRef(!1),y=o.useRef(null),E=o.useRef(0),T=o.useRef(d);T.current=d,o.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const _=o.useCallback((L,A,z)=>{const D=c.current;if(!D)return{x:A,y:z};const a=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,k=a?.clientWidth||D.clientWidth,B=a?.clientHeight||D.clientHeight,j=Math.max(0,(k*L-D.clientWidth)/2),Y=Math.max(0,(B*L-D.clientHeight)/2);return{x:Math.min(j,Math.max(-j,A)),y:Math.min(Y,Math.max(-Y,z))}},[]),U=o.useCallback((L,A,z)=>{h(D=>{const a=qg(L),k=c.current;if(!k||a===1)return{scale:a,x:0,y:0};const B=k.getBoundingClientRect(),j=(A??B.left+B.width/2)-B.left-B.width/2,Y=(z??B.top+B.height/2)-B.top-B.height/2,re=a/D.scale,se=j-(j-D.x)*re,he=Y-(Y-D.y)*re;return{scale:a,..._(a,se,he)}})},[_]),R=o.useCallback((L,A)=>{p(!0),T.current.scale>1?h({scale:1,x:0,y:0}):U(2.5,L,A),window.setTimeout(()=>p(!1),220)},[U]);o.useEffect(()=>{const L=c.current;if(!L)return;const A=a=>{if(a.pointerType==="mouse"&&a.button!==0)return;const k=u.current.size===0;if(u.current.add(a.pointerId),k){const B=Date.now(),j=y.current;if(j&&B-j.time<350&&Math.hypot(a.clientX-j.x,a.clientY-j.y)<24){y.current=null,E.current=B,s?.(),R(a.clientX,a.clientY);return}}if(u.current.size>1){w.current=!0,g.current=null;return}if(!(T.current.scale<=1)){a.preventDefault(),g.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,originX:T.current.x,originY:T.current.y,moved:!1};try{L.setPointerCapture?.(a.pointerId)}catch{}p(!1)}},z=a=>{const k=g.current;if(!k||k.pointerId!==a.pointerId)return;const B=a.clientX-k.startX,j=a.clientY-k.startY;if(!k.moved){if(Math.hypot(B,j)<6)return;k.moved=!0}a.stopPropagation(),a.preventDefault(),h(Y=>({...Y,..._(Y.scale,k.originX+B,k.originY+j)}))},D=a=>{const k=g.current,B=k?.pointerId===a.pointerId&&k.moved;if(k?.pointerId===a.pointerId){k.moved&&a.stopPropagation(),g.current=null;try{L.releasePointerCapture?.(a.pointerId)}catch{}}u.current.delete(a.pointerId)&&u.current.size===0&&(!w.current&&!B&&(y.current={time:Date.now(),x:a.clientX,y:a.clientY}),w.current=!1)};return L.addEventListener("pointerdown",A,{capture:!0,passive:!1}),window.addEventListener("pointermove",z,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{L.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("pointermove",z,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[_,s,R]),wd({onPinch:({offset:[L],origin:[A,z]})=>{p(!1),U(L,A,z)},onWheel:({event:L,delta:[A,z],ctrlKey:D})=>{if(D){L.preventDefault(),L.stopPropagation(),p(!1),U(T.current.scale*(1-z*.01),L.clientX,L.clientY);return}T.current.scale<=1||(L.preventDefault(),L.stopPropagation(),p(!1),h(a=>({...a,..._(a.scale,a.x-A,a.y-z)})))}},{target:c,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Bu,max:Ou},from:()=>[T.current.scale,0],rubberband:!0}});const M=d.scale>1;return o.useEffect(()=>{n?.(M)},[n,M]),e.jsx("div",{ref:c,"data-sidebar-gesture-ignore":M?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:M?"grab":"zoom-in"},onDoubleClick:L=>{L.stopPropagation(),!(Date.now()-E.current<500)&&(s?.(),R(L.clientX,L.clientY))},children:l({scale:d.scale,zoomed:M,animateTransform:m,transformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0) scale(${d.scale})`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0)`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Hu({src:t,alt:n,vector:s,onLoad:l,onError:c,onZoomChange:d,onDoubleTap:h}){const m=Pi(t,c),[p,g]=o.useState(null),u=s??qa(t);return o.useEffect(()=>{g(null)},[t]),e.jsx(Uu,{resetKey:t,onZoomChange:d,onDoubleTap:h,children:({transformStyle:w,vectorTransformStyle:y,scale:E,animateTransform:T})=>{const _=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:u&&p?{position:"absolute",left:"50%",top:"50%",width:p.width*E,height:p.height*E,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:T?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:p?{...w,width:p.width,height:p.height}:u?y:w,onLoad:U=>{const R=U.currentTarget,M=R.parentElement;if(M&&R.naturalWidth>0&&R.naturalHeight>0){const L=Math.max(1,M.clientWidth-2),A=Math.max(1,M.clientHeight-2),z=Math.min(L/R.naturalWidth,A/R.naturalHeight),D=u?z:Math.min(z,1);g({width:Math.max(1,Math.round(R.naturalWidth*D)),height:Math.max(1,Math.round(R.naturalHeight*D))})}l(U)},onError:c});return!u||!p?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:p.width,height:p.height},children:_})}})}function Kg({svg:t,title:n,scale:s,vectorTransformStyle:l}){const c=o.useRef(null);return o.useLayoutEffect(()=>{const d=c.current,h=d?.querySelector("svg");if(!d||!h)return;const m=()=>{const u=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let w=u[2],y=u[3];if((!Number.isFinite(w)||!Number.isFinite(y)||w<=0||y<=0)&&(w=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(w)||!Number.isFinite(y)||w<=0||y<=0)return;const E=Math.max(1,d.clientWidth-24),T=Math.max(1,d.clientHeight-24),_=Math.min(E/w,T/y,1);h.style.width=`${Math.max(1,Math.floor(w*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};m();const p=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return p?.observe(d),()=>p?.disconnect()},[s,t,l]),e.jsx("div",{ref:c,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function Vg({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(Uu,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:c,scale:d})=>e.jsx(Kg,{svg:t,title:n,scale:d,vectorTransformStyle:c})})}let Yg=0,Xg=0,Jg=0,Qg=0,Zg=0;function ci(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Je(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++Xg,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Aa(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++Qg,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function eb(){return`diff-ui-${Date.now().toString(36)}-${(++Zg).toString(36)}`}function tb(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function rb(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Ai({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:c,onReferenceCopied:d,onClose:h,onDirectoryLinkOpen:m,isMobile:p,markdownOutlineOpen:g,markdownOutlineCloseSignal:u,onOpenMarkdownOutline:w,onCloseMarkdownOutline:y,markdownImageLightboxOpen:E,markdownImageLightboxCloseSignal:T,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:U,lineRange:R,onLineRangeChange:M,insertedReferenceKey:L,copiedReferenceKey:A,scrollToLine:z,onScrollToLineHandled:D}){const{t:a}=xt(),k=oe(P=>P.rootPath),B=oe(P=>P.selectFile),[j,Y]=o.useState({kind:"idle"}),[re,se]=o.useState("schematic"),[he,G]=o.useState(null),J=o.useRef(null),[$,F]=o.useState(null),V=o.useRef(new Map),te=o.useRef(null),[ie,me]=o.useState(null),[pe,je]=o.useState(()=>Zc()),[N,Z]=o.useState(()=>Uc(k,n)),de=o.useRef(null),[Ee,ze]=o.useState(!1),[Pe,ce]=o.useState(null),[ne,S]=o.useState(0),[X,ke]=o.useState([]),[xe,De]=o.useState(null),ue=o.useRef(null),qe=o.useRef(n),[Le,W]=o.useState(null),[K,Se]=o.useState({status:"idle"}),[Re,ot]=o.useState(!1),[Ke,pn]=o.useState(""),[ft,ir]=o.useState([]),[Gt,gn]=o.useState(0),vt=o.useRef(null),Ft=Ad(d),Wr=Ui(k,n);o.useEffect(()=>{if(qe.current===n)return;qe.current=n;const P=n&&k&&!n.startsWith("/")?`${k}/${n}`:n;if(ue.current===P){ue.current=null;return}ue.current=null,ke([]),De(null),ot(!1),pn("")},[n,k]);const lr=n?k&&!n.startsWith("/")?`${k}/${n}`:n:null,qt=oe(P=>lr?(P.fileChangeVersions.get(lr)??0)+P.fileWatchEpoch:P.fileWatchEpoch),Lt=o.useRef(null),cr=o.useRef(null),[Bt,$s]=o.useState(0),bn=o.useCallback(()=>$s(P=>P+1),[]);o.useEffect(()=>{const P=J.current;return J.current=null,G(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const H=J.current;J.current=null,H&&URL.revokeObjectURL(H.objectUrl)}},[lr,qt,Bt]),o.useEffect(()=>{if(!n){Lt.current=null,Y({kind:"idle"});return}const P=k&&!n.startsWith("/")?`${k}/${n}`:n,H=new AbortController,le=++Yg,be=`right-sidebar-file-preview:${le}`,Fe=performance.now();let $e=!1;const Ue=(Q,_e={})=>{$e||($e=!0,ci("end",{loadingId:le,reason:Q,durationMs:Math.round(performance.now()-Fe),filePath:n,fullPath:P,rootPath:k,..._e}))};let Ie=null;const tt=Jf(P),st=tt?P.toLowerCase().endsWith(".kicad_pcb")?re==="schematic"?"pcb-front":re:"schematic":re,Xt=!tt&&xd(P),pr=!tt&&!Xt&&Qf(P),kn=!tt&&!Xt&&!pr&&Zf(P),Jr=ms(P),Xn=fs(P),Jt=tt?"eda":Xt?"image":pr?"model3d":kn?"video":"text",Qt=Lt.current!==P;if(Lt.current=P,Qt){ci("start",{loadingId:le,filePath:n,fullPath:P,rootPath:k,mode:Jt,externalVersion:qt}),Se({status:"idle"}),Y({kind:"loading",mode:Jt}),cr.current=null;const Q=ud(k,n);M(Q?.lineRange??null),je(Jr?Zc():"source"),Z(Xn?Uc(k,n):"source"),tt&&se(eh(P))}Qt||Y(Q=>Q.kind==="error"?{kind:"loading",mode:Jt}:Q);const Sn=window.setTimeout(()=>{$e||H.signal.aborted||ci("still_active",{loadingId:le,filePath:n,fullPath:P,rootPath:k,mode:Jt,durationMs:Math.round(performance.now()-Fe),isPathChange:Qt})},3e3),Qr=window.setTimeout(()=>{if($e||H.signal.aborted)return;const Q=tt?a("rightSidebar.edaTimeout"):pr?a("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";H.abort(new DOMException(Q,"TimeoutError")),Y({kind:"error",message:Q}),Ue("stuck_timeout",{error:Q})},tt?th+5e3:pr?rh+5e3:nh(P)?35e3:Op);if(tt){const Q=st==="pcb-3d"?J.current:null;Q?(Y(Q),Ue("eda_3d_client_cache_hit",{bytes:Q.meta.size,view:Q.view,mimeType:Q.meta.mimeType})):sh(P,st,H.signal,"view_file",be).then(_e=>{if(H.signal.aborted)return;Ie=URL.createObjectURL(_e.blob);const Zt={kind:"eda",sourcePath:_e.path||P,objectUrl:Ie,view:_e.view,meta:{size:_e.size,mimeType:_e.mimeType,modified:_e.modified}};if(_e.view==="pcb-3d"){const er=J.current;er&&er.objectUrl!==Ie&&URL.revokeObjectURL(er.objectUrl),J.current=Zt,G(Zt),Ie=null}Y(Zt),Ue("eda_loaded",{bytes:_e.size,view:_e.view,mimeType:_e.mimeType})}).catch(_e=>{H.signal.aborted||(Y({kind:"error",message:_e instanceof Error&&/timed out/i.test(_e.message)?a("rightSidebar.edaTimeout"):_e instanceof Error?_e.message:a("rightSidebar.edaLoadFailed")}),Ue("error",{error:_e instanceof Error?_e.message:String(_e)}))})}else if(Xt)ah(P,H.signal,"view_file",be).then(Q=>{Ie=URL.createObjectURL(Q.blob),Y({kind:"image",objectUrl:Ie,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ue("image_loaded",{bytes:Q.size,mimeType:Q.mimeType})}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:a("rightSidebar.imageLoadFailed")}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(pr)oh(P,H.signal,"view_file",be).then(Q=>{H.signal.aborted||(Ie=URL.createObjectURL(Q.blob),Y({kind:"model3d",sourcePath:Q.path||P,objectUrl:Ie,ext:Q.ext,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ue("model3d_loaded",{bytes:Q.size,ext:Q.ext}))}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error&&(Q.name==="TimeoutError"||/timed out/i.test(Q.message))?a("rightSidebar.model3dTimeout"):Q instanceof Error?Q.message:a("rightSidebar.model3dLoadFailed")}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(kn){const Q=ih(P)??"",_e=Sh(P);Y(Zt=>Zt.kind==="video"&&Zt.url===_e?Zt:{kind:"video",url:_e,meta:{size:null,mimeType:Q,modified:null}}),Ue("video_ready",{mimeType:Q})}else Rc(P,H.signal,"view_file",be).then(Q=>{if(!H.signal.aborted){if(Q.binary){Y({kind:"binary"});return}Y({kind:"text",content:Q.content,sourcePath:Q.path||P,meta:{size:Q.size,truncated:Q.truncated}}),Ue("text_loaded",{bytes:Q.size,truncated:!!Q.truncated})}}).catch(Q=>{H.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:"Failed to read file"}),Ue("error",{error:Q instanceof Error?Q.message:String(Q)}))});return()=>{H.abort(),Ct(be),window.clearTimeout(Sn),window.clearTimeout(Qr),Ie&&URL.revokeObjectURL(Ie),Ue("cleanup")}},[n,k,qt,Bt,M,a,re]),o.useEffect(()=>{if(j.kind!=="model3d"||!n){F(null);return}let P=!1;const H=n.lastIndexOf("/"),le=H>=0?n.slice(H+1):n,be=H>=0?n.slice(0,H):"",Fe=be.lastIndexOf("/"),$e=Fe>=0?be.slice(0,Fe):"",Ue=le.replace(/\.(stl|glb|gltf)$/i,""),Ie=`${$e?`${$e}/`:""}features/${Ue}.json`;return Rc(Ie).then(tt=>{if(!P)try{const st=JSON.parse(tt.content);F(st.version===1&&Array.isArray(st.features)&&st.features.length>0?st.features:null)}catch{F(null)}}).catch(()=>{P||F(null)}),()=>{P=!0}},[j,n]),o.useEffect(()=>{if(j.kind!=="text"){W(null);return}const P=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,H=Nd(P),le=j.content,be=ms(P??"")&&pe==="preview",Fe=fs(P??"")&&N==="preview";if(!H||be||Fe||!Md(le)){W(null);return}let $e=!1;const Ue=Ie=>{if($e||!Ie.registered(H)){$e||W(null);return}try{W(Ld(Ie,le,H))}catch{W(null)}};return Pe?Ue(Pe):(W(null),$d().then(Ie=>{$e||(ce(Ie),Ue(Ie))}).catch(()=>{})),()=>{$e=!0}},[j,Pe,n,k,pe,N]),o.useLayoutEffect(()=>{if(!Wr||j.kind!=="text")return;const P=`${Wr}:${pe}:${N}`;if(cr.current===P)return;const H=ud(k,n);if(cr.current=P,!H)return;const le=requestAnimationFrame(()=>{const be=te.current;if(!be)return;const Fe=pe==="preview"?H.markdownTop??H.top:H.top;be.scrollTo({top:Math.max(0,Fe??0),left:Math.max(0,H.left??0)}),S(pe==="preview"?Math.max(0,Fe??0):0)});return()=>cancelAnimationFrame(le)},[n,pe,N,j.kind,Wr,k]),o.useEffect(()=>{Wr&&ti(k,n,{lineRange:R})},[n,R,Wr,k]),o.useEffect(()=>{if(z==null||j.kind!=="text")return;me(null),M({start:z,end:z});const P=z,H=requestAnimationFrame(()=>{const le=V.current.get(P);le&&le.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(H)},[z,j,M,D]);const Gn=o.useCallback(P=>{const H=te.current;if(!H)return!1;const le=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),be=H.querySelector(`#${le}`);return be?(be.scrollIntoView({block:"start"}),!0):!1},[]);o.useEffect(()=>{const P=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,H=j.kind==="text"&&ms(P??"")&&pe==="preview";if(!xe||!H)return;const le=requestAnimationFrame(()=>{Gn(xe)&&De(null)});return()=>cancelAnimationFrame(le)},[n,Gn,pe,xe,j,k]),o.useLayoutEffect(()=>{const P=te.current;if(!P||!R){me(null);return}if(ie)return;const H=j.kind==="image"||j.kind==="loading"&&j.mode==="image",le=k&&n&&!n.startsWith("/")?`${k}/${n}`:n,be=j.kind==="text"&&ms(le??"")&&pe==="preview",Fe=j.kind==="text"&&fs(le??"")&&N==="preview";if(j.kind!=="text"||H||be||Fe){me(null);return}const $e=()=>{const Ie=V.current.get(R.end);if(!Ie||!P){me(null);return}const tt=Ie.offsetTop+Ie.offsetHeight/2,st=P.scrollLeft+Math.max(8,P.clientWidth-120);me({top:tt,left:st})};$e();const Ue=new ResizeObserver(()=>$e());return Ue.observe(P),()=>Ue.disconnect()},[R,ie,j,pe,N,n,k,Le]);const Ot=j.kind==="text"&&!(fs(lr??"")&&N==="preview")&&!lr?.toLowerCase().endsWith(".csv")&&!lr?.toLowerCase().endsWith(".kicad_pro")&&!lr?.toLowerCase().endsWith(".kicad_prl"),Gr=o.useCallback(()=>{ot(!1),pn(""),ir([]),gn(0),Ca()},[]),yt=o.useCallback(()=>{Ot&&(ot(!0),requestAnimationFrame(()=>{vt.current?.focus(),vt.current?.select()}))},[Ot]),Cr=o.useCallback(P=>{gn(H=>ft.length===0?0:(H+P+ft.length)%ft.length)},[ft.length]);if(o.useEffect(()=>{const P=H=>{const le=Sp(H);if(le==="open"&&Ot){H.preventDefault(),yt();return}Re&&(le==="close"?(H.preventDefault(),Gr()):(le==="next"||le==="previous")&&(H.preventDefault(),Cr(le==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[Gr,Re,Cr,yt,Ot]),o.useLayoutEffect(()=>{if(Ca(),!Re||!Ke.trim()||!te.current){ir([]),gn(0);return}const P=Rp(te.current,Ke);return ir(P),gn(0),Wc(P,0),Gc(P[0]),Ca},[Re,Ke,Le,pe,j]),o.useEffect(()=>{Re&&(Wc(ft,Gt),Gc(ft[Gt]))},[Gt,ft,Re]),o.useEffect(()=>Ca,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.selectFilePrompt")});const Te=k&&!n.startsWith("/")?`${k}/${n}`:n,Ut=_a(Te,k),Nr=vd(Te,k),dr=j.kind==="text"&&j.content?j.content.split(`
|
|
1654
|
+
`):[],Va=Math.max(2,String(dr.length).length)+1,wt=j.kind==="text"||j.kind==="image"||j.kind==="model3d"||j.kind==="video"||j.kind==="eda"?j.meta:null,Es=ms(Te),At=Te.toLowerCase().endsWith(".csv"),Ls=Te.toLowerCase().endsWith(".kicad_pro"),Kt=Te.toLowerCase().endsWith(".kicad_prl"),qr=j.kind==="text"&&Es&&pe==="preview",qn=fs(Te),ur=j.kind==="text"&&qn&&N==="preview",Ya=j.kind==="image"||j.kind==="loading"&&j.mode==="image",kt=j.kind==="model3d"||j.kind==="loading"&&j.mode==="model3d",Kr=j.kind==="video"||j.kind==="loading"&&j.mode==="video",Kn=j.kind==="eda"||j.kind==="loading"&&j.mode==="eda",Vn=j.kind==="text"?j.sourcePath:Te,Mr=Th(Vn,k,R),$r=(()=>{if(!R||j.kind!=="text"||dr.length===0)return Mr;const P=[];for(let be=R.start;be<=R.end;be+=1)P.push(`${be} ${dr[be-1]??""}`);const H=nu(Te).replace(/^\./,""),le="```";return`${Mr}
|
|
1655
1655
|
${le}${H}
|
|
1656
1656
|
${P.join(`
|
|
1657
1657
|
`)}
|
|
1658
1658
|
${le}
|
|
1659
|
-
`})(),Er=`path:${Te}`,Pt=R?`path:${Te}:${R.start}-${R.end}`:Er,Vr=L===Er,Yr=L===Pt,As=A===Er,Lr=A===Pt,fr=Yr||Lr,hr=R?R.start===R.end?`L${R.start}`:`L${R.start}-${R.end}`:null,xn=P=>{const H=te.current;if(!H)return;const le=H.getBoundingClientRect(),be=P.currentTarget.getBoundingClientRect(),Fe=P.clientX||be.left+be.width/2,Ue=(P.clientY||be.top+be.height/2)-le.top+H.scrollTop,Ie=p?116:132,tt=H.scrollLeft+Math.max(8,H.clientWidth-Ie),st=Math.min(Math.max(8,Fe-le.left+H.scrollLeft+10),tt);me({top:Ue,left:st})},vn=(P,H)=>{Ei()||(xn(P),M(le=>{const be=$i(le,H,H);return be||me(null),be}))},mr=(P,H,le)=>{xn(P),M(be=>{const Fe=$i(be,H,le);return Fe||me(null),Fe})},Vt=(P,H,le,be)=>{be==="end"&&xn(P),M({start:H,end:le})},Me=P=>{const{scrollTop:H,scrollLeft:le}=P.currentTarget;S(H),ei(k,n,{top:H,left:le,markdownTop:H})},Yt=P=>{if(P.directory){m?.(P.path);return}if(P.path===Te||j.kind==="text"&&P.path===j.sourcePath){P.fragment&&Gn(P.fragment);return}ke(H=>[...H,Te]),ue.current=P.path,De(P.fragment),M(null),B(P.path)},Xr=()=>{const P=X[X.length-1];P&&(ke(H=>H.slice(0,-1)),ue.current=P,De(null),M(null),B(P))},Yn=P=>{const{scrollTop:H,scrollLeft:le}=P.currentTarget;ei(k,n,{top:H,left:le})},yn=()=>{if(t){t($r,Pt);return}R&&l($r,Pt)},wn=async()=>{if(!(!Te||K.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){Se({status:"pending"});try{await Sh(Te),Se({status:"idle"})}catch(P){Se({status:"error",message:P instanceof Error?P.message:a("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Ft.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${p&&(qr||ur)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[p&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a("rightSidebar.backToFileList"),title:a("rightSidebar.backToFileList"),children:e.jsx(Sd,{size:16})}),X.length>0&&e.jsxs("button",{type:"button",onClick:Xr,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${p?"w-9":"px-2.5"}`,"aria-label":a("rightSidebar.backToPreviousPreview"),title:a("rightSidebar.backToPreviousPreview"),children:[e.jsx(ks,{size:15}),!p&&e.jsx("span",{className:"text-[11px] font-medium",children:a("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Te,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Ut.name}),Ut.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Ut.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ot&&e.jsx("button",{type:"button",onClick:Re?Gr:yt,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${Re?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":a("rightSidebar.findInFile"),title:`${a("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(zn,{size:14})}),Es&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{g&&y?.(),je(P=>{const H=P==="preview"?"source":"preview";return gt(Hd,H),H}),M(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:p?pe==="preview"?e.jsx(pi,{size:14}):e.jsx(mi,{size:14}):a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),qn&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(P=>{const H=P==="preview"?"source":"preview";return Ym(k,n,H),H}),M(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:p?N==="preview"?e.jsx(pi,{size:14}):e.jsx(mi,{size:14}):a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),ur&&e.jsx("button",{type:"button",onClick:()=>{de.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(Cd,{size:15})}),!p&&e.jsx("button",{type:"button",onClick:()=>s(Te,Er),...Ft(Nr,Er),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Vr||As?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:a("rightSidebar.insertReference",{reference:Nr}),children:a(As?"rightSidebar.copied":Vr?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Nr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.copyReference",{reference:Nr}),"aria-label":a("rightSidebar.copyFileRef"),children:e.jsx(lh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{wn()},disabled:K.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:K.status==="error"?K.message??a("rightSidebar.downloadFailed"):a("rightSidebar.downloadFile"),"aria-label":a("rightSidebar.downloadFile"),children:K.status==="pending"?e.jsx(nt,{size:13,className:"animate-spin"}):e.jsx(Th,{size:14})})]})]}),Re&&Ot&&e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:vt,type:"search",value:Ke,onChange:P=>pn(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),Cr(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:a("rightSidebar.findInFilePlaceholder"),"aria-label":a("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ft.length>0?`${Gt+1}/${ft.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Cr(-1),disabled:ft.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.previousSearchMatch"),title:`${a("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(yd,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Cr(1),disabled:ft.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.nextSearchMatch"),title:`${a("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Ih,{size:13})}),e.jsx("button",{type:"button",onClick:Gr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.closeFileSearch"),title:`${a("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Dt,{size:13})})]}),wt&&!(p&&(qr||ur))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[wt.size!==null&&e.jsx("span",{children:a("rightSidebar.byteCount",{count:wt.size.toLocaleString()})}),"truncated"in wt&&wt.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:a("rightSidebar.previewTruncated")}),"mimeType"in wt&&e.jsx("span",{children:wt.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(p&&(qr||ur))&&!kt&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:Kn?a("rightSidebar.edaPickHint"):At?a("rightSidebar.csvTablePreview"):Ls||Kt?a("rightSidebar.kicadProjectPickHint"):Kr?a("rightSidebar.videoPreviewHint"):Ya?a("rightSidebar.imagePreviewHint"):qr?R?a("rightSidebar.selectedLineHint",{lineLabel:hr??""}):a("rightSidebar.markdownPreviewHint"):ur?a("rightSidebar.htmlPreviewHint"):R?a("rightSidebar.selectedLineHint",{lineLabel:hr??""}):a("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?a("rightSidebar.edaLoading"):j.mode==="image"?a("rightSidebar.loadingImage"):j.mode==="model3d"?a("rightSidebar.model3dLoading"):j.mode==="video"?a("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:bn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:a("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:a("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(Dd,{blobUrl:j.objectUrl,filePath:Te,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(Hu,{src:j.objectUrl,alt:Ut.name,vector:!1,onLoad:P=>{const H=P.currentTarget;Y(le=>le.kind==="image"?{...le,dimensions:{width:H.naturalWidth,height:H.naturalHeight}}:le)},onError:()=>Y({kind:"error",message:a("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(ep,{url:j.url,onLoadError:()=>Y({kind:"error",message:a("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ip,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Te.toLowerCase().endsWith(".kicad_pcb"),onViewChange:se,onInsertAnnotation:t??c,onRefresh:bn,interactive3d:he?e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(Qc,{blobUrl:he.objectUrl,ext:".glb",fileName:Ut.name,filePath:he.sourcePath,features:null,onInsertFeature:t??c,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(Qc,{blobUrl:j.objectUrl,ext:j.ext,fileName:Ut.name,filePath:j.sourcePath,features:$,onInsertFeature:t??c,onRefresh:bn})})}):j.kind==="text"&&At?e.jsx(dp,{content:j.content,filePath:Te,onInsertAnnotation:t??c},Te):j.kind==="text"&&(Ls||Kt)?e.jsx(hp,{content:j.content,filePath:Te,localState:Kt,onInsertAnnotation:t??c},Te):qr?e.jsxs("div",{ref:te,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:Me,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Lu,{content:j.content,filePath:j.sourcePath,rootPath:k,lineRange:R,onLineRangeClick:mr,onLineRangeDrag:Vt,scrollTop:ne,outlineOpen:g,outlineCloseSignal:u,onOutlineOpen:w,onOutlineClose:y,lightboxOpen:E,lightboxCloseSignal:T,onLightboxOpen:_,onLightboxClose:U,onLocalLinkOpen:Yt}),R&&ie&&e.jsxs("button",{type:"button",onClick:yn,...Ft($r,Pt),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:fd(p,fr),title:`Insert markdown reference: ${Mr}`,children:[e.jsx(Da,{size:p?13:11}),Lr?a("rightSidebar.copied"):Yr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:hr??""})]})]}):ur?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(wp,{ref:de,src:ch(Te),title:`${Ut.name} preview`,exitFullscreenLabel:a("rightSidebar.htmlFullscreenExit"),onFullscreenChange:ze},`${Te}:${qt}:${Bt}`)}):j.kind==="text"?e.jsxs("div",{ref:te,onScroll:Yn,className:`${Ii} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[dr.length>0?e.jsx("div",{className:"min-w-full",children:dr.map((P,H)=>{const le=H+1,be=!!(R&&le>=R.start&&le<=R.end),Fe=Le&&Le.length===dr.length?Le[H]:null;return e.jsxs("div",{ref:$e=>{$e?V.current.set(le,$e):V.current.delete(le)},role:"button","data-file-preview-line":le,tabIndex:0,onClick:$e=>vn($e,le),onKeyDown:$e=>{$e.key!=="Enter"&&$e.key!==" "||($e.preventDefault(),vn($e,le))},style:{gridTemplateColumns:`${Va}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${be?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${Nr}:${le}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${be?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:le}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Fe??(P||" ")})]},H)})}):"Empty file.",R&&ie&&e.jsxs("button",{type:"button",onClick:yn,...Ft($r,Pt),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:fd(p,fr),title:`Insert code reference: ${Mr}`,children:[e.jsx(Da,{size:p?13:11}),Lr?a("rightSidebar.copied"):Yr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:hr??""})]})]}):null]})}function rb({isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:c,pinned:d=!1,onTogglePinned:h,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:p,onOpenRightSidebarFilePreview:g,onCloseRightSidebarFilePreview:u,rightSidebarRepoPickerOpen:w=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:E,onCloseRightSidebarRepoPicker:T,markdownOutlineOpen:_=!1,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L=!1,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D}){const{t:a,locale:k}=xt(),[B,j]=o.useState(""),[Y,re]=o.useState(null),se=oe(r=>r.rightSearchOpen),he=oe(r=>r.setRightSearchOpen),G=oe(r=>r.rightSidebarLayoutPreference),J=oe(r=>r.setRightSidebarLayoutPreference),[$,F]=o.useState(()=>Xp()),[V,te]=o.useState("."),[ie,me]=o.useState(""),[pe,je]=o.useState(!1),[N,Z]=o.useState(!1),[de,Ee]=o.useState(!1),[ze,Pe]=o.useState(!1),ce=o.useDeferredValue(B),[ne,S]=o.useState(null),[X,ke]=o.useState([]),[xe,De]=o.useState([]),[ue,qe]=o.useState(null),[Le,W]=o.useState(null),[K,Se]=o.useState(null),[Re,ot]=o.useState(null),[Ke,pn]=o.useState(()=>Ze(Kc,xs)??!1),[ft,ir]=o.useState(()=>Ze(Vc,xs)??!1),[Gt,gn]=o.useState(()=>Ze(Yc,xs)??!1),[vt,Ft]=o.useState(()=>Ze(Ko,Gp)??""),[Wr,lr]=o.useState(0),[qt,Lt]=o.useState(!1),[cr,Bt]=o.useState(!1),$s=o.useRef(null),bn=o.useRef(null),[Gn,Ot]=o.useState(!1),[Gr,yt]=o.useState(null),[Cr,Te]=o.useState(null),[Ut,Nr]=o.useState(()=>td(Go)),[dr,Va]=o.useState(()=>td(qc)),[wt,Es]=o.useState(()=>Wp()),[At,Ls]=o.useState(()=>qp()),[Kt,qr]=o.useState(()=>Vp()),qn="words",[ur,Ya]=o.useState(0),[kt,Kr]=o.useState([]),[Kn,Vn]=o.useState([]),[Mr,$r]=o.useState(!1),[Er,Pt]=o.useState(null),[Vr,Yr]=o.useState([]),[As,Lr]=o.useState(!1),[fr,hr]=o.useState([]),[xn,vn]=o.useState([]),[mr,Vt]=o.useState(!1),[Me,Yt]=o.useState(null),[Xr,Yn]=o.useState([]),[yn,wn]=o.useState({}),[P,H]=o.useState(!1),[le,be]=o.useState(null),[Fe,$e]=o.useState(null),[Ue,Ie]=o.useState(null),[tt,st]=o.useState(null),[Xt,pr]=o.useState(!1),[kn,Jr]=o.useState(""),Xn=o.useDeferredValue(kn),[Jt,Qt]=o.useState([]),[Sn,Qr]=o.useState(!1),[Q,_e]=o.useState(!1),[Zt,er]=o.useState(null),[Xa,jn]=o.useState(!1),tr=o.useRef(null),Ar=o.useRef(0),Hi=o.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[zu,Ps]=o.useState(null),[Jn,zi]=o.useState(()=>Ze(qo,xs)??!1),[Ja,Qa]=o.useState(!1),[Ts,Wi]=o.useState([]),[gr,Is]=o.useState({}),[St,_s]=o.useState({}),[Pr,Gi]=o.useState(!0),[qi,Ki]=o.useState(()=>new Set),[Ve,Zr]=o.useState(null),[Za,en]=o.useState(null),[Wu,br]=o.useState(!1),[Vi,xr]=o.useState(0),[,eo]=o.useState(0),[to,Ds]=o.useState(!1),[rr,ro]=o.useState(!1),[Gu,Yi]=o.useState(()=>oe.getState().rightTab==="diff"),[Ae,Qn]=o.useState(null),[Rn,Zn]=o.useState(null),[it,Tr]=o.useState(null),[Xi,lt]=o.useState(null),[Cn,Ji]=o.useState(null),[no,qu]=o.useState(()=>Date.now()),[Ku,Vu]=o.useState(!1),[tn,Fs]=o.useState(!1),[Bs,Qi]=o.useState(""),[es,so]=o.useState(""),[rn,ao]=o.useState(""),[nn,oo]=o.useState(""),[Zi,Nn]=o.useState(null),[Os,Us]=o.useState(!1),[el,io]=o.useState(!1),[tl,rl]=o.useState(!1),[Hs,Yu]=o.useState({key:null,nonce:0}),nl=o.useRef(null),sl=o.useRef(null),ee=jh(n,d,G),Xu=Zd(ee,d,Kt),[lo,co]=o.useState(()=>sg(n)),uo=oe(r=>r.rightTab),sn=oe(r=>r.setRightTab),v=oe(r=>r.rootPath),Mn=oe(r=>r.explorerRoot),al=oe(r=>r.pinnedExplorerRootsCache),ol=oe(r=>r.hydratePinnedExplorerRoots),il=oe(r=>r.syncPinnedExplorerRoots),Tt=oe(r=>r.setExplorerRoot),ll=oe(r=>r.resetExplorerToProject),$n=oe(r=>r.pinExplorerRoot),an=oe(r=>r.unpinExplorerRoot),Ge=oe(r=>r.selectedFilePath),Qe=oe(r=>r.selectFile),fo=oe(r=>r.showHiddenFiles),Ju=oe(r=>r.toggleShowHiddenFiles),ye=oe(r=>r.changedFiles),zs=oe(r=>r.setChangedFiles),Ws=oe(r=>r.invalidateDirectoryCache),Qu=oe(r=>r.setDirectorySortMode),cl=oe(r=>r.applyFileWatchEvents),dl=oe(r=>r.reconcileDirectoryCache),ul=oe(r=>r.bumpFileWatchEpoch),Nt=oe(r=>r.gitBundleLoading),Gs=oe(r=>r.gitBundleSlow),En=oe(r=>r.gitBundleError),Ir=oe(r=>r.gitBundleLastLoadedAt),fl=oe(r=>r.beginGitBundleLoading),hl=oe(r=>r.setGitBundleSlowFor),ho=oe(r=>r.finishGitBundleLoading),ml=oe(r=>r.resetGitBundleLoading),mo=oe(r=>r.setGitBundleError),pl=oe(r=>r.markGitBundleLoaded),ge=Mn??v,gl=o.useMemo(()=>ge?Cp(ge,V):"",[ge,V]),ts=o.useMemo(()=>Rp(ie),[ie]),bl=o.useMemo(()=>({excludePatterns:ts,caseSensitive:N,wholeWord:de,regex:ze}),[N,ts,ze,de]),qs=oe(r=>ge?r.fileSortModes[ge]??"name":"name"),Ks=oe(r=>!!(ge&&r.directoryCache.has(ge))),Ln=o.useRef(null),Mt=o.useRef(0),[xl]=o.useState(()=>++Xg),vr=o.useRef(null),_r=o.useRef(null),Vs=o.useRef(0),Ht=o.useRef(new Map),yr=o.useRef(new Map),Dr=o.useRef(new Set),rs=o.useRef(new Set),on=o.useRef(0),Fr=o.useRef(null),An=o.useRef(0),Pn=o.useRef(null),Tn=o.useRef(0),Br=o.useRef(null),po=o.useRef(new Set),go=o.useRef(null),bo=o.useRef(null),Ys=o.useRef(null),xo=o.useRef(null);o.useEffect(()=>{if(Cn===null)return;const r=Math.max(0,Date.now()-Cn),i=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,f=Math.max(50,i-r%i),b=window.setTimeout(()=>qu(Date.now()),f);return()=>window.clearTimeout(b)},[no,Cn]);const Xs=o.useRef(null),wr=o.useRef(null),Js=o.useRef(null),ns=o.useRef(null),Ce=o.useCallback(r=>oe.getState().rootPath===r,[]);o.useEffect(()=>{if(!t||typeof window>"u")return;const r=i=>{const f=eb(i.target);f&&Aa("global_change_row_event",{...tb(i),selectionPath:f.dataset.diffSelectionPath,filePath:f.dataset.diffFilePath,absolutePath:f.dataset.diffAbsolutePath,repoRoot:f.dataset.diffRepoRoot,status:f.dataset.diffStatus,selectedFilePath:oe.getState().selectedFilePath,rightTab:oe.getState().rightTab,activeGitRepoRoot:ue,changedFiles:oe.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[ue,t]);const vl=o.useCallback(async(r=v??void 0)=>{if(!r)return null;if(Dr.current.has(r)||rs.current.has(r))return Je("untracked_skip_cached",{cwd:r,rootPath:v,completed:Dr.current.has(r),running:rs.current.has(r)}),null;const i=v,f=Vs.current+1;Vs.current=f,Ht.current.set(r,f);const b=`right-sidebar-git-untracked:${r}`,x=new AbortController;yr.current.set(r,x),rs.current.add(r),Je("untracked_start",{requestId:f,cwd:r,rootPath:v});try{let C=await Cc(r,x.signal,b),I=0;for(;C.status==="running"&&I<120;){if(Ht.current.get(r)!==f||x.signal.aborted)return Je("untracked_stale_result",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,status:C.status}),null;if(!Ce(i))return Je("untracked_root_changed",{requestId:f,cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath}),null;await new Promise(q=>window.setTimeout(q,I<10?1e3:3e3)),I+=1,C=await Cc(r,x.signal,b)}if(Ht.current.get(r)!==f||!Ce(i))return Je("untracked_stale_result",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath,files:C.files.length,status:C.status}),null;if(C.status==="done")return zs(Iu(oe.getState().changedFiles,C.files)),C.files.length>0&&ke(q=>{const Xe=new Map(q.map(ve=>[ve.root,ve])).get(r);if(!Xe)return q;const Be=Fg(Xe.files,C.files),ae=q.map(ve=>ve.root===r?{...ve,files:Be,context:ve.context?{...ve.context,changedFiles:Be.map(Et=>({path:Et.path,absolutePath:Et.absolutePath,status:Et.status})),truncated:!1}:ve.context,untrackedDeferred:!1}:ve);De(_u(ae,v));const Oe=ae.find(ve=>ve.root===v);return Oe?.context&&S(ve=>ve?.root===Oe.root?{...ve,...Oe.context}:ve),ae}),Dr.current.add(r),Je("untracked_apply",{requestId:f,cwd:r,files:C.files.length}),C;const O=C.error||(C.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return Dr.current.add(r),Je("untracked_error",{requestId:f,cwd:r,message:O,code:C.code,status:C.status}),null}catch(C){if(Ht.current.get(r)!==f||!Ce(i)||or(C))return Je("untracked_aborted",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath,message:C instanceof Error?C.message:String(C)}),null;const I=C instanceof Error?C.message:"Failed to scan untracked files";return Dr.current.add(r),Je("untracked_error",{requestId:f,cwd:r,message:I}),null}finally{yr.current.get(r)===x&&yr.current.delete(r),Ht.current.get(r)===f&&Ht.current.delete(r),rs.current.delete(r)}},[ne,Ce,v,zs]),zt=o.useMemo(()=>{const r=new Set(xe.map(f=>f.root)),i=Vr.filter(f=>r.has(f));return i.length>0?i:ue?[ue]:[]},[ue,Vr,xe]),yl=zt.length===0,ln=o.useMemo(()=>zt.map(r=>X.find(i=>i.root===r)).filter(r=>!!r),[zt,X]),Zu=o.useMemo(()=>xe.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[xe]),nr=o.useCallback(async()=>{if(!v){Kr([]),Vn([]);return}const r=v,i=An.current+1;An.current=i,Pn.current?.abort();const f=new AbortController;Pn.current=f,$r(kt.length===0),Pt(null);try{const b=zt.length>0?await Promise.all(zt.map(x=>Nc({workspaceRoot:v,repoRoot:x},f.signal))).then(x=>({records:x.flatMap(C=>C.records),walkthroughs:x.flatMap(C=>C.walkthroughs??[])})):await Nc({workspaceRoot:v},f.signal);if(An.current!==i||!Ce(r))return;Kr(b.records),Vn(b.walkthroughs??[])}catch(b){if(An.current!==i||!Ce(r)||or(b))return;Pt(b instanceof Error?b.message:"Failed to load change audit explanations")}finally{Pn.current===f&&(Pn.current=null),An.current===i&&Ce(r)&&$r(!1)}},[kt.length,zt,Ce,v]),Qs=o.useCallback(async(r,i,f)=>{if(!r&&!v){hr([]),vn([]);return}const b=v,x=Tn.current+1;Tn.current=x,Br.current?.abort();const C=new AbortController;Br.current=C;try{const I=r?[r]:Array.from(new Set([v,...X.map(q=>q.root)].filter(q=>!!q))),O=await Promise.all(I.map(q=>uh({repoRoot:q,baseRef:i,branchName:f},C.signal))).then(q=>{const Ne=new Map,Xe=new Map;for(const Be of q){for(const ae of Be.records)Ne.set(ae.id,ae);for(const ae of Be.walkthroughs??[])Xe.set(ae.id,ae)}return{records:Array.from(Ne.values()),walkthroughs:Array.from(Xe.values())}});if(Tn.current!==x||!Ce(b))return;hr(O.records),vn(O.walkthroughs??[])}catch(I){if(Tn.current!==x||!Ce(b)||or(I))return;console.warn("[RightSidebar] Failed to load branch explanations",I)}finally{Br.current===C&&(Br.current=null)}},[X,Ce,v]),Or=o.useCallback((r,i={})=>{if(!Ce(v)){Je("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:oe.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}Je(r.files.length===0?"empty_bundle":"apply",{rootPath:v,available:r.available,files:r.files.length,repositories:r.repositories?.map(ae=>({root:ae.root,relativeRoot:ae.relativeRoot,files:ae.files.length,available:ae.available,error:ae.error})),repoFilters:r.repoFilters?.map(ae=>({root:ae.root,label:ae.label,count:ae.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let f=eu(r),b=r.repoFilters??[],x=r.files;const C=oe.getState().changedFiles;if(!!(i.cacheOnly&&!r.cached&&r.files.length===0&&f.length===0)&&(C.size>0||X.length>0||ne)){Je("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:C.size,currentRepositories:X.length});return}const O=hd(C.values(),v),q=hd(r.files,v),Ne=f.some(ae=>ae.root!==v);if(!!(i.background&&C.size>0&&(r.files.length===0&&!r.error||O>0&&q===0&&!Ne))){Je("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:C.size,nextFiles:r.files.length,currentNestedCount:O,nextNestedCount:q,nextRepositories:f.map(ae=>({root:ae.root,relativeRoot:ae.relativeRoot,files:ae.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(i.replaceRepoRoot){const ae=Du(C.values(),X,r,i.replaceRepoRoot,v);x=ae.files,f=ae.repositories,b=ae.repoFilters}if(zs(Tu(x)),ke(f),De(b),i.syncActiveRepo!==!1){const ae=i.activeRepoRoot!==void 0?i.activeRepoRoot:ue??ed(v),Oe=Qp({...r,repositories:f,repoFilters:b},ae);qe(Oe),Yo(v,Oe)}typeof r.cacheUpdatedAt=="number"&&Ji(r.cacheUpdatedAt),S(ae=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==v)return ae;if(!r.context)return null;const Oe=ae?.root??v;return!ae?.available||Oe!==(r.context.root??v)?r.context:{...ae,...r.context}}),i.reloadDiff&&Ya(ae=>ae+1);const Be=oe.getState().selectedFilePath;if(Be&&!Be.startsWith("/")&&!x.some(ae=>ae.path===Be||ae.absolutePath===Be)&&Qe(null),Nr(ae=>{const Oe=new Set(x.map(Et=>pt(Et,v)).filter(Boolean)),ve=new Set;for(const Et of ae)Oe.has(Et)&&ve.add(Et);return Xo(Go,ve),ve}),i.loadDeferred!==!1){const ae=f.filter(Oe=>Oe.untrackedDeferred&&Oe.root).map(Oe=>Oe.root);for(const Oe of ae)vl(Oe)}i.loadAudit!==!1&&nr()},[ue,Ce,nr,vl,v,Qe,zs]);o.useEffect(()=>{ml(),go.current=null,bo.current=v;const r=[],i=[],b=ed(v);Mt.current+=1,on.current+=1,Vs.current+=1,vr.current?.abort(),Ct(Hn(_r.current?.cwd??v??void 0)),_r.current=null,vr.current=null,Fr.current?.abort(),Ct("right-sidebar-git-details"),Fr.current=null;for(const q of yr.current.values())q.abort();for(const q of yr.current.keys())Ct(`right-sidebar-git-untracked:${q}`);yr.current.clear(),Ht.current.clear(),An.current+=1,Pn.current?.abort(),Pn.current=null,Tn.current+=1,Br.current?.abort(),Br.current=null,Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Kr([]),Vn([]),$r(!1),Pt(null),Yr([]),Lr(!1),hr([]),vn([]),Vt(!1),Yt(null),H(!1),be(null),$e(null),Ie(null),st(null),pr(!1),Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1),Ps(null),Zr(null),en(null),zi(!1),gt(qo,!1),Qa(!1);const x=v?rd()[v]:null,C=x?.previewEntries??[],I=x?.selectedPreviewKey??null,O=I?C.find(q=>q.key===I)??null:null;Wi(x?.selectedRepoRoots??[]),Is(x?.repoTargetBranches??{}),_s(x?.repoBaseBranches??{}),Yn(C),wn(x?.previewScrollTops??{}),O&&x?.previewDetailOpen&&(O.diff.hunks?.length??0)>0&&(Yt(O.diff),Zr(O.key),en(x.selectedPreviewFileKey??(O.diff.hunks?.[0]?`${O.diff.hunks[0].filePath}\0${O.diff.hunks[0].hunkHeader}\0${O.diff.hunks[0].hunkIndex}`:null)),Vt(!0)),Gi(x?.includeUncommitted??!0),go.current=v,Fs(!1),qe(b??null),Dr.current.clear(),rs.current.clear(),Qn(null),Zn(null),Tr(null),lt(null),Ji(null),ke(r),De(i),S(null),xo.current=null},[ml,v]);const In=o.useCallback(async(r=v??void 0,i={})=>{if(!r)return null;const f=v,b=i.includeNested??!0,x=i.refresh??i.reloadDiff??!1,C=i.cacheOnly??!1,I=i.background??!1;x&&Dr.current.clear();const O=_r.current;if(O&&O.cwd===r&&O.includeNested===b&&O.refresh===x&&O.cacheOnly===C)return Je("reuse_pending",{cwd:r,includeNested:b,refresh:x,cacheOnly:C}),O.promise;const q=Mt.current+1;Mt.current=q;const Ne=`right-sidebar:${xl}:${q}`;vr.current?.abort();const Xe=Hn(r);Ct(Xe);const Be=new AbortController;vr.current=Be;let ae=null;I||fl(Ne),mo(null),Je("start",{requestId:q,cwd:r,rootPath:v,requestSlotId:Xe,includeNested:b,refresh:x,cacheOnly:C,background:I,existingChanges:ye.size,lastLoadedAt:Ir}),!I&&typeof window<"u"&&(ae=window.setTimeout(()=>{Mt.current===q&&hl(Ne,!0)},Ip));const Oe=(async()=>{const ve=await ya(r,Be.signal,{includeNested:b,refresh:x,cacheOnly:C,action:x?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Xe,requestTimeoutMs:x?null:void 0});return Ug(ve)?(Je("cancelled_result_ignored",{requestId:q,activeRequestId:Mt.current,cwd:r,error:ve.error??ve.context?.error}),null):Mt.current!==q||!Ce(f)?(Je("stale_result",{requestId:q,activeRequestId:Mt.current,cwd:r,expectedRootPath:f,currentRootPath:oe.getState().rootPath,files:ve.files.length,repositories:ve.repositories?.length??0}),null):(Or(ve,{reloadDiff:i.reloadDiff,syncActiveRepo:b,background:I,cacheOnly:C,replaceRepoRoot:i.replaceRepoRoot}),ve)})();_r.current={cwd:r,includeNested:b,refresh:x,cacheOnly:C,promise:Oe};try{const ve=await Oe;return Mt.current===q&&ve&&Ce(f)?pl({cached:ve.cached,stale:ve.stale,cacheAgeMs:ve.cacheAgeMs,nestedDeferred:!b||ve.nestedDeferred,untrackedDeferred:ve.untrackedDeferred}):Mt.current===q&&Ce(f)&&ho(Ne),ve}catch(ve){return Mt.current!==q||!Ce(f)||or(ve)?(Je("aborted",{requestId:q,activeRequestId:Mt.current,cwd:r,expectedRootPath:f,currentRootPath:oe.getState().rootPath,message:ve instanceof Error?ve.message:String(ve)}),null):(Je("error",{requestId:q,cwd:r,includeNested:b,refresh:x,background:I,message:ve instanceof Error?ve.message:String(ve)}),I||(S(null),mo(ve instanceof Error?ve.message:"Failed to load Git changes")),null)}finally{ae!==null&&window.clearTimeout(ae),vr.current===Be&&(vr.current=null),_r.current?.promise===Oe&&(_r.current=null),!I&&Mt.current===q&&Ce(f)&&ho(Ne)}},[Or,fl,ye.size,ho,xl,Ir,Ce,pl,v,mo,hl]),ss=o.useCallback(async()=>{v&&await In(v,{reloadDiff:!0,includeNested:!0,refresh:!0})},[In,v]),vo=o.useCallback(async(r=v??void 0)=>{if(!r)return null;const i=v,f=on.current+1;on.current=f,Fr.current?.abort(),Ct("right-sidebar-git-details");const b=new AbortController;Fr.current=b,Fs(!0);try{const x=await Mc(r,b.signal,"load_git_details","right-sidebar-git-details");return on.current!==f||!Ce(i)?null:(ke(C=>C.map(I=>I.root===x.root?{...I,available:x.available,context:x,error:x.error}:I)),S(C=>C?.root&&x.root&&C.root!==x.root?C:!C?.available||!x.available?x:{...C,...x}),x)}catch(x){return or(x)||!Ce(i)||on.current===f&<(x instanceof Error?x.message:"Failed to load Git details"),null}finally{Fr.current===b&&(Fr.current=null),on.current===f&&Ce(i)&&Fs(!1)}},[Ce,v]);o.useEffect(()=>{if(!t){Mt.current+=1,on.current+=1,Vs.current+=1,vr.current?.abort(),Ct(Hn(_r.current?.cwd??v??void 0)),_r.current=null,vr.current=null,Fr.current?.abort(),Ct("right-sidebar-git-details"),Fr.current=null;for(const r of yr.current.values())r.abort();for(const r of yr.current.keys())Ct(`right-sidebar-git-untracked:${r}`);yr.current.clear(),Ht.current.clear(),Tn.current+=1,Br.current?.abort(),Br.current=null,Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Fs(!1),H(!1),be(null),$e(null),Ie(null),st(null),pr(!1),Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1),j(""),he(!1),yt(null),ro(!1),ee&&Yi(!1)}},[ee,t,he]),o.useEffect(()=>{if(!se)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[se]),o.useEffect(()=>{ee||br(!1)},[ee]);const as=o.useCallback(r=>{eo(r);const i=Js.current;i&&(i.update(),i.slideTo(r,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(r,0)}))},[]);o.useEffect(()=>{if(ee)if(br(m),m&&Ge){xr(1);const r=wr.current;r&&(r.update(),r.activeIndex!==1&&(ns.current=1,r.slideTo(1,0)))}else{xr(0);const r=wr.current;r&&r.activeIndex!==0&&(ns.current=0,r.slideTo(0,0)),yt(null)}},[ee,m,v,Ge]),o.useEffect(()=>{if(p!==void 0&&!m){xr(0);const r=wr.current;r&&r.activeIndex!==0&&(ns.current=0,r.slideTo(0,0)),br(!1),yt(null)}},[p,m]),o.useEffect(()=>{y!==void 0&&W(null)},[y]),o.useEffect(()=>{!ee&&m&&u?.()},[ee,u,m]),o.useEffect(()=>{co(r=>ki(r,n))},[n]);const ef=o.useCallback(r=>{ee||(r.preventDefault(),Xs.current={startX:r.clientX,startWidth:lo,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[lo,ee]),tf=o.useCallback(r=>{const i=Xs.current;if(!i||i.pointerId!==r.pointerId)return;const f=ki(i.startWidth+r.clientX-i.startX,n);co(f),vs(bs,f,Tp)},[n]),wl=o.useCallback(r=>{const i=Xs.current;if(!(!i||i.pointerId!==r.pointerId)){Xs.current=null,hs(bs);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),Zs=!!(v&&Ir!==null&&gd(ne)),kr=Zs?"files":uo,We=kr==="git",_n=kr==="files",ct=kr==="diff";o.useEffect(()=>{if(!ee){Ds(!0);return}if(!t){const i=window.setTimeout(()=>{Ds(!1)},Dp);return()=>window.clearTimeout(i)}Ds(!1);const r=window.setTimeout(()=>{Ds(!0)},_p);return()=>window.clearTimeout(r)},[ee,t]),o.useEffect(()=>{if(!ee||!ct)return;const r=Js.current;if(!r)return;const i=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(i)},[ct,ee]),o.useEffect(()=>{if(!Zs||!v||Nt)return;const r=window.setTimeout(()=>{In(v,{includeNested:!0,background:!0})},3e3);return()=>window.clearTimeout(r)},[Zs,v,Nt,In]),o.useEffect(()=>{if(!(t&&(We||ct))||!v||Nt||!Ks||xo.current===v)return;xo.current=v;const i=We&&!ee?0:Vo,f=window.setTimeout(()=>{In(v,{includeNested:!0,background:!0})},i);return()=>{window.clearTimeout(f)}},[ct,Nt,We,ee,t,In,Ks,v]),o.useEffect(()=>{!t||!We||(!ee||to)&&ro(!0)},[We,ee,t,to]),o.useEffect(()=>{if(!t||We)return;const r=window.setTimeout(()=>{ro(!0)},Vo);return()=>window.clearTimeout(r)},[We,t]),o.useEffect(()=>{ct&&Yi(!0)},[ct]);const kl=o.useCallback(r=>{ge&&Pg(ge,r.currentTarget.scrollTop)},[ge]);o.useEffect(()=>()=>{vr.current?.abort(),hs(Pi),hs(Ti),hs(bs),hs(Ko)},[]),o.useEffect(()=>{if(!ge||!Ks)return;const r=Au()[ge]?.top;if(typeof r!="number")return;let i=window.requestAnimationFrame(()=>{Ln.current&&(Ln.current.scrollTop=r),i=window.requestAnimationFrame(()=>{Ln.current&&(Ln.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(i)},[ge,Ks]),o.useEffect(()=>{if(!t)return;const r=new AbortController;return fh(r.signal).then(i=>rl(!!i.available)).catch(()=>rl(!1)),()=>r.abort()},[t]);const os=o.useCallback(r=>{if(re(null),Qe(r),yt(null),ee){br(!0),xr(1),wr.current?.slideTo(1),g?.();return}},[ee,g,Qe]),Sl=o.useCallback((r,i)=>{if(re(null),Qe(r),Te(i),ee){br(!0),xr(1),wr.current?.slideTo(1),g?.();return}},[ee,g,Qe]),is=o.useCallback(async(r,i)=>{const f=i||Mn||v;if(!(!f||r.length===0)){Us(!0);try{await Uo(f,r),Ws(f,!1)}catch(b){lt(b instanceof Error?b.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>lt(null),4e3)}finally{Us(!1)}}},[Mn,v,Ws,a]),jl=o.useCallback(async r=>{try{await hh(r)}catch(i){lt(i instanceof Error?i.message:a("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>lt(null),4e3)}},[a]),ea=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&io(!0)},[]),Rl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),io(!1)},[]),Cl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),io(!1);const i=r.dataTransfer.files;i.length>0&&is(Array.from(i))},[is]),Nl=o.useCallback(r=>{Se(r),window.setTimeout(()=>Se(i=>i===r?null:i),1400)},[]),Sr=o.useCallback(r=>{ot(r),window.setTimeout(()=>ot(i=>i===r?null:i),1400)},[]);o.useEffect(()=>{gt(Kc,Ke)},[Ke]),o.useEffect(()=>{gt(Vc,ft)},[ft]),o.useEffect(()=>{gt(Yc,Gt)},[Gt]),o.useEffect(()=>{vs(Ko,vt,$p)},[vt]),o.useEffect(()=>(ol().catch(()=>{}),Lc(r=>{r.type==="pinned-explorer-roots"&&il(r.pinnedExplorerRoots)})),[ol,il]);const Ml=o.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),ta=o.useRef(null),cn=o.useRef(null),[$l,yo]=o.useState(!1);o.useEffect(()=>{if(!t)return;yo(!1);let r=!1;mh().then(f=>{r||(ta.current=f.text,Ft(b=>f.text&&f.text!==b?f.text:b),yo(!0))}).catch(()=>{r||yo(!0)});const i=Lc(f=>{f.type==="context-draft"&&f.origin!==Ml.current&&(ta.current=f.text,Ft(f.text))});return()=>{r=!0,i(),cn.current!==null&&(window.clearTimeout(cn.current),cn.current=null)}},[t]),o.useEffect(()=>{if(!$l||ta.current===vt)return;cn.current!==null&&window.clearTimeout(cn.current);const r=vt;cn.current=window.setTimeout(()=>{cn.current=null,ph(r,Ml.current).then(()=>{ta.current=r}).catch(()=>{})},500)},[vt,$l]);const Dn=o.useCallback((r,i,f)=>{r&&(Ke?(Ft(b=>qm(b,r)+(f??"")),window.matchMedia("(pointer: coarse)").matches||(ir(!1),lr(b=>b+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:f?r+f:r,focus:!0}})),Nl(i))},[Ke,Nl]),ra=o.useCallback(r=>{const i=ka(r,v);return _h(i,v)},[v]),wo=Ad(Sr),Ur=o.useCallback((r,i)=>{const f=ka(r,v);Dn(Dh(f,v),i??`path:${f}`)},[v,Dn]),rf=o.useCallback(async r=>{Us(!0);try{await Fh(r,Uo,i=>{Ur(i,`path:${i}`)}),ee&&!Ke&&s()}catch(i){lt(i instanceof Error?i.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>lt(null),4e3)}finally{Us(!1)}},[Ke,Ur,ee,s,a]),jr=o.useCallback((r,i)=>{if(!r)return;const f=r.includes(`
|
|
1659
|
+
`})(),Er=`path:${Te}`,Pt=R?`path:${Te}:${R.start}-${R.end}`:Er,Vr=L===Er,Yr=L===Pt,As=A===Er,Lr=A===Pt,fr=Yr||Lr,hr=R?R.start===R.end?`L${R.start}`:`L${R.start}-${R.end}`:null,xn=P=>{const H=te.current;if(!H)return;const le=H.getBoundingClientRect(),be=P.currentTarget.getBoundingClientRect(),Fe=P.clientX||be.left+be.width/2,Ue=(P.clientY||be.top+be.height/2)-le.top+H.scrollTop,Ie=p?116:132,tt=H.scrollLeft+Math.max(8,H.clientWidth-Ie),st=Math.min(Math.max(8,Fe-le.left+H.scrollLeft+10),tt);me({top:Ue,left:st})},vn=(P,H)=>{Li()||(xn(P),M(le=>{const be=Ei(le,H,H);return be||me(null),be}))},mr=(P,H,le)=>{xn(P),M(be=>{const Fe=Ei(be,H,le);return Fe||me(null),Fe})},Vt=(P,H,le,be)=>{be==="end"&&xn(P),M({start:H,end:le})},Me=P=>{const{scrollTop:H,scrollLeft:le}=P.currentTarget;S(H),ti(k,n,{top:H,left:le,markdownTop:H})},Yt=P=>{if(P.directory){m?.(P.path);return}if(P.path===Te||j.kind==="text"&&P.path===j.sourcePath){P.fragment&&Gn(P.fragment);return}ke(H=>[...H,Te]),ue.current=P.path,De(P.fragment),M(null),B(P.path)},Xr=()=>{const P=X[X.length-1];P&&(ke(H=>H.slice(0,-1)),ue.current=P,De(null),M(null),B(P))},Yn=P=>{const{scrollTop:H,scrollLeft:le}=P.currentTarget;ti(k,n,{top:H,left:le})},yn=()=>{if(t){t($r,Pt);return}R&&l($r,Pt)},wn=async()=>{if(!(!Te||K.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){Se({status:"pending"});try{await jh(Te),Se({status:"idle"})}catch(P){Se({status:"error",message:P instanceof Error?P.message:a("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Ft.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${p&&(qr||ur)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[p&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a("rightSidebar.backToFileList"),title:a("rightSidebar.backToFileList"),children:e.jsx(Sd,{size:16})}),X.length>0&&e.jsxs("button",{type:"button",onClick:Xr,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${p?"w-9":"px-2.5"}`,"aria-label":a("rightSidebar.backToPreviousPreview"),title:a("rightSidebar.backToPreviousPreview"),children:[e.jsx(ks,{size:15}),!p&&e.jsx("span",{className:"text-[11px] font-medium",children:a("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Te,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Ut.name}),Ut.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Ut.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ot&&e.jsx("button",{type:"button",onClick:Re?Gr:yt,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${Re?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":a("rightSidebar.findInFile"),title:`${a("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(zn,{size:14})}),Es&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{g&&y?.(),je(P=>{const H=P==="preview"?"source":"preview";return gt(Hd,H),H}),M(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:p?pe==="preview"?e.jsx(gi,{size:14}):e.jsx(pi,{size:14}):a(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),qn&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(P=>{const H=P==="preview"?"source":"preview";return Xm(k,n,H),H}),M(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:p?N==="preview"?e.jsx(gi,{size:14}):e.jsx(pi,{size:14}):a(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),ur&&e.jsx("button",{type:"button",onClick:()=>{de.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(Cd,{size:15})}),!p&&e.jsx("button",{type:"button",onClick:()=>s(Te,Er),...Ft(Nr,Er),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Vr||As?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:a("rightSidebar.insertReference",{reference:Nr}),children:a(As?"rightSidebar.copied":Vr?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Nr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.copyReference",{reference:Nr}),"aria-label":a("rightSidebar.copyFileRef"),children:e.jsx(lh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{wn()},disabled:K.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:K.status==="error"?K.message??a("rightSidebar.downloadFailed"):a("rightSidebar.downloadFile"),"aria-label":a("rightSidebar.downloadFile"),children:K.status==="pending"?e.jsx(nt,{size:13,className:"animate-spin"}):e.jsx(Ih,{size:14})})]})]}),Re&&Ot&&e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:vt,type:"search",value:Ke,onChange:P=>pn(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),Cr(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:a("rightSidebar.findInFilePlaceholder"),"aria-label":a("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ft.length>0?`${Gt+1}/${ft.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Cr(-1),disabled:ft.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.previousSearchMatch"),title:`${a("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(yd,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Cr(1),disabled:ft.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.nextSearchMatch"),title:`${a("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(_h,{size:13})}),e.jsx("button",{type:"button",onClick:Gr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.closeFileSearch"),title:`${a("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Dt,{size:13})})]}),wt&&!(p&&(qr||ur))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[wt.size!==null&&e.jsx("span",{children:a("rightSidebar.byteCount",{count:wt.size.toLocaleString()})}),"truncated"in wt&&wt.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:a("rightSidebar.previewTruncated")}),"mimeType"in wt&&e.jsx("span",{children:wt.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(p&&(qr||ur))&&!kt&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:Kn?a("rightSidebar.edaPickHint"):At?a("rightSidebar.csvTablePreview"):Ls||Kt?a("rightSidebar.kicadProjectPickHint"):Kr?a("rightSidebar.videoPreviewHint"):Ya?a("rightSidebar.imagePreviewHint"):qr?R?a("rightSidebar.selectedLineHint",{lineLabel:hr??""}):a("rightSidebar.markdownPreviewHint"):ur?a("rightSidebar.htmlPreviewHint"):R?a("rightSidebar.selectedLineHint",{lineLabel:hr??""}):a("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?a("rightSidebar.edaLoading"):j.mode==="image"?a("rightSidebar.loadingImage"):j.mode==="model3d"?a("rightSidebar.model3dLoading"):j.mode==="video"?a("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:bn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:a("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:a("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(Dd,{blobUrl:j.objectUrl,filePath:Te,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(Hu,{src:j.objectUrl,alt:Ut.name,vector:!1,onLoad:P=>{const H=P.currentTarget;Y(le=>le.kind==="image"?{...le,dimensions:{width:H.naturalWidth,height:H.naturalHeight}}:le)},onError:()=>Y({kind:"error",message:a("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(tp,{url:j.url,onLoadError:()=>Y({kind:"error",message:a("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(lp,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Te.toLowerCase().endsWith(".kicad_pcb"),onViewChange:se,onInsertAnnotation:t??c,onRefresh:bn,interactive3d:he?e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(Qc,{blobUrl:he.objectUrl,ext:".glb",fileName:Ut.name,filePath:he.sourcePath,features:null,onInsertFeature:t??c,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(Qc,{blobUrl:j.objectUrl,ext:j.ext,fileName:Ut.name,filePath:j.sourcePath,features:$,onInsertFeature:t??c,onRefresh:bn})})}):j.kind==="text"&&At?e.jsx(up,{content:j.content,filePath:Te,onInsertAnnotation:t??c},Te):j.kind==="text"&&(Ls||Kt)?e.jsx(mp,{content:j.content,filePath:Te,localState:Kt,onInsertAnnotation:t??c},Te):qr?e.jsxs("div",{ref:te,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:Me,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Lu,{content:j.content,filePath:j.sourcePath,rootPath:k,lineRange:R,onLineRangeClick:mr,onLineRangeDrag:Vt,scrollTop:ne,outlineOpen:g,outlineCloseSignal:u,onOutlineOpen:w,onOutlineClose:y,lightboxOpen:E,lightboxCloseSignal:T,onLightboxOpen:_,onLightboxClose:U,onLocalLinkOpen:Yt}),R&&ie&&e.jsxs("button",{type:"button",onClick:yn,...Ft($r,Pt),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:fd(p,fr),title:`Insert markdown reference: ${Mr}`,children:[e.jsx(Da,{size:p?13:11}),Lr?a("rightSidebar.copied"):Yr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:hr??""})]})]}):ur?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(kp,{ref:de,src:ch(Te),title:`${Ut.name} preview`,exitFullscreenLabel:a("rightSidebar.htmlFullscreenExit"),onFullscreenChange:ze},`${Te}:${qt}:${Bt}`)}):j.kind==="text"?e.jsxs("div",{ref:te,onScroll:Yn,className:`${_i} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[dr.length>0?e.jsx("div",{className:"min-w-full",children:dr.map((P,H)=>{const le=H+1,be=!!(R&&le>=R.start&&le<=R.end),Fe=Le&&Le.length===dr.length?Le[H]:null;return e.jsxs("div",{ref:$e=>{$e?V.current.set(le,$e):V.current.delete(le)},role:"button","data-file-preview-line":le,tabIndex:0,onClick:$e=>vn($e,le),onKeyDown:$e=>{$e.key!=="Enter"&&$e.key!==" "||($e.preventDefault(),vn($e,le))},style:{gridTemplateColumns:`${Va}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${be?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${Nr}:${le}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${be?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:le}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Fe??(P||" ")})]},H)})}):"Empty file.",R&&ie&&e.jsxs("button",{type:"button",onClick:yn,...Ft($r,Pt),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:fd(p,fr),title:`Insert code reference: ${Mr}`,children:[e.jsx(Da,{size:p?13:11}),Lr?a("rightSidebar.copied"):Yr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:hr??""})]})]}):null]})}function nb({isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:c,pinned:d=!1,onTogglePinned:h,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:p,onOpenRightSidebarFilePreview:g,onCloseRightSidebarFilePreview:u,rightSidebarRepoPickerOpen:w=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:E,onCloseRightSidebarRepoPicker:T,markdownOutlineOpen:_=!1,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L=!1,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D}){const{t:a,locale:k}=xt(),[B,j]=o.useState(""),[Y,re]=o.useState(null),se=oe(r=>r.rightSearchOpen),he=oe(r=>r.setRightSearchOpen),G=oe(r=>r.rightSidebarLayoutPreference),J=oe(r=>r.setRightSidebarLayoutPreference),[$,F]=o.useState(()=>Jp()),[V,te]=o.useState("."),[ie,me]=o.useState(""),[pe,je]=o.useState(!1),[N,Z]=o.useState(!1),[de,Ee]=o.useState(!1),[ze,Pe]=o.useState(!1),ce=o.useDeferredValue(B),[ne,S]=o.useState(null),[X,ke]=o.useState([]),[xe,De]=o.useState([]),[ue,qe]=o.useState(null),[Le,W]=o.useState(null),[K,Se]=o.useState(null),[Re,ot]=o.useState(null),[Ke,pn]=o.useState(()=>Ze(Kc,xs)??!1),[ft,ir]=o.useState(()=>Ze(Vc,xs)??!1),[Gt,gn]=o.useState(()=>Ze(Yc,xs)??!1),[vt,Ft]=o.useState(()=>Ze(Vo,qp)??""),[Wr,lr]=o.useState(0),[qt,Lt]=o.useState(!1),[cr,Bt]=o.useState(!1),$s=o.useRef(null),bn=o.useRef(null),[Gn,Ot]=o.useState(!1),[Gr,yt]=o.useState(null),[Cr,Te]=o.useState(null),[Ut,Nr]=o.useState(()=>td(qo)),[dr,Va]=o.useState(()=>td(qc)),[wt,Es]=o.useState(()=>Gp()),[At,Ls]=o.useState(()=>Kp()),[Kt,qr]=o.useState(()=>Yp()),qn="words",[ur,Ya]=o.useState(0),[kt,Kr]=o.useState([]),[Kn,Vn]=o.useState([]),[Mr,$r]=o.useState(!1),[Er,Pt]=o.useState(null),[Vr,Yr]=o.useState([]),[As,Lr]=o.useState(!1),[fr,hr]=o.useState([]),[xn,vn]=o.useState([]),[mr,Vt]=o.useState(!1),[Me,Yt]=o.useState(null),[Xr,Yn]=o.useState([]),[yn,wn]=o.useState({}),[P,H]=o.useState(!1),[le,be]=o.useState(null),[Fe,$e]=o.useState(null),[Ue,Ie]=o.useState(null),[tt,st]=o.useState(null),[Xt,pr]=o.useState(!1),[kn,Jr]=o.useState(""),Xn=o.useDeferredValue(kn),[Jt,Qt]=o.useState([]),[Sn,Qr]=o.useState(!1),[Q,_e]=o.useState(!1),[Zt,er]=o.useState(null),[Xa,jn]=o.useState(!1),tr=o.useRef(null),Ar=o.useRef(0),zi=o.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[zu,Ps]=o.useState(null),[Jn,Wi]=o.useState(()=>Ze(Ko,xs)??!1),[Ja,Qa]=o.useState(!1),[Ts,Gi]=o.useState([]),[gr,Is]=o.useState({}),[St,_s]=o.useState({}),[Pr,qi]=o.useState(!0),[Ki,Vi]=o.useState(()=>new Set),[Ve,Zr]=o.useState(null),[Za,en]=o.useState(null),[Wu,br]=o.useState(!1),[Yi,xr]=o.useState(0),[,eo]=o.useState(0),[to,Ds]=o.useState(!1),[rr,ro]=o.useState(!1),[Gu,Xi]=o.useState(()=>oe.getState().rightTab==="diff"),[Ae,Qn]=o.useState(null),[Rn,Zn]=o.useState(null),[it,Tr]=o.useState(null),[Ji,lt]=o.useState(null),[Cn,Qi]=o.useState(null),[no,qu]=o.useState(()=>Date.now()),[Ku,Vu]=o.useState(!1),[tn,Fs]=o.useState(!1),[Bs,Zi]=o.useState(""),[es,so]=o.useState(""),[rn,ao]=o.useState(""),[nn,oo]=o.useState(""),[el,Nn]=o.useState(null),[Os,Us]=o.useState(!1),[tl,io]=o.useState(!1),[rl,nl]=o.useState(!1),[Hs,Yu]=o.useState({key:null,nonce:0}),sl=o.useRef(null),al=o.useRef(null),ee=Rh(n,d,G),Xu=Zd(ee,d,Kt),[lo,co]=o.useState(()=>ag(n)),uo=oe(r=>r.rightTab),sn=oe(r=>r.setRightTab),v=oe(r=>r.rootPath),Mn=oe(r=>r.explorerRoot),ol=oe(r=>r.pinnedExplorerRootsCache),il=oe(r=>r.hydratePinnedExplorerRoots),ll=oe(r=>r.syncPinnedExplorerRoots),Tt=oe(r=>r.setExplorerRoot),cl=oe(r=>r.resetExplorerToProject),$n=oe(r=>r.pinExplorerRoot),an=oe(r=>r.unpinExplorerRoot),Ge=oe(r=>r.selectedFilePath),Qe=oe(r=>r.selectFile),fo=oe(r=>r.showHiddenFiles),Ju=oe(r=>r.toggleShowHiddenFiles),ye=oe(r=>r.changedFiles),zs=oe(r=>r.setChangedFiles),Ws=oe(r=>r.invalidateDirectoryCache),Qu=oe(r=>r.setDirectorySortMode),dl=oe(r=>r.applyFileWatchEvents),ul=oe(r=>r.reconcileDirectoryCache),fl=oe(r=>r.bumpFileWatchEpoch),Nt=oe(r=>r.gitBundleLoading),Gs=oe(r=>r.gitBundleSlow),En=oe(r=>r.gitBundleError),Ir=oe(r=>r.gitBundleLastLoadedAt),hl=oe(r=>r.beginGitBundleLoading),ml=oe(r=>r.setGitBundleSlowFor),ho=oe(r=>r.finishGitBundleLoading),pl=oe(r=>r.resetGitBundleLoading),mo=oe(r=>r.setGitBundleError),gl=oe(r=>r.markGitBundleLoaded),ge=Mn??v,bl=o.useMemo(()=>ge?Np(ge,V):"",[ge,V]),ts=o.useMemo(()=>Cp(ie),[ie]),xl=o.useMemo(()=>({excludePatterns:ts,caseSensitive:N,wholeWord:de,regex:ze}),[N,ts,ze,de]),qs=oe(r=>ge?r.fileSortModes[ge]??"name":"name"),Ks=oe(r=>!!(ge&&r.directoryCache.has(ge))),Ln=o.useRef(null),Mt=o.useRef(0),[vl]=o.useState(()=>++Jg),vr=o.useRef(null),_r=o.useRef(null),Vs=o.useRef(0),Ht=o.useRef(new Map),yr=o.useRef(new Map),Dr=o.useRef(new Set),rs=o.useRef(new Set),on=o.useRef(0),Fr=o.useRef(null),An=o.useRef(0),Pn=o.useRef(null),Tn=o.useRef(0),Br=o.useRef(null),po=o.useRef(new Set),go=o.useRef(null),bo=o.useRef(null),Ys=o.useRef(null),xo=o.useRef(null);o.useEffect(()=>{if(Cn===null)return;const r=Math.max(0,Date.now()-Cn),i=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,f=Math.max(50,i-r%i),b=window.setTimeout(()=>qu(Date.now()),f);return()=>window.clearTimeout(b)},[no,Cn]);const Xs=o.useRef(null),wr=o.useRef(null),Js=o.useRef(null),ns=o.useRef(null),Ce=o.useCallback(r=>oe.getState().rootPath===r,[]);o.useEffect(()=>{if(!t||typeof window>"u")return;const r=i=>{const f=tb(i.target);f&&Aa("global_change_row_event",{...rb(i),selectionPath:f.dataset.diffSelectionPath,filePath:f.dataset.diffFilePath,absolutePath:f.dataset.diffAbsolutePath,repoRoot:f.dataset.diffRepoRoot,status:f.dataset.diffStatus,selectedFilePath:oe.getState().selectedFilePath,rightTab:oe.getState().rightTab,activeGitRepoRoot:ue,changedFiles:oe.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[ue,t]);const yl=o.useCallback(async(r=v??void 0)=>{if(!r)return null;if(Dr.current.has(r)||rs.current.has(r))return Je("untracked_skip_cached",{cwd:r,rootPath:v,completed:Dr.current.has(r),running:rs.current.has(r)}),null;const i=v,f=Vs.current+1;Vs.current=f,Ht.current.set(r,f);const b=`right-sidebar-git-untracked:${r}`,x=new AbortController;yr.current.set(r,x),rs.current.add(r),Je("untracked_start",{requestId:f,cwd:r,rootPath:v});try{let C=await Cc(r,x.signal,b),I=0;for(;C.status==="running"&&I<120;){if(Ht.current.get(r)!==f||x.signal.aborted)return Je("untracked_stale_result",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,status:C.status}),null;if(!Ce(i))return Je("untracked_root_changed",{requestId:f,cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath}),null;await new Promise(q=>window.setTimeout(q,I<10?1e3:3e3)),I+=1,C=await Cc(r,x.signal,b)}if(Ht.current.get(r)!==f||!Ce(i))return Je("untracked_stale_result",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath,files:C.files.length,status:C.status}),null;if(C.status==="done")return zs(Iu(oe.getState().changedFiles,C.files)),C.files.length>0&&ke(q=>{const Xe=new Map(q.map(ve=>[ve.root,ve])).get(r);if(!Xe)return q;const Be=Bg(Xe.files,C.files),ae=q.map(ve=>ve.root===r?{...ve,files:Be,context:ve.context?{...ve.context,changedFiles:Be.map(Et=>({path:Et.path,absolutePath:Et.absolutePath,status:Et.status})),truncated:!1}:ve.context,untrackedDeferred:!1}:ve);De(_u(ae,v));const Oe=ae.find(ve=>ve.root===v);return Oe?.context&&S(ve=>ve?.root===Oe.root?{...ve,...Oe.context}:ve),ae}),Dr.current.add(r),Je("untracked_apply",{requestId:f,cwd:r,files:C.files.length}),C;const O=C.error||(C.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return Dr.current.add(r),Je("untracked_error",{requestId:f,cwd:r,message:O,code:C.code,status:C.status}),null}catch(C){if(Ht.current.get(r)!==f||!Ce(i)||or(C))return Je("untracked_aborted",{requestId:f,activeRequestId:Ht.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:oe.getState().rootPath,message:C instanceof Error?C.message:String(C)}),null;const I=C instanceof Error?C.message:"Failed to scan untracked files";return Dr.current.add(r),Je("untracked_error",{requestId:f,cwd:r,message:I}),null}finally{yr.current.get(r)===x&&yr.current.delete(r),Ht.current.get(r)===f&&Ht.current.delete(r),rs.current.delete(r)}},[ne,Ce,v,zs]),zt=o.useMemo(()=>{const r=new Set(xe.map(f=>f.root)),i=Vr.filter(f=>r.has(f));return i.length>0?i:ue?[ue]:[]},[ue,Vr,xe]),wl=zt.length===0,ln=o.useMemo(()=>zt.map(r=>X.find(i=>i.root===r)).filter(r=>!!r),[zt,X]),Zu=o.useMemo(()=>xe.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[xe]),nr=o.useCallback(async()=>{if(!v){Kr([]),Vn([]);return}const r=v,i=An.current+1;An.current=i,Pn.current?.abort();const f=new AbortController;Pn.current=f,$r(kt.length===0),Pt(null);try{const b=zt.length>0?await Promise.all(zt.map(x=>Nc({workspaceRoot:v,repoRoot:x},f.signal))).then(x=>({records:x.flatMap(C=>C.records),walkthroughs:x.flatMap(C=>C.walkthroughs??[])})):await Nc({workspaceRoot:v},f.signal);if(An.current!==i||!Ce(r))return;Kr(b.records),Vn(b.walkthroughs??[])}catch(b){if(An.current!==i||!Ce(r)||or(b))return;Pt(b instanceof Error?b.message:"Failed to load change audit explanations")}finally{Pn.current===f&&(Pn.current=null),An.current===i&&Ce(r)&&$r(!1)}},[kt.length,zt,Ce,v]),Qs=o.useCallback(async(r,i,f)=>{if(!r&&!v){hr([]),vn([]);return}const b=v,x=Tn.current+1;Tn.current=x,Br.current?.abort();const C=new AbortController;Br.current=C;try{const I=r?[r]:Array.from(new Set([v,...X.map(q=>q.root)].filter(q=>!!q))),O=await Promise.all(I.map(q=>uh({repoRoot:q,baseRef:i,branchName:f},C.signal))).then(q=>{const Ne=new Map,Xe=new Map;for(const Be of q){for(const ae of Be.records)Ne.set(ae.id,ae);for(const ae of Be.walkthroughs??[])Xe.set(ae.id,ae)}return{records:Array.from(Ne.values()),walkthroughs:Array.from(Xe.values())}});if(Tn.current!==x||!Ce(b))return;hr(O.records),vn(O.walkthroughs??[])}catch(I){if(Tn.current!==x||!Ce(b)||or(I))return;console.warn("[RightSidebar] Failed to load branch explanations",I)}finally{Br.current===C&&(Br.current=null)}},[X,Ce,v]),Or=o.useCallback((r,i={})=>{if(!Ce(v)){Je("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:oe.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}Je(r.files.length===0?"empty_bundle":"apply",{rootPath:v,available:r.available,files:r.files.length,repositories:r.repositories?.map(ae=>({root:ae.root,relativeRoot:ae.relativeRoot,files:ae.files.length,available:ae.available,error:ae.error})),repoFilters:r.repoFilters?.map(ae=>({root:ae.root,label:ae.label,count:ae.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let f=eu(r),b=r.repoFilters??[],x=r.files;const C=oe.getState().changedFiles;if(!!(i.cacheOnly&&!r.cached&&r.files.length===0&&f.length===0)&&(C.size>0||X.length>0||ne)){Je("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:C.size,currentRepositories:X.length});return}const O=hd(C.values(),v),q=hd(r.files,v),Ne=f.some(ae=>ae.root!==v);if(!!(i.background&&C.size>0&&(r.files.length===0&&!r.error||O>0&&q===0&&!Ne))){Je("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:C.size,nextFiles:r.files.length,currentNestedCount:O,nextNestedCount:q,nextRepositories:f.map(ae=>({root:ae.root,relativeRoot:ae.relativeRoot,files:ae.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(i.replaceRepoRoot){const ae=Du(C.values(),X,r,i.replaceRepoRoot,v);x=ae.files,f=ae.repositories,b=ae.repoFilters}if(zs(Tu(x)),ke(f),De(b),i.syncActiveRepo!==!1){const ae=i.activeRepoRoot!==void 0?i.activeRepoRoot:ue??ed(v),Oe=Zp({...r,repositories:f,repoFilters:b},ae);qe(Oe),Xo(v,Oe)}typeof r.cacheUpdatedAt=="number"&&Qi(r.cacheUpdatedAt),S(ae=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==v)return ae;if(!r.context)return null;const Oe=ae?.root??v;return!ae?.available||Oe!==(r.context.root??v)?r.context:{...ae,...r.context}}),i.reloadDiff&&Ya(ae=>ae+1);const Be=oe.getState().selectedFilePath;if(Be&&!Be.startsWith("/")&&!x.some(ae=>ae.path===Be||ae.absolutePath===Be)&&Qe(null),Nr(ae=>{const Oe=new Set(x.map(Et=>pt(Et,v)).filter(Boolean)),ve=new Set;for(const Et of ae)Oe.has(Et)&&ve.add(Et);return Jo(qo,ve),ve}),i.loadDeferred!==!1){const ae=f.filter(Oe=>Oe.untrackedDeferred&&Oe.root).map(Oe=>Oe.root);for(const Oe of ae)yl(Oe)}i.loadAudit!==!1&&nr()},[ue,Ce,nr,yl,v,Qe,zs]);o.useEffect(()=>{pl(),go.current=null,bo.current=v;const r=[],i=[],b=ed(v);Mt.current+=1,on.current+=1,Vs.current+=1,vr.current?.abort(),Ct(Hn(_r.current?.cwd??v??void 0)),_r.current=null,vr.current=null,Fr.current?.abort(),Ct("right-sidebar-git-details"),Fr.current=null;for(const q of yr.current.values())q.abort();for(const q of yr.current.keys())Ct(`right-sidebar-git-untracked:${q}`);yr.current.clear(),Ht.current.clear(),An.current+=1,Pn.current?.abort(),Pn.current=null,Tn.current+=1,Br.current?.abort(),Br.current=null,Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Kr([]),Vn([]),$r(!1),Pt(null),Yr([]),Lr(!1),hr([]),vn([]),Vt(!1),Yt(null),H(!1),be(null),$e(null),Ie(null),st(null),pr(!1),Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1),Ps(null),Zr(null),en(null),Wi(!1),gt(Ko,!1),Qa(!1);const x=v?rd()[v]:null,C=x?.previewEntries??[],I=x?.selectedPreviewKey??null,O=I?C.find(q=>q.key===I)??null:null;Gi(x?.selectedRepoRoots??[]),Is(x?.repoTargetBranches??{}),_s(x?.repoBaseBranches??{}),Yn(C),wn(x?.previewScrollTops??{}),O&&x?.previewDetailOpen&&(O.diff.hunks?.length??0)>0&&(Yt(O.diff),Zr(O.key),en(x.selectedPreviewFileKey??(O.diff.hunks?.[0]?`${O.diff.hunks[0].filePath}\0${O.diff.hunks[0].hunkHeader}\0${O.diff.hunks[0].hunkIndex}`:null)),Vt(!0)),qi(x?.includeUncommitted??!0),go.current=v,Fs(!1),qe(b??null),Dr.current.clear(),rs.current.clear(),Qn(null),Zn(null),Tr(null),lt(null),Qi(null),ke(r),De(i),S(null),xo.current=null},[pl,v]);const In=o.useCallback(async(r=v??void 0,i={})=>{if(!r)return null;const f=v,b=i.includeNested??!0,x=i.refresh??i.reloadDiff??!1,C=i.cacheOnly??!1,I=i.background??!1;x&&Dr.current.clear();const O=_r.current;if(O&&O.cwd===r&&O.includeNested===b&&O.refresh===x&&O.cacheOnly===C)return Je("reuse_pending",{cwd:r,includeNested:b,refresh:x,cacheOnly:C}),O.promise;const q=Mt.current+1;Mt.current=q;const Ne=`right-sidebar:${vl}:${q}`;vr.current?.abort();const Xe=Hn(r);Ct(Xe);const Be=new AbortController;vr.current=Be;let ae=null;I||hl(Ne),mo(null),Je("start",{requestId:q,cwd:r,rootPath:v,requestSlotId:Xe,includeNested:b,refresh:x,cacheOnly:C,background:I,existingChanges:ye.size,lastLoadedAt:Ir}),!I&&typeof window<"u"&&(ae=window.setTimeout(()=>{Mt.current===q&&ml(Ne,!0)},_p));const Oe=(async()=>{const ve=await ya(r,Be.signal,{includeNested:b,refresh:x,cacheOnly:C,action:x?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Xe,requestTimeoutMs:x?null:void 0});return Hg(ve)?(Je("cancelled_result_ignored",{requestId:q,activeRequestId:Mt.current,cwd:r,error:ve.error??ve.context?.error}),null):Mt.current!==q||!Ce(f)?(Je("stale_result",{requestId:q,activeRequestId:Mt.current,cwd:r,expectedRootPath:f,currentRootPath:oe.getState().rootPath,files:ve.files.length,repositories:ve.repositories?.length??0}),null):(Or(ve,{reloadDiff:i.reloadDiff,syncActiveRepo:b,background:I,cacheOnly:C,replaceRepoRoot:i.replaceRepoRoot}),ve)})();_r.current={cwd:r,includeNested:b,refresh:x,cacheOnly:C,promise:Oe};try{const ve=await Oe;return Mt.current===q&&ve&&Ce(f)?gl({cached:ve.cached,stale:ve.stale,cacheAgeMs:ve.cacheAgeMs,nestedDeferred:!b||ve.nestedDeferred,untrackedDeferred:ve.untrackedDeferred}):Mt.current===q&&Ce(f)&&ho(Ne),ve}catch(ve){return Mt.current!==q||!Ce(f)||or(ve)?(Je("aborted",{requestId:q,activeRequestId:Mt.current,cwd:r,expectedRootPath:f,currentRootPath:oe.getState().rootPath,message:ve instanceof Error?ve.message:String(ve)}),null):(Je("error",{requestId:q,cwd:r,includeNested:b,refresh:x,background:I,message:ve instanceof Error?ve.message:String(ve)}),I||(S(null),mo(ve instanceof Error?ve.message:"Failed to load Git changes")),null)}finally{ae!==null&&window.clearTimeout(ae),vr.current===Be&&(vr.current=null),_r.current?.promise===Oe&&(_r.current=null),!I&&Mt.current===q&&Ce(f)&&ho(Ne)}},[Or,hl,ye.size,ho,vl,Ir,Ce,gl,v,mo,ml]),ss=o.useCallback(async()=>{v&&await In(v,{reloadDiff:!0,includeNested:!0,refresh:!0})},[In,v]),vo=o.useCallback(async(r=v??void 0)=>{if(!r)return null;const i=v,f=on.current+1;on.current=f,Fr.current?.abort(),Ct("right-sidebar-git-details");const b=new AbortController;Fr.current=b,Fs(!0);try{const x=await Mc(r,b.signal,"load_git_details","right-sidebar-git-details");return on.current!==f||!Ce(i)?null:(ke(C=>C.map(I=>I.root===x.root?{...I,available:x.available,context:x,error:x.error}:I)),S(C=>C?.root&&x.root&&C.root!==x.root?C:!C?.available||!x.available?x:{...C,...x}),x)}catch(x){return or(x)||!Ce(i)||on.current===f&<(x instanceof Error?x.message:"Failed to load Git details"),null}finally{Fr.current===b&&(Fr.current=null),on.current===f&&Ce(i)&&Fs(!1)}},[Ce,v]);o.useEffect(()=>{if(!t){Mt.current+=1,on.current+=1,Vs.current+=1,vr.current?.abort(),Ct(Hn(_r.current?.cwd??v??void 0)),_r.current=null,vr.current=null,Fr.current?.abort(),Ct("right-sidebar-git-details"),Fr.current=null;for(const r of yr.current.values())r.abort();for(const r of yr.current.keys())Ct(`right-sidebar-git-untracked:${r}`);yr.current.clear(),Ht.current.clear(),Tn.current+=1,Br.current?.abort(),Br.current=null,Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Fs(!1),H(!1),be(null),$e(null),Ie(null),st(null),pr(!1),Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1),j(""),he(!1),yt(null),ro(!1),ee&&Xi(!1)}},[ee,t,he]),o.useEffect(()=>{if(!se)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[se]),o.useEffect(()=>{ee||br(!1)},[ee]);const as=o.useCallback(r=>{eo(r);const i=Js.current;i&&(i.update(),i.slideTo(r,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(r,0)}))},[]);o.useEffect(()=>{if(ee)if(br(m),m&&Ge){xr(1);const r=wr.current;r&&(r.update(),r.activeIndex!==1&&(ns.current=1,r.slideTo(1,0)))}else{xr(0);const r=wr.current;r&&r.activeIndex!==0&&(ns.current=0,r.slideTo(0,0)),yt(null)}},[ee,m,v,Ge]),o.useEffect(()=>{if(p!==void 0&&!m){xr(0);const r=wr.current;r&&r.activeIndex!==0&&(ns.current=0,r.slideTo(0,0)),br(!1),yt(null)}},[p,m]),o.useEffect(()=>{y!==void 0&&W(null)},[y]),o.useEffect(()=>{!ee&&m&&u?.()},[ee,u,m]),o.useEffect(()=>{co(r=>Si(r,n))},[n]);const ef=o.useCallback(r=>{ee||(r.preventDefault(),Xs.current={startX:r.clientX,startWidth:lo,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[lo,ee]),tf=o.useCallback(r=>{const i=Xs.current;if(!i||i.pointerId!==r.pointerId)return;const f=Si(i.startWidth+r.clientX-i.startX,n);co(f),vs(bs,f,Ip)},[n]),kl=o.useCallback(r=>{const i=Xs.current;if(!(!i||i.pointerId!==r.pointerId)){Xs.current=null,hs(bs);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),Zs=!!(v&&Ir!==null&&gd(ne)),kr=Zs?"files":uo,We=kr==="git",_n=kr==="files",ct=kr==="diff";o.useEffect(()=>{if(!ee){Ds(!0);return}if(!t){const i=window.setTimeout(()=>{Ds(!1)},Fp);return()=>window.clearTimeout(i)}Ds(!1);const r=window.setTimeout(()=>{Ds(!0)},Dp);return()=>window.clearTimeout(r)},[ee,t]),o.useEffect(()=>{if(!ee||!ct)return;const r=Js.current;if(!r)return;const i=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(i)},[ct,ee]),o.useEffect(()=>{if(!Zs||!v||Nt)return;const r=window.setTimeout(()=>{In(v,{includeNested:!0,background:!0})},3e3);return()=>window.clearTimeout(r)},[Zs,v,Nt,In]),o.useEffect(()=>{if(!(t&&(We||ct))||!v||Nt||!Ks||xo.current===v)return;xo.current=v;const i=We&&!ee?0:Yo,f=window.setTimeout(()=>{In(v,{includeNested:!0,background:!0})},i);return()=>{window.clearTimeout(f)}},[ct,Nt,We,ee,t,In,Ks,v]),o.useEffect(()=>{!t||!We||(!ee||to)&&ro(!0)},[We,ee,t,to]),o.useEffect(()=>{if(!t||We)return;const r=window.setTimeout(()=>{ro(!0)},Yo);return()=>window.clearTimeout(r)},[We,t]),o.useEffect(()=>{ct&&Xi(!0)},[ct]);const Sl=o.useCallback(r=>{ge&&Tg(ge,r.currentTarget.scrollTop)},[ge]);o.useEffect(()=>()=>{vr.current?.abort(),hs(Ti),hs(Ii),hs(bs),hs(Vo)},[]),o.useEffect(()=>{if(!ge||!Ks)return;const r=Au()[ge]?.top;if(typeof r!="number")return;let i=window.requestAnimationFrame(()=>{Ln.current&&(Ln.current.scrollTop=r),i=window.requestAnimationFrame(()=>{Ln.current&&(Ln.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(i)},[ge,Ks]),o.useEffect(()=>{if(!t)return;const r=new AbortController;return fh(r.signal).then(i=>nl(!!i.available)).catch(()=>nl(!1)),()=>r.abort()},[t]);const os=o.useCallback(r=>{if(re(null),Qe(r),yt(null),ee){br(!0),xr(1),wr.current?.slideTo(1),g?.();return}},[ee,g,Qe]),jl=o.useCallback((r,i)=>{if(re(null),Qe(r),Te(i),ee){br(!0),xr(1),wr.current?.slideTo(1),g?.();return}},[ee,g,Qe]),is=o.useCallback(async(r,i)=>{const f=i||Mn||v;if(!(!f||r.length===0)){Us(!0);try{await Ho(f,r),Ws(f,!1)}catch(b){lt(b instanceof Error?b.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>lt(null),4e3)}finally{Us(!1)}}},[Mn,v,Ws,a]),Rl=o.useCallback(async r=>{try{await hh(r)}catch(i){lt(i instanceof Error?i.message:a("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>lt(null),4e3)}},[a]),ea=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&io(!0)},[]),Cl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),io(!1)},[]),Nl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),io(!1);const i=r.dataTransfer.files;i.length>0&&is(Array.from(i))},[is]),yo=o.useCallback(r=>{Se(r),window.setTimeout(()=>Se(i=>i===r?null:i),1400)},[]),Sr=o.useCallback(r=>{ot(r),window.setTimeout(()=>ot(i=>i===r?null:i),1400)},[]);o.useEffect(()=>{gt(Kc,Ke)},[Ke]),o.useEffect(()=>{gt(Vc,ft)},[ft]),o.useEffect(()=>{gt(Yc,Gt)},[Gt]),o.useEffect(()=>{vs(Vo,vt,Ep)},[vt]),o.useEffect(()=>(il().catch(()=>{}),Lc(r=>{r.type==="pinned-explorer-roots"&&ll(r.pinnedExplorerRoots)})),[il,ll]);const Ml=o.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),ta=o.useRef(null),cn=o.useRef(null),[$l,wo]=o.useState(!1);o.useEffect(()=>{if(!t)return;wo(!1);let r=!1;mh().then(f=>{r||(ta.current=f.text,Ft(b=>f.text&&f.text!==b?f.text:b),wo(!0))}).catch(()=>{r||wo(!0)});const i=Lc(f=>{f.type==="context-draft"&&f.origin!==Ml.current&&(ta.current=f.text,Ft(f.text))});return()=>{r=!0,i(),cn.current!==null&&(window.clearTimeout(cn.current),cn.current=null)}},[t]),o.useEffect(()=>{if(!$l||ta.current===vt)return;cn.current!==null&&window.clearTimeout(cn.current);const r=vt;cn.current=window.setTimeout(()=>{cn.current=null,ph(r,Ml.current).then(()=>{ta.current=r}).catch(()=>{})},500)},[vt,$l]);const Dn=o.useCallback((r,i,f)=>{if(r){if(gh(f?r+f:r)){yo(i);return}Ke?(Ft(b=>Km(b,r)+(f??"")),window.matchMedia("(pointer: coarse)").matches||(ir(!1),lr(b=>b+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:f?r+f:r,focus:!0}})),yo(i)}},[Ke,yo]),ra=o.useCallback(r=>{const i=ka(r,v);return Dh(i,v)},[v]),ko=Ad(Sr),Ur=o.useCallback((r,i)=>{const f=ka(r,v);Dn(Fh(f,v),i??`path:${f}`)},[v,Dn]),rf=o.useCallback(async r=>{Us(!0);try{await Bh(r,Ho,i=>{Ur(i,`path:${i}`)}),ee&&!Ke&&s()}catch(i){lt(i instanceof Error?i.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>lt(null),4e3)}finally{Us(!1)}},[Ke,Ur,ee,s,a]),jr=o.useCallback((r,i)=>{if(!r)return;const f=r.includes(`
|
|
1660
1660
|
`)?`
|
|
1661
1661
|
`:void 0;Dn(r.endsWith(`
|
|
1662
|
-
`)||r.endsWith(" ")?r:`${r} `,i,f)},[Dn]),El=o.useRef(jr);El.current=jr;const
|
|
1663
|
-
`)},[Dn]),Al=o.useCallback(r=>{const i=
|
|
1664
|
-
`),b=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let x=!1;const C=q=>{x||(x=!0,window.removeEventListener("termdock-insert-reference-ack",I),window.clearTimeout(O),q?(Ot(!1),Ft(""),Gt&&ir(!0)):(Ot(!0),ir(!1)))},I=q=>{const Ne=q.detail;Ne?.nonce===b&&C(Ne.ok===!0)},O=window.setTimeout(()=>C(!1),1500);window.addEventListener("termdock-insert-reference-ack",I),Ot(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:i,focus:!0,paste:f,nonce:b}}))},[Gt,vt]),Ye=o.useMemo(()=>v?ut(v):a("rightSidebar.workspace"),[v,a]),nf=o.useMemo(()=>ut(ge)||Ye,[ge,Ye]),na=o.useMemo(()=>
|
|
1665
|
-
`)},[Bl,_n,ge,v,Ge]),un=o.useRef(new Map);o.useEffect(()=>{const r=
|
|
1666
|
-
`):[];if(!t||r.length===0){Nn(null);return}const i=new AbortController;let f=!1,b=0,x=0;Nn(null);const C=async()=>{let I=0;for(;!f&&!i.signal.aborted;){let O=null;try{Nn(null),await Rh(r,Ne=>{const{applicableEvents:Xe,unavailableReason:Be}=Om(Ne);Xe.length>0&&cl(Xe);for(const ae of Xe){if(ae.type!=="rescan-required")continue;const Oe=oe.getState();if(!Oe.directoryCache.has(ae.path))continue;un.current.get(ae.path)?.abort();const Et=new AbortController;un.current.set(ae.path,Et);const jc=`file-watch-rescan:${ae.path}`;Ct(jc),Ch(ae.path,Et.signal,Oe.showHiddenFiles,"watch_rescan",jc,Oe.fileSortModes[ae.path]??"name").then(ds=>{un.current.get(ae.path)===Et&&dl(ae.path,ds.entries)}).catch(ds=>{or(ds)||Nn(ds instanceof Error?ds.message:"File refresh unavailable")}).finally(()=>{un.current.get(ae.path)===Et&&un.current.delete(ae.path)})}Be&&Nn(Be)},i.signal),O=new Error("File watch stream ended")}catch(Ne){O=Ne}if(f||i.signal.aborted||or(O))return;Nn(O instanceof Error?O.message:"File watching unavailable");const q=Xc[Math.min(I,Xc.length-1)];I+=1,await new Promise(Ne=>{x=window.setTimeout(Ne,q)})}};return b=window.setTimeout(()=>{f||C()},Vo),()=>{f=!0,window.clearTimeout(b),window.clearTimeout(x),i.abort();for(const I of un.current.values())I.abort();un.current.clear()}},[cl,t,dl,Ro]),o.useEffect(()=>{if(!v||go.current!==v)return;if(bo.current===v){bo.current=null;return}const r=rd();vs(Kd,{...r,[v]:{selectedRepoRoots:Ts,repoTargetBranches:gr,repoBaseBranches:St,previewEntries:Xr,selectedPreviewKey:Me&&mr?Ve:null,selectedPreviewFileKey:Me&&mr?Za:null,previewDetailOpen:!!(Me&&mr),previewScrollTops:yn,previewMobileSlideIndex:1,includeUncommitted:Pr,updatedAt:Date.now()}},Mp)},[mr,Pr,Me,Xr,yn,St,gr,Ts,v,Za,Ve]);const rt=o.useMemo(()=>pd(ye.values()),[ye]),ht=o.useMemo(()=>{const r=new Map;for(const i of X)r.set(i.root,i);return r},[X]),jt=o.useMemo(()=>ue?xe.find(r=>r.root===ue)??null:null,[ue,xe]),sr=o.useMemo(()=>Ge?Array.from(ye.values()).find(r=>r.path===Ge||r.absolutePath===Ge)??null:null,[ye,Ge]),mt=o.useMemo(()=>{const r=new Map;for(const i of X)i.available&&i.context?.available&&r.set(i.root,i);return r.size===0&&ne?.available&&ne.root&&r.set(ne.root,{id:ne.root,root:ne.root,relativeRoot:".",name:Ye,depth:0,nested:!1,available:!0,files:Array.from(ye.values()).filter(i=>pt(i,v)===ne.root),context:ne}),Array.from(r.values()).sort((i,f)=>i.root===v?-1:f.root===v?1:(i.relativeRoot||i.name).localeCompare(f.relativeRoot||f.name)).map(i=>{const f=i.relativeRoot==="."?Ye:i.relativeRoot||i.name||ut(i.root),b=md(i.files),x=i.files.length;return{value:i.root,label:f,meta:[i.context?.branch,x>0?a("rightSidebar.repoChangedCount",{count:x}):null,b>0?a("rightSidebar.repoStagedCount",{count:b}):null].filter(Boolean).join(" · ")}})},[ye,ne,X,Ye,v,a]),we=o.useMemo(()=>ue&&mt.some(r=>r.value===ue)?ue:sr?.repoRoot&&mt.some(r=>r.value===sr.repoRoot)?sr.repoRoot:mt.length===1||mt.length>1?mt[0].value:null,[ue,mt,sr?.repoRoot]),Ol=we?ht.get(we)??null:null,fe=Ol?.context?.available?Ol.context:we===ne?.root?ne:null,He=mt.length>0&&!we,Ul=o.useMemo(()=>He?[]:we?Array.from(ye.values()).filter(r=>pt(r,v)===we):Array.from(ye.values()),[we,ye,He,v]),fn=o.useMemo(()=>pd(Ul),[Ul]),Co=!!(fe?.available&&fe.root&&we&&fe.root===we),cf=we?mt.find(r=>r.value===we)?.label??ut(we):a("rightSidebar.gitRepositoryPlaceholder"),df=Co?fe?.branch??"HEAD":He?a("rightSidebar.selectRepositoryForGitActions"):tn?a("rightSidebar.gitActionRunning"):"HEAD",Fn=!!(fe?.available&&fe.root===we&&fe.status);o.useEffect(()=>{Hi.current={count:Jt.length,loading:Sn,loadingMore:Q,hasMore:Xa}},[Jt.length,Xa,Sn,Q]),o.useEffect(()=>{Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1)},[we]);const cs=o.useCallback(async(r={})=>{if(!v||!we||He)return;const i=r.reset??!1,f=Hi.current,b=i?0:f.count;if(!i&&(f.loading||f.loadingMore||!f.hasMore))return;const x=Ar.current+1;Ar.current=x,tr.current?.abort(),Ct("right-sidebar-recent-commits");const C=new AbortController;tr.current=C,i?Qr(!0):_e(!0),er(null);try{const I=await gh({cwd:v,repoRoot:we,limit:Fp,skip:b,query:Xn.trim(),requestSlotId:"right-sidebar-recent-commits"},C.signal);if(Ar.current!==x)return;if(!I.available){er(I.error??"Recent commits are unavailable"),i&&Qt([]),jn(!1);return}Qt(O=>i?I.commits:[...O,...I.commits]),jn(I.hasMore)}catch(I){if(Ar.current!==x||or(I))return;er(I instanceof Error?I.message:"Failed to load recent commits"),i&&Qt([]),jn(!1)}finally{tr.current===C&&(tr.current=null),Ar.current===x&&(Qr(!1),_e(!1))}},[we,Xn,He,v]);o.useEffect(()=>{Xt&&cs({reset:!0})},[Xn,cs,Xt]);const uf=o.useCallback(r=>{const i=r.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||cs({reset:!1})},[cs]);o.useEffect(()=>{!we||!ne?.available||!We||!rr||Fn||tn||He||vo(we)},[we,ne?.available,Fn,tn,We,rr,vo,He]),o.useEffect(()=>{!t||!ct&&!We||!v||nr()},[ct,We,t,nr,v]),o.useEffect(()=>{!t||!We||!rr||!Jn||!v||Qs(null)},[Jn,We,rr,t,Qs,v]);const ff=o.useMemo(()=>{if(!ue)return 0;const r=xe.findIndex(i=>i.root===ue);return r>=0?r+1:0},[ue,xe]),Hl=o.useCallback(r=>{if(!r)return null;const i=Array.from(ye.values()).filter(f=>pt(f,v)===r).sort((f,b)=>f.path.localeCompare(b.path))[0];return i?dt(i):null},[ye,v]),hn=xe.length>1,aa=o.useMemo(()=>[{root:null,label:a("rightSidebar.allRepositories"),count:ye.size,branch:null},...xe.map(r=>({root:r.root,label:r.label,count:r.count,branch:r.branch??null}))],[ye.size,xe,a]),zl=aa[ff]??aa[0],oa=!!ue;o.useEffect(()=>{ue&&!mt.some(r=>r.value===ue)&&(qe(null),Yo(v,null)),Yr(r=>r.filter(i=>xe.some(f=>f.root===i)))},[ue,mt,xe,v]);const hf=o.useMemo(()=>{const r=new Set;fe?.branch&&r.add(fe.branch);for(const i of fe?.branches??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0}))},[fe?.branch,fe?.branches,a]),Wl=o.useMemo(()=>{const r=new Set;fe?.upstreamRemote&&r.add(fe.upstreamRemote);for(const i of fe?.remotes??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===fe?.upstreamRemote?a("rightSidebar.pushUpstreamBadge"):void 0}))},[fe?.remotes,fe?.upstreamRemote,a]),Gl=Wl.length>1,mf=o.useMemo(()=>{const r=[],i=new Set,f=(x,C)=>{!x||i.has(x)||(i.add(x),r.push({value:x,label:x,meta:C}))};f(fe?.upstreamBranch,fe?.upstreamBranch?a("rightSidebar.pushUpstreamBadge"):void 0),f(fe?.branch,fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0);for(const x of fe?.branches??[])f(x,x===fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");const b=fe?.upstreamRemote;for(const x of fe?.remoteBranches??[]){const C=x.indexOf("/"),I=C>=0?x.slice(0,C):null,O=C>=0?x.slice(C+1):x;(!b||I===b)&&f(O,"remote")}return r},[fe?.branch,fe?.branches,fe?.remoteBranches,fe?.upstreamBranch,fe?.upstreamRemote,a]),It=o.useMemo(()=>mt.map(r=>{const i=ht.get(r.value);return{root:r.value,label:r.label,branch:i?.context?.branch??null}}),[mt,ht]);o.useEffect(()=>{It.length!==0&&(Is(r=>{let i=!1;const f={...r},b=new Set(It.map(x=>x.root));for(const x of Object.keys(f))b.has(x)||(delete f[x],i=!0);for(const x of It)!f[x.root]&&x.branch&&(f[x.root]=x.branch,i=!0);return i?f:r}),_s(r=>{let i=!1;const f={...r},b=new Set(It.map(x=>x.root));for(const x of Object.keys(f))b.has(x)||(delete f[x],i=!0);for(const x of It){const C=ht.get(x.root)?.context;if(f[x.root]&&ru(f[x.root],C?.branch)&&(delete f[x.root],i=!0),f[x.root])continue;const I=ad(C);I&&(f[x.root]=I,i=!0)}return i?f:r}))},[It,ht]);const ia=o.useMemo(()=>{const r=new Set(It.map(i=>i.root));return Ts.filter(i=>r.has(i))},[Ts,It]),la=ia.length===0,ar=o.useMemo(()=>la?It:It.filter(r=>ia.includes(r.root)),[It,ia,la]),Wt=o.useMemo(()=>ar.filter(r=>!!St[r.root]?.trim()),[St,ar]),ql=o.useMemo(()=>ar.filter(r=>!St[r.root]?.trim()),[St,ar]),Kl=o.useCallback(async r=>{if(!r||po.current.has(r))return;const i=ht.get(r)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const f=v;po.current.add(r),Ki(b=>new Set(b).add(r));try{const b=await Mc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!b.available||!Ce(f))return;ke(x=>x.map(C=>C.root===r?{...C,available:!0,context:{...C.context,...b},error:void 0}:C)),Is(x=>x[r]||!b.branch?x:{...x,[r]:b.branch}),_s(x=>{if(x[r])return x;const C=ad(b);return C?{...x,[r]:C}:x})}catch(b){or(b)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,b)}finally{po.current.delete(r),Ki(b=>{const x=new Set(b);return x.delete(r),x})}},[ht,Ce,v]);o.useEffect(()=>{if(Ja)for(const r of ar)Kl(r.root)},[Ja,ar,Kl]),o.useEffect(()=>{!Co||!fe||(so(fe.branch||(fe.branches?.[0]??"")),ao(fe.upstreamRemote||(fe.remotes?.includes("origin")?"origin":fe.remotes?.[0]??"")),oo(fe.upstreamBranch||fe.branch||(fe.branches?.[0]??"")))},[fe,Co]);const Vl=o.useMemo(()=>{if(He)return{text:a("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Fn||tn)return{text:a("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!fe?.upstream)return{text:a("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=fe.ahead??0,i=fe.behind??0;return r>0&&i>0?{text:a("rightSidebar.pushDivergedCount",{ahead:r,behind:i}),className:"bg-destructive/10 text-destructive"}:r>0?{text:a("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:i>0?{text:a("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:a("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[fe?.ahead,fe?.behind,fe?.upstream,Fn,tn,He,a]),pf=o.useCallback(r=>{if(r&&!ee){const i=r.currentTarget.getBoundingClientRect();W({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else W(null);E?.()},[ee,E]),No=o.useCallback(()=>{W(null),T?.()},[T]);function Yl(){if(!hn)return null;const r=zl?.label??a("rightSidebar.allRepositories"),i=zl?.count??ye.size,f=ut(r)||r;return e.jsxs("button",{type:"button",onClick:pf,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${w?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":w,title:r,children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:f}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(Ss,{size:12,className:"shrink-0"})]})}function gf(){if(!w||!hn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,f=Math.max(12,Math.min(Le?.x??r-368,r-352)),b=Math.max(12,Math.min(Le?.y??80,i-420)),x=ee?void 0:{left:f,top:b},C=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:No,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:x,onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:a("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:aa.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${ye.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:ye.size})]})]}),e.jsx("button",{type:"button",onClick:No,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.close"),children:e.jsx(Dt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:aa.map(I=>{const O=(I.root??null)===ue,q=ut(I.label)||I.label;return e.jsxs("button",{type:"button",onClick:()=>{pc(I.root),No()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${O?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:I.label,role:"option","aria-selected":O,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${O?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${O?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Rr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:q}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:I.root===null?a("rightSidebar.allRepositories"):I.label})]}),I.branch&&e.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:I.branch}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${I.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:I.count})]},I.root??"all")})})]})});return Ud(C,ee,document.body)}function bf(){return gf()}function Xl(r){const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path),b=_a(f,i??v);return{key:dt(r),path:r.path,absolutePath:f,displayName:b.name,displayDir:b.dir,oldPath:r.oldPath,status:r.status,title:f}}function Jl(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:a("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function Ql(r,i){const f=ka(r,v),b=`path:${f}`,x=K===b,C=Re===b,I=x||C;return e.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),Ur(f,b)},...wo(ra(f),b),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${I?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${I?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:a(C?"rightSidebar.copied":x?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Zl(r){const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path),b=zf(r),x=ai(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Hg,{actions:b,running:Ae,completed:Rn?.path===x?Rn:null}),Ql(f,a("rightSidebar.insertThisFile"))]})}function ec(r,i){const f=i.root??v;if(!f)return null;const b=ka(r,f);return Ql(b,a("fileTree.insertRefTitle"))}function Mo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":a("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>cc("unified"),"aria-pressed":Kt==="unified",title:a("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Kt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>cc("split"),"aria-pressed":Kt==="split",title:a("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Kt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.split")})]})}function tc(){return da.map(r=>{const i=md(r.files.map(([,C])=>C)),f=!ue&&(da.length>1||r.label!==Ye),b=!!(r.root&&Ut.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:b,files:r.files.map(([,C])=>Xl(C)),header:f?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${b?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>_f(r.root),"aria-expanded":!b,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:b?e.jsx(wa,{size:13}):e.jsx(Ss,{size:13})}),e.jsx(Rr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),ba("stage-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),ba("stash-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]})]}):null}})}function rc(){return ye.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:a("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ua.map(([,r])=>{const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path);return{key:dt(r),path:r.path,absolutePath:f,status:r.status,repoRoot:i,displayName:_a(f,i).name,displayDir:_a(f,i).dir,auditRecords:kt}})}function nc(r){const i=Array.from(ye.values()).find(x=>dt(x)===r.key),f=i?pt(i,v):null,b=Nm(kt,f,i?.path??r.path);return e.jsx(gi,{changeStatus:r.status,auditStatus:b,renderChangeBadge:x=>e.jsx(ys,{status:x})})}const ca=o.useCallback(r=>{if(ee)return null;const i=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const b=r.getBoundingClientRect().top+48;let x=null,C=Number.POSITIVE_INFINITY;for(const O of i){const q=O.getBoundingClientRect();if(q.bottom<b)continue;const Ne=Math.abs(q.top-b);Ne<C&&(x=O,C=Ne)}const I=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;return I?(Ys.current===I&&oe.getState().selectedFilePath===I||(Ys.current=I,Qe(I)),I):null},[ee,Qe]),xf=!!(!Ae&&we&&!He&&(fe?.upstream||rn.trim()&&nn.trim())),vf=!!(!Ae&&we&&!He&&(fe?.upstream||rn.trim()&&nn.trim())),yf=!!(!Ae&&we&&!He&&es.trim()&&es.trim()!==fe?.branch),_t=o.useMemo(()=>{const r=ce.trim().toLowerCase(),i=Array.from(ye.entries()).filter(([,f])=>!ue||pt(f,v)===ue).sort(([f],[b])=>f.localeCompare(b));return r?i.filter(([f,b])=>`${f} ${b.path} ${b.status} ${b.repoRelativeRoot??""} ${b.repoName??""}`.toLowerCase().includes(r)):i},[ue,ye,ce,v]);o.useEffect(()=>{Aa("selected_file_state",{selectedFilePath:Ge,selectedChangedFilePath:sr?.path??null,selectedChangedFileAbsolutePath:sr?.absolutePath??null,selectedChangedFileRepoRoot:sr?.repoRoot??null,rootPath:v,activeGitRepoRoot:ue,rightTab:uo,effectiveRightTab:kr,diffPaneActive:ct,changedFiles:ye.size,filteredChangedFiles:_t.length,gitBundleLoading:Nt,gitBundleLastLoadedAt:Ir})},[ue,ye.size,ct,kr,_t.length,Ir,Nt,uo,v,sr?.absolutePath,sr?.path,sr?.repoRoot,Ge]);const da=o.useMemo(()=>{const r=new Map;for(const i of _t){const[,f]=i,b=pt(f,v),x=Og(f)||Ye,C=b??x,I=b?ht.get(b):void 0,O=r.get(C)??{root:b,label:x,branch:I?.context?.branch,files:[]};O.files.push(i),r.set(C,O)}return Array.from(r.values()).sort((i,f)=>i.label===Ye?-1:f.label===Ye?1:i.label.localeCompare(f.label))},[_t,ht,Ye,v]),ua=o.useMemo(()=>{const r=[],i=new Map;for(const f of _t)i.set(dt(f[1]),f);for(const f of da){if(f.root&&Ut.has(f.root))continue;if(wt!=="tree"){r.push(...f.files);continue}const b=f.files.map(([,x])=>Xl(x));for(const x of qh(b)){const C=i.get(x.key);C&&r.push(C)}}return r},[Ut,wt,da,_t]);o.useEffect(()=>{if(!ct||ua.length===0||ee)return;const r=[],i=()=>{const f=document.querySelector(".termdock-diff-stream-scroller");if(f&&ca(f))return;const b=document.querySelector("[data-diff-stream-item]"),x=b?.dataset.diffSelectionPath??b?.dataset.diffStreamItem??null;if(x){Ys.current=x,Qe(x);return}const C=ua[0]?.[1];if(!C)return;const I=dt(C);Ys.current=I,Qe(I)};for(const f of[80,240,600,1200])r.push(window.setTimeout(i,f));return()=>r.forEach(f=>window.clearTimeout(f))},[ct,ee,ua,Qe,ca]);const $o=o.useMemo(()=>{const r=I=>`'${I.replace(/'/g,"'\\''")}'`,i=zt.length>0?ln:X.filter(I=>I.files.length>0),f=i.length>0?i:v?[{root:v,relativeRoot:".",name:Ye}]:[],b=f.length>0?f.map(I=>`- ${I.relativeRoot==="."?".":I.relativeRoot} (${I.root})`).join(`
|
|
1662
|
+
`)||r.endsWith(" ")?r:`${r} `,i,f)},[Dn]),El=o.useRef(jr);El.current=jr;const So=o.useRef(!0);o.useEffect(()=>(So.current=!0,()=>{So.current=!1}),[]);const jo=o.useRef(new Set),Ll=o.useCallback((r,i,f)=>{if(jo.current.has(i))return;const b=Dc.getState().activeSessionId;jo.current.add(i),Rm(r,i,f,{insert:jr,upload:async(x,C)=>(await Ho("/tmp",[x],C)).files[0]?.path,isCurrent:()=>So.current&&El.current===jr&&b===Dc.getState().activeSessionId}).finally(()=>jo.current.delete(i))},[jr]),Hr=o.useCallback((r,i,f)=>{i&&Dn(i.endsWith(" ")?i:`${i} `,f??`context:${r}`,`
|
|
1663
|
+
`)},[Dn]),Al=o.useCallback(r=>{const i=Vm(vt,r);if(!i)return;const f=r&&vt.trim().includes(`
|
|
1664
|
+
`),b=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let x=!1;const C=q=>{x||(x=!0,window.removeEventListener("termdock-insert-reference-ack",I),window.clearTimeout(O),q?(Ot(!1),Ft(""),Gt&&ir(!0)):(Ot(!0),ir(!1)))},I=q=>{const Ne=q.detail;Ne?.nonce===b&&C(Ne.ok===!0)},O=window.setTimeout(()=>C(!1),1500);window.addEventListener("termdock-insert-reference-ack",I),Ot(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:i,focus:!0,paste:f,nonce:b}}))},[Gt,vt]),Ye=o.useMemo(()=>v?ut(v):a("rightSidebar.workspace"),[v,a]),nf=o.useMemo(()=>ut(ge)||Ye,[ge,Ye]),na=o.useMemo(()=>ni(ge),[ge]),sa=o.useMemo(()=>v?ol[v]??[]:[],[ol,v]),dn=o.useMemo(()=>new Set(sa.map(r=>r.path)),[sa]),ls=!!(ge&&dn.has(ge)),Ro=!!(v&&ge&&ge!==v),sf=!!(v&&Mn&&Mn!==v),$t=ge?`path:${ge}`:null,Pl="context:change-audit",af=o.useCallback(()=>{na&&Tt(na)},[na,Tt]),Tl=o.useCallback(()=>{cl()},[cl]),of=o.useCallback(()=>{ge&&(Ws(ge,!0),fl())},[fl,ge,Ws]),lf=o.useCallback(()=>{!ge||!Ro||(ls?an(ge):$n(ge,"directory"))},[Ro,ge,ls,$n,an]),Il=o.useCallback(r=>{Tt(r),j("")},[Tt]),_l=o.useCallback(r=>{ge&&(te(Mp(ge,r)),he(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ge,he]),Dl=o.useCallback(r=>{!v||r===v||(dn.has(r)?an(r):$n(r,"directory"))},[$n,dn,v,an]),Fl=o.useCallback(r=>{!v||!r||(dn.has(r)?an(r):$n(r,"file"))},[$n,dn,v,an]),Bl=oe(r=>r.expandedPaths),Co=o.useMemo(()=>{const r=new Set;if(_n&&ge){r.add(ge);const i=`${ge.replace(/\/+$/,"")}/`;for(const f of Bl)f.startsWith(i)&&r.add(f)}if(_n&&v&&Ge){const i=Ge.startsWith("/")?Ge:`${v}/${Ge}`,f=ni(i);f&&r.add(f)}return Bm(r).join(`
|
|
1665
|
+
`)},[Bl,_n,ge,v,Ge]),un=o.useRef(new Map);o.useEffect(()=>{const r=Co?Co.split(`
|
|
1666
|
+
`):[];if(!t||r.length===0){Nn(null);return}const i=new AbortController;let f=!1,b=0,x=0;Nn(null);const C=async()=>{let I=0;for(;!f&&!i.signal.aborted;){let O=null;try{Nn(null),await Ch(r,Ne=>{const{applicableEvents:Xe,unavailableReason:Be}=Um(Ne);Xe.length>0&&dl(Xe);for(const ae of Xe){if(ae.type!=="rescan-required")continue;const Oe=oe.getState();if(!Oe.directoryCache.has(ae.path))continue;un.current.get(ae.path)?.abort();const Et=new AbortController;un.current.set(ae.path,Et);const jc=`file-watch-rescan:${ae.path}`;Ct(jc),Nh(ae.path,Et.signal,Oe.showHiddenFiles,"watch_rescan",jc,Oe.fileSortModes[ae.path]??"name").then(ds=>{un.current.get(ae.path)===Et&&ul(ae.path,ds.entries)}).catch(ds=>{or(ds)||Nn(ds instanceof Error?ds.message:"File refresh unavailable")}).finally(()=>{un.current.get(ae.path)===Et&&un.current.delete(ae.path)})}Be&&Nn(Be)},i.signal),O=new Error("File watch stream ended")}catch(Ne){O=Ne}if(f||i.signal.aborted||or(O))return;Nn(O instanceof Error?O.message:"File watching unavailable");const q=Xc[Math.min(I,Xc.length-1)];I+=1,await new Promise(Ne=>{x=window.setTimeout(Ne,q)})}};return b=window.setTimeout(()=>{f||C()},Yo),()=>{f=!0,window.clearTimeout(b),window.clearTimeout(x),i.abort();for(const I of un.current.values())I.abort();un.current.clear()}},[dl,t,ul,Co]),o.useEffect(()=>{if(!v||go.current!==v)return;if(bo.current===v){bo.current=null;return}const r=rd();vs(Kd,{...r,[v]:{selectedRepoRoots:Ts,repoTargetBranches:gr,repoBaseBranches:St,previewEntries:Xr,selectedPreviewKey:Me&&mr?Ve:null,selectedPreviewFileKey:Me&&mr?Za:null,previewDetailOpen:!!(Me&&mr),previewScrollTops:yn,previewMobileSlideIndex:1,includeUncommitted:Pr,updatedAt:Date.now()}},$p)},[mr,Pr,Me,Xr,yn,St,gr,Ts,v,Za,Ve]);const rt=o.useMemo(()=>pd(ye.values()),[ye]),ht=o.useMemo(()=>{const r=new Map;for(const i of X)r.set(i.root,i);return r},[X]),jt=o.useMemo(()=>ue?xe.find(r=>r.root===ue)??null:null,[ue,xe]),sr=o.useMemo(()=>Ge?Array.from(ye.values()).find(r=>r.path===Ge||r.absolutePath===Ge)??null:null,[ye,Ge]),mt=o.useMemo(()=>{const r=new Map;for(const i of X)i.available&&i.context?.available&&r.set(i.root,i);return r.size===0&&ne?.available&&ne.root&&r.set(ne.root,{id:ne.root,root:ne.root,relativeRoot:".",name:Ye,depth:0,nested:!1,available:!0,files:Array.from(ye.values()).filter(i=>pt(i,v)===ne.root),context:ne}),Array.from(r.values()).sort((i,f)=>i.root===v?-1:f.root===v?1:(i.relativeRoot||i.name).localeCompare(f.relativeRoot||f.name)).map(i=>{const f=i.relativeRoot==="."?Ye:i.relativeRoot||i.name||ut(i.root),b=md(i.files),x=i.files.length;return{value:i.root,label:f,meta:[i.context?.branch,x>0?a("rightSidebar.repoChangedCount",{count:x}):null,b>0?a("rightSidebar.repoStagedCount",{count:b}):null].filter(Boolean).join(" · ")}})},[ye,ne,X,Ye,v,a]),we=o.useMemo(()=>ue&&mt.some(r=>r.value===ue)?ue:sr?.repoRoot&&mt.some(r=>r.value===sr.repoRoot)?sr.repoRoot:mt.length===1||mt.length>1?mt[0].value:null,[ue,mt,sr?.repoRoot]),Ol=we?ht.get(we)??null:null,fe=Ol?.context?.available?Ol.context:we===ne?.root?ne:null,He=mt.length>0&&!we,Ul=o.useMemo(()=>He?[]:we?Array.from(ye.values()).filter(r=>pt(r,v)===we):Array.from(ye.values()),[we,ye,He,v]),fn=o.useMemo(()=>pd(Ul),[Ul]),No=!!(fe?.available&&fe.root&&we&&fe.root===we),cf=we?mt.find(r=>r.value===we)?.label??ut(we):a("rightSidebar.gitRepositoryPlaceholder"),df=No?fe?.branch??"HEAD":He?a("rightSidebar.selectRepositoryForGitActions"):tn?a("rightSidebar.gitActionRunning"):"HEAD",Fn=!!(fe?.available&&fe.root===we&&fe.status);o.useEffect(()=>{zi.current={count:Jt.length,loading:Sn,loadingMore:Q,hasMore:Xa}},[Jt.length,Xa,Sn,Q]),o.useEffect(()=>{Ar.current+=1,tr.current?.abort(),Ct("right-sidebar-recent-commits"),tr.current=null,Jr(""),Qt([]),Qr(!1),_e(!1),er(null),jn(!1)},[we]);const cs=o.useCallback(async(r={})=>{if(!v||!we||He)return;const i=r.reset??!1,f=zi.current,b=i?0:f.count;if(!i&&(f.loading||f.loadingMore||!f.hasMore))return;const x=Ar.current+1;Ar.current=x,tr.current?.abort(),Ct("right-sidebar-recent-commits");const C=new AbortController;tr.current=C,i?Qr(!0):_e(!0),er(null);try{const I=await bh({cwd:v,repoRoot:we,limit:Bp,skip:b,query:Xn.trim(),requestSlotId:"right-sidebar-recent-commits"},C.signal);if(Ar.current!==x)return;if(!I.available){er(I.error??"Recent commits are unavailable"),i&&Qt([]),jn(!1);return}Qt(O=>i?I.commits:[...O,...I.commits]),jn(I.hasMore)}catch(I){if(Ar.current!==x||or(I))return;er(I instanceof Error?I.message:"Failed to load recent commits"),i&&Qt([]),jn(!1)}finally{tr.current===C&&(tr.current=null),Ar.current===x&&(Qr(!1),_e(!1))}},[we,Xn,He,v]);o.useEffect(()=>{Xt&&cs({reset:!0})},[Xn,cs,Xt]);const uf=o.useCallback(r=>{const i=r.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||cs({reset:!1})},[cs]);o.useEffect(()=>{!we||!ne?.available||!We||!rr||Fn||tn||He||vo(we)},[we,ne?.available,Fn,tn,We,rr,vo,He]),o.useEffect(()=>{!t||!ct&&!We||!v||nr()},[ct,We,t,nr,v]),o.useEffect(()=>{!t||!We||!rr||!Jn||!v||Qs(null)},[Jn,We,rr,t,Qs,v]);const ff=o.useMemo(()=>{if(!ue)return 0;const r=xe.findIndex(i=>i.root===ue);return r>=0?r+1:0},[ue,xe]),Hl=o.useCallback(r=>{if(!r)return null;const i=Array.from(ye.values()).filter(f=>pt(f,v)===r).sort((f,b)=>f.path.localeCompare(b.path))[0];return i?dt(i):null},[ye,v]),hn=xe.length>1,aa=o.useMemo(()=>[{root:null,label:a("rightSidebar.allRepositories"),count:ye.size,branch:null},...xe.map(r=>({root:r.root,label:r.label,count:r.count,branch:r.branch??null}))],[ye.size,xe,a]),zl=aa[ff]??aa[0],oa=!!ue;o.useEffect(()=>{ue&&!mt.some(r=>r.value===ue)&&(qe(null),Xo(v,null)),Yr(r=>r.filter(i=>xe.some(f=>f.root===i)))},[ue,mt,xe,v]);const hf=o.useMemo(()=>{const r=new Set;fe?.branch&&r.add(fe.branch);for(const i of fe?.branches??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0}))},[fe?.branch,fe?.branches,a]),Wl=o.useMemo(()=>{const r=new Set;fe?.upstreamRemote&&r.add(fe.upstreamRemote);for(const i of fe?.remotes??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===fe?.upstreamRemote?a("rightSidebar.pushUpstreamBadge"):void 0}))},[fe?.remotes,fe?.upstreamRemote,a]),Gl=Wl.length>1,mf=o.useMemo(()=>{const r=[],i=new Set,f=(x,C)=>{!x||i.has(x)||(i.add(x),r.push({value:x,label:x,meta:C}))};f(fe?.upstreamBranch,fe?.upstreamBranch?a("rightSidebar.pushUpstreamBadge"):void 0),f(fe?.branch,fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0);for(const x of fe?.branches??[])f(x,x===fe?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");const b=fe?.upstreamRemote;for(const x of fe?.remoteBranches??[]){const C=x.indexOf("/"),I=C>=0?x.slice(0,C):null,O=C>=0?x.slice(C+1):x;(!b||I===b)&&f(O,"remote")}return r},[fe?.branch,fe?.branches,fe?.remoteBranches,fe?.upstreamBranch,fe?.upstreamRemote,a]),It=o.useMemo(()=>mt.map(r=>{const i=ht.get(r.value);return{root:r.value,label:r.label,branch:i?.context?.branch??null}}),[mt,ht]);o.useEffect(()=>{It.length!==0&&(Is(r=>{let i=!1;const f={...r},b=new Set(It.map(x=>x.root));for(const x of Object.keys(f))b.has(x)||(delete f[x],i=!0);for(const x of It)!f[x.root]&&x.branch&&(f[x.root]=x.branch,i=!0);return i?f:r}),_s(r=>{let i=!1;const f={...r},b=new Set(It.map(x=>x.root));for(const x of Object.keys(f))b.has(x)||(delete f[x],i=!0);for(const x of It){const C=ht.get(x.root)?.context;if(f[x.root]&&ru(f[x.root],C?.branch)&&(delete f[x.root],i=!0),f[x.root])continue;const I=ad(C);I&&(f[x.root]=I,i=!0)}return i?f:r}))},[It,ht]);const ia=o.useMemo(()=>{const r=new Set(It.map(i=>i.root));return Ts.filter(i=>r.has(i))},[Ts,It]),la=ia.length===0,ar=o.useMemo(()=>la?It:It.filter(r=>ia.includes(r.root)),[It,ia,la]),Wt=o.useMemo(()=>ar.filter(r=>!!St[r.root]?.trim()),[St,ar]),ql=o.useMemo(()=>ar.filter(r=>!St[r.root]?.trim()),[St,ar]),Kl=o.useCallback(async r=>{if(!r||po.current.has(r))return;const i=ht.get(r)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const f=v;po.current.add(r),Vi(b=>new Set(b).add(r));try{const b=await Mc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!b.available||!Ce(f))return;ke(x=>x.map(C=>C.root===r?{...C,available:!0,context:{...C.context,...b},error:void 0}:C)),Is(x=>x[r]||!b.branch?x:{...x,[r]:b.branch}),_s(x=>{if(x[r])return x;const C=ad(b);return C?{...x,[r]:C}:x})}catch(b){or(b)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,b)}finally{po.current.delete(r),Vi(b=>{const x=new Set(b);return x.delete(r),x})}},[ht,Ce,v]);o.useEffect(()=>{if(Ja)for(const r of ar)Kl(r.root)},[Ja,ar,Kl]),o.useEffect(()=>{!No||!fe||(so(fe.branch||(fe.branches?.[0]??"")),ao(fe.upstreamRemote||(fe.remotes?.includes("origin")?"origin":fe.remotes?.[0]??"")),oo(fe.upstreamBranch||fe.branch||(fe.branches?.[0]??"")))},[fe,No]);const Vl=o.useMemo(()=>{if(He)return{text:a("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Fn||tn)return{text:a("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!fe?.upstream)return{text:a("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=fe.ahead??0,i=fe.behind??0;return r>0&&i>0?{text:a("rightSidebar.pushDivergedCount",{ahead:r,behind:i}),className:"bg-destructive/10 text-destructive"}:r>0?{text:a("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:i>0?{text:a("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:a("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[fe?.ahead,fe?.behind,fe?.upstream,Fn,tn,He,a]),pf=o.useCallback(r=>{if(r&&!ee){const i=r.currentTarget.getBoundingClientRect();W({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else W(null);E?.()},[ee,E]),Mo=o.useCallback(()=>{W(null),T?.()},[T]);function Yl(){if(!hn)return null;const r=zl?.label??a("rightSidebar.allRepositories"),i=zl?.count??ye.size,f=ut(r)||r;return e.jsxs("button",{type:"button",onClick:pf,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${w?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":w,title:r,children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:f}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(Ss,{size:12,className:"shrink-0"})]})}function gf(){if(!w||!hn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,f=Math.max(12,Math.min(Le?.x??r-368,r-352)),b=Math.max(12,Math.min(Le?.y??80,i-420)),x=ee?void 0:{left:f,top:b},C=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Mo,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:x,onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:a("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:aa.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${ye.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:ye.size})]})]}),e.jsx("button",{type:"button",onClick:Mo,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.close"),children:e.jsx(Dt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:aa.map(I=>{const O=(I.root??null)===ue,q=ut(I.label)||I.label;return e.jsxs("button",{type:"button",onClick:()=>{pc(I.root),Mo()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${O?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:I.label,role:"option","aria-selected":O,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${O?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${O?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Rr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:q}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:I.root===null?a("rightSidebar.allRepositories"):I.label})]}),I.branch&&e.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:I.branch}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${I.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:I.count})]},I.root??"all")})})]})});return Ud(C,ee,document.body)}function bf(){return gf()}function Xl(r){const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path),b=_a(f,i??v);return{key:dt(r),path:r.path,absolutePath:f,displayName:b.name,displayDir:b.dir,oldPath:r.oldPath,status:r.status,title:f}}function Jl(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:a("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function Ql(r,i){const f=ka(r,v),b=`path:${f}`,x=K===b,C=Re===b,I=x||C;return e.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),Ur(f,b)},...ko(ra(f),b),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${I?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${I?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:a(C?"rightSidebar.copied":x?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Zl(r){const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path),b=zf(r),x=oi(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(zg,{actions:b,running:Ae,completed:Rn?.path===x?Rn:null}),Ql(f,a("rightSidebar.insertThisFile"))]})}function ec(r,i){const f=i.root??v;if(!f)return null;const b=ka(r,f);return Ql(b,a("fileTree.insertRefTitle"))}function $o(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":a("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>cc("unified"),"aria-pressed":Kt==="unified",title:a("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Kt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>cc("split"),"aria-pressed":Kt==="split",title:a("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Kt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.split")})]})}function tc(){return da.map(r=>{const i=md(r.files.map(([,C])=>C)),f=!ue&&(da.length>1||r.label!==Ye),b=!!(r.root&&Ut.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:b,files:r.files.map(([,C])=>Xl(C)),header:f?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${b?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>_f(r.root),"aria-expanded":!b,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:b?e.jsx(wa,{size:13}):e.jsx(Ss,{size:13})}),e.jsx(Rr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),ba("stage-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),ba("stash-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]})]}):null}})}function rc(){return ye.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:a("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ua.map(([,r])=>{const i=pt(r,v),f=r.absolutePath||(i?`${i}/${r.path}`:r.path);return{key:dt(r),path:r.path,absolutePath:f,status:r.status,repoRoot:i,displayName:_a(f,i).name,displayDir:_a(f,i).dir,auditRecords:kt}})}function nc(r){const i=Array.from(ye.values()).find(x=>dt(x)===r.key),f=i?pt(i,v):null,b=Mm(kt,f,i?.path??r.path);return e.jsx(bi,{changeStatus:r.status,auditStatus:b,renderChangeBadge:x=>e.jsx(ys,{status:x})})}const ca=o.useCallback(r=>{if(ee)return null;const i=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const b=r.getBoundingClientRect().top+48;let x=null,C=Number.POSITIVE_INFINITY;for(const O of i){const q=O.getBoundingClientRect();if(q.bottom<b)continue;const Ne=Math.abs(q.top-b);Ne<C&&(x=O,C=Ne)}const I=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;return I?(Ys.current===I&&oe.getState().selectedFilePath===I||(Ys.current=I,Qe(I)),I):null},[ee,Qe]),xf=!!(!Ae&&we&&!He&&(fe?.upstream||rn.trim()&&nn.trim())),vf=!!(!Ae&&we&&!He&&(fe?.upstream||rn.trim()&&nn.trim())),yf=!!(!Ae&&we&&!He&&es.trim()&&es.trim()!==fe?.branch),_t=o.useMemo(()=>{const r=ce.trim().toLowerCase(),i=Array.from(ye.entries()).filter(([,f])=>!ue||pt(f,v)===ue).sort(([f],[b])=>f.localeCompare(b));return r?i.filter(([f,b])=>`${f} ${b.path} ${b.status} ${b.repoRelativeRoot??""} ${b.repoName??""}`.toLowerCase().includes(r)):i},[ue,ye,ce,v]);o.useEffect(()=>{Aa("selected_file_state",{selectedFilePath:Ge,selectedChangedFilePath:sr?.path??null,selectedChangedFileAbsolutePath:sr?.absolutePath??null,selectedChangedFileRepoRoot:sr?.repoRoot??null,rootPath:v,activeGitRepoRoot:ue,rightTab:uo,effectiveRightTab:kr,diffPaneActive:ct,changedFiles:ye.size,filteredChangedFiles:_t.length,gitBundleLoading:Nt,gitBundleLastLoadedAt:Ir})},[ue,ye.size,ct,kr,_t.length,Ir,Nt,uo,v,sr?.absolutePath,sr?.path,sr?.repoRoot,Ge]);const da=o.useMemo(()=>{const r=new Map;for(const i of _t){const[,f]=i,b=pt(f,v),x=Ug(f)||Ye,C=b??x,I=b?ht.get(b):void 0,O=r.get(C)??{root:b,label:x,branch:I?.context?.branch,files:[]};O.files.push(i),r.set(C,O)}return Array.from(r.values()).sort((i,f)=>i.label===Ye?-1:f.label===Ye?1:i.label.localeCompare(f.label))},[_t,ht,Ye,v]),ua=o.useMemo(()=>{const r=[],i=new Map;for(const f of _t)i.set(dt(f[1]),f);for(const f of da){if(f.root&&Ut.has(f.root))continue;if(wt!=="tree"){r.push(...f.files);continue}const b=f.files.map(([,x])=>Xl(x));for(const x of Kh(b)){const C=i.get(x.key);C&&r.push(C)}}return r},[Ut,wt,da,_t]);o.useEffect(()=>{if(!ct||ua.length===0||ee)return;const r=[],i=()=>{const f=document.querySelector(".termdock-diff-stream-scroller");if(f&&ca(f))return;const b=document.querySelector("[data-diff-stream-item]"),x=b?.dataset.diffSelectionPath??b?.dataset.diffStreamItem??null;if(x){Ys.current=x,Qe(x);return}const C=ua[0]?.[1];if(!C)return;const I=dt(C);Ys.current=I,Qe(I)};for(const f of[80,240,600,1200])r.push(window.setTimeout(i,f));return()=>r.forEach(f=>window.clearTimeout(f))},[ct,ee,ua,Qe,ca]);const Eo=o.useMemo(()=>{const r=I=>`'${I.replace(/'/g,"'\\''")}'`,i=zt.length>0?ln:X.filter(I=>I.files.length>0),f=i.length>0?i:v?[{root:v,relativeRoot:".",name:Ye}]:[],b=f.length>0?f.map(I=>`- ${I.relativeRoot==="."?".":I.relativeRoot} (${I.root})`).join(`
|
|
1667
1667
|
`):`- ${v?".":""}`,x=f.length>0?f.map(I=>` td audit-export ${r(I.root)}`).join(`
|
|
1668
1668
|
`):" td audit-export",C=f.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${v??""}`,"目标仓库:",b,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",x,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",C,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
|
|
1669
|
-
`)},[zt.length,ln,X,Ye,v]),wf=o.useCallback((r="generate")=>{if(hn&&Vr.length===0&&!ue){Lr(!0);return}const i=r==="generate"
|
|
1670
|
-
`);Je("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:zt,mode:r,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Hr(a("rightSidebar.insertChangeAuditPrompt"),i,`${Pl}:${r}`),nr(),c||s()},[ue
|
|
1671
|
-
`))C.startsWith("+++")||C.startsWith("---")||(C.startsWith("+")&&(b+=1),C.startsWith("-")&&(x+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:b,deletions:x,diff:f}};return Me?(Me.hunks??[]).map(i=>{const f=fr.find(b=>b.repoRoot===Me.repoRoot&&b.baseRef===Me.baseRef&&(b.branchName??null)===(Me.currentBranch??null)&&b.filePath===i.filePath&&b.hunkHeader===i.hunkHeader&&(b.hunkIndex??0)===i.hunkIndex&&b.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,hunk:i,current:f,stale:null}}):Ve?fr.filter(i=>nd(i)===Ve).map(i=>{const f=r(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:f,current:i,stale:null}}):[]},[Me,fr,rr,Ve]),
|
|
1669
|
+
`)},[zt.length,ln,X,Ye,v]),wf=o.useCallback((r="generate")=>{if(hn&&Vr.length===0&&!ue){Lr(!0);return}const i=r==="generate"?Eo:[r==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Eo].join(`
|
|
1670
|
+
`);Je("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:zt,mode:r,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Hr(a("rightSidebar.insertChangeAuditPrompt"),i,`${Pl}:${r}`),nr(),c||s()},[ue,Eo,Vr.length,zt,Hr,nr,s,c,v,hn,a]),fa=o.useCallback(async r=>{try{await $c({ids:[r]}),Kr(i=>i.filter(f=>f.id!==r))}catch{nr()}},[nr]),kf=o.useCallback(async()=>{if(kt.length===0)return;const r=kt.map(i=>i.id);try{await $c({ids:r}),Kr(i=>i.filter(f=>!r.includes(f.id))),Pt(null)}catch(i){const f=i instanceof Error?i.message:"Failed to clear change audit explanations";Pt(a("rightSidebar.changeAuditClearFailed",{message:f})),nr()}},[kt,nr,a]),Sf=o.useCallback(async r=>{if(r.records.length===0)return;const i=r.records.map(f=>f.id);try{await xh({ids:i}),hr(f=>f.filter(b=>!i.includes(b.id))),Ve===r.key&&(Zr(null),Vt(!1))}catch(f){lt(a("rightSidebar.branchAuditClearFailed",{message:f instanceof Error?f.message:"Failed to clear branch explanation"})),Qs(null)}},[Qs,Ve,a]),jf=o.useCallback(r=>{Yr(i=>r===null?(Lr(!1),[]):i.includes(r)?i.filter(f=>f!==r):[...i,r])},[]),Rf=o.useCallback(r=>{Gi(i=>r===null?(Qa(!1),[]):i.includes(r)?i.filter(f=>f!==r):[...i,r])},[]),Lo=o.useMemo(()=>{if(!rr)return[];const r=i=>{const f=i.diff??"";let b=0,x=0;for(const C of f.split(`
|
|
1671
|
+
`))C.startsWith("+++")||C.startsWith("---")||(C.startsWith("+")&&(b+=1),C.startsWith("-")&&(x+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:b,deletions:x,diff:f}};return Me?(Me.hunks??[]).map(i=>{const f=fr.find(b=>b.repoRoot===Me.repoRoot&&b.baseRef===Me.baseRef&&(b.branchName??null)===(Me.currentBranch??null)&&b.filePath===i.filePath&&b.hunkHeader===i.hunkHeader&&(b.hunkIndex??0)===i.hunkIndex&&b.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,hunk:i,current:f,stale:null}}):Ve?fr.filter(i=>nd(i)===Ve).map(i=>{const f=r(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:f,current:i,stale:null}}):[]},[Me,fr,rr,Ve]),Ao=fr.length>0,Bn=o.useMemo(()=>{if(!rr)return[];const r=new Map;for(const i of fr){const f=i.repoRoot,b=ht.get(f),x=b?.relativeRoot==="."?Ye:b?.relativeRoot||b?.name||ut(f),C=nd(i),I=r.get(C)??{key:C,repoRoot:f,repoLabel:x,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};I.records.push(i),I.latestInjectedAt=Math.max(I.latestInjectedAt,i.injectedAt??0),r.set(C,I)}return Array.from(r.values()).sort((i,f)=>f.latestInjectedAt-i.latestInjectedAt)},[fr,ht,rr,Ye]),Po=o.useMemo(()=>Ve?Bn.find(r=>r.key===Ve)??null:null,[Bn,Ve]),ha=Me?{repoRoot:Me.repoRoot??"",repoLabel:Me.repoRoot?ht.get(Me.repoRoot)?.relativeRoot==="."?Ye:ht.get(Me.repoRoot)?.relativeRoot||ht.get(Me.repoRoot)?.name||ut(Me.repoRoot):Ye,baseRef:Me.baseRef??Me.baseBranch??"",branchName:Me.currentBranch??null,headRef:Me.headRef??null,diffFingerprint:Me.diffFingerprint??null}:Po,Cf=o.useMemo(()=>(Fe?.hunks??[]).map(r=>({key:`${r.filePath}\0${r.hunkHeader}\0${r.hunkIndex}`,hunk:r,current:null,stale:null})),[Fe?.hunks]),Nf=o.useMemo(()=>{if(Me)return[];const r=Po;return r?xn.filter(i=>i.repoRoot===r.repoRoot&&i.baseRef===r.baseRef&&(i.branchName??null)===r.branchName&&(!r.diffFingerprint||i.diffFingerprint===r.diffFingerprint)):[]},[Me,xn,Po]),Mf=o.useCallback(r=>{const i=Lo.find(f=>f.hunk.filePath===r.filePath||(r.repoRoot?`${r.repoRoot}/${f.hunk.filePath}`===r.filePath:!1));i&&(en(i.key),window.setTimeout(()=>mn(r),90),window.setTimeout(()=>mn(r),320),window.setTimeout(()=>mn(r),760))},[Lo]),To=o.useMemo(()=>{const r=x=>`'${x.replace(/'/g,"'\\''")}'`,i=Wt,f=i.length>0?i.map(x=>`- ${x.label} (${x.root}),目标分支:${gr[x.root]||x.branch||"(current branch)"},基线分支:${St[x.root]||"(not set)"}`).join(`
|
|
1672
1672
|
`):`- ${v?".":""}`,b=i.length>0?i.map(x=>{const C=gr[x.root]||x.branch||"",I=St[x.root]||"",O=x.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[C?` git -C ${r(x.root)} switch ${r(C)}`:` # ${x.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${r(I)} ${r(x.root)} > ~/.termdock/branch-audit/branch-audit-export-${O}.json`].join(`
|
|
1673
1673
|
`)}).join(`
|
|
1674
1674
|
`):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${v??""}`,`包含本地未提交更改:${Pr?"是":"否"}`,"目标仓库:",f,"","操作指令:",Pr?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",b,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:v??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
|
|
1675
|
-
`)},[Pr,Wt,St,gr,v]),$f=o.useCallback((r="generate")=>{const i=r==="generate"?
|
|
1676
|
-
`);Hr(a("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${r}`),c||s()},[
|
|
1675
|
+
`)},[Pr,Wt,St,gr,v]),$f=o.useCallback((r="generate")=>{const i=r==="generate"?To:[r==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",To].join(`
|
|
1676
|
+
`);Hr(a("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${r}`),c||s()},[To,Hr,s,c,a]),Ef=o.useCallback(async()=>{if(!v||Wt.length===0)return;const r=v;H(!0),be(null),Yt(null),$e(null);try{const i=await Promise.all(Wt.map(async O=>{const q=St[O.root]?.trim();if(!q)throw new Error(a("rightSidebar.branchAuditMissingBase",{repo:O.label}));const Ne=(gr[O.root]||O.branch||"").trim();return vh({cwd:v,repoRoot:O.root,base:q,head:Ne&&Ne!==O.branch?Ne:null,includeUncommitted:Pr,requestSlotId:`right-sidebar-branch-preview:${O.root}`})}));if(!Ce(r))return;const f=i.find(O=>!O.available);if(f){be(f.error??"Branch diff is unavailable");return}const b=i.length===1?i[0]:{available:!0,workspaceRoot:v,repoRoot:v,baseRef:i.map(O=>O.baseRef??O.baseBranch).filter(Boolean).join(", "),currentBranch:i.map(O=>O.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:i.map(O=>O.headRef).filter(Boolean).join(", "),diffFingerprint:i.map(O=>O.diffFingerprint).filter(Boolean).join("+"),stat:i.map(O=>O.stat).filter(Boolean).join(`
|
|
1677
1677
|
`),files:i.flatMap((O,q)=>{const Ne=Wt[q];return(O.files??[]).map(Xe=>`${Ne?.label??O.repoRoot??"repo"}/${Xe}`)}),hunks:i.flatMap((O,q)=>{const Xe=Wt[q]?.label??O.repoRoot??"repo";return(O.hunks??[]).map(Be=>({...Be,filePath:`${Xe}/${Be.filePath}`,oldPath:Be.oldPath?`${Xe}/${Be.oldPath}`:Be.oldPath,newPath:Be.newPath?`${Xe}/${Be.newPath}`:Be.newPath}))}),commits:i.flatMap(O=>O.commits??[]),commitCount:i.reduce((O,q)=>O+(q.commitCount??q.commits?.length??0),0),diff:i.map(O=>O.diff).filter(Boolean).join(`
|
|
1678
|
-
`),truncated:i.some(O=>O.truncated)};if((b.hunks??[]).length===0){be(a("rightSidebar.branchAuditDiffEmpty"));return}const x=Date.now(),C=["preview",b.repoRoot??v,b.baseRef??b.baseBranch??"",b.currentBranch??"",b.headRef??"",b.diffFingerprint??x].join("\0"),I=Wt.length===1?Wt[0].label:`${Wt.length} repos`;Yt(b),Yn(O=>[{key:C,diff:b,repoLabel:I,createdAt:x},...O.filter(q=>q.key!==C)].slice(0,8)),wn(O=>O[C]===void 0?O:{...O,[C]:0}),Zr(C),en(b.hunks?.[0]?`${b.hunks[0].filePath}\0${b.hunks[0].hunkHeader}\0${b.hunks[0].hunkIndex}`:null),Vt(!0)}catch(i){if(!Ce(r)||or(i))return;be(i instanceof Error?i.message:"Failed to load branch diff")}finally{Ce(r)&&H(!1)}},[Pr,Wt,St,gr,Ce,v,a]),Lf=o.useCallback(r=>{Yt(r.diff),be(null),Zr(r.key),en(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),Vt(!0)},[]),Af=o.useCallback(r=>{Yn(i=>i.filter(f=>f.key!==r)),wn(i=>{if(!(r in i))return i;const f={...i};return delete f[r],f}),Ve===r&&(Zr(null),Yt(null),Vt(!1))},[Ve]),Pf=o.useCallback(r=>{const i=Bn.find(f=>f.key===r);i&&(Yt(null),be(null),Zr(r),en(i.records[0]?.filePath??null),Vt(!0))},[Bn]),Tf=o.useCallback(async r=>{if(!v||!we)return;const[i]=r.split(/\s+/);if(i){Ie(i),st(null),$e(null);try{const f=await vh({cwd:v,repoRoot:we,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!f.available){st(f.error??"Commit diff is unavailable");return}$e(f);const b=f.hunks?.[0];Ps(b?`${b.filePath}\0${b.hunkHeader}\0${b.hunkIndex}`:null)}catch(f){st(f instanceof Error?f.message:"Failed to load commit diff")}finally{Ie(null)}}},[we,v]),If=o.useCallback(r=>{if(!Me||!Ve)return;const i=Math.max(0,Math.round(r));wn(f=>Math.abs((f[Ve]??0)-i)<24?f:{...f,[Ve]:i})},[Me,Ve]);o.useEffect(()=>{!ee||!mr||!Me||as(1)},[mr,Me,ee,as]);const sc=o.useCallback(r=>{r&&Yu(i=>Kh(i,r))},[]),ac=Hs.key===Ge?Hs.key:null,ma=o.useCallback(r=>{const i=oe.getState(),f=Zg();Aa("select_diff_file",{interactionId:f,path:r,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ue,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),Qe(r),sn("diff"),ee&&r&&as(1),sc(r),queueMicrotask(()=>{const b=oe.getState();Aa("select_diff_file_after",{interactionId:f,requestedPath:r,selectedFilePath:b.selectedFilePath,rootPath:b.rootPath,rightTab:b.rightTab,changedFiles:b.changedFiles.size,activeGitRepoRoot:ue})})},[ue,ee,sc,Qe,sn,as]),oc=o.useCallback(r=>{const i=Array.from(ye.values()).find(f=>{const b=pt(f,v),x=dt(f);return f.path===r.filePath||x===r.filePath||f.absolutePath===r.filePath||(b?`${b}/${f.path}`===r.filePath:!1)||r.repoRoot&&b===r.repoRoot&&f.path===r.filePath});if(i){ma(dt(i)),window.setTimeout(()=>mn(r),90),window.setTimeout(()=>mn(r),320),window.setTimeout(()=>mn(r),760);return}mn(r)},[ye,v,ma]),ic=o.useCallback(({slideToDetail:r,fullscreen:i,toggleFullscreen:f}={})=>Kn.length>0?e.jsx(jd,{walkthroughs:Kn,repoRoot:ue,fullscreen:i,onToggleFullscreen:f,onNavigate:b=>{ee&&window.requestAnimationFrame(()=>r?.()),oc(b)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(Rs,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),a("rightSidebar.changeWalkthroughEmpty")]}),[ue,Kn,oc,ee,a]),_f=o.useCallback(r=>{r&&Nr(i=>{const f=new Set(i);return f.has(r)?f.delete(r):f.add(r),Xo(Go,f),f})},[]),lc=o.useCallback(r=>{Va(i=>{const f=new Set(i);return f.has(r)?f.delete(r):f.add(r),Xo(qc,f),f})},[]),pa=o.useCallback(r=>{Es(r),gt(zd,r)},[]);o.useEffect(()=>{oa||wt!=="ai"||pa("tree")},[wt,pa,oa]);const To=o.useCallback(()=>{Ls(r=>{const i=!r;return gt(Wd,i),i})},[]),cc=o.useCallback(r=>{qr(r),gt(Gd,r)},[]),{whitespace:dc,context:uc}=Yh(),fc=o.useMemo(()=>({algorithm:"histogram",whitespace:dc,context:uc}),[dc,uc]),hc=o.useCallback(r=>{F(r),gt(qd,r)},[]),ga=o.useCallback(async(r,i,f,b)=>{let x=r;for(;x.ok&&x.status==="running";)await new Promise(I=>window.setTimeout(I,1500)),x=await Ec({jobId:x.jobId,cwd:i.cwd,action:i.action});if(!x.ok)throw new Error("Git action status is unavailable");if(x.status==="error")throw new Error(x.error||x.message||"Git action failed");const C={action:i.action,path:b,label:f};return Zn(C),window.setTimeout(()=>Zn(I=>I?.action===C.action&&I.path===C.path?null:I),1400),x},[]),at=o.useCallback(async(r,i,f)=>{const b=v;v&&Dr.current.delete(v),lt(null),Zn(null),Qn({action:r.action,path:f});try{const x=await yh(r),C=await ga(x,r,i,f);if(!Ce(b))return!1;const I=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>C.bundle):C.bundle;return Ce(b)?(I&&Or(I,{reloadDiff:!0,cacheOnly:!0}),Tr(null),!0):!1}catch(x){return Zn(null),lt(a("rightSidebar.gitActionFailed",{message:x instanceof Error?x.message:"Unknown error"})),!1}finally{Ce(b)&&Qn(null)}},[Or,Ce,v,a,ga]),mc=o.useCallback(async r=>{const i=v,f=await wh(r);if(!Ce(i))return;const b=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>f.bundle):f.bundle;Ce(i)&&b&&Or(b,{reloadDiff:!0,cacheOnly:!0})},[Or,Ce,v]),ba=o.useCallback((r,i,f)=>{if(i){if(r==="stage-all"){at({action:"stage-all",cwd:i},a("rightSidebar.stageAll"),`repo:${i}`);return}Tr({kind:"stash-all",repoRoot:i,repoLabel:f})}},[at,a]),pc=o.useCallback(r=>{qe(r),Yo(v,r),so(""),ao(""),oo(""),Qe(Hl(r)),We||sn("diff")},[Hl,We,v,Qe,sn]),Df=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=es.trim();!r||r===fe?.branch||await at({action:"switch-branch",cwd:we,branch:r},a("rightSidebar.switchBranch"))},[fe?.branch,we,He,at,es,a]),gc=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=Bs.trim();if(!r)return;await at({action:"commit",cwd:we,message:r},a("rightSidebar.commitChanges"))&&Qi("")},[we,Bs,He,at,a]),Ff=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=rn.trim(),i=nn.trim();await at({action:"push",cwd:we,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pushChanges"))},[we,nn,rn,He,at,a]),Bf=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=rn.trim(),i=nn.trim();await at({action:"pull",cwd:we,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pullChanges"))},[we,nn,rn,He,at,a]);o.useEffect(()=>{if(!We||!we||Ae)return;let r=!1;const i={push:a("rightSidebar.pushChanges"),pull:a("rightSidebar.pullChanges"),commit:a("rightSidebar.commitChanges"),"switch-branch":a("rightSidebar.switchBranch"),"stage-all":a("rightSidebar.stageAll"),"stash-all":a("rightSidebar.stashAll")};return(async()=>{for(const f of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const b=await Ec({cwd:we,action:f}).catch(()=>null);if(!b?.ok||b.status!=="running")continue;const x={action:f,cwd:we},C=i[f]??f;Qn({action:f});try{const I=await ga(b,x,C);if(r||!Ce(v))return;const O=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>I.bundle):I.bundle;O&&Or(O,{reloadDiff:!0,cacheOnly:!0})}catch(I){r||lt(a("rightSidebar.gitActionFailed",{message:I instanceof Error?I.message:"Unknown error"}))}finally{r||Qn(null)}return}})(),()=>{r=!0}},[we,Or,We,Ce,v,Ae,a,ga]);const Io=Rn?.action==="commit",_o=Rn?.action==="switch-branch",Do=Rn?.action==="pull",Fo=Rn?.action==="push",xa=We||Ku,Bo=la?a("rightSidebar.changeAuditScopeAll"):ar.length===1?ar[0].label:`${ar.length} repos`,Of=ar.length>0,bc=Wt.length>0,Uf=v?e.jsx(dd,{open:Ja,onOpenChange:Qa,showScopePicker:!0,selectedAll:la,repos:It,selectedRoots:ia,onToggleRepo:Rf,onGenerate:()=>$f(Lo?"regenerate":"generate"),disabled:!Of,generateDisabled:!bc,inserted:K?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:a(Lo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.branchAuditGenerateTitle"),ariaLabel:a("rightSidebar.branchAuditShort"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:Bo,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a(Lo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ef()},secondaryDisabled:!bc||P,secondaryLabel:a("rightSidebar.branchAuditViewDiff"),secondaryTitle:a("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:P,loading:qi.size>0,statusTitle:qi.size>0?a("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:a("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:a("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Pr,onChange:r=>Gi(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),ql.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:a("rightSidebar.missingBaseReposSkipped",{repositories:ql.map(r=>r.label).join(k==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const i=ht.get(r.root),f=[],b=new Set,x=(q,Ne)=>{!q||b.has(q)||(b.add(q),f.push({value:q,label:q,meta:Ne}))};x(gr[r.root]||i?.context?.branch,a("rightSidebar.pushCurrentBranchBadge"));for(const q of i?.context?.branches??[])x(q,q===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):a("rightSidebar.localBranch"));for(const q of i?.context?.remoteBranches??[])x(q,a("rightSidebar.remoteBranch"));const C=[],I=new Set,O=(q,Ne)=>{!q||I.has(q)||(I.add(q),C.push({value:q,label:q,meta:Ne}))};O(St[r.root],St[r.root]?a("rightSidebar.pushUpstreamBadge"):void 0),O(i?.context?.upstream,i?.context?.upstream?a("rightSidebar.pushUpstreamBadge"):void 0);for(const q of i?.context?.remoteBranches??[])O(q,"remote");for(const q of i?.context?.branches??[])O(q,q===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Un,{label:a("rightSidebar.currentBranchLabel"),value:gr[r.root]||i?.context?.branch||"",options:f,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),onChange:q=>{Is(Ne=>({...Ne,[r.root]:q}))}}),e.jsx(Un,{label:a("rightSidebar.branchAuditBaseLabel"),value:St[r.root]||"",options:C,placeholder:a("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:a("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:a("rightSidebar.branchAuditBaseEmpty"),onChange:q=>{_s(Ne=>({...Ne,[r.root]:q}))}})]})}}):null,xc=gs(kt.reduce((r,i)=>Math.max(r,i.injectedAt??0),0),k),Hf=v?e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>zi(r=>{const i=!r;return gt(qo,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Jn,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Rs,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:Bo})]}),e.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Jn?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]}),Jn&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[a("rightSidebar.changeAuditScopeLabel"),": ",Bo]}),Uf]}),le&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:le}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Xr.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ve===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Lf(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:a("rightSidebar.branchAuditViewDiff")})]}),gs(r.createdAt,k)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:gs(r.createdAt,k)})]}),e.jsx("button",{type:"button",onClick:()=>Af(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("common.delete"),"aria-label":a("common.delete"),children:e.jsx(Pa,{size:12})})]},r.key)),Bn.length>0?Bn.slice(0,Math.max(0,8-Xr.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ve===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Pf(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),gs(r.latestInjectedAt,k)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:a("rightSidebar.branchAuditGeneratedAt",{time:gs(r.latestInjectedAt,k)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Sf(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("rightSidebar.branchAuditClearTitle"),"aria-label":a("rightSidebar.branchAuditClearTitle"),children:e.jsx(Pa,{size:12})})]},r.key)):Xr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,vc=rr&&v&&Fn?e.jsxs("div",{className:xa?"overflow-visible":"overflow-hidden",children:[Hf,e.jsxs("button",{type:"button",onClick:()=>{We||Vu(r=>{const i=!r;return i&&we&&!Fn&&!tn&&vo(we),i})},"aria-expanded":xa,className:`group flex w-full items-center gap-2 px-1 py-1.5 text-left transition ${We?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Rr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex min-w-[4.5rem] items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${fn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[tn&&e.jsx(nt,{size:10,className:"animate-spin"}),fn.staged>0?a("rightSidebar.stagedCount",{count:fn.staged}):a("rightSidebar.noStagedChangesShort")]}),!We&&e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${xa?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]})]}),xa&&e.jsxs("div",{className:"space-y-0",children:[mt.length>1&&e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:cf})]})}),e.jsx(Un,{label:a("rightSidebar.gitRepositoryLabel"),value:we??"",options:mt,placeholder:a("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:a("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:a("rightSidebar.gitRepositoryEmpty"),disabled:!!Ae,onChange:r=>{pc(r||null)}}),He&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:a("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:df})]}),e.jsxs("button",{type:"button",onClick:()=>{Df()},disabled:!yf,className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${_o?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ae?.action==="switch-branch"||_o?"opacity-0":"",children:a("rightSidebar.switchBranch")}),Ae?.action==="switch-branch"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),_o&&Ae?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Un,{label:a("rightSidebar.currentBranchLabel"),value:es,options:hf,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),disabled:!!Ae,onChange:so})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:He?a("rightSidebar.selectRepositoryForGitActions"):fn.staged>0?a("rightSidebar.commitReadyHint",{count:fn.staged}):a("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{gc()},disabled:!!Ae||He||fn.staged===0||!Bs.trim(),className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition active:scale-95 ${Io?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:He?a("rightSidebar.selectRepositoryForGitActions"):fn.staged===0?a("rightSidebar.commitNeedsStaged"):a("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ae?.action==="commit"||Io?"opacity-0":"",children:a("rightSidebar.commitChanges")}),Ae?.action==="commit"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Io&&Ae?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Bs,onChange:r=>Qi(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),gc())},placeholder:a("rightSidebar.commitMessagePlaceholder"),disabled:!!Ae,className:"w-full rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-[12px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary/35 focus:ring-1 focus:ring-primary/25 disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>pr(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Xt,children:[e.jsx("span",{className:"min-w-0 text-[11px] font-semibold text-foreground",children:a("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Sn&&e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Xt?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]})]}),Xt&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:12,className:"shrink-0"}),e.jsx("input",{value:kn,onChange:r=>Jr(r.target.value),placeholder:a("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),kn&&e.jsx("button",{type:"button",onClick:()=>Jr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Dt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:uf,children:[Jt.length>0?Jt.map(r=>{const[i,...f]=r.split(/\s+/),b=f.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{Tf(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:b,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:b,children:b}),Ue===i&&e.jsx(nt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):Sn?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:a("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.recentCommitsEmpty")}),Q&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(nt,{size:12,className:"animate-spin"})}),Xa&&!Q&&Jt.length>0&&e.jsx("button",{type:"button",onClick:()=>{cs({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:a("rightSidebar.recentCommitsLoadMore")})]})]}),tt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:tt}),Zt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Zt})]}),e.jsxs("div",{className:"px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Bf()},disabled:!xf,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Do?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ae?.action==="pull"||Do?"opacity-0":"",children:a("rightSidebar.pullChanges")}),Ae?.action==="pull"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Do&&Ae?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Ff()},disabled:!vf,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Fo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ae?.action==="push"||Fo?"opacity-0":"",children:a("rightSidebar.pushChanges")}),Ae?.action==="push"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Fo&&Ae?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${Vl.className}`,title:fe?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:Vl.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:fe?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${Gl?"grid-cols-2":"grid-cols-1"}`,children:[Gl&&e.jsx(Un,{label:a("rightSidebar.pushRemoteLabel"),value:rn,options:Wl,placeholder:a("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:a("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:a("rightSidebar.pushNoRemotes"),disabled:!!Ae,onChange:ao}),e.jsx(Un,{label:a("rightSidebar.pushBranchLabel"),value:nn,options:mf,placeholder:a("rightSidebar.pushBranchPlaceholder",{branch:fe?.branch??"HEAD"}),searchPlaceholder:a("rightSidebar.pushBranchSearchPlaceholder"),emptyText:a("rightSidebar.pushNoBranches"),disabled:!!Ae,onChange:oo})]})]})]})]}):null,zf=o.useCallback(r=>{const i=pt(r,v);if(!i)return[];const f=ai(r),b=[];return r.canStage&&b.push({key:"stage-file",label:a("rightSidebar.stageFile"),onClick:()=>{at({action:"stage-file",cwd:i,paths:[r.path]},a("rightSidebar.stageFile"),f)}}),r.canUnstage&&b.push({key:"unstage-file",label:a("rightSidebar.unstageFile"),onClick:()=>{at({action:"unstage-file",cwd:i,paths:[r.path]},a("rightSidebar.unstageFile"),f)}}),r.canStash&&b.push({key:"stash-file",label:a("rightSidebar.stashFile"),onClick:()=>{at({action:"stash-file",cwd:i,paths:[r.path]},a("rightSidebar.stashFile"),f)}}),r.canRestoreWorktree&&b.push({key:"restore-worktree-file",label:a("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Tr({kind:"restore",file:r,phrase:""})}),b},[v,at,a]),Wf=o.useCallback(()=>{if(m){u?.();return}xr(0),wr.current?.slideTo(0),br(!1),yt(null)},[u,m]),yc=o.useCallback(r=>{if(j(""),Tt(r),Qe(null),yt(null),re(null),ee){m&&u?.(),xr(0),wr.current?.slideTo(0),br(!1);return}},[ee,u,m,Qe,Tt]);o.useEffect(()=>{const r=i=>{const f=i.detail,b=f?.path;if(typeof b!="string"||!b.startsWith("/"))return;j(""),yt(null);const x=!!(v&&(b===v||b.startsWith(`${v}/`)));if(f.kind==="file"){const C=ri(b);os(b),Tt(x?null:C),re(I=>({path:b,nonce:(I?.nonce??0)+1}));return}Qe(null),x?(Tt(null),re(C=>({path:b,nonce:(C?.nonce??0)+1}))):(re(null),Tt(b)),ee&&(m&&u?.(),xr(0),wr.current?.slideTo(0),br(!1))};return window.addEventListener(Ac,r),()=>window.removeEventListener(Ac,r)},[os,ee,u,m,v,Qe,Tt]),o.useEffect(()=>{t||(Lt(!1),Bt(!1))},[t]),o.useEffect(()=>{if(!qt&&!cr)return;const r=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&($s.current?.contains(i.target)||bn.current?.contains(i.target))||(Lt(!1),Bt(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[cr,qt]);const wc=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:af,disabled:!na,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.parentFolder"),title:a("rightSidebar.parentFolder"),children:e.jsx(yd,{size:14})}),e.jsx("button",{type:"button",onClick:Tl,disabled:!v||Mn===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.backToProjectRoot"),title:a("rightSidebar.backToProjectRoot"),children:e.jsx(Ic,{size:14})}),e.jsx("button",{type:"button",onClick:of,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.refreshFiles"),title:Zi?a("rightSidebar.fileWatchUnavailable",{message:Zi}):a("rightSidebar.refreshFiles"),children:e.jsx(ui,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:nf}),qs==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:a("fileTree.sortedByModified"),"aria-label":a("fileTree.sortedByModified"),children:e.jsx(Pc,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&Ur(ge,$t??void 0),disabled:!ge,...ge&&$t?wo(ra(ge),$t):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${$t&&(K===$t||Re===$t)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":a($t&&Re===$t?"rightSidebar.copied":$t&&K===$t?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:a("rightSidebar.insertCurrentFolder"),children:$t&&(K===$t||Re===$t)?e.jsx(ci,{size:13}):e.jsx(Da,{size:13})}),e.jsxs("div",{ref:bn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Lt(!1),Bt(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${cr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":cr,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(di,{size:14})}),cr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Bt(!1),lf()},disabled:!jo,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${ls?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ls?e.jsx(Ho,{size:14}):e.jsx(Sa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(ls?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Bt(!1),Ju()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${fo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[fo?e.jsx(Zh,{size:14}):e.jsx(mi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(fo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(Bt(!1),Qu(ge,qs==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[qs==="modified"?e.jsx(Bh,{size:14}):e.jsx(Pc,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(qs==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),v&&(sa.length>0||sf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Tl,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-full px-2 py-0.5 font-medium transition active:scale-95 ${ge===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(Ic,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Ye})]}),sa.map(r=>{const i=r.path,f=r.kind==="file",b=f?Ge===i:ge===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-full transition ${b?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>f?os(i):Tt(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[f?e.jsx(pi,{size:10,className:"shrink-0"}):e.jsx(Sa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ut(i)})]}),e.jsx("button",{type:"button",onClick:()=>an(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.unpinFolder",{name:ut(i)}),title:a("rightSidebar.unpinFolder",{name:ut(i)}),children:e.jsx(Dt,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Oo=o.useMemo(()=>{if(Cn===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((no-Cn)/1e3)),f=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[b,x]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return f.format(b,x)},[no,Cn]),kc=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Oo?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:a("rightSidebar.gitLastUpdated",{time:Oo}),children:Oo}):null,e.jsx("button",{type:"button",onClick:()=>{ss()},disabled:Nt,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":a("rightSidebar.refreshGit"),title:a("rightSidebar.refreshGit"),children:e.jsx(ui,{size:13,className:Nt?"animate-spin":""})})]}):null,Gf=yl?a("rightSidebar.changeAuditScopeAll"):ln.length===1?ln[0].relativeRoot==="."?Ye:ln[0].relativeRoot||ln[0].name:`${ln.length} repos`,Sc=v?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(dd,{open:As,onOpenChange:Lr,showScopePicker:hn,selectedAll:yl,repos:Zu,selectedRoots:zt,onToggleRepo:jf,onGenerate:()=>wf(),disabled:!v,inserted:K===Pl,buttonLabel:a("rightSidebar.changeAuditShort"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:a("rightSidebar.insertChangeAuditPrompt"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:Gf,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a("rightSidebar.changeAuditShort"),loading:Mr,error:!!Er,statusTitle:Er??(Mr?a("rightSidebar.changeAuditLoading"):kt.length>0?`${a("rightSidebar.changeAuditLoaded",{count:kt.length})}${xc?` · ${a("rightSidebar.changeAuditLoadedAt",{time:xc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{kf()},disabled:Mr||kt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${kt.length>0?"":"invisible"}`,title:a("rightSidebar.clearChangeAuditTitle"),"aria-label":a("rightSidebar.clearChangeAudit"),children:e.jsx(Pa,{size:12})})]}):null,va=ye.size>0||ne?.available||Ir?e.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] font-medium",children:[ne?.available&&ne.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:ne.branch,children:[e.jsx(Rr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ne.branch})]}),rt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[rt.modified,"M"]}),rt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",rt.added]}),rt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",rt.deleted]}),rt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[rt.renamed,"R"]}),rt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[rt.copied,"C"]}),rt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[rt.untracked,"U"]}),rt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[rt.conflicted,"!"]}),rt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[rt.other,"?"]}),rt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:a("rightSidebar.stagedCountShort",{count:rt.staged})}),ne?.available&&v&&ye.size>0&&X.length<=1&&e.jsx("button",{type:"button",onClick:()=>{at({action:"stage-all",cwd:v},a("rightSidebar.stageAll"))},disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),ne?.available&&v&&ye.size>0&&X.length<=1&&e.jsx("button",{type:"button",onClick:()=>Tr({kind:"stash-all",repoRoot:v,repoLabel:Ye}),disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}):null;return e.jsxs(Oh,{side:"right",isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:c,pinned:d,children:[wo.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:Ye}),(!ee||to)&&ne?.available&&ne.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:ne.branch,children:[e.jsx(Rr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:ne.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!se;he(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):j("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${se?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleSearch"),title:a("common.search"),children:e.jsx(zn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Ke,onClick:()=>{pn(r=>!r),ir(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Ke?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleContextDraft"),title:a("rightSidebar.contextDraftTitle"),children:[e.jsx(dm,{size:14}),!Ke&&vt.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:nl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const i=r.target.files;!i||i.length===0||(is(Array.from(i)),r.target.value="")}}),e.jsx("input",{ref:sl,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const i=r.target.files?.[0];r.target.value="",i&&rf(i)}}),h&&e.jsx("button",{type:"button",onClick:h,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${d?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:d?e.jsx(Ho,{size:14}):e.jsx(Sa,{size:14})}),e.jsxs("div",{ref:$s,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Bt(!1),Lt(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${qt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":qt,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(di,{size:15})}),qt&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),nl.current?.click()},disabled:Os,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Os?e.jsx(nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(vm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),sl.current?.click()},disabled:Os,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Os?e.jsx(nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(sm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.insertLocalImage")})]}),h&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),h()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${d?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[d?e.jsx(Ho,{size:14}):e.jsx(Sa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),d&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":a("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:a("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",a("rightSidebar.layoutModeAuto")],["narrow",a("rightSidebar.layoutModeNarrow")],["wide",a("rightSidebar.layoutModeWide")]].map(([r,i])=>{const f=G===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":f,onClick:()=>{J(r),Lt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},r)})})]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":a("rightSidebar.close"),children:e.jsx(Dt,{size:14})})]}),se&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:B,onChange:r=>j(r.target.value),placeholder:a($==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>hc("name"),"aria-pressed":$==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${$==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>hc("content"),"aria-pressed":$==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${$==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeContent")})]}),B&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Dt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Uh,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:V,onChange:r=>te(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchScopePlaceholder"),"aria-label":a("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),V!=="."&&e.jsx("button",{type:"button",onClick:()=>te("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.resetSearchScope"),children:e.jsx(Dt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>je(r=>!r),"aria-expanded":pe,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${pe||ts.length>0||N||de||ze?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:a("rightSidebar.searchOptions"),"aria-label":a("rightSidebar.searchOptions"),children:[e.jsx(Hh,{size:13}),ts.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 min-w-4 rounded-full bg-primary px-1 text-[8px] font-bold leading-4 text-primary-foreground",children:ts.length})]})]}),pe&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ie,onChange:r=>me(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchExcludePlaceholder"),"aria-label":a("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ie&&e.jsx("button",{type:"button",onClick:()=>me(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.clearSearchExclude"),children:e.jsx(Dt,{size:11})})]}),$==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":a("rightSidebar.contentSearchOptions"),children:[[N,()=>Z(r=>!r),Jh,a("rightSidebar.matchCase")],[de,()=>Ee(r=>!r),wm,a("rightSidebar.matchWholeWord")],[ze,()=>Pe(r=>!r),fm,a("rightSidebar.useRegex")]].map(([r,i,f,b])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(f,{size:12}),b]},b))})]})]}),Zs?null:e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>sn("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Rr,{size:12}),a("rightSidebar.tabGit"),Nt&&kr==="git"?e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}):null]}),e.jsxs("button",{type:"button",onClick:()=>sn("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Ed,{size:12}),a("rightSidebar.tabChanges"),Nt?e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}):ye.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:ye.size}):null]}),e.jsxs("button",{type:"button",onClick:()=>sn("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Gh,{size:12}),a("rightSidebar.tabFiles")]})]}),e.jsx("div",{className:"h-2"}),Xi&&e.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:Xi})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(ti,{active:We,mounted:rr,fallback:e.jsx(ps,{slow:!1}),children:Fe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Bc,{items:Cf,selectedKey:zu,onSelect:Ps,emptyText:a("rightSidebar.noChanges"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a("rightSidebar.recentCommitsTitle"),headerMeta:`${Fe.headRef??""}${Fe.commits?.[0]?` · ${Fe.commits[0]}`:""}`,onClose:()=>{$e(null),Ps(null)},closeLabel:a("common.back"),wrap:At,onToggleWrap:ee?To:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa})}):mr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Bc,{items:Eo,selectedKey:Za,onSelect:en,emptyText:a(Me?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a(Me?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:ha?`${ha.repoLabel} · ${ha.branchName??"HEAD"} → ${ha.baseRef}`:void 0,onClose:()=>{Vt(!1),Yt(null)},closeLabel:a("common.back"),wrap:At,onToggleWrap:ee?To:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,walkthroughs:Nf,onWalkthroughNavigate:Mf,initialDetailScrollTop:Me&&Ve?yn[Ve]:void 0,onDetailScrollPositionChange:If,externalSwiperRef:ee?Js:void 0,onMobileSlideChange:ee?eo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain px-2 py-2",children:vc||(Nt?e.jsx(ps,{slow:Gs}):En?e.jsx(La,{message:En,onRetry:()=>{ss()}}):gd(ne)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):ne?.available===!1?e.jsx(La,{message:ne.error??a("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{ss()}}):v?e.jsx(ps,{slow:Gs}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}))})}),e.jsx(ti,{active:_n,children:ee?e.jsxs(kd,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{wr.current=r,r.slideTo(Vi,0)},onSlideChange:r=>{if(xr(r.activeIndex),ns.current===r.activeIndex){ns.current=null;return}r.activeIndex===0&&(br(!1),yt(null),u?.())},children:[e.jsx(fi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Ln,onScroll:kl,onDragOver:ea,onDragEnter:ea,onDragLeave:Rl,onDrop:Cl,className:"h-full overflow-y-auto overscroll-contain bg-surface relative",children:[el&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:a("rightSidebar.dropToUpload")})}),!B.trim()&&wc,e.jsx(Tc,{rootPath:ge??"",onFileSelect:os,onPathReference:Ur,getReferenceText:ra,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onDirectoryRoot:Il,onSearchFromDirectory:_l,onDirectoryPinToggle:Dl,onFilePinToggle:Fl,pinnedPaths:dn,selectedFilePath:Ge,query:ce,searchRootPath:gl,searchOptions:bl,searchMode:$,onContentMatchSelect:Sl,onDirectoryDropFiles:(r,i)=>is(i,r),revealDirectory:Y,canOpenInFileBrowser:tl,onOpenInFileBrowser:jl})]})}),e.jsx(fi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Li,{filePath:_n&&(Wu||Vi===1)?Ge:null,onInsertReference:Ur,onInsertText:jr,onInsertFeature:jr,onReviewReference:Ll,onReferenceCopied:Sr,onClose:Wf,onDirectoryLinkOpen:yc,isMobile:!0,lineRange:Gr,onLineRangeChange:yt,insertedReferenceKey:K,copiedReferenceKey:Re,scrollToLine:Cr,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Ln,onScroll:kl,onDragOver:ea,onDragEnter:ea,onDragLeave:Rl,onDrop:Cl,className:"shrink-0 overflow-y-auto overscroll-contain bg-surface relative",style:{width:lo},children:[el&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:a("rightSidebar.dropToUpload")})}),!B.trim()&&wc,e.jsx(Tc,{rootPath:ge??"",onFileSelect:os,onPathReference:Ur,getReferenceText:ra,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onDirectoryRoot:Il,onSearchFromDirectory:_l,onDirectoryPinToggle:Dl,onFilePinToggle:Fl,pinnedPaths:dn,selectedFilePath:Ge,query:ce,searchRootPath:gl,searchOptions:bl,searchMode:$,onContentMatchSelect:Sl,onDirectoryDropFiles:(r,i)=>is(i,r),revealDirectory:Y,canOpenInFileBrowser:tl,onOpenInFileBrowser:jl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":a("rightSidebar.resizeFileTree"),title:a("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:ef,onPointerMove:tf,onPointerUp:wl,onPointerCancel:wl,onDoubleClick:()=>{co(yi),gt(bs,yi)},children:e.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Li,{filePath:_n?Ge:null,onInsertReference:Ur,onInsertText:jr,onInsertFeature:jr,onReviewReference:Ll,onReferenceCopied:Sr,onDirectoryLinkOpen:yc,isMobile:!1,lineRange:Gr,onLineRangeChange:yt,insertedReferenceKey:K,copiedReferenceKey:Re,scrollToLine:Cr,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D})})]})}),e.jsx(ti,{active:ct,mounted:Gu||ct,children:()=>ee?e.jsx(hi,{mobile:!0,backLabel:a("rightSidebar.backToChangeList"),externalSwiperRef:Js,onMobileSlideChange:eo,groups:_t.length>0?tc():[],mode:wt,onModeChange:pa,selectedKey:Ge,scrollToKey:ac,scrollToKeyNonce:Hs.nonce,compact:!1,collapsedDirectoryKeys:dr,onToggleDirectory:lc,onSelectFile:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);i&&ma(dt(i))},renderLeading:nc,renderTrailing:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Zl(i):null},renderDirectoryTrailing:ec,renderSubtitle:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Jl(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>v&&e.jsxs("div",{className:"px-0 py-0",children:[va&&e.jsx("div",{className:"mb-2",children:va}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[_t.length,"/",ye.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Yl(),r,d&&Mo(),Sc,kc]}),jt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:jt.label}),jt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:jt.branch})]}),!jt&&hn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:oa?(r=>ic(r)):void 0,emptyContent:Nt&&ye.size===0&&Ir===null?e.jsx(ps,{slow:Gs}):En&&ye.size===0?e.jsx(La,{message:En,onRetry:()=>{ss()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):_t.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>as(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.backToChangeList"),children:[e.jsx(ks,{size:14}),a("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[d&&Mo(),e.jsxs("button",{type:"button",onClick:To,"aria-pressed":At,title:a("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:rc(),activePane:ct,wrap:At,showScrollHint:!At,diffViewType:Xu,inlineMode:qn,diffOptions:fc,reloadKey:ur,renderStreamBadge:r=>e.jsx(ys,{status:r}),onHunkGitAction:mc,onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,onDetailScroll:ca}):e.jsx(hi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:a("rightSidebar.backToChangeList"),groups:_t.length>0?tc():[],mode:wt,onModeChange:pa,selectedKey:Ge,scrollToKey:ac,scrollToKeyNonce:Hs.nonce,compact:!0,collapsedDirectoryKeys:dr,onToggleDirectory:lc,onSelectFile:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);i&&ma(dt(i))},renderLeading:nc,renderTrailing:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Zl(i):null},renderDirectoryTrailing:ec,renderSubtitle:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Jl(i):null},aiContent:oa?(r=>ic(r)):void 0,emptyContent:Nt&&ye.size===0&&Ir===null?e.jsx(ps,{slow:Gs}):En&&ye.size===0?e.jsx(La,{message:En,onRetry:()=>{ss()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):_t.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>v&&e.jsxs("div",{className:"px-0 py-0",children:[va&&e.jsx("div",{className:"mb-2",children:va}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[_t.length,"/",ye.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Yl(),r,Mo(),Sc,kc]}),jt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:jt.label}),jt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:jt.branch}),e.jsx("button",{type:"button",onClick:()=>ba("stage-all",jt.root,jt.label),disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>ba("stash-all",jt.root,jt.label),disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}),!jt&&hn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),files:rc(),activePane:ct,wrap:At,showScrollHint:!At,diffViewType:Kt,inlineMode:qn,diffOptions:fc,reloadKey:ur,renderStreamBadge:r=>e.jsx(ys,{status:r}),onHunkGitAction:mc,onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,onDetailScroll:ca})})]}),t&&Ke&&e.jsx(Gm,{value:vt,collapsed:ft,autoCollapseAfterSend:Gt,focusRequest:Wr,insertError:Gn?a("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{Ot(!1),Ft(r)},onCollapsedChange:ir,onAutoCollapseAfterSendChange:gn,onDisable:()=>pn(!1),onClear:()=>Ft(""),onInsert:()=>Al(!1),onInsertAndSend:()=>Al(!0),labels:{title:a("rightSidebar.contextDraftTitle"),hint:a("rightSidebar.contextDraftHint"),placeholder:a("rightSidebar.contextDraftPlaceholder"),collapse:a("rightSidebar.contextDraftCollapse"),expand:a("rightSidebar.contextDraftExpand"),disable:a("rightSidebar.contextDraftDisable"),clear:a("rightSidebar.contextDraftClear"),insert:a("rightSidebar.contextDraftInsert"),insertAndSend:a("rightSidebar.contextDraftInsertAndSend"),inserted:a("rightSidebar.contextDraftInserted"),sent:a("rightSidebar.contextDraftSent"),send:a("rightSidebar.contextDraftSend"),appended:a("rightSidebar.contextDraftAppended"),resize:a("rightSidebar.contextDraftResize"),autoCollapseAfterSend:a("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>a("rightSidebar.contextDraftCharacterCount",{count:r})}}),bf(),it&&typeof document<"u"&&zr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Tr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:it.kind==="restore"?a("rightSidebar.confirmRestoreTitle"):a("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:it.kind==="restore"?a("rightSidebar.confirmRestoreDescription",{path:vd(it.file.absolutePath,v)}):a("rightSidebar.confirmStashAllDescription")}),it.kind==="restore"&&e.jsx("input",{value:it.phrase,onChange:r=>Tr({...it,phrase:r.target.value}),placeholder:a("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Tr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:a("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ae||it.kind==="restore"&&it.phrase.trim()!==a("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(it.kind==="restore"){const r=pt(it.file,v);if(!r)return;at({action:"restore-worktree-file",cwd:r,paths:[it.file.path],confirm:{acknowledged:!0,phrase:it.phrase}},a("rightSidebar.restoreFile"),ai(it.file))}else{const r=it.repoRoot??v;if(!r)return;at({action:"stash-all",cwd:r},a("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${it.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:a(Ae?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const mb=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Li,MarkdownImageLightbox:Eu,MarkdownPreview:Lu,RightSidebar:rb,__testParseMarkdownListBlock:vg,buildMarkdownPreviewBlocks:Eg,buildMarkdownPreviewRenderResult:Bi,computeMarkdownImageDisplayBox:hu,getMarkdownHeadingOutline:$u,getMarkdownHeadingPathAtLine:Mu,getNextMarkdownPreviewLineRange:_g,isSvgImageSrc:qa,mountRightSidebarRepoPickerOverlay:Ud,replaceGitRepositorySnapshot:Du,resolveMarkdownLocalLinkTarget:fu,resolveRightSidebarDiffViewType:Zd,shouldCloseMarkdownImageLightboxDrag:Ru},Symbol.toStringTag,{value:"Module"}));export{mi as E,Ic as H,om as M,mb as R,Zh as a,lm as b,km as c,hb as m};
|
|
1678
|
+
`),truncated:i.some(O=>O.truncated)};if((b.hunks??[]).length===0){be(a("rightSidebar.branchAuditDiffEmpty"));return}const x=Date.now(),C=["preview",b.repoRoot??v,b.baseRef??b.baseBranch??"",b.currentBranch??"",b.headRef??"",b.diffFingerprint??x].join("\0"),I=Wt.length===1?Wt[0].label:`${Wt.length} repos`;Yt(b),Yn(O=>[{key:C,diff:b,repoLabel:I,createdAt:x},...O.filter(q=>q.key!==C)].slice(0,8)),wn(O=>O[C]===void 0?O:{...O,[C]:0}),Zr(C),en(b.hunks?.[0]?`${b.hunks[0].filePath}\0${b.hunks[0].hunkHeader}\0${b.hunks[0].hunkIndex}`:null),Vt(!0)}catch(i){if(!Ce(r)||or(i))return;be(i instanceof Error?i.message:"Failed to load branch diff")}finally{Ce(r)&&H(!1)}},[Pr,Wt,St,gr,Ce,v,a]),Lf=o.useCallback(r=>{Yt(r.diff),be(null),Zr(r.key),en(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),Vt(!0)},[]),Af=o.useCallback(r=>{Yn(i=>i.filter(f=>f.key!==r)),wn(i=>{if(!(r in i))return i;const f={...i};return delete f[r],f}),Ve===r&&(Zr(null),Yt(null),Vt(!1))},[Ve]),Pf=o.useCallback(r=>{const i=Bn.find(f=>f.key===r);i&&(Yt(null),be(null),Zr(r),en(i.records[0]?.filePath??null),Vt(!0))},[Bn]),Tf=o.useCallback(async r=>{if(!v||!we)return;const[i]=r.split(/\s+/);if(i){Ie(i),st(null),$e(null);try{const f=await yh({cwd:v,repoRoot:we,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!f.available){st(f.error??"Commit diff is unavailable");return}$e(f);const b=f.hunks?.[0];Ps(b?`${b.filePath}\0${b.hunkHeader}\0${b.hunkIndex}`:null)}catch(f){st(f instanceof Error?f.message:"Failed to load commit diff")}finally{Ie(null)}}},[we,v]),If=o.useCallback(r=>{if(!Me||!Ve)return;const i=Math.max(0,Math.round(r));wn(f=>Math.abs((f[Ve]??0)-i)<24?f:{...f,[Ve]:i})},[Me,Ve]);o.useEffect(()=>{!ee||!mr||!Me||as(1)},[mr,Me,ee,as]);const sc=o.useCallback(r=>{r&&Yu(i=>Vh(i,r))},[]),ac=Hs.key===Ge?Hs.key:null,ma=o.useCallback(r=>{const i=oe.getState(),f=eb();Aa("select_diff_file",{interactionId:f,path:r,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ue,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),Qe(r),sn("diff"),ee&&r&&as(1),sc(r),queueMicrotask(()=>{const b=oe.getState();Aa("select_diff_file_after",{interactionId:f,requestedPath:r,selectedFilePath:b.selectedFilePath,rootPath:b.rootPath,rightTab:b.rightTab,changedFiles:b.changedFiles.size,activeGitRepoRoot:ue})})},[ue,ee,sc,Qe,sn,as]),oc=o.useCallback(r=>{const i=Array.from(ye.values()).find(f=>{const b=pt(f,v),x=dt(f);return f.path===r.filePath||x===r.filePath||f.absolutePath===r.filePath||(b?`${b}/${f.path}`===r.filePath:!1)||r.repoRoot&&b===r.repoRoot&&f.path===r.filePath});if(i){ma(dt(i)),window.setTimeout(()=>mn(r),90),window.setTimeout(()=>mn(r),320),window.setTimeout(()=>mn(r),760);return}mn(r)},[ye,v,ma]),ic=o.useCallback(({slideToDetail:r,fullscreen:i,toggleFullscreen:f}={})=>Kn.length>0?e.jsx(jd,{walkthroughs:Kn,repoRoot:ue,fullscreen:i,onToggleFullscreen:f,onNavigate:b=>{ee&&window.requestAnimationFrame(()=>r?.()),oc(b)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(Rs,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),a("rightSidebar.changeWalkthroughEmpty")]}),[ue,Kn,oc,ee,a]),_f=o.useCallback(r=>{r&&Nr(i=>{const f=new Set(i);return f.has(r)?f.delete(r):f.add(r),Jo(qo,f),f})},[]),lc=o.useCallback(r=>{Va(i=>{const f=new Set(i);return f.has(r)?f.delete(r):f.add(r),Jo(qc,f),f})},[]),pa=o.useCallback(r=>{Es(r),gt(zd,r)},[]);o.useEffect(()=>{oa||wt!=="ai"||pa("tree")},[wt,pa,oa]);const Io=o.useCallback(()=>{Ls(r=>{const i=!r;return gt(Wd,i),i})},[]),cc=o.useCallback(r=>{qr(r),gt(Gd,r)},[]),{whitespace:dc,context:uc}=Xh(),fc=o.useMemo(()=>({algorithm:"histogram",whitespace:dc,context:uc}),[dc,uc]),hc=o.useCallback(r=>{F(r),gt(qd,r)},[]),ga=o.useCallback(async(r,i,f,b)=>{let x=r;for(;x.ok&&x.status==="running";)await new Promise(I=>window.setTimeout(I,1500)),x=await Ec({jobId:x.jobId,cwd:i.cwd,action:i.action});if(!x.ok)throw new Error("Git action status is unavailable");if(x.status==="error")throw new Error(x.error||x.message||"Git action failed");const C={action:i.action,path:b,label:f};return Zn(C),window.setTimeout(()=>Zn(I=>I?.action===C.action&&I.path===C.path?null:I),1400),x},[]),at=o.useCallback(async(r,i,f)=>{const b=v;v&&Dr.current.delete(v),lt(null),Zn(null),Qn({action:r.action,path:f});try{const x=await wh(r),C=await ga(x,r,i,f);if(!Ce(b))return!1;const I=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>C.bundle):C.bundle;return Ce(b)?(I&&Or(I,{reloadDiff:!0,cacheOnly:!0}),Tr(null),!0):!1}catch(x){return Zn(null),lt(a("rightSidebar.gitActionFailed",{message:x instanceof Error?x.message:"Unknown error"})),!1}finally{Ce(b)&&Qn(null)}},[Or,Ce,v,a,ga]),mc=o.useCallback(async r=>{const i=v,f=await kh(r);if(!Ce(i))return;const b=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>f.bundle):f.bundle;Ce(i)&&b&&Or(b,{reloadDiff:!0,cacheOnly:!0})},[Or,Ce,v]),ba=o.useCallback((r,i,f)=>{if(i){if(r==="stage-all"){at({action:"stage-all",cwd:i},a("rightSidebar.stageAll"),`repo:${i}`);return}Tr({kind:"stash-all",repoRoot:i,repoLabel:f})}},[at,a]),pc=o.useCallback(r=>{qe(r),Xo(v,r),so(""),ao(""),oo(""),Qe(Hl(r)),We||sn("diff")},[Hl,We,v,Qe,sn]),Df=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=es.trim();!r||r===fe?.branch||await at({action:"switch-branch",cwd:we,branch:r},a("rightSidebar.switchBranch"))},[fe?.branch,we,He,at,es,a]),gc=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=Bs.trim();if(!r)return;await at({action:"commit",cwd:we,message:r},a("rightSidebar.commitChanges"))&&Zi("")},[we,Bs,He,at,a]),Ff=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=rn.trim(),i=nn.trim();await at({action:"push",cwd:we,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pushChanges"))},[we,nn,rn,He,at,a]),Bf=o.useCallback(async()=>{if(!we||He){lt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=rn.trim(),i=nn.trim();await at({action:"pull",cwd:we,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pullChanges"))},[we,nn,rn,He,at,a]);o.useEffect(()=>{if(!We||!we||Ae)return;let r=!1;const i={push:a("rightSidebar.pushChanges"),pull:a("rightSidebar.pullChanges"),commit:a("rightSidebar.commitChanges"),"switch-branch":a("rightSidebar.switchBranch"),"stage-all":a("rightSidebar.stageAll"),"stash-all":a("rightSidebar.stashAll")};return(async()=>{for(const f of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const b=await Ec({cwd:we,action:f}).catch(()=>null);if(!b?.ok||b.status!=="running")continue;const x={action:f,cwd:we},C=i[f]??f;Qn({action:f});try{const I=await ga(b,x,C);if(r||!Ce(v))return;const O=v?await ya(v,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Hn(v)}).catch(()=>I.bundle):I.bundle;O&&Or(O,{reloadDiff:!0,cacheOnly:!0})}catch(I){r||lt(a("rightSidebar.gitActionFailed",{message:I instanceof Error?I.message:"Unknown error"}))}finally{r||Qn(null)}return}})(),()=>{r=!0}},[we,Or,We,Ce,v,Ae,a,ga]);const _o=Rn?.action==="commit",Do=Rn?.action==="switch-branch",Fo=Rn?.action==="pull",Bo=Rn?.action==="push",xa=We||Ku,Oo=la?a("rightSidebar.changeAuditScopeAll"):ar.length===1?ar[0].label:`${ar.length} repos`,Of=ar.length>0,bc=Wt.length>0,Uf=v?e.jsx(dd,{open:Ja,onOpenChange:Qa,showScopePicker:!0,selectedAll:la,repos:It,selectedRoots:ia,onToggleRepo:Rf,onGenerate:()=>$f(Ao?"regenerate":"generate"),disabled:!Of,generateDisabled:!bc,inserted:K?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:a(Ao?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.branchAuditGenerateTitle"),ariaLabel:a("rightSidebar.branchAuditShort"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:Oo,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a(Ao?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ef()},secondaryDisabled:!bc||P,secondaryLabel:a("rightSidebar.branchAuditViewDiff"),secondaryTitle:a("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:P,loading:Ki.size>0,statusTitle:Ki.size>0?a("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:a("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:a("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Pr,onChange:r=>qi(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),ql.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:a("rightSidebar.missingBaseReposSkipped",{repositories:ql.map(r=>r.label).join(k==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const i=ht.get(r.root),f=[],b=new Set,x=(q,Ne)=>{!q||b.has(q)||(b.add(q),f.push({value:q,label:q,meta:Ne}))};x(gr[r.root]||i?.context?.branch,a("rightSidebar.pushCurrentBranchBadge"));for(const q of i?.context?.branches??[])x(q,q===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):a("rightSidebar.localBranch"));for(const q of i?.context?.remoteBranches??[])x(q,a("rightSidebar.remoteBranch"));const C=[],I=new Set,O=(q,Ne)=>{!q||I.has(q)||(I.add(q),C.push({value:q,label:q,meta:Ne}))};O(St[r.root],St[r.root]?a("rightSidebar.pushUpstreamBadge"):void 0),O(i?.context?.upstream,i?.context?.upstream?a("rightSidebar.pushUpstreamBadge"):void 0);for(const q of i?.context?.remoteBranches??[])O(q,"remote");for(const q of i?.context?.branches??[])O(q,q===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Un,{label:a("rightSidebar.currentBranchLabel"),value:gr[r.root]||i?.context?.branch||"",options:f,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),onChange:q=>{Is(Ne=>({...Ne,[r.root]:q}))}}),e.jsx(Un,{label:a("rightSidebar.branchAuditBaseLabel"),value:St[r.root]||"",options:C,placeholder:a("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:a("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:a("rightSidebar.branchAuditBaseEmpty"),onChange:q=>{_s(Ne=>({...Ne,[r.root]:q}))}})]})}}):null,xc=gs(kt.reduce((r,i)=>Math.max(r,i.injectedAt??0),0),k),Hf=v?e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>Wi(r=>{const i=!r;return gt(Ko,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Jn,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Rs,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:Oo})]}),e.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Jn?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]}),Jn&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[a("rightSidebar.changeAuditScopeLabel"),": ",Oo]}),Uf]}),le&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:le}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Xr.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ve===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Lf(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:a("rightSidebar.branchAuditViewDiff")})]}),gs(r.createdAt,k)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:gs(r.createdAt,k)})]}),e.jsx("button",{type:"button",onClick:()=>Af(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("common.delete"),"aria-label":a("common.delete"),children:e.jsx(Pa,{size:12})})]},r.key)),Bn.length>0?Bn.slice(0,Math.max(0,8-Xr.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ve===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Pf(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),gs(r.latestInjectedAt,k)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:a("rightSidebar.branchAuditGeneratedAt",{time:gs(r.latestInjectedAt,k)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Sf(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("rightSidebar.branchAuditClearTitle"),"aria-label":a("rightSidebar.branchAuditClearTitle"),children:e.jsx(Pa,{size:12})})]},r.key)):Xr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,vc=rr&&v&&Fn?e.jsxs("div",{className:xa?"overflow-visible":"overflow-hidden",children:[Hf,e.jsxs("button",{type:"button",onClick:()=>{We||Vu(r=>{const i=!r;return i&&we&&!Fn&&!tn&&vo(we),i})},"aria-expanded":xa,className:`group flex w-full items-center gap-2 px-1 py-1.5 text-left transition ${We?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Rr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex min-w-[4.5rem] items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${fn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[tn&&e.jsx(nt,{size:10,className:"animate-spin"}),fn.staged>0?a("rightSidebar.stagedCount",{count:fn.staged}):a("rightSidebar.noStagedChangesShort")]}),!We&&e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${xa?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]})]}),xa&&e.jsxs("div",{className:"space-y-0",children:[mt.length>1&&e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:cf})]})}),e.jsx(Un,{label:a("rightSidebar.gitRepositoryLabel"),value:we??"",options:mt,placeholder:a("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:a("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:a("rightSidebar.gitRepositoryEmpty"),disabled:!!Ae,onChange:r=>{pc(r||null)}}),He&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:a("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:df})]}),e.jsxs("button",{type:"button",onClick:()=>{Df()},disabled:!yf,className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Do?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ae?.action==="switch-branch"||Do?"opacity-0":"",children:a("rightSidebar.switchBranch")}),Ae?.action==="switch-branch"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Do&&Ae?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Un,{label:a("rightSidebar.currentBranchLabel"),value:es,options:hf,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),disabled:!!Ae,onChange:so})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:He?a("rightSidebar.selectRepositoryForGitActions"):fn.staged>0?a("rightSidebar.commitReadyHint",{count:fn.staged}):a("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{gc()},disabled:!!Ae||He||fn.staged===0||!Bs.trim(),className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition active:scale-95 ${_o?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:He?a("rightSidebar.selectRepositoryForGitActions"):fn.staged===0?a("rightSidebar.commitNeedsStaged"):a("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ae?.action==="commit"||_o?"opacity-0":"",children:a("rightSidebar.commitChanges")}),Ae?.action==="commit"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),_o&&Ae?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Bs,onChange:r=>Zi(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),gc())},placeholder:a("rightSidebar.commitMessagePlaceholder"),disabled:!!Ae,className:"w-full rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-[12px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary/35 focus:ring-1 focus:ring-primary/25 disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>pr(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Xt,children:[e.jsx("span",{className:"min-w-0 text-[11px] font-semibold text-foreground",children:a("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Sn&&e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Xt?"rotate-90":""}`,children:e.jsx(wa,{size:13})})]})]}),Xt&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:12,className:"shrink-0"}),e.jsx("input",{value:kn,onChange:r=>Jr(r.target.value),placeholder:a("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),kn&&e.jsx("button",{type:"button",onClick:()=>Jr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Dt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:uf,children:[Jt.length>0?Jt.map(r=>{const[i,...f]=r.split(/\s+/),b=f.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{Tf(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:b,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:b,children:b}),Ue===i&&e.jsx(nt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):Sn?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:a("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.recentCommitsEmpty")}),Q&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(nt,{size:12,className:"animate-spin"})}),Xa&&!Q&&Jt.length>0&&e.jsx("button",{type:"button",onClick:()=>{cs({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:a("rightSidebar.recentCommitsLoadMore")})]})]}),tt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:tt}),Zt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Zt})]}),e.jsxs("div",{className:"px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Bf()},disabled:!xf,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Fo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ae?.action==="pull"||Fo?"opacity-0":"",children:a("rightSidebar.pullChanges")}),Ae?.action==="pull"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Fo&&Ae?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Ff()},disabled:!vf,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Bo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ae?.action==="push"||Bo?"opacity-0":"",children:a("rightSidebar.pushChanges")}),Ae?.action==="push"&&e.jsx(nt,{size:12,className:"absolute animate-spin"}),Bo&&Ae?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${Vl.className}`,title:fe?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:Vl.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:fe?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${Gl?"grid-cols-2":"grid-cols-1"}`,children:[Gl&&e.jsx(Un,{label:a("rightSidebar.pushRemoteLabel"),value:rn,options:Wl,placeholder:a("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:a("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:a("rightSidebar.pushNoRemotes"),disabled:!!Ae,onChange:ao}),e.jsx(Un,{label:a("rightSidebar.pushBranchLabel"),value:nn,options:mf,placeholder:a("rightSidebar.pushBranchPlaceholder",{branch:fe?.branch??"HEAD"}),searchPlaceholder:a("rightSidebar.pushBranchSearchPlaceholder"),emptyText:a("rightSidebar.pushNoBranches"),disabled:!!Ae,onChange:oo})]})]})]})]}):null,zf=o.useCallback(r=>{const i=pt(r,v);if(!i)return[];const f=oi(r),b=[];return r.canStage&&b.push({key:"stage-file",label:a("rightSidebar.stageFile"),onClick:()=>{at({action:"stage-file",cwd:i,paths:[r.path]},a("rightSidebar.stageFile"),f)}}),r.canUnstage&&b.push({key:"unstage-file",label:a("rightSidebar.unstageFile"),onClick:()=>{at({action:"unstage-file",cwd:i,paths:[r.path]},a("rightSidebar.unstageFile"),f)}}),r.canStash&&b.push({key:"stash-file",label:a("rightSidebar.stashFile"),onClick:()=>{at({action:"stash-file",cwd:i,paths:[r.path]},a("rightSidebar.stashFile"),f)}}),r.canRestoreWorktree&&b.push({key:"restore-worktree-file",label:a("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Tr({kind:"restore",file:r,phrase:""})}),b},[v,at,a]),Wf=o.useCallback(()=>{if(m){u?.();return}xr(0),wr.current?.slideTo(0),br(!1),yt(null)},[u,m]),yc=o.useCallback(r=>{if(j(""),Tt(r),Qe(null),yt(null),re(null),ee){m&&u?.(),xr(0),wr.current?.slideTo(0),br(!1);return}},[ee,u,m,Qe,Tt]);o.useEffect(()=>{const r=i=>{const f=i.detail,b=f?.path;if(typeof b!="string"||!b.startsWith("/"))return;j(""),yt(null);const x=!!(v&&(b===v||b.startsWith(`${v}/`)));if(f.kind==="file"){const C=ni(b);os(b),Tt(x?null:C),re(I=>({path:b,nonce:(I?.nonce??0)+1}));return}Qe(null),x?(Tt(null),re(C=>({path:b,nonce:(C?.nonce??0)+1}))):(re(null),Tt(b)),ee&&(m&&u?.(),xr(0),wr.current?.slideTo(0),br(!1))};return window.addEventListener(Ac,r),()=>window.removeEventListener(Ac,r)},[os,ee,u,m,v,Qe,Tt]),o.useEffect(()=>{t||(Lt(!1),Bt(!1))},[t]),o.useEffect(()=>{if(!qt&&!cr)return;const r=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&($s.current?.contains(i.target)||bn.current?.contains(i.target))||(Lt(!1),Bt(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[cr,qt]);const wc=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:af,disabled:!na,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.parentFolder"),title:a("rightSidebar.parentFolder"),children:e.jsx(yd,{size:14})}),e.jsx("button",{type:"button",onClick:Tl,disabled:!v||Mn===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.backToProjectRoot"),title:a("rightSidebar.backToProjectRoot"),children:e.jsx(Ic,{size:14})}),e.jsx("button",{type:"button",onClick:of,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.refreshFiles"),title:el?a("rightSidebar.fileWatchUnavailable",{message:el}):a("rightSidebar.refreshFiles"),children:e.jsx(fi,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:nf}),qs==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:a("fileTree.sortedByModified"),"aria-label":a("fileTree.sortedByModified"),children:e.jsx(Pc,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&Ur(ge,$t??void 0),disabled:!ge,...ge&&$t?ko(ra(ge),$t):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${$t&&(K===$t||Re===$t)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":a($t&&Re===$t?"rightSidebar.copied":$t&&K===$t?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:a("rightSidebar.insertCurrentFolder"),children:$t&&(K===$t||Re===$t)?e.jsx(di,{size:13}):e.jsx(Da,{size:13})}),e.jsxs("div",{ref:bn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Lt(!1),Bt(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${cr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":cr,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(ui,{size:14})}),cr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Bt(!1),lf()},disabled:!Ro,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${ls?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ls?e.jsx(zo,{size:14}):e.jsx(Sa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(ls?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Bt(!1),Ju()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${fo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[fo?e.jsx(em,{size:14}):e.jsx(pi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(fo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(Bt(!1),Qu(ge,qs==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[qs==="modified"?e.jsx(Oh,{size:14}):e.jsx(Pc,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(qs==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),v&&(sa.length>0||sf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Tl,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-full px-2 py-0.5 font-medium transition active:scale-95 ${ge===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(Ic,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Ye})]}),sa.map(r=>{const i=r.path,f=r.kind==="file",b=f?Ge===i:ge===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-full transition ${b?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>f?os(i):Tt(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[f?e.jsx(gi,{size:10,className:"shrink-0"}):e.jsx(Sa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ut(i)})]}),e.jsx("button",{type:"button",onClick:()=>an(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.unpinFolder",{name:ut(i)}),title:a("rightSidebar.unpinFolder",{name:ut(i)}),children:e.jsx(Dt,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Uo=o.useMemo(()=>{if(Cn===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((no-Cn)/1e3)),f=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[b,x]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return f.format(b,x)},[no,Cn]),kc=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Uo?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:a("rightSidebar.gitLastUpdated",{time:Uo}),children:Uo}):null,e.jsx("button",{type:"button",onClick:()=>{ss()},disabled:Nt,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":a("rightSidebar.refreshGit"),title:a("rightSidebar.refreshGit"),children:e.jsx(fi,{size:13,className:Nt?"animate-spin":""})})]}):null,Gf=wl?a("rightSidebar.changeAuditScopeAll"):ln.length===1?ln[0].relativeRoot==="."?Ye:ln[0].relativeRoot||ln[0].name:`${ln.length} repos`,Sc=v?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(dd,{open:As,onOpenChange:Lr,showScopePicker:hn,selectedAll:wl,repos:Zu,selectedRoots:zt,onToggleRepo:jf,onGenerate:()=>wf(),disabled:!v,inserted:K===Pl,buttonLabel:a("rightSidebar.changeAuditShort"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:a("rightSidebar.insertChangeAuditPrompt"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:Gf,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a("rightSidebar.changeAuditShort"),loading:Mr,error:!!Er,statusTitle:Er??(Mr?a("rightSidebar.changeAuditLoading"):kt.length>0?`${a("rightSidebar.changeAuditLoaded",{count:kt.length})}${xc?` · ${a("rightSidebar.changeAuditLoadedAt",{time:xc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{kf()},disabled:Mr||kt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${kt.length>0?"":"invisible"}`,title:a("rightSidebar.clearChangeAuditTitle"),"aria-label":a("rightSidebar.clearChangeAudit"),children:e.jsx(Pa,{size:12})})]}):null,va=ye.size>0||ne?.available||Ir?e.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] font-medium",children:[ne?.available&&ne.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:ne.branch,children:[e.jsx(Rr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ne.branch})]}),rt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[rt.modified,"M"]}),rt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",rt.added]}),rt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",rt.deleted]}),rt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[rt.renamed,"R"]}),rt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[rt.copied,"C"]}),rt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[rt.untracked,"U"]}),rt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[rt.conflicted,"!"]}),rt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[rt.other,"?"]}),rt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:a("rightSidebar.stagedCountShort",{count:rt.staged})}),ne?.available&&v&&ye.size>0&&X.length<=1&&e.jsx("button",{type:"button",onClick:()=>{at({action:"stage-all",cwd:v},a("rightSidebar.stageAll"))},disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),ne?.available&&v&&ye.size>0&&X.length<=1&&e.jsx("button",{type:"button",onClick:()=>Tr({kind:"stash-all",repoRoot:v,repoLabel:Ye}),disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}):null;return e.jsxs(Uh,{side:"right",isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:c,pinned:d,children:[ko.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:Ye}),(!ee||to)&&ne?.available&&ne.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:ne.branch,children:[e.jsx(Rr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:ne.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!se;he(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):j("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${se?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleSearch"),title:a("common.search"),children:e.jsx(zn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Ke,onClick:()=>{pn(r=>!r),ir(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Ke?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleContextDraft"),title:a("rightSidebar.contextDraftTitle"),children:[e.jsx(um,{size:14}),!Ke&&vt.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:sl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const i=r.target.files;!i||i.length===0||(is(Array.from(i)),r.target.value="")}}),e.jsx("input",{ref:al,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const i=r.target.files?.[0];r.target.value="",i&&rf(i)}}),h&&e.jsx("button",{type:"button",onClick:h,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${d?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:d?e.jsx(zo,{size:14}):e.jsx(Sa,{size:14})}),e.jsxs("div",{ref:$s,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Bt(!1),Lt(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${qt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":qt,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(ui,{size:15})}),qt&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),sl.current?.click()},disabled:Os,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Os?e.jsx(nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(ym,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),al.current?.click()},disabled:Os,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Os?e.jsx(nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(am,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.insertLocalImage")})]}),h&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Lt(!1),h()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${d?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[d?e.jsx(zo,{size:14}):e.jsx(Sa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(d?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),d&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":a("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:a("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",a("rightSidebar.layoutModeAuto")],["narrow",a("rightSidebar.layoutModeNarrow")],["wide",a("rightSidebar.layoutModeWide")]].map(([r,i])=>{const f=G===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":f,onClick:()=>{J(r),Lt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},r)})})]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":a("rightSidebar.close"),children:e.jsx(Dt,{size:14})})]}),se&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(zn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:B,onChange:r=>j(r.target.value),placeholder:a($==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>hc("name"),"aria-pressed":$==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${$==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>hc("content"),"aria-pressed":$==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${$==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeContent")})]}),B&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Dt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Hh,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:V,onChange:r=>te(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchScopePlaceholder"),"aria-label":a("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),V!=="."&&e.jsx("button",{type:"button",onClick:()=>te("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.resetSearchScope"),children:e.jsx(Dt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>je(r=>!r),"aria-expanded":pe,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${pe||ts.length>0||N||de||ze?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:a("rightSidebar.searchOptions"),"aria-label":a("rightSidebar.searchOptions"),children:[e.jsx(zh,{size:13}),ts.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 min-w-4 rounded-full bg-primary px-1 text-[8px] font-bold leading-4 text-primary-foreground",children:ts.length})]})]}),pe&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ie,onChange:r=>me(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchExcludePlaceholder"),"aria-label":a("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ie&&e.jsx("button",{type:"button",onClick:()=>me(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.clearSearchExclude"),children:e.jsx(Dt,{size:11})})]}),$==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":a("rightSidebar.contentSearchOptions"),children:[[N,()=>Z(r=>!r),Qh,a("rightSidebar.matchCase")],[de,()=>Ee(r=>!r),km,a("rightSidebar.matchWholeWord")],[ze,()=>Pe(r=>!r),hm,a("rightSidebar.useRegex")]].map(([r,i,f,b])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(f,{size:12}),b]},b))})]})]}),Zs?null:e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>sn("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Rr,{size:12}),a("rightSidebar.tabGit"),Nt&&kr==="git"?e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}):null]}),e.jsxs("button",{type:"button",onClick:()=>sn("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Ed,{size:12}),a("rightSidebar.tabChanges"),Nt?e.jsx(nt,{size:12,className:"animate-spin text-muted-foreground"}):ye.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:ye.size}):null]}),e.jsxs("button",{type:"button",onClick:()=>sn("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${kr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(qh,{size:12}),a("rightSidebar.tabFiles")]})]}),e.jsx("div",{className:"h-2"}),Ji&&e.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:Ji})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(ri,{active:We,mounted:rr,fallback:e.jsx(ps,{slow:!1}),children:Fe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Bc,{items:Cf,selectedKey:zu,onSelect:Ps,emptyText:a("rightSidebar.noChanges"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a("rightSidebar.recentCommitsTitle"),headerMeta:`${Fe.headRef??""}${Fe.commits?.[0]?` · ${Fe.commits[0]}`:""}`,onClose:()=>{$e(null),Ps(null)},closeLabel:a("common.back"),wrap:At,onToggleWrap:ee?Io:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa})}):mr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Bc,{items:Lo,selectedKey:Za,onSelect:en,emptyText:a(Me?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a(Me?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:ha?`${ha.repoLabel} · ${ha.branchName??"HEAD"} → ${ha.baseRef}`:void 0,onClose:()=>{Vt(!1),Yt(null)},closeLabel:a("common.back"),wrap:At,onToggleWrap:ee?Io:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,walkthroughs:Nf,onWalkthroughNavigate:Mf,initialDetailScrollTop:Me&&Ve?yn[Ve]:void 0,onDetailScrollPositionChange:If,externalSwiperRef:ee?Js:void 0,onMobileSlideChange:ee?eo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain px-2 py-2",children:vc||(Nt?e.jsx(ps,{slow:Gs}):En?e.jsx(La,{message:En,onRetry:()=>{ss()}}):gd(ne)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):ne?.available===!1?e.jsx(La,{message:ne.error??a("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{ss()}}):v?e.jsx(ps,{slow:Gs}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}))})}),e.jsx(ri,{active:_n,children:ee?e.jsxs(kd,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{wr.current=r,r.slideTo(Yi,0)},onSlideChange:r=>{if(xr(r.activeIndex),ns.current===r.activeIndex){ns.current=null;return}r.activeIndex===0&&(br(!1),yt(null),u?.())},children:[e.jsx(hi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Ln,onScroll:Sl,onDragOver:ea,onDragEnter:ea,onDragLeave:Cl,onDrop:Nl,className:"h-full overflow-y-auto overscroll-contain bg-surface relative",children:[tl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:a("rightSidebar.dropToUpload")})}),!B.trim()&&wc,e.jsx(Tc,{rootPath:ge??"",onFileSelect:os,onPathReference:Ur,getReferenceText:ra,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onDirectoryRoot:Il,onSearchFromDirectory:_l,onDirectoryPinToggle:Dl,onFilePinToggle:Fl,pinnedPaths:dn,selectedFilePath:Ge,query:ce,searchRootPath:bl,searchOptions:xl,searchMode:$,onContentMatchSelect:jl,onDirectoryDropFiles:(r,i)=>is(i,r),revealDirectory:Y,canOpenInFileBrowser:rl,onOpenInFileBrowser:Rl})]})}),e.jsx(hi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Ai,{filePath:_n&&(Wu||Yi===1)?Ge:null,onInsertReference:Ur,onInsertText:jr,onInsertFeature:jr,onReviewReference:Ll,onReferenceCopied:Sr,onClose:Wf,onDirectoryLinkOpen:yc,isMobile:!0,lineRange:Gr,onLineRangeChange:yt,insertedReferenceKey:K,copiedReferenceKey:Re,scrollToLine:Cr,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Ln,onScroll:Sl,onDragOver:ea,onDragEnter:ea,onDragLeave:Cl,onDrop:Nl,className:"shrink-0 overflow-y-auto overscroll-contain bg-surface relative",style:{width:lo},children:[tl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:a("rightSidebar.dropToUpload")})}),!B.trim()&&wc,e.jsx(Tc,{rootPath:ge??"",onFileSelect:os,onPathReference:Ur,getReferenceText:ra,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onDirectoryRoot:Il,onSearchFromDirectory:_l,onDirectoryPinToggle:Dl,onFilePinToggle:Fl,pinnedPaths:dn,selectedFilePath:Ge,query:ce,searchRootPath:bl,searchOptions:xl,searchMode:$,onContentMatchSelect:jl,onDirectoryDropFiles:(r,i)=>is(i,r),revealDirectory:Y,canOpenInFileBrowser:rl,onOpenInFileBrowser:Rl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":a("rightSidebar.resizeFileTree"),title:a("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:ef,onPointerMove:tf,onPointerUp:kl,onPointerCancel:kl,onDoubleClick:()=>{co(wi),gt(bs,wi)},children:e.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Ai,{filePath:_n?Ge:null,onInsertReference:Ur,onInsertText:jr,onInsertFeature:jr,onReviewReference:Ll,onReferenceCopied:Sr,onDirectoryLinkOpen:yc,isMobile:!1,lineRange:Gr,onLineRangeChange:yt,insertedReferenceKey:K,copiedReferenceKey:Re,scrollToLine:Cr,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:R,onCloseMarkdownOutline:M,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:z,onCloseMarkdownImageLightbox:D})})]})}),e.jsx(ri,{active:ct,mounted:Gu||ct,children:()=>ee?e.jsx(mi,{mobile:!0,backLabel:a("rightSidebar.backToChangeList"),externalSwiperRef:Js,onMobileSlideChange:eo,groups:_t.length>0?tc():[],mode:wt,onModeChange:pa,selectedKey:Ge,scrollToKey:ac,scrollToKeyNonce:Hs.nonce,compact:!1,collapsedDirectoryKeys:dr,onToggleDirectory:lc,onSelectFile:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);i&&ma(dt(i))},renderLeading:nc,renderTrailing:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Zl(i):null},renderDirectoryTrailing:ec,renderSubtitle:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Jl(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>v&&e.jsxs("div",{className:"px-0 py-0",children:[va&&e.jsx("div",{className:"mb-2",children:va}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[_t.length,"/",ye.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Yl(),r,d&&$o(),Sc,kc]}),jt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:jt.label}),jt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:jt.branch})]}),!jt&&hn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:oa?(r=>ic(r)):void 0,emptyContent:Nt&&ye.size===0&&Ir===null?e.jsx(ps,{slow:Gs}):En&&ye.size===0?e.jsx(La,{message:En,onRetry:()=>{ss()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):_t.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>as(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.backToChangeList"),children:[e.jsx(ks,{size:14}),a("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[d&&$o(),e.jsxs("button",{type:"button",onClick:Io,"aria-pressed":At,title:a("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:rc(),activePane:ct,wrap:At,showScrollHint:!At,diffViewType:Xu,inlineMode:qn,diffOptions:fc,reloadKey:ur,renderStreamBadge:r=>e.jsx(ys,{status:r}),onHunkGitAction:mc,onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,onDetailScroll:ca}):e.jsx(mi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:a("rightSidebar.backToChangeList"),groups:_t.length>0?tc():[],mode:wt,onModeChange:pa,selectedKey:Ge,scrollToKey:ac,scrollToKeyNonce:Hs.nonce,compact:!0,collapsedDirectoryKeys:dr,onToggleDirectory:lc,onSelectFile:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);i&&ma(dt(i))},renderLeading:nc,renderTrailing:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Zl(i):null},renderDirectoryTrailing:ec,renderSubtitle:r=>{const i=Array.from(ye.values()).find(f=>dt(f)===r.key);return i?Jl(i):null},aiContent:oa?(r=>ic(r)):void 0,emptyContent:Nt&&ye.size===0&&Ir===null?e.jsx(ps,{slow:Gs}):En&&ye.size===0?e.jsx(La,{message:En,onRetry:()=>{ss()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):_t.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>v&&e.jsxs("div",{className:"px-0 py-0",children:[va&&e.jsx("div",{className:"mb-2",children:va}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[_t.length,"/",ye.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Yl(),r,$o(),Sc,kc]}),jt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:jt.label}),jt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:jt.branch}),e.jsx("button",{type:"button",onClick:()=>ba("stage-all",jt.root,jt.label),disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>ba("stash-all",jt.root,jt.label),disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}),!jt&&hn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Rr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),files:rc(),activePane:ct,wrap:At,showScrollHint:!At,diffViewType:Kt,inlineMode:qn,diffOptions:fc,reloadKey:ur,renderStreamBadge:r=>e.jsx(ys,{status:r}),onHunkGitAction:mc,onInsertDiffReference:Hr,onReferenceCopied:Sr,insertedReferenceKey:K,copiedReferenceKey:Re,onClearAuditRecord:fa,onDetailScroll:ca})})]}),t&&Ke&&e.jsx(qm,{value:vt,collapsed:ft,autoCollapseAfterSend:Gt,focusRequest:Wr,insertError:Gn?a("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{Ot(!1),Ft(r)},onCollapsedChange:ir,onAutoCollapseAfterSendChange:gn,onDisable:()=>pn(!1),onClear:()=>Ft(""),onInsert:()=>Al(!1),onInsertAndSend:()=>Al(!0),labels:{title:a("rightSidebar.contextDraftTitle"),hint:a("rightSidebar.contextDraftHint"),placeholder:a("rightSidebar.contextDraftPlaceholder"),collapse:a("rightSidebar.contextDraftCollapse"),expand:a("rightSidebar.contextDraftExpand"),disable:a("rightSidebar.contextDraftDisable"),clear:a("rightSidebar.contextDraftClear"),insert:a("rightSidebar.contextDraftInsert"),insertAndSend:a("rightSidebar.contextDraftInsertAndSend"),inserted:a("rightSidebar.contextDraftInserted"),sent:a("rightSidebar.contextDraftSent"),send:a("rightSidebar.contextDraftSend"),appended:a("rightSidebar.contextDraftAppended"),resize:a("rightSidebar.contextDraftResize"),autoCollapseAfterSend:a("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>a("rightSidebar.contextDraftCharacterCount",{count:r})}}),bf(),it&&typeof document<"u"&&zr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Tr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:it.kind==="restore"?a("rightSidebar.confirmRestoreTitle"):a("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:it.kind==="restore"?a("rightSidebar.confirmRestoreDescription",{path:vd(it.file.absolutePath,v)}):a("rightSidebar.confirmStashAllDescription")}),it.kind==="restore"&&e.jsx("input",{value:it.phrase,onChange:r=>Tr({...it,phrase:r.target.value}),placeholder:a("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Tr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:a("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ae||it.kind==="restore"&&it.phrase.trim()!==a("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(it.kind==="restore"){const r=pt(it.file,v);if(!r)return;at({action:"restore-worktree-file",cwd:r,paths:[it.file.path],confirm:{acknowledged:!0,phrase:it.phrase}},a("rightSidebar.restoreFile"),oi(it.file))}else{const r=it.repoRoot??v;if(!r)return;at({action:"stash-all",cwd:r},a("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${it.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:a(Ae?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const pb=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Ai,MarkdownImageLightbox:Eu,MarkdownPreview:Lu,RightSidebar:nb,__testParseMarkdownListBlock:yg,buildMarkdownPreviewBlocks:Lg,buildMarkdownPreviewRenderResult:Oi,computeMarkdownImageDisplayBox:hu,getMarkdownHeadingOutline:$u,getMarkdownHeadingPathAtLine:Mu,getNextMarkdownPreviewLineRange:Dg,isSvgImageSrc:qa,mountRightSidebarRepoPickerOverlay:Ud,replaceGitRepositorySnapshot:Du,resolveMarkdownLocalLinkTarget:fu,resolveRightSidebarDiffViewType:Zd,shouldCloseMarkdownImageLightboxDrag:Ru},Symbol.toStringTag,{value:"Module"}));export{pi as E,Ic as H,im as M,pb as R,em as a,cm as b,Sm as c,mb as m};
|