termdock 1.4.281 → 1.4.282

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 (336) hide show
  1. package/dist/client/assets/App-KjvxjYWp.js +157 -0
  2. package/dist/client/assets/App-KjvxjYWp.js.br +0 -0
  3. package/dist/client/assets/App-KjvxjYWp.js.gz +0 -0
  4. package/dist/client/assets/{ChangeWalkthroughPanel-CpJIxJoa.js → ChangeWalkthroughPanel-D0dLmuqS.js} +1 -1
  5. package/dist/client/assets/ChangeWalkthroughPanel-D0dLmuqS.js.br +0 -0
  6. package/dist/client/assets/ChangeWalkthroughPanel-D0dLmuqS.js.gz +0 -0
  7. package/dist/client/assets/{DagPlayground-DsZ_TzMA.js → DagPlayground-BnxrVoa1.js} +1 -1
  8. package/dist/client/assets/DagPlayground-BnxrVoa1.js.br +0 -0
  9. package/dist/client/assets/DagPlayground-BnxrVoa1.js.gz +0 -0
  10. package/dist/client/assets/{DiffLab-DVzd5Djx.js → DiffLab-CEJHH47s.js} +1 -1
  11. package/dist/client/assets/DiffLab-CEJHH47s.js.br +0 -0
  12. package/dist/client/assets/DiffLab-CEJHH47s.js.gz +0 -0
  13. package/dist/client/assets/{DiffReview-5MLGwl3s.js → DiffReview-B4MgHev_.js} +1 -1
  14. package/dist/client/assets/DiffReview-B4MgHev_.js.br +0 -0
  15. package/dist/client/assets/DiffReview-B4MgHev_.js.gz +0 -0
  16. package/dist/client/assets/{DiffReviewLab-B53N-9cX.js → DiffReviewLab-CwxhCK9D.js} +1 -1
  17. package/dist/client/assets/DiffReviewLab-CwxhCK9D.js.br +0 -0
  18. package/dist/client/assets/DiffReviewLab-CwxhCK9D.js.gz +0 -0
  19. package/dist/client/assets/{DiffViewer-PrcRXQq0.js → DiffViewer-B5Fj1S7h.js} +2 -2
  20. package/dist/client/assets/DiffViewer-B5Fj1S7h.js.br +0 -0
  21. package/dist/client/assets/DiffViewer-B5Fj1S7h.js.gz +0 -0
  22. package/dist/client/assets/{ModelPreview-C98dbuUF.js → ModelPreview-BgzcGTC4.js} +161 -161
  23. package/dist/client/assets/ModelPreview-BgzcGTC4.js.br +0 -0
  24. package/dist/client/assets/ModelPreview-BgzcGTC4.js.gz +0 -0
  25. package/dist/client/assets/{RightSidebar-B52JGGs9.js → RightSidebar-BZfXFW1d.js} +39 -39
  26. package/dist/client/assets/RightSidebar-BZfXFW1d.js.br +0 -0
  27. package/dist/client/assets/RightSidebar-BZfXFW1d.js.gz +0 -0
  28. package/dist/client/assets/{abnfDiagram-VCTEODGH-B5gA9_Ty.js → abnfDiagram-VCTEODGH-DrqWxUpF.js} +1 -1
  29. package/dist/client/assets/abnfDiagram-VCTEODGH-DrqWxUpF.js.br +0 -0
  30. package/dist/client/assets/abnfDiagram-VCTEODGH-DrqWxUpF.js.gz +0 -0
  31. package/dist/client/assets/app-Cx1S0NEn.js +35 -0
  32. package/dist/client/assets/app-Cx1S0NEn.js.br +0 -0
  33. package/dist/client/assets/app-Cx1S0NEn.js.gz +0 -0
  34. package/dist/client/assets/{arc-Bq6Y_399.js → arc-D-c2BO48.js} +1 -1
  35. package/dist/client/assets/arc-D-c2BO48.js.br +0 -0
  36. package/dist/client/assets/arc-D-c2BO48.js.gz +0 -0
  37. package/dist/client/assets/{architectureDiagram-5GKGNRK7-D7bXmRrP.js → architectureDiagram-5GKGNRK7-Dw3s7taT.js} +1 -1
  38. package/dist/client/assets/architectureDiagram-5GKGNRK7-Dw3s7taT.js.br +0 -0
  39. package/dist/client/assets/architectureDiagram-5GKGNRK7-Dw3s7taT.js.gz +0 -0
  40. package/dist/client/assets/{blockDiagram-I7D4REHJ-vmiTllrb.js → blockDiagram-I7D4REHJ-BJb1cd3h.js} +1 -1
  41. package/dist/client/assets/blockDiagram-I7D4REHJ-BJb1cd3h.js.br +0 -0
  42. package/dist/client/assets/blockDiagram-I7D4REHJ-BJb1cd3h.js.gz +0 -0
  43. package/dist/client/assets/{c4Diagram-7LVT6UL2-C6ThUVSU.js → c4Diagram-7LVT6UL2-BeS1pCi3.js} +1 -1
  44. package/dist/client/assets/{c4Diagram-7LVT6UL2-C6ThUVSU.js.br → c4Diagram-7LVT6UL2-BeS1pCi3.js.br} +0 -0
  45. package/dist/client/assets/c4Diagram-7LVT6UL2-BeS1pCi3.js.gz +0 -0
  46. package/dist/client/assets/channel-DhhM4ZRP.js +1 -0
  47. package/dist/client/assets/{chunk-2Q5K7J3B-DR-yB9IL.js → chunk-2Q5K7J3B-Bbs_OKMp.js} +1 -1
  48. package/dist/client/assets/{chunk-5VM5RSS4-B1nK9YvE.js → chunk-5VM5RSS4-Cb5qWSQ9.js} +1 -1
  49. package/dist/client/assets/{chunk-F27PBJKO-C7W0s-qY.js → chunk-F27PBJKO-DuSEgqou.js} +1 -1
  50. package/dist/client/assets/chunk-F27PBJKO-DuSEgqou.js.br +0 -0
  51. package/dist/client/assets/chunk-F27PBJKO-DuSEgqou.js.gz +0 -0
  52. package/dist/client/assets/{chunk-IMKFNOWR-CTjPfIKT.js → chunk-IMKFNOWR-DJ_KSg28.js} +1 -1
  53. package/dist/client/assets/chunk-IMKFNOWR-DJ_KSg28.js.br +0 -0
  54. package/dist/client/assets/chunk-IMKFNOWR-DJ_KSg28.js.gz +0 -0
  55. package/dist/client/assets/{chunk-JWPE2WC7-DdFiULME.js → chunk-JWPE2WC7-G6gJR-qb.js} +1 -1
  56. package/dist/client/assets/{chunk-POPQ4Y6H-7D3Xkf9O.js → chunk-POPQ4Y6H-4nUthGI-.js} +1 -1
  57. package/dist/client/assets/{chunk-SVP7TREG-CCuDpBKr.js → chunk-SVP7TREG-Bjz61A31.js} +1 -1
  58. package/dist/client/assets/chunk-SVP7TREG-Bjz61A31.js.br +0 -0
  59. package/dist/client/assets/chunk-SVP7TREG-Bjz61A31.js.gz +0 -0
  60. package/dist/client/assets/{chunk-TICWLB2K-DtYX2TNH.js → chunk-TICWLB2K-DibS9hjO.js} +1 -1
  61. package/dist/client/assets/chunk-TICWLB2K-DibS9hjO.js.br +0 -0
  62. package/dist/client/assets/chunk-TICWLB2K-DibS9hjO.js.gz +0 -0
  63. package/dist/client/assets/{chunk-XXDRQBXY-DhzCdSBY.js → chunk-XXDRQBXY-Pd9xo63D.js} +1 -1
  64. package/dist/client/assets/classDiagram-ZZMXUADV-CNhLKXhv.js +1 -0
  65. package/dist/client/assets/classDiagram-v2-VYDZK3BY-CNhLKXhv.js +1 -0
  66. package/dist/client/assets/{cose-bilkent-JH36ORCC-CyoiG3NB.js → cose-bilkent-JH36ORCC-C9juqAQ3.js} +1 -1
  67. package/dist/client/assets/cose-bilkent-JH36ORCC-C9juqAQ3.js.br +0 -0
  68. package/dist/client/assets/cose-bilkent-JH36ORCC-C9juqAQ3.js.gz +0 -0
  69. package/dist/client/assets/{cynefin-OW5HDTMX-SeWSNPvK.js → cynefin-OW5HDTMX-DVk5dNlQ.js} +1 -1
  70. package/dist/client/assets/cynefin-OW5HDTMX-DVk5dNlQ.js.br +0 -0
  71. package/dist/client/assets/cynefin-OW5HDTMX-DVk5dNlQ.js.gz +0 -0
  72. package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-C6Z9w461.js → cynefinDiagram-5FMLGOSQ-CUy-CI0N.js} +1 -1
  73. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CUy-CI0N.js.br +0 -0
  74. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CUy-CI0N.js.gz +0 -0
  75. package/dist/client/assets/{dagre-GXQ25YYZ-DgQ7oSI3.js → dagre-GXQ25YYZ-BF9uZc8K.js} +1 -1
  76. package/dist/client/assets/dagre-GXQ25YYZ-BF9uZc8K.js.br +0 -0
  77. package/dist/client/assets/dagre-GXQ25YYZ-BF9uZc8K.js.gz +0 -0
  78. package/dist/client/assets/{diagram-S7CK7UJ4-BrFJNnZh.js → diagram-S7CK7UJ4-CaYJASCw.js} +1 -1
  79. package/dist/client/assets/diagram-S7CK7UJ4-CaYJASCw.js.br +0 -0
  80. package/dist/client/assets/diagram-S7CK7UJ4-CaYJASCw.js.gz +0 -0
  81. package/dist/client/assets/{diagram-UQ7AKVKN-DW2EFMOu.js → diagram-UQ7AKVKN-0-M4q-QN.js} +1 -1
  82. package/dist/client/assets/diagram-UQ7AKVKN-0-M4q-QN.js.br +0 -0
  83. package/dist/client/assets/diagram-UQ7AKVKN-0-M4q-QN.js.gz +0 -0
  84. package/dist/client/assets/{diagram-VSXAHHWV-C5lTJcKk.js → diagram-VSXAHHWV-4ggjBQOj.js} +1 -1
  85. package/dist/client/assets/diagram-VSXAHHWV-4ggjBQOj.js.br +0 -0
  86. package/dist/client/assets/diagram-VSXAHHWV-4ggjBQOj.js.gz +0 -0
  87. package/dist/client/assets/{diagram-VX7I27RA-CObqcJqB.js → diagram-VX7I27RA-awKrOIYn.js} +1 -1
  88. package/dist/client/assets/diagram-VX7I27RA-awKrOIYn.js.br +0 -0
  89. package/dist/client/assets/diagram-VX7I27RA-awKrOIYn.js.gz +0 -0
  90. package/dist/client/assets/{diagram-Z3DM3KII-br3lGnhW.js → diagram-Z3DM3KII-CvmtkYW3.js} +1 -1
  91. package/dist/client/assets/diagram-Z3DM3KII-CvmtkYW3.js.br +0 -0
  92. package/dist/client/assets/diagram-Z3DM3KII-CvmtkYW3.js.gz +0 -0
  93. package/dist/client/assets/{ebnfDiagram-PWID7BFC-CkXxS9Pq.js → ebnfDiagram-PWID7BFC-ZS9U0Fk-.js} +1 -1
  94. package/dist/client/assets/ebnfDiagram-PWID7BFC-ZS9U0Fk-.js.br +0 -0
  95. package/dist/client/assets/ebnfDiagram-PWID7BFC-ZS9U0Fk-.js.gz +0 -0
  96. package/dist/client/assets/{erDiagram-RLTQ6QDP-CMBJEKp-.js → erDiagram-RLTQ6QDP-CcWwxLbE.js} +1 -1
  97. package/dist/client/assets/erDiagram-RLTQ6QDP-CcWwxLbE.js.br +0 -0
  98. package/dist/client/assets/erDiagram-RLTQ6QDP-CcWwxLbE.js.gz +0 -0
  99. package/dist/client/assets/{flowDiagram-HODETNUW-CuO0cLki.js → flowDiagram-HODETNUW-BvYM0Nn3.js} +1 -1
  100. package/dist/client/assets/flowDiagram-HODETNUW-BvYM0Nn3.js.br +0 -0
  101. package/dist/client/assets/flowDiagram-HODETNUW-BvYM0Nn3.js.gz +0 -0
  102. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-BIt0Y40Q.js → ganttDiagram-EL5Y4UJY-DEr4hj6W.js} +1 -1
  103. package/dist/client/assets/ganttDiagram-EL5Y4UJY-DEr4hj6W.js.br +0 -0
  104. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-BIt0Y40Q.js.gz → ganttDiagram-EL5Y4UJY-DEr4hj6W.js.gz} +0 -0
  105. package/dist/client/assets/{gestureArbiter--6cZMOnD.js → gestureArbiter-CDxeAcBI.js} +1 -1
  106. package/dist/client/assets/gestureArbiter-CDxeAcBI.js.br +0 -0
  107. package/dist/client/assets/gestureArbiter-CDxeAcBI.js.gz +0 -0
  108. package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-C1ljbYw7.js → gitGraphDiagram-WWUBYQGX-DJXcqbTp.js} +1 -1
  109. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DJXcqbTp.js.br +0 -0
  110. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DJXcqbTp.js.gz +0 -0
  111. package/dist/client/assets/imageCompression-DaUBNTq-.js +1 -0
  112. package/dist/client/assets/index-607UPNXL.js +1 -0
  113. package/dist/client/assets/index-607UPNXL.js.br +0 -0
  114. package/dist/client/assets/index-607UPNXL.js.gz +0 -0
  115. package/dist/client/assets/index-CUxsIblL.js +1 -0
  116. package/dist/client/assets/index-CUxsIblL.js.br +0 -0
  117. package/dist/client/assets/index-CUxsIblL.js.gz +0 -0
  118. package/dist/client/assets/{index-DeTcW7aT.css → index-IknuJMxJ.css} +1 -1
  119. package/dist/client/assets/index-IknuJMxJ.css.br +0 -0
  120. package/dist/client/assets/index-IknuJMxJ.css.gz +0 -0
  121. package/dist/client/assets/{infoDiagram-27XIBGKW-CrOPvG9H.js → infoDiagram-27XIBGKW-u_tuWUg-.js} +1 -1
  122. package/dist/client/assets/{ishikawaDiagram-5VMMS53U-Ch5ze9LB.js → ishikawaDiagram-5VMMS53U-BFYZSOqo.js} +1 -1
  123. package/dist/client/assets/ishikawaDiagram-5VMMS53U-BFYZSOqo.js.br +0 -0
  124. package/dist/client/assets/ishikawaDiagram-5VMMS53U-BFYZSOqo.js.gz +0 -0
  125. package/dist/client/assets/{journeyDiagram-3NMN7TZE-C3vqa0wB.js → journeyDiagram-3NMN7TZE-BCCDGuPm.js} +1 -1
  126. package/dist/client/assets/journeyDiagram-3NMN7TZE-BCCDGuPm.js.br +0 -0
  127. package/dist/client/assets/journeyDiagram-3NMN7TZE-BCCDGuPm.js.gz +0 -0
  128. package/dist/client/assets/{kanban-definition-UXKFOSKX-rEL2pKx0.js → kanban-definition-UXKFOSKX-BL414bhZ.js} +1 -1
  129. package/dist/client/assets/kanban-definition-UXKFOSKX-BL414bhZ.js.br +0 -0
  130. package/dist/client/assets/kanban-definition-UXKFOSKX-BL414bhZ.js.gz +0 -0
  131. package/dist/client/assets/{layout-CeDdQRYz.js → layout-BLj6qqUe.js} +1 -1
  132. package/dist/client/assets/layout-BLj6qqUe.js.br +0 -0
  133. package/dist/client/assets/layout-BLj6qqUe.js.gz +0 -0
  134. package/dist/client/assets/{linear-C9xkTlXu.js → linear-9XUUJjvf.js} +1 -1
  135. package/dist/client/assets/linear-9XUUJjvf.js.br +0 -0
  136. package/dist/client/assets/linear-9XUUJjvf.js.gz +0 -0
  137. package/dist/client/assets/{mermaid.core-CIW1IDpX.js → mermaid.core-BMjyQhe0.js} +5 -5
  138. package/dist/client/assets/mermaid.core-BMjyQhe0.js.br +0 -0
  139. package/dist/client/assets/mermaid.core-BMjyQhe0.js.gz +0 -0
  140. package/dist/client/assets/{mindmap-definition-YA3MSWOX-CT9M_dpw.js → mindmap-definition-YA3MSWOX-B5hQdEJ0.js} +1 -1
  141. package/dist/client/assets/mindmap-definition-YA3MSWOX-B5hQdEJ0.js.br +0 -0
  142. package/dist/client/assets/mindmap-definition-YA3MSWOX-B5hQdEJ0.js.gz +0 -0
  143. package/dist/client/assets/{passwordBootstrap-B8awl9Cz.js → passwordBootstrap-D7lxBxbp.js} +1 -1
  144. package/dist/client/assets/passwordBootstrap-D7lxBxbp.js.br +0 -0
  145. package/dist/client/assets/passwordBootstrap-D7lxBxbp.js.gz +0 -0
  146. package/dist/client/assets/{pegDiagram-XKGWAZYB-BkaUHxk6.js → pegDiagram-XKGWAZYB-CJQClA-K.js} +1 -1
  147. package/dist/client/assets/pegDiagram-XKGWAZYB-CJQClA-K.js.br +0 -0
  148. package/dist/client/assets/pegDiagram-XKGWAZYB-CJQClA-K.js.gz +0 -0
  149. package/dist/client/assets/{pieDiagram-E7YTZNPT-Di_VEsZA.js → pieDiagram-E7YTZNPT-D2ARaSkf.js} +1 -1
  150. package/dist/client/assets/pieDiagram-E7YTZNPT-D2ARaSkf.js.br +0 -0
  151. package/dist/client/assets/pieDiagram-E7YTZNPT-D2ARaSkf.js.gz +0 -0
  152. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-B--Y1EgY.js → quadrantDiagram-AXDQQJYC-B2Rs8gQh.js} +1 -1
  153. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-B--Y1EgY.js.br → quadrantDiagram-AXDQQJYC-B2Rs8gQh.js.br} +0 -0
  154. package/dist/client/assets/quadrantDiagram-AXDQQJYC-B2Rs8gQh.js.gz +0 -0
  155. package/dist/client/assets/{railroadDiagram-O6MQD6OU-CTTF__yz.js → railroadDiagram-O6MQD6OU-7zaEGVqP.js} +1 -1
  156. package/dist/client/assets/railroadDiagram-O6MQD6OU-7zaEGVqP.js.br +0 -0
  157. package/dist/client/assets/railroadDiagram-O6MQD6OU-7zaEGVqP.js.gz +0 -0
  158. package/dist/client/assets/{referenceLongPress-jOxtSE5l.js → referenceLongPress-1MdQQqBu.js} +1 -1
  159. package/dist/client/assets/referenceLongPress-1MdQQqBu.js.br +0 -0
  160. package/dist/client/assets/referenceLongPress-1MdQQqBu.js.gz +0 -0
  161. package/dist/client/assets/{requirementDiagram-BXWQKSXE-DI0C2RWw.js → requirementDiagram-BXWQKSXE-B7YLqxNi.js} +1 -1
  162. package/dist/client/assets/requirementDiagram-BXWQKSXE-B7YLqxNi.js.br +0 -0
  163. package/dist/client/assets/requirementDiagram-BXWQKSXE-B7YLqxNi.js.gz +0 -0
  164. package/dist/client/assets/{sankeyDiagram-P5KCCOFB-W5HRSQpx.js → sankeyDiagram-P5KCCOFB-BQqZ501N.js} +1 -1
  165. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BQqZ501N.js.br +0 -0
  166. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BQqZ501N.js.gz +0 -0
  167. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-BKkAIBat.js → sequenceDiagram-WJ2MYXX4-CI5zNczi.js} +1 -1
  168. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-BKkAIBat.js.br → sequenceDiagram-WJ2MYXX4-CI5zNczi.js.br} +0 -0
  169. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-CI5zNczi.js.gz +0 -0
  170. package/dist/client/assets/{sizeCapture-INFHLROL-DXBwqyIS.js → sizeCapture-INFHLROL-_g6rD1KV.js} +1 -1
  171. package/dist/client/assets/sizeCapture-INFHLROL-_g6rD1KV.js.br +0 -0
  172. package/dist/client/assets/sizeCapture-INFHLROL-_g6rD1KV.js.gz +0 -0
  173. package/dist/client/assets/{sparkles-DceTfvKw.js → sparkles-DZP-rTUQ.js} +1 -1
  174. package/dist/client/assets/{stateDiagram-D77RDMKH-BBVi-dyW.js → stateDiagram-D77RDMKH-Cu8lQyFr.js} +1 -1
  175. package/dist/client/assets/stateDiagram-D77RDMKH-Cu8lQyFr.js.br +0 -0
  176. package/dist/client/assets/stateDiagram-D77RDMKH-Cu8lQyFr.js.gz +0 -0
  177. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-CieARAQ3.js +1 -0
  178. package/dist/client/assets/{swimlanes-42K2YHIH-DwJjgXte.js → swimlanes-42K2YHIH-DyoG1kjH.js} +1 -1
  179. package/dist/client/assets/swimlanes-42K2YHIH-DyoG1kjH.js.br +0 -0
  180. package/dist/client/assets/swimlanes-42K2YHIH-DyoG1kjH.js.gz +0 -0
  181. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-D9qBVMDu.js +8 -0
  182. package/dist/client/assets/{timeline-definition-24CTP7MA-COX39iJ6.js → timeline-definition-24CTP7MA-MgVnEDIt.js} +1 -1
  183. package/dist/client/assets/timeline-definition-24CTP7MA-MgVnEDIt.js.br +0 -0
  184. package/dist/client/assets/timeline-definition-24CTP7MA-MgVnEDIt.js.gz +0 -0
  185. package/dist/client/assets/{triangle-alert-DjtUXw4T.js → triangle-alert-6HTQse_h.js} +1 -1
  186. package/dist/client/assets/{vennDiagram-4TSXK5OY-46HA9L0l.js → vennDiagram-4TSXK5OY-DIA3-8fT.js} +1 -1
  187. package/dist/client/assets/vennDiagram-4TSXK5OY-DIA3-8fT.js.br +0 -0
  188. package/dist/client/assets/vennDiagram-4TSXK5OY-DIA3-8fT.js.gz +0 -0
  189. package/dist/client/assets/videoCompression-BiLlPFCU.js +3 -0
  190. package/dist/client/assets/videoCompression-BiLlPFCU.js.br +0 -0
  191. package/dist/client/assets/videoCompression-BiLlPFCU.js.gz +0 -0
  192. package/dist/client/assets/{wardleyDiagram-VM6X3IG4-DfkGMObP.js → wardleyDiagram-VM6X3IG4-BrgRWH1G.js} +1 -1
  193. package/dist/client/assets/wardleyDiagram-VM6X3IG4-BrgRWH1G.js.br +0 -0
  194. package/dist/client/assets/wardleyDiagram-VM6X3IG4-BrgRWH1G.js.gz +0 -0
  195. package/dist/client/assets/worker-BAOIWoxA.js +1 -0
  196. package/dist/client/assets/worker-BAOIWoxA.js.br +0 -0
  197. package/dist/client/assets/worker-BAOIWoxA.js.gz +0 -0
  198. package/dist/client/assets/{xychartDiagram-S5SC5T6Z-vlKat3e7.js → xychartDiagram-S5SC5T6Z-DbVR2OUc.js} +1 -1
  199. package/dist/client/assets/xychartDiagram-S5SC5T6Z-DbVR2OUc.js.br +0 -0
  200. package/dist/client/assets/xychartDiagram-S5SC5T6Z-DbVR2OUc.js.gz +0 -0
  201. package/dist/client/index.html +44 -4
  202. package/dist/client/index.html.br +0 -0
  203. package/dist/client/index.html.gz +0 -0
  204. package/dist/client/licenses/loading-dev.txt +21 -0
  205. package/dist/client/licenses/loading-dev.txt.br +0 -0
  206. package/dist/client/licenses/loading-dev.txt.gz +0 -0
  207. package/dist/client/sw-encrypted-background.js +1 -1
  208. package/dist/client/sw-encrypted-background.js.br +0 -0
  209. package/dist/client/sw-encrypted-background.js.gz +0 -0
  210. package/dist/client/sw.js +1 -1
  211. package/dist/client/sw.js.br +0 -0
  212. package/dist/client/sw.js.gz +0 -0
  213. package/dist/server/entry.js +38 -1
  214. package/dist/server/routes/terminal.js +2 -1
  215. package/dist/server/utils/runtimeClient.js +34 -0
  216. package/package.json +4 -1
  217. package/runtime-manifest.json +4 -4
  218. package/dist/client/assets/App-VGKzpPWO.js +0 -156
  219. package/dist/client/assets/App-VGKzpPWO.js.br +0 -0
  220. package/dist/client/assets/App-VGKzpPWO.js.gz +0 -0
  221. package/dist/client/assets/ChangeWalkthroughPanel-CpJIxJoa.js.br +0 -0
  222. package/dist/client/assets/ChangeWalkthroughPanel-CpJIxJoa.js.gz +0 -0
  223. package/dist/client/assets/DagPlayground-DsZ_TzMA.js.br +0 -0
  224. package/dist/client/assets/DagPlayground-DsZ_TzMA.js.gz +0 -0
  225. package/dist/client/assets/DiffLab-DVzd5Djx.js.br +0 -0
  226. package/dist/client/assets/DiffLab-DVzd5Djx.js.gz +0 -0
  227. package/dist/client/assets/DiffReview-5MLGwl3s.js.br +0 -0
  228. package/dist/client/assets/DiffReview-5MLGwl3s.js.gz +0 -0
  229. package/dist/client/assets/DiffReviewLab-B53N-9cX.js.br +0 -0
  230. package/dist/client/assets/DiffReviewLab-B53N-9cX.js.gz +0 -0
  231. package/dist/client/assets/DiffViewer-PrcRXQq0.js.br +0 -0
  232. package/dist/client/assets/DiffViewer-PrcRXQq0.js.gz +0 -0
  233. package/dist/client/assets/ModelPreview-C98dbuUF.js.br +0 -0
  234. package/dist/client/assets/ModelPreview-C98dbuUF.js.gz +0 -0
  235. package/dist/client/assets/RightSidebar-B52JGGs9.js.br +0 -0
  236. package/dist/client/assets/RightSidebar-B52JGGs9.js.gz +0 -0
  237. package/dist/client/assets/abnfDiagram-VCTEODGH-B5gA9_Ty.js.br +0 -0
  238. package/dist/client/assets/abnfDiagram-VCTEODGH-B5gA9_Ty.js.gz +0 -0
  239. package/dist/client/assets/app-DnjpR35Q.js +0 -35
  240. package/dist/client/assets/app-DnjpR35Q.js.br +0 -0
  241. package/dist/client/assets/app-DnjpR35Q.js.gz +0 -0
  242. package/dist/client/assets/arc-Bq6Y_399.js.br +0 -0
  243. package/dist/client/assets/arc-Bq6Y_399.js.gz +0 -0
  244. package/dist/client/assets/architectureDiagram-5GKGNRK7-D7bXmRrP.js.br +0 -0
  245. package/dist/client/assets/architectureDiagram-5GKGNRK7-D7bXmRrP.js.gz +0 -0
  246. package/dist/client/assets/blockDiagram-I7D4REHJ-vmiTllrb.js.br +0 -0
  247. package/dist/client/assets/blockDiagram-I7D4REHJ-vmiTllrb.js.gz +0 -0
  248. package/dist/client/assets/c4Diagram-7LVT6UL2-C6ThUVSU.js.gz +0 -0
  249. package/dist/client/assets/channel-DLM_eD7J.js +0 -1
  250. package/dist/client/assets/chunk-F27PBJKO-C7W0s-qY.js.br +0 -0
  251. package/dist/client/assets/chunk-F27PBJKO-C7W0s-qY.js.gz +0 -0
  252. package/dist/client/assets/chunk-IMKFNOWR-CTjPfIKT.js.br +0 -0
  253. package/dist/client/assets/chunk-IMKFNOWR-CTjPfIKT.js.gz +0 -0
  254. package/dist/client/assets/chunk-SVP7TREG-CCuDpBKr.js.br +0 -0
  255. package/dist/client/assets/chunk-SVP7TREG-CCuDpBKr.js.gz +0 -0
  256. package/dist/client/assets/chunk-TICWLB2K-DtYX2TNH.js.br +0 -0
  257. package/dist/client/assets/chunk-TICWLB2K-DtYX2TNH.js.gz +0 -0
  258. package/dist/client/assets/classDiagram-ZZMXUADV-C1zXUzCS.js +0 -1
  259. package/dist/client/assets/classDiagram-v2-VYDZK3BY-C1zXUzCS.js +0 -1
  260. package/dist/client/assets/cose-bilkent-JH36ORCC-CyoiG3NB.js.br +0 -0
  261. package/dist/client/assets/cose-bilkent-JH36ORCC-CyoiG3NB.js.gz +0 -0
  262. package/dist/client/assets/cynefin-OW5HDTMX-SeWSNPvK.js.br +0 -0
  263. package/dist/client/assets/cynefin-OW5HDTMX-SeWSNPvK.js.gz +0 -0
  264. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-C6Z9w461.js.br +0 -0
  265. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-C6Z9w461.js.gz +0 -0
  266. package/dist/client/assets/dagre-GXQ25YYZ-DgQ7oSI3.js.br +0 -0
  267. package/dist/client/assets/dagre-GXQ25YYZ-DgQ7oSI3.js.gz +0 -0
  268. package/dist/client/assets/diagram-S7CK7UJ4-BrFJNnZh.js.br +0 -0
  269. package/dist/client/assets/diagram-S7CK7UJ4-BrFJNnZh.js.gz +0 -0
  270. package/dist/client/assets/diagram-UQ7AKVKN-DW2EFMOu.js.br +0 -0
  271. package/dist/client/assets/diagram-UQ7AKVKN-DW2EFMOu.js.gz +0 -0
  272. package/dist/client/assets/diagram-VSXAHHWV-C5lTJcKk.js.br +0 -0
  273. package/dist/client/assets/diagram-VSXAHHWV-C5lTJcKk.js.gz +0 -0
  274. package/dist/client/assets/diagram-VX7I27RA-CObqcJqB.js.br +0 -0
  275. package/dist/client/assets/diagram-VX7I27RA-CObqcJqB.js.gz +0 -0
  276. package/dist/client/assets/diagram-Z3DM3KII-br3lGnhW.js.br +0 -0
  277. package/dist/client/assets/diagram-Z3DM3KII-br3lGnhW.js.gz +0 -0
  278. package/dist/client/assets/ebnfDiagram-PWID7BFC-CkXxS9Pq.js.br +0 -0
  279. package/dist/client/assets/ebnfDiagram-PWID7BFC-CkXxS9Pq.js.gz +0 -0
  280. package/dist/client/assets/erDiagram-RLTQ6QDP-CMBJEKp-.js.br +0 -0
  281. package/dist/client/assets/erDiagram-RLTQ6QDP-CMBJEKp-.js.gz +0 -0
  282. package/dist/client/assets/flowDiagram-HODETNUW-CuO0cLki.js.br +0 -0
  283. package/dist/client/assets/flowDiagram-HODETNUW-CuO0cLki.js.gz +0 -0
  284. package/dist/client/assets/ganttDiagram-EL5Y4UJY-BIt0Y40Q.js.br +0 -0
  285. package/dist/client/assets/gestureArbiter--6cZMOnD.js.br +0 -0
  286. package/dist/client/assets/gestureArbiter--6cZMOnD.js.gz +0 -0
  287. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-C1ljbYw7.js.br +0 -0
  288. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-C1ljbYw7.js.gz +0 -0
  289. package/dist/client/assets/index-DeTcW7aT.css.br +0 -0
  290. package/dist/client/assets/index-DeTcW7aT.css.gz +0 -0
  291. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Ch5ze9LB.js.br +0 -0
  292. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Ch5ze9LB.js.gz +0 -0
  293. package/dist/client/assets/journeyDiagram-3NMN7TZE-C3vqa0wB.js.br +0 -0
  294. package/dist/client/assets/journeyDiagram-3NMN7TZE-C3vqa0wB.js.gz +0 -0
  295. package/dist/client/assets/kanban-definition-UXKFOSKX-rEL2pKx0.js.br +0 -0
  296. package/dist/client/assets/kanban-definition-UXKFOSKX-rEL2pKx0.js.gz +0 -0
  297. package/dist/client/assets/layout-CeDdQRYz.js.br +0 -0
  298. package/dist/client/assets/layout-CeDdQRYz.js.gz +0 -0
  299. package/dist/client/assets/linear-C9xkTlXu.js.br +0 -0
  300. package/dist/client/assets/linear-C9xkTlXu.js.gz +0 -0
  301. package/dist/client/assets/mermaid.core-CIW1IDpX.js.br +0 -0
  302. package/dist/client/assets/mermaid.core-CIW1IDpX.js.gz +0 -0
  303. package/dist/client/assets/mindmap-definition-YA3MSWOX-CT9M_dpw.js.br +0 -0
  304. package/dist/client/assets/mindmap-definition-YA3MSWOX-CT9M_dpw.js.gz +0 -0
  305. package/dist/client/assets/passwordBootstrap-B8awl9Cz.js.br +0 -0
  306. package/dist/client/assets/passwordBootstrap-B8awl9Cz.js.gz +0 -0
  307. package/dist/client/assets/pegDiagram-XKGWAZYB-BkaUHxk6.js.br +0 -0
  308. package/dist/client/assets/pegDiagram-XKGWAZYB-BkaUHxk6.js.gz +0 -0
  309. package/dist/client/assets/pieDiagram-E7YTZNPT-Di_VEsZA.js.br +0 -0
  310. package/dist/client/assets/pieDiagram-E7YTZNPT-Di_VEsZA.js.gz +0 -0
  311. package/dist/client/assets/quadrantDiagram-AXDQQJYC-B--Y1EgY.js.gz +0 -0
  312. package/dist/client/assets/railroadDiagram-O6MQD6OU-CTTF__yz.js.br +0 -0
  313. package/dist/client/assets/railroadDiagram-O6MQD6OU-CTTF__yz.js.gz +0 -0
  314. package/dist/client/assets/referenceLongPress-jOxtSE5l.js.br +0 -0
  315. package/dist/client/assets/referenceLongPress-jOxtSE5l.js.gz +0 -0
  316. package/dist/client/assets/requirementDiagram-BXWQKSXE-DI0C2RWw.js.br +0 -0
  317. package/dist/client/assets/requirementDiagram-BXWQKSXE-DI0C2RWw.js.gz +0 -0
  318. package/dist/client/assets/sankeyDiagram-P5KCCOFB-W5HRSQpx.js.br +0 -0
  319. package/dist/client/assets/sankeyDiagram-P5KCCOFB-W5HRSQpx.js.gz +0 -0
  320. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BKkAIBat.js.gz +0 -0
  321. package/dist/client/assets/sizeCapture-INFHLROL-DXBwqyIS.js.br +0 -0
  322. package/dist/client/assets/sizeCapture-INFHLROL-DXBwqyIS.js.gz +0 -0
  323. package/dist/client/assets/stateDiagram-D77RDMKH-BBVi-dyW.js.br +0 -0
  324. package/dist/client/assets/stateDiagram-D77RDMKH-BBVi-dyW.js.gz +0 -0
  325. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-DjAtlfPn.js +0 -1
  326. package/dist/client/assets/swimlanes-42K2YHIH-DwJjgXte.js.br +0 -0
  327. package/dist/client/assets/swimlanes-42K2YHIH-DwJjgXte.js.gz +0 -0
  328. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-BRWkDBH5.js +0 -8
  329. package/dist/client/assets/timeline-definition-24CTP7MA-COX39iJ6.js.br +0 -0
  330. package/dist/client/assets/timeline-definition-24CTP7MA-COX39iJ6.js.gz +0 -0
  331. package/dist/client/assets/vennDiagram-4TSXK5OY-46HA9L0l.js.br +0 -0
  332. package/dist/client/assets/vennDiagram-4TSXK5OY-46HA9L0l.js.gz +0 -0
  333. package/dist/client/assets/wardleyDiagram-VM6X3IG4-DfkGMObP.js.br +0 -0
  334. package/dist/client/assets/wardleyDiagram-VM6X3IG4-DfkGMObP.js.gz +0 -0
  335. package/dist/client/assets/xychartDiagram-S5SC5T6Z-vlKat3e7.js.br +0 -0
  336. package/dist/client/assets/xychartDiagram-S5SC5T6Z-vlKat3e7.js.gz +0 -0
@@ -1,17 +1,17 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-C98dbuUF.js","assets/app-DnjpR35Q.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-DeTcW7aT.css","assets/App-VGKzpPWO.js","assets/gestureArbiter--6cZMOnD.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-DjtUXw4T.js","assets/referenceLongPress-jOxtSE5l.js","assets/DiffReview-5MLGwl3s.js","assets/sparkles-DceTfvKw.js","assets/DiffViewer-PrcRXQq0.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-CpJIxJoa.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-CIW1IDpX.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
- import{a6 as Tr,cM as St,bi as e,g as lo,cW as At,bA as mt,a as Bs,aR as uu,C as Hi,c as Os,X as Yt,cJ as ro,b6 as qh,G as Cs,ap as Yh,cQ as J,ba as Xh,bc as dl,bd as Jh,be as fu,bb as Ns,aC as Qh,E as Zh,i as em,b9 as tm,bC as rm,bE as nm,bF as sm,b1 as am,bD as dd,F as Ct,f as om,L as Nt,x as im,b as lm,cL as yi,b0 as ud,ay as fd,au as cm,aG as wi,aH as hd,cX as Is,al as Ms,aI as dm,cK as Ha,bu as um,cv as md,aA as fm,cH as hm,c3 as mm,aL as pm,R as pd,Q as gm,av as gd,az as bm,aE as bd,c5 as xm,t as xd,d as za,m as vd,y as hu,ag as vm,_ as Us,bZ as ym,cU as wm,bp as km,aj as Sm}from"./app-DnjpR35Q.js";import{b as a,r as qr}from"./dnd-BCFAPC0L.js";import{q as mu,k as jm,r as yd,v as no,g as Rm,V as Cm,P as Nm,o as Mm,i as Em,M as $m,R as so,w as pu,x as Am,S as Qn,D as Lm,e as gu,c as Pm,N as bu,A as ki,J as Tm,E as wn,y as Im,z as Dm,I as Fm,K as _m,B as wd,O as kd,T as Sd,H as jd,f as Rd,n as Si,m as Wa,d as Bm,s as Om,l as Um,h as Hm,t as zm,F as Cd,C as Wm,a as Gm,G as Km}from"./App-VGKzpPWO.js";import{a as Nd,S as Md,b as xu,c as zi,F as Vm}from"./gestureArbiter--6cZMOnD.js";import{D as Wi,C as Ds,L as vu,f as qm,n as Ym}from"./DiffReview-5MLGwl3s.js";import{T as Xm,L as co,M as yu,G as Pr}from"./triangle-alert-DjtUXw4T.js";import{S as Hs}from"./sparkles-DceTfvKw.js";import{C as wu,M as ku}from"./ChangeWalkthroughPanel-CpJIxJoa.js";import{r as Su,s as ju,l as Ru,a as Ed,h as Gi,u as Jm,g as Ki,b as Cu}from"./DiffViewer-PrcRXQq0.js";import{u as Nu,G as Mu}from"./referenceLongPress-jOxtSE5l.js";const Qm=[["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"}]],Zm=Tr("case-sensitive",Qm);const ep=[["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"}]],tp=Tr("eye-off",ep);const rp=[["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"}]],Vi=Tr("eye",rp);const np=[["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"}]],qi=Tr("file-text",np);const sp=[["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"}]],ap=Tr("image-plus",sp);const op=[["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"}]],ip=Tr("regex",op);const lp=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],cp=Tr("scan",lp);const dp=[["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"}]],up=Tr("upload",dp);const fp=[["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"}]],hp=Tr("whole-word",fp);function $d({children:r,actions:n}){const{t:s}=St(),[l,u]=a.useState(!1),d=a.useId(),h=a.useRef(null);return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:h,type:"button","aria-expanded":l,"aria-controls":d,onClick:()=>u(g=>!g),className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${l?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(lo,{size:14}),s("sidebar.moreActions")]})]}),l&&e.jsx("div",{id:d,role:"region","aria-label":s("sidebar.moreActions"),className:"mt-2 flex flex-wrap items-center gap-2 rounded-xl border border-border/15 bg-surface-2 p-2 [&_button]:min-h-9",onKeyDown:g=>{g.key!=="Escape"||!g.currentTarget.contains(g.target)||(g.stopPropagation(),u(!1),h.current?.focus())},children:n})]})}async function mp(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function pp({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:u,load:d}){a.useEffect(()=>{if(!r||!n||s||u.current===n)return;const h=window.setTimeout(()=>{u.current=n,d(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,u,d])}function gp(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,u=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!u)return Promise.resolve(null);const d=r instanceof HTMLImageElement?1400/Math.max(l,u):Math.min(1,1400/Math.max(l,u)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*d)),h.height=Math.max(1,Math.round(u*d));const g=h.getContext("2d");if(!g)return Promise.resolve(null);const m=getComputedStyle(document.documentElement);if(g.fillStyle=m.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,h.height),g.drawImage(r,0,0,h.width,h.height),s){const b=Math.max(10,Math.min(16,h.width/35));g.font=`${b}px sans-serif`;const f=[];let j="";for(const w of s.split(" "))j&&g.measureText(`${j} ${w}`).width>h.width-20?(f.push(j),j=w):j=j?`${j} ${w}`:w;j&&f.push(j),g.fillStyle=m.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,f.length*(b+4)+12),g.fillStyle=m.getPropertyValue("--foreground").trim()||"black",f.forEach((w,M)=>g.fillText(w,10,8+b+M*(b+4)))}if(n){const b=n.xPercent*h.width/100,f=n.yPercent*h.height/100,j=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),w=j*1.6;g.strokeStyle=m.getPropertyValue("--primary").trim()||"black",g.lineWidth=Math.max(1,j/3),g.beginPath(),g.arc(b,f,j,0,Math.PI*2),g.stroke(),g.beginPath(),g.moveTo(b-w,f),g.lineTo(b+w,f),g.moveTo(b,f-w),g.lineTo(b,f+w),g.stroke()}return new Promise(b=>h.toBlob(b,"image/png"))}catch{return Promise.resolve(null)}}function bp(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
- `)}function px(r,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(u)*1.15}async function xp(r,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(r,n);return}const u=new Date().toISOString(),d=new AbortController;let h,g;try{g=await Promise.race([(async()=>{const m=await s.snapshot;if(!(!m||d.signal.aborted||!l.isCurrent()))return l.upload(new File([m],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),d.signal)})(),new Promise(m=>{h=setTimeout(()=>{d.abort(),m(void 0)},3e3)})])}catch{}finally{clearTimeout(h),d.abort()}l.isCurrent()&&l.insert(g?bp(r,"",u,g):r,n)}function vp(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function Ad(r,n){return`${r??""}\0${n}`}function yp(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=Ad(n,s);let u=0,d=0;for(const h of r){const g=[h.filePath,h.newPath,h.oldPath].filter(b=>typeof b=="string"&&b.length>0);(g.some(b=>Ad(h.repoRoot,b)===l)||g.some(b=>vp(b,s)))&&(u+=1)}return{explained:u,stale:d}}function wp({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(Xm,{size:10}):e.jsx(Hs,{size:10})})}function Yi({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(wp,{status:n})]})}const Eu="termdock:right-sidebar:diff-change-list-mode:v1";function kp(r){return r==="list"||r==="tree"}function Sp(){return mt(Eu,kp)??"tree"}function jp(r){for(const l of r){const u=l.hunk;if(u.oldPath&&u.newPath&&u.oldPath!==u.newPath)return"renamed";if(!u.oldPath&&u.newPath)return"added";if(u.oldPath&&!u.newPath)return"deleted"}const n=r.some(l=>l.hunk.additions>0),s=r.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function Rp(r){const n=new Map;for(const l of r){const u=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};u.items.push(l),u.additions+=l.hunk.additions,u.deletions+=l.hunk.deletions,l.current&&(u.explained+=1),l.stale&&(u.stale+=1),n.set(l.hunk.filePath,u)}const s=Array.from(n.values()).sort((l,u)=>l.filePath.localeCompare(u.filePath));for(const l of s)l.changeType=jp(l.items);return s}function Cp(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 Np(r,n){const s=r.filter(d=>d.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],u=new Set;for(const[d,h]of s.entries()){const g=h.split(`
4
- `),m=g.findIndex(j=>j.startsWith("@@ "));if(m<0){l.push(...g);continue}d===0&&l.push(...g.slice(0,m));const b=n[d];let f=m;for(;f>=0&&f<g.length;){const j=g.findIndex((E,$)=>$>f&&E.startsWith("@@ ")),w=j>=0?j:g.length,M=g.slice(f,w),I=M[0]??"",_=b?I===b:!0,B=I||b||M.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-BgzcGTC4.js","assets/app-Cx1S0NEn.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-IknuJMxJ.css","assets/App-KjvxjYWp.js","assets/gestureArbiter-CDxeAcBI.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-6HTQse_h.js","assets/referenceLongPress-1MdQQqBu.js","assets/DiffReview-B4MgHev_.js","assets/sparkles-DZP-rTUQ.js","assets/DiffViewer-B5Fj1S7h.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-D0dLmuqS.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-BMjyQhe0.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
+ import{a7 as Tr,cO as St,bk as e,g as lo,cY as At,bC as mt,a as Bs,aS as fu,C as zi,c as Os,X as Yt,cL as ro,b8 as Yh,H as Cs,aq as Xh,cS as J,bc as Jh,be as ul,bf as Zh,bg as hu,bd as Ns,aD as Qh,E as em,j as tm,bb as rm,bE as nm,bG as sm,bH as am,b3 as om,bF as ud,G as Ct,f as im,L as Nt,i as wi,y as lm,b as cm,cN as yi,b2 as fd,az as hd,av as dm,aH as ki,aI as md,cZ as Is,am as Ms,aJ as um,cM as Ha,bw as fm,cx as pd,aB as hm,cJ as mm,c5 as pm,aM as gm,U as gd,R as bm,aw as bd,aA as xm,aF as xd,c7 as vm,u as vd,d as za,n as wd,z as mu,ah as wm,_ as Us,b$ as ym,cW as km,br as Sm,ak as jm}from"./app-Cx1S0NEn.js";import{b as a,r as qr}from"./dnd-BCFAPC0L.js";import{q as pu,k as Rm,r as yd,v as no,g as Cm,V as Nm,P as Mm,o as Em,i as $m,M as Am,R as so,w as gu,x as Lm,S as Zn,D as Pm,e as bu,c as Tm,N as xu,A as Si,J as Im,E as yn,y as Dm,z as Fm,I as _m,K as Bm,B as kd,O as Sd,T as jd,H as Rd,f as Cd,n as ji,m as Wa,d as Om,s as Um,l as Hm,h as zm,t as Wm,F as Nd,C as Gm,a as Km,G as Vm}from"./App-KjvxjYWp.js";import{a as Md,S as Ed,b as vu,c as Wi,F as qm}from"./gestureArbiter-CDxeAcBI.js";import{D as Gi,C as Ds,L as wu,f as Ym,n as Xm}from"./DiffReview-B4MgHev_.js";import{T as Jm,L as co,M as yu,G as Pr}from"./triangle-alert-6HTQse_h.js";import{S as Hs}from"./sparkles-DZP-rTUQ.js";import{C as ku,M as Su}from"./ChangeWalkthroughPanel-D0dLmuqS.js";import{r as ju,s as Ru,l as Cu,a as $d,h as Ki,u as Zm,g as Vi,b as Nu}from"./DiffViewer-B5Fj1S7h.js";import{u as Mu,G as Eu}from"./referenceLongPress-1MdQQqBu.js";const Qm=[["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"}]],ep=Tr("case-sensitive",Qm);const tp=[["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"}]],rp=Tr("eye-off",tp);const np=[["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"}]],qi=Tr("eye",np);const sp=[["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"}]],Yi=Tr("file-text",sp);const ap=[["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"}]],op=Tr("image-plus",ap);const ip=[["path",{d:"M17 3v10",key:"15fgeh"}],["path",{d:"m12.67 5.5 8.66 5",key:"1gpheq"}],["path",{d:"m12.67 10.5 8.66-5",key:"1dkfa6"}],["path",{d:"M9 17a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2v-2z",key:"swwfx4"}]],lp=Tr("regex",ip);const cp=[["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"}]],dp=Tr("scan",cp);const up=[["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"}]],fp=Tr("upload",up);const hp=[["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"}]],mp=Tr("whole-word",hp);function Ad({children:r,actions:n}){const{t:s}=St(),[l,u]=a.useState(!1),d=a.useId(),h=a.useRef(null);return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r,e.jsxs("button",{ref:h,type:"button","aria-expanded":l,"aria-controls":d,onClick:()=>u(g=>!g),className:`ml-auto inline-flex h-8 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${l?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx(lo,{size:14}),s("sidebar.moreActions")]})]}),l&&e.jsx("div",{id:d,role:"region","aria-label":s("sidebar.moreActions"),className:"mt-2 flex flex-wrap items-center gap-2 rounded-xl border border-border/15 bg-surface-2 p-2 [&_button]:min-h-9",onKeyDown:g=>{g.key!=="Escape"||!g.currentTarget.contains(g.target)||(g.stopPropagation(),u(!1),h.current?.focus())},children:n})]})}async function pp(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function gp({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:u,load:d}){a.useEffect(()=>{if(!r||!n||s||u.current===n)return;const h=window.setTimeout(()=>{u.current=n,d(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,u,d])}function bp(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,u=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!u)return Promise.resolve(null);const d=r instanceof HTMLImageElement?1400/Math.max(l,u):Math.min(1,1400/Math.max(l,u)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*d)),h.height=Math.max(1,Math.round(u*d));const g=h.getContext("2d");if(!g)return Promise.resolve(null);const m=getComputedStyle(document.documentElement);if(g.fillStyle=m.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,h.height),g.drawImage(r,0,0,h.width,h.height),s){const b=Math.max(10,Math.min(16,h.width/35));g.font=`${b}px sans-serif`;const f=[];let j="";for(const y of s.split(" "))j&&g.measureText(`${j} ${y}`).width>h.width-20?(f.push(j),j=y):j=j?`${j} ${y}`:y;j&&f.push(j),g.fillStyle=m.getPropertyValue("--surface").trim()||"white",g.fillRect(0,0,h.width,f.length*(b+4)+12),g.fillStyle=m.getPropertyValue("--foreground").trim()||"black",f.forEach((y,M)=>g.fillText(y,10,8+b+M*(b+4)))}if(n){const b=n.xPercent*h.width/100,f=n.yPercent*h.height/100,j=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=j*1.6;g.strokeStyle=m.getPropertyValue("--primary").trim()||"black",g.lineWidth=Math.max(1,j/3),g.beginPath(),g.arc(b,f,j,0,Math.PI*2),g.stroke(),g.beginPath(),g.moveTo(b-y,f),g.lineTo(b+y,f),g.moveTo(b,f-y),g.lineTo(b,f+y),g.stroke()}return new Promise(b=>h.toBlob(b,"image/png"))}catch{return Promise.resolve(null)}}function xp(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
+ `)}function gx(r,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(u)*1.15}async function vp(r,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(r,n);return}const u=new Date().toISOString(),d=new AbortController;let h,g;try{g=await Promise.race([(async()=>{const m=await s.snapshot;if(!(!m||d.signal.aborted||!l.isCurrent()))return l.upload(new File([m],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),d.signal)})(),new Promise(m=>{h=setTimeout(()=>{d.abort(),m(void 0)},3e3)})])}catch{}finally{clearTimeout(h),d.abort()}l.isCurrent()&&l.insert(g?xp(r,"",u,g):r,n)}function wp(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function Ld(r,n){return`${r??""}\0${n}`}function yp(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=Ld(n,s);let u=0,d=0;for(const h of r){const g=[h.filePath,h.newPath,h.oldPath].filter(b=>typeof b=="string"&&b.length>0);(g.some(b=>Ld(h.repoRoot,b)===l)||g.some(b=>wp(b,s)))&&(u+=1)}return{explained:u,stale:d}}function kp({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(Jm,{size:10}):e.jsx(Hs,{size:10})})}function Xi({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(kp,{status:n})]})}const $u="termdock:right-sidebar:diff-change-list-mode:v1";function Sp(r){return r==="list"||r==="tree"}function jp(){return mt($u,Sp)??"tree"}function Rp(r){for(const l of r){const u=l.hunk;if(u.oldPath&&u.newPath&&u.oldPath!==u.newPath)return"renamed";if(!u.oldPath&&u.newPath)return"added";if(u.oldPath&&!u.newPath)return"deleted"}const n=r.some(l=>l.hunk.additions>0),s=r.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function Cp(r){const n=new Map;for(const l of r){const u=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};u.items.push(l),u.additions+=l.hunk.additions,u.deletions+=l.hunk.deletions,l.current&&(u.explained+=1),l.stale&&(u.stale+=1),n.set(l.hunk.filePath,u)}const s=Array.from(n.values()).sort((l,u)=>l.filePath.localeCompare(u.filePath));for(const l of s)l.changeType=Rp(l.items);return s}function Np(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 Mp(r,n){const s=r.filter(d=>d.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],u=new Set;for(const[d,h]of s.entries()){const g=h.split(`
4
+ `),m=g.findIndex(j=>j.startsWith("@@ "));if(m<0){l.push(...g);continue}d===0&&l.push(...g.slice(0,m));const b=n[d];let f=m;for(;f>=0&&f<g.length;){const j=g.findIndex((E,$)=>$>f&&E.startsWith("@@ ")),y=j>=0?j:g.length,M=g.slice(f,y),I=M[0]??"",_=b?I===b:!0,B=I||b||M.join(`
5
5
  `);_&&!u.has(B)&&(l.push(...M),u.add(B)),f=j}}return l.join(`
6
- `)}function Mp({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Np(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),u=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),d=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-d.length-1):"",g=s.items[0]?.repoRoot??u[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:d,displayDir:h,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(m=>m.hunk.previewRevert?[[m.hunk.hunkHeader,m.hunk.previewRevert]]:[])),auditRecords:u,onInsertDiffReference:n}})}function Ep(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const d=r.getBoundingClientRect().top+48;let h=null,g=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<d)continue;const j=Math.abs(f.top-d);j<g&&(h=b,g=j)}const m=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!m||m===n||s(m),m}function Ld({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:u=!1,backLabel:d="Back",headerTitle:h,headerMeta:g,onClose:m,closeLabel:b="Back",wrap:f=!0,diffViewType:j,inlineMode:w,viewControls:M,onToggleWrap:I,wrapTitle:_,wrapOnLabel:B="Wrap on",wrapOffLabel:E="Wrap off",desktopLayout:$="split",onInsertDiffReference:A,onReferenceCopied:T,renderPathReference:U,insertedReferenceKey:D,copiedReferenceKey:p,onClearAuditRecord:i,onRefresh:O,localOptions:C,onHunkGitAction:K,error:de,refreshing:te,actionsBusy:xe,refreshLabel:W,refreshTitle:X,walkthroughs:L=[],onWalkthroughNavigate:F,initialDetailScrollTop:V,onDetailScrollPositionChange:re,scrollToKey:ie,scrollToKeyNonce:ye,externalSwiperRef:pe,onMobileSlideChange:De}){const{t:N}=St(),q=a.useMemo(()=>Rp(r),[r]),he=a.useMemo(()=>new Map(q.map(oe=>[oe.key,oe])),[q]),[Ae,Ze]=a.useState(()=>Sp()),[Le,at]=a.useState(()=>new Set),[Be,R]=a.useState({key:null,nonce:0}),ee=q.find(oe=>oe.explained>0||oe.stale>0)?.key??q[0]?.key??null,le=n&&q.some(oe=>oe.key===n)?n:ee,Ee=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:q.map(Cp)}],[q]),Ne=a.useMemo(()=>Mp({groups:q,onInsertDiffReference:A}),[q,A]),We=a.useRef(ee),ce=a.useRef(s);We.current=ee,ce.current=s,a.useEffect(()=>{!n&&We.current&&ce.current(We.current)},[n]);const Pe=I?e.jsxs("button",{type:"button",onClick:I,"aria-pressed":f,title:_,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?B:E})]}):null,tt=C?.map(oe=>e.jsxs("label",{title:oe.disabled?N("rightSidebar.includeUncommittedCurrentBranchOnly"):oe.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:oe.checked,disabled:te||xe||oe.disabled&&!oe.checked,onChange:Ie=>oe.onChange(Ie.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[oe.label," · ",N("rightSidebar.includeUncommitted"),oe.disabled&&e.jsx("span",{className:"block text-[10px]",children:N("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},oe.key)),Te=de?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:de}):null,ke=O?e.jsxs("button",{type:"button",onClick:O,disabled:te||xe,title:X??W,"aria-label":X??W,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(mu,{size:12,className:te?"animate-spin":""}),W&&e.jsx("span",{children:W})]}):null,rt=oe=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),m&&e.jsxs("button",{type:"button",onClick:m,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(Bs,{size:14}),b]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[oe,tt,ke,M,Pe,Te]})]});if(r.length===0){const oe=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!m?oe:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[rt(null),oe]})}const nt=I||O?({slideToList:oe})=>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:oe,children:[e.jsx(Bs,{size:14}),d]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[tt,ke,M,I&&e.jsxs("button",{type:"button",onClick:I,"aria-pressed":f,title:_,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?B:E})]})]}),Te]}):void 0;return e.jsx(Wi,{mobile:u,preserveScrollOnUpdate:!!C?.length,desktopLayout:$,backLabel:d,groups:Ee,selectedKey:le,mode:Ae,onModeChange:oe=>{Ze(oe),oe!=="ai"&&At(Eu,oe)},compact:u,collapsedDirectoryKeys:Le,onToggleDirectory:oe=>{at(Ie=>{const ze=new Set(Ie);return ze.has(oe)?ze.delete(oe):ze.add(oe),ze})},onSelectFile:oe=>{s(oe.key),R(Ie=>({key:oe.key,nonce:Ie.nonce+1}))},renderLeading:oe=>{const Ie=he.get(oe.key);return e.jsx(Yi,{changeStatus:oe.status,auditStatus:Ie,renderChangeBadge:ze=>e.jsx(Ds,{status:ze})})},renderTrailing:oe=>{const Ie=he.get(oe.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[Ie&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Ie.additions," -",Ie.deletions]}),U?.(oe.path,"file")]})},renderDirectoryTrailing:oe=>U?.(oe,"directory"),renderListHeader:rt,aiContent:({slideToDetail:oe,fullscreen:Ie,toggleFullscreen:ze})=>L.length>0&&F?e.jsx(wu,{walkthroughs:L,repoRoot:L[0]?.repoRoot,fullscreen:Ie,onToggleFullscreen:ze,onNavigate:_t=>{u&&window.requestAnimationFrame(oe),F(_t)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:N("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:nt,externalSwiperRef:pe,onMobileSlideChange:De,detailContainerClassName:u?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:V,scrollToKey:ie??Be.key,scrollToKeyNonce:ie==null?Be.nonce:ye,onDetailScroll:oe=>{Ep(oe,le,s),re?.(oe.scrollTop)},files:Ne,activePane:!0,wrap:f,diffViewType:j,inlineMode:w,renderStreamBadge:(oe,Ie)=>{const ze=he.get(Ie.key);return e.jsx(Yi,{changeStatus:oe,auditStatus:ze,renderChangeBadge:_t=>e.jsx(Ds,{status:_t})})},onInsertDiffReference:A,onReferenceCopied:T,insertedReferenceKey:D,copiedReferenceKey:p,onClearAuditRecord:i,onHunkGitAction:te?void 0:K,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function $p(r){return r.replace(/\/+$/,"")||"/"}function Ap(r){return[...new Set(Array.from(r,$p))].sort((n,s)=>n.localeCompare(s))}function Lp(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function Pp(r){let n=null;return{applicableEvents:r.filter(l=>{const u=l.type==="rescan-required"&&!Lp(l.reason);return u&&l.reason&&!n&&(n=l.reason),!u}),unavailableReason:n}}const Tp=1400,Ip=1200,$u=44,Dp=.7;function ji(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function Xi(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function Fp(r){try{const n=window.localStorage.getItem(Xi(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=$u?s:null}catch{return null}}function Pd(r,n){try{n===null?window.localStorage.removeItem(Xi(r)):window.localStorage.setItem(Xi(r),String(n))}catch{}}function Ga(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function _p({value:r,collapsed:n,labels:s,focusRequest:l,insertError:u,autoCollapseAfterSend:d,onChange:h,onCollapsedChange:g,onAutoCollapseAfterSendChange:m,onDisable:b,onClear:f,onInsert:j,onInsertAndSend:w}){const[M,I]=a.useState(null),[_,B]=a.useState(!1),[E,$]=a.useState(()=>Fp(ji())),A=a.useRef(E),T=a.useRef(null),U=a.useRef(null),D=a.useRef(r),p=a.useRef(null),i=a.useRef(null),O=!!r.trim(),C=r.trim().split(`
7
- `)[0]??"",K=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{T.current!==null&&window.clearTimeout(T.current),U.current!==null&&window.clearTimeout(U.current)},[]),a.useEffect(()=>{let N=!1;const q=ji();return uu().then(he=>{if(N)return;const Ae=he.contextDraftHeight?.[q]??null;Pd(q,Ae),A.current=Ae,$(Ae)}).catch(()=>{}),()=>{N=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const N=p.current;if(!N)return;Ga()||N.focus(),N.setSelectionRange(N.value.length,N.value.length),N.scrollTop=N.scrollHeight}},[l]),a.useEffect(()=>{const N=D.current;D.current=r,!(!n||r.length<=N.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},Ip))},[r,n]),a.useEffect(()=>{if(n)return;const N=p.current;N&&(N.style.height=E!==null?`${E}px`:"")},[r,n,E]),a.useEffect(()=>{if(n)return;const N=p.current;!N||document.activeElement===N||(N.scrollTop=N.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||Ga())return;const N=p.current;!N||document.activeElement===N||(N.focus(),N.setSelectionRange(N.value.length,N.value.length))},[n]);const de=a.useRef(null);a.useLayoutEffect(()=>{if(!Ga())return;const N=window.visualViewport;if(!N)return;const q=()=>{const he=de.current;if(!he)return;if(N.height>=window.innerHeight*.75){he.style.transform="";return}const Ae=he.getBoundingClientRect(),Ze=Math.round(N.height-Ae.bottom);he.style.transform=Ze!==0?`translateY(${Ze}px)`:""};return q(),N.addEventListener("resize",q),N.addEventListener("scroll",q),()=>{N.removeEventListener("resize",q),N.removeEventListener("scroll",q),de.current&&(de.current.style.transform="")}},[n]);const te=N=>{I(N),T.current!==null&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{T.current=null,I(null)},Tp)},xe=N=>{g(!1),Ga()&&window.requestAnimationFrame(()=>{const q=p.current;if(!q)return;q.focus();const he=q.value.length;q.setSelectionRange(he,he),window.requestAnimationFrame(()=>{q.setSelectionRange(he,he)})})},W=()=>{j(),te("inserted")},X=()=>{O&&(w(),te("sent"))},L=N=>{if(N.key==="Escape"){N.preventDefault(),g(!0);return}N.key!=="Enter"||!N.metaKey&&!N.ctrlKey||(N.preventDefault(),X())},F=N=>{N.preventDefault()},V=N=>{N.preventDefault();const q=p.current;q&&(i.current={startY:N.clientY,startHeight:q.getBoundingClientRect().height},N.currentTarget.setPointerCapture?.(N.pointerId))},re=N=>{const q=i.current;if(!q)return;const he=window.visualViewport?.height??window.innerHeight,Ae=Math.round(Math.min(Math.max(q.startHeight+(q.startY-N.clientY),$u),he*Dp));A.current=Ae,$(Ae)},ie=N=>{const q=ji();Pd(q,N),ro({contextDraftHeight:{[q]:N}}).catch(()=>{})},ye=()=>{i.current&&(i.current=null,A.current!==null&&ie(A.current))},pe=()=>{A.current=null,$(null),ie(null)},De=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:de,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:()=>xe(),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(jm,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${u?"text-destructive":_?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:u??(_?s.appended:O?C:s.title)})]}),De,e.jsx("button",{type:"button",onClick:X,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:M==="sent"?e.jsx(Hi,{size:12}):e.jsx(yd,{size:12})})]})}):e.jsxs("section",{ref:de,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:V,onPointerMove:re,onPointerUp:ye,onPointerCancel:ye,onDoubleClick:pe,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:F,onClick:()=>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(Os,{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}),De]}),e.jsx("button",{type:"button",role:"switch","aria-checked":d,onPointerDown:F,onClick:()=>m(!d),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${d?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${d?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:F,onClick:b,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Yt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:p,value:r,onChange:N=>h(N.target.value),onKeyDown:L,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:F,onClick:f,disabled:!O,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(no,{size:11})}),u?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:u}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:W,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(Rm,{size:11}),e.jsx("span",{children:M==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:X,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${s.insertAndSend} · ${K}`,children:[M==="sent"?e.jsx(Hi,{size:11}):e.jsx(yd,{size:11}),e.jsx("span",{children:M==="sent"?s.sent:s.send})]})]})]})})]})}function Bp(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
6
+ `)}function Ep({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=Mp(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),u=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),d=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-d.length-1):"",g=s.items[0]?.repoRoot??u[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:d,displayDir:h,diffOverride:l,oldSourceRef:s.items[0]?.current?.headRef?`${s.items[0].current.baseRef}...${s.items[0].current.headRef}`:s.items[0]?.stale?.headRef?`${s.items[0].stale.baseRef}...${s.items[0].stale.headRef}`:void 0,previewReverts:Object.fromEntries(s.items.flatMap(m=>m.hunk.previewRevert?[[m.hunk.hunkHeader,m.hunk.previewRevert]]:[])),auditRecords:u,onInsertDiffReference:n}})}function $p(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const d=r.getBoundingClientRect().top+48;let h=null,g=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<d)continue;const j=Math.abs(f.top-d);j<g&&(h=b,g=j)}const m=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!m||m===n||s(m),m}function Pd({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:u=!1,backLabel:d="Back",headerTitle:h,headerMeta:g,onClose:m,closeLabel:b="Back",wrap:f=!0,diffViewType:j,inlineMode:y,viewControls:M,onToggleWrap:I,wrapTitle:_,wrapOnLabel:B="Wrap on",wrapOffLabel:E="Wrap off",desktopLayout:$="split",onInsertDiffReference:A,onReferenceCopied:T,renderPathReference:U,insertedReferenceKey:D,copiedReferenceKey:p,onClearAuditRecord:i,onRefresh:O,localOptions:C,onHunkGitAction:K,error:de,refreshing:te,actionsBusy:xe,refreshLabel:W,refreshTitle:X,walkthroughs:L=[],onWalkthroughNavigate:F,initialDetailScrollTop:V,onDetailScrollPositionChange:re,scrollToKey:ie,scrollToKeyNonce:we,externalSwiperRef:pe,onMobileSlideChange:De}){const{t:N}=St(),q=a.useMemo(()=>Cp(r),[r]),he=a.useMemo(()=>new Map(q.map(oe=>[oe.key,oe])),[q]),[Ae,Qe]=a.useState(()=>jp()),[Le,at]=a.useState(()=>new Set),[Be,R]=a.useState({key:null,nonce:0}),ee=q.find(oe=>oe.explained>0||oe.stale>0)?.key??q[0]?.key??null,le=n&&q.some(oe=>oe.key===n)?n:ee,Ee=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:q.map(Np)}],[q]),Ne=a.useMemo(()=>Ep({groups:q,onInsertDiffReference:A}),[q,A]),We=a.useRef(ee),ce=a.useRef(s);We.current=ee,ce.current=s,a.useEffect(()=>{!n&&We.current&&ce.current(We.current)},[n]);const Pe=I?e.jsxs("button",{type:"button",onClick:I,"aria-pressed":f,title:_,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?B:E})]}):null,tt=C?.map(oe=>e.jsxs("label",{title:oe.disabled?N("rightSidebar.includeUncommittedCurrentBranchOnly"):oe.key,className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:oe.checked,disabled:te||xe||oe.disabled&&!oe.checked,onChange:Ie=>oe.onChange(Ie.target.checked),className:"accent-primary"}),e.jsxs("span",{children:[oe.label," · ",N("rightSidebar.includeUncommitted"),oe.disabled&&e.jsx("span",{className:"block text-[10px]",children:N("rightSidebar.includeUncommittedCurrentBranchOnly")})]})]},oe.key)),Te=de?e.jsx("div",{role:"alert",className:"w-full text-xs text-destructive",children:de}):null,ke=O?e.jsxs("button",{type:"button",onClick:O,disabled:te||xe,title:X??W,"aria-label":X??W,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(pu,{size:12,className:te?"animate-spin":""}),W&&e.jsx("span",{children:W})]}):null,rt=oe=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),g&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:g})]}),m&&e.jsxs("button",{type:"button",onClick:m,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(Bs,{size:14}),b]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[oe,tt,ke,M,Pe,Te]})]});if(r.length===0){const oe=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!m?oe:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[rt(null),oe]})}const nt=I||O?({slideToList:oe})=>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:oe,children:[e.jsx(Bs,{size:14}),d]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[tt,ke,M,I&&e.jsxs("button",{type:"button",onClick:I,"aria-pressed":f,title:_,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?B:E})]})]}),Te]}):void 0;return e.jsx(Gi,{mobile:u,preserveScrollOnUpdate:!!C?.length,desktopLayout:$,backLabel:d,groups:Ee,selectedKey:le,mode:Ae,onModeChange:oe=>{Qe(oe),oe!=="ai"&&At($u,oe)},compact:u,collapsedDirectoryKeys:Le,onToggleDirectory:oe=>{at(Ie=>{const ze=new Set(Ie);return ze.has(oe)?ze.delete(oe):ze.add(oe),ze})},onSelectFile:oe=>{s(oe.key),R(Ie=>({key:oe.key,nonce:Ie.nonce+1}))},renderLeading:oe=>{const Ie=he.get(oe.key);return e.jsx(Xi,{changeStatus:oe.status,auditStatus:Ie,renderChangeBadge:ze=>e.jsx(Ds,{status:ze})})},renderTrailing:oe=>{const Ie=he.get(oe.key);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[Ie&&e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Ie.additions," -",Ie.deletions]}),U?.(oe.path,"file")]})},renderDirectoryTrailing:oe=>U?.(oe,"directory"),renderListHeader:rt,aiContent:({slideToDetail:oe,fullscreen:Ie,toggleFullscreen:ze})=>L.length>0&&F?e.jsx(ku,{walkthroughs:L,repoRoot:L[0]?.repoRoot,fullscreen:Ie,onToggleFullscreen:ze,onNavigate:_t=>{u&&window.requestAnimationFrame(oe),F(_t)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:N("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:nt,externalSwiperRef:pe,onMobileSlideChange:De,detailContainerClassName:u?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:V,scrollToKey:ie??Be.key,scrollToKeyNonce:ie==null?Be.nonce:we,onDetailScroll:oe=>{$p(oe,le,s),re?.(oe.scrollTop)},files:Ne,activePane:!0,wrap:f,diffViewType:j,inlineMode:y,renderStreamBadge:(oe,Ie)=>{const ze=he.get(Ie.key);return e.jsx(Xi,{changeStatus:oe,auditStatus:ze,renderChangeBadge:_t=>e.jsx(Ds,{status:_t})})},onInsertDiffReference:A,onReferenceCopied:T,insertedReferenceKey:D,copiedReferenceKey:p,onClearAuditRecord:i,onHunkGitAction:te?void 0:K,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function Ap(r){return r.replace(/\/+$/,"")||"/"}function Lp(r){return[...new Set(Array.from(r,Ap))].sort((n,s)=>n.localeCompare(s))}function Pp(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function Tp(r){let n=null;return{applicableEvents:r.filter(l=>{const u=l.type==="rescan-required"&&!Pp(l.reason);return u&&l.reason&&!n&&(n=l.reason),!u}),unavailableReason:n}}const Ip=1400,Dp=1200,Au=44,Fp=.7;function Ri(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function Ji(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function _p(r){try{const n=window.localStorage.getItem(Ji(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Au?s:null}catch{return null}}function Td(r,n){try{n===null?window.localStorage.removeItem(Ji(r)):window.localStorage.setItem(Ji(r),String(n))}catch{}}function Ga(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function Bp({value:r,collapsed:n,labels:s,focusRequest:l,insertError:u,autoCollapseAfterSend:d,onChange:h,onCollapsedChange:g,onAutoCollapseAfterSendChange:m,onDisable:b,onClear:f,onInsert:j,onInsertAndSend:y}){const[M,I]=a.useState(null),[_,B]=a.useState(!1),[E,$]=a.useState(()=>_p(Ri())),A=a.useRef(E),T=a.useRef(null),U=a.useRef(null),D=a.useRef(r),p=a.useRef(null),i=a.useRef(null),O=!!r.trim(),C=r.trim().split(`
7
+ `)[0]??"",K=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{T.current!==null&&window.clearTimeout(T.current),U.current!==null&&window.clearTimeout(U.current)},[]),a.useEffect(()=>{let N=!1;const q=Ri();return fu().then(he=>{if(N)return;const Ae=he.contextDraftHeight?.[q]??null;Td(q,Ae),A.current=Ae,$(Ae)}).catch(()=>{}),()=>{N=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const N=p.current;if(!N)return;Ga()||N.focus(),N.setSelectionRange(N.value.length,N.value.length),N.scrollTop=N.scrollHeight}},[l]),a.useEffect(()=>{const N=D.current;D.current=r,!(!n||r.length<=N.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},Dp))},[r,n]),a.useEffect(()=>{if(n)return;const N=p.current;N&&(N.style.height=E!==null?`${E}px`:"")},[r,n,E]),a.useEffect(()=>{if(n)return;const N=p.current;!N||document.activeElement===N||(N.scrollTop=N.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||Ga())return;const N=p.current;!N||document.activeElement===N||(N.focus(),N.setSelectionRange(N.value.length,N.value.length))},[n]);const de=a.useRef(null);a.useLayoutEffect(()=>{if(!Ga())return;const N=window.visualViewport;if(!N)return;const q=()=>{const he=de.current;if(!he)return;if(N.height>=window.innerHeight*.75){he.style.transform="";return}const Ae=he.getBoundingClientRect(),Qe=Math.round(N.height-Ae.bottom);he.style.transform=Qe!==0?`translateY(${Qe}px)`:""};return q(),N.addEventListener("resize",q),N.addEventListener("scroll",q),()=>{N.removeEventListener("resize",q),N.removeEventListener("scroll",q),de.current&&(de.current.style.transform="")}},[n]);const te=N=>{I(N),T.current!==null&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{T.current=null,I(null)},Ip)},xe=N=>{g(!1),Ga()&&window.requestAnimationFrame(()=>{const q=p.current;if(!q)return;q.focus();const he=q.value.length;q.setSelectionRange(he,he),window.requestAnimationFrame(()=>{q.setSelectionRange(he,he)})})},W=()=>{j(),te("inserted")},X=()=>{O&&(y(),te("sent"))},L=N=>{if(N.key==="Escape"){N.preventDefault(),g(!0);return}N.key!=="Enter"||!N.metaKey&&!N.ctrlKey||(N.preventDefault(),X())},F=N=>{N.preventDefault()},V=N=>{N.preventDefault();const q=p.current;q&&(i.current={startY:N.clientY,startHeight:q.getBoundingClientRect().height},N.currentTarget.setPointerCapture?.(N.pointerId))},re=N=>{const q=i.current;if(!q)return;const he=window.visualViewport?.height??window.innerHeight,Ae=Math.round(Math.min(Math.max(q.startHeight+(q.startY-N.clientY),Au),he*Fp));A.current=Ae,$(Ae)},ie=N=>{const q=Ri();Td(q,N),ro({contextDraftHeight:{[q]:N}}).catch(()=>{})},we=()=>{i.current&&(i.current=null,A.current!==null&&ie(A.current))},pe=()=>{A.current=null,$(null),ie(null)},De=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:de,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:()=>xe(),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(Rm,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${u?"text-destructive":_?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:u??(_?s.appended:O?C:s.title)})]}),De,e.jsx("button",{type:"button",onClick:X,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:M==="sent"?e.jsx(zi,{size:12}):e.jsx(yd,{size:12})})]})}):e.jsxs("section",{ref:de,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:V,onPointerMove:re,onPointerUp:we,onPointerCancel:we,onDoubleClick:pe,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:F,onClick:()=>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(Os,{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}),De]}),e.jsx("button",{type:"button",role:"switch","aria-checked":d,onPointerDown:F,onClick:()=>m(!d),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${d?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${d?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:F,onClick:b,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Yt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:p,value:r,onChange:N=>h(N.target.value),onKeyDown:L,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:F,onClick:f,disabled:!O,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(no,{size:11})}),u?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:u}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:W,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(Cm,{size:11}),e.jsx("span",{children:M==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:F,onClick:X,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${s.insertAndSend} · ${K}`,children:[M==="sent"?e.jsx(zi,{size:11}):e.jsx(yd,{size:11}),e.jsx("span",{children:M==="sent"?s.sent:s.send})]})]})]})})]})}function Op(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 Op(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const Ji="termdock:right-sidebar:html-view-mode-by-file:v1";function Up(r){return r==="preview"||r==="source"}function Au(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(Up)}function Lu(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function Td(r,n){const s=Lu(r,n);return s?mt(Ji,Au)?.[s]??"source":"source"}function Hp(r,n,s){const l=Lu(r,n);if(!l)return;const u=mt(Ji,Au)??{};At(Ji,{...u,[l]:s})}function zp(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Wp=1500,Id=256*1024*1024;async function Gp(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")??"",u=s.body?.getReader();if(!u){const g=await s.blob();if(g.size>Id)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const d=[];let h=0;try{for(;;){const{done:g,value:m}=await u.read();if(g)break;if(h+=m.byteLength,h>Id)throw new Error("Media too large for encrypted fallback");d.push(m)}}catch(g){throw await u.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(d,{type:l}))}function xo(r,n){const s=zp(r),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[d,h]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const m=navigator.serviceWorker,b=()=>u(!!m?.controller);return m?.addEventListener("controllerchange",b),b(),()=>m?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let m=!1,b;const f=new AbortController,j=window.setTimeout(()=>{Gp(r,f.signal).then(w=>{if(m){URL.revokeObjectURL(w);return}b=w,h(w)}).catch(()=>{m||f.signal.aborted||g.current?.()})},Wp);return()=>{m=!0,window.clearTimeout(j),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,r]),!s||l?r:d}function Ri(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,d=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${d}:${h}`:`${d}:${h}`}function Kp(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 Vr=2,Vp=8,qp=60,Ka=5,Dd=.05,Yp=900;function Xp(r){return!Number.isFinite(r)||r<=0?Vr:Math.min(Vp,Vr+Math.floor(r/qp))}const Jp=350,Qp=6,Zp=90;function eg({url:r,onLoadError:n}){const s=xo(r,n),{t:l}=St(),u=a.useRef(null),d=a.useRef(null),h=a.useRef(null),g=a.useRef(null),m=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),j=a.useRef(0),w=a.useRef(!1),M=a.useRef(!1),I=a.useRef(!1),_=a.useRef(null),B=a.useRef(null),E=a.useRef(!1),$=a.useRef(1),A=a.useRef(!1),[T,U]=a.useState(0),[D,p]=a.useState(0),[i,O]=a.useState(!1),[C,K]=a.useState(!1),[de,te]=a.useState(null),[xe,W]=a.useState(!1),[X,L]=a.useState(0),[F,V]=a.useState(!1),[re,ie]=a.useState({width:0,height:0}),[ye,pe]=a.useState(Vr),[De,N]=a.useState(1),[q,he]=a.useState(null),Ae=a.useRef(Vr),Ze=a.useRef(null),Le=a.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),at=a.useCallback(()=>{Le();const H=B.current;if(B.current=null,!E.current)return!1;const ae=h.current;if(ae&&(ae.playbackRate=$.current,H))try{ae.releasePointerCapture?.(H.id)}catch{}return E.current=!1,Ae.current=Vr,W(!1),!0},[Le]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),Ze.current!==null&&clearTimeout(Ze.current),Le();const H=h.current;H&&E.current&&(H.playbackRate=$.current)},[Le]),a.useEffect(()=>{const H=d.current;if(!H||typeof ResizeObserver>"u")return;const ae=new ResizeObserver(([ve])=>{ve&&ie({width:ve.contentRect.width,height:ve.contentRect.height})});return ae.observe(H),()=>ae.disconnect()},[]),a.useEffect(()=>{const H=()=>V(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",H),()=>document.removeEventListener("fullscreenchange",H)},[]);const Be=a.useCallback((H,ae=!1)=>{const ve=h.current;if(!ve)return!1;const Ke=Number.isFinite(ve.duration)?ve.duration:H,pt=Math.min(Math.max(H,0),Ke);if(p(pt),Math.abs(ve.currentTime-pt)<1/120)return!1;const mr=ve.fastSeek;return ae&&typeof mr=="function"?mr.call(ve,pt):ve.currentTime=pt,!0},[]),R=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const H=h.current;if(!H||!w.current||M.current||H.seeking)return;const ae=I.current;I.current=!1,M.current=Be(j.current,!ae)}))},[Be]),ee=a.useCallback(H=>{const ae=g.current,ve=h.current;if(!ae||!ve)return;const Ke=ae.getBoundingClientRect(),pt=Kp(H,Ke,ve.duration);j.current=pt,te(pt),I.current=!1,R(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,R()},Zp)},[R]),le=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,M.current=!1,Be(j.current)},[Be]),Ee=a.useCallback(H=>{const ae=h.current;if(!(!ae||!Number.isFinite(ae.duration)||ae.duration<=0)){m.current=!ae.paused,ae.pause(),w.current=!0,K(!0);try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}ee(H.clientX)}},[ee]),Ne=a.useCallback(()=>{w.current=!1,le(),K(!1),te(null);const H=h.current;H&&m.current&&!H.ended&&H.play().catch(()=>{}),m.current=!1},[le]),We=a.useCallback(()=>{const H=h.current;if(H){if(A.current){A.current=!1;return}H.paused?H.play().catch(()=>{}):H.pause()}},[]),ce=a.useCallback(H=>{const ae=h.current;if(!ae)return;const ve=Math.min(1,Math.max(0,Math.round((ae.volume+H)*100)/100));ae.volume=ve,ve>0&&(ae.muted=!1),N(ve),he(ve),Ze.current!==null&&clearTimeout(Ze.current),Ze.current=setTimeout(()=>{Ze.current=null,he(null)},Yp)},[]),Pe=a.useCallback(H=>{const ae=h.current;if(ae){if(H.key==="ArrowLeft"){H.preventDefault(),Be(ae.currentTime-(H.shiftKey?Ka*2:Ka));return}if(H.key==="ArrowRight"){H.preventDefault(),Be(ae.currentTime+(H.shiftKey?Ka*2:Ka));return}if(H.key==="ArrowUp"){H.preventDefault(),ce(Dd);return}if(H.key==="ArrowDown"){H.preventDefault(),ce(-Dd);return}(H.key===" "||H.key==="Spacebar"||H.key==="k"||H.key==="K")&&(H.preventDefault(),ae.paused?ae.play().catch(()=>{}):ae.pause())}},[Be,ce]),tt=a.useCallback(H=>{const ae=h.current;!ae||ae.paused||H.button!==0||(Le(),B.current={id:H.pointerId,x:H.clientX,y:H.clientY},_.current=setTimeout(()=>{_.current=null;const ve=B.current;if($.current=ae.playbackRate,ae.playbackRate=Vr,Ae.current=Vr,pe(Vr),E.current=!0,W(!0),ve)try{ae.setPointerCapture?.(ve.id)}catch{}},Jp))},[Le]),Te=a.useCallback(H=>{const ae=B.current;if(!ae||ae.id!==H.pointerId)return;if(!E.current){Math.hypot(H.clientX-ae.x,H.clientY-ae.y)>Qp&&(Le(),B.current=null);return}const ve=Xp(H.clientX-ae.x);if(ve===Ae.current)return;Ae.current=ve,pe(ve);const Ke=h.current;Ke&&(Ke.playbackRate=ve)},[Le]),ke=a.useCallback(()=>{at()&&(A.current=!0)},[at]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const rt=a.useCallback(async()=>{const H=u.current,ae=h.current;if(!(!H||!ae))try{document.fullscreenElement===H?await document.exitFullscreen():H.requestFullscreen?await H.requestFullscreen():ae.webkitEnterFullscreen?.()}catch{ae.webkitEnterFullscreen?.()}},[]),nt=a.useCallback(()=>L(H=>(H+90)%360),[]),oe=a.useCallback(H=>{const ae=h.current;if(!ae||!Number.isFinite(ae.duration))return;const ve=H.shiftKey?10:5;let Ke=null;H.key==="ArrowLeft"?Ke=ae.currentTime-ve:H.key==="ArrowRight"?Ke=ae.currentTime+ve:H.key==="Home"?Ke=0:H.key==="End"&&(Ke=ae.duration),Ke!==null&&(H.preventDefault(),Be(Ke))},[Be]),Ie=C&&de!==null?de:D,ze=T>0?Math.min(1,Math.max(0,Ie/T)):0,Bt=(X===90||X===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":X,children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:`absolute left-1/2 top-1/2 max-w-none object-contain outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${xe?` ${Nd}`:""}`,style:{...Bt,transform:`translate(-50%, -50%) rotate(${X}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...xe?{[Md]:""}:{},onClick:We,onKeyDown:Pe,onVolumeChange:H=>N(H.currentTarget.volume),onPointerDown:tt,onPointerMove:Te,onPointerUp:ke,onPointerCancel:ke,onContextMenu:H=>{E.current&&H.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:H=>p(H.currentTarget.currentTime),onSeeked:H=>{const ae=H.currentTarget;if(p(ae.currentTime),M.current=!1,!w.current)return;const ve=ae.requestVideoFrameCallback;typeof ve=="function"?ve.call(ae,()=>{w.current&&R()}):requestAnimationFrame(()=>{w.current&&R()})},onLoadedMetadata:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onDurationChange:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),xe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed",{rate:String(ye)})}),q!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(Cm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(De*100)})]}),C&&de!==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:`${ze*100}%`},"data-testid":"file-preview-video-scrub-time",children:Ri(de)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Nd}`,[Md]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:We,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:i?e.jsx(Nm,{size:14}):e.jsx(Mm,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(Ie),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:Ee,onPointerMove:H=>{C&&ee(H.clientX)},onPointerUp:Ne,onPointerCancel:Ne,onKeyDown:oe,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:`${ze*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:`${ze*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Ri(Ie)," / ",Ri(T)]}),e.jsx("button",{type:"button",onClick:nt,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(mu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{rt()},"aria-label":l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:F?e.jsx(Em,{size:14}):e.jsx($m,{size:14})})]})})]})}function tg(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 vo({anchor:r,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:d=>{d.stopPropagation(),l()},title:u,style:tg(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(co,{size:11}),n]})}function rg(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const d=l.width*u,h=l.height*u,g=s.left+(s.width-d)/2,m=s.top+(s.height-h)/2,b=r-g,f=n-m;if(b<0||f<0||b>d||f>h)return null;const j=b/d*100,w=f/h*100;return{x:l.x+l.width*j/100,y:l.y+l.height*w/100,xPercent:j,yPercent:w}}function ng(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function sg(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 u of Array.from(l.attributes)){const d=u.name.toLowerCase(),h=u.value.trim();(d.startsWith("on")||(d==="href"||d.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function ag(r,n,s){let l=null;for(const u of Array.from(r.querySelectorAll("text"))){const d=(u.textContent??"").replace(/\s+/g," ").trim();if(!d)continue;const h=Number(u.getAttribute("x")),g=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(g))continue;const m=Math.hypot(h-n,g-s);(!l||m<l.distance)&&(l={text:d,distance:m})}return l?.text.slice(0,120)}function Pu({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),d=a.useRef(null),[h,g]=a.useState(null),[m,b]=a.useState(null),[f,j]=a.useState(1),[w,M]=a.useState(!1),[I,_]=a.useState(null),B=a.useRef(new Map),E=a.useRef(null),$=a.useRef(!1),A=a.useRef(null),T=a.useRef(f);T.current=f,a.useEffect(()=>{const L=new AbortController;return g(null),b(null),_(null),j(1),fetch(r,{signal:L.signal}).then(F=>F.text()).then(F=>g(sg(F))).catch(F=>{L.signal.aborted||b(F instanceof Error?F.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!w)return;const L=F=>{F.key==="Escape"&&M(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[w]),a.useLayoutEffect(()=>{const L=d.current,F=L?.querySelector("[data-svg-document] > svg");if(!L||!F)return;let V;try{V=F.getBBox()}catch{return}if(!V.width||!V.height)return;const re=Math.max(2,Math.min(V.width,V.height)*.025);F.setAttribute("viewBox",`${V.x-re} ${V.y-re} ${V.width+2*re} ${V.height+2*re}`),F.style.width=`${f*100}%`,F.style.height=`${f*100}%`,F.style.minWidth=`${f*100}%`,F.style.minHeight=`${f*100}%`,F.style.display="block"},[h,f]);const U=a.useMemo(()=>I?ng(n,s,I):null,[n,I,s]),D=L=>{if($.current){$.current=!1;return}const F=d.current,V=F?.querySelector("[data-svg-document] > svg"),re=u.current;if(!F||!V||!re)return;const ie=V.viewBox.baseVal,ye=rg(L.clientX,L.clientY,V.getBoundingClientRect(),ie);if(!ye)return;const pe=re.getBoundingClientRect();_({...ye,nearestText:ag(V,ye.x,ye.y),stageX:L.clientX-pe.left,stageY:L.clientY-pe.top,stageXPercent:(L.clientX-pe.left)/pe.width*100,stageYPercent:(L.clientY-pe.top)/pe.height*100})},p=L=>Math.max(1,Math.min(12,L)),i=(L,F)=>{const V=p(F),re=L.querySelector("[data-svg-document] > svg");if(!re)return V;const ie=`${V*100}%`;return re.style.width=ie,re.style.height=ie,re.style.minWidth=ie,re.style.minHeight=ie,T.current=V,V},O=(L,F,V,re)=>{const ie=T.current,ye=L.getBoundingClientRect(),pe=V-ye.left,De=re-ye.top,N=(L.scrollLeft+pe)/ie,q=(L.scrollTop+De)/ie,he=i(L,F);return L.scrollLeft=N*he-pe,L.scrollTop=q*he-De,he},C=()=>{const L=Array.from(B.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},K=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const F=d.current;F&&(B.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),F.setPointerCapture?.(L.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startDistance:C(),startZoom:T.current,moved:!1},$.current=!0):T.current>1&&(E.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:T.current,moved:!1}))},de=L=>{if(!B.current.has(L.pointerId))return;B.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const F=d.current,V=E.current;if(!(!F||!V)){if(B.current.size>=2&&V.kind==="pinch"){const re=C();if(!V.startDistance||!re)return;const ie=p(V.startZoom*re/V.startDistance);if(Math.abs(ie-T.current)<.01)return;const ye=Array.from(B.current.values()),pe=(ye[0].x+ye[1].x)/2,De=(ye[0].y+ye[1].y)/2;V.moved=!0,$.current=!0,O(F,ie,pe,De),L.preventDefault();return}if(V.kind==="pan"&&B.current.size===1){const re=L.clientX-V.startX,ie=L.clientY-V.startY;if(!V.moved&&Math.hypot(re,ie)<6)return;V.moved=!0,$.current=!0,F.scrollLeft=V.startScrollLeft-re,F.scrollTop=V.startScrollTop-ie,L.preventDefault()}}},te=L=>{const F=d.current,V=E.current,re=B.current.size===1&&!V?.moved;B.current.delete(L.pointerId);try{F?.releasePointerCapture?.(L.pointerId)}catch{}if(B.current.size===1&&V?.kind==="pinch"){const pe=Array.from(B.current.values())[0];E.current=F?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,V?.kind==="pinch"&&j(T.current),!re||$.current))return;const ie=Date.now(),ye=A.current;ye&&ie-ye.time<350&&Math.hypot(L.clientX-ye.x,L.clientY-ye.y)<24?(A.current=null,$.current=!0,j(pe=>pe>1?1:2.5)):A.current={time:ie,x:L.clientX,y:L.clientY}},xe=L=>{if(!L.ctrlKey&&!L.metaKey)return;const F=d.current;if(!F)return;L.preventDefault();const V=O(F,T.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);j(V)},W=()=>{j(1),T.current=1,d.current&&(d.current.scrollLeft=0,d.current.scrollTop=0)},X=e.jsxs("div",{className:w?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:d,role:"button",tabIndex:0,onClick:D,onDoubleClick:L=>{L.preventDefault(),j(F=>F>1?1:2.5)},onPointerDown:K,onPointerMove:de,onPointerUp:te,onPointerCancel:te,onWheel:xe,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:m?e.jsx("div",{className:"p-4 text-sm text-destructive",children:m}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),I&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:I.stageX,top:I.stageY}}),I&&U&&e.jsx(vo,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.y.toFixed(2)}`),_(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),W()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(cp,{size:14})}),e.jsx("button",{type:"button","aria-label":w?"退出全屏 SVG":"全屏 SVG",title:w?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),M(F=>!F)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:w?e.jsx(ku,{size:14}):e.jsx(yu,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:I?`SVG (${I.x.toFixed(2)}, ${I.y.toFixed(2)}) · ${I.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return w?qr.createPortal(X,document.body):X}function ao(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function og(r,n,s,l){const u=[`电子标注: ${r}`,`视图: ${ao(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.push(`显示层: ${l.layer}`),l.nearest)){const d=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");u.push(`最近对象: ${l.nearest.label}${d?`(${d})`:""}`)}return`"${u.join(" / ")}"`}function ig({blobUrl:r,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:d,onRefresh:h,interactive3d:g}){const{t:m}=St(),b=a.useRef(null),f=a.useRef(null),j=a.useRef(null),[w,M]=a.useState(null),[I,_]=a.useState(!1);a.useEffect(()=>(j.current?.abort(),M(null),_(!1),()=>j.current?.abort()),[r,s]);const B=a.useMemo(()=>w?og(n,s,w,w.inspection):null,[n,w,s]),E=A=>{const T=b.current,U=f.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const D=T.getBoundingClientRect(),p=U.getBoundingClientRect(),i=Math.min(p.width/U.naturalWidth,p.height/U.naturalHeight),O=U.naturalWidth*i,C=U.naturalHeight*i,K=p.left+(p.width-O)/2,de=p.top+(p.height-C)/2,te=A.clientX-K,xe=A.clientY-de;if(te<0||xe<0||te>O||xe>C)return;const W={xPercent:Math.max(0,Math.min(100,te/O*100)),yPercent:Math.max(0,Math.min(100,xe/C*100)),stageXPercent:(A.clientX-D.left)/D.width*100,stageYPercent:(A.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(M(W),j.current?.abort(),!W.inspecting)return;const X=new AbortController;j.current=X,qh(n,s,W.xPercent,W.yPercent,X.signal).then(L=>M(F=>F===W?{...F,inspection:L,inspecting:!1}:F)).catch(()=>{X.signal.aborted||M(L=>L===W?{...L,inspection:{available:!1},inspecting:!1}:L)})},$=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:$.map(A=>e.jsx("button",{type:"button",onClick:()=>u(A),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${A===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:ao(A)},A))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:m("rightSidebar.edaRefresh"),"aria-label":m("rightSidebar.edaRefresh"),children:e.jsx(so,{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:b,role:"button",tabIndex:0,onClick:E,onKeyDown:A=>{A.key!=="Enter"&&A.key!==" "||(A.preventDefault(),M({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:m("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:r,alt:`${n} ${ao(s)}`,onLoad:()=>_(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${I?"opacity-100":"opacity-0"}`}),w&&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:`${w.stageXPercent}%`,top:`${w.stageYPercent}%`}}),w&&B&&e.jsx(vo,{anchor:{xPercent:w.stageXPercent,yPercent:w.stageYPercent},disabled:w.inspecting,title:m("rightSidebar.edaInsertAnnotation"),onClick:()=>{d?.(B,`eda:${s}:${w.xPercent.toFixed(1)}:${w.yPercent.toFixed(1)}`,{snapshot:f.current?gp(f.current,w):Promise.resolve(null)}),M(null)},children:m("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:w?w.inspecting?m("rightSidebar.edaInspecting"):w.inspection?.available?m("rightSidebar.edaPickedBoardPosition",{x:w.inspection.xMm?.toFixed(2)??"—",y:w.inspection.yMm?.toFixed(2)??"—",object:w.inspection.nearest?.label??m("rightSidebar.edaNoNearbyObject")}):m("rightSidebar.edaPickedPosition",{x:w.xPercent.toFixed(1),y:w.yPercent.toFixed(1)}):m("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Pu,{blobUrl:r,filePath:n,viewLabel:ao(s),onInsertAnnotation:d})})]})}function lg(r){const n=[];let s=[],l="",u=!1;for(let d=0;d<r.length;d+=1){const h=r[d];u?h==='"'&&r[d+1]==='"'?(l+='"',d+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
14
- `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function cg(r,n,s,l,u){const d=n[u]||`第${u+1}列`,h=s[u]??"",g=n.map((m,b)=>`${m||`第${b+1}列`}=${s[b]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${d} / 值: ${h} / 记录: ${g}"`}function dg({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=St(),u=a.useMemo(()=>lg(r),[r]),d=u[0]??[],h=u.slice(1),g=a.useRef(null),[m,b]=a.useState(null),f=m?h[m.row]:null,j=m&&f?cg(n,d,f,m.row+1,m.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:"#"}),d.map((w,M)=>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:w||l("rightSidebar.csvUnnamedColumn",{index:M+1})},`${w}:${M}`))]})}),e.jsx("tbody",{children:h.map((w,M)=>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:M+1}),d.map((I,_)=>{const B=m?.row===M&&m.column===_;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${B?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:E=>{const $=g.current?.getBoundingClientRect(),A=E.currentTarget.getBoundingClientRect();if(!$?.width||!$.height)return;const T=E.clientX||A.left+A.width/2,U=E.clientY||A.top+A.height/2;b({row:M,column:_,xPercent:(T-$.left)/$.width*100,yPercent:(U-$.top)/$.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:w[_]||" "})},`cell:${M}:${_}`)})]},`row:${M}`))})]})}),m&&j&&e.jsx(vo,{anchor:{xPercent:m.xPercent,yPercent:m.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(j,`csv:${n}:${m.row+1}:${m.column+1}`),b(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:m&&f?l("rightSidebar.csvSelectedCell",{row:m.row+1,column:d[m.column]||m.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:d.length})})})]})}function Xn(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function ug(r,n){const s=JSON.parse(r),l=Xn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Xn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Xn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Xn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const u=Xn(s,["net_settings","classes"]),d=Array.isArray(u)?u.find(g=>g&&typeof g=="object"&&g.name==="Default"):void 0,h=Xn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(u)?u.length:0)},{label:"默认间距",value:d?.clearance!==void 0?`${d.clearance} mm`:"未设置"},{label:"默认线宽",value:d?.track_width!==void 0?`${d.track_width} mm`:"未设置"},{label:"默认过孔",value:d?.via_diameter!==void 0?`${d.via_diameter} / ${d.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function fg(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function hg({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:u}=St(),d=a.useRef(null),[h,g]=a.useState(null),m=a.useMemo(()=>{try{return{items:ug(r,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[r,s]),b=h===null?null:m.items[h.index];return m.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:u("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:m.items.map((f,j)=>e.jsxs("button",{type:"button",onClick:w=>{const M=d.current?.getBoundingClientRect(),I=w.currentTarget.getBoundingClientRect();if(!M?.width||!M.height)return;const _=w.clientX||I.left+I.width/2,B=w.clientY||I.top+I.height/2;g({index:j,xPercent:(_-M.left)/M.width*100,yPercent:(B-M.top)/M.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${h?.index===j?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:f.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:f.value})]},f.label))}),e.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:u("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),b&&h&&e.jsx(vo,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:u("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(fg(n,b),`kicad-project:${n}:${b.label}`),g(null)},children:u("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?`${b.label}: ${b.value}`:u("rightSidebar.kicadProjectPickHint")})})]})}const mg=`/** ES Module Shims Wasm @version 2.8.4 */
13
+ `;return`${r}${l}${s}`}function Up(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const Zi="termdock:right-sidebar:html-view-mode-by-file:v1";function Hp(r){return r==="preview"||r==="source"}function Lu(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(Hp)}function Pu(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function Id(r,n){const s=Pu(r,n);return s?mt(Zi,Lu)?.[s]??"source":"source"}function zp(r,n,s){const l=Pu(r,n);if(!l)return;const u=mt(Zi,Lu)??{};At(Zi,{...u,[l]:s})}function Wp(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Gp=1500,Dd=256*1024*1024;async function Kp(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")??"",u=s.body?.getReader();if(!u){const g=await s.blob();if(g.size>Dd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(g)}const d=[];let h=0;try{for(;;){const{done:g,value:m}=await u.read();if(g)break;if(h+=m.byteLength,h>Dd)throw new Error("Media too large for encrypted fallback");d.push(m)}}catch(g){throw await u.cancel().catch(()=>{}),g}return URL.createObjectURL(new Blob(d,{type:l}))}function xo(r,n){const s=Wp(r),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[d,h]=a.useState(void 0),g=a.useRef(n);return g.current=n,a.useEffect(()=>{if(!s||l)return;const m=navigator.serviceWorker,b=()=>u(!!m?.controller);return m?.addEventListener("controllerchange",b),b(),()=>m?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let m=!1,b;const f=new AbortController,j=window.setTimeout(()=>{Kp(r,f.signal).then(y=>{if(m){URL.revokeObjectURL(y);return}b=y,h(y)}).catch(()=>{m||f.signal.aborted||g.current?.()})},Gp);return()=>{m=!0,window.clearTimeout(j),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,r]),!s||l?r:d}function Ci(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,d=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${d}:${h}`:`${d}:${h}`}function Vp(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 Vr=2,qp=8,Yp=60,Ka=5,Fd=.05,Xp=900;function Jp(r){return!Number.isFinite(r)||r<=0?Vr:Math.min(qp,Vr+Math.floor(r/Yp))}const Zp=350,Qp=6,eg=90;function tg({url:r,onLoadError:n}){const s=xo(r,n),{t:l}=St(),u=a.useRef(null),d=a.useRef(null),h=a.useRef(null),g=a.useRef(null),m=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),j=a.useRef(0),y=a.useRef(!1),M=a.useRef(!1),I=a.useRef(!1),_=a.useRef(null),B=a.useRef(null),E=a.useRef(!1),$=a.useRef(1),A=a.useRef(!1),[T,U]=a.useState(0),[D,p]=a.useState(0),[i,O]=a.useState(!1),[C,K]=a.useState(!1),[de,te]=a.useState(null),[xe,W]=a.useState(!1),[X,L]=a.useState(0),[F,V]=a.useState(!1),[re,ie]=a.useState({width:0,height:0}),[we,pe]=a.useState(Vr),[De,N]=a.useState(1),[q,he]=a.useState(null),Ae=a.useRef(Vr),Qe=a.useRef(null),Le=a.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),at=a.useCallback(()=>{Le();const H=B.current;if(B.current=null,!E.current)return!1;const ae=h.current;if(ae&&(ae.playbackRate=$.current,H))try{ae.releasePointerCapture?.(H.id)}catch{}return E.current=!1,Ae.current=Vr,W(!1),!0},[Le]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),Qe.current!==null&&clearTimeout(Qe.current),Le();const H=h.current;H&&E.current&&(H.playbackRate=$.current)},[Le]),a.useEffect(()=>{const H=d.current;if(!H||typeof ResizeObserver>"u")return;const ae=new ResizeObserver(([ve])=>{ve&&ie({width:ve.contentRect.width,height:ve.contentRect.height})});return ae.observe(H),()=>ae.disconnect()},[]),a.useEffect(()=>{const H=()=>V(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",H),()=>document.removeEventListener("fullscreenchange",H)},[]);const Be=a.useCallback((H,ae=!1)=>{const ve=h.current;if(!ve)return!1;const Ke=Number.isFinite(ve.duration)?ve.duration:H,pt=Math.min(Math.max(H,0),Ke);if(p(pt),Math.abs(ve.currentTime-pt)<1/120)return!1;const mr=ve.fastSeek;return ae&&typeof mr=="function"?mr.call(ve,pt):ve.currentTime=pt,!0},[]),R=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const H=h.current;if(!H||!y.current||M.current||H.seeking)return;const ae=I.current;I.current=!1,M.current=Be(j.current,!ae)}))},[Be]),ee=a.useCallback(H=>{const ae=g.current,ve=h.current;if(!ae||!ve)return;const Ke=ae.getBoundingClientRect(),pt=Vp(H,Ke,ve.duration);j.current=pt,te(pt),I.current=!1,R(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,R()},eg)},[R]),le=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,M.current=!1,Be(j.current)},[Be]),Ee=a.useCallback(H=>{const ae=h.current;if(!(!ae||!Number.isFinite(ae.duration)||ae.duration<=0)){m.current=!ae.paused,ae.pause(),y.current=!0,K(!0);try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}ee(H.clientX)}},[ee]),Ne=a.useCallback(()=>{y.current=!1,le(),K(!1),te(null);const H=h.current;H&&m.current&&!H.ended&&H.play().catch(()=>{}),m.current=!1},[le]),We=a.useCallback(()=>{const H=h.current;if(H){if(A.current){A.current=!1;return}H.paused?H.play().catch(()=>{}):H.pause()}},[]),ce=a.useCallback(H=>{const ae=h.current;if(!ae)return;const ve=Math.min(1,Math.max(0,Math.round((ae.volume+H)*100)/100));ae.volume=ve,ve>0&&(ae.muted=!1),N(ve),he(ve),Qe.current!==null&&clearTimeout(Qe.current),Qe.current=setTimeout(()=>{Qe.current=null,he(null)},Xp)},[]),Pe=a.useCallback(H=>{const ae=h.current;if(ae){if(H.key==="ArrowLeft"){H.preventDefault(),Be(ae.currentTime-(H.shiftKey?Ka*2:Ka));return}if(H.key==="ArrowRight"){H.preventDefault(),Be(ae.currentTime+(H.shiftKey?Ka*2:Ka));return}if(H.key==="ArrowUp"){H.preventDefault(),ce(Fd);return}if(H.key==="ArrowDown"){H.preventDefault(),ce(-Fd);return}(H.key===" "||H.key==="Spacebar"||H.key==="k"||H.key==="K")&&(H.preventDefault(),ae.paused?ae.play().catch(()=>{}):ae.pause())}},[Be,ce]),tt=a.useCallback(H=>{const ae=h.current;!ae||ae.paused||H.button!==0||(Le(),B.current={id:H.pointerId,x:H.clientX,y:H.clientY},_.current=setTimeout(()=>{_.current=null;const ve=B.current;if($.current=ae.playbackRate,ae.playbackRate=Vr,Ae.current=Vr,pe(Vr),E.current=!0,W(!0),ve)try{ae.setPointerCapture?.(ve.id)}catch{}},Zp))},[Le]),Te=a.useCallback(H=>{const ae=B.current;if(!ae||ae.id!==H.pointerId)return;if(!E.current){Math.hypot(H.clientX-ae.x,H.clientY-ae.y)>Qp&&(Le(),B.current=null);return}const ve=Jp(H.clientX-ae.x);if(ve===Ae.current)return;Ae.current=ve,pe(ve);const Ke=h.current;Ke&&(Ke.playbackRate=ve)},[Le]),ke=a.useCallback(()=>{at()&&(A.current=!0)},[at]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const rt=a.useCallback(async()=>{const H=u.current,ae=h.current;if(!(!H||!ae))try{document.fullscreenElement===H?await document.exitFullscreen():H.requestFullscreen?await H.requestFullscreen():ae.webkitEnterFullscreen?.()}catch{ae.webkitEnterFullscreen?.()}},[]),nt=a.useCallback(()=>L(H=>(H+90)%360),[]),oe=a.useCallback(H=>{const ae=h.current;if(!ae||!Number.isFinite(ae.duration))return;const ve=H.shiftKey?10:5;let Ke=null;H.key==="ArrowLeft"?Ke=ae.currentTime-ve:H.key==="ArrowRight"?Ke=ae.currentTime+ve:H.key==="Home"?Ke=0:H.key==="End"&&(Ke=ae.duration),Ke!==null&&(H.preventDefault(),Be(Ke))},[Be]),Ie=C&&de!==null?de:D,ze=T>0?Math.min(1,Math.max(0,Ie/T)):0,Bt=(X===90||X===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":X,children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:`absolute left-1/2 top-1/2 max-w-none object-contain outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${xe?` ${Md}`:""}`,style:{...Bt,transform:`translate(-50%, -50%) rotate(${X}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...xe?{[Ed]:""}:{},onClick:We,onKeyDown:Pe,onVolumeChange:H=>N(H.currentTarget.volume),onPointerDown:tt,onPointerMove:Te,onPointerUp:ke,onPointerCancel:ke,onContextMenu:H=>{E.current&&H.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:H=>p(H.currentTarget.currentTime),onSeeked:H=>{const ae=H.currentTarget;if(p(ae.currentTime),M.current=!1,!y.current)return;const ve=ae.requestVideoFrameCallback;typeof ve=="function"?ve.call(ae,()=>{y.current&&R()}):requestAnimationFrame(()=>{y.current&&R()})},onLoadedMetadata:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onDurationChange:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),xe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed",{rate:String(we)})}),q!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(Nm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(De*100)})]}),C&&de!==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:`${ze*100}%`},"data-testid":"file-preview-video-scrub-time",children:Ci(de)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${Md}`,[Ed]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:We,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:i?e.jsx(Mm,{size:14}):e.jsx(Em,{size:14})}),e.jsxs("div",{ref:g,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(Ie),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:Ee,onPointerMove:H=>{C&&ee(H.clientX)},onPointerUp:Ne,onPointerCancel:Ne,onKeyDown:oe,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:`${ze*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:`${ze*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Ci(Ie)," / ",Ci(T)]}),e.jsx("button",{type:"button",onClick:nt,"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(pu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{rt()},"aria-label":l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(F?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:F?e.jsx($m,{size:14}):e.jsx(Am,{size:14})})]})})]})}function rg(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function vo({anchor:r,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:d=>{d.stopPropagation(),l()},title:u,style:rg(r),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(co,{size:11}),n]})}function ng(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const d=l.width*u,h=l.height*u,g=s.left+(s.width-d)/2,m=s.top+(s.height-h)/2,b=r-g,f=n-m;if(b<0||f<0||b>d||f>h)return null;const j=b/d*100,y=f/h*100;return{x:l.x+l.width*j/100,y:l.y+l.height*y/100,xPercent:j,yPercent:y}}function sg(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 ag(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 u of Array.from(l.attributes)){const d=u.name.toLowerCase(),h=u.value.trim();(d.startsWith("on")||(d==="href"||d.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function og(r,n,s){let l=null;for(const u of Array.from(r.querySelectorAll("text"))){const d=(u.textContent??"").replace(/\s+/g," ").trim();if(!d)continue;const h=Number(u.getAttribute("x")),g=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(g))continue;const m=Math.hypot(h-n,g-s);(!l||m<l.distance)&&(l={text:d,distance:m})}return l?.text.slice(0,120)}function Tu({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),d=a.useRef(null),[h,g]=a.useState(null),[m,b]=a.useState(null),[f,j]=a.useState(1),[y,M]=a.useState(!1),[I,_]=a.useState(null),B=a.useRef(new Map),E=a.useRef(null),$=a.useRef(!1),A=a.useRef(null),T=a.useRef(f);T.current=f,a.useEffect(()=>{const L=new AbortController;return g(null),b(null),_(null),j(1),fetch(r,{signal:L.signal}).then(F=>F.text()).then(F=>g(ag(F))).catch(F=>{L.signal.aborted||b(F instanceof Error?F.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!y)return;const L=F=>{F.key==="Escape"&&M(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[y]),a.useLayoutEffect(()=>{const L=d.current,F=L?.querySelector("[data-svg-document] > svg");if(!L||!F)return;let V;try{V=F.getBBox()}catch{return}if(!V.width||!V.height)return;const re=Math.max(2,Math.min(V.width,V.height)*.025);F.setAttribute("viewBox",`${V.x-re} ${V.y-re} ${V.width+2*re} ${V.height+2*re}`),F.style.width=`${f*100}%`,F.style.height=`${f*100}%`,F.style.minWidth=`${f*100}%`,F.style.minHeight=`${f*100}%`,F.style.display="block"},[h,f]);const U=a.useMemo(()=>I?sg(n,s,I):null,[n,I,s]),D=L=>{if($.current){$.current=!1;return}const F=d.current,V=F?.querySelector("[data-svg-document] > svg"),re=u.current;if(!F||!V||!re)return;const ie=V.viewBox.baseVal,we=ng(L.clientX,L.clientY,V.getBoundingClientRect(),ie);if(!we)return;const pe=re.getBoundingClientRect();_({...we,nearestText:og(V,we.x,we.y),stageX:L.clientX-pe.left,stageY:L.clientY-pe.top,stageXPercent:(L.clientX-pe.left)/pe.width*100,stageYPercent:(L.clientY-pe.top)/pe.height*100})},p=L=>Math.max(1,Math.min(12,L)),i=(L,F)=>{const V=p(F),re=L.querySelector("[data-svg-document] > svg");if(!re)return V;const ie=`${V*100}%`;return re.style.width=ie,re.style.height=ie,re.style.minWidth=ie,re.style.minHeight=ie,T.current=V,V},O=(L,F,V,re)=>{const ie=T.current,we=L.getBoundingClientRect(),pe=V-we.left,De=re-we.top,N=(L.scrollLeft+pe)/ie,q=(L.scrollTop+De)/ie,he=i(L,F);return L.scrollLeft=N*he-pe,L.scrollTop=q*he-De,he},C=()=>{const L=Array.from(B.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},K=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const F=d.current;F&&(B.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),F.setPointerCapture?.(L.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startDistance:C(),startZoom:T.current,moved:!1},$.current=!0):T.current>1&&(E.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:T.current,moved:!1}))},de=L=>{if(!B.current.has(L.pointerId))return;B.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const F=d.current,V=E.current;if(!(!F||!V)){if(B.current.size>=2&&V.kind==="pinch"){const re=C();if(!V.startDistance||!re)return;const ie=p(V.startZoom*re/V.startDistance);if(Math.abs(ie-T.current)<.01)return;const we=Array.from(B.current.values()),pe=(we[0].x+we[1].x)/2,De=(we[0].y+we[1].y)/2;V.moved=!0,$.current=!0,O(F,ie,pe,De),L.preventDefault();return}if(V.kind==="pan"&&B.current.size===1){const re=L.clientX-V.startX,ie=L.clientY-V.startY;if(!V.moved&&Math.hypot(re,ie)<6)return;V.moved=!0,$.current=!0,F.scrollLeft=V.startScrollLeft-re,F.scrollTop=V.startScrollTop-ie,L.preventDefault()}}},te=L=>{const F=d.current,V=E.current,re=B.current.size===1&&!V?.moved;B.current.delete(L.pointerId);try{F?.releasePointerCapture?.(L.pointerId)}catch{}if(B.current.size===1&&V?.kind==="pinch"){const pe=Array.from(B.current.values())[0];E.current=F?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:F.scrollLeft,startScrollTop:F.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,V?.kind==="pinch"&&j(T.current),!re||$.current))return;const ie=Date.now(),we=A.current;we&&ie-we.time<350&&Math.hypot(L.clientX-we.x,L.clientY-we.y)<24?(A.current=null,$.current=!0,j(pe=>pe>1?1:2.5)):A.current={time:ie,x:L.clientX,y:L.clientY}},xe=L=>{if(!L.ctrlKey&&!L.metaKey)return;const F=d.current;if(!F)return;L.preventDefault();const V=O(F,T.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);j(V)},W=()=>{j(1),T.current=1,d.current&&(d.current.scrollLeft=0,d.current.scrollTop=0)},X=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:d,role:"button",tabIndex:0,onClick:D,onDoubleClick:L=>{L.preventDefault(),j(F=>F>1?1:2.5)},onPointerDown:K,onPointerMove:de,onPointerUp:te,onPointerCancel:te,onWheel:xe,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:m?e.jsx("div",{className:"p-4 text-sm text-destructive",children:m}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),I&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:I.stageX,top:I.stageY}}),I&&U&&e.jsx(vo,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.y.toFixed(2)}`),_(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),W()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(dp,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),M(F=>!F)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(Su,{size:14}):e.jsx(yu,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:I?`SVG (${I.x.toFixed(2)}, ${I.y.toFixed(2)}) · ${I.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?qr.createPortal(X,document.body):X}function ao(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function ig(r,n,s,l){const u=[`电子标注: ${r}`,`视图: ${ao(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.push(`显示层: ${l.layer}`),l.nearest)){const d=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");u.push(`最近对象: ${l.nearest.label}${d?`(${d})`:""}`)}return`"${u.join(" / ")}"`}function lg({blobUrl:r,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:d,onRefresh:h,interactive3d:g}){const{t:m}=St(),b=a.useRef(null),f=a.useRef(null),j=a.useRef(null),[y,M]=a.useState(null),[I,_]=a.useState(!1);a.useEffect(()=>(j.current?.abort(),M(null),_(!1),()=>j.current?.abort()),[r,s]);const B=a.useMemo(()=>y?ig(n,s,y,y.inspection):null,[n,y,s]),E=A=>{const T=b.current,U=f.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const D=T.getBoundingClientRect(),p=U.getBoundingClientRect(),i=Math.min(p.width/U.naturalWidth,p.height/U.naturalHeight),O=U.naturalWidth*i,C=U.naturalHeight*i,K=p.left+(p.width-O)/2,de=p.top+(p.height-C)/2,te=A.clientX-K,xe=A.clientY-de;if(te<0||xe<0||te>O||xe>C)return;const W={xPercent:Math.max(0,Math.min(100,te/O*100)),yPercent:Math.max(0,Math.min(100,xe/C*100)),stageXPercent:(A.clientX-D.left)/D.width*100,stageYPercent:(A.clientY-D.top)/D.height*100,inspecting:l&&s!=="pcb-3d"};if(M(W),j.current?.abort(),!W.inspecting)return;const X=new AbortController;j.current=X,Yh(n,s,W.xPercent,W.yPercent,X.signal).then(L=>M(F=>F===W?{...F,inspection:L,inspecting:!1}:F)).catch(()=>{X.signal.aborted||M(L=>L===W?{...L,inspection:{available:!1},inspecting:!1}:L)})},$=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:$.map(A=>e.jsx("button",{type:"button",onClick:()=>u(A),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${A===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:ao(A)},A))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:m("rightSidebar.edaRefresh"),"aria-label":m("rightSidebar.edaRefresh"),children:e.jsx(so,{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:b,role:"button",tabIndex:0,onClick:E,onKeyDown:A=>{A.key!=="Enter"&&A.key!==" "||(A.preventDefault(),M({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:m("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:r,alt:`${n} ${ao(s)}`,onLoad:()=>_(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${I?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&B&&e.jsx(vo,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:m("rightSidebar.edaInsertAnnotation"),onClick:()=>{d?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?bp(f.current,y):Promise.resolve(null)}),M(null)},children:m("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?m("rightSidebar.edaInspecting"):y.inspection?.available?m("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??m("rightSidebar.edaNoNearbyObject")}):m("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):m("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Tu,{blobUrl:r,filePath:n,viewLabel:ao(s),onInsertAnnotation:d})})]})}function cg(r){const n=[];let s=[],l="",u=!1;for(let d=0;d<r.length;d+=1){const h=r[d];u?h==='"'&&r[d+1]==='"'?(l+='"',d+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
14
+ `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function dg(r,n,s,l,u){const d=n[u]||`第${u+1}列`,h=s[u]??"",g=n.map((m,b)=>`${m||`第${b+1}列`}=${s[b]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${d} / 值: ${h} / 记录: ${g}"`}function ug({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=St(),u=a.useMemo(()=>cg(r),[r]),d=u[0]??[],h=u.slice(1),g=a.useRef(null),[m,b]=a.useState(null),f=m?h[m.row]:null,j=m&&f?dg(n,d,f,m.row+1,m.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:"#"}),d.map((y,M)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||l("rightSidebar.csvUnnamedColumn",{index:M+1})},`${y}:${M}`))]})}),e.jsx("tbody",{children:h.map((y,M)=>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:M+1}),d.map((I,_)=>{const B=m?.row===M&&m.column===_;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${B?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:E=>{const $=g.current?.getBoundingClientRect(),A=E.currentTarget.getBoundingClientRect();if(!$?.width||!$.height)return;const T=E.clientX||A.left+A.width/2,U=E.clientY||A.top+A.height/2;b({row:M,column:_,xPercent:(T-$.left)/$.width*100,yPercent:(U-$.top)/$.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[_]||" "})},`cell:${M}:${_}`)})]},`row:${M}`))})]})}),m&&j&&e.jsx(vo,{anchor:{xPercent:m.xPercent,yPercent:m.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(j,`csv:${n}:${m.row+1}:${m.column+1}`),b(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:m&&f?l("rightSidebar.csvSelectedCell",{row:m.row+1,column:d[m.column]||m.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:d.length})})})]})}function Xn(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function fg(r,n){const s=JSON.parse(r),l=Xn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Xn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Xn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Xn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const u=Xn(s,["net_settings","classes"]),d=Array.isArray(u)?u.find(g=>g&&typeof g=="object"&&g.name==="Default"):void 0,h=Xn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(u)?u.length:0)},{label:"默认间距",value:d?.clearance!==void 0?`${d.clearance} mm`:"未设置"},{label:"默认线宽",value:d?.track_width!==void 0?`${d.track_width} mm`:"未设置"},{label:"默认过孔",value:d?.via_diameter!==void 0?`${d.via_diameter} / ${d.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function hg(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function mg({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:u}=St(),d=a.useRef(null),[h,g]=a.useState(null),m=a.useMemo(()=>{try{return{items:fg(r,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[r,s]),b=h===null?null:m.items[h.index];return m.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:u("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:m.items.map((f,j)=>e.jsxs("button",{type:"button",onClick:y=>{const M=d.current?.getBoundingClientRect(),I=y.currentTarget.getBoundingClientRect();if(!M?.width||!M.height)return;const _=y.clientX||I.left+I.width/2,B=y.clientY||I.top+I.height/2;g({index:j,xPercent:(_-M.left)/M.width*100,yPercent:(B-M.top)/M.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${h?.index===j?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:f.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:f.value})]},f.label))}),e.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:u("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),b&&h&&e.jsx(vo,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:u("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(hg(n,b),`kicad-project:${n}:${b.label}`),g(null)},children:u("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?`${b.label}: ${b.value}`:u("rightSidebar.kicadProjectPickHint")})})]})}const pg=`/** 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{a6 as Tr,cM as St,bi as e,g as lo,cW as At,bA as mt,a as Bs,aR as uu,C as
1497
1497
  };
1498
1498
 
1499
1499
  })();
1500
- `,pg=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1500
+ `,gg=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1501
1501
  function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1502
1502
  const external = new Set(externalOrigins);
1503
1503
  const report = () => parent.postMessage({ type: 'preview-error', capability }, '*');
@@ -1632,47 +1632,47 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1632
1632
  window.addEventListener('error', report, true);
1633
1633
  window.addEventListener('unhandledrejection', report);
1634
1634
  }
1635
- `,Va="/api/terminal/fs/preview/",gg=8*1024*1024,bg=32*1024*1024,xg=128,vg="data:,";function $t(r){throw new Error(r)}function yg(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function Fd(r,n,s){let l="",u=0;for(const d of r.matchAll(n))l+=r.slice(u,d.index)+await s(d),u=d.index+d[0].length;return l+r.slice(u)}async function Tu(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!Cs(l.pathname)?.startsWith(Va))&&$t("预览地址不是有效的本地文件入口");const u=crypto.randomUUID(),d=`https://termdock-preview.invalid/${u}/`,h=[],g=W=>{!h.includes(W)&&h.length<20&&h.push(W)},m=new Set,b=[],f=new Set,j=new Map,w=new Map;let M=0,I=!1;const _=new Set,B=()=>{I=!0;for(const W of[..._])W();m.clear(),b.length=0};async function E(W){W.ok||$t(`预览资源读取失败(${W.status})`);const X=W.body?.getReader(),L=[];let F=0;try{if(X)for(;;){const ie=await X.read();if(ie.done)break;F+=ie.value.byteLength,M+=ie.value.byteLength,(F>gg||M>bg)&&$t("预览资源超出大小限制"),L.push(ie.value)}}catch(ie){throw await X?.cancel().catch(()=>{}),ie}finally{X?.releaseLock()}const V=new Uint8Array(F);let re=0;for(const ie of L)V.set(ie,re),re+=ie.length;return{bytes:V,type:W.headers.get("content-type")??"application/octet-stream",status:W.status}}let $=l,A;for(let W=0;W<4;W++){const X=await n.fetch($.pathname+$.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(X.status)){A=X;break}const L=X.headers.get("location");await X.body?.cancel(),L||$t("预览重定向缺少目标");const F=new URL(L,$);(F.origin!==s||!Cs(F.pathname)?.startsWith(Va))&&$t("预览重定向越出文件范围"),$=F}A||$t("预览重定向次数过多");const T=Cs($.pathname),U=T.slice(Va.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||$t("服务未提供有效的预览资源授权");const D=Cs(l.pathname).slice(Va.length).split("/");/^[a-f0-9]{32}$/.test(D[0])&&D.shift(),D.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const p=T.endsWith("/")?T:T.slice(0,T.lastIndexOf("/")+1),i=new URL($.pathname.endsWith("/")?$.pathname:$.pathname.slice(0,$.pathname.lastIndexOf("/")+1),s);function O(W,X){const L=new URL(W,X);return L.origin!==s?null:(Cs(L.pathname)?.startsWith(p)||$t("已阻止预览访问目录之外的资源"),L)}function C(W){const X=new URL(W,d);(X.origin!==new URL(d).origin||!X.pathname.startsWith(new URL(d).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const L=X.pathname.slice(new URL(d).pathname.length)+X.search;return O(L,i)??$t("预览资源无效")}function K(W){const X=W.pathname+W.search,L=j.get(X);if(L)return L;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(j.size>=xg)return Promise.reject(new Error("预览资源数量超出限制"));const F=n.fetch(X,{signal:n.signal,redirect:"manual"}).then(E);return j.set(X,F),F}function de(W,X){I&&$t("预览已关闭");const L=`termdock-resource-${u}-${b.length}`;return b.push({token:L,data:W,type:X}),m.add(L),L}async function te(W,X,L,F=new Set){if(!W||W.startsWith("#")||/^data:(?:image|font)\//i.test(W)&&L==="resource")return W;try{const V=O(W,X);if(!V){const De=new URL(W,X);return(De.protocol!=="https:"||De.username||De.password||De.origin===new URL(d).origin)&&$t("已阻止不安全的外部资源"),f.add(De.origin),De.href}const re=`${L}:${V.href}`;(F.has(re)||F.size>=8)&&$t("预览资源存在循环或过深引用");const ie=w.get(re);if(ie)return ie;const ye=new Set(F);ye.add(re);const pe=(async()=>{const De=await K(V);return L==="css"?de(await xe(new TextDecoder().decode(De.bytes),V,ye),"text/css"):L==="script"?de(De.bytes,"text/javascript"):de(De.bytes,De.type)})();return w.set(re,pe),await pe}catch(V){return g(V instanceof Error?V.message:"部分预览资源未能加载"),vg}}async function xe(W,X,L){return W=await Fd(W,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async F=>`@import url("${await te(F[1],X,"css",L)}")${F[2]};`),Fd(W,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async F=>{const V=(F[1]??F[2]??F[3]).trim();return m.has(V)?F[0]:`url("${await te(V,X,"resource",L)}")`})}try{const W=await E(A),X=de(mg,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(W.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(N=>N.remove());for(const N of L.querySelectorAll("*")){if(N.removeAttribute("ping"),N.removeAttribute("srcdoc"),N.hasAttribute("style")&&N.setAttribute("style",await xe(N.getAttribute("style"),$,new Set)),N.tagName==="STYLE"&&(N.textContent=await xe(N.textContent??"",$,new Set)),N.tagName==="A"||N.tagName==="AREA"){const q=N.getAttribute("href");try{if(q&&!q.startsWith("#")){const he=O(q,$);if(he)N.setAttribute("href",new URL(he.pathname.slice(i.pathname.length)+he.search+he.hash,d).href);else{const Ae=new URL(q,$);if(Ae.protocol!=="https:"){N.removeAttribute("href");continue}f.add(Ae.origin),N.setAttribute("href",Ae.href)}}}catch(he){N.removeAttribute("href"),g(he instanceof Error?he.message:"预览链接无法加载")}}for(const q of["data","manifest"])N.removeAttribute(q);if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="module"){N.setAttribute("type","module-shim");const q=N.getAttribute("src");if(q){const he=O(q,$);if(he)N.setAttribute("src",new URL(he.pathname.slice(i.pathname.length)+he.search,d).href);else{const Ae=new URL(q,$);if(Ae.protocol!=="https:"){N.remove();continue}f.add(Ae.origin),N.setAttribute("src",Ae.href)}}continue}if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="importmap"){N.setAttribute("type","importmap-shim");continue}if(N.tagName==="LINK"){const q=(N.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(q)){N.remove();continue}const he=N.getAttribute("href");he&&N.setAttribute("href",await te(he,$,q==="stylesheet"?"css":"resource"))}if(N.hasAttribute("src")&&N.setAttribute("src",await te(N.getAttribute("src"),$,N.tagName==="SCRIPT"?"script":"resource")),N.hasAttribute("poster")&&N.setAttribute("poster",await te(N.getAttribute("poster"),$,"resource")),N.hasAttribute("srcset")){const q=N.getAttribute("srcset");/data:/i.test(q)?(N.removeAttribute("srcset"),g("混合内嵌图片候选暂不支持安全预览")):N.setAttribute("srcset",(await Promise.all(q.split(",").map(async he=>{const[Ae,...Ze]=he.trim().split(/\s+/);return`${await te(Ae,$,"resource")} ${Ze.join(" ")}`}))).join(", "))}N.setAttribute("referrerpolicy","no-referrer"),N.removeAttribute("integrity"),N.removeAttribute("crossorigin")}const F=[...f].join(" "),V=L.createElement("meta");V.httpEquiv="Content-Security-Policy",V.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${F}; style-src 'unsafe-inline' blob: ${F}; img-src blob: data: ${F}; font-src blob: data: ${F}; media-src blob: data: ${F}; connect-src blob: ${F} ${[...f].map(N=>N.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=L.createElement("base");re.href=d;const ie=L.createElement("meta");ie.name="referrer",ie.content="no-referrer";const ye=L.createElement("script");ye.textContent=pg+`
1636
- installPreviewRuntime(`+[u,d,[...f],X].map(yg).join(",")+");";const pe=L.createElement("script");pe.src=X,L.head.prepend(V,ie,re,ye,pe);const De=`<!doctype html>
1637
- `+L.documentElement.outerHTML;return{html:De,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(N,q){const he=new Set,Ae=Le=>{if(Le.source!==N.contentWindow||Le.data?.capability!==u)return;if(Le.data.type==="preview-ready"){N.contentWindow?.postMessage({type:"preview-init",capability:u,html:De,resources:b},"*");return}if(Le.data.type==="preview-error"){q("部分动态内容被安全预览限制");return}if(Le.data.type==="preview-navigate"){(async()=>{const Be=C(String(Le.data.url)),R=await Tu(Be.pathname+Be.search,n);if(I){R.dispose();return}const ee=R.attach(N,q);_.add(()=>{ee(),R.dispose()}),N.src=R.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Be=>q(Be instanceof Error?Be.message:"无法打开预览页面"));return}if(Le.data.type==="preview-external"){try{const Be=new URL(String(Le.data.url));Be.protocol==="https:"&&f.has(Be.origin)&&window.open(Be.href,"_blank","noopener,noreferrer")}catch{}return}if(Le.data.type!=="preview-fetch"||Le.ports.length!==1)return;const at=Le.ports[0];if(he.size>=8||!["GET","HEAD"].includes(Le.data.method)){at.postMessage({error:"预览仅允许读取已授权目录资源"}),at.close();return}he.add(at),(async()=>{const Be=C(String(Le.data.url)),R=await K(Be);if(!he.has(at)||I)return;const ee=Le.data.method==="HEAD"?new Uint8Array:R.bytes.slice();at.postMessage({status:R.status,headers:{"content-type":R.type},data:ee.buffer},[ee.buffer])})().catch(()=>{at.postMessage({error:"预览资源不在授权范围或无法加载"}),q("部分动态资源不可用或超出预览目录")}).finally(()=>{he.delete(at),at.close()})};window.addEventListener("message",Ae);const Ze=()=>{window.removeEventListener("message",Ae);for(const Le of he)Le.close();he.clear(),_.delete(Ze)};return _.add(Ze),Ze},dispose:B}}catch(W){throw B(),W}}const wg=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},d){const h=a.useRef(null),[g,m]=a.useState(null),[b,f]=a.useState(),[j,w]=a.useState("");a.useEffect(()=>{const T=new AbortController;let U;return f(void 0),w(""),(async()=>{const D=await Yh();if(U=await Tu(n,{fetch:(p,i)=>D.fetch(p,i),signal:T.signal}),T.signal.aborted){U.dispose();return}f(U),U.errors.length&&w(U.errors.join(";"))})().catch(D=>{T.signal.aborted||w(D instanceof Error?D.message:"安全预览加载失败")}),()=>{T.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!g))return b.attach(g,w)},[b,g]);const[M,I]=a.useState(!1),[_,B]=a.useState(!1),E=M||_;a.useEffect(()=>{u?.(E)},[E,u]),a.useEffect(()=>{const T=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",T),()=>document.removeEventListener("fullscreenchange",T)},[]),a.useEffect(()=>{if(!_)return;const T=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[_]);const $=a.useCallback(async()=>{const T=h.current;if(T){if(_){B(!1);return}if(document.fullscreenElement===T){await document.exitFullscreen();return}if(T.requestFullscreen&&document.fullscreenEnabled!==!1)try{await T.requestFullscreen();return}catch{}B(!0)}},[_]);a.useImperativeHandle(d,()=>({toggleFullscreen:$}),[$]);const A=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:E?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[E&&e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[e.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:s}),e.jsx("button",{type:"button",onClick:()=>{$()},"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(ku,{size:15})})]}),j&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:j}),!b&&!j&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:m,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return _?qr.createPortal(A,document.body):A}),Iu="termdock-file-search-match",Qi="termdock-file-search-current";function kg(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 Sg(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function jg(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let u="",d=null;const h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const j=Sg(f);if(!j)continue;d&&d!==j&&(u+=`
1638
- `);const w=u.length;u+=f.data,l.push({node:f,start:w,end:u.length,group:j}),d=j}const g=u.toLocaleLowerCase(),m=[];let b=0;for(;b<=g.length-s.length;){const f=g.indexOf(s,b);if(f<0)break;const j=f+s.length,w=l.find(I=>I.start<=f&&I.end>f),M=l.find(I=>I.start<j&&I.end>=j);if(w&&M&&w.group===M.group){const I=document.createRange();I.setStart(w.node,f-w.start),I.setEnd(M.node,j-M.start),m.push(I)}b=f+Math.max(s.length,1)}return m}function Du(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function qa(){const r=Du();r?.delete(Iu),r?.delete(Qi)}function _d(r,n){const s=Du();if(!s||typeof Highlight>"u")return;s.set(Iu,new Highlight(...r));const l=r[n];l?s.set(Qi,new Highlight(l)):s.delete(Qi)}function Bd(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Rg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Cg(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Ng(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function Fu(r,n,s){return n?r:qr.createPortal(r,s)}const ul="termdock:right-sidebar:file-tree-scroll:v1",fl="termdock:right-sidebar:file-preview-reading-state:v1",Ps="termdock:right-sidebar:file-tree-width:v1",_u="termdock:right-sidebar:markdown-view-mode:v1",Bu="termdock:right-sidebar:diff-change-list-mode:v1",Ou="termdock:right-sidebar:diff-wrap:v1",Uu="termdock:diff-viewer:view-type:v1",Hu="termdock:right-sidebar:file-search-mode:v1",Ci="termdock:right-sidebar:collapsed-git-repo-groups:v1",Od="termdock:right-sidebar:collapsed-diff-directories:v1",Ni="termdock:right-sidebar:branch-audit-module-open:v1",zu="termdock:right-sidebar:branch-audit-module:v1",Mg=150,Ud="termdock:right-sidebar:context-draft-enabled:v1",Hd="termdock:right-sidebar:context-draft-collapsed:v1",zd="termdock:right-sidebar:context-draft-auto-collapse:v1",Mi="termdock:right-sidebar:context-draft-text:v1",Eg=300,$g=20,Ag=120,Lg=250,Pg=250,Tg=120,Ig=700,Ei=600,Dg=6e4;function Es(r){return!!(r&&J.getState().nestedGitScanRoots[r])}const Wd=[2e3,5e3,15e3,3e4],Fg=320,_g=500,Bg=20,Og=12e3,Zi=300,Gd=240,Ug=560,Wu="border-r px-2 py-1.5 sm:px-3 sm:py-2",uo="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Gu=`${Wu} border-b border-border/15 font-semibold last:border-r-0`,Ku=`${Wu} border-border/10 align-top text-muted-foreground last:border-r-0`,hl="termdock-file-preview-horizontal-scroll",Kd=a.lazy(()=>Us(()=>import("./ModelPreview-C98dbuUF.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Vu=`${hl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function qu(r,n,s){return r&&!n?"unified":s}const Hg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function zg(r){return r==="preview"||r==="source"}function Wg(r){return r==="list"||r==="tree"||r==="ai"}function Vd(){return mt(_u,zg)??"preview"}function Gg(){return mt(Bu,Wg)??"tree"}function Ts(r){return typeof r=="boolean"}function Kg(r){return typeof r=="string"}function Vg(){return mt(Ou,Ts)??!0}function qg(r){return r==="unified"||r==="split"}function Yg(){return mt(Uu,qg)??"unified"}function Xg(r){return r==="name"||r==="content"||r==="regex"}function Jg(){return mt(Hu,Xg)??"name"}function Yu(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:kt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function Qg(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 el(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Xu(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function tl(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function qd(r){const n=mt(r,tl);return n?new Set(n):new Set}function $i(r,n){At(r,[...n])}function Zg(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 eb(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||tl(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Zg))&&(n.commits===void 0||tl(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 tb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&eb(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function rb(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(tb))&&(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 Yd(){return mt(zu,rb)??{}}function Xd(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function Jd(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Ju(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||Jd(s)===Jd(l)}function Qd(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!Ju(l,n))??""}function rl(r,n){const s=Math.max(Gd,n-320),l=Math.min(Ug,s);return Math.min(l,Math.max(Gd,r))}function nb(r){return typeof r=="number"&&Number.isFinite(r)}function sb(r){return rl(mt(Ps,nb)??Zi,r)}function Qu(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function $s(r){return Hg.has(Qu(r))}function Zu(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)||Zu(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function ef(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const tf=a.createContext(null);function oo(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function rf(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function nf(r){return r.replace(/\s+#+\s*$/,"").trim()}function sl(r,n){const l=rf(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function Zd(r){return rf(r)||r.trim()}function fo(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=ol(n[2]);return s?{id:oo(n[1]),definition:{href:s.href,title:s.title}}:null}function ab(r){const n=new Map;for(const s of r){const l=fo(s);l&&n.set(l.id,l.definition)}return n}function sf(r){return r.trim().toLowerCase()}function af(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:sf(n[1]),text:n[2]}:null}function ob(r){const n=new Map;let s=null;for(const l of r){const u=af(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const d=n.get(s);d&&(d.text=`${d.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function of(r){const n=new Set;let s=!1;return r.forEach((l,u)=>{if(af(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function ib(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 u=r[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.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 lf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Fs(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const d of n.split("/"))if(!(!d||d===".")){if(d===".."){l.length>0&&l.pop();continue}l.push(d)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function ml(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 u=l.indexOf("#"),d=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",g=d.split("?",1)[0];if(!g)return null;let m,b=null;try{m=decodeURIComponent(g),b=h?decodeURIComponent(h):null}catch{return null}const f=s?Fs(s):null;let j;if(m.startsWith("/")){const w=f&&(m===f||m.startsWith(`${f}/`));j=Fs(f&&!w?`${f}/${m.slice(1)}`:m)}else{if(!n)return null;j=Fs(`${lf(n)}/${m}`)}return f&&j!==f&&!j.startsWith(`${f}/`)?null:{path:j,fragment:b,directory:/\/$/.test(g)}}function pl(r,n,s,l,u){const d=r.trim();if(!d||/^(?:javascript|data):/i.test(d))return null;if(/^https?:\/\//i.test(d))return d;if(!l(d.split(/[?#]/,1)[0]))return null;let h;if(d.startsWith("/")){const g=s&&(d===s||d.startsWith(`${s}/`));h=Fs(s&&!g?`${s}/${d.slice(1)}`:d)}else{if(!n)return null;h=Fs(`${lf(n)}/${d}`)}return u(h)}function lb(r,n,s){return pl(r,n,s,dl,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function cb(r,n,s){return pl(r,n,s,fu,hu)}const al=128,db=360,Ai=480;function yo(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function cf(r,n,s,l,u=0){if(!n||!s)return null;let d,h;return u>0?(d=l>0?Math.min(u,l):u,h=s*d/n):yo(r)?(h=Math.min(Math.max(s,al),db),d=n*h/s):(d=n,h=s),l>0&&d>l&&(h=h*l/d,d=l),h>Ai&&(d=d*Ai/h,h=Ai),{width:Math.max(1,Math.round(d)),height:Math.max(1,Math.round(h))}}function ub(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function df(r){const n=ub(r),s=J(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function fb({src:r,alt:n,title:s,requestedWidthPx:l}){const u=yo(r),d=df(r),h=xo(d),g=a.useRef(null),[m,b]=a.useState(!1),[f,j]=a.useState(0),[w,M]=a.useState({status:"loading"}),[I,_]=a.useState(null);a.useLayoutEffect(()=>{const $=g.current,A=$?.parentElement?.parentElement??$?.parentElement;if(!A)return;const T=()=>j(A.clientWidth);if(T(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(T);return U.observe(A),()=>U.disconnect()},[]),a.useEffect(()=>{if(m)return;const $=g.current;if(!$||typeof IntersectionObserver>"u"){b(!0);return}const A=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(b(!0),A.disconnect())},{rootMargin:"400px"});return A.observe($),()=>A.disconnect()},[m]),a.useEffect(()=>{if(!m)return;const $=new AbortController;let A=null;M({status:"loading"});const T=window.setTimeout(()=>{$.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Sm(d,{signal:$.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const D=Number(U.headers.get("X-Image-Width"))||0,p=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:D,height:p}}).then(({blob:U,width:D,height:p})=>{$.signal.aborted||(A=URL.createObjectURL(U),D>0&&p>0&&_({width:D,height:p}),M({status:"ready",objectUrl:A}))}).catch(()=>{const U=$.signal.reason;$.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||M({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),$.abort(),A&&URL.revokeObjectURL(A)}},[m,d]);const B=cf(r,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:al*2,height:al});return e.jsx("div",{ref:g,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:w.status==="ready"?e.jsx("img",{src:w.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:$=>{if(I)return;const A=$.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&_({width:A.naturalWidth,height:A.naturalHeight})}}):w.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:B?{width:B.width,height:B.height}:void 0,onLoad:$=>{if(I)return;const A=$.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&_({width:A.naturalWidth,height:A.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:E.width,height:E.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function _s(r,n,s,l,u,d){const h=lb(s,u.markdownFilePath,u.rootPath);if(!h)return d?.fallbackText??`![${n}](${s})`;const g=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const m=e.jsx(fb,{src:h,alt:n,title:l,requestedWidthPx:d?.requestedWidthPx});return u.onImageOpen&&d?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:b=>{b.stopPropagation(),u.onImageOpen?.(g)},children:m},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:m},r)}function Li(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function eu(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function ol(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 uf="",hb=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function mb(r){return r.replace(hb,(n,s)=>`${uf}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function tu(r){return r.replace(new RegExp(`${uf}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function pb(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const ff={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 Ya=null;function hf(){return Ya||(Ya=Us(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw Ya=null,r})),Ya}function mf({html:r}){const{t:n}=St(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),hf().then(d=>{u||l(d.sanitize(r,ff))}).catch(()=>{u||l("")}),()=>{u=!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 gb({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),hf().then(u=>{l||s(u.sanitize(r,ff))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function pf(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 Xa=null;function bb(){return Xa||(Xa=Promise.all([Us(()=>import("./katex-DnlPpQZa.js"),[]),Us(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw Xa=null,r})),Xa}function zs({tex:r,display:n=!1}){const[s,l]=a.useState(null),[u,d]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),d(!1),bb().then(m=>{g||l(m.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||d(!0)}),()=>{g=!0}},[n,r]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function gl(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 ru(r){const n=gl(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 xb(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=gl(s),u=l.get("src")?.trim()??"",d=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:g,widthPx:d?Number(d[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function vb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=St(),[d,h]=a.useState(!1),g=xo(r,()=>h(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:d?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function yb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),g=gl(h).get("href")?.trim()??"",m=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:j,widthPx:w}=ru(m);if(!b)return null;const M=pl(b,s.markdownFilePath,s.rootPath,dl,$=>$);if(!M)return null;const I=g?ml(g,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===M)&&g?ef(g):null,E=_s(n,f??"",b,j,s,{requestedWidthPx:w,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:g,title:m,widthPx:b}=ru(r);return h?_s(n,g??"",h,m,s,{fallbackText:r,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:g,widthPx:m,controls:b}=xb(r);if(!h)return null;const f=cb(h,s.markdownFilePath,s.rootPath);return f?e.jsx(vb,{url:f,fallbackText:g,widthPx:m,hasControls:b},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(gb,{html:r},n):null;const u=l[1].toLowerCase(),d=ut(l[2],`${n}-${u}`,!0,s);return u==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:d},n):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:d},n):u==="sub"?e.jsx("sub",{children:d},n):e.jsx("sup",{children:d},n)}function ut(r,n,s=!0,l){const u=mb(r),d=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let g=0,m;for(;(m=d.exec(u))!==null;){m.index>g&&h.push(tu(u.slice(g,m.index)));const b=m[0],f=`${n}-${m.index}`,j=b.startsWith("<")?yb(b,f,l):null;if(j)h.push(j);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(zs,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(zs,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const w=b.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:pb(b.slice(w,-w))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ut(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ut(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:ut(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const w=b.match(/^!\[([^\]]*)\]\((.*)\)$/),M=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^!\[([^\]]+)\]$/);if(w){const _=ol(w[2]);h.push(_?_s(f,w[1],_.href,_.title,l):b)}else if(M){const _=M[2]||M[1],B=l.referenceDefinitions.get(oo(_));h.push(B?_s(f,M[1],B.href,B.title,l):b)}else if(I){const _=l.referenceDefinitions.get(oo(I[1]));h.push(_?_s(f,I[1],_.href,_.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const w=sf(b.slice(2,-1)),M=l.footnoteDefinitions.get(w);h.push(M?e.jsx("sup",{id:`fnref-${M.id}`,title:M.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${M.id}`,className:"text-primary no-underline",children:M.index})},f):b)}else if(b.startsWith("<http")){const w=b.slice(1,-1);h.push(e.jsx("a",{href:w,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:w},f))}else if(b.startsWith("<")&&b.endsWith(">")&&eu(b.slice(1,-1))){const w=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${w}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:w},f))}else if(eu(Li(b).linkText)){const{linkText:w,suffix:M}=Li(b);h.push(e.jsx("a",{href:`mailto:${w}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:w},f)),M&&h.push(M)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:w,suffix:M}=Li(b),I=w.startsWith("www.")?`https://${w}`:w;h.push(e.jsx("a",{href:I,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:w},f)),M&&h.push(M)}else{const w=b.match(/^\[([^\]]+)\]\((.*)\)$/),M=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^\[([^\]]+)\]$/),_=M?M[2]||M[1]:I?.[1]??null,B=_?l.referenceDefinitions.get(oo(_)):null,E=w?ol(w[2]):null,$=E?.href??B?.href??null,A=$?ef($):null,T=w?.[1]??M?.[1]??I?.[1]??"";h.push(A?e.jsx("a",{href:A,title:E?.title??B?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ut(T,`${f}-link`,s,l)},f):b)}g=d.lastIndex}return g<u.length&&h.push(tu(u.slice(g))),h.length>0?h:[r]}function gf(r){return/(?: {2,}|\\)$/.test(r)}function bf(r){return r.replace(/(?: {2,}|\\)$/,"")}function ho(r){return/^(?: {4}|\t)/.test(r)}function xf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function vf(r,n,s){const l=[];return r.forEach((u,d)=>{const h=gf(u);l.push(...ut(bf(u),`${n}-${d}`,!0,s)),d<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${d}-br`):" ")}),l}function il(r,n,s){const l=[],u=[];return r.forEach((d,h)=>{u.push(gf(d)),l.push(ut(bf(d),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function ll(r,n,s,l,u){const d=[];return r.forEach((h,g)=>{const m=s[g]??0,b=!!(u&&m>=u.start&&m<=u.end);d.push(e.jsx("span",{"data-md-ref-start":m,"data-md-ref-end":m,"data-selected":b?"true":void 0,children:h},`${l}-ref-${g}`)),g<r.length-1&&d.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),d}function Ws(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,d=0,h=0;for(let g=0;g<n.length;g+=1){const m=n[g];if(u){l+=m,u=!1;continue}if(m==="\\"){u=!0;continue}if(m==="`"){const b=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const f=g-b+1;l+="`".repeat(f),d===0?d=f:d===f&&(d=0);continue}if(d===0&&m==="["?h+=1:d===0&&m==="]"&&h>0&&(h-=1),m==="|"&&d===0&&h===0){s.push(l.trim()),l="";continue}l+=m}return u&&(l+="\\"),s.push(l.trim()),s}function yf(r){return Ws(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 po(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function wf(r,n){return r>96||r>44&&n>.35}function wo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Gs(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 bl(r,n,s,l,u,d=new Set){const h=[],g=[];let m=n;for(;m<r.length;){const b=r[m];if(u&&(fo(b)||d.has(m))){m+=1;continue}const f=Gs(b),j=wo(b);if(!f){if(j>s&&g.length>0){([...g].reverse().find(_=>_.indent<j)?.item??g[g.length-1].item).paragraphs.push(b.trim());for(const _ of g)_.item.lineEnd=m+1;m+=1;continue}break}if(j<s||j===s&&f.ordered!==l)break;const w={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:m+1,lineEnd:m+1};for(;g.length>0&&g[g.length-1].indent>=j;)g.pop();const M=g[g.length-1]?.item??null;M?M.children.push(w):h.push(w),g.push({indent:j,item:w});for(const I of g)I.item.lineEnd=m+1;m+=1}return{items:h,nextIndex:m}}function wb(r){const n=r.find(l=>Gs(l));if(!n)return[];const s=Gs(n);return s?bl(r,0,wo(n),s.ordered,!0,of(r)).items:[]}function xl(r,n,s,l=0){return r.map((u,d)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${d}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,ut(h?.[2]??u.content,`li-${n}-${d}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((g,m)=>e.jsx("p",{children:ut(g,`li-${n}-${d}-p-${m}`,!0,s)},`paragraph-${m}`))})]}),groups:kb(u.children,`${n}-${d}`,s,l)}})}function kb(r,n,s,l=0){const u=[];for(const d of r){const h=u[u.length-1];h&&h.ordered===d.ordered?h.items.push(d):u.push({ordered:d.ordered,items:[d]})}return u.map((d,h)=>({ordered:d.ordered,start:d.ordered?d.items[0]?.start:void 0,items:xl(d.items,`${n}-g${h}`,s,l)}))}function vl(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&&Sb(s.groups,n)]},s.key)})}function Sb(r,n){return r.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:vl(s.items,n)},`nested-${l}`)})}function jb(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 Rb(r,n,s,l){const u=[];let d=0;const h=g=>l?.[g]??g+1;for(;d<r.length;){const g=r[d],m=g.trim();if(!m){d+=1;continue}if(/^<details>\s*$/i.test(m)){const E=d;let $="Details";const A=[];for(d+=1;d<r.length&&!/^<\/details>\s*$/i.test(r[d].trim());){const T=r[d].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?$=T[1].trim()||$:A.push(r[d].trimStart()),d+=1}d<r.length&&(d+=1),u.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:ut($,`${n}-details-${E}-summary`,!0,s)}),A.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:vf(A,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const b=pf(g);if(b){const E=[g],$=d;for(d+=1;d<r.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(r[d]);)E.push(r[d]),d+=1;d<r.length&&!b.selfContained&&(E.push(r[d]),d+=1),u.push({kind:"static",node:e.jsx(mf,{html:E.join(`
1639
- `)},`${n}-html-${$}`)});continue}const f=m.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],$=f[1],A=f[2]?.trim(),T=d;for(d+=1;d<r.length&&!r[d].trim().startsWith($);)E.push(r[d]),d+=1;d<r.length&&(d+=1),A.toLowerCase()==="mermaid"?u.push({kind:"static",node:e.jsx(Sf,{code:E.join(`
1635
+ `,Va="/api/terminal/fs/preview/",bg=8*1024*1024,xg=32*1024*1024,vg=128,wg="data:,";function $t(r){throw new Error(r)}function yg(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function _d(r,n,s){let l="",u=0;for(const d of r.matchAll(n))l+=r.slice(u,d.index)+await s(d),u=d.index+d[0].length;return l+r.slice(u)}async function Iu(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!Cs(l.pathname)?.startsWith(Va))&&$t("预览地址不是有效的本地文件入口");const u=crypto.randomUUID(),d=`https://termdock-preview.invalid/${u}/`,h=[],g=W=>{!h.includes(W)&&h.length<20&&h.push(W)},m=new Set,b=[],f=new Set,j=new Map,y=new Map;let M=0,I=!1;const _=new Set,B=()=>{I=!0;for(const W of[..._])W();m.clear(),b.length=0};async function E(W){W.ok||$t(`预览资源读取失败(${W.status})`);const X=W.body?.getReader(),L=[];let F=0;try{if(X)for(;;){const ie=await X.read();if(ie.done)break;F+=ie.value.byteLength,M+=ie.value.byteLength,(F>bg||M>xg)&&$t("预览资源超出大小限制"),L.push(ie.value)}}catch(ie){throw await X?.cancel().catch(()=>{}),ie}finally{X?.releaseLock()}const V=new Uint8Array(F);let re=0;for(const ie of L)V.set(ie,re),re+=ie.length;return{bytes:V,type:W.headers.get("content-type")??"application/octet-stream",status:W.status}}let $=l,A;for(let W=0;W<4;W++){const X=await n.fetch($.pathname+$.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(X.status)){A=X;break}const L=X.headers.get("location");await X.body?.cancel(),L||$t("预览重定向缺少目标");const F=new URL(L,$);(F.origin!==s||!Cs(F.pathname)?.startsWith(Va))&&$t("预览重定向越出文件范围"),$=F}A||$t("预览重定向次数过多");const T=Cs($.pathname),U=T.slice(Va.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||$t("服务未提供有效的预览资源授权");const D=Cs(l.pathname).slice(Va.length).split("/");/^[a-f0-9]{32}$/.test(D[0])&&D.shift(),D.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&$t("预览重定向改变了文件范围");const p=T.endsWith("/")?T:T.slice(0,T.lastIndexOf("/")+1),i=new URL($.pathname.endsWith("/")?$.pathname:$.pathname.slice(0,$.pathname.lastIndexOf("/")+1),s);function O(W,X){const L=new URL(W,X);return L.origin!==s?null:(Cs(L.pathname)?.startsWith(p)||$t("已阻止预览访问目录之外的资源"),L)}function C(W){const X=new URL(W,d);(X.origin!==new URL(d).origin||!X.pathname.startsWith(new URL(d).pathname))&&$t("已阻止预览访问服务接口或目录之外的资源");const L=X.pathname.slice(new URL(d).pathname.length)+X.search;return O(L,i)??$t("预览资源无效")}function K(W){const X=W.pathname+W.search,L=j.get(X);if(L)return L;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(j.size>=vg)return Promise.reject(new Error("预览资源数量超出限制"));const F=n.fetch(X,{signal:n.signal,redirect:"manual"}).then(E);return j.set(X,F),F}function de(W,X){I&&$t("预览已关闭");const L=`termdock-resource-${u}-${b.length}`;return b.push({token:L,data:W,type:X}),m.add(L),L}async function te(W,X,L,F=new Set){if(!W||W.startsWith("#")||/^data:(?:image|font)\//i.test(W)&&L==="resource")return W;try{const V=O(W,X);if(!V){const De=new URL(W,X);return(De.protocol!=="https:"||De.username||De.password||De.origin===new URL(d).origin)&&$t("已阻止不安全的外部资源"),f.add(De.origin),De.href}const re=`${L}:${V.href}`;(F.has(re)||F.size>=8)&&$t("预览资源存在循环或过深引用");const ie=y.get(re);if(ie)return ie;const we=new Set(F);we.add(re);const pe=(async()=>{const De=await K(V);return L==="css"?de(await xe(new TextDecoder().decode(De.bytes),V,we),"text/css"):L==="script"?de(De.bytes,"text/javascript"):de(De.bytes,De.type)})();return y.set(re,pe),await pe}catch(V){return g(V instanceof Error?V.message:"部分预览资源未能加载"),wg}}async function xe(W,X,L){return W=await _d(W,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async F=>`@import url("${await te(F[1],X,"css",L)}")${F[2]};`),_d(W,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async F=>{const V=(F[1]??F[2]??F[3]).trim();return m.has(V)?F[0]:`url("${await te(V,X,"resource",L)}")`})}try{const W=await E(A),X=de(pg,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(W.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(N=>N.remove());for(const N of L.querySelectorAll("*")){if(N.removeAttribute("ping"),N.removeAttribute("srcdoc"),N.hasAttribute("style")&&N.setAttribute("style",await xe(N.getAttribute("style"),$,new Set)),N.tagName==="STYLE"&&(N.textContent=await xe(N.textContent??"",$,new Set)),N.tagName==="A"||N.tagName==="AREA"){const q=N.getAttribute("href");try{if(q&&!q.startsWith("#")){const he=O(q,$);if(he)N.setAttribute("href",new URL(he.pathname.slice(i.pathname.length)+he.search+he.hash,d).href);else{const Ae=new URL(q,$);if(Ae.protocol!=="https:"){N.removeAttribute("href");continue}f.add(Ae.origin),N.setAttribute("href",Ae.href)}}}catch(he){N.removeAttribute("href"),g(he instanceof Error?he.message:"预览链接无法加载")}}for(const q of["data","manifest"])N.removeAttribute(q);if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="module"){N.setAttribute("type","module-shim");const q=N.getAttribute("src");if(q){const he=O(q,$);if(he)N.setAttribute("src",new URL(he.pathname.slice(i.pathname.length)+he.search,d).href);else{const Ae=new URL(q,$);if(Ae.protocol!=="https:"){N.remove();continue}f.add(Ae.origin),N.setAttribute("src",Ae.href)}}continue}if(N.tagName==="SCRIPT"&&N.getAttribute("type")==="importmap"){N.setAttribute("type","importmap-shim");continue}if(N.tagName==="LINK"){const q=(N.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(q)){N.remove();continue}const he=N.getAttribute("href");he&&N.setAttribute("href",await te(he,$,q==="stylesheet"?"css":"resource"))}if(N.hasAttribute("src")&&N.setAttribute("src",await te(N.getAttribute("src"),$,N.tagName==="SCRIPT"?"script":"resource")),N.hasAttribute("poster")&&N.setAttribute("poster",await te(N.getAttribute("poster"),$,"resource")),N.hasAttribute("srcset")){const q=N.getAttribute("srcset");/data:/i.test(q)?(N.removeAttribute("srcset"),g("混合内嵌图片候选暂不支持安全预览")):N.setAttribute("srcset",(await Promise.all(q.split(",").map(async he=>{const[Ae,...Qe]=he.trim().split(/\s+/);return`${await te(Ae,$,"resource")} ${Qe.join(" ")}`}))).join(", "))}N.setAttribute("referrerpolicy","no-referrer"),N.removeAttribute("integrity"),N.removeAttribute("crossorigin")}const F=[...f].join(" "),V=L.createElement("meta");V.httpEquiv="Content-Security-Policy",V.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${F}; style-src 'unsafe-inline' blob: ${F}; img-src blob: data: ${F}; font-src blob: data: ${F}; media-src blob: data: ${F}; connect-src blob: ${F} ${[...f].map(N=>N.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=L.createElement("base");re.href=d;const ie=L.createElement("meta");ie.name="referrer",ie.content="no-referrer";const we=L.createElement("script");we.textContent=gg+`
1636
+ installPreviewRuntime(`+[u,d,[...f],X].map(yg).join(",")+");";const pe=L.createElement("script");pe.src=X,L.head.prepend(V,ie,re,we,pe);const De=`<!doctype html>
1637
+ `+L.documentElement.outerHTML;return{html:De,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(N,q){const he=new Set,Ae=Le=>{if(Le.source!==N.contentWindow||Le.data?.capability!==u)return;if(Le.data.type==="preview-ready"){N.contentWindow?.postMessage({type:"preview-init",capability:u,html:De,resources:b},"*");return}if(Le.data.type==="preview-error"){q("部分动态内容被安全预览限制");return}if(Le.data.type==="preview-navigate"){(async()=>{const Be=C(String(Le.data.url)),R=await Iu(Be.pathname+Be.search,n);if(I){R.dispose();return}const ee=R.attach(N,q);_.add(()=>{ee(),R.dispose()}),N.src=R.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Be=>q(Be instanceof Error?Be.message:"无法打开预览页面"));return}if(Le.data.type==="preview-external"){try{const Be=new URL(String(Le.data.url));Be.protocol==="https:"&&f.has(Be.origin)&&window.open(Be.href,"_blank","noopener,noreferrer")}catch{}return}if(Le.data.type!=="preview-fetch"||Le.ports.length!==1)return;const at=Le.ports[0];if(he.size>=8||!["GET","HEAD"].includes(Le.data.method)){at.postMessage({error:"预览仅允许读取已授权目录资源"}),at.close();return}he.add(at),(async()=>{const Be=C(String(Le.data.url)),R=await K(Be);if(!he.has(at)||I)return;const ee=Le.data.method==="HEAD"?new Uint8Array:R.bytes.slice();at.postMessage({status:R.status,headers:{"content-type":R.type},data:ee.buffer},[ee.buffer])})().catch(()=>{at.postMessage({error:"预览资源不在授权范围或无法加载"}),q("部分动态资源不可用或超出预览目录")}).finally(()=>{he.delete(at),at.close()})};window.addEventListener("message",Ae);const Qe=()=>{window.removeEventListener("message",Ae);for(const Le of he)Le.close();he.clear(),_.delete(Qe)};return _.add(Qe),Qe},dispose:B}}catch(W){throw B(),W}}const kg=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},d){const h=a.useRef(null),[g,m]=a.useState(null),[b,f]=a.useState(),[j,y]=a.useState("");a.useEffect(()=>{const T=new AbortController;let U;return f(void 0),y(""),(async()=>{const D=await Xh();if(U=await Iu(n,{fetch:(p,i)=>D.fetch(p,i),signal:T.signal}),T.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(D=>{T.signal.aborted||y(D instanceof Error?D.message:"安全预览加载失败")}),()=>{T.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!g))return b.attach(g,y)},[b,g]);const[M,I]=a.useState(!1),[_,B]=a.useState(!1),E=M||_;a.useEffect(()=>{u?.(E)},[E,u]),a.useEffect(()=>{const T=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",T),()=>document.removeEventListener("fullscreenchange",T)},[]),a.useEffect(()=>{if(!_)return;const T=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[_]);const $=a.useCallback(async()=>{const T=h.current;if(T){if(_){B(!1);return}if(document.fullscreenElement===T){await document.exitFullscreen();return}if(T.requestFullscreen&&document.fullscreenEnabled!==!1)try{await T.requestFullscreen();return}catch{}B(!0)}},[_]);a.useImperativeHandle(d,()=>({toggleFullscreen:$}),[$]);const A=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:E?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[E&&e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[e.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:s}),e.jsx("button",{type:"button",onClick:()=>{$()},"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(Su,{size:15})})]}),j&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:j}),!b&&!j&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:m,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return _?qr.createPortal(A,document.body):A}),Du="termdock-file-search-match",Qi="termdock-file-search-current";function Sg(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 jg(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Rg(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let u="",d=null;const h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const j=jg(f);if(!j)continue;d&&d!==j&&(u+=`
1638
+ `);const y=u.length;u+=f.data,l.push({node:f,start:y,end:u.length,group:j}),d=j}const g=u.toLocaleLowerCase(),m=[];let b=0;for(;b<=g.length-s.length;){const f=g.indexOf(s,b);if(f<0)break;const j=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),M=l.find(I=>I.start<j&&I.end>=j);if(y&&M&&y.group===M.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(M.node,j-M.start),m.push(I)}b=f+Math.max(s.length,1)}return m}function Fu(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function qa(){const r=Fu();r?.delete(Du),r?.delete(Qi)}function Bd(r,n){const s=Fu();if(!s||typeof Highlight>"u")return;s.set(Du,new Highlight(...r));const l=r[n];l?s.set(Qi,new Highlight(l)):s.delete(Qi)}function Od(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Cg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Ng(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Mg(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function _u(r,n,s){return n?r:qr.createPortal(r,s)}const fl="termdock:right-sidebar:file-tree-scroll:v1",hl="termdock:right-sidebar:file-preview-reading-state:v1",Ps="termdock:right-sidebar:file-tree-width:v1",Bu="termdock:right-sidebar:markdown-view-mode:v1",Ou="termdock:right-sidebar:diff-change-list-mode:v1",Uu="termdock:right-sidebar:diff-wrap:v1",Hu="termdock:diff-viewer:view-type:v1",zu="termdock:right-sidebar:file-search-mode:v1",Ni="termdock:right-sidebar:collapsed-git-repo-groups:v1",Ud="termdock:right-sidebar:collapsed-diff-directories:v1",Mi="termdock:right-sidebar:branch-audit-module-open:v1",Wu="termdock:right-sidebar:branch-audit-module:v1",Eg=150,Hd="termdock:right-sidebar:context-draft-enabled:v1",zd="termdock:right-sidebar:context-draft-collapsed:v1",Wd="termdock:right-sidebar:context-draft-auto-collapse:v1",Ei="termdock:right-sidebar:context-draft-text:v1",$g=300,Ag=20,Lg=120,Pg=250,Tg=250,Ig=120,Dg=700,$i=600,Fg=6e4;function Es(r){return!!(r&&J.getState().nestedGitScanRoots[r])}const Gd=[2e3,5e3,15e3,3e4],_g=320,Bg=500,Og=20,Ug=12e3,el=300,Kd=240,Hg=560,Gu="border-r px-2 py-1.5 sm:px-3 sm:py-2",uo="min-w-full max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Ku=`${Gu} border-b border-border/15 font-semibold last:border-r-0`,Vu=`${Gu} border-border/10 align-top text-muted-foreground last:border-r-0`,ml="termdock-file-preview-horizontal-scroll",Vd=a.lazy(()=>Us(()=>import("./ModelPreview-BgzcGTC4.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),qu=`${ml} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Yu(r,n,s){return r&&!n?"unified":s}const zg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Wg(r){return r==="preview"||r==="source"}function Gg(r){return r==="list"||r==="tree"||r==="ai"}function qd(){return mt(Bu,Wg)??"preview"}function Kg(){return mt(Ou,Gg)??"tree"}function Ts(r){return typeof r=="boolean"}function Vg(r){return typeof r=="string"}function qg(){return mt(Uu,Ts)??!0}function Yg(r){return r==="unified"||r==="split"}function Xg(){return mt(Hu,Yg)??"unified"}function Jg(r){return r==="name"||r==="content"||r==="regex"}function Zg(){return mt(zu,Jg)??"name"}function Xu(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:kt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function Qg(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 tl(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Ju(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function rl(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function Yd(r){const n=mt(r,rl);return n?new Set(n):new Set}function Ai(r,n){At(r,[...n])}function eb(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 tb(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||rl(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(eb))&&(n.commits===void 0||rl(n.commits))&&(n.commitCount===void 0||typeof n.commitCount=="number")&&(n.diff===void 0||typeof n.diff=="string")&&(n.truncated===void 0||typeof n.truncated=="boolean")&&(n.error===void 0||typeof n.error=="string")}function rb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&tb(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function nb(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(rb))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.repoIncludeUncommitted===void 0||!!s.repoIncludeUncommitted&&typeof s.repoIncludeUncommitted=="object"&&!Array.isArray(s.repoIncludeUncommitted)&&Object.values(s.repoIncludeUncommitted).every(l=>typeof l=="boolean"))&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Xd(){return mt(Wu,nb)??{}}function Jd(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function Zd(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Zu(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||Zd(s)===Zd(l)}function Qd(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!Zu(l,n))??""}function nl(r,n){const s=Math.max(Kd,n-320),l=Math.min(Hg,s);return Math.min(l,Math.max(Kd,r))}function sb(r){return typeof r=="number"&&Number.isFinite(r)}function ab(r){return nl(mt(Ps,sb)??el,r)}function Qu(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function $s(r){return zg.has(Qu(r))}function ef(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function sl(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||ef(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function tf(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const rf=a.createContext(null);function oo(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function nf(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function sf(r){return r.replace(/\s+#+\s*$/,"").trim()}function al(r,n){const l=nf(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function eu(r){return nf(r)||r.trim()}function fo(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=il(n[2]);return s?{id:oo(n[1]),definition:{href:s.href,title:s.title}}:null}function ob(r){const n=new Map;for(const s of r){const l=fo(s);l&&n.set(l.id,l.definition)}return n}function af(r){return r.trim().toLowerCase()}function of(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:af(n[1]),text:n[2]}:null}function ib(r){const n=new Map;let s=null;for(const l of r){const u=of(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const d=n.get(s);d&&(d.text=`${d.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function lf(r){const n=new Set;let s=!1;return r.forEach((l,u)=>{if(of(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function lb(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const u=r[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.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 cf(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Fs(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const d of n.split("/"))if(!(!d||d===".")){if(d===".."){l.length>0&&l.pop();continue}l.push(d)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function pl(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 u=l.indexOf("#"),d=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",g=d.split("?",1)[0];if(!g)return null;let m,b=null;try{m=decodeURIComponent(g),b=h?decodeURIComponent(h):null}catch{return null}const f=s?Fs(s):null;let j;if(m.startsWith("/")){const y=f&&(m===f||m.startsWith(`${f}/`));j=Fs(f&&!y?`${f}/${m.slice(1)}`:m)}else{if(!n)return null;j=Fs(`${cf(n)}/${m}`)}return f&&j!==f&&!j.startsWith(`${f}/`)?null:{path:j,fragment:b,directory:/\/$/.test(g)}}function gl(r,n,s,l,u){const d=r.trim();if(!d||/^(?:javascript|data):/i.test(d))return null;if(/^https?:\/\//i.test(d))return d;if(!l(d.split(/[?#]/,1)[0]))return null;let h;if(d.startsWith("/")){const g=s&&(d===s||d.startsWith(`${s}/`));h=Fs(s&&!g?`${s}/${d.slice(1)}`:d)}else{if(!n)return null;h=Fs(`${cf(n)}/${d}`)}return u(h)}function cb(r,n,s){return gl(r,n,s,ul,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function db(r,n,s){return gl(r,n,s,hu,mu)}const ol=128,ub=360,Li=480;function wo(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function df(r,n,s,l,u=0){if(!n||!s)return null;let d,h;return u>0?(d=l>0?Math.min(u,l):u,h=s*d/n):wo(r)?(h=Math.min(Math.max(s,ol),ub),d=n*h/s):(d=n,h=s),l>0&&d>l&&(h=h*l/d,d=l),h>Li&&(d=d*Li/h,h=Li),{width:Math.max(1,Math.round(d)),height:Math.max(1,Math.round(h))}}function fb(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function uf(r){const n=fb(r),s=J(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function hb({src:r,alt:n,title:s,requestedWidthPx:l}){const u=wo(r),d=uf(r),h=xo(d),g=a.useRef(null),[m,b]=a.useState(!1),[f,j]=a.useState(0),[y,M]=a.useState({status:"loading"}),[I,_]=a.useState(null);a.useLayoutEffect(()=>{const $=g.current,A=$?.parentElement?.parentElement??$?.parentElement;if(!A)return;const T=()=>j(A.clientWidth);if(T(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(T);return U.observe(A),()=>U.disconnect()},[]),a.useEffect(()=>{if(m)return;const $=g.current;if(!$||typeof IntersectionObserver>"u"){b(!0);return}const A=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(b(!0),A.disconnect())},{rootMargin:"400px"});return A.observe($),()=>A.disconnect()},[m]),a.useEffect(()=>{if(!m)return;const $=new AbortController;let A=null;M({status:"loading"});const T=window.setTimeout(()=>{$.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return jm(d,{signal:$.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const D=Number(U.headers.get("X-Image-Width"))||0,p=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:D,height:p}}).then(({blob:U,width:D,height:p})=>{$.signal.aborted||(A=URL.createObjectURL(U),D>0&&p>0&&_({width:D,height:p}),M({status:"ready",objectUrl:A}))}).catch(()=>{const U=$.signal.reason;$.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||M({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),$.abort(),A&&URL.revokeObjectURL(A)}},[m,d]);const B=df(r,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:ol*2,height:ol});return e.jsx("div",{ref:g,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:$=>{if(I)return;const A=$.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&_({width:A.naturalWidth,height:A.naturalHeight})}}):y.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:B?{width:B.width,height:B.height}:void 0,onLoad:$=>{if(I)return;const A=$.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&_({width:A.naturalWidth,height:A.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:E.width,height:E.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function _s(r,n,s,l,u,d){const h=cb(s,u.markdownFilePath,u.rootPath);if(!h)return d?.fallbackText??`![${n}](${s})`;const g=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const m=e.jsx(hb,{src:h,alt:n,title:l,requestedWidthPx:d?.requestedWidthPx});return u.onImageOpen&&d?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:b=>{b.stopPropagation(),u.onImageOpen?.(g)},children:m},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:m},r)}function Pi(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function tu(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function il(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 ff="",mb=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function pb(r){return r.replace(mb,(n,s)=>`${ff}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ru(r){return r.replace(new RegExp(`${ff}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function gb(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const hf={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 Ya=null;function mf(){return Ya||(Ya=Us(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw Ya=null,r})),Ya}function pf({html:r}){const{t:n}=St(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),mf().then(d=>{u||l(d.sanitize(r,hf))}).catch(()=>{u||l("")}),()=>{u=!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 bb({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),mf().then(u=>{l||s(u.sanitize(r,hf))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function gf(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 Xa=null;function xb(){return Xa||(Xa=Promise.all([Us(()=>import("./katex-DnlPpQZa.js"),[]),Us(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw Xa=null,r})),Xa}function zs({tex:r,display:n=!1}){const[s,l]=a.useState(null),[u,d]=a.useState(!1);if(a.useEffect(()=>{let g=!1;return l(null),d(!1),xb().then(m=>{g||l(m.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{g||d(!0)}),()=>{g=!0}},[n,r]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function 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 nu(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 vb(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=bl(s),u=l.get("src")?.trim()??"",d=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),g=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:g,widthPx:d?Number(d[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function wb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=St(),[d,h]=a.useState(!1),g=xo(r,()=>h(!0));return g?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:d?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:g,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function yb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),g=bl(h).get("href")?.trim()??"",m=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:j,widthPx:y}=nu(m);if(!b)return null;const M=gl(b,s.markdownFilePath,s.rootPath,ul,$=>$);if(!M)return null;const I=g?pl(g,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===M)&&g?tf(g):null,E=_s(n,f??"",b,j,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:g,title:m,widthPx:b}=nu(r);return h?_s(n,g??"",h,m,s,{fallbackText:r,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:g,widthPx:m,controls:b}=vb(r);if(!h)return null;const f=db(h,s.markdownFilePath,s.rootPath);return f?e.jsx(wb,{url:f,fallbackText:g,widthPx:m,hasControls:b},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(bb,{html:r},n):null;const u=l[1].toLowerCase(),d=ut(l[2],`${n}-${u}`,!0,s);return u==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:d},n):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:d},n):u==="sub"?e.jsx("sub",{children:d},n):e.jsx("sup",{children:d},n)}function ut(r,n,s=!0,l){const u=pb(r),d=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let g=0,m;for(;(m=d.exec(u))!==null;){m.index>g&&h.push(ru(u.slice(g,m.index)));const b=m[0],f=`${n}-${m.index}`,j=b.startsWith("<")?yb(b,f,l):null;if(j)h.push(j);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(zs,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(zs,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const y=b.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:gb(b.slice(y,-y))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:ut(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:ut(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:ut(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const y=b.match(/^!\[([^\]]*)\]\((.*)\)$/),M=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^!\[([^\]]+)\]$/);if(y){const _=il(y[2]);h.push(_?_s(f,y[1],_.href,_.title,l):b)}else if(M){const _=M[2]||M[1],B=l.referenceDefinitions.get(oo(_));h.push(B?_s(f,M[1],B.href,B.title,l):b)}else if(I){const _=l.referenceDefinitions.get(oo(I[1]));h.push(_?_s(f,I[1],_.href,_.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const y=af(b.slice(2,-1)),M=l.footnoteDefinitions.get(y);h.push(M?e.jsx("sup",{id:`fnref-${M.id}`,title:M.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${M.id}`,className:"text-primary no-underline",children:M.index})},f):b)}else if(b.startsWith("<http")){const y=b.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(b.startsWith("<")&&b.endsWith(">")&&tu(b.slice(1,-1))){const y=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(tu(Pi(b).linkText)){const{linkText:y,suffix:M}=Pi(b);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),M&&h.push(M)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:y,suffix:M}=Pi(b),I=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:I,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),M&&h.push(M)}else{const y=b.match(/^\[([^\]]+)\]\((.*)\)$/),M=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^\[([^\]]+)\]$/),_=M?M[2]||M[1]:I?.[1]??null,B=_?l.referenceDefinitions.get(oo(_)):null,E=y?il(y[2]):null,$=E?.href??B?.href??null,A=$?tf($):null,T=y?.[1]??M?.[1]??I?.[1]??"";h.push(A?e.jsx("a",{href:A,title:E?.title??B?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:ut(T,`${f}-link`,s,l)},f):b)}g=d.lastIndex}return g<u.length&&h.push(ru(u.slice(g))),h.length>0?h:[r]}function bf(r){return/(?: {2,}|\\)$/.test(r)}function xf(r){return r.replace(/(?: {2,}|\\)$/,"")}function ho(r){return/^(?: {4}|\t)/.test(r)}function vf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function wf(r,n,s){const l=[];return r.forEach((u,d)=>{const h=bf(u);l.push(...ut(xf(u),`${n}-${d}`,!0,s)),d<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${d}-br`):" ")}),l}function ll(r,n,s){const l=[],u=[];return r.forEach((d,h)=>{u.push(bf(d)),l.push(ut(xf(d),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function cl(r,n,s,l,u){const d=[];return r.forEach((h,g)=>{const m=s[g]??0,b=!!(u&&m>=u.start&&m<=u.end);d.push(e.jsx("span",{"data-md-ref-start":m,"data-md-ref-end":m,"data-selected":b?"true":void 0,children:h},`${l}-ref-${g}`)),g<r.length-1&&d.push(n[g]?e.jsx("br",{},`${l}-${g}-br`):" ")}),d}function Ws(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,d=0,h=0;for(let g=0;g<n.length;g+=1){const m=n[g];if(u){l+=m,u=!1;continue}if(m==="\\"){u=!0;continue}if(m==="`"){const b=g;for(;g+1<n.length&&n[g+1]==="`";)g+=1;const f=g-b+1;l+="`".repeat(f),d===0?d=f:d===f&&(d=0);continue}if(d===0&&m==="["?h+=1:d===0&&m==="]"&&h>0&&(h-=1),m==="|"&&d===0&&h===0){s.push(l.trim()),l="";continue}l+=m}return u&&(l+="\\"),s.push(l.trim()),s}function yf(r){return Ws(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 po(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function kf(r,n){return r>96||r>44&&n>.35}function yo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Gs(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 xl(r,n,s,l,u,d=new Set){const h=[],g=[];let m=n;for(;m<r.length;){const b=r[m];if(u&&(fo(b)||d.has(m))){m+=1;continue}const f=Gs(b),j=yo(b);if(!f){if(j>s&&g.length>0){([...g].reverse().find(_=>_.indent<j)?.item??g[g.length-1].item).paragraphs.push(b.trim());for(const _ of g)_.item.lineEnd=m+1;m+=1;continue}break}if(j<s||j===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:m+1,lineEnd:m+1};for(;g.length>0&&g[g.length-1].indent>=j;)g.pop();const M=g[g.length-1]?.item??null;M?M.children.push(y):h.push(y),g.push({indent:j,item:y});for(const I of g)I.item.lineEnd=m+1;m+=1}return{items:h,nextIndex:m}}function kb(r){const n=r.find(l=>Gs(l));if(!n)return[];const s=Gs(n);return s?xl(r,0,yo(n),s.ordered,!0,lf(r)).items:[]}function vl(r,n,s,l=0){return r.map((u,d)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${d}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,ut(h?.[2]??u.content,`li-${n}-${d}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((g,m)=>e.jsx("p",{children:ut(g,`li-${n}-${d}-p-${m}`,!0,s)},`paragraph-${m}`))})]}),groups:Sb(u.children,`${n}-${d}`,s,l)}})}function Sb(r,n,s,l=0){const u=[];for(const d of r){const h=u[u.length-1];h&&h.ordered===d.ordered?h.items.push(d):u.push({ordered:d.ordered,items:[d]})}return u.map((d,h)=>({ordered:d.ordered,start:d.ordered?d.items[0]?.start:void 0,items:vl(d.items,`${n}-g${h}`,s,l)}))}function wl(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&&jb(s.groups,n)]},s.key)})}function jb(r,n){return r.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:wl(s.items,n)},`nested-${l}`)})}function Rb(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 Cb(r,n,s,l){const u=[];let d=0;const h=g=>l?.[g]??g+1;for(;d<r.length;){const g=r[d],m=g.trim();if(!m){d+=1;continue}if(/^<details>\s*$/i.test(m)){const E=d;let $="Details";const A=[];for(d+=1;d<r.length&&!/^<\/details>\s*$/i.test(r[d].trim());){const T=r[d].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?$=T[1].trim()||$:A.push(r[d].trimStart()),d+=1}d<r.length&&(d+=1),u.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:ut($,`${n}-details-${E}-summary`,!0,s)}),A.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:wf(A,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const b=gf(g);if(b){const E=[g],$=d;for(d+=1;d<r.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(r[d]);)E.push(r[d]),d+=1;d<r.length&&!b.selfContained&&(E.push(r[d]),d+=1),u.push({kind:"static",node:e.jsx(pf,{html:E.join(`
1639
+ `)},`${n}-html-${$}`)});continue}const f=m.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],$=f[1],A=f[2]?.trim(),T=d;for(d+=1;d<r.length&&!r[d].trim().startsWith($);)E.push(r[d]),d+=1;d<r.length&&(d+=1),A.toLowerCase()==="mermaid"?u.push({kind:"static",node:e.jsx(jf,{code:E.join(`
1640
1640
  `),blockKey:`${n}-code-${T}`},`${n}-code-${T}`)}):["math","latex","tex"].includes(A.toLowerCase())?u.push({kind:"static",node:e.jsx(zs,{tex:E.join(`
1641
1641
  `),display:!0},`${n}-code-${T}`)}):u.push({kind:"code",key:`${n}-code-${T}`,code:E.join(`
1642
- `),lang:A,blockKey:`${n}-code-${T}`,codeStartLine:h(T)+1});continue}if(ho(g)){const E=[],$=d;for(;d<r.length&&(ho(r[d])||!r[d].trim());)E.push(r[d].trim()?xf(r[d]):""),d+=1;u.push({kind:"code",key:`${n}-indented-code-${$}`,code:E.join(`
1643
- `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${$}`,codeStartLine:h($)});continue}const j=m.match(/^(#{1,6})\s+(.+)$/);if(j){const $=`h${Math.min(6,j[1].length+1)}`,A=nf(j[2]),T=sl(A,s);u.push({kind:"static",node:e.jsx($,{id:T,className:"scroll-mt-16 font-semibold text-foreground",children:ut(A,`${n}-heading-${d}`,!0,s)},`${n}-heading-${d}`)}),d+=1;continue}if(d+1<r.length&&g.includes("|")&&po(r[d+1])){const E=Ws(g),$=yf(r[d+1]),A=[],T=d;for(d+=2;d<r.length&&r[d].includes("|")&&r[d].trim();)A.push(Ws(r[d])),d+=1;u.push({kind:"static",node:e.jsx("div",{className:Vu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{children:E.map((U,D)=>e.jsx("th",{className:`${Gu} ${mo($[D]??null)}`,children:e.jsx("div",{className:uo,children:ut(U,`${n}-th-${T}-${D}`,!0,s)})},`h-${D}`))})}),e.jsx("tbody",{children:A.map((U,D)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((p,i)=>e.jsx("td",{className:`${Ku} ${mo($[i]??null)}`,children:e.jsx("div",{className:uo,children:ut(U[i]??"",`${n}-td-${T}-${D}-${i}`,!0,s)})},`c-${i}`))},`r-${D}`))})]})},`${n}-table-${T}`)});continue}const w=Gs(g);if(w){const E=w.ordered,$=wo(g),A=w.start,T=d,U=bl(r,d,$,E,!1);d=U.nextIndex,u.push({kind:"list",keyPrefix:`${n}-list-${T}`,ordered:E,start:E?A:void 0,renders:xl(U.items,`${n}-list-${T}`,s,h(0)-1)});continue}const M=[g.trimStart()],I=[h(d)],_=d;for(d+=1;d<r.length&&r[d].trim()&&!nl(r[d])&&!(d+1<r.length&&r[d].includes("|")&&po(r[d+1]));)M.push(r[d].trimStart()),I.push(h(d)),d+=1;const B=il(M,`${n}-p-${_}`,s);u.push({kind:"paragraph",keyPrefix:`${n}-p-${_}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:I})}return u}function Cb(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:vl(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(go,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Ja=null,nu=!1;const Qa=16,kf=192;function Nb(){return Ja||(Ja=Us(()=>import("./mermaid.core-CIW1IDpX.js").then(r=>r.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(r=>r.default??r).catch(r=>{throw Ja=null,r})),Ja}function Mb(r){nu||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),nu=!0)}function Eb(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,u,d]=l;if(!Number.isFinite(u)||!Number.isFinite(d)||u<=0||d<=0)return r;const h=Math.max(kf,Math.ceil(u)),g=Math.ceil(h/u*d);return r.replace(/<svg\b([^>]*)>/i,(m,b)=>`<svg${b.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${g}">`)}function $b(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-Qa,u=s.y-Qa,d=s.width+Qa*2,h=s.height+Qa*2,g=Math.max(kf,Math.ceil(d)),m=Math.ceil(g/d*h);n.setAttribute("viewBox",`${l} ${u} ${d} ${h}`),n.setAttribute("width",String(g)),n.setAttribute("height",String(m)),n.removeAttribute("style")}function Ab(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return Su(`code.${s}`)??s}function Sf({code:r,blockKey:n}){const{t:s}=St(),[l,u]=a.useState(null),[d,h]=a.useState(!1),g=a.useRef(null),m=a.useContext(tf);a.useEffect(()=>{let f=!1;return u(null),h(!1),Nb().then(async j=>{Mb(j);const w=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:M}=await j.render(w,r);f||u(Eb(M))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,r]),a.useLayoutEffect(()=>{l&&$b(g.current)},[l]);const b=a.useCallback(()=>{const f=g.current?.querySelector("svg")?.outerHTML??l;f&&m?.(f)},[m,l]);return d?e.jsx(go,{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:f=>{f.stopPropagation(),b()},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 go({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:u}){const d=Ab(n),[h,g]=a.useState(null);a.useEffect(()=>{if(!d||!ju(r)){g(null);return}let b=!1;return Ru().then(f=>{if(b||!f.registered(d)){b||g(null);return}try{g(Cu(f,r,d))}catch{b||g(null)}}).catch(()=>{b||g(null)}),()=>{b=!0}},[s,r,d]);const m=h??(r||" ").split(`
1644
- `).map(b=>[b||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${hl} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:m.map((b,f)=>{const j=l!=null?l+f:null,w=!!(u&&j!=null&&j>=u.start&&j<=u.end);return e.jsxs("span",{"data-md-ref-start":j??void 0,"data-md-ref-end":j??void 0,"data-selected":w?"true":void 0,children:[b,f<m.length-1?`
1645
- `:null]},`${s}-line-${f}`)})})})]})}function yl(r,n,s,l,u){r=ib(r);const d=ab(r),h=of(r),g=[],m={markdownFilePath:n,rootPath:s,referenceDefinitions:d,footnoteDefinitions:ob(r),headingSlugCounts:new Map,images:g,onImageOpen:l,footnotesLabel:u?.footnotes??"Footnotes",backToFootnoteLabel:u?.backToFootnote??(w=>`Back to footnote ${w}`)},b=[];let f=0;for(;f<r.length;){const w=r[f],M=w.trim();if(fo(w)||h.has(f)){f+=1;continue}if(!M){f+=1;continue}if(/^<details>\s*$/i.test(M)){const D=f;let p="Details";const i=[];for(f+=1;f<r.length&&!/^<\/details>\s*$/i.test(r[f].trim());){const O=r[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?p=O[1].trim()||p:i.push(r[f].trimStart()),f+=1}f<r.length&&(f+=1),b.push({key:`details-${D}`,startLine:D+1,endLine:f,content:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:ut(p,`details-${D}-summary`,!0,m)}),i.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:vf(i,`details-${D}`,m)})]})});continue}const I=pf(w);if(I){const D=[w],p=f;for(f+=1;f<r.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(r[f]);)D.push(r[f]),f+=1;f<r.length&&!I.selfContained&&(D.push(r[f]),f+=1),b.push({key:`html-${p}`,startLine:p+1,endLine:f,content:e.jsx(mf,{html:D.join(`
1646
- `)})});continue}const _=M.match(/^(```|~~~)\s*(.*)$/);if(_){const D=[],p=_[1],i=_[2]?.trim(),O=f;for(f+=1;f<r.length&&!r[f].trim().startsWith(p);)D.push(r[f]),f+=1;f<r.length&&(f+=1),b.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:i.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(i.toLowerCase()),content:i.toLowerCase()==="mermaid"?e.jsx(Sf,{code:D.join(`
1642
+ `),lang:A,blockKey:`${n}-code-${T}`,codeStartLine:h(T)+1});continue}if(ho(g)){const E=[],$=d;for(;d<r.length&&(ho(r[d])||!r[d].trim());)E.push(r[d].trim()?vf(r[d]):""),d+=1;u.push({kind:"code",key:`${n}-indented-code-${$}`,code:E.join(`
1643
+ `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${$}`,codeStartLine:h($)});continue}const j=m.match(/^(#{1,6})\s+(.+)$/);if(j){const $=`h${Math.min(6,j[1].length+1)}`,A=sf(j[2]),T=al(A,s);u.push({kind:"static",node:e.jsx($,{id:T,className:"scroll-mt-16 font-semibold text-foreground",children:ut(A,`${n}-heading-${d}`,!0,s)},`${n}-heading-${d}`)}),d+=1;continue}if(d+1<r.length&&g.includes("|")&&po(r[d+1])){const E=Ws(g),$=yf(r[d+1]),A=[],T=d;for(d+=2;d<r.length&&r[d].includes("|")&&r[d].trim();)A.push(Ws(r[d])),d+=1;u.push({kind:"static",node:e.jsx("div",{className:qu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{children:E.map((U,D)=>e.jsx("th",{className:`${Ku} ${mo($[D]??null)}`,children:e.jsx("div",{className:uo,children:ut(U,`${n}-th-${T}-${D}`,!0,s)})},`h-${D}`))})}),e.jsx("tbody",{children:A.map((U,D)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((p,i)=>e.jsx("td",{className:`${Vu} ${mo($[i]??null)}`,children:e.jsx("div",{className:uo,children:ut(U[i]??"",`${n}-td-${T}-${D}-${i}`,!0,s)})},`c-${i}`))},`r-${D}`))})]})},`${n}-table-${T}`)});continue}const y=Gs(g);if(y){const E=y.ordered,$=yo(g),A=y.start,T=d,U=xl(r,d,$,E,!1);d=U.nextIndex,u.push({kind:"list",keyPrefix:`${n}-list-${T}`,ordered:E,start:E?A:void 0,renders:vl(U.items,`${n}-list-${T}`,s,h(0)-1)});continue}const M=[g.trimStart()],I=[h(d)],_=d;for(d+=1;d<r.length&&r[d].trim()&&!sl(r[d])&&!(d+1<r.length&&r[d].includes("|")&&po(r[d+1]));)M.push(r[d].trimStart()),I.push(h(d)),d+=1;const B=ll(M,`${n}-p-${_}`,s);u.push({kind:"paragraph",keyPrefix:`${n}-p-${_}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:I})}return u}function Nb(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:cl(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:wl(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(go,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Ja=null,su=!1;const Za=16,Sf=192;function Mb(){return Ja||(Ja=Us(()=>import("./mermaid.core-BMjyQhe0.js").then(r=>r.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(r=>r.default??r).catch(r=>{throw Ja=null,r})),Ja}function Eb(r){su||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),su=!0)}function $b(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,u,d]=l;if(!Number.isFinite(u)||!Number.isFinite(d)||u<=0||d<=0)return r;const h=Math.max(Sf,Math.ceil(u)),g=Math.ceil(h/u*d);return r.replace(/<svg\b([^>]*)>/i,(m,b)=>`<svg${b.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${g}">`)}function Ab(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-Za,u=s.y-Za,d=s.width+Za*2,h=s.height+Za*2,g=Math.max(Sf,Math.ceil(d)),m=Math.ceil(g/d*h);n.setAttribute("viewBox",`${l} ${u} ${d} ${h}`),n.setAttribute("width",String(g)),n.setAttribute("height",String(m)),n.removeAttribute("style")}function Lb(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return ju(`code.${s}`)??s}function jf({code:r,blockKey:n}){const{t:s}=St(),[l,u]=a.useState(null),[d,h]=a.useState(!1),g=a.useRef(null),m=a.useContext(rf);a.useEffect(()=>{let f=!1;return u(null),h(!1),Mb().then(async j=>{Eb(j);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:M}=await j.render(y,r);f||u($b(M))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,r]),a.useLayoutEffect(()=>{l&&Ab(g.current)},[l]);const b=a.useCallback(()=>{const f=g.current?.querySelector("svg")?.outerHTML??l;f&&m?.(f)},[m,l]);return d?e.jsx(go,{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:f=>{f.stopPropagation(),b()},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 go({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:u}){const d=Lb(n),[h,g]=a.useState(null);a.useEffect(()=>{if(!d||!Ru(r)){g(null);return}let b=!1;return Cu().then(f=>{if(b||!f.registered(d)){b||g(null);return}try{g(Nu(f,r,d))}catch{b||g(null)}}).catch(()=>{b||g(null)}),()=>{b=!0}},[s,r,d]);const m=h??(r||" ").split(`
1644
+ `).map(b=>[b||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${ml} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:m.map((b,f)=>{const j=l!=null?l+f:null,y=!!(u&&j!=null&&j>=u.start&&j<=u.end);return e.jsxs("span",{"data-md-ref-start":j??void 0,"data-md-ref-end":j??void 0,"data-selected":y?"true":void 0,children:[b,f<m.length-1?`
1645
+ `:null]},`${s}-line-${f}`)})})})]})}function yl(r,n,s,l,u){r=lb(r);const d=ob(r),h=lf(r),g=[],m={markdownFilePath:n,rootPath:s,referenceDefinitions:d,footnoteDefinitions:ib(r),headingSlugCounts:new Map,images:g,onImageOpen:l,footnotesLabel:u?.footnotes??"Footnotes",backToFootnoteLabel:u?.backToFootnote??(y=>`Back to footnote ${y}`)},b=[];let f=0;for(;f<r.length;){const y=r[f],M=y.trim();if(fo(y)||h.has(f)){f+=1;continue}if(!M){f+=1;continue}if(/^<details>\s*$/i.test(M)){const D=f;let p="Details";const i=[];for(f+=1;f<r.length&&!/^<\/details>\s*$/i.test(r[f].trim());){const O=r[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?p=O[1].trim()||p:i.push(r[f].trimStart()),f+=1}f<r.length&&(f+=1),b.push({key:`details-${D}`,startLine:D+1,endLine:f,content:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:ut(p,`details-${D}-summary`,!0,m)}),i.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:wf(i,`details-${D}`,m)})]})});continue}const I=gf(y);if(I){const D=[y],p=f;for(f+=1;f<r.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(r[f]);)D.push(r[f]),f+=1;f<r.length&&!I.selfContained&&(D.push(r[f]),f+=1),b.push({key:`html-${p}`,startLine:p+1,endLine:f,content:e.jsx(pf,{html:D.join(`
1646
+ `)})});continue}const _=M.match(/^(```|~~~)\s*(.*)$/);if(_){const D=[],p=_[1],i=_[2]?.trim(),O=f;for(f+=1;f<r.length&&!r[f].trim().startsWith(p);)D.push(r[f]),f+=1;f<r.length&&(f+=1),b.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:i.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(i.toLowerCase()),content:i.toLowerCase()==="mermaid"?e.jsx(jf,{code:D.join(`
1647
1647
  `),blockKey:`code-${O}`}):["math","latex","tex"].includes(i.toLowerCase())?e.jsx(zs,{tex:D.join(`
1648
1648
  `),display:!0}):C=>e.jsx(go,{code:D.join(`
1649
- `),lang:i,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:C})});continue}if(ho(w)){const D=[],p=f;for(f+=0;f<r.length&&(ho(r[f])||!r[f].trim());)D.push(r[f].trim()?xf(r[f]):""),f+=1;b.push({key:`indented-code-${p}`,startLine:p+1,endLine:f,fineGrained:!0,content:i=>e.jsx(go,{code:D.join(`
1649
+ `),lang:i,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:C})});continue}if(ho(y)){const D=[],p=f;for(f+=0;f<r.length&&(ho(r[f])||!r[f].trim());)D.push(r[f].trim()?vf(r[f]):""),f+=1;b.push({key:`indented-code-${p}`,startLine:p+1,endLine:f,fineGrained:!0,content:i=>e.jsx(go,{code:D.join(`
1650
1650
  `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${p}`,codeStartLine:p+1,lineRange:i})});continue}if(M.startsWith("$$")){const D=[],p=f,i=M.replace(/^\$\$\s*/,"");if(i.endsWith("$$")&&i.length>2)D.push(i.replace(/\s*\$\$$/,"")),f+=1;else{for(i&&D.push(i),f+=1;f<r.length&&!r[f].trim().endsWith("$$");)D.push(r[f]),f+=1;if(f<r.length){const O=r[f].trim().replace(/\s*\$\$$/,"");O&&D.push(O),f+=1}}b.push({key:`math-${p}`,startLine:p+1,endLine:f,content:e.jsx(zs,{tex:D.join(`
1651
- `),display:!0})});continue}if(f+1<r.length&&M&&!nl(w)&&/^(=+|-+)\s*$/.test(r[f+1].trim())){const D=r[f+1].trim().startsWith("=")?1:2,p=`h${D}`,i=sl(M,m),O={level:D,text:Zd(M),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(p,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:ut(M,`setext-heading-${f}`,!0,m)})}),f+=2;continue}const B=M.match(/^(#{1,6})\s+(.+)$/);if(B){const D=B[1].length,p=nf(B[2]),i={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${D}`,C=sl(p,m),K={level:D,text:Zd(p),id:C};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:K,content:e.jsx(O,{id:C,className:`scroll-mt-16 font-semibold text-foreground ${i[D]}`,children:ut(p,`heading-${f}`,!0,m)})}),f+=1;continue}if(Zu(w)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(M.startsWith(">")){const D=[],p=[],i=f;for(;f<r.length&&/^>\s?/.test(r[f].trim());)D.push(r[f].trim().replace(/^>\s?/,"")),p.push(f+1),f+=1;const O=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const K=O[1].toUpperCase(),de=O[2]?.trim(),te=[...de?[de]:[],...D.slice(1)],xe=[...de?[p[0]]:[],...p.slice(1)],W=il(te,`callout-${i}`,m);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:X=>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:K}),te.length>0&&e.jsx("div",{children:ll(W.perLine,W.hardBreaks,xe,`callout-${i}`,X)})]})});continue}const C=Rb(D,`quote-${i}`,m,p);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:K=>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:Cb(C,K)})});continue}if(f+1<r.length&&w.includes("|")&&po(r[f+1])){const D=Ws(w),p=yf(r[f+1]),i=[],O=f;for(f+=2;f<r.length&&r[f].includes("|")&&r[f].trim();)i.push(Ws(r[f])),f+=1;const C=D.map((de,te)=>ut(de,`th-${O}-${te}`,!0,m)),K=i.map((de,te)=>D.map((xe,W)=>ut(de[W]??"",`td-${O}-${te}-${W}`,!0,m)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:de=>{const te=xe=>!!(de&&xe>=de.start&&xe<=de.end);return e.jsx("div",{className:Vu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":te(O+1)?"true":void 0,children:C.map((xe,W)=>e.jsx("th",{className:`${Gu} ${mo(p[W]??null)}`,children:e.jsx("div",{className:uo,children:xe})},`h-${W}`))})}),e.jsx("tbody",{children:K.map((xe,W)=>{const X=O+W+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":X,"data-md-ref-start":X,"data-md-ref-end":X,"data-selected":te(X)?"true":void 0,children:D.map((L,F)=>e.jsx("td",{className:`${Ku} ${mo(p[F]??null)}`,children:e.jsx("div",{className:uo,children:xe[F]})},`c-${F}`))},`r-${W}`)})})]})})}});continue}const E=Gs(w);if(E){const D=E.ordered,p=wo(w),i=E.start,O=f,C=bl(r,f,p,D,!0,h);f=C.nextIndex;const K=D?"ol":"ul",de=xl(C.items,`list-${O}`,m);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:te=>e.jsx(K,{start:D?i:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:vl(de,te)})});continue}const $=[w.trimStart()],A=[f+1],T=f;for(f+=1;f<r.length&&r[f].trim()&&!nl(r[f])&&!(f+1<r.length&&r[f].includes("|")&&po(r[f+1]));){if(fo(r[f])||h.has(f)){f+=1;continue}$.push(r[f].trimStart()),A.push(f+1),f+=1}const U=il($,`p-${T}`,m);b.push({key:`p-${T}`,startLine:T+1,endLine:f,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:ll(U.perLine,U.hardBreaks,A,`p-${T}`,D)})})}const j=jb(m);return j&&b.push({key:"footnotes",startLine:r.length,endLine:r.length,content:j}),{blocks:b,images:g}}function Lb(r,n,s){return yl(r,n,s).blocks}function jf(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 Rf(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Pb({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const u=df(r);return e.jsx(_f,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Cf({images:r,index:n,onChange:s,onClose:l}){const{t:u}=St(),d=r[n],h=r.length>1,g=a.useRef(null),m=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[j,w]=a.useState(!1),[M,I]=a.useState(0),[_,B]=a.useState(!1),E=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),$=a.useCallback(()=>{j||Date.now()<f.current||(E(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[E,j,l]),A=a.useCallback(p=>{if(r.length===0)return;const i=(p+r.length)%r.length;g.current?.slideTo(i),s(i)},[r.length,s]),T=a.useCallback(()=>A(n-1),[A,n]),U=a.useCallback(()=>A(n+1),[A,n]);if(a.useEffect(()=>{E(),I(0),B(!1),w(!1)},[E,n]),a.useEffect(()=>{const p=g.current;p&&(p.allowTouchMove=h&&!j)},[h,j]),a.useEffect(()=>{const p=g.current;!p||p.activeIndex===n||p.slideTo(n,0)},[n]),a.useEffect(()=>E,[E]),a.useEffect(()=>{const p=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),T()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[h,U,T,l]),bu({onDrag:({movement:[p,i],pinching:O})=>{O||j||Math.abs(i)<Math.abs(p)*1.15&&M===0||(B(!0),Math.abs(i)>8&&(f.current=Date.now()+300),I(Math.max(0,i)))},onDragEnd:({movement:[p,i],velocity:[,O],pinching:C,canceled:K})=>{if(B(!1),C||K||j||Math.abs(i)<Math.abs(p)*1.15){I(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),wf(i,O)){l();return}I(0)}},{target:m,drag:{filterTaps:!0,pointer:{touch:!0}}}),!d)return null;const D=d.title||d.alt||(d.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:T,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx(Bs,{size:17})}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(lm,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Yt,{size:18})})]})]}),e.jsx("div",{ref:m,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:$,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${M}px, 0) scale(${Math.max(.86,1-M/900)})`,opacity:Math.max(.35,1-M/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(xu,{onSwiper:p=>{g.current=p,p.allowTouchMove=h&&!j},onSlideChange:p=>{p.activeIndex!==n&&s(p.activeIndex)},onSliderMove:()=>{E(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((p,i)=>e.jsx(zi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:p.kind==="image"?e.jsx(Pb,{src:p.src,alt:p.alt||p.title||u("rightSidebar.markdownImage"),onZoomChange:w,onDoubleTap:E}):e.jsx(Yb,{svg:p.svg,title:p.title||p.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:w,onDoubleTap:E})})},`${p.kind}-${i}-${p.alt}`))})})})]})]}),document.body)}function Nf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:d,scrollTop:h,outlineOpen:g,outlineCloseSignal:m,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:j,lightboxCloseSignal:w,onLightboxOpen:M,onLightboxClose:I,onLocalLinkOpen:_}){const{t:B}=St(),[E,$]=a.useState(null),[A,T]=a.useState(null),[U,D]=a.useState(1),[p,i]=a.useState(null),O=a.useRef(null),C=a.useRef(null),{blocks:K,images:de}=a.useMemo(()=>yl(r.split(`
1652
- `),n,s,R=>{T(null),$(R),M?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:R=>B("rightSidebar.backToFootnote",{index:R})}),[r,n,s,M,B]),te=a.useMemo(()=>A?[...de,A]:de,[de,A]),xe=a.useCallback(R=>{T({kind:"mermaid",svg:R,alt:"Mermaid diagram",title:"Mermaid diagram"}),$(de.length),M?.()},[de.length,M]);a.useEffect(()=>{$(null),T(null)},[r,n]),a.useEffect(()=>{$(null),T(null)},[w]),a.useEffect(()=>{j||($(null),T(null))},[j]),a.useEffect(()=>{D(1)},[r,n]),a.useLayoutEffect(()=>{const R=O.current;if(!R||K.length===0)return;const ee=Array.from(R.querySelectorAll("[data-markdown-preview-block-start]"));let le=1;const Ee=28;for(const Ne of ee)if(Ne.offsetTop-h<=Ee)le=Number(Ne.dataset.markdownPreviewBlockStart)||le;else break;D(Ne=>Ne===le?Ne:le)},[K,h]);const W=a.useMemo(()=>jf(K,U),[U,K]),X=a.useMemo(()=>Rf(K),[K]),L=`${n??""}
1653
- ${r}`,F=a.useRef(L),V=a.useRef(null),re=a.useRef(null),ie=a.useRef(!1);a.useEffect(()=>{F.current!==L&&(F.current=L,f?.())},[f,L]),a.useEffect(()=>{m!==void 0&&i(null)},[m]),a.useLayoutEffect(()=>{if(!g){i(null);return}const R=()=>{const ee=C.current;if(!ee)return;const le=ee.getBoundingClientRect(),Ee=window.innerWidth;i({top:le.bottom+6,right:Math.max(8,Ee-le.right)})};return R(),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[g,h,W]);const ye=a.useCallback(R=>{const ee=O.current,le=ee?.closest("[data-markdown-preview-scroller]"),Ee=ee?.querySelector(`[data-markdown-preview-block-start="${R.startLine}"]`);if(!le||!Ee)return;const Ne=le.getBoundingClientRect(),We=Ee.getBoundingClientRect(),Pe=ee?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,tt=We.top-Ne.top+le.scrollTop;le.scrollTo({top:Math.max(0,tt-Pe-8),behavior:"smooth"}),D(R.startLine),f?.()},[f]),pe=a.useCallback(R=>{R.pointerType==="mouse"&&R.button!==0||Bi(R.target)||(V.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY})},[]),De=a.useCallback((R,ee,le)=>{const Ee=V.current;if(V.current=null,!Ee||Ee.pointerId!==R.pointerId)return;const Ne=Math.abs(R.clientX-Ee.startX),We=Math.abs(R.clientY-Ee.startY);if(Ne>8||We>8)return;const ce=R.target;if(Bi(ce)||Gi())return;const Pe=du(ce,ee,le);u(R,Pe.start,Pe.end)},[u]),N=a.useCallback(R=>{V.current?.pointerId===R.pointerId&&(V.current=null)},[]),q=a.useCallback((R,ee)=>{const le=O.current;if(!le||typeof document.elementFromPoint!="function")return null;const Ee=document.elementFromPoint(R,ee);if(!(Ee instanceof HTMLElement)||!le.contains(Ee))return null;const Ne=Ee.closest("[data-md-ref-start]");if(Ne){const ke=Number(Ne.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const We=Ee.closest("[data-markdown-preview-block-start]");if(!We)return null;const ce=Number(We.dataset.markdownPreviewBlockStart),Pe=K.find(ke=>ke.startLine===ce);if(!Pe)return Number.isFinite(ce)&&ce>0?ce:null;if(Pe.endLine<=Pe.startLine)return Pe.startLine;const tt=We.getBoundingClientRect(),Te=tt.height>0?Math.min(1,Math.max(0,(ee-tt.top)/tt.height)):0;return Math.round(Pe.startLine+Te*(Pe.endLine-Pe.startLine))},[K]),he=a.useCallback(R=>{if(!d||R.pointerType==="mouse"&&R.button!==0)return;const ee=q(R.clientX+24,R.clientY);if(ee!=null){re.current={pointerId:R.pointerId,anchorLine:ee,moved:!1};try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}}},[d,q]),Ae=a.useCallback(R=>{const ee=re.current;if(!ee||ee.pointerId!==R.pointerId||!d)return;const le=q(R.clientX+16,R.clientY);le!=null&&(!ee.moved&&le===ee.anchorLine||(ee.moved=!0,ie.current=!0,d(R,Math.min(ee.anchorLine,le),Math.max(ee.anchorLine,le),"move")))},[d,q]),Ze=a.useCallback(R=>{const ee=re.current;if(re.current=null,!ee||ee.pointerId!==R.pointerId||!d||!ee.moved)return;const le=q(R.clientX+16,R.clientY)??ee.anchorLine;d(R,Math.min(ee.anchorLine,le),Math.max(ee.anchorLine,le),"end")},[d,q]),Le=a.useCallback(R=>{re.current?.pointerId===R.pointerId&&(re.current=null)},[]),at={onPointerDown:he,onPointerMove:Ae,onPointerUp:Ze,onPointerCancel:Le},Be=()=>ie.current?(ie.current=!1,!0):!1;return K.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:B("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:R=>{const ee=R.target instanceof Element?R.target.closest("a[href]"):null;if(!ee||!_)return;const le=ee.getAttribute("href");if(!le)return;const Ee=ml(le,n,s);Ee&&(R.preventDefault(),_(Ee))},children:[W.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:W.map(R=>R.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:W[W.length-1].text}),X.length>1&&e.jsxs("button",{ref:C,type:"button",onClick:()=>{g?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${g?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":g,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(vu,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),g&&typeof document<"u"&&qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:f}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:p?{top:`${p.top}px`,right:`${p.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:X.map(R=>{const ee=W[W.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>ye(R),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${ee?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ee?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`desktop-${R.id}-${R.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:B("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":B("rightSidebar.closeMarkdownOutline"),title:B("common.close"),children:e.jsx(Yt,{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:X.map(R=>{const ee=W[W.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>ye(R),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${ee?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ee?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`${R.id}-${R.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(tf.Provider,{value:xe,children:K.map(R=>{const ee=!!(l&&R.startLine<=l.end&&R.endLine>=l.start),le=!!(l&&l.start<=R.startLine&&l.end>=R.endLine),Ee=R.kind==="table"?!1:R.fineGrained?le:ee,Ne=R.kind==="table"&&l?.start===R.startLine&&l.end===R.endLine;let We=null;if(R.kind!=="table"&&R.fineGrained&&ee&&!le&&l){const Te=R.endLine-R.startLine+1,ke=Math.max(l.start,R.startLine),rt=Math.min(l.end,R.endLine),nt=(ke-R.startLine)/Te,oe=(rt-ke+1)/Te;We=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) * ${nt})`,height:`calc((100% - 0.5rem) * ${oe})`}})}const ce=typeof R.content=="function"?R.content(l):R.content,Pe=R.startLine===R.endLine?String(R.startLine):`${R.startLine}-${R.endLine}`,tt=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:Di(Ee),"aria-hidden":"true",...at,children:[e.jsx("span",{className:Fi(Ee)}),We]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:ce})]});return R.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":R.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${Ee?"bg-primary/10":""}`,title:`Line ${Pe}`,"aria-label":`Line ${Pe}`,children:[R.kind==="table"?e.jsx("button",{type:"button",className:Di(Ne,"self"),onClick:Te=>{Te.preventDefault(),!Be()&&u(Te,R.startLine,R.endLine)},title:`Reference table lines ${Pe}`,"aria-label":`Reference table lines ${Pe}`,...at,children:e.jsx("span",{className:Fi(Ne,"self")})}):e.jsxs("span",{className:Di(Ee,"none"),"aria-hidden":"true",...at,children:[e.jsx("span",{className:Fi(Ee,"none")}),We]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:Te=>De(Te,R.startLine,R.endLine),onPointerCancel:N,onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),u(Te,R.startLine,R.endLine))},title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:ce})]},R.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":R.startLine,onClick:Te=>{const ke=Te.target;if(Bi(ke)||Gi()||Be())return;const rt=du(ke,R.startLine,R.endLine);u(Te,rt.start,rt.end)},onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),u(Te,R.startLine,R.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${Ee?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:tt},R.key)})})})]}),j&&E!==null&&te[E]&&e.jsx(Cf,{images:te,index:E,onChange:$,onClose:()=>{$(null),T(null),I?.()}})]})}function Jn({label:r,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:d,disabled:h,onChange:g}){const{t:m}=St(),[b,f]=a.useState(!1),[j,w]=a.useState(""),[M,I]=a.useState(null),_=a.useRef(null),B=a.useRef(null),E=j.trim().toLowerCase(),$=a.useMemo(()=>E?s.filter(p=>`${p.label} ${p.meta??""}`.toLowerCase().includes(E)):s,[E,s]),A=s.find(p=>p.value===n),T=()=>{const p=j.trim();p&&(g(p),f(!1),w(""))},U=a.useCallback(()=>{const p=_.current?.getBoundingClientRect();if(!p)return!1;const i=12,O=Math.max(220,Math.min(p.width,window.innerWidth-i*2)),C=Math.min(Math.max(i,p.left),window.innerWidth-O-i),K=window.innerHeight-p.bottom-i,de=p.top-i,te=K>=180||K>=de,xe=Math.max(96,(te?K:de)-4),W=Math.min(320,xe);return I({left:C,top:te?p.bottom+4:Math.max(i,p.top-W-4),width:O,maxHeight:W}),!0},[]),D=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let p=0;const i=()=>{p||(p=window.requestAnimationFrame(()=>{p=0,U()}))},O=C=>{const K=C.target;K instanceof Node&&(_.current?.contains(K)||B.current?.contains(K)||(f(!1),w("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{p&&window.cancelAnimationFrame(p),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(w(""),b){f(!1);return}D()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:A?.label??(n||l)})]}),e.jsx(Os,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&qr.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:p=>p.stopPropagation(),style:{left:M?.left??12,top:M?.top??12,width:M?.width??260,maxHeight:M?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(Qn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:j,onChange:p=>w(p.target.value),onKeyDown:p=>{if(p.key==="Escape"){p.preventDefault(),f(!1),w("");return}p.key==="Enter"&&(p.preventDefault(),T())},onBlur:()=>{j.trim()&&$.length===0&&T()},placeholder:u,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(M?.maxHeight??320)-46)},children:[j.trim()&&!s.some(p=>p.value===j.trim())&&e.jsxs("button",{type:"button",onMouseDown:p=>p.preventDefault(),onClick:T,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:j.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:m("common.use")})]}),$.length>0?$.map(p=>e.jsxs("button",{type:"button",onClick:()=>{g(p.value),f(!1),w("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${p.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:p.label}),p.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:p.meta})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:d})]})]}),document.body)]})}function su({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:d,onToggleRepo:h,onGenerate:g,onSecondaryAction:m,disabled:b,generateDisabled:f,secondaryDisabled:j,inserted:w,buttonLabel:M,insertedLabel:I,title:_,ariaLabel:B,scopeTitle:E,scopeLabel:$,allLabel:A,generateLabel:T,secondaryLabel:U,secondaryTitle:D,secondaryLoading:p,loading:i,error:O,statusTitle:C,extraContent:K,renderRepoExtra:de}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!r):f||g()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":w?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:C??(s?`${E}: ${$}`:_),children:[i?e.jsx(Nt,{size:13,className:"animate-spin"}):e.jsx(Hs,{size:13}),e.jsx("span",{children:w?I:M}),s&&e.jsx(Os,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&qr.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:te=>te.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:E}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:$})]}),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(Yt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[K,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:A}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(te=>{const xe=d.includes(te.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${xe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(te.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${xe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:te.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:te.label}),te.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:te.branch})]}),xe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),de&&(l||xe)&&e.jsx("div",{className:"px-2 pb-2",children:de(te)})]},te.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${m&&U?"sm:grid-cols-2":""}`,children:[m&&U&&e.jsxs("button",{type:"button",onClick:()=>{j||(n(!1),m())},disabled:j,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[p?e.jsx(Nt,{size:12,className:"animate-spin"}):e.jsx(Mu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),g())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Hs,{size:12}),T]})]})]})}),document.body)]})}function Tb(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 Mf(){return mt(ul,Tb)??{}}function Ib(r,n){const s=Mf(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,d])=>d.updatedAt-u.updatedAt).slice(0,$g);Is(ul,Object.fromEntries(l),Lg)}function Db(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 Fb(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&&!Db(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 Ef(){return mt(fl,Fb)??{}}function au(r,n){const s=wl(r,n);return s?Ef()[s]??null:null}function Pi(r,n,s){const l=wl(r,n);if(!l)return;const u=Ef(),d=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...d,...s,updatedAt:Date.now()}}).sort(([,g],[,m])=>m.updatedAt-g.updatedAt).slice(0,Ag);Is(fl,Object.fromEntries(h),Pg)}function Za({active:r,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${r?"block":"hidden"}`,"aria-hidden":!r,children:n?typeof l=="function"?l():l:s})}function Ti({slow:r}){return e.jsx(Km,{slow:r})}function eo({message:r,onRetry:n}){const{t:s}=St();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 io(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function kt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function Ii(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 _b(r,n,s){return Ki(r,n,s)}function Di(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 Fi(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 $f(r){const n=new Map;for(const s of r)n.set(kl(s),s);return n}function Af(r,n){const s=new Map(r);for(const l of n)s.set(kl(l),l);return s}function ou(r,n){let s=0;for(const l of r){const u=gt(l,n);u&&n&&u!==n&&(s+=1)}return s}function Bb(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Ob(r,n){return Array.from(Af($f(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Ub(r,n){const s=r.relativeRoot==="."?kt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||kt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Bb(r.files)}}function Lf(r,n){const s=kt(n??"")||n||"";return r.map(l=>Ub(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function Pf(r,n,s,l,u){const d=Yu(s),h=d.find(_=>_.root===l)??d[0]??null,g=n.find(_=>_.root===l)??null,m=g?.relativeRoot??h?.relativeRoot??".",b=g?.name??h?.name??(kt(l)||l),f=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:m,repoName:b})),j=h?.context??s.context,w={...g??h??{id:l,root:l,relativeRoot:m,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:g?.id??h?.id??l,root:l,displayRoot:g?.displayRoot??h?.displayRoot,relativeRoot:m,name:b,depth:g?.depth??h?.depth??0,nested:g?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,deferred:h?.deferred??!1,files:f,context:j?{...j,root:l,changedFiles:f.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},M=g?n.map(_=>_.root===l?w:_):[...n,w];return{files:Array.from(r).filter(_=>gt(_,u)!==l).concat(f),repositories:M,repoFilters:Lf(M,u)}}function gt(r,n){return r.repoRoot??n}function kl(r){return`${r.repoRoot??""}\0${r.path}`}function wt(r){return r.absolutePath||r.path}function _i(r){return kl(r)}function Hb(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function iu(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function lu(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 As(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 Ls(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 hr(r){return r instanceof DOMException&&r.name==="AbortError"}function zb(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function cu(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function Bi(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function du(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),d=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(d)&&d>0?{start:Math.min(u,d),end:Math.max(u,d)}:{start:n,end:s}}function Wb({actions:r,running:n,completed:s}){const{t:l}=St(),[u,d]=a.useState(!1),h=a.useRef(null),g=r.find(b=>n?.action===b.key),m=r.find(b=>s?.action===b.key);return r.length===0?null:(a.useEffect(()=>{if(!u)return;const b=j=>{const w=j.target;w instanceof Node&&h.current?.contains(w)||d(!1)},f=j=>{j.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),d(f=>!f)},disabled:r.every(b=>b.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${u?"bg-surface-elevated text-foreground":m?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:g?.label??m?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(Nt,{size:13,className:"animate-spin"}):m?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(lo,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(b=>{const f=n?.action===b.key,j=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:w=>{w.stopPropagation(),b.onClick(),d(!1)},disabled:b.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${j?"bg-accent/10 text-accent":b.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(Nt,{size:13,className:"animate-spin"}):j?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Gb(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function Tf(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Gb(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function Zn(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const Oi=new WeakMap;function bo(r){const n=Oi.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"),Oi.delete(r)},1700);Oi.set(r,s)}function Kb(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 u=null;for(const g of l){if(!Zn(g))continue;const m=g.querySelector(s);if(m&&Zn(m)){u=m;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Zn)??null,!u)return;const d=Tf(u);if(!d){u.scrollIntoView({block:"start",behavior:"smooth"}),bo(u);return}const h=u.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop;d.scrollTo({top:Math.max(0,h),behavior:"instant"}),bo(u)}function kn(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,u=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,d=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&d?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${d}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(I=>!!I),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let m=null;for(const I of g)if(Zn(I)){for(const _ of h){const B=I.querySelector(_);if(B&&Zn(B)){m=B;break}}if(m)break}if(m??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Zn)??null,!m){Kb(r.filePath);return}const b=Tf(m);if(!b){m.scrollIntoView({block:"center",behavior:"smooth"}),bo(m);return}const f=m.getBoundingClientRect(),j=b.getBoundingClientRect(),M=f.top-j.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,M),behavior:"instant"}),bo(m)}const If=1,Df=8;function Vb(r){return Math.min(Df,Math.max(If,r))}function Ff({resetKey:r,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[d,h]=a.useState({scale:1,x:0,y:0}),[g,m]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),j=a.useRef(!1),w=a.useRef(null),M=a.useRef(0),I=a.useRef(d);I.current=d,a.useEffect(()=>{h({scale:1,x:0,y:0})},[r]);const _=a.useCallback((A,T,U)=>{const D=u.current;if(!D)return{x:T,y:U};const p=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,i=p?.clientWidth||D.clientWidth,O=p?.clientHeight||D.clientHeight,C=Math.max(0,(i*A-D.clientWidth)/2),K=Math.max(0,(O*A-D.clientHeight)/2);return{x:Math.min(C,Math.max(-C,T)),y:Math.min(K,Math.max(-K,U))}},[]),B=a.useCallback((A,T,U)=>{h(D=>{const p=Vb(A),i=u.current;if(!i||p===1)return{scale:p,x:0,y:0};const O=i.getBoundingClientRect(),C=(T??O.left+O.width/2)-O.left-O.width/2,K=(U??O.top+O.height/2)-O.top-O.height/2,de=p/D.scale,te=C-(C-D.x)*de,xe=K-(K-D.y)*de;return{scale:p,..._(p,te,xe)}})},[_]),E=a.useCallback((A,T)=>{m(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,A,T),window.setTimeout(()=>m(!1),220)},[B]);a.useEffect(()=>{const A=u.current;if(!A)return;const T=p=>{if(p.pointerType==="mouse"&&p.button!==0)return;const i=f.current.size===0;if(f.current.add(p.pointerId),i){const O=Date.now(),C=w.current;if(C&&O-C.time<350&&Math.hypot(p.clientX-C.x,p.clientY-C.y)<24){w.current=null,M.current=O,s?.(),E(p.clientX,p.clientY);return}}if(f.current.size>1){j.current=!0,b.current=null;return}if(!(I.current.scale<=1)){p.preventDefault(),b.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{A.setPointerCapture?.(p.pointerId)}catch{}m(!1)}},U=p=>{const i=b.current;if(!i||i.pointerId!==p.pointerId)return;const O=p.clientX-i.startX,C=p.clientY-i.startY;if(!i.moved){if(Math.hypot(O,C)<6)return;i.moved=!0}p.stopPropagation(),p.preventDefault(),h(K=>({...K,..._(K.scale,i.originX+O,i.originY+C)}))},D=p=>{const i=b.current,O=i?.pointerId===p.pointerId&&i.moved;if(i?.pointerId===p.pointerId){i.moved&&p.stopPropagation(),b.current=null;try{A.releasePointerCapture?.(p.pointerId)}catch{}}f.current.delete(p.pointerId)&&f.current.size===0&&(!j.current&&!O&&(w.current={time:Date.now(),x:p.clientX,y:p.clientY}),j.current=!1)};return A.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{A.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[_,s,E]),bu({onPinch:({offset:[A],origin:[T,U]})=>{m(!1),B(A,T,U)},onWheel:({event:A,delta:[T,U],ctrlKey:D})=>{if(D){A.preventDefault(),A.stopPropagation(),m(!1),B(I.current.scale*(1-U*.01),A.clientX,A.clientY);return}I.current.scale<=1||(A.preventDefault(),A.stopPropagation(),m(!1),h(p=>({...p,..._(p.scale,p.x-T,p.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:If,max:Df},from:()=>[I.current.scale,0],rubberband:!0}});const $=d.scale>1;return a.useEffect(()=>{n?.($)},[n,$]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":$?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:$?"grab":"zoom-in"},onDoubleClick:A=>{A.stopPropagation(),!(Date.now()-M.current<500)&&(s?.(),E(A.clientX,A.clientY))},children:l({scale:d.scale,zoomed:$,animateTransform:g,transformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0) scale(${d.scale})`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0)`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function _f({src:r,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:d,onDoubleTap:h}){const g=xo(r,u),[m,b]=a.useState(null),f=s??yo(r);return a.useEffect(()=>{b(null)},[r]),e.jsx(Ff,{resetKey:r,onZoomChange:d,onDoubleTap:h,children:({transformStyle:j,vectorTransformStyle:w,scale:M,animateTransform:I})=>{const _=e.jsx("img",{src:g,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&m?{position:"absolute",left:"50%",top:"50%",width:m.width*M,height:m.height*M,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:m?{...j,width:m.width,height:m.height}:f?w:j,onLoad:B=>{const E=B.currentTarget,$=E.parentElement;if($&&E.naturalWidth>0&&E.naturalHeight>0){const A=Math.max(1,$.clientWidth-2),T=Math.max(1,$.clientHeight-2),U=Math.min(A/E.naturalWidth,T/E.naturalHeight),D=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(E.naturalWidth*D)),height:Math.max(1,Math.round(E.naturalHeight*D))})}l(B)},onError:u});return!f||!m?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...w,width:m.width,height:m.height},children:_})}})}function qb({svg:r,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const d=u.current,h=d?.querySelector("svg");if(!d||!h)return;const g=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let j=f[2],w=f[3];if((!Number.isFinite(j)||!Number.isFinite(w)||j<=0||w<=0)&&(j=Number(h.getAttribute("width")),w=Number(h.getAttribute("height"))),!Number.isFinite(j)||!Number.isFinite(w)||j<=0||w<=0)return;const M=Math.max(1,d.clientWidth-24),I=Math.max(1,d.clientHeight-24),_=Math.min(M/j,I/w,1);h.style.width=`${Math.max(1,Math.floor(j*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(w*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};g();const m=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return m?.observe(d),()=>m?.disconnect()},[s,r,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function Yb({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(Ff,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:d})=>e.jsx(qb,{svg:r,title:n,scale:d,vectorTransformStyle:u})})}let Xb=0,Jb=0,Qb=0,Zb=0,ex=0;function Ui(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 dt(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:++Jb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function to(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++Zb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function tx(){return`diff-ui-${Date.now().toString(36)}-${(++ex).toString(36)}`}function rx(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function nx(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function cl({onReviewReference:r,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:d,onClose:h,onDirectoryLinkOpen:g,isMobile:m,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:j,onCloseMarkdownOutline:w,markdownImageLightboxOpen:M,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:$,insertedReferenceKey:A,copiedReferenceKey:T,scrollToLine:U,onScrollToLineHandled:D}){const{t:p}=St(),i=J(P=>P.rootPath),O=J(P=>P.selectFile),[C,K]=a.useState({kind:"idle"}),[de,te]=a.useState("schematic"),[xe,W]=a.useState(null),X=a.useRef(null),[L,F]=a.useState(null),V=a.useRef(new Map),re=a.useRef(null),[ie,ye]=a.useState(null),[pe,De]=a.useState(()=>Vd()),[N,q]=a.useState(()=>Td(i,n)),he=a.useRef(null),[Ae,Ze]=a.useState(!1),[Le,at]=a.useState(null),[Be,R]=a.useState(0),[ee,le]=a.useState([]),[Ee,Ne]=a.useState(null),We=a.useRef(null),ce=a.useRef(n),[Pe,tt]=a.useState(null),[Te,ke]=a.useState({status:"idle"}),[rt,nt]=a.useState(!1),[oe,Ie]=a.useState(""),[ze,_t]=a.useState([]),[Bt,H]=a.useState(0),ae=a.useRef(null),ve=Nu(d),Ke=wl(i,n);a.useEffect(()=>{if(ce.current===n)return;ce.current=n;const P=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(We.current===P){We.current=null;return}We.current=null,le([]),Ne(null),nt(!1),Ie("")},[n,i]);const pt=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,mr=J(P=>pt?(P.fileChangeVersions.get(pt)??0)+P.fileWatchEpoch:P.fileWatchEpoch),pr=a.useRef(null),Ot=a.useRef(null),[gr,br]=a.useState(0),Sn=a.useCallback(()=>br(P=>P+1),[]);a.useEffect(()=>{const P=X.current;return X.current=null,W(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const z=X.current;X.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[pt,mr,gr]),a.useEffect(()=>{if(!n){pr.current=null,K({kind:"idle"});return}const P=i&&!n.startsWith("/")?`${i}/${n}`:n,z=new AbortController,ue=++Xb,Se=`right-sidebar-file-preview:${ue}`,et=performance.now();let Fe=!1;const Ve=(Q,Ye={})=>{Fe||(Fe=!0,Ui("end",{loadingId:ue,reason:Q,durationMs:Math.round(performance.now()-et),filePath:n,fullPath:P,rootPath:i,...Ye}))};let _e=null;const qe=Xh(P),ft=qe?P.toLowerCase().endsWith(".kicad_pcb")?de==="schematic"?"pcb-front":de:"schematic":de,Nn=!qe&&dl(P),sr=!qe&&!Nn&&Jh(P),os=!qe&&!Nn&&!sr&&fu(P),Zr=$s(P),en=Ns(P),Ur=qe?"eda":Nn?"image":sr?"model3d":os?"video":"text",tn=pr.current!==P;if(pr.current=P,tn){Ui("start",{loadingId:ue,filePath:n,fullPath:P,rootPath:i,mode:Ur,externalVersion:mr}),ke({status:"idle"}),K({kind:"loading",mode:Ur}),Ot.current=null;const Q=au(i,n);$(Q?.lineRange??null),De(Zr?Vd():"source"),q(en?Td(i,n):"source"),qe&&te(Qh(P))}tn||K(Q=>Q.kind==="error"?{kind:"loading",mode:Ur}:Q);const rn=window.setTimeout(()=>{Fe||z.signal.aborted||Ui("still_active",{loadingId:ue,filePath:n,fullPath:P,rootPath:i,mode:Ur,durationMs:Math.round(performance.now()-et),isPathChange:tn})},3e3),is=window.setTimeout(()=>{if(Fe||z.signal.aborted)return;const Q=qe?p("rightSidebar.edaTimeout"):sr?p("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(Q,"TimeoutError")),K({kind:"error",message:Q}),Ve("stuck_timeout",{error:Q})},qe?Zh+5e3:sr?em+5e3:tm(P)?35e3:Og);if(qe){const Q=ft==="pcb-3d"?X.current:null;Q?(K(Q),Ve("eda_3d_client_cache_hit",{bytes:Q.meta.size,view:Q.view,mimeType:Q.meta.mimeType})):rm(P,ft,z.signal,"view_file",Se).then(Ye=>{if(z.signal.aborted)return;_e=URL.createObjectURL(Ye.blob);const Tt={kind:"eda",sourcePath:Ye.path||P,objectUrl:_e,view:Ye.view,meta:{size:Ye.size,mimeType:Ye.mimeType,modified:Ye.modified}};if(Ye.view==="pcb-3d"){const ar=X.current;ar&&ar.objectUrl!==_e&&URL.revokeObjectURL(ar.objectUrl),X.current=Tt,W(Tt),_e=null}K(Tt),Ve("eda_loaded",{bytes:Ye.size,view:Ye.view,mimeType:Ye.mimeType})}).catch(Ye=>{z.signal.aborted||(K({kind:"error",message:Ye instanceof Error&&/timed out/i.test(Ye.message)?p("rightSidebar.edaTimeout"):Ye instanceof Error?Ye.message:p("rightSidebar.edaLoadFailed")}),Ve("error",{error:Ye instanceof Error?Ye.message:String(Ye)}))})}else if(Nn)nm(P,z.signal,"view_file",Se).then(Q=>{_e=URL.createObjectURL(Q.blob),K({kind:"image",objectUrl:_e,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ve("image_loaded",{bytes:Q.size,mimeType:Q.mimeType})}).catch(Q=>{z.signal.aborted||(K({kind:"error",message:Q instanceof Error?Q.message:p("rightSidebar.imageLoadFailed")}),Ve("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(sr)sm(P,z.signal,"view_file",Se).then(Q=>{z.signal.aborted||(_e=URL.createObjectURL(Q.blob),K({kind:"model3d",sourcePath:Q.path||P,objectUrl:_e,ext:Q.ext,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),Ve("model3d_loaded",{bytes:Q.size,ext:Q.ext}))}).catch(Q=>{z.signal.aborted||(K({kind:"error",message:Q instanceof Error&&(Q.name==="TimeoutError"||/timed out/i.test(Q.message))?p("rightSidebar.model3dTimeout"):Q instanceof Error?Q.message:p("rightSidebar.model3dLoadFailed")}),Ve("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(os){const Q=am(P)??"",Ye=hu(P);K(Tt=>Tt.kind==="video"&&Tt.url===Ye?Tt:{kind:"video",url:Ye,meta:{size:null,mimeType:Q,modified:null}}),Ve("video_ready",{mimeType:Q})}else dd(P,z.signal,"view_file",Se).then(Q=>{if(!z.signal.aborted){if(Q.binary){K({kind:"binary"});return}K({kind:"text",content:Q.content,sourcePath:Q.path||P,meta:{size:Q.size,truncated:Q.truncated}}),Ve("text_loaded",{bytes:Q.size,truncated:!!Q.truncated})}}).catch(Q=>{z.signal.aborted||(K({kind:"error",message:Q instanceof Error?Q.message:"Failed to read file"}),Ve("error",{error:Q instanceof Error?Q.message:String(Q)}))});return()=>{z.abort(),Ct(Se),window.clearTimeout(rn),window.clearTimeout(is),_e&&URL.revokeObjectURL(_e),Ve("cleanup")}},[n,i,mr,gr,$,p,de]),a.useEffect(()=>{if(C.kind!=="model3d"||!n){F(null);return}let P=!1;const z=n.lastIndexOf("/"),ue=z>=0?n.slice(z+1):n,Se=z>=0?n.slice(0,z):"",et=Se.lastIndexOf("/"),Fe=et>=0?Se.slice(0,et):"",Ve=ue.replace(/\.(stl|glb|gltf)$/i,""),_e=`${Fe?`${Fe}/`:""}features/${Ve}.json`;return dd(_e).then(qe=>{if(!P)try{const ft=JSON.parse(qe.content);F(ft.version===1&&Array.isArray(ft.features)&&ft.features.length>0?ft.features:null)}catch{F(null)}}).catch(()=>{P||F(null)}),()=>{P=!0}},[C,n]),a.useEffect(()=>{if(C.kind!=="text"){tt(null);return}const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=Su(P),ue=C.content,Se=$s(P??"")&&pe==="preview",et=Ns(P??"")&&N==="preview";if(!z||Se||et||!ju(ue)){tt(null);return}let Fe=!1;const Ve=_e=>{if(Fe||!_e.registered(z)){Fe||tt(null);return}try{tt(Cu(_e,ue,z))}catch{tt(null)}};return Le?Ve(Le):(tt(null),Ru().then(_e=>{Fe||(at(_e),Ve(_e))}).catch(()=>{})),()=>{Fe=!0}},[C,Le,n,i,pe,N]),a.useLayoutEffect(()=>{if(!Ke||C.kind!=="text")return;const P=`${Ke}:${pe}:${N}`;if(Ot.current===P)return;const z=au(i,n);if(Ot.current=P,!z)return;const ue=requestAnimationFrame(()=>{const Se=re.current;if(!Se)return;const et=pe==="preview"?z.markdownTop??z.top:z.top;Se.scrollTo({top:Math.max(0,et??0),left:Math.max(0,z.left??0)}),R(pe==="preview"?Math.max(0,et??0):0)});return()=>cancelAnimationFrame(ue)},[n,pe,N,C.kind,Ke,i]),a.useEffect(()=>{Ke&&Pi(i,n,{lineRange:E})},[n,E,Ke,i]),a.useEffect(()=>{if(U==null||C.kind!=="text")return;ye(null),$({start:U,end:U});const P=U,z=requestAnimationFrame(()=>{const ue=V.current.get(P);ue&&ue.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(z)},[U,C,$,D]);const jn=a.useCallback(P=>{const z=re.current;if(!z)return!1;const ue=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Se=z.querySelector(`#${ue}`);return Se?(Se.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=C.kind==="text"&&$s(P??"")&&pe==="preview";if(!Ee||!z)return;const ue=requestAnimationFrame(()=>{jn(Ee)&&Ne(null)});return()=>cancelAnimationFrame(ue)},[n,jn,pe,Ee,C,i]),a.useLayoutEffect(()=>{const P=re.current;if(!P||!E){ye(null);return}if(ie)return;const z=C.kind==="image"||C.kind==="loading"&&C.mode==="image",ue=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,Se=C.kind==="text"&&$s(ue??"")&&pe==="preview",et=C.kind==="text"&&Ns(ue??"")&&N==="preview";if(C.kind!=="text"||z||Se||et){ye(null);return}const Fe=()=>{const _e=V.current.get(E.end);if(!_e||!P){ye(null);return}const qe=_e.offsetTop+_e.offsetHeight/2,ft=P.scrollLeft+Math.max(8,P.clientWidth-120);ye({top:qe,left:ft})};Fe();const Ve=new ResizeObserver(()=>Fe());return Ve.observe(P),()=>Ve.disconnect()},[E,ie,C,pe,N,n,i,Pe]);const Ir=C.kind==="text"&&!(Ns(pt??"")&&N==="preview")&&!pt?.toLowerCase().endsWith(".csv")&&!pt?.toLowerCase().endsWith(".kicad_pro")&&!pt?.toLowerCase().endsWith(".kicad_prl"),xr=a.useCallback(()=>{nt(!1),Ie(""),_t([]),H(0),qa()},[]),Rn=a.useCallback(()=>{Ir&&(nt(!0),requestAnimationFrame(()=>{ae.current?.focus(),ae.current?.select()}))},[Ir]),bt=a.useCallback(P=>{H(z=>ze.length===0?0:(z+P+ze.length)%ze.length)},[ze.length]);if(a.useEffect(()=>{const P=z=>{const ue=kg(z);if(ue==="open"&&Ir){z.preventDefault(),Rn();return}rt&&(ue==="close"?(z.preventDefault(),xr()):(ue==="next"||ue==="previous")&&(z.preventDefault(),bt(ue==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[xr,rt,bt,Rn,Ir]),a.useLayoutEffect(()=>{if(qa(),!rt||!oe.trim()||!re.current){_t([]),H(0);return}const P=jg(re.current,oe);return _t(P),H(0),_d(P,0),Bd(P[0]),qa},[rt,oe,Pe,pe,C]),a.useEffect(()=>{rt&&(_d(ze,Bt),Bd(ze[Bt]))},[Bt,ze,rt]),a.useEffect(()=>qa,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.selectFilePrompt")});const Ge=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=io(Ge,i),vr=pu(Ge,i),yr=C.kind==="text"&&C.content?C.content.split(`
1654
- `):[],Ks=Math.max(2,String(yr.length).length)+1,wr=C.kind==="text"||C.kind==="image"||C.kind==="model3d"||C.kind==="video"||C.kind==="eda"?C.meta:null,kr=$s(Ge),Vs=Ge.toLowerCase().endsWith(".csv"),Pt=Ge.toLowerCase().endsWith(".kicad_pro"),es=Ge.toLowerCase().endsWith(".kicad_prl"),Ut=C.kind==="text"&&kr&&pe==="preview",qs=Ns(Ge),Xt=C.kind==="text"&&qs&&N==="preview",Ys=C.kind==="image"||C.kind==="loading"&&C.mode==="image",ko=C.kind==="model3d"||C.kind==="loading"&&C.mode==="model3d",Mt=C.kind==="video"||C.kind==="loading"&&C.mode==="video",Yr=C.kind==="eda"||C.kind==="loading"&&C.mode==="eda",ts=C.kind==="text"?C.sourcePath:Ge,Dr=Am(ts,i,E),Fr=(()=>{if(!E||C.kind!=="text"||yr.length===0)return Dr;const P=[];for(let Se=E.start;Se<=E.end;Se+=1)P.push(`${Se} ${yr[Se-1]??""}`);const z=Qu(Ge).replace(/^\./,""),ue="```";return`${Dr}
1651
+ `),display:!0})});continue}if(f+1<r.length&&M&&!sl(y)&&/^(=+|-+)\s*$/.test(r[f+1].trim())){const D=r[f+1].trim().startsWith("=")?1:2,p=`h${D}`,i=al(M,m),O={level:D,text:eu(M),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(p,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${D===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:ut(M,`setext-heading-${f}`,!0,m)})}),f+=2;continue}const B=M.match(/^(#{1,6})\s+(.+)$/);if(B){const D=B[1].length,p=sf(B[2]),i={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${D}`,C=al(p,m),K={level:D,text:eu(p),id:C};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:K,content:e.jsx(O,{id:C,className:`scroll-mt-16 font-semibold text-foreground ${i[D]}`,children:ut(p,`heading-${f}`,!0,m)})}),f+=1;continue}if(ef(y)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(M.startsWith(">")){const D=[],p=[],i=f;for(;f<r.length&&/^>\s?/.test(r[f].trim());)D.push(r[f].trim().replace(/^>\s?/,"")),p.push(f+1),f+=1;const O=D[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const K=O[1].toUpperCase(),de=O[2]?.trim(),te=[...de?[de]:[],...D.slice(1)],xe=[...de?[p[0]]:[],...p.slice(1)],W=ll(te,`callout-${i}`,m);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:X=>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:K}),te.length>0&&e.jsx("div",{children:cl(W.perLine,W.hardBreaks,xe,`callout-${i}`,X)})]})});continue}const C=Cb(D,`quote-${i}`,m,p);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:K=>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:Nb(C,K)})});continue}if(f+1<r.length&&y.includes("|")&&po(r[f+1])){const D=Ws(y),p=yf(r[f+1]),i=[],O=f;for(f+=2;f<r.length&&r[f].includes("|")&&r[f].trim();)i.push(Ws(r[f])),f+=1;const C=D.map((de,te)=>ut(de,`th-${O}-${te}`,!0,m)),K=i.map((de,te)=>D.map((xe,W)=>ut(de[W]??"",`td-${O}-${te}-${W}`,!0,m)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:de=>{const te=xe=>!!(de&&xe>=de.start&&xe<=de.end);return e.jsx("div",{className:qu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":te(O+1)?"true":void 0,children:C.map((xe,W)=>e.jsx("th",{className:`${Ku} ${mo(p[W]??null)}`,children:e.jsx("div",{className:uo,children:xe})},`h-${W}`))})}),e.jsx("tbody",{children:K.map((xe,W)=>{const X=O+W+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":X,"data-md-ref-start":X,"data-md-ref-end":X,"data-selected":te(X)?"true":void 0,children:D.map((L,F)=>e.jsx("td",{className:`${Vu} ${mo(p[F]??null)}`,children:e.jsx("div",{className:uo,children:xe[F]})},`c-${F}`))},`r-${W}`)})})]})})}});continue}const E=Gs(y);if(E){const D=E.ordered,p=yo(y),i=E.start,O=f,C=xl(r,f,p,D,!0,h);f=C.nextIndex;const K=D?"ol":"ul",de=vl(C.items,`list-${O}`,m);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:te=>e.jsx(K,{start:D?i:void 0,className:`${D?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:wl(de,te)})});continue}const $=[y.trimStart()],A=[f+1],T=f;for(f+=1;f<r.length&&r[f].trim()&&!sl(r[f])&&!(f+1<r.length&&r[f].includes("|")&&po(r[f+1]));){if(fo(r[f])||h.has(f)){f+=1;continue}$.push(r[f].trimStart()),A.push(f+1),f+=1}const U=ll($,`p-${T}`,m);b.push({key:`p-${T}`,startLine:T+1,endLine:f,fineGrained:!0,content:D=>e.jsx("p",{className:"text-muted-foreground",children:cl(U.perLine,U.hardBreaks,A,`p-${T}`,D)})})}const j=Rb(m);return j&&b.push({key:"footnotes",startLine:r.length,endLine:r.length,content:j}),{blocks:b,images:g}}function Pb(r,n,s){return yl(r,n,s).blocks}function Rf(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 Cf(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Tb({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const u=uf(r);return e.jsx(Bf,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Nf({images:r,index:n,onChange:s,onClose:l}){const{t:u}=St(),d=r[n],h=r.length>1,g=a.useRef(null),m=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[j,y]=a.useState(!1),[M,I]=a.useState(0),[_,B]=a.useState(!1),E=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),$=a.useCallback(()=>{j||Date.now()<f.current||(E(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[E,j,l]),A=a.useCallback(p=>{if(r.length===0)return;const i=(p+r.length)%r.length;g.current?.slideTo(i),s(i)},[r.length,s]),T=a.useCallback(()=>A(n-1),[A,n]),U=a.useCallback(()=>A(n+1),[A,n]);if(a.useEffect(()=>{E(),I(0),B(!1),y(!1)},[E,n]),a.useEffect(()=>{const p=g.current;p&&(p.allowTouchMove=h&&!j)},[h,j]),a.useEffect(()=>{const p=g.current;!p||p.activeIndex===n||p.slideTo(n,0)},[n]),a.useEffect(()=>E,[E]),a.useEffect(()=>{const p=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),T()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[h,U,T,l]),xu({onDrag:({movement:[p,i],pinching:O})=>{O||j||Math.abs(i)<Math.abs(p)*1.15&&M===0||(B(!0),Math.abs(i)>8&&(f.current=Date.now()+300),I(Math.max(0,i)))},onDragEnd:({movement:[p,i],velocity:[,O],pinching:C,canceled:K})=>{if(B(!1),C||K||j||Math.abs(i)<Math.abs(p)*1.15){I(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),kf(i,O)){l();return}I(0)}},{target:m,drag:{filterTaps:!0,pointer:{touch:!0}}}),!d)return null;const D=d.title||d.alt||(d.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:D}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:T,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx(Bs,{size:17})}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(cm,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Yt,{size:18})})]})]}),e.jsx("div",{ref:m,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:$,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${M}px, 0) scale(${Math.max(.86,1-M/900)})`,opacity:Math.max(.35,1-M/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(vu,{onSwiper:p=>{g.current=p,p.allowTouchMove=h&&!j},onSlideChange:p=>{p.activeIndex!==n&&s(p.activeIndex)},onSliderMove:()=>{E(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((p,i)=>e.jsx(Wi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:p.kind==="image"?e.jsx(Tb,{src:p.src,alt:p.alt||p.title||u("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(Xb,{svg:p.svg,title:p.title||p.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${p.kind}-${i}-${p.alt}`))})})})]})]}),document.body)}function Mf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:d,scrollTop:h,outlineOpen:g,outlineCloseSignal:m,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:j,lightboxCloseSignal:y,onLightboxOpen:M,onLightboxClose:I,onLocalLinkOpen:_}){const{t:B}=St(),[E,$]=a.useState(null),[A,T]=a.useState(null),[U,D]=a.useState(1),[p,i]=a.useState(null),O=a.useRef(null),C=a.useRef(null),{blocks:K,images:de}=a.useMemo(()=>yl(r.split(`
1652
+ `),n,s,R=>{T(null),$(R),M?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:R=>B("rightSidebar.backToFootnote",{index:R})}),[r,n,s,M,B]),te=a.useMemo(()=>A?[...de,A]:de,[de,A]),xe=a.useCallback(R=>{T({kind:"mermaid",svg:R,alt:"Mermaid diagram",title:"Mermaid diagram"}),$(de.length),M?.()},[de.length,M]);a.useEffect(()=>{$(null),T(null)},[r,n]),a.useEffect(()=>{$(null),T(null)},[y]),a.useEffect(()=>{j||($(null),T(null))},[j]),a.useEffect(()=>{D(1)},[r,n]),a.useLayoutEffect(()=>{const R=O.current;if(!R||K.length===0)return;const ee=Array.from(R.querySelectorAll("[data-markdown-preview-block-start]"));let le=1;const Ee=28;for(const Ne of ee)if(Ne.offsetTop-h<=Ee)le=Number(Ne.dataset.markdownPreviewBlockStart)||le;else break;D(Ne=>Ne===le?Ne:le)},[K,h]);const W=a.useMemo(()=>Rf(K,U),[U,K]),X=a.useMemo(()=>Cf(K),[K]),L=`${n??""}
1653
+ ${r}`,F=a.useRef(L),V=a.useRef(null),re=a.useRef(null),ie=a.useRef(!1);a.useEffect(()=>{F.current!==L&&(F.current=L,f?.())},[f,L]),a.useEffect(()=>{m!==void 0&&i(null)},[m]),a.useLayoutEffect(()=>{if(!g){i(null);return}const R=()=>{const ee=C.current;if(!ee)return;const le=ee.getBoundingClientRect(),Ee=window.innerWidth;i({top:le.bottom+6,right:Math.max(8,Ee-le.right)})};return R(),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[g,h,W]);const we=a.useCallback(R=>{const ee=O.current,le=ee?.closest("[data-markdown-preview-scroller]"),Ee=ee?.querySelector(`[data-markdown-preview-block-start="${R.startLine}"]`);if(!le||!Ee)return;const Ne=le.getBoundingClientRect(),We=Ee.getBoundingClientRect(),Pe=ee?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,tt=We.top-Ne.top+le.scrollTop;le.scrollTo({top:Math.max(0,tt-Pe-8),behavior:"smooth"}),D(R.startLine),f?.()},[f]),pe=a.useCallback(R=>{R.pointerType==="mouse"&&R.button!==0||Oi(R.target)||(V.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY})},[]),De=a.useCallback((R,ee,le)=>{const Ee=V.current;if(V.current=null,!Ee||Ee.pointerId!==R.pointerId)return;const Ne=Math.abs(R.clientX-Ee.startX),We=Math.abs(R.clientY-Ee.startY);if(Ne>8||We>8)return;const ce=R.target;if(Oi(ce)||Ki())return;const Pe=uu(ce,ee,le);u(R,Pe.start,Pe.end)},[u]),N=a.useCallback(R=>{V.current?.pointerId===R.pointerId&&(V.current=null)},[]),q=a.useCallback((R,ee)=>{const le=O.current;if(!le||typeof document.elementFromPoint!="function")return null;const Ee=document.elementFromPoint(R,ee);if(!(Ee instanceof HTMLElement)||!le.contains(Ee))return null;const Ne=Ee.closest("[data-md-ref-start]");if(Ne){const ke=Number(Ne.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const We=Ee.closest("[data-markdown-preview-block-start]");if(!We)return null;const ce=Number(We.dataset.markdownPreviewBlockStart),Pe=K.find(ke=>ke.startLine===ce);if(!Pe)return Number.isFinite(ce)&&ce>0?ce:null;if(Pe.endLine<=Pe.startLine)return Pe.startLine;const tt=We.getBoundingClientRect(),Te=tt.height>0?Math.min(1,Math.max(0,(ee-tt.top)/tt.height)):0;return Math.round(Pe.startLine+Te*(Pe.endLine-Pe.startLine))},[K]),he=a.useCallback(R=>{if(!d||R.pointerType==="mouse"&&R.button!==0)return;const ee=q(R.clientX+24,R.clientY);if(ee!=null){re.current={pointerId:R.pointerId,anchorLine:ee,moved:!1};try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}}},[d,q]),Ae=a.useCallback(R=>{const ee=re.current;if(!ee||ee.pointerId!==R.pointerId||!d)return;const le=q(R.clientX+16,R.clientY);le!=null&&(!ee.moved&&le===ee.anchorLine||(ee.moved=!0,ie.current=!0,d(R,Math.min(ee.anchorLine,le),Math.max(ee.anchorLine,le),"move")))},[d,q]),Qe=a.useCallback(R=>{const ee=re.current;if(re.current=null,!ee||ee.pointerId!==R.pointerId||!d||!ee.moved)return;const le=q(R.clientX+16,R.clientY)??ee.anchorLine;d(R,Math.min(ee.anchorLine,le),Math.max(ee.anchorLine,le),"end")},[d,q]),Le=a.useCallback(R=>{re.current?.pointerId===R.pointerId&&(re.current=null)},[]),at={onPointerDown:he,onPointerMove:Ae,onPointerUp:Qe,onPointerCancel:Le},Be=()=>ie.current?(ie.current=!1,!0):!1;return K.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:B("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:R=>{const ee=R.target instanceof Element?R.target.closest("a[href]"):null;if(!ee||!_)return;const le=ee.getAttribute("href");if(!le)return;const Ee=pl(le,n,s);Ee&&(R.preventDefault(),_(Ee))},children:[W.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:W.map(R=>R.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:W[W.length-1].text}),X.length>1&&e.jsxs("button",{ref:C,type:"button",onClick:()=>{g?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${g?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":g,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(wu,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),g&&typeof document<"u"&&qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:f}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:p?{top:`${p.top}px`,right:`${p.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:X.map(R=>{const ee=W[W.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>we(R),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${ee?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ee?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`desktop-${R.id}-${R.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:B("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":B("rightSidebar.closeMarkdownOutline"),title:B("common.close"),children:e.jsx(Yt,{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:X.map(R=>{const ee=W[W.length-1]?.startLine===R.startLine;return e.jsxs("button",{type:"button",onClick:()=>we(R),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${ee?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(R.level-1,4)*12+8}px`},title:R.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ee?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",R.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:R.text})]},`${R.id}-${R.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(rf.Provider,{value:xe,children:K.map(R=>{const ee=!!(l&&R.startLine<=l.end&&R.endLine>=l.start),le=!!(l&&l.start<=R.startLine&&l.end>=R.endLine),Ee=R.kind==="table"?!1:R.fineGrained?le:ee,Ne=R.kind==="table"&&l?.start===R.startLine&&l.end===R.endLine;let We=null;if(R.kind!=="table"&&R.fineGrained&&ee&&!le&&l){const Te=R.endLine-R.startLine+1,ke=Math.max(l.start,R.startLine),rt=Math.min(l.end,R.endLine),nt=(ke-R.startLine)/Te,oe=(rt-ke+1)/Te;We=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) * ${nt})`,height:`calc((100% - 0.5rem) * ${oe})`}})}const ce=typeof R.content=="function"?R.content(l):R.content,Pe=R.startLine===R.endLine?String(R.startLine):`${R.startLine}-${R.endLine}`,tt=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:Fi(Ee),"aria-hidden":"true",...at,children:[e.jsx("span",{className:_i(Ee)}),We]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:ce})]});return R.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":R.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${Ee?"bg-primary/10":""}`,title:`Line ${Pe}`,"aria-label":`Line ${Pe}`,children:[R.kind==="table"?e.jsx("button",{type:"button",className:Fi(Ne,"self"),onClick:Te=>{Te.preventDefault(),!Be()&&u(Te,R.startLine,R.endLine)},title:`Reference table lines ${Pe}`,"aria-label":`Reference table lines ${Pe}`,...at,children:e.jsx("span",{className:_i(Ne,"self")})}):e.jsxs("span",{className:Fi(Ee,"none"),"aria-hidden":"true",...at,children:[e.jsx("span",{className:_i(Ee,"none")}),We]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:Te=>De(Te,R.startLine,R.endLine),onPointerCancel:N,onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),u(Te,R.startLine,R.endLine))},title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:ce})]},R.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":R.startLine,onClick:Te=>{const ke=Te.target;if(Oi(ke)||Ki()||Be())return;const rt=uu(ke,R.startLine,R.endLine);u(Te,rt.start,rt.end)},onKeyDown:Te=>{Te.key!=="Enter"&&Te.key!==" "||(Te.preventDefault(),u(Te,R.startLine,R.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${Ee?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Pe}`,"aria-label":`Reference line ${Pe}`,children:tt},R.key)})})})]}),j&&E!==null&&te[E]&&e.jsx(Nf,{images:te,index:E,onChange:$,onClose:()=>{$(null),T(null),I?.()}})]})}function Jn({label:r,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:d,disabled:h,onChange:g}){const{t:m}=St(),[b,f]=a.useState(!1),[j,y]=a.useState(""),[M,I]=a.useState(null),_=a.useRef(null),B=a.useRef(null),E=j.trim().toLowerCase(),$=a.useMemo(()=>E?s.filter(p=>`${p.label} ${p.meta??""}`.toLowerCase().includes(E)):s,[E,s]),A=s.find(p=>p.value===n),T=()=>{const p=j.trim();p&&(g(p),f(!1),y(""))},U=a.useCallback(()=>{const p=_.current?.getBoundingClientRect();if(!p)return!1;const i=12,O=Math.max(220,Math.min(p.width,window.innerWidth-i*2)),C=Math.min(Math.max(i,p.left),window.innerWidth-O-i),K=window.innerHeight-p.bottom-i,de=p.top-i,te=K>=180||K>=de,xe=Math.max(96,(te?K:de)-4),W=Math.min(320,xe);return I({left:C,top:te?p.bottom+4:Math.max(i,p.top-W-4),width:O,maxHeight:W}),!0},[]),D=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let p=0;const i=()=>{p||(p=window.requestAnimationFrame(()=>{p=0,U()}))},O=C=>{const K=C.target;K instanceof Node&&(_.current?.contains(K)||B.current?.contains(K)||(f(!1),y("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{p&&window.cancelAnimationFrame(p),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),b){f(!1);return}D()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:A?.label??(n||l)})]}),e.jsx(Os,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&qr.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:p=>p.stopPropagation(),style:{left:M?.left??12,top:M?.top??12,width:M?.width??260,maxHeight:M?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(Zn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:j,onChange:p=>y(p.target.value),onKeyDown:p=>{if(p.key==="Escape"){p.preventDefault(),f(!1),y("");return}p.key==="Enter"&&(p.preventDefault(),T())},onBlur:()=>{j.trim()&&$.length===0&&T()},placeholder:u,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(M?.maxHeight??320)-46)},children:[j.trim()&&!s.some(p=>p.value===j.trim())&&e.jsxs("button",{type:"button",onMouseDown:p=>p.preventDefault(),onClick:T,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:j.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:m("common.use")})]}),$.length>0?$.map(p=>e.jsxs("button",{type:"button",onClick:()=>{g(p.value),f(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${p.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:p.label}),p.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:p.meta})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:d})]})]}),document.body)]})}function au({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:d,onToggleRepo:h,onGenerate:g,onSecondaryAction:m,disabled:b,generateDisabled:f,secondaryDisabled:j,inserted:y,buttonLabel:M,insertedLabel:I,title:_,ariaLabel:B,scopeTitle:E,scopeLabel:$,allLabel:A,generateLabel:T,secondaryLabel:U,secondaryTitle:D,secondaryLoading:p,loading:i,error:O,statusTitle:C,extraContent:K,renderRepoExtra:de}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!r):f||g()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:C??(s?`${E}: ${$}`:_),children:[i?e.jsx(Nt,{size:13,className:"animate-spin"}):e.jsx(Hs,{size:13}),e.jsx("span",{children:y?I:M}),s&&e.jsx(Os,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&qr.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:te=>te.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:E}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:$})]}),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(Yt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[K,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:A}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(te=>{const xe=d.includes(te.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${xe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(te.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${xe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:te.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:te.label}),te.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:te.branch})]}),xe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),de&&(l||xe)&&e.jsx("div",{className:"px-2 pb-2",children:de(te)})]},te.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${m&&U?"sm:grid-cols-2":""}`,children:[m&&U&&e.jsxs("button",{type:"button",onClick:()=>{j||(n(!1),m())},disabled:j,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[p?e.jsx(Nt,{size:12,className:"animate-spin"}):e.jsx(Eu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),g())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Hs,{size:12}),T]})]})]})}),document.body)]})}function Ib(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 Ef(){return mt(fl,Ib)??{}}function Db(r,n){const s=Ef(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,d])=>d.updatedAt-u.updatedAt).slice(0,Ag);Is(fl,Object.fromEntries(l),Pg)}function Fb(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 _b(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&&!Fb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function kl(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function $f(){return mt(hl,_b)??{}}function ou(r,n){const s=kl(r,n);return s?$f()[s]??null:null}function Ti(r,n,s){const l=kl(r,n);if(!l)return;const u=$f(),d=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...d,...s,updatedAt:Date.now()}}).sort(([,g],[,m])=>m.updatedAt-g.updatedAt).slice(0,Lg);Is(hl,Object.fromEntries(h),Tg)}function Qa({active:r,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${r?"block":"hidden"}`,"aria-hidden":!r,children:n?typeof l=="function"?l():l:s})}function Ii({slow:r}){return e.jsx(Vm,{slow:r})}function eo({message:r,onRetry:n}){const{t:s}=St();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 io(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function kt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function Di(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 Bb(r,n,s){return Vi(r,n,s)}function Fi(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 _i(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 Af(r){const n=new Map;for(const s of r)n.set(Sl(s),s);return n}function Lf(r,n){const s=new Map(r);for(const l of n)s.set(Sl(l),l);return s}function iu(r,n){let s=0;for(const l of r){const u=gt(l,n);u&&n&&u!==n&&(s+=1)}return s}function Ob(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Ub(r,n){return Array.from(Lf(Af(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Hb(r,n){const s=r.relativeRoot==="."?kt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||kt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Ob(r.files)}}function Pf(r,n){const s=kt(n??"")||n||"";return r.map(l=>Hb(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function Tf(r,n,s,l,u){const d=Xu(s),h=d.find(_=>_.root===l)??d[0]??null,g=n.find(_=>_.root===l)??null,m=g?.relativeRoot??h?.relativeRoot??".",b=g?.name??h?.name??(kt(l)||l),f=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:m,repoName:b})),j=h?.context??s.context,y={...g??h??{id:l,root:l,relativeRoot:m,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:g?.id??h?.id??l,root:l,displayRoot:g?.displayRoot??h?.displayRoot,relativeRoot:m,name:b,depth:g?.depth??h?.depth??0,nested:g?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,deferred:h?.deferred??!1,files:f,context:j?{...j,root:l,changedFiles:f.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},M=g?n.map(_=>_.root===l?y:_):[...n,y];return{files:Array.from(r).filter(_=>gt(_,u)!==l).concat(f),repositories:M,repoFilters:Pf(M,u)}}function gt(r,n){return r.repoRoot??n}function Sl(r){return`${r.repoRoot??""}\0${r.path}`}function yt(r){return r.absolutePath||r.path}function Bi(r){return Sl(r)}function zb(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function lu(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function cu(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 As(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 Ls(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 hr(r){return r instanceof DOMException&&r.name==="AbortError"}function Wb(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function du(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function Oi(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function uu(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),d=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(d)&&d>0?{start:Math.min(u,d),end:Math.max(u,d)}:{start:n,end:s}}function Gb({actions:r,running:n,completed:s}){const{t:l}=St(),[u,d]=a.useState(!1),h=a.useRef(null),g=r.find(b=>n?.action===b.key),m=r.find(b=>s?.action===b.key);return r.length===0?null:(a.useEffect(()=>{if(!u)return;const b=j=>{const y=j.target;y instanceof Node&&h.current?.contains(y)||d(!1)},f=j=>{j.key==="Escape"&&d(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),d(f=>!f)},disabled:r.every(b=>b.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${u?"bg-surface-elevated text-foreground":m?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:g?.label??m?.label??l("rightSidebar.gitQuickActions"),children:g?e.jsx(Nt,{size:13,className:"animate-spin"}):m?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(lo,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(b=>{const f=n?.action===b.key,j=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),b.onClick(),d(!1)},disabled:b.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${j?"bg-accent/10 text-accent":b.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(Nt,{size:13,className:"animate-spin"}):j?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Kb(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function If(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Kb(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function Qn(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const Ui=new WeakMap;function bo(r){const n=Ui.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"),Ui.delete(r)},1700);Ui.set(r,s)}function Vb(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 u=null;for(const g of l){if(!Qn(g))continue;const m=g.querySelector(s);if(m&&Qn(m)){u=m;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Qn)??null,!u)return;const d=If(u);if(!d){u.scrollIntoView({block:"start",behavior:"smooth"}),bo(u);return}const h=u.getBoundingClientRect().top-d.getBoundingClientRect().top+d.scrollTop;d.scrollTo({top:Math.max(0,h),behavior:"instant"}),bo(u)}function kn(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,u=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,d=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&d?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${d}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(I=>!!I),g=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let m=null;for(const I of g)if(Qn(I)){for(const _ of h){const B=I.querySelector(_);if(B&&Qn(B)){m=B;break}}if(m)break}if(m??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Qn)??null,!m){Vb(r.filePath);return}const b=If(m);if(!b){m.scrollIntoView({block:"center",behavior:"smooth"}),bo(m);return}const f=m.getBoundingClientRect(),j=b.getBoundingClientRect(),M=f.top-j.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,M),behavior:"instant"}),bo(m)}const Df=1,Ff=8;function qb(r){return Math.min(Ff,Math.max(Df,r))}function _f({resetKey:r,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[d,h]=a.useState({scale:1,x:0,y:0}),[g,m]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),j=a.useRef(!1),y=a.useRef(null),M=a.useRef(0),I=a.useRef(d);I.current=d,a.useEffect(()=>{h({scale:1,x:0,y:0})},[r]);const _=a.useCallback((A,T,U)=>{const D=u.current;if(!D)return{x:T,y:U};const p=D.firstElementChild instanceof HTMLElement?D.firstElementChild:null,i=p?.clientWidth||D.clientWidth,O=p?.clientHeight||D.clientHeight,C=Math.max(0,(i*A-D.clientWidth)/2),K=Math.max(0,(O*A-D.clientHeight)/2);return{x:Math.min(C,Math.max(-C,T)),y:Math.min(K,Math.max(-K,U))}},[]),B=a.useCallback((A,T,U)=>{h(D=>{const p=qb(A),i=u.current;if(!i||p===1)return{scale:p,x:0,y:0};const O=i.getBoundingClientRect(),C=(T??O.left+O.width/2)-O.left-O.width/2,K=(U??O.top+O.height/2)-O.top-O.height/2,de=p/D.scale,te=C-(C-D.x)*de,xe=K-(K-D.y)*de;return{scale:p,..._(p,te,xe)}})},[_]),E=a.useCallback((A,T)=>{m(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,A,T),window.setTimeout(()=>m(!1),220)},[B]);a.useEffect(()=>{const A=u.current;if(!A)return;const T=p=>{if(p.pointerType==="mouse"&&p.button!==0)return;const i=f.current.size===0;if(f.current.add(p.pointerId),i){const O=Date.now(),C=y.current;if(C&&O-C.time<350&&Math.hypot(p.clientX-C.x,p.clientY-C.y)<24){y.current=null,M.current=O,s?.(),E(p.clientX,p.clientY);return}}if(f.current.size>1){j.current=!0,b.current=null;return}if(!(I.current.scale<=1)){p.preventDefault(),b.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{A.setPointerCapture?.(p.pointerId)}catch{}m(!1)}},U=p=>{const i=b.current;if(!i||i.pointerId!==p.pointerId)return;const O=p.clientX-i.startX,C=p.clientY-i.startY;if(!i.moved){if(Math.hypot(O,C)<6)return;i.moved=!0}p.stopPropagation(),p.preventDefault(),h(K=>({...K,..._(K.scale,i.originX+O,i.originY+C)}))},D=p=>{const i=b.current,O=i?.pointerId===p.pointerId&&i.moved;if(i?.pointerId===p.pointerId){i.moved&&p.stopPropagation(),b.current=null;try{A.releasePointerCapture?.(p.pointerId)}catch{}}f.current.delete(p.pointerId)&&f.current.size===0&&(!j.current&&!O&&(y.current={time:Date.now(),x:p.clientX,y:p.clientY}),j.current=!1)};return A.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",D,{capture:!0}),window.addEventListener("pointercancel",D,{capture:!0}),()=>{A.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",D,{capture:!0}),window.removeEventListener("pointercancel",D,{capture:!0})}},[_,s,E]),xu({onPinch:({offset:[A],origin:[T,U]})=>{m(!1),B(A,T,U)},onWheel:({event:A,delta:[T,U],ctrlKey:D})=>{if(D){A.preventDefault(),A.stopPropagation(),m(!1),B(I.current.scale*(1-U*.01),A.clientX,A.clientY);return}I.current.scale<=1||(A.preventDefault(),A.stopPropagation(),m(!1),h(p=>({...p,..._(p.scale,p.x-T,p.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Df,max:Ff},from:()=>[I.current.scale,0],rubberband:!0}});const $=d.scale>1;return a.useEffect(()=>{n?.($)},[n,$]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":$?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:$?"grab":"zoom-in"},onDoubleClick:A=>{A.stopPropagation(),!(Date.now()-M.current<500)&&(s?.(),E(A.clientX,A.clientY))},children:l({scale:d.scale,zoomed:$,animateTransform:g,transformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0) scale(${d.scale})`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${d.x}px, ${d.y}px, 0)`,transformOrigin:"center center",transition:g?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Bf({src:r,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:d,onDoubleTap:h}){const g=xo(r,u),[m,b]=a.useState(null),f=s??wo(r);return a.useEffect(()=>{b(null)},[r]),e.jsx(_f,{resetKey:r,onZoomChange:d,onDoubleTap:h,children:({transformStyle:j,vectorTransformStyle:y,scale:M,animateTransform:I})=>{const _=e.jsx("img",{src:g,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&m?{position:"absolute",left:"50%",top:"50%",width:m.width*M,height:m.height*M,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:m?{...j,width:m.width,height:m.height}:f?y:j,onLoad:B=>{const E=B.currentTarget,$=E.parentElement;if($&&E.naturalWidth>0&&E.naturalHeight>0){const A=Math.max(1,$.clientWidth-2),T=Math.max(1,$.clientHeight-2),U=Math.min(A/E.naturalWidth,T/E.naturalHeight),D=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(E.naturalWidth*D)),height:Math.max(1,Math.round(E.naturalHeight*D))})}l(B)},onError:u});return!f||!m?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:m.width,height:m.height},children:_})}})}function Yb({svg:r,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const d=u.current,h=d?.querySelector("svg");if(!d||!h)return;const g=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let j=f[2],y=f[3];if((!Number.isFinite(j)||!Number.isFinite(y)||j<=0||y<=0)&&(j=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(j)||!Number.isFinite(y)||j<=0||y<=0)return;const M=Math.max(1,d.clientWidth-24),I=Math.max(1,d.clientHeight-24),_=Math.min(M/j,I/y,1);h.style.width=`${Math.max(1,Math.floor(j*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};g();const m=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return m?.observe(d),()=>m?.disconnect()},[s,r,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function Xb({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(_f,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:d})=>e.jsx(Yb,{svg:r,title:n,scale:d,vectorTransformStyle:u})})}let Jb=0,Zb=0,Qb=0,ex=0,tx=0;function Hi(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 dt(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:++Zb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function to(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++ex,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function rx(){return`diff-ui-${Date.now().toString(36)}-${(++tx).toString(36)}`}function nx(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function sx(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 dl({onReviewReference:r,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:d,onClose:h,onDirectoryLinkOpen:g,isMobile:m,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:j,onCloseMarkdownOutline:y,markdownImageLightboxOpen:M,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:$,insertedReferenceKey:A,copiedReferenceKey:T,scrollToLine:U,onScrollToLineHandled:D}){const{t:p}=St(),i=J(P=>P.rootPath),O=J(P=>P.selectFile),[C,K]=a.useState({kind:"idle"}),[de,te]=a.useState("schematic"),[xe,W]=a.useState(null),X=a.useRef(null),[L,F]=a.useState(null),V=a.useRef(new Map),re=a.useRef(null),[ie,we]=a.useState(null),[pe,De]=a.useState(()=>qd()),[N,q]=a.useState(()=>Id(i,n)),he=a.useRef(null),[Ae,Qe]=a.useState(!1),[Le,at]=a.useState(null),[Be,R]=a.useState(0),[ee,le]=a.useState([]),[Ee,Ne]=a.useState(null),We=a.useRef(null),ce=a.useRef(n),[Pe,tt]=a.useState(null),[Te,ke]=a.useState({status:"idle"}),[rt,nt]=a.useState(!1),[oe,Ie]=a.useState(""),[ze,_t]=a.useState([]),[Bt,H]=a.useState(0),ae=a.useRef(null),ve=Mu(d),Ke=kl(i,n);a.useEffect(()=>{if(ce.current===n)return;ce.current=n;const P=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(We.current===P){We.current=null;return}We.current=null,le([]),Ne(null),nt(!1),Ie("")},[n,i]);const pt=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,mr=J(P=>pt?(P.fileChangeVersions.get(pt)??0)+P.fileWatchEpoch:P.fileWatchEpoch),pr=a.useRef(null),Ot=a.useRef(null),[gr,br]=a.useState(0),Sn=a.useCallback(()=>br(P=>P+1),[]);a.useEffect(()=>{const P=X.current;return X.current=null,W(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const z=X.current;X.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[pt,mr,gr]),a.useEffect(()=>{if(!n){pr.current=null,K({kind:"idle"});return}const P=i&&!n.startsWith("/")?`${i}/${n}`:n,z=new AbortController,ue=++Jb,Se=`right-sidebar-file-preview:${ue}`,et=performance.now();let Fe=!1;const Ve=(Z,Ye={})=>{Fe||(Fe=!0,Hi("end",{loadingId:ue,reason:Z,durationMs:Math.round(performance.now()-et),filePath:n,fullPath:P,rootPath:i,...Ye}))};let _e=null;const qe=Jh(P),ft=qe?P.toLowerCase().endsWith(".kicad_pcb")?de==="schematic"?"pcb-front":de:"schematic":de,Nn=!qe&&ul(P),sr=!qe&&!Nn&&Zh(P),os=!qe&&!Nn&&!sr&&hu(P),Qr=$s(P),en=Ns(P),Ur=qe?"eda":Nn?"image":sr?"model3d":os?"video":"text",tn=pr.current!==P;if(pr.current=P,tn){Hi("start",{loadingId:ue,filePath:n,fullPath:P,rootPath:i,mode:Ur,externalVersion:mr}),ke({status:"idle"}),K({kind:"loading",mode:Ur}),Ot.current=null;const Z=ou(i,n);$(Z?.lineRange??null),De(Qr?qd():"source"),q(en?Id(i,n):"source"),qe&&te(Qh(P))}tn||K(Z=>Z.kind==="error"?{kind:"loading",mode:Ur}:Z);const rn=window.setTimeout(()=>{Fe||z.signal.aborted||Hi("still_active",{loadingId:ue,filePath:n,fullPath:P,rootPath:i,mode:Ur,durationMs:Math.round(performance.now()-et),isPathChange:tn})},3e3),is=window.setTimeout(()=>{if(Fe||z.signal.aborted)return;const Z=qe?p("rightSidebar.edaTimeout"):sr?p("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(Z,"TimeoutError")),K({kind:"error",message:Z}),Ve("stuck_timeout",{error:Z})},qe?em+5e3:sr?tm+5e3:rm(P)?35e3:Ug);if(qe){const Z=ft==="pcb-3d"?X.current:null;Z?(K(Z),Ve("eda_3d_client_cache_hit",{bytes:Z.meta.size,view:Z.view,mimeType:Z.meta.mimeType})):nm(P,ft,z.signal,"view_file",Se).then(Ye=>{if(z.signal.aborted)return;_e=URL.createObjectURL(Ye.blob);const Tt={kind:"eda",sourcePath:Ye.path||P,objectUrl:_e,view:Ye.view,meta:{size:Ye.size,mimeType:Ye.mimeType,modified:Ye.modified}};if(Ye.view==="pcb-3d"){const ar=X.current;ar&&ar.objectUrl!==_e&&URL.revokeObjectURL(ar.objectUrl),X.current=Tt,W(Tt),_e=null}K(Tt),Ve("eda_loaded",{bytes:Ye.size,view:Ye.view,mimeType:Ye.mimeType})}).catch(Ye=>{z.signal.aborted||(K({kind:"error",message:Ye instanceof Error&&/timed out/i.test(Ye.message)?p("rightSidebar.edaTimeout"):Ye instanceof Error?Ye.message:p("rightSidebar.edaLoadFailed")}),Ve("error",{error:Ye instanceof Error?Ye.message:String(Ye)}))})}else if(Nn)sm(P,z.signal,"view_file",Se).then(Z=>{_e=URL.createObjectURL(Z.blob),K({kind:"image",objectUrl:_e,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Ve("image_loaded",{bytes:Z.size,mimeType:Z.mimeType})}).catch(Z=>{z.signal.aborted||(K({kind:"error",message:Z instanceof Error?Z.message:p("rightSidebar.imageLoadFailed")}),Ve("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(sr)am(P,z.signal,"view_file",Se).then(Z=>{z.signal.aborted||(_e=URL.createObjectURL(Z.blob),K({kind:"model3d",sourcePath:Z.path||P,objectUrl:_e,ext:Z.ext,meta:{size:Z.size,mimeType:Z.mimeType,modified:Z.modified}}),Ve("model3d_loaded",{bytes:Z.size,ext:Z.ext}))}).catch(Z=>{z.signal.aborted||(K({kind:"error",message:Z instanceof Error&&(Z.name==="TimeoutError"||/timed out/i.test(Z.message))?p("rightSidebar.model3dTimeout"):Z instanceof Error?Z.message:p("rightSidebar.model3dLoadFailed")}),Ve("error",{error:Z instanceof Error?Z.message:String(Z)}))});else if(os){const Z=om(P)??"",Ye=mu(P);K(Tt=>Tt.kind==="video"&&Tt.url===Ye?Tt:{kind:"video",url:Ye,meta:{size:null,mimeType:Z,modified:null}}),Ve("video_ready",{mimeType:Z})}else ud(P,z.signal,"view_file",Se).then(Z=>{if(!z.signal.aborted){if(Z.binary){K({kind:"binary"});return}K({kind:"text",content:Z.content,sourcePath:Z.path||P,meta:{size:Z.size,truncated:Z.truncated}}),Ve("text_loaded",{bytes:Z.size,truncated:!!Z.truncated})}}).catch(Z=>{z.signal.aborted||(K({kind:"error",message:Z instanceof Error?Z.message:"Failed to read file"}),Ve("error",{error:Z instanceof Error?Z.message:String(Z)}))});return()=>{z.abort(),Ct(Se),window.clearTimeout(rn),window.clearTimeout(is),_e&&URL.revokeObjectURL(_e),Ve("cleanup")}},[n,i,mr,gr,$,p,de]),a.useEffect(()=>{if(C.kind!=="model3d"||!n){F(null);return}let P=!1;const z=n.lastIndexOf("/"),ue=z>=0?n.slice(z+1):n,Se=z>=0?n.slice(0,z):"",et=Se.lastIndexOf("/"),Fe=et>=0?Se.slice(0,et):"",Ve=ue.replace(/\.(stl|glb|gltf)$/i,""),_e=`${Fe?`${Fe}/`:""}features/${Ve}.json`;return ud(_e).then(qe=>{if(!P)try{const ft=JSON.parse(qe.content);F(ft.version===1&&Array.isArray(ft.features)&&ft.features.length>0?ft.features:null)}catch{F(null)}}).catch(()=>{P||F(null)}),()=>{P=!0}},[C,n]),a.useEffect(()=>{if(C.kind!=="text"){tt(null);return}const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=ju(P),ue=C.content,Se=$s(P??"")&&pe==="preview",et=Ns(P??"")&&N==="preview";if(!z||Se||et||!Ru(ue)){tt(null);return}let Fe=!1;const Ve=_e=>{if(Fe||!_e.registered(z)){Fe||tt(null);return}try{tt(Nu(_e,ue,z))}catch{tt(null)}};return Le?Ve(Le):(tt(null),Cu().then(_e=>{Fe||(at(_e),Ve(_e))}).catch(()=>{})),()=>{Fe=!0}},[C,Le,n,i,pe,N]),a.useLayoutEffect(()=>{if(!Ke||C.kind!=="text")return;const P=`${Ke}:${pe}:${N}`;if(Ot.current===P)return;const z=ou(i,n);if(Ot.current=P,!z)return;const ue=requestAnimationFrame(()=>{const Se=re.current;if(!Se)return;const et=pe==="preview"?z.markdownTop??z.top:z.top;Se.scrollTo({top:Math.max(0,et??0),left:Math.max(0,z.left??0)}),R(pe==="preview"?Math.max(0,et??0):0)});return()=>cancelAnimationFrame(ue)},[n,pe,N,C.kind,Ke,i]),a.useEffect(()=>{Ke&&Ti(i,n,{lineRange:E})},[n,E,Ke,i]),a.useEffect(()=>{if(U==null||C.kind!=="text")return;we(null),$({start:U,end:U});const P=U,z=requestAnimationFrame(()=>{const ue=V.current.get(P);ue&&ue.scrollIntoView({block:"center"}),D?.()});return()=>cancelAnimationFrame(z)},[U,C,$,D]);const jn=a.useCallback(P=>{const z=re.current;if(!z)return!1;const ue=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Se=z.querySelector(`#${ue}`);return Se?(Se.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=C.kind==="text"&&$s(P??"")&&pe==="preview";if(!Ee||!z)return;const ue=requestAnimationFrame(()=>{jn(Ee)&&Ne(null)});return()=>cancelAnimationFrame(ue)},[n,jn,pe,Ee,C,i]),a.useLayoutEffect(()=>{const P=re.current;if(!P||!E){we(null);return}if(ie)return;const z=C.kind==="image"||C.kind==="loading"&&C.mode==="image",ue=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,Se=C.kind==="text"&&$s(ue??"")&&pe==="preview",et=C.kind==="text"&&Ns(ue??"")&&N==="preview";if(C.kind!=="text"||z||Se||et){we(null);return}const Fe=()=>{const _e=V.current.get(E.end);if(!_e||!P){we(null);return}const qe=_e.offsetTop+_e.offsetHeight/2,ft=P.scrollLeft+Math.max(8,P.clientWidth-120);we({top:qe,left:ft})};Fe();const Ve=new ResizeObserver(()=>Fe());return Ve.observe(P),()=>Ve.disconnect()},[E,ie,C,pe,N,n,i,Pe]);const Ir=C.kind==="text"&&!(Ns(pt??"")&&N==="preview")&&!pt?.toLowerCase().endsWith(".csv")&&!pt?.toLowerCase().endsWith(".kicad_pro")&&!pt?.toLowerCase().endsWith(".kicad_prl"),xr=a.useCallback(()=>{nt(!1),Ie(""),_t([]),H(0),qa()},[]),Rn=a.useCallback(()=>{Ir&&(nt(!0),requestAnimationFrame(()=>{ae.current?.focus(),ae.current?.select()}))},[Ir]),bt=a.useCallback(P=>{H(z=>ze.length===0?0:(z+P+ze.length)%ze.length)},[ze.length]);if(a.useEffect(()=>{const P=z=>{const ue=Sg(z);if(ue==="open"&&Ir){z.preventDefault(),Rn();return}rt&&(ue==="close"?(z.preventDefault(),xr()):(ue==="next"||ue==="previous")&&(z.preventDefault(),bt(ue==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[xr,rt,bt,Rn,Ir]),a.useLayoutEffect(()=>{if(qa(),!rt||!oe.trim()||!re.current){_t([]),H(0);return}const P=Rg(re.current,oe);return _t(P),H(0),Bd(P,0),Od(P[0]),qa},[rt,oe,Pe,pe,C]),a.useEffect(()=>{rt&&(Bd(ze,Bt),Od(ze[Bt]))},[Bt,ze,rt]),a.useEffect(()=>qa,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.selectFilePrompt")});const Ge=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=io(Ge,i),vr=gu(Ge,i),wr=C.kind==="text"&&C.content?C.content.split(`
1654
+ `):[],Ks=Math.max(2,String(wr.length).length)+1,yr=C.kind==="text"||C.kind==="image"||C.kind==="model3d"||C.kind==="video"||C.kind==="eda"?C.meta:null,kr=$s(Ge),Vs=Ge.toLowerCase().endsWith(".csv"),Pt=Ge.toLowerCase().endsWith(".kicad_pro"),es=Ge.toLowerCase().endsWith(".kicad_prl"),Ut=C.kind==="text"&&kr&&pe==="preview",qs=Ns(Ge),Xt=C.kind==="text"&&qs&&N==="preview",Ys=C.kind==="image"||C.kind==="loading"&&C.mode==="image",ko=C.kind==="model3d"||C.kind==="loading"&&C.mode==="model3d",Mt=C.kind==="video"||C.kind==="loading"&&C.mode==="video",Yr=C.kind==="eda"||C.kind==="loading"&&C.mode==="eda",ts=C.kind==="text"?C.sourcePath:Ge,Dr=Lm(ts,i,E),Fr=(()=>{if(!E||C.kind!=="text"||wr.length===0)return Dr;const P=[];for(let Se=E.start;Se<=E.end;Se+=1)P.push(`${Se} ${wr[Se-1]??""}`);const z=Qu(Ge).replace(/^\./,""),ue="```";return`${Dr}
1655
1655
  ${ue}${z}
1656
1656
  ${P.join(`
1657
1657
  `)}
1658
1658
  ${ue}
1659
- `})(),Sr=`path:${Ge}`,jr=E?`path:${Ge}:${E.start}-${E.end}`:Sr,_r=A===Sr,Br=A===jr,Cn=T===Sr,rs=T===jr,Xr=Br||rs,Jt=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,Or=P=>{const z=re.current;if(!z)return;const ue=z.getBoundingClientRect(),Se=P.currentTarget.getBoundingClientRect(),et=P.clientX||Se.left+Se.width/2,Ve=(P.clientY||Se.top+Se.height/2)-ue.top+z.scrollTop,_e=m?116:132,qe=z.scrollLeft+Math.max(8,z.clientWidth-_e),ft=Math.min(Math.max(8,et-ue.left+z.scrollLeft+10),qe);ye({top:Ve,left:ft})},ns=(P,z)=>{Gi()||(Or(P),$(ue=>{const Se=Ki(ue,z,z);return Se||ye(null),Se}))},ss=(P,z,ue)=>{Or(P),$(Se=>{const et=Ki(Se,z,ue);return et||ye(null),et})},Rr=(P,z,ue,Se)=>{Se==="end"&&Or(P),$({start:z,end:ue})},nr=P=>{const{scrollTop:z,scrollLeft:ue}=P.currentTarget;R(z),Pi(i,n,{top:z,left:ue,markdownTop:z})},be=P=>{if(P.directory){g?.(P.path);return}if(P.path===Ge||C.kind==="text"&&P.path===C.sourcePath){P.fragment&&jn(P.fragment);return}le(z=>[...z,Ge]),We.current=P.path,Ne(P.fragment),$(null),O(P.path)},Qt=()=>{const P=ee[ee.length-1];P&&(le(z=>z.slice(0,-1)),We.current=P,Ne(null),$(null),O(P))},Jr=P=>{const{scrollTop:z,scrollLeft:ue}=P.currentTarget;Pi(i,n,{top:z,left:ue})},Qr=()=>{if(r){r(Fr,jr);return}E&&l(Fr,jr)},as=async()=>{if(!(!Ge||Te.status==="pending")&&!(C.kind==="loading"||C.kind==="error")){ke({status:"pending"});try{await vm(Ge),ke({status:"idle"})}catch(P){ke({status:"error",message:P instanceof Error?P.message:p("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[ve.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${m&&(Ut||Xt)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[m&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p("rightSidebar.backToFileList"),title:p("rightSidebar.backToFileList"),children:e.jsx(vu,{size:16})}),ee.length>0&&e.jsxs("button",{type:"button",onClick:Qt,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${m?"w-9":"px-2.5"}`,"aria-label":p("rightSidebar.backToPreviousPreview"),title:p("rightSidebar.backToPreviousPreview"),children:[e.jsx(Bs,{size:15}),!m&&e.jsx("span",{className:"text-[11px] font-medium",children:p("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Ge,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ir&&e.jsx("button",{type:"button",onClick:rt?xr:Rn,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${rt?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":p("rightSidebar.findInFile"),title:`${p("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Qn,{size:14})}),kr&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&w?.(),De(P=>{const z=P==="preview"?"source":"preview";return At(_u,z),z}),$(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${m?"w-9 px-0":"px-3"}`,"aria-label":p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:m?pe==="preview"?e.jsx(qi,{size:14}):e.jsx(Vi,{size:14}):p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),qs&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{q(P=>{const z=P==="preview"?"source":"preview";return Hp(i,n,z),z}),$(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${m?"w-9 px-0":"px-3"}`,"aria-label":p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:m?N==="preview"?e.jsx(qi,{size:14}):e.jsx(Vi,{size:14}):p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Xt&&e.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p(Ae?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:p(Ae?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(yu,{size:15})}),!m&&e.jsx("button",{type:"button",onClick:()=>s(Ge,Sr),...ve(vr,Sr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${_r||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:p("rightSidebar.insertReference",{reference:vr}),children:p(Cn?"rightSidebar.copied":_r?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(vr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:p("rightSidebar.copyReference",{reference:vr}),"aria-label":p("rightSidebar.copyFileRef"),children:e.jsx(om,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{as()},disabled:Te.status==="pending"||C.kind==="loading"||C.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.message??p("rightSidebar.downloadFailed"):p("rightSidebar.downloadFile"),"aria-label":p("rightSidebar.downloadFile"),children:Te.status==="pending"?e.jsx(Nt,{size:13,className:"animate-spin"}):e.jsx(Lm,{size:14})})]})]}),rt&&Ir&&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(Qn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:ae,type:"search",value:oe,onChange:P=>Ie(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),bt(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:p("rightSidebar.findInFilePlaceholder"),"aria-label":p("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ze.length>0?`${Bt+1}/${ze.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>bt(-1),disabled:ze.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.previousSearchMatch"),title:`${p("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(gu,{size:13})}),e.jsx("button",{type:"button",onClick:()=>bt(1),disabled:ze.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.nextSearchMatch"),title:`${p("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Pm,{size:13})}),e.jsx("button",{type:"button",onClick:xr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":p("rightSidebar.closeFileSearch"),title:`${p("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Yt,{size:13})})]}),wr&&!(m&&(Ut||Xt))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[wr.size!==null&&e.jsx("span",{children:p("rightSidebar.byteCount",{count:wr.size.toLocaleString()})}),"truncated"in wr&&wr.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:p("rightSidebar.previewTruncated")}),"mimeType"in wr&&e.jsx("span",{children:wr.mimeType}),"dimensions"in C&&C.dimensions&&e.jsxs("span",{children:[C.dimensions.width," × ",C.dimensions.height]})]}),!(m&&(Ut||Xt))&&!ko&&C.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:Yr?p("rightSidebar.edaPickHint"):Vs?p("rightSidebar.csvTablePreview"):Pt||es?p("rightSidebar.kicadProjectPickHint"):Mt?p("rightSidebar.videoPreviewHint"):Ys?p("rightSidebar.imagePreviewHint"):Ut?E?p("rightSidebar.selectedLineHint",{lineLabel:Jt??""}):p("rightSidebar.markdownPreviewHint"):Xt?p("rightSidebar.htmlPreviewHint"):E?p("rightSidebar.selectedLineHint",{lineLabel:Jt??""}):p("rightSidebar.multiLineHint")})})]}),C.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:C.mode==="eda"?p("rightSidebar.edaLoading"):C.mode==="image"?p("rightSidebar.loadingImage"):C.mode==="model3d"?p("rightSidebar.model3dLoading"):C.mode==="video"?p("rightSidebar.loadingVideo"):"Loading file…"}):C.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:C.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:p("common.retry")})]}):C.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:p("rightSidebar.binaryPreviewHint")})}):C.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:C.meta.mimeType==="image/svg+xml"?e.jsx(Pu,{blobUrl:C.objectUrl,filePath:Ge,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(_f,{src:C.objectUrl,alt:Lt.name,vector:!1,onLoad:P=>{const z=P.currentTarget;K(ue=>ue.kind==="image"?{...ue,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ue)},onError:()=>K({kind:"error",message:p("rightSidebar.imageLoadFailed")})})}):C.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(eg,{url:C.url,onLoadError:()=>K({kind:"error",message:p("rightSidebar.videoLoadFailed")})})}):C.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ig,{blobUrl:C.objectUrl,filePath:C.sourcePath,view:C.view,board:Ge.toLowerCase().endsWith(".kicad_pcb"),onViewChange:te,onInsertAnnotation:r??u,onRefresh:Sn,interactive3d:xe?e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Kd,{blobUrl:xe.objectUrl,ext:".glb",fileName:Lt.name,filePath:xe.sourcePath,features:null,onInsertFeature:r??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:C.view==="pcb-3d"})}):void 0})}):C.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Kd,{blobUrl:C.objectUrl,ext:C.ext,fileName:Lt.name,filePath:C.sourcePath,features:L,onInsertFeature:r??u,onRefresh:Sn})})}):C.kind==="text"&&Vs?e.jsx(dg,{content:C.content,filePath:Ge,onInsertAnnotation:r??u},Ge):C.kind==="text"&&(Pt||es)?e.jsx(hg,{content:C.content,filePath:Ge,localState:es,onInsertAnnotation:r??u},Ge):Ut?e.jsxs("div",{ref:re,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:nr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Nf,{content:C.content,filePath:C.sourcePath,rootPath:i,lineRange:E,onLineRangeClick:ss,onLineRangeDrag:Rr,scrollTop:Be,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:j,onOutlineClose:w,lightboxOpen:M,lightboxCloseSignal:I,onLightboxOpen:_,onLightboxClose:B,onLocalLinkOpen:be}),E&&ie&&e.jsxs("button",{type:"button",onClick:Qr,...ve(Fr,jr),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:Ed(m,Xr),title:`Insert markdown reference: ${Dr}`,children:[e.jsx(co,{size:m?13:11}),rs?p("rightSidebar.copied"):Br?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Jt??""})]})]}):Xt?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(wg,{ref:he,src:im(Ge),title:`${Lt.name} preview`,exitFullscreenLabel:p("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Ze},`${Ge}:${mr}:${gr}`)}):C.kind==="text"?e.jsxs("div",{ref:re,onScroll:Jr,className:`${hl} 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:[yr.length>0?e.jsx("div",{className:"min-w-full",children:yr.map((P,z)=>{const ue=z+1,Se=!!(E&&ue>=E.start&&ue<=E.end),et=Pe&&Pe.length===yr.length?Pe[z]:null;return e.jsxs("div",{ref:Fe=>{Fe?V.current.set(ue,Fe):V.current.delete(ue)},role:"button","data-file-preview-line":ue,tabIndex:0,onClick:Fe=>ns(Fe,ue),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ns(Fe,ue))},style:{gridTemplateColumns:`${Ks}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${Se?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${vr}:${ue}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${Se?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ue}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:et??(P||" ")})]},z)})}):"Empty file.",E&&ie&&e.jsxs("button",{type:"button",onClick:Qr,...ve(Fr,jr),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:Ed(m,Xr),title:`Insert code reference: ${Dr}`,children:[e.jsx(co,{size:m?13:11}),rs?p("rightSidebar.copied"):Br?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Jt??""})]})]}):null]})}function sx({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:d,pinned:h=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:j,rightSidebarRepoPickerOpen:w=!1,rightSidebarRepoPickerCloseSignal:M,onOpenRightSidebarRepoPicker:I,onCloseRightSidebarRepoPicker:_,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p}){const{t:i,locale:O}=St(),[C,K]=a.useState(""),[de,te]=a.useState(null),xe=J(t=>t.rightSearchOpen),W=J(t=>t.setRightSearchOpen),X=J(t=>t.rightSidebarLayoutPreference),L=J(t=>t.setRightSidebarLayoutPreference),[F,V]=a.useState(()=>Jg()),[re,ie]=a.useState("."),[ye,pe]=a.useState(""),[De,N]=a.useState(!1),[q,he]=a.useState(!1),[Ae,Ze]=a.useState(!1),[Le,at]=a.useState(!1),Be=a.useDeferredValue(C),[R,ee]=a.useState(null),[le,Ee]=a.useState([]),[Ne,We]=a.useState([]),ce=J(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Pe=J(t=>t.setActiveGitRepo),[tt,Te]=a.useState(null),[ke,rt]=a.useState(null),[nt,oe]=a.useState(null),[Ie,ze]=a.useState(()=>mt(Ud,Ts)??!1),[_t,Bt]=a.useState(()=>mt(Hd,Ts)??!1),[H,ae]=a.useState(()=>mt(zd,Ts)??!1),[ve,Ke]=a.useState(()=>mt(Mi,Kg)??""),[pt,mr]=a.useState(0),[pr,Ot]=a.useState(!1),[gr,br]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Ir,xr]=a.useState(!1),[Rn,bt]=a.useState(null),[Ge,Lt]=a.useState(null),[vr,yr]=a.useState(()=>qd(Ci)),[Ks,wr]=a.useState(()=>qd(Od)),[kr,Vs]=a.useState(()=>Gg()),[Pt,es]=a.useState(()=>Vg()),[Ut,qs]=a.useState(()=>Yg()),Xt="words",[Ys,ko]=a.useState(0),[Mt,Yr]=a.useState([]),[ts,Dr]=a.useState([]),[Fr,Sr]=a.useState(!1),[jr,_r]=a.useState(null),[Br,Cn]=a.useState([]),[rs,Xr]=a.useState(!1),[Jt,Or]=a.useState([]),[ns,ss]=a.useState([]),[Rr,nr]=a.useState(!1),[be,Qt]=a.useState(null),[Jr,Qr]=a.useState([]),[as,P]=a.useState({}),z=a.useRef(0),[ue,Se]=a.useState(0),[et,Fe]=a.useState(!1),[Ve,_e]=a.useState(null),[qe,ft]=a.useState(null),[Nn,sr]=a.useState(null),[os,Zr]=a.useState(null),[en,Ur]=a.useState(!1),[tn,rn]=a.useState(""),is=a.useDeferredValue(tn),[Q,Ye]=a.useState({}),[Tt,ar]=a.useState([]),[Xs,ls]=a.useState(!1),[Js,cs]=a.useState(!1),[So,Mn]=a.useState(null),[jo,En]=a.useState(!1),or=a.useRef(null),Hr=a.useRef(0),Sl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Bf,Qs]=a.useState(null),[ds,jl]=a.useState(()=>mt(Ni,Ts)??!1),[Ro,Co]=a.useState(!1),[Zs,No]=a.useState([]),[Zt,ea]=a.useState({}),[Et,ta]=a.useState({}),[nn,Mo]=a.useState({}),[Rl,Cl]=a.useState(()=>new Set),[Xe,sn]=a.useState(null),[Eo,an]=a.useState(null),[Of,Cr]=a.useState(!1),[Nl,Nr]=a.useState(0),[,$o]=a.useState(0),[Ao,ra]=a.useState(!1),[ir,Lo]=a.useState(!1),[Uf,Ml]=a.useState(()=>J.getState().rightTab==="diff"),[Po,El]=a.useState(()=>J.getState().rightTab==="android"),[zr,$l]=a.useState(!1),na=yi(t=>t.docks[ki]),Hf=!!na,[Ue,us]=a.useState(null),[$n,fs]=a.useState(null),[xt,on]=a.useState(null),[Al,vt]=a.useState(null),[An,Ll]=a.useState(null),[To,zf]=a.useState(()=>Date.now()),[Wf,Gf]=a.useState(!1),[ln,sa]=a.useState(!1),[aa,Pl]=a.useState(""),[Ln,oa]=a.useState(""),[cn,ia]=a.useState(""),[dn,la]=a.useState(""),[Tl,Pn]=a.useState(null),[ca,da]=a.useState(!1),[Il,Io]=a.useState(!1),[Dl,Fl]=a.useState(!1),[ua,Kf]=a.useState({key:null,nonce:0}),_l=a.useRef(null),Bl=a.useRef(null),ne=ym(s,h,X),Do=qu(ne,h,Ut),[Fo,_o]=a.useState(()=>sb(s)),Bo=J(t=>t.rightTab),er=J(t=>t.setRightTab),x=J(t=>t.rootPath),Tn=J(t=>t.explorerRoot),Ol=J(t=>t.pinnedExplorerRootsCache),Ul=J(t=>t.hydratePinnedExplorerRoots),Hl=J(t=>t.syncPinnedExplorerRoots),Ht=J(t=>t.setExplorerRoot),zl=J(t=>t.resetExplorerToProject),In=J(t=>t.pinExplorerRoot),un=J(t=>t.unpinExplorerRoot),ot=J(t=>t.selectedFilePath),it=J(t=>t.selectFile),Oo=J(t=>t.showHiddenFiles),Vf=J(t=>t.toggleShowHiddenFiles),Uo=J(t=>!!(x&&t.nestedGitScanRoots[x])),Re=J(t=>t.changedFiles),fa=J(t=>t.setChangedFiles),ha=J(t=>t.invalidateDirectoryCache),qf=J(t=>t.setDirectorySortMode),Wl=J(t=>t.applyFileWatchEvents),Gl=J(t=>t.reconcileDirectoryCache),Kl=J(t=>t.bumpFileWatchEpoch),lr=J(t=>t.gitBundleLoading),Vl=J(t=>t.gitBundleSlow),fn=J(t=>t.gitBundleError),Dn=J(t=>t.gitBundleLastLoadedAt),ql=J(t=>t.beginGitBundleLoading),Yl=J(t=>t.setGitBundleSlowFor),Ho=J(t=>t.finishGitBundleLoading),ma=J(t=>t.resetGitBundleLoading),zo=J(t=>t.setGitBundleError),Xl=J(t=>t.markGitBundleLoaded),ge=Tn??x,Jl=a.useMemo(()=>ge?Cg(ge,re):"",[ge,re]),hs=a.useMemo(()=>Rg(ye),[ye]),Ql=a.useMemo(()=>({excludePatterns:hs,caseSensitive:q,wholeWord:Ae,regex:Le}),[q,hs,Le,Ae]),pa=J(t=>ge?t.fileSortModes[ge]??"name":"name"),Zl=J(t=>!!(ge&&t.directoryCache.has(ge))),Fn=a.useRef(null),jt=a.useRef(0),[ec]=a.useState(()=>++Qb),Mr=a.useRef(null),Wr=a.useRef(null),ga=a.useRef(0),zt=a.useRef(new Map),Wt=a.useRef(new Map),cr=a.useRef(new Set),hn=a.useRef(new Set),mn=a.useRef(0),Gr=a.useRef(null),_n=a.useRef(0),Bn=a.useRef(null),On=a.useRef(0),Kr=a.useRef(null),Wo=a.useRef(new Set),Go=a.useRef(null),Ko=a.useRef(null),ba=a.useRef(null),Vo=a.useRef(null),qo=a.useRef(null),ms=a.useRef(new Set);a.useEffect(()=>{if(An===null)return;const t=Math.max(0,Date.now()-An),o=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,c=Math.max(50,o-t%o),y=window.setTimeout(()=>zf(Date.now()),c);return()=>window.clearTimeout(y)},[To,An]);const xa=a.useRef(null),Er=a.useRef(null),Yo=a.useRef(null),tc=a.useRef(null),ps=a.useRef(null),Ce=a.useCallback(t=>J.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=o=>{const c=rx(o.target);c&&to("global_change_row_event",{...nx(o),selectionPath:c.dataset.diffSelectionPath,filePath:c.dataset.diffFilePath,absolutePath:c.dataset.diffAbsolutePath,repoRoot:c.dataset.diffRepoRoot,status:c.dataset.diffStatus,selectedFilePath:J.getState().selectedFilePath,rightTab:J.getState().rightTab,activeGitRepoRoot:ce,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})}},[ce,r]);const rc=a.useCallback(async(t=x??void 0)=>{if(!t)return null;if(cr.current.has(t)||hn.current.has(t))return dt("untracked_skip_cached",{cwd:t,rootPath:x,completed:cr.current.has(t),running:hn.current.has(t)}),null;const o=x,c=ga.current+1;ga.current=c,zt.current.set(t,c);const y=`right-sidebar-git-untracked:${t}`,v=new AbortController;Wt.current.set(t,v),hn.current.add(t),dt("untracked_start",{requestId:c,cwd:t,rootPath:x});try{let k=await ud(t,v.signal,y),S=0;for(;k.status==="running"&&S<120;){if(zt.current.get(t)!==c||v.signal.aborted)return dt("untracked_stale_result",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,status:k.status}),null;if(!Ce(o))return dt("untracked_root_changed",{requestId:c,cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath}),null;await new Promise(Z=>window.setTimeout(Z,S<10?1e3:3e3)),S+=1,k=await ud(t,v.signal,y)}if(zt.current.get(t)!==c||!Ce(o))return dt("untracked_stale_result",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,files:k.files.length,status:k.status}),null;if(k.status==="done")return fa(Af(J.getState().changedFiles,k.files)),k.files.length>0&&Ee(Z=>{const $e=new Map(Z.map(je=>[je.root,je])).get(t);if(!$e)return Z;const Je=Ob($e.files,k.files),G=Z.map(je=>je.root===t?{...je,files:Je,context:je.context?{...je.context,changedFiles:Je.map(Me=>({path:Me.path,absolutePath:Me.absolutePath,status:Me.status})),truncated:!1}:je.context,untrackedDeferred:!1}:je);We(Lf(G,x));const Y=G.find(je=>je.root===x);return Y?.context&&ee(je=>je?.root===Y.root?{...je,...Y.context}:je),G}),cr.current.add(t),dt("untracked_apply",{requestId:c,cwd:t,files:k.files.length}),k;const se=k.error||(k.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return cr.current.add(t),dt("untracked_error",{requestId:c,cwd:t,message:se,code:k.code,status:k.status}),null}catch(k){if(zt.current.get(t)!==c||!Ce(o)||hr(k))return dt("untracked_aborted",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,message:k instanceof Error?k.message:String(k)}),null;const S=k instanceof Error?k.message:"Failed to scan untracked files";return cr.current.add(t),dt("untracked_error",{requestId:c,cwd:t,message:S}),null}finally{Wt.current.get(t)===v&&Wt.current.delete(t),zt.current.get(t)===c&&zt.current.delete(t),hn.current.delete(t)}},[R,Ce,x,fa]),tr=a.useMemo(()=>{const t=new Set(Ne.map(c=>c.root)),o=Br.filter(c=>t.has(c));return o.length>0?o:ce?[ce]:[]},[ce,Br,Ne]),nc=tr.length===0,pn=a.useMemo(()=>tr.map(t=>le.find(o=>o.root===t)).filter(t=>!!t),[tr,le]),Yf=a.useMemo(()=>Ne.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[Ne]),dr=a.useCallback(async()=>{if(!x){Yr([]),Dr([]);return}const t=x,o=_n.current+1;_n.current=o,Bn.current?.abort();const c=new AbortController;Bn.current=c,Sr(Mt.length===0),_r(null);try{const y=tr.length>0?await Promise.all(tr.map(v=>fd({workspaceRoot:x,repoRoot:v},c.signal))).then(v=>({records:v.flatMap(k=>k.records),walkthroughs:v.flatMap(k=>k.walkthroughs??[])})):await fd({workspaceRoot:x},c.signal);if(_n.current!==o||!Ce(t))return;Yr(y.records),Dr(y.walkthroughs??[])}catch(y){if(_n.current!==o||!Ce(t)||hr(y))return;_r(y instanceof Error?y.message:"Failed to load change audit explanations")}finally{Bn.current===c&&(Bn.current=null),_n.current===o&&Ce(t)&&Sr(!1)}},[Mt.length,tr,Ce,x]),va=a.useCallback(async(t,o,c)=>{if(!t&&!x){Or([]),ss([]);return}const y=x,v=On.current+1;On.current=v,Kr.current?.abort();const k=new AbortController;Kr.current=k;try{const S=t?[t]:Array.from(new Set([x,...le.map(Z=>Z.root)].filter(Z=>!!Z))),se=await Promise.all(S.map(Z=>cm({repoRoot:Z,baseRef:o,branchName:c},k.signal))).then(Z=>{const me=new Map,$e=new Map;for(const Je of Z){for(const G of Je.records)me.set(G.id,G);for(const G of Je.walkthroughs??[])$e.set(G.id,G)}return{records:Array.from(me.values()),walkthroughs:Array.from($e.values())}});if(On.current!==v||!Ce(y))return;Or(se.records),ss(se.walkthroughs??[])}catch(S){if(On.current!==v||!Ce(y)||hr(S))return;console.warn("[RightSidebar] Failed to load branch explanations",S)}finally{Kr.current===k&&(Kr.current=null)}},[le,Ce,x]),Un=a.useCallback((t,o={})=>{if(!Ce(x)){dt("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:J.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}dt(t.files.length===0?"empty_bundle":"apply",{rootPath:x,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 c=Yu(t),y=t.repoFilters??[],v=t.files;const k=J.getState().changedFiles;if(!!(o.cacheOnly&&!t.cached&&t.files.length===0&&c.length===0)&&(k.size>0||le.length>0||R)){dt("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:k.size,currentRepositories:le.length});return}const se=c.some(Y=>Y.deferred);if(se&&!o.replaceWorkspace){const Y=new Set(c.filter(Me=>!Me.deferred||Me.root===x).map(Me=>Me.root));v=[...Array.from(k.values()).filter(Me=>!Y.has(gt(Me,x)??"")),...t.files]}const Z=ou(k.values(),x),me=ou(t.files,x),$e=c.some(Y=>Y.root!==x);if(!!(o.background&&!se&&!o.replaceWorkspace&&k.size>0&&(t.files.length===0&&!t.error||Z>0&&me===0&&!$e))){dt("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:k.size,nextFiles:t.files.length,currentNestedCount:Z,nextNestedCount:me,nextRepositories:c.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(o.replaceRepoRoot){const Y=Pf(k.values(),le,t,o.replaceRepoRoot,x);v=Y.files,c=Y.repositories,y=Y.repoFilters}if(fa($f(v)),Ee(Y=>{if(!se||o.replaceWorkspace)return c;const je=new Map(Y.map(Me=>[Me.root,Me]));return c.map(Me=>{const He=je.get(Me.root);return!Me.deferred||!He?Me:{...Me,available:He.available,files:He.files,context:He.context,deferred:He.deferred,untrackedDeferred:He.untrackedDeferred,error:He.error}})}),We(y),qo.current=x,o.syncActiveRepo!==!1){const{contextKey:Y,activeGitRepos:je}=J.getState(),Me=Y?je[Y]??null:null,He=o.activeRepoRoot!==void 0?o.activeRepoRoot:Me,Oe=Qg({...t,repositories:c,repoFilters:y},He);Pe(Oe)}typeof t.cacheUpdatedAt=="number"&&Ll(t.cacheUpdatedAt),ee(Y=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==x)return Y;if(!t.context)return null;const je=Y?.root??x;return!Y?.available||je!==(t.context.root??x)?t.context:{...Y,...t.context}}),o.reloadDiff&&ko(Y=>Y+1);const G=J.getState().selectedFilePath;if(G&&!G.startsWith("/")&&!v.some(Y=>Y.path===G||Y.absolutePath===G)&&it(null),yr(Y=>{const je=new Set(v.map(He=>gt(He,x)).filter(Boolean)),Me=new Set;for(const He of Y)je.has(He)&&Me.add(He);return $i(Ci,Me),Me}),o.loadDeferred!==!1){const Y=c.filter(je=>je.untrackedDeferred&&je.root).map(je=>je.root);for(const je of Y)rc(je)}o.loadAudit!==!1&&dr()},[Ce,dr,rc,x,it,Pe,fa]);a.useEffect(()=>{ma(),Go.current=null,Ko.current=x;const t=[],o=[];jt.current+=1,mn.current+=1,ga.current+=1,Mr.current?.abort(),Ct(As(Wr.current?.cwd??x??void 0)),Wr.current=null,Mr.current=null,Gr.current?.abort(),Ct("right-sidebar-git-details"),Gr.current=null;for(const S of Wt.current.values())S.abort();for(const S of Wt.current.keys())Ct(`right-sidebar-git-untracked:${S}`);Wt.current.clear(),zt.current.clear(),_n.current+=1,Bn.current?.abort(),Bn.current=null,On.current+=1,Kr.current?.abort(),Kr.current=null,Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,Yr([]),Dr([]),Sr(!1),_r(null),Cn([]),Xr(!1),Or([]),ss([]),nr(!1),Qt(null),Fe(!1),_e(null),ft(null),sr(null),Zr(null),Ur(!1),rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1),Qs(null),sn(null),an(null),jl(!1),At(Ni,!1),Co(!1);const c=x?Yd()[x]:null,y=c?.previewEntries??[],v=c?.selectedPreviewKey??null,k=v?y.find(S=>S.key===v)??null:null;++z.current,Fe(!1),No(c?.selectedRepoRoots??[]),ea(c?.repoTargetBranches??{}),ta(c?.repoBaseBranches??{}),Qr(y),P(c?.previewScrollTops??{}),k&&c?.previewDetailOpen&&(k.diff.hunks?.length??0)>0&&(Qt(k.diff),sn(k.key),an(c.selectedPreviewFileKey??(k.diff.hunks?.[0]?`${k.diff.hunks[0].filePath}\0${k.diff.hunks[0].hunkHeader}\0${k.diff.hunks[0].hunkIndex}`:null)),nr(!0)),Mo(c?.repoIncludeUncommitted??Object.fromEntries(Object.keys(c?.repoTargetBranches??{}).map(S=>[S,c?.includeUncommitted??!0]))),Go.current=x,sa(!1),cr.current.clear(),hn.current.clear(),us(null),fs(null),on(null),vt(null),Ll(null),Ee(t),We(o),ee(null),Vo.current=null,qo.current=null,ms.current.clear()},[ma,x]);const It=a.useCallback(async(t=x??void 0,o={})=>{if(!t)return null;const c=x,y=jt.current;if(await mp(()=>Promise.all([J.getState().hydrateNestedGitScanRoots(),J.getState().hydrateActiveGitRepos()]).then(()=>{})),jt.current!==y||!Ce(c))return null;const v=t===x&&Es(x),k=o.includeNested??v,S=o.refresh??o.reloadDiff??!1,se=o.cacheOnly??!1,Z=o.background??!1,me=k&&(o.discoverOnly??!1);S&&cr.current.clear();const $e=Wr.current;if($e&&$e.cwd===t&&$e.includeNested===k&&$e.refresh===S&&$e.cacheOnly===se&&$e.discoverOnly===me)return dt("reuse_pending",{cwd:t,includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me}),$e.promise;const Je=jt.current+1;jt.current=Je;const G=`right-sidebar:${ec}:${Je}`;Mr.current?.abort();const Y=As(t);Ct(Y);const je=new AbortController;Mr.current=je;let Me=null;Z||ql(G),zo(null),dt("start",{requestId:Je,cwd:t,rootPath:x,requestSlotId:Y,includeNested:k,refresh:S,cacheOnly:se,background:Z,existingChanges:Re.size,lastLoadedAt:Dn}),!Z&&typeof window<"u"&&(Me=window.setTimeout(()=>{jt.current===Je&&Yl(G,!0)},Ig));const He=(async()=>{const Oe=await wi(t,je.signal,{includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me,action:S?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Y,requestTimeoutMs:S?null:void 0});if(zb(Oe)){if(dt("cancelled_result_ignored",{requestId:Je,activeRequestId:jt.current,cwd:t,error:Oe.error??Oe.context?.error}),je.signal.aborted)return null;throw new Error(Oe.error??Oe.context?.error??"Failed to load Git changes")}return jt.current!==Je||!Ce(c)?(dt("stale_result",{requestId:Je,activeRequestId:jt.current,cwd:t,expectedRootPath:c,currentRootPath:J.getState().rootPath,files:Oe.files.length,repositories:Oe.repositories?.length??0}),null):(Un(Oe,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:k,background:Z,cacheOnly:se,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),Oe)})();Wr.current={cwd:t,includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me,promise:He};try{const Oe=await He;return jt.current===Je&&Oe&&Ce(c)?Xl({cached:Oe.cached,stale:Oe.stale,cacheAgeMs:Oe.cacheAgeMs,nestedDeferred:!k||Oe.nestedDeferred,untrackedDeferred:Oe.untrackedDeferred}):jt.current===Je&&Ce(c)&&Ho(G),Oe}catch(Oe){return jt.current!==Je||!Ce(c)||je.signal.aborted?(dt("aborted",{requestId:Je,activeRequestId:jt.current,cwd:t,expectedRootPath:c,currentRootPath:J.getState().rootPath,message:Oe instanceof Error?Oe.message:String(Oe)}),null):(dt("error",{requestId:Je,cwd:t,includeNested:k,refresh:S,background:Z,message:Oe instanceof Error?Oe.message:String(Oe)}),Z||(ee(null),zo(Oe instanceof Error?Oe.message:"Failed to load Git changes")),null)}finally{Me!==null&&window.clearTimeout(Me),Mr.current===je&&(Mr.current=null),Wr.current?.promise===He&&(Wr.current=null),!Z&&jt.current===Je&&Ce(c)&&Ho(G)}},[Un,ql,Re.size,Ho,ec,Dn,Ce,Xl,x,zo,Yl]),Hn=a.useCallback(async()=>{x&&await It(x,{reloadDiff:!0,refresh:!0})},[It,x]),Xo=a.useCallback(async(t=x??void 0)=>{if(!t)return null;const o=x,c=mn.current+1;mn.current=c,Gr.current?.abort(),Ct("right-sidebar-git-details");const y=new AbortController;Gr.current=y,sa(!0);try{const v=await hd(t,y.signal,"load_git_details","right-sidebar-git-details");return mn.current!==c||!Ce(o)?null:(Ee(k=>k.map(S=>S.root===v.root?{...S,available:v.available,context:v,error:v.error}:S)),ee(k=>k?.root&&v.root&&k.root!==v.root?k:!k?.available||!v.available?v:{...k,...v}),v)}catch(v){return hr(v)||!Ce(o)||mn.current===c&&vt(v instanceof Error?v.message:"Failed to load Git details"),null}finally{Gr.current===y&&(Gr.current=null),mn.current===c&&Ce(o)&&sa(!1)}},[Ce,x]);a.useEffect(()=>{if(!r){jt.current+=1,ma(),Vo.current=null,mn.current+=1,ga.current+=1,Mr.current?.abort(),Ct(As(Wr.current?.cwd??x??void 0)),Wr.current=null,Mr.current=null,Gr.current?.abort(),Ct("right-sidebar-git-details"),Gr.current=null;for(const t of Wt.current.values())t.abort();for(const t of Wt.current.keys())Ct(`right-sidebar-git-untracked:${t}`);Wt.current.clear(),zt.current.clear(),On.current+=1,Kr.current?.abort(),Kr.current=null,Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,sa(!1),Fe(!1),_e(null),ft(null),sr(null),Zr(null),Ur(!1),rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1),K(""),W(!1),bt(null),Lo(!1),ne&&Ml(!1)}},[ne,r,ma,W]),a.useEffect(()=>{if(!xe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[xe]),a.useEffect(()=>{ne||Cr(!1)},[ne]);const sc=a.useCallback(t=>{$o(t);const o=Yo.current;o&&(o.update(),o.slideTo(t,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(t,0)}))},[]);a.useEffect(()=>{if(ne)if(Cr(m),m&&ot){Nr(1);const t=Er.current;t&&(t.update(),t.activeIndex!==1&&(ps.current=1,t.slideTo(1,0)))}else{Nr(0);const t=Er.current;t&&t.activeIndex!==0&&(ps.current=0,t.slideTo(0,0)),bt(null)}},[ne,m,x,ot]),a.useEffect(()=>{if(b!==void 0&&!m){Nr(0);const t=Er.current;t&&t.activeIndex!==0&&(ps.current=0,t.slideTo(0,0)),Cr(!1),bt(null)}},[b,m]),a.useEffect(()=>{M!==void 0&&Te(null)},[M]),a.useEffect(()=>{!ne&&m&&j?.()},[ne,j,m]),a.useEffect(()=>{_o(t=>rl(t,s))},[s]);const Xf=a.useCallback(t=>{ne||(t.preventDefault(),xa.current={startX:t.clientX,startWidth:Fo,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Fo,ne]),Jf=a.useCallback(t=>{const o=xa.current;if(!o||o.pointerId!==t.pointerId)return;const c=rl(o.startWidth+t.clientX-o.startX,s);_o(c),Is(Ps,c,Tg)},[s]),ac=a.useCallback(t=>{const o=xa.current;if(!(!o||o.pointerId!==t.pointerId)){xa.current=null,Ms(Ps);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),zn=!!(x&&Dn!==null&&cu(R)),Jo=!!(x&&!fn&&Re.size===0&&Dn===null),ur=(()=>{let t=Bo;return t==="android"&&!zr&&(t="files"),zn&&(t==="git"||t==="diff")&&(t="files"),t})(),lt=ur==="git",Wn=ur==="files",Rt=ur==="diff",Gn=ur==="android",Qf=Tm(t=>t.overlay==="sidebar")&&Gn;a.useEffect(()=>{if(!ne){ra(!0);return}if(!r){const o=window.setTimeout(()=>{ra(!1)},_g);return()=>window.clearTimeout(o)}ra(!1);const t=window.setTimeout(()=>{ra(!0)},Fg);return()=>window.clearTimeout(t)},[ne,r]),a.useEffect(()=>{if(!ne||!Rt)return;const t=Yo.current;if(!t)return;const o=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(o)},[Rt,ne]),a.useEffect(()=>{if(!zn||!x||lr)return;const t=window.setTimeout(()=>{It(x,{background:!0})},3e3);return()=>window.clearTimeout(t)},[zn,x,lr,It]);const Zf=a.useCallback(t=>{It(t,{discoverOnly:!0})},[It]);pp({active:r&&(lt||Rt),rootPath:x,loading:lr,delay:lt&&!ne?0:Ei,lastStartedRoot:Vo,load:Zf}),a.useEffect(()=>{!r||!lt||(!ne||Ao)&&Lo(!0)},[lt,ne,r,Ao]),a.useEffect(()=>{if(!r||lt)return;const t=window.setTimeout(()=>{Lo(!0)},Ei);return()=>window.clearTimeout(t)},[lt,r]),a.useEffect(()=>{Rt&&Ml(!0)},[Rt]),a.useEffect(()=>{!r||!Gn||(n&&na&&na.sessionId!==n&&(yi.getState().setDock(ki,null),ro({androidPanel:{docked:null}}).catch(()=>{})),El(!0))},[Gn,r,n,na]),a.useEffect(()=>{if(r&&Gn||!Po)return;const t=window.setTimeout(()=>El(!1),Dg);return()=>window.clearTimeout(t)},[r,Gn,Po]),a.useEffect(()=>{let t=!1;return uu().then(o=>{!t&&o.androidPanel&&$l(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const eh=a.useCallback(t=>{$l(t),t?er("android"):J.getState().rightTab==="android"&&er("files"),ro({androidPanel:{enabled:t}}).catch(()=>{})},[er]),oc=a.useCallback(t=>{ge&&Ib(ge,t.currentTarget.scrollTop)},[ge]);a.useEffect(()=>()=>{Mr.current?.abort(),Ms(ul),Ms(fl),Ms(Ps),Ms(Mi)},[]),a.useEffect(()=>{if(!ge||!Zl)return;const t=Mf()[ge]?.top;if(typeof t!="number")return;let o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=t),o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(o)},[ge,Zl]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return dm(t.signal).then(o=>Fl(!!o.available)).catch(()=>Fl(!1)),()=>t.abort()},[r]);const gs=a.useCallback(t=>{if(te(null),it(t),bt(null),ne){Cr(!0),Nr(1),Er.current?.slideTo(1),f?.();return}},[ne,f,it]),ic=a.useCallback((t,o)=>{if(te(null),it(t),Lt(o),ne){Cr(!0),Nr(1),Er.current?.slideTo(1),f?.();return}},[ne,f,it]),bs=a.useCallback(async(t,o)=>{const c=o||Tn||x;if(!(!c||t.length===0)){da(!0);try{await Ha(c,t),ha(c,!1)}catch(y){vt(y instanceof Error?y.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>vt(null),4e3)}finally{da(!1)}}},[Tn,x,ha,i]),lc=a.useCallback(async t=>{try{await um(t)}catch(o){vt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>vt(null),4e3)}},[i]),ya=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Io(!0)},[]),cc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Io(!1)},[]),dc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Io(!1);const o=t.dataTransfer.files;o.length>0&&bs(Array.from(o))},[bs]),Qo=a.useCallback(t=>{rt(t),window.setTimeout(()=>rt(o=>o===t?null:o),1400)},[]),$r=a.useCallback(t=>{oe(t),window.setTimeout(()=>oe(o=>o===t?null:o),1400)},[]);a.useEffect(()=>{At(Ud,Ie)},[Ie]),a.useEffect(()=>{At(Hd,_t)},[_t]),a.useEffect(()=>{At(zd,H)},[H]),a.useEffect(()=>{Is(Mi,ve,Eg)},[ve]),a.useEffect(()=>(Ul().catch(()=>{}),md(t=>{t.type==="pinned-explorer-roots"&&Hl(t.pinnedExplorerRoots)})),[Ul,Hl]);const uc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),wa=a.useRef(null),gn=a.useRef(null),[fc,Zo]=a.useState(!1);a.useEffect(()=>{if(!r)return;Zo(!1);let t=!1;fm().then(c=>{t||(wa.current=c.text,Ke(y=>c.text&&c.text!==y?c.text:y),Zo(!0))}).catch(()=>{t||Zo(!0)});const o=md(c=>{c.type==="context-draft"&&c.origin!==uc.current&&(wa.current=c.text,Ke(c.text))});return()=>{t=!0,o(),gn.current!==null&&(window.clearTimeout(gn.current),gn.current=null)}},[r]),a.useEffect(()=>{if(!fc||wa.current===ve)return;gn.current!==null&&window.clearTimeout(gn.current);const t=ve;gn.current=window.setTimeout(()=>{gn.current=null,hm(t,uc.current).then(()=>{wa.current=t}).catch(()=>{})},500)},[ve,fc]);const Kn=a.useCallback((t,o,c)=>{if(t){if(mm(c?t+c:t)){Qo(o);return}Ie?(Ke(y=>Bp(y,t)+(c??"")),window.matchMedia("(pointer: coarse)").matches||(Bt(!1),mr(y=>y+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:c?t+c:t,focus:!0}})),Qo(o)}},[Ie,Qo]),ka=a.useCallback(t=>{const o=wn(t,x);return Im(o,x)},[x]),ei=Nu($r),Gt=a.useCallback((t,o)=>{const c=wn(t,x);Kn(Dm(c,x),o??`path:${c}`)},[x,Kn]),th=a.useCallback(async t=>{da(!0);try{await Fm(t,Ha,o=>{Gt(o,`path:${o}`)}),ne&&!Ie&&l()}catch(o){vt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>vt(null),4e3)}finally{da(!1)}},[Ie,Gt,ne,l,i]),Sa=a.useRef(!0),ti=a.useRef(n);ti.current=n,a.useEffect(()=>(Sa.current=!0,()=>{Sa.current=!1}),[]);const rh=a.useCallback(t=>{_m.getState().enqueue(t,n??null,x||"/",o=>{if(Ie&&Sa.current&&ti.current===n)Gt(o);else return wd(o,n)})},[n,x,Ie,Gt]),nh=a.useCallback(async t=>{const c=(await Ha("/tmp",[t])).files[0]?.path;if(!c)throw new Error("截图上传未返回文件路径");Ie&&Sa.current&&ti.current===n?Gt(c):await wd(c,n)},[Ie,Gt,n]),Ar=a.useCallback((t,o)=>{if(!t)return;const c=t.includes(`
1659
+ `})(),Sr=`path:${Ge}`,jr=E?`path:${Ge}:${E.start}-${E.end}`:Sr,_r=A===Sr,Br=A===jr,Cn=T===Sr,rs=T===jr,Xr=Br||rs,Jt=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,Or=P=>{const z=re.current;if(!z)return;const ue=z.getBoundingClientRect(),Se=P.currentTarget.getBoundingClientRect(),et=P.clientX||Se.left+Se.width/2,Ve=(P.clientY||Se.top+Se.height/2)-ue.top+z.scrollTop,_e=m?116:132,qe=z.scrollLeft+Math.max(8,z.clientWidth-_e),ft=Math.min(Math.max(8,et-ue.left+z.scrollLeft+10),qe);we({top:Ve,left:ft})},ns=(P,z)=>{Ki()||(Or(P),$(ue=>{const Se=Vi(ue,z,z);return Se||we(null),Se}))},ss=(P,z,ue)=>{Or(P),$(Se=>{const et=Vi(Se,z,ue);return et||we(null),et})},Rr=(P,z,ue,Se)=>{Se==="end"&&Or(P),$({start:z,end:ue})},nr=P=>{const{scrollTop:z,scrollLeft:ue}=P.currentTarget;R(z),Ti(i,n,{top:z,left:ue,markdownTop:z})},be=P=>{if(P.directory){g?.(P.path);return}if(P.path===Ge||C.kind==="text"&&P.path===C.sourcePath){P.fragment&&jn(P.fragment);return}le(z=>[...z,Ge]),We.current=P.path,Ne(P.fragment),$(null),O(P.path)},Zt=()=>{const P=ee[ee.length-1];P&&(le(z=>z.slice(0,-1)),We.current=P,Ne(null),$(null),O(P))},Jr=P=>{const{scrollTop:z,scrollLeft:ue}=P.currentTarget;Ti(i,n,{top:z,left:ue})},Zr=()=>{if(r){r(Fr,jr);return}E&&l(Fr,jr)},as=async()=>{if(!(!Ge||Te.status==="pending")&&!(C.kind==="loading"||C.kind==="error")){ke({status:"pending"});try{await wm(Ge),ke({status:"idle"})}catch(P){ke({status:"error",message:P instanceof Error?P.message:p("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[ve.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${m&&(Ut||Xt)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[m&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p("rightSidebar.backToFileList"),title:p("rightSidebar.backToFileList"),children:e.jsx(wu,{size:16})}),ee.length>0&&e.jsxs("button",{type:"button",onClick:Zt,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${m?"w-9":"px-2.5"}`,"aria-label":p("rightSidebar.backToPreviousPreview"),title:p("rightSidebar.backToPreviousPreview"),children:[e.jsx(Bs,{size:15}),!m&&e.jsx("span",{className:"text-[11px] font-medium",children:p("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Ge,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ir&&e.jsx("button",{type:"button",onClick:rt?xr:Rn,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${rt?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":p("rightSidebar.findInFile"),title:`${p("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Zn,{size:14})}),kr&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&y?.(),De(P=>{const z=P==="preview"?"source":"preview";return At(Bu,z),z}),$(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${m?"w-9 px-0":"px-3"}`,"aria-label":p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:m?pe==="preview"?e.jsx(Yi,{size:14}):e.jsx(qi,{size:14}):p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),qs&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{q(P=>{const z=P==="preview"?"source":"preview";return zp(i,n,z),z}),$(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${m?"w-9 px-0":"px-3"}`,"aria-label":p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:m?N==="preview"?e.jsx(Yi,{size:14}):e.jsx(qi,{size:14}):p(N==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),Xt&&e.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p(Ae?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:p(Ae?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(yu,{size:15})}),!m&&e.jsx("button",{type:"button",onClick:()=>s(Ge,Sr),...ve(vr,Sr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${_r||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:p("rightSidebar.insertReference",{reference:vr}),children:p(Cn?"rightSidebar.copied":_r?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(vr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:p("rightSidebar.copyReference",{reference:vr}),"aria-label":p("rightSidebar.copyFileRef"),children:e.jsx(im,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{as()},disabled:Te.status==="pending"||C.kind==="loading"||C.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.message??p("rightSidebar.downloadFailed"):p("rightSidebar.downloadFile"),"aria-label":p("rightSidebar.downloadFile"),children:Te.status==="pending"?e.jsx(Nt,{size:13,className:"animate-spin"}):e.jsx(Pm,{size:14})})]})]}),rt&&Ir&&e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:ae,type:"search",value:oe,onChange:P=>Ie(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),bt(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:p("rightSidebar.findInFilePlaceholder"),"aria-label":p("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ze.length>0?`${Bt+1}/${ze.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>bt(-1),disabled:ze.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.previousSearchMatch"),title:`${p("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(bu,{size:13})}),e.jsx("button",{type:"button",onClick:()=>bt(1),disabled:ze.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.nextSearchMatch"),title:`${p("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Tm,{size:13})}),e.jsx("button",{type:"button",onClick:xr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":p("rightSidebar.closeFileSearch"),title:`${p("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Yt,{size:13})})]}),yr&&!(m&&(Ut||Xt))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[yr.size!==null&&e.jsx("span",{children:p("rightSidebar.byteCount",{count:yr.size.toLocaleString()})}),"truncated"in yr&&yr.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:p("rightSidebar.previewTruncated")}),"mimeType"in yr&&e.jsx("span",{children:yr.mimeType}),"dimensions"in C&&C.dimensions&&e.jsxs("span",{children:[C.dimensions.width," × ",C.dimensions.height]})]}),!(m&&(Ut||Xt))&&!ko&&C.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:Yr?p("rightSidebar.edaPickHint"):Vs?p("rightSidebar.csvTablePreview"):Pt||es?p("rightSidebar.kicadProjectPickHint"):Mt?p("rightSidebar.videoPreviewHint"):Ys?p("rightSidebar.imagePreviewHint"):Ut?E?p("rightSidebar.selectedLineHint",{lineLabel:Jt??""}):p("rightSidebar.markdownPreviewHint"):Xt?p("rightSidebar.htmlPreviewHint"):E?p("rightSidebar.selectedLineHint",{lineLabel:Jt??""}):p("rightSidebar.multiLineHint")})})]}),C.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8",children:e.jsx(wi,{label:C.mode==="eda"?p("rightSidebar.edaLoading"):C.mode==="image"?p("rightSidebar.loadingImage"):C.mode==="model3d"?p("rightSidebar.model3dLoading"):C.mode==="video"?p("rightSidebar.loadingVideo"):p("common.loading")})}):C.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:C.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:p("common.retry")})]}):C.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:p("rightSidebar.binaryPreviewHint")})}):C.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:C.meta.mimeType==="image/svg+xml"?e.jsx(Tu,{blobUrl:C.objectUrl,filePath:Ge,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(Bf,{src:C.objectUrl,alt:Lt.name,vector:!1,onLoad:P=>{const z=P.currentTarget;K(ue=>ue.kind==="image"?{...ue,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ue)},onError:()=>K({kind:"error",message:p("rightSidebar.imageLoadFailed")})})}):C.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(tg,{url:C.url,onLoadError:()=>K({kind:"error",message:p("rightSidebar.videoLoadFailed")})})}):C.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(lg,{blobUrl:C.objectUrl,filePath:C.sourcePath,view:C.view,board:Ge.toLowerCase().endsWith(".kicad_pcb"),onViewChange:te,onInsertAnnotation:r??u,onRefresh:Sn,interactive3d:xe?e.jsx(a.Suspense,{fallback:e.jsx(wi,{label:p("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Vd,{blobUrl:xe.objectUrl,ext:".glb",fileName:Lt.name,filePath:xe.sourcePath,features:null,onInsertFeature:r??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:C.view==="pcb-3d"})}):void 0})}):C.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(wi,{label:p("rightSidebar.model3dLoading"),className:"min-h-0 flex-1 px-3 py-8"}),children:e.jsx(Vd,{blobUrl:C.objectUrl,ext:C.ext,fileName:Lt.name,filePath:C.sourcePath,features:L,onInsertFeature:r??u,onRefresh:Sn})})}):C.kind==="text"&&Vs?e.jsx(ug,{content:C.content,filePath:Ge,onInsertAnnotation:r??u},Ge):C.kind==="text"&&(Pt||es)?e.jsx(mg,{content:C.content,filePath:Ge,localState:es,onInsertAnnotation:r??u},Ge):Ut?e.jsxs("div",{ref:re,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:nr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Mf,{content:C.content,filePath:C.sourcePath,rootPath:i,lineRange:E,onLineRangeClick:ss,onLineRangeDrag:Rr,scrollTop:Be,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:j,onOutlineClose:y,lightboxOpen:M,lightboxCloseSignal:I,onLightboxOpen:_,onLightboxClose:B,onLocalLinkOpen:be}),E&&ie&&e.jsxs("button",{type:"button",onClick:Zr,...ve(Fr,jr),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:$d(m,Xr),title:`Insert markdown reference: ${Dr}`,children:[e.jsx(co,{size:m?13:11}),rs?p("rightSidebar.copied"):Br?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Jt??""})]})]}):Xt?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(kg,{ref:he,src:lm(Ge),title:`${Lt.name} preview`,exitFullscreenLabel:p("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Qe},`${Ge}:${mr}:${gr}`)}):C.kind==="text"?e.jsxs("div",{ref:re,onScroll:Jr,className:`${ml} 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:[wr.length>0?e.jsx("div",{className:"min-w-full",children:wr.map((P,z)=>{const ue=z+1,Se=!!(E&&ue>=E.start&&ue<=E.end),et=Pe&&Pe.length===wr.length?Pe[z]:null;return e.jsxs("div",{ref:Fe=>{Fe?V.current.set(ue,Fe):V.current.delete(ue)},role:"button","data-file-preview-line":ue,tabIndex:0,onClick:Fe=>ns(Fe,ue),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ns(Fe,ue))},style:{gridTemplateColumns:`${Ks}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${Se?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${vr}:${ue}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${Se?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ue}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:et??(P||" ")})]},z)})}):"Empty file.",E&&ie&&e.jsxs("button",{type:"button",onClick:Zr,...ve(Fr,jr),style:{top:ie.top,left:ie.left,transform:"translateY(-50%)"},className:$d(m,Xr),title:`Insert code reference: ${Dr}`,children:[e.jsx(co,{size:m?13:11}),rs?p("rightSidebar.copied"):Br?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Jt??""})]})]}):null]})}function ax({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:d,pinned:h=!1,onTogglePinned:g,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:j,rightSidebarRepoPickerOpen:y=!1,rightSidebarRepoPickerCloseSignal:M,onOpenRightSidebarRepoPicker:I,onCloseRightSidebarRepoPicker:_,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p}){const{t:i,locale:O}=St(),[C,K]=a.useState(""),[de,te]=a.useState(null),xe=J(t=>t.rightSearchOpen),W=J(t=>t.setRightSearchOpen),X=J(t=>t.rightSidebarLayoutPreference),L=J(t=>t.setRightSidebarLayoutPreference),[F,V]=a.useState(()=>Zg()),[re,ie]=a.useState("."),[we,pe]=a.useState(""),[De,N]=a.useState(!1),[q,he]=a.useState(!1),[Ae,Qe]=a.useState(!1),[Le,at]=a.useState(!1),Be=a.useDeferredValue(C),[R,ee]=a.useState(null),[le,Ee]=a.useState([]),[Ne,We]=a.useState([]),ce=J(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Pe=J(t=>t.setActiveGitRepo),[tt,Te]=a.useState(null),[ke,rt]=a.useState(null),[nt,oe]=a.useState(null),[Ie,ze]=a.useState(()=>mt(Hd,Ts)??!1),[_t,Bt]=a.useState(()=>mt(zd,Ts)??!1),[H,ae]=a.useState(()=>mt(Wd,Ts)??!1),[ve,Ke]=a.useState(()=>mt(Ei,Vg)??""),[pt,mr]=a.useState(0),[pr,Ot]=a.useState(!1),[gr,br]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Ir,xr]=a.useState(!1),[Rn,bt]=a.useState(null),[Ge,Lt]=a.useState(null),[vr,wr]=a.useState(()=>Yd(Ni)),[Ks,yr]=a.useState(()=>Yd(Ud)),[kr,Vs]=a.useState(()=>Kg()),[Pt,es]=a.useState(()=>qg()),[Ut,qs]=a.useState(()=>Xg()),Xt="words",[Ys,ko]=a.useState(0),[Mt,Yr]=a.useState([]),[ts,Dr]=a.useState([]),[Fr,Sr]=a.useState(!1),[jr,_r]=a.useState(null),[Br,Cn]=a.useState([]),[rs,Xr]=a.useState(!1),[Jt,Or]=a.useState([]),[ns,ss]=a.useState([]),[Rr,nr]=a.useState(!1),[be,Zt]=a.useState(null),[Jr,Zr]=a.useState([]),[as,P]=a.useState({}),z=a.useRef(0),[ue,Se]=a.useState(0),[et,Fe]=a.useState(!1),[Ve,_e]=a.useState(null),[qe,ft]=a.useState(null),[Nn,sr]=a.useState(null),[os,Qr]=a.useState(null),[en,Ur]=a.useState(!1),[tn,rn]=a.useState(""),is=a.useDeferredValue(tn),[Z,Ye]=a.useState({}),[Tt,ar]=a.useState([]),[Xs,ls]=a.useState(!1),[Js,cs]=a.useState(!1),[So,Mn]=a.useState(null),[jo,En]=a.useState(!1),or=a.useRef(null),Hr=a.useRef(0),jl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Of,Zs]=a.useState(null),[ds,Rl]=a.useState(()=>mt(Mi,Ts)??!1),[Ro,Co]=a.useState(!1),[Qs,No]=a.useState([]),[Qt,ea]=a.useState({}),[Et,ta]=a.useState({}),[nn,Mo]=a.useState({}),[Cl,Nl]=a.useState(()=>new Set),[Xe,sn]=a.useState(null),[Eo,an]=a.useState(null),[Uf,Cr]=a.useState(!1),[Ml,Nr]=a.useState(0),[,$o]=a.useState(0),[Ao,ra]=a.useState(!1),[ir,Lo]=a.useState(!1),[Hf,El]=a.useState(()=>J.getState().rightTab==="diff"),[Po,$l]=a.useState(()=>J.getState().rightTab==="android"),[zr,Al]=a.useState(!1),na=yi(t=>t.docks[Si]),zf=!!na,[Ue,us]=a.useState(null),[$n,fs]=a.useState(null),[xt,on]=a.useState(null),[Ll,vt]=a.useState(null),[An,Pl]=a.useState(null),[To,Wf]=a.useState(()=>Date.now()),[Gf,Kf]=a.useState(!1),[ln,sa]=a.useState(!1),[aa,Tl]=a.useState(""),[Ln,oa]=a.useState(""),[cn,ia]=a.useState(""),[dn,la]=a.useState(""),[Il,Pn]=a.useState(null),[ca,da]=a.useState(!1),[Dl,Io]=a.useState(!1),[Fl,_l]=a.useState(!1),[ua,Vf]=a.useState({key:null,nonce:0}),Bl=a.useRef(null),Ol=a.useRef(null),ne=ym(s,h,X),Do=Yu(ne,h,Ut),[Fo,_o]=a.useState(()=>ab(s)),Bo=J(t=>t.rightTab),er=J(t=>t.setRightTab),x=J(t=>t.rootPath),Tn=J(t=>t.explorerRoot),Ul=J(t=>t.pinnedExplorerRootsCache),Hl=J(t=>t.hydratePinnedExplorerRoots),zl=J(t=>t.syncPinnedExplorerRoots),Ht=J(t=>t.setExplorerRoot),Wl=J(t=>t.resetExplorerToProject),In=J(t=>t.pinExplorerRoot),un=J(t=>t.unpinExplorerRoot),ot=J(t=>t.selectedFilePath),it=J(t=>t.selectFile),Oo=J(t=>t.showHiddenFiles),qf=J(t=>t.toggleShowHiddenFiles),Uo=J(t=>!!(x&&t.nestedGitScanRoots[x])),Re=J(t=>t.changedFiles),fa=J(t=>t.setChangedFiles),ha=J(t=>t.invalidateDirectoryCache),Yf=J(t=>t.setDirectorySortMode),Gl=J(t=>t.applyFileWatchEvents),Kl=J(t=>t.reconcileDirectoryCache),Vl=J(t=>t.bumpFileWatchEpoch),lr=J(t=>t.gitBundleLoading),ql=J(t=>t.gitBundleSlow),fn=J(t=>t.gitBundleError),Dn=J(t=>t.gitBundleLastLoadedAt),Yl=J(t=>t.beginGitBundleLoading),Xl=J(t=>t.setGitBundleSlowFor),Ho=J(t=>t.finishGitBundleLoading),ma=J(t=>t.resetGitBundleLoading),zo=J(t=>t.setGitBundleError),Jl=J(t=>t.markGitBundleLoaded),ge=Tn??x,Zl=a.useMemo(()=>ge?Ng(ge,re):"",[ge,re]),hs=a.useMemo(()=>Cg(we),[we]),Ql=a.useMemo(()=>({excludePatterns:hs,caseSensitive:q,wholeWord:Ae,regex:Le}),[q,hs,Le,Ae]),pa=J(t=>ge?t.fileSortModes[ge]??"name":"name"),ec=J(t=>!!(ge&&t.directoryCache.has(ge))),Fn=a.useRef(null),jt=a.useRef(0),[tc]=a.useState(()=>++Qb),Mr=a.useRef(null),Wr=a.useRef(null),ga=a.useRef(0),zt=a.useRef(new Map),Wt=a.useRef(new Map),cr=a.useRef(new Set),hn=a.useRef(new Set),mn=a.useRef(0),Gr=a.useRef(null),_n=a.useRef(0),Bn=a.useRef(null),On=a.useRef(0),Kr=a.useRef(null),Wo=a.useRef(new Set),Go=a.useRef(null),Ko=a.useRef(null),ba=a.useRef(null),Vo=a.useRef(null),qo=a.useRef(null),ms=a.useRef(new Set);a.useEffect(()=>{if(An===null)return;const t=Math.max(0,Date.now()-An),o=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,c=Math.max(50,o-t%o),w=window.setTimeout(()=>Wf(Date.now()),c);return()=>window.clearTimeout(w)},[To,An]);const xa=a.useRef(null),Er=a.useRef(null),Yo=a.useRef(null),rc=a.useRef(null),ps=a.useRef(null),Ce=a.useCallback(t=>J.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=o=>{const c=nx(o.target);c&&to("global_change_row_event",{...sx(o),selectionPath:c.dataset.diffSelectionPath,filePath:c.dataset.diffFilePath,absolutePath:c.dataset.diffAbsolutePath,repoRoot:c.dataset.diffRepoRoot,status:c.dataset.diffStatus,selectedFilePath:J.getState().selectedFilePath,rightTab:J.getState().rightTab,activeGitRepoRoot:ce,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})}},[ce,r]);const nc=a.useCallback(async(t=x??void 0)=>{if(!t)return null;if(cr.current.has(t)||hn.current.has(t))return dt("untracked_skip_cached",{cwd:t,rootPath:x,completed:cr.current.has(t),running:hn.current.has(t)}),null;const o=x,c=ga.current+1;ga.current=c,zt.current.set(t,c);const w=`right-sidebar-git-untracked:${t}`,v=new AbortController;Wt.current.set(t,v),hn.current.add(t),dt("untracked_start",{requestId:c,cwd:t,rootPath:x});try{let k=await fd(t,v.signal,w),S=0;for(;k.status==="running"&&S<120;){if(zt.current.get(t)!==c||v.signal.aborted)return dt("untracked_stale_result",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,status:k.status}),null;if(!Ce(o))return dt("untracked_root_changed",{requestId:c,cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath}),null;await new Promise(Q=>window.setTimeout(Q,S<10?1e3:3e3)),S+=1,k=await fd(t,v.signal,w)}if(zt.current.get(t)!==c||!Ce(o))return dt("untracked_stale_result",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,files:k.files.length,status:k.status}),null;if(k.status==="done")return fa(Lf(J.getState().changedFiles,k.files)),k.files.length>0&&Ee(Q=>{const $e=new Map(Q.map(je=>[je.root,je])).get(t);if(!$e)return Q;const Je=Ub($e.files,k.files),G=Q.map(je=>je.root===t?{...je,files:Je,context:je.context?{...je.context,changedFiles:Je.map(Me=>({path:Me.path,absolutePath:Me.absolutePath,status:Me.status})),truncated:!1}:je.context,untrackedDeferred:!1}:je);We(Pf(G,x));const Y=G.find(je=>je.root===x);return Y?.context&&ee(je=>je?.root===Y.root?{...je,...Y.context}:je),G}),cr.current.add(t),dt("untracked_apply",{requestId:c,cwd:t,files:k.files.length}),k;const se=k.error||(k.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return cr.current.add(t),dt("untracked_error",{requestId:c,cwd:t,message:se,code:k.code,status:k.status}),null}catch(k){if(zt.current.get(t)!==c||!Ce(o)||hr(k))return dt("untracked_aborted",{requestId:c,activeRequestId:zt.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,message:k instanceof Error?k.message:String(k)}),null;const S=k instanceof Error?k.message:"Failed to scan untracked files";return cr.current.add(t),dt("untracked_error",{requestId:c,cwd:t,message:S}),null}finally{Wt.current.get(t)===v&&Wt.current.delete(t),zt.current.get(t)===c&&zt.current.delete(t),hn.current.delete(t)}},[R,Ce,x,fa]),tr=a.useMemo(()=>{const t=new Set(Ne.map(c=>c.root)),o=Br.filter(c=>t.has(c));return o.length>0?o:ce?[ce]:[]},[ce,Br,Ne]),sc=tr.length===0,pn=a.useMemo(()=>tr.map(t=>le.find(o=>o.root===t)).filter(t=>!!t),[tr,le]),Xf=a.useMemo(()=>Ne.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[Ne]),dr=a.useCallback(async()=>{if(!x){Yr([]),Dr([]);return}const t=x,o=_n.current+1;_n.current=o,Bn.current?.abort();const c=new AbortController;Bn.current=c,Sr(Mt.length===0),_r(null);try{const w=tr.length>0?await Promise.all(tr.map(v=>hd({workspaceRoot:x,repoRoot:v},c.signal))).then(v=>({records:v.flatMap(k=>k.records),walkthroughs:v.flatMap(k=>k.walkthroughs??[])})):await hd({workspaceRoot:x},c.signal);if(_n.current!==o||!Ce(t))return;Yr(w.records),Dr(w.walkthroughs??[])}catch(w){if(_n.current!==o||!Ce(t)||hr(w))return;_r(w instanceof Error?w.message:"Failed to load change audit explanations")}finally{Bn.current===c&&(Bn.current=null),_n.current===o&&Ce(t)&&Sr(!1)}},[Mt.length,tr,Ce,x]),va=a.useCallback(async(t,o,c)=>{if(!t&&!x){Or([]),ss([]);return}const w=x,v=On.current+1;On.current=v,Kr.current?.abort();const k=new AbortController;Kr.current=k;try{const S=t?[t]:Array.from(new Set([x,...le.map(Q=>Q.root)].filter(Q=>!!Q))),se=await Promise.all(S.map(Q=>dm({repoRoot:Q,baseRef:o,branchName:c},k.signal))).then(Q=>{const me=new Map,$e=new Map;for(const Je of Q){for(const G of Je.records)me.set(G.id,G);for(const G of Je.walkthroughs??[])$e.set(G.id,G)}return{records:Array.from(me.values()),walkthroughs:Array.from($e.values())}});if(On.current!==v||!Ce(w))return;Or(se.records),ss(se.walkthroughs??[])}catch(S){if(On.current!==v||!Ce(w)||hr(S))return;console.warn("[RightSidebar] Failed to load branch explanations",S)}finally{Kr.current===k&&(Kr.current=null)}},[le,Ce,x]),Un=a.useCallback((t,o={})=>{if(!Ce(x)){dt("apply_skipped_root_changed",{expectedRootPath:x,currentRootPath:J.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}dt(t.files.length===0?"empty_bundle":"apply",{rootPath:x,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 c=Xu(t),w=t.repoFilters??[],v=t.files;const k=J.getState().changedFiles;if(!!(o.cacheOnly&&!t.cached&&t.files.length===0&&c.length===0)&&(k.size>0||le.length>0||R)){dt("cache_only_apply_skipped_empty_backend_cache",{rootPath:x,currentFiles:k.size,currentRepositories:le.length});return}const se=c.some(Y=>Y.deferred);if(se&&!o.replaceWorkspace){const Y=new Set(c.filter(Me=>!Me.deferred||Me.root===x).map(Me=>Me.root));v=[...Array.from(k.values()).filter(Me=>!Y.has(gt(Me,x)??"")),...t.files]}const Q=iu(k.values(),x),me=iu(t.files,x),$e=c.some(Y=>Y.root!==x);if(!!(o.background&&!se&&!o.replaceWorkspace&&k.size>0&&(t.files.length===0&&!t.error||Q>0&&me===0&&!$e))){dt("background_apply_skipped_degraded_bundle",{rootPath:x,currentFiles:k.size,nextFiles:t.files.length,currentNestedCount:Q,nextNestedCount:me,nextRepositories:c.map(Y=>({root:Y.root,relativeRoot:Y.relativeRoot,files:Y.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(o.replaceRepoRoot){const Y=Tf(k.values(),le,t,o.replaceRepoRoot,x);v=Y.files,c=Y.repositories,w=Y.repoFilters}if(fa(Af(v)),Ee(Y=>{if(!se||o.replaceWorkspace)return c;const je=new Map(Y.map(Me=>[Me.root,Me]));return c.map(Me=>{const He=je.get(Me.root);return!Me.deferred||!He?Me:{...Me,available:He.available,files:He.files,context:He.context,deferred:He.deferred,untrackedDeferred:He.untrackedDeferred,error:He.error}})}),We(w),qo.current=x,o.syncActiveRepo!==!1){const{contextKey:Y,activeGitRepos:je}=J.getState(),Me=Y?je[Y]??null:null,He=o.activeRepoRoot!==void 0?o.activeRepoRoot:Me,Oe=Qg({...t,repositories:c,repoFilters:w},He);Pe(Oe)}typeof t.cacheUpdatedAt=="number"&&Pl(t.cacheUpdatedAt),ee(Y=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==x)return Y;if(!t.context)return null;const je=Y?.root??x;return!Y?.available||je!==(t.context.root??x)?t.context:{...Y,...t.context}}),o.reloadDiff&&ko(Y=>Y+1);const G=J.getState().selectedFilePath;if(G&&!G.startsWith("/")&&!v.some(Y=>Y.path===G||Y.absolutePath===G)&&it(null),wr(Y=>{const je=new Set(v.map(He=>gt(He,x)).filter(Boolean)),Me=new Set;for(const He of Y)je.has(He)&&Me.add(He);return Ai(Ni,Me),Me}),o.loadDeferred!==!1){const Y=c.filter(je=>je.untrackedDeferred&&je.root).map(je=>je.root);for(const je of Y)nc(je)}o.loadAudit!==!1&&dr()},[Ce,dr,nc,x,it,Pe,fa]);a.useEffect(()=>{ma(),Go.current=null,Ko.current=x;const t=[],o=[];jt.current+=1,mn.current+=1,ga.current+=1,Mr.current?.abort(),Ct(As(Wr.current?.cwd??x??void 0)),Wr.current=null,Mr.current=null,Gr.current?.abort(),Ct("right-sidebar-git-details"),Gr.current=null;for(const S of Wt.current.values())S.abort();for(const S of Wt.current.keys())Ct(`right-sidebar-git-untracked:${S}`);Wt.current.clear(),zt.current.clear(),_n.current+=1,Bn.current?.abort(),Bn.current=null,On.current+=1,Kr.current?.abort(),Kr.current=null,Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,Yr([]),Dr([]),Sr(!1),_r(null),Cn([]),Xr(!1),Or([]),ss([]),nr(!1),Zt(null),Fe(!1),_e(null),ft(null),sr(null),Qr(null),Ur(!1),rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1),Zs(null),sn(null),an(null),Rl(!1),At(Mi,!1),Co(!1);const c=x?Xd()[x]:null,w=c?.previewEntries??[],v=c?.selectedPreviewKey??null,k=v?w.find(S=>S.key===v)??null:null;++z.current,Fe(!1),No(c?.selectedRepoRoots??[]),ea(c?.repoTargetBranches??{}),ta(c?.repoBaseBranches??{}),Zr(w),P(c?.previewScrollTops??{}),k&&c?.previewDetailOpen&&(k.diff.hunks?.length??0)>0&&(Zt(k.diff),sn(k.key),an(c.selectedPreviewFileKey??(k.diff.hunks?.[0]?`${k.diff.hunks[0].filePath}\0${k.diff.hunks[0].hunkHeader}\0${k.diff.hunks[0].hunkIndex}`:null)),nr(!0)),Mo(c?.repoIncludeUncommitted??Object.fromEntries(Object.keys(c?.repoTargetBranches??{}).map(S=>[S,c?.includeUncommitted??!0]))),Go.current=x,sa(!1),cr.current.clear(),hn.current.clear(),us(null),fs(null),on(null),vt(null),Pl(null),Ee(t),We(o),ee(null),Vo.current=null,qo.current=null,ms.current.clear()},[ma,x]);const It=a.useCallback(async(t=x??void 0,o={})=>{if(!t)return null;const c=x,w=jt.current;if(await pp(()=>Promise.all([J.getState().hydrateNestedGitScanRoots(),J.getState().hydrateActiveGitRepos()]).then(()=>{})),jt.current!==w||!Ce(c))return null;const v=t===x&&Es(x),k=o.includeNested??v,S=o.refresh??o.reloadDiff??!1,se=o.cacheOnly??!1,Q=o.background??!1,me=k&&(o.discoverOnly??!1);S&&cr.current.clear();const $e=Wr.current;if($e&&$e.cwd===t&&$e.includeNested===k&&$e.refresh===S&&$e.cacheOnly===se&&$e.discoverOnly===me)return dt("reuse_pending",{cwd:t,includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me}),$e.promise;const Je=jt.current+1;jt.current=Je;const G=`right-sidebar:${tc}:${Je}`;Mr.current?.abort();const Y=As(t);Ct(Y);const je=new AbortController;Mr.current=je;let Me=null;Q||Yl(G),zo(null),dt("start",{requestId:Je,cwd:t,rootPath:x,requestSlotId:Y,includeNested:k,refresh:S,cacheOnly:se,background:Q,existingChanges:Re.size,lastLoadedAt:Dn}),!Q&&typeof window<"u"&&(Me=window.setTimeout(()=>{jt.current===Je&&Xl(G,!0)},Dg));const He=(async()=>{const Oe=await ki(t,je.signal,{includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me,action:S?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Y,requestTimeoutMs:S?null:void 0});if(Wb(Oe)){if(dt("cancelled_result_ignored",{requestId:Je,activeRequestId:jt.current,cwd:t,error:Oe.error??Oe.context?.error}),je.signal.aborted)return null;throw new Error(Oe.error??Oe.context?.error??"Failed to load Git changes")}return jt.current!==Je||!Ce(c)?(dt("stale_result",{requestId:Je,activeRequestId:jt.current,cwd:t,expectedRootPath:c,currentRootPath:J.getState().rootPath,files:Oe.files.length,repositories:Oe.repositories?.length??0}),null):(Un(Oe,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:k,background:Q,cacheOnly:se,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),Oe)})();Wr.current={cwd:t,includeNested:k,refresh:S,cacheOnly:se,discoverOnly:me,promise:He};try{const Oe=await He;return jt.current===Je&&Oe&&Ce(c)?Jl({cached:Oe.cached,stale:Oe.stale,cacheAgeMs:Oe.cacheAgeMs,nestedDeferred:!k||Oe.nestedDeferred,untrackedDeferred:Oe.untrackedDeferred}):jt.current===Je&&Ce(c)&&Ho(G),Oe}catch(Oe){return jt.current!==Je||!Ce(c)||je.signal.aborted?(dt("aborted",{requestId:Je,activeRequestId:jt.current,cwd:t,expectedRootPath:c,currentRootPath:J.getState().rootPath,message:Oe instanceof Error?Oe.message:String(Oe)}),null):(dt("error",{requestId:Je,cwd:t,includeNested:k,refresh:S,background:Q,message:Oe instanceof Error?Oe.message:String(Oe)}),Q||(ee(null),zo(Oe instanceof Error?Oe.message:"Failed to load Git changes")),null)}finally{Me!==null&&window.clearTimeout(Me),Mr.current===je&&(Mr.current=null),Wr.current?.promise===He&&(Wr.current=null),!Q&&jt.current===Je&&Ce(c)&&Ho(G)}},[Un,Yl,Re.size,Ho,tc,Dn,Ce,Jl,x,zo,Xl]),Hn=a.useCallback(async()=>{x&&await It(x,{reloadDiff:!0,refresh:!0})},[It,x]),Xo=a.useCallback(async(t=x??void 0)=>{if(!t)return null;const o=x,c=mn.current+1;mn.current=c,Gr.current?.abort(),Ct("right-sidebar-git-details");const w=new AbortController;Gr.current=w,sa(!0);try{const v=await md(t,w.signal,"load_git_details","right-sidebar-git-details");return mn.current!==c||!Ce(o)?null:(Ee(k=>k.map(S=>S.root===v.root?{...S,available:v.available,context:v,error:v.error}:S)),ee(k=>k?.root&&v.root&&k.root!==v.root?k:!k?.available||!v.available?v:{...k,...v}),v)}catch(v){return hr(v)||!Ce(o)||mn.current===c&&vt(v instanceof Error?v.message:"Failed to load Git details"),null}finally{Gr.current===w&&(Gr.current=null),mn.current===c&&Ce(o)&&sa(!1)}},[Ce,x]);a.useEffect(()=>{if(!r){jt.current+=1,ma(),Vo.current=null,mn.current+=1,ga.current+=1,Mr.current?.abort(),Ct(As(Wr.current?.cwd??x??void 0)),Wr.current=null,Mr.current=null,Gr.current?.abort(),Ct("right-sidebar-git-details"),Gr.current=null;for(const t of Wt.current.values())t.abort();for(const t of Wt.current.keys())Ct(`right-sidebar-git-untracked:${t}`);Wt.current.clear(),zt.current.clear(),On.current+=1,Kr.current?.abort(),Kr.current=null,Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,sa(!1),Fe(!1),_e(null),ft(null),sr(null),Qr(null),Ur(!1),rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1),K(""),W(!1),bt(null),Lo(!1),ne&&El(!1)}},[ne,r,ma,W]),a.useEffect(()=>{if(!xe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[xe]),a.useEffect(()=>{ne||Cr(!1)},[ne]);const ac=a.useCallback(t=>{$o(t);const o=Yo.current;o&&(o.update(),o.slideTo(t,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(t,0)}))},[]);a.useEffect(()=>{if(ne)if(Cr(m),m&&ot){Nr(1);const t=Er.current;t&&(t.update(),t.activeIndex!==1&&(ps.current=1,t.slideTo(1,0)))}else{Nr(0);const t=Er.current;t&&t.activeIndex!==0&&(ps.current=0,t.slideTo(0,0)),bt(null)}},[ne,m,x,ot]),a.useEffect(()=>{if(b!==void 0&&!m){Nr(0);const t=Er.current;t&&t.activeIndex!==0&&(ps.current=0,t.slideTo(0,0)),Cr(!1),bt(null)}},[b,m]),a.useEffect(()=>{M!==void 0&&Te(null)},[M]),a.useEffect(()=>{!ne&&m&&j?.()},[ne,j,m]),a.useEffect(()=>{_o(t=>nl(t,s))},[s]);const Jf=a.useCallback(t=>{ne||(t.preventDefault(),xa.current={startX:t.clientX,startWidth:Fo,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Fo,ne]),Zf=a.useCallback(t=>{const o=xa.current;if(!o||o.pointerId!==t.pointerId)return;const c=nl(o.startWidth+t.clientX-o.startX,s);_o(c),Is(Ps,c,Ig)},[s]),oc=a.useCallback(t=>{const o=xa.current;if(!(!o||o.pointerId!==t.pointerId)){xa.current=null,Ms(Ps);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),zn=!!(x&&Dn!==null&&du(R)),Jo=!!(x&&!fn&&Re.size===0&&Dn===null),ur=(()=>{let t=Bo;return t==="android"&&!zr&&(t="files"),zn&&(t==="git"||t==="diff")&&(t="files"),t})(),lt=ur==="git",Wn=ur==="files",Rt=ur==="diff",Gn=ur==="android",Qf=Im(t=>t.overlay==="sidebar")&&Gn;a.useEffect(()=>{if(!ne){ra(!0);return}if(!r){const o=window.setTimeout(()=>{ra(!1)},Bg);return()=>window.clearTimeout(o)}ra(!1);const t=window.setTimeout(()=>{ra(!0)},_g);return()=>window.clearTimeout(t)},[ne,r]),a.useEffect(()=>{if(!ne||!Rt)return;const t=Yo.current;if(!t)return;const o=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(o)},[Rt,ne]),a.useEffect(()=>{if(!zn||!x||lr)return;const t=window.setTimeout(()=>{It(x,{background:!0})},3e3);return()=>window.clearTimeout(t)},[zn,x,lr,It]);const eh=a.useCallback(t=>{It(t,{discoverOnly:!0})},[It]);gp({active:r&&(lt||Rt),rootPath:x,loading:lr,delay:lt&&!ne?0:$i,lastStartedRoot:Vo,load:eh}),a.useEffect(()=>{!r||!lt||(!ne||Ao)&&Lo(!0)},[lt,ne,r,Ao]),a.useEffect(()=>{if(!r||lt)return;const t=window.setTimeout(()=>{Lo(!0)},$i);return()=>window.clearTimeout(t)},[lt,r]),a.useEffect(()=>{Rt&&El(!0)},[Rt]),a.useEffect(()=>{!r||!Gn||(n&&na&&na.sessionId!==n&&(yi.getState().setDock(Si,null),ro({androidPanel:{docked:null}}).catch(()=>{})),$l(!0))},[Gn,r,n,na]),a.useEffect(()=>{if(r&&Gn||!Po)return;const t=window.setTimeout(()=>$l(!1),Fg);return()=>window.clearTimeout(t)},[r,Gn,Po]),a.useEffect(()=>{let t=!1;return fu().then(o=>{!t&&o.androidPanel&&Al(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const th=a.useCallback(t=>{Al(t),t?er("android"):J.getState().rightTab==="android"&&er("files"),ro({androidPanel:{enabled:t}}).catch(()=>{})},[er]),ic=a.useCallback(t=>{ge&&Db(ge,t.currentTarget.scrollTop)},[ge]);a.useEffect(()=>()=>{Mr.current?.abort(),Ms(fl),Ms(hl),Ms(Ps),Ms(Ei)},[]),a.useEffect(()=>{if(!ge||!ec)return;const t=Ef()[ge]?.top;if(typeof t!="number")return;let o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=t),o=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(o)},[ge,ec]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return um(t.signal).then(o=>_l(!!o.available)).catch(()=>_l(!1)),()=>t.abort()},[r]);const gs=a.useCallback(t=>{if(te(null),it(t),bt(null),ne){Cr(!0),Nr(1),Er.current?.slideTo(1),f?.();return}},[ne,f,it]),lc=a.useCallback((t,o)=>{if(te(null),it(t),Lt(o),ne){Cr(!0),Nr(1),Er.current?.slideTo(1),f?.();return}},[ne,f,it]),bs=a.useCallback(async(t,o)=>{const c=o||Tn||x;if(!(!c||t.length===0)){da(!0);try{await Ha(c,t),ha(c,!1)}catch(w){vt(w instanceof Error?w.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>vt(null),4e3)}finally{da(!1)}}},[Tn,x,ha,i]),cc=a.useCallback(async t=>{try{await fm(t)}catch(o){vt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>vt(null),4e3)}},[i]),wa=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Io(!0)},[]),dc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Io(!1)},[]),uc=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Io(!1);const o=t.dataTransfer.files;o.length>0&&bs(Array.from(o))},[bs]),Zo=a.useCallback(t=>{rt(t),window.setTimeout(()=>rt(o=>o===t?null:o),1400)},[]),$r=a.useCallback(t=>{oe(t),window.setTimeout(()=>oe(o=>o===t?null:o),1400)},[]);a.useEffect(()=>{At(Hd,Ie)},[Ie]),a.useEffect(()=>{At(zd,_t)},[_t]),a.useEffect(()=>{At(Wd,H)},[H]),a.useEffect(()=>{Is(Ei,ve,$g)},[ve]),a.useEffect(()=>(Hl().catch(()=>{}),pd(t=>{t.type==="pinned-explorer-roots"&&zl(t.pinnedExplorerRoots)})),[Hl,zl]);const fc=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),ya=a.useRef(null),gn=a.useRef(null),[hc,Qo]=a.useState(!1);a.useEffect(()=>{if(!r)return;Qo(!1);let t=!1;hm().then(c=>{t||(ya.current=c.text,Ke(w=>c.text&&c.text!==w?c.text:w),Qo(!0))}).catch(()=>{t||Qo(!0)});const o=pd(c=>{c.type==="context-draft"&&c.origin!==fc.current&&(ya.current=c.text,Ke(c.text))});return()=>{t=!0,o(),gn.current!==null&&(window.clearTimeout(gn.current),gn.current=null)}},[r]),a.useEffect(()=>{if(!hc||ya.current===ve)return;gn.current!==null&&window.clearTimeout(gn.current);const t=ve;gn.current=window.setTimeout(()=>{gn.current=null,mm(t,fc.current).then(()=>{ya.current=t}).catch(()=>{})},500)},[ve,hc]);const Kn=a.useCallback((t,o,c)=>{if(t){if(pm(c?t+c:t)){Zo(o);return}Ie?(Ke(w=>Op(w,t)+(c??"")),window.matchMedia("(pointer: coarse)").matches||(Bt(!1),mr(w=>w+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:c?t+c:t,focus:!0}})),Zo(o)}},[Ie,Zo]),ka=a.useCallback(t=>{const o=yn(t,x);return Dm(o,x)},[x]),ei=Mu($r),Gt=a.useCallback((t,o)=>{const c=yn(t,x);Kn(Fm(c,x),o??`path:${c}`)},[x,Kn]),rh=a.useCallback(async t=>{da(!0);try{await _m(t,Ha,o=>{Gt(o,`path:${o}`)}),ne&&!Ie&&l()}catch(o){vt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>vt(null),4e3)}finally{da(!1)}},[Ie,Gt,ne,l,i]),Sa=a.useRef(!0),ti=a.useRef(n);ti.current=n,a.useEffect(()=>(Sa.current=!0,()=>{Sa.current=!1}),[]);const nh=a.useCallback(t=>{Bm.getState().enqueue(t,n??null,x||"/",o=>{if(Ie&&Sa.current&&ti.current===n)Gt(o);else return kd(o,n)})},[n,x,Ie,Gt]),sh=a.useCallback(async t=>{const c=(await Ha("/tmp",[t])).files[0]?.path;if(!c)throw new Error("截图上传未返回文件路径");Ie&&Sa.current&&ti.current===n?Gt(c):await kd(c,n)},[Ie,Gt,n]),Ar=a.useCallback((t,o)=>{if(!t)return;const c=t.includes(`
1660
1660
  `)?`
1661
1661
  `:void 0;Kn(t.endsWith(`
1662
- `)||t.endsWith(" ")?t:`${t} `,o,c)},[Kn]),hc=a.useRef(Ar);hc.current=Ar;const ri=a.useRef(!0);a.useEffect(()=>(ri.current=!0,()=>{ri.current=!1}),[]);const ni=a.useRef(new Set),mc=a.useCallback((t,o,c)=>{if(ni.current.has(o))return;const y=kd.getState().activeSessionId;ni.current.add(o),xp(t,o,c,{insert:Ar,upload:async(v,k)=>(await Ha("/tmp",[v],k)).files[0]?.path,isCurrent:()=>ri.current&&hc.current===Ar&&y===kd.getState().activeSessionId}).finally(()=>ni.current.delete(o))},[Ar]),Lr=a.useCallback((t,o,c)=>{o&&Kn(o.endsWith(" ")?o:`${o} `,c??`context:${t}`,`
1663
- `)},[Kn]),pc=a.useCallback(t=>{const o=Op(ve,t);if(!o)return;const c=t&&ve.trim().includes(`
1664
- `),y=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let v=!1;const k=Z=>{v||(v=!0,window.removeEventListener("termdock-insert-reference-ack",S),window.clearTimeout(se),Z?(xr(!1),Ke(""),H&&Bt(!0)):(xr(!0),Bt(!1)))},S=Z=>{const me=Z.detail;me?.nonce===y&&k(me.ok===!0)},se=window.setTimeout(()=>k(!1),1500);window.addEventListener("termdock-insert-reference-ack",S),xr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:c,nonce:y}}))},[H,ve]),st=a.useMemo(()=>x?kt(x):i("rightSidebar.workspace"),[x,i]),sh=a.useMemo(()=>kt(ge)||st,[ge,st]),ja=a.useMemo(()=>Ii(ge),[ge]),Ra=a.useMemo(()=>x?Ol[x]??[]:[],[Ol,x]),bn=a.useMemo(()=>new Set(Ra.map(t=>t.path)),[Ra]),xs=!!(ge&&bn.has(ge)),si=!!(x&&ge&&ge!==x),ah=!!(x&&Tn&&Tn!==x),Dt=ge?`path:${ge}`:null,gc="context:change-audit",oh=a.useCallback(()=>{ja&&Ht(ja)},[ja,Ht]),bc=a.useCallback(()=>{zl()},[zl]),ih=a.useCallback(()=>{ge&&(ha(ge,!0),Kl())},[Kl,ge,ha]),lh=a.useCallback(()=>{!ge||!si||(xs?un(ge):In(ge,"directory"))},[si,ge,xs,In,un]),xc=a.useCallback(t=>{Ht(t),K("")},[Ht]),vc=a.useCallback(t=>{ge&&(ie(Ng(ge,t)),W(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ge,W]),yc=a.useCallback(t=>{!x||t===x||(bn.has(t)?un(t):In(t,"directory"))},[In,bn,x,un]),wc=a.useCallback(t=>{!x||!t||(bn.has(t)?un(t):In(t,"file"))},[In,bn,x,un]),kc=J(t=>t.expandedPaths),ai=a.useMemo(()=>{const t=new Set;if(Wn&&ge){t.add(ge);const o=`${ge.replace(/\/+$/,"")}/`;for(const c of kc)c.startsWith(o)&&t.add(c)}if(Wn&&x&&ot){const o=ot.startsWith("/")?ot:`${x}/${ot}`,c=Ii(o);c&&t.add(c)}return Ap(t).join(`
1665
- `)},[kc,Wn,ge,x,ot]),xn=a.useRef(new Map);a.useEffect(()=>{const t=ai?ai.split(`
1666
- `):[];if(!r||t.length===0){Pn(null);return}const o=new AbortController;let c=!1,y=0,v=0;Pn(null);const k=async()=>{let S=0;for(;!c&&!o.signal.aborted;){let se=null;try{Pn(null),await wm(t,me=>{const{applicableEvents:$e,unavailableReason:Je}=Pp(me);$e.length>0&&Wl($e);for(const G of $e){if(G.type!=="rescan-required")continue;const Y=J.getState();if(!Y.directoryCache.has(G.path))continue;xn.current.get(G.path)?.abort();const Me=new AbortController;xn.current.set(G.path,Me);const He=`file-watch-rescan:${G.path}`;Ct(He),km(G.path,Me.signal,Y.showHiddenFiles,"watch_rescan",He,Y.fileSortModes[G.path]??"name").then(Oe=>{xn.current.get(G.path)===Me&&Gl(G.path,Oe.entries)}).catch(Oe=>{hr(Oe)||Pn(Oe instanceof Error?Oe.message:"File refresh unavailable")}).finally(()=>{xn.current.get(G.path)===Me&&xn.current.delete(G.path)})}Je&&Pn(Je)},o.signal),se=new Error("File watch stream ended")}catch(me){se=me}if(c||o.signal.aborted||hr(se))return;Pn(se instanceof Error?se.message:"File watching unavailable");const Z=Wd[Math.min(S,Wd.length-1)];S+=1,await new Promise(me=>{v=window.setTimeout(me,Z)})}};return y=window.setTimeout(()=>{c||k()},Ei),()=>{c=!0,window.clearTimeout(y),window.clearTimeout(v),o.abort();for(const S of xn.current.values())S.abort();xn.current.clear()}},[Wl,r,Gl,ai]),a.useEffect(()=>{if(!x||Go.current!==x)return;if(Ko.current===x){Ko.current=null;return}const t=Yd();Is(zu,{...t,[x]:{selectedRepoRoots:Zs,repoTargetBranches:Zt,repoBaseBranches:Et,previewEntries:Jr,selectedPreviewKey:be&&Rr?Xe:null,selectedPreviewFileKey:be&&Rr?Eo:null,previewDetailOpen:!!(be&&Rr),previewScrollTops:as,previewMobileSlideIndex:1,repoIncludeUncommitted:nn,updatedAt:Date.now()}},Mg)},[Rr,nn,be,Jr,as,Et,Zt,Zs,x,Eo,Xe]);const ht=a.useMemo(()=>lu(Re.values()),[Re]),ct=a.useMemo(()=>{const t=new Map;for(const o of le)t.set(o.root,o);return t},[le]),vs=a.useMemo(()=>{const t=new Map;for(const o of le)o.deferred||t.set(o.root,o.files.length);return t},[le]),Ca=a.useCallback(t=>{if(t){if(!t.deferred){ms.current.delete(t.root);return}vs.has(t.root)||ms.current.has(t.root)||(ms.current.add(t.root),It(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(o=>{o||ms.current.delete(t.root)}))}},[It,vs]),rr=a.useMemo(()=>ce?Ne.find(t=>t.root===ce)??null:null,[ce,Ne]),Kt=a.useMemo(()=>ot?Array.from(Re.values()).find(t=>t.path===ot||t.absolutePath===ot)??null:null,[Re,ot]),Ft=a.useMemo(()=>{const t=new Map;for(const o of le)o.available&&o.context?.available&&t.set(o.root,o);return t.size===0&&R?.available&&R.root&&t.set(R.root,{id:R.root,root:R.root,relativeRoot:".",name:st,depth:0,nested:!1,available:!0,files:Array.from(Re.values()).filter(o=>gt(o,x)===R.root),context:R}),Array.from(t.values()).sort((o,c)=>o.root===x?-1:c.root===x?1:(o.relativeRoot||o.name).localeCompare(c.relativeRoot||c.name)).map(o=>{const c=o.relativeRoot==="."?st:o.relativeRoot||o.name||kt(o.root),y=iu(o.files),v=o.files.length;return{value:o.root,label:c,meta:[o.context?.branch,v>0?i("rightSidebar.repoChangedCount",{count:v}):null,y>0?i("rightSidebar.repoStagedCount",{count:y}):null].filter(Boolean).join(" · ")}})},[Re,R,le,st,x,i]),we=a.useMemo(()=>ce&&Ft.some(t=>t.value===ce)?ce:Kt?.repoRoot&&Ft.some(t=>t.value===Kt.repoRoot)?Kt.repoRoot:Ft.length===1||Ft.length>1?Ft[0].value:null,[ce,Ft,Kt?.repoRoot]),Sc=we?ct.get(we)??null:null,fe=Sc?.context?.available?Sc.context:we===R?.root?R:null,Qe=Ft.length>0&&!we,jc=a.useMemo(()=>Qe?[]:we?Array.from(Re.values()).filter(t=>gt(t,x)===we):Array.from(Re.values()),[we,Re,Qe,x]),vn=a.useMemo(()=>lu(jc),[jc]),oi=!!(fe?.available&&fe.root&&we&&fe.root===we),ch=we?Ft.find(t=>t.value===we)?.label??kt(we):i("rightSidebar.gitRepositoryPlaceholder"),Rc=oi?fe?.branch??"HEAD":Qe?i("rightSidebar.selectRepositoryForGitActions"):ln?i("rightSidebar.gitActionRunning"):"HEAD",Vn=!!(fe?.available&&fe.root===we&&fe.status);a.useEffect(()=>{Sl.current={count:Tt.length,loading:Xs,loadingMore:Js,hasMore:jo}},[Tt.length,jo,Xs,Js]),a.useEffect(()=>{Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1)},[we]);const ys=a.useCallback(async(t={})=>{if(!x||!we||Qe)return;const o=t.reset??!1,c=Sl.current,y=o?0:c.count;if(!o&&(c.loading||c.loadingMore||!c.hasMore))return;const v=Hr.current+1;Hr.current=v,or.current?.abort(),Ct("right-sidebar-recent-commits");const k=new AbortController;or.current=k,o?ls(!0):cs(!0),Mn(null);try{const S=await pm({cwd:x,repoRoot:we,limit:Bg,skip:y,query:is.trim(),requestSlotId:"right-sidebar-recent-commits"},k.signal);if(Hr.current!==v)return;if(!S.available){Mn(S.error??"Recent commits are unavailable"),o&&ar([]),En(!1);return}Ye(se=>o?S.commitSyncStatus??{}:{...se,...S.commitSyncStatus}),ar(se=>o?S.commits:[...se,...S.commits]),En(S.hasMore)}catch(S){if(Hr.current!==v||hr(S))return;Mn(S instanceof Error?S.message:"Failed to load recent commits"),o&&ar([]),En(!1)}finally{or.current===k&&(or.current=null),Hr.current===v&&(ls(!1),cs(!1))}},[we,is,Qe,x]);a.useEffect(()=>{en&&ys({reset:!0})},[is,ys,en,fe?.ahead,fe?.behind,fe?.upstream]);const dh=a.useCallback(t=>{const o=t.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||ys({reset:!1})},[ys]);a.useEffect(()=>{!we||!R?.available||!lt||!ir||Vn||ln||Qe||Xo(we)},[we,R?.available,Vn,ln,lt,ir,Xo,Qe]),a.useEffect(()=>{!r||!Rt&&!lt||!x||dr()},[Rt,lt,r,dr,x]),a.useEffect(()=>{!r||!lt||!ir||!ds||!x||va(null)},[ds,lt,ir,r,va,x]);const uh=a.useMemo(()=>{if(!ce)return 0;const t=Ne.findIndex(o=>o.root===ce);return t>=0?t+1:0},[ce,Ne]),Cc=a.useCallback(t=>{if(!t)return null;const o=Array.from(Re.values()).filter(c=>gt(c,x)===t).sort((c,y)=>c.path.localeCompare(y.path))[0];return o?wt(o):null},[Re,x]),yn=Ne.length>1,Na=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:Re.size,branch:null,deferred:!1},...Ne.map(t=>({root:t.root,label:t.label,count:t.deferred?vs.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!vs.has(t.root)}))],[Re.size,Ne,vs,i]),Nc=Na[uh]??Na[0],Ma=!!ce,Mc=a.useMemo(()=>Xu(Ne,le),[Ne,le]);a.useEffect(()=>{qo.current===x&&ce&&!Mc.has(ce)&&Pe(null),Cn(t=>t.filter(o=>Ne.some(c=>c.root===o)))},[ce,Ne,Mc,x,Pe]),a.useEffect(()=>{ce&&Ca(ct.get(ce))},[ce,Ca,ct]);const fh=a.useMemo(()=>{const t=new Set;fe?.branch&&t.add(fe.branch);for(const o of fe?.branches??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[fe?.branch,fe?.branches,i]),Ec=a.useMemo(()=>{const t=new Set;fe?.upstreamRemote&&t.add(fe.upstreamRemote);for(const o of fe?.remotes??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===fe?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[fe?.remotes,fe?.upstreamRemote,i]),$c=Ec.length>1,hh=a.useMemo(()=>{const t=[],o=new Set,c=(v,k)=>{!v||o.has(v)||(o.add(v),t.push({value:v,label:v,meta:k}))};c(fe?.upstreamBranch,fe?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),c(fe?.branch,fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of fe?.branches??[])c(v,v===fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const y=fe?.upstreamRemote;for(const v of fe?.remoteBranches??[]){const k=v.indexOf("/"),S=k>=0?v.slice(0,k):null,se=k>=0?v.slice(k+1):v;(!y||S===y)&&c(se,"remote")}return t},[fe?.branch,fe?.branches,fe?.remoteBranches,fe?.upstreamBranch,fe?.upstreamRemote,i]),Vt=a.useMemo(()=>Ft.map(t=>{const o=ct.get(t.value);return{root:t.value,label:t.label,branch:o?.context?.branch??null}}),[Ft,ct]);a.useEffect(()=>{Vt.length!==0&&(ea(t=>{let o=!1;const c={...t},y=new Set(Vt.map(v=>v.root));for(const v of Object.keys(c))y.has(v)||(delete c[v],o=!0);for(const v of Vt)!c[v.root]&&v.branch&&(c[v.root]=v.branch,o=!0);return o?c:t}),ta(t=>{let o=!1;const c={...t},y=new Set(Vt.map(v=>v.root));for(const v of Object.keys(c))y.has(v)||(delete c[v],o=!0);for(const v of Vt){const k=ct.get(v.root)?.context;if(c[v.root]&&Ju(c[v.root],k?.branch)&&(delete c[v.root],o=!0),c[v.root])continue;const S=Qd(k);S&&(c[v.root]=S,o=!0)}return o?c:t}))},[Vt,ct]);const Ea=a.useMemo(()=>{const t=new Set(Vt.map(o=>o.root));return Zs.filter(o=>t.has(o))},[Zs,Vt]),$a=Ea.length===0,fr=a.useMemo(()=>$a?Vt:Vt.filter(t=>Ea.includes(t.root)),[Vt,Ea,$a]),ws=a.useMemo(()=>fr.filter(t=>!!Et[t.root]?.trim()),[Et,fr]),qn=a.useCallback((t,o)=>{const c=ct.get(t)?.context?.branch;return!!(c&&o&&o.replace(/^refs\/heads\//,"")===c)},[ct]),Ac=a.useMemo(()=>fr.filter(t=>!Et[t.root]?.trim()),[Et,fr]),Lc=a.useCallback(async t=>{if(!t||Wo.current.has(t))return;const o=ct.get(t)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const c=x;Wo.current.add(t),Cl(y=>new Set(y).add(t));try{const y=await hd(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!y.available||!Ce(c))return;Ee(v=>v.map(k=>k.root===t?{...k,available:!0,context:{...k.context,...y},error:void 0}:k)),ea(v=>v[t]||!y.branch?v:{...v,[t]:y.branch}),ta(v=>{if(v[t])return v;const k=Qd(y);return k?{...v,[t]:k}:v})}catch(y){hr(y)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,y)}finally{Wo.current.delete(t),Cl(y=>{const v=new Set(y);return v.delete(t),v})}},[ct,Ce,x]);a.useEffect(()=>{if(Ro)for(const t of fr)Lc(t.root)},[Ro,fr,Lc]),a.useEffect(()=>{!oi||!fe||(oa(fe.branch||(fe.branches?.[0]??"")),ia(fe.upstreamRemote||(fe.remotes?.includes("origin")?"origin":fe.remotes?.[0]??"")),la(fe.upstreamBranch||fe.branch||(fe.branches?.[0]??"")))},[fe,oi]);const Pc=a.useMemo(()=>{if(Qe)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Vn||ln)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!fe?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=fe.ahead??0,o=fe.behind??0;return t>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:t,behind:o}),className:"bg-destructive/10 text-destructive"}:t>0?{text:i("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[fe?.ahead,fe?.behind,fe?.upstream,Vn,ln,Qe,i]),mh=a.useCallback(t=>{if(t&&!ne){const o=t.currentTarget.getBoundingClientRect();Te({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Te(null);I?.()},[ne,I]),ii=a.useCallback(()=>{Te(null),_?.()},[_]);function Tc(){if(!yn)return null;const t=Nc?.label??i("rightSidebar.allRepositories"),o=Nc?.count??Re.size,c=kt(t)||t;return e.jsxs("button",{type:"button",onClick:mh,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${w?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":w,title:t,children:[e.jsx(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:c}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Os,{size:12,className:"shrink-0"})]})}function ph(){if(!w||!yn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,c=Math.max(12,Math.min(tt?.x??t-368,t-352)),y=Math.max(12,Math.min(tt?.y??80,o-420)),v=ne?void 0:{left:c,top:y},k=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ne?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:ii,children:e.jsxs("div",{className:ne?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:v,onClick:S=>S.stopPropagation(),children:[e.jsxs("div",{className:ne?"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:ne?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ne&&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:Na.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Re.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Re.size})]})]}),e.jsx("button",{type:"button",onClick:ii,className:ne?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Yt,{size:ne?16:14})})]}),e.jsx("div",{className:ne?"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:Na.map(S=>{const se=(S.root??null)===ce,Z=kt(S.label)||S.label;return e.jsxs("button",{type:"button",onClick:()=>{ed(S.root),ii()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ne?"px-3 py-2":"px-2 py-1.5"} ${se?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:S.label,role:"option","aria-selected":se,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${se?"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 ${se?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Pr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ne?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:Z}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:S.root===null?i("rightSidebar.allRepositories"):S.label})]}),S.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:S.branch}),S.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${S.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:S.count})]},S.root??"all")})})]})});return Fu(k,ne,document.body)}function gh(){return ph()}function Ic(t){const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path),y=io(c,o??x);return{key:wt(t),path:t.path,absolutePath:c,displayName:y.name,displayDir:y.dir,oldPath:t.oldPath,status:t.status,title:c}}function Dc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function Aa(t,o){const c=wn(t,x),y=`path:${c}`,v=ke===y,k=nt===y,S=v||k;return e.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),Gt(c,y)},...ei(ka(c),y),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${S?"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"} ${S?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(k?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Fc(t){const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path),y=zh(t),v=_i(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Wb,{actions:y,running:Ue,completed:$n?.path===v?$n:null}),Aa(c,i("rightSidebar.insertThisFile"))]})}function _c(t,o){const c=o.root??x;if(!c)return null;const y=wn(t,c);return Aa(y,i("fileTree.insertRefTitle"))}function ks(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>qc("unified"),"aria-pressed":Ut==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ut==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>qc("split"),"aria-pressed":Ut==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ut==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function Bc(){return Ss.map(t=>{const o=iu(t.files.map(([,k])=>k)),c=el({activeGitRepoRoot:ce,groupCount:Ss.length,label:t.label,rootName:st}),y=!!(c&&t.root&&vr.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:y,files:t.files.map(([,k])=>Ic(k)),header:c?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${y?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Th(t.root),"aria-expanded":!y,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:y?e.jsx(za,{size:13}):e.jsx(Os,{size:13})}),e.jsx(Pr,{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}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ba("stage-all",t.root,t.label)},disabled:!!Ue,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ba("stash-all",t.root,t.label)},disabled:!!Ue,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function Oc(){return Re.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:Pa.map(([,t])=>{const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path);return{key:wt(t),path:t.path,absolutePath:c,status:t.status,repoRoot:o,displayName:io(c,o).name,displayDir:io(c,o).dir,auditRecords:Mt}})}function Uc(t){const o=Array.from(Re.values()).find(v=>wt(v)===t.key),c=o?gt(o,x):null,y=yp(Mt,c,o?.path??t.path);return e.jsx(Yi,{changeStatus:t.status,auditStatus:y,renderChangeBadge:v=>e.jsx(Ds,{status:v})})}const La=a.useCallback(t=>{if(ne)return null;const o=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const y=t.getBoundingClientRect().top+48;let v=null,k=Number.POSITIVE_INFINITY;for(const se of o){const Z=se.getBoundingClientRect();if(Z.bottom<y)continue;const me=Math.abs(Z.top-y);me<k&&(v=se,k=me)}const S=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return S?(ba.current===S&&J.getState().selectedFilePath===S||(ba.current=S,it(S)),S):null},[ne,it]),bh=!!(!Ue&&we&&!Qe&&(fe?.upstream||cn.trim()&&dn.trim())),xh=!!(!Ue&&we&&!Qe&&(fe?.upstream||cn.trim()&&dn.trim())),vh=!!(!Ue&&we&&!Qe&&Ln.trim()&&Ln.trim()!==fe?.branch),qt=a.useMemo(()=>{const t=Be.trim().toLowerCase(),o=Array.from(Re.entries()).filter(([,c])=>!ce||gt(c,x)===ce).sort(([c],[y])=>c.localeCompare(y));return t?o.filter(([c,y])=>`${c} ${y.path} ${y.status} ${y.repoRelativeRoot??""} ${y.repoName??""}`.toLowerCase().includes(t)):o},[ce,Re,Be,x]);a.useEffect(()=>{to("selected_file_state",{selectedFilePath:ot,selectedChangedFilePath:Kt?.path??null,selectedChangedFileAbsolutePath:Kt?.absolutePath??null,selectedChangedFileRepoRoot:Kt?.repoRoot??null,rootPath:x,activeGitRepoRoot:ce,rightTab:Bo,effectiveRightTab:ur,diffPaneActive:Rt,changedFiles:Re.size,filteredChangedFiles:qt.length,gitBundleLoading:lr,gitBundleLastLoadedAt:Dn})},[ce,Re.size,Rt,ur,qt.length,Dn,lr,Bo,x,Kt?.absolutePath,Kt?.path,Kt?.repoRoot,ot]);const Ss=a.useMemo(()=>{const t=new Map;for(const o of qt){const[,c]=o,y=gt(c,x),v=Hb(c)||st,k=y??v,S=y?ct.get(y):void 0,se=t.get(k)??{root:y,label:v,branch:S?.context?.branch,files:[]};se.files.push(o),t.set(k,se)}return Array.from(t.values()).sort((o,c)=>o.label===st?-1:c.label===st?1:o.label.localeCompare(c.label))},[qt,ct,st,x]),Pa=a.useMemo(()=>{const t=[],o=new Map;for(const c of qt)o.set(wt(c[1]),c);for(const c of Ss){if(!!(c.root&&el({activeGitRepoRoot:ce,groupCount:Ss.length,label:c.label,rootName:st})&&vr.has(c.root)))continue;if(kr!=="tree"){t.push(...c.files);continue}const v=c.files.map(([,k])=>Ic(k));for(const k of qm(v)){const S=o.get(k.key);S&&t.push(S)}}return t},[ce,vr,kr,Ss,qt,st]);a.useEffect(()=>{if(!Rt||Pa.length===0||ne)return;const t=[],o=()=>{const c=document.querySelector(".termdock-diff-stream-scroller");if(c&&La(c))return;const y=document.querySelector("[data-diff-stream-item]"),v=y?.dataset.diffSelectionPath??y?.dataset.diffStreamItem??null;if(v){ba.current=v,it(v);return}const k=Pa[0]?.[1];if(!k)return;const S=wt(k);ba.current=S,it(S)};for(const c of[80,240,600,1200])t.push(window.setTimeout(o,c));return()=>t.forEach(c=>window.clearTimeout(c))},[Rt,ne,Pa,it,La]);const li=a.useMemo(()=>{const t=S=>`'${S.replace(/'/g,"'\\''")}'`,o=tr.length>0?pn:le.filter(S=>S.files.length>0),c=o.length>0?o:x?[{root:x,relativeRoot:".",name:st}]:[],y=c.length>0?c.map(S=>`- ${S.relativeRoot==="."?".":S.relativeRoot} (${S.root})`).join(`
1662
+ `)||t.endsWith(" ")?t:`${t} `,o,c)},[Kn]),mc=a.useRef(Ar);mc.current=Ar;const ri=a.useRef(!0);a.useEffect(()=>(ri.current=!0,()=>{ri.current=!1}),[]);const ni=a.useRef(new Set),pc=a.useCallback((t,o,c)=>{if(ni.current.has(o))return;const w=Sd.getState().activeSessionId;ni.current.add(o),vp(t,o,c,{insert:Ar,upload:async(v,k)=>(await Ha("/tmp",[v],k)).files[0]?.path,isCurrent:()=>ri.current&&mc.current===Ar&&w===Sd.getState().activeSessionId}).finally(()=>ni.current.delete(o))},[Ar]),Lr=a.useCallback((t,o,c)=>{o&&Kn(o.endsWith(" ")?o:`${o} `,c??`context:${t}`,`
1663
+ `)},[Kn]),gc=a.useCallback(t=>{const o=Up(ve,t);if(!o)return;const c=t&&ve.trim().includes(`
1664
+ `),w=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let v=!1;const k=Q=>{v||(v=!0,window.removeEventListener("termdock-insert-reference-ack",S),window.clearTimeout(se),Q?(xr(!1),Ke(""),H&&Bt(!0)):(xr(!0),Bt(!1)))},S=Q=>{const me=Q.detail;me?.nonce===w&&k(me.ok===!0)},se=window.setTimeout(()=>k(!1),1500);window.addEventListener("termdock-insert-reference-ack",S),xr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:c,nonce:w}}))},[H,ve]),st=a.useMemo(()=>x?kt(x):i("rightSidebar.workspace"),[x,i]),ah=a.useMemo(()=>kt(ge)||st,[ge,st]),ja=a.useMemo(()=>Di(ge),[ge]),Ra=a.useMemo(()=>x?Ul[x]??[]:[],[Ul,x]),bn=a.useMemo(()=>new Set(Ra.map(t=>t.path)),[Ra]),xs=!!(ge&&bn.has(ge)),si=!!(x&&ge&&ge!==x),oh=!!(x&&Tn&&Tn!==x),Dt=ge?`path:${ge}`:null,bc="context:change-audit",ih=a.useCallback(()=>{ja&&Ht(ja)},[ja,Ht]),xc=a.useCallback(()=>{Wl()},[Wl]),lh=a.useCallback(()=>{ge&&(ha(ge,!0),Vl())},[Vl,ge,ha]),ch=a.useCallback(()=>{!ge||!si||(xs?un(ge):In(ge,"directory"))},[si,ge,xs,In,un]),vc=a.useCallback(t=>{Ht(t),K("")},[Ht]),wc=a.useCallback(t=>{ge&&(ie(Mg(ge,t)),W(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ge,W]),yc=a.useCallback(t=>{!x||t===x||(bn.has(t)?un(t):In(t,"directory"))},[In,bn,x,un]),kc=a.useCallback(t=>{!x||!t||(bn.has(t)?un(t):In(t,"file"))},[In,bn,x,un]),Sc=J(t=>t.expandedPaths),ai=a.useMemo(()=>{const t=new Set;if(Wn&&ge){t.add(ge);const o=`${ge.replace(/\/+$/,"")}/`;for(const c of Sc)c.startsWith(o)&&t.add(c)}if(Wn&&x&&ot){const o=ot.startsWith("/")?ot:`${x}/${ot}`,c=Di(o);c&&t.add(c)}return Lp(t).join(`
1665
+ `)},[Sc,Wn,ge,x,ot]),xn=a.useRef(new Map);a.useEffect(()=>{const t=ai?ai.split(`
1666
+ `):[];if(!r||t.length===0){Pn(null);return}const o=new AbortController;let c=!1,w=0,v=0;Pn(null);const k=async()=>{let S=0;for(;!c&&!o.signal.aborted;){let se=null;try{Pn(null),await km(t,me=>{const{applicableEvents:$e,unavailableReason:Je}=Tp(me);$e.length>0&&Gl($e);for(const G of $e){if(G.type!=="rescan-required")continue;const Y=J.getState();if(!Y.directoryCache.has(G.path))continue;xn.current.get(G.path)?.abort();const Me=new AbortController;xn.current.set(G.path,Me);const He=`file-watch-rescan:${G.path}`;Ct(He),Sm(G.path,Me.signal,Y.showHiddenFiles,"watch_rescan",He,Y.fileSortModes[G.path]??"name").then(Oe=>{xn.current.get(G.path)===Me&&Kl(G.path,Oe.entries)}).catch(Oe=>{hr(Oe)||Pn(Oe instanceof Error?Oe.message:"File refresh unavailable")}).finally(()=>{xn.current.get(G.path)===Me&&xn.current.delete(G.path)})}Je&&Pn(Je)},o.signal),se=new Error("File watch stream ended")}catch(me){se=me}if(c||o.signal.aborted||hr(se))return;Pn(se instanceof Error?se.message:"File watching unavailable");const Q=Gd[Math.min(S,Gd.length-1)];S+=1,await new Promise(me=>{v=window.setTimeout(me,Q)})}};return w=window.setTimeout(()=>{c||k()},$i),()=>{c=!0,window.clearTimeout(w),window.clearTimeout(v),o.abort();for(const S of xn.current.values())S.abort();xn.current.clear()}},[Gl,r,Kl,ai]),a.useEffect(()=>{if(!x||Go.current!==x)return;if(Ko.current===x){Ko.current=null;return}const t=Xd();Is(Wu,{...t,[x]:{selectedRepoRoots:Qs,repoTargetBranches:Qt,repoBaseBranches:Et,previewEntries:Jr,selectedPreviewKey:be&&Rr?Xe:null,selectedPreviewFileKey:be&&Rr?Eo:null,previewDetailOpen:!!(be&&Rr),previewScrollTops:as,previewMobileSlideIndex:1,repoIncludeUncommitted:nn,updatedAt:Date.now()}},Eg)},[Rr,nn,be,Jr,as,Et,Qt,Qs,x,Eo,Xe]);const ht=a.useMemo(()=>cu(Re.values()),[Re]),ct=a.useMemo(()=>{const t=new Map;for(const o of le)t.set(o.root,o);return t},[le]),vs=a.useMemo(()=>{const t=new Map;for(const o of le)o.deferred||t.set(o.root,o.files.length);return t},[le]),Ca=a.useCallback(t=>{if(t){if(!t.deferred){ms.current.delete(t.root);return}vs.has(t.root)||ms.current.has(t.root)||(ms.current.add(t.root),It(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(o=>{o||ms.current.delete(t.root)}))}},[It,vs]),rr=a.useMemo(()=>ce?Ne.find(t=>t.root===ce)??null:null,[ce,Ne]),Kt=a.useMemo(()=>ot?Array.from(Re.values()).find(t=>t.path===ot||t.absolutePath===ot)??null:null,[Re,ot]),Ft=a.useMemo(()=>{const t=new Map;for(const o of le)o.available&&o.context?.available&&t.set(o.root,o);return t.size===0&&R?.available&&R.root&&t.set(R.root,{id:R.root,root:R.root,relativeRoot:".",name:st,depth:0,nested:!1,available:!0,files:Array.from(Re.values()).filter(o=>gt(o,x)===R.root),context:R}),Array.from(t.values()).sort((o,c)=>o.root===x?-1:c.root===x?1:(o.relativeRoot||o.name).localeCompare(c.relativeRoot||c.name)).map(o=>{const c=o.relativeRoot==="."?st:o.relativeRoot||o.name||kt(o.root),w=lu(o.files),v=o.files.length;return{value:o.root,label:c,meta:[o.context?.branch,v>0?i("rightSidebar.repoChangedCount",{count:v}):null,w>0?i("rightSidebar.repoStagedCount",{count:w}):null].filter(Boolean).join(" · ")}})},[Re,R,le,st,x,i]),ye=a.useMemo(()=>ce&&Ft.some(t=>t.value===ce)?ce:Kt?.repoRoot&&Ft.some(t=>t.value===Kt.repoRoot)?Kt.repoRoot:Ft.length===1||Ft.length>1?Ft[0].value:null,[ce,Ft,Kt?.repoRoot]),jc=ye?ct.get(ye)??null:null,fe=jc?.context?.available?jc.context:ye===R?.root?R:null,Ze=Ft.length>0&&!ye,Rc=a.useMemo(()=>Ze?[]:ye?Array.from(Re.values()).filter(t=>gt(t,x)===ye):Array.from(Re.values()),[ye,Re,Ze,x]),vn=a.useMemo(()=>cu(Rc),[Rc]),oi=!!(fe?.available&&fe.root&&ye&&fe.root===ye),dh=ye?Ft.find(t=>t.value===ye)?.label??kt(ye):i("rightSidebar.gitRepositoryPlaceholder"),Cc=oi?fe?.branch??"HEAD":Ze?i("rightSidebar.selectRepositoryForGitActions"):ln?i("rightSidebar.gitActionRunning"):"HEAD",Vn=!!(fe?.available&&fe.root===ye&&fe.status);a.useEffect(()=>{jl.current={count:Tt.length,loading:Xs,loadingMore:Js,hasMore:jo}},[Tt.length,jo,Xs,Js]),a.useEffect(()=>{Hr.current+=1,or.current?.abort(),Ct("right-sidebar-recent-commits"),or.current=null,rn(""),ar([]),ls(!1),cs(!1),Mn(null),En(!1)},[ye]);const ws=a.useCallback(async(t={})=>{if(!x||!ye||Ze)return;const o=t.reset??!1,c=jl.current,w=o?0:c.count;if(!o&&(c.loading||c.loadingMore||!c.hasMore))return;const v=Hr.current+1;Hr.current=v,or.current?.abort(),Ct("right-sidebar-recent-commits");const k=new AbortController;or.current=k,o?ls(!0):cs(!0),Mn(null);try{const S=await gm({cwd:x,repoRoot:ye,limit:Og,skip:w,query:is.trim(),requestSlotId:"right-sidebar-recent-commits"},k.signal);if(Hr.current!==v)return;if(!S.available){Mn(S.error??"Recent commits are unavailable"),o&&ar([]),En(!1);return}Ye(se=>o?S.commitSyncStatus??{}:{...se,...S.commitSyncStatus}),ar(se=>o?S.commits:[...se,...S.commits]),En(S.hasMore)}catch(S){if(Hr.current!==v||hr(S))return;Mn(S instanceof Error?S.message:"Failed to load recent commits"),o&&ar([]),En(!1)}finally{or.current===k&&(or.current=null),Hr.current===v&&(ls(!1),cs(!1))}},[ye,is,Ze,x]);a.useEffect(()=>{en&&ws({reset:!0})},[is,ws,en,fe?.ahead,fe?.behind,fe?.upstream]);const uh=a.useCallback(t=>{const o=t.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||ws({reset:!1})},[ws]);a.useEffect(()=>{!ye||!R?.available||!lt||!ir||Vn||ln||Ze||Xo(ye)},[ye,R?.available,Vn,ln,lt,ir,Xo,Ze]),a.useEffect(()=>{!r||!Rt&&!lt||!x||dr()},[Rt,lt,r,dr,x]),a.useEffect(()=>{!r||!lt||!ir||!ds||!x||va(null)},[ds,lt,ir,r,va,x]);const fh=a.useMemo(()=>{if(!ce)return 0;const t=Ne.findIndex(o=>o.root===ce);return t>=0?t+1:0},[ce,Ne]),Nc=a.useCallback(t=>{if(!t)return null;const o=Array.from(Re.values()).filter(c=>gt(c,x)===t).sort((c,w)=>c.path.localeCompare(w.path))[0];return o?yt(o):null},[Re,x]),wn=Ne.length>1,Na=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:Re.size,branch:null,deferred:!1},...Ne.map(t=>({root:t.root,label:t.label,count:t.deferred?vs.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!vs.has(t.root)}))],[Re.size,Ne,vs,i]),Mc=Na[fh]??Na[0],Ma=!!ce,Ec=a.useMemo(()=>Ju(Ne,le),[Ne,le]);a.useEffect(()=>{qo.current===x&&ce&&!Ec.has(ce)&&Pe(null),Cn(t=>t.filter(o=>Ne.some(c=>c.root===o)))},[ce,Ne,Ec,x,Pe]),a.useEffect(()=>{ce&&Ca(ct.get(ce))},[ce,Ca,ct]);const hh=a.useMemo(()=>{const t=new Set;fe?.branch&&t.add(fe.branch);for(const o of fe?.branches??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[fe?.branch,fe?.branches,i]),$c=a.useMemo(()=>{const t=new Set;fe?.upstreamRemote&&t.add(fe.upstreamRemote);for(const o of fe?.remotes??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===fe?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[fe?.remotes,fe?.upstreamRemote,i]),Ac=$c.length>1,mh=a.useMemo(()=>{const t=[],o=new Set,c=(v,k)=>{!v||o.has(v)||(o.add(v),t.push({value:v,label:v,meta:k}))};c(fe?.upstreamBranch,fe?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),c(fe?.branch,fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of fe?.branches??[])c(v,v===fe?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const w=fe?.upstreamRemote;for(const v of fe?.remoteBranches??[]){const k=v.indexOf("/"),S=k>=0?v.slice(0,k):null,se=k>=0?v.slice(k+1):v;(!w||S===w)&&c(se,"remote")}return t},[fe?.branch,fe?.branches,fe?.remoteBranches,fe?.upstreamBranch,fe?.upstreamRemote,i]),Vt=a.useMemo(()=>Ft.map(t=>{const o=ct.get(t.value);return{root:t.value,label:t.label,branch:o?.context?.branch??null}}),[Ft,ct]);a.useEffect(()=>{Vt.length!==0&&(ea(t=>{let o=!1;const c={...t},w=new Set(Vt.map(v=>v.root));for(const v of Object.keys(c))w.has(v)||(delete c[v],o=!0);for(const v of Vt)!c[v.root]&&v.branch&&(c[v.root]=v.branch,o=!0);return o?c:t}),ta(t=>{let o=!1;const c={...t},w=new Set(Vt.map(v=>v.root));for(const v of Object.keys(c))w.has(v)||(delete c[v],o=!0);for(const v of Vt){const k=ct.get(v.root)?.context;if(c[v.root]&&Zu(c[v.root],k?.branch)&&(delete c[v.root],o=!0),c[v.root])continue;const S=Qd(k);S&&(c[v.root]=S,o=!0)}return o?c:t}))},[Vt,ct]);const Ea=a.useMemo(()=>{const t=new Set(Vt.map(o=>o.root));return Qs.filter(o=>t.has(o))},[Qs,Vt]),$a=Ea.length===0,fr=a.useMemo(()=>$a?Vt:Vt.filter(t=>Ea.includes(t.root)),[Vt,Ea,$a]),ys=a.useMemo(()=>fr.filter(t=>!!Et[t.root]?.trim()),[Et,fr]),qn=a.useCallback((t,o)=>{const c=ct.get(t)?.context?.branch;return!!(c&&o&&o.replace(/^refs\/heads\//,"")===c)},[ct]),Lc=a.useMemo(()=>fr.filter(t=>!Et[t.root]?.trim()),[Et,fr]),Pc=a.useCallback(async t=>{if(!t||Wo.current.has(t))return;const o=ct.get(t)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const c=x;Wo.current.add(t),Nl(w=>new Set(w).add(t));try{const w=await md(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!w.available||!Ce(c))return;Ee(v=>v.map(k=>k.root===t?{...k,available:!0,context:{...k.context,...w},error:void 0}:k)),ea(v=>v[t]||!w.branch?v:{...v,[t]:w.branch}),ta(v=>{if(v[t])return v;const k=Qd(w);return k?{...v,[t]:k}:v})}catch(w){hr(w)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,w)}finally{Wo.current.delete(t),Nl(w=>{const v=new Set(w);return v.delete(t),v})}},[ct,Ce,x]);a.useEffect(()=>{if(Ro)for(const t of fr)Pc(t.root)},[Ro,fr,Pc]),a.useEffect(()=>{!oi||!fe||(oa(fe.branch||(fe.branches?.[0]??"")),ia(fe.upstreamRemote||(fe.remotes?.includes("origin")?"origin":fe.remotes?.[0]??"")),la(fe.upstreamBranch||fe.branch||(fe.branches?.[0]??"")))},[fe,oi]);const Tc=a.useMemo(()=>{if(Ze)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Vn||ln)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!fe?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=fe.ahead??0,o=fe.behind??0;return t>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:t,behind:o}),className:"bg-destructive/10 text-destructive"}:t>0?{text:i("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[fe?.ahead,fe?.behind,fe?.upstream,Vn,ln,Ze,i]),ph=a.useCallback(t=>{if(t&&!ne){const o=t.currentTarget.getBoundingClientRect();Te({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Te(null);I?.()},[ne,I]),ii=a.useCallback(()=>{Te(null),_?.()},[_]);function Ic(){if(!wn)return null;const t=Mc?.label??i("rightSidebar.allRepositories"),o=Mc?.count??Re.size,c=kt(t)||t;return e.jsxs("button",{type:"button",onClick:ph,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${y?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":y,title:t,children:[e.jsx(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:c}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Os,{size:12,className:"shrink-0"})]})}function gh(){if(!y||!wn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,c=Math.max(12,Math.min(tt?.x??t-368,t-352)),w=Math.max(12,Math.min(tt?.y??80,o-420)),v=ne?void 0:{left:c,top:w},k=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ne?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:ii,children:e.jsxs("div",{className:ne?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:v,onClick:S=>S.stopPropagation(),children:[e.jsxs("div",{className:ne?"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:ne?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ne&&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:Na.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Re.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Re.size})]})]}),e.jsx("button",{type:"button",onClick:ii,className:ne?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Yt,{size:ne?16:14})})]}),e.jsx("div",{className:ne?"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:Na.map(S=>{const se=(S.root??null)===ce,Q=kt(S.label)||S.label;return e.jsxs("button",{type:"button",onClick:()=>{td(S.root),ii()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ne?"px-3 py-2":"px-2 py-1.5"} ${se?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:S.label,role:"option","aria-selected":se,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${se?"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 ${se?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Pr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ne?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:Q}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:S.root===null?i("rightSidebar.allRepositories"):S.label})]}),S.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:S.branch}),S.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${S.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:S.count})]},S.root??"all")})})]})});return _u(k,ne,document.body)}function bh(){return gh()}function Dc(t){const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path),w=io(c,o??x);return{key:yt(t),path:t.path,absolutePath:c,displayName:w.name,displayDir:w.dir,oldPath:t.oldPath,status:t.status,title:c}}function Fc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function Aa(t,o){const c=yn(t,x),w=`path:${c}`,v=ke===w,k=nt===w,S=v||k;return e.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),Gt(c,w)},...ei(ka(c),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 ${S?"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"} ${S?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(k?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function _c(t){const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path),w=Wh(t),v=Bi(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Gb,{actions:w,running:Ue,completed:$n?.path===v?$n:null}),Aa(c,i("rightSidebar.insertThisFile"))]})}function Bc(t,o){const c=o.root??x;if(!c)return null;const w=yn(t,c);return Aa(w,i("fileTree.insertRefTitle"))}function ks(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>Yc("unified"),"aria-pressed":Ut==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ut==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>Yc("split"),"aria-pressed":Ut==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Ut==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function Oc(){return Ss.map(t=>{const o=lu(t.files.map(([,k])=>k)),c=tl({activeGitRepoRoot:ce,groupCount:Ss.length,label:t.label,rootName:st}),w=!!(c&&t.root&&vr.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])=>Dc(k)),header:c?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:()=>Ih(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(za,{size:13}):e.jsx(Os,{size:13})}),e.jsx(Pr,{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}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ba("stage-all",t.root,t.label)},disabled:!!Ue,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),Ba("stash-all",t.root,t.label)},disabled:!!Ue,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function Uc(){return Re.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:Pa.map(([,t])=>{const o=gt(t,x),c=t.absolutePath||(o?`${o}/${t.path}`:t.path);return{key:yt(t),path:t.path,absolutePath:c,status:t.status,repoRoot:o,displayName:io(c,o).name,displayDir:io(c,o).dir,auditRecords:Mt}})}function Hc(t){const o=Array.from(Re.values()).find(v=>yt(v)===t.key),c=o?gt(o,x):null,w=yp(Mt,c,o?.path??t.path);return e.jsx(Xi,{changeStatus:t.status,auditStatus:w,renderChangeBadge:v=>e.jsx(Ds,{status:v})})}const La=a.useCallback(t=>{if(ne)return null;const o=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const w=t.getBoundingClientRect().top+48;let v=null,k=Number.POSITIVE_INFINITY;for(const se of o){const Q=se.getBoundingClientRect();if(Q.bottom<w)continue;const me=Math.abs(Q.top-w);me<k&&(v=se,k=me)}const S=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return S?(ba.current===S&&J.getState().selectedFilePath===S||(ba.current=S,it(S)),S):null},[ne,it]),xh=!!(!Ue&&ye&&!Ze&&(fe?.upstream||cn.trim()&&dn.trim())),vh=!!(!Ue&&ye&&!Ze&&(fe?.upstream||cn.trim()&&dn.trim())),wh=!!(!Ue&&ye&&!Ze&&Ln.trim()&&Ln.trim()!==fe?.branch),qt=a.useMemo(()=>{const t=Be.trim().toLowerCase(),o=Array.from(Re.entries()).filter(([,c])=>!ce||gt(c,x)===ce).sort(([c],[w])=>c.localeCompare(w));return t?o.filter(([c,w])=>`${c} ${w.path} ${w.status} ${w.repoRelativeRoot??""} ${w.repoName??""}`.toLowerCase().includes(t)):o},[ce,Re,Be,x]);a.useEffect(()=>{to("selected_file_state",{selectedFilePath:ot,selectedChangedFilePath:Kt?.path??null,selectedChangedFileAbsolutePath:Kt?.absolutePath??null,selectedChangedFileRepoRoot:Kt?.repoRoot??null,rootPath:x,activeGitRepoRoot:ce,rightTab:Bo,effectiveRightTab:ur,diffPaneActive:Rt,changedFiles:Re.size,filteredChangedFiles:qt.length,gitBundleLoading:lr,gitBundleLastLoadedAt:Dn})},[ce,Re.size,Rt,ur,qt.length,Dn,lr,Bo,x,Kt?.absolutePath,Kt?.path,Kt?.repoRoot,ot]);const Ss=a.useMemo(()=>{const t=new Map;for(const o of qt){const[,c]=o,w=gt(c,x),v=zb(c)||st,k=w??v,S=w?ct.get(w):void 0,se=t.get(k)??{root:w,label:v,branch:S?.context?.branch,files:[]};se.files.push(o),t.set(k,se)}return Array.from(t.values()).sort((o,c)=>o.label===st?-1:c.label===st?1:o.label.localeCompare(c.label))},[qt,ct,st,x]),Pa=a.useMemo(()=>{const t=[],o=new Map;for(const c of qt)o.set(yt(c[1]),c);for(const c of Ss){if(!!(c.root&&tl({activeGitRepoRoot:ce,groupCount:Ss.length,label:c.label,rootName:st})&&vr.has(c.root)))continue;if(kr!=="tree"){t.push(...c.files);continue}const v=c.files.map(([,k])=>Dc(k));for(const k of Ym(v)){const S=o.get(k.key);S&&t.push(S)}}return t},[ce,vr,kr,Ss,qt,st]);a.useEffect(()=>{if(!Rt||Pa.length===0||ne)return;const t=[],o=()=>{const c=document.querySelector(".termdock-diff-stream-scroller");if(c&&La(c))return;const w=document.querySelector("[data-diff-stream-item]"),v=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;if(v){ba.current=v,it(v);return}const k=Pa[0]?.[1];if(!k)return;const S=yt(k);ba.current=S,it(S)};for(const c of[80,240,600,1200])t.push(window.setTimeout(o,c));return()=>t.forEach(c=>window.clearTimeout(c))},[Rt,ne,Pa,it,La]);const li=a.useMemo(()=>{const t=S=>`'${S.replace(/'/g,"'\\''")}'`,o=tr.length>0?pn:le.filter(S=>S.files.length>0),c=o.length>0?o:x?[{root:x,relativeRoot:".",name:st}]:[],w=c.length>0?c.map(S=>`- ${S.relativeRoot==="."?".":S.relativeRoot} (${S.root})`).join(`
1667
1667
  `):`- ${x?".":""}`,v=c.length>0?c.map(S=>` td audit-export ${t(S.root)}`).join(`
1668
- `):" td audit-export",k=c.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${x??""}`,"目标仓库:",y,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",v,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",k,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
1669
- `)},[tr.length,pn,le,st,x]),yh=a.useCallback((t="generate")=>{if(yn&&Br.length===0&&!ce){Xr(!0);return}const o=t==="generate"?li:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",li].join(`
1670
- `);dt("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:tr,mode:t,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Lr(i("rightSidebar.insertChangeAuditPrompt"),o,`${gc}:${t}`),dr(),d||l()},[ce,li,Br.length,tr,Lr,dr,l,d,x,yn,i]),Ta=a.useCallback(async t=>{try{await pd({ids:[t]}),Yr(o=>o.filter(c=>c.id!==t))}catch{dr()}},[dr]),wh=a.useCallback(async()=>{if(Mt.length===0)return;const t=Mt.map(o=>o.id);try{await pd({ids:t}),Yr(o=>o.filter(c=>!t.includes(c.id))),_r(null)}catch(o){const c=o instanceof Error?o.message:"Failed to clear change audit explanations";_r(i("rightSidebar.changeAuditClearFailed",{message:c})),dr()}},[Mt,dr,i]),kh=a.useCallback(async t=>{if(t.records.length===0)return;const o=t.records.map(c=>c.id);try{await gm({ids:o}),Or(c=>c.filter(y=>!o.includes(y.id))),Xe===t.key&&(sn(null),nr(!1))}catch(c){vt(i("rightSidebar.branchAuditClearFailed",{message:c instanceof Error?c.message:"Failed to clear branch explanation"})),va(null)}},[va,Xe,i]),Sh=a.useCallback(t=>{Cn(o=>t===null?(Xr(!1),[]):o.includes(t)?o.filter(c=>c!==t):[...o,t])},[]),jh=a.useCallback(t=>{No(o=>t===null?(Co(!1),[]):o.includes(t)?o.filter(c=>c!==t):[...o,t])},[]),ci=a.useMemo(()=>{if(!ir)return[];const t=o=>{const c=o.diff??"";let y=0,v=0;for(const k of c.split(`
1671
- `))k.startsWith("+++")||k.startsWith("---")||(k.startsWith("+")&&(y+=1),k.startsWith("-")&&(v+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:y,deletions:v,diff:c}};return be?(be.hunks??[]).map(o=>{const c=be.comparisonRepos&&be.comparisonRepos.length>1?[...be.comparisonRepos].sort((v,k)=>k.label.length-v.label.length).find(v=>o.filePath.startsWith(`${v.label}/`)):void 0,y=Jt.find(v=>v.repoRoot===be.repoRoot&&v.baseRef===be.baseRef&&(v.branchName??null)===(be.currentBranch??null)&&v.filePath===o.filePath&&v.hunkHeader===o.hunkHeader&&(v.hunkIndex??0)===o.hunkIndex&&v.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,repoRoot:c?.repoRoot??be.repoRoot,repositoryPath:c?o.filePath.slice(c.label.length+1):o.filePath,hunk:o.previewRevert&&!qn(o.previewRevert.cwd,o.previewRevert.comparisonBranch)?{...o,previewRevert:void 0}:o,current:y,stale:null}}):Xe?Jt.filter(o=>Xd(o)===Xe).map(o=>{const c=t(o);return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex??0}`,hunk:c,current:o,stale:null}}):[]},[be,Jt,qn,ir,Xe]),di=Jt.length>0,Yn=a.useMemo(()=>{if(!ir)return[];const t=new Map;for(const o of Jt){const c=o.repoRoot,y=ct.get(c),v=y?.relativeRoot==="."?st:y?.relativeRoot||y?.name||kt(c),k=Xd(o),S=t.get(k)??{key:k,repoRoot:c,repoLabel:v,baseRef:o.baseRef,branchName:o.branchName??null,headRef:o.headRef??null,diffFingerprint:o.diffFingerprint??null,records:[],latestInjectedAt:0};S.records.push(o),S.latestInjectedAt=Math.max(S.latestInjectedAt,o.injectedAt??0),t.set(k,S)}return Array.from(t.values()).sort((o,c)=>c.latestInjectedAt-o.latestInjectedAt)},[Jt,ct,ir,st]),ui=a.useMemo(()=>Xe?Yn.find(t=>t.key===Xe)??null:null,[Yn,Xe]),js=be?{repoRoot:be.repoRoot??"",repoLabel:be.repoRoot?ct.get(be.repoRoot)?.relativeRoot==="."?st:ct.get(be.repoRoot)?.relativeRoot||ct.get(be.repoRoot)?.name||kt(be.repoRoot):st,baseRef:be.baseRef??be.baseBranch??"",branchName:be.currentBranch??null,headRef:be.headRef??null,diffFingerprint:be.diffFingerprint??null}:ui,Rh=a.useMemo(()=>(qe?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,repoRoot:qe?.repoRoot,hunk:t,current:null,stale:null})),[qe?.hunks,qe?.repoRoot]),Ch=a.useMemo(()=>{if(be)return[];const t=ui;return t?ns.filter(o=>o.repoRoot===t.repoRoot&&o.baseRef===t.baseRef&&(o.branchName??null)===t.branchName&&(!t.diffFingerprint||o.diffFingerprint===t.diffFingerprint)):[]},[be,ns,ui]),Nh=a.useCallback(t=>{const o=ci.find(c=>c.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${c.hunk.filePath}`===t.filePath:!1));o&&(an(o.key),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760))},[ci]),fi=a.useMemo(()=>{const t=v=>`'${v.replace(/'/g,"'\\''")}'`,o=ws,c=o.length>0?o.map(v=>`- ${v.label} (${v.root}),目标分支:${Zt[v.root]||v.branch||"(current branch)"},基线分支:${Et[v.root]||"(not set)"},包含本地未提交更改:${qn(v.root,Zt[v.root]||v.branch)&&(nn[v.root]??!0)?"是":"否"}`).join(`
1672
- `):`- ${x?".":""}`,y=o.length>0?o.map(v=>{const k=Zt[v.root]||v.branch||"",S=Et[v.root]||"",se=v.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[k?` git -C ${t(v.root)} switch ${t(k)}`:` # ${v.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(S)} ${t(v.root)} > ~/.termdock/branch-audit/branch-audit-export-${se}.json`].join(`
1668
+ `):" td audit-export",k=c.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${x??""}`,"目标仓库:",w,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",v,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",k,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
1669
+ `)},[tr.length,pn,le,st,x]),yh=a.useCallback((t="generate")=>{if(wn&&Br.length===0&&!ce){Xr(!0);return}const o=t==="generate"?li:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",li].join(`
1670
+ `);dt("insert_change_audit_prompt",{rootPath:x,activeGitRepoRoots:tr,mode:t,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Lr(i("rightSidebar.insertChangeAuditPrompt"),o,`${bc}:${t}`),dr(),d||l()},[ce,li,Br.length,tr,Lr,dr,l,d,x,wn,i]),Ta=a.useCallback(async t=>{try{await gd({ids:[t]}),Yr(o=>o.filter(c=>c.id!==t))}catch{dr()}},[dr]),kh=a.useCallback(async()=>{if(Mt.length===0)return;const t=Mt.map(o=>o.id);try{await gd({ids:t}),Yr(o=>o.filter(c=>!t.includes(c.id))),_r(null)}catch(o){const c=o instanceof Error?o.message:"Failed to clear change audit explanations";_r(i("rightSidebar.changeAuditClearFailed",{message:c})),dr()}},[Mt,dr,i]),Sh=a.useCallback(async t=>{if(t.records.length===0)return;const o=t.records.map(c=>c.id);try{await bm({ids:o}),Or(c=>c.filter(w=>!o.includes(w.id))),Xe===t.key&&(sn(null),nr(!1))}catch(c){vt(i("rightSidebar.branchAuditClearFailed",{message:c instanceof Error?c.message:"Failed to clear branch explanation"})),va(null)}},[va,Xe,i]),jh=a.useCallback(t=>{Cn(o=>t===null?(Xr(!1),[]):o.includes(t)?o.filter(c=>c!==t):[...o,t])},[]),Rh=a.useCallback(t=>{No(o=>t===null?(Co(!1),[]):o.includes(t)?o.filter(c=>c!==t):[...o,t])},[]),ci=a.useMemo(()=>{if(!ir)return[];const t=o=>{const c=o.diff??"";let w=0,v=0;for(const k of c.split(`
1671
+ `))k.startsWith("+++")||k.startsWith("---")||(k.startsWith("+")&&(w+=1),k.startsWith("-")&&(v+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:w,deletions:v,diff:c}};return be?(be.hunks??[]).map(o=>{const c=be.comparisonRepos&&be.comparisonRepos.length>1?[...be.comparisonRepos].sort((v,k)=>k.label.length-v.label.length).find(v=>o.filePath.startsWith(`${v.label}/`)):void 0,w=Jt.find(v=>v.repoRoot===be.repoRoot&&v.baseRef===be.baseRef&&(v.branchName??null)===(be.currentBranch??null)&&v.filePath===o.filePath&&v.hunkHeader===o.hunkHeader&&(v.hunkIndex??0)===o.hunkIndex&&v.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,repoRoot:c?.repoRoot??be.repoRoot,repositoryPath:c?o.filePath.slice(c.label.length+1):o.filePath,hunk:o.previewRevert&&!qn(o.previewRevert.cwd,o.previewRevert.comparisonBranch)?{...o,previewRevert:void 0}:o,current:w,stale:null}}):Xe?Jt.filter(o=>Jd(o)===Xe).map(o=>{const c=t(o);return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex??0}`,hunk:c,current:o,stale:null}}):[]},[be,Jt,qn,ir,Xe]),di=Jt.length>0,Yn=a.useMemo(()=>{if(!ir)return[];const t=new Map;for(const o of Jt){const c=o.repoRoot,w=ct.get(c),v=w?.relativeRoot==="."?st:w?.relativeRoot||w?.name||kt(c),k=Jd(o),S=t.get(k)??{key:k,repoRoot:c,repoLabel:v,baseRef:o.baseRef,branchName:o.branchName??null,headRef:o.headRef??null,diffFingerprint:o.diffFingerprint??null,records:[],latestInjectedAt:0};S.records.push(o),S.latestInjectedAt=Math.max(S.latestInjectedAt,o.injectedAt??0),t.set(k,S)}return Array.from(t.values()).sort((o,c)=>c.latestInjectedAt-o.latestInjectedAt)},[Jt,ct,ir,st]),ui=a.useMemo(()=>Xe?Yn.find(t=>t.key===Xe)??null:null,[Yn,Xe]),js=be?{repoRoot:be.repoRoot??"",repoLabel:be.repoRoot?ct.get(be.repoRoot)?.relativeRoot==="."?st:ct.get(be.repoRoot)?.relativeRoot||ct.get(be.repoRoot)?.name||kt(be.repoRoot):st,baseRef:be.baseRef??be.baseBranch??"",branchName:be.currentBranch??null,headRef:be.headRef??null,diffFingerprint:be.diffFingerprint??null}:ui,Ch=a.useMemo(()=>(qe?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,repoRoot:qe?.repoRoot,hunk:t,current:null,stale:null})),[qe?.hunks,qe?.repoRoot]),Nh=a.useMemo(()=>{if(be)return[];const t=ui;return t?ns.filter(o=>o.repoRoot===t.repoRoot&&o.baseRef===t.baseRef&&(o.branchName??null)===t.branchName&&(!t.diffFingerprint||o.diffFingerprint===t.diffFingerprint)):[]},[be,ns,ui]),Mh=a.useCallback(t=>{const o=ci.find(c=>c.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${c.hunk.filePath}`===t.filePath:!1));o&&(an(o.key),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760))},[ci]),fi=a.useMemo(()=>{const t=v=>`'${v.replace(/'/g,"'\\''")}'`,o=ys,c=o.length>0?o.map(v=>`- ${v.label} (${v.root}),目标分支:${Qt[v.root]||v.branch||"(current branch)"},基线分支:${Et[v.root]||"(not set)"},包含本地未提交更改:${qn(v.root,Qt[v.root]||v.branch)&&(nn[v.root]??!0)?"是":"否"}`).join(`
1672
+ `):`- ${x?".":""}`,w=o.length>0?o.map(v=>{const k=Qt[v.root]||v.branch||"",S=Et[v.root]||"",se=v.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[k?` git -C ${t(v.root)} switch ${t(k)}`:` # ${v.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(S)} ${t(v.root)} > ~/.termdock/branch-audit/branch-audit-export-${se}.json`].join(`
1673
1673
  `)}).join(`
1674
- `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${x??""}`,"每个仓库分别遵循下面列出的本地未提交更改选项。","目标仓库:",c,"","操作指令:","1. 只针对上面列出的目标仓库导出分支 hunk,按各仓库所选目标分支与基线对比。本地未提交更改标记为是的仓库纳入 staged/unstaged/untracked 改动;标记为否的仓库只解释提交改动,忽略导出中混入的本地改动。嵌套子仓或软链接子仓使用括号内的仓库绝对路径。示例:",y,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:x??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
1675
- `)},[nn,qn,ws,Et,Zt,x]),Mh=a.useCallback((t="generate")=>{const o=t==="generate"?fi:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",fi].join(`
1676
- `);Lr(i("rightSidebar.branchAuditShort"),o,`context:branch-audit-scope:${t}`),d||l()},[fi,Lr,l,d,i]),hi=a.useCallback(async(t={})=>{const o=t.refresh===!0,c=o&&be?.comparisonRepos?be.comparisonRepos:ws.map(S=>{const se=(Zt[S.root]||S.branch||"").trim();return{repoRoot:S.root,label:S.label,base:Et[S.root]?.trim()??"",head:se||null,includeUncommitted:nn[S.root]??!0}});if(!x||c.length===0)return;const y=++z.current,v=x,k=()=>Ce(v)&&y===z.current;Fe(!0),_e(null),o||(Qt(null),ft(null));try{const S=await Promise.all(c.map(async G=>{if(!G.base)throw new Error(i("rightSidebar.branchAuditMissingBase",{repo:G.label}));return gd({cwd:x,repoRoot:G.repoRoot,base:G.base,head:G.head,includeUncommitted:t.repoRoot===G.repoRoot?t.includeUncommitted??!1:G.includeUncommitted??be?.includeUncommitted??!0,requestSlotId:`right-sidebar-branch-preview:${G.repoRoot}`})}));if(!k())return;const se=S.find(G=>!G.available);if(se){_e(se.error??"Branch diff is unavailable");return}const Z=S.length===1?S[0]:{available:!0,workspaceRoot:x,repoRoot:x,baseRef:S.map(G=>G.baseRef??G.baseBranch).filter(Boolean).join(", "),currentBranch:S.map(G=>G.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:S.map(G=>G.headRef).filter(Boolean).join(", "),diffFingerprint:S.map(G=>G.diffFingerprint).filter(Boolean).join("+"),stat:S.map(G=>G.stat).filter(Boolean).join(`
1674
+ `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${x??""}`,"每个仓库分别遵循下面列出的本地未提交更改选项。","目标仓库:",c,"","操作指令:","1. 只针对上面列出的目标仓库导出分支 hunk,按各仓库所选目标分支与基线对比。本地未提交更改标记为是的仓库纳入 staged/unstaged/untracked 改动;标记为否的仓库只解释提交改动,忽略导出中混入的本地改动。嵌套子仓或软链接子仓使用括号内的仓库绝对路径。示例:",w,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:x??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
1675
+ `)},[nn,qn,ys,Et,Qt,x]),Eh=a.useCallback((t="generate")=>{const o=t==="generate"?fi:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",fi].join(`
1676
+ `);Lr(i("rightSidebar.branchAuditShort"),o,`context:branch-audit-scope:${t}`),d||l()},[fi,Lr,l,d,i]),hi=a.useCallback(async(t={})=>{const o=t.refresh===!0,c=o&&be?.comparisonRepos?be.comparisonRepos:ys.map(S=>{const se=(Qt[S.root]||S.branch||"").trim();return{repoRoot:S.root,label:S.label,base:Et[S.root]?.trim()??"",head:se||null,includeUncommitted:nn[S.root]??!0}});if(!x||c.length===0)return;const w=++z.current,v=x,k=()=>Ce(v)&&w===z.current;Fe(!0),_e(null),o||(Zt(null),ft(null));try{const S=await Promise.all(c.map(async G=>{if(!G.base)throw new Error(i("rightSidebar.branchAuditMissingBase",{repo:G.label}));return bd({cwd:x,repoRoot:G.repoRoot,base:G.base,head:G.head,includeUncommitted:t.repoRoot===G.repoRoot?t.includeUncommitted??!1:G.includeUncommitted??be?.includeUncommitted??!0,requestSlotId:`right-sidebar-branch-preview:${G.repoRoot}`})}));if(!k())return;const se=S.find(G=>!G.available);if(se){_e(se.error??"Branch diff is unavailable");return}const Q=S.length===1?S[0]:{available:!0,workspaceRoot:x,repoRoot:x,baseRef:S.map(G=>G.baseRef??G.baseBranch).filter(Boolean).join(", "),currentBranch:S.map(G=>G.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:S.map(G=>G.headRef).filter(Boolean).join(", "),diffFingerprint:S.map(G=>G.diffFingerprint).filter(Boolean).join("+"),stat:S.map(G=>G.stat).filter(Boolean).join(`
1677
1677
  `),files:S.flatMap((G,Y)=>{const je=c[Y];return(G.files??[]).map(Me=>`${je?.label??G.repoRoot??"repo"}/${Me}`)}),hunks:S.flatMap((G,Y)=>{const Me=c[Y]?.label??G.repoRoot??"repo";return(G.hunks??[]).map(He=>({...He,filePath:`${Me}/${He.filePath}`,oldPath:He.oldPath?`${Me}/${He.oldPath}`:He.oldPath,newPath:He.newPath?`${Me}/${He.newPath}`:He.newPath}))}),commits:S.flatMap(G=>G.commits??[]),commitCount:S.reduce((G,Y)=>G+(Y.commitCount??Y.commits?.length??0),0),diff:S.map(G=>G.diff).filter(Boolean).join(`
1678
- `),truncated:S.some(G=>G.truncated)};if(Z.comparisonRepos=c.map((G,Y)=>({...G,head:G.head??S[Y].currentBranch??null,includeUncommitted:S[Y].includeUncommitted===!0,canIncludeUncommitted:S[Y].canIncludeUncommitted})),Z.canIncludeUncommitted=S.every(G=>G.canIncludeUncommitted===!0),Z.includeUncommitted=S.some(G=>G.includeUncommitted===!0),Mo(G=>({...G,...Object.fromEntries(Z.comparisonRepos.map(Y=>[Y.repoRoot,Y.includeUncommitted??!1]))})),!o&&(Z.hunks??[]).length===0){_e(i("rightSidebar.branchAuditDiffEmpty"));return}const me=Date.now(),$e=(o?Xe:null)??["preview",Z.repoRoot??x,Z.baseRef??Z.baseBranch??"",Z.currentBranch??"",Z.headRef??"",Z.diffFingerprint??me].join("\0"),Je=c.length===1?c[0].label:`${c.length} repos`;Qt(Z),Qr(G=>[{key:$e,diff:Z,repoLabel:Je,createdAt:me},...G.filter(Y=>Y.key!==$e)].slice(0,8)),o||P(G=>G[$e]===void 0?G:{...G,[$e]:0}),sn($e),an(G=>{const Y=Z.hunks?.[0],je=Y?`${Y.filePath}\0${Y.hunkHeader}\0${Y.hunkIndex}`:null;return o&&G&&(Z.hunks??[]).some(Me=>Me.filePath===G.split("\0")[0])?G:je}),nr(!0)}catch(S){if(!k()||hr(S))return;_e(S instanceof Error?S.message:"Failed to load branch diff")}finally{k()&&Fe(!1)}},[nn,be,Xe,ws,Et,Zt,Ce,x,i]),Eh=a.useCallback(t=>{++z.current,Fe(!1),Qt(t.diff),_e(null),sn(t.key),an(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),nr(!0)},[]),$h=a.useCallback(t=>{Qr(o=>o.filter(c=>c.key!==t)),P(o=>{if(!(t in o))return o;const c={...o};return delete c[t],c}),Xe===t&&(sn(null),Qt(null),nr(!1))},[Xe]),Ah=a.useCallback(t=>{++z.current,Fe(!1);const o=Yn.find(c=>c.key===t);o&&(Qt(null),_e(null),sn(t),an(o.records[0]?.filePath??null),nr(!0))},[Yn]),Lh=a.useCallback(async t=>{if(!x||!we)return;const[o]=t.split(/\s+/);if(o){sr(o),Zr(null),ft(null);try{const c=await bm({cwd:x,repoRoot:we,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!c.available){Zr(c.error??"Commit diff is unavailable");return}ft(c);const y=c.hunks?.[0];Qs(y?`${y.filePath}\0${y.hunkHeader}\0${y.hunkIndex}`:null)}catch(c){Zr(c instanceof Error?c.message:"Failed to load commit diff")}finally{sr(null)}}},[we,x]),Ph=a.useCallback(t=>{if(!be||!Xe)return;const o=Math.max(0,Math.round(t));P(c=>Math.abs((c[Xe]??0)-o)<24?c:{...c,[Xe]:o})},[be,Xe]);a.useEffect(()=>{!be||!Xe||Qr(t=>t.map(o=>o.key===Xe&&o.diff!==be?{...o,diff:be}:o))},[be,Xe]);const Hc=!!be;a.useEffect(()=>{if(!ne||!Rr||!Hc)return;const t=tc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const o=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(o)},[Rr,Hc,ne]);const zc=a.useCallback(t=>{t&&Kf(o=>Ym(o,t))},[]),Wc=ua.key===ot?ua.key:null,Ia=a.useCallback(t=>{const o=J.getState(),c=tx();to("select_diff_file",{interactionId:c,path:t,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:ce,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),it(t),er("diff"),ne&&t&&sc(1),zc(t),queueMicrotask(()=>{const y=J.getState();to("select_diff_file_after",{interactionId:c,requestedPath:t,selectedFilePath:y.selectedFilePath,rootPath:y.rootPath,rightTab:y.rightTab,changedFiles:y.changedFiles.size,activeGitRepoRoot:ce})})},[ce,ne,zc,it,er,sc]),Gc=a.useCallback(t=>{const o=Array.from(Re.values()).find(c=>{const y=gt(c,x),v=wt(c);return c.path===t.filePath||v===t.filePath||c.absolutePath===t.filePath||(y?`${y}/${c.path}`===t.filePath:!1)||t.repoRoot&&y===t.repoRoot&&c.path===t.filePath});if(o){Ia(wt(o)),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760);return}kn(t)},[Re,x,Ia]),Kc=a.useCallback(({slideToDetail:t,fullscreen:o,toggleFullscreen:c}={})=>ts.length>0?e.jsx(wu,{walkthroughs:ts,repoRoot:ce,fullscreen:o,onToggleFullscreen:c,onNavigate:y=>{ne&&window.requestAnimationFrame(()=>t?.()),Gc(y)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(Hs,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[ce,ts,Gc,ne,i]),Th=a.useCallback(t=>{t&&yr(o=>{const c=new Set(o);return c.has(t)?c.delete(t):c.add(t),$i(Ci,c),c})},[]),Vc=a.useCallback(t=>{wr(o=>{const c=new Set(o);return c.has(t)?c.delete(t):c.add(t),$i(Od,c),c})},[]),Da=a.useCallback(t=>{Vs(t),At(Bu,t)},[]);a.useEffect(()=>{Ma||kr!=="ai"||Da("tree")},[kr,Da,Ma]);const Fa=a.useCallback(()=>{es(t=>{const o=!t;return At(Ou,o),o})},[]),qc=a.useCallback(t=>{qs(t),At(Uu,t)},[]),{whitespace:Yc,context:Xc}=Jm(),Jc=a.useMemo(()=>({algorithm:"histogram",whitespace:Yc,context:Xc}),[Yc,Xc]),Qc=a.useCallback(t=>{V(t),At(Hu,t)},[]),_a=a.useCallback(async(t,o,c,y)=>{let v=t;for(;v.ok&&v.status==="running";)await new Promise(S=>window.setTimeout(S,1500)),v=await bd({jobId:v.jobId,cwd:o.cwd,action:o.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const k={action:o.action,path:y,label:c};return fs(k),window.setTimeout(()=>fs(S=>S?.action===k.action&&S.path===k.path?null:S),1400),v},[]),yt=a.useCallback(async(t,o,c)=>{const y=x;x&&cr.current.delete(x),vt(null),fs(null),us({action:t.action,path:c});try{const v=await xm({...t,includeNested:Es(x)}),k=await _a(v,t,o,c);if(!Ce(y))return!1;const S=x?await wi(x,void 0,{includeNested:Es(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:As(x)}).catch(()=>k.bundle):k.bundle;return Ce(y)?(S&&Un(S,{reloadDiff:!0,cacheOnly:!0}),on(null),!0):!1}catch(v){return fs(null),vt(i("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{Ce(y)&&us(null)}},[Un,Ce,x,i,_a]),Zc=a.useCallback(async t=>{const o=x;await xd({...t,includeNested:Es(x)}),Ce(o)&&It(x??void 0,{refresh:!0,background:!0})},[Ce,It,x]),Ih=a.useCallback(async t=>{const o=be,c=z.current,y=o?.hunks?.find(k=>k.previewRevert?.cwd===t.cwd&&k.previewRevert.path===t.path);if(!o||!y||!t.comparisonBase)throw new Error(i("diffViewer.hunkActionUnavailable"));Se(k=>k+1),_e(null);try{await xd(t)}catch(k){throw Se(S=>S-1),k}if(c!==z.current||!Ce(x)){Se(k=>k-1);return}const v=k=>{Qt(S=>{if(!S||c!==z.current)return S;const se=S.hunks??[],Z=k===void 0?se.filter($e=>!($e.previewRevert?.cwd===t.cwd&&$e.previewRevert.patch===t.patch)):[...se.filter($e=>$e.filePath!==y.filePath),...k];return{...S,hunks:Z}})};v(),gd({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(c!==z.current||!Ce(x))return;if(!k.available||k.truncated)throw new Error(k.error??i("diffViewer.hunkActionUnavailable"));const S=t.path.slice(t.cwd.length+1),se=y.filePath.slice(0,y.filePath.length-S.length);v((k.hunks??[]).map(Z=>({...Z,filePath:`${se}${Z.filePath}`,oldPath:Z.oldPath?`${se}${Z.oldPath}`:Z.oldPath,newPath:Z.newPath?`${se}${Z.newPath}`:Z.newPath})))}).catch(k=>{c===z.current&&Ce(x)&&!hr(k)&&_e(`${i("diffViewer.hunkActionReverted")} · ${k instanceof Error?k.message:String(k)}`)}).finally(()=>Se(k=>k-1))},[be,Ce,x,i]),Ba=a.useCallback((t,o,c)=>{if(o){if(t==="stage-all"){yt({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}on({kind:"stash-all",repoRoot:o,repoLabel:c})}},[yt,i]),ed=a.useCallback(t=>{Pe(t),oa(""),ia(""),la(""),it(Cc(t)),lt||er("diff"),t&&Ca(ct.get(t))},[Ca,Cc,lt,ct,it,Pe,er]),td=a.useCallback(t=>{const o=new Set([...Wt.current.keys(),...hn.current,...cr.current]);for(const c of o)c!==t&&(zt.current.delete(c),Wt.current.get(c)?.abort(),Wt.current.delete(c),Ct(`right-sidebar-git-untracked:${c}`),hn.current.delete(c),cr.current.delete(c))},[]),Dh=a.useCallback(async t=>{const o=x;if(!o||(await J.getState().setNestedGitScanRoot(o,t),!Ce(o)))return;if(t){await It(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}td(o),oa(""),ia(""),la(""),No(y=>y.filter(v=>v===o));const c=Kt;c&&gt(c,o)!==o&&it(null),await It(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[td,Ce,It,x,it,Kt]),Fh=a.useCallback(async()=>{if(!we||Qe){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Ln.trim();!t||t===fe?.branch||await yt({action:"switch-branch",cwd:we,branch:t},i("rightSidebar.switchBranch"))},[fe?.branch,we,Qe,yt,Ln,i]),rd=a.useCallback(async()=>{if(!we||Qe){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=aa.trim();if(!t)return;await yt({action:"commit",cwd:we,message:t},i("rightSidebar.commitChanges"))&&Pl("")},[we,aa,Qe,yt,i]),_h=a.useCallback(async()=>{if(!we||Qe){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=cn.trim(),o=dn.trim();await yt({action:"push",cwd:we,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[we,dn,cn,Qe,yt,i]),Bh=a.useCallback(async()=>{if(!we||Qe){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=cn.trim(),o=dn.trim();await yt({action:"pull",cwd:we,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[we,dn,cn,Qe,yt,i]);a.useEffect(()=>{if(!lt||!we||Ue)return;let t=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const c of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const y=await bd({cwd:we,action:c}).catch(()=>null);if(!y?.ok||y.status!=="running")continue;const v={action:c,cwd:we},k=o[c]??c;us({action:c});try{const S=await _a(y,v,k);if(t||!Ce(x))return;const se=x?await wi(x,void 0,{includeNested:Es(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:As(x)}).catch(()=>S.bundle):S.bundle;se&&Un(se,{reloadDiff:!0,cacheOnly:!0})}catch(S){t||vt(i("rightSidebar.gitActionFailed",{message:S instanceof Error?S.message:"Unknown error"}))}finally{t||us(null)}return}})(),()=>{t=!0}},[we,Un,lt,Ce,x,Ue,i,_a]);const mi=$n?.action==="commit",pi=$n?.action==="switch-branch",gi=$n?.action==="pull",bi=$n?.action==="push",Oa=lt||Wf,xi=$a?i("rightSidebar.changeAuditScopeAll"):fr.length===1?fr[0].label:`${fr.length} repos`,Oh=fr.length>0,nd=ws.length>0,Uh=x?e.jsx(su,{open:Ro,onOpenChange:Co,showScopePicker:!0,selectedAll:$a,repos:Vt,selectedRoots:Ea,onToggleRepo:jh,onGenerate:()=>Mh(di?"regenerate":"generate"),disabled:!Oh,generateDisabled:!nd,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(di?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:xi,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(di?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{hi()},secondaryDisabled:!nd||et,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:et,loading:Rl.size>0,statusTitle:Rl.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:Ac.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:i("rightSidebar.missingBaseReposSkipped",{repositories:Ac.map(t=>t.label).join(O==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const o=ct.get(t.root),c=qn(t.root,Zt[t.root]||o?.context?.branch),y=[],v=new Set,k=(me,$e)=>{!me||v.has(me)||(v.add(me),y.push({value:me,label:me,meta:$e}))};k(Zt[t.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const me of o?.context?.branches??[])k(me,me===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const me of o?.context?.remoteBranches??[])k(me,i("rightSidebar.remoteBranch"));const S=[],se=new Set,Z=(me,$e)=>{!me||se.has(me)||(se.add(me),S.push({value:me,label:me,meta:$e}))};Z(Et[t.root],Et[t.root]?i("rightSidebar.pushUpstreamBadge"):void 0),Z(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const me of o?.context?.remoteBranches??[])Z(me,"remote");for(const me of o?.context?.branches??[])Z(me,me===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Jn,{label:i("rightSidebar.currentBranchLabel"),value:Zt[t.root]||o?.context?.branch||"",options:y,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:me=>{ea($e=>({...$e,[t.root]:me}))}}),e.jsx(Jn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Et[t.root]||"",options:S,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:me=>{ta($e=>({...$e,[t.root]:me}))}}),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:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i(c?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:c&&(nn[t.root]??!0),disabled:!c,onChange:me=>Mo($e=>({...$e,[t.root]:me.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,sd=Ls(Mt.reduce((t,o)=>Math.max(t,o.injectedAt??0),0),O),Hh=x?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>jl(t=>{const o=!t;return At(Ni,o),o}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":ds,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(Hs,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:xi})]}),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 ${ds?"rotate-90":""}`,children:e.jsx(za,{size:13})})]}),ds&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[i("rightSidebar.changeAuditScopeLabel"),": ",xi]}),Uh]}),Ve&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Ve}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Jr.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Xe===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:()=>Eh(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:i("rightSidebar.branchAuditViewDiff")})]}),Ls(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Ls(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>$h(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:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(no,{size:12})})]},t.key)),Yn.length>0?Yn.slice(0,Math.max(0,8-Jr.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Xe===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:()=>Ah(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})]}),Ls(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Ls(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{kh(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:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(no,{size:12})})]},t.key)):Jr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,ad=ir&&x&&Vn?e.jsxs("div",{className:Oa?"overflow-visible":"overflow-hidden",children:[Hh,e.jsxs("button",{type:"button",onClick:()=>{lt||Gf(t=>{const o=!t;return o&&we&&!Vn&&!ln&&Xo(we),o})},"aria-expanded":Oa,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(Pr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${vn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[ln&&e.jsx(Nt,{size:10,className:"animate-spin"}),vn.staged>0?i("rightSidebar.stagedCount",{count:vn.staged}):i("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 ${Oa?"rotate-90":""}`,children:e.jsx(za,{size:13})})]})]}),Oa&&e.jsxs("div",{className:"space-y-0",children:[Ft.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:ch})]})}),e.jsx(Jn,{label:i("rightSidebar.gitRepositoryLabel"),value:we??"",options:Ft,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!Ue,onChange:t=>{ed(t||null)}}),Qe&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:i("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Ln!==Rc?Rc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{Fh()},disabled:!vh,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 ${pi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ue?.action==="switch-branch"||pi?"opacity-0":"",children:i("rightSidebar.switchBranch")}),Ue?.action==="switch-branch"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),pi&&Ue?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Jn,{label:i("rightSidebar.currentBranchLabel"),value:Ln,options:fh,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!Ue,onChange:oa})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Qe?i("rightSidebar.selectRepositoryForGitActions"):vn.staged>0?i("rightSidebar.commitReadyHint",{count:vn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{rd()},disabled:!!Ue||Qe||vn.staged===0||!aa.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 ${mi?"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:Qe?i("rightSidebar.selectRepositoryForGitActions"):vn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ue?.action==="commit"||mi?"opacity-0":"",children:i("rightSidebar.commitChanges")}),Ue?.action==="commit"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),mi&&Ue?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:aa,onChange:t=>Pl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),rd())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!Ue,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:()=>Ur(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":en,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Xs&&e.jsx(Nt,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${en?"rotate-90":""}`,children:e.jsx(za,{size:13})})]})]}),en&&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(Qn,{size:12,className:"shrink-0"}),e.jsx("input",{value:tn,onChange:t=>rn(t.target.value),placeholder:i("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),tn&&e.jsx("button",{type:"button",onClick:()=>rn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Yt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:dh,children:[Tt.length>0?Tt.map(t=>{const[o,...c]=t.split(/\s+/),y=c.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{Lh(t)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:y,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:y,children:y}),Q[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Q[o]==="ahead"?"bg-accent/10 text-accent":Q[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Q[o]==="ahead"?"rightSidebar.commitAhead":Q[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),Nn===o&&e.jsx(Nt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):Xs?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):So?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),Js&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(Nt,{size:12,className:"animate-spin"})}),jo&&!Js&&Tt.length>0&&e.jsx("button",{type:"button",onClick:()=>{ys({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:i("rightSidebar.recentCommitsLoadMore")})]})]}),os&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:os}),So&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:So})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Bh()},disabled:!bh,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 ${gi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ue?.action==="pull"||gi?"opacity-0":"",children:i("rightSidebar.pullChanges")}),Ue?.action==="pull"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),gi&&Ue?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{_h()},disabled:!xh,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 ${bi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ue?.action==="push"||bi?"opacity-0":"",children:i("rightSidebar.pushChanges")}),Ue?.action==="push"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),bi&&Ue?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${Pc.className}`,title:fe?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:Pc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:fe?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${$c?"grid-cols-2":"grid-cols-1"}`,children:[$c&&e.jsx(Jn,{label:i("rightSidebar.pushRemoteLabel"),value:cn,options:Ec,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!Ue,onChange:ia}),e.jsx(Jn,{label:i("rightSidebar.pushBranchLabel"),value:dn,options:hh,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:fe?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!Ue,onChange:la})]})]})]})]}):null,zh=a.useCallback(t=>{const o=gt(t,x);if(!o)return[];const c=_i(t),y=[];return t.canStage&&y.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{yt({action:"stage-file",cwd:o,paths:[t.path]},i("rightSidebar.stageFile"),c)}}),t.canUnstage&&y.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{yt({action:"unstage-file",cwd:o,paths:[t.path]},i("rightSidebar.unstageFile"),c)}}),t.canStash&&y.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{yt({action:"stash-file",cwd:o,paths:[t.path]},i("rightSidebar.stashFile"),c)}}),t.canRestoreWorktree&&y.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>on({kind:"restore",file:t,phrase:""})}),y},[x,yt,i]),Wh=a.useCallback(()=>{if(m){j?.();return}Nr(0),Er.current?.slideTo(0),Cr(!1),bt(null)},[j,m]),od=a.useCallback(t=>{if(K(""),Ht(t),it(null),bt(null),te(null),ne){m&&j?.(),Nr(0),Er.current?.slideTo(0),Cr(!1);return}},[ne,j,m,it,Ht]);a.useEffect(()=>{const t=o=>{const c=o.detail,y=c?.path;if(typeof y!="string"||!y.startsWith("/"))return;K(""),bt(null),Lt(null);const v=!!(x&&(y===x||y.startsWith(`${x}/`)));if(c.kind==="file"){const k=Ii(y);gs(y),typeof c.line=="number"&&Number.isSafeInteger(c.line)&&c.line>0&&Lt(c.line),Ht(v?null:k),te(S=>({path:y,nonce:(S?.nonce??0)+1}));return}it(null),v?(Ht(null),te(k=>({path:y,nonce:(k?.nonce??0)+1}))):(te(null),Ht(y)),ne&&(m&&j?.(),Nr(0),Er.current?.slideTo(0),Cr(!1))};return window.addEventListener(Sd,t),()=>window.removeEventListener(Sd,t)},[gs,ne,j,m,x,it,Ht]),a.useEffect(()=>{r||(Ot(!1),br(!1))},[r]),a.useEffect(()=>{if(!pr&&!gr)return;const t=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(Ot(!1),br(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[gr,pr]);const id=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:oh,disabled:!ja,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(gu,{size:14})}),e.jsx("button",{type:"button",onClick:bc,disabled:!x||Tn===x,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(jd,{size:14})}),e.jsx("button",{type:"button",onClick:ih,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.refreshFiles"),title:Tl?i("rightSidebar.fileWatchUnavailable",{message:Tl}):i("rightSidebar.refreshFiles"),children:e.jsx(so,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:sh}),pa==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(Rd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&Gt(ge,Dt??void 0),disabled:!ge,...ge&&Dt?ei(ka(ge),Dt):{},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 ${Dt&&(ke===Dt||nt===Dt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Dt&&nt===Dt?"rightSidebar.copied":Dt&&ke===Dt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Dt&&(ke===Dt||nt===Dt)?e.jsx(Hi,{size:13}):e.jsx(co,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Ot(!1),br(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${gr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":gr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(lo,{size:14})}),gr&&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:()=>{br(!1),lh()},disabled:!si,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${xs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[xs?e.jsx(Si,{size:14}):e.jsx(Wa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(xs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{br(!1),Vf()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Oo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Oo?e.jsx(tp,{size:14}):e.jsx(Vi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(Oo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(br(!1),qf(ge,pa==="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:[pa==="modified"?e.jsx(Bm,{size:14}):e.jsx(Rd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(pa==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),x&&(Ra.length>0||ah)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:bc,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 ${ge===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(jd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:st})]}),Ra.map(t=>{const o=t.path,c=t.kind==="file",y=c?ot===o:ge===o;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${y?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o,children:[e.jsxs("button",{type:"button",onClick:()=>c?gs(o):Ht(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[c?e.jsx(qi,{size:10,className:"shrink-0"}):e.jsx(Wa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:kt(o)})]}),e.jsx("button",{type:"button",onClick:()=>un(o),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":i("rightSidebar.unpinFolder",{name:kt(o)}),title:i("rightSidebar.unpinFolder",{name:kt(o)}),children:e.jsx(Yt,{size:9})})]},o)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),vi=a.useMemo(()=>{if(An===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((To-An)/1e3)),c=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[y,v]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return c.format(y,v)},[To,An]),Gh=x&&!zn?e.jsx("button",{type:"button",onClick:()=>{Dh(!Uo)},"aria-pressed":Uo,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${Uo?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,ld=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[vi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:vi}),children:vi}):null,e.jsx("button",{type:"button",onClick:()=>{Hn()},disabled:lr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx(so,{size:13,className:lr?"animate-spin":""})})]}):null,Kh=nc?i("rightSidebar.changeAuditScopeAll"):pn.length===1?pn[0].relativeRoot==="."?st:pn[0].relativeRoot||pn[0].name:`${pn.length} repos`,Vh=x?e.jsxs("div",{className:"inline-flex min-h-9 shrink-0 items-center",children:[e.jsx(su,{open:rs,onOpenChange:Xr,showScopePicker:yn,selectedAll:nc,repos:Yf,selectedRoots:tr,onToggleRepo:Sh,onGenerate:()=>yh(),disabled:!x,inserted:ke===gc,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Kh,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:Fr,error:!!jr,statusTitle:jr??(Fr?i("rightSidebar.changeAuditLoading"):Mt.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Mt.length})}${sd?` · ${i("rightSidebar.changeAuditLoadedAt",{time:sd})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{wh()},disabled:Fr||Mt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Mt.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(no,{size:12})})]}):null,Rs=rr??(R?.available&&x&&Re.size>0&&le.length<=1?{root:x,label:st}:null),cd=e.jsxs(e.Fragment,{children:[Rs&&e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Ba("stage-all",Rs.root,Rs.label),disabled:!!Ue,className:"flex-1 rounded-md bg-accent/10 px-2 py-1 text-[11px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>Ba("stash-all",Rs.root,Rs.label),disabled:!!Ue,className:"flex-1 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground hover:bg-surface disabled:opacity-50",children:i("rightSidebar.stashAll")})]}),Gh,Vh]}),Ua=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[R?.available&&R.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:R.branch,children:[e.jsx(Pr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:R.branch})]}),ht.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[ht.modified,"M"]}),ht.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",ht.added]}),ht.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",ht.deleted]}),ht.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ht.renamed,"R"]}),ht.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ht.copied,"C"]}),ht.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ht.untracked,"U"]}),ht.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[ht.conflicted,"!"]}),ht.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ht.other,"?"]}),ht.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:ht.staged})})]});return e.jsxs(Om,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:u,push:d,pinned:h,children:[ei.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${Qf?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:x??void 0,children:st}),(!ne||Ao)&&R?.available&&R.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:R.branch,children:[e.jsx(Pr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:R.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!xe;W(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):K("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${xe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Qn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Ie,onClick:()=>{ze(t=>!t),Bt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Ie?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(Um,{size:14}),!Ie&&ve.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:_l,type:"file",multiple:!0,className:"hidden",onChange:t=>{const o=t.target.files;!o||o.length===0||(bs(Array.from(o)),t.target.value="")}}),e.jsx("input",{ref:Bl,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const o=t.target.files?.[0];t.target.value="",o&&th(o)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(Si,{size:14}):e.jsx(Wa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{br(!1),Ot(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${pr?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":pr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(lo,{size:15})}),pr&&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":zr,onClick:()=>eh(!zr),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(vd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${zr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${zr?"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:()=>{Ot(!1),_l.current?.click()},disabled:ca,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:[ca?e.jsx(Nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(up,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ot(!1),Bl.current?.click()},disabled:ca,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:[ca?e.jsx(Nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(ap,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ot(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(Si,{size:14}):e.jsx(Wa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([t,o])=>{const c=X===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":c,onClick:()=>{L(t),Ot(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${c?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:o},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":i("rightSidebar.close"),children:e.jsx(Yt,{size:14})})]}),xe&&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(Qn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:C,onChange:t=>K(t.target.value),placeholder:i(F==="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 ${ne?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Qc("name"),"aria-pressed":F==="name",className:`rounded-full px-2 transition active:scale-95 ${ne?"py-1":"py-0.5"} ${F==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Qc("content"),"aria-pressed":F==="content",className:`rounded-full px-2 transition active:scale-95 ${ne?"py-1":"py-0.5"} ${F==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),C&&e.jsx("button",{type:"button",onClick:()=>K(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Yt,{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(Hm,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:re,onChange:t=>ie(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:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),re!=="."&&e.jsx("button",{type:"button",onClick:()=>ie("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Yt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>N(t=>!t),"aria-expanded":De,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${De||hs.length>0||q||Ae||Le?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(zm,{size:13}),hs.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:hs.length})]})]}),De&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ye,onChange:t=>pe(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ye&&e.jsx("button",{type:"button",onClick:()=>pe(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Yt,{size:11})})]}),F==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[q,()=>he(t=>!t),Zm,i("rightSidebar.matchCase")],[Ae,()=>Ze(t=>!t),hp,i("rightSidebar.matchWholeWord")],[Le,()=>at(t=>!t),ip,i("rightSidebar.useRegex")]].map(([t,o,c,y])=>e.jsxs("button",{type:"button",onClick:o,"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(c,{size:12}),y]},y))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(zn?2:3)+(zr?1:0)}, minmax(0, 1fr))`},children:[!zn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>er("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Pr,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>er("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Mu,{size:12}),i("rightSidebar.tabChanges"),Re.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Re.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>er("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Vm,{size:12}),i("rightSidebar.tabFiles")]}),zr&&e.jsxs("button",{type:"button",onClick:()=>er("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(vd,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),Al&&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:Al})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Za,{active:lt,mounted:ir,fallback:e.jsx(Ti,{slow:!1}),children:qe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Ld,{items:Rh,diffViewType:Do,inlineMode:Xt,viewControls:h?ks():void 0,renderPathReference:(t,o)=>Aa(wn(t,qe.repoRoot??x),i(o==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:Bf,onSelect:Qs,emptyText:i("rightSidebar.noChanges"),mobile:ne,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${qe.headRef??""}${qe.commits?.[0]?` · ${qe.commits[0]}`:""}`,onClose:()=>{ft(null),Qs(null)},closeLabel:i("common.back"),wrap:Pt,onToggleWrap:Fa,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ne?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta})}):Rr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Ld,{items:ci,diffViewType:Do,inlineMode:Xt,viewControls:h?ks():void 0,renderPathReference:(t,o)=>{const c=be?.comparisonRepos,y=c&&c.length>1?[...c].sort((k,S)=>S.label.length-k.label.length).find(k=>t===k.label||t.startsWith(`${k.label}/`)):void 0,v=y?t===y.label?y.repoRoot:wn(t.slice(y.label.length+1),y.repoRoot):wn(t,js?.repoRoot||x);return Aa(v,i(o==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:Eo,onSelect:an,emptyText:i(be?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ne,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(be?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:js?`${js.repoLabel} · ${js.branchName??"HEAD"} → ${js.baseRef}`:void 0,onClose:()=>{++z.current,Fe(!1),nr(!1),Qt(null)},closeLabel:i("common.back"),wrap:Pt,onToggleWrap:Fa,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ne?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,localOptions:be?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??be.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??qn(t.repoRoot,t.head)),onChange:o=>{hi({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:o})}})),onHunkGitAction:be?.includeUncommitted?Ih:void 0,error:Ve,actionsBusy:ue>0,onRefresh:()=>{hi({refresh:!0})},refreshing:et,refreshLabel:i("rightSidebar.branchAuditRefreshDiff"),refreshTitle:i("rightSidebar.branchAuditRefreshDiff"),walkthroughs:Ch,onWalkthroughNavigate:Nh,initialDetailScrollTop:be&&Xe?as[Xe]:void 0,onDetailScrollPositionChange:Ph,externalSwiperRef:ne?tc:void 0,onMobileSlideChange:ne?$o:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:ad?e.jsx("div",{className:"px-3",children:ad}):lr?e.jsx(Ti,{slow:Vl}):fn?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):cu(R)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):R?.available===!1?e.jsx(eo,{message:R.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{Hn()}}):x?e.jsx(Ti,{slow:Vl}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Za,{active:Wn,children:ne?e.jsxs(xu,{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=>{Er.current=t,t.slideTo(Nl,0)},onSlideChange:t=>{if(Nr(t.activeIndex),ps.current===t.activeIndex){ps.current=null;return}t.activeIndex===0&&(Cr(!1),bt(null),j?.())},children:[e.jsx(zi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Fn,onScroll:oc,onDragOver:ya,onDragEnter:ya,onDragLeave:cc,onDrop:dc,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[Il&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&id,e.jsx(Cd,{rootPath:ge??"",onFileSelect:gs,onPathReference:Gt,getReferenceText:ka,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onDirectoryRoot:xc,onSearchFromDirectory:vc,onDirectoryPinToggle:yc,onFilePinToggle:wc,pinnedPaths:bn,selectedFilePath:ot,query:Be,searchRootPath:Jl,searchOptions:Ql,searchMode:F,onContentMatchSelect:ic,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:de,canOpenInFileBrowser:Dl,onOpenInFileBrowser:lc})]})}),e.jsx(zi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(cl,{filePath:Wn&&(Of||Nl===1)?ot:null,onInsertReference:Gt,onInsertText:Ar,onInsertFeature:Ar,onReviewReference:mc,onReferenceCopied:$r,onClose:Wh,onDirectoryLinkOpen:od,isMobile:!0,lineRange:Rn,onLineRangeChange:bt,insertedReferenceKey:ke,copiedReferenceKey:nt,scrollToLine:Ge,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Fn,onScroll:oc,onDragOver:ya,onDragEnter:ya,onDragLeave:cc,onDrop:dc,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Fo},children:[Il&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&id,e.jsx(Cd,{rootPath:ge??"",onFileSelect:gs,onPathReference:Gt,getReferenceText:ka,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onDirectoryRoot:xc,onSearchFromDirectory:vc,onDirectoryPinToggle:yc,onFilePinToggle:wc,pinnedPaths:bn,selectedFilePath:ot,query:Be,searchRootPath:Jl,searchOptions:Ql,searchMode:F,onContentMatchSelect:ic,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:de,canOpenInFileBrowser:Dl,onOpenInFileBrowser:lc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Xf,onPointerMove:Jf,onPointerUp:ac,onPointerCancel:ac,onDoubleClick:()=>{_o(Zi),At(Ps,Zi)},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(cl,{filePath:Wn?ot:null,onInsertReference:Gt,onInsertText:Ar,onInsertFeature:Ar,onReviewReference:mc,onReferenceCopied:$r,onDirectoryLinkOpen:od,isMobile:!1,lineRange:Rn,onLineRangeChange:bt,insertedReferenceKey:ke,copiedReferenceKey:nt,scrollToLine:Ge,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})]})}),e.jsx(Za,{active:Rt,mounted:Uf||Rt,children:()=>Jo?e.jsx(Wm,{}):ne?e.jsx(Wi,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:Yo,onMobileSlideChange:$o,groups:qt.length>0?Bc():[],mode:kr,onModeChange:Da,selectedKey:ot,scrollToKey:Wc,scrollToKeyNonce:ua.nonce,compact:!1,collapsedDirectoryKeys:Ks,onToggleDirectory:Vc,onSelectFile:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);o&&Ia(wt(o))},renderLeading:Uc,renderTrailing:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);return o?Fc(o):null},renderDirectoryTrailing:_c,renderSubtitle:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);return o?Dc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ua&&e.jsx("div",{className:"mb-2",children:Ua}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[qt.length,"/",Re.size]})]}),e.jsxs($d,{actions:cd,children:[Tc(),t,h&&ks(),ld]},x),rr&&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:rr.label}),rr.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:rr.branch})]}),!rr&&yn&&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(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Ma?(t=>Kc(t)):void 0,emptyContent:Jo?null:fn&&Re.size===0?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):Re.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({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:i("rightSidebar.backToChangeList"),children:[e.jsx(Bs,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[h&&ks(),e.jsxs("button",{type:"button",onClick:Fa,"aria-pressed":Pt,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Pt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(Pt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),x&&e.jsx("button",{type:"button",onClick:()=>{Hn()},disabled:lr,"aria-label":i("rightSidebar.refreshGit"),title:i("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(so,{size:14,className:lr?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:Oc(),activePane:Rt,wrap:Pt,diffViewType:Do,inlineMode:Xt,diffOptions:Jc,reloadKey:Ys,renderStreamBadge:t=>e.jsx(Ds,{status:t}),onHunkGitAction:Zc,onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,onDetailScroll:La}):e.jsx(Wi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:i("rightSidebar.backToChangeList"),groups:qt.length>0?Bc():[],mode:kr,onModeChange:Da,selectedKey:ot,scrollToKey:Wc,scrollToKeyNonce:ua.nonce,compact:!0,collapsedDirectoryKeys:Ks,onToggleDirectory:Vc,onSelectFile:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);o&&Ia(wt(o))},renderLeading:Uc,renderTrailing:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);return o?Fc(o):null},renderDirectoryTrailing:_c,renderSubtitle:t=>{const o=Array.from(Re.values()).find(c=>wt(c)===t.key);return o?Dc(o):null},aiContent:Ma?(t=>Kc(t)):void 0,emptyContent:Jo?null:fn&&Re.size===0?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):Re.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ua&&e.jsx("div",{className:"mb-2",children:Ua}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[qt.length,"/",Re.size]})})]}),e.jsxs($d,{actions:cd,children:[Tc(),t,ks(),e.jsxs("button",{type:"button",onClick:Fa,"aria-pressed":Pt,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Pt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(Pt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),ld]},x),rr&&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:rr.label}),rr.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:rr.branch})]}),!rr&&yn&&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(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:Oc(),activePane:Rt,wrap:Pt,diffViewType:Ut,inlineMode:Xt,diffOptions:Jc,reloadKey:Ys,renderStreamBadge:t=>e.jsx(Ds,{status:t}),onHunkGitAction:Zc,onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,onDetailScroll:La})}),e.jsx(Za,{active:Gn,mounted:Po&&zr,children:Hf?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{yi.getState().setDock(ki,null),ro({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Gm,{sessionId:n??null,onInsertPrompt:t=>Lr("android-deps",t),onInsertFile:nh,onRecordingComplete:rh})})]}),r&&Ie&&e.jsx(_p,{value:ve,collapsed:_t,autoCollapseAfterSend:H,focusRequest:pt,insertError:Ir?i("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{xr(!1),Ke(t)},onCollapsedChange:Bt,onAutoCollapseAfterSendChange:ae,onDisable:()=>ze(!1),onClear:()=>Ke(""),onInsert:()=>pc(!1),onInsertAndSend:()=>pc(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>i("rightSidebar.contextDraftCharacterCount",{count:t})}}),gh(),xt&&typeof document<"u"&&qr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>on(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:xt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:xt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:pu(xt.file.absolutePath,x)}):i("rightSidebar.confirmStashAllDescription")}),xt.kind==="restore"&&e.jsx("input",{value:xt.phrase,onChange:t=>on({...xt,phrase:t.target.value}),placeholder:i("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>on(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ue||xt.kind==="restore"&&xt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(xt.kind==="restore"){const t=gt(xt.file,x);if(!t)return;yt({action:"restore-worktree-file",cwd:t,paths:[xt.file.path],confirm:{acknowledged:!0,phrase:xt.phrase}},i("rightSidebar.restoreFile"),_i(xt.file))}else{const t=xt.repoRoot??x;if(!t)return;yt({action:"stash-all",cwd:t},i("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${xt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(Ue?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const gx=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:cl,MarkdownImageLightbox:Cf,MarkdownPreview:Nf,RightSidebar:sx,__testParseMarkdownListBlock:wb,buildMarkdownPreviewBlocks:Lb,buildMarkdownPreviewRenderResult:yl,collectKnownGitRepoRoots:Xu,computeMarkdownImageDisplayBox:cf,getMarkdownHeadingOutline:Rf,getMarkdownHeadingPathAtLine:jf,getNextMarkdownPreviewLineRange:_b,isSvgImageSrc:yo,mountRightSidebarRepoPickerOverlay:Fu,replaceGitRepositorySnapshot:Pf,resolveMarkdownLocalLinkTarget:ml,resolveRightSidebarDiffViewType:qu,shouldCloseMarkdownImageLightboxDrag:wf,showsGitRepoGroupHeader:el},Symbol.toStringTag,{value:"Module"}));export{Vi as E,gx as R,tp as a,gp as c,px as m};
1678
+ `),truncated:S.some(G=>G.truncated)};if(Q.comparisonRepos=c.map((G,Y)=>({...G,head:G.head??S[Y].currentBranch??null,includeUncommitted:S[Y].includeUncommitted===!0,canIncludeUncommitted:S[Y].canIncludeUncommitted})),Q.canIncludeUncommitted=S.every(G=>G.canIncludeUncommitted===!0),Q.includeUncommitted=S.some(G=>G.includeUncommitted===!0),Mo(G=>({...G,...Object.fromEntries(Q.comparisonRepos.map(Y=>[Y.repoRoot,Y.includeUncommitted??!1]))})),!o&&(Q.hunks??[]).length===0){_e(i("rightSidebar.branchAuditDiffEmpty"));return}const me=Date.now(),$e=(o?Xe:null)??["preview",Q.repoRoot??x,Q.baseRef??Q.baseBranch??"",Q.currentBranch??"",Q.headRef??"",Q.diffFingerprint??me].join("\0"),Je=c.length===1?c[0].label:`${c.length} repos`;Zt(Q),Zr(G=>[{key:$e,diff:Q,repoLabel:Je,createdAt:me},...G.filter(Y=>Y.key!==$e)].slice(0,8)),o||P(G=>G[$e]===void 0?G:{...G,[$e]:0}),sn($e),an(G=>{const Y=Q.hunks?.[0],je=Y?`${Y.filePath}\0${Y.hunkHeader}\0${Y.hunkIndex}`:null;return o&&G&&(Q.hunks??[]).some(Me=>Me.filePath===G.split("\0")[0])?G:je}),nr(!0)}catch(S){if(!k()||hr(S))return;_e(S instanceof Error?S.message:"Failed to load branch diff")}finally{k()&&Fe(!1)}},[nn,be,Xe,ys,Et,Qt,Ce,x,i]),$h=a.useCallback(t=>{++z.current,Fe(!1),Zt(t.diff),_e(null),sn(t.key),an(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),nr(!0)},[]),Ah=a.useCallback(t=>{Zr(o=>o.filter(c=>c.key!==t)),P(o=>{if(!(t in o))return o;const c={...o};return delete c[t],c}),Xe===t&&(sn(null),Zt(null),nr(!1))},[Xe]),Lh=a.useCallback(t=>{++z.current,Fe(!1);const o=Yn.find(c=>c.key===t);o&&(Zt(null),_e(null),sn(t),an(o.records[0]?.filePath??null),nr(!0))},[Yn]),Ph=a.useCallback(async t=>{if(!x||!ye)return;const[o]=t.split(/\s+/);if(o){sr(o),Qr(null),ft(null);try{const c=await xm({cwd:x,repoRoot:ye,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!c.available){Qr(c.error??"Commit diff is unavailable");return}ft(c);const w=c.hunks?.[0];Zs(w?`${w.filePath}\0${w.hunkHeader}\0${w.hunkIndex}`:null)}catch(c){Qr(c instanceof Error?c.message:"Failed to load commit diff")}finally{sr(null)}}},[ye,x]),Th=a.useCallback(t=>{if(!be||!Xe)return;const o=Math.max(0,Math.round(t));P(c=>Math.abs((c[Xe]??0)-o)<24?c:{...c,[Xe]:o})},[be,Xe]);a.useEffect(()=>{!be||!Xe||Zr(t=>t.map(o=>o.key===Xe&&o.diff!==be?{...o,diff:be}:o))},[be,Xe]);const zc=!!be;a.useEffect(()=>{if(!ne||!Rr||!zc)return;const t=rc.current;if(!t||t.destroyed)return;t.update(),t.slideTo(1,0);const o=window.requestAnimationFrame(()=>{t.destroyed||(t.update(),t.slideTo(1,0))});return()=>window.cancelAnimationFrame(o)},[Rr,zc,ne]);const Wc=a.useCallback(t=>{t&&Vf(o=>Xm(o,t))},[]),Gc=ua.key===ot?ua.key:null,Ia=a.useCallback(t=>{const o=J.getState(),c=rx();to("select_diff_file",{interactionId:c,path:t,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:ce,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),it(t),er("diff"),ne&&t&&ac(1),Wc(t),queueMicrotask(()=>{const w=J.getState();to("select_diff_file_after",{interactionId:c,requestedPath:t,selectedFilePath:w.selectedFilePath,rootPath:w.rootPath,rightTab:w.rightTab,changedFiles:w.changedFiles.size,activeGitRepoRoot:ce})})},[ce,ne,Wc,it,er,ac]),Kc=a.useCallback(t=>{const o=Array.from(Re.values()).find(c=>{const w=gt(c,x),v=yt(c);return c.path===t.filePath||v===t.filePath||c.absolutePath===t.filePath||(w?`${w}/${c.path}`===t.filePath:!1)||t.repoRoot&&w===t.repoRoot&&c.path===t.filePath});if(o){Ia(yt(o)),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760);return}kn(t)},[Re,x,Ia]),Vc=a.useCallback(({slideToDetail:t,fullscreen:o,toggleFullscreen:c}={})=>ts.length>0?e.jsx(ku,{walkthroughs:ts,repoRoot:ce,fullscreen:o,onToggleFullscreen:c,onNavigate:w=>{ne&&window.requestAnimationFrame(()=>t?.()),Kc(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(Hs,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[ce,ts,Kc,ne,i]),Ih=a.useCallback(t=>{t&&wr(o=>{const c=new Set(o);return c.has(t)?c.delete(t):c.add(t),Ai(Ni,c),c})},[]),qc=a.useCallback(t=>{yr(o=>{const c=new Set(o);return c.has(t)?c.delete(t):c.add(t),Ai(Ud,c),c})},[]),Da=a.useCallback(t=>{Vs(t),At(Ou,t)},[]);a.useEffect(()=>{Ma||kr!=="ai"||Da("tree")},[kr,Da,Ma]);const Fa=a.useCallback(()=>{es(t=>{const o=!t;return At(Uu,o),o})},[]),Yc=a.useCallback(t=>{qs(t),At(Hu,t)},[]),{whitespace:Xc,context:Jc}=Zm(),Zc=a.useMemo(()=>({algorithm:"histogram",whitespace:Xc,context:Jc}),[Xc,Jc]),Qc=a.useCallback(t=>{V(t),At(zu,t)},[]),_a=a.useCallback(async(t,o,c,w)=>{let v=t;for(;v.ok&&v.status==="running";)await new Promise(S=>window.setTimeout(S,1500)),v=await xd({jobId:v.jobId,cwd:o.cwd,action:o.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const k={action:o.action,path:w,label:c};return fs(k),window.setTimeout(()=>fs(S=>S?.action===k.action&&S.path===k.path?null:S),1400),v},[]),wt=a.useCallback(async(t,o,c)=>{const w=x;x&&cr.current.delete(x),vt(null),fs(null),us({action:t.action,path:c});try{const v=await vm({...t,includeNested:Es(x)}),k=await _a(v,t,o,c);if(!Ce(w))return!1;const S=x?await ki(x,void 0,{includeNested:Es(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:As(x)}).catch(()=>k.bundle):k.bundle;return Ce(w)?(S&&Un(S,{reloadDiff:!0,cacheOnly:!0}),on(null),!0):!1}catch(v){return fs(null),vt(i("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{Ce(w)&&us(null)}},[Un,Ce,x,i,_a]),ed=a.useCallback(async t=>{const o=x;await vd({...t,includeNested:Es(x)}),Ce(o)&&It(x??void 0,{refresh:!0,background:!0})},[Ce,It,x]),Dh=a.useCallback(async t=>{const o=be,c=z.current,w=o?.hunks?.find(k=>k.previewRevert?.cwd===t.cwd&&k.previewRevert.path===t.path);if(!o||!w||!t.comparisonBase)throw new Error(i("diffViewer.hunkActionUnavailable"));Se(k=>k+1),_e(null);try{await vd(t)}catch(k){throw Se(S=>S-1),k}if(c!==z.current||!Ce(x)){Se(k=>k-1);return}const v=k=>{Zt(S=>{if(!S||c!==z.current)return S;const se=S.hunks??[],Q=k===void 0?se.filter($e=>!($e.previewRevert?.cwd===t.cwd&&$e.previewRevert.patch===t.patch)):[...se.filter($e=>$e.filePath!==w.filePath),...k];return{...S,hunks:Q}})};v(),bd({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(c!==z.current||!Ce(x))return;if(!k.available||k.truncated)throw new Error(k.error??i("diffViewer.hunkActionUnavailable"));const S=t.path.slice(t.cwd.length+1),se=w.filePath.slice(0,w.filePath.length-S.length);v((k.hunks??[]).map(Q=>({...Q,filePath:`${se}${Q.filePath}`,oldPath:Q.oldPath?`${se}${Q.oldPath}`:Q.oldPath,newPath:Q.newPath?`${se}${Q.newPath}`:Q.newPath})))}).catch(k=>{c===z.current&&Ce(x)&&!hr(k)&&_e(`${i("diffViewer.hunkActionReverted")} · ${k instanceof Error?k.message:String(k)}`)}).finally(()=>Se(k=>k-1))},[be,Ce,x,i]),Ba=a.useCallback((t,o,c)=>{if(o){if(t==="stage-all"){wt({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}on({kind:"stash-all",repoRoot:o,repoLabel:c})}},[wt,i]),td=a.useCallback(t=>{Pe(t),oa(""),ia(""),la(""),it(Nc(t)),lt||er("diff"),t&&Ca(ct.get(t))},[Ca,Nc,lt,ct,it,Pe,er]),rd=a.useCallback(t=>{const o=new Set([...Wt.current.keys(),...hn.current,...cr.current]);for(const c of o)c!==t&&(zt.current.delete(c),Wt.current.get(c)?.abort(),Wt.current.delete(c),Ct(`right-sidebar-git-untracked:${c}`),hn.current.delete(c),cr.current.delete(c))},[]),Fh=a.useCallback(async t=>{const o=x;if(!o||(await J.getState().setNestedGitScanRoot(o,t),!Ce(o)))return;if(t){await It(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}rd(o),oa(""),ia(""),la(""),No(w=>w.filter(v=>v===o));const c=Kt;c&&gt(c,o)!==o&&it(null),await It(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[rd,Ce,It,x,it,Kt]),_h=a.useCallback(async()=>{if(!ye||Ze){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Ln.trim();!t||t===fe?.branch||await wt({action:"switch-branch",cwd:ye,branch:t},i("rightSidebar.switchBranch"))},[fe?.branch,ye,Ze,wt,Ln,i]),nd=a.useCallback(async()=>{if(!ye||Ze){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=aa.trim();if(!t)return;await wt({action:"commit",cwd:ye,message:t},i("rightSidebar.commitChanges"))&&Tl("")},[ye,aa,Ze,wt,i]),Bh=a.useCallback(async()=>{if(!ye||Ze){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=cn.trim(),o=dn.trim();await wt({action:"push",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[ye,dn,cn,Ze,wt,i]),Oh=a.useCallback(async()=>{if(!ye||Ze){vt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=cn.trim(),o=dn.trim();await wt({action:"pull",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[ye,dn,cn,Ze,wt,i]);a.useEffect(()=>{if(!lt||!ye||Ue)return;let t=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const c of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const w=await xd({cwd:ye,action:c}).catch(()=>null);if(!w?.ok||w.status!=="running")continue;const v={action:c,cwd:ye},k=o[c]??c;us({action:c});try{const S=await _a(w,v,k);if(t||!Ce(x))return;const se=x?await ki(x,void 0,{includeNested:Es(x),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:As(x)}).catch(()=>S.bundle):S.bundle;se&&Un(se,{reloadDiff:!0,cacheOnly:!0})}catch(S){t||vt(i("rightSidebar.gitActionFailed",{message:S instanceof Error?S.message:"Unknown error"}))}finally{t||us(null)}return}})(),()=>{t=!0}},[ye,Un,lt,Ce,x,Ue,i,_a]);const mi=$n?.action==="commit",pi=$n?.action==="switch-branch",gi=$n?.action==="pull",bi=$n?.action==="push",Oa=lt||Gf,xi=$a?i("rightSidebar.changeAuditScopeAll"):fr.length===1?fr[0].label:`${fr.length} repos`,Uh=fr.length>0,sd=ys.length>0,Hh=x?e.jsx(au,{open:Ro,onOpenChange:Co,showScopePicker:!0,selectedAll:$a,repos:Vt,selectedRoots:Ea,onToggleRepo:Rh,onGenerate:()=>Eh(di?"regenerate":"generate"),disabled:!Uh,generateDisabled:!sd,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(di?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:xi,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(di?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{hi()},secondaryDisabled:!sd||et,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:et,loading:Cl.size>0,statusTitle:Cl.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsx("div",{className:"mb-2 space-y-1.5",children:Lc.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:i("rightSidebar.missingBaseReposSkipped",{repositories:Lc.map(t=>t.label).join(O==="zh"?"、":", ")})})}),renderRepoExtra:t=>{const o=ct.get(t.root),c=qn(t.root,Qt[t.root]||o?.context?.branch),w=[],v=new Set,k=(me,$e)=>{!me||v.has(me)||(v.add(me),w.push({value:me,label:me,meta:$e}))};k(Qt[t.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const me of o?.context?.branches??[])k(me,me===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const me of o?.context?.remoteBranches??[])k(me,i("rightSidebar.remoteBranch"));const S=[],se=new Set,Q=(me,$e)=>{!me||se.has(me)||(se.add(me),S.push({value:me,label:me,meta:$e}))};Q(Et[t.root],Et[t.root]?i("rightSidebar.pushUpstreamBadge"):void 0),Q(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const me of o?.context?.remoteBranches??[])Q(me,"remote");for(const me of o?.context?.branches??[])Q(me,me===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Jn,{label:i("rightSidebar.currentBranchLabel"),value:Qt[t.root]||o?.context?.branch||"",options:w,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:me=>{ea($e=>({...$e,[t.root]:me}))}}),e.jsx(Jn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Et[t.root]||"",options:S,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:me=>{ta($e=>({...$e,[t.root]:me}))}}),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:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i(c?"rightSidebar.includeUncommittedHint":"rightSidebar.includeUncommittedCurrentBranchOnly")})]}),e.jsx("input",{type:"checkbox",checked:c&&(nn[t.root]??!0),disabled:!c,onChange:me=>Mo($e=>({...$e,[t.root]:me.target.checked})),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]})]})}}):null,ad=Ls(Mt.reduce((t,o)=>Math.max(t,o.injectedAt??0),0),O),zh=x?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Rl(t=>{const o=!t;return At(Mi,o),o}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":ds,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(Hs,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:xi})]}),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 ${ds?"rotate-90":""}`,children:e.jsx(za,{size:13})})]}),ds&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[i("rightSidebar.changeAuditScopeLabel"),": ",xi]}),Hh]}),Ve&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Ve}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Jr.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Xe===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:()=>$h(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:i("rightSidebar.branchAuditViewDiff")})]}),Ls(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Ls(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>Ah(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:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(no,{size:12})})]},t.key)),Yn.length>0?Yn.slice(0,Math.max(0,8-Jr.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Xe===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:()=>Lh(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})]}),Ls(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Ls(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Sh(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:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(no,{size:12})})]},t.key)):Jr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,od=ir&&x&&Vn?e.jsxs("div",{className:Oa?"overflow-visible":"overflow-hidden",children:[zh,e.jsxs("button",{type:"button",onClick:()=>{lt||Kf(t=>{const o=!t;return o&&ye&&!Vn&&!ln&&Xo(ye),o})},"aria-expanded":Oa,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(Pr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${vn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[ln&&e.jsx(Nt,{size:10,className:"animate-spin"}),vn.staged>0?i("rightSidebar.stagedCount",{count:vn.staged}):i("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 ${Oa?"rotate-90":""}`,children:e.jsx(za,{size:13})})]})]}),Oa&&e.jsxs("div",{className:"space-y-0",children:[Ft.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:dh})]})}),e.jsx(Jn,{label:i("rightSidebar.gitRepositoryLabel"),value:ye??"",options:Ft,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!Ue,onChange:t=>{td(t||null)}}),Ze&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:i("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Ln!==Cc?Cc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{_h()},disabled:!wh,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 ${pi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ue?.action==="switch-branch"||pi?"opacity-0":"",children:i("rightSidebar.switchBranch")}),Ue?.action==="switch-branch"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),pi&&Ue?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Jn,{label:i("rightSidebar.currentBranchLabel"),value:Ln,options:hh,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!Ue,onChange:oa})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Ze?i("rightSidebar.selectRepositoryForGitActions"):vn.staged>0?i("rightSidebar.commitReadyHint",{count:vn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{nd()},disabled:!!Ue||Ze||vn.staged===0||!aa.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 ${mi?"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:Ze?i("rightSidebar.selectRepositoryForGitActions"):vn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ue?.action==="commit"||mi?"opacity-0":"",children:i("rightSidebar.commitChanges")}),Ue?.action==="commit"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),mi&&Ue?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:aa,onChange:t=>Tl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),nd())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!Ue,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:()=>Ur(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":en,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Xs&&e.jsx(Nt,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${en?"rotate-90":""}`,children:e.jsx(za,{size:13})})]})]}),en&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{value:tn,onChange:t=>rn(t.target.value),placeholder:i("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),tn&&e.jsx("button",{type:"button",onClick:()=>rn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Yt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:uh,children:[Tt.length>0?Tt.map(t=>{const[o,...c]=t.split(/\s+/),w=c.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{Ph(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:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:w,children:w}),Z[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Z[o]==="ahead"?"bg-accent/10 text-accent":Z[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Z[o]==="ahead"?"rightSidebar.commitAhead":Z[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),Nn===o&&e.jsx(Nt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):Xs?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):So?null:e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),Js&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(Nt,{size:12,className:"animate-spin"})}),jo&&!Js&&Tt.length>0&&e.jsx("button",{type:"button",onClick:()=>{ws({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:i("rightSidebar.recentCommitsLoadMore")})]})]}),os&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:os}),So&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:So})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Oh()},disabled:!xh,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 ${gi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ue?.action==="pull"||gi?"opacity-0":"",children:i("rightSidebar.pullChanges")}),Ue?.action==="pull"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),gi&&Ue?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Bh()},disabled:!vh,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 ${bi?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ue?.action==="push"||bi?"opacity-0":"",children:i("rightSidebar.pushChanges")}),Ue?.action==="push"&&e.jsx(Nt,{size:12,className:"absolute animate-spin"}),bi&&Ue?.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] ${Tc.className}`,title:fe?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:Tc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:fe?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${Ac?"grid-cols-2":"grid-cols-1"}`,children:[Ac&&e.jsx(Jn,{label:i("rightSidebar.pushRemoteLabel"),value:cn,options:$c,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!Ue,onChange:ia}),e.jsx(Jn,{label:i("rightSidebar.pushBranchLabel"),value:dn,options:mh,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:fe?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!Ue,onChange:la})]})]})]})]}):null,Wh=a.useCallback(t=>{const o=gt(t,x);if(!o)return[];const c=Bi(t),w=[];return t.canStage&&w.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{wt({action:"stage-file",cwd:o,paths:[t.path]},i("rightSidebar.stageFile"),c)}}),t.canUnstage&&w.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{wt({action:"unstage-file",cwd:o,paths:[t.path]},i("rightSidebar.unstageFile"),c)}}),t.canStash&&w.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{wt({action:"stash-file",cwd:o,paths:[t.path]},i("rightSidebar.stashFile"),c)}}),t.canRestoreWorktree&&w.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>on({kind:"restore",file:t,phrase:""})}),w},[x,wt,i]),Gh=a.useCallback(()=>{if(m){j?.();return}Nr(0),Er.current?.slideTo(0),Cr(!1),bt(null)},[j,m]),id=a.useCallback(t=>{if(K(""),Ht(t),it(null),bt(null),te(null),ne){m&&j?.(),Nr(0),Er.current?.slideTo(0),Cr(!1);return}},[ne,j,m,it,Ht]);a.useEffect(()=>{const t=o=>{const c=o.detail,w=c?.path;if(typeof w!="string"||!w.startsWith("/"))return;K(""),bt(null),Lt(null);const v=!!(x&&(w===x||w.startsWith(`${x}/`)));if(c.kind==="file"){const k=Di(w);gs(w),typeof c.line=="number"&&Number.isSafeInteger(c.line)&&c.line>0&&Lt(c.line),Ht(v?null:k),te(S=>({path:w,nonce:(S?.nonce??0)+1}));return}it(null),v?(Ht(null),te(k=>({path:w,nonce:(k?.nonce??0)+1}))):(te(null),Ht(w)),ne&&(m&&j?.(),Nr(0),Er.current?.slideTo(0),Cr(!1))};return window.addEventListener(jd,t),()=>window.removeEventListener(jd,t)},[gs,ne,j,m,x,it,Ht]),a.useEffect(()=>{r||(Ot(!1),br(!1))},[r]),a.useEffect(()=>{if(!pr&&!gr)return;const t=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(Ot(!1),br(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[gr,pr]);const ld=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:ih,disabled:!ja,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(bu,{size:14})}),e.jsx("button",{type:"button",onClick:xc,disabled:!x||Tn===x,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(Rd,{size:14})}),e.jsx("button",{type:"button",onClick:lh,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.refreshFiles"),title:Il?i("rightSidebar.fileWatchUnavailable",{message:Il}):i("rightSidebar.refreshFiles"),children:e.jsx(so,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:ah}),pa==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(Cd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&Gt(ge,Dt??void 0),disabled:!ge,...ge&&Dt?ei(ka(ge),Dt):{},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 ${Dt&&(ke===Dt||nt===Dt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Dt&&nt===Dt?"rightSidebar.copied":Dt&&ke===Dt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Dt&&(ke===Dt||nt===Dt)?e.jsx(zi,{size:13}):e.jsx(co,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Ot(!1),br(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${gr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":gr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(lo,{size:14})}),gr&&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:()=>{br(!1),ch()},disabled:!si,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${xs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[xs?e.jsx(ji,{size:14}):e.jsx(Wa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(xs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{br(!1),qf()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Oo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Oo?e.jsx(rp,{size:14}):e.jsx(qi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(Oo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(br(!1),Yf(ge,pa==="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:[pa==="modified"?e.jsx(Om,{size:14}):e.jsx(Cd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(pa==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),x&&(Ra.length>0||oh)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:xc,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 ${ge===x?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:x,children:[e.jsx(Rd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:st})]}),Ra.map(t=>{const o=t.path,c=t.kind==="file",w=c?ot===o:ge===o;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:o,children:[e.jsxs("button",{type:"button",onClick:()=>c?gs(o):Ht(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[c?e.jsx(Yi,{size:10,className:"shrink-0"}):e.jsx(Wa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:kt(o)})]}),e.jsx("button",{type:"button",onClick:()=>un(o),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":i("rightSidebar.unpinFolder",{name:kt(o)}),title:i("rightSidebar.unpinFolder",{name:kt(o)}),children:e.jsx(Yt,{size:9})})]},o)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),vi=a.useMemo(()=>{if(An===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((To-An)/1e3)),c=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[w,v]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return c.format(w,v)},[To,An]),Kh=x&&!zn?e.jsx("button",{type:"button",onClick:()=>{Fh(!Uo)},"aria-pressed":Uo,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${Uo?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,cd=x?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[vi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:vi}),children:vi}):null,e.jsx("button",{type:"button",onClick:()=>{Hn()},disabled:lr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx(so,{size:13,className:lr?"animate-spin":""})})]}):null,Vh=sc?i("rightSidebar.changeAuditScopeAll"):pn.length===1?pn[0].relativeRoot==="."?st:pn[0].relativeRoot||pn[0].name:`${pn.length} repos`,qh=x?e.jsxs("div",{className:"inline-flex min-h-9 shrink-0 items-center",children:[e.jsx(au,{open:rs,onOpenChange:Xr,showScopePicker:wn,selectedAll:sc,repos:Xf,selectedRoots:tr,onToggleRepo:jh,onGenerate:()=>yh(),disabled:!x,inserted:ke===bc,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Vh,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:Fr,error:!!jr,statusTitle:jr??(Fr?i("rightSidebar.changeAuditLoading"):Mt.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Mt.length})}${ad?` · ${i("rightSidebar.changeAuditLoadedAt",{time:ad})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{kh()},disabled:Fr||Mt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Mt.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(no,{size:12})})]}):null,Rs=rr??(R?.available&&x&&Re.size>0&&le.length<=1?{root:x,label:st}:null),dd=e.jsxs(e.Fragment,{children:[Rs&&e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Ba("stage-all",Rs.root,Rs.label),disabled:!!Ue,className:"flex-1 rounded-md bg-accent/10 px-2 py-1 text-[11px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>Ba("stash-all",Rs.root,Rs.label),disabled:!!Ue,className:"flex-1 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground hover:bg-surface disabled:opacity-50",children:i("rightSidebar.stashAll")})]}),Kh,qh]}),Ua=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[R?.available&&R.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:R.branch,children:[e.jsx(Pr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:R.branch})]}),ht.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[ht.modified,"M"]}),ht.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",ht.added]}),ht.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",ht.deleted]}),ht.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ht.renamed,"R"]}),ht.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ht.copied,"C"]}),ht.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[ht.untracked,"U"]}),ht.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[ht.conflicted,"!"]}),ht.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[ht.other,"?"]}),ht.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:ht.staged})})]});return e.jsxs(Um,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:u,push:d,pinned:h,children:[ei.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${Qf?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:x??void 0,children:st}),(!ne||Ao)&&R?.available&&R.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:R.branch,children:[e.jsx(Pr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:R.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!xe;W(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):K("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${xe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Zn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Ie,onClick:()=>{ze(t=>!t),Bt(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Ie?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(Hm,{size:14}),!Ie&&ve.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:Bl,type:"file",multiple:!0,className:"hidden",onChange:t=>{const o=t.target.files;!o||o.length===0||(bs(Array.from(o)),t.target.value="")}}),e.jsx("input",{ref:Ol,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const o=t.target.files?.[0];t.target.value="",o&&rh(o)}}),g&&e.jsx("button",{type:"button",onClick:g,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(ji,{size:14}):e.jsx(Wa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{br(!1),Ot(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${pr?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":pr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(lo,{size:15})}),pr&&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":zr,onClick:()=>th(!zr),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(wd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${zr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${zr?"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:()=>{Ot(!1),Bl.current?.click()},disabled:ca,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:[ca?e.jsx(Nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(fp,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ot(!1),Ol.current?.click()},disabled:ca,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:[ca?e.jsx(Nt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(op,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),g&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ot(!1),g()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(ji,{size:14}):e.jsx(Wa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([t,o])=>{const c=X===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":c,onClick:()=>{L(t),Ot(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${c?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:o},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":i("rightSidebar.close"),children:e.jsx(Yt,{size:14})})]}),xe&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:C,onChange:t=>K(t.target.value),placeholder:i(F==="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 ${ne?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Qc("name"),"aria-pressed":F==="name",className:`rounded-full px-2 transition active:scale-95 ${ne?"py-1":"py-0.5"} ${F==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Qc("content"),"aria-pressed":F==="content",className:`rounded-full px-2 transition active:scale-95 ${ne?"py-1":"py-0.5"} ${F==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),C&&e.jsx("button",{type:"button",onClick:()=>K(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Yt,{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(zm,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:re,onChange:t=>ie(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:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),re!=="."&&e.jsx("button",{type:"button",onClick:()=>ie("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Yt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>N(t=>!t),"aria-expanded":De,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${De||hs.length>0||q||Ae||Le?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(Wm,{size:13}),hs.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:hs.length})]})]}),De&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:we,onChange:t=>pe(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),we&&e.jsx("button",{type:"button",onClick:()=>pe(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Yt,{size:11})})]}),F==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[q,()=>he(t=>!t),ep,i("rightSidebar.matchCase")],[Ae,()=>Qe(t=>!t),mp,i("rightSidebar.matchWholeWord")],[Le,()=>at(t=>!t),lp,i("rightSidebar.useRegex")]].map(([t,o,c,w])=>e.jsxs("button",{type:"button",onClick:o,"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(c,{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(${(zn?2:3)+(zr?1:0)}, minmax(0, 1fr))`},children:[!zn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>er("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Pr,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>er("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Eu,{size:12}),i("rightSidebar.tabChanges"),Re.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:Re.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>er("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(qm,{size:12}),i("rightSidebar.tabFiles")]}),zr&&e.jsxs("button",{type:"button",onClick:()=>er("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ur==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(wd,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),Ll&&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:Ll})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Qa,{active:lt,mounted:ir,fallback:e.jsx(Ii,{slow:!1}),children:qe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Pd,{items:Ch,diffViewType:Do,inlineMode:Xt,viewControls:h?ks():void 0,renderPathReference:(t,o)=>Aa(yn(t,qe.repoRoot??x),i(o==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle")),selectedKey:Of,onSelect:Zs,emptyText:i("rightSidebar.noChanges"),mobile:ne,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${qe.headRef??""}${qe.commits?.[0]?` · ${qe.commits[0]}`:""}`,onClose:()=>{ft(null),Zs(null)},closeLabel:i("common.back"),wrap:Pt,onToggleWrap:Fa,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ne?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta})}):Rr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Pd,{items:ci,diffViewType:Do,inlineMode:Xt,viewControls:h?ks():void 0,renderPathReference:(t,o)=>{const c=be?.comparisonRepos,w=c&&c.length>1?[...c].sort((k,S)=>S.label.length-k.label.length).find(k=>t===k.label||t.startsWith(`${k.label}/`)):void 0,v=w?t===w.label?w.repoRoot:yn(t.slice(w.label.length+1),w.repoRoot):yn(t,js?.repoRoot||x);return Aa(v,i(o==="file"?"rightSidebar.insertThisFile":"fileTree.insertRefTitle"))},selectedKey:Eo,onSelect:an,emptyText:i(be?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ne,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(be?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:js?`${js.repoLabel} · ${js.branchName??"HEAD"} → ${js.baseRef}`:void 0,onClose:()=>{++z.current,Fe(!1),nr(!1),Zt(null)},closeLabel:i("common.back"),wrap:Pt,onToggleWrap:Fa,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ne?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,localOptions:be?.comparisonRepos?.map(t=>({key:t.repoRoot,label:t.label,checked:t.includeUncommitted??be.includeUncommitted??!1,disabled:!(t.canIncludeUncommitted??qn(t.repoRoot,t.head)),onChange:o=>{hi({refresh:!0,repoRoot:t.repoRoot,includeUncommitted:o})}})),onHunkGitAction:be?.includeUncommitted?Dh:void 0,error:Ve,actionsBusy:ue>0,onRefresh:()=>{hi({refresh:!0})},refreshing:et,refreshLabel:i("rightSidebar.branchAuditRefreshDiff"),refreshTitle:i("rightSidebar.branchAuditRefreshDiff"),walkthroughs:Nh,onWalkthroughNavigate:Mh,initialDetailScrollTop:be&&Xe?as[Xe]:void 0,onDetailScrollPositionChange:Th,externalSwiperRef:ne?rc:void 0,onMobileSlideChange:ne?$o:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:od?e.jsx("div",{className:"px-3",children:od}):lr?e.jsx(Ii,{slow:ql}):fn?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):du(R)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):R?.available===!1?e.jsx(eo,{message:R.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{Hn()}}):x?e.jsx(Ii,{slow:ql}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(x?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Qa,{active:Wn,children:ne?e.jsxs(vu,{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=>{Er.current=t,t.slideTo(Ml,0)},onSlideChange:t=>{if(Nr(t.activeIndex),ps.current===t.activeIndex){ps.current=null;return}t.activeIndex===0&&(Cr(!1),bt(null),j?.())},children:[e.jsx(Wi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Fn,onScroll:ic,onDragOver:wa,onDragEnter:wa,onDragLeave:dc,onDrop:uc,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[Dl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&ld,e.jsx(Nd,{rootPath:ge??"",onFileSelect:gs,onPathReference:Gt,getReferenceText:ka,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onDirectoryRoot:vc,onSearchFromDirectory:wc,onDirectoryPinToggle:yc,onFilePinToggle:kc,pinnedPaths:bn,selectedFilePath:ot,query:Be,searchRootPath:Zl,searchOptions:Ql,searchMode:F,onContentMatchSelect:lc,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:de,canOpenInFileBrowser:Fl,onOpenInFileBrowser:cc})]})}),e.jsx(Wi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(dl,{filePath:Wn&&(Uf||Ml===1)?ot:null,onInsertReference:Gt,onInsertText:Ar,onInsertFeature:Ar,onReviewReference:pc,onReferenceCopied:$r,onClose:Gh,onDirectoryLinkOpen:id,isMobile:!0,lineRange:Rn,onLineRangeChange:bt,insertedReferenceKey:ke,copiedReferenceKey:nt,scrollToLine:Ge,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Fn,onScroll:ic,onDragOver:wa,onDragEnter:wa,onDragLeave:dc,onDrop:uc,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Fo},children:[Dl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&ld,e.jsx(Nd,{rootPath:ge??"",onFileSelect:gs,onPathReference:Gt,getReferenceText:ka,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onDirectoryRoot:vc,onSearchFromDirectory:wc,onDirectoryPinToggle:yc,onFilePinToggle:kc,pinnedPaths:bn,selectedFilePath:ot,query:Be,searchRootPath:Zl,searchOptions:Ql,searchMode:F,onContentMatchSelect:lc,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:de,canOpenInFileBrowser:Fl,onOpenInFileBrowser:cc})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Jf,onPointerMove:Zf,onPointerUp:oc,onPointerCancel:oc,onDoubleClick:()=>{_o(el),At(Ps,el)},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(dl,{filePath:Wn?ot:null,onInsertReference:Gt,onInsertText:Ar,onInsertFeature:Ar,onReviewReference:pc,onReferenceCopied:$r,onDirectoryLinkOpen:id,isMobile:!1,lineRange:Rn,onLineRangeChange:bt,insertedReferenceKey:ke,copiedReferenceKey:nt,scrollToLine:Ge,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:$,onCloseMarkdownOutline:A,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:p})})]})}),e.jsx(Qa,{active:Rt,mounted:Hf||Rt,children:()=>Jo?e.jsx(Gm,{}):ne?e.jsx(Gi,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:Yo,onMobileSlideChange:$o,groups:qt.length>0?Oc():[],mode:kr,onModeChange:Da,selectedKey:ot,scrollToKey:Gc,scrollToKeyNonce:ua.nonce,compact:!1,collapsedDirectoryKeys:Ks,onToggleDirectory:qc,onSelectFile:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);o&&Ia(yt(o))},renderLeading:Hc,renderTrailing:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);return o?_c(o):null},renderDirectoryTrailing:Bc,renderSubtitle:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);return o?Fc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ua&&e.jsx("div",{className:"mb-2",children:Ua}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[qt.length,"/",Re.size]})]}),e.jsxs(Ad,{actions:dd,children:[Ic(),t,h&&ks(),cd]},x),rr&&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:rr.label}),rr.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:rr.branch})]}),!rr&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:Ma?(t=>Vc(t)):void 0,emptyContent:Jo?null:fn&&Re.size===0?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):Re.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:({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:i("rightSidebar.backToChangeList"),children:[e.jsx(Bs,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",children:[h&&ks(),e.jsxs("button",{type:"button",onClick:Fa,"aria-pressed":Pt,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Pt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(Pt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),x&&e.jsx("button",{type:"button",onClick:()=>{Hn()},disabled:lr,"aria-label":i("rightSidebar.refreshGit"),title:i("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(so,{size:14,className:lr?"animate-spin":""})})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:Uc(),activePane:Rt,wrap:Pt,diffViewType:Do,inlineMode:Xt,diffOptions:Zc,reloadKey:Ys,renderStreamBadge:t=>e.jsx(Ds,{status:t}),onHunkGitAction:ed,onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,onDetailScroll:La}):e.jsx(Gi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:i("rightSidebar.backToChangeList"),groups:qt.length>0?Oc():[],mode:kr,onModeChange:Da,selectedKey:ot,scrollToKey:Gc,scrollToKeyNonce:ua.nonce,compact:!0,collapsedDirectoryKeys:Ks,onToggleDirectory:qc,onSelectFile:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);o&&Ia(yt(o))},renderLeading:Hc,renderTrailing:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);return o?_c(o):null},renderDirectoryTrailing:Bc,renderSubtitle:t=>{const o=Array.from(Re.values()).find(c=>yt(c)===t.key);return o?Fc(o):null},aiContent:Ma?(t=>Vc(t)):void 0,emptyContent:Jo?null:fn&&Re.size===0?e.jsx(eo,{message:fn,onRetry:()=>{Hn()}}):Re.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):qt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>x&&e.jsxs("div",{className:"px-0 py-0",children:[Ua&&e.jsx("div",{className:"mb-2",children:Ua}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[qt.length,"/",Re.size]})})]}),e.jsxs(Ad,{actions:dd,children:[Ic(),t,ks(),e.jsxs("button",{type:"button",onClick:Fa,"aria-pressed":Pt,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Pt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(Pt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),cd]},x),rr&&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:rr.label}),rr.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:rr.branch})]}),!rr&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Pr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:Uc(),activePane:Rt,wrap:Pt,diffViewType:Ut,inlineMode:Xt,diffOptions:Zc,reloadKey:Ys,renderStreamBadge:t=>e.jsx(Ds,{status:t}),onHunkGitAction:ed,onInsertDiffReference:Lr,onReferenceCopied:$r,insertedReferenceKey:ke,copiedReferenceKey:nt,onClearAuditRecord:Ta,onDetailScroll:La})}),e.jsx(Qa,{active:Gn,mounted:Po&&zr,children:zf?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{yi.getState().setDock(Si,null),ro({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Km,{sessionId:n??null,onInsertPrompt:t=>Lr("android-deps",t),onInsertFile:sh,onRecordingComplete:nh})})]}),r&&Ie&&e.jsx(Bp,{value:ve,collapsed:_t,autoCollapseAfterSend:H,focusRequest:pt,insertError:Ir?i("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{xr(!1),Ke(t)},onCollapsedChange:Bt,onAutoCollapseAfterSendChange:ae,onDisable:()=>ze(!1),onClear:()=>Ke(""),onInsert:()=>gc(!1),onInsertAndSend:()=>gc(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>i("rightSidebar.contextDraftCharacterCount",{count:t})}}),bh(),xt&&typeof document<"u"&&qr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>on(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:xt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:xt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:gu(xt.file.absolutePath,x)}):i("rightSidebar.confirmStashAllDescription")}),xt.kind==="restore"&&e.jsx("input",{value:xt.phrase,onChange:t=>on({...xt,phrase:t.target.value}),placeholder:i("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>on(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ue||xt.kind==="restore"&&xt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(xt.kind==="restore"){const t=gt(xt.file,x);if(!t)return;wt({action:"restore-worktree-file",cwd:t,paths:[xt.file.path],confirm:{acknowledged:!0,phrase:xt.phrase}},i("rightSidebar.restoreFile"),Bi(xt.file))}else{const t=xt.repoRoot??x;if(!t)return;wt({action:"stash-all",cwd:t},i("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${xt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(Ue?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const bx=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:dl,MarkdownImageLightbox:Nf,MarkdownPreview:Mf,RightSidebar:ax,__testParseMarkdownListBlock:kb,buildMarkdownPreviewBlocks:Pb,buildMarkdownPreviewRenderResult:yl,collectKnownGitRepoRoots:Ju,computeMarkdownImageDisplayBox:df,getMarkdownHeadingOutline:Cf,getMarkdownHeadingPathAtLine:Rf,getNextMarkdownPreviewLineRange:Bb,isSvgImageSrc:wo,mountRightSidebarRepoPickerOverlay:_u,replaceGitRepositorySnapshot:Tf,resolveMarkdownLocalLinkTarget:pl,resolveRightSidebarDiffViewType:Yu,shouldCloseMarkdownImageLightboxDrag:kf,showsGitRepoGroupHeader:tl},Symbol.toStringTag,{value:"Module"}));export{qi as E,bx as R,rp as a,bp as c,gx as m};