termdock 1.4.216 → 1.4.218

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 (321) hide show
  1. package/dist/client/assets/App-B5iubRB9.js +156 -0
  2. package/dist/client/assets/App-B5iubRB9.js.br +0 -0
  3. package/dist/client/assets/App-B5iubRB9.js.gz +0 -0
  4. package/dist/client/assets/ChangeWalkthroughPanel-BMhWQpCh.js +2 -0
  5. package/dist/client/assets/ChangeWalkthroughPanel-BMhWQpCh.js.br +0 -0
  6. package/dist/client/assets/ChangeWalkthroughPanel-BMhWQpCh.js.gz +0 -0
  7. package/dist/client/assets/{DagPlayground-BtAvuTCa.js → DagPlayground-Dx-nv4Lf.js} +1 -1
  8. package/dist/client/assets/DagPlayground-Dx-nv4Lf.js.br +0 -0
  9. package/dist/client/assets/DagPlayground-Dx-nv4Lf.js.gz +0 -0
  10. package/dist/client/assets/{DiffLab-BsVORgBM.js → DiffLab-IFC4AGIF.js} +1 -1
  11. package/dist/client/assets/DiffLab-IFC4AGIF.js.br +0 -0
  12. package/dist/client/assets/DiffLab-IFC4AGIF.js.gz +0 -0
  13. package/dist/client/assets/DiffReview-WcdcQoMa.js +1 -0
  14. package/dist/client/assets/DiffReview-WcdcQoMa.js.br +0 -0
  15. package/dist/client/assets/DiffReview-WcdcQoMa.js.gz +0 -0
  16. package/dist/client/assets/{DiffReviewLab-BUO2nqkI.js → DiffReviewLab-DtSgnCr4.js} +1 -1
  17. package/dist/client/assets/DiffReviewLab-DtSgnCr4.js.br +0 -0
  18. package/dist/client/assets/DiffReviewLab-DtSgnCr4.js.gz +0 -0
  19. package/dist/client/assets/{DiffViewer-84qdL8a3.js → DiffViewer-BjAyUxOt.js} +17 -17
  20. package/dist/client/assets/DiffViewer-BjAyUxOt.js.br +0 -0
  21. package/dist/client/assets/DiffViewer-BjAyUxOt.js.gz +0 -0
  22. package/dist/client/assets/{ModelPreview-AlBS7WBE.js → ModelPreview-Da1kMWa7.js} +1 -1
  23. package/dist/client/assets/ModelPreview-Da1kMWa7.js.br +0 -0
  24. package/dist/client/assets/ModelPreview-Da1kMWa7.js.gz +0 -0
  25. package/dist/client/assets/{RightSidebar-DnbixLBX.js → RightSidebar-BtEMastJ.js} +44 -44
  26. package/dist/client/assets/RightSidebar-BtEMastJ.js.br +0 -0
  27. package/dist/client/assets/RightSidebar-BtEMastJ.js.gz +0 -0
  28. package/dist/client/assets/{abnfDiagram-VCTEODGH-BvNKLikS.js → abnfDiagram-VCTEODGH-BHLdU3dH.js} +1 -1
  29. package/dist/client/assets/abnfDiagram-VCTEODGH-BHLdU3dH.js.br +0 -0
  30. package/dist/client/assets/abnfDiagram-VCTEODGH-BHLdU3dH.js.gz +0 -0
  31. package/dist/client/assets/app-DIA5Fax_.js +34 -0
  32. package/dist/client/assets/app-DIA5Fax_.js.br +0 -0
  33. package/dist/client/assets/app-DIA5Fax_.js.gz +0 -0
  34. package/dist/client/assets/{arc-BS5_QxBd.js → arc-jrmdUiNn.js} +1 -1
  35. package/dist/client/assets/arc-jrmdUiNn.js.br +0 -0
  36. package/dist/client/assets/arc-jrmdUiNn.js.gz +0 -0
  37. package/dist/client/assets/{architectureDiagram-5GKGNRK7-RAnGHk-1.js → architectureDiagram-5GKGNRK7-DqUCZEG5.js} +1 -1
  38. package/dist/client/assets/architectureDiagram-5GKGNRK7-DqUCZEG5.js.br +0 -0
  39. package/dist/client/assets/architectureDiagram-5GKGNRK7-DqUCZEG5.js.gz +0 -0
  40. package/dist/client/assets/{blockDiagram-I7D4REHJ-B74GNPCh.js → blockDiagram-I7D4REHJ-BaTRfss3.js} +1 -1
  41. package/dist/client/assets/blockDiagram-I7D4REHJ-BaTRfss3.js.br +0 -0
  42. package/dist/client/assets/blockDiagram-I7D4REHJ-BaTRfss3.js.gz +0 -0
  43. package/dist/client/assets/{c4Diagram-7LVT6UL2-DwPuf6cG.js → c4Diagram-7LVT6UL2-dAzm-_VP.js} +1 -1
  44. package/dist/client/assets/c4Diagram-7LVT6UL2-dAzm-_VP.js.br +0 -0
  45. package/dist/client/assets/c4Diagram-7LVT6UL2-dAzm-_VP.js.gz +0 -0
  46. package/dist/client/assets/channel-CMES-IfO.js +1 -0
  47. package/dist/client/assets/{chunk-2Q5K7J3B-DsHB8CDO.js → chunk-2Q5K7J3B-BamqSBpE.js} +1 -1
  48. package/dist/client/assets/{chunk-5VM5RSS4-BGJFPCFF.js → chunk-5VM5RSS4-gqByiMDl.js} +1 -1
  49. package/dist/client/assets/{chunk-F27PBJKO-B0mLhbV9.js → chunk-F27PBJKO-B44WH4nI.js} +1 -1
  50. package/dist/client/assets/chunk-F27PBJKO-B44WH4nI.js.br +0 -0
  51. package/dist/client/assets/chunk-F27PBJKO-B44WH4nI.js.gz +0 -0
  52. package/dist/client/assets/{chunk-IMKFNOWR-C15YzBXr.js → chunk-IMKFNOWR-CLDpIRiG.js} +1 -1
  53. package/dist/client/assets/chunk-IMKFNOWR-CLDpIRiG.js.br +0 -0
  54. package/dist/client/assets/chunk-IMKFNOWR-CLDpIRiG.js.gz +0 -0
  55. package/dist/client/assets/{chunk-JWPE2WC7-D-hPwJNJ.js → chunk-JWPE2WC7-B5axUHKy.js} +1 -1
  56. package/dist/client/assets/{chunk-POPQ4Y6H-DrB6rlmg.js → chunk-POPQ4Y6H-C1KIKg6p.js} +1 -1
  57. package/dist/client/assets/{chunk-SVP7TREG-Dw-ef7TG.js → chunk-SVP7TREG-D1180vSd.js} +1 -1
  58. package/dist/client/assets/chunk-SVP7TREG-D1180vSd.js.br +0 -0
  59. package/dist/client/assets/chunk-SVP7TREG-D1180vSd.js.gz +0 -0
  60. package/dist/client/assets/{chunk-TICWLB2K-CuyxhxOQ.js → chunk-TICWLB2K-rRYUR8B8.js} +1 -1
  61. package/dist/client/assets/chunk-TICWLB2K-rRYUR8B8.js.br +0 -0
  62. package/dist/client/assets/chunk-TICWLB2K-rRYUR8B8.js.gz +0 -0
  63. package/dist/client/assets/{chunk-XXDRQBXY-DElV8i8a.js → chunk-XXDRQBXY-NW7wAU5m.js} +1 -1
  64. package/dist/client/assets/classDiagram-ZZMXUADV-BhV2fYDl.js +1 -0
  65. package/dist/client/assets/classDiagram-v2-VYDZK3BY-BhV2fYDl.js +1 -0
  66. package/dist/client/assets/{cose-bilkent-JH36ORCC-6Yb0qGFQ.js → cose-bilkent-JH36ORCC-D82qtj1R.js} +1 -1
  67. package/dist/client/assets/cose-bilkent-JH36ORCC-D82qtj1R.js.br +0 -0
  68. package/dist/client/assets/cose-bilkent-JH36ORCC-D82qtj1R.js.gz +0 -0
  69. package/dist/client/assets/{cynefin-OW5HDTMX-CC8ChA_X.js → cynefin-OW5HDTMX-x0KBZr_y.js} +1 -1
  70. package/dist/client/assets/cynefin-OW5HDTMX-x0KBZr_y.js.br +0 -0
  71. package/dist/client/assets/cynefin-OW5HDTMX-x0KBZr_y.js.gz +0 -0
  72. package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-D9l3UGkQ.js → cynefinDiagram-5FMLGOSQ-Ctj0w20u.js} +1 -1
  73. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-Ctj0w20u.js.br +0 -0
  74. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-Ctj0w20u.js.gz +0 -0
  75. package/dist/client/assets/{dagre-GXQ25YYZ-PPwL9Epb.js → dagre-GXQ25YYZ-Blxs620B.js} +1 -1
  76. package/dist/client/assets/dagre-GXQ25YYZ-Blxs620B.js.br +0 -0
  77. package/dist/client/assets/dagre-GXQ25YYZ-Blxs620B.js.gz +0 -0
  78. package/dist/client/assets/{diagram-S7CK7UJ4-JCcQojC6.js → diagram-S7CK7UJ4-twPxfNAz.js} +1 -1
  79. package/dist/client/assets/diagram-S7CK7UJ4-twPxfNAz.js.br +0 -0
  80. package/dist/client/assets/diagram-S7CK7UJ4-twPxfNAz.js.gz +0 -0
  81. package/dist/client/assets/{diagram-UQ7AKVKN-nQrpn9fe.js → diagram-UQ7AKVKN-CXsodpaC.js} +1 -1
  82. package/dist/client/assets/diagram-UQ7AKVKN-CXsodpaC.js.br +0 -0
  83. package/dist/client/assets/diagram-UQ7AKVKN-CXsodpaC.js.gz +0 -0
  84. package/dist/client/assets/{diagram-VSXAHHWV-ot1VVX6D.js → diagram-VSXAHHWV-BK54uIGU.js} +1 -1
  85. package/dist/client/assets/diagram-VSXAHHWV-BK54uIGU.js.br +0 -0
  86. package/dist/client/assets/diagram-VSXAHHWV-BK54uIGU.js.gz +0 -0
  87. package/dist/client/assets/{diagram-VX7I27RA-BnkRh0FY.js → diagram-VX7I27RA-CUfrOHxq.js} +1 -1
  88. package/dist/client/assets/diagram-VX7I27RA-CUfrOHxq.js.br +0 -0
  89. package/dist/client/assets/diagram-VX7I27RA-CUfrOHxq.js.gz +0 -0
  90. package/dist/client/assets/{diagram-Z3DM3KII-0_-pP3jI.js → diagram-Z3DM3KII-DEJtwS2R.js} +1 -1
  91. package/dist/client/assets/diagram-Z3DM3KII-DEJtwS2R.js.br +0 -0
  92. package/dist/client/assets/diagram-Z3DM3KII-DEJtwS2R.js.gz +0 -0
  93. package/dist/client/assets/{ebnfDiagram-PWID7BFC-C1F4bZda.js → ebnfDiagram-PWID7BFC-DqWJXM-3.js} +1 -1
  94. package/dist/client/assets/ebnfDiagram-PWID7BFC-DqWJXM-3.js.br +0 -0
  95. package/dist/client/assets/ebnfDiagram-PWID7BFC-DqWJXM-3.js.gz +0 -0
  96. package/dist/client/assets/{erDiagram-RLTQ6QDP-oZrQsyBk.js → erDiagram-RLTQ6QDP-BEGyACNz.js} +1 -1
  97. package/dist/client/assets/erDiagram-RLTQ6QDP-BEGyACNz.js.br +0 -0
  98. package/dist/client/assets/erDiagram-RLTQ6QDP-BEGyACNz.js.gz +0 -0
  99. package/dist/client/assets/{flowDiagram-HODETNUW-BO7wTWnA.js → flowDiagram-HODETNUW-XPNs5PDc.js} +1 -1
  100. package/dist/client/assets/flowDiagram-HODETNUW-XPNs5PDc.js.br +0 -0
  101. package/dist/client/assets/{flowDiagram-HODETNUW-BO7wTWnA.js.gz → flowDiagram-HODETNUW-XPNs5PDc.js.gz} +0 -0
  102. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-RSp1mvw5.js → ganttDiagram-EL5Y4UJY-D8DTgtvP.js} +1 -1
  103. package/dist/client/assets/ganttDiagram-EL5Y4UJY-D8DTgtvP.js.br +0 -0
  104. package/dist/client/assets/ganttDiagram-EL5Y4UJY-D8DTgtvP.js.gz +0 -0
  105. package/dist/client/assets/{gestureArbiter-CqgobOTI.js → gestureArbiter-HaGDIrQz.js} +1 -1
  106. package/dist/client/assets/gestureArbiter-HaGDIrQz.js.br +0 -0
  107. package/dist/client/assets/gestureArbiter-HaGDIrQz.js.gz +0 -0
  108. package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-Bll9I9Sq.js → gitGraphDiagram-WWUBYQGX-htdoxSEn.js} +1 -1
  109. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-htdoxSEn.js.br +0 -0
  110. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-htdoxSEn.js.gz +0 -0
  111. package/dist/client/assets/{index-BJPuCkHm.css → index-COVHbD7S.css} +1 -1
  112. package/dist/client/assets/index-COVHbD7S.css.br +0 -0
  113. package/dist/client/assets/index-COVHbD7S.css.gz +0 -0
  114. package/dist/client/assets/{infoDiagram-27XIBGKW-BEGS1z8T.js → infoDiagram-27XIBGKW-C2OQZIgE.js} +1 -1
  115. package/dist/client/assets/{ishikawaDiagram-5VMMS53U-4N6cv4T2.js → ishikawaDiagram-5VMMS53U-ClyW1ylU.js} +1 -1
  116. package/dist/client/assets/ishikawaDiagram-5VMMS53U-ClyW1ylU.js.br +0 -0
  117. package/dist/client/assets/ishikawaDiagram-5VMMS53U-ClyW1ylU.js.gz +0 -0
  118. package/dist/client/assets/{journeyDiagram-3NMN7TZE-Bm2WNf21.js → journeyDiagram-3NMN7TZE-CqWWznjs.js} +1 -1
  119. package/dist/client/assets/journeyDiagram-3NMN7TZE-CqWWznjs.js.br +0 -0
  120. package/dist/client/assets/journeyDiagram-3NMN7TZE-CqWWznjs.js.gz +0 -0
  121. package/dist/client/assets/{kanban-definition-UXKFOSKX-mOozRtH0.js → kanban-definition-UXKFOSKX-Ch7DE4cd.js} +1 -1
  122. package/dist/client/assets/kanban-definition-UXKFOSKX-Ch7DE4cd.js.br +0 -0
  123. package/dist/client/assets/kanban-definition-UXKFOSKX-Ch7DE4cd.js.gz +0 -0
  124. package/dist/client/assets/{layout-BFk1q7nt.js → layout-CT4ZJnhY.js} +1 -1
  125. package/dist/client/assets/layout-CT4ZJnhY.js.br +0 -0
  126. package/dist/client/assets/layout-CT4ZJnhY.js.gz +0 -0
  127. package/dist/client/assets/{linear-CPXynm7B.js → linear-DrHvrY-O.js} +1 -1
  128. package/dist/client/assets/linear-DrHvrY-O.js.br +0 -0
  129. package/dist/client/assets/linear-DrHvrY-O.js.gz +0 -0
  130. package/dist/client/assets/{mermaid.core-Ba4l96YR.js → mermaid.core-CW-pInWx.js} +5 -5
  131. package/dist/client/assets/mermaid.core-CW-pInWx.js.br +0 -0
  132. package/dist/client/assets/mermaid.core-CW-pInWx.js.gz +0 -0
  133. package/dist/client/assets/{mindmap-definition-YA3MSWOX-DZdl6uc-.js → mindmap-definition-YA3MSWOX-DYijhnQO.js} +1 -1
  134. package/dist/client/assets/mindmap-definition-YA3MSWOX-DYijhnQO.js.br +0 -0
  135. package/dist/client/assets/mindmap-definition-YA3MSWOX-DYijhnQO.js.gz +0 -0
  136. package/dist/client/assets/{passwordBootstrap-NIMQmJqW.js → passwordBootstrap-DWIbLBpG.js} +1 -1
  137. package/dist/client/assets/passwordBootstrap-DWIbLBpG.js.br +0 -0
  138. package/dist/client/assets/passwordBootstrap-DWIbLBpG.js.gz +0 -0
  139. package/dist/client/assets/{pegDiagram-XKGWAZYB-CxXMwwWw.js → pegDiagram-XKGWAZYB-D0RV4aIg.js} +1 -1
  140. package/dist/client/assets/pegDiagram-XKGWAZYB-D0RV4aIg.js.br +0 -0
  141. package/dist/client/assets/pegDiagram-XKGWAZYB-D0RV4aIg.js.gz +0 -0
  142. package/dist/client/assets/{pieDiagram-E7YTZNPT-BNY2m9Tf.js → pieDiagram-E7YTZNPT-DGyArfUr.js} +1 -1
  143. package/dist/client/assets/pieDiagram-E7YTZNPT-DGyArfUr.js.br +0 -0
  144. package/dist/client/assets/pieDiagram-E7YTZNPT-DGyArfUr.js.gz +0 -0
  145. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-sh99Gsbf.js → quadrantDiagram-AXDQQJYC-D00a3YLq.js} +1 -1
  146. package/dist/client/assets/quadrantDiagram-AXDQQJYC-D00a3YLq.js.br +0 -0
  147. package/dist/client/assets/quadrantDiagram-AXDQQJYC-D00a3YLq.js.gz +0 -0
  148. package/dist/client/assets/{railroadDiagram-O6MQD6OU-DHEXu_OI.js → railroadDiagram-O6MQD6OU-B7UC-Oeb.js} +1 -1
  149. package/dist/client/assets/railroadDiagram-O6MQD6OU-B7UC-Oeb.js.br +0 -0
  150. package/dist/client/assets/railroadDiagram-O6MQD6OU-B7UC-Oeb.js.gz +0 -0
  151. package/dist/client/assets/referenceLongPress-BfTDwMvD.js +1 -0
  152. package/dist/client/assets/referenceLongPress-BfTDwMvD.js.br +0 -0
  153. package/dist/client/assets/referenceLongPress-BfTDwMvD.js.gz +0 -0
  154. package/dist/client/assets/{requirementDiagram-BXWQKSXE-BeykS4A9.js → requirementDiagram-BXWQKSXE-Ba-f2Jsq.js} +1 -1
  155. package/dist/client/assets/requirementDiagram-BXWQKSXE-Ba-f2Jsq.js.br +0 -0
  156. package/dist/client/assets/requirementDiagram-BXWQKSXE-Ba-f2Jsq.js.gz +0 -0
  157. package/dist/client/assets/{sankeyDiagram-P5KCCOFB-ITbT_fDy.js → sankeyDiagram-P5KCCOFB-CMAQgFBf.js} +1 -1
  158. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CMAQgFBf.js.br +0 -0
  159. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CMAQgFBf.js.gz +0 -0
  160. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-rpXvTufG.js → sequenceDiagram-WJ2MYXX4-D2h5ZpjJ.js} +1 -1
  161. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-D2h5ZpjJ.js.br +0 -0
  162. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-D2h5ZpjJ.js.gz +0 -0
  163. package/dist/client/assets/{sizeCapture-INFHLROL-Dub9MK_t.js → sizeCapture-INFHLROL-BJyvF8B8.js} +1 -1
  164. package/dist/client/assets/sizeCapture-INFHLROL-BJyvF8B8.js.br +0 -0
  165. package/dist/client/assets/sizeCapture-INFHLROL-BJyvF8B8.js.gz +0 -0
  166. package/dist/client/assets/{sparkles-xIHgNZV_.js → sparkles-CxSnvQPG.js} +1 -1
  167. package/dist/client/assets/{stateDiagram-D77RDMKH-L1f4ArBt.js → stateDiagram-D77RDMKH-CxcLWshk.js} +1 -1
  168. package/dist/client/assets/stateDiagram-D77RDMKH-CxcLWshk.js.br +0 -0
  169. package/dist/client/assets/stateDiagram-D77RDMKH-CxcLWshk.js.gz +0 -0
  170. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-XyGgVHvy.js +1 -0
  171. package/dist/client/assets/{swimlanes-42K2YHIH-D97Yiq6N.js → swimlanes-42K2YHIH-DkA51VOD.js} +1 -1
  172. package/dist/client/assets/swimlanes-42K2YHIH-DkA51VOD.js.br +0 -0
  173. package/dist/client/assets/swimlanes-42K2YHIH-DkA51VOD.js.gz +0 -0
  174. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-Di6YUJei.js +8 -0
  175. package/dist/client/assets/{timeline-definition-24CTP7MA-CrqpPzWX.js → timeline-definition-24CTP7MA-WuKg4hBe.js} +1 -1
  176. package/dist/client/assets/timeline-definition-24CTP7MA-WuKg4hBe.js.br +0 -0
  177. package/dist/client/assets/timeline-definition-24CTP7MA-WuKg4hBe.js.gz +0 -0
  178. package/dist/client/assets/triangle-alert-6QR6NZO7.js +1 -0
  179. package/dist/client/assets/{vennDiagram-4TSXK5OY-BciR-COZ.js → vennDiagram-4TSXK5OY-BIeTGDv6.js} +1 -1
  180. package/dist/client/assets/vennDiagram-4TSXK5OY-BIeTGDv6.js.br +0 -0
  181. package/dist/client/assets/vennDiagram-4TSXK5OY-BIeTGDv6.js.gz +0 -0
  182. package/dist/client/assets/{wardleyDiagram-VM6X3IG4-DXdjTZNb.js → wardleyDiagram-VM6X3IG4-Czf3WhOk.js} +1 -1
  183. package/dist/client/assets/wardleyDiagram-VM6X3IG4-Czf3WhOk.js.br +0 -0
  184. package/dist/client/assets/wardleyDiagram-VM6X3IG4-Czf3WhOk.js.gz +0 -0
  185. package/dist/client/assets/{xychartDiagram-S5SC5T6Z-B6sPePg6.js → xychartDiagram-S5SC5T6Z-F1pMpC41.js} +1 -1
  186. package/dist/client/assets/xychartDiagram-S5SC5T6Z-F1pMpC41.js.br +0 -0
  187. package/dist/client/assets/xychartDiagram-S5SC5T6Z-F1pMpC41.js.gz +0 -0
  188. package/dist/client/index.html +2 -2
  189. package/dist/client/index.html.br +0 -0
  190. package/dist/client/index.html.gz +0 -0
  191. package/dist/client/sw.js +1 -1
  192. package/dist/client/sw.js.br +0 -0
  193. package/dist/client/sw.js.gz +0 -0
  194. package/package.json +1 -1
  195. package/runtime-manifest.json +2 -2
  196. package/dist/client/assets/App-BVWkSLJO.js +0 -156
  197. package/dist/client/assets/App-BVWkSLJO.js.br +0 -0
  198. package/dist/client/assets/App-BVWkSLJO.js.gz +0 -0
  199. package/dist/client/assets/ChangeWalkthroughPanel-ClJFLOsY.js +0 -2
  200. package/dist/client/assets/ChangeWalkthroughPanel-ClJFLOsY.js.br +0 -0
  201. package/dist/client/assets/ChangeWalkthroughPanel-ClJFLOsY.js.gz +0 -0
  202. package/dist/client/assets/DagPlayground-BtAvuTCa.js.br +0 -0
  203. package/dist/client/assets/DagPlayground-BtAvuTCa.js.gz +0 -0
  204. package/dist/client/assets/DiffLab-BsVORgBM.js.br +0 -0
  205. package/dist/client/assets/DiffLab-BsVORgBM.js.gz +0 -0
  206. package/dist/client/assets/DiffReview-B0fouDB5.js +0 -1
  207. package/dist/client/assets/DiffReview-B0fouDB5.js.br +0 -0
  208. package/dist/client/assets/DiffReview-B0fouDB5.js.gz +0 -0
  209. package/dist/client/assets/DiffReviewLab-BUO2nqkI.js.br +0 -0
  210. package/dist/client/assets/DiffReviewLab-BUO2nqkI.js.gz +0 -0
  211. package/dist/client/assets/DiffViewer-84qdL8a3.js.br +0 -0
  212. package/dist/client/assets/DiffViewer-84qdL8a3.js.gz +0 -0
  213. package/dist/client/assets/ModelPreview-AlBS7WBE.js.br +0 -0
  214. package/dist/client/assets/ModelPreview-AlBS7WBE.js.gz +0 -0
  215. package/dist/client/assets/RightSidebar-DnbixLBX.js.br +0 -0
  216. package/dist/client/assets/RightSidebar-DnbixLBX.js.gz +0 -0
  217. package/dist/client/assets/abnfDiagram-VCTEODGH-BvNKLikS.js.br +0 -0
  218. package/dist/client/assets/abnfDiagram-VCTEODGH-BvNKLikS.js.gz +0 -0
  219. package/dist/client/assets/app-Bf67B7nu.js +0 -34
  220. package/dist/client/assets/app-Bf67B7nu.js.br +0 -0
  221. package/dist/client/assets/app-Bf67B7nu.js.gz +0 -0
  222. package/dist/client/assets/arc-BS5_QxBd.js.br +0 -0
  223. package/dist/client/assets/arc-BS5_QxBd.js.gz +0 -0
  224. package/dist/client/assets/architectureDiagram-5GKGNRK7-RAnGHk-1.js.br +0 -0
  225. package/dist/client/assets/architectureDiagram-5GKGNRK7-RAnGHk-1.js.gz +0 -0
  226. package/dist/client/assets/blockDiagram-I7D4REHJ-B74GNPCh.js.br +0 -0
  227. package/dist/client/assets/blockDiagram-I7D4REHJ-B74GNPCh.js.gz +0 -0
  228. package/dist/client/assets/c4Diagram-7LVT6UL2-DwPuf6cG.js.br +0 -0
  229. package/dist/client/assets/c4Diagram-7LVT6UL2-DwPuf6cG.js.gz +0 -0
  230. package/dist/client/assets/channel-CH2bY7mN.js +0 -1
  231. package/dist/client/assets/chunk-F27PBJKO-B0mLhbV9.js.br +0 -0
  232. package/dist/client/assets/chunk-F27PBJKO-B0mLhbV9.js.gz +0 -0
  233. package/dist/client/assets/chunk-IMKFNOWR-C15YzBXr.js.br +0 -0
  234. package/dist/client/assets/chunk-IMKFNOWR-C15YzBXr.js.gz +0 -0
  235. package/dist/client/assets/chunk-SVP7TREG-Dw-ef7TG.js.br +0 -0
  236. package/dist/client/assets/chunk-SVP7TREG-Dw-ef7TG.js.gz +0 -0
  237. package/dist/client/assets/chunk-TICWLB2K-CuyxhxOQ.js.br +0 -0
  238. package/dist/client/assets/chunk-TICWLB2K-CuyxhxOQ.js.gz +0 -0
  239. package/dist/client/assets/classDiagram-ZZMXUADV-BZFAua3n.js +0 -1
  240. package/dist/client/assets/classDiagram-v2-VYDZK3BY-BZFAua3n.js +0 -1
  241. package/dist/client/assets/cose-bilkent-JH36ORCC-6Yb0qGFQ.js.br +0 -0
  242. package/dist/client/assets/cose-bilkent-JH36ORCC-6Yb0qGFQ.js.gz +0 -0
  243. package/dist/client/assets/cynefin-OW5HDTMX-CC8ChA_X.js.br +0 -0
  244. package/dist/client/assets/cynefin-OW5HDTMX-CC8ChA_X.js.gz +0 -0
  245. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-D9l3UGkQ.js.br +0 -0
  246. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-D9l3UGkQ.js.gz +0 -0
  247. package/dist/client/assets/dagre-GXQ25YYZ-PPwL9Epb.js.br +0 -0
  248. package/dist/client/assets/dagre-GXQ25YYZ-PPwL9Epb.js.gz +0 -0
  249. package/dist/client/assets/diagram-S7CK7UJ4-JCcQojC6.js.br +0 -0
  250. package/dist/client/assets/diagram-S7CK7UJ4-JCcQojC6.js.gz +0 -0
  251. package/dist/client/assets/diagram-UQ7AKVKN-nQrpn9fe.js.br +0 -0
  252. package/dist/client/assets/diagram-UQ7AKVKN-nQrpn9fe.js.gz +0 -0
  253. package/dist/client/assets/diagram-VSXAHHWV-ot1VVX6D.js.br +0 -0
  254. package/dist/client/assets/diagram-VSXAHHWV-ot1VVX6D.js.gz +0 -0
  255. package/dist/client/assets/diagram-VX7I27RA-BnkRh0FY.js.br +0 -0
  256. package/dist/client/assets/diagram-VX7I27RA-BnkRh0FY.js.gz +0 -0
  257. package/dist/client/assets/diagram-Z3DM3KII-0_-pP3jI.js.br +0 -0
  258. package/dist/client/assets/diagram-Z3DM3KII-0_-pP3jI.js.gz +0 -0
  259. package/dist/client/assets/ebnfDiagram-PWID7BFC-C1F4bZda.js.br +0 -0
  260. package/dist/client/assets/ebnfDiagram-PWID7BFC-C1F4bZda.js.gz +0 -0
  261. package/dist/client/assets/erDiagram-RLTQ6QDP-oZrQsyBk.js.br +0 -0
  262. package/dist/client/assets/erDiagram-RLTQ6QDP-oZrQsyBk.js.gz +0 -0
  263. package/dist/client/assets/flowDiagram-HODETNUW-BO7wTWnA.js.br +0 -0
  264. package/dist/client/assets/ganttDiagram-EL5Y4UJY-RSp1mvw5.js.br +0 -0
  265. package/dist/client/assets/ganttDiagram-EL5Y4UJY-RSp1mvw5.js.gz +0 -0
  266. package/dist/client/assets/gestureArbiter-CqgobOTI.js.br +0 -0
  267. package/dist/client/assets/gestureArbiter-CqgobOTI.js.gz +0 -0
  268. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-Bll9I9Sq.js.br +0 -0
  269. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-Bll9I9Sq.js.gz +0 -0
  270. package/dist/client/assets/index-BJPuCkHm.css.br +0 -0
  271. package/dist/client/assets/index-BJPuCkHm.css.gz +0 -0
  272. package/dist/client/assets/ishikawaDiagram-5VMMS53U-4N6cv4T2.js.br +0 -0
  273. package/dist/client/assets/ishikawaDiagram-5VMMS53U-4N6cv4T2.js.gz +0 -0
  274. package/dist/client/assets/journeyDiagram-3NMN7TZE-Bm2WNf21.js.br +0 -0
  275. package/dist/client/assets/journeyDiagram-3NMN7TZE-Bm2WNf21.js.gz +0 -0
  276. package/dist/client/assets/kanban-definition-UXKFOSKX-mOozRtH0.js.br +0 -0
  277. package/dist/client/assets/kanban-definition-UXKFOSKX-mOozRtH0.js.gz +0 -0
  278. package/dist/client/assets/layout-BFk1q7nt.js.br +0 -0
  279. package/dist/client/assets/layout-BFk1q7nt.js.gz +0 -0
  280. package/dist/client/assets/linear-CPXynm7B.js.br +0 -0
  281. package/dist/client/assets/linear-CPXynm7B.js.gz +0 -0
  282. package/dist/client/assets/mermaid.core-Ba4l96YR.js.br +0 -0
  283. package/dist/client/assets/mermaid.core-Ba4l96YR.js.gz +0 -0
  284. package/dist/client/assets/mindmap-definition-YA3MSWOX-DZdl6uc-.js.br +0 -0
  285. package/dist/client/assets/mindmap-definition-YA3MSWOX-DZdl6uc-.js.gz +0 -0
  286. package/dist/client/assets/passwordBootstrap-NIMQmJqW.js.br +0 -0
  287. package/dist/client/assets/passwordBootstrap-NIMQmJqW.js.gz +0 -0
  288. package/dist/client/assets/pegDiagram-XKGWAZYB-CxXMwwWw.js.br +0 -0
  289. package/dist/client/assets/pegDiagram-XKGWAZYB-CxXMwwWw.js.gz +0 -0
  290. package/dist/client/assets/pieDiagram-E7YTZNPT-BNY2m9Tf.js.br +0 -0
  291. package/dist/client/assets/pieDiagram-E7YTZNPT-BNY2m9Tf.js.gz +0 -0
  292. package/dist/client/assets/quadrantDiagram-AXDQQJYC-sh99Gsbf.js.br +0 -0
  293. package/dist/client/assets/quadrantDiagram-AXDQQJYC-sh99Gsbf.js.gz +0 -0
  294. package/dist/client/assets/railroadDiagram-O6MQD6OU-DHEXu_OI.js.br +0 -0
  295. package/dist/client/assets/railroadDiagram-O6MQD6OU-DHEXu_OI.js.gz +0 -0
  296. package/dist/client/assets/referenceLongPress-sxDdnRK9.js +0 -1
  297. package/dist/client/assets/referenceLongPress-sxDdnRK9.js.br +0 -0
  298. package/dist/client/assets/referenceLongPress-sxDdnRK9.js.gz +0 -0
  299. package/dist/client/assets/requirementDiagram-BXWQKSXE-BeykS4A9.js.br +0 -0
  300. package/dist/client/assets/requirementDiagram-BXWQKSXE-BeykS4A9.js.gz +0 -0
  301. package/dist/client/assets/sankeyDiagram-P5KCCOFB-ITbT_fDy.js.br +0 -0
  302. package/dist/client/assets/sankeyDiagram-P5KCCOFB-ITbT_fDy.js.gz +0 -0
  303. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-rpXvTufG.js.br +0 -0
  304. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-rpXvTufG.js.gz +0 -0
  305. package/dist/client/assets/sizeCapture-INFHLROL-Dub9MK_t.js.br +0 -0
  306. package/dist/client/assets/sizeCapture-INFHLROL-Dub9MK_t.js.gz +0 -0
  307. package/dist/client/assets/stateDiagram-D77RDMKH-L1f4ArBt.js.br +0 -0
  308. package/dist/client/assets/stateDiagram-D77RDMKH-L1f4ArBt.js.gz +0 -0
  309. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-BXG39Il-.js +0 -1
  310. package/dist/client/assets/swimlanes-42K2YHIH-D97Yiq6N.js.br +0 -0
  311. package/dist/client/assets/swimlanes-42K2YHIH-D97Yiq6N.js.gz +0 -0
  312. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-BCdj6Kxb.js +0 -8
  313. package/dist/client/assets/timeline-definition-24CTP7MA-CrqpPzWX.js.br +0 -0
  314. package/dist/client/assets/timeline-definition-24CTP7MA-CrqpPzWX.js.gz +0 -0
  315. package/dist/client/assets/triangle-alert-vrxNhnNT.js +0 -1
  316. package/dist/client/assets/vennDiagram-4TSXK5OY-BciR-COZ.js.br +0 -0
  317. package/dist/client/assets/vennDiagram-4TSXK5OY-BciR-COZ.js.gz +0 -0
  318. package/dist/client/assets/wardleyDiagram-VM6X3IG4-DXdjTZNb.js.br +0 -0
  319. package/dist/client/assets/wardleyDiagram-VM6X3IG4-DXdjTZNb.js.gz +0 -0
  320. package/dist/client/assets/xychartDiagram-S5SC5T6Z-B6sPePg6.js.br +0 -0
  321. package/dist/client/assets/xychartDiagram-S5SC5T6Z-B6sPePg6.js.gz +0 -0
@@ -1,17 +1,17 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-AlBS7WBE.js","assets/app-Bf67B7nu.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-BJPuCkHm.css","assets/App-BVWkSLJO.js","assets/gestureArbiter-CqgobOTI.js","assets/gestureArbiter-C2J0D0kV.css","assets/referenceLongPress-sxDdnRK9.js","assets/triangle-alert-vrxNhnNT.js","assets/DiffReview-B0fouDB5.js","assets/sparkles-xIHgNZV_.js","assets/DiffViewer-84qdL8a3.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-ClJFLOsY.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-Ba4l96YR.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
- import{a0 as yt,Y as ih,aV as e,ca as pt,ch as vt,b9 as tt,a as Ns,ay as lh,C as gi,c as Ms,X as Ut,c8 as ch,aL as dh,w as ps,ad as uh,cc as te,aP as fh,aR as Oi,aS as hh,aT as Ed,aQ as gs,an as mh,E as ph,h as gh,aO as bh,ba as xh,bc as vh,bd as yh,aG as wh,bb as Fc,v as xt,e as kh,L as at,s as Sh,b as jh,aF as _c,ak as Dc,ai as Rh,ar as Na,as as Bc,ci as Ss,ab as bs,at as Ch,c9 as Yo,b4 as Nh,am as Mh,c6 as $h,bD as Eh,av as Lh,I as Oc,H as Ah,aj as Ph,al as Th,ap as Uc,bF as Ih,q as Fh,d as Ma,f as bi,t as Ld,a7 as _h,_ as $s,bx as Dh,cf as Bh,b0 as Oh,a9 as Uh}from"./app-Bf67B7nu.js";import{b as o,r as Gr}from"./dnd-BCFAPC0L.js";import{w as Hh,f as zh,n as Oa,d as Wh,P as Gh,i as qh,R as xi,o as Ad,p as Kh,S as qn,D as Vh,c as Pd,a as Yh,v as Td,t as Hc,s as $a,q as Xh,r as Jh,u as Qh,T as zc,C as Wc,h as Xo,g as Ea,b as Zh,k as em,e as tm,l as rm,F as Gc}from"./App-BVWkSLJO.js";import{a as nm,S as sm,b as Id,c as vi,F as am}from"./gestureArbiter-CqgobOTI.js";import{D as yi,C as js,L as Fd,f as om,n as im}from"./DiffReview-B0fouDB5.js";import{T as lm,L as Wa}from"./triangle-alert-vrxNhnNT.js";import{S as Es}from"./sparkles-xIHgNZV_.js";import{C as _d,a as Dd,M as Bd,G as Mr}from"./ChangeWalkthroughPanel-ClJFLOsY.js";import{r as Od,s as Ud,l as Hd,u as cm,G as zd,h as Wd}from"./DiffViewer-84qdL8a3.js";import{u as Gd}from"./referenceLongPress-sxDdnRK9.js";const dm=[["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"}]],um=yt("case-sensitive",dm);const fm=[["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"}]],hm=yt("eye-off",fm);const mm=[["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"}]],wi=yt("eye",mm);const pm=[["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"}]],ki=yt("file-text",pm);const gm=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],qc=yt("house",gm);const bm=[["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"}]],xm=yt("image-plus",bm);const vm=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]],ym=yt("maximize",vm);const wm=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]],km=yt("minimize",wm);const Sm=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],jm=yt("pencil-line",Sm);const Rm=[["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"}]],Cm=yt("regex",Rm);const Nm=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Mm=yt("rotate-cw",Nm);const $m=[["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"}]],Em=yt("scan",$m);const Lm=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],Kc=yt("send",Lm);const Am=[["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"}]],Pm=yt("upload",Am);const Tm=[["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"}]],Im=yt("whole-word",Tm);function Fm(t,n,s){try{const l=t instanceof HTMLImageElement?t.naturalWidth:t.width,d=t instanceof HTMLImageElement?t.naturalHeight:t.height;if(!l||!d)return Promise.resolve(null);const c=t instanceof HTMLImageElement?1400/Math.max(l,d):Math.min(1,1400/Math.max(l,d)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(d*c));const m=h.getContext("2d");if(!m)return Promise.resolve(null);const g=getComputedStyle(document.documentElement);if(m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,h.height),m.drawImage(t,0,0,h.width,h.height),s){const p=Math.max(10,Math.min(16,h.width/35));m.font=`${p}px sans-serif`;const f=[];let k="";for(const y of s.split(" "))k&&m.measureText(`${k} ${y}`).width>h.width-20?(f.push(k),k=y):k=k?`${k} ${y}`:y;k&&f.push(k),m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,f.length*(p+4)+12),m.fillStyle=g.getPropertyValue("--foreground").trim()||"black",f.forEach((y,N)=>m.fillText(y,10,8+p+N*(p+4)))}if(n){const p=n.xPercent*h.width/100,f=n.yPercent*h.height/100,k=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=k*1.6;m.strokeStyle=g.getPropertyValue("--primary").trim()||"black",m.lineWidth=Math.max(1,k/3),m.beginPath(),m.arc(p,f,k,0,Math.PI*2),m.stroke(),m.beginPath(),m.moveTo(p-y,f),m.lineTo(p+y,f),m.moveTo(p,f-y),m.lineTo(p,f+y),m.stroke()}return new Promise(p=>h.toBlob(p,"image/png"))}catch{return Promise.resolve(null)}}function _m(t,n,s,l){return[t.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
- `)}function $b(t,n,s){const l=n*Math.PI/360,d=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(t,1e-6)/Math.sin(d)*1.15}async function Dm(t,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(t,n);return}const d=new Date().toISOString(),c=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(m?_m(t,"",d,m):t,n)}function Bm(t){let n=1,s="terminal";for(;;){let l=!1;for(const d of t.values())if(d.name===s){l=!0;break}if(!l)break;s=`terminal-${n}`,n++}return s}const Vc=ih((t,n)=>({sessions:new Map,activeSessionId:null,nextSessionNumber:1,createSession:s=>{const l=Hh(),d=Date.now(),c=n().sessions,h=Bm(c),m={id:l,cwd:s,sessionId:null,name:h,customName:!1,createdAt:d,lastActivity:d};return t(g=>{const p=new Map(g.sessions);return p.set(l,m),{sessions:p,activeSessionId:g.activeSessionId??l,nextSessionNumber:g.nextSessionNumber+1}}),l},closeSession:s=>{t(l=>{const d=new Map(l.sessions),c=l.activeSessionId===s;d.delete(s);let h=l.activeSessionId;if(c){const m=Array.from(d.keys());h=m.length>0?m[0]:null}return{sessions:d,activeSessionId:h}})},switchSession:s=>{t(l=>l.sessions.has(s)?{activeSessionId:s}:l)},updateSession:(s,l)=>{t(d=>{const c=d.sessions.get(s);if(!c)return d;const h=new Map(d.sessions);return h.set(s,{...c,...l,lastActivity:Date.now()}),{sessions:h}})},setTerminalSession:(s,l)=>{n().updateSession(s,{sessionId:l.sessionId})},getActiveSession:()=>{const s=n();if(s.activeSessionId)return s.sessions.get(s.activeSessionId)},getSessionCount:()=>n().sessions.size,clearAllSessions:()=>{t({sessions:new Map,activeSessionId:null,nextSessionNumber:1})}}));function Om(t,n){return t===n||n.endsWith(`/${t}`)||t.endsWith(`/${n}`)}function Yc(t,n){return`${t??""}\0${n}`}function Um(t,n,s){if(!t||t.length===0||!s)return{explained:0,stale:0};const l=Yc(n,s);let d=0,c=0;for(const h of t){const m=[h.filePath,h.newPath,h.oldPath].filter(p=>typeof p=="string"&&p.length>0);(m.some(p=>Yc(h.repoRoot,p)===l)||m.some(p=>Om(p,s)))&&(d+=1)}return{explained:d,stale:c}}function Hm({status:t}){if(!t)return null;const n=t.stale>0&&t.explained===0;if(!(t.explained>0||t.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(lm,{size:10}):e.jsx(Es,{size:10})})}function Si({changeStatus:t,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(t),e.jsx(Hm,{status:n})]})}const qd="termdock:right-sidebar:diff-change-list-mode:v1";function zm(t){return t==="list"||t==="tree"}function Wm(){return tt(qd,zm)??"tree"}function Gm(t){for(const l of t){const d=l.hunk;if(d.oldPath&&d.newPath&&d.oldPath!==d.newPath)return"renamed";if(!d.oldPath&&d.newPath)return"added";if(d.oldPath&&!d.newPath)return"deleted"}const n=t.some(l=>l.hunk.additions>0),s=t.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function qm(t){const n=new Map;for(const l of t){const d=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};d.items.push(l),d.additions+=l.hunk.additions,d.deletions+=l.hunk.deletions,l.current&&(d.explained+=1),l.stale&&(d.stale+=1),n.set(l.hunk.filePath,d)}const s=Array.from(n.values()).sort((l,d)=>l.filePath.localeCompare(d.filePath));for(const l of s)l.changeType=Gm(l.items);return s}function Km(t){const n=t.filePath.split("/").pop()??t.filePath;return{key:t.key,path:t.filePath,displayName:n,displayDir:t.filePath.includes("/")?t.filePath.slice(0,-n.length-1):"",status:t.changeType,title:t.filePath}}function Vm(t,n){const s=t.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],d=new Set;for(const[c,h]of s.entries()){const m=h.split(`
4
- `),g=m.findIndex(k=>k.startsWith("@@ "));if(g<0){l.push(...m);continue}c===0&&l.push(...m.slice(0,g));const p=n[c];let f=g;for(;f>=0&&f<m.length;){const k=m.findIndex((E,$)=>$>f&&E.startsWith("@@ ")),y=k>=0?k:m.length,N=m.slice(f,y),I=N[0]??"",_=p?I===p:!0,B=I||p||N.join(`
5
- `);_&&!d.has(B)&&(l.push(...N),d.add(B)),f=k}}return l.join(`
6
- `)}function Ym({groups:t,onInsertDiffReference:n}){return t.map(s=>{const l=Vm(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),d=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:d[0]?.repoRoot?`${d[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:d[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:d,onInsertDiffReference:n}})}function Xm(t,n,s){const l=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=t.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const p of l){const f=p.getBoundingClientRect();if(f.bottom<c)continue;const k=Math.abs(f.top-c);k<m&&(h=p,m=k)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function Xc({items:t,selectedKey:n,onSelect:s,emptyText:l,mobile:d=!1,backLabel:c="Back",headerTitle:h,headerMeta:m,onClose:g,closeLabel:p="Back",wrap:f=!0,onToggleWrap:k,wrapTitle:y,wrapOnLabel:N="Wrap on",wrapOffLabel:I="Wrap off",desktopLayout:_="split",onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:$,copiedReferenceKey:L,onClearAuditRecord:A,walkthroughs:U=[],onWalkthroughNavigate:F,initialDetailScrollTop:a,onDetailScrollPositionChange:w,scrollToKey:O,scrollToKeyNonce:j,externalSwiperRef:Y,onMobileSlideChange:ne}){const{t:ae}=pt(),fe=o.useMemo(()=>qm(t),[t]),G=o.useMemo(()=>new Map(fe.map(le=>[le.key,le])),[fe]),[J,M]=o.useState(()=>Wm()),[D,K]=o.useState(()=>new Set),[re,oe]=o.useState({key:null,nonce:0}),he=fe.find(le=>le.explained>0||le.stale>0)?.key??fe[0]?.key??null,me=n&&fe.some(le=>le.key===n)?n:he,Re=o.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:fe.map(Km)}],[fe]),C=o.useMemo(()=>Ym({groups:fe,onInsertDiffReference:B}),[fe,B]),Z=o.useRef(he),de=o.useRef(s);Z.current=he,de.current=s,o.useEffect(()=>{!n&&Z.current&&de.current(Z.current)},[n]);const Le=k?e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]}):null,We=le=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),m&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:m})]}),g&&e.jsxs("button",{type:"button",onClick:g,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[e.jsx(Ns,{size:14}),p]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[le,Le]})]});if(t.length===0){const le=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!g?le:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[We(null),le]})}const _e=k?({slideToList:le})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:le,children:[e.jsx(Ns,{size:14}),c]}),e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]})]}):void 0;return e.jsx(yi,{mobile:d,desktopLayout:_,backLabel:c,groups:Re,selectedKey:me,mode:J,onModeChange:le=>{M(le),le!=="ai"&&vt(qd,le)},compact:d,collapsedDirectoryKeys:D,onToggleDirectory:le=>{K(se=>{const S=new Set(se);return S.has(le)?S.delete(le):S.add(le),S})},onSelectFile:le=>{s(le.key),oe(se=>({key:le.key,nonce:se.nonce+1}))},renderLeading:le=>{const se=G.get(le.key);return e.jsx(Si,{changeStatus:le.status,auditStatus:se,renderChangeBadge:S=>e.jsx(js,{status:S})})},renderTrailing:le=>{const se=G.get(le.key);return se?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",se.additions," -",se.deletions]}):null},renderListHeader:We,aiContent:({slideToDetail:le,fullscreen:se,toggleFullscreen:S})=>U.length>0&&F?e.jsx(_d,{walkthroughs:U,repoRoot:U[0]?.repoRoot,fullscreen:se,onToggleFullscreen:S,onNavigate:V=>{d&&window.requestAnimationFrame(le),F(V)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:ae("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:_e,externalSwiperRef:Y,onMobileSlideChange:ne,detailContainerClassName:d?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:a,scrollToKey:O??re.key,scrollToKeyNonce:O==null?re.nonce:j,onDetailScroll:le=>{Xm(le,me,s),w?.(le.scrollTop)},files:C,activePane:!0,wrap:f,renderStreamBadge:(le,se)=>{const S=G.get(se.key);return e.jsx(Si,{changeStatus:le,auditStatus:S,renderChangeBadge:V=>e.jsx(js,{status:V})})},onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:$,copiedReferenceKey:L,onClearAuditRecord:A,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function Jm(t){return t.replace(/\/+$/,"")||"/"}function Qm(t){return[...new Set(Array.from(t,Jm))].sort((n,s)=>n.localeCompare(s))}function Zm(t){return t==="event-storm"||t==="reconnected"||t==="directory-rescan"||t==="polling-fallback"}function ep(t){let n=null;return{applicableEvents:t.filter(l=>{const d=l.type==="rescan-required"&&!Zm(l.reason);return d&&l.reason&&!n&&(n=l.reason),!d}),unavailableReason:n}}const tp=1400,rp=1200,Kd=44,np=.7;function Jo(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function ji(t){return`termdock:right-sidebar:context-draft-height:${t}:v1`}function sp(t){try{const n=window.localStorage.getItem(ji(t)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Kd?s:null}catch{return null}}function Jc(t,n){try{n===null?window.localStorage.removeItem(ji(t)):window.localStorage.setItem(ji(t),String(n))}catch{}}function La(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function ap({value:t,collapsed:n,labels:s,focusRequest:l,insertError:d,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:m,onAutoCollapseAfterSendChange:g,onDisable:p,onClear:f,onInsert:k,onInsertAndSend:y}){const[N,I]=o.useState(null),[_,B]=o.useState(!1),[E,$]=o.useState(()=>sp(Jo())),L=o.useRef(E),A=o.useRef(null),U=o.useRef(null),F=o.useRef(t),a=o.useRef(null),w=o.useRef(null),O=!!t.trim(),j=t.trim().split(`
7
- `)[0]??"",Y=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";o.useEffect(()=>()=>{A.current!==null&&window.clearTimeout(A.current),U.current!==null&&window.clearTimeout(U.current)},[]),o.useEffect(()=>{let C=!1;const Z=Jo();return lh().then(de=>{if(C)return;const Le=de.contextDraftHeight?.[Z]??null;Jc(Z,Le),L.current=Le,$(Le)}).catch(()=>{}),()=>{C=!0}},[]),o.useEffect(()=>{if(l!==void 0&&l>0){const C=a.current;if(!C)return;La()||C.focus(),C.setSelectionRange(C.value.length,C.value.length),C.scrollTop=C.scrollHeight}},[l]),o.useEffect(()=>{const C=F.current;F.current=t,!(!n||t.length<=C.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},rp))},[t,n]),o.useEffect(()=>{if(n)return;const C=a.current;C&&(C.style.height=E!==null?`${E}px`:"")},[t,n,E]),o.useEffect(()=>{if(n)return;const C=a.current;!C||document.activeElement===C||(C.scrollTop=C.scrollHeight)},[t,n]),o.useEffect(()=>{if(n||La())return;const C=a.current;!C||document.activeElement===C||(C.focus(),C.setSelectionRange(C.value.length,C.value.length))},[n]);const ne=o.useRef(null);o.useLayoutEffect(()=>{if(!La())return;const C=window.visualViewport;if(!C)return;const Z=()=>{const de=ne.current;if(!de)return;if(C.height>=window.innerHeight*.75){de.style.transform="";return}const Le=de.getBoundingClientRect(),We=Math.round(C.height-Le.bottom);de.style.transform=We!==0?`translateY(${We}px)`:""};return Z(),C.addEventListener("resize",Z),C.addEventListener("scroll",Z),()=>{C.removeEventListener("resize",Z),C.removeEventListener("scroll",Z),ne.current&&(ne.current.style.transform="")}},[n]);const ae=C=>{I(C),A.current!==null&&window.clearTimeout(A.current),A.current=window.setTimeout(()=>{A.current=null,I(null)},tp)},fe=C=>{m(!1),La()&&window.requestAnimationFrame(()=>{const Z=a.current;if(!Z)return;Z.focus();const de=Z.value.length;Z.setSelectionRange(de,de),window.requestAnimationFrame(()=>{Z.setSelectionRange(de,de)})})},G=()=>{k(),ae("inserted")},J=()=>{O&&(y(),ae("sent"))},M=C=>{if(C.key==="Escape"){C.preventDefault(),m(!0);return}C.key!=="Enter"||!C.metaKey&&!C.ctrlKey||(C.preventDefault(),J())},D=C=>{C.preventDefault()},K=C=>{C.preventDefault();const Z=a.current;Z&&(w.current={startY:C.clientY,startHeight:Z.getBoundingClientRect().height},C.currentTarget.setPointerCapture?.(C.pointerId))},re=C=>{const Z=w.current;if(!Z)return;const de=window.visualViewport?.height??window.innerHeight,Le=Math.round(Math.min(Math.max(Z.startHeight+(Z.startY-C.clientY),Kd),de*np));L.current=Le,$(Le)},oe=C=>{const Z=Jo();Jc(Z,C),ch({contextDraftHeight:{[Z]:C}}).catch(()=>{})},he=()=>{w.current&&(w.current=null,L.current!==null&&oe(L.current))},me=()=>{L.current=null,$(null),oe(null)},Re=t.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(t.length)});return n?e.jsx("section",{ref:ne,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:e.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[e.jsxs("button",{type:"button",onClick:()=>fe(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":s.expand,title:s.expand,children:[e.jsx(zh,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${d?"text-destructive":_?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:d??(_?s.appended:O?j:s.title)})]}),Re,e.jsx("button",{type:"button",onClick:J,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:N==="sent"?e.jsx(gi,{size:12}):e.jsx(Kc,{size:12})})]})}):e.jsxs("section",{ref:ne,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:K,onPointerMove:re,onPointerUp:he,onPointerCancel:he,onDoubleClick:me,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:D,onClick:()=>m(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Ms,{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}),Re]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:D,onClick:()=>g(!c),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${c?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:D,onClick:p,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Ut,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:a,value:t,onChange:C=>h(C.target.value),onKeyDown:M,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:D,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(Oa,{size:11})}),d?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:d}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:D,onClick:G,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(Wh,{size:11}),e.jsx("span",{children:N==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:D,onClick:J,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} · ${Y}`,children:[N==="sent"?e.jsx(gi,{size:11}):e.jsx(Kc,{size:11}),e.jsx("span",{children:N==="sent"?s.sent:s.send})]})]})]})})]})}function op(t,n){const s=n.trim();if(!s)return t;if(!t.trim())return s;const l=t.endsWith(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-Da1kMWa7.js","assets/app-DIA5Fax_.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-COVHbD7S.css","assets/App-B5iubRB9.js","assets/gestureArbiter-HaGDIrQz.js","assets/gestureArbiter-C2J0D0kV.css","assets/referenceLongPress-BfTDwMvD.js","assets/triangle-alert-6QR6NZO7.js","assets/DiffReview-WcdcQoMa.js","assets/sparkles-CxSnvQPG.js","assets/DiffViewer-BjAyUxOt.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-BMhWQpCh.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-CW-pInWx.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
+ import{a0 as Mt,Y as ch,aV as e,ca as yt,ch as xt,b9 as tt,a as Cs,ay as dh,C as gi,c as Ns,X as Ot,c8 as uh,aL as fh,w as ps,ad as hh,cc as te,aP as mh,aR as Oi,aS as ph,aT as Ad,aQ as gs,an as gh,E as bh,h as xh,aO as vh,ba as yh,bc as wh,bd as kh,aG as Sh,bb as _c,v as bt,e as jh,L as vt,s as Rh,b as Ch,aF as Bc,ak as Oc,ai as Nh,ar as Ra,as as Uc,ci as ks,ab as bs,at as Mh,c9 as Vo,b4 as $h,am as Eh,c6 as Lh,bD as Ah,av as Ph,I as Hc,H as Th,aj as Ih,al as Fh,ap as zc,bF as Dh,q as _h,d as Ca,f as bi,t as Pd,a7 as Bh,_ as Ms,bx as Oh,cf as Uh,b0 as Hh,a9 as zh}from"./app-DIA5Fax_.js";import{y as Wh,g as Gh,p as _a,e as qh,P as Kh,k as Vh,R as xi,q as Td,r as Yh,S as Vn,D as Xh,c as Id,a as Jh,x as Fd,v as Wc,u as Na,s as Qh,t as Zh,w as em,T as Gc,d as qc,j as Yo,i as Ma,b as tm,m as rm,h as nm,f as sm,n as am,F as Kc,C as om,G as im}from"./App-B5iubRB9.js";import{b as o,r as Gr}from"./dnd-BCFAPC0L.js";import{a as lm,S as cm,b as Dd,c as vi,F as dm}from"./gestureArbiter-HaGDIrQz.js";import{D as yi,C as Ss,L as _d,f as um,n as fm}from"./DiffReview-WcdcQoMa.js";import{T as hm,L as Ha,G as Cr}from"./triangle-alert-6QR6NZO7.js";import{S as $s}from"./sparkles-CxSnvQPG.js";import{C as Bd,a as Od,M as Ud}from"./ChangeWalkthroughPanel-BMhWQpCh.js";import{r as Hd,s as zd,l as Wd,u as mm,h as Gd}from"./DiffViewer-BjAyUxOt.js";import{u as qd,G as Kd}from"./referenceLongPress-BfTDwMvD.js";const pm=[["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"}]],gm=Mt("case-sensitive",pm);const bm=[["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"}]],xm=Mt("eye-off",bm);const vm=[["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"}]],wi=Mt("eye",vm);const ym=[["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"}]],ki=Mt("file-text",ym);const wm=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],Vc=Mt("house",wm);const km=[["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"}]],Sm=Mt("image-plus",km);const jm=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]],Rm=Mt("maximize",jm);const Cm=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]],Nm=Mt("minimize",Cm);const Mm=[["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"}]],$m=Mt("regex",Mm);const Em=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Lm=Mt("rotate-cw",Em);const Am=[["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"}]],Pm=Mt("scan",Am);const Tm=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],Yc=Mt("send",Tm);const Im=[["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"}]],Fm=Mt("upload",Im);const Dm=[["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"}]],_m=Mt("whole-word",Dm);async function Bm(t){let n;try{await Promise.race([t(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function Om({active:t,rootPath:n,loading:s,delay:l,lastStartedRoot:d,load:c}){o.useEffect(()=>{if(!t||!n||s||d.current===n)return;const h=window.setTimeout(()=>{d.current=n,c(n)},l);return()=>window.clearTimeout(h)},[t,n,s,l,d,c])}function Um(t,n,s){try{const l=t instanceof HTMLImageElement?t.naturalWidth:t.width,d=t instanceof HTMLImageElement?t.naturalHeight:t.height;if(!l||!d)return Promise.resolve(null);const c=t instanceof HTMLImageElement?1400/Math.max(l,d):Math.min(1,1400/Math.max(l,d)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(d*c));const m=h.getContext("2d");if(!m)return Promise.resolve(null);const g=getComputedStyle(document.documentElement);if(m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,h.height),m.drawImage(t,0,0,h.width,h.height),s){const p=Math.max(10,Math.min(16,h.width/35));m.font=`${p}px sans-serif`;const f=[];let k="";for(const y of s.split(" "))k&&m.measureText(`${k} ${y}`).width>h.width-20?(f.push(k),k=y):k=k?`${k} ${y}`:y;k&&f.push(k),m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,f.length*(p+4)+12),m.fillStyle=g.getPropertyValue("--foreground").trim()||"black",f.forEach((y,N)=>m.fillText(y,10,8+p+N*(p+4)))}if(n){const p=n.xPercent*h.width/100,f=n.yPercent*h.height/100,k=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=k*1.6;m.strokeStyle=g.getPropertyValue("--primary").trim()||"black",m.lineWidth=Math.max(1,k/3),m.beginPath(),m.arc(p,f,k,0,Math.PI*2),m.stroke(),m.beginPath(),m.moveTo(p-y,f),m.lineTo(p+y,f),m.moveTo(p,f-y),m.lineTo(p,f+y),m.stroke()}return new Promise(p=>h.toBlob(p,"image/png"))}catch{return Promise.resolve(null)}}function Hm(t,n,s,l){return[t.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
+ `)}function Tb(t,n,s){const l=n*Math.PI/360,d=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(t,1e-6)/Math.sin(d)*1.15}async function zm(t,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(t,n);return}const d=new Date().toISOString(),c=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(m?Hm(t,"",d,m):t,n)}function Wm(t){let n=1,s="terminal";for(;;){let l=!1;for(const d of t.values())if(d.name===s){l=!0;break}if(!l)break;s=`terminal-${n}`,n++}return s}const Xc=ch((t,n)=>({sessions:new Map,activeSessionId:null,nextSessionNumber:1,createSession:s=>{const l=Wh(),d=Date.now(),c=n().sessions,h=Wm(c),m={id:l,cwd:s,sessionId:null,name:h,customName:!1,createdAt:d,lastActivity:d};return t(g=>{const p=new Map(g.sessions);return p.set(l,m),{sessions:p,activeSessionId:g.activeSessionId??l,nextSessionNumber:g.nextSessionNumber+1}}),l},closeSession:s=>{t(l=>{const d=new Map(l.sessions),c=l.activeSessionId===s;d.delete(s);let h=l.activeSessionId;if(c){const m=Array.from(d.keys());h=m.length>0?m[0]:null}return{sessions:d,activeSessionId:h}})},switchSession:s=>{t(l=>l.sessions.has(s)?{activeSessionId:s}:l)},updateSession:(s,l)=>{t(d=>{const c=d.sessions.get(s);if(!c)return d;const h=new Map(d.sessions);return h.set(s,{...c,...l,lastActivity:Date.now()}),{sessions:h}})},setTerminalSession:(s,l)=>{n().updateSession(s,{sessionId:l.sessionId})},getActiveSession:()=>{const s=n();if(s.activeSessionId)return s.sessions.get(s.activeSessionId)},getSessionCount:()=>n().sessions.size,clearAllSessions:()=>{t({sessions:new Map,activeSessionId:null,nextSessionNumber:1})}}));function Gm(t,n){return t===n||n.endsWith(`/${t}`)||t.endsWith(`/${n}`)}function Jc(t,n){return`${t??""}\0${n}`}function qm(t,n,s){if(!t||t.length===0||!s)return{explained:0,stale:0};const l=Jc(n,s);let d=0,c=0;for(const h of t){const m=[h.filePath,h.newPath,h.oldPath].filter(p=>typeof p=="string"&&p.length>0);(m.some(p=>Jc(h.repoRoot,p)===l)||m.some(p=>Gm(p,s)))&&(d+=1)}return{explained:d,stale:c}}function Km({status:t}){if(!t)return null;const n=t.stale>0&&t.explained===0;if(!(t.explained>0||t.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(hm,{size:10}):e.jsx($s,{size:10})})}function Si({changeStatus:t,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(t),e.jsx(Km,{status:n})]})}const Vd="termdock:right-sidebar:diff-change-list-mode:v1";function Vm(t){return t==="list"||t==="tree"}function Ym(){return tt(Vd,Vm)??"tree"}function Xm(t){for(const l of t){const d=l.hunk;if(d.oldPath&&d.newPath&&d.oldPath!==d.newPath)return"renamed";if(!d.oldPath&&d.newPath)return"added";if(d.oldPath&&!d.newPath)return"deleted"}const n=t.some(l=>l.hunk.additions>0),s=t.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function Jm(t){const n=new Map;for(const l of t){const d=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};d.items.push(l),d.additions+=l.hunk.additions,d.deletions+=l.hunk.deletions,l.current&&(d.explained+=1),l.stale&&(d.stale+=1),n.set(l.hunk.filePath,d)}const s=Array.from(n.values()).sort((l,d)=>l.filePath.localeCompare(d.filePath));for(const l of s)l.changeType=Xm(l.items);return s}function Qm(t){const n=t.filePath.split("/").pop()??t.filePath;return{key:t.key,path:t.filePath,displayName:n,displayDir:t.filePath.includes("/")?t.filePath.slice(0,-n.length-1):"",status:t.changeType,title:t.filePath}}function Zm(t,n){const s=t.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],d=new Set;for(const[c,h]of s.entries()){const m=h.split(`
4
+ `),g=m.findIndex(k=>k.startsWith("@@ "));if(g<0){l.push(...m);continue}c===0&&l.push(...m.slice(0,g));const p=n[c];let f=g;for(;f>=0&&f<m.length;){const k=m.findIndex((E,$)=>$>f&&E.startsWith("@@ ")),y=k>=0?k:m.length,N=m.slice(f,y),I=N[0]??"",D=p?I===p:!0,B=I||p||N.join(`
5
+ `);D&&!d.has(B)&&(l.push(...N),d.add(B)),f=k}}return l.join(`
6
+ `)}function ep({groups:t,onInsertDiffReference:n}){return t.map(s=>{const l=Zm(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),d=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:d[0]?.repoRoot?`${d[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:d[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:d,onInsertDiffReference:n}})}function tp(t,n,s){const l=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=t.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const p of l){const f=p.getBoundingClientRect();if(f.bottom<c)continue;const k=Math.abs(f.top-c);k<m&&(h=p,m=k)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function Qc({items:t,selectedKey:n,onSelect:s,emptyText:l,mobile:d=!1,backLabel:c="Back",headerTitle:h,headerMeta:m,onClose:g,closeLabel:p="Back",wrap:f=!0,onToggleWrap:k,wrapTitle:y,wrapOnLabel:N="Wrap on",wrapOffLabel:I="Wrap off",desktopLayout:D="split",onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:$,copiedReferenceKey:L,onClearAuditRecord:A,walkthroughs:U=[],onWalkthroughNavigate:F,initialDetailScrollTop:a,onDetailScrollPositionChange:w,scrollToKey:O,scrollToKeyNonce:j,externalSwiperRef:X,onMobileSlideChange:ne}){const{t:se}=yt(),fe=o.useMemo(()=>Jm(t),[t]),G=o.useMemo(()=>new Map(fe.map(le=>[le.key,le])),[fe]),[J,M]=o.useState(()=>Ym()),[_,K]=o.useState(()=>new Set),[re,oe]=o.useState({key:null,nonce:0}),he=fe.find(le=>le.explained>0||le.stale>0)?.key??fe[0]?.key??null,me=n&&fe.some(le=>le.key===n)?n:he,je=o.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:fe.map(Qm)}],[fe]),C=o.useMemo(()=>ep({groups:fe,onInsertDiffReference:B}),[fe,B]),Z=o.useRef(he),de=o.useRef(s);Z.current=he,de.current=s,o.useEffect(()=>{!n&&Z.current&&de.current(Z.current)},[n]);const Ee=k?e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]}):null,Ge=le=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),m&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:m})]}),g&&e.jsxs("button",{type:"button",onClick:g,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[e.jsx(Cs,{size:14}),p]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[le,Ee]})]});if(t.length===0){const le=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!g?le:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[Ge(null),le]})}const De=k?({slideToList:le})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:le,children:[e.jsx(Cs,{size:14}),c]}),e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]})]}):void 0;return e.jsx(yi,{mobile:d,desktopLayout:D,backLabel:c,groups:je,selectedKey:me,mode:J,onModeChange:le=>{M(le),le!=="ai"&&xt(Vd,le)},compact:d,collapsedDirectoryKeys:_,onToggleDirectory:le=>{K(ae=>{const S=new Set(ae);return S.has(le)?S.delete(le):S.add(le),S})},onSelectFile:le=>{s(le.key),oe(ae=>({key:le.key,nonce:ae.nonce+1}))},renderLeading:le=>{const ae=G.get(le.key);return e.jsx(Si,{changeStatus:le.status,auditStatus:ae,renderChangeBadge:S=>e.jsx(Ss,{status:S})})},renderTrailing:le=>{const ae=G.get(le.key);return ae?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",ae.additions," -",ae.deletions]}):null},renderListHeader:Ge,aiContent:({slideToDetail:le,fullscreen:ae,toggleFullscreen:S})=>U.length>0&&F?e.jsx(Bd,{walkthroughs:U,repoRoot:U[0]?.repoRoot,fullscreen:ae,onToggleFullscreen:S,onNavigate:V=>{d&&window.requestAnimationFrame(le),F(V)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:se("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:De,externalSwiperRef:X,onMobileSlideChange:ne,detailContainerClassName:d?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:a,scrollToKey:O??re.key,scrollToKeyNonce:O==null?re.nonce:j,onDetailScroll:le=>{tp(le,me,s),w?.(le.scrollTop)},files:C,activePane:!0,wrap:f,renderStreamBadge:(le,ae)=>{const S=G.get(ae.key);return e.jsx(Si,{changeStatus:le,auditStatus:S,renderChangeBadge:V=>e.jsx(Ss,{status:V})})},onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:$,copiedReferenceKey:L,onClearAuditRecord:A,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function rp(t){return t.replace(/\/+$/,"")||"/"}function np(t){return[...new Set(Array.from(t,rp))].sort((n,s)=>n.localeCompare(s))}function sp(t){return t==="event-storm"||t==="reconnected"||t==="directory-rescan"||t==="polling-fallback"}function ap(t){let n=null;return{applicableEvents:t.filter(l=>{const d=l.type==="rescan-required"&&!sp(l.reason);return d&&l.reason&&!n&&(n=l.reason),!d}),unavailableReason:n}}const op=1400,ip=1200,Yd=44,lp=.7;function Xo(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function ji(t){return`termdock:right-sidebar:context-draft-height:${t}:v1`}function cp(t){try{const n=window.localStorage.getItem(ji(t)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=Yd?s:null}catch{return null}}function Zc(t,n){try{n===null?window.localStorage.removeItem(ji(t)):window.localStorage.setItem(ji(t),String(n))}catch{}}function $a(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function dp({value:t,collapsed:n,labels:s,focusRequest:l,insertError:d,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:m,onAutoCollapseAfterSendChange:g,onDisable:p,onClear:f,onInsert:k,onInsertAndSend:y}){const[N,I]=o.useState(null),[D,B]=o.useState(!1),[E,$]=o.useState(()=>cp(Xo())),L=o.useRef(E),A=o.useRef(null),U=o.useRef(null),F=o.useRef(t),a=o.useRef(null),w=o.useRef(null),O=!!t.trim(),j=t.trim().split(`
7
+ `)[0]??"",X=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";o.useEffect(()=>()=>{A.current!==null&&window.clearTimeout(A.current),U.current!==null&&window.clearTimeout(U.current)},[]),o.useEffect(()=>{let C=!1;const Z=Xo();return dh().then(de=>{if(C)return;const Ee=de.contextDraftHeight?.[Z]??null;Zc(Z,Ee),L.current=Ee,$(Ee)}).catch(()=>{}),()=>{C=!0}},[]),o.useEffect(()=>{if(l!==void 0&&l>0){const C=a.current;if(!C)return;$a()||C.focus(),C.setSelectionRange(C.value.length,C.value.length),C.scrollTop=C.scrollHeight}},[l]),o.useEffect(()=>{const C=F.current;F.current=t,!(!n||t.length<=C.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},ip))},[t,n]),o.useEffect(()=>{if(n)return;const C=a.current;C&&(C.style.height=E!==null?`${E}px`:"")},[t,n,E]),o.useEffect(()=>{if(n)return;const C=a.current;!C||document.activeElement===C||(C.scrollTop=C.scrollHeight)},[t,n]),o.useEffect(()=>{if(n||$a())return;const C=a.current;!C||document.activeElement===C||(C.focus(),C.setSelectionRange(C.value.length,C.value.length))},[n]);const ne=o.useRef(null);o.useLayoutEffect(()=>{if(!$a())return;const C=window.visualViewport;if(!C)return;const Z=()=>{const de=ne.current;if(!de)return;if(C.height>=window.innerHeight*.75){de.style.transform="";return}const Ee=de.getBoundingClientRect(),Ge=Math.round(C.height-Ee.bottom);de.style.transform=Ge!==0?`translateY(${Ge}px)`:""};return Z(),C.addEventListener("resize",Z),C.addEventListener("scroll",Z),()=>{C.removeEventListener("resize",Z),C.removeEventListener("scroll",Z),ne.current&&(ne.current.style.transform="")}},[n]);const se=C=>{I(C),A.current!==null&&window.clearTimeout(A.current),A.current=window.setTimeout(()=>{A.current=null,I(null)},op)},fe=C=>{m(!1),$a()&&window.requestAnimationFrame(()=>{const Z=a.current;if(!Z)return;Z.focus();const de=Z.value.length;Z.setSelectionRange(de,de),window.requestAnimationFrame(()=>{Z.setSelectionRange(de,de)})})},G=()=>{k(),se("inserted")},J=()=>{O&&(y(),se("sent"))},M=C=>{if(C.key==="Escape"){C.preventDefault(),m(!0);return}C.key!=="Enter"||!C.metaKey&&!C.ctrlKey||(C.preventDefault(),J())},_=C=>{C.preventDefault()},K=C=>{C.preventDefault();const Z=a.current;Z&&(w.current={startY:C.clientY,startHeight:Z.getBoundingClientRect().height},C.currentTarget.setPointerCapture?.(C.pointerId))},re=C=>{const Z=w.current;if(!Z)return;const de=window.visualViewport?.height??window.innerHeight,Ee=Math.round(Math.min(Math.max(Z.startHeight+(Z.startY-C.clientY),Yd),de*lp));L.current=Ee,$(Ee)},oe=C=>{const Z=Xo();Zc(Z,C),uh({contextDraftHeight:{[Z]:C}}).catch(()=>{})},he=()=>{w.current&&(w.current=null,L.current!==null&&oe(L.current))},me=()=>{L.current=null,$(null),oe(null)},je=t.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(t.length)});return n?e.jsx("section",{ref:ne,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:e.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[e.jsxs("button",{type:"button",onClick:()=>fe(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":s.expand,title:s.expand,children:[e.jsx(Gh,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${d?"text-destructive":D?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:d??(D?s.appended:O?j:s.title)})]}),je,e.jsx("button",{type:"button",onClick:J,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:N==="sent"?e.jsx(gi,{size:12}):e.jsx(Yc,{size:12})})]})}):e.jsxs("section",{ref:ne,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:K,onPointerMove:re,onPointerUp:he,onPointerCancel:he,onDoubleClick:me,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:_,onClick:()=>m(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Ns,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:s.title}),je]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:_,onClick:()=>g(!c),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${c?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:_,onClick:p,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Ot,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:a,value:t,onChange:C=>h(C.target.value),onKeyDown:M,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:_,onClick:f,disabled:!O,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(_a,{size:11})}),d?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:d}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:_,onClick:G,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(qh,{size:11}),e.jsx("span",{children:N==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:_,onClick:J,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} · ${X}`,children:[N==="sent"?e.jsx(gi,{size:11}):e.jsx(Yc,{size:11}),e.jsx("span",{children:N==="sent"?s.sent:s.send})]})]})]})})]})}function up(t,n){const s=n.trim();if(!s)return t;if(!t.trim())return s;const l=t.endsWith(`
8
8
 
9
9
  `)?"":t.endsWith(`
10
10
  `)?`
11
11
  `:`
12
12
 
13
- `;return`${t}${l}${s}`}function ip(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const Ri="termdock:right-sidebar:html-view-mode-by-file:v1";function lp(t){return t==="preview"||t==="source"}function Vd(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(lp)}function Yd(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Qc(t,n){const s=Yd(t,n);return s?tt(Ri,Vd)?.[s]??"source":"source"}function cp(t,n,s){const l=Yd(t,n);if(!l)return;const d=tt(Ri,Vd)??{};vt(Ri,{...d,[l]:s})}function Zc(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}function Qa(t,n){const[s,l]=o.useState(()=>!!navigator.serviceWorker?.controller);return o.useEffect(()=>{if(!Zc(t)||s)return;const d=navigator.serviceWorker,c=()=>l(!!d?.controller);d?.addEventListener("controllerchange",c),c();const h=window.setTimeout(()=>{d?.controller||n?.()},1e4);return()=>{d?.removeEventListener("controllerchange",c),window.clearTimeout(h)}},[t,s,n]),Zc(t)&&!s?void 0:t}function Qo(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),d=n%60,c=String(l).padStart(2,"0"),h=String(d).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function dp(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const up=350,fp=12,hp=90;function mp({url:t,onLoadError:n}){const s=Qa(t,n),{t:l}=pt(),d=o.useRef(null),c=o.useRef(null),h=o.useRef(null),m=o.useRef(null),g=o.useRef(!1),p=o.useRef(null),f=o.useRef(null),k=o.useRef(0),y=o.useRef(!1),N=o.useRef(!1),I=o.useRef(!1),_=o.useRef(null),B=o.useRef(null),E=o.useRef(!1),$=o.useRef(1),L=o.useRef(!1),[A,U]=o.useState(0),[F,a]=o.useState(0),[w,O]=o.useState(!1),[j,Y]=o.useState(!1),[ne,ae]=o.useState(null),[fe,G]=o.useState(!1),[J,M]=o.useState(0),[D,K]=o.useState(!1),[re,oe]=o.useState({width:0,height:0}),he=o.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),me=o.useCallback(()=>{if(he(),B.current=null,!E.current)return!1;const W=h.current;return W&&(W.playbackRate=$.current),E.current=!1,G(!1),!0},[he]);o.useEffect(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current),f.current!==null&&clearTimeout(f.current),he();const W=h.current;W&&E.current&&(W.playbackRate=$.current)},[he]),o.useEffect(()=>{const W=c.current;if(!W||typeof ResizeObserver>"u")return;const q=new ResizeObserver(([Se])=>{Se&&oe({width:Se.contentRect.width,height:Se.contentRect.height})});return q.observe(W),()=>q.disconnect()},[]),o.useEffect(()=>{const W=()=>K(document.fullscreenElement===d.current);return document.addEventListener("fullscreenchange",W),()=>document.removeEventListener("fullscreenchange",W)},[]);const Re=o.useCallback((W,q=!1)=>{const Se=h.current;if(!Se)return!1;const Ce=Number.isFinite(Se.duration)?Se.duration:W,ct=Math.min(Math.max(W,0),Ce);if(a(ct),Math.abs(Se.currentTime-ct)<1/120)return!1;const Qe=Se.fastSeek;return q&&typeof Qe=="function"?Qe.call(Se,ct):Se.currentTime=ct,!0},[]),C=o.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null;const W=h.current;if(!W||!y.current||N.current||W.seeking)return;const q=I.current;I.current=!1,N.current=Re(k.current,!q)}))},[Re]),Z=o.useCallback(W=>{const q=m.current,Se=h.current;if(!q||!Se)return;const Ce=q.getBoundingClientRect(),ct=dp(W,Ce,Se.duration);k.current=ct,ae(ct),I.current=!1,C(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,C()},hp)},[C]),de=o.useCallback(()=>{p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,N.current=!1,Re(k.current)},[Re]),Le=o.useCallback(W=>{const q=h.current;if(!(!q||!Number.isFinite(q.duration)||q.duration<=0)){g.current=!q.paused,q.pause(),y.current=!0,Y(!0);try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}Z(W.clientX)}},[Z]),We=o.useCallback(()=>{y.current=!1,de(),Y(!1),ae(null);const W=h.current;W&&g.current&&!W.ended&&W.play().catch(()=>{}),g.current=!1},[de]),_e=o.useCallback(()=>{const W=h.current;if(W){if(L.current){L.current=!1;return}W.paused?W.play().catch(()=>{}):W.pause()}},[]),le=o.useCallback(W=>{const q=h.current;!q||q.paused||W.button!==0||(he(),B.current={id:W.pointerId,x:W.clientX,y:W.clientY},_.current=setTimeout(()=>{_.current=null,$.current=q.playbackRate,q.playbackRate=2,E.current=!0,G(!0)},up))},[he]),se=o.useCallback(W=>{const q=B.current;!q||q.id!==W.pointerId||E.current||Math.hypot(W.clientX-q.x,W.clientY-q.y)>fp&&(he(),B.current=null)},[he]),S=o.useCallback(()=>{me()&&(L.current=!0)},[me]);o.useEffect(()=>(window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S),window.addEventListener("blur",S),()=>{window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),window.removeEventListener("blur",S)}),[S]);const V=o.useCallback(async()=>{const W=d.current,q=h.current;if(!(!W||!q))try{document.fullscreenElement===W?await document.exitFullscreen():W.requestFullscreen?await W.requestFullscreen():q.webkitEnterFullscreen?.()}catch{q.webkitEnterFullscreen?.()}},[]),we=o.useCallback(()=>M(W=>(W+90)%360),[]),be=o.useCallback(W=>{const q=h.current;if(!q||!Number.isFinite(q.duration))return;const Se=W.shiftKey?10:5;let Ce=null;W.key==="ArrowLeft"?Ce=q.currentTime-Se:W.key==="ArrowRight"?Ce=q.currentTime+Se:W.key==="Home"?Ce=0:W.key==="End"&&(Ce=q.duration),Ce!==null&&(W.preventDefault(),Re(Ce))},[Re]),Oe=j&&ne!==null?ne:F,ce=A>0?Math.min(1,Math.max(0,Oe/A)):0,Ae=(J===90||J===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:d,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":J,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...Ae,transform:`translate(-50%, -50%) rotate(${J}deg)`},src:s,preload:"auto",playsInline:!0,onClick:_e,onPointerDown:le,onPointerMove:se,onPointerUp:S,onPointerCancel:S,onContextMenu:W=>{E.current&&W.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:W=>a(W.currentTarget.currentTime),onSeeked:W=>{const q=W.currentTarget;if(a(q.currentTime),N.current=!1,!y.current)return;const Se=q.requestVideoFrameCallback;typeof Se=="function"?Se.call(q,()=>{y.current&&C()}):requestAnimationFrame(()=>{y.current&&C()})},onLoadedMetadata:W=>U(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onDurationChange:W=>U(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),fe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed")}),j&&ne!==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:`${ce*100}%`},"data-testid":"file-preview-video-scrub-time",children:Qo(ne)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${nm}`,[sm]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:_e,"aria-label":l(w?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(w?"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:w?e.jsx(Gh,{size:14}):e.jsx(qh,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(A),"aria-valuenow":Math.floor(Oe),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:Le,onPointerMove:W=>{j&&Z(W.clientX)},onPointerUp:We,onPointerCancel:We,onKeyDown:be,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:`${ce*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:`${ce*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Qo(Oe)," / ",Qo(A)]}),e.jsx("button",{type:"button",onClick:we,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(Mm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{V()},"aria-label":l(D?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(D?"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:D?e.jsx(km,{size:14}):e.jsx(ym,{size:14})})]})})]})}function pp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function Za({anchor:t,children:n,disabled:s=!1,onClick:l,title:d}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:d,style:pp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Wa,{size:11}),n]})}function gp(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const d=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(d)||d<=0)return null;const c=l.width*d,h=l.height*d,m=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,p=t-m,f=n-g;if(p<0||f<0||p>c||f>h)return null;const k=p/c*100,y=f/h*100;return{x:l.x+l.width*k/100,y:l.y+l.height*y/100,xPercent:k,yPercent:y}}function bp(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function xp(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const d of Array.from(l.attributes)){const c=d.name.toLowerCase(),h=d.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(d.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function vp(t,n,s){let l=null;for(const d of Array.from(t.querySelectorAll("text"))){const c=(d.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(d.getAttribute("x")),m=Number(d.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const g=Math.hypot(h-n,m-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function Xd({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const d=o.useRef(null),c=o.useRef(null),[h,m]=o.useState(null),[g,p]=o.useState(null),[f,k]=o.useState(1),[y,N]=o.useState(!1),[I,_]=o.useState(null),B=o.useRef(new Map),E=o.useRef(null),$=o.useRef(!1),L=o.useRef(null),A=o.useRef(f);A.current=f,o.useEffect(()=>{const M=new AbortController;return m(null),p(null),_(null),k(1),fetch(t,{signal:M.signal}).then(D=>D.text()).then(D=>m(xp(D))).catch(D=>{M.signal.aborted||p(D instanceof Error?D.message:"SVG preview failed")}),()=>M.abort()},[t]),o.useEffect(()=>{if(!y)return;const M=D=>{D.key==="Escape"&&N(!1)};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[y]),o.useLayoutEffect(()=>{const M=c.current,D=M?.querySelector("[data-svg-document] > svg");if(!M||!D)return;let K;try{K=D.getBBox()}catch{return}if(!K.width||!K.height)return;const re=Math.max(2,Math.min(K.width,K.height)*.025);D.setAttribute("viewBox",`${K.x-re} ${K.y-re} ${K.width+2*re} ${K.height+2*re}`),D.style.width=`${f*100}%`,D.style.height=`${f*100}%`,D.style.minWidth=`${f*100}%`,D.style.minHeight=`${f*100}%`,D.style.display="block"},[h,f]);const U=o.useMemo(()=>I?bp(n,s,I):null,[n,I,s]),F=M=>{if($.current){$.current=!1;return}const D=c.current,K=D?.querySelector("[data-svg-document] > svg"),re=d.current;if(!D||!K||!re)return;const oe=K.viewBox.baseVal,he=gp(M.clientX,M.clientY,K.getBoundingClientRect(),oe);if(!he)return;const me=re.getBoundingClientRect();_({...he,nearestText:vp(K,he.x,he.y),stageX:M.clientX-me.left,stageY:M.clientY-me.top,stageXPercent:(M.clientX-me.left)/me.width*100,stageYPercent:(M.clientY-me.top)/me.height*100})},a=M=>Math.max(1,Math.min(12,M)),w=(M,D)=>{const K=a(D),re=M.querySelector("[data-svg-document] > svg");if(!re)return K;const oe=`${K*100}%`;return re.style.width=oe,re.style.height=oe,re.style.minWidth=oe,re.style.minHeight=oe,A.current=K,K},O=(M,D,K,re)=>{const oe=A.current,he=M.getBoundingClientRect(),me=K-he.left,Re=re-he.top,C=(M.scrollLeft+me)/oe,Z=(M.scrollTop+Re)/oe,de=w(M,D);return M.scrollLeft=C*de-me,M.scrollTop=Z*de-Re,de},j=()=>{const M=Array.from(B.current.values());return M.length>=2?Math.hypot(M[0].x-M[1].x,M[0].y-M[1].y):0},Y=M=>{if(M.pointerType==="mouse"&&M.button!==0)return;const D=c.current;D&&(B.current.set(M.pointerId,{x:M.clientX,y:M.clientY}),D.setPointerCapture?.(M.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:M.clientX,startY:M.clientY,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startDistance:j(),startZoom:A.current,moved:!1},$.current=!0):A.current>1&&(E.current={kind:"pan",startX:M.clientX,startY:M.clientY,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startZoom:A.current,moved:!1}))},ne=M=>{if(!B.current.has(M.pointerId))return;B.current.set(M.pointerId,{x:M.clientX,y:M.clientY});const D=c.current,K=E.current;if(!(!D||!K)){if(B.current.size>=2&&K.kind==="pinch"){const re=j();if(!K.startDistance||!re)return;const oe=a(K.startZoom*re/K.startDistance);if(Math.abs(oe-A.current)<.01)return;const he=Array.from(B.current.values()),me=(he[0].x+he[1].x)/2,Re=(he[0].y+he[1].y)/2;K.moved=!0,$.current=!0,O(D,oe,me,Re),M.preventDefault();return}if(K.kind==="pan"&&B.current.size===1){const re=M.clientX-K.startX,oe=M.clientY-K.startY;if(!K.moved&&Math.hypot(re,oe)<6)return;K.moved=!0,$.current=!0,D.scrollLeft=K.startScrollLeft-re,D.scrollTop=K.startScrollTop-oe,M.preventDefault()}}},ae=M=>{const D=c.current,K=E.current,re=B.current.size===1&&!K?.moved;B.current.delete(M.pointerId);try{D?.releasePointerCapture?.(M.pointerId)}catch{}if(B.current.size===1&&K?.kind==="pinch"){const me=Array.from(B.current.values())[0];E.current=D?{kind:"pan",startX:me.x,startY:me.y,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startZoom:A.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,K?.kind==="pinch"&&k(A.current),!re||$.current))return;const oe=Date.now(),he=L.current;he&&oe-he.time<350&&Math.hypot(M.clientX-he.x,M.clientY-he.y)<24?(L.current=null,$.current=!0,k(me=>me>1?1:2.5)):L.current={time:oe,x:M.clientX,y:M.clientY}},fe=M=>{if(!M.ctrlKey&&!M.metaKey)return;const D=c.current;if(!D)return;M.preventDefault();const K=O(D,A.current*Math.exp(-M.deltaY*.01),M.clientX,M.clientY);k(K)},G=()=>{k(1),A.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},J=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:F,onDoubleClick:M=>{M.preventDefault(),k(D=>D>1?1:2.5)},onPointerDown:Y,onPointerMove:ne,onPointerUp:ae,onPointerCancel:ae,onWheel:fe,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),I&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:I.stageX,top:I.stageY}}),I&&U&&e.jsx(Za,{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:M=>{M.stopPropagation(),G()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(Em,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:M=>{M.stopPropagation(),N(D=>!D)},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(Dd,{size:14}):e.jsx(Bd,{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?Gr.createPortal(J,document.body):J}function Ua(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function yp(t,n,s,l){const d=[`电子标注: ${t}`,`视图: ${Ua(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(d.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&d.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");d.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${d.join(" / ")}"`}function wp({blobUrl:t,filePath:n,view:s,board:l,onViewChange:d,onInsertAnnotation:c,onRefresh:h,interactive3d:m}){const{t:g}=pt(),p=o.useRef(null),f=o.useRef(null),k=o.useRef(null),[y,N]=o.useState(null),[I,_]=o.useState(!1);o.useEffect(()=>(k.current?.abort(),N(null),_(!1),()=>k.current?.abort()),[t,s]);const B=o.useMemo(()=>y?yp(n,s,y,y.inspection):null,[n,y,s]),E=L=>{const A=p.current,U=f.current;if(!A||!U||!U.naturalWidth||!U.naturalHeight)return;const F=A.getBoundingClientRect(),a=U.getBoundingClientRect(),w=Math.min(a.width/U.naturalWidth,a.height/U.naturalHeight),O=U.naturalWidth*w,j=U.naturalHeight*w,Y=a.left+(a.width-O)/2,ne=a.top+(a.height-j)/2,ae=L.clientX-Y,fe=L.clientY-ne;if(ae<0||fe<0||ae>O||fe>j)return;const G={xPercent:Math.max(0,Math.min(100,ae/O*100)),yPercent:Math.max(0,Math.min(100,fe/j*100)),stageXPercent:(L.clientX-F.left)/F.width*100,stageYPercent:(L.clientY-F.top)/F.height*100,inspecting:l&&s!=="pcb-3d"};if(N(G),k.current?.abort(),!G.inspecting)return;const J=new AbortController;k.current=J,dh(n,s,G.xPercent,G.yPercent,J.signal).then(M=>N(D=>D===G?{...D,inspection:M,inspecting:!1}:D)).catch(()=>{J.signal.aborted||N(M=>M===G?{...M,inspection:{available:!1},inspecting:!1}:M)})},$=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:$.map(L=>e.jsx("button",{type:"button",onClick:()=>d(L),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${L===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ua(L)},L))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx(xi,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:p,role:"button",tabIndex:0,onClick:E,onKeyDown:L=>{L.key!=="Enter"&&L.key!==" "||(L.preventDefault(),N({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:t,alt:`${n} ${Ua(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(Za,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?Fm(f.current,y):Promise.resolve(null)}),N(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Xd,{blobUrl:t,filePath:n,viewLabel:Ua(s),onInsertAnnotation:c})})]})}function kp(t){const n=[];let s=[],l="",d=!1;for(let c=0;c<t.length;c+=1){const h=t[c];d?h==='"'&&t[c+1]==='"'?(l+='"',c+=1):h==='"'?d=!1:l+=h:h==='"'?d=!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 Sp(t,n,s,l,d){const c=n[d]||`第${d+1}列`,h=s[d]??"",m=n.map((g,p)=>`${g||`第${p+1}列`}=${s[p]??""}`).join(";");return`"表格标注: ${t} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${m}"`}function jp({content:t,filePath:n,onInsertAnnotation:s}){const{t:l}=pt(),d=o.useMemo(()=>kp(t),[t]),c=d[0]??[],h=d.slice(1),m=o.useRef(null),[g,p]=o.useState(null),f=g?h[g.row]:null,k=g&&f?Sp(n,c,f,g.row+1,g.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:m,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((y,N)=>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:N+1})},`${y}:${N}`))]})}),e.jsx("tbody",{children:h.map((y,N)=>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:N+1}),c.map((I,_)=>{const B=g?.row===N&&g.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 $=m.current?.getBoundingClientRect(),L=E.currentTarget.getBoundingClientRect();if(!$?.width||!$.height)return;const A=E.clientX||L.left+L.width/2,U=E.clientY||L.top+L.height/2;p({row:N,column:_,xPercent:(A-$.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:${N}:${_}`)})]},`row:${N}`))})]})}),g&&k&&e.jsx(Za,{anchor:{xPercent:g.xPercent,yPercent:g.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(k,`csv:${n}:${g.row+1}:${g.column+1}`),p(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:g&&f?l("rightSidebar.csvSelectedCell",{row:g.row+1,column:c[g.column]||g.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function Hn(t,n){let s=t;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function Rp(t,n){const s=JSON.parse(t),l=Hn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Hn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Hn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Hn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const d=Hn(s,["net_settings","classes"]),c=Array.isArray(d)?d.find(m=>m&&typeof m=="object"&&m.name==="Default"):void 0,h=Hn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(d)?d.length:0)},{label:"默认间距",value:c?.clearance!==void 0?`${c.clearance} mm`:"未设置"},{label:"默认线宽",value:c?.track_width!==void 0?`${c.track_width} mm`:"未设置"},{label:"默认过孔",value:c?.via_diameter!==void 0?`${c.via_diameter} / ${c.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function Cp(t,n){return`"KiCad项目标注: ${t} / 项: ${n.label} / 值: ${n.value}"`}function Np({content:t,filePath:n,localState:s,onInsertAnnotation:l}){const{t:d}=pt(),c=o.useRef(null),[h,m]=o.useState(null),g=o.useMemo(()=>{try{return{items:Rp(t,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[t,s]),p=h===null?null:g.items[h.index];return g.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:t}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:d("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:g.items.map((f,k)=>e.jsxs("button",{type:"button",onClick:y=>{const N=c.current?.getBoundingClientRect(),I=y.currentTarget.getBoundingClientRect();if(!N?.width||!N.height)return;const _=y.clientX||I.left+I.width/2,B=y.clientY||I.top+I.height/2;m({index:k,xPercent:(_-N.left)/N.width*100,yPercent:(B-N.top)/N.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===k?"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:d("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:t})]})]}),p&&h&&e.jsx(Za,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:d("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(Cp(n,p),`kicad-project:${n}:${p.label}`),m(null)},children:d("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:p?`${p.label}: ${p.value}`:d("rightSidebar.kicadProjectPickHint")})})]})}const Mp=`/** ES Module Shims Wasm @version 2.8.4 */
13
+ `;return`${t}${l}${s}`}function fp(t,n){const s=t.trim();return s?n?`${s}\r`:/\s$/.test(t)?t:`${s} `:""}const Ri="termdock:right-sidebar:html-view-mode-by-file:v1";function hp(t){return t==="preview"||t==="source"}function Xd(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(hp)}function Jd(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function ed(t,n){const s=Jd(t,n);return s?tt(Ri,Xd)?.[s]??"source":"source"}function mp(t,n,s){const l=Jd(t,n);if(!l)return;const d=tt(Ri,Xd)??{};xt(Ri,{...d,[l]:s})}function td(t){try{return new URL(t,location.href).pathname.startsWith("/api/")}catch{return!1}}function Xa(t,n){const[s,l]=o.useState(()=>!!navigator.serviceWorker?.controller);return o.useEffect(()=>{if(!td(t)||s)return;const d=navigator.serviceWorker,c=()=>l(!!d?.controller);d?.addEventListener("controllerchange",c),c();const h=window.setTimeout(()=>{d?.controller||n?.()},1e4);return()=>{d?.removeEventListener("controllerchange",c),window.clearTimeout(h)}},[t,s,n]),td(t)&&!s?void 0:t}function Jo(t){const n=Number.isFinite(t)&&t>0?Math.floor(t):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),d=n%60,c=String(l).padStart(2,"0"),h=String(d).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function pp(t,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(t-n.left)/n.width))*s}const gp=350,bp=12,xp=90;function vp({url:t,onLoadError:n}){const s=Xa(t,n),{t:l}=yt(),d=o.useRef(null),c=o.useRef(null),h=o.useRef(null),m=o.useRef(null),g=o.useRef(!1),p=o.useRef(null),f=o.useRef(null),k=o.useRef(0),y=o.useRef(!1),N=o.useRef(!1),I=o.useRef(!1),D=o.useRef(null),B=o.useRef(null),E=o.useRef(!1),$=o.useRef(1),L=o.useRef(!1),[A,U]=o.useState(0),[F,a]=o.useState(0),[w,O]=o.useState(!1),[j,X]=o.useState(!1),[ne,se]=o.useState(null),[fe,G]=o.useState(!1),[J,M]=o.useState(0),[_,K]=o.useState(!1),[re,oe]=o.useState({width:0,height:0}),he=o.useCallback(()=>{D.current!==null&&(clearTimeout(D.current),D.current=null)},[]),me=o.useCallback(()=>{if(he(),B.current=null,!E.current)return!1;const W=h.current;return W&&(W.playbackRate=$.current),E.current=!1,G(!1),!0},[he]);o.useEffect(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current),f.current!==null&&clearTimeout(f.current),he();const W=h.current;W&&E.current&&(W.playbackRate=$.current)},[he]),o.useEffect(()=>{const W=c.current;if(!W||typeof ResizeObserver>"u")return;const q=new ResizeObserver(([Se])=>{Se&&oe({width:Se.contentRect.width,height:Se.contentRect.height})});return q.observe(W),()=>q.disconnect()},[]),o.useEffect(()=>{const W=()=>K(document.fullscreenElement===d.current);return document.addEventListener("fullscreenchange",W),()=>document.removeEventListener("fullscreenchange",W)},[]);const je=o.useCallback((W,q=!1)=>{const Se=h.current;if(!Se)return!1;const Re=Number.isFinite(Se.duration)?Se.duration:W,lt=Math.min(Math.max(W,0),Re);if(a(lt),Math.abs(Se.currentTime-lt)<1/120)return!1;const Qe=Se.fastSeek;return q&&typeof Qe=="function"?Qe.call(Se,lt):Se.currentTime=lt,!0},[]),C=o.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null;const W=h.current;if(!W||!y.current||N.current||W.seeking)return;const q=I.current;I.current=!1,N.current=je(k.current,!q)}))},[je]),Z=o.useCallback(W=>{const q=m.current,Se=h.current;if(!q||!Se)return;const Re=q.getBoundingClientRect(),lt=pp(W,Re,Se.duration);k.current=lt,se(lt),I.current=!1,C(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,C()},xp)},[C]),de=o.useCallback(()=>{p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,N.current=!1,je(k.current)},[je]),Ee=o.useCallback(W=>{const q=h.current;if(!(!q||!Number.isFinite(q.duration)||q.duration<=0)){g.current=!q.paused,q.pause(),y.current=!0,X(!0);try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}Z(W.clientX)}},[Z]),Ge=o.useCallback(()=>{y.current=!1,de(),X(!1),se(null);const W=h.current;W&&g.current&&!W.ended&&W.play().catch(()=>{}),g.current=!1},[de]),De=o.useCallback(()=>{const W=h.current;if(W){if(L.current){L.current=!1;return}W.paused?W.play().catch(()=>{}):W.pause()}},[]),le=o.useCallback(W=>{const q=h.current;!q||q.paused||W.button!==0||(he(),B.current={id:W.pointerId,x:W.clientX,y:W.clientY},D.current=setTimeout(()=>{D.current=null,$.current=q.playbackRate,q.playbackRate=2,E.current=!0,G(!0)},gp))},[he]),ae=o.useCallback(W=>{const q=B.current;!q||q.id!==W.pointerId||E.current||Math.hypot(W.clientX-q.x,W.clientY-q.y)>bp&&(he(),B.current=null)},[he]),S=o.useCallback(()=>{me()&&(L.current=!0)},[me]);o.useEffect(()=>(window.addEventListener("pointerup",S),window.addEventListener("pointercancel",S),window.addEventListener("blur",S),()=>{window.removeEventListener("pointerup",S),window.removeEventListener("pointercancel",S),window.removeEventListener("blur",S)}),[S]);const V=o.useCallback(async()=>{const W=d.current,q=h.current;if(!(!W||!q))try{document.fullscreenElement===W?await document.exitFullscreen():W.requestFullscreen?await W.requestFullscreen():q.webkitEnterFullscreen?.()}catch{q.webkitEnterFullscreen?.()}},[]),ye=o.useCallback(()=>M(W=>(W+90)%360),[]),be=o.useCallback(W=>{const q=h.current;if(!q||!Number.isFinite(q.duration))return;const Se=W.shiftKey?10:5;let Re=null;W.key==="ArrowLeft"?Re=q.currentTime-Se:W.key==="ArrowRight"?Re=q.currentTime+Se:W.key==="Home"?Re=0:W.key==="End"&&(Re=q.duration),Re!==null&&(W.preventDefault(),je(Re))},[je]),Oe=j&&ne!==null?ne:F,ce=A>0?Math.min(1,Math.max(0,Oe/A)):0,Le=(J===90||J===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:d,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":J,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...Le,transform:`translate(-50%, -50%) rotate(${J}deg)`},src:s,preload:"auto",playsInline:!0,onClick:De,onPointerDown:le,onPointerMove:ae,onPointerUp:S,onPointerCancel:S,onContextMenu:W=>{E.current&&W.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:W=>a(W.currentTarget.currentTime),onSeeked:W=>{const q=W.currentTarget;if(a(q.currentTime),N.current=!1,!y.current)return;const Se=q.requestVideoFrameCallback;typeof Se=="function"?Se.call(q,()=>{y.current&&C()}):requestAnimationFrame(()=>{y.current&&C()})},onLoadedMetadata:W=>U(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onDurationChange:W=>U(Number.isFinite(W.currentTarget.duration)?W.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),fe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed")}),j&&ne!==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:`${ce*100}%`},"data-testid":"file-preview-video-scrub-time",children:Jo(ne)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${lm}`,[cm]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:De,"aria-label":l(w?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(w?"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:w?e.jsx(Kh,{size:14}):e.jsx(Vh,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(A),"aria-valuenow":Math.floor(Oe),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:Ee,onPointerMove:W=>{j&&Z(W.clientX)},onPointerUp:Ge,onPointerCancel:Ge,onKeyDown:be,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:`${ce*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:`${ce*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Jo(Oe)," / ",Jo(A)]}),e.jsx("button",{type:"button",onClick:ye,"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(Lm,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{V()},"aria-label":l(_?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(_?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:_?e.jsx(Nm,{size:14}):e.jsx(Rm,{size:14})})]})})]})}function yp(t){const n=Math.max(0,Math.min(100,t.xPercent)),s=Math.max(0,Math.min(100,t.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function Ja({anchor:t,children:n,disabled:s=!1,onClick:l,title:d}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:d,style:yp(t),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Ha,{size:11}),n]})}function wp(t,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const d=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(d)||d<=0)return null;const c=l.width*d,h=l.height*d,m=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,p=t-m,f=n-g;if(p<0||f<0||p>c||f>h)return null;const k=p/c*100,y=f/h*100;return{x:l.x+l.width*k/100,y:l.y+l.height*y/100,xPercent:k,yPercent:y}}function kp(t,n,s){const l=[`SVG标注: ${t}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function Sp(t){const n=new DOMParser().parseFromString(t,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const d of Array.from(l.attributes)){const c=d.name.toLowerCase(),h=d.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(d.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function jp(t,n,s){let l=null;for(const d of Array.from(t.querySelectorAll("text"))){const c=(d.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(d.getAttribute("x")),m=Number(d.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const g=Math.hypot(h-n,m-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function Qd({blobUrl:t,filePath:n,viewLabel:s,onInsertAnnotation:l}){const d=o.useRef(null),c=o.useRef(null),[h,m]=o.useState(null),[g,p]=o.useState(null),[f,k]=o.useState(1),[y,N]=o.useState(!1),[I,D]=o.useState(null),B=o.useRef(new Map),E=o.useRef(null),$=o.useRef(!1),L=o.useRef(null),A=o.useRef(f);A.current=f,o.useEffect(()=>{const M=new AbortController;return m(null),p(null),D(null),k(1),fetch(t,{signal:M.signal}).then(_=>_.text()).then(_=>m(Sp(_))).catch(_=>{M.signal.aborted||p(_ instanceof Error?_.message:"SVG preview failed")}),()=>M.abort()},[t]),o.useEffect(()=>{if(!y)return;const M=_=>{_.key==="Escape"&&N(!1)};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[y]),o.useLayoutEffect(()=>{const M=c.current,_=M?.querySelector("[data-svg-document] > svg");if(!M||!_)return;let K;try{K=_.getBBox()}catch{return}if(!K.width||!K.height)return;const re=Math.max(2,Math.min(K.width,K.height)*.025);_.setAttribute("viewBox",`${K.x-re} ${K.y-re} ${K.width+2*re} ${K.height+2*re}`),_.style.width=`${f*100}%`,_.style.height=`${f*100}%`,_.style.minWidth=`${f*100}%`,_.style.minHeight=`${f*100}%`,_.style.display="block"},[h,f]);const U=o.useMemo(()=>I?kp(n,s,I):null,[n,I,s]),F=M=>{if($.current){$.current=!1;return}const _=c.current,K=_?.querySelector("[data-svg-document] > svg"),re=d.current;if(!_||!K||!re)return;const oe=K.viewBox.baseVal,he=wp(M.clientX,M.clientY,K.getBoundingClientRect(),oe);if(!he)return;const me=re.getBoundingClientRect();D({...he,nearestText:jp(K,he.x,he.y),stageX:M.clientX-me.left,stageY:M.clientY-me.top,stageXPercent:(M.clientX-me.left)/me.width*100,stageYPercent:(M.clientY-me.top)/me.height*100})},a=M=>Math.max(1,Math.min(12,M)),w=(M,_)=>{const K=a(_),re=M.querySelector("[data-svg-document] > svg");if(!re)return K;const oe=`${K*100}%`;return re.style.width=oe,re.style.height=oe,re.style.minWidth=oe,re.style.minHeight=oe,A.current=K,K},O=(M,_,K,re)=>{const oe=A.current,he=M.getBoundingClientRect(),me=K-he.left,je=re-he.top,C=(M.scrollLeft+me)/oe,Z=(M.scrollTop+je)/oe,de=w(M,_);return M.scrollLeft=C*de-me,M.scrollTop=Z*de-je,de},j=()=>{const M=Array.from(B.current.values());return M.length>=2?Math.hypot(M[0].x-M[1].x,M[0].y-M[1].y):0},X=M=>{if(M.pointerType==="mouse"&&M.button!==0)return;const _=c.current;_&&(B.current.set(M.pointerId,{x:M.clientX,y:M.clientY}),_.setPointerCapture?.(M.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:M.clientX,startY:M.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startDistance:j(),startZoom:A.current,moved:!1},$.current=!0):A.current>1&&(E.current={kind:"pan",startX:M.clientX,startY:M.clientY,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:A.current,moved:!1}))},ne=M=>{if(!B.current.has(M.pointerId))return;B.current.set(M.pointerId,{x:M.clientX,y:M.clientY});const _=c.current,K=E.current;if(!(!_||!K)){if(B.current.size>=2&&K.kind==="pinch"){const re=j();if(!K.startDistance||!re)return;const oe=a(K.startZoom*re/K.startDistance);if(Math.abs(oe-A.current)<.01)return;const he=Array.from(B.current.values()),me=(he[0].x+he[1].x)/2,je=(he[0].y+he[1].y)/2;K.moved=!0,$.current=!0,O(_,oe,me,je),M.preventDefault();return}if(K.kind==="pan"&&B.current.size===1){const re=M.clientX-K.startX,oe=M.clientY-K.startY;if(!K.moved&&Math.hypot(re,oe)<6)return;K.moved=!0,$.current=!0,_.scrollLeft=K.startScrollLeft-re,_.scrollTop=K.startScrollTop-oe,M.preventDefault()}}},se=M=>{const _=c.current,K=E.current,re=B.current.size===1&&!K?.moved;B.current.delete(M.pointerId);try{_?.releasePointerCapture?.(M.pointerId)}catch{}if(B.current.size===1&&K?.kind==="pinch"){const me=Array.from(B.current.values())[0];E.current=_?{kind:"pan",startX:me.x,startY:me.y,startScrollLeft:_.scrollLeft,startScrollTop:_.scrollTop,startZoom:A.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,K?.kind==="pinch"&&k(A.current),!re||$.current))return;const oe=Date.now(),he=L.current;he&&oe-he.time<350&&Math.hypot(M.clientX-he.x,M.clientY-he.y)<24?(L.current=null,$.current=!0,k(me=>me>1?1:2.5)):L.current={time:oe,x:M.clientX,y:M.clientY}},fe=M=>{if(!M.ctrlKey&&!M.metaKey)return;const _=c.current;if(!_)return;M.preventDefault();const K=O(_,A.current*Math.exp(-M.deltaY*.01),M.clientX,M.clientY);k(K)},G=()=>{k(1),A.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},J=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:d,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:F,onDoubleClick:M=>{M.preventDefault(),k(_=>_>1?1:2.5)},onPointerDown:X,onPointerMove:ne,onPointerUp:se,onPointerCancel:se,onWheel:fe,onScroll:()=>D(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),I&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:I.stageX,top:I.stageY}}),I&&U&&e.jsx(Ja,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.y.toFixed(2)}`),D(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:M=>{M.stopPropagation(),G()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(Pm,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:M=>{M.stopPropagation(),N(_=>!_)},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(Od,{size:14}):e.jsx(Ud,{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?Gr.createPortal(J,document.body):J}function Ba(t){switch(t){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Rp(t,n,s,l){const d=[`电子标注: ${t}`,`视图: ${Ba(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(d.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&d.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");d.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${d.join(" / ")}"`}function Cp({blobUrl:t,filePath:n,view:s,board:l,onViewChange:d,onInsertAnnotation:c,onRefresh:h,interactive3d:m}){const{t:g}=yt(),p=o.useRef(null),f=o.useRef(null),k=o.useRef(null),[y,N]=o.useState(null),[I,D]=o.useState(!1);o.useEffect(()=>(k.current?.abort(),N(null),D(!1),()=>k.current?.abort()),[t,s]);const B=o.useMemo(()=>y?Rp(n,s,y,y.inspection):null,[n,y,s]),E=L=>{const A=p.current,U=f.current;if(!A||!U||!U.naturalWidth||!U.naturalHeight)return;const F=A.getBoundingClientRect(),a=U.getBoundingClientRect(),w=Math.min(a.width/U.naturalWidth,a.height/U.naturalHeight),O=U.naturalWidth*w,j=U.naturalHeight*w,X=a.left+(a.width-O)/2,ne=a.top+(a.height-j)/2,se=L.clientX-X,fe=L.clientY-ne;if(se<0||fe<0||se>O||fe>j)return;const G={xPercent:Math.max(0,Math.min(100,se/O*100)),yPercent:Math.max(0,Math.min(100,fe/j*100)),stageXPercent:(L.clientX-F.left)/F.width*100,stageYPercent:(L.clientY-F.top)/F.height*100,inspecting:l&&s!=="pcb-3d"};if(N(G),k.current?.abort(),!G.inspecting)return;const J=new AbortController;k.current=J,fh(n,s,G.xPercent,G.yPercent,J.signal).then(M=>N(_=>_===G?{..._,inspection:M,inspecting:!1}:_)).catch(()=>{J.signal.aborted||N(M=>M===G?{...M,inspection:{available:!1},inspecting:!1}:M)})},$=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:$.map(L=>e.jsx("button",{type:"button",onClick:()=>d(L),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${L===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Ba(L)},L))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx(xi,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:p,role:"button",tabIndex:0,onClick:E,onKeyDown:L=>{L.key!=="Enter"&&L.key!==" "||(L.preventDefault(),N({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:t,alt:`${n} ${Ba(s)}`,onLoad:()=>D(!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(Ja,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?Um(f.current,y):Promise.resolve(null)}),N(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Qd,{blobUrl:t,filePath:n,viewLabel:Ba(s),onInsertAnnotation:c})})]})}function Np(t){const n=[];let s=[],l="",d=!1;for(let c=0;c<t.length;c+=1){const h=t[c];d?h==='"'&&t[c+1]==='"'?(l+='"',c+=1):h==='"'?d=!1:l+=h:h==='"'?d=!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 Mp(t,n,s,l,d){const c=n[d]||`第${d+1}列`,h=s[d]??"",m=n.map((g,p)=>`${g||`第${p+1}列`}=${s[p]??""}`).join(";");return`"表格标注: ${t} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${m}"`}function $p({content:t,filePath:n,onInsertAnnotation:s}){const{t:l}=yt(),d=o.useMemo(()=>Np(t),[t]),c=d[0]??[],h=d.slice(1),m=o.useRef(null),[g,p]=o.useState(null),f=g?h[g.row]:null,k=g&&f?Mp(n,c,f,g.row+1,g.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:m,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((y,N)=>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:N+1})},`${y}:${N}`))]})}),e.jsx("tbody",{children:h.map((y,N)=>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:N+1}),c.map((I,D)=>{const B=g?.row===N&&g.column===D;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 $=m.current?.getBoundingClientRect(),L=E.currentTarget.getBoundingClientRect();if(!$?.width||!$.height)return;const A=E.clientX||L.left+L.width/2,U=E.clientY||L.top+L.height/2;p({row:N,column:D,xPercent:(A-$.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[D]||" "})},`cell:${N}:${D}`)})]},`row:${N}`))})]})}),g&&k&&e.jsx(Ja,{anchor:{xPercent:g.xPercent,yPercent:g.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(k,`csv:${n}:${g.row+1}:${g.column+1}`),p(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:g&&f?l("rightSidebar.csvSelectedCell",{row:g.row+1,column:c[g.column]||g.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function Wn(t,n){let s=t;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function Ep(t,n){const s=JSON.parse(t),l=Wn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Wn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Wn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Wn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const d=Wn(s,["net_settings","classes"]),c=Array.isArray(d)?d.find(m=>m&&typeof m=="object"&&m.name==="Default"):void 0,h=Wn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(d)?d.length:0)},{label:"默认间距",value:c?.clearance!==void 0?`${c.clearance} mm`:"未设置"},{label:"默认线宽",value:c?.track_width!==void 0?`${c.track_width} mm`:"未设置"},{label:"默认过孔",value:c?.via_diameter!==void 0?`${c.via_diameter} / ${c.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function Lp(t,n){return`"KiCad项目标注: ${t} / 项: ${n.label} / 值: ${n.value}"`}function Ap({content:t,filePath:n,localState:s,onInsertAnnotation:l}){const{t:d}=yt(),c=o.useRef(null),[h,m]=o.useState(null),g=o.useMemo(()=>{try{return{items:Ep(t,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[t,s]),p=h===null?null:g.items[h.index];return g.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:t}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:d("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:g.items.map((f,k)=>e.jsxs("button",{type:"button",onClick:y=>{const N=c.current?.getBoundingClientRect(),I=y.currentTarget.getBoundingClientRect();if(!N?.width||!N.height)return;const D=y.clientX||I.left+I.width/2,B=y.clientY||I.top+I.height/2;m({index:k,xPercent:(D-N.left)/N.width*100,yPercent:(B-N.top)/N.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===k?"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:d("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:t})]})]}),p&&h&&e.jsx(Ja,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:d("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(Lp(n,p),`kicad-project:${n}:${p.label}`),m(null)},children:d("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:p?`${p.label}: ${p.value}`:d("rightSidebar.kicadProjectPickHint")})})]})}const Pp=`/** ES Module Shims Wasm @version 2.8.4 */
15
15
  (function () {
16
16
 
17
17
  const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
@@ -1497,7 +1497,7 @@ import{a0 as yt,Y as ih,aV as e,ca as pt,ch as vt,b9 as tt,a as Ns,ay as lh,C as
1497
1497
  };
1498
1498
 
1499
1499
  })();
1500
- `,$p=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1500
+ `,Tp=`/* 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
- `,Aa="/api/terminal/fs/preview/",Ep=8*1024*1024,Lp=32*1024*1024,Ap=128,Pp="data:,";function Nt(t){throw new Error(t)}function Tp(t){return JSON.stringify(t).replace(/</g,"\\u003c")}async function ed(t,n,s){let l="",d=0;for(const c of t.matchAll(n))l+=t.slice(d,c.index)+await s(c),d=c.index+c[0].length;return l+t.slice(d)}async function Jd(t,n){const s=n.origin??location.origin,l=new URL(t,s);(l.origin!==s||!ps(l.pathname)?.startsWith(Aa))&&Nt("预览地址不是有效的本地文件入口");const d=crypto.randomUUID(),c=`https://termdock-preview.invalid/${d}/`,h=[],m=G=>{!h.includes(G)&&h.length<20&&h.push(G)},g=new Set,p=[],f=new Set,k=new Map,y=new Map;let N=0,I=!1;const _=new Set,B=()=>{I=!0;for(const G of[..._])G();g.clear(),p.length=0};async function E(G){G.ok||Nt(`预览资源读取失败(${G.status})`);const J=G.body?.getReader(),M=[];let D=0;try{if(J)for(;;){const oe=await J.read();if(oe.done)break;D+=oe.value.byteLength,N+=oe.value.byteLength,(D>Ep||N>Lp)&&Nt("预览资源超出大小限制"),M.push(oe.value)}}catch(oe){throw await J?.cancel().catch(()=>{}),oe}finally{J?.releaseLock()}const K=new Uint8Array(D);let re=0;for(const oe of M)K.set(oe,re),re+=oe.length;return{bytes:K,type:G.headers.get("content-type")??"application/octet-stream",status:G.status}}let $=l,L;for(let G=0;G<4;G++){const J=await n.fetch($.pathname+$.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(J.status)){L=J;break}const M=J.headers.get("location");await J.body?.cancel(),M||Nt("预览重定向缺少目标");const D=new URL(M,$);(D.origin!==s||!ps(D.pathname)?.startsWith(Aa))&&Nt("预览重定向越出文件范围"),$=D}L||Nt("预览重定向次数过多");const A=ps($.pathname),U=A.slice(Aa.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||Nt("服务未提供有效的预览资源授权");const F=ps(l.pathname).slice(Aa.length).split("/");/^[a-f0-9]{32}$/.test(F[0])&&F.shift(),F.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&Nt("预览重定向改变了文件范围");const a=A.endsWith("/")?A:A.slice(0,A.lastIndexOf("/")+1),w=new URL($.pathname.endsWith("/")?$.pathname:$.pathname.slice(0,$.pathname.lastIndexOf("/")+1),s);function O(G,J){const M=new URL(G,J);return M.origin!==s?null:(ps(M.pathname)?.startsWith(a)||Nt("已阻止预览访问目录之外的资源"),M)}function j(G){const J=new URL(G,c);(J.origin!==new URL(c).origin||!J.pathname.startsWith(new URL(c).pathname))&&Nt("已阻止预览访问服务接口或目录之外的资源");const M=J.pathname.slice(new URL(c).pathname.length)+J.search;return O(M,w)??Nt("预览资源无效")}function Y(G){const J=G.pathname+G.search,M=k.get(J);if(M)return M;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(k.size>=Ap)return Promise.reject(new Error("预览资源数量超出限制"));const D=n.fetch(J,{signal:n.signal,redirect:"manual"}).then(E);return k.set(J,D),D}function ne(G,J){I&&Nt("预览已关闭");const M=`termdock-resource-${d}-${p.length}`;return p.push({token:M,data:G,type:J}),g.add(M),M}async function ae(G,J,M,D=new Set){if(!G||G.startsWith("#")||/^data:(?:image|font)\//i.test(G)&&M==="resource")return G;try{const K=O(G,J);if(!K){const Re=new URL(G,J);return(Re.protocol!=="https:"||Re.username||Re.password||Re.origin===new URL(c).origin)&&Nt("已阻止不安全的外部资源"),f.add(Re.origin),Re.href}const re=`${M}:${K.href}`;(D.has(re)||D.size>=8)&&Nt("预览资源存在循环或过深引用");const oe=y.get(re);if(oe)return oe;const he=new Set(D);he.add(re);const me=(async()=>{const Re=await Y(K);return M==="css"?ne(await fe(new TextDecoder().decode(Re.bytes),K,he),"text/css"):M==="script"?ne(Re.bytes,"text/javascript"):ne(Re.bytes,Re.type)})();return y.set(re,me),await me}catch(K){return m(K instanceof Error?K.message:"部分预览资源未能加载"),Pp}}async function fe(G,J,M){return G=await ed(G,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async D=>`@import url("${await ae(D[1],J,"css",M)}")${D[2]};`),ed(G,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async D=>{const K=(D[1]??D[2]??D[3]).trim();return g.has(K)?D[0]:`url("${await ae(K,J,"resource",M)}")`})}try{const G=await E(L),J=ne(Mp,"text/javascript"),M=new DOMParser().parseFromString(new TextDecoder().decode(G.bytes),"text/html");M.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(C=>C.remove());for(const C of M.querySelectorAll("*")){if(C.removeAttribute("ping"),C.removeAttribute("srcdoc"),C.hasAttribute("style")&&C.setAttribute("style",await fe(C.getAttribute("style"),$,new Set)),C.tagName==="STYLE"&&(C.textContent=await fe(C.textContent??"",$,new Set)),C.tagName==="A"||C.tagName==="AREA"){const Z=C.getAttribute("href");try{if(Z&&!Z.startsWith("#")){const de=O(Z,$);if(de)C.setAttribute("href",new URL(de.pathname.slice(w.pathname.length)+de.search+de.hash,c).href);else{const Le=new URL(Z,$);if(Le.protocol!=="https:"){C.removeAttribute("href");continue}f.add(Le.origin),C.setAttribute("href",Le.href)}}}catch(de){C.removeAttribute("href"),m(de instanceof Error?de.message:"预览链接无法加载")}}for(const Z of["data","manifest"])C.removeAttribute(Z);if(C.tagName==="SCRIPT"&&C.getAttribute("type")==="module"){C.setAttribute("type","module-shim");const Z=C.getAttribute("src");if(Z){const de=O(Z,$);if(de)C.setAttribute("src",new URL(de.pathname.slice(w.pathname.length)+de.search,c).href);else{const Le=new URL(Z,$);if(Le.protocol!=="https:"){C.remove();continue}f.add(Le.origin),C.setAttribute("src",Le.href)}}continue}if(C.tagName==="SCRIPT"&&C.getAttribute("type")==="importmap"){C.setAttribute("type","importmap-shim");continue}if(C.tagName==="LINK"){const Z=(C.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Z)){C.remove();continue}const de=C.getAttribute("href");de&&C.setAttribute("href",await ae(de,$,Z==="stylesheet"?"css":"resource"))}if(C.hasAttribute("src")&&C.setAttribute("src",await ae(C.getAttribute("src"),$,C.tagName==="SCRIPT"?"script":"resource")),C.hasAttribute("poster")&&C.setAttribute("poster",await ae(C.getAttribute("poster"),$,"resource")),C.hasAttribute("srcset")){const Z=C.getAttribute("srcset");/data:/i.test(Z)?(C.removeAttribute("srcset"),m("混合内嵌图片候选暂不支持安全预览")):C.setAttribute("srcset",(await Promise.all(Z.split(",").map(async de=>{const[Le,...We]=de.trim().split(/\s+/);return`${await ae(Le,$,"resource")} ${We.join(" ")}`}))).join(", "))}C.setAttribute("referrerpolicy","no-referrer"),C.removeAttribute("integrity"),C.removeAttribute("crossorigin")}const D=[...f].join(" "),K=M.createElement("meta");K.httpEquiv="Content-Security-Policy",K.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${D}; style-src 'unsafe-inline' blob: ${D}; img-src blob: data: ${D}; font-src blob: data: ${D}; media-src blob: data: ${D}; connect-src blob: ${D} ${[...f].map(C=>C.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=M.createElement("base");re.href=c;const oe=M.createElement("meta");oe.name="referrer",oe.content="no-referrer";const he=M.createElement("script");he.textContent=$p+`
1636
- installPreviewRuntime(`+[d,c,[...f],J].map(Tp).join(",")+");";const me=M.createElement("script");me.src=J,M.head.prepend(K,oe,re,he,me);const Re=`<!doctype html>
1637
- `+M.documentElement.outerHTML;return{html:Re,shellUrl:`/preview-shell.html#${d}`,errors:h,attach(C,Z){const de=new Set,Le=_e=>{if(_e.source!==C.contentWindow||_e.data?.capability!==d)return;if(_e.data.type==="preview-ready"){C.contentWindow?.postMessage({type:"preview-init",capability:d,html:Re,resources:p},"*");return}if(_e.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(_e.data.type==="preview-navigate"){(async()=>{const se=j(String(_e.data.url)),S=await Jd(se.pathname+se.search,n);if(I){S.dispose();return}const V=S.attach(C,Z);_.add(()=>{V(),S.dispose()}),C.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(se=>Z(se instanceof Error?se.message:"无法打开预览页面"));return}if(_e.data.type==="preview-external"){try{const se=new URL(String(_e.data.url));se.protocol==="https:"&&f.has(se.origin)&&window.open(se.href,"_blank","noopener,noreferrer")}catch{}return}if(_e.data.type!=="preview-fetch"||_e.ports.length!==1)return;const le=_e.ports[0];if(de.size>=8||!["GET","HEAD"].includes(_e.data.method)){le.postMessage({error:"预览仅允许读取已授权目录资源"}),le.close();return}de.add(le),(async()=>{const se=j(String(_e.data.url)),S=await Y(se);if(!de.has(le)||I)return;const V=_e.data.method==="HEAD"?new Uint8Array:S.bytes.slice();le.postMessage({status:S.status,headers:{"content-type":S.type},data:V.buffer},[V.buffer])})().catch(()=>{le.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{de.delete(le),le.close()})};window.addEventListener("message",Le);const We=()=>{window.removeEventListener("message",Le);for(const _e of de)_e.close();de.clear(),_.delete(We)};return _.add(We),We},dispose:B}}catch(G){throw B(),G}}const Ip=o.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:d},c){const h=o.useRef(null),[m,g]=o.useState(null),[p,f]=o.useState(),[k,y]=o.useState("");o.useEffect(()=>{const A=new AbortController;let U;return f(void 0),y(""),(async()=>{const F=await uh();if(U=await Jd(n,{fetch:(a,w)=>F.fetch(a,w),signal:A.signal}),A.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(F=>{A.signal.aborted||y(F instanceof Error?F.message:"安全预览加载失败")}),()=>{A.abort(),U?.dispose()}},[n]),o.useEffect(()=>{if(!(!p||!m))return p.attach(m,y)},[p,m]);const[N,I]=o.useState(!1),[_,B]=o.useState(!1),E=N||_;o.useEffect(()=>{d?.(E)},[E,d]),o.useEffect(()=>{const A=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",A),()=>document.removeEventListener("fullscreenchange",A)},[]),o.useEffect(()=>{if(!_)return;const A=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[_]);const $=o.useCallback(async()=>{const A=h.current;if(A){if(_){B(!1);return}if(document.fullscreenElement===A){await document.exitFullscreen();return}if(A.requestFullscreen&&document.fullscreenEnabled!==!1)try{await A.requestFullscreen();return}catch{}B(!0)}},[_]);o.useImperativeHandle(c,()=>({toggleFullscreen:$}),[$]);const L=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(Dd,{size:15})})]}),k&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:k}),!p&&!k&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:p?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return _?Gr.createPortal(L,document.body):L}),Qd="termdock-file-search-match",Ci="termdock-file-search-current";function Fp(t){const n=t.metaKey||t.ctrlKey,s=t.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||t.key==="F3"?t.shiftKey?"previous":"next":t.key==="Escape"?"close":null}function _p(t){return t.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function Dp(t,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let d="",c=null;const h=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const k=_p(f);if(!k)continue;c&&c!==k&&(d+=`
1638
- `);const y=d.length;d+=f.data,l.push({node:f,start:y,end:d.length,group:k}),c=k}const m=d.toLocaleLowerCase(),g=[];let p=0;for(;p<=m.length-s.length;){const f=m.indexOf(s,p);if(f<0)break;const k=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),N=l.find(I=>I.start<k&&I.end>=k);if(y&&N&&y.group===N.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(N.node,k-N.start),g.push(I)}p=f+Math.max(s.length,1)}return g}function Zd(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Pa(){const t=Zd();t?.delete(Qd),t?.delete(Ci)}function td(t,n){const s=Zd();if(!s||typeof Highlight>"u")return;s.set(Qd,new Highlight(...t));const l=t[n];l?s.set(Ci,new Highlight(l)):s.delete(Ci)}function rd(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Bp(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Op(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function Up(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function eu(t,n,s){return n?t:Gr.createPortal(t,s)}const Ui="termdock:right-sidebar:file-tree-scroll:v1",Hi="termdock:right-sidebar:file-preview-reading-state:v1",ws="termdock:right-sidebar:file-tree-width:v1",tu="termdock:right-sidebar:markdown-view-mode:v1",ru="termdock:right-sidebar:diff-change-list-mode:v1",nu="termdock:right-sidebar:diff-wrap:v1",su="termdock:diff-viewer:view-type:v1",au="termdock:right-sidebar:file-search-mode:v1",Zo="termdock:right-sidebar:collapsed-git-repo-groups:v1",nd="termdock:right-sidebar:collapsed-diff-directories:v1",ei="termdock:right-sidebar:branch-audit-module-open:v1",ou="termdock:right-sidebar:branch-audit-module:v1",Hp=150,iu="termdock:right-sidebar:active-git-repo:v1",sd="termdock:right-sidebar:context-draft-enabled:v1",ad="termdock:right-sidebar:context-draft-collapsed:v1",od="termdock:right-sidebar:context-draft-auto-collapse:v1",ti="termdock:right-sidebar:context-draft-text:v1",zp=300,Wp=20,Gp=120,qp=250,Kp=250,Vp=120,Yp=700,ri=600;function zn(t){return!!(t&&te.getState().nestedGitScanRoots[t])}const id=[2e3,5e3,15e3,3e4],Xp=320,Jp=500,Qp=20,Zp=12e3,Ni=300,ld=240,eg=560,lu="border-r px-2 py-1.5 sm:px-3 sm:py-2",Ga="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",cu=`${lu} border-b border-border/15 font-semibold last:border-r-0`,du=`${lu} border-border/10 align-top text-muted-foreground last:border-r-0`,zi="termdock-file-preview-horizontal-scroll",cd=o.lazy(()=>$s(()=>import("./ModelPreview-AlBS7WBE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),uu=`${zi} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function fu(t,n,s){return t&&!n?"unified":s}const tg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function rg(t){return t==="preview"||t==="source"}function ng(t){return t==="list"||t==="tree"||t==="ai"}function dd(){return tt(tu,rg)??"preview"}function sg(){return tt(ru,ng)??"tree"}function ks(t){return typeof t=="boolean"}function ag(t){return typeof t=="string"}function og(){return tt(nu,ks)??!0}function ig(t){return t==="unified"||t==="split"}function lg(){return tt(su,ig)??"unified"}function cg(t){return t==="name"||t==="content"||t==="regex"}function dg(){return tt(au,cg)??"name"}function hu(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:mt(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function ug(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function mu(){return tt(iu,ug)??{}}function ud(t){if(!t)return;const n=mu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function ni(t,n){t&&vt(iu,{...mu(),[t]:n})}function fg(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function Mi(t){return!t.activeGitRepoRoot&&(t.groupCount>1||t.label!==t.rootName)}function pu(...t){const n=new Set;for(const s of t)for(const l of s)n.add(l.root);return n}function $i(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function fd(t){const n=tt(t,$i);return n?new Set(n):new Set}function si(t,n){vt(t,[...n])}function hg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function mg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||$i(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(hg))&&(n.commits===void 0||$i(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 pg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&mg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function gg(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(pg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function hd(){return tt(ou,gg)??{}}function md(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function pd(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function gu(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||pd(s)===pd(l)}function gd(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!gu(l,n))??""}function Ei(t,n){const s=Math.max(ld,n-320),l=Math.min(eg,s);return Math.min(l,Math.max(ld,t))}function bg(t){return typeof t=="number"&&Number.isFinite(t)}function xg(t){return Ei(tt(ws,bg)??Ni,t)}function bu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function xs(t){return tg.has(bu(t))}function xu(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Li(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||xu(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function vu(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const yu=o.createContext(null);function Ha(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function wu(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function ku(t){return t.replace(/\s+#+\s*$/,"").trim()}function Ai(t,n){const l=wu(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",d=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,d+1),d===0?l:`${l}-${d}`}function bd(t){return wu(t)||t.trim()}function qa(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ti(n[2]);return s?{id:Ha(n[1]),definition:{href:s.href,title:s.title}}:null}function vg(t){const n=new Map;for(const s of t){const l=qa(s);l&&n.set(l.id,l.definition)}return n}function Su(t){return t.trim().toLowerCase()}function ju(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Su(n[1]),text:n[2]}:null}function yg(t){const n=new Map;let s=null;for(const l of t){const d=ju(l);if(d){s=d.id,n.set(d.id,{id:d.id,text:d.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function Ru(t){const n=new Set;let s=!1;return t.forEach((l,d)=>{if(ju(l)){n.add(d),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(d);return}l.trim()&&(s=!1)}),n}function wg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const d=t[s].trim();if(d.startsWith("<!--")){if(n[s]="",!d.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Cu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Rs(t){const n=t.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function Wi(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const d=l.indexOf("#"),c=d>=0?l.slice(0,d):l,h=d>=0?l.slice(d+1):"",m=c.split("?",1)[0];if(!m)return null;let g,p=null;try{g=decodeURIComponent(m),p=h?decodeURIComponent(h):null}catch{return null}const f=s?Rs(s):null;let k;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));k=Rs(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;k=Rs(`${Cu(n)}/${g}`)}return f&&k!==f&&!k.startsWith(`${f}/`)?null:{path:k,fragment:p,directory:/\/$/.test(m)}}function Gi(t,n,s,l,d){const c=t.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const m=s&&(c===s||c.startsWith(`${s}/`));h=Rs(s&&!m?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Rs(`${Cu(n)}/${c}`)}return d(h)}function kg(t,n,s){return Gi(t,n,s,Oi,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Sg(t,n,s){return Gi(t,n,s,Ed,Ld)}const Pi=128,jg=360,ai=480;function eo(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function Nu(t,n,s,l,d=0){if(!n||!s)return null;let c,h;return d>0?(c=l>0?Math.min(d,l):d,h=s*c/n):eo(t)?(h=Math.min(Math.max(s,Pi),jg),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>ai&&(c=c*ai/h,h=ai),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Rg(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function Mu(t){const n=Rg(t),s=te(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function Cg({src:t,alt:n,title:s,requestedWidthPx:l}){const d=eo(t),c=Mu(t),h=Qa(c),m=o.useRef(null),[g,p]=o.useState(!1),[f,k]=o.useState(0),[y,N]=o.useState({status:"loading"}),[I,_]=o.useState(null);o.useLayoutEffect(()=>{const $=m.current,L=$?.parentElement?.parentElement??$?.parentElement;if(!L)return;const A=()=>k(L.clientWidth);if(A(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(A);return U.observe(L),()=>U.disconnect()},[]),o.useEffect(()=>{if(g)return;const $=m.current;if(!$||typeof IntersectionObserver>"u"){p(!0);return}const L=new IntersectionObserver(A=>{A.some(U=>U.isIntersecting)&&(p(!0),L.disconnect())},{rootMargin:"400px"});return L.observe($),()=>L.disconnect()},[g]),o.useEffect(()=>{if(!g)return;const $=new AbortController;let L=null;N({status:"loading"});const A=window.setTimeout(()=>{$.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return Uh(c,{signal:$.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=Number(U.headers.get("X-Image-Width"))||0,a=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:F,height:a}}).then(({blob:U,width:F,height:a})=>{$.signal.aborted||(L=URL.createObjectURL(U),F>0&&a>0&&_({width:F,height:a}),N({status:"ready",objectUrl:L}))}).catch(()=>{const U=$.signal.reason;$.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||N({status:"fallback"})}).finally(()=>{window.clearTimeout(A)}),()=>{window.clearTimeout(A),$.abort(),L&&URL.revokeObjectURL(L)}},[g,c]);const B=Nu(t,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:Pi*2,height:Pi});return e.jsx("div",{ref:m,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${d?"":"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 L=$.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&_({width:L.naturalWidth,height:L.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 L=$.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&_({width:L.naturalWidth,height:L.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 Cs(t,n,s,l,d,c){const h=kg(s,d.markdownFilePath,d.rootPath);if(!h)return c?.fallbackText??`![${n}](${s})`;const m=d.images.length;d.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(Cg,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return d.onImageOpen&&c?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:p=>{p.stopPropagation(),d.onImageOpen?.(m)},children:g},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},t)}function oi(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function xd(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Ti(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const $u="",Ng=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Mg(t){return t.replace(Ng,(n,s)=>`${$u}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function vd(t){return t.replace(new RegExp(`${$u}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function $g(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Eu={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 Ta=null;function Lu(){return Ta||(Ta=$s(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw Ta=null,t})),Ta}function Au({html:t}){const{t:n}=pt(),[s,l]=o.useState(null);return o.useEffect(()=>{let d=!1;return l(null),Lu().then(c=>{d||l(c.sanitize(t,Eu))}).catch(()=>{d||l("")}),()=>{d=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function Eg({html:t}){const[n,s]=o.useState(null);return o.useEffect(()=>{let l=!1;return s(null),Lu().then(d=>{l||s(d.sanitize(t,Eu))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function Pu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Ia=null;function Lg(){return Ia||(Ia=Promise.all([$s(()=>import("./katex-DnlPpQZa.js"),[]),$s(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Ia=null,t})),Ia}function Ls({tex:t,display:n=!1}){const[s,l]=o.useState(null),[d,c]=o.useState(!1);if(o.useEffect(()=>{let m=!1;return l(null),c(!1),Lg().then(g=>{m||l(g.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||c(!0)}),()=>{m=!0}},[n,t]),d)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function qi(t){const n=new Map;for(const s of t.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function yd(t){const n=qi(t),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Ag(t){const n=t.indexOf(">"),s=n<0?t:t.slice(0,n+1),l=qi(s),d=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),m=n<0?"":t.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:d,fallbackText:m,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function Pg({url:t,fallbackText:n,widthPx:s,hasControls:l}){const{t:d}=pt(),[c,h]=o.useState(!1),m=Qa(t,()=>h(!0));return m?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||d("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:m,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function Tg(t,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(t)){const h=t.slice(0,t.indexOf(">")+1),m=qi(h).get("href")?.trim()??"",g=t.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:p,alt:f,title:k,widthPx:y}=yd(g);if(!p)return null;const N=Gi(p,s.markdownFilePath,s.rootPath,Oi,$=>$);if(!N)return null;const I=m?Wi(m,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===N)&&m?vu(m):null,E=Cs(n,f??"",p,k,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(t)){const{src:h,alt:m,title:g,widthPx:p}=yd(t);return h?Cs(n,m??"",h,g,s,{fallbackText:t,requestedWidthPx:p}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(t)){const{src:h,fallbackText:m,widthPx:g,controls:p}=Ag(t);if(!h)return null;const f=Sg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(Pg,{url:f,fallbackText:m,widthPx:g,hasControls:p},n):null}if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(Eg,{html:t},n):null;const d=l[1].toLowerCase(),c=rt(l[2],`${n}-${d}`,!0,s);return d==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:c},n):d==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):d==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function rt(t,n,s=!0,l){const d=Mg(t),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let m=0,g;for(;(g=c.exec(d))!==null;){g.index>m&&h.push(vd(d.slice(m,g.index)));const p=g[0],f=`${n}-${g.index}`,k=p.startsWith("<")?Tg(p,f,l):null;if(k)h.push(k);else if(p.startsWith("\\(")&&p.endsWith("\\)"))h.push(e.jsx(Ls,{tex:p.slice(2,-2)},f));else if(p.startsWith("$")&&p.endsWith("$"))h.push(e.jsx(Ls,{tex:p.slice(1,-1)},f));else if(p.startsWith("`")){const y=p.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:$g(p.slice(y,-y))},f))}else if(p.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:rt(p.slice(2,-2),`${f}-del`,s,l)},f));else if(p.startsWith("**")||p.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:rt(p.slice(2,-2),`${f}-strong`,s,l)},f));else if(p.startsWith("*")||p.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:rt(p.slice(1,-1),`${f}-em`,s,l)},f));else if(p.startsWith("![")){const y=p.match(/^!\[([^\]]*)\]\((.*)\)$/),N=p.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=p.match(/^!\[([^\]]+)\]$/);if(y){const _=Ti(y[2]);h.push(_?Cs(f,y[1],_.href,_.title,l):p)}else if(N){const _=N[2]||N[1],B=l.referenceDefinitions.get(Ha(_));h.push(B?Cs(f,N[1],B.href,B.title,l):p)}else if(I){const _=l.referenceDefinitions.get(Ha(I[1]));h.push(_?Cs(f,I[1],_.href,_.title,l):p)}else h.push(p)}else if(p.startsWith("[^")){const y=Su(p.slice(2,-1)),N=l.footnoteDefinitions.get(y);h.push(N?e.jsx("sup",{id:`fnref-${N.id}`,title:N.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${N.id}`,className:"text-primary no-underline",children:N.index})},f):p)}else if(p.startsWith("<http")){const y=p.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(p.startsWith("<")&&p.endsWith(">")&&xd(p.slice(1,-1))){const y=p.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(xd(oi(p).linkText)){const{linkText:y,suffix:N}=oi(p);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)),N&&h.push(N)}else if(p.startsWith("http")||p.startsWith("www.")){const{linkText:y,suffix:N}=oi(p),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)),N&&h.push(N)}else{const y=p.match(/^\[([^\]]+)\]\((.*)\)$/),N=p.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=p.match(/^\[([^\]]+)\]$/),_=N?N[2]||N[1]:I?.[1]??null,B=_?l.referenceDefinitions.get(Ha(_)):null,E=y?Ti(y[2]):null,$=E?.href??B?.href??null,L=$?vu($):null,A=y?.[1]??N?.[1]??I?.[1]??"";h.push(L?e.jsx("a",{href:L,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:rt(A,`${f}-link`,s,l)},f):p)}m=c.lastIndex}return m<d.length&&h.push(vd(d.slice(m))),h.length>0?h:[t]}function Tu(t){return/(?: {2,}|\\)$/.test(t)}function Iu(t){return t.replace(/(?: {2,}|\\)$/,"")}function Ka(t){return/^(?: {4}|\t)/.test(t)}function Fu(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function _u(t,n,s){const l=[];return t.forEach((d,c)=>{const h=Tu(d);l.push(...rt(Iu(d),`${n}-${c}`,!0,s)),c<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Ii(t,n,s){const l=[],d=[];return t.forEach((c,h)=>{d.push(Tu(c)),l.push(rt(Iu(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:d}}function Fi(t,n,s,l,d){const c=[];return t.forEach((h,m)=>{const g=s[m]??0,p=!!(d&&g>=d.start&&g<=d.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":p?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&c.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),c}function As(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",d=!1,c=0,h=0;for(let m=0;m<n.length;m+=1){const g=n[m];if(d){l+=g,d=!1;continue}if(g==="\\"){d=!0;continue}if(g==="`"){const p=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const f=m-p+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return d&&(l+="\\"),s.push(l.trim()),s}function Du(t){return As(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function Va(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Ya(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function Bu(t,n){return t>96||t>44&&n>.35}function to(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Ps(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function Ki(t,n,s,l,d,c=new Set){const h=[],m=[];let g=n;for(;g<t.length;){const p=t[g];if(d&&(qa(p)||c.has(g))){g+=1;continue}const f=Ps(p),k=to(p);if(!f){if(k>s&&m.length>0){([...m].reverse().find(_=>_.indent<k)?.item??m[m.length-1].item).paragraphs.push(p.trim());for(const _ of m)_.item.lineEnd=g+1;g+=1;continue}break}if(k<s||k===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;m.length>0&&m[m.length-1].indent>=k;)m.pop();const N=m[m.length-1]?.item??null;N?N.children.push(y):h.push(y),m.push({indent:k,item:y});for(const I of m)I.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function Ig(t){const n=t.find(l=>Ps(l));if(!n)return[];const s=Ps(n);return s?Ki(t,0,to(n),s.ordered,!0,Ru(t)).items:[]}function Vi(t,n,s,l=0){return t.map((d,c)=>{const h=d.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:d.lineStart+l,refEnd:d.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,rt(h?.[2]??d.content,`li-${n}-${c}`,!0,s),d.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:d.paragraphs.map((m,g)=>e.jsx("p",{children:rt(m,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:Fg(d.children,`${n}-${c}`,s,l)}})}function Fg(t,n,s,l=0){const d=[];for(const c of t){const h=d[d.length-1];h&&h.ordered===c.ordered?h.items.push(c):d.push({ordered:c.ordered,items:[c]})}return d.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:Vi(c.items,`${n}-g${h}`,s,l)}))}function Yi(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&_g(s.groups,n)]},s.key)})}function _g(t,n){return t.map((s,l)=>{const d=s.ordered?"ol":"ul";return e.jsx(d,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Yi(s.items,n)},`nested-${l}`)})}function Dg(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[rt(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Bg(t,n,s,l){const d=[];let c=0;const h=m=>l?.[m]??m+1;for(;c<t.length;){const m=t[c],g=m.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const E=c;let $="Details";const L=[];for(c+=1;c<t.length&&!/^<\/details>\s*$/i.test(t[c].trim());){const A=t[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);A?$=A[1].trim()||$:L.push(t[c].trimStart()),c+=1}c<t.length&&(c+=1),d.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:rt($,`${n}-details-${E}-summary`,!0,s)}),L.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:_u(L,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const p=Pu(m);if(p){const E=[m],$=c;for(c+=1;c<t.length&&!p.selfContained&&!new RegExp(`</${p.tag}>`,"i").test(t[c]);)E.push(t[c]),c+=1;c<t.length&&!p.selfContained&&(E.push(t[c]),c+=1),d.push({kind:"static",node:e.jsx(Au,{html:E.join(`
1639
- `)},`${n}-html-${$}`)});continue}const f=g.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],$=f[1],L=f[2]?.trim(),A=c;for(c+=1;c<t.length&&!t[c].trim().startsWith($);)E.push(t[c]),c+=1;c<t.length&&(c+=1),L.toLowerCase()==="mermaid"?d.push({kind:"static",node:e.jsx(Uu,{code:E.join(`
1640
- `),blockKey:`${n}-code-${A}`},`${n}-code-${A}`)}):["math","latex","tex"].includes(L.toLowerCase())?d.push({kind:"static",node:e.jsx(Ls,{tex:E.join(`
1635
+ `,Ea="/api/terminal/fs/preview/",Ip=8*1024*1024,Fp=32*1024*1024,Dp=128,_p="data:,";function Nt(t){throw new Error(t)}function Bp(t){return JSON.stringify(t).replace(/</g,"\\u003c")}async function rd(t,n,s){let l="",d=0;for(const c of t.matchAll(n))l+=t.slice(d,c.index)+await s(c),d=c.index+c[0].length;return l+t.slice(d)}async function Zd(t,n){const s=n.origin??location.origin,l=new URL(t,s);(l.origin!==s||!ps(l.pathname)?.startsWith(Ea))&&Nt("预览地址不是有效的本地文件入口");const d=crypto.randomUUID(),c=`https://termdock-preview.invalid/${d}/`,h=[],m=G=>{!h.includes(G)&&h.length<20&&h.push(G)},g=new Set,p=[],f=new Set,k=new Map,y=new Map;let N=0,I=!1;const D=new Set,B=()=>{I=!0;for(const G of[...D])G();g.clear(),p.length=0};async function E(G){G.ok||Nt(`预览资源读取失败(${G.status})`);const J=G.body?.getReader(),M=[];let _=0;try{if(J)for(;;){const oe=await J.read();if(oe.done)break;_+=oe.value.byteLength,N+=oe.value.byteLength,(_>Ip||N>Fp)&&Nt("预览资源超出大小限制"),M.push(oe.value)}}catch(oe){throw await J?.cancel().catch(()=>{}),oe}finally{J?.releaseLock()}const K=new Uint8Array(_);let re=0;for(const oe of M)K.set(oe,re),re+=oe.length;return{bytes:K,type:G.headers.get("content-type")??"application/octet-stream",status:G.status}}let $=l,L;for(let G=0;G<4;G++){const J=await n.fetch($.pathname+$.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(J.status)){L=J;break}const M=J.headers.get("location");await J.body?.cancel(),M||Nt("预览重定向缺少目标");const _=new URL(M,$);(_.origin!==s||!ps(_.pathname)?.startsWith(Ea))&&Nt("预览重定向越出文件范围"),$=_}L||Nt("预览重定向次数过多");const A=ps($.pathname),U=A.slice(Ea.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||Nt("服务未提供有效的预览资源授权");const F=ps(l.pathname).slice(Ea.length).split("/");/^[a-f0-9]{32}$/.test(F[0])&&F.shift(),F.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&Nt("预览重定向改变了文件范围");const a=A.endsWith("/")?A:A.slice(0,A.lastIndexOf("/")+1),w=new URL($.pathname.endsWith("/")?$.pathname:$.pathname.slice(0,$.pathname.lastIndexOf("/")+1),s);function O(G,J){const M=new URL(G,J);return M.origin!==s?null:(ps(M.pathname)?.startsWith(a)||Nt("已阻止预览访问目录之外的资源"),M)}function j(G){const J=new URL(G,c);(J.origin!==new URL(c).origin||!J.pathname.startsWith(new URL(c).pathname))&&Nt("已阻止预览访问服务接口或目录之外的资源");const M=J.pathname.slice(new URL(c).pathname.length)+J.search;return O(M,w)??Nt("预览资源无效")}function X(G){const J=G.pathname+G.search,M=k.get(J);if(M)return M;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(k.size>=Dp)return Promise.reject(new Error("预览资源数量超出限制"));const _=n.fetch(J,{signal:n.signal,redirect:"manual"}).then(E);return k.set(J,_),_}function ne(G,J){I&&Nt("预览已关闭");const M=`termdock-resource-${d}-${p.length}`;return p.push({token:M,data:G,type:J}),g.add(M),M}async function se(G,J,M,_=new Set){if(!G||G.startsWith("#")||/^data:(?:image|font)\//i.test(G)&&M==="resource")return G;try{const K=O(G,J);if(!K){const je=new URL(G,J);return(je.protocol!=="https:"||je.username||je.password||je.origin===new URL(c).origin)&&Nt("已阻止不安全的外部资源"),f.add(je.origin),je.href}const re=`${M}:${K.href}`;(_.has(re)||_.size>=8)&&Nt("预览资源存在循环或过深引用");const oe=y.get(re);if(oe)return oe;const he=new Set(_);he.add(re);const me=(async()=>{const je=await X(K);return M==="css"?ne(await fe(new TextDecoder().decode(je.bytes),K,he),"text/css"):M==="script"?ne(je.bytes,"text/javascript"):ne(je.bytes,je.type)})();return y.set(re,me),await me}catch(K){return m(K instanceof Error?K.message:"部分预览资源未能加载"),_p}}async function fe(G,J,M){return G=await rd(G,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async _=>`@import url("${await se(_[1],J,"css",M)}")${_[2]};`),rd(G,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async _=>{const K=(_[1]??_[2]??_[3]).trim();return g.has(K)?_[0]:`url("${await se(K,J,"resource",M)}")`})}try{const G=await E(L),J=ne(Pp,"text/javascript"),M=new DOMParser().parseFromString(new TextDecoder().decode(G.bytes),"text/html");M.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(C=>C.remove());for(const C of M.querySelectorAll("*")){if(C.removeAttribute("ping"),C.removeAttribute("srcdoc"),C.hasAttribute("style")&&C.setAttribute("style",await fe(C.getAttribute("style"),$,new Set)),C.tagName==="STYLE"&&(C.textContent=await fe(C.textContent??"",$,new Set)),C.tagName==="A"||C.tagName==="AREA"){const Z=C.getAttribute("href");try{if(Z&&!Z.startsWith("#")){const de=O(Z,$);if(de)C.setAttribute("href",new URL(de.pathname.slice(w.pathname.length)+de.search+de.hash,c).href);else{const Ee=new URL(Z,$);if(Ee.protocol!=="https:"){C.removeAttribute("href");continue}f.add(Ee.origin),C.setAttribute("href",Ee.href)}}}catch(de){C.removeAttribute("href"),m(de instanceof Error?de.message:"预览链接无法加载")}}for(const Z of["data","manifest"])C.removeAttribute(Z);if(C.tagName==="SCRIPT"&&C.getAttribute("type")==="module"){C.setAttribute("type","module-shim");const Z=C.getAttribute("src");if(Z){const de=O(Z,$);if(de)C.setAttribute("src",new URL(de.pathname.slice(w.pathname.length)+de.search,c).href);else{const Ee=new URL(Z,$);if(Ee.protocol!=="https:"){C.remove();continue}f.add(Ee.origin),C.setAttribute("src",Ee.href)}}continue}if(C.tagName==="SCRIPT"&&C.getAttribute("type")==="importmap"){C.setAttribute("type","importmap-shim");continue}if(C.tagName==="LINK"){const Z=(C.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Z)){C.remove();continue}const de=C.getAttribute("href");de&&C.setAttribute("href",await se(de,$,Z==="stylesheet"?"css":"resource"))}if(C.hasAttribute("src")&&C.setAttribute("src",await se(C.getAttribute("src"),$,C.tagName==="SCRIPT"?"script":"resource")),C.hasAttribute("poster")&&C.setAttribute("poster",await se(C.getAttribute("poster"),$,"resource")),C.hasAttribute("srcset")){const Z=C.getAttribute("srcset");/data:/i.test(Z)?(C.removeAttribute("srcset"),m("混合内嵌图片候选暂不支持安全预览")):C.setAttribute("srcset",(await Promise.all(Z.split(",").map(async de=>{const[Ee,...Ge]=de.trim().split(/\s+/);return`${await se(Ee,$,"resource")} ${Ge.join(" ")}`}))).join(", "))}C.setAttribute("referrerpolicy","no-referrer"),C.removeAttribute("integrity"),C.removeAttribute("crossorigin")}const _=[...f].join(" "),K=M.createElement("meta");K.httpEquiv="Content-Security-Policy",K.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${_}; style-src 'unsafe-inline' blob: ${_}; img-src blob: data: ${_}; font-src blob: data: ${_}; media-src blob: data: ${_}; connect-src blob: ${_} ${[...f].map(C=>C.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=M.createElement("base");re.href=c;const oe=M.createElement("meta");oe.name="referrer",oe.content="no-referrer";const he=M.createElement("script");he.textContent=Tp+`
1636
+ installPreviewRuntime(`+[d,c,[...f],J].map(Bp).join(",")+");";const me=M.createElement("script");me.src=J,M.head.prepend(K,oe,re,he,me);const je=`<!doctype html>
1637
+ `+M.documentElement.outerHTML;return{html:je,shellUrl:`/preview-shell.html#${d}`,errors:h,attach(C,Z){const de=new Set,Ee=De=>{if(De.source!==C.contentWindow||De.data?.capability!==d)return;if(De.data.type==="preview-ready"){C.contentWindow?.postMessage({type:"preview-init",capability:d,html:je,resources:p},"*");return}if(De.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(De.data.type==="preview-navigate"){(async()=>{const ae=j(String(De.data.url)),S=await Zd(ae.pathname+ae.search,n);if(I){S.dispose();return}const V=S.attach(C,Z);D.add(()=>{V(),S.dispose()}),C.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(ae=>Z(ae instanceof Error?ae.message:"无法打开预览页面"));return}if(De.data.type==="preview-external"){try{const ae=new URL(String(De.data.url));ae.protocol==="https:"&&f.has(ae.origin)&&window.open(ae.href,"_blank","noopener,noreferrer")}catch{}return}if(De.data.type!=="preview-fetch"||De.ports.length!==1)return;const le=De.ports[0];if(de.size>=8||!["GET","HEAD"].includes(De.data.method)){le.postMessage({error:"预览仅允许读取已授权目录资源"}),le.close();return}de.add(le),(async()=>{const ae=j(String(De.data.url)),S=await X(ae);if(!de.has(le)||I)return;const V=De.data.method==="HEAD"?new Uint8Array:S.bytes.slice();le.postMessage({status:S.status,headers:{"content-type":S.type},data:V.buffer},[V.buffer])})().catch(()=>{le.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{de.delete(le),le.close()})};window.addEventListener("message",Ee);const Ge=()=>{window.removeEventListener("message",Ee);for(const De of de)De.close();de.clear(),D.delete(Ge)};return D.add(Ge),Ge},dispose:B}}catch(G){throw B(),G}}const Op=o.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:d},c){const h=o.useRef(null),[m,g]=o.useState(null),[p,f]=o.useState(),[k,y]=o.useState("");o.useEffect(()=>{const A=new AbortController;let U;return f(void 0),y(""),(async()=>{const F=await hh();if(U=await Zd(n,{fetch:(a,w)=>F.fetch(a,w),signal:A.signal}),A.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(F=>{A.signal.aborted||y(F instanceof Error?F.message:"安全预览加载失败")}),()=>{A.abort(),U?.dispose()}},[n]),o.useEffect(()=>{if(!(!p||!m))return p.attach(m,y)},[p,m]);const[N,I]=o.useState(!1),[D,B]=o.useState(!1),E=N||D;o.useEffect(()=>{d?.(E)},[E,d]),o.useEffect(()=>{const A=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",A),()=>document.removeEventListener("fullscreenchange",A)},[]),o.useEffect(()=>{if(!D)return;const A=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[D]);const $=o.useCallback(async()=>{const A=h.current;if(A){if(D){B(!1);return}if(document.fullscreenElement===A){await document.exitFullscreen();return}if(A.requestFullscreen&&document.fullscreenEnabled!==!1)try{await A.requestFullscreen();return}catch{}B(!0)}},[D]);o.useImperativeHandle(c,()=>({toggleFullscreen:$}),[$]);const L=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(Od,{size:15})})]}),k&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:k}),!p&&!k&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:p?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return D?Gr.createPortal(L,document.body):L}),eu="termdock-file-search-match",Ci="termdock-file-search-current";function Up(t){const n=t.metaKey||t.ctrlKey,s=t.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||t.key==="F3"?t.shiftKey?"previous":"next":t.key==="Escape"?"close":null}function Hp(t){return t.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function zp(t,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let d="",c=null;const h=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const k=Hp(f);if(!k)continue;c&&c!==k&&(d+=`
1638
+ `);const y=d.length;d+=f.data,l.push({node:f,start:y,end:d.length,group:k}),c=k}const m=d.toLocaleLowerCase(),g=[];let p=0;for(;p<=m.length-s.length;){const f=m.indexOf(s,p);if(f<0)break;const k=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),N=l.find(I=>I.start<k&&I.end>=k);if(y&&N&&y.group===N.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(N.node,k-N.start),g.push(I)}p=f+Math.max(s.length,1)}return g}function tu(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function La(){const t=tu();t?.delete(eu),t?.delete(Ci)}function nd(t,n){const s=tu();if(!s||typeof Highlight>"u")return;s.set(eu,new Highlight(...t));const l=t[n];l?s.set(Ci,new Highlight(l)):s.delete(Ci)}function sd(t){t?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function Wp(t){return Array.from(new Set(t.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function Gp(t,n){const s=n.trim();return!s||s==="."?t:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${t.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function qp(t,n){if(n===t)return".";const s=`${t.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function ru(t,n,s){return n?t:Gr.createPortal(t,s)}const Ui="termdock:right-sidebar:file-tree-scroll:v1",Hi="termdock:right-sidebar:file-preview-reading-state:v1",ys="termdock:right-sidebar:file-tree-width:v1",nu="termdock:right-sidebar:markdown-view-mode:v1",su="termdock:right-sidebar:diff-change-list-mode:v1",au="termdock:right-sidebar:diff-wrap:v1",ou="termdock:diff-viewer:view-type:v1",iu="termdock:right-sidebar:file-search-mode:v1",Qo="termdock:right-sidebar:collapsed-git-repo-groups:v1",ad="termdock:right-sidebar:collapsed-diff-directories:v1",Zo="termdock:right-sidebar:branch-audit-module-open:v1",lu="termdock:right-sidebar:branch-audit-module:v1",Kp=150,cu="termdock:right-sidebar:active-git-repo:v1",od="termdock:right-sidebar:context-draft-enabled:v1",id="termdock:right-sidebar:context-draft-collapsed:v1",ld="termdock:right-sidebar:context-draft-auto-collapse:v1",ei="termdock:right-sidebar:context-draft-text:v1",Vp=300,Yp=20,Xp=120,Jp=250,Qp=250,Zp=120,eg=700,ti=600;function Gn(t){return!!(t&&te.getState().nestedGitScanRoots[t])}const cd=[2e3,5e3,15e3,3e4],tg=320,rg=500,ng=20,sg=12e3,Ni=300,dd=240,ag=560,du="border-r px-2 py-1.5 sm:px-3 sm:py-2",za="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",uu=`${du} border-b border-border/15 font-semibold last:border-r-0`,fu=`${du} border-border/10 align-top text-muted-foreground last:border-r-0`,zi="termdock-file-preview-horizontal-scroll",ud=o.lazy(()=>Ms(()=>import("./ModelPreview-Da1kMWa7.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),hu=`${zi} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function mu(t,n,s){return t&&!n?"unified":s}const og=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function ig(t){return t==="preview"||t==="source"}function lg(t){return t==="list"||t==="tree"||t==="ai"}function fd(){return tt(nu,ig)??"preview"}function cg(){return tt(su,lg)??"tree"}function ws(t){return typeof t=="boolean"}function dg(t){return typeof t=="string"}function ug(){return tt(au,ws)??!0}function fg(t){return t==="unified"||t==="split"}function hg(){return tt(ou,fg)??"unified"}function mg(t){return t==="name"||t==="content"||t==="regex"}function pg(){return tt(iu,mg)??"name"}function pu(t){return t.repositories??(t.context?.root?[{id:t.context.root,root:t.context.root,relativeRoot:".",name:ft(t.context.root)||t.context.root,depth:0,nested:!1,available:t.available,files:t.files,context:t.context,error:t.error}]:[])}function gg(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(n=>n===null||typeof n=="string")}function gu(){return tt(cu,gg)??{}}function hd(t){if(!t)return;const n=gu();return Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function ri(t,n){t&&xt(cu,{...gu(),[t]:n})}function bg(t,n){if(!n)return null;const s=new Set((t.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(t.repositories??[]).some(l=>l.root===n)?n:null}function Mi(t){return!t.activeGitRepoRoot&&(t.groupCount>1||t.label!==t.rootName)}function bu(...t){const n=new Set;for(const s of t)for(const l of s)n.add(l.root);return n}function $i(t){return Array.isArray(t)&&t.every(n=>typeof n=="string")}function md(t){const n=tt(t,$i);return n?new Set(n):new Set}function ni(t,n){xt(t,[...n])}function xg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function vg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||$i(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(xg))&&(n.commits===void 0||$i(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 yg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.key=="string"&&vg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function wg(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.values(t).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(yg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function pd(){return tt(lu,wg)??{}}function gd(t){return[t.repoRoot,t.baseRef,t.branchName??"",t.headRef??"",t.diffFingerprint??""].join("\0")}function bd(t){const n=t?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function xu(t,n){const s=t?.trim(),l=n?.trim();return!s||!l?!1:s===l||bd(s)===bd(l)}function xd(t){const n=t?.branch??null;return[t?.upstream,...t?.remoteBranches??[],...t?.branches??[]].find(l=>l&&!xu(l,n))??""}function Ei(t,n){const s=Math.max(dd,n-320),l=Math.min(ag,s);return Math.min(l,Math.max(dd,t))}function kg(t){return typeof t=="number"&&Number.isFinite(t)}function Sg(t){return Ei(tt(ys,kg)??Ni,t)}function vu(t){const n=t.split(/[\\/]/).pop()??t,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function xs(t){return og.has(vu(t))}function yu(t){const n=t.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Li(t){const n=t.trim();return/^#{1,6}\s+/.test(n)||yu(t)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function wu(t){const n=t.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const ku=o.createContext(null);function Oa(t){return t.trim().replace(/\s+/g," ").toLowerCase()}function Su(t){return t.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function ju(t){return t.replace(/\s+#+\s*$/,"").trim()}function Ai(t,n){const l=Su(t).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",d=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,d+1),d===0?l:`${l}-${d}`}function vd(t){return Su(t)||t.trim()}function Wa(t){const n=t.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Ti(n[2]);return s?{id:Oa(n[1]),definition:{href:s.href,title:s.title}}:null}function jg(t){const n=new Map;for(const s of t){const l=Wa(s);l&&n.set(l.id,l.definition)}return n}function Ru(t){return t.trim().toLowerCase()}function Cu(t){const n=t.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Ru(n[1]),text:n[2]}:null}function Rg(t){const n=new Map;let s=null;for(const l of t){const d=Cu(l);if(d){s=d.id,n.set(d.id,{id:d.id,text:d.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function Nu(t){const n=new Set;let s=!1;return t.forEach((l,d)=>{if(Cu(l)){n.add(d),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(d);return}l.trim()&&(s=!1)}),n}function Cg(t){const n=[...t];let s=0;const l=t[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<t.length&&t[s].trim()!==l;)n[s]="",s+=1;s<t.length&&(n[s]="",s+=1)}for(;s<t.length;){const d=t[s].trim();if(d.startsWith("<!--")){if(n[s]="",!d.includes("-->")){for(s+=1;s<t.length&&!t[s].includes("-->");)n[s]="",s+=1;s<t.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Mu(t){const n=t.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function js(t){const n=t.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function Wi(t,n,s){const l=t.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const d=l.indexOf("#"),c=d>=0?l.slice(0,d):l,h=d>=0?l.slice(d+1):"",m=c.split("?",1)[0];if(!m)return null;let g,p=null;try{g=decodeURIComponent(m),p=h?decodeURIComponent(h):null}catch{return null}const f=s?js(s):null;let k;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));k=js(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;k=js(`${Mu(n)}/${g}`)}return f&&k!==f&&!k.startsWith(`${f}/`)?null:{path:k,fragment:p,directory:/\/$/.test(m)}}function Gi(t,n,s,l,d){const c=t.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const m=s&&(c===s||c.startsWith(`${s}/`));h=js(s&&!m?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=js(`${Mu(n)}/${c}`)}return d(h)}function Ng(t,n,s){return Gi(t,n,s,Oi,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Mg(t,n,s){return Gi(t,n,s,Ad,Pd)}const Pi=128,$g=360,si=480;function Qa(t){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(t))}catch{return!1}}function $u(t,n,s,l,d=0){if(!n||!s)return null;let c,h;return d>0?(c=l>0?Math.min(d,l):d,h=s*c/n):Qa(t)?(h=Math.min(Math.max(s,Pi),$g),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>si&&(c=c*si/h,h=si),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Eg(t){if(!t.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(t.slice(t.indexOf("?"))).get("path")}catch{return null}}function Eu(t){const n=Eg(t),s=te(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${t}&v=${s}`:t}function Lg({src:t,alt:n,title:s,requestedWidthPx:l}){const d=Qa(t),c=Eu(t),h=Xa(c),m=o.useRef(null),[g,p]=o.useState(!1),[f,k]=o.useState(0),[y,N]=o.useState({status:"loading"}),[I,D]=o.useState(null);o.useLayoutEffect(()=>{const $=m.current,L=$?.parentElement?.parentElement??$?.parentElement;if(!L)return;const A=()=>k(L.clientWidth);if(A(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(A);return U.observe(L),()=>U.disconnect()},[]),o.useEffect(()=>{if(g)return;const $=m.current;if(!$||typeof IntersectionObserver>"u"){p(!0);return}const L=new IntersectionObserver(A=>{A.some(U=>U.isIntersecting)&&(p(!0),L.disconnect())},{rootMargin:"400px"});return L.observe($),()=>L.disconnect()},[g]),o.useEffect(()=>{if(!g)return;const $=new AbortController;let L=null;N({status:"loading"});const A=window.setTimeout(()=>{$.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return zh(c,{signal:$.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=Number(U.headers.get("X-Image-Width"))||0,a=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:F,height:a}}).then(({blob:U,width:F,height:a})=>{$.signal.aborted||(L=URL.createObjectURL(U),F>0&&a>0&&D({width:F,height:a}),N({status:"ready",objectUrl:L}))}).catch(()=>{const U=$.signal.reason;$.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||N({status:"fallback"})}).finally(()=>{window.clearTimeout(A)}),()=>{window.clearTimeout(A),$.abort(),L&&URL.revokeObjectURL(L)}},[g,c]);const B=$u(t,I?.width??0,I?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:Pi*2,height:Pi});return e.jsx("div",{ref:m,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${d?"":"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 L=$.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&D({width:L.naturalWidth,height:L.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 L=$.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&D({width:L.naturalWidth,height:L.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 Rs(t,n,s,l,d,c){const h=Ng(s,d.markdownFilePath,d.rootPath);if(!h)return c?.fallbackText??`![${n}](${s})`;const m=d.images.length;d.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(Lg,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return d.onImageOpen&&c?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:p=>{p.stopPropagation(),d.onImageOpen?.(m)},children:g},t):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},t)}function ai(t){let n=t,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function yd(t){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(t)}function Ti(t){const n=t.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const Lu="",Ag=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Pg(t){return t.replace(Ag,(n,s)=>`${Lu}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function wd(t){return t.replace(new RegExp(`${Lu}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Tg(t){const n=t.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Au={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 Aa=null;function Pu(){return Aa||(Aa=Ms(()=>import("./purify.es-4eNOHKSq.js"),[]).then(t=>t.default??t).catch(t=>{throw Aa=null,t})),Aa}function Tu({html:t}){const{t:n}=yt(),[s,l]=o.useState(null);return o.useEffect(()=>{let d=!1;return l(null),Pu().then(c=>{d||l(c.sanitize(t,Au))}).catch(()=>{d||l("")}),()=>{d=!0}},[t]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function Ig({html:t}){const[n,s]=o.useState(null);return o.useEffect(()=>{let l=!1;return s(null),Pu().then(d=>{l||s(d.sanitize(t,Au))}).catch(()=>{l||s("")}),()=>{l=!0}},[t]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):t}function Iu(t){const n=t.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(t)}}let Pa=null;function Fg(){return Pa||(Pa=Promise.all([Ms(()=>import("./katex-DnlPpQZa.js"),[]),Ms(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([t])=>t.default??t).catch(t=>{throw Pa=null,t})),Pa}function Es({tex:t,display:n=!1}){const[s,l]=o.useState(null),[d,c]=o.useState(!1);if(o.useEffect(()=>{let m=!1;return l(null),c(!1),Fg().then(g=>{m||l(g.renderToString(t,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||c(!0)}),()=>{m=!0}},[n,t]),d)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${t}$$`:`$${t}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":t});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function qi(t){const n=new Map;for(const s of t.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function kd(t){const n=qi(t),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function Dg(t){const n=t.indexOf(">"),s=n<0?t:t.slice(0,n+1),l=qi(s),d=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),m=n<0?"":t.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:d,fallbackText:m,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function _g({url:t,fallbackText:n,widthPx:s,hasControls:l}){const{t:d}=yt(),[c,h]=o.useState(!1),m=Xa(t,()=>h(!0));return m?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||d("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:m,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function Bg(t,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(t)){const h=t.slice(0,t.indexOf(">")+1),m=qi(h).get("href")?.trim()??"",g=t.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:p,alt:f,title:k,widthPx:y}=kd(g);if(!p)return null;const N=Gi(p,s.markdownFilePath,s.rootPath,Oi,$=>$);if(!N)return null;const I=m?Wi(m,s.markdownFilePath,s.rootPath):null,B=!!!(I&&I.path===N)&&m?wu(m):null,E=Rs(n,f??"",p,k,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(t)){const{src:h,alt:m,title:g,widthPx:p}=kd(t);return h?Rs(n,m??"",h,g,s,{fallbackText:t,requestedWidthPx:p}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(t)){const{src:h,fallbackText:m,widthPx:g,controls:p}=Dg(t);if(!h)return null;const f=Mg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(_g,{url:f,fallbackText:m,widthPx:g,hasControls:p},n):null}if(/^<br\s*\/?>$/i.test(t))return e.jsx("br",{},n);const l=t.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(t)?e.jsx(Ig,{html:t},n):null;const d=l[1].toLowerCase(),c=rt(l[2],`${n}-${d}`,!0,s);return d==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:c},n):d==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):d==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function rt(t,n,s=!0,l){const d=Pg(t),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let m=0,g;for(;(g=c.exec(d))!==null;){g.index>m&&h.push(wd(d.slice(m,g.index)));const p=g[0],f=`${n}-${g.index}`,k=p.startsWith("<")?Bg(p,f,l):null;if(k)h.push(k);else if(p.startsWith("\\(")&&p.endsWith("\\)"))h.push(e.jsx(Es,{tex:p.slice(2,-2)},f));else if(p.startsWith("$")&&p.endsWith("$"))h.push(e.jsx(Es,{tex:p.slice(1,-1)},f));else if(p.startsWith("`")){const y=p.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:Tg(p.slice(y,-y))},f))}else if(p.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:rt(p.slice(2,-2),`${f}-del`,s,l)},f));else if(p.startsWith("**")||p.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:rt(p.slice(2,-2),`${f}-strong`,s,l)},f));else if(p.startsWith("*")||p.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:rt(p.slice(1,-1),`${f}-em`,s,l)},f));else if(p.startsWith("![")){const y=p.match(/^!\[([^\]]*)\]\((.*)\)$/),N=p.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=p.match(/^!\[([^\]]+)\]$/);if(y){const D=Ti(y[2]);h.push(D?Rs(f,y[1],D.href,D.title,l):p)}else if(N){const D=N[2]||N[1],B=l.referenceDefinitions.get(Oa(D));h.push(B?Rs(f,N[1],B.href,B.title,l):p)}else if(I){const D=l.referenceDefinitions.get(Oa(I[1]));h.push(D?Rs(f,I[1],D.href,D.title,l):p)}else h.push(p)}else if(p.startsWith("[^")){const y=Ru(p.slice(2,-1)),N=l.footnoteDefinitions.get(y);h.push(N?e.jsx("sup",{id:`fnref-${N.id}`,title:N.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${N.id}`,className:"text-primary no-underline",children:N.index})},f):p)}else if(p.startsWith("<http")){const y=p.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(p.startsWith("<")&&p.endsWith(">")&&yd(p.slice(1,-1))){const y=p.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(yd(ai(p).linkText)){const{linkText:y,suffix:N}=ai(p);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)),N&&h.push(N)}else if(p.startsWith("http")||p.startsWith("www.")){const{linkText:y,suffix:N}=ai(p),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)),N&&h.push(N)}else{const y=p.match(/^\[([^\]]+)\]\((.*)\)$/),N=p.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=p.match(/^\[([^\]]+)\]$/),D=N?N[2]||N[1]:I?.[1]??null,B=D?l.referenceDefinitions.get(Oa(D)):null,E=y?Ti(y[2]):null,$=E?.href??B?.href??null,L=$?wu($):null,A=y?.[1]??N?.[1]??I?.[1]??"";h.push(L?e.jsx("a",{href:L,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:rt(A,`${f}-link`,s,l)},f):p)}m=c.lastIndex}return m<d.length&&h.push(wd(d.slice(m))),h.length>0?h:[t]}function Fu(t){return/(?: {2,}|\\)$/.test(t)}function Du(t){return t.replace(/(?: {2,}|\\)$/,"")}function Ga(t){return/^(?: {4}|\t)/.test(t)}function _u(t){return t.startsWith(" ")?t.slice(1):t.replace(/^ {4}/,"")}function Bu(t,n,s){const l=[];return t.forEach((d,c)=>{const h=Fu(d);l.push(...rt(Du(d),`${n}-${c}`,!0,s)),c<t.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Ii(t,n,s){const l=[],d=[];return t.forEach((c,h)=>{d.push(Fu(c)),l.push(rt(Du(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:d}}function Fi(t,n,s,l,d){const c=[];return t.forEach((h,m)=>{const g=s[m]??0,p=!!(d&&g>=d.start&&g<=d.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":p?"true":void 0,children:h},`${l}-ref-${m}`)),m<t.length-1&&c.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),c}function Ls(t){const n=t.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",d=!1,c=0,h=0;for(let m=0;m<n.length;m+=1){const g=n[m];if(d){l+=g,d=!1;continue}if(g==="\\"){d=!0;continue}if(g==="`"){const p=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const f=m-p+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return d&&(l+="\\"),s.push(l.trim()),s}function Ou(t){return Ls(t).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function qa(t){return t==="center"?"text-center":t==="right"?"text-right":"text-left"}function Ka(t){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(t.trim())}function Uu(t,n){return t>96||t>44&&n>.35}function Za(t){return(t.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function As(t){const n=t.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function Ki(t,n,s,l,d,c=new Set){const h=[],m=[];let g=n;for(;g<t.length;){const p=t[g];if(d&&(Wa(p)||c.has(g))){g+=1;continue}const f=As(p),k=Za(p);if(!f){if(k>s&&m.length>0){([...m].reverse().find(D=>D.indent<k)?.item??m[m.length-1].item).paragraphs.push(p.trim());for(const D of m)D.item.lineEnd=g+1;g+=1;continue}break}if(k<s||k===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;m.length>0&&m[m.length-1].indent>=k;)m.pop();const N=m[m.length-1]?.item??null;N?N.children.push(y):h.push(y),m.push({indent:k,item:y});for(const I of m)I.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function Og(t){const n=t.find(l=>As(l));if(!n)return[];const s=As(n);return s?Ki(t,0,Za(n),s.ordered,!0,Nu(t)).items:[]}function Vi(t,n,s,l=0){return t.map((d,c)=>{const h=d.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:d.lineStart+l,refEnd:d.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,rt(h?.[2]??d.content,`li-${n}-${c}`,!0,s),d.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:d.paragraphs.map((m,g)=>e.jsx("p",{children:rt(m,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:Ug(d.children,`${n}-${c}`,s,l)}})}function Ug(t,n,s,l=0){const d=[];for(const c of t){const h=d[d.length-1];h&&h.ordered===c.ordered?h.items.push(c):d.push({ordered:c.ordered,items:[c]})}return d.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:Vi(c.items,`${n}-g${h}`,s,l)}))}function Yi(t,n){return t.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&Hg(s.groups,n)]},s.key)})}function Hg(t,n){return t.map((s,l)=>{const d=s.ordered?"ol":"ul";return e.jsx(d,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:Yi(s.items,n)},`nested-${l}`)})}function zg(t){const n=Array.from(t.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:t.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[rt(s.text,`footnote-${s.id}`,!0,t)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":t.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function Wg(t,n,s,l){const d=[];let c=0;const h=m=>l?.[m]??m+1;for(;c<t.length;){const m=t[c],g=m.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const E=c;let $="Details";const L=[];for(c+=1;c<t.length&&!/^<\/details>\s*$/i.test(t[c].trim());){const A=t[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);A?$=A[1].trim()||$:L.push(t[c].trimStart()),c+=1}c<t.length&&(c+=1),d.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:rt($,`${n}-details-${E}-summary`,!0,s)}),L.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Bu(L,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const p=Iu(m);if(p){const E=[m],$=c;for(c+=1;c<t.length&&!p.selfContained&&!new RegExp(`</${p.tag}>`,"i").test(t[c]);)E.push(t[c]),c+=1;c<t.length&&!p.selfContained&&(E.push(t[c]),c+=1),d.push({kind:"static",node:e.jsx(Tu,{html:E.join(`
1639
+ `)},`${n}-html-${$}`)});continue}const f=g.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],$=f[1],L=f[2]?.trim(),A=c;for(c+=1;c<t.length&&!t[c].trim().startsWith($);)E.push(t[c]),c+=1;c<t.length&&(c+=1),L.toLowerCase()==="mermaid"?d.push({kind:"static",node:e.jsx(zu,{code:E.join(`
1640
+ `),blockKey:`${n}-code-${A}`},`${n}-code-${A}`)}):["math","latex","tex"].includes(L.toLowerCase())?d.push({kind:"static",node:e.jsx(Es,{tex:E.join(`
1641
1641
  `),display:!0},`${n}-code-${A}`)}):d.push({kind:"code",key:`${n}-code-${A}`,code:E.join(`
1642
- `),lang:L,blockKey:`${n}-code-${A}`,codeStartLine:h(A)+1});continue}if(Ka(m)){const E=[],$=c;for(;c<t.length&&(Ka(t[c])||!t[c].trim());)E.push(t[c].trim()?Fu(t[c]):""),c+=1;d.push({kind:"code",key:`${n}-indented-code-${$}`,code:E.join(`
1643
- `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${$}`,codeStartLine:h($)});continue}const k=g.match(/^(#{1,6})\s+(.+)$/);if(k){const $=`h${Math.min(6,k[1].length+1)}`,L=ku(k[2]),A=Ai(L,s);d.push({kind:"static",node:e.jsx($,{id:A,className:"scroll-mt-16 font-semibold text-foreground",children:rt(L,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<t.length&&m.includes("|")&&Ya(t[c+1])){const E=As(m),$=Du(t[c+1]),L=[],A=c;for(c+=2;c<t.length&&t[c].includes("|")&&t[c].trim();)L.push(As(t[c])),c+=1;d.push({kind:"static",node:e.jsx("div",{className:uu,"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,F)=>e.jsx("th",{className:`${cu} ${Va($[F]??null)}`,children:e.jsx("div",{className:Ga,children:rt(U,`${n}-th-${A}-${F}`,!0,s)})},`h-${F}`))})}),e.jsx("tbody",{children:L.map((U,F)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((a,w)=>e.jsx("td",{className:`${du} ${Va($[w]??null)}`,children:e.jsx("div",{className:Ga,children:rt(U[w]??"",`${n}-td-${A}-${F}-${w}`,!0,s)})},`c-${w}`))},`r-${F}`))})]})},`${n}-table-${A}`)});continue}const y=Ps(m);if(y){const E=y.ordered,$=to(m),L=y.start,A=c,U=Ki(t,c,$,E,!1);c=U.nextIndex,d.push({kind:"list",keyPrefix:`${n}-list-${A}`,ordered:E,start:E?L:void 0,renders:Vi(U.items,`${n}-list-${A}`,s,h(0)-1)});continue}const N=[m.trimStart()],I=[h(c)],_=c;for(c+=1;c<t.length&&t[c].trim()&&!Li(t[c])&&!(c+1<t.length&&t[c].includes("|")&&Ya(t[c+1]));)N.push(t[c].trimStart()),I.push(h(c)),c+=1;const B=Ii(N,`${n}-p-${_}`,s);d.push({kind:"paragraph",keyPrefix:`${n}-p-${_}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:I})}return d}function Og(t,n){return t.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Fi(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:Yi(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(Xa,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Fa=null,wd=!1;const _a=16,Ou=192;function Ug(){return Fa||(Fa=$s(()=>import("./mermaid.core-Ba4l96YR.js").then(t=>t.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(t=>t.default??t).catch(t=>{throw Fa=null,t})),Fa}function Hg(t){wd||(t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),wd=!0)}function zg(t){const n=t.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return t;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,d,c]=l;if(!Number.isFinite(d)||!Number.isFinite(c)||d<=0||c<=0)return t;const h=Math.max(Ou,Math.ceil(d)),m=Math.ceil(h/d*c);return t.replace(/<svg\b([^>]*)>/i,(g,p)=>`<svg${p.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${m}">`)}function Wg(t){const n=t?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-_a,d=s.y-_a,c=s.width+_a*2,h=s.height+_a*2,m=Math.max(Ou,Math.ceil(c)),g=Math.ceil(m/c*h);n.setAttribute("viewBox",`${l} ${d} ${c} ${h}`),n.setAttribute("width",String(m)),n.setAttribute("height",String(g)),n.removeAttribute("style")}function Gg(t){const n=t.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return Od(`code.${s}`)??s}function Uu({code:t,blockKey:n}){const{t:s}=pt(),[l,d]=o.useState(null),[c,h]=o.useState(!1),m=o.useRef(null),g=o.useContext(yu);o.useEffect(()=>{let f=!1;return d(null),h(!1),Ug().then(async k=>{Hg(k);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:N}=await k.render(y,t);f||d(zg(N))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,t]),o.useLayoutEffect(()=>{l&&Wg(m.current)},[l]);const p=o.useCallback(()=>{const f=m.current?.querySelector("svg")?.outerHTML??l;f&&g?.(f)},[g,l]);return c?e.jsx(Xa,{code:t,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:f=>{f.stopPropagation(),p()},children:e.jsx("span",{ref:m,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function Xa({code:t,lang:n,blockKey:s,codeStartLine:l,lineRange:d}){const c=Gg(n),[h,m]=o.useState(null);o.useEffect(()=>{if(!c||!Ud(t)){m(null);return}let p=!1;return Hd().then(f=>{if(p||!f.registered(c)){p||m(null);return}try{m(Wd(f,t,c))}catch{p||m(null)}}).catch(()=>{p||m(null)}),()=>{p=!0}},[s,t,c]);const g=h??(t||" ").split(`
1642
+ `),lang:L,blockKey:`${n}-code-${A}`,codeStartLine:h(A)+1});continue}if(Ga(m)){const E=[],$=c;for(;c<t.length&&(Ga(t[c])||!t[c].trim());)E.push(t[c].trim()?_u(t[c]):""),c+=1;d.push({kind:"code",key:`${n}-indented-code-${$}`,code:E.join(`
1643
+ `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${$}`,codeStartLine:h($)});continue}const k=g.match(/^(#{1,6})\s+(.+)$/);if(k){const $=`h${Math.min(6,k[1].length+1)}`,L=ju(k[2]),A=Ai(L,s);d.push({kind:"static",node:e.jsx($,{id:A,className:"scroll-mt-16 font-semibold text-foreground",children:rt(L,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<t.length&&m.includes("|")&&Ka(t[c+1])){const E=Ls(m),$=Ou(t[c+1]),L=[],A=c;for(c+=2;c<t.length&&t[c].includes("|")&&t[c].trim();)L.push(Ls(t[c])),c+=1;d.push({kind:"static",node:e.jsx("div",{className:hu,"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,F)=>e.jsx("th",{className:`${uu} ${qa($[F]??null)}`,children:e.jsx("div",{className:za,children:rt(U,`${n}-th-${A}-${F}`,!0,s)})},`h-${F}`))})}),e.jsx("tbody",{children:L.map((U,F)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((a,w)=>e.jsx("td",{className:`${fu} ${qa($[w]??null)}`,children:e.jsx("div",{className:za,children:rt(U[w]??"",`${n}-td-${A}-${F}-${w}`,!0,s)})},`c-${w}`))},`r-${F}`))})]})},`${n}-table-${A}`)});continue}const y=As(m);if(y){const E=y.ordered,$=Za(m),L=y.start,A=c,U=Ki(t,c,$,E,!1);c=U.nextIndex,d.push({kind:"list",keyPrefix:`${n}-list-${A}`,ordered:E,start:E?L:void 0,renders:Vi(U.items,`${n}-list-${A}`,s,h(0)-1)});continue}const N=[m.trimStart()],I=[h(c)],D=c;for(c+=1;c<t.length&&t[c].trim()&&!Li(t[c])&&!(c+1<t.length&&t[c].includes("|")&&Ka(t[c+1]));)N.push(t[c].trimStart()),I.push(h(c)),c+=1;const B=Ii(N,`${n}-p-${D}`,s);d.push({kind:"paragraph",keyPrefix:`${n}-p-${D}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:I})}return d}function Gg(t,n){return t.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Fi(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:Yi(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(Va,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Ta=null,Sd=!1;const Ia=16,Hu=192;function qg(){return Ta||(Ta=Ms(()=>import("./mermaid.core-CW-pInWx.js").then(t=>t.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(t=>t.default??t).catch(t=>{throw Ta=null,t})),Ta}function Kg(t){Sd||(t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),Sd=!0)}function Vg(t){const n=t.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return t;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,d,c]=l;if(!Number.isFinite(d)||!Number.isFinite(c)||d<=0||c<=0)return t;const h=Math.max(Hu,Math.ceil(d)),m=Math.ceil(h/d*c);return t.replace(/<svg\b([^>]*)>/i,(g,p)=>`<svg${p.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${m}">`)}function Yg(t){const n=t?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-Ia,d=s.y-Ia,c=s.width+Ia*2,h=s.height+Ia*2,m=Math.max(Hu,Math.ceil(c)),g=Math.ceil(m/c*h);n.setAttribute("viewBox",`${l} ${d} ${c} ${h}`),n.setAttribute("width",String(m)),n.setAttribute("height",String(g)),n.removeAttribute("style")}function Xg(t){const n=t.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return Hd(`code.${s}`)??s}function zu({code:t,blockKey:n}){const{t:s}=yt(),[l,d]=o.useState(null),[c,h]=o.useState(!1),m=o.useRef(null),g=o.useContext(ku);o.useEffect(()=>{let f=!1;return d(null),h(!1),qg().then(async k=>{Kg(k);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:N}=await k.render(y,t);f||d(Vg(N))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,t]),o.useLayoutEffect(()=>{l&&Yg(m.current)},[l]);const p=o.useCallback(()=>{const f=m.current?.querySelector("svg")?.outerHTML??l;f&&g?.(f)},[g,l]);return c?e.jsx(Va,{code:t,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:f=>{f.stopPropagation(),p()},children:e.jsx("span",{ref:m,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function Va({code:t,lang:n,blockKey:s,codeStartLine:l,lineRange:d}){const c=Xg(n),[h,m]=o.useState(null);o.useEffect(()=>{if(!c||!zd(t)){m(null);return}let p=!1;return Wd().then(f=>{if(p||!f.registered(c)){p||m(null);return}try{m(Gd(f,t,c))}catch{p||m(null)}}).catch(()=>{p||m(null)}),()=>{p=!0}},[s,t,c]);const g=h??(t||" ").split(`
1644
1644
  `).map(p=>[p||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${zi} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:g.map((p,f)=>{const k=l!=null?l+f:null,y=!!(d&&k!=null&&k>=d.start&&k<=d.end);return e.jsxs("span",{"data-md-ref-start":k??void 0,"data-md-ref-end":k??void 0,"data-selected":y?"true":void 0,children:[p,f<g.length-1?`
1645
- `:null]},`${s}-line-${f}`)})})})]})}function Xi(t,n,s,l,d){t=wg(t);const c=vg(t),h=Ru(t),m=[],g={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:yg(t),headingSlugCounts:new Map,images:m,onImageOpen:l,footnotesLabel:d?.footnotes??"Footnotes",backToFootnoteLabel:d?.backToFootnote??(y=>`Back to footnote ${y}`)},p=[];let f=0;for(;f<t.length;){const y=t[f],N=y.trim();if(qa(y)||h.has(f)){f+=1;continue}if(!N){f+=1;continue}if(/^<details>\s*$/i.test(N)){const F=f;let a="Details";const w=[];for(f+=1;f<t.length&&!/^<\/details>\s*$/i.test(t[f].trim());){const O=t[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?a=O[1].trim()||a:w.push(t[f].trimStart()),f+=1}f<t.length&&(f+=1),p.push({key:`details-${F}`,startLine:F+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:rt(a,`details-${F}-summary`,!0,g)}),w.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:_u(w,`details-${F}`,g)})]})});continue}const I=Pu(y);if(I){const F=[y],a=f;for(f+=1;f<t.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(t[f]);)F.push(t[f]),f+=1;f<t.length&&!I.selfContained&&(F.push(t[f]),f+=1),p.push({key:`html-${a}`,startLine:a+1,endLine:f,content:e.jsx(Au,{html:F.join(`
1646
- `)})});continue}const _=N.match(/^(```|~~~)\s*(.*)$/);if(_){const F=[],a=_[1],w=_[2]?.trim(),O=f;for(f+=1;f<t.length&&!t[f].trim().startsWith(a);)F.push(t[f]),f+=1;f<t.length&&(f+=1),p.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:w.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(w.toLowerCase()),content:w.toLowerCase()==="mermaid"?e.jsx(Uu,{code:F.join(`
1647
- `),blockKey:`code-${O}`}):["math","latex","tex"].includes(w.toLowerCase())?e.jsx(Ls,{tex:F.join(`
1648
- `),display:!0}):j=>e.jsx(Xa,{code:F.join(`
1649
- `),lang:w,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:j})});continue}if(Ka(y)){const F=[],a=f;for(f+=0;f<t.length&&(Ka(t[f])||!t[f].trim());)F.push(t[f].trim()?Fu(t[f]):""),f+=1;p.push({key:`indented-code-${a}`,startLine:a+1,endLine:f,fineGrained:!0,content:w=>e.jsx(Xa,{code:F.join(`
1650
- `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${a}`,codeStartLine:a+1,lineRange:w})});continue}if(N.startsWith("$$")){const F=[],a=f,w=N.replace(/^\$\$\s*/,"");if(w.endsWith("$$")&&w.length>2)F.push(w.replace(/\s*\$\$$/,"")),f+=1;else{for(w&&F.push(w),f+=1;f<t.length&&!t[f].trim().endsWith("$$");)F.push(t[f]),f+=1;if(f<t.length){const O=t[f].trim().replace(/\s*\$\$$/,"");O&&F.push(O),f+=1}}p.push({key:`math-${a}`,startLine:a+1,endLine:f,content:e.jsx(Ls,{tex:F.join(`
1651
- `),display:!0})});continue}if(f+1<t.length&&N&&!Li(y)&&/^(=+|-+)\s*$/.test(t[f+1].trim())){const F=t[f+1].trim().startsWith("=")?1:2,a=`h${F}`,w=Ai(N,g),O={level:F,text:bd(N),id:w};p.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(a,{id:w,className:`scroll-mt-16 font-semibold text-foreground ${F===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:rt(N,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const B=N.match(/^(#{1,6})\s+(.+)$/);if(B){const F=B[1].length,a=ku(B[2]),w={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${F}`,j=Ai(a,g),Y={level:F,text:bd(a),id:j};p.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:Y,content:e.jsx(O,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${w[F]}`,children:rt(a,`heading-${f}`,!0,g)})}),f+=1;continue}if(xu(y)){p.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(N.startsWith(">")){const F=[],a=[],w=f;for(;f<t.length&&/^>\s?/.test(t[f].trim());)F.push(t[f].trim().replace(/^>\s?/,"")),a.push(f+1),f+=1;const O=F[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const Y=O[1].toUpperCase(),ne=O[2]?.trim(),ae=[...ne?[ne]:[],...F.slice(1)],fe=[...ne?[a[0]]:[],...a.slice(1)],G=Ii(ae,`callout-${w}`,g);p.push({key:`callout-${w}`,startLine:w+1,endLine:f,fineGrained:!0,content:J=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:Y}),ae.length>0&&e.jsx("div",{children:Fi(G.perLine,G.hardBreaks,fe,`callout-${w}`,J)})]})});continue}const j=Bg(F,`quote-${w}`,g,a);p.push({key:`quote-${w}`,startLine:w+1,endLine:f,fineGrained:!0,content:Y=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Og(j,Y)})});continue}if(f+1<t.length&&y.includes("|")&&Ya(t[f+1])){const F=As(y),a=Du(t[f+1]),w=[],O=f;for(f+=2;f<t.length&&t[f].includes("|")&&t[f].trim();)w.push(As(t[f])),f+=1;const j=F.map((ne,ae)=>rt(ne,`th-${O}-${ae}`,!0,g)),Y=w.map((ne,ae)=>F.map((fe,G)=>rt(ne[G]??"",`td-${O}-${ae}-${G}`,!0,g)));p.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:ne=>{const ae=fe=>!!(ne&&fe>=ne.start&&fe<=ne.end);return e.jsx("div",{className:uu,"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":ae(O+1)?"true":void 0,children:j.map((fe,G)=>e.jsx("th",{className:`${cu} ${Va(a[G]??null)}`,children:e.jsx("div",{className:Ga,children:fe})},`h-${G}`))})}),e.jsx("tbody",{children:Y.map((fe,G)=>{const J=O+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":J,"data-md-ref-start":J,"data-md-ref-end":J,"data-selected":ae(J)?"true":void 0,children:F.map((M,D)=>e.jsx("td",{className:`${du} ${Va(a[D]??null)}`,children:e.jsx("div",{className:Ga,children:fe[D]})},`c-${D}`))},`r-${G}`)})})]})})}});continue}const E=Ps(y);if(E){const F=E.ordered,a=to(y),w=E.start,O=f,j=Ki(t,f,a,F,!0,h);f=j.nextIndex;const Y=F?"ol":"ul",ne=Vi(j.items,`list-${O}`,g);p.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:ae=>e.jsx(Y,{start:F?w:void 0,className:`${F?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:Yi(ne,ae)})});continue}const $=[y.trimStart()],L=[f+1],A=f;for(f+=1;f<t.length&&t[f].trim()&&!Li(t[f])&&!(f+1<t.length&&t[f].includes("|")&&Ya(t[f+1]));){if(qa(t[f])||h.has(f)){f+=1;continue}$.push(t[f].trimStart()),L.push(f+1),f+=1}const U=Ii($,`p-${A}`,g);p.push({key:`p-${A}`,startLine:A+1,endLine:f,fineGrained:!0,content:F=>e.jsx("p",{className:"text-muted-foreground",children:Fi(U.perLine,U.hardBreaks,L,`p-${A}`,F)})})}const k=Dg(g);return k&&p.push({key:"footnotes",startLine:t.length,endLine:t.length,content:k}),{blocks:p,images:m}}function qg(t,n,s){return Xi(t,n,s).blocks}function Hu(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function zu(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Kg({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const d=Mu(t);return e.jsx(rf,{src:d,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function Wu({images:t,index:n,onChange:s,onClose:l}){const{t:d}=pt(),c=t[n],h=t.length>1,m=o.useRef(null),g=o.useRef(null),p=o.useRef(null),f=o.useRef(0),[k,y]=o.useState(!1),[N,I]=o.useState(0),[_,B]=o.useState(!1),E=o.useCallback(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),$=o.useCallback(()=>{k||Date.now()<f.current||(E(),p.current=window.setTimeout(()=>{p.current=null,l()},450))},[E,k,l]),L=o.useCallback(a=>{if(t.length===0)return;const w=(a+t.length)%t.length;m.current?.slideTo(w),s(w)},[t.length,s]),A=o.useCallback(()=>L(n-1),[L,n]),U=o.useCallback(()=>L(n+1),[L,n]);if(o.useEffect(()=>{E(),I(0),B(!1),y(!1)},[E,n]),o.useEffect(()=>{const a=m.current;a&&(a.allowTouchMove=h&&!k)},[h,k]),o.useEffect(()=>{const a=m.current;!a||a.activeIndex===n||a.slideTo(n,0)},[n]),o.useEffect(()=>E,[E]),o.useEffect(()=>{const a=w=>{if(w.key==="Escape"){w.preventDefault(),l();return}h&&(w.key==="ArrowLeft"?(w.preventDefault(),A()):w.key==="ArrowRight"&&(w.preventDefault(),U()))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[h,U,A,l]),Td({onDrag:({movement:[a,w],pinching:O})=>{O||k||Math.abs(w)<Math.abs(a)*1.15&&N===0||(B(!0),Math.abs(w)>8&&(f.current=Date.now()+300),I(Math.max(0,w)))},onDragEnd:({movement:[a,w],velocity:[,O],pinching:j,canceled:Y})=>{if(B(!1),j||Y||k||Math.abs(w)<Math.abs(a)*1.15){I(0);return}if(Math.abs(w)>8&&(f.current=Date.now()+300),Bu(w,O)){l();return}I(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const F=c.title||c.alt||(c.kind==="mermaid"?d("rightSidebar.mermaidDiagram"):d("rightSidebar.image"));return typeof document>"u"?null:Gr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:F}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:A,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":d("rightSidebar.previousImage"),title:d("common.previous"),children:e.jsx(Ns,{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":d("rightSidebar.nextImage"),title:d("common.next"),children:e.jsx(jh,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":d("rightSidebar.closeImagePreview"),title:d("common.close"),children:e.jsx(Ut,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:$,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${N}px, 0) scale(${Math.max(.86,1-N/900)})`,opacity:Math.max(.35,1-N/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Id,{onSwiper:a=>{m.current=a,a.allowTouchMove=h&&!k},onSlideChange:a=>{a.activeIndex!==n&&s(a.activeIndex)},onSliderMove:()=>{E(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:t.map((a,w)=>e.jsx(vi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:a.kind==="image"?e.jsx(Kg,{src:a.src,alt:a.alt||a.title||d("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(cb,{svg:a.svg,title:a.title||a.alt||d("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${a.kind}-${w}-${a.alt}`))})})})]})]}),document.body)}function Gu({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:d,onLineRangeDrag:c,scrollTop:h,outlineOpen:m,outlineCloseSignal:g,onOutlineOpen:p,onOutlineClose:f,lightboxOpen:k,lightboxCloseSignal:y,onLightboxOpen:N,onLightboxClose:I,onLocalLinkOpen:_}){const{t:B}=pt(),[E,$]=o.useState(null),[L,A]=o.useState(null),[U,F]=o.useState(1),[a,w]=o.useState(null),O=o.useRef(null),j=o.useRef(null),{blocks:Y,images:ne}=o.useMemo(()=>Xi(t.split(`
1652
- `),n,s,S=>{A(null),$(S),N?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:S=>B("rightSidebar.backToFootnote",{index:S})}),[t,n,s,N,B]),ae=o.useMemo(()=>L?[...ne,L]:ne,[ne,L]),fe=o.useCallback(S=>{A({kind:"mermaid",svg:S,alt:"Mermaid diagram",title:"Mermaid diagram"}),$(ne.length),N?.()},[ne.length,N]);o.useEffect(()=>{$(null),A(null)},[t,n]),o.useEffect(()=>{$(null),A(null)},[y]),o.useEffect(()=>{k||($(null),A(null))},[k]),o.useEffect(()=>{F(1)},[t,n]),o.useLayoutEffect(()=>{const S=O.current;if(!S||Y.length===0)return;const V=Array.from(S.querySelectorAll("[data-markdown-preview-block-start]"));let we=1;const be=28;for(const Oe of V)if(Oe.offsetTop-h<=be)we=Number(Oe.dataset.markdownPreviewBlockStart)||we;else break;F(Oe=>Oe===we?Oe:we)},[Y,h]);const G=o.useMemo(()=>Hu(Y,U),[U,Y]),J=o.useMemo(()=>zu(Y),[Y]),M=`${n??""}
1653
- ${t}`,D=o.useRef(M),K=o.useRef(null),re=o.useRef(null),oe=o.useRef(!1);o.useEffect(()=>{D.current!==M&&(D.current=M,f?.())},[f,M]),o.useEffect(()=>{g!==void 0&&w(null)},[g]),o.useLayoutEffect(()=>{if(!m){w(null);return}const S=()=>{const V=j.current;if(!V)return;const we=V.getBoundingClientRect(),be=window.innerWidth;w({top:we.bottom+6,right:Math.max(8,be-we.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[m,h,G]);const he=o.useCallback(S=>{const V=O.current,we=V?.closest("[data-markdown-preview-scroller]"),be=V?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!we||!be)return;const Oe=we.getBoundingClientRect(),ce=be.getBoundingClientRect(),Ae=V?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,W=ce.top-Oe.top+we.scrollTop;we.scrollTo({top:Math.max(0,W-Ae-8),behavior:"smooth"}),F(S.startLine),f?.()},[f]),me=o.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||hi(S.target)||(K.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),Re=o.useCallback((S,V,we)=>{const be=K.current;if(K.current=null,!be||be.pointerId!==S.pointerId)return;const Oe=Math.abs(S.clientX-be.startX),ce=Math.abs(S.clientY-be.startY);if(Oe>8||ce>8)return;const Je=S.target;if(hi(Je)||Di())return;const Ae=$d(Je,V,we);d(S,Ae.start,Ae.end)},[d]),C=o.useCallback(S=>{K.current?.pointerId===S.pointerId&&(K.current=null)},[]),Z=o.useCallback((S,V)=>{const we=O.current;if(!we||typeof document.elementFromPoint!="function")return null;const be=document.elementFromPoint(S,V);if(!(be instanceof HTMLElement)||!we.contains(be))return null;const Oe=be.closest("[data-md-ref-start]");if(Oe){const Se=Number(Oe.dataset.mdRefStart);if(Number.isFinite(Se)&&Se>0)return Se}const ce=be.closest("[data-markdown-preview-block-start]");if(!ce)return null;const Je=Number(ce.dataset.markdownPreviewBlockStart),Ae=Y.find(Se=>Se.startLine===Je);if(!Ae)return Number.isFinite(Je)&&Je>0?Je:null;if(Ae.endLine<=Ae.startLine)return Ae.startLine;const W=ce.getBoundingClientRect(),q=W.height>0?Math.min(1,Math.max(0,(V-W.top)/W.height)):0;return Math.round(Ae.startLine+q*(Ae.endLine-Ae.startLine))},[Y]),de=o.useCallback(S=>{if(!c||S.pointerType==="mouse"&&S.button!==0)return;const V=Z(S.clientX+24,S.clientY);if(V!=null){re.current={pointerId:S.pointerId,anchorLine:V,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[c,Z]),Le=o.useCallback(S=>{const V=re.current;if(!V||V.pointerId!==S.pointerId||!c)return;const we=Z(S.clientX+16,S.clientY);we!=null&&(!V.moved&&we===V.anchorLine||(V.moved=!0,oe.current=!0,c(S,Math.min(V.anchorLine,we),Math.max(V.anchorLine,we),"move")))},[c,Z]),We=o.useCallback(S=>{const V=re.current;if(re.current=null,!V||V.pointerId!==S.pointerId||!c||!V.moved)return;const we=Z(S.clientX+16,S.clientY)??V.anchorLine;c(S,Math.min(V.anchorLine,we),Math.max(V.anchorLine,we),"end")},[c,Z]),_e=o.useCallback(S=>{re.current?.pointerId===S.pointerId&&(re.current=null)},[]),le={onPointerDown:de,onPointerMove:Le,onPointerUp:We,onPointerCancel:_e},se=()=>oe.current?(oe.current=!1,!0):!1;return Y.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:B("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:S=>{const V=S.target instanceof Element?S.target.closest("a[href]"):null;if(!V||!_)return;const we=V.getAttribute("href");if(!we)return;const be=Wi(we,n,s);be&&(S.preventDefault(),_(be))},children:[G.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:G.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:G[G.length-1].text}),J.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?f?.():p?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(Fd,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&Gr.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:a?{top:`${a.top}px`,right:`${a.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:J.map(S=>{const V=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>he(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${V?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${V?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children: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(Ut,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:J.map(S=>{const V=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>he(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${V?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${V?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(yu.Provider,{value:fe,children:Y.map(S=>{const V=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),we=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),be=S.kind==="table"?!1:S.fineGrained?we:V,Oe=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let ce=null;if(S.kind!=="table"&&S.fineGrained&&V&&!we&&l){const q=S.endLine-S.startLine+1,Se=Math.max(l.start,S.startLine),Ce=Math.min(l.end,S.endLine),ct=(Se-S.startLine)/q,Qe=(Ce-Se+1)/q;ce=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) * ${ct})`,height:`calc((100% - 0.5rem) * ${Qe})`}})}const Je=typeof S.content=="function"?S.content(l):S.content,Ae=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,W=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:di(be),"aria-hidden":"true",...le,children:[e.jsx("span",{className:ui(be)}),ce]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:Je})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${be?"bg-primary/10":""}`,title:`Line ${Ae}`,"aria-label":`Line ${Ae}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:di(Oe,"self"),onClick:q=>{q.preventDefault(),!se()&&d(q,S.startLine,S.endLine)},title:`Reference table lines ${Ae}`,"aria-label":`Reference table lines ${Ae}`,...le,children:e.jsx("span",{className:ui(Oe,"self")})}):e.jsxs("span",{className:di(be,"none"),"aria-hidden":"true",...le,children:[e.jsx("span",{className:ui(be,"none")}),ce]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:me,onPointerUp:q=>Re(q,S.startLine,S.endLine),onPointerCancel:C,onKeyDown:q=>{q.key!=="Enter"&&q.key!==" "||(q.preventDefault(),d(q,S.startLine,S.endLine))},title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:Je})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:q=>{const Se=q.target;if(hi(Se)||Di()||se())return;const Ce=$d(Se,S.startLine,S.endLine);d(q,Ce.start,Ce.end)},onKeyDown:q=>{q.key!=="Enter"&&q.key!==" "||(q.preventDefault(),d(q,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${be?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ae}`,"aria-label":`Reference line ${Ae}`,children:W},S.key)})})})]}),k&&E!==null&&ae[E]&&e.jsx(Wu,{images:ae,index:E,onChange:$,onClose:()=>{$(null),A(null),I?.()}})]})}function Wn({label:t,value:n,options:s,placeholder:l,searchPlaceholder:d,emptyText:c,disabled:h,onChange:m}){const{t:g}=pt(),[p,f]=o.useState(!1),[k,y]=o.useState(""),[N,I]=o.useState(null),_=o.useRef(null),B=o.useRef(null),E=k.trim().toLowerCase(),$=o.useMemo(()=>E?s.filter(a=>`${a.label} ${a.meta??""}`.toLowerCase().includes(E)):s,[E,s]),L=s.find(a=>a.value===n),A=()=>{const a=k.trim();a&&(m(a),f(!1),y(""))},U=o.useCallback(()=>{const a=_.current?.getBoundingClientRect();if(!a)return!1;const w=12,O=Math.max(220,Math.min(a.width,window.innerWidth-w*2)),j=Math.min(Math.max(w,a.left),window.innerWidth-O-w),Y=window.innerHeight-a.bottom-w,ne=a.top-w,ae=Y>=180||Y>=ne,fe=Math.max(96,(ae?Y:ne)-4),G=Math.min(320,fe);return I({left:j,top:ae?a.bottom+4:Math.max(w,a.top-G-4),width:O,maxHeight:G}),!0},[]),F=()=>{U(),f(!0)};return o.useEffect(()=>{if(!p)return;let a=0;const w=()=>{a||(a=window.requestAnimationFrame(()=>{a=0,U()}))},O=j=>{const Y=j.target;Y instanceof Node&&(_.current?.contains(Y)||B.current?.contains(Y)||(f(!1),y("")))};return window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),document.addEventListener("pointerdown",O,!0),()=>{a&&window.cancelAnimationFrame(a),window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0),document.removeEventListener("pointerdown",O,!0)}},[p,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),p){f(!1);return}F()}},className:"group flex w-full items-center justify-between gap-2 rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-left transition hover:bg-surface-elevated disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("span",{className:`block truncate text-[12px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:L?.label??(n||l)})]}),e.jsx(Ms,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${p?"rotate-180":""}`})]}),p&&!h&&typeof document<"u"&&Gr.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:a=>a.stopPropagation(),style:{left:N?.left??12,top:N?.top??12,width:N?.width??260,maxHeight:N?.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:k,onChange:a=>y(a.target.value),onKeyDown:a=>{if(a.key==="Escape"){a.preventDefault(),f(!1),y("");return}a.key==="Enter"&&(a.preventDefault(),A())},onBlur:()=>{k.trim()&&$.length===0&&A()},placeholder:d,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(N?.maxHeight??320)-46)},children:[k.trim()&&!s.some(a=>a.value===k.trim())&&e.jsxs("button",{type:"button",onMouseDown:a=>a.preventDefault(),onClick:A,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),$.length>0?$.map(a=>e.jsxs("button",{type:"button",onClick:()=>{m(a.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 ${a.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:a.label}),a.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:a.meta})]},a.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function kd({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:d,selectedRoots:c,onToggleRepo:h,onGenerate:m,onSecondaryAction:g,disabled:p,generateDisabled:f,secondaryDisabled:k,inserted:y,buttonLabel:N,insertedLabel:I,title:_,ariaLabel:B,scopeTitle:E,scopeLabel:$,allLabel:L,generateLabel:A,secondaryLabel:U,secondaryTitle:F,secondaryLoading:a,loading:w,error:O,statusTitle:j,extraContent:Y,renderRepoExtra:ne}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):f||m()},disabled:p,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:j??(s?`${E}: ${$}`:_),children:[w?e.jsx(at,{size:13,className:"animate-spin"}):e.jsx(Es,{size:13}),e.jsx("span",{children:y?I:N}),s&&e.jsx(Ms,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&Gr.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:ae=>ae.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(Ut,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[Y,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:L}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),d.map(ae=>{const fe=c.includes(ae.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${fe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(ae.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${fe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:ae.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:ae.label}),ae.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:ae.branch})]}),fe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),ne&&(l||fe)&&e.jsx("div",{className:"px-2 pb-2",children:ne(ae)})]},ae.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{k||(n(!1),g())},disabled:k,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:F,children:[a?e.jsx(at,{size:12,className:"animate-spin"}):e.jsx(zd,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),m())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Es,{size:12}),A]})]})]})}),document.body)]})}function Vg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function qu(){return tt(Ui,Vg)??{}}function Yg(t,n){const s=qu(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,d],[,c])=>c.updatedAt-d.updatedAt).slice(0,Wp);Ss(Ui,Object.fromEntries(l),qp)}function Xg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function Jg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!Xg(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Ji(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Ku(){return tt(Hi,Jg)??{}}function Sd(t,n){const s=Ji(t,n);return s?Ku()[s]??null:null}function ii(t,n,s){const l=Ji(t,n);if(!l)return;const d=Ku(),c=d[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...d,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,m],[,g])=>g.updatedAt-m.updatedAt).slice(0,Gp);Ss(Hi,Object.fromEntries(h),Kp)}function li({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function vs({slow:t}){const{t:n}=pt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:[e.jsx(at,{size:20,className:"mx-auto mb-2 animate-spin text-muted-foreground/80"}),e.jsx("div",{children:n("rightSidebar.loadingGitChanges")}),t&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground/75",children:n("rightSidebar.loadingGitChangesSlow")})]})}function Da({message:t,onRetry:n}){const{t:s}=pt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function za(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function mt(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function ci(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function _i(t,n,s){const l=Math.min(n,s),d=Math.max(n,s);return t?.start===l&&t.end===d?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,d)}:{start:l,end:d}}function Qg(t,n,s){return _i(t,n,s)}function di(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function ui(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function jd(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function Vu(t){const n=new Map;for(const s of t)n.set(Qi(s),s);return n}function Yu(t,n){const s=new Map(t);for(const l of n)s.set(Qi(l),l);return s}function Rd(t,n){let s=0;for(const l of t){const d=lt(l,n);d&&n&&d!==n&&(s+=1)}return s}function Zg(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function eb(t,n){return Array.from(Yu(Vu(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function tb(t,n){const s=t.relativeRoot==="."?mt(n??t.root)||t.name||t.root:t.relativeRoot||t.name||mt(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:Zg(t.files)}}function Xu(t,n){const s=mt(n??"")||n||"";return t.map(l=>tb(l,n)).sort((l,d)=>s&&l.label===s?-1:s&&d.label===s?1:l.label.localeCompare(d.label))}function Ju(t,n,s,l,d){const c=hu(s),h=c.find(_=>_.root===l)??c[0]??null,m=n.find(_=>_.root===l)??null,g=m?.relativeRoot??h?.relativeRoot??".",p=m?.name??h?.name??(mt(l)||l),f=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:g,repoName:p})),k=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:g,name:p,depth:0,nested:!!(d&&l!==d),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:g,name:p,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(d&&l!==d),available:h?.available??s.available,files:f,context:k?{...k,root:l,changedFiles:f.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},N=m?n.map(_=>_.root===l?y:_):[...n,y];return{files:Array.from(t).filter(_=>lt(_,d)!==l).concat(f),repositories:N,repoFilters:Xu(N,d)}}function lt(t,n){return t.repoRoot??n}function Qi(t){return`${t.repoRoot??""}\0${t.path}`}function ht(t){return t.absolutePath||t.path}function fi(t){return Qi(t)}function rb(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function Cd(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function Nd(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Gn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function ys(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function dr(t){return t instanceof DOMException&&t.name==="AbortError"}function nb(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Md(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function Di(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function hi(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function $d(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,d=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(d)&&d>0&&Number.isFinite(c)&&c>0?{start:Math.min(d,c),end:Math.max(d,c)}:{start:n,end:s}}function sb({actions:t,running:n,completed:s}){const{t:l}=pt(),[d,c]=o.useState(!1),h=o.useRef(null),m=t.find(p=>n?.action===p.key),g=t.find(p=>s?.action===p.key);return t.length===0?null:(o.useEffect(()=>{if(!d)return;const p=k=>{const y=k.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=k=>{k.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",p),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",p),document.removeEventListener("keydown",f)}},[d]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),c(f=>!f)},disabled:t.every(p=>p.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50 ${d?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??g?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(at,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(bi,{size:14})}),d&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(p=>{const f=n?.action===p.key,k=s?.action===p.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),p.onClick(),c(!1)},disabled:p.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${k?"bg-accent/10 text-accent":p.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(at,{size:13,className:"animate-spin"}):k?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:p.label})]},p.key)})})]}))}function ab(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function Qu(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&ab(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Kn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const mi=new WeakMap;function Ja(t){const n=mi.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),mi.delete(t)},1700);mi.set(t,s)}function ob(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let d=null;for(const m of l){if(!Kn(m))continue;const g=m.querySelector(s);if(g&&Kn(g)){d=g;break}}if(d??=Array.from(document.querySelectorAll(s)).find(Kn)??null,!d)return;const c=Qu(d);if(!c){d.scrollIntoView({block:"start",behavior:"smooth"}),Ja(d);return}const h=d.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),Ja(d)}function bn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,d=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,c=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&d?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null&&d?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(I=>!!I),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const I of m)if(Kn(I)){for(const _ of h){const B=I.querySelector(_);if(B&&Kn(B)){g=B;break}}if(g)break}if(g??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Kn)??null,!g){ob(t.filePath);return}const p=Qu(g);if(!p){g.scrollIntoView({block:"center",behavior:"smooth"}),Ja(g);return}const f=g.getBoundingClientRect(),k=p.getBoundingClientRect(),N=f.top-k.top+p.scrollTop-Math.max(24,(p.clientHeight-f.height)/2);p.scrollTo({top:Math.max(0,N),behavior:"instant"}),Ja(g)}const Zu=1,ef=8;function ib(t){return Math.min(ef,Math.max(Zu,t))}function tf({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const d=o.useRef(null),[c,h]=o.useState({scale:1,x:0,y:0}),[m,g]=o.useState(!1),p=o.useRef(null),f=o.useRef(new Set),k=o.useRef(!1),y=o.useRef(null),N=o.useRef(0),I=o.useRef(c);I.current=c,o.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const _=o.useCallback((L,A,U)=>{const F=d.current;if(!F)return{x:A,y:U};const a=F.firstElementChild instanceof HTMLElement?F.firstElementChild:null,w=a?.clientWidth||F.clientWidth,O=a?.clientHeight||F.clientHeight,j=Math.max(0,(w*L-F.clientWidth)/2),Y=Math.max(0,(O*L-F.clientHeight)/2);return{x:Math.min(j,Math.max(-j,A)),y:Math.min(Y,Math.max(-Y,U))}},[]),B=o.useCallback((L,A,U)=>{h(F=>{const a=ib(L),w=d.current;if(!w||a===1)return{scale:a,x:0,y:0};const O=w.getBoundingClientRect(),j=(A??O.left+O.width/2)-O.left-O.width/2,Y=(U??O.top+O.height/2)-O.top-O.height/2,ne=a/F.scale,ae=j-(j-F.x)*ne,fe=Y-(Y-F.y)*ne;return{scale:a,..._(a,ae,fe)}})},[_]),E=o.useCallback((L,A)=>{g(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,L,A),window.setTimeout(()=>g(!1),220)},[B]);o.useEffect(()=>{const L=d.current;if(!L)return;const A=a=>{if(a.pointerType==="mouse"&&a.button!==0)return;const w=f.current.size===0;if(f.current.add(a.pointerId),w){const O=Date.now(),j=y.current;if(j&&O-j.time<350&&Math.hypot(a.clientX-j.x,a.clientY-j.y)<24){y.current=null,N.current=O,s?.(),E(a.clientX,a.clientY);return}}if(f.current.size>1){k.current=!0,p.current=null;return}if(!(I.current.scale<=1)){a.preventDefault(),p.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{L.setPointerCapture?.(a.pointerId)}catch{}g(!1)}},U=a=>{const w=p.current;if(!w||w.pointerId!==a.pointerId)return;const O=a.clientX-w.startX,j=a.clientY-w.startY;if(!w.moved){if(Math.hypot(O,j)<6)return;w.moved=!0}a.stopPropagation(),a.preventDefault(),h(Y=>({...Y,..._(Y.scale,w.originX+O,w.originY+j)}))},F=a=>{const w=p.current,O=w?.pointerId===a.pointerId&&w.moved;if(w?.pointerId===a.pointerId){w.moved&&a.stopPropagation(),p.current=null;try{L.releasePointerCapture?.(a.pointerId)}catch{}}f.current.delete(a.pointerId)&&f.current.size===0&&(!k.current&&!O&&(y.current={time:Date.now(),x:a.clientX,y:a.clientY}),k.current=!1)};return L.addEventListener("pointerdown",A,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",F,{capture:!0}),window.addEventListener("pointercancel",F,{capture:!0}),()=>{L.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",F,{capture:!0}),window.removeEventListener("pointercancel",F,{capture:!0})}},[_,s,E]),Td({onPinch:({offset:[L],origin:[A,U]})=>{g(!1),B(L,A,U)},onWheel:({event:L,delta:[A,U],ctrlKey:F})=>{if(F){L.preventDefault(),L.stopPropagation(),g(!1),B(I.current.scale*(1-U*.01),L.clientX,L.clientY);return}I.current.scale<=1||(L.preventDefault(),L.stopPropagation(),g(!1),h(a=>({...a,..._(a.scale,a.x-A,a.y-U)})))}},{target:d,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Zu,max:ef},from:()=>[I.current.scale,0],rubberband:!0}});const $=c.scale>1;return o.useEffect(()=>{n?.($)},[n,$]),e.jsx("div",{ref:d,"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:L=>{L.stopPropagation(),!(Date.now()-N.current<500)&&(s?.(),E(L.clientX,L.clientY))},children:l({scale:c.scale,zoomed:$,animateTransform:m,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0)`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function rf({src:t,alt:n,vector:s,onLoad:l,onError:d,onZoomChange:c,onDoubleTap:h}){const m=Qa(t,d),[g,p]=o.useState(null),f=s??eo(t);return o.useEffect(()=>{p(null)},[t]),e.jsx(tf,{resetKey:t,onZoomChange:c,onDoubleTap:h,children:({transformStyle:k,vectorTransformStyle:y,scale:N,animateTransform:I})=>{const _=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*N,height:g.height*N,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:g?{...k,width:g.width,height:g.height}:f?y:k,onLoad:B=>{const E=B.currentTarget,$=E.parentElement;if($&&E.naturalWidth>0&&E.naturalHeight>0){const L=Math.max(1,$.clientWidth-2),A=Math.max(1,$.clientHeight-2),U=Math.min(L/E.naturalWidth,A/E.naturalHeight),F=f?U:Math.min(U,1);p({width:Math.max(1,Math.round(E.naturalWidth*F)),height:Math.max(1,Math.round(E.naturalHeight*F))})}l(B)},onError:d});return!f||!g?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:_})}})}function lb({svg:t,title:n,scale:s,vectorTransformStyle:l}){const d=o.useRef(null);return o.useLayoutEffect(()=>{const c=d.current,h=c?.querySelector("svg");if(!c||!h)return;const m=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let k=f[2],y=f[3];if((!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)&&(k=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)return;const N=Math.max(1,c.clientWidth-24),I=Math.max(1,c.clientHeight-24),_=Math.min(N/k,I/y,1);h.style.width=`${Math.max(1,Math.floor(k*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};m();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return g?.observe(c),()=>g?.disconnect()},[s,t,l]),e.jsx("div",{ref:d,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function cb({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(tf,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:d,scale:c})=>e.jsx(lb,{svg:t,title:n,scale:c,vectorTransformStyle:d})})}let db=0,ub=0,fb=0,hb=0,mb=0;function pi(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function et(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++ub,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Ba(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++hb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function pb(){return`diff-ui-${Date.now().toString(36)}-${(++mb).toString(36)}`}function gb(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function bb(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Bi({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:d,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:m,isMobile:g,markdownOutlineOpen:p,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:k,onCloseMarkdownOutline:y,markdownImageLightboxOpen:N,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:$,insertedReferenceKey:L,copiedReferenceKey:A,scrollToLine:U,onScrollToLineHandled:F}){const{t:a}=pt(),w=te(P=>P.rootPath),O=te(P=>P.selectFile),[j,Y]=o.useState({kind:"idle"}),[ne,ae]=o.useState("schematic"),[fe,G]=o.useState(null),J=o.useRef(null),[M,D]=o.useState(null),K=o.useRef(new Map),re=o.useRef(null),[oe,he]=o.useState(null),[me,Re]=o.useState(()=>dd()),[C,Z]=o.useState(()=>Qc(w,n)),de=o.useRef(null),[Le,We]=o.useState(!1),[_e,le]=o.useState(null),[se,S]=o.useState(0),[V,we]=o.useState([]),[be,Oe]=o.useState(null),ce=o.useRef(null),Je=o.useRef(n),[Ae,W]=o.useState(null),[q,Se]=o.useState({status:"idle"}),[Ce,ct]=o.useState(!1),[Qe,xn]=o.useState(""),[gt,ur]=o.useState([]),[Yt,vn]=o.useState(0),wt=o.useRef(null),Ht=Gd(c),qr=Ji(w,n);o.useEffect(()=>{if(Je.current===n)return;Je.current=n;const P=n&&w&&!n.startsWith("/")?`${w}/${n}`:n;if(ce.current===P){ce.current=null;return}ce.current=null,we([]),Oe(null),ct(!1),xn("")},[n,w]);const fr=n?w&&!n.startsWith("/")?`${w}/${n}`:n:null,Xt=te(P=>fr?(P.fileChangeVersions.get(fr)??0)+P.fileWatchEpoch:P.fileWatchEpoch),Pt=o.useRef(null),hr=o.useRef(null),[zt,Ts]=o.useState(0),yn=o.useCallback(()=>Ts(P=>P+1),[]);o.useEffect(()=>{const P=J.current;return J.current=null,G(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const z=J.current;J.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[fr,Xt,zt]),o.useEffect(()=>{if(!n){Pt.current=null,Y({kind:"idle"});return}const P=w&&!n.startsWith("/")?`${w}/${n}`:n,z=new AbortController,ie=++db,xe=`right-sidebar-file-preview:${ie}`,Ue=performance.now();let $e=!1;const He=(Q,Be={})=>{$e||($e=!0,pi("end",{loadingId:ie,reason:Q,durationMs:Math.round(performance.now()-Ue),filePath:n,fullPath:P,rootPath:w,...Be}))};let De=null;const nt=fh(P),ot=nt?P.toLowerCase().endsWith(".kicad_pcb")?ne==="schematic"?"pcb-front":ne:"schematic":ne,er=!nt&&Oi(P),vr=!nt&&!er&&hh(P),Rn=!nt&&!er&&!vr&&Ed(P),Zr=xs(P),Zn=gs(P),tr=nt?"eda":er?"image":vr?"model3d":Rn?"video":"text",rr=Pt.current!==P;if(Pt.current=P,rr){pi("start",{loadingId:ie,filePath:n,fullPath:P,rootPath:w,mode:tr,externalVersion:Xt}),Se({status:"idle"}),Y({kind:"loading",mode:tr}),hr.current=null;const Q=Sd(w,n);$(Q?.lineRange??null),Re(Zr?dd():"source"),Z(Zn?Qc(w,n):"source"),nt&&ae(mh(P))}rr||Y(Q=>Q.kind==="error"?{kind:"loading",mode:tr}:Q);const Cn=window.setTimeout(()=>{$e||z.signal.aborted||pi("still_active",{loadingId:ie,filePath:n,fullPath:P,rootPath:w,mode:tr,durationMs:Math.round(performance.now()-Ue),isPathChange:rr})},3e3),en=window.setTimeout(()=>{if($e||z.signal.aborted)return;const Q=nt?a("rightSidebar.edaTimeout"):vr?a("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(Q,"TimeoutError")),Y({kind:"error",message:Q}),He("stuck_timeout",{error:Q})},nt?ph+5e3:vr?gh+5e3:bh(P)?35e3:Zp);if(nt){const Q=ot==="pcb-3d"?J.current:null;Q?(Y(Q),He("eda_3d_client_cache_hit",{bytes:Q.meta.size,view:Q.view,mimeType:Q.meta.mimeType})):xh(P,ot,z.signal,"view_file",xe).then(Be=>{if(z.signal.aborted)return;De=URL.createObjectURL(Be.blob);const nr={kind:"eda",sourcePath:Be.path||P,objectUrl:De,view:Be.view,meta:{size:Be.size,mimeType:Be.mimeType,modified:Be.modified}};if(Be.view==="pcb-3d"){const sr=J.current;sr&&sr.objectUrl!==De&&URL.revokeObjectURL(sr.objectUrl),J.current=nr,G(nr),De=null}Y(nr),He("eda_loaded",{bytes:Be.size,view:Be.view,mimeType:Be.mimeType})}).catch(Be=>{z.signal.aborted||(Y({kind:"error",message:Be instanceof Error&&/timed out/i.test(Be.message)?a("rightSidebar.edaTimeout"):Be instanceof Error?Be.message:a("rightSidebar.edaLoadFailed")}),He("error",{error:Be instanceof Error?Be.message:String(Be)}))})}else if(er)vh(P,z.signal,"view_file",xe).then(Q=>{De=URL.createObjectURL(Q.blob),Y({kind:"image",objectUrl:De,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),He("image_loaded",{bytes:Q.size,mimeType:Q.mimeType})}).catch(Q=>{z.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:a("rightSidebar.imageLoadFailed")}),He("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(vr)yh(P,z.signal,"view_file",xe).then(Q=>{z.signal.aborted||(De=URL.createObjectURL(Q.blob),Y({kind:"model3d",sourcePath:Q.path||P,objectUrl:De,ext:Q.ext,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),He("model3d_loaded",{bytes:Q.size,ext:Q.ext}))}).catch(Q=>{z.signal.aborted||(Y({kind:"error",message:Q instanceof Error&&(Q.name==="TimeoutError"||/timed out/i.test(Q.message))?a("rightSidebar.model3dTimeout"):Q instanceof Error?Q.message:a("rightSidebar.model3dLoadFailed")}),He("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(Rn){const Q=wh(P)??"",Be=Ld(P);Y(nr=>nr.kind==="video"&&nr.url===Be?nr:{kind:"video",url:Be,meta:{size:null,mimeType:Q,modified:null}}),He("video_ready",{mimeType:Q})}else Fc(P,z.signal,"view_file",xe).then(Q=>{if(!z.signal.aborted){if(Q.binary){Y({kind:"binary"});return}Y({kind:"text",content:Q.content,sourcePath:Q.path||P,meta:{size:Q.size,truncated:Q.truncated}}),He("text_loaded",{bytes:Q.size,truncated:!!Q.truncated})}}).catch(Q=>{z.signal.aborted||(Y({kind:"error",message:Q instanceof Error?Q.message:"Failed to read file"}),He("error",{error:Q instanceof Error?Q.message:String(Q)}))});return()=>{z.abort(),xt(xe),window.clearTimeout(Cn),window.clearTimeout(en),De&&URL.revokeObjectURL(De),He("cleanup")}},[n,w,Xt,zt,$,a,ne]),o.useEffect(()=>{if(j.kind!=="model3d"||!n){D(null);return}let P=!1;const z=n.lastIndexOf("/"),ie=z>=0?n.slice(z+1):n,xe=z>=0?n.slice(0,z):"",Ue=xe.lastIndexOf("/"),$e=Ue>=0?xe.slice(0,Ue):"",He=ie.replace(/\.(stl|glb|gltf)$/i,""),De=`${$e?`${$e}/`:""}features/${He}.json`;return Fc(De).then(nt=>{if(!P)try{const ot=JSON.parse(nt.content);D(ot.version===1&&Array.isArray(ot.features)&&ot.features.length>0?ot.features:null)}catch{D(null)}}).catch(()=>{P||D(null)}),()=>{P=!0}},[j,n]),o.useEffect(()=>{if(j.kind!=="text"){W(null);return}const P=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,z=Od(P),ie=j.content,xe=xs(P??"")&&me==="preview",Ue=gs(P??"")&&C==="preview";if(!z||xe||Ue||!Ud(ie)){W(null);return}let $e=!1;const He=De=>{if($e||!De.registered(z)){$e||W(null);return}try{W(Wd(De,ie,z))}catch{W(null)}};return _e?He(_e):(W(null),Hd().then(De=>{$e||(le(De),He(De))}).catch(()=>{})),()=>{$e=!0}},[j,_e,n,w,me,C]),o.useLayoutEffect(()=>{if(!qr||j.kind!=="text")return;const P=`${qr}:${me}:${C}`;if(hr.current===P)return;const z=Sd(w,n);if(hr.current=P,!z)return;const ie=requestAnimationFrame(()=>{const xe=re.current;if(!xe)return;const Ue=me==="preview"?z.markdownTop??z.top:z.top;xe.scrollTo({top:Math.max(0,Ue??0),left:Math.max(0,z.left??0)}),S(me==="preview"?Math.max(0,Ue??0):0)});return()=>cancelAnimationFrame(ie)},[n,me,C,j.kind,qr,w]),o.useEffect(()=>{qr&&ii(w,n,{lineRange:E})},[n,E,qr,w]),o.useEffect(()=>{if(U==null||j.kind!=="text")return;he(null),$({start:U,end:U});const P=U,z=requestAnimationFrame(()=>{const ie=K.current.get(P);ie&&ie.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(z)},[U,j,$,F]);const Vn=o.useCallback(P=>{const z=re.current;if(!z)return!1;const ie=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),xe=z.querySelector(`#${ie}`);return xe?(xe.scrollIntoView({block:"start"}),!0):!1},[]);o.useEffect(()=>{const P=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,z=j.kind==="text"&&xs(P??"")&&me==="preview";if(!be||!z)return;const ie=requestAnimationFrame(()=>{Vn(be)&&Oe(null)});return()=>cancelAnimationFrame(ie)},[n,Vn,me,be,j,w]),o.useLayoutEffect(()=>{const P=re.current;if(!P||!E){he(null);return}if(oe)return;const z=j.kind==="image"||j.kind==="loading"&&j.mode==="image",ie=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,xe=j.kind==="text"&&xs(ie??"")&&me==="preview",Ue=j.kind==="text"&&gs(ie??"")&&C==="preview";if(j.kind!=="text"||z||xe||Ue){he(null);return}const $e=()=>{const De=K.current.get(E.end);if(!De||!P){he(null);return}const nt=De.offsetTop+De.offsetHeight/2,ot=P.scrollLeft+Math.max(8,P.clientWidth-120);he({top:nt,left:ot})};$e();const He=new ResizeObserver(()=>$e());return He.observe(P),()=>He.disconnect()},[E,oe,j,me,C,n,w,Ae]);const Wt=j.kind==="text"&&!(gs(fr??"")&&C==="preview")&&!fr?.toLowerCase().endsWith(".csv")&&!fr?.toLowerCase().endsWith(".kicad_pro")&&!fr?.toLowerCase().endsWith(".kicad_prl"),Kr=o.useCallback(()=>{ct(!1),xn(""),ur([]),vn(0),Pa()},[]),kt=o.useCallback(()=>{Wt&&(ct(!0),requestAnimationFrame(()=>{wt.current?.focus(),wt.current?.select()}))},[Wt]),$r=o.useCallback(P=>{vn(z=>gt.length===0?0:(z+P+gt.length)%gt.length)},[gt.length]);if(o.useEffect(()=>{const P=z=>{const ie=Fp(z);if(ie==="open"&&Wt){z.preventDefault(),kt();return}Ce&&(ie==="close"?(z.preventDefault(),Kr()):(ie==="next"||ie==="previous")&&(z.preventDefault(),$r(ie==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[Kr,Ce,$r,kt,Wt]),o.useLayoutEffect(()=>{if(Pa(),!Ce||!Qe.trim()||!re.current){ur([]),vn(0);return}const P=Dp(re.current,Qe);return ur(P),vn(0),td(P,0),rd(P[0]),Pa},[Ce,Qe,Ae,me,j]),o.useEffect(()=>{Ce&&(td(gt,Yt),rd(gt[Yt]))},[Yt,gt,Ce]),o.useEffect(()=>Pa,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.selectFilePrompt")});const Te=w&&!n.startsWith("/")?`${w}/${n}`:n,Gt=za(Te,w),Er=Ad(Te,w),mr=j.kind==="text"&&j.content?j.content.split(`
1654
- `):[],ro=Math.max(2,String(mr.length).length)+1,St=j.kind==="text"||j.kind==="image"||j.kind==="model3d"||j.kind==="video"||j.kind==="eda"?j.meta:null,Is=xs(Te),Mt=Te.toLowerCase().endsWith(".csv"),Fs=Te.toLowerCase().endsWith(".kicad_pro"),Jt=Te.toLowerCase().endsWith(".kicad_prl"),Vr=j.kind==="text"&&Is&&me==="preview",Yn=gs(Te),pr=j.kind==="text"&&Yn&&C==="preview",no=j.kind==="image"||j.kind==="loading"&&j.mode==="image",jt=j.kind==="model3d"||j.kind==="loading"&&j.mode==="model3d",Yr=j.kind==="video"||j.kind==="loading"&&j.mode==="video",Xn=j.kind==="eda"||j.kind==="loading"&&j.mode==="eda",Jn=j.kind==="text"?j.sourcePath:Te,Lr=Kh(Jn,w,E),Ar=(()=>{if(!E||j.kind!=="text"||mr.length===0)return Lr;const P=[];for(let xe=E.start;xe<=E.end;xe+=1)P.push(`${xe} ${mr[xe-1]??""}`);const z=bu(Te).replace(/^\./,""),ie="```";return`${Lr}
1645
+ `:null]},`${s}-line-${f}`)})})})]})}function Xi(t,n,s,l,d){t=Cg(t);const c=jg(t),h=Nu(t),m=[],g={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:Rg(t),headingSlugCounts:new Map,images:m,onImageOpen:l,footnotesLabel:d?.footnotes??"Footnotes",backToFootnoteLabel:d?.backToFootnote??(y=>`Back to footnote ${y}`)},p=[];let f=0;for(;f<t.length;){const y=t[f],N=y.trim();if(Wa(y)||h.has(f)){f+=1;continue}if(!N){f+=1;continue}if(/^<details>\s*$/i.test(N)){const F=f;let a="Details";const w=[];for(f+=1;f<t.length&&!/^<\/details>\s*$/i.test(t[f].trim());){const O=t[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?a=O[1].trim()||a:w.push(t[f].trimStart()),f+=1}f<t.length&&(f+=1),p.push({key:`details-${F}`,startLine:F+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:rt(a,`details-${F}-summary`,!0,g)}),w.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:Bu(w,`details-${F}`,g)})]})});continue}const I=Iu(y);if(I){const F=[y],a=f;for(f+=1;f<t.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(t[f]);)F.push(t[f]),f+=1;f<t.length&&!I.selfContained&&(F.push(t[f]),f+=1),p.push({key:`html-${a}`,startLine:a+1,endLine:f,content:e.jsx(Tu,{html:F.join(`
1646
+ `)})});continue}const D=N.match(/^(```|~~~)\s*(.*)$/);if(D){const F=[],a=D[1],w=D[2]?.trim(),O=f;for(f+=1;f<t.length&&!t[f].trim().startsWith(a);)F.push(t[f]),f+=1;f<t.length&&(f+=1),p.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:w.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(w.toLowerCase()),content:w.toLowerCase()==="mermaid"?e.jsx(zu,{code:F.join(`
1647
+ `),blockKey:`code-${O}`}):["math","latex","tex"].includes(w.toLowerCase())?e.jsx(Es,{tex:F.join(`
1648
+ `),display:!0}):j=>e.jsx(Va,{code:F.join(`
1649
+ `),lang:w,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:j})});continue}if(Ga(y)){const F=[],a=f;for(f+=0;f<t.length&&(Ga(t[f])||!t[f].trim());)F.push(t[f].trim()?_u(t[f]):""),f+=1;p.push({key:`indented-code-${a}`,startLine:a+1,endLine:f,fineGrained:!0,content:w=>e.jsx(Va,{code:F.join(`
1650
+ `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${a}`,codeStartLine:a+1,lineRange:w})});continue}if(N.startsWith("$$")){const F=[],a=f,w=N.replace(/^\$\$\s*/,"");if(w.endsWith("$$")&&w.length>2)F.push(w.replace(/\s*\$\$$/,"")),f+=1;else{for(w&&F.push(w),f+=1;f<t.length&&!t[f].trim().endsWith("$$");)F.push(t[f]),f+=1;if(f<t.length){const O=t[f].trim().replace(/\s*\$\$$/,"");O&&F.push(O),f+=1}}p.push({key:`math-${a}`,startLine:a+1,endLine:f,content:e.jsx(Es,{tex:F.join(`
1651
+ `),display:!0})});continue}if(f+1<t.length&&N&&!Li(y)&&/^(=+|-+)\s*$/.test(t[f+1].trim())){const F=t[f+1].trim().startsWith("=")?1:2,a=`h${F}`,w=Ai(N,g),O={level:F,text:vd(N),id:w};p.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(a,{id:w,className:`scroll-mt-16 font-semibold text-foreground ${F===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:rt(N,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const B=N.match(/^(#{1,6})\s+(.+)$/);if(B){const F=B[1].length,a=ju(B[2]),w={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${F}`,j=Ai(a,g),X={level:F,text:vd(a),id:j};p.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:X,content:e.jsx(O,{id:j,className:`scroll-mt-16 font-semibold text-foreground ${w[F]}`,children:rt(a,`heading-${f}`,!0,g)})}),f+=1;continue}if(yu(y)){p.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(N.startsWith(">")){const F=[],a=[],w=f;for(;f<t.length&&/^>\s?/.test(t[f].trim());)F.push(t[f].trim().replace(/^>\s?/,"")),a.push(f+1),f+=1;const O=F[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const X=O[1].toUpperCase(),ne=O[2]?.trim(),se=[...ne?[ne]:[],...F.slice(1)],fe=[...ne?[a[0]]:[],...a.slice(1)],G=Ii(se,`callout-${w}`,g);p.push({key:`callout-${w}`,startLine:w+1,endLine:f,fineGrained:!0,content:J=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:X}),se.length>0&&e.jsx("div",{children:Fi(G.perLine,G.hardBreaks,fe,`callout-${w}`,J)})]})});continue}const j=Wg(F,`quote-${w}`,g,a);p.push({key:`quote-${w}`,startLine:w+1,endLine:f,fineGrained:!0,content:X=>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:Gg(j,X)})});continue}if(f+1<t.length&&y.includes("|")&&Ka(t[f+1])){const F=Ls(y),a=Ou(t[f+1]),w=[],O=f;for(f+=2;f<t.length&&t[f].includes("|")&&t[f].trim();)w.push(Ls(t[f])),f+=1;const j=F.map((ne,se)=>rt(ne,`th-${O}-${se}`,!0,g)),X=w.map((ne,se)=>F.map((fe,G)=>rt(ne[G]??"",`td-${O}-${se}-${G}`,!0,g)));p.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:ne=>{const se=fe=>!!(ne&&fe>=ne.start&&fe<=ne.end);return e.jsx("div",{className:hu,"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":se(O+1)?"true":void 0,children:j.map((fe,G)=>e.jsx("th",{className:`${uu} ${qa(a[G]??null)}`,children:e.jsx("div",{className:za,children:fe})},`h-${G}`))})}),e.jsx("tbody",{children:X.map((fe,G)=>{const J=O+G+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":J,"data-md-ref-start":J,"data-md-ref-end":J,"data-selected":se(J)?"true":void 0,children:F.map((M,_)=>e.jsx("td",{className:`${fu} ${qa(a[_]??null)}`,children:e.jsx("div",{className:za,children:fe[_]})},`c-${_}`))},`r-${G}`)})})]})})}});continue}const E=As(y);if(E){const F=E.ordered,a=Za(y),w=E.start,O=f,j=Ki(t,f,a,F,!0,h);f=j.nextIndex;const X=F?"ol":"ul",ne=Vi(j.items,`list-${O}`,g);p.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:se=>e.jsx(X,{start:F?w:void 0,className:`${F?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:Yi(ne,se)})});continue}const $=[y.trimStart()],L=[f+1],A=f;for(f+=1;f<t.length&&t[f].trim()&&!Li(t[f])&&!(f+1<t.length&&t[f].includes("|")&&Ka(t[f+1]));){if(Wa(t[f])||h.has(f)){f+=1;continue}$.push(t[f].trimStart()),L.push(f+1),f+=1}const U=Ii($,`p-${A}`,g);p.push({key:`p-${A}`,startLine:A+1,endLine:f,fineGrained:!0,content:F=>e.jsx("p",{className:"text-muted-foreground",children:Fi(U.perLine,U.hardBreaks,L,`p-${A}`,F)})})}const k=zg(g);return k&&p.push({key:"footnotes",startLine:t.length,endLine:t.length,content:k}),{blocks:p,images:m}}function Jg(t,n,s){return Xi(t,n,s).blocks}function Wu(t,n){const s=[];for(const l of t){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function Gu(t){return t.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function Qg({src:t,alt:n,onZoomChange:s,onDoubleTap:l}){const d=Eu(t);return e.jsx(sf,{src:d,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function qu({images:t,index:n,onChange:s,onClose:l}){const{t:d}=yt(),c=t[n],h=t.length>1,m=o.useRef(null),g=o.useRef(null),p=o.useRef(null),f=o.useRef(0),[k,y]=o.useState(!1),[N,I]=o.useState(0),[D,B]=o.useState(!1),E=o.useCallback(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),$=o.useCallback(()=>{k||Date.now()<f.current||(E(),p.current=window.setTimeout(()=>{p.current=null,l()},450))},[E,k,l]),L=o.useCallback(a=>{if(t.length===0)return;const w=(a+t.length)%t.length;m.current?.slideTo(w),s(w)},[t.length,s]),A=o.useCallback(()=>L(n-1),[L,n]),U=o.useCallback(()=>L(n+1),[L,n]);if(o.useEffect(()=>{E(),I(0),B(!1),y(!1)},[E,n]),o.useEffect(()=>{const a=m.current;a&&(a.allowTouchMove=h&&!k)},[h,k]),o.useEffect(()=>{const a=m.current;!a||a.activeIndex===n||a.slideTo(n,0)},[n]),o.useEffect(()=>E,[E]),o.useEffect(()=>{const a=w=>{if(w.key==="Escape"){w.preventDefault(),l();return}h&&(w.key==="ArrowLeft"?(w.preventDefault(),A()):w.key==="ArrowRight"&&(w.preventDefault(),U()))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[h,U,A,l]),Fd({onDrag:({movement:[a,w],pinching:O})=>{O||k||Math.abs(w)<Math.abs(a)*1.15&&N===0||(B(!0),Math.abs(w)>8&&(f.current=Date.now()+300),I(Math.max(0,w)))},onDragEnd:({movement:[a,w],velocity:[,O],pinching:j,canceled:X})=>{if(B(!1),j||X||k||Math.abs(w)<Math.abs(a)*1.15){I(0);return}if(Math.abs(w)>8&&(f.current=Date.now()+300),Uu(w,O)){l();return}I(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const F=c.title||c.alt||(c.kind==="mermaid"?d("rightSidebar.mermaidDiagram"):d("rightSidebar.image"));return typeof document>"u"?null:Gr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:F}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",t.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:A,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":d("rightSidebar.previousImage"),title:d("common.previous"),children:e.jsx(Cs,{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":d("rightSidebar.nextImage"),title:d("common.next"),children:e.jsx(Ch,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":d("rightSidebar.closeImagePreview"),title:d("common.close"),children:e.jsx(Ot,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:$,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${N}px, 0) scale(${Math.max(.86,1-N/900)})`,opacity:Math.max(.35,1-N/360),transition:D?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(Dd,{onSwiper:a=>{m.current=a,a.allowTouchMove=h&&!k},onSlideChange:a=>{a.activeIndex!==n&&s(a.activeIndex)},onSliderMove:()=>{E(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:t.map((a,w)=>e.jsx(vi,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:a.kind==="image"?e.jsx(Qg,{src:a.src,alt:a.alt||a.title||d("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(mb,{svg:a.svg,title:a.title||a.alt||d("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${a.kind}-${w}-${a.alt}`))})})})]})]}),document.body)}function Ku({content:t,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:d,onLineRangeDrag:c,scrollTop:h,outlineOpen:m,outlineCloseSignal:g,onOutlineOpen:p,onOutlineClose:f,lightboxOpen:k,lightboxCloseSignal:y,onLightboxOpen:N,onLightboxClose:I,onLocalLinkOpen:D}){const{t:B}=yt(),[E,$]=o.useState(null),[L,A]=o.useState(null),[U,F]=o.useState(1),[a,w]=o.useState(null),O=o.useRef(null),j=o.useRef(null),{blocks:X,images:ne}=o.useMemo(()=>Xi(t.split(`
1652
+ `),n,s,S=>{A(null),$(S),N?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:S=>B("rightSidebar.backToFootnote",{index:S})}),[t,n,s,N,B]),se=o.useMemo(()=>L?[...ne,L]:ne,[ne,L]),fe=o.useCallback(S=>{A({kind:"mermaid",svg:S,alt:"Mermaid diagram",title:"Mermaid diagram"}),$(ne.length),N?.()},[ne.length,N]);o.useEffect(()=>{$(null),A(null)},[t,n]),o.useEffect(()=>{$(null),A(null)},[y]),o.useEffect(()=>{k||($(null),A(null))},[k]),o.useEffect(()=>{F(1)},[t,n]),o.useLayoutEffect(()=>{const S=O.current;if(!S||X.length===0)return;const V=Array.from(S.querySelectorAll("[data-markdown-preview-block-start]"));let ye=1;const be=28;for(const Oe of V)if(Oe.offsetTop-h<=be)ye=Number(Oe.dataset.markdownPreviewBlockStart)||ye;else break;F(Oe=>Oe===ye?Oe:ye)},[X,h]);const G=o.useMemo(()=>Wu(X,U),[U,X]),J=o.useMemo(()=>Gu(X),[X]),M=`${n??""}
1653
+ ${t}`,_=o.useRef(M),K=o.useRef(null),re=o.useRef(null),oe=o.useRef(!1);o.useEffect(()=>{_.current!==M&&(_.current=M,f?.())},[f,M]),o.useEffect(()=>{g!==void 0&&w(null)},[g]),o.useLayoutEffect(()=>{if(!m){w(null);return}const S=()=>{const V=j.current;if(!V)return;const ye=V.getBoundingClientRect(),be=window.innerWidth;w({top:ye.bottom+6,right:Math.max(8,be-ye.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[m,h,G]);const he=o.useCallback(S=>{const V=O.current,ye=V?.closest("[data-markdown-preview-scroller]"),be=V?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!ye||!be)return;const Oe=ye.getBoundingClientRect(),ce=be.getBoundingClientRect(),Le=V?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,W=ce.top-Oe.top+ye.scrollTop;ye.scrollTo({top:Math.max(0,W-Le-8),behavior:"smooth"}),F(S.startLine),f?.()},[f]),me=o.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||hi(S.target)||(K.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),je=o.useCallback((S,V,ye)=>{const be=K.current;if(K.current=null,!be||be.pointerId!==S.pointerId)return;const Oe=Math.abs(S.clientX-be.startX),ce=Math.abs(S.clientY-be.startY);if(Oe>8||ce>8)return;const Je=S.target;if(hi(Je)||_i())return;const Le=Ld(Je,V,ye);d(S,Le.start,Le.end)},[d]),C=o.useCallback(S=>{K.current?.pointerId===S.pointerId&&(K.current=null)},[]),Z=o.useCallback((S,V)=>{const ye=O.current;if(!ye||typeof document.elementFromPoint!="function")return null;const be=document.elementFromPoint(S,V);if(!(be instanceof HTMLElement)||!ye.contains(be))return null;const Oe=be.closest("[data-md-ref-start]");if(Oe){const Se=Number(Oe.dataset.mdRefStart);if(Number.isFinite(Se)&&Se>0)return Se}const ce=be.closest("[data-markdown-preview-block-start]");if(!ce)return null;const Je=Number(ce.dataset.markdownPreviewBlockStart),Le=X.find(Se=>Se.startLine===Je);if(!Le)return Number.isFinite(Je)&&Je>0?Je:null;if(Le.endLine<=Le.startLine)return Le.startLine;const W=ce.getBoundingClientRect(),q=W.height>0?Math.min(1,Math.max(0,(V-W.top)/W.height)):0;return Math.round(Le.startLine+q*(Le.endLine-Le.startLine))},[X]),de=o.useCallback(S=>{if(!c||S.pointerType==="mouse"&&S.button!==0)return;const V=Z(S.clientX+24,S.clientY);if(V!=null){re.current={pointerId:S.pointerId,anchorLine:V,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[c,Z]),Ee=o.useCallback(S=>{const V=re.current;if(!V||V.pointerId!==S.pointerId||!c)return;const ye=Z(S.clientX+16,S.clientY);ye!=null&&(!V.moved&&ye===V.anchorLine||(V.moved=!0,oe.current=!0,c(S,Math.min(V.anchorLine,ye),Math.max(V.anchorLine,ye),"move")))},[c,Z]),Ge=o.useCallback(S=>{const V=re.current;if(re.current=null,!V||V.pointerId!==S.pointerId||!c||!V.moved)return;const ye=Z(S.clientX+16,S.clientY)??V.anchorLine;c(S,Math.min(V.anchorLine,ye),Math.max(V.anchorLine,ye),"end")},[c,Z]),De=o.useCallback(S=>{re.current?.pointerId===S.pointerId&&(re.current=null)},[]),le={onPointerDown:de,onPointerMove:Ee,onPointerUp:Ge,onPointerCancel:De},ae=()=>oe.current?(oe.current=!1,!0):!1;return X.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:S=>{const V=S.target instanceof Element?S.target.closest("a[href]"):null;if(!V||!D)return;const ye=V.getAttribute("href");if(!ye)return;const be=Wi(ye,n,s);be&&(S.preventDefault(),D(be))},children:[G.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:G.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:G[G.length-1].text}),J.length>1&&e.jsxs("button",{ref:j,type:"button",onClick:()=>{m?f?.():p?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(_d,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&Gr.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:a?{top:`${a.top}px`,right:`${a.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:J.map(S=>{const V=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>he(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${V?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${V?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children: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(Ot,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:J.map(S=>{const V=G[G.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>he(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${V?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${V?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(ku.Provider,{value:fe,children:X.map(S=>{const V=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),ye=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),be=S.kind==="table"?!1:S.fineGrained?ye:V,Oe=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let ce=null;if(S.kind!=="table"&&S.fineGrained&&V&&!ye&&l){const q=S.endLine-S.startLine+1,Se=Math.max(l.start,S.startLine),Re=Math.min(l.end,S.endLine),lt=(Se-S.startLine)/q,Qe=(Re-Se+1)/q;ce=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) * ${lt})`,height:`calc((100% - 0.5rem) * ${Qe})`}})}const Je=typeof S.content=="function"?S.content(l):S.content,Le=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,W=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:di(be),"aria-hidden":"true",...le,children:[e.jsx("span",{className:ui(be)}),ce]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:Je})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${be?"bg-primary/10":""}`,title:`Line ${Le}`,"aria-label":`Line ${Le}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:di(Oe,"self"),onClick:q=>{q.preventDefault(),!ae()&&d(q,S.startLine,S.endLine)},title:`Reference table lines ${Le}`,"aria-label":`Reference table lines ${Le}`,...le,children:e.jsx("span",{className:ui(Oe,"self")})}):e.jsxs("span",{className:di(be,"none"),"aria-hidden":"true",...le,children:[e.jsx("span",{className:ui(be,"none")}),ce]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:me,onPointerUp:q=>je(q,S.startLine,S.endLine),onPointerCancel:C,onKeyDown:q=>{q.key!=="Enter"&&q.key!==" "||(q.preventDefault(),d(q,S.startLine,S.endLine))},title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:Je})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:q=>{const Se=q.target;if(hi(Se)||_i()||ae())return;const Re=Ld(Se,S.startLine,S.endLine);d(q,Re.start,Re.end)},onKeyDown:q=>{q.key!=="Enter"&&q.key!==" "||(q.preventDefault(),d(q,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${be?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Le}`,"aria-label":`Reference line ${Le}`,children:W},S.key)})})})]}),k&&E!==null&&se[E]&&e.jsx(qu,{images:se,index:E,onChange:$,onClose:()=>{$(null),A(null),I?.()}})]})}function qn({label:t,value:n,options:s,placeholder:l,searchPlaceholder:d,emptyText:c,disabled:h,onChange:m}){const{t:g}=yt(),[p,f]=o.useState(!1),[k,y]=o.useState(""),[N,I]=o.useState(null),D=o.useRef(null),B=o.useRef(null),E=k.trim().toLowerCase(),$=o.useMemo(()=>E?s.filter(a=>`${a.label} ${a.meta??""}`.toLowerCase().includes(E)):s,[E,s]),L=s.find(a=>a.value===n),A=()=>{const a=k.trim();a&&(m(a),f(!1),y(""))},U=o.useCallback(()=>{const a=D.current?.getBoundingClientRect();if(!a)return!1;const w=12,O=Math.max(220,Math.min(a.width,window.innerWidth-w*2)),j=Math.min(Math.max(w,a.left),window.innerWidth-O-w),X=window.innerHeight-a.bottom-w,ne=a.top-w,se=X>=180||X>=ne,fe=Math.max(96,(se?X:ne)-4),G=Math.min(320,fe);return I({left:j,top:se?a.bottom+4:Math.max(w,a.top-G-4),width:O,maxHeight:G}),!0},[]),F=()=>{U(),f(!0)};return o.useEffect(()=>{if(!p)return;let a=0;const w=()=>{a||(a=window.requestAnimationFrame(()=>{a=0,U()}))},O=j=>{const X=j.target;X instanceof Node&&(D.current?.contains(X)||B.current?.contains(X)||(f(!1),y("")))};return window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),document.addEventListener("pointerdown",O,!0),()=>{a&&window.cancelAnimationFrame(a),window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0),document.removeEventListener("pointerdown",O,!0)}},[p,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:D,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),p){f(!1);return}F()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:t}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:L?.label??(n||l)})]}),e.jsx(Ns,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${p?"rotate-180":""}`})]}),p&&!h&&typeof document<"u"&&Gr.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:a=>a.stopPropagation(),style:{left:N?.left??12,top:N?.top??12,width:N?.width??260,maxHeight:N?.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(Vn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:k,onChange:a=>y(a.target.value),onKeyDown:a=>{if(a.key==="Escape"){a.preventDefault(),f(!1),y("");return}a.key==="Enter"&&(a.preventDefault(),A())},onBlur:()=>{k.trim()&&$.length===0&&A()},placeholder:d,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(N?.maxHeight??320)-46)},children:[k.trim()&&!s.some(a=>a.value===k.trim())&&e.jsxs("button",{type:"button",onMouseDown:a=>a.preventDefault(),onClick:A,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),$.length>0?$.map(a=>e.jsxs("button",{type:"button",onClick:()=>{m(a.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 ${a.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:a.label}),a.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:a.meta})]},a.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function jd({open:t,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:d,selectedRoots:c,onToggleRepo:h,onGenerate:m,onSecondaryAction:g,disabled:p,generateDisabled:f,secondaryDisabled:k,inserted:y,buttonLabel:N,insertedLabel:I,title:D,ariaLabel:B,scopeTitle:E,scopeLabel:$,allLabel:L,generateLabel:A,secondaryLabel:U,secondaryTitle:F,secondaryLoading:a,loading:w,error:O,statusTitle:j,extraContent:X,renderRepoExtra:ne}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!t):f||m()},disabled:p,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:j??(s?`${E}: ${$}`:D),children:[w?e.jsx(vt,{size:13,className:"animate-spin"}):e.jsx($s,{size:13}),e.jsx("span",{children:y?I:N}),s&&e.jsx(Ns,{size:11,className:`shrink-0 transition ${t?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&t&&typeof document<"u"&&Gr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>n(!1),children:e.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:se=>se.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children: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(Ot,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[X,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:L}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),d.map(se=>{const fe=c.includes(se.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${fe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(se.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${fe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:se.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:se.label}),se.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:se.branch})]}),fe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),ne&&(l||fe)&&e.jsx("div",{className:"px-2 pb-2",children:ne(se)})]},se.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{k||(n(!1),g())},disabled:k,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:F,children:[a?e.jsx(vt,{size:12,className:"animate-spin"}):e.jsx(Kd,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),m())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:D,children:[e.jsx($s,{size:12}),A]})]})]})}),document.body)]})}function Zg(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Vu(){return tt(Ui,Zg)??{}}function eb(t,n){const s=Vu(),l=Object.entries({...s,[t]:{top:n,updatedAt:Date.now()}}).sort(([,d],[,c])=>c.updatedAt-d.updatedAt).slice(0,Yp);ks(Ui,Object.fromEntries(l),Jp)}function tb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function rb(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;for(const n of Object.values(t)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!tb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function Ji(t,n){if(!n)return null;const s=t&&!n.startsWith("/")?`${t}/${n}`:n;return t?`${t}::${s}`:s}function Yu(){return tt(Hi,rb)??{}}function Rd(t,n){const s=Ji(t,n);return s?Yu()[s]??null:null}function oi(t,n,s){const l=Ji(t,n);if(!l)return;const d=Yu(),c=d[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...d,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,m],[,g])=>g.updatedAt-m.updatedAt).slice(0,Xp);ks(Hi,Object.fromEntries(h),Qp)}function ii({active:t,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${t?"block":"hidden"}`,"aria-hidden":!t,children:n?typeof l=="function"?l():l:s})}function li({slow:t}){return e.jsx(im,{slow:t})}function Fa({message:t,onRetry:n}){const{t:s}=yt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:t}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function Ua(t,n){const s=n&&t.startsWith(`${n}/`)?t.slice(n.length+1):t,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function ft(t){if(!t)return"";const n=t.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function ci(t){if(!t)return null;const n=t.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Di(t,n,s){const l=Math.min(n,s),d=Math.max(n,s);return t?.start===l&&t.end===d?null:t&&t.start===t.end?{start:Math.min(t.start,l),end:Math.max(t.end,d)}:{start:l,end:d}}function nb(t,n,s){return Di(t,n,s)}function di(t,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${t?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function ui(t,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${t?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function Cd(t,n){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${t?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${n?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function Xu(t){const n=new Map;for(const s of t)n.set(Qi(s),s);return n}function Ju(t,n){const s=new Map(t);for(const l of n)s.set(Qi(l),l);return s}function Nd(t,n){let s=0;for(const l of t){const d=it(l,n);d&&n&&d!==n&&(s+=1)}return s}function sb(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function ab(t,n){return Array.from(Ju(Xu(t),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function ob(t,n){const s=t.relativeRoot==="."?ft(n??t.root)||t.name||t.root:t.relativeRoot||t.name||ft(t.root)||t.root;return{root:t.root,label:s,branch:t.context?.branch??null,count:t.files.length,staged:sb(t.files)}}function Qu(t,n){const s=ft(n??"")||n||"";return t.map(l=>ob(l,n)).sort((l,d)=>s&&l.label===s?-1:s&&d.label===s?1:l.label.localeCompare(d.label))}function Zu(t,n,s,l,d){const c=pu(s),h=c.find(D=>D.root===l)??c[0]??null,m=n.find(D=>D.root===l)??null,g=m?.relativeRoot??h?.relativeRoot??".",p=m?.name??h?.name??(ft(l)||l),f=(h?.files??s.files).map(D=>({...D,repoRoot:l,repoRelativeRoot:g,repoName:p})),k=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:g,name:p,depth:0,nested:!!(d&&l!==d),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:g,name:p,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(d&&l!==d),available:h?.available??s.available,files:f,context:k?{...k,root:l,changedFiles:f.map(D=>({path:D.path,absolutePath:D.absolutePath,status:D.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},N=m?n.map(D=>D.root===l?y:D):[...n,y];return{files:Array.from(t).filter(D=>it(D,d)!==l).concat(f),repositories:N,repoFilters:Qu(N,d)}}function it(t,n){return t.repoRoot??n}function Qi(t){return`${t.repoRoot??""}\0${t.path}`}function ut(t){return t.absolutePath||t.path}function fi(t){return Qi(t)}function ib(t){return t.repoRelativeRoot&&t.repoRelativeRoot!=="."?t.repoRelativeRoot:t.repoName??""}function Md(t){return t.reduce((n,s)=>n+(s.staged?1:0),0)}function $d(t){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of t)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Kn(t){let n=0;const s=t??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function vs(t,n){return typeof t!="number"||!Number.isFinite(t)||t<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Nr(t){return t instanceof DOMException&&t.name==="AbortError"}function lb(t){const n=t.error??t.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Ed(t){return t?.available===!1&&t.code==="NOT_GIT_REPOSITORY"}function _i(){if(typeof window>"u")return!1;const t=window.getSelection();return!!(t&&!t.isCollapsed&&t.toString().trim())}function hi(t){return t instanceof HTMLElement&&!!t.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Ld(t,n,s){const l=t instanceof HTMLElement?t.closest("[data-md-ref-start]"):null,d=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(d)&&d>0&&Number.isFinite(c)&&c>0?{start:Math.min(d,c),end:Math.max(d,c)}:{start:n,end:s}}function cb({actions:t,running:n,completed:s}){const{t:l}=yt(),[d,c]=o.useState(!1),h=o.useRef(null),m=t.find(p=>n?.action===p.key),g=t.find(p=>s?.action===p.key);return t.length===0?null:(o.useEffect(()=>{if(!d)return;const p=k=>{const y=k.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=k=>{k.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",p),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",p),document.removeEventListener("keydown",f)}},[d]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),c(f=>!f)},disabled:t.every(p=>p.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${d?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??g?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(vt,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(bi,{size:14})}),d&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:t.map(p=>{const f=n?.action===p.key,k=s?.action===p.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),p.onClick(),c(!1)},disabled:p.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${k?"bg-accent/10 text-accent":p.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(vt,{size:13,className:"animate-spin"}):k?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:p.label})]},p.key)})})]}))}function db(t){const n=window.getComputedStyle(t).overflowY;return(n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight+1}function ef(t){let n=t;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&db(n))return n;n=n.parentElement}return t.closest(".termdock-diff-stream-scroller")}function Yn(t){return t.getClientRects().length>0&&window.getComputedStyle(t).visibility!=="hidden"}const mi=new WeakMap;function Ya(t){const n=mi.get(t);n!==void 0&&window.clearTimeout(n),t.classList.remove("diff-walkthrough-target"),t.offsetWidth,t.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{t.classList.remove("diff-walkthrough-target"),mi.delete(t)},1700);mi.set(t,s)}function ub(t){const n=CSS.escape(t),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let d=null;for(const m of l){if(!Yn(m))continue;const g=m.querySelector(s);if(g&&Yn(g)){d=g;break}}if(d??=Array.from(document.querySelectorAll(s)).find(Yn)??null,!d)return;const c=ef(d);if(!c){d.scrollIntoView({block:"start",behavior:"smooth"}),Ya(d);return}const h=d.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),Ya(d)}function xn(t){const n=CSS.escape(t.filePath),s=typeof t.sectionIndex=="number"?String(t.sectionIndex):null,l=typeof t.hunkIndex=="number"?String(t.hunkIndex):null,d=t.sectionFingerprint?CSS.escape(t.sectionFingerprint):null,c=t.hunkFingerprint?CSS.escape(t.hunkFingerprint):null,h=[s!==null&&d?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null&&d?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${d}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(I=>!!I),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const I of m)if(Yn(I)){for(const D of h){const B=I.querySelector(D);if(B&&Yn(B)){g=B;break}}if(g)break}if(g??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Yn)??null,!g){ub(t.filePath);return}const p=ef(g);if(!p){g.scrollIntoView({block:"center",behavior:"smooth"}),Ya(g);return}const f=g.getBoundingClientRect(),k=p.getBoundingClientRect(),N=f.top-k.top+p.scrollTop-Math.max(24,(p.clientHeight-f.height)/2);p.scrollTo({top:Math.max(0,N),behavior:"instant"}),Ya(g)}const tf=1,rf=8;function fb(t){return Math.min(rf,Math.max(tf,t))}function nf({resetKey:t,onZoomChange:n,onDoubleTap:s,children:l}){const d=o.useRef(null),[c,h]=o.useState({scale:1,x:0,y:0}),[m,g]=o.useState(!1),p=o.useRef(null),f=o.useRef(new Set),k=o.useRef(!1),y=o.useRef(null),N=o.useRef(0),I=o.useRef(c);I.current=c,o.useEffect(()=>{h({scale:1,x:0,y:0})},[t]);const D=o.useCallback((L,A,U)=>{const F=d.current;if(!F)return{x:A,y:U};const a=F.firstElementChild instanceof HTMLElement?F.firstElementChild:null,w=a?.clientWidth||F.clientWidth,O=a?.clientHeight||F.clientHeight,j=Math.max(0,(w*L-F.clientWidth)/2),X=Math.max(0,(O*L-F.clientHeight)/2);return{x:Math.min(j,Math.max(-j,A)),y:Math.min(X,Math.max(-X,U))}},[]),B=o.useCallback((L,A,U)=>{h(F=>{const a=fb(L),w=d.current;if(!w||a===1)return{scale:a,x:0,y:0};const O=w.getBoundingClientRect(),j=(A??O.left+O.width/2)-O.left-O.width/2,X=(U??O.top+O.height/2)-O.top-O.height/2,ne=a/F.scale,se=j-(j-F.x)*ne,fe=X-(X-F.y)*ne;return{scale:a,...D(a,se,fe)}})},[D]),E=o.useCallback((L,A)=>{g(!0),I.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,L,A),window.setTimeout(()=>g(!1),220)},[B]);o.useEffect(()=>{const L=d.current;if(!L)return;const A=a=>{if(a.pointerType==="mouse"&&a.button!==0)return;const w=f.current.size===0;if(f.current.add(a.pointerId),w){const O=Date.now(),j=y.current;if(j&&O-j.time<350&&Math.hypot(a.clientX-j.x,a.clientY-j.y)<24){y.current=null,N.current=O,s?.(),E(a.clientX,a.clientY);return}}if(f.current.size>1){k.current=!0,p.current=null;return}if(!(I.current.scale<=1)){a.preventDefault(),p.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{L.setPointerCapture?.(a.pointerId)}catch{}g(!1)}},U=a=>{const w=p.current;if(!w||w.pointerId!==a.pointerId)return;const O=a.clientX-w.startX,j=a.clientY-w.startY;if(!w.moved){if(Math.hypot(O,j)<6)return;w.moved=!0}a.stopPropagation(),a.preventDefault(),h(X=>({...X,...D(X.scale,w.originX+O,w.originY+j)}))},F=a=>{const w=p.current,O=w?.pointerId===a.pointerId&&w.moved;if(w?.pointerId===a.pointerId){w.moved&&a.stopPropagation(),p.current=null;try{L.releasePointerCapture?.(a.pointerId)}catch{}}f.current.delete(a.pointerId)&&f.current.size===0&&(!k.current&&!O&&(y.current={time:Date.now(),x:a.clientX,y:a.clientY}),k.current=!1)};return L.addEventListener("pointerdown",A,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",F,{capture:!0}),window.addEventListener("pointercancel",F,{capture:!0}),()=>{L.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",F,{capture:!0}),window.removeEventListener("pointercancel",F,{capture:!0})}},[D,s,E]),Fd({onPinch:({offset:[L],origin:[A,U]})=>{g(!1),B(L,A,U)},onWheel:({event:L,delta:[A,U],ctrlKey:F})=>{if(F){L.preventDefault(),L.stopPropagation(),g(!1),B(I.current.scale*(1-U*.01),L.clientX,L.clientY);return}I.current.scale<=1||(L.preventDefault(),L.stopPropagation(),g(!1),h(a=>({...a,...D(a.scale,a.x-A,a.y-U)})))}},{target:d,eventOptions:{passive:!1},pinch:{scaleBounds:{min:tf,max:rf},from:()=>[I.current.scale,0],rubberband:!0}});const $=c.scale>1;return o.useEffect(()=>{n?.($)},[n,$]),e.jsx("div",{ref:d,"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:L=>{L.stopPropagation(),!(Date.now()-N.current<500)&&(s?.(),E(L.clientX,L.clientY))},children:l({scale:c.scale,zoomed:$,animateTransform:m,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0)`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function sf({src:t,alt:n,vector:s,onLoad:l,onError:d,onZoomChange:c,onDoubleTap:h}){const m=Xa(t,d),[g,p]=o.useState(null),f=s??Qa(t);return o.useEffect(()=>{p(null)},[t]),e.jsx(nf,{resetKey:t,onZoomChange:c,onDoubleTap:h,children:({transformStyle:k,vectorTransformStyle:y,scale:N,animateTransform:I})=>{const D=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*N,height:g.height*N,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:g?{...k,width:g.width,height:g.height}:f?y:k,onLoad:B=>{const E=B.currentTarget,$=E.parentElement;if($&&E.naturalWidth>0&&E.naturalHeight>0){const L=Math.max(1,$.clientWidth-2),A=Math.max(1,$.clientHeight-2),U=Math.min(L/E.naturalWidth,A/E.naturalHeight),F=f?U:Math.min(U,1);p({width:Math.max(1,Math.round(E.naturalWidth*F)),height:Math.max(1,Math.round(E.naturalHeight*F))})}l(B)},onError:d});return!f||!g?D:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:D})}})}function hb({svg:t,title:n,scale:s,vectorTransformStyle:l}){const d=o.useRef(null);return o.useLayoutEffect(()=>{const c=d.current,h=c?.querySelector("svg");if(!c||!h)return;const m=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let k=f[2],y=f[3];if((!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)&&(k=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)return;const N=Math.max(1,c.clientWidth-24),I=Math.max(1,c.clientHeight-24),D=Math.min(N/k,I/y,1);h.style.width=`${Math.max(1,Math.floor(k*D*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*D*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};m();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return g?.observe(c),()=>g?.disconnect()},[s,t,l]),e.jsx("div",{ref:d,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:t}})}function mb({svg:t,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(nf,{resetKey:t,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:d,scale:c})=>e.jsx(hb,{svg:t,title:n,scale:c,vectorTransformStyle:d})})}let pb=0,gb=0,bb=0,xb=0,vb=0;function pi(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${t}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function et(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:t==="error"||t==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${t}`,data:{seq:++gb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Da(t,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${t}`,data:{seq:++xb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function yb(){return`diff-ui-${Date.now().toString(36)}-${(++vb).toString(36)}`}function wb(t){return t instanceof Element?t.closest("[data-diff-selection-path]"):null}function kb(t){const n=t.target instanceof HTMLElement?t.target:null;return{eventType:t.type,button:t.button,pointerType:t instanceof globalThis.PointerEvent?t.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Bi({onReviewReference:t,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:d,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:m,isMobile:g,markdownOutlineOpen:p,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:k,onCloseMarkdownOutline:y,markdownImageLightboxOpen:N,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:D,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:$,insertedReferenceKey:L,copiedReferenceKey:A,scrollToLine:U,onScrollToLineHandled:F}){const{t:a}=yt(),w=te(P=>P.rootPath),O=te(P=>P.selectFile),[j,X]=o.useState({kind:"idle"}),[ne,se]=o.useState("schematic"),[fe,G]=o.useState(null),J=o.useRef(null),[M,_]=o.useState(null),K=o.useRef(new Map),re=o.useRef(null),[oe,he]=o.useState(null),[me,je]=o.useState(()=>fd()),[C,Z]=o.useState(()=>ed(w,n)),de=o.useRef(null),[Ee,Ge]=o.useState(!1),[De,le]=o.useState(null),[ae,S]=o.useState(0),[V,ye]=o.useState([]),[be,Oe]=o.useState(null),ce=o.useRef(null),Je=o.useRef(n),[Le,W]=o.useState(null),[q,Se]=o.useState({status:"idle"}),[Re,lt]=o.useState(!1),[Qe,vn]=o.useState(""),[ht,dr]=o.useState([]),[Yt,yn]=o.useState(0),wt=o.useRef(null),Ut=qd(c),qr=Ji(w,n);o.useEffect(()=>{if(Je.current===n)return;Je.current=n;const P=n&&w&&!n.startsWith("/")?`${w}/${n}`:n;if(ce.current===P){ce.current=null;return}ce.current=null,ye([]),Oe(null),lt(!1),vn("")},[n,w]);const ur=n?w&&!n.startsWith("/")?`${w}/${n}`:n:null,Xt=te(P=>ur?(P.fileChangeVersions.get(ur)??0)+P.fileWatchEpoch:P.fileWatchEpoch),At=o.useRef(null),fr=o.useRef(null),[Ht,Ps]=o.useState(0),wn=o.useCallback(()=>Ps(P=>P+1),[]);o.useEffect(()=>{const P=J.current;return J.current=null,G(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const z=J.current;J.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[ur,Xt,Ht]),o.useEffect(()=>{if(!n){At.current=null,X({kind:"idle"});return}const P=w&&!n.startsWith("/")?`${w}/${n}`:n,z=new AbortController,ie=++pb,xe=`right-sidebar-file-preview:${ie}`,Ue=performance.now();let $e=!1;const ze=(Q,Be={})=>{$e||($e=!0,pi("end",{loadingId:ie,reason:Q,durationMs:Math.round(performance.now()-Ue),filePath:n,fullPath:P,rootPath:w,...Be}))};let _e=null;const nt=mh(P),at=nt?P.toLowerCase().endsWith(".kicad_pcb")?ne==="schematic"?"pcb-front":ne:"schematic":ne,er=!nt&&Oi(P),xr=!nt&&!er&&ph(P),Cn=!nt&&!er&&!xr&&Ad(P),Zr=xs(P),ts=gs(P),tr=nt?"eda":er?"image":xr?"model3d":Cn?"video":"text",rr=At.current!==P;if(At.current=P,rr){pi("start",{loadingId:ie,filePath:n,fullPath:P,rootPath:w,mode:tr,externalVersion:Xt}),Se({status:"idle"}),X({kind:"loading",mode:tr}),fr.current=null;const Q=Rd(w,n);$(Q?.lineRange??null),je(Zr?fd():"source"),Z(ts?ed(w,n):"source"),nt&&se(gh(P))}rr||X(Q=>Q.kind==="error"?{kind:"loading",mode:tr}:Q);const Nn=window.setTimeout(()=>{$e||z.signal.aborted||pi("still_active",{loadingId:ie,filePath:n,fullPath:P,rootPath:w,mode:tr,durationMs:Math.round(performance.now()-Ue),isPathChange:rr})},3e3),en=window.setTimeout(()=>{if($e||z.signal.aborted)return;const Q=nt?a("rightSidebar.edaTimeout"):xr?a("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(Q,"TimeoutError")),X({kind:"error",message:Q}),ze("stuck_timeout",{error:Q})},nt?bh+5e3:xr?xh+5e3:vh(P)?35e3:sg);if(nt){const Q=at==="pcb-3d"?J.current:null;Q?(X(Q),ze("eda_3d_client_cache_hit",{bytes:Q.meta.size,view:Q.view,mimeType:Q.meta.mimeType})):yh(P,at,z.signal,"view_file",xe).then(Be=>{if(z.signal.aborted)return;_e=URL.createObjectURL(Be.blob);const nr={kind:"eda",sourcePath:Be.path||P,objectUrl:_e,view:Be.view,meta:{size:Be.size,mimeType:Be.mimeType,modified:Be.modified}};if(Be.view==="pcb-3d"){const sr=J.current;sr&&sr.objectUrl!==_e&&URL.revokeObjectURL(sr.objectUrl),J.current=nr,G(nr),_e=null}X(nr),ze("eda_loaded",{bytes:Be.size,view:Be.view,mimeType:Be.mimeType})}).catch(Be=>{z.signal.aborted||(X({kind:"error",message:Be instanceof Error&&/timed out/i.test(Be.message)?a("rightSidebar.edaTimeout"):Be instanceof Error?Be.message:a("rightSidebar.edaLoadFailed")}),ze("error",{error:Be instanceof Error?Be.message:String(Be)}))})}else if(er)wh(P,z.signal,"view_file",xe).then(Q=>{_e=URL.createObjectURL(Q.blob),X({kind:"image",objectUrl:_e,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),ze("image_loaded",{bytes:Q.size,mimeType:Q.mimeType})}).catch(Q=>{z.signal.aborted||(X({kind:"error",message:Q instanceof Error?Q.message:a("rightSidebar.imageLoadFailed")}),ze("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(xr)kh(P,z.signal,"view_file",xe).then(Q=>{z.signal.aborted||(_e=URL.createObjectURL(Q.blob),X({kind:"model3d",sourcePath:Q.path||P,objectUrl:_e,ext:Q.ext,meta:{size:Q.size,mimeType:Q.mimeType,modified:Q.modified}}),ze("model3d_loaded",{bytes:Q.size,ext:Q.ext}))}).catch(Q=>{z.signal.aborted||(X({kind:"error",message:Q instanceof Error&&(Q.name==="TimeoutError"||/timed out/i.test(Q.message))?a("rightSidebar.model3dTimeout"):Q instanceof Error?Q.message:a("rightSidebar.model3dLoadFailed")}),ze("error",{error:Q instanceof Error?Q.message:String(Q)}))});else if(Cn){const Q=Sh(P)??"",Be=Pd(P);X(nr=>nr.kind==="video"&&nr.url===Be?nr:{kind:"video",url:Be,meta:{size:null,mimeType:Q,modified:null}}),ze("video_ready",{mimeType:Q})}else _c(P,z.signal,"view_file",xe).then(Q=>{if(!z.signal.aborted){if(Q.binary){X({kind:"binary"});return}X({kind:"text",content:Q.content,sourcePath:Q.path||P,meta:{size:Q.size,truncated:Q.truncated}}),ze("text_loaded",{bytes:Q.size,truncated:!!Q.truncated})}}).catch(Q=>{z.signal.aborted||(X({kind:"error",message:Q instanceof Error?Q.message:"Failed to read file"}),ze("error",{error:Q instanceof Error?Q.message:String(Q)}))});return()=>{z.abort(),bt(xe),window.clearTimeout(Nn),window.clearTimeout(en),_e&&URL.revokeObjectURL(_e),ze("cleanup")}},[n,w,Xt,Ht,$,a,ne]),o.useEffect(()=>{if(j.kind!=="model3d"||!n){_(null);return}let P=!1;const z=n.lastIndexOf("/"),ie=z>=0?n.slice(z+1):n,xe=z>=0?n.slice(0,z):"",Ue=xe.lastIndexOf("/"),$e=Ue>=0?xe.slice(0,Ue):"",ze=ie.replace(/\.(stl|glb|gltf)$/i,""),_e=`${$e?`${$e}/`:""}features/${ze}.json`;return _c(_e).then(nt=>{if(!P)try{const at=JSON.parse(nt.content);_(at.version===1&&Array.isArray(at.features)&&at.features.length>0?at.features:null)}catch{_(null)}}).catch(()=>{P||_(null)}),()=>{P=!0}},[j,n]),o.useEffect(()=>{if(j.kind!=="text"){W(null);return}const P=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,z=Hd(P),ie=j.content,xe=xs(P??"")&&me==="preview",Ue=gs(P??"")&&C==="preview";if(!z||xe||Ue||!zd(ie)){W(null);return}let $e=!1;const ze=_e=>{if($e||!_e.registered(z)){$e||W(null);return}try{W(Gd(_e,ie,z))}catch{W(null)}};return De?ze(De):(W(null),Wd().then(_e=>{$e||(le(_e),ze(_e))}).catch(()=>{})),()=>{$e=!0}},[j,De,n,w,me,C]),o.useLayoutEffect(()=>{if(!qr||j.kind!=="text")return;const P=`${qr}:${me}:${C}`;if(fr.current===P)return;const z=Rd(w,n);if(fr.current=P,!z)return;const ie=requestAnimationFrame(()=>{const xe=re.current;if(!xe)return;const Ue=me==="preview"?z.markdownTop??z.top:z.top;xe.scrollTo({top:Math.max(0,Ue??0),left:Math.max(0,z.left??0)}),S(me==="preview"?Math.max(0,Ue??0):0)});return()=>cancelAnimationFrame(ie)},[n,me,C,j.kind,qr,w]),o.useEffect(()=>{qr&&oi(w,n,{lineRange:E})},[n,E,qr,w]),o.useEffect(()=>{if(U==null||j.kind!=="text")return;he(null),$({start:U,end:U});const P=U,z=requestAnimationFrame(()=>{const ie=K.current.get(P);ie&&ie.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(z)},[U,j,$,F]);const Xn=o.useCallback(P=>{const z=re.current;if(!z)return!1;const ie=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),xe=z.querySelector(`#${ie}`);return xe?(xe.scrollIntoView({block:"start"}),!0):!1},[]);o.useEffect(()=>{const P=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,z=j.kind==="text"&&xs(P??"")&&me==="preview";if(!be||!z)return;const ie=requestAnimationFrame(()=>{Xn(be)&&Oe(null)});return()=>cancelAnimationFrame(ie)},[n,Xn,me,be,j,w]),o.useLayoutEffect(()=>{const P=re.current;if(!P||!E){he(null);return}if(oe)return;const z=j.kind==="image"||j.kind==="loading"&&j.mode==="image",ie=w&&n&&!n.startsWith("/")?`${w}/${n}`:n,xe=j.kind==="text"&&xs(ie??"")&&me==="preview",Ue=j.kind==="text"&&gs(ie??"")&&C==="preview";if(j.kind!=="text"||z||xe||Ue){he(null);return}const $e=()=>{const _e=K.current.get(E.end);if(!_e||!P){he(null);return}const nt=_e.offsetTop+_e.offsetHeight/2,at=P.scrollLeft+Math.max(8,P.clientWidth-120);he({top:nt,left:at})};$e();const ze=new ResizeObserver(()=>$e());return ze.observe(P),()=>ze.disconnect()},[E,oe,j,me,C,n,w,Le]);const zt=j.kind==="text"&&!(gs(ur??"")&&C==="preview")&&!ur?.toLowerCase().endsWith(".csv")&&!ur?.toLowerCase().endsWith(".kicad_pro")&&!ur?.toLowerCase().endsWith(".kicad_prl"),Kr=o.useCallback(()=>{lt(!1),vn(""),dr([]),yn(0),La()},[]),kt=o.useCallback(()=>{zt&&(lt(!0),requestAnimationFrame(()=>{wt.current?.focus(),wt.current?.select()}))},[zt]),Mr=o.useCallback(P=>{yn(z=>ht.length===0?0:(z+P+ht.length)%ht.length)},[ht.length]);if(o.useEffect(()=>{const P=z=>{const ie=Up(z);if(ie==="open"&&zt){z.preventDefault(),kt();return}Re&&(ie==="close"?(z.preventDefault(),Kr()):(ie==="next"||ie==="previous")&&(z.preventDefault(),Mr(ie==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[Kr,Re,Mr,kt,zt]),o.useLayoutEffect(()=>{if(La(),!Re||!Qe.trim()||!re.current){dr([]),yn(0);return}const P=zp(re.current,Qe);return dr(P),yn(0),nd(P,0),sd(P[0]),La},[Re,Qe,Le,me,j]),o.useEffect(()=>{Re&&(nd(ht,Yt),sd(ht[Yt]))},[Yt,ht,Re]),o.useEffect(()=>La,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.selectFilePrompt")});const Ie=w&&!n.startsWith("/")?`${w}/${n}`:n,Wt=Ua(Ie,w),$r=Td(Ie,w),hr=j.kind==="text"&&j.content?j.content.split(`
1654
+ `):[],eo=Math.max(2,String(hr.length).length)+1,St=j.kind==="text"||j.kind==="image"||j.kind==="model3d"||j.kind==="video"||j.kind==="eda"?j.meta:null,Ts=xs(Ie),$t=Ie.toLowerCase().endsWith(".csv"),Is=Ie.toLowerCase().endsWith(".kicad_pro"),Jt=Ie.toLowerCase().endsWith(".kicad_prl"),Vr=j.kind==="text"&&Ts&&me==="preview",Jn=gs(Ie),mr=j.kind==="text"&&Jn&&C==="preview",to=j.kind==="image"||j.kind==="loading"&&j.mode==="image",jt=j.kind==="model3d"||j.kind==="loading"&&j.mode==="model3d",Yr=j.kind==="video"||j.kind==="loading"&&j.mode==="video",Qn=j.kind==="eda"||j.kind==="loading"&&j.mode==="eda",Zn=j.kind==="text"?j.sourcePath:Ie,Er=Yh(Zn,w,E),Lr=(()=>{if(!E||j.kind!=="text"||hr.length===0)return Er;const P=[];for(let xe=E.start;xe<=E.end;xe+=1)P.push(`${xe} ${hr[xe-1]??""}`);const z=vu(Ie).replace(/^\./,""),ie="```";return`${Er}
1655
1655
  ${ie}${z}
1656
1656
  ${P.join(`
1657
1657
  `)}
1658
1658
  ${ie}
1659
- `})(),Pr=`path:${Te}`,Tt=E?`path:${Te}:${E.start}-${E.end}`:Pr,Xr=L===Pr,Jr=L===Tt,_s=A===Pr,Tr=A===Tt,gr=Jr||Tr,br=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,wn=P=>{const z=re.current;if(!z)return;const ie=z.getBoundingClientRect(),xe=P.currentTarget.getBoundingClientRect(),Ue=P.clientX||xe.left+xe.width/2,He=(P.clientY||xe.top+xe.height/2)-ie.top+z.scrollTop,De=g?116:132,nt=z.scrollLeft+Math.max(8,z.clientWidth-De),ot=Math.min(Math.max(8,Ue-ie.left+z.scrollLeft+10),nt);he({top:He,left:ot})},kn=(P,z)=>{Di()||(wn(P),$(ie=>{const xe=_i(ie,z,z);return xe||he(null),xe}))},xr=(P,z,ie)=>{wn(P),$(xe=>{const Ue=_i(xe,z,ie);return Ue||he(null),Ue})},Qt=(P,z,ie,xe)=>{xe==="end"&&wn(P),$({start:z,end:ie})},Me=P=>{const{scrollTop:z,scrollLeft:ie}=P.currentTarget;S(z),ii(w,n,{top:z,left:ie,markdownTop:z})},Zt=P=>{if(P.directory){m?.(P.path);return}if(P.path===Te||j.kind==="text"&&P.path===j.sourcePath){P.fragment&&Vn(P.fragment);return}we(z=>[...z,Te]),ce.current=P.path,Oe(P.fragment),$(null),O(P.path)},Qr=()=>{const P=V[V.length-1];P&&(we(z=>z.slice(0,-1)),ce.current=P,Oe(null),$(null),O(P))},Qn=P=>{const{scrollTop:z,scrollLeft:ie}=P.currentTarget;ii(w,n,{top:z,left:ie})},Sn=()=>{if(t){t(Ar,Tt);return}E&&l(Ar,Tt)},jn=async()=>{if(!(!Te||q.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){Se({status:"pending"});try{await _h(Te),Se({status:"idle"})}catch(P){Se({status:"error",message:P instanceof Error?P.message:a("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Ht.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Vr||pr)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a("rightSidebar.backToFileList"),title:a("rightSidebar.backToFileList"),children:e.jsx(Fd,{size:16})}),V.length>0&&e.jsxs("button",{type:"button",onClick:Qr,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${g?"w-9":"px-2.5"}`,"aria-label":a("rightSidebar.backToPreviousPreview"),title:a("rightSidebar.backToPreviousPreview"),children:[e.jsx(Ns,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:a("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Te,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Gt.name}),Gt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Gt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Wt&&e.jsx("button",{type:"button",onClick:Ce?Kr:kt,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 ${Ce?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":a("rightSidebar.findInFile"),title:`${a("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(qn,{size:14})}),Is&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{p&&y?.(),Re(P=>{const z=P==="preview"?"source":"preview";return vt(tu,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 ${g?"w-9 px-0":"px-3"}`,"aria-label":a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?me==="preview"?e.jsx(ki,{size:14}):e.jsx(wi,{size:14}):a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),Yn&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(P=>{const z=P==="preview"?"source":"preview";return cp(w,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 ${g?"w-9 px-0":"px-3"}`,"aria-label":a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?C==="preview"?e.jsx(ki,{size:14}):e.jsx(wi,{size:14}):a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),pr&&e.jsx("button",{type:"button",onClick:()=>{de.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a(Le?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:a(Le?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(Bd,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Te,Pr),...Ht(Er,Pr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Xr||_s?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:a("rightSidebar.insertReference",{reference:Er}),children:a(_s?"rightSidebar.copied":Xr?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(Er)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.copyReference",{reference:Er}),"aria-label":a("rightSidebar.copyFileRef"),children:e.jsx(kh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{jn()},disabled:q.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:q.status==="error"?q.message??a("rightSidebar.downloadFailed"):a("rightSidebar.downloadFile"),"aria-label":a("rightSidebar.downloadFile"),children:q.status==="pending"?e.jsx(at,{size:13,className:"animate-spin"}):e.jsx(Vh,{size:14})})]})]}),Ce&&Wt&&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:wt,type:"search",value:Qe,onChange:P=>xn(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),$r(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:a("rightSidebar.findInFilePlaceholder"),"aria-label":a("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:gt.length>0?`${Yt+1}/${gt.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>$r(-1),disabled:gt.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.previousSearchMatch"),title:`${a("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Pd,{size:13})}),e.jsx("button",{type:"button",onClick:()=>$r(1),disabled:gt.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.nextSearchMatch"),title:`${a("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Yh,{size:13})}),e.jsx("button",{type:"button",onClick:Kr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.closeFileSearch"),title:`${a("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Ut,{size:13})})]}),St&&!(g&&(Vr||pr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[St.size!==null&&e.jsx("span",{children:a("rightSidebar.byteCount",{count:St.size.toLocaleString()})}),"truncated"in St&&St.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:a("rightSidebar.previewTruncated")}),"mimeType"in St&&e.jsx("span",{children:St.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(g&&(Vr||pr))&&!jt&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:Xn?a("rightSidebar.edaPickHint"):Mt?a("rightSidebar.csvTablePreview"):Fs||Jt?a("rightSidebar.kicadProjectPickHint"):Yr?a("rightSidebar.videoPreviewHint"):no?a("rightSidebar.imagePreviewHint"):Vr?E?a("rightSidebar.selectedLineHint",{lineLabel:br??""}):a("rightSidebar.markdownPreviewHint"):pr?a("rightSidebar.htmlPreviewHint"):E?a("rightSidebar.selectedLineHint",{lineLabel:br??""}):a("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?a("rightSidebar.edaLoading"):j.mode==="image"?a("rightSidebar.loadingImage"):j.mode==="model3d"?a("rightSidebar.model3dLoading"):j.mode==="video"?a("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:yn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:a("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:a("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(Xd,{blobUrl:j.objectUrl,filePath:Te,viewLabel:"SVG 文件",onInsertAnnotation:d}):e.jsx(rf,{src:j.objectUrl,alt:Gt.name,vector:!1,onLoad:P=>{const z=P.currentTarget;Y(ie=>ie.kind==="image"?{...ie,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ie)},onError:()=>Y({kind:"error",message:a("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(mp,{url:j.url,onLoadError:()=>Y({kind:"error",message:a("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(wp,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Te.toLowerCase().endsWith(".kicad_pcb"),onViewChange:ae,onInsertAnnotation:t??d,onRefresh:yn,interactive3d:fe?e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(cd,{blobUrl:fe.objectUrl,ext:".glb",fileName:Gt.name,filePath:fe.sourcePath,features:null,onInsertFeature:t??d,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(cd,{blobUrl:j.objectUrl,ext:j.ext,fileName:Gt.name,filePath:j.sourcePath,features:M,onInsertFeature:t??d,onRefresh:yn})})}):j.kind==="text"&&Mt?e.jsx(jp,{content:j.content,filePath:Te,onInsertAnnotation:t??d},Te):j.kind==="text"&&(Fs||Jt)?e.jsx(Np,{content:j.content,filePath:Te,localState:Jt,onInsertAnnotation:t??d},Te):Vr?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:Me,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Gu,{content:j.content,filePath:j.sourcePath,rootPath:w,lineRange:E,onLineRangeClick:xr,onLineRangeDrag:Qt,scrollTop:se,outlineOpen:p,outlineCloseSignal:f,onOutlineOpen:k,onOutlineClose:y,lightboxOpen:N,lightboxCloseSignal:I,onLightboxOpen:_,onLightboxClose:B,onLocalLinkOpen:Zt}),E&&oe&&e.jsxs("button",{type:"button",onClick:Sn,...Ht(Ar,Tt),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:jd(g,gr),title:`Insert markdown reference: ${Lr}`,children:[e.jsx(Wa,{size:g?13:11}),Tr?a("rightSidebar.copied"):Jr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:br??""})]})]}):pr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Ip,{ref:de,src:Sh(Te),title:`${Gt.name} preview`,exitFullscreenLabel:a("rightSidebar.htmlFullscreenExit"),onFullscreenChange:We},`${Te}:${Xt}:${zt}`)}):j.kind==="text"?e.jsxs("div",{ref:re,onScroll:Qn,className:`${zi} 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:[mr.length>0?e.jsx("div",{className:"min-w-full",children:mr.map((P,z)=>{const ie=z+1,xe=!!(E&&ie>=E.start&&ie<=E.end),Ue=Ae&&Ae.length===mr.length?Ae[z]:null;return e.jsxs("div",{ref:$e=>{$e?K.current.set(ie,$e):K.current.delete(ie)},role:"button","data-file-preview-line":ie,tabIndex:0,onClick:$e=>kn($e,ie),onKeyDown:$e=>{$e.key!=="Enter"&&$e.key!==" "||($e.preventDefault(),kn($e,ie))},style:{gridTemplateColumns:`${ro}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${xe?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${Er}:${ie}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${xe?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ie}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ue??(P||" ")})]},z)})}):"Empty file.",E&&oe&&e.jsxs("button",{type:"button",onClick:Sn,...Ht(Ar,Tt),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:jd(g,gr),title:`Insert code reference: ${Lr}`,children:[e.jsx(Wa,{size:g?13:11}),Tr?a("rightSidebar.copied"):Jr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:br??""})]})]}):null]})}function xb({isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:d,pinned:c=!1,onTogglePinned:h,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:g,onOpenRightSidebarFilePreview:p,onCloseRightSidebarFilePreview:f,rightSidebarRepoPickerOpen:k=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:N,onCloseRightSidebarRepoPicker:I,markdownOutlineOpen:_=!1,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L=!1,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F}){const{t:a,locale:w}=pt(),[O,j]=o.useState(""),[Y,ne]=o.useState(null),ae=te(r=>r.rightSearchOpen),fe=te(r=>r.setRightSearchOpen),G=te(r=>r.rightSidebarLayoutPreference),J=te(r=>r.setRightSidebarLayoutPreference),[M,D]=o.useState(()=>dg()),[K,re]=o.useState("."),[oe,he]=o.useState(""),[me,Re]=o.useState(!1),[C,Z]=o.useState(!1),[de,Le]=o.useState(!1),[We,_e]=o.useState(!1),le=o.useDeferredValue(O),[se,S]=o.useState(null),[V,we]=o.useState([]),[be,Oe]=o.useState([]),[ce,Je]=o.useState(null),[Ae,W]=o.useState(null),[q,Se]=o.useState(null),[Ce,ct]=o.useState(null),[Qe,xn]=o.useState(()=>tt(sd,ks)??!1),[gt,ur]=o.useState(()=>tt(ad,ks)??!1),[Yt,vn]=o.useState(()=>tt(od,ks)??!1),[wt,Ht]=o.useState(()=>tt(ti,ag)??""),[qr,fr]=o.useState(0),[Xt,Pt]=o.useState(!1),[hr,zt]=o.useState(!1),Ts=o.useRef(null),yn=o.useRef(null),[Vn,Wt]=o.useState(!1),[Kr,kt]=o.useState(null),[$r,Te]=o.useState(null),[Gt,Er]=o.useState(()=>fd(Zo)),[mr,ro]=o.useState(()=>fd(nd)),[St,Is]=o.useState(()=>sg()),[Mt,Fs]=o.useState(()=>og()),[Jt,Vr]=o.useState(()=>lg()),Yn="words",[pr,no]=o.useState(0),[jt,Yr]=o.useState([]),[Xn,Jn]=o.useState([]),[Lr,Ar]=o.useState(!1),[Pr,Tt]=o.useState(null),[Xr,Jr]=o.useState([]),[_s,Tr]=o.useState(!1),[gr,br]=o.useState([]),[wn,kn]=o.useState([]),[xr,Qt]=o.useState(!1),[Me,Zt]=o.useState(null),[Qr,Qn]=o.useState([]),[Sn,jn]=o.useState({}),[P,z]=o.useState(!1),[ie,xe]=o.useState(null),[Ue,$e]=o.useState(null),[He,De]=o.useState(null),[nt,ot]=o.useState(null),[er,vr]=o.useState(!1),[Rn,Zr]=o.useState(""),Zn=o.useDeferredValue(Rn),[tr,rr]=o.useState([]),[Cn,en]=o.useState(!1),[Q,Be]=o.useState(!1),[nr,sr]=o.useState(null),[so,Nn]=o.useState(!1),ar=o.useRef(null),Ir=o.useRef(0),Zi=o.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[nf,Ds]=o.useState(null),[es,el]=o.useState(()=>tt(ei,ks)??!1),[ao,oo]=o.useState(!1),[Bs,io]=o.useState([]),[yr,Os]=o.useState({}),[Rt,Us]=o.useState({}),[Fr,tl]=o.useState(!0),[rl,nl]=o.useState(()=>new Set),[Ze,tn]=o.useState(null),[lo,rn]=o.useState(null),[sf,wr]=o.useState(!1),[sl,kr]=o.useState(0),[,co]=o.useState(0),[uo,Hs]=o.useState(!1),[or,fo]=o.useState(!1),[af,al]=o.useState(()=>te.getState().rightTab==="diff"),[Pe,ts]=o.useState(null),[Mn,rs]=o.useState(null),[dt,_r]=o.useState(null),[ol,ut]=o.useState(null),[$n,il]=o.useState(null),[ho,of]=o.useState(()=>Date.now()),[lf,cf]=o.useState(!1),[nn,zs]=o.useState(!1),[Ws,ll]=o.useState(""),[ns,Gs]=o.useState(""),[sn,qs]=o.useState(""),[an,Ks]=o.useState(""),[cl,En]=o.useState(null),[Vs,Ys]=o.useState(!1),[dl,mo]=o.useState(!1),[ul,fl]=o.useState(!1),[Xs,df]=o.useState({key:null,nonce:0}),hl=o.useRef(null),ml=o.useRef(null),ee=Dh(n,c,G),uf=fu(ee,c,Jt),[po,go]=o.useState(()=>xg(n)),bo=te(r=>r.rightTab),on=te(r=>r.setRightTab),b=te(r=>r.rootPath),Ln=te(r=>r.explorerRoot),pl=te(r=>r.pinnedExplorerRootsCache),gl=te(r=>r.hydratePinnedExplorerRoots),bl=te(r=>r.syncPinnedExplorerRoots),It=te(r=>r.setExplorerRoot),xl=te(r=>r.resetExplorerToProject),An=te(r=>r.pinExplorerRoot),ln=te(r=>r.unpinExplorerRoot),Ye=te(r=>r.selectedFilePath),Xe=te(r=>r.selectFile),xo=te(r=>r.showHiddenFiles),ff=te(r=>r.toggleShowHiddenFiles),vo=te(r=>!!(b&&r.nestedGitScanRoots[b])),ve=te(r=>r.changedFiles),Js=te(r=>r.setChangedFiles),Qs=te(r=>r.invalidateDirectoryCache),hf=te(r=>r.setDirectorySortMode),vl=te(r=>r.applyFileWatchEvents),yl=te(r=>r.reconcileDirectoryCache),wl=te(r=>r.bumpFileWatchEpoch),$t=te(r=>r.gitBundleLoading),Zs=te(r=>r.gitBundleSlow),Pn=te(r=>r.gitBundleError),Dr=te(r=>r.gitBundleLastLoadedAt),kl=te(r=>r.beginGitBundleLoading),Sl=te(r=>r.setGitBundleSlowFor),yo=te(r=>r.finishGitBundleLoading),jl=te(r=>r.resetGitBundleLoading),wo=te(r=>r.setGitBundleError),Rl=te(r=>r.markGitBundleLoaded),pe=Ln??b,Cl=o.useMemo(()=>pe?Op(pe,K):"",[pe,K]),ss=o.useMemo(()=>Bp(oe),[oe]),Nl=o.useMemo(()=>({excludePatterns:ss,caseSensitive:C,wholeWord:de,regex:We}),[C,ss,We,de]),ea=te(r=>pe?r.fileSortModes[pe]??"name":"name"),ta=te(r=>!!(pe&&r.directoryCache.has(pe))),Tn=o.useRef(null),Et=o.useRef(0),[Ml]=o.useState(()=>++fb),Sr=o.useRef(null),Br=o.useRef(null),ra=o.useRef(0),Ft=o.useRef(new Map),_t=o.useRef(new Map),ir=o.useRef(new Set),cn=o.useRef(new Set),dn=o.useRef(0),Or=o.useRef(null),In=o.useRef(0),Fn=o.useRef(null),_n=o.useRef(0),Ur=o.useRef(null),ko=o.useRef(new Set),So=o.useRef(null),jo=o.useRef(null),na=o.useRef(null),Ro=o.useRef(null);o.useEffect(()=>{if($n===null)return;const r=Math.max(0,Date.now()-$n),i=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,u=Math.max(50,i-r%i),x=window.setTimeout(()=>of(Date.now()),u);return()=>window.clearTimeout(x)},[ho,$n]);const sa=o.useRef(null),jr=o.useRef(null),aa=o.useRef(null),as=o.useRef(null),je=o.useCallback(r=>te.getState().rootPath===r,[]);o.useEffect(()=>{if(!t||typeof window>"u")return;const r=i=>{const u=gb(i.target);u&&Ba("global_change_row_event",{...bb(i),selectionPath:u.dataset.diffSelectionPath,filePath:u.dataset.diffFilePath,absolutePath:u.dataset.diffAbsolutePath,repoRoot:u.dataset.diffRepoRoot,status:u.dataset.diffStatus,selectedFilePath:te.getState().selectedFilePath,rightTab:te.getState().rightTab,activeGitRepoRoot:ce,changedFiles:te.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[ce,t]);const $l=o.useCallback(async(r=b??void 0)=>{if(!r)return null;if(ir.current.has(r)||cn.current.has(r))return et("untracked_skip_cached",{cwd:r,rootPath:b,completed:ir.current.has(r),running:cn.current.has(r)}),null;const i=b,u=ra.current+1;ra.current=u,Ft.current.set(r,u);const x=`right-sidebar-git-untracked:${r}`,v=new AbortController;_t.current.set(r,v),cn.current.add(r),et("untracked_start",{requestId:u,cwd:r,rootPath:b});try{let R=await _c(r,v.signal,x),T=0;for(;R.status==="running"&&T<120;){if(Ft.current.get(r)!==u||v.signal.aborted)return et("untracked_stale_result",{requestId:u,activeRequestId:Ft.current.get(r),cwd:r,status:R.status}),null;if(!je(i))return et("untracked_root_changed",{requestId:u,cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath}),null;await new Promise(X=>window.setTimeout(X,T<10?1e3:3e3)),T+=1,R=await _c(r,v.signal,x)}if(Ft.current.get(r)!==u||!je(i))return et("untracked_stale_result",{requestId:u,activeRequestId:Ft.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath,files:R.files.length,status:R.status}),null;if(R.status==="done")return Js(Yu(te.getState().changedFiles,R.files)),R.files.length>0&&we(X=>{const Ie=new Map(X.map(Ne=>[Ne.root,Ne])).get(r);if(!Ie)return X;const Ge=eb(Ie.files,R.files),Fe=X.map(Ne=>Ne.root===r?{...Ne,files:Ge,context:Ne.context?{...Ne.context,changedFiles:Ge.map(qe=>({path:qe.path,absolutePath:qe.absolutePath,status:qe.status})),truncated:!1}:Ne.context,untrackedDeferred:!1}:Ne);Oe(Xu(Fe,b));const ge=Fe.find(Ne=>Ne.root===b);return ge?.context&&S(Ne=>Ne?.root===ge.root?{...Ne,...ge.context}:Ne),Fe}),ir.current.add(r),et("untracked_apply",{requestId:u,cwd:r,files:R.files.length}),R;const H=R.error||(R.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ir.current.add(r),et("untracked_error",{requestId:u,cwd:r,message:H,code:R.code,status:R.status}),null}catch(R){if(Ft.current.get(r)!==u||!je(i)||dr(R))return et("untracked_aborted",{requestId:u,activeRequestId:Ft.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath,message:R instanceof Error?R.message:String(R)}),null;const T=R instanceof Error?R.message:"Failed to scan untracked files";return ir.current.add(r),et("untracked_error",{requestId:u,cwd:r,message:T}),null}finally{_t.current.get(r)===v&&_t.current.delete(r),Ft.current.get(r)===u&&Ft.current.delete(r),cn.current.delete(r)}},[se,je,b,Js]),qt=o.useMemo(()=>{const r=new Set(be.map(u=>u.root)),i=Xr.filter(u=>r.has(u));return i.length>0?i:ce?[ce]:[]},[ce,Xr,be]),El=qt.length===0,un=o.useMemo(()=>qt.map(r=>V.find(i=>i.root===r)).filter(r=>!!r),[qt,V]),mf=o.useMemo(()=>be.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[be]),lr=o.useCallback(async()=>{if(!b){Yr([]),Jn([]);return}const r=b,i=In.current+1;In.current=i,Fn.current?.abort();const u=new AbortController;Fn.current=u,Ar(jt.length===0),Tt(null);try{const x=qt.length>0?await Promise.all(qt.map(v=>Dc({workspaceRoot:b,repoRoot:v},u.signal))).then(v=>({records:v.flatMap(R=>R.records),walkthroughs:v.flatMap(R=>R.walkthroughs??[])})):await Dc({workspaceRoot:b},u.signal);if(In.current!==i||!je(r))return;Yr(x.records),Jn(x.walkthroughs??[])}catch(x){if(In.current!==i||!je(r)||dr(x))return;Tt(x instanceof Error?x.message:"Failed to load change audit explanations")}finally{Fn.current===u&&(Fn.current=null),In.current===i&&je(r)&&Ar(!1)}},[jt.length,qt,je,b]),oa=o.useCallback(async(r,i,u)=>{if(!r&&!b){br([]),kn([]);return}const x=b,v=_n.current+1;_n.current=v,Ur.current?.abort();const R=new AbortController;Ur.current=R;try{const T=r?[r]:Array.from(new Set([b,...V.map(X=>X.root)].filter(X=>!!X))),H=await Promise.all(T.map(X=>Rh({repoRoot:X,baseRef:i,branchName:u},R.signal))).then(X=>{const ke=new Map,Ie=new Map;for(const Ge of X){for(const Fe of Ge.records)ke.set(Fe.id,Fe);for(const Fe of Ge.walkthroughs??[])Ie.set(Fe.id,Fe)}return{records:Array.from(ke.values()),walkthroughs:Array.from(Ie.values())}});if(_n.current!==v||!je(x))return;br(H.records),kn(H.walkthroughs??[])}catch(T){if(_n.current!==v||!je(x)||dr(T))return;console.warn("[RightSidebar] Failed to load branch explanations",T)}finally{Ur.current===R&&(Ur.current=null)}},[V,je,b]),Hr=o.useCallback((r,i={})=>{if(!je(b)){et("apply_skipped_root_changed",{expectedRootPath:b,currentRootPath:te.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}et(r.files.length===0?"empty_bundle":"apply",{rootPath:b,available:r.available,files:r.files.length,repositories:r.repositories?.map(ge=>({root:ge.root,relativeRoot:ge.relativeRoot,files:ge.files.length,available:ge.available,error:ge.error})),repoFilters:r.repoFilters?.map(ge=>({root:ge.root,label:ge.label,count:ge.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let u=hu(r),x=r.repoFilters??[],v=r.files;const R=te.getState().changedFiles;if(!!(i.cacheOnly&&!r.cached&&r.files.length===0&&u.length===0)&&(R.size>0||V.length>0||se)){et("cache_only_apply_skipped_empty_backend_cache",{rootPath:b,currentFiles:R.size,currentRepositories:V.length});return}const H=u.some(ge=>ge.deferred);if(H&&!i.replaceWorkspace){const ge=new Set(u.filter(qe=>!qe.deferred||qe.root===b).map(qe=>qe.root));v=[...Array.from(R.values()).filter(qe=>!ge.has(lt(qe,b)??"")),...r.files]}const X=Rd(R.values(),b),ke=Rd(r.files,b),Ie=u.some(ge=>ge.root!==b);if(!!(i.background&&!H&&!i.replaceWorkspace&&R.size>0&&(r.files.length===0&&!r.error||X>0&&ke===0&&!Ie))){et("background_apply_skipped_degraded_bundle",{rootPath:b,currentFiles:R.size,nextFiles:r.files.length,currentNestedCount:X,nextNestedCount:ke,nextRepositories:u.map(ge=>({root:ge.root,relativeRoot:ge.relativeRoot,files:ge.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(i.replaceRepoRoot){const ge=Ju(R.values(),V,r,i.replaceRepoRoot,b);v=ge.files,u=ge.repositories,x=ge.repoFilters}if(Js(Vu(v)),we(u),Oe(x),i.syncActiveRepo!==!1){const ge=i.activeRepoRoot!==void 0?i.activeRepoRoot:ce??ud(b),Ne=fg({...r,repositories:u,repoFilters:x},ge);Je(Ne),ni(b,Ne)}typeof r.cacheUpdatedAt=="number"&&il(r.cacheUpdatedAt),S(ge=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==b)return ge;if(!r.context)return null;const Ne=ge?.root??b;return!ge?.available||Ne!==(r.context.root??b)?r.context:{...ge,...r.context}}),i.reloadDiff&&no(ge=>ge+1);const Fe=te.getState().selectedFilePath;if(Fe&&!Fe.startsWith("/")&&!v.some(ge=>ge.path===Fe||ge.absolutePath===Fe)&&Xe(null),Er(ge=>{const Ne=new Set(v.map(Ee=>lt(Ee,b)).filter(Boolean)),qe=new Set;for(const Ee of ge)Ne.has(Ee)&&qe.add(Ee);return si(Zo,qe),qe}),i.loadDeferred!==!1){const ge=u.filter(Ne=>Ne.untrackedDeferred&&Ne.root).map(Ne=>Ne.root);for(const Ne of ge)$l(Ne)}i.loadAudit!==!1&&lr()},[ce,je,lr,$l,b,Xe,Js]);o.useEffect(()=>{jl(),So.current=null,jo.current=b;const r=[],i=[],x=ud(b);Et.current+=1,dn.current+=1,ra.current+=1,Sr.current?.abort(),xt(Gn(Br.current?.cwd??b??void 0)),Br.current=null,Sr.current=null,Or.current?.abort(),xt("right-sidebar-git-details"),Or.current=null;for(const X of _t.current.values())X.abort();for(const X of _t.current.keys())xt(`right-sidebar-git-untracked:${X}`);_t.current.clear(),Ft.current.clear(),In.current+=1,Fn.current?.abort(),Fn.current=null,_n.current+=1,Ur.current?.abort(),Ur.current=null,Ir.current+=1,ar.current?.abort(),xt("right-sidebar-recent-commits"),ar.current=null,Yr([]),Jn([]),Ar(!1),Tt(null),Jr([]),Tr(!1),br([]),kn([]),Qt(!1),Zt(null),z(!1),xe(null),$e(null),De(null),ot(null),vr(!1),Zr(""),rr([]),en(!1),Be(!1),sr(null),Nn(!1),Ds(null),tn(null),rn(null),el(!1),vt(ei,!1),oo(!1);const v=b?hd()[b]:null,R=v?.previewEntries??[],T=v?.selectedPreviewKey??null,H=T?R.find(X=>X.key===T)??null:null;io(v?.selectedRepoRoots??[]),Os(v?.repoTargetBranches??{}),Us(v?.repoBaseBranches??{}),Qn(R),jn(v?.previewScrollTops??{}),H&&v?.previewDetailOpen&&(H.diff.hunks?.length??0)>0&&(Zt(H.diff),tn(H.key),rn(v.selectedPreviewFileKey??(H.diff.hunks?.[0]?`${H.diff.hunks[0].filePath}\0${H.diff.hunks[0].hunkHeader}\0${H.diff.hunks[0].hunkIndex}`:null)),Qt(!0)),tl(v?.includeUncommitted??!0),So.current=b,zs(!1),Je(x??null),ir.current.clear(),cn.current.clear(),ts(null),rs(null),_r(null),ut(null),il(null),we(r),Oe(i),S(null),Ro.current=null},[jl,b]);const Kt=o.useCallback(async(r=b??void 0,i={})=>{if(!r)return null;const u=b;try{await te.getState().hydrateNestedGitScanRoots()}catch{}const x=r===b&&zn(b),v=i.includeNested??x,R=i.refresh??i.reloadDiff??!1,T=i.cacheOnly??!1,H=i.background??!1,X=v&&(i.discoverOnly??!1);R&&ir.current.clear();const ke=Br.current;if(ke&&ke.cwd===r&&ke.includeNested===v&&ke.refresh===R&&ke.cacheOnly===T&&ke.discoverOnly===X)return et("reuse_pending",{cwd:r,includeNested:v,refresh:R,cacheOnly:T,discoverOnly:X}),ke.promise;const Ie=Et.current+1;Et.current=Ie;const Ge=`right-sidebar:${Ml}:${Ie}`;Sr.current?.abort();const Fe=Gn(r);xt(Fe);const ge=new AbortController;Sr.current=ge;let Ne=null;H||kl(Ge),wo(null),et("start",{requestId:Ie,cwd:r,rootPath:b,requestSlotId:Fe,includeNested:v,refresh:R,cacheOnly:T,background:H,existingChanges:ve.size,lastLoadedAt:Dr}),!H&&typeof window<"u"&&(Ne=window.setTimeout(()=>{Et.current===Ie&&Sl(Ge,!0)},Yp));const qe=(async()=>{const Ee=await Na(r,ge.signal,{includeNested:v,refresh:R,cacheOnly:T,discoverOnly:X,action:R?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:Fe,requestTimeoutMs:R?null:void 0});return nb(Ee)?(et("cancelled_result_ignored",{requestId:Ie,activeRequestId:Et.current,cwd:r,error:Ee.error??Ee.context?.error}),null):Et.current!==Ie||!je(u)?(et("stale_result",{requestId:Ie,activeRequestId:Et.current,cwd:r,expectedRootPath:u,currentRootPath:te.getState().rootPath,files:Ee.files.length,repositories:Ee.repositories?.length??0}),null):(Hr(Ee,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:v,background:H,cacheOnly:T,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),Ee)})();Br.current={cwd:r,includeNested:v,refresh:R,cacheOnly:T,discoverOnly:X,promise:qe};try{const Ee=await qe;return Et.current===Ie&&Ee&&je(u)?Rl({cached:Ee.cached,stale:Ee.stale,cacheAgeMs:Ee.cacheAgeMs,nestedDeferred:!v||Ee.nestedDeferred,untrackedDeferred:Ee.untrackedDeferred}):Et.current===Ie&&je(u)&&yo(Ge),Ee}catch(Ee){return Et.current!==Ie||!je(u)||dr(Ee)?(et("aborted",{requestId:Ie,activeRequestId:Et.current,cwd:r,expectedRootPath:u,currentRootPath:te.getState().rootPath,message:Ee instanceof Error?Ee.message:String(Ee)}),null):(et("error",{requestId:Ie,cwd:r,includeNested:v,refresh:R,background:H,message:Ee instanceof Error?Ee.message:String(Ee)}),H||(S(null),wo(Ee instanceof Error?Ee.message:"Failed to load Git changes")),null)}finally{Ne!==null&&window.clearTimeout(Ne),Sr.current===ge&&(Sr.current=null),Br.current?.promise===qe&&(Br.current=null),!H&&Et.current===Ie&&je(u)&&yo(Ge)}},[Hr,kl,ve.size,yo,Ml,Dr,je,Rl,b,wo,Sl]),os=o.useCallback(async()=>{b&&await Kt(b,{reloadDiff:!0,refresh:!0})},[Kt,b]),Co=o.useCallback(async(r=b??void 0)=>{if(!r)return null;const i=b,u=dn.current+1;dn.current=u,Or.current?.abort(),xt("right-sidebar-git-details");const x=new AbortController;Or.current=x,zs(!0);try{const v=await Bc(r,x.signal,"load_git_details","right-sidebar-git-details");return dn.current!==u||!je(i)?null:(we(R=>R.map(T=>T.root===v.root?{...T,available:v.available,context:v,error:v.error}:T)),S(R=>R?.root&&v.root&&R.root!==v.root?R:!R?.available||!v.available?v:{...R,...v}),v)}catch(v){return dr(v)||!je(i)||dn.current===u&&ut(v instanceof Error?v.message:"Failed to load Git details"),null}finally{Or.current===x&&(Or.current=null),dn.current===u&&je(i)&&zs(!1)}},[je,b]);o.useEffect(()=>{if(!t){Et.current+=1,dn.current+=1,ra.current+=1,Sr.current?.abort(),xt(Gn(Br.current?.cwd??b??void 0)),Br.current=null,Sr.current=null,Or.current?.abort(),xt("right-sidebar-git-details"),Or.current=null;for(const r of _t.current.values())r.abort();for(const r of _t.current.keys())xt(`right-sidebar-git-untracked:${r}`);_t.current.clear(),Ft.current.clear(),_n.current+=1,Ur.current?.abort(),Ur.current=null,Ir.current+=1,ar.current?.abort(),xt("right-sidebar-recent-commits"),ar.current=null,zs(!1),z(!1),xe(null),$e(null),De(null),ot(null),vr(!1),Zr(""),rr([]),en(!1),Be(!1),sr(null),Nn(!1),j(""),fe(!1),kt(null),fo(!1),ee&&al(!1)}},[ee,t,fe]),o.useEffect(()=>{if(!ae)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[ae]),o.useEffect(()=>{ee||wr(!1)},[ee]);const is=o.useCallback(r=>{co(r);const i=aa.current;i&&(i.update(),i.slideTo(r,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(r,0)}))},[]);o.useEffect(()=>{if(ee)if(wr(m),m&&Ye){kr(1);const r=jr.current;r&&(r.update(),r.activeIndex!==1&&(as.current=1,r.slideTo(1,0)))}else{kr(0);const r=jr.current;r&&r.activeIndex!==0&&(as.current=0,r.slideTo(0,0)),kt(null)}},[ee,m,b,Ye]),o.useEffect(()=>{if(g!==void 0&&!m){kr(0);const r=jr.current;r&&r.activeIndex!==0&&(as.current=0,r.slideTo(0,0)),wr(!1),kt(null)}},[g,m]),o.useEffect(()=>{y!==void 0&&W(null)},[y]),o.useEffect(()=>{!ee&&m&&f?.()},[ee,f,m]),o.useEffect(()=>{go(r=>Ei(r,n))},[n]);const pf=o.useCallback(r=>{ee||(r.preventDefault(),sa.current={startX:r.clientX,startWidth:po,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[po,ee]),gf=o.useCallback(r=>{const i=sa.current;if(!i||i.pointerId!==r.pointerId)return;const u=Ei(i.startWidth+r.clientX-i.startX,n);go(u),Ss(ws,u,Vp)},[n]),Ll=o.useCallback(r=>{const i=sa.current;if(!(!i||i.pointerId!==r.pointerId)){sa.current=null,bs(ws);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),ls=!!(b&&Dr!==null&&Md(se)),Rr=ls?"files":bo,Ke=Rr==="git",Dn=Rr==="files",ft=Rr==="diff";o.useEffect(()=>{if(!ee){Hs(!0);return}if(!t){const i=window.setTimeout(()=>{Hs(!1)},Jp);return()=>window.clearTimeout(i)}Hs(!1);const r=window.setTimeout(()=>{Hs(!0)},Xp);return()=>window.clearTimeout(r)},[ee,t]),o.useEffect(()=>{if(!ee||!ft)return;const r=aa.current;if(!r)return;const i=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(i)},[ft,ee]),o.useEffect(()=>{if(!ls||!b||$t)return;const r=window.setTimeout(()=>{Kt(b,{background:!0})},3e3);return()=>window.clearTimeout(r)},[ls,b,$t,Kt]),o.useEffect(()=>{if(!(t&&(Ke||ft))||!b||$t||!ta||Ro.current===b)return;Ro.current=b;const i=Ke&&!ee?0:ri,u=window.setTimeout(()=>{Kt(b,{background:!0,discoverOnly:!0})},i);return()=>{window.clearTimeout(u)}},[ft,$t,Ke,ee,t,Kt,ta,b]),o.useEffect(()=>{!t||!Ke||(!ee||uo)&&fo(!0)},[Ke,ee,t,uo]),o.useEffect(()=>{if(!t||Ke)return;const r=window.setTimeout(()=>{fo(!0)},ri);return()=>window.clearTimeout(r)},[Ke,t]),o.useEffect(()=>{ft&&al(!0)},[ft]);const Al=o.useCallback(r=>{pe&&Yg(pe,r.currentTarget.scrollTop)},[pe]);o.useEffect(()=>()=>{Sr.current?.abort(),bs(Ui),bs(Hi),bs(ws),bs(ti)},[]),o.useEffect(()=>{if(!pe||!ta)return;const r=qu()[pe]?.top;if(typeof r!="number")return;let i=window.requestAnimationFrame(()=>{Tn.current&&(Tn.current.scrollTop=r),i=window.requestAnimationFrame(()=>{Tn.current&&(Tn.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(i)},[pe,ta]),o.useEffect(()=>{if(!t)return;const r=new AbortController;return Ch(r.signal).then(i=>fl(!!i.available)).catch(()=>fl(!1)),()=>r.abort()},[t]);const cs=o.useCallback(r=>{if(ne(null),Xe(r),kt(null),ee){wr(!0),kr(1),jr.current?.slideTo(1),p?.();return}},[ee,p,Xe]),Pl=o.useCallback((r,i)=>{if(ne(null),Xe(r),Te(i),ee){wr(!0),kr(1),jr.current?.slideTo(1),p?.();return}},[ee,p,Xe]),ds=o.useCallback(async(r,i)=>{const u=i||Ln||b;if(!(!u||r.length===0)){Ys(!0);try{await Yo(u,r),Qs(u,!1)}catch(x){ut(x instanceof Error?x.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>ut(null),4e3)}finally{Ys(!1)}}},[Ln,b,Qs,a]),Tl=o.useCallback(async r=>{try{await Nh(r)}catch(i){ut(i instanceof Error?i.message:a("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>ut(null),4e3)}},[a]),ia=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&mo(!0)},[]),Il=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),mo(!1)},[]),Fl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),mo(!1);const i=r.dataTransfer.files;i.length>0&&ds(Array.from(i))},[ds]),No=o.useCallback(r=>{Se(r),window.setTimeout(()=>Se(i=>i===r?null:i),1400)},[]),Cr=o.useCallback(r=>{ct(r),window.setTimeout(()=>ct(i=>i===r?null:i),1400)},[]);o.useEffect(()=>{vt(sd,Qe)},[Qe]),o.useEffect(()=>{vt(ad,gt)},[gt]),o.useEffect(()=>{vt(od,Yt)},[Yt]),o.useEffect(()=>{Ss(ti,wt,zp)},[wt]),o.useEffect(()=>(gl().catch(()=>{}),Hc(r=>{r.type==="pinned-explorer-roots"&&bl(r.pinnedExplorerRoots)})),[gl,bl]);const _l=o.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),la=o.useRef(null),fn=o.useRef(null),[Dl,Mo]=o.useState(!1);o.useEffect(()=>{if(!t)return;Mo(!1);let r=!1;Mh().then(u=>{r||(la.current=u.text,Ht(x=>u.text&&u.text!==x?u.text:x),Mo(!0))}).catch(()=>{r||Mo(!0)});const i=Hc(u=>{u.type==="context-draft"&&u.origin!==_l.current&&(la.current=u.text,Ht(u.text))});return()=>{r=!0,i(),fn.current!==null&&(window.clearTimeout(fn.current),fn.current=null)}},[t]),o.useEffect(()=>{if(!Dl||la.current===wt)return;fn.current!==null&&window.clearTimeout(fn.current);const r=wt;fn.current=window.setTimeout(()=>{fn.current=null,$h(r,_l.current).then(()=>{la.current=r}).catch(()=>{})},500)},[wt,Dl]);const Bn=o.useCallback((r,i,u)=>{if(r){if(Eh(u?r+u:r)){No(i);return}Qe?(Ht(x=>op(x,r)+(u??"")),window.matchMedia("(pointer: coarse)").matches||(ur(!1),fr(x=>x+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:u?r+u:r,focus:!0}})),No(i)}},[Qe,No]),ca=o.useCallback(r=>{const i=$a(r,b);return Xh(i,b)},[b]),$o=Gd(Cr),zr=o.useCallback((r,i)=>{const u=$a(r,b);Bn(Jh(u,b),i??`path:${u}`)},[b,Bn]),bf=o.useCallback(async r=>{Ys(!0);try{await Qh(r,Yo,i=>{zr(i,`path:${i}`)}),ee&&!Qe&&s()}catch(i){ut(i instanceof Error?i.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>ut(null),4e3)}finally{Ys(!1)}},[Qe,zr,ee,s,a]),Nr=o.useCallback((r,i)=>{if(!r)return;const u=r.includes(`
1659
+ `})(),Ar=`path:${Ie}`,Pt=E?`path:${Ie}:${E.start}-${E.end}`:Ar,Xr=L===Ar,Jr=L===Pt,Fs=A===Ar,Pr=A===Pt,pr=Jr||Pr,gr=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,kn=P=>{const z=re.current;if(!z)return;const ie=z.getBoundingClientRect(),xe=P.currentTarget.getBoundingClientRect(),Ue=P.clientX||xe.left+xe.width/2,ze=(P.clientY||xe.top+xe.height/2)-ie.top+z.scrollTop,_e=g?116:132,nt=z.scrollLeft+Math.max(8,z.clientWidth-_e),at=Math.min(Math.max(8,Ue-ie.left+z.scrollLeft+10),nt);he({top:ze,left:at})},Sn=(P,z)=>{_i()||(kn(P),$(ie=>{const xe=Di(ie,z,z);return xe||he(null),xe}))},br=(P,z,ie)=>{kn(P),$(xe=>{const Ue=Di(xe,z,ie);return Ue||he(null),Ue})},Qt=(P,z,ie,xe)=>{xe==="end"&&kn(P),$({start:z,end:ie})},Me=P=>{const{scrollTop:z,scrollLeft:ie}=P.currentTarget;S(z),oi(w,n,{top:z,left:ie,markdownTop:z})},Zt=P=>{if(P.directory){m?.(P.path);return}if(P.path===Ie||j.kind==="text"&&P.path===j.sourcePath){P.fragment&&Xn(P.fragment);return}ye(z=>[...z,Ie]),ce.current=P.path,Oe(P.fragment),$(null),O(P.path)},Qr=()=>{const P=V[V.length-1];P&&(ye(z=>z.slice(0,-1)),ce.current=P,Oe(null),$(null),O(P))},es=P=>{const{scrollTop:z,scrollLeft:ie}=P.currentTarget;oi(w,n,{top:z,left:ie})},jn=()=>{if(t){t(Lr,Pt);return}E&&l(Lr,Pt)},Rn=async()=>{if(!(!Ie||q.status==="pending")&&!(j.kind==="loading"||j.kind==="error")){Se({status:"pending"});try{await Bh(Ie),Se({status:"idle"})}catch(P){Se({status:"error",message:P instanceof Error?P.message:a("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[Ut.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Vr||mr)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a("rightSidebar.backToFileList"),title:a("rightSidebar.backToFileList"),children:e.jsx(_d,{size:16})}),V.length>0&&e.jsxs("button",{type:"button",onClick:Qr,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${g?"w-9":"px-2.5"}`,"aria-label":a("rightSidebar.backToPreviousPreview"),title:a("rightSidebar.backToPreviousPreview"),children:[e.jsx(Cs,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:a("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Ie,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Wt.name}),Wt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Wt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[zt&&e.jsx("button",{type:"button",onClick:Re?Kr:kt,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${Re?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":a("rightSidebar.findInFile"),title:`${a("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Vn,{size:14})}),Ts&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{p&&y?.(),je(P=>{const z=P==="preview"?"source":"preview";return xt(nu,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 ${g?"w-9 px-0":"px-3"}`,"aria-label":a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?me==="preview"?e.jsx(ki,{size:14}):e.jsx(wi,{size:14}):a(me==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),Jn&&j.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(P=>{const z=P==="preview"?"source":"preview";return mp(w,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 ${g?"w-9 px-0":"px-3"}`,"aria-label":a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?C==="preview"?e.jsx(ki,{size:14}):e.jsx(wi,{size:14}):a(C==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),mr&&e.jsx("button",{type:"button",onClick:()=>{de.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:a(Ee?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(Ud,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Ie,Ar),...Ut($r,Ar),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Xr||Fs?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:a("rightSidebar.insertReference",{reference:$r}),children:a(Fs?"rightSidebar.copied":Xr?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText($r)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.copyReference",{reference:$r}),"aria-label":a("rightSidebar.copyFileRef"),children:e.jsx(jh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{Rn()},disabled:q.status==="pending"||j.kind==="loading"||j.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:q.status==="error"?q.message??a("rightSidebar.downloadFailed"):a("rightSidebar.downloadFile"),"aria-label":a("rightSidebar.downloadFile"),children:q.status==="pending"?e.jsx(vt,{size:13,className:"animate-spin"}):e.jsx(Xh,{size:14})})]})]}),Re&&zt&&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(Vn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:wt,type:"search",value:Qe,onChange:P=>vn(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),Mr(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:a("rightSidebar.findInFilePlaceholder"),"aria-label":a("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ht.length>0?`${Yt+1}/${ht.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>Mr(-1),disabled:ht.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.previousSearchMatch"),title:`${a("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(Id,{size:13})}),e.jsx("button",{type:"button",onClick:()=>Mr(1),disabled:ht.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":a("rightSidebar.nextSearchMatch"),title:`${a("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Jh,{size:13})}),e.jsx("button",{type:"button",onClick:Kr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.closeFileSearch"),title:`${a("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Ot,{size:13})})]}),St&&!(g&&(Vr||mr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[St.size!==null&&e.jsx("span",{children:a("rightSidebar.byteCount",{count:St.size.toLocaleString()})}),"truncated"in St&&St.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:a("rightSidebar.previewTruncated")}),"mimeType"in St&&e.jsx("span",{children:St.mimeType}),"dimensions"in j&&j.dimensions&&e.jsxs("span",{children:[j.dimensions.width," × ",j.dimensions.height]})]}),!(g&&(Vr||mr))&&!jt&&j.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:Qn?a("rightSidebar.edaPickHint"):$t?a("rightSidebar.csvTablePreview"):Is||Jt?a("rightSidebar.kicadProjectPickHint"):Yr?a("rightSidebar.videoPreviewHint"):to?a("rightSidebar.imagePreviewHint"):Vr?E?a("rightSidebar.selectedLineHint",{lineLabel:gr??""}):a("rightSidebar.markdownPreviewHint"):mr?a("rightSidebar.htmlPreviewHint"):E?a("rightSidebar.selectedLineHint",{lineLabel:gr??""}):a("rightSidebar.multiLineHint")})})]}),j.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:j.mode==="eda"?a("rightSidebar.edaLoading"):j.mode==="image"?a("rightSidebar.loadingImage"):j.mode==="model3d"?a("rightSidebar.model3dLoading"):j.mode==="video"?a("rightSidebar.loadingVideo"):"Loading file…"}):j.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:j.message}),e.jsx("button",{type:"button",onClick:wn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:a("common.retry")})]}):j.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:a("rightSidebar.binaryPreviewHint")})}):j.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:j.meta.mimeType==="image/svg+xml"?e.jsx(Qd,{blobUrl:j.objectUrl,filePath:Ie,viewLabel:"SVG 文件",onInsertAnnotation:d}):e.jsx(sf,{src:j.objectUrl,alt:Wt.name,vector:!1,onLoad:P=>{const z=P.currentTarget;X(ie=>ie.kind==="image"?{...ie,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ie)},onError:()=>X({kind:"error",message:a("rightSidebar.imageLoadFailed")})})}):j.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(vp,{url:j.url,onLoadError:()=>X({kind:"error",message:a("rightSidebar.videoLoadFailed")})})}):j.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Cp,{blobUrl:j.objectUrl,filePath:j.sourcePath,view:j.view,board:Ie.toLowerCase().endsWith(".kicad_pcb"),onViewChange:se,onInsertAnnotation:t??d,onRefresh:wn,interactive3d:fe?e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(ud,{blobUrl:fe.objectUrl,ext:".glb",fileName:Wt.name,filePath:fe.sourcePath,features:null,onInsertFeature:t??d,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:j.view==="pcb-3d"})}):void 0})}):j.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:a("rightSidebar.model3dLoading")}),children:e.jsx(ud,{blobUrl:j.objectUrl,ext:j.ext,fileName:Wt.name,filePath:j.sourcePath,features:M,onInsertFeature:t??d,onRefresh:wn})})}):j.kind==="text"&&$t?e.jsx($p,{content:j.content,filePath:Ie,onInsertAnnotation:t??d},Ie):j.kind==="text"&&(Is||Jt)?e.jsx(Ap,{content:j.content,filePath:Ie,localState:Jt,onInsertAnnotation:t??d},Ie):Vr?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:Me,style:{touchAction:"pan-x pan-y"},children:[e.jsx(Ku,{content:j.content,filePath:j.sourcePath,rootPath:w,lineRange:E,onLineRangeClick:br,onLineRangeDrag:Qt,scrollTop:ae,outlineOpen:p,outlineCloseSignal:f,onOutlineOpen:k,onOutlineClose:y,lightboxOpen:N,lightboxCloseSignal:I,onLightboxOpen:D,onLightboxClose:B,onLocalLinkOpen:Zt}),E&&oe&&e.jsxs("button",{type:"button",onClick:jn,...Ut(Lr,Pt),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Cd(g,pr),title:`Insert markdown reference: ${Er}`,children:[e.jsx(Ha,{size:g?13:11}),Pr?a("rightSidebar.copied"):Jr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:gr??""})]})]}):mr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Op,{ref:de,src:Rh(Ie),title:`${Wt.name} preview`,exitFullscreenLabel:a("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Ge},`${Ie}:${Xt}:${Ht}`)}):j.kind==="text"?e.jsxs("div",{ref:re,onScroll:es,className:`${zi} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[hr.length>0?e.jsx("div",{className:"min-w-full",children:hr.map((P,z)=>{const ie=z+1,xe=!!(E&&ie>=E.start&&ie<=E.end),Ue=Le&&Le.length===hr.length?Le[z]:null;return e.jsxs("div",{ref:$e=>{$e?K.current.set(ie,$e):K.current.delete(ie)},role:"button","data-file-preview-line":ie,tabIndex:0,onClick:$e=>Sn($e,ie),onKeyDown:$e=>{$e.key!=="Enter"&&$e.key!==" "||($e.preventDefault(),Sn($e,ie))},style:{gridTemplateColumns:`${eo}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${xe?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${$r}:${ie}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${xe?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ie}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:Ue??(P||" ")})]},z)})}):"Empty file.",E&&oe&&e.jsxs("button",{type:"button",onClick:jn,...Ut(Lr,Pt),style:{top:oe.top,left:oe.left,transform:"translateY(-50%)"},className:Cd(g,pr),title:`Insert code reference: ${Er}`,children:[e.jsx(Ha,{size:g?13:11}),Pr?a("rightSidebar.copied"):Jr?a("rightSidebar.inserted"):a("rightSidebar.insertLineRef",{lineLabel:gr??""})]})]}):null]})}function Sb({isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:d,pinned:c=!1,onTogglePinned:h,rightSidebarFilePreviewOpen:m=!1,rightSidebarFilePreviewCloseSignal:g,onOpenRightSidebarFilePreview:p,onCloseRightSidebarFilePreview:f,rightSidebarRepoPickerOpen:k=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:N,onCloseRightSidebarRepoPicker:I,markdownOutlineOpen:D=!1,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L=!1,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F}){const{t:a,locale:w}=yt(),[O,j]=o.useState(""),[X,ne]=o.useState(null),se=te(r=>r.rightSearchOpen),fe=te(r=>r.setRightSearchOpen),G=te(r=>r.rightSidebarLayoutPreference),J=te(r=>r.setRightSidebarLayoutPreference),[M,_]=o.useState(()=>pg()),[K,re]=o.useState("."),[oe,he]=o.useState(""),[me,je]=o.useState(!1),[C,Z]=o.useState(!1),[de,Ee]=o.useState(!1),[Ge,De]=o.useState(!1),le=o.useDeferredValue(O),[ae,S]=o.useState(null),[V,ye]=o.useState([]),[be,Oe]=o.useState([]),[ce,Je]=o.useState(null),[Le,W]=o.useState(null),[q,Se]=o.useState(null),[Re,lt]=o.useState(null),[Qe,vn]=o.useState(()=>tt(od,ws)??!1),[ht,dr]=o.useState(()=>tt(id,ws)??!1),[Yt,yn]=o.useState(()=>tt(ld,ws)??!1),[wt,Ut]=o.useState(()=>tt(ei,dg)??""),[qr,ur]=o.useState(0),[Xt,At]=o.useState(!1),[fr,Ht]=o.useState(!1),Ps=o.useRef(null),wn=o.useRef(null),[Xn,zt]=o.useState(!1),[Kr,kt]=o.useState(null),[Mr,Ie]=o.useState(null),[Wt,$r]=o.useState(()=>md(Qo)),[hr,eo]=o.useState(()=>md(ad)),[St,Ts]=o.useState(()=>cg()),[$t,Is]=o.useState(()=>ug()),[Jt,Vr]=o.useState(()=>hg()),Jn="words",[mr,to]=o.useState(0),[jt,Yr]=o.useState([]),[Qn,Zn]=o.useState([]),[Er,Lr]=o.useState(!1),[Ar,Pt]=o.useState(null),[Xr,Jr]=o.useState([]),[Fs,Pr]=o.useState(!1),[pr,gr]=o.useState([]),[kn,Sn]=o.useState([]),[br,Qt]=o.useState(!1),[Me,Zt]=o.useState(null),[Qr,es]=o.useState([]),[jn,Rn]=o.useState({}),[P,z]=o.useState(!1),[ie,xe]=o.useState(null),[Ue,$e]=o.useState(null),[ze,_e]=o.useState(null),[nt,at]=o.useState(null),[er,xr]=o.useState(!1),[Cn,Zr]=o.useState(""),ts=o.useDeferredValue(Cn),[tr,rr]=o.useState([]),[Nn,en]=o.useState(!1),[Q,Be]=o.useState(!1),[nr,sr]=o.useState(null),[ro,Mn]=o.useState(!1),ar=o.useRef(null),Tr=o.useRef(0),Zi=o.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[af,Ds]=o.useState(null),[rs,el]=o.useState(()=>tt(Zo,ws)??!1),[no,so]=o.useState(!1),[_s,ao]=o.useState([]),[vr,Bs]=o.useState({}),[Rt,Os]=o.useState({}),[Ir,tl]=o.useState(!0),[rl,nl]=o.useState(()=>new Set),[Ze,tn]=o.useState(null),[oo,rn]=o.useState(null),[of,yr]=o.useState(!1),[sl,wr]=o.useState(0),[,io]=o.useState(0),[lo,Us]=o.useState(!1),[or,co]=o.useState(!1),[lf,al]=o.useState(()=>te.getState().rightTab==="diff"),[Ae,ns]=o.useState(null),[$n,ss]=o.useState(null),[ct,Fr]=o.useState(null),[ol,dt]=o.useState(null),[En,il]=o.useState(null),[uo,cf]=o.useState(()=>Date.now()),[df,uf]=o.useState(!1),[nn,Hs]=o.useState(!1),[zs,ll]=o.useState(""),[Ln,Ws]=o.useState(""),[sn,Gs]=o.useState(""),[an,qs]=o.useState(""),[cl,An]=o.useState(null),[Ks,Vs]=o.useState(!1),[dl,fo]=o.useState(!1),[ul,fl]=o.useState(!1),[Ys,ff]=o.useState({key:null,nonce:0}),hl=o.useRef(null),ml=o.useRef(null),ee=Oh(n,c,G),hf=mu(ee,c,Jt),[ho,mo]=o.useState(()=>Sg(n)),po=te(r=>r.rightTab),on=te(r=>r.setRightTab),b=te(r=>r.rootPath),Pn=te(r=>r.explorerRoot),pl=te(r=>r.pinnedExplorerRootsCache),gl=te(r=>r.hydratePinnedExplorerRoots),bl=te(r=>r.syncPinnedExplorerRoots),Tt=te(r=>r.setExplorerRoot),xl=te(r=>r.resetExplorerToProject),Tn=te(r=>r.pinExplorerRoot),ln=te(r=>r.unpinExplorerRoot),Ve=te(r=>r.selectedFilePath),Ye=te(r=>r.selectFile),go=te(r=>r.showHiddenFiles),mf=te(r=>r.toggleShowHiddenFiles),bo=te(r=>!!(b&&r.nestedGitScanRoots[b])),we=te(r=>r.changedFiles),Xs=te(r=>r.setChangedFiles),Js=te(r=>r.invalidateDirectoryCache),pf=te(r=>r.setDirectorySortMode),vl=te(r=>r.applyFileWatchEvents),yl=te(r=>r.reconcileDirectoryCache),wl=te(r=>r.bumpFileWatchEpoch),Dr=te(r=>r.gitBundleLoading),kl=te(r=>r.gitBundleSlow),cn=te(r=>r.gitBundleError),In=te(r=>r.gitBundleLastLoadedAt),Sl=te(r=>r.beginGitBundleLoading),jl=te(r=>r.setGitBundleSlowFor),xo=te(r=>r.finishGitBundleLoading),Qs=te(r=>r.resetGitBundleLoading),vo=te(r=>r.setGitBundleError),Rl=te(r=>r.markGitBundleLoaded),pe=Pn??b,Cl=o.useMemo(()=>pe?Gp(pe,K):"",[pe,K]),as=o.useMemo(()=>Wp(oe),[oe]),Nl=o.useMemo(()=>({excludePatterns:as,caseSensitive:C,wholeWord:de,regex:Ge}),[C,as,Ge,de]),Zs=te(r=>pe?r.fileSortModes[pe]??"name":"name"),Ml=te(r=>!!(pe&&r.directoryCache.has(pe))),Fn=o.useRef(null),mt=o.useRef(0),[$l]=o.useState(()=>++bb),kr=o.useRef(null),_r=o.useRef(null),ea=o.useRef(0),It=o.useRef(new Map),Ft=o.useRef(new Map),ir=o.useRef(new Set),dn=o.useRef(new Set),un=o.useRef(0),Br=o.useRef(null),Dn=o.useRef(0),_n=o.useRef(null),Bn=o.useRef(0),Or=o.useRef(null),yo=o.useRef(new Set),wo=o.useRef(null),ko=o.useRef(null),ta=o.useRef(null),So=o.useRef(null);o.useEffect(()=>{if(En===null)return;const r=Math.max(0,Date.now()-En),i=r<6e4?1e3:r<36e5?6e4:r<864e5?36e5:864e5,u=Math.max(50,i-r%i),x=window.setTimeout(()=>cf(Date.now()),u);return()=>window.clearTimeout(x)},[uo,En]);const ra=o.useRef(null),Sr=o.useRef(null),na=o.useRef(null),os=o.useRef(null),ke=o.useCallback(r=>te.getState().rootPath===r,[]);o.useEffect(()=>{if(!t||typeof window>"u")return;const r=i=>{const u=wb(i.target);u&&Da("global_change_row_event",{...kb(i),selectionPath:u.dataset.diffSelectionPath,filePath:u.dataset.diffFilePath,absolutePath:u.dataset.diffAbsolutePath,repoRoot:u.dataset.diffRepoRoot,status:u.dataset.diffStatus,selectedFilePath:te.getState().selectedFilePath,rightTab:te.getState().rightTab,activeGitRepoRoot:ce,changedFiles:te.getState().changedFiles.size})};return window.addEventListener("pointerdown",r,{capture:!0}),window.addEventListener("click",r,{capture:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("click",r,{capture:!0})}},[ce,t]);const El=o.useCallback(async(r=b??void 0)=>{if(!r)return null;if(ir.current.has(r)||dn.current.has(r))return et("untracked_skip_cached",{cwd:r,rootPath:b,completed:ir.current.has(r),running:dn.current.has(r)}),null;const i=b,u=ea.current+1;ea.current=u,It.current.set(r,u);const x=`right-sidebar-git-untracked:${r}`,v=new AbortController;Ft.current.set(r,v),dn.current.add(r),et("untracked_start",{requestId:u,cwd:r,rootPath:b});try{let R=await Bc(r,v.signal,x),T=0;for(;R.status==="running"&&T<120;){if(It.current.get(r)!==u||v.signal.aborted)return et("untracked_stale_result",{requestId:u,activeRequestId:It.current.get(r),cwd:r,status:R.status}),null;if(!ke(i))return et("untracked_root_changed",{requestId:u,cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath}),null;await new Promise(Y=>window.setTimeout(Y,T<10?1e3:3e3)),T+=1,R=await Bc(r,v.signal,x)}if(It.current.get(r)!==u||!ke(i))return et("untracked_stale_result",{requestId:u,activeRequestId:It.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath,files:R.files.length,status:R.status}),null;if(R.status==="done")return Xs(Ju(te.getState().changedFiles,R.files)),R.files.length>0&&ye(Y=>{const He=new Map(Y.map(Ne=>[Ne.root,Ne])).get(r);if(!He)return Y;const Pe=ab(He.files,R.files),Fe=Y.map(Ne=>Ne.root===r?{...Ne,files:Pe,context:Ne.context?{...Ne.context,changedFiles:Pe.map(qe=>({path:qe.path,absolutePath:qe.absolutePath,status:qe.status})),truncated:!1}:Ne.context,untrackedDeferred:!1}:Ne);Oe(Qu(Fe,b));const ge=Fe.find(Ne=>Ne.root===b);return ge?.context&&S(Ne=>Ne?.root===ge.root?{...Ne,...ge.context}:Ne),Fe}),ir.current.add(r),et("untracked_apply",{requestId:u,cwd:r,files:R.files.length}),R;const H=R.error||(R.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ir.current.add(r),et("untracked_error",{requestId:u,cwd:r,message:H,code:R.code,status:R.status}),null}catch(R){if(It.current.get(r)!==u||!ke(i)||Nr(R))return et("untracked_aborted",{requestId:u,activeRequestId:It.current.get(r),cwd:r,expectedRootPath:i,currentRootPath:te.getState().rootPath,message:R instanceof Error?R.message:String(R)}),null;const T=R instanceof Error?R.message:"Failed to scan untracked files";return ir.current.add(r),et("untracked_error",{requestId:u,cwd:r,message:T}),null}finally{Ft.current.get(r)===v&&Ft.current.delete(r),It.current.get(r)===u&&It.current.delete(r),dn.current.delete(r)}},[ae,ke,b,Xs]),Gt=o.useMemo(()=>{const r=new Set(be.map(u=>u.root)),i=Xr.filter(u=>r.has(u));return i.length>0?i:ce?[ce]:[]},[ce,Xr,be]),Ll=Gt.length===0,fn=o.useMemo(()=>Gt.map(r=>V.find(i=>i.root===r)).filter(r=>!!r),[Gt,V]),gf=o.useMemo(()=>be.map(r=>({root:r.root,label:r.label,branch:r.branch??null})),[be]),lr=o.useCallback(async()=>{if(!b){Yr([]),Zn([]);return}const r=b,i=Dn.current+1;Dn.current=i,_n.current?.abort();const u=new AbortController;_n.current=u,Lr(jt.length===0),Pt(null);try{const x=Gt.length>0?await Promise.all(Gt.map(v=>Oc({workspaceRoot:b,repoRoot:v},u.signal))).then(v=>({records:v.flatMap(R=>R.records),walkthroughs:v.flatMap(R=>R.walkthroughs??[])})):await Oc({workspaceRoot:b},u.signal);if(Dn.current!==i||!ke(r))return;Yr(x.records),Zn(x.walkthroughs??[])}catch(x){if(Dn.current!==i||!ke(r)||Nr(x))return;Pt(x instanceof Error?x.message:"Failed to load change audit explanations")}finally{_n.current===u&&(_n.current=null),Dn.current===i&&ke(r)&&Lr(!1)}},[jt.length,Gt,ke,b]),sa=o.useCallback(async(r,i,u)=>{if(!r&&!b){gr([]),Sn([]);return}const x=b,v=Bn.current+1;Bn.current=v,Or.current?.abort();const R=new AbortController;Or.current=R;try{const T=r?[r]:Array.from(new Set([b,...V.map(Y=>Y.root)].filter(Y=>!!Y))),H=await Promise.all(T.map(Y=>Nh({repoRoot:Y,baseRef:i,branchName:u},R.signal))).then(Y=>{const Ce=new Map,He=new Map;for(const Pe of Y){for(const Fe of Pe.records)Ce.set(Fe.id,Fe);for(const Fe of Pe.walkthroughs??[])He.set(Fe.id,Fe)}return{records:Array.from(Ce.values()),walkthroughs:Array.from(He.values())}});if(Bn.current!==v||!ke(x))return;gr(H.records),Sn(H.walkthroughs??[])}catch(T){if(Bn.current!==v||!ke(x)||Nr(T))return;console.warn("[RightSidebar] Failed to load branch explanations",T)}finally{Or.current===R&&(Or.current=null)}},[V,ke,b]),Ur=o.useCallback((r,i={})=>{if(!ke(b)){et("apply_skipped_root_changed",{expectedRootPath:b,currentRootPath:te.getState().rootPath,bundleRoot:r.context?.root,files:r.files.length});return}et(r.files.length===0?"empty_bundle":"apply",{rootPath:b,available:r.available,files:r.files.length,repositories:r.repositories?.map(ge=>({root:ge.root,relativeRoot:ge.relativeRoot,files:ge.files.length,available:ge.available,error:ge.error})),repoFilters:r.repoFilters?.map(ge=>({root:ge.root,label:ge.label,count:ge.count})),cached:r.cached,stale:r.stale,cacheAgeMs:r.cacheAgeMs,untrackedDeferred:r.untrackedDeferred,error:r.error});let u=pu(r),x=r.repoFilters??[],v=r.files;const R=te.getState().changedFiles;if(!!(i.cacheOnly&&!r.cached&&r.files.length===0&&u.length===0)&&(R.size>0||V.length>0||ae)){et("cache_only_apply_skipped_empty_backend_cache",{rootPath:b,currentFiles:R.size,currentRepositories:V.length});return}const H=u.some(ge=>ge.deferred);if(H&&!i.replaceWorkspace){const ge=new Set(u.filter(qe=>!qe.deferred||qe.root===b).map(qe=>qe.root));v=[...Array.from(R.values()).filter(qe=>!ge.has(it(qe,b)??"")),...r.files]}const Y=Nd(R.values(),b),Ce=Nd(r.files,b),He=u.some(ge=>ge.root!==b);if(!!(i.background&&!H&&!i.replaceWorkspace&&R.size>0&&(r.files.length===0&&!r.error||Y>0&&Ce===0&&!He))){et("background_apply_skipped_degraded_bundle",{rootPath:b,currentFiles:R.size,nextFiles:r.files.length,currentNestedCount:Y,nextNestedCount:Ce,nextRepositories:u.map(ge=>({root:ge.root,relativeRoot:ge.relativeRoot,files:ge.files.length})),cached:r.cached,stale:r.stale,error:r.error});return}if(i.replaceRepoRoot){const ge=Zu(R.values(),V,r,i.replaceRepoRoot,b);v=ge.files,u=ge.repositories,x=ge.repoFilters}if(Xs(Xu(v)),ye(u),Oe(x),i.syncActiveRepo!==!1){const ge=i.activeRepoRoot!==void 0?i.activeRepoRoot:ce??hd(b),Ne=bg({...r,repositories:u,repoFilters:x},ge);Je(Ne),ri(b,Ne)}typeof r.cacheUpdatedAt=="number"&&il(r.cacheUpdatedAt),S(ge=>{if(i.replaceRepoRoot&&i.replaceRepoRoot!==b)return ge;if(!r.context)return null;const Ne=ge?.root??b;return!ge?.available||Ne!==(r.context.root??b)?r.context:{...ge,...r.context}}),i.reloadDiff&&to(ge=>ge+1);const Fe=te.getState().selectedFilePath;if(Fe&&!Fe.startsWith("/")&&!v.some(ge=>ge.path===Fe||ge.absolutePath===Fe)&&Ye(null),$r(ge=>{const Ne=new Set(v.map(Vt=>it(Vt,b)).filter(Boolean)),qe=new Set;for(const Vt of ge)Ne.has(Vt)&&qe.add(Vt);return ni(Qo,qe),qe}),i.loadDeferred!==!1){const ge=u.filter(Ne=>Ne.untrackedDeferred&&Ne.root).map(Ne=>Ne.root);for(const Ne of ge)El(Ne)}i.loadAudit!==!1&&lr()},[ce,ke,lr,El,b,Ye,Xs]);o.useEffect(()=>{Qs(),wo.current=null,ko.current=b;const r=[],i=[],x=hd(b);mt.current+=1,un.current+=1,ea.current+=1,kr.current?.abort(),bt(Kn(_r.current?.cwd??b??void 0)),_r.current=null,kr.current=null,Br.current?.abort(),bt("right-sidebar-git-details"),Br.current=null;for(const Y of Ft.current.values())Y.abort();for(const Y of Ft.current.keys())bt(`right-sidebar-git-untracked:${Y}`);Ft.current.clear(),It.current.clear(),Dn.current+=1,_n.current?.abort(),_n.current=null,Bn.current+=1,Or.current?.abort(),Or.current=null,Tr.current+=1,ar.current?.abort(),bt("right-sidebar-recent-commits"),ar.current=null,Yr([]),Zn([]),Lr(!1),Pt(null),Jr([]),Pr(!1),gr([]),Sn([]),Qt(!1),Zt(null),z(!1),xe(null),$e(null),_e(null),at(null),xr(!1),Zr(""),rr([]),en(!1),Be(!1),sr(null),Mn(!1),Ds(null),tn(null),rn(null),el(!1),xt(Zo,!1),so(!1);const v=b?pd()[b]:null,R=v?.previewEntries??[],T=v?.selectedPreviewKey??null,H=T?R.find(Y=>Y.key===T)??null:null;ao(v?.selectedRepoRoots??[]),Bs(v?.repoTargetBranches??{}),Os(v?.repoBaseBranches??{}),es(R),Rn(v?.previewScrollTops??{}),H&&v?.previewDetailOpen&&(H.diff.hunks?.length??0)>0&&(Zt(H.diff),tn(H.key),rn(v.selectedPreviewFileKey??(H.diff.hunks?.[0]?`${H.diff.hunks[0].filePath}\0${H.diff.hunks[0].hunkHeader}\0${H.diff.hunks[0].hunkIndex}`:null)),Qt(!0)),tl(v?.includeUncommitted??!0),wo.current=b,Hs(!1),Je(x??null),ir.current.clear(),dn.current.clear(),ns(null),ss(null),Fr(null),dt(null),il(null),ye(r),Oe(i),S(null),So.current=null},[Qs,b]);const qt=o.useCallback(async(r=b??void 0,i={})=>{if(!r)return null;const u=b,x=mt.current;if(await Bm(te.getState().hydrateNestedGitScanRoots),mt.current!==x||!ke(u))return null;const v=r===b&&Gn(b),R=i.includeNested??v,T=i.refresh??i.reloadDiff??!1,H=i.cacheOnly??!1,Y=i.background??!1,Ce=R&&(i.discoverOnly??!1);T&&ir.current.clear();const He=_r.current;if(He&&He.cwd===r&&He.includeNested===R&&He.refresh===T&&He.cacheOnly===H&&He.discoverOnly===Ce)return et("reuse_pending",{cwd:r,includeNested:R,refresh:T,cacheOnly:H,discoverOnly:Ce}),He.promise;const Pe=mt.current+1;mt.current=Pe;const Fe=`right-sidebar:${$l}:${Pe}`;kr.current?.abort();const ge=Kn(r);bt(ge);const Ne=new AbortController;kr.current=Ne;let qe=null;Y||Sl(Fe),vo(null),et("start",{requestId:Pe,cwd:r,rootPath:b,requestSlotId:ge,includeNested:R,refresh:T,cacheOnly:H,background:Y,existingChanges:we.size,lastLoadedAt:In}),!Y&&typeof window<"u"&&(qe=window.setTimeout(()=>{mt.current===Pe&&jl(Fe,!0)},eg));const Vt=(async()=>{const Te=await Ra(r,Ne.signal,{includeNested:R,refresh:T,cacheOnly:H,discoverOnly:Ce,action:T?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:ge,requestTimeoutMs:T?null:void 0});if(lb(Te)){if(et("cancelled_result_ignored",{requestId:Pe,activeRequestId:mt.current,cwd:r,error:Te.error??Te.context?.error}),Ne.signal.aborted)return null;throw new Error(Te.error??Te.context?.error??"Failed to load Git changes")}return mt.current!==Pe||!ke(u)?(et("stale_result",{requestId:Pe,activeRequestId:mt.current,cwd:r,expectedRootPath:u,currentRootPath:te.getState().rootPath,files:Te.files.length,repositories:Te.repositories?.length??0}),null):(Ur(Te,{reloadDiff:i.reloadDiff,syncActiveRepo:i.replaceWorkspace?!0:R,background:Y,cacheOnly:H,replaceRepoRoot:i.replaceRepoRoot,replaceWorkspace:i.replaceWorkspace}),Te)})();_r.current={cwd:r,includeNested:R,refresh:T,cacheOnly:H,discoverOnly:Ce,promise:Vt};try{const Te=await Vt;return mt.current===Pe&&Te&&ke(u)?Rl({cached:Te.cached,stale:Te.stale,cacheAgeMs:Te.cacheAgeMs,nestedDeferred:!R||Te.nestedDeferred,untrackedDeferred:Te.untrackedDeferred}):mt.current===Pe&&ke(u)&&xo(Fe),Te}catch(Te){return mt.current!==Pe||!ke(u)||Ne.signal.aborted?(et("aborted",{requestId:Pe,activeRequestId:mt.current,cwd:r,expectedRootPath:u,currentRootPath:te.getState().rootPath,message:Te instanceof Error?Te.message:String(Te)}),null):(et("error",{requestId:Pe,cwd:r,includeNested:R,refresh:T,background:Y,message:Te instanceof Error?Te.message:String(Te)}),Y||(S(null),vo(Te instanceof Error?Te.message:"Failed to load Git changes")),null)}finally{qe!==null&&window.clearTimeout(qe),kr.current===Ne&&(kr.current=null),_r.current?.promise===Vt&&(_r.current=null),!Y&&mt.current===Pe&&ke(u)&&xo(Fe)}},[Ur,Sl,we.size,xo,$l,In,ke,Rl,b,vo,jl]),is=o.useCallback(async()=>{b&&await qt(b,{reloadDiff:!0,refresh:!0})},[qt,b]),jo=o.useCallback(async(r=b??void 0)=>{if(!r)return null;const i=b,u=un.current+1;un.current=u,Br.current?.abort(),bt("right-sidebar-git-details");const x=new AbortController;Br.current=x,Hs(!0);try{const v=await Uc(r,x.signal,"load_git_details","right-sidebar-git-details");return un.current!==u||!ke(i)?null:(ye(R=>R.map(T=>T.root===v.root?{...T,available:v.available,context:v,error:v.error}:T)),S(R=>R?.root&&v.root&&R.root!==v.root?R:!R?.available||!v.available?v:{...R,...v}),v)}catch(v){return Nr(v)||!ke(i)||un.current===u&&dt(v instanceof Error?v.message:"Failed to load Git details"),null}finally{Br.current===x&&(Br.current=null),un.current===u&&ke(i)&&Hs(!1)}},[ke,b]);o.useEffect(()=>{if(!t){mt.current+=1,Qs(),So.current=null,un.current+=1,ea.current+=1,kr.current?.abort(),bt(Kn(_r.current?.cwd??b??void 0)),_r.current=null,kr.current=null,Br.current?.abort(),bt("right-sidebar-git-details"),Br.current=null;for(const r of Ft.current.values())r.abort();for(const r of Ft.current.keys())bt(`right-sidebar-git-untracked:${r}`);Ft.current.clear(),It.current.clear(),Bn.current+=1,Or.current?.abort(),Or.current=null,Tr.current+=1,ar.current?.abort(),bt("right-sidebar-recent-commits"),ar.current=null,Hs(!1),z(!1),xe(null),$e(null),_e(null),at(null),xr(!1),Zr(""),rr([]),en(!1),Be(!1),sr(null),Mn(!1),j(""),fe(!1),kt(null),co(!1),ee&&al(!1)}},[ee,t,Qs,fe]),o.useEffect(()=>{if(!se)return;const r=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(r)},[se]),o.useEffect(()=>{ee||yr(!1)},[ee]);const ls=o.useCallback(r=>{io(r);const i=na.current;i&&(i.update(),i.slideTo(r,0),window.requestAnimationFrame(()=>{i.update(),i.slideTo(r,0)}))},[]);o.useEffect(()=>{if(ee)if(yr(m),m&&Ve){wr(1);const r=Sr.current;r&&(r.update(),r.activeIndex!==1&&(os.current=1,r.slideTo(1,0)))}else{wr(0);const r=Sr.current;r&&r.activeIndex!==0&&(os.current=0,r.slideTo(0,0)),kt(null)}},[ee,m,b,Ve]),o.useEffect(()=>{if(g!==void 0&&!m){wr(0);const r=Sr.current;r&&r.activeIndex!==0&&(os.current=0,r.slideTo(0,0)),yr(!1),kt(null)}},[g,m]),o.useEffect(()=>{y!==void 0&&W(null)},[y]),o.useEffect(()=>{!ee&&m&&f?.()},[ee,f,m]),o.useEffect(()=>{mo(r=>Ei(r,n))},[n]);const bf=o.useCallback(r=>{ee||(r.preventDefault(),ra.current={startX:r.clientX,startWidth:ho,pointerId:r.pointerId},r.currentTarget.setPointerCapture(r.pointerId))},[ho,ee]),xf=o.useCallback(r=>{const i=ra.current;if(!i||i.pointerId!==r.pointerId)return;const u=Ei(i.startWidth+r.clientX-i.startX,n);mo(u),ks(ys,u,Zp)},[n]),Al=o.useCallback(r=>{const i=ra.current;if(!(!i||i.pointerId!==r.pointerId)){ra.current=null,bs(ys);try{r.currentTarget.releasePointerCapture(r.pointerId)}catch{}}},[]),cs=!!(b&&In!==null&&Ed(ae)),Ro=!!(b&&!cn&&we.size===0&&In===null),Hr=cs?"files":po,Xe=Hr==="git",On=Hr==="files",pt=Hr==="diff";o.useEffect(()=>{if(!ee){Us(!0);return}if(!t){const i=window.setTimeout(()=>{Us(!1)},rg);return()=>window.clearTimeout(i)}Us(!1);const r=window.setTimeout(()=>{Us(!0)},tg);return()=>window.clearTimeout(r)},[ee,t]),o.useEffect(()=>{if(!ee||!pt)return;const r=na.current;if(!r)return;const i=window.requestAnimationFrame(()=>{r.update()});return()=>window.cancelAnimationFrame(i)},[pt,ee]),o.useEffect(()=>{if(!cs||!b||Dr)return;const r=window.setTimeout(()=>{qt(b,{background:!0})},3e3);return()=>window.clearTimeout(r)},[cs,b,Dr,qt]);const vf=o.useCallback(r=>{qt(r,{discoverOnly:!0})},[qt]);Om({active:t&&(Xe||pt),rootPath:b,loading:Dr,delay:Xe&&!ee?0:ti,lastStartedRoot:So,load:vf}),o.useEffect(()=>{!t||!Xe||(!ee||lo)&&co(!0)},[Xe,ee,t,lo]),o.useEffect(()=>{if(!t||Xe)return;const r=window.setTimeout(()=>{co(!0)},ti);return()=>window.clearTimeout(r)},[Xe,t]),o.useEffect(()=>{pt&&al(!0)},[pt]);const Pl=o.useCallback(r=>{pe&&eb(pe,r.currentTarget.scrollTop)},[pe]);o.useEffect(()=>()=>{kr.current?.abort(),bs(Ui),bs(Hi),bs(ys),bs(ei)},[]),o.useEffect(()=>{if(!pe||!Ml)return;const r=Vu()[pe]?.top;if(typeof r!="number")return;let i=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r),i=window.requestAnimationFrame(()=>{Fn.current&&(Fn.current.scrollTop=r)})});return()=>window.cancelAnimationFrame(i)},[pe,Ml]),o.useEffect(()=>{if(!t)return;const r=new AbortController;return Mh(r.signal).then(i=>fl(!!i.available)).catch(()=>fl(!1)),()=>r.abort()},[t]);const ds=o.useCallback(r=>{if(ne(null),Ye(r),kt(null),ee){yr(!0),wr(1),Sr.current?.slideTo(1),p?.();return}},[ee,p,Ye]),Tl=o.useCallback((r,i)=>{if(ne(null),Ye(r),Ie(i),ee){yr(!0),wr(1),Sr.current?.slideTo(1),p?.();return}},[ee,p,Ye]),us=o.useCallback(async(r,i)=>{const u=i||Pn||b;if(!(!u||r.length===0)){Vs(!0);try{await Vo(u,r),Js(u,!1)}catch(x){dt(x instanceof Error?x.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>dt(null),4e3)}finally{Vs(!1)}}},[Pn,b,Js,a]),Il=o.useCallback(async r=>{try{await $h(r)}catch(i){dt(i instanceof Error?i.message:a("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>dt(null),4e3)}},[a]),aa=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),r.dataTransfer.types.includes("Files")&&fo(!0)},[]),Fl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),fo(!1)},[]),Dl=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),fo(!1);const i=r.dataTransfer.files;i.length>0&&us(Array.from(i))},[us]),Co=o.useCallback(r=>{Se(r),window.setTimeout(()=>Se(i=>i===r?null:i),1400)},[]),jr=o.useCallback(r=>{lt(r),window.setTimeout(()=>lt(i=>i===r?null:i),1400)},[]);o.useEffect(()=>{xt(od,Qe)},[Qe]),o.useEffect(()=>{xt(id,ht)},[ht]),o.useEffect(()=>{xt(ld,Yt)},[Yt]),o.useEffect(()=>{ks(ei,wt,Vp)},[wt]),o.useEffect(()=>(gl().catch(()=>{}),Wc(r=>{r.type==="pinned-explorer-roots"&&bl(r.pinnedExplorerRoots)})),[gl,bl]);const _l=o.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),oa=o.useRef(null),hn=o.useRef(null),[Bl,No]=o.useState(!1);o.useEffect(()=>{if(!t)return;No(!1);let r=!1;Eh().then(u=>{r||(oa.current=u.text,Ut(x=>u.text&&u.text!==x?u.text:x),No(!0))}).catch(()=>{r||No(!0)});const i=Wc(u=>{u.type==="context-draft"&&u.origin!==_l.current&&(oa.current=u.text,Ut(u.text))});return()=>{r=!0,i(),hn.current!==null&&(window.clearTimeout(hn.current),hn.current=null)}},[t]),o.useEffect(()=>{if(!Bl||oa.current===wt)return;hn.current!==null&&window.clearTimeout(hn.current);const r=wt;hn.current=window.setTimeout(()=>{hn.current=null,Lh(r,_l.current).then(()=>{oa.current=r}).catch(()=>{})},500)},[wt,Bl]);const Un=o.useCallback((r,i,u)=>{if(r){if(Ah(u?r+u:r)){Co(i);return}Qe?(Ut(x=>up(x,r)+(u??"")),window.matchMedia("(pointer: coarse)").matches||(dr(!1),ur(x=>x+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:u?r+u:r,focus:!0}})),Co(i)}},[Qe,Co]),ia=o.useCallback(r=>{const i=Na(r,b);return Qh(i,b)},[b]),Mo=qd(jr),zr=o.useCallback((r,i)=>{const u=Na(r,b);Un(Zh(u,b),i??`path:${u}`)},[b,Un]),yf=o.useCallback(async r=>{Vs(!0);try{await em(r,Vo,i=>{zr(i,`path:${i}`)}),ee&&!Qe&&s()}catch(i){dt(i instanceof Error?i.message:a("rightSidebar.uploadFailed")),window.setTimeout(()=>dt(null),4e3)}finally{Vs(!1)}},[Qe,zr,ee,s,a]),Rr=o.useCallback((r,i)=>{if(!r)return;const u=r.includes(`
1660
1660
  `)?`
1661
- `:void 0;Bn(r.endsWith(`
1662
- `)||r.endsWith(" ")?r:`${r} `,i,u)},[Bn]),Bl=o.useRef(Nr);Bl.current=Nr;const Eo=o.useRef(!0);o.useEffect(()=>(Eo.current=!0,()=>{Eo.current=!1}),[]);const Lo=o.useRef(new Set),Ol=o.useCallback((r,i,u)=>{if(Lo.current.has(i))return;const x=Vc.getState().activeSessionId;Lo.current.add(i),Dm(r,i,u,{insert:Nr,upload:async(v,R)=>(await Yo("/tmp",[v],R)).files[0]?.path,isCurrent:()=>Eo.current&&Bl.current===Nr&&x===Vc.getState().activeSessionId}).finally(()=>Lo.current.delete(i))},[Nr]),Wr=o.useCallback((r,i,u)=>{i&&Bn(i.endsWith(" ")?i:`${i} `,u??`context:${r}`,`
1663
- `)},[Bn]),Ul=o.useCallback(r=>{const i=ip(wt,r);if(!i)return;const u=r&&wt.trim().includes(`
1664
- `),x=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let v=!1;const R=X=>{v||(v=!0,window.removeEventListener("termdock-insert-reference-ack",T),window.clearTimeout(H),X?(Wt(!1),Ht(""),Yt&&ur(!0)):(Wt(!0),ur(!1)))},T=X=>{const ke=X.detail;ke?.nonce===x&&R(ke.ok===!0)},H=window.setTimeout(()=>R(!1),1500);window.addEventListener("termdock-insert-reference-ack",T),Wt(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:i,focus:!0,paste:u,nonce:x}}))},[Yt,wt]),Ve=o.useMemo(()=>b?mt(b):a("rightSidebar.workspace"),[b,a]),xf=o.useMemo(()=>mt(pe)||Ve,[pe,Ve]),da=o.useMemo(()=>ci(pe),[pe]),ua=o.useMemo(()=>b?pl[b]??[]:[],[pl,b]),hn=o.useMemo(()=>new Set(ua.map(r=>r.path)),[ua]),us=!!(pe&&hn.has(pe)),Ao=!!(b&&pe&&pe!==b),vf=!!(b&&Ln&&Ln!==b),Lt=pe?`path:${pe}`:null,Hl="context:change-audit",yf=o.useCallback(()=>{da&&It(da)},[da,It]),zl=o.useCallback(()=>{xl()},[xl]),wf=o.useCallback(()=>{pe&&(Qs(pe,!0),wl())},[wl,pe,Qs]),kf=o.useCallback(()=>{!pe||!Ao||(us?ln(pe):An(pe,"directory"))},[Ao,pe,us,An,ln]),Wl=o.useCallback(r=>{It(r),j("")},[It]),Gl=o.useCallback(r=>{pe&&(re(Up(pe,r)),fe(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[pe,fe]),ql=o.useCallback(r=>{!b||r===b||(hn.has(r)?ln(r):An(r,"directory"))},[An,hn,b,ln]),Kl=o.useCallback(r=>{!b||!r||(hn.has(r)?ln(r):An(r,"file"))},[An,hn,b,ln]),Vl=te(r=>r.expandedPaths),Po=o.useMemo(()=>{const r=new Set;if(Dn&&pe){r.add(pe);const i=`${pe.replace(/\/+$/,"")}/`;for(const u of Vl)u.startsWith(i)&&r.add(u)}if(Dn&&b&&Ye){const i=Ye.startsWith("/")?Ye:`${b}/${Ye}`,u=ci(i);u&&r.add(u)}return Qm(r).join(`
1665
- `)},[Vl,Dn,pe,b,Ye]),mn=o.useRef(new Map);o.useEffect(()=>{const r=Po?Po.split(`
1666
- `):[];if(!t||r.length===0){En(null);return}const i=new AbortController;let u=!1,x=0,v=0;En(null);const R=async()=>{let T=0;for(;!u&&!i.signal.aborted;){let H=null;try{En(null),await Bh(r,ke=>{const{applicableEvents:Ie,unavailableReason:Ge}=ep(ke);Ie.length>0&&vl(Ie);for(const Fe of Ie){if(Fe.type!=="rescan-required")continue;const ge=te.getState();if(!ge.directoryCache.has(Fe.path))continue;mn.current.get(Fe.path)?.abort();const qe=new AbortController;mn.current.set(Fe.path,qe);const Ee=`file-watch-rescan:${Fe.path}`;xt(Ee),Oh(Fe.path,qe.signal,ge.showHiddenFiles,"watch_rescan",Ee,ge.fileSortModes[Fe.path]??"name").then(ms=>{mn.current.get(Fe.path)===qe&&yl(Fe.path,ms.entries)}).catch(ms=>{dr(ms)||En(ms instanceof Error?ms.message:"File refresh unavailable")}).finally(()=>{mn.current.get(Fe.path)===qe&&mn.current.delete(Fe.path)})}Ge&&En(Ge)},i.signal),H=new Error("File watch stream ended")}catch(ke){H=ke}if(u||i.signal.aborted||dr(H))return;En(H instanceof Error?H.message:"File watching unavailable");const X=id[Math.min(T,id.length-1)];T+=1,await new Promise(ke=>{v=window.setTimeout(ke,X)})}};return x=window.setTimeout(()=>{u||R()},ri),()=>{u=!0,window.clearTimeout(x),window.clearTimeout(v),i.abort();for(const T of mn.current.values())T.abort();mn.current.clear()}},[vl,t,yl,Po]),o.useEffect(()=>{if(!b||So.current!==b)return;if(jo.current===b){jo.current=null;return}const r=hd();Ss(ou,{...r,[b]:{selectedRepoRoots:Bs,repoTargetBranches:yr,repoBaseBranches:Rt,previewEntries:Qr,selectedPreviewKey:Me&&xr?Ze:null,selectedPreviewFileKey:Me&&xr?lo:null,previewDetailOpen:!!(Me&&xr),previewScrollTops:Sn,previewMobileSlideIndex:1,includeUncommitted:Fr,updatedAt:Date.now()}},Hp)},[xr,Fr,Me,Qr,Sn,Rt,yr,Bs,b,lo,Ze]);const st=o.useMemo(()=>Nd(ve.values()),[ve]),bt=o.useMemo(()=>{const r=new Map;for(const i of V)r.set(i.root,i);return r},[V]),To=o.useMemo(()=>{const r=new Map;for(const i of V)i.deferred||r.set(i.root,i.files.length);return r},[V]),Ct=o.useMemo(()=>ce?be.find(r=>r.root===ce)??null:null,[ce,be]),Dt=o.useMemo(()=>Ye?Array.from(ve.values()).find(r=>r.path===Ye||r.absolutePath===Ye)??null:null,[ve,Ye]),At=o.useMemo(()=>{const r=new Map;for(const i of V)i.available&&i.context?.available&&r.set(i.root,i);return r.size===0&&se?.available&&se.root&&r.set(se.root,{id:se.root,root:se.root,relativeRoot:".",name:Ve,depth:0,nested:!1,available:!0,files:Array.from(ve.values()).filter(i=>lt(i,b)===se.root),context:se}),Array.from(r.values()).sort((i,u)=>i.root===b?-1:u.root===b?1:(i.relativeRoot||i.name).localeCompare(u.relativeRoot||u.name)).map(i=>{const u=i.relativeRoot==="."?Ve:i.relativeRoot||i.name||mt(i.root),x=Cd(i.files),v=i.files.length;return{value:i.root,label:u,meta:[i.context?.branch,v>0?a("rightSidebar.repoChangedCount",{count:v}):null,x>0?a("rightSidebar.repoStagedCount",{count:x}):null].filter(Boolean).join(" · ")}})},[ve,se,V,Ve,b,a]),ye=o.useMemo(()=>ce&&At.some(r=>r.value===ce)?ce:Dt?.repoRoot&&At.some(r=>r.value===Dt.repoRoot)?Dt.repoRoot:At.length===1||At.length>1?At[0].value:null,[ce,At,Dt?.repoRoot]),Yl=ye?bt.get(ye)??null:null,ue=Yl?.context?.available?Yl.context:ye===se?.root?se:null,ze=At.length>0&&!ye,Xl=o.useMemo(()=>ze?[]:ye?Array.from(ve.values()).filter(r=>lt(r,b)===ye):Array.from(ve.values()),[ye,ve,ze,b]),pn=o.useMemo(()=>Nd(Xl),[Xl]),Io=!!(ue?.available&&ue.root&&ye&&ue.root===ye),Sf=ye?At.find(r=>r.value===ye)?.label??mt(ye):a("rightSidebar.gitRepositoryPlaceholder"),jf=Io?ue?.branch??"HEAD":ze?a("rightSidebar.selectRepositoryForGitActions"):nn?a("rightSidebar.gitActionRunning"):"HEAD",On=!!(ue?.available&&ue.root===ye&&ue.status);o.useEffect(()=>{Zi.current={count:tr.length,loading:Cn,loadingMore:Q,hasMore:so}},[tr.length,so,Cn,Q]),o.useEffect(()=>{Ir.current+=1,ar.current?.abort(),xt("right-sidebar-recent-commits"),ar.current=null,Zr(""),rr([]),en(!1),Be(!1),sr(null),Nn(!1)},[ye]);const fs=o.useCallback(async(r={})=>{if(!b||!ye||ze)return;const i=r.reset??!1,u=Zi.current,x=i?0:u.count;if(!i&&(u.loading||u.loadingMore||!u.hasMore))return;const v=Ir.current+1;Ir.current=v,ar.current?.abort(),xt("right-sidebar-recent-commits");const R=new AbortController;ar.current=R,i?en(!0):Be(!0),sr(null);try{const T=await Lh({cwd:b,repoRoot:ye,limit:Qp,skip:x,query:Zn.trim(),requestSlotId:"right-sidebar-recent-commits"},R.signal);if(Ir.current!==v)return;if(!T.available){sr(T.error??"Recent commits are unavailable"),i&&rr([]),Nn(!1);return}rr(H=>i?T.commits:[...H,...T.commits]),Nn(T.hasMore)}catch(T){if(Ir.current!==v||dr(T))return;sr(T instanceof Error?T.message:"Failed to load recent commits"),i&&rr([]),Nn(!1)}finally{ar.current===R&&(ar.current=null),Ir.current===v&&(en(!1),Be(!1))}},[ye,Zn,ze,b]);o.useEffect(()=>{er&&fs({reset:!0})},[Zn,fs,er]);const Rf=o.useCallback(r=>{const i=r.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||fs({reset:!1})},[fs]);o.useEffect(()=>{!ye||!se?.available||!Ke||!or||On||nn||ze||Co(ye)},[ye,se?.available,On,nn,Ke,or,Co,ze]),o.useEffect(()=>{!t||!ft&&!Ke||!b||lr()},[ft,Ke,t,lr,b]),o.useEffect(()=>{!t||!Ke||!or||!es||!b||oa(null)},[es,Ke,or,t,oa,b]);const Cf=o.useMemo(()=>{if(!ce)return 0;const r=be.findIndex(i=>i.root===ce);return r>=0?r+1:0},[ce,be]),Jl=o.useCallback(r=>{if(!r)return null;const i=Array.from(ve.values()).filter(u=>lt(u,b)===r).sort((u,x)=>u.path.localeCompare(x.path))[0];return i?ht(i):null},[ve,b]),gn=be.length>1,fa=o.useMemo(()=>[{root:null,label:a("rightSidebar.allRepositories"),count:ve.size,branch:null,deferred:!1},...be.map(r=>({root:r.root,label:r.label,count:r.deferred?To.get(r.root)??0:r.count,branch:r.branch??null,deferred:!!r.deferred&&!To.has(r.root)}))],[ve.size,be,To,a]),Ql=fa[Cf]??fa[0],ha=!!ce,Zl=o.useMemo(()=>pu(be,V),[be,V]);o.useEffect(()=>{ce&&!Zl.has(ce)&&(Je(null),ni(b,null)),Jr(r=>r.filter(i=>be.some(u=>u.root===i)))},[ce,be,Zl,b]);const Nf=o.useMemo(()=>{const r=new Set;ue?.branch&&r.add(ue.branch);for(const i of ue?.branches??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ue?.branch,ue?.branches,a]),ec=o.useMemo(()=>{const r=new Set;ue?.upstreamRemote&&r.add(ue.upstreamRemote);for(const i of ue?.remotes??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===ue?.upstreamRemote?a("rightSidebar.pushUpstreamBadge"):void 0}))},[ue?.remotes,ue?.upstreamRemote,a]),tc=ec.length>1,Mf=o.useMemo(()=>{const r=[],i=new Set,u=(v,R)=>{!v||i.has(v)||(i.add(v),r.push({value:v,label:v,meta:R}))};u(ue?.upstreamBranch,ue?.upstreamBranch?a("rightSidebar.pushUpstreamBadge"):void 0),u(ue?.branch,ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of ue?.branches??[])u(v,v===ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");const x=ue?.upstreamRemote;for(const v of ue?.remoteBranches??[]){const R=v.indexOf("/"),T=R>=0?v.slice(0,R):null,H=R>=0?v.slice(R+1):v;(!x||T===x)&&u(H,"remote")}return r},[ue?.branch,ue?.branches,ue?.remoteBranches,ue?.upstreamBranch,ue?.upstreamRemote,a]),Bt=o.useMemo(()=>At.map(r=>{const i=bt.get(r.value);return{root:r.value,label:r.label,branch:i?.context?.branch??null}}),[At,bt]);o.useEffect(()=>{Bt.length!==0&&(Os(r=>{let i=!1;const u={...r},x=new Set(Bt.map(v=>v.root));for(const v of Object.keys(u))x.has(v)||(delete u[v],i=!0);for(const v of Bt)!u[v.root]&&v.branch&&(u[v.root]=v.branch,i=!0);return i?u:r}),Us(r=>{let i=!1;const u={...r},x=new Set(Bt.map(v=>v.root));for(const v of Object.keys(u))x.has(v)||(delete u[v],i=!0);for(const v of Bt){const R=bt.get(v.root)?.context;if(u[v.root]&&gu(u[v.root],R?.branch)&&(delete u[v.root],i=!0),u[v.root])continue;const T=gd(R);T&&(u[v.root]=T,i=!0)}return i?u:r}))},[Bt,bt]);const ma=o.useMemo(()=>{const r=new Set(Bt.map(i=>i.root));return Bs.filter(i=>r.has(i))},[Bs,Bt]),pa=ma.length===0,cr=o.useMemo(()=>pa?Bt:Bt.filter(r=>ma.includes(r.root)),[Bt,ma,pa]),Vt=o.useMemo(()=>cr.filter(r=>!!Rt[r.root]?.trim()),[Rt,cr]),rc=o.useMemo(()=>cr.filter(r=>!Rt[r.root]?.trim()),[Rt,cr]),nc=o.useCallback(async r=>{if(!r||ko.current.has(r))return;const i=bt.get(r)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const u=b;ko.current.add(r),nl(x=>new Set(x).add(r));try{const x=await Bc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!x.available||!je(u))return;we(v=>v.map(R=>R.root===r?{...R,available:!0,context:{...R.context,...x},error:void 0}:R)),Os(v=>v[r]||!x.branch?v:{...v,[r]:x.branch}),Us(v=>{if(v[r])return v;const R=gd(x);return R?{...v,[r]:R}:v})}catch(x){dr(x)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,x)}finally{ko.current.delete(r),nl(x=>{const v=new Set(x);return v.delete(r),v})}},[bt,je,b]);o.useEffect(()=>{if(ao)for(const r of cr)nc(r.root)},[ao,cr,nc]),o.useEffect(()=>{!Io||!ue||(Gs(ue.branch||(ue.branches?.[0]??"")),qs(ue.upstreamRemote||(ue.remotes?.includes("origin")?"origin":ue.remotes?.[0]??"")),Ks(ue.upstreamBranch||ue.branch||(ue.branches?.[0]??"")))},[ue,Io]);const sc=o.useMemo(()=>{if(ze)return{text:a("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!On||nn)return{text:a("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ue?.upstream)return{text:a("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=ue.ahead??0,i=ue.behind??0;return r>0&&i>0?{text:a("rightSidebar.pushDivergedCount",{ahead:r,behind:i}),className:"bg-destructive/10 text-destructive"}:r>0?{text:a("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:i>0?{text:a("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:a("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ue?.ahead,ue?.behind,ue?.upstream,On,nn,ze,a]),$f=o.useCallback(r=>{if(r&&!ee){const i=r.currentTarget.getBoundingClientRect();W({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else W(null);N?.()},[ee,N]),Fo=o.useCallback(()=>{W(null),I?.()},[I]);function ac(){if(!gn)return null;const r=Ql?.label??a("rightSidebar.allRepositories"),i=Ql?.count??ve.size,u=mt(r)||r;return e.jsxs("button",{type:"button",onClick:$f,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 ${k?"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":k,title:r,children:[e.jsx(Mr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:u}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(Ms,{size:12,className:"shrink-0"})]})}function Ef(){if(!k||!gn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,u=Math.max(12,Math.min(Ae?.x??r-368,r-352)),x=Math.max(12,Math.min(Ae?.y??80,i-420)),v=ee?void 0:{left:u,top:x},R=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Fo,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:v,onClick:T=>T.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:a("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:fa.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${ve.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:ve.size})]})]}),e.jsx("button",{type:"button",onClick:Fo,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.close"),children:e.jsx(Ut,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:fa.map(T=>{const H=(T.root??null)===ce,X=mt(T.label)||T.label;return e.jsxs("button",{type:"button",onClick:()=>{Rc(T.root),Fo()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${H?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:T.label,role:"option","aria-selected":H,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${H?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${H?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Mr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:X}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:T.root===null?a("rightSidebar.allRepositories"):T.label})]}),T.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:T.branch}),T.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:a("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${T.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:T.count})]},T.root??"all")})})]})});return eu(R,ee,document.body)}function Lf(){return Ef()}function oc(r){const i=lt(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path),x=za(u,i??b);return{key:ht(r),path:r.path,absolutePath:u,displayName:x.name,displayDir:x.dir,oldPath:r.oldPath,status:r.status,title:u}}function ic(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:a("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function lc(r,i){const u=$a(r,b),x=`path:${u}`,v=q===x,R=Ce===x,T=v||R;return e.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),zr(u,x)},...$o(ca(u),x),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${T?"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"} ${T?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:a(R?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function cc(r){const i=lt(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path),x=sh(r),v=fi(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(sb,{actions:x,running:Pe,completed:Mn?.path===v?Mn:null}),lc(u,a("rightSidebar.insertThisFile"))]})}function dc(r,i){const u=i.root??b;if(!u)return null;const x=$a(r,u);return lc(x,a("fileTree.insertRefTitle"))}function _o(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":a("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>vc("unified"),"aria-pressed":Jt==="unified",title:a("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Jt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>vc("split"),"aria-pressed":Jt==="split",title:a("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Jt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.split")})]})}function uc(){return hs.map(r=>{const i=Cd(r.files.map(([,R])=>R)),u=Mi({activeGitRepoRoot:ce,groupCount:hs.length,label:r.label,rootName:Ve}),x=!!(u&&r.root&&Gt.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:x,files:r.files.map(([,R])=>oc(R)),header:u?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${x?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Xf(r.root),"aria-expanded":!x,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:x?e.jsx(Ma,{size:13}):e.jsx(Ms,{size:13})}),e.jsx(Mr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),ja("stage-all",r.root,r.label)},disabled:!!Pe,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),ja("stash-all",r.root,r.label)},disabled:!!Pe,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]})]}):null}})}function fc(){return ve.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:a("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ba.map(([,r])=>{const i=lt(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path);return{key:ht(r),path:r.path,absolutePath:u,status:r.status,repoRoot:i,displayName:za(u,i).name,displayDir:za(u,i).dir,auditRecords:jt}})}function hc(r){const i=Array.from(ve.values()).find(v=>ht(v)===r.key),u=i?lt(i,b):null,x=Um(jt,u,i?.path??r.path);return e.jsx(Si,{changeStatus:r.status,auditStatus:x,renderChangeBadge:v=>e.jsx(js,{status:v})})}const ga=o.useCallback(r=>{if(ee)return null;const i=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const x=r.getBoundingClientRect().top+48;let v=null,R=Number.POSITIVE_INFINITY;for(const H of i){const X=H.getBoundingClientRect();if(X.bottom<x)continue;const ke=Math.abs(X.top-x);ke<R&&(v=H,R=ke)}const T=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return T?(na.current===T&&te.getState().selectedFilePath===T||(na.current=T,Xe(T)),T):null},[ee,Xe]),Af=!!(!Pe&&ye&&!ze&&(ue?.upstream||sn.trim()&&an.trim())),Pf=!!(!Pe&&ye&&!ze&&(ue?.upstream||sn.trim()&&an.trim())),Tf=!!(!Pe&&ye&&!ze&&ns.trim()&&ns.trim()!==ue?.branch),Ot=o.useMemo(()=>{const r=le.trim().toLowerCase(),i=Array.from(ve.entries()).filter(([,u])=>!ce||lt(u,b)===ce).sort(([u],[x])=>u.localeCompare(x));return r?i.filter(([u,x])=>`${u} ${x.path} ${x.status} ${x.repoRelativeRoot??""} ${x.repoName??""}`.toLowerCase().includes(r)):i},[ce,ve,le,b]);o.useEffect(()=>{Ba("selected_file_state",{selectedFilePath:Ye,selectedChangedFilePath:Dt?.path??null,selectedChangedFileAbsolutePath:Dt?.absolutePath??null,selectedChangedFileRepoRoot:Dt?.repoRoot??null,rootPath:b,activeGitRepoRoot:ce,rightTab:bo,effectiveRightTab:Rr,diffPaneActive:ft,changedFiles:ve.size,filteredChangedFiles:Ot.length,gitBundleLoading:$t,gitBundleLastLoadedAt:Dr})},[ce,ve.size,ft,Rr,Ot.length,Dr,$t,bo,b,Dt?.absolutePath,Dt?.path,Dt?.repoRoot,Ye]);const hs=o.useMemo(()=>{const r=new Map;for(const i of Ot){const[,u]=i,x=lt(u,b),v=rb(u)||Ve,R=x??v,T=x?bt.get(x):void 0,H=r.get(R)??{root:x,label:v,branch:T?.context?.branch,files:[]};H.files.push(i),r.set(R,H)}return Array.from(r.values()).sort((i,u)=>i.label===Ve?-1:u.label===Ve?1:i.label.localeCompare(u.label))},[Ot,bt,Ve,b]),ba=o.useMemo(()=>{const r=[],i=new Map;for(const u of Ot)i.set(ht(u[1]),u);for(const u of hs){if(!!(u.root&&Mi({activeGitRepoRoot:ce,groupCount:hs.length,label:u.label,rootName:Ve})&&Gt.has(u.root)))continue;if(St!=="tree"){r.push(...u.files);continue}const v=u.files.map(([,R])=>oc(R));for(const R of om(v)){const T=i.get(R.key);T&&r.push(T)}}return r},[ce,Gt,St,hs,Ot,Ve]);o.useEffect(()=>{if(!ft||ba.length===0||ee)return;const r=[],i=()=>{const u=document.querySelector(".termdock-diff-stream-scroller");if(u&&ga(u))return;const x=document.querySelector("[data-diff-stream-item]"),v=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;if(v){na.current=v,Xe(v);return}const R=ba[0]?.[1];if(!R)return;const T=ht(R);na.current=T,Xe(T)};for(const u of[80,240,600,1200])r.push(window.setTimeout(i,u));return()=>r.forEach(u=>window.clearTimeout(u))},[ft,ee,ba,Xe,ga]);const Do=o.useMemo(()=>{const r=T=>`'${T.replace(/'/g,"'\\''")}'`,i=qt.length>0?un:V.filter(T=>T.files.length>0),u=i.length>0?i:b?[{root:b,relativeRoot:".",name:Ve}]:[],x=u.length>0?u.map(T=>`- ${T.relativeRoot==="."?".":T.relativeRoot} (${T.root})`).join(`
1661
+ `:void 0;Un(r.endsWith(`
1662
+ `)||r.endsWith(" ")?r:`${r} `,i,u)},[Un]),Ol=o.useRef(Rr);Ol.current=Rr;const $o=o.useRef(!0);o.useEffect(()=>($o.current=!0,()=>{$o.current=!1}),[]);const Eo=o.useRef(new Set),Ul=o.useCallback((r,i,u)=>{if(Eo.current.has(i))return;const x=Xc.getState().activeSessionId;Eo.current.add(i),zm(r,i,u,{insert:Rr,upload:async(v,R)=>(await Vo("/tmp",[v],R)).files[0]?.path,isCurrent:()=>$o.current&&Ol.current===Rr&&x===Xc.getState().activeSessionId}).finally(()=>Eo.current.delete(i))},[Rr]),Wr=o.useCallback((r,i,u)=>{i&&Un(i.endsWith(" ")?i:`${i} `,u??`context:${r}`,`
1663
+ `)},[Un]),Hl=o.useCallback(r=>{const i=fp(wt,r);if(!i)return;const u=r&&wt.trim().includes(`
1664
+ `),x=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let v=!1;const R=Y=>{v||(v=!0,window.removeEventListener("termdock-insert-reference-ack",T),window.clearTimeout(H),Y?(zt(!1),Ut(""),Yt&&dr(!0)):(zt(!0),dr(!1)))},T=Y=>{const Ce=Y.detail;Ce?.nonce===x&&R(Ce.ok===!0)},H=window.setTimeout(()=>R(!1),1500);window.addEventListener("termdock-insert-reference-ack",T),zt(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:i,focus:!0,paste:u,nonce:x}}))},[Yt,wt]),Ke=o.useMemo(()=>b?ft(b):a("rightSidebar.workspace"),[b,a]),wf=o.useMemo(()=>ft(pe)||Ke,[pe,Ke]),la=o.useMemo(()=>ci(pe),[pe]),ca=o.useMemo(()=>b?pl[b]??[]:[],[pl,b]),mn=o.useMemo(()=>new Set(ca.map(r=>r.path)),[ca]),fs=!!(pe&&mn.has(pe)),Lo=!!(b&&pe&&pe!==b),kf=!!(b&&Pn&&Pn!==b),Et=pe?`path:${pe}`:null,zl="context:change-audit",Sf=o.useCallback(()=>{la&&Tt(la)},[la,Tt]),Wl=o.useCallback(()=>{xl()},[xl]),jf=o.useCallback(()=>{pe&&(Js(pe,!0),wl())},[wl,pe,Js]),Rf=o.useCallback(()=>{!pe||!Lo||(fs?ln(pe):Tn(pe,"directory"))},[Lo,pe,fs,Tn,ln]),Gl=o.useCallback(r=>{Tt(r),j("")},[Tt]),ql=o.useCallback(r=>{pe&&(re(qp(pe,r)),fe(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[pe,fe]),Kl=o.useCallback(r=>{!b||r===b||(mn.has(r)?ln(r):Tn(r,"directory"))},[Tn,mn,b,ln]),Vl=o.useCallback(r=>{!b||!r||(mn.has(r)?ln(r):Tn(r,"file"))},[Tn,mn,b,ln]),Yl=te(r=>r.expandedPaths),Ao=o.useMemo(()=>{const r=new Set;if(On&&pe){r.add(pe);const i=`${pe.replace(/\/+$/,"")}/`;for(const u of Yl)u.startsWith(i)&&r.add(u)}if(On&&b&&Ve){const i=Ve.startsWith("/")?Ve:`${b}/${Ve}`,u=ci(i);u&&r.add(u)}return np(r).join(`
1665
+ `)},[Yl,On,pe,b,Ve]),pn=o.useRef(new Map);o.useEffect(()=>{const r=Ao?Ao.split(`
1666
+ `):[];if(!t||r.length===0){An(null);return}const i=new AbortController;let u=!1,x=0,v=0;An(null);const R=async()=>{let T=0;for(;!u&&!i.signal.aborted;){let H=null;try{An(null),await Uh(r,Ce=>{const{applicableEvents:He,unavailableReason:Pe}=ap(Ce);He.length>0&&vl(He);for(const Fe of He){if(Fe.type!=="rescan-required")continue;const ge=te.getState();if(!ge.directoryCache.has(Fe.path))continue;pn.current.get(Fe.path)?.abort();const qe=new AbortController;pn.current.set(Fe.path,qe);const Vt=`file-watch-rescan:${Fe.path}`;bt(Vt),Hh(Fe.path,qe.signal,ge.showHiddenFiles,"watch_rescan",Vt,ge.fileSortModes[Fe.path]??"name").then(Te=>{pn.current.get(Fe.path)===qe&&yl(Fe.path,Te.entries)}).catch(Te=>{Nr(Te)||An(Te instanceof Error?Te.message:"File refresh unavailable")}).finally(()=>{pn.current.get(Fe.path)===qe&&pn.current.delete(Fe.path)})}Pe&&An(Pe)},i.signal),H=new Error("File watch stream ended")}catch(Ce){H=Ce}if(u||i.signal.aborted||Nr(H))return;An(H instanceof Error?H.message:"File watching unavailable");const Y=cd[Math.min(T,cd.length-1)];T+=1,await new Promise(Ce=>{v=window.setTimeout(Ce,Y)})}};return x=window.setTimeout(()=>{u||R()},ti),()=>{u=!0,window.clearTimeout(x),window.clearTimeout(v),i.abort();for(const T of pn.current.values())T.abort();pn.current.clear()}},[vl,t,yl,Ao]),o.useEffect(()=>{if(!b||wo.current!==b)return;if(ko.current===b){ko.current=null;return}const r=pd();ks(lu,{...r,[b]:{selectedRepoRoots:_s,repoTargetBranches:vr,repoBaseBranches:Rt,previewEntries:Qr,selectedPreviewKey:Me&&br?Ze:null,selectedPreviewFileKey:Me&&br?oo:null,previewDetailOpen:!!(Me&&br),previewScrollTops:jn,previewMobileSlideIndex:1,includeUncommitted:Ir,updatedAt:Date.now()}},Kp)},[br,Ir,Me,Qr,jn,Rt,vr,_s,b,oo,Ze]);const st=o.useMemo(()=>$d(we.values()),[we]),gt=o.useMemo(()=>{const r=new Map;for(const i of V)r.set(i.root,i);return r},[V]),Po=o.useMemo(()=>{const r=new Map;for(const i of V)i.deferred||r.set(i.root,i.files.length);return r},[V]),Ct=o.useMemo(()=>ce?be.find(r=>r.root===ce)??null:null,[ce,be]),Dt=o.useMemo(()=>Ve?Array.from(we.values()).find(r=>r.path===Ve||r.absolutePath===Ve)??null:null,[we,Ve]),Lt=o.useMemo(()=>{const r=new Map;for(const i of V)i.available&&i.context?.available&&r.set(i.root,i);return r.size===0&&ae?.available&&ae.root&&r.set(ae.root,{id:ae.root,root:ae.root,relativeRoot:".",name:Ke,depth:0,nested:!1,available:!0,files:Array.from(we.values()).filter(i=>it(i,b)===ae.root),context:ae}),Array.from(r.values()).sort((i,u)=>i.root===b?-1:u.root===b?1:(i.relativeRoot||i.name).localeCompare(u.relativeRoot||u.name)).map(i=>{const u=i.relativeRoot==="."?Ke:i.relativeRoot||i.name||ft(i.root),x=Md(i.files),v=i.files.length;return{value:i.root,label:u,meta:[i.context?.branch,v>0?a("rightSidebar.repoChangedCount",{count:v}):null,x>0?a("rightSidebar.repoStagedCount",{count:x}):null].filter(Boolean).join(" · ")}})},[we,ae,V,Ke,b,a]),ve=o.useMemo(()=>ce&&Lt.some(r=>r.value===ce)?ce:Dt?.repoRoot&&Lt.some(r=>r.value===Dt.repoRoot)?Dt.repoRoot:Lt.length===1||Lt.length>1?Lt[0].value:null,[ce,Lt,Dt?.repoRoot]),Xl=ve?gt.get(ve)??null:null,ue=Xl?.context?.available?Xl.context:ve===ae?.root?ae:null,We=Lt.length>0&&!ve,Jl=o.useMemo(()=>We?[]:ve?Array.from(we.values()).filter(r=>it(r,b)===ve):Array.from(we.values()),[ve,we,We,b]),gn=o.useMemo(()=>$d(Jl),[Jl]),To=!!(ue?.available&&ue.root&&ve&&ue.root===ve),Cf=ve?Lt.find(r=>r.value===ve)?.label??ft(ve):a("rightSidebar.gitRepositoryPlaceholder"),Ql=To?ue?.branch??"HEAD":We?a("rightSidebar.selectRepositoryForGitActions"):nn?a("rightSidebar.gitActionRunning"):"HEAD",Hn=!!(ue?.available&&ue.root===ve&&ue.status);o.useEffect(()=>{Zi.current={count:tr.length,loading:Nn,loadingMore:Q,hasMore:ro}},[tr.length,ro,Nn,Q]),o.useEffect(()=>{Tr.current+=1,ar.current?.abort(),bt("right-sidebar-recent-commits"),ar.current=null,Zr(""),rr([]),en(!1),Be(!1),sr(null),Mn(!1)},[ve]);const hs=o.useCallback(async(r={})=>{if(!b||!ve||We)return;const i=r.reset??!1,u=Zi.current,x=i?0:u.count;if(!i&&(u.loading||u.loadingMore||!u.hasMore))return;const v=Tr.current+1;Tr.current=v,ar.current?.abort(),bt("right-sidebar-recent-commits");const R=new AbortController;ar.current=R,i?en(!0):Be(!0),sr(null);try{const T=await Ph({cwd:b,repoRoot:ve,limit:ng,skip:x,query:ts.trim(),requestSlotId:"right-sidebar-recent-commits"},R.signal);if(Tr.current!==v)return;if(!T.available){sr(T.error??"Recent commits are unavailable"),i&&rr([]),Mn(!1);return}rr(H=>i?T.commits:[...H,...T.commits]),Mn(T.hasMore)}catch(T){if(Tr.current!==v||Nr(T))return;sr(T instanceof Error?T.message:"Failed to load recent commits"),i&&rr([]),Mn(!1)}finally{ar.current===R&&(ar.current=null),Tr.current===v&&(en(!1),Be(!1))}},[ve,ts,We,b]);o.useEffect(()=>{er&&hs({reset:!0})},[ts,hs,er]);const Nf=o.useCallback(r=>{const i=r.currentTarget;i.scrollTop+i.clientHeight<i.scrollHeight-48||hs({reset:!1})},[hs]);o.useEffect(()=>{!ve||!ae?.available||!Xe||!or||Hn||nn||We||jo(ve)},[ve,ae?.available,Hn,nn,Xe,or,jo,We]),o.useEffect(()=>{!t||!pt&&!Xe||!b||lr()},[pt,Xe,t,lr,b]),o.useEffect(()=>{!t||!Xe||!or||!rs||!b||sa(null)},[rs,Xe,or,t,sa,b]);const Mf=o.useMemo(()=>{if(!ce)return 0;const r=be.findIndex(i=>i.root===ce);return r>=0?r+1:0},[ce,be]),Zl=o.useCallback(r=>{if(!r)return null;const i=Array.from(we.values()).filter(u=>it(u,b)===r).sort((u,x)=>u.path.localeCompare(x.path))[0];return i?ut(i):null},[we,b]),bn=be.length>1,da=o.useMemo(()=>[{root:null,label:a("rightSidebar.allRepositories"),count:we.size,branch:null,deferred:!1},...be.map(r=>({root:r.root,label:r.label,count:r.deferred?Po.get(r.root)??0:r.count,branch:r.branch??null,deferred:!!r.deferred&&!Po.has(r.root)}))],[we.size,be,Po,a]),ec=da[Mf]??da[0],ua=!!ce,tc=o.useMemo(()=>bu(be,V),[be,V]);o.useEffect(()=>{ce&&!tc.has(ce)&&(Je(null),ri(b,null)),Jr(r=>r.filter(i=>be.some(u=>u.root===i)))},[ce,be,tc,b]);const $f=o.useMemo(()=>{const r=new Set;ue?.branch&&r.add(ue.branch);for(const i of ue?.branches??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0}))},[ue?.branch,ue?.branches,a]),rc=o.useMemo(()=>{const r=new Set;ue?.upstreamRemote&&r.add(ue.upstreamRemote);for(const i of ue?.remotes??[])r.add(i);return Array.from(r).map(i=>({value:i,label:i,meta:i===ue?.upstreamRemote?a("rightSidebar.pushUpstreamBadge"):void 0}))},[ue?.remotes,ue?.upstreamRemote,a]),nc=rc.length>1,Ef=o.useMemo(()=>{const r=[],i=new Set,u=(v,R)=>{!v||i.has(v)||(i.add(v),r.push({value:v,label:v,meta:R}))};u(ue?.upstreamBranch,ue?.upstreamBranch?a("rightSidebar.pushUpstreamBadge"):void 0),u(ue?.branch,ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):void 0);for(const v of ue?.branches??[])u(v,v===ue?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");const x=ue?.upstreamRemote;for(const v of ue?.remoteBranches??[]){const R=v.indexOf("/"),T=R>=0?v.slice(0,R):null,H=R>=0?v.slice(R+1):v;(!x||T===x)&&u(H,"remote")}return r},[ue?.branch,ue?.branches,ue?.remoteBranches,ue?.upstreamBranch,ue?.upstreamRemote,a]),_t=o.useMemo(()=>Lt.map(r=>{const i=gt.get(r.value);return{root:r.value,label:r.label,branch:i?.context?.branch??null}}),[Lt,gt]);o.useEffect(()=>{_t.length!==0&&(Bs(r=>{let i=!1;const u={...r},x=new Set(_t.map(v=>v.root));for(const v of Object.keys(u))x.has(v)||(delete u[v],i=!0);for(const v of _t)!u[v.root]&&v.branch&&(u[v.root]=v.branch,i=!0);return i?u:r}),Os(r=>{let i=!1;const u={...r},x=new Set(_t.map(v=>v.root));for(const v of Object.keys(u))x.has(v)||(delete u[v],i=!0);for(const v of _t){const R=gt.get(v.root)?.context;if(u[v.root]&&xu(u[v.root],R?.branch)&&(delete u[v.root],i=!0),u[v.root])continue;const T=xd(R);T&&(u[v.root]=T,i=!0)}return i?u:r}))},[_t,gt]);const fa=o.useMemo(()=>{const r=new Set(_t.map(i=>i.root));return _s.filter(i=>r.has(i))},[_s,_t]),ha=fa.length===0,cr=o.useMemo(()=>ha?_t:_t.filter(r=>fa.includes(r.root)),[_t,fa,ha]),Kt=o.useMemo(()=>cr.filter(r=>!!Rt[r.root]?.trim()),[Rt,cr]),sc=o.useMemo(()=>cr.filter(r=>!Rt[r.root]?.trim()),[Rt,cr]),ac=o.useCallback(async r=>{if(!r||yo.current.has(r))return;const i=gt.get(r)?.context;if((i?.branches?.length??0)>0||(i?.remoteBranches?.length??0)>0||i?.upstream)return;const u=b;yo.current.add(r),nl(x=>new Set(x).add(r));try{const x=await Uc(r,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${r}`);if(!x.available||!ke(u))return;ye(v=>v.map(R=>R.root===r?{...R,available:!0,context:{...R.context,...x},error:void 0}:R)),Bs(v=>v[r]||!x.branch?v:{...v,[r]:x.branch}),Os(v=>{if(v[r])return v;const R=xd(x);return R?{...v,[r]:R}:v})}catch(x){Nr(x)||console.warn("[RightSidebar] Failed to load branch audit repo details",r,x)}finally{yo.current.delete(r),nl(x=>{const v=new Set(x);return v.delete(r),v})}},[gt,ke,b]);o.useEffect(()=>{if(no)for(const r of cr)ac(r.root)},[no,cr,ac]),o.useEffect(()=>{!To||!ue||(Ws(ue.branch||(ue.branches?.[0]??"")),Gs(ue.upstreamRemote||(ue.remotes?.includes("origin")?"origin":ue.remotes?.[0]??"")),qs(ue.upstreamBranch||ue.branch||(ue.branches?.[0]??"")))},[ue,To]);const oc=o.useMemo(()=>{if(We)return{text:a("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Hn||nn)return{text:a("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!ue?.upstream)return{text:a("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const r=ue.ahead??0,i=ue.behind??0;return r>0&&i>0?{text:a("rightSidebar.pushDivergedCount",{ahead:r,behind:i}),className:"bg-destructive/10 text-destructive"}:r>0?{text:a("rightSidebar.pushAheadCount",{count:r}),className:"bg-accent/10 text-accent"}:i>0?{text:a("rightSidebar.pushBehindCount",{count:i}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:a("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[ue?.ahead,ue?.behind,ue?.upstream,Hn,nn,We,a]),Lf=o.useCallback(r=>{if(r&&!ee){const i=r.currentTarget.getBoundingClientRect();W({x:Math.min(i.left,window.innerWidth-352),y:Math.min(i.bottom+6,window.innerHeight-64)})}else W(null);N?.()},[ee,N]),Io=o.useCallback(()=>{W(null),I?.()},[I]);function ic(){if(!bn)return null;const r=ec?.label??a("rightSidebar.allRepositories"),i=ec?.count??we.size,u=ft(r)||r;return e.jsxs("button",{type:"button",onClick:Lf,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 ${k?"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":k,title:r,children:[e.jsx(Cr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:u}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${i>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:i}),e.jsx(Ns,{size:12,className:"shrink-0"})]})}function Af(){if(!k||!bn||typeof document>"u")return null;const r=typeof window>"u"?1024:window.innerWidth,i=typeof window>"u"?768:window.innerHeight,u=Math.max(12,Math.min(Le?.x??r-368,r-352)),x=Math.max(12,Math.min(Le?.y??80,i-420)),v=ee?void 0:{left:u,top:x},R=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Io,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:v,onClick:T=>T.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:a("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:da.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${we.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:we.size})]})]}),e.jsx("button",{type:"button",onClick:Io,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.close"),children:e.jsx(Ot,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:da.map(T=>{const H=(T.root??null)===ce,Y=ft(T.label)||T.label;return e.jsxs("button",{type:"button",onClick:()=>{Nc(T.root),Io()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${H?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:T.label,role:"option","aria-selected":H,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${H?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${H?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Cr,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:Y}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:T.root===null?a("rightSidebar.allRepositories"):T.label})]}),T.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:T.branch}),T.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:a("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${T.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:T.count})]},T.root??"all")})})]})});return ru(R,ee,document.body)}function Pf(){return Af()}function lc(r){const i=it(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path),x=Ua(u,i??b);return{key:ut(r),path:r.path,absolutePath:u,displayName:x.name,displayDir:x.dir,oldPath:r.oldPath,status:r.status,title:u}}function cc(r){return r.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:a("rightSidebar.changedFromPath",{path:r.oldPath})}):null}function dc(r,i){const u=Na(r,b),x=`path:${u}`,v=q===x,R=Re===x,T=v||R;return e.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),zr(u,x)},...Mo(ia(u),x),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 ${T?"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"} ${T?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:i,children:e.jsx("span",{className:"whitespace-nowrap",children:a(R?"rightSidebar.copied":v?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function uc(r){const i=it(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path),x=oh(r),v=fi(r);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(cb,{actions:x,running:Ae,completed:$n?.path===v?$n:null}),dc(u,a("rightSidebar.insertThisFile"))]})}function fc(r,i){const u=i.root??b;if(!u)return null;const x=Na(r,u);return dc(x,a("fileTree.insertRefTitle"))}function Fo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":a("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>wc("unified"),"aria-pressed":Jt==="unified",title:a("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Jt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>wc("split"),"aria-pressed":Jt==="split",title:a("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Jt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("diffViewer.split")})]})}function hc(){return ms.map(r=>{const i=Md(r.files.map(([,R])=>R)),u=Mi({activeGitRepoRoot:ce,groupCount:ms.length,label:r.label,rootName:Ke}),x=!!(u&&r.root&&Wt.has(r.root));return{key:r.root??r.label,root:r.root,label:r.label,branch:r.branch,collapsed:x,files:r.files.map(([,R])=>lc(R)),header:u?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${x?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Qf(r.root),"aria-expanded":!x,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:x?e.jsx(Ca,{size:13}):e.jsx(Ns,{size:13})}),e.jsx(Cr,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:r.label}),r.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:r.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:r.files.length}),i>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:i})]}),r.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),ka("stage-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),ka("stash-all",r.root,r.label)},disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]})]}):null}})}function mc(){return we.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:a("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:pa.map(([,r])=>{const i=it(r,b),u=r.absolutePath||(i?`${i}/${r.path}`:r.path);return{key:ut(r),path:r.path,absolutePath:u,status:r.status,repoRoot:i,displayName:Ua(u,i).name,displayDir:Ua(u,i).dir,auditRecords:jt}})}function pc(r){const i=Array.from(we.values()).find(v=>ut(v)===r.key),u=i?it(i,b):null,x=qm(jt,u,i?.path??r.path);return e.jsx(Si,{changeStatus:r.status,auditStatus:x,renderChangeBadge:v=>e.jsx(Ss,{status:v})})}const ma=o.useCallback(r=>{if(ee)return null;const i=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(i.length===0)return null;const x=r.getBoundingClientRect().top+48;let v=null,R=Number.POSITIVE_INFINITY;for(const H of i){const Y=H.getBoundingClientRect();if(Y.bottom<x)continue;const Ce=Math.abs(Y.top-x);Ce<R&&(v=H,R=Ce)}const T=v?.dataset.diffSelectionPath??v?.dataset.diffStreamItem??null;return T?(ta.current===T&&te.getState().selectedFilePath===T||(ta.current=T,Ye(T)),T):null},[ee,Ye]),Tf=!!(!Ae&&ve&&!We&&(ue?.upstream||sn.trim()&&an.trim())),If=!!(!Ae&&ve&&!We&&(ue?.upstream||sn.trim()&&an.trim())),Ff=!!(!Ae&&ve&&!We&&Ln.trim()&&Ln.trim()!==ue?.branch),Bt=o.useMemo(()=>{const r=le.trim().toLowerCase(),i=Array.from(we.entries()).filter(([,u])=>!ce||it(u,b)===ce).sort(([u],[x])=>u.localeCompare(x));return r?i.filter(([u,x])=>`${u} ${x.path} ${x.status} ${x.repoRelativeRoot??""} ${x.repoName??""}`.toLowerCase().includes(r)):i},[ce,we,le,b]);o.useEffect(()=>{Da("selected_file_state",{selectedFilePath:Ve,selectedChangedFilePath:Dt?.path??null,selectedChangedFileAbsolutePath:Dt?.absolutePath??null,selectedChangedFileRepoRoot:Dt?.repoRoot??null,rootPath:b,activeGitRepoRoot:ce,rightTab:po,effectiveRightTab:Hr,diffPaneActive:pt,changedFiles:we.size,filteredChangedFiles:Bt.length,gitBundleLoading:Dr,gitBundleLastLoadedAt:In})},[ce,we.size,pt,Hr,Bt.length,In,Dr,po,b,Dt?.absolutePath,Dt?.path,Dt?.repoRoot,Ve]);const ms=o.useMemo(()=>{const r=new Map;for(const i of Bt){const[,u]=i,x=it(u,b),v=ib(u)||Ke,R=x??v,T=x?gt.get(x):void 0,H=r.get(R)??{root:x,label:v,branch:T?.context?.branch,files:[]};H.files.push(i),r.set(R,H)}return Array.from(r.values()).sort((i,u)=>i.label===Ke?-1:u.label===Ke?1:i.label.localeCompare(u.label))},[Bt,gt,Ke,b]),pa=o.useMemo(()=>{const r=[],i=new Map;for(const u of Bt)i.set(ut(u[1]),u);for(const u of ms){if(!!(u.root&&Mi({activeGitRepoRoot:ce,groupCount:ms.length,label:u.label,rootName:Ke})&&Wt.has(u.root)))continue;if(St!=="tree"){r.push(...u.files);continue}const v=u.files.map(([,R])=>lc(R));for(const R of um(v)){const T=i.get(R.key);T&&r.push(T)}}return r},[ce,Wt,St,ms,Bt,Ke]);o.useEffect(()=>{if(!pt||pa.length===0||ee)return;const r=[],i=()=>{const u=document.querySelector(".termdock-diff-stream-scroller");if(u&&ma(u))return;const x=document.querySelector("[data-diff-stream-item]"),v=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;if(v){ta.current=v,Ye(v);return}const R=pa[0]?.[1];if(!R)return;const T=ut(R);ta.current=T,Ye(T)};for(const u of[80,240,600,1200])r.push(window.setTimeout(i,u));return()=>r.forEach(u=>window.clearTimeout(u))},[pt,ee,pa,Ye,ma]);const Do=o.useMemo(()=>{const r=T=>`'${T.replace(/'/g,"'\\''")}'`,i=Gt.length>0?fn:V.filter(T=>T.files.length>0),u=i.length>0?i:b?[{root:b,relativeRoot:".",name:Ke}]:[],x=u.length>0?u.map(T=>`- ${T.relativeRoot==="."?".":T.relativeRoot} (${T.root})`).join(`
1667
1667
  `):`- ${b?".":""}`,v=u.length>0?u.map(T=>` td audit-export ${r(T.root)}`).join(`
1668
1668
  `):" td audit-export",R=u.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${b??""}`,"目标仓库:",x,"","执行步骤:","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 后批量注入:",R,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
1669
- `)},[qt.length,un,V,Ve,b]),If=o.useCallback((r="generate")=>{if(gn&&Xr.length===0&&!ce){Tr(!0);return}const i=r==="generate"?Do:[r==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Do].join(`
1670
- `);et("insert_change_audit_prompt",{rootPath:b,activeGitRepoRoots:qt,mode:r,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Wr(a("rightSidebar.insertChangeAuditPrompt"),i,`${Hl}:${r}`),lr(),d||s()},[ce,Do,Xr.length,qt,Wr,lr,s,d,b,gn,a]),xa=o.useCallback(async r=>{try{await Oc({ids:[r]}),Yr(i=>i.filter(u=>u.id!==r))}catch{lr()}},[lr]),Ff=o.useCallback(async()=>{if(jt.length===0)return;const r=jt.map(i=>i.id);try{await Oc({ids:r}),Yr(i=>i.filter(u=>!r.includes(u.id))),Tt(null)}catch(i){const u=i instanceof Error?i.message:"Failed to clear change audit explanations";Tt(a("rightSidebar.changeAuditClearFailed",{message:u})),lr()}},[jt,lr,a]),_f=o.useCallback(async r=>{if(r.records.length===0)return;const i=r.records.map(u=>u.id);try{await Ah({ids:i}),br(u=>u.filter(x=>!i.includes(x.id))),Ze===r.key&&(tn(null),Qt(!1))}catch(u){ut(a("rightSidebar.branchAuditClearFailed",{message:u instanceof Error?u.message:"Failed to clear branch explanation"})),oa(null)}},[oa,Ze,a]),Df=o.useCallback(r=>{Jr(i=>r===null?(Tr(!1),[]):i.includes(r)?i.filter(u=>u!==r):[...i,r])},[]),Bf=o.useCallback(r=>{io(i=>r===null?(oo(!1),[]):i.includes(r)?i.filter(u=>u!==r):[...i,r])},[]),Bo=o.useMemo(()=>{if(!or)return[];const r=i=>{const u=i.diff??"";let x=0,v=0;for(const R of u.split(`
1671
- `))R.startsWith("+++")||R.startsWith("---")||(R.startsWith("+")&&(x+=1),R.startsWith("-")&&(v+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:x,deletions:v,diff:u}};return Me?(Me.hunks??[]).map(i=>{const u=gr.find(x=>x.repoRoot===Me.repoRoot&&x.baseRef===Me.baseRef&&(x.branchName??null)===(Me.currentBranch??null)&&x.filePath===i.filePath&&x.hunkHeader===i.hunkHeader&&(x.hunkIndex??0)===i.hunkIndex&&x.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,hunk:i,current:u,stale:null}}):Ze?gr.filter(i=>md(i)===Ze).map(i=>{const u=r(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:u,current:i,stale:null}}):[]},[Me,gr,or,Ze]),Oo=gr.length>0,Un=o.useMemo(()=>{if(!or)return[];const r=new Map;for(const i of gr){const u=i.repoRoot,x=bt.get(u),v=x?.relativeRoot==="."?Ve:x?.relativeRoot||x?.name||mt(u),R=md(i),T=r.get(R)??{key:R,repoRoot:u,repoLabel:v,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};T.records.push(i),T.latestInjectedAt=Math.max(T.latestInjectedAt,i.injectedAt??0),r.set(R,T)}return Array.from(r.values()).sort((i,u)=>u.latestInjectedAt-i.latestInjectedAt)},[gr,bt,or,Ve]),Uo=o.useMemo(()=>Ze?Un.find(r=>r.key===Ze)??null:null,[Un,Ze]),va=Me?{repoRoot:Me.repoRoot??"",repoLabel:Me.repoRoot?bt.get(Me.repoRoot)?.relativeRoot==="."?Ve:bt.get(Me.repoRoot)?.relativeRoot||bt.get(Me.repoRoot)?.name||mt(Me.repoRoot):Ve,baseRef:Me.baseRef??Me.baseBranch??"",branchName:Me.currentBranch??null,headRef:Me.headRef??null,diffFingerprint:Me.diffFingerprint??null}:Uo,Of=o.useMemo(()=>(Ue?.hunks??[]).map(r=>({key:`${r.filePath}\0${r.hunkHeader}\0${r.hunkIndex}`,hunk:r,current:null,stale:null})),[Ue?.hunks]),Uf=o.useMemo(()=>{if(Me)return[];const r=Uo;return r?wn.filter(i=>i.repoRoot===r.repoRoot&&i.baseRef===r.baseRef&&(i.branchName??null)===r.branchName&&(!r.diffFingerprint||i.diffFingerprint===r.diffFingerprint)):[]},[Me,wn,Uo]),Hf=o.useCallback(r=>{const i=Bo.find(u=>u.hunk.filePath===r.filePath||(r.repoRoot?`${r.repoRoot}/${u.hunk.filePath}`===r.filePath:!1));i&&(rn(i.key),window.setTimeout(()=>bn(r),90),window.setTimeout(()=>bn(r),320),window.setTimeout(()=>bn(r),760))},[Bo]),Ho=o.useMemo(()=>{const r=v=>`'${v.replace(/'/g,"'\\''")}'`,i=Vt,u=i.length>0?i.map(v=>`- ${v.label} (${v.root}),目标分支:${yr[v.root]||v.branch||"(current branch)"},基线分支:${Rt[v.root]||"(not set)"}`).join(`
1672
- `):`- ${b?".":""}`,x=i.length>0?i.map(v=>{const R=yr[v.root]||v.branch||"",T=Rt[v.root]||"",H=v.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[R?` git -C ${r(v.root)} switch ${r(R)}`:` # ${v.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${r(T)} ${r(v.root)} > ~/.termdock/branch-audit/branch-audit-export-${H}.json`].join(`
1669
+ `)},[Gt.length,fn,V,Ke,b]),Df=o.useCallback((r="generate")=>{if(bn&&Xr.length===0&&!ce){Pr(!0);return}const i=r==="generate"?Do:[r==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Do].join(`
1670
+ `);et("insert_change_audit_prompt",{rootPath:b,activeGitRepoRoots:Gt,mode:r,hasAuditListCommand:i.includes("td audit-list"),promptLength:i.length}),Wr(a("rightSidebar.insertChangeAuditPrompt"),i,`${zl}:${r}`),lr(),d||s()},[ce,Do,Xr.length,Gt,Wr,lr,s,d,b,bn,a]),ga=o.useCallback(async r=>{try{await Hc({ids:[r]}),Yr(i=>i.filter(u=>u.id!==r))}catch{lr()}},[lr]),_f=o.useCallback(async()=>{if(jt.length===0)return;const r=jt.map(i=>i.id);try{await Hc({ids:r}),Yr(i=>i.filter(u=>!r.includes(u.id))),Pt(null)}catch(i){const u=i instanceof Error?i.message:"Failed to clear change audit explanations";Pt(a("rightSidebar.changeAuditClearFailed",{message:u})),lr()}},[jt,lr,a]),Bf=o.useCallback(async r=>{if(r.records.length===0)return;const i=r.records.map(u=>u.id);try{await Th({ids:i}),gr(u=>u.filter(x=>!i.includes(x.id))),Ze===r.key&&(tn(null),Qt(!1))}catch(u){dt(a("rightSidebar.branchAuditClearFailed",{message:u instanceof Error?u.message:"Failed to clear branch explanation"})),sa(null)}},[sa,Ze,a]),Of=o.useCallback(r=>{Jr(i=>r===null?(Pr(!1),[]):i.includes(r)?i.filter(u=>u!==r):[...i,r])},[]),Uf=o.useCallback(r=>{ao(i=>r===null?(so(!1),[]):i.includes(r)?i.filter(u=>u!==r):[...i,r])},[]),_o=o.useMemo(()=>{if(!or)return[];const r=i=>{const u=i.diff??"";let x=0,v=0;for(const R of u.split(`
1671
+ `))R.startsWith("+++")||R.startsWith("---")||(R.startsWith("+")&&(x+=1),R.startsWith("-")&&(v+=1));return{filePath:i.filePath,oldPath:i.oldPath,newPath:i.newPath,hunkHeader:i.hunkHeader,hunkIndex:i.hunkIndex??0,fingerprint:i.fingerprint,additions:x,deletions:v,diff:u}};return Me?(Me.hunks??[]).map(i=>{const u=pr.find(x=>x.repoRoot===Me.repoRoot&&x.baseRef===Me.baseRef&&(x.branchName??null)===(Me.currentBranch??null)&&x.filePath===i.filePath&&x.hunkHeader===i.hunkHeader&&(x.hunkIndex??0)===i.hunkIndex&&x.fingerprint===i.fingerprint)??null;return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex}`,hunk:i,current:u,stale:null}}):Ze?pr.filter(i=>gd(i)===Ze).map(i=>{const u=r(i);return{key:`${i.filePath}\0${i.hunkHeader}\0${i.hunkIndex??0}`,hunk:u,current:i,stale:null}}):[]},[Me,pr,or,Ze]),Bo=pr.length>0,zn=o.useMemo(()=>{if(!or)return[];const r=new Map;for(const i of pr){const u=i.repoRoot,x=gt.get(u),v=x?.relativeRoot==="."?Ke:x?.relativeRoot||x?.name||ft(u),R=gd(i),T=r.get(R)??{key:R,repoRoot:u,repoLabel:v,baseRef:i.baseRef,branchName:i.branchName??null,headRef:i.headRef??null,diffFingerprint:i.diffFingerprint??null,records:[],latestInjectedAt:0};T.records.push(i),T.latestInjectedAt=Math.max(T.latestInjectedAt,i.injectedAt??0),r.set(R,T)}return Array.from(r.values()).sort((i,u)=>u.latestInjectedAt-i.latestInjectedAt)},[pr,gt,or,Ke]),Oo=o.useMemo(()=>Ze?zn.find(r=>r.key===Ze)??null:null,[zn,Ze]),ba=Me?{repoRoot:Me.repoRoot??"",repoLabel:Me.repoRoot?gt.get(Me.repoRoot)?.relativeRoot==="."?Ke:gt.get(Me.repoRoot)?.relativeRoot||gt.get(Me.repoRoot)?.name||ft(Me.repoRoot):Ke,baseRef:Me.baseRef??Me.baseBranch??"",branchName:Me.currentBranch??null,headRef:Me.headRef??null,diffFingerprint:Me.diffFingerprint??null}:Oo,Hf=o.useMemo(()=>(Ue?.hunks??[]).map(r=>({key:`${r.filePath}\0${r.hunkHeader}\0${r.hunkIndex}`,hunk:r,current:null,stale:null})),[Ue?.hunks]),zf=o.useMemo(()=>{if(Me)return[];const r=Oo;return r?kn.filter(i=>i.repoRoot===r.repoRoot&&i.baseRef===r.baseRef&&(i.branchName??null)===r.branchName&&(!r.diffFingerprint||i.diffFingerprint===r.diffFingerprint)):[]},[Me,kn,Oo]),Wf=o.useCallback(r=>{const i=_o.find(u=>u.hunk.filePath===r.filePath||(r.repoRoot?`${r.repoRoot}/${u.hunk.filePath}`===r.filePath:!1));i&&(rn(i.key),window.setTimeout(()=>xn(r),90),window.setTimeout(()=>xn(r),320),window.setTimeout(()=>xn(r),760))},[_o]),Uo=o.useMemo(()=>{const r=v=>`'${v.replace(/'/g,"'\\''")}'`,i=Kt,u=i.length>0?i.map(v=>`- ${v.label} (${v.root}),目标分支:${vr[v.root]||v.branch||"(current branch)"},基线分支:${Rt[v.root]||"(not set)"}`).join(`
1672
+ `):`- ${b?".":""}`,x=i.length>0?i.map(v=>{const R=vr[v.root]||v.branch||"",T=Rt[v.root]||"",H=v.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[R?` git -C ${r(v.root)} switch ${r(R)}`:` # ${v.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${r(T)} ${r(v.root)} > ~/.termdock/branch-audit/branch-audit-export-${H}.json`].join(`
1673
1673
  `)}).join(`
1674
- `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${b??""}`,`包含本地未提交更改:${Fr?"是":"否"}`,"目标仓库:",u,"","操作指令:",Fr?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",x,"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:b??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
- `)},[Fr,Vt,Rt,yr,b]),zf=o.useCallback((r="generate")=>{const i=r==="generate"?Ho:[r==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",Ho].join(`
1676
- `);Wr(a("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${r}`),d||s()},[Ho,Wr,s,d,a]),Wf=o.useCallback(async()=>{if(!b||Vt.length===0)return;const r=b;z(!0),xe(null),Zt(null),$e(null);try{const i=await Promise.all(Vt.map(async H=>{const X=Rt[H.root]?.trim();if(!X)throw new Error(a("rightSidebar.branchAuditMissingBase",{repo:H.label}));const ke=(yr[H.root]||H.branch||"").trim();return Ph({cwd:b,repoRoot:H.root,base:X,head:ke&&ke!==H.branch?ke:null,includeUncommitted:Fr,requestSlotId:`right-sidebar-branch-preview:${H.root}`})}));if(!je(r))return;const u=i.find(H=>!H.available);if(u){xe(u.error??"Branch diff is unavailable");return}const x=i.length===1?i[0]:{available:!0,workspaceRoot:b,repoRoot:b,baseRef:i.map(H=>H.baseRef??H.baseBranch).filter(Boolean).join(", "),currentBranch:i.map(H=>H.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:i.map(H=>H.headRef).filter(Boolean).join(", "),diffFingerprint:i.map(H=>H.diffFingerprint).filter(Boolean).join("+"),stat:i.map(H=>H.stat).filter(Boolean).join(`
1677
- `),files:i.flatMap((H,X)=>{const ke=Vt[X];return(H.files??[]).map(Ie=>`${ke?.label??H.repoRoot??"repo"}/${Ie}`)}),hunks:i.flatMap((H,X)=>{const Ie=Vt[X]?.label??H.repoRoot??"repo";return(H.hunks??[]).map(Ge=>({...Ge,filePath:`${Ie}/${Ge.filePath}`,oldPath:Ge.oldPath?`${Ie}/${Ge.oldPath}`:Ge.oldPath,newPath:Ge.newPath?`${Ie}/${Ge.newPath}`:Ge.newPath}))}),commits:i.flatMap(H=>H.commits??[]),commitCount:i.reduce((H,X)=>H+(X.commitCount??X.commits?.length??0),0),diff:i.map(H=>H.diff).filter(Boolean).join(`
1678
- `),truncated:i.some(H=>H.truncated)};if((x.hunks??[]).length===0){xe(a("rightSidebar.branchAuditDiffEmpty"));return}const v=Date.now(),R=["preview",x.repoRoot??b,x.baseRef??x.baseBranch??"",x.currentBranch??"",x.headRef??"",x.diffFingerprint??v].join("\0"),T=Vt.length===1?Vt[0].label:`${Vt.length} repos`;Zt(x),Qn(H=>[{key:R,diff:x,repoLabel:T,createdAt:v},...H.filter(X=>X.key!==R)].slice(0,8)),jn(H=>H[R]===void 0?H:{...H,[R]:0}),tn(R),rn(x.hunks?.[0]?`${x.hunks[0].filePath}\0${x.hunks[0].hunkHeader}\0${x.hunks[0].hunkIndex}`:null),Qt(!0)}catch(i){if(!je(r)||dr(i))return;xe(i instanceof Error?i.message:"Failed to load branch diff")}finally{je(r)&&z(!1)}},[Fr,Vt,Rt,yr,je,b,a]),Gf=o.useCallback(r=>{Zt(r.diff),xe(null),tn(r.key),rn(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),Qt(!0)},[]),qf=o.useCallback(r=>{Qn(i=>i.filter(u=>u.key!==r)),jn(i=>{if(!(r in i))return i;const u={...i};return delete u[r],u}),Ze===r&&(tn(null),Zt(null),Qt(!1))},[Ze]),Kf=o.useCallback(r=>{const i=Un.find(u=>u.key===r);i&&(Zt(null),xe(null),tn(r),rn(i.records[0]?.filePath??null),Qt(!0))},[Un]),Vf=o.useCallback(async r=>{if(!b||!ye)return;const[i]=r.split(/\s+/);if(i){De(i),ot(null),$e(null);try{const u=await Th({cwd:b,repoRoot:ye,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!u.available){ot(u.error??"Commit diff is unavailable");return}$e(u);const x=u.hunks?.[0];Ds(x?`${x.filePath}\0${x.hunkHeader}\0${x.hunkIndex}`:null)}catch(u){ot(u instanceof Error?u.message:"Failed to load commit diff")}finally{De(null)}}},[ye,b]),Yf=o.useCallback(r=>{if(!Me||!Ze)return;const i=Math.max(0,Math.round(r));jn(u=>Math.abs((u[Ze]??0)-i)<24?u:{...u,[Ze]:i})},[Me,Ze]);o.useEffect(()=>{!ee||!xr||!Me||is(1)},[xr,Me,ee,is]);const mc=o.useCallback(r=>{r&&df(i=>im(i,r))},[]),pc=Xs.key===Ye?Xs.key:null,ya=o.useCallback(r=>{const i=te.getState(),u=pb();Ba("select_diff_file",{interactionId:u,path:r,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ce,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),Xe(r),on("diff"),ee&&r&&is(1),mc(r),queueMicrotask(()=>{const x=te.getState();Ba("select_diff_file_after",{interactionId:u,requestedPath:r,selectedFilePath:x.selectedFilePath,rootPath:x.rootPath,rightTab:x.rightTab,changedFiles:x.changedFiles.size,activeGitRepoRoot:ce})})},[ce,ee,mc,Xe,on,is]),gc=o.useCallback(r=>{const i=Array.from(ve.values()).find(u=>{const x=lt(u,b),v=ht(u);return u.path===r.filePath||v===r.filePath||u.absolutePath===r.filePath||(x?`${x}/${u.path}`===r.filePath:!1)||r.repoRoot&&x===r.repoRoot&&u.path===r.filePath});if(i){ya(ht(i)),window.setTimeout(()=>bn(r),90),window.setTimeout(()=>bn(r),320),window.setTimeout(()=>bn(r),760);return}bn(r)},[ve,b,ya]),bc=o.useCallback(({slideToDetail:r,fullscreen:i,toggleFullscreen:u}={})=>Xn.length>0?e.jsx(_d,{walkthroughs:Xn,repoRoot:ce,fullscreen:i,onToggleFullscreen:u,onNavigate:x=>{ee&&window.requestAnimationFrame(()=>r?.()),gc(x)}}):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(Es,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),a("rightSidebar.changeWalkthroughEmpty")]}),[ce,Xn,gc,ee,a]),Xf=o.useCallback(r=>{r&&Er(i=>{const u=new Set(i);return u.has(r)?u.delete(r):u.add(r),si(Zo,u),u})},[]),xc=o.useCallback(r=>{ro(i=>{const u=new Set(i);return u.has(r)?u.delete(r):u.add(r),si(nd,u),u})},[]),wa=o.useCallback(r=>{Is(r),vt(ru,r)},[]);o.useEffect(()=>{ha||St!=="ai"||wa("tree")},[St,wa,ha]);const ka=o.useCallback(()=>{Fs(r=>{const i=!r;return vt(nu,i),i})},[]),vc=o.useCallback(r=>{Vr(r),vt(su,r)},[]),{whitespace:yc,context:wc}=cm(),kc=o.useMemo(()=>({algorithm:"histogram",whitespace:yc,context:wc}),[yc,wc]),Sc=o.useCallback(r=>{D(r),vt(au,r)},[]),Sa=o.useCallback(async(r,i,u,x)=>{let v=r;for(;v.ok&&v.status==="running";)await new Promise(T=>window.setTimeout(T,1500)),v=await Uc({jobId:v.jobId,cwd:i.cwd,action:i.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const R={action:i.action,path:x,label:u};return rs(R),window.setTimeout(()=>rs(T=>T?.action===R.action&&T.path===R.path?null:T),1400),v},[]),it=o.useCallback(async(r,i,u)=>{const x=b;b&&ir.current.delete(b),ut(null),rs(null),ts({action:r.action,path:u});try{const v=await Ih({...r,includeNested:zn(b)}),R=await Sa(v,r,i,u);if(!je(x))return!1;const T=b?await Na(b,void 0,{includeNested:zn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Gn(b)}).catch(()=>R.bundle):R.bundle;return je(x)?(T&&Hr(T,{reloadDiff:!0,cacheOnly:!0}),_r(null),!0):!1}catch(v){return rs(null),ut(a("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{je(x)&&ts(null)}},[Hr,je,b,a,Sa]),jc=o.useCallback(async r=>{const i=b,u=await Fh({...r,includeNested:zn(b)});if(!je(i))return;const x=b?await Na(b,void 0,{includeNested:zn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Gn(b)}).catch(()=>u.bundle):u.bundle;je(i)&&x&&Hr(x,{reloadDiff:!0,cacheOnly:!0})},[Hr,je,b]),ja=o.useCallback((r,i,u)=>{if(i){if(r==="stage-all"){it({action:"stage-all",cwd:i},a("rightSidebar.stageAll"),`repo:${i}`);return}_r({kind:"stash-all",repoRoot:i,repoLabel:u})}},[it,a]),Rc=o.useCallback(r=>{Je(r),ni(b,r),Gs(""),qs(""),Ks(""),Xe(Jl(r)),Ke||on("diff"),r&&r!==b&&V.find(u=>u.root===r)?.deferred&&Kt(r,{includeNested:!1,background:!0,replaceRepoRoot:r})},[Jl,Ke,V,Kt,b,Xe,on]),Cc=o.useCallback(r=>{const i=new Set([..._t.current.keys(),...cn.current,...ir.current]);for(const u of i)u!==r&&(Ft.current.delete(u),_t.current.get(u)?.abort(),_t.current.delete(u),xt(`right-sidebar-git-untracked:${u}`),cn.current.delete(u),ir.current.delete(u))},[]),Jf=o.useCallback(async r=>{const i=b;if(!i||(await te.getState().setNestedGitScanRoot(i,r),!je(i)))return;if(r){await Kt(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Cc(i),Gs(""),qs(""),Ks(""),io(x=>x.filter(v=>v===i));const u=Dt;u&&lt(u,i)!==i&&Xe(null),await Kt(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Cc,je,Kt,b,Xe,Dt]),Qf=o.useCallback(async()=>{if(!ye||ze){ut(a("rightSidebar.selectRepositoryForGitActions"));return}const r=ns.trim();!r||r===ue?.branch||await it({action:"switch-branch",cwd:ye,branch:r},a("rightSidebar.switchBranch"))},[ue?.branch,ye,ze,it,ns,a]),Nc=o.useCallback(async()=>{if(!ye||ze){ut(a("rightSidebar.selectRepositoryForGitActions"));return}const r=Ws.trim();if(!r)return;await it({action:"commit",cwd:ye,message:r},a("rightSidebar.commitChanges"))&&ll("")},[ye,Ws,ze,it,a]),Zf=o.useCallback(async()=>{if(!ye||ze){ut(a("rightSidebar.selectRepositoryForGitActions"));return}const r=sn.trim(),i=an.trim();await it({action:"push",cwd:ye,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pushChanges"))},[ye,an,sn,ze,it,a]),eh=o.useCallback(async()=>{if(!ye||ze){ut(a("rightSidebar.selectRepositoryForGitActions"));return}const r=sn.trim(),i=an.trim();await it({action:"pull",cwd:ye,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pullChanges"))},[ye,an,sn,ze,it,a]);o.useEffect(()=>{if(!Ke||!ye||Pe)return;let r=!1;const i={push:a("rightSidebar.pushChanges"),pull:a("rightSidebar.pullChanges"),commit:a("rightSidebar.commitChanges"),"switch-branch":a("rightSidebar.switchBranch"),"stage-all":a("rightSidebar.stageAll"),"stash-all":a("rightSidebar.stashAll")};return(async()=>{for(const u of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const x=await Uc({cwd:ye,action:u}).catch(()=>null);if(!x?.ok||x.status!=="running")continue;const v={action:u,cwd:ye},R=i[u]??u;ts({action:u});try{const T=await Sa(x,v,R);if(r||!je(b))return;const H=b?await Na(b,void 0,{includeNested:zn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Gn(b)}).catch(()=>T.bundle):T.bundle;H&&Hr(H,{reloadDiff:!0,cacheOnly:!0})}catch(T){r||ut(a("rightSidebar.gitActionFailed",{message:T instanceof Error?T.message:"Unknown error"}))}finally{r||ts(null)}return}})(),()=>{r=!0}},[ye,Hr,Ke,je,b,Pe,a,Sa]);const zo=Mn?.action==="commit",Wo=Mn?.action==="switch-branch",Go=Mn?.action==="pull",qo=Mn?.action==="push",Ra=Ke||lf,Ko=pa?a("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,th=cr.length>0,Mc=Vt.length>0,rh=b?e.jsx(kd,{open:ao,onOpenChange:oo,showScopePicker:!0,selectedAll:pa,repos:Bt,selectedRoots:ma,onToggleRepo:Bf,onGenerate:()=>zf(Oo?"regenerate":"generate"),disabled:!th,generateDisabled:!Mc,inserted:q?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:a(Oo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.branchAuditGenerateTitle"),ariaLabel:a("rightSidebar.branchAuditShort"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:Ko,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a(Oo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Wf()},secondaryDisabled:!Mc||P,secondaryLabel:a("rightSidebar.branchAuditViewDiff"),secondaryTitle:a("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:P,loading:rl.size>0,statusTitle:rl.size>0?a("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:a("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:a("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Fr,onChange:r=>tl(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),rc.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:a("rightSidebar.missingBaseReposSkipped",{repositories:rc.map(r=>r.label).join(w==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const i=bt.get(r.root),u=[],x=new Set,v=(X,ke)=>{!X||x.has(X)||(x.add(X),u.push({value:X,label:X,meta:ke}))};v(yr[r.root]||i?.context?.branch,a("rightSidebar.pushCurrentBranchBadge"));for(const X of i?.context?.branches??[])v(X,X===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):a("rightSidebar.localBranch"));for(const X of i?.context?.remoteBranches??[])v(X,a("rightSidebar.remoteBranch"));const R=[],T=new Set,H=(X,ke)=>{!X||T.has(X)||(T.add(X),R.push({value:X,label:X,meta:ke}))};H(Rt[r.root],Rt[r.root]?a("rightSidebar.pushUpstreamBadge"):void 0),H(i?.context?.upstream,i?.context?.upstream?a("rightSidebar.pushUpstreamBadge"):void 0);for(const X of i?.context?.remoteBranches??[])H(X,"remote");for(const X of i?.context?.branches??[])H(X,X===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Wn,{label:a("rightSidebar.currentBranchLabel"),value:yr[r.root]||i?.context?.branch||"",options:u,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),onChange:X=>{Os(ke=>({...ke,[r.root]:X}))}}),e.jsx(Wn,{label:a("rightSidebar.branchAuditBaseLabel"),value:Rt[r.root]||"",options:R,placeholder:a("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:a("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:a("rightSidebar.branchAuditBaseEmpty"),onChange:X=>{Us(ke=>({...ke,[r.root]:X}))}})]})}}):null,$c=ys(jt.reduce((r,i)=>Math.max(r,i.injectedAt??0),0),w),nh=b?e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>el(r=>{const i=!r;return vt(ei,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":es,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(Es,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:Ko})]}),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 ${es?"rotate-90":""}`,children:e.jsx(Ma,{size:13})})]}),es&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[a("rightSidebar.changeAuditScopeLabel"),": ",Ko]}),rh]}),ie&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:ie}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Qr.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Gf(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:a("rightSidebar.branchAuditViewDiff")})]}),ys(r.createdAt,w)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:ys(r.createdAt,w)})]}),e.jsx("button",{type:"button",onClick:()=>qf(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("common.delete"),"aria-label":a("common.delete"),children:e.jsx(Oa,{size:12})})]},r.key)),Un.length>0?Un.slice(0,Math.max(0,8-Qr.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Kf(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),ys(r.latestInjectedAt,w)&&e.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:a("rightSidebar.branchAuditGeneratedAt",{time:ys(r.latestInjectedAt,w)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{_f(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("rightSidebar.branchAuditClearTitle"),"aria-label":a("rightSidebar.branchAuditClearTitle"),children:e.jsx(Oa,{size:12})})]},r.key)):Qr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Ec=or&&b&&On?e.jsxs("div",{className:Ra?"overflow-visible":"overflow-hidden",children:[nh,e.jsxs("button",{type:"button",onClick:()=>{Ke||cf(r=>{const i=!r;return i&&ye&&!On&&!nn&&Co(ye),i})},"aria-expanded":Ra,className:`group flex w-full items-center gap-2 px-1 py-1.5 text-left transition ${Ke?"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(Mr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex min-w-[4.5rem] items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${pn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[nn&&e.jsx(at,{size:10,className:"animate-spin"}),pn.staged>0?a("rightSidebar.stagedCount",{count:pn.staged}):a("rightSidebar.noStagedChangesShort")]}),!Ke&&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 ${Ra?"rotate-90":""}`,children:e.jsx(Ma,{size:13})})]})]}),Ra&&e.jsxs("div",{className:"space-y-0",children:[At.length>1&&e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:Sf})]})}),e.jsx(Wn,{label:a("rightSidebar.gitRepositoryLabel"),value:ye??"",options:At,placeholder:a("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:a("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:a("rightSidebar.gitRepositoryEmpty"),disabled:!!Pe,onChange:r=>{Rc(r||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:a("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:jf})]}),e.jsxs("button",{type:"button",onClick:()=>{Qf()},disabled:!Tf,className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Wo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Pe?.action==="switch-branch"||Wo?"opacity-0":"",children:a("rightSidebar.switchBranch")}),Pe?.action==="switch-branch"&&e.jsx(at,{size:12,className:"absolute animate-spin"}),Wo&&Pe?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Wn,{label:a("rightSidebar.currentBranchLabel"),value:ns,options:Nf,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),disabled:!!Pe,onChange:Gs})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:ze?a("rightSidebar.selectRepositoryForGitActions"):pn.staged>0?a("rightSidebar.commitReadyHint",{count:pn.staged}):a("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Nc()},disabled:!!Pe||ze||pn.staged===0||!Ws.trim(),className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition active:scale-95 ${zo?"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?a("rightSidebar.selectRepositoryForGitActions"):pn.staged===0?a("rightSidebar.commitNeedsStaged"):a("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Pe?.action==="commit"||zo?"opacity-0":"",children:a("rightSidebar.commitChanges")}),Pe?.action==="commit"&&e.jsx(at,{size:12,className:"absolute animate-spin"}),zo&&Pe?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Ws,onChange:r=>ll(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),Nc())},placeholder:a("rightSidebar.commitMessagePlaceholder"),disabled:!!Pe,className:"w-full rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-[12px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary/35 focus:ring-1 focus:ring-primary/25 disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>vr(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":er,children:[e.jsx("span",{className:"min-w-0 text-[11px] font-semibold text-foreground",children:a("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Cn&&e.jsx(at,{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 ${er?"rotate-90":""}`,children:e.jsx(Ma,{size:13})})]})]}),er&&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:Rn,onChange:r=>Zr(r.target.value),placeholder:a("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),Rn&&e.jsx("button",{type:"button",onClick:()=>Zr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Ut,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Rf,children:[tr.length>0?tr.map(r=>{const[i,...u]=r.split(/\s+/),x=u.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{Vf(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:x,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:x,children:x}),He===i&&e.jsx(at,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):Cn?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:a("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.recentCommitsEmpty")}),Q&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(at,{size:12,className:"animate-spin"})}),so&&!Q&&tr.length>0&&e.jsx("button",{type:"button",onClick:()=>{fs({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:a("rightSidebar.recentCommitsLoadMore")})]})]}),nt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:nt}),nr&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:nr})]}),e.jsxs("div",{className:"px-1 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:a("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{eh()},disabled:!Af,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${Go?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Pe?.action==="pull"||Go?"opacity-0":"",children:a("rightSidebar.pullChanges")}),Pe?.action==="pull"&&e.jsx(at,{size:12,className:"absolute animate-spin"}),Go&&Pe?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Zf()},disabled:!Pf,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${qo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Pe?.action==="push"||qo?"opacity-0":"",children:a("rightSidebar.pushChanges")}),Pe?.action==="push"&&e.jsx(at,{size:12,className:"absolute animate-spin"}),qo&&Pe?.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] ${sc.className}`,title:ue?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:sc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ue?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${tc?"grid-cols-2":"grid-cols-1"}`,children:[tc&&e.jsx(Wn,{label:a("rightSidebar.pushRemoteLabel"),value:sn,options:ec,placeholder:a("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:a("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:a("rightSidebar.pushNoRemotes"),disabled:!!Pe,onChange:qs}),e.jsx(Wn,{label:a("rightSidebar.pushBranchLabel"),value:an,options:Mf,placeholder:a("rightSidebar.pushBranchPlaceholder",{branch:ue?.branch??"HEAD"}),searchPlaceholder:a("rightSidebar.pushBranchSearchPlaceholder"),emptyText:a("rightSidebar.pushNoBranches"),disabled:!!Pe,onChange:Ks})]})]})]})]}):null,sh=o.useCallback(r=>{const i=lt(r,b);if(!i)return[];const u=fi(r),x=[];return r.canStage&&x.push({key:"stage-file",label:a("rightSidebar.stageFile"),onClick:()=>{it({action:"stage-file",cwd:i,paths:[r.path]},a("rightSidebar.stageFile"),u)}}),r.canUnstage&&x.push({key:"unstage-file",label:a("rightSidebar.unstageFile"),onClick:()=>{it({action:"unstage-file",cwd:i,paths:[r.path]},a("rightSidebar.unstageFile"),u)}}),r.canStash&&x.push({key:"stash-file",label:a("rightSidebar.stashFile"),onClick:()=>{it({action:"stash-file",cwd:i,paths:[r.path]},a("rightSidebar.stashFile"),u)}}),r.canRestoreWorktree&&x.push({key:"restore-worktree-file",label:a("rightSidebar.restoreFile"),destructive:!0,onClick:()=>_r({kind:"restore",file:r,phrase:""})}),x},[b,it,a]),ah=o.useCallback(()=>{if(m){f?.();return}kr(0),jr.current?.slideTo(0),wr(!1),kt(null)},[f,m]),Lc=o.useCallback(r=>{if(j(""),It(r),Xe(null),kt(null),ne(null),ee){m&&f?.(),kr(0),jr.current?.slideTo(0),wr(!1);return}},[ee,f,m,Xe,It]);o.useEffect(()=>{const r=i=>{const u=i.detail,x=u?.path;if(typeof x!="string"||!x.startsWith("/"))return;j(""),kt(null),Te(null);const v=!!(b&&(x===b||x.startsWith(`${b}/`)));if(u.kind==="file"){const R=ci(x);cs(x),typeof u.line=="number"&&Number.isSafeInteger(u.line)&&u.line>0&&Te(u.line),It(v?null:R),ne(T=>({path:x,nonce:(T?.nonce??0)+1}));return}Xe(null),v?(It(null),ne(R=>({path:x,nonce:(R?.nonce??0)+1}))):(ne(null),It(x)),ee&&(m&&f?.(),kr(0),jr.current?.slideTo(0),wr(!1))};return window.addEventListener(zc,r),()=>window.removeEventListener(zc,r)},[cs,ee,f,m,b,Xe,It]),o.useEffect(()=>{t||(Pt(!1),zt(!1))},[t]),o.useEffect(()=>{if(!Xt&&!hr)return;const r=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&(Ts.current?.contains(i.target)||yn.current?.contains(i.target))||(Pt(!1),zt(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[hr,Xt]);const Ac=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:yf,disabled:!da,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.parentFolder"),title:a("rightSidebar.parentFolder"),children:e.jsx(Pd,{size:14})}),e.jsx("button",{type:"button",onClick:zl,disabled:!b||Ln===b,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.backToProjectRoot"),title:a("rightSidebar.backToProjectRoot"),children:e.jsx(qc,{size:14})}),e.jsx("button",{type:"button",onClick:wf,disabled:!pe,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.refreshFiles"),title:cl?a("rightSidebar.fileWatchUnavailable",{message:cl}):a("rightSidebar.refreshFiles"),children:e.jsx(xi,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:pe??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:xf}),ea==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:a("fileTree.sortedByModified"),"aria-label":a("fileTree.sortedByModified"),children:e.jsx(Wc,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>pe&&zr(pe,Lt??void 0),disabled:!pe,...pe&&Lt?$o(ca(pe),Lt):{},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 ${Lt&&(q===Lt||Ce===Lt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":a(Lt&&Ce===Lt?"rightSidebar.copied":Lt&&q===Lt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:a("rightSidebar.insertCurrentFolder"),children:Lt&&(q===Lt||Ce===Lt)?e.jsx(gi,{size:13}):e.jsx(Wa,{size:13})}),e.jsxs("div",{ref:yn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Pt(!1),zt(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${hr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":hr,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(bi,{size:14})}),hr&&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:()=>{zt(!1),kf()},disabled:!Ao,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${us?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[us?e.jsx(Xo,{size:14}):e.jsx(Ea,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(us?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{zt(!1),ff()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${xo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[xo?e.jsx(hm,{size:14}):e.jsx(wi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(xo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!pe,onClick:()=>{pe&&(zt(!1),hf(pe,ea==="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:[ea==="modified"?e.jsx(Zh,{size:14}):e.jsx(Wc,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(ea==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),b&&(ua.length>0||vf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:zl,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-full px-2 py-0.5 font-medium transition active:scale-95 ${pe===b?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:b,children:[e.jsx(qc,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Ve})]}),ua.map(r=>{const i=r.path,u=r.kind==="file",x=u?Ye===i:pe===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-full transition ${x?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>u?cs(i):It(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[u?e.jsx(ki,{size:10,className:"shrink-0"}):e.jsx(Ea,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:mt(i)})]}),e.jsx("button",{type:"button",onClick:()=>ln(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.unpinFolder",{name:mt(i)}),title:a("rightSidebar.unpinFolder",{name:mt(i)}),children:e.jsx(Ut,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Vo=o.useMemo(()=>{if($n===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((ho-$n)/1e3)),u=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[x,v]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return u.format(x,v)},[ho,$n]),Pc=b&&!ls?e.jsx("button",{type:"button",onClick:()=>{Jf(!vo)},"aria-pressed":vo,title:a("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${vo?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:a("rightSidebar.multiRepoScan")}):null,Tc=b?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Vo?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:a("rightSidebar.gitLastUpdated",{time:Vo}),children:Vo}):null,e.jsx("button",{type:"button",onClick:()=>{os()},disabled:$t,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":a("rightSidebar.refreshGit"),title:a("rightSidebar.refreshGit"),children:e.jsx(xi,{size:13,className:$t?"animate-spin":""})})]}):null,oh=El?a("rightSidebar.changeAuditScopeAll"):un.length===1?un[0].relativeRoot==="."?Ve:un[0].relativeRoot||un[0].name:`${un.length} repos`,Ic=b?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(kd,{open:_s,onOpenChange:Tr,showScopePicker:gn,selectedAll:El,repos:mf,selectedRoots:qt,onToggleRepo:Df,onGenerate:()=>If(),disabled:!b,inserted:q===Hl,buttonLabel:a("rightSidebar.changeAuditShort"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:a("rightSidebar.insertChangeAuditPrompt"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:oh,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a("rightSidebar.changeAuditShort"),loading:Lr,error:!!Pr,statusTitle:Pr??(Lr?a("rightSidebar.changeAuditLoading"):jt.length>0?`${a("rightSidebar.changeAuditLoaded",{count:jt.length})}${$c?` · ${a("rightSidebar.changeAuditLoadedAt",{time:$c})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{Ff()},disabled:Lr||jt.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 ${jt.length>0?"":"invisible"}`,title:a("rightSidebar.clearChangeAuditTitle"),"aria-label":a("rightSidebar.clearChangeAudit"),children:e.jsx(Oa,{size:12})})]}):null,Ca=ve.size>0||se?.available||Dr?e.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] font-medium",children:[se?.available&&se.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:se.branch,children:[e.jsx(Mr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:se.branch})]}),st.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[st.modified,"M"]}),st.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",st.added]}),st.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",st.deleted]}),st.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[st.renamed,"R"]}),st.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[st.copied,"C"]}),st.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[st.untracked,"U"]}),st.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[st.conflicted,"!"]}),st.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[st.other,"?"]}),st.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:a("rightSidebar.stagedCountShort",{count:st.staged})}),se?.available&&b&&ve.size>0&&V.length<=1&&e.jsx("button",{type:"button",onClick:()=>{it({action:"stage-all",cwd:b},a("rightSidebar.stageAll"))},disabled:!!Pe,className:"rounded-full bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),se?.available&&b&&ve.size>0&&V.length<=1&&e.jsx("button",{type:"button",onClick:()=>_r({kind:"stash-all",repoRoot:b,repoLabel:Ve}),disabled:!!Pe,className:"rounded-full bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}):null;return e.jsxs(em,{side:"right",isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:d,pinned:c,children:[$o.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:b??void 0,children:Ve}),(!ee||uo)&&se?.available&&se.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:se.branch,children:[e.jsx(Mr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:se.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!ae;fe(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):j("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ae?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleSearch"),title:a("common.search"),children:e.jsx(qn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Qe,onClick:()=>{xn(r=>!r),ur(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Qe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleContextDraft"),title:a("rightSidebar.contextDraftTitle"),children:[e.jsx(jm,{size:14}),!Qe&&wt.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:hl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const i=r.target.files;!i||i.length===0||(ds(Array.from(i)),r.target.value="")}}),e.jsx("input",{ref:ml,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const i=r.target.files?.[0];r.target.value="",i&&bf(i)}}),h&&e.jsx("button",{type:"button",onClick:h,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${c?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:c?e.jsx(Xo,{size:14}):e.jsx(Ea,{size:14})}),e.jsxs("div",{ref:Ts,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{zt(!1),Pt(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${Xt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":Xt,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(bi,{size:15})}),Xt&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),hl.current?.click()},disabled:Vs,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:[Vs?e.jsx(at,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Pm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),ml.current?.click()},disabled:Vs,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:[Vs?e.jsx(at,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(xm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.insertLocalImage")})]}),h&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Pt(!1),h()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${c?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[c?e.jsx(Xo,{size:14}):e.jsx(Ea,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),c&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":a("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:a("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",a("rightSidebar.layoutModeAuto")],["narrow",a("rightSidebar.layoutModeNarrow")],["wide",a("rightSidebar.layoutModeWide")]].map(([r,i])=>{const u=G===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":u,onClick:()=>{J(r),Pt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},r)})})]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":a("rightSidebar.close"),children:e.jsx(Ut,{size:14})})]}),ae&&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:O,onChange:r=>j(r.target.value),placeholder:a(M==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Sc("name"),"aria-pressed":M==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${M==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Sc("content"),"aria-pressed":M==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${M==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeContent")})]}),O&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Ut,{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(tm,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:K,onChange:r=>re(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchScopePlaceholder"),"aria-label":a("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),K!=="."&&e.jsx("button",{type:"button",onClick:()=>re("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.resetSearchScope"),children:e.jsx(Ut,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>Re(r=>!r),"aria-expanded":me,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${me||ss.length>0||C||de||We?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:a("rightSidebar.searchOptions"),"aria-label":a("rightSidebar.searchOptions"),children:[e.jsx(rm,{size:13}),ss.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:ss.length})]})]}),me&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:oe,onChange:r=>he(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchExcludePlaceholder"),"aria-label":a("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),oe&&e.jsx("button",{type:"button",onClick:()=>he(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.clearSearchExclude"),children:e.jsx(Ut,{size:11})})]}),M==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":a("rightSidebar.contentSearchOptions"),children:[[C,()=>Z(r=>!r),um,a("rightSidebar.matchCase")],[de,()=>Le(r=>!r),Im,a("rightSidebar.matchWholeWord")],[We,()=>_e(r=>!r),Cm,a("rightSidebar.useRegex")]].map(([r,i,u,x])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(u,{size:12}),x]},x))})]})]}),ls?null:e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>on("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Rr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Mr,{size:12}),a("rightSidebar.tabGit"),$t&&Rr==="git"?e.jsx(at,{size:12,className:"animate-spin text-muted-foreground"}):null]}),e.jsxs("button",{type:"button",onClick:()=>on("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Rr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(zd,{size:12}),a("rightSidebar.tabChanges"),$t?e.jsx(at,{size:12,className:"animate-spin text-muted-foreground"}):ve.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:ve.size}):null]}),e.jsxs("button",{type:"button",onClick:()=>on("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Rr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(am,{size:12}),a("rightSidebar.tabFiles")]})]}),e.jsx("div",{className:"h-2"}),ol&&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:ol})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(li,{active:Ke,mounted:or,fallback:e.jsx(vs,{slow:!1}),children:Ue?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Xc,{items:Of,selectedKey:nf,onSelect:Ds,emptyText:a("rightSidebar.noChanges"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a("rightSidebar.recentCommitsTitle"),headerMeta:`${Ue.headRef??""}${Ue.commits?.[0]?` · ${Ue.commits[0]}`:""}`,onClose:()=>{$e(null),Ds(null)},closeLabel:a("common.back"),wrap:Mt,onToggleWrap:ee?ka:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Wr,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onClearAuditRecord:xa})}):xr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Xc,{items:Bo,selectedKey:lo,onSelect:rn,emptyText:a(Me?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a(Me?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:va?`${va.repoLabel} · ${va.branchName??"HEAD"} → ${va.baseRef}`:void 0,onClose:()=>{Qt(!1),Zt(null)},closeLabel:a("common.back"),wrap:Mt,onToggleWrap:ee?ka:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Wr,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onClearAuditRecord:xa,walkthroughs:Uf,onWalkthroughNavigate:Hf,initialDetailScrollTop:Me&&Ze?Sn[Ze]:void 0,onDetailScrollPositionChange:Yf,externalSwiperRef:ee?aa:void 0,onMobileSlideChange:ee?co:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain px-2 py-2",children:Ec||($t?e.jsx(vs,{slow:Zs}):Pn?e.jsx(Da,{message:Pn,onRetry:()=>{os()}}):Md(se)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(b?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):se?.available===!1?e.jsx(Da,{message:se.error??a("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{os()}}):b?e.jsx(vs,{slow:Zs}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(b?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}))})}),e.jsx(li,{active:Dn,children:ee?e.jsxs(Id,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{jr.current=r,r.slideTo(sl,0)},onSlideChange:r=>{if(kr(r.activeIndex),as.current===r.activeIndex){as.current=null;return}r.activeIndex===0&&(wr(!1),kt(null),f?.())},children:[e.jsx(vi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Tn,onScroll:Al,onDragOver:ia,onDragEnter:ia,onDragLeave:Il,onDrop:Fl,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:a("rightSidebar.dropToUpload")})}),!O.trim()&&Ac,e.jsx(Gc,{rootPath:pe??"",onFileSelect:cs,onPathReference:zr,getReferenceText:ca,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onDirectoryRoot:Wl,onSearchFromDirectory:Gl,onDirectoryPinToggle:ql,onFilePinToggle:Kl,pinnedPaths:hn,selectedFilePath:Ye,query:le,searchRootPath:Cl,searchOptions:Nl,searchMode:M,onContentMatchSelect:Pl,onDirectoryDropFiles:(r,i)=>ds(i,r),revealDirectory:Y,canOpenInFileBrowser:ul,onOpenInFileBrowser:Tl})]})}),e.jsx(vi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Bi,{filePath:Dn&&(sf||sl===1)?Ye:null,onInsertReference:zr,onInsertText:Nr,onInsertFeature:Nr,onReviewReference:Ol,onReferenceCopied:Cr,onClose:ah,onDirectoryLinkOpen:Lc,isMobile:!0,lineRange:Kr,onLineRangeChange:kt,insertedReferenceKey:q,copiedReferenceKey:Ce,scrollToLine:$r,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Tn,onScroll:Al,onDragOver:ia,onDragEnter:ia,onDragLeave:Il,onDrop:Fl,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:po},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:a("rightSidebar.dropToUpload")})}),!O.trim()&&Ac,e.jsx(Gc,{rootPath:pe??"",onFileSelect:cs,onPathReference:zr,getReferenceText:ca,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onDirectoryRoot:Wl,onSearchFromDirectory:Gl,onDirectoryPinToggle:ql,onFilePinToggle:Kl,pinnedPaths:hn,selectedFilePath:Ye,query:le,searchRootPath:Cl,searchOptions:Nl,searchMode:M,onContentMatchSelect:Pl,onDirectoryDropFiles:(r,i)=>ds(i,r),revealDirectory:Y,canOpenInFileBrowser:ul,onOpenInFileBrowser:Tl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":a("rightSidebar.resizeFileTree"),title:a("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:pf,onPointerMove:gf,onPointerUp:Ll,onPointerCancel:Ll,onDoubleClick:()=>{go(Ni),vt(ws,Ni)},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(Bi,{filePath:Dn?Ye:null,onInsertReference:zr,onInsertText:Nr,onInsertFeature:Nr,onReviewReference:Ol,onReferenceCopied:Cr,onDirectoryLinkOpen:Lc,isMobile:!1,lineRange:Kr,onLineRangeChange:kt,insertedReferenceKey:q,copiedReferenceKey:Ce,scrollToLine:$r,onScrollToLineHandled:()=>Te(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F})})]})}),e.jsx(li,{active:ft,mounted:af||ft,children:()=>ee?e.jsx(yi,{mobile:!0,backLabel:a("rightSidebar.backToChangeList"),externalSwiperRef:aa,onMobileSlideChange:co,groups:Ot.length>0?uc():[],mode:St,onModeChange:wa,selectedKey:Ye,scrollToKey:pc,scrollToKeyNonce:Xs.nonce,compact:!1,collapsedDirectoryKeys:mr,onToggleDirectory:xc,onSelectFile:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);i&&ya(ht(i))},renderLeading:hc,renderTrailing:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);return i?cc(i):null},renderDirectoryTrailing:dc,renderSubtitle:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);return i?ic(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>b&&e.jsxs("div",{className:"px-0 py-0",children:[Ca&&e.jsx("div",{className:"mb-2",children:Ca}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Ot.length,"/",ve.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ac(),Pc,r,c&&_o(),Ic,Tc]}),Ct&&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:Ct.label}),Ct.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:Ct.branch})]}),!Ct&&gn&&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(Mr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:ha?(r=>bc(r)):void 0,emptyContent:$t&&ve.size===0&&Dr===null?e.jsx(vs,{slow:Zs}):Pn&&ve.size===0?e.jsx(Da,{message:Pn,onRetry:()=>{os()}}):ve.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):Ot.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>is(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.backToChangeList"),children:[e.jsx(Ns,{size:14}),a("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[c&&_o(),e.jsxs("button",{type:"button",onClick:ka,"aria-pressed":Mt,title:a("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Mt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a(Mt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:fc(),activePane:ft,wrap:Mt,diffViewType:uf,inlineMode:Yn,diffOptions:kc,reloadKey:pr,renderStreamBadge:r=>e.jsx(js,{status:r}),onHunkGitAction:jc,onInsertDiffReference:Wr,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onClearAuditRecord:xa,onDetailScroll:ga}):e.jsx(yi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:a("rightSidebar.backToChangeList"),groups:Ot.length>0?uc():[],mode:St,onModeChange:wa,selectedKey:Ye,scrollToKey:pc,scrollToKeyNonce:Xs.nonce,compact:!0,collapsedDirectoryKeys:mr,onToggleDirectory:xc,onSelectFile:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);i&&ya(ht(i))},renderLeading:hc,renderTrailing:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);return i?cc(i):null},renderDirectoryTrailing:dc,renderSubtitle:r=>{const i=Array.from(ve.values()).find(u=>ht(u)===r.key);return i?ic(i):null},aiContent:ha?(r=>bc(r)):void 0,emptyContent:$t&&ve.size===0&&Dr===null?e.jsx(vs,{slow:Zs}):Pn&&ve.size===0?e.jsx(Da,{message:Pn,onRetry:()=>{os()}}):ve.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):Ot.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>b&&e.jsxs("div",{className:"px-0 py-0",children:[Ca&&e.jsx("div",{className:"mb-2",children:Ca}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Ot.length,"/",ve.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ac(),Pc,r,_o(),e.jsxs("button",{type:"button",onClick:ka,"aria-pressed":Mt,title:a("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 ${Mt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a(Mt?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Ic,Tc]}),Ct&&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:Ct.label}),Ct.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:Ct.branch}),e.jsx("button",{type:"button",onClick:()=>ja("stage-all",Ct.root,Ct.label),disabled:!!Pe,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>ja("stash-all",Ct.root,Ct.label),disabled:!!Pe,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}),!Ct&&gn&&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(Mr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),files:fc(),activePane:ft,wrap:Mt,diffViewType:Jt,inlineMode:Yn,diffOptions:kc,reloadKey:pr,renderStreamBadge:r=>e.jsx(js,{status:r}),onHunkGitAction:jc,onInsertDiffReference:Wr,onReferenceCopied:Cr,insertedReferenceKey:q,copiedReferenceKey:Ce,onClearAuditRecord:xa,onDetailScroll:ga})})]}),t&&Qe&&e.jsx(ap,{value:wt,collapsed:gt,autoCollapseAfterSend:Yt,focusRequest:qr,insertError:Vn?a("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{Wt(!1),Ht(r)},onCollapsedChange:ur,onAutoCollapseAfterSendChange:vn,onDisable:()=>xn(!1),onClear:()=>Ht(""),onInsert:()=>Ul(!1),onInsertAndSend:()=>Ul(!0),labels:{title:a("rightSidebar.contextDraftTitle"),hint:a("rightSidebar.contextDraftHint"),placeholder:a("rightSidebar.contextDraftPlaceholder"),collapse:a("rightSidebar.contextDraftCollapse"),expand:a("rightSidebar.contextDraftExpand"),disable:a("rightSidebar.contextDraftDisable"),clear:a("rightSidebar.contextDraftClear"),insert:a("rightSidebar.contextDraftInsert"),insertAndSend:a("rightSidebar.contextDraftInsertAndSend"),inserted:a("rightSidebar.contextDraftInserted"),sent:a("rightSidebar.contextDraftSent"),send:a("rightSidebar.contextDraftSend"),appended:a("rightSidebar.contextDraftAppended"),resize:a("rightSidebar.contextDraftResize"),autoCollapseAfterSend:a("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>a("rightSidebar.contextDraftCharacterCount",{count:r})}}),Lf(),dt&&typeof document<"u"&&Gr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>_r(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:dt.kind==="restore"?a("rightSidebar.confirmRestoreTitle"):a("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:dt.kind==="restore"?a("rightSidebar.confirmRestoreDescription",{path:Ad(dt.file.absolutePath,b)}):a("rightSidebar.confirmStashAllDescription")}),dt.kind==="restore"&&e.jsx("input",{value:dt.phrase,onChange:r=>_r({...dt,phrase:r.target.value}),placeholder:a("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>_r(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:a("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Pe||dt.kind==="restore"&&dt.phrase.trim()!==a("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(dt.kind==="restore"){const r=lt(dt.file,b);if(!r)return;it({action:"restore-worktree-file",cwd:r,paths:[dt.file.path],confirm:{acknowledged:!0,phrase:dt.phrase}},a("rightSidebar.restoreFile"),fi(dt.file))}else{const r=dt.repoRoot??b;if(!r)return;it({action:"stash-all",cwd:r},a("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${dt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:a(Pe?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const Eb=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Bi,MarkdownImageLightbox:Wu,MarkdownPreview:Gu,RightSidebar:xb,__testParseMarkdownListBlock:Ig,buildMarkdownPreviewBlocks:qg,buildMarkdownPreviewRenderResult:Xi,collectKnownGitRepoRoots:pu,computeMarkdownImageDisplayBox:Nu,getMarkdownHeadingOutline:zu,getMarkdownHeadingPathAtLine:Hu,getNextMarkdownPreviewLineRange:Qg,isSvgImageSrc:eo,mountRightSidebarRepoPickerOverlay:eu,replaceGitRepositorySnapshot:Ju,resolveMarkdownLocalLinkTarget:Wi,resolveRightSidebarDiffViewType:fu,shouldCloseMarkdownImageLightboxDrag:Bu,showsGitRepoGroupHeader:Mi},Symbol.toStringTag,{value:"Module"}));export{wi as E,qc as H,ym as M,Eb as R,hm as a,km as b,Fm as c,$b as m};
1674
+ `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${b??""}`,`包含本地未提交更改:${Ir?"是":"否"}`,"目标仓库:",u,"","操作指令:",Ir?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",x,"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:b??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
+ `)},[Ir,Kt,Rt,vr,b]),Gf=o.useCallback((r="generate")=>{const i=r==="generate"?Uo:[r==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",Uo].join(`
1676
+ `);Wr(a("rightSidebar.branchAuditShort"),i,`context:branch-audit-scope:${r}`),d||s()},[Uo,Wr,s,d,a]),qf=o.useCallback(async()=>{if(!b||Kt.length===0)return;const r=b;z(!0),xe(null),Zt(null),$e(null);try{const i=await Promise.all(Kt.map(async H=>{const Y=Rt[H.root]?.trim();if(!Y)throw new Error(a("rightSidebar.branchAuditMissingBase",{repo:H.label}));const Ce=(vr[H.root]||H.branch||"").trim();return Ih({cwd:b,repoRoot:H.root,base:Y,head:Ce&&Ce!==H.branch?Ce:null,includeUncommitted:Ir,requestSlotId:`right-sidebar-branch-preview:${H.root}`})}));if(!ke(r))return;const u=i.find(H=>!H.available);if(u){xe(u.error??"Branch diff is unavailable");return}const x=i.length===1?i[0]:{available:!0,workspaceRoot:b,repoRoot:b,baseRef:i.map(H=>H.baseRef??H.baseBranch).filter(Boolean).join(", "),currentBranch:i.map(H=>H.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:i.map(H=>H.headRef).filter(Boolean).join(", "),diffFingerprint:i.map(H=>H.diffFingerprint).filter(Boolean).join("+"),stat:i.map(H=>H.stat).filter(Boolean).join(`
1677
+ `),files:i.flatMap((H,Y)=>{const Ce=Kt[Y];return(H.files??[]).map(He=>`${Ce?.label??H.repoRoot??"repo"}/${He}`)}),hunks:i.flatMap((H,Y)=>{const He=Kt[Y]?.label??H.repoRoot??"repo";return(H.hunks??[]).map(Pe=>({...Pe,filePath:`${He}/${Pe.filePath}`,oldPath:Pe.oldPath?`${He}/${Pe.oldPath}`:Pe.oldPath,newPath:Pe.newPath?`${He}/${Pe.newPath}`:Pe.newPath}))}),commits:i.flatMap(H=>H.commits??[]),commitCount:i.reduce((H,Y)=>H+(Y.commitCount??Y.commits?.length??0),0),diff:i.map(H=>H.diff).filter(Boolean).join(`
1678
+ `),truncated:i.some(H=>H.truncated)};if((x.hunks??[]).length===0){xe(a("rightSidebar.branchAuditDiffEmpty"));return}const v=Date.now(),R=["preview",x.repoRoot??b,x.baseRef??x.baseBranch??"",x.currentBranch??"",x.headRef??"",x.diffFingerprint??v].join("\0"),T=Kt.length===1?Kt[0].label:`${Kt.length} repos`;Zt(x),es(H=>[{key:R,diff:x,repoLabel:T,createdAt:v},...H.filter(Y=>Y.key!==R)].slice(0,8)),Rn(H=>H[R]===void 0?H:{...H,[R]:0}),tn(R),rn(x.hunks?.[0]?`${x.hunks[0].filePath}\0${x.hunks[0].hunkHeader}\0${x.hunks[0].hunkIndex}`:null),Qt(!0)}catch(i){if(!ke(r)||Nr(i))return;xe(i instanceof Error?i.message:"Failed to load branch diff")}finally{ke(r)&&z(!1)}},[Ir,Kt,Rt,vr,ke,b,a]),Kf=o.useCallback(r=>{Zt(r.diff),xe(null),tn(r.key),rn(r.diff.hunks?.[0]?`${r.diff.hunks[0].filePath}\0${r.diff.hunks[0].hunkHeader}\0${r.diff.hunks[0].hunkIndex}`:null),Qt(!0)},[]),Vf=o.useCallback(r=>{es(i=>i.filter(u=>u.key!==r)),Rn(i=>{if(!(r in i))return i;const u={...i};return delete u[r],u}),Ze===r&&(tn(null),Zt(null),Qt(!1))},[Ze]),Yf=o.useCallback(r=>{const i=zn.find(u=>u.key===r);i&&(Zt(null),xe(null),tn(r),rn(i.records[0]?.filePath??null),Qt(!0))},[zn]),Xf=o.useCallback(async r=>{if(!b||!ve)return;const[i]=r.split(/\s+/);if(i){_e(i),at(null),$e(null);try{const u=await Fh({cwd:b,repoRoot:ve,commit:i,requestSlotId:"right-sidebar-commit-diff"});if(!u.available){at(u.error??"Commit diff is unavailable");return}$e(u);const x=u.hunks?.[0];Ds(x?`${x.filePath}\0${x.hunkHeader}\0${x.hunkIndex}`:null)}catch(u){at(u instanceof Error?u.message:"Failed to load commit diff")}finally{_e(null)}}},[ve,b]),Jf=o.useCallback(r=>{if(!Me||!Ze)return;const i=Math.max(0,Math.round(r));Rn(u=>Math.abs((u[Ze]??0)-i)<24?u:{...u,[Ze]:i})},[Me,Ze]);o.useEffect(()=>{!ee||!br||!Me||ls(1)},[br,Me,ee,ls]);const gc=o.useCallback(r=>{r&&ff(i=>fm(i,r))},[]),bc=Ys.key===Ve?Ys.key:null,xa=o.useCallback(r=>{const i=te.getState(),u=yb();Da("select_diff_file",{interactionId:u,path:r,previousSelectedFilePath:i.selectedFilePath,rootPath:i.rootPath,activeGitRepoRoot:ce,changedFiles:i.changedFiles.size,gitBundleLoading:i.gitBundleLoading,gitBundleLastLoadedAt:i.gitBundleLastLoadedAt,rightTab:i.rightTab}),Ye(r),on("diff"),ee&&r&&ls(1),gc(r),queueMicrotask(()=>{const x=te.getState();Da("select_diff_file_after",{interactionId:u,requestedPath:r,selectedFilePath:x.selectedFilePath,rootPath:x.rootPath,rightTab:x.rightTab,changedFiles:x.changedFiles.size,activeGitRepoRoot:ce})})},[ce,ee,gc,Ye,on,ls]),xc=o.useCallback(r=>{const i=Array.from(we.values()).find(u=>{const x=it(u,b),v=ut(u);return u.path===r.filePath||v===r.filePath||u.absolutePath===r.filePath||(x?`${x}/${u.path}`===r.filePath:!1)||r.repoRoot&&x===r.repoRoot&&u.path===r.filePath});if(i){xa(ut(i)),window.setTimeout(()=>xn(r),90),window.setTimeout(()=>xn(r),320),window.setTimeout(()=>xn(r),760);return}xn(r)},[we,b,xa]),vc=o.useCallback(({slideToDetail:r,fullscreen:i,toggleFullscreen:u}={})=>Qn.length>0?e.jsx(Bd,{walkthroughs:Qn,repoRoot:ce,fullscreen:i,onToggleFullscreen:u,onNavigate:x=>{ee&&window.requestAnimationFrame(()=>r?.()),xc(x)}}):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($s,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),a("rightSidebar.changeWalkthroughEmpty")]}),[ce,Qn,xc,ee,a]),Qf=o.useCallback(r=>{r&&$r(i=>{const u=new Set(i);return u.has(r)?u.delete(r):u.add(r),ni(Qo,u),u})},[]),yc=o.useCallback(r=>{eo(i=>{const u=new Set(i);return u.has(r)?u.delete(r):u.add(r),ni(ad,u),u})},[]),va=o.useCallback(r=>{Ts(r),xt(su,r)},[]);o.useEffect(()=>{ua||St!=="ai"||va("tree")},[St,va,ua]);const ya=o.useCallback(()=>{Is(r=>{const i=!r;return xt(au,i),i})},[]),wc=o.useCallback(r=>{Vr(r),xt(ou,r)},[]),{whitespace:kc,context:Sc}=mm(),jc=o.useMemo(()=>({algorithm:"histogram",whitespace:kc,context:Sc}),[kc,Sc]),Rc=o.useCallback(r=>{_(r),xt(iu,r)},[]),wa=o.useCallback(async(r,i,u,x)=>{let v=r;for(;v.ok&&v.status==="running";)await new Promise(T=>window.setTimeout(T,1500)),v=await zc({jobId:v.jobId,cwd:i.cwd,action:i.action});if(!v.ok)throw new Error("Git action status is unavailable");if(v.status==="error")throw new Error(v.error||v.message||"Git action failed");const R={action:i.action,path:x,label:u};return ss(R),window.setTimeout(()=>ss(T=>T?.action===R.action&&T.path===R.path?null:T),1400),v},[]),ot=o.useCallback(async(r,i,u)=>{const x=b;b&&ir.current.delete(b),dt(null),ss(null),ns({action:r.action,path:u});try{const v=await Dh({...r,includeNested:Gn(b)}),R=await wa(v,r,i,u);if(!ke(x))return!1;const T=b?await Ra(b,void 0,{includeNested:Gn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Kn(b)}).catch(()=>R.bundle):R.bundle;return ke(x)?(T&&Ur(T,{reloadDiff:!0,cacheOnly:!0}),Fr(null),!0):!1}catch(v){return ss(null),dt(a("rightSidebar.gitActionFailed",{message:v instanceof Error?v.message:"Unknown error"})),!1}finally{ke(x)&&ns(null)}},[Ur,ke,b,a,wa]),Cc=o.useCallback(async r=>{const i=b,u=await _h({...r,includeNested:Gn(b)});if(!ke(i))return;const x=b?await Ra(b,void 0,{includeNested:Gn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Kn(b)}).catch(()=>u.bundle):u.bundle;ke(i)&&x&&Ur(x,{reloadDiff:!0,cacheOnly:!0})},[Ur,ke,b]),ka=o.useCallback((r,i,u)=>{if(i){if(r==="stage-all"){ot({action:"stage-all",cwd:i},a("rightSidebar.stageAll"),`repo:${i}`);return}Fr({kind:"stash-all",repoRoot:i,repoLabel:u})}},[ot,a]),Nc=o.useCallback(r=>{Je(r),ri(b,r),Ws(""),Gs(""),qs(""),Ye(Zl(r)),Xe||on("diff"),r&&r!==b&&V.find(u=>u.root===r)?.deferred&&qt(r,{includeNested:!1,background:!0,replaceRepoRoot:r})},[Zl,Xe,V,qt,b,Ye,on]),Mc=o.useCallback(r=>{const i=new Set([...Ft.current.keys(),...dn.current,...ir.current]);for(const u of i)u!==r&&(It.current.delete(u),Ft.current.get(u)?.abort(),Ft.current.delete(u),bt(`right-sidebar-git-untracked:${u}`),dn.current.delete(u),ir.current.delete(u))},[]),Zf=o.useCallback(async r=>{const i=b;if(!i||(await te.getState().setNestedGitScanRoot(i,r),!ke(i)))return;if(r){await qt(i,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Mc(i),Ws(""),Gs(""),qs(""),ao(x=>x.filter(v=>v===i));const u=Dt;u&&it(u,i)!==i&&Ye(null),await qt(i,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Mc,ke,qt,b,Ye,Dt]),eh=o.useCallback(async()=>{if(!ve||We){dt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=Ln.trim();!r||r===ue?.branch||await ot({action:"switch-branch",cwd:ve,branch:r},a("rightSidebar.switchBranch"))},[ue?.branch,ve,We,ot,Ln,a]),$c=o.useCallback(async()=>{if(!ve||We){dt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=zs.trim();if(!r)return;await ot({action:"commit",cwd:ve,message:r},a("rightSidebar.commitChanges"))&&ll("")},[ve,zs,We,ot,a]),th=o.useCallback(async()=>{if(!ve||We){dt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=sn.trim(),i=an.trim();await ot({action:"push",cwd:ve,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pushChanges"))},[ve,an,sn,We,ot,a]),rh=o.useCallback(async()=>{if(!ve||We){dt(a("rightSidebar.selectRepositoryForGitActions"));return}const r=sn.trim(),i=an.trim();await ot({action:"pull",cwd:ve,...r?{remote:r}:{},...i?{branch:i}:{}},a("rightSidebar.pullChanges"))},[ve,an,sn,We,ot,a]);o.useEffect(()=>{if(!Xe||!ve||Ae)return;let r=!1;const i={push:a("rightSidebar.pushChanges"),pull:a("rightSidebar.pullChanges"),commit:a("rightSidebar.commitChanges"),"switch-branch":a("rightSidebar.switchBranch"),"stage-all":a("rightSidebar.stageAll"),"stash-all":a("rightSidebar.stashAll")};return(async()=>{for(const u of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(r)return;const x=await zc({cwd:ve,action:u}).catch(()=>null);if(!x?.ok||x.status!=="running")continue;const v={action:u,cwd:ve},R=i[u]??u;ns({action:u});try{const T=await wa(x,v,R);if(r||!ke(b))return;const H=b?await Ra(b,void 0,{includeNested:Gn(b),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Kn(b)}).catch(()=>T.bundle):T.bundle;H&&Ur(H,{reloadDiff:!0,cacheOnly:!0})}catch(T){r||dt(a("rightSidebar.gitActionFailed",{message:T instanceof Error?T.message:"Unknown error"}))}finally{r||ns(null)}return}})(),()=>{r=!0}},[ve,Ur,Xe,ke,b,Ae,a,wa]);const Ho=$n?.action==="commit",zo=$n?.action==="switch-branch",Wo=$n?.action==="pull",Go=$n?.action==="push",Sa=Xe||df,qo=ha?a("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,nh=cr.length>0,Ec=Kt.length>0,sh=b?e.jsx(jd,{open:no,onOpenChange:so,showScopePicker:!0,selectedAll:ha,repos:_t,selectedRoots:fa,onToggleRepo:Uf,onGenerate:()=>Gf(Bo?"regenerate":"generate"),disabled:!nh,generateDisabled:!Ec,inserted:q?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:a(Bo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.branchAuditGenerateTitle"),ariaLabel:a("rightSidebar.branchAuditShort"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:qo,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a(Bo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{qf()},secondaryDisabled:!Ec||P,secondaryLabel:a("rightSidebar.branchAuditViewDiff"),secondaryTitle:a("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:P,loading:rl.size>0,statusTitle:rl.size>0?a("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:a("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:a("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Ir,onChange:r=>tl(r.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),sc.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:a("rightSidebar.missingBaseReposSkipped",{repositories:sc.map(r=>r.label).join(w==="zh"?"、":", ")})})]}),renderRepoExtra:r=>{const i=gt.get(r.root),u=[],x=new Set,v=(Y,Ce)=>{!Y||x.has(Y)||(x.add(Y),u.push({value:Y,label:Y,meta:Ce}))};v(vr[r.root]||i?.context?.branch,a("rightSidebar.pushCurrentBranchBadge"));for(const Y of i?.context?.branches??[])v(Y,Y===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):a("rightSidebar.localBranch"));for(const Y of i?.context?.remoteBranches??[])v(Y,a("rightSidebar.remoteBranch"));const R=[],T=new Set,H=(Y,Ce)=>{!Y||T.has(Y)||(T.add(Y),R.push({value:Y,label:Y,meta:Ce}))};H(Rt[r.root],Rt[r.root]?a("rightSidebar.pushUpstreamBadge"):void 0),H(i?.context?.upstream,i?.context?.upstream?a("rightSidebar.pushUpstreamBadge"):void 0);for(const Y of i?.context?.remoteBranches??[])H(Y,"remote");for(const Y of i?.context?.branches??[])H(Y,Y===i?.context?.branch?a("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(qn,{label:a("rightSidebar.currentBranchLabel"),value:vr[r.root]||i?.context?.branch||"",options:u,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),onChange:Y=>{Bs(Ce=>({...Ce,[r.root]:Y}))}}),e.jsx(qn,{label:a("rightSidebar.branchAuditBaseLabel"),value:Rt[r.root]||"",options:R,placeholder:a("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:a("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:a("rightSidebar.branchAuditBaseEmpty"),onChange:Y=>{Os(Ce=>({...Ce,[r.root]:Y}))}})]})}}):null,Lc=vs(jt.reduce((r,i)=>Math.max(r,i.injectedAt??0),0),w),ah=b?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>el(r=>{const i=!r;return xt(Zo,i),i}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":rs,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($s,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:qo})]}),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 ${rs?"rotate-90":""}`,children:e.jsx(Ca,{size:13})})]}),rs&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[a("rightSidebar.changeAuditScopeLabel"),": ",qo]}),sh]}),ie&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:ie}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[Qr.map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Kf(r),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diff.baseRef??r.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:a("rightSidebar.branchAuditViewDiff")})]}),vs(r.createdAt,w)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:vs(r.createdAt,w)})]}),e.jsx("button",{type:"button",onClick:()=>Vf(r.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("common.delete"),"aria-label":a("common.delete"),children:e.jsx(_a,{size:12})})]},r.key)),zn.length>0?zn.slice(0,Math.max(0,8-Qr.length)).map(r=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${Ze===r.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>Yf(r.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:r.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[r.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.baseRef}),r.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:r.diffFingerprint})]}),vs(r.latestInjectedAt,w)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:a("rightSidebar.branchAuditGeneratedAt",{time:vs(r.latestInjectedAt,w)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{Bf(r)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:a("rightSidebar.branchAuditClearTitle"),"aria-label":a("rightSidebar.branchAuditClearTitle"),children:e.jsx(_a,{size:12})})]},r.key)):Qr.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Ac=or&&b&&Hn?e.jsxs("div",{className:Sa?"overflow-visible":"overflow-hidden",children:[ah,e.jsxs("button",{type:"button",onClick:()=>{Xe||uf(r=>{const i=!r;return i&&ve&&!Hn&&!nn&&jo(ve),i})},"aria-expanded":Sa,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${Xe?"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(Cr,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:a("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${gn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[nn&&e.jsx(vt,{size:10,className:"animate-spin"}),gn.staged>0?a("rightSidebar.stagedCount",{count:gn.staged}):a("rightSidebar.noStagedChangesShort")]}),!Xe&&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 ${Sa?"rotate-90":""}`,children:e.jsx(Ca,{size:13})})]})]}),Sa&&e.jsxs("div",{className:"space-y-0",children:[Lt.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:a("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Cf})]})}),e.jsx(qn,{label:a("rightSidebar.gitRepositoryLabel"),value:ve??"",options:Lt,placeholder:a("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:a("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:a("rightSidebar.gitRepositoryEmpty"),disabled:!!Ae,onChange:r=>{Nc(r||null)}}),We&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:a("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/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:a("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Ln!==Ql?Ql:null})]}),e.jsxs("button",{type:"button",onClick:()=>{eh()},disabled:!Ff,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 ${zo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.switchBranch"),children:[e.jsx("span",{className:Ae?.action==="switch-branch"||zo?"opacity-0":"",children:a("rightSidebar.switchBranch")}),Ae?.action==="switch-branch"&&e.jsx(vt,{size:12,className:"absolute animate-spin"}),zo&&Ae?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(qn,{label:a("rightSidebar.currentBranchLabel"),value:Ln,options:$f,placeholder:a("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:a("rightSidebar.switchBranchSearchPlaceholder"),emptyText:a("rightSidebar.switchNoBranches"),disabled:!!Ae,onChange:Ws})]}),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:a("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:We?a("rightSidebar.selectRepositoryForGitActions"):gn.staged>0?a("rightSidebar.commitReadyHint",{count:gn.staged}):a("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{$c()},disabled:!!Ae||We||gn.staged===0||!zs.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 ${Ho?"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:We?a("rightSidebar.selectRepositoryForGitActions"):gn.staged===0?a("rightSidebar.commitNeedsStaged"):a("rightSidebar.commitChanges"),children:[e.jsx("span",{className:Ae?.action==="commit"||Ho?"opacity-0":"",children:a("rightSidebar.commitChanges")}),Ae?.action==="commit"&&e.jsx(vt,{size:12,className:"absolute animate-spin"}),Ho&&Ae?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:zs,onChange:r=>ll(r.target.value),onKeyDown:r=>{(r.metaKey||r.ctrlKey)&&r.key==="Enter"&&(r.preventDefault(),$c())},placeholder:a("rightSidebar.commitMessagePlaceholder"),disabled:!!Ae,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:()=>xr(r=>!r),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":er,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:a("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[Nn&&e.jsx(vt,{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 ${er?"rotate-90":""}`,children:e.jsx(Ca,{size:13})})]})]}),er&&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(Vn,{size:12,className:"shrink-0"}),e.jsx("input",{value:Cn,onChange:r=>Zr(r.target.value),placeholder:a("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),Cn&&e.jsx("button",{type:"button",onClick:()=>Zr(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Ot,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Nf,children:[tr.length>0?tr.map(r=>{const[i,...u]=r.split(/\s+/),x=u.join(" ")||r;return e.jsxs("button",{type:"button",onClick:()=>{Xf(r)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:x,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:x,children:x}),ze===i&&e.jsx(vt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},r)}):Nn?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:a("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:a("rightSidebar.recentCommitsEmpty")}),Q&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(vt,{size:12,className:"animate-spin"})}),ro&&!Q&&tr.length>0&&e.jsx("button",{type:"button",onClick:()=>{hs({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:a("rightSidebar.recentCommitsLoadMore")})]})]}),nt&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:nt}),nr&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:nr})]}),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:a("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{rh()},disabled:!Tf,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 ${Wo?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pullChanges"),children:[e.jsx("span",{className:Ae?.action==="pull"||Wo?"opacity-0":"",children:a("rightSidebar.pullChanges")}),Ae?.action==="pull"&&e.jsx(vt,{size:12,className:"absolute animate-spin"}),Wo&&Ae?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{th()},disabled:!If,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 ${Go?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:a("rightSidebar.pushChanges"),children:[e.jsx("span",{className:Ae?.action==="push"||Go?"opacity-0":"",children:a("rightSidebar.pushChanges")}),Ae?.action==="push"&&e.jsx(vt,{size:12,className:"absolute animate-spin"}),Go&&Ae?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${oc.className}`,title:ue?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:oc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:ue?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${nc?"grid-cols-2":"grid-cols-1"}`,children:[nc&&e.jsx(qn,{label:a("rightSidebar.pushRemoteLabel"),value:sn,options:rc,placeholder:a("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:a("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:a("rightSidebar.pushNoRemotes"),disabled:!!Ae,onChange:Gs}),e.jsx(qn,{label:a("rightSidebar.pushBranchLabel"),value:an,options:Ef,placeholder:a("rightSidebar.pushBranchPlaceholder",{branch:ue?.branch??"HEAD"}),searchPlaceholder:a("rightSidebar.pushBranchSearchPlaceholder"),emptyText:a("rightSidebar.pushNoBranches"),disabled:!!Ae,onChange:qs})]})]})]})]}):null,oh=o.useCallback(r=>{const i=it(r,b);if(!i)return[];const u=fi(r),x=[];return r.canStage&&x.push({key:"stage-file",label:a("rightSidebar.stageFile"),onClick:()=>{ot({action:"stage-file",cwd:i,paths:[r.path]},a("rightSidebar.stageFile"),u)}}),r.canUnstage&&x.push({key:"unstage-file",label:a("rightSidebar.unstageFile"),onClick:()=>{ot({action:"unstage-file",cwd:i,paths:[r.path]},a("rightSidebar.unstageFile"),u)}}),r.canStash&&x.push({key:"stash-file",label:a("rightSidebar.stashFile"),onClick:()=>{ot({action:"stash-file",cwd:i,paths:[r.path]},a("rightSidebar.stashFile"),u)}}),r.canRestoreWorktree&&x.push({key:"restore-worktree-file",label:a("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Fr({kind:"restore",file:r,phrase:""})}),x},[b,ot,a]),ih=o.useCallback(()=>{if(m){f?.();return}wr(0),Sr.current?.slideTo(0),yr(!1),kt(null)},[f,m]),Pc=o.useCallback(r=>{if(j(""),Tt(r),Ye(null),kt(null),ne(null),ee){m&&f?.(),wr(0),Sr.current?.slideTo(0),yr(!1);return}},[ee,f,m,Ye,Tt]);o.useEffect(()=>{const r=i=>{const u=i.detail,x=u?.path;if(typeof x!="string"||!x.startsWith("/"))return;j(""),kt(null),Ie(null);const v=!!(b&&(x===b||x.startsWith(`${b}/`)));if(u.kind==="file"){const R=ci(x);ds(x),typeof u.line=="number"&&Number.isSafeInteger(u.line)&&u.line>0&&Ie(u.line),Tt(v?null:R),ne(T=>({path:x,nonce:(T?.nonce??0)+1}));return}Ye(null),v?(Tt(null),ne(R=>({path:x,nonce:(R?.nonce??0)+1}))):(ne(null),Tt(x)),ee&&(m&&f?.(),wr(0),Sr.current?.slideTo(0),yr(!1))};return window.addEventListener(Gc,r),()=>window.removeEventListener(Gc,r)},[ds,ee,f,m,b,Ye,Tt]),o.useEffect(()=>{t||(At(!1),Ht(!1))},[t]),o.useEffect(()=>{if(!Xt&&!fr)return;const r=i=>{i instanceof globalThis.KeyboardEvent&&i.key!=="Escape"||i instanceof globalThis.MouseEvent&&i.target instanceof Node&&(Ps.current?.contains(i.target)||wn.current?.contains(i.target))||(At(!1),Ht(!1))};return window.addEventListener("mousedown",r),window.addEventListener("keydown",r),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("keydown",r)}},[fr,Xt]);const Tc=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:Sf,disabled:!la,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.parentFolder"),title:a("rightSidebar.parentFolder"),children:e.jsx(Id,{size:14})}),e.jsx("button",{type:"button",onClick:Wl,disabled:!b||Pn===b,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.backToProjectRoot"),title:a("rightSidebar.backToProjectRoot"),children:e.jsx(Vc,{size:14})}),e.jsx("button",{type:"button",onClick:jf,disabled:!pe,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":a("rightSidebar.refreshFiles"),title:cl?a("rightSidebar.fileWatchUnavailable",{message:cl}):a("rightSidebar.refreshFiles"),children:e.jsx(xi,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:pe??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:wf}),Zs==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:a("fileTree.sortedByModified"),"aria-label":a("fileTree.sortedByModified"),children:e.jsx(qc,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>pe&&zr(pe,Et??void 0),disabled:!pe,...pe&&Et?Mo(ia(pe),Et):{},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 ${Et&&(q===Et||Re===Et)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":a(Et&&Re===Et?"rightSidebar.copied":Et&&q===Et?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:a("rightSidebar.insertCurrentFolder"),children:Et&&(q===Et||Re===Et)?e.jsx(gi,{size:13}):e.jsx(Ha,{size:13})}),e.jsxs("div",{ref:wn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{At(!1),Ht(r=>!r)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${fr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":fr,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(bi,{size:14})}),fr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ht(!1),Rf()},disabled:!Lo,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${fs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[fs?e.jsx(Yo,{size:14}):e.jsx(Ma,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(fs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Ht(!1),mf()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${go?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[go?e.jsx(xm,{size:14}):e.jsx(wi,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(go?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!pe,onClick:()=>{pe&&(Ht(!1),pf(pe,Zs==="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:[Zs==="modified"?e.jsx(tm,{size:14}):e.jsx(qc,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(Zs==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),b&&(ca.length>0||kf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:Wl,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 ${pe===b?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:b,children:[e.jsx(Vc,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Ke})]}),ca.map(r=>{const i=r.path,u=r.kind==="file",x=u?Ve===i:pe===i;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${x?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i,children:[e.jsxs("button",{type:"button",onClick:()=>u?ds(i):Tt(i),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[u?e.jsx(ki,{size:10,className:"shrink-0"}):e.jsx(Ma,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ft(i)})]}),e.jsx("button",{type:"button",onClick:()=>ln(i),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":a("rightSidebar.unpinFolder",{name:ft(i)}),title:a("rightSidebar.unpinFolder",{name:ft(i)}),children:e.jsx(Ot,{size:9})})]},i)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Ko=o.useMemo(()=>{if(En===null)return null;const r=typeof navigator>"u"?void 0:navigator.language,i=Math.max(0,Math.floor((uo-En)/1e3)),u=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),[x,v]=i<60?[-i,"second"]:i<3600?[-Math.floor(i/60),"minute"]:i<86400?[-Math.floor(i/3600),"hour"]:[-Math.floor(i/86400),"day"];return u.format(x,v)},[uo,En]),Ic=b&&!cs?e.jsx("button",{type:"button",onClick:()=>{Zf(!bo)},"aria-pressed":bo,title:a("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${bo?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:a("rightSidebar.multiRepoScan")}):null,Fc=b?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Ko?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:a("rightSidebar.gitLastUpdated",{time:Ko}),children:Ko}):null,e.jsx("button",{type:"button",onClick:()=>{is()},disabled:Dr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":a("rightSidebar.refreshGit"),title:a("rightSidebar.refreshGit"),children:e.jsx(xi,{size:13,className:Dr?"animate-spin":""})})]}):null,lh=Ll?a("rightSidebar.changeAuditScopeAll"):fn.length===1?fn[0].relativeRoot==="."?Ke:fn[0].relativeRoot||fn[0].name:`${fn.length} repos`,Dc=b?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(jd,{open:Fs,onOpenChange:Pr,showScopePicker:bn,selectedAll:Ll,repos:gf,selectedRoots:Gt,onToggleRepo:Of,onGenerate:()=>Df(),disabled:!b,inserted:q===zl,buttonLabel:a("rightSidebar.changeAuditShort"),insertedLabel:a("rightSidebar.inserted"),title:a("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:a("rightSidebar.insertChangeAuditPrompt"),scopeTitle:a("rightSidebar.changeAuditScopeLabel"),scopeLabel:lh,allLabel:a("rightSidebar.changeAuditScopeAll"),generateLabel:a("rightSidebar.changeAuditShort"),loading:Er,error:!!Ar,statusTitle:Ar??(Er?a("rightSidebar.changeAuditLoading"):jt.length>0?`${a("rightSidebar.changeAuditLoaded",{count:jt.length})}${Lc?` · ${a("rightSidebar.changeAuditLoadedAt",{time:Lc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{_f()},disabled:Er||jt.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 ${jt.length>0?"":"invisible"}`,title:a("rightSidebar.clearChangeAuditTitle"),"aria-label":a("rightSidebar.clearChangeAudit"),children:e.jsx(_a,{size:12})})]}):null,ja=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:[ae?.available&&ae.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:ae.branch,children:[e.jsx(Cr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ae.branch})]}),st.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[st.modified,"M"]}),st.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",st.added]}),st.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",st.deleted]}),st.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[st.renamed,"R"]}),st.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[st.copied,"C"]}),st.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[st.untracked,"U"]}),st.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[st.conflicted,"!"]}),st.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[st.other,"?"]}),st.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:a("rightSidebar.stagedCountShort",{count:st.staged})}),ae?.available&&b&&we.size>0&&V.length<=1&&e.jsx("button",{type:"button",onClick:()=>{ot({action:"stage-all",cwd:b},a("rightSidebar.stageAll"))},disabled:!!Ae,className:"rounded-md bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),ae?.available&&b&&we.size>0&&V.length<=1&&e.jsx("button",{type:"button",onClick:()=>Fr({kind:"stash-all",repoRoot:b,repoLabel:Ke}),disabled:!!Ae,className:"rounded-md bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]});return e.jsxs(rm,{side:"right",isOpen:t,drawerWidthPx:n,onClose:s,onOpen:l,push:d,pinned:c,children:[Mo.popoverNode,e.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:b??void 0,children:Ke}),(!ee||lo)&&ae?.available&&ae.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:ae.branch,children:[e.jsx(Cr,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:ae.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const r=!se;fe(r),r?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):j("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${se?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleSearch"),title:a("common.search"),children:e.jsx(Vn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":Qe,onClick:()=>{vn(r=>!r),dr(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${Qe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a("rightSidebar.toggleContextDraft"),title:a("rightSidebar.contextDraftTitle"),children:[e.jsx(nm,{size:14}),!Qe&&wt.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:hl,type:"file",multiple:!0,className:"hidden",onChange:r=>{const i=r.target.files;!i||i.length===0||(us(Array.from(i)),r.target.value="")}}),e.jsx("input",{ref:ml,type:"file",accept:"image/*",className:"hidden",onChange:r=>{const i=r.target.files?.[0];r.target.value="",i&&yf(i)}}),h&&e.jsx("button",{type:"button",onClick:h,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${c?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:c?e.jsx(Yo,{size:14}):e.jsx(Ma,{size:14})}),e.jsxs("div",{ref:Ps,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{Ht(!1),At(r=>!r)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${Xt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":Xt,"aria-haspopup":"menu","aria-label":a("sidebar.moreActions"),title:a("sidebar.moreActions"),children:e.jsx(bi,{size:15})}),Xt&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{At(!1),hl.current?.click()},disabled:Ks,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:[Ks?e.jsx(vt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Fm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{At(!1),ml.current?.click()},disabled:Ks,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:[Ks?e.jsx(vt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Sm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a("rightSidebar.insertLocalImage")})]}),h&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{At(!1),h()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${c?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[c?e.jsx(Yo,{size:14}):e.jsx(Ma,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:a(c?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),c&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":a("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:a("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",a("rightSidebar.layoutModeAuto")],["narrow",a("rightSidebar.layoutModeNarrow")],["wide",a("rightSidebar.layoutModeWide")]].map(([r,i])=>{const u=G===r;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":u,onClick:()=>{J(r),At(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${u?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:i},r)})})]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":a("rightSidebar.close"),children:e.jsx(Ot,{size:14})})]}),se&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Vn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:O,onChange:r=>j(r.target.value),placeholder:a(M==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Rc("name"),"aria-pressed":M==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${M==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Rc("content"),"aria-pressed":M==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${M==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:a("rightSidebar.searchModeContent")})]}),O&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.clearSearch"),children:e.jsx(Ot,{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(sm,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:K,onChange:r=>re(r.target.value),onKeyDown:r=>{r.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchScopePlaceholder"),"aria-label":a("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),K!=="."&&e.jsx("button",{type:"button",onClick:()=>re("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":a("rightSidebar.resetSearchScope"),children:e.jsx(Ot,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>je(r=>!r),"aria-expanded":me,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${me||as.length>0||C||de||Ge?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:a("rightSidebar.searchOptions"),"aria-label":a("rightSidebar.searchOptions"),children:[e.jsx(am,{size:13}),as.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:as.length})]})]}),me&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:a("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:oe,onChange:r=>he(r.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:a("rightSidebar.searchExcludePlaceholder"),"aria-label":a("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),oe&&e.jsx("button",{type:"button",onClick:()=>he(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":a("rightSidebar.clearSearchExclude"),children:e.jsx(Ot,{size:11})})]}),M==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":a("rightSidebar.contentSearchOptions"),children:[[C,()=>Z(r=>!r),gm,a("rightSidebar.matchCase")],[de,()=>Ee(r=>!r),_m,a("rightSidebar.matchWholeWord")],[Ge,()=>De(r=>!r),$m,a("rightSidebar.useRegex")]].map(([r,i,u,x])=>e.jsxs("button",{type:"button",onClick:i,"aria-pressed":r,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${r?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(u,{size:12}),x]},x))})]})]}),cs?null:e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>on("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Hr==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Cr,{size:12}),a("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>on("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Hr==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Kd,{size:12}),a("rightSidebar.tabChanges"),we.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:we.size}):null]}),e.jsxs("button",{type:"button",onClick:()=>on("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${Hr==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(dm,{size:12}),a("rightSidebar.tabFiles")]})]}),e.jsx("div",{className:"h-2"}),ol&&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:ol})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(ii,{active:Xe,mounted:or,fallback:e.jsx(li,{slow:!1}),children:Ue?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Qc,{items:Hf,selectedKey:af,onSelect:Ds,emptyText:a("rightSidebar.noChanges"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a("rightSidebar.recentCommitsTitle"),headerMeta:`${Ue.headRef??""}${Ue.commits?.[0]?` · ${Ue.commits[0]}`:""}`,onClose:()=>{$e(null),Ds(null)},closeLabel:a("common.back"),wrap:$t,onToggleWrap:ee?ya:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Wr,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onClearAuditRecord:ga})}):br?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(Qc,{items:_o,selectedKey:oo,onSelect:rn,emptyText:a(Me?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:a("rightSidebar.backToChangeList"),headerTitle:a(Me?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:ba?`${ba.repoLabel} · ${ba.branchName??"HEAD"} → ${ba.baseRef}`:void 0,onClose:()=>{Qt(!1),Zt(null)},closeLabel:a("common.back"),wrap:$t,onToggleWrap:ee?ya:void 0,wrapTitle:a("rightSidebar.wrapLongLines"),wrapOnLabel:a("rightSidebar.wrapOn"),wrapOffLabel:a("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Wr,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onClearAuditRecord:ga,walkthroughs:zf,onWalkthroughNavigate:Wf,initialDetailScrollTop:Me&&Ze?jn[Ze]:void 0,onDetailScrollPositionChange:Jf,externalSwiperRef:ee?na:void 0,onMobileSlideChange:ee?io:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:Ac?e.jsx("div",{className:"px-3",children:Ac}):Dr?e.jsx(li,{slow:kl}):cn?e.jsx(Fa,{message:cn,onRetry:()=>{is()}}):Ed(ae)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(b?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):ae?.available===!1?e.jsx(Fa,{message:ae.error??a("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{is()}}):b?e.jsx(li,{slow:kl}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a(b?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(ii,{active:On,children:ee?e.jsxs(Dd,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:r=>{Sr.current=r,r.slideTo(sl,0)},onSlideChange:r=>{if(wr(r.activeIndex),os.current===r.activeIndex){os.current=null;return}r.activeIndex===0&&(yr(!1),kt(null),f?.())},children:[e.jsx(vi,{className:"h-full min-h-0",children:e.jsxs("div",{ref:Fn,onScroll:Pl,onDragOver:aa,onDragEnter:aa,onDragLeave:Fl,onDrop:Dl,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:a("rightSidebar.dropToUpload")})}),!O.trim()&&Tc,e.jsx(Kc,{rootPath:pe??"",onFileSelect:ds,onPathReference:zr,getReferenceText:ia,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onDirectoryRoot:Gl,onSearchFromDirectory:ql,onDirectoryPinToggle:Kl,onFilePinToggle:Vl,pinnedPaths:mn,selectedFilePath:Ve,query:le,searchRootPath:Cl,searchOptions:Nl,searchMode:M,onContentMatchSelect:Tl,onDirectoryDropFiles:(r,i)=>us(i,r),revealDirectory:X,canOpenInFileBrowser:ul,onOpenInFileBrowser:Il})]})}),e.jsx(vi,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Bi,{filePath:On&&(of||sl===1)?Ve:null,onInsertReference:zr,onInsertText:Rr,onInsertFeature:Rr,onReviewReference:Ul,onReferenceCopied:jr,onClose:ih,onDirectoryLinkOpen:Pc,isMobile:!0,lineRange:Kr,onLineRangeChange:kt,insertedReferenceKey:q,copiedReferenceKey:Re,scrollToLine:Mr,onScrollToLineHandled:()=>Ie(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:Fn,onScroll:Pl,onDragOver:aa,onDragEnter:aa,onDragLeave:Fl,onDrop:Dl,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:ho},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:a("rightSidebar.dropToUpload")})}),!O.trim()&&Tc,e.jsx(Kc,{rootPath:pe??"",onFileSelect:ds,onPathReference:zr,getReferenceText:ia,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onDirectoryRoot:Gl,onSearchFromDirectory:ql,onDirectoryPinToggle:Kl,onFilePinToggle:Vl,pinnedPaths:mn,selectedFilePath:Ve,query:le,searchRootPath:Cl,searchOptions:Nl,searchMode:M,onContentMatchSelect:Tl,onDirectoryDropFiles:(r,i)=>us(i,r),revealDirectory:X,canOpenInFileBrowser:ul,onOpenInFileBrowser:Il})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":a("rightSidebar.resizeFileTree"),title:a("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:bf,onPointerMove:xf,onPointerUp:Al,onPointerCancel:Al,onDoubleClick:()=>{mo(Ni),xt(ys,Ni)},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(Bi,{filePath:On?Ve:null,onInsertReference:zr,onInsertText:Rr,onInsertFeature:Rr,onReviewReference:Ul,onReferenceCopied:jr,onDirectoryLinkOpen:Pc,isMobile:!1,lineRange:Kr,onLineRangeChange:kt,insertedReferenceKey:q,copiedReferenceKey:Re,scrollToLine:Mr,onScrollToLineHandled:()=>Ie(null),markdownOutlineOpen:D,markdownOutlineCloseSignal:B,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:L,markdownImageLightboxCloseSignal:A,onOpenMarkdownImageLightbox:U,onCloseMarkdownImageLightbox:F})})]})}),e.jsx(ii,{active:pt,mounted:lf||pt,children:()=>Ro?e.jsx(om,{}):ee?e.jsx(yi,{mobile:!0,backLabel:a("rightSidebar.backToChangeList"),externalSwiperRef:na,onMobileSlideChange:io,groups:Bt.length>0?hc():[],mode:St,onModeChange:va,selectedKey:Ve,scrollToKey:bc,scrollToKeyNonce:Ys.nonce,compact:!1,collapsedDirectoryKeys:hr,onToggleDirectory:yc,onSelectFile:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);i&&xa(ut(i))},renderLeading:pc,renderTrailing:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);return i?uc(i):null},renderDirectoryTrailing:fc,renderSubtitle:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);return i?cc(i):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:r=>b&&e.jsxs("div",{className:"px-0 py-0",children:[ja&&e.jsx("div",{className:"mb-2",children:ja}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Bt.length,"/",we.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ic(),Ic,r,c&&Fo(),Dc,Fc]}),Ct&&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:Ct.label}),Ct.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:Ct.branch})]}),!Ct&&bn&&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(Cr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:ua?(r=>vc(r)):void 0,emptyContent:Ro?null:cn&&we.size===0?e.jsx(Fa,{message:cn,onRetry:()=>{is()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):Bt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>ls(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:a("rightSidebar.backToChangeList"),children:[e.jsx(Cs,{size:14}),a("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[c&&Fo(),e.jsxs("button",{type:"button",onClick:ya,"aria-pressed":$t,title:a("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${$t?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a($t?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:mc(),activePane:pt,wrap:$t,diffViewType:hf,inlineMode:Jn,diffOptions:jc,reloadKey:mr,renderStreamBadge:r=>e.jsx(Ss,{status:r}),onHunkGitAction:Cc,onInsertDiffReference:Wr,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onClearAuditRecord:ga,onDetailScroll:ma}):e.jsx(yi,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:a("rightSidebar.backToChangeList"),groups:Bt.length>0?hc():[],mode:St,onModeChange:va,selectedKey:Ve,scrollToKey:bc,scrollToKeyNonce:Ys.nonce,compact:!0,collapsedDirectoryKeys:hr,onToggleDirectory:yc,onSelectFile:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);i&&xa(ut(i))},renderLeading:pc,renderTrailing:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);return i?uc(i):null},renderDirectoryTrailing:fc,renderSubtitle:r=>{const i=Array.from(we.values()).find(u=>ut(u)===r.key);return i?cc(i):null},aiContent:ua?(r=>vc(r)):void 0,emptyContent:Ro?null:cn&&we.size===0?e.jsx(Fa,{message:cn,onRetry:()=>{is()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("rightSidebar.noChanges")}):Bt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:a("rightSidebar.noMatchingChanges")}):null,renderListHeader:r=>b&&e.jsxs("div",{className:"px-0 py-0",children:[ja&&e.jsx("div",{className:"mb-2",children:ja}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Bt.length,"/",we.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ic(),Ic,r,Fo(),e.jsxs("button",{type:"button",onClick:ya,"aria-pressed":$t,title:a("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 ${$t?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:a($t?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Dc,Fc]}),Ct&&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:Ct.label}),Ct.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:Ct.branch}),e.jsx("button",{type:"button",onClick:()=>ka("stage-all",Ct.root,Ct.label),disabled:!!Ae,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:a("rightSidebar.stageAll"),children:a("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>ka("stash-all",Ct.root,Ct.label),disabled:!!Ae,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:a("rightSidebar.stashAll"),children:a("rightSidebar.stashAll")})]}),!Ct&&bn&&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(Cr,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:a("rightSidebar.selectRepositoryForDiff")})]})]}),files:mc(),activePane:pt,wrap:$t,diffViewType:Jt,inlineMode:Jn,diffOptions:jc,reloadKey:mr,renderStreamBadge:r=>e.jsx(Ss,{status:r}),onHunkGitAction:Cc,onInsertDiffReference:Wr,onReferenceCopied:jr,insertedReferenceKey:q,copiedReferenceKey:Re,onClearAuditRecord:ga,onDetailScroll:ma})})]}),t&&Qe&&e.jsx(dp,{value:wt,collapsed:ht,autoCollapseAfterSend:Yt,focusRequest:qr,insertError:Xn?a("rightSidebar.contextDraftInsertFailed"):null,onChange:r=>{zt(!1),Ut(r)},onCollapsedChange:dr,onAutoCollapseAfterSendChange:yn,onDisable:()=>vn(!1),onClear:()=>Ut(""),onInsert:()=>Hl(!1),onInsertAndSend:()=>Hl(!0),labels:{title:a("rightSidebar.contextDraftTitle"),hint:a("rightSidebar.contextDraftHint"),placeholder:a("rightSidebar.contextDraftPlaceholder"),collapse:a("rightSidebar.contextDraftCollapse"),expand:a("rightSidebar.contextDraftExpand"),disable:a("rightSidebar.contextDraftDisable"),clear:a("rightSidebar.contextDraftClear"),insert:a("rightSidebar.contextDraftInsert"),insertAndSend:a("rightSidebar.contextDraftInsertAndSend"),inserted:a("rightSidebar.contextDraftInserted"),sent:a("rightSidebar.contextDraftSent"),send:a("rightSidebar.contextDraftSend"),appended:a("rightSidebar.contextDraftAppended"),resize:a("rightSidebar.contextDraftResize"),autoCollapseAfterSend:a("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:r=>a("rightSidebar.contextDraftCharacterCount",{count:r})}}),Pf(),ct&&typeof document<"u"&&Gr.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Fr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:ct.kind==="restore"?a("rightSidebar.confirmRestoreTitle"):a("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:ct.kind==="restore"?a("rightSidebar.confirmRestoreDescription",{path:Td(ct.file.absolutePath,b)}):a("rightSidebar.confirmStashAllDescription")}),ct.kind==="restore"&&e.jsx("input",{value:ct.phrase,onChange:r=>Fr({...ct,phrase:r.target.value}),placeholder:a("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Fr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:a("common.cancel")}),e.jsx("button",{type:"button",disabled:!!Ae||ct.kind==="restore"&&ct.phrase.trim()!==a("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(ct.kind==="restore"){const r=it(ct.file,b);if(!r)return;ot({action:"restore-worktree-file",cwd:r,paths:[ct.file.path],confirm:{acknowledged:!0,phrase:ct.phrase}},a("rightSidebar.restoreFile"),fi(ct.file))}else{const r=ct.repoRoot??b;if(!r)return;ot({action:"stash-all",cwd:r},a("rightSidebar.stashAll"),`repo:${r}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${ct.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:a(Ae?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const Ib=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Bi,MarkdownImageLightbox:qu,MarkdownPreview:Ku,RightSidebar:Sb,__testParseMarkdownListBlock:Og,buildMarkdownPreviewBlocks:Jg,buildMarkdownPreviewRenderResult:Xi,collectKnownGitRepoRoots:bu,computeMarkdownImageDisplayBox:$u,getMarkdownHeadingOutline:Gu,getMarkdownHeadingPathAtLine:Wu,getNextMarkdownPreviewLineRange:nb,isSvgImageSrc:Qa,mountRightSidebarRepoPickerOverlay:ru,replaceGitRepositorySnapshot:Zu,resolveMarkdownLocalLinkTarget:Wi,resolveRightSidebarDiffViewType:mu,shouldCloseMarkdownImageLightboxDrag:Uu,showsGitRepoGroupHeader:Mi},Symbol.toStringTag,{value:"Module"}));export{wi as E,Vc as H,Rm as M,Ib as R,xm as a,Nm as b,Um as c,Tb as m};