termdock 1.4.294 → 1.4.296
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-BiLjlrk-.js +171 -0
- package/dist/client/assets/App-BiLjlrk-.js.br +0 -0
- package/dist/client/assets/App-BiLjlrk-.js.gz +0 -0
- package/dist/client/assets/{ChangeWalkthroughPanel-D2hm-GX-.js → ChangeWalkthroughPanel-DXprT-7m.js} +1 -1
- package/dist/client/assets/ChangeWalkthroughPanel-DXprT-7m.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-DXprT-7m.js.gz +0 -0
- package/dist/client/assets/{DagPlayground-DLmKJylJ.js → DagPlayground-DZcUunT5.js} +1 -1
- package/dist/client/assets/DagPlayground-DZcUunT5.js.br +0 -0
- package/dist/client/assets/DagPlayground-DZcUunT5.js.gz +0 -0
- package/dist/client/assets/{DiffLab-Bje07ujV.js → DiffLab-Brv4DCTb.js} +1 -1
- package/dist/client/assets/DiffLab-Brv4DCTb.js.br +0 -0
- package/dist/client/assets/DiffLab-Brv4DCTb.js.gz +0 -0
- package/dist/client/assets/{DiffReview-CcLHnQu-.js → DiffReview-BuLu1qCi.js} +1 -1
- package/dist/client/assets/DiffReview-BuLu1qCi.js.br +0 -0
- package/dist/client/assets/DiffReview-BuLu1qCi.js.gz +0 -0
- package/dist/client/assets/{DiffReviewLab-CIieaScN.js → DiffReviewLab-DSGamuAD.js} +1 -1
- package/dist/client/assets/DiffReviewLab-DSGamuAD.js.br +0 -0
- package/dist/client/assets/DiffReviewLab-DSGamuAD.js.gz +0 -0
- package/dist/client/assets/{DiffViewer-0nWShFhC.js → DiffViewer-BUCYxg27.js} +1 -1
- package/dist/client/assets/DiffViewer-BUCYxg27.js.br +0 -0
- package/dist/client/assets/DiffViewer-BUCYxg27.js.gz +0 -0
- package/dist/client/assets/{ModelPreview-B2Hrizox.js → ModelPreview-Bnlo-oVE.js} +1 -1
- package/dist/client/assets/ModelPreview-Bnlo-oVE.js.br +0 -0
- package/dist/client/assets/ModelPreview-Bnlo-oVE.js.gz +0 -0
- package/dist/client/assets/{RightSidebar-CiYxOpjs.js → RightSidebar-r_3Lk5Rp.js} +48 -52
- package/dist/client/assets/RightSidebar-r_3Lk5Rp.js.br +0 -0
- package/dist/client/assets/RightSidebar-r_3Lk5Rp.js.gz +0 -0
- package/dist/client/assets/{abnfDiagram-VCTEODGH-BvhG-Int.js → abnfDiagram-VCTEODGH-K6Ppkrbt.js} +1 -1
- package/dist/client/assets/abnfDiagram-VCTEODGH-K6Ppkrbt.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-K6Ppkrbt.js.gz +0 -0
- package/dist/client/assets/app-CATnTUZF.js +35 -0
- package/dist/client/assets/app-CATnTUZF.js.br +0 -0
- package/dist/client/assets/app-CATnTUZF.js.gz +0 -0
- package/dist/client/assets/{arc-Cfd1r0w4.js → arc-Co2OQqtH.js} +1 -1
- package/dist/client/assets/arc-Co2OQqtH.js.br +0 -0
- package/dist/client/assets/arc-Co2OQqtH.js.gz +0 -0
- package/dist/client/assets/{architectureDiagram-5GKGNRK7-CYcaAY_y.js → architectureDiagram-5GKGNRK7-BQnl7tVF.js} +1 -1
- package/dist/client/assets/architectureDiagram-5GKGNRK7-BQnl7tVF.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-BQnl7tVF.js.gz +0 -0
- package/dist/client/assets/{blockDiagram-I7D4REHJ-uGZowYBC.js → blockDiagram-I7D4REHJ-Bm5D5-qq.js} +1 -1
- package/dist/client/assets/blockDiagram-I7D4REHJ-Bm5D5-qq.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-Bm5D5-qq.js.gz +0 -0
- package/dist/client/assets/{c4Diagram-7LVT6UL2-BuAjHXw2.js → c4Diagram-7LVT6UL2-B9oPpey8.js} +1 -1
- package/dist/client/assets/c4Diagram-7LVT6UL2-B9oPpey8.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-B9oPpey8.js.gz +0 -0
- package/dist/client/assets/channel-Czv2W4qA.js +1 -0
- package/dist/client/assets/{chunk-2Q5K7J3B-DpblcTaf.js → chunk-2Q5K7J3B-TMaWHH0U.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-9DQ9Xhrj.js → chunk-5VM5RSS4-CH7XpknV.js} +1 -1
- package/dist/client/assets/{chunk-F27PBJKO-C99DgtYa.js → chunk-F27PBJKO-CJ1rotBe.js} +1 -1
- package/dist/client/assets/chunk-F27PBJKO-CJ1rotBe.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-CJ1rotBe.js.gz +0 -0
- package/dist/client/assets/{chunk-IMKFNOWR-CJs2LWtE.js → chunk-IMKFNOWR-UYKZ5uOG.js} +1 -1
- package/dist/client/assets/chunk-IMKFNOWR-UYKZ5uOG.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-UYKZ5uOG.js.gz +0 -0
- package/dist/client/assets/{chunk-JWPE2WC7-Bi6NDDYZ.js → chunk-JWPE2WC7-BYL8aXjQ.js} +1 -1
- package/dist/client/assets/{chunk-POPQ4Y6H-EDihZ7ei.js → chunk-POPQ4Y6H-C3E8yfU2.js} +1 -1
- package/dist/client/assets/{chunk-SVP7TREG-Deb_Pzwv.js → chunk-SVP7TREG-DCTDYa1E.js} +1 -1
- package/dist/client/assets/chunk-SVP7TREG-DCTDYa1E.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-DCTDYa1E.js.gz +0 -0
- package/dist/client/assets/{chunk-TICWLB2K-C6wEoKIF.js → chunk-TICWLB2K-wHiaOsBh.js} +1 -1
- package/dist/client/assets/chunk-TICWLB2K-wHiaOsBh.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-wHiaOsBh.js.gz +0 -0
- package/dist/client/assets/{chunk-XXDRQBXY-DkhA8D3i.js → chunk-XXDRQBXY-D_d479hK.js} +1 -1
- package/dist/client/assets/classDiagram-ZZMXUADV-BdvOOL9k.js +1 -0
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-BdvOOL9k.js +1 -0
- package/dist/client/assets/{cose-bilkent-JH36ORCC-CAImJ8rh.js → cose-bilkent-JH36ORCC-DnhlPBLr.js} +1 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-DnhlPBLr.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-DnhlPBLr.js.gz +0 -0
- package/dist/client/assets/{cynefin-OW5HDTMX-D3Egll3y.js → cynefin-OW5HDTMX-BsjzNqJZ.js} +1 -1
- package/dist/client/assets/cynefin-OW5HDTMX-BsjzNqJZ.js.br +0 -0
- package/dist/client/assets/{cynefin-OW5HDTMX-D3Egll3y.js.gz → cynefin-OW5HDTMX-BsjzNqJZ.js.gz} +0 -0
- package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-MjvCZkx7.js → cynefinDiagram-5FMLGOSQ-sVUb0zY5.js} +1 -1
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-sVUb0zY5.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-sVUb0zY5.js.gz +0 -0
- package/dist/client/assets/{dagre-GXQ25YYZ-CrJn07Be.js → dagre-GXQ25YYZ-YErk8S-c.js} +1 -1
- package/dist/client/assets/dagre-GXQ25YYZ-YErk8S-c.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-YErk8S-c.js.gz +0 -0
- package/dist/client/assets/{diagram-S7CK7UJ4-x2YTsmxU.js → diagram-S7CK7UJ4-BaHbV5ho.js} +1 -1
- package/dist/client/assets/diagram-S7CK7UJ4-BaHbV5ho.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-BaHbV5ho.js.gz +0 -0
- package/dist/client/assets/{diagram-UQ7AKVKN-D98MzrbS.js → diagram-UQ7AKVKN-BocCYx3V.js} +1 -1
- package/dist/client/assets/diagram-UQ7AKVKN-BocCYx3V.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-BocCYx3V.js.gz +0 -0
- package/dist/client/assets/{diagram-VSXAHHWV-DB_ACbg-.js → diagram-VSXAHHWV-ZMTYwWOQ.js} +1 -1
- package/dist/client/assets/diagram-VSXAHHWV-ZMTYwWOQ.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-ZMTYwWOQ.js.gz +0 -0
- package/dist/client/assets/{diagram-VX7I27RA-Drt4iWsQ.js → diagram-VX7I27RA-xmk_EY1h.js} +1 -1
- package/dist/client/assets/diagram-VX7I27RA-xmk_EY1h.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-xmk_EY1h.js.gz +0 -0
- package/dist/client/assets/{diagram-Z3DM3KII-D8mGxerZ.js → diagram-Z3DM3KII-DKDY_cG6.js} +1 -1
- package/dist/client/assets/diagram-Z3DM3KII-DKDY_cG6.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-DKDY_cG6.js.gz +0 -0
- package/dist/client/assets/{ebnfDiagram-PWID7BFC-DTYnrl_Q.js → ebnfDiagram-PWID7BFC-C_0z-Jx9.js} +1 -1
- package/dist/client/assets/ebnfDiagram-PWID7BFC-C_0z-Jx9.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-C_0z-Jx9.js.gz +0 -0
- package/dist/client/assets/{erDiagram-RLTQ6QDP-ChsNovQf.js → erDiagram-RLTQ6QDP-DHUaG7mt.js} +1 -1
- package/dist/client/assets/erDiagram-RLTQ6QDP-DHUaG7mt.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-DHUaG7mt.js.gz +0 -0
- package/dist/client/assets/{flowDiagram-HODETNUW-DsFiio6_.js → flowDiagram-HODETNUW-BMNsdMBD.js} +1 -1
- package/dist/client/assets/flowDiagram-HODETNUW-BMNsdMBD.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-BMNsdMBD.js.gz +0 -0
- package/dist/client/assets/{ganttDiagram-EL5Y4UJY-BbHyLMqr.js → ganttDiagram-EL5Y4UJY-BH1AiKuF.js} +1 -1
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-BH1AiKuF.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-BH1AiKuF.js.gz +0 -0
- package/dist/client/assets/{gestureArbiter-3rZyzlwR.js → gestureArbiter-DvupkPra.js} +1 -1
- package/dist/client/assets/gestureArbiter-DvupkPra.js.br +0 -0
- package/dist/client/assets/gestureArbiter-DvupkPra.js.gz +0 -0
- package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-CTPZoYHy.js → gitGraphDiagram-WWUBYQGX-DAgV0MV-.js} +1 -1
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DAgV0MV-.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DAgV0MV-.js.gz +0 -0
- package/dist/client/assets/{index-DxhkHH1u.css → index-Bi9A6QUP.css} +1 -1
- package/dist/client/assets/index-Bi9A6QUP.css.br +0 -0
- package/dist/client/assets/index-Bi9A6QUP.css.gz +0 -0
- package/dist/client/assets/{infoDiagram-27XIBGKW-DqG9-3Dv.js → infoDiagram-27XIBGKW-C7iSg0cB.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-5VMMS53U-C7BUr6Q1.js → ishikawaDiagram-5VMMS53U-BpZwsQvw.js} +1 -1
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-BpZwsQvw.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-BpZwsQvw.js.gz +0 -0
- package/dist/client/assets/{journeyDiagram-3NMN7TZE-DeKgSie7.js → journeyDiagram-3NMN7TZE-DXEeFLvw.js} +1 -1
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DXEeFLvw.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DXEeFLvw.js.gz +0 -0
- package/dist/client/assets/{kanban-definition-UXKFOSKX-BXLMRLCs.js → kanban-definition-UXKFOSKX-CV9ivL5u.js} +1 -1
- package/dist/client/assets/kanban-definition-UXKFOSKX-CV9ivL5u.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-CV9ivL5u.js.gz +0 -0
- package/dist/client/assets/{layout-BIGVsIVB.js → layout-DsKKsJKX.js} +1 -1
- package/dist/client/assets/layout-DsKKsJKX.js.br +0 -0
- package/dist/client/assets/layout-DsKKsJKX.js.gz +0 -0
- package/dist/client/assets/{linear-BhqHS_Ls.js → linear-Dl9MDNV3.js} +1 -1
- package/dist/client/assets/linear-Dl9MDNV3.js.br +0 -0
- package/dist/client/assets/linear-Dl9MDNV3.js.gz +0 -0
- package/dist/client/assets/{mermaid.core-DYTWj2Pu.js → mermaid.core-CxZFe3as.js} +5 -5
- package/dist/client/assets/mermaid.core-CxZFe3as.js.br +0 -0
- package/dist/client/assets/mermaid.core-CxZFe3as.js.gz +0 -0
- package/dist/client/assets/{mindmap-definition-YA3MSWOX-BKVI5pEJ.js → mindmap-definition-YA3MSWOX-C3ormYdL.js} +2 -2
- package/dist/client/assets/mindmap-definition-YA3MSWOX-C3ormYdL.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-C3ormYdL.js.gz +0 -0
- package/dist/client/assets/{passwordBootstrap-DyrBaUP8.js → passwordBootstrap-a8z6jJNY.js} +2 -2
- package/dist/client/assets/passwordBootstrap-a8z6jJNY.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-a8z6jJNY.js.gz +0 -0
- package/dist/client/assets/{pegDiagram-XKGWAZYB-DdRPwDgf.js → pegDiagram-XKGWAZYB-CG0wNylH.js} +1 -1
- package/dist/client/assets/pegDiagram-XKGWAZYB-CG0wNylH.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-CG0wNylH.js.gz +0 -0
- package/dist/client/assets/{pieDiagram-E7YTZNPT-KzblsFOl.js → pieDiagram-E7YTZNPT-D2-ydqyX.js} +1 -1
- package/dist/client/assets/pieDiagram-E7YTZNPT-D2-ydqyX.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-D2-ydqyX.js.gz +0 -0
- package/dist/client/assets/{quadrantDiagram-AXDQQJYC-Co2Mu1vo.js → quadrantDiagram-AXDQQJYC-CK3fRC18.js} +1 -1
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-CK3fRC18.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-CK3fRC18.js.gz +0 -0
- package/dist/client/assets/{railroadDiagram-O6MQD6OU-DjvJ0Ysn.js → railroadDiagram-O6MQD6OU-V4EFlydu.js} +1 -1
- package/dist/client/assets/railroadDiagram-O6MQD6OU-V4EFlydu.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-V4EFlydu.js.gz +0 -0
- package/dist/client/assets/{referenceLongPress-VL4F6lii.js → referenceLongPress-BjmYd1vB.js} +1 -1
- package/dist/client/assets/referenceLongPress-BjmYd1vB.js.br +0 -0
- package/dist/client/assets/referenceLongPress-BjmYd1vB.js.gz +0 -0
- package/dist/client/assets/{requirementDiagram-BXWQKSXE-QJ6afxsR.js → requirementDiagram-BXWQKSXE-Di1_tyAX.js} +1 -1
- package/dist/client/assets/{requirementDiagram-BXWQKSXE-QJ6afxsR.js.br → requirementDiagram-BXWQKSXE-Di1_tyAX.js.br} +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-Di1_tyAX.js.gz +0 -0
- package/dist/client/assets/{sankeyDiagram-P5KCCOFB-CYd9OO8p.js → sankeyDiagram-P5KCCOFB-D-qpWNza.js} +1 -1
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-D-qpWNza.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-D-qpWNza.js.gz +0 -0
- package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-Cau471RQ.js → sequenceDiagram-WJ2MYXX4-DmIxafrB.js} +1 -1
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-DmIxafrB.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-DmIxafrB.js.gz +0 -0
- package/dist/client/assets/{sizeCapture-INFHLROL-CWBvI9Ex.js → sizeCapture-INFHLROL-4MTh3tTt.js} +1 -1
- package/dist/client/assets/sizeCapture-INFHLROL-4MTh3tTt.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-4MTh3tTt.js.gz +0 -0
- package/dist/client/assets/{sparkles-BpYEa9ns.js → sparkles-Dk93lHg0.js} +1 -1
- package/dist/client/assets/{stateDiagram-D77RDMKH-ih47Vg8d.js → stateDiagram-D77RDMKH-CgYgneIv.js} +1 -1
- package/dist/client/assets/stateDiagram-D77RDMKH-CgYgneIv.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-CgYgneIv.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-CvPf0fxf.js +1 -0
- package/dist/client/assets/{swimlanes-42K2YHIH-Cks23MF4.js → swimlanes-42K2YHIH-OWA9HFVf.js} +1 -1
- package/dist/client/assets/swimlanes-42K2YHIH-OWA9HFVf.js.br +0 -0
- package/dist/client/assets/swimlanes-42K2YHIH-OWA9HFVf.js.gz +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-CZ_OauyW.js +8 -0
- package/dist/client/assets/{timeline-definition-24CTP7MA-C3Z6mGRy.js → timeline-definition-24CTP7MA-BAzx5DyO.js} +1 -1
- package/dist/client/assets/timeline-definition-24CTP7MA-BAzx5DyO.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-BAzx5DyO.js.gz +0 -0
- package/dist/client/assets/{triangle-alert-onS3H-d9.js → triangle-alert-CUIBOwqW.js} +1 -1
- package/dist/client/assets/{vennDiagram-4TSXK5OY-9GLhPNes.js → vennDiagram-4TSXK5OY-CBZ-PhTQ.js} +1 -1
- package/dist/client/assets/{vennDiagram-4TSXK5OY-9GLhPNes.js.br → vennDiagram-4TSXK5OY-CBZ-PhTQ.js.br} +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-CBZ-PhTQ.js.gz +0 -0
- package/dist/client/assets/{videoCompression-KoXLuxZT.js → videoCompression-BCnqCkRK.js} +1 -1
- package/dist/client/assets/videoCompression-BCnqCkRK.js.br +0 -0
- package/dist/client/assets/videoCompression-BCnqCkRK.js.gz +0 -0
- package/dist/client/assets/{wardleyDiagram-VM6X3IG4-BsZeAlBb.js → wardleyDiagram-VM6X3IG4-DbWzC6l5.js} +1 -1
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DbWzC6l5.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DbWzC6l5.js.gz +0 -0
- package/dist/client/assets/{xychartDiagram-S5SC5T6Z-BRT0eEuC.js → xychartDiagram-S5SC5T6Z-BmApnTWE.js} +1 -1
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-BmApnTWE.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-BmApnTWE.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/collaborationCli.js +45 -4
- package/dist/server/agent/collaborationDeliveryWorker.js +1 -1
- package/dist/server/agent/collaborationPeerTransport.js +8 -2
- package/dist/server/agent/collaborationRoutes.js +18 -2
- package/dist/server/agent/collaborationService.js +43 -1
- package/dist/server/agent/collaborationTaskBundles.js +121 -0
- package/dist/server/agent/collaborationTaskCli.js +54 -0
- package/dist/server/agent/collaborationTaskRoutes.js +58 -0
- package/dist/server/agent/collaborationTaskService.js +355 -0
- package/dist/server/agent/collaborationTaskStore.js +773 -0
- package/dist/server/agent/collaborationTaskTypes.js +1 -0
- package/dist/server/agent/collaborationTaskWorkspace.js +100 -0
- package/dist/server/entry.js +11 -1
- package/dist/server/federation/runtime.js +6 -1
- package/dist/server/routes/terminal.js +66 -2
- package/package.json +1 -1
- package/runtime-manifest.json +3 -3
- package/dist/client/assets/App-CDGrOo_r.js +0 -158
- package/dist/client/assets/App-CDGrOo_r.js.br +0 -0
- package/dist/client/assets/App-CDGrOo_r.js.gz +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-D2hm-GX-.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-D2hm-GX-.js.gz +0 -0
- package/dist/client/assets/DagPlayground-DLmKJylJ.js.br +0 -0
- package/dist/client/assets/DagPlayground-DLmKJylJ.js.gz +0 -0
- package/dist/client/assets/DiffLab-Bje07ujV.js.br +0 -0
- package/dist/client/assets/DiffLab-Bje07ujV.js.gz +0 -0
- package/dist/client/assets/DiffReview-CcLHnQu-.js.br +0 -0
- package/dist/client/assets/DiffReview-CcLHnQu-.js.gz +0 -0
- package/dist/client/assets/DiffReviewLab-CIieaScN.js.br +0 -0
- package/dist/client/assets/DiffReviewLab-CIieaScN.js.gz +0 -0
- package/dist/client/assets/DiffViewer-0nWShFhC.js.br +0 -0
- package/dist/client/assets/DiffViewer-0nWShFhC.js.gz +0 -0
- package/dist/client/assets/ModelPreview-B2Hrizox.js.br +0 -0
- package/dist/client/assets/ModelPreview-B2Hrizox.js.gz +0 -0
- package/dist/client/assets/RightSidebar-CiYxOpjs.js.br +0 -0
- package/dist/client/assets/RightSidebar-CiYxOpjs.js.gz +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-BvhG-Int.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-BvhG-Int.js.gz +0 -0
- package/dist/client/assets/app-CjvwGDVy.js +0 -35
- package/dist/client/assets/app-CjvwGDVy.js.br +0 -0
- package/dist/client/assets/app-CjvwGDVy.js.gz +0 -0
- package/dist/client/assets/arc-Cfd1r0w4.js.br +0 -0
- package/dist/client/assets/arc-Cfd1r0w4.js.gz +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-CYcaAY_y.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-CYcaAY_y.js.gz +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-uGZowYBC.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-uGZowYBC.js.gz +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-BuAjHXw2.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-BuAjHXw2.js.gz +0 -0
- package/dist/client/assets/channel-klM1FsDR.js +0 -1
- package/dist/client/assets/chunk-F27PBJKO-C99DgtYa.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-C99DgtYa.js.gz +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-CJs2LWtE.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-CJs2LWtE.js.gz +0 -0
- package/dist/client/assets/chunk-SVP7TREG-Deb_Pzwv.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-Deb_Pzwv.js.gz +0 -0
- package/dist/client/assets/chunk-TICWLB2K-C6wEoKIF.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-C6wEoKIF.js.gz +0 -0
- package/dist/client/assets/classDiagram-ZZMXUADV-Ccewxt_X.js +0 -1
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-Ccewxt_X.js +0 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-CAImJ8rh.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-CAImJ8rh.js.gz +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-D3Egll3y.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-MjvCZkx7.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-MjvCZkx7.js.gz +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-CrJn07Be.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-CrJn07Be.js.gz +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-x2YTsmxU.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-x2YTsmxU.js.gz +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-D98MzrbS.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-D98MzrbS.js.gz +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-DB_ACbg-.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-DB_ACbg-.js.gz +0 -0
- package/dist/client/assets/diagram-VX7I27RA-Drt4iWsQ.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-Drt4iWsQ.js.gz +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-D8mGxerZ.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-D8mGxerZ.js.gz +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-DTYnrl_Q.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-DTYnrl_Q.js.gz +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-ChsNovQf.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-ChsNovQf.js.gz +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-DsFiio6_.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-DsFiio6_.js.gz +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-BbHyLMqr.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-BbHyLMqr.js.gz +0 -0
- package/dist/client/assets/gestureArbiter-3rZyzlwR.js.br +0 -0
- package/dist/client/assets/gestureArbiter-3rZyzlwR.js.gz +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CTPZoYHy.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CTPZoYHy.js.gz +0 -0
- package/dist/client/assets/index-DxhkHH1u.css.br +0 -0
- package/dist/client/assets/index-DxhkHH1u.css.gz +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-C7BUr6Q1.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-C7BUr6Q1.js.gz +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DeKgSie7.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DeKgSie7.js.gz +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-BXLMRLCs.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-BXLMRLCs.js.gz +0 -0
- package/dist/client/assets/layout-BIGVsIVB.js.br +0 -0
- package/dist/client/assets/layout-BIGVsIVB.js.gz +0 -0
- package/dist/client/assets/linear-BhqHS_Ls.js.br +0 -0
- package/dist/client/assets/linear-BhqHS_Ls.js.gz +0 -0
- package/dist/client/assets/mermaid.core-DYTWj2Pu.js.br +0 -0
- package/dist/client/assets/mermaid.core-DYTWj2Pu.js.gz +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-BKVI5pEJ.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-BKVI5pEJ.js.gz +0 -0
- package/dist/client/assets/passwordBootstrap-DyrBaUP8.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-DyrBaUP8.js.gz +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-DdRPwDgf.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-DdRPwDgf.js.gz +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-KzblsFOl.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-KzblsFOl.js.gz +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-Co2Mu1vo.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-Co2Mu1vo.js.gz +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-DjvJ0Ysn.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-DjvJ0Ysn.js.gz +0 -0
- package/dist/client/assets/referenceLongPress-VL4F6lii.js.br +0 -0
- package/dist/client/assets/referenceLongPress-VL4F6lii.js.gz +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-QJ6afxsR.js.gz +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-CYd9OO8p.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-CYd9OO8p.js.gz +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-Cau471RQ.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-Cau471RQ.js.gz +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-CWBvI9Ex.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-CWBvI9Ex.js.gz +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-ih47Vg8d.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-ih47Vg8d.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-D0ybQxyy.js +0 -1
- package/dist/client/assets/swimlanes-42K2YHIH-Cks23MF4.js.br +0 -0
- package/dist/client/assets/swimlanes-42K2YHIH-Cks23MF4.js.gz +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-CTe40kKh.js +0 -8
- package/dist/client/assets/timeline-definition-24CTP7MA-C3Z6mGRy.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-C3Z6mGRy.js.gz +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-9GLhPNes.js.gz +0 -0
- package/dist/client/assets/videoCompression-KoXLuxZT.js.br +0 -0
- package/dist/client/assets/videoCompression-KoXLuxZT.js.gz +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-BsZeAlBb.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-BsZeAlBb.js.gz +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-BRT0eEuC.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-BRT0eEuC.js.gz +0 -0
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-
|
|
2
|
-
import{a7 as or,cT as bt,bk as e,g as po,cX as Y,L as gt,X as Bt,d1 as Lt,bD as ht,a as Vs,aS as Cu,C as go,c as Ys,cQ as lo,b8 as fm,H as Ps,aq as hm,bc as mm,be as wl,bf as pm,bg as Nu,bd as Ts,aD as gm,E as bm,j as xm,bb as vm,bF as wm,bH as ym,bI as km,b3 as Sm,bG as Rd,G as Ct,f as jm,i as $i,y as Rm,b as Cm,cS as Li,b2 as Cd,az as Nd,av as Nm,aH as Ai,aI as Ed,d2 as Ws,am as Is,aJ as Em,cR as Ya,bw as Mm,cC as Md,aB as $m,cO as Lm,c8 as Am,aM as Pm,U as $d,R as Tm,aw as Ld,aA as Im,aF as Ad,ca as Dm,u as Pd,n as Td,z as Eu,ah as Fm,_ as Xs,c1 as _m,c$ as Bm,br as Om,d as Us,l as Um,ak as Hm}from"./app-CjvwGDVy.js";import{b as a,r as kr}from"./dnd-BCFAPC0L.js";import{q as Mu,k as zm,r as Id,v as co,g as Wm,V as Gm,P as Km,o as qm,i as Vm,M as Ym,R as uo,w as $u,x as Xm,S as ns,D as Jm,e as Lu,c as Qm,N as Au,A as Pi,J as Zm,E as Nn,y as ep,z as tp,I as rp,K as np,B as Dd,O as Fd,T as _d,H as Bd,f as Od,n as Ti,m as Xa,d as sp,s as ap,l as op,h as ip,t as lp,F as Ud,C as cp,a as dp,G as up}from"./App-CDGrOo_r.js";import{a as Hd,S as zd,b as Pu,c as Zi,F as fp}from"./gestureArbiter-3rZyzlwR.js";import{D as el,C as Gs,L as Tu,f as hp,n as mp}from"./DiffReview-CcLHnQu-.js";import{T as pp,L as bo,M as Iu,G as vr}from"./triangle-alert-onS3H-d9.js";import{S as Js}from"./sparkles-BpYEa9ns.js";import{C as Du,M as Fu}from"./ChangeWalkthroughPanel-D2hm-GX-.js";import{r as _u,s as Bu,l as Ou,a as Wd,h as tl,u as gp,g as rl,b as Uu}from"./DiffViewer-0nWShFhC.js";import{u as Hu,G as zu}from"./referenceLongPress-VL4F6lii.js";const bp=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],xp=or("archive",bp);const vp=[["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"}]],wp=or("case-sensitive",vp);const yp=[["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"}]],kp=or("eye-off",yp);const Sp=[["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"}]],nl=or("eye",Sp);const jp=[["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"}]],sl=or("file-text",jp);const Rp=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],Cp=or("funnel",Rp);const Np=[["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"}]],Ep=or("image-plus",Np);const Mp=[["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"}]],$p=or("regex",Mp);const Lp=[["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"}]],Ap=or("scan",Lp);const Pp=[["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"}]],Tp=or("upload",Pp);const Ip=[["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"}]],Dp=or("whole-word",Ip);function Gd({children:r,actions:n}){const{t:s}=bt(),[l,f]=a.useState(!1),c=a.useId(),h=a.useRef(null),g=a.useRef(null),p=()=>{f(!1),h.current?.focus({preventScroll:!0})};return a.useLayoutEffect(()=>{if(!l)return;const m=h.current,u=g.current;if(!m||!u)return;const k=window.visualViewport,b=()=>{const A=m.getBoundingClientRect(),F=(k?.offsetLeft??0)+8,B=(k?.offsetTop??0)+8,D=Math.max(0,(k?.width??window.innerWidth)-16),C=B+(k?.height??window.innerHeight)-16,E=Math.min(240,D),T=Math.max(0,A.top-B-6),U=Math.max(0,C-A.bottom-6),L=u.scrollHeight>U&&T>U;Object.assign(u.style,{width:`${E}px`,left:`${Math.max(F,Math.min(A.right-E,F+D-E))}px`,top:`${L?A.top-6:A.bottom+6}px`,maxHeight:`${L?T:U}px`,transform:L?"translateY(-100%)":"none"})};b();const M=typeof ResizeObserver>"u"?null:new ResizeObserver(b);return M?.observe(m),M?.observe(u),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),k?.addEventListener("resize",b),k?.addEventListener("scroll",b),()=>{M?.disconnect(),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),k?.removeEventListener("resize",b),k?.removeEventListener("scroll",b)}},[l]),a.useEffect(()=>{if(!l)return;g.current?.querySelector("button:not(:disabled)")?.focus({preventScroll:!0});const m=u=>{u.target instanceof Node&&!h.current?.contains(u.target)&&!g.current?.contains(u.target)&&f(!1)};return document.addEventListener("pointerdown",m),()=>document.removeEventListener("pointerdown",m)},[l]),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:h,type:"button","aria-haspopup":"menu","aria-expanded":l,"aria-controls":l?c:void 0,onClick:()=>f(m=>!m),onKeyDown:m=>{(m.key==="ArrowDown"||m.key==="ArrowUp")&&(m.preventDefault(),f(!0))},className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-[11px] font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary ${l?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(po,{size:14}),s("sidebar.moreActions")]})]}),typeof document<"u"&&kr.createPortal(e.jsx("div",{ref:g,id:c,hidden:!l,role:"menu","data-sidebar-gesture-ignore":!0,"aria-label":s("sidebar.moreActions"),className:"fixed z-menu-panel overflow-y-auto overscroll-contain rounded-lg border border-border/30 bg-surface p-1 shadow-[0_8px_24px_var(--app-shadow-soft)]",onKeyDown:m=>{if(!m.currentTarget.contains(m.target))return;const u=[...m.currentTarget.querySelectorAll("button:not(:disabled)")],k=u.indexOf(document.activeElement);let b;if(m.key==="Escape"){m.preventDefault(),m.stopPropagation(),p();return}if(m.key==="Tab"){p();return}if(m.key==="ArrowDown")b=(k+1)%u.length;else if(m.key==="ArrowUp")b=(k-1+u.length)%u.length;else if(m.key==="Home")b=0;else if(m.key==="End")b=u.length-1;else return;m.preventDefault(),u[b]?.focus({preventScroll:!0})},children:n(p)}),document.body)]})}const Ii="a[href],button,input,select,textarea,[tabindex],[contenteditable],iframe,summary,audio[controls],video[controls]",Ja=a.memo(function({active:n,mounted:s=!0,fallback:l=null,children:f}){const c=a.useRef(null);return a.useLayoutEffect(()=>{const h=c.current;if(!h||n)return;const g=new Map,p=k=>{g.has(k)||(g.set(k,k.inert),k.inert=!0)},m=k=>{k instanceof HTMLElement&&k.matches(Ii)&&p(k),k.querySelectorAll(Ii).forEach(p)};m(h);const u=new MutationObserver(k=>{for(const b of k)b.type==="attributes"?b.target instanceof HTMLElement&&b.target.matches(Ii)&&p(b.target):b.addedNodes.forEach(M=>{M instanceof Element&&m(M)})});return u.observe(h,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex","href","contenteditable","controls"]}),()=>{u.disconnect();for(const[k,b]of g)k.inert=b}},[n,s]),e.jsx("div",{ref:c,className:"absolute inset-0 min-h-0 overflow-hidden bg-surface text-foreground",style:n?void 0:{clipPath:"inset(100%)"},"aria-hidden":!n,children:s?typeof f=="function"?f():f:l})},(r,n)=>!r.active&&!n.active&&r.mounted===n.mounted);async function Fp(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function _p({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:f,load:c}){a.useEffect(()=>{if(!r||!n||s||f.current===n)return;const h=window.setTimeout(()=>{f.current=n,c(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,f,c])}function Bp({rootPath:r,disabled:n,pressed:s,saving:l,onToggle:f}){const{t:c}=bt(),h=a.useId(),g=a.useRef(null),p=a.useRef(null),m=a.useRef(null),u=a.useRef(null),k=a.useRef(null),b=a.useRef(!1),[M,A]=a.useState(!1),[F,B]=a.useState(""),[D,C]=a.useState(!1),[E,T]=a.useState(null),U=Y(W=>W.setGitIgnoreExceptions),L=()=>{u.current!==null&&clearTimeout(u.current),u.current=null,k.current=null},w=()=>{L(),!(n||D||!r)&&(B((Y.getState().gitIgnoreExceptions[r]??[]).join(`
|
|
3
|
-
`)),
|
|
4
|
-
`).
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
`)
|
|
8
|
-
`),p=g.findIndex(k=>k.startsWith("@@ "));if(p<0){l.push(...g);continue}c===0&&l.push(...g.slice(0,p));const m=n[c];let u=p;for(;u>=0&&u<g.length;){const k=g.findIndex((D,C)=>C>u&&D.startsWith("@@ ")),b=k>=0?k:g.length,M=g.slice(u,b),A=M[0]??"",F=m?A===m:!0,B=A||m||M.join(`
|
|
9
|
-
`);F&&!f.has(B)&&(l.push(...M),f.add(B)),u=k}}return l.join(`
|
|
10
|
-
`)}function Qp({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Jp(s.items.map(p=>p.hunk.diff||p.current?.diff||p.stale?.diff||""),s.items.map(p=>p.hunk.hunkHeader)),f=s.items.map(p=>p.current??p.stale).filter(p=>!!p).map(p=>({id:p.id,repoRoot:p.repoRoot,filePath:p.filePath,oldPath:p.oldPath,newPath:p.newPath,hunkHeader:p.hunkHeader,hunkIndex:p.hunkIndex,fingerprint:p.fingerprint,diff:p.diff,explanation:p.explanation,summary:p.summary,workspaceRoot:p.workspaceRoot,generatedBy:p.generatedBy,injectedAt:p.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"",g=s.items[0]?.repoRoot??f[0]?.repoRoot??null;return{key:s.key,path:s.filePath,oldPath:s.items[0]?.hunk.oldPath??void 0,absolutePath:g?`${g}/${s.items[0]?.repositoryPath??s.filePath}`:s.filePath,status:s.changeType,repoRoot:g,displayName:c,displayDir:h,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(p=>p.hunk.previewRevert?[[p.hunk.hunkHeader,p.hunk.previewRevert]]:[])),auditRecords:f,onInsertDiffReference:n}})}function Zp(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let h=null,g=Number.POSITIVE_INFINITY;for(const m of l){const u=m.getBoundingClientRect();if(u.bottom<c)continue;const k=Math.abs(u.top-c);k<g&&(h=m,g=k)}const p=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!p||p===n||s(p),p}function qd({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:f=!1,backLabel:c="Back",headerTitle:h,headerMeta:g,onClose:p,closeLabel:m="Back",wrap:u=!0,diffViewType:k,inlineMode:b,viewControls:M,onToggleWrap:A,wrapTitle:F,wrapOnLabel:B="Wrap on",wrapOffLabel:D="Wrap off",desktopLayout:C="split",onInsertDiffReference:E,onReferenceCopied:T,renderPathReference:U,insertedReferenceKey:L,copiedReferenceKey:w,onClearAuditRecord:o,onRefresh:O,localOptions:H,onHunkGitAction:W,error:N,refreshing:q,actionsBusy:fe,refreshLabel:G,refreshTitle:ee,walkthroughs:P=[],onWalkthroughNavigate:_,initialDetailScrollTop:J,onDetailScrollPositionChange:ue,scrollToKey:pe,scrollToKeyNonce:we,externalSwiperRef:je,onMobileSlideChange:Ce}){const{t:$}=bt(),Q=a.useMemo(()=>Yp(r),[r]),ne=a.useMemo(()=>new Map(Q.map(re=>[re.key,re])),[Q]),[Le,Ye]=a.useState(()=>qp()),[De,rt]=a.useState(()=>new Set),[_e,R]=a.useState({key:null,nonce:0}),se=Q.find(re=>re.explained>0||re.stale>0)?.key??Q[0]?.key??null,he=n&&Q.some(re=>re.key===n)?n:se,Ee=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:Q.map(Xp)}],[Q]),Me=a.useMemo(()=>Qp({groups:Q,onInsertDiffReference:E}),[Q,E]),Ke=a.useRef(se),le=a.useRef(s);Ke.current=se,le.current=s,a.useEffect(()=>{!n&&Ke.current&&le.current(Ke.current)},[n]);const Ae=A?e.jsxs("button",{type:"button",onClick:A,"aria-pressed":u,title:F,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?B:D})]}):null,dt=H?.map(re=>e.jsxs("label",{title:re.disabled?$("rightSidebar.includeUncommittedCurrentBranchOnly"):re.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:re.checked,disabled:q||fe||re.disabled&&!re.checked,onChange:Te=>re.onChange(Te.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[re.label," · ",$("rightSidebar.includeUncommitted"),re.disabled&&e.jsx("span",{className:"block text-[10px]",children:$("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},re.key)),Pe=N?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:N}):null,ke=O?e.jsxs("button",{type:"button",onClick:O,disabled:q||fe,title:ee??G,"aria-label":ee??G,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(Mu,{size:12,className:q?"animate-spin":""}),G&&e.jsx("span",{children:G})]}):null,ut=re=>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}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),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(Vs,{size:14}),m]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[re,dt,ke,M,Ae,Pe]})]});if(r.length===0){const re=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?re:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[ut(null),re]})}const Qe=A||O?({slideToList:re})=>e.jsxs("div",{className:"flex flex-wrap 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:re,children:[e.jsx(Vs,{size:14}),c]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[dt,ke,M,A&&e.jsxs("button",{type:"button",onClick:A,"aria-pressed":u,title:F,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?B:D})]})]}),Pe]}):void 0;return e.jsx(el,{mobile:f,preserveScrollOnUpdate:!!H?.length,desktopLayout:C,backLabel:c,groups:Ee,selectedKey:he,mode:Le,onModeChange:re=>{Ye(re),re!=="ai"&&Lt(Wu,re)},compact:f,collapsedDirectoryKeys:De,onToggleDirectory:re=>{rt(Te=>{const et=new Set(Te);return et.has(re)?et.delete(re):et.add(re),et})},onSelectFile:re=>{s(re.key),R(Te=>({key:re.key,nonce:Te.nonce+1}))},renderLeading:re=>{const Te=ne.get(re.key);return e.jsx(al,{changeStatus:re.status,auditStatus:Te,renderChangeBadge:et=>e.jsx(Gs,{status:et})})},renderTrailing:re=>{const Te=ne.get(re.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[Te&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Te.additions," -",Te.deletions]}),U?.(re.path,"file")]})},renderDirectoryTrailing:re=>U?.(re,"directory"),renderListHeader:ut,aiContent:({slideToDetail:re,fullscreen:Te,toggleFullscreen:et})=>P.length>0&&_?e.jsx(Du,{walkthroughs:P,repoRoot:P[0]?.repoRoot,fullscreen:Te,onToggleFullscreen:et,onNavigate:Ot=>{f&&window.requestAnimationFrame(re),_(Ot)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:$("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Qe,externalSwiperRef:je,onMobileSlideChange:Ce,detailContainerClassName:f?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:J,scrollToKey:pe??_e.key,scrollToKeyNonce:pe==null?_e.nonce:we,onDetailScroll:re=>{Zp(re,he,s),ue?.(re.scrollTop)},files:Me,activePane:!0,wrap:u,diffViewType:k,inlineMode:b,renderStreamBadge:(re,Te)=>{const et=ne.get(Te.key);return e.jsx(al,{changeStatus:re,auditStatus:et,renderChangeBadge:Ot=>e.jsx(Gs,{status:Ot})})},onInsertDiffReference:E,onReferenceCopied:T,insertedReferenceKey:L,copiedReferenceKey:w,onClearAuditRecord:o,onHunkGitAction:q?void 0:W,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function eg(r){return r.replace(/\/+$/,"")||"/"}function tg(r){return[...new Set(Array.from(r,eg))].sort((n,s)=>n.localeCompare(s))}function rg(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function ng(r){let n=null;return{applicableEvents:r.filter(l=>{const f=l.type==="rescan-required"&&!rg(l.reason);return f&&l.reason&&!n&&(n=l.reason),!f}),unavailableReason:n}}const sg=1400,ag=1200,Gu=44,og=.7;function Di(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function ol(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function ig(r){try{const n=window.localStorage.getItem(ol(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Gu?s:null}catch{return null}}function Vd(r,n){try{n===null?window.localStorage.removeItem(ol(r)):window.localStorage.setItem(ol(r),String(n))}catch{}}function Qa(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function lg({value:r,collapsed:n,labels:s,focusRequest:l,insertError:f,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:g,onAutoCollapseAfterSendChange:p,onDisable:m,onClear:u,onInsert:k,onInsertAndSend:b}){const[M,A]=a.useState(null),[F,B]=a.useState(!1),[D,C]=a.useState(()=>ig(Di())),E=a.useRef(D),T=a.useRef(null),U=a.useRef(null),L=a.useRef(r),w=a.useRef(null),o=a.useRef(null),O=!!r.trim(),H=r.trim().split(`
|
|
11
|
-
`)[0]??"",W=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{T.current!==null&&window.clearTimeout(T.current),U.current!==null&&window.clearTimeout(U.current)},[]),a.useEffect(()=>{let $=!1;const Q=Di();return Cu().then(ne=>{if($)return;const Le=ne.contextDraftHeight?.[Q]??null;Vd(Q,Le),E.current=Le,C(Le)}).catch(()=>{}),()=>{$=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const $=w.current;if(!$)return;Qa()||$.focus(),$.setSelectionRange($.value.length,$.value.length),$.scrollTop=$.scrollHeight}},[l]),a.useEffect(()=>{const $=L.current;L.current=r,!(!n||r.length<=$.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},ag))},[r,n]),a.useEffect(()=>{if(n)return;const $=w.current;$&&($.style.height=D!==null?`${D}px`:"")},[r,n,D]),a.useEffect(()=>{if(n)return;const $=w.current;!$||document.activeElement===$||($.scrollTop=$.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||Qa())return;const $=w.current;!$||document.activeElement===$||($.focus(),$.setSelectionRange($.value.length,$.value.length))},[n]);const N=a.useRef(null);a.useLayoutEffect(()=>{if(!Qa())return;const $=window.visualViewport;if(!$)return;const Q=()=>{const ne=N.current;if(!ne)return;if($.height>=window.innerHeight*.75){ne.style.transform="";return}const Le=ne.getBoundingClientRect(),Ye=Math.round($.height-Le.bottom);ne.style.transform=Ye!==0?`translateY(${Ye}px)`:""};return Q(),$.addEventListener("resize",Q),$.addEventListener("scroll",Q),()=>{$.removeEventListener("resize",Q),$.removeEventListener("scroll",Q),N.current&&(N.current.style.transform="")}},[n]);const q=$=>{A($),T.current!==null&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{T.current=null,A(null)},sg)},fe=$=>{g(!1),Qa()&&window.requestAnimationFrame(()=>{const Q=w.current;if(!Q)return;Q.focus();const ne=Q.value.length;Q.setSelectionRange(ne,ne),window.requestAnimationFrame(()=>{Q.setSelectionRange(ne,ne)})})},G=()=>{k(),q("inserted")},ee=()=>{O&&(b(),q("sent"))},P=$=>{if($.key==="Escape"){$.preventDefault(),g(!0);return}$.key!=="Enter"||!$.metaKey&&!$.ctrlKey||($.preventDefault(),ee())},_=$=>{$.preventDefault()},J=$=>{$.preventDefault();const Q=w.current;Q&&(o.current={startY:$.clientY,startHeight:Q.getBoundingClientRect().height},$.currentTarget.setPointerCapture?.($.pointerId))},ue=$=>{const Q=o.current;if(!Q)return;const ne=window.visualViewport?.height??window.innerHeight,Le=Math.round(Math.min(Math.max(Q.startHeight+(Q.startY-$.clientY),Gu),ne*og));E.current=Le,C(Le)},pe=$=>{const Q=Di();Vd(Q,$),lo({contextDraftHeight:{[Q]:$}}).catch(()=>{})},we=()=>{o.current&&(o.current=null,E.current!==null&&pe(E.current))},je=()=>{E.current=null,C(null),pe(null)},Ce=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:N,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:()=>fe(),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(zm,{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] ${f?"text-destructive":F?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:f??(F?s.appended:O?H:s.title)})]}),Ce,e.jsx("button",{type:"button",onClick:ee,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:M==="sent"?e.jsx(go,{size:12}):e.jsx(Id,{size:12})})]})}):e.jsxs("section",{ref:N,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:J,onPointerMove:ue,onPointerUp:we,onPointerCancel:we,onDoubleClick:je,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:_,onClick:()=>g(!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(Ys,{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}),Ce]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:_,onClick:()=>p(!c),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 ${c?"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 ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:_,onClick:m,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(Bt,{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:w,value:r,onChange:$=>h($.target.value),onKeyDown:P,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:_,onClick:u,disabled:!O,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(co,{size:11})}),f?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:f}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:_,onClick:G,disabled:!O,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(Wm,{size:11}),e.jsx("span",{children:M==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:_,onClick:ee,disabled:!O,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} · ${W}`,children:[M==="sent"?e.jsx(go,{size:11}):e.jsx(Id,{size:11}),e.jsx("span",{children:M==="sent"?s.sent:s.send})]})]})]})})]})}function cg(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-Bnlo-oVE.js","assets/app-CATnTUZF.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-Bi9A6QUP.css","assets/App-BiLjlrk-.js","assets/gestureArbiter-DvupkPra.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-CUIBOwqW.js","assets/referenceLongPress-BjmYd1vB.js","assets/DiffReview-BuLu1qCi.js","assets/sparkles-Dk93lHg0.js","assets/DiffViewer-BUCYxg27.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-DXprT-7m.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-CxZFe3as.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a9 as or,cY as pt,bn as e,g as po,bv as Mu,L as ht,d as ns,X as Pt,d0 as Y,d6 as Lt,bH as mt,a as Vs,aV as $u,C as go,c as Ys,cV as lo,bb as mm,H as Ts,as as pm,bf as gm,bh as wl,bi as bm,bj as Lu,bg as Is,aG as xm,E as vm,j as ym,be as wm,bJ as km,bL as Sm,bM as jm,b6 as Rm,bK as Ed,G as Nt,f as Nm,i as $i,y as Cm,b as Em,cX as Li,b5 as Md,aB as $d,ax as Mm,aK as Pi,aL as Ld,d7 as Ws,ao as Ds,aM as $m,cW as Ya,bA as Lm,cG as Pd,aE as Pm,cT as Am,cc as Tm,aP as Im,U as Ad,R as Dm,ay as Td,aD as Fm,aI as Id,ce as _m,u as Dd,n as Fd,z as Pu,aj as Bm,_ as Xs,c5 as Om,d4 as Um,l as Hm,am as zm}from"./app-CATnTUZF.js";import{b as a,r as kr}from"./dnd-BCFAPC0L.js";import{e as kl,F as Wm,r as Au,l as Gm,s as _d,w as co,g as Km,V as qm,P as Vm,p as Ym,j as Xm,M as Jm,R as uo,x as Tu,y as Qm,S as ss,D as Zm,c as ep,O as Iu,A as Ai,K as tp,I as Cn,z as rp,B as np,J as sp,N as ap,E as Bd,Q as Od,T as Ud,H as Hd,f as zd,o as Ti,n as Xa,d as op,t as ip,m as lp,i as cp,u as dp,h as Wd,C as up,a as fp,G as hp}from"./App-BiLjlrk-.js";import{F as Zi,a as Gd,S as Kd,b as Du,c as el}from"./gestureArbiter-DvupkPra.js";import{D as tl,C as Gs,L as Fu,f as mp,n as pp}from"./DiffReview-BuLu1qCi.js";import{T as gp,L as bo,M as _u,G as vr}from"./triangle-alert-CUIBOwqW.js";import{S as Js}from"./sparkles-Dk93lHg0.js";import{C as Bu,M as Ou}from"./ChangeWalkthroughPanel-DXprT-7m.js";import{r as Uu,s as Hu,l as zu,a as qd,h as rl,u as bp,g as nl,b as Wu}from"./DiffViewer-BUCYxg27.js";import{u as Gu,G as Ku}from"./referenceLongPress-BjmYd1vB.js";const xp=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],vp=or("archive",xp);const yp=[["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"}]],wp=or("case-sensitive",yp);const kp=[["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"}]],Sp=or("eye-off",kp);const jp=[["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"}]],sl=or("eye",jp);const Rp=[["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"}]],al=or("file-text",Rp);const Np=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],Cp=or("funnel",Np);const Ep=[["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"}]],Mp=or("image-plus",Ep);const $p=[["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"}]],Lp=or("regex",$p);const Pp=[["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"}]],Ap=or("scan",Pp);const Tp=[["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"}]],Ip=or("upload",Tp);const Dp=[["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"}]],Fp=or("whole-word",Dp);function Vd({children:r,actions:n}){const{t:s}=pt(),[l,f]=a.useState(!1),c=a.useId(),h=a.useRef(null),g=a.useRef(null),p=()=>{f(!1),h.current?.focus({preventScroll:!0})};return a.useLayoutEffect(()=>{if(!l)return;const m=h.current,u=g.current;if(!m||!u)return;const y=window.visualViewport,b=()=>{const T=m.getBoundingClientRect(),I=(y?.offsetLeft??0)+8,D=(y?.offsetTop??0)+8,U=Math.max(0,(y?.width??window.innerWidth)-16),C=D+(y?.height??window.innerHeight)-16,R=Math.min(240,U),M=Math.max(0,T.top-D-6),H=Math.max(0,C-T.bottom-6),F=u.scrollHeight>H&&M>H;Object.assign(u.style,{width:`${R}px`,left:`${Math.max(I,Math.min(T.right-R,I+U-R))}px`,top:`${F?T.top-6:T.bottom+6}px`,maxHeight:`${F?M:H}px`,transform:F?"translateY(-100%)":"none"})};b();const $=typeof ResizeObserver>"u"?null:new ResizeObserver(b);return $?.observe(m),$?.observe(u),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),y?.addEventListener("resize",b),y?.addEventListener("scroll",b),()=>{$?.disconnect(),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),y?.removeEventListener("resize",b),y?.removeEventListener("scroll",b)}},[l]),a.useEffect(()=>{if(!l)return;g.current?.querySelector("button:not(:disabled)")?.focus({preventScroll:!0});const m=u=>{u.target instanceof Node&&!h.current?.contains(u.target)&&!g.current?.contains(u.target)&&f(!1)};return document.addEventListener("pointerdown",m),()=>document.removeEventListener("pointerdown",m)},[l]),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:h,type:"button","aria-haspopup":"menu","aria-expanded":l,"aria-controls":l?c:void 0,onClick:()=>f(m=>!m),onKeyDown:m=>{(m.key==="ArrowDown"||m.key==="ArrowUp")&&(m.preventDefault(),f(!0))},className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-[11px] font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary ${l?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(po,{size:14}),s("sidebar.moreActions")]})]}),typeof document<"u"&&kr.createPortal(e.jsx("div",{ref:g,id:c,hidden:!l,role:"menu","data-sidebar-gesture-ignore":!0,"aria-label":s("sidebar.moreActions"),className:"fixed z-menu-panel overflow-y-auto overscroll-contain rounded-lg border border-border/30 bg-surface p-1 shadow-[0_8px_24px_var(--app-shadow-soft)]",onKeyDown:m=>{if(!m.currentTarget.contains(m.target))return;const u=[...m.currentTarget.querySelectorAll("button:not(:disabled)")],y=u.indexOf(document.activeElement);let b;if(m.key==="Escape"){m.preventDefault(),m.stopPropagation(),p();return}if(m.key==="Tab"){p();return}if(m.key==="ArrowDown")b=(y+1)%u.length;else if(m.key==="ArrowUp")b=(y-1+u.length)%u.length;else if(m.key==="Home")b=0;else if(m.key==="End")b=u.length-1;else return;m.preventDefault(),u[b]?.focus({preventScroll:!0})},children:n(p)}),document.body)]})}const Ii="a[href],button,input,select,textarea,[tabindex],[contenteditable],iframe,summary,audio[controls],video[controls]",Ja=a.memo(function({active:n,mounted:s=!0,fallback:l=null,children:f}){const c=a.useRef(null);return a.useLayoutEffect(()=>{const h=c.current;if(!h||n)return;const g=new Map,p=y=>{g.has(y)||(g.set(y,y.inert),y.inert=!0)},m=y=>{y instanceof HTMLElement&&y.matches(Ii)&&p(y),y.querySelectorAll(Ii).forEach(p)};m(h);const u=new MutationObserver(y=>{for(const b of y)b.type==="attributes"?b.target instanceof HTMLElement&&b.target.matches(Ii)&&p(b.target):b.addedNodes.forEach($=>{$ instanceof Element&&m($)})});return u.observe(h,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex","href","contenteditable","controls"]}),()=>{u.disconnect();for(const[y,b]of g)y.inert=b}},[n,s]),e.jsx("div",{ref:c,className:"absolute inset-0 min-h-0 overflow-hidden bg-surface text-foreground",style:n?void 0:{clipPath:"inset(100%)"},"aria-hidden":!n,children:s?typeof f=="function"?f():f:l})},(r,n)=>!r.active&&!n.active&&r.mounted===n.mounted);async function _p(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function Bp({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:f,load:c}){a.useEffect(()=>{if(!r||!n||s||f.current===n)return;const h=window.setTimeout(()=>{f.current=n,c(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,f,c])}function Op({rootPath:r,paths:n,disabled:s,onChange:l}){const{t:f}=pt(),[c,h]=a.useState(""),[g,p]=a.useState(0),[m,u]=a.useState(null),[y,b]=a.useState(!1),[$,T]=a.useState(!1),I=`${r.replace(/[\\/]+$/,"")}/${c}`;a.useEffect(()=>{const R=new AbortController;return u(null),b(!1),Mu(I,R.signal,!0,"pick_git_ignore_exception").then(M=>{R.signal.aborted||u({directory:c,entries:M.entries,truncated:!!M.truncated})}).catch(()=>{R.signal.aborted||b(!0)}),()=>R.abort()},[I,c,g]);const D=R=>{u(null),b(!1),h(R)},U=m?.directory===c,C=R=>{if(R.length>200){T(!0);return}T(!1),l(R)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/30 bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/20 p-2",children:[e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(c.slice(0,Math.max(0,c.lastIndexOf("/")))),"aria-label":f("rightSidebar.parentFolder"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(kl,{size:14})}),e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(""),"aria-label":f("rightSidebar.backToProjectRoot"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(Zi,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:I,children:c||"./"})]}),e.jsxs("div",{className:"h-56 overflow-y-auto overscroll-contain p-1",role:"group","aria-label":f("rightSidebar.gitIgnoreExceptionsPaths"),"aria-busy":!U&&!y,children:[y?e.jsxs("div",{className:"flex flex-col items-center gap-2 p-4 text-center text-xs",children:[e.jsx("p",{role:"alert",className:"text-destructive",children:f("rightSidebar.gitIgnoreExceptionsLoadFailed")}),e.jsx("button",{type:"button",disabled:s,onClick:()=>{b(!1),p(R=>R+1)},className:"rounded-md px-3 py-2 text-primary hover:bg-surface-elevated disabled:opacity-40",children:f("common.retry")})]}):U?m.entries.length===0?e.jsx("p",{className:"p-4 text-center text-xs text-muted-foreground",children:f("rightSidebar.gitIgnoreExceptionsEmptyDirectory")}):m.entries.map(R=>{const M=c?`${c}/${R.name}`:R.name,H=M+(R.type==="directory"?"/":""),F=n.includes(H)||n.includes(M),S=n.some(O=>O.endsWith("/")&&M.startsWith(O)),o=R.type==="directory"?Zi:Wm;return e.jsxs("div",{className:"flex items-center gap-1 rounded-md hover:bg-surface-elevated",children:[e.jsxs("label",{className:"flex min-h-10 min-w-0 flex-1 cursor-pointer items-center gap-2 px-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:F||S,disabled:s||S,onChange:()=>C(F?n.filter(O=>O!==H&&O!==M):[...n,H]),className:"h-4 w-4 shrink-0 accent-[var(--primary)] disabled:opacity-40"}),e.jsx(o,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",title:R.name,children:R.name})]}),R.type==="directory"&&e.jsx("button",{type:"button",disabled:s,onClick:()=>D(M),"aria-label":f("rightSidebar.gitIgnoreExceptionsOpenDirectory",{name:R.name}),className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface hover:text-foreground disabled:opacity-40",children:e.jsx(ns,{size:15})})]},R.name)}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(ht,{size:18})}),U&&m.truncated&&e.jsx("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:f("rightSidebar.gitIgnoreExceptionsTruncated")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"font-medium",children:f("rightSidebar.gitIgnoreExceptionsSelected",{count:n.length})}),e.jsx("button",{type:"button",disabled:s||n.length===0,onClick:()=>C([]),className:"rounded-md px-2 py-1 text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:f("rightSidebar.gitIgnoreExceptionsClear")})]}),n.length>0&&e.jsx("ul",{className:"max-h-24 overflow-y-auto overscroll-contain",children:n.map(R=>e.jsxs("li",{className:"flex items-center gap-2 rounded-md pl-2 text-xs hover:bg-surface-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:R,children:R}),e.jsx("button",{type:"button",disabled:s,onClick:()=>C(n.filter(M=>M!==R)),"aria-label":f("rightSidebar.gitIgnoreExceptionsRemove",{path:R}),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:13})})]},R))}),$&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:f("rightSidebar.gitIgnoreExceptionsInvalid")})]})}function Up({rootPath:r,disabled:n,pressed:s,saving:l,onToggle:f}){const{t:c}=pt(),h=a.useId(),g=a.useRef(null),p=a.useRef(null),m=a.useRef(null),u=a.useRef(null),y=a.useRef(!1),[b,$]=a.useState(!1),[T,I]=a.useState([]),[D,U]=a.useState(!1),[C,R]=a.useState(null),M=Y(P=>P.setGitIgnoreExceptions),H=()=>{m.current!==null&&clearTimeout(m.current),m.current=null,u.current=null},F=()=>{H(),!(n||D||!r)&&(I([...Y.getState().gitIgnoreExceptions[r]??[]]),R(null),$(!0))},S=()=>{D||$(!1)},o=P=>{H(),y.current=!1,!(P.button!==0||!P.isPrimary||n)&&(P.currentTarget.setPointerCapture(P.pointerId),u.current={x:P.clientX,y:P.clientY},m.current=setTimeout(()=>{y.current=!0,F()},450))};a.useEffect(()=>($(!1),H(),H),[r]),a.useEffect(()=>{if(b)return p.current?.focus(),()=>g.current?.focus()},[b]);const O=c(s?"rightSidebar.showGitIgnoredFiles":"rightSidebar.hideGitIgnoredFiles");return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",disabled:n||D,"aria-pressed":s,"aria-label":O,"aria-description":c("rightSidebar.gitIgnoreConfigureHint"),title:`${O} · ${c("rightSidebar.gitIgnoreConfigureHint")}`,onClick:P=>{if(y.current&&P.detail!==0){y.current=!1,P.preventDefault();return}f()},onContextMenu:P=>{P.preventDefault(),y.current=!0,b||F()},onPointerDown:o,onPointerMove:P=>{const V=u.current;V&&Math.hypot(P.clientX-V.x,P.clientY-V.y)>10&&H()},onPointerUp:H,onPointerCancel:H,onLostPointerCapture:H,className:`inline-flex h-7 w-7 shrink-0 select-none items-center justify-center rounded-md transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-35 [-webkit-touch-callout:none] ${s?"bg-surface-2 text-primary hover:bg-surface-elevated":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:l?e.jsx(ht,{size:14}):e.jsx(Cp,{size:14})}),b&&kr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop flex items-center justify-center bg-[var(--app-backdrop)] p-3 backdrop-blur-sm",onClick:S,children:e.jsxs("form",{ref:p,role:"dialog",tabIndex:-1,"aria-modal":"true","aria-labelledby":`${h}-title`,"aria-describedby":`${h}-hint`,className:"relative z-modal-panel flex max-h-[80dvh] w-full max-w-lg flex-col gap-3 overflow-y-auto rounded-xl border border-border/20 bg-surface p-4 text-foreground shadow-2xl",onClick:P=>P.stopPropagation(),onKeyDown:P=>{if(P.key==="Escape"&&(P.preventDefault(),P.stopPropagation(),S()),P.key==="Tab"){const V=Array.from(p.current?.querySelectorAll("button:not(:disabled), input:not(:disabled)")??[]);if(!V.length){P.preventDefault(),p.current?.focus();return}const E=V[0],K=V[V.length-1];P.shiftKey&&document.activeElement===E&&(P.preventDefault(),K?.focus()),document.activeElement===p.current?(P.preventDefault(),(P.shiftKey?K:E)?.focus()):!P.shiftKey&&document.activeElement===K&&(P.preventDefault(),E?.focus())}},onSubmit:P=>{if(P.preventDefault(),!(!r||D)){if(T.length>200){R(c("rightSidebar.gitIgnoreExceptionsInvalid"));return}U(!0),R(null),M(r,T).then(()=>$(!1)).catch(()=>R(c("rightSidebar.gitIgnoreExceptionsSaveFailed"))).finally(()=>U(!1))}},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{id:`${h}-title`,className:"text-sm font-medium",children:c("rightSidebar.gitIgnoreExceptionsTitle")}),e.jsx("button",{type:"button",disabled:D,onClick:S,"aria-label":c("common.close"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:16})})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:r??void 0,children:r}),e.jsx("p",{id:`${h}-hint`,className:"text-xs leading-relaxed text-muted-foreground",children:c("rightSidebar.gitIgnoreExceptionsHint")}),e.jsx("p",{className:"text-xs font-medium",children:c("rightSidebar.gitIgnoreExceptionsPaths")}),r&&e.jsx(Op,{rootPath:r,paths:T,onChange:I,disabled:D}),C&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:C}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",disabled:D,onClick:S,className:"rounded-lg px-3 py-2 text-xs text-muted-foreground hover:bg-surface-2 disabled:opacity-40",children:c("common.cancel")}),e.jsxs("button",{type:"submit",disabled:D,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-xs font-medium text-primary-foreground disabled:opacity-50",children:[D&&e.jsx(ht,{size:13}),c("common.save")]})]})]})}),document.body)]})}function Hp(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,f=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!f)return Promise.resolve(null);const c=r instanceof HTMLImageElement?1400/Math.max(l,f):Math.min(1,1400/Math.max(l,f)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(f*c));const g=h.getContext("2d");if(!g)return Promise.resolve(null);const p=getComputedStyle(document.documentElement);if(g.fillStyle=p.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,h.height),g.drawImage(r,0,0,h.width,h.height),s){const m=Math.max(10,Math.min(16,h.width/35));g.font=`${m}px sans-serif`;const u=[];let y="";for(const b of s.split(" "))y&&g.measureText(`${y} ${b}`).width>h.width-20?(u.push(y),y=b):y=y?`${y} ${b}`:b;y&&u.push(y),g.fillStyle=p.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,u.length*(m+4)+12),g.fillStyle=p.getPropertyValue("--foreground").trim()||"black",u.forEach((b,$)=>g.fillText(b,10,8+m+$*(m+4)))}if(n){const m=n.xPercent*h.width/100,u=n.yPercent*h.height/100,y=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),b=y*1.6;g.strokeStyle=p.getPropertyValue("--primary").trim()||"black",g.lineWidth=Math.max(1,y/3),g.beginPath(),g.arc(m,u,y,0,Math.PI*2),g.stroke(),g.beginPath(),g.moveTo(m-b,u),g.lineTo(m+b,u),g.moveTo(m,u-b),g.lineTo(m,u+b),g.stroke()}return new Promise(m=>h.toBlob(m,"image/png"))}catch{return Promise.resolve(null)}}function zp(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
|
|
3
|
+
`)}function Ux(r,n,s){const l=n*Math.PI/360,f=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(f)*1.15}async function Wp(r,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(r,n);return}const f=new Date().toISOString(),c=new AbortController;let h,g;try{g=await Promise.race([(async()=>{const p=await s.snapshot;if(!(!p||c.signal.aborted||!l.isCurrent()))return l.upload(new File([p],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(p=>{h=setTimeout(()=>{c.abort(),p(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(g?zp(r,"",f,g):r,n)}function Gp(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function Yd(r,n){return`${r??""}\0${n}`}function Kp(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=Yd(n,s);let f=0,c=0;for(const h of r){const g=[h.filePath,h.newPath,h.oldPath].filter(m=>typeof m=="string"&&m.length>0);(g.some(m=>Yd(h.repoRoot,m)===l)||g.some(m=>Gp(m,s)))&&(f+=1)}return{explained:f,stale:c}}function qp({status:r}){if(!r)return null;const n=r.stale>0&&r.explained===0;if(!(r.explained>0||r.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(gp,{size:10}):e.jsx(Js,{size:10})})}function ol({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(qp,{status:n})]})}const qu="termdock:right-sidebar:diff-change-list-mode:v1";function Vp(r){return r==="list"||r==="tree"}function Yp(){return mt(qu,Vp)??"tree"}function Xp(r){for(const n of r){const s=n.hunk;if(s.oldPath&&s.newPath&&s.oldPath!==s.newPath)return"renamed";if(s.oldPath===null&&s.newPath)return"added";if(s.oldPath&&s.newPath===null)return"deleted"}return"modified"}function Jp(r){const n=new Map;for(const l of r){const f=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};f.items.push(l),f.additions+=l.hunk.additions,f.deletions+=l.hunk.deletions,l.current&&(f.explained+=1),l.stale&&(f.stale+=1),n.set(l.hunk.filePath,f)}const s=Array.from(n.values()).sort((l,f)=>l.filePath.localeCompare(f.filePath));for(const l of s)l.changeType=Xp(l.items);return s}function Qp(r){const n=r.filePath.split("/").pop()??r.filePath;return{key:r.key,path:r.filePath,displayName:n,displayDir:r.filePath.includes("/")?r.filePath.slice(0,-n.length-1):"",status:r.changeType,title:r.filePath}}function Zp(r,n){const s=r.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],f=new Set;for(const[c,h]of s.entries()){const g=h.split(`
|
|
4
|
+
`),p=g.findIndex(y=>y.startsWith("@@ "));if(p<0){l.push(...g);continue}c===0&&l.push(...g.slice(0,p));const m=n[c];let u=p;for(;u>=0&&u<g.length;){const y=g.findIndex((U,C)=>C>u&&U.startsWith("@@ ")),b=y>=0?y:g.length,$=g.slice(u,b),T=$[0]??"",I=m?T===m:!0,D=T||m||$.join(`
|
|
5
|
+
`);I&&!f.has(D)&&(l.push(...$),f.add(D)),u=y}}return l.join(`
|
|
6
|
+
`)}function eg({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Zp(s.items.map(p=>p.hunk.diff||p.current?.diff||p.stale?.diff||""),s.items.map(p=>p.hunk.hunkHeader)),f=s.items.map(p=>p.current??p.stale).filter(p=>!!p).map(p=>({id:p.id,repoRoot:p.repoRoot,filePath:p.filePath,oldPath:p.oldPath,newPath:p.newPath,hunkHeader:p.hunkHeader,hunkIndex:p.hunkIndex,fingerprint:p.fingerprint,diff:p.diff,explanation:p.explanation,summary:p.summary,workspaceRoot:p.workspaceRoot,generatedBy:p.generatedBy,injectedAt:p.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"",g=s.items[0]?.repoRoot??f[0]?.repoRoot??null;return{key:s.key,path:s.filePath,oldPath:s.items[0]?.hunk.oldPath??void 0,absolutePath:g?`${g}/${s.items[0]?.repositoryPath??s.filePath}`:s.filePath,status:s.changeType,repoRoot:g,displayName:c,displayDir:h,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(p=>p.hunk.previewRevert?[[p.hunk.hunkHeader,p.hunk.previewRevert]]:[])),auditRecords:f,onInsertDiffReference:n}})}function tg(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let h=null,g=Number.POSITIVE_INFINITY;for(const m of l){const u=m.getBoundingClientRect();if(u.bottom<c)continue;const y=Math.abs(u.top-c);y<g&&(h=m,g=y)}const p=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!p||p===n||s(p),p}function Xd({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:f=!1,backLabel:c="Back",headerTitle:h,headerMeta:g,onClose:p,closeLabel:m="Back",wrap:u=!0,diffViewType:y,inlineMode:b,viewControls:$,onToggleWrap:T,wrapTitle:I,wrapOnLabel:D="Wrap on",wrapOffLabel:U="Wrap off",desktopLayout:C="split",onInsertDiffReference:R,onReferenceCopied:M,renderPathReference:H,insertedReferenceKey:F,copiedReferenceKey:S,onClearAuditRecord:o,onRefresh:O,localOptions:P,onHunkGitAction:V,error:E,refreshing:K,actionsBusy:pe,refreshLabel:W,refreshTitle:ee,walkthroughs:A=[],onWalkthroughNavigate:B,initialDetailScrollTop:J,onDetailScrollPositionChange:ue,scrollToKey:me,scrollToKeyNonce:ye,externalSwiperRef:je,onMobileSlideChange:Ne}){const{t:L}=pt(),Q=a.useMemo(()=>Jp(r),[r]),ne=a.useMemo(()=>new Map(Q.map(re=>[re.key,re])),[Q]),[Le,Ye]=a.useState(()=>Yp()),[De,rt]=a.useState(()=>new Set),[_e,N]=a.useState({key:null,nonce:0}),se=Q.find(re=>re.explained>0||re.stale>0)?.key??Q[0]?.key??null,fe=n&&Q.some(re=>re.key===n)?n:se,Ee=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:Q.map(Qp)}],[Q]),Me=a.useMemo(()=>eg({groups:Q,onInsertDiffReference:R}),[Q,R]),Ke=a.useRef(se),le=a.useRef(s);Ke.current=se,le.current=s,a.useEffect(()=>{!n&&Ke.current&&le.current(Ke.current)},[n]);const Pe=T?e.jsxs("button",{type:"button",onClick:T,"aria-pressed":u,title:I,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?D:U})]}):null,dt=P?.map(re=>e.jsxs("label",{title:re.disabled?L("rightSidebar.includeUncommittedCurrentBranchOnly"):re.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:re.checked,disabled:K||pe||re.disabled&&!re.checked,onChange:Te=>re.onChange(Te.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[re.label," · ",L("rightSidebar.includeUncommitted"),re.disabled&&e.jsx("span",{className:"block text-[10px]",children:L("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},re.key)),Ae=E?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:E}):null,ke=O?e.jsxs("button",{type:"button",onClick:O,disabled:K||pe,title:ee??W,"aria-label":ee??W,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(Au,{size:12,className:K?"animate-spin":""}),W&&e.jsx("span",{children:W})]}):null,ut=re=>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}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),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(Vs,{size:14}),m]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[re,dt,ke,$,Pe,Ae]})]});if(r.length===0){const re=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?re:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[ut(null),re]})}const Qe=T||O?({slideToList:re})=>e.jsxs("div",{className:"flex flex-wrap 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:re,children:[e.jsx(Vs,{size:14}),c]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[dt,ke,$,T&&e.jsxs("button",{type:"button",onClick:T,"aria-pressed":u,title:I,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?D:U})]})]}),Ae]}):void 0;return e.jsx(tl,{mobile:f,preserveScrollOnUpdate:!!P?.length,desktopLayout:C,backLabel:c,groups:Ee,selectedKey:fe,mode:Le,onModeChange:re=>{Ye(re),re!=="ai"&&Lt(qu,re)},compact:f,collapsedDirectoryKeys:De,onToggleDirectory:re=>{rt(Te=>{const et=new Set(Te);return et.has(re)?et.delete(re):et.add(re),et})},onSelectFile:re=>{s(re.key),N(Te=>({key:re.key,nonce:Te.nonce+1}))},renderLeading:re=>{const Te=ne.get(re.key);return e.jsx(ol,{changeStatus:re.status,auditStatus:Te,renderChangeBadge:et=>e.jsx(Gs,{status:et})})},renderTrailing:re=>{const Te=ne.get(re.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[Te&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Te.additions," -",Te.deletions]}),H?.(re.path,"file")]})},renderDirectoryTrailing:re=>H?.(re,"directory"),renderListHeader:ut,aiContent:({slideToDetail:re,fullscreen:Te,toggleFullscreen:et})=>A.length>0&&B?e.jsx(Bu,{walkthroughs:A,repoRoot:A[0]?.repoRoot,fullscreen:Te,onToggleFullscreen:et,onNavigate:Ot=>{f&&window.requestAnimationFrame(re),B(Ot)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:L("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Qe,externalSwiperRef:je,onMobileSlideChange:Ne,detailContainerClassName:f?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:J,scrollToKey:me??_e.key,scrollToKeyNonce:me==null?_e.nonce:ye,onDetailScroll:re=>{tg(re,fe,s),ue?.(re.scrollTop)},files:Me,activePane:!0,wrap:u,diffViewType:y,inlineMode:b,renderStreamBadge:(re,Te)=>{const et=ne.get(Te.key);return e.jsx(ol,{changeStatus:re,auditStatus:et,renderChangeBadge:Ot=>e.jsx(Gs,{status:Ot})})},onInsertDiffReference:R,onReferenceCopied:M,insertedReferenceKey:F,copiedReferenceKey:S,onClearAuditRecord:o,onHunkGitAction:K?void 0:V,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function rg(r){return r.replace(/\/+$/,"")||"/"}function ng(r){return[...new Set(Array.from(r,rg))].sort((n,s)=>n.localeCompare(s))}function sg(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function ag(r){let n=null;return{applicableEvents:r.filter(l=>{const f=l.type==="rescan-required"&&!sg(l.reason);return f&&l.reason&&!n&&(n=l.reason),!f}),unavailableReason:n}}const og=1400,ig=1200,Vu=44,lg=.7;function Di(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function il(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function cg(r){try{const n=window.localStorage.getItem(il(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Vu?s:null}catch{return null}}function Jd(r,n){try{n===null?window.localStorage.removeItem(il(r)):window.localStorage.setItem(il(r),String(n))}catch{}}function Qa(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function dg({value:r,collapsed:n,labels:s,focusRequest:l,insertError:f,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:g,onAutoCollapseAfterSendChange:p,onDisable:m,onClear:u,onInsert:y,onInsertAndSend:b}){const[$,T]=a.useState(null),[I,D]=a.useState(!1),[U,C]=a.useState(()=>cg(Di())),R=a.useRef(U),M=a.useRef(null),H=a.useRef(null),F=a.useRef(r),S=a.useRef(null),o=a.useRef(null),O=!!r.trim(),P=r.trim().split(`
|
|
7
|
+
`)[0]??"",V=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{M.current!==null&&window.clearTimeout(M.current),H.current!==null&&window.clearTimeout(H.current)},[]),a.useEffect(()=>{let L=!1;const Q=Di();return $u().then(ne=>{if(L)return;const Le=ne.contextDraftHeight?.[Q]??null;Jd(Q,Le),R.current=Le,C(Le)}).catch(()=>{}),()=>{L=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const L=S.current;if(!L)return;Qa()||L.focus(),L.setSelectionRange(L.value.length,L.value.length),L.scrollTop=L.scrollHeight}},[l]),a.useEffect(()=>{const L=F.current;F.current=r,!(!n||r.length<=L.length)&&(D(!0),H.current!==null&&window.clearTimeout(H.current),H.current=window.setTimeout(()=>{H.current=null,D(!1)},ig))},[r,n]),a.useEffect(()=>{if(n)return;const L=S.current;L&&(L.style.height=U!==null?`${U}px`:"")},[r,n,U]),a.useEffect(()=>{if(n)return;const L=S.current;!L||document.activeElement===L||(L.scrollTop=L.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||Qa())return;const L=S.current;!L||document.activeElement===L||(L.focus(),L.setSelectionRange(L.value.length,L.value.length))},[n]);const E=a.useRef(null);a.useLayoutEffect(()=>{if(!Qa())return;const L=window.visualViewport;if(!L)return;const Q=()=>{const ne=E.current;if(!ne)return;if(L.height>=window.innerHeight*.75){ne.style.transform="";return}const Le=ne.getBoundingClientRect(),Ye=Math.round(L.height-Le.bottom);ne.style.transform=Ye!==0?`translateY(${Ye}px)`:""};return Q(),L.addEventListener("resize",Q),L.addEventListener("scroll",Q),()=>{L.removeEventListener("resize",Q),L.removeEventListener("scroll",Q),E.current&&(E.current.style.transform="")}},[n]);const K=L=>{T(L),M.current!==null&&window.clearTimeout(M.current),M.current=window.setTimeout(()=>{M.current=null,T(null)},og)},pe=L=>{g(!1),Qa()&&window.requestAnimationFrame(()=>{const Q=S.current;if(!Q)return;Q.focus();const ne=Q.value.length;Q.setSelectionRange(ne,ne),window.requestAnimationFrame(()=>{Q.setSelectionRange(ne,ne)})})},W=()=>{y(),K("inserted")},ee=()=>{O&&(b(),K("sent"))},A=L=>{if(L.key==="Escape"){L.preventDefault(),g(!0);return}L.key!=="Enter"||!L.metaKey&&!L.ctrlKey||(L.preventDefault(),ee())},B=L=>{L.preventDefault()},J=L=>{L.preventDefault();const Q=S.current;Q&&(o.current={startY:L.clientY,startHeight:Q.getBoundingClientRect().height},L.currentTarget.setPointerCapture?.(L.pointerId))},ue=L=>{const Q=o.current;if(!Q)return;const ne=window.visualViewport?.height??window.innerHeight,Le=Math.round(Math.min(Math.max(Q.startHeight+(Q.startY-L.clientY),Vu),ne*lg));R.current=Le,C(Le)},me=L=>{const Q=Di();Jd(Q,L),lo({contextDraftHeight:{[Q]:L}}).catch(()=>{})},ye=()=>{o.current&&(o.current=null,R.current!==null&&me(R.current))},je=()=>{R.current=null,C(null),me(null)},Ne=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:E,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:()=>pe(),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(Gm,{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] ${f?"text-destructive":I?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:f??(I?s.appended:O?P:s.title)})]}),Ne,e.jsx("button",{type:"button",onClick:ee,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:$==="sent"?e.jsx(go,{size:12}):e.jsx(_d,{size:12})})]})}):e.jsxs("section",{ref:E,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:J,onPointerMove:ue,onPointerUp:ye,onPointerCancel:ye,onDoubleClick:je,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:B,onClick:()=>g(!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(Ys,{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}),Ne]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:B,onClick:()=>p(!c),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 ${c?"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 ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:B,onClick:m,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(Pt,{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:S,value:r,onChange:L=>h(L.target.value),onKeyDown:A,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:B,onClick:u,disabled:!O,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(co,{size:11})}),f?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:f}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:B,onClick:W,disabled:!O,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(Km,{size:11}),e.jsx("span",{children:$==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:B,onClick:ee,disabled:!O,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} · ${V}`,children:[$==="sent"?e.jsx(go,{size:11}):e.jsx(_d,{size:11}),e.jsx("span",{children:$==="sent"?s.sent:s.send})]})]})]})})]})}function ug(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
|
|
12
8
|
|
|
13
9
|
`)?"":r.endsWith(`
|
|
14
10
|
`)?`
|
|
15
11
|
`:`
|
|
16
12
|
|
|
17
|
-
`;return`${r}${l}${s}`}function dg(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const il="termdock:right-sidebar:html-view-mode-by-file:v1";function ug(r){return r==="preview"||r==="source"}function Ku(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(ug)}function qu(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function Yd(r,n){const s=qu(r,n);return s?ht(il,Ku)?.[s]??"source":"source"}function fg(r,n,s){const l=qu(r,n);if(!l)return;const f=ht(il,Ku)??{};Lt(il,{...f,[l]:s})}function hg(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const mg=1500,Xd=256*1024*1024;async function pg(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",f=s.body?.getReader();if(!f){const g=await s.blob();if(g.size>Xd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const c=[];let h=0;try{for(;;){const{done:g,value:p}=await f.read();if(g)break;if(h+=p.byteLength,h>Xd)throw new Error("Media too large for encrypted fallback");c.push(p)}}catch(g){throw await f.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(c,{type:l}))}function Ro(r,n){const s=hg(r),[l,f]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const p=navigator.serviceWorker,m=()=>f(!!p?.controller);return p?.addEventListener("controllerchange",m),m(),()=>p?.removeEventListener("controllerchange",m)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let p=!1,m;const u=new AbortController,k=window.setTimeout(()=>{pg(r,u.signal).then(b=>{if(p){URL.revokeObjectURL(b);return}m=b,h(b)}).catch(()=>{p||u.signal.aborted||g.current?.()})},mg);return()=>{p=!0,window.clearTimeout(k),u.abort(),m&&URL.revokeObjectURL(m)}},[s,l,r]),!s||l?r:c}function Fi(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),f=n%60,c=String(l).padStart(2,"0"),h=String(f).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function gg(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const Yr=2,bg=8,xg=60,Za=5,Jd=.05,vg=900;function wg(r){return!Number.isFinite(r)||r<=0?Yr:Math.min(bg,Yr+Math.floor(r/xg))}const yg=350,kg=6,Sg=90;function jg({url:r,onLoadError:n}){const s=Ro(r,n),{t:l}=bt(),f=a.useRef(null),c=a.useRef(null),h=a.useRef(null),g=a.useRef(null),p=a.useRef(!1),m=a.useRef(null),u=a.useRef(null),k=a.useRef(0),b=a.useRef(!1),M=a.useRef(!1),A=a.useRef(!1),F=a.useRef(null),B=a.useRef(null),D=a.useRef(!1),C=a.useRef(1),E=a.useRef(!1),[T,U]=a.useState(0),[L,w]=a.useState(0),[o,O]=a.useState(!1),[H,W]=a.useState(!1),[N,q]=a.useState(null),[fe,G]=a.useState(!1),[ee,P]=a.useState(0),[_,J]=a.useState(!1),[ue,pe]=a.useState({width:0,height:0}),[we,je]=a.useState(Yr),[Ce,$]=a.useState(1),[Q,ne]=a.useState(null),Le=a.useRef(Yr),Ye=a.useRef(null),De=a.useCallback(()=>{F.current!==null&&(clearTimeout(F.current),F.current=null)},[]),rt=a.useCallback(()=>{De();const z=B.current;if(B.current=null,!D.current)return!1;const ae=h.current;if(ae&&(ae.playbackRate=C.current,z))try{ae.releasePointerCapture?.(z.id)}catch{}return D.current=!1,Le.current=Yr,G(!1),!0},[De]);a.useEffect(()=>()=>{m.current!==null&&cancelAnimationFrame(m.current),u.current!==null&&clearTimeout(u.current),Ye.current!==null&&clearTimeout(Ye.current),De();const z=h.current;z&&D.current&&(z.playbackRate=C.current)},[De]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const ae=new ResizeObserver(([ve])=>{ve&&pe({width:ve.contentRect.width,height:ve.contentRect.height})});return ae.observe(z),()=>ae.disconnect()},[]),a.useEffect(()=>{const z=()=>J(document.fullscreenElement===f.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const _e=a.useCallback((z,ae=!1)=>{const ve=h.current;if(!ve)return!1;const Xe=Number.isFinite(ve.duration)?ve.duration:z,Nt=Math.min(Math.max(z,0),Xe);if(w(Nt),Math.abs(ve.currentTime-Nt)<1/120)return!1;const ir=ve.fastSeek;return ae&&typeof ir=="function"?ir.call(ve,Nt):ve.currentTime=Nt,!0},[]),R=a.useCallback(()=>{m.current===null&&(m.current=requestAnimationFrame(()=>{m.current=null;const z=h.current;if(!z||!b.current||M.current||z.seeking)return;const ae=A.current;A.current=!1,M.current=_e(k.current,!ae)}))},[_e]),se=a.useCallback(z=>{const ae=g.current,ve=h.current;if(!ae||!ve)return;const Xe=ae.getBoundingClientRect(),Nt=gg(z,Xe,ve.duration);k.current=Nt,q(Nt),A.current=!1,R(),u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,A.current=!0,R()},Sg)},[R]),he=a.useCallback(()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),u.current!==null&&(clearTimeout(u.current),u.current=null),A.current=!1,M.current=!1,_e(k.current)},[_e]),Ee=a.useCallback(z=>{const ae=h.current;if(!(!ae||!Number.isFinite(ae.duration)||ae.duration<=0)){p.current=!ae.paused,ae.pause(),b.current=!0,W(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}se(z.clientX)}},[se]),Me=a.useCallback(()=>{b.current=!1,he(),W(!1),q(null);const z=h.current;z&&p.current&&!z.ended&&z.play().catch(()=>{}),p.current=!1},[he]),Ke=a.useCallback(()=>{const z=h.current;if(z){if(E.current){E.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),le=a.useCallback(z=>{const ae=h.current;if(!ae)return;const ve=Math.min(1,Math.max(0,Math.round((ae.volume+z)*100)/100));ae.volume=ve,ve>0&&(ae.muted=!1),$(ve),ne(ve),Ye.current!==null&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ye.current=null,ne(null)},vg)},[]),Ae=a.useCallback(z=>{const ae=h.current;if(ae){if(z.key==="ArrowLeft"){z.preventDefault(),_e(ae.currentTime-(z.shiftKey?Za*2:Za));return}if(z.key==="ArrowRight"){z.preventDefault(),_e(ae.currentTime+(z.shiftKey?Za*2:Za));return}if(z.key==="ArrowUp"){z.preventDefault(),le(Jd);return}if(z.key==="ArrowDown"){z.preventDefault(),le(-Jd);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),ae.paused?ae.play().catch(()=>{}):ae.pause())}},[_e,le]),dt=a.useCallback(z=>{const ae=h.current;!ae||ae.paused||z.button!==0||(De(),B.current={id:z.pointerId,x:z.clientX,y:z.clientY},F.current=setTimeout(()=>{F.current=null;const ve=B.current;if(C.current=ae.playbackRate,ae.playbackRate=Yr,Le.current=Yr,je(Yr),D.current=!0,G(!0),ve)try{ae.setPointerCapture?.(ve.id)}catch{}},yg))},[De]),Pe=a.useCallback(z=>{const ae=B.current;if(!ae||ae.id!==z.pointerId)return;if(!D.current){Math.hypot(z.clientX-ae.x,z.clientY-ae.y)>kg&&(De(),B.current=null);return}const ve=wg(z.clientX-ae.x);if(ve===Le.current)return;Le.current=ve,je(ve);const Xe=h.current;Xe&&(Xe.playbackRate=ve)},[De]),ke=a.useCallback(()=>{rt()&&(E.current=!0)},[rt]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const ut=a.useCallback(async()=>{const z=f.current,ae=h.current;if(!(!z||!ae))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():ae.webkitEnterFullscreen?.()}catch{ae.webkitEnterFullscreen?.()}},[]),Qe=a.useCallback(()=>P(z=>(z+90)%360),[]),re=a.useCallback(z=>{const ae=h.current;if(!ae||!Number.isFinite(ae.duration))return;const ve=z.shiftKey?10:5;let Xe=null;z.key==="ArrowLeft"?Xe=ae.currentTime-ve:z.key==="ArrowRight"?Xe=ae.currentTime+ve:z.key==="Home"?Xe=0:z.key==="End"&&(Xe=ae.duration),Xe!==null&&(z.preventDefault(),_e(Xe))},[_e]),Te=H&&N!==null?N:L,et=T>0?Math.min(1,Math.max(0,Te/T)):0,lt=(ee===90||ee===270)&&ue.width>0&&ue.height>0?{width:`${ue.height}px`,height:`${ue.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:f,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":ee,children:[e.jsxs("div",{ref:c,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 outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${fe?` ${Hd}`:""}`,style:{...lt,transform:`translate(-50%, -50%) rotate(${ee}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...fe?{[zd]:""}:{},onClick:Ke,onKeyDown:Ae,onVolumeChange:z=>$(z.currentTarget.volume),onPointerDown:dt,onPointerMove:Pe,onPointerUp:ke,onPointerCancel:ke,onContextMenu:z=>{D.current&&z.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:z=>w(z.currentTarget.currentTime),onSeeked:z=>{const ae=z.currentTarget;if(w(ae.currentTime),M.current=!1,!b.current)return;const ve=ae.requestVideoFrameCallback;typeof ve=="function"?ve.call(ae,()=>{b.current&&R()}):requestAnimationFrame(()=>{b.current&&R()})},onLoadedMetadata:z=>U(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onDurationChange:z=>U(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),fe&&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",{rate:String(we)})}),Q!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(Gm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(Ce*100)})]}),H&&N!==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:`${et*100}%`},"data-testid":"file-preview-video-scrub-time",children:Fi(N)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Hd}`,[zd]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ke,"aria-label":l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(o?"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:o?e.jsx(Km,{size:14}):e.jsx(qm,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(Te),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:z=>{H&&se(z.clientX)},onPointerUp:Me,onPointerCancel:Me,onKeyDown:re,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:`${et*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:`${et*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Fi(Te)," / ",Fi(T)]}),e.jsx("button",{type:"button",onClick:Qe,"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(Mu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{ut()},"aria-label":l(_?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(_?"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:_?e.jsx(Vm,{size:14}):e.jsx(Ym,{size:14})})]})})]})}function Rg(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.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 Co({anchor:r,children:n,disabled:s=!1,onClick:l,title:f}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:f,style:Rg(r),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(bo,{size:11}),n]})}function Cg(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const f=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(f)||f<=0)return null;const c=l.width*f,h=l.height*f,g=s.left+(s.width-c)/2,p=s.top+(s.height-h)/2,m=r-g,u=n-p;if(m<0||u<0||m>c||u>h)return null;const k=m/c*100,b=u/h*100;return{x:l.x+l.width*k/100,y:l.y+l.height*b/100,xPercent:k,yPercent:b}}function Ng(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${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 Eg(r){const n=new DOMParser().parseFromString(r,"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 f of Array.from(l.attributes)){const c=f.name.toLowerCase(),h=f.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(f.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function Mg(r,n,s){let l=null;for(const f of Array.from(r.querySelectorAll("text"))){const c=(f.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(f.getAttribute("x")),g=Number(f.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(g))continue;const p=Math.hypot(h-n,g-s);(!l||p<l.distance)&&(l={text:c,distance:p})}return l?.text.slice(0,120)}function Vu({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const f=a.useRef(null),c=a.useRef(null),[h,g]=a.useState(null),[p,m]=a.useState(null),[u,k]=a.useState(1),[b,M]=a.useState(!1),[A,F]=a.useState(null),B=a.useRef(new Map),D=a.useRef(null),C=a.useRef(!1),E=a.useRef(null),T=a.useRef(u);T.current=u,a.useEffect(()=>{const P=new AbortController;return g(null),m(null),F(null),k(1),fetch(r,{signal:P.signal}).then(_=>_.text()).then(_=>g(Eg(_))).catch(_=>{P.signal.aborted||m(_ instanceof Error?_.message:"SVG preview failed")}),()=>P.abort()},[r]),a.useEffect(()=>{if(!b)return;const P=_=>{_.key==="Escape"&&M(!1)};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[b]),a.useLayoutEffect(()=>{const P=c.current,_=P?.querySelector("[data-svg-document] > svg");if(!P||!_)return;let J;try{J=_.getBBox()}catch{return}if(!J.width||!J.height)return;const ue=Math.max(2,Math.min(J.width,J.height)*.025);_.setAttribute("viewBox",`${J.x-ue} ${J.y-ue} ${J.width+2*ue} ${J.height+2*ue}`),_.style.width=`${u*100}%`,_.style.height=`${u*100}%`,_.style.minWidth=`${u*100}%`,_.style.minHeight=`${u*100}%`,_.style.display="block"},[h,u]);const U=a.useMemo(()=>A?Ng(n,s,A):null,[n,A,s]),L=P=>{if(C.current){C.current=!1;return}const _=c.current,J=_?.querySelector("[data-svg-document] > svg"),ue=f.current;if(!_||!J||!ue)return;const pe=J.viewBox.baseVal,we=Cg(P.clientX,P.clientY,J.getBoundingClientRect(),pe);if(!we)return;const je=ue.getBoundingClientRect();F({...we,nearestText:Mg(J,we.x,we.y),stageX:P.clientX-je.left,stageY:P.clientY-je.top,stageXPercent:(P.clientX-je.left)/je.width*100,stageYPercent:(P.clientY-je.top)/je.height*100})},w=P=>Math.max(1,Math.min(12,P)),o=(P,_)=>{const J=w(_),ue=P.querySelector("[data-svg-document] > svg");if(!ue)return J;const pe=`${J*100}%`;return ue.style.width=pe,ue.style.height=pe,ue.style.minWidth=pe,ue.style.minHeight=pe,T.current=J,J},O=(P,_,J,ue)=>{const pe=T.current,we=P.getBoundingClientRect(),je=J-we.left,Ce=ue-we.top,$=(P.scrollLeft+je)/pe,Q=(P.scrollTop+Ce)/pe,ne=o(P,_);return P.scrollLeft=$*ne-je,P.scrollTop=Q*ne-Ce,ne},H=()=>{const P=Array.from(B.current.values());return P.length>=2?Math.hypot(P[0].x-P[1].x,P[0].y-P[1].y):0},W=P=>{if(P.pointerType==="mouse"&&P.button!==0)return;const _=c.current;_&&(B.current.set(P.pointerId,{x:P.clientX,y:P.clientY}),_.setPointerCapture?.(P.pointerId),B.current.size>=2?(D.current={kind:"pinch",startX:P.clientX,startY:P.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startDistance:H(),startZoom:T.current,moved:!1},C.current=!0):T.current>1&&(D.current={kind:"pan",startX:P.clientX,startY:P.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}))},N=P=>{if(!B.current.has(P.pointerId))return;B.current.set(P.pointerId,{x:P.clientX,y:P.clientY});const _=c.current,J=D.current;if(!(!_||!J)){if(B.current.size>=2&&J.kind==="pinch"){const ue=H();if(!J.startDistance||!ue)return;const pe=w(J.startZoom*ue/J.startDistance);if(Math.abs(pe-T.current)<.01)return;const we=Array.from(B.current.values()),je=(we[0].x+we[1].x)/2,Ce=(we[0].y+we[1].y)/2;J.moved=!0,C.current=!0,O(_,pe,je,Ce),P.preventDefault();return}if(J.kind==="pan"&&B.current.size===1){const ue=P.clientX-J.startX,pe=P.clientY-J.startY;if(!J.moved&&Math.hypot(ue,pe)<6)return;J.moved=!0,C.current=!0,_.scrollLeft=J.startScrollLeft-ue,_.scrollTop=J.startScrollTop-pe,P.preventDefault()}}},q=P=>{const _=c.current,J=D.current,ue=B.current.size===1&&!J?.moved;B.current.delete(P.pointerId);try{_?.releasePointerCapture?.(P.pointerId)}catch{}if(B.current.size===1&&J?.kind==="pinch"){const je=Array.from(B.current.values())[0];D.current=_?{kind:"pan",startX:je.x,startY:je.y,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(D.current=null,J?.kind==="pinch"&&k(T.current),!ue||C.current))return;const pe=Date.now(),we=E.current;we&&pe-we.time<350&&Math.hypot(P.clientX-we.x,P.clientY-we.y)<24?(E.current=null,C.current=!0,k(je=>je>1?1:2.5)):E.current={time:pe,x:P.clientX,y:P.clientY}},fe=P=>{if(!P.ctrlKey&&!P.metaKey)return;const _=c.current;if(!_)return;P.preventDefault();const J=O(_,T.current*Math.exp(-P.deltaY*.01),P.clientX,P.clientY);k(J)},G=()=>{k(1),T.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},ee=e.jsxs("div",{className:b?"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:f,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:L,onDoubleClick:P=>{P.preventDefault(),k(_=>_>1?1:2.5)},onPointerDown:W,onPointerMove:N,onPointerUp:q,onPointerCancel:q,onWheel:fe,onScroll:()=>F(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…"})}),A&&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:A.stageX,top:A.stageY}}),A&&U&&e.jsx(Co,{anchor:{xPercent:A.stageXPercent,yPercent:A.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${A.x.toFixed(2)}:${A.y.toFixed(2)}`),F(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:P=>{P.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(Ap,{size:14})}),e.jsx("button",{type:"button","aria-label":b?"退出全屏 SVG":"全屏 SVG",title:b?"退出全屏 SVG":"全屏 SVG",onClick:P=>{P.stopPropagation(),M(_=>!_)},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:b?e.jsx(Fu,{size:14}):e.jsx(Iu,{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:A?`SVG (${A.x.toFixed(2)}, ${A.y.toFixed(2)}) · ${A.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return b?kr.createPortal(ee,document.body):ee}function fo(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function $g(r,n,s,l){const f=[`电子标注: ${r}`,`视图: ${fo(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(f.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&f.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");f.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${f.join(" / ")}"`}function Lg({blobUrl:r,filePath:n,view:s,board:l,onViewChange:f,onInsertAnnotation:c,onRefresh:h,interactive3d:g}){const{t:p}=bt(),m=a.useRef(null),u=a.useRef(null),k=a.useRef(null),[b,M]=a.useState(null),[A,F]=a.useState(!1);a.useEffect(()=>(k.current?.abort(),M(null),F(!1),()=>k.current?.abort()),[r,s]);const B=a.useMemo(()=>b?$g(n,s,b,b.inspection):null,[n,b,s]),D=E=>{const T=m.current,U=u.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const L=T.getBoundingClientRect(),w=U.getBoundingClientRect(),o=Math.min(w.width/U.naturalWidth,w.height/U.naturalHeight),O=U.naturalWidth*o,H=U.naturalHeight*o,W=w.left+(w.width-O)/2,N=w.top+(w.height-H)/2,q=E.clientX-W,fe=E.clientY-N;if(q<0||fe<0||q>O||fe>H)return;const G={xPercent:Math.max(0,Math.min(100,q/O*100)),yPercent:Math.max(0,Math.min(100,fe/H*100)),stageXPercent:(E.clientX-L.left)/L.width*100,stageYPercent:(E.clientY-L.top)/L.height*100,inspecting:l&&s!=="pcb-3d"};if(M(G),k.current?.abort(),!G.inspecting)return;const ee=new AbortController;k.current=ee,fm(n,s,G.xPercent,G.yPercent,ee.signal).then(P=>M(_=>_===G?{..._,inspection:P,inspecting:!1}:_)).catch(()=>{ee.signal.aborted||M(P=>P===G?{...P,inspection:{available:!1},inspecting:!1}:P)})},C=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:C.map(E=>e.jsx("button",{type:"button",onClick:()=>f(E),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${E===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:fo(E)},E))}),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(uo,{size:13})})]}),l&&g?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:g}):null,l?s==="pcb-3d"?g?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:m,role:"button",tabIndex:0,onClick:D,onKeyDown:E=>{E.key!=="Enter"&&E.key!==" "||(E.preventDefault(),M({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:r,alt:`${n} ${fo(s)}`,onLoad:()=>F(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${A?"opacity-100":"opacity-0"}`}),b&&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:`${b.stageXPercent}%`,top:`${b.stageYPercent}%`}}),b&&B&&e.jsx(Co,{anchor:{xPercent:b.stageXPercent,yPercent:b.stageYPercent},disabled:b.inspecting,title:p("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${b.xPercent.toFixed(1)}:${b.yPercent.toFixed(1)}`,{snapshot:u.current?Op(u.current,b):Promise.resolve(null)}),M(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:b?b.inspecting?p("rightSidebar.edaInspecting"):b.inspection?.available?p("rightSidebar.edaPickedBoardPosition",{x:b.inspection.xMm?.toFixed(2)??"—",y:b.inspection.yMm?.toFixed(2)??"—",object:b.inspection.nearest?.label??p("rightSidebar.edaNoNearbyObject")}):p("rightSidebar.edaPickedPosition",{x:b.xPercent.toFixed(1),y:b.yPercent.toFixed(1)}):p("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Vu,{blobUrl:r,filePath:n,viewLabel:fo(s),onInsertAnnotation:c})})]})}function Ag(r){const n=[];let s=[],l="",f=!1;for(let c=0;c<r.length;c+=1){const h=r[c];f?h==='"'&&r[c+1]==='"'?(l+='"',c+=1):h==='"'?f=!1:l+=h:h==='"'?f=!0:h===","?(s.push(l),l=""):h===`
|
|
18
|
-
`?(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`${r}${l}${s}`}function fg(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const ll="termdock:right-sidebar:html-view-mode-by-file:v1";function hg(r){return r==="preview"||r==="source"}function Yu(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(hg)}function Xu(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function Qd(r,n){const s=Xu(r,n);return s?mt(ll,Yu)?.[s]??"source":"source"}function mg(r,n,s){const l=Xu(r,n);if(!l)return;const f=mt(ll,Yu)??{};Lt(ll,{...f,[l]:s})}function pg(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const gg=1500,Zd=256*1024*1024;async function bg(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",f=s.body?.getReader();if(!f){const g=await s.blob();if(g.size>Zd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const c=[];let h=0;try{for(;;){const{done:g,value:p}=await f.read();if(g)break;if(h+=p.byteLength,h>Zd)throw new Error("Media too large for encrypted fallback");c.push(p)}}catch(g){throw await f.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(c,{type:l}))}function Ro(r,n){const s=pg(r),[l,f]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const p=navigator.serviceWorker,m=()=>f(!!p?.controller);return p?.addEventListener("controllerchange",m),m(),()=>p?.removeEventListener("controllerchange",m)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let p=!1,m;const u=new AbortController,y=window.setTimeout(()=>{bg(r,u.signal).then(b=>{if(p){URL.revokeObjectURL(b);return}m=b,h(b)}).catch(()=>{p||u.signal.aborted||g.current?.()})},gg);return()=>{p=!0,window.clearTimeout(y),u.abort(),m&&URL.revokeObjectURL(m)}},[s,l,r]),!s||l?r:c}function Fi(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),f=n%60,c=String(l).padStart(2,"0"),h=String(f).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function xg(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const Yr=2,vg=8,yg=60,Za=5,eu=.05,wg=900;function kg(r){return!Number.isFinite(r)||r<=0?Yr:Math.min(vg,Yr+Math.floor(r/yg))}const Sg=350,jg=6,Rg=90;function Ng({url:r,onLoadError:n}){const s=Ro(r,n),{t:l}=pt(),f=a.useRef(null),c=a.useRef(null),h=a.useRef(null),g=a.useRef(null),p=a.useRef(!1),m=a.useRef(null),u=a.useRef(null),y=a.useRef(0),b=a.useRef(!1),$=a.useRef(!1),T=a.useRef(!1),I=a.useRef(null),D=a.useRef(null),U=a.useRef(!1),C=a.useRef(1),R=a.useRef(!1),[M,H]=a.useState(0),[F,S]=a.useState(0),[o,O]=a.useState(!1),[P,V]=a.useState(!1),[E,K]=a.useState(null),[pe,W]=a.useState(!1),[ee,A]=a.useState(0),[B,J]=a.useState(!1),[ue,me]=a.useState({width:0,height:0}),[ye,je]=a.useState(Yr),[Ne,L]=a.useState(1),[Q,ne]=a.useState(null),Le=a.useRef(Yr),Ye=a.useRef(null),De=a.useCallback(()=>{I.current!==null&&(clearTimeout(I.current),I.current=null)},[]),rt=a.useCallback(()=>{De();const z=D.current;if(D.current=null,!U.current)return!1;const ae=h.current;if(ae&&(ae.playbackRate=C.current,z))try{ae.releasePointerCapture?.(z.id)}catch{}return U.current=!1,Le.current=Yr,W(!1),!0},[De]);a.useEffect(()=>()=>{m.current!==null&&cancelAnimationFrame(m.current),u.current!==null&&clearTimeout(u.current),Ye.current!==null&&clearTimeout(Ye.current),De();const z=h.current;z&&U.current&&(z.playbackRate=C.current)},[De]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const ae=new ResizeObserver(([ve])=>{ve&&me({width:ve.contentRect.width,height:ve.contentRect.height})});return ae.observe(z),()=>ae.disconnect()},[]),a.useEffect(()=>{const z=()=>J(document.fullscreenElement===f.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const _e=a.useCallback((z,ae=!1)=>{const ve=h.current;if(!ve)return!1;const Xe=Number.isFinite(ve.duration)?ve.duration:z,Ct=Math.min(Math.max(z,0),Xe);if(S(Ct),Math.abs(ve.currentTime-Ct)<1/120)return!1;const ir=ve.fastSeek;return ae&&typeof ir=="function"?ir.call(ve,Ct):ve.currentTime=Ct,!0},[]),N=a.useCallback(()=>{m.current===null&&(m.current=requestAnimationFrame(()=>{m.current=null;const z=h.current;if(!z||!b.current||$.current||z.seeking)return;const ae=T.current;T.current=!1,$.current=_e(y.current,!ae)}))},[_e]),se=a.useCallback(z=>{const ae=g.current,ve=h.current;if(!ae||!ve)return;const Xe=ae.getBoundingClientRect(),Ct=xg(z,Xe,ve.duration);y.current=Ct,K(Ct),T.current=!1,N(),u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null,T.current=!0,N()},Rg)},[N]),fe=a.useCallback(()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),u.current!==null&&(clearTimeout(u.current),u.current=null),T.current=!1,$.current=!1,_e(y.current)},[_e]),Ee=a.useCallback(z=>{const ae=h.current;if(!(!ae||!Number.isFinite(ae.duration)||ae.duration<=0)){p.current=!ae.paused,ae.pause(),b.current=!0,V(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}se(z.clientX)}},[se]),Me=a.useCallback(()=>{b.current=!1,fe(),V(!1),K(null);const z=h.current;z&&p.current&&!z.ended&&z.play().catch(()=>{}),p.current=!1},[fe]),Ke=a.useCallback(()=>{const z=h.current;if(z){if(R.current){R.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),le=a.useCallback(z=>{const ae=h.current;if(!ae)return;const ve=Math.min(1,Math.max(0,Math.round((ae.volume+z)*100)/100));ae.volume=ve,ve>0&&(ae.muted=!1),L(ve),ne(ve),Ye.current!==null&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ye.current=null,ne(null)},wg)},[]),Pe=a.useCallback(z=>{const ae=h.current;if(ae){if(z.key==="ArrowLeft"){z.preventDefault(),_e(ae.currentTime-(z.shiftKey?Za*2:Za));return}if(z.key==="ArrowRight"){z.preventDefault(),_e(ae.currentTime+(z.shiftKey?Za*2:Za));return}if(z.key==="ArrowUp"){z.preventDefault(),le(eu);return}if(z.key==="ArrowDown"){z.preventDefault(),le(-eu);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),ae.paused?ae.play().catch(()=>{}):ae.pause())}},[_e,le]),dt=a.useCallback(z=>{const ae=h.current;!ae||ae.paused||z.button!==0||(De(),D.current={id:z.pointerId,x:z.clientX,y:z.clientY},I.current=setTimeout(()=>{I.current=null;const ve=D.current;if(C.current=ae.playbackRate,ae.playbackRate=Yr,Le.current=Yr,je(Yr),U.current=!0,W(!0),ve)try{ae.setPointerCapture?.(ve.id)}catch{}},Sg))},[De]),Ae=a.useCallback(z=>{const ae=D.current;if(!ae||ae.id!==z.pointerId)return;if(!U.current){Math.hypot(z.clientX-ae.x,z.clientY-ae.y)>jg&&(De(),D.current=null);return}const ve=kg(z.clientX-ae.x);if(ve===Le.current)return;Le.current=ve,je(ve);const Xe=h.current;Xe&&(Xe.playbackRate=ve)},[De]),ke=a.useCallback(()=>{rt()&&(R.current=!0)},[rt]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const ut=a.useCallback(async()=>{const z=f.current,ae=h.current;if(!(!z||!ae))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():ae.webkitEnterFullscreen?.()}catch{ae.webkitEnterFullscreen?.()}},[]),Qe=a.useCallback(()=>A(z=>(z+90)%360),[]),re=a.useCallback(z=>{const ae=h.current;if(!ae||!Number.isFinite(ae.duration))return;const ve=z.shiftKey?10:5;let Xe=null;z.key==="ArrowLeft"?Xe=ae.currentTime-ve:z.key==="ArrowRight"?Xe=ae.currentTime+ve:z.key==="Home"?Xe=0:z.key==="End"&&(Xe=ae.duration),Xe!==null&&(z.preventDefault(),_e(Xe))},[_e]),Te=P&&E!==null?E:F,et=M>0?Math.min(1,Math.max(0,Te/M)):0,lt=(ee===90||ee===270)&&ue.width>0&&ue.height>0?{width:`${ue.height}px`,height:`${ue.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:f,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":ee,children:[e.jsxs("div",{ref:c,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 outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${pe?` ${Gd}`:""}`,style:{...lt,transform:`translate(-50%, -50%) rotate(${ee}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...pe?{[Kd]:""}:{},onClick:Ke,onKeyDown:Pe,onVolumeChange:z=>L(z.currentTarget.volume),onPointerDown:dt,onPointerMove:Ae,onPointerUp:ke,onPointerCancel:ke,onContextMenu:z=>{U.current&&z.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:z=>S(z.currentTarget.currentTime),onSeeked:z=>{const ae=z.currentTarget;if(S(ae.currentTime),$.current=!1,!b.current)return;const ve=ae.requestVideoFrameCallback;typeof ve=="function"?ve.call(ae,()=>{b.current&&N()}):requestAnimationFrame(()=>{b.current&&N()})},onLoadedMetadata:z=>H(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onDurationChange:z=>H(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),pe&&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",{rate:String(ye)})}),Q!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(qm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(Ne*100)})]}),P&&E!==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:`${et*100}%`},"data-testid":"file-preview-video-scrub-time",children:Fi(E)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Gd}`,[Kd]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ke,"aria-label":l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(o?"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:o?e.jsx(Vm,{size:14}):e.jsx(Ym,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(M),"aria-valuenow":Math.floor(Te),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:z=>{P&&se(z.clientX)},onPointerUp:Me,onPointerCancel:Me,onKeyDown:re,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:`${et*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:`${et*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Fi(Te)," / ",Fi(M)]}),e.jsx("button",{type:"button",onClick:Qe,"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(Au,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{ut()},"aria-label":l(B?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(B?"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:B?e.jsx(Xm,{size:14}):e.jsx(Jm,{size:14})})]})})]})}function Cg(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.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 No({anchor:r,children:n,disabled:s=!1,onClick:l,title:f}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:f,style:Cg(r),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(bo,{size:11}),n]})}function Eg(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const f=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(f)||f<=0)return null;const c=l.width*f,h=l.height*f,g=s.left+(s.width-c)/2,p=s.top+(s.height-h)/2,m=r-g,u=n-p;if(m<0||u<0||m>c||u>h)return null;const y=m/c*100,b=u/h*100;return{x:l.x+l.width*y/100,y:l.y+l.height*b/100,xPercent:y,yPercent:b}}function Mg(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${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 $g(r){const n=new DOMParser().parseFromString(r,"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 f of Array.from(l.attributes)){const c=f.name.toLowerCase(),h=f.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(f.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function Lg(r,n,s){let l=null;for(const f of Array.from(r.querySelectorAll("text"))){const c=(f.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(f.getAttribute("x")),g=Number(f.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(g))continue;const p=Math.hypot(h-n,g-s);(!l||p<l.distance)&&(l={text:c,distance:p})}return l?.text.slice(0,120)}function Ju({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const f=a.useRef(null),c=a.useRef(null),[h,g]=a.useState(null),[p,m]=a.useState(null),[u,y]=a.useState(1),[b,$]=a.useState(!1),[T,I]=a.useState(null),D=a.useRef(new Map),U=a.useRef(null),C=a.useRef(!1),R=a.useRef(null),M=a.useRef(u);M.current=u,a.useEffect(()=>{const A=new AbortController;return g(null),m(null),I(null),y(1),fetch(r,{signal:A.signal}).then(B=>B.text()).then(B=>g($g(B))).catch(B=>{A.signal.aborted||m(B instanceof Error?B.message:"SVG preview failed")}),()=>A.abort()},[r]),a.useEffect(()=>{if(!b)return;const A=B=>{B.key==="Escape"&&$(!1)};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[b]),a.useLayoutEffect(()=>{const A=c.current,B=A?.querySelector("[data-svg-document] > svg");if(!A||!B)return;let J;try{J=B.getBBox()}catch{return}if(!J.width||!J.height)return;const ue=Math.max(2,Math.min(J.width,J.height)*.025);B.setAttribute("viewBox",`${J.x-ue} ${J.y-ue} ${J.width+2*ue} ${J.height+2*ue}`),B.style.width=`${u*100}%`,B.style.height=`${u*100}%`,B.style.minWidth=`${u*100}%`,B.style.minHeight=`${u*100}%`,B.style.display="block"},[h,u]);const H=a.useMemo(()=>T?Mg(n,s,T):null,[n,T,s]),F=A=>{if(C.current){C.current=!1;return}const B=c.current,J=B?.querySelector("[data-svg-document] > svg"),ue=f.current;if(!B||!J||!ue)return;const me=J.viewBox.baseVal,ye=Eg(A.clientX,A.clientY,J.getBoundingClientRect(),me);if(!ye)return;const je=ue.getBoundingClientRect();I({...ye,nearestText:Lg(J,ye.x,ye.y),stageX:A.clientX-je.left,stageY:A.clientY-je.top,stageXPercent:(A.clientX-je.left)/je.width*100,stageYPercent:(A.clientY-je.top)/je.height*100})},S=A=>Math.max(1,Math.min(12,A)),o=(A,B)=>{const J=S(B),ue=A.querySelector("[data-svg-document] > svg");if(!ue)return J;const me=`${J*100}%`;return ue.style.width=me,ue.style.height=me,ue.style.minWidth=me,ue.style.minHeight=me,M.current=J,J},O=(A,B,J,ue)=>{const me=M.current,ye=A.getBoundingClientRect(),je=J-ye.left,Ne=ue-ye.top,L=(A.scrollLeft+je)/me,Q=(A.scrollTop+Ne)/me,ne=o(A,B);return A.scrollLeft=L*ne-je,A.scrollTop=Q*ne-Ne,ne},P=()=>{const A=Array.from(D.current.values());return A.length>=2?Math.hypot(A[0].x-A[1].x,A[0].y-A[1].y):0},V=A=>{if(A.pointerType==="mouse"&&A.button!==0)return;const B=c.current;B&&(D.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),B.setPointerCapture?.(A.pointerId),D.current.size>=2?(U.current={kind:"pinch",startX:A.clientX,startY:A.clientY,startScrollLeft:B.scrollLeft,startScrollTop:B.scrollTop,startDistance:P(),startZoom:M.current,moved:!1},C.current=!0):M.current>1&&(U.current={kind:"pan",startX:A.clientX,startY:A.clientY,startScrollLeft:B.scrollLeft,startScrollTop:B.scrollTop,startZoom:M.current,moved:!1}))},E=A=>{if(!D.current.has(A.pointerId))return;D.current.set(A.pointerId,{x:A.clientX,y:A.clientY});const B=c.current,J=U.current;if(!(!B||!J)){if(D.current.size>=2&&J.kind==="pinch"){const ue=P();if(!J.startDistance||!ue)return;const me=S(J.startZoom*ue/J.startDistance);if(Math.abs(me-M.current)<.01)return;const ye=Array.from(D.current.values()),je=(ye[0].x+ye[1].x)/2,Ne=(ye[0].y+ye[1].y)/2;J.moved=!0,C.current=!0,O(B,me,je,Ne),A.preventDefault();return}if(J.kind==="pan"&&D.current.size===1){const ue=A.clientX-J.startX,me=A.clientY-J.startY;if(!J.moved&&Math.hypot(ue,me)<6)return;J.moved=!0,C.current=!0,B.scrollLeft=J.startScrollLeft-ue,B.scrollTop=J.startScrollTop-me,A.preventDefault()}}},K=A=>{const B=c.current,J=U.current,ue=D.current.size===1&&!J?.moved;D.current.delete(A.pointerId);try{B?.releasePointerCapture?.(A.pointerId)}catch{}if(D.current.size===1&&J?.kind==="pinch"){const je=Array.from(D.current.values())[0];U.current=B?{kind:"pan",startX:je.x,startY:je.y,startScrollLeft:B.scrollLeft,startScrollTop:B.scrollTop,startZoom:M.current,moved:!1}:null;return}if(D.current.size>0||(U.current=null,J?.kind==="pinch"&&y(M.current),!ue||C.current))return;const me=Date.now(),ye=R.current;ye&&me-ye.time<350&&Math.hypot(A.clientX-ye.x,A.clientY-ye.y)<24?(R.current=null,C.current=!0,y(je=>je>1?1:2.5)):R.current={time:me,x:A.clientX,y:A.clientY}},pe=A=>{if(!A.ctrlKey&&!A.metaKey)return;const B=c.current;if(!B)return;A.preventDefault();const J=O(B,M.current*Math.exp(-A.deltaY*.01),A.clientX,A.clientY);y(J)},W=()=>{y(1),M.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},ee=e.jsxs("div",{className:b?"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:f,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:F,onDoubleClick:A=>{A.preventDefault(),y(B=>B>1?1:2.5)},onPointerDown:V,onPointerMove:E,onPointerUp:K,onPointerCancel:K,onWheel:pe,onScroll:()=>I(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&&H&&e.jsx(No,{anchor:{xPercent:T.stageXPercent,yPercent:T.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(H,`svg:${T.x.toFixed(2)}:${T.y.toFixed(2)}`),I(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:A=>{A.stopPropagation(),W()},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(Ap,{size:14})}),e.jsx("button",{type:"button","aria-label":b?"退出全屏 SVG":"全屏 SVG",title:b?"退出全屏 SVG":"全屏 SVG",onClick:A=>{A.stopPropagation(),$(B=>!B)},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:b?e.jsx(Ou,{size:14}):e.jsx(_u,{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 b?kr.createPortal(ee,document.body):ee}function fo(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Pg(r,n,s,l){const f=[`电子标注: ${r}`,`视图: ${fo(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(f.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&f.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");f.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${f.join(" / ")}"`}function Ag({blobUrl:r,filePath:n,view:s,board:l,onViewChange:f,onInsertAnnotation:c,onRefresh:h,interactive3d:g}){const{t:p}=pt(),m=a.useRef(null),u=a.useRef(null),y=a.useRef(null),[b,$]=a.useState(null),[T,I]=a.useState(!1);a.useEffect(()=>(y.current?.abort(),$(null),I(!1),()=>y.current?.abort()),[r,s]);const D=a.useMemo(()=>b?Pg(n,s,b,b.inspection):null,[n,b,s]),U=R=>{const M=m.current,H=u.current;if(!M||!H||!H.naturalWidth||!H.naturalHeight)return;const F=M.getBoundingClientRect(),S=H.getBoundingClientRect(),o=Math.min(S.width/H.naturalWidth,S.height/H.naturalHeight),O=H.naturalWidth*o,P=H.naturalHeight*o,V=S.left+(S.width-O)/2,E=S.top+(S.height-P)/2,K=R.clientX-V,pe=R.clientY-E;if(K<0||pe<0||K>O||pe>P)return;const W={xPercent:Math.max(0,Math.min(100,K/O*100)),yPercent:Math.max(0,Math.min(100,pe/P*100)),stageXPercent:(R.clientX-F.left)/F.width*100,stageYPercent:(R.clientY-F.top)/F.height*100,inspecting:l&&s!=="pcb-3d"};if($(W),y.current?.abort(),!W.inspecting)return;const ee=new AbortController;y.current=ee,mm(n,s,W.xPercent,W.yPercent,ee.signal).then(A=>$(B=>B===W?{...B,inspection:A,inspecting:!1}:B)).catch(()=>{ee.signal.aborted||$(A=>A===W?{...A,inspection:{available:!1},inspecting:!1}:A)})},C=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:C.map(R=>e.jsx("button",{type:"button",onClick:()=>f(R),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${R===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:fo(R)},R))}),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(uo,{size:13})})]}),l&&g?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:g}):null,l?s==="pcb-3d"?g?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:m,role:"button",tabIndex:0,onClick:U,onKeyDown:R=>{R.key!=="Enter"&&R.key!==" "||(R.preventDefault(),$({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:r,alt:`${n} ${fo(s)}`,onLoad:()=>I(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${T?"opacity-100":"opacity-0"}`}),b&&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:`${b.stageXPercent}%`,top:`${b.stageYPercent}%`}}),b&&D&&e.jsx(No,{anchor:{xPercent:b.stageXPercent,yPercent:b.stageYPercent},disabled:b.inspecting,title:p("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(D,`eda:${s}:${b.xPercent.toFixed(1)}:${b.yPercent.toFixed(1)}`,{snapshot:u.current?Hp(u.current,b):Promise.resolve(null)}),$(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:b?b.inspecting?p("rightSidebar.edaInspecting"):b.inspection?.available?p("rightSidebar.edaPickedBoardPosition",{x:b.inspection.xMm?.toFixed(2)??"—",y:b.inspection.yMm?.toFixed(2)??"—",object:b.inspection.nearest?.label??p("rightSidebar.edaNoNearbyObject")}):p("rightSidebar.edaPickedPosition",{x:b.xPercent.toFixed(1),y:b.yPercent.toFixed(1)}):p("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Ju,{blobUrl:r,filePath:n,viewLabel:fo(s),onInsertAnnotation:c})})]})}function Tg(r){const n=[];let s=[],l="",f=!1;for(let c=0;c<r.length;c+=1){const h=r[c];f?h==='"'&&r[c+1]==='"'?(l+='"',c+=1):h==='"'?f=!1:l+=h:h==='"'?f=!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 Ig(r,n,s,l,f){const c=n[f]||`第${f+1}列`,h=s[f]??"",g=n.map((p,m)=>`${p||`第${m+1}列`}=${s[m]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${g}"`}function Dg({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=pt(),f=a.useMemo(()=>Tg(r),[r]),c=f[0]??[],h=f.slice(1),g=a.useRef(null),[p,m]=a.useState(null),u=p?h[p.row]:null,y=p&&u?Ig(n,c,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:g,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:"#"}),c.map((b,$)=>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:b||l("rightSidebar.csvUnnamedColumn",{index:$+1})},`${b}:${$}`))]})}),e.jsx("tbody",{children:h.map((b,$)=>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:$+1}),c.map((T,I)=>{const D=p?.row===$&&p.column===I;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${D?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:U=>{const C=g.current?.getBoundingClientRect(),R=U.currentTarget.getBoundingClientRect();if(!C?.width||!C.height)return;const M=U.clientX||R.left+R.width/2,H=U.clientY||R.top+R.height/2;m({row:$,column:I,xPercent:(M-C.left)/C.width*100,yPercent:(H-C.top)/C.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:b[I]||" "})},`cell:${$}:${I}`)})]},`row:${$}`))})]})}),p&&y&&e.jsx(No,{anchor:{xPercent:p.xPercent,yPercent:p.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(y,`csv:${n}:${p.row+1}:${p.column+1}`),m(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:c[p.column]||p.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function ts(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function Fg(r,n){const s=JSON.parse(r),l=ts(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(ts(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(ts(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:ts(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const f=ts(s,["net_settings","classes"]),c=Array.isArray(f)?f.find(g=>g&&typeof g=="object"&&g.name==="Default"):void 0,h=ts(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(f)?f.length:0)},{label:"默认间距",value:c?.clearance!==void 0?`${c.clearance} mm`:"未设置"},{label:"默认线宽",value:c?.track_width!==void 0?`${c.track_width} mm`:"未设置"},{label:"默认过孔",value:c?.via_diameter!==void 0?`${c.via_diameter} / ${c.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function _g(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function Bg({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:f}=pt(),c=a.useRef(null),[h,g]=a.useState(null),p=a.useMemo(()=>{try{return{items:Fg(r,s),error:null}}catch(u){return{items:[],error:u instanceof Error?u.message:String(u)}}},[r,s]),m=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:r}):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:f("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:c,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,y)=>e.jsxs("button",{type:"button",onClick:b=>{const $=c.current?.getBoundingClientRect(),T=b.currentTarget.getBoundingClientRect();if(!$?.width||!$.height)return;const I=b.clientX||T.left+T.width/2,D=b.clientY||T.top+T.height/2;g({index:y,xPercent:(I-$.left)/$.width*100,yPercent:(D-$.top)/$.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===y?"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:f("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),m&&h&&e.jsx(No,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:f("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(_g(n,m),`kicad-project:${n}:${m.label}`),g(null)},children:f("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:m?`${m.label}: ${m.value}`:f("rightSidebar.kicadProjectPickHint")})})]})}const Og=`/** ES Module Shims Wasm @version 2.8.4 */
|
|
19
15
|
(function () {
|
|
20
16
|
|
|
21
17
|
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
@@ -1501,7 +1497,7 @@ build/report.html`,className:"min-h-32 w-full resize-y rounded-lg border border-
|
|
|
1501
1497
|
};
|
|
1502
1498
|
|
|
1503
1499
|
})();
|
|
1504
|
-
`,
|
|
1500
|
+
`,Ug=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
|
|
1505
1501
|
function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
|
|
1506
1502
|
const external = new Set(externalOrigins);
|
|
1507
1503
|
const report = () => parent.postMessage({ type: 'preview-error', capability }, '*');
|
|
@@ -1636,47 +1632,47 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
|
|
|
1636
1632
|
window.addEventListener('error', report, true);
|
|
1637
1633
|
window.addEventListener('unhandledrejection', report);
|
|
1638
1634
|
}
|
|
1639
|
-
`,eo="/api/terminal/fs/preview/",
|
|
1640
|
-
installPreviewRuntime(`+[f,c,[...u],ee].map(
|
|
1641
|
-
`+
|
|
1642
|
-
`);const b=f.length;f+=u.data,l.push({node:u,start:b,end:f.length,group:k}),c=k}const g=f.toLocaleLowerCase(),p=[];let m=0;for(;m<=g.length-s.length;){const u=g.indexOf(s,m);if(u<0)break;const k=u+s.length,b=l.find(A=>A.start<=u&&A.end>u),M=l.find(A=>A.start<k&&A.end>=k);if(b&&M&&b.group===M.group){const A=document.createRange();A.setStart(b.node,u-b.start),A.setEnd(M.node,k-M.start),p.push(A)}m=u+Math.max(s.length,1)}return p}function Ju(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function to(){const r=Ju();r?.delete(Xu),r?.delete(ll)}function Zd(r,n){const s=Ju();if(!s||typeof Highlight>"u")return;s.set(Xu,new Highlight(...r));const l=r[n];l?s.set(ll,new Highlight(l)):s.delete(ll)}function eu(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Yg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Xg(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Jg(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function Qu(r,n,s){return n?r:kr.createPortal(r,s)}const yl="termdock:right-sidebar:file-tree-scroll:v1",kl="termdock:right-sidebar:file-preview-reading-state:v1",Hs="termdock:right-sidebar:file-tree-width:v1",Zu="termdock:right-sidebar:markdown-view-mode:v1",ef="termdock:right-sidebar:diff-change-list-mode:v1",tf="termdock:right-sidebar:diff-wrap:v1",rf="termdock:diff-viewer:view-type:v1",nf="termdock:right-sidebar:file-search-mode:v1",_i="termdock:right-sidebar:collapsed-git-repo-groups:v1",tu="termdock:right-sidebar:collapsed-diff-directories:v1",Bi="termdock:right-sidebar:branch-audit-module-open:v1",sf="termdock:right-sidebar:branch-audit-module:v1",Qg=150,ru="termdock:right-sidebar:context-draft-enabled:v1",nu="termdock:right-sidebar:context-draft-collapsed:v1",su="termdock:right-sidebar:context-draft-auto-collapse:v1",Oi="termdock:right-sidebar:context-draft-text:v1",Zg=300,eb=20,tb=120,rb=250,nb=250,sb=120,ab=700,Ui=600,ob=6e4;function Ds(r){return!!(r&&Y.getState().nestedGitScanRoots[r])}const au=[2e3,5e3,15e3,3e4],ib=320,lb=500,cb=20,db=12e3,cl=300,ou=240,ub=560,af="border-r px-2 py-1.5 sm:px-3 sm:py-2",xo="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",of=`${af} border-b border-border/15 font-semibold last:border-r-0`,lf=`${af} border-border/10 align-top text-muted-foreground last:border-r-0`,Sl="termdock-file-preview-horizontal-scroll",iu=a.lazy(()=>Xs(()=>import("./ModelPreview-B2Hrizox.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),cf=`${Sl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function df(r,n,s){return r&&!n?"unified":s}const fb=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function hb(r){return r==="preview"||r==="source"}function mb(r){return r==="list"||r==="tree"||r==="ai"}function lu(){return ht(Zu,hb)??"preview"}function pb(){return ht(ef,mb)??"tree"}function zs(r){return typeof r=="boolean"}function gb(r){return typeof r=="string"}function bb(){return ht(tf,zs)??!0}function xb(r){return r==="unified"||r==="split"}function vb(){return ht(rf,xb)??"unified"}function wb(r){return r==="name"||r==="content"||r==="regex"}function yb(){return ht(nf,wb)??"name"}function uf(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:kt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function kb(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function dl(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function ff(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function ul(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function cu(r){const n=ht(r,ul);return n?new Set(n):new Set}function Hi(r,n){Lt(r,[...n])}function Sb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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 jb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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||ul(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Sb))&&(n.commits===void 0||ul(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 Rb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&jb(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Cb(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).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(Rb))&&(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.repoIncludeUncommitted===void 0||!!s.repoIncludeUncommitted&&typeof s.repoIncludeUncommitted=="object"&&!Array.isArray(s.repoIncludeUncommitted)&&Object.values(s.repoIncludeUncommitted).every(l=>typeof l=="boolean"))&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function du(){return ht(sf,Cb)??{}}function uu(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function fu(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function hf(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||fu(s)===fu(l)}function hu(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!hf(l,n))??""}function fl(r,n){const s=Math.max(ou,n-320),l=Math.min(ub,s);return Math.min(l,Math.max(ou,r))}function Nb(r){return typeof r=="number"&&Number.isFinite(r)}function Eb(r){return fl(ht(Hs,Nb)??cl,r)}function mf(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function Fs(r){return fb.has(mf(r))}function pf(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function hl(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||pf(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function gf(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const bf=a.createContext(null);function ho(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function xf(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function vf(r){return r.replace(/\s+#+\s*$/,"").trim()}function ml(r,n){const l=xf(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",f=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,f+1),f===0?l:`${l}-${f}`}function mu(r){return xf(r)||r.trim()}function vo(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=gl(n[2]);return s?{id:ho(n[1]),definition:{href:s.href,title:s.title}}:null}function Mb(r){const n=new Map;for(const s of r){const l=vo(s);l&&n.set(l.id,l.definition)}return n}function wf(r){return r.trim().toLowerCase()}function yf(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:wf(n[1]),text:n[2]}:null}function $b(r){const n=new Map;let s=null;for(const l of r){const f=yf(l);if(f){s=f.id,n.set(f.id,{id:f.id,text:f.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function kf(r){const n=new Set;let s=!1;return r.forEach((l,f)=>{if(yf(l)){n.add(f),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(f);return}l.trim()&&(s=!1)}),n}function Lb(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const f=r[s].trim();if(f.startsWith("<!--")){if(n[s]="",!f.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Sf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Ks(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function jl(r,n,s){const l=r.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 f=l.indexOf("#"),c=f>=0?l.slice(0,f):l,h=f>=0?l.slice(f+1):"",g=c.split("?",1)[0];if(!g)return null;let p,m=null;try{p=decodeURIComponent(g),m=h?decodeURIComponent(h):null}catch{return null}const u=s?Ks(s):null;let k;if(p.startsWith("/")){const b=u&&(p===u||p.startsWith(`${u}/`));k=Ks(u&&!b?`${u}/${p.slice(1)}`:p)}else{if(!n)return null;k=Ks(`${Sf(n)}/${p}`)}return u&&k!==u&&!k.startsWith(`${u}/`)?null:{path:k,fragment:m,directory:/\/$/.test(g)}}function Rl(r,n,s,l,f){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const g=s&&(c===s||c.startsWith(`${s}/`));h=Ks(s&&!g?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Ks(`${Sf(n)}/${c}`)}return f(h)}function Ab(r,n,s){return Rl(r,n,s,wl,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Pb(r,n,s){return Rl(r,n,s,Nu,Eu)}const pl=128,Tb=360,zi=480;function No(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function jf(r,n,s,l,f=0){if(!n||!s)return null;let c,h;return f>0?(c=l>0?Math.min(f,l):f,h=s*c/n):No(r)?(h=Math.min(Math.max(s,pl),Tb),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>zi&&(c=c*zi/h,h=zi),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Ib(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Rf(r){const n=Ib(r),s=Y(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function Db({src:r,alt:n,title:s,requestedWidthPx:l}){const f=No(r),c=Rf(r),h=Ro(c),g=a.useRef(null),[p,m]=a.useState(!1),[u,k]=a.useState(0),[b,M]=a.useState({status:"loading"}),[A,F]=a.useState(null);a.useLayoutEffect(()=>{const C=g.current;let E=C?.parentElement?.parentElement??C?.parentElement;for(;E;){const w=window.getComputedStyle(E).display;if(w!=="inline"&&w!=="contents")break;E=E.parentElement}if(!E)return;const T=E,U=()=>{const w=window.getComputedStyle(T),o=(parseFloat(w.paddingLeft)||0)+(parseFloat(w.paddingRight)||0);k(Math.max(0,T.clientWidth-o))};if(U(),typeof ResizeObserver>"u")return;const L=new ResizeObserver(U);return L.observe(T),()=>L.disconnect()},[]),a.useEffect(()=>{if(p)return;const C=g.current;if(!C||typeof IntersectionObserver>"u"){m(!0);return}const E=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(m(!0),E.disconnect())},{rootMargin:"400px"});return E.observe(C),()=>E.disconnect()},[p]),a.useEffect(()=>{if(!p)return;const C=new AbortController;let E=null;M({status:"loading"});const T=window.setTimeout(()=>{C.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Hm(c,{signal:C.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const L=Number(U.headers.get("X-Image-Width"))||0,w=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:L,height:w}}).then(({blob:U,width:L,height:w})=>{C.signal.aborted||(E=URL.createObjectURL(U),L>0&&w>0&&F({width:L,height:w}),M({status:"ready",objectUrl:E}))}).catch(()=>{const U=C.signal.reason;C.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||M({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),C.abort(),E&&URL.revokeObjectURL(E)}},[p,c]);const B=jf(r,A?.width??0,A?.height??0,u,l??0),D=B??(l?{width:u>0?Math.min(l,u):l,height:Math.round(l*.75)}:{width:pl*2,height:pl});return e.jsx("div",{ref:g,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:b.status==="ready"?e.jsx("img",{src:b.objectUrl,alt:n,title:s,decoding:"async",className:`${f?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:C=>{const E=C.currentTarget;E.naturalWidth>0&&E.naturalHeight>0&&(A?.width!==E.naturalWidth||A?.height!==E.naturalHeight)&&F({width:E.naturalWidth,height:E.naturalHeight})}}):b.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:B?{width:B.width,height:B.height}:void 0,onLoad:C=>{const E=C.currentTarget;E.naturalWidth>0&&E.naturalHeight>0&&(A?.width!==E.naturalWidth||A?.height!==E.naturalHeight)&&F({width:E.naturalWidth,height:E.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:D.width,height:D.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function qs(r,n,s,l,f,c){const h=Ab(s,f.markdownFilePath,f.rootPath);if(!h)return c?.fallbackText??``;const g=f.images.length;f.images.push({kind:"image",src:h,alt:n,title:l});const p=e.jsx(Db,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return f.onImageOpen&&c?.interactive!==!1?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:m=>{m.stopPropagation(),f.onImageOpen?.(g)},children:p},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:p},r)}function Wi(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function pu(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function gl(r){const n=r.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 Cf="",Fb=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function _b(r){return r.replace(Fb,(n,s)=>`${Cf}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function gu(r){return r.replace(new RegExp(`${Cf}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Bb(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Nf={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 ro=null;function Ef(){return ro||(ro=Xs(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw ro=null,r})),ro}function Mf({html:r}){const{t:n}=bt(),[s,l]=a.useState(null);return a.useEffect(()=>{let f=!1;return l(null),Ef().then(c=>{f||l(c.sanitize(r,Nf))}).catch(()=>{f||l("")}),()=>{f=!0}},[r]),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 Ob({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Ef().then(f=>{l||s(f.sanitize(r,Nf))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function $f(r){const n=r.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(r)}}let no=null;function Ub(){return no||(no=Promise.all([Xs(()=>import("./katex-DnlPpQZa.js"),[]),Xs(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw no=null,r})),no}function Qs({tex:r,display:n=!1}){const[s,l]=a.useState(null),[f,c]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),c(!1),Ub().then(p=>{g||l(p.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||c(!0)}),()=>{g=!0}},[n,r]),f)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});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 Cl(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function bu(r){const n=Cl(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Hb(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=Cl(s),f=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:f,fallbackText:g,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function zb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:f}=bt(),[c,h]=a.useState(!1),g=Ro(r,()=>h(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||f("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function Wb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),g=Cl(h).get("href")?.trim()??"",p=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:m,alt:u,title:k,widthPx:b}=bu(p);if(!m)return null;const M=Rl(m,s.markdownFilePath,s.rootPath,wl,C=>C);if(!M)return null;const A=g?jl(g,s.markdownFilePath,s.rootPath):null,B=!!!(A&&A.path===M)&&g?gf(g):null,D=qs(n,u??"",m,k,s,{requestedWidthPx:b,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:D},n):D}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:g,title:p,widthPx:m}=bu(r);return h?qs(n,g??"",h,p,s,{fallbackText:r,requestedWidthPx:m}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:g,widthPx:p,controls:m}=Hb(r);if(!h)return null;const u=Pb(h,s.markdownFilePath,s.rootPath);return u?e.jsx(zb,{url:u,fallbackText:g,widthPx:p,hasControls:m},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.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(r)?e.jsx(Ob,{html:r},n):null;const f=l[1].toLowerCase(),c=ct(l[2],`${n}-${f}`,!0,s);return f==="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:c},n):f==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):f==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function ct(r,n,s=!0,l){const f=_b(r),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\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 g=0,p;for(;(p=c.exec(f))!==null;){p.index>g&&h.push(gu(f.slice(g,p.index)));const m=p[0],u=`${n}-${p.index}`,k=m.startsWith("<")?Wb(m,u,l):null;if(k)h.push(k);else if(m.startsWith("\\(")&&m.endsWith("\\)"))h.push(e.jsx(Qs,{tex:m.slice(2,-2)},u));else if(m.startsWith("$")&&m.endsWith("$"))h.push(e.jsx(Qs,{tex:m.slice(1,-1)},u));else if(m.startsWith("`")){const b=m.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:Bb(m.slice(b,-b))},u))}else if(m.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ct(m.slice(2,-2),`${u}-del`,s,l)},u));else if(m.startsWith("**")||m.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ct(m.slice(2,-2),`${u}-strong`,s,l)},u));else if(m.startsWith("*")||m.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:ct(m.slice(1,-1),`${u}-em`,s,l)},u));else if(m.startsWith("![")){const b=m.match(/^!\[([^\]]*)\]\((.*)\)$/),M=m.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),A=m.match(/^!\[([^\]]+)\]$/);if(b){const F=gl(b[2]);h.push(F?qs(u,b[1],F.href,F.title,l):m)}else if(M){const F=M[2]||M[1],B=l.referenceDefinitions.get(ho(F));h.push(B?qs(u,M[1],B.href,B.title,l):m)}else if(A){const F=l.referenceDefinitions.get(ho(A[1]));h.push(F?qs(u,A[1],F.href,F.title,l):m)}else h.push(m)}else if(m.startsWith("[^")){const b=wf(m.slice(2,-1)),M=l.footnoteDefinitions.get(b);h.push(M?e.jsx("sup",{id:`fnref-${M.id}`,title:M.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${M.id}`,className:"text-primary no-underline",children:M.index})},u):m)}else if(m.startsWith("<http")){const b=m.slice(1,-1);h.push(e.jsx("a",{href:b,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u))}else if(m.startsWith("<")&&m.endsWith(">")&&pu(m.slice(1,-1))){const b=m.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${b}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u))}else if(pu(Wi(m).linkText)){const{linkText:b,suffix:M}=Wi(m);h.push(e.jsx("a",{href:`mailto:${b}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u)),M&&h.push(M)}else if(m.startsWith("http")||m.startsWith("www.")){const{linkText:b,suffix:M}=Wi(m),A=b.startsWith("www.")?`https://${b}`:b;h.push(e.jsx("a",{href:A,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u)),M&&h.push(M)}else{const b=m.match(/^\[([^\]]+)\]\((.*)\)$/),M=m.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),A=m.match(/^\[([^\]]+)\]$/),F=M?M[2]||M[1]:A?.[1]??null,B=F?l.referenceDefinitions.get(ho(F)):null,D=b?gl(b[2]):null,C=D?.href??B?.href??null,E=C?gf(C):null,T=b?.[1]??M?.[1]??A?.[1]??"";h.push(E?e.jsx("a",{href:E,title:D?.title??B?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ct(T,`${u}-link`,s,l)},u):m)}g=c.lastIndex}return g<f.length&&h.push(gu(f.slice(g))),h.length>0?h:[r]}function Lf(r){return/(?: {2,}|\\)$/.test(r)}function Af(r){return r.replace(/(?: {2,}|\\)$/,"")}function wo(r){return/^(?: {4}|\t)/.test(r)}function Pf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function Tf(r,n,s){const l=[];return r.forEach((f,c)=>{const h=Lf(f);l.push(...ct(Af(f),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function bl(r,n,s){const l=[],f=[];return r.forEach((c,h)=>{f.push(Lf(c)),l.push(ct(Af(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:f}}function xl(r,n,s,l,f){const c=[];return r.forEach((h,g)=>{const p=s[g]??0,m=!!(f&&p>=f.start&&p<=f.end);c.push(e.jsx("span",{"data-md-ref-start":p,"data-md-ref-end":p,"data-selected":m?"true":void 0,children:h},`${l}-ref-${g}`)),g<r.length-1&&c.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),c}function Zs(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",f=!1,c=0,h=0;for(let g=0;g<n.length;g+=1){const p=n[g];if(f){l+=p,f=!1;continue}if(p==="\\"){f=!0;continue}if(p==="`"){const m=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const u=g-m+1;l+="`".repeat(u),c===0?c=u:c===u&&(c=0);continue}if(c===0&&p==="["?h+=1:c===0&&p==="]"&&h>0&&(h-=1),p==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=p}return f&&(l+="\\"),s.push(l.trim()),s}function If(r){return Zs(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function yo(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function ko(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function Df(r,n){return r>96||r>44&&n>.35}function Eo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function ea(r){const n=r.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 Nl(r,n,s,l,f,c=new Set){const h=[],g=[];let p=n;for(;p<r.length;){const m=r[p];if(f&&(vo(m)||c.has(p))){p+=1;continue}const u=ea(m),k=Eo(m);if(!u){if(k>s&&g.length>0){([...g].reverse().find(F=>F.indent<k)?.item??g[g.length-1].item).paragraphs.push(m.trim());for(const F of g)F.item.lineEnd=p+1;p+=1;continue}break}if(k<s||k===s&&u.ordered!==l)break;const b={content:u.content,ordered:u.ordered,start:u.start,children:[],paragraphs:[],lineStart:p+1,lineEnd:p+1};for(;g.length>0&&g[g.length-1].indent>=k;)g.pop();const M=g[g.length-1]?.item??null;M?M.children.push(b):h.push(b),g.push({indent:k,item:b});for(const A of g)A.item.lineEnd=p+1;p+=1}return{items:h,nextIndex:p}}function Gb(r){const n=r.find(l=>ea(l));if(!n)return[];const s=ea(n);return s?Nl(r,0,Eo(n),s.ordered,!0,kf(r)).items:[]}function El(r,n,s,l=0){return r.map((f,c)=>{const h=f.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:f.lineStart+l,refEnd:f.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,ct(h?.[2]??f.content,`li-${n}-${c}`,!0,s),f.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:f.paragraphs.map((g,p)=>e.jsx("p",{children:ct(g,`li-${n}-${c}-p-${p}`,!0,s)},`paragraph-${p}`))})]}),groups:Kb(f.children,`${n}-${c}`,s,l)}})}function Kb(r,n,s,l=0){const f=[];for(const c of r){const h=f[f.length-1];h&&h.ordered===c.ordered?h.items.push(c):f.push({ordered:c.ordered,items:[c]})}return f.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:El(c.items,`${n}-g${h}`,s,l)}))}function Ml(r,n){return r.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&&qb(s.groups,n)]},s.key)})}function qb(r,n){return r.map((s,l)=>{const f=s.ordered?"ol":"ul";return e.jsx(f,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Ml(s.items,n)},`nested-${l}`)})}function Vb(r){const n=Array.from(r.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:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[ct(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Yb(r,n,s,l){const f=[];let c=0;const h=g=>l?.[g]??g+1;for(;c<r.length;){const g=r[c],p=g.trim();if(!p){c+=1;continue}if(/^<details>\s*$/i.test(p)){const D=c;let C="Details";const E=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const T=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?C=T[1].trim()||C:E.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),f.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:ct(C,`${n}-details-${D}-summary`,!0,s)}),E.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Tf(E,`${n}-details-${D}`,s)})]},`${n}-details-${D}`)});continue}const m=$f(g);if(m){const D=[g],C=c;for(c+=1;c<r.length&&!m.selfContained&&!new RegExp(`</${m.tag}>`,"i").test(r[c]);)D.push(r[c]),c+=1;c<r.length&&!m.selfContained&&(D.push(r[c]),c+=1),f.push({kind:"static",node:e.jsx(Mf,{html:D.join(`
|
|
1643
|
-
`)},`${n}-html-${C}`)});continue}const u=p.match(/^(```|~~~)\s*(.*)$/);if(u){const
|
|
1644
|
-
`),blockKey:`${n}-code-${
|
|
1645
|
-
`),display:!0},`${n}-code-${
|
|
1646
|
-
`),lang:
|
|
1647
|
-
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${C}`,codeStartLine:h(C)});continue}const
|
|
1648
|
-
`).map(m=>[m||" "]);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:`${
|
|
1649
|
-
`:null]},`${s}-line-${u}`)})})})]})}function
|
|
1650
|
-
`)})});continue}const
|
|
1651
|
-
`),blockKey:`code-${O}`}):["math","latex","tex"].includes(o.toLowerCase())?e.jsx(Qs,{tex:
|
|
1652
|
-
`),display:!0}):
|
|
1653
|
-
`),lang:o,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:
|
|
1654
|
-
`).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${
|
|
1655
|
-
`),display:!0})});continue}if(u+1<r.length&&M&&!hl(b)&&/^(=+|-+)\s*$/.test(r[u+1].trim())){const L=r[u+1].trim().startsWith("=")?1:2,w=`h${L}`,o=ml(M,p),O={level:L,text:mu(M),id:o};m.push({key:`setext-heading-${u}`,startLine:u+1,endLine:u+2,heading:O,content:e.jsx(w,{id:o,className:`scroll-mt-16 font-semibold text-foreground ${L===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:ct(M,`setext-heading-${u}`,!0,p)})}),u+=2;continue}const B=M.match(/^(#{1,6})\s+(.+)$/);if(B){const L=B[1].length,w=vf(B[2]),o={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"},O=`h${L}`,H=ml(w,p),W={level:L,text:mu(w),id:H};m.push({key:`heading-${u}`,startLine:u+1,endLine:u+1,heading:W,content:e.jsx(O,{id:H,className:`scroll-mt-16 font-semibold text-foreground ${o[L]}`,children:ct(w,`heading-${u}`,!0,p)})}),u+=1;continue}if(pf(b)){m.push({key:`hr-${u}`,startLine:u+1,endLine:u+1,content:e.jsx("hr",{className:"border-border/20"})}),u+=1;continue}if(M.startsWith(">")){const L=[],w=[],o=u;for(;u<r.length&&/^>\s?/.test(r[u].trim());)L.push(r[u].trim().replace(/^>\s?/,"")),w.push(u+1),u+=1;const O=L[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const W=O[1].toUpperCase(),N=O[2]?.trim(),q=[...N?[N]:[],...L.slice(1)],fe=[...N?[w[0]]:[],...w.slice(1)],G=bl(q,`callout-${o}`,p);m.push({key:`callout-${o}`,startLine:o+1,endLine:u,fineGrained:!0,content:ee=>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:W}),q.length>0&&e.jsx("div",{children:xl(G.perLine,G.hardBreaks,fe,`callout-${o}`,ee)})]})});continue}const H=Yb(L,`quote-${o}`,p,w);m.push({key:`quote-${o}`,startLine:o+1,endLine:u,fineGrained:!0,content:W=>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:Xb(H,W)})});continue}if(u+1<r.length&&b.includes("|")&&ko(r[u+1])){const L=Zs(b),w=If(r[u+1]),o=[],O=u;for(u+=2;u<r.length&&r[u].includes("|")&&r[u].trim();)o.push(Zs(r[u])),u+=1;const H=L.map((N,q)=>ct(N,`th-${O}-${q}`,!0,p)),W=o.map((N,q)=>L.map((fe,G)=>ct(N[G]??"",`td-${O}-${q}-${G}`,!0,p)));m.push({key:`table-${O}`,startLine:O+1,endLine:u,interactive:!1,kind:"table",content:N=>{const q=fe=>!!(N&&fe>=N.start&&fe<=N.end);return e.jsx("div",{className:cf,"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":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":q(O+1)?"true":void 0,children:H.map((fe,G)=>e.jsx("th",{className:`${of} ${yo(w[G]??null)}`,children:e.jsx("div",{className:xo,children:fe})},`h-${G}`))})}),e.jsx("tbody",{children:W.map((fe,G)=>{const ee=O+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":ee,"data-md-ref-start":ee,"data-md-ref-end":ee,"data-selected":q(ee)?"true":void 0,children:L.map((P,_)=>e.jsx("td",{className:`${lf} ${yo(w[_]??null)}`,children:e.jsx("div",{className:xo,children:fe[_]})},`c-${_}`))},`r-${G}`)})})]})})}});continue}const D=ea(b);if(D){const L=D.ordered,w=Eo(b),o=D.start,O=u,H=Nl(r,u,w,L,!0,h);u=H.nextIndex;const W=L?"ol":"ul",N=El(H.items,`list-${O}`,p);m.push({key:`list-${O}`,startLine:O+1,endLine:u,fineGrained:!0,content:q=>e.jsx(W,{start:L?o:void 0,className:`${L?"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:Ml(N,q)})});continue}const C=[b.trimStart()],E=[u+1],T=u;for(u+=1;u<r.length&&r[u].trim()&&!hl(r[u])&&!(u+1<r.length&&r[u].includes("|")&&ko(r[u+1]));){if(vo(r[u])||h.has(u)){u+=1;continue}C.push(r[u].trimStart()),E.push(u+1),u+=1}const U=bl(C,`p-${T}`,p);m.push({key:`p-${T}`,startLine:T+1,endLine:u,fineGrained:!0,content:L=>e.jsx("p",{className:"text-muted-foreground",children:xl(U.perLine,U.hardBreaks,E,`p-${T}`,L)})})}const k=Vb(p);return k&&m.push({key:"footnotes",startLine:r.length,endLine:r.length,content:k}),{blocks:m,images:g}}function rx(r,n,s){return $l(r,n,s).blocks}function Bf(r,n){const s=[];for(const l of r){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 Of(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function nx({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const f=Rf(r);return e.jsx(Zf,{src:f,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Uf({images:r,index:n,onChange:s,onClose:l}){const{t:f}=bt(),c=r[n],h=r.length>1,g=a.useRef(null),p=a.useRef(null),m=a.useRef(null),u=a.useRef(0),[k,b]=a.useState(!1),[M,A]=a.useState(0),[F,B]=a.useState(!1),D=a.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),C=a.useCallback(()=>{k||Date.now()<u.current||(D(),m.current=window.setTimeout(()=>{m.current=null,l()},450))},[D,k,l]),E=a.useCallback(w=>{if(r.length===0)return;const o=(w+r.length)%r.length;g.current?.slideTo(o),s(o)},[r.length,s]),T=a.useCallback(()=>E(n-1),[E,n]),U=a.useCallback(()=>E(n+1),[E,n]);if(a.useEffect(()=>{D(),A(0),B(!1),b(!1)},[D,n]),a.useEffect(()=>{const w=g.current;w&&(w.allowTouchMove=h&&!k)},[h,k]),a.useEffect(()=>{const w=g.current;!w||w.activeIndex===n||w.slideTo(n,0)},[n]),a.useEffect(()=>D,[D]),a.useEffect(()=>{const w=o=>{if(o.key==="Escape"){o.preventDefault(),l();return}h&&(o.key==="ArrowLeft"?(o.preventDefault(),T()):o.key==="ArrowRight"&&(o.preventDefault(),U()))};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[h,U,T,l]),Au({onDrag:({movement:[w,o],pinching:O})=>{O||k||Math.abs(o)<Math.abs(w)*1.15&&M===0||(B(!0),Math.abs(o)>8&&(u.current=Date.now()+300),A(Math.max(0,o)))},onDragEnd:({movement:[w,o],velocity:[,O],pinching:H,canceled:W})=>{if(B(!1),H||W||k||Math.abs(o)<Math.abs(w)*1.15){A(0);return}if(Math.abs(o)>8&&(u.current=Date.now()+300),Df(o,O)){l();return}A(0)}},{target:p,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const L=c.title||c.alt||(c.kind==="mermaid"?f("rightSidebar.mermaidDiagram"):f("rightSidebar.image"));return typeof document>"u"?null:kr.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:L}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.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:T,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":f("rightSidebar.previousImage"),title:f("common.previous"),children:e.jsx(Vs,{size:17})}),e.jsx("button",{type:"button",onClick:U,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":f("rightSidebar.nextImage"),title:f("common.next"),children:e.jsx(Cm,{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":f("rightSidebar.closeImagePreview"),title:f("common.close"),children:e.jsx(Bt,{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,onClick:C,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${M}px, 0) scale(${Math.max(.86,1-M/900)})`,opacity:Math.max(.35,1-M/360),transition:F?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Pu,{onSwiper:w=>{g.current=w,w.allowTouchMove=h&&!k},onSlideChange:w=>{w.activeIndex!==n&&s(w.activeIndex)},onSliderMove:()=>{D(),u.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((w,o)=>e.jsx(Zi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:w.kind==="image"?e.jsx(nx,{src:w.src,alt:w.alt||w.title||f("rightSidebar.markdownImage"),onZoomChange:b,onDoubleTap:D}):e.jsx(vx,{svg:w.svg,title:w.title||w.alt||f("rightSidebar.mermaidDiagram"),onZoomChange:b,onDoubleTap:D})})},`${w.kind}-${o}-${w.alt}`))})})})]})]}),document.body)}function Hf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:f,onLineRangeDrag:c,scrollTop:h,outlineOpen:g,outlineCloseSignal:p,onOutlineOpen:m,onOutlineClose:u,lightboxOpen:k,lightboxCloseSignal:b,onLightboxOpen:M,onLightboxClose:A,onLocalLinkOpen:F}){const{t:B}=bt(),[D,C]=a.useState(null),[E,T]=a.useState(null),[U,L]=a.useState(1),[w,o]=a.useState(null),O=a.useRef(null),H=a.useRef(null),{blocks:W,images:N}=a.useMemo(()=>$l(r.split(`
|
|
1656
|
-
`),n,s,
|
|
1657
|
-
${r}`,_=a.useRef(P),J=a.useRef(null),ue=a.useRef(null),pe=a.useRef(!1);a.useEffect(()=>{_.current!==P&&(_.current=P,u?.())},[u,P]),a.useEffect(()=>{p!==void 0&&o(null)},[p]),a.useLayoutEffect(()=>{if(!g){o(null);return}const R=()=>{const se=H.current;if(!se)return;const he=se.getBoundingClientRect(),Ee=window.innerWidth;o({top:he.bottom+6,right:Math.max(8,Ee-he.right)})};return R(),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[g,h,G]);const we=a.useCallback(R=>{const se=O.current,he=se?.closest("[data-markdown-preview-scroller]"),Ee=se?.querySelector(`[data-markdown-preview-block-start="${R.startLine}"]`);if(!he||!Ee)return;const Me=he.getBoundingClientRect(),Ke=Ee.getBoundingClientRect(),Ae=se?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,dt=Ke.top-Me.top+he.scrollTop;he.scrollTo({top:Math.max(0,dt-Ae-8),behavior:"smooth"}),L(R.startLine),u?.()},[u]),je=a.useCallback(R=>{R.pointerType==="mouse"&&R.button!==0||Xi(R.target)||(J.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY})},[]),Ce=a.useCallback((R,se,he)=>{const Ee=J.current;if(J.current=null,!Ee||Ee.pointerId!==R.pointerId)return;const Me=Math.abs(R.clientX-Ee.startX),Ke=Math.abs(R.clientY-Ee.startY);if(Me>8||Ke>8)return;const le=R.target;if(Xi(le)||tl())return;const Ae=Ru(le,se,he);f(R,Ae.start,Ae.end)},[f]),$=a.useCallback(R=>{J.current?.pointerId===R.pointerId&&(J.current=null)},[]),Q=a.useCallback((R,se)=>{const he=O.current;if(!he||typeof document.elementFromPoint!="function")return null;const Ee=document.elementFromPoint(R,se);if(!(Ee instanceof HTMLElement)||!he.contains(Ee))return null;const Me=Ee.closest("[data-md-ref-start]");if(Me){const ke=Number(Me.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const Ke=Ee.closest("[data-markdown-preview-block-start]");if(!Ke)return null;const le=Number(Ke.dataset.markdownPreviewBlockStart),Ae=W.find(ke=>ke.startLine===le);if(!Ae)return Number.isFinite(le)&&le>0?le:null;if(Ae.endLine<=Ae.startLine)return Ae.startLine;const dt=Ke.getBoundingClientRect(),Pe=dt.height>0?Math.min(1,Math.max(0,(se-dt.top)/dt.height)):0;return Math.round(Ae.startLine+Pe*(Ae.endLine-Ae.startLine))},[W]),ne=a.useCallback(R=>{if(!c||R.pointerType==="mouse"&&R.button!==0)return;const se=Q(R.clientX+24,R.clientY);if(se!=null){ue.current={pointerId:R.pointerId,anchorLine:se,moved:!1};try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}}},[c,Q]),Le=a.useCallback(R=>{const se=ue.current;if(!se||se.pointerId!==R.pointerId||!c)return;const he=Q(R.clientX+16,R.clientY);he!=null&&(!se.moved&&he===se.anchorLine||(se.moved=!0,pe.current=!0,c(R,Math.min(se.anchorLine,he),Math.max(se.anchorLine,he),"move")))},[c,Q]),Ye=a.useCallback(R=>{const se=ue.current;if(ue.current=null,!se||se.pointerId!==R.pointerId||!c||!se.moved)return;const he=Q(R.clientX+16,R.clientY)??se.anchorLine;c(R,Math.min(se.anchorLine,he),Math.max(se.anchorLine,he),"end")},[c,Q]),De=a.useCallback(R=>{ue.current?.pointerId===R.pointerId&&(ue.current=null)},[]),rt={onPointerDown:ne,onPointerMove:Le,onPointerUp:Ye,onPointerCancel:De},_e=()=>pe.current?(pe.current=!1,!0):!1;return W.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:B("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:R=>{const se=R.target instanceof Element?R.target.closest("a[href]"):null;if(!se||!F)return;const he=se.getAttribute("href");if(!he)return;const Ee=jl(he,n,s);Ee&&(R.preventDefault(),F(Ee))},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(R=>R.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}),ee.length>1&&e.jsxs("button",{ref:H,type:"button",onClick:()=>{g?u?.():m?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${g?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":g,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(Tu,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),g&&typeof document<"u"&&kr.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:w?{top:`${w.top}px`,right:`${w.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:ee.map(R=>{const se=G[G.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>we(R),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] ${se?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${se?"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",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`desktop-${R.id}-${R.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:B("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":B("rightSidebar.closeMarkdownOutline"),title:B("common.close"),children:e.jsx(Bt,{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:ee.map(R=>{const se=G[G.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>we(R),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] ${se?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${se?"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",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`${R.id}-${R.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(bf.Provider,{value:fe,children:W.map(R=>{const se=!!(l&&R.startLine<=l.end&&R.endLine>=l.start),he=!!(l&&l.start<=R.startLine&&l.end>=R.endLine),Ee=R.kind==="table"?!1:R.fineGrained?he:se,Me=R.kind==="table"&&l?.start===R.startLine&&l.end===R.endLine;let Ke=null;if(R.kind!=="table"&&R.fineGrained&&se&&!he&&l){const Pe=R.endLine-R.startLine+1,ke=Math.max(l.start,R.startLine),ut=Math.min(l.end,R.endLine),Qe=(ke-R.startLine)/Pe,re=(ut-ke+1)/Pe;Ke=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) * ${Qe})`,height:`calc((100% - 0.5rem) * ${re})`}})}const le=typeof R.content=="function"?R.content(l):R.content,Ae=R.startLine===R.endLine?String(R.startLine):`${R.startLine}-${R.endLine}`,dt=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:qi(Ee),"aria-hidden":"true",...rt,children:[e.jsx("span",{className:Vi(Ee)}),Ke]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:le})]});return R.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":R.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 ${Ee?"bg-primary/10":""}`,title:`Line ${Ae}`,"aria-label":`Line ${Ae}`,children:[R.kind==="table"?e.jsx("button",{type:"button",className:qi(Me,"self"),onClick:Pe=>{Pe.preventDefault(),!_e()&&f(Pe,R.startLine,R.endLine)},title:`Reference table lines ${Ae}`,"aria-label":`Reference table lines ${Ae}`,...rt,children:e.jsx("span",{className:Vi(Me,"self")})}):e.jsxs("span",{className:qi(Ee,"none"),"aria-hidden":"true",...rt,children:[e.jsx("span",{className:Vi(Ee,"none")}),Ke]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:je,onPointerUp:Pe=>Ce(Pe,R.startLine,R.endLine),onPointerCancel:$,onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),f(Pe,R.startLine,R.endLine))},title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:le})]},R.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":R.startLine,onClick:Pe=>{const ke=Pe.target;if(Xi(ke)||tl()||_e())return;const ut=Ru(ke,R.startLine,R.endLine);f(Pe,ut.start,ut.end)},onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),f(Pe,R.startLine,R.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 ${Ee?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:dt},R.key)})})})]}),k&&D!==null&&q[D]&&e.jsx(Uf,{images:q,index:D,onChange:C,onClose:()=>{C(null),T(null),A?.()}})]})}function rs({label:r,value:n,options:s,placeholder:l,searchPlaceholder:f,emptyText:c,disabled:h,onChange:g}){const{t:p}=bt(),[m,u]=a.useState(!1),[k,b]=a.useState(""),[M,A]=a.useState(null),F=a.useRef(null),B=a.useRef(null),D=k.trim().toLowerCase(),C=a.useMemo(()=>D?s.filter(w=>`${w.label} ${w.meta??""}`.toLowerCase().includes(D)):s,[D,s]),E=s.find(w=>w.value===n),T=()=>{const w=k.trim();w&&(g(w),u(!1),b(""))},U=a.useCallback(()=>{const w=F.current?.getBoundingClientRect();if(!w)return!1;const o=12,O=Math.max(220,Math.min(w.width,window.innerWidth-o*2)),H=Math.min(Math.max(o,w.left),window.innerWidth-O-o),W=window.innerHeight-w.bottom-o,N=w.top-o,q=W>=180||W>=N,fe=Math.max(96,(q?W:N)-4),G=Math.min(320,fe);return A({left:H,top:q?w.bottom+4:Math.max(o,w.top-G-4),width:O,maxHeight:G}),!0},[]),L=()=>{U(),u(!0)};return a.useEffect(()=>{if(!m)return;let w=0;const o=()=>{w||(w=window.requestAnimationFrame(()=>{w=0,U()}))},O=H=>{const W=H.target;W instanceof Node&&(F.current?.contains(W)||B.current?.contains(W)||(u(!1),b("")))};return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),document.addEventListener("pointerdown",O,!0),()=>{w&&window.cancelAnimationFrame(w),window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0),document.removeEventListener("pointerdown",O,!0)}},[m,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:F,type:"button",disabled:h,onClick:()=>{if(!h){if(b(""),m){u(!1);return}L()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:E?.label??(n||l)})]}),e.jsx(Ys,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${m?"rotate-180":""}`})]}),m&&!h&&typeof document<"u"&&kr.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:w=>w.stopPropagation(),style:{left:M?.left??12,top:M?.top??12,width:M?.width??260,maxHeight:M?.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(ns,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:k,onChange:w=>b(w.target.value),onKeyDown:w=>{if(w.key==="Escape"){w.preventDefault(),u(!1),b("");return}w.key==="Enter"&&(w.preventDefault(),T())},onBlur:()=>{k.trim()&&C.length===0&&T()},placeholder:f,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,(M?.maxHeight??320)-46)},children:[k.trim()&&!s.some(w=>w.value===k.trim())&&e.jsxs("button",{type:"button",onMouseDown:w=>w.preventDefault(),onClick:T,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:k.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:p("common.use")})]}),C.length>0?C.map(w=>e.jsxs("button",{type:"button",onClick:()=>{g(w.value),u(!1),b("")},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 ${w.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:w.label}),w.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:w.meta})]},w.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function vu({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:f,selectedRoots:c,onToggleRepo:h,onGenerate:g,onSecondaryAction:p,disabled:m,generateDisabled:u,secondaryDisabled:k,inserted:b,buttonLabel:M,insertedLabel:A,title:F,ariaLabel:B,scopeTitle:D,scopeLabel:C,allLabel:E,generateLabel:T,secondaryLabel:U,secondaryTitle:L,secondaryLoading:w,loading:o,error:O,statusTitle:H,extraContent:W,renderRepoExtra:N,menuItem:q=!1}){return e.jsxs("div",{className:q?"relative w-full":"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",role:q?"menuitem":void 0,tabIndex:q?-1:void 0,onClick:()=>{s?n(!r):u||g()},disabled:m,className:`relative flex items-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-50 ${q?"min-h-10 w-full gap-2.5 px-2.5 text-left text-[12px] focus:bg-surface-2 focus:outline-none [@media(pointer:coarse)]:min-h-11":"h-7 shrink-0 justify-center gap-1 px-2 text-[11px] font-medium active:scale-95"} ${O?"text-destructive hover:bg-destructive/5":b?"bg-surface-elevated text-foreground":q?"text-foreground hover:bg-surface-2":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:H??(s?`${D}: ${C}`:F),children:[o?e.jsx(gt,{size:q?15:13,className:"shrink-0 animate-spin"}):e.jsx(Js,{size:q?15:13,className:q?"shrink-0 text-muted-foreground":void 0}),e.jsx("span",{className:q?"min-w-0 flex-1":void 0,children:b?A:M}),s&&(q?e.jsx(Us,{size:13,className:"shrink-0 text-muted-foreground"}):e.jsx(Ys,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`})),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&kr.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:fe=>fe.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:D}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:C})]}),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(Bt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[W,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:E}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),f.map(fe=>{const G=c.includes(fe.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${G?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(fe.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${G?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:fe.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:fe.label}),fe.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:fe.branch})]}),G&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),N&&(l||G)&&e.jsx("div",{className:"px-2 pb-2",children:N(fe)})]},fe.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${p&&U?"sm:grid-cols-2":""}`,children:[p&&U&&e.jsxs("button",{type:"button",onClick:()=>{k||(n(!1),p())},disabled:k,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:L,children:[w?e.jsx(gt,{size:12,className:"animate-spin"}):e.jsx(zu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{u||(n(!1),g())},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:F,children:[e.jsx(Js,{size:12}),T]})]})]})}),document.body)]})}function sx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){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 zf(){return ht(yl,sx)??{}}function ax(r,n){const s=zf(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,f],[,c])=>c.updatedAt-f.updatedAt).slice(0,eb);Ws(yl,Object.fromEntries(l),rb)}function ox(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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 ix(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){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&&!ox(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Ll(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function Wf(){return ht(kl,ix)??{}}function wu(r,n){const s=Ll(r,n);return s?Wf()[s]??null:null}function Gi(r,n,s){const l=Ll(r,n);if(!l)return;const f=Wf(),c=f[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...f,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,g],[,p])=>p.updatedAt-g.updatedAt).slice(0,tb);Ws(kl,Object.fromEntries(h),nb)}function Ki({slow:r}){return e.jsx(up,{slow:r})}function oo({message:r,onRetry:n}){const{t:s}=bt();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:r}),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 mo(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function kt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function io(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function lx(r,n,s){return rl(r,n,s)}function qi(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function Vi(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function Gf(r){const n=new Map;for(const s of r)n.set(Al(s),s);return n}function Kf(r,n){const s=new Map(r);for(const l of n)s.set(Al(l),l);return s}function yu(r,n){let s=0;for(const l of r){const f=pt(l,n);f&&n&&f!==n&&(s+=1)}return s}function cx(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function dx(r,n){return Array.from(Kf(Gf(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function ux(r,n){const s=r.relativeRoot==="."?kt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||kt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:cx(r.files)}}function qf(r,n){const s=kt(n??"")||n||"";return r.map(l=>ux(l,n)).sort((l,f)=>s&&l.label===s?-1:s&&f.label===s?1:l.label.localeCompare(f.label))}function Vf(r,n,s,l,f){const c=uf(s),h=c.find(F=>F.root===l)??c[0]??null,g=n.find(F=>F.root===l)??null,p=g?.relativeRoot??h?.relativeRoot??".",m=g?.name??h?.name??(kt(l)||l),u=(h?.files??s.files).map(F=>({...F,repoRoot:l,repoRelativeRoot:p,repoName:m})),k=h?.context??s.context,b={...g??h??{id:l,root:l,relativeRoot:p,name:m,depth:0,nested:!!(f&&l!==f),available:s.available,files:[],context:null},...h??{},id:g?.id??h?.id??l,root:l,displayRoot:g?.displayRoot??h?.displayRoot,relativeRoot:p,name:m,depth:g?.depth??h?.depth??0,nested:g?.nested??h?.nested??!!(f&&l!==f),available:h?.available??s.available,deferred:h?.deferred??!1,files:u,context:k?{...k,root:l,changedFiles:u.map(F=>({path:F.path,absolutePath:F.absolutePath,status:F.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},M=g?n.map(F=>F.root===l?b:F):[...n,b];return{files:Array.from(r).filter(F=>pt(F,f)!==l).concat(u),repositories:M,repoFilters:qf(M,f)}}function pt(r,n){return r.repoRoot??n}function Al(r){return`${r.repoRoot??""}\0${r.path}`}function wr(r){return r.absolutePath||r.path}function Yi(r){return Al(r)}function fx(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function ku(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Su(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)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 _s(r){let n=0;const s=r??"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 Bs(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function yr(r){return r instanceof DOMException&&r.name==="AbortError"}function hx(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function ju(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function Xi(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Ru(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,f=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(f)&&f>0&&Number.isFinite(c)&&c>0?{start:Math.min(f,c),end:Math.max(f,c)}:{start:n,end:s}}function mx({actions:r,running:n,completed:s}){const{t:l}=bt(),[f,c]=a.useState(!1),h=a.useRef(null),g=r.find(m=>n?.action===m.key),p=r.find(m=>s?.action===m.key);return r.length===0?null:(a.useEffect(()=>{if(!f)return;const m=k=>{const b=k.target;b instanceof Node&&h.current?.contains(b)||c(!1)},u=k=>{k.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",m),document.addEventListener("keydown",u),()=>{document.removeEventListener("pointerdown",m),document.removeEventListener("keydown",u)}},[f]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),c(u=>!u)},disabled:r.every(m=>m.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${f?"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:g?.label??p?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(gt,{size:13,className:"animate-spin"}):p?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(po,{size:14})}),f&&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:r.map(m=>{const u=n?.action===m.key,k=s?.action===m.key;return e.jsxs("button",{type:"button",onClick:b=>{b.stopPropagation(),m.onClick(),c(!1)},disabled:m.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 ${k?"bg-accent/10 text-accent":m.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(gt,{size:13,className:"animate-spin"}):k?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.label})]},m.key)})})]}))}function px(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function Yf(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&px(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function ss(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const Ji=new WeakMap;function jo(r){const n=Ji.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),Ji.delete(r)},1700);Ji.set(r,s)}function gx(r){const n=CSS.escape(r),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 f=null;for(const g of l){if(!ss(g))continue;const p=g.querySelector(s);if(p&&ss(p)){f=p;break}}if(f??=Array.from(document.querySelectorAll(s)).find(ss)??null,!f)return;const c=Yf(f);if(!c){f.scrollIntoView({block:"start",behavior:"smooth"}),jo(f);return}const h=f.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),jo(f)}function En(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,f=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&f?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${f}"]`:null,s!==null&&f?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${f}"]`: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&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(A=>!!A),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let p=null;for(const A of g)if(ss(A)){for(const F of h){const B=A.querySelector(F);if(B&&ss(B)){p=B;break}}if(p)break}if(p??=h.flatMap(A=>Array.from(document.querySelectorAll(A))).find(ss)??null,!p){gx(r.filePath);return}const m=Yf(p);if(!m){p.scrollIntoView({block:"center",behavior:"smooth"}),jo(p);return}const u=p.getBoundingClientRect(),k=m.getBoundingClientRect(),M=u.top-k.top+m.scrollTop-Math.max(24,(m.clientHeight-u.height)/2);m.scrollTo({top:Math.max(0,M),behavior:"instant"}),jo(p)}const Xf=1,Jf=8;function bx(r){return Math.min(Jf,Math.max(Xf,r))}function Qf({resetKey:r,onZoomChange:n,onDoubleTap:s,children:l}){const f=a.useRef(null),[c,h]=a.useState({scale:1,x:0,y:0}),[g,p]=a.useState(!1),m=a.useRef(null),u=a.useRef(new Set),k=a.useRef(!1),b=a.useRef(null),M=a.useRef(0),A=a.useRef(c);A.current=c,a.useEffect(()=>{h({scale:1,x:0,y:0})},[r]);const F=a.useCallback((E,T,U)=>{const L=f.current;if(!L)return{x:T,y:U};const w=L.firstElementChild instanceof HTMLElement?L.firstElementChild:null,o=w?.clientWidth||L.clientWidth,O=w?.clientHeight||L.clientHeight,H=Math.max(0,(o*E-L.clientWidth)/2),W=Math.max(0,(O*E-L.clientHeight)/2);return{x:Math.min(H,Math.max(-H,T)),y:Math.min(W,Math.max(-W,U))}},[]),B=a.useCallback((E,T,U)=>{h(L=>{const w=bx(E),o=f.current;if(!o||w===1)return{scale:w,x:0,y:0};const O=o.getBoundingClientRect(),H=(T??O.left+O.width/2)-O.left-O.width/2,W=(U??O.top+O.height/2)-O.top-O.height/2,N=w/L.scale,q=H-(H-L.x)*N,fe=W-(W-L.y)*N;return{scale:w,...F(w,q,fe)}})},[F]),D=a.useCallback((E,T)=>{p(!0),A.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,E,T),window.setTimeout(()=>p(!1),220)},[B]);a.useEffect(()=>{const E=f.current;if(!E)return;const T=w=>{if(w.pointerType==="mouse"&&w.button!==0)return;const o=u.current.size===0;if(u.current.add(w.pointerId),o){const O=Date.now(),H=b.current;if(H&&O-H.time<350&&Math.hypot(w.clientX-H.x,w.clientY-H.y)<24){b.current=null,M.current=O,s?.(),D(w.clientX,w.clientY);return}}if(u.current.size>1){k.current=!0,m.current=null;return}if(!(A.current.scale<=1)){w.preventDefault(),m.current={pointerId:w.pointerId,startX:w.clientX,startY:w.clientY,originX:A.current.x,originY:A.current.y,moved:!1};try{E.setPointerCapture?.(w.pointerId)}catch{}p(!1)}},U=w=>{const o=m.current;if(!o||o.pointerId!==w.pointerId)return;const O=w.clientX-o.startX,H=w.clientY-o.startY;if(!o.moved){if(Math.hypot(O,H)<6)return;o.moved=!0}w.stopPropagation(),w.preventDefault(),h(W=>({...W,...F(W.scale,o.originX+O,o.originY+H)}))},L=w=>{const o=m.current,O=o?.pointerId===w.pointerId&&o.moved;if(o?.pointerId===w.pointerId){o.moved&&w.stopPropagation(),m.current=null;try{E.releasePointerCapture?.(w.pointerId)}catch{}}u.current.delete(w.pointerId)&&u.current.size===0&&(!k.current&&!O&&(b.current={time:Date.now(),x:w.clientX,y:w.clientY}),k.current=!1)};return E.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",L,{capture:!0}),window.addEventListener("pointercancel",L,{capture:!0}),()=>{E.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",L,{capture:!0}),window.removeEventListener("pointercancel",L,{capture:!0})}},[F,s,D]),Au({onPinch:({offset:[E],origin:[T,U]})=>{p(!1),B(E,T,U)},onWheel:({event:E,delta:[T,U],ctrlKey:L})=>{if(L){E.preventDefault(),E.stopPropagation(),p(!1),B(A.current.scale*(1-U*.01),E.clientX,E.clientY);return}A.current.scale<=1||(E.preventDefault(),E.stopPropagation(),p(!1),h(w=>({...w,...F(w.scale,w.x-T,w.y-U)})))}},{target:f,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Xf,max:Jf},from:()=>[A.current.scale,0],rubberband:!0}});const C=c.scale>1;return a.useEffect(()=>{n?.(C)},[n,C]),e.jsx("div",{ref:f,"data-sidebar-gesture-ignore":C?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:C?"grab":"zoom-in"},onDoubleClick:E=>{E.stopPropagation(),!(Date.now()-M.current<500)&&(s?.(),D(E.clientX,E.clientY))},children:l({scale:c.scale,zoomed:C,animateTransform:g,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0)`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Zf({src:r,alt:n,vector:s,onLoad:l,onError:f,onZoomChange:c,onDoubleTap:h}){const g=Ro(r,f),[p,m]=a.useState(null),u=s??No(r);return a.useEffect(()=>{m(null)},[r]),e.jsx(Qf,{resetKey:r,onZoomChange:c,onDoubleTap:h,children:({transformStyle:k,vectorTransformStyle:b,scale:M,animateTransform:A})=>{const F=e.jsx("img",{src:g,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*M,height:p.height*M,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:A?"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?{...k,width:p.width,height:p.height}:u?b:k,onLoad:B=>{const D=B.currentTarget,C=D.parentElement;if(C&&D.naturalWidth>0&&D.naturalHeight>0){const E=Math.max(1,C.clientWidth-2),T=Math.max(1,C.clientHeight-2),U=Math.min(E/D.naturalWidth,T/D.naturalHeight),L=u?U:Math.min(U,1);m({width:Math.max(1,Math.round(D.naturalWidth*L)),height:Math.max(1,Math.round(D.naturalHeight*L))})}l(B)},onError:f});return!u||!p?F:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...b,width:p.width,height:p.height},children:F})}})}function xx({svg:r,title:n,scale:s,vectorTransformStyle:l}){const f=a.useRef(null);return a.useLayoutEffect(()=>{const c=f.current,h=c?.querySelector("svg");if(!c||!h)return;const g=()=>{const u=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let k=u[2],b=u[3];if((!Number.isFinite(k)||!Number.isFinite(b)||k<=0||b<=0)&&(k=Number(h.getAttribute("width")),b=Number(h.getAttribute("height"))),!Number.isFinite(k)||!Number.isFinite(b)||k<=0||b<=0)return;const M=Math.max(1,c.clientWidth-24),A=Math.max(1,c.clientHeight-24),F=Math.min(M/k,A/b,1);h.style.width=`${Math.max(1,Math.floor(k*F*s))}px`,h.style.height=`${Math.max(1,Math.floor(b*F*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")};g();const p=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return p?.observe(c),()=>p?.disconnect()},[s,r,l]),e.jsx("div",{ref:f,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:r}})}function vx({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(Qf,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:f,scale:c})=>e.jsx(xx,{svg:r,title:n,scale:c,vectorTransformStyle:f})})}let wx=0,yx=0,kx=0,Sx=0,jx=0;function Qi(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function it(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++yx,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Os(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++Sx,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Rx(){return`diff-ui-${Date.now().toString(36)}-${(++jx).toString(36)}`}function Cx(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function Nx(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function vl({onReviewReference:r,filePath:n,active:s=!0,onInsertReference:l,onInsertText:f,onInsertFeature:c,onReferenceCopied:h,onClose:g,onDirectoryLinkOpen:p,isMobile:m,markdownOutlineOpen:u,markdownOutlineCloseSignal:k,onOpenMarkdownOutline:b,onCloseMarkdownOutline:M,markdownImageLightboxOpen:A,markdownImageLightboxCloseSignal:F,onOpenMarkdownImageLightbox:B,onCloseMarkdownImageLightbox:D,lineRange:C,onLineRangeChange:E,insertedReferenceKey:T,copiedReferenceKey:U,scrollToLine:L,onScrollToLineHandled:w}){const{t:o}=bt(),O=a.useRef(null);a.useEffect(()=>{s||O.current?.querySelectorAll("video").forEach(I=>I.pause())},[s]);const H=Y(I=>I.rootPath),W=Y(I=>I.selectFile),[N,q]=a.useState({kind:"idle"}),[fe,G]=a.useState("schematic"),[ee,P]=a.useState(null),_=a.useRef(null),[J,ue]=a.useState(null),pe=a.useRef(new Map),we=a.useRef(null),[je,Ce]=a.useState(null),[$,Q]=a.useState(()=>lu()),[ne,Le]=a.useState(()=>Yd(H,n)),Ye=a.useRef(null),[De,rt]=a.useState(!1),[_e,R]=a.useState(null),[se,he]=a.useState(0),[Ee,Me]=a.useState([]),[Ke,le]=a.useState(null),Ae=a.useRef(null),dt=a.useRef(n),[Pe,ke]=a.useState(null),[ut,Qe]=a.useState({status:"idle"}),[re,Te]=a.useState(!1),[et,Ot]=a.useState(""),[lt,z]=a.useState([]),[ae,ve]=a.useState(0),Xe=a.useRef(null),Nt=Hu(h),ir=Ll(H,n);a.useEffect(()=>{if(dt.current===n)return;dt.current=n;const I=n&&H&&!n.startsWith("/")?`${H}/${n}`:n;if(Ae.current===I){Ae.current=null;return}Ae.current=null,Me([]),le(null),Te(!1),Ot("")},[n,H]);const At=n?H&&!n.startsWith("/")?`${H}/${n}`:n:null,Pt=Y(I=>At?(I.fileChangeVersions.get(At)??0)+I.fileWatchEpoch:I.fileWatchEpoch),Sr=a.useRef(null),Xt=a.useRef(null),[Mn,ta]=a.useState(0),as=a.useCallback(()=>ta(I=>I+1),[]);a.useEffect(()=>{const I=_.current;return _.current=null,P(null),I&&URL.revokeObjectURL(I.objectUrl),()=>{const K=_.current;_.current=null,K&&URL.revokeObjectURL(K.objectUrl)}},[At,Pt,Mn]),a.useEffect(()=>{if(!n){Sr.current=null,q({kind:"idle"});return}const I=H&&!n.startsWith("/")?`${H}/${n}`:n,K=new AbortController,de=++wx,ye=`right-sidebar-file-preview:${de}`,Ze=performance.now();let Fe=!1;const Oe=(Z,He={})=>{Fe||(Fe=!0,Qi("end",{loadingId:de,reason:Z,durationMs:Math.round(performance.now()-Ze),filePath:n,fullPath:I,rootPath:H,...He}))};let Ue=null;const mt=mm(I),xt=mt?I.toLowerCase().endsWith(".kicad_pcb")?fe==="schematic"?"pcb-front":fe:"schematic":fe,sn=!mt&&wl(I),tr=!mt&&!sn&&pm(I),zr=!mt&&!sn&&!tr&&Nu(I),hs=Fs(I),ms=Ts(I),hr=mt?"eda":sn?"image":tr?"model3d":zr?"video":"text",an=Sr.current!==I;if(Sr.current=I,an){Qi("start",{loadingId:de,filePath:n,fullPath:I,rootPath:H,mode:hr,externalVersion:Pt}),Qe({status:"idle"}),q({kind:"loading",mode:hr}),Xt.current=null;const Z=wu(H,n);E(Z?.lineRange??null),Q(hs?lu():"source"),Le(ms?Yd(H,n):"source"),mt&&G(gm(I))}an||q(Z=>Z.kind==="error"?{kind:"loading",mode:hr}:Z);const on=window.setTimeout(()=>{Fe||K.signal.aborted||Qi("still_active",{loadingId:de,filePath:n,fullPath:I,rootPath:H,mode:hr,durationMs:Math.round(performance.now()-Ze),isPathChange:an})},3e3),Mo=window.setTimeout(()=>{if(Fe||K.signal.aborted)return;const Z=mt?o("rightSidebar.edaTimeout"):tr?o("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";K.abort(new DOMException(Z,"TimeoutError")),q({kind:"error",message:Z}),Oe("stuck_timeout",{error:Z})},mt?bm+5e3:tr?xm+5e3:vm(I)?35e3:db);if(mt){const Z=xt==="pcb-3d"?_.current:null;Z?(q(Z),Oe("eda_3d_client_cache_hit",{bytes:Z.meta.size,view:Z.view,mimeType:Z.meta.mimeType})):wm(I,xt,K.signal,"view_file",ye).then(He=>{if(K.signal.aborted)return;Ue=URL.createObjectURL(He.blob);const Ut={kind:"eda",sourcePath:He.path||I,objectUrl:Ue,view:He.view,meta:{size:He.size,mimeType:He.mimeType,modified:He.modified}};if(He.view==="pcb-3d"){const Er=_.current;Er&&Er.objectUrl!==Ue&&URL.revokeObjectURL(Er.objectUrl),_.current=Ut,P(Ut),Ue=null}q(Ut),Oe("eda_loaded",{bytes:He.size,view:He.view,mimeType:He.mimeType})}).catch(He=>{K.signal.aborted||(q({kind:"error",message:He instanceof Error&&/timed out/i.test(He.message)?o("rightSidebar.edaTimeout"):He instanceof Error?He.message:o("rightSidebar.edaLoadFailed")}),Oe("error",{error:He instanceof Error?He.message:String(He)}))})}else if(sn)ym(I,K.signal,"view_file",ye).then(Z=>{Ue=URL.createObjectURL(Z.blob),q({kind:"image",objectUrl:Ue,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Oe("image_loaded",{bytes:Z.size,mimeType:Z.mimeType})}).catch(Z=>{K.signal.aborted||(q({kind:"error",message:Z instanceof Error?Z.message:o("rightSidebar.imageLoadFailed")}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(tr)km(I,K.signal,"view_file",ye).then(Z=>{K.signal.aborted||(Ue=URL.createObjectURL(Z.blob),q({kind:"model3d",sourcePath:Z.path||I,objectUrl:Ue,ext:Z.ext,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Oe("model3d_loaded",{bytes:Z.size,ext:Z.ext}))}).catch(Z=>{K.signal.aborted||(q({kind:"error",message:Z instanceof Error&&(Z.name==="TimeoutError"||/timed out/i.test(Z.message))?o("rightSidebar.model3dTimeout"):Z instanceof Error?Z.message:o("rightSidebar.model3dLoadFailed")}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(zr){const Z=Sm(I)??"",He=Eu(I);q(Ut=>Ut.kind==="video"&&Ut.url===He?Ut:{kind:"video",url:He,meta:{size:null,mimeType:Z,modified:null}}),Oe("video_ready",{mimeType:Z})}else Rd(I,K.signal,"view_file",ye).then(Z=>{if(!K.signal.aborted){if(Z.binary){q({kind:"binary"});return}q({kind:"text",content:Z.content,sourcePath:Z.path||I,meta:{size:Z.size,truncated:Z.truncated}}),Oe("text_loaded",{bytes:Z.size,truncated:!!Z.truncated})}}).catch(Z=>{K.signal.aborted||(q({kind:"error",message:Z instanceof Error?Z.message:"Failed to read file"}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});return()=>{K.abort(),Ct(ye),window.clearTimeout(on),window.clearTimeout(Mo),Ue&&URL.revokeObjectURL(Ue),Oe("cleanup")}},[n,H,Pt,Mn,E,o,fe]),a.useEffect(()=>{if(N.kind!=="model3d"||!n){ue(null);return}let I=!1;const K=n.lastIndexOf("/"),de=K>=0?n.slice(K+1):n,ye=K>=0?n.slice(0,K):"",Ze=ye.lastIndexOf("/"),Fe=Ze>=0?ye.slice(0,Ze):"",Oe=de.replace(/\.(stl|glb|gltf)$/i,""),Ue=`${Fe?`${Fe}/`:""}features/${Oe}.json`;return Rd(Ue).then(mt=>{if(!I)try{const xt=JSON.parse(mt.content);ue(xt.version===1&&Array.isArray(xt.features)&&xt.features.length>0?xt.features:null)}catch{ue(null)}}).catch(()=>{I||ue(null)}),()=>{I=!0}},[N,n]),a.useEffect(()=>{if(N.kind!=="text"){ke(null);return}const I=H&&n&&!n.startsWith("/")?`${H}/${n}`:n,K=_u(I),de=N.content,ye=Fs(I??"")&&$==="preview",Ze=Ts(I??"")&&ne==="preview";if(!K||ye||Ze||!Bu(de)){ke(null);return}let Fe=!1;const Oe=Ue=>{if(Fe||!Ue.registered(K)){Fe||ke(null);return}try{ke(Uu(Ue,de,K))}catch{ke(null)}};return _e?Oe(_e):(ke(null),Ou().then(Ue=>{Fe||(R(Ue),Oe(Ue))}).catch(()=>{})),()=>{Fe=!0}},[N,_e,n,H,$,ne]),a.useLayoutEffect(()=>{if(!ir||N.kind!=="text")return;const I=`${ir}:${$}:${ne}`;if(Xt.current===I)return;const K=wu(H,n);if(Xt.current=I,!K)return;const de=requestAnimationFrame(()=>{const ye=we.current;if(!ye)return;const Ze=$==="preview"?K.markdownTop??K.top:K.top;ye.scrollTo({top:Math.max(0,Ze??0),left:Math.max(0,K.left??0)}),he($==="preview"?Math.max(0,Ze??0):0)});return()=>cancelAnimationFrame(de)},[n,$,ne,N.kind,ir,H]),a.useEffect(()=>{ir&&Gi(H,n,{lineRange:C})},[n,C,ir,H]),a.useEffect(()=>{if(L==null||N.kind!=="text")return;Ce(null),E({start:L,end:L});const I=L,K=requestAnimationFrame(()=>{const de=pe.current.get(I);de&&de.scrollIntoView({block:"center"}),w?.()});return()=>cancelAnimationFrame(K)},[L,N,E,w]);const _r=a.useCallback(I=>{const K=we.current;if(!K)return!1;const de=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(I):I.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ye=K.querySelector(`#${de}`);return ye?(ye.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const I=H&&n&&!n.startsWith("/")?`${H}/${n}`:n,K=N.kind==="text"&&Fs(I??"")&&$==="preview";if(!Ke||!K)return;const de=requestAnimationFrame(()=>{_r(Ke)&&le(null)});return()=>cancelAnimationFrame(de)},[n,_r,$,Ke,N,H]),a.useLayoutEffect(()=>{const I=we.current;if(!I||!C){Ce(null);return}if(je)return;const K=N.kind==="image"||N.kind==="loading"&&N.mode==="image",de=H&&n&&!n.startsWith("/")?`${H}/${n}`:n,ye=N.kind==="text"&&Fs(de??"")&&$==="preview",Ze=N.kind==="text"&&Ts(de??"")&&ne==="preview";if(N.kind!=="text"||K||ye||Ze){Ce(null);return}const Fe=()=>{const Ue=pe.current.get(C.end);if(!Ue||!I){Ce(null);return}const mt=Ue.offsetTop+Ue.offsetHeight/2,xt=I.scrollLeft+Math.max(8,I.clientWidth-120);Ce({top:mt,left:xt})};Fe();const Oe=new ResizeObserver(()=>Fe());return Oe.observe(I),()=>Oe.disconnect()},[C,je,N,$,ne,n,H,Pe]);const jr=N.kind==="text"&&!(Ts(At??"")&&ne==="preview")&&!At?.toLowerCase().endsWith(".csv")&&!At?.toLowerCase().endsWith(".kicad_pro")&&!At?.toLowerCase().endsWith(".kicad_prl"),St=a.useCallback(()=>{Te(!1),Ot(""),z([]),ve(0),to()},[]),$n=a.useCallback(()=>{jr&&(Te(!0),requestAnimationFrame(()=>{Xe.current?.focus(),Xe.current?.select()}))},[jr]),Jt=a.useCallback(I=>{ve(K=>lt.length===0?0:(K+I+lt.length)%lt.length)},[lt.length]);if(a.useEffect(()=>{const I=K=>{const de=Kg(K);if(de==="open"&&jr){K.preventDefault(),$n();return}re&&(de==="close"?(K.preventDefault(),St()):(de==="next"||de==="previous")&&(K.preventDefault(),Jt(de==="previous"?-1:1)))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[St,re,Jt,$n,jr]),a.useLayoutEffect(()=>{if(to(),!re||!et.trim()||!we.current){z([]),ve(0);return}const I=Vg(we.current,et);return z(I),ve(0),Zd(I,0),eu(I[0]),to},[re,et,Pe,$,N]),a.useEffect(()=>{re&&(Zd(lt,ae),eu(lt[ae]))},[ae,lt,re]),a.useEffect(()=>to,[]),!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:o("rightSidebar.selectFilePrompt")});const We=H&&!n.startsWith("/")?`${H}/${n}`:n,lr=mo(We,H),Br=$u(We,H),Or=N.kind==="text"&&N.content?N.content.split(`
|
|
1658
|
-
`):[],Ur=Math.max(2,String(Or.length).length)+1,Rr=
|
|
1659
|
-
${de}${
|
|
1660
|
-
${
|
|
1635
|
+
`,eo="/api/terminal/fs/preview/",Hg=8*1024*1024,zg=32*1024*1024,Wg=128,Gg="data:,";function $t(r){throw new Error(r)}function Kg(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function tu(r,n,s){let l="",f=0;for(const c of r.matchAll(n))l+=r.slice(f,c.index)+await s(c),f=c.index+c[0].length;return l+r.slice(f)}async function Qu(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!Ts(l.pathname)?.startsWith(eo))&&$t("预览地址不是有效的本地文件入口");const f=crypto.randomUUID(),c=`https://termdock-preview.invalid/${f}/`,h=[],g=W=>{!h.includes(W)&&h.length<20&&h.push(W)},p=new Set,m=[],u=new Set,y=new Map,b=new Map;let $=0,T=!1;const I=new Set,D=()=>{T=!0;for(const W of[...I])W();p.clear(),m.length=0};async function U(W){W.ok||$t(`预览资源读取失败(${W.status})`);const ee=W.body?.getReader(),A=[];let B=0;try{if(ee)for(;;){const me=await ee.read();if(me.done)break;B+=me.value.byteLength,$+=me.value.byteLength,(B>Hg||$>zg)&&$t("预览资源超出大小限制"),A.push(me.value)}}catch(me){throw await ee?.cancel().catch(()=>{}),me}finally{ee?.releaseLock()}const J=new Uint8Array(B);let ue=0;for(const me of A)J.set(me,ue),ue+=me.length;return{bytes:J,type:W.headers.get("content-type")??"application/octet-stream",status:W.status}}let C=l,R;for(let W=0;W<4;W++){const ee=await n.fetch(C.pathname+C.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(ee.status)){R=ee;break}const A=ee.headers.get("location");await ee.body?.cancel(),A||$t("预览重定向缺少目标");const B=new URL(A,C);(B.origin!==s||!Ts(B.pathname)?.startsWith(eo))&&$t("预览重定向越出文件范围"),C=B}R||$t("预览重定向次数过多");const M=Ts(C.pathname),H=M.slice(eo.length).split("/");/^[a-f0-9]{32}$/.test(H[0])||$t("服务未提供有效的预览资源授权");const F=Ts(l.pathname).slice(eo.length).split("/");/^[a-f0-9]{32}$/.test(F[0])&&F.shift(),F.join("/").replace(/\/$/,"")!==H.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const S=M.endsWith("/")?M:M.slice(0,M.lastIndexOf("/")+1),o=new URL(C.pathname.endsWith("/")?C.pathname:C.pathname.slice(0,C.pathname.lastIndexOf("/")+1),s);function O(W,ee){const A=new URL(W,ee);return A.origin!==s?null:(Ts(A.pathname)?.startsWith(S)||$t("已阻止预览访问目录之外的资源"),A)}function P(W){const ee=new URL(W,c);(ee.origin!==new URL(c).origin||!ee.pathname.startsWith(new URL(c).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const A=ee.pathname.slice(new URL(c).pathname.length)+ee.search;return O(A,o)??$t("预览资源无效")}function V(W){const ee=W.pathname+W.search,A=y.get(ee);if(A)return A;if(T||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(y.size>=Wg)return Promise.reject(new Error("预览资源数量超出限制"));const B=n.fetch(ee,{signal:n.signal,redirect:"manual"}).then(U);return y.set(ee,B),B}function E(W,ee){T&&$t("预览已关闭");const A=`termdock-resource-${f}-${m.length}`;return m.push({token:A,data:W,type:ee}),p.add(A),A}async function K(W,ee,A,B=new Set){if(!W||W.startsWith("#")||/^data:(?:image|font)\//i.test(W)&&A==="resource")return W;try{const J=O(W,ee);if(!J){const Ne=new URL(W,ee);return(Ne.protocol!=="https:"||Ne.username||Ne.password||Ne.origin===new URL(c).origin)&&$t("已阻止不安全的外部资源"),u.add(Ne.origin),Ne.href}const ue=`${A}:${J.href}`;(B.has(ue)||B.size>=8)&&$t("预览资源存在循环或过深引用");const me=b.get(ue);if(me)return me;const ye=new Set(B);ye.add(ue);const je=(async()=>{const Ne=await V(J);return A==="css"?E(await pe(new TextDecoder().decode(Ne.bytes),J,ye),"text/css"):A==="script"?E(Ne.bytes,"text/javascript"):E(Ne.bytes,Ne.type)})();return b.set(ue,je),await je}catch(J){return g(J instanceof Error?J.message:"部分预览资源未能加载"),Gg}}async function pe(W,ee,A){return W=await tu(W,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async B=>`@import url("${await K(B[1],ee,"css",A)}")${B[2]};`),tu(W,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async B=>{const J=(B[1]??B[2]??B[3]).trim();return p.has(J)?B[0]:`url("${await K(J,ee,"resource",A)}")`})}try{const W=await U(R),ee=E(Og,"text/javascript"),A=new DOMParser().parseFromString(new TextDecoder().decode(W.bytes),"text/html");A.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(L=>L.remove());for(const L of A.querySelectorAll("*")){if(L.removeAttribute("ping"),L.removeAttribute("srcdoc"),L.hasAttribute("style")&&L.setAttribute("style",await pe(L.getAttribute("style"),C,new Set)),L.tagName==="STYLE"&&(L.textContent=await pe(L.textContent??"",C,new Set)),L.tagName==="A"||L.tagName==="AREA"){const Q=L.getAttribute("href");try{if(Q&&!Q.startsWith("#")){const ne=O(Q,C);if(ne)L.setAttribute("href",new URL(ne.pathname.slice(o.pathname.length)+ne.search+ne.hash,c).href);else{const Le=new URL(Q,C);if(Le.protocol!=="https:"){L.removeAttribute("href");continue}u.add(Le.origin),L.setAttribute("href",Le.href)}}}catch(ne){L.removeAttribute("href"),g(ne instanceof Error?ne.message:"预览链接无法加载")}}for(const Q of["data","manifest"])L.removeAttribute(Q);if(L.tagName==="SCRIPT"&&L.getAttribute("type")==="module"){L.setAttribute("type","module-shim");const Q=L.getAttribute("src");if(Q){const ne=O(Q,C);if(ne)L.setAttribute("src",new URL(ne.pathname.slice(o.pathname.length)+ne.search,c).href);else{const Le=new URL(Q,C);if(Le.protocol!=="https:"){L.remove();continue}u.add(Le.origin),L.setAttribute("src",Le.href)}}continue}if(L.tagName==="SCRIPT"&&L.getAttribute("type")==="importmap"){L.setAttribute("type","importmap-shim");continue}if(L.tagName==="LINK"){const Q=(L.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Q)){L.remove();continue}const ne=L.getAttribute("href");ne&&L.setAttribute("href",await K(ne,C,Q==="stylesheet"?"css":"resource"))}if(L.hasAttribute("src")&&L.setAttribute("src",await K(L.getAttribute("src"),C,L.tagName==="SCRIPT"?"script":"resource")),L.hasAttribute("poster")&&L.setAttribute("poster",await K(L.getAttribute("poster"),C,"resource")),L.hasAttribute("srcset")){const Q=L.getAttribute("srcset");/data:/i.test(Q)?(L.removeAttribute("srcset"),g("混合内嵌图片候选暂不支持安全预览")):L.setAttribute("srcset",(await Promise.all(Q.split(",").map(async ne=>{const[Le,...Ye]=ne.trim().split(/\s+/);return`${await K(Le,C,"resource")} ${Ye.join(" ")}`}))).join(", "))}L.setAttribute("referrerpolicy","no-referrer"),L.removeAttribute("integrity"),L.removeAttribute("crossorigin")}const B=[...u].join(" "),J=A.createElement("meta");J.httpEquiv="Content-Security-Policy",J.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${B}; style-src 'unsafe-inline' blob: ${B}; img-src blob: data: ${B}; font-src blob: data: ${B}; media-src blob: data: ${B}; connect-src blob: ${B} ${[...u].map(L=>L.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const ue=A.createElement("base");ue.href=c;const me=A.createElement("meta");me.name="referrer",me.content="no-referrer";const ye=A.createElement("script");ye.textContent=Ug+`
|
|
1636
|
+
installPreviewRuntime(`+[f,c,[...u],ee].map(Kg).join(",")+");";const je=A.createElement("script");je.src=ee,A.head.prepend(J,me,ue,ye,je);const Ne=`<!doctype html>
|
|
1637
|
+
`+A.documentElement.outerHTML;return{html:Ne,shellUrl:`/preview-shell.html#${f}`,errors:h,attach(L,Q){const ne=new Set,Le=De=>{if(De.source!==L.contentWindow||De.data?.capability!==f)return;if(De.data.type==="preview-ready"){L.contentWindow?.postMessage({type:"preview-init",capability:f,html:Ne,resources:m},"*");return}if(De.data.type==="preview-error"){Q("部分动态内容被安全预览限制");return}if(De.data.type==="preview-navigate"){(async()=>{const _e=P(String(De.data.url)),N=await Qu(_e.pathname+_e.search,n);if(T){N.dispose();return}const se=N.attach(L,Q);I.add(()=>{se(),N.dispose()}),L.src=N.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(_e=>Q(_e instanceof Error?_e.message:"无法打开预览页面"));return}if(De.data.type==="preview-external"){try{const _e=new URL(String(De.data.url));_e.protocol==="https:"&&u.has(_e.origin)&&window.open(_e.href,"_blank","noopener,noreferrer")}catch{}return}if(De.data.type!=="preview-fetch"||De.ports.length!==1)return;const rt=De.ports[0];if(ne.size>=8||!["GET","HEAD"].includes(De.data.method)){rt.postMessage({error:"预览仅允许读取已授权目录资源"}),rt.close();return}ne.add(rt),(async()=>{const _e=P(String(De.data.url)),N=await V(_e);if(!ne.has(rt)||T)return;const se=De.data.method==="HEAD"?new Uint8Array:N.bytes.slice();rt.postMessage({status:N.status,headers:{"content-type":N.type},data:se.buffer},[se.buffer])})().catch(()=>{rt.postMessage({error:"预览资源不在授权范围或无法加载"}),Q("部分动态资源不可用或超出预览目录")}).finally(()=>{ne.delete(rt),rt.close()})};window.addEventListener("message",Le);const Ye=()=>{window.removeEventListener("message",Le);for(const De of ne)De.close();ne.clear(),I.delete(Ye)};return I.add(Ye),Ye},dispose:D}}catch(W){throw D(),W}}const qg=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:f},c){const h=a.useRef(null),[g,p]=a.useState(null),[m,u]=a.useState(),[y,b]=a.useState("");a.useEffect(()=>{const M=new AbortController;let H;return u(void 0),b(""),(async()=>{const F=await pm();if(H=await Qu(n,{fetch:(S,o)=>F.fetch(S,o),signal:M.signal}),M.signal.aborted){H.dispose();return}u(H),H.errors.length&&b(H.errors.join(";"))})().catch(F=>{M.signal.aborted||b(F instanceof Error?F.message:"安全预览加载失败")}),()=>{M.abort(),H?.dispose()}},[n]),a.useEffect(()=>{if(!(!m||!g))return m.attach(g,b)},[m,g]);const[$,T]=a.useState(!1),[I,D]=a.useState(!1),U=$||I;a.useEffect(()=>{f?.(U)},[U,f]),a.useEffect(()=>{const M=()=>{T(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",M),()=>document.removeEventListener("fullscreenchange",M)},[]),a.useEffect(()=>{if(!I)return;const M=H=>{H.key==="Escape"&&D(!1)};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[I]);const C=a.useCallback(async()=>{const M=h.current;if(M){if(I){D(!1);return}if(document.fullscreenElement===M){await document.exitFullscreen();return}if(M.requestFullscreen&&document.fullscreenEnabled!==!1)try{await M.requestFullscreen();return}catch{}D(!0)}},[I]);a.useImperativeHandle(c,()=>({toggleFullscreen:C}),[C]);const R=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:()=>{C()},"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(Ou,{size:15})})]}),y&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:y}),!m&&!y&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:p,src:m?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return I?kr.createPortal(R,document.body):R}),Zu="termdock-file-search-match",cl="termdock-file-search-current";function Vg(r){const n=r.metaKey||r.ctrlKey,s=r.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||r.key==="F3"?r.shiftKey?"previous":"next":r.key==="Escape"?"close":null}function Yg(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Xg(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let f="",c=null;const h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let u=h.nextNode();u;u=h.nextNode()){if(!(u instanceof Text)||!u.data)continue;const y=Yg(u);if(!y)continue;c&&c!==y&&(f+=`
|
|
1638
|
+
`);const b=f.length;f+=u.data,l.push({node:u,start:b,end:f.length,group:y}),c=y}const g=f.toLocaleLowerCase(),p=[];let m=0;for(;m<=g.length-s.length;){const u=g.indexOf(s,m);if(u<0)break;const y=u+s.length,b=l.find(T=>T.start<=u&&T.end>u),$=l.find(T=>T.start<y&&T.end>=y);if(b&&$&&b.group===$.group){const T=document.createRange();T.setStart(b.node,u-b.start),T.setEnd($.node,y-$.start),p.push(T)}m=u+Math.max(s.length,1)}return p}function ef(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function to(){const r=ef();r?.delete(Zu),r?.delete(cl)}function ru(r,n){const s=ef();if(!s||typeof Highlight>"u")return;s.set(Zu,new Highlight(...r));const l=r[n];l?s.set(cl,new Highlight(l)):s.delete(cl)}function nu(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Jg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Qg(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Zg(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function tf(r,n,s){return n?r:kr.createPortal(r,s)}const Sl="termdock:right-sidebar:file-tree-scroll:v1",jl="termdock:right-sidebar:file-preview-reading-state:v1",Hs="termdock:right-sidebar:file-tree-width:v1",rf="termdock:right-sidebar:markdown-view-mode:v1",nf="termdock:right-sidebar:diff-change-list-mode:v1",sf="termdock:right-sidebar:diff-wrap:v1",af="termdock:diff-viewer:view-type:v1",of="termdock:right-sidebar:file-search-mode:v1",_i="termdock:right-sidebar:collapsed-git-repo-groups:v1",su="termdock:right-sidebar:collapsed-diff-directories:v1",Bi="termdock:right-sidebar:branch-audit-module-open:v1",lf="termdock:right-sidebar:branch-audit-module:v1",eb=150,au="termdock:right-sidebar:context-draft-enabled:v1",ou="termdock:right-sidebar:context-draft-collapsed:v1",iu="termdock:right-sidebar:context-draft-auto-collapse:v1",Oi="termdock:right-sidebar:context-draft-text:v1",tb=300,rb=20,nb=120,sb=250,ab=250,ob=120,ib=700,Ui=600,lb=6e4;function Fs(r){return!!(r&&Y.getState().nestedGitScanRoots[r])}const lu=[2e3,5e3,15e3,3e4],cb=320,db=500,ub=20,fb=12e3,dl=300,cu=240,hb=560,cf="border-r px-2 py-1.5 sm:px-3 sm:py-2",xo="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",df=`${cf} border-b border-border/15 font-semibold last:border-r-0`,uf=`${cf} border-border/10 align-top text-muted-foreground last:border-r-0`,Rl="termdock-file-preview-horizontal-scroll",du=a.lazy(()=>Xs(()=>import("./ModelPreview-Bnlo-oVE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),ff=`${Rl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function hf(r,n,s){return r&&!n?"unified":s}const mb=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function pb(r){return r==="preview"||r==="source"}function gb(r){return r==="list"||r==="tree"||r==="ai"}function uu(){return mt(rf,pb)??"preview"}function bb(){return mt(nf,gb)??"tree"}function zs(r){return typeof r=="boolean"}function xb(r){return typeof r=="string"}function vb(){return mt(sf,zs)??!0}function yb(r){return r==="unified"||r==="split"}function wb(){return mt(af,yb)??"unified"}function kb(r){return r==="name"||r==="content"||r==="regex"}function Sb(){return mt(of,kb)??"name"}function mf(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:kt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function jb(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function ul(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function pf(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function fl(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function fu(r){const n=mt(r,fl);return n?new Set(n):new Set}function Hi(r,n){Lt(r,[...n])}function Rb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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 Nb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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||fl(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Rb))&&(n.commits===void 0||fl(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 Cb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&Nb(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Eb(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).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(Cb))&&(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.repoIncludeUncommitted===void 0||!!s.repoIncludeUncommitted&&typeof s.repoIncludeUncommitted=="object"&&!Array.isArray(s.repoIncludeUncommitted)&&Object.values(s.repoIncludeUncommitted).every(l=>typeof l=="boolean"))&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function hu(){return mt(lf,Eb)??{}}function mu(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function pu(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function gf(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||pu(s)===pu(l)}function gu(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!gf(l,n))??""}function hl(r,n){const s=Math.max(cu,n-320),l=Math.min(hb,s);return Math.min(l,Math.max(cu,r))}function Mb(r){return typeof r=="number"&&Number.isFinite(r)}function $b(r){return hl(mt(Hs,Mb)??dl,r)}function bf(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function _s(r){return mb.has(bf(r))}function xf(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function ml(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||xf(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function vf(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const yf=a.createContext(null);function ho(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function wf(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function kf(r){return r.replace(/\s+#+\s*$/,"").trim()}function pl(r,n){const l=wf(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",f=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,f+1),f===0?l:`${l}-${f}`}function bu(r){return wf(r)||r.trim()}function vo(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=bl(n[2]);return s?{id:ho(n[1]),definition:{href:s.href,title:s.title}}:null}function Lb(r){const n=new Map;for(const s of r){const l=vo(s);l&&n.set(l.id,l.definition)}return n}function Sf(r){return r.trim().toLowerCase()}function jf(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Sf(n[1]),text:n[2]}:null}function Pb(r){const n=new Map;let s=null;for(const l of r){const f=jf(l);if(f){s=f.id,n.set(f.id,{id:f.id,text:f.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function Rf(r){const n=new Set;let s=!1;return r.forEach((l,f)=>{if(jf(l)){n.add(f),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(f);return}l.trim()&&(s=!1)}),n}function Ab(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const f=r[s].trim();if(f.startsWith("<!--")){if(n[s]="",!f.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Nf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Ks(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function Nl(r,n,s){const l=r.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 f=l.indexOf("#"),c=f>=0?l.slice(0,f):l,h=f>=0?l.slice(f+1):"",g=c.split("?",1)[0];if(!g)return null;let p,m=null;try{p=decodeURIComponent(g),m=h?decodeURIComponent(h):null}catch{return null}const u=s?Ks(s):null;let y;if(p.startsWith("/")){const b=u&&(p===u||p.startsWith(`${u}/`));y=Ks(u&&!b?`${u}/${p.slice(1)}`:p)}else{if(!n)return null;y=Ks(`${Nf(n)}/${p}`)}return u&&y!==u&&!y.startsWith(`${u}/`)?null:{path:y,fragment:m,directory:/\/$/.test(g)}}function Cl(r,n,s,l,f){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const g=s&&(c===s||c.startsWith(`${s}/`));h=Ks(s&&!g?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Ks(`${Nf(n)}/${c}`)}return f(h)}function Tb(r,n,s){return Cl(r,n,s,wl,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Ib(r,n,s){return Cl(r,n,s,Lu,Pu)}const gl=128,Db=360,zi=480;function Co(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function Cf(r,n,s,l,f=0){if(!n||!s)return null;let c,h;return f>0?(c=l>0?Math.min(f,l):f,h=s*c/n):Co(r)?(h=Math.min(Math.max(s,gl),Db),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>zi&&(c=c*zi/h,h=zi),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Fb(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Ef(r){const n=Fb(r),s=Y(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function _b({src:r,alt:n,title:s,requestedWidthPx:l}){const f=Co(r),c=Ef(r),h=Ro(c),g=a.useRef(null),[p,m]=a.useState(!1),[u,y]=a.useState(0),[b,$]=a.useState({status:"loading"}),[T,I]=a.useState(null);a.useLayoutEffect(()=>{const C=g.current;let R=C?.parentElement?.parentElement??C?.parentElement;for(;R;){const S=window.getComputedStyle(R).display;if(S!=="inline"&&S!=="contents")break;R=R.parentElement}if(!R)return;const M=R,H=()=>{const S=window.getComputedStyle(M),o=(parseFloat(S.paddingLeft)||0)+(parseFloat(S.paddingRight)||0);y(Math.max(0,M.clientWidth-o))};if(H(),typeof ResizeObserver>"u")return;const F=new ResizeObserver(H);return F.observe(M),()=>F.disconnect()},[]),a.useEffect(()=>{if(p)return;const C=g.current;if(!C||typeof IntersectionObserver>"u"){m(!0);return}const R=new IntersectionObserver(M=>{M.some(H=>H.isIntersecting)&&(m(!0),R.disconnect())},{rootMargin:"400px"});return R.observe(C),()=>R.disconnect()},[p]),a.useEffect(()=>{if(!p)return;const C=new AbortController;let R=null;$({status:"loading"});const M=window.setTimeout(()=>{C.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return zm(c,{signal:C.signal}).then(async H=>{if(!H.ok)throw new Error(`HTTP ${H.status}`);const F=Number(H.headers.get("X-Image-Width"))||0,S=Number(H.headers.get("X-Image-Height"))||0;return{blob:await H.blob(),width:F,height:S}}).then(({blob:H,width:F,height:S})=>{C.signal.aborted||(R=URL.createObjectURL(H),F>0&&S>0&&I({width:F,height:S}),$({status:"ready",objectUrl:R}))}).catch(()=>{const H=C.signal.reason;C.signal.aborted&&!(H instanceof DOMException&&H.name==="TimeoutError")||$({status:"fallback"})}).finally(()=>{window.clearTimeout(M)}),()=>{window.clearTimeout(M),C.abort(),R&&URL.revokeObjectURL(R)}},[p,c]);const D=Cf(r,T?.width??0,T?.height??0,u,l??0),U=D??(l?{width:u>0?Math.min(l,u):l,height:Math.round(l*.75)}:{width:gl*2,height:gl});return e.jsx("div",{ref:g,className:"block max-w-full",style:D?{width:D.width,height:D.height}:void 0,children:b.status==="ready"?e.jsx("img",{src:b.objectUrl,alt:n,title:s,decoding:"async",className:`${f?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:D?{width:D.width,height:D.height}:void 0,onLoad:C=>{const R=C.currentTarget;R.naturalWidth>0&&R.naturalHeight>0&&(T?.width!==R.naturalWidth||T?.height!==R.naturalHeight)&&I({width:R.naturalWidth,height:R.naturalHeight})}}):b.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:D?{width:D.width,height:D.height}:void 0,onLoad:C=>{const R=C.currentTarget;R.naturalWidth>0&&R.naturalHeight>0&&(T?.width!==R.naturalWidth||T?.height!==R.naturalHeight)&&I({width:R.naturalWidth,height:R.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 qs(r,n,s,l,f,c){const h=Tb(s,f.markdownFilePath,f.rootPath);if(!h)return c?.fallbackText??``;const g=f.images.length;f.images.push({kind:"image",src:h,alt:n,title:l});const p=e.jsx(_b,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return f.onImageOpen&&c?.interactive!==!1?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:m=>{m.stopPropagation(),f.onImageOpen?.(g)},children:p},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:p},r)}function Wi(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function xu(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function bl(r){const n=r.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 Mf="",Bb=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Ob(r){return r.replace(Bb,(n,s)=>`${Mf}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function vu(r){return r.replace(new RegExp(`${Mf}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Ub(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const $f={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 ro=null;function Lf(){return ro||(ro=Xs(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw ro=null,r})),ro}function Pf({html:r}){const{t:n}=pt(),[s,l]=a.useState(null);return a.useEffect(()=>{let f=!1;return l(null),Lf().then(c=>{f||l(c.sanitize(r,$f))}).catch(()=>{f||l("")}),()=>{f=!0}},[r]),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 Hb({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Lf().then(f=>{l||s(f.sanitize(r,$f))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function Af(r){const n=r.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(r)}}let no=null;function zb(){return no||(no=Promise.all([Xs(()=>import("./katex-DnlPpQZa.js"),[]),Xs(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw no=null,r})),no}function Qs({tex:r,display:n=!1}){const[s,l]=a.useState(null),[f,c]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),c(!1),zb().then(p=>{g||l(p.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||c(!0)}),()=>{g=!0}},[n,r]),f)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});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 El(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function yu(r){const n=El(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Wb(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=El(s),f=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:f,fallbackText:g,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function Gb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:f}=pt(),[c,h]=a.useState(!1),g=Ro(r,()=>h(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||f("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function Kb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),g=El(h).get("href")?.trim()??"",p=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:m,alt:u,title:y,widthPx:b}=yu(p);if(!m)return null;const $=Cl(m,s.markdownFilePath,s.rootPath,wl,C=>C);if(!$)return null;const T=g?Nl(g,s.markdownFilePath,s.rootPath):null,D=!!!(T&&T.path===$)&&g?vf(g):null,U=qs(n,u??"",m,y,s,{requestedWidthPx:b,interactive:D?!1:void 0});return D?e.jsx("a",{href:D,target:"_blank",rel:"noreferrer",children:U},n):U}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:g,title:p,widthPx:m}=yu(r);return h?qs(n,g??"",h,p,s,{fallbackText:r,requestedWidthPx:m}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:g,widthPx:p,controls:m}=Wb(r);if(!h)return null;const u=Ib(h,s.markdownFilePath,s.rootPath);return u?e.jsx(Gb,{url:u,fallbackText:g,widthPx:p,hasControls:m},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.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(r)?e.jsx(Hb,{html:r},n):null;const f=l[1].toLowerCase(),c=ct(l[2],`${n}-${f}`,!0,s);return f==="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:c},n):f==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):f==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function ct(r,n,s=!0,l){const f=Ob(r),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\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 g=0,p;for(;(p=c.exec(f))!==null;){p.index>g&&h.push(vu(f.slice(g,p.index)));const m=p[0],u=`${n}-${p.index}`,y=m.startsWith("<")?Kb(m,u,l):null;if(y)h.push(y);else if(m.startsWith("\\(")&&m.endsWith("\\)"))h.push(e.jsx(Qs,{tex:m.slice(2,-2)},u));else if(m.startsWith("$")&&m.endsWith("$"))h.push(e.jsx(Qs,{tex:m.slice(1,-1)},u));else if(m.startsWith("`")){const b=m.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:Ub(m.slice(b,-b))},u))}else if(m.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ct(m.slice(2,-2),`${u}-del`,s,l)},u));else if(m.startsWith("**")||m.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ct(m.slice(2,-2),`${u}-strong`,s,l)},u));else if(m.startsWith("*")||m.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:ct(m.slice(1,-1),`${u}-em`,s,l)},u));else if(m.startsWith("![")){const b=m.match(/^!\[([^\]]*)\]\((.*)\)$/),$=m.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),T=m.match(/^!\[([^\]]+)\]$/);if(b){const I=bl(b[2]);h.push(I?qs(u,b[1],I.href,I.title,l):m)}else if($){const I=$[2]||$[1],D=l.referenceDefinitions.get(ho(I));h.push(D?qs(u,$[1],D.href,D.title,l):m)}else if(T){const I=l.referenceDefinitions.get(ho(T[1]));h.push(I?qs(u,T[1],I.href,I.title,l):m)}else h.push(m)}else if(m.startsWith("[^")){const b=Sf(m.slice(2,-1)),$=l.footnoteDefinitions.get(b);h.push($?e.jsx("sup",{id:`fnref-${$.id}`,title:$.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${$.id}`,className:"text-primary no-underline",children:$.index})},u):m)}else if(m.startsWith("<http")){const b=m.slice(1,-1);h.push(e.jsx("a",{href:b,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u))}else if(m.startsWith("<")&&m.endsWith(">")&&xu(m.slice(1,-1))){const b=m.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${b}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u))}else if(xu(Wi(m).linkText)){const{linkText:b,suffix:$}=Wi(m);h.push(e.jsx("a",{href:`mailto:${b}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:b},u)),$&&h.push($)}else if(m.startsWith("http")||m.startsWith("www.")){const{linkText:b,suffix:$}=Wi(m),T=b.startsWith("www.")?`https://${b}`:b;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:b},u)),$&&h.push($)}else{const b=m.match(/^\[([^\]]+)\]\((.*)\)$/),$=m.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),T=m.match(/^\[([^\]]+)\]$/),I=$?$[2]||$[1]:T?.[1]??null,D=I?l.referenceDefinitions.get(ho(I)):null,U=b?bl(b[2]):null,C=U?.href??D?.href??null,R=C?vf(C):null,M=b?.[1]??$?.[1]??T?.[1]??"";h.push(R?e.jsx("a",{href:R,title:U?.title??D?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ct(M,`${u}-link`,s,l)},u):m)}g=c.lastIndex}return g<f.length&&h.push(vu(f.slice(g))),h.length>0?h:[r]}function Tf(r){return/(?: {2,}|\\)$/.test(r)}function If(r){return r.replace(/(?: {2,}|\\)$/,"")}function yo(r){return/^(?: {4}|\t)/.test(r)}function Df(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function Ff(r,n,s){const l=[];return r.forEach((f,c)=>{const h=Tf(f);l.push(...ct(If(f),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function xl(r,n,s){const l=[],f=[];return r.forEach((c,h)=>{f.push(Tf(c)),l.push(ct(If(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:f}}function vl(r,n,s,l,f){const c=[];return r.forEach((h,g)=>{const p=s[g]??0,m=!!(f&&p>=f.start&&p<=f.end);c.push(e.jsx("span",{"data-md-ref-start":p,"data-md-ref-end":p,"data-selected":m?"true":void 0,children:h},`${l}-ref-${g}`)),g<r.length-1&&c.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),c}function Zs(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",f=!1,c=0,h=0;for(let g=0;g<n.length;g+=1){const p=n[g];if(f){l+=p,f=!1;continue}if(p==="\\"){f=!0;continue}if(p==="`"){const m=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const u=g-m+1;l+="`".repeat(u),c===0?c=u:c===u&&(c=0);continue}if(c===0&&p==="["?h+=1:c===0&&p==="]"&&h>0&&(h-=1),p==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=p}return f&&(l+="\\"),s.push(l.trim()),s}function _f(r){return Zs(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function wo(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function ko(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function Bf(r,n){return r>96||r>44&&n>.35}function Eo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function ea(r){const n=r.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 Ml(r,n,s,l,f,c=new Set){const h=[],g=[];let p=n;for(;p<r.length;){const m=r[p];if(f&&(vo(m)||c.has(p))){p+=1;continue}const u=ea(m),y=Eo(m);if(!u){if(y>s&&g.length>0){([...g].reverse().find(I=>I.indent<y)?.item??g[g.length-1].item).paragraphs.push(m.trim());for(const I of g)I.item.lineEnd=p+1;p+=1;continue}break}if(y<s||y===s&&u.ordered!==l)break;const b={content:u.content,ordered:u.ordered,start:u.start,children:[],paragraphs:[],lineStart:p+1,lineEnd:p+1};for(;g.length>0&&g[g.length-1].indent>=y;)g.pop();const $=g[g.length-1]?.item??null;$?$.children.push(b):h.push(b),g.push({indent:y,item:b});for(const T of g)T.item.lineEnd=p+1;p+=1}return{items:h,nextIndex:p}}function qb(r){const n=r.find(l=>ea(l));if(!n)return[];const s=ea(n);return s?Ml(r,0,Eo(n),s.ordered,!0,Rf(r)).items:[]}function $l(r,n,s,l=0){return r.map((f,c)=>{const h=f.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:f.lineStart+l,refEnd:f.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,ct(h?.[2]??f.content,`li-${n}-${c}`,!0,s),f.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:f.paragraphs.map((g,p)=>e.jsx("p",{children:ct(g,`li-${n}-${c}-p-${p}`,!0,s)},`paragraph-${p}`))})]}),groups:Vb(f.children,`${n}-${c}`,s,l)}})}function Vb(r,n,s,l=0){const f=[];for(const c of r){const h=f[f.length-1];h&&h.ordered===c.ordered?h.items.push(c):f.push({ordered:c.ordered,items:[c]})}return f.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:$l(c.items,`${n}-g${h}`,s,l)}))}function Ll(r,n){return r.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&&Yb(s.groups,n)]},s.key)})}function Yb(r,n){return r.map((s,l)=>{const f=s.ordered?"ol":"ul";return e.jsx(f,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Ll(s.items,n)},`nested-${l}`)})}function Xb(r){const n=Array.from(r.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:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[ct(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Jb(r,n,s,l){const f=[];let c=0;const h=g=>l?.[g]??g+1;for(;c<r.length;){const g=r[c],p=g.trim();if(!p){c+=1;continue}if(/^<details>\s*$/i.test(p)){const U=c;let C="Details";const R=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const M=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);M?C=M[1].trim()||C:R.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),f.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:ct(C,`${n}-details-${U}-summary`,!0,s)}),R.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Ff(R,`${n}-details-${U}`,s)})]},`${n}-details-${U}`)});continue}const m=Af(g);if(m){const U=[g],C=c;for(c+=1;c<r.length&&!m.selfContained&&!new RegExp(`</${m.tag}>`,"i").test(r[c]);)U.push(r[c]),c+=1;c<r.length&&!m.selfContained&&(U.push(r[c]),c+=1),f.push({kind:"static",node:e.jsx(Pf,{html:U.join(`
|
|
1639
|
+
`)},`${n}-html-${C}`)});continue}const u=p.match(/^(```|~~~)\s*(.*)$/);if(u){const U=[],C=u[1],R=u[2]?.trim(),M=c;for(c+=1;c<r.length&&!r[c].trim().startsWith(C);)U.push(r[c]),c+=1;c<r.length&&(c+=1),R.toLowerCase()==="mermaid"?f.push({kind:"static",node:e.jsx(Uf,{code:U.join(`
|
|
1640
|
+
`),blockKey:`${n}-code-${M}`},`${n}-code-${M}`)}):["math","latex","tex"].includes(R.toLowerCase())?f.push({kind:"static",node:e.jsx(Qs,{tex:U.join(`
|
|
1641
|
+
`),display:!0},`${n}-code-${M}`)}):f.push({kind:"code",key:`${n}-code-${M}`,code:U.join(`
|
|
1642
|
+
`),lang:R,blockKey:`${n}-code-${M}`,codeStartLine:h(M)+1});continue}if(yo(g)){const U=[],C=c;for(;c<r.length&&(yo(r[c])||!r[c].trim());)U.push(r[c].trim()?Df(r[c]):""),c+=1;f.push({kind:"code",key:`${n}-indented-code-${C}`,code:U.join(`
|
|
1643
|
+
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${C}`,codeStartLine:h(C)});continue}const y=p.match(/^(#{1,6})\s+(.+)$/);if(y){const C=`h${Math.min(6,y[1].length+1)}`,R=kf(y[2]),M=pl(R,s);f.push({kind:"static",node:e.jsx(C,{id:M,className:"scroll-mt-16 font-semibold text-foreground",children:ct(R,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<r.length&&g.includes("|")&&ko(r[c+1])){const U=Zs(g),C=_f(r[c+1]),R=[],M=c;for(c+=2;c<r.length&&r[c].includes("|")&&r[c].trim();)R.push(Zs(r[c])),c+=1;f.push({kind:"static",node:e.jsx("div",{className:ff,"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:U.map((H,F)=>e.jsx("th",{className:`${df} ${wo(C[F]??null)}`,children:e.jsx("div",{className:xo,children:ct(H,`${n}-th-${M}-${F}`,!0,s)})},`h-${F}`))})}),e.jsx("tbody",{children:R.map((H,F)=>e.jsx("tr",{className:"border-t border-border/10",children:U.map((S,o)=>e.jsx("td",{className:`${uf} ${wo(C[o]??null)}`,children:e.jsx("div",{className:xo,children:ct(H[o]??"",`${n}-td-${M}-${F}-${o}`,!0,s)})},`c-${o}`))},`r-${F}`))})]})},`${n}-table-${M}`)});continue}const b=ea(g);if(b){const U=b.ordered,C=Eo(g),R=b.start,M=c,H=Ml(r,c,C,U,!1);c=H.nextIndex,f.push({kind:"list",keyPrefix:`${n}-list-${M}`,ordered:U,start:U?R:void 0,renders:$l(H.items,`${n}-list-${M}`,s,h(0)-1)});continue}const $=[g.trimStart()],T=[h(c)],I=c;for(c+=1;c<r.length&&r[c].trim()&&!ml(r[c])&&!(c+1<r.length&&r[c].includes("|")&&ko(r[c+1]));)$.push(r[c].trimStart()),T.push(h(c)),c+=1;const D=xl($,`${n}-p-${I}`,s);f.push({kind:"paragraph",keyPrefix:`${n}-p-${I}`,perLine:D.perLine,hardBreaks:D.hardBreaks,lineNums:T})}return f}function Qb(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:vl(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:Ll(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(So,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let so=null,wu=!1;const ao=16,Of=192;function Zb(){return so||(so=Xs(()=>import("./mermaid.core-CxZFe3as.js").then(r=>r.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(r=>r.default??r).catch(r=>{throw so=null,r})),so}function ex(r){wu||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),wu=!0)}function tx(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,f,c]=l;if(!Number.isFinite(f)||!Number.isFinite(c)||f<=0||c<=0)return r;const h=Math.max(Of,Math.ceil(f)),g=Math.ceil(h/f*c);return r.replace(/<svg\b([^>]*)>/i,(p,m)=>`<svg${m.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${g}">`)}function rx(r){const n=r?.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-ao,f=s.y-ao,c=s.width+ao*2,h=s.height+ao*2,g=Math.max(Of,Math.ceil(c)),p=Math.ceil(g/c*h);n.setAttribute("viewBox",`${l} ${f} ${c} ${h}`),n.setAttribute("width",String(g)),n.setAttribute("height",String(p)),n.removeAttribute("style")}function nx(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return Uu(`code.${s}`)??s}function Uf({code:r,blockKey:n}){const{t:s}=pt(),[l,f]=a.useState(null),[c,h]=a.useState(!1),g=a.useRef(null),p=a.useContext(yf);a.useEffect(()=>{let u=!1;return f(null),h(!1),Zb().then(async y=>{ex(y);const b=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:$}=await y.render(b,r);u||f(tx($))}).catch(()=>{u||h(!0)}),()=>{u=!0}},[n,r]),a.useLayoutEffect(()=>{l&&rx(g.current)},[l]);const m=a.useCallback(()=>{const u=g.current?.querySelector("svg")?.outerHTML??l;u&&p?.(u)},[p,l]);return c?e.jsx(So,{code:r,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(),m()},children:e.jsx("span",{ref:g,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 So({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:f}){const c=nx(n),[h,g]=a.useState(null);a.useEffect(()=>{if(!c||!Hu(r)){g(null);return}let m=!1;return zu().then(u=>{if(m||!u.registered(c)){m||g(null);return}try{g(Wu(u,r,c))}catch{m||g(null)}}).catch(()=>{m||g(null)}),()=>{m=!0}},[s,r,c]);const p=h??(r||" ").split(`
|
|
1644
|
+
`).map(m=>[m||" "]);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:`${Rl} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:p.map((m,u)=>{const y=l!=null?l+u:null,b=!!(f&&y!=null&&y>=f.start&&y<=f.end);return e.jsxs("span",{"data-md-ref-start":y??void 0,"data-md-ref-end":y??void 0,"data-selected":b?"true":void 0,children:[m,u<p.length-1?`
|
|
1645
|
+
`:null]},`${s}-line-${u}`)})})})]})}function Pl(r,n,s,l,f){r=Ab(r);const c=Lb(r),h=Rf(r),g=[],p={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:Pb(r),headingSlugCounts:new Map,images:g,onImageOpen:l,footnotesLabel:f?.footnotes??"Footnotes",backToFootnoteLabel:f?.backToFootnote??(b=>`Back to footnote ${b}`)},m=[];let u=0;for(;u<r.length;){const b=r[u],$=b.trim();if(vo(b)||h.has(u)){u+=1;continue}if(!$){u+=1;continue}if(/^<details>\s*$/i.test($)){const F=u;let S="Details";const o=[];for(u+=1;u<r.length&&!/^<\/details>\s*$/i.test(r[u].trim());){const O=r[u].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?S=O[1].trim()||S:o.push(r[u].trimStart()),u+=1}u<r.length&&(u+=1),m.push({key:`details-${F}`,startLine:F+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:ct(S,`details-${F}-summary`,!0,p)}),o.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Ff(o,`details-${F}`,p)})]})});continue}const T=Af(b);if(T){const F=[b],S=u;for(u+=1;u<r.length&&!T.selfContained&&!new RegExp(`</${T.tag}>`,"i").test(r[u]);)F.push(r[u]),u+=1;u<r.length&&!T.selfContained&&(F.push(r[u]),u+=1),m.push({key:`html-${S}`,startLine:S+1,endLine:u,content:e.jsx(Pf,{html:F.join(`
|
|
1646
|
+
`)})});continue}const I=$.match(/^(```|~~~)\s*(.*)$/);if(I){const F=[],S=I[1],o=I[2]?.trim(),O=u;for(u+=1;u<r.length&&!r[u].trim().startsWith(S);)F.push(r[u]),u+=1;u<r.length&&(u+=1),m.push({key:`code-${O}`,startLine:O+1,endLine:u,fineGrained:o.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(o.toLowerCase()),content:o.toLowerCase()==="mermaid"?e.jsx(Uf,{code:F.join(`
|
|
1647
|
+
`),blockKey:`code-${O}`}):["math","latex","tex"].includes(o.toLowerCase())?e.jsx(Qs,{tex:F.join(`
|
|
1648
|
+
`),display:!0}):P=>e.jsx(So,{code:F.join(`
|
|
1649
|
+
`),lang:o,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:P})});continue}if(yo(b)){const F=[],S=u;for(u+=0;u<r.length&&(yo(r[u])||!r[u].trim());)F.push(r[u].trim()?Df(r[u]):""),u+=1;m.push({key:`indented-code-${S}`,startLine:S+1,endLine:u,fineGrained:!0,content:o=>e.jsx(So,{code:F.join(`
|
|
1650
|
+
`).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${S}`,codeStartLine:S+1,lineRange:o})});continue}if($.startsWith("$$")){const F=[],S=u,o=$.replace(/^\$\$\s*/,"");if(o.endsWith("$$")&&o.length>2)F.push(o.replace(/\s*\$\$$/,"")),u+=1;else{for(o&&F.push(o),u+=1;u<r.length&&!r[u].trim().endsWith("$$");)F.push(r[u]),u+=1;if(u<r.length){const O=r[u].trim().replace(/\s*\$\$$/,"");O&&F.push(O),u+=1}}m.push({key:`math-${S}`,startLine:S+1,endLine:u,content:e.jsx(Qs,{tex:F.join(`
|
|
1651
|
+
`),display:!0})});continue}if(u+1<r.length&&$&&!ml(b)&&/^(=+|-+)\s*$/.test(r[u+1].trim())){const F=r[u+1].trim().startsWith("=")?1:2,S=`h${F}`,o=pl($,p),O={level:F,text:bu($),id:o};m.push({key:`setext-heading-${u}`,startLine:u+1,endLine:u+2,heading:O,content:e.jsx(S,{id:o,className:`scroll-mt-16 font-semibold text-foreground ${F===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:ct($,`setext-heading-${u}`,!0,p)})}),u+=2;continue}const D=$.match(/^(#{1,6})\s+(.+)$/);if(D){const F=D[1].length,S=kf(D[2]),o={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"},O=`h${F}`,P=pl(S,p),V={level:F,text:bu(S),id:P};m.push({key:`heading-${u}`,startLine:u+1,endLine:u+1,heading:V,content:e.jsx(O,{id:P,className:`scroll-mt-16 font-semibold text-foreground ${o[F]}`,children:ct(S,`heading-${u}`,!0,p)})}),u+=1;continue}if(xf(b)){m.push({key:`hr-${u}`,startLine:u+1,endLine:u+1,content:e.jsx("hr",{className:"border-border/20"})}),u+=1;continue}if($.startsWith(">")){const F=[],S=[],o=u;for(;u<r.length&&/^>\s?/.test(r[u].trim());)F.push(r[u].trim().replace(/^>\s?/,"")),S.push(u+1),u+=1;const O=F[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const V=O[1].toUpperCase(),E=O[2]?.trim(),K=[...E?[E]:[],...F.slice(1)],pe=[...E?[S[0]]:[],...S.slice(1)],W=xl(K,`callout-${o}`,p);m.push({key:`callout-${o}`,startLine:o+1,endLine:u,fineGrained:!0,content:ee=>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:V}),K.length>0&&e.jsx("div",{children:vl(W.perLine,W.hardBreaks,pe,`callout-${o}`,ee)})]})});continue}const P=Jb(F,`quote-${o}`,p,S);m.push({key:`quote-${o}`,startLine:o+1,endLine:u,fineGrained:!0,content:V=>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:Qb(P,V)})});continue}if(u+1<r.length&&b.includes("|")&&ko(r[u+1])){const F=Zs(b),S=_f(r[u+1]),o=[],O=u;for(u+=2;u<r.length&&r[u].includes("|")&&r[u].trim();)o.push(Zs(r[u])),u+=1;const P=F.map((E,K)=>ct(E,`th-${O}-${K}`,!0,p)),V=o.map((E,K)=>F.map((pe,W)=>ct(E[W]??"",`td-${O}-${K}-${W}`,!0,p)));m.push({key:`table-${O}`,startLine:O+1,endLine:u,interactive:!1,kind:"table",content:E=>{const K=pe=>!!(E&&pe>=E.start&&pe<=E.end);return e.jsx("div",{className:ff,"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":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":K(O+1)?"true":void 0,children:P.map((pe,W)=>e.jsx("th",{className:`${df} ${wo(S[W]??null)}`,children:e.jsx("div",{className:xo,children:pe})},`h-${W}`))})}),e.jsx("tbody",{children:V.map((pe,W)=>{const ee=O+W+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":ee,"data-md-ref-start":ee,"data-md-ref-end":ee,"data-selected":K(ee)?"true":void 0,children:F.map((A,B)=>e.jsx("td",{className:`${uf} ${wo(S[B]??null)}`,children:e.jsx("div",{className:xo,children:pe[B]})},`c-${B}`))},`r-${W}`)})})]})})}});continue}const U=ea(b);if(U){const F=U.ordered,S=Eo(b),o=U.start,O=u,P=Ml(r,u,S,F,!0,h);u=P.nextIndex;const V=F?"ol":"ul",E=$l(P.items,`list-${O}`,p);m.push({key:`list-${O}`,startLine:O+1,endLine:u,fineGrained:!0,content:K=>e.jsx(V,{start:F?o:void 0,className:`${F?"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:Ll(E,K)})});continue}const C=[b.trimStart()],R=[u+1],M=u;for(u+=1;u<r.length&&r[u].trim()&&!ml(r[u])&&!(u+1<r.length&&r[u].includes("|")&&ko(r[u+1]));){if(vo(r[u])||h.has(u)){u+=1;continue}C.push(r[u].trimStart()),R.push(u+1),u+=1}const H=xl(C,`p-${M}`,p);m.push({key:`p-${M}`,startLine:M+1,endLine:u,fineGrained:!0,content:F=>e.jsx("p",{className:"text-muted-foreground",children:vl(H.perLine,H.hardBreaks,R,`p-${M}`,F)})})}const y=Xb(p);return y&&m.push({key:"footnotes",startLine:r.length,endLine:r.length,content:y}),{blocks:m,images:g}}function sx(r,n,s){return Pl(r,n,s).blocks}function Hf(r,n){const s=[];for(const l of r){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 zf(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function ax({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const f=Ef(r);return e.jsx(th,{src:f,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Wf({images:r,index:n,onChange:s,onClose:l}){const{t:f}=pt(),c=r[n],h=r.length>1,g=a.useRef(null),p=a.useRef(null),m=a.useRef(null),u=a.useRef(0),[y,b]=a.useState(!1),[$,T]=a.useState(0),[I,D]=a.useState(!1),U=a.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),C=a.useCallback(()=>{y||Date.now()<u.current||(U(),m.current=window.setTimeout(()=>{m.current=null,l()},450))},[U,y,l]),R=a.useCallback(S=>{if(r.length===0)return;const o=(S+r.length)%r.length;g.current?.slideTo(o),s(o)},[r.length,s]),M=a.useCallback(()=>R(n-1),[R,n]),H=a.useCallback(()=>R(n+1),[R,n]);if(a.useEffect(()=>{U(),T(0),D(!1),b(!1)},[U,n]),a.useEffect(()=>{const S=g.current;S&&(S.allowTouchMove=h&&!y)},[h,y]),a.useEffect(()=>{const S=g.current;!S||S.activeIndex===n||S.slideTo(n,0)},[n]),a.useEffect(()=>U,[U]),a.useEffect(()=>{const S=o=>{if(o.key==="Escape"){o.preventDefault(),l();return}h&&(o.key==="ArrowLeft"?(o.preventDefault(),M()):o.key==="ArrowRight"&&(o.preventDefault(),H()))};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[h,H,M,l]),Iu({onDrag:({movement:[S,o],pinching:O})=>{O||y||Math.abs(o)<Math.abs(S)*1.15&&$===0||(D(!0),Math.abs(o)>8&&(u.current=Date.now()+300),T(Math.max(0,o)))},onDragEnd:({movement:[S,o],velocity:[,O],pinching:P,canceled:V})=>{if(D(!1),P||V||y||Math.abs(o)<Math.abs(S)*1.15){T(0);return}if(Math.abs(o)>8&&(u.current=Date.now()+300),Bf(o,O)){l();return}T(0)}},{target:p,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const F=c.title||c.alt||(c.kind==="mermaid"?f("rightSidebar.mermaidDiagram"):f("rightSidebar.image"));return typeof document>"u"?null:kr.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:F}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.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:M,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":f("rightSidebar.previousImage"),title:f("common.previous"),children:e.jsx(Vs,{size:17})}),e.jsx("button",{type:"button",onClick:H,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":f("rightSidebar.nextImage"),title:f("common.next"),children:e.jsx(Em,{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":f("rightSidebar.closeImagePreview"),title:f("common.close"),children:e.jsx(Pt,{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,onClick:C,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${$}px, 0) scale(${Math.max(.86,1-$/900)})`,opacity:Math.max(.35,1-$/360),transition:I?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Du,{onSwiper:S=>{g.current=S,S.allowTouchMove=h&&!y},onSlideChange:S=>{S.activeIndex!==n&&s(S.activeIndex)},onSliderMove:()=>{U(),u.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((S,o)=>e.jsx(el,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:S.kind==="image"?e.jsx(ax,{src:S.src,alt:S.alt||S.title||f("rightSidebar.markdownImage"),onZoomChange:b,onDoubleTap:U}):e.jsx(wx,{svg:S.svg,title:S.title||S.alt||f("rightSidebar.mermaidDiagram"),onZoomChange:b,onDoubleTap:U})})},`${S.kind}-${o}-${S.alt}`))})})})]})]}),document.body)}function Gf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:f,onLineRangeDrag:c,scrollTop:h,outlineOpen:g,outlineCloseSignal:p,onOutlineOpen:m,onOutlineClose:u,lightboxOpen:y,lightboxCloseSignal:b,onLightboxOpen:$,onLightboxClose:T,onLocalLinkOpen:I}){const{t:D}=pt(),[U,C]=a.useState(null),[R,M]=a.useState(null),[H,F]=a.useState(1),[S,o]=a.useState(null),O=a.useRef(null),P=a.useRef(null),{blocks:V,images:E}=a.useMemo(()=>Pl(r.split(`
|
|
1652
|
+
`),n,s,N=>{M(null),C(N),$?.()},{footnotes:D("rightSidebar.footnotes"),backToFootnote:N=>D("rightSidebar.backToFootnote",{index:N})}),[r,n,s,$,D]),K=a.useMemo(()=>R?[...E,R]:E,[E,R]),pe=a.useCallback(N=>{M({kind:"mermaid",svg:N,alt:"Mermaid diagram",title:"Mermaid diagram"}),C(E.length),$?.()},[E.length,$]);a.useEffect(()=>{C(null),M(null)},[r,n]),a.useEffect(()=>{C(null),M(null)},[b]),a.useEffect(()=>{y||(C(null),M(null))},[y]),a.useEffect(()=>{F(1)},[r,n]),a.useLayoutEffect(()=>{const N=O.current;if(!N||V.length===0)return;const se=Array.from(N.querySelectorAll("[data-markdown-preview-block-start]"));let fe=1;const Ee=28;for(const Me of se)if(Me.offsetTop-h<=Ee)fe=Number(Me.dataset.markdownPreviewBlockStart)||fe;else break;F(Me=>Me===fe?Me:fe)},[V,h]);const W=a.useMemo(()=>Hf(V,H),[H,V]),ee=a.useMemo(()=>zf(V),[V]),A=`${n??""}
|
|
1653
|
+
${r}`,B=a.useRef(A),J=a.useRef(null),ue=a.useRef(null),me=a.useRef(!1);a.useEffect(()=>{B.current!==A&&(B.current=A,u?.())},[u,A]),a.useEffect(()=>{p!==void 0&&o(null)},[p]),a.useLayoutEffect(()=>{if(!g){o(null);return}const N=()=>{const se=P.current;if(!se)return;const fe=se.getBoundingClientRect(),Ee=window.innerWidth;o({top:fe.bottom+6,right:Math.max(8,Ee-fe.right)})};return N(),window.addEventListener("resize",N),window.addEventListener("scroll",N,!0),()=>{window.removeEventListener("resize",N),window.removeEventListener("scroll",N,!0)}},[g,h,W]);const ye=a.useCallback(N=>{const se=O.current,fe=se?.closest("[data-markdown-preview-scroller]"),Ee=se?.querySelector(`[data-markdown-preview-block-start="${N.startLine}"]`);if(!fe||!Ee)return;const Me=fe.getBoundingClientRect(),Ke=Ee.getBoundingClientRect(),Pe=se?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,dt=Ke.top-Me.top+fe.scrollTop;fe.scrollTo({top:Math.max(0,dt-Pe-8),behavior:"smooth"}),F(N.startLine),u?.()},[u]),je=a.useCallback(N=>{N.pointerType==="mouse"&&N.button!==0||Xi(N.target)||(J.current={pointerId:N.pointerId,startX:N.clientX,startY:N.clientY})},[]),Ne=a.useCallback((N,se,fe)=>{const Ee=J.current;if(J.current=null,!Ee||Ee.pointerId!==N.pointerId)return;const Me=Math.abs(N.clientX-Ee.startX),Ke=Math.abs(N.clientY-Ee.startY);if(Me>8||Ke>8)return;const le=N.target;if(Xi(le)||rl())return;const Pe=Eu(le,se,fe);f(N,Pe.start,Pe.end)},[f]),L=a.useCallback(N=>{J.current?.pointerId===N.pointerId&&(J.current=null)},[]),Q=a.useCallback((N,se)=>{const fe=O.current;if(!fe||typeof document.elementFromPoint!="function")return null;const Ee=document.elementFromPoint(N,se);if(!(Ee instanceof HTMLElement)||!fe.contains(Ee))return null;const Me=Ee.closest("[data-md-ref-start]");if(Me){const ke=Number(Me.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const Ke=Ee.closest("[data-markdown-preview-block-start]");if(!Ke)return null;const le=Number(Ke.dataset.markdownPreviewBlockStart),Pe=V.find(ke=>ke.startLine===le);if(!Pe)return Number.isFinite(le)&&le>0?le:null;if(Pe.endLine<=Pe.startLine)return Pe.startLine;const dt=Ke.getBoundingClientRect(),Ae=dt.height>0?Math.min(1,Math.max(0,(se-dt.top)/dt.height)):0;return Math.round(Pe.startLine+Ae*(Pe.endLine-Pe.startLine))},[V]),ne=a.useCallback(N=>{if(!c||N.pointerType==="mouse"&&N.button!==0)return;const se=Q(N.clientX+24,N.clientY);if(se!=null){ue.current={pointerId:N.pointerId,anchorLine:se,moved:!1};try{N.currentTarget.setPointerCapture(N.pointerId)}catch{}}},[c,Q]),Le=a.useCallback(N=>{const se=ue.current;if(!se||se.pointerId!==N.pointerId||!c)return;const fe=Q(N.clientX+16,N.clientY);fe!=null&&(!se.moved&&fe===se.anchorLine||(se.moved=!0,me.current=!0,c(N,Math.min(se.anchorLine,fe),Math.max(se.anchorLine,fe),"move")))},[c,Q]),Ye=a.useCallback(N=>{const se=ue.current;if(ue.current=null,!se||se.pointerId!==N.pointerId||!c||!se.moved)return;const fe=Q(N.clientX+16,N.clientY)??se.anchorLine;c(N,Math.min(se.anchorLine,fe),Math.max(se.anchorLine,fe),"end")},[c,Q]),De=a.useCallback(N=>{ue.current?.pointerId===N.pointerId&&(ue.current=null)},[]),rt={onPointerDown:ne,onPointerMove:Le,onPointerUp:Ye,onPointerCancel:De},_e=()=>me.current?(me.current=!1,!0):!1;return V.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:D("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:N=>{const se=N.target instanceof Element?N.target.closest("a[href]"):null;if(!se||!I)return;const fe=se.getAttribute("href");if(!fe)return;const Ee=Nl(fe,n,s);Ee&&(N.preventDefault(),I(Ee))},children:[W.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:W.map(N=>N.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:W[W.length-1].text}),ee.length>1&&e.jsxs("button",{ref:P,type:"button",onClick:()=>{g?u?.():m?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${g?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":g,"aria-label":D("rightSidebar.markdownOutline"),title:D("rightSidebar.markdownOutline"),children:[e.jsx(Fu,{size:12}),e.jsx("span",{children:D("rightSidebar.markdownOutlineShort")})]})]})}),g&&typeof document<"u"&&kr.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:S?{top:`${S.top}px`,right:`${S.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:ee.map(N=>{const se=W[W.length-1]?.startLine===N.startLine;return e.jsxs("button",{type:"button",onClick:()=>ye(N),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] ${se?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(N.level-1,4)*12+8}px`},title:N.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${se?"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",N.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:N.text})]},`desktop-${N.id}-${N.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:D("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":D("rightSidebar.closeMarkdownOutline"),title:D("common.close"),children:e.jsx(Pt,{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:ee.map(N=>{const se=W[W.length-1]?.startLine===N.startLine;return e.jsxs("button",{type:"button",onClick:()=>ye(N),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] ${se?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(N.level-1,4)*12+8}px`},title:N.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${se?"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",N.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:N.text})]},`${N.id}-${N.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(yf.Provider,{value:pe,children:V.map(N=>{const se=!!(l&&N.startLine<=l.end&&N.endLine>=l.start),fe=!!(l&&l.start<=N.startLine&&l.end>=N.endLine),Ee=N.kind==="table"?!1:N.fineGrained?fe:se,Me=N.kind==="table"&&l?.start===N.startLine&&l.end===N.endLine;let Ke=null;if(N.kind!=="table"&&N.fineGrained&&se&&!fe&&l){const Ae=N.endLine-N.startLine+1,ke=Math.max(l.start,N.startLine),ut=Math.min(l.end,N.endLine),Qe=(ke-N.startLine)/Ae,re=(ut-ke+1)/Ae;Ke=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) * ${Qe})`,height:`calc((100% - 0.5rem) * ${re})`}})}const le=typeof N.content=="function"?N.content(l):N.content,Pe=N.startLine===N.endLine?String(N.startLine):`${N.startLine}-${N.endLine}`,dt=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:qi(Ee),"aria-hidden":"true",...rt,children:[e.jsx("span",{className:Vi(Ee)}),Ke]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:le})]});return N.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":N.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 ${Ee?"bg-primary/10":""}`,title:`Line ${Pe}`,"aria-label":`Line ${Pe}`,children:[N.kind==="table"?e.jsx("button",{type:"button",className:qi(Me,"self"),onClick:Ae=>{Ae.preventDefault(),!_e()&&f(Ae,N.startLine,N.endLine)},title:`Reference table lines ${Pe}`,"aria-label":`Reference table lines ${Pe}`,...rt,children:e.jsx("span",{className:Vi(Me,"self")})}):e.jsxs("span",{className:qi(Ee,"none"),"aria-hidden":"true",...rt,children:[e.jsx("span",{className:Vi(Ee,"none")}),Ke]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:je,onPointerUp:Ae=>Ne(Ae,N.startLine,N.endLine),onPointerCancel:L,onKeyDown:Ae=>{Ae.key!=="Enter"&&Ae.key!==" "||(Ae.preventDefault(),f(Ae,N.startLine,N.endLine))},title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:le})]},N.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":N.startLine,onClick:Ae=>{const ke=Ae.target;if(Xi(ke)||rl()||_e())return;const ut=Eu(ke,N.startLine,N.endLine);f(Ae,ut.start,ut.end)},onKeyDown:Ae=>{Ae.key!=="Enter"&&Ae.key!==" "||(Ae.preventDefault(),f(Ae,N.startLine,N.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 ${Ee?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:dt},N.key)})})})]}),y&&U!==null&&K[U]&&e.jsx(Wf,{images:K,index:U,onChange:C,onClose:()=>{C(null),M(null),T?.()}})]})}function rs({label:r,value:n,options:s,placeholder:l,searchPlaceholder:f,emptyText:c,disabled:h,onChange:g}){const{t:p}=pt(),[m,u]=a.useState(!1),[y,b]=a.useState(""),[$,T]=a.useState(null),I=a.useRef(null),D=a.useRef(null),U=y.trim().toLowerCase(),C=a.useMemo(()=>U?s.filter(S=>`${S.label} ${S.meta??""}`.toLowerCase().includes(U)):s,[U,s]),R=s.find(S=>S.value===n),M=()=>{const S=y.trim();S&&(g(S),u(!1),b(""))},H=a.useCallback(()=>{const S=I.current?.getBoundingClientRect();if(!S)return!1;const o=12,O=Math.max(220,Math.min(S.width,window.innerWidth-o*2)),P=Math.min(Math.max(o,S.left),window.innerWidth-O-o),V=window.innerHeight-S.bottom-o,E=S.top-o,K=V>=180||V>=E,pe=Math.max(96,(K?V:E)-4),W=Math.min(320,pe);return T({left:P,top:K?S.bottom+4:Math.max(o,S.top-W-4),width:O,maxHeight:W}),!0},[]),F=()=>{H(),u(!0)};return a.useEffect(()=>{if(!m)return;let S=0;const o=()=>{S||(S=window.requestAnimationFrame(()=>{S=0,H()}))},O=P=>{const V=P.target;V instanceof Node&&(I.current?.contains(V)||D.current?.contains(V)||(u(!1),b("")))};return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),document.addEventListener("pointerdown",O,!0),()=>{S&&window.cancelAnimationFrame(S),window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0),document.removeEventListener("pointerdown",O,!0)}},[m,H]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:I,type:"button",disabled:h,onClick:()=>{if(!h){if(b(""),m){u(!1);return}F()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:R?.label??(n||l)})]}),e.jsx(Ys,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${m?"rotate-180":""}`})]}),m&&!h&&typeof document<"u"&&kr.createPortal(e.jsxs("div",{ref:D,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:S=>S.stopPropagation(),style:{left:$?.left??12,top:$?.top??12,width:$?.width??260,maxHeight:$?.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(ss,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:y,onChange:S=>b(S.target.value),onKeyDown:S=>{if(S.key==="Escape"){S.preventDefault(),u(!1),b("");return}S.key==="Enter"&&(S.preventDefault(),M())},onBlur:()=>{y.trim()&&C.length===0&&M()},placeholder:f,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,($?.maxHeight??320)-46)},children:[y.trim()&&!s.some(S=>S.value===y.trim())&&e.jsxs("button",{type:"button",onMouseDown:S=>S.preventDefault(),onClick:M,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:y.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:p("common.use")})]}),C.length>0?C.map(S=>e.jsxs("button",{type:"button",onClick:()=>{g(S.value),u(!1),b("")},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 ${S.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:S.label}),S.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:S.meta})]},S.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function ku({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:f,selectedRoots:c,onToggleRepo:h,onGenerate:g,onSecondaryAction:p,disabled:m,generateDisabled:u,secondaryDisabled:y,inserted:b,buttonLabel:$,insertedLabel:T,title:I,ariaLabel:D,scopeTitle:U,scopeLabel:C,allLabel:R,generateLabel:M,secondaryLabel:H,secondaryTitle:F,secondaryLoading:S,loading:o,error:O,statusTitle:P,extraContent:V,renderRepoExtra:E,menuItem:K=!1}){return e.jsxs("div",{className:K?"relative w-full":"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",role:K?"menuitem":void 0,tabIndex:K?-1:void 0,onClick:()=>{s?n(!r):u||g()},disabled:m,className:`relative flex items-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-50 ${K?"min-h-10 w-full gap-2.5 px-2.5 text-left text-[12px] focus:bg-surface-2 focus:outline-none [@media(pointer:coarse)]:min-h-11":"h-7 shrink-0 justify-center gap-1 px-2 text-[11px] font-medium active:scale-95"} ${O?"text-destructive hover:bg-destructive/5":b?"bg-surface-elevated text-foreground":K?"text-foreground hover:bg-surface-2":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":D,title:P??(s?`${U}: ${C}`:I),children:[o?e.jsx(ht,{size:K?15:13,className:"shrink-0 animate-spin"}):e.jsx(Js,{size:K?15:13,className:K?"shrink-0 text-muted-foreground":void 0}),e.jsx("span",{className:K?"min-w-0 flex-1":void 0,children:b?T:$}),s&&(K?e.jsx(ns,{size:13,className:"shrink-0 text-muted-foreground"}):e.jsx(Ys,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`})),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&kr.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:pe=>pe.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:U}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:C})]}),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(Pt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[V,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:R}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),f.map(pe=>{const W=c.includes(pe.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${W?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(pe.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${W?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:pe.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:pe.label}),pe.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:pe.branch})]}),W&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),E&&(l||W)&&e.jsx("div",{className:"px-2 pb-2",children:E(pe)})]},pe.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${p&&H?"sm:grid-cols-2":""}`,children:[p&&H&&e.jsxs("button",{type:"button",onClick:()=>{y||(n(!1),p())},disabled:y,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:F,children:[S?e.jsx(ht,{size:12,className:"animate-spin"}):e.jsx(Ku,{size:12}),H]}),e.jsxs("button",{type:"button",onClick:()=>{u||(n(!1),g())},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:I,children:[e.jsx(Js,{size:12}),M]})]})]})}),document.body)]})}function ox(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){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 Kf(){return mt(Sl,ox)??{}}function ix(r,n){const s=Kf(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,f],[,c])=>c.updatedAt-f.updatedAt).slice(0,rb);Ws(Sl,Object.fromEntries(l),sb)}function lx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;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 cx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){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&&!lx(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Al(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function qf(){return mt(jl,cx)??{}}function Su(r,n){const s=Al(r,n);return s?qf()[s]??null:null}function Gi(r,n,s){const l=Al(r,n);if(!l)return;const f=qf(),c=f[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...f,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,g],[,p])=>p.updatedAt-g.updatedAt).slice(0,nb);Ws(jl,Object.fromEntries(h),ab)}function Ki({slow:r}){return e.jsx(hp,{slow:r})}function oo({message:r,onRetry:n}){const{t:s}=pt();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:r}),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 mo(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function kt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function io(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function dx(r,n,s){return nl(r,n,s)}function qi(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function Vi(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function Vf(r){const n=new Map;for(const s of r)n.set(Tl(s),s);return n}function Yf(r,n){const s=new Map(r);for(const l of n)s.set(Tl(l),l);return s}function ju(r,n){let s=0;for(const l of r){const f=bt(l,n);f&&n&&f!==n&&(s+=1)}return s}function ux(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function fx(r,n){return Array.from(Yf(Vf(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function hx(r,n){const s=r.relativeRoot==="."?kt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||kt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:ux(r.files)}}function Xf(r,n){const s=kt(n??"")||n||"";return r.map(l=>hx(l,n)).sort((l,f)=>s&&l.label===s?-1:s&&f.label===s?1:l.label.localeCompare(f.label))}function Jf(r,n,s,l,f){const c=mf(s),h=c.find(I=>I.root===l)??c[0]??null,g=n.find(I=>I.root===l)??null,p=g?.relativeRoot??h?.relativeRoot??".",m=g?.name??h?.name??(kt(l)||l),u=(h?.files??s.files).map(I=>({...I,repoRoot:l,repoRelativeRoot:p,repoName:m})),y=h?.context??s.context,b={...g??h??{id:l,root:l,relativeRoot:p,name:m,depth:0,nested:!!(f&&l!==f),available:s.available,files:[],context:null},...h??{},id:g?.id??h?.id??l,root:l,displayRoot:g?.displayRoot??h?.displayRoot,relativeRoot:p,name:m,depth:g?.depth??h?.depth??0,nested:g?.nested??h?.nested??!!(f&&l!==f),available:h?.available??s.available,deferred:h?.deferred??!1,files:u,context:y?{...y,root:l,changedFiles:u.map(I=>({path:I.path,absolutePath:I.absolutePath,status:I.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},$=g?n.map(I=>I.root===l?b:I):[...n,b];return{files:Array.from(r).filter(I=>bt(I,f)!==l).concat(u),repositories:$,repoFilters:Xf($,f)}}function bt(r,n){return r.repoRoot??n}function Tl(r){return`${r.repoRoot??""}\0${r.path}`}function yr(r){return r.absolutePath||r.path}function Yi(r){return Tl(r)}function mx(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function Ru(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Nu(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)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 Bs(r){let n=0;const s=r??"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 Os(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function wr(r){return r instanceof DOMException&&r.name==="AbortError"}function px(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Cu(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function Xi(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Eu(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,f=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(f)&&f>0&&Number.isFinite(c)&&c>0?{start:Math.min(f,c),end:Math.max(f,c)}:{start:n,end:s}}function gx({actions:r,running:n,completed:s}){const{t:l}=pt(),[f,c]=a.useState(!1),h=a.useRef(null),g=r.find(m=>n?.action===m.key),p=r.find(m=>s?.action===m.key);return r.length===0?null:(a.useEffect(()=>{if(!f)return;const m=y=>{const b=y.target;b instanceof Node&&h.current?.contains(b)||c(!1)},u=y=>{y.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",m),document.addEventListener("keydown",u),()=>{document.removeEventListener("pointerdown",m),document.removeEventListener("keydown",u)}},[f]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),c(u=>!u)},disabled:r.every(m=>m.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${f?"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:g?.label??p?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(ht,{size:13,className:"animate-spin"}):p?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(po,{size:14})}),f&&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:r.map(m=>{const u=n?.action===m.key,y=s?.action===m.key;return e.jsxs("button",{type:"button",onClick:b=>{b.stopPropagation(),m.onClick(),c(!1)},disabled:m.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 ${y?"bg-accent/10 text-accent":m.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(ht,{size:13,className:"animate-spin"}):y?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.label})]},m.key)})})]}))}function bx(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function Qf(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&bx(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function as(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const Ji=new WeakMap;function jo(r){const n=Ji.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),Ji.delete(r)},1700);Ji.set(r,s)}function xx(r){const n=CSS.escape(r),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 f=null;for(const g of l){if(!as(g))continue;const p=g.querySelector(s);if(p&&as(p)){f=p;break}}if(f??=Array.from(document.querySelectorAll(s)).find(as)??null,!f)return;const c=Qf(f);if(!c){f.scrollIntoView({block:"start",behavior:"smooth"}),jo(f);return}const h=f.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),jo(f)}function En(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,f=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&f?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${f}"]`:null,s!==null&&f?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${f}"]`: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&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(T=>!!T),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let p=null;for(const T of g)if(as(T)){for(const I of h){const D=T.querySelector(I);if(D&&as(D)){p=D;break}}if(p)break}if(p??=h.flatMap(T=>Array.from(document.querySelectorAll(T))).find(as)??null,!p){xx(r.filePath);return}const m=Qf(p);if(!m){p.scrollIntoView({block:"center",behavior:"smooth"}),jo(p);return}const u=p.getBoundingClientRect(),y=m.getBoundingClientRect(),$=u.top-y.top+m.scrollTop-Math.max(24,(m.clientHeight-u.height)/2);m.scrollTo({top:Math.max(0,$),behavior:"instant"}),jo(p)}const Zf=1,Il=8;function vx(r,n=Il){return Math.min(n,Math.max(Zf,r))}function eh({resetKey:r,maxScale:n=Il,onZoomChange:s,onDoubleTap:l,children:f}){const c=a.useRef(null),[h,g]=a.useState({scale:1,x:0,y:0}),[p,m]=a.useState(!1),u=a.useRef(null),y=a.useRef(new Set),b=a.useRef(!1),$=a.useRef(null),T=a.useRef(0),I=a.useRef(h);I.current=h,a.useEffect(()=>{g({scale:1,x:0,y:0})},[r]);const D=a.useCallback((M,H,F)=>{const S=c.current;if(!S)return{x:H,y:F};const o=S.firstElementChild instanceof HTMLElement?S.firstElementChild:null,O=o?.clientWidth||S.clientWidth,P=o?.clientHeight||S.clientHeight,V=Math.max(0,(O*M-S.clientWidth)/2),E=Math.max(0,(P*M-S.clientHeight)/2);return{x:Math.min(V,Math.max(-V,H)),y:Math.min(E,Math.max(-E,F))}},[]),U=a.useCallback((M,H,F)=>{g(S=>{const o=vx(M,n),O=c.current;if(!O||o===1)return{scale:o,x:0,y:0};const P=O.getBoundingClientRect(),V=(H??P.left+P.width/2)-P.left-P.width/2,E=(F??P.top+P.height/2)-P.top-P.height/2,K=o/S.scale,pe=V-(V-S.x)*K,W=E-(E-S.y)*K;return{scale:o,...D(o,pe,W)}})},[D,n]),C=a.useCallback((M,H)=>{m(!0),I.current.scale>1?g({scale:1,x:0,y:0}):U(2.5,M,H),window.setTimeout(()=>m(!1),220)},[U]);a.useEffect(()=>{const M=c.current;if(!M)return;const H=o=>{if(o.pointerType==="mouse"&&o.button!==0)return;const O=y.current.size===0;if(y.current.add(o.pointerId),O){const P=Date.now(),V=$.current;if(V&&P-V.time<350&&Math.hypot(o.clientX-V.x,o.clientY-V.y)<24){$.current=null,T.current=P,l?.(),C(o.clientX,o.clientY);return}}if(y.current.size>1){b.current=!0,u.current=null;return}if(!(I.current.scale<=1)){o.preventDefault(),u.current={pointerId:o.pointerId,startX:o.clientX,startY:o.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{M.setPointerCapture?.(o.pointerId)}catch{}m(!1)}},F=o=>{const O=u.current;if(!O||O.pointerId!==o.pointerId)return;const P=o.clientX-O.startX,V=o.clientY-O.startY;if(!O.moved){if(Math.hypot(P,V)<6)return;O.moved=!0}o.stopPropagation(),o.preventDefault(),g(E=>({...E,...D(E.scale,O.originX+P,O.originY+V)}))},S=o=>{const O=u.current,P=O?.pointerId===o.pointerId&&O.moved;if(O?.pointerId===o.pointerId){O.moved&&o.stopPropagation(),u.current=null;try{M.releasePointerCapture?.(o.pointerId)}catch{}}y.current.delete(o.pointerId)&&y.current.size===0&&(!b.current&&!P&&($.current={time:Date.now(),x:o.clientX,y:o.clientY}),b.current=!1)};return M.addEventListener("pointerdown",H,{capture:!0,passive:!1}),window.addEventListener("pointermove",F,{capture:!0,passive:!1}),window.addEventListener("pointerup",S,{capture:!0}),window.addEventListener("pointercancel",S,{capture:!0}),()=>{M.removeEventListener("pointerdown",H,{capture:!0}),window.removeEventListener("pointermove",F,{capture:!0}),window.removeEventListener("pointerup",S,{capture:!0}),window.removeEventListener("pointercancel",S,{capture:!0})}},[D,l,C]),Iu({onPinch:({offset:[M],origin:[H,F]})=>{m(!1),U(M,H,F)},onWheel:({event:M,delta:[H,F],ctrlKey:S})=>{if(S){M.preventDefault(),M.stopPropagation(),m(!1),U(I.current.scale*(1-F*.01),M.clientX,M.clientY);return}I.current.scale<=1||(M.preventDefault(),M.stopPropagation(),m(!1),g(o=>({...o,...D(o.scale,o.x-H,o.y-F)})))}},{target:c,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Zf,max:n},from:()=>[I.current.scale,0],rubberband:!0}});const R=h.scale>1;return a.useEffect(()=>{s?.(R)},[s,R]),e.jsx("div",{ref:c,"data-sidebar-gesture-ignore":R?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden","data-image-zoom-viewport":!0,style:{cursor:R?"grab":"zoom-in"},onDoubleClick:M=>{M.stopPropagation(),!(Date.now()-T.current<500)&&(l?.(),C(M.clientX,M.clientY))},children:f({scale:h.scale,zoomed:R,animateTransform:p,transformStyle:{transform:`translate3d(${h.x}px, ${h.y}px, 0) scale(${h.scale})`,transformOrigin:"center center",transition:p?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${h.x}px, ${h.y}px, 0)`,transformOrigin:"center center",transition:p?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function th({src:r,alt:n,vector:s,onLoad:l,onError:f,onZoomChange:c,onDoubleTap:h}){const g=Ro(r,f),[p,m]=a.useState(null),u=s??Co(r);return a.useEffect(()=>{m(null)},[r]),e.jsx(eh,{resetKey:r,maxScale:Math.max(Il,p?.originalScale??1),onZoomChange:c,onDoubleTap:h,children:({vectorTransformStyle:y,scale:b,animateTransform:$})=>e.jsx("div",{"data-image-zoom-surface":!0,"data-vector-zoom-surface":u?"":void 0,className:"relative shrink-0 touch-none select-none",style:p?{...y,width:p.width,height:p.height}:{width:"100%",height:"100%"},children:e.jsx("img",{src:g,alt:n,draggable:!1,className:"touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:{position:"absolute",left:"50%",top:"50%",width:p?p.width*b:void 0,height:p?p.height*b:void 0,maxWidth:p?"none":"100%",maxHeight:p?"none":"100%",transform:"translate(-50%, -50%)",transition:$?"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"},onLoad:T=>{const I=T.currentTarget,D=I.closest("[data-image-zoom-viewport]");if(D&&I.naturalWidth>0&&I.naturalHeight>0){const U=Math.max(1,D.clientWidth-2),C=Math.max(1,D.clientHeight-2),R=Math.min(U/I.naturalWidth,C/I.naturalHeight),M=u?R:Math.min(R,1);m({width:I.naturalWidth*M,height:I.naturalHeight*M,originalScale:1/M})}l(T)},onError:f})})})}function yx({svg:r,title:n,scale:s,vectorTransformStyle:l}){const f=a.useRef(null);return a.useLayoutEffect(()=>{const c=f.current,h=c?.querySelector("svg");if(!c||!h)return;const g=()=>{const u=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let y=u[2],b=u[3];if((!Number.isFinite(y)||!Number.isFinite(b)||y<=0||b<=0)&&(y=Number(h.getAttribute("width")),b=Number(h.getAttribute("height"))),!Number.isFinite(y)||!Number.isFinite(b)||y<=0||b<=0)return;const $=Math.max(1,c.clientWidth-24),T=Math.max(1,c.clientHeight-24),I=Math.min($/y,T/b,1);h.style.width=`${Math.max(1,Math.floor(y*I*s))}px`,h.style.height=`${Math.max(1,Math.floor(b*I*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")};g();const p=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return p?.observe(c),()=>p?.disconnect()},[s,r,l]),e.jsx("div",{ref:f,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:r}})}function wx({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(eh,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:f,scale:c})=>e.jsx(yx,{svg:r,title:n,scale:c,vectorTransformStyle:f})})}let kx=0,Sx=0,jx=0,Rx=0,Nx=0;function Qi(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function it(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++Sx,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Us(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++Rx,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Cx(){return`diff-ui-${Date.now().toString(36)}-${(++Nx).toString(36)}`}function Ex(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function Mx(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function yl({onReviewReference:r,filePath:n,active:s=!0,onInsertReference:l,onInsertText:f,onInsertFeature:c,onReferenceCopied:h,onClose:g,onDirectoryLinkOpen:p,isMobile:m,markdownOutlineOpen:u,markdownOutlineCloseSignal:y,onOpenMarkdownOutline:b,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:U,lineRange:C,onLineRangeChange:R,insertedReferenceKey:M,copiedReferenceKey:H,scrollToLine:F,onScrollToLineHandled:S}){const{t:o}=pt(),O=a.useRef(null);a.useEffect(()=>{s||O.current?.querySelectorAll("video").forEach(_=>_.pause())},[s]);const P=Y(_=>_.rootPath),V=Y(_=>_.selectFile),[E,K]=a.useState({kind:"idle"}),[pe,W]=a.useState("schematic"),[ee,A]=a.useState(null),B=a.useRef(null),[J,ue]=a.useState(null),me=a.useRef(new Map),ye=a.useRef(null),[je,Ne]=a.useState(null),[L,Q]=a.useState(()=>uu()),[ne,Le]=a.useState(()=>Qd(P,n)),Ye=a.useRef(null),[De,rt]=a.useState(!1),[_e,N]=a.useState(null),[se,fe]=a.useState(0),[Ee,Me]=a.useState([]),[Ke,le]=a.useState(null),Pe=a.useRef(null),dt=a.useRef(n),[Ae,ke]=a.useState(null),[ut,Qe]=a.useState({status:"idle"}),[re,Te]=a.useState(!1),[et,Ot]=a.useState(""),[lt,z]=a.useState([]),[ae,ve]=a.useState(0),Xe=a.useRef(null),Ct=Gu(h),ir=Al(P,n);a.useEffect(()=>{if(dt.current===n)return;dt.current=n;const _=n&&P&&!n.startsWith("/")?`${P}/${n}`:n;if(Pe.current===_){Pe.current=null;return}Pe.current=null,Me([]),le(null),Te(!1),Ot("")},[n,P]);const At=n?P&&!n.startsWith("/")?`${P}/${n}`:n:null,Tt=Y(_=>At?(_.fileChangeVersions.get(At)??0)+_.fileWatchEpoch:_.fileWatchEpoch),Sr=a.useRef(null),Xt=a.useRef(null),[Mn,ta]=a.useState(0),os=a.useCallback(()=>ta(_=>_+1),[]);a.useEffect(()=>{const _=B.current;return B.current=null,A(null),_&&URL.revokeObjectURL(_.objectUrl),()=>{const G=B.current;B.current=null,G&&URL.revokeObjectURL(G.objectUrl)}},[At,Tt,Mn]),a.useEffect(()=>{if(!n){Sr.current=null,K({kind:"idle"});return}const _=P&&!n.startsWith("/")?`${P}/${n}`:n,G=new AbortController,de=++kx,we=`right-sidebar-file-preview:${de}`,Ze=performance.now();let Fe=!1;const Oe=(Z,He={})=>{Fe||(Fe=!0,Qi("end",{loadingId:de,reason:Z,durationMs:Math.round(performance.now()-Ze),filePath:n,fullPath:_,rootPath:P,...He}))};let Ue=null;const gt=gm(_),xt=gt?_.toLowerCase().endsWith(".kicad_pcb")?pe==="schematic"?"pcb-front":pe:"schematic":pe,sn=!gt&&wl(_),tr=!gt&&!sn&&bm(_),zr=!gt&&!sn&&!tr&&Lu(_),ms=_s(_),ps=Is(_),hr=gt?"eda":sn?"image":tr?"model3d":zr?"video":"text",an=Sr.current!==_;if(Sr.current=_,an){Qi("start",{loadingId:de,filePath:n,fullPath:_,rootPath:P,mode:hr,externalVersion:Tt}),Qe({status:"idle"}),K({kind:"loading",mode:hr}),Xt.current=null;const Z=Su(P,n);R(Z?.lineRange??null),Q(ms?uu():"source"),Le(ps?Qd(P,n):"source"),gt&&W(xm(_))}an||K(Z=>Z.kind==="error"?{kind:"loading",mode:hr}:Z);const on=window.setTimeout(()=>{Fe||G.signal.aborted||Qi("still_active",{loadingId:de,filePath:n,fullPath:_,rootPath:P,mode:hr,durationMs:Math.round(performance.now()-Ze),isPathChange:an})},3e3),Mo=window.setTimeout(()=>{if(Fe||G.signal.aborted)return;const Z=gt?o("rightSidebar.edaTimeout"):tr?o("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";G.abort(new DOMException(Z,"TimeoutError")),K({kind:"error",message:Z}),Oe("stuck_timeout",{error:Z})},gt?vm+5e3:tr?ym+5e3:wm(_)?35e3:fb);if(gt){const Z=xt==="pcb-3d"?B.current:null;Z?(K(Z),Oe("eda_3d_client_cache_hit",{bytes:Z.meta.size,view:Z.view,mimeType:Z.meta.mimeType})):km(_,xt,G.signal,"view_file",we).then(He=>{if(G.signal.aborted)return;Ue=URL.createObjectURL(He.blob);const Ut={kind:"eda",sourcePath:He.path||_,objectUrl:Ue,view:He.view,meta:{size:He.size,mimeType:He.mimeType,modified:He.modified}};if(He.view==="pcb-3d"){const Er=B.current;Er&&Er.objectUrl!==Ue&&URL.revokeObjectURL(Er.objectUrl),B.current=Ut,A(Ut),Ue=null}K(Ut),Oe("eda_loaded",{bytes:He.size,view:He.view,mimeType:He.mimeType})}).catch(He=>{G.signal.aborted||(K({kind:"error",message:He instanceof Error&&/timed out/i.test(He.message)?o("rightSidebar.edaTimeout"):He instanceof Error?He.message:o("rightSidebar.edaLoadFailed")}),Oe("error",{error:He instanceof Error?He.message:String(He)}))})}else if(sn)Sm(_,G.signal,"view_file",we).then(Z=>{Ue=URL.createObjectURL(Z.blob),K({kind:"image",objectUrl:Ue,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Oe("image_loaded",{bytes:Z.size,mimeType:Z.mimeType})}).catch(Z=>{G.signal.aborted||(K({kind:"error",message:Z instanceof Error?Z.message:o("rightSidebar.imageLoadFailed")}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(tr)jm(_,G.signal,"view_file",we).then(Z=>{G.signal.aborted||(Ue=URL.createObjectURL(Z.blob),K({kind:"model3d",sourcePath:Z.path||_,objectUrl:Ue,ext:Z.ext,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Oe("model3d_loaded",{bytes:Z.size,ext:Z.ext}))}).catch(Z=>{G.signal.aborted||(K({kind:"error",message:Z instanceof Error&&(Z.name==="TimeoutError"||/timed out/i.test(Z.message))?o("rightSidebar.model3dTimeout"):Z instanceof Error?Z.message:o("rightSidebar.model3dLoadFailed")}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(zr){const Z=Rm(_)??"",He=Pu(_);K(Ut=>Ut.kind==="video"&&Ut.url===He?Ut:{kind:"video",url:He,meta:{size:null,mimeType:Z,modified:null}}),Oe("video_ready",{mimeType:Z})}else Ed(_,G.signal,"view_file",we).then(Z=>{if(!G.signal.aborted){if(Z.binary){K({kind:"binary"});return}K({kind:"text",content:Z.content,sourcePath:Z.path||_,meta:{size:Z.size,truncated:Z.truncated}}),Oe("text_loaded",{bytes:Z.size,truncated:!!Z.truncated})}}).catch(Z=>{G.signal.aborted||(K({kind:"error",message:Z instanceof Error?Z.message:"Failed to read file"}),Oe("error",{error:Z instanceof Error?Z.message:String(Z)}))});return()=>{G.abort(),Nt(we),window.clearTimeout(on),window.clearTimeout(Mo),Ue&&URL.revokeObjectURL(Ue),Oe("cleanup")}},[n,P,Tt,Mn,R,o,pe]),a.useEffect(()=>{if(E.kind!=="model3d"||!n){ue(null);return}let _=!1;const G=n.lastIndexOf("/"),de=G>=0?n.slice(G+1):n,we=G>=0?n.slice(0,G):"",Ze=we.lastIndexOf("/"),Fe=Ze>=0?we.slice(0,Ze):"",Oe=de.replace(/\.(stl|glb|gltf)$/i,""),Ue=`${Fe?`${Fe}/`:""}features/${Oe}.json`;return Ed(Ue).then(gt=>{if(!_)try{const xt=JSON.parse(gt.content);ue(xt.version===1&&Array.isArray(xt.features)&&xt.features.length>0?xt.features:null)}catch{ue(null)}}).catch(()=>{_||ue(null)}),()=>{_=!0}},[E,n]),a.useEffect(()=>{if(E.kind!=="text"){ke(null);return}const _=P&&n&&!n.startsWith("/")?`${P}/${n}`:n,G=Uu(_),de=E.content,we=_s(_??"")&&L==="preview",Ze=Is(_??"")&&ne==="preview";if(!G||we||Ze||!Hu(de)){ke(null);return}let Fe=!1;const Oe=Ue=>{if(Fe||!Ue.registered(G)){Fe||ke(null);return}try{ke(Wu(Ue,de,G))}catch{ke(null)}};return _e?Oe(_e):(ke(null),zu().then(Ue=>{Fe||(N(Ue),Oe(Ue))}).catch(()=>{})),()=>{Fe=!0}},[E,_e,n,P,L,ne]),a.useLayoutEffect(()=>{if(!ir||E.kind!=="text")return;const _=`${ir}:${L}:${ne}`;if(Xt.current===_)return;const G=Su(P,n);if(Xt.current=_,!G)return;const de=requestAnimationFrame(()=>{const we=ye.current;if(!we)return;const Ze=L==="preview"?G.markdownTop??G.top:G.top;we.scrollTo({top:Math.max(0,Ze??0),left:Math.max(0,G.left??0)}),fe(L==="preview"?Math.max(0,Ze??0):0)});return()=>cancelAnimationFrame(de)},[n,L,ne,E.kind,ir,P]),a.useEffect(()=>{ir&&Gi(P,n,{lineRange:C})},[n,C,ir,P]),a.useEffect(()=>{if(F==null||E.kind!=="text")return;Ne(null),R({start:F,end:F});const _=F,G=requestAnimationFrame(()=>{const de=me.current.get(_);de&&de.scrollIntoView({block:"center"}),S?.()});return()=>cancelAnimationFrame(G)},[F,E,R,S]);const _r=a.useCallback(_=>{const G=ye.current;if(!G)return!1;const de=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(_):_.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),we=G.querySelector(`#${de}`);return we?(we.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const _=P&&n&&!n.startsWith("/")?`${P}/${n}`:n,G=E.kind==="text"&&_s(_??"")&&L==="preview";if(!Ke||!G)return;const de=requestAnimationFrame(()=>{_r(Ke)&&le(null)});return()=>cancelAnimationFrame(de)},[n,_r,L,Ke,E,P]),a.useLayoutEffect(()=>{const _=ye.current;if(!_||!C){Ne(null);return}if(je)return;const G=E.kind==="image"||E.kind==="loading"&&E.mode==="image",de=P&&n&&!n.startsWith("/")?`${P}/${n}`:n,we=E.kind==="text"&&_s(de??"")&&L==="preview",Ze=E.kind==="text"&&Is(de??"")&&ne==="preview";if(E.kind!=="text"||G||we||Ze){Ne(null);return}const Fe=()=>{const Ue=me.current.get(C.end);if(!Ue||!_){Ne(null);return}const gt=Ue.offsetTop+Ue.offsetHeight/2,xt=_.scrollLeft+Math.max(8,_.clientWidth-120);Ne({top:gt,left:xt})};Fe();const Oe=new ResizeObserver(()=>Fe());return Oe.observe(_),()=>Oe.disconnect()},[C,je,E,L,ne,n,P,Ae]);const jr=E.kind==="text"&&!(Is(At??"")&&ne==="preview")&&!At?.toLowerCase().endsWith(".csv")&&!At?.toLowerCase().endsWith(".kicad_pro")&&!At?.toLowerCase().endsWith(".kicad_prl"),St=a.useCallback(()=>{Te(!1),Ot(""),z([]),ve(0),to()},[]),$n=a.useCallback(()=>{jr&&(Te(!0),requestAnimationFrame(()=>{Xe.current?.focus(),Xe.current?.select()}))},[jr]),Jt=a.useCallback(_=>{ve(G=>lt.length===0?0:(G+_+lt.length)%lt.length)},[lt.length]);if(a.useEffect(()=>{const _=G=>{const de=Vg(G);if(de==="open"&&jr){G.preventDefault(),$n();return}re&&(de==="close"?(G.preventDefault(),St()):(de==="next"||de==="previous")&&(G.preventDefault(),Jt(de==="previous"?-1:1)))};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[St,re,Jt,$n,jr]),a.useLayoutEffect(()=>{if(to(),!re||!et.trim()||!ye.current){z([]),ve(0);return}const _=Xg(ye.current,et);return z(_),ve(0),ru(_,0),nu(_[0]),to},[re,et,Ae,L,E]),a.useEffect(()=>{re&&(ru(lt,ae),nu(lt[ae]))},[ae,lt,re]),a.useEffect(()=>to,[]),!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:o("rightSidebar.selectFilePrompt")});const We=P&&!n.startsWith("/")?`${P}/${n}`:n,lr=mo(We,P),Br=Tu(We,P),Or=E.kind==="text"&&E.content?E.content.split(`
|
|
1654
|
+
`):[],Ur=Math.max(2,String(Or.length).length)+1,Rr=E.kind==="text"||E.kind==="image"||E.kind==="model3d"||E.kind==="video"||E.kind==="eda"?E.meta:null,It=_s(We),ra=We.toLowerCase().endsWith(".csv"),Nr=We.toLowerCase().endsWith(".kicad_pro"),is=We.toLowerCase().endsWith(".kicad_prl"),cr=E.kind==="text"&&It&&L==="preview",ls=Is(We),Cr=E.kind==="text"&&ls&&ne==="preview",jt=E.kind==="image"||E.kind==="loading"&&E.mode==="image",Xr=E.kind==="model3d"||E.kind==="loading"&&E.mode==="model3d",cs=E.kind==="video"||E.kind==="loading"&&E.mode==="video",ds=E.kind==="eda"||E.kind==="loading"&&E.mode==="eda",us=E.kind==="text"?E.sourcePath:We,Hr=Qm(us,P,C),Jr=(()=>{if(!C||E.kind!=="text"||Or.length===0)return Hr;const _=[];for(let we=C.start;we<=C.end;we+=1)_.push(`${we} ${Or[we-1]??""}`);const G=bf(We).replace(/^\./,""),de="```";return`${Hr}
|
|
1655
|
+
${de}${G}
|
|
1656
|
+
${_.join(`
|
|
1661
1657
|
`)}
|
|
1662
1658
|
${de}
|
|
1663
|
-
`})(),Qt=`path:${We}`,Zt=C?`path:${We}:${C.start}-${C.end}`:Qt,Ln=T===Qt,us=T===Zt,Qr=U===Qt,dr=U===Zt,Zr=us||dr,en=C?C.start===C.end?`L${C.start}`:`L${C.start}-${C.end}`:null,tn=I=>{const K=we.current;if(!K)return;const de=K.getBoundingClientRect(),ye=I.currentTarget.getBoundingClientRect(),Ze=I.clientX||ye.left+ye.width/2,Oe=(I.clientY||ye.top+ye.height/2)-de.top+K.scrollTop,Ue=m?116:132,mt=K.scrollLeft+Math.max(8,K.clientWidth-Ue),xt=Math.min(Math.max(8,Ze-de.left+K.scrollLeft+10),mt);Ce({top:Oe,left:xt})},ur=(I,K)=>{tl()||(tn(I),E(de=>{const ye=rl(de,K,K);return ye||Ce(null),ye}))},fr=(I,K,de)=>{tn(I),E(ye=>{const Ze=rl(ye,K,de);return Ze||Ce(null),Ze})},xe=(I,K,de,ye)=>{ye==="end"&&tn(I),E({start:K,end:de})},er=I=>{const{scrollTop:K,scrollLeft:de}=I.currentTarget;he(K),Gi(H,n,{top:K,left:de,markdownTop:K})},rn=I=>{if(I.directory){p?.(I.path);return}if(I.path===We||N.kind==="text"&&I.path===N.sourcePath){I.fragment&&_r(I.fragment);return}Me(K=>[...K,We]),Ae.current=I.path,le(I.fragment),E(null),W(I.path)},An=()=>{const I=Ee[Ee.length-1];I&&(Me(K=>K.slice(0,-1)),Ae.current=I,le(null),E(null),W(I))},fs=I=>{const{scrollTop:K,scrollLeft:de}=I.currentTarget;Gi(H,n,{top:K,left:de})},nn=()=>{if(r){r(Jr,Zt);return}C&&f(Jr,Zt)},It=async()=>{if(!(!We||ut.status==="pending")&&!(N.kind==="loading"||N.kind==="error")){Qe({status:"pending"});try{await Fm(We),Qe({status:"idle"})}catch(I){Qe({status:"error",message:I instanceof Error?I.message:o("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{ref:O,className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Nt.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${m&&(cr||Nr)?"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:[m&&g&&e.jsx("button",{type:"button",onClick:g,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":o("rightSidebar.backToFileList"),title:o("rightSidebar.backToFileList"),children:e.jsx(Tu,{size:16})}),Ee.length>0&&e.jsxs("button",{type:"button",onClick:An,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 ${m?"w-9":"px-2.5"}`,"aria-label":o("rightSidebar.backToPreviousPreview"),title:o("rightSidebar.backToPreviousPreview"),children:[e.jsx(Vs,{size:15}),!m&&e.jsx("span",{className:"text-[11px] font-medium",children:o("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:We,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:lr.name}),lr.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:lr.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[jr&&e.jsx("button",{type:"button",onClick:re?St:$n,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":o("rightSidebar.findInFile"),title:`${o("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(ns,{size:14})}),Tt&&N.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{u&&M?.(),Q(I=>{const K=I==="preview"?"source":"preview";return Lt(Zu,K),K}),E(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 ${m?"w-9 px-0":"px-3"}`,"aria-label":o($==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:o($==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:m?$==="preview"?e.jsx(sl,{size:14}):e.jsx(nl,{size:14}):o($==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),is&&N.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Le(I=>{const K=I==="preview"?"source":"preview";return fg(H,n,K),K}),E(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 ${m?"w-9 px-0":"px-3"}`,"aria-label":o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:m?ne==="preview"?e.jsx(sl,{size:14}):e.jsx(nl,{size:14}):o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Nr&&e.jsx("button",{type:"button",onClick:()=>{Ye.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":o(De?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:o(De?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(Iu,{size:15})}),!m&&e.jsx("button",{type:"button",onClick:()=>l(We,Qt),...Nt(Br,Qt),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Ln||Qr?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:o("rightSidebar.insertReference",{reference:Br}),children:o(Qr?"rightSidebar.copied":Ln?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Br)},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:o("rightSidebar.copyReference",{reference:Br}),"aria-label":o("rightSidebar.copyFileRef"),children:e.jsx(jm,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{It()},disabled:ut.status==="pending"||N.kind==="loading"||N.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:ut.status==="error"?ut.message??o("rightSidebar.downloadFailed"):o("rightSidebar.downloadFile"),"aria-label":o("rightSidebar.downloadFile"),children:ut.status==="pending"?e.jsx(gt,{size:13,className:"animate-spin"}):e.jsx(Jm,{size:14})})]})]}),re&&jr&&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(ns,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:Xe,type:"search",value:et,onChange:I=>Ot(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),Jt(I.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:o("rightSidebar.findInFilePlaceholder"),"aria-label":o("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:lt.length>0?`${ae+1}/${lt.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Jt(-1),disabled:lt.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":o("rightSidebar.previousSearchMatch"),title:`${o("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Lu,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Jt(1),disabled:lt.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":o("rightSidebar.nextSearchMatch"),title:`${o("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Qm,{size:13})}),e.jsx("button",{type:"button",onClick:St,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":o("rightSidebar.closeFileSearch"),title:`${o("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Bt,{size:13})})]}),Rr&&!(m&&(cr||Nr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[Rr.size!==null&&e.jsx("span",{children:o("rightSidebar.byteCount",{count:Rr.size.toLocaleString()})}),"truncated"in Rr&&Rr.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:o("rightSidebar.previewTruncated")}),"mimeType"in Rr&&e.jsx("span",{children:Rr.mimeType}),"dimensions"in N&&N.dimensions&&e.jsxs("span",{children:[N.dimensions.width," × ",N.dimensions.height]})]}),!(m&&(cr||Nr))&&!Xr&&N.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:cs?o("rightSidebar.edaPickHint"):ra?o("rightSidebar.csvTablePreview"):Cr||os?o("rightSidebar.kicadProjectPickHint"):ls?o("rightSidebar.videoPreviewHint"):jt?o("rightSidebar.imagePreviewHint"):cr?C?o("rightSidebar.selectedLineHint",{lineLabel:en??""}):o("rightSidebar.markdownPreviewHint"):Nr?o("rightSidebar.htmlPreviewHint"):C?o("rightSidebar.selectedLineHint",{lineLabel:en??""}):o("rightSidebar.multiLineHint")})})]}),!s&&(N.kind==="video"||N.kind==="model3d"||N.kind==="eda"||Nr)?null:N.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8",children:e.jsx($i,{label:N.mode==="eda"?o("rightSidebar.edaLoading"):N.mode==="image"?o("rightSidebar.loadingImage"):N.mode==="model3d"?o("rightSidebar.model3dLoading"):N.mode==="video"?o("rightSidebar.loadingVideo"):o("common.loading")})}):N.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:N.message}),e.jsx("button",{type:"button",onClick:as,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:o("common.retry")})]}):N.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:o("rightSidebar.binaryPreviewHint")})}):N.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:N.meta.mimeType==="image/svg+xml"?e.jsx(Vu,{blobUrl:N.objectUrl,filePath:We,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(Zf,{src:N.objectUrl,alt:lr.name,vector:!1,onLoad:I=>{const K=I.currentTarget;q(de=>de.kind==="image"?{...de,dimensions:{width:K.naturalWidth,height:K.naturalHeight}}:de)},onError:()=>q({kind:"error",message:o("rightSidebar.imageLoadFailed")})})}):N.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(jg,{url:N.url,onLoadError:()=>q({kind:"error",message:o("rightSidebar.videoLoadFailed")})})}):N.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Lg,{blobUrl:N.objectUrl,filePath:N.sourcePath,view:N.view,board:We.toLowerCase().endsWith(".kicad_pcb"),onViewChange:G,onInsertAnnotation:r??c,onRefresh:as,interactive3d:ee?e.jsx(a.Suspense,{fallback:e.jsx($i,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(iu,{blobUrl:ee.objectUrl,ext:".glb",fileName:lr.name,filePath:ee.sourcePath,features:null,onInsertFeature:r??c,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:I=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(I)?I:"PCB板体/铜箔/丝印",active:N.view==="pcb-3d"})}):void 0})}):N.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx($i,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(iu,{blobUrl:N.objectUrl,ext:N.ext,fileName:lr.name,filePath:N.sourcePath,features:J,onInsertFeature:r??c,onRefresh:as})})}):N.kind==="text"&&ra?e.jsx(Tg,{content:N.content,filePath:We,onInsertAnnotation:r??c},We):N.kind==="text"&&(Cr||os)?e.jsx(Fg,{content:N.content,filePath:We,localState:os,onInsertAnnotation:r??c},We):cr?e.jsxs("div",{ref:we,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:er,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Hf,{content:N.content,filePath:N.sourcePath,rootPath:H,lineRange:C,onLineRangeClick:fr,onLineRangeDrag:xe,scrollTop:se,outlineOpen:u,outlineCloseSignal:k,onOutlineOpen:b,onOutlineClose:M,lightboxOpen:A,lightboxCloseSignal:F,onLightboxOpen:B,onLightboxClose:D,onLocalLinkOpen:rn}),C&&je&&e.jsxs("button",{type:"button",onClick:nn,...Nt(Jr,Zt),style:{top:je.top,left:je.left,transform:"translateY(-50%)"},className:Wd(m,Zr),title:`Insert markdown reference: ${Hr}`,children:[e.jsx(bo,{size:m?13:11}),dr?o("rightSidebar.copied"):us?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:en??""})]})]}):Nr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Gg,{ref:Ye,src:Rm(We),title:`${lr.name} preview`,exitFullscreenLabel:o("rightSidebar.htmlFullscreenExit"),onFullscreenChange:rt},`${We}:${Pt}:${Mn}`)}):N.kind==="text"?e.jsxs("div",{ref:we,onScroll:fs,className:`${Sl} 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:[Or.length>0?e.jsx("div",{className:"min-w-full",children:Or.map((I,K)=>{const de=K+1,ye=!!(C&&de>=C.start&&de<=C.end),Ze=Pe&&Pe.length===Or.length?Pe[K]:null;return e.jsxs("div",{ref:Fe=>{Fe?pe.current.set(de,Fe):pe.current.delete(de)},role:"button","data-file-preview-line":de,tabIndex:0,onClick:Fe=>ur(Fe,de),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ur(Fe,de))},style:{gridTemplateColumns:`${Ur}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${ye?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${Br}:${de}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${ye?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:de}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ze??(I||" ")})]},K)})}):"Empty file.",C&&je&&e.jsxs("button",{type:"button",onClick:nn,...Nt(Jr,Zt),style:{top:je.top,left:je.left,transform:"translateY(-50%)"},className:Wd(m,Zr),title:`Insert code reference: ${Hr}`,children:[e.jsx(bo,{size:m?13:11}),dr?o("rightSidebar.copied"):us?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:en??""})]})]}):null]})}function Ex({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:f,push:c,pinned:h=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:p=!1,rightSidebarFilePreviewCloseSignal:m,onOpenRightSidebarFilePreview:u,onCloseRightSidebarFilePreview:k,rightSidebarRepoPickerOpen:b=!1,rightSidebarRepoPickerCloseSignal:M,onOpenRightSidebarRepoPicker:A,onCloseRightSidebarRepoPicker:F,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:D,onOpenMarkdownOutline:C,onCloseMarkdownOutline:E,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:L,onCloseMarkdownImageLightbox:w}){const{t:o,locale:O}=bt(),[H,W]=a.useState(""),[N,q]=a.useState(null),fe=Y(t=>t.rightSearchOpen),G=Y(t=>t.setRightSearchOpen),ee=Y(t=>t.rightSidebarLayoutPreference),P=Y(t=>t.setRightSidebarLayoutPreference),[_,J]=a.useState(()=>yb()),[ue,pe]=a.useState("."),[we,je]=a.useState(""),[Ce,$]=a.useState(!1),[Q,ne]=a.useState(!1),[Le,Ye]=a.useState(!1),[De,rt]=a.useState(!1),_e=a.useDeferredValue(H),[R,se]=a.useState(null),[he,Ee]=a.useState([]),[Me,Ke]=a.useState([]),le=Y(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Ae=Y(t=>t.setActiveGitRepo),[dt,Pe]=a.useState(null),[ke,ut]=a.useState(null),[Qe,re]=a.useState(null),[Te,et]=a.useState(()=>ht(ru,zs)??!1),[Ot,lt]=a.useState(()=>ht(nu,zs)??!1),[z,ae]=a.useState(()=>ht(su,zs)??!1),[ve,Xe]=a.useState(()=>ht(Oi,gb)??""),[Nt,ir]=a.useState(0),[At,Pt]=a.useState(!1),[Sr,Xt]=a.useState(!1),Mn=a.useRef(null),ta=a.useRef(null),[as,_r]=a.useState(!1),[jr,St]=a.useState(null),[$n,Jt]=a.useState(null),[We,lr]=a.useState(()=>cu(_i)),[Br,Or]=a.useState(()=>cu(tu)),[Ur,Rr]=a.useState(()=>pb()),[Tt,ra]=a.useState(()=>bb()),[Cr,os]=a.useState(()=>vb()),cr="words",[is,Nr]=a.useState(0),[jt,Xr]=a.useState([]),[ls,cs]=a.useState([]),[ds,Hr]=a.useState(!1),[Jr,Qt]=a.useState(null),[Zt,Ln]=a.useState([]),[us,Qr]=a.useState(!1),[dr,Zr]=a.useState([]),[en,tn]=a.useState([]),[ur,fr]=a.useState(!1),[xe,er]=a.useState(null),[rn,An]=a.useState([]),[fs,nn]=a.useState({}),It=a.useRef(0),[I,K]=a.useState(0),[de,ye]=a.useState(!1),[Ze,Fe]=a.useState(null),[Oe,Ue]=a.useState(null),[mt,xt]=a.useState(null),[sn,tr]=a.useState(null),[zr,hs]=a.useState(!1),[ms,hr]=a.useState(""),an=a.useDeferredValue(ms),[on,Mo]=a.useState({}),[Z,He]=a.useState([]),[Ut,Er]=a.useState(!1),[na,ps]=a.useState(!1),[$o,Pn]=a.useState(null),[Lo,Tn]=a.useState(!1),mr=a.useRef(null),Wr=a.useRef(0),Pl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[eh,sa]=a.useState(null),[gs,Tl]=a.useState(()=>ht(Bi,zs)??!1),[Ao,Po]=a.useState(!1),[aa,To]=a.useState([]),[rr,oa]=a.useState({}),[Et,ia]=a.useState({}),[ln,Io]=a.useState({}),[Il,Dl]=a.useState(()=>new Set),[qe,cn]=a.useState(null),[Do,dn]=a.useState(null),[th,Mr]=a.useState(!1),[Fl,$r]=a.useState(0),[,Fo]=a.useState(0),[_o,la]=a.useState(!1),[rh,nh]=a.useState(()=>Y.getState().rightTab==="files"),[nr,Bo]=a.useState(!1),[sh,_l]=a.useState(()=>Y.getState().rightTab==="diff"),[Oo,Bl]=a.useState(()=>Y.getState().rightTab==="android"),[Gr,Ol]=a.useState(!1),ca=Li(t=>t.docks[Pi]),ah=!!ca,[ze,bs]=a.useState(null),[In,xs]=a.useState(null),[vt,un]=a.useState(null),[Ul,wt]=a.useState(null),[Dn,Hl]=a.useState(null),[Uo,oh]=a.useState(()=>Date.now()),[ih,lh]=a.useState(!1),[fn,da]=a.useState(!1),[ua,zl]=a.useState(""),[Fn,fa]=a.useState(""),[hn,ha]=a.useState(""),[mn,ma]=a.useState(""),[Wl,_n]=a.useState(null),[pa,ga]=a.useState(!1),[Gl,Ho]=a.useState(!1),[Kl,ql]=a.useState(!1),[ba,ch]=a.useState({key:null,nonce:0}),Vl=a.useRef(null),Yl=a.useRef(null),oe=_m(s,h,ee),zo=df(oe,h,Cr),[Wo,Go]=a.useState(()=>Eb(s)),Ko=Y(t=>t.rightTab),Lr=Y(t=>t.setRightTab),x=Y(t=>t.rootPath),Bn=Y(t=>t.explorerRoot),Xl=Y(t=>t.pinnedExplorerRootsCache),Jl=Y(t=>t.hydratePinnedExplorerRoots),Ql=Y(t=>t.syncPinnedExplorerRoots),Ht=Y(t=>t.setExplorerRoot),Zl=Y(t=>t.resetExplorerToProject),On=Y(t=>t.pinExplorerRoot),pn=Y(t=>t.unpinExplorerRoot),nt=Y(t=>t.selectedFilePath),st=Y(t=>t.selectFile),qo=Y(t=>t.showHiddenFiles),dh=Y(t=>t.toggleShowHiddenFiles),Vo=Y(t=>!!(x&&t.nestedGitScanRoots[x])),Ie=Y(t=>t.changedFiles),xa=Y(t=>t.setChangedFiles),Un=Y(t=>t.invalidateDirectoryCache),uh=Y(t=>t.setDirectorySortMode),ec=Y(t=>t.applyFileWatchEvents),tc=Y(t=>t.reconcileDirectoryCache),rc=Y(t=>t.bumpFileWatchEpoch),pr=Y(t=>t.gitBundleLoading),nc=Y(t=>t.gitBundleSlow),gn=Y(t=>t.gitBundleError),Hn=Y(t=>t.gitBundleLastLoadedAt),sc=Y(t=>t.beginGitBundleLoading),ac=Y(t=>t.setGitBundleSlowFor),Yo=Y(t=>t.finishGitBundleLoading),va=Y(t=>t.resetGitBundleLoading),Xo=Y(t=>t.setGitBundleError),oc=Y(t=>t.markGitBundleLoaded),ce=Bn??x,wa=Y(t=>!!(ce&&t.hideGitIgnoredRoots[ce])),fh=Y(t=>t.hideGitIgnoredRootsHydrated),hh=Y(t=>t.setHideGitIgnoredRoot),[Jo,ic]=a.useState(!1),[lc,Qo]=a.useState(null);a.useEffect(()=>{Qo(null)},[ce]);const cc=a.useMemo(()=>ce?Xg(ce,ue):"",[ce,ue]),vs=a.useMemo(()=>Yg(we),[we]),dc=a.useMemo(()=>({excludePatterns:vs,caseSensitive:Q,wholeWord:Le,regex:De}),[Q,vs,De,Le]),ya=Y(t=>ce?t.fileSortModes[ce]??"name":"name"),uc=Y(t=>!!(ce&&t.directoryCache.has(ce))),zn=a.useRef(null),Rt=a.useRef(0),[fc]=a.useState(()=>++kx),Ar=a.useRef(null),Kr=a.useRef(null),ka=a.useRef(0),zt=a.useRef(new Map),Wt=a.useRef(new Map),gr=a.useRef(new Set),bn=a.useRef(new Set),xn=a.useRef(0),qr=a.useRef(null),Wn=a.useRef(0),Gn=a.useRef(null),Kn=a.useRef(0),Vr=a.useRef(null),Zo=a.useRef(new Set),ei=a.useRef(null),ti=a.useRef(null),Sa=a.useRef(null),ri=a.useRef(null),ni=a.useRef(null),ws=a.useRef(new Set);a.useEffect(()=>{if(Dn===null)return;const t=Math.max(0,Date.now()-Dn),i=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,d=Math.max(50,i-t%i),y=window.setTimeout(()=>oh(Date.now()),d);return()=>window.clearTimeout(y)},[Uo,Dn]);const ja=a.useRef(null),Pr=a.useRef(null),si=a.useRef(null),hc=a.useRef(null),ys=a.useRef(null),Re=a.useCallback(t=>Y.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=i=>{const d=Cx(i.target);d&&Os("global_change_row_event",{...Nx(i),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:Y.getState().selectedFilePath,rightTab:Y.getState().rightTab,activeGitRepoRoot:le,changedFiles:Y.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[le,r]);const mc=a.useCallback(async(t=x??void 0)=>{if(!t)return null;if(gr.current.has(t)||bn.current.has(t))return it("untracked_skip_cached",{cwd:t,rootPath:x,completed:gr.current.has(t),running:bn.current.has(t)}),null;const i=x,d=ka.current+1;ka.current=d,zt.current.set(t,d);const y=`right-sidebar-git-untracked:${t}`,v=new AbortController;Wt.current.set(t,v),bn.current.add(t),it("untracked_start",{requestId:d,cwd:t,rootPath:x});try{let S=await Cd(t,v.signal,y),j=0;for(;S.status==="running"&&j<120;){if(zt.current.get(t)!==d||v.signal.aborted)return it("untracked_stale_result",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,status:S.status}),null;if(!Re(i))return it("untracked_root_changed",{requestId:d,cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath}),null;await new Promise(te=>window.setTimeout(te,j<10?1e3:3e3)),j+=1,S=await Cd(t,v.signal,y)}if(zt.current.get(t)!==d||!Re(i))return it("untracked_stale_result",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath,files:S.files.length,status:S.status}),null;if(S.status==="done")return xa(Kf(Y.getState().changedFiles,S.files)),S.files.length>0&&Ee(te=>{const Ne=new Map(te.map(ge=>[ge.root,ge])).get(t);if(!Ne)return te;const Ve=dx(Ne.files,S.files),X=te.map(ge=>ge.root===t?{...ge,files:Ve,context:ge.context?{...ge.context,changedFiles:Ve.map($e=>({path:$e.path,absolutePath:$e.absolutePath,status:$e.status})),truncated:!1}:ge.context,untrackedDeferred:!1}:ge);Ke(qf(X,x));const V=X.find(ge=>ge.root===x);return V?.context&&se(ge=>ge?.root===V.root?{...ge,...V.context}:ge),X}),gr.current.add(t),it("untracked_apply",{requestId:d,cwd:t,files:S.files.length}),S;const ie=S.error||(S.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return gr.current.add(t),it("untracked_error",{requestId:d,cwd:t,message:ie,code:S.code,status:S.status}),null}catch(S){if(zt.current.get(t)!==d||!Re(i)||yr(S))return it("untracked_aborted",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath,message:S instanceof Error?S.message:String(S)}),null;const j=S instanceof Error?S.message:"Failed to scan untracked files";return gr.current.add(t),it("untracked_error",{requestId:d,cwd:t,message:j}),null}finally{Wt.current.get(t)===v&&Wt.current.delete(t),zt.current.get(t)===d&&zt.current.delete(t),bn.current.delete(t)}},[R,Re,x,xa]),sr=a.useMemo(()=>{const t=new Set(Me.map(d=>d.root)),i=Zt.filter(d=>t.has(d));return i.length>0?i:le?[le]:[]},[le,Zt,Me]),pc=sr.length===0,vn=a.useMemo(()=>sr.map(t=>he.find(i=>i.root===t)).filter(t=>!!t),[sr,he]),mh=a.useMemo(()=>Me.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[Me]),br=a.useCallback(async()=>{if(!x){Xr([]),cs([]);return}const t=x,i=Wn.current+1;Wn.current=i,Gn.current?.abort();const d=new AbortController;Gn.current=d,Hr(jt.length===0),Qt(null);try{const y=sr.length>0?await Promise.all(sr.map(v=>Nd({workspaceRoot:x,repoRoot:v},d.signal))).then(v=>({records:v.flatMap(S=>S.records),walkthroughs:v.flatMap(S=>S.walkthroughs??[])})):await Nd({workspaceRoot:x},d.signal);if(Wn.current!==i||!Re(t))return;Xr(y.records),cs(y.walkthroughs??[])}catch(y){if(Wn.current!==i||!Re(t)||yr(y))return;Qt(y instanceof Error?y.message:"Failed to load change audit explanations")}finally{Gn.current===d&&(Gn.current=null),Wn.current===i&&Re(t)&&Hr(!1)}},[jt.length,sr,Re,x]),Ra=a.useCallback(async(t,i,d)=>{if(!t&&!x){Zr([]),tn([]);return}const y=x,v=Kn.current+1;Kn.current=v,Vr.current?.abort();const S=new AbortController;Vr.current=S;try{const j=t?[t]:Array.from(new Set([x,...he.map(te=>te.root)].filter(te=>!!te))),ie=await Promise.all(j.map(te=>Nm({repoRoot:te,baseRef:i,branchName:d},S.signal))).then(te=>{const be=new Map,Ne=new Map;for(const Ve of te){for(const X of Ve.records)be.set(X.id,X);for(const X of Ve.walkthroughs??[])Ne.set(X.id,X)}return{records:Array.from(be.values()),walkthroughs:Array.from(Ne.values())}});if(Kn.current!==v||!Re(y))return;Zr(ie.records),tn(ie.walkthroughs??[])}catch(j){if(Kn.current!==v||!Re(y)||yr(j))return;console.warn("[RightSidebar] Failed to load branch explanations",j)}finally{Vr.current===S&&(Vr.current=null)}},[he,Re,x]),qn=a.useCallback((t,i={})=>{if(!Re(x)){it("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:Y.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}it(t.files.length===0?"empty_bundle":"apply",{rootPath:x,available:t.available,files:t.files.length,repositories:t.repositories?.map(V=>({root:V.root,relativeRoot:V.relativeRoot,files:V.files.length,available:V.available,error:V.error})),repoFilters:t.repoFilters?.map(V=>({root:V.root,label:V.label,count:V.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let d=uf(t),y=t.repoFilters??[],v=t.files;const S=Y.getState().changedFiles;if(!!(i.cacheOnly&&!t.cached&&t.files.length===0&&d.length===0)&&(S.size>0||he.length>0||R)){it("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:S.size,currentRepositories:he.length});return}const ie=d.some(V=>V.deferred);if(ie&&!i.replaceWorkspace){const V=new Set(d.filter($e=>!$e.deferred||$e.root===x).map($e=>$e.root));v=[...Array.from(S.values()).filter($e=>!V.has(pt($e,x)??"")),...t.files]}const te=yu(S.values(),x),be=yu(t.files,x),Ne=d.some(V=>V.root!==x);if(!!(i.background&&!ie&&!i.replaceWorkspace&&S.size>0&&(t.files.length===0&&!t.error||te>0&&be===0&&!Ne))){it("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:S.size,nextFiles:t.files.length,currentNestedCount:te,nextNestedCount:be,nextRepositories:d.map(V=>({root:V.root,relativeRoot:V.relativeRoot,files:V.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(i.replaceRepoRoot){const V=Vf(S.values(),he,t,i.replaceRepoRoot,x);v=V.files,d=V.repositories,y=V.repoFilters}if(xa(Gf(v)),Ee(V=>{if(!ie||i.replaceWorkspace)return d;const ge=new Map(V.map($e=>[$e.root,$e]));return d.map($e=>{const Ge=ge.get($e.root);return!$e.deferred||!Ge?$e:{...$e,available:Ge.available,files:Ge.files,context:Ge.context,deferred:Ge.deferred,untrackedDeferred:Ge.untrackedDeferred,error:Ge.error}})}),Ke(y),ni.current=x,i.syncActiveRepo!==!1){const{contextKey:V,activeGitRepos:ge}=Y.getState(),$e=V?ge[V]??null:null,Ge=i.activeRepoRoot!==void 0?i.activeRepoRoot:$e,Be=kb({...t,repositories:d,repoFilters:y},Ge);Ae(Be)}typeof t.cacheUpdatedAt=="number"&&Hl(t.cacheUpdatedAt),se(V=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==x)return V;if(!t.context)return null;const ge=V?.root??x;return!V?.available||ge!==(t.context.root??x)?t.context:{...V,...t.context}}),i.reloadDiff&&Nr(V=>V+1);const X=Y.getState().selectedFilePath;if(X&&!X.startsWith("/")&&!v.some(V=>V.path===X||V.absolutePath===X)&&st(null),lr(V=>{const ge=new Set(v.map(Ge=>pt(Ge,x)).filter(Boolean)),$e=new Set;for(const Ge of V)ge.has(Ge)&&$e.add(Ge);return Hi(_i,$e),$e}),i.loadDeferred!==!1){const V=d.filter(ge=>ge.untrackedDeferred&&ge.root).map(ge=>ge.root);for(const ge of V)mc(ge)}i.loadAudit!==!1&&br()},[Re,br,mc,x,st,Ae,xa]);a.useEffect(()=>{va(),ei.current=null,ti.current=x;const t=[],i=[];Rt.current+=1,xn.current+=1,ka.current+=1,Ar.current?.abort(),Ct(_s(Kr.current?.cwd??x??void 0)),Kr.current=null,Ar.current=null,qr.current?.abort(),Ct("right-sidebar-git-details"),qr.current=null;for(const j of Wt.current.values())j.abort();for(const j of Wt.current.keys())Ct(`right-sidebar-git-untracked:${j}`);Wt.current.clear(),zt.current.clear(),Wn.current+=1,Gn.current?.abort(),Gn.current=null,Kn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,Xr([]),cs([]),Hr(!1),Qt(null),Ln([]),Qr(!1),Zr([]),tn([]),fr(!1),er(null),ye(!1),Fe(null),Ue(null),xt(null),tr(null),hs(!1),hr(""),He([]),Er(!1),ps(!1),Pn(null),Tn(!1),sa(null),cn(null),dn(null),Tl(!1),Lt(Bi,!1),Po(!1);const d=x?du()[x]:null,y=d?.previewEntries??[],v=d?.selectedPreviewKey??null,S=v?y.find(j=>j.key===v)??null:null;++It.current,ye(!1),To(d?.selectedRepoRoots??[]),oa(d?.repoTargetBranches??{}),ia(d?.repoBaseBranches??{}),An(y),nn(d?.previewScrollTops??{}),S&&d?.previewDetailOpen&&(S.diff.hunks?.length??0)>0&&(er(S.diff),cn(S.key),dn(d.selectedPreviewFileKey??(S.diff.hunks?.[0]?`${S.diff.hunks[0].filePath}\0${S.diff.hunks[0].hunkHeader}\0${S.diff.hunks[0].hunkIndex}`:null)),fr(!0)),Io(d?.repoIncludeUncommitted??Object.fromEntries(Object.keys(d?.repoTargetBranches??{}).map(j=>[j,d?.includeUncommitted??!0]))),ei.current=x,da(!1),gr.current.clear(),bn.current.clear(),bs(null),xs(null),un(null),wt(null),Hl(null),Ee(t),Ke(i),se(null),ri.current=null,ni.current=null,ws.current.clear()},[va,x]);const Dt=a.useCallback(async(t=x??void 0,i={})=>{if(!t)return null;const d=x,y=Rt.current;if(await Fp(()=>Promise.all([Y.getState().hydrateNestedGitScanRoots(),Y.getState().hydrateActiveGitRepos()]).then(()=>{})),Rt.current!==y||!Re(d))return null;const v=t===x&&Ds(x),S=i.includeNested??v,j=i.refresh??i.reloadDiff??!1,ie=i.cacheOnly??!1,te=i.background??!1,be=S&&(i.discoverOnly??!1);j&&gr.current.clear();const Ne=Kr.current;if(Ne&&Ne.cwd===t&&Ne.includeNested===S&&Ne.refresh===j&&Ne.cacheOnly===ie&&Ne.discoverOnly===be)return it("reuse_pending",{cwd:t,includeNested:S,refresh:j,cacheOnly:ie,discoverOnly:be}),Ne.promise;const Ve=Rt.current+1;Rt.current=Ve;const X=`right-sidebar:${fc}:${Ve}`;Ar.current?.abort();const V=_s(t);Ct(V);const ge=new AbortController;Ar.current=ge;let $e=null;te||sc(X),Xo(null),it("start",{requestId:Ve,cwd:t,rootPath:x,requestSlotId:V,includeNested:S,refresh:j,cacheOnly:ie,background:te,existingChanges:Ie.size,lastLoadedAt:Hn}),!te&&typeof window<"u"&&($e=window.setTimeout(()=>{Rt.current===Ve&&ac(X,!0)},ab));const Ge=(async()=>{const Be=await Ai(t,ge.signal,{includeNested:S,refresh:j,cacheOnly:ie,discoverOnly:be,action:j?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:V,requestTimeoutMs:j?null:void 0});if(hx(Be)){if(it("cancelled_result_ignored",{requestId:Ve,activeRequestId:Rt.current,cwd:t,error:Be.error??Be.context?.error}),ge.signal.aborted)return null;throw new Error(Be.error??Be.context?.error??"Failed to load Git changes")}return Rt.current!==Ve||!Re(d)?(it("stale_result",{requestId:Ve,activeRequestId:Rt.current,cwd:t,expectedRootPath:d,currentRootPath:Y.getState().rootPath,files:Be.files.length,repositories:Be.repositories?.length??0}),null):(qn(Be,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:S,background:te,cacheOnly:ie,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),Be)})();Kr.current={cwd:t,includeNested:S,refresh:j,cacheOnly:ie,discoverOnly:be,promise:Ge};try{const Be=await Ge;return Rt.current===Ve&&Be&&Re(d)?oc({cached:Be.cached,stale:Be.stale,cacheAgeMs:Be.cacheAgeMs,nestedDeferred:!S||Be.nestedDeferred,untrackedDeferred:Be.untrackedDeferred}):Rt.current===Ve&&Re(d)&&Yo(X),Be}catch(Be){return Rt.current!==Ve||!Re(d)||ge.signal.aborted?(it("aborted",{requestId:Ve,activeRequestId:Rt.current,cwd:t,expectedRootPath:d,currentRootPath:Y.getState().rootPath,message:Be instanceof Error?Be.message:String(Be)}),null):(it("error",{requestId:Ve,cwd:t,includeNested:S,refresh:j,background:te,message:Be instanceof Error?Be.message:String(Be)}),te||(se(null),Xo(Be instanceof Error?Be.message:"Failed to load Git changes")),null)}finally{$e!==null&&window.clearTimeout($e),Ar.current===ge&&(Ar.current=null),Kr.current?.promise===Ge&&(Kr.current=null),!te&&Rt.current===Ve&&Re(d)&&Yo(X)}},[qn,sc,Ie.size,Yo,fc,Hn,Re,oc,x,Xo,ac]),Vn=a.useCallback(async()=>{x&&await Dt(x,{reloadDiff:!0,refresh:!0})},[Dt,x]),ai=a.useCallback(async(t=x??void 0)=>{if(!t)return null;const i=x,d=xn.current+1;xn.current=d,qr.current?.abort(),Ct("right-sidebar-git-details");const y=new AbortController;qr.current=y,da(!0);try{const v=await Ed(t,y.signal,"load_git_details","right-sidebar-git-details");return xn.current!==d||!Re(i)?null:(Ee(S=>S.map(j=>j.root===v.root?{...j,available:v.available,context:v,error:v.error}:j)),se(S=>S?.root&&v.root&&S.root!==v.root?S:!S?.available||!v.available?v:{...S,...v}),v)}catch(v){return yr(v)||!Re(i)||xn.current===d&&wt(v instanceof Error?v.message:"Failed to load Git details"),null}finally{qr.current===y&&(qr.current=null),xn.current===d&&Re(i)&&da(!1)}},[Re,x]);a.useEffect(()=>{if(!r){Rt.current+=1,va(),ri.current=null,xn.current+=1,ka.current+=1,Ar.current?.abort(),Ct(_s(Kr.current?.cwd??x??void 0)),Kr.current=null,Ar.current=null,qr.current?.abort(),Ct("right-sidebar-git-details"),qr.current=null;for(const t of Wt.current.values())t.abort();for(const t of Wt.current.keys())Ct(`right-sidebar-git-untracked:${t}`);Wt.current.clear(),zt.current.clear(),Kn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,da(!1),ye(!1),Fe(null),Ue(null),xt(null),tr(null),hs(!1),hr(""),He([]),Er(!1),ps(!1),Pn(null),Tn(!1),W(""),G(!1),St(null),Bo(!1),oe&&_l(!1)}},[oe,r,va,G]),a.useEffect(()=>{if(!fe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[fe]),a.useEffect(()=>{oe||Mr(!1)},[oe]);const gc=a.useCallback(t=>{Fo(t);const i=si.current;i&&(i.update(),i.slideTo(t,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(t,0)}))},[]);a.useEffect(()=>{if(oe)if(Mr(p),p&&nt){$r(1);const t=Pr.current;t&&(t.update(),t.activeIndex!==1&&(ys.current=1,t.slideTo(1,0)))}else{$r(0);const t=Pr.current;t&&t.activeIndex!==0&&(ys.current=0,t.slideTo(0,0)),St(null)}},[oe,p,x,nt]),a.useEffect(()=>{if(m!==void 0&&!p){$r(0);const t=Pr.current;t&&t.activeIndex!==0&&(ys.current=0,t.slideTo(0,0)),Mr(!1),St(null)}},[m,p]),a.useEffect(()=>{M!==void 0&&Pe(null)},[M]),a.useEffect(()=>{!oe&&p&&k?.()},[oe,k,p]),a.useEffect(()=>{Go(t=>fl(t,s))},[s]);const ph=a.useCallback(t=>{oe||(t.preventDefault(),ja.current={startX:t.clientX,startWidth:Wo,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Wo,oe]),gh=a.useCallback(t=>{const i=ja.current;if(!i||i.pointerId!==t.pointerId)return;const d=fl(i.startWidth+t.clientX-i.startX,s);Go(d),Ws(Hs,d,sb)},[s]),bc=a.useCallback(t=>{const i=ja.current;if(!(!i||i.pointerId!==t.pointerId)){ja.current=null,Is(Hs);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),Yn=!!(x&&Hn!==null&&ju(R)),oi=!!(x&&!gn&&Ie.size===0&&Hn===null),Gt=(()=>{let t=Ko;return t==="android"&&!Gr&&(t="files"),Yn&&(t==="git"||t==="diff")&&(t="files"),t})(),ot=Gt==="git",Tr=Gt==="files",Mt=Gt==="diff",Xn=Gt==="android",ii=a.useRef(null),Ca=a.useCallback((t,i)=>{const d=Y.getState().rightTab;if(d===t)return;const y=performance.now(),v=y-i.timeStamp;ii.current={from:d,to:t,startedAt:y,inputDelayMs:v>=0&&v<6e4?Math.round(v):null},Lr(t)},[Lr]);a.useEffect(()=>{const t=ii.current;if(!t||t.to!==Gt)return;ii.current=null;const i=Math.round(performance.now()-t.startedAt);let d=window.requestAnimationFrame(()=>{d=window.requestAnimationFrame(()=>{Os("tab_switch_presented",{from:t.from,to:t.to,inputDelayMs:t.inputDelayMs,commitMs:i,frameMs:Math.round(performance.now()-t.startedAt)})})});return()=>window.cancelAnimationFrame(d)},[Gt]);const bh=Zm(t=>t.overlay==="sidebar")&&Xn;a.useEffect(()=>{if(!oe){la(!0);return}if(!r){const i=window.setTimeout(()=>{la(!1)},lb);return()=>window.clearTimeout(i)}la(!1);const t=window.setTimeout(()=>{la(!0)},ib);return()=>window.clearTimeout(t)},[oe,r]),a.useEffect(()=>{if(!oe||!Mt)return;const t=si.current;if(!t)return;const i=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(i)},[Mt,oe]),a.useEffect(()=>{if(!Yn||!x||pr)return;const t=window.setTimeout(()=>{Dt(x,{background:!0})},3e3);return()=>window.clearTimeout(t)},[Yn,x,pr,Dt]);const xh=a.useCallback(t=>{Dt(t,{discoverOnly:!0})},[Dt]);_p({active:r&&(ot||Mt),rootPath:x,loading:pr,delay:ot&&!oe?0:Ui,lastStartedRoot:ri,load:xh}),a.useEffect(()=>{!r||!ot||(!oe||_o)&&Bo(!0)},[ot,oe,r,_o]),a.useEffect(()=>{if(!r||ot)return;const t=window.setTimeout(()=>{Bo(!0)},Ui);return()=>window.clearTimeout(t)},[ot,r]),a.useEffect(()=>{Tr&&nh(!0)},[Tr]),a.useEffect(()=>{Mt&&_l(!0)},[Mt]),a.useEffect(()=>{!r||!Xn||(n&&ca&&ca.sessionId!==n&&(Li.getState().setDock(Pi,null),lo({androidPanel:{docked:null}}).catch(()=>{})),Bl(!0))},[Xn,r,n,ca]),a.useEffect(()=>{if(r&&Xn||!Oo)return;const t=window.setTimeout(()=>Bl(!1),ob);return()=>window.clearTimeout(t)},[r,Xn,Oo]),a.useEffect(()=>{let t=!1;return Cu().then(i=>{!t&&i.androidPanel&&Ol(i.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const xc=a.useCallback(t=>{Ol(t),t?Lr("android"):Y.getState().rightTab==="android"&&Lr("files"),lo({androidPanel:{enabled:t}}).catch(()=>{})},[Lr]),vc=a.useCallback(t=>{ce&&ax(ce,t.currentTarget.scrollTop)},[ce]);a.useEffect(()=>()=>{Ar.current?.abort(),Is(yl),Is(kl),Is(Hs),Is(Oi)},[]),a.useEffect(()=>{if(!ce||!uc)return;const t=zf()[ce]?.top;if(typeof t!="number")return;let i=window.requestAnimationFrame(()=>{zn.current&&(zn.current.scrollTop=t),i=window.requestAnimationFrame(()=>{zn.current&&(zn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(i)},[ce,uc]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return Em(t.signal).then(i=>ql(!!i.available)).catch(()=>ql(!1)),()=>t.abort()},[r]);const ks=a.useCallback(t=>{if(q(null),st(t),St(null),oe){Mr(!0),$r(1),Pr.current?.slideTo(1),u?.();return}},[oe,u,st]),wc=a.useCallback((t,i)=>{if(q(null),st(t),Jt(i),oe){Mr(!0),$r(1),Pr.current?.slideTo(1),u?.();return}},[oe,u,st]),Ss=a.useCallback(async(t,i)=>{const d=i||Bn||x;if(!(!d||t.length===0)){ga(!0);try{await Ya(d,t),Un(d,!1)}catch(y){wt(y instanceof Error?y.message:o("rightSidebar.uploadFailed")),window.setTimeout(()=>wt(null),4e3)}finally{ga(!1)}}},[Bn,x,Un,o]),yc=a.useCallback(async t=>{try{await Mm(t)}catch(i){wt(i instanceof Error?i.message:o("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>wt(null),4e3)}},[o]),Na=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Ho(!0)},[]),kc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ho(!1)},[]),Sc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ho(!1);const i=t.dataTransfer.files;i.length>0&&Ss(Array.from(i))},[Ss]),li=a.useCallback(t=>{ut(t),window.setTimeout(()=>ut(i=>i===t?null:i),1400)},[]),Ir=a.useCallback(t=>{re(t),window.setTimeout(()=>re(i=>i===t?null:i),1400)},[]);a.useEffect(()=>{Lt(ru,Te)},[Te]),a.useEffect(()=>{Lt(nu,Ot)},[Ot]),a.useEffect(()=>{Lt(su,z)},[z]),a.useEffect(()=>{Ws(Oi,ve,Zg)},[ve]),a.useEffect(()=>(Jl().catch(()=>{}),Md(t=>{t.type==="pinned-explorer-roots"&&Ql(t.pinnedExplorerRoots)})),[Jl,Ql]);const jc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),Ea=a.useRef(null),wn=a.useRef(null),[Rc,ci]=a.useState(!1);a.useEffect(()=>{if(!r)return;ci(!1);let t=!1;$m().then(d=>{t||(Ea.current=d.text,Xe(y=>d.text&&d.text!==y?d.text:y),ci(!0))}).catch(()=>{t||ci(!0)});const i=Md(d=>{d.type==="context-draft"&&d.origin!==jc.current&&(Ea.current=d.text,Xe(d.text))});return()=>{t=!0,i(),wn.current!==null&&(window.clearTimeout(wn.current),wn.current=null)}},[r]),a.useEffect(()=>{if(!Rc||Ea.current===ve)return;wn.current!==null&&window.clearTimeout(wn.current);const t=ve;wn.current=window.setTimeout(()=>{wn.current=null,Lm(t,jc.current).then(()=>{Ea.current=t}).catch(()=>{})},500)},[ve,Rc]);const Jn=a.useCallback((t,i,d)=>{if(t){if(Am(d?t+d:t)){li(i);return}Te?(Xe(y=>cg(y,t)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(lt(!1),ir(y=>y+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?t+d:t,focus:!0}})),li(i)}},[Te,li]),Ma=a.useCallback(t=>{const i=Nn(t,x);return ep(i,x)},[x]),di=Hu(Ir),Kt=a.useCallback((t,i)=>{const d=Nn(t,x);Jn(tp(d,x),i??`path:${d}`)},[x,Jn]),vh=a.useCallback(async t=>{ga(!0);try{await rp(t,Ya,i=>{Kt(i,`path:${i}`)}),oe&&!Te&&l()}catch(i){wt(i instanceof Error?i.message:o("rightSidebar.uploadFailed")),window.setTimeout(()=>wt(null),4e3)}finally{ga(!1)}},[Te,Kt,oe,l,o]),$a=a.useRef(!0),ui=a.useRef(n);ui.current=n,a.useEffect(()=>($a.current=!0,()=>{$a.current=!1}),[]);const wh=a.useCallback(t=>{np.getState().enqueue(t,n??null,x||"/",i=>{if(Te&&$a.current&&ui.current===n)Kt(i);else return Dd(i,n)})},[n,x,Te,Kt]),yh=a.useCallback(async t=>{const d=(await Ya("/tmp",[t])).files[0]?.path;if(!d)throw new Error("截图上传未返回文件路径");Te&&$a.current&&ui.current===n?Kt(d):await Dd(d,n)},[Te,Kt,n]),Dr=a.useCallback((t,i)=>{if(!t)return;const d=t.includes(`
|
|
1659
|
+
`})(),Qt=`path:${We}`,Zt=C?`path:${We}:${C.start}-${C.end}`:Qt,Ln=M===Qt,fs=M===Zt,Qr=H===Qt,dr=H===Zt,Zr=fs||dr,en=C?C.start===C.end?`L${C.start}`:`L${C.start}-${C.end}`:null,tn=_=>{const G=ye.current;if(!G)return;const de=G.getBoundingClientRect(),we=_.currentTarget.getBoundingClientRect(),Ze=_.clientX||we.left+we.width/2,Oe=(_.clientY||we.top+we.height/2)-de.top+G.scrollTop,Ue=m?116:132,gt=G.scrollLeft+Math.max(8,G.clientWidth-Ue),xt=Math.min(Math.max(8,Ze-de.left+G.scrollLeft+10),gt);Ne({top:Oe,left:xt})},ur=(_,G)=>{rl()||(tn(_),R(de=>{const we=nl(de,G,G);return we||Ne(null),we}))},fr=(_,G,de)=>{tn(_),R(we=>{const Ze=nl(we,G,de);return Ze||Ne(null),Ze})},xe=(_,G,de,we)=>{we==="end"&&tn(_),R({start:G,end:de})},er=_=>{const{scrollTop:G,scrollLeft:de}=_.currentTarget;fe(G),Gi(P,n,{top:G,left:de,markdownTop:G})},rn=_=>{if(_.directory){p?.(_.path);return}if(_.path===We||E.kind==="text"&&_.path===E.sourcePath){_.fragment&&_r(_.fragment);return}Me(G=>[...G,We]),Pe.current=_.path,le(_.fragment),R(null),V(_.path)},Pn=()=>{const _=Ee[Ee.length-1];_&&(Me(G=>G.slice(0,-1)),Pe.current=_,le(null),R(null),V(_))},hs=_=>{const{scrollTop:G,scrollLeft:de}=_.currentTarget;Gi(P,n,{top:G,left:de})},nn=()=>{if(r){r(Jr,Zt);return}C&&f(Jr,Zt)},Dt=async()=>{if(!(!We||ut.status==="pending")&&!(E.kind==="loading"||E.kind==="error")){Qe({status:"pending"});try{await Bm(We),Qe({status:"idle"})}catch(_){Qe({status:"error",message:_ instanceof Error?_.message:o("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{ref:O,className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Ct.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${m&&(cr||Cr)?"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:[m&&g&&e.jsx("button",{type:"button",onClick:g,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":o("rightSidebar.backToFileList"),title:o("rightSidebar.backToFileList"),children:e.jsx(Fu,{size:16})}),Ee.length>0&&e.jsxs("button",{type:"button",onClick:Pn,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 ${m?"w-9":"px-2.5"}`,"aria-label":o("rightSidebar.backToPreviousPreview"),title:o("rightSidebar.backToPreviousPreview"),children:[e.jsx(Vs,{size:15}),!m&&e.jsx("span",{className:"text-[11px] font-medium",children:o("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:We,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:lr.name}),lr.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:lr.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[jr&&e.jsx("button",{type:"button",onClick:re?St:$n,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":o("rightSidebar.findInFile"),title:`${o("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(ss,{size:14})}),It&&E.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{u&&$?.(),Q(_=>{const G=_==="preview"?"source":"preview";return Lt(rf,G),G}),R(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 ${m?"w-9 px-0":"px-3"}`,"aria-label":o(L==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:o(L==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:m?L==="preview"?e.jsx(al,{size:14}):e.jsx(sl,{size:14}):o(L==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),ls&&E.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Le(_=>{const G=_==="preview"?"source":"preview";return mg(P,n,G),G}),R(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 ${m?"w-9 px-0":"px-3"}`,"aria-label":o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:m?ne==="preview"?e.jsx(al,{size:14}):e.jsx(sl,{size:14}):o(ne==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Cr&&e.jsx("button",{type:"button",onClick:()=>{Ye.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":o(De?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:o(De?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(_u,{size:15})}),!m&&e.jsx("button",{type:"button",onClick:()=>l(We,Qt),...Ct(Br,Qt),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Ln||Qr?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:o("rightSidebar.insertReference",{reference:Br}),children:o(Qr?"rightSidebar.copied":Ln?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Br)},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:o("rightSidebar.copyReference",{reference:Br}),"aria-label":o("rightSidebar.copyFileRef"),children:e.jsx(Nm,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{Dt()},disabled:ut.status==="pending"||E.kind==="loading"||E.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:ut.status==="error"?ut.message??o("rightSidebar.downloadFailed"):o("rightSidebar.downloadFile"),"aria-label":o("rightSidebar.downloadFile"),children:ut.status==="pending"?e.jsx(ht,{size:13,className:"animate-spin"}):e.jsx(Zm,{size:14})})]})]}),re&&jr&&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(ss,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:Xe,type:"search",value:et,onChange:_=>Ot(_.target.value),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),Jt(_.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:o("rightSidebar.findInFilePlaceholder"),"aria-label":o("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:lt.length>0?`${ae+1}/${lt.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Jt(-1),disabled:lt.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":o("rightSidebar.previousSearchMatch"),title:`${o("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(kl,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Jt(1),disabled:lt.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":o("rightSidebar.nextSearchMatch"),title:`${o("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(ep,{size:13})}),e.jsx("button",{type:"button",onClick:St,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":o("rightSidebar.closeFileSearch"),title:`${o("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Pt,{size:13})})]}),Rr&&!(m&&(cr||Cr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[Rr.size!==null&&e.jsx("span",{children:o("rightSidebar.byteCount",{count:Rr.size.toLocaleString()})}),"truncated"in Rr&&Rr.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:o("rightSidebar.previewTruncated")}),"mimeType"in Rr&&e.jsx("span",{children:Rr.mimeType}),"dimensions"in E&&E.dimensions&&e.jsxs("span",{children:[E.dimensions.width," × ",E.dimensions.height]})]}),!(m&&(cr||Cr))&&!Xr&&E.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:ds?o("rightSidebar.edaPickHint"):ra?o("rightSidebar.csvTablePreview"):Nr||is?o("rightSidebar.kicadProjectPickHint"):cs?o("rightSidebar.videoPreviewHint"):jt?o("rightSidebar.imagePreviewHint"):cr?C?o("rightSidebar.selectedLineHint",{lineLabel:en??""}):o("rightSidebar.markdownPreviewHint"):Cr?o("rightSidebar.htmlPreviewHint"):C?o("rightSidebar.selectedLineHint",{lineLabel:en??""}):o("rightSidebar.multiLineHint")})})]}),!s&&(E.kind==="video"||E.kind==="model3d"||E.kind==="eda"||Cr)?null:E.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8",children:e.jsx($i,{label:E.mode==="eda"?o("rightSidebar.edaLoading"):E.mode==="image"?o("rightSidebar.loadingImage"):E.mode==="model3d"?o("rightSidebar.model3dLoading"):E.mode==="video"?o("rightSidebar.loadingVideo"):o("common.loading")})}):E.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:E.message}),e.jsx("button",{type:"button",onClick:os,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:o("common.retry")})]}):E.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:o("rightSidebar.binaryPreviewHint")})}):E.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:E.meta.mimeType==="image/svg+xml"?e.jsx(Ju,{blobUrl:E.objectUrl,filePath:We,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(th,{src:E.objectUrl,alt:lr.name,vector:!1,onLoad:_=>{const G=_.currentTarget;K(de=>de.kind==="image"?{...de,dimensions:{width:G.naturalWidth,height:G.naturalHeight}}:de)},onError:()=>K({kind:"error",message:o("rightSidebar.imageLoadFailed")})})}):E.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(Ng,{url:E.url,onLoadError:()=>K({kind:"error",message:o("rightSidebar.videoLoadFailed")})})}):E.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Ag,{blobUrl:E.objectUrl,filePath:E.sourcePath,view:E.view,board:We.toLowerCase().endsWith(".kicad_pcb"),onViewChange:W,onInsertAnnotation:r??c,onRefresh:os,interactive3d:ee?e.jsx(a.Suspense,{fallback:e.jsx($i,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(du,{blobUrl:ee.objectUrl,ext:".glb",fileName:lr.name,filePath:ee.sourcePath,features:null,onInsertFeature:r??c,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:_=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(_)?_:"PCB板体/铜箔/丝印",active:E.view==="pcb-3d"})}):void 0})}):E.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx($i,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(du,{blobUrl:E.objectUrl,ext:E.ext,fileName:lr.name,filePath:E.sourcePath,features:J,onInsertFeature:r??c,onRefresh:os})})}):E.kind==="text"&&ra?e.jsx(Dg,{content:E.content,filePath:We,onInsertAnnotation:r??c},We):E.kind==="text"&&(Nr||is)?e.jsx(Bg,{content:E.content,filePath:We,localState:is,onInsertAnnotation:r??c},We):cr?e.jsxs("div",{ref:ye,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:er,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Gf,{content:E.content,filePath:E.sourcePath,rootPath:P,lineRange:C,onLineRangeClick:fr,onLineRangeDrag:xe,scrollTop:se,outlineOpen:u,outlineCloseSignal:y,onOutlineOpen:b,onOutlineClose:$,lightboxOpen:T,lightboxCloseSignal:I,onLightboxOpen:D,onLightboxClose:U,onLocalLinkOpen:rn}),C&&je&&e.jsxs("button",{type:"button",onClick:nn,...Ct(Jr,Zt),style:{top:je.top,left:je.left,transform:"translateY(-50%)"},className:qd(m,Zr),title:`Insert markdown reference: ${Hr}`,children:[e.jsx(bo,{size:m?13:11}),dr?o("rightSidebar.copied"):fs?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:en??""})]})]}):Cr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(qg,{ref:Ye,src:Cm(We),title:`${lr.name} preview`,exitFullscreenLabel:o("rightSidebar.htmlFullscreenExit"),onFullscreenChange:rt},`${We}:${Tt}:${Mn}`)}):E.kind==="text"?e.jsxs("div",{ref:ye,onScroll:hs,className:`${Rl} 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:[Or.length>0?e.jsx("div",{className:"min-w-full",children:Or.map((_,G)=>{const de=G+1,we=!!(C&&de>=C.start&&de<=C.end),Ze=Ae&&Ae.length===Or.length?Ae[G]:null;return e.jsxs("div",{ref:Fe=>{Fe?me.current.set(de,Fe):me.current.delete(de)},role:"button","data-file-preview-line":de,tabIndex:0,onClick:Fe=>ur(Fe,de),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ur(Fe,de))},style:{gridTemplateColumns:`${Ur}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${we?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${Br}:${de}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${we?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:de}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ze??(_||" ")})]},G)})}):"Empty file.",C&&je&&e.jsxs("button",{type:"button",onClick:nn,...Ct(Jr,Zt),style:{top:je.top,left:je.left,transform:"translateY(-50%)"},className:qd(m,Zr),title:`Insert code reference: ${Hr}`,children:[e.jsx(bo,{size:m?13:11}),dr?o("rightSidebar.copied"):fs?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:en??""})]})]}):null]})}function $x({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:f,push:c,pinned:h=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:p=!1,rightSidebarFilePreviewCloseSignal:m,onOpenRightSidebarFilePreview:u,onCloseRightSidebarFilePreview:y,rightSidebarRepoPickerOpen:b=!1,rightSidebarRepoPickerCloseSignal:$,onOpenRightSidebarRepoPicker:T,onCloseRightSidebarRepoPicker:I,markdownOutlineOpen:D=!1,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:C,onCloseMarkdownOutline:R,markdownImageLightboxOpen:M=!1,markdownImageLightboxCloseSignal:H,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:S}){const{t:o,locale:O}=pt(),[P,V]=a.useState(""),[E,K]=a.useState(null),pe=Y(t=>t.rightSearchOpen),W=Y(t=>t.setRightSearchOpen),ee=Y(t=>t.rightSidebarLayoutPreference),A=Y(t=>t.setRightSidebarLayoutPreference),[B,J]=a.useState(()=>Sb()),[ue,me]=a.useState("."),[ye,je]=a.useState(""),[Ne,L]=a.useState(!1),[Q,ne]=a.useState(!1),[Le,Ye]=a.useState(!1),[De,rt]=a.useState(!1),_e=a.useDeferredValue(P),[N,se]=a.useState(null),[fe,Ee]=a.useState([]),[Me,Ke]=a.useState([]),le=Y(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Pe=Y(t=>t.setActiveGitRepo),[dt,Ae]=a.useState(null),[ke,ut]=a.useState(null),[Qe,re]=a.useState(null),[Te,et]=a.useState(()=>mt(au,zs)??!1),[Ot,lt]=a.useState(()=>mt(ou,zs)??!1),[z,ae]=a.useState(()=>mt(iu,zs)??!1),[ve,Xe]=a.useState(()=>mt(Oi,xb)??""),[Ct,ir]=a.useState(0),[At,Tt]=a.useState(!1),[Sr,Xt]=a.useState(!1),Mn=a.useRef(null),ta=a.useRef(null),[os,_r]=a.useState(!1),[jr,St]=a.useState(null),[$n,Jt]=a.useState(null),[We,lr]=a.useState(()=>fu(_i)),[Br,Or]=a.useState(()=>fu(su)),[Ur,Rr]=a.useState(()=>bb()),[It,ra]=a.useState(()=>vb()),[Nr,is]=a.useState(()=>wb()),cr="words",[ls,Cr]=a.useState(0),[jt,Xr]=a.useState([]),[cs,ds]=a.useState([]),[us,Hr]=a.useState(!1),[Jr,Qt]=a.useState(null),[Zt,Ln]=a.useState([]),[fs,Qr]=a.useState(!1),[dr,Zr]=a.useState([]),[en,tn]=a.useState([]),[ur,fr]=a.useState(!1),[xe,er]=a.useState(null),[rn,Pn]=a.useState([]),[hs,nn]=a.useState({}),Dt=a.useRef(0),[_,G]=a.useState(0),[de,we]=a.useState(!1),[Ze,Fe]=a.useState(null),[Oe,Ue]=a.useState(null),[gt,xt]=a.useState(null),[sn,tr]=a.useState(null),[zr,ms]=a.useState(!1),[ps,hr]=a.useState(""),an=a.useDeferredValue(ps),[on,Mo]=a.useState({}),[Z,He]=a.useState([]),[Ut,Er]=a.useState(!1),[na,gs]=a.useState(!1),[$o,An]=a.useState(null),[Lo,Tn]=a.useState(!1),mr=a.useRef(null),Wr=a.useRef(0),Dl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[rh,sa]=a.useState(null),[bs,Fl]=a.useState(()=>mt(Bi,zs)??!1),[Po,Ao]=a.useState(!1),[aa,To]=a.useState([]),[rr,oa]=a.useState({}),[Et,ia]=a.useState({}),[ln,Io]=a.useState({}),[_l,Bl]=a.useState(()=>new Set),[qe,cn]=a.useState(null),[Do,dn]=a.useState(null),[nh,Mr]=a.useState(!1),[Ol,$r]=a.useState(0),[,Fo]=a.useState(0),[_o,la]=a.useState(!1),[sh,ah]=a.useState(()=>Y.getState().rightTab==="files"),[nr,Bo]=a.useState(!1),[oh,Ul]=a.useState(()=>Y.getState().rightTab==="diff"),[Oo,Hl]=a.useState(()=>Y.getState().rightTab==="android"),[Gr,zl]=a.useState(!1),ca=Li(t=>t.docks[Ai]),ih=!!ca,[ze,xs]=a.useState(null),[In,vs]=a.useState(null),[vt,un]=a.useState(null),[Wl,yt]=a.useState(null),[Dn,Gl]=a.useState(null),[Uo,lh]=a.useState(()=>Date.now()),[ch,dh]=a.useState(!1),[fn,da]=a.useState(!1),[ua,Kl]=a.useState(""),[Fn,fa]=a.useState(""),[hn,ha]=a.useState(""),[mn,ma]=a.useState(""),[ql,_n]=a.useState(null),[pa,ga]=a.useState(!1),[Vl,Ho]=a.useState(!1),[Yl,Xl]=a.useState(!1),[ba,uh]=a.useState({key:null,nonce:0}),Jl=a.useRef(null),Ql=a.useRef(null),oe=Om(s,h,ee),zo=hf(oe,h,Nr),[Wo,Go]=a.useState(()=>$b(s)),Ko=Y(t=>t.rightTab),Lr=Y(t=>t.setRightTab),x=Y(t=>t.rootPath),Bn=Y(t=>t.explorerRoot),Zl=Y(t=>t.pinnedExplorerRootsCache),ec=Y(t=>t.hydratePinnedExplorerRoots),tc=Y(t=>t.syncPinnedExplorerRoots),Ht=Y(t=>t.setExplorerRoot),rc=Y(t=>t.resetExplorerToProject),On=Y(t=>t.pinExplorerRoot),pn=Y(t=>t.unpinExplorerRoot),nt=Y(t=>t.selectedFilePath),st=Y(t=>t.selectFile),qo=Y(t=>t.showHiddenFiles),fh=Y(t=>t.toggleShowHiddenFiles),Vo=Y(t=>!!(x&&t.nestedGitScanRoots[x])),Ie=Y(t=>t.changedFiles),xa=Y(t=>t.setChangedFiles),Un=Y(t=>t.invalidateDirectoryCache),hh=Y(t=>t.setDirectorySortMode),nc=Y(t=>t.applyFileWatchEvents),sc=Y(t=>t.reconcileDirectoryCache),ac=Y(t=>t.bumpFileWatchEpoch),pr=Y(t=>t.gitBundleLoading),oc=Y(t=>t.gitBundleSlow),gn=Y(t=>t.gitBundleError),Hn=Y(t=>t.gitBundleLastLoadedAt),ic=Y(t=>t.beginGitBundleLoading),lc=Y(t=>t.setGitBundleSlowFor),Yo=Y(t=>t.finishGitBundleLoading),va=Y(t=>t.resetGitBundleLoading),Xo=Y(t=>t.setGitBundleError),cc=Y(t=>t.markGitBundleLoaded),ce=Bn??x,ya=Y(t=>!!(ce&&t.hideGitIgnoredRoots[ce])),mh=Y(t=>t.hideGitIgnoredRootsHydrated),ph=Y(t=>t.setHideGitIgnoredRoot),[Jo,dc]=a.useState(!1),[uc,Qo]=a.useState(null);a.useEffect(()=>{Qo(null)},[ce]);const fc=a.useMemo(()=>ce?Qg(ce,ue):"",[ce,ue]),ys=a.useMemo(()=>Jg(ye),[ye]),hc=a.useMemo(()=>({excludePatterns:ys,caseSensitive:Q,wholeWord:Le,regex:De}),[Q,ys,De,Le]),wa=Y(t=>ce?t.fileSortModes[ce]??"name":"name"),mc=Y(t=>!!(ce&&t.directoryCache.has(ce))),zn=a.useRef(null),Rt=a.useRef(0),[pc]=a.useState(()=>++jx),Pr=a.useRef(null),Kr=a.useRef(null),ka=a.useRef(0),zt=a.useRef(new Map),Wt=a.useRef(new Map),gr=a.useRef(new Set),bn=a.useRef(new Set),xn=a.useRef(0),qr=a.useRef(null),Wn=a.useRef(0),Gn=a.useRef(null),Kn=a.useRef(0),Vr=a.useRef(null),Zo=a.useRef(new Set),ei=a.useRef(null),ti=a.useRef(null),Sa=a.useRef(null),ri=a.useRef(null),ni=a.useRef(null),ws=a.useRef(new Set);a.useEffect(()=>{if(Dn===null)return;const t=Math.max(0,Date.now()-Dn),i=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,d=Math.max(50,i-t%i),w=window.setTimeout(()=>lh(Date.now()),d);return()=>window.clearTimeout(w)},[Uo,Dn]);const ja=a.useRef(null),Ar=a.useRef(null),si=a.useRef(null),gc=a.useRef(null),ks=a.useRef(null),Re=a.useCallback(t=>Y.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=i=>{const d=Ex(i.target);d&&Us("global_change_row_event",{...Mx(i),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:Y.getState().selectedFilePath,rightTab:Y.getState().rightTab,activeGitRepoRoot:le,changedFiles:Y.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[le,r]);const bc=a.useCallback(async(t=x??void 0)=>{if(!t)return null;if(gr.current.has(t)||bn.current.has(t))return it("untracked_skip_cached",{cwd:t,rootPath:x,completed:gr.current.has(t),running:bn.current.has(t)}),null;const i=x,d=ka.current+1;ka.current=d,zt.current.set(t,d);const w=`right-sidebar-git-untracked:${t}`,v=new AbortController;Wt.current.set(t,v),bn.current.add(t),it("untracked_start",{requestId:d,cwd:t,rootPath:x});try{let k=await Md(t,v.signal,w),j=0;for(;k.status==="running"&&j<120;){if(zt.current.get(t)!==d||v.signal.aborted)return it("untracked_stale_result",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,status:k.status}),null;if(!Re(i))return it("untracked_root_changed",{requestId:d,cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath}),null;await new Promise(te=>window.setTimeout(te,j<10?1e3:3e3)),j+=1,k=await Md(t,v.signal,w)}if(zt.current.get(t)!==d||!Re(i))return it("untracked_stale_result",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath,files:k.files.length,status:k.status}),null;if(k.status==="done")return xa(Yf(Y.getState().changedFiles,k.files)),k.files.length>0&&Ee(te=>{const Ce=new Map(te.map(ge=>[ge.root,ge])).get(t);if(!Ce)return te;const Ve=fx(Ce.files,k.files),X=te.map(ge=>ge.root===t?{...ge,files:Ve,context:ge.context?{...ge.context,changedFiles:Ve.map($e=>({path:$e.path,absolutePath:$e.absolutePath,status:$e.status})),truncated:!1}:ge.context,untrackedDeferred:!1}:ge);Ke(Xf(X,x));const q=X.find(ge=>ge.root===x);return q?.context&&se(ge=>ge?.root===q.root?{...ge,...q.context}:ge),X}),gr.current.add(t),it("untracked_apply",{requestId:d,cwd:t,files:k.files.length}),k;const ie=k.error||(k.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return gr.current.add(t),it("untracked_error",{requestId:d,cwd:t,message:ie,code:k.code,status:k.status}),null}catch(k){if(zt.current.get(t)!==d||!Re(i)||wr(k))return it("untracked_aborted",{requestId:d,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Y.getState().rootPath,message:k instanceof Error?k.message:String(k)}),null;const j=k instanceof Error?k.message:"Failed to scan untracked files";return gr.current.add(t),it("untracked_error",{requestId:d,cwd:t,message:j}),null}finally{Wt.current.get(t)===v&&Wt.current.delete(t),zt.current.get(t)===d&&zt.current.delete(t),bn.current.delete(t)}},[N,Re,x,xa]),sr=a.useMemo(()=>{const t=new Set(Me.map(d=>d.root)),i=Zt.filter(d=>t.has(d));return i.length>0?i:le?[le]:[]},[le,Zt,Me]),xc=sr.length===0,vn=a.useMemo(()=>sr.map(t=>fe.find(i=>i.root===t)).filter(t=>!!t),[sr,fe]),gh=a.useMemo(()=>Me.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[Me]),br=a.useCallback(async()=>{if(!x){Xr([]),ds([]);return}const t=x,i=Wn.current+1;Wn.current=i,Gn.current?.abort();const d=new AbortController;Gn.current=d,Hr(jt.length===0),Qt(null);try{const w=sr.length>0?await Promise.all(sr.map(v=>$d({workspaceRoot:x,repoRoot:v},d.signal))).then(v=>({records:v.flatMap(k=>k.records),walkthroughs:v.flatMap(k=>k.walkthroughs??[])})):await $d({workspaceRoot:x},d.signal);if(Wn.current!==i||!Re(t))return;Xr(w.records),ds(w.walkthroughs??[])}catch(w){if(Wn.current!==i||!Re(t)||wr(w))return;Qt(w instanceof Error?w.message:"Failed to load change audit explanations")}finally{Gn.current===d&&(Gn.current=null),Wn.current===i&&Re(t)&&Hr(!1)}},[jt.length,sr,Re,x]),Ra=a.useCallback(async(t,i,d)=>{if(!t&&!x){Zr([]),tn([]);return}const w=x,v=Kn.current+1;Kn.current=v,Vr.current?.abort();const k=new AbortController;Vr.current=k;try{const j=t?[t]:Array.from(new Set([x,...fe.map(te=>te.root)].filter(te=>!!te))),ie=await Promise.all(j.map(te=>Mm({repoRoot:te,baseRef:i,branchName:d},k.signal))).then(te=>{const be=new Map,Ce=new Map;for(const Ve of te){for(const X of Ve.records)be.set(X.id,X);for(const X of Ve.walkthroughs??[])Ce.set(X.id,X)}return{records:Array.from(be.values()),walkthroughs:Array.from(Ce.values())}});if(Kn.current!==v||!Re(w))return;Zr(ie.records),tn(ie.walkthroughs??[])}catch(j){if(Kn.current!==v||!Re(w)||wr(j))return;console.warn("[RightSidebar] Failed to load branch explanations",j)}finally{Vr.current===k&&(Vr.current=null)}},[fe,Re,x]),qn=a.useCallback((t,i={})=>{if(!Re(x)){it("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:Y.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}it(t.files.length===0?"empty_bundle":"apply",{rootPath:x,available:t.available,files:t.files.length,repositories:t.repositories?.map(q=>({root:q.root,relativeRoot:q.relativeRoot,files:q.files.length,available:q.available,error:q.error})),repoFilters:t.repoFilters?.map(q=>({root:q.root,label:q.label,count:q.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let d=mf(t),w=t.repoFilters??[],v=t.files;const k=Y.getState().changedFiles;if(!!(i.cacheOnly&&!t.cached&&t.files.length===0&&d.length===0)&&(k.size>0||fe.length>0||N)){it("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:k.size,currentRepositories:fe.length});return}const ie=d.some(q=>q.deferred);if(ie&&!i.replaceWorkspace){const q=new Set(d.filter($e=>!$e.deferred||$e.root===x).map($e=>$e.root));v=[...Array.from(k.values()).filter($e=>!q.has(bt($e,x)??"")),...t.files]}const te=ju(k.values(),x),be=ju(t.files,x),Ce=d.some(q=>q.root!==x);if(!!(i.background&&!ie&&!i.replaceWorkspace&&k.size>0&&(t.files.length===0&&!t.error||te>0&&be===0&&!Ce))){it("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:k.size,nextFiles:t.files.length,currentNestedCount:te,nextNestedCount:be,nextRepositories:d.map(q=>({root:q.root,relativeRoot:q.relativeRoot,files:q.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(i.replaceRepoRoot){const q=Jf(k.values(),fe,t,i.replaceRepoRoot,x);v=q.files,d=q.repositories,w=q.repoFilters}if(xa(Vf(v)),Ee(q=>{if(!ie||i.replaceWorkspace)return d;const ge=new Map(q.map($e=>[$e.root,$e]));return d.map($e=>{const Ge=ge.get($e.root);return!$e.deferred||!Ge?$e:{...$e,available:Ge.available,files:Ge.files,context:Ge.context,deferred:Ge.deferred,untrackedDeferred:Ge.untrackedDeferred,error:Ge.error}})}),Ke(w),ni.current=x,i.syncActiveRepo!==!1){const{contextKey:q,activeGitRepos:ge}=Y.getState(),$e=q?ge[q]??null:null,Ge=i.activeRepoRoot!==void 0?i.activeRepoRoot:$e,Be=jb({...t,repositories:d,repoFilters:w},Ge);Pe(Be)}typeof t.cacheUpdatedAt=="number"&&Gl(t.cacheUpdatedAt),se(q=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==x)return q;if(!t.context)return null;const ge=q?.root??x;return!q?.available||ge!==(t.context.root??x)?t.context:{...q,...t.context}}),i.reloadDiff&&Cr(q=>q+1);const X=Y.getState().selectedFilePath;if(X&&!X.startsWith("/")&&!v.some(q=>q.path===X||q.absolutePath===X)&&st(null),lr(q=>{const ge=new Set(v.map(Ge=>bt(Ge,x)).filter(Boolean)),$e=new Set;for(const Ge of q)ge.has(Ge)&&$e.add(Ge);return Hi(_i,$e),$e}),i.loadDeferred!==!1){const q=d.filter(ge=>ge.untrackedDeferred&&ge.root).map(ge=>ge.root);for(const ge of q)bc(ge)}i.loadAudit!==!1&&br()},[Re,br,bc,x,st,Pe,xa]);a.useEffect(()=>{va(),ei.current=null,ti.current=x;const t=[],i=[];Rt.current+=1,xn.current+=1,ka.current+=1,Pr.current?.abort(),Nt(Bs(Kr.current?.cwd??x??void 0)),Kr.current=null,Pr.current=null,qr.current?.abort(),Nt("right-sidebar-git-details"),qr.current=null;for(const j of Wt.current.values())j.abort();for(const j of Wt.current.keys())Nt(`right-sidebar-git-untracked:${j}`);Wt.current.clear(),zt.current.clear(),Wn.current+=1,Gn.current?.abort(),Gn.current=null,Kn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Nt("right-sidebar-recent-commits"),mr.current=null,Xr([]),ds([]),Hr(!1),Qt(null),Ln([]),Qr(!1),Zr([]),tn([]),fr(!1),er(null),we(!1),Fe(null),Ue(null),xt(null),tr(null),ms(!1),hr(""),He([]),Er(!1),gs(!1),An(null),Tn(!1),sa(null),cn(null),dn(null),Fl(!1),Lt(Bi,!1),Ao(!1);const d=x?hu()[x]:null,w=d?.previewEntries??[],v=d?.selectedPreviewKey??null,k=v?w.find(j=>j.key===v)??null:null;++Dt.current,we(!1),To(d?.selectedRepoRoots??[]),oa(d?.repoTargetBranches??{}),ia(d?.repoBaseBranches??{}),Pn(w),nn(d?.previewScrollTops??{}),k&&d?.previewDetailOpen&&(k.diff.hunks?.length??0)>0&&(er(k.diff),cn(k.key),dn(d.selectedPreviewFileKey??(k.diff.hunks?.[0]?`${k.diff.hunks[0].filePath}\0${k.diff.hunks[0].hunkHeader}\0${k.diff.hunks[0].hunkIndex}`:null)),fr(!0)),Io(d?.repoIncludeUncommitted??Object.fromEntries(Object.keys(d?.repoTargetBranches??{}).map(j=>[j,d?.includeUncommitted??!0]))),ei.current=x,da(!1),gr.current.clear(),bn.current.clear(),xs(null),vs(null),un(null),yt(null),Gl(null),Ee(t),Ke(i),se(null),ri.current=null,ni.current=null,ws.current.clear()},[va,x]);const Ft=a.useCallback(async(t=x??void 0,i={})=>{if(!t)return null;const d=x,w=Rt.current;if(await _p(()=>Promise.all([Y.getState().hydrateNestedGitScanRoots(),Y.getState().hydrateActiveGitRepos()]).then(()=>{})),Rt.current!==w||!Re(d))return null;const v=t===x&&Fs(x),k=i.includeNested??v,j=i.refresh??i.reloadDiff??!1,ie=i.cacheOnly??!1,te=i.background??!1,be=k&&(i.discoverOnly??!1);j&&gr.current.clear();const Ce=Kr.current;if(Ce&&Ce.cwd===t&&Ce.includeNested===k&&Ce.refresh===j&&Ce.cacheOnly===ie&&Ce.discoverOnly===be)return it("reuse_pending",{cwd:t,includeNested:k,refresh:j,cacheOnly:ie,discoverOnly:be}),Ce.promise;const Ve=Rt.current+1;Rt.current=Ve;const X=`right-sidebar:${pc}:${Ve}`;Pr.current?.abort();const q=Bs(t);Nt(q);const ge=new AbortController;Pr.current=ge;let $e=null;te||ic(X),Xo(null),it("start",{requestId:Ve,cwd:t,rootPath:x,requestSlotId:q,includeNested:k,refresh:j,cacheOnly:ie,background:te,existingChanges:Ie.size,lastLoadedAt:Hn}),!te&&typeof window<"u"&&($e=window.setTimeout(()=>{Rt.current===Ve&&lc(X,!0)},ib));const Ge=(async()=>{const Be=await Pi(t,ge.signal,{includeNested:k,refresh:j,cacheOnly:ie,discoverOnly:be,action:j?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:q,requestTimeoutMs:j?null:void 0});if(px(Be)){if(it("cancelled_result_ignored",{requestId:Ve,activeRequestId:Rt.current,cwd:t,error:Be.error??Be.context?.error}),ge.signal.aborted)return null;throw new Error(Be.error??Be.context?.error??"Failed to load Git changes")}return Rt.current!==Ve||!Re(d)?(it("stale_result",{requestId:Ve,activeRequestId:Rt.current,cwd:t,expectedRootPath:d,currentRootPath:Y.getState().rootPath,files:Be.files.length,repositories:Be.repositories?.length??0}),null):(qn(Be,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:k,background:te,cacheOnly:ie,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),Be)})();Kr.current={cwd:t,includeNested:k,refresh:j,cacheOnly:ie,discoverOnly:be,promise:Ge};try{const Be=await Ge;return Rt.current===Ve&&Be&&Re(d)?cc({cached:Be.cached,stale:Be.stale,cacheAgeMs:Be.cacheAgeMs,nestedDeferred:!k||Be.nestedDeferred,untrackedDeferred:Be.untrackedDeferred}):Rt.current===Ve&&Re(d)&&Yo(X),Be}catch(Be){return Rt.current!==Ve||!Re(d)||ge.signal.aborted?(it("aborted",{requestId:Ve,activeRequestId:Rt.current,cwd:t,expectedRootPath:d,currentRootPath:Y.getState().rootPath,message:Be instanceof Error?Be.message:String(Be)}),null):(it("error",{requestId:Ve,cwd:t,includeNested:k,refresh:j,background:te,message:Be instanceof Error?Be.message:String(Be)}),te||(se(null),Xo(Be instanceof Error?Be.message:"Failed to load Git changes")),null)}finally{$e!==null&&window.clearTimeout($e),Pr.current===ge&&(Pr.current=null),Kr.current?.promise===Ge&&(Kr.current=null),!te&&Rt.current===Ve&&Re(d)&&Yo(X)}},[qn,ic,Ie.size,Yo,pc,Hn,Re,cc,x,Xo,lc]),Vn=a.useCallback(async()=>{x&&await Ft(x,{reloadDiff:!0,refresh:!0})},[Ft,x]),ai=a.useCallback(async(t=x??void 0)=>{if(!t)return null;const i=x,d=xn.current+1;xn.current=d,qr.current?.abort(),Nt("right-sidebar-git-details");const w=new AbortController;qr.current=w,da(!0);try{const v=await Ld(t,w.signal,"load_git_details","right-sidebar-git-details");return xn.current!==d||!Re(i)?null:(Ee(k=>k.map(j=>j.root===v.root?{...j,available:v.available,context:v,error:v.error}:j)),se(k=>k?.root&&v.root&&k.root!==v.root?k:!k?.available||!v.available?v:{...k,...v}),v)}catch(v){return wr(v)||!Re(i)||xn.current===d&&yt(v instanceof Error?v.message:"Failed to load Git details"),null}finally{qr.current===w&&(qr.current=null),xn.current===d&&Re(i)&&da(!1)}},[Re,x]);a.useEffect(()=>{if(!r){Rt.current+=1,va(),ri.current=null,xn.current+=1,ka.current+=1,Pr.current?.abort(),Nt(Bs(Kr.current?.cwd??x??void 0)),Kr.current=null,Pr.current=null,qr.current?.abort(),Nt("right-sidebar-git-details"),qr.current=null;for(const t of Wt.current.values())t.abort();for(const t of Wt.current.keys())Nt(`right-sidebar-git-untracked:${t}`);Wt.current.clear(),zt.current.clear(),Kn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Nt("right-sidebar-recent-commits"),mr.current=null,da(!1),we(!1),Fe(null),Ue(null),xt(null),tr(null),ms(!1),hr(""),He([]),Er(!1),gs(!1),An(null),Tn(!1),V(""),W(!1),St(null),Bo(!1),oe&&Ul(!1)}},[oe,r,va,W]),a.useEffect(()=>{if(!pe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[pe]),a.useEffect(()=>{oe||Mr(!1)},[oe]);const vc=a.useCallback(t=>{Fo(t);const i=si.current;i&&(i.update(),i.slideTo(t,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(t,0)}))},[]);a.useEffect(()=>{if(oe)if(Mr(p),p&&nt){$r(1);const t=Ar.current;t&&(t.update(),t.activeIndex!==1&&(ks.current=1,t.slideTo(1,0)))}else{$r(0);const t=Ar.current;t&&t.activeIndex!==0&&(ks.current=0,t.slideTo(0,0)),St(null)}},[oe,p,x,nt]),a.useEffect(()=>{if(m!==void 0&&!p){$r(0);const t=Ar.current;t&&t.activeIndex!==0&&(ks.current=0,t.slideTo(0,0)),Mr(!1),St(null)}},[m,p]),a.useEffect(()=>{$!==void 0&&Ae(null)},[$]),a.useEffect(()=>{!oe&&p&&y?.()},[oe,y,p]),a.useEffect(()=>{Go(t=>hl(t,s))},[s]);const bh=a.useCallback(t=>{oe||(t.preventDefault(),ja.current={startX:t.clientX,startWidth:Wo,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Wo,oe]),xh=a.useCallback(t=>{const i=ja.current;if(!i||i.pointerId!==t.pointerId)return;const d=hl(i.startWidth+t.clientX-i.startX,s);Go(d),Ws(Hs,d,ob)},[s]),yc=a.useCallback(t=>{const i=ja.current;if(!(!i||i.pointerId!==t.pointerId)){ja.current=null,Ds(Hs);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),Yn=!!(x&&Hn!==null&&Cu(N)),oi=!!(x&&!gn&&Ie.size===0&&Hn===null),Gt=(()=>{let t=Ko;return t==="android"&&!Gr&&(t="files"),Yn&&(t==="git"||t==="diff")&&(t="files"),t})(),ot=Gt==="git",Tr=Gt==="files",Mt=Gt==="diff",Xn=Gt==="android",ii=a.useRef(null),Na=a.useCallback((t,i)=>{const d=Y.getState().rightTab;if(d===t)return;const w=performance.now(),v=w-i.timeStamp;ii.current={from:d,to:t,startedAt:w,inputDelayMs:v>=0&&v<6e4?Math.round(v):null},Lr(t)},[Lr]);a.useEffect(()=>{const t=ii.current;if(!t||t.to!==Gt)return;ii.current=null;const i=Math.round(performance.now()-t.startedAt);let d=window.requestAnimationFrame(()=>{d=window.requestAnimationFrame(()=>{Us("tab_switch_presented",{from:t.from,to:t.to,inputDelayMs:t.inputDelayMs,commitMs:i,frameMs:Math.round(performance.now()-t.startedAt)})})});return()=>window.cancelAnimationFrame(d)},[Gt]);const vh=tp(t=>t.overlay==="sidebar")&&Xn;a.useEffect(()=>{if(!oe){la(!0);return}if(!r){const i=window.setTimeout(()=>{la(!1)},db);return()=>window.clearTimeout(i)}la(!1);const t=window.setTimeout(()=>{la(!0)},cb);return()=>window.clearTimeout(t)},[oe,r]),a.useEffect(()=>{if(!oe||!Mt)return;const t=si.current;if(!t)return;const i=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(i)},[Mt,oe]),a.useEffect(()=>{if(!Yn||!x||pr)return;const t=window.setTimeout(()=>{Ft(x,{background:!0})},3e3);return()=>window.clearTimeout(t)},[Yn,x,pr,Ft]);const yh=a.useCallback(t=>{Ft(t,{discoverOnly:!0})},[Ft]);Bp({active:r&&(ot||Mt),rootPath:x,loading:pr,delay:ot&&!oe?0:Ui,lastStartedRoot:ri,load:yh}),a.useEffect(()=>{!r||!ot||(!oe||_o)&&Bo(!0)},[ot,oe,r,_o]),a.useEffect(()=>{if(!r||ot)return;const t=window.setTimeout(()=>{Bo(!0)},Ui);return()=>window.clearTimeout(t)},[ot,r]),a.useEffect(()=>{Tr&&ah(!0)},[Tr]),a.useEffect(()=>{Mt&&Ul(!0)},[Mt]),a.useEffect(()=>{!r||!Xn||(n&&ca&&ca.sessionId!==n&&(Li.getState().setDock(Ai,null),lo({androidPanel:{docked:null}}).catch(()=>{})),Hl(!0))},[Xn,r,n,ca]),a.useEffect(()=>{if(r&&Xn||!Oo)return;const t=window.setTimeout(()=>Hl(!1),lb);return()=>window.clearTimeout(t)},[r,Xn,Oo]),a.useEffect(()=>{let t=!1;return $u().then(i=>{!t&&i.androidPanel&&zl(i.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const wc=a.useCallback(t=>{zl(t),t?Lr("android"):Y.getState().rightTab==="android"&&Lr("files"),lo({androidPanel:{enabled:t}}).catch(()=>{})},[Lr]),kc=a.useCallback(t=>{ce&&ix(ce,t.currentTarget.scrollTop)},[ce]);a.useEffect(()=>()=>{Pr.current?.abort(),Ds(Sl),Ds(jl),Ds(Hs),Ds(Oi)},[]),a.useEffect(()=>{if(!ce||!mc)return;const t=Kf()[ce]?.top;if(typeof t!="number")return;let i=window.requestAnimationFrame(()=>{zn.current&&(zn.current.scrollTop=t),i=window.requestAnimationFrame(()=>{zn.current&&(zn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(i)},[ce,mc]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return $m(t.signal).then(i=>Xl(!!i.available)).catch(()=>Xl(!1)),()=>t.abort()},[r]);const Ss=a.useCallback(t=>{if(K(null),st(t),St(null),oe){Mr(!0),$r(1),Ar.current?.slideTo(1),u?.();return}},[oe,u,st]),Sc=a.useCallback((t,i)=>{if(K(null),st(t),Jt(i),oe){Mr(!0),$r(1),Ar.current?.slideTo(1),u?.();return}},[oe,u,st]),js=a.useCallback(async(t,i)=>{const d=i||Bn||x;if(!(!d||t.length===0)){ga(!0);try{await Ya(d,t),Un(d,!1)}catch(w){yt(w instanceof Error?w.message:o("rightSidebar.uploadFailed")),window.setTimeout(()=>yt(null),4e3)}finally{ga(!1)}}},[Bn,x,Un,o]),jc=a.useCallback(async t=>{try{await Lm(t)}catch(i){yt(i instanceof Error?i.message:o("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>yt(null),4e3)}},[o]),Ca=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Ho(!0)},[]),Rc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ho(!1)},[]),Nc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ho(!1);const i=t.dataTransfer.files;i.length>0&&js(Array.from(i))},[js]),li=a.useCallback(t=>{ut(t),window.setTimeout(()=>ut(i=>i===t?null:i),1400)},[]),Ir=a.useCallback(t=>{re(t),window.setTimeout(()=>re(i=>i===t?null:i),1400)},[]);a.useEffect(()=>{Lt(au,Te)},[Te]),a.useEffect(()=>{Lt(ou,Ot)},[Ot]),a.useEffect(()=>{Lt(iu,z)},[z]),a.useEffect(()=>{Ws(Oi,ve,tb)},[ve]),a.useEffect(()=>(ec().catch(()=>{}),Pd(t=>{t.type==="pinned-explorer-roots"&&tc(t.pinnedExplorerRoots)})),[ec,tc]);const Cc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),Ea=a.useRef(null),yn=a.useRef(null),[Ec,ci]=a.useState(!1);a.useEffect(()=>{if(!r)return;ci(!1);let t=!1;Pm().then(d=>{t||(Ea.current=d.text,Xe(w=>d.text&&d.text!==w?d.text:w),ci(!0))}).catch(()=>{t||ci(!0)});const i=Pd(d=>{d.type==="context-draft"&&d.origin!==Cc.current&&(Ea.current=d.text,Xe(d.text))});return()=>{t=!0,i(),yn.current!==null&&(window.clearTimeout(yn.current),yn.current=null)}},[r]),a.useEffect(()=>{if(!Ec||Ea.current===ve)return;yn.current!==null&&window.clearTimeout(yn.current);const t=ve;yn.current=window.setTimeout(()=>{yn.current=null,Am(t,Cc.current).then(()=>{Ea.current=t}).catch(()=>{})},500)},[ve,Ec]);const Jn=a.useCallback((t,i,d)=>{if(t){if(Tm(d?t+d:t)){li(i);return}Te?(Xe(w=>ug(w,t)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(lt(!1),ir(w=>w+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?t+d:t,focus:!0}})),li(i)}},[Te,li]),Ma=a.useCallback(t=>{const i=Cn(t,x);return rp(i,x)},[x]),di=Gu(Ir),Kt=a.useCallback((t,i)=>{const d=Cn(t,x);Jn(np(d,x),i??`path:${d}`)},[x,Jn]),wh=a.useCallback(async t=>{ga(!0);try{await sp(t,Ya,i=>{Kt(i,`path:${i}`)}),oe&&!Te&&l()}catch(i){yt(i instanceof Error?i.message:o("rightSidebar.uploadFailed")),window.setTimeout(()=>yt(null),4e3)}finally{ga(!1)}},[Te,Kt,oe,l,o]),$a=a.useRef(!0),ui=a.useRef(n);ui.current=n,a.useEffect(()=>($a.current=!0,()=>{$a.current=!1}),[]);const kh=a.useCallback(t=>{ap.getState().enqueue(t,n??null,x||"/",i=>{if(Te&&$a.current&&ui.current===n)Kt(i);else return Bd(i,n)})},[n,x,Te,Kt]),Sh=a.useCallback(async t=>{const d=(await Ya("/tmp",[t])).files[0]?.path;if(!d)throw new Error("截图上传未返回文件路径");Te&&$a.current&&ui.current===n?Kt(d):await Bd(d,n)},[Te,Kt,n]),Dr=a.useCallback((t,i)=>{if(!t)return;const d=t.includes(`
|
|
1664
1660
|
`)?`
|
|
1665
1661
|
`:void 0;Jn(t.endsWith(`
|
|
1666
|
-
`)||t.endsWith(" ")?t:`${t} `,i,d)},[Jn]),
|
|
1667
|
-
`)},[Jn]),
|
|
1668
|
-
`),
|
|
1669
|
-
`)},[
|
|
1670
|
-
`):[];if(!r||t.length===0){_n(null);return}const i=new AbortController;let d=!1,y=0,v=0;_n(null);const S=async()=>{let j=0;for(;!d&&!i.signal.aborted;){let ie=null;try{_n(null),await Bm(t,be=>{const{applicableEvents:Ne,unavailableReason:Ve}=ng(be);Ne.length>0&&ec(Ne);const X=new Set(Ne.filter(V=>V.type==="rescan-required").map(V=>V.path));if(wa)for(const V of Ne){if(V.type==="created"||V.type==="updated"){const ge=io(V.path);ge&&X.add(ge)}V.path.endsWith("/.gitignore")&&ce&&Un(ce,!0)}for(const V of X){const ge={path:V},$e=Y.getState();if(!$e.directoryCache.has(ge.path))continue;kn.current.get(ge.path)?.abort();const Be=new AbortController;kn.current.set(ge.path,Be);const jd=`file-watch-rescan:${ge.path}`;Ct(jd),Om(ge.path,Be.signal,$e.showHiddenFiles,"watch_rescan",jd,$e.fileSortModes[ge.path]??"name",ce??void 0).then(As=>{kn.current.get(ge.path)===Be&&tc(ge.path,As.entries)}).catch(As=>{yr(As)||_n(As instanceof Error?As.message:"File refresh unavailable")}).finally(()=>{kn.current.get(ge.path)===Be&&kn.current.delete(ge.path)})}Ve&&_n(Ve)},i.signal),ie=new Error("File watch stream ended")}catch(be){ie=be}if(d||i.signal.aborted||yr(ie))return;_n(ie instanceof Error?ie.message:"File watching unavailable");const te=au[Math.min(j,au.length-1)];j+=1,await new Promise(be=>{v=window.setTimeout(be,te)})}};return y=window.setTimeout(()=>{d||S()},Ui),()=>{d=!0,window.clearTimeout(y),window.clearTimeout(v),i.abort();for(const j of kn.current.values())j.abort();kn.current.clear()}},[ec,r,tc,pi,ce,wa,Un]),a.useEffect(()=>{if(!x||ei.current!==x)return;if(ti.current===x){ti.current=null;return}const t=du();Ws(sf,{...t,[x]:{selectedRepoRoots:aa,repoTargetBranches:rr,repoBaseBranches:Et,previewEntries:rn,selectedPreviewKey:xe&&ur?qe:null,selectedPreviewFileKey:xe&&ur?Do:null,previewDetailOpen:!!(xe&&ur),previewScrollTops:fs,previewMobileSlideIndex:1,repoIncludeUncommitted:ln,updatedAt:Date.now()}},Qg)},[ur,ln,xe,rn,fs,Et,rr,aa,x,Do,qe]);const ft=a.useMemo(()=>Su(Ie.values()),[Ie]),at=a.useMemo(()=>{const t=new Map;for(const i of he)t.set(i.root,i);return t},[he]),Rs=a.useMemo(()=>{const t=new Map;for(const i of he)i.deferred||t.set(i.root,i.files.length);return t},[he]),Pa=a.useCallback(t=>{if(t){if(!t.deferred){ws.current.delete(t.root);return}Rs.has(t.root)||ws.current.has(t.root)||(ws.current.add(t.root),Dt(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(i=>{i||ws.current.delete(t.root)}))}},[Dt,Rs]),ar=a.useMemo(()=>le?Me.find(t=>t.root===le)??null:null,[le,Me]),qt=a.useMemo(()=>nt?Array.from(Ie.values()).find(t=>t.path===nt||t.absolutePath===nt)??null:null,[Ie,nt]),_t=a.useMemo(()=>{const t=new Map;for(const i of he)i.available&&i.context?.available&&t.set(i.root,i);return t.size===0&&R?.available&&R.root&&t.set(R.root,{id:R.root,root:R.root,relativeRoot:".",name:tt,depth:0,nested:!1,available:!0,files:Array.from(Ie.values()).filter(i=>pt(i,x)===R.root),context:R}),Array.from(t.values()).sort((i,d)=>i.root===x?-1:d.root===x?1:(i.relativeRoot||i.name).localeCompare(d.relativeRoot||d.name)).map(i=>{const d=i.relativeRoot==="."?tt:i.relativeRoot||i.name||kt(i.root),y=ku(i.files),v=i.files.length;return{value:i.root,label:d,meta:[i.context?.branch,v>0?o("rightSidebar.repoChangedCount",{count:v}):null,y>0?o("rightSidebar.repoStagedCount",{count:y}):null].filter(Boolean).join(" · ")}})},[Ie,R,he,tt,x,o]),Se=a.useMemo(()=>le&&_t.some(t=>t.value===le)?le:qt?.repoRoot&&_t.some(t=>t.value===qt.repoRoot)?qt.repoRoot:_t.length===1||_t.length>1?_t[0].value:null,[le,_t,qt?.repoRoot]),Dc=Se?at.get(Se)??null:null,me=Dc?.context?.available?Dc.context:Se===R?.root?R:null,Je=_t.length>0&&!Se,Fc=a.useMemo(()=>Je?[]:Se?Array.from(Ie.values()).filter(t=>pt(t,x)===Se):Array.from(Ie.values()),[Se,Ie,Je,x]),Sn=a.useMemo(()=>Su(Fc),[Fc]),gi=!!(me?.available&&me.root&&Se&&me.root===Se),Nh=Se?_t.find(t=>t.value===Se)?.label??kt(Se):o("rightSidebar.gitRepositoryPlaceholder"),_c=gi?me?.branch??"HEAD":Je?o("rightSidebar.selectRepositoryForGitActions"):fn?o("rightSidebar.gitActionRunning"):"HEAD",jn=!!(me?.available&&me.root===Se&&me.status);a.useEffect(()=>{Pl.current={count:Z.length,loading:Ut,loadingMore:na,hasMore:Lo}},[Z.length,Lo,Ut,na]),a.useEffect(()=>{Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,hr(""),He([]),Er(!1),ps(!1),Pn(null),Tn(!1)},[Se]);const Cs=a.useCallback(async(t={})=>{if(!x||!Se||Je)return;const i=t.reset??!1,d=Pl.current,y=i?0:d.count;if(!i&&(d.loading||d.loadingMore||!d.hasMore))return;const v=Wr.current+1;Wr.current=v,mr.current?.abort(),Ct("right-sidebar-recent-commits");const S=new AbortController;mr.current=S,i?Er(!0):ps(!0),Pn(null);try{const j=await Pm({cwd:x,repoRoot:Se,limit:cb,skip:y,query:an.trim(),requestSlotId:"right-sidebar-recent-commits"},S.signal);if(Wr.current!==v)return;if(!j.available){Pn(j.error??"Recent commits are unavailable"),i&&He([]),Tn(!1);return}Mo(ie=>i?j.commitSyncStatus??{}:{...ie,...j.commitSyncStatus}),He(ie=>i?j.commits:[...ie,...j.commits]),Tn(j.hasMore)}catch(j){if(Wr.current!==v||yr(j))return;Pn(j instanceof Error?j.message:"Failed to load recent commits"),i&&He([]),Tn(!1)}finally{mr.current===S&&(mr.current=null),Wr.current===v&&(Er(!1),ps(!1))}},[Se,an,Je,x]);a.useEffect(()=>{zr&&Cs({reset:!0})},[an,Cs,zr,me?.ahead,me?.behind,me?.upstream]);const Eh=a.useCallback(t=>{const i=t.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||Cs({reset:!1})},[Cs]);a.useEffect(()=>{!Se||!R?.available||!ot||!nr||jn||fn||Je||ai(Se)},[Se,R?.available,jn,fn,ot,nr,ai,Je]);const Bc=r&&(Mt||ot);a.useEffect(()=>{!Bc||!x||br()},[Bc,br,x]),a.useEffect(()=>{!r||!ot||!nr||!gs||!x||Ra(null)},[gs,ot,nr,r,Ra,x]);const Mh=a.useMemo(()=>{if(!le)return 0;const t=Me.findIndex(i=>i.root===le);return t>=0?t+1:0},[le,Me]),Oc=a.useCallback(t=>{if(!t)return null;const i=Array.from(Ie.values()).filter(d=>pt(d,x)===t).sort((d,y)=>d.path.localeCompare(y.path))[0];return i?wr(i):null},[Ie,x]),Rn=Me.length>1,Ta=a.useMemo(()=>[{root:null,label:o("rightSidebar.allRepositories"),count:Ie.size,branch:null,deferred:!1},...Me.map(t=>({root:t.root,label:t.label,count:t.deferred?Rs.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!Rs.has(t.root)}))],[Ie.size,Me,Rs,o]),Uc=Ta[Mh]??Ta[0],Ia=!!le,Hc=a.useMemo(()=>ff(Me,he),[Me,he]);a.useEffect(()=>{ni.current===x&&le&&!Hc.has(le)&&Ae(null),Ln(t=>t.filter(i=>Me.some(d=>d.root===i)))},[le,Me,Hc,x,Ae]),a.useEffect(()=>{le&&Pa(at.get(le))},[le,Pa,at]);const $h=a.useMemo(()=>{const t=new Set;me?.branch&&t.add(me.branch);for(const i of me?.branches??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===me?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0}))},[me?.branch,me?.branches,o]),zc=a.useMemo(()=>{const t=new Set;me?.upstreamRemote&&t.add(me.upstreamRemote);for(const i of me?.remotes??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===me?.upstreamRemote?o("rightSidebar.pushUpstreamBadge"):void 0}))},[me?.remotes,me?.upstreamRemote,o]),Wc=zc.length>1,Lh=a.useMemo(()=>{const t=[],i=new Set,d=(v,S)=>{!v||i.has(v)||(i.add(v),t.push({value:v,label:v,meta:S}))};d(me?.upstreamBranch,me?.upstreamBranch?o("rightSidebar.pushUpstreamBadge"):void 0),d(me?.branch,me?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of me?.branches??[])d(v,v===me?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");const y=me?.upstreamRemote;for(const v of me?.remoteBranches??[]){const S=v.indexOf("/"),j=S>=0?v.slice(0,S):null,ie=S>=0?v.slice(S+1):v;(!y||j===y)&&d(ie,"remote")}return t},[me?.branch,me?.branches,me?.remoteBranches,me?.upstreamBranch,me?.upstreamRemote,o]),Vt=a.useMemo(()=>_t.map(t=>{const i=at.get(t.value);return{root:t.value,label:t.label,branch:i?.context?.branch??null}}),[_t,at]);a.useEffect(()=>{Vt.length!==0&&(oa(t=>{let i=!1;const d={...t},y=new Set(Vt.map(v=>v.root));for(const v of Object.keys(d))y.has(v)||(delete d[v],i=!0);for(const v of Vt)!d[v.root]&&v.branch&&(d[v.root]=v.branch,i=!0);return i?d:t}),ia(t=>{let i=!1;const d={...t},y=new Set(Vt.map(v=>v.root));for(const v of Object.keys(d))y.has(v)||(delete d[v],i=!0);for(const v of Vt){const S=at.get(v.root)?.context;if(d[v.root]&&hf(d[v.root],S?.branch)&&(delete d[v.root],i=!0),d[v.root])continue;const j=hu(S);j&&(d[v.root]=j,i=!0)}return i?d:t}))},[Vt,at]);const Da=a.useMemo(()=>{const t=new Set(Vt.map(i=>i.root));return aa.filter(i=>t.has(i))},[aa,Vt]),Fa=Da.length===0,xr=a.useMemo(()=>Fa?Vt:Vt.filter(t=>Da.includes(t.root)),[Vt,Da,Fa]),Ns=a.useMemo(()=>xr.filter(t=>!!Et[t.root]?.trim()),[Et,xr]),Qn=a.useCallback((t,i)=>{const d=at.get(t)?.context?.branch;return!!(d&&i&&i.replace(/^refs\/heads\//,"")===d)},[at]),Gc=a.useMemo(()=>xr.filter(t=>!Et[t.root]?.trim()),[Et,xr]),Kc=a.useCallback(async t=>{if(!t||Zo.current.has(t))return;const i=at.get(t)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const d=x;Zo.current.add(t),Dl(y=>new Set(y).add(t));try{const y=await Ed(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!y.available||!Re(d))return;Ee(v=>v.map(S=>S.root===t?{...S,available:!0,context:{...S.context,...y},error:void 0}:S)),oa(v=>v[t]||!y.branch?v:{...v,[t]:y.branch}),ia(v=>{if(v[t])return v;const S=hu(y);return S?{...v,[t]:S}:v})}catch(y){yr(y)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,y)}finally{Zo.current.delete(t),Dl(y=>{const v=new Set(y);return v.delete(t),v})}},[at,Re,x]);a.useEffect(()=>{if(Ao)for(const t of xr)Kc(t.root)},[Ao,xr,Kc]),a.useEffect(()=>{!gi||!me||(fa(me.branch||(me.branches?.[0]??"")),ha(me.upstreamRemote||(me.remotes?.includes("origin")?"origin":me.remotes?.[0]??"")),ma(me.upstreamBranch||me.branch||(me.branches?.[0]??"")))},[me,gi]);const qc=a.useMemo(()=>{if(Je)return{text:o("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!jn||fn)return{text:o("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!me?.upstream)return{text:o("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=me.ahead??0,i=me.behind??0;return t>0&&i>0?{text:o("rightSidebar.pushDivergedCount",{ahead:t,behind:i}),className:"bg-destructive/10 text-destructive"}:t>0?{text:o("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:i>0?{text:o("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:o("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[me?.ahead,me?.behind,me?.upstream,jn,fn,Je,o]),Ah=a.useCallback(t=>{if(t&&!oe){const i=t.currentTarget.getBoundingClientRect();Pe({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else Pe(null);A?.()},[oe,A]),bi=a.useCallback(()=>{Pe(null),F?.()},[F]);function Vc(){if(!Rn)return null;const t=Uc?.label??o("rightSidebar.allRepositories"),i=Uc?.count??Ie.size,d=kt(t)||t;return e.jsxs("button",{type:"button",onClick:Ah,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 ${b?"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":b,title:t,children:[e.jsx(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:d}),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(Ys,{size:12,className:"shrink-0"})]})}function Ph(){if(!b||!Rn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(dt?.x??t-368,t-352)),y=Math.max(12,Math.min(dt?.y??80,i-420)),v=oe?void 0:{left:d,top:y},S=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${oe?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:bi,children:e.jsxs("div",{className:oe?"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:v,onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:oe?"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:oe?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:o("rightSidebar.repositories")}),!oe&&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:Ta.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Ie.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ie.size})]})]}),e.jsx("button",{type:"button",onClick:bi,className:oe?"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":o("rightSidebar.close"),children:e.jsx(Bt,{size:oe?16:14})})]}),e.jsx("div",{className:oe?"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:Ta.map(j=>{const ie=(j.root??null)===le,te=kt(j.label)||j.label;return e.jsxs("button",{type:"button",onClick:()=>{md(j.root),bi()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${oe?"px-3 py-2":"px-2 py-1.5"} ${ie?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:j.label,role:"option","aria-selected":ie,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${ie?"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 ${ie?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(vr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${oe?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:te}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:j.root===null?o("rightSidebar.allRepositories"):j.label})]}),j.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:j.branch}),j.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:o("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${j.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:j.count})]},j.root??"all")})})]})});return Qu(S,oe,document.body)}function Th(){return Ph()}function Yc(t){const i=pt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path),y=mo(d,i??x);return{key:wr(t),path:t.path,absolutePath:d,displayName:y.name,displayDir:y.dir,oldPath:t.oldPath,status:t.status,title:d}}function Xc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:o("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function _a(t,i){const d=Nn(t,x),y=`path:${d}`,v=ke===y,S=Qe===y,j=v||S;return e.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),Kt(d,y)},...di(Ma(d),y),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${j?"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"} ${j?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:o(S?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Jc(t){const i=pt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path),y=lm(t),v=Yi(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(mx,{actions:y,running:ze,completed:In?.path===v?In:null}),_a(d,o("rightSidebar.insertThisFile"))]})}function Qc(t,i){const d=i.root??x;if(!d)return null;const y=Nn(t,d);return _a(y,o("fileTree.insertRefTitle"))}function Es(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":o("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>ld("unified"),"aria-pressed":Cr==="unified",title:o("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>ld("split"),"aria-pressed":Cr==="split",title:o("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.split")})]})}function Zc(){return Ms.map(t=>{const i=ku(t.files.map(([,S])=>S)),d=dl({activeGitRepoRoot:le,groupCount:Ms.length,label:t.label,rootName:tt}),y=!!(d&&t.root&&We.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:y,files:t.files.map(([,S])=>Yc(S)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${y?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Qh(t.root),"aria-expanded":!y,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:y?e.jsx(Us,{size:13}):e.jsx(Ys,{size:13})}),e.jsx(vr,{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:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.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})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),Ga("stage-all",t.root,t.label)},disabled:!!ze,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:o("rightSidebar.stageAll"),children:o("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),Ga("stash-all",t.root,t.label)},disabled:!!ze,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:o("rightSidebar.stashAll"),children:o("rightSidebar.stashAll")})]})]}):null}})}const Cn=a.useMemo(()=>new Map(Array.from(Ie.values(),t=>[wr(t),t])),[Ie]);function ed(t){const i=Cn.get(t.key),d=i?pt(i,x):null,y=Wp(jt,d,i?.path??t.path);return e.jsx(al,{changeStatus:t.status,auditStatus:y,renderChangeBadge:v=>e.jsx(Gs,{status:v})})}const Ba=a.useCallback(t=>{if(oe)return null;const i=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const y=t.getBoundingClientRect().top+48;let v=null,S=Number.POSITIVE_INFINITY;for(const ie of i){const te=ie.getBoundingClientRect();if(te.bottom<y)continue;const be=Math.abs(te.top-y);be<S&&(v=ie,S=be)}const j=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return j?(Sa.current===j&&Y.getState().selectedFilePath===j||(Sa.current=j,st(j)),j):null},[oe,st]),Ih=!!(!ze&&Se&&!Je&&(me?.upstream||hn.trim()&&mn.trim())),Dh=!!(!ze&&Se&&!Je&&(me?.upstream||hn.trim()&&mn.trim())),Fh=!!(!ze&&Se&&!Je&&Fn.trim()&&Fn.trim()!==me?.branch),Yt=a.useMemo(()=>{const t=_e.trim().toLowerCase(),i=Array.from(Ie.entries()).filter(([,d])=>!le||pt(d,x)===le).sort(([d],[y])=>d.localeCompare(y));return t?i.filter(([d,y])=>`${d} ${y.path} ${y.status} ${y.repoRelativeRoot??""} ${y.repoName??""}`.toLowerCase().includes(t)):i},[le,Ie,_e,x]);a.useEffect(()=>{Os("selected_file_state",{selectedFilePath:nt,selectedChangedFilePath:qt?.path??null,selectedChangedFileAbsolutePath:qt?.absolutePath??null,selectedChangedFileRepoRoot:qt?.repoRoot??null,rootPath:x,activeGitRepoRoot:le,rightTab:Ko,effectiveRightTab:Gt,diffPaneActive:Mt,changedFiles:Ie.size,filteredChangedFiles:Yt.length,gitBundleLoading:pr,gitBundleLastLoadedAt:Hn})},[le,Ie.size,Mt,Gt,Yt.length,Hn,pr,Ko,x,qt?.absolutePath,qt?.path,qt?.repoRoot,nt]);const Ms=a.useMemo(()=>{const t=new Map;for(const i of Yt){const[,d]=i,y=pt(d,x),v=fx(d)||tt,S=y??v,j=y?at.get(y):void 0,ie=t.get(S)??{root:y,label:v,branch:j?.context?.branch,files:[]};ie.files.push(i),t.set(S,ie)}return Array.from(t.values()).sort((i,d)=>i.label===tt?-1:d.label===tt?1:i.label.localeCompare(d.label))},[Yt,at,tt,x]),$s=a.useMemo(()=>{const t=[],i=new Map;for(const d of Yt)i.set(wr(d[1]),d);for(const d of Ms){if(!!(d.root&&dl({activeGitRepoRoot:le,groupCount:Ms.length,label:d.label,rootName:tt})&&We.has(d.root)))continue;if(Ur!=="tree"){t.push(...d.files);continue}const v=d.files.map(([,S])=>Yc(S));for(const S of hp(v)){const j=i.get(S.key);j&&t.push(j)}}return t},[le,We,Ur,Ms,Yt,tt]),td=a.useMemo(()=>Ie.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:o("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:$s.map(([,t])=>{const i=pt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path);return{key:wr(t),path:t.path,absolutePath:d,status:t.status,repoRoot:i,displayName:mo(d,i).name,displayDir:mo(d,i).dir,auditRecords:jt}}),[jt,Ie.size,$s,x,o]);a.useEffect(()=>{if(!Mt||$s.length===0||oe)return;const t=[],i=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&Ba(d))return;const y=document.querySelector("[data-diff-stream-item]"),v=y?.dataset.diffSelectionPath??y?.dataset.diffStreamItem??null;if(v){Sa.current=v,st(v);return}const S=$s[0]?.[1];if(!S)return;const j=wr(S);Sa.current=j,st(j)};for(const d of[80,240,600,1200])t.push(window.setTimeout(i,d));return()=>t.forEach(d=>window.clearTimeout(d))},[Mt,oe,$s,st,Ba]);const xi=a.useMemo(()=>{const t=j=>`'${j.replace(/'/g,"'\\''")}'`,i=sr.length>0?vn:he.filter(j=>j.files.length>0),d=i.length>0?i:x?[{root:x,relativeRoot:".",name:tt}]:[],y=d.length>0?d.map(j=>`- ${j.relativeRoot==="."?".":j.relativeRoot} (${j.root})`).join(`
|
|
1662
|
+
`)||t.endsWith(" ")?t:`${t} `,i,d)},[Jn]),Mc=a.useRef(Dr);Mc.current=Dr;const fi=a.useRef(!0);a.useEffect(()=>(fi.current=!0,()=>{fi.current=!1}),[]);const hi=a.useRef(new Set),$c=a.useCallback((t,i,d)=>{if(hi.current.has(i))return;const w=Od.getState().activeSessionId;hi.current.add(i),Wp(t,i,d,{insert:Dr,upload:async(v,k)=>(await Ya("/tmp",[v],k)).files[0]?.path,isCurrent:()=>fi.current&&Mc.current===Dr&&w===Od.getState().activeSessionId}).finally(()=>hi.current.delete(i))},[Dr]),Fr=a.useCallback((t,i,d)=>{i&&Jn(i.endsWith(" ")?i:`${i} `,d??`context:${t}`,`
|
|
1663
|
+
`)},[Jn]),Lc=a.useCallback(t=>{const i=fg(ve,t);if(!i)return;const d=t&&ve.trim().includes(`
|
|
1664
|
+
`),w=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let v=!1;const k=te=>{v||(v=!0,window.removeEventListener("termdock-insert-reference-ack",j),window.clearTimeout(ie),te?(_r(!1),Xe(""),z&<(!0)):(_r(!0),lt(!1)))},j=te=>{const be=te.detail;be?.nonce===w&&k(be.ok===!0)},ie=window.setTimeout(()=>k(!1),1500);window.addEventListener("termdock-insert-reference-ack",j),_r(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:i,focus:!0,paste:d,nonce:w}}))},[z,ve]),tt=a.useMemo(()=>x?kt(x):o("rightSidebar.workspace"),[x,o]),jh=a.useMemo(()=>kt(ce)||tt,[ce,tt]),La=a.useMemo(()=>io(ce),[ce]),Pa=a.useMemo(()=>x?Zl[x]??[]:[],[Zl,x]),wn=a.useMemo(()=>new Set(Pa.map(t=>t.path)),[Pa]),Rs=!!(ce&&wn.has(ce)),mi=!!(x&&ce&&ce!==x),Rh=!!(x&&Bn&&Bn!==x),_t=ce?`path:${ce}`:null,Pc="context:change-audit",Nh=a.useCallback(()=>{La&&Ht(La)},[La,Ht]),Ac=a.useCallback(()=>{rc()},[rc]),Ch=a.useCallback(()=>{ce&&(Un(ce,!0),ac())},[ac,ce,Un]),Eh=a.useCallback(()=>{!ce||!mi||(Rs?pn(ce):On(ce,"directory"))},[mi,ce,Rs,On,pn]),Tc=a.useCallback(t=>{Ht(t),V("")},[Ht]),Ic=a.useCallback(t=>{ce&&(me(Zg(ce,t)),W(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ce,W]),Dc=a.useCallback(t=>{!x||t===x||(wn.has(t)?pn(t):On(t,"directory"))},[On,wn,x,pn]),Fc=a.useCallback(t=>{!x||!t||(wn.has(t)?pn(t):On(t,"file"))},[On,wn,x,pn]),_c=Y(t=>t.expandedPaths),pi=a.useMemo(()=>{const t=new Set;if(Tr&&ce){t.add(ce);const i=`${ce.replace(/\/+$/,"")}/`;for(const d of _c)d.startsWith(i)&&t.add(d)}if(Tr&&x&&nt){const i=nt.startsWith("/")?nt:`${x}/${nt}`,d=io(i);d&&t.add(d)}return ng(t).join(`
|
|
1665
|
+
`)},[_c,Tr,ce,x,nt]),kn=a.useRef(new Map);a.useEffect(()=>{const t=pi?pi.split(`
|
|
1666
|
+
`):[];if(!r||t.length===0){_n(null);return}const i=new AbortController;let d=!1,w=0,v=0;_n(null);const k=async()=>{let j=0;for(;!d&&!i.signal.aborted;){let ie=null;try{_n(null),await Um(t,be=>{const{applicableEvents:Ce,unavailableReason:Ve}=ag(be);Ce.length>0&&nc(Ce);const X=new Set(Ce.filter(q=>q.type==="rescan-required").map(q=>q.path));if(ya)for(const q of Ce){if(q.type==="created"||q.type==="updated"){const ge=io(q.path);ge&&X.add(ge)}q.path.endsWith("/.gitignore")&&ce&&Un(ce,!0)}for(const q of X){const ge={path:q},$e=Y.getState();if(!$e.directoryCache.has(ge.path))continue;kn.current.get(ge.path)?.abort();const Be=new AbortController;kn.current.set(ge.path,Be);const Cd=`file-watch-rescan:${ge.path}`;Nt(Cd),Mu(ge.path,Be.signal,$e.showHiddenFiles,"watch_rescan",Cd,$e.fileSortModes[ge.path]??"name",ce??void 0).then(As=>{kn.current.get(ge.path)===Be&&sc(ge.path,As.entries)}).catch(As=>{wr(As)||_n(As instanceof Error?As.message:"File refresh unavailable")}).finally(()=>{kn.current.get(ge.path)===Be&&kn.current.delete(ge.path)})}Ve&&_n(Ve)},i.signal),ie=new Error("File watch stream ended")}catch(be){ie=be}if(d||i.signal.aborted||wr(ie))return;_n(ie instanceof Error?ie.message:"File watching unavailable");const te=lu[Math.min(j,lu.length-1)];j+=1,await new Promise(be=>{v=window.setTimeout(be,te)})}};return w=window.setTimeout(()=>{d||k()},Ui),()=>{d=!0,window.clearTimeout(w),window.clearTimeout(v),i.abort();for(const j of kn.current.values())j.abort();kn.current.clear()}},[nc,r,sc,pi,ce,ya,Un]),a.useEffect(()=>{if(!x||ei.current!==x)return;if(ti.current===x){ti.current=null;return}const t=hu();Ws(lf,{...t,[x]:{selectedRepoRoots:aa,repoTargetBranches:rr,repoBaseBranches:Et,previewEntries:rn,selectedPreviewKey:xe&&ur?qe:null,selectedPreviewFileKey:xe&&ur?Do:null,previewDetailOpen:!!(xe&&ur),previewScrollTops:hs,previewMobileSlideIndex:1,repoIncludeUncommitted:ln,updatedAt:Date.now()}},eb)},[ur,ln,xe,rn,hs,Et,rr,aa,x,Do,qe]);const ft=a.useMemo(()=>Nu(Ie.values()),[Ie]),at=a.useMemo(()=>{const t=new Map;for(const i of fe)t.set(i.root,i);return t},[fe]),Ns=a.useMemo(()=>{const t=new Map;for(const i of fe)i.deferred||t.set(i.root,i.files.length);return t},[fe]),Aa=a.useCallback(t=>{if(t){if(!t.deferred){ws.current.delete(t.root);return}Ns.has(t.root)||ws.current.has(t.root)||(ws.current.add(t.root),Ft(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(i=>{i||ws.current.delete(t.root)}))}},[Ft,Ns]),ar=a.useMemo(()=>le?Me.find(t=>t.root===le)??null:null,[le,Me]),qt=a.useMemo(()=>nt?Array.from(Ie.values()).find(t=>t.path===nt||t.absolutePath===nt)??null:null,[Ie,nt]),Bt=a.useMemo(()=>{const t=new Map;for(const i of fe)i.available&&i.context?.available&&t.set(i.root,i);return t.size===0&&N?.available&&N.root&&t.set(N.root,{id:N.root,root:N.root,relativeRoot:".",name:tt,depth:0,nested:!1,available:!0,files:Array.from(Ie.values()).filter(i=>bt(i,x)===N.root),context:N}),Array.from(t.values()).sort((i,d)=>i.root===x?-1:d.root===x?1:(i.relativeRoot||i.name).localeCompare(d.relativeRoot||d.name)).map(i=>{const d=i.relativeRoot==="."?tt:i.relativeRoot||i.name||kt(i.root),w=Ru(i.files),v=i.files.length;return{value:i.root,label:d,meta:[i.context?.branch,v>0?o("rightSidebar.repoChangedCount",{count:v}):null,w>0?o("rightSidebar.repoStagedCount",{count:w}):null].filter(Boolean).join(" · ")}})},[Ie,N,fe,tt,x,o]),Se=a.useMemo(()=>le&&Bt.some(t=>t.value===le)?le:qt?.repoRoot&&Bt.some(t=>t.value===qt.repoRoot)?qt.repoRoot:Bt.length===1||Bt.length>1?Bt[0].value:null,[le,Bt,qt?.repoRoot]),Bc=Se?at.get(Se)??null:null,he=Bc?.context?.available?Bc.context:Se===N?.root?N:null,Je=Bt.length>0&&!Se,Oc=a.useMemo(()=>Je?[]:Se?Array.from(Ie.values()).filter(t=>bt(t,x)===Se):Array.from(Ie.values()),[Se,Ie,Je,x]),Sn=a.useMemo(()=>Nu(Oc),[Oc]),gi=!!(he?.available&&he.root&&Se&&he.root===Se),Mh=Se?Bt.find(t=>t.value===Se)?.label??kt(Se):o("rightSidebar.gitRepositoryPlaceholder"),Uc=gi?he?.branch??"HEAD":Je?o("rightSidebar.selectRepositoryForGitActions"):fn?o("rightSidebar.gitActionRunning"):"HEAD",jn=!!(he?.available&&he.root===Se&&he.status);a.useEffect(()=>{Dl.current={count:Z.length,loading:Ut,loadingMore:na,hasMore:Lo}},[Z.length,Lo,Ut,na]),a.useEffect(()=>{Wr.current+=1,mr.current?.abort(),Nt("right-sidebar-recent-commits"),mr.current=null,hr(""),He([]),Er(!1),gs(!1),An(null),Tn(!1)},[Se]);const Cs=a.useCallback(async(t={})=>{if(!x||!Se||Je)return;const i=t.reset??!1,d=Dl.current,w=i?0:d.count;if(!i&&(d.loading||d.loadingMore||!d.hasMore))return;const v=Wr.current+1;Wr.current=v,mr.current?.abort(),Nt("right-sidebar-recent-commits");const k=new AbortController;mr.current=k,i?Er(!0):gs(!0),An(null);try{const j=await Im({cwd:x,repoRoot:Se,limit:ub,skip:w,query:an.trim(),requestSlotId:"right-sidebar-recent-commits"},k.signal);if(Wr.current!==v)return;if(!j.available){An(j.error??"Recent commits are unavailable"),i&&He([]),Tn(!1);return}Mo(ie=>i?j.commitSyncStatus??{}:{...ie,...j.commitSyncStatus}),He(ie=>i?j.commits:[...ie,...j.commits]),Tn(j.hasMore)}catch(j){if(Wr.current!==v||wr(j))return;An(j instanceof Error?j.message:"Failed to load recent commits"),i&&He([]),Tn(!1)}finally{mr.current===k&&(mr.current=null),Wr.current===v&&(Er(!1),gs(!1))}},[Se,an,Je,x]);a.useEffect(()=>{zr&&Cs({reset:!0})},[an,Cs,zr,he?.ahead,he?.behind,he?.upstream]);const $h=a.useCallback(t=>{const i=t.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||Cs({reset:!1})},[Cs]);a.useEffect(()=>{!Se||!N?.available||!ot||!nr||jn||fn||Je||ai(Se)},[Se,N?.available,jn,fn,ot,nr,ai,Je]);const Hc=r&&(Mt||ot);a.useEffect(()=>{!Hc||!x||br()},[Hc,br,x]),a.useEffect(()=>{!r||!ot||!nr||!bs||!x||Ra(null)},[bs,ot,nr,r,Ra,x]);const Lh=a.useMemo(()=>{if(!le)return 0;const t=Me.findIndex(i=>i.root===le);return t>=0?t+1:0},[le,Me]),zc=a.useCallback(t=>{if(!t)return null;const i=Array.from(Ie.values()).filter(d=>bt(d,x)===t).sort((d,w)=>d.path.localeCompare(w.path))[0];return i?yr(i):null},[Ie,x]),Rn=Me.length>1,Ta=a.useMemo(()=>[{root:null,label:o("rightSidebar.allRepositories"),count:Ie.size,branch:null,deferred:!1},...Me.map(t=>({root:t.root,label:t.label,count:t.deferred?Ns.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!Ns.has(t.root)}))],[Ie.size,Me,Ns,o]),Wc=Ta[Lh]??Ta[0],Ia=!!le,Gc=a.useMemo(()=>pf(Me,fe),[Me,fe]);a.useEffect(()=>{ni.current===x&&le&&!Gc.has(le)&&Pe(null),Ln(t=>t.filter(i=>Me.some(d=>d.root===i)))},[le,Me,Gc,x,Pe]),a.useEffect(()=>{le&&Aa(at.get(le))},[le,Aa,at]);const Ph=a.useMemo(()=>{const t=new Set;he?.branch&&t.add(he.branch);for(const i of he?.branches??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===he?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0}))},[he?.branch,he?.branches,o]),Kc=a.useMemo(()=>{const t=new Set;he?.upstreamRemote&&t.add(he.upstreamRemote);for(const i of he?.remotes??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===he?.upstreamRemote?o("rightSidebar.pushUpstreamBadge"):void 0}))},[he?.remotes,he?.upstreamRemote,o]),qc=Kc.length>1,Ah=a.useMemo(()=>{const t=[],i=new Set,d=(v,k)=>{!v||i.has(v)||(i.add(v),t.push({value:v,label:v,meta:k}))};d(he?.upstreamBranch,he?.upstreamBranch?o("rightSidebar.pushUpstreamBadge"):void 0),d(he?.branch,he?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of he?.branches??[])d(v,v===he?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");const w=he?.upstreamRemote;for(const v of he?.remoteBranches??[]){const k=v.indexOf("/"),j=k>=0?v.slice(0,k):null,ie=k>=0?v.slice(k+1):v;(!w||j===w)&&d(ie,"remote")}return t},[he?.branch,he?.branches,he?.remoteBranches,he?.upstreamBranch,he?.upstreamRemote,o]),Vt=a.useMemo(()=>Bt.map(t=>{const i=at.get(t.value);return{root:t.value,label:t.label,branch:i?.context?.branch??null}}),[Bt,at]);a.useEffect(()=>{Vt.length!==0&&(oa(t=>{let i=!1;const d={...t},w=new Set(Vt.map(v=>v.root));for(const v of Object.keys(d))w.has(v)||(delete d[v],i=!0);for(const v of Vt)!d[v.root]&&v.branch&&(d[v.root]=v.branch,i=!0);return i?d:t}),ia(t=>{let i=!1;const d={...t},w=new Set(Vt.map(v=>v.root));for(const v of Object.keys(d))w.has(v)||(delete d[v],i=!0);for(const v of Vt){const k=at.get(v.root)?.context;if(d[v.root]&&gf(d[v.root],k?.branch)&&(delete d[v.root],i=!0),d[v.root])continue;const j=gu(k);j&&(d[v.root]=j,i=!0)}return i?d:t}))},[Vt,at]);const Da=a.useMemo(()=>{const t=new Set(Vt.map(i=>i.root));return aa.filter(i=>t.has(i))},[aa,Vt]),Fa=Da.length===0,xr=a.useMemo(()=>Fa?Vt:Vt.filter(t=>Da.includes(t.root)),[Vt,Da,Fa]),Es=a.useMemo(()=>xr.filter(t=>!!Et[t.root]?.trim()),[Et,xr]),Qn=a.useCallback((t,i)=>{const d=at.get(t)?.context?.branch;return!!(d&&i&&i.replace(/^refs\/heads\//,"")===d)},[at]),Vc=a.useMemo(()=>xr.filter(t=>!Et[t.root]?.trim()),[Et,xr]),Yc=a.useCallback(async t=>{if(!t||Zo.current.has(t))return;const i=at.get(t)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const d=x;Zo.current.add(t),Bl(w=>new Set(w).add(t));try{const w=await Ld(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!w.available||!Re(d))return;Ee(v=>v.map(k=>k.root===t?{...k,available:!0,context:{...k.context,...w},error:void 0}:k)),oa(v=>v[t]||!w.branch?v:{...v,[t]:w.branch}),ia(v=>{if(v[t])return v;const k=gu(w);return k?{...v,[t]:k}:v})}catch(w){wr(w)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,w)}finally{Zo.current.delete(t),Bl(w=>{const v=new Set(w);return v.delete(t),v})}},[at,Re,x]);a.useEffect(()=>{if(Po)for(const t of xr)Yc(t.root)},[Po,xr,Yc]),a.useEffect(()=>{!gi||!he||(fa(he.branch||(he.branches?.[0]??"")),ha(he.upstreamRemote||(he.remotes?.includes("origin")?"origin":he.remotes?.[0]??"")),ma(he.upstreamBranch||he.branch||(he.branches?.[0]??"")))},[he,gi]);const Xc=a.useMemo(()=>{if(Je)return{text:o("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!jn||fn)return{text:o("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!he?.upstream)return{text:o("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=he.ahead??0,i=he.behind??0;return t>0&&i>0?{text:o("rightSidebar.pushDivergedCount",{ahead:t,behind:i}),className:"bg-destructive/10 text-destructive"}:t>0?{text:o("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:i>0?{text:o("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:o("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[he?.ahead,he?.behind,he?.upstream,jn,fn,Je,o]),Th=a.useCallback(t=>{if(t&&!oe){const i=t.currentTarget.getBoundingClientRect();Ae({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else Ae(null);T?.()},[oe,T]),bi=a.useCallback(()=>{Ae(null),I?.()},[I]);function Jc(){if(!Rn)return null;const t=Wc?.label??o("rightSidebar.allRepositories"),i=Wc?.count??Ie.size,d=kt(t)||t;return e.jsxs("button",{type:"button",onClick:Th,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 ${b?"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":b,title:t,children:[e.jsx(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:d}),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(Ys,{size:12,className:"shrink-0"})]})}function Ih(){if(!b||!Rn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(dt?.x??t-368,t-352)),w=Math.max(12,Math.min(dt?.y??80,i-420)),v=oe?void 0:{left:d,top:w},k=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${oe?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:bi,children:e.jsxs("div",{className:oe?"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:v,onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:oe?"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:oe?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:o("rightSidebar.repositories")}),!oe&&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:Ta.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Ie.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ie.size})]})]}),e.jsx("button",{type:"button",onClick:bi,className:oe?"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":o("rightSidebar.close"),children:e.jsx(Pt,{size:oe?16:14})})]}),e.jsx("div",{className:oe?"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:Ta.map(j=>{const ie=(j.root??null)===le,te=kt(j.label)||j.label;return e.jsxs("button",{type:"button",onClick:()=>{bd(j.root),bi()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${oe?"px-3 py-2":"px-2 py-1.5"} ${ie?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:j.label,role:"option","aria-selected":ie,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${ie?"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 ${ie?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(vr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${oe?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:te}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:j.root===null?o("rightSidebar.allRepositories"):j.label})]}),j.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:j.branch}),j.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:o("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${j.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:j.count})]},j.root??"all")})})]})});return tf(k,oe,document.body)}function Dh(){return Ih()}function Qc(t){const i=bt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=mo(d,i??x);return{key:yr(t),path:t.path,absolutePath:d,displayName:w.name,displayDir:w.dir,oldPath:t.oldPath,status:t.status,title:d}}function Zc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:o("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function _a(t,i){const d=Cn(t,x),w=`path:${d}`,v=ke===w,k=Qe===w,j=v||k;return e.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),Kt(d,w)},...di(Ma(d),w),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${j?"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"} ${j?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:o(k?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function ed(t){const i=bt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=dm(t),v=Yi(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(gx,{actions:w,running:ze,completed:In?.path===v?In:null}),_a(d,o("rightSidebar.insertThisFile"))]})}function td(t,i){const d=i.root??x;if(!d)return null;const w=Cn(t,d);return _a(w,o("fileTree.insertRefTitle"))}function Ms(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":o("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>ud("unified"),"aria-pressed":Nr==="unified",title:o("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Nr==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>ud("split"),"aria-pressed":Nr==="split",title:o("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Nr==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.split")})]})}function rd(){return $s.map(t=>{const i=Ru(t.files.map(([,k])=>k)),d=ul({activeGitRepoRoot:le,groupCount:$s.length,label:t.label,rootName:tt}),w=!!(d&&t.root&&We.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:w,files:t.files.map(([,k])=>Qc(k)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${w?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>em(t.root),"aria-expanded":!w,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:w?e.jsx(ns,{size:13}):e.jsx(Ys,{size:13})}),e.jsx(vr,{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:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.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})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ga("stage-all",t.root,t.label)},disabled:!!ze,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:o("rightSidebar.stageAll"),children:o("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ga("stash-all",t.root,t.label)},disabled:!!ze,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:o("rightSidebar.stashAll"),children:o("rightSidebar.stashAll")})]})]}):null}})}const Nn=a.useMemo(()=>new Map(Array.from(Ie.values(),t=>[yr(t),t])),[Ie]);function nd(t){const i=Nn.get(t.key),d=i?bt(i,x):null,w=Kp(jt,d,i?.path??t.path);return e.jsx(ol,{changeStatus:t.status,auditStatus:w,renderChangeBadge:v=>e.jsx(Gs,{status:v})})}const Ba=a.useCallback(t=>{if(oe)return null;const i=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const w=t.getBoundingClientRect().top+48;let v=null,k=Number.POSITIVE_INFINITY;for(const ie of i){const te=ie.getBoundingClientRect();if(te.bottom<w)continue;const be=Math.abs(te.top-w);be<k&&(v=ie,k=be)}const j=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return j?(Sa.current===j&&Y.getState().selectedFilePath===j||(Sa.current=j,st(j)),j):null},[oe,st]),Fh=!!(!ze&&Se&&!Je&&(he?.upstream||hn.trim()&&mn.trim())),_h=!!(!ze&&Se&&!Je&&(he?.upstream||hn.trim()&&mn.trim())),Bh=!!(!ze&&Se&&!Je&&Fn.trim()&&Fn.trim()!==he?.branch),Yt=a.useMemo(()=>{const t=_e.trim().toLowerCase(),i=Array.from(Ie.entries()).filter(([,d])=>!le||bt(d,x)===le).sort(([d],[w])=>d.localeCompare(w));return t?i.filter(([d,w])=>`${d} ${w.path} ${w.status} ${w.repoRelativeRoot??""} ${w.repoName??""}`.toLowerCase().includes(t)):i},[le,Ie,_e,x]);a.useEffect(()=>{Us("selected_file_state",{selectedFilePath:nt,selectedChangedFilePath:qt?.path??null,selectedChangedFileAbsolutePath:qt?.absolutePath??null,selectedChangedFileRepoRoot:qt?.repoRoot??null,rootPath:x,activeGitRepoRoot:le,rightTab:Ko,effectiveRightTab:Gt,diffPaneActive:Mt,changedFiles:Ie.size,filteredChangedFiles:Yt.length,gitBundleLoading:pr,gitBundleLastLoadedAt:Hn})},[le,Ie.size,Mt,Gt,Yt.length,Hn,pr,Ko,x,qt?.absolutePath,qt?.path,qt?.repoRoot,nt]);const $s=a.useMemo(()=>{const t=new Map;for(const i of Yt){const[,d]=i,w=bt(d,x),v=mx(d)||tt,k=w??v,j=w?at.get(w):void 0,ie=t.get(k)??{root:w,label:v,branch:j?.context?.branch,files:[]};ie.files.push(i),t.set(k,ie)}return Array.from(t.values()).sort((i,d)=>i.label===tt?-1:d.label===tt?1:i.label.localeCompare(d.label))},[Yt,at,tt,x]),Ls=a.useMemo(()=>{const t=[],i=new Map;for(const d of Yt)i.set(yr(d[1]),d);for(const d of $s){if(!!(d.root&&ul({activeGitRepoRoot:le,groupCount:$s.length,label:d.label,rootName:tt})&&We.has(d.root)))continue;if(Ur!=="tree"){t.push(...d.files);continue}const v=d.files.map(([,k])=>Qc(k));for(const k of mp(v)){const j=i.get(k.key);j&&t.push(j)}}return t},[le,We,Ur,$s,Yt,tt]),sd=a.useMemo(()=>Ie.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:o("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:Ls.map(([,t])=>{const i=bt(t,x),d=t.absolutePath||(i?`${i}/${t.path}`:t.path);return{key:yr(t),path:t.path,absolutePath:d,status:t.status,repoRoot:i,displayName:mo(d,i).name,displayDir:mo(d,i).dir,auditRecords:jt}}),[jt,Ie.size,Ls,x,o]);a.useEffect(()=>{if(!Mt||Ls.length===0||oe)return;const t=[],i=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&Ba(d))return;const w=document.querySelector("[data-diff-stream-item]"),v=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;if(v){Sa.current=v,st(v);return}const k=Ls[0]?.[1];if(!k)return;const j=yr(k);Sa.current=j,st(j)};for(const d of[80,240,600,1200])t.push(window.setTimeout(i,d));return()=>t.forEach(d=>window.clearTimeout(d))},[Mt,oe,Ls,st,Ba]);const xi=a.useMemo(()=>{const t=j=>`'${j.replace(/'/g,"'\\''")}'`,i=sr.length>0?vn:fe.filter(j=>j.files.length>0),d=i.length>0?i:x?[{root:x,relativeRoot:".",name:tt}]:[],w=d.length>0?d.map(j=>`- ${j.relativeRoot==="."?".":j.relativeRoot} (${j.root})`).join(`
|
|
1671
1667
|
`):`- ${x?".":""}`,v=d.length>0?d.map(j=>` td audit-export ${t(j.root)}`).join(`
|
|
1672
|
-
`):" td audit-export",
|
|
1673
|
-
`)},[sr.length,vn,
|
|
1674
|
-
`);it("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:sr,mode:t,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Fr(o("rightSidebar.insertChangeAuditPrompt"),i,`${
|
|
1675
|
-
`))
|
|
1676
|
-
`):`- ${x?".":""}`,
|
|
1668
|
+
`):" td audit-export",k=d.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${x??""}`,"目标仓库:",w,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",v,"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 后批量注入:",k,'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
|
+
`)},[sr.length,vn,fe,tt,x]),Oh=a.useCallback((t="generate")=>{if(Rn&&Zt.length===0&&!le){Qr(!0);return}const i=t==="generate"?xi:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",xi].join(`
|
|
1670
|
+
`);it("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:sr,mode:t,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Fr(o("rightSidebar.insertChangeAuditPrompt"),i,`${Pc}:${t}`),br(),c||l()},[le,xi,Zt.length,sr,Fr,br,l,c,x,Rn,o]),Oa=a.useCallback(async t=>{try{await Ad({ids:[t]}),Xr(i=>i.filter(d=>d.id!==t))}catch{br()}},[br]),Uh=a.useCallback(async()=>{if(jt.length===0)return;const t=jt.map(i=>i.id);try{await Ad({ids:t}),Xr(i=>i.filter(d=>!t.includes(d.id))),Qt(null)}catch(i){const d=i instanceof Error?i.message:"Failed to clear change audit explanations";Qt(o("rightSidebar.changeAuditClearFailed",{message:d})),br()}},[jt,br,o]),Hh=a.useCallback(async t=>{if(t.records.length===0)return;const i=t.records.map(d=>d.id);try{await Dm({ids:i}),Zr(d=>d.filter(w=>!i.includes(w.id))),qe===t.key&&(cn(null),fr(!1))}catch(d){yt(o("rightSidebar.branchAuditClearFailed",{message:d instanceof Error?d.message:"Failed to clear branch explanation"})),Ra(null)}},[Ra,qe,o]),zh=a.useCallback(t=>{Ln(i=>t===null?(Qr(!1),[]):i.includes(t)?i.filter(d=>d!==t):[...i,t])},[]),Wh=a.useCallback(t=>{To(i=>t===null?(Ao(!1),[]):i.includes(t)?i.filter(d=>d!==t):[...i,t])},[]),vi=a.useMemo(()=>{if(!nr)return[];const t=i=>{const d=i.diff??"";let w=0,v=0;for(const k of d.split(`
|
|
1671
|
+
`))k.startsWith("+++")||k.startsWith("---")||(k.startsWith("+")&&(w+=1),k.startsWith("-")&&(v+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:w,deletions:v,diff:d}};return xe?(xe.hunks??[]).map(i=>{const d=xe.comparisonRepos&&xe.comparisonRepos.length>1?[...xe.comparisonRepos].sort((v,k)=>k.label.length-v.label.length).find(v=>i.filePath.startsWith(`${v.label}/`)):void 0,w=dr.find(v=>v.repoRoot===xe.repoRoot&&v.baseRef===xe.baseRef&&(v.branchName??null)===(xe.currentBranch??null)&&v.filePath===i.filePath&&v.hunkHeader===i.hunkHeader&&(v.hunkIndex??0)===i.hunkIndex&&v.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,repoRoot:d?.repoRoot??xe.repoRoot,repositoryPath:d?i.filePath.slice(d.label.length+1):i.filePath,hunk:i.previewRevert&&!Qn(i.previewRevert.cwd,i.previewRevert.comparisonBranch)?{...i,previewRevert:void 0}:i,current:w,stale:null}}):qe?dr.filter(i=>mu(i)===qe).map(i=>{const d=t(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:d,current:i,stale:null}}):[]},[xe,dr,Qn,nr,qe]),yi=dr.length>0,Zn=a.useMemo(()=>{if(!nr)return[];const t=new Map;for(const i of dr){const d=i.repoRoot,w=at.get(d),v=w?.relativeRoot==="."?tt:w?.relativeRoot||w?.name||kt(d),k=mu(i),j=t.get(k)??{key:k,repoRoot:d,repoLabel:v,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};j.records.push(i),j.latestInjectedAt=Math.max(j.latestInjectedAt,i.injectedAt??0),t.set(k,j)}return Array.from(t.values()).sort((i,d)=>d.latestInjectedAt-i.latestInjectedAt)},[dr,at,nr,tt]),wi=a.useMemo(()=>qe?Zn.find(t=>t.key===qe)??null:null,[Zn,qe]),Ps=xe?{repoRoot:xe.repoRoot??"",repoLabel:xe.repoRoot?at.get(xe.repoRoot)?.relativeRoot==="."?tt:at.get(xe.repoRoot)?.relativeRoot||at.get(xe.repoRoot)?.name||kt(xe.repoRoot):tt,baseRef:xe.baseRef??xe.baseBranch??"",branchName:xe.currentBranch??null,headRef:xe.headRef??null,diffFingerprint:xe.diffFingerprint??null}:wi,Gh=a.useMemo(()=>(Oe?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,repoRoot:Oe?.repoRoot,hunk:t,current:null,stale:null})),[Oe?.hunks,Oe?.repoRoot]),Kh=a.useMemo(()=>{if(xe)return[];const t=wi;return t?en.filter(i=>i.repoRoot===t.repoRoot&&i.baseRef===t.baseRef&&(i.branchName??null)===t.branchName&&(!t.diffFingerprint||i.diffFingerprint===t.diffFingerprint)):[]},[xe,en,wi]),qh=a.useCallback(t=>{const i=vi.find(d=>d.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${d.hunk.filePath}`===t.filePath:!1));i&&(dn(i.key),window.setTimeout(()=>En(t),90),window.setTimeout(()=>En(t),320),window.setTimeout(()=>En(t),760))},[vi]),ki=a.useMemo(()=>{const t=v=>`'${v.replace(/'/g,"'\\''")}'`,i=Es,d=i.length>0?i.map(v=>`- ${v.label} (${v.root}),目标分支:${rr[v.root]||v.branch||"(current branch)"},基线分支:${Et[v.root]||"(not set)"},包含本地未提交更改:${Qn(v.root,rr[v.root]||v.branch)&&(ln[v.root]??!0)?"是":"否"}`).join(`
|
|
1672
|
+
`):`- ${x?".":""}`,w=i.length>0?i.map(v=>{const k=rr[v.root]||v.branch||"",j=Et[v.root]||"",ie=v.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[k?` git -C ${t(v.root)} switch ${t(k)}`:` # ${v.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(j)} ${t(v.root)} > ~/.termdock/branch-audit/branch-audit-export-${ie}.json`].join(`
|
|
1677
1673
|
`)}).join(`
|
|
1678
|
-
`):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${x??""}`,"每个仓库分别遵循下面列出的本地未提交更改选项。","目标仓库:",d,"","操作指令:","1. 只针对上面列出的目标仓库导出分支 hunk,按各仓库所选目标分支与基线对比。本地未提交更改标记为是的仓库纳入 staged/unstaged/untracked 改动;标记为否的仓库只解释提交改动,忽略导出中混入的本地改动。嵌套子仓或软链接子仓使用括号内的仓库绝对路径。示例:",
|
|
1679
|
-
`)},[ln,Qn,
|
|
1680
|
-
`);Fr(o("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${t}`),c||l()},[ki,Fr,l,c,o]),Si=a.useCallback(async(t={})=>{const i=t.refresh===!0,d=i&&xe?.comparisonRepos?xe.comparisonRepos:
|
|
1681
|
-
`),files:j.flatMap((X,
|
|
1682
|
-
`),truncated:j.some(X=>X.truncated)};if(te.comparisonRepos=d.map((X,V)=>({...X,head:X.head??j[V].currentBranch??null,includeUncommitted:j[V].includeUncommitted===!0,canIncludeUncommitted:j[V].canIncludeUncommitted})),te.canIncludeUncommitted=j.every(X=>X.canIncludeUncommitted===!0),te.includeUncommitted=j.some(X=>X.includeUncommitted===!0),Io(X=>({...X,...Object.fromEntries(te.comparisonRepos.map(V=>[V.repoRoot,V.includeUncommitted??!1]))})),!i&&(te.hunks??[]).length===0){Fe(o("rightSidebar.branchAuditDiffEmpty"));return}const be=Date.now(),Ne=(i?qe:null)??["preview",te.repoRoot??x,te.baseRef??te.baseBranch??"",te.currentBranch??"",te.headRef??"",te.diffFingerprint??be].join("\0"),Ve=d.length===1?d[0].label:`${d.length} repos`;er(te),An(X=>[{key:Ne,diff:te,repoLabel:Ve,createdAt:be},...X.filter(V=>V.key!==Ne)].slice(0,8)),i||nn(X=>X[Ne]===void 0?X:{...X,[Ne]:0}),cn(Ne),dn(X=>{const V=te.hunks?.[0],ge=V?`${V.filePath}\0${V.hunkHeader}\0${V.hunkIndex}`:null;return i&&X&&(te.hunks??[]).some($e=>$e.filePath===X.split("\0")[0])?X:ge}),fr(!0)}catch(j){if(!S()||yr(j))return;Fe(j instanceof Error?j.message:"Failed to load branch diff")}finally{S()&&ye(!1)}},[ln,xe,qe,Ns,Et,rr,Re,x,o]),qh=a.useCallback(t=>{++It.current,ye(!1),er(t.diff),Fe(null),cn(t.key),dn(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),fr(!0)},[]),Vh=a.useCallback(t=>{An(i=>i.filter(d=>d.key!==t)),nn(i=>{if(!(t in i))return i;const d={...i};return delete d[t],d}),qe===t&&(cn(null),er(null),fr(!1))},[qe]),Yh=a.useCallback(t=>{++It.current,ye(!1);const i=Zn.find(d=>d.key===t);i&&(er(null),Fe(null),cn(t),dn(i.records[0]?.filePath??null),fr(!0))},[Zn]),Xh=a.useCallback(async t=>{if(!x||!Se)return;const[i]=t.split(/\s+/);if(i){xt(i),tr(null),Ue(null);try{const d=await Im({cwd:x,repoRoot:Se,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){tr(d.error??"Commit diff is unavailable");return}Ue(d);const y=d.hunks?.[0];sa(y?`${y.filePath}\0${y.hunkHeader}\0${y.hunkIndex}`:null)}catch(d){tr(d instanceof Error?d.message:"Failed to load commit diff")}finally{xt(null)}}},[Se,x]),Jh=a.useCallback(t=>{if(!xe||!qe)return;const i=Math.max(0,Math.round(t));nn(d=>Math.abs((d[qe]??0)-i)<24?d:{...d,[qe]:i})},[xe,qe]);a.useEffect(()=>{!xe||!qe||An(t=>t.map(i=>i.key===qe&&i.diff!==xe?{...i,diff:xe}:i))},[xe,qe]);const rd=!!xe;a.useEffect(()=>{if(!oe||!ur||!rd)return;const t=hc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const i=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(i)},[ur,rd,oe]);const nd=a.useCallback(t=>{t&&ch(i=>mp(i,t))},[]),sd=ba.key===nt?ba.key:null,Ua=a.useCallback(t=>{const i=Y.getState(),d=Rx();Os("select_diff_file",{interactionId:d,path:t,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:le,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),st(t),Lr("diff"),oe&&t&&gc(1),nd(t),queueMicrotask(()=>{const y=Y.getState();Os("select_diff_file_after",{interactionId:d,requestedPath:t,selectedFilePath:y.selectedFilePath,rootPath:y.rootPath,rightTab:y.rightTab,changedFiles:y.changedFiles.size,activeGitRepoRoot:le})})},[le,oe,nd,st,Lr,gc]),ad=a.useCallback(t=>{const i=Array.from(Ie.values()).find(d=>{const y=pt(d,x),v=wr(d);return d.path===t.filePath||v===t.filePath||d.absolutePath===t.filePath||(y?`${y}/${d.path}`===t.filePath:!1)||t.repoRoot&&y===t.repoRoot&&d.path===t.filePath});if(i){Ua(wr(i)),window.setTimeout(()=>En(t),90),window.setTimeout(()=>En(t),320),window.setTimeout(()=>En(t),760);return}En(t)},[Ie,x,Ua]),od=a.useCallback(({slideToDetail:t,fullscreen:i,toggleFullscreen:d}={})=>ls.length>0?e.jsx(Du,{walkthroughs:ls,repoRoot:le,fullscreen:i,onToggleFullscreen:d,onNavigate:y=>{oe&&window.requestAnimationFrame(()=>t?.()),ad(y)}}):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(Js,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),o("rightSidebar.changeWalkthroughEmpty")]}),[le,ls,ad,oe,o]),Qh=a.useCallback(t=>{t&&lr(i=>{const d=new Set(i);return d.has(t)?d.delete(t):d.add(t),Hi(_i,d),d})},[]),id=a.useCallback(t=>{Or(i=>{const d=new Set(i);return d.has(t)?d.delete(t):d.add(t),Hi(tu,d),d})},[]),Ha=a.useCallback(t=>{Rr(t),Lt(ef,t)},[]);a.useEffect(()=>{Ia||Ur!=="ai"||Ha("tree")},[Ur,Ha,Ia]);const za=a.useCallback(()=>{ra(t=>{const i=!t;return Lt(tf,i),i})},[]),ld=a.useCallback(t=>{os(t),Lt(rf,t)},[]),{whitespace:cd,context:dd}=gp(),ud=a.useMemo(()=>({algorithm:"histogram",whitespace:cd,context:dd}),[cd,dd]),fd=a.useCallback(t=>{J(t),Lt(nf,t)},[]),Wa=a.useCallback(async(t,i,d,y)=>{let v=t;for(;v.ok&&v.status==="running";)await new Promise(j=>window.setTimeout(j,1500)),v=await Ad({jobId:v.jobId,cwd:i.cwd,action:i.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const S={action:i.action,path:y,label:d};return xs(S),window.setTimeout(()=>xs(j=>j?.action===S.action&&j.path===S.path?null:j),1400),v},[]),yt=a.useCallback(async(t,i,d)=>{const y=x;x&&gr.current.delete(x),wt(null),xs(null),bs({action:t.action,path:d});try{const v=await Dm({...t,includeNested:Ds(x)}),S=await Wa(v,t,i,d);if(!Re(y))return!1;const j=x?await Ai(x,void 0,{includeNested:Ds(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:_s(x)}).catch(()=>S.bundle):S.bundle;return Re(y)?(j&&qn(j,{reloadDiff:!0,cacheOnly:!0}),un(null),!0):!1}catch(v){return xs(null),wt(o("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{Re(y)&&bs(null)}},[qn,Re,x,o,Wa]),hd=a.useCallback(async t=>{const i=x;await Pd({...t,includeNested:Ds(x)}),Re(i)&&Dt(x??void 0,{refresh:!0,background:!0})},[Re,Dt,x]),Zh=a.useCallback(async t=>{const i=xe,d=It.current,y=i?.hunks?.find(S=>S.previewRevert?.cwd===t.cwd&&S.previewRevert.path===t.path);if(!i||!y||!t.comparisonBase)throw new Error(o("diffViewer.hunkActionUnavailable"));K(S=>S+1),Fe(null);try{await Pd(t)}catch(S){throw K(j=>j-1),S}if(d!==It.current||!Re(x)){K(S=>S-1);return}const v=S=>{er(j=>{if(!j||d!==It.current)return j;const ie=j.hunks??[],te=S===void 0?ie.filter(Ne=>!(Ne.previewRevert?.cwd===t.cwd&&Ne.previewRevert.patch===t.patch)):[...ie.filter(Ne=>Ne.filePath!==y.filePath),...S];return{...j,hunks:te}})};v(),Ld({cwd:t.cwd,repoRoot:t.cwd,base:t.comparisonBase,comparisonBase:t.comparisonBase,filePath:t.path,requestSlotId:`branch-preview-file:${t.cwd}:${t.path}`}).then(S=>{if(d!==It.current||!Re(x))return;if(!S.available||S.truncated)throw new Error(S.error??o("diffViewer.hunkActionUnavailable"));const j=t.path.slice(t.cwd.length+1),ie=y.filePath.slice(0,y.filePath.length-j.length);v((S.hunks??[]).map(te=>({...te,filePath:`${ie}${te.filePath}`,oldPath:te.oldPath?`${ie}${te.oldPath}`:te.oldPath,newPath:te.newPath?`${ie}${te.newPath}`:te.newPath})))}).catch(S=>{d===It.current&&Re(x)&&!yr(S)&&Fe(`${o("diffViewer.hunkActionReverted")} · ${S instanceof Error?S.message:String(S)}`)}).finally(()=>K(S=>S-1))},[xe,Re,x,o]),Ga=a.useCallback((t,i,d)=>{if(i){if(t==="stage-all"){yt({action:"stage-all",cwd:i},o("rightSidebar.stageAll"),`repo:${i}`);return}un({kind:"stash-all",repoRoot:i,repoLabel:d})}},[yt,o]),md=a.useCallback(t=>{Ae(t),fa(""),ha(""),ma(""),st(Oc(t)),ot||Lr("diff"),t&&Pa(at.get(t))},[Pa,Oc,ot,at,st,Ae,Lr]),pd=a.useCallback(t=>{const i=new Set([...Wt.current.keys(),...bn.current,...gr.current]);for(const d of i)d!==t&&(zt.current.delete(d),Wt.current.get(d)?.abort(),Wt.current.delete(d),Ct(`right-sidebar-git-untracked:${d}`),bn.current.delete(d),gr.current.delete(d))},[]),em=a.useCallback(async t=>{const i=x;if(!i||(await Y.getState().setNestedGitScanRoot(i,t),!Re(i)))return;if(t){await Dt(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}pd(i),fa(""),ha(""),ma(""),To(y=>y.filter(v=>v===i));const d=qt;d&&pt(d,i)!==i&&st(null),await Dt(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[pd,Re,Dt,x,st,qt]),tm=a.useCallback(async()=>{if(!Se||Je){wt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=Fn.trim();!t||t===me?.branch||await yt({action:"switch-branch",cwd:Se,branch:t},o("rightSidebar.switchBranch"))},[me?.branch,Se,Je,yt,Fn,o]),gd=a.useCallback(async()=>{if(!Se||Je){wt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=ua.trim();if(!t)return;await yt({action:"commit",cwd:Se,message:t},o("rightSidebar.commitChanges"))&&zl("")},[Se,ua,Je,yt,o]),rm=a.useCallback(async()=>{if(!Se||Je){wt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await yt({action:"push",cwd:Se,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pushChanges"))},[Se,mn,hn,Je,yt,o]),nm=a.useCallback(async()=>{if(!Se||Je){wt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await yt({action:"pull",cwd:Se,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pullChanges"))},[Se,mn,hn,Je,yt,o]);a.useEffect(()=>{if(!ot||!Se||ze)return;let t=!1;const i={push:o("rightSidebar.pushChanges"),pull:o("rightSidebar.pullChanges"),commit:o("rightSidebar.commitChanges"),"switch-branch":o("rightSidebar.switchBranch"),"stage-all":o("rightSidebar.stageAll"),"stash-all":o("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const y=await Ad({cwd:Se,action:d}).catch(()=>null);if(!y?.ok||y.status!=="running")continue;const v={action:d,cwd:Se},S=i[d]??d;bs({action:d});try{const j=await Wa(y,v,S);if(t||!Re(x))return;const ie=x?await Ai(x,void 0,{includeNested:Ds(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:_s(x)}).catch(()=>j.bundle):j.bundle;ie&&qn(ie,{reloadDiff:!0,cacheOnly:!0})}catch(j){t||wt(o("rightSidebar.gitActionFailed",{message:j instanceof Error?j.message:"Unknown error"}))}finally{t||bs(null)}return}})(),()=>{t=!0}},[Se,qn,ot,Re,x,ze,o,Wa]);const ji=In?.action==="commit",Ri=In?.action==="switch-branch",Ci=In?.action==="pull",Ni=In?.action==="push",Ka=ot||ih,Ei=Fa?o("rightSidebar.changeAuditScopeAll"):xr.length===1?xr[0].label:`${xr.length} repos`,sm=xr.length>0,bd=Ns.length>0,am=x?e.jsx(vu,{open:Ao,onOpenChange:Po,showScopePicker:!0,selectedAll:Fa,repos:Vt,selectedRoots:Da,onToggleRepo:Hh,onGenerate:()=>Kh(wi?"regenerate":"generate"),disabled:!sm,generateDisabled:!bd,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:o(wi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.branchAuditGenerateTitle"),ariaLabel:o("rightSidebar.branchAuditShort"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Ei,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o(wi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Si()},secondaryDisabled:!bd||de,secondaryLabel:o("rightSidebar.branchAuditViewDiff"),secondaryTitle:o("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:de,loading:Il.size>0,statusTitle:Il.size>0?o("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:Gc.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:o("rightSidebar.missingBaseReposSkipped",{repositories:Gc.map(t=>t.label).join(O==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const i=at.get(t.root),d=Qn(t.root,rr[t.root]||i?.context?.branch),y=[],v=new Set,S=(be,Ne)=>{!be||v.has(be)||(v.add(be),y.push({value:be,label:be,meta:Ne}))};S(rr[t.root]||i?.context?.branch,o("rightSidebar.pushCurrentBranchBadge"));for(const be of i?.context?.branches??[])S(be,be===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):o("rightSidebar.localBranch"));for(const be of i?.context?.remoteBranches??[])S(be,o("rightSidebar.remoteBranch"));const j=[],ie=new Set,te=(be,Ne)=>{!be||ie.has(be)||(ie.add(be),j.push({value:be,label:be,meta:Ne}))};te(Et[t.root],Et[t.root]?o("rightSidebar.pushUpstreamBadge"):void 0),te(i?.context?.upstream,i?.context?.upstream?o("rightSidebar.pushUpstreamBadge"):void 0);for(const be of i?.context?.remoteBranches??[])te(be,"remote");for(const be of i?.context?.branches??[])te(be,be===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(rs,{label:o("rightSidebar.currentBranchLabel"),value:rr[t.root]||i?.context?.branch||"",options:y,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),onChange:be=>{oa(Ne=>({...Ne,[t.root]:be}))}}),e.jsx(rs,{label:o("rightSidebar.branchAuditBaseLabel"),value:Et[t.root]||"",options:j,placeholder:o("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:o("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:o("rightSidebar.branchAuditBaseEmpty"),onChange:be=>{ia(Ne=>({...Ne,[t.root]:be}))}}),e.jsxs("label",{className:"sm:col-span-2 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:o("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:o(d?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:d&&(ln[t.root]??!0),disabled:!d,onChange:be=>Io(Ne=>({...Ne,[t.root]:be.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,xd=Bs(jt.reduce((t,i)=>Math.max(t,i.injectedAt??0),0),O),om=()=>x?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Tl(t=>{const i=!t;return Lt(Bi,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":gs,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(Js,{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:o("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Ei})]}),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 ${gs?"rotate-90":""}`,children:e.jsx(Us,{size:13})})]}),gs&&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:[o("rightSidebar.changeAuditScopeLabel"),": ",Ei]}),am]}),Ze&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Ze}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[rn.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${qe===t.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:()=>qh(t),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:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.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:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:o("rightSidebar.branchAuditViewDiff")})]}),Bs(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Bs(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>Vh(t.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:o("common.delete"),"aria-label":o("common.delete"),children:e.jsx(co,{size:12})})]},t.key)),Zn.length>0?Zn.slice(0,Math.max(0,8-rn.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${qe===t.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:()=>Yh(t.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:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.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:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),Bs(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:o("rightSidebar.branchAuditGeneratedAt",{time:Bs(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Oh(t)},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:o("rightSidebar.branchAuditClearTitle"),"aria-label":o("rightSidebar.branchAuditClearTitle"),children:e.jsx(co,{size:12})})]},t.key)):rn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,im=()=>nr&&x&&jn?e.jsxs("div",{className:Ka?"overflow-visible":"overflow-hidden",children:[om(),e.jsxs("button",{type:"button",onClick:()=>{ot||lh(t=>{const i=!t;return i&&Se&&!jn&&!fn&&ai(Se),i})},"aria-expanded":Ka,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${ot?"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(vr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${Sn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[fn&&e.jsx(gt,{size:10,className:"animate-spin"}),Sn.staged>0?o("rightSidebar.stagedCount",{count:Sn.staged}):o("rightSidebar.noStagedChangesShort")]}),!ot&&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 ${Ka?"rotate-90":""}`,children:e.jsx(Us,{size:13})})]})]}),Ka&&e.jsxs("div",{className:"space-y-0",children:[_t.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Nh})]})}),e.jsx(rs,{label:o("rightSidebar.gitRepositoryLabel"),value:Se??"",options:_t,placeholder:o("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:o("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:o("rightSidebar.gitRepositoryEmpty"),disabled:!!ze,onChange:t=>{md(t||null)}}),Je&&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:o("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Fn!==_c?_c:null})]}),e.jsxs("button",{type:"button",onClick:()=>{tm()},disabled:!Fh,className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ri?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.switchBranch"),children:[e.jsx("span",{className:ze?.action==="switch-branch"||Ri?"opacity-0":"",children:o("rightSidebar.switchBranch")}),ze?.action==="switch-branch"&&e.jsx(gt,{size:12,className:"absolute animate-spin"}),Ri&&ze?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(rs,{label:o("rightSidebar.currentBranchLabel"),value:Fn,options:$h,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),disabled:!!ze,onChange:fa})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Je?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged>0?o("rightSidebar.commitReadyHint",{count:Sn.staged}):o("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{gd()},disabled:!!ze||Je||Sn.staged===0||!ua.trim(),className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition active:scale-95 ${ji?"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:Je?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged===0?o("rightSidebar.commitNeedsStaged"):o("rightSidebar.commitChanges"),children:[e.jsx("span",{className:ze?.action==="commit"||ji?"opacity-0":"",children:o("rightSidebar.commitChanges")}),ze?.action==="commit"&&e.jsx(gt,{size:12,className:"absolute animate-spin"}),ji&&ze?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:ua,onChange:t=>zl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),gd())},placeholder:o("rightSidebar.commitMessagePlaceholder"),disabled:!!ze,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>hs(t=>!t),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":zr,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:o("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Ut&&e.jsx(gt,{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 ${zr?"rotate-90":""}`,children:e.jsx(Us,{size:13})})]})]}),zr&&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(ns,{size:12,className:"shrink-0"}),e.jsx("input",{value:ms,onChange:t=>hr(t.target.value),placeholder:o("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}),ms&&e.jsx("button",{type:"button",onClick:()=>hr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Bt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Eh,children:[Z.length>0?Z.map(t=>{const[i,...d]=t.split(/\s+/),y=d.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{Xh(t)},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:y,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:y,children:y}),on[i]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${on[i]==="ahead"?"bg-accent/10 text-accent":on[i]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:o(on[i]==="ahead"?"rightSidebar.commitAhead":on[i]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),mt===i&&e.jsx(gt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):Ut?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:o("common.loading")}):$o?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.recentCommitsEmpty")}),na&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(gt,{size:12,className:"animate-spin"})}),Lo&&!na&&Z.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:o("rightSidebar.recentCommitsLoadMore")})]})]}),sn&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:sn}),$o&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:$o})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{nm()},disabled:!Ih,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ci?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pullChanges"),children:[e.jsx("span",{className:ze?.action==="pull"||Ci?"opacity-0":"",children:o("rightSidebar.pullChanges")}),ze?.action==="pull"&&e.jsx(gt,{size:12,className:"absolute animate-spin"}),Ci&&ze?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{rm()},disabled:!Dh,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ni?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pushChanges"),children:[e.jsx("span",{className:ze?.action==="push"||Ni?"opacity-0":"",children:o("rightSidebar.pushChanges")}),ze?.action==="push"&&e.jsx(gt,{size:12,className:"absolute animate-spin"}),Ni&&ze?.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] ${qc.className}`,title:me?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:qc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:me?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${Wc?"grid-cols-2":"grid-cols-1"}`,children:[Wc&&e.jsx(rs,{label:o("rightSidebar.pushRemoteLabel"),value:hn,options:zc,placeholder:o("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:o("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:o("rightSidebar.pushNoRemotes"),disabled:!!ze,onChange:ha}),e.jsx(rs,{label:o("rightSidebar.pushBranchLabel"),value:mn,options:Lh,placeholder:o("rightSidebar.pushBranchPlaceholder",{branch:me?.branch??"HEAD"}),searchPlaceholder:o("rightSidebar.pushBranchSearchPlaceholder"),emptyText:o("rightSidebar.pushNoBranches"),disabled:!!ze,onChange:ma})]})]})]})]}):null,lm=a.useCallback(t=>{const i=pt(t,x);if(!i)return[];const d=Yi(t),y=[];return t.canStage&&y.push({key:"stage-file",label:o("rightSidebar.stageFile"),onClick:()=>{yt({action:"stage-file",cwd:i,paths:[t.path]},o("rightSidebar.stageFile"),d)}}),t.canUnstage&&y.push({key:"unstage-file",label:o("rightSidebar.unstageFile"),onClick:()=>{yt({action:"unstage-file",cwd:i,paths:[t.path]},o("rightSidebar.unstageFile"),d)}}),t.canStash&&y.push({key:"stash-file",label:o("rightSidebar.stashFile"),onClick:()=>{yt({action:"stash-file",cwd:i,paths:[t.path]},o("rightSidebar.stashFile"),d)}}),t.canRestoreWorktree&&y.push({key:"restore-worktree-file",label:o("rightSidebar.restoreFile"),destructive:!0,onClick:()=>un({kind:"restore",file:t,phrase:""})}),y},[x,yt,o]),cm=a.useCallback(()=>{if(p){k?.();return}$r(0),Pr.current?.slideTo(0),Mr(!1),St(null)},[k,p]),vd=a.useCallback(t=>{if(W(""),Ht(t),st(null),St(null),q(null),oe){p&&k?.(),$r(0),Pr.current?.slideTo(0),Mr(!1);return}},[oe,k,p,st,Ht]);a.useEffect(()=>{const t=i=>{const d=i.detail,y=d?.path;if(typeof y!="string"||!y.startsWith("/"))return;W(""),St(null),Jt(null);const v=!!(x&&(y===x||y.startsWith(`${x}/`)));if(d.kind==="file"){const S=io(y);ks(y),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Jt(d.line),Ht(v?null:S),q(j=>({path:y,nonce:(j?.nonce??0)+1}));return}st(null),v?(Ht(null),q(S=>({path:y,nonce:(S?.nonce??0)+1}))):(q(null),Ht(y)),oe&&(p&&k?.(),$r(0),Pr.current?.slideTo(0),Mr(!1))};return window.addEventListener(_d,t),()=>window.removeEventListener(_d,t)},[ks,oe,k,p,x,st,Ht]),a.useEffect(()=>{r||(Pt(!1),Xt(!1))},[r]),a.useEffect(()=>{if(!At&&!Sr)return;const t=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&(Mn.current?.contains(i.target)||ta.current?.contains(i.target))||(Pt(!1),Xt(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[Sr,At]);const wd=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:jh,disabled:!La,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":o("rightSidebar.parentFolder"),title:o("rightSidebar.parentFolder"),children:e.jsx(Lu,{size:14})}),e.jsx("button",{type:"button",onClick:$c,disabled:!x||Bn===x,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":o("rightSidebar.backToProjectRoot"),title:o("rightSidebar.backToProjectRoot"),children:e.jsx(Bd,{size:14})}),e.jsx("button",{type:"button",onClick:Rh,disabled:!ce,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":o("rightSidebar.refreshFiles"),title:Wl?o("rightSidebar.fileWatchUnavailable",{message:Wl}):o("rightSidebar.refreshFiles"),children:e.jsx(uo,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ce??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:kh}),ya==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:o("fileTree.sortedByModified"),"aria-label":o("fileTree.sortedByModified"),children:e.jsx(Od,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ce&&Kt(ce,Ft??void 0),disabled:!ce,...ce&&Ft?di(Ma(ce),Ft):{},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 ${Ft&&(ke===Ft||Qe===Ft)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":o(Ft&&Qe===Ft?"rightSidebar.copied":Ft&&ke===Ft?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:o("rightSidebar.insertCurrentFolder"),children:Ft&&(ke===Ft||Qe===Ft)?e.jsx(go,{size:13}):e.jsx(bo,{size:13})}),e.jsx(Bp,{rootPath:ce,disabled:!ce||!fh||Jo,pressed:wa,saving:Jo,onToggle:()=>{if(!ce||Jo)return;const t=ce;ic(!0),Qo(null),hh(t,!wa).catch(()=>{const i=Y.getState();(i.explorerRoot??i.rootPath)===t&&Qo(o("rightSidebar.gitIgnoreSaveFailed"))}).finally(()=>ic(!1))}}),e.jsxs("div",{ref:ta,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Pt(!1),Xt(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${Sr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":Sr,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(po,{size:14})}),Sr&&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:()=>{Xt(!1),Ch()},disabled:!mi,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${js?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[js?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(js?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Xt(!1),dh()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${qo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[qo?e.jsx(kp,{size:14}):e.jsx(nl,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(qo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ce,onClick:()=>{ce&&(Xt(!1),uh(ce,ya==="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:[ya==="modified"?e.jsx(sp,{size:14}):e.jsx(Od,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(ya==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),lc&&e.jsx("p",{role:"alert",className:"px-1 py-1 text-[11px] text-destructive",children:lc}),x&&(Aa.length>0||Sh)&&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:o("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:$c,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-md px-2 py-0.5 font-medium transition active:scale-95 ${ce===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(Bd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:tt})]}),Aa.map(t=>{const i=t.path,d=t.kind==="file",y=d?nt===i:ce===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${y?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>d?ks(i):Ht(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(sl,{size:10,className:"shrink-0"}):e.jsx(Xa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:kt(i)})]}),e.jsx("button",{type:"button",onClick:()=>pn(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.unpinFolder",{name:kt(i)}),title:o("rightSidebar.unpinFolder",{name:kt(i)}),children:e.jsx(Bt,{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"})]}),Mi=a.useMemo(()=>{if(Dn===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((Uo-Dn)/1e3)),d=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[y,v]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return d.format(y,v)},[Uo,Dn]),qa="flex min-h-10 w-full items-center gap-2.5 rounded-md px-2.5 text-left text-[12px] text-foreground transition hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:min-h-11",yd=x&&!Yn?e.jsxs("button",{type:"button",role:"menuitemcheckbox",tabIndex:-1,onClick:()=>{em(!Vo)},"aria-checked":Vo,title:o("rightSidebar.multiRepoScanTitle"),className:qa,children:[e.jsx(vr,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1",children:o("rightSidebar.multiRepoScan")}),Vo&&e.jsx(go,{size:14,className:"shrink-0 text-primary"})]}):null,kd=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Mi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:o("rightSidebar.gitLastUpdated",{time:Mi}),children:Mi}):null,e.jsx("button",{type:"button",onClick:()=>{Vn()},disabled:pr,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":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),children:e.jsx(uo,{size:13,className:pr?"animate-spin":""})})]}):null,dm=pc?o("rightSidebar.changeAuditScopeAll"):vn.length===1?vn[0].relativeRoot==="."?tt:vn[0].relativeRoot||vn[0].name:`${vn.length} repos`,um=t=>x?e.jsxs("div",{role:"none",children:[e.jsx(vu,{menuItem:!0,open:us,onOpenChange:i=>{Qr(i),i&&t()},showScopePicker:Rn,selectedAll:pc,repos:mh,selectedRoots:sr,onToggleRepo:Uh,onGenerate:()=>{t(),_h()},disabled:!x,inserted:ke===Mc,buttonLabel:o("rightSidebar.changeAuditShort"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:o("rightSidebar.insertChangeAuditPrompt"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:dm,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o("rightSidebar.changeAuditShort"),loading:ds,error:!!Jr,statusTitle:Jr??(ds?o("rightSidebar.changeAuditLoading"):jt.length>0?`${o("rightSidebar.changeAuditLoaded",{count:jt.length})}${xd?` · ${o("rightSidebar.changeAuditLoadedAt",{time:xd})}`:""}`:void 0)}),jt.length>0&&e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Bh()},disabled:ds||jt.length===0,className:qa,title:o("rightSidebar.clearChangeAuditTitle"),"aria-label":o("rightSidebar.clearChangeAudit"),children:[e.jsx(co,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.clearChangeAudit")})]})]}):null,es=ar??(R?.available&&x&&Ie.size>0&&he.length<=1?{root:x,label:tt}:null),Sd=t=>e.jsxs(e.Fragment,{children:[es&&e.jsxs("div",{role:"group","aria-label":o("rightSidebar.gitQuickActions"),children:[e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Ga("stage-all",es.root,es.label)},disabled:!!ze,className:qa,children:[e.jsx(Um,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stageAll")]}),e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Ga("stash-all",es.root,es.label)},disabled:!!ze,className:qa,children:[e.jsx(xp,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stashAll")]})]}),es&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),um(t),yd&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),yd]}),Va=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[R?.available&&R.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:R.branch,children:[e.jsx(vr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:R.branch})]}),ft.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[ft.modified,"M"]}),ft.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",ft.added]}),ft.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",ft.deleted]}),ft.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ft.renamed,"R"]}),ft.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ft.copied,"C"]}),ft.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ft.untracked,"U"]}),ft.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[ft.conflicted,"!"]}),ft.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ft.other,"?"]}),ft.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:o("rightSidebar.stagedCountShort",{count:ft.staged})})]});return e.jsxs(ap,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:f,push:c,pinned:h,children:[di.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${bh?"hidden":""}`,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:x??void 0,children:tt}),(!oe||_o)&&R?.available&&R.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:R.branch,children:[e.jsx(vr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:R.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!fe;G(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):W("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${fe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleSearch"),title:o("common.search"),children:e.jsx(ns,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Te,onClick:()=>{et(t=>!t),lt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Te?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleContextDraft"),title:o("rightSidebar.contextDraftTitle"),children:[e.jsx(op,{size:14}),!Te&&ve.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:Vl,type:"file",multiple:!0,className:"hidden",onChange:t=>{const i=t.target.files;!i||i.length===0||(Ss(Array.from(i)),t.target.value="")}}),e.jsx("input",{ref:Yl,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const i=t.target.files?.[0];t.target.value="",i&&vh(i)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14})}),e.jsxs("div",{ref:Mn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Xt(!1),Pt(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${At?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":At,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(po,{size:15})}),At&&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:"menuitemcheckbox","aria-checked":Gr,onClick:()=>xc(!Gr),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2",children:[e.jsx(Td,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:o("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Gr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Gr?"left-3.5":"left-0.5"}`})})]}),e.jsx("div",{className:"my-1 h-px bg-border/15",role:"separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),Vl.current?.click()},disabled:pa,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:[pa?e.jsx(gt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Tp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),Yl.current?.click()},disabled:pa,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:[pa?e.jsx(gt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Ep,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&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":o("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:o("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",o("rightSidebar.layoutModeAuto")],["narrow",o("rightSidebar.layoutModeNarrow")],["wide",o("rightSidebar.layoutModeWide")]].map(([t,i])=>{const d=ee===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{P(t),Pt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${d?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,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":o("rightSidebar.close"),children:e.jsx(Bt,{size:14})})]}),fe&&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(ns,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:H,onChange:t=>W(t.target.value),placeholder:o(_==="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 ${oe?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>fd("name"),"aria-pressed":_==="name",className:`rounded-full px-2 transition active:scale-95 ${oe?"py-1":"py-0.5"} ${_==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>fd("content"),"aria-pressed":_==="content",className:`rounded-full px-2 transition active:scale-95 ${oe?"py-1":"py-0.5"} ${_==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeContent")})]}),H&&e.jsx("button",{type:"button",onClick:()=>W(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Bt,{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(ip,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:o("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:ue,onChange:t=>pe(t.target.value),onKeyDown:t=>{t.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:o("rightSidebar.searchScopePlaceholder"),"aria-label":o("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ue!=="."&&e.jsx("button",{type:"button",onClick:()=>pe("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.resetSearchScope"),children:e.jsx(Bt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>$(t=>!t),"aria-expanded":Ce,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${Ce||vs.length>0||Q||Le||De?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:o("rightSidebar.searchOptions"),"aria-label":o("rightSidebar.searchOptions"),children:[e.jsx(lp,{size:13}),vs.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:vs.length})]})]}),Ce&&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:o("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:we,onChange:t=>je(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchExcludePlaceholder"),"aria-label":o("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),we&&e.jsx("button",{type:"button",onClick:()=>je(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.clearSearchExclude"),children:e.jsx(Bt,{size:11})})]}),_==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":o("rightSidebar.contentSearchOptions"),children:[[Q,()=>ne(t=>!t),wp,o("rightSidebar.matchCase")],[Le,()=>Ye(t=>!t),Dp,o("rightSidebar.matchWholeWord")],[De,()=>rt(t=>!t),$p,o("rightSidebar.useRegex")]].map(([t,i,d,y])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),y]},y))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Yn?2:3)+(Gr?1:0)}, minmax(0, 1fr))`},children:[!Yn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:t=>Ca("git",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(vr,{size:12}),o("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:t=>Ca("diff",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(zu,{size:12}),o("rightSidebar.tabChanges"),Ie.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Ie.size}):null]})]}),e.jsxs("button",{type:"button",onClick:t=>Ca("files",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(fp,{size:12}),o("rightSidebar.tabFiles")]}),Gr&&e.jsxs("button",{type:"button",onClick:t=>Ca("android",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Td,{size:12}),o("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),Ul&&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:Ul})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ja,{active:ot,mounted:nr,fallback:e.jsx(Ki,{slow:!1}),children:()=>Oe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(qd,{items:zh,diffViewType:zo,inlineMode:cr,viewControls:h?Es():void 0,renderPathReference:(t,i)=>_a(Nn(t,Oe.repoRoot??x),o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:eh,onSelect:sa,emptyText:o("rightSidebar.noChanges"),mobile:oe,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o("rightSidebar.recentCommitsTitle"),headerMeta:`${Oe.headRef??""}${Oe.commits?.[0]?` · ${Oe.commits[0]}`:""}`,onClose:()=>{Ue(null),sa(null)},closeLabel:o("common.back"),wrap:Tt,onToggleWrap:za,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:oe?"stacked":"split",onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa})}):ur?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(qd,{items:vi,diffViewType:zo,inlineMode:cr,viewControls:h?Es():void 0,renderPathReference:(t,i)=>{const d=xe?.comparisonRepos,y=d&&d.length>1?[...d].sort((S,j)=>j.label.length-S.label.length).find(S=>t===S.label||t.startsWith(`${S.label}/`)):void 0,v=y?t===y.label?y.repoRoot:Nn(t.slice(y.label.length+1),y.repoRoot):Nn(t,Ls?.repoRoot||x);return _a(v,o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:Do,onSelect:dn,emptyText:o(xe?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:oe,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o(xe?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Ls?`${Ls.repoLabel} · ${Ls.branchName??"HEAD"} → ${Ls.baseRef}`:void 0,onClose:()=>{++It.current,ye(!1),fr(!1),er(null)},closeLabel:o("common.back"),wrap:Tt,onToggleWrap:za,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:oe?"stacked":"split",onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,localOptions:xe?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??xe.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??Qn(t.repoRoot,t.head)),onChange:i=>{Si({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:i})}})),onHunkGitAction:xe?.includeUncommitted?Zh:void 0,error:Ze,actionsBusy:I>0,onRefresh:()=>{Si({refresh:!0})},refreshing:de,refreshLabel:o("rightSidebar.branchAuditRefreshDiff"),refreshTitle:o("rightSidebar.branchAuditRefreshDiff"),walkthroughs:Wh,onWalkthroughNavigate:Gh,initialDetailScrollTop:xe&&qe?fs[qe]:void 0,onDetailScrollPositionChange:Jh,externalSwiperRef:oe?hc:void 0,onMobileSlideChange:oe?Fo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:nr&&x&&jn?e.jsx("div",{className:"px-3",children:im()}):pr?e.jsx(Ki,{slow:nc}):gn?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):ju(R)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):R?.available===!1?e.jsx(oo,{message:R.error??o("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{Vn()}}):x?e.jsx(Ki,{slow:nc}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ja,{active:Tr,mounted:rh||Tr,children:()=>oe?e.jsxs(Pu,{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:t=>{Pr.current=t,t.slideTo(Fl,0)},onSlideChange:t=>{if($r(t.activeIndex),ys.current===t.activeIndex){ys.current=null;return}t.activeIndex===0&&(Mr(!1),St(null),k?.())},children:[e.jsx(Zi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:zn,onScroll:vc,onDragOver:Na,onDragEnter:Na,onDragLeave:kc,onDrop:Sc,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[Gl&&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:o("rightSidebar.dropToUpload")})}),!H.trim()&&wd,e.jsx(Ud,{rootPath:ce??"",onFileSelect:ks,onPathReference:Kt,getReferenceText:Ma,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onDirectoryRoot:Lc,onSearchFromDirectory:Ac,onDirectoryPinToggle:Pc,onFilePinToggle:Tc,pinnedPaths:yn,selectedFilePath:nt,query:_e,searchRootPath:cc,searchOptions:dc,searchMode:_,onContentMatchSelect:wc,onDirectoryDropFiles:(t,i)=>Ss(i,t),revealDirectory:N,canOpenInFileBrowser:Kl,onOpenInFileBrowser:yc})]})}),e.jsx(Zi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(vl,{filePath:th||Fl===1?nt:null,active:Tr,onInsertReference:Kt,onInsertText:Dr,onInsertFeature:Dr,onReviewReference:Nc,onReferenceCopied:Ir,onClose:cm,onDirectoryLinkOpen:vd,isMobile:!0,lineRange:jr,onLineRangeChange:St,insertedReferenceKey:ke,copiedReferenceKey:Qe,scrollToLine:$n,onScrollToLineHandled:()=>Jt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:D,onOpenMarkdownOutline:C,onCloseMarkdownOutline:E,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:L,onCloseMarkdownImageLightbox:w})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:zn,onScroll:vc,onDragOver:Na,onDragEnter:Na,onDragLeave:kc,onDrop:Sc,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Wo},children:[Gl&&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:o("rightSidebar.dropToUpload")})}),!H.trim()&&wd,e.jsx(Ud,{rootPath:ce??"",onFileSelect:ks,onPathReference:Kt,getReferenceText:Ma,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onDirectoryRoot:Lc,onSearchFromDirectory:Ac,onDirectoryPinToggle:Pc,onFilePinToggle:Tc,pinnedPaths:yn,selectedFilePath:nt,query:_e,searchRootPath:cc,searchOptions:dc,searchMode:_,onContentMatchSelect:wc,onDirectoryDropFiles:(t,i)=>Ss(i,t),revealDirectory:N,canOpenInFileBrowser:Kl,onOpenInFileBrowser:yc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":o("rightSidebar.resizeFileTree"),title:o("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:ph,onPointerMove:gh,onPointerUp:bc,onPointerCancel:bc,onDoubleClick:()=>{Go(cl),Lt(Hs,cl)},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(vl,{filePath:nt,active:Tr,onInsertReference:Kt,onInsertText:Dr,onInsertFeature:Dr,onReviewReference:Nc,onReferenceCopied:Ir,onDirectoryLinkOpen:vd,isMobile:!1,lineRange:jr,onLineRangeChange:St,insertedReferenceKey:ke,copiedReferenceKey:Qe,scrollToLine:$n,onScrollToLineHandled:()=>Jt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:D,onOpenMarkdownOutline:C,onCloseMarkdownOutline:E,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:L,onCloseMarkdownImageLightbox:w})})]})}),e.jsx(Ja,{active:Mt,mounted:sh||Mt,children:()=>oi?e.jsx(cp,{}):oe?e.jsx(el,{mobile:!0,backLabel:o("rightSidebar.backToChangeList"),externalSwiperRef:si,onMobileSlideChange:Fo,groups:Yt.length>0?Zc():[],mode:Ur,onModeChange:Ha,selectedKey:nt,scrollToKey:sd,scrollToKeyNonce:ba.nonce,compact:!1,collapsedDirectoryKeys:Br,onToggleDirectory:id,onSelectFile:t=>{const i=Cn.get(t.key);i&&Ua(wr(i))},renderLeading:ed,renderTrailing:t=>{const i=Cn.get(t.key);return i?Jc(i):null},renderDirectoryTrailing:Qc,renderSubtitle:t=>{const i=Cn.get(t.key);return i?Xc(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>x&&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:o("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Yt.length,"/",Ie.size]})]}),e.jsxs(Gd,{actions:Sd,children:[Vc(),t,h&&Es(),kd]},x),ar&&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:ar.label}),ar.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:ar.branch})]}),!ar&&Rn&&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(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Ia?(t=>od(t)):void 0,emptyContent:oi?null:gn&&Ie.size===0?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Yt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({slideToList:t})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:t,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:o("rightSidebar.backToChangeList"),children:[e.jsx(Vs,{size:14}),o("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[h&&Es(),e.jsxs("button",{type:"button",onClick:za,"aria-pressed":Tt,title:o("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 ${Tt?"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:o(Tt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),x&&e.jsx("button",{type:"button",onClick:()=>{Vn()},disabled:pr,"aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),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 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",children:e.jsx(uo,{size:14,className:pr?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:td,activePane:Mt,wrap:Tt,diffViewType:zo,inlineMode:cr,diffOptions:ud,reloadKey:is,renderStreamBadge:t=>e.jsx(Gs,{status:t}),onHunkGitAction:hd,onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,onDetailScroll:Ba}):e.jsx(el,{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:o("rightSidebar.backToChangeList"),groups:Yt.length>0?Zc():[],mode:Ur,onModeChange:Ha,selectedKey:nt,scrollToKey:sd,scrollToKeyNonce:ba.nonce,compact:!0,collapsedDirectoryKeys:Br,onToggleDirectory:id,onSelectFile:t=>{const i=Cn.get(t.key);i&&Ua(wr(i))},renderLeading:ed,renderTrailing:t=>{const i=Cn.get(t.key);return i?Jc(i):null},renderDirectoryTrailing:Qc,renderSubtitle:t=>{const i=Cn.get(t.key);return i?Xc(i):null},aiContent:Ia?(t=>od(t)):void 0,emptyContent:oi?null:gn&&Ie.size===0?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Yt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>x&&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:o("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Yt.length,"/",Ie.size]})})]}),e.jsxs(Gd,{actions:Sd,children:[Vc(),t,Es(),e.jsxs("button",{type:"button",onClick:za,"aria-pressed":Tt,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Tt?"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:o(Tt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),kd]},x),ar&&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:ar.label}),ar.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:ar.branch})]}),!ar&&Rn&&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(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),files:td,activePane:Mt,wrap:Tt,diffViewType:Cr,inlineMode:cr,diffOptions:ud,reloadKey:is,renderStreamBadge:t=>e.jsx(Gs,{status:t}),onHunkGitAction:hd,onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,onDetailScroll:Ba})}),e.jsx(Ja,{active:Xn,mounted:Oo&&Gr,children:ah?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:o("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Li.getState().setDock(Pi,null),lo({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:o("android.splitClose")})]}):e.jsx(dp,{sessionId:n??null,onCloseTab:()=>xc(!1),onInsertPrompt:t=>Fr("android-deps",t),onInsertFile:yh,onRecordingComplete:wh})})]}),r&&Te&&e.jsx(lg,{value:ve,collapsed:Ot,autoCollapseAfterSend:z,focusRequest:Nt,insertError:as?o("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{_r(!1),Xe(t)},onCollapsedChange:lt,onAutoCollapseAfterSendChange:ae,onDisable:()=>et(!1),onClear:()=>Xe(""),onInsert:()=>Ec(!1),onInsertAndSend:()=>Ec(!0),labels:{title:o("rightSidebar.contextDraftTitle"),hint:o("rightSidebar.contextDraftHint"),placeholder:o("rightSidebar.contextDraftPlaceholder"),collapse:o("rightSidebar.contextDraftCollapse"),expand:o("rightSidebar.contextDraftExpand"),disable:o("rightSidebar.contextDraftDisable"),clear:o("rightSidebar.contextDraftClear"),insert:o("rightSidebar.contextDraftInsert"),insertAndSend:o("rightSidebar.contextDraftInsertAndSend"),inserted:o("rightSidebar.contextDraftInserted"),sent:o("rightSidebar.contextDraftSent"),send:o("rightSidebar.contextDraftSend"),appended:o("rightSidebar.contextDraftAppended"),resize:o("rightSidebar.contextDraftResize"),autoCollapseAfterSend:o("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>o("rightSidebar.contextDraftCharacterCount",{count:t})}}),Th(),vt&&typeof document<"u"&&kr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>un(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:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:vt.kind==="restore"?o("rightSidebar.confirmRestoreTitle"):o("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:vt.kind==="restore"?o("rightSidebar.confirmRestoreDescription",{path:$u(vt.file.absolutePath,x)}):o("rightSidebar.confirmStashAllDescription")}),vt.kind==="restore"&&e.jsx("input",{value:vt.phrase,onChange:t=>un({...vt,phrase:t.target.value}),placeholder:o("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:()=>un(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:o("common.cancel")}),e.jsx("button",{type:"button",disabled:!!ze||vt.kind==="restore"&&vt.phrase.trim()!==o("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(vt.kind==="restore"){const t=pt(vt.file,x);if(!t)return;yt({action:"restore-worktree-file",cwd:t,paths:[vt.file.path],confirm:{acknowledged:!0,phrase:vt.phrase}},o("rightSidebar.restoreFile"),Yi(vt.file))}else{const t=vt.repoRoot??x;if(!t)return;yt({action:"stash-all",cwd:t},o("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${vt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:o(ze?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const Ox=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:vl,MarkdownImageLightbox:Uf,MarkdownPreview:Hf,RightSidebar:Ex,__testParseMarkdownListBlock:Gb,buildMarkdownPreviewBlocks:rx,buildMarkdownPreviewRenderResult:$l,collectKnownGitRepoRoots:ff,computeMarkdownImageDisplayBox:jf,getMarkdownHeadingOutline:Of,getMarkdownHeadingPathAtLine:Bf,getNextMarkdownPreviewLineRange:lx,isSvgImageSrc:No,mountRightSidebarRepoPickerOverlay:Qu,replaceGitRepositorySnapshot:Vf,resolveMarkdownLocalLinkTarget:jl,resolveRightSidebarDiffViewType:df,shouldCloseMarkdownImageLightboxDrag:Df,showsGitRepoGroupHeader:dl},Symbol.toStringTag,{value:"Module"}));export{nl as E,Ox as R,kp as a,Op as c,Bx as m};
|
|
1674
|
+
`):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${x??""}`,"每个仓库分别遵循下面列出的本地未提交更改选项。","目标仓库:",d,"","操作指令:","1. 只针对上面列出的目标仓库导出分支 hunk,按各仓库所选目标分支与基线对比。本地未提交更改标记为是的仓库纳入 staged/unstaged/untracked 改动;标记为否的仓库只解释提交改动,忽略导出中混入的本地改动。嵌套子仓或软链接子仓使用括号内的仓库绝对路径。示例:",w,"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:x??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
|
+
`)},[ln,Qn,Es,Et,rr,x]),Vh=a.useCallback((t="generate")=>{const i=t==="generate"?ki:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",ki].join(`
|
|
1676
|
+
`);Fr(o("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${t}`),c||l()},[ki,Fr,l,c,o]),Si=a.useCallback(async(t={})=>{const i=t.refresh===!0,d=i&&xe?.comparisonRepos?xe.comparisonRepos:Es.map(j=>{const ie=(rr[j.root]||j.branch||"").trim();return{repoRoot:j.root,label:j.label,base:Et[j.root]?.trim()??"",head:ie||null,includeUncommitted:ln[j.root]??!0}});if(!x||d.length===0)return;const w=++Dt.current,v=x,k=()=>Re(v)&&w===Dt.current;we(!0),Fe(null),i||(er(null),Ue(null));try{const j=await Promise.all(d.map(async X=>{if(!X.base)throw new Error(o("rightSidebar.branchAuditMissingBase",{repo:X.label}));return Td({cwd:x,repoRoot:X.repoRoot,base:X.base,head:X.head,includeUncommitted:t.repoRoot===X.repoRoot?t.includeUncommitted??!1:X.includeUncommitted??xe?.includeUncommitted??!0,requestSlotId:`right-sidebar-branch-preview:${X.repoRoot}`})}));if(!k())return;const ie=j.find(X=>!X.available);if(ie){Fe(ie.error??"Branch diff is unavailable");return}const te=j.length===1?j[0]:{available:!0,workspaceRoot:x,repoRoot:x,baseRef:j.map(X=>X.baseRef??X.baseBranch).filter(Boolean).join(", "),currentBranch:j.map(X=>X.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:j.map(X=>X.headRef).filter(Boolean).join(", "),diffFingerprint:j.map(X=>X.diffFingerprint).filter(Boolean).join("+"),stat:j.map(X=>X.stat).filter(Boolean).join(`
|
|
1677
|
+
`),files:j.flatMap((X,q)=>{const ge=d[q];return(X.files??[]).map($e=>`${ge?.label??X.repoRoot??"repo"}/${$e}`)}),hunks:j.flatMap((X,q)=>{const $e=d[q]?.label??X.repoRoot??"repo";return(X.hunks??[]).map(Ge=>({...Ge,filePath:`${$e}/${Ge.filePath}`,oldPath:Ge.oldPath?`${$e}/${Ge.oldPath}`:Ge.oldPath,newPath:Ge.newPath?`${$e}/${Ge.newPath}`:Ge.newPath}))}),commits:j.flatMap(X=>X.commits??[]),commitCount:j.reduce((X,q)=>X+(q.commitCount??q.commits?.length??0),0),diff:j.map(X=>X.diff).filter(Boolean).join(`
|
|
1678
|
+
`),truncated:j.some(X=>X.truncated)};if(te.comparisonRepos=d.map((X,q)=>({...X,head:X.head??j[q].currentBranch??null,includeUncommitted:j[q].includeUncommitted===!0,canIncludeUncommitted:j[q].canIncludeUncommitted})),te.canIncludeUncommitted=j.every(X=>X.canIncludeUncommitted===!0),te.includeUncommitted=j.some(X=>X.includeUncommitted===!0),Io(X=>({...X,...Object.fromEntries(te.comparisonRepos.map(q=>[q.repoRoot,q.includeUncommitted??!1]))})),!i&&(te.hunks??[]).length===0){Fe(o("rightSidebar.branchAuditDiffEmpty"));return}const be=Date.now(),Ce=(i?qe:null)??["preview",te.repoRoot??x,te.baseRef??te.baseBranch??"",te.currentBranch??"",te.headRef??"",te.diffFingerprint??be].join("\0"),Ve=d.length===1?d[0].label:`${d.length} repos`;er(te),Pn(X=>[{key:Ce,diff:te,repoLabel:Ve,createdAt:be},...X.filter(q=>q.key!==Ce)].slice(0,8)),i||nn(X=>X[Ce]===void 0?X:{...X,[Ce]:0}),cn(Ce),dn(X=>{const q=te.hunks?.[0],ge=q?`${q.filePath}\0${q.hunkHeader}\0${q.hunkIndex}`:null;return i&&X&&(te.hunks??[]).some($e=>$e.filePath===X.split("\0")[0])?X:ge}),fr(!0)}catch(j){if(!k()||wr(j))return;Fe(j instanceof Error?j.message:"Failed to load branch diff")}finally{k()&&we(!1)}},[ln,xe,qe,Es,Et,rr,Re,x,o]),Yh=a.useCallback(t=>{++Dt.current,we(!1),er(t.diff),Fe(null),cn(t.key),dn(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),fr(!0)},[]),Xh=a.useCallback(t=>{Pn(i=>i.filter(d=>d.key!==t)),nn(i=>{if(!(t in i))return i;const d={...i};return delete d[t],d}),qe===t&&(cn(null),er(null),fr(!1))},[qe]),Jh=a.useCallback(t=>{++Dt.current,we(!1);const i=Zn.find(d=>d.key===t);i&&(er(null),Fe(null),cn(t),dn(i.records[0]?.filePath??null),fr(!0))},[Zn]),Qh=a.useCallback(async t=>{if(!x||!Se)return;const[i]=t.split(/\s+/);if(i){xt(i),tr(null),Ue(null);try{const d=await Fm({cwd:x,repoRoot:Se,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){tr(d.error??"Commit diff is unavailable");return}Ue(d);const w=d.hunks?.[0];sa(w?`${w.filePath}\0${w.hunkHeader}\0${w.hunkIndex}`:null)}catch(d){tr(d instanceof Error?d.message:"Failed to load commit diff")}finally{xt(null)}}},[Se,x]),Zh=a.useCallback(t=>{if(!xe||!qe)return;const i=Math.max(0,Math.round(t));nn(d=>Math.abs((d[qe]??0)-i)<24?d:{...d,[qe]:i})},[xe,qe]);a.useEffect(()=>{!xe||!qe||Pn(t=>t.map(i=>i.key===qe&&i.diff!==xe?{...i,diff:xe}:i))},[xe,qe]);const ad=!!xe;a.useEffect(()=>{if(!oe||!ur||!ad)return;const t=gc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const i=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(i)},[ur,ad,oe]);const od=a.useCallback(t=>{t&&uh(i=>pp(i,t))},[]),id=ba.key===nt?ba.key:null,Ua=a.useCallback(t=>{const i=Y.getState(),d=Cx();Us("select_diff_file",{interactionId:d,path:t,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:le,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),st(t),Lr("diff"),oe&&t&&vc(1),od(t),queueMicrotask(()=>{const w=Y.getState();Us("select_diff_file_after",{interactionId:d,requestedPath:t,selectedFilePath:w.selectedFilePath,rootPath:w.rootPath,rightTab:w.rightTab,changedFiles:w.changedFiles.size,activeGitRepoRoot:le})})},[le,oe,od,st,Lr,vc]),ld=a.useCallback(t=>{const i=Array.from(Ie.values()).find(d=>{const w=bt(d,x),v=yr(d);return d.path===t.filePath||v===t.filePath||d.absolutePath===t.filePath||(w?`${w}/${d.path}`===t.filePath:!1)||t.repoRoot&&w===t.repoRoot&&d.path===t.filePath});if(i){Ua(yr(i)),window.setTimeout(()=>En(t),90),window.setTimeout(()=>En(t),320),window.setTimeout(()=>En(t),760);return}En(t)},[Ie,x,Ua]),cd=a.useCallback(({slideToDetail:t,fullscreen:i,toggleFullscreen:d}={})=>cs.length>0?e.jsx(Bu,{walkthroughs:cs,repoRoot:le,fullscreen:i,onToggleFullscreen:d,onNavigate:w=>{oe&&window.requestAnimationFrame(()=>t?.()),ld(w)}}):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(Js,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),o("rightSidebar.changeWalkthroughEmpty")]}),[le,cs,ld,oe,o]),em=a.useCallback(t=>{t&&lr(i=>{const d=new Set(i);return d.has(t)?d.delete(t):d.add(t),Hi(_i,d),d})},[]),dd=a.useCallback(t=>{Or(i=>{const d=new Set(i);return d.has(t)?d.delete(t):d.add(t),Hi(su,d),d})},[]),Ha=a.useCallback(t=>{Rr(t),Lt(nf,t)},[]);a.useEffect(()=>{Ia||Ur!=="ai"||Ha("tree")},[Ur,Ha,Ia]);const za=a.useCallback(()=>{ra(t=>{const i=!t;return Lt(sf,i),i})},[]),ud=a.useCallback(t=>{is(t),Lt(af,t)},[]),{whitespace:fd,context:hd}=bp(),md=a.useMemo(()=>({algorithm:"histogram",whitespace:fd,context:hd}),[fd,hd]),pd=a.useCallback(t=>{J(t),Lt(of,t)},[]),Wa=a.useCallback(async(t,i,d,w)=>{let v=t;for(;v.ok&&v.status==="running";)await new Promise(j=>window.setTimeout(j,1500)),v=await Id({jobId:v.jobId,cwd:i.cwd,action:i.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const k={action:i.action,path:w,label:d};return vs(k),window.setTimeout(()=>vs(j=>j?.action===k.action&&j.path===k.path?null:j),1400),v},[]),wt=a.useCallback(async(t,i,d)=>{const w=x;x&&gr.current.delete(x),yt(null),vs(null),xs({action:t.action,path:d});try{const v=await _m({...t,includeNested:Fs(x)}),k=await Wa(v,t,i,d);if(!Re(w))return!1;const j=x?await Pi(x,void 0,{includeNested:Fs(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Bs(x)}).catch(()=>k.bundle):k.bundle;return Re(w)?(j&&qn(j,{reloadDiff:!0,cacheOnly:!0}),un(null),!0):!1}catch(v){return vs(null),yt(o("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{Re(w)&&xs(null)}},[qn,Re,x,o,Wa]),gd=a.useCallback(async t=>{const i=x;await Dd({...t,includeNested:Fs(x)}),Re(i)&&Ft(x??void 0,{refresh:!0,background:!0})},[Re,Ft,x]),tm=a.useCallback(async t=>{const i=xe,d=Dt.current,w=i?.hunks?.find(k=>k.previewRevert?.cwd===t.cwd&&k.previewRevert.path===t.path);if(!i||!w||!t.comparisonBase)throw new Error(o("diffViewer.hunkActionUnavailable"));G(k=>k+1),Fe(null);try{await Dd(t)}catch(k){throw G(j=>j-1),k}if(d!==Dt.current||!Re(x)){G(k=>k-1);return}const v=k=>{er(j=>{if(!j||d!==Dt.current)return j;const ie=j.hunks??[],te=k===void 0?ie.filter(Ce=>!(Ce.previewRevert?.cwd===t.cwd&&Ce.previewRevert.patch===t.patch)):[...ie.filter(Ce=>Ce.filePath!==w.filePath),...k];return{...j,hunks:te}})};v(),Td({cwd:t.cwd,repoRoot:t.cwd,base:t.comparisonBase,comparisonBase:t.comparisonBase,filePath:t.path,requestSlotId:`branch-preview-file:${t.cwd}:${t.path}`}).then(k=>{if(d!==Dt.current||!Re(x))return;if(!k.available||k.truncated)throw new Error(k.error??o("diffViewer.hunkActionUnavailable"));const j=t.path.slice(t.cwd.length+1),ie=w.filePath.slice(0,w.filePath.length-j.length);v((k.hunks??[]).map(te=>({...te,filePath:`${ie}${te.filePath}`,oldPath:te.oldPath?`${ie}${te.oldPath}`:te.oldPath,newPath:te.newPath?`${ie}${te.newPath}`:te.newPath})))}).catch(k=>{d===Dt.current&&Re(x)&&!wr(k)&&Fe(`${o("diffViewer.hunkActionReverted")} · ${k instanceof Error?k.message:String(k)}`)}).finally(()=>G(k=>k-1))},[xe,Re,x,o]),Ga=a.useCallback((t,i,d)=>{if(i){if(t==="stage-all"){wt({action:"stage-all",cwd:i},o("rightSidebar.stageAll"),`repo:${i}`);return}un({kind:"stash-all",repoRoot:i,repoLabel:d})}},[wt,o]),bd=a.useCallback(t=>{Pe(t),fa(""),ha(""),ma(""),st(zc(t)),ot||Lr("diff"),t&&Aa(at.get(t))},[Aa,zc,ot,at,st,Pe,Lr]),xd=a.useCallback(t=>{const i=new Set([...Wt.current.keys(),...bn.current,...gr.current]);for(const d of i)d!==t&&(zt.current.delete(d),Wt.current.get(d)?.abort(),Wt.current.delete(d),Nt(`right-sidebar-git-untracked:${d}`),bn.current.delete(d),gr.current.delete(d))},[]),rm=a.useCallback(async t=>{const i=x;if(!i||(await Y.getState().setNestedGitScanRoot(i,t),!Re(i)))return;if(t){await Ft(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}xd(i),fa(""),ha(""),ma(""),To(w=>w.filter(v=>v===i));const d=qt;d&&bt(d,i)!==i&&st(null),await Ft(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[xd,Re,Ft,x,st,qt]),nm=a.useCallback(async()=>{if(!Se||Je){yt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=Fn.trim();!t||t===he?.branch||await wt({action:"switch-branch",cwd:Se,branch:t},o("rightSidebar.switchBranch"))},[he?.branch,Se,Je,wt,Fn,o]),vd=a.useCallback(async()=>{if(!Se||Je){yt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=ua.trim();if(!t)return;await wt({action:"commit",cwd:Se,message:t},o("rightSidebar.commitChanges"))&&Kl("")},[Se,ua,Je,wt,o]),sm=a.useCallback(async()=>{if(!Se||Je){yt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await wt({action:"push",cwd:Se,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pushChanges"))},[Se,mn,hn,Je,wt,o]),am=a.useCallback(async()=>{if(!Se||Je){yt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await wt({action:"pull",cwd:Se,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pullChanges"))},[Se,mn,hn,Je,wt,o]);a.useEffect(()=>{if(!ot||!Se||ze)return;let t=!1;const i={push:o("rightSidebar.pushChanges"),pull:o("rightSidebar.pullChanges"),commit:o("rightSidebar.commitChanges"),"switch-branch":o("rightSidebar.switchBranch"),"stage-all":o("rightSidebar.stageAll"),"stash-all":o("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const w=await Id({cwd:Se,action:d}).catch(()=>null);if(!w?.ok||w.status!=="running")continue;const v={action:d,cwd:Se},k=i[d]??d;xs({action:d});try{const j=await Wa(w,v,k);if(t||!Re(x))return;const ie=x?await Pi(x,void 0,{includeNested:Fs(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Bs(x)}).catch(()=>j.bundle):j.bundle;ie&&qn(ie,{reloadDiff:!0,cacheOnly:!0})}catch(j){t||yt(o("rightSidebar.gitActionFailed",{message:j instanceof Error?j.message:"Unknown error"}))}finally{t||xs(null)}return}})(),()=>{t=!0}},[Se,qn,ot,Re,x,ze,o,Wa]);const ji=In?.action==="commit",Ri=In?.action==="switch-branch",Ni=In?.action==="pull",Ci=In?.action==="push",Ka=ot||ch,Ei=Fa?o("rightSidebar.changeAuditScopeAll"):xr.length===1?xr[0].label:`${xr.length} repos`,om=xr.length>0,yd=Es.length>0,im=x?e.jsx(ku,{open:Po,onOpenChange:Ao,showScopePicker:!0,selectedAll:Fa,repos:Vt,selectedRoots:Da,onToggleRepo:Wh,onGenerate:()=>Vh(yi?"regenerate":"generate"),disabled:!om,generateDisabled:!yd,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:o(yi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.branchAuditGenerateTitle"),ariaLabel:o("rightSidebar.branchAuditShort"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Ei,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o(yi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Si()},secondaryDisabled:!yd||de,secondaryLabel:o("rightSidebar.branchAuditViewDiff"),secondaryTitle:o("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:de,loading:_l.size>0,statusTitle:_l.size>0?o("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:Vc.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:o("rightSidebar.missingBaseReposSkipped",{repositories:Vc.map(t=>t.label).join(O==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const i=at.get(t.root),d=Qn(t.root,rr[t.root]||i?.context?.branch),w=[],v=new Set,k=(be,Ce)=>{!be||v.has(be)||(v.add(be),w.push({value:be,label:be,meta:Ce}))};k(rr[t.root]||i?.context?.branch,o("rightSidebar.pushCurrentBranchBadge"));for(const be of i?.context?.branches??[])k(be,be===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):o("rightSidebar.localBranch"));for(const be of i?.context?.remoteBranches??[])k(be,o("rightSidebar.remoteBranch"));const j=[],ie=new Set,te=(be,Ce)=>{!be||ie.has(be)||(ie.add(be),j.push({value:be,label:be,meta:Ce}))};te(Et[t.root],Et[t.root]?o("rightSidebar.pushUpstreamBadge"):void 0),te(i?.context?.upstream,i?.context?.upstream?o("rightSidebar.pushUpstreamBadge"):void 0);for(const be of i?.context?.remoteBranches??[])te(be,"remote");for(const be of i?.context?.branches??[])te(be,be===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(rs,{label:o("rightSidebar.currentBranchLabel"),value:rr[t.root]||i?.context?.branch||"",options:w,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),onChange:be=>{oa(Ce=>({...Ce,[t.root]:be}))}}),e.jsx(rs,{label:o("rightSidebar.branchAuditBaseLabel"),value:Et[t.root]||"",options:j,placeholder:o("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:o("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:o("rightSidebar.branchAuditBaseEmpty"),onChange:be=>{ia(Ce=>({...Ce,[t.root]:be}))}}),e.jsxs("label",{className:"sm:col-span-2 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:o("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:o(d?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:d&&(ln[t.root]??!0),disabled:!d,onChange:be=>Io(Ce=>({...Ce,[t.root]:be.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,wd=Os(jt.reduce((t,i)=>Math.max(t,i.injectedAt??0),0),O),lm=()=>x?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Fl(t=>{const i=!t;return Lt(Bi,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":bs,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(Js,{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:o("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Ei})]}),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 ${bs?"rotate-90":""}`,children:e.jsx(ns,{size:13})})]}),bs&&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:[o("rightSidebar.changeAuditScopeLabel"),": ",Ei]}),im]}),Ze&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Ze}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[rn.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${qe===t.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:()=>Yh(t),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:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.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:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:o("rightSidebar.branchAuditViewDiff")})]}),Os(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Os(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>Xh(t.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:o("common.delete"),"aria-label":o("common.delete"),children:e.jsx(co,{size:12})})]},t.key)),Zn.length>0?Zn.slice(0,Math.max(0,8-rn.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${qe===t.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:()=>Jh(t.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:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.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:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),Os(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:o("rightSidebar.branchAuditGeneratedAt",{time:Os(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Hh(t)},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:o("rightSidebar.branchAuditClearTitle"),"aria-label":o("rightSidebar.branchAuditClearTitle"),children:e.jsx(co,{size:12})})]},t.key)):rn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,cm=()=>nr&&x&&jn?e.jsxs("div",{className:Ka?"overflow-visible":"overflow-hidden",children:[lm(),e.jsxs("button",{type:"button",onClick:()=>{ot||dh(t=>{const i=!t;return i&&Se&&!jn&&!fn&&ai(Se),i})},"aria-expanded":Ka,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${ot?"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(vr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${Sn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[fn&&e.jsx(ht,{size:10,className:"animate-spin"}),Sn.staged>0?o("rightSidebar.stagedCount",{count:Sn.staged}):o("rightSidebar.noStagedChangesShort")]}),!ot&&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 ${Ka?"rotate-90":""}`,children:e.jsx(ns,{size:13})})]})]}),Ka&&e.jsxs("div",{className:"space-y-0",children:[Bt.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Mh})]})}),e.jsx(rs,{label:o("rightSidebar.gitRepositoryLabel"),value:Se??"",options:Bt,placeholder:o("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:o("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:o("rightSidebar.gitRepositoryEmpty"),disabled:!!ze,onChange:t=>{bd(t||null)}}),Je&&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:o("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Fn!==Uc?Uc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{nm()},disabled:!Bh,className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ri?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.switchBranch"),children:[e.jsx("span",{className:ze?.action==="switch-branch"||Ri?"opacity-0":"",children:o("rightSidebar.switchBranch")}),ze?.action==="switch-branch"&&e.jsx(ht,{size:12,className:"absolute animate-spin"}),Ri&&ze?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(rs,{label:o("rightSidebar.currentBranchLabel"),value:Fn,options:Ph,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),disabled:!!ze,onChange:fa})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",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-[12px] font-medium text-foreground",children:o("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Je?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged>0?o("rightSidebar.commitReadyHint",{count:Sn.staged}):o("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{vd()},disabled:!!ze||Je||Sn.staged===0||!ua.trim(),className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition active:scale-95 ${ji?"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:Je?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged===0?o("rightSidebar.commitNeedsStaged"):o("rightSidebar.commitChanges"),children:[e.jsx("span",{className:ze?.action==="commit"||ji?"opacity-0":"",children:o("rightSidebar.commitChanges")}),ze?.action==="commit"&&e.jsx(ht,{size:12,className:"absolute animate-spin"}),ji&&ze?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:ua,onChange:t=>Kl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),vd())},placeholder:o("rightSidebar.commitMessagePlaceholder"),disabled:!!ze,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ms(t=>!t),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":zr,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:o("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Ut&&e.jsx(ht,{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 ${zr?"rotate-90":""}`,children:e.jsx(ns,{size:13})})]})]}),zr&&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(ss,{size:12,className:"shrink-0"}),e.jsx("input",{value:ps,onChange:t=>hr(t.target.value),placeholder:o("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}),ps&&e.jsx("button",{type:"button",onClick:()=>hr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:$h,children:[Z.length>0?Z.map(t=>{const[i,...d]=t.split(/\s+/),w=d.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{Qh(t)},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:w,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:w,children:w}),on[i]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${on[i]==="ahead"?"bg-accent/10 text-accent":on[i]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:o(on[i]==="ahead"?"rightSidebar.commitAhead":on[i]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),gt===i&&e.jsx(ht,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):Ut?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:o("common.loading")}):$o?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.recentCommitsEmpty")}),na&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(ht,{size:12,className:"animate-spin"})}),Lo&&!na&&Z.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:o("rightSidebar.recentCommitsLoadMore")})]})]}),sn&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:sn}),$o&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:$o})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{am()},disabled:!Fh,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ni?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pullChanges"),children:[e.jsx("span",{className:ze?.action==="pull"||Ni?"opacity-0":"",children:o("rightSidebar.pullChanges")}),ze?.action==="pull"&&e.jsx(ht,{size:12,className:"absolute animate-spin"}),Ni&&ze?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{sm()},disabled:!_h,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Ci?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pushChanges"),children:[e.jsx("span",{className:ze?.action==="push"||Ci?"opacity-0":"",children:o("rightSidebar.pushChanges")}),ze?.action==="push"&&e.jsx(ht,{size:12,className:"absolute animate-spin"}),Ci&&ze?.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] ${Xc.className}`,title:he?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:Xc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:he?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${qc?"grid-cols-2":"grid-cols-1"}`,children:[qc&&e.jsx(rs,{label:o("rightSidebar.pushRemoteLabel"),value:hn,options:Kc,placeholder:o("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:o("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:o("rightSidebar.pushNoRemotes"),disabled:!!ze,onChange:ha}),e.jsx(rs,{label:o("rightSidebar.pushBranchLabel"),value:mn,options:Ah,placeholder:o("rightSidebar.pushBranchPlaceholder",{branch:he?.branch??"HEAD"}),searchPlaceholder:o("rightSidebar.pushBranchSearchPlaceholder"),emptyText:o("rightSidebar.pushNoBranches"),disabled:!!ze,onChange:ma})]})]})]})]}):null,dm=a.useCallback(t=>{const i=bt(t,x);if(!i)return[];const d=Yi(t),w=[];return t.canStage&&w.push({key:"stage-file",label:o("rightSidebar.stageFile"),onClick:()=>{wt({action:"stage-file",cwd:i,paths:[t.path]},o("rightSidebar.stageFile"),d)}}),t.canUnstage&&w.push({key:"unstage-file",label:o("rightSidebar.unstageFile"),onClick:()=>{wt({action:"unstage-file",cwd:i,paths:[t.path]},o("rightSidebar.unstageFile"),d)}}),t.canStash&&w.push({key:"stash-file",label:o("rightSidebar.stashFile"),onClick:()=>{wt({action:"stash-file",cwd:i,paths:[t.path]},o("rightSidebar.stashFile"),d)}}),t.canRestoreWorktree&&w.push({key:"restore-worktree-file",label:o("rightSidebar.restoreFile"),destructive:!0,onClick:()=>un({kind:"restore",file:t,phrase:""})}),w},[x,wt,o]),um=a.useCallback(()=>{if(p){y?.();return}$r(0),Ar.current?.slideTo(0),Mr(!1),St(null)},[y,p]),kd=a.useCallback(t=>{if(V(""),Ht(t),st(null),St(null),K(null),oe){p&&y?.(),$r(0),Ar.current?.slideTo(0),Mr(!1);return}},[oe,y,p,st,Ht]);a.useEffect(()=>{const t=i=>{const d=i.detail,w=d?.path;if(typeof w!="string"||!w.startsWith("/"))return;V(""),St(null),Jt(null);const v=!!(x&&(w===x||w.startsWith(`${x}/`)));if(d.kind==="file"){const k=io(w);Ss(w),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Jt(d.line),Ht(v?null:k),K(j=>({path:w,nonce:(j?.nonce??0)+1}));return}st(null),v?(Ht(null),K(k=>({path:w,nonce:(k?.nonce??0)+1}))):(K(null),Ht(w)),oe&&(p&&y?.(),$r(0),Ar.current?.slideTo(0),Mr(!1))};return window.addEventListener(Ud,t),()=>window.removeEventListener(Ud,t)},[Ss,oe,y,p,x,st,Ht]),a.useEffect(()=>{r||(Tt(!1),Xt(!1))},[r]),a.useEffect(()=>{if(!At&&!Sr)return;const t=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&(Mn.current?.contains(i.target)||ta.current?.contains(i.target))||(Tt(!1),Xt(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[Sr,At]);const Sd=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:Nh,disabled:!La,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":o("rightSidebar.parentFolder"),title:o("rightSidebar.parentFolder"),children:e.jsx(kl,{size:14})}),e.jsx("button",{type:"button",onClick:Ac,disabled:!x||Bn===x,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":o("rightSidebar.backToProjectRoot"),title:o("rightSidebar.backToProjectRoot"),children:e.jsx(Hd,{size:14})}),e.jsx("button",{type:"button",onClick:Ch,disabled:!ce,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":o("rightSidebar.refreshFiles"),title:ql?o("rightSidebar.fileWatchUnavailable",{message:ql}):o("rightSidebar.refreshFiles"),children:e.jsx(uo,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ce??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:jh}),wa==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:o("fileTree.sortedByModified"),"aria-label":o("fileTree.sortedByModified"),children:e.jsx(zd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ce&&Kt(ce,_t??void 0),disabled:!ce,...ce&&_t?di(Ma(ce),_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&&(ke===_t||Qe===_t)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":o(_t&&Qe===_t?"rightSidebar.copied":_t&&ke===_t?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:o("rightSidebar.insertCurrentFolder"),children:_t&&(ke===_t||Qe===_t)?e.jsx(go,{size:13}):e.jsx(bo,{size:13})}),e.jsx(Up,{rootPath:ce,disabled:!ce||!mh||Jo,pressed:ya,saving:Jo,onToggle:()=>{if(!ce||Jo)return;const t=ce;dc(!0),Qo(null),ph(t,!ya).catch(()=>{const i=Y.getState();(i.explorerRoot??i.rootPath)===t&&Qo(o("rightSidebar.gitIgnoreSaveFailed"))}).finally(()=>dc(!1))}}),e.jsxs("div",{ref:ta,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Tt(!1),Xt(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${Sr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":Sr,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(po,{size:14})}),Sr&&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:()=>{Xt(!1),Eh()},disabled:!mi,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${Rs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Rs?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(Rs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Xt(!1),fh()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${qo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[qo?e.jsx(Sp,{size:14}):e.jsx(sl,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(qo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ce,onClick:()=>{ce&&(Xt(!1),hh(ce,wa==="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:[wa==="modified"?e.jsx(op,{size:14}):e.jsx(zd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(wa==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),uc&&e.jsx("p",{role:"alert",className:"px-1 py-1 text-[11px] text-destructive",children:uc}),x&&(Pa.length>0||Rh)&&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:o("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Ac,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-md px-2 py-0.5 font-medium transition active:scale-95 ${ce===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(Hd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:tt})]}),Pa.map(t=>{const i=t.path,d=t.kind==="file",w=d?nt===i:ce===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${w?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>d?Ss(i):Ht(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(al,{size:10,className:"shrink-0"}):e.jsx(Xa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:kt(i)})]}),e.jsx("button",{type:"button",onClick:()=>pn(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.unpinFolder",{name:kt(i)}),title:o("rightSidebar.unpinFolder",{name:kt(i)}),children:e.jsx(Pt,{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"})]}),Mi=a.useMemo(()=>{if(Dn===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((Uo-Dn)/1e3)),d=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[w,v]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return d.format(w,v)},[Uo,Dn]),qa="flex min-h-10 w-full items-center gap-2.5 rounded-md px-2.5 text-left text-[12px] text-foreground transition hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:min-h-11",jd=x&&!Yn?e.jsxs("button",{type:"button",role:"menuitemcheckbox",tabIndex:-1,onClick:()=>{rm(!Vo)},"aria-checked":Vo,title:o("rightSidebar.multiRepoScanTitle"),className:qa,children:[e.jsx(vr,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1",children:o("rightSidebar.multiRepoScan")}),Vo&&e.jsx(go,{size:14,className:"shrink-0 text-primary"})]}):null,Rd=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Mi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:o("rightSidebar.gitLastUpdated",{time:Mi}),children:Mi}):null,e.jsx("button",{type:"button",onClick:()=>{Vn()},disabled:pr,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":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),children:e.jsx(uo,{size:13,className:pr?"animate-spin":""})})]}):null,fm=xc?o("rightSidebar.changeAuditScopeAll"):vn.length===1?vn[0].relativeRoot==="."?tt:vn[0].relativeRoot||vn[0].name:`${vn.length} repos`,hm=t=>x?e.jsxs("div",{role:"none",children:[e.jsx(ku,{menuItem:!0,open:fs,onOpenChange:i=>{Qr(i),i&&t()},showScopePicker:Rn,selectedAll:xc,repos:gh,selectedRoots:sr,onToggleRepo:zh,onGenerate:()=>{t(),Oh()},disabled:!x,inserted:ke===Pc,buttonLabel:o("rightSidebar.changeAuditShort"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:o("rightSidebar.insertChangeAuditPrompt"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:fm,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o("rightSidebar.changeAuditShort"),loading:us,error:!!Jr,statusTitle:Jr??(us?o("rightSidebar.changeAuditLoading"):jt.length>0?`${o("rightSidebar.changeAuditLoaded",{count:jt.length})}${wd?` · ${o("rightSidebar.changeAuditLoadedAt",{time:wd})}`:""}`:void 0)}),jt.length>0&&e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Uh()},disabled:us||jt.length===0,className:qa,title:o("rightSidebar.clearChangeAuditTitle"),"aria-label":o("rightSidebar.clearChangeAudit"),children:[e.jsx(co,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.clearChangeAudit")})]})]}):null,es=ar??(N?.available&&x&&Ie.size>0&&fe.length<=1?{root:x,label:tt}:null),Nd=t=>e.jsxs(e.Fragment,{children:[es&&e.jsxs("div",{role:"group","aria-label":o("rightSidebar.gitQuickActions"),children:[e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Ga("stage-all",es.root,es.label)},disabled:!!ze,className:qa,children:[e.jsx(Hm,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stageAll")]}),e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Ga("stash-all",es.root,es.label)},disabled:!!ze,className:qa,children:[e.jsx(vp,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stashAll")]})]}),es&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),hm(t),jd&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),jd]}),Va=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[N?.available&&N.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:N.branch,children:[e.jsx(vr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:N.branch})]}),ft.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[ft.modified,"M"]}),ft.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",ft.added]}),ft.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",ft.deleted]}),ft.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ft.renamed,"R"]}),ft.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ft.copied,"C"]}),ft.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ft.untracked,"U"]}),ft.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[ft.conflicted,"!"]}),ft.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ft.other,"?"]}),ft.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:o("rightSidebar.stagedCountShort",{count:ft.staged})})]});return e.jsxs(ip,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:f,push:c,pinned:h,children:[di.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${vh?"hidden":""}`,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:x??void 0,children:tt}),(!oe||_o)&&N?.available&&N.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:N.branch,children:[e.jsx(vr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:N.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!pe;W(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):V("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${pe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleSearch"),title:o("common.search"),children:e.jsx(ss,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Te,onClick:()=>{et(t=>!t),lt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Te?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleContextDraft"),title:o("rightSidebar.contextDraftTitle"),children:[e.jsx(lp,{size:14}),!Te&&ve.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:Jl,type:"file",multiple:!0,className:"hidden",onChange:t=>{const i=t.target.files;!i||i.length===0||(js(Array.from(i)),t.target.value="")}}),e.jsx("input",{ref:Ql,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const i=t.target.files?.[0];t.target.value="",i&&wh(i)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14})}),e.jsxs("div",{ref:Mn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Xt(!1),Tt(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${At?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":At,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(po,{size:15})}),At&&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:"menuitemcheckbox","aria-checked":Gr,onClick:()=>wc(!Gr),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2",children:[e.jsx(Fd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:o("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Gr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Gr?"left-3.5":"left-0.5"}`})})]}),e.jsx("div",{className:"my-1 h-px bg-border/15",role:"separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Tt(!1),Jl.current?.click()},disabled:pa,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:[pa?e.jsx(ht,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Ip,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Tt(!1),Ql.current?.click()},disabled:pa,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:[pa?e.jsx(ht,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Mp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Tt(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(Ti,{size:14}):e.jsx(Xa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&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":o("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:o("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",o("rightSidebar.layoutModeAuto")],["narrow",o("rightSidebar.layoutModeNarrow")],["wide",o("rightSidebar.layoutModeWide")]].map(([t,i])=>{const d=ee===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{A(t),Tt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${d?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,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":o("rightSidebar.close"),children:e.jsx(Pt,{size:14})})]}),pe&&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(ss,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:P,onChange:t=>V(t.target.value),placeholder:o(B==="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 ${oe?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>pd("name"),"aria-pressed":B==="name",className:`rounded-full px-2 transition active:scale-95 ${oe?"py-1":"py-0.5"} ${B==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>pd("content"),"aria-pressed":B==="content",className:`rounded-full px-2 transition active:scale-95 ${oe?"py-1":"py-0.5"} ${B==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeContent")})]}),P&&e.jsx("button",{type:"button",onClick:()=>V(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{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(cp,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:o("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:ue,onChange:t=>me(t.target.value),onKeyDown:t=>{t.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:o("rightSidebar.searchScopePlaceholder"),"aria-label":o("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ue!=="."&&e.jsx("button",{type:"button",onClick:()=>me("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.resetSearchScope"),children:e.jsx(Pt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>L(t=>!t),"aria-expanded":Ne,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${Ne||ys.length>0||Q||Le||De?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:o("rightSidebar.searchOptions"),"aria-label":o("rightSidebar.searchOptions"),children:[e.jsx(dp,{size:13}),ys.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:ys.length})]})]}),Ne&&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:o("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ye,onChange:t=>je(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchExcludePlaceholder"),"aria-label":o("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ye&&e.jsx("button",{type:"button",onClick:()=>je(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.clearSearchExclude"),children:e.jsx(Pt,{size:11})})]}),B==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":o("rightSidebar.contentSearchOptions"),children:[[Q,()=>ne(t=>!t),wp,o("rightSidebar.matchCase")],[Le,()=>Ye(t=>!t),Fp,o("rightSidebar.matchWholeWord")],[De,()=>rt(t=>!t),Lp,o("rightSidebar.useRegex")]].map(([t,i,d,w])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),w]},w))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Yn?2:3)+(Gr?1:0)}, minmax(0, 1fr))`},children:[!Yn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:t=>Na("git",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(vr,{size:12}),o("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:t=>Na("diff",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Ku,{size:12}),o("rightSidebar.tabChanges"),Ie.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Ie.size}):null]})]}),e.jsxs("button",{type:"button",onClick:t=>Na("files",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Zi,{size:12}),o("rightSidebar.tabFiles")]}),Gr&&e.jsxs("button",{type:"button",onClick:t=>Na("android",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Gt==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Fd,{size:12}),o("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),Wl&&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:Wl})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ja,{active:ot,mounted:nr,fallback:e.jsx(Ki,{slow:!1}),children:()=>Oe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Xd,{items:Gh,diffViewType:zo,inlineMode:cr,viewControls:h?Ms():void 0,renderPathReference:(t,i)=>_a(Cn(t,Oe.repoRoot??x),o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:rh,onSelect:sa,emptyText:o("rightSidebar.noChanges"),mobile:oe,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o("rightSidebar.recentCommitsTitle"),headerMeta:`${Oe.headRef??""}${Oe.commits?.[0]?` · ${Oe.commits[0]}`:""}`,onClose:()=>{Ue(null),sa(null)},closeLabel:o("common.back"),wrap:It,onToggleWrap:za,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:oe?"stacked":"split",onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa})}):ur?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Xd,{items:vi,diffViewType:zo,inlineMode:cr,viewControls:h?Ms():void 0,renderPathReference:(t,i)=>{const d=xe?.comparisonRepos,w=d&&d.length>1?[...d].sort((k,j)=>j.label.length-k.label.length).find(k=>t===k.label||t.startsWith(`${k.label}/`)):void 0,v=w?t===w.label?w.repoRoot:Cn(t.slice(w.label.length+1),w.repoRoot):Cn(t,Ps?.repoRoot||x);return _a(v,o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:Do,onSelect:dn,emptyText:o(xe?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:oe,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o(xe?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Ps?`${Ps.repoLabel} · ${Ps.branchName??"HEAD"} → ${Ps.baseRef}`:void 0,onClose:()=>{++Dt.current,we(!1),fr(!1),er(null)},closeLabel:o("common.back"),wrap:It,onToggleWrap:za,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:oe?"stacked":"split",onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,localOptions:xe?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??xe.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??Qn(t.repoRoot,t.head)),onChange:i=>{Si({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:i})}})),onHunkGitAction:xe?.includeUncommitted?tm:void 0,error:Ze,actionsBusy:_>0,onRefresh:()=>{Si({refresh:!0})},refreshing:de,refreshLabel:o("rightSidebar.branchAuditRefreshDiff"),refreshTitle:o("rightSidebar.branchAuditRefreshDiff"),walkthroughs:Kh,onWalkthroughNavigate:qh,initialDetailScrollTop:xe&&qe?hs[qe]:void 0,onDetailScrollPositionChange:Zh,externalSwiperRef:oe?gc:void 0,onMobileSlideChange:oe?Fo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:nr&&x&&jn?e.jsx("div",{className:"px-3",children:cm()}):pr?e.jsx(Ki,{slow:oc}):gn?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):Cu(N)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):N?.available===!1?e.jsx(oo,{message:N.error??o("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{Vn()}}):x?e.jsx(Ki,{slow:oc}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ja,{active:Tr,mounted:sh||Tr,children:()=>oe?e.jsxs(Du,{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:t=>{Ar.current=t,t.slideTo(Ol,0)},onSlideChange:t=>{if($r(t.activeIndex),ks.current===t.activeIndex){ks.current=null;return}t.activeIndex===0&&(Mr(!1),St(null),y?.())},children:[e.jsx(el,{className:"h-full min-h-0",children:e.jsxs("div",{ref:zn,onScroll:kc,onDragOver:Ca,onDragEnter:Ca,onDragLeave:Rc,onDrop:Nc,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[Vl&&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:o("rightSidebar.dropToUpload")})}),!P.trim()&&Sd,e.jsx(Wd,{rootPath:ce??"",onFileSelect:Ss,onPathReference:Kt,getReferenceText:Ma,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onDirectoryRoot:Tc,onSearchFromDirectory:Ic,onDirectoryPinToggle:Dc,onFilePinToggle:Fc,pinnedPaths:wn,selectedFilePath:nt,query:_e,searchRootPath:fc,searchOptions:hc,searchMode:B,onContentMatchSelect:Sc,onDirectoryDropFiles:(t,i)=>js(i,t),revealDirectory:E,canOpenInFileBrowser:Yl,onOpenInFileBrowser:jc})]})}),e.jsx(el,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(yl,{filePath:nh||Ol===1?nt:null,active:Tr,onInsertReference:Kt,onInsertText:Dr,onInsertFeature:Dr,onReviewReference:$c,onReferenceCopied:Ir,onClose:um,onDirectoryLinkOpen:kd,isMobile:!0,lineRange:jr,onLineRangeChange:St,insertedReferenceKey:ke,copiedReferenceKey:Qe,scrollToLine:$n,onScrollToLineHandled:()=>Jt(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:C,onCloseMarkdownOutline:R,markdownImageLightboxOpen:M,markdownImageLightboxCloseSignal:H,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:S})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:zn,onScroll:kc,onDragOver:Ca,onDragEnter:Ca,onDragLeave:Rc,onDrop:Nc,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Wo},children:[Vl&&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:o("rightSidebar.dropToUpload")})}),!P.trim()&&Sd,e.jsx(Wd,{rootPath:ce??"",onFileSelect:Ss,onPathReference:Kt,getReferenceText:Ma,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onDirectoryRoot:Tc,onSearchFromDirectory:Ic,onDirectoryPinToggle:Dc,onFilePinToggle:Fc,pinnedPaths:wn,selectedFilePath:nt,query:_e,searchRootPath:fc,searchOptions:hc,searchMode:B,onContentMatchSelect:Sc,onDirectoryDropFiles:(t,i)=>js(i,t),revealDirectory:E,canOpenInFileBrowser:Yl,onOpenInFileBrowser:jc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":o("rightSidebar.resizeFileTree"),title:o("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:bh,onPointerMove:xh,onPointerUp:yc,onPointerCancel:yc,onDoubleClick:()=>{Go(dl),Lt(Hs,dl)},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(yl,{filePath:nt,active:Tr,onInsertReference:Kt,onInsertText:Dr,onInsertFeature:Dr,onReviewReference:$c,onReferenceCopied:Ir,onDirectoryLinkOpen:kd,isMobile:!1,lineRange:jr,onLineRangeChange:St,insertedReferenceKey:ke,copiedReferenceKey:Qe,scrollToLine:$n,onScrollToLineHandled:()=>Jt(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:U,onOpenMarkdownOutline:C,onCloseMarkdownOutline:R,markdownImageLightboxOpen:M,markdownImageLightboxCloseSignal:H,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:S})})]})}),e.jsx(Ja,{active:Mt,mounted:oh||Mt,children:()=>oi?e.jsx(up,{}):oe?e.jsx(tl,{mobile:!0,backLabel:o("rightSidebar.backToChangeList"),externalSwiperRef:si,onMobileSlideChange:Fo,groups:Yt.length>0?rd():[],mode:Ur,onModeChange:Ha,selectedKey:nt,scrollToKey:id,scrollToKeyNonce:ba.nonce,compact:!1,collapsedDirectoryKeys:Br,onToggleDirectory:dd,onSelectFile:t=>{const i=Nn.get(t.key);i&&Ua(yr(i))},renderLeading:nd,renderTrailing:t=>{const i=Nn.get(t.key);return i?ed(i):null},renderDirectoryTrailing:td,renderSubtitle:t=>{const i=Nn.get(t.key);return i?Zc(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>x&&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:o("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Yt.length,"/",Ie.size]})]}),e.jsxs(Vd,{actions:Nd,children:[Jc(),t,h&&Ms(),Rd]},x),ar&&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:ar.label}),ar.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:ar.branch})]}),!ar&&Rn&&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(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Ia?(t=>cd(t)):void 0,emptyContent:oi?null:gn&&Ie.size===0?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Yt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({slideToList:t})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:t,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:o("rightSidebar.backToChangeList"),children:[e.jsx(Vs,{size:14}),o("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[h&&Ms(),e.jsxs("button",{type:"button",onClick:za,"aria-pressed":It,title:o("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 ${It?"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:o(It?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),x&&e.jsx("button",{type:"button",onClick:()=>{Vn()},disabled:pr,"aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),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 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",children:e.jsx(uo,{size:14,className:pr?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:sd,activePane:Mt,wrap:It,diffViewType:zo,inlineMode:cr,diffOptions:md,reloadKey:ls,renderStreamBadge:t=>e.jsx(Gs,{status:t}),onHunkGitAction:gd,onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,onDetailScroll:Ba}):e.jsx(tl,{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:o("rightSidebar.backToChangeList"),groups:Yt.length>0?rd():[],mode:Ur,onModeChange:Ha,selectedKey:nt,scrollToKey:id,scrollToKeyNonce:ba.nonce,compact:!0,collapsedDirectoryKeys:Br,onToggleDirectory:dd,onSelectFile:t=>{const i=Nn.get(t.key);i&&Ua(yr(i))},renderLeading:nd,renderTrailing:t=>{const i=Nn.get(t.key);return i?ed(i):null},renderDirectoryTrailing:td,renderSubtitle:t=>{const i=Nn.get(t.key);return i?Zc(i):null},aiContent:Ia?(t=>cd(t)):void 0,emptyContent:oi?null:gn&&Ie.size===0?e.jsx(oo,{message:gn,onRetry:()=>{Vn()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Yt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>x&&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:o("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Yt.length,"/",Ie.size]})})]}),e.jsxs(Vd,{actions:Nd,children:[Jc(),t,Ms(),e.jsxs("button",{type:"button",onClick:za,"aria-pressed":It,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${It?"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:o(It?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Rd]},x),ar&&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:ar.label}),ar.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:ar.branch})]}),!ar&&Rn&&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(vr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),files:sd,activePane:Mt,wrap:It,diffViewType:Nr,inlineMode:cr,diffOptions:md,reloadKey:ls,renderStreamBadge:t=>e.jsx(Gs,{status:t}),onHunkGitAction:gd,onInsertDiffReference:Fr,onReferenceCopied:Ir,insertedReferenceKey:ke,copiedReferenceKey:Qe,onClearAuditRecord:Oa,onDetailScroll:Ba})}),e.jsx(Ja,{active:Xn,mounted:Oo&&Gr,children:ih?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:o("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Li.getState().setDock(Ai,null),lo({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:o("android.splitClose")})]}):e.jsx(fp,{sessionId:n??null,onCloseTab:()=>wc(!1),onInsertPrompt:t=>Fr("android-deps",t),onInsertFile:Sh,onRecordingComplete:kh})})]}),r&&Te&&e.jsx(dg,{value:ve,collapsed:Ot,autoCollapseAfterSend:z,focusRequest:Ct,insertError:os?o("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{_r(!1),Xe(t)},onCollapsedChange:lt,onAutoCollapseAfterSendChange:ae,onDisable:()=>et(!1),onClear:()=>Xe(""),onInsert:()=>Lc(!1),onInsertAndSend:()=>Lc(!0),labels:{title:o("rightSidebar.contextDraftTitle"),hint:o("rightSidebar.contextDraftHint"),placeholder:o("rightSidebar.contextDraftPlaceholder"),collapse:o("rightSidebar.contextDraftCollapse"),expand:o("rightSidebar.contextDraftExpand"),disable:o("rightSidebar.contextDraftDisable"),clear:o("rightSidebar.contextDraftClear"),insert:o("rightSidebar.contextDraftInsert"),insertAndSend:o("rightSidebar.contextDraftInsertAndSend"),inserted:o("rightSidebar.contextDraftInserted"),sent:o("rightSidebar.contextDraftSent"),send:o("rightSidebar.contextDraftSend"),appended:o("rightSidebar.contextDraftAppended"),resize:o("rightSidebar.contextDraftResize"),autoCollapseAfterSend:o("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>o("rightSidebar.contextDraftCharacterCount",{count:t})}}),Dh(),vt&&typeof document<"u"&&kr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>un(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:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:vt.kind==="restore"?o("rightSidebar.confirmRestoreTitle"):o("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:vt.kind==="restore"?o("rightSidebar.confirmRestoreDescription",{path:Tu(vt.file.absolutePath,x)}):o("rightSidebar.confirmStashAllDescription")}),vt.kind==="restore"&&e.jsx("input",{value:vt.phrase,onChange:t=>un({...vt,phrase:t.target.value}),placeholder:o("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:()=>un(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:o("common.cancel")}),e.jsx("button",{type:"button",disabled:!!ze||vt.kind==="restore"&&vt.phrase.trim()!==o("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(vt.kind==="restore"){const t=bt(vt.file,x);if(!t)return;wt({action:"restore-worktree-file",cwd:t,paths:[vt.file.path],confirm:{acknowledged:!0,phrase:vt.phrase}},o("rightSidebar.restoreFile"),Yi(vt.file))}else{const t=vt.repoRoot??x;if(!t)return;wt({action:"stash-all",cwd:t},o("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${vt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:o(ze?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const Hx=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:yl,MarkdownImageLightbox:Wf,MarkdownPreview:Gf,RightSidebar:$x,__testParseMarkdownListBlock:qb,buildMarkdownPreviewBlocks:sx,buildMarkdownPreviewRenderResult:Pl,collectKnownGitRepoRoots:pf,computeMarkdownImageDisplayBox:Cf,getMarkdownHeadingOutline:zf,getMarkdownHeadingPathAtLine:Hf,getNextMarkdownPreviewLineRange:dx,isSvgImageSrc:Co,mountRightSidebarRepoPickerOverlay:tf,replaceGitRepositorySnapshot:Jf,resolveMarkdownLocalLinkTarget:Nl,resolveRightSidebarDiffViewType:hf,shouldCloseMarkdownImageLightboxDrag:Bf,showsGitRepoGroupHeader:ul},Symbol.toStringTag,{value:"Module"}));export{sl as E,Hx as R,Sp as a,Hp as c,Ux as m};
|