wind-agent-cli 1.38.0 → 1.38.2

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 (78) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/{CodeEditor-FvgsnJ7J.js → CodeEditor-C6BtLdoC.js} +1 -1
  3. package/dist/assets/{FileTree-NLULrBDi.js → FileTree-CGxNFZda.js} +1 -1
  4. package/dist/assets/{GitPanel-51KUBbEW.js → GitPanel-BV-IAyEC.js} +1 -1
  5. package/dist/assets/{MarkdownPreview-PEEWVWeS.js → MarkdownPreview-DVoEzpoc.js} +1 -1
  6. package/dist/assets/{Shell-BEx66cW_.js → Shell-CUTO-THd.js} +2 -2
  7. package/dist/assets/{StandaloneShell-BkuUCPZP.js → StandaloneShell-BKM1qxUc.js} +1 -1
  8. package/dist/assets/{TaskMasterPanel-DfQG80SF.js → TaskMasterPanel-DDDCVF6M.js} +2 -2
  9. package/dist/assets/{abnfDiagram-N423BO3Z-Cc0ul87U.js → abnfDiagram-N423BO3Z-Crubtav6.js} +1 -1
  10. package/dist/assets/{arc-BAuugHw_.js → arc-h9xb7EWA.js} +1 -1
  11. package/dist/assets/{architectureDiagram-T3A2C74G-DA3G7QZD.js → architectureDiagram-T3A2C74G-BmMQp4MC.js} +1 -1
  12. package/dist/assets/{blockDiagram-VBNYF7ZC-tJ12IJs3.js → blockDiagram-VBNYF7ZC-BtD-zDnJ.js} +1 -1
  13. package/dist/assets/{c4Diagram-5PPSVZJV-5BTMCXL4.js → c4Diagram-5PPSVZJV-D18s6J-v.js} +1 -1
  14. package/dist/assets/channel-CuR3zGvy.js +1 -0
  15. package/dist/assets/{chunk-2GRJ4B5K-BPaI06Ou.js → chunk-2GRJ4B5K-BHIcCvB_.js} +1 -1
  16. package/dist/assets/{chunk-2Q5K7J3B-HV4zmsEe.js → chunk-2Q5K7J3B-DcX4AeRe.js} +1 -1
  17. package/dist/assets/{chunk-5RXB4S5H-BAwutJoU.js → chunk-5RXB4S5H-CZwYDv9K.js} +1 -1
  18. package/dist/assets/{chunk-5VM5RSS4-B9QAJPrv.js → chunk-5VM5RSS4-CR-F7R13.js} +1 -1
  19. package/dist/assets/{chunk-6Q2QTUOP-BOIW8bzI.js → chunk-6Q2QTUOP-BPP216SB.js} +1 -1
  20. package/dist/assets/{chunk-GF5L2VYU-DD13o00-.js → chunk-GF5L2VYU-CcFeSmHe.js} +1 -1
  21. package/dist/assets/{chunk-JWPE2WC7-CFBm23VK.js → chunk-JWPE2WC7-C5T_9-OI.js} +1 -1
  22. package/dist/assets/{chunk-KBJHAD2P-C0i0v8Op.js → chunk-KBJHAD2P-g5eR5X5h.js} +1 -1
  23. package/dist/assets/{chunk-RYQCIY6F-DfeK0taV.js → chunk-RYQCIY6F-76WBDsoZ.js} +1 -1
  24. package/dist/assets/{chunk-XXDRQBXY-BKWvf-QE.js → chunk-XXDRQBXY-DGuy3LLn.js} +1 -1
  25. package/dist/assets/classDiagram-JCYQIIEL-BWpl-4NG.js +1 -0
  26. package/dist/assets/classDiagram-v2-OCEON4UE-BWpl-4NG.js +1 -0
  27. package/dist/assets/{cose-bilkent-JH36ORCC-CBE8oM7L.js → cose-bilkent-JH36ORCC-Cg4R1M0H.js} +1 -1
  28. package/dist/assets/{cynefin-VYW2F7L2-DziGp35A.js → cynefin-VYW2F7L2-Cbmals-o.js} +1 -1
  29. package/dist/assets/{cynefinDiagram-MW4NZA55-CNvtHl39.js → cynefinDiagram-MW4NZA55-CI79hpHc.js} +1 -1
  30. package/dist/assets/{dagre-VZM6K2ZE-Bz9lsU7m.js → dagre-VZM6K2ZE-r3Uz8Fhv.js} +1 -1
  31. package/dist/assets/{diagram-7IWD3JNH-CV7D3VSd.js → diagram-7IWD3JNH-ClRIkmQw.js} +1 -1
  32. package/dist/assets/{diagram-B4RE2ZJO-Dj4EjDNC.js → diagram-B4RE2ZJO-C71qkNlS.js} +1 -1
  33. package/dist/assets/{diagram-LBJQPF4R-wJ6FHvf-.js → diagram-LBJQPF4R-CC7ShhCC.js} +1 -1
  34. package/dist/assets/{diagram-Q27KOJAE-DMFYMhOB.js → diagram-Q27KOJAE-DPHL4vnP.js} +1 -1
  35. package/dist/assets/{diagram-UB23O5K3-DeBSbWAI.js → diagram-UB23O5K3-CP_My5E9.js} +1 -1
  36. package/dist/assets/{ebnfDiagram-BXEA7PRR-2NnJSGhT.js → ebnfDiagram-BXEA7PRR-BQe4AU9Z.js} +1 -1
  37. package/dist/assets/{erDiagram-JOGREHBK-DrSlg8hr.js → erDiagram-JOGREHBK-CFidQ-d5.js} +1 -1
  38. package/dist/assets/feature-chat-CHKsDTs-.js +88 -0
  39. package/dist/assets/{feature-workspace-CAB6bgPy.js → feature-workspace-BodovOw6.js} +2 -2
  40. package/dist/assets/{flowDiagram-UKHOOZJN-C0pejU6W.js → flowDiagram-UKHOOZJN-X5fPFxbp.js} +1 -1
  41. package/dist/assets/{ganttDiagram-PKOTCBZU-BM0VCUUz.js → ganttDiagram-PKOTCBZU-CILFHjP8.js} +1 -1
  42. package/dist/assets/{gitGraphDiagram-DS77QQ5N-SbLG0c5_.js → gitGraphDiagram-DS77QQ5N-DCQCtC_g.js} +1 -1
  43. package/dist/assets/{index-nyrkoQK6.js → index-Bn37f1jp.js} +13 -13
  44. package/dist/assets/{index-Gqazqfs3.js → index-Bo9nFrtn.js} +1 -1
  45. package/dist/assets/{index-Btkf0_rU.js → index-D0vbG70l.js} +1 -1
  46. package/dist/assets/{index-BflGfU1C.js → index-cNARKAN2.js} +1 -1
  47. package/dist/assets/{infoDiagram-6WML65LV-Cf5DSa66.js → infoDiagram-6WML65LV-Da145n1G.js} +1 -1
  48. package/dist/assets/{ishikawaDiagram-WSZJBQD7-DwyFutKy.js → ishikawaDiagram-WSZJBQD7-DGUP61eq.js} +1 -1
  49. package/dist/assets/{journeyDiagram-NVQOT4AX-Df0FRhLo.js → journeyDiagram-NVQOT4AX-BqfnKWDJ.js} +1 -1
  50. package/dist/assets/{kanban-definition-27J2QSJJ-HmpbjrZz.js → kanban-definition-27J2QSJJ-US6pQfNy.js} +1 -1
  51. package/dist/assets/{linear-DOM01LBe.js → linear-d91wK5kZ.js} +1 -1
  52. package/dist/assets/{mermaid.core-C2Ma-_S6.js → mermaid.core-BsWqrIaW.js} +4 -4
  53. package/dist/assets/{mindmap-definition-FAOFIHXS-B4GOIn76.js → mindmap-definition-FAOFIHXS-CXWD2UbS.js} +1 -1
  54. package/dist/assets/{pegDiagram-VL7TDLO6-BHur7aH2.js → pegDiagram-VL7TDLO6-BVzfDR-8.js} +1 -1
  55. package/dist/assets/{pieDiagram-7S7Q4E2Y-Cw0UELLV.js → pieDiagram-7S7Q4E2Y-PNpHZnJ9.js} +1 -1
  56. package/dist/assets/{quadrantDiagram-CIZ2JOQS-CB2BrX3g.js → quadrantDiagram-CIZ2JOQS-DxCI4i3K.js} +1 -1
  57. package/dist/assets/{railroadDiagram-AXF67PYL-DPYZYmLX.js → railroadDiagram-AXF67PYL-BYkvo3om.js} +1 -1
  58. package/dist/assets/{requirementDiagram-LRYGKXZP-DSX4IJ1n.js → requirementDiagram-LRYGKXZP-LUtvOYtV.js} +1 -1
  59. package/dist/assets/{sankeyDiagram-W5VNT64P-TenC3ZQo.js → sankeyDiagram-W5VNT64P-CVyI8YeM.js} +1 -1
  60. package/dist/assets/{sequenceDiagram-SI44F4Z6-DltGsf3F.js → sequenceDiagram-SI44F4Z6-1vuRFolM.js} +1 -1
  61. package/dist/assets/{sizeCapture-X5ZJPWSS-D7llwbJZ.js → sizeCapture-X5ZJPWSS-o4oVZXe8.js} +1 -1
  62. package/dist/assets/{stateDiagram-OKZ733FA-C-hAvbnY.js → stateDiagram-OKZ733FA-WedLIlXF.js} +1 -1
  63. package/dist/assets/stateDiagram-v2-UEYNNEHI-BqzvLVVB.js +1 -0
  64. package/dist/assets/{swimlanes-SLNWSIFB-DWD30fv6.js → swimlanes-SLNWSIFB-CpeXuk67.js} +2 -2
  65. package/dist/assets/swimlanesDiagram-ULZ7WXOC-CeI6fByR.js +8 -0
  66. package/dist/assets/{timeline-definition-Z64GVDOM-quWmimSE.js → timeline-definition-Z64GVDOM-DFcPWe47.js} +1 -1
  67. package/dist/assets/{vennDiagram-T6HMQDX7-aUQcm8h5.js → vennDiagram-T6HMQDX7-BH8C1C49.js} +1 -1
  68. package/dist/assets/{wardleyDiagram-T6FBY63Y-BZ0bwsFQ.js → wardleyDiagram-T6FBY63Y-K1Ew0uit.js} +1 -1
  69. package/dist/assets/{xychartDiagram-ELKLHX3M-DOVzAq63.js → xychartDiagram-ELKLHX3M-CQHlqWY2.js} +1 -1
  70. package/dist/index.html +3 -3
  71. package/dist/sw.js +1 -1
  72. package/package.json +5 -1
  73. package/dist/assets/channel-BGDgNNQz.js +0 -1
  74. package/dist/assets/classDiagram-JCYQIIEL-C2SNM4oy.js +0 -1
  75. package/dist/assets/classDiagram-v2-OCEON4UE-C2SNM4oy.js +0 -1
  76. package/dist/assets/feature-chat-CvOCyaLe.js +0 -88
  77. package/dist/assets/stateDiagram-v2-UEYNNEHI-DaYSFcRQ.js +0 -1
  78. package/dist/assets/swimlanesDiagram-ULZ7WXOC-LTkF2T6t.js +0 -8
@@ -1,4 +1,4 @@
1
- import{r as n,j as e}from"./vendor-react-C2GTiUCy.js";import{a as Z}from"./feature-workspace-CAB6bgPy.js";import{bs as Te,C as xe,o as fe,t as Re,r as oe,I as ht,R as V,G as P,bt as ft,bu as Ke,h as he,b as Xe,X as Ne,J as pt,av as gt,bv as Ye,bw as we,bx as bt,by as yt,a1 as Fe,aa as Ze,u as Pe,n as jt,L as Nt,$ as wt,T as vt}from"./vendor-ui-CAUHSABu.js";import"./vendor-i18n-B6HjLCnN.js";import"./vendor-data-DsEZeNPr.js";import"./vendor-markdown-DkITEES2.js";const Ct="main",kt=50,et=[{key:"modified",status:"M"},{key:"added",status:"A"},{key:"deleted",status:"D"},{key:"untracked",status:"U"}],St={M:"Modified",A:"Added",D:"Deleted",U:"Untracked"},Be={M:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800/50",A:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300 border-green-200 dark:border-green-800/50",D:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300 border-red-200 dark:border-red-800/50",U:"bg-muted text-muted-foreground border-border"},$t={discard:"Discard Changes",delete:"Delete File",commit:"Confirm Action",pull:"Confirm Pull",push:"Confirm Push",publish:"Publish Branch",revertLocalCommit:"Revert Local Commit",deleteBranch:"Delete Branch"},Et={discard:"Discard",delete:"Delete",commit:"Confirm",pull:"Pull",push:"Push",publish:"Publish",revertLocalCommit:"Revert Commit",deleteBranch:"Delete"},It={discard:"bg-red-600 hover:bg-red-700",delete:"bg-red-600 hover:bg-red-700",commit:"bg-primary hover:bg-primary/90",pull:"bg-green-600 hover:bg-green-700",push:"bg-orange-600 hover:bg-orange-700",publish:"bg-purple-600 hover:bg-purple-700",revertLocalCommit:"bg-yellow-600 hover:bg-yellow-700",deleteBranch:"bg-red-600 hover:bg-red-700"},Tt={discard:"bg-red-100 dark:bg-red-900/30",delete:"bg-red-100 dark:bg-red-900/30",commit:"bg-yellow-100 dark:bg-yellow-900/30",pull:"bg-yellow-100 dark:bg-yellow-900/30",push:"bg-yellow-100 dark:bg-yellow-900/30",publish:"bg-yellow-100 dark:bg-yellow-900/30",revertLocalCommit:"bg-yellow-100 dark:bg-yellow-900/30",deleteBranch:"bg-red-100 dark:bg-red-900/30"};function Ae(t){return t?et.flatMap(({key:r})=>t[r]||[]):[]}function tt(t){return Ae(t).length}function We(t){return tt(t)>0}function Ft(t){return St[t]||t}function De(t){return Be[t]||Be.U}function Lt(t){const r=[],s=t.split(/^diff --git /m).slice(1);for(const a of s){const o=a.split(`
1
+ import{r as n,j as e}from"./vendor-react-C2GTiUCy.js";import{a as Z}from"./feature-workspace-BodovOw6.js";import{bs as Te,C as xe,o as fe,t as Re,r as oe,I as ht,R as V,G as P,bt as ft,bu as Ke,h as he,b as Xe,X as Ne,J as pt,av as gt,bv as Ye,bw as we,bx as bt,by as yt,a1 as Fe,aa as Ze,u as Pe,n as jt,L as Nt,$ as wt,T as vt}from"./vendor-ui-CAUHSABu.js";import"./vendor-i18n-B6HjLCnN.js";import"./vendor-data-DsEZeNPr.js";import"./vendor-markdown-DkITEES2.js";const Ct="main",kt=50,et=[{key:"modified",status:"M"},{key:"added",status:"A"},{key:"deleted",status:"D"},{key:"untracked",status:"U"}],St={M:"Modified",A:"Added",D:"Deleted",U:"Untracked"},Be={M:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800/50",A:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300 border-green-200 dark:border-green-800/50",D:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300 border-red-200 dark:border-red-800/50",U:"bg-muted text-muted-foreground border-border"},$t={discard:"Discard Changes",delete:"Delete File",commit:"Confirm Action",pull:"Confirm Pull",push:"Confirm Push",publish:"Publish Branch",revertLocalCommit:"Revert Local Commit",deleteBranch:"Delete Branch"},Et={discard:"Discard",delete:"Delete",commit:"Confirm",pull:"Pull",push:"Push",publish:"Publish",revertLocalCommit:"Revert Commit",deleteBranch:"Delete"},It={discard:"bg-red-600 hover:bg-red-700",delete:"bg-red-600 hover:bg-red-700",commit:"bg-primary hover:bg-primary/90",pull:"bg-green-600 hover:bg-green-700",push:"bg-orange-600 hover:bg-orange-700",publish:"bg-purple-600 hover:bg-purple-700",revertLocalCommit:"bg-yellow-600 hover:bg-yellow-700",deleteBranch:"bg-red-600 hover:bg-red-700"},Tt={discard:"bg-red-100 dark:bg-red-900/30",delete:"bg-red-100 dark:bg-red-900/30",commit:"bg-yellow-100 dark:bg-yellow-900/30",pull:"bg-yellow-100 dark:bg-yellow-900/30",push:"bg-yellow-100 dark:bg-yellow-900/30",publish:"bg-yellow-100 dark:bg-yellow-900/30",revertLocalCommit:"bg-yellow-100 dark:bg-yellow-900/30",deleteBranch:"bg-red-100 dark:bg-red-900/30"};function Ae(t){return t?et.flatMap(({key:r})=>t[r]||[]):[]}function tt(t){return Ae(t).length}function We(t){return tt(t)>0}function Ft(t){return St[t]||t}function De(t){return Be[t]||Be.U}function Lt(t){const r=[],s=t.split(/^diff --git /m).slice(1);for(const a of s){const o=a.split(`
2
2
  `),i=(o[0]??"").match(/^a\/(.+?) b\/(.+)/);if(!i)continue;const g=i[1],x=i[2];let m="M";const f=o.slice(0,6).join(`
3
3
  `);f.includes("new file mode")?m="A":f.includes("deleted file mode")&&(m="D");const v=m==="D"?g:x;let y=0,p=0;for(const h of o)h.startsWith("+++")||h.startsWith("---")||(h.startsWith("+")?y++:h.startsWith("-")&&p++);const j=v.lastIndexOf("/"),u=j>=0?v.substring(0,j+1):"",N=j>=0?v.substring(j+1):v;r.push({path:v,directory:u,filename:N,status:m,insertions:y,deletions:p})}return{files:r,totalFiles:r.length,totalInsertions:r.reduce((a,o)=>a+o.insertions,0),totalDeletions:r.reduce((a,o)=>a+o.deletions,0)}}function Rt(){const[t,r]=n.useState(()=>localStorage.getItem("selected-provider")||"claude");return n.useEffect(()=>{const s=()=>{const a=localStorage.getItem("selected-provider")||"claude";r(a)};return window.addEventListener("storage",s),()=>window.removeEventListener("storage",s)},[]),t}const W=Z;function Me(t){return t instanceof DOMException&&t.name==="AbortError"}async function O(t,r){if(r?.aborted)throw new DOMException("Request aborted","AbortError");const s=await t.json();if(r?.aborted)throw new DOMException("Request aborted","AbortError");return s}function At({selectedProject:t,activeView:r,onFileOpen:s}){const[a,o]=n.useState(null),[d,i]=n.useState({}),[g,x]=n.useState(!1),[m,f]=n.useState(""),[v,y]=n.useState([]),[p,j]=n.useState([]),[u,N]=n.useState(!1),[h,T]=n.useState(!1),[I,B]=n.useState({}),[M,w]=n.useState(null),[$,k]=n.useState([]),[L,S]=n.useState([]),[R,z]=n.useState(!1),[H,Y]=n.useState(!1),[_,C]=n.useState(!1),[A,J]=n.useState(!1),[Q,se]=n.useState(!1),[ie,ne]=n.useState(!1),[le,D]=n.useState(!1),[K,G]=n.useState(null),ve=n.useCallback(()=>G(null),[]),X=n.useRef(t?.projectId??null);n.useEffect(()=>{X.current=t?.projectId??null},[t]);const pe=Rt(),ge=n.useCallback(async(c,l)=>{if(!t)return;const b=t.projectId;try{const F=await W(`/api/git/diff?project=${encodeURIComponent(b)}&file=${encodeURIComponent(c)}`,{signal:l}),ye=await O(F,l);if(l?.aborted||X.current!==b)return;!ye.error&&ye.diff&&i(Ee=>({...Ee,[c]:ye.diff}))}catch(F){if(l?.aborted||Me(F))return;console.error("Error fetching file diff:",F)}},[t]),E=n.useCallback(async c=>{if(!t)return;const l=t.projectId;x(!0);try{const b=await W(`/api/git/status?project=${encodeURIComponent(l)}`,{signal:c}),F=await O(b,c);if(c?.aborted||X.current!==l)return;if(F.error){F.notGitRepository||console.error("Git status error:",F.error),o({error:F.error,details:F.details,notGitRepository:F.notGitRepository}),f("");return}o(F),f(F.branch||Ct),Ae(F).forEach(Ee=>{ge(Ee,c)})}catch(b){if(c?.aborted||Me(b)||X.current!==l)return;console.error("Error fetching git status:",b),o({error:"Git operation failed",details:String(b)}),f("")}finally{x(!1)}},[ge,t]),q=n.useCallback(async()=>{if(t)try{const c=await W(`/api/git/branches?project=${encodeURIComponent(t.projectId)}`),l=await O(c);if(!l.error&&l.branches){y(l.branches),k(l.localBranches??l.branches),S(l.remoteBranches??[]);return}y([]),k([]),S([])}catch(c){console.error("Error fetching branches:",c),y([]),k([]),S([])}},[t]),U=n.useCallback(async()=>{if(t)try{const c=await W(`/api/git/remote-status?project=${encodeURIComponent(t.projectId)}`),l=await O(c);if(!l.error){w(l);return}w(null)}catch(c){console.error("Error fetching remote status:",c),w(null)}},[t]),Ce=n.useCallback(async c=>{if(!t)return!1;try{const l=await W("/api/git/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:c})}),b=await O(l);return b.success?(f(c),E(),!0):(console.error("Failed to switch branch:",b.error),!1)}catch(l){return console.error("Error switching branch:",l),!1}},[E,t]),ke=n.useCallback(async c=>{const l=c.trim();if(!t||!l)return!1;z(!0);try{const b=await W("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:l})}),F=await O(b);return F.success?(f(l),q(),E(),!0):(console.error("Failed to create branch:",F.error),!1)}catch(b){return console.error("Error creating branch:",b),!1}finally{z(!1)}},[q,E,t]),Se=n.useCallback(async(c,l=!1)=>{if(!t)return!1;try{const b=await W("/api/git/delete-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:c,force:l})}),F=await O(b);return F.success?(q(),!0):(G(F.error??"Delete branch failed"),!1)}catch(b){return G(b instanceof Error?b.message:"Delete branch failed"),!1}},[q,t]),$e=n.useCallback(async()=>{if(t){Y(!0);try{const c=await W("/api/git/fetch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U(),q();return}G(l.error??"Fetch failed")}catch(c){G(c instanceof Error?c.message:"Fetch failed")}finally{Y(!1)}}},[q,E,U,t]),ce=n.useCallback(async()=>{if(t){C(!0);try{const c=await W("/api/git/pull",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U();return}G(l.error??"Pull failed")}catch(c){G(c instanceof Error?c.message:"Pull failed")}finally{C(!1)}}},[E,U,t]),de=n.useCallback(async()=>{if(t){J(!0);try{const c=await W("/api/git/push",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U();return}G(l.error??"Push failed")}catch(c){G(c instanceof Error?c.message:"Push failed")}finally{J(!1)}}},[E,U,t]),me=n.useCallback(async()=>{if(t){se(!0);try{const c=await W("/api/git/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:m})}),l=await O(c);if(l.success){E(),U();return}console.error("Publish failed:",l.error)}catch(c){console.error("Error publishing branch:",c)}finally{se(!1)}}},[m,E,U,t]),be=n.useCallback(async c=>{if(t)try{const l=await W("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,file:c})}),b=await O(l);if(b.success){E();return}console.error("Discard failed:",b.error)}catch(l){console.error("Error discarding changes:",l)}},[E,t]),nt=n.useCallback(async c=>{if(t)try{const l=await W("/api/git/delete-untracked",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,file:c})}),b=await O(l);if(b.success){E();return}console.error("Delete failed:",b.error)}catch(l){console.error("Error deleting untracked file:",l)}},[E,t]),at=n.useCallback(async c=>{if(!t||c.length===0)return!1;try{const l=await W("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c})}),b=await O(l);return b.success?(await E(),!0):(G(b.error??"Stage failed"),!1)}catch(l){return G(l instanceof Error?l.message:"Stage failed"),!1}},[E,t]),ot=n.useCallback(async c=>{if(!t||c.length===0)return!1;try{const l=await W("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c})}),b=await O(l);return b.success?(await E(),!0):(G(b.error??"Unstage failed"),!1)}catch(l){return G(l instanceof Error?l.message:"Unstage failed"),!1}},[E,t]),Oe=n.useCallback(async()=>{if(!t)return;const c=t.projectId;N(!0);try{const l=await W(`/api/git/commits?project=${encodeURIComponent(c)}&limit=${kt}`),b=await O(l);if(X.current!==c)return;!b.error&&b.commits&&j(b.commits)}catch(l){console.error("Error fetching commits:",l)}finally{X.current===c&&(N(!1),T(!0))}},[t]),it=n.useCallback(async c=>{if(t)try{const l=await W(`/api/git/commit-diff?project=${encodeURIComponent(t.projectId)}&commit=${c}`),b=await O(l);!b.error&&b.diff&&B(F=>({...F,[c]:b.diff}))}catch(l){console.error("Error fetching commit diff:",l)}},[t]),lt=n.useCallback(async c=>{if(!t||c.length===0)return null;try{const l=await Z("/api/git/generate-commit-message",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c,provider:pe})}),b=await O(l);return b.message?b.message:(console.error("Failed to generate commit message:",b.error),null)}catch(l){return console.error("Error generating commit message:",l),null}},[pe,t]),ct=n.useCallback(async(c,l)=>{if(!t||!c.trim()||l.length===0)return!1;try{const b=await W("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,message:c,files:l})}),F=await O(b);return F.success?(E(),U(),!0):(console.error("Commit failed:",F.error),!1)}catch(b){return console.error("Error committing changes:",b),!1}},[E,U,t]),dt=n.useCallback(async()=>{if(!t)throw new Error("No project selected");ne(!0);try{const c=await W("/api/git/initial-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success)return E(),U(),!0;throw new Error(l.error||"Failed to create initial commit")}catch(c){throw console.error("Error creating initial commit:",c),c}finally{ne(!1)}},[E,U,t]),mt=n.useCallback(async()=>{if(!t)return!1;const c=t.projectId;D(!0);try{const l=await W("/api/git/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:c})}),b=await O(l);return X.current!==c?!1:b.success?(E(),q(),U(),!0):(G(b.error??"Failed to initialize repository"),!1)}catch(l){return X.current===c&&G(l instanceof Error?l.message:"Failed to initialize repository"),!1}finally{D(!1)}},[q,E,U,t]),ut=n.useCallback(async c=>{if(s){if(!t){s(c);return}try{const l=await W(`/api/git/file-with-diff?project=${encodeURIComponent(t.projectId)}&file=${encodeURIComponent(c)}`),b=await O(l);if(b.error){console.error("Error fetching file with diff:",b.error),s(c);return}s(c,{old_string:b.oldContent||"",new_string:b.currentContent||""})}catch(l){console.error("Error opening file:",l),s(c)}}},[s,t]),xt=n.useCallback(()=>{E(),q(),U()},[q,E,U]);return n.useEffect(()=>{const c=new AbortController;return f(""),y([]),k([]),S([]),o(null),w(null),i({}),j([]),B({}),x(!1),N(!1),T(!1),G(null),t?(E(c.signal),q(),U(),()=>{c.abort()}):()=>{c.abort()}},[q,E,U,t]),n.useEffect(()=>{!t||r!=="history"||Oe()},[r,Oe,t]),{gitStatus:a,gitDiff:d,isLoading:g,isLoadingCommits:u||!h,currentBranch:m,branches:v,localBranches:$,remoteBranches:L,recentCommits:p,commitDiffs:I,remoteStatus:M,isCreatingBranch:R,isFetching:H,isPulling:_,isPushing:A,isPublishing:Q,isCreatingInitialCommit:ie,isInitializingRepository:le,operationError:K,clearOperationError:ve,refreshAll:xt,switchBranch:Ce,createBranch:ke,deleteBranch:Se,handleFetch:$e,handlePull:ce,handlePush:de,handlePublish:me,discardChanges:be,deleteUntrackedFile:nt,stageFiles:at,unstageFiles:ot,fetchCommitDiff:it,generateCommitMessage:lt,commitChanges:ct,createInitialCommit:dt,initRepository:mt,openFile:ut}}async function Dt(t){return await t.json()}function Ot({projectId:t,onSuccess:r}){const[s,a]=n.useState(!1),o=n.useCallback(async()=>{if(t){a(!0);try{const d=await Z("/api/git/revert-local-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t})}),i=await Dt(d);if(!i.success){console.error("Revert local commit failed:",i.error||i.details||"Unknown error");return}r?.()}catch(d){console.error("Error reverting local commit:",d)}finally{a(!1)}}},[r,t]);return{isRevertingLocalCommit:s,revertLatestLocalCommit:o}}const Ie=new Map;function Bt({isMobile:t,projectPath:r,selectedFileCount:s,isHidden:a,onCommit:o,onRequestConfirmation:d}){const[i,g]=n.useState(()=>Ie.get(r)??""),x=u=>{g(u),u?Ie.set(r,u):Ie.delete(r)},[m,f]=n.useState(!1),[v,y]=n.useState(t),p=async(u=i)=>{const N=u.trim();if(!N||s===0||m)return!1;f(!0);try{const h=await o(N);return h&&x(""),h}finally{f(!1)}},j=()=>{const u=i.trim();!u||s===0||m||d({type:"commit",message:`Commit ${s} file${s!==1?"s":""} with message: "${u}"?`,onConfirm:async()=>{await p(u)}})};return e.jsx("div",{className:`transition-all duration-300 ease-in-out ${a?"max-h-0 -translate-y-2 overflow-hidden opacity-0":"max-h-96 translate-y-0 opacity-100"}`,children:t&&v?e.jsx("div",{className:"border-b border-border/60 px-4 py-2",children:e.jsxs("button",{onClick:()=>y(!1),className:"flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsxs("span",{children:["Commit ",s," file",s!==1?"s":""]}),e.jsx(xe,{className:"h-3 w-3"})]})}):e.jsxs("div",{className:"border-b border-border/60 px-4 py-3",children:[t&&e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Commit Changes"}),e.jsx("button",{onClick:()=>y(!0),className:"rounded-lg p-1 transition-colors hover:bg-accent",children:e.jsx(xe,{className:"h-4 w-4 rotate-180"})})]}),e.jsx("textarea",{value:i,onChange:u=>x(u.target.value),placeholder:"Message (Ctrl+Enter to commit)",className:"w-full resize-none rounded-xl border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",rows:3,onKeyDown:u=>{u.key==="Enter"&&(u.ctrlKey||u.metaKey)&&(u.preventDefault(),p())}}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," file",s!==1?"s":""," selected"]}),e.jsxs("button",{onClick:j,disabled:!i.trim()||s===0||m,className:"flex items-center space-x-1 rounded-lg bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(fe,{className:"h-3 w-3"}),e.jsx("span",{children:m?"Committing...":"Commit"})]})]})]})})}const Ue=2e5,_e=1500;function Wt(t){const r=t.length>Ue,a=(r?t.slice(0,Ue):t).split(`
4
4
  `),o=a.length>_e;return{lines:o?a.slice(0,_e):a,isCharacterTruncated:r,isLineTruncated:o}}function rt({diff:t,isMobile:r,wrapText:s}){const a=n.useMemo(()=>Wt(t||""),[t]),o=a.isCharacterTruncated||a.isLineTruncated;if(!t)return e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No diff available"});const d=(i,g)=>{const x=i.startsWith("+")&&!i.startsWith("+++"),m=i.startsWith("-")&&!i.startsWith("---"),f=i.startsWith("@@");return e.jsx("div",{className:`px-3 py-0.5 font-mono text-xs ${r&&s?"whitespace-pre-wrap break-all":"overflow-x-auto whitespace-pre"} ${x?"bg-green-50 text-green-700 dark:bg-green-950/50 dark:text-green-300":m?"bg-red-50 text-red-700 dark:bg-red-950/50 dark:text-red-300":f?"bg-primary/5 text-primary":"text-muted-foreground/70"}`,children:i},g)};return e.jsxs("div",{className:"diff-viewer",children:[o&&e.jsx("div",{className:"mb-2 rounded-md border border-border bg-card px-3 py-2 text-xs text-muted-foreground",children:"Large diff preview: rendering is limited to keep the tab responsive."}),a.lines.map((i,g)=>d(i,g))]})}function Mt({filePath:t,status:r,isMobile:s,isExpanded:a,isSelected:o,diff:d,wrapText:i,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v}){const y=Ft(r),p=De(r);return e.jsxs("div",{className:"border-b border-border last:border-0",children:[e.jsxs("div",{className:`flex items-center transition-colors hover:bg-accent/50 ${s?"px-2 py-1.5":"px-3 py-2"}`,children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>g(t),onClick:j=>j.stopPropagation(),className:`rounded border-border bg-background text-primary checked:bg-primary focus:ring-primary/40 ${s?"mr-1.5":"mr-2"}`}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[e.jsx("button",{onClick:j=>{j.stopPropagation(),x(t)},className:`cursor-pointer rounded p-0.5 hover:bg-accent ${s?"mr-1":"mr-2"}`,title:a?"Collapse diff":"Expand diff",children:e.jsx(Re,{className:`h-3 w-3 transition-transform duration-200 ease-in-out ${a?"rotate-90":"rotate-0"}`})}),e.jsx("span",{className:`flex-1 truncate ${s?"text-xs":"text-sm"} cursor-pointer hover:text-primary hover:underline`,onClick:j=>{j.stopPropagation(),m(t)},title:"Click to open file",children:t}),e.jsxs("span",{className:"flex items-center gap-1",children:[(r==="M"||r==="D"||r==="U")&&e.jsxs("button",{onClick:j=>{j.stopPropagation(),v(t,r)},className:`${s?"px-2 py-1 text-xs":"p-1"} flex items-center gap-1 rounded font-medium text-destructive hover:bg-destructive/10`,title:r==="U"?"Delete untracked file":"Discard changes",children:[e.jsx(oe,{className:"h-3 w-3"}),s&&e.jsx("span",{children:r==="U"?"Delete":"Discard"})]}),e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${p}`,title:y,children:r})]})]})]}),e.jsxs("div",{className:`duration-400 overflow-hidden bg-muted/50 transition-all ease-in-out ${a&&d?"max-h-[600px] translate-y-0 opacity-100":"max-h-0 -translate-y-1 opacity-0"}`,children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border p-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${p}`,children:r}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:y})]}),s&&e.jsx("button",{onClick:j=>{j.stopPropagation(),f()},className:"text-sm text-muted-foreground transition-colors hover:text-foreground",title:i?"Switch to horizontal scroll":"Switch to text wrap",children:i?"Scroll":"Wrap"})]}),e.jsx("div",{className:"max-h-96 overflow-y-auto",children:d&&e.jsx(rt,{diff:d,isMobile:s,wrapText:i})})]})]})}function Ge({gitStatus:t,gitDiff:r,expandedFiles:s,selectedFiles:a,isMobile:o,wrapText:d,filePaths:i,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v}){return e.jsx(e.Fragment,{children:et.map(({key:y,status:p})=>(t[y]||[]).filter(j=>!i||i.has(j)).map(j=>e.jsx(Mt,{filePath:j,status:p,isMobile:o,isExpanded:s.has(j),isSelected:a.has(j),diff:r[j],wrapText:d,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v},j)))})}const Ut=[{status:"M",label:"Modified"},{status:"A",label:"Added"},{status:"D",label:"Deleted"},{status:"U",label:"Untracked"}];function _t({isMobile:t}){const[r,s]=n.useState(!1);return t?null:e.jsxs("div",{className:"border-b border-border/60",children:[e.jsxs("button",{onClick:()=>s(a=>!a),className:"flex w-full items-center justify-center gap-1 bg-muted/30 px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50",children:[e.jsx(ht,{className:"h-3 w-3"}),e.jsx("span",{children:"File Status Guide"}),r?e.jsx(xe,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"})]}),r&&e.jsx("div",{className:"bg-muted/30 px-4 py-3 text-sm",children:e.jsx("div",{className:"flex justify-center gap-6",children:Ut.map(a=>e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${De(a.status)}`,children:a.status}),e.jsx("span",{className:"italic text-muted-foreground",children:a.label})]},a.status))})})]})}function Gt({isMobile:t,projectPath:r,gitStatus:s,gitDiff:a,isLoading:o,wrapText:d,isCreatingInitialCommit:i,onWrapTextChange:g,onCreateInitialCommit:x,onOpenFile:m,onDiscardFile:f,onDeleteFile:v,onStageFiles:y,onUnstageFiles:p,onCommitChanges:j,onRequestConfirmation:u,onExpandedFilesChange:N}){const[h,T]=n.useState(new Set),[I,B]=n.useState(new Set),[M,w]=n.useState(0),$=n.useRef(Promise.resolve()),k=n.useMemo(()=>Ae(s),[s]),L=h.size>0,S=n.useCallback(C=>{w(A=>A+1),$.current=$.current.catch(()=>{}).then(C).finally(()=>w(A=>A-1))},[]);n.useEffect(()=>{if(!s||s.error){B(new Set);return}M>0||B(new Set(s.staged??[]))},[s,M]),n.useEffect(()=>{N(L)},[L,N]),n.useEffect(()=>()=>{N(!1)},[N]);const R=n.useCallback(C=>{T(A=>{const J=new Set(A);return J.has(C)?J.delete(C):J.add(C),J})},[]),z=n.useCallback(C=>{const A=I.has(C);B(J=>{const Q=new Set(J);return A?Q.delete(C):Q.add(C),Q}),S(()=>A?p([C]):y([C]))},[S,y,p,I]),H=n.useCallback((C,A)=>{if(A==="U"){u({type:"delete",message:`Delete untracked file "${C}"? This action cannot be undone.`,onConfirm:async()=>{await v(C)}});return}u({type:"discard",message:`Discard all changes to "${C}"? This action cannot be undone.`,onConfirm:async()=>{await f(C)}})},[v,f,u]),Y=n.useCallback(C=>j(C,Array.from(I)),[j,I]),_=n.useMemo(()=>new Set(k.filter(C=>!I.has(C))),[k,I]);return e.jsxs(e.Fragment,{children:[e.jsx(Bt,{isMobile:t,projectPath:r,selectedFileCount:I.size,isHidden:L,onCommit:Y,onRequestConfirmation:u}),!s?.error&&e.jsx(_t,{isMobile:t}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:o?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):s?.hasCommits===!1&&We(s)?e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[e.jsx("div",{className:"mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-muted/50",children:e.jsx(P,{className:"h-7 w-7 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-2 text-lg font-medium text-foreground",children:"No commits yet"}),e.jsx("p",{className:"mb-6 max-w-md text-sm text-muted-foreground",children:"This repository doesn't have any commits yet. Create your first commit to start tracking changes."}),e.jsx("button",{onClick:()=>{x()},disabled:i,className:"flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:i?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Creating Initial Commit..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{children:"Create Initial Commit"})]})})]}):!s||!We(s)?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center text-muted-foreground",children:[e.jsx(Te,{className:"mb-2 h-10 w-10 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No changes detected"})]}):e.jsxs("div",{className:t?"pb-4":"",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 bg-muted/30 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["Staged (",I.size,")"]}),I.size>0&&e.jsx("button",{onClick:()=>{const C=Array.from(I);B(new Set),S(()=>p(C))},className:"text-xs text-primary transition-colors hover:text-primary/80",children:"Unstage All"})]}),I.size===0?e.jsx("div",{className:"px-3 py-2 text-xs italic text-muted-foreground",children:"No staged files"}):e.jsx(Ge,{gitStatus:s,gitDiff:a,expandedFiles:h,selectedFiles:I,isMobile:t,wrapText:d,filePaths:I,onToggleSelected:z,onToggleExpanded:R,onOpenFile:C=>{m(C)},onToggleWrapText:()=>g(!d),onRequestFileAction:H}),e.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 bg-muted/30 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["Changes (",_.size,")"]}),_.size>0&&e.jsx("button",{onClick:()=>{const C=Array.from(_);B(new Set(k)),S(()=>y(C))},className:"text-xs text-primary transition-colors hover:text-primary/80",children:"Stage All"})]}),_.size===0?e.jsx("div",{className:"px-3 py-2 text-xs italic text-muted-foreground",children:"All changes staged"}):e.jsx(Ge,{gitStatus:s,gitDiff:a,expandedFiles:h,selectedFiles:I,isMobile:t,wrapText:d,filePaths:_,onToggleSelected:z,onToggleExpanded:R,onOpenFile:C=>{m(C)},onToggleWrapText:()=>g(!d),onRequestFileAction:H})]})})]})}const ze=["#0ea5e9","#f97316","#a855f7","#22c55e","#ef4444","#eab308","#14b8a6","#ec4899","#6366f1","#84cc16"],ae=t=>ze[t%ze.length];function zt(t){const r=[],s=[],a=()=>{const o=r.indexOf(null);return o!==-1?o:(r.push(null),r.length-1)};for(const o of t){const d=new Set;r.forEach((u,N)=>{u!==null&&d.add(N)});const i=[];r.forEach((u,N)=>{u===o.hash&&i.push(N)});const g=i.length>0,x=g?i[0]:a(),m=i.slice(1);for(const u of m)r[u]=null;const f=o.parents??[];r[x]=f.length>0?f[0]:null;const v=[];for(const u of f.slice(1)){const N=r.findIndex(h=>h===u);if(N!==-1&&N!==x)v.push(N);else{const h=a();r[h]=u,v.push(h)}}const y=[...d].filter(u=>u!==x&&!i.includes(u)).sort((u,N)=>u-N),p=[];r.forEach((u,N)=>{u!==null&&p.push(N)});const j=Math.max(r.length,x+1);for(;r.length>0&&r[r.length-1]===null;)r.pop();s.push({nodeLane:x,laneCount:j,hasTopContinuation:g,hasParentContinuation:f.length>0,inbound:m,outbound:v,passThrough:y,bottomLanes:p})}return s}const Le=12,ue=56,ee=28,Je=3.5,te=2,re=t=>t*Le+Le/2;function Jt({row:t}){const r=t.laneCount*Le,s=re(t.nodeLane),a=ae(t.nodeLane);return e.jsxs("div",{"aria-hidden":!0,className:"relative shrink-0 self-stretch overflow-hidden",style:{width:r},children:[e.jsxs("svg",{className:"absolute left-0 top-0",width:r,height:ue,fill:"none",children:[t.passThrough.map(o=>e.jsx("path",{d:`M ${re(o)} 0 V ${ue}`,stroke:ae(o),strokeWidth:te},`pass-${o}`)),t.hasTopContinuation&&e.jsx("path",{d:`M ${s} 0 V ${ee}`,stroke:a,strokeWidth:te}),t.hasParentContinuation&&e.jsx("path",{d:`M ${s} ${ee} V ${ue}`,stroke:a,strokeWidth:te}),t.inbound.map(o=>e.jsx("path",{d:`M ${re(o)} 0 Q ${re(o)} ${ee} ${s} ${ee}`,stroke:ae(o),strokeWidth:te},`in-${o}`)),t.outbound.map(o=>e.jsx("path",{d:`M ${s} ${ee} Q ${re(o)} ${ee} ${re(o)} ${ue}`,stroke:ae(o),strokeWidth:te},`out-${o}`)),e.jsx("circle",{cx:s,cy:ee,r:t.inbound.length>0||t.outbound.length>0?Je+.5:Je,fill:a})]}),t.bottomLanes.map(o=>e.jsx("div",{className:"absolute",style:{left:re(o)-te/2,top:ue,bottom:0,width:te,backgroundColor:ae(o)}},`rail-${o}`))]})}function Ht(t){return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function qt({refName:t,color:r}){const s=t.startsWith("tag: "),a=t.startsWith("HEAD -> "),o=s?t.slice(5):a?t.slice(8):t;return e.jsxs("span",{className:"inline-flex max-w-40 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium leading-4",style:{borderColor:r,color:r,backgroundColor:a?`${r}22`:"transparent"},title:t,children:[s?e.jsx(ft,{className:"h-2.5 w-2.5 shrink-0"}):e.jsx(P,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]})}function Vt({commit:t,isExpanded:r,diff:s,isMobile:a,wrapText:o,graphRow:d,onToggle:i}){const g=n.useMemo(()=>s?Lt(s):null,[s]),x=d?ae(d.nodeLane):"#0ea5e9";return e.jsxs("div",{className:"flex border-b border-border last:border-0",children:[d&&e.jsx(Jt,{row:d}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("button",{type:"button","aria-expanded":r,className:"flex w-full cursor-pointer items-start border-0 bg-transparent p-3 text-left transition-colors hover:bg-accent/50",onClick:i,children:[e.jsx("span",{className:"mr-2 mt-1 rounded p-0.5 hover:bg-accent",children:r?e.jsx(xe,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[t.refs&&t.refs.length>0&&e.jsx("span",{className:"mb-0.5 flex flex-wrap gap-1",children:t.refs.map(m=>e.jsx(qt,{refName:m,color:x},m))}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:t.message}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[t.author," • ",t.date]})]}),e.jsx("span",{className:"flex-shrink-0 font-mono text-sm text-muted-foreground/60",children:t.hash.substring(0,7)})]})})]}),r&&s&&e.jsx("div",{className:"bg-muted/50",children:e.jsxs("div",{className:"max-h-[32rem] overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 select-all font-mono text-xs text-muted-foreground/70",children:t.hash}),e.jsxs("div",{className:"mb-3 flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground/60",children:"Author "}),t.author]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground/60",children:"Date "}),Ht(t.date)]})]}),g&&e.jsxs("div",{className:"mb-3 flex gap-4 rounded-md bg-muted/80 px-4 py-2 text-center text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Files"}),e.jsx("div",{className:"font-semibold text-foreground",children:g.totalFiles})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Added"}),e.jsxs("div",{className:"font-semibold text-green-600 dark:text-green-400",children:["+",g.totalInsertions]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Removed"}),e.jsxs("div",{className:"font-semibold text-red-600 dark:text-red-400",children:["-",g.totalDeletions]})]})]}),g&&g.files.length>0&&e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"mb-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Changed Files"}),e.jsx("div",{className:"rounded-md border border-border/60",children:g.files.map((m,f)=>e.jsxs("div",{className:`flex items-center gap-2 px-2.5 py-1.5 text-xs ${f<g.files.length-1?"border-b border-border/40":""}`,children:[e.jsx("span",{className:`inline-flex h-4 w-4 flex-shrink-0 items-center justify-center rounded border text-[9px] font-bold ${De(m.status)}`,children:m.status}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[m.directory&&e.jsx("span",{className:"text-muted-foreground/60",children:m.directory}),e.jsx("span",{className:"font-medium text-foreground",children:m.filename})]}),e.jsxs("span",{className:"flex-shrink-0 font-mono text-muted-foreground/60",children:[m.insertions>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["+",m.insertions]}),m.insertions>0&&m.deletions>0&&"/",m.deletions>0&&e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["-",m.deletions]})]})]},m.path))})]}),e.jsx(rt,{diff:s,isMobile:a,wrapText:o})]})})]})]})}function Qt({isMobile:t,isLoading:r,recentCommits:s,commitDiffs:a,wrapText:o,onFetchCommitDiff:d}){const[i,g]=n.useState(new Set),x=n.useMemo(()=>s.some(f=>f.parents!==void 0)?zt(s):null,[s]),m=n.useCallback(f=>{const v=!i.has(f);g(y=>{const p=new Set(y);return p.has(f)?p.delete(f):p.add(f),p}),v&&!a[f]&&d(f).catch(y=>{console.error("Failed to fetch commit diff:",y)})},[a,i,d,g]);return e.jsx("div",{className:"flex-1 overflow-y-auto",children:r?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):s.length===0?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center text-muted-foreground",children:[e.jsx(Ke,{className:"mb-2 h-10 w-10 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No commits found"})]}):e.jsx("div",{className:t?"pb-4":"",children:s.map((f,v)=>e.jsx(Vt,{commit:f,isExpanded:i.has(f.hash),diff:a[f.hash],isMobile:t,wrapText:o,graphRow:x?.[v],onToggle:()=>m(f.hash)},f.hash))})})}function st({isOpen:t,currentBranch:r,isCreatingBranch:s,onClose:a,onCreateBranch:o}){const[d,i]=n.useState("");n.useEffect(()=>{t||i("")},[t]);const g=async()=>{const x=d.trim();if(!x)return!1;try{const m=await o(x);return m&&(i(""),a()),m}catch(m){return console.error("Failed to create branch:",m),!1}};return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:a}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"new-branch-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"mb-4 text-lg font-semibold text-foreground",children:"Create New Branch"}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"git-new-branch-name",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Branch Name"}),e.jsx("input",{id:"git-new-branch-name",type:"text",value:d,onChange:x=>i(x.target.value),onKeyDown:x=>{if(x.key==="Enter"&&!s){x.preventDefault(),x.stopPropagation(),g();return}x.key==="Escape"&&!s&&(x.preventDefault(),x.stopPropagation(),a())},placeholder:"feature/new-feature",className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",autoFocus:!0})]}),e.jsxs("p",{className:"mb-4 text-sm text-muted-foreground",children:["This will create a new branch from the current branch (",r,")"]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:a,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{g()},disabled:!d.trim()||s,className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Creating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{children:"Create Branch"})]})})]})]})})]}):null}function He({name:t,isCurrent:r,isRemote:s,aheadCount:a,behindCount:o,isMobile:d,onSwitch:i,onDelete:g}){return e.jsxs("div",{className:`group flex items-center gap-3 border-b border-border/40 px-4 transition-colors hover:bg-accent/40 ${d?"py-2.5":"py-3"} ${r?"bg-primary/5":""}`,children:[e.jsx("div",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${r?"border-primary/30 bg-primary/10 text-primary":s?"border-border bg-muted text-muted-foreground":"border-border bg-muted/50 text-muted-foreground"}`,children:s?e.jsx(pt,{className:"h-3.5 w-3.5"}):e.jsx(P,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`truncate text-sm font-medium ${r?"text-foreground":"text-foreground/80"}`,children:t}),r&&e.jsx("span",{className:"shrink-0 rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:"current"}),s&&!r&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"remote"})]}),r&&(a>0||o>0)&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["↑",a," ahead"]}),o>0&&e.jsxs("span",{className:"text-primary",children:["↓",o," behind"]})]})]}),e.jsx("div",{className:`flex shrink-0 items-center gap-1 ${r?"opacity-100":"opacity-0 group-hover:opacity-100"} transition-opacity`,children:r?e.jsx(fe,{className:"h-4 w-4 text-primary"}):s?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:i,className:"rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:`Switch to ${t}`,children:"Switch"}),e.jsx("button",{onClick:g,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",title:`Delete ${t}`,children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]})})]})}function qe({label:t,count:r}){return e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between bg-background/95 px-4 py-2 backdrop-blur-sm",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:r})]})}function Kt({isMobile:t,isLoading:r,currentBranch:s,localBranches:a,remoteBranches:o,remoteStatus:d,isCreatingBranch:i,onSwitchBranch:g,onCreateBranch:x,onDeleteBranch:m,onRequestConfirmation:f}){const[v,y]=n.useState(!1),[p,j]=n.useState(""),u=d?.ahead??0,N=d?.behind??0,h=p.trim().toLowerCase(),T=n.useMemo(()=>h?a.filter(w=>w.toLowerCase().includes(h)):a,[a,h]),I=n.useMemo(()=>h?o.filter(w=>w.toLowerCase().includes(h)):o,[h,o]),B=w=>{f({type:"commit",message:`Switch to branch "${w}"? Make sure you have no uncommitted changes.`,onConfirm:()=>{g(w)}})},M=w=>{f({type:"deleteBranch",message:`Delete branch "${w}"? A normal delete only succeeds when the branch is fully merged. This cannot be undone.`,onConfirm:()=>{m(w)},alternateConfirmation:{label:"Force delete this unmerged branch",description:"Permanently removes the branch even when it contains commits that have not been merged elsewhere.",actionLabel:"Force delete",onConfirm:()=>{m(w,!0)}}})};return r&&a.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/40 px-4 py-2.5",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[a.length," local",o.length>0?`, ${o.length} remote`:""]}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-1.5 rounded-lg bg-primary/10 px-3 py-1.5 text-sm font-medium text-primary transition-colors hover:bg-primary/20",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"New branch"]})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-4 py-2",children:[e.jsx(Xe,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("input",{type:"text",value:p,onChange:w=>j(w.target.value),placeholder:"Search branches...",className:"w-full bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"}),p&&e.jsx("button",{onClick:()=>j(""),className:"shrink-0 text-muted-foreground transition-colors hover:text-foreground",title:"Clear search",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Local",count:T.length}),T.map(w=>e.jsx(He,{name:w,isCurrent:w===s,isRemote:!1,aheadCount:w===s?u:0,behindCount:w===s?N:0,isMobile:t,onSwitch:()=>B(w),onDelete:()=>M(w)},`local:${w}`))]}),I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Remote",count:I.length}),I.map(w=>e.jsx(He,{name:w,isCurrent:!1,isRemote:!0,aheadCount:0,behindCount:0,isMobile:t,onSwitch:()=>B(w),onDelete:()=>M(w)},`remote:${w}`))]}),T.length===0&&I.length===0&&e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-2 text-muted-foreground",children:[e.jsx(P,{className:"h-10 w-10 opacity-30"}),e.jsx("p",{className:"text-sm",children:h?"No branches match your search":"No branches found"})]})]}),e.jsx(st,{isOpen:v,currentBranch:s,isCreatingBranch:i,onClose:()=>y(!1),onCreateBranch:x})]})}function je(t,r){const s=t.error?.message||r,a=t.error?.details;return Array.isArray(a)&&a.length>0?`${s}: ${a.slice(0,5).join(", ")}${a.length>5?", …":""}`:typeof a=="string"&&a.trim()?`${s}: ${a.trim()}`:s}function Xt({selectedProject:t,onProjectSelect:r,onProjectsRefresh:s}){const[a,o]=n.useState(null),[d,i]=n.useState(!1),[g,x]=n.useState(!1),[m,f]=n.useState(!1),[v,y]=n.useState(null),p=n.useRef(null),[j,u]=n.useState(null),N=n.useCallback(()=>u(null),[]),h=n.useRef(t?.projectId??null);n.useEffect(()=>{h.current=t?.projectId??null},[t]);const T=n.useCallback(async()=>{if(!t)return;const $=t.projectId;i(!0);try{const k=await Z(`/api/worktrees?project=${encodeURIComponent($)}`),L=await k.json();if(h.current!==$)return;if(!k.ok||!L.data){o(null);return}o(L.data)}catch(k){console.error("Error fetching worktrees:",k),h.current===$&&o(null)}finally{h.current===$&&(i(!1),x(!0))}},[t]);n.useEffect(()=>{o(null),x(!1),u(null),T()},[T]);const I=n.useCallback(async($,k,L)=>{const S=$.trim();if(!t||!S)return!1;const R=t.projectId;f(!0),u(null);try{const z=await Z("/api/worktrees/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:R,branch:S,baseBranch:k})}),H=await z.json();return h.current!==R?!1:!z.ok||!H.data?(u(je(H,"Failed to create worktree")),!1):(s?.(),L&&H.data.project&&r?r(H.data.project):T(),!0)}catch(z){return h.current===R&&u(z instanceof Error?z.message:"Failed to create worktree"),!1}finally{f(!1)}},[T,r,s,t]),B=n.useCallback(async $=>{if(!t||p.current!==null)return!1;const k=t.projectId,L=Symbol("open-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:k,worktreePath:$})}),R=await S.json();return h.current!==k?!1:!S.ok||!R.data?.project?(u(je(R,"Failed to open worktree")),!1):(s?.(),r?.(R.data.project),!0)}catch(S){return h.current===k&&u(S instanceof Error?S.message:"Failed to open worktree"),!1}finally{p.current===L&&(p.current=null,y(null))}},[r,s,t]),M=n.useCallback(async($,k)=>{if(!t||p.current!==null)return!1;const L=Symbol("merge-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/merge",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,worktreePath:$,squash:k.squash,message:k.message,removeAfterMerge:k.removeAfterMerge})}),R=await S.json();return!S.ok||!R.success?(u(je(R,"Merge failed")),!1):(s?.(),T(),!0)}catch(S){return u(S instanceof Error?S.message:"Merge failed"),!1}finally{p.current===L&&(p.current=null,y(null))}},[T,s,t]),w=n.useCallback(async($,k)=>{if(!t||p.current!==null)return!1;const L=Symbol("remove-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/remove",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,worktreePath:$,force:k.force,deleteBranch:k.deleteBranch})}),R=await S.json();return!S.ok||!R.success?(u(je(R,"Failed to remove worktree")),!1):(s?.(),T(),!0)}catch(S){return u(S instanceof Error?S.message:"Failed to remove worktree"),!1}finally{p.current===L&&(p.current=null,y(null))}},[T,s,t]);return{worktreeData:a,isLoading:d||!g,isCreatingWorktree:m,busyWorktreePath:v,actionError:j,clearActionError:N,refreshWorktrees:T,createWorktree:I,openWorktree:B,mergeWorktree:M,removeWorktree:w}}function Ve(t,r){return t?r?`Squash merge branch '${t}'`:`Merge branch '${t}'`:""}function Yt({worktree:t,baseBranch:r,isMerging:s,onClose:a,onMerge:o}){const[d,i]=n.useState(!0),[g,x]=n.useState(""),[m,f]=n.useState(!0),[v,y]=n.useState(!1);n.useEffect(()=>{t&&(i(!0),f(!0),x(Ve(t.branch,!0)),y(!1))},[t]);const p=N=>{i(N),v||x(Ve(t?.branch??null,N))},j=async()=>{if(!t)return;await o(t.path,{squash:d,message:g.trim(),removeAfterMerge:m})&&a()};if(!t)return null;const u=`${t.ahead} commit${t.ahead===1?"":"s"}`;return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:a}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"merge-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{id:"merge-worktree-title",className:"mb-1 text-lg font-semibold text-foreground",children:"Merge Worktree"}),e.jsxs("div",{className:"mb-4 flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"max-w-[45%] truncate rounded-md bg-primary/10 px-2 py-1 font-mono text-primary",children:t.branch}),e.jsx(gt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"max-w-[45%] truncate rounded-md bg-muted px-2 py-1 font-mono text-foreground/80",children:r}),e.jsx("span",{className:"ml-auto shrink-0 text-xs text-muted-foreground",children:u})]}),e.jsxs("label",{className:"mb-3 flex cursor-pointer items-start gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:N=>p(N.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsxs("span",{children:["Squash commits",e.jsxs("span",{className:"block text-xs text-muted-foreground",children:["Combine all ",u," into a single commit on ",r]})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{htmlFor:"merge-worktree-message",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Commit message"}),e.jsx("textarea",{id:"merge-worktree-message",value:g,onChange:N=>{x(N.target.value),y(!0)},rows:2,className:"w-full resize-none rounded-xl border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20"})]}),e.jsxs("label",{className:"mb-4 flex cursor-pointer items-start gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:N=>f(N.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsxs("span",{children:["Clean up after merge",e.jsx("span",{className:"block text-xs text-muted-foreground",children:"Remove the worktree and delete its branch once merged"})]})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:a,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{j()},disabled:s||!g.trim(),className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Merging..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{className:"h-3 w-3"}),e.jsx("span",{children:d?"Squash & Merge":"Merge"})]})})]})]})})]})}function Zt(t){return t.replace(/[/\\:*?"<>|\s]+/g,"-").replace(/\.+$/g,"").replace(/^-+|-+$/g,"")}function Pt(t){const r=t.split(/[\\/]/).filter(Boolean);return r[r.length-1]??t}function er({isOpen:t,baseBranch:r,localBranches:s,repositoryRoot:a,isCreating:o,onClose:d,onCreate:i}){const[g,x]=n.useState(""),[m,f]=n.useState(""),[v,y]=n.useState(!0);n.useEffect(()=>{if(!t)x(""),y(!0);else{const h=r&&s.includes(r)?r:s[0]??"";f(h)}},[t,r,s]);const p=g.trim(),j=s.includes(p),u=n.useMemo(()=>{if(!p)return null;const h=Zt(p);return h?`${Pt(a)}-worktrees/${h}`:null},[a,p]),N=async()=>{if(!p)return!1;const h=await i(p,j?null:m||null,v);return h&&d(),h};return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:d}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"new-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{id:"new-worktree-title",className:"mb-1 text-lg font-semibold text-foreground",children:"New Worktree"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Check out a branch in its own folder and work on it in parallel."}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"worktree-branch-name",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Branch"}),e.jsx("input",{id:"worktree-branch-name",type:"text",value:g,onChange:h=>x(h.target.value),onKeyDown:h=>{if(h.key==="Enter"&&!o){h.preventDefault(),h.stopPropagation(),N();return}h.key==="Escape"&&!o&&(h.preventDefault(),h.stopPropagation(),d())},placeholder:"feature/new-feature",className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",autoFocus:!0}),j&&e.jsx("p",{className:"mt-1.5 text-xs text-muted-foreground",children:"Existing branch — it will be checked out as-is."})]}),!j&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"worktree-base-branch",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Create from"}),e.jsx("select",{id:"worktree-base-branch",value:m,onChange:h=>f(h.target.value),className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",children:s.map(h=>e.jsx("option",{value:h,children:h},h))})]}),u&&e.jsxs("p",{className:"mb-4 rounded-lg bg-muted/50 px-3 py-2 text-xs text-muted-foreground",children:["Will be created in ",e.jsx("span",{className:"font-mono text-foreground/80",children:u})]}),e.jsxs("label",{className:"mb-4 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:h=>y(h.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Switch to the worktree after creating it"]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:d,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{N()},disabled:!p||o,className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Creating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:"Create Worktree"})]})})]})]})})]}):null}function tr({worktree:t,isRemoving:r,onClose:s,onRemove:a}){const[o,d]=n.useState(!0),[i,g]=n.useState(!1);n.useEffect(()=>{t&&(d(!0),g(!1))},[t]);const x=async()=>{if(!t)return;await a(t.path,{force:i,deleteBranch:o})&&s()};if(!t)return null;const m=t.changedFileCount>0;return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:s}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"remove-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-4 flex items-center",children:[e.jsx("div",{className:"mr-3 rounded-full bg-red-100 p-2 dark:bg-red-900/30",children:e.jsx(oe,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),e.jsx("h3",{id:"remove-worktree-title",className:"text-lg font-semibold text-foreground",children:"Remove Worktree"})]}),e.jsxs("p",{className:"mb-3 text-sm text-muted-foreground",children:["Remove the worktree for"," ",e.jsx("span",{className:"font-mono text-foreground/80",children:t.branch??"detached HEAD"}),"? Its folder is deleted and the linked project is archived — chat sessions stay recoverable."]}),m&&e.jsxs("p",{className:"mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-600 dark:text-amber-400",children:["This worktree has ",t.changedFileCount," uncommitted change",t.changedFileCount===1?"":"s"," that will be lost."]}),t.branch&&e.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:f=>d(f.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Also delete branch ",e.jsx("span",{className:"font-mono",children:t.branch})]}),m&&e.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:f=>g(f.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Discard uncommitted changes"]}),e.jsxs("div",{className:"mt-4 flex justify-end space-x-3",children:[e.jsx("button",{onClick:s,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{x()},disabled:r||m&&!i,className:"flex items-center space-x-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50",children:r?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Removing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3"}),e.jsx("span",{children:"Remove"})]})})]})]})})]})}function rr(t){return t.split(/[\\/]/).filter(Boolean).slice(-2).join("/")||t}function sr({worktree:t,isMobile:r,isBusy:s,onOpen:a,onMerge:o,onRemove:d}){const i=t.branch??(t.headSha?`detached @ ${t.headSha.slice(0,7)}`:"detached");return e.jsxs("div",{className:`group flex items-center gap-3 border-b border-border/40 px-4 transition-colors hover:bg-accent/40 ${r?"py-2.5":"py-3"} ${t.isCurrent?"bg-primary/5":""}`,children:[e.jsx("div",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${t.isCurrent?"border-primary/30 bg-primary/10 text-primary":"border-border bg-muted/50 text-muted-foreground"}`,children:t.isMain?e.jsx(bt,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`truncate text-sm font-medium ${t.isCurrent?"text-foreground":"text-foreground/80"}`,children:i}),t.isCurrent&&e.jsx("span",{className:"shrink-0 rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:"current"}),t.isMain&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"main worktree"}),t.isLocked&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"locked"})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"shrink-0 font-mono",children:rr(t.path)}),t.ahead>0&&e.jsxs("span",{className:"shrink-0 text-green-600 dark:text-green-400",children:["↑",t.ahead]}),t.behind>0&&e.jsxs("span",{className:"shrink-0 text-primary",children:["↓",t.behind]}),t.changedFileCount>0&&e.jsxs("span",{className:"shrink-0 text-amber-600 dark:text-amber-400",children:["● ",t.changedFileCount," change",t.changedFileCount===1?"":"s"]}),t.lastCommitSubject&&e.jsx("span",{className:"truncate",children:t.lastCommitSubject})]})]}),e.jsx("div",{className:`flex shrink-0 items-center gap-1 ${t.isCurrent||s?"opacity-100":"opacity-100 sm:opacity-0 sm:focus-within:opacity-100 sm:group-hover:opacity-100"} transition-opacity`,children:s?e.jsx(V,{className:"h-4 w-4 animate-spin text-muted-foreground"}):t.isCurrent?e.jsx(fe,{className:"h-4 w-4 text-primary"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:`Switch to ${i}`,children:[e.jsx(yt,{className:"h-3 w-3"}),"Open"]}),!t.isMain&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:o,disabled:!t.branch||t.ahead===0,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-primary/10 hover:text-primary disabled:cursor-not-allowed disabled:opacity-40",title:t.ahead===0?"Nothing to merge — no commits ahead of the base branch":`Merge ${i} into the base branch`,children:e.jsx(Ye,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:d,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",title:`Remove worktree for ${i}`,children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]})]})})]})}function nr({isMobile:t,selectedProject:r,localBranches:s,onProjectSelect:a,onProjectsRefresh:o}){const{worktreeData:d,isLoading:i,isCreatingWorktree:g,busyWorktreePath:x,actionError:m,clearActionError:f,refreshWorktrees:v,createWorktree:y,openWorktree:p,mergeWorktree:j,removeWorktree:u}=Xt({selectedProject:r,onProjectSelect:a,onProjectsRefresh:o}),[N,h]=n.useState(!1),[T,I]=n.useState(null),[B,M]=n.useState(null),w=d?.worktrees??[],$=w.filter(k=>!k.isMain).length;return i&&w.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/40 px-4 py-2.5",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:$===0?"No worktrees":`${$} worktree${$===1?"":"s"}`}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>{v()},className:"rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:"Refresh worktrees",children:e.jsx(V,{className:`h-3.5 w-3.5 ${i?"animate-spin":""}`})}),e.jsxs("button",{onClick:()=>h(!0),disabled:!d,className:"flex items-center gap-1.5 rounded-lg bg-primary/10 px-3 py-1.5 text-sm font-medium text-primary transition-colors hover:bg-primary/20 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"New worktree"]})]})]}),m&&e.jsxs("div",{className:"flex items-start gap-2 border-b border-destructive/30 bg-destructive/10 px-4 py-2.5",children:[e.jsx("p",{className:"min-w-0 flex-1 break-words text-xs text-destructive",children:m}),e.jsx("button",{onClick:f,className:"shrink-0 text-destructive/70 transition-colors hover:text-destructive",title:"Dismiss",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[w.map(k=>e.jsx(sr,{worktree:k,isMobile:t,isBusy:x===k.path,onOpen:()=>{p(k.path)},onMerge:()=>I(k),onRemove:()=>M(k)},k.path)),$===0&&e.jsxs("div",{className:"flex flex-col items-center gap-3 px-6 py-10 text-center",children:[e.jsx(we,{className:"h-10 w-10 text-muted-foreground opacity-30"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground/80",children:"Work on branches in parallel"}),e.jsx("p",{className:"mx-auto mt-1 max-w-xs text-xs text-muted-foreground",children:"A worktree checks out a branch in its own folder, so you can run separate chat sessions side by side and merge the results back when they're ready."})]}),e.jsxs("button",{onClick:()=>h(!0),disabled:!d,className:"flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"Create your first worktree"]})]})]}),e.jsx(er,{isOpen:N,baseBranch:d?.baseBranch??null,localBranches:s,repositoryRoot:d?.repositoryRoot??"",isCreating:g,onClose:()=>h(!1),onCreate:y}),e.jsx(Yt,{worktree:T,baseBranch:d?.baseBranch??null,isMerging:T!==null&&x===T.path,onClose:()=>I(null),onMerge:j}),e.jsx(tr,{worktree:B,isRemoving:B!==null&&x===B.path,onClose:()=>M(null),onRemove:u})]})}function ar({isMobile:t,currentBranch:r,branches:s,remoteStatus:a,isLoading:o,isCreatingBranch:d,isFetching:i,isPulling:g,isPushing:x,isPublishing:m,isRevertingLocalCommit:f,operationError:v,onRefresh:y,onRevertLocalCommit:p,onSwitchBranch:j,onCreateBranch:u,onFetch:N,onPull:h,onPush:T,onPublish:I,onClearError:B,onRequestConfirmation:M}){const[w,$]=n.useState(!1),[k,L]=n.useState(!1),[S,R]=n.useState(""),z=n.useRef(null),H=n.useRef(null);n.useEffect(()=>{w?H.current?.focus():R("")},[w]);const Y=n.useMemo(()=>{const D=S.trim().toLowerCase();return D?s.filter(K=>K.toLowerCase().includes(D)):s},[s,S]);n.useEffect(()=>{const D=K=>{z.current&&!z.current.contains(K.target)&&$(!1)};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);const _=a?.ahead??0,C=a?.behind??0,A=a?.remoteName??"remote",J=i||g||x||m,Q=()=>{M({type:"pull",message:`Pull ${C} commit${C!==1?"s":""} from ${A}?`,onConfirm:h})},se=()=>{M({type:"push",message:`Push ${_} commit${_!==1?"s":""} to ${A}?`,onConfirm:T})},ie=()=>{M({type:"publish",message:`Publish branch "${r}" to ${A}?`,onConfirm:I})},ne=()=>{M({type:"revertLocalCommit",message:"Revert the latest local commit? This removes the commit but keeps its changes staged.",onConfirm:p})},le=async D=>{try{await j(D)&&$(!1)}catch(K){console.error("[GitPanelHeader] Failed to switch branch:",K)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between border-b border-border/60 ${t?"px-3 py-2":"px-4 py-3"}`,children:[e.jsxs("div",{className:"relative",ref:z,children:[e.jsxs("button",{onClick:()=>$(D=>!D),className:`flex items-center rounded-lg transition-colors hover:bg-accent ${t?"space-x-1 px-2 py-1":"space-x-2 px-3 py-1.5"}`,children:[e.jsx(P,{className:`text-muted-foreground ${t?"h-3 w-3":"h-4 w-4"}`}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:`font-medium ${t?"text-xs":"text-sm"}`,children:r}),a?.hasRemote&&e.jsxs("span",{className:"flex items-center gap-0.5 text-xs",children:[_>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",title:`${_} ahead`,children:["↑",_]}),C>0&&e.jsxs("span",{className:"text-primary",title:`${C} behind`,children:["↓",C]}),a.isUpToDate&&e.jsx("span",{className:"text-muted-foreground",title:"Up to date",children:"✓"})]})]}),e.jsx(xe,{className:`h-3 w-3 text-muted-foreground transition-transform ${w?"rotate-180":""}`})]}),w&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-xl border border-border bg-card shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[e.jsx(Xe,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("input",{ref:H,type:"text",value:S,onChange:D=>R(D.target.value),placeholder:"Search branches...",className:"w-full bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"}),S&&e.jsx("button",{onClick:()=>R(""),className:"shrink-0 text-muted-foreground transition-colors hover:text-foreground",title:"Clear search",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto py-1",children:Y.length===0?e.jsx("div",{className:"px-4 py-3 text-center text-sm text-muted-foreground",children:"No matching branches"}):Y.map(D=>e.jsx("button",{onClick:()=>{le(D)},className:`w-full px-4 py-2 text-left text-sm transition-colors hover:bg-accent ${D===r?"bg-accent/50 text-foreground":"text-muted-foreground"}`,children:e.jsxs("span",{className:"flex items-center space-x-2",children:[D===r&&e.jsx(fe,{className:"h-3 w-3 text-primary"}),e.jsx("span",{className:D===r?"font-medium":"",children:D})]})},D))}),e.jsx("div",{className:"border-t border-border py-1",children:e.jsxs("button",{onClick:()=>{L(!0),$(!1)},className:"flex w-full items-center space-x-2 px-4 py-2 text-left text-sm transition-colors hover:bg-accent",children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{children:"Create new branch"})]})})]})]}),e.jsxs("div",{className:`flex items-center ${t?"gap-1":"gap-2"}`,children:[a?.hasRemote&&e.jsx(e.Fragment,{children:a.hasUpstream?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>{N()},disabled:J,className:"flex items-center gap-1 rounded-lg bg-primary px-2.5 py-1 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",title:`Fetch from ${A}`,children:[e.jsx(V,{className:`h-3 w-3 ${i?"animate-spin":""}`}),!t&&e.jsx("span",{children:i?"Fetching…":"Fetch"})]}),C>0&&e.jsxs("button",{onClick:Q,disabled:J,className:"flex items-center gap-1 rounded-lg bg-green-600 px-2.5 py-1 text-sm text-white transition-colors hover:bg-green-700 disabled:opacity-50",title:`Pull ${C} from ${A}`,children:[e.jsx(Ze,{className:`h-3 w-3 ${g?"animate-pulse":""}`}),!t&&e.jsx("span",{children:g?"Pulling…":`Pull ${C}`})]}),_>0&&e.jsxs("button",{onClick:se,disabled:J,className:"flex items-center gap-1 rounded-lg bg-orange-600 px-2.5 py-1 text-sm text-white transition-colors hover:bg-orange-700 disabled:opacity-50",title:`Push ${_} to ${A}`,children:[e.jsx(Fe,{className:`h-3 w-3 ${x?"animate-pulse":""}`}),!t&&e.jsx("span",{children:x?"Pushing…":`Push ${_}`})]})]}):e.jsxs("button",{onClick:ie,disabled:J,className:"flex items-center gap-1 rounded-lg bg-primary px-2.5 py-1 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",title:`Publish "${r}" to ${A}`,children:[e.jsx(Fe,{className:`h-3 w-3 ${m?"animate-pulse":""}`}),!t&&e.jsx("span",{children:m?"Publishing…":"Publish"})]})}),e.jsx("button",{onClick:ne,disabled:f,className:`rounded-lg transition-colors hover:bg-accent disabled:opacity-50 ${t?"p-1":"p-1.5"}`,title:"Revert latest local commit",children:e.jsx(Pe,{className:`text-muted-foreground ${f?"animate-pulse":""} ${t?"h-3 w-3":"h-4 w-4"}`})}),e.jsx("button",{onClick:y,disabled:o,className:`rounded-lg transition-colors hover:bg-accent ${t?"p-1":"p-1.5"}`,title:"Refresh git status",children:e.jsx(V,{className:`text-muted-foreground ${o?"animate-spin":""} ${t?"h-3 w-3":"h-4 w-4"}`})})]})]}),v&&e.jsxs("div",{className:"flex items-start gap-2 border-b border-destructive/20 bg-destructive/10 px-4 py-2.5 text-sm text-destructive",children:[e.jsx(jt,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{className:"flex-1 leading-snug",children:v}),e.jsx("button",{onClick:B,className:"shrink-0 rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsx(st,{isOpen:k,currentBranch:r,isCreatingBranch:d,onClose:()=>L(!1),onCreateBranch:u})]})}function or({error:t,details:r,canInitRepository:s=!1,isInitializingRepository:a=!1,initError:o,onInitRepository:d}){const i=s&&!!d;return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-12 text-muted-foreground",children:[e.jsx("div",{className:"mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-muted/50",children:e.jsx(P,{className:"h-8 w-8 opacity-40"})}),i?e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-3 text-center text-lg font-medium text-foreground",children:"No git repository"}),e.jsx("p",{className:"mb-6 max-w-md text-center text-sm leading-relaxed",children:"This project is not a git repository yet. Initialize one to start tracking changes and use source control features."}),e.jsx("button",{onClick:d,disabled:a,className:"flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-60",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"h-4 w-4 animate-spin"}),"Initializing repository..."]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-4 w-4"}),"Run git init"]})}),o&&e.jsx("p",{className:"mt-4 max-w-md text-center text-sm leading-relaxed text-destructive",children:o})]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-3 text-center text-lg font-medium text-foreground",children:t}),r&&e.jsx("p",{className:"max-w-md text-center text-sm leading-relaxed",children:r})]})]})}const ir=[{id:"changes",label:"Changes",Icon:wt},{id:"history",label:"Commits",Icon:Ke},{id:"branches",label:"Branches",Icon:P},{id:"worktrees",label:"Worktrees",Icon:we}];function lr({activeView:t,isHidden:r,changeCount:s,onChange:a}){return e.jsx("div",{className:`border-b border-border/60 transition-all duration-300 ease-in-out ${r?"max-h-0 -translate-y-2 overflow-hidden opacity-0":"max-h-16 translate-y-0 opacity-100"}`,children:e.jsx("div",{className:"scrollbar-hide flex w-full snap-x overflow-x-auto overscroll-x-contain [-webkit-overflow-scrolling:touch]",role:"tablist","aria-label":"Source control views",children:ir.map(({id:o,label:d,Icon:i})=>e.jsx("button",{type:"button",role:"tab","aria-selected":t===o,onClick:()=>a(o),className:`min-w-max flex-none snap-start px-4 py-2 text-sm font-medium transition-colors sm:min-w-0 sm:flex-1 ${t===o?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"}`,children:e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(i,{className:"h-4 w-4"}),e.jsx("span",{children:d}),o==="changes"&&s>0&&e.jsx("span",{className:"rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:s})]})},o))})})}function Qe(t){return t==="discard"||t==="delete"?e.jsx(oe,{className:"h-4 w-4"}):t==="commit"?e.jsx(fe,{className:"h-4 w-4"}):t==="pull"?e.jsx(Ze,{className:"h-4 w-4"}):t==="revertLocalCommit"?e.jsx(Pe,{className:"h-4 w-4"}):e.jsx(Fe,{className:"h-4 w-4"})}function cr({action:t,onCancel:r,onConfirm:s}){const[a,o]=n.useState(!1),d=t?`confirmation-title-${t.type}`:void 0,i=()=>{o(!1),r()},g=()=>{const x=a&&!!t?.alternateConfirmation;o(!1),s(x)};return n.useEffect(()=>{if(!t)return;const x=m=>{m.key==="Escape"&&(o(!1),r())};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x)}},[t,r]),t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:i}),e.jsxs("div",{className:"relative flex max-h-[calc(100dvh-2rem)] w-full max-w-md flex-col overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":d,children:[e.jsxs("div",{className:"flex shrink-0 items-center px-6 pt-6",children:[e.jsx("div",{className:`mr-3 rounded-full p-2 ${Tt[t.type]}`,children:Qe(t.type)}),e.jsx("h3",{id:d,className:"text-lg font-semibold text-foreground",children:$t[t.type]})]}),e.jsx("p",{className:"scrollbar-thin my-4 min-h-0 flex-1 overflow-y-auto overscroll-contain whitespace-pre-wrap break-words px-6 text-sm text-muted-foreground",children:t.message}),t.alternateConfirmation&&e.jsxs("label",{className:"mx-6 mb-5 flex cursor-pointer items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/5 p-3 transition-colors hover:bg-destructive/10",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:x=>o(x.target.checked),className:"mt-0.5 h-4 w-4 shrink-0 accent-destructive"}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-sm font-medium text-foreground",children:[e.jsx(vt,{className:"h-3.5 w-3.5 text-destructive"}),t.alternateConfirmation.label]}),e.jsx("span",{className:"mt-1 block text-xs leading-relaxed text-muted-foreground",children:t.alternateConfirmation.description})]})]}),e.jsxs("div",{className:"flex shrink-0 justify-end space-x-3 px-6 pb-6",children:[e.jsx("button",{onClick:i,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsxs("button",{onClick:g,className:`flex items-center space-x-2 rounded-lg px-4 py-2 text-sm text-white transition-colors ${It[t.type]}`,children:[Qe(t.type),e.jsx("span",{children:a&&t.alternateConfirmation?t.alternateConfirmation.actionLabel:Et[t.type]})]})]})]})]}):null}function pr({selectedProject:t,isMobile:r=!1,onFileOpen:s,onProjectSelect:a,onProjectsRefresh:o}){const[d,i]=n.useState("changes"),[g,x]=n.useState(!0),[m,f]=n.useState(!1),[v,y]=n.useState(null),{gitStatus:p,gitDiff:j,isLoading:u,isLoadingCommits:N,currentBranch:h,branches:T,localBranches:I,remoteBranches:B,recentCommits:M,commitDiffs:w,remoteStatus:$,isCreatingBranch:k,isFetching:L,isPulling:S,isPushing:R,isPublishing:z,isCreatingInitialCommit:H,isInitializingRepository:Y,operationError:_,clearOperationError:C,refreshAll:A,switchBranch:J,createBranch:Q,deleteBranch:se,handleFetch:ie,handlePull:ne,handlePush:le,handlePublish:D,discardChanges:K,deleteUntrackedFile:G,stageFiles:ve,unstageFiles:X,fetchCommitDiff:pe,commitChanges:ge,createInitialCommit:E,initRepository:q,openFile:U}=At({selectedProject:t,activeView:d,onFileOpen:s}),{isRevertingLocalCommit:Ce,revertLatestLocalCommit:ke}=Ot({projectId:t?.projectId??null,onSuccess:A}),Se=n.useCallback(async(de=!1)=>{if(!v)return;const me=v;y(null);try{await(de?me.alternateConfirmation?.onConfirm??me.onConfirm:me.onConfirm)()}catch(be){console.error("Error executing confirmation action:",be)}},[v]),$e=tt(p),ce=!!p?.notGitRepository;return t?e.jsxs("div",{className:"flex h-full flex-col bg-background",children:[!ce&&e.jsx(ar,{isMobile:r,currentBranch:h,branches:T,remoteStatus:$,isLoading:u,isCreatingBranch:k,isFetching:L,isPulling:S,isPushing:R,isPublishing:z,isRevertingLocalCommit:Ce,operationError:_,onRefresh:A,onRevertLocalCommit:ke,onSwitchBranch:J,onCreateBranch:Q,onFetch:ie,onPull:ne,onPush:le,onPublish:D,onClearError:C,onRequestConfirmation:y}),p?.error?e.jsx(or,{error:p.error,details:p.details,canInitRepository:ce,isInitializingRepository:Y,initError:ce?_:null,onInitRepository:()=>{C(),q()}}):e.jsxs(e.Fragment,{children:[e.jsx(lr,{activeView:d,isHidden:m,changeCount:$e,onChange:i}),d==="changes"&&e.jsx(Gt,{isMobile:r,projectPath:t.fullPath,gitStatus:p,gitDiff:j,isLoading:u,wrapText:g,isCreatingInitialCommit:H,onWrapTextChange:x,onCreateInitialCommit:E,onOpenFile:U,onDiscardFile:K,onDeleteFile:G,onStageFiles:ve,onUnstageFiles:X,onCommitChanges:ge,onRequestConfirmation:y,onExpandedFilesChange:f},t.fullPath),d==="history"&&e.jsx(Qt,{isMobile:r,isLoading:u||M.length===0&&N,recentCommits:M,commitDiffs:w,wrapText:g,onFetchCommitDiff:pe}),d==="worktrees"&&e.jsx(nr,{isMobile:r,selectedProject:t,localBranches:I,onProjectSelect:a,onProjectsRefresh:o},t.fullPath),d==="branches"&&e.jsx(Kt,{isMobile:r,isLoading:u,currentBranch:h,localBranches:I,remoteBranches:B,remoteStatus:$,isCreatingBranch:k,onSwitchBranch:J,onCreateBranch:Q,onDeleteBranch:se,onRequestConfirmation:y})]}),e.jsx(cr,{action:v,onCancel:()=>y(null),onConfirm:de=>{Se(de)}})]}):e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:e.jsx("p",{children:"Select a project to view source control"})})}export{pr as default};
@@ -1,4 +1,4 @@
1
- import{_ as dp,z as Op,S as pp,w as mp,x as gp,r as Sp,q as bp,v as Qp,M as yp}from"./vendor-markdown-DkITEES2.js";import{r as ue,j as ge}from"./vendor-react-C2GTiUCy.js";import{M as xp}from"./feature-chat-CvOCyaLe.js";import{u as kp,g as wp}from"./feature-workspace-CAB6bgPy.js";let no=[],Gc=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?Gc:no).push(t=t+n[e])})();function vp(n){if(n<768)return!1;for(let e=0,t=no.length;;){let i=e+t>>1;if(n<no[i])t=i;else if(n>=Gc[i])e=i+1;else return!0;if(e==t)return!1}}function oa(n){return n>=127462&&n<=127487}const la=8205;function Pp(n,e,t=!0,i=!0){return(t?Uc:$p)(n,e,i)}function Uc(n,e,t){if(e==n.length)return e;e&&Fc(n.charCodeAt(e))&&Hc(n.charCodeAt(e-1))&&e--;let i=gr(n,e);for(e+=aa(i);e<n.length;){let s=gr(n,e);if(i==la||s==la||t&&vp(s))e+=aa(s),i=s;else if(oa(s)){let r=0,o=e-2;for(;o>=0&&oa(gr(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function $p(n,e,t){for(;e>0;){let i=Uc(n,e-2,t);if(i<e)return i;e--}return 0}function gr(n,e){let t=n.charCodeAt(e);if(!Hc(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Fc(i)?(t-55296<<10)+(i-56320)+65536:t}function Fc(n){return n>=56320&&n<57344}function Hc(n){return n>=55296&&n<56320}function aa(n){return n<65536?1:2}class W{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=gi(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),ot.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=gi(this,e,t);let i=[];return this.decompose(e,t,i,0),ot.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new Ji(this),r=new Ji(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new Ji(this,e)}iterRange(e,t=this.length){return new Kc(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Jc(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?W.empty:e.length<=32?new ne(e):ot.from(ne.split(e,[]))}}class ne extends W{constructor(e,t=Cp(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new Tp(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new ne(ha(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=us(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new ne(l,o.length+r.length));else{let a=l.length>>1;i.push(new ne(l.slice(0,a)),new ne(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof ne))return super.replace(e,t,i);[e,t]=gi(this,e,t);let s=us(this.text,us(i.text,ha(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new ne(s,r):ot.from(ne.split(s,[]),r)}sliceString(e,t=this.length,i=`
1
+ import{_ as dp,z as Op,S as pp,w as mp,x as gp,r as Sp,q as bp,v as Qp,M as yp}from"./vendor-markdown-DkITEES2.js";import{r as ue,j as ge}from"./vendor-react-C2GTiUCy.js";import{M as xp}from"./feature-chat-CHKsDTs-.js";import{u as kp,g as wp}from"./feature-workspace-BodovOw6.js";let no=[],Gc=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?Gc:no).push(t=t+n[e])})();function vp(n){if(n<768)return!1;for(let e=0,t=no.length;;){let i=e+t>>1;if(n<no[i])t=i;else if(n>=Gc[i])e=i+1;else return!0;if(e==t)return!1}}function oa(n){return n>=127462&&n<=127487}const la=8205;function Pp(n,e,t=!0,i=!0){return(t?Uc:$p)(n,e,i)}function Uc(n,e,t){if(e==n.length)return e;e&&Fc(n.charCodeAt(e))&&Hc(n.charCodeAt(e-1))&&e--;let i=gr(n,e);for(e+=aa(i);e<n.length;){let s=gr(n,e);if(i==la||s==la||t&&vp(s))e+=aa(s),i=s;else if(oa(s)){let r=0,o=e-2;for(;o>=0&&oa(gr(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function $p(n,e,t){for(;e>0;){let i=Uc(n,e-2,t);if(i<e)return i;e--}return 0}function gr(n,e){let t=n.charCodeAt(e);if(!Hc(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Fc(i)?(t-55296<<10)+(i-56320)+65536:t}function Fc(n){return n>=56320&&n<57344}function Hc(n){return n>=55296&&n<56320}function aa(n){return n<65536?1:2}class W{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=gi(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),ot.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=gi(this,e,t);let i=[];return this.decompose(e,t,i,0),ot.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new Ji(this),r=new Ji(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new Ji(this,e)}iterRange(e,t=this.length){return new Kc(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Jc(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?W.empty:e.length<=32?new ne(e):ot.from(ne.split(e,[]))}}class ne extends W{constructor(e,t=Cp(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new Tp(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new ne(ha(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=us(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new ne(l,o.length+r.length));else{let a=l.length>>1;i.push(new ne(l.slice(0,a)),new ne(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof ne))return super.replace(e,t,i);[e,t]=gi(this,e,t);let s=us(this.text,us(i.text,ha(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new ne(s,r):ot.from(ne.split(s,[]),r)}sliceString(e,t=this.length,i=`
2
2
  `){[e,t]=gi(this,e,t);let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new ne(i,s)),i=[],s=-1);return s>-1&&t.push(new ne(i,s)),t}}class ot extends W{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=gi(this,e,t),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[s]=a,new ot(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
3
3
  `){[e,t]=gi(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof ot))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let O of e)O.flatten(d);return new ne(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function f(d){let O;if(d.lines>r&&d instanceof ot)for(let m of d.children)f(m);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof ne&&a&&(O=c[c.length-1])instanceof ne&&d.lines+O.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new ne(O.text.concat(d.text),O.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:ot.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new ot(l,t)}}W.empty=new ne([""],0);function Cp(n){let e=-1;for(let t of n)e+=t.length+1;return e}function us(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function ha(n,e,t){return us(n,[""],e,t)}class Ji{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ne?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof ne?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
4
4
  `,this;e--}else if(s instanceof ne){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ne?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Kc{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new Ji(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Jc{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(W.prototype[Symbol.iterator]=function(){return this.iter()},Ji.prototype[Symbol.iterator]=Kc.prototype[Symbol.iterator]=Jc.prototype[Symbol.iterator]=function(){return this});let Tp=class{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}};function gi(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Qe(n,e,t=!0,i=!0){return Pp(n,e,t,i)}function Ap(n){return n>=56320&&n<57344}function Xp(n){return n>=55296&&n<56320}function Xe(n,e){let t=n.charCodeAt(e);if(!Xp(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Ap(i)?(t-55296<<10)+(i-56320)+65536:t}function cl(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function lt(n){return n<65536?1:2}const so=/\r\n?|\n/;var be=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(be||(be={}));class ut{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){ro(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new ut(e)}composeDesc(e){return this.empty?e:e.empty?this:ef(this,e)}mapDesc(e,t=!1){return e.empty?this:oo(this,e,t)}mapPos(e,t=-1,i=be.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=be.Simple&&h>=e&&(i==be.TrackDel&&s<e&&h>e||i==be.TrackBefore&&s<e||i==be.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ut(e)}static create(e){return new ut(e)}}class ce extends ut{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return ro(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return oo(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(W.empty);i.push(o?e.slice(r,r+o):W.empty)}r+=o}return new ce(t,i)}compose(e){return this.empty?e:e.empty?this:ef(this,e,!0)}map(e,t=!1){return e.empty?this:oo(this,e,t,!0)}iterChanges(e,t=!1){ro(this,e,t)}get desc(){return ut.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new an(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);ke(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;ke(t,c,f),f>0&&Xt(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);ke(t,c,-1),ke(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new ce(t,i),filtered:ut.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&ke(s,t-o,-1);let f=new ce(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof ce){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let O=d?typeof d=="string"?W.of(d.split(i||so)):d:W.empty,m=O.length;if(f==u&&m==0)return;f<o&&a(),f>o&&ke(s,f-o,-1),ke(s,u-f,m),Xt(r,s,O),o=u}}return h(e),a(!l),l}static empty(e){return new ce(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(W.empty);i[s]=W.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new ce(t,i)}static createSet(e,t){return new ce(e,t)}}function ke(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:s>=0&&e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function Xt(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(W.empty);n.push(t)}}function ro(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,f=W.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,f),s=h,r=c}}}function oo(n,e,t,i=!1){let s=[],r=i?[]:null,o=new an(n),l=new an(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);ke(s,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(ke(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(ke(s,0,o.ins),r&&Xt(r,s,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;ke(s,h,a<o.i?o.ins:0),r&&a<o.i&&Xt(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?ce.createSet(s,r):ut.create(s);throw new Error("Mismatched change set lengths")}}}function ef(n,e,t=!1){let i=[],s=t?[]:null,r=new an(n),o=new an(e);for(let l=!1;;){if(r.done&&o.done)return s?ce.createSet(i,s):ut.create(i);if(r.ins==0)ke(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)ke(i,0,o.ins,l),s&&Xt(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;ke(i,a,c,l),s&&c&&Xt(s,i,o.text)}else o.ins==-1?(ke(i,r.off?0:r.len,a,l),s&&Xt(s,i,r.textBit(a))):(ke(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&Xt(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class an{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?W.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?W.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class Gt{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new Gt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return Q.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return Q.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return Q.range(e.anchor,e.head)}static create(e,t,i){return new Gt(e,t,i)}}class Q{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:Q.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new Q([this.main],0)}addRange(e,t=!0){return Q.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,Q.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new Q(e.ranges.map(t=>Gt.fromJSON(t)),e.main)}static single(e,t=e){return new Q([Q.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return Q.normalized(e.slice(),t);i=r.to}return new Q(e,t)}static cursor(e,t=0,i,s){return Gt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return t<e?Gt.create(t,e,48|r):Gt.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?Q.range(a,l):Q.range(l,a))}}return new Q(e,t)}}function tf(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let fl=0;class A{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=fl++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new A(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:ul),!!e.static,e.enables)}of(e){return new ds([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ds(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ds(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function ul(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class ds{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=fl++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||lo(f,c)){let d=i(f);if(l?!ca(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,O=u.config.address[r];if(O!=null){let m=Ts(u,O);if(this.dependencies.every(g=>g instanceof A?u.facet(g)===f.facet(g):g instanceof Oe?u.field(g,!1)==f.field(g,!1):!0)||(l?ca(d=i(f),m,s):s(d=i(f),m)))return f.values[o]=m,0}else d=i(f);return f.values[o]=d,1}}}}function ca(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function lo(n,e){let t=!1;for(let i of e)en(n,i)&1&&(t=!0);return t}function Mp(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=Ts(a,i[c]);if(s[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)en(a,h);return a.values[o]=l(a),1},update(a,h){if(!lo(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=lo(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&ul(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Bn=A.define({static:!0});class Oe{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Oe(fl++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Bn).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>{let r=i.facet(Bn),o=s.facet(Bn),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,Bn.of({field:this,create:e})]}get extension(){return this}}const Wt={lowest:4,low:3,default:2,high:1,highest:0};function Yi(n){return e=>new nf(e,n)}const $t={highest:Yi(Wt.highest),high:Yi(Wt.high),default:Yi(Wt.default),low:Yi(Wt.low),lowest:Yi(Wt.lowest)};class nf{constructor(e,t){this.inner=e,this.prec=t}}class nr{of(e){return new ao(this,e)}reconfigure(e){return nr.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ao{constructor(e,t){this.compartment=e,this.inner=t}}class Cs{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let u of Zp(e,t,o))u instanceof Oe?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of s)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let c=i?.config.facets;for(let u in r){let d=r[u],O=d[0].facet,m=c&&c[u]||[];if(d.every(g=>g.type==0))if(l[O.id]=a.length<<1|1,ul(m,d))a.push(i.facet(O));else{let g=O.combine(d.map(S=>S.value));a.push(i&&O.compare(g,i.facet(O))?i.facet(O):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(S=>g.dynamicSlot(S)));l[O.id]=h.length<<1,h.push(g=>Mp(g,O,d))}}let f=h.map(u=>u(l));return new Cs(e,o,f,l,a,r)}}function Zp(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof ao&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof ao){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof nf)r(o.inner,o.prec);else if(o instanceof Oe)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof ds)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,Wt.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(h,l)}}return r(n,Wt.default),i.reduce((o,l)=>o.concat(l))}function en(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Ts(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const sf=A.define(),ho=A.define({combine:n=>n.some(e=>e),static:!0}),rf=A.define({combine:n=>n.length?n[0]:void 0,static:!0}),of=A.define(),lf=A.define(),af=A.define(),hf=A.define({combine:n=>n.length?n[0]:!1});class pt{constructor(e,t){this.type=e,this.value=t}static define(){return new Rp}}class Rp{of(e){return new pt(this,e)}}class qp{constructor(e){this.map=e}of(e){return new E(this,e)}}class E{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new E(this.type,t)}is(e){return this.type==e}static define(e={}){return new qp(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}E.reconfigure=E.define();E.appendConfig=E.define();class le{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&tf(i,t.newLength),r.some(l=>l.type==le.time)||(this.annotations=r.concat(le.time.of(Date.now())))}static create(e,t,i,s,r,o){return new le(e,t,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(le.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}le.time=pt.define();le.userEvent=pt.define();le.addToHistory=pt.define();le.remote=pt.define();function Lp(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function cf(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=ce.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:E.mapEffects(n.effects,s).concat(E.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function co(n,e,t){let i=e.selection,s=fi(e.annotations);return e.userEvent&&(s=s.concat(le.userEvent.of(e.userEvent))),{changes:e.changes instanceof ce?e.changes:ce.of(e.changes||[],t,n.facet(rf)),selection:i&&(i instanceof Q?i:Q.single(i.anchor,i.head)),effects:fi(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function ff(n,e,t){let i=co(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=cf(i,co(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=le.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Vp(t?Ep(s):s)}function Ep(n){let e=n.startState,t=!0;for(let s of e.facet(of)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:Lp(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=ce.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=le.create(e,s,n.selection&&n.selection.map(r),E.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(lf);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof le?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof le?n=r[0]:n=ff(e,fi(r),!1)}return n}function Vp(n){let e=n.startState,t=e.facet(af),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=cf(i,co(e,r,n.changes.newLength),!0))}return i==n?n:le.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const Yp=[];function fi(n){return n==null?Yp:Array.isArray(n)?n:[n]}var ie=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(ie||(ie={}));const Dp=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let fo;try{fo=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Bp(n){if(fo)return fo.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||Dp.test(t)))return!0}return!1}function _p(n){return e=>{if(!/\S/.test(e))return ie.Space;if(Bp(e))return ie.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return ie.Word;return ie.Other}}class z{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)en(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return en(this,i),Ts(this,i)}update(...e){return ff(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(nr.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,h)=>s.set(h,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(E.reconfigure)?(t=null,i=l.value):l.is(E.appendConfig)&&(t=null,i=fi(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=Cs.resolve(i,s,this),r=new z(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(ho)?e.newSelection:e.newSelection.asSingle();new z(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:Q.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=fi(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=s.mapDesc(h,!0);r.push(a.range.map(f)),s=s.compose(c),o=E.mapEffects(o,c).concat(E.mapEffects(fi(a.effects),f))}return{changes:s,selection:Q.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ce?e:ce.of(e,this.doc.length,this.facet(z.lineSeparator))}toText(e){return W.of(e.split(this.facet(z.lineSeparator)||so))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(en(this,t),Ts(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof Oe&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return z.create({doc:e.doc,selection:Q.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=Cs.resolve(e.extensions||[],new Map),i=e.doc instanceof W?e.doc:W.of((e.doc||"").split(t.staticFacet(z.lineSeparator)||so)),s=e.selection?e.selection instanceof Q?e.selection:Q.single(e.selection.anchor,e.selection.head):Q.single(0);return tf(s,i.length),t.staticFacet(ho)||(s=s.asSingle()),new z(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(z.tabSize)}get lineBreak(){return this.facet(z.lineSeparator)||`