tmex-cli 0.16.0 → 0.16.1

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 (72) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/runtime/server.js +24 -2
  3. package/package.json +1 -1
  4. package/resources/fe-dist/assets/DevicePage-Ccz8gNji.js +24 -0
  5. package/resources/fe-dist/assets/{DevicesPage-_SYGKgwy.js → DevicesPage-sJHXbS_f.js} +1 -1
  6. package/resources/fe-dist/assets/{FilePage-Blf_MlAq.js → FilePage-7FFd1YcW.js} +1 -1
  7. package/resources/fe-dist/assets/{SettingsPage-BRt22APt.js → SettingsPage-FrEtqZyI.js} +1 -1
  8. package/resources/fe-dist/assets/{agent-tab-DRkW6D0y.js → agent-tab-9THUj7Cf.js} +1 -1
  9. package/resources/fe-dist/assets/{api-C2-crTt8.js → api-DV7-9Pvt.js} +1 -1
  10. package/resources/fe-dist/assets/{arc-Bzi-2Wgo.js → arc-PDHKfnGP.js} +1 -1
  11. package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-DZYFrhja.js → architectureDiagram-3BPJPVTR-BiPHTh1e.js} +1 -1
  12. package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-lpc1A1G1.js → blockDiagram-GPEHLZMM-DP_BRHKg.js} +1 -1
  13. package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-DOc1BzPY.js → c4Diagram-AAUBKEIU-D16QYgyT.js} +1 -1
  14. package/resources/fe-dist/assets/{card-BA66zlg1.js → card-DmfNw0hd.js} +1 -1
  15. package/resources/fe-dist/assets/channel-Dzz9b4fW.js +1 -0
  16. package/resources/fe-dist/assets/{chunk-2J33WTMH-DqycjO3G.js → chunk-2J33WTMH-DOjtL7ww.js} +1 -1
  17. package/resources/fe-dist/assets/{chunk-4BX2VUAB-t2B-Cl6x.js → chunk-4BX2VUAB-BbT67ZXa.js} +1 -1
  18. package/resources/fe-dist/assets/{chunk-55IACEB6-BmFdQL7n.js → chunk-55IACEB6-CnnXwmY_.js} +1 -1
  19. package/resources/fe-dist/assets/{chunk-727SXJPM-DEa9FPer.js → chunk-727SXJPM-TyUdLEW5.js} +1 -1
  20. package/resources/fe-dist/assets/{chunk-AQP2D5EJ-DiZ9AoB9.js → chunk-AQP2D5EJ-BMpK4dqa.js} +1 -1
  21. package/resources/fe-dist/assets/{chunk-FMBD7UC4-DLcIMhi1.js → chunk-FMBD7UC4-Dx0HVCZZ.js} +1 -1
  22. package/resources/fe-dist/assets/{chunk-ND2GUHAM-Cu1P2Ot8.js → chunk-ND2GUHAM-BQCoMEti.js} +1 -1
  23. package/resources/fe-dist/assets/{chunk-QZHKN3VN-C8ki16q3.js → chunk-QZHKN3VN-ilmf5OgK.js} +1 -1
  24. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-BB9_4XLL.js +1 -0
  25. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-BB9_4XLL.js +1 -0
  26. package/resources/fe-dist/assets/{copy-C8vDYUVz.js → copy-Ct5TNzGp.js} +1 -1
  27. package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-baMBJteT.js → cose-bilkent-S5V4N54A-CpWhM7Za.js} +1 -1
  28. package/resources/fe-dist/assets/{dagre-BM42HDAG-CwWSiSwb.js → dagre-BM42HDAG-CWJttTzC.js} +1 -1
  29. package/resources/fe-dist/assets/{diagram-2AECGRRQ-CeSwouYZ.js → diagram-2AECGRRQ-BD8ny_Yg.js} +1 -1
  30. package/resources/fe-dist/assets/{diagram-5GNKFQAL-DgxdcMax.js → diagram-5GNKFQAL-CeHcPWRz.js} +1 -1
  31. package/resources/fe-dist/assets/{diagram-KO2AKTUF-DrglkRZC.js → diagram-KO2AKTUF-tVlrBE8C.js} +1 -1
  32. package/resources/fe-dist/assets/{diagram-LMA3HP47-BLHZ3p7v.js → diagram-LMA3HP47-DGUn-oQn.js} +1 -1
  33. package/resources/fe-dist/assets/{diagram-OG6HWLK6-_I_mMaa6.js → diagram-OG6HWLK6-xKCd1kwA.js} +1 -1
  34. package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-Zkbnn8Kh.js → erDiagram-TEJ5UH35-C6M5qkGl.js} +1 -1
  35. package/resources/fe-dist/assets/{files-tab-CPud4eIT.js → files-tab-BWkYfaye.js} +1 -1
  36. package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-BnV7dZI4.js → flowDiagram-I6XJVG4X-D0MZDHnB.js} +1 -1
  37. package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-Cn2f5kRI.js → ganttDiagram-6RSMTGT7-YeduSSa_.js} +1 -1
  38. package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-CEswG7nI.js → gitGraphDiagram-PVQCEYII-Nem1Mvvg.js} +1 -1
  39. package/resources/fe-dist/assets/{index-BK6c5W5S.js → index-B3ddLSja.js} +28 -28
  40. package/resources/fe-dist/assets/{index-DLyPliOu.js → index-iee3U_rD.js} +1 -1
  41. package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-Dsx1fQI9.js → infoDiagram-5YYISTIA-Bh6bbh_V.js} +1 -1
  42. package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-CgNMvXgO.js → ishikawaDiagram-YF4QCWOH-CsZHu48j.js} +1 -1
  43. package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-CVeui1xn.js → journeyDiagram-JHISSGLW-CPgnovXt.js} +1 -1
  44. package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-WnLUDsz4.js → kanban-definition-UN3LZRKU-D4OAuDsS.js} +1 -1
  45. package/resources/fe-dist/assets/{linear-B0SWPrkI.js → linear-CcA4wV7f.js} +1 -1
  46. package/resources/fe-dist/assets/{markdown-preview-CDjnYorp.js → markdown-preview-CBGlxpTs.js} +3 -3
  47. package/resources/fe-dist/assets/{mermaid.core-CXD-Pc2r.js → mermaid.core-D-CshtYr.js} +5 -5
  48. package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DYEXXmag.js → mindmap-definition-RKZ34NQL-DBpI1nMC.js} +1 -1
  49. package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-DkZtnbYj.js → pieDiagram-4H26LBE5-D4kh0_Y0.js} +1 -1
  50. package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-DblvGass.js → quadrantDiagram-W4KKPZXB-DNw3oGHQ.js} +1 -1
  51. package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-KAX1DxRY.js → requirementDiagram-4Y6WPE33-DqtMaND0.js} +1 -1
  52. package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-h9Z2LXNr.js → sankeyDiagram-5OEKKPKP-D-m9Pyie.js} +1 -1
  53. package/resources/fe-dist/assets/{send-BVxB0Ywb.js → send-DaOB9hLq.js} +1 -1
  54. package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-DUJcq5qX.js → sequenceDiagram-3UESZ5HK-CjrimNJf.js} +1 -1
  55. package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-BBT56nPD.js → stateDiagram-AJRCARHV-BT5d8Z8W.js} +1 -1
  56. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-kSh9IuUW.js +1 -0
  57. package/resources/fe-dist/assets/terminal-settings-panel-DDhlnbRH.js +25 -0
  58. package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-DLkgXxGG.js → timeline-definition-PNZ67QCA-BeocAFDX.js} +1 -1
  59. package/resources/fe-dist/assets/{transfer-toast-BYw9LLNi.js → transfer-toast-DXl4RHsV.js} +1 -1
  60. package/resources/fe-dist/assets/{triangle-alert-D4oQhgpz.js → triangle-alert-FQRTtbTP.js} +1 -1
  61. package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-CyUw7cRl.js → vennDiagram-CIIHVFJN-CYlmUB5_.js} +1 -1
  62. package/resources/fe-dist/assets/{wardley-L42UT6IY-UVd2D_HQ.js → wardley-L42UT6IY-CTyaodt9.js} +1 -1
  63. package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-B6As-5ml.js → wardleyDiagram-YWT4CUSO-DNlEcEwQ.js} +1 -1
  64. package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-DFypVaEh.js → xychartDiagram-2RQKCTM6-7Zi-6P-I.js} +1 -1
  65. package/resources/fe-dist/assets/{zap-DxVtkroR.js → zap-BFIAXPXd.js} +1 -1
  66. package/resources/fe-dist/index.html +1 -1
  67. package/resources/fe-dist/assets/DevicePage-CxCVolw8.js +0 -24
  68. package/resources/fe-dist/assets/channel-DFyg9jlp.js +0 -1
  69. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CAgGMVvn.js +0 -1
  70. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CAgGMVvn.js +0 -1
  71. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-wyzFZc_5.js +0 -1
  72. package/resources/fe-dist/assets/terminal-settings-panel-DHrIp0wf.js +0 -25
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ # 0.16.1
2
+
3
+ _2026-07-03_
4
+
5
+ ## English
6
+
7
+ ### Fixes
8
+
9
+ - Split screen pane overflow: deep-column panes no longer exceed their content area. Window row calculation now deducts the deepest vertical stack's title bar overhead.
10
+ - Mobile connect no longer shrinks the PC terminal window. Mobile select never carries size; resize/sync are skipped until snapshot arrives.
11
+ - PC and mobile no longer fight over terminal size. Remote resize snapshots no longer trigger local re-resize — last resizer wins.
12
+ - Split handle drag now uses the actual rendered cell CSS pixel size instead of tmux window cols, so dragging produces correct pane ratios even after the window was resized by another device. Both resize-window and resize-pane fire on pointerup, ensuring the pane resize executes in the correctly-sized window.
13
+
14
+ ---
15
+
16
+ ## 中文
17
+
18
+ ### 修复
19
+
20
+ - 分屏 pane 溢出:深列 pane 不再超出内容区域。整窗行数计算现在扣除最深垂直堆叠的标题栏占位。
21
+ - 手机连接不再缩小 PC 终端窗口。手机端 select 不携带尺寸;resize/sync 在快照到达前跳过。
22
+ - PC 与手机不再抢终端尺寸。远端 resize 快照不再触发本地重报——后操作者赢。
23
+ - 分隔条拖拽现在使用实际渲染 cell CSS 像素尺寸而非 tmux window cols,即使窗口被其他设备 resize 过,拖拽也能产生正确的 pane 比例。pointerup 时同时发 resize-window 和 resize-pane,确保 pane resize 在正确尺寸的 window 中执行。
24
+
25
+ ---
26
+
1
27
  # 0.16.0
2
28
 
3
29
  _2026-07-02_
@@ -107248,8 +107248,8 @@ function getBaseVersion() {
107248
107248
  if (cachedBase !== undefined)
107249
107249
  return cachedBase;
107250
107250
  let base = null;
107251
- if ("0.16.0") {
107252
- base = "0.16.0";
107251
+ if ("0.16.1") {
107252
+ base = "0.16.1";
107253
107253
  }
107254
107254
  if (!base && config.isProd) {
107255
107255
  base = readInstallMeta()?.cliVersion ?? null;
@@ -110282,6 +110282,15 @@ class SwitchBarrier {
110282
110282
  this.completeTransaction(ws, deviceId);
110283
110283
  pending.callbacks.onLiveResumed?.();
110284
110284
  }
110285
+ getTransactionPaneId(ws, deviceId) {
110286
+ const pending = this.getPending(ws, deviceId);
110287
+ if (!pending)
110288
+ return null;
110289
+ const selectState = sessionStateStore.getOrCreateSelectTransaction(ws, deviceId)?.state;
110290
+ if (selectState !== "ACKED")
110291
+ return null;
110292
+ return pending.context.paneId;
110293
+ }
110285
110294
  getSelectToken(ws, deviceId) {
110286
110295
  return this.getPending(ws, deviceId)?.context.selectToken ?? null;
110287
110296
  }
@@ -110963,6 +110972,14 @@ class WebSocketServer {
110963
110972
  const entry = this.connections.get(deviceId);
110964
110973
  if (!entry)
110965
110974
  return;
110975
+ const snapshot = entry.lastSnapshot;
110976
+ if (snapshot?.session?.windows) {
110977
+ const window2 = snapshot.session.windows.find((w) => w.panes && w.panes.some((p) => p.id === paneId));
110978
+ if (window2 && window2.panes && window2.panes.length > 1) {
110979
+ entry.runtime.resizeWindow(window2.id, cols, rows);
110980
+ return;
110981
+ }
110982
+ }
110966
110983
  entry.runtime.resizePane(paneId, cols, rows);
110967
110984
  }
110968
110985
  handleTermPaste(deviceId, paneId, data) {
@@ -111354,6 +111371,11 @@ class WebSocketServer {
111354
111371
  const historyBytes = new TextEncoder().encode(data);
111355
111372
  const fetchKey = `${deviceId}:${paneId}`;
111356
111373
  for (const client of entry.clients) {
111374
+ const txPaneId = switchBarrier.getTransactionPaneId(client, deviceId);
111375
+ if (txPaneId !== null && txPaneId === paneId) {
111376
+ switchBarrier.sendTermHistory(client, deviceId, paneId, historyBytes, alternateScreen);
111377
+ continue;
111378
+ }
111357
111379
  if (client.data.borshState.selectedPanes[deviceId] === paneId) {
111358
111380
  switchBarrier.sendTermHistory(client, deviceId, paneId, historyBytes, alternateScreen);
111359
111381
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmex-cli",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tmex": "./bin/tmex.js",
@@ -0,0 +1,24 @@
1
+ import{Y as Ye,u as Ie,j as i,aD as Tt,aE as Ct,aF as jt,aG as Nt,aH as Mt,at as Pt,r as n,d as O,af as pe,ai as ut,ah as dt,ag as kt,aj as It,aI as Lt,aJ as At,o as ke,aK as _t,D as zt,p as Dt,q as $t,s as Bt,aL as tt,aw as ft,b as ht,aM as nt,aN as Ft,c as rt,aC as mt,aO as je,aP as Wt,ay as Ht,aq as Ke,y as Ot,a2 as Xt,B as Ce,T as qt,aQ as Yt,aR as Ut,aS as Vt,aT as Kt,aU as Gt,$ as Qt,aV as Jt,A as Zt,f as en,g as tn,i as nn,k as rn,l as sn,m as on,n as cn}from"./index-B3ddLSja.js";import{T as an,C as ln,c as un,F as dn,a as wt,R as fn,A as hn,f as mn,t as wn,S as pn}from"./terminal-settings-panel-DDhlnbRH.js";import{e as gn}from"./selection-clipboard-D3gUQQ7L.js";import{C as xn}from"./copy-Ct5TNzGp.js";import{S as ct,K as vn}from"./send-DaOB9hLq.js";const bn=/^[0-9a-fA-F]{4}$/;function Sn(t){if(typeof t!="string"||t.length<6)return null;const e=t.slice(0,4);if(!bn.test(e)||t[4]!==",")return null;const s={input:t,pos:5},c=pt(s);return!c||s.pos!==t.length?null:{checksum:e,root:c}}function De(t){const e=t.pos;for(;t.pos<t.input.length;){const s=t.input.charCodeAt(t.pos);if(s<48||s>57)break;t.pos+=1}return t.pos===e?null:Number.parseInt(t.input.slice(e,t.pos),10)}function $e(t,e){return t.input[t.pos]!==e?!1:(t.pos+=1,!0)}function pt(t){const e=De(t);if(e===null||!$e(t,"x"))return null;const s=De(t);if(s===null||!$e(t,","))return null;const c=De(t);if(c===null||!$e(t,","))return null;const l=De(t);if(l===null)return null;const p=t.input[t.pos];if(p===","){t.pos+=1;const v=De(t);return v===null?null:{type:"leaf",paneNumId:v,width:e,height:s,x:c,y:l}}if(p==="{"||p==="["){const v=p==="{"?"}":"]";t.pos+=1;const b=[];for(;;){const R=pt(t);if(!R)return null;if(b.push(R),!$e(t,",")){if($e(t,v))break;return null}}return b.length<2?null:{type:p==="{"?"row":"column",width:e,height:s,x:c,y:l,children:b}}return null}function Ge(t){return`%${t.paneNumId}`}/**
2
+ * @license lucide-react v0.564.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const yn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],En=Ye("columns-2",yn);/**
7
+ * @license lucide-react v0.564.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Rn=[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],Tn=Ye("search-x",Rn);/**
12
+ * @license lucide-react v0.564.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Cn=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],jn=Ye("settings-2",Cn);/**
17
+ * @license lucide-react v0.564.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Nn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Mn=Ye("smartphone",Nn);function Pn({open:t,onOpenChange:e}){const{t:s}=Ie();return i.jsx(Tt,{open:t,onOpenChange:e,children:i.jsxs(Ct,{side:"bottom",className:"max-h-[88dvh] overflow-y-auto pb-[var(--tmex-safe-area-bottom)] sm:mx-auto sm:max-w-md sm:rounded-t-2xl sm:border sm:border-b-0","data-testid":"keyboard-behavior-sheet",children:[i.jsxs(jt,{children:[i.jsx(Nt,{children:s("settings.terminal.title")}),i.jsx(Mt,{children:s("settings.terminal.savedInBrowser")})]}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx(an,{})})]})})}function kn({visible:t,canPaste:e,onCopy:s,onPaste:c,onDismiss:l}){const{t:p}=Ie();if(!t)return null;const v=b=>{b.preventDefault()};return i.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[i.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:s,"data-testid":"terminal-selection-copy",children:[i.jsx(xn,{className:"h-4 w-4"}),p("terminal.copy")]}),e&&i.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:c,"data-testid":"terminal-selection-paste",children:[i.jsx(ln,{className:"h-4 w-4"}),p("terminal.paste")]}),i.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:l,"aria-label":p("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:i.jsx(Pt,{className:"h-4 w-4"})})]})}function gt(t){if(!t)return t;const e=t.replace(/\r\n/g,`
22
+ `);return(e.endsWith(`
23
+ `)?e.slice(0,-1):e).replace(/\n/g,`\r
24
+ `)}const In="\x1B[?1049h\x1B[H\x1B[2J";function Ln(t){return In+gt(t)}function An(t,e){let s=e,c=0;for(const b of t)b===10&&!s&&(c+=1),s=b===13;const l=s;if(c===0)return{normalized:t,endedWithCR:l};const p=new Uint8Array(t.length+c);let v=0;s=e;for(const b of t)b===10&&!s&&(p[v]=13,v+=1),p[v]=b,v+=1,s=b===13;return{normalized:p,endedWithCR:l}}const _n=1.3,zn=36,Dn=500,$n=12;function Bn(t,e){const s=n.useRef(!1);return n.useEffect(()=>{const c=t.current;if(!c||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;s.current=!0;let p=0,v=null,b=!1,R=0,B=0,$=0,T=null,U=!1;const r=()=>{T!==null&&(clearTimeout(T),T=null)},ae=S=>S?!!(S.closest(".scrollbar")||S.closest(".slider")||S.closest(".xterm-scroll-area")):!1,V=(S,h,M)=>{const W=M instanceof Element?M:null;if(ae(W))return!0;const A=document.elementFromPoint(S,h);if(ae(A))return!0;const H=c.querySelector(".xterm");if(!(H instanceof HTMLElement))return!1;const u=H.getBoundingClientRect(),N=S>=u.left&&S<=u.right,X=h>=u.top&&h<=u.bottom;return!N||!X?!1:S>=u.right-zn},C=()=>[c.querySelector(".xterm-viewport"),c.querySelector(".xterm-scrollable-element")].filter(h=>h instanceof HTMLElement),le=S=>{if(v===null)return null;for(let h=0;h<S.length;h+=1){const M=S.item(h);if(M&&M.identifier===v)return M}return null},se=S=>{if(r(),S.touches.length!==1)return;const h=S.touches.item(0);h&&(v=h.identifier,p=h.clientY,R=0,b=V(h.clientX,h.clientY,S.target),B=h.clientX,$=h.clientY,U=!1,b||(T=setTimeout(()=>{var W;T=null;const M=(e==null?void 0:e())??null;(W=M==null?void 0:M.startTouchSelection)!=null&&W.call(M,B,$,"word")&&(U=!0)},Dn)))},de=S=>{var N,X,J,I,Y,te,me,fe,we;const h=le(S.touches)??S.touches.item(0);if(!h)return;if(U){const _=(e==null?void 0:e())??null;(N=_==null?void 0:_.updateTouchSelection)==null||N.call(_,h.clientX,h.clientY),S.cancelable&&S.preventDefault();return}if(T!==null&&Math.hypot(h.clientX-B,h.clientY-$)>$n&&r(),b||(b=V(h.clientX,h.clientY,S.target),b&&(R=0)),b)return;const M=h.clientY,W=p-M;if(p=M,W===0)return;let A=!1,H=!1;const u=(e==null?void 0:e())??null;if(u){const _=u==null?void 0:u._core,Q=((Y=(I=(J=(X=_==null?void 0:_._renderService)==null?void 0:X.dimensions)==null?void 0:J.css)==null?void 0:I.cell)==null?void 0:Y.height)??18;R+=W*_n;const Z=R>0?Math.floor(R/Q):Math.ceil(R/Q);if(typeof u.handleViewportGesture=="function")Z!==0&&(A=u.handleViewportGesture({source:"touch",deltaY:Z*Q,clientX:h.clientX,clientY:h.clientY}),R-=Z*Q);else if(Z!==0){const j=((me=(te=u.buffer)==null?void 0:te.active)==null?void 0:me.viewportY)??0;u.scrollLines(Z);const a=((we=(fe=u.buffer)==null?void 0:fe.active)==null?void 0:we.viewportY)??0;A=j!==a,H=Z<0&&j<=0&&a<=0,R-=Z*Q}}else{const _=C();if(_.length===0)return;for(const Q of _){const Z=Q.scrollTop;Q.scrollTop+=W;const j=Q.scrollTop;Math.abs(j-Z)>0&&(A=!0),W<0&&j<=0&&(H=!0)}if(!A){const Q=c.querySelector(".xterm");if(Q instanceof HTMLElement){const Z=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:W}),j=Q.dispatchEvent(Z);A=Z.defaultPrevented||!j}}}S.cancelable&&(A||H)&&S.preventDefault()},re=S=>{var M;if(r(),!(v===null||!le(S.changedTouches))&&(v=null,R=0,b=!1,U)){U=!1;const W=(e==null?void 0:e())??null;(M=W==null?void 0:W.endTouchSelection)==null||M.call(W)}},f=S=>{U&&S.preventDefault()};return c.addEventListener("touchstart",se,{passive:!0}),c.addEventListener("touchmove",de,{passive:!1}),c.addEventListener("touchend",re,{passive:!0}),c.addEventListener("touchcancel",re,{passive:!0}),c.addEventListener("contextmenu",f),()=>{s.current=!1,r(),c.removeEventListener("touchstart",se),c.removeEventListener("touchmove",de),c.removeEventListener("touchend",re),c.removeEventListener("touchcancel",re),c.removeEventListener("contextmenu",f)}},[t,e]),s}function Fn({now:t,remoteSize:e,pendingLocalSize:s,ttlMs:c=2e3}){return!s||t-s.at>c?!0:s.cols===e.cols&&s.rows===e.rows}function Wn({currentSize:t,containerSize:e,force:s=!1}){return s?!0:t.cols!==e.cols||t.rows!==e.rows}function Hn({deviceId:t,paneId:e,deviceConnected:s,isSelectionInvalid:c,sizingMode:l="report",onResize:p,onSync:v,getContainerRect:b}){const R=n.useRef(null),B=n.useRef(null),$=n.useRef(null),T=n.useRef(null),U=n.useRef(0),r=n.useRef([]),ae=n.useRef(null),V=n.useRef(null),C=n.useRef(b),le=n.useRef(!1),se=n.useRef(p),de=n.useRef(v);n.useEffect(()=>{se.current=p},[p]),n.useEffect(()=>{de.current=v},[v]),n.useEffect(()=>{C.current=b},[b]);const re=n.useCallback(()=>{var me,fe,we,_,Q,Z,j,a,m,E;const u=V.current,N=ae.current;if(!u||!N||!u.element)return null;let X;try{const y=N.proposeDimensions();if(!y)throw new Error("fitAddon.proposeDimensions() returned null");X=Math.max(2,y.cols)}catch{const y=u._core,q=((_=(we=(fe=(me=y==null?void 0:y._renderService)==null?void 0:me.dimensions)==null?void 0:fe.css)==null?void 0:we.cell)==null?void 0:_.width)??9,oe=(Q=C.current)==null?void 0:Q.call(C);if(!oe||oe.width===0)return null;X=Math.max(2,Math.floor(oe.width/q))}const J=(Z=C.current)==null?void 0:Z.call(C);if(!J||J.height===0)return null;const I=u._core,Y=((E=(m=(a=(j=I==null?void 0:I._renderService)==null?void 0:j.dimensions)==null?void 0:a.css)==null?void 0:m.cell)==null?void 0:E.height)??17,te=Math.max(2,Math.floor(J.height/Y));return{cols:X,rows:te}},[]),f=n.useCallback((u,N)=>{const X=V.current;X&&(X.cols===u&&X.rows===N||X.resize(u,N))},[]),S=n.useCallback((u,N=!1)=>{if(l==="follow"||!t||!e||!s||c&&u!=="sync"||!N&&Date.now()<U.current||!V.current)return!1;const J=re();if(!J)return!1;const{cols:I,rows:Y}=J,te=$.current;return!N&&te&&te.cols===I&&te.rows===Y?(f(I,Y),!0):(f(I,Y),u==="sync"?de.current(I,Y):se.current(I,Y),$.current={cols:I,rows:Y},T.current={cols:I,rows:Y,at:Date.now()},!0)},[f,s,t,c,re,e,l]),h=n.useCallback((u="resize",N={})=>{const{immediate:X=!1,force:J=!1}=N;B.current!==null&&(window.clearTimeout(B.current),B.current=null),R.current!==null&&(cancelAnimationFrame(R.current),R.current=null);const I=()=>{R.current=requestAnimationFrame(()=>{R.current=null,S(u,J)})};if(X){I();return}B.current=window.setTimeout(()=>{B.current=null,I()},150)},[S]),M=n.useCallback(()=>{for(const u of r.current)window.clearTimeout(u);r.current=[]},[]),W=n.useCallback(()=>{var N;M(),h("sync",{immediate:!0,force:!0});const u=window.setTimeout(()=>{h("sync",{immediate:!0,force:!0})},60);r.current.push(u),typeof document<"u"&&"fonts"in document&&((N=document.fonts)!=null&&N.ready)&&document.fonts.ready.then(()=>{h("sync",{immediate:!0,force:!0})}).catch(()=>{})},[M,h]);n.useEffect(()=>{let u=null;const N=()=>{u!==null&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{u=null,h("resize")})};return window.addEventListener("resize",N),()=>{window.removeEventListener("resize",N),u!==null&&cancelAnimationFrame(u)}},[h]),n.useEffect(()=>{const u=()=>{var me;const I=V.current,Y=re();if(!I||!Y)return;if(!Wn({currentSize:{cols:Math.max(2,I.cols),rows:Math.max(2,I.rows)},containerSize:Y})){(me=I.forceFullRepaint)==null||me.call(I);return}h("sync",{force:!0})},N=()=>{if(document.visibilityState!=="visible"){le.current=!0;return}le.current&&(le.current=!1,u())},X=()=>{le.current=!0},J=()=>{le.current&&(le.current=!1,u())};return document.addEventListener("visibilitychange",N),window.addEventListener("blur",X),window.addEventListener("focus",J),()=>{document.removeEventListener("visibilitychange",N),window.removeEventListener("blur",X),window.removeEventListener("focus",J)}},[re,h]),n.useEffect(()=>()=>{M(),B.current!==null&&window.clearTimeout(B.current),R.current!==null&&cancelAnimationFrame(R.current)},[M]);const A=n.useCallback(u=>{ae.current=u},[]),H=n.useCallback(u=>{V.current=u},[]);return{scheduleResize:h,runPostSelectResize:W,clearPostSelectResizeTimers:M,setFitAddon:A,setTerminal:H,lastReportedSize:$,pendingLocalSize:T,suppressLocalResizeUntil:U}}const On=1e4,Je="tmex:terminal-mode-cache";function Xn(t,e){try{const s=sessionStorage.getItem(Je);return s?JSON.parse(s)[`${t}:${e}`]??null:null}catch{return null}}function qn(t,e,s){try{const c=sessionStorage.getItem(Je),l=c?JSON.parse(c):{},p=`${t}:${e}`;s?l[p]=s:delete l[p],sessionStorage.setItem(Je,JSON.stringify(l))}catch{}}function Yn(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function Un(t,e){if(!e)return t?{...t,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const s=Yn();if(!t)return s;const c=t.mouseNormal||t.mouseButton||t.mouseAny;return{...t,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:c?t.mouseNormal:s.mouseNormal}}function Vn(t){var s;const e=globalThis;e.__tmexE2eXterm=t,e.__tmexE2eTerminal=t,e.__tmexE2eTerminalEngine=wt,e.__tmexE2eTerminalRenderer=((s=t.getRendererKind)==null?void 0:s.call(t))??null}function Kn(t){if(!t)return;const e=globalThis;e.__tmexE2eTerminal!==t&&e.__tmexE2eXterm!==t||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const st=n.forwardRef(({deviceId:t,paneId:e,theme:s,inputMode:c,deviceConnected:l,isSelectionInvalid:p,sizingMode:v="report",autoFocus:b=!0,focused:R=!0,onResize:B,onSync:$,children:T},U)=>{const[r,ae]=n.useState(null),[V,C]=n.useState(!1),le=O(d=>d.sendInput),se=pe(d=>d.terminalFontId),de=pe(d=>d.terminalFontSize),re=pe(d=>d.terminalLineHeight),{t:f}=Ie(),S=n.useMemo(()=>{switch(s){case"light":return dt;default:return ut}},[s]),h=n.useRef(null),M=n.useRef(null),W=n.useRef(null),A=n.useRef(t),H=n.useRef(e),u=n.useRef(t),N=n.useRef(e),X=n.useRef(l&&!p),J=n.useRef(c),I=n.useRef(S),Y=n.useRef(!1),te=n.useRef(!1),me=n.useRef(null),fe=n.useRef(!1),we=n.useCallback((d,x,L)=>{!(d!=null&&d.exportModeSnapshot)||!x||!L||qn(x,L,d.exportModeSnapshot())},[]),_=n.useCallback(()=>r,[r]);Bn(h,_),n.useEffect(()=>{A.current=t,H.current=e,te.current=!1},[t,e]),n.useEffect(()=>{X.current=l&&!p},[l,p]),n.useEffect(()=>{J.current=c},[c]),n.useEffect(()=>{I.current=S},[S]);const Q=n.useCallback(d=>{if(!d||c!=="direct"||!X.current)return;const x=A.current,L=H.current;!x||!L||le(x,L,d,!1)},[c,le]),{pendingLocalSize:Z,scheduleResize:j,runPostSelectResize:a,setFitAddon:m,setTerminal:E}=Hn({deviceId:t,paneId:e,deviceConnected:l,isSelectionInvalid:p,sizingMode:v,onResize:B,onSync:$,getContainerRect:()=>{const d=h.current;if(!d)return null;const x=d.getBoundingClientRect();return{width:x.width,height:x.height}}});n.useEffect(()=>{let d=!1,x=null;return(async()=>{if(await kt(se,de),d)return;const L=await un({fontFamily:It(se),fontSize:de,lineHeight:re,scrollback:On,theme:I.current,disableStdin:J.current==="editor"});if(d){L.dispose();return}x=L,M.current&&L.open(M.current),ae(L)})(),()=>{d=!0,ae(null),Kn(x),x==null||x.dispose()}},[se,de,re]),n.useEffect(()=>{!r||!b||Vn(r)},[r,b]),n.useEffect(()=>{var d;(d=r==null?void 0:r.setFocused)==null||d.call(r,R)},[r,R]),n.useEffect(()=>{!r||!("setTheme"in r)||r.setTheme(S)},[r,S]),n.useEffect(()=>{!r||!("setDisableStdin"in r)||r.setDisableStdin(c==="editor")},[r,c]),n.useEffect(()=>{if(!(r!=null&&r.getCursorViewportRect))return;const d=()=>{var x;return((x=r.getCursorViewportRect)==null?void 0:x.call(r))??null};return _t(d),()=>Lt(d)},[r]),n.useEffect(()=>{!r||c!=="direct"||!b||window.innerWidth<768||"ontouchstart"in window||r.focus()},[r,c,b]);const y=n.useMemo(()=>r?{onReset:()=>{we(r,u.current,N.current),fe.current=!0,r.reset(),Y.current=!1,a()},onApplyHistory:(d,x)=>{var P,ie;const L=Un(Xn(A.current,H.current),x);L&&((P=r.restoreModeSnapshot)==null||P.call(r,L));const z=x?Ln(d):gt(d);te.current=!0,r.write(z),(ie=r.forceFullRepaint)==null||ie.call(r),fe.current=!1,u.current=A.current,N.current=H.current,we(r,A.current,H.current)},onOutput:d=>{const x=An(d,Y.current);Y.current=x.endedWithCR,r.write(x.normalized),te.current&&(r.buffer.active.baseY<=1&&r.scrollToTop(),te.current=!1),u.current=A.current,N.current=H.current,we(r,A.current,H.current)}}:null,[r,we,a]);n.useEffect(()=>{r?me.current!==r&&(Y.current=!1,u.current=A.current,N.current=H.current,me.current=r):me.current=null},[r]),n.useEffect(()=>{if(!(!r||!t||!e))return()=>{if(fe.current){fe.current=!1;return}we(r,u.current,N.current)}},[t,r,e,we]),n.useEffect(()=>{if(!(!y||!t||!e))return At(t,e,y)},[y,t,e]),n.useEffect(()=>{if(!r){W.current=null,m(null),E(null);return}const d=new dn;return r.loadAddon(d),W.current=d,m(d),E(r),a(),()=>{try{d.dispose()}finally{W.current=null,m(null),E(null)}}},[r,a,m,E]),n.useEffect(()=>{const d=h.current;if(!d)return;let x=null;const L=new ResizeObserver(()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,j("resize")})});return L.observe(d),()=>{L.disconnect(),x!==null&&cancelAnimationFrame(x)}},[j]),n.useEffect(()=>{if(!r||!t||!e)return;const d=r.onData(x=>{!l||p||Q(x)});return r.attachCustomKeyEventHandler(x=>!l||p||x.type!=="keydown"||c!=="direct"?!0:x.shiftKey&&x.key==="Enter"?(x.preventDefault(),Q("\x1B[13;2u"),!1):!0),()=>{d.dispose(),r.attachCustomKeyEventHandler(()=>!0)}},[r,l,p,c,Q,t,e]),n.useEffect(()=>{if(!(r!=null&&r.onLinkActivated))return;const d=r.onLinkActivated(x=>{window.open(x,"_blank","noopener,noreferrer")});return()=>d.dispose()},[r]),n.useEffect(()=>{if(!(r!=null&&r.onSelectionChange)){C(!1);return}const d=r.onSelectionChange(x=>{C(!!x)});return()=>{d.dispose(),C(!1)}},[r]);const q=n.useCallback(()=>{var x;if(!r)return;const d=((x=r.getSelection)==null?void 0:x.call(r))??"";d&&gn(d).then(()=>{ke.success(f("terminal.copied"))}).catch(()=>{ke.error(f("terminal.copyFailed"))}).finally(()=>{var L;(L=r.clearSelection)==null||L.call(r),r.focus()})},[r,f]),oe=n.useCallback(()=>{var x;if(!r)return;((x=navigator.clipboard)!=null&&x.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(L=>{var z;L&&r.paste(L),(z=r.clearSelection)==null||z.call(r),r.focus()}).catch(()=>{ke.error(f("terminal.pasteFailed"))})},[r,f]),he=n.useCallback(()=>{var d;(d=r==null?void 0:r.clearSelection)==null||d.call(r),r==null||r.focus()},[r]);return n.useImperativeHandle(U,()=>({write:d=>r==null?void 0:r.write(d),reset:()=>{r==null||r.reset(),Y.current=!1},scrollToBottom:()=>r==null?void 0:r.scrollToBottom(),resize:(d,x)=>r==null?void 0:r.resize(d,x),getTerminal:()=>r??null,getSize:()=>r?{cols:Math.max(2,r.cols),rows:Math.max(2,r.rows)}:null,runPostSelectResize:()=>a(),scheduleResize:(d,x)=>j(d,x),calculateSizeFromContainer:()=>{var ge,F,ee,D,K,G,ce,ye,Ee,xe,Pe,Le,_e,ue,Ae,Ne;const d=h.current,x=r,L=W.current;if(!d||!x)return null;const z=d.getBoundingClientRect();if(z.width===0||z.height===0)return null;const P=x._core;let ie;if(L)try{const Te=L.proposeDimensions();if(Te)ie=Math.max(2,Te.cols);else{const Fe=((D=(ee=(F=(ge=P==null?void 0:P._renderService)==null?void 0:ge.dimensions)==null?void 0:F.css)==null?void 0:ee.cell)==null?void 0:D.width)??9;ie=Math.max(2,Math.floor(z.width/Fe))}}catch{const Te=((ye=(ce=(G=(K=P==null?void 0:P._renderService)==null?void 0:K.dimensions)==null?void 0:G.css)==null?void 0:ce.cell)==null?void 0:ye.width)??9;ie=Math.max(2,Math.floor(z.width/Te))}else{const Te=((Le=(Pe=(xe=(Ee=P==null?void 0:P._renderService)==null?void 0:Ee.dimensions)==null?void 0:xe.css)==null?void 0:Pe.cell)==null?void 0:Le.width)??9;ie=Math.max(2,Math.floor(z.width/Te))}const Re=((Ne=(Ae=(ue=(_e=P==null?void 0:P._renderService)==null?void 0:_e.dimensions)==null?void 0:ue.css)==null?void 0:Ae.cell)==null?void 0:Ne.height)??17,Se=Math.max(2,Math.floor(z.height/Re));return{cols:ie,rows:Se}},getPendingLocalSize:()=>Z.current,getCellSize:()=>{var L,z,P;const d=r==null?void 0:r._core,x=(P=(z=(L=d==null?void 0:d._renderService)==null?void 0:L.dimensions)==null?void 0:z.css)==null?void 0:P.cell;return!(x!=null&&x.width)||!(x!=null&&x.height)?null:{width:x.width,height:x.height}}}),[r,Z,a,j]),i.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:S.background},"data-terminal-engine":wt,children:[i.jsxs("div",{ref:h,className:"relative min-h-0 w-full flex-1",children:[i.jsx("div",{ref:M,className:"absolute inset-0"}),i.jsx(kn,{visible:V,canPaste:c==="direct"&&l&&!p,onCopy:q,onPaste:oe,onDismiss:he})]}),T]})});st.displayName="Terminal";function Gn({window:t,currentPaneId:e,onSelectPane:s}){const{t:c}=Ie();return i.jsxs(zt,{children:[i.jsxs(Dt,{"data-testid":"pane-switcher-button","aria-label":c("window.switchPane"),title:c("window.switchPane"),className:"relative inline-flex size-7 items-center justify-center rounded-[min(var(--radius-md),12px)] text-sm hover:bg-muted hover:text-foreground data-popup-open:bg-muted",children:[i.jsx(En,{className:"h-4 w-4"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-primary px-0.5 text-[9px] font-medium leading-none text-primary-foreground",children:t.panes.length})]}),i.jsx($t,{align:"end",backdrop:!0,className:"min-w-56 max-w-[80vw]","data-testid":"pane-switcher-menu",children:t.panes.map(l=>{const p=l.id===e;return i.jsxs(Bt,{"data-testid":"pane-switcher-item","data-pane-id":l.id,className:`py-2 [@media(any-pointer:coarse)]:py-2.5 ${p?"bg-primary/10 text-primary":l.active?"bg-accent text-accent-foreground":""}`,onClick:()=>{p||s(l.id)},children:[i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"font-mono text-[11px] leading-tight font-medium line-clamp-2 [overflow-wrap:break-word]",children:l.customName||l.title||c("window.pane")}),l.currentCommand&&i.jsx("span",{className:"font-mono text-[10.5px] leading-tight text-muted-foreground line-clamp-1 break-all",children:l.currentPath?`${l.currentCommand}@${l.currentPath}`:l.currentCommand})]}),p&&i.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]},l.id)})})]})}const We=2;function He(t){if(t.type==="leaf")return We;if(t.type==="row"){let s=t.children.length-1;for(const c of t.children)s+=He(c);return s}let e=We;for(const s of t.children)e=Math.max(e,He(s));return e}function Oe(t){if(t.type==="leaf")return We;if(t.type==="column"){let s=t.children.length-1;for(const c of t.children)s+=Oe(c);return s}let e=We;for(const s of t.children)e=Math.max(e,Oe(s));return e}function Ze(t){return t.type==="leaf"?t:t.type==="row"?Ze(t.children[t.children.length-1]):Ze(t.children[0])}function et(t){return t.type==="leaf"?t:t.type==="column"?et(t.children[t.children.length-1]):et(t.children[0])}function Qn(t,e){const s=[],c=[],l=p=>{if(p.type==="leaf"){s.push({paneId:Ge(p),cols:p.width,rows:p.height,rect:{left:p.x*e.width,top:p.y*e.height,width:p.width*e.width,height:p.height*e.height}});return}for(let v=0;v<p.children.length;v+=1){const b=p.children[v];if(l(b),v===p.children.length-1)continue;const R=p.children[v+1];if(p.type==="row"){const B=Ze(b);c.push({axis:"x",rect:{left:(b.x+b.width)*e.width,top:p.y*e.height,width:e.width,height:p.height*e.height},edgeLeafPaneId:Ge(B),edgeLeafSizeCells:B.width,minDeltaCells:-(b.width-He(b)),maxDeltaCells:R.width-He(R)})}else{const B=et(b);c.push({axis:"y",rect:{left:p.x*e.width,top:(b.y+b.height)*e.height,width:p.width*e.width,height:e.height},edgeLeafPaneId:Ge(B),edgeLeafSizeCells:B.height,minDeltaCells:-(b.height-Oe(b)),maxDeltaCells:R.height-Oe(R)})}}};return l(t),{panes:s,gutters:c}}function Xe(t){if(t.type==="leaf")return 1;if(t.type==="column"){let s=0;for(const c of t.children)s+=Xe(c);return s}let e=1;for(const s of t.children)e=Math.max(e,Xe(s));return e}function qe(t){if(t.type==="leaf")return 1;if(t.type==="row"){let s=0;for(const c of t.children)s+=qe(c);return s}let e=1;for(const s of t.children)e=Math.max(e,qe(s));return e}function Jn(t,e){const s=Xe(t),c=qe(t),l=Math.max(0,e.viewport.width-c*e.paneChrome.width),p=Math.max(0,e.viewport.height-s*e.paneChrome.height),v=Math.max(2,Math.floor(l/e.cell.width)),b=Math.max(2,Math.floor(p/e.cell.height));return{cols:v,rows:b}}function Zn(t,e){const s=Math.min(1,Math.max(0,t)),c=Math.min(1,Math.max(0,e)),l=[["left",s],["right",1-s],["top",c],["bottom",1-c]];return l.sort((p,v)=>p[1]-v[1]),l[0][0]}const at=150,er=200,tr=15,nr=46,rr=38,sr=12,or=6;function lt(t){var e,s;return((e=t==null?void 0:t.customName)==null?void 0:e.trim())||((s=t==null?void 0:t.title)==null?void 0:s.trim())||"Pane"}function ir(t){var c,l;const e=(c=t==null?void 0:t.currentCommand)==null?void 0:c.trim();if(!e)return null;const s=(l=t==null?void 0:t.currentPath)==null?void 0:l.trim();return s?`${e}@${s}`:e}const cr={left:"left-0 top-0 bottom-0 w-1/2",right:"right-0 top-0 bottom-0 w-1/2",top:"left-0 right-0 top-0 h-1/2",bottom:"left-0 right-0 bottom-0 h-1/2"};function ar({deviceId:t,window:e,focusedPaneId:s,theme:c,inputMode:l,deviceConnected:p,focusedTerminalRef:v,onUserSelectPane:b,onWindowResize:R}){var Q,Z,j;const B=n.useRef(null),$=n.useRef(new Map),[T,U]=n.useState(null),[r,ae]=n.useState(null),{t:V}=Ie(),C=O(a=>a.subscribePanes),le=O(a=>a.fetchPaneHistory),se=O(a=>a.resizePaneInWindow),de=O(a=>a.movePane),re=O(a=>a.breakPane),f=O(a=>a.closePane),S=n.useMemo(()=>{const a=new Map;for(const m of e.panes)a.set(m.id,m);return a},[e.panes]),h=n.useMemo(()=>e.layout?Sn(e.layout):null,[e.layout]),M=n.useMemo(()=>h?Qn(h.root,{width:1,height:1}):null,[h]),W=n.useRef(M);W.current=M;const A=(h==null?void 0:h.root.width)??1,H=(h==null?void 0:h.root.height)??1,u=e.panes.map(a=>a.id).join(",");n.useEffect(()=>(C(t,u?u.split(","):[]),()=>{C(t,[])}),[t,u,C]);const N=n.useRef({key:"",fetched:new Set});n.useEffect(()=>{const a=`${t}:${e.id}`;N.current.key!==a&&(N.current={key:a,fetched:new Set});for(const m of u?u.split(","):[])N.current.fetched.has(m)||m!==s&&(N.current.fetched.add(m),le(t,m))},[t,e.id,u,s,le]),n.useEffect(()=>{var m,E;l!=="direct"||window.innerWidth<768||"ontouchstart"in window||(E=(m=$.current.get(s))==null?void 0:m.getTerminal())==null||E.focus()},[s,l]);const X=n.useCallback(()=>{var a;for(const m of[s,...$.current.keys()]){const E=(a=$.current.get(m))==null?void 0:a.getCellSize();if(E)return E}return null},[s]);n.useEffect(()=>{var a;if(M)for(const m of M.panes)(a=$.current.get(m.paneId))==null||a.resize(m.cols,m.rows)},[M]);const J=n.useMemo(()=>h?Xe(h.root):1,[h]),I=n.useMemo(()=>h?qe(h.root):1,[h]),Y=n.useCallback(()=>{const a=B.current;if(!a||!h)return!1;const m=a.getBoundingClientRect();if(m.width<1||m.height<1)return!1;const E=X();if(!E)return!1;const{cols:y,rows:q}=Jn(h.root,{viewport:{width:m.width,height:m.height},cell:E,paneChrome:{width:sr,height:nr}});return R(y,q),!0},[X,h,R]),te=n.useRef(Y);n.useEffect(()=>{te.current=Y},[Y]),n.useEffect(()=>{const a=B.current;if(!a)return;let m=null,E=null,y=0;const q=()=>{if(te.current()){y=0;return}y<tr&&(y+=1,E=setTimeout(q,er))},oe=new ResizeObserver(()=>{m&&clearTimeout(m),m=setTimeout(q,at)});return oe.observe(a),()=>{oe.disconnect(),m&&clearTimeout(m),E&&clearTimeout(E)}},[]),n.useEffect(()=>{const a=setTimeout(()=>{te.current()},at);return()=>clearTimeout(a)},[J,I]);const me=n.useCallback((a,m,E)=>{E.preventDefault();const y=B.current;if(!y)return;const q=E.clientX,oe=E.clientY,he=E.currentTarget;he.setPointerCapture(E.pointerId),U({gutterIndex:a,deltaPx:0});const d=P=>{const ie=m.axis==="x"?P.clientX-q:P.clientY-oe;U({gutterIndex:a,deltaPx:ie})},x=(P,ie)=>{if(he.removeEventListener("pointermove",d),he.removeEventListener("pointerup",L),he.removeEventListener("pointercancel",z),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",z),U(null),!ie)return;const Re=X();if(!Re)return;const Se=m.axis==="x"?P.clientX-q:P.clientY-oe,ge=m.axis==="x"?Re.width:Re.height;if(ge<=0)return;const F=Math.round(Se/ge);if(F===0)return;const ee=y.querySelector(`[data-pane-id="${m.edgeLeafPaneId}"]`);if(!ee)return;const D=ee.getBoundingClientRect(),G=(m.axis==="x"?Math.floor(D.width/ge):Math.floor(D.height/ge))+F;G<2||(te.current(),se(t,m.edgeLeafPaneId,m.axis==="x"?{cols:G}:{rows:G}))},L=P=>x(P,!0),z=P=>x(P,!1);he.addEventListener("pointermove",d),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",z)},[t,X,se]),fe=n.useCallback((a,m)=>{const E=B.current,y=M;if(!E||!y)return;m.preventDefault();const q=m.clientX,oe=m.clientY,he=m.currentTarget;he.setPointerCapture(m.pointerId);let d=!1;const x=(F,ee)=>{const D=E.getBoundingClientRect();if(D.width<1||D.height<1)return null;const K=(F-D.left)/D.width*Math.max(1,A),G=(ee-D.top)/D.height*Math.max(1,H);for(const ce of y.panes)if(K>=ce.rect.left&&K<=ce.rect.left+ce.rect.width&&G>=ce.rect.top&&G<=ce.rect.top+ce.rect.height){const ye=(K-ce.rect.left)/Math.max(1e-6,ce.rect.width),Ee=(G-ce.rect.top)/Math.max(1e-6,ce.rect.height);return{paneId:ce.paneId,position:Zn(ye,Ee)}}return null},L=(F,ee,D)=>F>=D.left&&F<=D.right&&ee>=D.top&&ee<=D.bottom,z=(F,ee)=>{for(const D of Array.from(document.querySelectorAll('[data-testid^="window-item-"]'))){const K=D.getBoundingClientRect();if(K.width<1||!L(F,ee,K))continue;const G=(D.getAttribute("data-testid")??"").replace("window-item-","");return!G||G===e.id?null:{type:"window",windowId:G,rect:{left:K.left,top:K.top,width:K.width,height:K.height}}}for(const D of Array.from(document.querySelectorAll('[data-slot="sidebar"]'))){const K=D.getBoundingClientRect();if(!(K.width<1||!L(F,ee,K)))return{type:"break",rect:{left:K.left,top:K.top,width:K.width,height:K.height}}}return null},P=(F,ee)=>{const D=x(F,ee);return D?D.paneId===a?null:{type:"pane",...D}:z(F,ee)},ie=F=>{const ee=Math.hypot(F.clientX-q,F.clientY-oe);!d&&ee<or||(d=!0,ae({srcPaneId:a,active:!0,pointerX:F.clientX,pointerY:F.clientY,target:P(F.clientX,F.clientY)}))},Re=(F,ee)=>{var K,G;if(he.removeEventListener("pointermove",ie),he.removeEventListener("pointerup",Se),he.removeEventListener("pointercancel",ge),window.removeEventListener("pointerup",Se),window.removeEventListener("pointercancel",ge),ae(null),!ee||!d)return;const D=P(F.clientX,F.clientY);if(D){if(D.type==="pane"){de(t,a,D.paneId,D.position);return}if(D.type==="window"){const ce=(G=(K=O.getState().snapshots[t])==null?void 0:K.session)==null?void 0:G.windows,ye=ce==null?void 0:ce.find(xe=>xe.id===D.windowId),Ee=(ye==null?void 0:ye.panes.find(xe=>xe.active))??(ye==null?void 0:ye.panes[0]);Ee&&de(t,a,Ee.id,"right");return}re(t,a)}},Se=F=>Re(F,!0),ge=F=>Re(F,!1);he.addEventListener("pointermove",ie),window.addEventListener("pointerup",Se),window.addEventListener("pointercancel",ge)},[t,M,de,re,A,H,e.id]),we=n.useCallback(a=>m=>{var E;if(m){$.current.set(a,m);const y=(E=W.current)==null?void 0:E.panes.find(q=>q.paneId===a);y&&m.resize(y.cols,y.rows)}else $.current.delete(a);a===s&&v(m)},[s,v]);if(n.useEffect(()=>{v($.current.get(s)??null)},[s,v]),!M)return null;const _=(a,m)=>`${a/Math.max(1,m)*100}%`;return i.jsxs("div",{ref:B,className:"relative h-full w-full min-h-0 min-w-0","data-testid":"split-terminal-area",children:[M.panes.map(a=>{var he;const m=a.paneId===s,E=S.get(a.paneId),y=ir(E),q=(r==null?void 0:r.active)&&r.srcPaneId===a.paneId,oe=r!=null&&r.active&&((he=r.target)==null?void 0:he.type)==="pane"&&r.target.paneId===a.paneId?r.target.position:null;return i.jsxs("div",{className:`absolute flex flex-col overflow-hidden ${q?"opacity-60":""}`,"data-testid":"split-pane","data-pane-id":a.paneId,"data-focused":m||void 0,style:{left:_(a.rect.left,A),top:_(a.rect.top,H),width:_(a.rect.width,A),height:_(a.rect.height,H)},onPointerDownCapture:()=>{m||b(e.id,a.paneId)},children:[i.jsx("div",{className:"shrink-0 px-1.5 pt-1.5 pb-2",style:{height:rr},children:i.jsxs("div",{"data-testid":"split-pane-titlebar","data-active":m||void 0,className:`flex h-6 cursor-grab touch-none select-none items-center gap-1.5 rounded-md px-2.5 transition-colors active:cursor-grabbing ${m?"bg-foreground/10":"bg-foreground/[0.04]"}`,onPointerDown:d=>fe(a.paneId,d),children:[i.jsx("span",{className:`shrink-0 truncate font-mono text-[10.5px] leading-none ${m?"text-foreground/90":"text-foreground/50"}`,children:lt(E)}),y&&i.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[10px] leading-none ${m?"text-muted-foreground":"text-muted-foreground/60"}`,children:y}),i.jsx("button",{type:"button","data-testid":`split-pane-close-${a.paneId}`,"aria-label":V("window.closePane"),title:V("window.closePane"),className:"ml-auto flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/50 hover:bg-foreground/10 hover:text-foreground",onPointerDown:d=>d.stopPropagation(),onClick:d=>{d.stopPropagation(),f(t,a.paneId)},children:i.jsx("span",{className:"text-xs leading-none",children:"×"})})]})}),i.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden px-1.5 pb-2","data-pane-content-id":a.paneId,children:i.jsx(st,{ref:we(a.paneId),deviceId:t,paneId:a.paneId,theme:c,inputMode:l,deviceConnected:p,isSelectionInvalid:!1,sizingMode:"follow",autoFocus:m,focused:m,onResize:()=>{},onSync:()=>{}},`${t}:${a.paneId}`)}),oe&&i.jsx("div",{"data-testid":"split-pane-drop-preview","data-position":oe,className:`pointer-events-none absolute z-30 rounded-sm bg-primary/20 ring-1 ring-inset ring-primary/60 ${cr[oe]}`})]},a.paneId)}),(T!==null||(r==null?void 0:r.active))&&i.jsx("div",{"data-testid":"split-drag-shield",className:`absolute inset-0 z-30 ${T!==null?((Q=M.gutters[T.gutterIndex])==null?void 0:Q.axis)==="x"?"cursor-col-resize":"cursor-row-resize":"cursor-grabbing"}`}),(r==null?void 0:r.active)&&r.target&&r.target.type!=="pane"&&i.jsx("div",{"data-testid":"split-pane-sidebar-drop","data-drop-type":r.target.type,className:"pointer-events-none fixed z-40 rounded-lg bg-primary/15 ring-1 ring-inset ring-primary/50",style:{left:r.target.rect.left,top:r.target.rect.top,width:r.target.rect.width,height:r.target.rect.height}}),(r==null?void 0:r.active)&&i.jsxs("div",{className:"pointer-events-none fixed z-50 rounded border border-primary/40 bg-popover/95 px-2 py-1 font-mono text-[10.5px] text-popover-foreground shadow-md",style:{left:r.pointerX+12,top:r.pointerY+12},children:[i.jsx("div",{children:lt(S.get(r.srcPaneId))}),((Z=r.target)==null?void 0:Z.type)==="window"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:V("window.moveToWindow")}),((j=r.target)==null?void 0:j.type)==="break"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:V("window.breakToWindow")})]}),M.gutters.map((a,m)=>{const E=a.axis==="x",y=(T==null?void 0:T.gutterIndex)===m;return i.jsxs("div",{className:"absolute z-20",style:{left:_(a.rect.left,A),top:_(a.rect.top,H),width:_(E?1:a.rect.width,A),height:_(E?a.rect.height:1,H)},children:[i.jsx("div",{"data-testid":"split-gutter","data-axis":a.axis,className:`absolute touch-none select-none ${E?"-inset-x-1 inset-y-0 cursor-col-resize":"inset-x-0 -inset-y-1 cursor-row-resize"}`,onPointerDown:q=>me(m,a,q),children:i.jsx("div",{className:`absolute bg-foreground/[0.08] transition-colors hover:bg-primary/50 ${E?"inset-y-0 left-1/2 w-px -translate-x-1/2":"inset-x-0 top-1/2 h-px -translate-y-1/2"} ${y?"bg-primary":""}`})}),y&&T&&i.jsx("div",{className:"pointer-events-none absolute bg-primary/70",style:E?{top:0,bottom:0,width:2,left:`calc(50% + ${T.deltaPx}px)`}:{left:0,right:0,height:2,top:`calc(50% + ${T.deltaPx}px)`}})]},`${e.layout??""}:${m}`)})]})}const lr=1200,ur=2e3;function Me(t,e){return!t||!e?!1:t.windowId===e.windowId&&t.paneId===e.paneId}function xt(t,e){const s=t.filter(c=>e-c.at<lr);return s.length===0?null:s.reduce((c,l)=>l.at>c.at?l:c)}function Be(t,e=Date.now()){return!t||e-t.at>ur?null:t}function dr(t){const e=t.now??Date.now(),s=xt(t.recentSelectRequests,e),c=p=>!!(p&&p.paneId===t.activePaneFromEvent.paneId&&p.windowId!==t.activePaneFromEvent.windowId);if(s&&!Me(s,t.activePaneFromEvent)&&!c(s)||Me(t.currentRoute,t.activePaneFromEvent)||Me(t.lastHandledActive,t.activePaneFromEvent))return!0;const l=Be(t.pendingUserSelection,e);return!!(l&&!Me(l,t.activePaneFromEvent)&&!c(l))}function fr(t){const e=t.now??Date.now(),s=xt(t.recentSelectRequests,e),c=Be(t.pendingUserSelection,e);return!!(c&&!Me(c,t.snapshotActive)||s&&!Me(s,t.snapshotActive))}function hr(t){const e=t.now??Date.now(),s=Be(t.pendingUserSelection,e);return!(s&&Me(s,t.routeTarget)||t.snapshotActive&&Me(t.snapshotActive,t.routeTarget))}const Qe=n.memo(function({onActivate:e,disabled:s}){const{data:c}=rt({queryKey:wn,queryFn:mn,staleTime:6e4}),l=(c==null?void 0:c.items)??[];return l.length===0?null:i.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:i.jsx(pn,{items:l,useIcons:(c==null?void 0:c.useIcons)??!1,onActivate:e,disabled:s,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function vr(){var it;const{t}=Ie(),{deviceId:e,windowId:s,paneId:c}=tt(),l=ft(),p=n.useRef(null),v=n.useRef(null),b=n.useRef(null),R=n.useRef(null),B=n.useRef(!1),$=n.useRef(!1),T=n.useRef(null),U=O(o=>o.selectPane),r=O(o=>o.focusPane),ae=O(o=>e?o.snapshots[e]:void 0),V=O(o=>{var g;return e?(g=o.deviceErrors)==null?void 0:g[e]:void 0}),C=O(o=>{var g;return e?((g=o.deviceConnected)==null?void 0:g[e])??!1:!1}),se=!!O(o=>{var g;return e?(g=o.deviceReconnecting)==null?void 0:g[e]:void 0}),de=O(o=>e?o.connectedDevices.has(e):!1),re=ht(o=>{var g;return((g=o.settings)==null?void 0:g.siteName)??"tmex"}),f=n.useMemo(()=>nt(c),[c]),S=n.useMemo(()=>e&&f?`${e}:${f}`:null,[e,f]),[h,M]=n.useState(!1),W=n.useRef(!1);n.useEffect(()=>{W.current=h},[h]);const[A,H]=n.useState(""),u=n.useRef(!1),N=!C||!f,[X,J]=n.useState(!1),I=pe(o=>o.inputMode),Y=pe(o=>o.theme),te=pe(o=>o.editorSendWithEnter),me=pe(o=>o.setEditorSendWithEnter),fe=pe(o=>o.addEditorHistory),we=pe(o=>o.setEditorDraft),_=pe(o=>o.removeEditorDraft),Q=pe(o=>S?o.editorDrafts[S]??"":""),Z=n.useMemo(()=>Ft(),[]),j=(it=ae==null?void 0:ae.session)==null?void 0:it.windows,a=Y==="light"?dt:ut,{data:m}=rt({queryKey:["devices"],queryFn:async()=>{const o=await fetch("/api/devices");if(!o.ok)throw new Error("Failed to fetch devices");return o.json()},throwOnError:!1}),E=n.useMemo(()=>{if(e)return m==null?void 0:m.devices.find(o=>o.id===e)},[e,m==null?void 0:m.devices]),y=n.useMemo(()=>{if(!(!s||!j))return j.find(o=>o.id===s)},[s,j]),q=n.useMemo(()=>{if(!(!f||!y))return y.panes.find(o=>o.id===f)},[f,y]),oe=!!j,x=oe&&!!s&&!y?t("terminal.windowClosed"):oe&&!!s&&!!f&&!!y&&!q?t("terminal.paneClosed"):null,L=!!x,z=!!(C&&f&&!L),P=!!(!h&&y&&y.panes.length>1&&y.layout&&!L),ie=n.useRef(P);n.useEffect(()=>{ie.current=P},[P]);const Re=n.useMemo(()=>{if(!y||!q)return null;const o=(E==null?void 0:E.name)??e;return mt({paneCustomName:q.customName,paneTitle:q.title,windowName:y.name,windowCustomName:y.customName,deviceName:o})},[E==null?void 0:E.name,e,q,y]),Se=n.useMemo(()=>{if(!j||j.length===0)return null;const o=j.find(w=>w.active),g=o==null?void 0:o.panes.find(w=>w.active);return!o||!g?null:{windowId:o.id,paneId:g.id}},[j]),ge=h&&y&&y.panes.length>1?y.id:null,F=n.useRef(ge);n.useEffect(()=>{F.current=ge},[ge]);const ee=n.useRef(!1);n.useEffect(()=>{ee.current=!!j&&!!s},[j,s]);const D=n.useCallback((o,g)=>{if(!e||!f)return;const w=F.current;if(w){O.getState().applyStackedLayout(e,w,o,g);return}W.current&&!ee.current||O.getState().resizePane(e,f,o,g)},[e,f]),K=n.useCallback((o,g)=>{if(!e||!f)return;const w=F.current;if(w){O.getState().applyStackedLayout(e,w,o,g);return}W.current&&!ee.current||O.getState().syncPaneSize(e,f,o,g)},[e,f]),G=n.useCallback((o,g)=>{var ze;const w=R.current;if(ie.current){const be=(ze=p.current)==null?void 0:ze.getBoundingClientRect(),Ve=w==null?void 0:w.getCellSize();return be&&Ve&&be.width>0&&be.height>0?{cols:Math.max(2,Math.floor(be.width/Ve.width)),rows:Math.max(2,Math.floor(be.height/Ve.height))}:void 0}if(W.current)return;const k=(w==null?void 0:w.calculateSizeFromContainer())??(w==null?void 0:w.getSize())??void 0;if(k)return k;if(!o||!g||!j)return;const ne=j.find(be=>be.id===o),ve=ne==null?void 0:ne.panes.find(be=>be.id===g);if(!(!ve||ve.width<=1||ve.height<=1))return{cols:ve.width,rows:ve.height}},[j]),ce=n.useCallback((o,g)=>{e&&(T.current={windowId:o,paneId:g,at:Date.now()},l(`/devices/${e}/windows/${o}/panes/${je(g)}`,{replace:!0}))},[e,l]),ye=n.useCallback(o=>{R.current=o},[]);n.useEffect(()=>{const o=()=>{M(window.innerWidth<768||"ontouchstart"in window)};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),n.useEffect(()=>{if(!h||!Z||$.current)return;$.current=!0;const o=()=>{window.scrollTo(0,1)},g=window.requestAnimationFrame(o),w=window.setTimeout(o,120),k=window.setTimeout(o,420);return()=>{window.cancelAnimationFrame(g),window.clearTimeout(w),window.clearTimeout(k)}},[Z,h]),n.useEffect(()=>{e&&(B.current=!1,Ae.current=null,Ne.current=null,T.current=null,Ee.current=[])},[e]),n.useEffect(()=>{C||(B.current=!1)},[C]),n.useEffect(()=>{if(!e||!C||!s||!j)return;if(j.length===0){l("/devices",{replace:!0});return}const o=j.find(w=>w.id===s);if(!o)return;if(!f){const w=o.panes.find(k=>k.active)??o.panes[0];w&&l(`/devices/${e}/windows/${s}/panes/${je(w.id)}`,{replace:!0});return}if(!o.panes.find(w=>w.id===f)){const w=j.find(ne=>ne.panes.some(ve=>ve.id===f));if(w){l(`/devices/${e}/windows/${w.id}/panes/${je(f)}`,{replace:!0});return}const k=o.panes.find(ne=>ne.active)??o.panes[0];k&&l(`/devices/${e}/windows/${s}/panes/${je(k.id)}`,{replace:!0});return}},[e,C,j,s,f,l]),n.useEffect(()=>{if(!e||!C||!j||j.length===0||s&&f||B.current)return;const o=j.find(w=>w.active)??j[0],g=o.panes.find(w=>w.active)??o.panes[0];g&&(B.current=!0,l(`/devices/${e}/windows/${o.id}/panes/${je(g.id)}`,{replace:!0}))},[C,e,l,f,s,j]);const Ee=n.useRef([]),xe=n.useCallback((o,g)=>{const w=Date.now(),k=[...Ee.current.filter(ne=>w-ne.at<2e3),{windowId:o,paneId:g,at:w}];Ee.current=k.slice(-8)},[]),Pe=n.useRef(null);n.useEffect(()=>{Pe.current=null},[e,f]);const Le=n.useRef(null),_e=n.useRef(P);n.useEffect(()=>{_e.current!==P&&(_e.current=P,Pe.current=null,Le.current=null)},[P]),n.useEffect(()=>{if(!e||!s||!f||N||!C)return;const o=`${e}:${s}:${f}`;if(Pe.current===o)return;Pe.current=o;const g=P&&Le.current===`${e}:${s}`&&!!(y!=null&&y.panes.some(k=>k.id===f));if(xe(s,f),g){r(e,s,f);return}const w=G(s,f);U(e,s,f,w),Le.current=`${e}:${s}`},[C,e,r,G,N,P,xe,f,U,y,s]),n.useEffect(()=>{if(!e||!C||!s||!f)return;const o={windowId:s,paneId:f};hr({routeTarget:o,snapshotActive:Se,pendingUserSelection:T.current})&&(T.current={windowId:o.windowId,paneId:o.paneId,at:Date.now()})},[C,e,f,Se,s]);const ue=O(o=>e?o.activePaneFromEvent[e]:void 0),Ae=n.useRef(null);n.useEffect(()=>{if(!e||!C||!s||!f||!ue)return;const o=Date.now(),g=Be(T.current,o);if(T.current=g,dr({now:o,pendingUserSelection:g,activePaneFromEvent:ue,currentRoute:{windowId:s,paneId:f},recentSelectRequests:Ee.current,lastHandledActive:Ae.current}))return;if(Ae.current={...ue},g&&g.windowId===ue.windowId&&g.paneId===ue.paneId&&(T.current=null),!(ie.current&&ue.windowId===s)){const k=G(ue.windowId,ue.paneId);xe(ue.windowId,ue.paneId),U(e,ue.windowId,ue.paneId,k)}l(`/devices/${e}/windows/${ue.windowId}/panes/${je(ue.paneId)}`,{replace:!0})},[e,C,s,f,ue,xe,G,U,l]);const Ne=n.useRef(null);n.useEffect(()=>{if(!e||!C||!j||j.length===0)return;const o=Ee.current,g=j.find(be=>be.active);if(!g)return;const w=g.panes.find(be=>be.active);if(!w)return;const k={windowId:g.id,paneId:w.id},ne=Date.now(),ve=Be(T.current,ne);if(T.current=ve,fr({now:ne,pendingUserSelection:ve,snapshotActive:k,recentSelectRequests:o})||Ne.current&&Ne.current.windowId===k.windowId&&Ne.current.paneId===k.paneId||(Ne.current={...k},ve&&ve.windowId===k.windowId&&ve.paneId===k.paneId&&(T.current=null),s===k.windowId&&f===k.paneId))return;if(!(ie.current&&k.windowId===s)){const be=G(k.windowId,k.paneId);xe(k.windowId,k.paneId),U(e,k.windowId,k.paneId,be)}l(`/devices/${e}/windows/${k.windowId}/panes/${je(k.paneId)}`,{replace:!0})},[e,C,j,s,f,xe,G,U,l]);const Te=O(o=>e?o.pendingCreateWindowAt[e]:void 0);n.useEffect(()=>{if(!e||!C||!Te)return;const o=5e3,g=Date.now()-Te;if(g>o){O.getState().clearPendingCreateWindow(e);return}if(!Se){const ne=window.setTimeout(()=>{O.getState().clearPendingCreateWindow(e)},o-g);return()=>window.clearTimeout(ne)}const w=Se;if(s===w.windowId&&f===w.paneId){const ne=window.setTimeout(()=>{O.getState().clearPendingCreateWindow(e)},o-g);return()=>window.clearTimeout(ne)}T.current={windowId:w.windowId,paneId:w.paneId,at:Date.now()};const k=G(w.windowId,w.paneId);xe(w.windowId,w.paneId),U(e,w.windowId,w.paneId,k),l(`/devices/${e}/windows/${w.windowId}/panes/${je(w.paneId)}`,{replace:!0}),O.getState().clearPendingCreateWindow(e)},[e,C,Te,Se,s,f,xe,G,U,l]),n.useEffect(()=>{if(P||!z||!q||N)return;const o=R.current,g=o==null?void 0:o.getTerminal();if(!g)return;const w=Math.max(2,Math.floor(q.width||0)),k=Math.max(2,Math.floor(q.height||0));if(!w||!k)return;const ne=Date.now(),ve={cols:w,rows:k},ze=(o==null?void 0:o.getPendingLocalSize())??null;Fn({now:ne,remoteSize:ve,pendingLocalSize:ze})&&(g.cols===w&&g.rows===k||g.resize(w,k))},[z,N,P,q]),n.useEffect(()=>{const o=window.requestAnimationFrame(()=>{var w;(w=R.current)==null||w.scrollToBottom()}),g=window.setTimeout(()=>{var w;(w=R.current)==null||w.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(o),window.clearTimeout(g)}},[I]),n.useEffect(()=>{V!=null&&V.message&&ke.error(V.message)},[V==null?void 0:V.message]),n.useEffect(()=>(document.title=Wt(Re),()=>{document.title=re}),[re,Re]),n.useEffect(()=>{const o=()=>{var g;(g=R.current)==null||g.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",o),()=>{window.removeEventListener("tmex:jump-to-latest",o)}},[]),n.useEffect(()=>{const o=g=>{const{deviceId:w,windowId:k,paneId:ne}=g.detail;w===e&&(T.current={windowId:k,paneId:ne,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",o),()=>{window.removeEventListener("tmex:user-initiated-selection",o)}},[e]),n.useEffect(()=>{H(Q)},[Q]);const Fe=n.useCallback(o=>{if(!e||!f||!z)return;O.getState().sendInput(e,f,o,!1)},[z,e,f]),Ue=n.useCallback(o=>{var g,w;if(o.type==="action"){if(o.action==="toggleKeyboard"){pe.getState().setInputMode(I==="direct"?"editor":"direct");return}if(o.action==="scrollToBottom"){(g=R.current)==null||g.scrollToBottom();return}}if(o.type==="send"){o.payload&&Fe(o.payload);return}if(!(!e||!f||!z))switch(o.action){case"paste":{((w=navigator.clipboard)!=null&&w.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(ne=>{ne&&O.getState().paste(e,f,ne)}).catch(()=>ke.error(t("terminal.pasteFailed")));break}case"newAgentSession":Ht.getState().startDraft(e,f,null),pe.getState().setSidebarCollapsed(!1),pe.getState().setSidebarTab("agent");break}},[z,e,Fe,I,f,t]),vt=n.useCallback(()=>{if(!z){ke.error(t("wsError.checkGateway"));return}if(!e||!f||!A.trim())return;J(!0),window.setTimeout(()=>J(!1),150);const o=te?`${A}\r`:A;O.getState().sendInput(e,f,o,!1),fe(A),S&&_(S),H("")},[fe,z,e,S,te,A,_,f,t]),bt=n.useCallback(()=>{if(!z){ke.error(t("wsError.checkGateway"));return}if(!e||!f||!A.trim())return;J(!0),window.setTimeout(()=>J(!1),150);const o=A.split(/\r?\n/),g=O.getState();for(const w of o)w.trim()&&g.sendInput(e,f,`${w}\r`,!1);fe(A),S&&_(S),H("")},[fe,z,e,S,A,_,f,t]),St=n.useCallback(()=>{var o;(o=b.current)==null||o.focus({preventScroll:!0})},[]);if(!e)return i.jsx("div",{className:"flex h-full items-center justify-center p-4",children:i.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:t("device.noDevices")})});const yt=!!f&&!L&&(C||se),Et=C&&!!f&&!L&&!q,Rt=de&&!C&&!V&&!se,ot=i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Ke,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("terminal.connecting")})]});return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[i.jsx("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${h&&I==="editor"?"pb-1":""}`,children:i.jsxs("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:a.background},children:[L?i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm space-y-4",children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Tn,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:x})]})}):yt&&f?P&&y?i.jsxs("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col","data-virtual-keyboard-avoid":!0,children:[i.jsx("div",{ref:p,className:"relative min-h-0 flex-1",children:i.jsx(ar,{deviceId:e,window:y,focusedPaneId:f,theme:Y,inputMode:I,deviceConnected:C,focusedTerminalRef:ye,onUserSelectPane:ce,onWindowResize:D},`${e}:${y.id}`)}),I==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:i.jsx(Qe,{onActivate:Ue,disabled:!z})})]}):i.jsx("div",{ref:p,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:i.jsx(st,{ref:R,deviceId:e,paneId:f,theme:Y,inputMode:I,deviceConnected:C,isSelectionInvalid:L,onResize:D,onSync:K,children:I==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:i.jsx(Qe,{onActivate:Ue,disabled:!z})})},`${e}:${f}`)}):i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsx("div",{className:"max-w-sm space-y-4",children:Rt?ot:!C&&!se?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("device.disconnected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("device.connectToStart")})]}):s?ot:i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("window.noWindowSelected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("window.selectWindowToStart")})]})})}),se&&i.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center","data-testid":"terminal-reconnecting-indicator",children:i.jsx(Ot,{deviceId:e,className:"shadow-sm"})}),Et&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:i.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[i.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),i.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:t("terminal.connecting")})]})})]})}),I==="editor"&&i.jsxs("div",{ref:v,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[h&&i.jsx(Qe,{onActivate:o=>{Ue(o),o.type==="send"&&St()},disabled:!z}),i.jsx("textarea",{ref:b,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:A,onChange:o=>{const g=o.target.value;if(H(g),!!S){if(g){we(S,g);return}_(S)}},placeholder:t("terminal.inputPlaceholder"),onCompositionStart:()=>{u.current=!0},onCompositionEnd:()=>{u.current=!1}}),i.jsx("div",{className:"actions mt-2",children:i.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[i.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[i.jsx(Xt,{size:"sm",checked:te,onCheckedChange:o=>me(!!o)}),i.jsx("span",{children:t("terminal.editorSendWithEnter")})]}),i.jsxs(Ce,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;H(""),S&&_(S),h&&I==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},title:t("terminal.clear"),children:[i.jsx(qt,{className:"h-4 w-4"}),t("terminal.clear")]}),i.jsxs(Ce,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;bt(),h&&I==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},disabled:!z||X,children:[X?i.jsx(Ke,{className:"h-4 w-4 animate-spin"}):i.jsx(ct,{className:"h-4 w-4"}),t("terminal.editorSendLineByLine")]}),i.jsxs(Ce,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;vt(),h&&I==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},disabled:!z||X,children:[X?i.jsx(Ke,{className:"h-4 w-4 animate-spin"}):i.jsx(ct,{className:"h-4 w-4"}),t("common.send")]})]})})]})]})}function br(){const{deviceId:t,windowId:e,paneId:s}=tt(),c=s?nt(s):void 0,l=O($=>$.snapshots),p=ht($=>{var T;return((T=$.settings)==null?void 0:T.siteName)??"tmex"}),v=t?l[t]:void 0,b=n.useMemo(()=>{var $;if(!(!e||!(($=v==null?void 0:v.session)!=null&&$.windows)))return v.session.windows.find(T=>T.id===e)},[e,v]),R=n.useMemo(()=>{if(!(!c||!b))return b.panes.find($=>$.id===c)},[c,b]),B=n.useMemo(()=>b&&R?mt({paneCustomName:R.customName,paneTitle:R.title,windowName:b.name,windowCustomName:b.customName,deviceName:p}):t??"",[b,R,p,t]);return i.jsx(i.Fragment,{children:B})}function Sr(){const{t}=Ie(),{deviceId:e,windowId:s,paneId:c}=tt(),l=ft(),p=Yt(),v=c?nt(c):void 0,b=pe(u=>u.inputMode),R=pe(u=>u.setInputMode),B=O(u=>{var N;return e?((N=u.deviceConnected)==null?void 0:N[e])??!1:!1}),$=O(u=>e?u.snapshots[e]:void 0),T=n.useMemo(()=>{var u;if(!(!s||!((u=$==null?void 0:$.session)!=null&&u.windows)))return $.session.windows.find(N=>N.id===s)},[s,$]),U=n.useCallback(u=>{!e||!s||l(`/devices/${e}/windows/${s}/panes/${je(u)}`,{replace:!0})},[e,s,l]),r=n.useMemo(()=>{if(!(!v||!T))return T.panes.find(u=>u.id===v)},[v,T]),ae=n.useCallback(u=>{!e||!v||O.getState().splitPane(e,v,u,r==null?void 0:r.currentPath)},[e,v,r==null?void 0:r.currentPath]),[V,C]=n.useState(!1),[le,se]=n.useState(!1),[de,re]=n.useState(!1),f=!!(v&&B),h=(rt({queryKey:Vt(e??"",v??""),queryFn:()=>Ut(e??"",v??""),enabled:!!(e&&v),throwOnError:!1}).data??[]).some(u=>u.enabled),M=()=>{R(b==="direct"?"editor":"direct")},W=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},A=()=>{C(!0)},H=()=>{window.location.reload()};return i.jsxs(i.Fragment,{children:[p&&v&&T&&T.panes.length>1&&i.jsx(Gn,{window:T,currentPaneId:v,onSelectPane:U}),!p&&i.jsxs(i.Fragment,{children:[i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:()=>ae("right"),disabled:!f,"data-testid":"split-right-button","aria-label":t("window.splitRight"),title:t("window.splitRight"),children:i.jsx(Kt,{className:"h-4 w-4"})}),i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:()=>ae("down"),disabled:!f,"data-testid":"split-down-button","aria-label":t("window.splitDown"),title:t("window.splitDown"),children:i.jsx(Gt,{className:"h-4 w-4"})})]}),i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:A,"aria-label":t("nav.refreshPage"),title:t("nav.refreshPage"),children:i.jsx(fn,{className:"h-4 w-4"})}),i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:M,disabled:!f,"data-testid":"terminal-input-mode-toggle","aria-label":t(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:t(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:b==="direct"?i.jsx(vn,{className:"h-4 w-4"}):i.jsx(Mn,{className:"h-4 w-4"})}),i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:W,disabled:!f,"aria-label":t("nav.jumpToLatest"),title:t("nav.jumpToLatest"),children:i.jsx(hn,{className:"h-4 w-4"})}),i.jsxs(Ce,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>se(!0),disabled:!v,"data-testid":"watch-open-button","aria-label":t("watch.title"),title:t("watch.title"),children:[i.jsx(Qt,{className:"h-4 w-4"}),h&&i.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),i.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:()=>re(!0),"data-testid":"keyboard-behavior-open-button","aria-label":t("settings.terminal.title"),title:t("settings.terminal.title"),children:i.jsx(jn,{className:"h-4 w-4"})}),i.jsx(Pn,{open:de,onOpenChange:re}),e&&v&&i.jsx(Jt,{open:le,onOpenChange:se,deviceId:e,paneId:v}),i.jsx(Zt,{open:V,onOpenChange:C,children:i.jsxs(en,{children:[i.jsxs(tn,{children:[i.jsx(nn,{children:t("nav.refreshPage")}),i.jsx(rn,{children:t("nav.refreshPageConfirm")})]}),i.jsxs(sn,{children:[i.jsx(on,{onClick:()=>C(!1),children:t("common.cancel")}),i.jsx(cn,{onClick:H,children:t("common.confirm")})]})]})})]})}export{Sr as PageActions,br as PageTitle,vr as default};
@@ -1 +1 @@
1
- import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-BK6c5W5S.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-BA66zlg1.js";import{Z as We}from"./zap-DxVtkroR.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
1
+ import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-B3ddLSja.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-DmfNw0hd.js";import{Z as We}from"./zap-BFIAXPXd.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
@@ -1,4 +1,4 @@
1
- import{Y as zn,_ as ut,r as oe,j as h,X as gt,aL as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-BK6c5W5S.js";import{r as pt,M as _t}from"./markdown-preview-CDjnYorp.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-C2-crTt8.js";import{R as yt,s as vt}from"./transfer-toast-BYw9LLNi.js";import"./index-DLyPliOu.js";/**
1
+ import{Y as zn,_ as ut,r as oe,j as h,X as gt,aL as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-B3ddLSja.js";import{r as pt,M as _t}from"./markdown-preview-CBGlxpTs.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-DV7-9Pvt.js";import{R as yt,s as vt}from"./transfer-toast-DXl4RHsV.js";import"./index-iee3U_rD.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{Y as ce,u as F,j as e,L as It,M as Ze,z as Lt,r as w,c as Q,B as k,P as ge,a as O,e as M,o as b,a2 as D,v as De,T as te,A as xe,f as fe,g as pe,h as $t,i as we,k as ye,l as je,m as ve,n as be,C as ae,F as ne,H as ie,I as re,J as Ne,N as Ce,O as Ee,Q as ke,R as Se,U as le,K as B,W as de,aq as U,G as Bt,x as xt,at as Dt,b as Oe,t as et,bs as $,X as ft,af as nt,bt as Ot,bu as _t,aB as zt,bv as qt,bw as Kt,bx as Qt,by as Ut,bz as it,Z as Ht}from"./index-BK6c5W5S.js";import{C as H,b as G,c as J,d as pt,a as V}from"./card-BA66zlg1.js";import{e as Vt,h as wt,F as We,i as Wt,j as Gt,D as Jt}from"./api-C2-crTt8.js";import{R as tt,T as Yt,b as Xt,d as Zt}from"./terminal-settings-panel-DHrIp0wf.js";import{S as yt}from"./send-BVxB0Ywb.js";import{M as es}from"./markdown-preview-CDjnYorp.js";import{T as jt}from"./triangle-alert-D4oQhgpz.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-DLyPliOu.js";/**
1
+ import{Y as ce,u as F,j as e,L as It,M as Ze,z as Lt,r as w,c as Q,B as k,P as ge,a as O,e as M,o as b,a2 as D,v as De,T as te,A as xe,f as fe,g as pe,h as $t,i as we,k as ye,l as je,m as ve,n as be,C as ae,F as ne,H as ie,I as re,J as Ne,N as Ce,O as Ee,Q as ke,R as Se,U as le,K as B,W as de,aq as U,G as Bt,x as xt,at as Dt,b as Oe,t as et,bs as $,X as ft,af as nt,bt as Ot,bu as _t,aB as zt,bv as qt,bw as Kt,bx as Qt,by as Ut,bz as it,Z as Ht}from"./index-B3ddLSja.js";import{C as H,b as G,c as J,d as pt,a as V}from"./card-DmfNw0hd.js";import{e as Vt,h as wt,F as We,i as Wt,j as Gt,D as Jt}from"./api-DV7-9Pvt.js";import{R as tt,T as Yt,b as Xt,d as Zt}from"./terminal-settings-panel-DDhlnbRH.js";import{S as yt}from"./send-DaOB9hLq.js";import{M as es}from"./markdown-preview-CBGlxpTs.js";import{T as jt}from"./triangle-alert-FQRTtbTP.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-iee3U_rD.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{Y as _,r as N,j as e,X as C,u as k,an as Y,ao as ee,ap as te,aq as se,ar as ne,am as F,as as B,at as H,B as y,G as be,M as ve,x as Ne,c as K,N as ye,O as ke,R as Ie,U as X,au as Ce,av as Se,V as re,v as Me,aw as _e,af as ze,ax as Te,ay as g,d as Ee,az as Be,aA as qe,P as $e,aB as Pe,a2 as Ae,aC as Re}from"./index-BK6c5W5S.js";import{M as Fe,r as He}from"./index-DLyPliOu.js";import{K as Ke,S as Z}from"./send-BVxB0Ywb.js";import{Z as ae}from"./zap-DxVtkroR.js";/**
1
+ import{Y as _,r as N,j as e,X as C,u as k,an as Y,ao as ee,ap as te,aq as se,ar as ne,am as F,as as B,at as H,B as y,G as be,M as ve,x as Ne,c as K,N as ye,O as ke,R as Ie,U as X,au as Ce,av as Se,V as re,v as Me,aw as _e,af as ze,ax as Te,ay as g,d as Ee,az as Be,aA as qe,P as $e,aB as Pe,a2 as Ae,aC as Re}from"./index-B3ddLSja.js";import{M as Fe,r as He}from"./index-iee3U_rD.js";import{K as Ke,S as Z}from"./send-DaOB9hLq.js";import{Z as ae}from"./zap-BFIAXPXd.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- var N=Object.defineProperty;var P=(t,e,o)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var O=(t,e,o)=>P(t,typeof e!="symbol"?e+"":e,o);import{Y as x}from"./index-BK6c5W5S.js";/**
1
+ var N=Object.defineProperty;var P=(t,e,o)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var O=(t,e,o)=>P(t,typeof e!="symbol"?e+"":e,o);import{Y as x}from"./index-B3ddLSja.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./mermaid.core-CXD-Pc2r.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(on(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,F=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<an)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(fn((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
1
+ import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./mermaid.core-D-CshtYr.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(on(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,F=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<an)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(fn((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};