termdock 1.4.254 → 1.4.255
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-DUN01sjH.js → App-By5NgCF9.js} +36 -36
- package/dist/client/assets/App-By5NgCF9.js.br +0 -0
- package/dist/client/assets/App-By5NgCF9.js.gz +0 -0
- package/dist/client/assets/{ChangeWalkthroughPanel-BKgw7uwn.js → ChangeWalkthroughPanel-DJkbghZv.js} +1 -1
- package/dist/client/assets/ChangeWalkthroughPanel-DJkbghZv.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-DJkbghZv.js.gz +0 -0
- package/dist/client/assets/{DagPlayground-DcDIH-JE.js → DagPlayground-D7jKADVh.js} +1 -1
- package/dist/client/assets/DagPlayground-D7jKADVh.js.br +0 -0
- package/dist/client/assets/DagPlayground-D7jKADVh.js.gz +0 -0
- package/dist/client/assets/{DiffLab-C6EDHcn9.js → DiffLab-DO9GlXnk.js} +1 -1
- package/dist/client/assets/DiffLab-DO9GlXnk.js.br +0 -0
- package/dist/client/assets/DiffLab-DO9GlXnk.js.gz +0 -0
- package/dist/client/assets/{DiffReview-M1yMvDJm.js → DiffReview-DEXctUC6.js} +1 -1
- package/dist/client/assets/DiffReview-DEXctUC6.js.br +0 -0
- package/dist/client/assets/DiffReview-DEXctUC6.js.gz +0 -0
- package/dist/client/assets/{DiffReviewLab-IxBu2Jhy.js → DiffReviewLab-Ly6yxJmM.js} +1 -1
- package/dist/client/assets/DiffReviewLab-Ly6yxJmM.js.br +0 -0
- package/dist/client/assets/DiffReviewLab-Ly6yxJmM.js.gz +0 -0
- package/dist/client/assets/{DiffViewer-BplAmfVX.js → DiffViewer-BPlz1EKX.js} +1 -1
- package/dist/client/assets/DiffViewer-BPlz1EKX.js.br +0 -0
- package/dist/client/assets/DiffViewer-BPlz1EKX.js.gz +0 -0
- package/dist/client/assets/{ModelPreview-BktvfOu3.js → ModelPreview-jn0vZDsm.js} +1 -1
- package/dist/client/assets/ModelPreview-jn0vZDsm.js.br +0 -0
- package/dist/client/assets/ModelPreview-jn0vZDsm.js.gz +0 -0
- package/dist/client/assets/{RightSidebar-BtUbjvuk.js → RightSidebar-Dv5QyBwQ.js} +23 -23
- package/dist/client/assets/RightSidebar-Dv5QyBwQ.js.br +0 -0
- package/dist/client/assets/RightSidebar-Dv5QyBwQ.js.gz +0 -0
- package/dist/client/assets/{abnfDiagram-VCTEODGH-BW9uDKEa.js → abnfDiagram-VCTEODGH-Bv96bwkp.js} +1 -1
- package/dist/client/assets/abnfDiagram-VCTEODGH-Bv96bwkp.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-Bv96bwkp.js.gz +0 -0
- package/dist/client/assets/{app-xeVXFEoQ.js → app-DyKSx7Mz.js} +3 -3
- package/dist/client/assets/app-DyKSx7Mz.js.br +0 -0
- package/dist/client/assets/app-DyKSx7Mz.js.gz +0 -0
- package/dist/client/assets/{arc-CHvEinNX.js → arc-Bdutazby.js} +1 -1
- package/dist/client/assets/arc-Bdutazby.js.br +0 -0
- package/dist/client/assets/arc-Bdutazby.js.gz +0 -0
- package/dist/client/assets/{architectureDiagram-5GKGNRK7-CQhdC45P.js → architectureDiagram-5GKGNRK7-C5Lutsn8.js} +1 -1
- package/dist/client/assets/architectureDiagram-5GKGNRK7-C5Lutsn8.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-C5Lutsn8.js.gz +0 -0
- package/dist/client/assets/{blockDiagram-I7D4REHJ-BOxomMhb.js → blockDiagram-I7D4REHJ-DoTWrGLo.js} +1 -1
- package/dist/client/assets/blockDiagram-I7D4REHJ-DoTWrGLo.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-DoTWrGLo.js.gz +0 -0
- package/dist/client/assets/{c4Diagram-7LVT6UL2-DSM3tyKf.js → c4Diagram-7LVT6UL2-ZRiB7mhU.js} +1 -1
- package/dist/client/assets/c4Diagram-7LVT6UL2-ZRiB7mhU.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-ZRiB7mhU.js.gz +0 -0
- package/dist/client/assets/channel-DRk1RkSj.js +1 -0
- package/dist/client/assets/{chunk-2Q5K7J3B-BzoVnsHL.js → chunk-2Q5K7J3B-DhNBZb2u.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-DJDhE6TC.js → chunk-5VM5RSS4-BHZFuxQW.js} +1 -1
- package/dist/client/assets/{chunk-F27PBJKO-D8hyPkQH.js → chunk-F27PBJKO-CMIphDpA.js} +1 -1
- package/dist/client/assets/chunk-F27PBJKO-CMIphDpA.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-CMIphDpA.js.gz +0 -0
- package/dist/client/assets/{chunk-IMKFNOWR-BNw9KbwS.js → chunk-IMKFNOWR-BDe7e8jA.js} +1 -1
- package/dist/client/assets/chunk-IMKFNOWR-BDe7e8jA.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-BDe7e8jA.js.gz +0 -0
- package/dist/client/assets/{chunk-JWPE2WC7-NZf7kJas.js → chunk-JWPE2WC7-OPwpFYFs.js} +1 -1
- package/dist/client/assets/{chunk-POPQ4Y6H-B0gdSjPa.js → chunk-POPQ4Y6H-Bgn6X4is.js} +1 -1
- package/dist/client/assets/{chunk-SVP7TREG-BXBG4u7p.js → chunk-SVP7TREG-CndFuFdB.js} +1 -1
- package/dist/client/assets/chunk-SVP7TREG-CndFuFdB.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-CndFuFdB.js.gz +0 -0
- package/dist/client/assets/{chunk-TICWLB2K-DKb-77nl.js → chunk-TICWLB2K-CcTAB1T8.js} +1 -1
- package/dist/client/assets/chunk-TICWLB2K-CcTAB1T8.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-CcTAB1T8.js.gz +0 -0
- package/dist/client/assets/{chunk-XXDRQBXY-BneqFAer.js → chunk-XXDRQBXY-cRFuDAoI.js} +1 -1
- package/dist/client/assets/classDiagram-ZZMXUADV-rgfIggQ0.js +1 -0
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-rgfIggQ0.js +1 -0
- package/dist/client/assets/{cose-bilkent-JH36ORCC-C8IZvnC6.js → cose-bilkent-JH36ORCC-CtkHODw6.js} +1 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-CtkHODw6.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-CtkHODw6.js.gz +0 -0
- package/dist/client/assets/{cynefin-OW5HDTMX-DDBQbhQs.js → cynefin-OW5HDTMX-xjPGDvew.js} +1 -1
- package/dist/client/assets/cynefin-OW5HDTMX-xjPGDvew.js.br +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-xjPGDvew.js.gz +0 -0
- package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-VflKH0wb.js → cynefinDiagram-5FMLGOSQ-D0gENXW-.js} +1 -1
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-D0gENXW-.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-D0gENXW-.js.gz +0 -0
- package/dist/client/assets/{dagre-GXQ25YYZ-Cnq-y5YV.js → dagre-GXQ25YYZ-DrpJ83DN.js} +1 -1
- package/dist/client/assets/dagre-GXQ25YYZ-DrpJ83DN.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-DrpJ83DN.js.gz +0 -0
- package/dist/client/assets/{diagram-S7CK7UJ4-H9xjyXbh.js → diagram-S7CK7UJ4-CjcQn0kl.js} +1 -1
- package/dist/client/assets/diagram-S7CK7UJ4-CjcQn0kl.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-CjcQn0kl.js.gz +0 -0
- package/dist/client/assets/{diagram-UQ7AKVKN-Bb2Da5Q5.js → diagram-UQ7AKVKN-hvQHUxqm.js} +1 -1
- package/dist/client/assets/diagram-UQ7AKVKN-hvQHUxqm.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-hvQHUxqm.js.gz +0 -0
- package/dist/client/assets/{diagram-VSXAHHWV-BZpHMdKx.js → diagram-VSXAHHWV-BrTUApG2.js} +1 -1
- package/dist/client/assets/diagram-VSXAHHWV-BrTUApG2.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-BrTUApG2.js.gz +0 -0
- package/dist/client/assets/{diagram-VX7I27RA-TPtfTwWC.js → diagram-VX7I27RA-DmnmEkUV.js} +1 -1
- package/dist/client/assets/diagram-VX7I27RA-DmnmEkUV.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-DmnmEkUV.js.gz +0 -0
- package/dist/client/assets/{diagram-Z3DM3KII-CKFEAKhS.js → diagram-Z3DM3KII-C3snQW6_.js} +1 -1
- package/dist/client/assets/diagram-Z3DM3KII-C3snQW6_.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-C3snQW6_.js.gz +0 -0
- package/dist/client/assets/{ebnfDiagram-PWID7BFC-DG6pxUcX.js → ebnfDiagram-PWID7BFC-CFx5y6O_.js} +1 -1
- package/dist/client/assets/ebnfDiagram-PWID7BFC-CFx5y6O_.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-CFx5y6O_.js.gz +0 -0
- package/dist/client/assets/{erDiagram-RLTQ6QDP-DAasNlBB.js → erDiagram-RLTQ6QDP-CEO1mGX9.js} +1 -1
- package/dist/client/assets/erDiagram-RLTQ6QDP-CEO1mGX9.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-CEO1mGX9.js.gz +0 -0
- package/dist/client/assets/{flowDiagram-HODETNUW-xhoAaz9Q.js → flowDiagram-HODETNUW-DczILCSj.js} +1 -1
- package/dist/client/assets/flowDiagram-HODETNUW-DczILCSj.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-DczILCSj.js.gz +0 -0
- package/dist/client/assets/{ganttDiagram-EL5Y4UJY-DycnNfVN.js → ganttDiagram-EL5Y4UJY-CWfbOBx-.js} +1 -1
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-CWfbOBx-.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-CWfbOBx-.js.gz +0 -0
- package/dist/client/assets/{gestureArbiter-DfEbdDLy.js → gestureArbiter-DtC8HeYn.js} +1 -1
- package/dist/client/assets/gestureArbiter-DtC8HeYn.js.br +0 -0
- package/dist/client/assets/gestureArbiter-DtC8HeYn.js.gz +0 -0
- package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-ugsxyTX1.js → gitGraphDiagram-WWUBYQGX-CJaquhnL.js} +1 -1
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CJaquhnL.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CJaquhnL.js.gz +0 -0
- package/dist/client/assets/{infoDiagram-27XIBGKW-Cf35duXO.js → infoDiagram-27XIBGKW-BrpNYnlX.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-5VMMS53U-CHgP7O8Q.js → ishikawaDiagram-5VMMS53U-BeUcPryy.js} +1 -1
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-BeUcPryy.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-BeUcPryy.js.gz +0 -0
- package/dist/client/assets/{journeyDiagram-3NMN7TZE-DvgYJYK0.js → journeyDiagram-3NMN7TZE-DrkmI2C_.js} +1 -1
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DrkmI2C_.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DrkmI2C_.js.gz +0 -0
- package/dist/client/assets/{kanban-definition-UXKFOSKX-CmQu1IPn.js → kanban-definition-UXKFOSKX-DUYKiPom.js} +1 -1
- package/dist/client/assets/kanban-definition-UXKFOSKX-DUYKiPom.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-DUYKiPom.js.gz +0 -0
- package/dist/client/assets/{layout-Bp8bIVj7.js → layout-XWY2OfU8.js} +1 -1
- package/dist/client/assets/layout-XWY2OfU8.js.br +0 -0
- package/dist/client/assets/layout-XWY2OfU8.js.gz +0 -0
- package/dist/client/assets/{linear-CFRqYftw.js → linear-CKK22C_V.js} +1 -1
- package/dist/client/assets/linear-CKK22C_V.js.br +0 -0
- package/dist/client/assets/linear-CKK22C_V.js.gz +0 -0
- package/dist/client/assets/{mermaid.core-tQO4G1xW.js → mermaid.core-VzkSqOKz.js} +5 -5
- package/dist/client/assets/mermaid.core-VzkSqOKz.js.br +0 -0
- package/dist/client/assets/mermaid.core-VzkSqOKz.js.gz +0 -0
- package/dist/client/assets/{mindmap-definition-YA3MSWOX-D1_mF82L.js → mindmap-definition-YA3MSWOX-D0g720Ty.js} +1 -1
- package/dist/client/assets/mindmap-definition-YA3MSWOX-D0g720Ty.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-D0g720Ty.js.gz +0 -0
- package/dist/client/assets/{passwordBootstrap-Bxy2dCQ-.js → passwordBootstrap-BaRrnJWI.js} +1 -1
- package/dist/client/assets/passwordBootstrap-BaRrnJWI.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-BaRrnJWI.js.gz +0 -0
- package/dist/client/assets/{pegDiagram-XKGWAZYB-Cjq0Kx05.js → pegDiagram-XKGWAZYB-F-tmYn5J.js} +1 -1
- package/dist/client/assets/pegDiagram-XKGWAZYB-F-tmYn5J.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-F-tmYn5J.js.gz +0 -0
- package/dist/client/assets/{pieDiagram-E7YTZNPT-DzRJDPgH.js → pieDiagram-E7YTZNPT-w551-rUm.js} +1 -1
- package/dist/client/assets/pieDiagram-E7YTZNPT-w551-rUm.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-w551-rUm.js.gz +0 -0
- package/dist/client/assets/{quadrantDiagram-AXDQQJYC-DR9FFrqS.js → quadrantDiagram-AXDQQJYC-CCEGbNxI.js} +1 -1
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-CCEGbNxI.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-CCEGbNxI.js.gz +0 -0
- package/dist/client/assets/{railroadDiagram-O6MQD6OU-B23Qp9aW.js → railroadDiagram-O6MQD6OU-obfo4yCA.js} +1 -1
- package/dist/client/assets/railroadDiagram-O6MQD6OU-obfo4yCA.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-obfo4yCA.js.gz +0 -0
- package/dist/client/assets/{referenceLongPress-BEsxlfz0.js → referenceLongPress-BZpZjDWj.js} +1 -1
- package/dist/client/assets/referenceLongPress-BZpZjDWj.js.br +0 -0
- package/dist/client/assets/referenceLongPress-BZpZjDWj.js.gz +0 -0
- package/dist/client/assets/{requirementDiagram-BXWQKSXE-DgrqUDn8.js → requirementDiagram-BXWQKSXE-DGxq6_tu.js} +1 -1
- package/dist/client/assets/requirementDiagram-BXWQKSXE-DGxq6_tu.js.br +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-DGxq6_tu.js.gz +0 -0
- package/dist/client/assets/{sankeyDiagram-P5KCCOFB-58t8XkME.js → sankeyDiagram-P5KCCOFB-a4XciJtk.js} +1 -1
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-a4XciJtk.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-a4XciJtk.js.gz +0 -0
- package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-CmUoZkds.js → sequenceDiagram-WJ2MYXX4-d868a5nP.js} +1 -1
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-d868a5nP.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-d868a5nP.js.gz +0 -0
- package/dist/client/assets/{sizeCapture-INFHLROL-77jVrQ94.js → sizeCapture-INFHLROL-DfDcxTH5.js} +1 -1
- package/dist/client/assets/sizeCapture-INFHLROL-DfDcxTH5.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-DfDcxTH5.js.gz +0 -0
- package/dist/client/assets/{sparkles-cjS43NnG.js → sparkles-B-rI69hg.js} +1 -1
- package/dist/client/assets/{stateDiagram-D77RDMKH-C4pg4fDV.js → stateDiagram-D77RDMKH-_rlkjaFb.js} +1 -1
- package/dist/client/assets/stateDiagram-D77RDMKH-_rlkjaFb.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-_rlkjaFb.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-B8Kq1U38.js +1 -0
- package/dist/client/assets/{swimlanes-42K2YHIH-D6LWPp6D.js → swimlanes-42K2YHIH-DoDpL828.js} +1 -1
- package/dist/client/assets/swimlanes-42K2YHIH-DoDpL828.js.br +0 -0
- package/dist/client/assets/{swimlanes-42K2YHIH-D6LWPp6D.js.gz → swimlanes-42K2YHIH-DoDpL828.js.gz} +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-CzMZEhpW.js +8 -0
- package/dist/client/assets/{timeline-definition-24CTP7MA-CGss01YN.js → timeline-definition-24CTP7MA-DrYLDIfs.js} +1 -1
- package/dist/client/assets/timeline-definition-24CTP7MA-DrYLDIfs.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-DrYLDIfs.js.gz +0 -0
- package/dist/client/assets/{triangle-alert-CB88m01k.js → triangle-alert-CyykxOx-.js} +1 -1
- package/dist/client/assets/{vennDiagram-4TSXK5OY-BAa-WaNo.js → vennDiagram-4TSXK5OY-Ch97JoeR.js} +1 -1
- package/dist/client/assets/vennDiagram-4TSXK5OY-Ch97JoeR.js.br +0 -0
- package/dist/client/assets/{vennDiagram-4TSXK5OY-BAa-WaNo.js.gz → vennDiagram-4TSXK5OY-Ch97JoeR.js.gz} +0 -0
- package/dist/client/assets/{wardleyDiagram-VM6X3IG4-Dh2Ev2xt.js → wardleyDiagram-VM6X3IG4-DoXfEj4Q.js} +1 -1
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DoXfEj4Q.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-DoXfEj4Q.js.gz +0 -0
- package/dist/client/assets/{xychartDiagram-S5SC5T6Z-DP9NVLab.js → xychartDiagram-S5SC5T6Z-DaavXfGD.js} +1 -1
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DaavXfGD.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DaavXfGD.js.gz +0 -0
- package/dist/client/index.html +1 -1
- 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/routes/terminal.js +1 -0
- package/dist/server/utils/settings.js +11 -1
- package/package.json +1 -1
- package/runtime-manifest.json +3 -3
- package/dist/client/assets/App-DUN01sjH.js.br +0 -0
- package/dist/client/assets/App-DUN01sjH.js.gz +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-BKgw7uwn.js.br +0 -0
- package/dist/client/assets/ChangeWalkthroughPanel-BKgw7uwn.js.gz +0 -0
- package/dist/client/assets/DagPlayground-DcDIH-JE.js.br +0 -0
- package/dist/client/assets/DagPlayground-DcDIH-JE.js.gz +0 -0
- package/dist/client/assets/DiffLab-C6EDHcn9.js.br +0 -0
- package/dist/client/assets/DiffLab-C6EDHcn9.js.gz +0 -0
- package/dist/client/assets/DiffReview-M1yMvDJm.js.br +0 -0
- package/dist/client/assets/DiffReview-M1yMvDJm.js.gz +0 -0
- package/dist/client/assets/DiffReviewLab-IxBu2Jhy.js.br +0 -0
- package/dist/client/assets/DiffReviewLab-IxBu2Jhy.js.gz +0 -0
- package/dist/client/assets/DiffViewer-BplAmfVX.js.br +0 -0
- package/dist/client/assets/DiffViewer-BplAmfVX.js.gz +0 -0
- package/dist/client/assets/ModelPreview-BktvfOu3.js.br +0 -0
- package/dist/client/assets/ModelPreview-BktvfOu3.js.gz +0 -0
- package/dist/client/assets/RightSidebar-BtUbjvuk.js.br +0 -0
- package/dist/client/assets/RightSidebar-BtUbjvuk.js.gz +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-BW9uDKEa.js.br +0 -0
- package/dist/client/assets/abnfDiagram-VCTEODGH-BW9uDKEa.js.gz +0 -0
- package/dist/client/assets/app-xeVXFEoQ.js.br +0 -0
- package/dist/client/assets/app-xeVXFEoQ.js.gz +0 -0
- package/dist/client/assets/arc-CHvEinNX.js.br +0 -0
- package/dist/client/assets/arc-CHvEinNX.js.gz +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-CQhdC45P.js.br +0 -0
- package/dist/client/assets/architectureDiagram-5GKGNRK7-CQhdC45P.js.gz +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-BOxomMhb.js.br +0 -0
- package/dist/client/assets/blockDiagram-I7D4REHJ-BOxomMhb.js.gz +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-DSM3tyKf.js.br +0 -0
- package/dist/client/assets/c4Diagram-7LVT6UL2-DSM3tyKf.js.gz +0 -0
- package/dist/client/assets/channel-Cgd1Bekt.js +0 -1
- package/dist/client/assets/chunk-F27PBJKO-D8hyPkQH.js.br +0 -0
- package/dist/client/assets/chunk-F27PBJKO-D8hyPkQH.js.gz +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-BNw9KbwS.js.br +0 -0
- package/dist/client/assets/chunk-IMKFNOWR-BNw9KbwS.js.gz +0 -0
- package/dist/client/assets/chunk-SVP7TREG-BXBG4u7p.js.br +0 -0
- package/dist/client/assets/chunk-SVP7TREG-BXBG4u7p.js.gz +0 -0
- package/dist/client/assets/chunk-TICWLB2K-DKb-77nl.js.br +0 -0
- package/dist/client/assets/chunk-TICWLB2K-DKb-77nl.js.gz +0 -0
- package/dist/client/assets/classDiagram-ZZMXUADV-1Ik-dkBM.js +0 -1
- package/dist/client/assets/classDiagram-v2-VYDZK3BY-1Ik-dkBM.js +0 -1
- package/dist/client/assets/cose-bilkent-JH36ORCC-C8IZvnC6.js.br +0 -0
- package/dist/client/assets/cose-bilkent-JH36ORCC-C8IZvnC6.js.gz +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-DDBQbhQs.js.br +0 -0
- package/dist/client/assets/cynefin-OW5HDTMX-DDBQbhQs.js.gz +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-VflKH0wb.js.br +0 -0
- package/dist/client/assets/cynefinDiagram-5FMLGOSQ-VflKH0wb.js.gz +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-Cnq-y5YV.js.br +0 -0
- package/dist/client/assets/dagre-GXQ25YYZ-Cnq-y5YV.js.gz +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-H9xjyXbh.js.br +0 -0
- package/dist/client/assets/diagram-S7CK7UJ4-H9xjyXbh.js.gz +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-Bb2Da5Q5.js.br +0 -0
- package/dist/client/assets/diagram-UQ7AKVKN-Bb2Da5Q5.js.gz +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-BZpHMdKx.js.br +0 -0
- package/dist/client/assets/diagram-VSXAHHWV-BZpHMdKx.js.gz +0 -0
- package/dist/client/assets/diagram-VX7I27RA-TPtfTwWC.js.br +0 -0
- package/dist/client/assets/diagram-VX7I27RA-TPtfTwWC.js.gz +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-CKFEAKhS.js.br +0 -0
- package/dist/client/assets/diagram-Z3DM3KII-CKFEAKhS.js.gz +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-DG6pxUcX.js.br +0 -0
- package/dist/client/assets/ebnfDiagram-PWID7BFC-DG6pxUcX.js.gz +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-DAasNlBB.js.br +0 -0
- package/dist/client/assets/erDiagram-RLTQ6QDP-DAasNlBB.js.gz +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-xhoAaz9Q.js.br +0 -0
- package/dist/client/assets/flowDiagram-HODETNUW-xhoAaz9Q.js.gz +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-DycnNfVN.js.br +0 -0
- package/dist/client/assets/ganttDiagram-EL5Y4UJY-DycnNfVN.js.gz +0 -0
- package/dist/client/assets/gestureArbiter-DfEbdDLy.js.br +0 -0
- package/dist/client/assets/gestureArbiter-DfEbdDLy.js.gz +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-ugsxyTX1.js.br +0 -0
- package/dist/client/assets/gitGraphDiagram-WWUBYQGX-ugsxyTX1.js.gz +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-CHgP7O8Q.js.br +0 -0
- package/dist/client/assets/ishikawaDiagram-5VMMS53U-CHgP7O8Q.js.gz +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DvgYJYK0.js.br +0 -0
- package/dist/client/assets/journeyDiagram-3NMN7TZE-DvgYJYK0.js.gz +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-CmQu1IPn.js.br +0 -0
- package/dist/client/assets/kanban-definition-UXKFOSKX-CmQu1IPn.js.gz +0 -0
- package/dist/client/assets/layout-Bp8bIVj7.js.br +0 -0
- package/dist/client/assets/layout-Bp8bIVj7.js.gz +0 -0
- package/dist/client/assets/linear-CFRqYftw.js.br +0 -0
- package/dist/client/assets/linear-CFRqYftw.js.gz +0 -0
- package/dist/client/assets/mermaid.core-tQO4G1xW.js.br +0 -0
- package/dist/client/assets/mermaid.core-tQO4G1xW.js.gz +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-D1_mF82L.js.br +0 -0
- package/dist/client/assets/mindmap-definition-YA3MSWOX-D1_mF82L.js.gz +0 -0
- package/dist/client/assets/passwordBootstrap-Bxy2dCQ-.js.br +0 -0
- package/dist/client/assets/passwordBootstrap-Bxy2dCQ-.js.gz +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-Cjq0Kx05.js.br +0 -0
- package/dist/client/assets/pegDiagram-XKGWAZYB-Cjq0Kx05.js.gz +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-DzRJDPgH.js.br +0 -0
- package/dist/client/assets/pieDiagram-E7YTZNPT-DzRJDPgH.js.gz +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-DR9FFrqS.js.br +0 -0
- package/dist/client/assets/quadrantDiagram-AXDQQJYC-DR9FFrqS.js.gz +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-B23Qp9aW.js.br +0 -0
- package/dist/client/assets/railroadDiagram-O6MQD6OU-B23Qp9aW.js.gz +0 -0
- package/dist/client/assets/referenceLongPress-BEsxlfz0.js.br +0 -0
- package/dist/client/assets/referenceLongPress-BEsxlfz0.js.gz +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-DgrqUDn8.js.br +0 -0
- package/dist/client/assets/requirementDiagram-BXWQKSXE-DgrqUDn8.js.gz +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-58t8XkME.js.br +0 -0
- package/dist/client/assets/sankeyDiagram-P5KCCOFB-58t8XkME.js.gz +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-CmUoZkds.js.br +0 -0
- package/dist/client/assets/sequenceDiagram-WJ2MYXX4-CmUoZkds.js.gz +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-77jVrQ94.js.br +0 -0
- package/dist/client/assets/sizeCapture-INFHLROL-77jVrQ94.js.gz +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-C4pg4fDV.js.br +0 -0
- package/dist/client/assets/stateDiagram-D77RDMKH-C4pg4fDV.js.gz +0 -0
- package/dist/client/assets/stateDiagram-v2-MP3YSRHH-B5YOJ5EZ.js +0 -1
- package/dist/client/assets/swimlanes-42K2YHIH-D6LWPp6D.js.br +0 -0
- package/dist/client/assets/swimlanesDiagram-VR7AAH4N-BvX87YrB.js +0 -8
- package/dist/client/assets/timeline-definition-24CTP7MA-CGss01YN.js.br +0 -0
- package/dist/client/assets/timeline-definition-24CTP7MA-CGss01YN.js.gz +0 -0
- package/dist/client/assets/vennDiagram-4TSXK5OY-BAa-WaNo.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-Dh2Ev2xt.js.br +0 -0
- package/dist/client/assets/wardleyDiagram-VM6X3IG4-Dh2Ev2xt.js.gz +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DP9NVLab.js.br +0 -0
- package/dist/client/assets/xychartDiagram-S5SC5T6Z-DP9NVLab.js.gz +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-
|
|
2
|
-
import{a4 as er,bd as e,cH as Rt,cR as St,bv as ot,a as $s,aM as
|
|
3
|
-
`)}function Zb(t,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(t,1e-6)/Math.sin(u)*1.15}async function rp(t,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(t,n);return}const u=new Date().toISOString(),c=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(m?tp(t,"",u,m):t,n)}function np(t,n){return t===n||n.endsWith(`/${t}`)||t.endsWith(`/${n}`)}function
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-jn0vZDsm.js","assets/app-DyKSx7Mz.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-mZxreyvP.css","assets/App-By5NgCF9.js","assets/gestureArbiter-DtC8HeYn.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-CyykxOx-.js","assets/referenceLongPress-BZpZjDWj.js","assets/DiffReview-DEXctUC6.js","assets/sparkles-B-rI69hg.js","assets/DiffViewer-BPlz1EKX.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-DJkbghZv.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-VzkSqOKz.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a4 as er,bd as e,cH as Rt,cR as St,bv as ot,a as $s,aM as qd,C as ki,c as Ls,X as Gt,cE as Si,b1 as Nh,z as vs,al as Mh,cL as Z,b5 as Eh,b7 as Ki,b8 as $h,b9 as Kd,b6 as ys,ay as Lh,E as Ah,i as Ph,b4 as Th,bx as Ih,bz as Dh,bA as _h,aY as Fh,by as Vc,y as kt,f as Bh,L as jt,v as Oh,b as Uh,cG as Yc,aX as Xc,au as Jc,aq as Hh,aC as Ea,aD as Qc,cS as Cs,ah as ws,aE as zh,cF as ti,bp as Wh,cq as Zc,aw as Gh,cC as qh,b_ as Kh,aH as Vh,O as ed,N as Yh,ar as Xh,av as Jh,aA as td,c0 as Qh,s as Zh,d as $a,g as ji,m as rd,w as Vd,ad as em,_ as As,bU as tm,cP as rm,bk as nm,af as sm}from"./app-DyKSx7Mz.js";import{i as am,p as nd,t as Wa,g as om,V as im,P as lm,m as cm,o as dm,R as Ri,u as Yd,v as um,S as Jn,D as fm,e as Xd,c as hm,B as Jd,A as sd,y as La,w as mm,x as pm,z as gm,E as ad,T as od,H as id,f as ld,l as ri,k as Aa,d as bm,q as xm,j as vm,h as ym,r as wm,F as cd,C as km,a as Sm,G as jm}from"./App-By5NgCF9.js";import{b as a,r as en}from"./dnd-BCFAPC0L.js";import{a as Rm,S as Cm,b as Qd,c as Ci,F as Nm}from"./gestureArbiter-DtC8HeYn.js";import{D as Ni,C as Ns,L as Zd,f as Mm,n as Em}from"./DiffReview-DEXctUC6.js";import{T as $m,L as Va,M as eu,G as Lr}from"./triangle-alert-CyykxOx-.js";import{S as Ps}from"./sparkles-B-rI69hg.js";import{C as tu,M as ru}from"./ChangeWalkthroughPanel-DJkbghZv.js";import{r as nu,s as su,l as au,u as Lm,h as ou}from"./DiffViewer-BPlz1EKX.js";import{u as iu,G as lu}from"./referenceLongPress-BZpZjDWj.js";const Am=[["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"}]],Pm=er("case-sensitive",Am);const Tm=[["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"}]],Im=er("eye-off",Tm);const Dm=[["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"}]],Mi=er("eye",Dm);const _m=[["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"}]],Ei=er("file-text",_m);const Fm=[["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"}]],Bm=er("image-plus",Fm);const Om=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]],Um=er("maximize",Om);const Hm=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]],zm=er("minimize",Hm);const Wm=[["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"}]],Gm=er("regex",Wm);const qm=[["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"}]],Km=er("scan",qm);const Vm=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Ym=er("upload",Vm);const Xm=[["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"}]],Jm=er("whole-word",Xm);async function Qm(t){let n;try{await Promise.race([t(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function Zm({active:t,rootPath:n,loading:s,delay:l,lastStartedRoot:u,load:c}){a.useEffect(()=>{if(!t||!n||s||u.current===n)return;const h=window.setTimeout(()=>{u.current=n,c(n)},l);return()=>window.clearTimeout(h)},[t,n,s,l,u,c])}function ep(t,n,s){try{const l=t instanceof HTMLImageElement?t.naturalWidth:t.width,u=t instanceof HTMLImageElement?t.naturalHeight:t.height;if(!l||!u)return Promise.resolve(null);const c=t instanceof HTMLImageElement?1400/Math.max(l,u):Math.min(1,1400/Math.max(l,u)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(u*c));const m=h.getContext("2d");if(!m)return Promise.resolve(null);const g=getComputedStyle(document.documentElement);if(m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,h.height),m.drawImage(t,0,0,h.width,h.height),s){const b=Math.max(10,Math.min(16,h.width/35));m.font=`${b}px sans-serif`;const f=[];let S="";for(const y of s.split(" "))S&&m.measureText(`${S} ${y}`).width>h.width-20?(f.push(S),S=y):S=S?`${S} ${y}`:y;S&&f.push(S),m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,f.length*(b+4)+12),m.fillStyle=g.getPropertyValue("--foreground").trim()||"black",f.forEach((y,C)=>m.fillText(y,10,8+b+C*(b+4)))}if(n){const b=n.xPercent*h.width/100,f=n.yPercent*h.height/100,S=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=S*1.6;m.strokeStyle=g.getPropertyValue("--primary").trim()||"black",m.lineWidth=Math.max(1,S/3),m.beginPath(),m.arc(b,f,S,0,Math.PI*2),m.stroke(),m.beginPath(),m.moveTo(b-y,f),m.lineTo(b+y,f),m.moveTo(b,f-y),m.lineTo(b,f+y),m.stroke()}return new Promise(b=>h.toBlob(b,"image/png"))}catch{return Promise.resolve(null)}}function tp(t,n,s,l){return[t.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
|
|
3
|
+
`)}function Zb(t,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(t,1e-6)/Math.sin(u)*1.15}async function rp(t,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(t,n);return}const u=new Date().toISOString(),c=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(m?tp(t,"",u,m):t,n)}function np(t,n){return t===n||n.endsWith(`/${t}`)||t.endsWith(`/${n}`)}function dd(t,n){return`${t??""}\0${n}`}function sp(t,n,s){if(!t||t.length===0||!s)return{explained:0,stale:0};const l=dd(n,s);let u=0,c=0;for(const h of t){const m=[h.filePath,h.newPath,h.oldPath].filter(b=>typeof b=="string"&&b.length>0);(m.some(b=>dd(h.repoRoot,b)===l)||m.some(b=>np(b,s)))&&(u+=1)}return{explained:u,stale:c}}function ap({status:t}){if(!t)return null;const n=t.stale>0&&t.explained===0;if(!(t.explained>0||t.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx($m,{size:10}):e.jsx(Ps,{size:10})})}function $i({changeStatus:t,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(t),e.jsx(ap,{status:n})]})}const cu="termdock:right-sidebar:diff-change-list-mode:v1";function op(t){return t==="list"||t==="tree"}function ip(){return ot(cu,op)??"tree"}function lp(t){for(const l of t){const u=l.hunk;if(u.oldPath&&u.newPath&&u.oldPath!==u.newPath)return"renamed";if(!u.oldPath&&u.newPath)return"added";if(u.oldPath&&!u.newPath)return"deleted"}const n=t.some(l=>l.hunk.additions>0),s=t.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function cp(t){const n=new Map;for(const l of t){const u=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};u.items.push(l),u.additions+=l.hunk.additions,u.deletions+=l.hunk.deletions,l.current&&(u.explained+=1),l.stale&&(u.stale+=1),n.set(l.hunk.filePath,u)}const s=Array.from(n.values()).sort((l,u)=>l.filePath.localeCompare(u.filePath));for(const l of s)l.changeType=lp(l.items);return s}function dp(t){const n=t.filePath.split("/").pop()??t.filePath;return{key:t.key,path:t.filePath,displayName:n,displayDir:t.filePath.includes("/")?t.filePath.slice(0,-n.length-1):"",status:t.changeType,title:t.filePath}}function up(t,n){const s=t.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],u=new Set;for(const[c,h]of s.entries()){const m=h.split(`
|
|
4
4
|
`),g=m.findIndex(S=>S.startsWith("@@ "));if(g<0){l.push(...m);continue}c===0&&l.push(...m.slice(0,g));const b=n[c];let f=g;for(;f>=0&&f<m.length;){const S=m.findIndex((E,N)=>N>f&&E.startsWith("@@ ")),y=S>=0?S:m.length,C=m.slice(f,y),I=C[0]??"",F=b?I===b:!0,B=I||b||C.join(`
|
|
5
5
|
`);F&&!u.has(B)&&(l.push(...C),u.add(B)),f=S}}return l.join(`
|
|
6
|
-
`)}function fp({groups:t,onInsertDiffReference:n}){return t.map(s=>{const l=up(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),u=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:u[0]?.repoRoot?`${u[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:u[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:u,onInsertDiffReference:n}})}function hp(t,n,s){const l=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=t.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<c)continue;const S=Math.abs(f.top-c);S<m&&(h=b,m=S)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function
|
|
7
|
-
`)[0]??"",q=/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 M=!1;const J=ni();return
|
|
6
|
+
`)}function fp({groups:t,onInsertDiffReference:n}){return t.map(s=>{const l=up(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),u=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:u[0]?.repoRoot?`${u[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:u[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:u,onInsertDiffReference:n}})}function hp(t,n,s){const l=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=t.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<c)continue;const S=Math.abs(f.top-c);S<m&&(h=b,m=S)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function ud({items:t,selectedKey:n,onSelect:s,emptyText:l,mobile:u=!1,backLabel:c="Back",headerTitle:h,headerMeta:m,onClose:g,closeLabel:b="Back",wrap:f=!0,onToggleWrap:S,wrapTitle:y,wrapOnLabel:C="Wrap on",wrapOffLabel:I="Wrap off",desktopLayout:F="split",onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:N,copiedReferenceKey:$,onClearAuditRecord:T,walkthroughs:U=[],onWalkthroughNavigate:D,initialDetailScrollTop:p,onDetailScrollPositionChange:i,scrollToKey:O,scrollToKeyNonce:j,externalSwiperRef:q,onMobileSlideChange:le}){const{t:ne}=Rt(),ue=a.useMemo(()=>cp(t),[t]),G=a.useMemo(()=>new Map(ue.map(ce=>[ce.key,ce])),[ue]),[Y,L]=a.useState(()=>ip()),[_,V]=a.useState(()=>new Set),[te,oe]=a.useState({key:null,nonce:0}),ge=ue.find(ce=>ce.explained>0||ce.stale>0)?.key??ue[0]?.key??null,he=n&&ue.some(ce=>ce.key===n)?n:ge,$e=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:ue.map(dp)}],[ue]),M=a.useMemo(()=>fp({groups:ue,onInsertDiffReference:B}),[ue,B]),J=a.useRef(ge),fe=a.useRef(s);J.current=ge,fe.current=s,a.useEffect(()=>{!n&&J.current&&fe.current(J.current)},[n]);const Re=S?e.jsxs("button",{type:"button",onClick:S,"aria-pressed":f,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"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:f?C:I})]}):null,qe=ce=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),m&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:m})]}),g&&e.jsxs("button",{type:"button",onClick:g,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($s,{size:14}),b]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ce,Re]})]});if(t.length===0){const ce=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!g?ce:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[qe(null),ce]})}const Ce=S?({slideToList:ce})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:ce,children:[e.jsx($s,{size:14}),c]}),e.jsxs("button",{type:"button",onClick:S,"aria-pressed":f,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"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:f?C:I})]})]}):void 0;return e.jsx(Ni,{mobile:u,desktopLayout:F,backLabel:c,groups:$e,selectedKey:he,mode:Y,onModeChange:ce=>{L(ce),ce!=="ai"&&St(cu,ce)},compact:u,collapsedDirectoryKeys:_,onToggleDirectory:ce=>{V(xe=>{const k=new Set(xe);return k.has(ce)?k.delete(ce):k.add(ce),k})},onSelectFile:ce=>{s(ce.key),oe(xe=>({key:ce.key,nonce:xe.nonce+1}))},renderLeading:ce=>{const xe=G.get(ce.key);return e.jsx($i,{changeStatus:ce.status,auditStatus:xe,renderChangeBadge:k=>e.jsx(Ns,{status:k})})},renderTrailing:ce=>{const xe=G.get(ce.key);return xe?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",xe.additions," -",xe.deletions]}):null},renderListHeader:qe,aiContent:({slideToDetail:ce,fullscreen:xe,toggleFullscreen:k})=>U.length>0&&D?e.jsx(tu,{walkthroughs:U,repoRoot:U[0]?.repoRoot,fullscreen:xe,onToggleFullscreen:k,onNavigate:Q=>{u&&window.requestAnimationFrame(ce),D(Q)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:ne("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Ce,externalSwiperRef:q,onMobileSlideChange:le,detailContainerClassName:u?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:p,scrollToKey:O??te.key,scrollToKeyNonce:O==null?te.nonce:j,onDetailScroll:ce=>{hp(ce,he,s),i?.(ce.scrollTop)},files:M,activePane:!0,wrap:f,renderStreamBadge:(ce,xe)=>{const k=G.get(xe.key);return e.jsx($i,{changeStatus:ce,auditStatus:k,renderChangeBadge:Q=>e.jsx(Ns,{status:Q})})},onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:N,copiedReferenceKey:$,onClearAuditRecord:T,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function mp(t){return t.replace(/\/+$/,"")||"/"}function pp(t){return[...new Set(Array.from(t,mp))].sort((n,s)=>n.localeCompare(s))}function gp(t){return t==="event-storm"||t==="reconnected"||t==="directory-rescan"||t==="polling-fallback"}function bp(t){let n=null;return{applicableEvents:t.filter(l=>{const u=l.type==="rescan-required"&&!gp(l.reason);return u&&l.reason&&!n&&(n=l.reason),!u}),unavailableReason:n}}const xp=1400,vp=1200,du=44,yp=.7;function ni(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function Li(t){return`termdock:right-sidebar:context-draft-height:${t}:v1`}function wp(t){try{const n=window.localStorage.getItem(Li(t)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=du?s:null}catch{return null}}function fd(t,n){try{n===null?window.localStorage.removeItem(Li(t)):window.localStorage.setItem(Li(t),String(n))}catch{}}function Pa(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function kp({value:t,collapsed:n,labels:s,focusRequest:l,insertError:u,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:m,onAutoCollapseAfterSendChange:g,onDisable:b,onClear:f,onInsert:S,onInsertAndSend:y}){const[C,I]=a.useState(null),[F,B]=a.useState(!1),[E,N]=a.useState(()=>wp(ni())),$=a.useRef(E),T=a.useRef(null),U=a.useRef(null),D=a.useRef(t),p=a.useRef(null),i=a.useRef(null),O=!!t.trim(),j=t.trim().split(`
|
|
7
|
+
`)[0]??"",q=/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 M=!1;const J=ni();return qd().then(fe=>{if(M)return;const Re=fe.contextDraftHeight?.[J]??null;fd(J,Re),$.current=Re,N(Re)}).catch(()=>{}),()=>{M=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const M=p.current;if(!M)return;Pa()||M.focus(),M.setSelectionRange(M.value.length,M.value.length),M.scrollTop=M.scrollHeight}},[l]),a.useEffect(()=>{const M=D.current;D.current=t,!(!n||t.length<=M.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},vp))},[t,n]),a.useEffect(()=>{if(n)return;const M=p.current;M&&(M.style.height=E!==null?`${E}px`:"")},[t,n,E]),a.useEffect(()=>{if(n)return;const M=p.current;!M||document.activeElement===M||(M.scrollTop=M.scrollHeight)},[t,n]),a.useEffect(()=>{if(n||Pa())return;const M=p.current;!M||document.activeElement===M||(M.focus(),M.setSelectionRange(M.value.length,M.value.length))},[n]);const le=a.useRef(null);a.useLayoutEffect(()=>{if(!Pa())return;const M=window.visualViewport;if(!M)return;const J=()=>{const fe=le.current;if(!fe)return;if(M.height>=window.innerHeight*.75){fe.style.transform="";return}const Re=fe.getBoundingClientRect(),qe=Math.round(M.height-Re.bottom);fe.style.transform=qe!==0?`translateY(${qe}px)`:""};return J(),M.addEventListener("resize",J),M.addEventListener("scroll",J),()=>{M.removeEventListener("resize",J),M.removeEventListener("scroll",J),le.current&&(le.current.style.transform="")}},[n]);const ne=M=>{I(M),T.current!==null&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{T.current=null,I(null)},xp)},ue=M=>{m(!1),Pa()&&window.requestAnimationFrame(()=>{const J=p.current;if(!J)return;J.focus();const fe=J.value.length;J.setSelectionRange(fe,fe),window.requestAnimationFrame(()=>{J.setSelectionRange(fe,fe)})})},G=()=>{S(),ne("inserted")},Y=()=>{O&&(y(),ne("sent"))},L=M=>{if(M.key==="Escape"){M.preventDefault(),m(!0);return}M.key!=="Enter"||!M.metaKey&&!M.ctrlKey||(M.preventDefault(),Y())},_=M=>{M.preventDefault()},V=M=>{M.preventDefault();const J=p.current;J&&(i.current={startY:M.clientY,startHeight:J.getBoundingClientRect().height},M.currentTarget.setPointerCapture?.(M.pointerId))},te=M=>{const J=i.current;if(!J)return;const fe=window.visualViewport?.height??window.innerHeight,Re=Math.round(Math.min(Math.max(J.startHeight+(J.startY-M.clientY),du),fe*yp));$.current=Re,N(Re)},oe=M=>{const J=ni();fd(J,M),Si({contextDraftHeight:{[J]:M}}).catch(()=>{})},ge=()=>{i.current&&(i.current=null,$.current!==null&&oe($.current))},he=()=>{$.current=null,N(null),oe(null)},$e=t.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(t.length)});return n?e.jsx("section",{ref:le,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:()=>ue(),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(am,{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] ${u?"text-destructive":F?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:u??(F?s.appended:O?j:s.title)})]}),$e,e.jsx("button",{type:"button",onClick:Y,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:C==="sent"?e.jsx(ki,{size:12}):e.jsx(nd,{size:12})})]})}):e.jsxs("section",{ref:le,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:V,onPointerMove:te,onPointerUp:ge,onPointerCancel:ge,onDoubleClick:he,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:()=>m(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Ls,{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}),$e]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:_,onClick:()=>g(!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:b,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(Gt,{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:p,value:t,onChange:M=>h(M.target.value),onKeyDown:L,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:f,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(Wa,{size:11})}),u?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:u}):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(om,{size:11}),e.jsx("span",{children:C==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:_,onClick:Y,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} · ${q}`,children:[C==="sent"?e.jsx(ki,{size:11}):e.jsx(nd,{size:11}),e.jsx("span",{children:C==="sent"?s.sent:s.send})]})]})]})})]})}function Sp(t,n){const s=n.trim();if(!s)return t;if(!t.trim())return s;const l=t.endsWith(`
|
|
8
8
|
|
|
9
9
|
`)?"":t.endsWith(`
|
|
10
10
|
`)?`
|
|
11
11
|
`:`
|
|
12
12
|
|
|
13
|
-
`;return`${t}${l}${s}`}function jp(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const Li="termdock:right-sidebar:html-view-mode-by-file:v1";function Rp(t){return t==="preview"||t==="source"}function uu(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(Rp)}function fu(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function fd(t,n){const s=fu(t,n);return s?ot(Li,uu)?.[s]??"source":"source"}function Cp(t,n,s){const l=fu(t,n);if(!l)return;const u=ot(Li,uu)??{};St(Li,{...u,[l]:s})}function Np(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}const Mp=1500,hd=256*1024*1024;async function Ep(t,n){const s=await fetch(t,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",u=s.body?.getReader();if(!u){const m=await s.blob();if(m.size>hd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(m)}const c=[];let h=0;try{for(;;){const{done:m,value:g}=await u.read();if(m)break;if(h+=g.byteLength,h>hd)throw new Error("Media too large for encrypted fallback");c.push(g)}}catch(m){throw await u.cancel().catch(()=>{}),m}return URL.createObjectURL(new Blob(c,{type:l}))}function ro(t,n){const s=Np(t),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),m=a.useRef(n);return m.current=n,a.useEffect(()=>{if(!s||l)return;const g=navigator.serviceWorker,b=()=>u(!!g?.controller);return g?.addEventListener("controllerchange",b),b(),()=>g?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let g=!1,b;const f=new AbortController,S=window.setTimeout(()=>{Ep(t,f.signal).then(y=>{if(g){URL.revokeObjectURL(y);return}b=y,h(y)}).catch(()=>{g||f.signal.aborted||m.current?.()})},Mp);return()=>{g=!0,window.clearTimeout(S),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,t]),!s||l?t:c}function si(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,c=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function $p(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const Zr=2,Lp=8,Ap=60,Ta=5,md=.05,Pp=900;function Tp(t){return!Number.isFinite(t)||t<=0?Zr:Math.min(Lp,Zr+Math.floor(t/Ap))}const Ip=350,Dp=12,_p=90;function Fp({url:t,onLoadError:n}){const s=ro(t,n),{t:l}=Rt(),u=a.useRef(null),c=a.useRef(null),h=a.useRef(null),m=a.useRef(null),g=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),S=a.useRef(0),y=a.useRef(!1),C=a.useRef(!1),I=a.useRef(!1),F=a.useRef(null),B=a.useRef(null),E=a.useRef(!1),N=a.useRef(1),$=a.useRef(!1),[T,U]=a.useState(0),[D,p]=a.useState(0),[i,O]=a.useState(!1),[j,q]=a.useState(!1),[le,ne]=a.useState(null),[ue,G]=a.useState(!1),[Y,L]=a.useState(0),[_,V]=a.useState(!1),[te,oe]=a.useState({width:0,height:0}),[ge,he]=a.useState(Zr),[$e,M]=a.useState(1),[J,fe]=a.useState(null),Re=a.useRef(Zr),qe=a.useRef(null),Ce=a.useCallback(()=>{F.current!==null&&(clearTimeout(F.current),F.current=null)},[]),ce=a.useCallback(()=>{Ce();const z=B.current;if(B.current=null,!E.current)return!1;const re=h.current;if(re&&(re.playbackRate=N.current,z))try{re.releasePointerCapture?.(z.id)}catch{}return E.current=!1,Re.current=Zr,G(!1),!0},[Ce]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),qe.current!==null&&clearTimeout(qe.current),Ce();const z=h.current;z&&E.current&&(z.playbackRate=N.current)},[Ce]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const re=new ResizeObserver(([be])=>{be&&oe({width:be.contentRect.width,height:be.contentRect.height})});return re.observe(z),()=>re.disconnect()},[]),a.useEffect(()=>{const z=()=>V(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const xe=a.useCallback((z,re=!1)=>{const be=h.current;if(!be)return!1;const ze=Number.isFinite(be.duration)?be.duration:z,ut=Math.min(Math.max(z,0),ze);if(p(ut),Math.abs(be.currentTime-ut)<1/120)return!1;const dr=be.fastSeek;return re&&typeof dr=="function"?dr.call(be,ut):be.currentTime=ut,!0},[]),k=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const z=h.current;if(!z||!y.current||C.current||z.seeking)return;const re=I.current;I.current=!1,C.current=xe(S.current,!re)}))},[xe]),Q=a.useCallback(z=>{const re=m.current,be=h.current;if(!re||!be)return;const ze=re.getBoundingClientRect(),ut=$p(z,ze,be.duration);S.current=ut,ne(ut),I.current=!1,k(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,k()},_p)},[k]),ae=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,C.current=!1,xe(S.current)},[xe]),Ne=a.useCallback(z=>{const re=h.current;if(!(!re||!Number.isFinite(re.duration)||re.duration<=0)){g.current=!re.paused,re.pause(),y.current=!0,q(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}Q(z.clientX)}},[Q]),je=a.useCallback(()=>{y.current=!1,ae(),q(!1),ne(null);const z=h.current;z&&g.current&&!z.ended&&z.play().catch(()=>{}),g.current=!1},[ae]),Ke=a.useCallback(()=>{const z=h.current;if(z){if($.current){$.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),de=a.useCallback(z=>{const re=h.current;if(!re)return;const be=Math.min(1,Math.max(0,Math.round((re.volume+z)*100)/100));re.volume=be,be>0&&(re.muted=!1),M(be),fe(be),qe.current!==null&&clearTimeout(qe.current),qe.current=setTimeout(()=>{qe.current=null,fe(null)},Pp)},[]),Ae=a.useCallback(z=>{const re=h.current;if(re){if(z.key==="ArrowLeft"){z.preventDefault(),xe(re.currentTime-(z.shiftKey?Ta*2:Ta));return}if(z.key==="ArrowRight"){z.preventDefault(),xe(re.currentTime+(z.shiftKey?Ta*2:Ta));return}if(z.key==="ArrowUp"){z.preventDefault(),de(md);return}if(z.key==="ArrowDown"){z.preventDefault(),de(-md);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),re.paused?re.play().catch(()=>{}):re.pause())}},[xe,de]),st=a.useCallback(z=>{const re=h.current;!re||re.paused||z.button!==0||(Ce(),B.current={id:z.pointerId,x:z.clientX,y:z.clientY},F.current=setTimeout(()=>{F.current=null;const be=B.current;if(N.current=re.playbackRate,re.playbackRate=Zr,Re.current=Zr,he(Zr),E.current=!0,G(!0),be)try{re.setPointerCapture?.(be.id)}catch{}},Ip))},[Ce]),Le=a.useCallback(z=>{const re=B.current;if(!re||re.id!==z.pointerId)return;if(!E.current){Math.hypot(z.clientX-re.x,z.clientY-re.y)>Dp&&(Ce(),B.current=null);return}const be=Tp(z.clientX-re.x);if(be===Re.current)return;Re.current=be,he(be);const ze=h.current;ze&&(ze.playbackRate=be)},[Ce]),we=a.useCallback(()=>{ce()&&($.current=!0)},[ce]);a.useEffect(()=>(window.addEventListener("pointerup",we),window.addEventListener("pointercancel",we),window.addEventListener("blur",we),()=>{window.removeEventListener("pointerup",we),window.removeEventListener("pointercancel",we),window.removeEventListener("blur",we)}),[we]);const at=a.useCallback(async()=>{const z=u.current,re=h.current;if(!(!z||!re))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():re.webkitEnterFullscreen?.()}catch{re.webkitEnterFullscreen?.()}},[]),et=a.useCallback(()=>L(z=>(z+90)%360),[]),qt=a.useCallback(z=>{const re=h.current;if(!re||!Number.isFinite(re.duration))return;const be=z.shiftKey?10:5;let ze=null;z.key==="ArrowLeft"?ze=re.currentTime-be:z.key==="ArrowRight"?ze=re.currentTime+be:z.key==="Home"?ze=0:z.key==="End"&&(ze=re.duration),ze!==null&&(z.preventDefault(),xe(ze))},[xe]),lt=j&&le!==null?le:D,ct=T>0?Math.min(1,Math.max(0,lt/T)):0,Dt=(Y===90||Y===270)&&te.width>0&&te.height>0?{width:`${te.height}px`,height:`${te.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,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":Y,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",style:{...Dt,transform:`translate(-50%, -50%) rotate(${Y}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,onClick:Ke,onKeyDown:Ae,onVolumeChange:z=>M(z.currentTarget.volume),onPointerDown:st,onPointerMove:Le,onPointerUp:we,onPointerCancel:we,onContextMenu:z=>{E.current&&z.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:z=>p(z.currentTarget.currentTime),onSeeked:z=>{const re=z.currentTarget;if(p(re.currentTime),C.current=!1,!y.current)return;const be=re.requestVideoFrameCallback;typeof be=="function"?be.call(re,()=>{y.current&&k()}):requestAnimationFrame(()=>{y.current&&k()})},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")}),ue&&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(ge)})}),J!==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(im,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round($e*100)})]}),j&&le!==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:`${ct*100}%`},"data-testid":"file-preview-video-scrub-time",children:si(le)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Rm}`,[Cm]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ke,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"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:i?e.jsx(lm,{size:14}):e.jsx(cm,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(lt),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:Ne,onPointerMove:z=>{j&&Q(z.clientX)},onPointerUp:je,onPointerCancel:je,onKeyDown:qt,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:`${ct*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:`${ct*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[si(lt)," / ",si(T)]}),e.jsx("button",{type:"button",onClick:et,"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(dm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{at()},"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(zm,{size:14}):e.jsx(Um,{size:14})})]})})]})}function Bp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function no({anchor:t,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:u,style:Bp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Va,{size:11}),n]})}function Op(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const c=l.width*u,h=l.height*u,m=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,b=t-m,f=n-g;if(b<0||f<0||b>c||f>h)return null;const S=b/c*100,y=f/h*100;return{x:l.x+l.width*S/100,y:l.y+l.height*y/100,xPercent:S,yPercent:y}}function Up(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function Hp(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const u of Array.from(l.attributes)){const c=u.name.toLowerCase(),h=u.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function zp(t,n,s){let l=null;for(const u of Array.from(t.querySelectorAll("text"))){const c=(u.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(u.getAttribute("x")),m=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const g=Math.hypot(h-n,m-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function hu({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),c=a.useRef(null),[h,m]=a.useState(null),[g,b]=a.useState(null),[f,S]=a.useState(1),[y,C]=a.useState(!1),[I,F]=a.useState(null),B=a.useRef(new Map),E=a.useRef(null),N=a.useRef(!1),$=a.useRef(null),T=a.useRef(f);T.current=f,a.useEffect(()=>{const L=new AbortController;return m(null),b(null),F(null),S(1),fetch(t,{signal:L.signal}).then(_=>_.text()).then(_=>m(Hp(_))).catch(_=>{L.signal.aborted||b(_ instanceof Error?_.message:"SVG preview failed")}),()=>L.abort()},[t]),a.useEffect(()=>{if(!y)return;const L=_=>{_.key==="Escape"&&C(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[y]),a.useLayoutEffect(()=>{const L=c.current,_=L?.querySelector("[data-svg-document] > svg");if(!L||!_)return;let V;try{V=_.getBBox()}catch{return}if(!V.width||!V.height)return;const te=Math.max(2,Math.min(V.width,V.height)*.025);_.setAttribute("viewBox",`${V.x-te} ${V.y-te} ${V.width+2*te} ${V.height+2*te}`),_.style.width=`${f*100}%`,_.style.height=`${f*100}%`,_.style.minWidth=`${f*100}%`,_.style.minHeight=`${f*100}%`,_.style.display="block"},[h,f]);const U=a.useMemo(()=>I?Up(n,s,I):null,[n,I,s]),D=L=>{if(N.current){N.current=!1;return}const _=c.current,V=_?.querySelector("[data-svg-document] > svg"),te=u.current;if(!_||!V||!te)return;const oe=V.viewBox.baseVal,ge=Op(L.clientX,L.clientY,V.getBoundingClientRect(),oe);if(!ge)return;const he=te.getBoundingClientRect();F({...ge,nearestText:zp(V,ge.x,ge.y),stageX:L.clientX-he.left,stageY:L.clientY-he.top,stageXPercent:(L.clientX-he.left)/he.width*100,stageYPercent:(L.clientY-he.top)/he.height*100})},p=L=>Math.max(1,Math.min(12,L)),i=(L,_)=>{const V=p(_),te=L.querySelector("[data-svg-document] > svg");if(!te)return V;const oe=`${V*100}%`;return te.style.width=oe,te.style.height=oe,te.style.minWidth=oe,te.style.minHeight=oe,T.current=V,V},O=(L,_,V,te)=>{const oe=T.current,ge=L.getBoundingClientRect(),he=V-ge.left,$e=te-ge.top,M=(L.scrollLeft+he)/oe,J=(L.scrollTop+$e)/oe,fe=i(L,_);return L.scrollLeft=M*fe-he,L.scrollTop=J*fe-$e,fe},j=()=>{const L=Array.from(B.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},q=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const _=c.current;_&&(B.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),_.setPointerCapture?.(L.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startDistance:j(),startZoom:T.current,moved:!1},N.current=!0):T.current>1&&(E.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}))},le=L=>{if(!B.current.has(L.pointerId))return;B.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const _=c.current,V=E.current;if(!(!_||!V)){if(B.current.size>=2&&V.kind==="pinch"){const te=j();if(!V.startDistance||!te)return;const oe=p(V.startZoom*te/V.startDistance);if(Math.abs(oe-T.current)<.01)return;const ge=Array.from(B.current.values()),he=(ge[0].x+ge[1].x)/2,$e=(ge[0].y+ge[1].y)/2;V.moved=!0,N.current=!0,O(_,oe,he,$e),L.preventDefault();return}if(V.kind==="pan"&&B.current.size===1){const te=L.clientX-V.startX,oe=L.clientY-V.startY;if(!V.moved&&Math.hypot(te,oe)<6)return;V.moved=!0,N.current=!0,_.scrollLeft=V.startScrollLeft-te,_.scrollTop=V.startScrollTop-oe,L.preventDefault()}}},ne=L=>{const _=c.current,V=E.current,te=B.current.size===1&&!V?.moved;B.current.delete(L.pointerId);try{_?.releasePointerCapture?.(L.pointerId)}catch{}if(B.current.size===1&&V?.kind==="pinch"){const he=Array.from(B.current.values())[0];E.current=_?{kind:"pan",startX:he.x,startY:he.y,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,V?.kind==="pinch"&&S(T.current),!te||N.current))return;const oe=Date.now(),ge=$.current;ge&&oe-ge.time<350&&Math.hypot(L.clientX-ge.x,L.clientY-ge.y)<24?($.current=null,N.current=!0,S(he=>he>1?1:2.5)):$.current={time:oe,x:L.clientX,y:L.clientY}},ue=L=>{if(!L.ctrlKey&&!L.metaKey)return;const _=c.current;if(!_)return;L.preventDefault();const V=O(_,T.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);S(V)},G=()=>{S(1),T.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},Y=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:D,onDoubleClick:L=>{L.preventDefault(),S(_=>_>1?1:2.5)},onPointerDown:q,onPointerMove:le,onPointerUp:ne,onPointerCancel:ne,onWheel:ue,onScroll:()=>F(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):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…"})}),I&&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:I.stageX,top:I.stageY}}),I&&U&&e.jsx(no,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.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:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.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(Km,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),C(_=>!_)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(ru,{size:14}):e.jsx(eu,{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:I?`SVG (${I.x.toFixed(2)}, ${I.y.toFixed(2)}) · ${I.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?en.createPortal(Y,document.body):Y}function Ga(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Wp(t,n,s,l){const u=[`电子标注: ${t}`,`视图: ${Ga(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.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(",");u.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${u.join(" / ")}"`}function Gp({blobUrl:t,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:c,onRefresh:h,interactive3d:m}){const{t:g}=Rt(),b=a.useRef(null),f=a.useRef(null),S=a.useRef(null),[y,C]=a.useState(null),[I,F]=a.useState(!1);a.useEffect(()=>(S.current?.abort(),C(null),F(!1),()=>S.current?.abort()),[t,s]);const B=a.useMemo(()=>y?Wp(n,s,y,y.inspection):null,[n,y,s]),E=$=>{const T=b.current,U=f.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const D=T.getBoundingClientRect(),p=U.getBoundingClientRect(),i=Math.min(p.width/U.naturalWidth,p.height/U.naturalHeight),O=U.naturalWidth*i,j=U.naturalHeight*i,q=p.left+(p.width-O)/2,le=p.top+(p.height-j)/2,ne=$.clientX-q,ue=$.clientY-le;if(ne<0||ue<0||ne>O||ue>j)return;const G={xPercent:Math.max(0,Math.min(100,ne/O*100)),yPercent:Math.max(0,Math.min(100,ue/j*100)),stageXPercent:($.clientX-D.left)/D.width*100,stageYPercent:($.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(C(G),S.current?.abort(),!G.inspecting)return;const Y=new AbortController;S.current=Y,Nh(n,s,G.xPercent,G.yPercent,Y.signal).then(L=>C(_=>_===G?{..._,inspection:L,inspecting:!1}:_)).catch(()=>{Y.signal.aborted||C(L=>L===G?{...L,inspection:{available:!1},inspecting:!1}:L)})},N=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:N.map($=>e.jsx("button",{type:"button",onClick:()=>u($),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${$===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ga($)},$))}),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:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx(ji,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:b,role:"button",tabIndex:0,onClick:E,onKeyDown:$=>{$.key!=="Enter"&&$.key!==" "||($.preventDefault(),C({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:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:t,alt:`${n} ${Ga(s)}`,onLoad:()=>F(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${I?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&B&&e.jsx(no,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?ep(f.current,y):Promise.resolve(null)}),C(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(hu,{blobUrl:t,filePath:n,viewLabel:Ga(s),onInsertAnnotation:c})})]})}function qp(t){const n=[];let s=[],l="",u=!1;for(let c=0;c<t.length;c+=1){const h=t[c];u?h==='"'&&t[c+1]==='"'?(l+='"',c+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
|
|
13
|
+
`;return`${t}${l}${s}`}function jp(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const Ai="termdock:right-sidebar:html-view-mode-by-file:v1";function Rp(t){return t==="preview"||t==="source"}function uu(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(Rp)}function fu(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function hd(t,n){const s=fu(t,n);return s?ot(Ai,uu)?.[s]??"source":"source"}function Cp(t,n,s){const l=fu(t,n);if(!l)return;const u=ot(Ai,uu)??{};St(Ai,{...u,[l]:s})}function Np(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}const Mp=1500,md=256*1024*1024;async function Ep(t,n){const s=await fetch(t,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",u=s.body?.getReader();if(!u){const m=await s.blob();if(m.size>md)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(m)}const c=[];let h=0;try{for(;;){const{done:m,value:g}=await u.read();if(m)break;if(h+=g.byteLength,h>md)throw new Error("Media too large for encrypted fallback");c.push(g)}}catch(m){throw await u.cancel().catch(()=>{}),m}return URL.createObjectURL(new Blob(c,{type:l}))}function ro(t,n){const s=Np(t),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),m=a.useRef(n);return m.current=n,a.useEffect(()=>{if(!s||l)return;const g=navigator.serviceWorker,b=()=>u(!!g?.controller);return g?.addEventListener("controllerchange",b),b(),()=>g?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let g=!1,b;const f=new AbortController,S=window.setTimeout(()=>{Ep(t,f.signal).then(y=>{if(g){URL.revokeObjectURL(y);return}b=y,h(y)}).catch(()=>{g||f.signal.aborted||m.current?.()})},Mp);return()=>{g=!0,window.clearTimeout(S),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,t]),!s||l?t:c}function si(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,c=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function $p(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const Zr=2,Lp=8,Ap=60,Ta=5,pd=.05,Pp=900;function Tp(t){return!Number.isFinite(t)||t<=0?Zr:Math.min(Lp,Zr+Math.floor(t/Ap))}const Ip=350,Dp=12,_p=90;function Fp({url:t,onLoadError:n}){const s=ro(t,n),{t:l}=Rt(),u=a.useRef(null),c=a.useRef(null),h=a.useRef(null),m=a.useRef(null),g=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),S=a.useRef(0),y=a.useRef(!1),C=a.useRef(!1),I=a.useRef(!1),F=a.useRef(null),B=a.useRef(null),E=a.useRef(!1),N=a.useRef(1),$=a.useRef(!1),[T,U]=a.useState(0),[D,p]=a.useState(0),[i,O]=a.useState(!1),[j,q]=a.useState(!1),[le,ne]=a.useState(null),[ue,G]=a.useState(!1),[Y,L]=a.useState(0),[_,V]=a.useState(!1),[te,oe]=a.useState({width:0,height:0}),[ge,he]=a.useState(Zr),[$e,M]=a.useState(1),[J,fe]=a.useState(null),Re=a.useRef(Zr),qe=a.useRef(null),Ce=a.useCallback(()=>{F.current!==null&&(clearTimeout(F.current),F.current=null)},[]),ce=a.useCallback(()=>{Ce();const z=B.current;if(B.current=null,!E.current)return!1;const re=h.current;if(re&&(re.playbackRate=N.current,z))try{re.releasePointerCapture?.(z.id)}catch{}return E.current=!1,Re.current=Zr,G(!1),!0},[Ce]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),qe.current!==null&&clearTimeout(qe.current),Ce();const z=h.current;z&&E.current&&(z.playbackRate=N.current)},[Ce]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const re=new ResizeObserver(([be])=>{be&&oe({width:be.contentRect.width,height:be.contentRect.height})});return re.observe(z),()=>re.disconnect()},[]),a.useEffect(()=>{const z=()=>V(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const xe=a.useCallback((z,re=!1)=>{const be=h.current;if(!be)return!1;const ze=Number.isFinite(be.duration)?be.duration:z,ut=Math.min(Math.max(z,0),ze);if(p(ut),Math.abs(be.currentTime-ut)<1/120)return!1;const dr=be.fastSeek;return re&&typeof dr=="function"?dr.call(be,ut):be.currentTime=ut,!0},[]),k=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const z=h.current;if(!z||!y.current||C.current||z.seeking)return;const re=I.current;I.current=!1,C.current=xe(S.current,!re)}))},[xe]),Q=a.useCallback(z=>{const re=m.current,be=h.current;if(!re||!be)return;const ze=re.getBoundingClientRect(),ut=$p(z,ze,be.duration);S.current=ut,ne(ut),I.current=!1,k(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,k()},_p)},[k]),ae=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,C.current=!1,xe(S.current)},[xe]),Ne=a.useCallback(z=>{const re=h.current;if(!(!re||!Number.isFinite(re.duration)||re.duration<=0)){g.current=!re.paused,re.pause(),y.current=!0,q(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}Q(z.clientX)}},[Q]),je=a.useCallback(()=>{y.current=!1,ae(),q(!1),ne(null);const z=h.current;z&&g.current&&!z.ended&&z.play().catch(()=>{}),g.current=!1},[ae]),Ke=a.useCallback(()=>{const z=h.current;if(z){if($.current){$.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),de=a.useCallback(z=>{const re=h.current;if(!re)return;const be=Math.min(1,Math.max(0,Math.round((re.volume+z)*100)/100));re.volume=be,be>0&&(re.muted=!1),M(be),fe(be),qe.current!==null&&clearTimeout(qe.current),qe.current=setTimeout(()=>{qe.current=null,fe(null)},Pp)},[]),Ae=a.useCallback(z=>{const re=h.current;if(re){if(z.key==="ArrowLeft"){z.preventDefault(),xe(re.currentTime-(z.shiftKey?Ta*2:Ta));return}if(z.key==="ArrowRight"){z.preventDefault(),xe(re.currentTime+(z.shiftKey?Ta*2:Ta));return}if(z.key==="ArrowUp"){z.preventDefault(),de(pd);return}if(z.key==="ArrowDown"){z.preventDefault(),de(-pd);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),re.paused?re.play().catch(()=>{}):re.pause())}},[xe,de]),st=a.useCallback(z=>{const re=h.current;!re||re.paused||z.button!==0||(Ce(),B.current={id:z.pointerId,x:z.clientX,y:z.clientY},F.current=setTimeout(()=>{F.current=null;const be=B.current;if(N.current=re.playbackRate,re.playbackRate=Zr,Re.current=Zr,he(Zr),E.current=!0,G(!0),be)try{re.setPointerCapture?.(be.id)}catch{}},Ip))},[Ce]),Le=a.useCallback(z=>{const re=B.current;if(!re||re.id!==z.pointerId)return;if(!E.current){Math.hypot(z.clientX-re.x,z.clientY-re.y)>Dp&&(Ce(),B.current=null);return}const be=Tp(z.clientX-re.x);if(be===Re.current)return;Re.current=be,he(be);const ze=h.current;ze&&(ze.playbackRate=be)},[Ce]),we=a.useCallback(()=>{ce()&&($.current=!0)},[ce]);a.useEffect(()=>(window.addEventListener("pointerup",we),window.addEventListener("pointercancel",we),window.addEventListener("blur",we),()=>{window.removeEventListener("pointerup",we),window.removeEventListener("pointercancel",we),window.removeEventListener("blur",we)}),[we]);const at=a.useCallback(async()=>{const z=u.current,re=h.current;if(!(!z||!re))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():re.webkitEnterFullscreen?.()}catch{re.webkitEnterFullscreen?.()}},[]),et=a.useCallback(()=>L(z=>(z+90)%360),[]),qt=a.useCallback(z=>{const re=h.current;if(!re||!Number.isFinite(re.duration))return;const be=z.shiftKey?10:5;let ze=null;z.key==="ArrowLeft"?ze=re.currentTime-be:z.key==="ArrowRight"?ze=re.currentTime+be:z.key==="Home"?ze=0:z.key==="End"&&(ze=re.duration),ze!==null&&(z.preventDefault(),xe(ze))},[xe]),lt=j&&le!==null?le:D,ct=T>0?Math.min(1,Math.max(0,lt/T)):0,Dt=(Y===90||Y===270)&&te.width>0&&te.height>0?{width:`${te.height}px`,height:`${te.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,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":Y,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",style:{...Dt,transform:`translate(-50%, -50%) rotate(${Y}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,onClick:Ke,onKeyDown:Ae,onVolumeChange:z=>M(z.currentTarget.volume),onPointerDown:st,onPointerMove:Le,onPointerUp:we,onPointerCancel:we,onContextMenu:z=>{E.current&&z.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:z=>p(z.currentTarget.currentTime),onSeeked:z=>{const re=z.currentTarget;if(p(re.currentTime),C.current=!1,!y.current)return;const be=re.requestVideoFrameCallback;typeof be=="function"?be.call(re,()=>{y.current&&k()}):requestAnimationFrame(()=>{y.current&&k()})},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")}),ue&&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(ge)})}),J!==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(im,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round($e*100)})]}),j&&le!==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:`${ct*100}%`},"data-testid":"file-preview-video-scrub-time",children:si(le)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Rm}`,[Cm]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ke,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"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:i?e.jsx(lm,{size:14}):e.jsx(cm,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(lt),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:Ne,onPointerMove:z=>{j&&Q(z.clientX)},onPointerUp:je,onPointerCancel:je,onKeyDown:qt,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:`${ct*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:`${ct*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[si(lt)," / ",si(T)]}),e.jsx("button",{type:"button",onClick:et,"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(dm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{at()},"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(zm,{size:14}):e.jsx(Um,{size:14})})]})})]})}function Bp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function no({anchor:t,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:u,style:Bp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Va,{size:11}),n]})}function Op(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const c=l.width*u,h=l.height*u,m=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,b=t-m,f=n-g;if(b<0||f<0||b>c||f>h)return null;const S=b/c*100,y=f/h*100;return{x:l.x+l.width*S/100,y:l.y+l.height*y/100,xPercent:S,yPercent:y}}function Up(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function Hp(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const u of Array.from(l.attributes)){const c=u.name.toLowerCase(),h=u.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function zp(t,n,s){let l=null;for(const u of Array.from(t.querySelectorAll("text"))){const c=(u.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(u.getAttribute("x")),m=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const g=Math.hypot(h-n,m-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function hu({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),c=a.useRef(null),[h,m]=a.useState(null),[g,b]=a.useState(null),[f,S]=a.useState(1),[y,C]=a.useState(!1),[I,F]=a.useState(null),B=a.useRef(new Map),E=a.useRef(null),N=a.useRef(!1),$=a.useRef(null),T=a.useRef(f);T.current=f,a.useEffect(()=>{const L=new AbortController;return m(null),b(null),F(null),S(1),fetch(t,{signal:L.signal}).then(_=>_.text()).then(_=>m(Hp(_))).catch(_=>{L.signal.aborted||b(_ instanceof Error?_.message:"SVG preview failed")}),()=>L.abort()},[t]),a.useEffect(()=>{if(!y)return;const L=_=>{_.key==="Escape"&&C(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[y]),a.useLayoutEffect(()=>{const L=c.current,_=L?.querySelector("[data-svg-document] > svg");if(!L||!_)return;let V;try{V=_.getBBox()}catch{return}if(!V.width||!V.height)return;const te=Math.max(2,Math.min(V.width,V.height)*.025);_.setAttribute("viewBox",`${V.x-te} ${V.y-te} ${V.width+2*te} ${V.height+2*te}`),_.style.width=`${f*100}%`,_.style.height=`${f*100}%`,_.style.minWidth=`${f*100}%`,_.style.minHeight=`${f*100}%`,_.style.display="block"},[h,f]);const U=a.useMemo(()=>I?Up(n,s,I):null,[n,I,s]),D=L=>{if(N.current){N.current=!1;return}const _=c.current,V=_?.querySelector("[data-svg-document] > svg"),te=u.current;if(!_||!V||!te)return;const oe=V.viewBox.baseVal,ge=Op(L.clientX,L.clientY,V.getBoundingClientRect(),oe);if(!ge)return;const he=te.getBoundingClientRect();F({...ge,nearestText:zp(V,ge.x,ge.y),stageX:L.clientX-he.left,stageY:L.clientY-he.top,stageXPercent:(L.clientX-he.left)/he.width*100,stageYPercent:(L.clientY-he.top)/he.height*100})},p=L=>Math.max(1,Math.min(12,L)),i=(L,_)=>{const V=p(_),te=L.querySelector("[data-svg-document] > svg");if(!te)return V;const oe=`${V*100}%`;return te.style.width=oe,te.style.height=oe,te.style.minWidth=oe,te.style.minHeight=oe,T.current=V,V},O=(L,_,V,te)=>{const oe=T.current,ge=L.getBoundingClientRect(),he=V-ge.left,$e=te-ge.top,M=(L.scrollLeft+he)/oe,J=(L.scrollTop+$e)/oe,fe=i(L,_);return L.scrollLeft=M*fe-he,L.scrollTop=J*fe-$e,fe},j=()=>{const L=Array.from(B.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},q=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const _=c.current;_&&(B.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),_.setPointerCapture?.(L.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startDistance:j(),startZoom:T.current,moved:!1},N.current=!0):T.current>1&&(E.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}))},le=L=>{if(!B.current.has(L.pointerId))return;B.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const _=c.current,V=E.current;if(!(!_||!V)){if(B.current.size>=2&&V.kind==="pinch"){const te=j();if(!V.startDistance||!te)return;const oe=p(V.startZoom*te/V.startDistance);if(Math.abs(oe-T.current)<.01)return;const ge=Array.from(B.current.values()),he=(ge[0].x+ge[1].x)/2,$e=(ge[0].y+ge[1].y)/2;V.moved=!0,N.current=!0,O(_,oe,he,$e),L.preventDefault();return}if(V.kind==="pan"&&B.current.size===1){const te=L.clientX-V.startX,oe=L.clientY-V.startY;if(!V.moved&&Math.hypot(te,oe)<6)return;V.moved=!0,N.current=!0,_.scrollLeft=V.startScrollLeft-te,_.scrollTop=V.startScrollTop-oe,L.preventDefault()}}},ne=L=>{const _=c.current,V=E.current,te=B.current.size===1&&!V?.moved;B.current.delete(L.pointerId);try{_?.releasePointerCapture?.(L.pointerId)}catch{}if(B.current.size===1&&V?.kind==="pinch"){const he=Array.from(B.current.values())[0];E.current=_?{kind:"pan",startX:he.x,startY:he.y,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,V?.kind==="pinch"&&S(T.current),!te||N.current))return;const oe=Date.now(),ge=$.current;ge&&oe-ge.time<350&&Math.hypot(L.clientX-ge.x,L.clientY-ge.y)<24?($.current=null,N.current=!0,S(he=>he>1?1:2.5)):$.current={time:oe,x:L.clientX,y:L.clientY}},ue=L=>{if(!L.ctrlKey&&!L.metaKey)return;const _=c.current;if(!_)return;L.preventDefault();const V=O(_,T.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);S(V)},G=()=>{S(1),T.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},Y=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:D,onDoubleClick:L=>{L.preventDefault(),S(_=>_>1?1:2.5)},onPointerDown:q,onPointerMove:le,onPointerUp:ne,onPointerCancel:ne,onWheel:ue,onScroll:()=>F(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):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…"})}),I&&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:I.stageX,top:I.stageY}}),I&&U&&e.jsx(no,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.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:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.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(Km,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),C(_=>!_)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(ru,{size:14}):e.jsx(eu,{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:I?`SVG (${I.x.toFixed(2)}, ${I.y.toFixed(2)}) · ${I.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?en.createPortal(Y,document.body):Y}function Ga(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Wp(t,n,s,l){const u=[`电子标注: ${t}`,`视图: ${Ga(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.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(",");u.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${u.join(" / ")}"`}function Gp({blobUrl:t,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:c,onRefresh:h,interactive3d:m}){const{t:g}=Rt(),b=a.useRef(null),f=a.useRef(null),S=a.useRef(null),[y,C]=a.useState(null),[I,F]=a.useState(!1);a.useEffect(()=>(S.current?.abort(),C(null),F(!1),()=>S.current?.abort()),[t,s]);const B=a.useMemo(()=>y?Wp(n,s,y,y.inspection):null,[n,y,s]),E=$=>{const T=b.current,U=f.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const D=T.getBoundingClientRect(),p=U.getBoundingClientRect(),i=Math.min(p.width/U.naturalWidth,p.height/U.naturalHeight),O=U.naturalWidth*i,j=U.naturalHeight*i,q=p.left+(p.width-O)/2,le=p.top+(p.height-j)/2,ne=$.clientX-q,ue=$.clientY-le;if(ne<0||ue<0||ne>O||ue>j)return;const G={xPercent:Math.max(0,Math.min(100,ne/O*100)),yPercent:Math.max(0,Math.min(100,ue/j*100)),stageXPercent:($.clientX-D.left)/D.width*100,stageYPercent:($.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(C(G),S.current?.abort(),!G.inspecting)return;const Y=new AbortController;S.current=Y,Nh(n,s,G.xPercent,G.yPercent,Y.signal).then(L=>C(_=>_===G?{..._,inspection:L,inspecting:!1}:_)).catch(()=>{Y.signal.aborted||C(L=>L===G?{...L,inspection:{available:!1},inspecting:!1}:L)})},N=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:N.map($=>e.jsx("button",{type:"button",onClick:()=>u($),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${$===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ga($)},$))}),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:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx(Ri,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:b,role:"button",tabIndex:0,onClick:E,onKeyDown:$=>{$.key!=="Enter"&&$.key!==" "||($.preventDefault(),C({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:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:t,alt:`${n} ${Ga(s)}`,onLoad:()=>F(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${I?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&B&&e.jsx(no,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?ep(f.current,y):Promise.resolve(null)}),C(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(hu,{blobUrl:t,filePath:n,viewLabel:Ga(s),onInsertAnnotation:c})})]})}function qp(t){const n=[];let s=[],l="",u=!1;for(let c=0;c<t.length;c+=1){const h=t[c];u?h==='"'&&t[c+1]==='"'?(l+='"',c+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
|
|
14
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 Kp(t,n,s,l,u){const c=n[u]||`第${u+1}列`,h=s[u]??"",m=n.map((g,b)=>`${g||`第${b+1}列`}=${s[b]??""}`).join(";");return`"表格标注: ${t} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${m}"`}function Vp({content:t,filePath:n,onInsertAnnotation:s}){const{t:l}=Rt(),u=a.useMemo(()=>qp(t),[t]),c=u[0]??[],h=u.slice(1),m=a.useRef(null),[g,b]=a.useState(null),f=g?h[g.row]:null,S=g&&f?Kp(n,c,f,g.row+1,g.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:m,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((y,C)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||l("rightSidebar.csvUnnamedColumn",{index:C+1})},`${y}:${C}`))]})}),e.jsx("tbody",{children:h.map((y,C)=>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:C+1}),c.map((I,F)=>{const B=g?.row===C&&g.column===F;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${B?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:E=>{const N=m.current?.getBoundingClientRect(),$=E.currentTarget.getBoundingClientRect();if(!N?.width||!N.height)return;const T=E.clientX||$.left+$.width/2,U=E.clientY||$.top+$.height/2;b({row:C,column:F,xPercent:(T-N.left)/N.width*100,yPercent:(U-N.top)/N.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[F]||" "})},`cell:${C}:${F}`)})]},`row:${C}`))})]})}),g&&S&&e.jsx(no,{anchor:{xPercent:g.xPercent,yPercent:g.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(S,`csv:${n}:${g.row+1}:${g.column+1}`),b(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:g&&f?l("rightSidebar.csvSelectedCell",{row:g.row+1,column:c[g.column]||g.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function Kn(t,n){let s=t;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function Yp(t,n){const s=JSON.parse(t),l=Kn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Kn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Kn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Kn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const u=Kn(s,["net_settings","classes"]),c=Array.isArray(u)?u.find(m=>m&&typeof m=="object"&&m.name==="Default"):void 0,h=Kn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(u)?u.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 Xp(t,n){return`"KiCad项目标注: ${t} / 项: ${n.label} / 值: ${n.value}"`}function Jp({content:t,filePath:n,localState:s,onInsertAnnotation:l}){const{t:u}=Rt(),c=a.useRef(null),[h,m]=a.useState(null),g=a.useMemo(()=>{try{return{items:Yp(t,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[t,s]),b=h===null?null:g.items[h.index];return g.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:t}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:u("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:g.items.map((f,S)=>e.jsxs("button",{type:"button",onClick:y=>{const C=c.current?.getBoundingClientRect(),I=y.currentTarget.getBoundingClientRect();if(!C?.width||!C.height)return;const F=y.clientX||I.left+I.width/2,B=y.clientY||I.top+I.height/2;m({index:S,xPercent:(F-C.left)/C.width*100,yPercent:(B-C.top)/C.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===S?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:f.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:f.value})]},f.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:u("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:t})]})]}),b&&h&&e.jsx(no,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:u("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(Xp(n,b),`kicad-project:${n}:${b.label}`),m(null)},children:u("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:b?`${b.label}: ${b.value}`:u("rightSidebar.kicadProjectPickHint")})})]})}const Qp=`/** ES Module Shims Wasm @version 2.8.4 */
|
|
15
15
|
(function () {
|
|
16
16
|
|
|
@@ -1632,47 +1632,47 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
|
|
|
1632
1632
|
window.addEventListener('error', report, true);
|
|
1633
1633
|
window.addEventListener('unhandledrejection', report);
|
|
1634
1634
|
}
|
|
1635
|
-
`,Ia="/api/terminal/fs/preview/",eg=8*1024*1024,tg=32*1024*1024,rg=128,ng="data:,";function $t(t){throw new Error(t)}function sg(t){return JSON.stringify(t).replace(/</g,"\\u003c")}async function
|
|
1635
|
+
`,Ia="/api/terminal/fs/preview/",eg=8*1024*1024,tg=32*1024*1024,rg=128,ng="data:,";function $t(t){throw new Error(t)}function sg(t){return JSON.stringify(t).replace(/</g,"\\u003c")}async function gd(t,n,s){let l="",u=0;for(const c of t.matchAll(n))l+=t.slice(u,c.index)+await s(c),u=c.index+c[0].length;return l+t.slice(u)}async function mu(t,n){const s=n.origin??location.origin,l=new URL(t,s);(l.origin!==s||!vs(l.pathname)?.startsWith(Ia))&&$t("预览地址不是有效的本地文件入口");const u=crypto.randomUUID(),c=`https://termdock-preview.invalid/${u}/`,h=[],m=G=>{!h.includes(G)&&h.length<20&&h.push(G)},g=new Set,b=[],f=new Set,S=new Map,y=new Map;let C=0,I=!1;const F=new Set,B=()=>{I=!0;for(const G of[...F])G();g.clear(),b.length=0};async function E(G){G.ok||$t(`预览资源读取失败(${G.status})`);const Y=G.body?.getReader(),L=[];let _=0;try{if(Y)for(;;){const oe=await Y.read();if(oe.done)break;_+=oe.value.byteLength,C+=oe.value.byteLength,(_>eg||C>tg)&&$t("预览资源超出大小限制"),L.push(oe.value)}}catch(oe){throw await Y?.cancel().catch(()=>{}),oe}finally{Y?.releaseLock()}const V=new Uint8Array(_);let te=0;for(const oe of L)V.set(oe,te),te+=oe.length;return{bytes:V,type:G.headers.get("content-type")??"application/octet-stream",status:G.status}}let N=l,$;for(let G=0;G<4;G++){const Y=await n.fetch(N.pathname+N.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(Y.status)){$=Y;break}const L=Y.headers.get("location");await Y.body?.cancel(),L||$t("预览重定向缺少目标");const _=new URL(L,N);(_.origin!==s||!vs(_.pathname)?.startsWith(Ia))&&$t("预览重定向越出文件范围"),N=_}$||$t("预览重定向次数过多");const T=vs(N.pathname),U=T.slice(Ia.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||$t("服务未提供有效的预览资源授权");const D=vs(l.pathname).slice(Ia.length).split("/");/^[a-f0-9]{32}$/.test(D[0])&&D.shift(),D.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const p=T.endsWith("/")?T:T.slice(0,T.lastIndexOf("/")+1),i=new URL(N.pathname.endsWith("/")?N.pathname:N.pathname.slice(0,N.pathname.lastIndexOf("/")+1),s);function O(G,Y){const L=new URL(G,Y);return L.origin!==s?null:(vs(L.pathname)?.startsWith(p)||$t("已阻止预览访问目录之外的资源"),L)}function j(G){const Y=new URL(G,c);(Y.origin!==new URL(c).origin||!Y.pathname.startsWith(new URL(c).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const L=Y.pathname.slice(new URL(c).pathname.length)+Y.search;return O(L,i)??$t("预览资源无效")}function q(G){const Y=G.pathname+G.search,L=S.get(Y);if(L)return L;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(S.size>=rg)return Promise.reject(new Error("预览资源数量超出限制"));const _=n.fetch(Y,{signal:n.signal,redirect:"manual"}).then(E);return S.set(Y,_),_}function le(G,Y){I&&$t("预览已关闭");const L=`termdock-resource-${u}-${b.length}`;return b.push({token:L,data:G,type:Y}),g.add(L),L}async function ne(G,Y,L,_=new Set){if(!G||G.startsWith("#")||/^data:(?:image|font)\//i.test(G)&&L==="resource")return G;try{const V=O(G,Y);if(!V){const $e=new URL(G,Y);return($e.protocol!=="https:"||$e.username||$e.password||$e.origin===new URL(c).origin)&&$t("已阻止不安全的外部资源"),f.add($e.origin),$e.href}const te=`${L}:${V.href}`;(_.has(te)||_.size>=8)&&$t("预览资源存在循环或过深引用");const oe=y.get(te);if(oe)return oe;const ge=new Set(_);ge.add(te);const he=(async()=>{const $e=await q(V);return L==="css"?le(await ue(new TextDecoder().decode($e.bytes),V,ge),"text/css"):L==="script"?le($e.bytes,"text/javascript"):le($e.bytes,$e.type)})();return y.set(te,he),await he}catch(V){return m(V instanceof Error?V.message:"部分预览资源未能加载"),ng}}async function ue(G,Y,L){return G=await gd(G,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async _=>`@import url("${await ne(_[1],Y,"css",L)}")${_[2]};`),gd(G,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async _=>{const V=(_[1]??_[2]??_[3]).trim();return g.has(V)?_[0]:`url("${await ne(V,Y,"resource",L)}")`})}try{const G=await E($),Y=le(Qp,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(G.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(M=>M.remove());for(const M of L.querySelectorAll("*")){if(M.removeAttribute("ping"),M.removeAttribute("srcdoc"),M.hasAttribute("style")&&M.setAttribute("style",await ue(M.getAttribute("style"),N,new Set)),M.tagName==="STYLE"&&(M.textContent=await ue(M.textContent??"",N,new Set)),M.tagName==="A"||M.tagName==="AREA"){const J=M.getAttribute("href");try{if(J&&!J.startsWith("#")){const fe=O(J,N);if(fe)M.setAttribute("href",new URL(fe.pathname.slice(i.pathname.length)+fe.search+fe.hash,c).href);else{const Re=new URL(J,N);if(Re.protocol!=="https:"){M.removeAttribute("href");continue}f.add(Re.origin),M.setAttribute("href",Re.href)}}}catch(fe){M.removeAttribute("href"),m(fe instanceof Error?fe.message:"预览链接无法加载")}}for(const J of["data","manifest"])M.removeAttribute(J);if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="module"){M.setAttribute("type","module-shim");const J=M.getAttribute("src");if(J){const fe=O(J,N);if(fe)M.setAttribute("src",new URL(fe.pathname.slice(i.pathname.length)+fe.search,c).href);else{const Re=new URL(J,N);if(Re.protocol!=="https:"){M.remove();continue}f.add(Re.origin),M.setAttribute("src",Re.href)}}continue}if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="importmap"){M.setAttribute("type","importmap-shim");continue}if(M.tagName==="LINK"){const J=(M.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(J)){M.remove();continue}const fe=M.getAttribute("href");fe&&M.setAttribute("href",await ne(fe,N,J==="stylesheet"?"css":"resource"))}if(M.hasAttribute("src")&&M.setAttribute("src",await ne(M.getAttribute("src"),N,M.tagName==="SCRIPT"?"script":"resource")),M.hasAttribute("poster")&&M.setAttribute("poster",await ne(M.getAttribute("poster"),N,"resource")),M.hasAttribute("srcset")){const J=M.getAttribute("srcset");/data:/i.test(J)?(M.removeAttribute("srcset"),m("混合内嵌图片候选暂不支持安全预览")):M.setAttribute("srcset",(await Promise.all(J.split(",").map(async fe=>{const[Re,...qe]=fe.trim().split(/\s+/);return`${await ne(Re,N,"resource")} ${qe.join(" ")}`}))).join(", "))}M.setAttribute("referrerpolicy","no-referrer"),M.removeAttribute("integrity"),M.removeAttribute("crossorigin")}const _=[...f].join(" "),V=L.createElement("meta");V.httpEquiv="Content-Security-Policy",V.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${_}; style-src 'unsafe-inline' blob: ${_}; img-src blob: data: ${_}; font-src blob: data: ${_}; media-src blob: data: ${_}; connect-src blob: ${_} ${[...f].map(M=>M.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const te=L.createElement("base");te.href=c;const oe=L.createElement("meta");oe.name="referrer",oe.content="no-referrer";const ge=L.createElement("script");ge.textContent=Zp+`
|
|
1636
1636
|
installPreviewRuntime(`+[u,c,[...f],Y].map(sg).join(",")+");";const he=L.createElement("script");he.src=Y,L.head.prepend(V,oe,te,ge,he);const $e=`<!doctype html>
|
|
1637
|
-
`+L.documentElement.outerHTML;return{html:$e,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(M,J){const fe=new Set,Re=Ce=>{if(Ce.source!==M.contentWindow||Ce.data?.capability!==u)return;if(Ce.data.type==="preview-ready"){M.contentWindow?.postMessage({type:"preview-init",capability:u,html:$e,resources:b},"*");return}if(Ce.data.type==="preview-error"){J("部分动态内容被安全预览限制");return}if(Ce.data.type==="preview-navigate"){(async()=>{const xe=j(String(Ce.data.url)),k=await mu(xe.pathname+xe.search,n);if(I){k.dispose();return}const Q=k.attach(M,J);F.add(()=>{Q(),k.dispose()}),M.src=k.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(xe=>J(xe instanceof Error?xe.message:"无法打开预览页面"));return}if(Ce.data.type==="preview-external"){try{const xe=new URL(String(Ce.data.url));xe.protocol==="https:"&&f.has(xe.origin)&&window.open(xe.href,"_blank","noopener,noreferrer")}catch{}return}if(Ce.data.type!=="preview-fetch"||Ce.ports.length!==1)return;const ce=Ce.ports[0];if(fe.size>=8||!["GET","HEAD"].includes(Ce.data.method)){ce.postMessage({error:"预览仅允许读取已授权目录资源"}),ce.close();return}fe.add(ce),(async()=>{const xe=j(String(Ce.data.url)),k=await q(xe);if(!fe.has(ce)||I)return;const Q=Ce.data.method==="HEAD"?new Uint8Array:k.bytes.slice();ce.postMessage({status:k.status,headers:{"content-type":k.type},data:Q.buffer},[Q.buffer])})().catch(()=>{ce.postMessage({error:"预览资源不在授权范围或无法加载"}),J("部分动态资源不可用或超出预览目录")}).finally(()=>{fe.delete(ce),ce.close()})};window.addEventListener("message",Re);const qe=()=>{window.removeEventListener("message",Re);for(const Ce of fe)Ce.close();fe.clear(),F.delete(qe)};return F.add(qe),qe},dispose:B}}catch(G){throw B(),G}}const ag=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},c){const h=a.useRef(null),[m,g]=a.useState(null),[b,f]=a.useState(),[S,y]=a.useState("");a.useEffect(()=>{const T=new AbortController;let U;return f(void 0),y(""),(async()=>{const D=await Mh();if(U=await mu(n,{fetch:(p,i)=>D.fetch(p,i),signal:T.signal}),T.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(D=>{T.signal.aborted||y(D instanceof Error?D.message:"安全预览加载失败")}),()=>{T.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!m))return b.attach(m,y)},[b,m]);const[C,I]=a.useState(!1),[F,B]=a.useState(!1),E=C||F;a.useEffect(()=>{u?.(E)},[E,u]),a.useEffect(()=>{const T=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",T),()=>document.removeEventListener("fullscreenchange",T)},[]),a.useEffect(()=>{if(!F)return;const T=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[F]);const N=a.useCallback(async()=>{const T=h.current;if(T){if(F){B(!1);return}if(document.fullscreenElement===T){await document.exitFullscreen();return}if(T.requestFullscreen&&document.fullscreenEnabled!==!1)try{await T.requestFullscreen();return}catch{}B(!0)}},[F]);a.useImperativeHandle(c,()=>({toggleFullscreen:N}),[N]);const $=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:E?"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:[E&&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:()=>{N()},"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(ru,{size:15})})]}),S&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:S}),!b&&!S&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return F?en.createPortal($,document.body):$}),pu="termdock-file-search-match",
|
|
1638
|
-
`);const y=u.length;u+=f.data,l.push({node:f,start:y,end:u.length,group:S}),c=S}const m=u.toLocaleLowerCase(),g=[];let b=0;for(;b<=m.length-s.length;){const f=m.indexOf(s,b);if(f<0)break;const S=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),C=l.find(I=>I.start<S&&I.end>=S);if(y&&C&&y.group===C.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(C.node,S-C.start),g.push(I)}b=f+Math.max(s.length,1)}return g}function gu(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Da(){const t=gu();t?.delete(pu),t?.delete(Ai)}function gd(t,n){const s=gu();if(!s||typeof Highlight>"u")return;s.set(pu,new Highlight(...t));const l=t[n];l?s.set(Ai,new Highlight(l)):s.delete(Ai)}function bd(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function cg(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function dg(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function ug(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function bu(t,n,s){return n?t:en.createPortal(t,s)}const Ki="termdock:right-sidebar:file-tree-scroll:v1",Vi="termdock:right-sidebar:file-preview-reading-state:v1",js="termdock:right-sidebar:file-tree-width:v1",xu="termdock:right-sidebar:markdown-view-mode:v1",vu="termdock:right-sidebar:diff-change-list-mode:v1",yu="termdock:right-sidebar:diff-wrap:v1",wu="termdock:diff-viewer:view-type:v1",ku="termdock:right-sidebar:file-search-mode:v1",ai="termdock:right-sidebar:collapsed-git-repo-groups:v1",xd="termdock:right-sidebar:collapsed-diff-directories:v1",oi="termdock:right-sidebar:branch-audit-module-open:v1",Su="termdock:right-sidebar:branch-audit-module:v1",fg=150,ju="termdock:right-sidebar:active-git-repo:v1",vd="termdock:right-sidebar:context-draft-enabled:v1",yd="termdock:right-sidebar:context-draft-collapsed:v1",wd="termdock:right-sidebar:context-draft-auto-collapse:v1",ii="termdock:right-sidebar:context-draft-text:v1",hg=300,mg=20,pg=120,gg=250,bg=250,xg=120,vg=700,li=600;function Vn(t){return!!(t&&Z.getState().nestedGitScanRoots[t])}const kd=[2e3,5e3,15e3,3e4],yg=320,wg=500,kg=20,Sg=12e3,Pi=300,Sd=240,jg=560,Ru="border-r px-2 py-1.5 sm:px-3 sm:py-2",Ya="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Cu=`${Ru} border-b border-border/15 font-semibold last:border-r-0`,Nu=`${Ru} border-border/10 align-top text-muted-foreground last:border-r-0`,Yi="termdock-file-preview-horizontal-scroll",jd=a.lazy(()=>As(()=>import("./ModelPreview-BktvfOu3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Mu=`${Yi} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Eu(t,n,s){return t&&!n?"unified":s}const Rg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Cg(t){return t==="preview"||t==="source"}function Ng(t){return t==="list"||t==="tree"||t==="ai"}function Rd(){return ot(xu,Cg)??"preview"}function Mg(){return ot(vu,Ng)??"tree"}function Rs(t){return typeof t=="boolean"}function Eg(t){return typeof t=="string"}function $g(){return ot(yu,Rs)??!0}function Lg(t){return t==="unified"||t==="split"}function Ag(){return ot(wu,Lg)??"unified"}function Pg(t){return t==="name"||t==="content"||t==="regex"}function Tg(){return ot(ku,Pg)??"name"}function $u(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:xt(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function Ig(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function Lu(){return ot(ju,Ig)??{}}function Cd(t){if(!t)return;const n=Lu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function ci(t,n){t&&St(ju,{...Lu(),[t]:n})}function Dg(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function Ti(t){return!t.activeGitRepoRoot&&(t.groupCount>1||t.label!==t.rootName)}function Au(...t){const n=new Set;for(const s of t)for(const l of s)n.add(l.root);return n}function Ii(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function Nd(t){const n=ot(t,Ii);return n?new Set(n):new Set}function di(t,n){St(t,[...n])}function _g(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function Fg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||Ii(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(_g))&&(n.commits===void 0||Ii(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 Bg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&Fg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Og(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(Bg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Md(){return ot(Su,Og)??{}}function Ed(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function $d(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Pu(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||$d(s)===$d(l)}function Ld(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!Pu(l,n))??""}function Di(t,n){const s=Math.max(Sd,n-320),l=Math.min(jg,s);return Math.min(l,Math.max(Sd,t))}function Ug(t){return typeof t=="number"&&Number.isFinite(t)}function Hg(t){return Di(ot(js,Ug)??Pi,t)}function Tu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function ks(t){return Rg.has(Tu(t))}function Iu(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function _i(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||Iu(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Du(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const _u=a.createContext(null);function qa(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function Fu(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function Bu(t){return t.replace(/\s+#+\s*$/,"").trim()}function Fi(t,n){const l=Fu(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function Ad(t){return Fu(t)||t.trim()}function Xa(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Oi(n[2]);return s?{id:qa(n[1]),definition:{href:s.href,title:s.title}}:null}function zg(t){const n=new Map;for(const s of t){const l=Xa(s);l&&n.set(l.id,l.definition)}return n}function Ou(t){return t.trim().toLowerCase()}function Uu(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Ou(n[1]),text:n[2]}:null}function Wg(t){const n=new Map;let s=null;for(const l of t){const u=Uu(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.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 Hu(t){const n=new Set;let s=!1;return t.forEach((l,u)=>{if(Uu(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function Gg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const u=t[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function zu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Ms(t){const n=t.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 Xi(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const u=l.indexOf("#"),c=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",m=c.split("?",1)[0];if(!m)return null;let g,b=null;try{g=decodeURIComponent(m),b=h?decodeURIComponent(h):null}catch{return null}const f=s?Ms(s):null;let S;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));S=Ms(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;S=Ms(`${zu(n)}/${g}`)}return f&&S!==f&&!S.startsWith(`${f}/`)?null:{path:S,fragment:b,directory:/\/$/.test(m)}}function Ji(t,n,s,l,u){const c=t.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 m=s&&(c===s||c.startsWith(`${s}/`));h=Ms(s&&!m?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Ms(`${zu(n)}/${c}`)}return u(h)}function qg(t,n,s){return Ji(t,n,s,qi,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Kg(t,n,s){return Ji(t,n,s,Kd,Vd)}const Bi=128,Vg=360,ui=480;function so(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function Wu(t,n,s,l,u=0){if(!n||!s)return null;let c,h;return u>0?(c=l>0?Math.min(u,l):u,h=s*c/n):so(t)?(h=Math.min(Math.max(s,Bi),Vg),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>ui&&(c=c*ui/h,h=ui),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Yg(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function Gu(t){const n=Yg(t),s=Z(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function Xg({src:t,alt:n,title:s,requestedWidthPx:l}){const u=so(t),c=Gu(t),h=ro(c),m=a.useRef(null),[g,b]=a.useState(!1),[f,S]=a.useState(0),[y,C]=a.useState({status:"loading"}),[I,F]=a.useState(null);a.useLayoutEffect(()=>{const N=m.current,$=N?.parentElement?.parentElement??N?.parentElement;if(!$)return;const T=()=>S($.clientWidth);if(T(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(T);return U.observe($),()=>U.disconnect()},[]),a.useEffect(()=>{if(g)return;const N=m.current;if(!N||typeof IntersectionObserver>"u"){b(!0);return}const $=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(b(!0),$.disconnect())},{rootMargin:"400px"});return $.observe(N),()=>$.disconnect()},[g]),a.useEffect(()=>{if(!g)return;const N=new AbortController;let $=null;C({status:"loading"});const T=window.setTimeout(()=>{N.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return sm(c,{signal:N.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const D=Number(U.headers.get("X-Image-Width"))||0,p=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:D,height:p}}).then(({blob:U,width:D,height:p})=>{N.signal.aborted||($=URL.createObjectURL(U),D>0&&p>0&&F({width:D,height:p}),C({status:"ready",objectUrl:$}))}).catch(()=>{const U=N.signal.reason;N.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||C({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),N.abort(),$&&URL.revokeObjectURL($)}},[g,c]);const B=Wu(t,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:Bi*2,height:Bi});return e.jsx("div",{ref:m,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:N=>{if(I)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&F({width:$.naturalWidth,height:$.naturalHeight})}}):y.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:N=>{if(I)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&F({width:$.naturalWidth,height:$.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:E.width,height:E.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function Es(t,n,s,l,u,c){const h=qg(s,u.markdownFilePath,u.rootPath);if(!h)return c?.fallbackText??``;const m=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(Xg,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return u.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:b=>{b.stopPropagation(),u.onImageOpen?.(m)},children:g},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},t)}function fi(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Pd(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Oi(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const qu="",Jg=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Qg(t){return t.replace(Jg,(n,s)=>`${qu}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Td(t){return t.replace(new RegExp(`${qu}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Zg(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Ku={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 _a=null;function Vu(){return _a||(_a=As(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw _a=null,t})),_a}function Yu({html:t}){const{t:n}=Rt(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),Vu().then(c=>{u||l(c.sanitize(t,Ku))}).catch(()=>{u||l("")}),()=>{u=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function eb({html:t}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Vu().then(u=>{l||s(u.sanitize(t,Ku))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function Xu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Fa=null;function tb(){return Fa||(Fa=Promise.all([As(()=>import("./katex-DnlPpQZa.js"),[]),As(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Fa=null,t})),Fa}function Ts({tex:t,display:n=!1}){const[s,l]=a.useState(null),[u,c]=a.useState(!1);if(a.useEffect(()=>{let m=!1;return l(null),c(!1),tb().then(g=>{m||l(g.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||c(!0)}),()=>{m=!0}},[n,t]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function Qi(t){const n=new Map;for(const s of t.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 Id(t){const n=Qi(t),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 rb(t){const n=t.indexOf(">"),s=n<0?t:t.slice(0,n+1),l=Qi(s),u=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),m=n<0?"":t.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:m,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function nb({url:t,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=Rt(),[c,h]=a.useState(!1),m=ro(t,()=>h(!0));return m?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()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:m,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function sb(t,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(t)){const h=t.slice(0,t.indexOf(">")+1),m=Qi(h).get("href")?.trim()??"",g=t.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:S,widthPx:y}=Id(g);if(!b)return null;const C=Ji(b,s.markdownFilePath,s.rootPath,qi,N=>N);if(!C)return null;const I=m?Xi(m,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===C)&&m?Du(m):null,E=Es(n,f??"",b,S,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(t)){const{src:h,alt:m,title:g,widthPx:b}=Id(t);return h?Es(n,m??"",h,g,s,{fallbackText:t,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(t)){const{src:h,fallbackText:m,widthPx:g,controls:b}=rb(t);if(!h)return null;const f=Kg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(nb,{url:f,fallbackText:m,widthPx:g,hasControls:b},n):null}if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(eb,{html:t},n):null;const u=l[1].toLowerCase(),c=it(l[2],`${n}-${u}`,!0,s);return u==="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):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):u==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function it(t,n,s=!0,l){const u=Qg(t),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 m=0,g;for(;(g=c.exec(u))!==null;){g.index>m&&h.push(Td(u.slice(m,g.index)));const b=g[0],f=`${n}-${g.index}`,S=b.startsWith("<")?sb(b,f,l):null;if(S)h.push(S);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(Ts,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(Ts,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const y=b.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:Zg(b.slice(y,-y))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:it(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:it(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:it(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const y=b.match(/^!\[([^\]]*)\]\((.*)\)$/),C=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^!\[([^\]]+)\]$/);if(y){const F=Oi(y[2]);h.push(F?Es(f,y[1],F.href,F.title,l):b)}else if(C){const F=C[2]||C[1],B=l.referenceDefinitions.get(qa(F));h.push(B?Es(f,C[1],B.href,B.title,l):b)}else if(I){const F=l.referenceDefinitions.get(qa(I[1]));h.push(F?Es(f,I[1],F.href,F.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const y=Ou(b.slice(2,-1)),C=l.footnoteDefinitions.get(y);h.push(C?e.jsx("sup",{id:`fnref-${C.id}`,title:C.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${C.id}`,className:"text-primary no-underline",children:C.index})},f):b)}else if(b.startsWith("<http")){const y=b.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(b.startsWith("<")&&b.endsWith(">")&&Pd(b.slice(1,-1))){const y=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(Pd(fi(b).linkText)){const{linkText:y,suffix:C}=fi(b);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:y,suffix:C}=fi(b),I=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:I,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else{const y=b.match(/^\[([^\]]+)\]\((.*)\)$/),C=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^\[([^\]]+)\]$/),F=C?C[2]||C[1]:I?.[1]??null,B=F?l.referenceDefinitions.get(qa(F)):null,E=y?Oi(y[2]):null,N=E?.href??B?.href??null,$=N?Du(N):null,T=y?.[1]??C?.[1]??I?.[1]??"";h.push($?e.jsx("a",{href:$,title:E?.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:it(T,`${f}-link`,s,l)},f):b)}m=c.lastIndex}return m<u.length&&h.push(Td(u.slice(m))),h.length>0?h:[t]}function Ju(t){return/(?: {2,}|\\)$/.test(t)}function Qu(t){return t.replace(/(?: {2,}|\\)$/,"")}function Ja(t){return/^(?: {4}|\t)/.test(t)}function Zu(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function ef(t,n,s){const l=[];return t.forEach((u,c)=>{const h=Ju(u);l.push(...it(Qu(u),`${n}-${c}`,!0,s)),c<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Ui(t,n,s){const l=[],u=[];return t.forEach((c,h)=>{u.push(Ju(c)),l.push(it(Qu(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function Hi(t,n,s,l,u){const c=[];return t.forEach((h,m)=>{const g=s[m]??0,b=!!(u&&g>=u.start&&g<=u.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":b?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&c.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),c}function Is(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,c=0,h=0;for(let m=0;m<n.length;m+=1){const g=n[m];if(u){l+=g,u=!1;continue}if(g==="\\"){u=!0;continue}if(g==="`"){const b=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const f=m-b+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return u&&(l+="\\"),s.push(l.trim()),s}function tf(t){return Is(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Qa(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Za(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function rf(t,n){return t>96||t>44&&n>.35}function ao(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Ds(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function Zi(t,n,s,l,u,c=new Set){const h=[],m=[];let g=n;for(;g<t.length;){const b=t[g];if(u&&(Xa(b)||c.has(g))){g+=1;continue}const f=Ds(b),S=ao(b);if(!f){if(S>s&&m.length>0){([...m].reverse().find(F=>F.indent<S)?.item??m[m.length-1].item).paragraphs.push(b.trim());for(const F of m)F.item.lineEnd=g+1;g+=1;continue}break}if(S<s||S===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;m.length>0&&m[m.length-1].indent>=S;)m.pop();const C=m[m.length-1]?.item??null;C?C.children.push(y):h.push(y),m.push({indent:S,item:y});for(const I of m)I.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function ab(t){const n=t.find(l=>Ds(l));if(!n)return[];const s=Ds(n);return s?Zi(t,0,ao(n),s.ordered,!0,Hu(t)).items:[]}function el(t,n,s,l=0){return t.map((u,c)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.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,it(h?.[2]??u.content,`li-${n}-${c}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((m,g)=>e.jsx("p",{children:it(m,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:ob(u.children,`${n}-${c}`,s,l)}})}function ob(t,n,s,l=0){const u=[];for(const c of t){const h=u[u.length-1];h&&h.ordered===c.ordered?h.items.push(c):u.push({ordered:c.ordered,items:[c]})}return u.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 tl(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&ib(s.groups,n)]},s.key)})}function ib(t,n){return t.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:tl(s.items,n)},`nested-${l}`)})}function lb(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[it(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function cb(t,n,s,l){const u=[];let c=0;const h=m=>l?.[m]??m+1;for(;c<t.length;){const m=t[c],g=m.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const E=c;let N="Details";const $=[];for(c+=1;c<t.length&&!/^<\/details>\s*$/i.test(t[c].trim());){const T=t[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?N=T[1].trim()||N:$.push(t[c].trimStart()),c+=1}c<t.length&&(c+=1),u.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:it(N,`${n}-details-${E}-summary`,!0,s)}),$.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:ef($,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const b=Xu(m);if(b){const E=[m],N=c;for(c+=1;c<t.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(t[c]);)E.push(t[c]),c+=1;c<t.length&&!b.selfContained&&(E.push(t[c]),c+=1),u.push({kind:"static",node:e.jsx(Yu,{html:E.join(`
|
|
1637
|
+
`+L.documentElement.outerHTML;return{html:$e,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(M,J){const fe=new Set,Re=Ce=>{if(Ce.source!==M.contentWindow||Ce.data?.capability!==u)return;if(Ce.data.type==="preview-ready"){M.contentWindow?.postMessage({type:"preview-init",capability:u,html:$e,resources:b},"*");return}if(Ce.data.type==="preview-error"){J("部分动态内容被安全预览限制");return}if(Ce.data.type==="preview-navigate"){(async()=>{const xe=j(String(Ce.data.url)),k=await mu(xe.pathname+xe.search,n);if(I){k.dispose();return}const Q=k.attach(M,J);F.add(()=>{Q(),k.dispose()}),M.src=k.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(xe=>J(xe instanceof Error?xe.message:"无法打开预览页面"));return}if(Ce.data.type==="preview-external"){try{const xe=new URL(String(Ce.data.url));xe.protocol==="https:"&&f.has(xe.origin)&&window.open(xe.href,"_blank","noopener,noreferrer")}catch{}return}if(Ce.data.type!=="preview-fetch"||Ce.ports.length!==1)return;const ce=Ce.ports[0];if(fe.size>=8||!["GET","HEAD"].includes(Ce.data.method)){ce.postMessage({error:"预览仅允许读取已授权目录资源"}),ce.close();return}fe.add(ce),(async()=>{const xe=j(String(Ce.data.url)),k=await q(xe);if(!fe.has(ce)||I)return;const Q=Ce.data.method==="HEAD"?new Uint8Array:k.bytes.slice();ce.postMessage({status:k.status,headers:{"content-type":k.type},data:Q.buffer},[Q.buffer])})().catch(()=>{ce.postMessage({error:"预览资源不在授权范围或无法加载"}),J("部分动态资源不可用或超出预览目录")}).finally(()=>{fe.delete(ce),ce.close()})};window.addEventListener("message",Re);const qe=()=>{window.removeEventListener("message",Re);for(const Ce of fe)Ce.close();fe.clear(),F.delete(qe)};return F.add(qe),qe},dispose:B}}catch(G){throw B(),G}}const ag=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},c){const h=a.useRef(null),[m,g]=a.useState(null),[b,f]=a.useState(),[S,y]=a.useState("");a.useEffect(()=>{const T=new AbortController;let U;return f(void 0),y(""),(async()=>{const D=await Mh();if(U=await mu(n,{fetch:(p,i)=>D.fetch(p,i),signal:T.signal}),T.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(D=>{T.signal.aborted||y(D instanceof Error?D.message:"安全预览加载失败")}),()=>{T.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!m))return b.attach(m,y)},[b,m]);const[C,I]=a.useState(!1),[F,B]=a.useState(!1),E=C||F;a.useEffect(()=>{u?.(E)},[E,u]),a.useEffect(()=>{const T=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",T),()=>document.removeEventListener("fullscreenchange",T)},[]),a.useEffect(()=>{if(!F)return;const T=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[F]);const N=a.useCallback(async()=>{const T=h.current;if(T){if(F){B(!1);return}if(document.fullscreenElement===T){await document.exitFullscreen();return}if(T.requestFullscreen&&document.fullscreenEnabled!==!1)try{await T.requestFullscreen();return}catch{}B(!0)}},[F]);a.useImperativeHandle(c,()=>({toggleFullscreen:N}),[N]);const $=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:E?"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:[E&&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:()=>{N()},"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(ru,{size:15})})]}),S&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:S}),!b&&!S&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return F?en.createPortal($,document.body):$}),pu="termdock-file-search-match",Pi="termdock-file-search-current";function og(t){const n=t.metaKey||t.ctrlKey,s=t.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||t.key==="F3"?t.shiftKey?"previous":"next":t.key==="Escape"?"close":null}function ig(t){return t.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function lg(t,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let u="",c=null;const h=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const S=ig(f);if(!S)continue;c&&c!==S&&(u+=`
|
|
1638
|
+
`);const y=u.length;u+=f.data,l.push({node:f,start:y,end:u.length,group:S}),c=S}const m=u.toLocaleLowerCase(),g=[];let b=0;for(;b<=m.length-s.length;){const f=m.indexOf(s,b);if(f<0)break;const S=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),C=l.find(I=>I.start<S&&I.end>=S);if(y&&C&&y.group===C.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(C.node,S-C.start),g.push(I)}b=f+Math.max(s.length,1)}return g}function gu(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Da(){const t=gu();t?.delete(pu),t?.delete(Pi)}function bd(t,n){const s=gu();if(!s||typeof Highlight>"u")return;s.set(pu,new Highlight(...t));const l=t[n];l?s.set(Pi,new Highlight(l)):s.delete(Pi)}function xd(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function cg(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function dg(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function ug(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function bu(t,n,s){return n?t:en.createPortal(t,s)}const Vi="termdock:right-sidebar:file-tree-scroll:v1",Yi="termdock:right-sidebar:file-preview-reading-state:v1",js="termdock:right-sidebar:file-tree-width:v1",xu="termdock:right-sidebar:markdown-view-mode:v1",vu="termdock:right-sidebar:diff-change-list-mode:v1",yu="termdock:right-sidebar:diff-wrap:v1",wu="termdock:diff-viewer:view-type:v1",ku="termdock:right-sidebar:file-search-mode:v1",ai="termdock:right-sidebar:collapsed-git-repo-groups:v1",vd="termdock:right-sidebar:collapsed-diff-directories:v1",oi="termdock:right-sidebar:branch-audit-module-open:v1",Su="termdock:right-sidebar:branch-audit-module:v1",fg=150,ju="termdock:right-sidebar:active-git-repo:v1",yd="termdock:right-sidebar:context-draft-enabled:v1",wd="termdock:right-sidebar:context-draft-collapsed:v1",kd="termdock:right-sidebar:context-draft-auto-collapse:v1",ii="termdock:right-sidebar:context-draft-text:v1",hg=300,mg=20,pg=120,gg=250,bg=250,xg=120,vg=700,li=600;function Vn(t){return!!(t&&Z.getState().nestedGitScanRoots[t])}const Sd=[2e3,5e3,15e3,3e4],yg=320,wg=500,kg=20,Sg=12e3,Ti=300,jd=240,jg=560,Ru="border-r px-2 py-1.5 sm:px-3 sm:py-2",Ya="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Cu=`${Ru} border-b border-border/15 font-semibold last:border-r-0`,Nu=`${Ru} border-border/10 align-top text-muted-foreground last:border-r-0`,Xi="termdock-file-preview-horizontal-scroll",Rd=a.lazy(()=>As(()=>import("./ModelPreview-jn0vZDsm.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Mu=`${Xi} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Eu(t,n,s){return t&&!n?"unified":s}const Rg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Cg(t){return t==="preview"||t==="source"}function Ng(t){return t==="list"||t==="tree"||t==="ai"}function Cd(){return ot(xu,Cg)??"preview"}function Mg(){return ot(vu,Ng)??"tree"}function Rs(t){return typeof t=="boolean"}function Eg(t){return typeof t=="string"}function $g(){return ot(yu,Rs)??!0}function Lg(t){return t==="unified"||t==="split"}function Ag(){return ot(wu,Lg)??"unified"}function Pg(t){return t==="name"||t==="content"||t==="regex"}function Tg(){return ot(ku,Pg)??"name"}function $u(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:xt(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function Ig(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function Lu(){return ot(ju,Ig)??{}}function Nd(t){if(!t)return;const n=Lu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function ci(t,n){t&&St(ju,{...Lu(),[t]:n})}function Dg(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function Ii(t){return!t.activeGitRepoRoot&&(t.groupCount>1||t.label!==t.rootName)}function Au(...t){const n=new Set;for(const s of t)for(const l of s)n.add(l.root);return n}function Di(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function Md(t){const n=ot(t,Di);return n?new Set(n):new Set}function di(t,n){St(t,[...n])}function _g(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function Fg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||Di(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(_g))&&(n.commits===void 0||Di(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 Bg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&Fg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Og(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(Bg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Ed(){return ot(Su,Og)??{}}function $d(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function Ld(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Pu(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||Ld(s)===Ld(l)}function Ad(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!Pu(l,n))??""}function _i(t,n){const s=Math.max(jd,n-320),l=Math.min(jg,s);return Math.min(l,Math.max(jd,t))}function Ug(t){return typeof t=="number"&&Number.isFinite(t)}function Hg(t){return _i(ot(js,Ug)??Ti,t)}function Tu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function ks(t){return Rg.has(Tu(t))}function Iu(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Fi(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||Iu(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Du(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const _u=a.createContext(null);function qa(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function Fu(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function Bu(t){return t.replace(/\s+#+\s*$/,"").trim()}function Bi(t,n){const l=Fu(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function Pd(t){return Fu(t)||t.trim()}function Xa(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ui(n[2]);return s?{id:qa(n[1]),definition:{href:s.href,title:s.title}}:null}function zg(t){const n=new Map;for(const s of t){const l=Xa(s);l&&n.set(l.id,l.definition)}return n}function Ou(t){return t.trim().toLowerCase()}function Uu(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Ou(n[1]),text:n[2]}:null}function Wg(t){const n=new Map;let s=null;for(const l of t){const u=Uu(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.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 Hu(t){const n=new Set;let s=!1;return t.forEach((l,u)=>{if(Uu(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function Gg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const u=t[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function zu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Ms(t){const n=t.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 Ji(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const u=l.indexOf("#"),c=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",m=c.split("?",1)[0];if(!m)return null;let g,b=null;try{g=decodeURIComponent(m),b=h?decodeURIComponent(h):null}catch{return null}const f=s?Ms(s):null;let S;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));S=Ms(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;S=Ms(`${zu(n)}/${g}`)}return f&&S!==f&&!S.startsWith(`${f}/`)?null:{path:S,fragment:b,directory:/\/$/.test(m)}}function Qi(t,n,s,l,u){const c=t.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 m=s&&(c===s||c.startsWith(`${s}/`));h=Ms(s&&!m?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Ms(`${zu(n)}/${c}`)}return u(h)}function qg(t,n,s){return Qi(t,n,s,Ki,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Kg(t,n,s){return Qi(t,n,s,Kd,Vd)}const Oi=128,Vg=360,ui=480;function so(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function Wu(t,n,s,l,u=0){if(!n||!s)return null;let c,h;return u>0?(c=l>0?Math.min(u,l):u,h=s*c/n):so(t)?(h=Math.min(Math.max(s,Oi),Vg),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>ui&&(c=c*ui/h,h=ui),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Yg(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function Gu(t){const n=Yg(t),s=Z(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function Xg({src:t,alt:n,title:s,requestedWidthPx:l}){const u=so(t),c=Gu(t),h=ro(c),m=a.useRef(null),[g,b]=a.useState(!1),[f,S]=a.useState(0),[y,C]=a.useState({status:"loading"}),[I,F]=a.useState(null);a.useLayoutEffect(()=>{const N=m.current,$=N?.parentElement?.parentElement??N?.parentElement;if(!$)return;const T=()=>S($.clientWidth);if(T(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(T);return U.observe($),()=>U.disconnect()},[]),a.useEffect(()=>{if(g)return;const N=m.current;if(!N||typeof IntersectionObserver>"u"){b(!0);return}const $=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(b(!0),$.disconnect())},{rootMargin:"400px"});return $.observe(N),()=>$.disconnect()},[g]),a.useEffect(()=>{if(!g)return;const N=new AbortController;let $=null;C({status:"loading"});const T=window.setTimeout(()=>{N.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return sm(c,{signal:N.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const D=Number(U.headers.get("X-Image-Width"))||0,p=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:D,height:p}}).then(({blob:U,width:D,height:p})=>{N.signal.aborted||($=URL.createObjectURL(U),D>0&&p>0&&F({width:D,height:p}),C({status:"ready",objectUrl:$}))}).catch(()=>{const U=N.signal.reason;N.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||C({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),N.abort(),$&&URL.revokeObjectURL($)}},[g,c]);const B=Wu(t,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:Oi*2,height:Oi});return e.jsx("div",{ref:m,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:N=>{if(I)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&F({width:$.naturalWidth,height:$.naturalHeight})}}):y.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:N=>{if(I)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&F({width:$.naturalWidth,height:$.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:E.width,height:E.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function Es(t,n,s,l,u,c){const h=qg(s,u.markdownFilePath,u.rootPath);if(!h)return c?.fallbackText??``;const m=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(Xg,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return u.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:b=>{b.stopPropagation(),u.onImageOpen?.(m)},children:g},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},t)}function fi(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Td(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Ui(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const qu="",Jg=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Qg(t){return t.replace(Jg,(n,s)=>`${qu}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Id(t){return t.replace(new RegExp(`${qu}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Zg(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Ku={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 _a=null;function Vu(){return _a||(_a=As(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw _a=null,t})),_a}function Yu({html:t}){const{t:n}=Rt(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),Vu().then(c=>{u||l(c.sanitize(t,Ku))}).catch(()=>{u||l("")}),()=>{u=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function eb({html:t}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Vu().then(u=>{l||s(u.sanitize(t,Ku))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function Xu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Fa=null;function tb(){return Fa||(Fa=Promise.all([As(()=>import("./katex-DnlPpQZa.js"),[]),As(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Fa=null,t})),Fa}function Ts({tex:t,display:n=!1}){const[s,l]=a.useState(null),[u,c]=a.useState(!1);if(a.useEffect(()=>{let m=!1;return l(null),c(!1),tb().then(g=>{m||l(g.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||c(!0)}),()=>{m=!0}},[n,t]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function Zi(t){const n=new Map;for(const s of t.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 Dd(t){const n=Zi(t),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 rb(t){const n=t.indexOf(">"),s=n<0?t:t.slice(0,n+1),l=Zi(s),u=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),m=n<0?"":t.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:m,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function nb({url:t,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=Rt(),[c,h]=a.useState(!1),m=ro(t,()=>h(!0));return m?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()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:m,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function sb(t,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(t)){const h=t.slice(0,t.indexOf(">")+1),m=Zi(h).get("href")?.trim()??"",g=t.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:S,widthPx:y}=Dd(g);if(!b)return null;const C=Qi(b,s.markdownFilePath,s.rootPath,Ki,N=>N);if(!C)return null;const I=m?Ji(m,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===C)&&m?Du(m):null,E=Es(n,f??"",b,S,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(t)){const{src:h,alt:m,title:g,widthPx:b}=Dd(t);return h?Es(n,m??"",h,g,s,{fallbackText:t,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(t)){const{src:h,fallbackText:m,widthPx:g,controls:b}=rb(t);if(!h)return null;const f=Kg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(nb,{url:f,fallbackText:m,widthPx:g,hasControls:b},n):null}if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(eb,{html:t},n):null;const u=l[1].toLowerCase(),c=it(l[2],`${n}-${u}`,!0,s);return u==="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):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):u==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function it(t,n,s=!0,l){const u=Qg(t),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 m=0,g;for(;(g=c.exec(u))!==null;){g.index>m&&h.push(Id(u.slice(m,g.index)));const b=g[0],f=`${n}-${g.index}`,S=b.startsWith("<")?sb(b,f,l):null;if(S)h.push(S);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(Ts,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(Ts,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const y=b.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:Zg(b.slice(y,-y))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:it(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:it(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:it(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const y=b.match(/^!\[([^\]]*)\]\((.*)\)$/),C=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^!\[([^\]]+)\]$/);if(y){const F=Ui(y[2]);h.push(F?Es(f,y[1],F.href,F.title,l):b)}else if(C){const F=C[2]||C[1],B=l.referenceDefinitions.get(qa(F));h.push(B?Es(f,C[1],B.href,B.title,l):b)}else if(I){const F=l.referenceDefinitions.get(qa(I[1]));h.push(F?Es(f,I[1],F.href,F.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const y=Ou(b.slice(2,-1)),C=l.footnoteDefinitions.get(y);h.push(C?e.jsx("sup",{id:`fnref-${C.id}`,title:C.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${C.id}`,className:"text-primary no-underline",children:C.index})},f):b)}else if(b.startsWith("<http")){const y=b.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(b.startsWith("<")&&b.endsWith(">")&&Td(b.slice(1,-1))){const y=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(Td(fi(b).linkText)){const{linkText:y,suffix:C}=fi(b);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:y,suffix:C}=fi(b),I=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:I,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else{const y=b.match(/^\[([^\]]+)\]\((.*)\)$/),C=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^\[([^\]]+)\]$/),F=C?C[2]||C[1]:I?.[1]??null,B=F?l.referenceDefinitions.get(qa(F)):null,E=y?Ui(y[2]):null,N=E?.href??B?.href??null,$=N?Du(N):null,T=y?.[1]??C?.[1]??I?.[1]??"";h.push($?e.jsx("a",{href:$,title:E?.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:it(T,`${f}-link`,s,l)},f):b)}m=c.lastIndex}return m<u.length&&h.push(Id(u.slice(m))),h.length>0?h:[t]}function Ju(t){return/(?: {2,}|\\)$/.test(t)}function Qu(t){return t.replace(/(?: {2,}|\\)$/,"")}function Ja(t){return/^(?: {4}|\t)/.test(t)}function Zu(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function ef(t,n,s){const l=[];return t.forEach((u,c)=>{const h=Ju(u);l.push(...it(Qu(u),`${n}-${c}`,!0,s)),c<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Hi(t,n,s){const l=[],u=[];return t.forEach((c,h)=>{u.push(Ju(c)),l.push(it(Qu(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function zi(t,n,s,l,u){const c=[];return t.forEach((h,m)=>{const g=s[m]??0,b=!!(u&&g>=u.start&&g<=u.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":b?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&c.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),c}function Is(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,c=0,h=0;for(let m=0;m<n.length;m+=1){const g=n[m];if(u){l+=g,u=!1;continue}if(g==="\\"){u=!0;continue}if(g==="`"){const b=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const f=m-b+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return u&&(l+="\\"),s.push(l.trim()),s}function tf(t){return Is(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Qa(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Za(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function rf(t,n){return t>96||t>44&&n>.35}function ao(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Ds(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function el(t,n,s,l,u,c=new Set){const h=[],m=[];let g=n;for(;g<t.length;){const b=t[g];if(u&&(Xa(b)||c.has(g))){g+=1;continue}const f=Ds(b),S=ao(b);if(!f){if(S>s&&m.length>0){([...m].reverse().find(F=>F.indent<S)?.item??m[m.length-1].item).paragraphs.push(b.trim());for(const F of m)F.item.lineEnd=g+1;g+=1;continue}break}if(S<s||S===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;m.length>0&&m[m.length-1].indent>=S;)m.pop();const C=m[m.length-1]?.item??null;C?C.children.push(y):h.push(y),m.push({indent:S,item:y});for(const I of m)I.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function ab(t){const n=t.find(l=>Ds(l));if(!n)return[];const s=Ds(n);return s?el(t,0,ao(n),s.ordered,!0,Hu(t)).items:[]}function tl(t,n,s,l=0){return t.map((u,c)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.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,it(h?.[2]??u.content,`li-${n}-${c}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((m,g)=>e.jsx("p",{children:it(m,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:ob(u.children,`${n}-${c}`,s,l)}})}function ob(t,n,s,l=0){const u=[];for(const c of t){const h=u[u.length-1];h&&h.ordered===c.ordered?h.items.push(c):u.push({ordered:c.ordered,items:[c]})}return u.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:tl(c.items,`${n}-g${h}`,s,l)}))}function rl(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&ib(s.groups,n)]},s.key)})}function ib(t,n){return t.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:rl(s.items,n)},`nested-${l}`)})}function lb(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[it(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function cb(t,n,s,l){const u=[];let c=0;const h=m=>l?.[m]??m+1;for(;c<t.length;){const m=t[c],g=m.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const E=c;let N="Details";const $=[];for(c+=1;c<t.length&&!/^<\/details>\s*$/i.test(t[c].trim());){const T=t[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?N=T[1].trim()||N:$.push(t[c].trimStart()),c+=1}c<t.length&&(c+=1),u.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:it(N,`${n}-details-${E}-summary`,!0,s)}),$.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:ef($,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const b=Xu(m);if(b){const E=[m],N=c;for(c+=1;c<t.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(t[c]);)E.push(t[c]),c+=1;c<t.length&&!b.selfContained&&(E.push(t[c]),c+=1),u.push({kind:"static",node:e.jsx(Yu,{html:E.join(`
|
|
1639
1639
|
`)},`${n}-html-${N}`)});continue}const f=g.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],N=f[1],$=f[2]?.trim(),T=c;for(c+=1;c<t.length&&!t[c].trim().startsWith(N);)E.push(t[c]),c+=1;c<t.length&&(c+=1),$.toLowerCase()==="mermaid"?u.push({kind:"static",node:e.jsx(sf,{code:E.join(`
|
|
1640
1640
|
`),blockKey:`${n}-code-${T}`},`${n}-code-${T}`)}):["math","latex","tex"].includes($.toLowerCase())?u.push({kind:"static",node:e.jsx(Ts,{tex:E.join(`
|
|
1641
1641
|
`),display:!0},`${n}-code-${T}`)}):u.push({kind:"code",key:`${n}-code-${T}`,code:E.join(`
|
|
1642
1642
|
`),lang:$,blockKey:`${n}-code-${T}`,codeStartLine:h(T)+1});continue}if(Ja(m)){const E=[],N=c;for(;c<t.length&&(Ja(t[c])||!t[c].trim());)E.push(t[c].trim()?Zu(t[c]):""),c+=1;u.push({kind:"code",key:`${n}-indented-code-${N}`,code:E.join(`
|
|
1643
|
-
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${N}`,codeStartLine:h(N)});continue}const S=g.match(/^(#{1,6})\s+(.+)$/);if(S){const N=`h${Math.min(6,S[1].length+1)}`,$=Bu(S[2]),T=
|
|
1644
|
-
`).map(b=>[b||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${
|
|
1645
|
-
`:null]},`${s}-line-${f}`)})})})]})}function
|
|
1643
|
+
`).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${N}`,codeStartLine:h(N)});continue}const S=g.match(/^(#{1,6})\s+(.+)$/);if(S){const N=`h${Math.min(6,S[1].length+1)}`,$=Bu(S[2]),T=Bi($,s);u.push({kind:"static",node:e.jsx(N,{id:T,className:"scroll-mt-16 font-semibold text-foreground",children:it($,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<t.length&&m.includes("|")&&Za(t[c+1])){const E=Is(m),N=tf(t[c+1]),$=[],T=c;for(c+=2;c<t.length&&t[c].includes("|")&&t[c].trim();)$.push(Is(t[c])),c+=1;u.push({kind:"static",node:e.jsx("div",{className:Mu,"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:E.map((U,D)=>e.jsx("th",{className:`${Cu} ${Qa(N[D]??null)}`,children:e.jsx("div",{className:Ya,children:it(U,`${n}-th-${T}-${D}`,!0,s)})},`h-${D}`))})}),e.jsx("tbody",{children:$.map((U,D)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((p,i)=>e.jsx("td",{className:`${Nu} ${Qa(N[i]??null)}`,children:e.jsx("div",{className:Ya,children:it(U[i]??"",`${n}-td-${T}-${D}-${i}`,!0,s)})},`c-${i}`))},`r-${D}`))})]})},`${n}-table-${T}`)});continue}const y=Ds(m);if(y){const E=y.ordered,N=ao(m),$=y.start,T=c,U=el(t,c,N,E,!1);c=U.nextIndex,u.push({kind:"list",keyPrefix:`${n}-list-${T}`,ordered:E,start:E?$:void 0,renders:tl(U.items,`${n}-list-${T}`,s,h(0)-1)});continue}const C=[m.trimStart()],I=[h(c)],F=c;for(c+=1;c<t.length&&t[c].trim()&&!Fi(t[c])&&!(c+1<t.length&&t[c].includes("|")&&Za(t[c+1]));)C.push(t[c].trimStart()),I.push(h(c)),c+=1;const B=Hi(C,`${n}-p-${F}`,s);u.push({kind:"paragraph",keyPrefix:`${n}-p-${F}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:I})}return u}function db(t,n){return t.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:zi(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:rl(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(eo,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Ba=null,_d=!1;const Oa=16,nf=192;function ub(){return Ba||(Ba=As(()=>import("./mermaid.core-VzkSqOKz.js").then(t=>t.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(t=>t.default??t).catch(t=>{throw Ba=null,t})),Ba}function fb(t){_d||(t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),_d=!0)}function hb(t){const n=t.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return t;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,u,c]=l;if(!Number.isFinite(u)||!Number.isFinite(c)||u<=0||c<=0)return t;const h=Math.max(nf,Math.ceil(u)),m=Math.ceil(h/u*c);return t.replace(/<svg\b([^>]*)>/i,(g,b)=>`<svg${b.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${m}">`)}function mb(t){const n=t?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-Oa,u=s.y-Oa,c=s.width+Oa*2,h=s.height+Oa*2,m=Math.max(nf,Math.ceil(c)),g=Math.ceil(m/c*h);n.setAttribute("viewBox",`${l} ${u} ${c} ${h}`),n.setAttribute("width",String(m)),n.setAttribute("height",String(g)),n.removeAttribute("style")}function pb(t){const n=t.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return nu(`code.${s}`)??s}function sf({code:t,blockKey:n}){const{t:s}=Rt(),[l,u]=a.useState(null),[c,h]=a.useState(!1),m=a.useRef(null),g=a.useContext(_u);a.useEffect(()=>{let f=!1;return u(null),h(!1),ub().then(async S=>{fb(S);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:C}=await S.render(y,t);f||u(hb(C))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,t]),a.useLayoutEffect(()=>{l&&mb(m.current)},[l]);const b=a.useCallback(()=>{const f=m.current?.querySelector("svg")?.outerHTML??l;f&&g?.(f)},[g,l]);return c?e.jsx(eo,{code:t,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:f=>{f.stopPropagation(),b()},children:e.jsx("span",{ref:m,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function eo({code:t,lang:n,blockKey:s,codeStartLine:l,lineRange:u}){const c=pb(n),[h,m]=a.useState(null);a.useEffect(()=>{if(!c||!su(t)){m(null);return}let b=!1;return au().then(f=>{if(b||!f.registered(c)){b||m(null);return}try{m(ou(f,t,c))}catch{b||m(null)}}).catch(()=>{b||m(null)}),()=>{b=!0}},[s,t,c]);const g=h??(t||" ").split(`
|
|
1644
|
+
`).map(b=>[b||" "]);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:`${Xi} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:g.map((b,f)=>{const S=l!=null?l+f:null,y=!!(u&&S!=null&&S>=u.start&&S<=u.end);return e.jsxs("span",{"data-md-ref-start":S??void 0,"data-md-ref-end":S??void 0,"data-selected":y?"true":void 0,children:[b,f<g.length-1?`
|
|
1645
|
+
`:null]},`${s}-line-${f}`)})})})]})}function nl(t,n,s,l,u){t=Gg(t);const c=zg(t),h=Hu(t),m=[],g={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:Wg(t),headingSlugCounts:new Map,images:m,onImageOpen:l,footnotesLabel:u?.footnotes??"Footnotes",backToFootnoteLabel:u?.backToFootnote??(y=>`Back to footnote ${y}`)},b=[];let f=0;for(;f<t.length;){const y=t[f],C=y.trim();if(Xa(y)||h.has(f)){f+=1;continue}if(!C){f+=1;continue}if(/^<details>\s*$/i.test(C)){const D=f;let p="Details";const i=[];for(f+=1;f<t.length&&!/^<\/details>\s*$/i.test(t[f].trim());){const O=t[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?p=O[1].trim()||p:i.push(t[f].trimStart()),f+=1}f<t.length&&(f+=1),b.push({key:`details-${D}`,startLine:D+1,endLine:f,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:it(p,`details-${D}-summary`,!0,g)}),i.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:ef(i,`details-${D}`,g)})]})});continue}const I=Xu(y);if(I){const D=[y],p=f;for(f+=1;f<t.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(t[f]);)D.push(t[f]),f+=1;f<t.length&&!I.selfContained&&(D.push(t[f]),f+=1),b.push({key:`html-${p}`,startLine:p+1,endLine:f,content:e.jsx(Yu,{html:D.join(`
|
|
1646
1646
|
`)})});continue}const F=C.match(/^(```|~~~)\s*(.*)$/);if(F){const D=[],p=F[1],i=F[2]?.trim(),O=f;for(f+=1;f<t.length&&!t[f].trim().startsWith(p);)D.push(t[f]),f+=1;f<t.length&&(f+=1),b.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:i.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(i.toLowerCase()),content:i.toLowerCase()==="mermaid"?e.jsx(sf,{code:D.join(`
|
|
1647
1647
|
`),blockKey:`code-${O}`}):["math","latex","tex"].includes(i.toLowerCase())?e.jsx(Ts,{tex:D.join(`
|
|
1648
1648
|
`),display:!0}):j=>e.jsx(eo,{code:D.join(`
|
|
1649
1649
|
`),lang:i,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:j})});continue}if(Ja(y)){const D=[],p=f;for(f+=0;f<t.length&&(Ja(t[f])||!t[f].trim());)D.push(t[f].trim()?Zu(t[f]):""),f+=1;b.push({key:`indented-code-${p}`,startLine:p+1,endLine:f,fineGrained:!0,content:i=>e.jsx(eo,{code:D.join(`
|
|
1650
1650
|
`).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${p}`,codeStartLine:p+1,lineRange:i})});continue}if(C.startsWith("$$")){const D=[],p=f,i=C.replace(/^\$\$\s*/,"");if(i.endsWith("$$")&&i.length>2)D.push(i.replace(/\s*\$\$$/,"")),f+=1;else{for(i&&D.push(i),f+=1;f<t.length&&!t[f].trim().endsWith("$$");)D.push(t[f]),f+=1;if(f<t.length){const O=t[f].trim().replace(/\s*\$\$$/,"");O&&D.push(O),f+=1}}b.push({key:`math-${p}`,startLine:p+1,endLine:f,content:e.jsx(Ts,{tex:D.join(`
|
|
1651
|
-
`),display:!0})});continue}if(f+1<t.length&&C&&!_i(y)&&/^(=+|-+)\s*$/.test(t[f+1].trim())){const D=t[f+1].trim().startsWith("=")?1:2,p=`h${D}`,i=Fi(C,g),O={level:D,text:Ad(C),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(p,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:it(C,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const B=C.match(/^(#{1,6})\s+(.+)$/);if(B){const D=B[1].length,p=Bu(B[2]),i={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${D}`,j=Fi(p,g),q={level:D,text:Ad(p),id:j};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:q,content:e.jsx(O,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${i[D]}`,children:it(p,`heading-${f}`,!0,g)})}),f+=1;continue}if(Iu(y)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(C.startsWith(">")){const D=[],p=[],i=f;for(;f<t.length&&/^>\s?/.test(t[f].trim());)D.push(t[f].trim().replace(/^>\s?/,"")),p.push(f+1),f+=1;const O=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const q=O[1].toUpperCase(),le=O[2]?.trim(),ne=[...le?[le]:[],...D.slice(1)],ue=[...le?[p[0]]:[],...p.slice(1)],G=Ui(ne,`callout-${i}`,g);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:Y=>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:q}),ne.length>0&&e.jsx("div",{children:Hi(G.perLine,G.hardBreaks,ue,`callout-${i}`,Y)})]})});continue}const j=cb(D,`quote-${i}`,g,p);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:q=>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:db(j,q)})});continue}if(f+1<t.length&&y.includes("|")&&Za(t[f+1])){const D=Is(y),p=tf(t[f+1]),i=[],O=f;for(f+=2;f<t.length&&t[f].includes("|")&&t[f].trim();)i.push(Is(t[f])),f+=1;const j=D.map((le,ne)=>it(le,`th-${O}-${ne}`,!0,g)),q=i.map((le,ne)=>D.map((ue,G)=>it(le[G]??"",`td-${O}-${ne}-${G}`,!0,g)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:le=>{const ne=ue=>!!(le&&ue>=le.start&&ue<=le.end);return e.jsx("div",{className:Mu,"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":ne(O+1)?"true":void 0,children:j.map((ue,G)=>e.jsx("th",{className:`${Cu} ${Qa(p[G]??null)}`,children:e.jsx("div",{className:Ya,children:ue})},`h-${G}`))})}),e.jsx("tbody",{children:q.map((ue,G)=>{const Y=O+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":Y,"data-md-ref-start":Y,"data-md-ref-end":Y,"data-selected":ne(Y)?"true":void 0,children:D.map((L,_)=>e.jsx("td",{className:`${Nu} ${Qa(p[_]??null)}`,children:e.jsx("div",{className:Ya,children:ue[_]})},`c-${_}`))},`r-${G}`)})})]})})}});continue}const E=Ds(y);if(E){const D=E.ordered,p=ao(y),i=E.start,O=f,j=Zi(t,f,p,D,!0,h);f=j.nextIndex;const q=D?"ol":"ul",le=el(j.items,`list-${O}`,g);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:ne=>e.jsx(q,{start:D?i:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:tl(le,ne)})});continue}const N=[y.trimStart()],$=[f+1],T=f;for(f+=1;f<t.length&&t[f].trim()&&!_i(t[f])&&!(f+1<t.length&&t[f].includes("|")&&Za(t[f+1]));){if(Xa(t[f])||h.has(f)){f+=1;continue}N.push(t[f].trimStart()),$.push(f+1),f+=1}const U=Ui(N,`p-${T}`,g);b.push({key:`p-${T}`,startLine:T+1,endLine:f,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:Hi(U.perLine,U.hardBreaks,$,`p-${T}`,D)})})}const S=lb(g);return S&&b.push({key:"footnotes",startLine:t.length,endLine:t.length,content:S}),{blocks:b,images:m}}function gb(t,n,s){return rl(t,n,s).blocks}function af(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function of(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function bb({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const u=Gu(t);return e.jsx(yf,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function lf({images:t,index:n,onChange:s,onClose:l}){const{t:u}=Rt(),c=t[n],h=t.length>1,m=a.useRef(null),g=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[S,y]=a.useState(!1),[C,I]=a.useState(0),[F,B]=a.useState(!1),E=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),N=a.useCallback(()=>{S||Date.now()<f.current||(E(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[E,S,l]),$=a.useCallback(p=>{if(t.length===0)return;const i=(p+t.length)%t.length;m.current?.slideTo(i),s(i)},[t.length,s]),T=a.useCallback(()=>$(n-1),[$,n]),U=a.useCallback(()=>$(n+1),[$,n]);if(a.useEffect(()=>{E(),I(0),B(!1),y(!1)},[E,n]),a.useEffect(()=>{const p=m.current;p&&(p.allowTouchMove=h&&!S)},[h,S]),a.useEffect(()=>{const p=m.current;!p||p.activeIndex===n||p.slideTo(n,0)},[n]),a.useEffect(()=>E,[E]),a.useEffect(()=>{const p=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),T()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[h,U,T,l]),Jd({onDrag:({movement:[p,i],pinching:O})=>{O||S||Math.abs(i)<Math.abs(p)*1.15&&C===0||(B(!0),Math.abs(i)>8&&(f.current=Date.now()+300),I(Math.max(0,i)))},onDragEnd:({movement:[p,i],velocity:[,O],pinching:j,canceled:q})=>{if(B(!1),j||q||S||Math.abs(i)<Math.abs(p)*1.15){I(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),rf(i,O)){l();return}I(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const D=c.title||c.alt||(c.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:en.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick: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":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx($s,{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":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(Uh,{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":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Gt,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:N,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${C}px, 0) scale(${Math.max(.86,1-C/900)})`,opacity:Math.max(.35,1-C/360),transition:F?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Qd,{onSwiper:p=>{m.current=p,p.allowTouchMove=h&&!S},onSlideChange:p=>{p.activeIndex!==n&&s(p.activeIndex)},onSliderMove:()=>{E(),f.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:t.map((p,i)=>e.jsx(Ri,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:p.kind==="image"?e.jsx(bb,{src:p.src,alt:p.alt||p.title||u("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(Pb,{svg:p.svg,title:p.title||p.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${p.kind}-${i}-${p.alt}`))})})})]})]}),document.body)}function cf({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:c,scrollTop:h,outlineOpen:m,outlineCloseSignal:g,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:S,lightboxCloseSignal:y,onLightboxOpen:C,onLightboxClose:I,onLocalLinkOpen:F}){const{t:B}=Rt(),[E,N]=a.useState(null),[$,T]=a.useState(null),[U,D]=a.useState(1),[p,i]=a.useState(null),O=a.useRef(null),j=a.useRef(null),{blocks:q,images:le}=a.useMemo(()=>rl(t.split(`
|
|
1651
|
+
`),display:!0})});continue}if(f+1<t.length&&C&&!Fi(y)&&/^(=+|-+)\s*$/.test(t[f+1].trim())){const D=t[f+1].trim().startsWith("=")?1:2,p=`h${D}`,i=Bi(C,g),O={level:D,text:Pd(C),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(p,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:it(C,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const B=C.match(/^(#{1,6})\s+(.+)$/);if(B){const D=B[1].length,p=Bu(B[2]),i={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${D}`,j=Bi(p,g),q={level:D,text:Pd(p),id:j};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:q,content:e.jsx(O,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${i[D]}`,children:it(p,`heading-${f}`,!0,g)})}),f+=1;continue}if(Iu(y)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(C.startsWith(">")){const D=[],p=[],i=f;for(;f<t.length&&/^>\s?/.test(t[f].trim());)D.push(t[f].trim().replace(/^>\s?/,"")),p.push(f+1),f+=1;const O=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const q=O[1].toUpperCase(),le=O[2]?.trim(),ne=[...le?[le]:[],...D.slice(1)],ue=[...le?[p[0]]:[],...p.slice(1)],G=Hi(ne,`callout-${i}`,g);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:Y=>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:q}),ne.length>0&&e.jsx("div",{children:zi(G.perLine,G.hardBreaks,ue,`callout-${i}`,Y)})]})});continue}const j=cb(D,`quote-${i}`,g,p);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:q=>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:db(j,q)})});continue}if(f+1<t.length&&y.includes("|")&&Za(t[f+1])){const D=Is(y),p=tf(t[f+1]),i=[],O=f;for(f+=2;f<t.length&&t[f].includes("|")&&t[f].trim();)i.push(Is(t[f])),f+=1;const j=D.map((le,ne)=>it(le,`th-${O}-${ne}`,!0,g)),q=i.map((le,ne)=>D.map((ue,G)=>it(le[G]??"",`td-${O}-${ne}-${G}`,!0,g)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:le=>{const ne=ue=>!!(le&&ue>=le.start&&ue<=le.end);return e.jsx("div",{className:Mu,"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":ne(O+1)?"true":void 0,children:j.map((ue,G)=>e.jsx("th",{className:`${Cu} ${Qa(p[G]??null)}`,children:e.jsx("div",{className:Ya,children:ue})},`h-${G}`))})}),e.jsx("tbody",{children:q.map((ue,G)=>{const Y=O+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":Y,"data-md-ref-start":Y,"data-md-ref-end":Y,"data-selected":ne(Y)?"true":void 0,children:D.map((L,_)=>e.jsx("td",{className:`${Nu} ${Qa(p[_]??null)}`,children:e.jsx("div",{className:Ya,children:ue[_]})},`c-${_}`))},`r-${G}`)})})]})})}});continue}const E=Ds(y);if(E){const D=E.ordered,p=ao(y),i=E.start,O=f,j=el(t,f,p,D,!0,h);f=j.nextIndex;const q=D?"ol":"ul",le=tl(j.items,`list-${O}`,g);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:ne=>e.jsx(q,{start:D?i:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:rl(le,ne)})});continue}const N=[y.trimStart()],$=[f+1],T=f;for(f+=1;f<t.length&&t[f].trim()&&!Fi(t[f])&&!(f+1<t.length&&t[f].includes("|")&&Za(t[f+1]));){if(Xa(t[f])||h.has(f)){f+=1;continue}N.push(t[f].trimStart()),$.push(f+1),f+=1}const U=Hi(N,`p-${T}`,g);b.push({key:`p-${T}`,startLine:T+1,endLine:f,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:zi(U.perLine,U.hardBreaks,$,`p-${T}`,D)})})}const S=lb(g);return S&&b.push({key:"footnotes",startLine:t.length,endLine:t.length,content:S}),{blocks:b,images:m}}function gb(t,n,s){return nl(t,n,s).blocks}function af(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function of(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function bb({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const u=Gu(t);return e.jsx(yf,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function lf({images:t,index:n,onChange:s,onClose:l}){const{t:u}=Rt(),c=t[n],h=t.length>1,m=a.useRef(null),g=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[S,y]=a.useState(!1),[C,I]=a.useState(0),[F,B]=a.useState(!1),E=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),N=a.useCallback(()=>{S||Date.now()<f.current||(E(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[E,S,l]),$=a.useCallback(p=>{if(t.length===0)return;const i=(p+t.length)%t.length;m.current?.slideTo(i),s(i)},[t.length,s]),T=a.useCallback(()=>$(n-1),[$,n]),U=a.useCallback(()=>$(n+1),[$,n]);if(a.useEffect(()=>{E(),I(0),B(!1),y(!1)},[E,n]),a.useEffect(()=>{const p=m.current;p&&(p.allowTouchMove=h&&!S)},[h,S]),a.useEffect(()=>{const p=m.current;!p||p.activeIndex===n||p.slideTo(n,0)},[n]),a.useEffect(()=>E,[E]),a.useEffect(()=>{const p=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),T()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[h,U,T,l]),Jd({onDrag:({movement:[p,i],pinching:O})=>{O||S||Math.abs(i)<Math.abs(p)*1.15&&C===0||(B(!0),Math.abs(i)>8&&(f.current=Date.now()+300),I(Math.max(0,i)))},onDragEnd:({movement:[p,i],velocity:[,O],pinching:j,canceled:q})=>{if(B(!1),j||q||S||Math.abs(i)<Math.abs(p)*1.15){I(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),rf(i,O)){l();return}I(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const D=c.title||c.alt||(c.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:en.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick: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":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx($s,{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":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(Uh,{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":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Gt,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:N,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${C}px, 0) scale(${Math.max(.86,1-C/900)})`,opacity:Math.max(.35,1-C/360),transition:F?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Qd,{onSwiper:p=>{m.current=p,p.allowTouchMove=h&&!S},onSlideChange:p=>{p.activeIndex!==n&&s(p.activeIndex)},onSliderMove:()=>{E(),f.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:t.map((p,i)=>e.jsx(Ci,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:p.kind==="image"?e.jsx(bb,{src:p.src,alt:p.alt||p.title||u("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(Pb,{svg:p.svg,title:p.title||p.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${p.kind}-${i}-${p.alt}`))})})})]})]}),document.body)}function cf({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:c,scrollTop:h,outlineOpen:m,outlineCloseSignal:g,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:S,lightboxCloseSignal:y,onLightboxOpen:C,onLightboxClose:I,onLocalLinkOpen:F}){const{t:B}=Rt(),[E,N]=a.useState(null),[$,T]=a.useState(null),[U,D]=a.useState(1),[p,i]=a.useState(null),O=a.useRef(null),j=a.useRef(null),{blocks:q,images:le}=a.useMemo(()=>nl(t.split(`
|
|
1652
1652
|
`),n,s,k=>{T(null),N(k),C?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:k=>B("rightSidebar.backToFootnote",{index:k})}),[t,n,s,C,B]),ne=a.useMemo(()=>$?[...le,$]:le,[le,$]),ue=a.useCallback(k=>{T({kind:"mermaid",svg:k,alt:"Mermaid diagram",title:"Mermaid diagram"}),N(le.length),C?.()},[le.length,C]);a.useEffect(()=>{N(null),T(null)},[t,n]),a.useEffect(()=>{N(null),T(null)},[y]),a.useEffect(()=>{S||(N(null),T(null))},[S]),a.useEffect(()=>{D(1)},[t,n]),a.useLayoutEffect(()=>{const k=O.current;if(!k||q.length===0)return;const Q=Array.from(k.querySelectorAll("[data-markdown-preview-block-start]"));let ae=1;const Ne=28;for(const je of Q)if(je.offsetTop-h<=Ne)ae=Number(je.dataset.markdownPreviewBlockStart)||ae;else break;D(je=>je===ae?je:ae)},[q,h]);const G=a.useMemo(()=>af(q,U),[U,q]),Y=a.useMemo(()=>of(q),[q]),L=`${n??""}
|
|
1653
|
-
${t}`,_=a.useRef(L),V=a.useRef(null),te=a.useRef(null),oe=a.useRef(!1);a.useEffect(()=>{_.current!==L&&(_.current=L,f?.())},[f,L]),a.useEffect(()=>{g!==void 0&&i(null)},[g]),a.useLayoutEffect(()=>{if(!m){i(null);return}const k=()=>{const Q=j.current;if(!Q)return;const ae=Q.getBoundingClientRect(),Ne=window.innerWidth;i({top:ae.bottom+6,right:Math.max(8,Ne-ae.right)})};return k(),window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},[m,h,G]);const ge=a.useCallback(k=>{const Q=O.current,ae=Q?.closest("[data-markdown-preview-scroller]"),Ne=Q?.querySelector(`[data-markdown-preview-block-start="${k.startLine}"]`);if(!ae||!Ne)return;const je=ae.getBoundingClientRect(),Ke=Ne.getBoundingClientRect(),Ae=Q?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,st=Ke.top-je.top+ae.scrollTop;ae.scrollTo({top:Math.max(0,st-Ae-8),behavior:"smooth"}),D(k.startLine),f?.()},[f]),he=a.useCallback(k=>{k.pointerType==="mouse"&&k.button!==0||vi(k.target)||(V.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY})},[]),$e=a.useCallback((k,Q,ae)=>{const Ne=V.current;if(V.current=null,!Ne||Ne.pointerId!==k.pointerId)return;const je=Math.abs(k.clientX-Ne.startX),Ke=Math.abs(k.clientY-Ne.startY);if(je>8||Ke>8)return;const de=k.target;if(vi(de)||Wi())return;const Ae=Wd(de,Q,ae);u(k,Ae.start,Ae.end)},[u]),M=a.useCallback(k=>{V.current?.pointerId===k.pointerId&&(V.current=null)},[]),J=a.useCallback((k,Q)=>{const ae=O.current;if(!ae||typeof document.elementFromPoint!="function")return null;const Ne=document.elementFromPoint(k,Q);if(!(Ne instanceof HTMLElement)||!ae.contains(Ne))return null;const je=Ne.closest("[data-md-ref-start]");if(je){const we=Number(je.dataset.mdRefStart);if(Number.isFinite(we)&&we>0)return we}const Ke=Ne.closest("[data-markdown-preview-block-start]");if(!Ke)return null;const de=Number(Ke.dataset.markdownPreviewBlockStart),Ae=q.find(we=>we.startLine===de);if(!Ae)return Number.isFinite(de)&&de>0?de:null;if(Ae.endLine<=Ae.startLine)return Ae.startLine;const st=Ke.getBoundingClientRect(),Le=st.height>0?Math.min(1,Math.max(0,(Q-st.top)/st.height)):0;return Math.round(Ae.startLine+Le*(Ae.endLine-Ae.startLine))},[q]),fe=a.useCallback(k=>{if(!c||k.pointerType==="mouse"&&k.button!==0)return;const Q=J(k.clientX+24,k.clientY);if(Q!=null){te.current={pointerId:k.pointerId,anchorLine:Q,moved:!1};try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}}},[c,J]),Re=a.useCallback(k=>{const Q=te.current;if(!Q||Q.pointerId!==k.pointerId||!c)return;const ae=J(k.clientX+16,k.clientY);ae!=null&&(!Q.moved&&ae===Q.anchorLine||(Q.moved=!0,oe.current=!0,c(k,Math.min(Q.anchorLine,ae),Math.max(Q.anchorLine,ae),"move")))},[c,J]),qe=a.useCallback(k=>{const Q=te.current;if(te.current=null,!Q||Q.pointerId!==k.pointerId||!c||!Q.moved)return;const ae=J(k.clientX+16,k.clientY)??Q.anchorLine;c(k,Math.min(Q.anchorLine,ae),Math.max(Q.anchorLine,ae),"end")},[c,J]),Ce=a.useCallback(k=>{te.current?.pointerId===k.pointerId&&(te.current=null)},[]),ce={onPointerDown:fe,onPointerMove:Re,onPointerUp:qe,onPointerCancel:Ce},xe=()=>oe.current?(oe.current=!1,!0):!1;return q.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:k=>{const Q=k.target instanceof Element?k.target.closest("a[href]"):null;if(!Q||!F)return;const ae=Q.getAttribute("href");if(!ae)return;const Ne=Xi(ae,n,s);Ne&&(k.preventDefault(),F(Ne))},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(k=>k.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}),Y.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(Zd,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&en.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:f}),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:p?{top:`${p.top}px`,right:`${p.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:Y.map(k=>{const Q=G[G.length-1]?.startLine===k.startLine;return e.jsxs("button",{type:"button",onClick:()=>ge(k),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] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(k.level-1,4)*12+8}px`},title:k.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"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",k.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:k.text})]},`desktop-${k.id}-${k.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:f,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(Gt,{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:Y.map(k=>{const Q=G[G.length-1]?.startLine===k.startLine;return e.jsxs("button",{type:"button",onClick:()=>ge(k),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] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(k.level-1,4)*12+8}px`},title:k.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"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",k.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:k.text})]},`${k.id}-${k.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(_u.Provider,{value:ue,children:q.map(k=>{const Q=!!(l&&k.startLine<=l.end&&k.endLine>=l.start),ae=!!(l&&l.start<=k.startLine&&l.end>=k.endLine),Ne=k.kind==="table"?!1:k.fineGrained?ae:Q,je=k.kind==="table"&&l?.start===k.startLine&&l.end===k.endLine;let Ke=null;if(k.kind!=="table"&&k.fineGrained&&Q&&!ae&&l){const Le=k.endLine-k.startLine+1,we=Math.max(l.start,k.startLine),at=Math.min(l.end,k.endLine),et=(we-k.startLine)/Le,qt=(at-we+1)/Le;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) * ${et})`,height:`calc((100% - 0.5rem) * ${qt})`}})}const de=typeof k.content=="function"?k.content(l):k.content,Ae=k.startLine===k.endLine?String(k.startLine):`${k.startLine}-${k.endLine}`,st=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:gi(Ne),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:bi(Ne)}),Ke]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:de})]});return k.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":k.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 ${Ne?"bg-primary/10":""}`,title:`Line ${Ae}`,"aria-label":`Line ${Ae}`,children:[k.kind==="table"?e.jsx("button",{type:"button",className:gi(je,"self"),onClick:Le=>{Le.preventDefault(),!xe()&&u(Le,k.startLine,k.endLine)},title:`Reference table lines ${Ae}`,"aria-label":`Reference table lines ${Ae}`,...ce,children:e.jsx("span",{className:bi(je,"self")})}):e.jsxs("span",{className:gi(Ne,"none"),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:bi(Ne,"none")}),Ke]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:he,onPointerUp:Le=>$e(Le,k.startLine,k.endLine),onPointerCancel:M,onKeyDown:Le=>{Le.key!=="Enter"&&Le.key!==" "||(Le.preventDefault(),u(Le,k.startLine,k.endLine))},title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:de})]},k.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":k.startLine,onClick:Le=>{const we=Le.target;if(vi(we)||Wi()||xe())return;const at=Wd(we,k.startLine,k.endLine);u(Le,at.start,at.end)},onKeyDown:Le=>{Le.key!=="Enter"&&Le.key!==" "||(Le.preventDefault(),u(Le,k.startLine,k.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 ${Ne?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:st},k.key)})})})]}),S&&E!==null&&ne[E]&&e.jsx(lf,{images:ne,index:E,onChange:N,onClose:()=>{N(null),T(null),I?.()}})]})}function Yn({label:t,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:c,disabled:h,onChange:m}){const{t:g}=Rt(),[b,f]=a.useState(!1),[S,y]=a.useState(""),[C,I]=a.useState(null),F=a.useRef(null),B=a.useRef(null),E=S.trim().toLowerCase(),N=a.useMemo(()=>E?s.filter(p=>`${p.label} ${p.meta??""}`.toLowerCase().includes(E)):s,[E,s]),$=s.find(p=>p.value===n),T=()=>{const p=S.trim();p&&(m(p),f(!1),y(""))},U=a.useCallback(()=>{const p=F.current?.getBoundingClientRect();if(!p)return!1;const i=12,O=Math.max(220,Math.min(p.width,window.innerWidth-i*2)),j=Math.min(Math.max(i,p.left),window.innerWidth-O-i),q=window.innerHeight-p.bottom-i,le=p.top-i,ne=q>=180||q>=le,ue=Math.max(96,(ne?q:le)-4),G=Math.min(320,ue);return I({left:j,top:ne?p.bottom+4:Math.max(i,p.top-G-4),width:O,maxHeight:G}),!0},[]),D=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let p=0;const i=()=>{p||(p=window.requestAnimationFrame(()=>{p=0,U()}))},O=j=>{const q=j.target;q instanceof Node&&(F.current?.contains(q)||B.current?.contains(q)||(f(!1),y("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{p&&window.cancelAnimationFrame(p),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:F,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),b){f(!1);return}D()}},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:t}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:$?.label??(n||l)})]}),e.jsx(Ls,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&en.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:p=>p.stopPropagation(),style:{left:C?.left??12,top:C?.top??12,width:C?.width??260,maxHeight:C?.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(Jn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:S,onChange:p=>y(p.target.value),onKeyDown:p=>{if(p.key==="Escape"){p.preventDefault(),f(!1),y("");return}p.key==="Enter"&&(p.preventDefault(),T())},onBlur:()=>{S.trim()&&N.length===0&&T()},placeholder:u,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,(C?.maxHeight??320)-46)},children:[S.trim()&&!s.some(p=>p.value===S.trim())&&e.jsxs("button",{type:"button",onMouseDown:p=>p.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:S.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),N.length>0?N.map(p=>e.jsxs("button",{type:"button",onClick:()=>{m(p.value),f(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${p.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:p.label}),p.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:p.meta})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function _d({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:c,onToggleRepo:h,onGenerate:m,onSecondaryAction:g,disabled:b,generateDisabled:f,secondaryDisabled:S,inserted:y,buttonLabel:C,insertedLabel:I,title:F,ariaLabel:B,scopeTitle:E,scopeLabel:N,allLabel:$,generateLabel:T,secondaryLabel:U,secondaryTitle:D,secondaryLoading:p,loading:i,error:O,statusTitle:j,extraContent:q,renderRepoExtra:le}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):f||m()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:j??(s?`${E}: ${N}`:F),children:[i?e.jsx(jt,{size:13,className:"animate-spin"}):e.jsx(Ps,{size:13}),e.jsx("span",{children:y?I:C}),s&&e.jsx(Ls,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&en.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:ne=>ne.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:E}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:N})]}),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(Gt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[q,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:$}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(ne=>{const ue=c.includes(ne.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${ue?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(ne.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${ue?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:ne.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:ne.label}),ne.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:ne.branch})]}),ue&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),le&&(l||ue)&&e.jsx("div",{className:"px-2 pb-2",children:le(ne)})]},ne.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{S||(n(!1),g())},disabled:S,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[p?e.jsx(jt,{size:12,className:"animate-spin"}):e.jsx(lu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),m())},disabled:f,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(Ps,{size:12}),T]})]})]})}),document.body)]})}function xb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function df(){return ot(Ki,xb)??{}}function vb(t,n){const s=df(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,c])=>c.updatedAt-u.updatedAt).slice(0,mg);Cs(Ki,Object.fromEntries(l),gg)}function yb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function wb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!yb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function nl(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function uf(){return ot(Vi,wb)??{}}function Fd(t,n){const s=nl(t,n);return s?uf()[s]??null:null}function hi(t,n,s){const l=nl(t,n);if(!l)return;const u=uf(),c=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,m],[,g])=>g.updatedAt-m.updatedAt).slice(0,pg);Cs(Vi,Object.fromEntries(h),bg)}function Ua({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function mi({slow:t}){return e.jsx(jm,{slow:t})}function Ha({message:t,onRetry:n}){const{t:s}=Rt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function Ka(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function xt(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function pi(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function zi(t,n,s){const l=Math.min(n,s),u=Math.max(n,s);return t?.start===l&&t.end===u?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,u)}:{start:l,end:u}}function kb(t,n,s){return zi(t,n,s)}function gi(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function bi(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function Bd(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function ff(t){const n=new Map;for(const s of t)n.set(sl(s),s);return n}function hf(t,n){const s=new Map(t);for(const l of n)s.set(sl(l),l);return s}function Od(t,n){let s=0;for(const l of t){const u=ht(l,n);u&&n&&u!==n&&(s+=1)}return s}function Sb(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function jb(t,n){return Array.from(hf(ff(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Rb(t,n){const s=t.relativeRoot==="."?xt(n??t.root)||t.name||t.root:t.relativeRoot||t.name||xt(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:Sb(t.files)}}function mf(t,n){const s=xt(n??"")||n||"";return t.map(l=>Rb(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function pf(t,n,s,l,u){const c=$u(s),h=c.find(F=>F.root===l)??c[0]??null,m=n.find(F=>F.root===l)??null,g=m?.relativeRoot??h?.relativeRoot??".",b=m?.name??h?.name??(xt(l)||l),f=(h?.files??s.files).map(F=>({...F,repoRoot:l,repoRelativeRoot:g,repoName:b})),S=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:g,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:g,name:b,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,files:f,context:S?{...S,root:l,changedFiles:f.map(F=>({path:F.path,absolutePath:F.absolutePath,status:F.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},C=m?n.map(F=>F.root===l?y:F):[...n,y];return{files:Array.from(t).filter(F=>ht(F,u)!==l).concat(f),repositories:C,repoFilters:mf(C,u)}}function ht(t,n){return t.repoRoot??n}function sl(t){return`${t.repoRoot??""}\0${t.path}`}function bt(t){return t.absolutePath||t.path}function xi(t){return sl(t)}function Cb(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function Ud(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function Hd(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Xn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function Ss(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ar(t){return t instanceof DOMException&&t.name==="AbortError"}function Nb(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function zd(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function Wi(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function vi(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Wd(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(c)&&c>0?{start:Math.min(u,c),end:Math.max(u,c)}:{start:n,end:s}}function Mb({actions:t,running:n,completed:s}){const{t:l}=Rt(),[u,c]=a.useState(!1),h=a.useRef(null),m=t.find(b=>n?.action===b.key),g=t.find(b=>s?.action===b.key);return t.length===0?null:(a.useEffect(()=>{if(!u)return;const b=S=>{const y=S.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=S=>{S.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),c(f=>!f)},disabled:t.every(b=>b.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 ${u?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??g?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(jt,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(Si,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(b=>{const f=n?.action===b.key,S=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),b.onClick(),c(!1)},disabled:b.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 ${S?"bg-accent/10 text-accent":b.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:f?e.jsx(jt,{size:13,className:"animate-spin"}):S?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Eb(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function gf(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Eb(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Qn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const yi=new WeakMap;function to(t){const n=yi.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),yi.delete(t)},1700);yi.set(t,s)}function $b(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const m of l){if(!Qn(m))continue;const g=m.querySelector(s);if(g&&Qn(g)){u=g;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Qn)??null,!u)return;const c=gf(u);if(!c){u.scrollIntoView({block:"start",behavior:"smooth"}),to(u);return}const h=u.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),to(u)}function kn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,u=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,c=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`: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(I=>!!I),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const I of m)if(Qn(I)){for(const F of h){const B=I.querySelector(F);if(B&&Qn(B)){g=B;break}}if(g)break}if(g??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Qn)??null,!g){$b(t.filePath);return}const b=gf(g);if(!b){g.scrollIntoView({block:"center",behavior:"smooth"}),to(g);return}const f=g.getBoundingClientRect(),S=b.getBoundingClientRect(),C=f.top-S.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,C),behavior:"instant"}),to(g)}const bf=1,xf=8;function Lb(t){return Math.min(xf,Math.max(bf,t))}function vf({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[c,h]=a.useState({scale:1,x:0,y:0}),[m,g]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),S=a.useRef(!1),y=a.useRef(null),C=a.useRef(0),I=a.useRef(c);I.current=c,a.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const F=a.useCallback(($,T,U)=>{const D=u.current;if(!D)return{x:T,y:U};const p=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,i=p?.clientWidth||D.clientWidth,O=p?.clientHeight||D.clientHeight,j=Math.max(0,(i*$-D.clientWidth)/2),q=Math.max(0,(O*$-D.clientHeight)/2);return{x:Math.min(j,Math.max(-j,T)),y:Math.min(q,Math.max(-q,U))}},[]),B=a.useCallback(($,T,U)=>{h(D=>{const p=Lb($),i=u.current;if(!i||p===1)return{scale:p,x:0,y:0};const O=i.getBoundingClientRect(),j=(T??O.left+O.width/2)-O.left-O.width/2,q=(U??O.top+O.height/2)-O.top-O.height/2,le=p/D.scale,ne=j-(j-D.x)*le,ue=q-(q-D.y)*le;return{scale:p,...F(p,ne,ue)}})},[F]),E=a.useCallback(($,T)=>{g(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,$,T),window.setTimeout(()=>g(!1),220)},[B]);a.useEffect(()=>{const $=u.current;if(!$)return;const T=p=>{if(p.pointerType==="mouse"&&p.button!==0)return;const i=f.current.size===0;if(f.current.add(p.pointerId),i){const O=Date.now(),j=y.current;if(j&&O-j.time<350&&Math.hypot(p.clientX-j.x,p.clientY-j.y)<24){y.current=null,C.current=O,s?.(),E(p.clientX,p.clientY);return}}if(f.current.size>1){S.current=!0,b.current=null;return}if(!(I.current.scale<=1)){p.preventDefault(),b.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{$.setPointerCapture?.(p.pointerId)}catch{}g(!1)}},U=p=>{const i=b.current;if(!i||i.pointerId!==p.pointerId)return;const O=p.clientX-i.startX,j=p.clientY-i.startY;if(!i.moved){if(Math.hypot(O,j)<6)return;i.moved=!0}p.stopPropagation(),p.preventDefault(),h(q=>({...q,...F(q.scale,i.originX+O,i.originY+j)}))},D=p=>{const i=b.current,O=i?.pointerId===p.pointerId&&i.moved;if(i?.pointerId===p.pointerId){i.moved&&p.stopPropagation(),b.current=null;try{$.releasePointerCapture?.(p.pointerId)}catch{}}f.current.delete(p.pointerId)&&f.current.size===0&&(!S.current&&!O&&(y.current={time:Date.now(),x:p.clientX,y:p.clientY}),S.current=!1)};return $.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{$.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[F,s,E]),Jd({onPinch:({offset:[$],origin:[T,U]})=>{g(!1),B($,T,U)},onWheel:({event:$,delta:[T,U],ctrlKey:D})=>{if(D){$.preventDefault(),$.stopPropagation(),g(!1),B(I.current.scale*(1-U*.01),$.clientX,$.clientY);return}I.current.scale<=1||($.preventDefault(),$.stopPropagation(),g(!1),h(p=>({...p,...F(p.scale,p.x-T,p.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:bf,max:xf},from:()=>[I.current.scale,0],rubberband:!0}});const N=c.scale>1;return a.useEffect(()=>{n?.(N)},[n,N]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":N?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:N?"grab":"zoom-in"},onDoubleClick:$=>{$.stopPropagation(),!(Date.now()-C.current<500)&&(s?.(),E($.clientX,$.clientY))},children:l({scale:c.scale,zoomed:N,animateTransform:m,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:m?"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:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function yf({src:t,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:c,onDoubleTap:h}){const m=ro(t,u),[g,b]=a.useState(null),f=s??so(t);return a.useEffect(()=>{b(null)},[t]),e.jsx(vf,{resetKey:t,onZoomChange:c,onDoubleTap:h,children:({transformStyle:S,vectorTransformStyle:y,scale:C,animateTransform:I})=>{const F=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*C,height:g.height*C,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"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"}:g?{...S,width:g.width,height:g.height}:f?y:S,onLoad:B=>{const E=B.currentTarget,N=E.parentElement;if(N&&E.naturalWidth>0&&E.naturalHeight>0){const $=Math.max(1,N.clientWidth-2),T=Math.max(1,N.clientHeight-2),U=Math.min($/E.naturalWidth,T/E.naturalHeight),D=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(E.naturalWidth*D)),height:Math.max(1,Math.round(E.naturalHeight*D))})}l(B)},onError:u});return!f||!g?F:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:F})}})}function Ab({svg:t,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const c=u.current,h=c?.querySelector("svg");if(!c||!h)return;const m=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let S=f[2],y=f[3];if((!Number.isFinite(S)||!Number.isFinite(y)||S<=0||y<=0)&&(S=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(S)||!Number.isFinite(y)||S<=0||y<=0)return;const C=Math.max(1,c.clientWidth-24),I=Math.max(1,c.clientHeight-24),F=Math.min(C/S,I/y,1);h.style.width=`${Math.max(1,Math.floor(S*F*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*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")};m();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return g?.observe(c),()=>g?.disconnect()},[s,t,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function Pb({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(vf,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:c})=>e.jsx(Ab,{svg:t,title:n,scale:c,vectorTransformStyle:u})})}let Tb=0,Ib=0,Db=0,_b=0,Fb=0;function wi(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function nt(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++Ib,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function za(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++_b,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Bb(){return`diff-ui-${Date.now().toString(36)}-${(++Fb).toString(36)}`}function Ob(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function Ub(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Gi({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:m,isMobile:g,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:S,onCloseMarkdownOutline:y,markdownImageLightboxOpen:C,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:N,insertedReferenceKey:$,copiedReferenceKey:T,scrollToLine:U,onScrollToLineHandled:D}){const{t:p}=Rt(),i=Z(A=>A.rootPath),O=Z(A=>A.selectFile),[j,q]=a.useState({kind:"idle"}),[le,ne]=a.useState("schematic"),[ue,G]=a.useState(null),Y=a.useRef(null),[L,_]=a.useState(null),V=a.useRef(new Map),te=a.useRef(null),[oe,ge]=a.useState(null),[he,$e]=a.useState(()=>Rd()),[M,J]=a.useState(()=>fd(i,n)),fe=a.useRef(null),[Re,qe]=a.useState(!1),[Ce,ce]=a.useState(null),[xe,k]=a.useState(0),[Q,ae]=a.useState([]),[Ne,je]=a.useState(null),Ke=a.useRef(null),de=a.useRef(n),[Ae,st]=a.useState(null),[Le,we]=a.useState({status:"idle"}),[at,et]=a.useState(!1),[qt,lt]=a.useState(""),[ct,Pr]=a.useState([]),[Dt,z]=a.useState(0),re=a.useRef(null),be=iu(c),ze=nl(i,n);a.useEffect(()=>{if(de.current===n)return;de.current=n;const A=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(Ke.current===A){Ke.current=null;return}Ke.current=null,ae([]),je(null),et(!1),lt("")},[n,i]);const ut=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,dr=Z(A=>ut?(A.fileChangeVersions.get(ut)??0)+A.fileWatchEpoch:A.fileWatchEpoch),ur=a.useRef(null),_t=a.useRef(null),[fr,hr]=a.useState(0),Sn=a.useCallback(()=>hr(A=>A+1),[]);a.useEffect(()=>{const A=Y.current;return Y.current=null,G(null),A&&URL.revokeObjectURL(A.objectUrl),()=>{const W=Y.current;Y.current=null,W&&URL.revokeObjectURL(W.objectUrl)}},[ut,dr,fr]),a.useEffect(()=>{if(!n){ur.current=null,q({kind:"idle"});return}const A=i&&!n.startsWith("/")?`${i}/${n}`:n,W=new AbortController,se=++Tb,ke=`right-sidebar-file-preview:${se}`,Ue=performance.now();let Te=!1;const Be=(X,He={})=>{Te||(Te=!0,wi("end",{loadingId:se,reason:X,durationMs:Math.round(performance.now()-Ue),filePath:n,fullPath:A,rootPath:i,...He}))};let We=null;const tt=Eh(A),Nt=tt?A.toLowerCase().endsWith(".kicad_pcb")?le==="schematic"?"pcb-front":le:"schematic":le,nr=!tt&&qi(A),Vt=!tt&&!nr&&$h(A),Mn=!tt&&!nr&&!Vt&&Kd(A),as=ks(A),sn=ys(A),Or=tt?"eda":nr?"image":Vt?"model3d":Mn?"video":"text",Sr=ur.current!==A;if(ur.current=A,Sr){wi("start",{loadingId:se,filePath:n,fullPath:A,rootPath:i,mode:Or,externalVersion:dr}),we({status:"idle"}),q({kind:"loading",mode:Or}),_t.current=null;const X=Fd(i,n);N(X?.lineRange??null),$e(as?Rd():"source"),J(sn?fd(i,n):"source"),tt&&ne(Lh(A))}Sr||q(X=>X.kind==="error"?{kind:"loading",mode:Or}:X);const io=window.setTimeout(()=>{Te||W.signal.aborted||wi("still_active",{loadingId:se,filePath:n,fullPath:A,rootPath:i,mode:Or,durationMs:Math.round(performance.now()-Ue),isPathChange:Sr})},3e3),an=window.setTimeout(()=>{if(Te||W.signal.aborted)return;const X=tt?p("rightSidebar.edaTimeout"):Vt?p("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";W.abort(new DOMException(X,"TimeoutError")),q({kind:"error",message:X}),Be("stuck_timeout",{error:X})},tt?Ah+5e3:Vt?Ph+5e3:Th(A)?35e3:Sg);if(tt){const X=Nt==="pcb-3d"?Y.current:null;X?(q(X),Be("eda_3d_client_cache_hit",{bytes:X.meta.size,view:X.view,mimeType:X.meta.mimeType})):Ih(A,Nt,W.signal,"view_file",ke).then(He=>{if(W.signal.aborted)return;We=URL.createObjectURL(He.blob);const Pt={kind:"eda",sourcePath:He.path||A,objectUrl:We,view:He.view,meta:{size:He.size,mimeType:He.mimeType,modified:He.modified}};if(He.view==="pcb-3d"){const Ur=Y.current;Ur&&Ur.objectUrl!==We&&URL.revokeObjectURL(Ur.objectUrl),Y.current=Pt,G(Pt),We=null}q(Pt),Be("eda_loaded",{bytes:He.size,view:He.view,mimeType:He.mimeType})}).catch(He=>{W.signal.aborted||(q({kind:"error",message:He instanceof Error&&/timed out/i.test(He.message)?p("rightSidebar.edaTimeout"):He instanceof Error?He.message:p("rightSidebar.edaLoadFailed")}),Be("error",{error:He instanceof Error?He.message:String(He)}))})}else if(nr)Dh(A,W.signal,"view_file",ke).then(X=>{We=URL.createObjectURL(X.blob),q({kind:"image",objectUrl:We,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Be("image_loaded",{bytes:X.size,mimeType:X.mimeType})}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error?X.message:p("rightSidebar.imageLoadFailed")}),Be("error",{error:X instanceof Error?X.message:String(X)}))});else if(Vt)_h(A,W.signal,"view_file",ke).then(X=>{W.signal.aborted||(We=URL.createObjectURL(X.blob),q({kind:"model3d",sourcePath:X.path||A,objectUrl:We,ext:X.ext,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Be("model3d_loaded",{bytes:X.size,ext:X.ext}))}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error&&(X.name==="TimeoutError"||/timed out/i.test(X.message))?p("rightSidebar.model3dTimeout"):X instanceof Error?X.message:p("rightSidebar.model3dLoadFailed")}),Be("error",{error:X instanceof Error?X.message:String(X)}))});else if(Mn){const X=Fh(A)??"",He=Vd(A);q(Pt=>Pt.kind==="video"&&Pt.url===He?Pt:{kind:"video",url:He,meta:{size:null,mimeType:X,modified:null}}),Be("video_ready",{mimeType:X})}else Kc(A,W.signal,"view_file",ke).then(X=>{if(!W.signal.aborted){if(X.binary){q({kind:"binary"});return}q({kind:"text",content:X.content,sourcePath:X.path||A,meta:{size:X.size,truncated:X.truncated}}),Be("text_loaded",{bytes:X.size,truncated:!!X.truncated})}}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error?X.message:"Failed to read file"}),Be("error",{error:X instanceof Error?X.message:String(X)}))});return()=>{W.abort(),kt(ke),window.clearTimeout(io),window.clearTimeout(an),We&&URL.revokeObjectURL(We),Be("cleanup")}},[n,i,dr,fr,N,p,le]),a.useEffect(()=>{if(j.kind!=="model3d"||!n){_(null);return}let A=!1;const W=n.lastIndexOf("/"),se=W>=0?n.slice(W+1):n,ke=W>=0?n.slice(0,W):"",Ue=ke.lastIndexOf("/"),Te=Ue>=0?ke.slice(0,Ue):"",Be=se.replace(/\.(stl|glb|gltf)$/i,""),We=`${Te?`${Te}/`:""}features/${Be}.json`;return Kc(We).then(tt=>{if(!A)try{const Nt=JSON.parse(tt.content);_(Nt.version===1&&Array.isArray(Nt.features)&&Nt.features.length>0?Nt.features:null)}catch{_(null)}}).catch(()=>{A||_(null)}),()=>{A=!0}},[j,n]),a.useEffect(()=>{if(j.kind!=="text"){st(null);return}const A=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,W=nu(A),se=j.content,ke=ks(A??"")&&he==="preview",Ue=ys(A??"")&&M==="preview";if(!W||ke||Ue||!su(se)){st(null);return}let Te=!1;const Be=We=>{if(Te||!We.registered(W)){Te||st(null);return}try{st(ou(We,se,W))}catch{st(null)}};return Ce?Be(Ce):(st(null),au().then(We=>{Te||(ce(We),Be(We))}).catch(()=>{})),()=>{Te=!0}},[j,Ce,n,i,he,M]),a.useLayoutEffect(()=>{if(!ze||j.kind!=="text")return;const A=`${ze}:${he}:${M}`;if(_t.current===A)return;const W=Fd(i,n);if(_t.current=A,!W)return;const se=requestAnimationFrame(()=>{const ke=te.current;if(!ke)return;const Ue=he==="preview"?W.markdownTop??W.top:W.top;ke.scrollTo({top:Math.max(0,Ue??0),left:Math.max(0,W.left??0)}),k(he==="preview"?Math.max(0,Ue??0):0)});return()=>cancelAnimationFrame(se)},[n,he,M,j.kind,ze,i]),a.useEffect(()=>{ze&&hi(i,n,{lineRange:E})},[n,E,ze,i]),a.useEffect(()=>{if(U==null||j.kind!=="text")return;ge(null),N({start:U,end:U});const A=U,W=requestAnimationFrame(()=>{const se=V.current.get(A);se&&se.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(W)},[U,j,N,D]);const jn=a.useCallback(A=>{const W=te.current;if(!W)return!1;const se=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(A):A.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ke=W.querySelector(`#${se}`);return ke?(ke.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const A=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,W=j.kind==="text"&&ks(A??"")&&he==="preview";if(!Ne||!W)return;const se=requestAnimationFrame(()=>{jn(Ne)&&je(null)});return()=>cancelAnimationFrame(se)},[n,jn,he,Ne,j,i]),a.useLayoutEffect(()=>{const A=te.current;if(!A||!E){ge(null);return}if(oe)return;const W=j.kind==="image"||j.kind==="loading"&&j.mode==="image",se=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,ke=j.kind==="text"&&ks(se??"")&&he==="preview",Ue=j.kind==="text"&&ys(se??"")&&M==="preview";if(j.kind!=="text"||W||ke||Ue){ge(null);return}const Te=()=>{const We=V.current.get(E.end);if(!We||!A){ge(null);return}const tt=We.offsetTop+We.offsetHeight/2,Nt=A.scrollLeft+Math.max(8,A.clientWidth-120);ge({top:tt,left:Nt})};Te();const Be=new ResizeObserver(()=>Te());return Be.observe(A),()=>Be.disconnect()},[E,oe,j,he,M,n,i,Ae]);const Tr=j.kind==="text"&&!(ys(ut??"")&&M==="preview")&&!ut?.toLowerCase().endsWith(".csv")&&!ut?.toLowerCase().endsWith(".kicad_pro")&&!ut?.toLowerCase().endsWith(".kicad_prl"),mr=a.useCallback(()=>{et(!1),lt(""),Pr([]),z(0),Da()},[]),Rn=a.useCallback(()=>{Tr&&(et(!0),requestAnimationFrame(()=>{re.current?.focus(),re.current?.select()}))},[Tr]),mt=a.useCallback(A=>{z(W=>ct.length===0?0:(W+A+ct.length)%ct.length)},[ct.length]);if(a.useEffect(()=>{const A=W=>{const se=og(W);if(se==="open"&&Tr){W.preventDefault(),Rn();return}at&&(se==="close"?(W.preventDefault(),mr()):(se==="next"||se==="previous")&&(W.preventDefault(),mt(se==="previous"?-1:1)))};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[mr,at,mt,Rn,Tr]),a.useLayoutEffect(()=>{if(Da(),!at||!qt.trim()||!te.current){Pr([]),z(0);return}const A=lg(te.current,qt);return Pr(A),z(0),gd(A,0),bd(A[0]),Da},[at,qt,Ae,he,j]),a.useEffect(()=>{at&&(gd(ct,Dt),bd(ct[Dt]))},[Dt,ct,at]),a.useEffect(()=>Da,[]),!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:p("rightSidebar.selectFilePrompt")});const Oe=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=Ka(Oe,i),pr=Yd(Oe,i),gr=j.kind==="text"&&j.content?j.content.split(`
|
|
1653
|
+
${t}`,_=a.useRef(L),V=a.useRef(null),te=a.useRef(null),oe=a.useRef(!1);a.useEffect(()=>{_.current!==L&&(_.current=L,f?.())},[f,L]),a.useEffect(()=>{g!==void 0&&i(null)},[g]),a.useLayoutEffect(()=>{if(!m){i(null);return}const k=()=>{const Q=j.current;if(!Q)return;const ae=Q.getBoundingClientRect(),Ne=window.innerWidth;i({top:ae.bottom+6,right:Math.max(8,Ne-ae.right)})};return k(),window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},[m,h,G]);const ge=a.useCallback(k=>{const Q=O.current,ae=Q?.closest("[data-markdown-preview-scroller]"),Ne=Q?.querySelector(`[data-markdown-preview-block-start="${k.startLine}"]`);if(!ae||!Ne)return;const je=ae.getBoundingClientRect(),Ke=Ne.getBoundingClientRect(),Ae=Q?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,st=Ke.top-je.top+ae.scrollTop;ae.scrollTo({top:Math.max(0,st-Ae-8),behavior:"smooth"}),D(k.startLine),f?.()},[f]),he=a.useCallback(k=>{k.pointerType==="mouse"&&k.button!==0||vi(k.target)||(V.current={pointerId:k.pointerId,startX:k.clientX,startY:k.clientY})},[]),$e=a.useCallback((k,Q,ae)=>{const Ne=V.current;if(V.current=null,!Ne||Ne.pointerId!==k.pointerId)return;const je=Math.abs(k.clientX-Ne.startX),Ke=Math.abs(k.clientY-Ne.startY);if(je>8||Ke>8)return;const de=k.target;if(vi(de)||Gi())return;const Ae=Gd(de,Q,ae);u(k,Ae.start,Ae.end)},[u]),M=a.useCallback(k=>{V.current?.pointerId===k.pointerId&&(V.current=null)},[]),J=a.useCallback((k,Q)=>{const ae=O.current;if(!ae||typeof document.elementFromPoint!="function")return null;const Ne=document.elementFromPoint(k,Q);if(!(Ne instanceof HTMLElement)||!ae.contains(Ne))return null;const je=Ne.closest("[data-md-ref-start]");if(je){const we=Number(je.dataset.mdRefStart);if(Number.isFinite(we)&&we>0)return we}const Ke=Ne.closest("[data-markdown-preview-block-start]");if(!Ke)return null;const de=Number(Ke.dataset.markdownPreviewBlockStart),Ae=q.find(we=>we.startLine===de);if(!Ae)return Number.isFinite(de)&&de>0?de:null;if(Ae.endLine<=Ae.startLine)return Ae.startLine;const st=Ke.getBoundingClientRect(),Le=st.height>0?Math.min(1,Math.max(0,(Q-st.top)/st.height)):0;return Math.round(Ae.startLine+Le*(Ae.endLine-Ae.startLine))},[q]),fe=a.useCallback(k=>{if(!c||k.pointerType==="mouse"&&k.button!==0)return;const Q=J(k.clientX+24,k.clientY);if(Q!=null){te.current={pointerId:k.pointerId,anchorLine:Q,moved:!1};try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}}},[c,J]),Re=a.useCallback(k=>{const Q=te.current;if(!Q||Q.pointerId!==k.pointerId||!c)return;const ae=J(k.clientX+16,k.clientY);ae!=null&&(!Q.moved&&ae===Q.anchorLine||(Q.moved=!0,oe.current=!0,c(k,Math.min(Q.anchorLine,ae),Math.max(Q.anchorLine,ae),"move")))},[c,J]),qe=a.useCallback(k=>{const Q=te.current;if(te.current=null,!Q||Q.pointerId!==k.pointerId||!c||!Q.moved)return;const ae=J(k.clientX+16,k.clientY)??Q.anchorLine;c(k,Math.min(Q.anchorLine,ae),Math.max(Q.anchorLine,ae),"end")},[c,J]),Ce=a.useCallback(k=>{te.current?.pointerId===k.pointerId&&(te.current=null)},[]),ce={onPointerDown:fe,onPointerMove:Re,onPointerUp:qe,onPointerCancel:Ce},xe=()=>oe.current?(oe.current=!1,!0):!1;return q.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:k=>{const Q=k.target instanceof Element?k.target.closest("a[href]"):null;if(!Q||!F)return;const ae=Q.getAttribute("href");if(!ae)return;const Ne=Ji(ae,n,s);Ne&&(k.preventDefault(),F(Ne))},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(k=>k.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}),Y.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(Zd,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&en.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:f}),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:p?{top:`${p.top}px`,right:`${p.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:Y.map(k=>{const Q=G[G.length-1]?.startLine===k.startLine;return e.jsxs("button",{type:"button",onClick:()=>ge(k),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] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(k.level-1,4)*12+8}px`},title:k.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"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",k.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:k.text})]},`desktop-${k.id}-${k.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:f,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(Gt,{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:Y.map(k=>{const Q=G[G.length-1]?.startLine===k.startLine;return e.jsxs("button",{type:"button",onClick:()=>ge(k),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] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(k.level-1,4)*12+8}px`},title:k.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"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",k.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:k.text})]},`${k.id}-${k.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(_u.Provider,{value:ue,children:q.map(k=>{const Q=!!(l&&k.startLine<=l.end&&k.endLine>=l.start),ae=!!(l&&l.start<=k.startLine&&l.end>=k.endLine),Ne=k.kind==="table"?!1:k.fineGrained?ae:Q,je=k.kind==="table"&&l?.start===k.startLine&&l.end===k.endLine;let Ke=null;if(k.kind!=="table"&&k.fineGrained&&Q&&!ae&&l){const Le=k.endLine-k.startLine+1,we=Math.max(l.start,k.startLine),at=Math.min(l.end,k.endLine),et=(we-k.startLine)/Le,qt=(at-we+1)/Le;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) * ${et})`,height:`calc((100% - 0.5rem) * ${qt})`}})}const de=typeof k.content=="function"?k.content(l):k.content,Ae=k.startLine===k.endLine?String(k.startLine):`${k.startLine}-${k.endLine}`,st=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:gi(Ne),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:bi(Ne)}),Ke]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:de})]});return k.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":k.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 ${Ne?"bg-primary/10":""}`,title:`Line ${Ae}`,"aria-label":`Line ${Ae}`,children:[k.kind==="table"?e.jsx("button",{type:"button",className:gi(je,"self"),onClick:Le=>{Le.preventDefault(),!xe()&&u(Le,k.startLine,k.endLine)},title:`Reference table lines ${Ae}`,"aria-label":`Reference table lines ${Ae}`,...ce,children:e.jsx("span",{className:bi(je,"self")})}):e.jsxs("span",{className:gi(Ne,"none"),"aria-hidden":"true",...ce,children:[e.jsx("span",{className:bi(Ne,"none")}),Ke]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:he,onPointerUp:Le=>$e(Le,k.startLine,k.endLine),onPointerCancel:M,onKeyDown:Le=>{Le.key!=="Enter"&&Le.key!==" "||(Le.preventDefault(),u(Le,k.startLine,k.endLine))},title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:de})]},k.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":k.startLine,onClick:Le=>{const we=Le.target;if(vi(we)||Gi()||xe())return;const at=Gd(we,k.startLine,k.endLine);u(Le,at.start,at.end)},onKeyDown:Le=>{Le.key!=="Enter"&&Le.key!==" "||(Le.preventDefault(),u(Le,k.startLine,k.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 ${Ne?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:st},k.key)})})})]}),S&&E!==null&&ne[E]&&e.jsx(lf,{images:ne,index:E,onChange:N,onClose:()=>{N(null),T(null),I?.()}})]})}function Yn({label:t,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:c,disabled:h,onChange:m}){const{t:g}=Rt(),[b,f]=a.useState(!1),[S,y]=a.useState(""),[C,I]=a.useState(null),F=a.useRef(null),B=a.useRef(null),E=S.trim().toLowerCase(),N=a.useMemo(()=>E?s.filter(p=>`${p.label} ${p.meta??""}`.toLowerCase().includes(E)):s,[E,s]),$=s.find(p=>p.value===n),T=()=>{const p=S.trim();p&&(m(p),f(!1),y(""))},U=a.useCallback(()=>{const p=F.current?.getBoundingClientRect();if(!p)return!1;const i=12,O=Math.max(220,Math.min(p.width,window.innerWidth-i*2)),j=Math.min(Math.max(i,p.left),window.innerWidth-O-i),q=window.innerHeight-p.bottom-i,le=p.top-i,ne=q>=180||q>=le,ue=Math.max(96,(ne?q:le)-4),G=Math.min(320,ue);return I({left:j,top:ne?p.bottom+4:Math.max(i,p.top-G-4),width:O,maxHeight:G}),!0},[]),D=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let p=0;const i=()=>{p||(p=window.requestAnimationFrame(()=>{p=0,U()}))},O=j=>{const q=j.target;q instanceof Node&&(F.current?.contains(q)||B.current?.contains(q)||(f(!1),y("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{p&&window.cancelAnimationFrame(p),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:F,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),b){f(!1);return}D()}},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:t}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:$?.label??(n||l)})]}),e.jsx(Ls,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&en.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:p=>p.stopPropagation(),style:{left:C?.left??12,top:C?.top??12,width:C?.width??260,maxHeight:C?.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(Jn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:S,onChange:p=>y(p.target.value),onKeyDown:p=>{if(p.key==="Escape"){p.preventDefault(),f(!1),y("");return}p.key==="Enter"&&(p.preventDefault(),T())},onBlur:()=>{S.trim()&&N.length===0&&T()},placeholder:u,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,(C?.maxHeight??320)-46)},children:[S.trim()&&!s.some(p=>p.value===S.trim())&&e.jsxs("button",{type:"button",onMouseDown:p=>p.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:S.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),N.length>0?N.map(p=>e.jsxs("button",{type:"button",onClick:()=>{m(p.value),f(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${p.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:p.label}),p.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:p.meta})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function Fd({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:c,onToggleRepo:h,onGenerate:m,onSecondaryAction:g,disabled:b,generateDisabled:f,secondaryDisabled:S,inserted:y,buttonLabel:C,insertedLabel:I,title:F,ariaLabel:B,scopeTitle:E,scopeLabel:N,allLabel:$,generateLabel:T,secondaryLabel:U,secondaryTitle:D,secondaryLoading:p,loading:i,error:O,statusTitle:j,extraContent:q,renderRepoExtra:le}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):f||m()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:j??(s?`${E}: ${N}`:F),children:[i?e.jsx(jt,{size:13,className:"animate-spin"}):e.jsx(Ps,{size:13}),e.jsx("span",{children:y?I:C}),s&&e.jsx(Ls,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&en.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:ne=>ne.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:E}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:N})]}),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(Gt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[q,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:$}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(ne=>{const ue=c.includes(ne.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${ue?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(ne.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${ue?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:ne.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:ne.label}),ne.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:ne.branch})]}),ue&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),le&&(l||ue)&&e.jsx("div",{className:"px-2 pb-2",children:le(ne)})]},ne.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{S||(n(!1),g())},disabled:S,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[p?e.jsx(jt,{size:12,className:"animate-spin"}):e.jsx(lu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),m())},disabled:f,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(Ps,{size:12}),T]})]})]})}),document.body)]})}function xb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function df(){return ot(Vi,xb)??{}}function vb(t,n){const s=df(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,c])=>c.updatedAt-u.updatedAt).slice(0,mg);Cs(Vi,Object.fromEntries(l),gg)}function yb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function wb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!yb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function sl(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function uf(){return ot(Yi,wb)??{}}function Bd(t,n){const s=sl(t,n);return s?uf()[s]??null:null}function hi(t,n,s){const l=sl(t,n);if(!l)return;const u=uf(),c=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,m],[,g])=>g.updatedAt-m.updatedAt).slice(0,pg);Cs(Yi,Object.fromEntries(h),bg)}function Ua({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function mi({slow:t}){return e.jsx(jm,{slow:t})}function Ha({message:t,onRetry:n}){const{t:s}=Rt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function Ka(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function xt(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function pi(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Wi(t,n,s){const l=Math.min(n,s),u=Math.max(n,s);return t?.start===l&&t.end===u?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,u)}:{start:l,end:u}}function kb(t,n,s){return Wi(t,n,s)}function gi(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function bi(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function Od(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function ff(t){const n=new Map;for(const s of t)n.set(al(s),s);return n}function hf(t,n){const s=new Map(t);for(const l of n)s.set(al(l),l);return s}function Ud(t,n){let s=0;for(const l of t){const u=ht(l,n);u&&n&&u!==n&&(s+=1)}return s}function Sb(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function jb(t,n){return Array.from(hf(ff(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Rb(t,n){const s=t.relativeRoot==="."?xt(n??t.root)||t.name||t.root:t.relativeRoot||t.name||xt(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:Sb(t.files)}}function mf(t,n){const s=xt(n??"")||n||"";return t.map(l=>Rb(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function pf(t,n,s,l,u){const c=$u(s),h=c.find(F=>F.root===l)??c[0]??null,m=n.find(F=>F.root===l)??null,g=m?.relativeRoot??h?.relativeRoot??".",b=m?.name??h?.name??(xt(l)||l),f=(h?.files??s.files).map(F=>({...F,repoRoot:l,repoRelativeRoot:g,repoName:b})),S=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:g,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:g,name:b,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,files:f,context:S?{...S,root:l,changedFiles:f.map(F=>({path:F.path,absolutePath:F.absolutePath,status:F.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},C=m?n.map(F=>F.root===l?y:F):[...n,y];return{files:Array.from(t).filter(F=>ht(F,u)!==l).concat(f),repositories:C,repoFilters:mf(C,u)}}function ht(t,n){return t.repoRoot??n}function al(t){return`${t.repoRoot??""}\0${t.path}`}function bt(t){return t.absolutePath||t.path}function xi(t){return al(t)}function Cb(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function Hd(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function zd(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Xn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function Ss(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ar(t){return t instanceof DOMException&&t.name==="AbortError"}function Nb(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Wd(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function Gi(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function vi(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Gd(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(c)&&c>0?{start:Math.min(u,c),end:Math.max(u,c)}:{start:n,end:s}}function Mb({actions:t,running:n,completed:s}){const{t:l}=Rt(),[u,c]=a.useState(!1),h=a.useRef(null),m=t.find(b=>n?.action===b.key),g=t.find(b=>s?.action===b.key);return t.length===0?null:(a.useEffect(()=>{if(!u)return;const b=S=>{const y=S.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=S=>{S.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),c(f=>!f)},disabled:t.every(b=>b.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 ${u?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??g?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(jt,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(ji,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(b=>{const f=n?.action===b.key,S=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),b.onClick(),c(!1)},disabled:b.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 ${S?"bg-accent/10 text-accent":b.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:f?e.jsx(jt,{size:13,className:"animate-spin"}):S?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Eb(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function gf(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Eb(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Qn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const yi=new WeakMap;function to(t){const n=yi.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),yi.delete(t)},1700);yi.set(t,s)}function $b(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const m of l){if(!Qn(m))continue;const g=m.querySelector(s);if(g&&Qn(g)){u=g;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Qn)??null,!u)return;const c=gf(u);if(!c){u.scrollIntoView({block:"start",behavior:"smooth"}),to(u);return}const h=u.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),to(u)}function kn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,u=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,c=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`: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(I=>!!I),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const I of m)if(Qn(I)){for(const F of h){const B=I.querySelector(F);if(B&&Qn(B)){g=B;break}}if(g)break}if(g??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Qn)??null,!g){$b(t.filePath);return}const b=gf(g);if(!b){g.scrollIntoView({block:"center",behavior:"smooth"}),to(g);return}const f=g.getBoundingClientRect(),S=b.getBoundingClientRect(),C=f.top-S.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,C),behavior:"instant"}),to(g)}const bf=1,xf=8;function Lb(t){return Math.min(xf,Math.max(bf,t))}function vf({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[c,h]=a.useState({scale:1,x:0,y:0}),[m,g]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),S=a.useRef(!1),y=a.useRef(null),C=a.useRef(0),I=a.useRef(c);I.current=c,a.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const F=a.useCallback(($,T,U)=>{const D=u.current;if(!D)return{x:T,y:U};const p=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,i=p?.clientWidth||D.clientWidth,O=p?.clientHeight||D.clientHeight,j=Math.max(0,(i*$-D.clientWidth)/2),q=Math.max(0,(O*$-D.clientHeight)/2);return{x:Math.min(j,Math.max(-j,T)),y:Math.min(q,Math.max(-q,U))}},[]),B=a.useCallback(($,T,U)=>{h(D=>{const p=Lb($),i=u.current;if(!i||p===1)return{scale:p,x:0,y:0};const O=i.getBoundingClientRect(),j=(T??O.left+O.width/2)-O.left-O.width/2,q=(U??O.top+O.height/2)-O.top-O.height/2,le=p/D.scale,ne=j-(j-D.x)*le,ue=q-(q-D.y)*le;return{scale:p,...F(p,ne,ue)}})},[F]),E=a.useCallback(($,T)=>{g(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,$,T),window.setTimeout(()=>g(!1),220)},[B]);a.useEffect(()=>{const $=u.current;if(!$)return;const T=p=>{if(p.pointerType==="mouse"&&p.button!==0)return;const i=f.current.size===0;if(f.current.add(p.pointerId),i){const O=Date.now(),j=y.current;if(j&&O-j.time<350&&Math.hypot(p.clientX-j.x,p.clientY-j.y)<24){y.current=null,C.current=O,s?.(),E(p.clientX,p.clientY);return}}if(f.current.size>1){S.current=!0,b.current=null;return}if(!(I.current.scale<=1)){p.preventDefault(),b.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{$.setPointerCapture?.(p.pointerId)}catch{}g(!1)}},U=p=>{const i=b.current;if(!i||i.pointerId!==p.pointerId)return;const O=p.clientX-i.startX,j=p.clientY-i.startY;if(!i.moved){if(Math.hypot(O,j)<6)return;i.moved=!0}p.stopPropagation(),p.preventDefault(),h(q=>({...q,...F(q.scale,i.originX+O,i.originY+j)}))},D=p=>{const i=b.current,O=i?.pointerId===p.pointerId&&i.moved;if(i?.pointerId===p.pointerId){i.moved&&p.stopPropagation(),b.current=null;try{$.releasePointerCapture?.(p.pointerId)}catch{}}f.current.delete(p.pointerId)&&f.current.size===0&&(!S.current&&!O&&(y.current={time:Date.now(),x:p.clientX,y:p.clientY}),S.current=!1)};return $.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{$.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[F,s,E]),Jd({onPinch:({offset:[$],origin:[T,U]})=>{g(!1),B($,T,U)},onWheel:({event:$,delta:[T,U],ctrlKey:D})=>{if(D){$.preventDefault(),$.stopPropagation(),g(!1),B(I.current.scale*(1-U*.01),$.clientX,$.clientY);return}I.current.scale<=1||($.preventDefault(),$.stopPropagation(),g(!1),h(p=>({...p,...F(p.scale,p.x-T,p.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:bf,max:xf},from:()=>[I.current.scale,0],rubberband:!0}});const N=c.scale>1;return a.useEffect(()=>{n?.(N)},[n,N]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":N?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:N?"grab":"zoom-in"},onDoubleClick:$=>{$.stopPropagation(),!(Date.now()-C.current<500)&&(s?.(),E($.clientX,$.clientY))},children:l({scale:c.scale,zoomed:N,animateTransform:m,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:m?"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:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function yf({src:t,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:c,onDoubleTap:h}){const m=ro(t,u),[g,b]=a.useState(null),f=s??so(t);return a.useEffect(()=>{b(null)},[t]),e.jsx(vf,{resetKey:t,onZoomChange:c,onDoubleTap:h,children:({transformStyle:S,vectorTransformStyle:y,scale:C,animateTransform:I})=>{const F=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*C,height:g.height*C,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"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"}:g?{...S,width:g.width,height:g.height}:f?y:S,onLoad:B=>{const E=B.currentTarget,N=E.parentElement;if(N&&E.naturalWidth>0&&E.naturalHeight>0){const $=Math.max(1,N.clientWidth-2),T=Math.max(1,N.clientHeight-2),U=Math.min($/E.naturalWidth,T/E.naturalHeight),D=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(E.naturalWidth*D)),height:Math.max(1,Math.round(E.naturalHeight*D))})}l(B)},onError:u});return!f||!g?F:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:F})}})}function Ab({svg:t,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const c=u.current,h=c?.querySelector("svg");if(!c||!h)return;const m=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let S=f[2],y=f[3];if((!Number.isFinite(S)||!Number.isFinite(y)||S<=0||y<=0)&&(S=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(S)||!Number.isFinite(y)||S<=0||y<=0)return;const C=Math.max(1,c.clientWidth-24),I=Math.max(1,c.clientHeight-24),F=Math.min(C/S,I/y,1);h.style.width=`${Math.max(1,Math.floor(S*F*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*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")};m();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return g?.observe(c),()=>g?.disconnect()},[s,t,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function Pb({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(vf,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:c})=>e.jsx(Ab,{svg:t,title:n,scale:c,vectorTransformStyle:u})})}let Tb=0,Ib=0,Db=0,_b=0,Fb=0;function wi(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function nt(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++Ib,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function za(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++_b,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Bb(){return`diff-ui-${Date.now().toString(36)}-${(++Fb).toString(36)}`}function Ob(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function Ub(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function qi({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:m,isMobile:g,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:S,onCloseMarkdownOutline:y,markdownImageLightboxOpen:C,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:N,insertedReferenceKey:$,copiedReferenceKey:T,scrollToLine:U,onScrollToLineHandled:D}){const{t:p}=Rt(),i=Z(A=>A.rootPath),O=Z(A=>A.selectFile),[j,q]=a.useState({kind:"idle"}),[le,ne]=a.useState("schematic"),[ue,G]=a.useState(null),Y=a.useRef(null),[L,_]=a.useState(null),V=a.useRef(new Map),te=a.useRef(null),[oe,ge]=a.useState(null),[he,$e]=a.useState(()=>Cd()),[M,J]=a.useState(()=>hd(i,n)),fe=a.useRef(null),[Re,qe]=a.useState(!1),[Ce,ce]=a.useState(null),[xe,k]=a.useState(0),[Q,ae]=a.useState([]),[Ne,je]=a.useState(null),Ke=a.useRef(null),de=a.useRef(n),[Ae,st]=a.useState(null),[Le,we]=a.useState({status:"idle"}),[at,et]=a.useState(!1),[qt,lt]=a.useState(""),[ct,Pr]=a.useState([]),[Dt,z]=a.useState(0),re=a.useRef(null),be=iu(c),ze=sl(i,n);a.useEffect(()=>{if(de.current===n)return;de.current=n;const A=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(Ke.current===A){Ke.current=null;return}Ke.current=null,ae([]),je(null),et(!1),lt("")},[n,i]);const ut=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,dr=Z(A=>ut?(A.fileChangeVersions.get(ut)??0)+A.fileWatchEpoch:A.fileWatchEpoch),ur=a.useRef(null),_t=a.useRef(null),[fr,hr]=a.useState(0),Sn=a.useCallback(()=>hr(A=>A+1),[]);a.useEffect(()=>{const A=Y.current;return Y.current=null,G(null),A&&URL.revokeObjectURL(A.objectUrl),()=>{const W=Y.current;Y.current=null,W&&URL.revokeObjectURL(W.objectUrl)}},[ut,dr,fr]),a.useEffect(()=>{if(!n){ur.current=null,q({kind:"idle"});return}const A=i&&!n.startsWith("/")?`${i}/${n}`:n,W=new AbortController,se=++Tb,ke=`right-sidebar-file-preview:${se}`,Ue=performance.now();let Te=!1;const Be=(X,He={})=>{Te||(Te=!0,wi("end",{loadingId:se,reason:X,durationMs:Math.round(performance.now()-Ue),filePath:n,fullPath:A,rootPath:i,...He}))};let We=null;const tt=Eh(A),Nt=tt?A.toLowerCase().endsWith(".kicad_pcb")?le==="schematic"?"pcb-front":le:"schematic":le,nr=!tt&&Ki(A),Vt=!tt&&!nr&&$h(A),Mn=!tt&&!nr&&!Vt&&Kd(A),as=ks(A),sn=ys(A),Or=tt?"eda":nr?"image":Vt?"model3d":Mn?"video":"text",Sr=ur.current!==A;if(ur.current=A,Sr){wi("start",{loadingId:se,filePath:n,fullPath:A,rootPath:i,mode:Or,externalVersion:dr}),we({status:"idle"}),q({kind:"loading",mode:Or}),_t.current=null;const X=Bd(i,n);N(X?.lineRange??null),$e(as?Cd():"source"),J(sn?hd(i,n):"source"),tt&&ne(Lh(A))}Sr||q(X=>X.kind==="error"?{kind:"loading",mode:Or}:X);const io=window.setTimeout(()=>{Te||W.signal.aborted||wi("still_active",{loadingId:se,filePath:n,fullPath:A,rootPath:i,mode:Or,durationMs:Math.round(performance.now()-Ue),isPathChange:Sr})},3e3),an=window.setTimeout(()=>{if(Te||W.signal.aborted)return;const X=tt?p("rightSidebar.edaTimeout"):Vt?p("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";W.abort(new DOMException(X,"TimeoutError")),q({kind:"error",message:X}),Be("stuck_timeout",{error:X})},tt?Ah+5e3:Vt?Ph+5e3:Th(A)?35e3:Sg);if(tt){const X=Nt==="pcb-3d"?Y.current:null;X?(q(X),Be("eda_3d_client_cache_hit",{bytes:X.meta.size,view:X.view,mimeType:X.meta.mimeType})):Ih(A,Nt,W.signal,"view_file",ke).then(He=>{if(W.signal.aborted)return;We=URL.createObjectURL(He.blob);const Pt={kind:"eda",sourcePath:He.path||A,objectUrl:We,view:He.view,meta:{size:He.size,mimeType:He.mimeType,modified:He.modified}};if(He.view==="pcb-3d"){const Ur=Y.current;Ur&&Ur.objectUrl!==We&&URL.revokeObjectURL(Ur.objectUrl),Y.current=Pt,G(Pt),We=null}q(Pt),Be("eda_loaded",{bytes:He.size,view:He.view,mimeType:He.mimeType})}).catch(He=>{W.signal.aborted||(q({kind:"error",message:He instanceof Error&&/timed out/i.test(He.message)?p("rightSidebar.edaTimeout"):He instanceof Error?He.message:p("rightSidebar.edaLoadFailed")}),Be("error",{error:He instanceof Error?He.message:String(He)}))})}else if(nr)Dh(A,W.signal,"view_file",ke).then(X=>{We=URL.createObjectURL(X.blob),q({kind:"image",objectUrl:We,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Be("image_loaded",{bytes:X.size,mimeType:X.mimeType})}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error?X.message:p("rightSidebar.imageLoadFailed")}),Be("error",{error:X instanceof Error?X.message:String(X)}))});else if(Vt)_h(A,W.signal,"view_file",ke).then(X=>{W.signal.aborted||(We=URL.createObjectURL(X.blob),q({kind:"model3d",sourcePath:X.path||A,objectUrl:We,ext:X.ext,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Be("model3d_loaded",{bytes:X.size,ext:X.ext}))}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error&&(X.name==="TimeoutError"||/timed out/i.test(X.message))?p("rightSidebar.model3dTimeout"):X instanceof Error?X.message:p("rightSidebar.model3dLoadFailed")}),Be("error",{error:X instanceof Error?X.message:String(X)}))});else if(Mn){const X=Fh(A)??"",He=Vd(A);q(Pt=>Pt.kind==="video"&&Pt.url===He?Pt:{kind:"video",url:He,meta:{size:null,mimeType:X,modified:null}}),Be("video_ready",{mimeType:X})}else Vc(A,W.signal,"view_file",ke).then(X=>{if(!W.signal.aborted){if(X.binary){q({kind:"binary"});return}q({kind:"text",content:X.content,sourcePath:X.path||A,meta:{size:X.size,truncated:X.truncated}}),Be("text_loaded",{bytes:X.size,truncated:!!X.truncated})}}).catch(X=>{W.signal.aborted||(q({kind:"error",message:X instanceof Error?X.message:"Failed to read file"}),Be("error",{error:X instanceof Error?X.message:String(X)}))});return()=>{W.abort(),kt(ke),window.clearTimeout(io),window.clearTimeout(an),We&&URL.revokeObjectURL(We),Be("cleanup")}},[n,i,dr,fr,N,p,le]),a.useEffect(()=>{if(j.kind!=="model3d"||!n){_(null);return}let A=!1;const W=n.lastIndexOf("/"),se=W>=0?n.slice(W+1):n,ke=W>=0?n.slice(0,W):"",Ue=ke.lastIndexOf("/"),Te=Ue>=0?ke.slice(0,Ue):"",Be=se.replace(/\.(stl|glb|gltf)$/i,""),We=`${Te?`${Te}/`:""}features/${Be}.json`;return Vc(We).then(tt=>{if(!A)try{const Nt=JSON.parse(tt.content);_(Nt.version===1&&Array.isArray(Nt.features)&&Nt.features.length>0?Nt.features:null)}catch{_(null)}}).catch(()=>{A||_(null)}),()=>{A=!0}},[j,n]),a.useEffect(()=>{if(j.kind!=="text"){st(null);return}const A=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,W=nu(A),se=j.content,ke=ks(A??"")&&he==="preview",Ue=ys(A??"")&&M==="preview";if(!W||ke||Ue||!su(se)){st(null);return}let Te=!1;const Be=We=>{if(Te||!We.registered(W)){Te||st(null);return}try{st(ou(We,se,W))}catch{st(null)}};return Ce?Be(Ce):(st(null),au().then(We=>{Te||(ce(We),Be(We))}).catch(()=>{})),()=>{Te=!0}},[j,Ce,n,i,he,M]),a.useLayoutEffect(()=>{if(!ze||j.kind!=="text")return;const A=`${ze}:${he}:${M}`;if(_t.current===A)return;const W=Bd(i,n);if(_t.current=A,!W)return;const se=requestAnimationFrame(()=>{const ke=te.current;if(!ke)return;const Ue=he==="preview"?W.markdownTop??W.top:W.top;ke.scrollTo({top:Math.max(0,Ue??0),left:Math.max(0,W.left??0)}),k(he==="preview"?Math.max(0,Ue??0):0)});return()=>cancelAnimationFrame(se)},[n,he,M,j.kind,ze,i]),a.useEffect(()=>{ze&&hi(i,n,{lineRange:E})},[n,E,ze,i]),a.useEffect(()=>{if(U==null||j.kind!=="text")return;ge(null),N({start:U,end:U});const A=U,W=requestAnimationFrame(()=>{const se=V.current.get(A);se&&se.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(W)},[U,j,N,D]);const jn=a.useCallback(A=>{const W=te.current;if(!W)return!1;const se=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(A):A.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ke=W.querySelector(`#${se}`);return ke?(ke.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const A=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,W=j.kind==="text"&&ks(A??"")&&he==="preview";if(!Ne||!W)return;const se=requestAnimationFrame(()=>{jn(Ne)&&je(null)});return()=>cancelAnimationFrame(se)},[n,jn,he,Ne,j,i]),a.useLayoutEffect(()=>{const A=te.current;if(!A||!E){ge(null);return}if(oe)return;const W=j.kind==="image"||j.kind==="loading"&&j.mode==="image",se=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,ke=j.kind==="text"&&ks(se??"")&&he==="preview",Ue=j.kind==="text"&&ys(se??"")&&M==="preview";if(j.kind!=="text"||W||ke||Ue){ge(null);return}const Te=()=>{const We=V.current.get(E.end);if(!We||!A){ge(null);return}const tt=We.offsetTop+We.offsetHeight/2,Nt=A.scrollLeft+Math.max(8,A.clientWidth-120);ge({top:tt,left:Nt})};Te();const Be=new ResizeObserver(()=>Te());return Be.observe(A),()=>Be.disconnect()},[E,oe,j,he,M,n,i,Ae]);const Tr=j.kind==="text"&&!(ys(ut??"")&&M==="preview")&&!ut?.toLowerCase().endsWith(".csv")&&!ut?.toLowerCase().endsWith(".kicad_pro")&&!ut?.toLowerCase().endsWith(".kicad_prl"),mr=a.useCallback(()=>{et(!1),lt(""),Pr([]),z(0),Da()},[]),Rn=a.useCallback(()=>{Tr&&(et(!0),requestAnimationFrame(()=>{re.current?.focus(),re.current?.select()}))},[Tr]),mt=a.useCallback(A=>{z(W=>ct.length===0?0:(W+A+ct.length)%ct.length)},[ct.length]);if(a.useEffect(()=>{const A=W=>{const se=og(W);if(se==="open"&&Tr){W.preventDefault(),Rn();return}at&&(se==="close"?(W.preventDefault(),mr()):(se==="next"||se==="previous")&&(W.preventDefault(),mt(se==="previous"?-1:1)))};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[mr,at,mt,Rn,Tr]),a.useLayoutEffect(()=>{if(Da(),!at||!qt.trim()||!te.current){Pr([]),z(0);return}const A=lg(te.current,qt);return Pr(A),z(0),bd(A,0),xd(A[0]),Da},[at,qt,Ae,he,j]),a.useEffect(()=>{at&&(bd(ct,Dt),xd(ct[Dt]))},[Dt,ct,at]),a.useEffect(()=>Da,[]),!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:p("rightSidebar.selectFilePrompt")});const Oe=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=Ka(Oe,i),pr=Yd(Oe,i),gr=j.kind==="text"&&j.content?j.content.split(`
|
|
1654
1654
|
`):[],_s=Math.max(2,String(gr.length).length)+1,br=j.kind==="text"||j.kind==="image"||j.kind==="model3d"||j.kind==="video"||j.kind==="eda"?j.meta:null,xr=ks(Oe),Fs=Oe.toLowerCase().endsWith(".csv"),At=Oe.toLowerCase().endsWith(".kicad_pro"),Zn=Oe.toLowerCase().endsWith(".kicad_prl"),Ft=j.kind==="text"&&xr&&he==="preview",Bs=ys(Oe),vr=j.kind==="text"&&Bs&&M==="preview",Os=j.kind==="image"||j.kind==="loading"&&j.mode==="image",oo=j.kind==="model3d"||j.kind==="loading"&&j.mode==="model3d",Ct=j.kind==="video"||j.kind==="loading"&&j.mode==="video",tn=j.kind==="eda"||j.kind==="loading"&&j.mode==="eda",es=j.kind==="text"?j.sourcePath:Oe,Ir=um(es,i,E),Dr=(()=>{if(!E||j.kind!=="text"||gr.length===0)return Ir;const A=[];for(let ke=E.start;ke<=E.end;ke+=1)A.push(`${ke} ${gr[ke-1]??""}`);const W=Tu(Oe).replace(/^\./,""),se="```";return`${Ir}
|
|
1655
1655
|
${se}${W}
|
|
1656
1656
|
${A.join(`
|
|
1657
1657
|
`)}
|
|
1658
1658
|
${se}
|
|
1659
|
-
`})(),yr=`path:${Oe}`,wr=E?`path:${Oe}:${E.start}-${E.end}`:yr,_r=$===yr,Fr=$===wr,Cn=T===yr,ts=T===wr,rn=Fr||ts,Kt=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,Br=A=>{const W=te.current;if(!W)return;const se=W.getBoundingClientRect(),ke=A.currentTarget.getBoundingClientRect(),Ue=A.clientX||ke.left+ke.width/2,Be=(A.clientY||ke.top+ke.height/2)-se.top+W.scrollTop,We=g?116:132,tt=W.scrollLeft+Math.max(8,W.clientWidth-We),Nt=Math.min(Math.max(8,Ue-se.left+W.scrollLeft+10),tt);ge({top:Be,left:Nt})},rs=(A,W)=>{Wi()||(Br(A),N(se=>{const ke=zi(se,W,W);return ke||ge(null),ke}))},ns=(A,W,se)=>{Br(A),N(ke=>{const Ue=zi(ke,W,se);return Ue||ge(null),Ue})},kr=(A,W,se,ke)=>{ke==="end"&&Br(A),N({start:W,end:se})},tr=A=>{const{scrollTop:W,scrollLeft:se}=A.currentTarget;k(W),hi(i,n,{top:W,left:se,markdownTop:W})},Pe=A=>{if(A.directory){m?.(A.path);return}if(A.path===Oe||j.kind==="text"&&A.path===j.sourcePath){A.fragment&&jn(A.fragment);return}ae(W=>[...W,Oe]),Ke.current=A.path,je(A.fragment),N(null),O(A.path)},rr=()=>{const A=Q[Q.length-1];A&&(ae(W=>W.slice(0,-1)),Ke.current=A,je(null),N(null),O(A))},nn=A=>{const{scrollTop:W,scrollLeft:se}=A.currentTarget;hi(i,n,{top:W,left:se})},Nn=()=>{if(t){t(Dr,wr);return}E&&l(Dr,wr)},ss=async()=>{if(!(!Oe||Le.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){we({status:"pending"});try{await em(Oe),we({status:"idle"})}catch(A){we({status:"error",message:A instanceof Error?A.message:p("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[be.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Ft||vr)?"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:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p("rightSidebar.backToFileList"),title:p("rightSidebar.backToFileList"),children:e.jsx(Zd,{size:16})}),Q.length>0&&e.jsxs("button",{type:"button",onClick:rr,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 ${g?"w-9":"px-2.5"}`,"aria-label":p("rightSidebar.backToPreviousPreview"),title:p("rightSidebar.backToPreviousPreview"),children:[e.jsx($s,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:p("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Oe,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Tr&&e.jsx("button",{type:"button",onClick:at?mr:Rn,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 ${at?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":p("rightSidebar.findInFile"),title:`${p("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Jn,{size:14})}),xr&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&y?.(),$e(A=>{const W=A==="preview"?"source":"preview";return St(xu,W),W}),N(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 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?he==="preview"?e.jsx(Mi,{size:14}):e.jsx(Ni,{size:14}):p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),Bs&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{J(A=>{const W=A==="preview"?"source":"preview";return Cp(i,n,W),W}),N(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 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?M==="preview"?e.jsx(Mi,{size:14}):e.jsx(Ni,{size:14}):p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),vr&&e.jsx("button",{type:"button",onClick:()=>{fe.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":p(Re?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:p(Re?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(eu,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Oe,yr),...be(pr,yr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${_r||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:p("rightSidebar.insertReference",{reference:pr}),children:p(Cn?"rightSidebar.copied":_r?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(pr)},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:p("rightSidebar.copyReference",{reference:pr}),"aria-label":p("rightSidebar.copyFileRef"),children:e.jsx(Bh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{ss()},disabled:Le.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Le.status==="error"?Le.message??p("rightSidebar.downloadFailed"):p("rightSidebar.downloadFile"),"aria-label":p("rightSidebar.downloadFile"),children:Le.status==="pending"?e.jsx(jt,{size:13,className:"animate-spin"}):e.jsx(fm,{size:14})})]})]}),at&&Tr&&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(Jn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:re,type:"search",value:qt,onChange:A=>lt(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),mt(A.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:p("rightSidebar.findInFilePlaceholder"),"aria-label":p("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ct.length>0?`${Dt+1}/${ct.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>mt(-1),disabled:ct.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":p("rightSidebar.previousSearchMatch"),title:`${p("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Xd,{size:13})}),e.jsx("button",{type:"button",onClick:()=>mt(1),disabled:ct.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":p("rightSidebar.nextSearchMatch"),title:`${p("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(hm,{size:13})}),e.jsx("button",{type:"button",onClick:mr,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":p("rightSidebar.closeFileSearch"),title:`${p("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Gt,{size:13})})]}),br&&!(g&&(Ft||vr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[br.size!==null&&e.jsx("span",{children:p("rightSidebar.byteCount",{count:br.size.toLocaleString()})}),"truncated"in br&&br.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:p("rightSidebar.previewTruncated")}),"mimeType"in br&&e.jsx("span",{children:br.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(g&&(Ft||vr))&&!oo&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:tn?p("rightSidebar.edaPickHint"):Fs?p("rightSidebar.csvTablePreview"):At||Zn?p("rightSidebar.kicadProjectPickHint"):Ct?p("rightSidebar.videoPreviewHint"):Os?p("rightSidebar.imagePreviewHint"):Ft?E?p("rightSidebar.selectedLineHint",{lineLabel:Kt??""}):p("rightSidebar.markdownPreviewHint"):vr?p("rightSidebar.htmlPreviewHint"):E?p("rightSidebar.selectedLineHint",{lineLabel:Kt??""}):p("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?p("rightSidebar.edaLoading"):j.mode==="image"?p("rightSidebar.loadingImage"):j.mode==="model3d"?p("rightSidebar.model3dLoading"):j.mode==="video"?p("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:p("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:p("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(hu,{blobUrl:j.objectUrl,filePath:Oe,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(yf,{src:j.objectUrl,alt:Lt.name,vector:!1,onLoad:A=>{const W=A.currentTarget;q(se=>se.kind==="image"?{...se,dimensions:{width:W.naturalWidth,height:W.naturalHeight}}:se)},onError:()=>q({kind:"error",message:p("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(Fp,{url:j.url,onLoadError:()=>q({kind:"error",message:p("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Gp,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Oe.toLowerCase().endsWith(".kicad_pcb"),onViewChange:ne,onInsertAnnotation:t??u,onRefresh:Sn,interactive3d:ue?e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(jd,{blobUrl:ue.objectUrl,ext:".glb",fileName:Lt.name,filePath:ue.sourcePath,features:null,onInsertFeature:t??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:A=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(A)?A:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(jd,{blobUrl:j.objectUrl,ext:j.ext,fileName:Lt.name,filePath:j.sourcePath,features:L,onInsertFeature:t??u,onRefresh:Sn})})}):j.kind==="text"&&Fs?e.jsx(Vp,{content:j.content,filePath:Oe,onInsertAnnotation:t??u},Oe):j.kind==="text"&&(At||Zn)?e.jsx(Jp,{content:j.content,filePath:Oe,localState:Zn,onInsertAnnotation:t??u},Oe):Ft?e.jsxs("div",{ref:te,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:tr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(cf,{content:j.content,filePath:j.sourcePath,rootPath:i,lineRange:E,onLineRangeClick:ns,onLineRangeDrag:kr,scrollTop:xe,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:S,onOutlineClose:y,lightboxOpen:C,lightboxCloseSignal:I,onLightboxOpen:F,onLightboxClose:B,onLocalLinkOpen:Pe}),E&&oe&&e.jsxs("button",{type:"button",onClick:Nn,...be(Dr,wr),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Bd(g,rn),title:`Insert markdown reference: ${Ir}`,children:[e.jsx(Va,{size:g?13:11}),ts?p("rightSidebar.copied"):Fr?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Kt??""})]})]}):vr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ag,{ref:fe,src:Oh(Oe),title:`${Lt.name} preview`,exitFullscreenLabel:p("rightSidebar.htmlFullscreenExit"),onFullscreenChange:qe},`${Oe}:${dr}:${fr}`)}):j.kind==="text"?e.jsxs("div",{ref:te,onScroll:nn,className:`${Yi} 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:[gr.length>0?e.jsx("div",{className:"min-w-full",children:gr.map((A,W)=>{const se=W+1,ke=!!(E&&se>=E.start&&se<=E.end),Ue=Ae&&Ae.length===gr.length?Ae[W]:null;return e.jsxs("div",{ref:Te=>{Te?V.current.set(se,Te):V.current.delete(se)},role:"button","data-file-preview-line":se,tabIndex:0,onClick:Te=>rs(Te,se),onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),rs(Te,se))},style:{gridTemplateColumns:`${_s}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${ke?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${pr}:${se}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${ke?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:se}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ue??(A||" ")})]},W)})}):"Empty file.",E&&oe&&e.jsxs("button",{type:"button",onClick:Nn,...be(Dr,wr),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Bd(g,rn),title:`Insert code reference: ${Ir}`,children:[e.jsx(Va,{size:g?13:11}),ts?p("rightSidebar.copied"):Fr?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Kt??""})]})]}):null]})}function Hb({isOpen:t,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h=!1,onTogglePinned:m,rightSidebarFilePreviewOpen:g=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:S,rightSidebarRepoPickerOpen:y=!1,rightSidebarRepoPickerCloseSignal:C,onOpenRightSidebarRepoPicker:I,onCloseRightSidebarRepoPicker:F,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p}){const{t:i,locale:O}=Rt(),[j,q]=a.useState(""),[le,ne]=a.useState(null),ue=Z(r=>r.rightSearchOpen),G=Z(r=>r.setRightSearchOpen),Y=Z(r=>r.rightSidebarLayoutPreference),L=Z(r=>r.setRightSidebarLayoutPreference),[_,V]=a.useState(()=>Tg()),[te,oe]=a.useState("."),[ge,he]=a.useState(""),[$e,M]=a.useState(!1),[J,fe]=a.useState(!1),[Re,qe]=a.useState(!1),[Ce,ce]=a.useState(!1),xe=a.useDeferredValue(j),[k,Q]=a.useState(null),[ae,Ne]=a.useState([]),[je,Ke]=a.useState([]),[de,Ae]=a.useState(null),[st,Le]=a.useState(null),[we,at]=a.useState(null),[et,qt]=a.useState(null),[lt,ct]=a.useState(()=>ot(vd,Rs)??!1),[Pr,Dt]=a.useState(()=>ot(yd,Rs)??!1),[z,re]=a.useState(()=>ot(wd,Rs)??!1),[be,ze]=a.useState(()=>ot(ii,Eg)??""),[ut,dr]=a.useState(0),[ur,_t]=a.useState(!1),[fr,hr]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Tr,mr]=a.useState(!1),[Rn,mt]=a.useState(null),[Oe,Lt]=a.useState(null),[pr,gr]=a.useState(()=>Nd(ai)),[_s,br]=a.useState(()=>Nd(xd)),[xr,Fs]=a.useState(()=>Mg()),[At,Zn]=a.useState(()=>$g()),[Ft,Bs]=a.useState(()=>Ag()),vr="words",[Os,oo]=a.useState(0),[Ct,tn]=a.useState([]),[es,Ir]=a.useState([]),[Dr,yr]=a.useState(!1),[wr,_r]=a.useState(null),[Fr,Cn]=a.useState([]),[ts,rn]=a.useState(!1),[Kt,Br]=a.useState([]),[rs,ns]=a.useState([]),[kr,tr]=a.useState(!1),[Pe,rr]=a.useState(null),[nn,Nn]=a.useState([]),[ss,A]=a.useState({}),[W,se]=a.useState(!1),[ke,Ue]=a.useState(null),[Te,Be]=a.useState(null),[We,tt]=a.useState(null),[Nt,nr]=a.useState(null),[Vt,Mn]=a.useState(!1),[as,sn]=a.useState(""),Or=a.useDeferredValue(as),[Sr,io]=a.useState({}),[an,X]=a.useState([]),[He,Pt]=a.useState(!1),[Ur,os]=a.useState(!1),[al,En]=a.useState(null),[lo,$n]=a.useState(!1),sr=a.useRef(null),Hr=a.useRef(0),ol=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[wf,Us]=a.useState(null),[is,il]=a.useState(()=>ot(oi,Rs)??!1),[co,uo]=a.useState(!1),[Hs,fo]=a.useState([]),[jr,zs]=a.useState({}),[Mt,Ws]=a.useState({}),[zr,ll]=a.useState(!0),[cl,dl]=a.useState(()=>new Set),[rt,on]=a.useState(null),[ho,ln]=a.useState(null),[kf,Rr]=a.useState(!1),[ul,Cr]=a.useState(0),[,mo]=a.useState(0),[po,Gs]=a.useState(!1),[ar,go]=a.useState(!1),[Sf,fl]=a.useState(()=>Z.getState().rightTab==="diff"),[jf,hl]=a.useState(()=>Z.getState().rightTab==="android"),[Wr,ml]=a.useState(!1),Rf=Vc(r=>!!r.docks[nd]),[Ie,ls]=a.useState(null),[Ln,cs]=a.useState(null),[pt,Gr]=a.useState(null),[pl,gt]=a.useState(null),[An,gl]=a.useState(null),[bo,Cf]=a.useState(()=>Date.now()),[Nf,Mf]=a.useState(!1),[cn,qs]=a.useState(!1),[Ks,bl]=a.useState(""),[Pn,Vs]=a.useState(""),[dn,Ys]=a.useState(""),[un,Xs]=a.useState(""),[xl,Tn]=a.useState(null),[Js,Qs]=a.useState(!1),[vl,xo]=a.useState(!1),[yl,wl]=a.useState(!1),[Zs,Ef]=a.useState({key:null,nonce:0}),kl=a.useRef(null),Sl=a.useRef(null),ee=tm(s,h,Y),$f=Eu(ee,h,Ft),[vo,yo]=a.useState(()=>Hg(s)),wo=Z(r=>r.rightTab),Yt=Z(r=>r.setRightTab),x=Z(r=>r.rootPath),In=Z(r=>r.explorerRoot),jl=Z(r=>r.pinnedExplorerRootsCache),Rl=Z(r=>r.hydratePinnedExplorerRoots),Cl=Z(r=>r.syncPinnedExplorerRoots),Bt=Z(r=>r.setExplorerRoot),Nl=Z(r=>r.resetExplorerToProject),Dn=Z(r=>r.pinExplorerRoot),fn=Z(r=>r.unpinExplorerRoot),Je=Z(r=>r.selectedFilePath),Qe=Z(r=>r.selectFile),ko=Z(r=>r.showHiddenFiles),Lf=Z(r=>r.toggleShowHiddenFiles),So=Z(r=>!!(x&&r.nestedGitScanRoots[x])),ye=Z(r=>r.changedFiles),ea=Z(r=>r.setChangedFiles),ta=Z(r=>r.invalidateDirectoryCache),Af=Z(r=>r.setDirectorySortMode),Ml=Z(r=>r.applyFileWatchEvents),El=Z(r=>r.reconcileDirectoryCache),$l=Z(r=>r.bumpFileWatchEpoch),qr=Z(r=>r.gitBundleLoading),Ll=Z(r=>r.gitBundleSlow),hn=Z(r=>r.gitBundleError),_n=Z(r=>r.gitBundleLastLoadedAt),Al=Z(r=>r.beginGitBundleLoading),Pl=Z(r=>r.setGitBundleSlowFor),jo=Z(r=>r.finishGitBundleLoading),ra=Z(r=>r.resetGitBundleLoading),Ro=Z(r=>r.setGitBundleError),Tl=Z(r=>r.markGitBundleLoaded),me=In??x,Il=a.useMemo(()=>me?dg(me,te):"",[me,te]),ds=a.useMemo(()=>cg(ge),[ge]),Dl=a.useMemo(()=>({excludePatterns:ds,caseSensitive:J,wholeWord:Re,regex:Ce}),[J,ds,Ce,Re]),na=Z(r=>me?r.fileSortModes[me]??"name":"name"),_l=Z(r=>!!(me&&r.directoryCache.has(me))),Fn=a.useRef(null),vt=a.useRef(0),[Fl]=a.useState(()=>++Db),Nr=a.useRef(null),Kr=a.useRef(null),sa=a.useRef(0),Ot=a.useRef(new Map),Ut=a.useRef(new Map),or=a.useRef(new Set),mn=a.useRef(new Set),pn=a.useRef(0),Vr=a.useRef(null),Bn=a.useRef(0),On=a.useRef(null),Un=a.useRef(0),Yr=a.useRef(null),Co=a.useRef(new Set),No=a.useRef(null),Mo=a.useRef(null),aa=a.useRef(null),Eo=a.useRef(null);a.useEffect(()=>{if(An===null)return;const r=Math.max(0,Date.now()-An),o=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,d=Math.max(50,o-r%o),v=window.setTimeout(()=>Cf(Date.now()),d);return()=>window.clearTimeout(v)},[bo,An]);const oa=a.useRef(null),Mr=a.useRef(null),ia=a.useRef(null),us=a.useRef(null),Se=a.useCallback(r=>Z.getState().rootPath===r,[]);a.useEffect(()=>{if(!t||typeof window>"u")return;const r=o=>{const d=Ob(o.target);d&&za("global_change_row_event",{...Ub(o),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:Z.getState().selectedFilePath,rightTab:Z.getState().rightTab,activeGitRepoRoot:de,changedFiles:Z.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[de,t]);const Bl=a.useCallback(async(r=x??void 0)=>{if(!r)return null;if(or.current.has(r)||mn.current.has(r))return nt("untracked_skip_cached",{cwd:r,rootPath:x,completed:or.current.has(r),running:mn.current.has(r)}),null;const o=x,d=sa.current+1;sa.current=d,Ot.current.set(r,d);const v=`right-sidebar-git-untracked:${r}`,w=new AbortController;Ut.current.set(r,w),mn.current.add(r),nt("untracked_start",{requestId:d,cwd:r,rootPath:x});try{let R=await Yc(r,w.signal,v),P=0;for(;R.status==="running"&&P<120;){if(Ot.current.get(r)!==d||w.signal.aborted)return nt("untracked_stale_result",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,status:R.status}),null;if(!Se(o))return nt("untracked_root_changed",{requestId:d,cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath}),null;await new Promise(K=>window.setTimeout(K,P<10?1e3:3e3)),P+=1,R=await Yc(r,w.signal,v)}if(Ot.current.get(r)!==d||!Se(o))return nt("untracked_stale_result",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath,files:R.files.length,status:R.status}),null;if(R.status==="done")return ea(hf(Z.getState().changedFiles,R.files)),R.files.length>0&&Ne(K=>{const Ge=new Map(K.map(Ee=>[Ee.root,Ee])).get(r);if(!Ge)return K;const De=jb(Ge.files,R.files),Fe=K.map(Ee=>Ee.root===r?{...Ee,files:De,context:Ee.context?{...Ee.context,changedFiles:De.map(Ye=>({path:Ye.path,absolutePath:Ye.absolutePath,status:Ye.status})),truncated:!1}:Ee.context,untrackedDeferred:!1}:Ee);Ke(mf(Fe,x));const pe=Fe.find(Ee=>Ee.root===x);return pe?.context&&Q(Ee=>Ee?.root===pe.root?{...Ee,...pe.context}:Ee),Fe}),or.current.add(r),nt("untracked_apply",{requestId:d,cwd:r,files:R.files.length}),R;const H=R.error||(R.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return or.current.add(r),nt("untracked_error",{requestId:d,cwd:r,message:H,code:R.code,status:R.status}),null}catch(R){if(Ot.current.get(r)!==d||!Se(o)||Ar(R))return nt("untracked_aborted",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath,message:R instanceof Error?R.message:String(R)}),null;const P=R instanceof Error?R.message:"Failed to scan untracked files";return or.current.add(r),nt("untracked_error",{requestId:d,cwd:r,message:P}),null}finally{Ut.current.get(r)===w&&Ut.current.delete(r),Ot.current.get(r)===d&&Ot.current.delete(r),mn.current.delete(r)}},[k,Se,x,ea]),Xt=a.useMemo(()=>{const r=new Set(je.map(d=>d.root)),o=Fr.filter(d=>r.has(d));return o.length>0?o:de?[de]:[]},[de,Fr,je]),Ol=Xt.length===0,gn=a.useMemo(()=>Xt.map(r=>ae.find(o=>o.root===r)).filter(r=>!!r),[Xt,ae]),Pf=a.useMemo(()=>je.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[je]),ir=a.useCallback(async()=>{if(!x){tn([]),Ir([]);return}const r=x,o=Bn.current+1;Bn.current=o,On.current?.abort();const d=new AbortController;On.current=d,yr(Ct.length===0),_r(null);try{const v=Xt.length>0?await Promise.all(Xt.map(w=>Xc({workspaceRoot:x,repoRoot:w},d.signal))).then(w=>({records:w.flatMap(R=>R.records),walkthroughs:w.flatMap(R=>R.walkthroughs??[])})):await Xc({workspaceRoot:x},d.signal);if(Bn.current!==o||!Se(r))return;tn(v.records),Ir(v.walkthroughs??[])}catch(v){if(Bn.current!==o||!Se(r)||Ar(v))return;_r(v instanceof Error?v.message:"Failed to load change audit explanations")}finally{On.current===d&&(On.current=null),Bn.current===o&&Se(r)&&yr(!1)}},[Ct.length,Xt,Se,x]),la=a.useCallback(async(r,o,d)=>{if(!r&&!x){Br([]),ns([]);return}const v=x,w=Un.current+1;Un.current=w,Yr.current?.abort();const R=new AbortController;Yr.current=R;try{const P=r?[r]:Array.from(new Set([x,...ae.map(K=>K.root)].filter(K=>!!K))),H=await Promise.all(P.map(K=>Hh({repoRoot:K,baseRef:o,branchName:d},R.signal))).then(K=>{const Me=new Map,Ge=new Map;for(const De of K){for(const Fe of De.records)Me.set(Fe.id,Fe);for(const Fe of De.walkthroughs??[])Ge.set(Fe.id,Fe)}return{records:Array.from(Me.values()),walkthroughs:Array.from(Ge.values())}});if(Un.current!==w||!Se(v))return;Br(H.records),ns(H.walkthroughs??[])}catch(P){if(Un.current!==w||!Se(v)||Ar(P))return;console.warn("[RightSidebar] Failed to load branch explanations",P)}finally{Yr.current===R&&(Yr.current=null)}},[ae,Se,x]),Xr=a.useCallback((r,o={})=>{if(!Se(x)){nt("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:Z.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}nt(r.files.length===0?"empty_bundle":"apply",{rootPath:x,available:r.available,files:r.files.length,repositories:r.repositories?.map(pe=>({root:pe.root,relativeRoot:pe.relativeRoot,files:pe.files.length,available:pe.available,error:pe.error})),repoFilters:r.repoFilters?.map(pe=>({root:pe.root,label:pe.label,count:pe.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let d=$u(r),v=r.repoFilters??[],w=r.files;const R=Z.getState().changedFiles;if(!!(o.cacheOnly&&!r.cached&&r.files.length===0&&d.length===0)&&(R.size>0||ae.length>0||k)){nt("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:R.size,currentRepositories:ae.length});return}const H=d.some(pe=>pe.deferred);if(H&&!o.replaceWorkspace){const pe=new Set(d.filter(Ye=>!Ye.deferred||Ye.root===x).map(Ye=>Ye.root));w=[...Array.from(R.values()).filter(Ye=>!pe.has(ht(Ye,x)??"")),...r.files]}const K=Od(R.values(),x),Me=Od(r.files,x),Ge=d.some(pe=>pe.root!==x);if(!!(o.background&&!H&&!o.replaceWorkspace&&R.size>0&&(r.files.length===0&&!r.error||K>0&&Me===0&&!Ge))){nt("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:R.size,nextFiles:r.files.length,currentNestedCount:K,nextNestedCount:Me,nextRepositories:d.map(pe=>({root:pe.root,relativeRoot:pe.relativeRoot,files:pe.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(o.replaceRepoRoot){const pe=pf(R.values(),ae,r,o.replaceRepoRoot,x);w=pe.files,d=pe.repositories,v=pe.repoFilters}if(ea(ff(w)),Ne(d),Ke(v),o.syncActiveRepo!==!1){const pe=o.activeRepoRoot!==void 0?o.activeRepoRoot:de??Cd(x),Ee=Dg({...r,repositories:d,repoFilters:v},pe);Ae(Ee),ci(x,Ee)}typeof r.cacheUpdatedAt=="number"&&gl(r.cacheUpdatedAt),Q(pe=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==x)return pe;if(!r.context)return null;const Ee=pe?.root??x;return!pe?.available||Ee!==(r.context.root??x)?r.context:{...pe,...r.context}}),o.reloadDiff&&oo(pe=>pe+1);const Fe=Z.getState().selectedFilePath;if(Fe&&!Fe.startsWith("/")&&!w.some(pe=>pe.path===Fe||pe.absolutePath===Fe)&&Qe(null),gr(pe=>{const Ee=new Set(w.map(Zt=>ht(Zt,x)).filter(Boolean)),Ye=new Set;for(const Zt of pe)Ee.has(Zt)&&Ye.add(Zt);return di(ai,Ye),Ye}),o.loadDeferred!==!1){const pe=d.filter(Ee=>Ee.untrackedDeferred&&Ee.root).map(Ee=>Ee.root);for(const Ee of pe)Bl(Ee)}o.loadAudit!==!1&&ir()},[de,Se,ir,Bl,x,Qe,ea]);a.useEffect(()=>{ra(),No.current=null,Mo.current=x;const r=[],o=[],v=Cd(x);vt.current+=1,pn.current+=1,sa.current+=1,Nr.current?.abort(),kt(Xn(Kr.current?.cwd??x??void 0)),Kr.current=null,Nr.current=null,Vr.current?.abort(),kt("right-sidebar-git-details"),Vr.current=null;for(const K of Ut.current.values())K.abort();for(const K of Ut.current.keys())kt(`right-sidebar-git-untracked:${K}`);Ut.current.clear(),Ot.current.clear(),Bn.current+=1,On.current?.abort(),On.current=null,Un.current+=1,Yr.current?.abort(),Yr.current=null,Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,tn([]),Ir([]),yr(!1),_r(null),Cn([]),rn(!1),Br([]),ns([]),tr(!1),rr(null),se(!1),Ue(null),Be(null),tt(null),nr(null),Mn(!1),sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1),Us(null),on(null),ln(null),il(!1),St(oi,!1),uo(!1);const w=x?Md()[x]:null,R=w?.previewEntries??[],P=w?.selectedPreviewKey??null,H=P?R.find(K=>K.key===P)??null:null;fo(w?.selectedRepoRoots??[]),zs(w?.repoTargetBranches??{}),Ws(w?.repoBaseBranches??{}),Nn(R),A(w?.previewScrollTops??{}),H&&w?.previewDetailOpen&&(H.diff.hunks?.length??0)>0&&(rr(H.diff),on(H.key),ln(w.selectedPreviewFileKey??(H.diff.hunks?.[0]?`${H.diff.hunks[0].filePath}\0${H.diff.hunks[0].hunkHeader}\0${H.diff.hunks[0].hunkIndex}`:null)),tr(!0)),ll(w?.includeUncommitted??!0),No.current=x,qs(!1),Ae(v??null),or.current.clear(),mn.current.clear(),ls(null),cs(null),Gr(null),gt(null),gl(null),Ne(r),Ke(o),Q(null),Eo.current=null},[ra,x]);const Jt=a.useCallback(async(r=x??void 0,o={})=>{if(!r)return null;const d=x,v=vt.current;if(await Qm(Z.getState().hydrateNestedGitScanRoots),vt.current!==v||!Se(d))return null;const w=r===x&&Vn(x),R=o.includeNested??w,P=o.refresh??o.reloadDiff??!1,H=o.cacheOnly??!1,K=o.background??!1,Me=R&&(o.discoverOnly??!1);P&&or.current.clear();const Ge=Kr.current;if(Ge&&Ge.cwd===r&&Ge.includeNested===R&&Ge.refresh===P&&Ge.cacheOnly===H&&Ge.discoverOnly===Me)return nt("reuse_pending",{cwd:r,includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me}),Ge.promise;const De=vt.current+1;vt.current=De;const Fe=`right-sidebar:${Fl}:${De}`;Nr.current?.abort();const pe=Xn(r);kt(pe);const Ee=new AbortController;Nr.current=Ee;let Ye=null;K||Al(Fe),Ro(null),nt("start",{requestId:De,cwd:r,rootPath:x,requestSlotId:pe,includeNested:R,refresh:P,cacheOnly:H,background:K,existingChanges:ye.size,lastLoadedAt:_n}),!K&&typeof window<"u"&&(Ye=window.setTimeout(()=>{vt.current===De&&Pl(Fe,!0)},vg));const Zt=(async()=>{const _e=await Ea(r,Ee.signal,{includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me,action:P?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:pe,requestTimeoutMs:P?null:void 0});if(Nb(_e)){if(nt("cancelled_result_ignored",{requestId:De,activeRequestId:vt.current,cwd:r,error:_e.error??_e.context?.error}),Ee.signal.aborted)return null;throw new Error(_e.error??_e.context?.error??"Failed to load Git changes")}return vt.current!==De||!Se(d)?(nt("stale_result",{requestId:De,activeRequestId:vt.current,cwd:r,expectedRootPath:d,currentRootPath:Z.getState().rootPath,files:_e.files.length,repositories:_e.repositories?.length??0}),null):(Xr(_e,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:R,background:K,cacheOnly:H,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),_e)})();Kr.current={cwd:r,includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me,promise:Zt};try{const _e=await Zt;return vt.current===De&&_e&&Se(d)?Tl({cached:_e.cached,stale:_e.stale,cacheAgeMs:_e.cacheAgeMs,nestedDeferred:!R||_e.nestedDeferred,untrackedDeferred:_e.untrackedDeferred}):vt.current===De&&Se(d)&&jo(Fe),_e}catch(_e){return vt.current!==De||!Se(d)||Ee.signal.aborted?(nt("aborted",{requestId:De,activeRequestId:vt.current,cwd:r,expectedRootPath:d,currentRootPath:Z.getState().rootPath,message:_e instanceof Error?_e.message:String(_e)}),null):(nt("error",{requestId:De,cwd:r,includeNested:R,refresh:P,background:K,message:_e instanceof Error?_e.message:String(_e)}),K||(Q(null),Ro(_e instanceof Error?_e.message:"Failed to load Git changes")),null)}finally{Ye!==null&&window.clearTimeout(Ye),Nr.current===Ee&&(Nr.current=null),Kr.current?.promise===Zt&&(Kr.current=null),!K&&vt.current===De&&Se(d)&&jo(Fe)}},[Xr,Al,ye.size,jo,Fl,_n,Se,Tl,x,Ro,Pl]),fs=a.useCallback(async()=>{x&&await Jt(x,{reloadDiff:!0,refresh:!0})},[Jt,x]),$o=a.useCallback(async(r=x??void 0)=>{if(!r)return null;const o=x,d=pn.current+1;pn.current=d,Vr.current?.abort(),kt("right-sidebar-git-details");const v=new AbortController;Vr.current=v,qs(!0);try{const w=await Jc(r,v.signal,"load_git_details","right-sidebar-git-details");return pn.current!==d||!Se(o)?null:(Ne(R=>R.map(P=>P.root===w.root?{...P,available:w.available,context:w,error:w.error}:P)),Q(R=>R?.root&&w.root&&R.root!==w.root?R:!R?.available||!w.available?w:{...R,...w}),w)}catch(w){return Ar(w)||!Se(o)||pn.current===d&>(w instanceof Error?w.message:"Failed to load Git details"),null}finally{Vr.current===v&&(Vr.current=null),pn.current===d&&Se(o)&&qs(!1)}},[Se,x]);a.useEffect(()=>{if(!t){vt.current+=1,ra(),Eo.current=null,pn.current+=1,sa.current+=1,Nr.current?.abort(),kt(Xn(Kr.current?.cwd??x??void 0)),Kr.current=null,Nr.current=null,Vr.current?.abort(),kt("right-sidebar-git-details"),Vr.current=null;for(const r of Ut.current.values())r.abort();for(const r of Ut.current.keys())kt(`right-sidebar-git-untracked:${r}`);Ut.current.clear(),Ot.current.clear(),Un.current+=1,Yr.current?.abort(),Yr.current=null,Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,qs(!1),se(!1),Ue(null),Be(null),tt(null),nr(null),Mn(!1),sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1),q(""),G(!1),mt(null),go(!1),hl(!1),ee&&fl(!1)}},[ee,t,ra,G]),a.useEffect(()=>{if(!ue)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[ue]),a.useEffect(()=>{ee||Rr(!1)},[ee]);const hs=a.useCallback(r=>{mo(r);const o=ia.current;o&&(o.update(),o.slideTo(r,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(r,0)}))},[]);a.useEffect(()=>{if(ee)if(Rr(g),g&&Je){Cr(1);const r=Mr.current;r&&(r.update(),r.activeIndex!==1&&(us.current=1,r.slideTo(1,0)))}else{Cr(0);const r=Mr.current;r&&r.activeIndex!==0&&(us.current=0,r.slideTo(0,0)),mt(null)}},[ee,g,x,Je]),a.useEffect(()=>{if(b!==void 0&&!g){Cr(0);const r=Mr.current;r&&r.activeIndex!==0&&(us.current=0,r.slideTo(0,0)),Rr(!1),mt(null)}},[b,g]),a.useEffect(()=>{C!==void 0&&Le(null)},[C]),a.useEffect(()=>{!ee&&g&&S?.()},[ee,S,g]),a.useEffect(()=>{yo(r=>Di(r,s))},[s]);const Tf=a.useCallback(r=>{ee||(r.preventDefault(),oa.current={startX:r.clientX,startWidth:vo,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[vo,ee]),If=a.useCallback(r=>{const o=oa.current;if(!o||o.pointerId!==r.pointerId)return;const d=Di(o.startWidth+r.clientX-o.startX,s);yo(d),Cs(js,d,xg)},[s]),Ul=a.useCallback(r=>{const o=oa.current;if(!(!o||o.pointerId!==r.pointerId)){oa.current=null,ws(js);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),Hn=!!(x&&_n!==null&&zd(k)),Lo=!!(x&&!hn&&ye.size===0&&_n===null),lr=(()=>{let r=wo;return r==="android"&&!Wr&&(r="files"),Hn&&(r==="git"||r==="diff")&&(r="files"),r})(),Ze=lr==="git",zn=lr==="files",yt=lr==="diff",Ao=lr==="android";a.useEffect(()=>{if(!ee){Gs(!0);return}if(!t){const o=window.setTimeout(()=>{Gs(!1)},wg);return()=>window.clearTimeout(o)}Gs(!1);const r=window.setTimeout(()=>{Gs(!0)},yg);return()=>window.clearTimeout(r)},[ee,t]),a.useEffect(()=>{if(!ee||!yt)return;const r=ia.current;if(!r)return;const o=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(o)},[yt,ee]),a.useEffect(()=>{if(!Hn||!x||qr)return;const r=window.setTimeout(()=>{Jt(x,{background:!0})},3e3);return()=>window.clearTimeout(r)},[Hn,x,qr,Jt]);const Df=a.useCallback(r=>{Jt(r,{discoverOnly:!0})},[Jt]);Zm({active:t&&(Ze||yt),rootPath:x,loading:qr,delay:Ze&&!ee?0:li,lastStartedRoot:Eo,load:Df}),a.useEffect(()=>{!t||!Ze||(!ee||po)&&go(!0)},[Ze,ee,t,po]),a.useEffect(()=>{if(!t||Ze)return;const r=window.setTimeout(()=>{go(!0)},li);return()=>window.clearTimeout(r)},[Ze,t]),a.useEffect(()=>{yt&&fl(!0)},[yt]),a.useEffect(()=>{Ao&&hl(!0)},[Ao]),a.useEffect(()=>{let r=!1;return Gd().then(o=>{!r&&o.androidPanel&&ml(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{r=!0}},[]);const _f=a.useCallback(r=>{ml(r),r?Yt("android"):Z.getState().rightTab==="android"&&Yt("files"),qd({androidPanel:{enabled:r}}).catch(()=>{})},[Yt]),Hl=a.useCallback(r=>{me&&vb(me,r.currentTarget.scrollTop)},[me]);a.useEffect(()=>()=>{Nr.current?.abort(),ws(Ki),ws(Vi),ws(js),ws(ii)},[]),a.useEffect(()=>{if(!me||!_l)return;const r=df()[me]?.top;if(typeof r!="number")return;let o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r),o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(o)},[me,_l]),a.useEffect(()=>{if(!t)return;const r=new AbortController;return zh(r.signal).then(o=>wl(!!o.available)).catch(()=>wl(!1)),()=>r.abort()},[t]);const ms=a.useCallback(r=>{if(ne(null),Qe(r),mt(null),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Qe]),zl=a.useCallback((r,o)=>{if(ne(null),Qe(r),Lt(o),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Qe]),ps=a.useCallback(async(r,o)=>{const d=o||In||x;if(!(!d||r.length===0)){Qs(!0);try{await ti(d,r),ta(d,!1)}catch(v){gt(v instanceof Error?v.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>gt(null),4e3)}finally{Qs(!1)}}},[In,x,ta,i]),Wl=a.useCallback(async r=>{try{await Wh(r)}catch(o){gt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>gt(null),4e3)}},[i]),ca=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&xo(!0)},[]),Gl=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),xo(!1)},[]),ql=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),xo(!1);const o=r.dataTransfer.files;o.length>0&&ps(Array.from(o))},[ps]),Po=a.useCallback(r=>{at(r),window.setTimeout(()=>at(o=>o===r?null:o),1400)},[]),Er=a.useCallback(r=>{qt(r),window.setTimeout(()=>qt(o=>o===r?null:o),1400)},[]);a.useEffect(()=>{St(vd,lt)},[lt]),a.useEffect(()=>{St(yd,Pr)},[Pr]),a.useEffect(()=>{St(wd,z)},[z]),a.useEffect(()=>{Cs(ii,be,hg)},[be]),a.useEffect(()=>(Rl().catch(()=>{}),Qc(r=>{r.type==="pinned-explorer-roots"&&Cl(r.pinnedExplorerRoots)})),[Rl,Cl]);const Kl=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),da=a.useRef(null),bn=a.useRef(null),[Vl,To]=a.useState(!1);a.useEffect(()=>{if(!t)return;To(!1);let r=!1;Gh().then(d=>{r||(da.current=d.text,ze(v=>d.text&&d.text!==v?d.text:v),To(!0))}).catch(()=>{r||To(!0)});const o=Qc(d=>{d.type==="context-draft"&&d.origin!==Kl.current&&(da.current=d.text,ze(d.text))});return()=>{r=!0,o(),bn.current!==null&&(window.clearTimeout(bn.current),bn.current=null)}},[t]),a.useEffect(()=>{if(!Vl||da.current===be)return;bn.current!==null&&window.clearTimeout(bn.current);const r=be;bn.current=window.setTimeout(()=>{bn.current=null,qh(r,Kl.current).then(()=>{da.current=r}).catch(()=>{})},500)},[be,Vl]);const Wn=a.useCallback((r,o,d)=>{if(r){if(Kh(d?r+d:r)){Po(o);return}lt?(ze(v=>Sp(v,r)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(Dt(!1),dr(v=>v+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?r+d:r,focus:!0}})),Po(o)}},[lt,Po]),ua=a.useCallback(r=>{const o=La(r,x);return mm(o,x)},[x]),Io=iu(Er),Jr=a.useCallback((r,o)=>{const d=La(r,x);Wn(pm(d,x),o??`path:${d}`)},[x,Wn]),Ff=a.useCallback(async r=>{Qs(!0);try{await gm(r,ti,o=>{Jr(o,`path:${o}`)}),ee&&!lt&&l()}catch(o){gt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>gt(null),4e3)}finally{Qs(!1)}},[lt,Jr,ee,l,i]),$r=a.useCallback((r,o)=>{if(!r)return;const d=r.includes(`
|
|
1659
|
+
`})(),yr=`path:${Oe}`,wr=E?`path:${Oe}:${E.start}-${E.end}`:yr,_r=$===yr,Fr=$===wr,Cn=T===yr,ts=T===wr,rn=Fr||ts,Kt=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,Br=A=>{const W=te.current;if(!W)return;const se=W.getBoundingClientRect(),ke=A.currentTarget.getBoundingClientRect(),Ue=A.clientX||ke.left+ke.width/2,Be=(A.clientY||ke.top+ke.height/2)-se.top+W.scrollTop,We=g?116:132,tt=W.scrollLeft+Math.max(8,W.clientWidth-We),Nt=Math.min(Math.max(8,Ue-se.left+W.scrollLeft+10),tt);ge({top:Be,left:Nt})},rs=(A,W)=>{Gi()||(Br(A),N(se=>{const ke=Wi(se,W,W);return ke||ge(null),ke}))},ns=(A,W,se)=>{Br(A),N(ke=>{const Ue=Wi(ke,W,se);return Ue||ge(null),Ue})},kr=(A,W,se,ke)=>{ke==="end"&&Br(A),N({start:W,end:se})},tr=A=>{const{scrollTop:W,scrollLeft:se}=A.currentTarget;k(W),hi(i,n,{top:W,left:se,markdownTop:W})},Pe=A=>{if(A.directory){m?.(A.path);return}if(A.path===Oe||j.kind==="text"&&A.path===j.sourcePath){A.fragment&&jn(A.fragment);return}ae(W=>[...W,Oe]),Ke.current=A.path,je(A.fragment),N(null),O(A.path)},rr=()=>{const A=Q[Q.length-1];A&&(ae(W=>W.slice(0,-1)),Ke.current=A,je(null),N(null),O(A))},nn=A=>{const{scrollTop:W,scrollLeft:se}=A.currentTarget;hi(i,n,{top:W,left:se})},Nn=()=>{if(t){t(Dr,wr);return}E&&l(Dr,wr)},ss=async()=>{if(!(!Oe||Le.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){we({status:"pending"});try{await em(Oe),we({status:"idle"})}catch(A){we({status:"error",message:A instanceof Error?A.message:p("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[be.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Ft||vr)?"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:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p("rightSidebar.backToFileList"),title:p("rightSidebar.backToFileList"),children:e.jsx(Zd,{size:16})}),Q.length>0&&e.jsxs("button",{type:"button",onClick:rr,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 ${g?"w-9":"px-2.5"}`,"aria-label":p("rightSidebar.backToPreviousPreview"),title:p("rightSidebar.backToPreviousPreview"),children:[e.jsx($s,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:p("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Oe,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Tr&&e.jsx("button",{type:"button",onClick:at?mr:Rn,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 ${at?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":p("rightSidebar.findInFile"),title:`${p("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Jn,{size:14})}),xr&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&y?.(),$e(A=>{const W=A==="preview"?"source":"preview";return St(xu,W),W}),N(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 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?he==="preview"?e.jsx(Ei,{size:14}):e.jsx(Mi,{size:14}):p(he==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),Bs&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{J(A=>{const W=A==="preview"?"source":"preview";return Cp(i,n,W),W}),N(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 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?M==="preview"?e.jsx(Ei,{size:14}):e.jsx(Mi,{size:14}):p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),vr&&e.jsx("button",{type:"button",onClick:()=>{fe.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":p(Re?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:p(Re?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(eu,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Oe,yr),...be(pr,yr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${_r||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:p("rightSidebar.insertReference",{reference:pr}),children:p(Cn?"rightSidebar.copied":_r?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(pr)},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:p("rightSidebar.copyReference",{reference:pr}),"aria-label":p("rightSidebar.copyFileRef"),children:e.jsx(Bh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{ss()},disabled:Le.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Le.status==="error"?Le.message??p("rightSidebar.downloadFailed"):p("rightSidebar.downloadFile"),"aria-label":p("rightSidebar.downloadFile"),children:Le.status==="pending"?e.jsx(jt,{size:13,className:"animate-spin"}):e.jsx(fm,{size:14})})]})]}),at&&Tr&&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(Jn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:re,type:"search",value:qt,onChange:A=>lt(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),mt(A.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:p("rightSidebar.findInFilePlaceholder"),"aria-label":p("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ct.length>0?`${Dt+1}/${ct.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>mt(-1),disabled:ct.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":p("rightSidebar.previousSearchMatch"),title:`${p("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Xd,{size:13})}),e.jsx("button",{type:"button",onClick:()=>mt(1),disabled:ct.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":p("rightSidebar.nextSearchMatch"),title:`${p("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(hm,{size:13})}),e.jsx("button",{type:"button",onClick:mr,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":p("rightSidebar.closeFileSearch"),title:`${p("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Gt,{size:13})})]}),br&&!(g&&(Ft||vr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[br.size!==null&&e.jsx("span",{children:p("rightSidebar.byteCount",{count:br.size.toLocaleString()})}),"truncated"in br&&br.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:p("rightSidebar.previewTruncated")}),"mimeType"in br&&e.jsx("span",{children:br.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(g&&(Ft||vr))&&!oo&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:tn?p("rightSidebar.edaPickHint"):Fs?p("rightSidebar.csvTablePreview"):At||Zn?p("rightSidebar.kicadProjectPickHint"):Ct?p("rightSidebar.videoPreviewHint"):Os?p("rightSidebar.imagePreviewHint"):Ft?E?p("rightSidebar.selectedLineHint",{lineLabel:Kt??""}):p("rightSidebar.markdownPreviewHint"):vr?p("rightSidebar.htmlPreviewHint"):E?p("rightSidebar.selectedLineHint",{lineLabel:Kt??""}):p("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?p("rightSidebar.edaLoading"):j.mode==="image"?p("rightSidebar.loadingImage"):j.mode==="model3d"?p("rightSidebar.model3dLoading"):j.mode==="video"?p("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:p("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:p("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(hu,{blobUrl:j.objectUrl,filePath:Oe,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(yf,{src:j.objectUrl,alt:Lt.name,vector:!1,onLoad:A=>{const W=A.currentTarget;q(se=>se.kind==="image"?{...se,dimensions:{width:W.naturalWidth,height:W.naturalHeight}}:se)},onError:()=>q({kind:"error",message:p("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(Fp,{url:j.url,onLoadError:()=>q({kind:"error",message:p("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Gp,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Oe.toLowerCase().endsWith(".kicad_pcb"),onViewChange:ne,onInsertAnnotation:t??u,onRefresh:Sn,interactive3d:ue?e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Rd,{blobUrl:ue.objectUrl,ext:".glb",fileName:Lt.name,filePath:ue.sourcePath,features:null,onInsertFeature:t??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:A=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(A)?A:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Rd,{blobUrl:j.objectUrl,ext:j.ext,fileName:Lt.name,filePath:j.sourcePath,features:L,onInsertFeature:t??u,onRefresh:Sn})})}):j.kind==="text"&&Fs?e.jsx(Vp,{content:j.content,filePath:Oe,onInsertAnnotation:t??u},Oe):j.kind==="text"&&(At||Zn)?e.jsx(Jp,{content:j.content,filePath:Oe,localState:Zn,onInsertAnnotation:t??u},Oe):Ft?e.jsxs("div",{ref:te,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:tr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(cf,{content:j.content,filePath:j.sourcePath,rootPath:i,lineRange:E,onLineRangeClick:ns,onLineRangeDrag:kr,scrollTop:xe,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:S,onOutlineClose:y,lightboxOpen:C,lightboxCloseSignal:I,onLightboxOpen:F,onLightboxClose:B,onLocalLinkOpen:Pe}),E&&oe&&e.jsxs("button",{type:"button",onClick:Nn,...be(Dr,wr),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Od(g,rn),title:`Insert markdown reference: ${Ir}`,children:[e.jsx(Va,{size:g?13:11}),ts?p("rightSidebar.copied"):Fr?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Kt??""})]})]}):vr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ag,{ref:fe,src:Oh(Oe),title:`${Lt.name} preview`,exitFullscreenLabel:p("rightSidebar.htmlFullscreenExit"),onFullscreenChange:qe},`${Oe}:${dr}:${fr}`)}):j.kind==="text"?e.jsxs("div",{ref:te,onScroll:nn,className:`${Xi} 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:[gr.length>0?e.jsx("div",{className:"min-w-full",children:gr.map((A,W)=>{const se=W+1,ke=!!(E&&se>=E.start&&se<=E.end),Ue=Ae&&Ae.length===gr.length?Ae[W]:null;return e.jsxs("div",{ref:Te=>{Te?V.current.set(se,Te):V.current.delete(se)},role:"button","data-file-preview-line":se,tabIndex:0,onClick:Te=>rs(Te,se),onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),rs(Te,se))},style:{gridTemplateColumns:`${_s}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${ke?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${pr}:${se}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${ke?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:se}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ue??(A||" ")})]},W)})}):"Empty file.",E&&oe&&e.jsxs("button",{type:"button",onClick:Nn,...be(Dr,wr),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Od(g,rn),title:`Insert code reference: ${Ir}`,children:[e.jsx(Va,{size:g?13:11}),ts?p("rightSidebar.copied"):Fr?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Kt??""})]})]}):null]})}function Hb({isOpen:t,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h=!1,onTogglePinned:m,rightSidebarFilePreviewOpen:g=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:S,rightSidebarRepoPickerOpen:y=!1,rightSidebarRepoPickerCloseSignal:C,onOpenRightSidebarRepoPicker:I,onCloseRightSidebarRepoPicker:F,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p}){const{t:i,locale:O}=Rt(),[j,q]=a.useState(""),[le,ne]=a.useState(null),ue=Z(r=>r.rightSearchOpen),G=Z(r=>r.setRightSearchOpen),Y=Z(r=>r.rightSidebarLayoutPreference),L=Z(r=>r.setRightSidebarLayoutPreference),[_,V]=a.useState(()=>Tg()),[te,oe]=a.useState("."),[ge,he]=a.useState(""),[$e,M]=a.useState(!1),[J,fe]=a.useState(!1),[Re,qe]=a.useState(!1),[Ce,ce]=a.useState(!1),xe=a.useDeferredValue(j),[k,Q]=a.useState(null),[ae,Ne]=a.useState([]),[je,Ke]=a.useState([]),[de,Ae]=a.useState(null),[st,Le]=a.useState(null),[we,at]=a.useState(null),[et,qt]=a.useState(null),[lt,ct]=a.useState(()=>ot(yd,Rs)??!1),[Pr,Dt]=a.useState(()=>ot(wd,Rs)??!1),[z,re]=a.useState(()=>ot(kd,Rs)??!1),[be,ze]=a.useState(()=>ot(ii,Eg)??""),[ut,dr]=a.useState(0),[ur,_t]=a.useState(!1),[fr,hr]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Tr,mr]=a.useState(!1),[Rn,mt]=a.useState(null),[Oe,Lt]=a.useState(null),[pr,gr]=a.useState(()=>Md(ai)),[_s,br]=a.useState(()=>Md(vd)),[xr,Fs]=a.useState(()=>Mg()),[At,Zn]=a.useState(()=>$g()),[Ft,Bs]=a.useState(()=>Ag()),vr="words",[Os,oo]=a.useState(0),[Ct,tn]=a.useState([]),[es,Ir]=a.useState([]),[Dr,yr]=a.useState(!1),[wr,_r]=a.useState(null),[Fr,Cn]=a.useState([]),[ts,rn]=a.useState(!1),[Kt,Br]=a.useState([]),[rs,ns]=a.useState([]),[kr,tr]=a.useState(!1),[Pe,rr]=a.useState(null),[nn,Nn]=a.useState([]),[ss,A]=a.useState({}),[W,se]=a.useState(!1),[ke,Ue]=a.useState(null),[Te,Be]=a.useState(null),[We,tt]=a.useState(null),[Nt,nr]=a.useState(null),[Vt,Mn]=a.useState(!1),[as,sn]=a.useState(""),Or=a.useDeferredValue(as),[Sr,io]=a.useState({}),[an,X]=a.useState([]),[He,Pt]=a.useState(!1),[Ur,os]=a.useState(!1),[ol,En]=a.useState(null),[lo,$n]=a.useState(!1),sr=a.useRef(null),Hr=a.useRef(0),il=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[wf,Us]=a.useState(null),[is,ll]=a.useState(()=>ot(oi,Rs)??!1),[co,uo]=a.useState(!1),[Hs,fo]=a.useState([]),[jr,zs]=a.useState({}),[Mt,Ws]=a.useState({}),[zr,cl]=a.useState(!0),[dl,ul]=a.useState(()=>new Set),[rt,on]=a.useState(null),[ho,ln]=a.useState(null),[kf,Rr]=a.useState(!1),[fl,Cr]=a.useState(0),[,mo]=a.useState(0),[po,Gs]=a.useState(!1),[ar,go]=a.useState(!1),[Sf,hl]=a.useState(()=>Z.getState().rightTab==="diff"),[jf,ml]=a.useState(()=>Z.getState().rightTab==="android"),[Wr,pl]=a.useState(!1),Rf=Yc(r=>!!r.docks[sd]),[Ie,ls]=a.useState(null),[Ln,cs]=a.useState(null),[pt,Gr]=a.useState(null),[gl,gt]=a.useState(null),[An,bl]=a.useState(null),[bo,Cf]=a.useState(()=>Date.now()),[Nf,Mf]=a.useState(!1),[cn,qs]=a.useState(!1),[Ks,xl]=a.useState(""),[Pn,Vs]=a.useState(""),[dn,Ys]=a.useState(""),[un,Xs]=a.useState(""),[vl,Tn]=a.useState(null),[Js,Qs]=a.useState(!1),[yl,xo]=a.useState(!1),[wl,kl]=a.useState(!1),[Zs,Ef]=a.useState({key:null,nonce:0}),Sl=a.useRef(null),jl=a.useRef(null),ee=tm(s,h,Y),$f=Eu(ee,h,Ft),[vo,yo]=a.useState(()=>Hg(s)),wo=Z(r=>r.rightTab),Yt=Z(r=>r.setRightTab),x=Z(r=>r.rootPath),In=Z(r=>r.explorerRoot),Rl=Z(r=>r.pinnedExplorerRootsCache),Cl=Z(r=>r.hydratePinnedExplorerRoots),Nl=Z(r=>r.syncPinnedExplorerRoots),Bt=Z(r=>r.setExplorerRoot),Ml=Z(r=>r.resetExplorerToProject),Dn=Z(r=>r.pinExplorerRoot),fn=Z(r=>r.unpinExplorerRoot),Je=Z(r=>r.selectedFilePath),Qe=Z(r=>r.selectFile),ko=Z(r=>r.showHiddenFiles),Lf=Z(r=>r.toggleShowHiddenFiles),So=Z(r=>!!(x&&r.nestedGitScanRoots[x])),ye=Z(r=>r.changedFiles),ea=Z(r=>r.setChangedFiles),ta=Z(r=>r.invalidateDirectoryCache),Af=Z(r=>r.setDirectorySortMode),El=Z(r=>r.applyFileWatchEvents),$l=Z(r=>r.reconcileDirectoryCache),Ll=Z(r=>r.bumpFileWatchEpoch),qr=Z(r=>r.gitBundleLoading),Al=Z(r=>r.gitBundleSlow),hn=Z(r=>r.gitBundleError),_n=Z(r=>r.gitBundleLastLoadedAt),Pl=Z(r=>r.beginGitBundleLoading),Tl=Z(r=>r.setGitBundleSlowFor),jo=Z(r=>r.finishGitBundleLoading),ra=Z(r=>r.resetGitBundleLoading),Ro=Z(r=>r.setGitBundleError),Il=Z(r=>r.markGitBundleLoaded),me=In??x,Dl=a.useMemo(()=>me?dg(me,te):"",[me,te]),ds=a.useMemo(()=>cg(ge),[ge]),_l=a.useMemo(()=>({excludePatterns:ds,caseSensitive:J,wholeWord:Re,regex:Ce}),[J,ds,Ce,Re]),na=Z(r=>me?r.fileSortModes[me]??"name":"name"),Fl=Z(r=>!!(me&&r.directoryCache.has(me))),Fn=a.useRef(null),vt=a.useRef(0),[Bl]=a.useState(()=>++Db),Nr=a.useRef(null),Kr=a.useRef(null),sa=a.useRef(0),Ot=a.useRef(new Map),Ut=a.useRef(new Map),or=a.useRef(new Set),mn=a.useRef(new Set),pn=a.useRef(0),Vr=a.useRef(null),Bn=a.useRef(0),On=a.useRef(null),Un=a.useRef(0),Yr=a.useRef(null),Co=a.useRef(new Set),No=a.useRef(null),Mo=a.useRef(null),aa=a.useRef(null),Eo=a.useRef(null);a.useEffect(()=>{if(An===null)return;const r=Math.max(0,Date.now()-An),o=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,d=Math.max(50,o-r%o),v=window.setTimeout(()=>Cf(Date.now()),d);return()=>window.clearTimeout(v)},[bo,An]);const oa=a.useRef(null),Mr=a.useRef(null),ia=a.useRef(null),us=a.useRef(null),Se=a.useCallback(r=>Z.getState().rootPath===r,[]);a.useEffect(()=>{if(!t||typeof window>"u")return;const r=o=>{const d=Ob(o.target);d&&za("global_change_row_event",{...Ub(o),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:Z.getState().selectedFilePath,rightTab:Z.getState().rightTab,activeGitRepoRoot:de,changedFiles:Z.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[de,t]);const Ol=a.useCallback(async(r=x??void 0)=>{if(!r)return null;if(or.current.has(r)||mn.current.has(r))return nt("untracked_skip_cached",{cwd:r,rootPath:x,completed:or.current.has(r),running:mn.current.has(r)}),null;const o=x,d=sa.current+1;sa.current=d,Ot.current.set(r,d);const v=`right-sidebar-git-untracked:${r}`,w=new AbortController;Ut.current.set(r,w),mn.current.add(r),nt("untracked_start",{requestId:d,cwd:r,rootPath:x});try{let R=await Xc(r,w.signal,v),P=0;for(;R.status==="running"&&P<120;){if(Ot.current.get(r)!==d||w.signal.aborted)return nt("untracked_stale_result",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,status:R.status}),null;if(!Se(o))return nt("untracked_root_changed",{requestId:d,cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath}),null;await new Promise(K=>window.setTimeout(K,P<10?1e3:3e3)),P+=1,R=await Xc(r,w.signal,v)}if(Ot.current.get(r)!==d||!Se(o))return nt("untracked_stale_result",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath,files:R.files.length,status:R.status}),null;if(R.status==="done")return ea(hf(Z.getState().changedFiles,R.files)),R.files.length>0&&Ne(K=>{const Ge=new Map(K.map(Ee=>[Ee.root,Ee])).get(r);if(!Ge)return K;const De=jb(Ge.files,R.files),Fe=K.map(Ee=>Ee.root===r?{...Ee,files:De,context:Ee.context?{...Ee.context,changedFiles:De.map(Ye=>({path:Ye.path,absolutePath:Ye.absolutePath,status:Ye.status})),truncated:!1}:Ee.context,untrackedDeferred:!1}:Ee);Ke(mf(Fe,x));const pe=Fe.find(Ee=>Ee.root===x);return pe?.context&&Q(Ee=>Ee?.root===pe.root?{...Ee,...pe.context}:Ee),Fe}),or.current.add(r),nt("untracked_apply",{requestId:d,cwd:r,files:R.files.length}),R;const H=R.error||(R.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return or.current.add(r),nt("untracked_error",{requestId:d,cwd:r,message:H,code:R.code,status:R.status}),null}catch(R){if(Ot.current.get(r)!==d||!Se(o)||Ar(R))return nt("untracked_aborted",{requestId:d,activeRequestId:Ot.current.get(r),cwd:r,expectedRootPath:o,currentRootPath:Z.getState().rootPath,message:R instanceof Error?R.message:String(R)}),null;const P=R instanceof Error?R.message:"Failed to scan untracked files";return or.current.add(r),nt("untracked_error",{requestId:d,cwd:r,message:P}),null}finally{Ut.current.get(r)===w&&Ut.current.delete(r),Ot.current.get(r)===d&&Ot.current.delete(r),mn.current.delete(r)}},[k,Se,x,ea]),Xt=a.useMemo(()=>{const r=new Set(je.map(d=>d.root)),o=Fr.filter(d=>r.has(d));return o.length>0?o:de?[de]:[]},[de,Fr,je]),Ul=Xt.length===0,gn=a.useMemo(()=>Xt.map(r=>ae.find(o=>o.root===r)).filter(r=>!!r),[Xt,ae]),Pf=a.useMemo(()=>je.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[je]),ir=a.useCallback(async()=>{if(!x){tn([]),Ir([]);return}const r=x,o=Bn.current+1;Bn.current=o,On.current?.abort();const d=new AbortController;On.current=d,yr(Ct.length===0),_r(null);try{const v=Xt.length>0?await Promise.all(Xt.map(w=>Jc({workspaceRoot:x,repoRoot:w},d.signal))).then(w=>({records:w.flatMap(R=>R.records),walkthroughs:w.flatMap(R=>R.walkthroughs??[])})):await Jc({workspaceRoot:x},d.signal);if(Bn.current!==o||!Se(r))return;tn(v.records),Ir(v.walkthroughs??[])}catch(v){if(Bn.current!==o||!Se(r)||Ar(v))return;_r(v instanceof Error?v.message:"Failed to load change audit explanations")}finally{On.current===d&&(On.current=null),Bn.current===o&&Se(r)&&yr(!1)}},[Ct.length,Xt,Se,x]),la=a.useCallback(async(r,o,d)=>{if(!r&&!x){Br([]),ns([]);return}const v=x,w=Un.current+1;Un.current=w,Yr.current?.abort();const R=new AbortController;Yr.current=R;try{const P=r?[r]:Array.from(new Set([x,...ae.map(K=>K.root)].filter(K=>!!K))),H=await Promise.all(P.map(K=>Hh({repoRoot:K,baseRef:o,branchName:d},R.signal))).then(K=>{const Me=new Map,Ge=new Map;for(const De of K){for(const Fe of De.records)Me.set(Fe.id,Fe);for(const Fe of De.walkthroughs??[])Ge.set(Fe.id,Fe)}return{records:Array.from(Me.values()),walkthroughs:Array.from(Ge.values())}});if(Un.current!==w||!Se(v))return;Br(H.records),ns(H.walkthroughs??[])}catch(P){if(Un.current!==w||!Se(v)||Ar(P))return;console.warn("[RightSidebar] Failed to load branch explanations",P)}finally{Yr.current===R&&(Yr.current=null)}},[ae,Se,x]),Xr=a.useCallback((r,o={})=>{if(!Se(x)){nt("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:Z.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}nt(r.files.length===0?"empty_bundle":"apply",{rootPath:x,available:r.available,files:r.files.length,repositories:r.repositories?.map(pe=>({root:pe.root,relativeRoot:pe.relativeRoot,files:pe.files.length,available:pe.available,error:pe.error})),repoFilters:r.repoFilters?.map(pe=>({root:pe.root,label:pe.label,count:pe.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let d=$u(r),v=r.repoFilters??[],w=r.files;const R=Z.getState().changedFiles;if(!!(o.cacheOnly&&!r.cached&&r.files.length===0&&d.length===0)&&(R.size>0||ae.length>0||k)){nt("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:R.size,currentRepositories:ae.length});return}const H=d.some(pe=>pe.deferred);if(H&&!o.replaceWorkspace){const pe=new Set(d.filter(Ye=>!Ye.deferred||Ye.root===x).map(Ye=>Ye.root));w=[...Array.from(R.values()).filter(Ye=>!pe.has(ht(Ye,x)??"")),...r.files]}const K=Ud(R.values(),x),Me=Ud(r.files,x),Ge=d.some(pe=>pe.root!==x);if(!!(o.background&&!H&&!o.replaceWorkspace&&R.size>0&&(r.files.length===0&&!r.error||K>0&&Me===0&&!Ge))){nt("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:R.size,nextFiles:r.files.length,currentNestedCount:K,nextNestedCount:Me,nextRepositories:d.map(pe=>({root:pe.root,relativeRoot:pe.relativeRoot,files:pe.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(o.replaceRepoRoot){const pe=pf(R.values(),ae,r,o.replaceRepoRoot,x);w=pe.files,d=pe.repositories,v=pe.repoFilters}if(ea(ff(w)),Ne(d),Ke(v),o.syncActiveRepo!==!1){const pe=o.activeRepoRoot!==void 0?o.activeRepoRoot:de??Nd(x),Ee=Dg({...r,repositories:d,repoFilters:v},pe);Ae(Ee),ci(x,Ee)}typeof r.cacheUpdatedAt=="number"&&bl(r.cacheUpdatedAt),Q(pe=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==x)return pe;if(!r.context)return null;const Ee=pe?.root??x;return!pe?.available||Ee!==(r.context.root??x)?r.context:{...pe,...r.context}}),o.reloadDiff&&oo(pe=>pe+1);const Fe=Z.getState().selectedFilePath;if(Fe&&!Fe.startsWith("/")&&!w.some(pe=>pe.path===Fe||pe.absolutePath===Fe)&&Qe(null),gr(pe=>{const Ee=new Set(w.map(Zt=>ht(Zt,x)).filter(Boolean)),Ye=new Set;for(const Zt of pe)Ee.has(Zt)&&Ye.add(Zt);return di(ai,Ye),Ye}),o.loadDeferred!==!1){const pe=d.filter(Ee=>Ee.untrackedDeferred&&Ee.root).map(Ee=>Ee.root);for(const Ee of pe)Ol(Ee)}o.loadAudit!==!1&&ir()},[de,Se,ir,Ol,x,Qe,ea]);a.useEffect(()=>{ra(),No.current=null,Mo.current=x;const r=[],o=[],v=Nd(x);vt.current+=1,pn.current+=1,sa.current+=1,Nr.current?.abort(),kt(Xn(Kr.current?.cwd??x??void 0)),Kr.current=null,Nr.current=null,Vr.current?.abort(),kt("right-sidebar-git-details"),Vr.current=null;for(const K of Ut.current.values())K.abort();for(const K of Ut.current.keys())kt(`right-sidebar-git-untracked:${K}`);Ut.current.clear(),Ot.current.clear(),Bn.current+=1,On.current?.abort(),On.current=null,Un.current+=1,Yr.current?.abort(),Yr.current=null,Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,tn([]),Ir([]),yr(!1),_r(null),Cn([]),rn(!1),Br([]),ns([]),tr(!1),rr(null),se(!1),Ue(null),Be(null),tt(null),nr(null),Mn(!1),sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1),Us(null),on(null),ln(null),ll(!1),St(oi,!1),uo(!1);const w=x?Ed()[x]:null,R=w?.previewEntries??[],P=w?.selectedPreviewKey??null,H=P?R.find(K=>K.key===P)??null:null;fo(w?.selectedRepoRoots??[]),zs(w?.repoTargetBranches??{}),Ws(w?.repoBaseBranches??{}),Nn(R),A(w?.previewScrollTops??{}),H&&w?.previewDetailOpen&&(H.diff.hunks?.length??0)>0&&(rr(H.diff),on(H.key),ln(w.selectedPreviewFileKey??(H.diff.hunks?.[0]?`${H.diff.hunks[0].filePath}\0${H.diff.hunks[0].hunkHeader}\0${H.diff.hunks[0].hunkIndex}`:null)),tr(!0)),cl(w?.includeUncommitted??!0),No.current=x,qs(!1),Ae(v??null),or.current.clear(),mn.current.clear(),ls(null),cs(null),Gr(null),gt(null),bl(null),Ne(r),Ke(o),Q(null),Eo.current=null},[ra,x]);const Jt=a.useCallback(async(r=x??void 0,o={})=>{if(!r)return null;const d=x,v=vt.current;if(await Qm(Z.getState().hydrateNestedGitScanRoots),vt.current!==v||!Se(d))return null;const w=r===x&&Vn(x),R=o.includeNested??w,P=o.refresh??o.reloadDiff??!1,H=o.cacheOnly??!1,K=o.background??!1,Me=R&&(o.discoverOnly??!1);P&&or.current.clear();const Ge=Kr.current;if(Ge&&Ge.cwd===r&&Ge.includeNested===R&&Ge.refresh===P&&Ge.cacheOnly===H&&Ge.discoverOnly===Me)return nt("reuse_pending",{cwd:r,includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me}),Ge.promise;const De=vt.current+1;vt.current=De;const Fe=`right-sidebar:${Bl}:${De}`;Nr.current?.abort();const pe=Xn(r);kt(pe);const Ee=new AbortController;Nr.current=Ee;let Ye=null;K||Pl(Fe),Ro(null),nt("start",{requestId:De,cwd:r,rootPath:x,requestSlotId:pe,includeNested:R,refresh:P,cacheOnly:H,background:K,existingChanges:ye.size,lastLoadedAt:_n}),!K&&typeof window<"u"&&(Ye=window.setTimeout(()=>{vt.current===De&&Tl(Fe,!0)},vg));const Zt=(async()=>{const _e=await Ea(r,Ee.signal,{includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me,action:P?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:pe,requestTimeoutMs:P?null:void 0});if(Nb(_e)){if(nt("cancelled_result_ignored",{requestId:De,activeRequestId:vt.current,cwd:r,error:_e.error??_e.context?.error}),Ee.signal.aborted)return null;throw new Error(_e.error??_e.context?.error??"Failed to load Git changes")}return vt.current!==De||!Se(d)?(nt("stale_result",{requestId:De,activeRequestId:vt.current,cwd:r,expectedRootPath:d,currentRootPath:Z.getState().rootPath,files:_e.files.length,repositories:_e.repositories?.length??0}),null):(Xr(_e,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:R,background:K,cacheOnly:H,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),_e)})();Kr.current={cwd:r,includeNested:R,refresh:P,cacheOnly:H,discoverOnly:Me,promise:Zt};try{const _e=await Zt;return vt.current===De&&_e&&Se(d)?Il({cached:_e.cached,stale:_e.stale,cacheAgeMs:_e.cacheAgeMs,nestedDeferred:!R||_e.nestedDeferred,untrackedDeferred:_e.untrackedDeferred}):vt.current===De&&Se(d)&&jo(Fe),_e}catch(_e){return vt.current!==De||!Se(d)||Ee.signal.aborted?(nt("aborted",{requestId:De,activeRequestId:vt.current,cwd:r,expectedRootPath:d,currentRootPath:Z.getState().rootPath,message:_e instanceof Error?_e.message:String(_e)}),null):(nt("error",{requestId:De,cwd:r,includeNested:R,refresh:P,background:K,message:_e instanceof Error?_e.message:String(_e)}),K||(Q(null),Ro(_e instanceof Error?_e.message:"Failed to load Git changes")),null)}finally{Ye!==null&&window.clearTimeout(Ye),Nr.current===Ee&&(Nr.current=null),Kr.current?.promise===Zt&&(Kr.current=null),!K&&vt.current===De&&Se(d)&&jo(Fe)}},[Xr,Pl,ye.size,jo,Bl,_n,Se,Il,x,Ro,Tl]),fs=a.useCallback(async()=>{x&&await Jt(x,{reloadDiff:!0,refresh:!0})},[Jt,x]),$o=a.useCallback(async(r=x??void 0)=>{if(!r)return null;const o=x,d=pn.current+1;pn.current=d,Vr.current?.abort(),kt("right-sidebar-git-details");const v=new AbortController;Vr.current=v,qs(!0);try{const w=await Qc(r,v.signal,"load_git_details","right-sidebar-git-details");return pn.current!==d||!Se(o)?null:(Ne(R=>R.map(P=>P.root===w.root?{...P,available:w.available,context:w,error:w.error}:P)),Q(R=>R?.root&&w.root&&R.root!==w.root?R:!R?.available||!w.available?w:{...R,...w}),w)}catch(w){return Ar(w)||!Se(o)||pn.current===d&>(w instanceof Error?w.message:"Failed to load Git details"),null}finally{Vr.current===v&&(Vr.current=null),pn.current===d&&Se(o)&&qs(!1)}},[Se,x]);a.useEffect(()=>{if(!t){vt.current+=1,ra(),Eo.current=null,pn.current+=1,sa.current+=1,Nr.current?.abort(),kt(Xn(Kr.current?.cwd??x??void 0)),Kr.current=null,Nr.current=null,Vr.current?.abort(),kt("right-sidebar-git-details"),Vr.current=null;for(const r of Ut.current.values())r.abort();for(const r of Ut.current.keys())kt(`right-sidebar-git-untracked:${r}`);Ut.current.clear(),Ot.current.clear(),Un.current+=1,Yr.current?.abort(),Yr.current=null,Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,qs(!1),se(!1),Ue(null),Be(null),tt(null),nr(null),Mn(!1),sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1),q(""),G(!1),mt(null),go(!1),ml(!1),ee&&hl(!1)}},[ee,t,ra,G]),a.useEffect(()=>{if(!ue)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[ue]),a.useEffect(()=>{ee||Rr(!1)},[ee]);const hs=a.useCallback(r=>{mo(r);const o=ia.current;o&&(o.update(),o.slideTo(r,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(r,0)}))},[]);a.useEffect(()=>{if(ee)if(Rr(g),g&&Je){Cr(1);const r=Mr.current;r&&(r.update(),r.activeIndex!==1&&(us.current=1,r.slideTo(1,0)))}else{Cr(0);const r=Mr.current;r&&r.activeIndex!==0&&(us.current=0,r.slideTo(0,0)),mt(null)}},[ee,g,x,Je]),a.useEffect(()=>{if(b!==void 0&&!g){Cr(0);const r=Mr.current;r&&r.activeIndex!==0&&(us.current=0,r.slideTo(0,0)),Rr(!1),mt(null)}},[b,g]),a.useEffect(()=>{C!==void 0&&Le(null)},[C]),a.useEffect(()=>{!ee&&g&&S?.()},[ee,S,g]),a.useEffect(()=>{yo(r=>_i(r,s))},[s]);const Tf=a.useCallback(r=>{ee||(r.preventDefault(),oa.current={startX:r.clientX,startWidth:vo,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[vo,ee]),If=a.useCallback(r=>{const o=oa.current;if(!o||o.pointerId!==r.pointerId)return;const d=_i(o.startWidth+r.clientX-o.startX,s);yo(d),Cs(js,d,xg)},[s]),Hl=a.useCallback(r=>{const o=oa.current;if(!(!o||o.pointerId!==r.pointerId)){oa.current=null,ws(js);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),Hn=!!(x&&_n!==null&&Wd(k)),Lo=!!(x&&!hn&&ye.size===0&&_n===null),lr=(()=>{let r=wo;return r==="android"&&!Wr&&(r="files"),Hn&&(r==="git"||r==="diff")&&(r="files"),r})(),Ze=lr==="git",zn=lr==="files",yt=lr==="diff",Ao=lr==="android";a.useEffect(()=>{if(!ee){Gs(!0);return}if(!t){const o=window.setTimeout(()=>{Gs(!1)},wg);return()=>window.clearTimeout(o)}Gs(!1);const r=window.setTimeout(()=>{Gs(!0)},yg);return()=>window.clearTimeout(r)},[ee,t]),a.useEffect(()=>{if(!ee||!yt)return;const r=ia.current;if(!r)return;const o=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(o)},[yt,ee]),a.useEffect(()=>{if(!Hn||!x||qr)return;const r=window.setTimeout(()=>{Jt(x,{background:!0})},3e3);return()=>window.clearTimeout(r)},[Hn,x,qr,Jt]);const Df=a.useCallback(r=>{Jt(r,{discoverOnly:!0})},[Jt]);Zm({active:t&&(Ze||yt),rootPath:x,loading:qr,delay:Ze&&!ee?0:li,lastStartedRoot:Eo,load:Df}),a.useEffect(()=>{!t||!Ze||(!ee||po)&&go(!0)},[Ze,ee,t,po]),a.useEffect(()=>{if(!t||Ze)return;const r=window.setTimeout(()=>{go(!0)},li);return()=>window.clearTimeout(r)},[Ze,t]),a.useEffect(()=>{yt&&hl(!0)},[yt]),a.useEffect(()=>{Ao&&ml(!0)},[Ao]),a.useEffect(()=>{let r=!1;return qd().then(o=>{!r&&o.androidPanel&&pl(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{r=!0}},[]);const _f=a.useCallback(r=>{pl(r),r?Yt("android"):Z.getState().rightTab==="android"&&Yt("files"),Si({androidPanel:{enabled:r}}).catch(()=>{})},[Yt]),zl=a.useCallback(r=>{me&&vb(me,r.currentTarget.scrollTop)},[me]);a.useEffect(()=>()=>{Nr.current?.abort(),ws(Vi),ws(Yi),ws(js),ws(ii)},[]),a.useEffect(()=>{if(!me||!Fl)return;const r=df()[me]?.top;if(typeof r!="number")return;let o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r),o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(o)},[me,Fl]),a.useEffect(()=>{if(!t)return;const r=new AbortController;return zh(r.signal).then(o=>kl(!!o.available)).catch(()=>kl(!1)),()=>r.abort()},[t]);const ms=a.useCallback(r=>{if(ne(null),Qe(r),mt(null),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Qe]),Wl=a.useCallback((r,o)=>{if(ne(null),Qe(r),Lt(o),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Qe]),ps=a.useCallback(async(r,o)=>{const d=o||In||x;if(!(!d||r.length===0)){Qs(!0);try{await ti(d,r),ta(d,!1)}catch(v){gt(v instanceof Error?v.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>gt(null),4e3)}finally{Qs(!1)}}},[In,x,ta,i]),Gl=a.useCallback(async r=>{try{await Wh(r)}catch(o){gt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>gt(null),4e3)}},[i]),ca=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&xo(!0)},[]),ql=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),xo(!1)},[]),Kl=a.useCallback(r=>{r.preventDefault(),r.stopPropagation(),xo(!1);const o=r.dataTransfer.files;o.length>0&&ps(Array.from(o))},[ps]),Po=a.useCallback(r=>{at(r),window.setTimeout(()=>at(o=>o===r?null:o),1400)},[]),Er=a.useCallback(r=>{qt(r),window.setTimeout(()=>qt(o=>o===r?null:o),1400)},[]);a.useEffect(()=>{St(yd,lt)},[lt]),a.useEffect(()=>{St(wd,Pr)},[Pr]),a.useEffect(()=>{St(kd,z)},[z]),a.useEffect(()=>{Cs(ii,be,hg)},[be]),a.useEffect(()=>(Cl().catch(()=>{}),Zc(r=>{r.type==="pinned-explorer-roots"&&Nl(r.pinnedExplorerRoots)})),[Cl,Nl]);const Vl=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),da=a.useRef(null),bn=a.useRef(null),[Yl,To]=a.useState(!1);a.useEffect(()=>{if(!t)return;To(!1);let r=!1;Gh().then(d=>{r||(da.current=d.text,ze(v=>d.text&&d.text!==v?d.text:v),To(!0))}).catch(()=>{r||To(!0)});const o=Zc(d=>{d.type==="context-draft"&&d.origin!==Vl.current&&(da.current=d.text,ze(d.text))});return()=>{r=!0,o(),bn.current!==null&&(window.clearTimeout(bn.current),bn.current=null)}},[t]),a.useEffect(()=>{if(!Yl||da.current===be)return;bn.current!==null&&window.clearTimeout(bn.current);const r=be;bn.current=window.setTimeout(()=>{bn.current=null,qh(r,Vl.current).then(()=>{da.current=r}).catch(()=>{})},500)},[be,Yl]);const Wn=a.useCallback((r,o,d)=>{if(r){if(Kh(d?r+d:r)){Po(o);return}lt?(ze(v=>Sp(v,r)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(Dt(!1),dr(v=>v+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?r+d:r,focus:!0}})),Po(o)}},[lt,Po]),ua=a.useCallback(r=>{const o=La(r,x);return mm(o,x)},[x]),Io=iu(Er),Jr=a.useCallback((r,o)=>{const d=La(r,x);Wn(pm(d,x),o??`path:${d}`)},[x,Wn]),Ff=a.useCallback(async r=>{Qs(!0);try{await gm(r,ti,o=>{Jr(o,`path:${o}`)}),ee&&!lt&&l()}catch(o){gt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>gt(null),4e3)}finally{Qs(!1)}},[lt,Jr,ee,l,i]),$r=a.useCallback((r,o)=>{if(!r)return;const d=r.includes(`
|
|
1660
1660
|
`)?`
|
|
1661
1661
|
`:void 0;Wn(r.endsWith(`
|
|
1662
|
-
`)||r.endsWith(" ")?r:`${r} `,o,d)},[Wn]),
|
|
1663
|
-
`)},[Wn]),
|
|
1664
|
-
`),v=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let w=!1;const R=K=>{w||(w=!0,window.removeEventListener("termdock-insert-reference-ack",P),window.clearTimeout(H),K?(mr(!1),ze(""),z&&Dt(!0)):(mr(!0),Dt(!1)))},P=K=>{const Me=K.detail;Me?.nonce===v&&R(Me.ok===!0)},H=window.setTimeout(()=>R(!1),1500);window.addEventListener("termdock-insert-reference-ack",P),mr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:d,nonce:v}}))},[z,be]),Xe=a.useMemo(()=>x?xt(x):i("rightSidebar.workspace"),[x,i]),Bf=a.useMemo(()=>xt(me)||Xe,[me,Xe]),fa=a.useMemo(()=>pi(me),[me]),ha=a.useMemo(()=>x?
|
|
1665
|
-
`)},[
|
|
1666
|
-
`):[];if(!t||r.length===0){Tn(null);return}const o=new AbortController;let d=!1,v=0,w=0;Tn(null);const R=async()=>{let P=0;for(;!d&&!o.signal.aborted;){let H=null;try{Tn(null),await rm(r,Me=>{const{applicableEvents:Ge,unavailableReason:De}=bp(Me);Ge.length>0&&Ml(Ge);for(const Fe of Ge){if(Fe.type!=="rescan-required")continue;const pe=Z.getState();if(!pe.directoryCache.has(Fe.path))continue;vn.current.get(Fe.path)?.abort();const Ye=new AbortController;vn.current.set(Fe.path,Ye);const Zt=`file-watch-rescan:${Fe.path}`;kt(Zt),nm(Fe.path,Ye.signal,pe.showHiddenFiles,"watch_rescan",Zt,pe.fileSortModes[Fe.path]??"name").then(_e=>{vn.current.get(Fe.path)===Ye&&El(Fe.path,_e.entries)}).catch(_e=>{Ar(_e)||Tn(_e instanceof Error?_e.message:"File refresh unavailable")}).finally(()=>{vn.current.get(Fe.path)===Ye&&vn.current.delete(Fe.path)})}De&&Tn(De)},o.signal),H=new Error("File watch stream ended")}catch(Me){H=Me}if(d||o.signal.aborted||Ar(H))return;Tn(H instanceof Error?H.message:"File watching unavailable");const K=kd[Math.min(P,kd.length-1)];P+=1,await new Promise(Me=>{w=window.setTimeout(Me,K)})}};return v=window.setTimeout(()=>{d||R()},li),()=>{d=!0,window.clearTimeout(v),window.clearTimeout(w),o.abort();for(const P of vn.current.values())P.abort();vn.current.clear()}},[Ml,t,El,Bo]),a.useEffect(()=>{if(!x||No.current!==x)return;if(Mo.current===x){Mo.current=null;return}const r=Md();Cs(Su,{...r,[x]:{selectedRepoRoots:Hs,repoTargetBranches:jr,repoBaseBranches:Mt,previewEntries:nn,selectedPreviewKey:Pe&&kr?rt:null,selectedPreviewFileKey:Pe&&kr?ho:null,previewDetailOpen:!!(Pe&&kr),previewScrollTops:ss,previewMobileSlideIndex:1,includeUncommitted:zr,updatedAt:Date.now()}},fg)},[kr,zr,Pe,nn,ss,Mt,jr,Hs,x,ho,rt]);const dt=a.useMemo(()=>Hd(ye.values()),[ye]),wt=a.useMemo(()=>{const r=new Map;for(const o of ae)r.set(o.root,o);return r},[ae]),Oo=a.useMemo(()=>{const r=new Map;for(const o of ae)o.deferred||r.set(o.root,o.files.length);return r},[ae]),Et=a.useMemo(()=>de?je.find(r=>r.root===de)??null:null,[de,je]),Ht=a.useMemo(()=>Je?Array.from(ye.values()).find(r=>r.path===Je||r.absolutePath===Je)??null:null,[ye,Je]),It=a.useMemo(()=>{const r=new Map;for(const o of ae)o.available&&o.context?.available&&r.set(o.root,o);return r.size===0&&k?.available&&k.root&&r.set(k.root,{id:k.root,root:k.root,relativeRoot:".",name:Xe,depth:0,nested:!1,available:!0,files:Array.from(ye.values()).filter(o=>ht(o,x)===k.root),context:k}),Array.from(r.values()).sort((o,d)=>o.root===x?-1:d.root===x?1:(o.relativeRoot||o.name).localeCompare(d.relativeRoot||d.name)).map(o=>{const d=o.relativeRoot==="."?Xe:o.relativeRoot||o.name||xt(o.root),v=Ud(o.files),w=o.files.length;return{value:o.root,label:d,meta:[o.context?.branch,w>0?i("rightSidebar.repoChangedCount",{count:w}):null,v>0?i("rightSidebar.repoStagedCount",{count:v}):null].filter(Boolean).join(" · ")}})},[ye,k,ae,Xe,x,i]),ve=a.useMemo(()=>de&&It.some(r=>r.value===de)?de:Ht?.repoRoot&&It.some(r=>r.value===Ht.repoRoot)?Ht.repoRoot:It.length===1||It.length>1?It[0].value:null,[de,It,Ht?.repoRoot]),ac=ve?wt.get(ve)??null:null,ie=ac?.context?.available?ac.context:ve===k?.root?k:null,Ve=It.length>0&&!ve,oc=a.useMemo(()=>Ve?[]:ve?Array.from(ye.values()).filter(r=>ht(r,x)===ve):Array.from(ye.values()),[ve,ye,Ve,x]),yn=a.useMemo(()=>Hd(oc),[oc]),Uo=!!(ie?.available&&ie.root&&ve&&ie.root===ve),Wf=ve?It.find(r=>r.value===ve)?.label??xt(ve):i("rightSidebar.gitRepositoryPlaceholder"),ic=Uo?ie?.branch??"HEAD":Ve?i("rightSidebar.selectRepositoryForGitActions"):cn?i("rightSidebar.gitActionRunning"):"HEAD",Gn=!!(ie?.available&&ie.root===ve&&ie.status);a.useEffect(()=>{ol.current={count:an.length,loading:He,loadingMore:Ur,hasMore:lo}},[an.length,lo,He,Ur]),a.useEffect(()=>{Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1)},[ve]);const bs=a.useCallback(async(r={})=>{if(!x||!ve||Ve)return;const o=r.reset??!1,d=ol.current,v=o?0:d.count;if(!o&&(d.loading||d.loadingMore||!d.hasMore))return;const w=Hr.current+1;Hr.current=w,sr.current?.abort(),kt("right-sidebar-recent-commits");const R=new AbortController;sr.current=R,o?Pt(!0):os(!0),En(null);try{const P=await Vh({cwd:x,repoRoot:ve,limit:kg,skip:v,query:Or.trim(),requestSlotId:"right-sidebar-recent-commits"},R.signal);if(Hr.current!==w)return;if(!P.available){En(P.error??"Recent commits are unavailable"),o&&X([]),$n(!1);return}io(H=>o?P.commitSyncStatus??{}:{...H,...P.commitSyncStatus}),X(H=>o?P.commits:[...H,...P.commits]),$n(P.hasMore)}catch(P){if(Hr.current!==w||Ar(P))return;En(P instanceof Error?P.message:"Failed to load recent commits"),o&&X([]),$n(!1)}finally{sr.current===R&&(sr.current=null),Hr.current===w&&(Pt(!1),os(!1))}},[ve,Or,Ve,x]);a.useEffect(()=>{Vt&&bs({reset:!0})},[Or,bs,Vt,ie?.ahead,ie?.behind,ie?.upstream]);const Gf=a.useCallback(r=>{const o=r.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||bs({reset:!1})},[bs]);a.useEffect(()=>{!ve||!k?.available||!Ze||!ar||Gn||cn||Ve||$o(ve)},[ve,k?.available,Gn,cn,Ze,ar,$o,Ve]),a.useEffect(()=>{!t||!yt&&!Ze||!x||ir()},[yt,Ze,t,ir,x]),a.useEffect(()=>{!t||!Ze||!ar||!is||!x||la(null)},[is,Ze,ar,t,la,x]);const qf=a.useMemo(()=>{if(!de)return 0;const r=je.findIndex(o=>o.root===de);return r>=0?r+1:0},[de,je]),lc=a.useCallback(r=>{if(!r)return null;const o=Array.from(ye.values()).filter(d=>ht(d,x)===r).sort((d,v)=>d.path.localeCompare(v.path))[0];return o?bt(o):null},[ye,x]),wn=je.length>1,ma=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:ye.size,branch:null,deferred:!1},...je.map(r=>({root:r.root,label:r.label,count:r.deferred?Oo.get(r.root)??0:r.count,branch:r.branch??null,deferred:!!r.deferred&&!Oo.has(r.root)}))],[ye.size,je,Oo,i]),cc=ma[qf]??ma[0],pa=!!de,dc=a.useMemo(()=>Au(je,ae),[je,ae]);a.useEffect(()=>{de&&!dc.has(de)&&(Ae(null),ci(x,null)),Cn(r=>r.filter(o=>je.some(d=>d.root===o)))},[de,je,dc,x]);const Kf=a.useMemo(()=>{const r=new Set;ie?.branch&&r.add(ie.branch);for(const o of ie?.branches??[])r.add(o);return Array.from(r).map(o=>({value:o,label:o,meta:o===ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ie?.branch,ie?.branches,i]),uc=a.useMemo(()=>{const r=new Set;ie?.upstreamRemote&&r.add(ie.upstreamRemote);for(const o of ie?.remotes??[])r.add(o);return Array.from(r).map(o=>({value:o,label:o,meta:o===ie?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[ie?.remotes,ie?.upstreamRemote,i]),fc=uc.length>1,Vf=a.useMemo(()=>{const r=[],o=new Set,d=(w,R)=>{!w||o.has(w)||(o.add(w),r.push({value:w,label:w,meta:R}))};d(ie?.upstreamBranch,ie?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),d(ie?.branch,ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const w of ie?.branches??[])d(w,w===ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const v=ie?.upstreamRemote;for(const w of ie?.remoteBranches??[]){const R=w.indexOf("/"),P=R>=0?w.slice(0,R):null,H=R>=0?w.slice(R+1):w;(!v||P===v)&&d(H,"remote")}return r},[ie?.branch,ie?.branches,ie?.remoteBranches,ie?.upstreamBranch,ie?.upstreamRemote,i]),zt=a.useMemo(()=>It.map(r=>{const o=wt.get(r.value);return{root:r.value,label:r.label,branch:o?.context?.branch??null}}),[It,wt]);a.useEffect(()=>{zt.length!==0&&(zs(r=>{let o=!1;const d={...r},v=new Set(zt.map(w=>w.root));for(const w of Object.keys(d))v.has(w)||(delete d[w],o=!0);for(const w of zt)!d[w.root]&&w.branch&&(d[w.root]=w.branch,o=!0);return o?d:r}),Ws(r=>{let o=!1;const d={...r},v=new Set(zt.map(w=>w.root));for(const w of Object.keys(d))v.has(w)||(delete d[w],o=!0);for(const w of zt){const R=wt.get(w.root)?.context;if(d[w.root]&&Pu(d[w.root],R?.branch)&&(delete d[w.root],o=!0),d[w.root])continue;const P=Ld(R);P&&(d[w.root]=P,o=!0)}return o?d:r}))},[zt,wt]);const ga=a.useMemo(()=>{const r=new Set(zt.map(o=>o.root));return Hs.filter(o=>r.has(o))},[Hs,zt]),ba=ga.length===0,cr=a.useMemo(()=>ba?zt:zt.filter(r=>ga.includes(r.root)),[zt,ga,ba]),Qt=a.useMemo(()=>cr.filter(r=>!!Mt[r.root]?.trim()),[Mt,cr]),hc=a.useMemo(()=>cr.filter(r=>!Mt[r.root]?.trim()),[Mt,cr]),mc=a.useCallback(async r=>{if(!r||Co.current.has(r))return;const o=wt.get(r)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const d=x;Co.current.add(r),dl(v=>new Set(v).add(r));try{const v=await Jc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!v.available||!Se(d))return;Ne(w=>w.map(R=>R.root===r?{...R,available:!0,context:{...R.context,...v},error:void 0}:R)),zs(w=>w[r]||!v.branch?w:{...w,[r]:v.branch}),Ws(w=>{if(w[r])return w;const R=Ld(v);return R?{...w,[r]:R}:w})}catch(v){Ar(v)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,v)}finally{Co.current.delete(r),dl(v=>{const w=new Set(v);return w.delete(r),w})}},[wt,Se,x]);a.useEffect(()=>{if(co)for(const r of cr)mc(r.root)},[co,cr,mc]),a.useEffect(()=>{!Uo||!ie||(Vs(ie.branch||(ie.branches?.[0]??"")),Ys(ie.upstreamRemote||(ie.remotes?.includes("origin")?"origin":ie.remotes?.[0]??"")),Xs(ie.upstreamBranch||ie.branch||(ie.branches?.[0]??"")))},[ie,Uo]);const pc=a.useMemo(()=>{if(Ve)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Gn||cn)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ie?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=ie.ahead??0,o=ie.behind??0;return r>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:r,behind:o}),className:"bg-destructive/10 text-destructive"}:r>0?{text:i("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ie?.ahead,ie?.behind,ie?.upstream,Gn,cn,Ve,i]),Yf=a.useCallback(r=>{if(r&&!ee){const o=r.currentTarget.getBoundingClientRect();Le({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Le(null);I?.()},[ee,I]),Ho=a.useCallback(()=>{Le(null),F?.()},[F]);function gc(){if(!wn)return null;const r=cc?.label??i("rightSidebar.allRepositories"),o=cc?.count??ye.size,d=xt(r)||r;return e.jsxs("button",{type:"button",onClick:Yf,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 ${y?"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":y,title:r,children:[e.jsx(Lr,{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] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Ls,{size:12,className:"shrink-0"})]})}function Xf(){if(!y||!wn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(st?.x??r-368,r-352)),v=Math.max(12,Math.min(st?.y??80,o-420)),w=ee?void 0:{left:d,top:v},R=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Ho,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:w,onClick:P=>P.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:ma.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${ye.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:ye.size})]})]}),e.jsx("button",{type:"button",onClick:Ho,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Gt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:ma.map(P=>{const H=(P.root??null)===de,K=xt(P.label)||P.label;return e.jsxs("button",{type:"button",onClick:()=>{Dc(P.root),Ho()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${H?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:P.label,role:"option","aria-selected":H,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${H?"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 ${H?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Lr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:K}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:P.root===null?i("rightSidebar.allRepositories"):P.label})]}),P.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:P.branch}),P.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${P.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:P.count})]},P.root??"all")})})]})});return bu(R,ee,document.body)}function Jf(){return Xf()}function bc(r){const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path),v=Ka(d,o??x);return{key:bt(r),path:r.path,absolutePath:d,displayName:v.name,displayDir:v.dir,oldPath:r.oldPath,status:r.status,title:d}}function xc(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function vc(r,o){const d=La(r,x),v=`path:${d}`,w=we===v,R=et===v,P=w||R;return e.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),Jr(d,v)},...Io(ua(d),v),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 ${P?"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"} ${P?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(R?"rightSidebar.copied":w?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function yc(r){const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path),v=jh(r),w=xi(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Mb,{actions:v,running:Ie,completed:Ln?.path===w?Ln:null}),vc(d,i("rightSidebar.insertThisFile"))]})}function wc(r,o){const d=o.root??x;if(!d)return null;const v=La(r,d);return vc(v,i("fileTree.insertRefTitle"))}function zo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>$c("unified"),"aria-pressed":Ft==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ft==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>$c("split"),"aria-pressed":Ft==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ft==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function kc(){return xs.map(r=>{const o=Ud(r.files.map(([,R])=>R)),d=Ti({activeGitRepoRoot:de,groupCount:xs.length,label:r.label,rootName:Xe}),v=!!(d&&r.root&&pr.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:v,files:r.files.map(([,R])=>bc(R)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${v?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>gh(r.root),"aria-expanded":!v,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:v?e.jsx($a,{size:13}):e.jsx(Ls,{size:13})}),e.jsx(Lr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),Ca("stage-all",r.root,r.label)},disabled:!!Ie,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:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),Ca("stash-all",r.root,r.label)},disabled:!!Ie,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:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function Sc(){return ye.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:va.map(([,r])=>{const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path);return{key:bt(r),path:r.path,absolutePath:d,status:r.status,repoRoot:o,displayName:Ka(d,o).name,displayDir:Ka(d,o).dir,auditRecords:Ct}})}function jc(r){const o=Array.from(ye.values()).find(w=>bt(w)===r.key),d=o?ht(o,x):null,v=sp(Ct,d,o?.path??r.path);return e.jsx(Ei,{changeStatus:r.status,auditStatus:v,renderChangeBadge:w=>e.jsx(Ns,{status:w})})}const xa=a.useCallback(r=>{if(ee)return null;const o=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const v=r.getBoundingClientRect().top+48;let w=null,R=Number.POSITIVE_INFINITY;for(const H of o){const K=H.getBoundingClientRect();if(K.bottom<v)continue;const Me=Math.abs(K.top-v);Me<R&&(w=H,R=Me)}const P=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;return P?(aa.current===P&&Z.getState().selectedFilePath===P||(aa.current=P,Qe(P)),P):null},[ee,Qe]),Qf=!!(!Ie&&ve&&!Ve&&(ie?.upstream||dn.trim()&&un.trim())),Zf=!!(!Ie&&ve&&!Ve&&(ie?.upstream||dn.trim()&&un.trim())),eh=!!(!Ie&&ve&&!Ve&&Pn.trim()&&Pn.trim()!==ie?.branch),Wt=a.useMemo(()=>{const r=xe.trim().toLowerCase(),o=Array.from(ye.entries()).filter(([,d])=>!de||ht(d,x)===de).sort(([d],[v])=>d.localeCompare(v));return r?o.filter(([d,v])=>`${d} ${v.path} ${v.status} ${v.repoRelativeRoot??""} ${v.repoName??""}`.toLowerCase().includes(r)):o},[de,ye,xe,x]);a.useEffect(()=>{za("selected_file_state",{selectedFilePath:Je,selectedChangedFilePath:Ht?.path??null,selectedChangedFileAbsolutePath:Ht?.absolutePath??null,selectedChangedFileRepoRoot:Ht?.repoRoot??null,rootPath:x,activeGitRepoRoot:de,rightTab:wo,effectiveRightTab:lr,diffPaneActive:yt,changedFiles:ye.size,filteredChangedFiles:Wt.length,gitBundleLoading:qr,gitBundleLastLoadedAt:_n})},[de,ye.size,yt,lr,Wt.length,_n,qr,wo,x,Ht?.absolutePath,Ht?.path,Ht?.repoRoot,Je]);const xs=a.useMemo(()=>{const r=new Map;for(const o of Wt){const[,d]=o,v=ht(d,x),w=Cb(d)||Xe,R=v??w,P=v?wt.get(v):void 0,H=r.get(R)??{root:v,label:w,branch:P?.context?.branch,files:[]};H.files.push(o),r.set(R,H)}return Array.from(r.values()).sort((o,d)=>o.label===Xe?-1:d.label===Xe?1:o.label.localeCompare(d.label))},[Wt,wt,Xe,x]),va=a.useMemo(()=>{const r=[],o=new Map;for(const d of Wt)o.set(bt(d[1]),d);for(const d of xs){if(!!(d.root&&Ti({activeGitRepoRoot:de,groupCount:xs.length,label:d.label,rootName:Xe})&&pr.has(d.root)))continue;if(xr!=="tree"){r.push(...d.files);continue}const w=d.files.map(([,R])=>bc(R));for(const R of Mm(w)){const P=o.get(R.key);P&&r.push(P)}}return r},[de,pr,xr,xs,Wt,Xe]);a.useEffect(()=>{if(!yt||va.length===0||ee)return;const r=[],o=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&xa(d))return;const v=document.querySelector("[data-diff-stream-item]"),w=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;if(w){aa.current=w,Qe(w);return}const R=va[0]?.[1];if(!R)return;const P=bt(R);aa.current=P,Qe(P)};for(const d of[80,240,600,1200])r.push(window.setTimeout(o,d));return()=>r.forEach(d=>window.clearTimeout(d))},[yt,ee,va,Qe,xa]);const Wo=a.useMemo(()=>{const r=P=>`'${P.replace(/'/g,"'\\''")}'`,o=Xt.length>0?gn:ae.filter(P=>P.files.length>0),d=o.length>0?o:x?[{root:x,relativeRoot:".",name:Xe}]:[],v=d.length>0?d.map(P=>`- ${P.relativeRoot==="."?".":P.relativeRoot} (${P.root})`).join(`
|
|
1662
|
+
`)||r.endsWith(" ")?r:`${r} `,o,d)},[Wn]),Xl=a.useRef($r);Xl.current=$r;const Do=a.useRef(!0);a.useEffect(()=>(Do.current=!0,()=>{Do.current=!1}),[]);const _o=a.useRef(new Set),Jl=a.useCallback((r,o,d)=>{if(_o.current.has(o))return;const v=ad.getState().activeSessionId;_o.current.add(o),rp(r,o,d,{insert:$r,upload:async(w,R)=>(await ti("/tmp",[w],R)).files[0]?.path,isCurrent:()=>Do.current&&Xl.current===$r&&v===ad.getState().activeSessionId}).finally(()=>_o.current.delete(o))},[$r]),Qr=a.useCallback((r,o,d)=>{o&&Wn(o.endsWith(" ")?o:`${o} `,d??`context:${r}`,`
|
|
1663
|
+
`)},[Wn]),Ql=a.useCallback(r=>{const o=jp(be,r);if(!o)return;const d=r&&be.trim().includes(`
|
|
1664
|
+
`),v=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let w=!1;const R=K=>{w||(w=!0,window.removeEventListener("termdock-insert-reference-ack",P),window.clearTimeout(H),K?(mr(!1),ze(""),z&&Dt(!0)):(mr(!0),Dt(!1)))},P=K=>{const Me=K.detail;Me?.nonce===v&&R(Me.ok===!0)},H=window.setTimeout(()=>R(!1),1500);window.addEventListener("termdock-insert-reference-ack",P),mr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:d,nonce:v}}))},[z,be]),Xe=a.useMemo(()=>x?xt(x):i("rightSidebar.workspace"),[x,i]),Bf=a.useMemo(()=>xt(me)||Xe,[me,Xe]),fa=a.useMemo(()=>pi(me),[me]),ha=a.useMemo(()=>x?Rl[x]??[]:[],[Rl,x]),xn=a.useMemo(()=>new Set(ha.map(r=>r.path)),[ha]),gs=!!(me&&xn.has(me)),Fo=!!(x&&me&&me!==x),Of=!!(x&&In&&In!==x),Tt=me?`path:${me}`:null,Zl="context:change-audit",Uf=a.useCallback(()=>{fa&&Bt(fa)},[fa,Bt]),ec=a.useCallback(()=>{Ml()},[Ml]),Hf=a.useCallback(()=>{me&&(ta(me,!0),Ll())},[Ll,me,ta]),zf=a.useCallback(()=>{!me||!Fo||(gs?fn(me):Dn(me,"directory"))},[Fo,me,gs,Dn,fn]),tc=a.useCallback(r=>{Bt(r),q("")},[Bt]),rc=a.useCallback(r=>{me&&(oe(ug(me,r)),G(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[me,G]),nc=a.useCallback(r=>{!x||r===x||(xn.has(r)?fn(r):Dn(r,"directory"))},[Dn,xn,x,fn]),sc=a.useCallback(r=>{!x||!r||(xn.has(r)?fn(r):Dn(r,"file"))},[Dn,xn,x,fn]),ac=Z(r=>r.expandedPaths),Bo=a.useMemo(()=>{const r=new Set;if(zn&&me){r.add(me);const o=`${me.replace(/\/+$/,"")}/`;for(const d of ac)d.startsWith(o)&&r.add(d)}if(zn&&x&&Je){const o=Je.startsWith("/")?Je:`${x}/${Je}`,d=pi(o);d&&r.add(d)}return pp(r).join(`
|
|
1665
|
+
`)},[ac,zn,me,x,Je]),vn=a.useRef(new Map);a.useEffect(()=>{const r=Bo?Bo.split(`
|
|
1666
|
+
`):[];if(!t||r.length===0){Tn(null);return}const o=new AbortController;let d=!1,v=0,w=0;Tn(null);const R=async()=>{let P=0;for(;!d&&!o.signal.aborted;){let H=null;try{Tn(null),await rm(r,Me=>{const{applicableEvents:Ge,unavailableReason:De}=bp(Me);Ge.length>0&&El(Ge);for(const Fe of Ge){if(Fe.type!=="rescan-required")continue;const pe=Z.getState();if(!pe.directoryCache.has(Fe.path))continue;vn.current.get(Fe.path)?.abort();const Ye=new AbortController;vn.current.set(Fe.path,Ye);const Zt=`file-watch-rescan:${Fe.path}`;kt(Zt),nm(Fe.path,Ye.signal,pe.showHiddenFiles,"watch_rescan",Zt,pe.fileSortModes[Fe.path]??"name").then(_e=>{vn.current.get(Fe.path)===Ye&&$l(Fe.path,_e.entries)}).catch(_e=>{Ar(_e)||Tn(_e instanceof Error?_e.message:"File refresh unavailable")}).finally(()=>{vn.current.get(Fe.path)===Ye&&vn.current.delete(Fe.path)})}De&&Tn(De)},o.signal),H=new Error("File watch stream ended")}catch(Me){H=Me}if(d||o.signal.aborted||Ar(H))return;Tn(H instanceof Error?H.message:"File watching unavailable");const K=Sd[Math.min(P,Sd.length-1)];P+=1,await new Promise(Me=>{w=window.setTimeout(Me,K)})}};return v=window.setTimeout(()=>{d||R()},li),()=>{d=!0,window.clearTimeout(v),window.clearTimeout(w),o.abort();for(const P of vn.current.values())P.abort();vn.current.clear()}},[El,t,$l,Bo]),a.useEffect(()=>{if(!x||No.current!==x)return;if(Mo.current===x){Mo.current=null;return}const r=Ed();Cs(Su,{...r,[x]:{selectedRepoRoots:Hs,repoTargetBranches:jr,repoBaseBranches:Mt,previewEntries:nn,selectedPreviewKey:Pe&&kr?rt:null,selectedPreviewFileKey:Pe&&kr?ho:null,previewDetailOpen:!!(Pe&&kr),previewScrollTops:ss,previewMobileSlideIndex:1,includeUncommitted:zr,updatedAt:Date.now()}},fg)},[kr,zr,Pe,nn,ss,Mt,jr,Hs,x,ho,rt]);const dt=a.useMemo(()=>zd(ye.values()),[ye]),wt=a.useMemo(()=>{const r=new Map;for(const o of ae)r.set(o.root,o);return r},[ae]),Oo=a.useMemo(()=>{const r=new Map;for(const o of ae)o.deferred||r.set(o.root,o.files.length);return r},[ae]),Et=a.useMemo(()=>de?je.find(r=>r.root===de)??null:null,[de,je]),Ht=a.useMemo(()=>Je?Array.from(ye.values()).find(r=>r.path===Je||r.absolutePath===Je)??null:null,[ye,Je]),It=a.useMemo(()=>{const r=new Map;for(const o of ae)o.available&&o.context?.available&&r.set(o.root,o);return r.size===0&&k?.available&&k.root&&r.set(k.root,{id:k.root,root:k.root,relativeRoot:".",name:Xe,depth:0,nested:!1,available:!0,files:Array.from(ye.values()).filter(o=>ht(o,x)===k.root),context:k}),Array.from(r.values()).sort((o,d)=>o.root===x?-1:d.root===x?1:(o.relativeRoot||o.name).localeCompare(d.relativeRoot||d.name)).map(o=>{const d=o.relativeRoot==="."?Xe:o.relativeRoot||o.name||xt(o.root),v=Hd(o.files),w=o.files.length;return{value:o.root,label:d,meta:[o.context?.branch,w>0?i("rightSidebar.repoChangedCount",{count:w}):null,v>0?i("rightSidebar.repoStagedCount",{count:v}):null].filter(Boolean).join(" · ")}})},[ye,k,ae,Xe,x,i]),ve=a.useMemo(()=>de&&It.some(r=>r.value===de)?de:Ht?.repoRoot&&It.some(r=>r.value===Ht.repoRoot)?Ht.repoRoot:It.length===1||It.length>1?It[0].value:null,[de,It,Ht?.repoRoot]),oc=ve?wt.get(ve)??null:null,ie=oc?.context?.available?oc.context:ve===k?.root?k:null,Ve=It.length>0&&!ve,ic=a.useMemo(()=>Ve?[]:ve?Array.from(ye.values()).filter(r=>ht(r,x)===ve):Array.from(ye.values()),[ve,ye,Ve,x]),yn=a.useMemo(()=>zd(ic),[ic]),Uo=!!(ie?.available&&ie.root&&ve&&ie.root===ve),Wf=ve?It.find(r=>r.value===ve)?.label??xt(ve):i("rightSidebar.gitRepositoryPlaceholder"),lc=Uo?ie?.branch??"HEAD":Ve?i("rightSidebar.selectRepositoryForGitActions"):cn?i("rightSidebar.gitActionRunning"):"HEAD",Gn=!!(ie?.available&&ie.root===ve&&ie.status);a.useEffect(()=>{il.current={count:an.length,loading:He,loadingMore:Ur,hasMore:lo}},[an.length,lo,He,Ur]),a.useEffect(()=>{Hr.current+=1,sr.current?.abort(),kt("right-sidebar-recent-commits"),sr.current=null,sn(""),X([]),Pt(!1),os(!1),En(null),$n(!1)},[ve]);const bs=a.useCallback(async(r={})=>{if(!x||!ve||Ve)return;const o=r.reset??!1,d=il.current,v=o?0:d.count;if(!o&&(d.loading||d.loadingMore||!d.hasMore))return;const w=Hr.current+1;Hr.current=w,sr.current?.abort(),kt("right-sidebar-recent-commits");const R=new AbortController;sr.current=R,o?Pt(!0):os(!0),En(null);try{const P=await Vh({cwd:x,repoRoot:ve,limit:kg,skip:v,query:Or.trim(),requestSlotId:"right-sidebar-recent-commits"},R.signal);if(Hr.current!==w)return;if(!P.available){En(P.error??"Recent commits are unavailable"),o&&X([]),$n(!1);return}io(H=>o?P.commitSyncStatus??{}:{...H,...P.commitSyncStatus}),X(H=>o?P.commits:[...H,...P.commits]),$n(P.hasMore)}catch(P){if(Hr.current!==w||Ar(P))return;En(P instanceof Error?P.message:"Failed to load recent commits"),o&&X([]),$n(!1)}finally{sr.current===R&&(sr.current=null),Hr.current===w&&(Pt(!1),os(!1))}},[ve,Or,Ve,x]);a.useEffect(()=>{Vt&&bs({reset:!0})},[Or,bs,Vt,ie?.ahead,ie?.behind,ie?.upstream]);const Gf=a.useCallback(r=>{const o=r.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||bs({reset:!1})},[bs]);a.useEffect(()=>{!ve||!k?.available||!Ze||!ar||Gn||cn||Ve||$o(ve)},[ve,k?.available,Gn,cn,Ze,ar,$o,Ve]),a.useEffect(()=>{!t||!yt&&!Ze||!x||ir()},[yt,Ze,t,ir,x]),a.useEffect(()=>{!t||!Ze||!ar||!is||!x||la(null)},[is,Ze,ar,t,la,x]);const qf=a.useMemo(()=>{if(!de)return 0;const r=je.findIndex(o=>o.root===de);return r>=0?r+1:0},[de,je]),cc=a.useCallback(r=>{if(!r)return null;const o=Array.from(ye.values()).filter(d=>ht(d,x)===r).sort((d,v)=>d.path.localeCompare(v.path))[0];return o?bt(o):null},[ye,x]),wn=je.length>1,ma=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:ye.size,branch:null,deferred:!1},...je.map(r=>({root:r.root,label:r.label,count:r.deferred?Oo.get(r.root)??0:r.count,branch:r.branch??null,deferred:!!r.deferred&&!Oo.has(r.root)}))],[ye.size,je,Oo,i]),dc=ma[qf]??ma[0],pa=!!de,uc=a.useMemo(()=>Au(je,ae),[je,ae]);a.useEffect(()=>{de&&!uc.has(de)&&(Ae(null),ci(x,null)),Cn(r=>r.filter(o=>je.some(d=>d.root===o)))},[de,je,uc,x]);const Kf=a.useMemo(()=>{const r=new Set;ie?.branch&&r.add(ie.branch);for(const o of ie?.branches??[])r.add(o);return Array.from(r).map(o=>({value:o,label:o,meta:o===ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ie?.branch,ie?.branches,i]),fc=a.useMemo(()=>{const r=new Set;ie?.upstreamRemote&&r.add(ie.upstreamRemote);for(const o of ie?.remotes??[])r.add(o);return Array.from(r).map(o=>({value:o,label:o,meta:o===ie?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[ie?.remotes,ie?.upstreamRemote,i]),hc=fc.length>1,Vf=a.useMemo(()=>{const r=[],o=new Set,d=(w,R)=>{!w||o.has(w)||(o.add(w),r.push({value:w,label:w,meta:R}))};d(ie?.upstreamBranch,ie?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),d(ie?.branch,ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const w of ie?.branches??[])d(w,w===ie?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const v=ie?.upstreamRemote;for(const w of ie?.remoteBranches??[]){const R=w.indexOf("/"),P=R>=0?w.slice(0,R):null,H=R>=0?w.slice(R+1):w;(!v||P===v)&&d(H,"remote")}return r},[ie?.branch,ie?.branches,ie?.remoteBranches,ie?.upstreamBranch,ie?.upstreamRemote,i]),zt=a.useMemo(()=>It.map(r=>{const o=wt.get(r.value);return{root:r.value,label:r.label,branch:o?.context?.branch??null}}),[It,wt]);a.useEffect(()=>{zt.length!==0&&(zs(r=>{let o=!1;const d={...r},v=new Set(zt.map(w=>w.root));for(const w of Object.keys(d))v.has(w)||(delete d[w],o=!0);for(const w of zt)!d[w.root]&&w.branch&&(d[w.root]=w.branch,o=!0);return o?d:r}),Ws(r=>{let o=!1;const d={...r},v=new Set(zt.map(w=>w.root));for(const w of Object.keys(d))v.has(w)||(delete d[w],o=!0);for(const w of zt){const R=wt.get(w.root)?.context;if(d[w.root]&&Pu(d[w.root],R?.branch)&&(delete d[w.root],o=!0),d[w.root])continue;const P=Ad(R);P&&(d[w.root]=P,o=!0)}return o?d:r}))},[zt,wt]);const ga=a.useMemo(()=>{const r=new Set(zt.map(o=>o.root));return Hs.filter(o=>r.has(o))},[Hs,zt]),ba=ga.length===0,cr=a.useMemo(()=>ba?zt:zt.filter(r=>ga.includes(r.root)),[zt,ga,ba]),Qt=a.useMemo(()=>cr.filter(r=>!!Mt[r.root]?.trim()),[Mt,cr]),mc=a.useMemo(()=>cr.filter(r=>!Mt[r.root]?.trim()),[Mt,cr]),pc=a.useCallback(async r=>{if(!r||Co.current.has(r))return;const o=wt.get(r)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const d=x;Co.current.add(r),ul(v=>new Set(v).add(r));try{const v=await Qc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!v.available||!Se(d))return;Ne(w=>w.map(R=>R.root===r?{...R,available:!0,context:{...R.context,...v},error:void 0}:R)),zs(w=>w[r]||!v.branch?w:{...w,[r]:v.branch}),Ws(w=>{if(w[r])return w;const R=Ad(v);return R?{...w,[r]:R}:w})}catch(v){Ar(v)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,v)}finally{Co.current.delete(r),ul(v=>{const w=new Set(v);return w.delete(r),w})}},[wt,Se,x]);a.useEffect(()=>{if(co)for(const r of cr)pc(r.root)},[co,cr,pc]),a.useEffect(()=>{!Uo||!ie||(Vs(ie.branch||(ie.branches?.[0]??"")),Ys(ie.upstreamRemote||(ie.remotes?.includes("origin")?"origin":ie.remotes?.[0]??"")),Xs(ie.upstreamBranch||ie.branch||(ie.branches?.[0]??"")))},[ie,Uo]);const gc=a.useMemo(()=>{if(Ve)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Gn||cn)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ie?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=ie.ahead??0,o=ie.behind??0;return r>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:r,behind:o}),className:"bg-destructive/10 text-destructive"}:r>0?{text:i("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ie?.ahead,ie?.behind,ie?.upstream,Gn,cn,Ve,i]),Yf=a.useCallback(r=>{if(r&&!ee){const o=r.currentTarget.getBoundingClientRect();Le({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Le(null);I?.()},[ee,I]),Ho=a.useCallback(()=>{Le(null),F?.()},[F]);function bc(){if(!wn)return null;const r=dc?.label??i("rightSidebar.allRepositories"),o=dc?.count??ye.size,d=xt(r)||r;return e.jsxs("button",{type:"button",onClick:Yf,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 ${y?"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":y,title:r,children:[e.jsx(Lr,{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] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Ls,{size:12,className:"shrink-0"})]})}function Xf(){if(!y||!wn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(st?.x??r-368,r-352)),v=Math.max(12,Math.min(st?.y??80,o-420)),w=ee?void 0:{left:d,top:v},R=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Ho,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:w,onClick:P=>P.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:ma.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${ye.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:ye.size})]})]}),e.jsx("button",{type:"button",onClick:Ho,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Gt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:ma.map(P=>{const H=(P.root??null)===de,K=xt(P.label)||P.label;return e.jsxs("button",{type:"button",onClick:()=>{_c(P.root),Ho()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${H?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:P.label,role:"option","aria-selected":H,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${H?"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 ${H?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Lr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:K}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:P.root===null?i("rightSidebar.allRepositories"):P.label})]}),P.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:P.branch}),P.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${P.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:P.count})]},P.root??"all")})})]})});return bu(R,ee,document.body)}function Jf(){return Xf()}function xc(r){const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path),v=Ka(d,o??x);return{key:bt(r),path:r.path,absolutePath:d,displayName:v.name,displayDir:v.dir,oldPath:r.oldPath,status:r.status,title:d}}function vc(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function yc(r,o){const d=La(r,x),v=`path:${d}`,w=we===v,R=et===v,P=w||R;return e.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),Jr(d,v)},...Io(ua(d),v),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 ${P?"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"} ${P?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(R?"rightSidebar.copied":w?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function wc(r){const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path),v=jh(r),w=xi(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Mb,{actions:v,running:Ie,completed:Ln?.path===w?Ln:null}),yc(d,i("rightSidebar.insertThisFile"))]})}function kc(r,o){const d=o.root??x;if(!d)return null;const v=La(r,d);return yc(v,i("fileTree.insertRefTitle"))}function zo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>Lc("unified"),"aria-pressed":Ft==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ft==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>Lc("split"),"aria-pressed":Ft==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ft==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function Sc(){return xs.map(r=>{const o=Hd(r.files.map(([,R])=>R)),d=Ii({activeGitRepoRoot:de,groupCount:xs.length,label:r.label,rootName:Xe}),v=!!(d&&r.root&&pr.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:v,files:r.files.map(([,R])=>xc(R)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${v?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>gh(r.root),"aria-expanded":!v,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:v?e.jsx($a,{size:13}):e.jsx(Ls,{size:13})}),e.jsx(Lr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),Ca("stage-all",r.root,r.label)},disabled:!!Ie,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:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),Ca("stash-all",r.root,r.label)},disabled:!!Ie,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:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function jc(){return ye.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:va.map(([,r])=>{const o=ht(r,x),d=r.absolutePath||(o?`${o}/${r.path}`:r.path);return{key:bt(r),path:r.path,absolutePath:d,status:r.status,repoRoot:o,displayName:Ka(d,o).name,displayDir:Ka(d,o).dir,auditRecords:Ct}})}function Rc(r){const o=Array.from(ye.values()).find(w=>bt(w)===r.key),d=o?ht(o,x):null,v=sp(Ct,d,o?.path??r.path);return e.jsx($i,{changeStatus:r.status,auditStatus:v,renderChangeBadge:w=>e.jsx(Ns,{status:w})})}const xa=a.useCallback(r=>{if(ee)return null;const o=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const v=r.getBoundingClientRect().top+48;let w=null,R=Number.POSITIVE_INFINITY;for(const H of o){const K=H.getBoundingClientRect();if(K.bottom<v)continue;const Me=Math.abs(K.top-v);Me<R&&(w=H,R=Me)}const P=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;return P?(aa.current===P&&Z.getState().selectedFilePath===P||(aa.current=P,Qe(P)),P):null},[ee,Qe]),Qf=!!(!Ie&&ve&&!Ve&&(ie?.upstream||dn.trim()&&un.trim())),Zf=!!(!Ie&&ve&&!Ve&&(ie?.upstream||dn.trim()&&un.trim())),eh=!!(!Ie&&ve&&!Ve&&Pn.trim()&&Pn.trim()!==ie?.branch),Wt=a.useMemo(()=>{const r=xe.trim().toLowerCase(),o=Array.from(ye.entries()).filter(([,d])=>!de||ht(d,x)===de).sort(([d],[v])=>d.localeCompare(v));return r?o.filter(([d,v])=>`${d} ${v.path} ${v.status} ${v.repoRelativeRoot??""} ${v.repoName??""}`.toLowerCase().includes(r)):o},[de,ye,xe,x]);a.useEffect(()=>{za("selected_file_state",{selectedFilePath:Je,selectedChangedFilePath:Ht?.path??null,selectedChangedFileAbsolutePath:Ht?.absolutePath??null,selectedChangedFileRepoRoot:Ht?.repoRoot??null,rootPath:x,activeGitRepoRoot:de,rightTab:wo,effectiveRightTab:lr,diffPaneActive:yt,changedFiles:ye.size,filteredChangedFiles:Wt.length,gitBundleLoading:qr,gitBundleLastLoadedAt:_n})},[de,ye.size,yt,lr,Wt.length,_n,qr,wo,x,Ht?.absolutePath,Ht?.path,Ht?.repoRoot,Je]);const xs=a.useMemo(()=>{const r=new Map;for(const o of Wt){const[,d]=o,v=ht(d,x),w=Cb(d)||Xe,R=v??w,P=v?wt.get(v):void 0,H=r.get(R)??{root:v,label:w,branch:P?.context?.branch,files:[]};H.files.push(o),r.set(R,H)}return Array.from(r.values()).sort((o,d)=>o.label===Xe?-1:d.label===Xe?1:o.label.localeCompare(d.label))},[Wt,wt,Xe,x]),va=a.useMemo(()=>{const r=[],o=new Map;for(const d of Wt)o.set(bt(d[1]),d);for(const d of xs){if(!!(d.root&&Ii({activeGitRepoRoot:de,groupCount:xs.length,label:d.label,rootName:Xe})&&pr.has(d.root)))continue;if(xr!=="tree"){r.push(...d.files);continue}const w=d.files.map(([,R])=>xc(R));for(const R of Mm(w)){const P=o.get(R.key);P&&r.push(P)}}return r},[de,pr,xr,xs,Wt,Xe]);a.useEffect(()=>{if(!yt||va.length===0||ee)return;const r=[],o=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&xa(d))return;const v=document.querySelector("[data-diff-stream-item]"),w=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;if(w){aa.current=w,Qe(w);return}const R=va[0]?.[1];if(!R)return;const P=bt(R);aa.current=P,Qe(P)};for(const d of[80,240,600,1200])r.push(window.setTimeout(o,d));return()=>r.forEach(d=>window.clearTimeout(d))},[yt,ee,va,Qe,xa]);const Wo=a.useMemo(()=>{const r=P=>`'${P.replace(/'/g,"'\\''")}'`,o=Xt.length>0?gn:ae.filter(P=>P.files.length>0),d=o.length>0?o:x?[{root:x,relativeRoot:".",name:Xe}]:[],v=d.length>0?d.map(P=>`- ${P.relativeRoot==="."?".":P.relativeRoot} (${P.root})`).join(`
|
|
1667
1667
|
`):`- ${x?".":""}`,w=d.length>0?d.map(P=>` td audit-export ${r(P.root)}`).join(`
|
|
1668
1668
|
`):" td audit-export",R=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??""}`,"目标仓库:",v,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",w,"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 后批量注入:",R,'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
1669
|
`)},[Xt.length,gn,ae,Xe,x]),th=a.useCallback((r="generate")=>{if(wn&&Fr.length===0&&!de){rn(!0);return}const o=r==="generate"?Wo:[r==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Wo].join(`
|
|
1670
|
-
`);nt("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:Xt,mode:r,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Qr(i("rightSidebar.insertChangeAuditPrompt"),o,`${
|
|
1671
|
-
`))R.startsWith("+++")||R.startsWith("---")||(R.startsWith("+")&&(v+=1),R.startsWith("-")&&(w+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:v,deletions:w,diff:d}};return Pe?(Pe.hunks??[]).map(o=>{const d=Kt.find(v=>v.repoRoot===Pe.repoRoot&&v.baseRef===Pe.baseRef&&(v.branchName??null)===(Pe.currentBranch??null)&&v.filePath===o.filePath&&v.hunkHeader===o.hunkHeader&&(v.hunkIndex??0)===o.hunkIndex&&v.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,hunk:o,current:d,stale:null}}):rt?Kt.filter(o
|
|
1670
|
+
`);nt("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:Xt,mode:r,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Qr(i("rightSidebar.insertChangeAuditPrompt"),o,`${Zl}:${r}`),ir(),c||l()},[de,Wo,Fr.length,Xt,Qr,ir,l,c,x,wn,i]),ya=a.useCallback(async r=>{try{await ed({ids:[r]}),tn(o=>o.filter(d=>d.id!==r))}catch{ir()}},[ir]),rh=a.useCallback(async()=>{if(Ct.length===0)return;const r=Ct.map(o=>o.id);try{await ed({ids:r}),tn(o=>o.filter(d=>!r.includes(d.id))),_r(null)}catch(o){const d=o instanceof Error?o.message:"Failed to clear change audit explanations";_r(i("rightSidebar.changeAuditClearFailed",{message:d})),ir()}},[Ct,ir,i]),nh=a.useCallback(async r=>{if(r.records.length===0)return;const o=r.records.map(d=>d.id);try{await Yh({ids:o}),Br(d=>d.filter(v=>!o.includes(v.id))),rt===r.key&&(on(null),tr(!1))}catch(d){gt(i("rightSidebar.branchAuditClearFailed",{message:d instanceof Error?d.message:"Failed to clear branch explanation"})),la(null)}},[la,rt,i]),sh=a.useCallback(r=>{Cn(o=>r===null?(rn(!1),[]):o.includes(r)?o.filter(d=>d!==r):[...o,r])},[]),ah=a.useCallback(r=>{fo(o=>r===null?(uo(!1),[]):o.includes(r)?o.filter(d=>d!==r):[...o,r])},[]),Go=a.useMemo(()=>{if(!ar)return[];const r=o=>{const d=o.diff??"";let v=0,w=0;for(const R of d.split(`
|
|
1671
|
+
`))R.startsWith("+++")||R.startsWith("---")||(R.startsWith("+")&&(v+=1),R.startsWith("-")&&(w+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:v,deletions:w,diff:d}};return Pe?(Pe.hunks??[]).map(o=>{const d=Kt.find(v=>v.repoRoot===Pe.repoRoot&&v.baseRef===Pe.baseRef&&(v.branchName??null)===(Pe.currentBranch??null)&&v.filePath===o.filePath&&v.hunkHeader===o.hunkHeader&&(v.hunkIndex??0)===o.hunkIndex&&v.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,hunk:o,current:d,stale:null}}):rt?Kt.filter(o=>$d(o)===rt).map(o=>{const d=r(o);return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex??0}`,hunk:d,current:o,stale:null}}):[]},[Pe,Kt,ar,rt]),qo=Kt.length>0,qn=a.useMemo(()=>{if(!ar)return[];const r=new Map;for(const o of Kt){const d=o.repoRoot,v=wt.get(d),w=v?.relativeRoot==="."?Xe:v?.relativeRoot||v?.name||xt(d),R=$d(o),P=r.get(R)??{key:R,repoRoot:d,repoLabel:w,baseRef:o.baseRef,branchName:o.branchName??null,headRef:o.headRef??null,diffFingerprint:o.diffFingerprint??null,records:[],latestInjectedAt:0};P.records.push(o),P.latestInjectedAt=Math.max(P.latestInjectedAt,o.injectedAt??0),r.set(R,P)}return Array.from(r.values()).sort((o,d)=>d.latestInjectedAt-o.latestInjectedAt)},[Kt,wt,ar,Xe]),Ko=a.useMemo(()=>rt?qn.find(r=>r.key===rt)??null:null,[qn,rt]),wa=Pe?{repoRoot:Pe.repoRoot??"",repoLabel:Pe.repoRoot?wt.get(Pe.repoRoot)?.relativeRoot==="."?Xe:wt.get(Pe.repoRoot)?.relativeRoot||wt.get(Pe.repoRoot)?.name||xt(Pe.repoRoot):Xe,baseRef:Pe.baseRef??Pe.baseBranch??"",branchName:Pe.currentBranch??null,headRef:Pe.headRef??null,diffFingerprint:Pe.diffFingerprint??null}:Ko,oh=a.useMemo(()=>(Te?.hunks??[]).map(r=>({key:`${r.filePath}\0${r.hunkHeader}\0${r.hunkIndex}`,hunk:r,current:null,stale:null})),[Te?.hunks]),ih=a.useMemo(()=>{if(Pe)return[];const r=Ko;return r?rs.filter(o=>o.repoRoot===r.repoRoot&&o.baseRef===r.baseRef&&(o.branchName??null)===r.branchName&&(!r.diffFingerprint||o.diffFingerprint===r.diffFingerprint)):[]},[Pe,rs,Ko]),lh=a.useCallback(r=>{const o=Go.find(d=>d.hunk.filePath===r.filePath||(r.repoRoot?`${r.repoRoot}/${d.hunk.filePath}`===r.filePath:!1));o&&(ln(o.key),window.setTimeout(()=>kn(r),90),window.setTimeout(()=>kn(r),320),window.setTimeout(()=>kn(r),760))},[Go]),Vo=a.useMemo(()=>{const r=w=>`'${w.replace(/'/g,"'\\''")}'`,o=Qt,d=o.length>0?o.map(w=>`- ${w.label} (${w.root}),目标分支:${jr[w.root]||w.branch||"(current branch)"},基线分支:${Mt[w.root]||"(not set)"}`).join(`
|
|
1672
1672
|
`):`- ${x?".":""}`,v=o.length>0?o.map(w=>{const R=jr[w.root]||w.branch||"",P=Mt[w.root]||"",H=w.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[R?` git -C ${r(w.root)} switch ${r(R)}`:` # ${w.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${r(P)} ${r(w.root)} > ~/.termdock/branch-audit/branch-audit-export-${H}.json`].join(`
|
|
1673
1673
|
`)}).join(`
|
|
1674
1674
|
`):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${x??""}`,`包含本地未提交更改:${zr?"是":"否"}`,"目标仓库:",d,"","操作指令:",zr?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",v,"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
1675
|
`)},[zr,Qt,Mt,jr,x]),ch=a.useCallback((r="generate")=>{const o=r==="generate"?Vo:[r==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",Vo].join(`
|
|
1676
1676
|
`);Qr(i("rightSidebar.branchAuditShort"),o,`context:branch-audit-scope:${r}`),c||l()},[Vo,Qr,l,c,i]),dh=a.useCallback(async()=>{if(!x||Qt.length===0)return;const r=x;se(!0),Ue(null),rr(null),Be(null);try{const o=await Promise.all(Qt.map(async H=>{const K=Mt[H.root]?.trim();if(!K)throw new Error(i("rightSidebar.branchAuditMissingBase",{repo:H.label}));const Me=(jr[H.root]||H.branch||"").trim();return Xh({cwd:x,repoRoot:H.root,base:K,head:Me&&Me!==H.branch?Me:null,includeUncommitted:zr,requestSlotId:`right-sidebar-branch-preview:${H.root}`})}));if(!Se(r))return;const d=o.find(H=>!H.available);if(d){Ue(d.error??"Branch diff is unavailable");return}const v=o.length===1?o[0]:{available:!0,workspaceRoot:x,repoRoot:x,baseRef:o.map(H=>H.baseRef??H.baseBranch).filter(Boolean).join(", "),currentBranch:o.map(H=>H.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:o.map(H=>H.headRef).filter(Boolean).join(", "),diffFingerprint:o.map(H=>H.diffFingerprint).filter(Boolean).join("+"),stat:o.map(H=>H.stat).filter(Boolean).join(`
|
|
1677
1677
|
`),files:o.flatMap((H,K)=>{const Me=Qt[K];return(H.files??[]).map(Ge=>`${Me?.label??H.repoRoot??"repo"}/${Ge}`)}),hunks:o.flatMap((H,K)=>{const Ge=Qt[K]?.label??H.repoRoot??"repo";return(H.hunks??[]).map(De=>({...De,filePath:`${Ge}/${De.filePath}`,oldPath:De.oldPath?`${Ge}/${De.oldPath}`:De.oldPath,newPath:De.newPath?`${Ge}/${De.newPath}`:De.newPath}))}),commits:o.flatMap(H=>H.commits??[]),commitCount:o.reduce((H,K)=>H+(K.commitCount??K.commits?.length??0),0),diff:o.map(H=>H.diff).filter(Boolean).join(`
|
|
1678
|
-
`),truncated:o.some(H=>H.truncated)};if((v.hunks??[]).length===0){Ue(i("rightSidebar.branchAuditDiffEmpty"));return}const w=Date.now(),R=["preview",v.repoRoot??x,v.baseRef??v.baseBranch??"",v.currentBranch??"",v.headRef??"",v.diffFingerprint??w].join("\0"),P=Qt.length===1?Qt[0].label:`${Qt.length} repos`;rr(v),Nn(H=>[{key:R,diff:v,repoLabel:P,createdAt:w},...H.filter(K=>K.key!==R)].slice(0,8)),A(H=>H[R]===void 0?H:{...H,[R]:0}),on(R),ln(v.hunks?.[0]?`${v.hunks[0].filePath}\0${v.hunks[0].hunkHeader}\0${v.hunks[0].hunkIndex}`:null),tr(!0)}catch(o){if(!Se(r)||Ar(o))return;Ue(o instanceof Error?o.message:"Failed to load branch diff")}finally{Se(r)&&se(!1)}},[zr,Qt,Mt,jr,Se,x,i]),uh=a.useCallback(r=>{rr(r.diff),Ue(null),on(r.key),ln(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),tr(!0)},[]),fh=a.useCallback(r=>{Nn(o=>o.filter(d=>d.key!==r)),A(o=>{if(!(r in o))return o;const d={...o};return delete d[r],d}),rt===r&&(on(null),rr(null),tr(!1))},[rt]),hh=a.useCallback(r=>{const o=qn.find(d=>d.key===r);o&&(rr(null),Ue(null),on(r),ln(o.records[0]?.filePath??null),tr(!0))},[qn]),mh=a.useCallback(async r=>{if(!x||!ve)return;const[o]=r.split(/\s+/);if(o){tt(o),nr(null),Be(null);try{const d=await Jh({cwd:x,repoRoot:ve,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){nr(d.error??"Commit diff is unavailable");return}Be(d);const v=d.hunks?.[0];Us(v?`${v.filePath}\0${v.hunkHeader}\0${v.hunkIndex}`:null)}catch(d){nr(d instanceof Error?d.message:"Failed to load commit diff")}finally{tt(null)}}},[ve,x]),ph=a.useCallback(r=>{if(!Pe||!rt)return;const o=Math.max(0,Math.round(r));A(d=>Math.abs((d[rt]??0)-o)<24?d:{...d,[rt]:o})},[Pe,rt]);a.useEffect(()=>{!ee||!kr||!Pe||hs(1)},[kr,Pe,ee,hs]);const Rc=a.useCallback(r=>{r&&Ef(o=>Em(o,r))},[]),Cc=Zs.key===Je?Zs.key:null,ka=a.useCallback(r=>{const o=Z.getState(),d=Bb();za("select_diff_file",{interactionId:d,path:r,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:de,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),Qe(r),Yt("diff"),ee&&r&&hs(1),Rc(r),queueMicrotask(()=>{const v=Z.getState();za("select_diff_file_after",{interactionId:d,requestedPath:r,selectedFilePath:v.selectedFilePath,rootPath:v.rootPath,rightTab:v.rightTab,changedFiles:v.changedFiles.size,activeGitRepoRoot:de})})},[de,ee,Rc,Qe,Yt,hs]),Nc=a.useCallback(r=>{const o=Array.from(ye.values()).find(d=>{const v=ht(d,x),w=bt(d);return d.path===r.filePath||w===r.filePath||d.absolutePath===r.filePath||(v?`${v}/${d.path}`===r.filePath:!1)||r.repoRoot&&v===r.repoRoot&&d.path===r.filePath});if(o){ka(bt(o)),window.setTimeout(()=>kn(r),90),window.setTimeout(()=>kn(r),320),window.setTimeout(()=>kn(r),760);return}kn(r)},[ye,x,ka]),Mc=a.useCallback(({slideToDetail:r,fullscreen:o,toggleFullscreen:d}={})=>es.length>0?e.jsx(tu,{walkthroughs:es,repoRoot:de,fullscreen:o,onToggleFullscreen:d,onNavigate:v=>{ee&&window.requestAnimationFrame(()=>r?.()),Nc(v)}}):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(Ps,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[de,es,Nc,ee,i]),gh=a.useCallback(r=>{r&&gr(o=>{const d=new Set(o);return d.has(r)?d.delete(r):d.add(r),di(ai,d),d})},[]),Ec=a.useCallback(r=>{br(o=>{const d=new Set(o);return d.has(r)?d.delete(r):d.add(r),di(xd,d),d})},[]),Sa=a.useCallback(r=>{Fs(r),St(vu,r)},[]);a.useEffect(()=>{pa||xr!=="ai"||Sa("tree")},[xr,Sa,pa]);const ja=a.useCallback(()=>{Zn(r=>{const o=!r;return St(yu,o),o})},[]),$c=a.useCallback(r=>{Bs(r),St(wu,r)},[]),{whitespace:Lc,context:Ac}=Lm(),Pc=a.useMemo(()=>({algorithm:"histogram",whitespace:Lc,context:Ac}),[Lc,Ac]),Tc=a.useCallback(r=>{V(r),St(ku,r)},[]),Ra=a.useCallback(async(r,o,d,v)=>{let w=r;for(;w.ok&&w.status==="running";)await new Promise(P=>window.setTimeout(P,1500)),w=await ed({jobId:w.jobId,cwd:o.cwd,action:o.action});if(!w.ok)throw new Error("Git action status is unavailable");if(w.status==="error")throw new Error(w.error||w.message||"Git action failed");const R={action:o.action,path:v,label:d};return cs(R),window.setTimeout(()=>cs(P=>P?.action===R.action&&P.path===R.path?null:P),1400),w},[]),ft=a.useCallback(async(r,o,d)=>{const v=x;x&&or.current.delete(x),gt(null),cs(null),ls({action:r.action,path:d});try{const w=await Qh({...r,includeNested:Vn(x)}),R=await Ra(w,r,o,d);if(!Se(v))return!1;const P=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>R.bundle):R.bundle;return Se(v)?(P&&Xr(P,{reloadDiff:!0,cacheOnly:!0}),Gr(null),!0):!1}catch(w){return cs(null),gt(i("rightSidebar.gitActionFailed",{message:w instanceof Error?w.message:"Unknown error"})),!1}finally{Se(v)&&ls(null)}},[Xr,Se,x,i,Ra]),Ic=a.useCallback(async r=>{const o=x,d=await Zh({...r,includeNested:Vn(x)});if(!Se(o))return;const v=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>d.bundle):d.bundle;Se(o)&&v&&Xr(v,{reloadDiff:!0,cacheOnly:!0})},[Xr,Se,x]),Ca=a.useCallback((r,o,d)=>{if(o){if(r==="stage-all"){ft({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}Gr({kind:"stash-all",repoRoot:o,repoLabel:d})}},[ft,i]),Dc=a.useCallback(r=>{Ae(r),ci(x,r),Vs(""),Ys(""),Xs(""),Qe(lc(r)),Ze||Yt("diff"),r&&r!==x&&ae.find(d=>d.root===r)?.deferred&&Jt(r,{includeNested:!1,background:!0,replaceRepoRoot:r})},[lc,Ze,ae,Jt,x,Qe,Yt]),_c=a.useCallback(r=>{const o=new Set([...Ut.current.keys(),...mn.current,...or.current]);for(const d of o)d!==r&&(Ot.current.delete(d),Ut.current.get(d)?.abort(),Ut.current.delete(d),kt(`right-sidebar-git-untracked:${d}`),mn.current.delete(d),or.current.delete(d))},[]),bh=a.useCallback(async r=>{const o=x;if(!o||(await Z.getState().setNestedGitScanRoot(o,r),!Se(o)))return;if(r){await Jt(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}_c(o),Vs(""),Ys(""),Xs(""),fo(v=>v.filter(w=>w===o));const d=Ht;d&&ht(d,o)!==o&&Qe(null),await Jt(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[_c,Se,Jt,x,Qe,Ht]),xh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=Pn.trim();!r||r===ie?.branch||await ft({action:"switch-branch",cwd:ve,branch:r},i("rightSidebar.switchBranch"))},[ie?.branch,ve,Ve,ft,Pn,i]),Fc=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=Ks.trim();if(!r)return;await ft({action:"commit",cwd:ve,message:r},i("rightSidebar.commitChanges"))&&bl("")},[ve,Ks,Ve,ft,i]),vh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=dn.trim(),o=un.trim();await ft({action:"push",cwd:ve,...r?{remote:r}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[ve,un,dn,Ve,ft,i]),yh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=dn.trim(),o=un.trim();await ft({action:"pull",cwd:ve,...r?{remote:r}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[ve,un,dn,Ve,ft,i]);a.useEffect(()=>{if(!Ze||!ve||Ie)return;let r=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const v=await ed({cwd:ve,action:d}).catch(()=>null);if(!v?.ok||v.status!=="running")continue;const w={action:d,cwd:ve},R=o[d]??d;ls({action:d});try{const P=await Ra(v,w,R);if(r||!Se(x))return;const H=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>P.bundle):P.bundle;H&&Xr(H,{reloadDiff:!0,cacheOnly:!0})}catch(P){r||gt(i("rightSidebar.gitActionFailed",{message:P instanceof Error?P.message:"Unknown error"}))}finally{r||ls(null)}return}})(),()=>{r=!0}},[ve,Xr,Ze,Se,x,Ie,i,Ra]);const Yo=Ln?.action==="commit",Xo=Ln?.action==="switch-branch",Jo=Ln?.action==="pull",Qo=Ln?.action==="push",Na=Ze||Nf,Zo=ba?i("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,wh=cr.length>0,Bc=Qt.length>0,kh=x?e.jsx(_d,{open:co,onOpenChange:uo,showScopePicker:!0,selectedAll:ba,repos:zt,selectedRoots:ga,onToggleRepo:ah,onGenerate:()=>ch(qo?"regenerate":"generate"),disabled:!wh,generateDisabled:!Bc,inserted:we?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Zo,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{dh()},secondaryDisabled:!Bc||W,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:W,loading:cl.size>0,statusTitle:cl.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:zr,onChange:r=>ll(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),hc.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:i("rightSidebar.missingBaseReposSkipped",{repositories:hc.map(r=>r.label).join(O==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const o=wt.get(r.root),d=[],v=new Set,w=(K,Me)=>{!K||v.has(K)||(v.add(K),d.push({value:K,label:K,meta:Me}))};w(jr[r.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const K of o?.context?.branches??[])w(K,K===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const K of o?.context?.remoteBranches??[])w(K,i("rightSidebar.remoteBranch"));const R=[],P=new Set,H=(K,Me)=>{!K||P.has(K)||(P.add(K),R.push({value:K,label:K,meta:Me}))};H(Mt[r.root],Mt[r.root]?i("rightSidebar.pushUpstreamBadge"):void 0),H(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const K of o?.context?.remoteBranches??[])H(K,"remote");for(const K of o?.context?.branches??[])H(K,K===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Yn,{label:i("rightSidebar.currentBranchLabel"),value:jr[r.root]||o?.context?.branch||"",options:d,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:K=>{zs(Me=>({...Me,[r.root]:K}))}}),e.jsx(Yn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Mt[r.root]||"",options:R,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:K=>{Ws(Me=>({...Me,[r.root]:K}))}})]})}}):null,Oc=Ss(Ct.reduce((r,o)=>Math.max(r,o.injectedAt??0),0),O),Sh=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:()=>il(r=>{const o=!r;return St(oi,o),o}),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":is,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(Ps,{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:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Zo})]}),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 ${is?"rotate-90":""}`,children:e.jsx($a,{size:13})})]}),is&&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:[i("rightSidebar.changeAuditScopeLabel"),": ",Zo]}),kh]}),ke&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:ke}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[nn.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>uh(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:i("rightSidebar.branchAuditViewDiff")})]}),Ss(r.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Ss(r.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>fh(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(Wa,{size:12})})]},r.key)),qn.length>0?qn.slice(0,Math.max(0,8-nn.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>hh(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),Ss(r.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Ss(r.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{nh(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(Wa,{size:12})})]},r.key)):nn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Uc=ar&&x&&Gn?e.jsxs("div",{className:Na?"overflow-visible":"overflow-hidden",children:[Sh,e.jsxs("button",{type:"button",onClick:()=>{Ze||Mf(r=>{const o=!r;return o&&ve&&!Gn&&!cn&&$o(ve),o})},"aria-expanded":Na,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${Ze?"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(Lr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("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 ${yn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[cn&&e.jsx(jt,{size:10,className:"animate-spin"}),yn.staged>0?i("rightSidebar.stagedCount",{count:yn.staged}):i("rightSidebar.noStagedChangesShort")]}),!Ze&&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 ${Na?"rotate-90":""}`,children:e.jsx($a,{size:13})})]})]}),Na&&e.jsxs("div",{className:"space-y-0",children:[It.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:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Wf})]})}),e.jsx(Yn,{label:i("rightSidebar.gitRepositoryLabel"),value:ve??"",options:It,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!Ie,onChange:r=>{Dc(r||null)}}),Ve&&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:i("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:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Pn!==ic?ic:null})]}),e.jsxs("button",{type:"button",onClick:()=>{xh()},disabled:!eh,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 ${Xo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ie?.action==="switch-branch"||Xo?"opacity-0":"",children:i("rightSidebar.switchBranch")}),Ie?.action==="switch-branch"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Xo&&Ie?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Yn,{label:i("rightSidebar.currentBranchLabel"),value:Pn,options:Kf,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!Ie,onChange:Vs})]}),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:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Ve?i("rightSidebar.selectRepositoryForGitActions"):yn.staged>0?i("rightSidebar.commitReadyHint",{count:yn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Fc()},disabled:!!Ie||Ve||yn.staged===0||!Ks.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 ${Yo?"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:Ve?i("rightSidebar.selectRepositoryForGitActions"):yn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ie?.action==="commit"||Yo?"opacity-0":"",children:i("rightSidebar.commitChanges")}),Ie?.action==="commit"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Yo&&Ie?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Ks,onChange:r=>bl(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),Fc())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!Ie,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:()=>Mn(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Vt,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[He&&e.jsx(jt,{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 ${Vt?"rotate-90":""}`,children:e.jsx($a,{size:13})})]})]}),Vt&&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(Jn,{size:12,className:"shrink-0"}),e.jsx("input",{value:as,onChange:r=>sn(r.target.value),placeholder:i("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}),as&&e.jsx("button",{type:"button",onClick:()=>sn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Gt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Gf,children:[an.length>0?an.map(r=>{const[o,...d]=r.split(/\s+/),v=d.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{mh(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:v,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:v,children:v}),Sr[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Sr[o]==="ahead"?"bg-accent/10 text-accent":Sr[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Sr[o]==="ahead"?"rightSidebar.commitAhead":Sr[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),We===o&&e.jsx(jt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):He?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),Ur&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(jt,{size:12,className:"animate-spin"})}),lo&&!Ur&&an.length>0&&e.jsx("button",{type:"button",onClick:()=>{bs({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:i("rightSidebar.recentCommitsLoadMore")})]})]}),Nt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Nt}),al&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:al})]}),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:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{yh()},disabled:!Qf,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 ${Jo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ie?.action==="pull"||Jo?"opacity-0":"",children:i("rightSidebar.pullChanges")}),Ie?.action==="pull"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Jo&&Ie?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{vh()},disabled:!Zf,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 ${Qo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ie?.action==="push"||Qo?"opacity-0":"",children:i("rightSidebar.pushChanges")}),Ie?.action==="push"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Qo&&Ie?.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] ${pc.className}`,title:ie?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:pc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ie?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${fc?"grid-cols-2":"grid-cols-1"}`,children:[fc&&e.jsx(Yn,{label:i("rightSidebar.pushRemoteLabel"),value:dn,options:uc,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!Ie,onChange:Ys}),e.jsx(Yn,{label:i("rightSidebar.pushBranchLabel"),value:un,options:Vf,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:ie?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!Ie,onChange:Xs})]})]})]})]}):null,jh=a.useCallback(r=>{const o=ht(r,x);if(!o)return[];const d=xi(r),v=[];return r.canStage&&v.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{ft({action:"stage-file",cwd:o,paths:[r.path]},i("rightSidebar.stageFile"),d)}}),r.canUnstage&&v.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{ft({action:"unstage-file",cwd:o,paths:[r.path]},i("rightSidebar.unstageFile"),d)}}),r.canStash&&v.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{ft({action:"stash-file",cwd:o,paths:[r.path]},i("rightSidebar.stashFile"),d)}}),r.canRestoreWorktree&&v.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Gr({kind:"restore",file:r,phrase:""})}),v},[x,ft,i]),Rh=a.useCallback(()=>{if(g){S?.();return}Cr(0),Mr.current?.slideTo(0),Rr(!1),mt(null)},[S,g]),Hc=a.useCallback(r=>{if(q(""),Bt(r),Qe(null),mt(null),ne(null),ee){g&&S?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1);return}},[ee,S,g,Qe,Bt]);a.useEffect(()=>{const r=o=>{const d=o.detail,v=d?.path;if(typeof v!="string"||!v.startsWith("/"))return;q(""),mt(null),Lt(null);const w=!!(x&&(v===x||v.startsWith(`${x}/`)));if(d.kind==="file"){const R=pi(v);ms(v),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Lt(d.line),Bt(w?null:R),ne(P=>({path:v,nonce:(P?.nonce??0)+1}));return}Qe(null),w?(Bt(null),ne(R=>({path:v,nonce:(R?.nonce??0)+1}))):(ne(null),Bt(v)),ee&&(g&&S?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1))};return window.addEventListener(ad,r),()=>window.removeEventListener(ad,r)},[ms,ee,S,g,x,Qe,Bt]),a.useEffect(()=>{t||(_t(!1),hr(!1))},[t]),a.useEffect(()=>{if(!ur&&!fr)return;const r=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(_t(!1),hr(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[fr,ur]);const zc=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:Uf,disabled:!fa,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":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(Xd,{size:14})}),e.jsx("button",{type:"button",onClick:Zl,disabled:!x||In===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":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(od,{size:14})}),e.jsx("button",{type:"button",onClick:Hf,disabled:!me,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":i("rightSidebar.refreshFiles"),title:xl?i("rightSidebar.fileWatchUnavailable",{message:xl}):i("rightSidebar.refreshFiles"),children:e.jsx(ji,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:me??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:Bf}),na==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(id,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>me&&Jr(me,Tt??void 0),disabled:!me,...me&&Tt?Io(ua(me),Tt):{},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 ${Tt&&(we===Tt||et===Tt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Tt&&et===Tt?"rightSidebar.copied":Tt&&we===Tt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Tt&&(we===Tt||et===Tt)?e.jsx(ki,{size:13}):e.jsx(Va,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{_t(!1),hr(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${fr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":fr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Si,{size:14})}),fr&&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:()=>{hr(!1),zf()},disabled:!Fo,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${gs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[gs?e.jsx(ri,{size:14}):e.jsx(Aa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(gs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),Lf()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${ko?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ko?e.jsx(Im,{size:14}):e.jsx(Ni,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(ko?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!me,onClick:()=>{me&&(hr(!1),Af(me,na==="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:[na==="modified"?e.jsx(bm,{size:14}):e.jsx(id,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(na==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),x&&(ha.length>0||Of)&&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:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Zl,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 ${me===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(od,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Xe})]}),ha.map(r=>{const o=r.path,d=r.kind==="file",v=d?Je===o:me===o;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${v?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o,children:[e.jsxs("button",{type:"button",onClick:()=>d?ms(o):Bt(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(Mi,{size:10,className:"shrink-0"}):e.jsx(Aa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:xt(o)})]}),e.jsx("button",{type:"button",onClick:()=>fn(o),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":i("rightSidebar.unpinFolder",{name:xt(o)}),title:i("rightSidebar.unpinFolder",{name:xt(o)}),children:e.jsx(Gt,{size:9})})]},o)})]}),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"})]}),ei=a.useMemo(()=>{if(An===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((bo-An)/1e3)),d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[v,w]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return d.format(v,w)},[bo,An]),Wc=x&&!Hn?e.jsx("button",{type:"button",onClick:()=>{bh(!So)},"aria-pressed":So,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${So?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,Gc=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[ei?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:ei}),children:ei}):null,e.jsx("button",{type:"button",onClick:()=>{fs()},disabled:qr,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":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx(ji,{size:13,className:qr?"animate-spin":""})})]}):null,Ch=Ol?i("rightSidebar.changeAuditScopeAll"):gn.length===1?gn[0].relativeRoot==="."?Xe:gn[0].relativeRoot||gn[0].name:`${gn.length} repos`,qc=x?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(_d,{open:ts,onOpenChange:rn,showScopePicker:wn,selectedAll:Ol,repos:Pf,selectedRoots:Xt,onToggleRepo:sh,onGenerate:()=>th(),disabled:!x,inserted:we===Ql,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Ch,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:Dr,error:!!wr,statusTitle:wr??(Dr?i("rightSidebar.changeAuditLoading"):Ct.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Ct.length})}${Oc?` · ${i("rightSidebar.changeAuditLoadedAt",{time:Oc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{rh()},disabled:Dr||Ct.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Ct.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(Wa,{size:12})})]}):null,Ma=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:[k?.available&&k.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:k.branch,children:[e.jsx(Lr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:k.branch})]}),dt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[dt.modified,"M"]}),dt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",dt.added]}),dt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",dt.deleted]}),dt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.renamed,"R"]}),dt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.copied,"C"]}),dt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.untracked,"U"]}),dt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[dt.conflicted,"!"]}),dt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.other,"?"]}),dt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:dt.staged})}),k?.available&&x&&ye.size>0&&ae.length<=1&&e.jsx("button",{type:"button",onClick:()=>{ft({action:"stage-all",cwd:x},i("rightSidebar.stageAll"))},disabled:!!Ie,className:"rounded-md bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),k?.available&&x&&ye.size>0&&ae.length<=1&&e.jsx("button",{type:"button",onClick:()=>Gr({kind:"stash-all",repoRoot:x,repoLabel:Xe}),disabled:!!Ie,className:"rounded-md bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]});return e.jsxs(xm,{side:"right",isOpen:t,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h,children:[Io.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:x??void 0,children:Xe}),(!ee||po)&&k?.available&&k.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:k.branch,children:[e.jsx(Lr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:k.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!ue;G(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):q("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ue?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Jn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":lt,onClick:()=>{ct(r=>!r),Dt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${lt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(vm,{size:14}),!lt&&be.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:kl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const o=r.target.files;!o||o.length===0||(ps(Array.from(o)),r.target.value="")}}),e.jsx("input",{ref:Sl,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const o=r.target.files?.[0];r.target.value="",o&&Ff(o)}}),m&&e.jsx("button",{type:"button",onClick:m,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":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(ri,{size:14}):e.jsx(Aa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{hr(!1),_t(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${ur?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":ur,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Si,{size:15})}),ur&&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":Wr,onClick:()=>_f(!Wr),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:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Wr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Wr?"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:()=>{_t(!1),kl.current?.click()},disabled:Js,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:[Js?e.jsx(jt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Ym,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),Sl.current?.click()},disabled:Js,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:[Js?e.jsx(jt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Bm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),m&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),m()},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(ri,{size:14}):e.jsx(Aa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(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":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("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",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([r,o])=>{const d=Y===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{L(r),_t(!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:o},r)})})]})]})]}),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":i("rightSidebar.close"),children:e.jsx(Gt,{size:14})})]}),ue&&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(Jn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:j,onChange:r=>q(r.target.value),placeholder:i(_==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Tc("name"),"aria-pressed":_==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${_==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Tc("content"),"aria-pressed":_==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${_==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),j&&e.jsx("button",{type:"button",onClick:()=>q(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Gt,{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(ym,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:te,onChange:r=>oe(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),te!=="."&&e.jsx("button",{type:"button",onClick:()=>oe("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Gt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>M(r=>!r),"aria-expanded":$e,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${$e||ds.length>0||J||Re||Ce?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(wm,{size:13}),ds.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:ds.length})]})]}),$e&&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:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ge,onChange:r=>he(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ge&&e.jsx("button",{type:"button",onClick:()=>he(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Gt,{size:11})})]}),_==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[J,()=>fe(r=>!r),Pm,i("rightSidebar.matchCase")],[Re,()=>qe(r=>!r),Jm,i("rightSidebar.matchWholeWord")],[Ce,()=>ce(r=>!r),Gm,i("rightSidebar.useRegex")]].map(([r,o,d,v])=>e.jsxs("button",{type:"button",onClick:o,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),v]},v))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Hn?2:3)+(Wr?1:0)}, minmax(0, 1fr))`},children:[!Hn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>Yt("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Lr,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>Yt("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(lu,{size:12}),i("rightSidebar.tabChanges"),ye.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:ye.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>Yt("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Nm,{size:12}),i("rightSidebar.tabFiles")]}),Wr&&e.jsxs("button",{type:"button",onClick:()=>Yt("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(td,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),pl&&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:pl})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ua,{active:Ze,mounted:ar,fallback:e.jsx(mi,{slow:!1}),children:Te?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(dd,{items:oh,selectedKey:wf,onSelect:Us,emptyText:i("rightSidebar.noChanges"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${Te.headRef??""}${Te.commits?.[0]?` · ${Te.commits[0]}`:""}`,onClose:()=>{Be(null),Us(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?ja:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya})}):kr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(dd,{items:Go,selectedKey:ho,onSelect:ln,emptyText:i(Pe?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(Pe?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:wa?`${wa.repoLabel} · ${wa.branchName??"HEAD"} → ${wa.baseRef}`:void 0,onClose:()=>{tr(!1),rr(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?ja:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,walkthroughs:ih,onWalkthroughNavigate:lh,initialDetailScrollTop:Pe&&rt?ss[rt]:void 0,onDetailScrollPositionChange:ph,externalSwiperRef:ee?ia:void 0,onMobileSlideChange:ee?mo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:Uc?e.jsx("div",{className:"px-3",children:Uc}):qr?e.jsx(mi,{slow:Ll}):hn?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):zd(k)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):k?.available===!1?e.jsx(Ha,{message:k.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{fs()}}):x?e.jsx(mi,{slow:Ll}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ua,{active:zn,children:ee?e.jsxs(Qd,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{Mr.current=r,r.slideTo(ul,0)},onSlideChange:r=>{if(Cr(r.activeIndex),us.current===r.activeIndex){us.current=null;return}r.activeIndex===0&&(Rr(!1),mt(null),S?.())},children:[e.jsx(Ri,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Fn,onScroll:Hl,onDragOver:ca,onDragEnter:ca,onDragLeave:Gl,onDrop:ql,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:i("rightSidebar.dropToUpload")})}),!j.trim()&&zc,e.jsx(ld,{rootPath:me??"",onFileSelect:ms,onPathReference:Jr,getReferenceText:ua,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onDirectoryRoot:ec,onSearchFromDirectory:tc,onDirectoryPinToggle:rc,onFilePinToggle:nc,pinnedPaths:xn,selectedFilePath:Je,query:xe,searchRootPath:Il,searchOptions:Dl,searchMode:_,onContentMatchSelect:zl,onDirectoryDropFiles:(r,o)=>ps(o,r),revealDirectory:le,canOpenInFileBrowser:yl,onOpenInFileBrowser:Wl})]})}),e.jsx(Ri,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Gi,{filePath:zn&&(kf||ul===1)?Je:null,onInsertReference:Jr,onInsertText:$r,onInsertFeature:$r,onReviewReference:Xl,onReferenceCopied:Er,onClose:Rh,onDirectoryLinkOpen:Hc,isMobile:!0,lineRange:Rn,onLineRangeChange:mt,insertedReferenceKey:we,copiedReferenceKey:et,scrollToLine:Oe,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Fn,onScroll:Hl,onDragOver:ca,onDragEnter:ca,onDragLeave:Gl,onDrop:ql,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:vo},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:i("rightSidebar.dropToUpload")})}),!j.trim()&&zc,e.jsx(ld,{rootPath:me??"",onFileSelect:ms,onPathReference:Jr,getReferenceText:ua,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onDirectoryRoot:ec,onSearchFromDirectory:tc,onDirectoryPinToggle:rc,onFilePinToggle:nc,pinnedPaths:xn,selectedFilePath:Je,query:xe,searchRootPath:Il,searchOptions:Dl,searchMode:_,onContentMatchSelect:zl,onDirectoryDropFiles:(r,o)=>ps(o,r),revealDirectory:le,canOpenInFileBrowser:yl,onOpenInFileBrowser:Wl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("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:Tf,onPointerMove:If,onPointerUp:Ul,onPointerCancel:Ul,onDoubleClick:()=>{yo(Pi),St(js,Pi)},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(Gi,{filePath:zn?Je:null,onInsertReference:Jr,onInsertText:$r,onInsertFeature:$r,onReviewReference:Xl,onReferenceCopied:Er,onDirectoryLinkOpen:Hc,isMobile:!1,lineRange:Rn,onLineRangeChange:mt,insertedReferenceKey:we,copiedReferenceKey:et,scrollToLine:Oe,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})]})}),e.jsx(Ua,{active:yt,mounted:Sf||yt,children:()=>Lo?e.jsx(km,{}):ee?e.jsx(Ci,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:ia,onMobileSlideChange:mo,groups:Wt.length>0?kc():[],mode:xr,onModeChange:Sa,selectedKey:Je,scrollToKey:Cc,scrollToKeyNonce:Zs.nonce,compact:!1,collapsedDirectoryKeys:_s,onToggleDirectory:Ec,onSelectFile:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);o&&ka(bt(o))},renderLeading:jc,renderTrailing:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?yc(o):null},renderDirectoryTrailing:wc,renderSubtitle:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?xc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ma&&e.jsx("div",{className:"mb-2",children:Ma}),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:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Wt.length,"/",ye.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[gc(),Wc,r,h&&zo(),qc,Gc]}),Et&&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:Et.label}),Et.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:Et.branch})]}),!Et&&wn&&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(Lr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:pa?(r=>Mc(r)):void 0,emptyContent:Lo?null:hn&&ye.size===0?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Wt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>hs(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:i("rightSidebar.backToChangeList"),children:[e.jsx($s,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[h&&zo(),e.jsxs("button",{type:"button",onClick:ja,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:Sc(),activePane:yt,wrap:At,diffViewType:$f,inlineMode:vr,diffOptions:Pc,reloadKey:Os,renderStreamBadge:r=>e.jsx(Ns,{status:r}),onHunkGitAction:Ic,onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,onDetailScroll:xa}):e.jsx(Ci,{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:i("rightSidebar.backToChangeList"),groups:Wt.length>0?kc():[],mode:xr,onModeChange:Sa,selectedKey:Je,scrollToKey:Cc,scrollToKeyNonce:Zs.nonce,compact:!0,collapsedDirectoryKeys:_s,onToggleDirectory:Ec,onSelectFile:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);o&&ka(bt(o))},renderLeading:jc,renderTrailing:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?yc(o):null},renderDirectoryTrailing:wc,renderSubtitle:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?xc(o):null},aiContent:pa?(r=>Mc(r)):void 0,emptyContent:Lo?null:hn&&ye.size===0?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Wt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ma&&e.jsx("div",{className:"mb-2",children:Ma}),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:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Wt.length,"/",ye.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[gc(),Wc,r,zo(),e.jsxs("button",{type:"button",onClick:ja,"aria-pressed":At,title:i("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 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),qc,Gc]}),Et&&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:Et.label}),Et.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:Et.branch}),e.jsx("button",{type:"button",onClick:()=>Ca("stage-all",Et.root,Et.label),disabled:!!Ie,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:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>Ca("stash-all",Et.root,Et.label),disabled:!!Ie,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:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]}),!Et&&wn&&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(Lr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:Sc(),activePane:yt,wrap:At,diffViewType:Ft,inlineMode:vr,diffOptions:Pc,reloadKey:Os,renderStreamBadge:r=>e.jsx(Ns,{status:r}),onHunkGitAction:Ic,onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,onDetailScroll:xa})}),e.jsx(Ua,{active:Ao,mounted:jf&&Wr,children:Rf?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:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>Vc.getState().setDock(nd,null),className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Sm,{sessionId:n??null})})]}),t&<&&e.jsx(kp,{value:be,collapsed:Pr,autoCollapseAfterSend:z,focusRequest:ut,insertError:Tr?i("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{mr(!1),ze(r)},onCollapsedChange:Dt,onAutoCollapseAfterSendChange:re,onDisable:()=>ct(!1),onClear:()=>ze(""),onInsert:()=>Jl(!1),onInsertAndSend:()=>Jl(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>i("rightSidebar.contextDraftCharacterCount",{count:r})}}),Jf(),pt&&typeof document<"u"&&en.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Gr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:pt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:pt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:Yd(pt.file.absolutePath,x)}):i("rightSidebar.confirmStashAllDescription")}),pt.kind==="restore"&&e.jsx("input",{value:pt.phrase,onChange:r=>Gr({...pt,phrase:r.target.value}),placeholder:i("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:()=>Gr(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:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ie||pt.kind==="restore"&&pt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(pt.kind==="restore"){const r=ht(pt.file,x);if(!r)return;ft({action:"restore-worktree-file",cwd:r,paths:[pt.file.path],confirm:{acknowledged:!0,phrase:pt.phrase}},i("rightSidebar.restoreFile"),xi(pt.file))}else{const r=pt.repoRoot??x;if(!r)return;ft({action:"stash-all",cwd:r},i("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${pt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(Ie?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const ex=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Gi,MarkdownImageLightbox:lf,MarkdownPreview:cf,RightSidebar:Hb,__testParseMarkdownListBlock:ab,buildMarkdownPreviewBlocks:gb,buildMarkdownPreviewRenderResult:rl,collectKnownGitRepoRoots:Au,computeMarkdownImageDisplayBox:Wu,getMarkdownHeadingOutline:of,getMarkdownHeadingPathAtLine:af,getNextMarkdownPreviewLineRange:kb,isSvgImageSrc:so,mountRightSidebarRepoPickerOverlay:bu,replaceGitRepositorySnapshot:pf,resolveMarkdownLocalLinkTarget:Xi,resolveRightSidebarDiffViewType:Eu,shouldCloseMarkdownImageLightboxDrag:rf,showsGitRepoGroupHeader:Ti},Symbol.toStringTag,{value:"Module"}));export{Ni as E,Um as M,ex as R,Im as a,zm as b,ep as c,Zb as m};
|
|
1678
|
+
`),truncated:o.some(H=>H.truncated)};if((v.hunks??[]).length===0){Ue(i("rightSidebar.branchAuditDiffEmpty"));return}const w=Date.now(),R=["preview",v.repoRoot??x,v.baseRef??v.baseBranch??"",v.currentBranch??"",v.headRef??"",v.diffFingerprint??w].join("\0"),P=Qt.length===1?Qt[0].label:`${Qt.length} repos`;rr(v),Nn(H=>[{key:R,diff:v,repoLabel:P,createdAt:w},...H.filter(K=>K.key!==R)].slice(0,8)),A(H=>H[R]===void 0?H:{...H,[R]:0}),on(R),ln(v.hunks?.[0]?`${v.hunks[0].filePath}\0${v.hunks[0].hunkHeader}\0${v.hunks[0].hunkIndex}`:null),tr(!0)}catch(o){if(!Se(r)||Ar(o))return;Ue(o instanceof Error?o.message:"Failed to load branch diff")}finally{Se(r)&&se(!1)}},[zr,Qt,Mt,jr,Se,x,i]),uh=a.useCallback(r=>{rr(r.diff),Ue(null),on(r.key),ln(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),tr(!0)},[]),fh=a.useCallback(r=>{Nn(o=>o.filter(d=>d.key!==r)),A(o=>{if(!(r in o))return o;const d={...o};return delete d[r],d}),rt===r&&(on(null),rr(null),tr(!1))},[rt]),hh=a.useCallback(r=>{const o=qn.find(d=>d.key===r);o&&(rr(null),Ue(null),on(r),ln(o.records[0]?.filePath??null),tr(!0))},[qn]),mh=a.useCallback(async r=>{if(!x||!ve)return;const[o]=r.split(/\s+/);if(o){tt(o),nr(null),Be(null);try{const d=await Jh({cwd:x,repoRoot:ve,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){nr(d.error??"Commit diff is unavailable");return}Be(d);const v=d.hunks?.[0];Us(v?`${v.filePath}\0${v.hunkHeader}\0${v.hunkIndex}`:null)}catch(d){nr(d instanceof Error?d.message:"Failed to load commit diff")}finally{tt(null)}}},[ve,x]),ph=a.useCallback(r=>{if(!Pe||!rt)return;const o=Math.max(0,Math.round(r));A(d=>Math.abs((d[rt]??0)-o)<24?d:{...d,[rt]:o})},[Pe,rt]);a.useEffect(()=>{!ee||!kr||!Pe||hs(1)},[kr,Pe,ee,hs]);const Cc=a.useCallback(r=>{r&&Ef(o=>Em(o,r))},[]),Nc=Zs.key===Je?Zs.key:null,ka=a.useCallback(r=>{const o=Z.getState(),d=Bb();za("select_diff_file",{interactionId:d,path:r,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:de,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),Qe(r),Yt("diff"),ee&&r&&hs(1),Cc(r),queueMicrotask(()=>{const v=Z.getState();za("select_diff_file_after",{interactionId:d,requestedPath:r,selectedFilePath:v.selectedFilePath,rootPath:v.rootPath,rightTab:v.rightTab,changedFiles:v.changedFiles.size,activeGitRepoRoot:de})})},[de,ee,Cc,Qe,Yt,hs]),Mc=a.useCallback(r=>{const o=Array.from(ye.values()).find(d=>{const v=ht(d,x),w=bt(d);return d.path===r.filePath||w===r.filePath||d.absolutePath===r.filePath||(v?`${v}/${d.path}`===r.filePath:!1)||r.repoRoot&&v===r.repoRoot&&d.path===r.filePath});if(o){ka(bt(o)),window.setTimeout(()=>kn(r),90),window.setTimeout(()=>kn(r),320),window.setTimeout(()=>kn(r),760);return}kn(r)},[ye,x,ka]),Ec=a.useCallback(({slideToDetail:r,fullscreen:o,toggleFullscreen:d}={})=>es.length>0?e.jsx(tu,{walkthroughs:es,repoRoot:de,fullscreen:o,onToggleFullscreen:d,onNavigate:v=>{ee&&window.requestAnimationFrame(()=>r?.()),Mc(v)}}):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(Ps,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[de,es,Mc,ee,i]),gh=a.useCallback(r=>{r&&gr(o=>{const d=new Set(o);return d.has(r)?d.delete(r):d.add(r),di(ai,d),d})},[]),$c=a.useCallback(r=>{br(o=>{const d=new Set(o);return d.has(r)?d.delete(r):d.add(r),di(vd,d),d})},[]),Sa=a.useCallback(r=>{Fs(r),St(vu,r)},[]);a.useEffect(()=>{pa||xr!=="ai"||Sa("tree")},[xr,Sa,pa]);const ja=a.useCallback(()=>{Zn(r=>{const o=!r;return St(yu,o),o})},[]),Lc=a.useCallback(r=>{Bs(r),St(wu,r)},[]),{whitespace:Ac,context:Pc}=Lm(),Tc=a.useMemo(()=>({algorithm:"histogram",whitespace:Ac,context:Pc}),[Ac,Pc]),Ic=a.useCallback(r=>{V(r),St(ku,r)},[]),Ra=a.useCallback(async(r,o,d,v)=>{let w=r;for(;w.ok&&w.status==="running";)await new Promise(P=>window.setTimeout(P,1500)),w=await td({jobId:w.jobId,cwd:o.cwd,action:o.action});if(!w.ok)throw new Error("Git action status is unavailable");if(w.status==="error")throw new Error(w.error||w.message||"Git action failed");const R={action:o.action,path:v,label:d};return cs(R),window.setTimeout(()=>cs(P=>P?.action===R.action&&P.path===R.path?null:P),1400),w},[]),ft=a.useCallback(async(r,o,d)=>{const v=x;x&&or.current.delete(x),gt(null),cs(null),ls({action:r.action,path:d});try{const w=await Qh({...r,includeNested:Vn(x)}),R=await Ra(w,r,o,d);if(!Se(v))return!1;const P=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>R.bundle):R.bundle;return Se(v)?(P&&Xr(P,{reloadDiff:!0,cacheOnly:!0}),Gr(null),!0):!1}catch(w){return cs(null),gt(i("rightSidebar.gitActionFailed",{message:w instanceof Error?w.message:"Unknown error"})),!1}finally{Se(v)&&ls(null)}},[Xr,Se,x,i,Ra]),Dc=a.useCallback(async r=>{const o=x,d=await Zh({...r,includeNested:Vn(x)});if(!Se(o))return;const v=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>d.bundle):d.bundle;Se(o)&&v&&Xr(v,{reloadDiff:!0,cacheOnly:!0})},[Xr,Se,x]),Ca=a.useCallback((r,o,d)=>{if(o){if(r==="stage-all"){ft({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}Gr({kind:"stash-all",repoRoot:o,repoLabel:d})}},[ft,i]),_c=a.useCallback(r=>{Ae(r),ci(x,r),Vs(""),Ys(""),Xs(""),Qe(cc(r)),Ze||Yt("diff"),r&&r!==x&&ae.find(d=>d.root===r)?.deferred&&Jt(r,{includeNested:!1,background:!0,replaceRepoRoot:r})},[cc,Ze,ae,Jt,x,Qe,Yt]),Fc=a.useCallback(r=>{const o=new Set([...Ut.current.keys(),...mn.current,...or.current]);for(const d of o)d!==r&&(Ot.current.delete(d),Ut.current.get(d)?.abort(),Ut.current.delete(d),kt(`right-sidebar-git-untracked:${d}`),mn.current.delete(d),or.current.delete(d))},[]),bh=a.useCallback(async r=>{const o=x;if(!o||(await Z.getState().setNestedGitScanRoot(o,r),!Se(o)))return;if(r){await Jt(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Fc(o),Vs(""),Ys(""),Xs(""),fo(v=>v.filter(w=>w===o));const d=Ht;d&&ht(d,o)!==o&&Qe(null),await Jt(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Fc,Se,Jt,x,Qe,Ht]),xh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=Pn.trim();!r||r===ie?.branch||await ft({action:"switch-branch",cwd:ve,branch:r},i("rightSidebar.switchBranch"))},[ie?.branch,ve,Ve,ft,Pn,i]),Bc=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=Ks.trim();if(!r)return;await ft({action:"commit",cwd:ve,message:r},i("rightSidebar.commitChanges"))&&xl("")},[ve,Ks,Ve,ft,i]),vh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=dn.trim(),o=un.trim();await ft({action:"push",cwd:ve,...r?{remote:r}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[ve,un,dn,Ve,ft,i]),yh=a.useCallback(async()=>{if(!ve||Ve){gt(i("rightSidebar.selectRepositoryForGitActions"));return}const r=dn.trim(),o=un.trim();await ft({action:"pull",cwd:ve,...r?{remote:r}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[ve,un,dn,Ve,ft,i]);a.useEffect(()=>{if(!Ze||!ve||Ie)return;let r=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const v=await td({cwd:ve,action:d}).catch(()=>null);if(!v?.ok||v.status!=="running")continue;const w={action:d,cwd:ve},R=o[d]??d;ls({action:d});try{const P=await Ra(v,w,R);if(r||!Se(x))return;const H=x?await Ea(x,void 0,{includeNested:Vn(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Xn(x)}).catch(()=>P.bundle):P.bundle;H&&Xr(H,{reloadDiff:!0,cacheOnly:!0})}catch(P){r||gt(i("rightSidebar.gitActionFailed",{message:P instanceof Error?P.message:"Unknown error"}))}finally{r||ls(null)}return}})(),()=>{r=!0}},[ve,Xr,Ze,Se,x,Ie,i,Ra]);const Yo=Ln?.action==="commit",Xo=Ln?.action==="switch-branch",Jo=Ln?.action==="pull",Qo=Ln?.action==="push",Na=Ze||Nf,Zo=ba?i("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,wh=cr.length>0,Oc=Qt.length>0,kh=x?e.jsx(Fd,{open:co,onOpenChange:uo,showScopePicker:!0,selectedAll:ba,repos:zt,selectedRoots:ga,onToggleRepo:ah,onGenerate:()=>ch(qo?"regenerate":"generate"),disabled:!wh,generateDisabled:!Oc,inserted:we?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Zo,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{dh()},secondaryDisabled:!Oc||W,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:W,loading:dl.size>0,statusTitle:dl.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:zr,onChange:r=>cl(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),mc.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:i("rightSidebar.missingBaseReposSkipped",{repositories:mc.map(r=>r.label).join(O==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const o=wt.get(r.root),d=[],v=new Set,w=(K,Me)=>{!K||v.has(K)||(v.add(K),d.push({value:K,label:K,meta:Me}))};w(jr[r.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const K of o?.context?.branches??[])w(K,K===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const K of o?.context?.remoteBranches??[])w(K,i("rightSidebar.remoteBranch"));const R=[],P=new Set,H=(K,Me)=>{!K||P.has(K)||(P.add(K),R.push({value:K,label:K,meta:Me}))};H(Mt[r.root],Mt[r.root]?i("rightSidebar.pushUpstreamBadge"):void 0),H(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const K of o?.context?.remoteBranches??[])H(K,"remote");for(const K of o?.context?.branches??[])H(K,K===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Yn,{label:i("rightSidebar.currentBranchLabel"),value:jr[r.root]||o?.context?.branch||"",options:d,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:K=>{zs(Me=>({...Me,[r.root]:K}))}}),e.jsx(Yn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Mt[r.root]||"",options:R,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:K=>{Ws(Me=>({...Me,[r.root]:K}))}})]})}}):null,Uc=Ss(Ct.reduce((r,o)=>Math.max(r,o.injectedAt??0),0),O),Sh=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:()=>ll(r=>{const o=!r;return St(oi,o),o}),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":is,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(Ps,{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:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Zo})]}),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 ${is?"rotate-90":""}`,children:e.jsx($a,{size:13})})]}),is&&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:[i("rightSidebar.changeAuditScopeLabel"),": ",Zo]}),kh]}),ke&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:ke}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[nn.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>uh(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:i("rightSidebar.branchAuditViewDiff")})]}),Ss(r.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Ss(r.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>fh(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(Wa,{size:12})})]},r.key)),qn.length>0?qn.slice(0,Math.max(0,8-nn.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>hh(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),Ss(r.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Ss(r.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{nh(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(Wa,{size:12})})]},r.key)):nn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Hc=ar&&x&&Gn?e.jsxs("div",{className:Na?"overflow-visible":"overflow-hidden",children:[Sh,e.jsxs("button",{type:"button",onClick:()=>{Ze||Mf(r=>{const o=!r;return o&&ve&&!Gn&&!cn&&$o(ve),o})},"aria-expanded":Na,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${Ze?"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(Lr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("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 ${yn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[cn&&e.jsx(jt,{size:10,className:"animate-spin"}),yn.staged>0?i("rightSidebar.stagedCount",{count:yn.staged}):i("rightSidebar.noStagedChangesShort")]}),!Ze&&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 ${Na?"rotate-90":""}`,children:e.jsx($a,{size:13})})]})]}),Na&&e.jsxs("div",{className:"space-y-0",children:[It.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:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Wf})]})}),e.jsx(Yn,{label:i("rightSidebar.gitRepositoryLabel"),value:ve??"",options:It,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!Ie,onChange:r=>{_c(r||null)}}),Ve&&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:i("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:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Pn!==lc?lc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{xh()},disabled:!eh,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 ${Xo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ie?.action==="switch-branch"||Xo?"opacity-0":"",children:i("rightSidebar.switchBranch")}),Ie?.action==="switch-branch"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Xo&&Ie?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Yn,{label:i("rightSidebar.currentBranchLabel"),value:Pn,options:Kf,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!Ie,onChange:Vs})]}),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:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Ve?i("rightSidebar.selectRepositoryForGitActions"):yn.staged>0?i("rightSidebar.commitReadyHint",{count:yn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Bc()},disabled:!!Ie||Ve||yn.staged===0||!Ks.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 ${Yo?"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:Ve?i("rightSidebar.selectRepositoryForGitActions"):yn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ie?.action==="commit"||Yo?"opacity-0":"",children:i("rightSidebar.commitChanges")}),Ie?.action==="commit"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Yo&&Ie?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Ks,onChange:r=>xl(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),Bc())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!Ie,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:()=>Mn(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Vt,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[He&&e.jsx(jt,{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 ${Vt?"rotate-90":""}`,children:e.jsx($a,{size:13})})]})]}),Vt&&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(Jn,{size:12,className:"shrink-0"}),e.jsx("input",{value:as,onChange:r=>sn(r.target.value),placeholder:i("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}),as&&e.jsx("button",{type:"button",onClick:()=>sn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Gt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Gf,children:[an.length>0?an.map(r=>{const[o,...d]=r.split(/\s+/),v=d.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{mh(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:v,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:v,children:v}),Sr[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Sr[o]==="ahead"?"bg-accent/10 text-accent":Sr[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Sr[o]==="ahead"?"rightSidebar.commitAhead":Sr[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),We===o&&e.jsx(jt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):He?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),Ur&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(jt,{size:12,className:"animate-spin"})}),lo&&!Ur&&an.length>0&&e.jsx("button",{type:"button",onClick:()=>{bs({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:i("rightSidebar.recentCommitsLoadMore")})]})]}),Nt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Nt}),ol&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ol})]}),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:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{yh()},disabled:!Qf,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 ${Jo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ie?.action==="pull"||Jo?"opacity-0":"",children:i("rightSidebar.pullChanges")}),Ie?.action==="pull"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Jo&&Ie?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{vh()},disabled:!Zf,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 ${Qo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ie?.action==="push"||Qo?"opacity-0":"",children:i("rightSidebar.pushChanges")}),Ie?.action==="push"&&e.jsx(jt,{size:12,className:"absolute animate-spin"}),Qo&&Ie?.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] ${gc.className}`,title:ie?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:gc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ie?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${hc?"grid-cols-2":"grid-cols-1"}`,children:[hc&&e.jsx(Yn,{label:i("rightSidebar.pushRemoteLabel"),value:dn,options:fc,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!Ie,onChange:Ys}),e.jsx(Yn,{label:i("rightSidebar.pushBranchLabel"),value:un,options:Vf,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:ie?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!Ie,onChange:Xs})]})]})]})]}):null,jh=a.useCallback(r=>{const o=ht(r,x);if(!o)return[];const d=xi(r),v=[];return r.canStage&&v.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{ft({action:"stage-file",cwd:o,paths:[r.path]},i("rightSidebar.stageFile"),d)}}),r.canUnstage&&v.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{ft({action:"unstage-file",cwd:o,paths:[r.path]},i("rightSidebar.unstageFile"),d)}}),r.canStash&&v.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{ft({action:"stash-file",cwd:o,paths:[r.path]},i("rightSidebar.stashFile"),d)}}),r.canRestoreWorktree&&v.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Gr({kind:"restore",file:r,phrase:""})}),v},[x,ft,i]),Rh=a.useCallback(()=>{if(g){S?.();return}Cr(0),Mr.current?.slideTo(0),Rr(!1),mt(null)},[S,g]),zc=a.useCallback(r=>{if(q(""),Bt(r),Qe(null),mt(null),ne(null),ee){g&&S?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1);return}},[ee,S,g,Qe,Bt]);a.useEffect(()=>{const r=o=>{const d=o.detail,v=d?.path;if(typeof v!="string"||!v.startsWith("/"))return;q(""),mt(null),Lt(null);const w=!!(x&&(v===x||v.startsWith(`${x}/`)));if(d.kind==="file"){const R=pi(v);ms(v),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Lt(d.line),Bt(w?null:R),ne(P=>({path:v,nonce:(P?.nonce??0)+1}));return}Qe(null),w?(Bt(null),ne(R=>({path:v,nonce:(R?.nonce??0)+1}))):(ne(null),Bt(v)),ee&&(g&&S?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1))};return window.addEventListener(od,r),()=>window.removeEventListener(od,r)},[ms,ee,S,g,x,Qe,Bt]),a.useEffect(()=>{t||(_t(!1),hr(!1))},[t]),a.useEffect(()=>{if(!ur&&!fr)return;const r=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(_t(!1),hr(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[fr,ur]);const Wc=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:Uf,disabled:!fa,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":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(Xd,{size:14})}),e.jsx("button",{type:"button",onClick:ec,disabled:!x||In===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":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(id,{size:14})}),e.jsx("button",{type:"button",onClick:Hf,disabled:!me,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":i("rightSidebar.refreshFiles"),title:vl?i("rightSidebar.fileWatchUnavailable",{message:vl}):i("rightSidebar.refreshFiles"),children:e.jsx(Ri,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:me??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:Bf}),na==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(ld,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>me&&Jr(me,Tt??void 0),disabled:!me,...me&&Tt?Io(ua(me),Tt):{},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 ${Tt&&(we===Tt||et===Tt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Tt&&et===Tt?"rightSidebar.copied":Tt&&we===Tt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Tt&&(we===Tt||et===Tt)?e.jsx(ki,{size:13}):e.jsx(Va,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{_t(!1),hr(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${fr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":fr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(ji,{size:14})}),fr&&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:()=>{hr(!1),zf()},disabled:!Fo,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${gs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[gs?e.jsx(ri,{size:14}):e.jsx(Aa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(gs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),Lf()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${ko?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ko?e.jsx(Im,{size:14}):e.jsx(Mi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(ko?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!me,onClick:()=>{me&&(hr(!1),Af(me,na==="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:[na==="modified"?e.jsx(bm,{size:14}):e.jsx(ld,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(na==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),x&&(ha.length>0||Of)&&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:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:ec,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 ${me===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(id,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Xe})]}),ha.map(r=>{const o=r.path,d=r.kind==="file",v=d?Je===o:me===o;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${v?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o,children:[e.jsxs("button",{type:"button",onClick:()=>d?ms(o):Bt(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(Ei,{size:10,className:"shrink-0"}):e.jsx(Aa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:xt(o)})]}),e.jsx("button",{type:"button",onClick:()=>fn(o),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":i("rightSidebar.unpinFolder",{name:xt(o)}),title:i("rightSidebar.unpinFolder",{name:xt(o)}),children:e.jsx(Gt,{size:9})})]},o)})]}),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"})]}),ei=a.useMemo(()=>{if(An===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((bo-An)/1e3)),d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[v,w]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return d.format(v,w)},[bo,An]),Gc=x&&!Hn?e.jsx("button",{type:"button",onClick:()=>{bh(!So)},"aria-pressed":So,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${So?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,qc=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[ei?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:ei}),children:ei}):null,e.jsx("button",{type:"button",onClick:()=>{fs()},disabled:qr,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":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx(Ri,{size:13,className:qr?"animate-spin":""})})]}):null,Ch=Ul?i("rightSidebar.changeAuditScopeAll"):gn.length===1?gn[0].relativeRoot==="."?Xe:gn[0].relativeRoot||gn[0].name:`${gn.length} repos`,Kc=x?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(Fd,{open:ts,onOpenChange:rn,showScopePicker:wn,selectedAll:Ul,repos:Pf,selectedRoots:Xt,onToggleRepo:sh,onGenerate:()=>th(),disabled:!x,inserted:we===Zl,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Ch,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:Dr,error:!!wr,statusTitle:wr??(Dr?i("rightSidebar.changeAuditLoading"):Ct.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Ct.length})}${Uc?` · ${i("rightSidebar.changeAuditLoadedAt",{time:Uc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{rh()},disabled:Dr||Ct.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Ct.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(Wa,{size:12})})]}):null,Ma=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:[k?.available&&k.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:k.branch,children:[e.jsx(Lr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:k.branch})]}),dt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[dt.modified,"M"]}),dt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",dt.added]}),dt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",dt.deleted]}),dt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.renamed,"R"]}),dt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.copied,"C"]}),dt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.untracked,"U"]}),dt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[dt.conflicted,"!"]}),dt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.other,"?"]}),dt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:dt.staged})}),k?.available&&x&&ye.size>0&&ae.length<=1&&e.jsx("button",{type:"button",onClick:()=>{ft({action:"stage-all",cwd:x},i("rightSidebar.stageAll"))},disabled:!!Ie,className:"rounded-md bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),k?.available&&x&&ye.size>0&&ae.length<=1&&e.jsx("button",{type:"button",onClick:()=>Gr({kind:"stash-all",repoRoot:x,repoLabel:Xe}),disabled:!!Ie,className:"rounded-md bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]});return e.jsxs(xm,{side:"right",isOpen:t,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h,children:[Io.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:x??void 0,children:Xe}),(!ee||po)&&k?.available&&k.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:k.branch,children:[e.jsx(Lr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:k.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!ue;G(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):q("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ue?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Jn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":lt,onClick:()=>{ct(r=>!r),Dt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${lt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(vm,{size:14}),!lt&&be.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:Sl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const o=r.target.files;!o||o.length===0||(ps(Array.from(o)),r.target.value="")}}),e.jsx("input",{ref:jl,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const o=r.target.files?.[0];r.target.value="",o&&Ff(o)}}),m&&e.jsx("button",{type:"button",onClick:m,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":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(ri,{size:14}):e.jsx(Aa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{hr(!1),_t(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${ur?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":ur,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(ji,{size:15})}),ur&&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":Wr,onClick:()=>_f(!Wr),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(rd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Wr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Wr?"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:()=>{_t(!1),Sl.current?.click()},disabled:Js,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:[Js?e.jsx(jt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Ym,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),jl.current?.click()},disabled:Js,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:[Js?e.jsx(jt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Bm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),m&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),m()},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(ri,{size:14}):e.jsx(Aa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(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":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("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",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([r,o])=>{const d=Y===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{L(r),_t(!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:o},r)})})]})]})]}),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":i("rightSidebar.close"),children:e.jsx(Gt,{size:14})})]}),ue&&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(Jn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:j,onChange:r=>q(r.target.value),placeholder:i(_==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Ic("name"),"aria-pressed":_==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${_==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Ic("content"),"aria-pressed":_==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${_==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),j&&e.jsx("button",{type:"button",onClick:()=>q(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Gt,{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(ym,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:te,onChange:r=>oe(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),te!=="."&&e.jsx("button",{type:"button",onClick:()=>oe("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Gt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>M(r=>!r),"aria-expanded":$e,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${$e||ds.length>0||J||Re||Ce?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(wm,{size:13}),ds.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:ds.length})]})]}),$e&&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:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ge,onChange:r=>he(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ge&&e.jsx("button",{type:"button",onClick:()=>he(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Gt,{size:11})})]}),_==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[J,()=>fe(r=>!r),Pm,i("rightSidebar.matchCase")],[Re,()=>qe(r=>!r),Jm,i("rightSidebar.matchWholeWord")],[Ce,()=>ce(r=>!r),Gm,i("rightSidebar.useRegex")]].map(([r,o,d,v])=>e.jsxs("button",{type:"button",onClick:o,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),v]},v))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Hn?2:3)+(Wr?1:0)}, minmax(0, 1fr))`},children:[!Hn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>Yt("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Lr,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>Yt("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(lu,{size:12}),i("rightSidebar.tabChanges"),ye.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:ye.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>Yt("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Nm,{size:12}),i("rightSidebar.tabFiles")]}),Wr&&e.jsxs("button",{type:"button",onClick:()=>Yt("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${lr==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(rd,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),gl&&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:gl})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ua,{active:Ze,mounted:ar,fallback:e.jsx(mi,{slow:!1}),children:Te?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(ud,{items:oh,selectedKey:wf,onSelect:Us,emptyText:i("rightSidebar.noChanges"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${Te.headRef??""}${Te.commits?.[0]?` · ${Te.commits[0]}`:""}`,onClose:()=>{Be(null),Us(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?ja:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya})}):kr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(ud,{items:Go,selectedKey:ho,onSelect:ln,emptyText:i(Pe?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(Pe?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:wa?`${wa.repoLabel} · ${wa.branchName??"HEAD"} → ${wa.baseRef}`:void 0,onClose:()=>{tr(!1),rr(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?ja:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,walkthroughs:ih,onWalkthroughNavigate:lh,initialDetailScrollTop:Pe&&rt?ss[rt]:void 0,onDetailScrollPositionChange:ph,externalSwiperRef:ee?ia:void 0,onMobileSlideChange:ee?mo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:Hc?e.jsx("div",{className:"px-3",children:Hc}):qr?e.jsx(mi,{slow:Al}):hn?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):Wd(k)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):k?.available===!1?e.jsx(Ha,{message:k.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{fs()}}):x?e.jsx(mi,{slow:Al}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ua,{active:zn,children:ee?e.jsxs(Qd,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{Mr.current=r,r.slideTo(fl,0)},onSlideChange:r=>{if(Cr(r.activeIndex),us.current===r.activeIndex){us.current=null;return}r.activeIndex===0&&(Rr(!1),mt(null),S?.())},children:[e.jsx(Ci,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Fn,onScroll:zl,onDragOver:ca,onDragEnter:ca,onDragLeave:ql,onDrop:Kl,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[yl&&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:i("rightSidebar.dropToUpload")})}),!j.trim()&&Wc,e.jsx(cd,{rootPath:me??"",onFileSelect:ms,onPathReference:Jr,getReferenceText:ua,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onDirectoryRoot:tc,onSearchFromDirectory:rc,onDirectoryPinToggle:nc,onFilePinToggle:sc,pinnedPaths:xn,selectedFilePath:Je,query:xe,searchRootPath:Dl,searchOptions:_l,searchMode:_,onContentMatchSelect:Wl,onDirectoryDropFiles:(r,o)=>ps(o,r),revealDirectory:le,canOpenInFileBrowser:wl,onOpenInFileBrowser:Gl})]})}),e.jsx(Ci,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(qi,{filePath:zn&&(kf||fl===1)?Je:null,onInsertReference:Jr,onInsertText:$r,onInsertFeature:$r,onReviewReference:Jl,onReferenceCopied:Er,onClose:Rh,onDirectoryLinkOpen:zc,isMobile:!0,lineRange:Rn,onLineRangeChange:mt,insertedReferenceKey:we,copiedReferenceKey:et,scrollToLine:Oe,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Fn,onScroll:zl,onDragOver:ca,onDragEnter:ca,onDragLeave:ql,onDrop:Kl,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:vo},children:[yl&&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:i("rightSidebar.dropToUpload")})}),!j.trim()&&Wc,e.jsx(cd,{rootPath:me??"",onFileSelect:ms,onPathReference:Jr,getReferenceText:ua,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onDirectoryRoot:tc,onSearchFromDirectory:rc,onDirectoryPinToggle:nc,onFilePinToggle:sc,pinnedPaths:xn,selectedFilePath:Je,query:xe,searchRootPath:Dl,searchOptions:_l,searchMode:_,onContentMatchSelect:Wl,onDirectoryDropFiles:(r,o)=>ps(o,r),revealDirectory:le,canOpenInFileBrowser:wl,onOpenInFileBrowser:Gl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("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:Tf,onPointerMove:If,onPointerUp:Hl,onPointerCancel:Hl,onDoubleClick:()=>{yo(Ti),St(js,Ti)},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(qi,{filePath:zn?Je:null,onInsertReference:Jr,onInsertText:$r,onInsertFeature:$r,onReviewReference:Jl,onReferenceCopied:Er,onDirectoryLinkOpen:zc,isMobile:!1,lineRange:Rn,onLineRangeChange:mt,insertedReferenceKey:we,copiedReferenceKey:et,scrollToLine:Oe,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})]})}),e.jsx(Ua,{active:yt,mounted:Sf||yt,children:()=>Lo?e.jsx(km,{}):ee?e.jsx(Ni,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:ia,onMobileSlideChange:mo,groups:Wt.length>0?Sc():[],mode:xr,onModeChange:Sa,selectedKey:Je,scrollToKey:Nc,scrollToKeyNonce:Zs.nonce,compact:!1,collapsedDirectoryKeys:_s,onToggleDirectory:$c,onSelectFile:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);o&&ka(bt(o))},renderLeading:Rc,renderTrailing:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?wc(o):null},renderDirectoryTrailing:kc,renderSubtitle:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?vc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ma&&e.jsx("div",{className:"mb-2",children:Ma}),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:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Wt.length,"/",ye.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[bc(),Gc,r,h&&zo(),Kc,qc]}),Et&&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:Et.label}),Et.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:Et.branch})]}),!Et&&wn&&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(Lr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:pa?(r=>Ec(r)):void 0,emptyContent:Lo?null:hn&&ye.size===0?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Wt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>hs(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:i("rightSidebar.backToChangeList"),children:[e.jsx($s,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[h&&zo(),e.jsxs("button",{type:"button",onClick:ja,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:jc(),activePane:yt,wrap:At,diffViewType:$f,inlineMode:vr,diffOptions:Tc,reloadKey:Os,renderStreamBadge:r=>e.jsx(Ns,{status:r}),onHunkGitAction:Dc,onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,onDetailScroll:xa}):e.jsx(Ni,{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:i("rightSidebar.backToChangeList"),groups:Wt.length>0?Sc():[],mode:xr,onModeChange:Sa,selectedKey:Je,scrollToKey:Nc,scrollToKeyNonce:Zs.nonce,compact:!0,collapsedDirectoryKeys:_s,onToggleDirectory:$c,onSelectFile:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);o&&ka(bt(o))},renderLeading:Rc,renderTrailing:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?wc(o):null},renderDirectoryTrailing:kc,renderSubtitle:r=>{const o=Array.from(ye.values()).find(d=>bt(d)===r.key);return o?vc(o):null},aiContent:pa?(r=>Ec(r)):void 0,emptyContent:Lo?null:hn&&ye.size===0?e.jsx(Ha,{message:hn,onRetry:()=>{fs()}}):ye.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Wt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ma&&e.jsx("div",{className:"mb-2",children:Ma}),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:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Wt.length,"/",ye.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[bc(),Gc,r,zo(),e.jsxs("button",{type:"button",onClick:ja,"aria-pressed":At,title:i("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 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Kc,qc]}),Et&&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:Et.label}),Et.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:Et.branch}),e.jsx("button",{type:"button",onClick:()=>Ca("stage-all",Et.root,Et.label),disabled:!!Ie,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:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>Ca("stash-all",Et.root,Et.label),disabled:!!Ie,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:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]}),!Et&&wn&&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(Lr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:jc(),activePane:yt,wrap:At,diffViewType:Ft,inlineMode:vr,diffOptions:Tc,reloadKey:Os,renderStreamBadge:r=>e.jsx(Ns,{status:r}),onHunkGitAction:Dc,onInsertDiffReference:Qr,onReferenceCopied:Er,insertedReferenceKey:we,copiedReferenceKey:et,onClearAuditRecord:ya,onDetailScroll:xa})}),e.jsx(Ua,{active:Ao,mounted:jf&&Wr,children:Rf?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:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Yc.getState().setDock(sd,null),Si({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Sm,{sessionId:n??null})})]}),t&<&&e.jsx(kp,{value:be,collapsed:Pr,autoCollapseAfterSend:z,focusRequest:ut,insertError:Tr?i("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{mr(!1),ze(r)},onCollapsedChange:Dt,onAutoCollapseAfterSendChange:re,onDisable:()=>ct(!1),onClear:()=>ze(""),onInsert:()=>Ql(!1),onInsertAndSend:()=>Ql(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>i("rightSidebar.contextDraftCharacterCount",{count:r})}}),Jf(),pt&&typeof document<"u"&&en.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Gr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:pt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:pt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:Yd(pt.file.absolutePath,x)}):i("rightSidebar.confirmStashAllDescription")}),pt.kind==="restore"&&e.jsx("input",{value:pt.phrase,onChange:r=>Gr({...pt,phrase:r.target.value}),placeholder:i("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:()=>Gr(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:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ie||pt.kind==="restore"&&pt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(pt.kind==="restore"){const r=ht(pt.file,x);if(!r)return;ft({action:"restore-worktree-file",cwd:r,paths:[pt.file.path],confirm:{acknowledged:!0,phrase:pt.phrase}},i("rightSidebar.restoreFile"),xi(pt.file))}else{const r=pt.repoRoot??x;if(!r)return;ft({action:"stash-all",cwd:r},i("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${pt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(Ie?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const ex=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:qi,MarkdownImageLightbox:lf,MarkdownPreview:cf,RightSidebar:Hb,__testParseMarkdownListBlock:ab,buildMarkdownPreviewBlocks:gb,buildMarkdownPreviewRenderResult:nl,collectKnownGitRepoRoots:Au,computeMarkdownImageDisplayBox:Wu,getMarkdownHeadingOutline:of,getMarkdownHeadingPathAtLine:af,getNextMarkdownPreviewLineRange:kb,isSvgImageSrc:so,mountRightSidebarRepoPickerOverlay:bu,replaceGitRepositorySnapshot:pf,resolveMarkdownLocalLinkTarget:Ji,resolveRightSidebarDiffViewType:Eu,shouldCloseMarkdownImageLightboxDrag:rf,showsGitRepoGroupHeader:Ii},Symbol.toStringTag,{value:"Module"}));export{Mi as E,Um as M,ex as R,Im as a,zm as b,ep as c,Zb as m};
|