termdock 1.4.315 → 1.4.317

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.
Files changed (344) hide show
  1. package/dist/client/assets/{App-B2SFV3qg.js → App-BF_s1-_u.js} +6 -6
  2. package/dist/client/assets/App-BF_s1-_u.js.br +0 -0
  3. package/dist/client/assets/App-BF_s1-_u.js.gz +0 -0
  4. package/dist/client/assets/{ArchitecturePanel-Cj7za6DZ.js → ArchitecturePanel-CdgUQsVD.js} +2 -2
  5. package/dist/client/assets/ArchitecturePanel-CdgUQsVD.js.br +0 -0
  6. package/dist/client/assets/ArchitecturePanel-CdgUQsVD.js.gz +0 -0
  7. package/dist/client/assets/{ChangeWalkthroughPanel-BB52iLLC.js → ChangeWalkthroughPanel-DHp5r1k9.js} +1 -1
  8. package/dist/client/assets/ChangeWalkthroughPanel-DHp5r1k9.js.br +0 -0
  9. package/dist/client/assets/ChangeWalkthroughPanel-DHp5r1k9.js.gz +0 -0
  10. package/dist/client/assets/{CollaborationMainWorkspace-D5WKV3rA.js → CollaborationMainWorkspace-P_jXjsT-.js} +1 -1
  11. package/dist/client/assets/CollaborationMainWorkspace-P_jXjsT-.js.br +0 -0
  12. package/dist/client/assets/CollaborationMainWorkspace-P_jXjsT-.js.gz +0 -0
  13. package/dist/client/assets/CollaborationTaskContent-DSkxOlKQ.js +2 -0
  14. package/dist/client/assets/{ComputerControlView-Dkc4R1IU.js → ComputerControlView-B5Yng8Dt.js} +2 -2
  15. package/dist/client/assets/ComputerControlView-B5Yng8Dt.js.br +0 -0
  16. package/dist/client/assets/ComputerControlView-B5Yng8Dt.js.gz +0 -0
  17. package/dist/client/assets/{DagPlayground-BHY3l8UG.js → DagPlayground-rZE40fcL.js} +1 -1
  18. package/dist/client/assets/DagPlayground-rZE40fcL.js.br +0 -0
  19. package/dist/client/assets/DagPlayground-rZE40fcL.js.gz +0 -0
  20. package/dist/client/assets/{DiffLab-BSQiKfBJ.js → DiffLab-3sIn0W3p.js} +1 -1
  21. package/dist/client/assets/DiffLab-3sIn0W3p.js.br +0 -0
  22. package/dist/client/assets/DiffLab-3sIn0W3p.js.gz +0 -0
  23. package/dist/client/assets/{DiffReview-CYrBBq0V.js → DiffReview-CBf8-Tli.js} +1 -1
  24. package/dist/client/assets/DiffReview-CBf8-Tli.js.br +0 -0
  25. package/dist/client/assets/DiffReview-CBf8-Tli.js.gz +0 -0
  26. package/dist/client/assets/{DiffReviewLab-VSIbEnxm.js → DiffReviewLab-BXhskTlx.js} +1 -1
  27. package/dist/client/assets/DiffReviewLab-BXhskTlx.js.br +0 -0
  28. package/dist/client/assets/DiffReviewLab-BXhskTlx.js.gz +0 -0
  29. package/dist/client/assets/{DiffViewer-Cx5fyiMB.js → DiffViewer-DZfgjOBh.js} +1 -1
  30. package/dist/client/assets/DiffViewer-DZfgjOBh.js.br +0 -0
  31. package/dist/client/assets/DiffViewer-DZfgjOBh.js.gz +0 -0
  32. package/dist/client/assets/{ModelPreview-B22odexG.js → ModelPreview-Bzdi_sPh.js} +1 -1
  33. package/dist/client/assets/ModelPreview-Bzdi_sPh.js.br +0 -0
  34. package/dist/client/assets/ModelPreview-Bzdi_sPh.js.gz +0 -0
  35. package/dist/client/assets/{RightSidebar-DKA0jXPW.js → RightSidebar-DaRdlJzn.js} +42 -42
  36. package/dist/client/assets/RightSidebar-DaRdlJzn.js.br +0 -0
  37. package/dist/client/assets/RightSidebar-DaRdlJzn.js.gz +0 -0
  38. package/dist/client/assets/{abnfDiagram-VCTEODGH-sbUSsiPn.js → abnfDiagram-VCTEODGH-CarKrfAf.js} +1 -1
  39. package/dist/client/assets/abnfDiagram-VCTEODGH-CarKrfAf.js.br +0 -0
  40. package/dist/client/assets/abnfDiagram-VCTEODGH-CarKrfAf.js.gz +0 -0
  41. package/dist/client/assets/{app-CYOLJycb.js → app-BCTEfclM.js} +3 -3
  42. package/dist/client/assets/app-BCTEfclM.js.br +0 -0
  43. package/dist/client/assets/app-BCTEfclM.js.gz +0 -0
  44. package/dist/client/assets/{arc-GhJ9aeQ3.js → arc-B6Qdq2Vw.js} +1 -1
  45. package/dist/client/assets/arc-B6Qdq2Vw.js.br +0 -0
  46. package/dist/client/assets/arc-B6Qdq2Vw.js.gz +0 -0
  47. package/dist/client/assets/{architectureDiagram-5GKGNRK7-BYmAIJBx.js → architectureDiagram-5GKGNRK7-DgPJ0l9i.js} +1 -1
  48. package/dist/client/assets/architectureDiagram-5GKGNRK7-DgPJ0l9i.js.br +0 -0
  49. package/dist/client/assets/architectureDiagram-5GKGNRK7-DgPJ0l9i.js.gz +0 -0
  50. package/dist/client/assets/{blockDiagram-I7D4REHJ-CZNZT_ez.js → blockDiagram-I7D4REHJ-BsorvNo4.js} +1 -1
  51. package/dist/client/assets/blockDiagram-I7D4REHJ-BsorvNo4.js.br +0 -0
  52. package/dist/client/assets/blockDiagram-I7D4REHJ-BsorvNo4.js.gz +0 -0
  53. package/dist/client/assets/{c4Diagram-7LVT6UL2-6xcSowLn.js → c4Diagram-7LVT6UL2-Bbpi62ab.js} +1 -1
  54. package/dist/client/assets/c4Diagram-7LVT6UL2-Bbpi62ab.js.br +0 -0
  55. package/dist/client/assets/c4Diagram-7LVT6UL2-Bbpi62ab.js.gz +0 -0
  56. package/dist/client/assets/channel-uZtI4GD8.js +1 -0
  57. package/dist/client/assets/{chunk-2Q5K7J3B-C06nkhUQ.js → chunk-2Q5K7J3B-Cm7mDz66.js} +1 -1
  58. package/dist/client/assets/{chunk-5VM5RSS4-BHY43hJO.js → chunk-5VM5RSS4-BMERXU_m.js} +1 -1
  59. package/dist/client/assets/{chunk-F27PBJKO-Dl8JYcZO.js → chunk-F27PBJKO-fe9Yw7OI.js} +1 -1
  60. package/dist/client/assets/chunk-F27PBJKO-fe9Yw7OI.js.br +0 -0
  61. package/dist/client/assets/chunk-F27PBJKO-fe9Yw7OI.js.gz +0 -0
  62. package/dist/client/assets/{chunk-IMKFNOWR-BALi4Q3g.js → chunk-IMKFNOWR-QquKV9k-.js} +1 -1
  63. package/dist/client/assets/chunk-IMKFNOWR-QquKV9k-.js.br +0 -0
  64. package/dist/client/assets/chunk-IMKFNOWR-QquKV9k-.js.gz +0 -0
  65. package/dist/client/assets/{chunk-JWPE2WC7-BBD2d7j7.js → chunk-JWPE2WC7-CVe8_YO4.js} +1 -1
  66. package/dist/client/assets/{chunk-POPQ4Y6H-CZN0_ndj.js → chunk-POPQ4Y6H-DT8PalJ4.js} +1 -1
  67. package/dist/client/assets/{chunk-SVP7TREG-CD-Zf9rn.js → chunk-SVP7TREG-BUQulipE.js} +1 -1
  68. package/dist/client/assets/chunk-SVP7TREG-BUQulipE.js.br +0 -0
  69. package/dist/client/assets/chunk-SVP7TREG-BUQulipE.js.gz +0 -0
  70. package/dist/client/assets/{chunk-TICWLB2K-Clpg1zwp.js → chunk-TICWLB2K-fubKwUCg.js} +1 -1
  71. package/dist/client/assets/chunk-TICWLB2K-fubKwUCg.js.br +0 -0
  72. package/dist/client/assets/chunk-TICWLB2K-fubKwUCg.js.gz +0 -0
  73. package/dist/client/assets/{chunk-XXDRQBXY-BanPVnIr.js → chunk-XXDRQBXY-CdwTi82y.js} +1 -1
  74. package/dist/client/assets/classDiagram-ZZMXUADV-CgJJ1J4J.js +1 -0
  75. package/dist/client/assets/classDiagram-v2-VYDZK3BY-CgJJ1J4J.js +1 -0
  76. package/dist/client/assets/{cose-bilkent-JH36ORCC-431u7cfU.js → cose-bilkent-JH36ORCC-DmEDc2ee.js} +1 -1
  77. package/dist/client/assets/cose-bilkent-JH36ORCC-DmEDc2ee.js.br +0 -0
  78. package/dist/client/assets/cose-bilkent-JH36ORCC-DmEDc2ee.js.gz +0 -0
  79. package/dist/client/assets/{cynefin-OW5HDTMX-BuLFGx14.js → cynefin-OW5HDTMX-C-mfarRX.js} +1 -1
  80. package/dist/client/assets/cynefin-OW5HDTMX-C-mfarRX.js.br +0 -0
  81. package/dist/client/assets/cynefin-OW5HDTMX-C-mfarRX.js.gz +0 -0
  82. package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-qLzjwMMG.js → cynefinDiagram-5FMLGOSQ-CgVmp8od.js} +1 -1
  83. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CgVmp8od.js.br +0 -0
  84. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CgVmp8od.js.gz +0 -0
  85. package/dist/client/assets/{dagre-GXQ25YYZ-CUdd5M5g.js → dagre-GXQ25YYZ-WU_d2fSU.js} +1 -1
  86. package/dist/client/assets/dagre-GXQ25YYZ-WU_d2fSU.js.br +0 -0
  87. package/dist/client/assets/dagre-GXQ25YYZ-WU_d2fSU.js.gz +0 -0
  88. package/dist/client/assets/{diagram-S7CK7UJ4-DLQClBzm.js → diagram-S7CK7UJ4-Dtikk80Z.js} +1 -1
  89. package/dist/client/assets/diagram-S7CK7UJ4-Dtikk80Z.js.br +0 -0
  90. package/dist/client/assets/diagram-S7CK7UJ4-Dtikk80Z.js.gz +0 -0
  91. package/dist/client/assets/{diagram-UQ7AKVKN-1RGASXU_.js → diagram-UQ7AKVKN-DuTCB36P.js} +1 -1
  92. package/dist/client/assets/diagram-UQ7AKVKN-DuTCB36P.js.br +0 -0
  93. package/dist/client/assets/diagram-UQ7AKVKN-DuTCB36P.js.gz +0 -0
  94. package/dist/client/assets/{diagram-VSXAHHWV-DqnCzn2R.js → diagram-VSXAHHWV-DSLAcWi6.js} +1 -1
  95. package/dist/client/assets/diagram-VSXAHHWV-DSLAcWi6.js.br +0 -0
  96. package/dist/client/assets/diagram-VSXAHHWV-DSLAcWi6.js.gz +0 -0
  97. package/dist/client/assets/{diagram-VX7I27RA-CMXsPqTS.js → diagram-VX7I27RA-DyQOu10m.js} +1 -1
  98. package/dist/client/assets/diagram-VX7I27RA-DyQOu10m.js.br +0 -0
  99. package/dist/client/assets/diagram-VX7I27RA-DyQOu10m.js.gz +0 -0
  100. package/dist/client/assets/{diagram-Z3DM3KII-BM0N1kCR.js → diagram-Z3DM3KII-CuMI1k1t.js} +1 -1
  101. package/dist/client/assets/diagram-Z3DM3KII-CuMI1k1t.js.br +0 -0
  102. package/dist/client/assets/diagram-Z3DM3KII-CuMI1k1t.js.gz +0 -0
  103. package/dist/client/assets/{ebnfDiagram-PWID7BFC-CvaVo-wh.js → ebnfDiagram-PWID7BFC-Di8RxhNL.js} +1 -1
  104. package/dist/client/assets/ebnfDiagram-PWID7BFC-Di8RxhNL.js.br +0 -0
  105. package/dist/client/assets/ebnfDiagram-PWID7BFC-Di8RxhNL.js.gz +0 -0
  106. package/dist/client/assets/{erDiagram-RLTQ6QDP-okw-AY7i.js → erDiagram-RLTQ6QDP-C1wPuBtH.js} +1 -1
  107. package/dist/client/assets/erDiagram-RLTQ6QDP-C1wPuBtH.js.br +0 -0
  108. package/dist/client/assets/erDiagram-RLTQ6QDP-C1wPuBtH.js.gz +0 -0
  109. package/dist/client/assets/{flowDiagram-HODETNUW-B_DWtzOe.js → flowDiagram-HODETNUW-D0SIEpUy.js} +1 -1
  110. package/dist/client/assets/flowDiagram-HODETNUW-D0SIEpUy.js.br +0 -0
  111. package/dist/client/assets/flowDiagram-HODETNUW-D0SIEpUy.js.gz +0 -0
  112. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-Bm4nYUVg.js → ganttDiagram-EL5Y4UJY-DgeD2fKd.js} +1 -1
  113. package/dist/client/assets/ganttDiagram-EL5Y4UJY-DgeD2fKd.js.br +0 -0
  114. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-Bm4nYUVg.js.gz → ganttDiagram-EL5Y4UJY-DgeD2fKd.js.gz} +0 -0
  115. package/dist/client/assets/{gestureArbiter-XalN4TaN.js → gestureArbiter-Xl7awIrX.js} +1 -1
  116. package/dist/client/assets/gestureArbiter-Xl7awIrX.js.br +0 -0
  117. package/dist/client/assets/gestureArbiter-Xl7awIrX.js.gz +0 -0
  118. package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-B7LAo8S2.js → gitGraphDiagram-WWUBYQGX-CzFKSKK_.js} +1 -1
  119. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CzFKSKK_.js.br +0 -0
  120. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-CzFKSKK_.js.gz +0 -0
  121. package/dist/client/assets/{infoDiagram-27XIBGKW-DXncUrwz.js → infoDiagram-27XIBGKW-C9mmJGhv.js} +1 -1
  122. package/dist/client/assets/{ishikawaDiagram-5VMMS53U-Ds28H7pI.js → ishikawaDiagram-5VMMS53U-D9uVb4Og.js} +1 -1
  123. package/dist/client/assets/ishikawaDiagram-5VMMS53U-D9uVb4Og.js.br +0 -0
  124. package/dist/client/assets/ishikawaDiagram-5VMMS53U-D9uVb4Og.js.gz +0 -0
  125. package/dist/client/assets/{journeyDiagram-3NMN7TZE-WeF_efZ2.js → journeyDiagram-3NMN7TZE-BMKNUyUx.js} +1 -1
  126. package/dist/client/assets/journeyDiagram-3NMN7TZE-BMKNUyUx.js.br +0 -0
  127. package/dist/client/assets/journeyDiagram-3NMN7TZE-BMKNUyUx.js.gz +0 -0
  128. package/dist/client/assets/{kanban-definition-UXKFOSKX-CMbZcy6U.js → kanban-definition-UXKFOSKX-8i7nyqix.js} +1 -1
  129. package/dist/client/assets/{kanban-definition-UXKFOSKX-CMbZcy6U.js.br → kanban-definition-UXKFOSKX-8i7nyqix.js.br} +0 -0
  130. package/dist/client/assets/kanban-definition-UXKFOSKX-8i7nyqix.js.gz +0 -0
  131. package/dist/client/assets/{layout-DNapC8T-.js → layout-BS5SCHbc.js} +1 -1
  132. package/dist/client/assets/layout-BS5SCHbc.js.br +0 -0
  133. package/dist/client/assets/layout-BS5SCHbc.js.gz +0 -0
  134. package/dist/client/assets/{linear-B9AFx-TF.js → linear-fo2zkK6T.js} +1 -1
  135. package/dist/client/assets/linear-fo2zkK6T.js.br +0 -0
  136. package/dist/client/assets/linear-fo2zkK6T.js.gz +0 -0
  137. package/dist/client/assets/{mermaid.core-Ddh1Z0hf.js → mermaid.core-B8k3pAmc.js} +5 -5
  138. package/dist/client/assets/mermaid.core-B8k3pAmc.js.br +0 -0
  139. package/dist/client/assets/mermaid.core-B8k3pAmc.js.gz +0 -0
  140. package/dist/client/assets/{mindmap-definition-YA3MSWOX-B0xMGUol.js → mindmap-definition-YA3MSWOX-BwgQTj2Q.js} +1 -1
  141. package/dist/client/assets/mindmap-definition-YA3MSWOX-BwgQTj2Q.js.br +0 -0
  142. package/dist/client/assets/mindmap-definition-YA3MSWOX-BwgQTj2Q.js.gz +0 -0
  143. package/dist/client/assets/{passwordBootstrap-DQRd5vCF.js → passwordBootstrap-DvQk0qYt.js} +1 -1
  144. package/dist/client/assets/passwordBootstrap-DvQk0qYt.js.br +0 -0
  145. package/dist/client/assets/passwordBootstrap-DvQk0qYt.js.gz +0 -0
  146. package/dist/client/assets/{pegDiagram-XKGWAZYB-BVZ-3kEF.js → pegDiagram-XKGWAZYB-CumSoxLr.js} +1 -1
  147. package/dist/client/assets/pegDiagram-XKGWAZYB-CumSoxLr.js.br +0 -0
  148. package/dist/client/assets/pegDiagram-XKGWAZYB-CumSoxLr.js.gz +0 -0
  149. package/dist/client/assets/{pieDiagram-E7YTZNPT-Cim4Hk3I.js → pieDiagram-E7YTZNPT-Dc3txkBL.js} +1 -1
  150. package/dist/client/assets/pieDiagram-E7YTZNPT-Dc3txkBL.js.br +0 -0
  151. package/dist/client/assets/pieDiagram-E7YTZNPT-Dc3txkBL.js.gz +0 -0
  152. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-CYiEj5sp.js → quadrantDiagram-AXDQQJYC-D92mwZnT.js} +1 -1
  153. package/dist/client/assets/quadrantDiagram-AXDQQJYC-D92mwZnT.js.br +0 -0
  154. package/dist/client/assets/quadrantDiagram-AXDQQJYC-D92mwZnT.js.gz +0 -0
  155. package/dist/client/assets/{railroadDiagram-O6MQD6OU-DjNNfYra.js → railroadDiagram-O6MQD6OU-O1UOZ30Y.js} +1 -1
  156. package/dist/client/assets/railroadDiagram-O6MQD6OU-O1UOZ30Y.js.br +0 -0
  157. package/dist/client/assets/railroadDiagram-O6MQD6OU-O1UOZ30Y.js.gz +0 -0
  158. package/dist/client/assets/{rdpSession-DEzSQAuN.js → rdpSession-Dr_tPwzx.js} +1 -1
  159. package/dist/client/assets/rdpSession-Dr_tPwzx.js.br +0 -0
  160. package/dist/client/assets/rdpSession-Dr_tPwzx.js.gz +0 -0
  161. package/dist/client/assets/{referenceLongPress-BjyTtoDY.js → referenceLongPress-YuGU-PYw.js} +1 -1
  162. package/dist/client/assets/referenceLongPress-YuGU-PYw.js.br +0 -0
  163. package/dist/client/assets/referenceLongPress-YuGU-PYw.js.gz +0 -0
  164. package/dist/client/assets/{requirementDiagram-BXWQKSXE-ZwiKdiI3.js → requirementDiagram-BXWQKSXE-uD1cgrxA.js} +1 -1
  165. package/dist/client/assets/requirementDiagram-BXWQKSXE-uD1cgrxA.js.br +0 -0
  166. package/dist/client/assets/requirementDiagram-BXWQKSXE-uD1cgrxA.js.gz +0 -0
  167. package/dist/client/assets/{sankeyDiagram-P5KCCOFB-BYR7ctps.js → sankeyDiagram-P5KCCOFB-CIJE4-pc.js} +1 -1
  168. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CIJE4-pc.js.br +0 -0
  169. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CIJE4-pc.js.gz +0 -0
  170. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-DxYCvK80.js → sequenceDiagram-WJ2MYXX4-BT6LG37W.js} +1 -1
  171. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BT6LG37W.js.br +0 -0
  172. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BT6LG37W.js.gz +0 -0
  173. package/dist/client/assets/{sizeCapture-INFHLROL-CXruk8Ko.js → sizeCapture-INFHLROL-DoYY94Rj.js} +1 -1
  174. package/dist/client/assets/sizeCapture-INFHLROL-DoYY94Rj.js.br +0 -0
  175. package/dist/client/assets/sizeCapture-INFHLROL-DoYY94Rj.js.gz +0 -0
  176. package/dist/client/assets/{sparkles-DRH97PDH.js → sparkles-DFYGpezN.js} +1 -1
  177. package/dist/client/assets/{stateDiagram-D77RDMKH-CENDGrxr.js → stateDiagram-D77RDMKH-C4xmgR_-.js} +1 -1
  178. package/dist/client/assets/stateDiagram-D77RDMKH-C4xmgR_-.js.br +0 -0
  179. package/dist/client/assets/stateDiagram-D77RDMKH-C4xmgR_-.js.gz +0 -0
  180. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-BLHH60cg.js +1 -0
  181. package/dist/client/assets/{swimlanes-42K2YHIH-BZQeVFeA.js → swimlanes-42K2YHIH-mRdmZmAA.js} +1 -1
  182. package/dist/client/assets/swimlanes-42K2YHIH-mRdmZmAA.js.br +0 -0
  183. package/dist/client/assets/swimlanes-42K2YHIH-mRdmZmAA.js.gz +0 -0
  184. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-D-lNPW5d.js +8 -0
  185. package/dist/client/assets/{timeline-definition-24CTP7MA-DiJ9i33g.js → timeline-definition-24CTP7MA-BFFrD5kR.js} +1 -1
  186. package/dist/client/assets/timeline-definition-24CTP7MA-BFFrD5kR.js.br +0 -0
  187. package/dist/client/assets/timeline-definition-24CTP7MA-BFFrD5kR.js.gz +0 -0
  188. package/dist/client/assets/{triangle-alert-DECoBoOV.js → triangle-alert-BwJ6Q_Y0.js} +1 -1
  189. package/dist/client/assets/{vennDiagram-4TSXK5OY-DBiEJQ9Y.js → vennDiagram-4TSXK5OY-Dy59OxIM.js} +1 -1
  190. package/dist/client/assets/vennDiagram-4TSXK5OY-Dy59OxIM.js.br +0 -0
  191. package/dist/client/assets/vennDiagram-4TSXK5OY-Dy59OxIM.js.gz +0 -0
  192. package/dist/client/assets/{videoCompression-8r1jOza9.js → videoCompression-DrQ47oZA.js} +1 -1
  193. package/dist/client/assets/videoCompression-DrQ47oZA.js.br +0 -0
  194. package/dist/client/assets/videoCompression-DrQ47oZA.js.gz +0 -0
  195. package/dist/client/assets/{wardleyDiagram-VM6X3IG4-B6wCSfya.js → wardleyDiagram-VM6X3IG4-B-BKlX7o.js} +1 -1
  196. package/dist/client/assets/wardleyDiagram-VM6X3IG4-B-BKlX7o.js.br +0 -0
  197. package/dist/client/assets/wardleyDiagram-VM6X3IG4-B-BKlX7o.js.gz +0 -0
  198. package/dist/client/assets/{xychartDiagram-S5SC5T6Z-DlNQayU5.js → xychartDiagram-S5SC5T6Z-79qktI_4.js} +1 -1
  199. package/dist/client/assets/xychartDiagram-S5SC5T6Z-79qktI_4.js.br +0 -0
  200. package/dist/client/assets/xychartDiagram-S5SC5T6Z-79qktI_4.js.gz +0 -0
  201. package/dist/client/index.html +1 -1
  202. package/dist/client/index.html.br +0 -0
  203. package/dist/client/index.html.gz +0 -0
  204. package/dist/client/sw.js +1 -1
  205. package/dist/client/sw.js.br +0 -0
  206. package/dist/client/sw.js.gz +0 -0
  207. package/dist/server/agent/collaborationPrompt.js +1 -1
  208. package/dist/server/agent/collaborationProtocol.js +2 -0
  209. package/dist/server/agent/collaborationStore.js +47 -3
  210. package/dist/server/agent/integrationCli.js +30 -0
  211. package/dist/server/agent/integrationServer.js +9 -0
  212. package/dist/server/routes/terminal.js +5 -1
  213. package/dist/server/utils/settings.js +14 -0
  214. package/docs/integrations.md +67 -0
  215. package/package.json +1 -1
  216. package/runtime-manifest.json +3 -3
  217. package/dist/client/assets/App-B2SFV3qg.js.br +0 -0
  218. package/dist/client/assets/App-B2SFV3qg.js.gz +0 -0
  219. package/dist/client/assets/ArchitecturePanel-Cj7za6DZ.js.br +0 -0
  220. package/dist/client/assets/ArchitecturePanel-Cj7za6DZ.js.gz +0 -0
  221. package/dist/client/assets/ChangeWalkthroughPanel-BB52iLLC.js.br +0 -0
  222. package/dist/client/assets/ChangeWalkthroughPanel-BB52iLLC.js.gz +0 -0
  223. package/dist/client/assets/CollaborationMainWorkspace-D5WKV3rA.js.br +0 -0
  224. package/dist/client/assets/CollaborationMainWorkspace-D5WKV3rA.js.gz +0 -0
  225. package/dist/client/assets/CollaborationTaskContent-MwUgcmG_.js +0 -2
  226. package/dist/client/assets/ComputerControlView-Dkc4R1IU.js.br +0 -0
  227. package/dist/client/assets/ComputerControlView-Dkc4R1IU.js.gz +0 -0
  228. package/dist/client/assets/DagPlayground-BHY3l8UG.js.br +0 -0
  229. package/dist/client/assets/DagPlayground-BHY3l8UG.js.gz +0 -0
  230. package/dist/client/assets/DiffLab-BSQiKfBJ.js.br +0 -0
  231. package/dist/client/assets/DiffLab-BSQiKfBJ.js.gz +0 -0
  232. package/dist/client/assets/DiffReview-CYrBBq0V.js.br +0 -0
  233. package/dist/client/assets/DiffReview-CYrBBq0V.js.gz +0 -0
  234. package/dist/client/assets/DiffReviewLab-VSIbEnxm.js.br +0 -0
  235. package/dist/client/assets/DiffReviewLab-VSIbEnxm.js.gz +0 -0
  236. package/dist/client/assets/DiffViewer-Cx5fyiMB.js.br +0 -0
  237. package/dist/client/assets/DiffViewer-Cx5fyiMB.js.gz +0 -0
  238. package/dist/client/assets/ModelPreview-B22odexG.js.br +0 -0
  239. package/dist/client/assets/ModelPreview-B22odexG.js.gz +0 -0
  240. package/dist/client/assets/RightSidebar-DKA0jXPW.js.br +0 -0
  241. package/dist/client/assets/RightSidebar-DKA0jXPW.js.gz +0 -0
  242. package/dist/client/assets/abnfDiagram-VCTEODGH-sbUSsiPn.js.br +0 -0
  243. package/dist/client/assets/abnfDiagram-VCTEODGH-sbUSsiPn.js.gz +0 -0
  244. package/dist/client/assets/app-CYOLJycb.js.br +0 -0
  245. package/dist/client/assets/app-CYOLJycb.js.gz +0 -0
  246. package/dist/client/assets/arc-GhJ9aeQ3.js.br +0 -0
  247. package/dist/client/assets/arc-GhJ9aeQ3.js.gz +0 -0
  248. package/dist/client/assets/architectureDiagram-5GKGNRK7-BYmAIJBx.js.br +0 -0
  249. package/dist/client/assets/architectureDiagram-5GKGNRK7-BYmAIJBx.js.gz +0 -0
  250. package/dist/client/assets/blockDiagram-I7D4REHJ-CZNZT_ez.js.br +0 -0
  251. package/dist/client/assets/blockDiagram-I7D4REHJ-CZNZT_ez.js.gz +0 -0
  252. package/dist/client/assets/c4Diagram-7LVT6UL2-6xcSowLn.js.br +0 -0
  253. package/dist/client/assets/c4Diagram-7LVT6UL2-6xcSowLn.js.gz +0 -0
  254. package/dist/client/assets/channel-C1FwyjiU.js +0 -1
  255. package/dist/client/assets/chunk-F27PBJKO-Dl8JYcZO.js.br +0 -0
  256. package/dist/client/assets/chunk-F27PBJKO-Dl8JYcZO.js.gz +0 -0
  257. package/dist/client/assets/chunk-IMKFNOWR-BALi4Q3g.js.br +0 -0
  258. package/dist/client/assets/chunk-IMKFNOWR-BALi4Q3g.js.gz +0 -0
  259. package/dist/client/assets/chunk-SVP7TREG-CD-Zf9rn.js.br +0 -0
  260. package/dist/client/assets/chunk-SVP7TREG-CD-Zf9rn.js.gz +0 -0
  261. package/dist/client/assets/chunk-TICWLB2K-Clpg1zwp.js.br +0 -0
  262. package/dist/client/assets/chunk-TICWLB2K-Clpg1zwp.js.gz +0 -0
  263. package/dist/client/assets/classDiagram-ZZMXUADV-FyKDan8T.js +0 -1
  264. package/dist/client/assets/classDiagram-v2-VYDZK3BY-FyKDan8T.js +0 -1
  265. package/dist/client/assets/cose-bilkent-JH36ORCC-431u7cfU.js.br +0 -0
  266. package/dist/client/assets/cose-bilkent-JH36ORCC-431u7cfU.js.gz +0 -0
  267. package/dist/client/assets/cynefin-OW5HDTMX-BuLFGx14.js.br +0 -0
  268. package/dist/client/assets/cynefin-OW5HDTMX-BuLFGx14.js.gz +0 -0
  269. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-qLzjwMMG.js.br +0 -0
  270. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-qLzjwMMG.js.gz +0 -0
  271. package/dist/client/assets/dagre-GXQ25YYZ-CUdd5M5g.js.br +0 -0
  272. package/dist/client/assets/dagre-GXQ25YYZ-CUdd5M5g.js.gz +0 -0
  273. package/dist/client/assets/diagram-S7CK7UJ4-DLQClBzm.js.br +0 -0
  274. package/dist/client/assets/diagram-S7CK7UJ4-DLQClBzm.js.gz +0 -0
  275. package/dist/client/assets/diagram-UQ7AKVKN-1RGASXU_.js.br +0 -0
  276. package/dist/client/assets/diagram-UQ7AKVKN-1RGASXU_.js.gz +0 -0
  277. package/dist/client/assets/diagram-VSXAHHWV-DqnCzn2R.js.br +0 -0
  278. package/dist/client/assets/diagram-VSXAHHWV-DqnCzn2R.js.gz +0 -0
  279. package/dist/client/assets/diagram-VX7I27RA-CMXsPqTS.js.br +0 -0
  280. package/dist/client/assets/diagram-VX7I27RA-CMXsPqTS.js.gz +0 -0
  281. package/dist/client/assets/diagram-Z3DM3KII-BM0N1kCR.js.br +0 -0
  282. package/dist/client/assets/diagram-Z3DM3KII-BM0N1kCR.js.gz +0 -0
  283. package/dist/client/assets/ebnfDiagram-PWID7BFC-CvaVo-wh.js.br +0 -0
  284. package/dist/client/assets/ebnfDiagram-PWID7BFC-CvaVo-wh.js.gz +0 -0
  285. package/dist/client/assets/erDiagram-RLTQ6QDP-okw-AY7i.js.br +0 -0
  286. package/dist/client/assets/erDiagram-RLTQ6QDP-okw-AY7i.js.gz +0 -0
  287. package/dist/client/assets/flowDiagram-HODETNUW-B_DWtzOe.js.br +0 -0
  288. package/dist/client/assets/flowDiagram-HODETNUW-B_DWtzOe.js.gz +0 -0
  289. package/dist/client/assets/ganttDiagram-EL5Y4UJY-Bm4nYUVg.js.br +0 -0
  290. package/dist/client/assets/gestureArbiter-XalN4TaN.js.br +0 -0
  291. package/dist/client/assets/gestureArbiter-XalN4TaN.js.gz +0 -0
  292. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-B7LAo8S2.js.br +0 -0
  293. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-B7LAo8S2.js.gz +0 -0
  294. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Ds28H7pI.js.br +0 -0
  295. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Ds28H7pI.js.gz +0 -0
  296. package/dist/client/assets/journeyDiagram-3NMN7TZE-WeF_efZ2.js.br +0 -0
  297. package/dist/client/assets/journeyDiagram-3NMN7TZE-WeF_efZ2.js.gz +0 -0
  298. package/dist/client/assets/kanban-definition-UXKFOSKX-CMbZcy6U.js.gz +0 -0
  299. package/dist/client/assets/layout-DNapC8T-.js.br +0 -0
  300. package/dist/client/assets/layout-DNapC8T-.js.gz +0 -0
  301. package/dist/client/assets/linear-B9AFx-TF.js.br +0 -0
  302. package/dist/client/assets/linear-B9AFx-TF.js.gz +0 -0
  303. package/dist/client/assets/mermaid.core-Ddh1Z0hf.js.br +0 -0
  304. package/dist/client/assets/mermaid.core-Ddh1Z0hf.js.gz +0 -0
  305. package/dist/client/assets/mindmap-definition-YA3MSWOX-B0xMGUol.js.br +0 -0
  306. package/dist/client/assets/mindmap-definition-YA3MSWOX-B0xMGUol.js.gz +0 -0
  307. package/dist/client/assets/passwordBootstrap-DQRd5vCF.js.br +0 -0
  308. package/dist/client/assets/passwordBootstrap-DQRd5vCF.js.gz +0 -0
  309. package/dist/client/assets/pegDiagram-XKGWAZYB-BVZ-3kEF.js.br +0 -0
  310. package/dist/client/assets/pegDiagram-XKGWAZYB-BVZ-3kEF.js.gz +0 -0
  311. package/dist/client/assets/pieDiagram-E7YTZNPT-Cim4Hk3I.js.br +0 -0
  312. package/dist/client/assets/pieDiagram-E7YTZNPT-Cim4Hk3I.js.gz +0 -0
  313. package/dist/client/assets/quadrantDiagram-AXDQQJYC-CYiEj5sp.js.br +0 -0
  314. package/dist/client/assets/quadrantDiagram-AXDQQJYC-CYiEj5sp.js.gz +0 -0
  315. package/dist/client/assets/railroadDiagram-O6MQD6OU-DjNNfYra.js.br +0 -0
  316. package/dist/client/assets/railroadDiagram-O6MQD6OU-DjNNfYra.js.gz +0 -0
  317. package/dist/client/assets/rdpSession-DEzSQAuN.js.br +0 -0
  318. package/dist/client/assets/rdpSession-DEzSQAuN.js.gz +0 -0
  319. package/dist/client/assets/referenceLongPress-BjyTtoDY.js.br +0 -0
  320. package/dist/client/assets/referenceLongPress-BjyTtoDY.js.gz +0 -0
  321. package/dist/client/assets/requirementDiagram-BXWQKSXE-ZwiKdiI3.js.br +0 -0
  322. package/dist/client/assets/requirementDiagram-BXWQKSXE-ZwiKdiI3.js.gz +0 -0
  323. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BYR7ctps.js.br +0 -0
  324. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BYR7ctps.js.gz +0 -0
  325. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-DxYCvK80.js.br +0 -0
  326. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-DxYCvK80.js.gz +0 -0
  327. package/dist/client/assets/sizeCapture-INFHLROL-CXruk8Ko.js.br +0 -0
  328. package/dist/client/assets/sizeCapture-INFHLROL-CXruk8Ko.js.gz +0 -0
  329. package/dist/client/assets/stateDiagram-D77RDMKH-CENDGrxr.js.br +0 -0
  330. package/dist/client/assets/stateDiagram-D77RDMKH-CENDGrxr.js.gz +0 -0
  331. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-De-tGy_n.js +0 -1
  332. package/dist/client/assets/swimlanes-42K2YHIH-BZQeVFeA.js.br +0 -0
  333. package/dist/client/assets/swimlanes-42K2YHIH-BZQeVFeA.js.gz +0 -0
  334. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-D1YMLrIO.js +0 -8
  335. package/dist/client/assets/timeline-definition-24CTP7MA-DiJ9i33g.js.br +0 -0
  336. package/dist/client/assets/timeline-definition-24CTP7MA-DiJ9i33g.js.gz +0 -0
  337. package/dist/client/assets/vennDiagram-4TSXK5OY-DBiEJQ9Y.js.br +0 -0
  338. package/dist/client/assets/vennDiagram-4TSXK5OY-DBiEJQ9Y.js.gz +0 -0
  339. package/dist/client/assets/videoCompression-8r1jOza9.js.br +0 -0
  340. package/dist/client/assets/videoCompression-8r1jOza9.js.gz +0 -0
  341. package/dist/client/assets/wardleyDiagram-VM6X3IG4-B6wCSfya.js.br +0 -0
  342. package/dist/client/assets/wardleyDiagram-VM6X3IG4-B6wCSfya.js.gz +0 -0
  343. package/dist/client/assets/xychartDiagram-S5SC5T6Z-DlNQayU5.js.br +0 -0
  344. package/dist/client/assets/xychartDiagram-S5SC5T6Z-DlNQayU5.js.gz +0 -0
@@ -1,17 +1,17 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-Ddh1Z0hf.js","assets/app-CYOLJycb.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-BObjbh2R.css","assets/purify.es-4eNOHKSq.js","assets/ModelPreview-B22odexG.js","assets/App-B2SFV3qg.js","assets/gestureArbiter-XalN4TaN.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-DECoBoOV.js","assets/referenceLongPress-BjyTtoDY.js","assets/DiffReview-CYrBBq0V.js","assets/sparkles-DRH97PDH.js","assets/DiffViewer-Cx5fyiMB.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-BB52iLLC.js","assets/ArchitecturePanel-Cj7za6DZ.js","assets/ArchitecturePanel-B_BDrrfR.css","assets/ComputerControlView-Dkc4R1IU.js","assets/katex-55ZPZeOF.css"])))=>i.map(i=>d[i]);
2
- import{ag as lr,da as ft,by as e,h as wo,ct as Id,ap as Uu,_ as Mn,bG as Hu,L as dt,e as fs,X as Pt,dg as Q,dn as Lt,bT as pt,a as ta,b1 as zu,C as ko,d as ra,d6 as mo,d7 as ll,U as Dd,bj as Am,O as Us,ay as Tm,bq as Im,bs as $l,bt as Dm,bu as Wu,br as Hs,aO as Fm,E as _m,k as Bm,bn as Om,bV as Um,bX as Hm,bY as zm,be as Wm,bW as Fd,N as Ct,g as Gm,j as Bi,I as Km,b as qm,d8 as Oi,bd as _d,aI as Bd,aE as Vm,aS as Ui,aT as Od,dp as Js,av as zs,aU as Ym,bL as Xm,cT as Ud,aL as Jm,d4 as Qm,co as Zm,dh as Yr,aX as ep,a2 as Hd,a1 as tp,aF as zd,aK as rp,aQ as Wd,cq as np,z as Gd,r as Kd,l as sp,J as Gu,at as Ku,cg as ap,dl as op,n as ip}from"./app-CYOLJycb.js";import{b as a,r as jr}from"./dnd-BCFAPC0L.js";import{i as Ll,F as lp,J as qu,x as cp,O as qd,W as po,m as dp,ah as Vu,Y as up,w as fp,E as hp,s as mp,M as pp,R as go,a5 as Yu,a6 as gp,S as hs,n as Xu,g as bp,am as Ju,A as Hi,aj as xp,ai as Nn,a7 as vp,a8 as yp,ak as wp,aa as Vd,V as Yd,r as Xd,k as Jd,B as zi,z as ro,h as kp,Q as Sp,y as jp,q as Rp,T as Cp,N as Np,o as Qd,C as Ep,c as Mp,G as $p,f as Lp}from"./App-B2SFV3qg.js";import{F as cl,a as Zd,S as eu,b as Qu,c as dl}from"./gestureArbiter-XalN4TaN.js";import{D as ul,C as Qs,L as Zu,f as Pp,n as Ap}from"./DiffReview-CYrBBq0V.js";import{T as Tp,L as So,M as ef,G as wr}from"./triangle-alert-DECoBoOV.js";import{S as na}from"./sparkles-DRH97PDH.js";import{C as tf,M as rf}from"./ChangeWalkthroughPanel-BB52iLLC.js";import{r as nf,s as sf,l as af,a as tu,h as fl,u as Ip,g as hl,b as of}from"./DiffViewer-Cx5fyiMB.js";import{u as lf,G as cf}from"./referenceLongPress-BjyTtoDY.js";const Dp=[["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"}]],Fp=lr("case-sensitive",Dp);const _p=[["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"}]],Bp=lr("eye-off",_p);const Op=[["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"}]],ml=lr("eye",Op);const Up=[["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"}]],pl=lr("file-text",Up);const Hp=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],zp=lr("funnel",Hp);const Wp=[["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"}]],Gp=lr("image-plus",Wp);const Kp=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],ru=lr("loader-circle",Kp);const qp=[["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"}]],Vp=lr("regex",qp);const Yp=[["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"}]],Xp=lr("scan",Yp);const Jp=[["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"}]],Qp=lr("upload",Jp);const Zp=[["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"}]],eg=lr("whole-word",Zp),tg=100,rg=5e5,ng=1e4,nu=16384,sg=32,ag=1e5;class ls extends Error{constructor(n){super(`Markdown preview parsing stopped: ${n}`),this.reason=n,this.name="MarkdownParseError"}reason}class og{startedAt=performance.now();operations=0;depth=0;check(){if(++this.operations>ag)throw new ls("complexity");if(performance.now()-this.startedAt>=tg)throw new ls("timeout")}validateLines(n){if(n.length>ng)throw new ls("size");let s=0;for(const l of n)if(this.check(),s+=l.length+1,s>rg||l.length>nu)throw new ls("size")}validateInline(n){if(this.check(),n.length>nu)throw new ls("size")}nested(n){if(this.check(),this.depth>=sg)throw new ls("depth");this.depth+=1;try{return n()}finally{this.depth-=1}}}const su=new RegExp(`(\\\\\\([^)]*\\\\\\)|\\$[^$\\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+(?:"[^"]*"|'[^']*'|\\([^)]*\\)))?\\)|!?\\[[^\\]]+\\]\\[[^\\]]*\\]|!?\\[[^\\]]+\\]|\\[\\^[^\\]]+\\]|~~[^~]+~~|\\*\\*[^*]+\\*\\*|(?<![\\p{L}\\p{N}_])__[^_]+__(?![\\p{L}\\p{N}_])|\\*[^*\\s][^*]*\\*|(?<![\\p{L}\\p{N}_])_[^_\\s][^_]*_(?![\\p{L}\\p{N}_])|<https?:\\/\\/[^>\\s]+>|<[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+>|https?:\\/\\/[^\\s<]+|www\\.[^\\s<]+|[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+)`,"iyu");function ig(r,n,s){let l=n;for(;r[l]==="`";)l+=1;const d=l-n;let c=l;for(;c<r.length;){s.check();const m=r.indexOf("`",c);if(m<0)return null;for(c=m;r[c]==="`";)c+=1;if(c-m===d)return c}return null}function*lg(r,n){n.validateInline(r);const s=new RegExp(su.source,su.flags);let l=0;for(;l<r.length;){if(n.check(),r[l]==="`"){const c=ig(r,l,n);if(c!==null)yield{index:l,token:r.slice(l,c)},l=c;else for(;r[l]==="`";)l+=1;continue}s.lastIndex=l;const d=s.exec(r);n.check(),d?(yield{index:l,token:d[0]},l=s.lastIndex):l+=(r.codePointAt(l)??0)>65535?2:1}}function au({children:r,actions:n}){const{t:s}=ft(),[l,d]=a.useState(!1),c=a.useId(),m=a.useRef(null),g=a.useRef(null),f=()=>{d(!1),m.current?.focus({preventScroll:!0})};return a.useLayoutEffect(()=>{if(!l)return;const p=m.current,x=g.current;if(!p||!x)return;const h=window.visualViewport,b=()=>{const S=p.getBoundingClientRect(),T=(h?.offsetLeft??0)+8,D=(h?.offsetTop??0)+8,F=Math.max(0,(h?.width??window.innerWidth)-16),M=D+(h?.height??window.innerHeight)-16,N=Math.min(240,F),P=Math.max(0,S.top-D-6),B=Math.max(0,M-S.bottom-6),q=x.scrollHeight>B&&P>B;Object.assign(x.style,{width:`${N}px`,left:`${Math.max(T,Math.min(S.right-N,T+F-N))}px`,top:`${q?S.top-6:S.bottom+6}px`,maxHeight:`${q?P:B}px`,transform:q?"translateY(-100%)":"none"})};b();const E=typeof ResizeObserver>"u"?null:new ResizeObserver(b);return E?.observe(p),E?.observe(x),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),h?.addEventListener("resize",b),h?.addEventListener("scroll",b),()=>{E?.disconnect(),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),h?.removeEventListener("resize",b),h?.removeEventListener("scroll",b)}},[l]),a.useEffect(()=>{if(!l)return;g.current?.querySelector("button:not(:disabled)")?.focus({preventScroll:!0});const p=x=>{x.target instanceof Node&&!m.current?.contains(x.target)&&!g.current?.contains(x.target)&&d(!1)};return document.addEventListener("pointerdown",p),()=>document.removeEventListener("pointerdown",p)},[l]),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:m,type:"button","aria-haspopup":"menu","aria-expanded":l,"aria-controls":l?c:void 0,onClick:()=>d(p=>!p),onKeyDown:p=>{(p.key==="ArrowDown"||p.key==="ArrowUp")&&(p.preventDefault(),d(!0))},className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-[11px] font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary ${l?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(wo,{size:14}),s("sidebar.moreActions")]})]}),typeof document<"u"&&jr.createPortal(e.jsx("div",{ref:g,id:c,hidden:!l,role:"menu","data-sidebar-gesture-ignore":!0,"aria-label":s("sidebar.moreActions"),className:"fixed z-menu-panel overflow-y-auto overscroll-contain rounded-lg border border-border/30 bg-surface p-1 shadow-[0_8px_24px_var(--app-shadow-soft)]",onKeyDown:p=>{if(!p.currentTarget.contains(p.target))return;const x=[...p.currentTarget.querySelectorAll("button:not(:disabled)")],h=x.indexOf(document.activeElement);let b;if(p.key==="Escape"){p.preventDefault(),p.stopPropagation(),f();return}if(p.key==="Tab"){f();return}if(p.key==="ArrowDown")b=(h+1)%x.length;else if(p.key==="ArrowUp")b=(h-1+x.length)%x.length;else if(p.key==="Home")b=0;else if(p.key==="End")b=x.length-1;else return;p.preventDefault(),x[b]?.focus({preventScroll:!0})},children:n(f)}),document.body)]})}const Wi="a[href],button,input,select,textarea,[tabindex],[contenteditable],iframe,summary,audio[controls],video[controls]",cs=a.memo(function({active:n,mounted:s=!0,fallback:l=null,children:d}){const c=a.useRef(null);return a.useLayoutEffect(()=>{const m=c.current;if(!m||n)return;const g=new Map,f=h=>{g.has(h)||(g.set(h,h.inert),h.inert=!0)},p=h=>{h instanceof HTMLElement&&h.matches(Wi)&&f(h),h.querySelectorAll(Wi).forEach(f)};p(m);const x=new MutationObserver(h=>{for(const b of h)b.type==="attributes"?b.target instanceof HTMLElement&&b.target.matches(Wi)&&f(b.target):b.addedNodes.forEach(E=>{E instanceof Element&&p(E)})});return x.observe(m,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex","href","contenteditable","controls"]}),()=>{x.disconnect();for(const[h,b]of g)h.inert=b}},[n,s]),e.jsx("div",{ref:c,className:"absolute inset-0 min-h-0 overflow-hidden bg-surface text-foreground",style:n?void 0:{clipPath:"inset(100%)"},"aria-hidden":!n,children:s?typeof d=="function"?d():d:l})},(r,n)=>!r.active&&!n.active&&r.mounted===n.mounted);async function cg(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function dg({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:d,load:c}){a.useEffect(()=>{if(!r||!n||s||d.current===n)return;const m=window.setTimeout(()=>{d.current=n,c(n)},l);return()=>window.clearTimeout(m)},[r,n,s,l,d,c])}async function ug(r){if(r.kind==="mermaid"){await Id(new Blob([r.svg],{type:"image/svg+xml"}),"mermaid.svg");return}const n=new URL(r.src,window.location.href);if(n.origin===window.location.origin&&n.pathname==="/api/terminal/fs/blob"){const c=n.searchParams.get("path");if(!c)throw new Error("Missing image path");await Uu(c);return}const s=await fetch(r.src);if(!s.ok)throw new Error(`HTTP ${s.status}`);const l=await s.blob(),d=decodeURIComponent(n.pathname.split("/").pop()||"")||`image.${{"image/svg+xml":"svg","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif"}[l.type]||"png"}`;await Id(l,d)}let no=null,ou=!1;function fg(){return no||(no=Mn(()=>import("./mermaid.core-Ddh1Z0hf.js").then(r=>r.bl),__vite__mapDeps([0,1,2,3,4,5,6])).then(r=>r.default??r).catch(r=>{throw no=null,r})),no}function hg(r){ou||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),ou=!0)}function mg({rootPath:r,paths:n,disabled:s,onChange:l}){const{t:d}=ft(),[c,m]=a.useState(""),[g,f]=a.useState(0),[p,x]=a.useState(null),[h,b]=a.useState(!1),[E,S]=a.useState(!1),T=`${r.replace(/[\\/]+$/,"")}/${c}`;a.useEffect(()=>{const N=new AbortController;return x(null),b(!1),Hu(T,N.signal,!0,"pick_git_ignore_exception").then(P=>{N.signal.aborted||x({directory:c,entries:P.entries,truncated:!!P.truncated})}).catch(()=>{N.signal.aborted||b(!0)}),()=>N.abort()},[T,c,g]);const D=N=>{x(null),b(!1),m(N)},F=p?.directory===c,M=N=>{if(N.length>200){S(!0);return}S(!1),l(N)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/30 bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/20 p-2",children:[e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(c.slice(0,Math.max(0,c.lastIndexOf("/")))),"aria-label":d("rightSidebar.parentFolder"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(Ll,{size:14})}),e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(""),"aria-label":d("rightSidebar.backToProjectRoot"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(cl,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:T,children:c||"./"})]}),e.jsxs("div",{className:"h-56 overflow-y-auto overscroll-contain p-1",role:"group","aria-label":d("rightSidebar.gitIgnoreExceptionsPaths"),"aria-busy":!F&&!h,children:[h?e.jsxs("div",{className:"flex flex-col items-center gap-2 p-4 text-center text-xs",children:[e.jsx("p",{role:"alert",className:"text-destructive",children:d("rightSidebar.gitIgnoreExceptionsLoadFailed")}),e.jsx("button",{type:"button",disabled:s,onClick:()=>{b(!1),f(N=>N+1)},className:"rounded-md px-3 py-2 text-primary hover:bg-surface-elevated disabled:opacity-40",children:d("common.retry")})]}):F?p.entries.length===0?e.jsx("p",{className:"p-4 text-center text-xs text-muted-foreground",children:d("rightSidebar.gitIgnoreExceptionsEmptyDirectory")}):p.entries.map(N=>{const P=c?`${c}/${N.name}`:N.name,B=P+(N.type==="directory"?"/":""),q=n.includes(B)||n.includes(P),j=n.some(_=>_.endsWith("/")&&P.startsWith(_)),o=N.type==="directory"?cl:lp;return e.jsxs("div",{className:"flex items-center gap-1 rounded-md hover:bg-surface-elevated",children:[e.jsxs("label",{className:"flex min-h-10 min-w-0 flex-1 cursor-pointer items-center gap-2 px-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:q||j,disabled:s||j,onChange:()=>M(q?n.filter(_=>_!==B&&_!==P):[...n,B]),className:"h-4 w-4 shrink-0 accent-[var(--primary)] disabled:opacity-40"}),e.jsx(o,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",title:N.name,children:N.name})]}),N.type==="directory"&&e.jsx("button",{type:"button",disabled:s,onClick:()=>D(P),"aria-label":d("rightSidebar.gitIgnoreExceptionsOpenDirectory",{name:N.name}),className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface hover:text-foreground disabled:opacity-40",children:e.jsx(fs,{size:15})})]},N.name)}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(dt,{size:18})}),F&&p.truncated&&e.jsx("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:d("rightSidebar.gitIgnoreExceptionsTruncated")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"font-medium",children:d("rightSidebar.gitIgnoreExceptionsSelected",{count:n.length})}),e.jsx("button",{type:"button",disabled:s||n.length===0,onClick:()=>M([]),className:"rounded-md px-2 py-1 text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:d("rightSidebar.gitIgnoreExceptionsClear")})]}),n.length>0&&e.jsx("ul",{className:"max-h-24 overflow-y-auto overscroll-contain",children:n.map(N=>e.jsxs("li",{className:"flex items-center gap-2 rounded-md pl-2 text-xs hover:bg-surface-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:N,children:N}),e.jsx("button",{type:"button",disabled:s,onClick:()=>M(n.filter(P=>P!==N)),"aria-label":d("rightSidebar.gitIgnoreExceptionsRemove",{path:N}),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:13})})]},N))}),E&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:d("rightSidebar.gitIgnoreExceptionsInvalid")})]})}function pg({rootPath:r,disabled:n,pressed:s,saving:l,onToggle:d}){const{t:c}=ft(),m=a.useId(),g=a.useRef(null),f=a.useRef(null),p=a.useRef(null),x=a.useRef(null),h=a.useRef(!1),[b,E]=a.useState(!1),[S,T]=a.useState([]),[D,F]=a.useState(!1),[M,N]=a.useState(null),P=Q(I=>I.setGitIgnoreExceptions),B=()=>{p.current!==null&&clearTimeout(p.current),p.current=null,x.current=null},q=()=>{B(),!(n||D||!r)&&(T([...Q.getState().gitIgnoreExceptions[r]??[]]),N(null),E(!0))},j=()=>{D||E(!1)},o=I=>{B(),h.current=!1,!(I.button!==0||!I.isPrimary||n)&&(I.currentTarget.setPointerCapture(I.pointerId),x.current={x:I.clientX,y:I.clientY},p.current=setTimeout(()=>{h.current=!0,q()},450))};a.useEffect(()=>(E(!1),B(),B),[r]),a.useEffect(()=>{if(b)return f.current?.focus(),()=>g.current?.focus()},[b]);const _=c(s?"rightSidebar.showGitIgnoredFiles":"rightSidebar.hideGitIgnoredFiles");return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",disabled:n||D,"aria-pressed":s,"aria-label":_,"aria-description":c("rightSidebar.gitIgnoreConfigureHint"),title:`${_} · ${c("rightSidebar.gitIgnoreConfigureHint")}`,onClick:I=>{if(h.current&&I.detail!==0){h.current=!1,I.preventDefault();return}d()},onContextMenu:I=>{I.preventDefault(),h.current=!0,b||q()},onPointerDown:o,onPointerMove:I=>{const V=x.current;V&&Math.hypot(I.clientX-V.x,I.clientY-V.y)>10&&B()},onPointerUp:B,onPointerCancel:B,onLostPointerCapture:B,className:`inline-flex h-7 w-7 shrink-0 select-none items-center justify-center rounded-md transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-35 [-webkit-touch-callout:none] ${s?"bg-surface-2 text-primary hover:bg-surface-elevated":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:l?e.jsx(dt,{size:14}):e.jsx(zp,{size:14})}),b&&jr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop flex items-center justify-center bg-[var(--app-backdrop)] p-3 backdrop-blur-sm",onClick:j,children:e.jsxs("form",{ref:f,role:"dialog",tabIndex:-1,"aria-modal":"true","aria-labelledby":`${m}-title`,"aria-describedby":`${m}-hint`,className:"relative z-modal-panel flex max-h-[80dvh] w-full max-w-lg flex-col gap-3 overflow-y-auto rounded-xl border border-border/20 bg-surface p-4 text-foreground shadow-2xl",onClick:I=>I.stopPropagation(),onKeyDown:I=>{if(I.key==="Escape"&&(I.preventDefault(),I.stopPropagation(),j()),I.key==="Tab"){const V=Array.from(f.current?.querySelectorAll("button:not(:disabled), input:not(:disabled)")??[]);if(!V.length){I.preventDefault(),f.current?.focus();return}const W=V[0],O=V[V.length-1];I.shiftKey&&document.activeElement===W&&(I.preventDefault(),O?.focus()),document.activeElement===f.current?(I.preventDefault(),(I.shiftKey?O:W)?.focus()):!I.shiftKey&&document.activeElement===O&&(I.preventDefault(),W?.focus())}},onSubmit:I=>{if(I.preventDefault(),!(!r||D)){if(S.length>200){N(c("rightSidebar.gitIgnoreExceptionsInvalid"));return}F(!0),N(null),P(r,S).then(()=>E(!1)).catch(()=>N(c("rightSidebar.gitIgnoreExceptionsSaveFailed"))).finally(()=>F(!1))}},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{id:`${m}-title`,className:"text-sm font-medium",children:c("rightSidebar.gitIgnoreExceptionsTitle")}),e.jsx("button",{type:"button",disabled:D,onClick:j,"aria-label":c("common.close"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:16})})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:r??void 0,children:r}),e.jsx("p",{id:`${m}-hint`,className:"text-xs leading-relaxed text-muted-foreground",children:c("rightSidebar.gitIgnoreExceptionsHint")}),e.jsx("p",{className:"text-xs font-medium",children:c("rightSidebar.gitIgnoreExceptionsPaths")}),r&&e.jsx(mg,{rootPath:r,paths:S,onChange:T,disabled:D}),M&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:M}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",disabled:D,onClick:j,className:"rounded-lg px-3 py-2 text-xs text-muted-foreground hover:bg-surface-2 disabled:opacity-40",children:c("common.cancel")}),e.jsxs("button",{type:"submit",disabled:D,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-xs font-medium text-primary-foreground disabled:opacity-50",children:[D&&e.jsx(dt,{size:13}),c("common.save")]})]})]})}),document.body)]})}function gg(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,d=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!d)return Promise.resolve(null);const c=r instanceof HTMLImageElement?1400/Math.max(l,d):Math.min(1,1400/Math.max(l,d)),m=document.createElement("canvas");m.width=Math.max(1,Math.round(l*c)),m.height=Math.max(1,Math.round(d*c));const g=m.getContext("2d");if(!g)return Promise.resolve(null);const f=getComputedStyle(document.documentElement);if(g.fillStyle=f.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,m.width,m.height),g.drawImage(r,0,0,m.width,m.height),s){const p=Math.max(10,Math.min(16,m.width/35));g.font=`${p}px sans-serif`;const x=[];let h="";for(const b of s.split(" "))h&&g.measureText(`${h} ${b}`).width>m.width-20?(x.push(h),h=b):h=h?`${h} ${b}`:b;h&&x.push(h),g.fillStyle=f.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,m.width,x.length*(p+4)+12),g.fillStyle=f.getPropertyValue("--foreground").trim()||"black",x.forEach((b,E)=>g.fillText(b,10,8+p+E*(p+4)))}if(n){const p=n.xPercent*m.width/100,x=n.yPercent*m.height/100,h=Math.max(4,Math.min(12,Math.min(m.width,m.height)*.015)),b=h*1.6;g.strokeStyle=f.getPropertyValue("--primary").trim()||"black",g.lineWidth=Math.max(1,h/3),g.beginPath(),g.arc(p,x,h,0,Math.PI*2),g.stroke(),g.beginPath(),g.moveTo(p-b,x),g.lineTo(p+b,x),g.moveTo(p,x-b),g.lineTo(p,x+b),g.stroke()}return new Promise(p=>m.toBlob(p,"image/png"))}catch{return Promise.resolve(null)}}function bg(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
- `)}function S0(r,n,s){const l=n*Math.PI/360,d=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(d)*1.15}async function xg(r,n,s,l){if(!s?.snapshot)return l.isCurrent()?await l.insert(r,n):!1;const d=new Date().toISOString(),c=new AbortController;let m,g;try{g=await Promise.race([(async()=>{const f=await s.snapshot;if(!(!f||c.signal.aborted||!l.isCurrent()))return l.upload(new File([f],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(f=>{m=setTimeout(()=>{c.abort(),f(void 0)},3e3)})])}catch{}finally{clearTimeout(m),c.abort()}return l.isCurrent()?await l.insert(g?bg(r,"",d,g):r,n):!1}function vg(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function iu(r,n){return`${r??""}\0${n}`}function yg(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=iu(n,s);let d=0,c=0;for(const m of r){const g=[m.filePath,m.newPath,m.oldPath].filter(p=>typeof p=="string"&&p.length>0);(g.some(p=>iu(m.repoRoot,p)===l)||g.some(p=>vg(p,s)))&&(d+=1)}return{explained:d,stale:c}}function wg({status:r}){if(!r)return null;const n=r.stale>0&&r.explained===0;if(!(r.explained>0||r.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(Tp,{size:10}):e.jsx(na,{size:10})})}function gl({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(wg,{status:n})]})}const df="termdock:right-sidebar:diff-change-list-mode:v1";function kg(r){return r==="list"||r==="tree"}function Sg(){return pt(df,kg)??"tree"}function jg(r){for(const n of r){const s=n.hunk;if(s.oldPath&&s.newPath&&s.oldPath!==s.newPath)return"renamed";if(s.oldPath===null&&s.newPath)return"added";if(s.oldPath&&s.newPath===null)return"deleted"}return"modified"}function Rg(r){const n=new Map;for(const l of r){const d=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};d.items.push(l),d.additions+=l.hunk.additions,d.deletions+=l.hunk.deletions,l.current&&(d.explained+=1),l.stale&&(d.stale+=1),n.set(l.hunk.filePath,d)}const s=Array.from(n.values()).sort((l,d)=>l.filePath.localeCompare(d.filePath));for(const l of s)l.changeType=jg(l.items);return s}function Cg(r){const n=r.filePath.split("/").pop()??r.filePath;return{key:r.key,path:r.filePath,displayName:n,displayDir:r.filePath.includes("/")?r.filePath.slice(0,-n.length-1):"",status:r.changeType,title:r.filePath}}function Ng(r,n){const s=r.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],d=new Set;for(const[c,m]of s.entries()){const g=m.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-B8k3pAmc.js","assets/app-BCTEfclM.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-BObjbh2R.css","assets/purify.es-4eNOHKSq.js","assets/ModelPreview-Bzdi_sPh.js","assets/App-BF_s1-_u.js","assets/gestureArbiter-Xl7awIrX.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-BwJ6Q_Y0.js","assets/referenceLongPress-YuGU-PYw.js","assets/DiffReview-CBf8-Tli.js","assets/sparkles-DFYGpezN.js","assets/DiffViewer-DZfgjOBh.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-DHp5r1k9.js","assets/ArchitecturePanel-CdgUQsVD.js","assets/ArchitecturePanel-B_BDrrfR.css","assets/ComputerControlView-B5Yng8Dt.js","assets/katex-55ZPZeOF.css"])))=>i.map(i=>d[i]);
2
+ import{ag as cr,da as ft,by as e,h as ko,ct as _d,ap as Ku,_ as $n,bG as qu,L as dt,e as hs,X as Pt,dg as J,dn as Lt,bT as pt,a as na,b1 as Vu,C as So,d as sa,d6 as Xs,d7 as dl,U as Bd,bj as Bm,O as Hs,ay as Om,bq as Um,bs as Pl,bt as Hm,bu as Yu,br as zs,aO as zm,E as Wm,k as Gm,bn as Km,bV as qm,bX as Vm,bY as Ym,be as Xm,bW as Od,N as Nt,g as Jm,j as Ui,I as Qm,b as Zm,d8 as Hi,bd as Ud,aI as Hd,aE as ep,aS as zi,aT as zd,dp as Zs,av as Ws,aU as tp,bL as rp,cT as Wd,aL as np,d4 as sp,co as ap,dh as Xr,aX as op,a2 as Gd,a1 as ip,aF as Kd,aK as lp,aQ as qd,cq as cp,z as Vd,l as Yd,r as Xd,J as Xu,at as Ju,cg as dp,dl as up,n as fp}from"./app-BCTEfclM.js";import{b as a,r as Rr}from"./dnd-BCFAPC0L.js";import{i as Al,F as hp,J as Qu,x as mp,O as Jd,W as go,m as pp,ah as Zu,Y as gp,w as bp,E as xp,s as vp,M as yp,R as bo,a5 as ef,a6 as wp,S as ms,n as tf,g as kp,am as rf,A as Wi,aj as Sp,ai as En,a7 as jp,a8 as Rp,ak as Np,aa as Qd,V as Zd,r as eu,k as tu,B as Gi,z as so,h as Cp,Q as Ep,y as Mp,N as ru,q as $p,T as Lp,o as nu,C as Pp,c as Ap,G as Tp,f as Ip}from"./App-BF_s1-_u.js";import{F as ul,a as su,S as au,b as nf,c as fl}from"./gestureArbiter-Xl7awIrX.js";import{D as hl,C as ea,L as sf,f as Dp,n as Fp}from"./DiffReview-CBf8-Tli.js";import{T as _p,L as jo,M as af,G as kr}from"./triangle-alert-BwJ6Q_Y0.js";import{S as aa}from"./sparkles-DFYGpezN.js";import{C as of,M as lf}from"./ChangeWalkthroughPanel-DHp5r1k9.js";import{r as cf,s as df,l as uf,a as ou,h as ml,u as Bp,g as pl,b as ff}from"./DiffViewer-DZfgjOBh.js";import{u as hf,G as mf}from"./referenceLongPress-YuGU-PYw.js";const Op=[["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"}]],Up=cr("case-sensitive",Op);const Hp=[["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"}]],zp=cr("eye-off",Hp);const Wp=[["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"}]],gl=cr("eye",Wp);const Gp=[["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"}]],bl=cr("file-text",Gp);const Kp=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],qp=cr("funnel",Kp);const Vp=[["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"}]],Yp=cr("image-plus",Vp);const Xp=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],iu=cr("loader-circle",Xp);const Jp=[["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"}]],Qp=cr("regex",Jp);const Zp=[["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"}]],eg=cr("scan",Zp);const tg=[["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"}]],rg=cr("upload",tg);const ng=[["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"}]],sg=cr("whole-word",ng),ag=100,og=5e5,ig=1e4,lu=16384,lg=32,cg=1e5;class cs extends Error{constructor(n){super(`Markdown preview parsing stopped: ${n}`),this.reason=n,this.name="MarkdownParseError"}reason}class dg{startedAt=performance.now();operations=0;depth=0;check(){if(++this.operations>cg)throw new cs("complexity");if(performance.now()-this.startedAt>=ag)throw new cs("timeout")}validateLines(n){if(n.length>ig)throw new cs("size");let s=0;for(const l of n)if(this.check(),s+=l.length+1,s>og||l.length>lu)throw new cs("size")}validateInline(n){if(this.check(),n.length>lu)throw new cs("size")}nested(n){if(this.check(),this.depth>=lg)throw new cs("depth");this.depth+=1;try{return n()}finally{this.depth-=1}}}const cu=new RegExp(`(\\\\\\([^)]*\\\\\\)|\\$[^$\\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+(?:"[^"]*"|'[^']*'|\\([^)]*\\)))?\\)|!?\\[[^\\]]+\\]\\[[^\\]]*\\]|!?\\[[^\\]]+\\]|\\[\\^[^\\]]+\\]|~~[^~]+~~|\\*\\*[^*]+\\*\\*|(?<![\\p{L}\\p{N}_])__[^_]+__(?![\\p{L}\\p{N}_])|\\*[^*\\s][^*]*\\*|(?<![\\p{L}\\p{N}_])_[^_\\s][^_]*_(?![\\p{L}\\p{N}_])|<https?:\\/\\/[^>\\s]+>|<[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+>|https?:\\/\\/[^\\s<]+|www\\.[^\\s<]+|[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+)`,"iyu");function ug(r,n,s){let l=n;for(;r[l]==="`";)l+=1;const d=l-n;let c=l;for(;c<r.length;){s.check();const m=r.indexOf("`",c);if(m<0)return null;for(c=m;r[c]==="`";)c+=1;if(c-m===d)return c}return null}function*fg(r,n){n.validateInline(r);const s=new RegExp(cu.source,cu.flags);let l=0;for(;l<r.length;){if(n.check(),r[l]==="`"){const c=ug(r,l,n);if(c!==null)yield{index:l,token:r.slice(l,c)},l=c;else for(;r[l]==="`";)l+=1;continue}s.lastIndex=l;const d=s.exec(r);n.check(),d?(yield{index:l,token:d[0]},l=s.lastIndex):l+=(r.codePointAt(l)??0)>65535?2:1}}function du({children:r,actions:n}){const{t:s}=ft(),[l,d]=a.useState(!1),c=a.useId(),m=a.useRef(null),g=a.useRef(null),f=()=>{d(!1),m.current?.focus({preventScroll:!0})};return a.useLayoutEffect(()=>{if(!l)return;const p=m.current,x=g.current;if(!p||!x)return;const h=window.visualViewport,b=()=>{const S=p.getBoundingClientRect(),T=(h?.offsetLeft??0)+8,D=(h?.offsetTop??0)+8,F=Math.max(0,(h?.width??window.innerWidth)-16),M=D+(h?.height??window.innerHeight)-16,C=Math.min(240,F),P=Math.max(0,S.top-D-6),B=Math.max(0,M-S.bottom-6),q=x.scrollHeight>B&&P>B;Object.assign(x.style,{width:`${C}px`,left:`${Math.max(T,Math.min(S.right-C,T+F-C))}px`,top:`${q?S.top-6:S.bottom+6}px`,maxHeight:`${q?P:B}px`,transform:q?"translateY(-100%)":"none"})};b();const E=typeof ResizeObserver>"u"?null:new ResizeObserver(b);return E?.observe(p),E?.observe(x),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),h?.addEventListener("resize",b),h?.addEventListener("scroll",b),()=>{E?.disconnect(),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),h?.removeEventListener("resize",b),h?.removeEventListener("scroll",b)}},[l]),a.useEffect(()=>{if(!l)return;g.current?.querySelector("button:not(:disabled)")?.focus({preventScroll:!0});const p=x=>{x.target instanceof Node&&!m.current?.contains(x.target)&&!g.current?.contains(x.target)&&d(!1)};return document.addEventListener("pointerdown",p),()=>document.removeEventListener("pointerdown",p)},[l]),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:m,type:"button","aria-haspopup":"menu","aria-expanded":l,"aria-controls":l?c:void 0,onClick:()=>d(p=>!p),onKeyDown:p=>{(p.key==="ArrowDown"||p.key==="ArrowUp")&&(p.preventDefault(),d(!0))},className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-[11px] font-medium transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary ${l?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(ko,{size:14}),s("sidebar.moreActions")]})]}),typeof document<"u"&&Rr.createPortal(e.jsx("div",{ref:g,id:c,hidden:!l,role:"menu","data-sidebar-gesture-ignore":!0,"aria-label":s("sidebar.moreActions"),className:"fixed z-menu-panel overflow-y-auto overscroll-contain rounded-lg border border-border/30 bg-surface p-1 shadow-[0_8px_24px_var(--app-shadow-soft)]",onKeyDown:p=>{if(!p.currentTarget.contains(p.target))return;const x=[...p.currentTarget.querySelectorAll("button:not(:disabled)")],h=x.indexOf(document.activeElement);let b;if(p.key==="Escape"){p.preventDefault(),p.stopPropagation(),f();return}if(p.key==="Tab"){f();return}if(p.key==="ArrowDown")b=(h+1)%x.length;else if(p.key==="ArrowUp")b=(h-1+x.length)%x.length;else if(p.key==="Home")b=0;else if(p.key==="End")b=x.length-1;else return;p.preventDefault(),x[b]?.focus({preventScroll:!0})},children:n(f)}),document.body)]})}const Ki="a[href],button,input,select,textarea,[tabindex],[contenteditable],iframe,summary,audio[controls],video[controls]",ds=a.memo(function({active:n,mounted:s=!0,fallback:l=null,children:d}){const c=a.useRef(null);return a.useLayoutEffect(()=>{const m=c.current;if(!m||n)return;const g=new Map,f=h=>{g.has(h)||(g.set(h,h.inert),h.inert=!0)},p=h=>{h instanceof HTMLElement&&h.matches(Ki)&&f(h),h.querySelectorAll(Ki).forEach(f)};p(m);const x=new MutationObserver(h=>{for(const b of h)b.type==="attributes"?b.target instanceof HTMLElement&&b.target.matches(Ki)&&f(b.target):b.addedNodes.forEach(E=>{E instanceof Element&&p(E)})});return x.observe(m,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabindex","href","contenteditable","controls"]}),()=>{x.disconnect();for(const[h,b]of g)h.inert=b}},[n,s]),e.jsx("div",{ref:c,className:"absolute inset-0 min-h-0 overflow-hidden bg-surface text-foreground",style:n?void 0:{clipPath:"inset(100%)"},"aria-hidden":!n,children:s?typeof d=="function"?d():d:l})},(r,n)=>!r.active&&!n.active&&r.mounted===n.mounted);async function hg(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function mg({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:d,load:c}){a.useEffect(()=>{if(!r||!n||s||d.current===n)return;const m=window.setTimeout(()=>{d.current=n,c(n)},l);return()=>window.clearTimeout(m)},[r,n,s,l,d,c])}async function pg(r){if(r.kind==="mermaid"){await _d(new Blob([r.svg],{type:"image/svg+xml"}),"mermaid.svg");return}const n=new URL(r.src,window.location.href);if(n.origin===window.location.origin&&n.pathname==="/api/terminal/fs/blob"){const c=n.searchParams.get("path");if(!c)throw new Error("Missing image path");await Ku(c);return}const s=await fetch(r.src);if(!s.ok)throw new Error(`HTTP ${s.status}`);const l=await s.blob(),d=decodeURIComponent(n.pathname.split("/").pop()||"")||`image.${{"image/svg+xml":"svg","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif"}[l.type]||"png"}`;await _d(l,d)}let ao=null,uu=!1;function gg(){return ao||(ao=$n(()=>import("./mermaid.core-B8k3pAmc.js").then(r=>r.bl),__vite__mapDeps([0,1,2,3,4,5,6])).then(r=>r.default??r).catch(r=>{throw ao=null,r})),ao}function bg(r){uu||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),uu=!0)}function xg({rootPath:r,paths:n,disabled:s,onChange:l}){const{t:d}=ft(),[c,m]=a.useState(""),[g,f]=a.useState(0),[p,x]=a.useState(null),[h,b]=a.useState(!1),[E,S]=a.useState(!1),T=`${r.replace(/[\\/]+$/,"")}/${c}`;a.useEffect(()=>{const C=new AbortController;return x(null),b(!1),qu(T,C.signal,!0,"pick_git_ignore_exception").then(P=>{C.signal.aborted||x({directory:c,entries:P.entries,truncated:!!P.truncated})}).catch(()=>{C.signal.aborted||b(!0)}),()=>C.abort()},[T,c,g]);const D=C=>{x(null),b(!1),m(C)},F=p?.directory===c,M=C=>{if(C.length>200){S(!0);return}S(!1),l(C)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/30 bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/20 p-2",children:[e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(c.slice(0,Math.max(0,c.lastIndexOf("/")))),"aria-label":d("rightSidebar.parentFolder"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(Al,{size:14})}),e.jsx("button",{type:"button",disabled:s||!c,onClick:()=>D(""),"aria-label":d("rightSidebar.backToProjectRoot"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-30",children:e.jsx(ul,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs",title:T,children:c||"./"})]}),e.jsxs("div",{className:"h-56 overflow-y-auto overscroll-contain p-1",role:"group","aria-label":d("rightSidebar.gitIgnoreExceptionsPaths"),"aria-busy":!F&&!h,children:[h?e.jsxs("div",{className:"flex flex-col items-center gap-2 p-4 text-center text-xs",children:[e.jsx("p",{role:"alert",className:"text-destructive",children:d("rightSidebar.gitIgnoreExceptionsLoadFailed")}),e.jsx("button",{type:"button",disabled:s,onClick:()=>{b(!1),f(C=>C+1)},className:"rounded-md px-3 py-2 text-primary hover:bg-surface-elevated disabled:opacity-40",children:d("common.retry")})]}):F?p.entries.length===0?e.jsx("p",{className:"p-4 text-center text-xs text-muted-foreground",children:d("rightSidebar.gitIgnoreExceptionsEmptyDirectory")}):p.entries.map(C=>{const P=c?`${c}/${C.name}`:C.name,B=P+(C.type==="directory"?"/":""),q=n.includes(B)||n.includes(P),j=n.some(_=>_.endsWith("/")&&P.startsWith(_)),o=C.type==="directory"?ul:hp;return e.jsxs("div",{className:"flex items-center gap-1 rounded-md hover:bg-surface-elevated",children:[e.jsxs("label",{className:"flex min-h-10 min-w-0 flex-1 cursor-pointer items-center gap-2 px-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:q||j,disabled:s||j,onChange:()=>M(q?n.filter(_=>_!==B&&_!==P):[...n,B]),className:"h-4 w-4 shrink-0 accent-[var(--primary)] disabled:opacity-40"}),e.jsx(o,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",title:C.name,children:C.name})]}),C.type==="directory"&&e.jsx("button",{type:"button",disabled:s,onClick:()=>D(P),"aria-label":d("rightSidebar.gitIgnoreExceptionsOpenDirectory",{name:C.name}),className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface hover:text-foreground disabled:opacity-40",children:e.jsx(hs,{size:15})})]},C.name)}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(dt,{size:18})}),F&&p.truncated&&e.jsx("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:d("rightSidebar.gitIgnoreExceptionsTruncated")})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"font-medium",children:d("rightSidebar.gitIgnoreExceptionsSelected",{count:n.length})}),e.jsx("button",{type:"button",disabled:s||n.length===0,onClick:()=>M([]),className:"rounded-md px-2 py-1 text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:d("rightSidebar.gitIgnoreExceptionsClear")})]}),n.length>0&&e.jsx("ul",{className:"max-h-24 overflow-y-auto overscroll-contain",children:n.map(C=>e.jsxs("li",{className:"flex items-center gap-2 rounded-md pl-2 text-xs hover:bg-surface-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:C,children:C}),e.jsx("button",{type:"button",disabled:s,onClick:()=>M(n.filter(P=>P!==C)),"aria-label":d("rightSidebar.gitIgnoreExceptionsRemove",{path:C}),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-elevated hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:13})})]},C))}),E&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:d("rightSidebar.gitIgnoreExceptionsInvalid")})]})}function vg({rootPath:r,disabled:n,pressed:s,saving:l,onToggle:d}){const{t:c}=ft(),m=a.useId(),g=a.useRef(null),f=a.useRef(null),p=a.useRef(null),x=a.useRef(null),h=a.useRef(!1),[b,E]=a.useState(!1),[S,T]=a.useState([]),[D,F]=a.useState(!1),[M,C]=a.useState(null),P=J(I=>I.setGitIgnoreExceptions),B=()=>{p.current!==null&&clearTimeout(p.current),p.current=null,x.current=null},q=()=>{B(),!(n||D||!r)&&(T([...J.getState().gitIgnoreExceptions[r]??[]]),C(null),E(!0))},j=()=>{D||E(!1)},o=I=>{B(),h.current=!1,!(I.button!==0||!I.isPrimary||n)&&(I.currentTarget.setPointerCapture(I.pointerId),x.current={x:I.clientX,y:I.clientY},p.current=setTimeout(()=>{h.current=!0,q()},450))};a.useEffect(()=>(E(!1),B(),B),[r]),a.useEffect(()=>{if(b)return f.current?.focus(),()=>g.current?.focus()},[b]);const _=c(s?"rightSidebar.showGitIgnoredFiles":"rightSidebar.hideGitIgnoredFiles");return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:g,type:"button",disabled:n||D,"aria-pressed":s,"aria-label":_,"aria-description":c("rightSidebar.gitIgnoreConfigureHint"),title:`${_} · ${c("rightSidebar.gitIgnoreConfigureHint")}`,onClick:I=>{if(h.current&&I.detail!==0){h.current=!1,I.preventDefault();return}d()},onContextMenu:I=>{I.preventDefault(),h.current=!0,b||q()},onPointerDown:o,onPointerMove:I=>{const V=x.current;V&&Math.hypot(I.clientX-V.x,I.clientY-V.y)>10&&B()},onPointerUp:B,onPointerCancel:B,onLostPointerCapture:B,className:`inline-flex h-7 w-7 shrink-0 select-none items-center justify-center rounded-md transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-35 [-webkit-touch-callout:none] ${s?"bg-surface-2 text-primary hover:bg-surface-elevated":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:l?e.jsx(dt,{size:14}):e.jsx(qp,{size:14})}),b&&Rr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop flex items-center justify-center bg-[var(--app-backdrop)] p-3 backdrop-blur-sm",onClick:j,children:e.jsxs("form",{ref:f,role:"dialog",tabIndex:-1,"aria-modal":"true","aria-labelledby":`${m}-title`,"aria-describedby":`${m}-hint`,className:"relative z-modal-panel flex max-h-[80dvh] w-full max-w-lg flex-col gap-3 overflow-y-auto rounded-xl border border-border/20 bg-surface p-4 text-foreground shadow-2xl",onClick:I=>I.stopPropagation(),onKeyDown:I=>{if(I.key==="Escape"&&(I.preventDefault(),I.stopPropagation(),j()),I.key==="Tab"){const V=Array.from(f.current?.querySelectorAll("button:not(:disabled), input:not(:disabled)")??[]);if(!V.length){I.preventDefault(),f.current?.focus();return}const W=V[0],O=V[V.length-1];I.shiftKey&&document.activeElement===W&&(I.preventDefault(),O?.focus()),document.activeElement===f.current?(I.preventDefault(),(I.shiftKey?O:W)?.focus()):!I.shiftKey&&document.activeElement===O&&(I.preventDefault(),W?.focus())}},onSubmit:I=>{if(I.preventDefault(),!(!r||D)){if(S.length>200){C(c("rightSidebar.gitIgnoreExceptionsInvalid"));return}F(!0),C(null),P(r,S).then(()=>E(!1)).catch(()=>C(c("rightSidebar.gitIgnoreExceptionsSaveFailed"))).finally(()=>F(!1))}},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{id:`${m}-title`,className:"text-sm font-medium",children:c("rightSidebar.gitIgnoreExceptionsTitle")}),e.jsx("button",{type:"button",disabled:D,onClick:j,"aria-label":c("common.close"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground disabled:opacity-40",children:e.jsx(Pt,{size:16})})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:r??void 0,children:r}),e.jsx("p",{id:`${m}-hint`,className:"text-xs leading-relaxed text-muted-foreground",children:c("rightSidebar.gitIgnoreExceptionsHint")}),e.jsx("p",{className:"text-xs font-medium",children:c("rightSidebar.gitIgnoreExceptionsPaths")}),r&&e.jsx(xg,{rootPath:r,paths:S,onChange:T,disabled:D}),M&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:M}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",disabled:D,onClick:j,className:"rounded-lg px-3 py-2 text-xs text-muted-foreground hover:bg-surface-2 disabled:opacity-40",children:c("common.cancel")}),e.jsxs("button",{type:"submit",disabled:D,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-xs font-medium text-primary-foreground disabled:opacity-50",children:[D&&e.jsx(dt,{size:13}),c("common.save")]})]})]})}),document.body)]})}function yg(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,d=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!d)return Promise.resolve(null);const c=r instanceof HTMLImageElement?1400/Math.max(l,d):Math.min(1,1400/Math.max(l,d)),m=document.createElement("canvas");m.width=Math.max(1,Math.round(l*c)),m.height=Math.max(1,Math.round(d*c));const g=m.getContext("2d");if(!g)return Promise.resolve(null);const f=getComputedStyle(document.documentElement);if(g.fillStyle=f.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,m.width,m.height),g.drawImage(r,0,0,m.width,m.height),s){const p=Math.max(10,Math.min(16,m.width/35));g.font=`${p}px sans-serif`;const x=[];let h="";for(const b of s.split(" "))h&&g.measureText(`${h} ${b}`).width>m.width-20?(x.push(h),h=b):h=h?`${h} ${b}`:b;h&&x.push(h),g.fillStyle=f.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,m.width,x.length*(p+4)+12),g.fillStyle=f.getPropertyValue("--foreground").trim()||"black",x.forEach((b,E)=>g.fillText(b,10,8+p+E*(p+4)))}if(n){const p=n.xPercent*m.width/100,x=n.yPercent*m.height/100,h=Math.max(4,Math.min(12,Math.min(m.width,m.height)*.015)),b=h*1.6;g.strokeStyle=f.getPropertyValue("--primary").trim()||"black",g.lineWidth=Math.max(1,h/3),g.beginPath(),g.arc(p,x,h,0,Math.PI*2),g.stroke(),g.beginPath(),g.moveTo(p-b,x),g.lineTo(p+b,x),g.moveTo(p,x-b),g.lineTo(p,x+b),g.stroke()}return new Promise(p=>m.toBlob(p,"image/png"))}catch{return Promise.resolve(null)}}function wg(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
+ `)}function C0(r,n,s){const l=n*Math.PI/360,d=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(d)*1.15}async function kg(r,n,s,l){if(!s?.snapshot)return l.isCurrent()?await l.insert(r,n):!1;const d=new Date().toISOString(),c=new AbortController;let m,g;try{g=await Promise.race([(async()=>{const f=await s.snapshot;if(!(!f||c.signal.aborted||!l.isCurrent()))return l.upload(new File([f],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(f=>{m=setTimeout(()=>{c.abort(),f(void 0)},3e3)})])}catch{}finally{clearTimeout(m),c.abort()}return l.isCurrent()?await l.insert(g?wg(r,"",d,g):r,n):!1}function Sg(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function fu(r,n){return`${r??""}\0${n}`}function jg(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=fu(n,s);let d=0,c=0;for(const m of r){const g=[m.filePath,m.newPath,m.oldPath].filter(p=>typeof p=="string"&&p.length>0);(g.some(p=>fu(m.repoRoot,p)===l)||g.some(p=>Sg(p,s)))&&(d+=1)}return{explained:d,stale:c}}function Rg({status:r}){if(!r)return null;const n=r.stale>0&&r.explained===0;if(!(r.explained>0||r.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(_p,{size:10}):e.jsx(aa,{size:10})})}function xl({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(Rg,{status:n})]})}const pf="termdock:right-sidebar:diff-change-list-mode:v1";function Ng(r){return r==="list"||r==="tree"}function Cg(){return pt(pf,Ng)??"tree"}function Eg(r){for(const n of r){const s=n.hunk;if(s.oldPath&&s.newPath&&s.oldPath!==s.newPath)return"renamed";if(s.oldPath===null&&s.newPath)return"added";if(s.oldPath&&s.newPath===null)return"deleted"}return"modified"}function Mg(r){const n=new Map;for(const l of r){const d=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};d.items.push(l),d.additions+=l.hunk.additions,d.deletions+=l.hunk.deletions,l.current&&(d.explained+=1),l.stale&&(d.stale+=1),n.set(l.hunk.filePath,d)}const s=Array.from(n.values()).sort((l,d)=>l.filePath.localeCompare(d.filePath));for(const l of s)l.changeType=Eg(l.items);return s}function $g(r){const n=r.filePath.split("/").pop()??r.filePath;return{key:r.key,path:r.filePath,displayName:n,displayDir:r.filePath.includes("/")?r.filePath.slice(0,-n.length-1):"",status:r.changeType,title:r.filePath}}function Lg(r,n){const s=r.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],d=new Set;for(const[c,m]of s.entries()){const g=m.split(`
4
4
  `),f=g.findIndex(h=>h.startsWith("@@ "));if(f<0){l.push(...g);continue}c===0&&l.push(...g.slice(0,f));const p=n[c];let x=f;for(;x>=0&&x<g.length;){const h=g.findIndex((F,M)=>M>x&&F.startsWith("@@ ")),b=h>=0?h:g.length,E=g.slice(x,b),S=E[0]??"",T=p?S===p:!0,D=S||p||E.join(`
5
5
  `);T&&!d.has(D)&&(l.push(...E),d.add(D)),x=h}}return l.join(`
6
- `)}function Eg({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Ng(s.items.map(f=>f.hunk.diff||f.current?.diff||f.stale?.diff||""),s.items.map(f=>f.hunk.hunkHeader)),d=s.items.map(f=>f.current??f.stale).filter(f=>!!f).map(f=>({id:f.id,repoRoot:f.repoRoot,filePath:f.filePath,oldPath:f.oldPath,newPath:f.newPath,hunkHeader:f.hunkHeader,hunkIndex:f.hunkIndex,fingerprint:f.fingerprint,diff:f.diff,explanation:f.explanation,summary:f.summary,workspaceRoot:f.workspaceRoot,generatedBy:f.generatedBy,injectedAt:f.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,m=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"",g=s.items[0]?.repoRoot??d[0]?.repoRoot??null;return{key:s.key,path:s.filePath,oldPath:s.items[0]?.hunk.oldPath??void 0,absolutePath:g?`${g}/${s.items[0]?.repositoryPath??s.filePath}`:s.filePath,status:s.changeType,repoRoot:g,displayName:c,displayDir:m,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(f=>f.hunk.previewRevert?[[f.hunk.hunkHeader,f.hunk.previewRevert]]:[])),auditRecords:d,onInsertDiffReference:n}})}function Mg(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let m=null,g=Number.POSITIVE_INFINITY;for(const p of l){const x=p.getBoundingClientRect();if(x.bottom<c)continue;const h=Math.abs(x.top-c);h<g&&(m=p,g=h)}const f=m?.dataset.diffSelectionPath??m?.dataset.diffStreamItem??null;return!f||f===n||s(f),f}function lu({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:d=!1,backLabel:c="Back",headerTitle:m,headerMeta:g,onClose:f,closeLabel:p="Back",wrap:x=!0,diffViewType:h,inlineMode:b,viewControls:E,onToggleWrap:S,wrapTitle:T,wrapOnLabel:D="Wrap on",wrapOffLabel:F="Wrap off",desktopLayout:M="split",onInsertDiffReference:N,onReferenceCopied:P,renderPathReference:B,insertedReferenceKey:q,copiedReferenceKey:j,onClearAuditRecord:o,onRefresh:_,localOptions:I,onHunkGitAction:V,error:W,refreshing:O,actionsBusy:R,refreshLabel:H,refreshTitle:ee,walkthroughs:L=[],onWalkthroughNavigate:U,initialDetailScrollTop:X,onDetailScrollPositionChange:ce,scrollToKey:he,scrollToKeyNonce:Re,externalSwiperRef:Ce,onMobileSlideChange:$e}){const{t:J}=ft(),xe=a.useMemo(()=>Rg(r),[r]),fe=a.useMemo(()=>new Map(xe.map(te=>[te.key,te])),[xe]),[Fe,Oe]=a.useState(()=>Sg()),[G,Ne]=a.useState(()=>new Set),[Se,de]=a.useState({key:null,nonce:0}),qe=xe.find(te=>te.explained>0||te.stale>0)?.key??xe[0]?.key??null,$=n&&xe.some(te=>te.key===n)?n:qe,me=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:xe.map(Cg)}],[xe]),ge=a.useMemo(()=>Eg({groups:xe,onInsertDiffReference:N}),[xe,N]),Le=a.useRef(qe),ne=a.useRef(s);Le.current=qe,ne.current=s,a.useEffect(()=>{!n&&Le.current&&ne.current(Le.current)},[n]);const Ye=S?e.jsxs("button",{type:"button",onClick:S,"aria-pressed":x,title:T,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${x?"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:x?D:F})]}):null,Je=I?.map(te=>e.jsxs("label",{title:te.disabled?J("rightSidebar.includeUncommittedCurrentBranchOnly"):te.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:te.checked,disabled:O||R||te.disabled&&!te.checked,onChange:ye=>te.onChange(ye.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[te.label," · ",J("rightSidebar.includeUncommitted"),te.disabled&&e.jsx("span",{className:"block text-[10px]",children:J("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},te.key)),De=W?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:W}):null,Te=_?e.jsxs("button",{type:"button",onClick:_,disabled:O||R,title:ee??H,"aria-label":ee??H,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(qu,{size:12,className:O?"animate-spin":""}),H&&e.jsx("span",{children:H})]}):null,_e=te=>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:[m&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:m}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),f&&e.jsxs("button",{type:"button",onClick:f,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(ta,{size:14}),p]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[te,Je,Te,E,Ye,De]})]});if(r.length===0){const te=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!m&&!f?te:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[_e(null),te]})}const Be=S||_?({slideToList:te})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:te,children:[e.jsx(ta,{size:14}),c]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[Je,Te,E,S&&e.jsxs("button",{type:"button",onClick:S,"aria-pressed":x,title:T,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${x?"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:x?D:F})]})]}),De]}):void 0;return e.jsx(ul,{mobile:d,preserveScrollOnUpdate:!!I?.length,desktopLayout:M,backLabel:c,groups:me,selectedKey:$,mode:Fe,onModeChange:te=>{Oe(te),te!=="ai"&&Lt(df,te)},compact:d,collapsedDirectoryKeys:G,onToggleDirectory:te=>{Ne(ye=>{const nt=new Set(ye);return nt.has(te)?nt.delete(te):nt.add(te),nt})},onSelectFile:te=>{s(te.key),de(ye=>({key:te.key,nonce:ye.nonce+1}))},renderLeading:te=>{const ye=fe.get(te.key);return e.jsx(gl,{changeStatus:te.status,auditStatus:ye,renderChangeBadge:nt=>e.jsx(Qs,{status:nt})})},renderTrailing:te=>{const ye=fe.get(te.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[ye&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",ye.additions," -",ye.deletions]}),B?.(te.path,"file")]})},renderDirectoryTrailing:te=>B?.(te,"directory"),renderListHeader:_e,aiContent:({slideToDetail:te,fullscreen:ye,toggleFullscreen:nt})=>L.length>0&&U?e.jsx(tf,{walkthroughs:L,repoRoot:L[0]?.repoRoot,fullscreen:ye,onToggleFullscreen:nt,onNavigate:vt=>{d&&window.requestAnimationFrame(te),U(vt)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:J("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Be,externalSwiperRef:Ce,onMobileSlideChange:$e,detailContainerClassName:d?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:X,scrollToKey:he??Se.key,scrollToKeyNonce:he==null?Se.nonce:Re,onDetailScroll:te=>{Mg(te,$,s),ce?.(te.scrollTop)},files:ge,activePane:!0,wrap:x,diffViewType:h,inlineMode:b,renderStreamBadge:(te,ye)=>{const nt=fe.get(ye.key);return e.jsx(gl,{changeStatus:te,auditStatus:nt,renderChangeBadge:vt=>e.jsx(Qs,{status:vt})})},onInsertDiffReference:N,onReferenceCopied:P,insertedReferenceKey:q,copiedReferenceKey:j,onClearAuditRecord:o,onHunkGitAction:O?void 0:V,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function $g(r){return r.replace(/\/+$/,"")||"/"}function Lg(r){return[...new Set(Array.from(r,$g))].sort((n,s)=>n.localeCompare(s))}function Pg(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function Ag(r){let n=null;return{applicableEvents:r.filter(l=>{const d=l.type==="rescan-required"&&!Pg(l.reason);return d&&l.reason&&!n&&(n=l.reason),!d}),unavailableReason:n}}const Tg=1400,Ig=1200,uf=44,Dg=.7;function Gi(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function bl(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function Fg(r){try{const n=window.localStorage.getItem(bl(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=uf?s:null}catch{return null}}function cu(r,n){try{n===null?window.localStorage.removeItem(bl(r)):window.localStorage.setItem(bl(r),String(n))}catch{}}function so(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function _g({value:r,collapsed:n,labels:s,focusRequest:l,insertError:d,autoCollapseAfterSend:c,onChange:m,onCollapsedChange:g,onAutoCollapseAfterSendChange:f,onDisable:p,onClear:x,onInsert:h,onInsertAndSend:b}){const[E,S]=a.useState(null),[T,D]=a.useState(!1),F=a.useRef(!1),M=a.useRef(!0),[N,P]=a.useState(!1),[B,q]=a.useState(()=>Fg(Gi())),j=a.useRef(B),o=a.useRef(null),_=a.useRef(null),I=a.useRef(r),V=a.useRef(null),W=a.useRef(null),O=!!r.trim(),R=r.trim().split(`
7
- `)[0]??"",H=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>(M.current=!0,()=>{M.current=!1,o.current!==null&&window.clearTimeout(o.current),_.current!==null&&window.clearTimeout(_.current)}),[]),a.useEffect(()=>{let G=!1;const Ne=Gi();return zu().then(Se=>{if(G)return;const de=Se.contextDraftHeight?.[Ne]??null;cu(Ne,de),j.current=de,q(de)}).catch(()=>{}),()=>{G=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const G=V.current;if(!G)return;so()||G.focus(),G.setSelectionRange(G.value.length,G.value.length),G.scrollTop=G.scrollHeight}},[l]),a.useEffect(()=>{const G=I.current;I.current=r,!(!n||r.length<=G.length)&&(P(!0),_.current!==null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{_.current=null,P(!1)},Ig))},[r,n]),a.useEffect(()=>{if(n)return;const G=V.current;G&&(G.style.height=B!==null?`${B}px`:"")},[r,n,B]),a.useEffect(()=>{if(n)return;const G=V.current;!G||document.activeElement===G||(G.scrollTop=G.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||so())return;const G=V.current;!G||document.activeElement===G||(G.focus(),G.setSelectionRange(G.value.length,G.value.length))},[n]);const ee=a.useRef(null);a.useLayoutEffect(()=>{if(!so())return;const G=window.visualViewport;if(!G)return;const Ne=()=>{const Se=ee.current;if(!Se)return;if(G.height>=window.innerHeight*.75){Se.style.transform="";return}const de=Se.getBoundingClientRect(),qe=Math.round(G.height-de.bottom);Se.style.transform=qe!==0?`translateY(${qe}px)`:""};return Ne(),G.addEventListener("resize",Ne),G.addEventListener("scroll",Ne),()=>{G.removeEventListener("resize",Ne),G.removeEventListener("scroll",Ne),ee.current&&(ee.current.style.transform="")}},[n]);const L=G=>{S(G),o.current!==null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=null,S(null)},Tg)},U=G=>{g(!1),so()&&window.requestAnimationFrame(()=>{const Ne=V.current;if(!Ne)return;Ne.focus();const Se=Ne.value.length;Ne.setSelectionRange(Se,Se),window.requestAnimationFrame(()=>{Ne.setSelectionRange(Se,Se)})})},X=async G=>{if(!(!O||F.current)){F.current=!0,D(!0),S(null);try{await(G==="sent"?b():h())&&M.current&&L(G)}catch{}finally{F.current=!1,M.current&&D(!1)}}},ce=()=>{X("inserted")},he=()=>{X("sent")},Re=G=>{if(G.key==="Escape"){G.preventDefault(),g(!0);return}G.nativeEvent.isComposing||G.keyCode===229||G.key!=="Enter"||!G.metaKey&&!G.ctrlKey||(G.preventDefault(),he())},Ce=G=>{G.preventDefault()},$e=G=>{G.preventDefault();const Ne=V.current;Ne&&(W.current={startY:G.clientY,startHeight:Ne.getBoundingClientRect().height},G.currentTarget.setPointerCapture?.(G.pointerId))},J=G=>{const Ne=W.current;if(!Ne)return;const Se=window.visualViewport?.height??window.innerHeight,de=Math.round(Math.min(Math.max(Ne.startHeight+(Ne.startY-G.clientY),uf),Se*Dg));j.current=de,q(de)},xe=G=>{const Ne=Gi();cu(Ne,G),mo({contextDraftHeight:{[Ne]:G}}).catch(()=>{})},fe=()=>{W.current&&(W.current=null,j.current!==null&&xe(j.current))},Fe=()=>{j.current=null,q(null),xe(null)},Oe=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:ee,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:()=>U(),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(cp,{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] ${d?"text-destructive":N?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:d??(N?s.appended:O?R:s.title)})]}),Oe,e.jsx("button",{type:"button",onClick:he,disabled:!O||T,"aria-busy":T,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:T?e.jsx(ru,{size:12,className:"animate-spin"}):E==="sent"?e.jsx(ko,{size:12}):e.jsx(qd,{size:12})})]})}):e.jsxs("section",{ref:ee,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:$e,onPointerMove:J,onPointerUp:fe,onPointerCancel:fe,onDoubleClick:Fe,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:Ce,onClick:()=>g(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(ra,{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}),Oe]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:Ce,onClick:()=>f(!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:Ce,onClick:p,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Pt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:V,value:r,onChange:G=>m(G.target.value),onKeyDown:Re,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:Ce,onClick:x,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(po,{size:11})}),d?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:d}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:Ce,onClick:ce,disabled:!O||T,"aria-busy":T,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(dp,{size:11}),e.jsx("span",{children:T?s.pending??s.insert:E==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:Ce,onClick:he,disabled:!O||T,"aria-busy":T,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} · ${H}`,children:[T?e.jsx(ru,{size:11,className:"animate-spin"}):E==="sent"?e.jsx(ko,{size:11}):e.jsx(qd,{size:11}),e.jsx("span",{children:E==="sent"?s.sent:s.send})]})]})]})})]})}function Bg(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
6
+ `)}function Pg({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Lg(s.items.map(f=>f.hunk.diff||f.current?.diff||f.stale?.diff||""),s.items.map(f=>f.hunk.hunkHeader)),d=s.items.map(f=>f.current??f.stale).filter(f=>!!f).map(f=>({id:f.id,repoRoot:f.repoRoot,filePath:f.filePath,oldPath:f.oldPath,newPath:f.newPath,hunkHeader:f.hunkHeader,hunkIndex:f.hunkIndex,fingerprint:f.fingerprint,diff:f.diff,explanation:f.explanation,summary:f.summary,workspaceRoot:f.workspaceRoot,generatedBy:f.generatedBy,injectedAt:f.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,m=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"",g=s.items[0]?.repoRoot??d[0]?.repoRoot??null;return{key:s.key,path:s.filePath,oldPath:s.items[0]?.hunk.oldPath??void 0,absolutePath:g?`${g}/${s.items[0]?.repositoryPath??s.filePath}`:s.filePath,status:s.changeType,repoRoot:g,displayName:c,displayDir:m,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(f=>f.hunk.previewRevert?[[f.hunk.hunkHeader,f.hunk.previewRevert]]:[])),auditRecords:d,onInsertDiffReference:n}})}function Ag(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let m=null,g=Number.POSITIVE_INFINITY;for(const p of l){const x=p.getBoundingClientRect();if(x.bottom<c)continue;const h=Math.abs(x.top-c);h<g&&(m=p,g=h)}const f=m?.dataset.diffSelectionPath??m?.dataset.diffStreamItem??null;return!f||f===n||s(f),f}function hu({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:d=!1,backLabel:c="Back",headerTitle:m,headerMeta:g,onClose:f,closeLabel:p="Back",wrap:x=!0,diffViewType:h,inlineMode:b,viewControls:E,onToggleWrap:S,wrapTitle:T,wrapOnLabel:D="Wrap on",wrapOffLabel:F="Wrap off",desktopLayout:M="split",onInsertDiffReference:C,onReferenceCopied:P,renderPathReference:B,insertedReferenceKey:q,copiedReferenceKey:j,onClearAuditRecord:o,onRefresh:_,localOptions:I,onHunkGitAction:V,error:W,refreshing:O,actionsBusy:R,refreshLabel:H,refreshTitle:ee,walkthroughs:L=[],onWalkthroughNavigate:U,initialDetailScrollTop:X,onDetailScrollPositionChange:ce,scrollToKey:he,scrollToKeyNonce:Re,externalSwiperRef:Ne,onMobileSlideChange:$e}){const{t:Q}=ft(),xe=a.useMemo(()=>Mg(r),[r]),fe=a.useMemo(()=>new Map(xe.map(te=>[te.key,te])),[xe]),[Fe,Oe]=a.useState(()=>Cg()),[G,Ce]=a.useState(()=>new Set),[Se,de]=a.useState({key:null,nonce:0}),qe=xe.find(te=>te.explained>0||te.stale>0)?.key??xe[0]?.key??null,$=n&&xe.some(te=>te.key===n)?n:qe,me=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:xe.map($g)}],[xe]),ge=a.useMemo(()=>Pg({groups:xe,onInsertDiffReference:C}),[xe,C]),Le=a.useRef(qe),ne=a.useRef(s);Le.current=qe,ne.current=s,a.useEffect(()=>{!n&&Le.current&&ne.current(Le.current)},[n]);const Ye=S?e.jsxs("button",{type:"button",onClick:S,"aria-pressed":x,title:T,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${x?"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:x?D:F})]}):null,Je=I?.map(te=>e.jsxs("label",{title:te.disabled?Q("rightSidebar.includeUncommittedCurrentBranchOnly"):te.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:te.checked,disabled:O||R||te.disabled&&!te.checked,onChange:ye=>te.onChange(ye.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[te.label," · ",Q("rightSidebar.includeUncommitted"),te.disabled&&e.jsx("span",{className:"block text-[10px]",children:Q("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},te.key)),De=W?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:W}):null,Te=_?e.jsxs("button",{type:"button",onClick:_,disabled:O||R,title:ee??H,"aria-label":ee??H,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(Qu,{size:12,className:O?"animate-spin":""}),H&&e.jsx("span",{children:H})]}):null,_e=te=>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:[m&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:m}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),f&&e.jsxs("button",{type:"button",onClick:f,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(na,{size:14}),p]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[te,Je,Te,E,Ye,De]})]});if(r.length===0){const te=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!m&&!f?te:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[_e(null),te]})}const Be=S||_?({slideToList:te})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:te,children:[e.jsx(na,{size:14}),c]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[Je,Te,E,S&&e.jsxs("button",{type:"button",onClick:S,"aria-pressed":x,title:T,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${x?"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:x?D:F})]})]}),De]}):void 0;return e.jsx(hl,{mobile:d,preserveScrollOnUpdate:!!I?.length,desktopLayout:M,backLabel:c,groups:me,selectedKey:$,mode:Fe,onModeChange:te=>{Oe(te),te!=="ai"&&Lt(pf,te)},compact:d,collapsedDirectoryKeys:G,onToggleDirectory:te=>{Ce(ye=>{const nt=new Set(ye);return nt.has(te)?nt.delete(te):nt.add(te),nt})},onSelectFile:te=>{s(te.key),de(ye=>({key:te.key,nonce:ye.nonce+1}))},renderLeading:te=>{const ye=fe.get(te.key);return e.jsx(xl,{changeStatus:te.status,auditStatus:ye,renderChangeBadge:nt=>e.jsx(ea,{status:nt})})},renderTrailing:te=>{const ye=fe.get(te.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[ye&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",ye.additions," -",ye.deletions]}),B?.(te.path,"file")]})},renderDirectoryTrailing:te=>B?.(te,"directory"),renderListHeader:_e,aiContent:({slideToDetail:te,fullscreen:ye,toggleFullscreen:nt})=>L.length>0&&U?e.jsx(of,{walkthroughs:L,repoRoot:L[0]?.repoRoot,fullscreen:ye,onToggleFullscreen:nt,onNavigate:vt=>{d&&window.requestAnimationFrame(te),U(vt)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:Q("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Be,externalSwiperRef:Ne,onMobileSlideChange:$e,detailContainerClassName:d?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:X,scrollToKey:he??Se.key,scrollToKeyNonce:he==null?Se.nonce:Re,onDetailScroll:te=>{Ag(te,$,s),ce?.(te.scrollTop)},files:ge,activePane:!0,wrap:x,diffViewType:h,inlineMode:b,renderStreamBadge:(te,ye)=>{const nt=fe.get(ye.key);return e.jsx(xl,{changeStatus:te,auditStatus:nt,renderChangeBadge:vt=>e.jsx(ea,{status:vt})})},onInsertDiffReference:C,onReferenceCopied:P,insertedReferenceKey:q,copiedReferenceKey:j,onClearAuditRecord:o,onHunkGitAction:O?void 0:V,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function Tg(r){return r.replace(/\/+$/,"")||"/"}function Ig(r){return[...new Set(Array.from(r,Tg))].sort((n,s)=>n.localeCompare(s))}function Dg(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function Fg(r){let n=null;return{applicableEvents:r.filter(l=>{const d=l.type==="rescan-required"&&!Dg(l.reason);return d&&l.reason&&!n&&(n=l.reason),!d}),unavailableReason:n}}const _g=1400,Bg=1200,gf=44,Og=.7;function qi(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function vl(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function Ug(r){try{const n=window.localStorage.getItem(vl(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=gf?s:null}catch{return null}}function mu(r,n){try{n===null?window.localStorage.removeItem(vl(r)):window.localStorage.setItem(vl(r),String(n))}catch{}}function oo(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function Hg({value:r,collapsed:n,labels:s,focusRequest:l,insertError:d,autoCollapseAfterSend:c,onChange:m,onCollapsedChange:g,onAutoCollapseAfterSendChange:f,onDisable:p,onClear:x,onInsert:h,onInsertAndSend:b}){const[E,S]=a.useState(null),[T,D]=a.useState(!1),F=a.useRef(!1),M=a.useRef(!0),[C,P]=a.useState(!1),[B,q]=a.useState(()=>Ug(qi())),j=a.useRef(B),o=a.useRef(null),_=a.useRef(null),I=a.useRef(r),V=a.useRef(null),W=a.useRef(null),O=!!r.trim(),R=r.trim().split(`
7
+ `)[0]??"",H=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>(M.current=!0,()=>{M.current=!1,o.current!==null&&window.clearTimeout(o.current),_.current!==null&&window.clearTimeout(_.current)}),[]),a.useEffect(()=>{let G=!1;const Ce=qi();return Vu().then(Se=>{if(G)return;const de=Se.contextDraftHeight?.[Ce]??null;mu(Ce,de),j.current=de,q(de)}).catch(()=>{}),()=>{G=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const G=V.current;if(!G)return;oo()||G.focus(),G.setSelectionRange(G.value.length,G.value.length),G.scrollTop=G.scrollHeight}},[l]),a.useEffect(()=>{const G=I.current;I.current=r,!(!n||r.length<=G.length)&&(P(!0),_.current!==null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{_.current=null,P(!1)},Bg))},[r,n]),a.useEffect(()=>{if(n)return;const G=V.current;G&&(G.style.height=B!==null?`${B}px`:"")},[r,n,B]),a.useEffect(()=>{if(n)return;const G=V.current;!G||document.activeElement===G||(G.scrollTop=G.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||oo())return;const G=V.current;!G||document.activeElement===G||(G.focus(),G.setSelectionRange(G.value.length,G.value.length))},[n]);const ee=a.useRef(null);a.useLayoutEffect(()=>{if(!oo())return;const G=window.visualViewport;if(!G)return;const Ce=()=>{const Se=ee.current;if(!Se)return;if(G.height>=window.innerHeight*.75){Se.style.transform="";return}const de=Se.getBoundingClientRect(),qe=Math.round(G.height-de.bottom);Se.style.transform=qe!==0?`translateY(${qe}px)`:""};return Ce(),G.addEventListener("resize",Ce),G.addEventListener("scroll",Ce),()=>{G.removeEventListener("resize",Ce),G.removeEventListener("scroll",Ce),ee.current&&(ee.current.style.transform="")}},[n]);const L=G=>{S(G),o.current!==null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=null,S(null)},_g)},U=G=>{g(!1),oo()&&window.requestAnimationFrame(()=>{const Ce=V.current;if(!Ce)return;Ce.focus();const Se=Ce.value.length;Ce.setSelectionRange(Se,Se),window.requestAnimationFrame(()=>{Ce.setSelectionRange(Se,Se)})})},X=async G=>{if(!(!O||F.current)){F.current=!0,D(!0),S(null);try{await(G==="sent"?b():h())&&M.current&&L(G)}catch{}finally{F.current=!1,M.current&&D(!1)}}},ce=()=>{X("inserted")},he=()=>{X("sent")},Re=G=>{if(G.key==="Escape"){G.preventDefault(),g(!0);return}G.nativeEvent.isComposing||G.keyCode===229||G.key!=="Enter"||!G.metaKey&&!G.ctrlKey||(G.preventDefault(),he())},Ne=G=>{G.preventDefault()},$e=G=>{G.preventDefault();const Ce=V.current;Ce&&(W.current={startY:G.clientY,startHeight:Ce.getBoundingClientRect().height},G.currentTarget.setPointerCapture?.(G.pointerId))},Q=G=>{const Ce=W.current;if(!Ce)return;const Se=window.visualViewport?.height??window.innerHeight,de=Math.round(Math.min(Math.max(Ce.startHeight+(Ce.startY-G.clientY),gf),Se*Og));j.current=de,q(de)},xe=G=>{const Ce=qi();mu(Ce,G),Xs({contextDraftHeight:{[Ce]:G}}).catch(()=>{})},fe=()=>{W.current&&(W.current=null,j.current!==null&&xe(j.current))},Fe=()=>{j.current=null,q(null),xe(null)},Oe=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:ee,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:()=>U(),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(mp,{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] ${d?"text-destructive":C?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:d??(C?s.appended:O?R:s.title)})]}),Oe,e.jsx("button",{type:"button",onClick:he,disabled:!O||T,"aria-busy":T,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:T?e.jsx(iu,{size:12,className:"animate-spin"}):E==="sent"?e.jsx(So,{size:12}):e.jsx(Jd,{size:12})})]})}):e.jsxs("section",{ref:ee,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:$e,onPointerMove:Q,onPointerUp:fe,onPointerCancel:fe,onDoubleClick:Fe,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:Ne,onClick:()=>g(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(sa,{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}),Oe]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:Ne,onClick:()=>f(!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:Ne,onClick:p,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Pt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:V,value:r,onChange:G=>m(G.target.value),onKeyDown:Re,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:Ne,onClick:x,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(go,{size:11})}),d?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:d}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:Ne,onClick:ce,disabled:!O||T,"aria-busy":T,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(pp,{size:11}),e.jsx("span",{children:T?s.pending??s.insert:E==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:Ne,onClick:he,disabled:!O||T,"aria-busy":T,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} · ${H}`,children:[T?e.jsx(iu,{size:11,className:"animate-spin"}):E==="sent"?e.jsx(So,{size:11}):e.jsx(Jd,{size:11}),e.jsx("span",{children:E==="sent"?s.sent:s.send})]})]})]})})]})}function zg(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
8
8
 
9
9
  `)?"":r.endsWith(`
10
10
  `)?`
11
11
  `:`
12
12
 
13
- `;return`${r}${l}${s}`}function Og(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}function Ug(r,n){return{text:Og(r,n),options:{paste:/[\r\n]/.test(r),submitAfterPaste:n}}}function Hg(r){const[n,s]=a.useState(null),l=a.useRef(null),d=a.useRef(null),c=a.useRef(!0),m=a.useRef(r);m.current=r,a.useEffect(()=>(c.current=!0,()=>{c.current=!1,l.current?.controller.abort()}),[]);const g=a.useCallback(async b=>{if(l.current)return!1;l.current=b,d.current=b;const E=S=>{b.task={...b.task,...S},c.current&&l.current===b&&s(b.task)};E({status:b.task.retryFiles.length?"uploading":"inserting",error:void 0});try{if(b.task.retryFiles.length){const S=await ll(b.task.directory,b.task.retryFiles,b.controller.signal);if(E({uploaded:[...b.task.uploaded,...S.files]}),m.current(b.task.directory),S.files.length!==b.task.retryFiles.length){const T=new Set(S.results?.filter(D=>D.status==="uploaded").map(D=>D.index)??[]);throw E({retryFiles:S.results?b.task.retryFiles.filter((D,F)=>!T.has(F)):[]}),new Error("Incomplete upload result. Check the saved paths before retrying.")}E({retryFiles:[]})}if(b.controller.signal.aborted)throw new DOMException("Upload canceled","AbortError");if(b.insert){E({status:"inserting"});const S=b.task.uploaded[0]?.path;if(!S||!b.isCurrent?.()||!await b.insert(S)||!b.isCurrent?.()||b.controller.signal.aborted)return E({status:"error",error:"reference"}),!1}return E({status:"done"}),!0}catch(S){if(S instanceof Dd&&S.result?.files.length){const T=new Set(S.result.results?.filter(D=>D.status==="uploaded").map(D=>D.index)??[]);E({uploaded:[...b.task.uploaded,...S.result.files],retryFiles:S.result.results?b.task.retryFiles.filter((D,F)=>!T.has(F)):[]}),m.current(b.task.directory)}return E({status:b.controller.signal.aborted?"canceled":"error",error:S instanceof Dd&&S.code==="UPLOAD_LIMIT"?"UPLOAD_LIMIT":S instanceof Error?S.message:String(S)}),!1}finally{l.current===b&&(l.current=null)}},[]),f=a.useCallback((b,E,S,T)=>E.length?g({task:{kind:S?"image":"files",directory:b,files:E,retryFiles:E,uploaded:[],status:"uploading"},controller:new AbortController,insert:S,isCurrent:T}):Promise.resolve(!1),[g]),p=a.useCallback(()=>{const b=d.current;if(!b||l.current||!b.insert&&!b.task.retryFiles.length)return Promise.resolve(!1);const E={...b,controller:new AbortController,task:{...b.task}};return g(E)},[g]),x=a.useCallback(()=>{const b=l.current;!b||b.task.status!=="uploading"||b.controller.abort()},[]),h=a.useCallback(()=>{l.current||(d.current=null,s(null))},[]);return{task:n,start:f,retry:p,cancel:x,dismiss:h,busy:n?.status==="uploading"||n?.status==="inserting"}}function zg({task:r,labels:n,onCancel:s,onRetry:l,onDismiss:d}){const c=r.status==="uploading"||r.status==="inserting",m=r.error==="reference"?n.referenceRejected:r.error==="UPLOAD_LIMIT"?n.limit:r.status==="error"?`${n.failed}: ${r.error??""}`:n[r.status],g=r.status==="error"&&(r.kind==="image"&&r.uploaded.length>0||r.retryFiles.length>0&&r.retryFiles.length<=50);return e.jsxs("section",{className:"shrink-0 border-t border-border/20 bg-surface/80 px-3 py-2 text-xs","data-sidebar-upload-status":!0,"aria-busy":c,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`min-w-0 flex-1 break-words ${r.status==="error"?"text-destructive":"text-foreground"}`,role:r.status==="error"?"alert":"status",children:m}),r.status==="uploading"&&e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-2 py-1 hover:bg-surface-elevated",onClick:s,children:n.cancel}),g&&e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-2 py-1 hover:bg-surface-elevated",onClick:l,children:n.retry}),!c&&e.jsx("button",{type:"button",className:"shrink-0 rounded px-2 py-1 text-muted-foreground hover:bg-surface-2",onClick:d,"aria-label":n.dismiss,children:"×"})]}),e.jsx("div",{className:"mt-1 truncate text-muted-foreground",title:r.directory,children:r.directory}),e.jsxs("details",{className:"mt-1 min-w-0 text-muted-foreground",children:[e.jsxs("summary",{className:"cursor-pointer truncate",children:[n.files," · ",r.files[0]?.name]}),e.jsxs("ul",{className:"mt-1 max-h-24 overflow-y-auto font-mono text-[10px]",children:[r.files.map((f,p)=>e.jsx("li",{className:"break-all",children:f.name},`${p}:${f.name}`)),r.uploaded.map(f=>e.jsx("li",{className:"break-all text-foreground",children:f.path},f.path))]})]})]})}function Wg(r){const n=a.useRef(r),s=a.useRef(0);(n.current.text!==r.text||n.current.sessionId!==r.sessionId||n.current.active!==r.active)&&(s.current+=1),n.current=r;const l=a.useRef(!0),d=a.useRef(!1);return a.useEffect(()=>(l.current=!0,()=>{l.current=!1,s.current+=1}),[]),a.useCallback(async c=>{if(d.current||!n.current.active)return!1;const m=n.current,g=s.current,{text:f,options:p}=Ug(m.text,c);if(!f)return!1;d.current=!0;try{const x=await Vu(f,m.sessionId,()=>l.current&&n.current.active&&n.current.sessionId===m.sessionId,void 0,p),h=l.current&&g===s.current;return h&&(x?n.current.onAccepted():n.current.onRejected()),x&&h}finally{d.current=!1}},[])}const du={status:"idle",error:null,result:null};function Gg(r,n=!0){const[s,l]=a.useState(du),d=a.useRef(null);a.useLayoutEffect(()=>(l(du),()=>{const g=d.current;d.current=null,g?.abort()}),[r,n]);const c=a.useCallback(()=>{const g=d.current;g&&(d.current=null,g.abort(),l({status:"canceled",error:null,result:"canceled"}))},[]),m=a.useCallback(async()=>{if(!n||!r||d.current)return;const g=new AbortController;d.current=g,l({status:"pending",error:null,result:null});try{const f=await Uu(r,g.signal);if(d.current!==g)return;d.current=null;const p=g.signal.aborted?"canceled":f;l({status:p,error:null,result:p})}catch(f){if(d.current!==g)return;d.current=null,g.signal.aborted?l({status:"canceled",error:null,result:"canceled"}):l({status:"error",error:f instanceof Error?f.message:String(f),result:null})}},[r,n]);return{...s,start:m,cancel:c}}const xl="termdock:right-sidebar:html-view-mode-by-file:v1";function Kg(r){return r==="preview"||r==="source"}function ff(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(Kg)}function hf(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function uu(r,n){const s=hf(r,n);return s?pt(xl,ff)?.[s]??"source":"source"}function qg(r,n,s){const l=hf(r,n);if(!l)return;const d=pt(xl,ff)??{};Lt(xl,{...d,[l]:s})}function mf(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Vg=1500,fu=256*1024*1024;async function Yg(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",d=s.body?.getReader();if(!d){const g=await s.blob();if(g.size>fu)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const c=[];let m=0;try{for(;;){const{done:g,value:f}=await d.read();if(g)break;if(m+=f.byteLength,m>fu)throw new Error("Media too large for encrypted fallback");c.push(f)}}catch(g){throw await d.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(c,{type:l}))}function Ao(r,n){const s=mf(r),[l,d]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,m]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const f=navigator.serviceWorker,p=()=>d(!!f?.controller);return f?.addEventListener("controllerchange",p),p(),()=>f?.removeEventListener("controllerchange",p)},[s,l]),a.useEffect(()=>{if(!s||l){m(void 0);return}let f=!1,p;const x=new AbortController,h=window.setTimeout(()=>{Yg(r,x.signal).then(b=>{if(f){URL.revokeObjectURL(b);return}p=b,m(b)}).catch(()=>{f||x.signal.aborted||g.current?.()})},Vg);return()=>{f=!0,window.clearTimeout(h),x.abort(),p&&URL.revokeObjectURL(p)}},[s,l,r]),!s||l?r:c}function Ki(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),d=n%60,c=String(l).padStart(2,"0"),m=String(d).padStart(2,"0");return s>0?`${s}:${c}:${m}`:`${c}:${m}`}function Xg(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const Xr=2,Jg=8,Qg=60,ao=5,hu=.05,Zg=900;function eb(r){return!Number.isFinite(r)||r<=0?Xr:Math.min(Jg,Xr+Math.floor(r/Qg))}const tb=350,rb=6,nb=90;function sb({url:r,onLoadError:n}){const s=Ao(r,n),{t:l}=ft(),d=a.useRef(null),c=a.useRef(null),m=a.useRef(null),g=a.useRef(null),f=a.useRef(!1),p=a.useRef(null),x=a.useRef(null),h=a.useRef(0),b=a.useRef(!1),E=a.useRef(!1),S=a.useRef(!1),T=a.useRef(null),D=a.useRef(null),F=a.useRef(!1),M=a.useRef(1),N=a.useRef(!1),[P,B]=a.useState(0),[q,j]=a.useState(0),[o,_]=a.useState(!1),[I,V]=a.useState(!1),[W,O]=a.useState(null),[R,H]=a.useState(!1),[ee,L]=a.useState(0),[U,X]=a.useState(!1),[ce,he]=a.useState({width:0,height:0}),[Re,Ce]=a.useState(Xr),[$e,J]=a.useState(1),[xe,fe]=a.useState(null),Fe=a.useRef(Xr),Oe=a.useRef(null),G=a.useCallback(()=>{T.current!==null&&(clearTimeout(T.current),T.current=null)},[]),Ne=a.useCallback(()=>{G();const z=D.current;if(D.current=null,!F.current)return!1;const oe=m.current;if(oe&&(oe.playbackRate=M.current,z))try{oe.releasePointerCapture?.(z.id)}catch{}return F.current=!1,Fe.current=Xr,H(!1),!0},[G]);a.useEffect(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current),x.current!==null&&clearTimeout(x.current),Oe.current!==null&&clearTimeout(Oe.current),G();const z=m.current;z&&F.current&&(z.playbackRate=M.current)},[G]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const oe=new ResizeObserver(([je])=>{je&&he({width:je.contentRect.width,height:je.contentRect.height})});return oe.observe(z),()=>oe.disconnect()},[]),a.useEffect(()=>{const z=()=>X(document.fullscreenElement===d.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const Se=a.useCallback((z,oe=!1)=>{const je=m.current;if(!je)return!1;const Qe=Number.isFinite(je.duration)?je.duration:z,At=Math.min(Math.max(z,0),Qe);if(j(At),Math.abs(je.currentTime-At)<1/120)return!1;const Rr=je.fastSeek;return oe&&typeof Rr=="function"?Rr.call(je,At):je.currentTime=At,!0},[]),de=a.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null;const z=m.current;if(!z||!b.current||E.current||z.seeking)return;const oe=S.current;S.current=!1,E.current=Se(h.current,!oe)}))},[Se]),qe=a.useCallback(z=>{const oe=g.current,je=m.current;if(!oe||!je)return;const Qe=oe.getBoundingClientRect(),At=Xg(z,Qe,je.duration);h.current=At,O(At),S.current=!1,de(),x.current!==null&&clearTimeout(x.current),x.current=setTimeout(()=>{x.current=null,S.current=!0,de()},nb)},[de]),$=a.useCallback(()=>{p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),x.current!==null&&(clearTimeout(x.current),x.current=null),S.current=!1,E.current=!1,Se(h.current)},[Se]),me=a.useCallback(z=>{const oe=m.current;if(!(!oe||!Number.isFinite(oe.duration)||oe.duration<=0)){f.current=!oe.paused,oe.pause(),b.current=!0,V(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}qe(z.clientX)}},[qe]),ge=a.useCallback(()=>{b.current=!1,$(),V(!1),O(null);const z=m.current;z&&f.current&&!z.ended&&z.play().catch(()=>{}),f.current=!1},[$]),Le=a.useCallback(()=>{const z=m.current;if(z){if(N.current){N.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),ne=a.useCallback(z=>{const oe=m.current;if(!oe)return;const je=Math.min(1,Math.max(0,Math.round((oe.volume+z)*100)/100));oe.volume=je,je>0&&(oe.muted=!1),J(je),fe(je),Oe.current!==null&&clearTimeout(Oe.current),Oe.current=setTimeout(()=>{Oe.current=null,fe(null)},Zg)},[]),Ye=a.useCallback(z=>{const oe=m.current;if(oe){if(z.key==="ArrowLeft"){z.preventDefault(),Se(oe.currentTime-(z.shiftKey?ao*2:ao));return}if(z.key==="ArrowRight"){z.preventDefault(),Se(oe.currentTime+(z.shiftKey?ao*2:ao));return}if(z.key==="ArrowUp"){z.preventDefault(),ne(hu);return}if(z.key==="ArrowDown"){z.preventDefault(),ne(-hu);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),oe.paused?oe.play().catch(()=>{}):oe.pause())}},[Se,ne]),Je=a.useCallback(z=>{const oe=m.current;!oe||oe.paused||z.button!==0||(G(),D.current={id:z.pointerId,x:z.clientX,y:z.clientY},T.current=setTimeout(()=>{T.current=null;const je=D.current;if(M.current=oe.playbackRate,oe.playbackRate=Xr,Fe.current=Xr,Ce(Xr),F.current=!0,H(!0),je)try{oe.setPointerCapture?.(je.id)}catch{}},tb))},[G]),De=a.useCallback(z=>{const oe=D.current;if(!oe||oe.id!==z.pointerId)return;if(!F.current){Math.hypot(z.clientX-oe.x,z.clientY-oe.y)>rb&&(G(),D.current=null);return}const je=eb(z.clientX-oe.x);if(je===Fe.current)return;Fe.current=je,Ce(je);const Qe=m.current;Qe&&(Qe.playbackRate=je)},[G]),Te=a.useCallback(()=>{Ne()&&(N.current=!0)},[Ne]);a.useEffect(()=>(window.addEventListener("pointerup",Te),window.addEventListener("pointercancel",Te),window.addEventListener("blur",Te),()=>{window.removeEventListener("pointerup",Te),window.removeEventListener("pointercancel",Te),window.removeEventListener("blur",Te)}),[Te]);const _e=a.useCallback(async()=>{const z=d.current,oe=m.current;if(!(!z||!oe))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():oe.webkitEnterFullscreen?.()}catch{oe.webkitEnterFullscreen?.()}},[]),Be=a.useCallback(()=>L(z=>(z+90)%360),[]),te=a.useCallback(z=>{const oe=m.current;if(!oe||!Number.isFinite(oe.duration))return;const je=z.shiftKey?10:5;let Qe=null;z.key==="ArrowLeft"?Qe=oe.currentTime-je:z.key==="ArrowRight"?Qe=oe.currentTime+je:z.key==="Home"?Qe=0:z.key==="End"&&(Qe=oe.duration),Qe!==null&&(z.preventDefault(),Se(Qe))},[Se]),ye=I&&W!==null?W:q,nt=P>0?Math.min(1,Math.max(0,ye/P)):0,Zt=(ee===90||ee===270)&&ce.width>0&&ce.height>0?{width:`${ce.height}px`,height:`${ce.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:d,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":ee,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:m,"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${R?` ${Zd}`:""}`,style:{...Zt,transform:`translate(-50%, -50%) rotate(${ee}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...R?{[eu]:""}:{},onClick:Le,onKeyDown:Ye,onVolumeChange:z=>J(z.currentTarget.volume),onPointerDown:Je,onPointerMove:De,onPointerUp:Te,onPointerCancel:Te,onContextMenu:z=>{F.current&&z.preventDefault()},onPlay:()=>_(!0),onPause:()=>_(!1),onTimeUpdate:z=>j(z.currentTarget.currentTime),onSeeked:z=>{const oe=z.currentTarget;if(j(oe.currentTime),E.current=!1,!b.current)return;const je=oe.requestVideoFrameCallback;typeof je=="function"?je.call(oe,()=>{b.current&&de()}):requestAnimationFrame(()=>{b.current&&de()})},onLoadedMetadata:z=>B(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onDurationChange:z=>B(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),R&&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(Re)})}),xe!==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(up,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round($e*100)})]}),I&&W!==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:`${nt*100}%`},"data-testid":"file-preview-video-scrub-time",children:Ki(W)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Zd}`,[eu]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Le,"aria-label":l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:o?e.jsx(fp,{size:14}):e.jsx(hp,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(P),"aria-valuenow":Math.floor(ye),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:me,onPointerMove:z=>{I&&qe(z.clientX)},onPointerUp:ge,onPointerCancel:ge,onKeyDown:te,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:`${nt*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:`${nt*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Ki(ye)," / ",Ki(P)]}),e.jsx("button",{type:"button",onClick:Be,"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(qu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{_e()},"aria-label":l(U?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(U?"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:U?e.jsx(mp,{size:14}):e.jsx(pp,{size:14})})]})})]})}function ab(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function To({anchor:r,children:n,disabled:s=!1,onClick:l,title:d}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:d,style:ab(r),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(So,{size:11}),n]})}function ob(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const d=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(d)||d<=0)return null;const c=l.width*d,m=l.height*d,g=s.left+(s.width-c)/2,f=s.top+(s.height-m)/2,p=r-g,x=n-f;if(p<0||x<0||p>c||x>m)return null;const h=p/c*100,b=x/m*100;return{x:l.x+l.width*h/100,y:l.y+l.height*b/100,xPercent:h,yPercent:b}}function ib(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function lb(r){const n=new DOMParser().parseFromString(r,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const d of Array.from(l.attributes)){const c=d.name.toLowerCase(),m=d.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&m&&!m.startsWith("#"))&&l.removeAttribute(d.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function cb(r,n,s){let l=null;for(const d of Array.from(r.querySelectorAll("text"))){const c=(d.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const m=Number(d.getAttribute("x")),g=Number(d.getAttribute("y"));if(!Number.isFinite(m)||!Number.isFinite(g))continue;const f=Math.hypot(m-n,g-s);(!l||f<l.distance)&&(l={text:c,distance:f})}return l?.text.slice(0,120)}function pf({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const d=a.useRef(null),c=a.useRef(null),[m,g]=a.useState(null),[f,p]=a.useState(null),[x,h]=a.useState(1),[b,E]=a.useState(!1),[S,T]=a.useState(null),D=a.useRef(new Map),F=a.useRef(null),M=a.useRef(!1),N=a.useRef(null),P=a.useRef(x);P.current=x,a.useEffect(()=>{const L=new AbortController;return g(null),p(null),T(null),h(1),fetch(r,{signal:L.signal}).then(U=>U.text()).then(U=>g(lb(U))).catch(U=>{L.signal.aborted||p(U instanceof Error?U.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!b)return;const L=U=>{U.key==="Escape"&&E(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b]),a.useLayoutEffect(()=>{const L=c.current,U=L?.querySelector("[data-svg-document] > svg");if(!L||!U)return;let X;try{X=U.getBBox()}catch{return}if(!X.width||!X.height)return;const ce=Math.max(2,Math.min(X.width,X.height)*.025);U.setAttribute("viewBox",`${X.x-ce} ${X.y-ce} ${X.width+2*ce} ${X.height+2*ce}`),U.style.width=`${x*100}%`,U.style.height=`${x*100}%`,U.style.minWidth=`${x*100}%`,U.style.minHeight=`${x*100}%`,U.style.display="block"},[m,x]);const B=a.useMemo(()=>S?ib(n,s,S):null,[n,S,s]),q=L=>{if(M.current){M.current=!1;return}const U=c.current,X=U?.querySelector("[data-svg-document] > svg"),ce=d.current;if(!U||!X||!ce)return;const he=X.viewBox.baseVal,Re=ob(L.clientX,L.clientY,X.getBoundingClientRect(),he);if(!Re)return;const Ce=ce.getBoundingClientRect();T({...Re,nearestText:cb(X,Re.x,Re.y),stageX:L.clientX-Ce.left,stageY:L.clientY-Ce.top,stageXPercent:(L.clientX-Ce.left)/Ce.width*100,stageYPercent:(L.clientY-Ce.top)/Ce.height*100})},j=L=>Math.max(1,Math.min(12,L)),o=(L,U)=>{const X=j(U),ce=L.querySelector("[data-svg-document] > svg");if(!ce)return X;const he=`${X*100}%`;return ce.style.width=he,ce.style.height=he,ce.style.minWidth=he,ce.style.minHeight=he,P.current=X,X},_=(L,U,X,ce)=>{const he=P.current,Re=L.getBoundingClientRect(),Ce=X-Re.left,$e=ce-Re.top,J=(L.scrollLeft+Ce)/he,xe=(L.scrollTop+$e)/he,fe=o(L,U);return L.scrollLeft=J*fe-Ce,L.scrollTop=xe*fe-$e,fe},I=()=>{const L=Array.from(D.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},V=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const U=c.current;U&&(D.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),U.setPointerCapture?.(L.pointerId),D.current.size>=2?(F.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startDistance:I(),startZoom:P.current,moved:!1},M.current=!0):P.current>1&&(F.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startZoom:P.current,moved:!1}))},W=L=>{if(!D.current.has(L.pointerId))return;D.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const U=c.current,X=F.current;if(!(!U||!X)){if(D.current.size>=2&&X.kind==="pinch"){const ce=I();if(!X.startDistance||!ce)return;const he=j(X.startZoom*ce/X.startDistance);if(Math.abs(he-P.current)<.01)return;const Re=Array.from(D.current.values()),Ce=(Re[0].x+Re[1].x)/2,$e=(Re[0].y+Re[1].y)/2;X.moved=!0,M.current=!0,_(U,he,Ce,$e),L.preventDefault();return}if(X.kind==="pan"&&D.current.size===1){const ce=L.clientX-X.startX,he=L.clientY-X.startY;if(!X.moved&&Math.hypot(ce,he)<6)return;X.moved=!0,M.current=!0,U.scrollLeft=X.startScrollLeft-ce,U.scrollTop=X.startScrollTop-he,L.preventDefault()}}},O=L=>{const U=c.current,X=F.current,ce=D.current.size===1&&!X?.moved;D.current.delete(L.pointerId);try{U?.releasePointerCapture?.(L.pointerId)}catch{}if(D.current.size===1&&X?.kind==="pinch"){const Ce=Array.from(D.current.values())[0];F.current=U?{kind:"pan",startX:Ce.x,startY:Ce.y,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startZoom:P.current,moved:!1}:null;return}if(D.current.size>0||(F.current=null,X?.kind==="pinch"&&h(P.current),!ce||M.current))return;const he=Date.now(),Re=N.current;Re&&he-Re.time<350&&Math.hypot(L.clientX-Re.x,L.clientY-Re.y)<24?(N.current=null,M.current=!0,h(Ce=>Ce>1?1:2.5)):N.current={time:he,x:L.clientX,y:L.clientY}},R=L=>{if(!L.ctrlKey&&!L.metaKey)return;const U=c.current;if(!U)return;L.preventDefault();const X=_(U,P.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);h(X)},H=()=>{h(1),P.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},ee=e.jsxs("div",{className:b?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:q,onDoubleClick:L=>{L.preventDefault(),h(U=>U>1?1:2.5)},onPointerDown:V,onPointerMove:W,onPointerUp:O,onPointerCancel:O,onWheel:R,onScroll:()=>T(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:f?e.jsx("div",{className:"p-4 text-sm text-destructive",children:f}):m?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:m}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),S&&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:S.stageX,top:S.stageY}}),S&&B&&e.jsx(To,{anchor:{xPercent:S.stageXPercent,yPercent:S.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(B,`svg:${S.x.toFixed(2)}:${S.y.toFixed(2)}`),T(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[x>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),H()},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(Xp,{size:14})}),e.jsx("button",{type:"button","aria-label":b?"退出全屏 SVG":"全屏 SVG",title:b?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),E(U=>!U)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:b?e.jsx(rf,{size:14}):e.jsx(ef,{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:S?`SVG (${S.x.toFixed(2)}, ${S.y.toFixed(2)}) · ${S.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return b?jr.createPortal(ee,document.body):ee}function bo(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function db(r,n,s,l){const d=[`电子标注: ${r}`,`视图: ${bo(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(d.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&d.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(",");d.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${d.join(" / ")}"`}function ub({blobUrl:r,filePath:n,view:s,board:l,onViewChange:d,onInsertAnnotation:c,onRefresh:m,interactive3d:g}){const{t:f}=ft(),p=a.useRef(null),x=a.useRef(null),h=a.useRef(null),[b,E]=a.useState(null),[S,T]=a.useState(!1);a.useEffect(()=>(h.current?.abort(),E(null),T(!1),()=>h.current?.abort()),[r,s]);const D=a.useMemo(()=>b?db(n,s,b,b.inspection):null,[n,b,s]),F=N=>{const P=p.current,B=x.current;if(!P||!B||!B.naturalWidth||!B.naturalHeight)return;const q=P.getBoundingClientRect(),j=B.getBoundingClientRect(),o=Math.min(j.width/B.naturalWidth,j.height/B.naturalHeight),_=B.naturalWidth*o,I=B.naturalHeight*o,V=j.left+(j.width-_)/2,W=j.top+(j.height-I)/2,O=N.clientX-V,R=N.clientY-W;if(O<0||R<0||O>_||R>I)return;const H={xPercent:Math.max(0,Math.min(100,O/_*100)),yPercent:Math.max(0,Math.min(100,R/I*100)),stageXPercent:(N.clientX-q.left)/q.width*100,stageYPercent:(N.clientY-q.top)/q.height*100,inspecting:l&&s!=="pcb-3d"};if(E(H),h.current?.abort(),!H.inspecting)return;const ee=new AbortController;h.current=ee,Am(n,s,H.xPercent,H.yPercent,ee.signal).then(L=>E(U=>U===H?{...U,inspection:L,inspecting:!1}:U)).catch(()=>{ee.signal.aborted||E(L=>L===H?{...L,inspection:{available:!1},inspecting:!1}:L)})},M=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:M.map(N=>e.jsx("button",{type:"button",onClick:()=>d(N),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${N===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:bo(N)},N))}),e.jsx("button",{type:"button",onClick:m,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:f("rightSidebar.edaRefresh"),"aria-label":f("rightSidebar.edaRefresh"),children:e.jsx(go,{size:13})})]}),l&&g?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:g}):null,l?s==="pcb-3d"?g?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:p,role:"button",tabIndex:0,onClick:F,onKeyDown:N=>{N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),E({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:f("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:x,src:r,alt:`${n} ${bo(s)}`,onLoad:()=>T(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${S?"opacity-100":"opacity-0"}`}),b&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${b.stageXPercent}%`,top:`${b.stageYPercent}%`}}),b&&D&&e.jsx(To,{anchor:{xPercent:b.stageXPercent,yPercent:b.stageYPercent},disabled:b.inspecting,title:f("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(D,`eda:${s}:${b.xPercent.toFixed(1)}:${b.yPercent.toFixed(1)}`,{snapshot:x.current?gg(x.current,b):Promise.resolve(null)}),E(null)},children:f("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?b.inspecting?f("rightSidebar.edaInspecting"):b.inspection?.available?f("rightSidebar.edaPickedBoardPosition",{x:b.inspection.xMm?.toFixed(2)??"—",y:b.inspection.yMm?.toFixed(2)??"—",object:b.inspection.nearest?.label??f("rightSidebar.edaNoNearbyObject")}):f("rightSidebar.edaPickedPosition",{x:b.xPercent.toFixed(1),y:b.yPercent.toFixed(1)}):f("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(pf,{blobUrl:r,filePath:n,viewLabel:bo(s),onInsertAnnotation:c})})]})}function fb(r){const n=[];let s=[],l="",d=!1;for(let c=0;c<r.length;c+=1){const m=r[c];d?m==='"'&&r[c+1]==='"'?(l+='"',c+=1):m==='"'?d=!1:l+=m:m==='"'?d=!0:m===","?(s.push(l),l=""):m===`
14
- `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=m}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function hb(r,n,s,l,d){const c=n[d]||`第${d+1}列`,m=s[d]??"",g=n.map((f,p)=>`${f||`第${p+1}列`}=${s[p]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${c} / 值: ${m} / 记录: ${g}"`}function mb({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=ft(),d=a.useMemo(()=>fb(r),[r]),c=d[0]??[],m=d.slice(1),g=a.useRef(null),[f,p]=a.useState(null),x=f?m[f.row]:null,h=f&&x?hb(n,c,x,f.row+1,f.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:g,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((b,E)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:b||l("rightSidebar.csvUnnamedColumn",{index:E+1})},`${b}:${E}`))]})}),e.jsx("tbody",{children:m.map((b,E)=>e.jsxs("tr",{className:"hover:bg-surface-2",children:[e.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:E+1}),c.map((S,T)=>{const D=f?.row===E&&f.column===T;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${D?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:F=>{const M=g.current?.getBoundingClientRect(),N=F.currentTarget.getBoundingClientRect();if(!M?.width||!M.height)return;const P=F.clientX||N.left+N.width/2,B=F.clientY||N.top+N.height/2;p({row:E,column:T,xPercent:(P-M.left)/M.width*100,yPercent:(B-M.top)/M.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:b[T]||" "})},`cell:${E}:${T}`)})]},`row:${E}`))})]})}),f&&h&&e.jsx(To,{anchor:{xPercent:f.xPercent,yPercent:f.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(h,`csv:${n}:${f.row+1}:${f.column+1}`),p(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:f&&x?l("rightSidebar.csvSelectedCell",{row:f.row+1,column:c[f.column]||f.column+1}):l("rightSidebar.csvPickHint",{rows:m.length,columns:c.length})})})]})}function ds(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function pb(r,n){const s=JSON.parse(r),l=ds(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(ds(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(ds(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:ds(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const d=ds(s,["net_settings","classes"]),c=Array.isArray(d)?d.find(g=>g&&typeof g=="object"&&g.name==="Default"):void 0,m=ds(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(d)?d.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(m)?m.length:0)}]}function gb(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function bb({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:d}=ft(),c=a.useRef(null),[m,g]=a.useState(null),f=a.useMemo(()=>{try{return{items:pb(r,s),error:null}}catch(x){return{items:[],error:x instanceof Error?x.message:String(x)}}},[r,s]),p=m===null?null:f.items[m.index];return f.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:r}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:d("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:f.items.map((x,h)=>e.jsxs("button",{type:"button",onClick:b=>{const E=c.current?.getBoundingClientRect(),S=b.currentTarget.getBoundingClientRect();if(!E?.width||!E.height)return;const T=b.clientX||S.left+S.width/2,D=b.clientY||S.top+S.height/2;g({index:h,xPercent:(T-E.left)/E.width*100,yPercent:(D-E.top)/E.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${m?.index===h?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:x.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:x.value})]},x.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:d("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),p&&m&&e.jsx(To,{anchor:{xPercent:m.xPercent,yPercent:m.yPercent},title:d("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(gb(n,p),`kicad-project:${n}:${p.label}`),g(null)},children:d("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:p?`${p.label}: ${p.value}`:d("rightSidebar.kicadProjectPickHint")})})]})}const xb=`/** ES Module Shims Wasm @version 2.8.4 */
13
+ `;return`${r}${l}${s}`}function Wg(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}function Gg(r,n){return{text:Wg(r,n),options:{paste:/[\r\n]/.test(r),submitAfterPaste:n}}}function Kg(r){const[n,s]=a.useState(null),l=a.useRef(null),d=a.useRef(null),c=a.useRef(!0),m=a.useRef(r);m.current=r,a.useEffect(()=>(c.current=!0,()=>{c.current=!1,l.current?.controller.abort()}),[]);const g=a.useCallback(async b=>{if(l.current)return!1;l.current=b,d.current=b;const E=S=>{b.task={...b.task,...S},c.current&&l.current===b&&s(b.task)};E({status:b.task.retryFiles.length?"uploading":"inserting",error:void 0});try{if(b.task.retryFiles.length){const S=await dl(b.task.directory,b.task.retryFiles,b.controller.signal);if(E({uploaded:[...b.task.uploaded,...S.files]}),m.current(b.task.directory),S.files.length!==b.task.retryFiles.length){const T=new Set(S.results?.filter(D=>D.status==="uploaded").map(D=>D.index)??[]);throw E({retryFiles:S.results?b.task.retryFiles.filter((D,F)=>!T.has(F)):[]}),new Error("Incomplete upload result. Check the saved paths before retrying.")}E({retryFiles:[]})}if(b.controller.signal.aborted)throw new DOMException("Upload canceled","AbortError");if(b.insert){E({status:"inserting"});const S=b.task.uploaded[0]?.path;if(!S||!b.isCurrent?.()||!await b.insert(S)||!b.isCurrent?.()||b.controller.signal.aborted)return E({status:"error",error:"reference"}),!1}return E({status:"done"}),!0}catch(S){if(S instanceof Bd&&S.result?.files.length){const T=new Set(S.result.results?.filter(D=>D.status==="uploaded").map(D=>D.index)??[]);E({uploaded:[...b.task.uploaded,...S.result.files],retryFiles:S.result.results?b.task.retryFiles.filter((D,F)=>!T.has(F)):[]}),m.current(b.task.directory)}return E({status:b.controller.signal.aborted?"canceled":"error",error:S instanceof Bd&&S.code==="UPLOAD_LIMIT"?"UPLOAD_LIMIT":S instanceof Error?S.message:String(S)}),!1}finally{l.current===b&&(l.current=null)}},[]),f=a.useCallback((b,E,S,T)=>E.length?g({task:{kind:S?"image":"files",directory:b,files:E,retryFiles:E,uploaded:[],status:"uploading"},controller:new AbortController,insert:S,isCurrent:T}):Promise.resolve(!1),[g]),p=a.useCallback(()=>{const b=d.current;if(!b||l.current||!b.insert&&!b.task.retryFiles.length)return Promise.resolve(!1);const E={...b,controller:new AbortController,task:{...b.task}};return g(E)},[g]),x=a.useCallback(()=>{const b=l.current;!b||b.task.status!=="uploading"||b.controller.abort()},[]),h=a.useCallback(()=>{l.current||(d.current=null,s(null))},[]);return{task:n,start:f,retry:p,cancel:x,dismiss:h,busy:n?.status==="uploading"||n?.status==="inserting"}}function qg({task:r,labels:n,onCancel:s,onRetry:l,onDismiss:d}){const c=r.status==="uploading"||r.status==="inserting",m=r.error==="reference"?n.referenceRejected:r.error==="UPLOAD_LIMIT"?n.limit:r.status==="error"?`${n.failed}: ${r.error??""}`:n[r.status],g=r.status==="error"&&(r.kind==="image"&&r.uploaded.length>0||r.retryFiles.length>0&&r.retryFiles.length<=50);return e.jsxs("section",{className:"shrink-0 border-t border-border/20 bg-surface/80 px-3 py-2 text-xs","data-sidebar-upload-status":!0,"aria-busy":c,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`min-w-0 flex-1 break-words ${r.status==="error"?"text-destructive":"text-foreground"}`,role:r.status==="error"?"alert":"status",children:m}),r.status==="uploading"&&e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-2 py-1 hover:bg-surface-elevated",onClick:s,children:n.cancel}),g&&e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-2 py-1 hover:bg-surface-elevated",onClick:l,children:n.retry}),!c&&e.jsx("button",{type:"button",className:"shrink-0 rounded px-2 py-1 text-muted-foreground hover:bg-surface-2",onClick:d,"aria-label":n.dismiss,children:"×"})]}),e.jsx("div",{className:"mt-1 truncate text-muted-foreground",title:r.directory,children:r.directory}),e.jsxs("details",{className:"mt-1 min-w-0 text-muted-foreground",children:[e.jsxs("summary",{className:"cursor-pointer truncate",children:[n.files," · ",r.files[0]?.name]}),e.jsxs("ul",{className:"mt-1 max-h-24 overflow-y-auto font-mono text-[10px]",children:[r.files.map((f,p)=>e.jsx("li",{className:"break-all",children:f.name},`${p}:${f.name}`)),r.uploaded.map(f=>e.jsx("li",{className:"break-all text-foreground",children:f.path},f.path))]})]})]})}function Vg(r){const n=a.useRef(r),s=a.useRef(0);(n.current.text!==r.text||n.current.sessionId!==r.sessionId||n.current.active!==r.active)&&(s.current+=1),n.current=r;const l=a.useRef(!0),d=a.useRef(!1);return a.useEffect(()=>(l.current=!0,()=>{l.current=!1,s.current+=1}),[]),a.useCallback(async c=>{if(d.current||!n.current.active)return!1;const m=n.current,g=s.current,{text:f,options:p}=Gg(m.text,c);if(!f)return!1;d.current=!0;try{const x=await Zu(f,m.sessionId,()=>l.current&&n.current.active&&n.current.sessionId===m.sessionId,void 0,p),h=l.current&&g===s.current;return h&&(x?n.current.onAccepted():n.current.onRejected()),x&&h}finally{d.current=!1}},[])}const pu={status:"idle",error:null,result:null};function Yg(r,n=!0){const[s,l]=a.useState(pu),d=a.useRef(null);a.useLayoutEffect(()=>(l(pu),()=>{const g=d.current;d.current=null,g?.abort()}),[r,n]);const c=a.useCallback(()=>{const g=d.current;g&&(d.current=null,g.abort(),l({status:"canceled",error:null,result:"canceled"}))},[]),m=a.useCallback(async()=>{if(!n||!r||d.current)return;const g=new AbortController;d.current=g,l({status:"pending",error:null,result:null});try{const f=await Ku(r,g.signal);if(d.current!==g)return;d.current=null;const p=g.signal.aborted?"canceled":f;l({status:p,error:null,result:p})}catch(f){if(d.current!==g)return;d.current=null,g.signal.aborted?l({status:"canceled",error:null,result:"canceled"}):l({status:"error",error:f instanceof Error?f.message:String(f),result:null})}},[r,n]);return{...s,start:m,cancel:c}}const yl="termdock:right-sidebar:html-view-mode-by-file:v1";function Xg(r){return r==="preview"||r==="source"}function bf(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(Xg)}function xf(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function gu(r,n){const s=xf(r,n);return s?pt(yl,bf)?.[s]??"source":"source"}function Jg(r,n,s){const l=xf(r,n);if(!l)return;const d=pt(yl,bf)??{};Lt(yl,{...d,[l]:s})}function vf(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Qg=1500,bu=256*1024*1024;async function Zg(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",d=s.body?.getReader();if(!d){const g=await s.blob();if(g.size>bu)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const c=[];let m=0;try{for(;;){const{done:g,value:f}=await d.read();if(g)break;if(m+=f.byteLength,m>bu)throw new Error("Media too large for encrypted fallback");c.push(f)}}catch(g){throw await d.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(c,{type:l}))}function To(r,n){const s=vf(r),[l,d]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,m]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const f=navigator.serviceWorker,p=()=>d(!!f?.controller);return f?.addEventListener("controllerchange",p),p(),()=>f?.removeEventListener("controllerchange",p)},[s,l]),a.useEffect(()=>{if(!s||l){m(void 0);return}let f=!1,p;const x=new AbortController,h=window.setTimeout(()=>{Zg(r,x.signal).then(b=>{if(f){URL.revokeObjectURL(b);return}p=b,m(b)}).catch(()=>{f||x.signal.aborted||g.current?.()})},Qg);return()=>{f=!0,window.clearTimeout(h),x.abort(),p&&URL.revokeObjectURL(p)}},[s,l,r]),!s||l?r:c}function Vi(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),d=n%60,c=String(l).padStart(2,"0"),m=String(d).padStart(2,"0");return s>0?`${s}:${c}:${m}`:`${c}:${m}`}function eb(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const Jr=2,tb=8,rb=60,io=5,xu=.05,nb=900;function sb(r){return!Number.isFinite(r)||r<=0?Jr:Math.min(tb,Jr+Math.floor(r/rb))}const ab=350,ob=6,ib=90;function lb({url:r,onLoadError:n}){const s=To(r,n),{t:l}=ft(),d=a.useRef(null),c=a.useRef(null),m=a.useRef(null),g=a.useRef(null),f=a.useRef(!1),p=a.useRef(null),x=a.useRef(null),h=a.useRef(0),b=a.useRef(!1),E=a.useRef(!1),S=a.useRef(!1),T=a.useRef(null),D=a.useRef(null),F=a.useRef(!1),M=a.useRef(1),C=a.useRef(!1),[P,B]=a.useState(0),[q,j]=a.useState(0),[o,_]=a.useState(!1),[I,V]=a.useState(!1),[W,O]=a.useState(null),[R,H]=a.useState(!1),[ee,L]=a.useState(0),[U,X]=a.useState(!1),[ce,he]=a.useState({width:0,height:0}),[Re,Ne]=a.useState(Jr),[$e,Q]=a.useState(1),[xe,fe]=a.useState(null),Fe=a.useRef(Jr),Oe=a.useRef(null),G=a.useCallback(()=>{T.current!==null&&(clearTimeout(T.current),T.current=null)},[]),Ce=a.useCallback(()=>{G();const z=D.current;if(D.current=null,!F.current)return!1;const oe=m.current;if(oe&&(oe.playbackRate=M.current,z))try{oe.releasePointerCapture?.(z.id)}catch{}return F.current=!1,Fe.current=Jr,H(!1),!0},[G]);a.useEffect(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current),x.current!==null&&clearTimeout(x.current),Oe.current!==null&&clearTimeout(Oe.current),G();const z=m.current;z&&F.current&&(z.playbackRate=M.current)},[G]),a.useEffect(()=>{const z=c.current;if(!z||typeof ResizeObserver>"u")return;const oe=new ResizeObserver(([je])=>{je&&he({width:je.contentRect.width,height:je.contentRect.height})});return oe.observe(z),()=>oe.disconnect()},[]),a.useEffect(()=>{const z=()=>X(document.fullscreenElement===d.current);return document.addEventListener("fullscreenchange",z),()=>document.removeEventListener("fullscreenchange",z)},[]);const Se=a.useCallback((z,oe=!1)=>{const je=m.current;if(!je)return!1;const Qe=Number.isFinite(je.duration)?je.duration:z,At=Math.min(Math.max(z,0),Qe);if(j(At),Math.abs(je.currentTime-At)<1/120)return!1;const Nr=je.fastSeek;return oe&&typeof Nr=="function"?Nr.call(je,At):je.currentTime=At,!0},[]),de=a.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null;const z=m.current;if(!z||!b.current||E.current||z.seeking)return;const oe=S.current;S.current=!1,E.current=Se(h.current,!oe)}))},[Se]),qe=a.useCallback(z=>{const oe=g.current,je=m.current;if(!oe||!je)return;const Qe=oe.getBoundingClientRect(),At=eb(z,Qe,je.duration);h.current=At,O(At),S.current=!1,de(),x.current!==null&&clearTimeout(x.current),x.current=setTimeout(()=>{x.current=null,S.current=!0,de()},ib)},[de]),$=a.useCallback(()=>{p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),x.current!==null&&(clearTimeout(x.current),x.current=null),S.current=!1,E.current=!1,Se(h.current)},[Se]),me=a.useCallback(z=>{const oe=m.current;if(!(!oe||!Number.isFinite(oe.duration)||oe.duration<=0)){f.current=!oe.paused,oe.pause(),b.current=!0,V(!0);try{z.currentTarget.setPointerCapture(z.pointerId)}catch{}qe(z.clientX)}},[qe]),ge=a.useCallback(()=>{b.current=!1,$(),V(!1),O(null);const z=m.current;z&&f.current&&!z.ended&&z.play().catch(()=>{}),f.current=!1},[$]),Le=a.useCallback(()=>{const z=m.current;if(z){if(C.current){C.current=!1;return}z.paused?z.play().catch(()=>{}):z.pause()}},[]),ne=a.useCallback(z=>{const oe=m.current;if(!oe)return;const je=Math.min(1,Math.max(0,Math.round((oe.volume+z)*100)/100));oe.volume=je,je>0&&(oe.muted=!1),Q(je),fe(je),Oe.current!==null&&clearTimeout(Oe.current),Oe.current=setTimeout(()=>{Oe.current=null,fe(null)},nb)},[]),Ye=a.useCallback(z=>{const oe=m.current;if(oe){if(z.key==="ArrowLeft"){z.preventDefault(),Se(oe.currentTime-(z.shiftKey?io*2:io));return}if(z.key==="ArrowRight"){z.preventDefault(),Se(oe.currentTime+(z.shiftKey?io*2:io));return}if(z.key==="ArrowUp"){z.preventDefault(),ne(xu);return}if(z.key==="ArrowDown"){z.preventDefault(),ne(-xu);return}(z.key===" "||z.key==="Spacebar"||z.key==="k"||z.key==="K")&&(z.preventDefault(),oe.paused?oe.play().catch(()=>{}):oe.pause())}},[Se,ne]),Je=a.useCallback(z=>{const oe=m.current;!oe||oe.paused||z.button!==0||(G(),D.current={id:z.pointerId,x:z.clientX,y:z.clientY},T.current=setTimeout(()=>{T.current=null;const je=D.current;if(M.current=oe.playbackRate,oe.playbackRate=Jr,Fe.current=Jr,Ne(Jr),F.current=!0,H(!0),je)try{oe.setPointerCapture?.(je.id)}catch{}},ab))},[G]),De=a.useCallback(z=>{const oe=D.current;if(!oe||oe.id!==z.pointerId)return;if(!F.current){Math.hypot(z.clientX-oe.x,z.clientY-oe.y)>ob&&(G(),D.current=null);return}const je=sb(z.clientX-oe.x);if(je===Fe.current)return;Fe.current=je,Ne(je);const Qe=m.current;Qe&&(Qe.playbackRate=je)},[G]),Te=a.useCallback(()=>{Ce()&&(C.current=!0)},[Ce]);a.useEffect(()=>(window.addEventListener("pointerup",Te),window.addEventListener("pointercancel",Te),window.addEventListener("blur",Te),()=>{window.removeEventListener("pointerup",Te),window.removeEventListener("pointercancel",Te),window.removeEventListener("blur",Te)}),[Te]);const _e=a.useCallback(async()=>{const z=d.current,oe=m.current;if(!(!z||!oe))try{document.fullscreenElement===z?await document.exitFullscreen():z.requestFullscreen?await z.requestFullscreen():oe.webkitEnterFullscreen?.()}catch{oe.webkitEnterFullscreen?.()}},[]),Be=a.useCallback(()=>L(z=>(z+90)%360),[]),te=a.useCallback(z=>{const oe=m.current;if(!oe||!Number.isFinite(oe.duration))return;const je=z.shiftKey?10:5;let Qe=null;z.key==="ArrowLeft"?Qe=oe.currentTime-je:z.key==="ArrowRight"?Qe=oe.currentTime+je:z.key==="Home"?Qe=0:z.key==="End"&&(Qe=oe.duration),Qe!==null&&(z.preventDefault(),Se(Qe))},[Se]),ye=I&&W!==null?W:q,nt=P>0?Math.min(1,Math.max(0,ye/P)):0,er=(ee===90||ee===270)&&ce.width>0&&ce.height>0?{width:`${ce.height}px`,height:`${ce.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:d,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":ee,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:m,"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${R?` ${su}`:""}`,style:{...er,transform:`translate(-50%, -50%) rotate(${ee}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...R?{[au]:""}:{},onClick:Le,onKeyDown:Ye,onVolumeChange:z=>Q(z.currentTarget.volume),onPointerDown:Je,onPointerMove:De,onPointerUp:Te,onPointerCancel:Te,onContextMenu:z=>{F.current&&z.preventDefault()},onPlay:()=>_(!0),onPause:()=>_(!1),onTimeUpdate:z=>j(z.currentTarget.currentTime),onSeeked:z=>{const oe=z.currentTarget;if(j(oe.currentTime),E.current=!1,!b.current)return;const je=oe.requestVideoFrameCallback;typeof je=="function"?je.call(oe,()=>{b.current&&de()}):requestAnimationFrame(()=>{b.current&&de()})},onLoadedMetadata:z=>B(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onDurationChange:z=>B(Number.isFinite(z.currentTarget.duration)?z.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),R&&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(Re)})}),xe!==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(gp,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round($e*100)})]}),I&&W!==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:`${nt*100}%`},"data-testid":"file-preview-video-scrub-time",children:Vi(W)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${su}`,[au]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Le,"aria-label":l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(o?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:o?e.jsx(bp,{size:14}):e.jsx(xp,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(P),"aria-valuenow":Math.floor(ye),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:me,onPointerMove:z=>{I&&qe(z.clientX)},onPointerUp:ge,onPointerCancel:ge,onKeyDown:te,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:`${nt*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:`${nt*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Vi(ye)," / ",Vi(P)]}),e.jsx("button",{type:"button",onClick:Be,"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(Qu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{_e()},"aria-label":l(U?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(U?"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:U?e.jsx(vp,{size:14}):e.jsx(yp,{size:14})})]})})]})}function cb(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function Io({anchor:r,children:n,disabled:s=!1,onClick:l,title:d}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:d,style:cb(r),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(jo,{size:11}),n]})}function db(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const d=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(d)||d<=0)return null;const c=l.width*d,m=l.height*d,g=s.left+(s.width-c)/2,f=s.top+(s.height-m)/2,p=r-g,x=n-f;if(p<0||x<0||p>c||x>m)return null;const h=p/c*100,b=x/m*100;return{x:l.x+l.width*h/100,y:l.y+l.height*b/100,xPercent:h,yPercent:b}}function ub(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function fb(r){const n=new DOMParser().parseFromString(r,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const d of Array.from(l.attributes)){const c=d.name.toLowerCase(),m=d.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&m&&!m.startsWith("#"))&&l.removeAttribute(d.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function hb(r,n,s){let l=null;for(const d of Array.from(r.querySelectorAll("text"))){const c=(d.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const m=Number(d.getAttribute("x")),g=Number(d.getAttribute("y"));if(!Number.isFinite(m)||!Number.isFinite(g))continue;const f=Math.hypot(m-n,g-s);(!l||f<l.distance)&&(l={text:c,distance:f})}return l?.text.slice(0,120)}function yf({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const d=a.useRef(null),c=a.useRef(null),[m,g]=a.useState(null),[f,p]=a.useState(null),[x,h]=a.useState(1),[b,E]=a.useState(!1),[S,T]=a.useState(null),D=a.useRef(new Map),F=a.useRef(null),M=a.useRef(!1),C=a.useRef(null),P=a.useRef(x);P.current=x,a.useEffect(()=>{const L=new AbortController;return g(null),p(null),T(null),h(1),fetch(r,{signal:L.signal}).then(U=>U.text()).then(U=>g(fb(U))).catch(U=>{L.signal.aborted||p(U instanceof Error?U.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!b)return;const L=U=>{U.key==="Escape"&&E(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b]),a.useLayoutEffect(()=>{const L=c.current,U=L?.querySelector("[data-svg-document] > svg");if(!L||!U)return;let X;try{X=U.getBBox()}catch{return}if(!X.width||!X.height)return;const ce=Math.max(2,Math.min(X.width,X.height)*.025);U.setAttribute("viewBox",`${X.x-ce} ${X.y-ce} ${X.width+2*ce} ${X.height+2*ce}`),U.style.width=`${x*100}%`,U.style.height=`${x*100}%`,U.style.minWidth=`${x*100}%`,U.style.minHeight=`${x*100}%`,U.style.display="block"},[m,x]);const B=a.useMemo(()=>S?ub(n,s,S):null,[n,S,s]),q=L=>{if(M.current){M.current=!1;return}const U=c.current,X=U?.querySelector("[data-svg-document] > svg"),ce=d.current;if(!U||!X||!ce)return;const he=X.viewBox.baseVal,Re=db(L.clientX,L.clientY,X.getBoundingClientRect(),he);if(!Re)return;const Ne=ce.getBoundingClientRect();T({...Re,nearestText:hb(X,Re.x,Re.y),stageX:L.clientX-Ne.left,stageY:L.clientY-Ne.top,stageXPercent:(L.clientX-Ne.left)/Ne.width*100,stageYPercent:(L.clientY-Ne.top)/Ne.height*100})},j=L=>Math.max(1,Math.min(12,L)),o=(L,U)=>{const X=j(U),ce=L.querySelector("[data-svg-document] > svg");if(!ce)return X;const he=`${X*100}%`;return ce.style.width=he,ce.style.height=he,ce.style.minWidth=he,ce.style.minHeight=he,P.current=X,X},_=(L,U,X,ce)=>{const he=P.current,Re=L.getBoundingClientRect(),Ne=X-Re.left,$e=ce-Re.top,Q=(L.scrollLeft+Ne)/he,xe=(L.scrollTop+$e)/he,fe=o(L,U);return L.scrollLeft=Q*fe-Ne,L.scrollTop=xe*fe-$e,fe},I=()=>{const L=Array.from(D.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},V=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const U=c.current;U&&(D.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),U.setPointerCapture?.(L.pointerId),D.current.size>=2?(F.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startDistance:I(),startZoom:P.current,moved:!1},M.current=!0):P.current>1&&(F.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startZoom:P.current,moved:!1}))},W=L=>{if(!D.current.has(L.pointerId))return;D.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const U=c.current,X=F.current;if(!(!U||!X)){if(D.current.size>=2&&X.kind==="pinch"){const ce=I();if(!X.startDistance||!ce)return;const he=j(X.startZoom*ce/X.startDistance);if(Math.abs(he-P.current)<.01)return;const Re=Array.from(D.current.values()),Ne=(Re[0].x+Re[1].x)/2,$e=(Re[0].y+Re[1].y)/2;X.moved=!0,M.current=!0,_(U,he,Ne,$e),L.preventDefault();return}if(X.kind==="pan"&&D.current.size===1){const ce=L.clientX-X.startX,he=L.clientY-X.startY;if(!X.moved&&Math.hypot(ce,he)<6)return;X.moved=!0,M.current=!0,U.scrollLeft=X.startScrollLeft-ce,U.scrollTop=X.startScrollTop-he,L.preventDefault()}}},O=L=>{const U=c.current,X=F.current,ce=D.current.size===1&&!X?.moved;D.current.delete(L.pointerId);try{U?.releasePointerCapture?.(L.pointerId)}catch{}if(D.current.size===1&&X?.kind==="pinch"){const Ne=Array.from(D.current.values())[0];F.current=U?{kind:"pan",startX:Ne.x,startY:Ne.y,startScrollLeft:U.scrollLeft,startScrollTop:U.scrollTop,startZoom:P.current,moved:!1}:null;return}if(D.current.size>0||(F.current=null,X?.kind==="pinch"&&h(P.current),!ce||M.current))return;const he=Date.now(),Re=C.current;Re&&he-Re.time<350&&Math.hypot(L.clientX-Re.x,L.clientY-Re.y)<24?(C.current=null,M.current=!0,h(Ne=>Ne>1?1:2.5)):C.current={time:he,x:L.clientX,y:L.clientY}},R=L=>{if(!L.ctrlKey&&!L.metaKey)return;const U=c.current;if(!U)return;L.preventDefault();const X=_(U,P.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);h(X)},H=()=>{h(1),P.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},ee=e.jsxs("div",{className:b?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:q,onDoubleClick:L=>{L.preventDefault(),h(U=>U>1?1:2.5)},onPointerDown:V,onPointerMove:W,onPointerUp:O,onPointerCancel:O,onWheel:R,onScroll:()=>T(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:f?e.jsx("div",{className:"p-4 text-sm text-destructive",children:f}):m?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:m}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),S&&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:S.stageX,top:S.stageY}}),S&&B&&e.jsx(Io,{anchor:{xPercent:S.stageXPercent,yPercent:S.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(B,`svg:${S.x.toFixed(2)}:${S.y.toFixed(2)}`),T(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[x>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),H()},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(eg,{size:14})}),e.jsx("button",{type:"button","aria-label":b?"退出全屏 SVG":"全屏 SVG",title:b?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),E(U=>!U)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:b?e.jsx(lf,{size:14}):e.jsx(af,{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:S?`SVG (${S.x.toFixed(2)}, ${S.y.toFixed(2)}) · ${S.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return b?Rr.createPortal(ee,document.body):ee}function xo(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function mb(r,n,s,l){const d=[`电子标注: ${r}`,`视图: ${xo(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(d.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&d.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(",");d.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${d.join(" / ")}"`}function pb({blobUrl:r,filePath:n,view:s,board:l,onViewChange:d,onInsertAnnotation:c,onRefresh:m,interactive3d:g}){const{t:f}=ft(),p=a.useRef(null),x=a.useRef(null),h=a.useRef(null),[b,E]=a.useState(null),[S,T]=a.useState(!1);a.useEffect(()=>(h.current?.abort(),E(null),T(!1),()=>h.current?.abort()),[r,s]);const D=a.useMemo(()=>b?mb(n,s,b,b.inspection):null,[n,b,s]),F=C=>{const P=p.current,B=x.current;if(!P||!B||!B.naturalWidth||!B.naturalHeight)return;const q=P.getBoundingClientRect(),j=B.getBoundingClientRect(),o=Math.min(j.width/B.naturalWidth,j.height/B.naturalHeight),_=B.naturalWidth*o,I=B.naturalHeight*o,V=j.left+(j.width-_)/2,W=j.top+(j.height-I)/2,O=C.clientX-V,R=C.clientY-W;if(O<0||R<0||O>_||R>I)return;const H={xPercent:Math.max(0,Math.min(100,O/_*100)),yPercent:Math.max(0,Math.min(100,R/I*100)),stageXPercent:(C.clientX-q.left)/q.width*100,stageYPercent:(C.clientY-q.top)/q.height*100,inspecting:l&&s!=="pcb-3d"};if(E(H),h.current?.abort(),!H.inspecting)return;const ee=new AbortController;h.current=ee,Bm(n,s,H.xPercent,H.yPercent,ee.signal).then(L=>E(U=>U===H?{...U,inspection:L,inspecting:!1}:U)).catch(()=>{ee.signal.aborted||E(L=>L===H?{...L,inspection:{available:!1},inspecting:!1}:L)})},M=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:M.map(C=>e.jsx("button",{type:"button",onClick:()=>d(C),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${C===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:xo(C)},C))}),e.jsx("button",{type:"button",onClick:m,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:f("rightSidebar.edaRefresh"),"aria-label":f("rightSidebar.edaRefresh"),children:e.jsx(bo,{size:13})})]}),l&&g?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:g}):null,l?s==="pcb-3d"?g?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:p,role:"button",tabIndex:0,onClick:F,onKeyDown:C=>{C.key!=="Enter"&&C.key!==" "||(C.preventDefault(),E({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:f("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:x,src:r,alt:`${n} ${xo(s)}`,onLoad:()=>T(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${S?"opacity-100":"opacity-0"}`}),b&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${b.stageXPercent}%`,top:`${b.stageYPercent}%`}}),b&&D&&e.jsx(Io,{anchor:{xPercent:b.stageXPercent,yPercent:b.stageYPercent},disabled:b.inspecting,title:f("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(D,`eda:${s}:${b.xPercent.toFixed(1)}:${b.yPercent.toFixed(1)}`,{snapshot:x.current?yg(x.current,b):Promise.resolve(null)}),E(null)},children:f("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?b.inspecting?f("rightSidebar.edaInspecting"):b.inspection?.available?f("rightSidebar.edaPickedBoardPosition",{x:b.inspection.xMm?.toFixed(2)??"—",y:b.inspection.yMm?.toFixed(2)??"—",object:b.inspection.nearest?.label??f("rightSidebar.edaNoNearbyObject")}):f("rightSidebar.edaPickedPosition",{x:b.xPercent.toFixed(1),y:b.yPercent.toFixed(1)}):f("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(yf,{blobUrl:r,filePath:n,viewLabel:xo(s),onInsertAnnotation:c})})]})}function gb(r){const n=[];let s=[],l="",d=!1;for(let c=0;c<r.length;c+=1){const m=r[c];d?m==='"'&&r[c+1]==='"'?(l+='"',c+=1):m==='"'?d=!1:l+=m:m==='"'?d=!0:m===","?(s.push(l),l=""):m===`
14
+ `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=m}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function bb(r,n,s,l,d){const c=n[d]||`第${d+1}列`,m=s[d]??"",g=n.map((f,p)=>`${f||`第${p+1}列`}=${s[p]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${c} / 值: ${m} / 记录: ${g}"`}function xb({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=ft(),d=a.useMemo(()=>gb(r),[r]),c=d[0]??[],m=d.slice(1),g=a.useRef(null),[f,p]=a.useState(null),x=f?m[f.row]:null,h=f&&x?bb(n,c,x,f.row+1,f.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:g,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((b,E)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:b||l("rightSidebar.csvUnnamedColumn",{index:E+1})},`${b}:${E}`))]})}),e.jsx("tbody",{children:m.map((b,E)=>e.jsxs("tr",{className:"hover:bg-surface-2",children:[e.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:E+1}),c.map((S,T)=>{const D=f?.row===E&&f.column===T;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${D?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:F=>{const M=g.current?.getBoundingClientRect(),C=F.currentTarget.getBoundingClientRect();if(!M?.width||!M.height)return;const P=F.clientX||C.left+C.width/2,B=F.clientY||C.top+C.height/2;p({row:E,column:T,xPercent:(P-M.left)/M.width*100,yPercent:(B-M.top)/M.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:b[T]||" "})},`cell:${E}:${T}`)})]},`row:${E}`))})]})}),f&&h&&e.jsx(Io,{anchor:{xPercent:f.xPercent,yPercent:f.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(h,`csv:${n}:${f.row+1}:${f.column+1}`),p(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:f&&x?l("rightSidebar.csvSelectedCell",{row:f.row+1,column:c[f.column]||f.column+1}):l("rightSidebar.csvPickHint",{rows:m.length,columns:c.length})})})]})}function us(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function vb(r,n){const s=JSON.parse(r),l=us(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(us(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(us(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:us(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const d=us(s,["net_settings","classes"]),c=Array.isArray(d)?d.find(g=>g&&typeof g=="object"&&g.name==="Default"):void 0,m=us(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(d)?d.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(m)?m.length:0)}]}function yb(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function wb({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:d}=ft(),c=a.useRef(null),[m,g]=a.useState(null),f=a.useMemo(()=>{try{return{items:vb(r,s),error:null}}catch(x){return{items:[],error:x instanceof Error?x.message:String(x)}}},[r,s]),p=m===null?null:f.items[m.index];return f.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:r}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:d("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:f.items.map((x,h)=>e.jsxs("button",{type:"button",onClick:b=>{const E=c.current?.getBoundingClientRect(),S=b.currentTarget.getBoundingClientRect();if(!E?.width||!E.height)return;const T=b.clientX||S.left+S.width/2,D=b.clientY||S.top+S.height/2;g({index:h,xPercent:(T-E.left)/E.width*100,yPercent:(D-E.top)/E.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${m?.index===h?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:x.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:x.value})]},x.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:d("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),p&&m&&e.jsx(Io,{anchor:{xPercent:m.xPercent,yPercent:m.yPercent},title:d("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(yb(n,p),`kicad-project:${n}:${p.label}`),g(null)},children:d("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:p?`${p.label}: ${p.value}`:d("rightSidebar.kicadProjectPickHint")})})]})}const kb=`/** ES Module Shims Wasm @version 2.8.4 */
15
15
  (function () {
16
16
 
17
17
  const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
@@ -1497,7 +1497,7 @@ import{ag as lr,da as ft,by as e,h as wo,ct as Id,ap as Uu,_ as Mn,bG as Hu,L as
1497
1497
  };
1498
1498
 
1499
1499
  })();
1500
- `,vb=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1500
+ `,Sb=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1501
1501
  function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1502
1502
  const external = new Set(externalOrigins);
1503
1503
  const report = () => parent.postMessage({ type: 'preview-error', capability }, '*');
@@ -1632,46 +1632,46 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1632
1632
  window.addEventListener('error', report, true);
1633
1633
  window.addEventListener('unhandledrejection', report);
1634
1634
  }
1635
- `,oo="/api/terminal/fs/preview/",yb=8*1024*1024,wb=32*1024*1024,kb=128,Sb="data:,";function $t(r){throw new Error(r)}function jb(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function mu(r,n,s){let l="",d=0;for(const c of r.matchAll(n))l+=r.slice(d,c.index)+await s(c),d=c.index+c[0].length;return l+r.slice(d)}async function gf(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!Us(l.pathname)?.startsWith(oo))&&$t("预览地址不是有效的本地文件入口");const d=crypto.randomUUID(),c=`https://termdock-preview.invalid/${d}/`,m=[],g=H=>{!m.includes(H)&&m.length<20&&m.push(H)},f=new Set,p=[],x=new Set,h=new Map,b=new Map;let E=0,S=!1;const T=new Set,D=()=>{S=!0;for(const H of[...T])H();f.clear(),p.length=0};async function F(H){H.ok||$t(`预览资源读取失败(${H.status})`);const ee=H.body?.getReader(),L=[];let U=0;try{if(ee)for(;;){const he=await ee.read();if(he.done)break;U+=he.value.byteLength,E+=he.value.byteLength,(U>yb||E>wb)&&$t("预览资源超出大小限制"),L.push(he.value)}}catch(he){throw await ee?.cancel().catch(()=>{}),he}finally{ee?.releaseLock()}const X=new Uint8Array(U);let ce=0;for(const he of L)X.set(he,ce),ce+=he.length;return{bytes:X,type:H.headers.get("content-type")??"application/octet-stream",status:H.status}}let M=l,N;for(let H=0;H<4;H++){const ee=await n.fetch(M.pathname+M.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(ee.status)){N=ee;break}const L=ee.headers.get("location");await ee.body?.cancel(),L||$t("预览重定向缺少目标");const U=new URL(L,M);(U.origin!==s||!Us(U.pathname)?.startsWith(oo))&&$t("预览重定向越出文件范围"),M=U}N||$t("预览重定向次数过多");const P=Us(M.pathname),B=P.slice(oo.length).split("/");/^[a-f0-9]{32}$/.test(B[0])||$t("服务未提供有效的预览资源授权");const q=Us(l.pathname).slice(oo.length).split("/");/^[a-f0-9]{32}$/.test(q[0])&&q.shift(),q.join("/").replace(/\/$/,"")!==B.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const j=P.endsWith("/")?P:P.slice(0,P.lastIndexOf("/")+1),o=new URL(M.pathname.endsWith("/")?M.pathname:M.pathname.slice(0,M.pathname.lastIndexOf("/")+1),s);function _(H,ee){const L=new URL(H,ee);return L.origin!==s?null:(Us(L.pathname)?.startsWith(j)||$t("已阻止预览访问目录之外的资源"),L)}function I(H){const ee=new URL(H,c);(ee.origin!==new URL(c).origin||!ee.pathname.startsWith(new URL(c).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const L=ee.pathname.slice(new URL(c).pathname.length)+ee.search;return _(L,o)??$t("预览资源无效")}function V(H){const ee=H.pathname+H.search,L=h.get(ee);if(L)return L;if(S||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(h.size>=kb)return Promise.reject(new Error("预览资源数量超出限制"));const U=n.fetch(ee,{signal:n.signal,redirect:"manual"}).then(F);return h.set(ee,U),U}function W(H,ee){S&&$t("预览已关闭");const L=`termdock-resource-${d}-${p.length}`;return p.push({token:L,data:H,type:ee}),f.add(L),L}async function O(H,ee,L,U=new Set){if(!H||H.startsWith("#")||/^data:(?:image|font)\//i.test(H)&&L==="resource")return H;try{const X=_(H,ee);if(!X){const $e=new URL(H,ee);return($e.protocol!=="https:"||$e.username||$e.password||$e.origin===new URL(c).origin)&&$t("已阻止不安全的外部资源"),x.add($e.origin),$e.href}const ce=`${L}:${X.href}`;(U.has(ce)||U.size>=8)&&$t("预览资源存在循环或过深引用");const he=b.get(ce);if(he)return he;const Re=new Set(U);Re.add(ce);const Ce=(async()=>{const $e=await V(X);return L==="css"?W(await R(new TextDecoder().decode($e.bytes),X,Re),"text/css"):L==="script"?W($e.bytes,"text/javascript"):W($e.bytes,$e.type)})();return b.set(ce,Ce),await Ce}catch(X){return g(X instanceof Error?X.message:"部分预览资源未能加载"),Sb}}async function R(H,ee,L){return H=await mu(H,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async U=>`@import url("${await O(U[1],ee,"css",L)}")${U[2]};`),mu(H,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async U=>{const X=(U[1]??U[2]??U[3]).trim();return f.has(X)?U[0]:`url("${await O(X,ee,"resource",L)}")`})}try{const H=await F(N),ee=W(xb,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(H.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(J=>J.remove());for(const J of L.querySelectorAll("*")){if(J.removeAttribute("ping"),J.removeAttribute("srcdoc"),J.hasAttribute("style")&&J.setAttribute("style",await R(J.getAttribute("style"),M,new Set)),J.tagName==="STYLE"&&(J.textContent=await R(J.textContent??"",M,new Set)),J.tagName==="A"||J.tagName==="AREA"){const xe=J.getAttribute("href");try{if(xe&&!xe.startsWith("#")){const fe=_(xe,M);if(fe)J.setAttribute("href",new URL(fe.pathname.slice(o.pathname.length)+fe.search+fe.hash,c).href);else{const Fe=new URL(xe,M);if(Fe.protocol!=="https:"){J.removeAttribute("href");continue}x.add(Fe.origin),J.setAttribute("href",Fe.href)}}}catch(fe){J.removeAttribute("href"),g(fe instanceof Error?fe.message:"预览链接无法加载")}}for(const xe of["data","manifest"])J.removeAttribute(xe);if(J.tagName==="SCRIPT"&&J.getAttribute("type")==="module"){J.setAttribute("type","module-shim");const xe=J.getAttribute("src");if(xe){const fe=_(xe,M);if(fe)J.setAttribute("src",new URL(fe.pathname.slice(o.pathname.length)+fe.search,c).href);else{const Fe=new URL(xe,M);if(Fe.protocol!=="https:"){J.remove();continue}x.add(Fe.origin),J.setAttribute("src",Fe.href)}}continue}if(J.tagName==="SCRIPT"&&J.getAttribute("type")==="importmap"){J.setAttribute("type","importmap-shim");continue}if(J.tagName==="LINK"){const xe=(J.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(xe)){J.remove();continue}const fe=J.getAttribute("href");fe&&J.setAttribute("href",await O(fe,M,xe==="stylesheet"?"css":"resource"))}if(J.hasAttribute("src")&&J.setAttribute("src",await O(J.getAttribute("src"),M,J.tagName==="SCRIPT"?"script":"resource")),J.hasAttribute("poster")&&J.setAttribute("poster",await O(J.getAttribute("poster"),M,"resource")),J.hasAttribute("srcset")){const xe=J.getAttribute("srcset");/data:/i.test(xe)?(J.removeAttribute("srcset"),g("混合内嵌图片候选暂不支持安全预览")):J.setAttribute("srcset",(await Promise.all(xe.split(",").map(async fe=>{const[Fe,...Oe]=fe.trim().split(/\s+/);return`${await O(Fe,M,"resource")} ${Oe.join(" ")}`}))).join(", "))}J.setAttribute("referrerpolicy","no-referrer"),J.removeAttribute("integrity"),J.removeAttribute("crossorigin")}const U=[...x].join(" "),X=L.createElement("meta");X.httpEquiv="Content-Security-Policy",X.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${U}; style-src 'unsafe-inline' blob: ${U}; img-src blob: data: ${U}; font-src blob: data: ${U}; media-src blob: data: ${U}; connect-src blob: ${U} ${[...x].map(J=>J.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const ce=L.createElement("base");ce.href=c;const he=L.createElement("meta");he.name="referrer",he.content="no-referrer";const Re=L.createElement("script");Re.textContent=vb+`
1636
- installPreviewRuntime(`+[d,c,[...x],ee].map(jb).join(",")+");";const Ce=L.createElement("script");Ce.src=ee,L.head.prepend(X,he,ce,Re,Ce);const $e=`<!doctype html>
1637
- `+L.documentElement.outerHTML;return{html:$e,shellUrl:`/preview-shell.html#${d}`,errors:m,attach(J,xe){const fe=new Set,Fe=G=>{if(G.source!==J.contentWindow||G.data?.capability!==d)return;if(G.data.type==="preview-ready"){J.contentWindow?.postMessage({type:"preview-init",capability:d,html:$e,resources:p},"*");return}if(G.data.type==="preview-error"){xe("部分动态内容被安全预览限制");return}if(G.data.type==="preview-navigate"){(async()=>{const Se=I(String(G.data.url)),de=await gf(Se.pathname+Se.search,n);if(S){de.dispose();return}const qe=de.attach(J,xe);T.add(()=>{qe(),de.dispose()}),J.src=de.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Se=>xe(Se instanceof Error?Se.message:"无法打开预览页面"));return}if(G.data.type==="preview-external"){try{const Se=new URL(String(G.data.url));Se.protocol==="https:"&&x.has(Se.origin)&&window.open(Se.href,"_blank","noopener,noreferrer")}catch{}return}if(G.data.type!=="preview-fetch"||G.ports.length!==1)return;const Ne=G.ports[0];if(fe.size>=8||!["GET","HEAD"].includes(G.data.method)){Ne.postMessage({error:"预览仅允许读取已授权目录资源"}),Ne.close();return}fe.add(Ne),(async()=>{const Se=I(String(G.data.url)),de=await V(Se);if(!fe.has(Ne)||S)return;const qe=G.data.method==="HEAD"?new Uint8Array:de.bytes.slice();Ne.postMessage({status:de.status,headers:{"content-type":de.type},data:qe.buffer},[qe.buffer])})().catch(()=>{Ne.postMessage({error:"预览资源不在授权范围或无法加载"}),xe("部分动态资源不可用或超出预览目录")}).finally(()=>{fe.delete(Ne),Ne.close()})};window.addEventListener("message",Fe);const Oe=()=>{window.removeEventListener("message",Fe);for(const G of fe)G.close();fe.clear(),T.delete(Oe)};return T.add(Oe),Oe},dispose:D}}catch(H){throw D(),H}}const Rb=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:d},c){const m=a.useRef(null),[g,f]=a.useState(null),[p,x]=a.useState(),[h,b]=a.useState("");a.useEffect(()=>{const P=new AbortController;let B;return x(void 0),b(""),(async()=>{const q=await Tm();if(B=await gf(n,{fetch:(j,o)=>q.fetch(j,o),signal:P.signal}),P.signal.aborted){B.dispose();return}x(B),B.errors.length&&b(B.errors.join(";"))})().catch(q=>{P.signal.aborted||b(q instanceof Error?q.message:"安全预览加载失败")}),()=>{P.abort(),B?.dispose()}},[n]),a.useEffect(()=>{if(!(!p||!g))return p.attach(g,b)},[p,g]);const[E,S]=a.useState(!1),[T,D]=a.useState(!1),F=E||T;a.useEffect(()=>{d?.(F)},[F,d]),a.useEffect(()=>{const P=()=>{S(document.fullscreenElement===m.current)};return document.addEventListener("fullscreenchange",P),()=>document.removeEventListener("fullscreenchange",P)},[]),a.useEffect(()=>{if(!T)return;const P=B=>{B.key==="Escape"&&D(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[T]);const M=a.useCallback(async()=>{const P=m.current;if(P){if(T){D(!1);return}if(document.fullscreenElement===P){await document.exitFullscreen();return}if(P.requestFullscreen&&document.fullscreenEnabled!==!1)try{await P.requestFullscreen();return}catch{}D(!0)}},[T]);a.useImperativeHandle(c,()=>({toggleFullscreen:M}),[M]);const N=e.jsxs("div",{ref:m,"data-html-preview-frame":!0,className:F?"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:[F&&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:()=>{M()},"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(rf,{size:15})})]}),h&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:h}),!p&&!h&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:f,src:p?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return T?jr.createPortal(N,document.body):N}),bf="termdock-file-search-match",vl="termdock-file-search-current";function Cb(r,n,s){return!!(n&&r?.isConnected&&!s.defaultPrevented&&!r.closest('[inert], [aria-hidden="true"], [hidden]')&&s.target instanceof Node&&r.contains(s.target))}function Nb(r){const n=r.metaKey||r.ctrlKey,s=r.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||r.key==="F3"?r.shiftKey?"previous":"next":r.key==="Escape"?"close":null}function Eb(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Mb(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let d="",c=null;const m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let x=m.nextNode();x;x=m.nextNode()){if(!(x instanceof Text)||!x.data)continue;const h=Eb(x);if(!h)continue;c&&c!==h&&(d+=`
1638
- `);const b=d.length;d+=x.data,l.push({node:x,start:b,end:d.length,group:h}),c=h}const g=d.toLocaleLowerCase(),f=[];let p=0;for(;p<=g.length-s.length;){const x=g.indexOf(s,p);if(x<0)break;const h=x+s.length,b=l.find(S=>S.start<=x&&S.end>x),E=l.find(S=>S.start<h&&S.end>=h);if(b&&E&&b.group===E.group){const S=document.createRange();S.setStart(b.node,x-b.start),S.setEnd(E.node,h-E.start),f.push(S)}p=x+Math.max(s.length,1)}return f}function xf(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}let jo;function pu(r){return jo===r}function io(r){if(r&&jo!==r)return;const n=xf();n?.delete(bf),n?.delete(vl),jo=void 0}function qi(r,n,s){const l=xf();if(!l||typeof Highlight>"u")return;jo=s,l.set(bf,new Highlight(...r));const d=r[n];d?l.set(vl,new Highlight(d)):l.delete(vl)}function gu(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function $b(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Lb(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Pb(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function vf(r,n,s){return n?r:jr.createPortal(r,s)}const Pl="termdock:right-sidebar:file-tree-scroll:v1",Al="termdock:right-sidebar:file-preview-reading-state:v1",Ys="termdock:right-sidebar:file-tree-width:v1",yf="termdock:right-sidebar:markdown-view-mode:v1",wf="termdock:right-sidebar:diff-change-list-mode:v1",kf="termdock:right-sidebar:diff-wrap:v1",Sf="termdock:diff-viewer:view-type:v1",jf="termdock:right-sidebar:file-search-mode:v1",Vi="termdock:right-sidebar:collapsed-git-repo-groups:v1",bu="termdock:right-sidebar:collapsed-diff-directories:v1",Yi="termdock:right-sidebar:branch-audit-module-open:v1",Rf="termdock:right-sidebar:branch-audit-module:v1",Ab=150,xu="termdock:right-sidebar:context-draft-enabled:v1",vu="termdock:right-sidebar:context-draft-collapsed:v1",yu="termdock:right-sidebar:context-draft-auto-collapse:v1",Xi="termdock:right-sidebar:context-draft-text:v1",Tb=300,Ib=20,Db=120,Fb=250,_b=250,Bb=120,Ob=700,Ji=600,Ub=6e4;function Ws(r){return!!(r&&Q.getState().nestedGitScanRoots[r])}const wu=[2e3,5e3,15e3,3e4],Hb=320,zb=500,Wb=20,Gb=12e3,yl=300,ku=240,Kb=560,Cf="border-r px-2 py-1.5 sm:px-3 sm:py-2",Ro="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Nf=`${Cf} border-b border-border/15 font-semibold last:border-r-0`,Ef=`${Cf} border-border/10 align-top text-muted-foreground last:border-r-0`,Tl="termdock-file-preview-horizontal-scroll",Su=a.lazy(()=>Mn(()=>import("./ModelPreview-B22odexG.js"),__vite__mapDeps([7,1,2,3,4,5,8,9,10,11,12,13,14,15,16,17]))),qb=a.lazy(()=>Mn(()=>import("./ArchitecturePanel-Cj7za6DZ.js"),__vite__mapDeps([18,1,2,3,4,5,8,9,10,11,12,15,16,6,14,13,17,19])).then(r=>({default:r.ArchitecturePanel}))),Vb=a.lazy(()=>Mn(()=>import("./ComputerControlView-Dkc4R1IU.js").then(r=>r.C),__vite__mapDeps([20,1,2,3,4,5,17,14,11,8,9,10,12]))),Mf=`${Tl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function $f(r,n,s){return r&&!n?"unified":s}const Yb=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Xb(r){return r==="preview"||r==="source"}function Jb(r){return r==="list"||r==="tree"||r==="ai"}function ju(){return pt(yf,Xb)??"preview"}function Qb(){return pt(wf,Jb)??"tree"}function Xs(r){return typeof r=="boolean"}function Zb(r){return typeof r=="string"}function ex(){return pt(kf,Xs)??!0}function tx(r){return r==="unified"||r==="split"}function rx(){return pt(Sf,tx)??"unified"}function nx(r){return r==="name"||r==="content"||r==="regex"}function sx(){return pt(jf,nx)??"name"}function Lf(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:jt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function ax(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function wl(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Pf(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function kl(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function Ru(r){const n=pt(r,kl);return n?new Set(n):new Set}function Qi(r,n){Lt(r,[...n])}function ox(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function ix(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||kl(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(ox))&&(n.commits===void 0||kl(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 lx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&ix(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function cx(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(lx))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.repoIncludeUncommitted===void 0||!!s.repoIncludeUncommitted&&typeof s.repoIncludeUncommitted=="object"&&!Array.isArray(s.repoIncludeUncommitted)&&Object.values(s.repoIncludeUncommitted).every(l=>typeof l=="boolean"))&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Cu(){return pt(Rf,cx)??{}}function Nu(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function Eu(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Af(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||Eu(s)===Eu(l)}function Mu(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!Af(l,n))??""}function Sl(r,n){const s=Math.max(ku,n-320),l=Math.min(Kb,s);return Math.min(l,Math.max(ku,r))}function dx(r){return typeof r=="number"&&Number.isFinite(r)}function ux(r){return Sl(pt(Ys,dx)??yl,r)}function Tf(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function Gs(r){return Yb.has(Tf(r))}function If(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function jl(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||If(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Df(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const Ff=a.createContext(null);function xo(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function _f(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function Bf(r){return r.replace(/\s+#+\s*$/,"").trim()}function Rl(r,n){const l=_f(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",d=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,d+1),d===0?l:`${l}-${d}`}function $u(r){return _f(r)||r.trim()}function Co(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Nl(n[2]);return s?{id:xo(n[1]),definition:{href:s.href,title:s.title}}:null}function fx(r){const n=new Map;for(const s of r){const l=Co(s);l&&n.set(l.id,l.definition)}return n}function Of(r){return r.trim().toLowerCase()}function Uf(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Of(n[1]),text:n[2]}:null}function hx(r){const n=new Map;let s=null;for(const l of r){const d=Uf(l);if(d){s=d.id,n.set(d.id,{id:d.id,text:d.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 Hf(r){const n=new Set;let s=!1;return r.forEach((l,d)=>{if(Uf(l)){n.add(d),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(d);return}l.trim()&&(s=!1)}),n}function mx(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const d=r[s].trim();if(d.startsWith("<!--")){if(n[s]="",!d.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function zf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Zs(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function Il(r,n,s){const l=r.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const d=l.indexOf("#"),c=d>=0?l.slice(0,d):l,m=d>=0?l.slice(d+1):"",g=c.split("?",1)[0];if(!g)return null;let f,p=null;try{f=decodeURIComponent(g),p=m?decodeURIComponent(m):null}catch{return null}const x=s?Zs(s):null;let h;if(f.startsWith("/")){const b=x&&(f===x||f.startsWith(`${x}/`));h=Zs(x&&!b?`${x}/${f.slice(1)}`:f)}else{if(!n)return null;h=Zs(`${zf(n)}/${f}`)}return x&&h!==x&&!h.startsWith(`${x}/`)?null:{path:h,fragment:p,directory:/\/$/.test(g)}}function Dl(r,n,s,l,d){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let m;if(c.startsWith("/")){const g=s&&(c===s||c.startsWith(`${s}/`));m=Zs(s&&!g?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;m=Zs(`${zf(n)}/${c}`)}return d(m)}function px(r,n,s){return Dl(r,n,s,$l,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function gx(r,n,s){return Dl(r,n,s,Wu,Gu)}const Cl=128,bx=360,Zi=480;function ia(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function Wf(r,n,s,l,d=0){if(!n||!s)return null;let c,m;return d>0?(c=l>0?Math.min(d,l):d,m=s*c/n):ia(r)?(m=Math.min(Math.max(s,Cl),bx),c=n*m/s):(c=n,m=s),l>0&&c>l&&(m=m*l/c,c=l),m>Zi&&(c=c*Zi/m,m=Zi),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(m))}}function xx(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Gf(r){const n=xx(r),s=Q(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function vx({src:r,alt:n,title:s,requestedWidthPx:l}){const d=ia(r),c=Gf(r),m=Ao(c),g=a.useRef(null),[f,p]=a.useState(!1),[x,h]=a.useState(0),[b,E]=a.useState({status:"loading"}),[S,T]=a.useState(null);a.useLayoutEffect(()=>{const M=g.current;let N=M?.parentElement?.parentElement??M?.parentElement;for(;N;){const j=window.getComputedStyle(N).display;if(j!=="inline"&&j!=="contents")break;N=N.parentElement}if(!N)return;const P=N,B=()=>{const j=window.getComputedStyle(P),o=(parseFloat(j.paddingLeft)||0)+(parseFloat(j.paddingRight)||0);h(Math.max(0,P.clientWidth-o))};if(B(),typeof ResizeObserver>"u")return;const q=new ResizeObserver(B);return q.observe(P),()=>q.disconnect()},[]),a.useEffect(()=>{if(f)return;const M=g.current;if(!M||typeof IntersectionObserver>"u"){p(!0);return}const N=new IntersectionObserver(P=>{P.some(B=>B.isIntersecting)&&(p(!0),N.disconnect())},{rootMargin:"400px"});return N.observe(M),()=>N.disconnect()},[f]),a.useEffect(()=>{if(!f)return;const M=new AbortController;let N=null;E({status:"loading"});const P=window.setTimeout(()=>{M.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Ku(c,{signal:M.signal}).then(async B=>{if(!B.ok)throw new Error(`HTTP ${B.status}`);const q=Number(B.headers.get("X-Image-Width"))||0,j=Number(B.headers.get("X-Image-Height"))||0;return{blob:await B.blob(),width:q,height:j}}).then(({blob:B,width:q,height:j})=>{M.signal.aborted||(N=URL.createObjectURL(B),q>0&&j>0&&T({width:q,height:j}),E({status:"ready",objectUrl:N}))}).catch(()=>{const B=M.signal.reason;M.signal.aborted&&!(B instanceof DOMException&&B.name==="TimeoutError")||E({status:"fallback"})}).finally(()=>{window.clearTimeout(P)}),()=>{window.clearTimeout(P),M.abort(),N&&URL.revokeObjectURL(N)}},[f,c]);const D=Wf(r,S?.width??0,S?.height??0,x,l??0),F=D??(l?{width:x>0?Math.min(l,x):l,height:Math.round(l*.75)}:{width:Cl*2,height:Cl});return e.jsx("div",{ref:g,className:"block max-w-full",style:D?{width:D.width,height:D.height}:void 0,children:b.status==="ready"?e.jsx("img",{src:b.objectUrl,alt:n,title:s,decoding:"async",className:`${d?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:D?{width:D.width,height:D.height}:void 0,onLoad:M=>{const N=M.currentTarget;N.naturalWidth>0&&N.naturalHeight>0&&(S?.width!==N.naturalWidth||S?.height!==N.naturalHeight)&&T({width:N.naturalWidth,height:N.naturalHeight})}}):b.status==="fallback"?e.jsx("img",{src:m,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:D?{width:D.width,height:D.height}:void 0,onLoad:M=>{const N=M.currentTarget;N.naturalWidth>0&&N.naturalHeight>0&&(S?.width!==N.naturalWidth||S?.height!==N.naturalHeight)&&T({width:N.naturalWidth,height:N.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:F.width,height:F.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function ea(r,n,s,l,d,c){const m=px(s,d.markdownFilePath,d.rootPath);if(!m)return c?.fallbackText??`![${n}](${s})`;const g=d.images.length;d.images.push({kind:"image",src:m,alt:n,title:l});const f=e.jsx(vx,{src:m,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return d.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:p=>{p.stopPropagation(),d.onImageOpen?.(g)},children:f},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:f},r)}function el(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Lu(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function Nl(r){const n=r.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const Kf="",yx=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function wx(r){return r.replace(yx,(n,s)=>`${Kf}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Pu(r){return r.replace(new RegExp(`${Kf}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function kx(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const qf={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 lo=null;function Vf(){return lo||(lo=Mn(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw lo=null,r})),lo}function Yf({html:r}){const{t:n}=ft(),[s,l]=a.useState(null);return a.useEffect(()=>{let d=!1;return l(null),Vf().then(c=>{d||l(c.sanitize(r,qf))}).catch(()=>{d||l("")}),()=>{d=!0}},[r]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function Sx({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Vf().then(d=>{l||s(d.sanitize(r,qf))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function Xf(r){const n=r.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(r)}}let co=null;function jx(){return co||(co=Promise.all([Mn(()=>import("./katex-DnlPpQZa.js"),[]),Mn(()=>Promise.resolve({}),__vite__mapDeps([21]))]).then(([r])=>r.default??r).catch(r=>{throw co=null,r})),co}function sa({tex:r,display:n=!1}){const[s,l]=a.useState(null),[d,c]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),c(!1),jx().then(f=>{g||l(f.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||c(!0)}),()=>{g=!0}},[n,r]),d)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const m=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:m,dangerouslySetInnerHTML:{__html:s}})}function Fl(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function Au(r){const n=Fl(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Rx(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=Fl(s),d=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),m=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:d,fallbackText:g,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(m)}}function Cx({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:d}=ft(),[c,m]=a.useState(!1),g=Ao(r,()=>m(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||d("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>m(!0)})}):null}function Nx(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const m=r.slice(0,r.indexOf(">")+1),g=Fl(m).get("href")?.trim()??"",f=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:p,alt:x,title:h,widthPx:b}=Au(f);if(!p)return null;const E=Dl(p,s.markdownFilePath,s.rootPath,$l,M=>M);if(!E)return null;const S=g?Il(g,s.markdownFilePath,s.rootPath):null,D=!!!(S&&S.path===E)&&g?Df(g):null,F=ea(n,x??"",p,h,s,{requestedWidthPx:b,interactive:D?!1:void 0});return D?e.jsx("a",{href:D,target:"_blank",rel:"noreferrer",children:F},n):F}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:m,alt:g,title:f,widthPx:p}=Au(r);return m?ea(n,g??"",m,f,s,{fallbackText:r,requestedWidthPx:p}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:m,fallbackText:g,widthPx:f,controls:p}=Rx(r);if(!m)return null;const x=gx(m,s.markdownFilePath,s.rootPath);return x?e.jsx(Cx,{url:x,fallbackText:g,widthPx:f,hasControls:p},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(r)?e.jsx(Sx,{html:r},n):null;const d=l[1].toLowerCase(),c=ut(l[2],`${n}-${d}`,!0,s);return d==="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):d==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):d==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function ut(r,n,s=!0,l){return l.budget.nested(()=>Ex(r,n,s,l))}function Ex(r,n,s=!0,l){l.budget.validateInline(r);const d=wx(r),c=[];let m=0;for(const{index:g,token:f}of lg(d,l.budget)){g>m&&c.push(Pu(d.slice(m,g)));const p=`${n}-${g}`,x=f.startsWith("<")?Nx(f,p,l):null;if(x)c.push(x);else if(f.startsWith("\\(")&&f.endsWith("\\)"))c.push(e.jsx(sa,{tex:f.slice(2,-2)},p));else if(f.startsWith("$")&&f.endsWith("$"))c.push(e.jsx(sa,{tex:f.slice(1,-1)},p));else if(f.startsWith("`")){const h=f.match(/^`+/)?.[0].length??1;c.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:kx(f.slice(h,-h))},p))}else if(f.startsWith("~~"))c.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ut(f.slice(2,-2),`${p}-del`,s,l)},p));else if(f.startsWith("**")||f.startsWith("__"))c.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ut(f.slice(2,-2),`${p}-strong`,s,l)},p));else if(f.startsWith("*")||f.startsWith("_"))c.push(e.jsx("em",{className:"italic",children:ut(f.slice(1,-1),`${p}-em`,s,l)},p));else if(f.startsWith("![")){const h=f.match(/^!\[([^\]]*)\]\((.*)\)$/),b=f.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),E=f.match(/^!\[([^\]]+)\]$/);if(h){const S=Nl(h[2]);c.push(S?ea(p,h[1],S.href,S.title,l):f)}else if(b){const S=b[2]||b[1],T=l.referenceDefinitions.get(xo(S));c.push(T?ea(p,b[1],T.href,T.title,l):f)}else if(E){const S=l.referenceDefinitions.get(xo(E[1]));c.push(S?ea(p,E[1],S.href,S.title,l):f)}else c.push(f)}else if(f.startsWith("[^")){const h=Of(f.slice(2,-1)),b=l.footnoteDefinitions.get(h);c.push(b?e.jsx("sup",{id:`fnref-${b.id}`,title:b.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${b.id}`,className:"text-primary no-underline",children:b.index})},p):f)}else if(f.startsWith("<http")){const h=f.slice(1,-1);c.push(e.jsx("a",{href:h,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p))}else if(f.startsWith("<")&&f.endsWith(">")&&Lu(f.slice(1,-1))){const h=f.slice(1,-1);c.push(e.jsx("a",{href:`mailto:${h}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p))}else if(Lu(el(f).linkText)){const{linkText:h,suffix:b}=el(f);c.push(e.jsx("a",{href:`mailto:${h}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p)),b&&c.push(b)}else if(f.startsWith("http")||f.startsWith("www.")){const{linkText:h,suffix:b}=el(f),E=h.startsWith("www.")?`https://${h}`:h;c.push(e.jsx("a",{href:E,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p)),b&&c.push(b)}else{const h=f.match(/^\[([^\]]+)\]\((.*)\)$/),b=f.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),E=f.match(/^\[([^\]]+)\]$/),S=b?b[2]||b[1]:E?.[1]??null,T=S?l.referenceDefinitions.get(xo(S)):null,D=h?Nl(h[2]):null,F=D?.href??T?.href??null,M=F?Df(F):null,N=h?.[1]??b?.[1]??E?.[1]??"";c.push(M?e.jsx("a",{href:M,title:D?.title??T?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ut(N,`${p}-link`,s,l)},p):f)}m=g+f.length}return m<d.length&&c.push(Pu(d.slice(m))),c.length>0?c:[r]}function Jf(r){return/(?: {2,}|\\)$/.test(r)}function Qf(r){return r.replace(/(?: {2,}|\\)$/,"")}function No(r){return/^(?: {4}|\t)/.test(r)}function Zf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function eh(r,n,s){const l=[];return r.forEach((d,c)=>{const m=Jf(d);l.push(...ut(Qf(d),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(m?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function El(r,n,s){const l=[],d=[];return r.forEach((c,m)=>{d.push(Jf(c)),l.push(ut(Qf(c),`${n}-${m}`,!0,s))}),{perLine:l,hardBreaks:d}}function Ml(r,n,s,l,d){const c=[];return r.forEach((m,g)=>{const f=s[g]??0,p=!!(d&&f>=d.start&&f<=d.end);c.push(e.jsx("span",{"data-md-ref-start":f,"data-md-ref-end":f,"data-selected":p?"true":void 0,children:m},`${l}-ref-${g}`)),g<r.length-1&&c.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),c}function aa(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",d=!1,c=0,m=0;for(let g=0;g<n.length;g+=1){const f=n[g];if(d){l+=f,d=!1;continue}if(f==="\\"){d=!0;continue}if(f==="`"){const p=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const x=g-p+1;l+="`".repeat(x),c===0?c=x:c===x&&(c=0);continue}if(c===0&&f==="["?m+=1:c===0&&f==="]"&&m>0&&(m-=1),f==="|"&&c===0&&m===0){s.push(l.trim()),l="";continue}l+=f}return d&&(l+="\\"),s.push(l.trim()),s}function th(r){return aa(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Eo(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function Mo(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function rh(r,n){return r>96||r>44&&n>.35}function Io(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function oa(r){const n=r.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function _l(r,n,s,l,d,c=new Set){const m=[],g=[];let f=n;for(;f<r.length;){const p=r[f];if(d&&(Co(p)||c.has(f))){f+=1;continue}const x=oa(p),h=Io(p);if(!x){if(h>s&&g.length>0){([...g].reverse().find(T=>T.indent<h)?.item??g[g.length-1].item).paragraphs.push(p.trim());for(const T of g)T.item.lineEnd=f+1;f+=1;continue}break}if(h<s||h===s&&x.ordered!==l)break;const b={content:x.content,ordered:x.ordered,start:x.start,children:[],paragraphs:[],lineStart:f+1,lineEnd:f+1};for(;g.length>0&&g[g.length-1].indent>=h;)g.pop();const E=g[g.length-1]?.item??null;E?E.children.push(b):m.push(b),g.push({indent:h,item:b});for(const S of g)S.item.lineEnd=f+1;f+=1}return{items:m,nextIndex:f}}function Mx(r){const n=r.find(l=>oa(l));if(!n)return[];const s=oa(n);return s?_l(r,0,Io(n),s.ordered,!0,Hf(r)).items:[]}function Bl(r,n,s,l=0){return s.budget.nested(()=>$x(r,n,s,l))}function $x(r,n,s,l=0){return r.map((d,c)=>{const m=d.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!m,refStart:d.lineStart+l,refEnd:d.lineEnd+l,content:e.jsxs(e.Fragment,{children:[m?e.jsx("input",{type:"checkbox",checked:m[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,ut(m?.[2]??d.content,`li-${n}-${c}`,!0,s),d.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:d.paragraphs.map((g,f)=>e.jsx("p",{children:ut(g,`li-${n}-${c}-p-${f}`,!0,s)},`paragraph-${f}`))})]}),groups:Lx(d.children,`${n}-${c}`,s,l)}})}function Lx(r,n,s,l=0){const d=[];for(const c of r){const m=d[d.length-1];m&&m.ordered===c.ordered?m.items.push(c):d.push({ordered:c.ordered,items:[c]})}return d.map((c,m)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:Bl(c.items,`${n}-g${m}`,s,l)}))}function Ol(r,n){return r.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&Px(s.groups,n)]},s.key)})}function Px(r,n){return r.map((s,l)=>{const d=s.ordered?"ol":"ul";return e.jsx(d,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Ol(s.items,n)},`nested-${l}`)})}function Ax(r){const n=Array.from(r.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[ut(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Tx(r,n,s,l){const d=[];let c=0;const m=g=>l?.[g]??g+1;for(;c<r.length;){s.budget.check();const g=r[c],f=g.trim();if(!f){c+=1;continue}if(/^<details>\s*$/i.test(f)){const F=c;let M="Details";const N=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const P=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);P?M=P[1].trim()||M:N.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),d.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:ut(M,`${n}-details-${F}-summary`,!0,s)}),N.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:eh(N,`${n}-details-${F}`,s)})]},`${n}-details-${F}`)});continue}const p=Xf(g);if(p){const F=[g],M=c;for(c+=1;c<r.length&&!p.selfContained&&!new RegExp(`</${p.tag}>`,"i").test(r[c]);)F.push(r[c]),c+=1;c<r.length&&!p.selfContained&&(F.push(r[c]),c+=1),d.push({kind:"static",node:e.jsx(Yf,{html:F.join(`
1639
- `)},`${n}-html-${M}`)});continue}const x=f.match(/^(```|~~~)\s*(.*)$/);if(x){const F=[],M=x[1],N=x[2]?.trim(),P=c;for(c+=1;c<r.length&&!r[c].trim().startsWith(M);)F.push(r[c]),c+=1;c<r.length&&(c+=1),N.toLowerCase()==="mermaid"?d.push({kind:"static",node:e.jsx(sh,{code:F.join(`
1640
- `),blockKey:`${n}-code-${P}`},`${n}-code-${P}`)}):["math","latex","tex"].includes(N.toLowerCase())?d.push({kind:"static",node:e.jsx(sa,{tex:F.join(`
1635
+ `,lo="/api/terminal/fs/preview/",jb=8*1024*1024,Rb=32*1024*1024,Nb=128,Cb="data:,";function $t(r){throw new Error(r)}function Eb(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function vu(r,n,s){let l="",d=0;for(const c of r.matchAll(n))l+=r.slice(d,c.index)+await s(c),d=c.index+c[0].length;return l+r.slice(d)}async function wf(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!Hs(l.pathname)?.startsWith(lo))&&$t("预览地址不是有效的本地文件入口");const d=crypto.randomUUID(),c=`https://termdock-preview.invalid/${d}/`,m=[],g=H=>{!m.includes(H)&&m.length<20&&m.push(H)},f=new Set,p=[],x=new Set,h=new Map,b=new Map;let E=0,S=!1;const T=new Set,D=()=>{S=!0;for(const H of[...T])H();f.clear(),p.length=0};async function F(H){H.ok||$t(`预览资源读取失败(${H.status})`);const ee=H.body?.getReader(),L=[];let U=0;try{if(ee)for(;;){const he=await ee.read();if(he.done)break;U+=he.value.byteLength,E+=he.value.byteLength,(U>jb||E>Rb)&&$t("预览资源超出大小限制"),L.push(he.value)}}catch(he){throw await ee?.cancel().catch(()=>{}),he}finally{ee?.releaseLock()}const X=new Uint8Array(U);let ce=0;for(const he of L)X.set(he,ce),ce+=he.length;return{bytes:X,type:H.headers.get("content-type")??"application/octet-stream",status:H.status}}let M=l,C;for(let H=0;H<4;H++){const ee=await n.fetch(M.pathname+M.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(ee.status)){C=ee;break}const L=ee.headers.get("location");await ee.body?.cancel(),L||$t("预览重定向缺少目标");const U=new URL(L,M);(U.origin!==s||!Hs(U.pathname)?.startsWith(lo))&&$t("预览重定向越出文件范围"),M=U}C||$t("预览重定向次数过多");const P=Hs(M.pathname),B=P.slice(lo.length).split("/");/^[a-f0-9]{32}$/.test(B[0])||$t("服务未提供有效的预览资源授权");const q=Hs(l.pathname).slice(lo.length).split("/");/^[a-f0-9]{32}$/.test(q[0])&&q.shift(),q.join("/").replace(/\/$/,"")!==B.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const j=P.endsWith("/")?P:P.slice(0,P.lastIndexOf("/")+1),o=new URL(M.pathname.endsWith("/")?M.pathname:M.pathname.slice(0,M.pathname.lastIndexOf("/")+1),s);function _(H,ee){const L=new URL(H,ee);return L.origin!==s?null:(Hs(L.pathname)?.startsWith(j)||$t("已阻止预览访问目录之外的资源"),L)}function I(H){const ee=new URL(H,c);(ee.origin!==new URL(c).origin||!ee.pathname.startsWith(new URL(c).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const L=ee.pathname.slice(new URL(c).pathname.length)+ee.search;return _(L,o)??$t("预览资源无效")}function V(H){const ee=H.pathname+H.search,L=h.get(ee);if(L)return L;if(S||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(h.size>=Nb)return Promise.reject(new Error("预览资源数量超出限制"));const U=n.fetch(ee,{signal:n.signal,redirect:"manual"}).then(F);return h.set(ee,U),U}function W(H,ee){S&&$t("预览已关闭");const L=`termdock-resource-${d}-${p.length}`;return p.push({token:L,data:H,type:ee}),f.add(L),L}async function O(H,ee,L,U=new Set){if(!H||H.startsWith("#")||/^data:(?:image|font)\//i.test(H)&&L==="resource")return H;try{const X=_(H,ee);if(!X){const $e=new URL(H,ee);return($e.protocol!=="https:"||$e.username||$e.password||$e.origin===new URL(c).origin)&&$t("已阻止不安全的外部资源"),x.add($e.origin),$e.href}const ce=`${L}:${X.href}`;(U.has(ce)||U.size>=8)&&$t("预览资源存在循环或过深引用");const he=b.get(ce);if(he)return he;const Re=new Set(U);Re.add(ce);const Ne=(async()=>{const $e=await V(X);return L==="css"?W(await R(new TextDecoder().decode($e.bytes),X,Re),"text/css"):L==="script"?W($e.bytes,"text/javascript"):W($e.bytes,$e.type)})();return b.set(ce,Ne),await Ne}catch(X){return g(X instanceof Error?X.message:"部分预览资源未能加载"),Cb}}async function R(H,ee,L){return H=await vu(H,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async U=>`@import url("${await O(U[1],ee,"css",L)}")${U[2]};`),vu(H,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async U=>{const X=(U[1]??U[2]??U[3]).trim();return f.has(X)?U[0]:`url("${await O(X,ee,"resource",L)}")`})}try{const H=await F(C),ee=W(kb,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(H.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(Q=>Q.remove());for(const Q of L.querySelectorAll("*")){if(Q.removeAttribute("ping"),Q.removeAttribute("srcdoc"),Q.hasAttribute("style")&&Q.setAttribute("style",await R(Q.getAttribute("style"),M,new Set)),Q.tagName==="STYLE"&&(Q.textContent=await R(Q.textContent??"",M,new Set)),Q.tagName==="A"||Q.tagName==="AREA"){const xe=Q.getAttribute("href");try{if(xe&&!xe.startsWith("#")){const fe=_(xe,M);if(fe)Q.setAttribute("href",new URL(fe.pathname.slice(o.pathname.length)+fe.search+fe.hash,c).href);else{const Fe=new URL(xe,M);if(Fe.protocol!=="https:"){Q.removeAttribute("href");continue}x.add(Fe.origin),Q.setAttribute("href",Fe.href)}}}catch(fe){Q.removeAttribute("href"),g(fe instanceof Error?fe.message:"预览链接无法加载")}}for(const xe of["data","manifest"])Q.removeAttribute(xe);if(Q.tagName==="SCRIPT"&&Q.getAttribute("type")==="module"){Q.setAttribute("type","module-shim");const xe=Q.getAttribute("src");if(xe){const fe=_(xe,M);if(fe)Q.setAttribute("src",new URL(fe.pathname.slice(o.pathname.length)+fe.search,c).href);else{const Fe=new URL(xe,M);if(Fe.protocol!=="https:"){Q.remove();continue}x.add(Fe.origin),Q.setAttribute("src",Fe.href)}}continue}if(Q.tagName==="SCRIPT"&&Q.getAttribute("type")==="importmap"){Q.setAttribute("type","importmap-shim");continue}if(Q.tagName==="LINK"){const xe=(Q.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(xe)){Q.remove();continue}const fe=Q.getAttribute("href");fe&&Q.setAttribute("href",await O(fe,M,xe==="stylesheet"?"css":"resource"))}if(Q.hasAttribute("src")&&Q.setAttribute("src",await O(Q.getAttribute("src"),M,Q.tagName==="SCRIPT"?"script":"resource")),Q.hasAttribute("poster")&&Q.setAttribute("poster",await O(Q.getAttribute("poster"),M,"resource")),Q.hasAttribute("srcset")){const xe=Q.getAttribute("srcset");/data:/i.test(xe)?(Q.removeAttribute("srcset"),g("混合内嵌图片候选暂不支持安全预览")):Q.setAttribute("srcset",(await Promise.all(xe.split(",").map(async fe=>{const[Fe,...Oe]=fe.trim().split(/\s+/);return`${await O(Fe,M,"resource")} ${Oe.join(" ")}`}))).join(", "))}Q.setAttribute("referrerpolicy","no-referrer"),Q.removeAttribute("integrity"),Q.removeAttribute("crossorigin")}const U=[...x].join(" "),X=L.createElement("meta");X.httpEquiv="Content-Security-Policy",X.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${U}; style-src 'unsafe-inline' blob: ${U}; img-src blob: data: ${U}; font-src blob: data: ${U}; media-src blob: data: ${U}; connect-src blob: ${U} ${[...x].map(Q=>Q.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const ce=L.createElement("base");ce.href=c;const he=L.createElement("meta");he.name="referrer",he.content="no-referrer";const Re=L.createElement("script");Re.textContent=Sb+`
1636
+ installPreviewRuntime(`+[d,c,[...x],ee].map(Eb).join(",")+");";const Ne=L.createElement("script");Ne.src=ee,L.head.prepend(X,he,ce,Re,Ne);const $e=`<!doctype html>
1637
+ `+L.documentElement.outerHTML;return{html:$e,shellUrl:`/preview-shell.html#${d}`,errors:m,attach(Q,xe){const fe=new Set,Fe=G=>{if(G.source!==Q.contentWindow||G.data?.capability!==d)return;if(G.data.type==="preview-ready"){Q.contentWindow?.postMessage({type:"preview-init",capability:d,html:$e,resources:p},"*");return}if(G.data.type==="preview-error"){xe("部分动态内容被安全预览限制");return}if(G.data.type==="preview-navigate"){(async()=>{const Se=I(String(G.data.url)),de=await wf(Se.pathname+Se.search,n);if(S){de.dispose();return}const qe=de.attach(Q,xe);T.add(()=>{qe(),de.dispose()}),Q.src=de.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Se=>xe(Se instanceof Error?Se.message:"无法打开预览页面"));return}if(G.data.type==="preview-external"){try{const Se=new URL(String(G.data.url));Se.protocol==="https:"&&x.has(Se.origin)&&window.open(Se.href,"_blank","noopener,noreferrer")}catch{}return}if(G.data.type!=="preview-fetch"||G.ports.length!==1)return;const Ce=G.ports[0];if(fe.size>=8||!["GET","HEAD"].includes(G.data.method)){Ce.postMessage({error:"预览仅允许读取已授权目录资源"}),Ce.close();return}fe.add(Ce),(async()=>{const Se=I(String(G.data.url)),de=await V(Se);if(!fe.has(Ce)||S)return;const qe=G.data.method==="HEAD"?new Uint8Array:de.bytes.slice();Ce.postMessage({status:de.status,headers:{"content-type":de.type},data:qe.buffer},[qe.buffer])})().catch(()=>{Ce.postMessage({error:"预览资源不在授权范围或无法加载"}),xe("部分动态资源不可用或超出预览目录")}).finally(()=>{fe.delete(Ce),Ce.close()})};window.addEventListener("message",Fe);const Oe=()=>{window.removeEventListener("message",Fe);for(const G of fe)G.close();fe.clear(),T.delete(Oe)};return T.add(Oe),Oe},dispose:D}}catch(H){throw D(),H}}const Mb=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:d},c){const m=a.useRef(null),[g,f]=a.useState(null),[p,x]=a.useState(),[h,b]=a.useState("");a.useEffect(()=>{const P=new AbortController;let B;return x(void 0),b(""),(async()=>{const q=await Om();if(B=await wf(n,{fetch:(j,o)=>q.fetch(j,o),signal:P.signal}),P.signal.aborted){B.dispose();return}x(B),B.errors.length&&b(B.errors.join(";"))})().catch(q=>{P.signal.aborted||b(q instanceof Error?q.message:"安全预览加载失败")}),()=>{P.abort(),B?.dispose()}},[n]),a.useEffect(()=>{if(!(!p||!g))return p.attach(g,b)},[p,g]);const[E,S]=a.useState(!1),[T,D]=a.useState(!1),F=E||T;a.useEffect(()=>{d?.(F)},[F,d]),a.useEffect(()=>{const P=()=>{S(document.fullscreenElement===m.current)};return document.addEventListener("fullscreenchange",P),()=>document.removeEventListener("fullscreenchange",P)},[]),a.useEffect(()=>{if(!T)return;const P=B=>{B.key==="Escape"&&D(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[T]);const M=a.useCallback(async()=>{const P=m.current;if(P){if(T){D(!1);return}if(document.fullscreenElement===P){await document.exitFullscreen();return}if(P.requestFullscreen&&document.fullscreenEnabled!==!1)try{await P.requestFullscreen();return}catch{}D(!0)}},[T]);a.useImperativeHandle(c,()=>({toggleFullscreen:M}),[M]);const C=e.jsxs("div",{ref:m,"data-html-preview-frame":!0,className:F?"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:[F&&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:()=>{M()},"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(lf,{size:15})})]}),h&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:h}),!p&&!h&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:f,src:p?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return T?Rr.createPortal(C,document.body):C}),kf="termdock-file-search-match",wl="termdock-file-search-current";function $b(r,n,s){return!!(n&&r?.isConnected&&!s.defaultPrevented&&!r.closest('[inert], [aria-hidden="true"], [hidden]')&&s.target instanceof Node&&r.contains(s.target))}function Lb(r){const n=r.metaKey||r.ctrlKey,s=r.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||r.key==="F3"?r.shiftKey?"previous":"next":r.key==="Escape"?"close":null}function Pb(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Ab(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let d="",c=null;const m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let x=m.nextNode();x;x=m.nextNode()){if(!(x instanceof Text)||!x.data)continue;const h=Pb(x);if(!h)continue;c&&c!==h&&(d+=`
1638
+ `);const b=d.length;d+=x.data,l.push({node:x,start:b,end:d.length,group:h}),c=h}const g=d.toLocaleLowerCase(),f=[];let p=0;for(;p<=g.length-s.length;){const x=g.indexOf(s,p);if(x<0)break;const h=x+s.length,b=l.find(S=>S.start<=x&&S.end>x),E=l.find(S=>S.start<h&&S.end>=h);if(b&&E&&b.group===E.group){const S=document.createRange();S.setStart(b.node,x-b.start),S.setEnd(E.node,h-E.start),f.push(S)}p=x+Math.max(s.length,1)}return f}function Sf(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}let Ro;function yu(r){return Ro===r}function co(r){if(r&&Ro!==r)return;const n=Sf();n?.delete(kf),n?.delete(wl),Ro=void 0}function Yi(r,n,s){const l=Sf();if(!l||typeof Highlight>"u")return;Ro=s,l.set(kf,new Highlight(...r));const d=r[n];d?l.set(wl,new Highlight(d)):l.delete(wl)}function wu(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Tb(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Ib(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Db(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function jf(r,n,s){return n?r:Rr.createPortal(r,s)}const Tl="termdock:right-sidebar:file-tree-scroll:v1",Il="termdock:right-sidebar:file-preview-reading-state:v1",Js="termdock:right-sidebar:file-tree-width:v1",Rf="termdock:right-sidebar:markdown-view-mode:v1",Nf="termdock:right-sidebar:diff-change-list-mode:v1",Cf="termdock:right-sidebar:diff-wrap:v1",Ef="termdock:diff-viewer:view-type:v1",Mf="termdock:right-sidebar:file-search-mode:v1",Xi="termdock:right-sidebar:collapsed-git-repo-groups:v1",ku="termdock:right-sidebar:collapsed-diff-directories:v1",Ji="termdock:right-sidebar:branch-audit-module-open:v1",$f="termdock:right-sidebar:branch-audit-module:v1",Fb=150,Su="termdock:right-sidebar:context-draft-enabled:v1",ju="termdock:right-sidebar:context-draft-collapsed:v1",Ru="termdock:right-sidebar:context-draft-auto-collapse:v1",Qi="termdock:right-sidebar:context-draft-text:v1",_b=300,Bb=20,Ob=120,Ub=250,Hb=250,zb=120,Wb=700,Zi=600,Gb=6e4;function Gs(r){return!!(r&&J.getState().nestedGitScanRoots[r])}const Nu=[2e3,5e3,15e3,3e4],Kb=320,qb=500,Vb=20,Yb=12e3,kl=300,Cu=240,Xb=560,Lf="border-r px-2 py-1.5 sm:px-3 sm:py-2",No="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Pf=`${Lf} border-b border-border/15 font-semibold last:border-r-0`,Af=`${Lf} border-border/10 align-top text-muted-foreground last:border-r-0`,Dl="termdock-file-preview-horizontal-scroll",Eu=a.lazy(()=>$n(()=>import("./ModelPreview-Bzdi_sPh.js"),__vite__mapDeps([7,1,2,3,4,5,8,9,10,11,12,13,14,15,16,17]))),Jb=a.lazy(()=>$n(()=>import("./ArchitecturePanel-CdgUQsVD.js"),__vite__mapDeps([18,1,2,3,4,5,8,9,10,11,12,15,16,6,14,13,17,19])).then(r=>({default:r.ArchitecturePanel}))),Qb=a.lazy(()=>$n(()=>import("./ComputerControlView-B5Yng8Dt.js").then(r=>r.C),__vite__mapDeps([20,1,2,3,4,5,17,14,11,8,9,10,12]))),Tf=`${Dl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function If(r,n,s){return r&&!n?"unified":s}const Zb=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function ex(r){return r==="preview"||r==="source"}function tx(r){return r==="list"||r==="tree"||r==="ai"}function Mu(){return pt(Rf,ex)??"preview"}function rx(){return pt(Nf,tx)??"tree"}function Qs(r){return typeof r=="boolean"}function nx(r){return typeof r=="string"}function sx(){return pt(Cf,Qs)??!0}function ax(r){return r==="unified"||r==="split"}function ox(){return pt(Ef,ax)??"unified"}function ix(r){return r==="name"||r==="content"||r==="regex"}function lx(){return pt(Mf,ix)??"name"}function Df(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:jt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function cx(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function Sl(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Ff(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function jl(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function $u(r){const n=pt(r,jl);return n?new Set(n):new Set}function el(r,n){Lt(r,[...n])}function dx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function ux(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||jl(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(dx))&&(n.commits===void 0||jl(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 fx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&ux(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function hx(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(fx))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.repoIncludeUncommitted===void 0||!!s.repoIncludeUncommitted&&typeof s.repoIncludeUncommitted=="object"&&!Array.isArray(s.repoIncludeUncommitted)&&Object.values(s.repoIncludeUncommitted).every(l=>typeof l=="boolean"))&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Lu(){return pt($f,hx)??{}}function Pu(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function Au(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function _f(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||Au(s)===Au(l)}function Tu(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!_f(l,n))??""}function Rl(r,n){const s=Math.max(Cu,n-320),l=Math.min(Xb,s);return Math.min(l,Math.max(Cu,r))}function mx(r){return typeof r=="number"&&Number.isFinite(r)}function px(r){return Rl(pt(Js,mx)??kl,r)}function Bf(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function Ks(r){return Zb.has(Bf(r))}function Of(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Nl(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||Of(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Uf(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const Hf=a.createContext(null);function vo(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function zf(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function Wf(r){return r.replace(/\s+#+\s*$/,"").trim()}function Cl(r,n){const l=zf(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",d=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,d+1),d===0?l:`${l}-${d}`}function Iu(r){return zf(r)||r.trim()}function Co(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ml(n[2]);return s?{id:vo(n[1]),definition:{href:s.href,title:s.title}}:null}function gx(r){const n=new Map;for(const s of r){const l=Co(s);l&&n.set(l.id,l.definition)}return n}function Gf(r){return r.trim().toLowerCase()}function Kf(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Gf(n[1]),text:n[2]}:null}function bx(r){const n=new Map;let s=null;for(const l of r){const d=Kf(l);if(d){s=d.id,n.set(d.id,{id:d.id,text:d.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 qf(r){const n=new Set;let s=!1;return r.forEach((l,d)=>{if(Kf(l)){n.add(d),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(d);return}l.trim()&&(s=!1)}),n}function xx(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const d=r[s].trim();if(d.startsWith("<!--")){if(n[s]="",!d.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Vf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function ta(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function Fl(r,n,s){const l=r.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const d=l.indexOf("#"),c=d>=0?l.slice(0,d):l,m=d>=0?l.slice(d+1):"",g=c.split("?",1)[0];if(!g)return null;let f,p=null;try{f=decodeURIComponent(g),p=m?decodeURIComponent(m):null}catch{return null}const x=s?ta(s):null;let h;if(f.startsWith("/")){const b=x&&(f===x||f.startsWith(`${x}/`));h=ta(x&&!b?`${x}/${f.slice(1)}`:f)}else{if(!n)return null;h=ta(`${Vf(n)}/${f}`)}return x&&h!==x&&!h.startsWith(`${x}/`)?null:{path:h,fragment:p,directory:/\/$/.test(g)}}function _l(r,n,s,l,d){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let m;if(c.startsWith("/")){const g=s&&(c===s||c.startsWith(`${s}/`));m=ta(s&&!g?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;m=ta(`${Vf(n)}/${c}`)}return d(m)}function vx(r,n,s){return _l(r,n,s,Pl,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function yx(r,n,s){return _l(r,n,s,Yu,Xu)}const El=128,wx=360,tl=480;function ca(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function Yf(r,n,s,l,d=0){if(!n||!s)return null;let c,m;return d>0?(c=l>0?Math.min(d,l):d,m=s*c/n):ca(r)?(m=Math.min(Math.max(s,El),wx),c=n*m/s):(c=n,m=s),l>0&&c>l&&(m=m*l/c,c=l),m>tl&&(c=c*tl/m,m=tl),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(m))}}function kx(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Xf(r){const n=kx(r),s=J(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function Sx({src:r,alt:n,title:s,requestedWidthPx:l}){const d=ca(r),c=Xf(r),m=To(c),g=a.useRef(null),[f,p]=a.useState(!1),[x,h]=a.useState(0),[b,E]=a.useState({status:"loading"}),[S,T]=a.useState(null);a.useLayoutEffect(()=>{const M=g.current;let C=M?.parentElement?.parentElement??M?.parentElement;for(;C;){const j=window.getComputedStyle(C).display;if(j!=="inline"&&j!=="contents")break;C=C.parentElement}if(!C)return;const P=C,B=()=>{const j=window.getComputedStyle(P),o=(parseFloat(j.paddingLeft)||0)+(parseFloat(j.paddingRight)||0);h(Math.max(0,P.clientWidth-o))};if(B(),typeof ResizeObserver>"u")return;const q=new ResizeObserver(B);return q.observe(P),()=>q.disconnect()},[]),a.useEffect(()=>{if(f)return;const M=g.current;if(!M||typeof IntersectionObserver>"u"){p(!0);return}const C=new IntersectionObserver(P=>{P.some(B=>B.isIntersecting)&&(p(!0),C.disconnect())},{rootMargin:"400px"});return C.observe(M),()=>C.disconnect()},[f]),a.useEffect(()=>{if(!f)return;const M=new AbortController;let C=null;E({status:"loading"});const P=window.setTimeout(()=>{M.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Ju(c,{signal:M.signal}).then(async B=>{if(!B.ok)throw new Error(`HTTP ${B.status}`);const q=Number(B.headers.get("X-Image-Width"))||0,j=Number(B.headers.get("X-Image-Height"))||0;return{blob:await B.blob(),width:q,height:j}}).then(({blob:B,width:q,height:j})=>{M.signal.aborted||(C=URL.createObjectURL(B),q>0&&j>0&&T({width:q,height:j}),E({status:"ready",objectUrl:C}))}).catch(()=>{const B=M.signal.reason;M.signal.aborted&&!(B instanceof DOMException&&B.name==="TimeoutError")||E({status:"fallback"})}).finally(()=>{window.clearTimeout(P)}),()=>{window.clearTimeout(P),M.abort(),C&&URL.revokeObjectURL(C)}},[f,c]);const D=Yf(r,S?.width??0,S?.height??0,x,l??0),F=D??(l?{width:x>0?Math.min(l,x):l,height:Math.round(l*.75)}:{width:El*2,height:El});return e.jsx("div",{ref:g,className:"block max-w-full",style:D?{width:D.width,height:D.height}:void 0,children:b.status==="ready"?e.jsx("img",{src:b.objectUrl,alt:n,title:s,decoding:"async",className:`${d?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:D?{width:D.width,height:D.height}:void 0,onLoad:M=>{const C=M.currentTarget;C.naturalWidth>0&&C.naturalHeight>0&&(S?.width!==C.naturalWidth||S?.height!==C.naturalHeight)&&T({width:C.naturalWidth,height:C.naturalHeight})}}):b.status==="fallback"?e.jsx("img",{src:m,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:D?{width:D.width,height:D.height}:void 0,onLoad:M=>{const C=M.currentTarget;C.naturalWidth>0&&C.naturalHeight>0&&(S?.width!==C.naturalWidth||S?.height!==C.naturalHeight)&&T({width:C.naturalWidth,height:C.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:F.width,height:F.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function ra(r,n,s,l,d,c){const m=vx(s,d.markdownFilePath,d.rootPath);if(!m)return c?.fallbackText??`![${n}](${s})`;const g=d.images.length;d.images.push({kind:"image",src:m,alt:n,title:l});const f=e.jsx(Sx,{src:m,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return d.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:p=>{p.stopPropagation(),d.onImageOpen?.(g)},children:f},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:f},r)}function rl(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Du(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function Ml(r){const n=r.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const Jf="",jx=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Rx(r){return r.replace(jx,(n,s)=>`${Jf}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Fu(r){return r.replace(new RegExp(`${Jf}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Nx(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Qf={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 uo=null;function Zf(){return uo||(uo=$n(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw uo=null,r})),uo}function eh({html:r}){const{t:n}=ft(),[s,l]=a.useState(null);return a.useEffect(()=>{let d=!1;return l(null),Zf().then(c=>{d||l(c.sanitize(r,Qf))}).catch(()=>{d||l("")}),()=>{d=!0}},[r]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function Cx({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Zf().then(d=>{l||s(d.sanitize(r,Qf))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function th(r){const n=r.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(r)}}let fo=null;function Ex(){return fo||(fo=Promise.all([$n(()=>import("./katex-DnlPpQZa.js"),[]),$n(()=>Promise.resolve({}),__vite__mapDeps([21]))]).then(([r])=>r.default??r).catch(r=>{throw fo=null,r})),fo}function oa({tex:r,display:n=!1}){const[s,l]=a.useState(null),[d,c]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),c(!1),Ex().then(f=>{g||l(f.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||c(!0)}),()=>{g=!0}},[n,r]),d)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const m=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:m,dangerouslySetInnerHTML:{__html:s}})}function Bl(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function _u(r){const n=Bl(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Mx(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=Bl(s),d=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),m=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:d,fallbackText:g,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(m)}}function $x({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:d}=ft(),[c,m]=a.useState(!1),g=To(r,()=>m(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||d("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>m(!0)})}):null}function Lx(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const m=r.slice(0,r.indexOf(">")+1),g=Bl(m).get("href")?.trim()??"",f=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:p,alt:x,title:h,widthPx:b}=_u(f);if(!p)return null;const E=_l(p,s.markdownFilePath,s.rootPath,Pl,M=>M);if(!E)return null;const S=g?Fl(g,s.markdownFilePath,s.rootPath):null,D=!!!(S&&S.path===E)&&g?Uf(g):null,F=ra(n,x??"",p,h,s,{requestedWidthPx:b,interactive:D?!1:void 0});return D?e.jsx("a",{href:D,target:"_blank",rel:"noreferrer",children:F},n):F}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:m,alt:g,title:f,widthPx:p}=_u(r);return m?ra(n,g??"",m,f,s,{fallbackText:r,requestedWidthPx:p}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:m,fallbackText:g,widthPx:f,controls:p}=Mx(r);if(!m)return null;const x=yx(m,s.markdownFilePath,s.rootPath);return x?e.jsx($x,{url:x,fallbackText:g,widthPx:f,hasControls:p},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(r)?e.jsx(Cx,{html:r},n):null;const d=l[1].toLowerCase(),c=ut(l[2],`${n}-${d}`,!0,s);return d==="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):d==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):d==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function ut(r,n,s=!0,l){return l.budget.nested(()=>Px(r,n,s,l))}function Px(r,n,s=!0,l){l.budget.validateInline(r);const d=Rx(r),c=[];let m=0;for(const{index:g,token:f}of fg(d,l.budget)){g>m&&c.push(Fu(d.slice(m,g)));const p=`${n}-${g}`,x=f.startsWith("<")?Lx(f,p,l):null;if(x)c.push(x);else if(f.startsWith("\\(")&&f.endsWith("\\)"))c.push(e.jsx(oa,{tex:f.slice(2,-2)},p));else if(f.startsWith("$")&&f.endsWith("$"))c.push(e.jsx(oa,{tex:f.slice(1,-1)},p));else if(f.startsWith("`")){const h=f.match(/^`+/)?.[0].length??1;c.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:Nx(f.slice(h,-h))},p))}else if(f.startsWith("~~"))c.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ut(f.slice(2,-2),`${p}-del`,s,l)},p));else if(f.startsWith("**")||f.startsWith("__"))c.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ut(f.slice(2,-2),`${p}-strong`,s,l)},p));else if(f.startsWith("*")||f.startsWith("_"))c.push(e.jsx("em",{className:"italic",children:ut(f.slice(1,-1),`${p}-em`,s,l)},p));else if(f.startsWith("![")){const h=f.match(/^!\[([^\]]*)\]\((.*)\)$/),b=f.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),E=f.match(/^!\[([^\]]+)\]$/);if(h){const S=Ml(h[2]);c.push(S?ra(p,h[1],S.href,S.title,l):f)}else if(b){const S=b[2]||b[1],T=l.referenceDefinitions.get(vo(S));c.push(T?ra(p,b[1],T.href,T.title,l):f)}else if(E){const S=l.referenceDefinitions.get(vo(E[1]));c.push(S?ra(p,E[1],S.href,S.title,l):f)}else c.push(f)}else if(f.startsWith("[^")){const h=Gf(f.slice(2,-1)),b=l.footnoteDefinitions.get(h);c.push(b?e.jsx("sup",{id:`fnref-${b.id}`,title:b.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${b.id}`,className:"text-primary no-underline",children:b.index})},p):f)}else if(f.startsWith("<http")){const h=f.slice(1,-1);c.push(e.jsx("a",{href:h,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p))}else if(f.startsWith("<")&&f.endsWith(">")&&Du(f.slice(1,-1))){const h=f.slice(1,-1);c.push(e.jsx("a",{href:`mailto:${h}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p))}else if(Du(rl(f).linkText)){const{linkText:h,suffix:b}=rl(f);c.push(e.jsx("a",{href:`mailto:${h}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p)),b&&c.push(b)}else if(f.startsWith("http")||f.startsWith("www.")){const{linkText:h,suffix:b}=rl(f),E=h.startsWith("www.")?`https://${h}`:h;c.push(e.jsx("a",{href:E,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:h},p)),b&&c.push(b)}else{const h=f.match(/^\[([^\]]+)\]\((.*)\)$/),b=f.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),E=f.match(/^\[([^\]]+)\]$/),S=b?b[2]||b[1]:E?.[1]??null,T=S?l.referenceDefinitions.get(vo(S)):null,D=h?Ml(h[2]):null,F=D?.href??T?.href??null,M=F?Uf(F):null,C=h?.[1]??b?.[1]??E?.[1]??"";c.push(M?e.jsx("a",{href:M,title:D?.title??T?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ut(C,`${p}-link`,s,l)},p):f)}m=g+f.length}return m<d.length&&c.push(Fu(d.slice(m))),c.length>0?c:[r]}function rh(r){return/(?: {2,}|\\)$/.test(r)}function nh(r){return r.replace(/(?: {2,}|\\)$/,"")}function Eo(r){return/^(?: {4}|\t)/.test(r)}function sh(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function ah(r,n,s){const l=[];return r.forEach((d,c)=>{const m=rh(d);l.push(...ut(nh(d),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(m?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function $l(r,n,s){const l=[],d=[];return r.forEach((c,m)=>{d.push(rh(c)),l.push(ut(nh(c),`${n}-${m}`,!0,s))}),{perLine:l,hardBreaks:d}}function Ll(r,n,s,l,d){const c=[];return r.forEach((m,g)=>{const f=s[g]??0,p=!!(d&&f>=d.start&&f<=d.end);c.push(e.jsx("span",{"data-md-ref-start":f,"data-md-ref-end":f,"data-selected":p?"true":void 0,children:m},`${l}-ref-${g}`)),g<r.length-1&&c.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),c}function ia(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",d=!1,c=0,m=0;for(let g=0;g<n.length;g+=1){const f=n[g];if(d){l+=f,d=!1;continue}if(f==="\\"){d=!0;continue}if(f==="`"){const p=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const x=g-p+1;l+="`".repeat(x),c===0?c=x:c===x&&(c=0);continue}if(c===0&&f==="["?m+=1:c===0&&f==="]"&&m>0&&(m-=1),f==="|"&&c===0&&m===0){s.push(l.trim()),l="";continue}l+=f}return d&&(l+="\\"),s.push(l.trim()),s}function oh(r){return ia(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Mo(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function $o(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function ih(r,n){return r>96||r>44&&n>.35}function Do(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function la(r){const n=r.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function Ol(r,n,s,l,d,c=new Set){const m=[],g=[];let f=n;for(;f<r.length;){const p=r[f];if(d&&(Co(p)||c.has(f))){f+=1;continue}const x=la(p),h=Do(p);if(!x){if(h>s&&g.length>0){([...g].reverse().find(T=>T.indent<h)?.item??g[g.length-1].item).paragraphs.push(p.trim());for(const T of g)T.item.lineEnd=f+1;f+=1;continue}break}if(h<s||h===s&&x.ordered!==l)break;const b={content:x.content,ordered:x.ordered,start:x.start,children:[],paragraphs:[],lineStart:f+1,lineEnd:f+1};for(;g.length>0&&g[g.length-1].indent>=h;)g.pop();const E=g[g.length-1]?.item??null;E?E.children.push(b):m.push(b),g.push({indent:h,item:b});for(const S of g)S.item.lineEnd=f+1;f+=1}return{items:m,nextIndex:f}}function Ax(r){const n=r.find(l=>la(l));if(!n)return[];const s=la(n);return s?Ol(r,0,Do(n),s.ordered,!0,qf(r)).items:[]}function Ul(r,n,s,l=0){return s.budget.nested(()=>Tx(r,n,s,l))}function Tx(r,n,s,l=0){return r.map((d,c)=>{const m=d.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!m,refStart:d.lineStart+l,refEnd:d.lineEnd+l,content:e.jsxs(e.Fragment,{children:[m?e.jsx("input",{type:"checkbox",checked:m[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,ut(m?.[2]??d.content,`li-${n}-${c}`,!0,s),d.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:d.paragraphs.map((g,f)=>e.jsx("p",{children:ut(g,`li-${n}-${c}-p-${f}`,!0,s)},`paragraph-${f}`))})]}),groups:Ix(d.children,`${n}-${c}`,s,l)}})}function Ix(r,n,s,l=0){const d=[];for(const c of r){const m=d[d.length-1];m&&m.ordered===c.ordered?m.items.push(c):d.push({ordered:c.ordered,items:[c]})}return d.map((c,m)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:Ul(c.items,`${n}-g${m}`,s,l)}))}function Hl(r,n){return r.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&Dx(s.groups,n)]},s.key)})}function Dx(r,n){return r.map((s,l)=>{const d=s.ordered?"ol":"ul";return e.jsx(d,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Hl(s.items,n)},`nested-${l}`)})}function Fx(r){const n=Array.from(r.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[ut(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function _x(r,n,s,l){const d=[];let c=0;const m=g=>l?.[g]??g+1;for(;c<r.length;){s.budget.check();const g=r[c],f=g.trim();if(!f){c+=1;continue}if(/^<details>\s*$/i.test(f)){const F=c;let M="Details";const C=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const P=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);P?M=P[1].trim()||M:C.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),d.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:ut(M,`${n}-details-${F}-summary`,!0,s)}),C.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:ah(C,`${n}-details-${F}`,s)})]},`${n}-details-${F}`)});continue}const p=th(g);if(p){const F=[g],M=c;for(c+=1;c<r.length&&!p.selfContained&&!new RegExp(`</${p.tag}>`,"i").test(r[c]);)F.push(r[c]),c+=1;c<r.length&&!p.selfContained&&(F.push(r[c]),c+=1),d.push({kind:"static",node:e.jsx(eh,{html:F.join(`
1639
+ `)},`${n}-html-${M}`)});continue}const x=f.match(/^(```|~~~)\s*(.*)$/);if(x){const F=[],M=x[1],C=x[2]?.trim(),P=c;for(c+=1;c<r.length&&!r[c].trim().startsWith(M);)F.push(r[c]),c+=1;c<r.length&&(c+=1),C.toLowerCase()==="mermaid"?d.push({kind:"static",node:e.jsx(ch,{code:F.join(`
1640
+ `),blockKey:`${n}-code-${P}`},`${n}-code-${P}`)}):["math","latex","tex"].includes(C.toLowerCase())?d.push({kind:"static",node:e.jsx(oa,{tex:F.join(`
1641
1641
  `),display:!0},`${n}-code-${P}`)}):d.push({kind:"code",key:`${n}-code-${P}`,code:F.join(`
1642
- `),lang:N,blockKey:`${n}-code-${P}`,codeStartLine:m(P)+1});continue}if(No(g)){const F=[],M=c;for(;c<r.length&&(No(r[c])||!r[c].trim());)F.push(r[c].trim()?Zf(r[c]):""),c+=1;d.push({kind:"code",key:`${n}-indented-code-${M}`,code:F.join(`
1643
- `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${M}`,codeStartLine:m(M)});continue}const h=f.match(/^(#{1,6})\s+(.+)$/);if(h){const M=`h${Math.min(6,h[1].length+1)}`,N=Bf(h[2]),P=Rl(N,s);d.push({kind:"static",node:e.jsx(M,{id:P,className:"scroll-mt-16 font-semibold text-foreground",children:ut(N,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<r.length&&g.includes("|")&&Mo(r[c+1])){const F=aa(g),M=th(r[c+1]),N=[],P=c;for(c+=2;c<r.length&&r[c].includes("|")&&r[c].trim();)N.push(aa(r[c])),c+=1;d.push({kind:"static",node:e.jsx("div",{className:Mf,"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:F.map((B,q)=>e.jsx("th",{className:`${Nf} ${Eo(M[q]??null)}`,children:e.jsx("div",{className:Ro,children:ut(B,`${n}-th-${P}-${q}`,!0,s)})},`h-${q}`))})}),e.jsx("tbody",{children:N.map((B,q)=>e.jsx("tr",{className:"border-t border-border/10",children:F.map((j,o)=>e.jsx("td",{className:`${Ef} ${Eo(M[o]??null)}`,children:e.jsx("div",{className:Ro,children:ut(B[o]??"",`${n}-td-${P}-${q}-${o}`,!0,s)})},`c-${o}`))},`r-${q}`))})]})},`${n}-table-${P}`)});continue}const b=oa(g);if(b){const F=b.ordered,M=Io(g),N=b.start,P=c,B=_l(r,c,M,F,!1);c=B.nextIndex,d.push({kind:"list",keyPrefix:`${n}-list-${P}`,ordered:F,start:F?N:void 0,renders:Bl(B.items,`${n}-list-${P}`,s,m(0)-1)});continue}const E=[g.trimStart()],S=[m(c)],T=c;for(c+=1;c<r.length&&r[c].trim()&&!jl(r[c])&&!(c+1<r.length&&r[c].includes("|")&&Mo(r[c+1]));)E.push(r[c].trimStart()),S.push(m(c)),c+=1;const D=El(E,`${n}-p-${T}`,s);d.push({kind:"paragraph",keyPrefix:`${n}-p-${T}`,perLine:D.perLine,hardBreaks:D.hardBreaks,lineNums:S})}return d}function Ix(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Ml(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:Ol(s.renders,n)},s.keyPrefix)}case"code":return e.jsx($o,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}const uo=16,nh=192;function Dx(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,d,c]=l;if(!Number.isFinite(d)||!Number.isFinite(c)||d<=0||c<=0)return r;const m=Math.max(nh,Math.ceil(d)),g=Math.ceil(m/d*c);return r.replace(/<svg\b([^>]*)>/i,(f,p)=>`<svg${p.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${m}" height="${g}">`)}function Fx(r){const n=r?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-uo,d=s.y-uo,c=s.width+uo*2,m=s.height+uo*2,g=Math.max(nh,Math.ceil(c)),f=Math.ceil(g/c*m);n.setAttribute("viewBox",`${l} ${d} ${c} ${m}`),n.setAttribute("width",String(g)),n.setAttribute("height",String(f)),n.removeAttribute("style")}function _x(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return nf(`code.${s}`)??s}function sh({code:r,blockKey:n}){const{t:s}=ft(),[l,d]=a.useState(null),[c,m]=a.useState(!1),g=a.useRef(null),f=a.useContext(Ff);a.useEffect(()=>{let x=!1;return d(null),m(!1),fg().then(async h=>{hg(h);const b=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:E}=await h.render(b,r);x||d(Dx(E))}).catch(()=>{x||m(!0)}),()=>{x=!0}},[n,r]),a.useLayoutEffect(()=>{l&&Fx(g.current)},[l]);const p=a.useCallback(()=>{const x=g.current?.querySelector("svg")?.outerHTML??l;x&&f?.(x)},[f,l]);return c?e.jsx($o,{code:r,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:x=>{x.stopPropagation(),p()},children:e.jsx("span",{ref:g,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function $o({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:d}){const c=_x(n),[m,g]=a.useState(null);a.useEffect(()=>{if(!c||!sf(r)){g(null);return}let p=!1;return af().then(x=>{if(p||!x.registered(c)){p||g(null);return}try{g(of(x,r,c))}catch{p||g(null)}}).catch(()=>{p||g(null)}),()=>{p=!0}},[s,r,c]);const f=m??(r||" ").split(`
1644
- `).map(p=>[p||" "]);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:`${Tl} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:f.map((p,x)=>{const h=l!=null?l+x:null,b=!!(d&&h!=null&&h>=d.start&&h<=d.end);return e.jsxs("span",{"data-md-ref-start":h??void 0,"data-md-ref-end":h??void 0,"data-selected":b?"true":void 0,children:[p,x<f.length-1?`
1645
- `:null]},`${s}-line-${x}`)})})})]})}function Ul(r,n,s,l,d){const c=new og;c.validateLines(r),r=mx(r);const m=fx(r),g=Hf(r),f=[],p={budget:c,markdownFilePath:n,rootPath:s,referenceDefinitions:m,footnoteDefinitions:hx(r),headingSlugCounts:new Map,images:f,onImageOpen:l,footnotesLabel:d?.footnotes??"Footnotes",backToFootnoteLabel:d?.backToFootnote??(E=>`Back to footnote ${E}`)},x=[];let h=0;for(;h<r.length;){p.budget.check();const E=r[h],S=E.trim();if(Co(E)||g.has(h)){h+=1;continue}if(!S){h+=1;continue}if(/^<details>\s*$/i.test(S)){const j=h;let o="Details";const _=[];for(h+=1;h<r.length&&!/^<\/details>\s*$/i.test(r[h].trim());){const I=r[h].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);I?o=I[1].trim()||o:_.push(r[h].trimStart()),h+=1}h<r.length&&(h+=1),x.push({key:`details-${j}`,startLine:j+1,endLine:h,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:ut(o,`details-${j}-summary`,!0,p)}),_.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:eh(_,`details-${j}`,p)})]})});continue}const T=Xf(E);if(T){const j=[E],o=h;for(h+=1;h<r.length&&!T.selfContained&&!new RegExp(`</${T.tag}>`,"i").test(r[h]);)j.push(r[h]),h+=1;h<r.length&&!T.selfContained&&(j.push(r[h]),h+=1),x.push({key:`html-${o}`,startLine:o+1,endLine:h,content:e.jsx(Yf,{html:j.join(`
1646
- `)})});continue}const D=S.match(/^(```|~~~)\s*(.*)$/);if(D){const j=[],o=D[1],_=D[2]?.trim(),I=h;for(h+=1;h<r.length&&!r[h].trim().startsWith(o);)j.push(r[h]),h+=1;h<r.length&&(h+=1),x.push({key:`code-${I}`,startLine:I+1,endLine:h,fineGrained:_.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(_.toLowerCase()),content:_.toLowerCase()==="mermaid"?e.jsx(sh,{code:j.join(`
1647
- `),blockKey:`code-${I}`}):["math","latex","tex"].includes(_.toLowerCase())?e.jsx(sa,{tex:j.join(`
1648
- `),display:!0}):V=>e.jsx($o,{code:j.join(`
1649
- `),lang:_,blockKey:`code-${I}`,codeStartLine:I+2,lineRange:V})});continue}if(No(E)){const j=[],o=h;for(h+=0;h<r.length&&(No(r[h])||!r[h].trim());)j.push(r[h].trim()?Zf(r[h]):""),h+=1;x.push({key:`indented-code-${o}`,startLine:o+1,endLine:h,fineGrained:!0,content:_=>e.jsx($o,{code:j.join(`
1650
- `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${o}`,codeStartLine:o+1,lineRange:_})});continue}if(S.startsWith("$$")){const j=[],o=h,_=S.replace(/^\$\$\s*/,"");if(_.endsWith("$$")&&_.length>2)j.push(_.replace(/\s*\$\$$/,"")),h+=1;else{for(_&&j.push(_),h+=1;h<r.length&&!r[h].trim().endsWith("$$");)j.push(r[h]),h+=1;if(h<r.length){const I=r[h].trim().replace(/\s*\$\$$/,"");I&&j.push(I),h+=1}}x.push({key:`math-${o}`,startLine:o+1,endLine:h,content:e.jsx(sa,{tex:j.join(`
1651
- `),display:!0})});continue}if(h+1<r.length&&S&&!jl(E)&&/^(=+|-+)\s*$/.test(r[h+1].trim())){const j=r[h+1].trim().startsWith("=")?1:2,o=`h${j}`,_=Rl(S,p),I={level:j,text:$u(S),id:_};x.push({key:`setext-heading-${h}`,startLine:h+1,endLine:h+2,heading:I,content:e.jsx(o,{id:_,className:`scroll-mt-16 font-semibold text-foreground ${j===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:ut(S,`setext-heading-${h}`,!0,p)})}),h+=2;continue}const F=S.match(/^(#{1,6})\s+(.+)$/);if(F){const j=F[1].length,o=Bf(F[2]),_={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"},I=`h${j}`,V=Rl(o,p),W={level:j,text:$u(o),id:V};x.push({key:`heading-${h}`,startLine:h+1,endLine:h+1,heading:W,content:e.jsx(I,{id:V,className:`scroll-mt-16 font-semibold text-foreground ${_[j]}`,children:ut(o,`heading-${h}`,!0,p)})}),h+=1;continue}if(If(E)){x.push({key:`hr-${h}`,startLine:h+1,endLine:h+1,content:e.jsx("hr",{className:"border-border/20"})}),h+=1;continue}if(S.startsWith(">")){const j=[],o=[],_=h;for(;h<r.length&&/^>\s?/.test(r[h].trim());)j.push(r[h].trim().replace(/^>\s?/,"")),o.push(h+1),h+=1;const I=j[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(I){const W=I[1].toUpperCase(),O=I[2]?.trim(),R=[...O?[O]:[],...j.slice(1)],H=[...O?[o[0]]:[],...o.slice(1)],ee=El(R,`callout-${_}`,p);x.push({key:`callout-${_}`,startLine:_+1,endLine:h,fineGrained:!0,content:L=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:W}),R.length>0&&e.jsx("div",{children:Ml(ee.perLine,ee.hardBreaks,H,`callout-${_}`,L)})]})});continue}const V=Tx(j,`quote-${_}`,p,o);x.push({key:`quote-${_}`,startLine:_+1,endLine:h,fineGrained:!0,content:W=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Ix(V,W)})});continue}if(h+1<r.length&&E.includes("|")&&Mo(r[h+1])){const j=aa(E),o=th(r[h+1]),_=[],I=h;for(h+=2;h<r.length&&r[h].includes("|")&&r[h].trim();)_.push(aa(r[h])),h+=1;const V=j.map((O,R)=>ut(O,`th-${I}-${R}`,!0,p)),W=_.map((O,R)=>j.map((H,ee)=>ut(O[ee]??"",`td-${I}-${R}-${ee}`,!0,p)));x.push({key:`table-${I}`,startLine:I+1,endLine:h,interactive:!1,kind:"table",content:O=>{const R=H=>!!(O&&H>=O.start&&H<=O.end);return e.jsx("div",{className:Mf,"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":I+1,"data-md-ref-start":I+1,"data-md-ref-end":I+1,"data-selected":R(I+1)?"true":void 0,children:V.map((H,ee)=>e.jsx("th",{className:`${Nf} ${Eo(o[ee]??null)}`,children:e.jsx("div",{className:Ro,children:H})},`h-${ee}`))})}),e.jsx("tbody",{children:W.map((H,ee)=>{const L=I+ee+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":L,"data-md-ref-start":L,"data-md-ref-end":L,"data-selected":R(L)?"true":void 0,children:j.map((U,X)=>e.jsx("td",{className:`${Ef} ${Eo(o[X]??null)}`,children:e.jsx("div",{className:Ro,children:H[X]})},`c-${X}`))},`r-${ee}`)})})]})})}});continue}const M=oa(E);if(M){const j=M.ordered,o=Io(E),_=M.start,I=h,V=_l(r,h,o,j,!0,g);h=V.nextIndex;const W=j?"ol":"ul",O=Bl(V.items,`list-${I}`,p);x.push({key:`list-${I}`,startLine:I+1,endLine:h,fineGrained:!0,content:R=>e.jsx(W,{start:j?_:void 0,className:`${j?"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:Ol(O,R)})});continue}const N=[E.trimStart()],P=[h+1],B=h;for(h+=1;h<r.length&&r[h].trim()&&!jl(r[h])&&!(h+1<r.length&&r[h].includes("|")&&Mo(r[h+1]));){if(Co(r[h])||g.has(h)){h+=1;continue}N.push(r[h].trimStart()),P.push(h+1),h+=1}const q=El(N,`p-${B}`,p);x.push({key:`p-${B}`,startLine:B+1,endLine:h,fineGrained:!0,content:j=>e.jsx("p",{className:"text-muted-foreground",children:Ml(q.perLine,q.hardBreaks,P,`p-${B}`,j)})})}const b=Ax(p);return b&&x.push({key:"footnotes",startLine:r.length,endLine:r.length,content:b}),c.check(),{blocks:x,images:f}}function Bx(r,n,s){return Ul(r,n,s).blocks}function ah(r,n){const s=[];for(const l of r){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function oh(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Ox({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const{t:d}=ft(),c=Gf(r),m=mf(c),[g,f]=a.useState(null),[p,x]=a.useState(0);a.useEffect(()=>{if(!m)return;const b=new AbortController;let E;return f(null),Ku(c,{signal:b.signal}).then(async S=>{if(!S.ok)throw new Error(`HTTP ${S.status}`);const T=await S.blob();b.signal.aborted||(E=URL.createObjectURL(T),f({src:c,objectUrl:E}))}).catch(()=>{b.signal.aborted||f({src:c,failed:!0})}),()=>{b.abort(),E&&URL.revokeObjectURL(E)}},[m,c,p]);const h=g?.src===c?g:null;return m&&!h?.objectUrl?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",role:h?.failed?"alert":"status",children:h?.failed?e.jsxs("div",{className:"flex flex-col items-center gap-3",onClick:b=>b.stopPropagation(),children:[e.jsx("span",{children:d("rightSidebar.imageLoadFailed")}),e.jsx("button",{type:"button",className:"rounded bg-surface-2 px-3 py-2 hover:bg-surface-elevated",onClick:()=>x(b=>b+1),children:d("common.retry")})]}):d("rightSidebar.loadingImage")}):e.jsx(xh,{src:m?h.objectUrl:c,vector:ia(r),alt:n,onLoad:()=>{},onError:()=>{m&&f({src:c,failed:!0})},onZoomChange:s,onDoubleTap:l})}function ih({images:r,index:n,onChange:s,onClose:l}){const{t:d}=ft(),c=r[n],m=r.length>1,g=a.useRef(null),f=a.useRef(null),p=a.useRef(null),x=a.useRef(0),[h,b]=a.useState(!1),[E,S]=a.useState(0),[T,D]=a.useState(!1),[F,M]=a.useState(!1),[N,P]=a.useState(null),B=a.useRef(!1),q=async()=>{if(!(!c||B.current)){j(),B.current=!0,M(!0),P(null);try{await ug(c)}catch(O){P({image:c,message:O instanceof Error?O.message:d("rightSidebar.downloadFailed")})}finally{B.current=!1,M(!1)}}},j=a.useCallback(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),o=a.useCallback(()=>{h||Date.now()<x.current||(j(),p.current=window.setTimeout(()=>{p.current=null,l()},450))},[j,h,l]),_=a.useCallback(O=>{if(r.length===0)return;const R=(O+r.length)%r.length;g.current?.slideTo(R),s(R)},[r.length,s]),I=a.useCallback(()=>_(n-1),[_,n]),V=a.useCallback(()=>_(n+1),[_,n]);if(a.useEffect(()=>{j(),S(0),D(!1),b(!1)},[j,n]),a.useEffect(()=>{const O=g.current;O&&(O.allowTouchMove=m&&!h)},[m,h]),a.useEffect(()=>{const O=g.current;!O||O.activeIndex===n||O.slideTo(n,0)},[n]),a.useEffect(()=>j,[j]),a.useEffect(()=>{const O=R=>{if(R.key==="Escape"){R.preventDefault(),l();return}m&&(R.key==="ArrowLeft"?(R.preventDefault(),I()):R.key==="ArrowRight"&&(R.preventDefault(),V()))};return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[m,V,I,l]),Ju({onDrag:({movement:[O,R],pinching:H})=>{H||h||Math.abs(R)<Math.abs(O)*1.15&&E===0||(D(!0),Math.abs(R)>8&&(x.current=Date.now()+300),S(Math.max(0,R)))},onDragEnd:({movement:[O,R],velocity:[,H],pinching:ee,canceled:L})=>{if(D(!1),ee||L||h||Math.abs(R)<Math.abs(O)*1.15){S(0);return}if(Math.abs(R)>8&&(x.current=Date.now()+300),rh(R,H)){l();return}S(0)}},{target:f,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const W=c.title||c.alt||(c.kind==="mermaid"?d("rightSidebar.mermaidDiagram"):d("rightSidebar.image"));return typeof document>"u"?null:jr.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:W}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[m&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:I,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":d("rightSidebar.previousImage"),title:d("common.previous"),children:e.jsx(ta,{size:17})}),e.jsx("button",{type:"button",onClick:V,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":d("rightSidebar.nextImage"),title:d("common.next"),children:e.jsx(qm,{size:17})})]}),e.jsx("button",{type:"button",onClick:()=>{q()},disabled:F,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","aria-label":d("rightSidebar.downloadFile"),title:d("rightSidebar.downloadFile"),"aria-busy":F,children:F?e.jsx(dt,{size:17,className:"animate-spin"}):e.jsx(Xu,{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":d("rightSidebar.closeImagePreview"),title:d("common.close"),children:e.jsx(Pt,{size:18})})]})]}),N?.image===c&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 bg-surface px-3 py-2 text-xs text-destructive",children:[e.jsxs("span",{className:"min-w-0 break-words",children:[d("rightSidebar.downloadFailed"),": ",N.message]}),e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-3 py-1 text-foreground hover:bg-surface-elevated",onClick:()=>{q()},disabled:F,children:d("common.retry")})]}),e.jsx("div",{ref:f,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:O=>{if(!(Date.now()<x.current)){if(O.target instanceof Element&&O.target.closest('img, [role="img"]')){o();return}j(),l()}},children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${E}px, 0) scale(${Math.max(.86,1-E/900)})`,opacity:Math.max(.35,1-E/360),transition:T?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Qu,{onSwiper:O=>{g.current=O,O.allowTouchMove=m&&!h},onSlideChange:O=>{O.activeIndex!==n&&s(O.activeIndex)},onSliderMove:()=>{j(),x.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((O,R)=>e.jsx(dl,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:O.kind==="image"?e.jsx(Ox,{src:O.src,alt:O.alt||O.title||d("rightSidebar.markdownImage"),onZoomChange:b,onDoubleTap:j}):e.jsx(r0,{svg:O.svg,title:O.title||O.alt||d("rightSidebar.mermaidDiagram"),onZoomChange:b,onDoubleTap:j})})},`${O.kind}-${R}-${O.alt}`))})})})]})]}),document.body)}function lh({referenceLines:r=!0,content:n,filePath:s,rootPath:l,lineRange:d,onLineRangeClick:c,onLineRangeDrag:m,scrollTop:g,outlineOpen:f,outlineCloseSignal:p,onOutlineOpen:x,onOutlineClose:h,lightboxOpen:b,lightboxCloseSignal:E,onLightboxOpen:S,onLightboxClose:T,onLocalLinkOpen:D}){const{t:F}=ft(),[M,N]=a.useState(null),[P,B]=a.useState(null),[q,j]=a.useState(1),[o,_]=a.useState(null),I=a.useRef(null),V=a.useRef(null),{blocks:W,images:O,parseError:R}=a.useMemo(()=>{try{return{...Ul(n.split(`
1652
- `),s,l,$=>{B(null),N($),S?.()},{footnotes:F("rightSidebar.footnotes"),backToFootnote:$=>F("rightSidebar.backToFootnote",{index:$})}),parseError:null}}catch($){return{blocks:[],images:[],parseError:$ instanceof Error?$.message:String($)}}},[n,s,l,S,F]);a.useEffect(()=>{R&&yo("markdown_error",{filePath:s,rootPath:l,error:R,fallback:"plain_text"})},[R,s,l]);const H=a.useMemo(()=>P?[...O,P]:O,[O,P]),ee=a.useCallback($=>{B({kind:"mermaid",svg:$,alt:"Mermaid diagram",title:"Mermaid diagram"}),N(O.length),S?.()},[O.length,S]);a.useEffect(()=>{N(null),B(null)},[n,s]),a.useEffect(()=>{N(null),B(null)},[E]),a.useEffect(()=>{b||(N(null),B(null))},[b]),a.useEffect(()=>{j(1)},[n,s]),a.useLayoutEffect(()=>{const $=I.current;if(!$||W.length===0)return;const me=Array.from($.querySelectorAll("[data-markdown-preview-block-start]"));let ge=1;const Le=28;for(const ne of me)if(ne.offsetTop-g<=Le)ge=Number(ne.dataset.markdownPreviewBlockStart)||ge;else break;j(ne=>ne===ge?ne:ge)},[W,g]);const L=a.useMemo(()=>ah(W,q),[q,W]),U=a.useMemo(()=>oh(W),[W]),X=`${s??""}
1653
- ${n}`,ce=a.useRef(X),he=a.useRef(null),Re=a.useRef(null),Ce=a.useRef(!1);a.useEffect(()=>{ce.current!==X&&(ce.current=X,h?.())},[h,X]),a.useEffect(()=>{p!==void 0&&_(null)},[p]),a.useLayoutEffect(()=>{if(!f){_(null);return}const $=()=>{const me=V.current;if(!me)return;const ge=me.getBoundingClientRect(),Le=window.innerWidth;_({top:ge.bottom+6,right:Math.max(8,Le-ge.right)})};return $(),window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[f,g,L]);const $e=a.useCallback($=>{const me=I.current,ge=me?.closest("[data-markdown-preview-scroller]"),Le=me?.querySelector(`[data-markdown-preview-block-start="${$.startLine}"]`);if(!ge||!Le)return;const ne=ge.getBoundingClientRect(),Ye=Le.getBoundingClientRect(),De=me?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,Te=Ye.top-ne.top+ge.scrollTop;ge.scrollTo({top:Math.max(0,Te-De-8),behavior:"smooth"}),j($.startLine),h?.()},[h]),J=a.useCallback($=>{$.pointerType==="mouse"&&$.button!==0||ol($.target)||(he.current={pointerId:$.pointerId,startX:$.clientX,startY:$.clientY})},[]),xe=a.useCallback(($,me,ge)=>{const Le=he.current;if(he.current=null,!Le||Le.pointerId!==$.pointerId)return;const ne=Math.abs($.clientX-Le.startX),Ye=Math.abs($.clientY-Le.startY);if(ne>8||Ye>8)return;const Je=$.target;if(ol(Je)||fl())return;const De=Ou(Je,me,ge);c($,De.start,De.end)},[c]),fe=a.useCallback($=>{he.current?.pointerId===$.pointerId&&(he.current=null)},[]),Fe=a.useCallback(($,me)=>{const ge=I.current;if(!ge||typeof document.elementFromPoint!="function")return null;const Le=document.elementFromPoint($,me);if(!(Le instanceof HTMLElement)||!ge.contains(Le))return null;const ne=Le.closest("[data-md-ref-start]");if(ne){const Be=Number(ne.dataset.mdRefStart);if(Number.isFinite(Be)&&Be>0)return Be}const Ye=Le.closest("[data-markdown-preview-block-start]");if(!Ye)return null;const Je=Number(Ye.dataset.markdownPreviewBlockStart),De=W.find(Be=>Be.startLine===Je);if(!De)return Number.isFinite(Je)&&Je>0?Je:null;if(De.endLine<=De.startLine)return De.startLine;const Te=Ye.getBoundingClientRect(),_e=Te.height>0?Math.min(1,Math.max(0,(me-Te.top)/Te.height)):0;return Math.round(De.startLine+_e*(De.endLine-De.startLine))},[W]),Oe=a.useCallback($=>{if(!m||$.pointerType==="mouse"&&$.button!==0)return;const me=Fe($.clientX+24,$.clientY);if(me!=null){Re.current={pointerId:$.pointerId,anchorLine:me,moved:!1};try{$.currentTarget.setPointerCapture($.pointerId)}catch{}}},[m,Fe]),G=a.useCallback($=>{const me=Re.current;if(!me||me.pointerId!==$.pointerId||!m)return;const ge=Fe($.clientX+16,$.clientY);ge!=null&&(!me.moved&&ge===me.anchorLine||(me.moved=!0,Ce.current=!0,m($,Math.min(me.anchorLine,ge),Math.max(me.anchorLine,ge),"move")))},[m,Fe]),Ne=a.useCallback($=>{const me=Re.current;if(Re.current=null,!me||me.pointerId!==$.pointerId||!m||!me.moved)return;const ge=Fe($.clientX+16,$.clientY)??me.anchorLine;m($,Math.min(me.anchorLine,ge),Math.max(me.anchorLine,ge),"end")},[m,Fe]),Se=a.useCallback($=>{Re.current?.pointerId===$.pointerId&&(Re.current=null)},[]),de={onPointerDown:Oe,onPointerMove:G,onPointerUp:Ne,onPointerCancel:Se},qe=()=>Ce.current?(Ce.current=!1,!0):!1;return R?e.jsxs("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground","data-markdown-preview-fallback":!0,children:[e.jsx("p",{role:"alert",className:"mb-3 text-destructive",children:F("rightSidebar.markdownParseFailed")}),e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-xs",children:n})]}):W.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:F("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:I,className:"relative min-w-0 max-w-full",onClickCapture:$=>{const me=$.target instanceof Element?$.target.closest("a[href]"):null;if(!me||!D)return;const ge=me.getAttribute("href");if(!ge)return;const Le=Il(ge,s,l);Le&&($.preventDefault(),D(Le))},children:[r&&L.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:L.map($=>$.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:L[L.length-1].text}),U.length>1&&e.jsxs("button",{ref:V,type:"button",onClick:()=>{f?h?.():x?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${f?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":f,"aria-label":F("rightSidebar.markdownOutline"),title:F("rightSidebar.markdownOutline"),children:[e.jsx(Zu,{size:12}),e.jsx("span",{children:F("rightSidebar.markdownOutlineShort")})]})]})}),f&&typeof document<"u"&&jr.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:h}),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:o?{top:`${o.top}px`,right:`${o.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:U.map($=>{const me=L[L.length-1]?.startLine===$.startLine;return e.jsxs("button",{type:"button",onClick:()=>$e($),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] ${me?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min($.level-1,4)*12+8}px`},title:$.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${me?"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",$.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:$.text})]},`desktop-${$.id}-${$.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:F("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:h,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":F("rightSidebar.closeMarkdownOutline"),title:F("common.close"),children:e.jsx(Pt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:U.map($=>{const me=L[L.length-1]?.startLine===$.startLine;return e.jsxs("button",{type:"button",onClick:()=>$e($),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] ${me?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min($.level-1,4)*12+8}px`},title:$.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${me?"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",$.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:$.text})]},`${$.id}-${$.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(Ff.Provider,{value:ee,children:W.map($=>{const me=!!(d&&$.startLine<=d.end&&$.endLine>=d.start),ge=!!(d&&d.start<=$.startLine&&d.end>=$.endLine),Le=$.kind==="table"?!1:$.fineGrained?ge:me,ne=$.kind==="table"&&d?.start===$.startLine&&d.end===$.endLine;let Ye=null;if($.kind!=="table"&&$.fineGrained&&me&&!ge&&d){const _e=$.endLine-$.startLine+1,Be=Math.max(d.start,$.startLine),te=Math.min(d.end,$.endLine),ye=(Be-$.startLine)/_e,nt=(te-Be+1)/_e;Ye=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) * ${ye})`,height:`calc((100% - 0.5rem) * ${nt})`}})}const Je=typeof $.content=="function"?$.content(d):$.content;if(!r)return e.jsx("div",{"data-markdown-preview-block-start":$.startLine,className:"min-w-0 cursor-text select-text py-0.5",children:Je},$.key);const De=$.startLine===$.endLine?String($.startLine):`${$.startLine}-${$.endLine}`,Te=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:nl(Le),"aria-hidden":"true",...de,children:[e.jsx("span",{className:sl(Le)}),Ye]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:Je})]});return $.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":$.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 ${Le?"bg-primary/10":""}`,title:`Line ${De}`,"aria-label":`Line ${De}`,children:[$.kind==="table"?e.jsx("button",{type:"button",className:nl(ne,"self"),onClick:_e=>{_e.preventDefault(),!qe()&&c(_e,$.startLine,$.endLine)},title:`Reference table lines ${De}`,"aria-label":`Reference table lines ${De}`,...de,children:e.jsx("span",{className:sl(ne,"self")})}):e.jsxs("span",{className:nl(Le,"none"),"aria-hidden":"true",...de,children:[e.jsx("span",{className:sl(Le,"none")}),Ye]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:J,onPointerUp:_e=>xe(_e,$.startLine,$.endLine),onPointerCancel:fe,onKeyDown:_e=>{_e.key!=="Enter"&&_e.key!==" "||(_e.preventDefault(),c(_e,$.startLine,$.endLine))},title:`Reference line ${De}`,"aria-label":`Reference line ${De}`,children:Je})]},$.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":$.startLine,onClick:_e=>{const Be=_e.target;if(ol(Be)||fl()||qe())return;const te=Ou(Be,$.startLine,$.endLine);c(_e,te.start,te.end)},onKeyDown:_e=>{_e.key!=="Enter"&&_e.key!==" "||(_e.preventDefault(),c(_e,$.startLine,$.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 ${Le?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${De}`,"aria-label":`Reference line ${De}`,children:Te},$.key)})})})]}),b&&M!==null&&H[M]&&e.jsx(ih,{images:H,index:M,onChange:N,onClose:()=>{N(null),B(null),T?.()}})]})}function us({label:r,value:n,options:s,placeholder:l,searchPlaceholder:d,emptyText:c,disabled:m,onChange:g}){const{t:f}=ft(),[p,x]=a.useState(!1),[h,b]=a.useState(""),[E,S]=a.useState(null),T=a.useRef(null),D=a.useRef(null),F=h.trim().toLowerCase(),M=a.useMemo(()=>F?s.filter(j=>`${j.label} ${j.meta??""}`.toLowerCase().includes(F)):s,[F,s]),N=s.find(j=>j.value===n),P=()=>{const j=h.trim();j&&(g(j),x(!1),b(""))},B=a.useCallback(()=>{const j=T.current?.getBoundingClientRect();if(!j)return!1;const o=12,_=Math.max(220,Math.min(j.width,window.innerWidth-o*2)),I=Math.min(Math.max(o,j.left),window.innerWidth-_-o),V=window.innerHeight-j.bottom-o,W=j.top-o,O=V>=180||V>=W,R=Math.max(96,(O?V:W)-4),H=Math.min(320,R);return S({left:I,top:O?j.bottom+4:Math.max(o,j.top-H-4),width:_,maxHeight:H}),!0},[]),q=()=>{B(),x(!0)};return a.useEffect(()=>{if(!p)return;let j=0;const o=()=>{j||(j=window.requestAnimationFrame(()=>{j=0,B()}))},_=I=>{const V=I.target;V instanceof Node&&(T.current?.contains(V)||D.current?.contains(V)||(x(!1),b("")))};return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),document.addEventListener("pointerdown",_,!0),()=>{j&&window.cancelAnimationFrame(j),window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0),document.removeEventListener("pointerdown",_,!0)}},[p,B]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:T,type:"button",disabled:m,onClick:()=>{if(!m){if(b(""),p){x(!1);return}q()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:N?.label??(n||l)})]}),e.jsx(ra,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${p?"rotate-180":""}`})]}),p&&!m&&typeof document<"u"&&jr.createPortal(e.jsxs("div",{ref:D,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:j=>j.stopPropagation(),style:{left:E?.left??12,top:E?.top??12,width:E?.width??260,maxHeight:E?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(hs,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:h,onChange:j=>b(j.target.value),onKeyDown:j=>{if(j.key==="Escape"){j.preventDefault(),x(!1),b("");return}j.key==="Enter"&&(j.preventDefault(),P())},onBlur:()=>{h.trim()&&M.length===0&&P()},placeholder:d,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(E?.maxHeight??320)-46)},children:[h.trim()&&!s.some(j=>j.value===h.trim())&&e.jsxs("button",{type:"button",onMouseDown:j=>j.preventDefault(),onClick:P,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:h.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:f("common.use")})]}),M.length>0?M.map(j=>e.jsxs("button",{type:"button",onClick:()=>{g(j.value),x(!1),b("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${j.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:j.label}),j.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:j.meta})]},j.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function Tu({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:d,selectedRoots:c,onToggleRepo:m,onGenerate:g,onSecondaryAction:f,disabled:p,generateDisabled:x,secondaryDisabled:h,inserted:b,buttonLabel:E,insertedLabel:S,title:T,ariaLabel:D,scopeTitle:F,scopeLabel:M,allLabel:N,generateLabel:P,secondaryLabel:B,secondaryTitle:q,secondaryLoading:j,loading:o,error:_,statusTitle:I,extraContent:V,renderRepoExtra:W,menuItem:O=!1}){return e.jsxs("div",{className:O?"relative w-full":"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",role:O?"menuitem":void 0,tabIndex:O?-1:void 0,onClick:()=>{s?n(!r):x||g()},disabled:p,className:`relative flex items-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-50 ${O?"min-h-10 w-full gap-2.5 px-2.5 text-left text-[12px] focus:bg-surface-2 focus:outline-none [@media(pointer:coarse)]:min-h-11":"h-7 shrink-0 justify-center gap-1 px-2 text-[11px] font-medium active:scale-95"} ${_?"text-destructive hover:bg-destructive/5":b?"bg-surface-elevated text-foreground":O?"text-foreground hover:bg-surface-2":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":D,title:I??(s?`${F}: ${M}`:T),children:[o?e.jsx(dt,{size:O?15:13,className:"shrink-0 animate-spin"}):e.jsx(na,{size:O?15:13,className:O?"shrink-0 text-muted-foreground":void 0}),e.jsx("span",{className:O?"min-w-0 flex-1":void 0,children:b?S:E}),s&&(O?e.jsx(fs,{size:13,className:"shrink-0 text-muted-foreground"}):e.jsx(ra,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`})),_&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&jr.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:R=>R.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:F}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:M})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Pt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[V,e.jsxs("button",{type:"button",onClick:()=>m(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:N}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),d.map(R=>{const H=c.includes(R.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${H?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>m(R.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${H?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:R.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:R.label}),R.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:R.branch})]}),H&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),W&&(l||H)&&e.jsx("div",{className:"px-2 pb-2",children:W(R)})]},R.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${f&&B?"sm:grid-cols-2":""}`,children:[f&&B&&e.jsxs("button",{type:"button",onClick:()=>{h||(n(!1),f())},disabled:h,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:q,children:[j?e.jsx(dt,{size:12,className:"animate-spin"}):e.jsx(cf,{size:12}),B]}),e.jsxs("button",{type:"button",onClick:()=>{x||(n(!1),g())},disabled:x,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:T,children:[e.jsx(na,{size:12}),P]})]})]})}),document.body)]})}function Ux(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function ch(){return pt(Pl,Ux)??{}}function Hx(r,n){const s=ch(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,d],[,c])=>c.updatedAt-d.updatedAt).slice(0,Ib);Js(Pl,Object.fromEntries(l),Fb)}function zx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function Wx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!zx(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Hl(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function dh(){return pt(Al,Wx)??{}}function Iu(r,n){const s=Hl(r,n);return s?dh()[s]??null:null}function tl(r,n,s){const l=Hl(r,n);if(!l)return;const d=dh(),c=d[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},m=Object.entries({...d,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,g],[,f])=>f.updatedAt-g.updatedAt).slice(0,Db);Js(Al,Object.fromEntries(m),_b)}function rl({slow:r}){return e.jsx($p,{slow:r})}function fo({message:r,onRetry:n}){const{t:s}=ft();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:r}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function vo(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function jt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function ho(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Gx(r,n,s){return hl(r,n,s)}function nl(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function sl(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function uh(r){const n=new Map;for(const s of r)n.set(zl(s),s);return n}function fh(r,n){const s=new Map(r);for(const l of n)s.set(zl(l),l);return s}function Du(r,n){let s=0;for(const l of r){const d=xt(l,n);d&&n&&d!==n&&(s+=1)}return s}function Kx(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function qx(r,n){return Array.from(fh(uh(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Vx(r,n){const s=r.relativeRoot==="."?jt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||jt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Kx(r.files)}}function hh(r,n){const s=jt(n??"")||n||"";return r.map(l=>Vx(l,n)).sort((l,d)=>s&&l.label===s?-1:s&&d.label===s?1:l.label.localeCompare(d.label))}function mh(r,n,s,l,d){const c=Lf(s),m=c.find(T=>T.root===l)??c[0]??null,g=n.find(T=>T.root===l)??null,f=g?.relativeRoot??m?.relativeRoot??".",p=g?.name??m?.name??(jt(l)||l),x=(m?.files??s.files).map(T=>({...T,repoRoot:l,repoRelativeRoot:f,repoName:p})),h=m?.context??s.context,b={...g??m??{id:l,root:l,relativeRoot:f,name:p,depth:0,nested:!!(d&&l!==d),available:s.available,files:[],context:null},...m??{},id:g?.id??m?.id??l,root:l,displayRoot:g?.displayRoot??m?.displayRoot,relativeRoot:f,name:p,depth:g?.depth??m?.depth??0,nested:g?.nested??m?.nested??!!(d&&l!==d),available:m?.available??s.available,deferred:m?.deferred??!1,files:x,context:h?{...h,root:l,changedFiles:x.map(T=>({path:T.path,absolutePath:T.absolutePath,status:T.status}))}:null,untrackedDeferred:m?.untrackedDeferred??s.untrackedDeferred,error:m?.error??s.error},E=g?n.map(T=>T.root===l?b:T):[...n,b];return{files:Array.from(r).filter(T=>xt(T,d)!==l).concat(x),repositories:E,repoFilters:hh(E,d)}}function xt(r,n){return r.repoRoot??n}function zl(r){return`${r.repoRoot??""}\0${r.path}`}function kr(r){return r.absolutePath||r.path}function al(r){return zl(r)}function Yx(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function Fu(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function _u(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Ks(r){let n=0;const s=r??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function qs(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function Sr(r){return r instanceof DOMException&&r.name==="AbortError"}function Xx(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Bu(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function ol(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Ou(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,d=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(d)&&d>0&&Number.isFinite(c)&&c>0?{start:Math.min(d,c),end:Math.max(d,c)}:{start:n,end:s}}function Jx({actions:r,running:n,completed:s}){const{t:l}=ft(),[d,c]=a.useState(!1),m=a.useRef(null),g=r.find(p=>n?.action===p.key),f=r.find(p=>s?.action===p.key);return r.length===0?null:(a.useEffect(()=>{if(!d)return;const p=h=>{const b=h.target;b instanceof Node&&m.current?.contains(b)||c(!1)},x=h=>{h.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",p),document.addEventListener("keydown",x),()=>{document.removeEventListener("pointerdown",p),document.removeEventListener("keydown",x)}},[d]),e.jsxs("div",{ref:m,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),c(x=>!x)},disabled:r.every(p=>p.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 ${d?"bg-surface-elevated text-foreground":f?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:g?.label??f?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(dt,{size:13,className:"animate-spin"}):f?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(wo,{size:14})}),d&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(p=>{const x=n?.action===p.key,h=s?.action===p.key;return e.jsxs("button",{type:"button",onClick:b=>{b.stopPropagation(),p.onClick(),c(!1)},disabled:p.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 ${h?"bg-accent/10 text-accent":p.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:x?e.jsx(dt,{size:13,className:"animate-spin"}):h?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:p.label})]},p.key)})})]}))}function Qx(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function ph(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Qx(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function ms(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const il=new WeakMap;function Lo(r){const n=il.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),il.delete(r)},1700);il.set(r,s)}function Zx(r){const n=CSS.escape(r),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let d=null;for(const g of l){if(!ms(g))continue;const f=g.querySelector(s);if(f&&ms(f)){d=f;break}}if(d??=Array.from(document.querySelectorAll(s)).find(ms)??null,!d)return;const c=ph(d);if(!c){d.scrollIntoView({block:"start",behavior:"smooth"}),Lo(d);return}const m=d.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,m),behavior:"instant"}),Lo(d)}function En(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,d=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,m=[s!==null&&d?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null&&d?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`: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(S=>!!S),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let f=null;for(const S of g)if(ms(S)){for(const T of m){const D=S.querySelector(T);if(D&&ms(D)){f=D;break}}if(f)break}if(f??=m.flatMap(S=>Array.from(document.querySelectorAll(S))).find(ms)??null,!f){Zx(r.filePath);return}const p=ph(f);if(!p){f.scrollIntoView({block:"center",behavior:"smooth"}),Lo(f);return}const x=f.getBoundingClientRect(),h=p.getBoundingClientRect(),E=x.top-h.top+p.scrollTop-Math.max(24,(p.clientHeight-x.height)/2);p.scrollTo({top:Math.max(0,E),behavior:"instant"}),Lo(f)}const gh=1,Wl=8;function e0(r,n=Wl){return Math.min(n,Math.max(gh,r))}function bh({resetKey:r,maxScale:n=Wl,onZoomChange:s,onDoubleTap:l,children:d}){const c=a.useRef(null),[m,g]=a.useState({scale:1,x:0,y:0}),[f,p]=a.useState(!1),x=a.useRef(null),h=a.useRef(new Set),b=a.useRef(!1),E=a.useRef(null),S=a.useRef(0),T=a.useRef(m);T.current=m,a.useEffect(()=>{g({scale:1,x:0,y:0})},[r]);const D=a.useCallback((P,B,q)=>{const j=c.current;if(!j)return{x:B,y:q};const o=j.firstElementChild instanceof HTMLElement?j.firstElementChild:null,_=o?.clientWidth||j.clientWidth,I=o?.clientHeight||j.clientHeight,V=Math.max(0,(_*P-j.clientWidth)/2),W=Math.max(0,(I*P-j.clientHeight)/2);return{x:Math.min(V,Math.max(-V,B)),y:Math.min(W,Math.max(-W,q))}},[]),F=a.useCallback((P,B,q)=>{g(j=>{const o=e0(P,n),_=c.current;if(!_||o===1)return{scale:o,x:0,y:0};const I=_.getBoundingClientRect(),V=(B??I.left+I.width/2)-I.left-I.width/2,W=(q??I.top+I.height/2)-I.top-I.height/2,O=o/j.scale,R=V-(V-j.x)*O,H=W-(W-j.y)*O;return{scale:o,...D(o,R,H)}})},[D,n]),M=a.useCallback((P,B)=>{p(!0),T.current.scale>1?g({scale:1,x:0,y:0}):F(2.5,P,B),window.setTimeout(()=>p(!1),220)},[F]);a.useEffect(()=>{const P=c.current;if(!P)return;const B=o=>{if(o.pointerType==="mouse"&&o.button!==0)return;const _=h.current.size===0;if(h.current.add(o.pointerId),_){const I=Date.now(),V=E.current;if(V&&I-V.time<350&&Math.hypot(o.clientX-V.x,o.clientY-V.y)<24){E.current=null,S.current=I,l?.(),M(o.clientX,o.clientY);return}}if(h.current.size>1){b.current=!0,x.current=null;return}if(!(T.current.scale<=1)){o.preventDefault(),x.current={pointerId:o.pointerId,startX:o.clientX,startY:o.clientY,originX:T.current.x,originY:T.current.y,moved:!1};try{P.setPointerCapture?.(o.pointerId)}catch{}p(!1)}},q=o=>{const _=x.current;if(!_||_.pointerId!==o.pointerId)return;const I=o.clientX-_.startX,V=o.clientY-_.startY;if(!_.moved){if(Math.hypot(I,V)<6)return;_.moved=!0}o.stopPropagation(),o.preventDefault(),g(W=>({...W,...D(W.scale,_.originX+I,_.originY+V)}))},j=o=>{const _=x.current,I=_?.pointerId===o.pointerId&&_.moved;if(_?.pointerId===o.pointerId){_.moved&&o.stopPropagation(),x.current=null;try{P.releasePointerCapture?.(o.pointerId)}catch{}}h.current.delete(o.pointerId)&&h.current.size===0&&(!b.current&&!I&&(E.current={time:Date.now(),x:o.clientX,y:o.clientY}),b.current=!1)};return P.addEventListener("pointerdown",B,{capture:!0,passive:!1}),window.addEventListener("pointermove",q,{capture:!0,passive:!1}),window.addEventListener("pointerup",j,{capture:!0}),window.addEventListener("pointercancel",j,{capture:!0}),()=>{P.removeEventListener("pointerdown",B,{capture:!0}),window.removeEventListener("pointermove",q,{capture:!0}),window.removeEventListener("pointerup",j,{capture:!0}),window.removeEventListener("pointercancel",j,{capture:!0})}},[D,l,M]),Ju({onPinch:({offset:[P],origin:[B,q]})=>{p(!1),F(P,B,q)},onWheel:({event:P,delta:[B,q],ctrlKey:j})=>{if(j){P.preventDefault(),P.stopPropagation(),p(!1),F(T.current.scale*(1-q*.01),P.clientX,P.clientY);return}T.current.scale<=1||(P.preventDefault(),P.stopPropagation(),p(!1),g(o=>({...o,...D(o.scale,o.x-B,o.y-q)})))}},{target:c,eventOptions:{passive:!1},pinch:{scaleBounds:{min:gh,max:n},from:()=>[T.current.scale,0],rubberband:!0}});const N=m.scale>1;return a.useEffect(()=>{s?.(N)},[s,N]),e.jsx("div",{ref:c,"data-sidebar-gesture-ignore":N?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden","data-image-zoom-viewport":!0,style:{cursor:N?"grab":"zoom-in"},onDoubleClick:P=>{P.stopPropagation(),!(Date.now()-S.current<500)&&(l?.(),M(P.clientX,P.clientY))},children:d({scale:m.scale,zoomed:N,animateTransform:f,transformStyle:{transform:`translate3d(${m.x}px, ${m.y}px, 0) scale(${m.scale})`,transformOrigin:"center center",transition:f?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${m.x}px, ${m.y}px, 0)`,transformOrigin:"center center",transition:f?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function xh({src:r,alt:n,vector:s,onLoad:l,onError:d,onZoomChange:c,onDoubleTap:m}){const g=Ao(r,d),[f,p]=a.useState(null),x=s??ia(r);return a.useEffect(()=>{p(null)},[r]),e.jsx(bh,{resetKey:r,maxScale:Math.max(Wl,f?.originalScale??1),onZoomChange:c,onDoubleTap:m,children:({vectorTransformStyle:h,scale:b,animateTransform:E})=>e.jsx("div",{"data-image-zoom-surface":!0,"data-vector-zoom-surface":x?"":void 0,className:"relative shrink-0 touch-none select-none",style:f?{...h,width:f.width,height:f.height}:{width:"100%",height:"100%"},children:e.jsx("img",{src:g,alt:n,draggable:!1,className:"touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:{position:"absolute",left:"50%",top:"50%",width:f?f.width*b:void 0,height:f?f.height*b:void 0,maxWidth:f?"none":"100%",maxHeight:f?"none":"100%",transform:"translate(-50%, -50%)",transition:E?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"},onLoad:S=>{const T=S.currentTarget,D=T.closest("[data-image-zoom-viewport]");if(D&&T.naturalWidth>0&&T.naturalHeight>0){const F=Math.max(1,D.clientWidth-2),M=Math.max(1,D.clientHeight-2),N=Math.min(F/T.naturalWidth,M/T.naturalHeight),P=x?N:Math.min(N,1);p({width:T.naturalWidth*P,height:T.naturalHeight*P,originalScale:1/P})}l(S)},onError:d})})})}function t0({svg:r,title:n,scale:s,vectorTransformStyle:l}){const d=a.useRef(null);return a.useLayoutEffect(()=>{const c=d.current,m=c?.querySelector("svg");if(!c||!m)return;const g=()=>{const x=m.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let h=x[2],b=x[3];if((!Number.isFinite(h)||!Number.isFinite(b)||h<=0||b<=0)&&(h=Number(m.getAttribute("width")),b=Number(m.getAttribute("height"))),!Number.isFinite(h)||!Number.isFinite(b)||h<=0||b<=0)return;const E=Math.max(1,c.clientWidth-24),S=Math.max(1,c.clientHeight-24),T=Math.min(E/h,S/b,1);m.style.width=`${Math.max(1,Math.floor(h*T*s))}px`,m.style.height=`${Math.max(1,Math.floor(b*T*s))}px`,m.style.maxWidth="none",m.style.maxHeight="none",m.style.transform=String(l.transform??""),m.style.transformOrigin="center center",m.style.transition=String(l.transition??"none")};g();const f=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return f?.observe(c),()=>f?.disconnect()},[s,r,l]),e.jsx("div",{ref:d,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function r0({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(bh,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:d,scale:c})=>e.jsx(t0,{svg:r,title:n,scale:c,vectorTransformStyle:d})})}let n0=0,s0=0,a0=0,o0=0,i0=0;function yo(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function ct(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++s0,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Vs(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++o0,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function l0(){return`diff-ui-${Date.now().toString(36)}-${(++i0).toString(36)}`}function c0(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function d0(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Po({onReviewReference:r,filePath:n,active:s=!0,onInsertReference:l,onInsertText:d,onInsertFeature:c,onReferenceCopied:m,onClose:g,onDirectoryLinkOpen:f,isMobile:p,markdownOutlineOpen:x,markdownOutlineCloseSignal:h,onOpenMarkdownOutline:b,onCloseMarkdownOutline:E,markdownImageLightboxOpen:S,markdownImageLightboxCloseSignal:T,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:F,lineRange:M,onLineRangeChange:N,insertedReferenceKey:P,copiedReferenceKey:B,scrollToLine:q,onScrollToLineHandled:j}){const{t:o}=ft(),_=a.useRef(null),I=a.useRef({}),V=a.useRef(s);V.current=s,a.useEffect(()=>{s||_.current?.querySelectorAll("video").forEach(A=>A.pause())},[s]);const W=Q(A=>A.rootPath),O=Q(A=>A.selectFile),[R,H]=a.useState({kind:"idle"}),[ee,L]=a.useState("schematic"),[U,X]=a.useState(null),ce=a.useRef(null),[he,Re]=a.useState(null),Ce=a.useRef(new Map),$e=a.useRef(null),[J,xe]=a.useState(null),[fe,Fe]=a.useState(()=>ju()),[Oe,G]=a.useState(()=>uu(W,n)),Ne=a.useRef(null),[Se,de]=a.useState(!1),[qe,$]=a.useState(null),[me,ge]=a.useState(0),[Le,ne]=a.useState([]),[Ye,Je]=a.useState(null),De=a.useRef(null),Te=a.useRef(n),[_e,Be]=a.useState(null),te=Gg(W&&n&&!n.startsWith("/")?`${W}/${n}`:n,s),[ye,nt]=a.useState(!1),[vt,Zt]=a.useState(""),[z,oe]=a.useState([]),[je,Qe]=a.useState(0),At=a.useRef(null),Rr=lf(m),er=Hl(W,n);a.useEffect(()=>{if(Te.current===n)return;Te.current=n;const A=n&&W&&!n.startsWith("/")?`${W}/${n}`:n;if(De.current===A){De.current=null;return}De.current=null,ne([]),Je(null),nt(!1),Zt("")},[n,W]);const yt=n?W&&!n.startsWith("/")?`${W}/${n}`:n:null,cr=Q(A=>yt?(A.fileChangeVersions.get(yt)??0)+A.fileWatchEpoch:A.fileWatchEpoch),tr=a.useRef(null),$n=a.useRef(null),[Ln,Do]=a.useState(0),Jr=a.useCallback(()=>Do(A=>A+1),[]);a.useEffect(()=>{const A=ce.current;return ce.current=null,X(null),A&&URL.revokeObjectURL(A.objectUrl),()=>{const K=ce.current;ce.current=null,K&&URL.revokeObjectURL(K.objectUrl)}},[yt,cr,Ln]),a.useEffect(()=>{if(!n){tr.current=null,H({kind:"idle"});return}const A=W&&!n.startsWith("/")?`${W}/${n}`:n,K=new AbortController,be=++n0,ke=`right-sidebar-file-preview:${be}`,We=performance.now();let Ue=!1;const tt=(re,Ke={})=>{Ue||(Ue=!0,yo("end",{loadingId:be,reason:re,durationMs:Math.round(performance.now()-We),filePath:n,fullPath:A,rootPath:W,...Ke}))};let Ge=null;const ht=Im(A),bt=ht?A.toLowerCase().endsWith(".kicad_pcb")?ee==="schematic"?"pcb-front":ee:"schematic":ee,fr=!ht&&$l(A),Ar=!ht&&!fr&&Dm(A),Bn=!ht&&!fr&&!Ar&&Wu(A),sn=Gs(A),ys=Hs(A),hr=ht?"eda":fr?"image":Ar?"model3d":Bn?"video":"text",ws=tr.current!==A;if(tr.current=A,ws){yo("start",{loadingId:be,filePath:n,fullPath:A,rootPath:W,mode:hr,externalVersion:cr}),H({kind:"loading",mode:hr}),$n.current=null;const re=Iu(W,n);N(re?.lineRange??null),Fe(sn?ju():"source"),G(ys?uu(W,n):"source"),ht&&L(Fm(A))}ws||H(re=>re.kind==="error"?{kind:"loading",mode:hr}:re);const an=window.setTimeout(()=>{Ue||K.signal.aborted||yo("still_active",{loadingId:be,filePath:n,fullPath:A,rootPath:W,mode:hr,durationMs:Math.round(performance.now()-We),isPathChange:ws})},3e3),zr=window.setTimeout(()=>{if(Ue||K.signal.aborted)return;const re=ht?o("rightSidebar.edaTimeout"):Ar?o("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";K.abort(new DOMException(re,"TimeoutError")),H({kind:"error",message:re}),tt("stuck_timeout",{error:re})},ht?_m+5e3:Ar?Bm+5e3:Om(A)?35e3:Gb);if(ht){const re=bt==="pcb-3d"?ce.current:null;re?(H(re),tt("eda_3d_client_cache_hit",{bytes:re.meta.size,view:re.view,mimeType:re.meta.mimeType})):Um(A,bt,K.signal,"view_file",ke).then(Ke=>{if(K.signal.aborted)return;Ge=URL.createObjectURL(Ke.blob);const Kt={kind:"eda",sourcePath:Ke.path||A,objectUrl:Ge,view:Ke.view,meta:{size:Ke.size,mimeType:Ke.mimeType,modified:Ke.modified}};if(Ke.view==="pcb-3d"){const Tr=ce.current;Tr&&Tr.objectUrl!==Ge&&URL.revokeObjectURL(Tr.objectUrl),ce.current=Kt,X(Kt),Ge=null}H(Kt),tt("eda_loaded",{bytes:Ke.size,view:Ke.view,mimeType:Ke.mimeType})}).catch(Ke=>{K.signal.aborted||(H({kind:"error",message:Ke instanceof Error&&/timed out/i.test(Ke.message)?o("rightSidebar.edaTimeout"):Ke instanceof Error?Ke.message:o("rightSidebar.edaLoadFailed")}),tt("error",{error:Ke instanceof Error?Ke.message:String(Ke)}))})}else if(fr)Hm(A,K.signal,"view_file",ke).then(re=>{Ge=URL.createObjectURL(re.blob),H({kind:"image",objectUrl:Ge,meta:{size:re.size,mimeType:re.mimeType,modified:re.modified}}),tt("image_loaded",{bytes:re.size,mimeType:re.mimeType})}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error?re.message:o("rightSidebar.imageLoadFailed")}),tt("error",{error:re instanceof Error?re.message:String(re)}))});else if(Ar)zm(A,K.signal,"view_file",ke).then(re=>{K.signal.aborted||(Ge=URL.createObjectURL(re.blob),H({kind:"model3d",sourcePath:re.path||A,objectUrl:Ge,ext:re.ext,meta:{size:re.size,mimeType:re.mimeType,modified:re.modified}}),tt("model3d_loaded",{bytes:re.size,ext:re.ext}))}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error&&(re.name==="TimeoutError"||/timed out/i.test(re.message))?o("rightSidebar.model3dTimeout"):re instanceof Error?re.message:o("rightSidebar.model3dLoadFailed")}),tt("error",{error:re instanceof Error?re.message:String(re)}))});else if(Bn){const re=Wm(A)??"",Ke=Gu(A);H(Kt=>Kt.kind==="video"&&Kt.url===Ke?Kt:{kind:"video",url:Ke,meta:{size:null,mimeType:re,modified:null}}),tt("video_ready",{mimeType:re})}else Fd(A,K.signal,"view_file",ke).then(re=>{if(!K.signal.aborted){if(re.binary){H({kind:"binary"});return}H({kind:"text",content:re.content,sourcePath:re.path||A,meta:{size:re.size,truncated:re.truncated}}),tt("text_loaded",{bytes:re.size,truncated:!!re.truncated})}}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error?re.message:"Failed to read file"}),tt("error",{error:re instanceof Error?re.message:String(re)}))});return()=>{K.abort(),Ct(ke),window.clearTimeout(an),window.clearTimeout(zr),Ge&&URL.revokeObjectURL(Ge),tt("cleanup")}},[n,W,cr,Ln,N,o,ee]),a.useEffect(()=>{if(R.kind!=="model3d"||!n){Re(null);return}let A=!1;const K=n.lastIndexOf("/"),be=K>=0?n.slice(K+1):n,ke=K>=0?n.slice(0,K):"",We=ke.lastIndexOf("/"),Ue=We>=0?ke.slice(0,We):"",tt=be.replace(/\.(stl|glb|gltf)$/i,""),Ge=`${Ue?`${Ue}/`:""}features/${tt}.json`;return Fd(Ge).then(ht=>{if(!A)try{const bt=JSON.parse(ht.content);Re(bt.version===1&&Array.isArray(bt.features)&&bt.features.length>0?bt.features:null)}catch{Re(null)}}).catch(()=>{A||Re(null)}),()=>{A=!0}},[R,n]),a.useEffect(()=>{if(R.kind!=="text"){Be(null);return}const A=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,K=nf(A),be=R.content,ke=Gs(A??"")&&fe==="preview",We=Hs(A??"")&&Oe==="preview";if(!K||ke||We||!sf(be)){Be(null);return}let Ue=!1;const tt=Ge=>{if(Ue||!Ge.registered(K)){Ue||Be(null);return}try{Be(of(Ge,be,K))}catch{Be(null)}};return qe?tt(qe):(Be(null),af().then(Ge=>{Ue||($(Ge),tt(Ge))}).catch(()=>{})),()=>{Ue=!0}},[R,qe,n,W,fe,Oe]),a.useLayoutEffect(()=>{if(!er||R.kind!=="text")return;const A=`${er}:${fe}:${Oe}`;if($n.current===A)return;const K=Iu(W,n);if($n.current=A,!K)return;const be=requestAnimationFrame(()=>{const ke=$e.current;if(!ke)return;const We=fe==="preview"?K.markdownTop??K.top:K.top;ke.scrollTo({top:Math.max(0,We??0),left:Math.max(0,K.left??0)}),ge(fe==="preview"?Math.max(0,We??0):0)});return()=>cancelAnimationFrame(be)},[n,fe,Oe,R.kind,er,W]),a.useEffect(()=>{er&&tl(W,n,{lineRange:M})},[n,M,er,W]),a.useEffect(()=>{if(q==null||R.kind!=="text")return;xe(null),N({start:q,end:q});const A=q,K=requestAnimationFrame(()=>{const be=Ce.current.get(A);be&&be.scrollIntoView({block:"center"}),j?.()});return()=>cancelAnimationFrame(K)},[q,R,N,j]);const Pn=a.useCallback(A=>{const K=$e.current;if(!K)return!1;const be=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(A):A.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ke=K.querySelector(`#${be}`);return ke?(ke.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const A=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,K=R.kind==="text"&&Gs(A??"")&&fe==="preview";if(!Ye||!K)return;const be=requestAnimationFrame(()=>{Pn(Ye)&&Je(null)});return()=>cancelAnimationFrame(be)},[n,Pn,fe,Ye,R,W]),a.useLayoutEffect(()=>{const A=$e.current;if(!A||!M){xe(null);return}if(J)return;const K=R.kind==="image"||R.kind==="loading"&&R.mode==="image",be=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,ke=R.kind==="text"&&Gs(be??"")&&fe==="preview",We=R.kind==="text"&&Hs(be??"")&&Oe==="preview";if(R.kind!=="text"||K||ke||We){xe(null);return}const Ue=()=>{const Ge=Ce.current.get(M.end);if(!Ge||!A){xe(null);return}const ht=Ge.offsetTop+Ge.offsetHeight/2,bt=A.scrollLeft+Math.max(8,A.clientWidth-120);xe({top:ht,left:bt})};Ue();const tt=new ResizeObserver(()=>Ue());return tt.observe(A),()=>tt.disconnect()},[M,J,R,fe,Oe,n,W,_e]);const gt=R.kind==="text"&&!(Hs(yt??"")&&Oe==="preview")&&!yt?.toLowerCase().endsWith(".csv")&&!yt?.toLowerCase().endsWith(".kicad_pro")&&!yt?.toLowerCase().endsWith(".kicad_prl"),Qr=a.useCallback(()=>{nt(!1),Zt(""),oe([]),Qe(0),io(I.current)},[]),Cr=a.useCallback(()=>{!s||!gt||(nt(!0),requestAnimationFrame(()=>{const A=_.current;!V.current||!A?.isConnected||A.closest('[inert], [aria-hidden="true"], [hidden]')||A.getClientRects().length===0||getComputedStyle(A).visibility==="hidden"||!A.contains(document.activeElement)||(At.current?.focus(),At.current?.select())}))},[s,gt]),Nr=a.useCallback(A=>{Qe(K=>z.length===0?0:(K+A+z.length)%z.length)},[z.length]),la=a.useCallback(A=>{if(A.nativeEvent.isComposing||!Cb(_.current,s,A))return;const K=Nb(A);if(K==="open"&&gt){A.preventDefault(),Cr();return}ye&&(K==="close"?(A.preventDefault(),Qr()):(K==="next"||K==="previous")&&(A.preventDefault(),Nr(K==="previous"?-1:1)))},[s,Qr,ye,Nr,Cr,gt]);if(a.useLayoutEffect(()=>{if(io(I.current),!s||!ye||!vt.trim()||!$e.current){oe([]),Qe(0);return}const A=Mb($e.current,vt);return oe(A),Qe(0),(_.current?.contains(document.activeElement)||pu(I.current))&&(qi(A,0,I.current),gu(A[0])),()=>io(I.current)},[s,ye,vt,_e,fe,R]),a.useEffect(()=>{!s||!ye||!vt.trim()||!_.current?.contains(document.activeElement)&&!pu(I.current)||(qi(z,je,I.current),gu(z[je]))},[s,je,z,ye,vt]),a.useEffect(()=>()=>io(I.current),[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:o("rightSidebar.selectFilePrompt")});const Xe=W&&!n.startsWith("/")?`${W}/${n}`:n,Er=vo(Xe,W),Ht=Yu(Xe,W),Ur=R.kind==="text"&&R.content?R.content.split(`
1654
- `):[],zt=Math.max(2,String(Ur.length).length)+1,Mr=R.kind==="text"||R.kind==="image"||R.kind==="model3d"||R.kind==="video"||R.kind==="eda"?R.meta:null,$r=Gs(Xe),ca=Xe.toLowerCase().endsWith(".csv"),Zr=Xe.toLowerCase().endsWith(".kicad_pro"),An=Xe.toLowerCase().endsWith(".kicad_prl"),en=R.kind==="text"&&$r&&fe==="preview",wt=Hs(Xe),Tt=R.kind==="text"&&wt&&Oe==="preview",ps=R.kind==="image"||R.kind==="loading"&&R.mode==="image",gs=R.kind==="model3d"||R.kind==="loading"&&R.mode==="model3d",bs=R.kind==="video"||R.kind==="loading"&&R.mode==="video",xs=R.kind==="eda"||R.kind==="loading"&&R.mode==="eda",da=R.kind==="text"?R.sourcePath:Xe,dr=gp(da,W,M),Lr=(()=>{if(!M||R.kind!=="text"||Ur.length===0)return dr;const A=[];for(let ke=M.start;ke<=M.end;ke+=1)A.push(`${ke} ${Ur[ke-1]??""}`);const K=Tf(Xe).replace(/^\./,""),be="```";return`${dr}
1642
+ `),lang:C,blockKey:`${n}-code-${P}`,codeStartLine:m(P)+1});continue}if(Eo(g)){const F=[],M=c;for(;c<r.length&&(Eo(r[c])||!r[c].trim());)F.push(r[c].trim()?sh(r[c]):""),c+=1;d.push({kind:"code",key:`${n}-indented-code-${M}`,code:F.join(`
1643
+ `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${M}`,codeStartLine:m(M)});continue}const h=f.match(/^(#{1,6})\s+(.+)$/);if(h){const M=`h${Math.min(6,h[1].length+1)}`,C=Wf(h[2]),P=Cl(C,s);d.push({kind:"static",node:e.jsx(M,{id:P,className:"scroll-mt-16 font-semibold text-foreground",children:ut(C,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<r.length&&g.includes("|")&&$o(r[c+1])){const F=ia(g),M=oh(r[c+1]),C=[],P=c;for(c+=2;c<r.length&&r[c].includes("|")&&r[c].trim();)C.push(ia(r[c])),c+=1;d.push({kind:"static",node:e.jsx("div",{className:Tf,"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:F.map((B,q)=>e.jsx("th",{className:`${Pf} ${Mo(M[q]??null)}`,children:e.jsx("div",{className:No,children:ut(B,`${n}-th-${P}-${q}`,!0,s)})},`h-${q}`))})}),e.jsx("tbody",{children:C.map((B,q)=>e.jsx("tr",{className:"border-t border-border/10",children:F.map((j,o)=>e.jsx("td",{className:`${Af} ${Mo(M[o]??null)}`,children:e.jsx("div",{className:No,children:ut(B[o]??"",`${n}-td-${P}-${q}-${o}`,!0,s)})},`c-${o}`))},`r-${q}`))})]})},`${n}-table-${P}`)});continue}const b=la(g);if(b){const F=b.ordered,M=Do(g),C=b.start,P=c,B=Ol(r,c,M,F,!1);c=B.nextIndex,d.push({kind:"list",keyPrefix:`${n}-list-${P}`,ordered:F,start:F?C:void 0,renders:Ul(B.items,`${n}-list-${P}`,s,m(0)-1)});continue}const E=[g.trimStart()],S=[m(c)],T=c;for(c+=1;c<r.length&&r[c].trim()&&!Nl(r[c])&&!(c+1<r.length&&r[c].includes("|")&&$o(r[c+1]));)E.push(r[c].trimStart()),S.push(m(c)),c+=1;const D=$l(E,`${n}-p-${T}`,s);d.push({kind:"paragraph",keyPrefix:`${n}-p-${T}`,perLine:D.perLine,hardBreaks:D.hardBreaks,lineNums:S})}return d}function Bx(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Ll(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:Hl(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(Lo,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}const ho=16,lh=192;function Ox(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,d,c]=l;if(!Number.isFinite(d)||!Number.isFinite(c)||d<=0||c<=0)return r;const m=Math.max(lh,Math.ceil(d)),g=Math.ceil(m/d*c);return r.replace(/<svg\b([^>]*)>/i,(f,p)=>`<svg${p.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${m}" height="${g}">`)}function Ux(r){const n=r?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-ho,d=s.y-ho,c=s.width+ho*2,m=s.height+ho*2,g=Math.max(lh,Math.ceil(c)),f=Math.ceil(g/c*m);n.setAttribute("viewBox",`${l} ${d} ${c} ${m}`),n.setAttribute("width",String(g)),n.setAttribute("height",String(f)),n.removeAttribute("style")}function Hx(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return cf(`code.${s}`)??s}function ch({code:r,blockKey:n}){const{t:s}=ft(),[l,d]=a.useState(null),[c,m]=a.useState(!1),g=a.useRef(null),f=a.useContext(Hf);a.useEffect(()=>{let x=!1;return d(null),m(!1),gg().then(async h=>{bg(h);const b=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:E}=await h.render(b,r);x||d(Ox(E))}).catch(()=>{x||m(!0)}),()=>{x=!0}},[n,r]),a.useLayoutEffect(()=>{l&&Ux(g.current)},[l]);const p=a.useCallback(()=>{const x=g.current?.querySelector("svg")?.outerHTML??l;x&&f?.(x)},[f,l]);return c?e.jsx(Lo,{code:r,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:x=>{x.stopPropagation(),p()},children:e.jsx("span",{ref:g,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function Lo({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:d}){const c=Hx(n),[m,g]=a.useState(null);a.useEffect(()=>{if(!c||!df(r)){g(null);return}let p=!1;return uf().then(x=>{if(p||!x.registered(c)){p||g(null);return}try{g(ff(x,r,c))}catch{p||g(null)}}).catch(()=>{p||g(null)}),()=>{p=!0}},[s,r,c]);const f=m??(r||" ").split(`
1644
+ `).map(p=>[p||" "]);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:`${Dl} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:f.map((p,x)=>{const h=l!=null?l+x:null,b=!!(d&&h!=null&&h>=d.start&&h<=d.end);return e.jsxs("span",{"data-md-ref-start":h??void 0,"data-md-ref-end":h??void 0,"data-selected":b?"true":void 0,children:[p,x<f.length-1?`
1645
+ `:null]},`${s}-line-${x}`)})})})]})}function zl(r,n,s,l,d){const c=new dg;c.validateLines(r),r=xx(r);const m=gx(r),g=qf(r),f=[],p={budget:c,markdownFilePath:n,rootPath:s,referenceDefinitions:m,footnoteDefinitions:bx(r),headingSlugCounts:new Map,images:f,onImageOpen:l,footnotesLabel:d?.footnotes??"Footnotes",backToFootnoteLabel:d?.backToFootnote??(E=>`Back to footnote ${E}`)},x=[];let h=0;for(;h<r.length;){p.budget.check();const E=r[h],S=E.trim();if(Co(E)||g.has(h)){h+=1;continue}if(!S){h+=1;continue}if(/^<details>\s*$/i.test(S)){const j=h;let o="Details";const _=[];for(h+=1;h<r.length&&!/^<\/details>\s*$/i.test(r[h].trim());){const I=r[h].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);I?o=I[1].trim()||o:_.push(r[h].trimStart()),h+=1}h<r.length&&(h+=1),x.push({key:`details-${j}`,startLine:j+1,endLine:h,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:ut(o,`details-${j}-summary`,!0,p)}),_.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:ah(_,`details-${j}`,p)})]})});continue}const T=th(E);if(T){const j=[E],o=h;for(h+=1;h<r.length&&!T.selfContained&&!new RegExp(`</${T.tag}>`,"i").test(r[h]);)j.push(r[h]),h+=1;h<r.length&&!T.selfContained&&(j.push(r[h]),h+=1),x.push({key:`html-${o}`,startLine:o+1,endLine:h,content:e.jsx(eh,{html:j.join(`
1646
+ `)})});continue}const D=S.match(/^(```|~~~)\s*(.*)$/);if(D){const j=[],o=D[1],_=D[2]?.trim(),I=h;for(h+=1;h<r.length&&!r[h].trim().startsWith(o);)j.push(r[h]),h+=1;h<r.length&&(h+=1),x.push({key:`code-${I}`,startLine:I+1,endLine:h,fineGrained:_.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(_.toLowerCase()),content:_.toLowerCase()==="mermaid"?e.jsx(ch,{code:j.join(`
1647
+ `),blockKey:`code-${I}`}):["math","latex","tex"].includes(_.toLowerCase())?e.jsx(oa,{tex:j.join(`
1648
+ `),display:!0}):V=>e.jsx(Lo,{code:j.join(`
1649
+ `),lang:_,blockKey:`code-${I}`,codeStartLine:I+2,lineRange:V})});continue}if(Eo(E)){const j=[],o=h;for(h+=0;h<r.length&&(Eo(r[h])||!r[h].trim());)j.push(r[h].trim()?sh(r[h]):""),h+=1;x.push({key:`indented-code-${o}`,startLine:o+1,endLine:h,fineGrained:!0,content:_=>e.jsx(Lo,{code:j.join(`
1650
+ `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${o}`,codeStartLine:o+1,lineRange:_})});continue}if(S.startsWith("$$")){const j=[],o=h,_=S.replace(/^\$\$\s*/,"");if(_.endsWith("$$")&&_.length>2)j.push(_.replace(/\s*\$\$$/,"")),h+=1;else{for(_&&j.push(_),h+=1;h<r.length&&!r[h].trim().endsWith("$$");)j.push(r[h]),h+=1;if(h<r.length){const I=r[h].trim().replace(/\s*\$\$$/,"");I&&j.push(I),h+=1}}x.push({key:`math-${o}`,startLine:o+1,endLine:h,content:e.jsx(oa,{tex:j.join(`
1651
+ `),display:!0})});continue}if(h+1<r.length&&S&&!Nl(E)&&/^(=+|-+)\s*$/.test(r[h+1].trim())){const j=r[h+1].trim().startsWith("=")?1:2,o=`h${j}`,_=Cl(S,p),I={level:j,text:Iu(S),id:_};x.push({key:`setext-heading-${h}`,startLine:h+1,endLine:h+2,heading:I,content:e.jsx(o,{id:_,className:`scroll-mt-16 font-semibold text-foreground ${j===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:ut(S,`setext-heading-${h}`,!0,p)})}),h+=2;continue}const F=S.match(/^(#{1,6})\s+(.+)$/);if(F){const j=F[1].length,o=Wf(F[2]),_={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"},I=`h${j}`,V=Cl(o,p),W={level:j,text:Iu(o),id:V};x.push({key:`heading-${h}`,startLine:h+1,endLine:h+1,heading:W,content:e.jsx(I,{id:V,className:`scroll-mt-16 font-semibold text-foreground ${_[j]}`,children:ut(o,`heading-${h}`,!0,p)})}),h+=1;continue}if(Of(E)){x.push({key:`hr-${h}`,startLine:h+1,endLine:h+1,content:e.jsx("hr",{className:"border-border/20"})}),h+=1;continue}if(S.startsWith(">")){const j=[],o=[],_=h;for(;h<r.length&&/^>\s?/.test(r[h].trim());)j.push(r[h].trim().replace(/^>\s?/,"")),o.push(h+1),h+=1;const I=j[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(I){const W=I[1].toUpperCase(),O=I[2]?.trim(),R=[...O?[O]:[],...j.slice(1)],H=[...O?[o[0]]:[],...o.slice(1)],ee=$l(R,`callout-${_}`,p);x.push({key:`callout-${_}`,startLine:_+1,endLine:h,fineGrained:!0,content:L=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:W}),R.length>0&&e.jsx("div",{children:Ll(ee.perLine,ee.hardBreaks,H,`callout-${_}`,L)})]})});continue}const V=_x(j,`quote-${_}`,p,o);x.push({key:`quote-${_}`,startLine:_+1,endLine:h,fineGrained:!0,content:W=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Bx(V,W)})});continue}if(h+1<r.length&&E.includes("|")&&$o(r[h+1])){const j=ia(E),o=oh(r[h+1]),_=[],I=h;for(h+=2;h<r.length&&r[h].includes("|")&&r[h].trim();)_.push(ia(r[h])),h+=1;const V=j.map((O,R)=>ut(O,`th-${I}-${R}`,!0,p)),W=_.map((O,R)=>j.map((H,ee)=>ut(O[ee]??"",`td-${I}-${R}-${ee}`,!0,p)));x.push({key:`table-${I}`,startLine:I+1,endLine:h,interactive:!1,kind:"table",content:O=>{const R=H=>!!(O&&H>=O.start&&H<=O.end);return e.jsx("div",{className:Tf,"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":I+1,"data-md-ref-start":I+1,"data-md-ref-end":I+1,"data-selected":R(I+1)?"true":void 0,children:V.map((H,ee)=>e.jsx("th",{className:`${Pf} ${Mo(o[ee]??null)}`,children:e.jsx("div",{className:No,children:H})},`h-${ee}`))})}),e.jsx("tbody",{children:W.map((H,ee)=>{const L=I+ee+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":L,"data-md-ref-start":L,"data-md-ref-end":L,"data-selected":R(L)?"true":void 0,children:j.map((U,X)=>e.jsx("td",{className:`${Af} ${Mo(o[X]??null)}`,children:e.jsx("div",{className:No,children:H[X]})},`c-${X}`))},`r-${ee}`)})})]})})}});continue}const M=la(E);if(M){const j=M.ordered,o=Do(E),_=M.start,I=h,V=Ol(r,h,o,j,!0,g);h=V.nextIndex;const W=j?"ol":"ul",O=Ul(V.items,`list-${I}`,p);x.push({key:`list-${I}`,startLine:I+1,endLine:h,fineGrained:!0,content:R=>e.jsx(W,{start:j?_:void 0,className:`${j?"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:Hl(O,R)})});continue}const C=[E.trimStart()],P=[h+1],B=h;for(h+=1;h<r.length&&r[h].trim()&&!Nl(r[h])&&!(h+1<r.length&&r[h].includes("|")&&$o(r[h+1]));){if(Co(r[h])||g.has(h)){h+=1;continue}C.push(r[h].trimStart()),P.push(h+1),h+=1}const q=$l(C,`p-${B}`,p);x.push({key:`p-${B}`,startLine:B+1,endLine:h,fineGrained:!0,content:j=>e.jsx("p",{className:"text-muted-foreground",children:Ll(q.perLine,q.hardBreaks,P,`p-${B}`,j)})})}const b=Fx(p);return b&&x.push({key:"footnotes",startLine:r.length,endLine:r.length,content:b}),c.check(),{blocks:x,images:f}}function zx(r,n,s){return zl(r,n,s).blocks}function dh(r,n){const s=[];for(const l of r){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function uh(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Wx({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const{t:d}=ft(),c=Xf(r),m=vf(c),[g,f]=a.useState(null),[p,x]=a.useState(0);a.useEffect(()=>{if(!m)return;const b=new AbortController;let E;return f(null),Ju(c,{signal:b.signal}).then(async S=>{if(!S.ok)throw new Error(`HTTP ${S.status}`);const T=await S.blob();b.signal.aborted||(E=URL.createObjectURL(T),f({src:c,objectUrl:E}))}).catch(()=>{b.signal.aborted||f({src:c,failed:!0})}),()=>{b.abort(),E&&URL.revokeObjectURL(E)}},[m,c,p]);const h=g?.src===c?g:null;return m&&!h?.objectUrl?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",role:h?.failed?"alert":"status",children:h?.failed?e.jsxs("div",{className:"flex flex-col items-center gap-3",onClick:b=>b.stopPropagation(),children:[e.jsx("span",{children:d("rightSidebar.imageLoadFailed")}),e.jsx("button",{type:"button",className:"rounded bg-surface-2 px-3 py-2 hover:bg-surface-elevated",onClick:()=>x(b=>b+1),children:d("common.retry")})]}):d("rightSidebar.loadingImage")}):e.jsx(Sh,{src:m?h.objectUrl:c,vector:ca(r),alt:n,onLoad:()=>{},onError:()=>{m&&f({src:c,failed:!0})},onZoomChange:s,onDoubleTap:l})}function fh({images:r,index:n,onChange:s,onClose:l}){const{t:d}=ft(),c=r[n],m=r.length>1,g=a.useRef(null),f=a.useRef(null),p=a.useRef(null),x=a.useRef(0),[h,b]=a.useState(!1),[E,S]=a.useState(0),[T,D]=a.useState(!1),[F,M]=a.useState(!1),[C,P]=a.useState(null),B=a.useRef(!1),q=async()=>{if(!(!c||B.current)){j(),B.current=!0,M(!0),P(null);try{await pg(c)}catch(O){P({image:c,message:O instanceof Error?O.message:d("rightSidebar.downloadFailed")})}finally{B.current=!1,M(!1)}}},j=a.useCallback(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),o=a.useCallback(()=>{h||Date.now()<x.current||(j(),p.current=window.setTimeout(()=>{p.current=null,l()},450))},[j,h,l]),_=a.useCallback(O=>{if(r.length===0)return;const R=(O+r.length)%r.length;g.current?.slideTo(R),s(R)},[r.length,s]),I=a.useCallback(()=>_(n-1),[_,n]),V=a.useCallback(()=>_(n+1),[_,n]);if(a.useEffect(()=>{j(),S(0),D(!1),b(!1)},[j,n]),a.useEffect(()=>{const O=g.current;O&&(O.allowTouchMove=m&&!h)},[m,h]),a.useEffect(()=>{const O=g.current;!O||O.activeIndex===n||O.slideTo(n,0)},[n]),a.useEffect(()=>j,[j]),a.useEffect(()=>{const O=R=>{if(R.key==="Escape"){R.preventDefault(),l();return}m&&(R.key==="ArrowLeft"?(R.preventDefault(),I()):R.key==="ArrowRight"&&(R.preventDefault(),V()))};return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[m,V,I,l]),rf({onDrag:({movement:[O,R],pinching:H})=>{H||h||Math.abs(R)<Math.abs(O)*1.15&&E===0||(D(!0),Math.abs(R)>8&&(x.current=Date.now()+300),S(Math.max(0,R)))},onDragEnd:({movement:[O,R],velocity:[,H],pinching:ee,canceled:L})=>{if(D(!1),ee||L||h||Math.abs(R)<Math.abs(O)*1.15){S(0);return}if(Math.abs(R)>8&&(x.current=Date.now()+300),ih(R,H)){l();return}S(0)}},{target:f,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const W=c.title||c.alt||(c.kind==="mermaid"?d("rightSidebar.mermaidDiagram"):d("rightSidebar.image"));return typeof document>"u"?null:Rr.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:W}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[m&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:I,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":d("rightSidebar.previousImage"),title:d("common.previous"),children:e.jsx(na,{size:17})}),e.jsx("button",{type:"button",onClick:V,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":d("rightSidebar.nextImage"),title:d("common.next"),children:e.jsx(Zm,{size:17})})]}),e.jsx("button",{type:"button",onClick:()=>{q()},disabled:F,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","aria-label":d("rightSidebar.downloadFile"),title:d("rightSidebar.downloadFile"),"aria-busy":F,children:F?e.jsx(dt,{size:17,className:"animate-spin"}):e.jsx(tf,{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":d("rightSidebar.closeImagePreview"),title:d("common.close"),children:e.jsx(Pt,{size:18})})]})]}),C?.image===c&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 bg-surface px-3 py-2 text-xs text-destructive",children:[e.jsxs("span",{className:"min-w-0 break-words",children:[d("rightSidebar.downloadFailed"),": ",C.message]}),e.jsx("button",{type:"button",className:"shrink-0 rounded bg-surface-2 px-3 py-1 text-foreground hover:bg-surface-elevated",onClick:()=>{q()},disabled:F,children:d("common.retry")})]}),e.jsx("div",{ref:f,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:O=>{if(!(Date.now()<x.current)){if(O.target instanceof Element&&O.target.closest('img, [role="img"]')){o();return}j(),l()}},children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${E}px, 0) scale(${Math.max(.86,1-E/900)})`,opacity:Math.max(.35,1-E/360),transition:T?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(nf,{onSwiper:O=>{g.current=O,O.allowTouchMove=m&&!h},onSlideChange:O=>{O.activeIndex!==n&&s(O.activeIndex)},onSliderMove:()=>{j(),x.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((O,R)=>e.jsx(fl,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:O.kind==="image"?e.jsx(Wx,{src:O.src,alt:O.alt||O.title||d("rightSidebar.markdownImage"),onZoomChange:b,onDoubleTap:j}):e.jsx(o0,{svg:O.svg,title:O.title||O.alt||d("rightSidebar.mermaidDiagram"),onZoomChange:b,onDoubleTap:j})})},`${O.kind}-${R}-${O.alt}`))})})})]})]}),document.body)}function hh({referenceLines:r=!0,content:n,filePath:s,rootPath:l,lineRange:d,onLineRangeClick:c,onLineRangeDrag:m,scrollTop:g,outlineOpen:f,outlineCloseSignal:p,onOutlineOpen:x,onOutlineClose:h,lightboxOpen:b,lightboxCloseSignal:E,onLightboxOpen:S,onLightboxClose:T,onLocalLinkOpen:D}){const{t:F}=ft(),[M,C]=a.useState(null),[P,B]=a.useState(null),[q,j]=a.useState(1),[o,_]=a.useState(null),I=a.useRef(null),V=a.useRef(null),{blocks:W,images:O,parseError:R}=a.useMemo(()=>{try{return{...zl(n.split(`
1652
+ `),s,l,$=>{B(null),C($),S?.()},{footnotes:F("rightSidebar.footnotes"),backToFootnote:$=>F("rightSidebar.backToFootnote",{index:$})}),parseError:null}}catch($){return{blocks:[],images:[],parseError:$ instanceof Error?$.message:String($)}}},[n,s,l,S,F]);a.useEffect(()=>{R&&wo("markdown_error",{filePath:s,rootPath:l,error:R,fallback:"plain_text"})},[R,s,l]);const H=a.useMemo(()=>P?[...O,P]:O,[O,P]),ee=a.useCallback($=>{B({kind:"mermaid",svg:$,alt:"Mermaid diagram",title:"Mermaid diagram"}),C(O.length),S?.()},[O.length,S]);a.useEffect(()=>{C(null),B(null)},[n,s]),a.useEffect(()=>{C(null),B(null)},[E]),a.useEffect(()=>{b||(C(null),B(null))},[b]),a.useEffect(()=>{j(1)},[n,s]),a.useLayoutEffect(()=>{const $=I.current;if(!$||W.length===0)return;const me=Array.from($.querySelectorAll("[data-markdown-preview-block-start]"));let ge=1;const Le=28;for(const ne of me)if(ne.offsetTop-g<=Le)ge=Number(ne.dataset.markdownPreviewBlockStart)||ge;else break;j(ne=>ne===ge?ne:ge)},[W,g]);const L=a.useMemo(()=>dh(W,q),[q,W]),U=a.useMemo(()=>uh(W),[W]),X=`${s??""}
1653
+ ${n}`,ce=a.useRef(X),he=a.useRef(null),Re=a.useRef(null),Ne=a.useRef(!1);a.useEffect(()=>{ce.current!==X&&(ce.current=X,h?.())},[h,X]),a.useEffect(()=>{p!==void 0&&_(null)},[p]),a.useLayoutEffect(()=>{if(!f){_(null);return}const $=()=>{const me=V.current;if(!me)return;const ge=me.getBoundingClientRect(),Le=window.innerWidth;_({top:ge.bottom+6,right:Math.max(8,Le-ge.right)})};return $(),window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),()=>{window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0)}},[f,g,L]);const $e=a.useCallback($=>{const me=I.current,ge=me?.closest("[data-markdown-preview-scroller]"),Le=me?.querySelector(`[data-markdown-preview-block-start="${$.startLine}"]`);if(!ge||!Le)return;const ne=ge.getBoundingClientRect(),Ye=Le.getBoundingClientRect(),De=me?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,Te=Ye.top-ne.top+ge.scrollTop;ge.scrollTo({top:Math.max(0,Te-De-8),behavior:"smooth"}),j($.startLine),h?.()},[h]),Q=a.useCallback($=>{$.pointerType==="mouse"&&$.button!==0||ll($.target)||(he.current={pointerId:$.pointerId,startX:$.clientX,startY:$.clientY})},[]),xe=a.useCallback(($,me,ge)=>{const Le=he.current;if(he.current=null,!Le||Le.pointerId!==$.pointerId)return;const ne=Math.abs($.clientX-Le.startX),Ye=Math.abs($.clientY-Le.startY);if(ne>8||Ye>8)return;const Je=$.target;if(ll(Je)||ml())return;const De=Gu(Je,me,ge);c($,De.start,De.end)},[c]),fe=a.useCallback($=>{he.current?.pointerId===$.pointerId&&(he.current=null)},[]),Fe=a.useCallback(($,me)=>{const ge=I.current;if(!ge||typeof document.elementFromPoint!="function")return null;const Le=document.elementFromPoint($,me);if(!(Le instanceof HTMLElement)||!ge.contains(Le))return null;const ne=Le.closest("[data-md-ref-start]");if(ne){const Be=Number(ne.dataset.mdRefStart);if(Number.isFinite(Be)&&Be>0)return Be}const Ye=Le.closest("[data-markdown-preview-block-start]");if(!Ye)return null;const Je=Number(Ye.dataset.markdownPreviewBlockStart),De=W.find(Be=>Be.startLine===Je);if(!De)return Number.isFinite(Je)&&Je>0?Je:null;if(De.endLine<=De.startLine)return De.startLine;const Te=Ye.getBoundingClientRect(),_e=Te.height>0?Math.min(1,Math.max(0,(me-Te.top)/Te.height)):0;return Math.round(De.startLine+_e*(De.endLine-De.startLine))},[W]),Oe=a.useCallback($=>{if(!m||$.pointerType==="mouse"&&$.button!==0)return;const me=Fe($.clientX+24,$.clientY);if(me!=null){Re.current={pointerId:$.pointerId,anchorLine:me,moved:!1};try{$.currentTarget.setPointerCapture($.pointerId)}catch{}}},[m,Fe]),G=a.useCallback($=>{const me=Re.current;if(!me||me.pointerId!==$.pointerId||!m)return;const ge=Fe($.clientX+16,$.clientY);ge!=null&&(!me.moved&&ge===me.anchorLine||(me.moved=!0,Ne.current=!0,m($,Math.min(me.anchorLine,ge),Math.max(me.anchorLine,ge),"move")))},[m,Fe]),Ce=a.useCallback($=>{const me=Re.current;if(Re.current=null,!me||me.pointerId!==$.pointerId||!m||!me.moved)return;const ge=Fe($.clientX+16,$.clientY)??me.anchorLine;m($,Math.min(me.anchorLine,ge),Math.max(me.anchorLine,ge),"end")},[m,Fe]),Se=a.useCallback($=>{Re.current?.pointerId===$.pointerId&&(Re.current=null)},[]),de={onPointerDown:Oe,onPointerMove:G,onPointerUp:Ce,onPointerCancel:Se},qe=()=>Ne.current?(Ne.current=!1,!0):!1;return R?e.jsxs("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground","data-markdown-preview-fallback":!0,children:[e.jsx("p",{role:"alert",className:"mb-3 text-destructive",children:F("rightSidebar.markdownParseFailed")}),e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-xs",children:n})]}):W.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:F("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:I,className:"relative min-w-0 max-w-full",onClickCapture:$=>{const me=$.target instanceof Element?$.target.closest("a[href]"):null;if(!me||!D)return;const ge=me.getAttribute("href");if(!ge)return;const Le=Fl(ge,s,l);Le&&($.preventDefault(),D(Le))},children:[r&&L.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:L.map($=>$.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:L[L.length-1].text}),U.length>1&&e.jsxs("button",{ref:V,type:"button",onClick:()=>{f?h?.():x?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${f?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":f,"aria-label":F("rightSidebar.markdownOutline"),title:F("rightSidebar.markdownOutline"),children:[e.jsx(sf,{size:12}),e.jsx("span",{children:F("rightSidebar.markdownOutlineShort")})]})]})}),f&&typeof document<"u"&&Rr.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:h}),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:o?{top:`${o.top}px`,right:`${o.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:U.map($=>{const me=L[L.length-1]?.startLine===$.startLine;return e.jsxs("button",{type:"button",onClick:()=>$e($),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] ${me?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min($.level-1,4)*12+8}px`},title:$.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${me?"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",$.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:$.text})]},`desktop-${$.id}-${$.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:F("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:h,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":F("rightSidebar.closeMarkdownOutline"),title:F("common.close"),children:e.jsx(Pt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:U.map($=>{const me=L[L.length-1]?.startLine===$.startLine;return e.jsxs("button",{type:"button",onClick:()=>$e($),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] ${me?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min($.level-1,4)*12+8}px`},title:$.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${me?"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",$.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:$.text})]},`${$.id}-${$.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(Hf.Provider,{value:ee,children:W.map($=>{const me=!!(d&&$.startLine<=d.end&&$.endLine>=d.start),ge=!!(d&&d.start<=$.startLine&&d.end>=$.endLine),Le=$.kind==="table"?!1:$.fineGrained?ge:me,ne=$.kind==="table"&&d?.start===$.startLine&&d.end===$.endLine;let Ye=null;if($.kind!=="table"&&$.fineGrained&&me&&!ge&&d){const _e=$.endLine-$.startLine+1,Be=Math.max(d.start,$.startLine),te=Math.min(d.end,$.endLine),ye=(Be-$.startLine)/_e,nt=(te-Be+1)/_e;Ye=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) * ${ye})`,height:`calc((100% - 0.5rem) * ${nt})`}})}const Je=typeof $.content=="function"?$.content(d):$.content;if(!r)return e.jsx("div",{"data-markdown-preview-block-start":$.startLine,className:"min-w-0 cursor-text select-text py-0.5",children:Je},$.key);const De=$.startLine===$.endLine?String($.startLine):`${$.startLine}-${$.endLine}`,Te=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:al(Le),"aria-hidden":"true",...de,children:[e.jsx("span",{className:ol(Le)}),Ye]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:Je})]});return $.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":$.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 ${Le?"bg-primary/10":""}`,title:`Line ${De}`,"aria-label":`Line ${De}`,children:[$.kind==="table"?e.jsx("button",{type:"button",className:al(ne,"self"),onClick:_e=>{_e.preventDefault(),!qe()&&c(_e,$.startLine,$.endLine)},title:`Reference table lines ${De}`,"aria-label":`Reference table lines ${De}`,...de,children:e.jsx("span",{className:ol(ne,"self")})}):e.jsxs("span",{className:al(Le,"none"),"aria-hidden":"true",...de,children:[e.jsx("span",{className:ol(Le,"none")}),Ye]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:Q,onPointerUp:_e=>xe(_e,$.startLine,$.endLine),onPointerCancel:fe,onKeyDown:_e=>{_e.key!=="Enter"&&_e.key!==" "||(_e.preventDefault(),c(_e,$.startLine,$.endLine))},title:`Reference line ${De}`,"aria-label":`Reference line ${De}`,children:Je})]},$.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":$.startLine,onClick:_e=>{const Be=_e.target;if(ll(Be)||ml()||qe())return;const te=Gu(Be,$.startLine,$.endLine);c(_e,te.start,te.end)},onKeyDown:_e=>{_e.key!=="Enter"&&_e.key!==" "||(_e.preventDefault(),c(_e,$.startLine,$.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 ${Le?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${De}`,"aria-label":`Reference line ${De}`,children:Te},$.key)})})})]}),b&&M!==null&&H[M]&&e.jsx(fh,{images:H,index:M,onChange:C,onClose:()=>{C(null),B(null),T?.()}})]})}function fs({label:r,value:n,options:s,placeholder:l,searchPlaceholder:d,emptyText:c,disabled:m,onChange:g}){const{t:f}=ft(),[p,x]=a.useState(!1),[h,b]=a.useState(""),[E,S]=a.useState(null),T=a.useRef(null),D=a.useRef(null),F=h.trim().toLowerCase(),M=a.useMemo(()=>F?s.filter(j=>`${j.label} ${j.meta??""}`.toLowerCase().includes(F)):s,[F,s]),C=s.find(j=>j.value===n),P=()=>{const j=h.trim();j&&(g(j),x(!1),b(""))},B=a.useCallback(()=>{const j=T.current?.getBoundingClientRect();if(!j)return!1;const o=12,_=Math.max(220,Math.min(j.width,window.innerWidth-o*2)),I=Math.min(Math.max(o,j.left),window.innerWidth-_-o),V=window.innerHeight-j.bottom-o,W=j.top-o,O=V>=180||V>=W,R=Math.max(96,(O?V:W)-4),H=Math.min(320,R);return S({left:I,top:O?j.bottom+4:Math.max(o,j.top-H-4),width:_,maxHeight:H}),!0},[]),q=()=>{B(),x(!0)};return a.useEffect(()=>{if(!p)return;let j=0;const o=()=>{j||(j=window.requestAnimationFrame(()=>{j=0,B()}))},_=I=>{const V=I.target;V instanceof Node&&(T.current?.contains(V)||D.current?.contains(V)||(x(!1),b("")))};return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),document.addEventListener("pointerdown",_,!0),()=>{j&&window.cancelAnimationFrame(j),window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0),document.removeEventListener("pointerdown",_,!0)}},[p,B]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:T,type:"button",disabled:m,onClick:()=>{if(!m){if(b(""),p){x(!1);return}q()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:C?.label??(n||l)})]}),e.jsx(sa,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${p?"rotate-180":""}`})]}),p&&!m&&typeof document<"u"&&Rr.createPortal(e.jsxs("div",{ref:D,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:j=>j.stopPropagation(),style:{left:E?.left??12,top:E?.top??12,width:E?.width??260,maxHeight:E?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(ms,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:h,onChange:j=>b(j.target.value),onKeyDown:j=>{if(j.key==="Escape"){j.preventDefault(),x(!1),b("");return}j.key==="Enter"&&(j.preventDefault(),P())},onBlur:()=>{h.trim()&&M.length===0&&P()},placeholder:d,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(E?.maxHeight??320)-46)},children:[h.trim()&&!s.some(j=>j.value===h.trim())&&e.jsxs("button",{type:"button",onMouseDown:j=>j.preventDefault(),onClick:P,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:h.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:f("common.use")})]}),M.length>0?M.map(j=>e.jsxs("button",{type:"button",onClick:()=>{g(j.value),x(!1),b("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${j.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:j.label}),j.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:j.meta})]},j.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function Bu({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:d,selectedRoots:c,onToggleRepo:m,onGenerate:g,onSecondaryAction:f,disabled:p,generateDisabled:x,secondaryDisabled:h,inserted:b,buttonLabel:E,insertedLabel:S,title:T,ariaLabel:D,scopeTitle:F,scopeLabel:M,allLabel:C,generateLabel:P,secondaryLabel:B,secondaryTitle:q,secondaryLoading:j,loading:o,error:_,statusTitle:I,extraContent:V,renderRepoExtra:W,menuItem:O=!1}){return e.jsxs("div",{className:O?"relative w-full":"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",role:O?"menuitem":void 0,tabIndex:O?-1:void 0,onClick:()=>{s?n(!r):x||g()},disabled:p,className:`relative flex items-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-50 ${O?"min-h-10 w-full gap-2.5 px-2.5 text-left text-[12px] focus:bg-surface-2 focus:outline-none [@media(pointer:coarse)]:min-h-11":"h-7 shrink-0 justify-center gap-1 px-2 text-[11px] font-medium active:scale-95"} ${_?"text-destructive hover:bg-destructive/5":b?"bg-surface-elevated text-foreground":O?"text-foreground hover:bg-surface-2":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":D,title:I??(s?`${F}: ${M}`:T),children:[o?e.jsx(dt,{size:O?15:13,className:"shrink-0 animate-spin"}):e.jsx(aa,{size:O?15:13,className:O?"shrink-0 text-muted-foreground":void 0}),e.jsx("span",{className:O?"min-w-0 flex-1":void 0,children:b?S:E}),s&&(O?e.jsx(hs,{size:13,className:"shrink-0 text-muted-foreground"}):e.jsx(sa,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`})),_&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&Rr.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:R=>R.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:F}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:M})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Pt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[V,e.jsxs("button",{type:"button",onClick:()=>m(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:C}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),d.map(R=>{const H=c.includes(R.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${H?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>m(R.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${H?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:R.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:R.label}),R.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:R.branch})]}),H&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),W&&(l||H)&&e.jsx("div",{className:"px-2 pb-2",children:W(R)})]},R.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${f&&B?"sm:grid-cols-2":""}`,children:[f&&B&&e.jsxs("button",{type:"button",onClick:()=>{h||(n(!1),f())},disabled:h,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:q,children:[j?e.jsx(dt,{size:12,className:"animate-spin"}):e.jsx(mf,{size:12}),B]}),e.jsxs("button",{type:"button",onClick:()=>{x||(n(!1),g())},disabled:x,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:T,children:[e.jsx(aa,{size:12}),P]})]})]})}),document.body)]})}function Gx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function mh(){return pt(Tl,Gx)??{}}function Kx(r,n){const s=mh(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,d],[,c])=>c.updatedAt-d.updatedAt).slice(0,Bb);Zs(Tl,Object.fromEntries(l),Ub)}function qx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function Vx(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!qx(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Wl(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function ph(){return pt(Il,Vx)??{}}function Ou(r,n){const s=Wl(r,n);return s?ph()[s]??null:null}function nl(r,n,s){const l=Wl(r,n);if(!l)return;const d=ph(),c=d[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},m=Object.entries({...d,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,g],[,f])=>f.updatedAt-g.updatedAt).slice(0,Ob);Zs(Il,Object.fromEntries(m),Hb)}function sl({slow:r}){return e.jsx(Tp,{slow:r})}function mo({message:r,onRetry:n}){const{t:s}=ft();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:r}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function yo(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function jt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function po(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Yx(r,n,s){return pl(r,n,s)}function al(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function ol(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function gh(r){const n=new Map;for(const s of r)n.set(Gl(s),s);return n}function bh(r,n){const s=new Map(r);for(const l of n)s.set(Gl(l),l);return s}function Uu(r,n){let s=0;for(const l of r){const d=xt(l,n);d&&n&&d!==n&&(s+=1)}return s}function Xx(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Jx(r,n){return Array.from(bh(gh(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Qx(r,n){const s=r.relativeRoot==="."?jt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||jt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Xx(r.files)}}function xh(r,n){const s=jt(n??"")||n||"";return r.map(l=>Qx(l,n)).sort((l,d)=>s&&l.label===s?-1:s&&d.label===s?1:l.label.localeCompare(d.label))}function vh(r,n,s,l,d){const c=Df(s),m=c.find(T=>T.root===l)??c[0]??null,g=n.find(T=>T.root===l)??null,f=g?.relativeRoot??m?.relativeRoot??".",p=g?.name??m?.name??(jt(l)||l),x=(m?.files??s.files).map(T=>({...T,repoRoot:l,repoRelativeRoot:f,repoName:p})),h=m?.context??s.context,b={...g??m??{id:l,root:l,relativeRoot:f,name:p,depth:0,nested:!!(d&&l!==d),available:s.available,files:[],context:null},...m??{},id:g?.id??m?.id??l,root:l,displayRoot:g?.displayRoot??m?.displayRoot,relativeRoot:f,name:p,depth:g?.depth??m?.depth??0,nested:g?.nested??m?.nested??!!(d&&l!==d),available:m?.available??s.available,deferred:m?.deferred??!1,files:x,context:h?{...h,root:l,changedFiles:x.map(T=>({path:T.path,absolutePath:T.absolutePath,status:T.status}))}:null,untrackedDeferred:m?.untrackedDeferred??s.untrackedDeferred,error:m?.error??s.error},E=g?n.map(T=>T.root===l?b:T):[...n,b];return{files:Array.from(r).filter(T=>xt(T,d)!==l).concat(x),repositories:E,repoFilters:xh(E,d)}}function xt(r,n){return r.repoRoot??n}function Gl(r){return`${r.repoRoot??""}\0${r.path}`}function Sr(r){return r.absolutePath||r.path}function il(r){return Gl(r)}function Zx(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function Hu(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function zu(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function qs(r){let n=0;const s=r??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function Vs(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function jr(r){return r instanceof DOMException&&r.name==="AbortError"}function e0(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Wu(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function ll(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Gu(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,d=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(d)&&d>0&&Number.isFinite(c)&&c>0?{start:Math.min(d,c),end:Math.max(d,c)}:{start:n,end:s}}function t0({actions:r,running:n,completed:s}){const{t:l}=ft(),[d,c]=a.useState(!1),m=a.useRef(null),g=r.find(p=>n?.action===p.key),f=r.find(p=>s?.action===p.key);return r.length===0?null:(a.useEffect(()=>{if(!d)return;const p=h=>{const b=h.target;b instanceof Node&&m.current?.contains(b)||c(!1)},x=h=>{h.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",p),document.addEventListener("keydown",x),()=>{document.removeEventListener("pointerdown",p),document.removeEventListener("keydown",x)}},[d]),e.jsxs("div",{ref:m,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),c(x=>!x)},disabled:r.every(p=>p.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 ${d?"bg-surface-elevated text-foreground":f?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:g?.label??f?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(dt,{size:13,className:"animate-spin"}):f?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(ko,{size:14})}),d&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(p=>{const x=n?.action===p.key,h=s?.action===p.key;return e.jsxs("button",{type:"button",onClick:b=>{b.stopPropagation(),p.onClick(),c(!1)},disabled:p.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 ${h?"bg-accent/10 text-accent":p.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:x?e.jsx(dt,{size:13,className:"animate-spin"}):h?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:p.label})]},p.key)})})]}))}function r0(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function yh(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&r0(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function ps(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const cl=new WeakMap;function Po(r){const n=cl.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),cl.delete(r)},1700);cl.set(r,s)}function n0(r){const n=CSS.escape(r),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let d=null;for(const g of l){if(!ps(g))continue;const f=g.querySelector(s);if(f&&ps(f)){d=f;break}}if(d??=Array.from(document.querySelectorAll(s)).find(ps)??null,!d)return;const c=yh(d);if(!c){d.scrollIntoView({block:"start",behavior:"smooth"}),Po(d);return}const m=d.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,m),behavior:"instant"}),Po(d)}function Mn(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,d=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,m=[s!==null&&d?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null&&d?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`: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(S=>!!S),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let f=null;for(const S of g)if(ps(S)){for(const T of m){const D=S.querySelector(T);if(D&&ps(D)){f=D;break}}if(f)break}if(f??=m.flatMap(S=>Array.from(document.querySelectorAll(S))).find(ps)??null,!f){n0(r.filePath);return}const p=yh(f);if(!p){f.scrollIntoView({block:"center",behavior:"smooth"}),Po(f);return}const x=f.getBoundingClientRect(),h=p.getBoundingClientRect(),E=x.top-h.top+p.scrollTop-Math.max(24,(p.clientHeight-x.height)/2);p.scrollTo({top:Math.max(0,E),behavior:"instant"}),Po(f)}const wh=1,Kl=8;function s0(r,n=Kl){return Math.min(n,Math.max(wh,r))}function kh({resetKey:r,maxScale:n=Kl,onZoomChange:s,onDoubleTap:l,children:d}){const c=a.useRef(null),[m,g]=a.useState({scale:1,x:0,y:0}),[f,p]=a.useState(!1),x=a.useRef(null),h=a.useRef(new Set),b=a.useRef(!1),E=a.useRef(null),S=a.useRef(0),T=a.useRef(m);T.current=m,a.useEffect(()=>{g({scale:1,x:0,y:0})},[r]);const D=a.useCallback((P,B,q)=>{const j=c.current;if(!j)return{x:B,y:q};const o=j.firstElementChild instanceof HTMLElement?j.firstElementChild:null,_=o?.clientWidth||j.clientWidth,I=o?.clientHeight||j.clientHeight,V=Math.max(0,(_*P-j.clientWidth)/2),W=Math.max(0,(I*P-j.clientHeight)/2);return{x:Math.min(V,Math.max(-V,B)),y:Math.min(W,Math.max(-W,q))}},[]),F=a.useCallback((P,B,q)=>{g(j=>{const o=s0(P,n),_=c.current;if(!_||o===1)return{scale:o,x:0,y:0};const I=_.getBoundingClientRect(),V=(B??I.left+I.width/2)-I.left-I.width/2,W=(q??I.top+I.height/2)-I.top-I.height/2,O=o/j.scale,R=V-(V-j.x)*O,H=W-(W-j.y)*O;return{scale:o,...D(o,R,H)}})},[D,n]),M=a.useCallback((P,B)=>{p(!0),T.current.scale>1?g({scale:1,x:0,y:0}):F(2.5,P,B),window.setTimeout(()=>p(!1),220)},[F]);a.useEffect(()=>{const P=c.current;if(!P)return;const B=o=>{if(o.pointerType==="mouse"&&o.button!==0)return;const _=h.current.size===0;if(h.current.add(o.pointerId),_){const I=Date.now(),V=E.current;if(V&&I-V.time<350&&Math.hypot(o.clientX-V.x,o.clientY-V.y)<24){E.current=null,S.current=I,l?.(),M(o.clientX,o.clientY);return}}if(h.current.size>1){b.current=!0,x.current=null;return}if(!(T.current.scale<=1)){o.preventDefault(),x.current={pointerId:o.pointerId,startX:o.clientX,startY:o.clientY,originX:T.current.x,originY:T.current.y,moved:!1};try{P.setPointerCapture?.(o.pointerId)}catch{}p(!1)}},q=o=>{const _=x.current;if(!_||_.pointerId!==o.pointerId)return;const I=o.clientX-_.startX,V=o.clientY-_.startY;if(!_.moved){if(Math.hypot(I,V)<6)return;_.moved=!0}o.stopPropagation(),o.preventDefault(),g(W=>({...W,...D(W.scale,_.originX+I,_.originY+V)}))},j=o=>{const _=x.current,I=_?.pointerId===o.pointerId&&_.moved;if(_?.pointerId===o.pointerId){_.moved&&o.stopPropagation(),x.current=null;try{P.releasePointerCapture?.(o.pointerId)}catch{}}h.current.delete(o.pointerId)&&h.current.size===0&&(!b.current&&!I&&(E.current={time:Date.now(),x:o.clientX,y:o.clientY}),b.current=!1)};return P.addEventListener("pointerdown",B,{capture:!0,passive:!1}),window.addEventListener("pointermove",q,{capture:!0,passive:!1}),window.addEventListener("pointerup",j,{capture:!0}),window.addEventListener("pointercancel",j,{capture:!0}),()=>{P.removeEventListener("pointerdown",B,{capture:!0}),window.removeEventListener("pointermove",q,{capture:!0}),window.removeEventListener("pointerup",j,{capture:!0}),window.removeEventListener("pointercancel",j,{capture:!0})}},[D,l,M]),rf({onPinch:({offset:[P],origin:[B,q]})=>{p(!1),F(P,B,q)},onWheel:({event:P,delta:[B,q],ctrlKey:j})=>{if(j){P.preventDefault(),P.stopPropagation(),p(!1),F(T.current.scale*(1-q*.01),P.clientX,P.clientY);return}T.current.scale<=1||(P.preventDefault(),P.stopPropagation(),p(!1),g(o=>({...o,...D(o.scale,o.x-B,o.y-q)})))}},{target:c,eventOptions:{passive:!1},pinch:{scaleBounds:{min:wh,max:n},from:()=>[T.current.scale,0],rubberband:!0}});const C=m.scale>1;return a.useEffect(()=>{s?.(C)},[s,C]),e.jsx("div",{ref:c,"data-sidebar-gesture-ignore":C?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden","data-image-zoom-viewport":!0,style:{cursor:C?"grab":"zoom-in"},onDoubleClick:P=>{P.stopPropagation(),!(Date.now()-S.current<500)&&(l?.(),M(P.clientX,P.clientY))},children:d({scale:m.scale,zoomed:C,animateTransform:f,transformStyle:{transform:`translate3d(${m.x}px, ${m.y}px, 0) scale(${m.scale})`,transformOrigin:"center center",transition:f?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${m.x}px, ${m.y}px, 0)`,transformOrigin:"center center",transition:f?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Sh({src:r,alt:n,vector:s,onLoad:l,onError:d,onZoomChange:c,onDoubleTap:m}){const g=To(r,d),[f,p]=a.useState(null),x=s??ca(r);return a.useEffect(()=>{p(null)},[r]),e.jsx(kh,{resetKey:r,maxScale:Math.max(Kl,f?.originalScale??1),onZoomChange:c,onDoubleTap:m,children:({vectorTransformStyle:h,scale:b,animateTransform:E})=>e.jsx("div",{"data-image-zoom-surface":!0,"data-vector-zoom-surface":x?"":void 0,className:"relative shrink-0 touch-none select-none",style:f?{...h,width:f.width,height:f.height}:{width:"100%",height:"100%"},children:e.jsx("img",{src:g,alt:n,draggable:!1,className:"touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:{position:"absolute",left:"50%",top:"50%",width:f?f.width*b:void 0,height:f?f.height*b:void 0,maxWidth:f?"none":"100%",maxHeight:f?"none":"100%",transform:"translate(-50%, -50%)",transition:E?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"},onLoad:S=>{const T=S.currentTarget,D=T.closest("[data-image-zoom-viewport]");if(D&&T.naturalWidth>0&&T.naturalHeight>0){const F=Math.max(1,D.clientWidth-2),M=Math.max(1,D.clientHeight-2),C=Math.min(F/T.naturalWidth,M/T.naturalHeight),P=x?C:Math.min(C,1);p({width:T.naturalWidth*P,height:T.naturalHeight*P,originalScale:1/P})}l(S)},onError:d})})})}function a0({svg:r,title:n,scale:s,vectorTransformStyle:l}){const d=a.useRef(null);return a.useLayoutEffect(()=>{const c=d.current,m=c?.querySelector("svg");if(!c||!m)return;const g=()=>{const x=m.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let h=x[2],b=x[3];if((!Number.isFinite(h)||!Number.isFinite(b)||h<=0||b<=0)&&(h=Number(m.getAttribute("width")),b=Number(m.getAttribute("height"))),!Number.isFinite(h)||!Number.isFinite(b)||h<=0||b<=0)return;const E=Math.max(1,c.clientWidth-24),S=Math.max(1,c.clientHeight-24),T=Math.min(E/h,S/b,1);m.style.width=`${Math.max(1,Math.floor(h*T*s))}px`,m.style.height=`${Math.max(1,Math.floor(b*T*s))}px`,m.style.maxWidth="none",m.style.maxHeight="none",m.style.transform=String(l.transform??""),m.style.transformOrigin="center center",m.style.transition=String(l.transition??"none")};g();const f=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return f?.observe(c),()=>f?.disconnect()},[s,r,l]),e.jsx("div",{ref:d,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function o0({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(kh,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:d,scale:c})=>e.jsx(a0,{svg:r,title:n,scale:c,vectorTransformStyle:d})})}let i0=0,l0=0,c0=0,d0=0,u0=0;function wo(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function ct(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++l0,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Ys(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++d0,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function f0(){return`diff-ui-${Date.now().toString(36)}-${(++u0).toString(36)}`}function h0(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function m0(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Ao({onReviewReference:r,filePath:n,active:s=!0,onInsertReference:l,onInsertText:d,onInsertFeature:c,onReferenceCopied:m,onClose:g,onDirectoryLinkOpen:f,isMobile:p,markdownOutlineOpen:x,markdownOutlineCloseSignal:h,onOpenMarkdownOutline:b,onCloseMarkdownOutline:E,markdownImageLightboxOpen:S,markdownImageLightboxCloseSignal:T,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:F,lineRange:M,onLineRangeChange:C,insertedReferenceKey:P,copiedReferenceKey:B,scrollToLine:q,onScrollToLineHandled:j}){const{t:o}=ft(),_=a.useRef(null),I=a.useRef({}),V=a.useRef(s);V.current=s,a.useEffect(()=>{s||_.current?.querySelectorAll("video").forEach(A=>A.pause())},[s]);const W=J(A=>A.rootPath),O=J(A=>A.selectFile),[R,H]=a.useState({kind:"idle"}),[ee,L]=a.useState("schematic"),[U,X]=a.useState(null),ce=a.useRef(null),[he,Re]=a.useState(null),Ne=a.useRef(new Map),$e=a.useRef(null),[Q,xe]=a.useState(null),[fe,Fe]=a.useState(()=>Mu()),[Oe,G]=a.useState(()=>gu(W,n)),Ce=a.useRef(null),[Se,de]=a.useState(!1),[qe,$]=a.useState(null),[me,ge]=a.useState(0),[Le,ne]=a.useState([]),[Ye,Je]=a.useState(null),De=a.useRef(null),Te=a.useRef(n),[_e,Be]=a.useState(null),te=Yg(W&&n&&!n.startsWith("/")?`${W}/${n}`:n,s),[ye,nt]=a.useState(!1),[vt,er]=a.useState(""),[z,oe]=a.useState([]),[je,Qe]=a.useState(0),At=a.useRef(null),Nr=hf(m),tr=Wl(W,n);a.useEffect(()=>{if(Te.current===n)return;Te.current=n;const A=n&&W&&!n.startsWith("/")?`${W}/${n}`:n;if(De.current===A){De.current=null;return}De.current=null,ne([]),Je(null),nt(!1),er("")},[n,W]);const yt=n?W&&!n.startsWith("/")?`${W}/${n}`:n:null,dr=J(A=>yt?(A.fileChangeVersions.get(yt)??0)+A.fileWatchEpoch:A.fileWatchEpoch),rr=a.useRef(null),Ln=a.useRef(null),[Pn,Fo]=a.useState(0),Qr=a.useCallback(()=>Fo(A=>A+1),[]);a.useEffect(()=>{const A=ce.current;return ce.current=null,X(null),A&&URL.revokeObjectURL(A.objectUrl),()=>{const K=ce.current;ce.current=null,K&&URL.revokeObjectURL(K.objectUrl)}},[yt,dr,Pn]),a.useEffect(()=>{if(!n){rr.current=null,H({kind:"idle"});return}const A=W&&!n.startsWith("/")?`${W}/${n}`:n,K=new AbortController,be=++i0,ke=`right-sidebar-file-preview:${be}`,We=performance.now();let Ue=!1;const tt=(re,Ke={})=>{Ue||(Ue=!0,wo("end",{loadingId:be,reason:re,durationMs:Math.round(performance.now()-We),filePath:n,fullPath:A,rootPath:W,...Ke}))};let Ge=null;const ht=Um(A),bt=ht?A.toLowerCase().endsWith(".kicad_pcb")?ee==="schematic"?"pcb-front":ee:"schematic":ee,hr=!ht&&Pl(A),Tr=!ht&&!hr&&Hm(A),On=!ht&&!hr&&!Tr&&Yu(A),an=Ks(A),ws=zs(A),mr=ht?"eda":hr?"image":Tr?"model3d":On?"video":"text",ks=rr.current!==A;if(rr.current=A,ks){wo("start",{loadingId:be,filePath:n,fullPath:A,rootPath:W,mode:mr,externalVersion:dr}),H({kind:"loading",mode:mr}),Ln.current=null;const re=Ou(W,n);C(re?.lineRange??null),Fe(an?Mu():"source"),G(ws?gu(W,n):"source"),ht&&L(zm(A))}ks||H(re=>re.kind==="error"?{kind:"loading",mode:mr}:re);const on=window.setTimeout(()=>{Ue||K.signal.aborted||wo("still_active",{loadingId:be,filePath:n,fullPath:A,rootPath:W,mode:mr,durationMs:Math.round(performance.now()-We),isPathChange:ks})},3e3),Wr=window.setTimeout(()=>{if(Ue||K.signal.aborted)return;const re=ht?o("rightSidebar.edaTimeout"):Tr?o("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";K.abort(new DOMException(re,"TimeoutError")),H({kind:"error",message:re}),tt("stuck_timeout",{error:re})},ht?Wm+5e3:Tr?Gm+5e3:Km(A)?35e3:Yb);if(ht){const re=bt==="pcb-3d"?ce.current:null;re?(H(re),tt("eda_3d_client_cache_hit",{bytes:re.meta.size,view:re.view,mimeType:re.meta.mimeType})):qm(A,bt,K.signal,"view_file",ke).then(Ke=>{if(K.signal.aborted)return;Ge=URL.createObjectURL(Ke.blob);const qt={kind:"eda",sourcePath:Ke.path||A,objectUrl:Ge,view:Ke.view,meta:{size:Ke.size,mimeType:Ke.mimeType,modified:Ke.modified}};if(Ke.view==="pcb-3d"){const Ir=ce.current;Ir&&Ir.objectUrl!==Ge&&URL.revokeObjectURL(Ir.objectUrl),ce.current=qt,X(qt),Ge=null}H(qt),tt("eda_loaded",{bytes:Ke.size,view:Ke.view,mimeType:Ke.mimeType})}).catch(Ke=>{K.signal.aborted||(H({kind:"error",message:Ke instanceof Error&&/timed out/i.test(Ke.message)?o("rightSidebar.edaTimeout"):Ke instanceof Error?Ke.message:o("rightSidebar.edaLoadFailed")}),tt("error",{error:Ke instanceof Error?Ke.message:String(Ke)}))})}else if(hr)Vm(A,K.signal,"view_file",ke).then(re=>{Ge=URL.createObjectURL(re.blob),H({kind:"image",objectUrl:Ge,meta:{size:re.size,mimeType:re.mimeType,modified:re.modified}}),tt("image_loaded",{bytes:re.size,mimeType:re.mimeType})}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error?re.message:o("rightSidebar.imageLoadFailed")}),tt("error",{error:re instanceof Error?re.message:String(re)}))});else if(Tr)Ym(A,K.signal,"view_file",ke).then(re=>{K.signal.aborted||(Ge=URL.createObjectURL(re.blob),H({kind:"model3d",sourcePath:re.path||A,objectUrl:Ge,ext:re.ext,meta:{size:re.size,mimeType:re.mimeType,modified:re.modified}}),tt("model3d_loaded",{bytes:re.size,ext:re.ext}))}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error&&(re.name==="TimeoutError"||/timed out/i.test(re.message))?o("rightSidebar.model3dTimeout"):re instanceof Error?re.message:o("rightSidebar.model3dLoadFailed")}),tt("error",{error:re instanceof Error?re.message:String(re)}))});else if(On){const re=Xm(A)??"",Ke=Xu(A);H(qt=>qt.kind==="video"&&qt.url===Ke?qt:{kind:"video",url:Ke,meta:{size:null,mimeType:re,modified:null}}),tt("video_ready",{mimeType:re})}else Od(A,K.signal,"view_file",ke).then(re=>{if(!K.signal.aborted){if(re.binary){H({kind:"binary"});return}H({kind:"text",content:re.content,sourcePath:re.path||A,meta:{size:re.size,truncated:re.truncated}}),tt("text_loaded",{bytes:re.size,truncated:!!re.truncated})}}).catch(re=>{K.signal.aborted||(H({kind:"error",message:re instanceof Error?re.message:"Failed to read file"}),tt("error",{error:re instanceof Error?re.message:String(re)}))});return()=>{K.abort(),Nt(ke),window.clearTimeout(on),window.clearTimeout(Wr),Ge&&URL.revokeObjectURL(Ge),tt("cleanup")}},[n,W,dr,Pn,C,o,ee]),a.useEffect(()=>{if(R.kind!=="model3d"||!n){Re(null);return}let A=!1;const K=n.lastIndexOf("/"),be=K>=0?n.slice(K+1):n,ke=K>=0?n.slice(0,K):"",We=ke.lastIndexOf("/"),Ue=We>=0?ke.slice(0,We):"",tt=be.replace(/\.(stl|glb|gltf)$/i,""),Ge=`${Ue?`${Ue}/`:""}features/${tt}.json`;return Od(Ge).then(ht=>{if(!A)try{const bt=JSON.parse(ht.content);Re(bt.version===1&&Array.isArray(bt.features)&&bt.features.length>0?bt.features:null)}catch{Re(null)}}).catch(()=>{A||Re(null)}),()=>{A=!0}},[R,n]),a.useEffect(()=>{if(R.kind!=="text"){Be(null);return}const A=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,K=cf(A),be=R.content,ke=Ks(A??"")&&fe==="preview",We=zs(A??"")&&Oe==="preview";if(!K||ke||We||!df(be)){Be(null);return}let Ue=!1;const tt=Ge=>{if(Ue||!Ge.registered(K)){Ue||Be(null);return}try{Be(ff(Ge,be,K))}catch{Be(null)}};return qe?tt(qe):(Be(null),uf().then(Ge=>{Ue||($(Ge),tt(Ge))}).catch(()=>{})),()=>{Ue=!0}},[R,qe,n,W,fe,Oe]),a.useLayoutEffect(()=>{if(!tr||R.kind!=="text")return;const A=`${tr}:${fe}:${Oe}`;if(Ln.current===A)return;const K=Ou(W,n);if(Ln.current=A,!K)return;const be=requestAnimationFrame(()=>{const ke=$e.current;if(!ke)return;const We=fe==="preview"?K.markdownTop??K.top:K.top;ke.scrollTo({top:Math.max(0,We??0),left:Math.max(0,K.left??0)}),ge(fe==="preview"?Math.max(0,We??0):0)});return()=>cancelAnimationFrame(be)},[n,fe,Oe,R.kind,tr,W]),a.useEffect(()=>{tr&&nl(W,n,{lineRange:M})},[n,M,tr,W]),a.useEffect(()=>{if(q==null||R.kind!=="text")return;xe(null),C({start:q,end:q});const A=q,K=requestAnimationFrame(()=>{const be=Ne.current.get(A);be&&be.scrollIntoView({block:"center"}),j?.()});return()=>cancelAnimationFrame(K)},[q,R,C,j]);const An=a.useCallback(A=>{const K=$e.current;if(!K)return!1;const be=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(A):A.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),ke=K.querySelector(`#${be}`);return ke?(ke.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const A=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,K=R.kind==="text"&&Ks(A??"")&&fe==="preview";if(!Ye||!K)return;const be=requestAnimationFrame(()=>{An(Ye)&&Je(null)});return()=>cancelAnimationFrame(be)},[n,An,fe,Ye,R,W]),a.useLayoutEffect(()=>{const A=$e.current;if(!A||!M){xe(null);return}if(Q)return;const K=R.kind==="image"||R.kind==="loading"&&R.mode==="image",be=W&&n&&!n.startsWith("/")?`${W}/${n}`:n,ke=R.kind==="text"&&Ks(be??"")&&fe==="preview",We=R.kind==="text"&&zs(be??"")&&Oe==="preview";if(R.kind!=="text"||K||ke||We){xe(null);return}const Ue=()=>{const Ge=Ne.current.get(M.end);if(!Ge||!A){xe(null);return}const ht=Ge.offsetTop+Ge.offsetHeight/2,bt=A.scrollLeft+Math.max(8,A.clientWidth-120);xe({top:ht,left:bt})};Ue();const tt=new ResizeObserver(()=>Ue());return tt.observe(A),()=>tt.disconnect()},[M,Q,R,fe,Oe,n,W,_e]);const gt=R.kind==="text"&&!(zs(yt??"")&&Oe==="preview")&&!yt?.toLowerCase().endsWith(".csv")&&!yt?.toLowerCase().endsWith(".kicad_pro")&&!yt?.toLowerCase().endsWith(".kicad_prl"),Zr=a.useCallback(()=>{nt(!1),er(""),oe([]),Qe(0),co(I.current)},[]),Cr=a.useCallback(()=>{!s||!gt||(nt(!0),requestAnimationFrame(()=>{const A=_.current;!V.current||!A?.isConnected||A.closest('[inert], [aria-hidden="true"], [hidden]')||A.getClientRects().length===0||getComputedStyle(A).visibility==="hidden"||!A.contains(document.activeElement)||(At.current?.focus(),At.current?.select())}))},[s,gt]),Er=a.useCallback(A=>{Qe(K=>z.length===0?0:(K+A+z.length)%z.length)},[z.length]),da=a.useCallback(A=>{if(A.nativeEvent.isComposing||!$b(_.current,s,A))return;const K=Lb(A);if(K==="open"&&gt){A.preventDefault(),Cr();return}ye&&(K==="close"?(A.preventDefault(),Zr()):(K==="next"||K==="previous")&&(A.preventDefault(),Er(K==="previous"?-1:1)))},[s,Zr,ye,Er,Cr,gt]);if(a.useLayoutEffect(()=>{if(co(I.current),!s||!ye||!vt.trim()||!$e.current){oe([]),Qe(0);return}const A=Ab($e.current,vt);return oe(A),Qe(0),(_.current?.contains(document.activeElement)||yu(I.current))&&(Yi(A,0,I.current),wu(A[0])),()=>co(I.current)},[s,ye,vt,_e,fe,R]),a.useEffect(()=>{!s||!ye||!vt.trim()||!_.current?.contains(document.activeElement)&&!yu(I.current)||(Yi(z,je,I.current),wu(z[je]))},[s,je,z,ye,vt]),a.useEffect(()=>()=>co(I.current),[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:o("rightSidebar.selectFilePrompt")});const Xe=W&&!n.startsWith("/")?`${W}/${n}`:n,Mr=yo(Xe,W),zt=ef(Xe,W),Hr=R.kind==="text"&&R.content?R.content.split(`
1654
+ `):[],Wt=Math.max(2,String(Hr.length).length)+1,$r=R.kind==="text"||R.kind==="image"||R.kind==="model3d"||R.kind==="video"||R.kind==="eda"?R.meta:null,Lr=Ks(Xe),ua=Xe.toLowerCase().endsWith(".csv"),en=Xe.toLowerCase().endsWith(".kicad_pro"),Tn=Xe.toLowerCase().endsWith(".kicad_prl"),tn=R.kind==="text"&&Lr&&fe==="preview",wt=zs(Xe),Tt=R.kind==="text"&&wt&&Oe==="preview",gs=R.kind==="image"||R.kind==="loading"&&R.mode==="image",bs=R.kind==="model3d"||R.kind==="loading"&&R.mode==="model3d",xs=R.kind==="video"||R.kind==="loading"&&R.mode==="video",vs=R.kind==="eda"||R.kind==="loading"&&R.mode==="eda",fa=R.kind==="text"?R.sourcePath:Xe,ur=wp(fa,W,M),Pr=(()=>{if(!M||R.kind!=="text"||Hr.length===0)return ur;const A=[];for(let ke=M.start;ke<=M.end;ke+=1)A.push(`${ke} ${Hr[ke-1]??""}`);const K=Bf(Xe).replace(/^\./,""),be="```";return`${ur}
1655
1655
  ${be}${K}
1656
1656
  ${A.join(`
1657
1657
  `)}
1658
1658
  ${be}
1659
- `})(),Pr=`path:${Xe}`,Hr=M?`path:${Xe}:${M.start}-${M.end}`:Pr,tn=P===Pr,ur=P===Hr,rn=B===Pr,Tn=B===Hr,In=ur||Tn,Wt=M?M.start===M.end?`L${M.start}`:`L${M.start}-${M.end}`:null,Gt=A=>{const K=$e.current;if(!K)return;const be=K.getBoundingClientRect(),ke=A.currentTarget.getBoundingClientRect(),We=A.clientX||ke.left+ke.width/2,tt=(A.clientY||ke.top+ke.height/2)-be.top+K.scrollTop,Ge=p?116:132,ht=K.scrollLeft+Math.max(8,K.clientWidth-Ge),bt=Math.min(Math.max(8,We-be.left+K.scrollLeft+10),ht);xe({top:tt,left:bt})},we=(A,K)=>{fl()||(Gt(A),N(be=>{const ke=hl(be,K,K);return ke||xe(null),ke}))},rr=(A,K,be)=>{Gt(A),N(ke=>{const We=hl(ke,K,be);return We||xe(null),We})},nn=(A,K,be,ke)=>{ke==="end"&&Gt(A),N({start:K,end:be})},Dn=A=>{const{scrollTop:K,scrollLeft:be}=A.currentTarget;ge(K),tl(W,n,{top:K,left:be,markdownTop:K})},vs=A=>{if(A.directory){f?.(A.path);return}if(A.path===Xe||R.kind==="text"&&A.path===R.sourcePath){A.fragment&&Pn(A.fragment);return}ne(K=>[...K,Xe]),De.current=A.path,Je(A.fragment),N(null),O(A.path)},Fn=()=>{const A=Le[Le.length-1];A&&(ne(K=>K.slice(0,-1)),De.current=A,Je(null),N(null),O(A))},It=A=>{const{scrollTop:K,scrollLeft:be}=A.currentTarget;tl(W,n,{top:K,left:be})},ua=A=>{if(r){r(Lr,Hr);return}M&&d(Lr,Hr,A.currentTarget)},_n=()=>{if(!(R.kind==="loading"||R.kind==="error"))return te.start()};return e.jsxs("div",{ref:_,tabIndex:-1,onKeyDown:la,onFocusCapture:()=>{s&&ye&&vt.trim()&&qi(z,je,I.current)},onPointerDownCapture:A=>{A.target instanceof Element&&!A.target.closest('button, input, textarea, select, a, [tabindex]:not([tabindex="-1"])')&&A.currentTarget.focus({preventScroll:!0})},className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Rr.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${p&&(en||Tt)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[p&&g&&e.jsx("button",{type:"button",onClick:g,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":o("rightSidebar.backToFileList"),title:o("rightSidebar.backToFileList"),children:e.jsx(Zu,{size:16})}),Le.length>0&&e.jsxs("button",{type:"button",onClick:Fn,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${p?"w-9":"px-2.5"}`,"aria-label":o("rightSidebar.backToPreviousPreview"),title:o("rightSidebar.backToPreviousPreview"),children:[e.jsx(ta,{size:15}),!p&&e.jsx("span",{className:"text-[11px] font-medium",children:o("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Xe,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Er.name}),Er.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Er.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[gt&&e.jsx("button",{type:"button",onClick:ye?Qr:Cr,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 ${ye?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":o("rightSidebar.findInFile"),title:`${o("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(hs,{size:14})}),$r&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{x&&E?.(),Fe(A=>{const K=A==="preview"?"source":"preview";return Lt(yf,K),K}),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 ${p?"w-9 px-0":"px-3"}`,"aria-label":o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:p?fe==="preview"?e.jsx(pl,{size:14}):e.jsx(ml,{size:14}):o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),wt&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{G(A=>{const K=A==="preview"?"source":"preview";return qg(W,n,K),K}),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 ${p?"w-9 px-0":"px-3"}`,"aria-label":o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:p?Oe==="preview"?e.jsx(pl,{size:14}):e.jsx(ml,{size:14}):o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Tt&&e.jsx("button",{type:"button",onClick:()=>{Ne.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":o(Se?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:o(Se?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(ef,{size:15})}),!p&&e.jsx("button",{type:"button",onClick:A=>l(Xe,Pr,A.currentTarget),...Rr(Ht,Pr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${tn||rn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:o("rightSidebar.insertReference",{reference:Ht}),children:o(rn?"rightSidebar.copied":tn?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Ht)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:o("rightSidebar.copyReference",{reference:Ht}),"aria-label":o("rightSidebar.copyFileRef"),children:e.jsx(Gm,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{_n()},disabled:te.status==="pending"||R.kind==="loading"||R.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:te.status==="error"?te.error??o("rightSidebar.downloadFailed"):o("rightSidebar.downloadFile"),"aria-label":o("rightSidebar.downloadFile"),children:te.status==="pending"?e.jsx(dt,{size:13,className:"animate-spin"}):e.jsx(Xu,{size:14})}),te.status==="pending"&&e.jsx("button",{type:"button",onClick:te.cancel,className:"inline-flex h-9 shrink-0 items-center rounded-full bg-surface-2 px-2 text-xs text-foreground hover:bg-surface-elevated",children:o("common.cancel")})]})]}),te.status==="error"&&e.jsxs("div",{role:"alert",className:"mt-2 text-xs text-destructive",children:[o("rightSidebar.downloadFailed"),": ",te.error]}),te.status==="canceled"&&e.jsx("div",{role:"status",className:"mt-2 text-xs text-muted-foreground",children:o("rightSidebar.downloadCanceled")}),ye&&gt&&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(hs,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:At,type:"search",value:vt,onChange:A=>Zt(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),Nr(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:o("rightSidebar.findInFilePlaceholder"),"aria-label":o("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:z.length>0?`${je+1}/${z.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Nr(-1),disabled:z.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":o("rightSidebar.previousSearchMatch"),title:`${o("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Ll,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Nr(1),disabled:z.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":o("rightSidebar.nextSearchMatch"),title:`${o("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(bp,{size:13})}),e.jsx("button",{type:"button",onClick:Qr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.closeFileSearch"),title:`${o("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Pt,{size:13})})]}),Mr&&!(p&&(en||Tt))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[Mr.size!==null&&e.jsx("span",{children:o("rightSidebar.byteCount",{count:Mr.size.toLocaleString()})}),"truncated"in Mr&&Mr.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:o("rightSidebar.previewTruncated")}),"mimeType"in Mr&&e.jsx("span",{children:Mr.mimeType}),"dimensions"in R&&R.dimensions&&e.jsxs("span",{children:[R.dimensions.width," × ",R.dimensions.height]})]}),!(p&&(en||Tt))&&!gs&&R.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:xs?o("rightSidebar.edaPickHint"):ca?o("rightSidebar.csvTablePreview"):Zr||An?o("rightSidebar.kicadProjectPickHint"):bs?o("rightSidebar.videoPreviewHint"):ps?o("rightSidebar.imagePreviewHint"):en?M?o("rightSidebar.selectedLineHint",{lineLabel:Wt??""}):o("rightSidebar.markdownPreviewHint"):Tt?o("rightSidebar.htmlPreviewHint"):M?o("rightSidebar.selectedLineHint",{lineLabel:Wt??""}):o("rightSidebar.multiLineHint")})})]}),!s&&(R.kind==="video"||R.kind==="model3d"||R.kind==="eda"||Tt)?null:R.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8",children:e.jsx(Bi,{label:R.mode==="eda"?o("rightSidebar.edaLoading"):R.mode==="image"?o("rightSidebar.loadingImage"):R.mode==="model3d"?o("rightSidebar.model3dLoading"):R.mode==="video"?o("rightSidebar.loadingVideo"):o("common.loading")})}):R.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:R.message}),e.jsx("button",{type:"button",onClick:Jr,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:o("common.retry")})]}):R.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:o("rightSidebar.binaryPreviewHint")})}):R.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:R.meta.mimeType==="image/svg+xml"?e.jsx(pf,{blobUrl:R.objectUrl,filePath:Xe,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(xh,{src:R.objectUrl,alt:Er.name,vector:!1,onLoad:A=>{const K=A.currentTarget;H(be=>be.kind==="image"?{...be,dimensions:{width:K.naturalWidth,height:K.naturalHeight}}:be)},onError:()=>H({kind:"error",message:o("rightSidebar.imageLoadFailed")})})}):R.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(sb,{url:R.url,onLoadError:()=>H({kind:"error",message:o("rightSidebar.videoLoadFailed")})})}):R.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ub,{blobUrl:R.objectUrl,filePath:R.sourcePath,view:R.view,board:Xe.toLowerCase().endsWith(".kicad_pcb"),onViewChange:L,onInsertAnnotation:r??c,onRefresh:Jr,interactive3d:U?e.jsx(a.Suspense,{fallback:e.jsx(Bi,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Su,{blobUrl:U.objectUrl,ext:".glb",fileName:Er.name,filePath:U.sourcePath,features:null,onInsertFeature:r??c,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:R.view==="pcb-3d"})}):void 0})}):R.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(Bi,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Su,{blobUrl:R.objectUrl,ext:R.ext,fileName:Er.name,filePath:R.sourcePath,features:he,onInsertFeature:r??c,onRefresh:Jr})})}):R.kind==="text"&&ca?e.jsx(mb,{content:R.content,filePath:Xe,onInsertAnnotation:r??c},Xe):R.kind==="text"&&(Zr||An)?e.jsx(bb,{content:R.content,filePath:Xe,localState:An,onInsertAnnotation:r??c},Xe):en?e.jsxs("div",{ref:$e,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:Dn,style:{touchAction:"pan-x pan-y"},children:[e.jsx(lh,{content:R.content,filePath:R.sourcePath,rootPath:W,lineRange:M,onLineRangeClick:rr,onLineRangeDrag:nn,scrollTop:me,outlineOpen:x,outlineCloseSignal:h,onOutlineOpen:b,onOutlineClose:E,lightboxOpen:S,lightboxCloseSignal:T,onLightboxOpen:D,onLightboxClose:F,onLocalLinkOpen:vs}),M&&J&&e.jsxs("button",{type:"button",onClick:ua,...Rr(Lr,Hr),style:{top:J.top,left:J.left,transform:"translateY(-50%)"},className:tu(p,In),title:`Insert markdown reference: ${dr}`,children:[e.jsx(So,{size:p?13:11}),Tn?o("rightSidebar.copied"):ur?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:Wt??""})]})]}):Tt?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Rb,{ref:Ne,src:Km(Xe),title:`${Er.name} preview`,exitFullscreenLabel:o("rightSidebar.htmlFullscreenExit"),onFullscreenChange:de},`${Xe}:${cr}:${Ln}`)}):R.kind==="text"?e.jsxs("div",{ref:$e,onScroll:It,className:`${Tl} 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:[Ur.length>0?e.jsx("div",{className:"min-w-full",children:Ur.map((A,K)=>{const be=K+1,ke=!!(M&&be>=M.start&&be<=M.end),We=_e&&_e.length===Ur.length?_e[K]:null;return e.jsxs("div",{ref:Ue=>{Ue?Ce.current.set(be,Ue):Ce.current.delete(be)},role:"button","data-file-preview-line":be,tabIndex:0,onClick:Ue=>we(Ue,be),onKeyDown:Ue=>{Ue.key!=="Enter"&&Ue.key!==" "||(Ue.preventDefault(),we(Ue,be))},style:{gridTemplateColumns:`${zt}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 ${Ht}:${be}`,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:be}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:We??(A||" ")})]},K)})}):"Empty file.",M&&J&&e.jsxs("button",{type:"button",onClick:ua,...Rr(Lr,Hr),style:{top:J.top,left:J.left,transform:"translateY(-50%)"},className:tu(p,In),title:`Insert code reference: ${dr}`,children:[e.jsx(So,{size:p?13:11}),Tn?o("rightSidebar.copied"):ur?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:Wt??""})]})]}):null]})}function u0({rootPath:r,file:n,active:s,...l}){const[d,c]=a.useState(null),[m,g]=a.useState(n.line??1),f=a.useCallback(()=>g(null),[]);return e.jsx("div",{"data-architecture-source":!0,className:"h-full min-h-0",children:e.jsx(Po,{...l,filePath:`${r.replace(/\/+$/,"")}/${n.path}`,active:s,lineRange:d,onLineRangeChange:c,scrollToLine:m,onScrollToLineHandled:f,markdownOutlineOpen:!1,markdownImageLightboxOpen:!1})})}function f0({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:d,push:c,pinned:m=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:f=!1,rightSidebarFilePreviewCloseSignal:p,onOpenRightSidebarFilePreview:x,onCloseRightSidebarFilePreview:h,rightSidebarRepoPickerOpen:b=!1,rightSidebarRepoPickerCloseSignal:E,onOpenRightSidebarRepoPicker:S,onCloseRightSidebarRepoPicker:T,markdownOutlineOpen:D=!1,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:N,markdownImageLightboxOpen:P=!1,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j}){const{t:o,locale:_}=ft(),[I,V]=a.useState(""),[W,O]=a.useState(null),R=Q(t=>t.rightSearchOpen),H=Q(t=>t.setRightSearchOpen),ee=Q(t=>t.rightSidebarLayoutPreference),L=Q(t=>t.setRightSidebarLayoutPreference),[U,X]=a.useState(()=>sx()),[ce,he]=a.useState("."),[Re,Ce]=a.useState(""),[$e,J]=a.useState(!1),[xe,fe]=a.useState(!1),[Fe,Oe]=a.useState(!1),[G,Ne]=a.useState(!1),Se=a.useDeferredValue(I),[de,qe]=a.useState(null),[$,me]=a.useState([]),[ge,Le]=a.useState([]),ne=Q(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Ye=Q(t=>t.setActiveGitRepo),[Je,De]=a.useState(null),[Te,_e]=a.useState(null),[Be,te]=a.useState(null),[ye,nt]=a.useState(()=>pt(xu,Xs)??!1),[vt,Zt]=a.useState(()=>pt(vu,Xs)??!1),[z,oe]=a.useState(()=>pt(yu,Xs)??!1),[je,Qe]=a.useState(()=>pt(Xi,Zb)??""),[At,Rr]=a.useState(0),[er,yt]=a.useState(!1),[cr,tr]=a.useState(!1),$n=a.useRef(null),Ln=a.useRef(null),[Do,Jr]=a.useState(!1),[Pn,gt]=a.useState(null),[Qr,Cr]=a.useState(null),[Nr,la]=a.useState(()=>Ru(Vi)),[Xe,Er]=a.useState(()=>Ru(bu)),[Ht,Ur]=a.useState(()=>Qb()),[zt,Mr]=a.useState(()=>ex()),[$r,ca]=a.useState(()=>rx()),Zr="words",[An,en]=a.useState(0),[wt,Tt]=a.useState([]),[ps,gs]=a.useState([]),[bs,xs]=a.useState(!1),[da,dr]=a.useState(null),[Lr,Pr]=a.useState([]),[Hr,tn]=a.useState(!1),[ur,rn]=a.useState([]),[Tn,In]=a.useState([]),[Wt,Gt]=a.useState(!1),[we,rr]=a.useState(null),[nn,Dn]=a.useState([]),[vs,Fn]=a.useState({}),It=a.useRef(0),[ua,_n]=a.useState(0),[A,K]=a.useState(!1),[be,ke]=a.useState(null),[We,Ue]=a.useState(null),[tt,Ge]=a.useState(null),[ht,bt]=a.useState(null),[fr,Ar]=a.useState(!1),[Bn,sn]=a.useState(""),ys=a.useDeferredValue(Bn),[hr,ws]=a.useState({}),[an,zr]=a.useState([]),[re,Ke]=a.useState(!1),[Kt,Tr]=a.useState(!1),[Fo,On]=a.useState(null),[_o,Un]=a.useState(!1),mr=a.useRef(null),Wr=a.useRef(0),Gl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[vh,fa]=a.useState(null),[ks,Kl]=a.useState(()=>pt(Yi,Xs)??!1),[Bo,Oo]=a.useState(!1),[ha,Uo]=a.useState([]),[nr,ma]=a.useState({}),[Nt,pa]=a.useState({}),[on,Ho]=a.useState({}),[ql,Vl]=a.useState(()=>new Set),[Ze,ln]=a.useState(null),[zo,cn]=a.useState(null),[yh,Ir]=a.useState(!1),[Wo,Dr]=a.useState(0),[,Go]=a.useState(0),[Ko,ga]=a.useState(!1),[wh,kh]=a.useState(()=>Q.getState().rightTab==="files"),[sr,qo]=a.useState(!1),[Sh,Yl]=a.useState(()=>Q.getState().rightTab==="diff"),[Vo,Xl]=a.useState(()=>Q.getState().rightTab==="android"),[Gr,Jl]=a.useState(!1),ba=Oi(t=>t.docks[Hi]),jh=!!ba,[ze,Ss]=a.useState(null),[Hn,js]=a.useState(null),[kt,dn]=a.useState(null),[Ql,qt]=a.useState(null),[zn,Zl]=a.useState(null),[Yo,Rh]=a.useState(()=>Date.now()),[Ch,Nh]=a.useState(!1),[un,xa]=a.useState(!1),[va,ec]=a.useState(""),[Wn,ya]=a.useState(""),[fn,wa]=a.useState(""),[hn,ka]=a.useState(""),[tc,Gn]=a.useState(null),[rc,Xo]=a.useState(!1),[nc,sc]=a.useState(!1),[Sa,Eh]=a.useState({key:null,nonce:0}),ac=a.useRef(null),oc=a.useRef(null),se=ap(s,m,ee),Jo=$f(se,m,$r),[Qo,Zo]=a.useState(()=>ux(s)),ei=Q(t=>t.rightTab),pr=Q(t=>t.setRightTab),v=Q(t=>t.rootPath),Kn=Q(t=>t.explorerRoot),ic=Q(t=>t.pinnedExplorerRootsCache),lc=Q(t=>t.hydratePinnedExplorerRoots),cc=Q(t=>t.syncPinnedExplorerRoots),Dt=Q(t=>t.setExplorerRoot),dc=Q(t=>t.resetExplorerToProject),qn=Q(t=>t.pinExplorerRoot),mn=Q(t=>t.unpinExplorerRoot),at=Q(t=>t.selectedFilePath),ot=Q(t=>t.selectFile),ti=Q(t=>t.showHiddenFiles),Mh=Q(t=>t.toggleShowHiddenFiles),ri=Q(t=>!!(v&&t.nestedGitScanRoots[v])),Ie=Q(t=>t.changedFiles),ja=Q(t=>t.setChangedFiles),Rs=Q(t=>t.invalidateDirectoryCache),$h=Q(t=>t.setDirectorySortMode),uc=Q(t=>t.applyFileWatchEvents),fc=Q(t=>t.reconcileDirectoryCache),hc=Q(t=>t.bumpFileWatchEpoch),gr=Q(t=>t.gitBundleLoading),mc=Q(t=>t.gitBundleSlow),pn=Q(t=>t.gitBundleError),Vn=Q(t=>t.gitBundleLastLoadedAt),pc=Q(t=>t.beginGitBundleLoading),gc=Q(t=>t.setGitBundleSlowFor),ni=Q(t=>t.finishGitBundleLoading),Ra=Q(t=>t.resetGitBundleLoading),si=Q(t=>t.setGitBundleError),bc=Q(t=>t.markGitBundleLoaded),ie=Kn??v,Ca=Q(t=>!!(ie&&t.hideGitIgnoredRoots[ie])),Lh=Q(t=>t.hideGitIgnoredRootsHydrated),Ph=Q(t=>t.setHideGitIgnoredRoot),[ai,xc]=a.useState(!1),[vc,oi]=a.useState(null);a.useEffect(()=>{oi(null)},[ie]);const yc=a.useMemo(()=>ie?Lb(ie,ce):"",[ie,ce]),Cs=a.useMemo(()=>$b(Re),[Re]),wc=a.useMemo(()=>({excludePatterns:Cs,caseSensitive:xe,wholeWord:Fe,regex:G}),[xe,Cs,G,Fe]),Na=Q(t=>ie?t.fileSortModes[ie]??"name":"name"),kc=Q(t=>!!(ie&&t.directoryCache.has(ie))),Yn=a.useRef(null),Rt=a.useRef(0),[Sc]=a.useState(()=>++a0),Fr=a.useRef(null),Kr=a.useRef(null),Ea=a.useRef(0),Vt=a.useRef(new Map),Yt=a.useRef(new Map),br=a.useRef(new Set),gn=a.useRef(new Set),bn=a.useRef(0),qr=a.useRef(null),Xn=a.useRef(0),Jn=a.useRef(null),Qn=a.useRef(0),Vr=a.useRef(null),ii=a.useRef(new Set),li=a.useRef(null),ci=a.useRef(null),Ma=a.useRef(null),di=a.useRef(null),ui=a.useRef(null),Ns=a.useRef(new Set);a.useEffect(()=>{if(zn===null)return;const t=Math.max(0,Date.now()-zn),i=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,u=Math.max(50,i-t%i),w=window.setTimeout(()=>Rh(Date.now()),u);return()=>window.clearTimeout(w)},[Yo,zn]);const $a=a.useRef(null),_r=a.useRef(null),fi=a.useRef(null),jc=a.useRef(null),Es=a.useRef(null),Me=a.useCallback(t=>Q.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=i=>{const u=c0(i.target);u&&Vs("global_change_row_event",{...d0(i),selectionPath:u.dataset.diffSelectionPath,filePath:u.dataset.diffFilePath,absolutePath:u.dataset.diffAbsolutePath,repoRoot:u.dataset.diffRepoRoot,status:u.dataset.diffStatus,selectedFilePath:Q.getState().selectedFilePath,rightTab:Q.getState().rightTab,activeGitRepoRoot:ne,changedFiles:Q.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[ne,r]);const Rc=a.useCallback(async(t=v??void 0)=>{if(!t)return null;if(br.current.has(t)||gn.current.has(t))return ct("untracked_skip_cached",{cwd:t,rootPath:v,completed:br.current.has(t),running:gn.current.has(t)}),null;const i=v,u=Ea.current+1;Ea.current=u,Vt.current.set(t,u);const w=`right-sidebar-git-untracked:${t}`,y=new AbortController;Yt.current.set(t,y),gn.current.add(t),ct("untracked_start",{requestId:u,cwd:t,rootPath:v});try{let k=await _d(t,y.signal,w),C=0;for(;k.status==="running"&&C<120;){if(Vt.current.get(t)!==u||y.signal.aborted)return ct("untracked_stale_result",{requestId:u,activeRequestId:Vt.current.get(t),cwd:t,status:k.status}),null;if(!Me(i))return ct("untracked_root_changed",{requestId:u,cwd:t,expectedRootPath:i,currentRootPath:Q.getState().rootPath}),null;await new Promise(ae=>window.setTimeout(ae,C<10?1e3:3e3)),C+=1,k=await _d(t,y.signal,w)}if(Vt.current.get(t)!==u||!Me(i))return ct("untracked_stale_result",{requestId:u,activeRequestId:Vt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Q.getState().rootPath,files:k.files.length,status:k.status}),null;if(k.status==="done")return ja(fh(Q.getState().changedFiles,k.files)),k.files.length>0&&me(ae=>{const Pe=new Map(ae.map(pe=>[pe.root,pe])).get(t);if(!Pe)return ae;const et=qx(Pe.files,k.files),Z=ae.map(pe=>pe.root===t?{...pe,files:et,context:pe.context?{...pe.context,changedFiles:et.map(Ae=>({path:Ae.path,absolutePath:Ae.absolutePath,status:Ae.status})),truncated:!1}:pe.context,untrackedDeferred:!1}:pe);Le(hh(Z,v));const Y=Z.find(pe=>pe.root===v);return Y?.context&&qe(pe=>pe?.root===Y.root?{...pe,...Y.context}:pe),Z}),br.current.add(t),ct("untracked_apply",{requestId:u,cwd:t,files:k.files.length}),k;const le=k.error||(k.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return br.current.add(t),ct("untracked_error",{requestId:u,cwd:t,message:le,code:k.code,status:k.status}),null}catch(k){if(Vt.current.get(t)!==u||!Me(i)||Sr(k))return ct("untracked_aborted",{requestId:u,activeRequestId:Vt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:Q.getState().rootPath,message:k instanceof Error?k.message:String(k)}),null;const C=k instanceof Error?k.message:"Failed to scan untracked files";return br.current.add(t),ct("untracked_error",{requestId:u,cwd:t,message:C}),null}finally{Yt.current.get(t)===y&&Yt.current.delete(t),Vt.current.get(t)===u&&Vt.current.delete(t),gn.current.delete(t)}},[de,Me,v,ja]),ar=a.useMemo(()=>{const t=new Set(ge.map(u=>u.root)),i=Lr.filter(u=>t.has(u));return i.length>0?i:ne?[ne]:[]},[ne,Lr,ge]),Cc=ar.length===0,xn=a.useMemo(()=>ar.map(t=>$.find(i=>i.root===t)).filter(t=>!!t),[ar,$]),Ah=a.useMemo(()=>ge.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[ge]),xr=a.useCallback(async()=>{if(!v){Tt([]),gs([]);return}const t=v,i=Xn.current+1;Xn.current=i,Jn.current?.abort();const u=new AbortController;Jn.current=u,xs(wt.length===0),dr(null);try{const w=ar.length>0?await Promise.all(ar.map(y=>Bd({workspaceRoot:v,repoRoot:y},u.signal))).then(y=>({records:y.flatMap(k=>k.records),walkthroughs:y.flatMap(k=>k.walkthroughs??[])})):await Bd({workspaceRoot:v},u.signal);if(Xn.current!==i||!Me(t))return;Tt(w.records),gs(w.walkthroughs??[])}catch(w){if(Xn.current!==i||!Me(t)||Sr(w))return;dr(w instanceof Error?w.message:"Failed to load change audit explanations")}finally{Jn.current===u&&(Jn.current=null),Xn.current===i&&Me(t)&&xs(!1)}},[wt.length,ar,Me,v]),La=a.useCallback(async(t,i,u)=>{if(!t&&!v){rn([]),In([]);return}const w=v,y=Qn.current+1;Qn.current=y,Vr.current?.abort();const k=new AbortController;Vr.current=k;try{const C=t?[t]:Array.from(new Set([v,...$.map(ae=>ae.root)].filter(ae=>!!ae))),le=await Promise.all(C.map(ae=>Vm({repoRoot:ae,baseRef:i,branchName:u},k.signal))).then(ae=>{const ve=new Map,Pe=new Map;for(const et of ae){for(const Z of et.records)ve.set(Z.id,Z);for(const Z of et.walkthroughs??[])Pe.set(Z.id,Z)}return{records:Array.from(ve.values()),walkthroughs:Array.from(Pe.values())}});if(Qn.current!==y||!Me(w))return;rn(le.records),In(le.walkthroughs??[])}catch(C){if(Qn.current!==y||!Me(w)||Sr(C))return;console.warn("[RightSidebar] Failed to load branch explanations",C)}finally{Vr.current===k&&(Vr.current=null)}},[$,Me,v]),Zn=a.useCallback((t,i={})=>{if(!Me(v)){ct("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:Q.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}ct(t.files.length===0?"empty_bundle":"apply",{rootPath:v,available:t.available,files:t.files.length,repositories:t.repositories?.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length,available:Y.available,error:Y.error})),repoFilters:t.repoFilters?.map(Y=>({root:Y.root,label:Y.label,count:Y.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let u=Lf(t),w=t.repoFilters??[],y=t.files;const k=Q.getState().changedFiles;if(!!(i.cacheOnly&&!t.cached&&t.files.length===0&&u.length===0)&&(k.size>0||$.length>0||de)){ct("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:k.size,currentRepositories:$.length});return}const le=u.some(Y=>Y.deferred);if(le&&!i.replaceWorkspace){const Y=new Set(u.filter(Ae=>!Ae.deferred||Ae.root===v).map(Ae=>Ae.root));y=[...Array.from(k.values()).filter(Ae=>!Y.has(xt(Ae,v)??"")),...t.files]}const ae=Du(k.values(),v),ve=Du(t.files,v),Pe=u.some(Y=>Y.root!==v);if(!!(i.background&&!le&&!i.replaceWorkspace&&k.size>0&&(t.files.length===0&&!t.error||ae>0&&ve===0&&!Pe))){ct("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:k.size,nextFiles:t.files.length,currentNestedCount:ae,nextNestedCount:ve,nextRepositories:u.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(i.replaceRepoRoot){const Y=mh(k.values(),$,t,i.replaceRepoRoot,v);y=Y.files,u=Y.repositories,w=Y.repoFilters}if(ja(uh(y)),me(Y=>{if(!le||i.replaceWorkspace)return u;const pe=new Map(Y.map(Ae=>[Ae.root,Ae]));return u.map(Ae=>{const Ve=pe.get(Ae.root);return!Ae.deferred||!Ve?Ae:{...Ae,available:Ve.available,files:Ve.files,context:Ve.context,deferred:Ve.deferred,untrackedDeferred:Ve.untrackedDeferred,error:Ve.error}})}),Le(w),ui.current=v,i.syncActiveRepo!==!1){const{contextKey:Y,activeGitRepos:pe}=Q.getState(),Ae=Y?pe[Y]??null:null,Ve=i.activeRepoRoot!==void 0?i.activeRepoRoot:Ae,He=ax({...t,repositories:u,repoFilters:w},Ve);Ye(He)}typeof t.cacheUpdatedAt=="number"&&Zl(t.cacheUpdatedAt),qe(Y=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==v)return Y;if(!t.context)return null;const pe=Y?.root??v;return!Y?.available||pe!==(t.context.root??v)?t.context:{...Y,...t.context}}),i.reloadDiff&&en(Y=>Y+1);const Z=Q.getState().selectedFilePath;if(Z&&!Z.startsWith("/")&&!y.some(Y=>Y.path===Z||Y.absolutePath===Z)&&ot(null),la(Y=>{const pe=new Set(y.map(Ve=>xt(Ve,v)).filter(Boolean)),Ae=new Set;for(const Ve of Y)pe.has(Ve)&&Ae.add(Ve);return Qi(Vi,Ae),Ae}),i.loadDeferred!==!1){const Y=u.filter(pe=>pe.untrackedDeferred&&pe.root).map(pe=>pe.root);for(const pe of Y)Rc(pe)}i.loadAudit!==!1&&xr()},[Me,xr,Rc,v,ot,Ye,ja]);a.useEffect(()=>{Ra(),li.current=null,ci.current=v;const t=[],i=[];Rt.current+=1,bn.current+=1,Ea.current+=1,Fr.current?.abort(),Ct(Ks(Kr.current?.cwd??v??void 0)),Kr.current=null,Fr.current=null,qr.current?.abort(),Ct("right-sidebar-git-details"),qr.current=null;for(const C of Yt.current.values())C.abort();for(const C of Yt.current.keys())Ct(`right-sidebar-git-untracked:${C}`);Yt.current.clear(),Vt.current.clear(),Xn.current+=1,Jn.current?.abort(),Jn.current=null,Qn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,Tt([]),gs([]),xs(!1),dr(null),Pr([]),tn(!1),rn([]),In([]),Gt(!1),rr(null),K(!1),ke(null),Ue(null),Ge(null),bt(null),Ar(!1),sn(""),zr([]),Ke(!1),Tr(!1),On(null),Un(!1),fa(null),ln(null),cn(null),Kl(!1),Lt(Yi,!1),Oo(!1);const u=v?Cu()[v]:null,w=u?.previewEntries??[],y=u?.selectedPreviewKey??null,k=y?w.find(C=>C.key===y)??null:null;++It.current,K(!1),Uo(u?.selectedRepoRoots??[]),ma(u?.repoTargetBranches??{}),pa(u?.repoBaseBranches??{}),Dn(w),Fn(u?.previewScrollTops??{}),k&&u?.previewDetailOpen&&(k.diff.hunks?.length??0)>0&&(rr(k.diff),ln(k.key),cn(u.selectedPreviewFileKey??(k.diff.hunks?.[0]?`${k.diff.hunks[0].filePath}\0${k.diff.hunks[0].hunkHeader}\0${k.diff.hunks[0].hunkIndex}`:null)),Gt(!0)),Ho(u?.repoIncludeUncommitted??Object.fromEntries(Object.keys(u?.repoTargetBranches??{}).map(C=>[C,u?.includeUncommitted??!0]))),li.current=v,xa(!1),br.current.clear(),gn.current.clear(),Ss(null),js(null),dn(null),qt(null),Zl(null),me(t),Le(i),qe(null),di.current=null,ui.current=null,Ns.current.clear()},[Ra,v]);const Ft=a.useCallback(async(t=v??void 0,i={})=>{if(!t)return null;const u=v,w=Rt.current;if(await cg(()=>Promise.all([Q.getState().hydrateNestedGitScanRoots(),Q.getState().hydrateActiveGitRepos()]).then(()=>{})),Rt.current!==w||!Me(u))return null;const y=t===v&&Ws(v),k=i.includeNested??y,C=i.refresh??i.reloadDiff??!1,le=i.cacheOnly??!1,ae=i.background??!1,ve=k&&(i.discoverOnly??!1);C&&br.current.clear();const Pe=Kr.current;if(Pe&&Pe.cwd===t&&Pe.includeNested===k&&Pe.refresh===C&&Pe.cacheOnly===le&&Pe.discoverOnly===ve)return ct("reuse_pending",{cwd:t,includeNested:k,refresh:C,cacheOnly:le,discoverOnly:ve}),Pe.promise;const et=Rt.current+1;Rt.current=et;const Z=`right-sidebar:${Sc}:${et}`;Fr.current?.abort();const Y=Ks(t);Ct(Y);const pe=new AbortController;Fr.current=pe;let Ae=null;ae||pc(Z),si(null),ct("start",{requestId:et,cwd:t,rootPath:v,requestSlotId:Y,includeNested:k,refresh:C,cacheOnly:le,background:ae,existingChanges:Ie.size,lastLoadedAt:Vn}),!ae&&typeof window<"u"&&(Ae=window.setTimeout(()=>{Rt.current===et&&gc(Z,!0)},Ob));const Ve=(async()=>{const He=await Ui(t,pe.signal,{includeNested:k,refresh:C,cacheOnly:le,discoverOnly:ve,action:C?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Y,requestTimeoutMs:C?null:void 0});if(Xx(He)){if(ct("cancelled_result_ignored",{requestId:et,activeRequestId:Rt.current,cwd:t,error:He.error??He.context?.error}),pe.signal.aborted)return null;throw new Error(He.error??He.context?.error??"Failed to load Git changes")}return Rt.current!==et||!Me(u)?(ct("stale_result",{requestId:et,activeRequestId:Rt.current,cwd:t,expectedRootPath:u,currentRootPath:Q.getState().rootPath,files:He.files.length,repositories:He.repositories?.length??0}),null):(Zn(He,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:k,background:ae,cacheOnly:le,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),He)})();Kr.current={cwd:t,includeNested:k,refresh:C,cacheOnly:le,discoverOnly:ve,promise:Ve};try{const He=await Ve;return Rt.current===et&&He&&Me(u)?bc({cached:He.cached,stale:He.stale,cacheAgeMs:He.cacheAgeMs,nestedDeferred:!k||He.nestedDeferred,untrackedDeferred:He.untrackedDeferred}):Rt.current===et&&Me(u)&&ni(Z),He}catch(He){return Rt.current!==et||!Me(u)||pe.signal.aborted?(ct("aborted",{requestId:et,activeRequestId:Rt.current,cwd:t,expectedRootPath:u,currentRootPath:Q.getState().rootPath,message:He instanceof Error?He.message:String(He)}),null):(ct("error",{requestId:et,cwd:t,includeNested:k,refresh:C,background:ae,message:He instanceof Error?He.message:String(He)}),ae||(qe(null),si(He instanceof Error?He.message:"Failed to load Git changes")),null)}finally{Ae!==null&&window.clearTimeout(Ae),Fr.current===pe&&(Fr.current=null),Kr.current?.promise===Ve&&(Kr.current=null),!ae&&Rt.current===et&&Me(u)&&ni(Z)}},[Zn,pc,Ie.size,ni,Sc,Vn,Me,bc,v,si,gc]),es=a.useCallback(async()=>{v&&await Ft(v,{reloadDiff:!0,refresh:!0})},[Ft,v]),hi=a.useCallback(async(t=v??void 0)=>{if(!t)return null;const i=v,u=bn.current+1;bn.current=u,qr.current?.abort(),Ct("right-sidebar-git-details");const w=new AbortController;qr.current=w,xa(!0);try{const y=await Od(t,w.signal,"load_git_details","right-sidebar-git-details");return bn.current!==u||!Me(i)?null:(me(k=>k.map(C=>C.root===y.root?{...C,available:y.available,context:y,error:y.error}:C)),qe(k=>k?.root&&y.root&&k.root!==y.root?k:!k?.available||!y.available?y:{...k,...y}),y)}catch(y){return Sr(y)||!Me(i)||bn.current===u&&qt(y instanceof Error?y.message:"Failed to load Git details"),null}finally{qr.current===w&&(qr.current=null),bn.current===u&&Me(i)&&xa(!1)}},[Me,v]);a.useEffect(()=>{if(!r){Rt.current+=1,Ra(),di.current=null,bn.current+=1,Ea.current+=1,Fr.current?.abort(),Ct(Ks(Kr.current?.cwd??v??void 0)),Kr.current=null,Fr.current=null,qr.current?.abort(),Ct("right-sidebar-git-details"),qr.current=null;for(const t of Yt.current.values())t.abort();for(const t of Yt.current.keys())Ct(`right-sidebar-git-untracked:${t}`);Yt.current.clear(),Vt.current.clear(),Qn.current+=1,Vr.current?.abort(),Vr.current=null,Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,xa(!1),K(!1),ke(null),Ue(null),Ge(null),bt(null),Ar(!1),sn(""),zr([]),Ke(!1),Tr(!1),On(null),Un(!1),V(""),H(!1),gt(null),qo(!1),se&&Yl(!1)}},[se,r,Ra,H]),a.useEffect(()=>{if(!R)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[R]),a.useEffect(()=>{se||Ir(!1)},[se]);const Nc=a.useCallback(t=>{Go(t);const i=fi.current;i&&(i.update(),i.slideTo(t,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(t,0)}))},[]);a.useEffect(()=>{if(se)if(Ir(f),f&&at){Dr(1);const t=_r.current;t&&(t.update(),t.activeIndex!==1&&(Es.current=1,t.slideTo(1,0)))}else{Dr(0);const t=_r.current;t&&t.activeIndex!==0&&(Es.current=0,t.slideTo(0,0)),gt(null)}},[se,f,v,at]),a.useEffect(()=>{if(p!==void 0&&!f){Dr(0);const t=_r.current;t&&t.activeIndex!==0&&(Es.current=0,t.slideTo(0,0)),Ir(!1),gt(null)}},[p,f]),a.useEffect(()=>{E!==void 0&&De(null)},[E]),a.useEffect(()=>{!se&&f&&h?.()},[se,h,f]),a.useEffect(()=>{Zo(t=>Sl(t,s))},[s]);const Th=a.useCallback(t=>{se||(t.preventDefault(),$a.current={startX:t.clientX,startWidth:Qo,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Qo,se]),Ih=a.useCallback(t=>{const i=$a.current;if(!i||i.pointerId!==t.pointerId)return;const u=Sl(i.startWidth+t.clientX-i.startX,s);Zo(u),Js(Ys,u,Bb)},[s]),Ec=a.useCallback(t=>{const i=$a.current;if(!(!i||i.pointerId!==t.pointerId)){$a.current=null,zs(Ys);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),ts=!!(v&&Vn!==null&&Bu(de)),mi=!!(v&&!pn&&Ie.size===0&&Vn===null),Et=(()=>{let t=ei;return t==="android"&&!Gr&&(t="files"),ts&&(t==="git"||t==="diff")&&(t="files"),t})(),lt=Et==="git",Br=Et==="files",Mt=Et==="diff",rs=Et==="android",pi=Et==="computer",vn=Et==="architecture",[Dh,Fh]=a.useState(!1);a.useEffect(()=>{r&&vn&&Fh(!0)},[r,vn]);const gi=a.useRef(null),ns=a.useCallback((t,i)=>{const u=Q.getState().rightTab;if(u===t)return;const w=performance.now(),y=w-i.timeStamp;gi.current={from:u,to:t,startedAt:w,inputDelayMs:y>=0&&y<6e4?Math.round(y):null},pr(t)},[pr]);a.useEffect(()=>{const t=gi.current;if(!t||t.to!==Et)return;gi.current=null;const i=Math.round(performance.now()-t.startedAt);let u=window.requestAnimationFrame(()=>{u=window.requestAnimationFrame(()=>{Vs("tab_switch_presented",{from:t.from,to:t.to,inputDelayMs:t.inputDelayMs,commitMs:i,frameMs:Math.round(performance.now()-t.startedAt)})})});return()=>window.cancelAnimationFrame(u)},[Et]);const _h=xp(t=>t.overlay==="sidebar")&&rs;a.useEffect(()=>{if(!se){ga(!0);return}if(!r){const i=window.setTimeout(()=>{ga(!1)},zb);return()=>window.clearTimeout(i)}ga(!1);const t=window.setTimeout(()=>{ga(!0)},Hb);return()=>window.clearTimeout(t)},[se,r]),a.useEffect(()=>{if(!se||!Mt)return;const t=fi.current;if(!t)return;const i=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(i)},[Mt,se]),a.useEffect(()=>{if(!ts||!v||gr)return;const t=window.setTimeout(()=>{Ft(v,{background:!0})},3e3);return()=>window.clearTimeout(t)},[ts,v,gr,Ft]);const Bh=a.useCallback(t=>{Ft(t,{discoverOnly:!0})},[Ft]);dg({active:r&&(lt||Mt),rootPath:v,loading:gr,delay:lt&&!se?0:Ji,lastStartedRoot:di,load:Bh}),a.useEffect(()=>{!r||!lt||(!se||Ko)&&qo(!0)},[lt,se,r,Ko]),a.useEffect(()=>{if(!r||lt)return;const t=window.setTimeout(()=>{qo(!0)},Ji);return()=>window.clearTimeout(t)},[lt,r]),a.useEffect(()=>{Br&&kh(!0)},[Br]),a.useEffect(()=>{Mt&&Yl(!0)},[Mt]),a.useEffect(()=>{!r||!rs||(n&&ba&&ba.sessionId!==n&&(Oi.getState().setDock(Hi,null),mo({androidPanel:{docked:null}}).catch(()=>{})),Xl(!0))},[rs,r,n,ba]),a.useEffect(()=>{if(r&&rs||!Vo)return;const t=window.setTimeout(()=>Xl(!1),Ub);return()=>window.clearTimeout(t)},[r,rs,Vo]),a.useEffect(()=>{let t=!1;return zu().then(i=>{!t&&i.androidPanel&&Jl(i.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const Mc=a.useCallback(t=>{Jl(t),t?pr("android"):Q.getState().rightTab==="android"&&pr("files"),mo({androidPanel:{enabled:t}}).catch(()=>{})},[pr]),$c=a.useCallback(t=>{ie&&Hx(ie,t.currentTarget.scrollTop)},[ie]);a.useEffect(()=>()=>{Fr.current?.abort(),zs(Pl),zs(Al),zs(Ys),zs(Xi)},[]),a.useEffect(()=>{if(!ie||!kc)return;const t=ch()[ie]?.top;if(typeof t!="number")return;let i=window.requestAnimationFrame(()=>{Yn.current&&(Yn.current.scrollTop=t),i=window.requestAnimationFrame(()=>{Yn.current&&(Yn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(i)},[ie,kc]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return Ym(t.signal).then(i=>sc(!!i.available)).catch(()=>sc(!1)),()=>t.abort()},[r]);const Ms=a.useCallback(t=>{if(O(null),ot(t),gt(null),se){Ir(!0),Dr(1),_r.current?.slideTo(1),x?.();return}},[se,x,ot]),bi=a.useCallback((t,i)=>{if(O(null),ot(t),Cr(i),se){Ir(!0),Dr(1),_r.current?.slideTo(1),x?.();return}},[se,x,ot]),_t=Hg(t=>Rs(t,!1)),Pa=_t.busy,$s=a.useCallback(async(t,i)=>{const u=i||Kn||v;!u||!t.length||await _t.start(u,t)},[Kn,v,_t.start]),Lc=a.useCallback(async t=>{try{await Xm(t)}catch(i){qt(i instanceof Error?i.message:o("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>qt(null),4e3)}},[o]),Aa=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Xo(!0)},[]),Pc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Xo(!1)},[]),Ac=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Xo(!1);const i=t.dataTransfer.files;i.length>0&&$s(Array.from(i))},[$s]),xi=a.useCallback(t=>{_e(t),window.setTimeout(()=>_e(i=>i===t?null:i),1400)},[]),vr=a.useCallback(t=>{te(t),window.setTimeout(()=>te(i=>i===t?null:i),1400)},[]);a.useEffect(()=>{Lt(xu,ye)},[ye]),a.useEffect(()=>{Lt(vu,vt)},[vt]),a.useEffect(()=>{Lt(yu,z)},[z]),a.useEffect(()=>{Js(Xi,je,Tb)},[je]),a.useEffect(()=>(lc().catch(()=>{}),Ud(t=>{t.type==="pinned-explorer-roots"&&cc(t.pinnedExplorerRoots)})),[lc,cc]);const Tc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),Ta=a.useRef(null),yn=a.useRef(null),[Ic,vi]=a.useState(!1);a.useEffect(()=>{if(!r)return;vi(!1);let t=!1;Jm().then(u=>{t||(Ta.current=u.text,Qe(w=>u.text&&u.text!==w?u.text:w),vi(!0))}).catch(()=>{t||vi(!0)});const i=Ud(u=>{u.type==="context-draft"&&u.origin!==Tc.current&&(Ta.current=u.text,Qe(u.text))});return()=>{t=!0,i(),yn.current!==null&&(window.clearTimeout(yn.current),yn.current=null)}},[r]),a.useEffect(()=>{if(!Ic||Ta.current===je)return;yn.current!==null&&window.clearTimeout(yn.current);const t=je;yn.current=window.setTimeout(()=>{yn.current=null,Qm(t,Tc.current).then(()=>{Ta.current=t}).catch(()=>{})},500)},[je,Ic]);const ss=a.useCallback(async(t,i,u,w)=>{if(!t)return!1;if(Zm(u?t+u:t))return xi(i),!0;if(ye)Qe(y=>Bg(y,t)+(u??"")),window.matchMedia("(pointer: coarse)").matches||(Zt(!1),Rr(y=>y+1));else{const y=n??Yr.getState().activeSessionId;if(!await Vu(u?t+u:t,y,()=>Ls.current&&y===Yr.getState().activeSessionId,w))return!1}return xi(i),!0},[ye,xi,n]),Ia=a.useCallback(t=>{const i=Nn(t,v);return vp(i,v)},[v]),yi=lf(vr),Bt=a.useCallback((t,i,u)=>{const w=Nn(t,v);return ss(yp(w,v),i??`path:${w}`,void 0,u)},[v,ss]),Da=a.useRef({sessionId:n,contextDraftEnabled:ye,isOpen:r});Da.current={sessionId:n,contextDraftEnabled:ye,isOpen:r};const Oh=a.useCallback(async t=>{const i=n??Yr.getState().activeSessionId,u=()=>Ls.current&&Da.current.isOpen&&(Da.current.sessionId??Yr.getState().activeSessionId)===i&&Yr.getState().activeSessionId===i&&Da.current.contextDraftEnabled===ye;await _t.start("/tmp",[t],y=>Bt(y,`path:${y}`),u)&&u()&&se&&!ye&&l()},[ye,Bt,se,l,n,_t.start]),Fa=a.useRef(!0),wi=a.useRef(n);wi.current=n,a.useEffect(()=>(Fa.current=!0,()=>{Fa.current=!1}),[]);const Uh=a.useCallback(t=>{wp.getState().enqueue(t,n??null,v||"/",i=>{if(ye&&Fa.current&&wi.current===n)Bt(i);else return Vd(i,n)})},[n,v,ye,Bt]),Hh=a.useCallback(async t=>{const u=(await ll("/tmp",[t])).files[0]?.path;if(!u)throw new Error("截图上传未返回文件路径");ye&&Fa.current&&wi.current===n?Bt(u):await Vd(u,n)},[ye,Bt,n]),or=a.useCallback((t,i,u)=>{if(!t)return Promise.resolve(!1);const w=t.includes(`
1659
+ `})(),Ar=`path:${Xe}`,zr=M?`path:${Xe}:${M.start}-${M.end}`:Ar,rn=P===Ar,fr=P===zr,nn=B===Ar,In=B===zr,Dn=fr||In,Gt=M?M.start===M.end?`L${M.start}`:`L${M.start}-${M.end}`:null,Kt=A=>{const K=$e.current;if(!K)return;const be=K.getBoundingClientRect(),ke=A.currentTarget.getBoundingClientRect(),We=A.clientX||ke.left+ke.width/2,tt=(A.clientY||ke.top+ke.height/2)-be.top+K.scrollTop,Ge=p?116:132,ht=K.scrollLeft+Math.max(8,K.clientWidth-Ge),bt=Math.min(Math.max(8,We-be.left+K.scrollLeft+10),ht);xe({top:tt,left:bt})},we=(A,K)=>{ml()||(Kt(A),C(be=>{const ke=pl(be,K,K);return ke||xe(null),ke}))},nr=(A,K,be)=>{Kt(A),C(ke=>{const We=pl(ke,K,be);return We||xe(null),We})},sn=(A,K,be,ke)=>{ke==="end"&&Kt(A),C({start:K,end:be})},Fn=A=>{const{scrollTop:K,scrollLeft:be}=A.currentTarget;ge(K),nl(W,n,{top:K,left:be,markdownTop:K})},ys=A=>{if(A.directory){f?.(A.path);return}if(A.path===Xe||R.kind==="text"&&A.path===R.sourcePath){A.fragment&&An(A.fragment);return}ne(K=>[...K,Xe]),De.current=A.path,Je(A.fragment),C(null),O(A.path)},_n=()=>{const A=Le[Le.length-1];A&&(ne(K=>K.slice(0,-1)),De.current=A,Je(null),C(null),O(A))},It=A=>{const{scrollTop:K,scrollLeft:be}=A.currentTarget;nl(W,n,{top:K,left:be})},ha=A=>{if(r){r(Pr,zr);return}M&&d(Pr,zr,A.currentTarget)},Bn=()=>{if(!(R.kind==="loading"||R.kind==="error"))return te.start()};return e.jsxs("div",{ref:_,tabIndex:-1,onKeyDown:da,onFocusCapture:()=>{s&&ye&&vt.trim()&&Yi(z,je,I.current)},onPointerDownCapture:A=>{A.target instanceof Element&&!A.target.closest('button, input, textarea, select, a, [tabindex]:not([tabindex="-1"])')&&A.currentTarget.focus({preventScroll:!0})},className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Nr.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${p&&(tn||Tt)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[p&&g&&e.jsx("button",{type:"button",onClick:g,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":o("rightSidebar.backToFileList"),title:o("rightSidebar.backToFileList"),children:e.jsx(sf,{size:16})}),Le.length>0&&e.jsxs("button",{type:"button",onClick:_n,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${p?"w-9":"px-2.5"}`,"aria-label":o("rightSidebar.backToPreviousPreview"),title:o("rightSidebar.backToPreviousPreview"),children:[e.jsx(na,{size:15}),!p&&e.jsx("span",{className:"text-[11px] font-medium",children:o("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Xe,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Mr.name}),Mr.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Mr.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[gt&&e.jsx("button",{type:"button",onClick:ye?Zr:Cr,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 ${ye?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":o("rightSidebar.findInFile"),title:`${o("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(ms,{size:14})}),Lr&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{x&&E?.(),Fe(A=>{const K=A==="preview"?"source":"preview";return Lt(Rf,K),K}),C(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:p?fe==="preview"?e.jsx(bl,{size:14}):e.jsx(gl,{size:14}):o(fe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),wt&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{G(A=>{const K=A==="preview"?"source":"preview";return Jg(W,n,K),K}),C(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${p?"w-9 px-0":"px-3"}`,"aria-label":o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:p?Oe==="preview"?e.jsx(bl,{size:14}):e.jsx(gl,{size:14}):o(Oe==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Tt&&e.jsx("button",{type:"button",onClick:()=>{Ce.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":o(Se?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:o(Se?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(af,{size:15})}),!p&&e.jsx("button",{type:"button",onClick:A=>l(Xe,Ar,A.currentTarget),...Nr(zt,Ar),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${rn||nn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:o("rightSidebar.insertReference",{reference:zt}),children:o(nn?"rightSidebar.copied":rn?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(zt)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:o("rightSidebar.copyReference",{reference:zt}),"aria-label":o("rightSidebar.copyFileRef"),children:e.jsx(Jm,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{Bn()},disabled:te.status==="pending"||R.kind==="loading"||R.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:te.status==="error"?te.error??o("rightSidebar.downloadFailed"):o("rightSidebar.downloadFile"),"aria-label":o("rightSidebar.downloadFile"),children:te.status==="pending"?e.jsx(dt,{size:13,className:"animate-spin"}):e.jsx(tf,{size:14})}),te.status==="pending"&&e.jsx("button",{type:"button",onClick:te.cancel,className:"inline-flex h-9 shrink-0 items-center rounded-full bg-surface-2 px-2 text-xs text-foreground hover:bg-surface-elevated",children:o("common.cancel")})]})]}),te.status==="error"&&e.jsxs("div",{role:"alert",className:"mt-2 text-xs text-destructive",children:[o("rightSidebar.downloadFailed"),": ",te.error]}),te.status==="canceled"&&e.jsx("div",{role:"status",className:"mt-2 text-xs text-muted-foreground",children:o("rightSidebar.downloadCanceled")}),ye&&gt&&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(ms,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:At,type:"search",value:vt,onChange:A=>er(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),Er(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:o("rightSidebar.findInFilePlaceholder"),"aria-label":o("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:z.length>0?`${je+1}/${z.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Er(-1),disabled:z.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":o("rightSidebar.previousSearchMatch"),title:`${o("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Al,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Er(1),disabled:z.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":o("rightSidebar.nextSearchMatch"),title:`${o("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(kp,{size:13})}),e.jsx("button",{type:"button",onClick:Zr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.closeFileSearch"),title:`${o("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Pt,{size:13})})]}),$r&&!(p&&(tn||Tt))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[$r.size!==null&&e.jsx("span",{children:o("rightSidebar.byteCount",{count:$r.size.toLocaleString()})}),"truncated"in $r&&$r.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:o("rightSidebar.previewTruncated")}),"mimeType"in $r&&e.jsx("span",{children:$r.mimeType}),"dimensions"in R&&R.dimensions&&e.jsxs("span",{children:[R.dimensions.width," × ",R.dimensions.height]})]}),!(p&&(tn||Tt))&&!bs&&R.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:vs?o("rightSidebar.edaPickHint"):ua?o("rightSidebar.csvTablePreview"):en||Tn?o("rightSidebar.kicadProjectPickHint"):xs?o("rightSidebar.videoPreviewHint"):gs?o("rightSidebar.imagePreviewHint"):tn?M?o("rightSidebar.selectedLineHint",{lineLabel:Gt??""}):o("rightSidebar.markdownPreviewHint"):Tt?o("rightSidebar.htmlPreviewHint"):M?o("rightSidebar.selectedLineHint",{lineLabel:Gt??""}):o("rightSidebar.multiLineHint")})})]}),!s&&(R.kind==="video"||R.kind==="model3d"||R.kind==="eda"||Tt)?null:R.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8",children:e.jsx(Ui,{label:R.mode==="eda"?o("rightSidebar.edaLoading"):R.mode==="image"?o("rightSidebar.loadingImage"):R.mode==="model3d"?o("rightSidebar.model3dLoading"):R.mode==="video"?o("rightSidebar.loadingVideo"):o("common.loading")})}):R.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:R.message}),e.jsx("button",{type:"button",onClick:Qr,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:o("common.retry")})]}):R.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:o("rightSidebar.binaryPreviewHint")})}):R.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:R.meta.mimeType==="image/svg+xml"?e.jsx(yf,{blobUrl:R.objectUrl,filePath:Xe,viewLabel:"SVG 文件",onInsertAnnotation:c}):e.jsx(Sh,{src:R.objectUrl,alt:Mr.name,vector:!1,onLoad:A=>{const K=A.currentTarget;H(be=>be.kind==="image"?{...be,dimensions:{width:K.naturalWidth,height:K.naturalHeight}}:be)},onError:()=>H({kind:"error",message:o("rightSidebar.imageLoadFailed")})})}):R.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(lb,{url:R.url,onLoadError:()=>H({kind:"error",message:o("rightSidebar.videoLoadFailed")})})}):R.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(pb,{blobUrl:R.objectUrl,filePath:R.sourcePath,view:R.view,board:Xe.toLowerCase().endsWith(".kicad_pcb"),onViewChange:L,onInsertAnnotation:r??c,onRefresh:Qr,interactive3d:U?e.jsx(a.Suspense,{fallback:e.jsx(Ui,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Eu,{blobUrl:U.objectUrl,ext:".glb",fileName:Mr.name,filePath:U.sourcePath,features:null,onInsertFeature:r??c,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:R.view==="pcb-3d"})}):void 0})}):R.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(Ui,{label:o("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Eu,{blobUrl:R.objectUrl,ext:R.ext,fileName:Mr.name,filePath:R.sourcePath,features:he,onInsertFeature:r??c,onRefresh:Qr})})}):R.kind==="text"&&ua?e.jsx(xb,{content:R.content,filePath:Xe,onInsertAnnotation:r??c},Xe):R.kind==="text"&&(en||Tn)?e.jsx(wb,{content:R.content,filePath:Xe,localState:Tn,onInsertAnnotation:r??c},Xe):tn?e.jsxs("div",{ref:$e,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:Fn,style:{touchAction:"pan-x pan-y"},children:[e.jsx(hh,{content:R.content,filePath:R.sourcePath,rootPath:W,lineRange:M,onLineRangeClick:nr,onLineRangeDrag:sn,scrollTop:me,outlineOpen:x,outlineCloseSignal:h,onOutlineOpen:b,onOutlineClose:E,lightboxOpen:S,lightboxCloseSignal:T,onLightboxOpen:D,onLightboxClose:F,onLocalLinkOpen:ys}),M&&Q&&e.jsxs("button",{type:"button",onClick:ha,...Nr(Pr,zr),style:{top:Q.top,left:Q.left,transform:"translateY(-50%)"},className:ou(p,Dn),title:`Insert markdown reference: ${ur}`,children:[e.jsx(jo,{size:p?13:11}),In?o("rightSidebar.copied"):fr?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:Gt??""})]})]}):Tt?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Mb,{ref:Ce,src:Qm(Xe),title:`${Mr.name} preview`,exitFullscreenLabel:o("rightSidebar.htmlFullscreenExit"),onFullscreenChange:de},`${Xe}:${dr}:${Pn}`)}):R.kind==="text"?e.jsxs("div",{ref:$e,onScroll:It,className:`${Dl} 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:[Hr.length>0?e.jsx("div",{className:"min-w-full",children:Hr.map((A,K)=>{const be=K+1,ke=!!(M&&be>=M.start&&be<=M.end),We=_e&&_e.length===Hr.length?_e[K]:null;return e.jsxs("div",{ref:Ue=>{Ue?Ne.current.set(be,Ue):Ne.current.delete(be)},role:"button","data-file-preview-line":be,tabIndex:0,onClick:Ue=>we(Ue,be),onKeyDown:Ue=>{Ue.key!=="Enter"&&Ue.key!==" "||(Ue.preventDefault(),we(Ue,be))},style:{gridTemplateColumns:`${Wt}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 ${zt}:${be}`,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:be}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:We??(A||" ")})]},K)})}):"Empty file.",M&&Q&&e.jsxs("button",{type:"button",onClick:ha,...Nr(Pr,zr),style:{top:Q.top,left:Q.left,transform:"translateY(-50%)"},className:ou(p,Dn),title:`Insert code reference: ${ur}`,children:[e.jsx(jo,{size:p?13:11}),In?o("rightSidebar.copied"):fr?o("rightSidebar.inserted"):o("rightSidebar.insertLineRef",{lineLabel:Gt??""})]})]}):null]})}function p0({rootPath:r,file:n,active:s,...l}){const[d,c]=a.useState(null),[m,g]=a.useState(n.line??1),f=a.useCallback(()=>g(null),[]);return e.jsx("div",{"data-architecture-source":!0,className:"h-full min-h-0",children:e.jsx(Ao,{...l,filePath:`${r.replace(/\/+$/,"")}/${n.path}`,active:s,lineRange:d,onLineRangeChange:c,scrollToLine:m,onScrollToLineHandled:f,markdownOutlineOpen:!1,markdownImageLightboxOpen:!1})})}function g0({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:d,push:c,pinned:m=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:f=!1,rightSidebarFilePreviewCloseSignal:p,onOpenRightSidebarFilePreview:x,onCloseRightSidebarFilePreview:h,rightSidebarRepoPickerOpen:b=!1,rightSidebarRepoPickerCloseSignal:E,onOpenRightSidebarRepoPicker:S,onCloseRightSidebarRepoPicker:T,markdownOutlineOpen:D=!1,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:C,markdownImageLightboxOpen:P=!1,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j}){const{t:o,locale:_}=ft(),[I,V]=a.useState(""),[W,O]=a.useState(null),R=J(t=>t.rightSearchOpen),H=J(t=>t.setRightSearchOpen),ee=J(t=>t.rightSidebarLayoutPreference),L=J(t=>t.setRightSidebarLayoutPreference),[U,X]=a.useState(()=>lx()),[ce,he]=a.useState("."),[Re,Ne]=a.useState(""),[$e,Q]=a.useState(!1),[xe,fe]=a.useState(!1),[Fe,Oe]=a.useState(!1),[G,Ce]=a.useState(!1),Se=a.useDeferredValue(I),[de,qe]=a.useState(null),[$,me]=a.useState([]),[ge,Le]=a.useState([]),ne=J(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Ye=J(t=>t.setActiveGitRepo),[Je,De]=a.useState(null),[Te,_e]=a.useState(null),[Be,te]=a.useState(null),[ye,nt]=a.useState(()=>pt(Su,Qs)??!1),[vt,er]=a.useState(()=>pt(ju,Qs)??!1),[z,oe]=a.useState(()=>pt(Ru,Qs)??!1),[je,Qe]=a.useState(()=>pt(Qi,nx)??""),[At,Nr]=a.useState(0),[tr,yt]=a.useState(!1),[dr,rr]=a.useState(!1),Ln=a.useRef(null),Pn=a.useRef(null),[Fo,Qr]=a.useState(!1),[An,gt]=a.useState(null),[Zr,Cr]=a.useState(null),[Er,da]=a.useState(()=>$u(Xi)),[Xe,Mr]=a.useState(()=>$u(ku)),[zt,Hr]=a.useState(()=>rx()),[Wt,$r]=a.useState(()=>sx()),[Lr,ua]=a.useState(()=>ox()),en="words",[Tn,tn]=a.useState(0),[wt,Tt]=a.useState([]),[gs,bs]=a.useState([]),[xs,vs]=a.useState(!1),[fa,ur]=a.useState(null),[Pr,Ar]=a.useState([]),[zr,rn]=a.useState(!1),[fr,nn]=a.useState([]),[In,Dn]=a.useState([]),[Gt,Kt]=a.useState(!1),[we,nr]=a.useState(null),[sn,Fn]=a.useState([]),[ys,_n]=a.useState({}),It=a.useRef(0),[ha,Bn]=a.useState(0),[A,K]=a.useState(!1),[be,ke]=a.useState(null),[We,Ue]=a.useState(null),[tt,Ge]=a.useState(null),[ht,bt]=a.useState(null),[hr,Tr]=a.useState(!1),[On,an]=a.useState(""),ws=a.useDeferredValue(On),[mr,ks]=a.useState({}),[on,Wr]=a.useState([]),[re,Ke]=a.useState(!1),[qt,Ir]=a.useState(!1),[_o,Un]=a.useState(null),[Bo,Hn]=a.useState(!1),pr=a.useRef(null),Gr=a.useRef(0),ql=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[jh,ma]=a.useState(null),[Ss,Vl]=a.useState(()=>pt(Ji,Qs)??!1),[Oo,Uo]=a.useState(!1),[pa,Ho]=a.useState([]),[sr,ga]=a.useState({}),[Ct,ba]=a.useState({}),[ln,zo]=a.useState({}),[Yl,Xl]=a.useState(()=>new Set),[Ze,cn]=a.useState(null),[Wo,dn]=a.useState(null),[Rh,Dr]=a.useState(!1),[Go,Fr]=a.useState(0),[,Ko]=a.useState(0),[qo,xa]=a.useState(!1),[Nh,Ch]=a.useState(()=>J.getState().rightTab==="files"),[ar,Vo]=a.useState(!1),[Eh,Jl]=a.useState(()=>J.getState().rightTab==="diff"),[Yo,Ql]=a.useState(()=>J.getState().rightTab==="android"),[Kr,Zl]=a.useState(!1),[gr,ec]=a.useState({architecture:!0,computer:!0}),Xo=a.useRef(new Set),va=Hi(t=>t.docks[Wi]),Mh=!!va,[ze,js]=a.useState(null),[zn,Rs]=a.useState(null),[kt,un]=a.useState(null),[tc,Vt]=a.useState(null),[Wn,rc]=a.useState(null),[Jo,$h]=a.useState(()=>Date.now()),[Lh,Ph]=a.useState(!1),[fn,ya]=a.useState(!1),[wa,nc]=a.useState(""),[Gn,ka]=a.useState(""),[hn,Sa]=a.useState(""),[mn,ja]=a.useState(""),[sc,Kn]=a.useState(null),[ac,Qo]=a.useState(!1),[oc,ic]=a.useState(!1),[Ra,Ah]=a.useState({key:null,nonce:0}),lc=a.useRef(null),cc=a.useRef(null),se=dp(s,m,ee),Zo=If(se,m,Lr),[ei,ti]=a.useState(()=>px(s)),ri=J(t=>t.rightTab),Dt=J(t=>t.setRightTab),v=J(t=>t.rootPath),qn=J(t=>t.explorerRoot),dc=J(t=>t.pinnedExplorerRootsCache),uc=J(t=>t.hydratePinnedExplorerRoots),fc=J(t=>t.syncPinnedExplorerRoots),Ft=J(t=>t.setExplorerRoot),hc=J(t=>t.resetExplorerToProject),Vn=J(t=>t.pinExplorerRoot),pn=J(t=>t.unpinExplorerRoot),at=J(t=>t.selectedFilePath),ot=J(t=>t.selectFile),ni=J(t=>t.showHiddenFiles),Th=J(t=>t.toggleShowHiddenFiles),si=J(t=>!!(v&&t.nestedGitScanRoots[v])),Ie=J(t=>t.changedFiles),Na=J(t=>t.setChangedFiles),Ns=J(t=>t.invalidateDirectoryCache),Ih=J(t=>t.setDirectorySortMode),mc=J(t=>t.applyFileWatchEvents),pc=J(t=>t.reconcileDirectoryCache),gc=J(t=>t.bumpFileWatchEpoch),br=J(t=>t.gitBundleLoading),bc=J(t=>t.gitBundleSlow),gn=J(t=>t.gitBundleError),Yn=J(t=>t.gitBundleLastLoadedAt),xc=J(t=>t.beginGitBundleLoading),vc=J(t=>t.setGitBundleSlowFor),ai=J(t=>t.finishGitBundleLoading),Ca=J(t=>t.resetGitBundleLoading),oi=J(t=>t.setGitBundleError),yc=J(t=>t.markGitBundleLoaded),ie=qn??v,Ea=J(t=>!!(ie&&t.hideGitIgnoredRoots[ie])),Dh=J(t=>t.hideGitIgnoredRootsHydrated),Fh=J(t=>t.setHideGitIgnoredRoot),[ii,wc]=a.useState(!1),[kc,li]=a.useState(null);a.useEffect(()=>{li(null)},[ie]);const Sc=a.useMemo(()=>ie?Ib(ie,ce):"",[ie,ce]),Cs=a.useMemo(()=>Tb(Re),[Re]),jc=a.useMemo(()=>({excludePatterns:Cs,caseSensitive:xe,wholeWord:Fe,regex:G}),[xe,Cs,G,Fe]),Ma=J(t=>ie?t.fileSortModes[ie]??"name":"name"),Rc=J(t=>!!(ie&&t.directoryCache.has(ie))),Xn=a.useRef(null),Rt=a.useRef(0),[Nc]=a.useState(()=>++c0),_r=a.useRef(null),qr=a.useRef(null),$a=a.useRef(0),Yt=a.useRef(new Map),Xt=a.useRef(new Map),xr=a.useRef(new Set),bn=a.useRef(new Set),xn=a.useRef(0),Vr=a.useRef(null),Jn=a.useRef(0),Qn=a.useRef(null),Zn=a.useRef(0),Yr=a.useRef(null),ci=a.useRef(new Set),di=a.useRef(null),ui=a.useRef(null),La=a.useRef(null),fi=a.useRef(null),hi=a.useRef(null),Es=a.useRef(new Set);a.useEffect(()=>{if(Wn===null)return;const t=Math.max(0,Date.now()-Wn),i=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,u=Math.max(50,i-t%i),w=window.setTimeout(()=>$h(Date.now()),u);return()=>window.clearTimeout(w)},[Jo,Wn]);const Pa=a.useRef(null),Br=a.useRef(null),mi=a.useRef(null),Cc=a.useRef(null),Ms=a.useRef(null),Me=a.useCallback(t=>J.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=i=>{const u=h0(i.target);u&&Ys("global_change_row_event",{...m0(i),selectionPath:u.dataset.diffSelectionPath,filePath:u.dataset.diffFilePath,absolutePath:u.dataset.diffAbsolutePath,repoRoot:u.dataset.diffRepoRoot,status:u.dataset.diffStatus,selectedFilePath:J.getState().selectedFilePath,rightTab:J.getState().rightTab,activeGitRepoRoot:ne,changedFiles:J.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[ne,r]);const Ec=a.useCallback(async(t=v??void 0)=>{if(!t)return null;if(xr.current.has(t)||bn.current.has(t))return ct("untracked_skip_cached",{cwd:t,rootPath:v,completed:xr.current.has(t),running:bn.current.has(t)}),null;const i=v,u=$a.current+1;$a.current=u,Yt.current.set(t,u);const w=`right-sidebar-git-untracked:${t}`,y=new AbortController;Xt.current.set(t,y),bn.current.add(t),ct("untracked_start",{requestId:u,cwd:t,rootPath:v});try{let k=await Ud(t,y.signal,w),N=0;for(;k.status==="running"&&N<120;){if(Yt.current.get(t)!==u||y.signal.aborted)return ct("untracked_stale_result",{requestId:u,activeRequestId:Yt.current.get(t),cwd:t,status:k.status}),null;if(!Me(i))return ct("untracked_root_changed",{requestId:u,cwd:t,expectedRootPath:i,currentRootPath:J.getState().rootPath}),null;await new Promise(ae=>window.setTimeout(ae,N<10?1e3:3e3)),N+=1,k=await Ud(t,y.signal,w)}if(Yt.current.get(t)!==u||!Me(i))return ct("untracked_stale_result",{requestId:u,activeRequestId:Yt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:J.getState().rootPath,files:k.files.length,status:k.status}),null;if(k.status==="done")return Na(bh(J.getState().changedFiles,k.files)),k.files.length>0&&me(ae=>{const Pe=new Map(ae.map(pe=>[pe.root,pe])).get(t);if(!Pe)return ae;const et=Jx(Pe.files,k.files),Z=ae.map(pe=>pe.root===t?{...pe,files:et,context:pe.context?{...pe.context,changedFiles:et.map(Ae=>({path:Ae.path,absolutePath:Ae.absolutePath,status:Ae.status})),truncated:!1}:pe.context,untrackedDeferred:!1}:pe);Le(xh(Z,v));const Y=Z.find(pe=>pe.root===v);return Y?.context&&qe(pe=>pe?.root===Y.root?{...pe,...Y.context}:pe),Z}),xr.current.add(t),ct("untracked_apply",{requestId:u,cwd:t,files:k.files.length}),k;const le=k.error||(k.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return xr.current.add(t),ct("untracked_error",{requestId:u,cwd:t,message:le,code:k.code,status:k.status}),null}catch(k){if(Yt.current.get(t)!==u||!Me(i)||jr(k))return ct("untracked_aborted",{requestId:u,activeRequestId:Yt.current.get(t),cwd:t,expectedRootPath:i,currentRootPath:J.getState().rootPath,message:k instanceof Error?k.message:String(k)}),null;const N=k instanceof Error?k.message:"Failed to scan untracked files";return xr.current.add(t),ct("untracked_error",{requestId:u,cwd:t,message:N}),null}finally{Xt.current.get(t)===y&&Xt.current.delete(t),Yt.current.get(t)===u&&Yt.current.delete(t),bn.current.delete(t)}},[de,Me,v,Na]),or=a.useMemo(()=>{const t=new Set(ge.map(u=>u.root)),i=Pr.filter(u=>t.has(u));return i.length>0?i:ne?[ne]:[]},[ne,Pr,ge]),Mc=or.length===0,vn=a.useMemo(()=>or.map(t=>$.find(i=>i.root===t)).filter(t=>!!t),[or,$]),_h=a.useMemo(()=>ge.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[ge]),vr=a.useCallback(async()=>{if(!v){Tt([]),bs([]);return}const t=v,i=Jn.current+1;Jn.current=i,Qn.current?.abort();const u=new AbortController;Qn.current=u,vs(wt.length===0),ur(null);try{const w=or.length>0?await Promise.all(or.map(y=>Hd({workspaceRoot:v,repoRoot:y},u.signal))).then(y=>({records:y.flatMap(k=>k.records),walkthroughs:y.flatMap(k=>k.walkthroughs??[])})):await Hd({workspaceRoot:v},u.signal);if(Jn.current!==i||!Me(t))return;Tt(w.records),bs(w.walkthroughs??[])}catch(w){if(Jn.current!==i||!Me(t)||jr(w))return;ur(w instanceof Error?w.message:"Failed to load change audit explanations")}finally{Qn.current===u&&(Qn.current=null),Jn.current===i&&Me(t)&&vs(!1)}},[wt.length,or,Me,v]),Aa=a.useCallback(async(t,i,u)=>{if(!t&&!v){nn([]),Dn([]);return}const w=v,y=Zn.current+1;Zn.current=y,Yr.current?.abort();const k=new AbortController;Yr.current=k;try{const N=t?[t]:Array.from(new Set([v,...$.map(ae=>ae.root)].filter(ae=>!!ae))),le=await Promise.all(N.map(ae=>ep({repoRoot:ae,baseRef:i,branchName:u},k.signal))).then(ae=>{const ve=new Map,Pe=new Map;for(const et of ae){for(const Z of et.records)ve.set(Z.id,Z);for(const Z of et.walkthroughs??[])Pe.set(Z.id,Z)}return{records:Array.from(ve.values()),walkthroughs:Array.from(Pe.values())}});if(Zn.current!==y||!Me(w))return;nn(le.records),Dn(le.walkthroughs??[])}catch(N){if(Zn.current!==y||!Me(w)||jr(N))return;console.warn("[RightSidebar] Failed to load branch explanations",N)}finally{Yr.current===k&&(Yr.current=null)}},[$,Me,v]),es=a.useCallback((t,i={})=>{if(!Me(v)){ct("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:J.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}ct(t.files.length===0?"empty_bundle":"apply",{rootPath:v,available:t.available,files:t.files.length,repositories:t.repositories?.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length,available:Y.available,error:Y.error})),repoFilters:t.repoFilters?.map(Y=>({root:Y.root,label:Y.label,count:Y.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let u=Df(t),w=t.repoFilters??[],y=t.files;const k=J.getState().changedFiles;if(!!(i.cacheOnly&&!t.cached&&t.files.length===0&&u.length===0)&&(k.size>0||$.length>0||de)){ct("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:k.size,currentRepositories:$.length});return}const le=u.some(Y=>Y.deferred);if(le&&!i.replaceWorkspace){const Y=new Set(u.filter(Ae=>!Ae.deferred||Ae.root===v).map(Ae=>Ae.root));y=[...Array.from(k.values()).filter(Ae=>!Y.has(xt(Ae,v)??"")),...t.files]}const ae=Uu(k.values(),v),ve=Uu(t.files,v),Pe=u.some(Y=>Y.root!==v);if(!!(i.background&&!le&&!i.replaceWorkspace&&k.size>0&&(t.files.length===0&&!t.error||ae>0&&ve===0&&!Pe))){ct("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:k.size,nextFiles:t.files.length,currentNestedCount:ae,nextNestedCount:ve,nextRepositories:u.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(i.replaceRepoRoot){const Y=vh(k.values(),$,t,i.replaceRepoRoot,v);y=Y.files,u=Y.repositories,w=Y.repoFilters}if(Na(gh(y)),me(Y=>{if(!le||i.replaceWorkspace)return u;const pe=new Map(Y.map(Ae=>[Ae.root,Ae]));return u.map(Ae=>{const Ve=pe.get(Ae.root);return!Ae.deferred||!Ve?Ae:{...Ae,available:Ve.available,files:Ve.files,context:Ve.context,deferred:Ve.deferred,untrackedDeferred:Ve.untrackedDeferred,error:Ve.error}})}),Le(w),hi.current=v,i.syncActiveRepo!==!1){const{contextKey:Y,activeGitRepos:pe}=J.getState(),Ae=Y?pe[Y]??null:null,Ve=i.activeRepoRoot!==void 0?i.activeRepoRoot:Ae,He=cx({...t,repositories:u,repoFilters:w},Ve);Ye(He)}typeof t.cacheUpdatedAt=="number"&&rc(t.cacheUpdatedAt),qe(Y=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==v)return Y;if(!t.context)return null;const pe=Y?.root??v;return!Y?.available||pe!==(t.context.root??v)?t.context:{...Y,...t.context}}),i.reloadDiff&&tn(Y=>Y+1);const Z=J.getState().selectedFilePath;if(Z&&!Z.startsWith("/")&&!y.some(Y=>Y.path===Z||Y.absolutePath===Z)&&ot(null),da(Y=>{const pe=new Set(y.map(Ve=>xt(Ve,v)).filter(Boolean)),Ae=new Set;for(const Ve of Y)pe.has(Ve)&&Ae.add(Ve);return el(Xi,Ae),Ae}),i.loadDeferred!==!1){const Y=u.filter(pe=>pe.untrackedDeferred&&pe.root).map(pe=>pe.root);for(const pe of Y)Ec(pe)}i.loadAudit!==!1&&vr()},[Me,vr,Ec,v,ot,Ye,Na]);a.useEffect(()=>{Ca(),di.current=null,ui.current=v;const t=[],i=[];Rt.current+=1,xn.current+=1,$a.current+=1,_r.current?.abort(),Nt(qs(qr.current?.cwd??v??void 0)),qr.current=null,_r.current=null,Vr.current?.abort(),Nt("right-sidebar-git-details"),Vr.current=null;for(const N of Xt.current.values())N.abort();for(const N of Xt.current.keys())Nt(`right-sidebar-git-untracked:${N}`);Xt.current.clear(),Yt.current.clear(),Jn.current+=1,Qn.current?.abort(),Qn.current=null,Zn.current+=1,Yr.current?.abort(),Yr.current=null,Gr.current+=1,pr.current?.abort(),Nt("right-sidebar-recent-commits"),pr.current=null,Tt([]),bs([]),vs(!1),ur(null),Ar([]),rn(!1),nn([]),Dn([]),Kt(!1),nr(null),K(!1),ke(null),Ue(null),Ge(null),bt(null),Tr(!1),an(""),Wr([]),Ke(!1),Ir(!1),Un(null),Hn(!1),ma(null),cn(null),dn(null),Vl(!1),Lt(Ji,!1),Uo(!1);const u=v?Lu()[v]:null,w=u?.previewEntries??[],y=u?.selectedPreviewKey??null,k=y?w.find(N=>N.key===y)??null:null;++It.current,K(!1),Ho(u?.selectedRepoRoots??[]),ga(u?.repoTargetBranches??{}),ba(u?.repoBaseBranches??{}),Fn(w),_n(u?.previewScrollTops??{}),k&&u?.previewDetailOpen&&(k.diff.hunks?.length??0)>0&&(nr(k.diff),cn(k.key),dn(u.selectedPreviewFileKey??(k.diff.hunks?.[0]?`${k.diff.hunks[0].filePath}\0${k.diff.hunks[0].hunkHeader}\0${k.diff.hunks[0].hunkIndex}`:null)),Kt(!0)),zo(u?.repoIncludeUncommitted??Object.fromEntries(Object.keys(u?.repoTargetBranches??{}).map(N=>[N,u?.includeUncommitted??!0]))),di.current=v,ya(!1),xr.current.clear(),bn.current.clear(),js(null),Rs(null),un(null),Vt(null),rc(null),me(t),Le(i),qe(null),fi.current=null,hi.current=null,Es.current.clear()},[Ca,v]);const _t=a.useCallback(async(t=v??void 0,i={})=>{if(!t)return null;const u=v,w=Rt.current;if(await hg(()=>Promise.all([J.getState().hydrateNestedGitScanRoots(),J.getState().hydrateActiveGitRepos()]).then(()=>{})),Rt.current!==w||!Me(u))return null;const y=t===v&&Gs(v),k=i.includeNested??y,N=i.refresh??i.reloadDiff??!1,le=i.cacheOnly??!1,ae=i.background??!1,ve=k&&(i.discoverOnly??!1);N&&xr.current.clear();const Pe=qr.current;if(Pe&&Pe.cwd===t&&Pe.includeNested===k&&Pe.refresh===N&&Pe.cacheOnly===le&&Pe.discoverOnly===ve)return ct("reuse_pending",{cwd:t,includeNested:k,refresh:N,cacheOnly:le,discoverOnly:ve}),Pe.promise;const et=Rt.current+1;Rt.current=et;const Z=`right-sidebar:${Nc}:${et}`;_r.current?.abort();const Y=qs(t);Nt(Y);const pe=new AbortController;_r.current=pe;let Ae=null;ae||xc(Z),oi(null),ct("start",{requestId:et,cwd:t,rootPath:v,requestSlotId:Y,includeNested:k,refresh:N,cacheOnly:le,background:ae,existingChanges:Ie.size,lastLoadedAt:Yn}),!ae&&typeof window<"u"&&(Ae=window.setTimeout(()=>{Rt.current===et&&vc(Z,!0)},Wb));const Ve=(async()=>{const He=await zi(t,pe.signal,{includeNested:k,refresh:N,cacheOnly:le,discoverOnly:ve,action:N?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Y,requestTimeoutMs:N?null:void 0});if(e0(He)){if(ct("cancelled_result_ignored",{requestId:et,activeRequestId:Rt.current,cwd:t,error:He.error??He.context?.error}),pe.signal.aborted)return null;throw new Error(He.error??He.context?.error??"Failed to load Git changes")}return Rt.current!==et||!Me(u)?(ct("stale_result",{requestId:et,activeRequestId:Rt.current,cwd:t,expectedRootPath:u,currentRootPath:J.getState().rootPath,files:He.files.length,repositories:He.repositories?.length??0}),null):(es(He,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:k,background:ae,cacheOnly:le,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),He)})();qr.current={cwd:t,includeNested:k,refresh:N,cacheOnly:le,discoverOnly:ve,promise:Ve};try{const He=await Ve;return Rt.current===et&&He&&Me(u)?yc({cached:He.cached,stale:He.stale,cacheAgeMs:He.cacheAgeMs,nestedDeferred:!k||He.nestedDeferred,untrackedDeferred:He.untrackedDeferred}):Rt.current===et&&Me(u)&&ai(Z),He}catch(He){return Rt.current!==et||!Me(u)||pe.signal.aborted?(ct("aborted",{requestId:et,activeRequestId:Rt.current,cwd:t,expectedRootPath:u,currentRootPath:J.getState().rootPath,message:He instanceof Error?He.message:String(He)}),null):(ct("error",{requestId:et,cwd:t,includeNested:k,refresh:N,background:ae,message:He instanceof Error?He.message:String(He)}),ae||(qe(null),oi(He instanceof Error?He.message:"Failed to load Git changes")),null)}finally{Ae!==null&&window.clearTimeout(Ae),_r.current===pe&&(_r.current=null),qr.current?.promise===Ve&&(qr.current=null),!ae&&Rt.current===et&&Me(u)&&ai(Z)}},[es,xc,Ie.size,ai,Nc,Yn,Me,yc,v,oi,vc]),ts=a.useCallback(async()=>{v&&await _t(v,{reloadDiff:!0,refresh:!0})},[_t,v]),pi=a.useCallback(async(t=v??void 0)=>{if(!t)return null;const i=v,u=xn.current+1;xn.current=u,Vr.current?.abort(),Nt("right-sidebar-git-details");const w=new AbortController;Vr.current=w,ya(!0);try{const y=await zd(t,w.signal,"load_git_details","right-sidebar-git-details");return xn.current!==u||!Me(i)?null:(me(k=>k.map(N=>N.root===y.root?{...N,available:y.available,context:y,error:y.error}:N)),qe(k=>k?.root&&y.root&&k.root!==y.root?k:!k?.available||!y.available?y:{...k,...y}),y)}catch(y){return jr(y)||!Me(i)||xn.current===u&&Vt(y instanceof Error?y.message:"Failed to load Git details"),null}finally{Vr.current===w&&(Vr.current=null),xn.current===u&&Me(i)&&ya(!1)}},[Me,v]);a.useEffect(()=>{if(!r){Rt.current+=1,Ca(),fi.current=null,xn.current+=1,$a.current+=1,_r.current?.abort(),Nt(qs(qr.current?.cwd??v??void 0)),qr.current=null,_r.current=null,Vr.current?.abort(),Nt("right-sidebar-git-details"),Vr.current=null;for(const t of Xt.current.values())t.abort();for(const t of Xt.current.keys())Nt(`right-sidebar-git-untracked:${t}`);Xt.current.clear(),Yt.current.clear(),Zn.current+=1,Yr.current?.abort(),Yr.current=null,Gr.current+=1,pr.current?.abort(),Nt("right-sidebar-recent-commits"),pr.current=null,ya(!1),K(!1),ke(null),Ue(null),Ge(null),bt(null),Tr(!1),an(""),Wr([]),Ke(!1),Ir(!1),Un(null),Hn(!1),V(""),H(!1),gt(null),Vo(!1),se&&Jl(!1)}},[se,r,Ca,H]),a.useEffect(()=>{if(!R)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[R]),a.useEffect(()=>{se||Dr(!1)},[se]);const $c=a.useCallback(t=>{Ko(t);const i=mi.current;i&&(i.update(),i.slideTo(t,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(t,0)}))},[]);a.useEffect(()=>{if(se)if(Dr(f),f&&at){Fr(1);const t=Br.current;t&&(t.update(),t.activeIndex!==1&&(Ms.current=1,t.slideTo(1,0)))}else{Fr(0);const t=Br.current;t&&t.activeIndex!==0&&(Ms.current=0,t.slideTo(0,0)),gt(null)}},[se,f,v,at]),a.useEffect(()=>{if(p!==void 0&&!f){Fr(0);const t=Br.current;t&&t.activeIndex!==0&&(Ms.current=0,t.slideTo(0,0)),Dr(!1),gt(null)}},[p,f]),a.useEffect(()=>{E!==void 0&&De(null)},[E]),a.useEffect(()=>{!se&&f&&h?.()},[se,h,f]),a.useEffect(()=>{ti(t=>Rl(t,s))},[s]);const Bh=a.useCallback(t=>{se||(t.preventDefault(),Pa.current={startX:t.clientX,startWidth:ei,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[ei,se]),Oh=a.useCallback(t=>{const i=Pa.current;if(!i||i.pointerId!==t.pointerId)return;const u=Rl(i.startWidth+t.clientX-i.startX,s);ti(u),Zs(Js,u,zb)},[s]),Lc=a.useCallback(t=>{const i=Pa.current;if(!(!i||i.pointerId!==t.pointerId)){Pa.current=null,Ws(Js);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),rs=!!(v&&Yn!==null&&Wu(de)),gi=!!(v&&!gn&&Ie.size===0&&Yn===null),Et=(()=>{let t=ri;return t==="android"&&!Kr&&(t="files"),(t==="architecture"||t==="computer")&&!gr[t]&&(t="files"),rs&&(t==="git"||t==="diff")&&(t="files"),t})(),lt=Et==="git",Or=Et==="files",Mt=Et==="diff",ns=Et==="android",bi=Et==="computer",yn=Et==="architecture",[Uh,Hh]=a.useState(!1);a.useEffect(()=>{r&&yn&&Hh(!0)},[r,yn]);const xi=a.useRef(null),ss=a.useCallback((t,i)=>{const u=J.getState().rightTab;if(u===t)return;const w=performance.now(),y=w-i.timeStamp;xi.current={from:u,to:t,startedAt:w,inputDelayMs:y>=0&&y<6e4?Math.round(y):null},Dt(t)},[Dt]);a.useEffect(()=>{const t=xi.current;if(!t||t.to!==Et)return;xi.current=null;const i=Math.round(performance.now()-t.startedAt);let u=window.requestAnimationFrame(()=>{u=window.requestAnimationFrame(()=>{Ys("tab_switch_presented",{from:t.from,to:t.to,inputDelayMs:t.inputDelayMs,commitMs:i,frameMs:Math.round(performance.now()-t.startedAt)})})});return()=>window.cancelAnimationFrame(u)},[Et]);const zh=Sp(t=>t.overlay==="sidebar")&&ns;a.useEffect(()=>{if(!se){xa(!0);return}if(!r){const i=window.setTimeout(()=>{xa(!1)},qb);return()=>window.clearTimeout(i)}xa(!1);const t=window.setTimeout(()=>{xa(!0)},Kb);return()=>window.clearTimeout(t)},[se,r]),a.useEffect(()=>{if(!se||!Mt)return;const t=mi.current;if(!t)return;const i=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(i)},[Mt,se]),a.useEffect(()=>{if(!rs||!v||br)return;const t=window.setTimeout(()=>{_t(v,{background:!0})},3e3);return()=>window.clearTimeout(t)},[rs,v,br,_t]);const Wh=a.useCallback(t=>{_t(t,{discoverOnly:!0})},[_t]);mg({active:r&&(lt||Mt),rootPath:v,loading:br,delay:lt&&!se?0:Zi,lastStartedRoot:fi,load:Wh}),a.useEffect(()=>{!r||!lt||(!se||qo)&&Vo(!0)},[lt,se,r,qo]),a.useEffect(()=>{if(!r||lt)return;const t=window.setTimeout(()=>{Vo(!0)},Zi);return()=>window.clearTimeout(t)},[lt,r]),a.useEffect(()=>{Or&&Ch(!0)},[Or]),a.useEffect(()=>{Mt&&Jl(!0)},[Mt]),a.useEffect(()=>{!r||!ns||(n&&va&&va.sessionId!==n&&(Hi.getState().setDock(Wi,null),Xs({androidPanel:{docked:null}}).catch(()=>{})),Ql(!0))},[ns,r,n,va]),a.useEffect(()=>{if(r&&ns||!Yo)return;const t=window.setTimeout(()=>Ql(!1),Gb);return()=>window.clearTimeout(t)},[r,ns,Yo]),a.useEffect(()=>{let t=!1;return Vu().then(i=>{t||(i.androidPanel&&Zl(i.androidPanel.enabled===!0),ec(u=>({architecture:Xo.current.has("architecture")?u.architecture:i.rightSidebarTabs?.architecture!==!1,computer:Xo.current.has("computer")?u.computer:i.rightSidebarTabs?.computer!==!1})))}).catch(()=>{}),()=>{t=!0}},[]);const Pc=a.useCallback(t=>{Zl(t),t?Dt("android"):J.getState().rightTab==="android"&&Dt("files"),Xs({androidPanel:{enabled:t}}).catch(()=>{})},[Dt]),Gh=a.useCallback((t,i)=>{Xo.current.add(t),ec(u=>({...u,[t]:i})),i?Dt(t):J.getState().rightTab===t&&Dt("files"),Xs({rightSidebarTabs:{[t]:i}}).catch(()=>{})},[Dt]),Ac=a.useCallback(t=>{ie&&Kx(ie,t.currentTarget.scrollTop)},[ie]);a.useEffect(()=>()=>{_r.current?.abort(),Ws(Tl),Ws(Il),Ws(Js),Ws(Qi)},[]),a.useEffect(()=>{if(!ie||!Rc)return;const t=mh()[ie]?.top;if(typeof t!="number")return;let i=window.requestAnimationFrame(()=>{Xn.current&&(Xn.current.scrollTop=t),i=window.requestAnimationFrame(()=>{Xn.current&&(Xn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(i)},[ie,Rc]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return tp(t.signal).then(i=>ic(!!i.available)).catch(()=>ic(!1)),()=>t.abort()},[r]);const $s=a.useCallback(t=>{if(O(null),ot(t),gt(null),se){Dr(!0),Fr(1),Br.current?.slideTo(1),x?.();return}},[se,x,ot]),vi=a.useCallback((t,i)=>{if(O(null),ot(t),Cr(i),se){Dr(!0),Fr(1),Br.current?.slideTo(1),x?.();return}},[se,x,ot]),Bt=Kg(t=>Ns(t,!1)),Ta=Bt.busy,Ls=a.useCallback(async(t,i)=>{const u=i||qn||v;!u||!t.length||await Bt.start(u,t)},[qn,v,Bt.start]),Tc=a.useCallback(async t=>{try{await rp(t)}catch(i){Vt(i instanceof Error?i.message:o("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>Vt(null),4e3)}},[o]),Ia=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Qo(!0)},[]),Ic=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Qo(!1)},[]),Dc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Qo(!1);const i=t.dataTransfer.files;i.length>0&&Ls(Array.from(i))},[Ls]),yi=a.useCallback(t=>{_e(t),window.setTimeout(()=>_e(i=>i===t?null:i),1400)},[]),yr=a.useCallback(t=>{te(t),window.setTimeout(()=>te(i=>i===t?null:i),1400)},[]);a.useEffect(()=>{Lt(Su,ye)},[ye]),a.useEffect(()=>{Lt(ju,vt)},[vt]),a.useEffect(()=>{Lt(Ru,z)},[z]),a.useEffect(()=>{Zs(Qi,je,_b)},[je]),a.useEffect(()=>(uc().catch(()=>{}),Wd(t=>{t.type==="pinned-explorer-roots"&&fc(t.pinnedExplorerRoots)})),[uc,fc]);const Fc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),Da=a.useRef(null),wn=a.useRef(null),[_c,wi]=a.useState(!1);a.useEffect(()=>{if(!r)return;wi(!1);let t=!1;np().then(u=>{t||(Da.current=u.text,Qe(w=>u.text&&u.text!==w?u.text:w),wi(!0))}).catch(()=>{t||wi(!0)});const i=Wd(u=>{u.type==="context-draft"&&u.origin!==Fc.current&&(Da.current=u.text,Qe(u.text))});return()=>{t=!0,i(),wn.current!==null&&(window.clearTimeout(wn.current),wn.current=null)}},[r]),a.useEffect(()=>{if(!_c||Da.current===je)return;wn.current!==null&&window.clearTimeout(wn.current);const t=je;wn.current=window.setTimeout(()=>{wn.current=null,sp(t,Fc.current).then(()=>{Da.current=t}).catch(()=>{})},500)},[je,_c]);const as=a.useCallback(async(t,i,u,w)=>{if(!t)return!1;if(ap(u?t+u:t))return yi(i),!0;if(ye)Qe(y=>zg(y,t)+(u??"")),window.matchMedia("(pointer: coarse)").matches||(er(!1),Nr(y=>y+1));else{const y=n??Xr.getState().activeSessionId;if(!await Zu(u?t+u:t,y,()=>Ps.current&&y===Xr.getState().activeSessionId,w))return!1}return yi(i),!0},[ye,yi,n]),Fa=a.useCallback(t=>{const i=En(t,v);return jp(i,v)},[v]),ki=hf(yr),Ot=a.useCallback((t,i,u)=>{const w=En(t,v);return as(Rp(w,v),i??`path:${w}`,void 0,u)},[v,as]),_a=a.useRef({sessionId:n,contextDraftEnabled:ye,isOpen:r});_a.current={sessionId:n,contextDraftEnabled:ye,isOpen:r};const Kh=a.useCallback(async t=>{const i=n??Xr.getState().activeSessionId,u=()=>Ps.current&&_a.current.isOpen&&(_a.current.sessionId??Xr.getState().activeSessionId)===i&&Xr.getState().activeSessionId===i&&_a.current.contextDraftEnabled===ye;await Bt.start("/tmp",[t],y=>Ot(y,`path:${y}`),u)&&u()&&se&&!ye&&l()},[ye,Ot,se,l,n,Bt.start]),Ba=a.useRef(!0),Si=a.useRef(n);Si.current=n,a.useEffect(()=>(Ba.current=!0,()=>{Ba.current=!1}),[]);const qh=a.useCallback(t=>{Np.getState().enqueue(t,n??null,v||"/",i=>{if(ye&&Ba.current&&Si.current===n)Ot(i);else return Qd(i,n)})},[n,v,ye,Ot]),Vh=a.useCallback(async t=>{const u=(await dl("/tmp",[t])).files[0]?.path;if(!u)throw new Error("截图上传未返回文件路径");ye&&Ba.current&&Si.current===n?Ot(u):await Qd(u,n)},[ye,Ot,n]),ir=a.useCallback((t,i,u)=>{if(!t)return Promise.resolve(!1);const w=t.includes(`
1660
1660
  `)?`
1661
- `:void 0;return ss(t.endsWith(`
1662
- `)||t.endsWith(" ")?t:`${t} `,i,w,u)},[ss]),Dc=a.useRef(or);Dc.current=or;const Ls=a.useRef(!0);a.useEffect(()=>(Ls.current=!0,()=>{Ls.current=!1}),[]);const ki=a.useRef(new Set),Fc=a.useCallback((t,i,u)=>{if(ki.current.has(i))return;const w=n??Yr.getState().activeSessionId;ki.current.add(i),xg(t,i,u,{insert:or,upload:async(y,k)=>(await ll("/tmp",[y],k)).files[0]?.path,isCurrent:()=>Ls.current&&Dc.current===or&&w===Yr.getState().activeSessionId}).catch(()=>{}).finally(()=>ki.current.delete(i))},[or,n]),Or=a.useCallback((t,i,u)=>{i&&ss(i.endsWith(" ")?i:`${i} `,u??`context:${t}`,`
1663
- `)},[ss]),_c=Wg({text:je,sessionId:n??Yr.getState().activeSessionId,active:r&&ye,onAccepted:()=>{Jr(!1),Qe(""),z&&Zt(!0)},onRejected:()=>{Jr(!0),Zt(!1)}}),st=a.useMemo(()=>v?jt(v):o("rightSidebar.workspace"),[v,o]),zh=a.useMemo(()=>jt(ie)||st,[ie,st]),_a=a.useMemo(()=>ho(ie),[ie]),Ba=a.useMemo(()=>v?ic[v]??[]:[],[ic,v]),wn=a.useMemo(()=>new Set(Ba.map(t=>t.path)),[Ba]),Ps=!!(ie&&wn.has(ie)),Si=!!(v&&ie&&ie!==v),Wh=!!(v&&Kn&&Kn!==v),Ot=ie?`path:${ie}`:null,Bc="context:change-audit",Gh=a.useCallback(()=>{_a&&Dt(_a)},[_a,Dt]),Oc=a.useCallback(()=>{dc()},[dc]),Kh=a.useCallback(()=>{ie&&(Rs(ie,!0),hc())},[hc,ie,Rs]),qh=a.useCallback(()=>{!ie||!Si||(Ps?mn(ie):qn(ie,"directory"))},[Si,ie,Ps,qn,mn]),Uc=a.useCallback(t=>{Dt(t),V("")},[Dt]),Hc=a.useCallback(t=>{ie&&(he(Pb(ie,t)),H(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ie,H]),zc=a.useCallback(t=>{!v||t===v||(wn.has(t)?mn(t):qn(t,"directory"))},[qn,wn,v,mn]),Wc=a.useCallback(t=>{!v||!t||(wn.has(t)?mn(t):qn(t,"file"))},[qn,wn,v,mn]),Gc=Q(t=>t.expandedPaths),ji=a.useMemo(()=>{const t=new Set;if(Br&&ie){t.add(ie);const i=`${ie.replace(/\/+$/,"")}/`;for(const u of Gc)u.startsWith(i)&&t.add(u)}if(Br&&v&&at){const i=at.startsWith("/")?at:`${v}/${at}`,u=ho(i);u&&t.add(u)}return Lg(t).join(`
1664
- `)},[Gc,Br,ie,v,at]),kn=a.useRef(new Map);a.useEffect(()=>{const t=ji?ji.split(`
1665
- `):[];if(!r||t.length===0){Gn(null);return}const i=new AbortController;let u=!1,w=0,y=0;Gn(null);const k=async()=>{let C=0;for(;!u&&!i.signal.aborted;){let le=null;try{Gn(null),await op(t,ve=>{const{applicableEvents:Pe,unavailableReason:et}=Ag(ve);Pe.length>0&&uc(Pe);const Z=new Set(Pe.filter(Y=>Y.type==="rescan-required").map(Y=>Y.path));if(Ca)for(const Y of Pe){if(Y.type==="created"||Y.type==="updated"){const pe=ho(Y.path);pe&&Z.add(pe)}Y.path.endsWith("/.gitignore")&&ie&&Rs(ie,!0)}for(const Y of Z){const pe={path:Y},Ae=Q.getState();if(!Ae.directoryCache.has(pe.path))continue;kn.current.get(pe.path)?.abort();const He=new AbortController;kn.current.set(pe.path,He);const Td=`file-watch-rescan:${pe.path}`;Ct(Td),Hu(pe.path,He.signal,Ae.showHiddenFiles,"watch_rescan",Td,Ae.fileSortModes[pe.path]??"name",ie??void 0).then(Os=>{kn.current.get(pe.path)===He&&fc(pe.path,Os.entries)}).catch(Os=>{Sr(Os)||Gn(Os instanceof Error?Os.message:"File refresh unavailable")}).finally(()=>{kn.current.get(pe.path)===He&&kn.current.delete(pe.path)})}et&&Gn(et)},i.signal),le=new Error("File watch stream ended")}catch(ve){le=ve}if(u||i.signal.aborted||Sr(le))return;Gn(le instanceof Error?le.message:"File watching unavailable");const ae=wu[Math.min(C,wu.length-1)];C+=1,await new Promise(ve=>{y=window.setTimeout(ve,ae)})}};return w=window.setTimeout(()=>{u||k()},Ji),()=>{u=!0,window.clearTimeout(w),window.clearTimeout(y),i.abort();for(const C of kn.current.values())C.abort();kn.current.clear()}},[uc,r,fc,ji,ie,Ca,Rs]),a.useEffect(()=>{if(!v||li.current!==v)return;if(ci.current===v){ci.current=null;return}const t=Cu();Js(Rf,{...t,[v]:{selectedRepoRoots:ha,repoTargetBranches:nr,repoBaseBranches:Nt,previewEntries:nn,selectedPreviewKey:we&&Wt?Ze:null,selectedPreviewFileKey:we&&Wt?zo:null,previewDetailOpen:!!(we&&Wt),previewScrollTops:vs,previewMobileSlideIndex:1,repoIncludeUncommitted:on,updatedAt:Date.now()}},Ab)},[Wt,on,we,nn,vs,Nt,nr,ha,v,zo,Ze]);const mt=a.useMemo(()=>_u(Ie.values()),[Ie]),it=a.useMemo(()=>{const t=new Map;for(const i of $)t.set(i.root,i);return t},[$]),As=a.useMemo(()=>{const t=new Map;for(const i of $)i.deferred||t.set(i.root,i.files.length);return t},[$]),Oa=a.useCallback(t=>{if(t){if(!t.deferred){Ns.current.delete(t.root);return}As.has(t.root)||Ns.current.has(t.root)||(Ns.current.add(t.root),Ft(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(i=>{i||Ns.current.delete(t.root)}))}},[Ft,As]),ir=a.useMemo(()=>ne?ge.find(t=>t.root===ne)??null:null,[ne,ge]),Xt=a.useMemo(()=>at?Array.from(Ie.values()).find(t=>t.path===at||t.absolutePath===at)??null:null,[Ie,at]),Ut=a.useMemo(()=>{const t=new Map;for(const i of $)i.available&&i.context?.available&&t.set(i.root,i);return t.size===0&&de?.available&&de.root&&t.set(de.root,{id:de.root,root:de.root,relativeRoot:".",name:st,depth:0,nested:!1,available:!0,files:Array.from(Ie.values()).filter(i=>xt(i,v)===de.root),context:de}),Array.from(t.values()).sort((i,u)=>i.root===v?-1:u.root===v?1:(i.relativeRoot||i.name).localeCompare(u.relativeRoot||u.name)).map(i=>{const u=i.relativeRoot==="."?st:i.relativeRoot||i.name||jt(i.root),w=Fu(i.files),y=i.files.length;return{value:i.root,label:u,meta:[i.context?.branch,y>0?o("rightSidebar.repoChangedCount",{count:y}):null,w>0?o("rightSidebar.repoStagedCount",{count:w}):null].filter(Boolean).join(" · ")}})},[Ie,de,$,st,v,o]),Ee=a.useMemo(()=>ne&&Ut.some(t=>t.value===ne)?ne:Xt?.repoRoot&&Ut.some(t=>t.value===Xt.repoRoot)?Xt.repoRoot:Ut.length===1||Ut.length>1?Ut[0].value:null,[ne,Ut,Xt?.repoRoot]),Kc=Ee?it.get(Ee)??null:null,ue=Kc?.context?.available?Kc.context:Ee===de?.root?de:null,rt=Ut.length>0&&!Ee,qc=a.useMemo(()=>rt?[]:Ee?Array.from(Ie.values()).filter(t=>xt(t,v)===Ee):Array.from(Ie.values()),[Ee,Ie,rt,v]),Sn=a.useMemo(()=>_u(qc),[qc]),Ri=!!(ue?.available&&ue.root&&Ee&&ue.root===Ee),Vh=Ee?Ut.find(t=>t.value===Ee)?.label??jt(Ee):o("rightSidebar.gitRepositoryPlaceholder"),Vc=Ri?ue?.branch??"HEAD":rt?o("rightSidebar.selectRepositoryForGitActions"):un?o("rightSidebar.gitActionRunning"):"HEAD",jn=!!(ue?.available&&ue.root===Ee&&ue.status);a.useEffect(()=>{Gl.current={count:an.length,loading:re,loadingMore:Kt,hasMore:_o}},[an.length,_o,re,Kt]),a.useEffect(()=>{Wr.current+=1,mr.current?.abort(),Ct("right-sidebar-recent-commits"),mr.current=null,sn(""),zr([]),Ke(!1),Tr(!1),On(null),Un(!1)},[Ee]);const Ts=a.useCallback(async(t={})=>{if(!v||!Ee||rt)return;const i=t.reset??!1,u=Gl.current,w=i?0:u.count;if(!i&&(u.loading||u.loadingMore||!u.hasMore))return;const y=Wr.current+1;Wr.current=y,mr.current?.abort(),Ct("right-sidebar-recent-commits");const k=new AbortController;mr.current=k,i?Ke(!0):Tr(!0),On(null);try{const C=await ep({cwd:v,repoRoot:Ee,limit:Wb,skip:w,query:ys.trim(),requestSlotId:"right-sidebar-recent-commits"},k.signal);if(Wr.current!==y)return;if(!C.available){On(C.error??"Recent commits are unavailable"),i&&zr([]),Un(!1);return}ws(le=>i?C.commitSyncStatus??{}:{...le,...C.commitSyncStatus}),zr(le=>i?C.commits:[...le,...C.commits]),Un(C.hasMore)}catch(C){if(Wr.current!==y||Sr(C))return;On(C instanceof Error?C.message:"Failed to load recent commits"),i&&zr([]),Un(!1)}finally{mr.current===k&&(mr.current=null),Wr.current===y&&(Ke(!1),Tr(!1))}},[Ee,ys,rt,v]);a.useEffect(()=>{fr&&Ts({reset:!0})},[ys,Ts,fr,ue?.ahead,ue?.behind,ue?.upstream]);const Yh=a.useCallback(t=>{const i=t.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||Ts({reset:!1})},[Ts]);a.useEffect(()=>{!Ee||!de?.available||!lt||!sr||jn||un||rt||hi(Ee)},[Ee,de?.available,jn,un,lt,sr,hi,rt]);const Yc=r&&(Mt||lt);a.useEffect(()=>{!Yc||!v||xr()},[Yc,xr,v]),a.useEffect(()=>{!r||!lt||!sr||!ks||!v||La(null)},[ks,lt,sr,r,La,v]);const Xh=a.useMemo(()=>{if(!ne)return 0;const t=ge.findIndex(i=>i.root===ne);return t>=0?t+1:0},[ne,ge]),Xc=a.useCallback(t=>{if(!t)return null;const i=Array.from(Ie.values()).filter(u=>xt(u,v)===t).sort((u,w)=>u.path.localeCompare(w.path))[0];return i?kr(i):null},[Ie,v]),Rn=ge.length>1,Ua=a.useMemo(()=>[{root:null,label:o("rightSidebar.allRepositories"),count:Ie.size,branch:null,deferred:!1},...ge.map(t=>({root:t.root,label:t.label,count:t.deferred?As.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!As.has(t.root)}))],[Ie.size,ge,As,o]),Jc=Ua[Xh]??Ua[0],Ha=!!ne,Qc=a.useMemo(()=>Pf(ge,$),[ge,$]);a.useEffect(()=>{ui.current===v&&ne&&!Qc.has(ne)&&Ye(null),Pr(t=>t.filter(i=>ge.some(u=>u.root===i)))},[ne,ge,Qc,v,Ye]),a.useEffect(()=>{ne&&Oa(it.get(ne))},[ne,Oa,it]);const Jh=a.useMemo(()=>{const t=new Set;ue?.branch&&t.add(ue.branch);for(const i of ue?.branches??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ue?.branch,ue?.branches,o]),Zc=a.useMemo(()=>{const t=new Set;ue?.upstreamRemote&&t.add(ue.upstreamRemote);for(const i of ue?.remotes??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===ue?.upstreamRemote?o("rightSidebar.pushUpstreamBadge"):void 0}))},[ue?.remotes,ue?.upstreamRemote,o]),ed=Zc.length>1,Qh=a.useMemo(()=>{const t=[],i=new Set,u=(y,k)=>{!y||i.has(y)||(i.add(y),t.push({value:y,label:y,meta:k}))};u(ue?.upstreamBranch,ue?.upstreamBranch?o("rightSidebar.pushUpstreamBadge"):void 0),u(ue?.branch,ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0);for(const y of ue?.branches??[])u(y,y===ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");const w=ue?.upstreamRemote;for(const y of ue?.remoteBranches??[]){const k=y.indexOf("/"),C=k>=0?y.slice(0,k):null,le=k>=0?y.slice(k+1):y;(!w||C===w)&&u(le,"remote")}return t},[ue?.branch,ue?.branches,ue?.remoteBranches,ue?.upstreamBranch,ue?.upstreamRemote,o]),Jt=a.useMemo(()=>Ut.map(t=>{const i=it.get(t.value);return{root:t.value,label:t.label,branch:i?.context?.branch??null}}),[Ut,it]);a.useEffect(()=>{Jt.length!==0&&(ma(t=>{let i=!1;const u={...t},w=new Set(Jt.map(y=>y.root));for(const y of Object.keys(u))w.has(y)||(delete u[y],i=!0);for(const y of Jt)!u[y.root]&&y.branch&&(u[y.root]=y.branch,i=!0);return i?u:t}),pa(t=>{let i=!1;const u={...t},w=new Set(Jt.map(y=>y.root));for(const y of Object.keys(u))w.has(y)||(delete u[y],i=!0);for(const y of Jt){const k=it.get(y.root)?.context;if(u[y.root]&&Af(u[y.root],k?.branch)&&(delete u[y.root],i=!0),u[y.root])continue;const C=Mu(k);C&&(u[y.root]=C,i=!0)}return i?u:t}))},[Jt,it]);const za=a.useMemo(()=>{const t=new Set(Jt.map(i=>i.root));return ha.filter(i=>t.has(i))},[ha,Jt]),Wa=za.length===0,yr=a.useMemo(()=>Wa?Jt:Jt.filter(t=>za.includes(t.root)),[Jt,za,Wa]),Is=a.useMemo(()=>yr.filter(t=>!!Nt[t.root]?.trim()),[Nt,yr]),as=a.useCallback((t,i)=>{const u=it.get(t)?.context?.branch;return!!(u&&i&&i.replace(/^refs\/heads\//,"")===u)},[it]),td=a.useMemo(()=>yr.filter(t=>!Nt[t.root]?.trim()),[Nt,yr]),rd=a.useCallback(async t=>{if(!t||ii.current.has(t))return;const i=it.get(t)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const u=v;ii.current.add(t),Vl(w=>new Set(w).add(t));try{const w=await Od(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!w.available||!Me(u))return;me(y=>y.map(k=>k.root===t?{...k,available:!0,context:{...k.context,...w},error:void 0}:k)),ma(y=>y[t]||!w.branch?y:{...y,[t]:w.branch}),pa(y=>{if(y[t])return y;const k=Mu(w);return k?{...y,[t]:k}:y})}catch(w){Sr(w)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,w)}finally{ii.current.delete(t),Vl(w=>{const y=new Set(w);return y.delete(t),y})}},[it,Me,v]);a.useEffect(()=>{if(Bo)for(const t of yr)rd(t.root)},[Bo,yr,rd]),a.useEffect(()=>{!Ri||!ue||(ya(ue.branch||(ue.branches?.[0]??"")),wa(ue.upstreamRemote||(ue.remotes?.includes("origin")?"origin":ue.remotes?.[0]??"")),ka(ue.upstreamBranch||ue.branch||(ue.branches?.[0]??"")))},[ue,Ri]);const nd=a.useMemo(()=>{if(rt)return{text:o("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!jn||un)return{text:o("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ue?.upstream)return{text:o("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=ue.ahead??0,i=ue.behind??0;return t>0&&i>0?{text:o("rightSidebar.pushDivergedCount",{ahead:t,behind:i}),className:"bg-destructive/10 text-destructive"}:t>0?{text:o("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:i>0?{text:o("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:o("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ue?.ahead,ue?.behind,ue?.upstream,jn,un,rt,o]),Zh=a.useCallback(t=>{if(t&&!se){const i=t.currentTarget.getBoundingClientRect();De({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else De(null);S?.()},[se,S]),Ci=a.useCallback(()=>{De(null),T?.()},[T]);function sd(){if(!Rn)return null;const t=Jc?.label??o("rightSidebar.allRepositories"),i=Jc?.count??Ie.size,u=jt(t)||t;return e.jsxs("button",{type:"button",onClick:Zh,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${b?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":b,title:t,children:[e.jsx(wr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:u}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(ra,{size:12,className:"shrink-0"})]})}function em(){if(!b||!Rn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,u=Math.max(12,Math.min(Je?.x??t-368,t-352)),w=Math.max(12,Math.min(Je?.y??80,i-420)),y=se?void 0:{left:u,top:w},k=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${se?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Ci,children:e.jsxs("div",{className:se?"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:y,onClick:C=>C.stopPropagation(),children:[e.jsxs("div",{className:se?"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:se?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:o("rightSidebar.repositories")}),!se&&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:Ua.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Ie.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ie.size})]})]}),e.jsx("button",{type:"button",onClick:Ci,className:se?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.close"),children:e.jsx(Pt,{size:se?16:14})})]}),e.jsx("div",{className:se?"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:Ua.map(C=>{const le=(C.root??null)===ne,ae=jt(C.label)||C.label;return e.jsxs("button",{type:"button",onClick:()=>{jd(C.root),Ci()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${se?"px-3 py-2":"px-2 py-1.5"} ${le?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:C.label,role:"option","aria-selected":le,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${le?"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 ${le?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(wr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${se?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:ae}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:C.root===null?o("rightSidebar.allRepositories"):C.label})]}),C.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:C.branch}),C.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:o("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${C.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:C.count})]},C.root??"all")})})]})});return vf(k,se,document.body)}function tm(){return em()}function ad(t){const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=vo(u,i??v);return{key:kr(t),path:t.path,absolutePath:u,displayName:w.name,displayDir:w.dir,oldPath:t.oldPath,status:t.status,title:u}}function od(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:o("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function Ga(t,i){const u=Nn(t,v),w=`path:${u}`,y=Te===w,k=Be===w,C=y||k;return e.jsx("button",{type:"button",onClick:le=>{le.stopPropagation(),Bt(u,w)},...yi(Ia(u),w),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${C?"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"} ${C?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:o(k?"rightSidebar.copied":y?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function id(t){const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=Mm(t),y=al(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Jx,{actions:w,running:ze,completed:Hn?.path===y?Hn:null}),Ga(u,o("rightSidebar.insertThisFile"))]})}function ld(t,i){const u=i.root??v;if(!u)return null;const w=Nn(t,u);return Ga(w,o("fileTree.insertRefTitle"))}function Ds(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":o("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>xd("unified"),"aria-pressed":$r==="unified",title:o("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${$r==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>xd("split"),"aria-pressed":$r==="split",title:o("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${$r==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.split")})]})}function cd(){return Fs.map(t=>{const i=Fu(t.files.map(([,k])=>k)),u=wl({activeGitRepoRoot:ne,groupCount:Fs.length,label:t.label,rootName:st}),w=!!(u&&t.root&&Nr.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:w,files:t.files.map(([,k])=>ad(k)),header:u?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${w?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>vm(t.root),"aria-expanded":!w,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:w?e.jsx(fs,{size:13}):e.jsx(ra,{size:13})}),e.jsx(wr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Qa("stage-all",t.root,t.label)},disabled:!!ze,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:o("rightSidebar.stageAll"),children:o("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Qa("stash-all",t.root,t.label)},disabled:!!ze,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:o("rightSidebar.stashAll"),children:o("rightSidebar.stashAll")})]})]}):null}})}const Cn=a.useMemo(()=>new Map(Array.from(Ie.values(),t=>[kr(t),t])),[Ie]);function dd(t){const i=Cn.get(t.key),u=i?xt(i,v):null,w=yg(wt,u,i?.path??t.path);return e.jsx(gl,{changeStatus:t.status,auditStatus:w,renderChangeBadge:y=>e.jsx(Qs,{status:y})})}const Ka=a.useCallback(t=>{if(se)return null;const i=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const w=t.getBoundingClientRect().top+48;let y=null,k=Number.POSITIVE_INFINITY;for(const le of i){const ae=le.getBoundingClientRect();if(ae.bottom<w)continue;const ve=Math.abs(ae.top-w);ve<k&&(y=le,k=ve)}const C=y?.dataset.diffSelectionPath??y?.dataset.diffStreamItem??null;return C?(Ma.current===C&&Q.getState().selectedFilePath===C||(Ma.current=C,ot(C)),C):null},[se,ot]),rm=!!(!ze&&Ee&&!rt&&(ue?.upstream||fn.trim()&&hn.trim())),nm=!!(!ze&&Ee&&!rt&&(ue?.upstream||fn.trim()&&hn.trim())),sm=!!(!ze&&Ee&&!rt&&Wn.trim()&&Wn.trim()!==ue?.branch),Qt=a.useMemo(()=>{const t=Se.trim().toLowerCase(),i=Array.from(Ie.entries()).filter(([,u])=>!ne||xt(u,v)===ne).sort(([u],[w])=>u.localeCompare(w));return t?i.filter(([u,w])=>`${u} ${w.path} ${w.status} ${w.repoRelativeRoot??""} ${w.repoName??""}`.toLowerCase().includes(t)):i},[ne,Ie,Se,v]);a.useEffect(()=>{Vs("selected_file_state",{selectedFilePath:at,selectedChangedFilePath:Xt?.path??null,selectedChangedFileAbsolutePath:Xt?.absolutePath??null,selectedChangedFileRepoRoot:Xt?.repoRoot??null,rootPath:v,activeGitRepoRoot:ne,rightTab:ei,effectiveRightTab:Et,diffPaneActive:Mt,changedFiles:Ie.size,filteredChangedFiles:Qt.length,gitBundleLoading:gr,gitBundleLastLoadedAt:Vn})},[ne,Ie.size,Mt,Et,Qt.length,Vn,gr,ei,v,Xt?.absolutePath,Xt?.path,Xt?.repoRoot,at]);const Fs=a.useMemo(()=>{const t=new Map;for(const i of Qt){const[,u]=i,w=xt(u,v),y=Yx(u)||st,k=w??y,C=w?it.get(w):void 0,le=t.get(k)??{root:w,label:y,branch:C?.context?.branch,files:[]};le.files.push(i),t.set(k,le)}return Array.from(t.values()).sort((i,u)=>i.label===st?-1:u.label===st?1:i.label.localeCompare(u.label))},[Qt,it,st,v]),_s=a.useMemo(()=>{const t=[],i=new Map;for(const u of Qt)i.set(kr(u[1]),u);for(const u of Fs){if(!!(u.root&&wl({activeGitRepoRoot:ne,groupCount:Fs.length,label:u.label,rootName:st})&&Nr.has(u.root)))continue;if(Ht!=="tree"){t.push(...u.files);continue}const y=u.files.map(([,k])=>ad(k));for(const k of Pp(y)){const C=i.get(k.key);C&&t.push(C)}}return t},[ne,Nr,Ht,Fs,Qt,st]),ud=a.useMemo(()=>Ie.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:o("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:_s.map(([,t])=>{const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path);return{key:kr(t),path:t.path,absolutePath:u,status:t.status,repoRoot:i,displayName:vo(u,i).name,displayDir:vo(u,i).dir,auditRecords:wt}}),[wt,Ie.size,_s,v,o]);a.useEffect(()=>{if(!Mt||_s.length===0||se)return;const t=[],i=()=>{const u=document.querySelector(".termdock-diff-stream-scroller");if(u&&Ka(u))return;const w=document.querySelector("[data-diff-stream-item]"),y=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;if(y){Ma.current=y,ot(y);return}const k=_s[0]?.[1];if(!k)return;const C=kr(k);Ma.current=C,ot(C)};for(const u of[80,240,600,1200])t.push(window.setTimeout(i,u));return()=>t.forEach(u=>window.clearTimeout(u))},[Mt,se,_s,ot,Ka]);const Ni=a.useMemo(()=>{const t=C=>`'${C.replace(/'/g,"'\\''")}'`,i=ar.length>0?xn:$.filter(C=>C.files.length>0),u=i.length>0?i:v?[{root:v,relativeRoot:".",name:st}]:[],w=u.length>0?u.map(C=>`- ${C.relativeRoot==="."?".":C.relativeRoot} (${C.root})`).join(`
1666
- `):`- ${v?".":""}`,y=u.length>0?u.map(C=>` td audit-export ${t(C.root)}`).join(`
1661
+ `:void 0;return as(t.endsWith(`
1662
+ `)||t.endsWith(" ")?t:`${t} `,i,w,u)},[as]),Bc=a.useRef(ir);Bc.current=ir;const Ps=a.useRef(!0);a.useEffect(()=>(Ps.current=!0,()=>{Ps.current=!1}),[]);const ji=a.useRef(new Set),Oc=a.useCallback((t,i,u)=>{if(ji.current.has(i))return;const w=n??Xr.getState().activeSessionId;ji.current.add(i),kg(t,i,u,{insert:ir,upload:async(y,k)=>(await dl("/tmp",[y],k)).files[0]?.path,isCurrent:()=>Ps.current&&Bc.current===ir&&w===Xr.getState().activeSessionId}).catch(()=>{}).finally(()=>ji.current.delete(i))},[ir,n]),Ur=a.useCallback((t,i,u)=>{i&&as(i.endsWith(" ")?i:`${i} `,u??`context:${t}`,`
1663
+ `)},[as]),Uc=Vg({text:je,sessionId:n??Xr.getState().activeSessionId,active:r&&ye,onAccepted:()=>{Qr(!1),Qe(""),z&&er(!0)},onRejected:()=>{Qr(!0),er(!1)}}),st=a.useMemo(()=>v?jt(v):o("rightSidebar.workspace"),[v,o]),Yh=a.useMemo(()=>jt(ie)||st,[ie,st]),Oa=a.useMemo(()=>po(ie),[ie]),Ua=a.useMemo(()=>v?dc[v]??[]:[],[dc,v]),kn=a.useMemo(()=>new Set(Ua.map(t=>t.path)),[Ua]),As=!!(ie&&kn.has(ie)),Ri=!!(v&&ie&&ie!==v),Xh=!!(v&&qn&&qn!==v),Ut=ie?`path:${ie}`:null,Hc="context:change-audit",Jh=a.useCallback(()=>{Oa&&Ft(Oa)},[Oa,Ft]),zc=a.useCallback(()=>{hc()},[hc]),Qh=a.useCallback(()=>{ie&&(Ns(ie,!0),gc())},[gc,ie,Ns]),Zh=a.useCallback(()=>{!ie||!Ri||(As?pn(ie):Vn(ie,"directory"))},[Ri,ie,As,Vn,pn]),Wc=a.useCallback(t=>{Ft(t),V("")},[Ft]),Gc=a.useCallback(t=>{ie&&(he(Db(ie,t)),H(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ie,H]),Kc=a.useCallback(t=>{!v||t===v||(kn.has(t)?pn(t):Vn(t,"directory"))},[Vn,kn,v,pn]),qc=a.useCallback(t=>{!v||!t||(kn.has(t)?pn(t):Vn(t,"file"))},[Vn,kn,v,pn]),Vc=J(t=>t.expandedPaths),Ni=a.useMemo(()=>{const t=new Set;if(Or&&ie){t.add(ie);const i=`${ie.replace(/\/+$/,"")}/`;for(const u of Vc)u.startsWith(i)&&t.add(u)}if(Or&&v&&at){const i=at.startsWith("/")?at:`${v}/${at}`,u=po(i);u&&t.add(u)}return Ig(t).join(`
1664
+ `)},[Vc,Or,ie,v,at]),Sn=a.useRef(new Map);a.useEffect(()=>{const t=Ni?Ni.split(`
1665
+ `):[];if(!r||t.length===0){Kn(null);return}const i=new AbortController;let u=!1,w=0,y=0;Kn(null);const k=async()=>{let N=0;for(;!u&&!i.signal.aborted;){let le=null;try{Kn(null),await up(t,ve=>{const{applicableEvents:Pe,unavailableReason:et}=Fg(ve);Pe.length>0&&mc(Pe);const Z=new Set(Pe.filter(Y=>Y.type==="rescan-required").map(Y=>Y.path));if(Ea)for(const Y of Pe){if(Y.type==="created"||Y.type==="updated"){const pe=po(Y.path);pe&&Z.add(pe)}Y.path.endsWith("/.gitignore")&&ie&&Ns(ie,!0)}for(const Y of Z){const pe={path:Y},Ae=J.getState();if(!Ae.directoryCache.has(pe.path))continue;Sn.current.get(pe.path)?.abort();const He=new AbortController;Sn.current.set(pe.path,He);const Fd=`file-watch-rescan:${pe.path}`;Nt(Fd),qu(pe.path,He.signal,Ae.showHiddenFiles,"watch_rescan",Fd,Ae.fileSortModes[pe.path]??"name",ie??void 0).then(Us=>{Sn.current.get(pe.path)===He&&pc(pe.path,Us.entries)}).catch(Us=>{jr(Us)||Kn(Us instanceof Error?Us.message:"File refresh unavailable")}).finally(()=>{Sn.current.get(pe.path)===He&&Sn.current.delete(pe.path)})}et&&Kn(et)},i.signal),le=new Error("File watch stream ended")}catch(ve){le=ve}if(u||i.signal.aborted||jr(le))return;Kn(le instanceof Error?le.message:"File watching unavailable");const ae=Nu[Math.min(N,Nu.length-1)];N+=1,await new Promise(ve=>{y=window.setTimeout(ve,ae)})}};return w=window.setTimeout(()=>{u||k()},Zi),()=>{u=!0,window.clearTimeout(w),window.clearTimeout(y),i.abort();for(const N of Sn.current.values())N.abort();Sn.current.clear()}},[mc,r,pc,Ni,ie,Ea,Ns]),a.useEffect(()=>{if(!v||di.current!==v)return;if(ui.current===v){ui.current=null;return}const t=Lu();Zs($f,{...t,[v]:{selectedRepoRoots:pa,repoTargetBranches:sr,repoBaseBranches:Ct,previewEntries:sn,selectedPreviewKey:we&&Gt?Ze:null,selectedPreviewFileKey:we&&Gt?Wo:null,previewDetailOpen:!!(we&&Gt),previewScrollTops:ys,previewMobileSlideIndex:1,repoIncludeUncommitted:ln,updatedAt:Date.now()}},Fb)},[Gt,ln,we,sn,ys,Ct,sr,pa,v,Wo,Ze]);const mt=a.useMemo(()=>zu(Ie.values()),[Ie]),it=a.useMemo(()=>{const t=new Map;for(const i of $)t.set(i.root,i);return t},[$]),Ts=a.useMemo(()=>{const t=new Map;for(const i of $)i.deferred||t.set(i.root,i.files.length);return t},[$]),Ha=a.useCallback(t=>{if(t){if(!t.deferred){Es.current.delete(t.root);return}Ts.has(t.root)||Es.current.has(t.root)||(Es.current.add(t.root),_t(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(i=>{i||Es.current.delete(t.root)}))}},[_t,Ts]),lr=a.useMemo(()=>ne?ge.find(t=>t.root===ne)??null:null,[ne,ge]),Jt=a.useMemo(()=>at?Array.from(Ie.values()).find(t=>t.path===at||t.absolutePath===at)??null:null,[Ie,at]),Ht=a.useMemo(()=>{const t=new Map;for(const i of $)i.available&&i.context?.available&&t.set(i.root,i);return t.size===0&&de?.available&&de.root&&t.set(de.root,{id:de.root,root:de.root,relativeRoot:".",name:st,depth:0,nested:!1,available:!0,files:Array.from(Ie.values()).filter(i=>xt(i,v)===de.root),context:de}),Array.from(t.values()).sort((i,u)=>i.root===v?-1:u.root===v?1:(i.relativeRoot||i.name).localeCompare(u.relativeRoot||u.name)).map(i=>{const u=i.relativeRoot==="."?st:i.relativeRoot||i.name||jt(i.root),w=Hu(i.files),y=i.files.length;return{value:i.root,label:u,meta:[i.context?.branch,y>0?o("rightSidebar.repoChangedCount",{count:y}):null,w>0?o("rightSidebar.repoStagedCount",{count:w}):null].filter(Boolean).join(" · ")}})},[Ie,de,$,st,v,o]),Ee=a.useMemo(()=>ne&&Ht.some(t=>t.value===ne)?ne:Jt?.repoRoot&&Ht.some(t=>t.value===Jt.repoRoot)?Jt.repoRoot:Ht.length===1||Ht.length>1?Ht[0].value:null,[ne,Ht,Jt?.repoRoot]),Yc=Ee?it.get(Ee)??null:null,ue=Yc?.context?.available?Yc.context:Ee===de?.root?de:null,rt=Ht.length>0&&!Ee,Xc=a.useMemo(()=>rt?[]:Ee?Array.from(Ie.values()).filter(t=>xt(t,v)===Ee):Array.from(Ie.values()),[Ee,Ie,rt,v]),jn=a.useMemo(()=>zu(Xc),[Xc]),Ci=!!(ue?.available&&ue.root&&Ee&&ue.root===Ee),em=Ee?Ht.find(t=>t.value===Ee)?.label??jt(Ee):o("rightSidebar.gitRepositoryPlaceholder"),Jc=Ci?ue?.branch??"HEAD":rt?o("rightSidebar.selectRepositoryForGitActions"):fn?o("rightSidebar.gitActionRunning"):"HEAD",Rn=!!(ue?.available&&ue.root===Ee&&ue.status);a.useEffect(()=>{ql.current={count:on.length,loading:re,loadingMore:qt,hasMore:Bo}},[on.length,Bo,re,qt]),a.useEffect(()=>{Gr.current+=1,pr.current?.abort(),Nt("right-sidebar-recent-commits"),pr.current=null,an(""),Wr([]),Ke(!1),Ir(!1),Un(null),Hn(!1)},[Ee]);const Is=a.useCallback(async(t={})=>{if(!v||!Ee||rt)return;const i=t.reset??!1,u=ql.current,w=i?0:u.count;if(!i&&(u.loading||u.loadingMore||!u.hasMore))return;const y=Gr.current+1;Gr.current=y,pr.current?.abort(),Nt("right-sidebar-recent-commits");const k=new AbortController;pr.current=k,i?Ke(!0):Ir(!0),Un(null);try{const N=await op({cwd:v,repoRoot:Ee,limit:Vb,skip:w,query:ws.trim(),requestSlotId:"right-sidebar-recent-commits"},k.signal);if(Gr.current!==y)return;if(!N.available){Un(N.error??"Recent commits are unavailable"),i&&Wr([]),Hn(!1);return}ks(le=>i?N.commitSyncStatus??{}:{...le,...N.commitSyncStatus}),Wr(le=>i?N.commits:[...le,...N.commits]),Hn(N.hasMore)}catch(N){if(Gr.current!==y||jr(N))return;Un(N instanceof Error?N.message:"Failed to load recent commits"),i&&Wr([]),Hn(!1)}finally{pr.current===k&&(pr.current=null),Gr.current===y&&(Ke(!1),Ir(!1))}},[Ee,ws,rt,v]);a.useEffect(()=>{hr&&Is({reset:!0})},[ws,Is,hr,ue?.ahead,ue?.behind,ue?.upstream]);const tm=a.useCallback(t=>{const i=t.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||Is({reset:!1})},[Is]);a.useEffect(()=>{!Ee||!de?.available||!lt||!ar||Rn||fn||rt||pi(Ee)},[Ee,de?.available,Rn,fn,lt,ar,pi,rt]);const Qc=r&&(Mt||lt);a.useEffect(()=>{!Qc||!v||vr()},[Qc,vr,v]),a.useEffect(()=>{!r||!lt||!ar||!Ss||!v||Aa(null)},[Ss,lt,ar,r,Aa,v]);const rm=a.useMemo(()=>{if(!ne)return 0;const t=ge.findIndex(i=>i.root===ne);return t>=0?t+1:0},[ne,ge]),Zc=a.useCallback(t=>{if(!t)return null;const i=Array.from(Ie.values()).filter(u=>xt(u,v)===t).sort((u,w)=>u.path.localeCompare(w.path))[0];return i?Sr(i):null},[Ie,v]),Nn=ge.length>1,za=a.useMemo(()=>[{root:null,label:o("rightSidebar.allRepositories"),count:Ie.size,branch:null,deferred:!1},...ge.map(t=>({root:t.root,label:t.label,count:t.deferred?Ts.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!Ts.has(t.root)}))],[Ie.size,ge,Ts,o]),ed=za[rm]??za[0],Wa=!!ne,td=a.useMemo(()=>Ff(ge,$),[ge,$]);a.useEffect(()=>{hi.current===v&&ne&&!td.has(ne)&&Ye(null),Ar(t=>t.filter(i=>ge.some(u=>u.root===i)))},[ne,ge,td,v,Ye]),a.useEffect(()=>{ne&&Ha(it.get(ne))},[ne,Ha,it]);const nm=a.useMemo(()=>{const t=new Set;ue?.branch&&t.add(ue.branch);for(const i of ue?.branches??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ue?.branch,ue?.branches,o]),rd=a.useMemo(()=>{const t=new Set;ue?.upstreamRemote&&t.add(ue.upstreamRemote);for(const i of ue?.remotes??[])t.add(i);return Array.from(t).map(i=>({value:i,label:i,meta:i===ue?.upstreamRemote?o("rightSidebar.pushUpstreamBadge"):void 0}))},[ue?.remotes,ue?.upstreamRemote,o]),nd=rd.length>1,sm=a.useMemo(()=>{const t=[],i=new Set,u=(y,k)=>{!y||i.has(y)||(i.add(y),t.push({value:y,label:y,meta:k}))};u(ue?.upstreamBranch,ue?.upstreamBranch?o("rightSidebar.pushUpstreamBadge"):void 0),u(ue?.branch,ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):void 0);for(const y of ue?.branches??[])u(y,y===ue?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");const w=ue?.upstreamRemote;for(const y of ue?.remoteBranches??[]){const k=y.indexOf("/"),N=k>=0?y.slice(0,k):null,le=k>=0?y.slice(k+1):y;(!w||N===w)&&u(le,"remote")}return t},[ue?.branch,ue?.branches,ue?.remoteBranches,ue?.upstreamBranch,ue?.upstreamRemote,o]),Qt=a.useMemo(()=>Ht.map(t=>{const i=it.get(t.value);return{root:t.value,label:t.label,branch:i?.context?.branch??null}}),[Ht,it]);a.useEffect(()=>{Qt.length!==0&&(ga(t=>{let i=!1;const u={...t},w=new Set(Qt.map(y=>y.root));for(const y of Object.keys(u))w.has(y)||(delete u[y],i=!0);for(const y of Qt)!u[y.root]&&y.branch&&(u[y.root]=y.branch,i=!0);return i?u:t}),ba(t=>{let i=!1;const u={...t},w=new Set(Qt.map(y=>y.root));for(const y of Object.keys(u))w.has(y)||(delete u[y],i=!0);for(const y of Qt){const k=it.get(y.root)?.context;if(u[y.root]&&_f(u[y.root],k?.branch)&&(delete u[y.root],i=!0),u[y.root])continue;const N=Tu(k);N&&(u[y.root]=N,i=!0)}return i?u:t}))},[Qt,it]);const Ga=a.useMemo(()=>{const t=new Set(Qt.map(i=>i.root));return pa.filter(i=>t.has(i))},[pa,Qt]),Ka=Ga.length===0,wr=a.useMemo(()=>Ka?Qt:Qt.filter(t=>Ga.includes(t.root)),[Qt,Ga,Ka]),Ds=a.useMemo(()=>wr.filter(t=>!!Ct[t.root]?.trim()),[Ct,wr]),os=a.useCallback((t,i)=>{const u=it.get(t)?.context?.branch;return!!(u&&i&&i.replace(/^refs\/heads\//,"")===u)},[it]),sd=a.useMemo(()=>wr.filter(t=>!Ct[t.root]?.trim()),[Ct,wr]),ad=a.useCallback(async t=>{if(!t||ci.current.has(t))return;const i=it.get(t)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const u=v;ci.current.add(t),Xl(w=>new Set(w).add(t));try{const w=await zd(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!w.available||!Me(u))return;me(y=>y.map(k=>k.root===t?{...k,available:!0,context:{...k.context,...w},error:void 0}:k)),ga(y=>y[t]||!w.branch?y:{...y,[t]:w.branch}),ba(y=>{if(y[t])return y;const k=Tu(w);return k?{...y,[t]:k}:y})}catch(w){jr(w)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,w)}finally{ci.current.delete(t),Xl(w=>{const y=new Set(w);return y.delete(t),y})}},[it,Me,v]);a.useEffect(()=>{if(Oo)for(const t of wr)ad(t.root)},[Oo,wr,ad]),a.useEffect(()=>{!Ci||!ue||(ka(ue.branch||(ue.branches?.[0]??"")),Sa(ue.upstreamRemote||(ue.remotes?.includes("origin")?"origin":ue.remotes?.[0]??"")),ja(ue.upstreamBranch||ue.branch||(ue.branches?.[0]??"")))},[ue,Ci]);const od=a.useMemo(()=>{if(rt)return{text:o("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Rn||fn)return{text:o("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ue?.upstream)return{text:o("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=ue.ahead??0,i=ue.behind??0;return t>0&&i>0?{text:o("rightSidebar.pushDivergedCount",{ahead:t,behind:i}),className:"bg-destructive/10 text-destructive"}:t>0?{text:o("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:i>0?{text:o("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:o("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ue?.ahead,ue?.behind,ue?.upstream,Rn,fn,rt,o]),am=a.useCallback(t=>{if(t&&!se){const i=t.currentTarget.getBoundingClientRect();De({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else De(null);S?.()},[se,S]),Ei=a.useCallback(()=>{De(null),T?.()},[T]);function id(){if(!Nn)return null;const t=ed?.label??o("rightSidebar.allRepositories"),i=ed?.count??Ie.size,u=jt(t)||t;return e.jsxs("button",{type:"button",onClick:am,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${b?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":b,title:t,children:[e.jsx(kr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:u}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(sa,{size:12,className:"shrink-0"})]})}function om(){if(!b||!Nn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,u=Math.max(12,Math.min(Je?.x??t-368,t-352)),w=Math.max(12,Math.min(Je?.y??80,i-420)),y=se?void 0:{left:u,top:w},k=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${se?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Ei,children:e.jsxs("div",{className:se?"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:y,onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:se?"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:se?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:o("rightSidebar.repositories")}),!se&&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:za.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Ie.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ie.size})]})]}),e.jsx("button",{type:"button",onClick:Ei,className:se?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.close"),children:e.jsx(Pt,{size:se?16:14})})]}),e.jsx("div",{className:se?"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:za.map(N=>{const le=(N.root??null)===ne,ae=jt(N.label)||N.label;return e.jsxs("button",{type:"button",onClick:()=>{Cd(N.root),Ei()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${se?"px-3 py-2":"px-2 py-1.5"} ${le?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:N.label,role:"option","aria-selected":le,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${le?"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 ${le?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(kr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${se?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:ae}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:N.root===null?o("rightSidebar.allRepositories"):N.label})]}),N.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:N.branch}),N.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:o("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${N.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:N.count})]},N.root??"all")})})]})});return jf(k,se,document.body)}function im(){return om()}function ld(t){const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=yo(u,i??v);return{key:Sr(t),path:t.path,absolutePath:u,displayName:w.name,displayDir:w.dir,oldPath:t.oldPath,status:t.status,title:u}}function cd(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:o("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function qa(t,i){const u=En(t,v),w=`path:${u}`,y=Te===w,k=Be===w,N=y||k;return e.jsx("button",{type:"button",onClick:le=>{le.stopPropagation(),Ot(u,w)},...ki(Fa(u),w),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${N?"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"} ${N?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:o(k?"rightSidebar.copied":y?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function dd(t){const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path),w=Im(t),y=il(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(t0,{actions:w,running:ze,completed:zn?.path===y?zn:null}),qa(u,o("rightSidebar.insertThisFile"))]})}function ud(t,i){const u=i.root??v;if(!u)return null;const w=En(t,u);return qa(w,o("fileTree.insertRefTitle"))}function Fs(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":o("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>wd("unified"),"aria-pressed":Lr==="unified",title:o("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Lr==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>wd("split"),"aria-pressed":Lr==="split",title:o("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Lr==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:o("diffViewer.split")})]})}function fd(){return _s.map(t=>{const i=Hu(t.files.map(([,k])=>k)),u=Sl({activeGitRepoRoot:ne,groupCount:_s.length,label:t.label,rootName:st}),w=!!(u&&t.root&&Er.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:w,files:t.files.map(([,k])=>ld(k)),header:u?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${w?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Rm(t.root),"aria-expanded":!w,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:w?e.jsx(hs,{size:13}):e.jsx(sa,{size:13})}),e.jsx(kr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),eo("stage-all",t.root,t.label)},disabled:!!ze,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:o("rightSidebar.stageAll"),children:o("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),eo("stash-all",t.root,t.label)},disabled:!!ze,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:o("rightSidebar.stashAll"),children:o("rightSidebar.stashAll")})]})]}):null}})}const Cn=a.useMemo(()=>new Map(Array.from(Ie.values(),t=>[Sr(t),t])),[Ie]);function hd(t){const i=Cn.get(t.key),u=i?xt(i,v):null,w=jg(wt,u,i?.path??t.path);return e.jsx(xl,{changeStatus:t.status,auditStatus:w,renderChangeBadge:y=>e.jsx(ea,{status:y})})}const Va=a.useCallback(t=>{if(se)return null;const i=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const w=t.getBoundingClientRect().top+48;let y=null,k=Number.POSITIVE_INFINITY;for(const le of i){const ae=le.getBoundingClientRect();if(ae.bottom<w)continue;const ve=Math.abs(ae.top-w);ve<k&&(y=le,k=ve)}const N=y?.dataset.diffSelectionPath??y?.dataset.diffStreamItem??null;return N?(La.current===N&&J.getState().selectedFilePath===N||(La.current=N,ot(N)),N):null},[se,ot]),lm=!!(!ze&&Ee&&!rt&&(ue?.upstream||hn.trim()&&mn.trim())),cm=!!(!ze&&Ee&&!rt&&(ue?.upstream||hn.trim()&&mn.trim())),dm=!!(!ze&&Ee&&!rt&&Gn.trim()&&Gn.trim()!==ue?.branch),Zt=a.useMemo(()=>{const t=Se.trim().toLowerCase(),i=Array.from(Ie.entries()).filter(([,u])=>!ne||xt(u,v)===ne).sort(([u],[w])=>u.localeCompare(w));return t?i.filter(([u,w])=>`${u} ${w.path} ${w.status} ${w.repoRelativeRoot??""} ${w.repoName??""}`.toLowerCase().includes(t)):i},[ne,Ie,Se,v]);a.useEffect(()=>{Ys("selected_file_state",{selectedFilePath:at,selectedChangedFilePath:Jt?.path??null,selectedChangedFileAbsolutePath:Jt?.absolutePath??null,selectedChangedFileRepoRoot:Jt?.repoRoot??null,rootPath:v,activeGitRepoRoot:ne,rightTab:ri,effectiveRightTab:Et,diffPaneActive:Mt,changedFiles:Ie.size,filteredChangedFiles:Zt.length,gitBundleLoading:br,gitBundleLastLoadedAt:Yn})},[ne,Ie.size,Mt,Et,Zt.length,Yn,br,ri,v,Jt?.absolutePath,Jt?.path,Jt?.repoRoot,at]);const _s=a.useMemo(()=>{const t=new Map;for(const i of Zt){const[,u]=i,w=xt(u,v),y=Zx(u)||st,k=w??y,N=w?it.get(w):void 0,le=t.get(k)??{root:w,label:y,branch:N?.context?.branch,files:[]};le.files.push(i),t.set(k,le)}return Array.from(t.values()).sort((i,u)=>i.label===st?-1:u.label===st?1:i.label.localeCompare(u.label))},[Zt,it,st,v]),Bs=a.useMemo(()=>{const t=[],i=new Map;for(const u of Zt)i.set(Sr(u[1]),u);for(const u of _s){if(!!(u.root&&Sl({activeGitRepoRoot:ne,groupCount:_s.length,label:u.label,rootName:st})&&Er.has(u.root)))continue;if(zt!=="tree"){t.push(...u.files);continue}const y=u.files.map(([,k])=>ld(k));for(const k of Dp(y)){const N=i.get(k.key);N&&t.push(N)}}return t},[ne,Er,zt,_s,Zt,st]),md=a.useMemo(()=>Ie.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:o("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:Bs.map(([,t])=>{const i=xt(t,v),u=t.absolutePath||(i?`${i}/${t.path}`:t.path);return{key:Sr(t),path:t.path,absolutePath:u,status:t.status,repoRoot:i,displayName:yo(u,i).name,displayDir:yo(u,i).dir,auditRecords:wt}}),[wt,Ie.size,Bs,v,o]);a.useEffect(()=>{if(!Mt||Bs.length===0||se)return;const t=[],i=()=>{const u=document.querySelector(".termdock-diff-stream-scroller");if(u&&Va(u))return;const w=document.querySelector("[data-diff-stream-item]"),y=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;if(y){La.current=y,ot(y);return}const k=Bs[0]?.[1];if(!k)return;const N=Sr(k);La.current=N,ot(N)};for(const u of[80,240,600,1200])t.push(window.setTimeout(i,u));return()=>t.forEach(u=>window.clearTimeout(u))},[Mt,se,Bs,ot,Va]);const Mi=a.useMemo(()=>{const t=N=>`'${N.replace(/'/g,"'\\''")}'`,i=or.length>0?vn:$.filter(N=>N.files.length>0),u=i.length>0?i:v?[{root:v,relativeRoot:".",name:st}]:[],w=u.length>0?u.map(N=>`- ${N.relativeRoot==="."?".":N.relativeRoot} (${N.root})`).join(`
1666
+ `):`- ${v?".":""}`,y=u.length>0?u.map(N=>` td audit-export ${t(N.root)}`).join(`
1667
1667
  `):" td audit-export",k=u.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${v??""}`,"目标仓库:",w,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",y,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",k,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
1668
- `)},[ar.length,xn,$,st,v]),am=a.useCallback((t="generate")=>{if(Rn&&Lr.length===0&&!ne){tn(!0);return}const i=t==="generate"?Ni:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Ni].join(`
1669
- `);ct("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:ar,mode:t,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Or(o("rightSidebar.insertChangeAuditPrompt"),i,`${Bc}:${t}`),xr(),c||l()},[ne,Ni,Lr.length,ar,Or,xr,l,c,v,Rn,o]),qa=a.useCallback(async t=>{try{await Hd({ids:[t]}),Tt(i=>i.filter(u=>u.id!==t))}catch{xr()}},[xr]),om=a.useCallback(async()=>{if(wt.length===0)return;const t=wt.map(i=>i.id);try{await Hd({ids:t}),Tt(i=>i.filter(u=>!t.includes(u.id))),dr(null)}catch(i){const u=i instanceof Error?i.message:"Failed to clear change audit explanations";dr(o("rightSidebar.changeAuditClearFailed",{message:u})),xr()}},[wt,xr,o]),im=a.useCallback(async t=>{if(t.records.length===0)return;const i=t.records.map(u=>u.id);try{await tp({ids:i}),rn(u=>u.filter(w=>!i.includes(w.id))),Ze===t.key&&(ln(null),Gt(!1))}catch(u){qt(o("rightSidebar.branchAuditClearFailed",{message:u instanceof Error?u.message:"Failed to clear branch explanation"})),La(null)}},[La,Ze,o]),lm=a.useCallback(t=>{Pr(i=>t===null?(tn(!1),[]):i.includes(t)?i.filter(u=>u!==t):[...i,t])},[]),cm=a.useCallback(t=>{Uo(i=>t===null?(Oo(!1),[]):i.includes(t)?i.filter(u=>u!==t):[...i,t])},[]),Ei=a.useMemo(()=>{if(!sr)return[];const t=i=>{const u=i.diff??"";let w=0,y=0;for(const k of u.split(`
1670
- `))k.startsWith("+++")||k.startsWith("---")||(k.startsWith("+")&&(w+=1),k.startsWith("-")&&(y+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:w,deletions:y,diff:u}};return we?(we.hunks??[]).map(i=>{const u=we.comparisonRepos&&we.comparisonRepos.length>1?[...we.comparisonRepos].sort((y,k)=>k.label.length-y.label.length).find(y=>i.filePath.startsWith(`${y.label}/`)):void 0,w=ur.find(y=>y.repoRoot===we.repoRoot&&y.baseRef===we.baseRef&&(y.branchName??null)===(we.currentBranch??null)&&y.filePath===i.filePath&&y.hunkHeader===i.hunkHeader&&(y.hunkIndex??0)===i.hunkIndex&&y.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,repoRoot:u?.repoRoot??we.repoRoot,repositoryPath:u?i.filePath.slice(u.label.length+1):i.filePath,hunk:i.previewRevert&&!as(i.previewRevert.cwd,i.previewRevert.comparisonBranch)?{...i,previewRevert:void 0}:i,current:w,stale:null}}):Ze?ur.filter(i=>Nu(i)===Ze).map(i=>{const u=t(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:u,current:i,stale:null}}):[]},[we,ur,as,sr,Ze]),Mi=ur.length>0,os=a.useMemo(()=>{if(!sr)return[];const t=new Map;for(const i of ur){const u=i.repoRoot,w=it.get(u),y=w?.relativeRoot==="."?st:w?.relativeRoot||w?.name||jt(u),k=Nu(i),C=t.get(k)??{key:k,repoRoot:u,repoLabel:y,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};C.records.push(i),C.latestInjectedAt=Math.max(C.latestInjectedAt,i.injectedAt??0),t.set(k,C)}return Array.from(t.values()).sort((i,u)=>u.latestInjectedAt-i.latestInjectedAt)},[ur,it,sr,st]),$i=a.useMemo(()=>Ze?os.find(t=>t.key===Ze)??null:null,[os,Ze]),Bs=we?{repoRoot:we.repoRoot??"",repoLabel:we.repoRoot?it.get(we.repoRoot)?.relativeRoot==="."?st:it.get(we.repoRoot)?.relativeRoot||it.get(we.repoRoot)?.name||jt(we.repoRoot):st,baseRef:we.baseRef??we.baseBranch??"",branchName:we.currentBranch??null,headRef:we.headRef??null,diffFingerprint:we.diffFingerprint??null}:$i,dm=a.useMemo(()=>(We?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,repoRoot:We?.repoRoot,hunk:t,current:null,stale:null})),[We?.hunks,We?.repoRoot]),um=a.useMemo(()=>{if(we)return[];const t=$i;return t?Tn.filter(i=>i.repoRoot===t.repoRoot&&i.baseRef===t.baseRef&&(i.branchName??null)===t.branchName&&(!t.diffFingerprint||i.diffFingerprint===t.diffFingerprint)):[]},[we,Tn,$i]),fm=a.useCallback(t=>{const i=Ei.find(u=>u.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${u.hunk.filePath}`===t.filePath:!1));i&&(cn(i.key),window.setTimeout(()=>En(t),90),window.setTimeout(()=>En(t),320),window.setTimeout(()=>En(t),760))},[Ei]),Li=a.useMemo(()=>{const t=y=>`'${y.replace(/'/g,"'\\''")}'`,i=Is,u=i.length>0?i.map(y=>`- ${y.label} (${y.root}),目标分支:${nr[y.root]||y.branch||"(current branch)"},基线分支:${Nt[y.root]||"(not set)"},包含本地未提交更改:${as(y.root,nr[y.root]||y.branch)&&(on[y.root]??!0)?"是":"否"}`).join(`
1671
- `):`- ${v?".":""}`,w=i.length>0?i.map(y=>{const k=nr[y.root]||y.branch||"",C=Nt[y.root]||"",le=y.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[k?` git -C ${t(y.root)} switch ${t(k)}`:` # ${y.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(C)} ${t(y.root)} > ~/.termdock/branch-audit/branch-audit-export-${le}.json`].join(`
1668
+ `)},[or.length,vn,$,st,v]),um=a.useCallback((t="generate")=>{if(Nn&&Pr.length===0&&!ne){rn(!0);return}const i=t==="generate"?Mi:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Mi].join(`
1669
+ `);ct("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:or,mode:t,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Ur(o("rightSidebar.insertChangeAuditPrompt"),i,`${Hc}:${t}`),vr(),c||l()},[ne,Mi,Pr.length,or,Ur,vr,l,c,v,Nn,o]),Ya=a.useCallback(async t=>{try{await Gd({ids:[t]}),Tt(i=>i.filter(u=>u.id!==t))}catch{vr()}},[vr]),fm=a.useCallback(async()=>{if(wt.length===0)return;const t=wt.map(i=>i.id);try{await Gd({ids:t}),Tt(i=>i.filter(u=>!t.includes(u.id))),ur(null)}catch(i){const u=i instanceof Error?i.message:"Failed to clear change audit explanations";ur(o("rightSidebar.changeAuditClearFailed",{message:u})),vr()}},[wt,vr,o]),hm=a.useCallback(async t=>{if(t.records.length===0)return;const i=t.records.map(u=>u.id);try{await ip({ids:i}),nn(u=>u.filter(w=>!i.includes(w.id))),Ze===t.key&&(cn(null),Kt(!1))}catch(u){Vt(o("rightSidebar.branchAuditClearFailed",{message:u instanceof Error?u.message:"Failed to clear branch explanation"})),Aa(null)}},[Aa,Ze,o]),mm=a.useCallback(t=>{Ar(i=>t===null?(rn(!1),[]):i.includes(t)?i.filter(u=>u!==t):[...i,t])},[]),pm=a.useCallback(t=>{Ho(i=>t===null?(Uo(!1),[]):i.includes(t)?i.filter(u=>u!==t):[...i,t])},[]),$i=a.useMemo(()=>{if(!ar)return[];const t=i=>{const u=i.diff??"";let w=0,y=0;for(const k of u.split(`
1670
+ `))k.startsWith("+++")||k.startsWith("---")||(k.startsWith("+")&&(w+=1),k.startsWith("-")&&(y+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:w,deletions:y,diff:u}};return we?(we.hunks??[]).map(i=>{const u=we.comparisonRepos&&we.comparisonRepos.length>1?[...we.comparisonRepos].sort((y,k)=>k.label.length-y.label.length).find(y=>i.filePath.startsWith(`${y.label}/`)):void 0,w=fr.find(y=>y.repoRoot===we.repoRoot&&y.baseRef===we.baseRef&&(y.branchName??null)===(we.currentBranch??null)&&y.filePath===i.filePath&&y.hunkHeader===i.hunkHeader&&(y.hunkIndex??0)===i.hunkIndex&&y.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,repoRoot:u?.repoRoot??we.repoRoot,repositoryPath:u?i.filePath.slice(u.label.length+1):i.filePath,hunk:i.previewRevert&&!os(i.previewRevert.cwd,i.previewRevert.comparisonBranch)?{...i,previewRevert:void 0}:i,current:w,stale:null}}):Ze?fr.filter(i=>Pu(i)===Ze).map(i=>{const u=t(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:u,current:i,stale:null}}):[]},[we,fr,os,ar,Ze]),Li=fr.length>0,is=a.useMemo(()=>{if(!ar)return[];const t=new Map;for(const i of fr){const u=i.repoRoot,w=it.get(u),y=w?.relativeRoot==="."?st:w?.relativeRoot||w?.name||jt(u),k=Pu(i),N=t.get(k)??{key:k,repoRoot:u,repoLabel:y,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};N.records.push(i),N.latestInjectedAt=Math.max(N.latestInjectedAt,i.injectedAt??0),t.set(k,N)}return Array.from(t.values()).sort((i,u)=>u.latestInjectedAt-i.latestInjectedAt)},[fr,it,ar,st]),Pi=a.useMemo(()=>Ze?is.find(t=>t.key===Ze)??null:null,[is,Ze]),Os=we?{repoRoot:we.repoRoot??"",repoLabel:we.repoRoot?it.get(we.repoRoot)?.relativeRoot==="."?st:it.get(we.repoRoot)?.relativeRoot||it.get(we.repoRoot)?.name||jt(we.repoRoot):st,baseRef:we.baseRef??we.baseBranch??"",branchName:we.currentBranch??null,headRef:we.headRef??null,diffFingerprint:we.diffFingerprint??null}:Pi,gm=a.useMemo(()=>(We?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,repoRoot:We?.repoRoot,hunk:t,current:null,stale:null})),[We?.hunks,We?.repoRoot]),bm=a.useMemo(()=>{if(we)return[];const t=Pi;return t?In.filter(i=>i.repoRoot===t.repoRoot&&i.baseRef===t.baseRef&&(i.branchName??null)===t.branchName&&(!t.diffFingerprint||i.diffFingerprint===t.diffFingerprint)):[]},[we,In,Pi]),xm=a.useCallback(t=>{const i=$i.find(u=>u.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${u.hunk.filePath}`===t.filePath:!1));i&&(dn(i.key),window.setTimeout(()=>Mn(t),90),window.setTimeout(()=>Mn(t),320),window.setTimeout(()=>Mn(t),760))},[$i]),Ai=a.useMemo(()=>{const t=y=>`'${y.replace(/'/g,"'\\''")}'`,i=Ds,u=i.length>0?i.map(y=>`- ${y.label} (${y.root}),目标分支:${sr[y.root]||y.branch||"(current branch)"},基线分支:${Ct[y.root]||"(not set)"},包含本地未提交更改:${os(y.root,sr[y.root]||y.branch)&&(ln[y.root]??!0)?"是":"否"}`).join(`
1671
+ `):`- ${v?".":""}`,w=i.length>0?i.map(y=>{const k=sr[y.root]||y.branch||"",N=Ct[y.root]||"",le=y.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[k?` git -C ${t(y.root)} switch ${t(k)}`:` # ${y.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(N)} ${t(y.root)} > ~/.termdock/branch-audit/branch-audit-export-${le}.json`].join(`
1672
1672
  `)}).join(`
1673
1673
  `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${v??""}`,"每个仓库分别遵循下面列出的本地未提交更改选项。","目标仓库:",u,"","操作指令:","1. 只针对上面列出的目标仓库导出分支 hunk,按各仓库所选目标分支与基线对比。本地未提交更改标记为是的仓库纳入 staged/unstaged/untracked 改动;标记为否的仓库只解释提交改动,忽略导出中混入的本地改动。嵌套子仓或软链接子仓使用括号内的仓库绝对路径。示例:",w,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:v??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
1674
- `)},[on,as,Is,Nt,nr,v]),hm=a.useCallback((t="generate")=>{const i=t==="generate"?Li:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",Li].join(`
1675
- `);Or(o("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${t}`),c||l()},[Li,Or,l,c,o]),Pi=a.useCallback(async(t={})=>{const i=t.refresh===!0,u=i&&we?.comparisonRepos?we.comparisonRepos:Is.map(C=>{const le=(nr[C.root]||C.branch||"").trim();return{repoRoot:C.root,label:C.label,base:Nt[C.root]?.trim()??"",head:le||null,includeUncommitted:on[C.root]??!0}});if(!v||u.length===0)return;const w=++It.current,y=v,k=()=>Me(y)&&w===It.current;K(!0),ke(null),i||(rr(null),Ue(null));try{const C=await Promise.all(u.map(async Z=>{if(!Z.base)throw new Error(o("rightSidebar.branchAuditMissingBase",{repo:Z.label}));return zd({cwd:v,repoRoot:Z.repoRoot,base:Z.base,head:Z.head,includeUncommitted:t.repoRoot===Z.repoRoot?t.includeUncommitted??!1:Z.includeUncommitted??we?.includeUncommitted??!0,requestSlotId:`right-sidebar-branch-preview:${Z.repoRoot}`})}));if(!k())return;const le=C.find(Z=>!Z.available);if(le){ke(le.error??"Branch diff is unavailable");return}const ae=C.length===1?C[0]:{available:!0,workspaceRoot:v,repoRoot:v,baseRef:C.map(Z=>Z.baseRef??Z.baseBranch).filter(Boolean).join(", "),currentBranch:C.map(Z=>Z.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:C.map(Z=>Z.headRef).filter(Boolean).join(", "),diffFingerprint:C.map(Z=>Z.diffFingerprint).filter(Boolean).join("+"),stat:C.map(Z=>Z.stat).filter(Boolean).join(`
1676
- `),files:C.flatMap((Z,Y)=>{const pe=u[Y];return(Z.files??[]).map(Ae=>`${pe?.label??Z.repoRoot??"repo"}/${Ae}`)}),hunks:C.flatMap((Z,Y)=>{const Ae=u[Y]?.label??Z.repoRoot??"repo";return(Z.hunks??[]).map(Ve=>({...Ve,filePath:`${Ae}/${Ve.filePath}`,oldPath:Ve.oldPath?`${Ae}/${Ve.oldPath}`:Ve.oldPath,newPath:Ve.newPath?`${Ae}/${Ve.newPath}`:Ve.newPath}))}),commits:C.flatMap(Z=>Z.commits??[]),commitCount:C.reduce((Z,Y)=>Z+(Y.commitCount??Y.commits?.length??0),0),diff:C.map(Z=>Z.diff).filter(Boolean).join(`
1677
- `),truncated:C.some(Z=>Z.truncated)};if(ae.comparisonRepos=u.map((Z,Y)=>({...Z,head:Z.head??C[Y].currentBranch??null,includeUncommitted:C[Y].includeUncommitted===!0,canIncludeUncommitted:C[Y].canIncludeUncommitted})),ae.canIncludeUncommitted=C.every(Z=>Z.canIncludeUncommitted===!0),ae.includeUncommitted=C.some(Z=>Z.includeUncommitted===!0),Ho(Z=>({...Z,...Object.fromEntries(ae.comparisonRepos.map(Y=>[Y.repoRoot,Y.includeUncommitted??!1]))})),!i&&(ae.hunks??[]).length===0){ke(o("rightSidebar.branchAuditDiffEmpty"));return}const ve=Date.now(),Pe=(i?Ze:null)??["preview",ae.repoRoot??v,ae.baseRef??ae.baseBranch??"",ae.currentBranch??"",ae.headRef??"",ae.diffFingerprint??ve].join("\0"),et=u.length===1?u[0].label:`${u.length} repos`;rr(ae),Dn(Z=>[{key:Pe,diff:ae,repoLabel:et,createdAt:ve},...Z.filter(Y=>Y.key!==Pe)].slice(0,8)),i||Fn(Z=>Z[Pe]===void 0?Z:{...Z,[Pe]:0}),ln(Pe),cn(Z=>{const Y=ae.hunks?.[0],pe=Y?`${Y.filePath}\0${Y.hunkHeader}\0${Y.hunkIndex}`:null;return i&&Z&&(ae.hunks??[]).some(Ae=>Ae.filePath===Z.split("\0")[0])?Z:pe}),Gt(!0)}catch(C){if(!k()||Sr(C))return;ke(C instanceof Error?C.message:"Failed to load branch diff")}finally{k()&&K(!1)}},[on,we,Ze,Is,Nt,nr,Me,v,o]),mm=a.useCallback(t=>{++It.current,K(!1),rr(t.diff),ke(null),ln(t.key),cn(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),Gt(!0)},[]),pm=a.useCallback(t=>{Dn(i=>i.filter(u=>u.key!==t)),Fn(i=>{if(!(t in i))return i;const u={...i};return delete u[t],u}),Ze===t&&(ln(null),rr(null),Gt(!1))},[Ze]),gm=a.useCallback(t=>{++It.current,K(!1);const i=os.find(u=>u.key===t);i&&(rr(null),ke(null),ln(t),cn(i.records[0]?.filePath??null),Gt(!0))},[os]),bm=a.useCallback(async t=>{if(!v||!Ee)return;const[i]=t.split(/\s+/);if(i){Ge(i),bt(null),Ue(null);try{const u=await rp({cwd:v,repoRoot:Ee,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!u.available){bt(u.error??"Commit diff is unavailable");return}Ue(u);const w=u.hunks?.[0];fa(w?`${w.filePath}\0${w.hunkHeader}\0${w.hunkIndex}`:null)}catch(u){bt(u instanceof Error?u.message:"Failed to load commit diff")}finally{Ge(null)}}},[Ee,v]),xm=a.useCallback(t=>{if(!we||!Ze)return;const i=Math.max(0,Math.round(t));Fn(u=>Math.abs((u[Ze]??0)-i)<24?u:{...u,[Ze]:i})},[we,Ze]);a.useEffect(()=>{!we||!Ze||Dn(t=>t.map(i=>i.key===Ze&&i.diff!==we?{...i,diff:we}:i))},[we,Ze]);const fd=!!we;a.useEffect(()=>{if(!se||!Wt||!fd)return;const t=jc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const i=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(i)},[Wt,fd,se]);const hd=a.useCallback(t=>{t&&Eh(i=>Ap(i,t))},[]),md=Sa.key===at?Sa.key:null,Va=a.useCallback(t=>{const i=Q.getState(),u=l0();Vs("select_diff_file",{interactionId:u,path:t,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ne,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),ot(t),pr("diff"),se&&t&&Nc(1),hd(t),queueMicrotask(()=>{const w=Q.getState();Vs("select_diff_file_after",{interactionId:u,requestedPath:t,selectedFilePath:w.selectedFilePath,rootPath:w.rootPath,rightTab:w.rightTab,changedFiles:w.changedFiles.size,activeGitRepoRoot:ne})})},[ne,se,hd,ot,pr,Nc]),pd=a.useCallback(t=>{const i=Array.from(Ie.values()).find(u=>{const w=xt(u,v),y=kr(u);return u.path===t.filePath||y===t.filePath||u.absolutePath===t.filePath||(w?`${w}/${u.path}`===t.filePath:!1)||t.repoRoot&&w===t.repoRoot&&u.path===t.filePath});if(i){Va(kr(i)),window.setTimeout(()=>En(t),90),window.setTimeout(()=>En(t),320),window.setTimeout(()=>En(t),760);return}En(t)},[Ie,v,Va]),gd=a.useCallback(({slideToDetail:t,fullscreen:i,toggleFullscreen:u}={})=>ps.length>0?e.jsx(tf,{walkthroughs:ps,repoRoot:ne,fullscreen:i,onToggleFullscreen:u,onNavigate:w=>{se&&window.requestAnimationFrame(()=>t?.()),pd(w)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(na,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),o("rightSidebar.changeWalkthroughEmpty")]}),[ne,ps,pd,se,o]),vm=a.useCallback(t=>{t&&la(i=>{const u=new Set(i);return u.has(t)?u.delete(t):u.add(t),Qi(Vi,u),u})},[]),bd=a.useCallback(t=>{Er(i=>{const u=new Set(i);return u.has(t)?u.delete(t):u.add(t),Qi(bu,u),u})},[]),Ya=a.useCallback(t=>{Ur(t),Lt(wf,t)},[]);a.useEffect(()=>{Ha||Ht!=="ai"||Ya("tree")},[Ht,Ya,Ha]);const Xa=a.useCallback(()=>{Mr(t=>{const i=!t;return Lt(kf,i),i})},[]),xd=a.useCallback(t=>{ca(t),Lt(Sf,t)},[]),{whitespace:vd,context:yd}=Ip(),wd=a.useMemo(()=>({algorithm:"histogram",whitespace:vd,context:yd}),[vd,yd]),kd=a.useCallback(t=>{X(t),Lt(jf,t)},[]),Ja=a.useCallback(async(t,i,u,w)=>{let y=t;for(;y.ok&&y.status==="running";)await new Promise(C=>window.setTimeout(C,1500)),y=await Wd({jobId:y.jobId,cwd:i.cwd,action:i.action});if(!y.ok)throw new Error("Git action status is unavailable");if(y.status==="error")throw new Error(y.error||y.message||"Git action failed");const k={action:i.action,path:w,label:u};return js(k),window.setTimeout(()=>js(C=>C?.action===k.action&&C.path===k.path?null:C),1400),y},[]),St=a.useCallback(async(t,i,u)=>{const w=v;v&&br.current.delete(v),qt(null),js(null),Ss({action:t.action,path:u});try{const y=await np({...t,includeNested:Ws(v)}),k=await Ja(y,t,i,u);if(!Me(w))return!1;const C=v?await Ui(v,void 0,{includeNested:Ws(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Ks(v)}).catch(()=>k.bundle):k.bundle;return Me(w)?(C&&Zn(C,{reloadDiff:!0,cacheOnly:!0}),dn(null),!0):!1}catch(y){return js(null),qt(o("rightSidebar.gitActionFailed",{message:y instanceof Error?y.message:"Unknown error"})),!1}finally{Me(w)&&Ss(null)}},[Zn,Me,v,o,Ja]),Sd=a.useCallback(async t=>{const i=v;await Gd({...t,includeNested:Ws(v)}),Me(i)&&Ft(v??void 0,{refresh:!0,background:!0})},[Me,Ft,v]),ym=a.useCallback(async t=>{const i=we,u=It.current,w=i?.hunks?.find(k=>k.previewRevert?.cwd===t.cwd&&k.previewRevert.path===t.path);if(!i||!w||!t.comparisonBase)throw new Error(o("diffViewer.hunkActionUnavailable"));_n(k=>k+1),ke(null);try{await Gd(t)}catch(k){throw _n(C=>C-1),k}if(u!==It.current||!Me(v)){_n(k=>k-1);return}const y=k=>{rr(C=>{if(!C||u!==It.current)return C;const le=C.hunks??[],ae=k===void 0?le.filter(Pe=>!(Pe.previewRevert?.cwd===t.cwd&&Pe.previewRevert.patch===t.patch)):[...le.filter(Pe=>Pe.filePath!==w.filePath),...k];return{...C,hunks:ae}})};y(),zd({cwd:t.cwd,repoRoot:t.cwd,base:t.comparisonBase,comparisonBase:t.comparisonBase,filePath:t.path,requestSlotId:`branch-preview-file:${t.cwd}:${t.path}`}).then(k=>{if(u!==It.current||!Me(v))return;if(!k.available||k.truncated)throw new Error(k.error??o("diffViewer.hunkActionUnavailable"));const C=t.path.slice(t.cwd.length+1),le=w.filePath.slice(0,w.filePath.length-C.length);y((k.hunks??[]).map(ae=>({...ae,filePath:`${le}${ae.filePath}`,oldPath:ae.oldPath?`${le}${ae.oldPath}`:ae.oldPath,newPath:ae.newPath?`${le}${ae.newPath}`:ae.newPath})))}).catch(k=>{u===It.current&&Me(v)&&!Sr(k)&&ke(`${o("diffViewer.hunkActionReverted")} · ${k instanceof Error?k.message:String(k)}`)}).finally(()=>_n(k=>k-1))},[we,Me,v,o]),Qa=a.useCallback((t,i,u)=>{if(i){if(t==="stage-all"){St({action:"stage-all",cwd:i},o("rightSidebar.stageAll"),`repo:${i}`);return}dn({kind:"stash-all",repoRoot:i,repoLabel:u})}},[St,o]),jd=a.useCallback(t=>{Ye(t),ya(""),wa(""),ka(""),ot(Xc(t)),lt||pr("diff"),t&&Oa(it.get(t))},[Oa,Xc,lt,it,ot,Ye,pr]),Rd=a.useCallback(t=>{const i=new Set([...Yt.current.keys(),...gn.current,...br.current]);for(const u of i)u!==t&&(Vt.current.delete(u),Yt.current.get(u)?.abort(),Yt.current.delete(u),Ct(`right-sidebar-git-untracked:${u}`),gn.current.delete(u),br.current.delete(u))},[]),wm=a.useCallback(async t=>{const i=v;if(!i||(await Q.getState().setNestedGitScanRoot(i,t),!Me(i)))return;if(t){await Ft(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Rd(i),ya(""),wa(""),ka(""),Uo(w=>w.filter(y=>y===i));const u=Xt;u&&xt(u,i)!==i&&ot(null),await Ft(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Rd,Me,Ft,v,ot,Xt]),km=a.useCallback(async()=>{if(!Ee||rt){qt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=Wn.trim();!t||t===ue?.branch||await St({action:"switch-branch",cwd:Ee,branch:t},o("rightSidebar.switchBranch"))},[ue?.branch,Ee,rt,St,Wn,o]),Cd=a.useCallback(async()=>{if(!Ee||rt){qt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=va.trim();if(!t)return;await St({action:"commit",cwd:Ee,message:t},o("rightSidebar.commitChanges"))&&ec("")},[Ee,va,rt,St,o]),Sm=a.useCallback(async()=>{if(!Ee||rt){qt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=fn.trim(),i=hn.trim();await St({action:"push",cwd:Ee,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pushChanges"))},[Ee,hn,fn,rt,St,o]),jm=a.useCallback(async()=>{if(!Ee||rt){qt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=fn.trim(),i=hn.trim();await St({action:"pull",cwd:Ee,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pullChanges"))},[Ee,hn,fn,rt,St,o]);a.useEffect(()=>{if(!lt||!Ee||ze)return;let t=!1;const i={push:o("rightSidebar.pushChanges"),pull:o("rightSidebar.pullChanges"),commit:o("rightSidebar.commitChanges"),"switch-branch":o("rightSidebar.switchBranch"),"stage-all":o("rightSidebar.stageAll"),"stash-all":o("rightSidebar.stashAll")};return(async()=>{for(const u of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const w=await Wd({cwd:Ee,action:u}).catch(()=>null);if(!w?.ok||w.status!=="running")continue;const y={action:u,cwd:Ee},k=i[u]??u;Ss({action:u});try{const C=await Ja(w,y,k);if(t||!Me(v))return;const le=v?await Ui(v,void 0,{includeNested:Ws(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Ks(v)}).catch(()=>C.bundle):C.bundle;le&&Zn(le,{reloadDiff:!0,cacheOnly:!0})}catch(C){t||qt(o("rightSidebar.gitActionFailed",{message:C instanceof Error?C.message:"Unknown error"}))}finally{t||Ss(null)}return}})(),()=>{t=!0}},[Ee,Zn,lt,Me,v,ze,o,Ja]);const Ai=Hn?.action==="commit",Ti=Hn?.action==="switch-branch",Ii=Hn?.action==="pull",Di=Hn?.action==="push",Za=lt||Ch,Fi=Wa?o("rightSidebar.changeAuditScopeAll"):yr.length===1?yr[0].label:`${yr.length} repos`,Rm=yr.length>0,Nd=Is.length>0,Cm=v?e.jsx(Tu,{open:Bo,onOpenChange:Oo,showScopePicker:!0,selectedAll:Wa,repos:Jt,selectedRoots:za,onToggleRepo:cm,onGenerate:()=>hm(Mi?"regenerate":"generate"),disabled:!Rm,generateDisabled:!Nd,inserted:Te?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:o(Mi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.branchAuditGenerateTitle"),ariaLabel:o("rightSidebar.branchAuditShort"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Fi,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o(Mi?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Pi()},secondaryDisabled:!Nd||A,secondaryLabel:o("rightSidebar.branchAuditViewDiff"),secondaryTitle:o("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:A,loading:ql.size>0,statusTitle:ql.size>0?o("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:td.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:o("rightSidebar.missingBaseReposSkipped",{repositories:td.map(t=>t.label).join(_==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const i=it.get(t.root),u=as(t.root,nr[t.root]||i?.context?.branch),w=[],y=new Set,k=(ve,Pe)=>{!ve||y.has(ve)||(y.add(ve),w.push({value:ve,label:ve,meta:Pe}))};k(nr[t.root]||i?.context?.branch,o("rightSidebar.pushCurrentBranchBadge"));for(const ve of i?.context?.branches??[])k(ve,ve===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):o("rightSidebar.localBranch"));for(const ve of i?.context?.remoteBranches??[])k(ve,o("rightSidebar.remoteBranch"));const C=[],le=new Set,ae=(ve,Pe)=>{!ve||le.has(ve)||(le.add(ve),C.push({value:ve,label:ve,meta:Pe}))};ae(Nt[t.root],Nt[t.root]?o("rightSidebar.pushUpstreamBadge"):void 0),ae(i?.context?.upstream,i?.context?.upstream?o("rightSidebar.pushUpstreamBadge"):void 0);for(const ve of i?.context?.remoteBranches??[])ae(ve,"remote");for(const ve of i?.context?.branches??[])ae(ve,ve===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(us,{label:o("rightSidebar.currentBranchLabel"),value:nr[t.root]||i?.context?.branch||"",options:w,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),onChange:ve=>{ma(Pe=>({...Pe,[t.root]:ve}))}}),e.jsx(us,{label:o("rightSidebar.branchAuditBaseLabel"),value:Nt[t.root]||"",options:C,placeholder:o("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:o("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:o("rightSidebar.branchAuditBaseEmpty"),onChange:ve=>{pa(Pe=>({...Pe,[t.root]:ve}))}}),e.jsxs("label",{className:"sm:col-span-2 flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:o("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:o(u?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:u&&(on[t.root]??!0),disabled:!u,onChange:ve=>Ho(Pe=>({...Pe,[t.root]:ve.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,Ed=qs(wt.reduce((t,i)=>Math.max(t,i.injectedAt??0),0),_),Nm=()=>v?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Kl(t=>{const i=!t;return Lt(Yi,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":ks,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(na,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Fi})]}),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 ${ks?"rotate-90":""}`,children:e.jsx(fs,{size:13})})]}),ks&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[o("rightSidebar.changeAuditScopeLabel"),": ",Fi]}),Cm]}),be&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:be}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[nn.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>mm(t),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:o("rightSidebar.branchAuditViewDiff")})]}),qs(t.createdAt,_)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:qs(t.createdAt,_)})]}),e.jsx("button",{type:"button",onClick:()=>pm(t.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:o("common.delete"),"aria-label":o("common.delete"),children:e.jsx(po,{size:12})})]},t.key)),os.length>0?os.slice(0,Math.max(0,8-nn.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>gm(t.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),qs(t.latestInjectedAt,_)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:o("rightSidebar.branchAuditGeneratedAt",{time:qs(t.latestInjectedAt,_)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{im(t)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:o("rightSidebar.branchAuditClearTitle"),"aria-label":o("rightSidebar.branchAuditClearTitle"),children:e.jsx(po,{size:12})})]},t.key)):nn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Em=()=>sr&&v&&jn?e.jsxs("div",{className:Za?"overflow-visible":"overflow-hidden",children:[Nm(),e.jsxs("button",{type:"button",onClick:()=>{lt||Nh(t=>{const i=!t;return i&&Ee&&!jn&&!un&&hi(Ee),i})},"aria-expanded":Za,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${lt?"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(wr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${Sn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[un&&e.jsx(dt,{size:10,className:"animate-spin"}),Sn.staged>0?o("rightSidebar.stagedCount",{count:Sn.staged}):o("rightSidebar.noStagedChangesShort")]}),!lt&&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 ${Za?"rotate-90":""}`,children:e.jsx(fs,{size:13})})]})]}),Za&&e.jsxs("div",{className:"space-y-0",children:[Ut.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Vh})]})}),e.jsx(us,{label:o("rightSidebar.gitRepositoryLabel"),value:Ee??"",options:Ut,placeholder:o("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:o("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:o("rightSidebar.gitRepositoryEmpty"),disabled:!!ze,onChange:t=>{jd(t||null)}}),rt&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:o("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Wn!==Vc?Vc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{km()},disabled:!sm,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 ${Ti?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.switchBranch"),children:[e.jsx("span",{className:ze?.action==="switch-branch"||Ti?"opacity-0":"",children:o("rightSidebar.switchBranch")}),ze?.action==="switch-branch"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Ti&&ze?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(us,{label:o("rightSidebar.currentBranchLabel"),value:Wn,options:Jh,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),disabled:!!ze,onChange:ya})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:rt?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged>0?o("rightSidebar.commitReadyHint",{count:Sn.staged}):o("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Cd()},disabled:!!ze||rt||Sn.staged===0||!va.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 ${Ai?"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:rt?o("rightSidebar.selectRepositoryForGitActions"):Sn.staged===0?o("rightSidebar.commitNeedsStaged"):o("rightSidebar.commitChanges"),children:[e.jsx("span",{className:ze?.action==="commit"||Ai?"opacity-0":"",children:o("rightSidebar.commitChanges")}),ze?.action==="commit"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Ai&&ze?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:va,onChange:t=>ec(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),Cd())},placeholder:o("rightSidebar.commitMessagePlaceholder"),disabled:!!ze,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Ar(t=>!t),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":fr,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:o("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[re&&e.jsx(dt,{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 ${fr?"rotate-90":""}`,children:e.jsx(fs,{size:13})})]})]}),fr&&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(hs,{size:12,className:"shrink-0"}),e.jsx("input",{value:Bn,onChange:t=>sn(t.target.value),placeholder:o("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),Bn&&e.jsx("button",{type:"button",onClick:()=>sn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Yh,children:[an.length>0?an.map(t=>{const[i,...u]=t.split(/\s+/),w=u.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{bm(t)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:w,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:w,children:w}),hr[i]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${hr[i]==="ahead"?"bg-accent/10 text-accent":hr[i]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:o(hr[i]==="ahead"?"rightSidebar.commitAhead":hr[i]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),tt===i&&e.jsx(dt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):re?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:o("common.loading")}):Fo?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.recentCommitsEmpty")}),Kt&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(dt,{size:12,className:"animate-spin"})}),_o&&!Kt&&an.length>0&&e.jsx("button",{type:"button",onClick:()=>{Ts({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:o("rightSidebar.recentCommitsLoadMore")})]})]}),ht&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ht}),Fo&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Fo})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{jm()},disabled:!rm,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 ${Ii?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pullChanges"),children:[e.jsx("span",{className:ze?.action==="pull"||Ii?"opacity-0":"",children:o("rightSidebar.pullChanges")}),ze?.action==="pull"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Ii&&ze?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Sm()},disabled:!nm,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 ${Di?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pushChanges"),children:[e.jsx("span",{className:ze?.action==="push"||Di?"opacity-0":"",children:o("rightSidebar.pushChanges")}),ze?.action==="push"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Di&&ze?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${nd.className}`,title:ue?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:nd.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ue?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${ed?"grid-cols-2":"grid-cols-1"}`,children:[ed&&e.jsx(us,{label:o("rightSidebar.pushRemoteLabel"),value:fn,options:Zc,placeholder:o("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:o("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:o("rightSidebar.pushNoRemotes"),disabled:!!ze,onChange:wa}),e.jsx(us,{label:o("rightSidebar.pushBranchLabel"),value:hn,options:Qh,placeholder:o("rightSidebar.pushBranchPlaceholder",{branch:ue?.branch??"HEAD"}),searchPlaceholder:o("rightSidebar.pushBranchSearchPlaceholder"),emptyText:o("rightSidebar.pushNoBranches"),disabled:!!ze,onChange:ka})]})]})]})]}):null,Mm=a.useCallback(t=>{const i=xt(t,v);if(!i)return[];const u=al(t),w=[];return t.canStage&&w.push({key:"stage-file",label:o("rightSidebar.stageFile"),onClick:()=>{St({action:"stage-file",cwd:i,paths:[t.path]},o("rightSidebar.stageFile"),u)}}),t.canUnstage&&w.push({key:"unstage-file",label:o("rightSidebar.unstageFile"),onClick:()=>{St({action:"unstage-file",cwd:i,paths:[t.path]},o("rightSidebar.unstageFile"),u)}}),t.canStash&&w.push({key:"stash-file",label:o("rightSidebar.stashFile"),onClick:()=>{St({action:"stash-file",cwd:i,paths:[t.path]},o("rightSidebar.stashFile"),u)}}),t.canRestoreWorktree&&w.push({key:"restore-worktree-file",label:o("rightSidebar.restoreFile"),destructive:!0,onClick:()=>dn({kind:"restore",file:t,phrase:""})}),w},[v,St,o]),$m=a.useCallback(()=>{if(f){h?.();return}Dr(0),_r.current?.slideTo(0),Ir(!1),gt(null)},[h,f]),Md=a.useCallback(t=>{if(V(""),Dt(t),ot(null),gt(null),O(null),se){f&&h?.(),Dr(0),_r.current?.slideTo(0),Ir(!1);return}},[se,h,f,ot,Dt]);a.useEffect(()=>{const t=i=>{const u=i.detail,w=u?.path;if(typeof w!="string"||!w.startsWith("/"))return;V(""),gt(null),Cr(null);const y=!!(v&&(w===v||w.startsWith(`${v}/`)));if(u.kind==="file"){const k=ho(w);Ms(w),typeof u.line=="number"&&Number.isSafeInteger(u.line)&&u.line>0&&Cr(u.line),Dt(y?null:k),O(C=>({path:w,nonce:(C?.nonce??0)+1}));return}ot(null),y?(Dt(null),O(k=>({path:w,nonce:(k?.nonce??0)+1}))):(O(null),Dt(w)),se&&(f&&h?.(),Dr(0),_r.current?.slideTo(0),Ir(!1))};return window.addEventListener(Yd,t),()=>window.removeEventListener(Yd,t)},[Ms,se,h,f,v,ot,Dt]),a.useEffect(()=>{r||(yt(!1),tr(!1))},[r]),a.useEffect(()=>{if(!er&&!cr)return;const t=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&($n.current?.contains(i.target)||Ln.current?.contains(i.target))||(yt(!1),tr(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[cr,er]);const $d=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:Gh,disabled:!_a,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.parentFolder"),title:o("rightSidebar.parentFolder"),children:e.jsx(Ll,{size:14})}),e.jsx("button",{type:"button",onClick:Oc,disabled:!v||Kn===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.backToProjectRoot"),title:o("rightSidebar.backToProjectRoot"),children:e.jsx(Xd,{size:14})}),e.jsx("button",{type:"button",onClick:Kh,disabled:!ie,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.refreshFiles"),title:tc?o("rightSidebar.fileWatchUnavailable",{message:tc}):o("rightSidebar.refreshFiles"),children:e.jsx(go,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ie??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:zh}),Na==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:o("fileTree.sortedByModified"),"aria-label":o("fileTree.sortedByModified"),children:e.jsx(Jd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ie&&Bt(ie,Ot??void 0),disabled:!ie,...ie&&Ot?yi(Ia(ie),Ot):{},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 ${Ot&&(Te===Ot||Be===Ot)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":o(Ot&&Be===Ot?"rightSidebar.copied":Ot&&Te===Ot?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:o("rightSidebar.insertCurrentFolder"),children:Ot&&(Te===Ot||Be===Ot)?e.jsx(ko,{size:13}):e.jsx(So,{size:13})}),e.jsx(pg,{rootPath:ie,disabled:!ie||!Lh||ai,pressed:Ca,saving:ai,onToggle:()=>{if(!ie||ai)return;const t=ie;xc(!0),oi(null),Ph(t,!Ca).catch(()=>{const i=Q.getState();(i.explorerRoot??i.rootPath)===t&&oi(o("rightSidebar.gitIgnoreSaveFailed"))}).finally(()=>xc(!1))}}),e.jsxs("div",{ref:Ln,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{yt(!1),tr(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${cr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":cr,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(wo,{size:14})}),cr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{tr(!1),qh()},disabled:!Si,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${Ps?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Ps?e.jsx(zi,{size:14}):e.jsx(ro,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(Ps?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{tr(!1),Mh()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${ti?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ti?e.jsx(Bp,{size:14}):e.jsx(ml,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(ti?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ie,onClick:()=>{ie&&(tr(!1),$h(ie,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(kp,{size:14}):e.jsx(Jd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(Na==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),vc&&e.jsx("p",{role:"alert",className:"px-1 py-1 text-[11px] text-destructive",children:vc}),v&&(Ba.length>0||Wh)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Oc,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 ${ie===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(Xd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:st})]}),Ba.map(t=>{const i=t.path,u=t.kind==="file",w=u?at===i:ie===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${w?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>u?Ms(i):Dt(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[u?e.jsx(pl,{size:10,className:"shrink-0"}):e.jsx(ro,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:jt(i)})]}),e.jsx("button",{type:"button",onClick:()=>mn(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.unpinFolder",{name:jt(i)}),title:o("rightSidebar.unpinFolder",{name:jt(i)}),children:e.jsx(Pt,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),_i=a.useMemo(()=>{if(zn===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((Yo-zn)/1e3)),u=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[w,y]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return u.format(w,y)},[Yo,zn]),eo="flex min-h-10 w-full items-center gap-2.5 rounded-md px-2.5 text-left text-[12px] text-foreground transition hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:min-h-11",Ld=v&&!ts?e.jsxs("button",{type:"button",role:"menuitemcheckbox",tabIndex:-1,onClick:()=>{wm(!ri)},"aria-checked":ri,title:o("rightSidebar.multiRepoScanTitle"),className:eo,children:[e.jsx(wr,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1",children:o("rightSidebar.multiRepoScan")}),ri&&e.jsx(ko,{size:14,className:"shrink-0 text-primary"})]}):null,Pd=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[_i?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:o("rightSidebar.gitLastUpdated",{time:_i}),children:_i}):null,e.jsx("button",{type:"button",onClick:()=>{es()},disabled:gr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),children:e.jsx(go,{size:13,className:gr?"animate-spin":""})})]}):null,Lm=Cc?o("rightSidebar.changeAuditScopeAll"):xn.length===1?xn[0].relativeRoot==="."?st:xn[0].relativeRoot||xn[0].name:`${xn.length} repos`,Pm=t=>v?e.jsxs("div",{role:"none",children:[e.jsx(Tu,{menuItem:!0,open:Hr,onOpenChange:i=>{tn(i),i&&t()},showScopePicker:Rn,selectedAll:Cc,repos:Ah,selectedRoots:ar,onToggleRepo:lm,onGenerate:()=>{t(),am()},disabled:!v,inserted:Te===Bc,buttonLabel:o("rightSidebar.changeAuditShort"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:o("rightSidebar.insertChangeAuditPrompt"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Lm,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o("rightSidebar.changeAuditShort"),loading:bs,error:!!da,statusTitle:da??(bs?o("rightSidebar.changeAuditLoading"):wt.length>0?`${o("rightSidebar.changeAuditLoaded",{count:wt.length})}${Ed?` · ${o("rightSidebar.changeAuditLoadedAt",{time:Ed})}`:""}`:void 0)}),wt.length>0&&e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),om()},disabled:bs||wt.length===0,className:eo,title:o("rightSidebar.clearChangeAuditTitle"),"aria-label":o("rightSidebar.clearChangeAudit"),children:[e.jsx(po,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.clearChangeAudit")})]})]}):null,is=ir??(de?.available&&v&&Ie.size>0&&$.length<=1?{root:v,label:st}:null),Ad=t=>e.jsxs(e.Fragment,{children:[is&&e.jsxs("div",{role:"group","aria-label":o("rightSidebar.gitQuickActions"),children:[e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Qa("stage-all",is.root,is.label)},disabled:!!ze,className:eo,children:[e.jsx(ip,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stageAll")]}),e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),Qa("stash-all",is.root,is.label)},disabled:!!ze,className:eo,children:[e.jsx(Lp,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stashAll")]})]}),is&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),Pm(t),Ld&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),Ld]}),to=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:[de?.available&&de.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:de.branch,children:[e.jsx(wr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:de.branch})]}),mt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[mt.modified,"M"]}),mt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",mt.added]}),mt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",mt.deleted]}),mt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[mt.renamed,"R"]}),mt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[mt.copied,"C"]}),mt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[mt.untracked,"U"]}),mt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[mt.conflicted,"!"]}),mt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[mt.other,"?"]}),mt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:o("rightSidebar.stagedCountShort",{count:mt.staged})})]});return e.jsxs(Sp,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:d,push:c,pinned:m,children:[yi.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${_h?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:st}),(!se||Ko)&&de?.available&&de.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:de.branch,children:[e.jsx(wr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:de.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!R;H(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):V("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${R?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleSearch"),title:o("common.search"),children:e.jsx(hs,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":ye,onClick:()=>{nt(t=>!t),Zt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ye?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleContextDraft"),title:o("rightSidebar.contextDraftTitle"),children:[e.jsx(jp,{size:14}),!ye&&je.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:ac,type:"file",multiple:!0,className:"hidden",onChange:t=>{const i=t.target.files;!i||i.length===0||($s(Array.from(i)),t.target.value="")}}),e.jsx("input",{ref:oc,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const i=t.target.files?.[0];t.target.value="",i&&Oh(i)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${m?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:m?e.jsx(zi,{size:14}):e.jsx(ro,{size:14})}),e.jsxs("div",{ref:$n,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{tr(!1),yt(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${er?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":er,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(wo,{size:15})}),er&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Gr,onClick:()=>Mc(!Gr),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2",children:[e.jsx(Kd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:o("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Gr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Gr?"left-3.5":"left-0.5"}`})})]}),e.jsx("div",{className:"my-1 h-px bg-border/15",role:"separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{yt(!1),ac.current?.click()},disabled:Pa,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Pa?e.jsx(dt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Qp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{yt(!1),oc.current?.click()},disabled:Pa,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[Pa?e.jsx(dt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Gp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{yt(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${m?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[m?e.jsx(zi,{size:14}):e.jsx(ro,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),m&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":o("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:o("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",o("rightSidebar.layoutModeAuto")],["narrow",o("rightSidebar.layoutModeNarrow")],["wide",o("rightSidebar.layoutModeWide")]].map(([t,i])=>{const u=ee===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":u,onClick:()=>{L(t),yt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":o("rightSidebar.close"),children:e.jsx(Pt,{size:14})})]}),R&&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(hs,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:I,onChange:t=>V(t.target.value),placeholder:o(U==="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 ${se?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>kd("name"),"aria-pressed":U==="name",className:`rounded-full px-2 transition active:scale-95 ${se?"py-1":"py-0.5"} ${U==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>kd("content"),"aria-pressed":U==="content",className:`rounded-full px-2 transition active:scale-95 ${se?"py-1":"py-0.5"} ${U==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeContent")})]}),I&&e.jsx("button",{type:"button",onClick:()=>V(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Rp,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:o("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:ce,onChange:t=>he(t.target.value),onKeyDown:t=>{t.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchScopePlaceholder"),"aria-label":o("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ce!=="."&&e.jsx("button",{type:"button",onClick:()=>he("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.resetSearchScope"),children:e.jsx(Pt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>J(t=>!t),"aria-expanded":$e,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${$e||Cs.length>0||xe||Fe||G?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:o("rightSidebar.searchOptions"),"aria-label":o("rightSidebar.searchOptions"),children:[e.jsx(Cp,{size:13}),Cs.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:Cs.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:o("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:Re,onChange:t=>Ce(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchExcludePlaceholder"),"aria-label":o("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),Re&&e.jsx("button",{type:"button",onClick:()=>Ce(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.clearSearchExclude"),children:e.jsx(Pt,{size:11})})]}),U==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":o("rightSidebar.contentSearchOptions"),children:[[xe,()=>fe(t=>!t),Fp,o("rightSidebar.matchCase")],[Fe,()=>Oe(t=>!t),eg,o("rightSidebar.matchWholeWord")],[G,()=>Ne(t=>!t),Vp,o("rightSidebar.useRegex")]].map(([t,i,u,w])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(u,{size:12}),w]},w))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(ts?3:5)+(Gr?1:0)}, minmax(0, 1fr))`},children:[!ts&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:t=>ns("git",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(wr,{size:12}),o("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:t=>ns("diff",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(cf,{size:12}),o("rightSidebar.tabChanges"),Ie.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Ie.size}):null]})]}),e.jsxs("button",{type:"button",onClick:t=>ns("files",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(cl,{size:12}),o("rightSidebar.tabFiles")]}),e.jsxs("button",{type:"button",onClick:t=>ns("architecture",t),className:`flex items-center justify-center gap-1 rounded px-1 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${vn?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Np,{size:12}),o("architecture.tab")]}),e.jsxs("button",{type:"button",onClick:t=>ns("computer",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${pi?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(sp,{size:12}),o("rightSidebar.tabComputer")]}),Gr&&e.jsxs("button",{type:"button",onClick:t=>ns("android",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Kd,{size:12}),o("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),Ql&&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:Ql})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(cs,{active:lt,mounted:sr,fallback:e.jsx(rl,{slow:!1}),children:()=>We?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(lu,{items:dm,diffViewType:Jo,inlineMode:Zr,viewControls:m?Ds():void 0,renderPathReference:(t,i)=>Ga(Nn(t,We.repoRoot??v),o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:vh,onSelect:fa,emptyText:o("rightSidebar.noChanges"),mobile:se,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o("rightSidebar.recentCommitsTitle"),headerMeta:`${We.headRef??""}${We.commits?.[0]?` · ${We.commits[0]}`:""}`,onClose:()=>{Ue(null),fa(null)},closeLabel:o("common.back"),wrap:zt,onToggleWrap:Xa,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:se?"stacked":"split",onInsertDiffReference:Or,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:qa})}):Wt?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(lu,{items:Ei,diffViewType:Jo,inlineMode:Zr,viewControls:m?Ds():void 0,renderPathReference:(t,i)=>{const u=we?.comparisonRepos,w=u&&u.length>1?[...u].sort((k,C)=>C.label.length-k.label.length).find(k=>t===k.label||t.startsWith(`${k.label}/`)):void 0,y=w?t===w.label?w.repoRoot:Nn(t.slice(w.label.length+1),w.repoRoot):Nn(t,Bs?.repoRoot||v);return Ga(y,o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:zo,onSelect:cn,emptyText:o(we?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:se,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o(we?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Bs?`${Bs.repoLabel} · ${Bs.branchName??"HEAD"} → ${Bs.baseRef}`:void 0,onClose:()=>{++It.current,K(!1),Gt(!1),rr(null)},closeLabel:o("common.back"),wrap:zt,onToggleWrap:Xa,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:se?"stacked":"split",onInsertDiffReference:Or,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:qa,localOptions:we?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??we.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??as(t.repoRoot,t.head)),onChange:i=>{Pi({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:i})}})),onHunkGitAction:we?.includeUncommitted?ym:void 0,error:be,actionsBusy:ua>0,onRefresh:()=>{Pi({refresh:!0})},refreshing:A,refreshLabel:o("rightSidebar.branchAuditRefreshDiff"),refreshTitle:o("rightSidebar.branchAuditRefreshDiff"),walkthroughs:um,onWalkthroughNavigate:fm,initialDetailScrollTop:we&&Ze?vs[Ze]:void 0,onDetailScrollPositionChange:xm,externalSwiperRef:se?jc:void 0,onMobileSlideChange:se?Go:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:sr&&v&&jn?e.jsx("div",{className:"px-3",children:Em()}):gr?e.jsx(rl,{slow:mc}):pn?e.jsx(fo,{message:pn,onRetry:()=>{es()}}):Bu(de)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):de?.available===!1?e.jsx(fo,{message:de.error??o("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{es()}}):v?e.jsx(rl,{slow:mc}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(cs,{active:Br,mounted:wh||Br,children:()=>se?e.jsxs(Qu,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:t=>{_r.current=t,t.slideTo(Wo,0)},onSlideChange:t=>{if(Dr(t.activeIndex),Es.current===t.activeIndex){Es.current=null;return}t.activeIndex===0&&(Ir(!1),gt(null),h?.())},children:[e.jsx(dl,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Yn,onScroll:$c,onDragOver:Aa,onDragEnter:Aa,onDragLeave:Pc,onDrop:Ac,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[rc&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:o("rightSidebar.dropToUpload")})}),!I.trim()&&$d,e.jsx(Qd,{rootPath:ie??"",onFileSelect:Ms,onPathReference:Bt,getReferenceText:Ia,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onDirectoryRoot:Uc,onSearchFromDirectory:Hc,onDirectoryPinToggle:zc,onFilePinToggle:Wc,pinnedPaths:wn,selectedFilePath:at,query:Se,searchRootPath:yc,searchOptions:wc,searchMode:U,onContentMatchSelect:bi,onDirectoryDropFiles:(t,i)=>$s(i,t),revealDirectory:W,canOpenInFileBrowser:nc,onOpenInFileBrowser:Lc})]})}),e.jsx(dl,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Po,{filePath:yh||Wo===1?at:null,active:r&&Br&&Wo===1,onInsertReference:Bt,onInsertText:or,onInsertFeature:or,onReviewReference:Fc,onReferenceCopied:vr,onClose:$m,onDirectoryLinkOpen:Md,isMobile:!0,lineRange:Pn,onLineRangeChange:gt,insertedReferenceKey:Te,copiedReferenceKey:Be,scrollToLine:Qr,onScrollToLineHandled:()=>Cr(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:N,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Yn,onScroll:$c,onDragOver:Aa,onDragEnter:Aa,onDragLeave:Pc,onDrop:Ac,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Qo},children:[rc&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:o("rightSidebar.dropToUpload")})}),!I.trim()&&$d,e.jsx(Qd,{rootPath:ie??"",onFileSelect:Ms,onPathReference:Bt,getReferenceText:Ia,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onDirectoryRoot:Uc,onSearchFromDirectory:Hc,onDirectoryPinToggle:zc,onFilePinToggle:Wc,pinnedPaths:wn,selectedFilePath:at,query:Se,searchRootPath:yc,searchOptions:wc,searchMode:U,onContentMatchSelect:bi,onDirectoryDropFiles:(t,i)=>$s(i,t),revealDirectory:W,canOpenInFileBrowser:nc,onOpenInFileBrowser:Lc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":o("rightSidebar.resizeFileTree"),title:o("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Th,onPointerMove:Ih,onPointerUp:Ec,onPointerCancel:Ec,onDoubleClick:()=>{Zo(yl),Lt(Ys,yl)},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(Po,{filePath:at,active:r&&Br,onInsertReference:Bt,onInsertText:or,onInsertFeature:or,onReviewReference:Fc,onReferenceCopied:vr,onDirectoryLinkOpen:Md,isMobile:!1,lineRange:Pn,onLineRangeChange:gt,insertedReferenceKey:Te,copiedReferenceKey:Be,scrollToLine:Qr,onScrollToLineHandled:()=>Cr(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:N,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j})})]})}),e.jsx(cs,{active:Mt,mounted:Sh||Mt,children:()=>mi?e.jsx(Ep,{}):se?e.jsx(ul,{mobile:!0,backLabel:o("rightSidebar.backToChangeList"),externalSwiperRef:fi,onMobileSlideChange:Go,groups:Qt.length>0?cd():[],mode:Ht,onModeChange:Ya,selectedKey:at,scrollToKey:md,scrollToKeyNonce:Sa.nonce,compact:!1,collapsedDirectoryKeys:Xe,onToggleDirectory:bd,onSelectFile:t=>{const i=Cn.get(t.key);i&&Va(kr(i))},renderLeading:dd,renderTrailing:t=>{const i=Cn.get(t.key);return i?id(i):null},renderDirectoryTrailing:ld,renderSubtitle:t=>{const i=Cn.get(t.key);return i?od(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[to&&e.jsx("div",{className:"mb-2",children:to}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Qt.length,"/",Ie.size]})]}),e.jsxs(au,{actions:Ad,children:[sd(),t,m&&Ds(),Pd]},v),ir&&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:ir.label}),ir.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:ir.branch})]}),!ir&&Rn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(wr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Ha?(t=>gd(t)):void 0,emptyContent:mi?null:pn&&Ie.size===0?e.jsx(fo,{message:pn,onRetry:()=>{es()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({slideToList:t})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:t,className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:o("rightSidebar.backToChangeList"),children:[e.jsx(ta,{size:14}),o("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[m&&Ds(),e.jsxs("button",{type:"button",onClick:Xa,"aria-pressed":zt,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${zt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:o(zt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),v&&e.jsx("button",{type:"button",onClick:()=>{es()},disabled:gr,"aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",children:e.jsx(go,{size:14,className:gr?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:ud,activePane:Mt,wrap:zt,diffViewType:Jo,inlineMode:Zr,diffOptions:wd,reloadKey:An,renderStreamBadge:t=>e.jsx(Qs,{status:t}),onHunkGitAction:Sd,onInsertDiffReference:Or,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:qa,onDetailScroll:Ka}):e.jsx(ul,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:o("rightSidebar.backToChangeList"),groups:Qt.length>0?cd():[],mode:Ht,onModeChange:Ya,selectedKey:at,scrollToKey:md,scrollToKeyNonce:Sa.nonce,compact:!0,collapsedDirectoryKeys:Xe,onToggleDirectory:bd,onSelectFile:t=>{const i=Cn.get(t.key);i&&Va(kr(i))},renderLeading:dd,renderTrailing:t=>{const i=Cn.get(t.key);return i?id(i):null},renderDirectoryTrailing:ld,renderSubtitle:t=>{const i=Cn.get(t.key);return i?od(i):null},aiContent:Ha?(t=>gd(t)):void 0,emptyContent:mi?null:pn&&Ie.size===0?e.jsx(fo,{message:pn,onRetry:()=>{es()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[to&&e.jsx("div",{className:"mb-2",children:to}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Qt.length,"/",Ie.size]})})]}),e.jsxs(au,{actions:Ad,children:[sd(),t,Ds(),e.jsxs("button",{type:"button",onClick:Xa,"aria-pressed":zt,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${zt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:o(zt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Pd]},v),ir&&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:ir.label}),ir.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:ir.branch})]}),!ir&&Rn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(wr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),files:ud,activePane:Mt,wrap:zt,diffViewType:$r,inlineMode:Zr,diffOptions:wd,reloadKey:An,renderStreamBadge:t=>e.jsx(Qs,{status:t}),onHunkGitAction:Sd,onInsertDiffReference:Or,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:qa,onDetailScroll:Ka})}),e.jsx(cs,{active:vn,mounted:Dh||r&&vn,children:e.jsx(a.Suspense,{fallback:e.jsx("p",{role:"status",className:"p-4 text-sm text-muted-foreground",children:o("architecture.loading")}),children:e.jsx(qb,{rootPath:v,active:r&&vn,onInsertPrompt:(t,i)=>or(t,`architecture:${v}`,i),renderSource:t=>v&&e.jsx(u0,{rootPath:v,file:t,active:r&&vn,isMobile:se,onInsertReference:Bt,onInsertText:or,onReferenceCopied:vr,insertedReferenceKey:Te,copiedReferenceKey:Be},`${t.path}:${t.line??1}`),onOpenFile:t=>{v&&(pr("files"),Dt(null),bi(`${v.replace(/\/+$/,"")}/${t.path}`,t.line??1))}},v)})}),e.jsx(cs,{active:pi,mounted:r&&pi,children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"p-3 text-xs text-muted-foreground",children:o("computer.loading")}),children:e.jsx(Vb,{})})}),e.jsx(cs,{active:rs,mounted:Vo&&Gr,children:jh?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:o("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Oi.getState().setDock(Hi,null),mo({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:o("android.splitClose")})]}):e.jsx(Mp,{sessionId:n??null,onCloseTab:()=>Mc(!1),onInsertPrompt:t=>Or("android-deps",t),onInsertFile:Hh,onRecordingComplete:Uh})})]}),r&&_t.task&&e.jsx(zg,{task:_t.task,onCancel:_t.cancel,onRetry:()=>{_t.retry()},onDismiss:_t.dismiss,labels:{uploading:o("rightSidebar.uploadPending"),inserting:o("rightSidebar.uploadInserting"),done:o(_t.task.kind==="image"?"rightSidebar.uploadReferenceDone":"rightSidebar.uploadDone",{count:_t.task.uploaded.length}),failed:o("rightSidebar.uploadFailed"),canceled:o("rightSidebar.uploadCanceled"),referenceRejected:o("rightSidebar.uploadReferenceRejected"),limit:o("rightSidebar.uploadLimit"),cancel:o("common.cancel"),retry:o("common.retry"),dismiss:o("common.close"),files:o("rightSidebar.uploadFileCount",{count:_t.task.files.length})}}),r&&ye&&e.jsx(_g,{value:je,collapsed:vt,autoCollapseAfterSend:z,focusRequest:At,insertError:Do?o("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{Jr(!1),Qe(t)},onCollapsedChange:Zt,onAutoCollapseAfterSendChange:oe,onDisable:()=>nt(!1),onClear:()=>Qe(""),onInsert:()=>_c(!1),onInsertAndSend:()=>_c(!0),labels:{title:o("rightSidebar.contextDraftTitle"),hint:o("rightSidebar.contextDraftHint"),placeholder:o("rightSidebar.contextDraftPlaceholder"),collapse:o("rightSidebar.contextDraftCollapse"),expand:o("rightSidebar.contextDraftExpand"),disable:o("rightSidebar.contextDraftDisable"),clear:o("rightSidebar.contextDraftClear"),insert:o("rightSidebar.contextDraftInsert"),insertAndSend:o("rightSidebar.contextDraftInsertAndSend"),inserted:o("rightSidebar.contextDraftInserted"),sent:o("rightSidebar.contextDraftSent"),pending:o("rightSidebar.contextDraftPending"),send:o("rightSidebar.contextDraftSend"),appended:o("rightSidebar.contextDraftAppended"),resize:o("rightSidebar.contextDraftResize"),autoCollapseAfterSend:o("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>o("rightSidebar.contextDraftCharacterCount",{count:t})}}),tm(),kt&&typeof document<"u"&&jr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>dn(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:kt.kind==="restore"?o("rightSidebar.confirmRestoreTitle"):o("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:kt.kind==="restore"?o("rightSidebar.confirmRestoreDescription",{path:Yu(kt.file.absolutePath,v)}):o("rightSidebar.confirmStashAllDescription")}),kt.kind==="restore"&&e.jsx("input",{value:kt.phrase,onChange:t=>dn({...kt,phrase:t.target.value}),placeholder:o("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>dn(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:o("common.cancel")}),e.jsx("button",{type:"button",disabled:!!ze||kt.kind==="restore"&&kt.phrase.trim()!==o("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(kt.kind==="restore"){const t=xt(kt.file,v);if(!t)return;St({action:"restore-worktree-file",cwd:t,paths:[kt.file.path],confirm:{acknowledged:!0,phrase:kt.phrase}},o("rightSidebar.restoreFile"),al(kt.file))}else{const t=kt.repoRoot??v;if(!t)return;St({action:"stash-all",cwd:t},o("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${kt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:o(ze?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const j0=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Po,MarkdownImageLightbox:ih,MarkdownPreview:lh,RightSidebar:f0,__testParseMarkdownListBlock:Mx,buildMarkdownPreviewBlocks:Bx,buildMarkdownPreviewRenderResult:Ul,collectKnownGitRepoRoots:Pf,computeMarkdownImageDisplayBox:Wf,getMarkdownHeadingOutline:oh,getMarkdownHeadingPathAtLine:ah,getNextMarkdownPreviewLineRange:Gx,isSvgImageSrc:ia,mountRightSidebarRepoPickerOverlay:vf,replaceGitRepositorySnapshot:mh,resolveMarkdownLocalLinkTarget:Il,resolveRightSidebarDiffViewType:$f,shouldCloseMarkdownImageLightboxDrag:rh,showsGitRepoGroupHeader:wl},Symbol.toStringTag,{value:"Module"}));export{ml as E,ru as L,j0 as R,Xp as S,Qp as U,Bp as a,Bx as b,gg as c,hg as i,fg as l,S0 as m};
1674
+ `)},[ln,os,Ds,Ct,sr,v]),vm=a.useCallback((t="generate")=>{const i=t==="generate"?Ai:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",Ai].join(`
1675
+ `);Ur(o("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${t}`),c||l()},[Ai,Ur,l,c,o]),Ti=a.useCallback(async(t={})=>{const i=t.refresh===!0,u=i&&we?.comparisonRepos?we.comparisonRepos:Ds.map(N=>{const le=(sr[N.root]||N.branch||"").trim();return{repoRoot:N.root,label:N.label,base:Ct[N.root]?.trim()??"",head:le||null,includeUncommitted:ln[N.root]??!0}});if(!v||u.length===0)return;const w=++It.current,y=v,k=()=>Me(y)&&w===It.current;K(!0),ke(null),i||(nr(null),Ue(null));try{const N=await Promise.all(u.map(async Z=>{if(!Z.base)throw new Error(o("rightSidebar.branchAuditMissingBase",{repo:Z.label}));return Kd({cwd:v,repoRoot:Z.repoRoot,base:Z.base,head:Z.head,includeUncommitted:t.repoRoot===Z.repoRoot?t.includeUncommitted??!1:Z.includeUncommitted??we?.includeUncommitted??!0,requestSlotId:`right-sidebar-branch-preview:${Z.repoRoot}`})}));if(!k())return;const le=N.find(Z=>!Z.available);if(le){ke(le.error??"Branch diff is unavailable");return}const ae=N.length===1?N[0]:{available:!0,workspaceRoot:v,repoRoot:v,baseRef:N.map(Z=>Z.baseRef??Z.baseBranch).filter(Boolean).join(", "),currentBranch:N.map(Z=>Z.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:N.map(Z=>Z.headRef).filter(Boolean).join(", "),diffFingerprint:N.map(Z=>Z.diffFingerprint).filter(Boolean).join("+"),stat:N.map(Z=>Z.stat).filter(Boolean).join(`
1676
+ `),files:N.flatMap((Z,Y)=>{const pe=u[Y];return(Z.files??[]).map(Ae=>`${pe?.label??Z.repoRoot??"repo"}/${Ae}`)}),hunks:N.flatMap((Z,Y)=>{const Ae=u[Y]?.label??Z.repoRoot??"repo";return(Z.hunks??[]).map(Ve=>({...Ve,filePath:`${Ae}/${Ve.filePath}`,oldPath:Ve.oldPath?`${Ae}/${Ve.oldPath}`:Ve.oldPath,newPath:Ve.newPath?`${Ae}/${Ve.newPath}`:Ve.newPath}))}),commits:N.flatMap(Z=>Z.commits??[]),commitCount:N.reduce((Z,Y)=>Z+(Y.commitCount??Y.commits?.length??0),0),diff:N.map(Z=>Z.diff).filter(Boolean).join(`
1677
+ `),truncated:N.some(Z=>Z.truncated)};if(ae.comparisonRepos=u.map((Z,Y)=>({...Z,head:Z.head??N[Y].currentBranch??null,includeUncommitted:N[Y].includeUncommitted===!0,canIncludeUncommitted:N[Y].canIncludeUncommitted})),ae.canIncludeUncommitted=N.every(Z=>Z.canIncludeUncommitted===!0),ae.includeUncommitted=N.some(Z=>Z.includeUncommitted===!0),zo(Z=>({...Z,...Object.fromEntries(ae.comparisonRepos.map(Y=>[Y.repoRoot,Y.includeUncommitted??!1]))})),!i&&(ae.hunks??[]).length===0){ke(o("rightSidebar.branchAuditDiffEmpty"));return}const ve=Date.now(),Pe=(i?Ze:null)??["preview",ae.repoRoot??v,ae.baseRef??ae.baseBranch??"",ae.currentBranch??"",ae.headRef??"",ae.diffFingerprint??ve].join("\0"),et=u.length===1?u[0].label:`${u.length} repos`;nr(ae),Fn(Z=>[{key:Pe,diff:ae,repoLabel:et,createdAt:ve},...Z.filter(Y=>Y.key!==Pe)].slice(0,8)),i||_n(Z=>Z[Pe]===void 0?Z:{...Z,[Pe]:0}),cn(Pe),dn(Z=>{const Y=ae.hunks?.[0],pe=Y?`${Y.filePath}\0${Y.hunkHeader}\0${Y.hunkIndex}`:null;return i&&Z&&(ae.hunks??[]).some(Ae=>Ae.filePath===Z.split("\0")[0])?Z:pe}),Kt(!0)}catch(N){if(!k()||jr(N))return;ke(N instanceof Error?N.message:"Failed to load branch diff")}finally{k()&&K(!1)}},[ln,we,Ze,Ds,Ct,sr,Me,v,o]),ym=a.useCallback(t=>{++It.current,K(!1),nr(t.diff),ke(null),cn(t.key),dn(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),Kt(!0)},[]),wm=a.useCallback(t=>{Fn(i=>i.filter(u=>u.key!==t)),_n(i=>{if(!(t in i))return i;const u={...i};return delete u[t],u}),Ze===t&&(cn(null),nr(null),Kt(!1))},[Ze]),km=a.useCallback(t=>{++It.current,K(!1);const i=is.find(u=>u.key===t);i&&(nr(null),ke(null),cn(t),dn(i.records[0]?.filePath??null),Kt(!0))},[is]),Sm=a.useCallback(async t=>{if(!v||!Ee)return;const[i]=t.split(/\s+/);if(i){Ge(i),bt(null),Ue(null);try{const u=await lp({cwd:v,repoRoot:Ee,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!u.available){bt(u.error??"Commit diff is unavailable");return}Ue(u);const w=u.hunks?.[0];ma(w?`${w.filePath}\0${w.hunkHeader}\0${w.hunkIndex}`:null)}catch(u){bt(u instanceof Error?u.message:"Failed to load commit diff")}finally{Ge(null)}}},[Ee,v]),jm=a.useCallback(t=>{if(!we||!Ze)return;const i=Math.max(0,Math.round(t));_n(u=>Math.abs((u[Ze]??0)-i)<24?u:{...u,[Ze]:i})},[we,Ze]);a.useEffect(()=>{!we||!Ze||Fn(t=>t.map(i=>i.key===Ze&&i.diff!==we?{...i,diff:we}:i))},[we,Ze]);const pd=!!we;a.useEffect(()=>{if(!se||!Gt||!pd)return;const t=Cc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const i=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(i)},[Gt,pd,se]);const gd=a.useCallback(t=>{t&&Ah(i=>Fp(i,t))},[]),bd=Ra.key===at?Ra.key:null,Xa=a.useCallback(t=>{const i=J.getState(),u=f0();Ys("select_diff_file",{interactionId:u,path:t,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ne,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),ot(t),Dt("diff"),se&&t&&$c(1),gd(t),queueMicrotask(()=>{const w=J.getState();Ys("select_diff_file_after",{interactionId:u,requestedPath:t,selectedFilePath:w.selectedFilePath,rootPath:w.rootPath,rightTab:w.rightTab,changedFiles:w.changedFiles.size,activeGitRepoRoot:ne})})},[ne,se,gd,ot,Dt,$c]),xd=a.useCallback(t=>{const i=Array.from(Ie.values()).find(u=>{const w=xt(u,v),y=Sr(u);return u.path===t.filePath||y===t.filePath||u.absolutePath===t.filePath||(w?`${w}/${u.path}`===t.filePath:!1)||t.repoRoot&&w===t.repoRoot&&u.path===t.filePath});if(i){Xa(Sr(i)),window.setTimeout(()=>Mn(t),90),window.setTimeout(()=>Mn(t),320),window.setTimeout(()=>Mn(t),760);return}Mn(t)},[Ie,v,Xa]),vd=a.useCallback(({slideToDetail:t,fullscreen:i,toggleFullscreen:u}={})=>gs.length>0?e.jsx(of,{walkthroughs:gs,repoRoot:ne,fullscreen:i,onToggleFullscreen:u,onNavigate:w=>{se&&window.requestAnimationFrame(()=>t?.()),xd(w)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(aa,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),o("rightSidebar.changeWalkthroughEmpty")]}),[ne,gs,xd,se,o]),Rm=a.useCallback(t=>{t&&da(i=>{const u=new Set(i);return u.has(t)?u.delete(t):u.add(t),el(Xi,u),u})},[]),yd=a.useCallback(t=>{Mr(i=>{const u=new Set(i);return u.has(t)?u.delete(t):u.add(t),el(ku,u),u})},[]),Ja=a.useCallback(t=>{Hr(t),Lt(Nf,t)},[]);a.useEffect(()=>{Wa||zt!=="ai"||Ja("tree")},[zt,Ja,Wa]);const Qa=a.useCallback(()=>{$r(t=>{const i=!t;return Lt(Cf,i),i})},[]),wd=a.useCallback(t=>{ua(t),Lt(Ef,t)},[]),{whitespace:kd,context:Sd}=Bp(),jd=a.useMemo(()=>({algorithm:"histogram",whitespace:kd,context:Sd}),[kd,Sd]),Rd=a.useCallback(t=>{X(t),Lt(Mf,t)},[]),Za=a.useCallback(async(t,i,u,w)=>{let y=t;for(;y.ok&&y.status==="running";)await new Promise(N=>window.setTimeout(N,1500)),y=await qd({jobId:y.jobId,cwd:i.cwd,action:i.action});if(!y.ok)throw new Error("Git action status is unavailable");if(y.status==="error")throw new Error(y.error||y.message||"Git action failed");const k={action:i.action,path:w,label:u};return Rs(k),window.setTimeout(()=>Rs(N=>N?.action===k.action&&N.path===k.path?null:N),1400),y},[]),St=a.useCallback(async(t,i,u)=>{const w=v;v&&xr.current.delete(v),Vt(null),Rs(null),js({action:t.action,path:u});try{const y=await cp({...t,includeNested:Gs(v)}),k=await Za(y,t,i,u);if(!Me(w))return!1;const N=v?await zi(v,void 0,{includeNested:Gs(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:qs(v)}).catch(()=>k.bundle):k.bundle;return Me(w)?(N&&es(N,{reloadDiff:!0,cacheOnly:!0}),un(null),!0):!1}catch(y){return Rs(null),Vt(o("rightSidebar.gitActionFailed",{message:y instanceof Error?y.message:"Unknown error"})),!1}finally{Me(w)&&js(null)}},[es,Me,v,o,Za]),Nd=a.useCallback(async t=>{const i=v;await Vd({...t,includeNested:Gs(v)}),Me(i)&&_t(v??void 0,{refresh:!0,background:!0})},[Me,_t,v]),Nm=a.useCallback(async t=>{const i=we,u=It.current,w=i?.hunks?.find(k=>k.previewRevert?.cwd===t.cwd&&k.previewRevert.path===t.path);if(!i||!w||!t.comparisonBase)throw new Error(o("diffViewer.hunkActionUnavailable"));Bn(k=>k+1),ke(null);try{await Vd(t)}catch(k){throw Bn(N=>N-1),k}if(u!==It.current||!Me(v)){Bn(k=>k-1);return}const y=k=>{nr(N=>{if(!N||u!==It.current)return N;const le=N.hunks??[],ae=k===void 0?le.filter(Pe=>!(Pe.previewRevert?.cwd===t.cwd&&Pe.previewRevert.patch===t.patch)):[...le.filter(Pe=>Pe.filePath!==w.filePath),...k];return{...N,hunks:ae}})};y(),Kd({cwd:t.cwd,repoRoot:t.cwd,base:t.comparisonBase,comparisonBase:t.comparisonBase,filePath:t.path,requestSlotId:`branch-preview-file:${t.cwd}:${t.path}`}).then(k=>{if(u!==It.current||!Me(v))return;if(!k.available||k.truncated)throw new Error(k.error??o("diffViewer.hunkActionUnavailable"));const N=t.path.slice(t.cwd.length+1),le=w.filePath.slice(0,w.filePath.length-N.length);y((k.hunks??[]).map(ae=>({...ae,filePath:`${le}${ae.filePath}`,oldPath:ae.oldPath?`${le}${ae.oldPath}`:ae.oldPath,newPath:ae.newPath?`${le}${ae.newPath}`:ae.newPath})))}).catch(k=>{u===It.current&&Me(v)&&!jr(k)&&ke(`${o("diffViewer.hunkActionReverted")} · ${k instanceof Error?k.message:String(k)}`)}).finally(()=>Bn(k=>k-1))},[we,Me,v,o]),eo=a.useCallback((t,i,u)=>{if(i){if(t==="stage-all"){St({action:"stage-all",cwd:i},o("rightSidebar.stageAll"),`repo:${i}`);return}un({kind:"stash-all",repoRoot:i,repoLabel:u})}},[St,o]),Cd=a.useCallback(t=>{Ye(t),ka(""),Sa(""),ja(""),ot(Zc(t)),lt||Dt("diff"),t&&Ha(it.get(t))},[Ha,Zc,lt,it,ot,Ye,Dt]),Ed=a.useCallback(t=>{const i=new Set([...Xt.current.keys(),...bn.current,...xr.current]);for(const u of i)u!==t&&(Yt.current.delete(u),Xt.current.get(u)?.abort(),Xt.current.delete(u),Nt(`right-sidebar-git-untracked:${u}`),bn.current.delete(u),xr.current.delete(u))},[]),Cm=a.useCallback(async t=>{const i=v;if(!i||(await J.getState().setNestedGitScanRoot(i,t),!Me(i)))return;if(t){await _t(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Ed(i),ka(""),Sa(""),ja(""),Ho(w=>w.filter(y=>y===i));const u=Jt;u&&xt(u,i)!==i&&ot(null),await _t(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Ed,Me,_t,v,ot,Jt]),Em=a.useCallback(async()=>{if(!Ee||rt){Vt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=Gn.trim();!t||t===ue?.branch||await St({action:"switch-branch",cwd:Ee,branch:t},o("rightSidebar.switchBranch"))},[ue?.branch,Ee,rt,St,Gn,o]),Md=a.useCallback(async()=>{if(!Ee||rt){Vt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=wa.trim();if(!t)return;await St({action:"commit",cwd:Ee,message:t},o("rightSidebar.commitChanges"))&&nc("")},[Ee,wa,rt,St,o]),Mm=a.useCallback(async()=>{if(!Ee||rt){Vt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await St({action:"push",cwd:Ee,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pushChanges"))},[Ee,mn,hn,rt,St,o]),$m=a.useCallback(async()=>{if(!Ee||rt){Vt(o("rightSidebar.selectRepositoryForGitActions"));return}const t=hn.trim(),i=mn.trim();await St({action:"pull",cwd:Ee,...t?{remote:t}:{},...i?{branch:i}:{}},o("rightSidebar.pullChanges"))},[Ee,mn,hn,rt,St,o]);a.useEffect(()=>{if(!lt||!Ee||ze)return;let t=!1;const i={push:o("rightSidebar.pushChanges"),pull:o("rightSidebar.pullChanges"),commit:o("rightSidebar.commitChanges"),"switch-branch":o("rightSidebar.switchBranch"),"stage-all":o("rightSidebar.stageAll"),"stash-all":o("rightSidebar.stashAll")};return(async()=>{for(const u of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const w=await qd({cwd:Ee,action:u}).catch(()=>null);if(!w?.ok||w.status!=="running")continue;const y={action:u,cwd:Ee},k=i[u]??u;js({action:u});try{const N=await Za(w,y,k);if(t||!Me(v))return;const le=v?await zi(v,void 0,{includeNested:Gs(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:qs(v)}).catch(()=>N.bundle):N.bundle;le&&es(le,{reloadDiff:!0,cacheOnly:!0})}catch(N){t||Vt(o("rightSidebar.gitActionFailed",{message:N instanceof Error?N.message:"Unknown error"}))}finally{t||js(null)}return}})(),()=>{t=!0}},[Ee,es,lt,Me,v,ze,o,Za]);const Ii=zn?.action==="commit",Di=zn?.action==="switch-branch",Fi=zn?.action==="pull",_i=zn?.action==="push",to=lt||Lh,Bi=Ka?o("rightSidebar.changeAuditScopeAll"):wr.length===1?wr[0].label:`${wr.length} repos`,Lm=wr.length>0,$d=Ds.length>0,Pm=v?e.jsx(Bu,{open:Oo,onOpenChange:Uo,showScopePicker:!0,selectedAll:Ka,repos:Qt,selectedRoots:Ga,onToggleRepo:pm,onGenerate:()=>vm(Li?"regenerate":"generate"),disabled:!Lm,generateDisabled:!$d,inserted:Te?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:o(Li?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.branchAuditGenerateTitle"),ariaLabel:o("rightSidebar.branchAuditShort"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Bi,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o(Li?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ti()},secondaryDisabled:!$d||A,secondaryLabel:o("rightSidebar.branchAuditViewDiff"),secondaryTitle:o("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:A,loading:Yl.size>0,statusTitle:Yl.size>0?o("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:sd.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:o("rightSidebar.missingBaseReposSkipped",{repositories:sd.map(t=>t.label).join(_==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const i=it.get(t.root),u=os(t.root,sr[t.root]||i?.context?.branch),w=[],y=new Set,k=(ve,Pe)=>{!ve||y.has(ve)||(y.add(ve),w.push({value:ve,label:ve,meta:Pe}))};k(sr[t.root]||i?.context?.branch,o("rightSidebar.pushCurrentBranchBadge"));for(const ve of i?.context?.branches??[])k(ve,ve===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):o("rightSidebar.localBranch"));for(const ve of i?.context?.remoteBranches??[])k(ve,o("rightSidebar.remoteBranch"));const N=[],le=new Set,ae=(ve,Pe)=>{!ve||le.has(ve)||(le.add(ve),N.push({value:ve,label:ve,meta:Pe}))};ae(Ct[t.root],Ct[t.root]?o("rightSidebar.pushUpstreamBadge"):void 0),ae(i?.context?.upstream,i?.context?.upstream?o("rightSidebar.pushUpstreamBadge"):void 0);for(const ve of i?.context?.remoteBranches??[])ae(ve,"remote");for(const ve of i?.context?.branches??[])ae(ve,ve===i?.context?.branch?o("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(fs,{label:o("rightSidebar.currentBranchLabel"),value:sr[t.root]||i?.context?.branch||"",options:w,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),onChange:ve=>{ga(Pe=>({...Pe,[t.root]:ve}))}}),e.jsx(fs,{label:o("rightSidebar.branchAuditBaseLabel"),value:Ct[t.root]||"",options:N,placeholder:o("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:o("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:o("rightSidebar.branchAuditBaseEmpty"),onChange:ve=>{ba(Pe=>({...Pe,[t.root]:ve}))}}),e.jsxs("label",{className:"sm:col-span-2 flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:o("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:o(u?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:u&&(ln[t.root]??!0),disabled:!u,onChange:ve=>zo(Pe=>({...Pe,[t.root]:ve.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,Ld=Vs(wt.reduce((t,i)=>Math.max(t,i.injectedAt??0),0),_),Am=()=>v?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Vl(t=>{const i=!t;return Lt(Ji,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Ss,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(aa,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:Bi})]}),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 ${Ss?"rotate-90":""}`,children:e.jsx(hs,{size:13})})]}),Ss&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[o("rightSidebar.changeAuditScopeLabel"),": ",Bi]}),Pm]}),be&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:be}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[sn.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>ym(t),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:o("rightSidebar.branchAuditViewDiff")})]}),Vs(t.createdAt,_)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Vs(t.createdAt,_)})]}),e.jsx("button",{type:"button",onClick:()=>wm(t.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:o("common.delete"),"aria-label":o("common.delete"),children:e.jsx(go,{size:12})})]},t.key)),is.length>0?is.slice(0,Math.max(0,8-sn.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>km(t.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),Vs(t.latestInjectedAt,_)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:o("rightSidebar.branchAuditGeneratedAt",{time:Vs(t.latestInjectedAt,_)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{hm(t)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:o("rightSidebar.branchAuditClearTitle"),"aria-label":o("rightSidebar.branchAuditClearTitle"),children:e.jsx(go,{size:12})})]},t.key)):sn.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Tm=()=>ar&&v&&Rn?e.jsxs("div",{className:to?"overflow-visible":"overflow-hidden",children:[Am(),e.jsxs("button",{type:"button",onClick:()=>{lt||Ph(t=>{const i=!t;return i&&Ee&&!Rn&&!fn&&pi(Ee),i})},"aria-expanded":to,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${lt?"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(kr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:o("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${jn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[fn&&e.jsx(dt,{size:10,className:"animate-spin"}),jn.staged>0?o("rightSidebar.stagedCount",{count:jn.staged}):o("rightSidebar.noStagedChangesShort")]}),!lt&&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 ${to?"rotate-90":""}`,children:e.jsx(hs,{size:13})})]})]}),to&&e.jsxs("div",{className:"space-y-0",children:[Ht.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:em})]})}),e.jsx(fs,{label:o("rightSidebar.gitRepositoryLabel"),value:Ee??"",options:Ht,placeholder:o("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:o("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:o("rightSidebar.gitRepositoryEmpty"),disabled:!!ze,onChange:t=>{Cd(t||null)}}),rt&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:o("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Gn!==Jc?Jc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{Em()},disabled:!dm,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 ${Di?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.switchBranch"),children:[e.jsx("span",{className:ze?.action==="switch-branch"||Di?"opacity-0":"",children:o("rightSidebar.switchBranch")}),ze?.action==="switch-branch"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Di&&ze?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(fs,{label:o("rightSidebar.currentBranchLabel"),value:Gn,options:nm,placeholder:o("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:o("rightSidebar.switchBranchSearchPlaceholder"),emptyText:o("rightSidebar.switchNoBranches"),disabled:!!ze,onChange:ka})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:rt?o("rightSidebar.selectRepositoryForGitActions"):jn.staged>0?o("rightSidebar.commitReadyHint",{count:jn.staged}):o("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Md()},disabled:!!ze||rt||jn.staged===0||!wa.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 ${Ii?"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:rt?o("rightSidebar.selectRepositoryForGitActions"):jn.staged===0?o("rightSidebar.commitNeedsStaged"):o("rightSidebar.commitChanges"),children:[e.jsx("span",{className:ze?.action==="commit"||Ii?"opacity-0":"",children:o("rightSidebar.commitChanges")}),ze?.action==="commit"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Ii&&ze?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:wa,onChange:t=>nc(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),Md())},placeholder:o("rightSidebar.commitMessagePlaceholder"),disabled:!!ze,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Tr(t=>!t),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":hr,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:o("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[re&&e.jsx(dt,{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 ${hr?"rotate-90":""}`,children:e.jsx(hs,{size:13})})]})]}),hr&&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(ms,{size:12,className:"shrink-0"}),e.jsx("input",{value:On,onChange:t=>an(t.target.value),placeholder:o("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),On&&e.jsx("button",{type:"button",onClick:()=>an(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:tm,children:[on.length>0?on.map(t=>{const[i,...u]=t.split(/\s+/),w=u.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{Sm(t)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:w,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:w,children:w}),mr[i]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${mr[i]==="ahead"?"bg-accent/10 text-accent":mr[i]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:o(mr[i]==="ahead"?"rightSidebar.commitAhead":mr[i]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),tt===i&&e.jsx(dt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):re?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:o("common.loading")}):_o?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:o("rightSidebar.recentCommitsEmpty")}),qt&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(dt,{size:12,className:"animate-spin"})}),Bo&&!qt&&on.length>0&&e.jsx("button",{type:"button",onClick:()=>{Is({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:o("rightSidebar.recentCommitsLoadMore")})]})]}),ht&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ht}),_o&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:_o})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:o("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{$m()},disabled:!lm,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 ${Fi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pullChanges"),children:[e.jsx("span",{className:ze?.action==="pull"||Fi?"opacity-0":"",children:o("rightSidebar.pullChanges")}),ze?.action==="pull"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),Fi&&ze?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Mm()},disabled:!cm,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 ${_i?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o("rightSidebar.pushChanges"),children:[e.jsx("span",{className:ze?.action==="push"||_i?"opacity-0":"",children:o("rightSidebar.pushChanges")}),ze?.action==="push"&&e.jsx(dt,{size:12,className:"absolute animate-spin"}),_i&&ze?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${od.className}`,title:ue?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:od.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ue?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${nd?"grid-cols-2":"grid-cols-1"}`,children:[nd&&e.jsx(fs,{label:o("rightSidebar.pushRemoteLabel"),value:hn,options:rd,placeholder:o("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:o("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:o("rightSidebar.pushNoRemotes"),disabled:!!ze,onChange:Sa}),e.jsx(fs,{label:o("rightSidebar.pushBranchLabel"),value:mn,options:sm,placeholder:o("rightSidebar.pushBranchPlaceholder",{branch:ue?.branch??"HEAD"}),searchPlaceholder:o("rightSidebar.pushBranchSearchPlaceholder"),emptyText:o("rightSidebar.pushNoBranches"),disabled:!!ze,onChange:ja})]})]})]})]}):null,Im=a.useCallback(t=>{const i=xt(t,v);if(!i)return[];const u=il(t),w=[];return t.canStage&&w.push({key:"stage-file",label:o("rightSidebar.stageFile"),onClick:()=>{St({action:"stage-file",cwd:i,paths:[t.path]},o("rightSidebar.stageFile"),u)}}),t.canUnstage&&w.push({key:"unstage-file",label:o("rightSidebar.unstageFile"),onClick:()=>{St({action:"unstage-file",cwd:i,paths:[t.path]},o("rightSidebar.unstageFile"),u)}}),t.canStash&&w.push({key:"stash-file",label:o("rightSidebar.stashFile"),onClick:()=>{St({action:"stash-file",cwd:i,paths:[t.path]},o("rightSidebar.stashFile"),u)}}),t.canRestoreWorktree&&w.push({key:"restore-worktree-file",label:o("rightSidebar.restoreFile"),destructive:!0,onClick:()=>un({kind:"restore",file:t,phrase:""})}),w},[v,St,o]),Dm=a.useCallback(()=>{if(f){h?.();return}Fr(0),Br.current?.slideTo(0),Dr(!1),gt(null)},[h,f]),Pd=a.useCallback(t=>{if(V(""),Ft(t),ot(null),gt(null),O(null),se){f&&h?.(),Fr(0),Br.current?.slideTo(0),Dr(!1);return}},[se,h,f,ot,Ft]);a.useEffect(()=>{const t=i=>{const u=i.detail,w=u?.path;if(typeof w!="string"||!w.startsWith("/"))return;V(""),gt(null),Cr(null);const y=!!(v&&(w===v||w.startsWith(`${v}/`)));if(u.kind==="file"){const k=po(w);$s(w),typeof u.line=="number"&&Number.isSafeInteger(u.line)&&u.line>0&&Cr(u.line),Ft(y?null:k),O(N=>({path:w,nonce:(N?.nonce??0)+1}));return}ot(null),y?(Ft(null),O(k=>({path:w,nonce:(k?.nonce??0)+1}))):(O(null),Ft(w)),se&&(f&&h?.(),Fr(0),Br.current?.slideTo(0),Dr(!1))};return window.addEventListener(Zd,t),()=>window.removeEventListener(Zd,t)},[$s,se,h,f,v,ot,Ft]),a.useEffect(()=>{r||(yt(!1),rr(!1))},[r]),a.useEffect(()=>{if(!tr&&!dr)return;const t=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&(Ln.current?.contains(i.target)||Pn.current?.contains(i.target))||(yt(!1),rr(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[dr,tr]);const Ad=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:Jh,disabled:!Oa,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.parentFolder"),title:o("rightSidebar.parentFolder"),children:e.jsx(Al,{size:14})}),e.jsx("button",{type:"button",onClick:zc,disabled:!v||qn===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.backToProjectRoot"),title:o("rightSidebar.backToProjectRoot"),children:e.jsx(eu,{size:14})}),e.jsx("button",{type:"button",onClick:Qh,disabled:!ie,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":o("rightSidebar.refreshFiles"),title:sc?o("rightSidebar.fileWatchUnavailable",{message:sc}):o("rightSidebar.refreshFiles"),children:e.jsx(bo,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ie??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:Yh}),Ma==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:o("fileTree.sortedByModified"),"aria-label":o("fileTree.sortedByModified"),children:e.jsx(tu,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ie&&Ot(ie,Ut??void 0),disabled:!ie,...ie&&Ut?ki(Fa(ie),Ut):{},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 ${Ut&&(Te===Ut||Be===Ut)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":o(Ut&&Be===Ut?"rightSidebar.copied":Ut&&Te===Ut?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:o("rightSidebar.insertCurrentFolder"),children:Ut&&(Te===Ut||Be===Ut)?e.jsx(So,{size:13}):e.jsx(jo,{size:13})}),e.jsx(vg,{rootPath:ie,disabled:!ie||!Dh||ii,pressed:Ea,saving:ii,onToggle:()=>{if(!ie||ii)return;const t=ie;wc(!0),li(null),Fh(t,!Ea).catch(()=>{const i=J.getState();(i.explorerRoot??i.rootPath)===t&&li(o("rightSidebar.gitIgnoreSaveFailed"))}).finally(()=>wc(!1))}}),e.jsxs("div",{ref:Pn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{yt(!1),rr(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${dr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":dr,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(ko,{size:14})}),dr&&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:()=>{rr(!1),Zh()},disabled:!Ri,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${As?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[As?e.jsx(Gi,{size:14}):e.jsx(so,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(As?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{rr(!1),Th()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${ni?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[ni?e.jsx(zp,{size:14}):e.jsx(gl,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(ni?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ie,onClick:()=>{ie&&(rr(!1),Ih(ie,Ma==="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:[Ma==="modified"?e.jsx(Cp,{size:14}):e.jsx(tu,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(Ma==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),kc&&e.jsx("p",{role:"alert",className:"px-1 py-1 text-[11px] text-destructive",children:kc}),v&&(Ua.length>0||Xh)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:zc,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 ${ie===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(eu,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:st})]}),Ua.map(t=>{const i=t.path,u=t.kind==="file",w=u?at===i:ie===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${w?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>u?$s(i):Ft(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[u?e.jsx(bl,{size:10,className:"shrink-0"}):e.jsx(so,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:jt(i)})]}),e.jsx("button",{type:"button",onClick:()=>pn(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":o("rightSidebar.unpinFolder",{name:jt(i)}),title:o("rightSidebar.unpinFolder",{name:jt(i)}),children:e.jsx(Pt,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Oi=a.useMemo(()=>{if(Wn===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((Jo-Wn)/1e3)),u=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[w,y]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return u.format(w,y)},[Jo,Wn]),ro="flex min-h-10 w-full items-center gap-2.5 rounded-md px-2.5 text-left text-[12px] text-foreground transition hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [@media(pointer:coarse)]:min-h-11",Td=v&&!rs?e.jsxs("button",{type:"button",role:"menuitemcheckbox",tabIndex:-1,onClick:()=>{Cm(!si)},"aria-checked":si,title:o("rightSidebar.multiRepoScanTitle"),className:ro,children:[e.jsx(kr,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1",children:o("rightSidebar.multiRepoScan")}),si&&e.jsx(So,{size:14,className:"shrink-0 text-primary"})]}):null,Id=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Oi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:o("rightSidebar.gitLastUpdated",{time:Oi}),children:Oi}):null,e.jsx("button",{type:"button",onClick:()=>{ts()},disabled:br,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),children:e.jsx(bo,{size:13,className:br?"animate-spin":""})})]}):null,Fm=Mc?o("rightSidebar.changeAuditScopeAll"):vn.length===1?vn[0].relativeRoot==="."?st:vn[0].relativeRoot||vn[0].name:`${vn.length} repos`,_m=t=>v?e.jsxs("div",{role:"none",children:[e.jsx(Bu,{menuItem:!0,open:zr,onOpenChange:i=>{rn(i),i&&t()},showScopePicker:Nn,selectedAll:Mc,repos:_h,selectedRoots:or,onToggleRepo:mm,onGenerate:()=>{t(),um()},disabled:!v,inserted:Te===Hc,buttonLabel:o("rightSidebar.changeAuditShort"),insertedLabel:o("rightSidebar.inserted"),title:o("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:o("rightSidebar.insertChangeAuditPrompt"),scopeTitle:o("rightSidebar.changeAuditScopeLabel"),scopeLabel:Fm,allLabel:o("rightSidebar.changeAuditScopeAll"),generateLabel:o("rightSidebar.changeAuditShort"),loading:xs,error:!!fa,statusTitle:fa??(xs?o("rightSidebar.changeAuditLoading"):wt.length>0?`${o("rightSidebar.changeAuditLoaded",{count:wt.length})}${Ld?` · ${o("rightSidebar.changeAuditLoadedAt",{time:Ld})}`:""}`:void 0)}),wt.length>0&&e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),fm()},disabled:xs||wt.length===0,className:ro,title:o("rightSidebar.clearChangeAuditTitle"),"aria-label":o("rightSidebar.clearChangeAudit"),children:[e.jsx(go,{size:15,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.clearChangeAudit")})]})]}):null,ls=lr??(de?.available&&v&&Ie.size>0&&$.length<=1?{root:v,label:st}:null),Dd=t=>e.jsxs(e.Fragment,{children:[ls&&e.jsxs("div",{role:"group","aria-label":o("rightSidebar.gitQuickActions"),children:[e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),eo("stage-all",ls.root,ls.label)},disabled:!!ze,className:ro,children:[e.jsx(fp,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stageAll")]}),e.jsxs("button",{type:"button",role:"menuitem",tabIndex:-1,onClick:()=>{t(),eo("stash-all",ls.root,ls.label)},disabled:!!ze,className:ro,children:[e.jsx(Ip,{size:15,className:"shrink-0 text-muted-foreground"}),o("rightSidebar.stashAll")]})]}),ls&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),_m(t),Td&&e.jsx("div",{role:"separator",className:"mx-2 my-1 h-px bg-border/30"}),Td]}),no=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:[de?.available&&de.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:de.branch,children:[e.jsx(kr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:de.branch})]}),mt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[mt.modified,"M"]}),mt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",mt.added]}),mt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",mt.deleted]}),mt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[mt.renamed,"R"]}),mt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[mt.copied,"C"]}),mt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[mt.untracked,"U"]}),mt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[mt.conflicted,"!"]}),mt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[mt.other,"?"]}),mt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:o("rightSidebar.stagedCountShort",{count:mt.staged})})]});return e.jsxs(Ep,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:d,push:c,pinned:m,children:[ki.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${zh?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:st}),(!se||qo)&&de?.available&&de.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:de.branch,children:[e.jsx(kr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:de.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!R;H(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):V("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${R?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleSearch"),title:o("common.search"),children:e.jsx(ms,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":ye,onClick:()=>{nt(t=>!t),er(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ye?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o("rightSidebar.toggleContextDraft"),title:o("rightSidebar.contextDraftTitle"),children:[e.jsx(Mp,{size:14}),!ye&&je.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:lc,type:"file",multiple:!0,className:"hidden",onChange:t=>{const i=t.target.files;!i||i.length===0||(Ls(Array.from(i)),t.target.value="")}}),e.jsx("input",{ref:cc,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const i=t.target.files?.[0];t.target.value="",i&&Kh(i)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${m?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:m?e.jsx(Gi,{size:14}):e.jsx(so,{size:14})}),e.jsxs("div",{ref:Ln,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{rr(!1),yt(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${tr?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":tr,"aria-haspopup":"menu","aria-label":o("sidebar.moreActions"),title:o("sidebar.moreActions"),children:e.jsx(ko,{size:15})}),tr&&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:[["architecture","computer"].map(t=>e.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":gr[t],onClick:()=>Gh(t,!gr[t]),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:[t==="architecture"?e.jsx(ru,{size:14,className:"text-muted-foreground"}):e.jsx(Yd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:o(t==="architecture"?"rightSidebar.showArchitectureTab":"rightSidebar.showComputerTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${gr[t]?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${gr[t]?"left-3.5":"left-0.5"}`})})]},t)),e.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Kr,onClick:()=>Pc(!Kr),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(Xd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:o("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Kr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Kr?"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:()=>{yt(!1),lc.current?.click()},disabled:Ta,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:[Ta?e.jsx(dt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(rg,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{yt(!1),cc.current?.click()},disabled:Ta,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:[Ta?e.jsx(dt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Yp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{yt(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${m?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[m?e.jsx(Gi,{size:14}):e.jsx(so,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:o(m?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),m&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":o("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:o("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",o("rightSidebar.layoutModeAuto")],["narrow",o("rightSidebar.layoutModeNarrow")],["wide",o("rightSidebar.layoutModeWide")]].map(([t,i])=>{const u=ee===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":u,onClick:()=>{L(t),yt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":o("rightSidebar.close"),children:e.jsx(Pt,{size:14})})]}),R&&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(ms,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:I,onChange:t=>V(t.target.value),placeholder:o(U==="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 ${se?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Rd("name"),"aria-pressed":U==="name",className:`rounded-full px-2 transition active:scale-95 ${se?"py-1":"py-0.5"} ${U==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Rd("content"),"aria-pressed":U==="content",className:`rounded-full px-2 transition active:scale-95 ${se?"py-1":"py-0.5"} ${U==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:o("rightSidebar.searchModeContent")})]}),I&&e.jsx("button",{type:"button",onClick:()=>V(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.clearSearch"),children:e.jsx(Pt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx($p,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:o("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:ce,onChange:t=>he(t.target.value),onKeyDown:t=>{t.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchScopePlaceholder"),"aria-label":o("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ce!=="."&&e.jsx("button",{type:"button",onClick:()=>he("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":o("rightSidebar.resetSearchScope"),children:e.jsx(Pt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>Q(t=>!t),"aria-expanded":$e,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${$e||Cs.length>0||xe||Fe||G?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:o("rightSidebar.searchOptions"),"aria-label":o("rightSidebar.searchOptions"),children:[e.jsx(Lp,{size:13}),Cs.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:Cs.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:o("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:Re,onChange:t=>Ne(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:o("rightSidebar.searchExcludePlaceholder"),"aria-label":o("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),Re&&e.jsx("button",{type:"button",onClick:()=>Ne(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":o("rightSidebar.clearSearchExclude"),children:e.jsx(Pt,{size:11})})]}),U==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":o("rightSidebar.contentSearchOptions"),children:[[xe,()=>fe(t=>!t),Up,o("rightSidebar.matchCase")],[Fe,()=>Oe(t=>!t),sg,o("rightSidebar.matchWholeWord")],[G,()=>Ce(t=>!t),Qp,o("rightSidebar.useRegex")]].map(([t,i,u,w])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(u,{size:12}),w]},w))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(rs?1:3)+Number(gr.architecture)+Number(gr.computer)+Number(Kr)}, minmax(0, 1fr))`},children:[!rs&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:t=>ss("git",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(kr,{size:12}),o("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:t=>ss("diff",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(mf,{size:12}),o("rightSidebar.tabChanges"),Ie.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Ie.size}):null]})]}),e.jsxs("button",{type:"button",onClick:t=>ss("files",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(ul,{size:12}),o("rightSidebar.tabFiles")]}),gr.architecture&&e.jsxs("button",{type:"button",onClick:t=>ss("architecture",t),className:`flex items-center justify-center gap-1 rounded px-1 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${yn?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(ru,{size:12}),o("architecture.tab")]}),gr.computer&&e.jsxs("button",{type:"button",onClick:t=>ss("computer",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${bi?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Yd,{size:12}),o("rightSidebar.tabComputer")]}),Kr&&e.jsxs("button",{type:"button",onClick:t=>ss("android",t),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Et==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Xd,{size:12}),o("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),tc&&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:tc})]}),e.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(ds,{active:lt,mounted:ar,fallback:e.jsx(sl,{slow:!1}),children:()=>We?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(hu,{items:gm,diffViewType:Zo,inlineMode:en,viewControls:m?Fs():void 0,renderPathReference:(t,i)=>qa(En(t,We.repoRoot??v),o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:jh,onSelect:ma,emptyText:o("rightSidebar.noChanges"),mobile:se,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o("rightSidebar.recentCommitsTitle"),headerMeta:`${We.headRef??""}${We.commits?.[0]?` · ${We.commits[0]}`:""}`,onClose:()=>{Ue(null),ma(null)},closeLabel:o("common.back"),wrap:Wt,onToggleWrap:Qa,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:se?"stacked":"split",onInsertDiffReference:Ur,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:Ya})}):Gt?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(hu,{items:$i,diffViewType:Zo,inlineMode:en,viewControls:m?Fs():void 0,renderPathReference:(t,i)=>{const u=we?.comparisonRepos,w=u&&u.length>1?[...u].sort((k,N)=>N.label.length-k.label.length).find(k=>t===k.label||t.startsWith(`${k.label}/`)):void 0,y=w?t===w.label?w.repoRoot:En(t.slice(w.label.length+1),w.repoRoot):En(t,Os?.repoRoot||v);return qa(y,o(i==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:Wo,onSelect:dn,emptyText:o(we?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:se,backLabel:o("rightSidebar.backToChangeList"),headerTitle:o(we?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Os?`${Os.repoLabel} · ${Os.branchName??"HEAD"} → ${Os.baseRef}`:void 0,onClose:()=>{++It.current,K(!1),Kt(!1),nr(null)},closeLabel:o("common.back"),wrap:Wt,onToggleWrap:Qa,wrapTitle:o("rightSidebar.wrapLongLines"),wrapOnLabel:o("rightSidebar.wrapOn"),wrapOffLabel:o("rightSidebar.wrapOff"),desktopLayout:se?"stacked":"split",onInsertDiffReference:Ur,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:Ya,localOptions:we?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??we.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??os(t.repoRoot,t.head)),onChange:i=>{Ti({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:i})}})),onHunkGitAction:we?.includeUncommitted?Nm:void 0,error:be,actionsBusy:ha>0,onRefresh:()=>{Ti({refresh:!0})},refreshing:A,refreshLabel:o("rightSidebar.branchAuditRefreshDiff"),refreshTitle:o("rightSidebar.branchAuditRefreshDiff"),walkthroughs:bm,onWalkthroughNavigate:xm,initialDetailScrollTop:we&&Ze?ys[Ze]:void 0,onDetailScrollPositionChange:jm,externalSwiperRef:se?Cc:void 0,onMobileSlideChange:se?Ko:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:ar&&v&&Rn?e.jsx("div",{className:"px-3",children:Tm()}):br?e.jsx(sl,{slow:bc}):gn?e.jsx(mo,{message:gn,onRetry:()=>{ts()}}):Wu(de)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):de?.available===!1?e.jsx(mo,{message:de.error??o("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{ts()}}):v?e.jsx(sl,{slow:bc}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(ds,{active:Or,mounted:Nh||Or,children:()=>se?e.jsxs(nf,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:t=>{Br.current=t,t.slideTo(Go,0)},onSlideChange:t=>{if(Fr(t.activeIndex),Ms.current===t.activeIndex){Ms.current=null;return}t.activeIndex===0&&(Dr(!1),gt(null),h?.())},children:[e.jsx(fl,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Xn,onScroll:Ac,onDragOver:Ia,onDragEnter:Ia,onDragLeave:Ic,onDrop:Dc,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[ac&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:o("rightSidebar.dropToUpload")})}),!I.trim()&&Ad,e.jsx(nu,{rootPath:ie??"",onFileSelect:$s,onPathReference:Ot,getReferenceText:Fa,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onDirectoryRoot:Wc,onSearchFromDirectory:Gc,onDirectoryPinToggle:Kc,onFilePinToggle:qc,pinnedPaths:kn,selectedFilePath:at,query:Se,searchRootPath:Sc,searchOptions:jc,searchMode:U,onContentMatchSelect:vi,onDirectoryDropFiles:(t,i)=>Ls(i,t),revealDirectory:W,canOpenInFileBrowser:oc,onOpenInFileBrowser:Tc})]})}),e.jsx(fl,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Ao,{filePath:Rh||Go===1?at:null,active:r&&Or&&Go===1,onInsertReference:Ot,onInsertText:ir,onInsertFeature:ir,onReviewReference:Oc,onReferenceCopied:yr,onClose:Dm,onDirectoryLinkOpen:Pd,isMobile:!0,lineRange:An,onLineRangeChange:gt,insertedReferenceKey:Te,copiedReferenceKey:Be,scrollToLine:Zr,onScrollToLineHandled:()=>Cr(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:C,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Xn,onScroll:Ac,onDragOver:Ia,onDragEnter:Ia,onDragLeave:Ic,onDrop:Dc,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:ei},children:[ac&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:o("rightSidebar.dropToUpload")})}),!I.trim()&&Ad,e.jsx(nu,{rootPath:ie??"",onFileSelect:$s,onPathReference:Ot,getReferenceText:Fa,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onDirectoryRoot:Wc,onSearchFromDirectory:Gc,onDirectoryPinToggle:Kc,onFilePinToggle:qc,pinnedPaths:kn,selectedFilePath:at,query:Se,searchRootPath:Sc,searchOptions:jc,searchMode:U,onContentMatchSelect:vi,onDirectoryDropFiles:(t,i)=>Ls(i,t),revealDirectory:W,canOpenInFileBrowser:oc,onOpenInFileBrowser:Tc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":o("rightSidebar.resizeFileTree"),title:o("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Bh,onPointerMove:Oh,onPointerUp:Lc,onPointerCancel:Lc,onDoubleClick:()=>{ti(kl),Lt(Js,kl)},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(Ao,{filePath:at,active:r&&Or,onInsertReference:Ot,onInsertText:ir,onInsertFeature:ir,onReviewReference:Oc,onReferenceCopied:yr,onDirectoryLinkOpen:Pd,isMobile:!1,lineRange:An,onLineRangeChange:gt,insertedReferenceKey:Te,copiedReferenceKey:Be,scrollToLine:Zr,onScrollToLineHandled:()=>Cr(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:F,onOpenMarkdownOutline:M,onCloseMarkdownOutline:C,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:B,onOpenMarkdownImageLightbox:q,onCloseMarkdownImageLightbox:j})})]})}),e.jsx(ds,{active:Mt,mounted:Eh||Mt,children:()=>gi?e.jsx(Pp,{}):se?e.jsx(hl,{mobile:!0,backLabel:o("rightSidebar.backToChangeList"),externalSwiperRef:mi,onMobileSlideChange:Ko,groups:Zt.length>0?fd():[],mode:zt,onModeChange:Ja,selectedKey:at,scrollToKey:bd,scrollToKeyNonce:Ra.nonce,compact:!1,collapsedDirectoryKeys:Xe,onToggleDirectory:yd,onSelectFile:t=>{const i=Cn.get(t.key);i&&Xa(Sr(i))},renderLeading:hd,renderTrailing:t=>{const i=Cn.get(t.key);return i?dd(i):null},renderDirectoryTrailing:ud,renderSubtitle:t=>{const i=Cn.get(t.key);return i?cd(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[no&&e.jsx("div",{className:"mb-2",children:no}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Zt.length,"/",Ie.size]})]}),e.jsxs(du,{actions:Dd,children:[id(),t,m&&Fs(),Id]},v),lr&&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:lr.label}),lr.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:lr.branch})]}),!lr&&Nn&&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(kr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Wa?(t=>vd(t)):void 0,emptyContent:gi?null:gn&&Ie.size===0?e.jsx(mo,{message:gn,onRetry:()=>{ts()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Zt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({slideToList:t})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:t,className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:o("rightSidebar.backToChangeList"),children:[e.jsx(na,{size:14}),o("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[m&&Fs(),e.jsxs("button",{type:"button",onClick:Qa,"aria-pressed":Wt,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Wt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:o(Wt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),v&&e.jsx("button",{type:"button",onClick:()=>{ts()},disabled:br,"aria-label":o("rightSidebar.refreshGit"),title:o("rightSidebar.refreshGit"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",children:e.jsx(bo,{size:14,className:br?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:md,activePane:Mt,wrap:Wt,diffViewType:Zo,inlineMode:en,diffOptions:jd,reloadKey:Tn,renderStreamBadge:t=>e.jsx(ea,{status:t}),onHunkGitAction:Nd,onInsertDiffReference:Ur,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:Ya,onDetailScroll:Va}):e.jsx(hl,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:o("rightSidebar.backToChangeList"),groups:Zt.length>0?fd():[],mode:zt,onModeChange:Ja,selectedKey:at,scrollToKey:bd,scrollToKeyNonce:Ra.nonce,compact:!0,collapsedDirectoryKeys:Xe,onToggleDirectory:yd,onSelectFile:t=>{const i=Cn.get(t.key);i&&Xa(Sr(i))},renderLeading:hd,renderTrailing:t=>{const i=Cn.get(t.key);return i?dd(i):null},renderDirectoryTrailing:ud,renderSubtitle:t=>{const i=Cn.get(t.key);return i?cd(i):null},aiContent:Wa?(t=>vd(t)):void 0,emptyContent:gi?null:gn&&Ie.size===0?e.jsx(mo,{message:gn,onRetry:()=>{ts()}}):Ie.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o("rightSidebar.noChanges")}):Zt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:o("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[no&&e.jsx("div",{className:"mb-2",children:no}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:o("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Zt.length,"/",Ie.size]})})]}),e.jsxs(du,{actions:Dd,children:[id(),t,Fs(),e.jsxs("button",{type:"button",onClick:Qa,"aria-pressed":Wt,title:o("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Wt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:o(Wt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Id]},v),lr&&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:lr.label}),lr.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:lr.branch})]}),!lr&&Nn&&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(kr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:o("rightSidebar.selectRepositoryForDiff")})]})]}),files:md,activePane:Mt,wrap:Wt,diffViewType:Lr,inlineMode:en,diffOptions:jd,reloadKey:Tn,renderStreamBadge:t=>e.jsx(ea,{status:t}),onHunkGitAction:Nd,onInsertDiffReference:Ur,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be,onClearAuditRecord:Ya,onDetailScroll:Va})}),e.jsx(ds,{active:yn,mounted:gr.architecture&&(Uh||r&&yn),children:e.jsx(a.Suspense,{fallback:e.jsx("p",{role:"status",className:"p-4 text-sm text-muted-foreground",children:o("architecture.loading")}),children:e.jsx(Jb,{rootPath:v,active:r&&yn,onInsertPrompt:(t,i)=>ir(t,`architecture:${v}`,i),renderSource:t=>v&&e.jsx(p0,{rootPath:v,file:t,active:r&&yn,isMobile:se,onInsertReference:Ot,onInsertText:ir,onReferenceCopied:yr,insertedReferenceKey:Te,copiedReferenceKey:Be},`${t.path}:${t.line??1}`),onOpenFile:t=>{v&&(Dt("files"),Ft(null),vi(`${v.replace(/\/+$/,"")}/${t.path}`,t.line??1))}},v)})}),e.jsx(ds,{active:bi,mounted:r&&bi,children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"p-3 text-xs text-muted-foreground",children:o("computer.loading")}),children:e.jsx(Qb,{})})}),e.jsx(ds,{active:ns,mounted:Yo&&Kr,children:Mh?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:o("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Hi.getState().setDock(Wi,null),Xs({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:o("android.splitClose")})]}):e.jsx(Ap,{sessionId:n??null,onCloseTab:()=>Pc(!1),onInsertPrompt:t=>Ur("android-deps",t),onInsertFile:Vh,onRecordingComplete:qh})})]}),r&&Bt.task&&e.jsx(qg,{task:Bt.task,onCancel:Bt.cancel,onRetry:()=>{Bt.retry()},onDismiss:Bt.dismiss,labels:{uploading:o("rightSidebar.uploadPending"),inserting:o("rightSidebar.uploadInserting"),done:o(Bt.task.kind==="image"?"rightSidebar.uploadReferenceDone":"rightSidebar.uploadDone",{count:Bt.task.uploaded.length}),failed:o("rightSidebar.uploadFailed"),canceled:o("rightSidebar.uploadCanceled"),referenceRejected:o("rightSidebar.uploadReferenceRejected"),limit:o("rightSidebar.uploadLimit"),cancel:o("common.cancel"),retry:o("common.retry"),dismiss:o("common.close"),files:o("rightSidebar.uploadFileCount",{count:Bt.task.files.length})}}),r&&ye&&e.jsx(Hg,{value:je,collapsed:vt,autoCollapseAfterSend:z,focusRequest:At,insertError:Fo?o("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{Qr(!1),Qe(t)},onCollapsedChange:er,onAutoCollapseAfterSendChange:oe,onDisable:()=>nt(!1),onClear:()=>Qe(""),onInsert:()=>Uc(!1),onInsertAndSend:()=>Uc(!0),labels:{title:o("rightSidebar.contextDraftTitle"),hint:o("rightSidebar.contextDraftHint"),placeholder:o("rightSidebar.contextDraftPlaceholder"),collapse:o("rightSidebar.contextDraftCollapse"),expand:o("rightSidebar.contextDraftExpand"),disable:o("rightSidebar.contextDraftDisable"),clear:o("rightSidebar.contextDraftClear"),insert:o("rightSidebar.contextDraftInsert"),insertAndSend:o("rightSidebar.contextDraftInsertAndSend"),inserted:o("rightSidebar.contextDraftInserted"),sent:o("rightSidebar.contextDraftSent"),pending:o("rightSidebar.contextDraftPending"),send:o("rightSidebar.contextDraftSend"),appended:o("rightSidebar.contextDraftAppended"),resize:o("rightSidebar.contextDraftResize"),autoCollapseAfterSend:o("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>o("rightSidebar.contextDraftCharacterCount",{count:t})}}),im(),kt&&typeof document<"u"&&Rr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>un(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:kt.kind==="restore"?o("rightSidebar.confirmRestoreTitle"):o("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:kt.kind==="restore"?o("rightSidebar.confirmRestoreDescription",{path:ef(kt.file.absolutePath,v)}):o("rightSidebar.confirmStashAllDescription")}),kt.kind==="restore"&&e.jsx("input",{value:kt.phrase,onChange:t=>un({...kt,phrase:t.target.value}),placeholder:o("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>un(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:o("common.cancel")}),e.jsx("button",{type:"button",disabled:!!ze||kt.kind==="restore"&&kt.phrase.trim()!==o("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(kt.kind==="restore"){const t=xt(kt.file,v);if(!t)return;St({action:"restore-worktree-file",cwd:t,paths:[kt.file.path],confirm:{acknowledged:!0,phrase:kt.phrase}},o("rightSidebar.restoreFile"),il(kt.file))}else{const t=kt.repoRoot??v;if(!t)return;St({action:"stash-all",cwd:t},o("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${kt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:o(ze?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const E0=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Ao,MarkdownImageLightbox:fh,MarkdownPreview:hh,RightSidebar:g0,__testParseMarkdownListBlock:Ax,buildMarkdownPreviewBlocks:zx,buildMarkdownPreviewRenderResult:zl,collectKnownGitRepoRoots:Ff,computeMarkdownImageDisplayBox:Yf,getMarkdownHeadingOutline:uh,getMarkdownHeadingPathAtLine:dh,getNextMarkdownPreviewLineRange:Yx,isSvgImageSrc:ca,mountRightSidebarRepoPickerOverlay:jf,replaceGitRepositorySnapshot:vh,resolveMarkdownLocalLinkTarget:Fl,resolveRightSidebarDiffViewType:If,shouldCloseMarkdownImageLightboxDrag:ih,showsGitRepoGroupHeader:Sl},Symbol.toStringTag,{value:"Module"}));export{gl as E,iu as L,E0 as R,eg as S,rg as U,zp as a,zx as b,yg as c,bg as i,gg as l,C0 as m};