tmex-cli 0.6.7 → 0.6.8
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.
- package/dist/runtime/server.js +50 -5
- package/package.json +1 -1
- package/resources/fe-dist/assets/DevicePage-CJEjk7rL.js +36 -0
- package/resources/fe-dist/assets/{DevicesPage-ed49Jc29.js → DevicesPage-BvCZBCO1.js} +2 -2
- package/resources/fe-dist/assets/{SettingsPage-CEPZVSnc.js → SettingsPage-BU-Jjd2f.js} +2 -2
- package/resources/fe-dist/assets/{index-CmLsM0XA.js → index-YVZKH9DX.js} +43 -43
- package/resources/fe-dist/assets/{select-C02R2Kd_.js → select-CD0ieoCm.js} +2 -2
- package/resources/fe-dist/assets/{switch-WtpunVNm.js → switch-B4Od47H9.js} +2 -2
- package/resources/fe-dist/assets/{useValueChanged-CHeT2_Oy.js → useValueChanged-CFS5t0R_.js} +2 -2
- package/resources/fe-dist/index.html +1 -1
- package/resources/fe-dist/assets/DevicePage-DtUN4_7I.js +0 -36
package/dist/runtime/server.js
CHANGED
|
@@ -21472,6 +21472,7 @@ __export(exports_ws_borsh, {
|
|
|
21472
21472
|
MAX_CHUNK_STREAMS: () => MAX_CHUNK_STREAMS,
|
|
21473
21473
|
MAX_CHUNKS_PER_MESSAGE: () => MAX_CHUNKS_PER_MESSAGE,
|
|
21474
21474
|
MAGIC: () => MAGIC,
|
|
21475
|
+
KIND_TMUX_SET_WINDOW_STYLE: () => KIND_TMUX_SET_WINDOW_STYLE,
|
|
21475
21476
|
KIND_TMUX_SELECT_WINDOW: () => KIND_TMUX_SELECT_WINDOW,
|
|
21476
21477
|
KIND_TMUX_SELECT: () => KIND_TMUX_SELECT,
|
|
21477
21478
|
KIND_TMUX_RENAME_WINDOW: () => KIND_TMUX_RENAME_WINDOW,
|
|
@@ -21545,6 +21546,7 @@ var KIND_TMUX_RENAME_WINDOW = 518;
|
|
|
21545
21546
|
var KIND_TMUX_EVENT = 519;
|
|
21546
21547
|
var KIND_STATE_SNAPSHOT = 520;
|
|
21547
21548
|
var KIND_STATE_SNAPSHOT_DIFF = 521;
|
|
21549
|
+
var KIND_TMUX_SET_WINDOW_STYLE = 522;
|
|
21548
21550
|
var KIND_TERM_INPUT = 769;
|
|
21549
21551
|
var KIND_TERM_PASTE = 770;
|
|
21550
21552
|
var KIND_TERM_RESIZE = 771;
|
|
@@ -21574,6 +21576,7 @@ var VALID_KINDS = new Set([
|
|
|
21574
21576
|
KIND_TMUX_EVENT,
|
|
21575
21577
|
KIND_STATE_SNAPSHOT,
|
|
21576
21578
|
KIND_STATE_SNAPSHOT_DIFF,
|
|
21579
|
+
KIND_TMUX_SET_WINDOW_STYLE,
|
|
21577
21580
|
KIND_TERM_INPUT,
|
|
21578
21581
|
KIND_TERM_PASTE,
|
|
21579
21582
|
KIND_TERM_RESIZE,
|
|
@@ -21608,6 +21611,7 @@ function kindToString(kind) {
|
|
|
21608
21611
|
[KIND_TMUX_EVENT]: "TMUX_EVENT",
|
|
21609
21612
|
[KIND_STATE_SNAPSHOT]: "STATE_SNAPSHOT",
|
|
21610
21613
|
[KIND_STATE_SNAPSHOT_DIFF]: "STATE_SNAPSHOT_DIFF",
|
|
21614
|
+
[KIND_TMUX_SET_WINDOW_STYLE]: "TMUX_SET_WINDOW_STYLE",
|
|
21611
21615
|
[KIND_TERM_INPUT]: "TERM_INPUT",
|
|
21612
21616
|
[KIND_TERM_PASTE]: "TERM_PASTE",
|
|
21613
21617
|
[KIND_TERM_RESIZE]: "TERM_RESIZE",
|
|
@@ -21669,6 +21673,7 @@ __export(exports_schema, {
|
|
|
21669
21673
|
WindowCloseEventSchema: () => WindowCloseEventSchema,
|
|
21670
21674
|
WindowAddEventSchema: () => WindowAddEventSchema,
|
|
21671
21675
|
WindowActiveEventSchema: () => WindowActiveEventSchema,
|
|
21676
|
+
TmuxSetWindowStyleSchema: () => TmuxSetWindowStyleSchema,
|
|
21672
21677
|
TmuxSelectWindowSchema: () => TmuxSelectWindowSchema,
|
|
21673
21678
|
TmuxSelectSchema: () => TmuxSelectSchema,
|
|
21674
21679
|
TmuxRenameWindowSchema: () => TmuxRenameWindowSchema,
|
|
@@ -21795,6 +21800,10 @@ var TmuxRenameWindowSchema = import_zorsh.b.struct({
|
|
|
21795
21800
|
windowId: import_zorsh.b.string(),
|
|
21796
21801
|
name: import_zorsh.b.string()
|
|
21797
21802
|
});
|
|
21803
|
+
var TmuxSetWindowStyleSchema = import_zorsh.b.struct({
|
|
21804
|
+
deviceId: import_zorsh.b.string(),
|
|
21805
|
+
style: import_zorsh.b.string()
|
|
21806
|
+
});
|
|
21798
21807
|
var TmuxEventSchema = import_zorsh.b.struct({
|
|
21799
21808
|
deviceId: import_zorsh.b.string(),
|
|
21800
21809
|
eventType: import_zorsh.b.u8(),
|
|
@@ -53434,7 +53443,7 @@ function resolveTmuxWindowStyle(value) {
|
|
|
53434
53443
|
return null;
|
|
53435
53444
|
}
|
|
53436
53445
|
if (!WINDOW_STYLE_PATTERN.test(style)) {
|
|
53437
|
-
console.warn(`[tmex] ignoring invalid
|
|
53446
|
+
console.warn(`[tmex] ignoring invalid tmux window-style: ${style}`);
|
|
53438
53447
|
return null;
|
|
53439
53448
|
}
|
|
53440
53449
|
return style;
|
|
@@ -53652,6 +53661,17 @@ class LocalExternalTmuxConnection {
|
|
|
53652
53661
|
this.callbacks.onError(error);
|
|
53653
53662
|
});
|
|
53654
53663
|
}
|
|
53664
|
+
setWindowStyle(style) {
|
|
53665
|
+
if (!this.connected) {
|
|
53666
|
+
return;
|
|
53667
|
+
}
|
|
53668
|
+
if (!resolveTmuxWindowStyle(config.tmuxWindowStyle)) {
|
|
53669
|
+
return;
|
|
53670
|
+
}
|
|
53671
|
+
this.configureWindowStyle(style).catch((error) => {
|
|
53672
|
+
this.callbacks.onError(error);
|
|
53673
|
+
});
|
|
53674
|
+
}
|
|
53655
53675
|
async ensureSession() {
|
|
53656
53676
|
const exists3 = await this.runTmuxAllowFailure(["has-session", "-t", this.sessionName]);
|
|
53657
53677
|
if (exists3.exitCode === 0) {
|
|
@@ -53713,8 +53733,8 @@ class LocalExternalTmuxConnection {
|
|
|
53713
53733
|
]);
|
|
53714
53734
|
await this.configureWindowStyle();
|
|
53715
53735
|
}
|
|
53716
|
-
async configureWindowStyle() {
|
|
53717
|
-
const windowStyle = resolveTmuxWindowStyle(
|
|
53736
|
+
async configureWindowStyle(styleValue = config.tmuxWindowStyle) {
|
|
53737
|
+
const windowStyle = resolveTmuxWindowStyle(styleValue);
|
|
53718
53738
|
if (!windowStyle) {
|
|
53719
53739
|
return;
|
|
53720
53740
|
}
|
|
@@ -54777,6 +54797,17 @@ class SshExternalTmuxConnection {
|
|
|
54777
54797
|
this.callbacks.onError(error);
|
|
54778
54798
|
});
|
|
54779
54799
|
}
|
|
54800
|
+
setWindowStyle(style) {
|
|
54801
|
+
if (!this.connected) {
|
|
54802
|
+
return;
|
|
54803
|
+
}
|
|
54804
|
+
if (!resolveTmuxWindowStyle(config.tmuxWindowStyle)) {
|
|
54805
|
+
return;
|
|
54806
|
+
}
|
|
54807
|
+
this.configureWindowStyle(style).catch((error) => {
|
|
54808
|
+
this.callbacks.onError(error);
|
|
54809
|
+
});
|
|
54810
|
+
}
|
|
54780
54811
|
async connectSshClient() {
|
|
54781
54812
|
if (!this.device) {
|
|
54782
54813
|
throw new Error("SSH device not loaded");
|
|
@@ -54944,8 +54975,8 @@ class SshExternalTmuxConnection {
|
|
|
54944
54975
|
]);
|
|
54945
54976
|
await this.configureWindowStyle();
|
|
54946
54977
|
}
|
|
54947
|
-
async configureWindowStyle() {
|
|
54948
|
-
const windowStyle = resolveTmuxWindowStyle(
|
|
54978
|
+
async configureWindowStyle(styleValue = config.tmuxWindowStyle) {
|
|
54979
|
+
const windowStyle = resolveTmuxWindowStyle(styleValue);
|
|
54949
54980
|
if (!windowStyle) {
|
|
54950
54981
|
return;
|
|
54951
54982
|
}
|
|
@@ -55683,6 +55714,9 @@ class DeviceSessionRuntime {
|
|
|
55683
55714
|
renameWindow(windowId, name) {
|
|
55684
55715
|
this.connection.renameWindow(windowId, name);
|
|
55685
55716
|
}
|
|
55717
|
+
setWindowStyle(style) {
|
|
55718
|
+
this.connection.setWindowStyle(style);
|
|
55719
|
+
}
|
|
55686
55720
|
broadcast(action) {
|
|
55687
55721
|
for (const listener of this.listeners) {
|
|
55688
55722
|
try {
|
|
@@ -57548,6 +57582,11 @@ class WebSocketServer {
|
|
|
57548
57582
|
this.handleRenameWindow(decoded.deviceId, decoded.windowId, decoded.name);
|
|
57549
57583
|
return;
|
|
57550
57584
|
}
|
|
57585
|
+
case exports_ws_borsh.KIND_TMUX_SET_WINDOW_STYLE: {
|
|
57586
|
+
const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxSetWindowStyleSchema, payload);
|
|
57587
|
+
this.handleSetWindowStyle(decoded.deviceId, decoded.style);
|
|
57588
|
+
return;
|
|
57589
|
+
}
|
|
57551
57590
|
case exports_ws_borsh.KIND_TERM_INPUT: {
|
|
57552
57591
|
const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TermInputSchema, payload);
|
|
57553
57592
|
if (decoded.isComposing)
|
|
@@ -57793,6 +57832,12 @@ class WebSocketServer {
|
|
|
57793
57832
|
return;
|
|
57794
57833
|
this.sendSnapshotToClients(entry, entry.lastSnapshot);
|
|
57795
57834
|
}
|
|
57835
|
+
handleSetWindowStyle(deviceId, style) {
|
|
57836
|
+
const entry = this.connections.get(deviceId);
|
|
57837
|
+
if (!entry)
|
|
57838
|
+
return;
|
|
57839
|
+
entry.runtime.setWindowStyle(style);
|
|
57840
|
+
}
|
|
57796
57841
|
applyWindowCustomNames(payload) {
|
|
57797
57842
|
const names = this.windowCustomNames.get(payload.deviceId);
|
|
57798
57843
|
if (!names?.size || !payload.session)
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var Wt=Object.defineProperty;var $t=(n,e,t)=>e in n?Wt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>$t(n,typeof e!="symbol"?e+"":e,t);import{c as xe,u as Ke,j as h,b3 as jt,r as d,s as Z,b4 as At,b5 as Ot,b6 as dt,g as _e,b7 as qt,b8 as it,b9 as Xt,b as kt,ba as ot,d as ae,bb as Jt,e as Qt,bc as Ht,bd as Se,be as Zt,B as pe,A as en,h as tn,i as nn,k as sn,l as rn,m as on,n as ln,o as an}from"./index-YVZKH9DX.js";import{L as je,S as cn,a as ut}from"./switch-B4Od47H9.js";import{T as dn}from"./useValueChanged-CFS5t0R_.js";/**
|
|
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 un=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],hn=xe("arrow-down-to-line",un);/**
|
|
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 fn=[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]],mn=xe("clipboard-paste",fn);/**
|
|
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 pn=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],wn=xe("copy",pn);/**
|
|
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 yn=[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]],gn=xe("keyboard",yn);/**
|
|
22
|
+
* @license lucide-react v0.564.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Sn=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],_n=xe("refresh-cw",Sn);/**
|
|
27
|
+
* @license lucide-react v0.564.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const xn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],bn=xe("smartphone",xn);function Tn(n){return`rgb(${n.r} ${n.g} ${n.b})`}const En=new Map([[9622,4],[9623,8],[9624,1],[9625,13],[9626,9],[9627,7],[9628,11],[9629,2],[9630,6],[9631,14]]),Rn=new Map([[9617,.25],[9618,.5],[9619,.75]]);function Cn(n){return n>=9600&&n<=9631}function qe(n){const e=n.getContext("2d");if(!e)throw new Error("2d canvas context unavailable");return e}class vn{constructor(e){m(this,"kind","canvas");m(this,"mainCanvas");m(this,"selectionCanvas");m(this,"cursorCanvas");m(this,"mainContext");m(this,"selectionContext");m(this,"cursorContext");m(this,"theme");m(this,"fontFamily");m(this,"fontSize");m(this,"cellDimensions",{width:9,height:17});m(this,"deviceCellWidth",9);m(this,"deviceCellHeight",17);m(this,"dpr",1);m(this,"cols",0);m(this,"rows",0);m(this,"lastCursor",null);m(this,"frameCount",0);m(this,"lastDrawnRows",[]);m(this,"colorCache",new Map);m(this,"fontCache",new Map);m(this,"cursorBlinkVisible",!0);m(this,"cursorBlinkTimer",null);this.theme=e.theme,this.fontFamily=e.fontFamily,this.fontSize=e.fontSize,e.screenElement.style.position="relative",e.screenElement.style.overflow="hidden",this.mainCanvas=document.createElement("canvas"),this.selectionCanvas=document.createElement("canvas"),this.cursorCanvas=document.createElement("canvas");for(const[t,s]of[[this.mainCanvas,"main"],[this.selectionCanvas,"selection"],[this.cursorCanvas,"cursor"]])t.dataset.layer=s,t.style.position="absolute",t.style.inset="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",e.screenElement.appendChild(t);this.mainContext=qe(this.mainCanvas),this.selectionContext=qe(this.selectionCanvas),this.cursorContext=qe(this.cursorCanvas)}setTheme(e){this.theme=e,this.colorCache.clear()}render(e){if(this.frameCount+=1,this.lastDrawnRows=[],this.cellDimensions=e.cellDimensions,this.resize(e.meta.cols,e.meta.rows),this.drawSelection(e.selectionRects??[],e.selectionColor??this.theme.selectionBackground),e.meta.dirty==="clean"){this.drawCursor(e.meta);return}const s=e.meta.dirty==="full"?e.rows:e.rows.filter(i=>i.dirty);for(const i of s)this.drawRow(i,e.meta.colors),this.lastDrawnRows.push(i.y);this.drawCursor(e.meta)}getDebugState(){return{kind:this.kind,frameCount:this.frameCount,lastDrawnRows:[...this.lastDrawnRows]}}dispose(){this.mainCanvas.remove(),this.selectionCanvas.remove(),this.cursorCanvas.remove(),this.colorCache.clear(),this.fontCache.clear(),this.lastCursor=null,this.stopCursorBlink()}startCursorBlink(){this.cursorBlinkTimer||(this.cursorBlinkTimer=setInterval(()=>{this.cursorBlinkVisible=!this.cursorBlinkVisible,this.cursorCanvas.style.opacity=this.cursorBlinkVisible?"1":"0"},1e3))}stopCursorBlink(){this.cursorBlinkTimer&&(clearInterval(this.cursorBlinkTimer),this.cursorBlinkTimer=null),this.cursorBlinkVisible=!0,this.cursorCanvas.style.opacity="1"}resize(e,t){const s=Math.max(1,e),i=Math.max(1,t),r=Math.max(1,globalThis.devicePixelRatio??1),o=Math.max(1,Math.round(this.cellDimensions.width*r)),l=Math.max(1,Math.round(this.cellDimensions.height*r));if(this.cols===s&&this.rows===i&&this.dpr===r&&this.deviceCellWidth===o&&this.deviceCellHeight===l)return;this.cols=s,this.rows=i,this.dpr=r,this.deviceCellWidth=o,this.deviceCellHeight=l;const u=s*o,a=i*l;for(const f of[this.mainCanvas,this.selectionCanvas,this.cursorCanvas])f.width=u,f.height=a,f.style.width=`${u/r}px`,f.style.height=`${a/r}px`;for(const f of[this.mainContext,this.selectionContext,this.cursorContext])f.setTransform(1,0,0,1,0,0),f.textBaseline="top",f.imageSmoothingEnabled=!1}drawSelection(e,t){if(this.selectionContext.clearRect(0,0,this.selectionCanvas.width,this.selectionCanvas.height),e.length!==0){this.selectionContext.fillStyle=t;for(const s of e)this.selectionContext.fillRect(s.x*this.deviceCellWidth,s.row*this.deviceCellHeight,s.width*this.deviceCellWidth,this.deviceCellHeight)}}drawRow(e,t){const s=e.y*this.deviceCellHeight,i=this.cols*this.deviceCellWidth,r=this.toCss(t.background),o=Math.max(1,Math.round(this.dpr));this.mainContext.clearRect(0,s,i,this.deviceCellHeight),this.mainContext.fillStyle=r,this.mainContext.fillRect(0,s,i,this.deviceCellHeight);for(const l of e.cells){if(l.widthKind==="spacer-tail"||l.widthKind==="spacer-head")continue;const u=l.x*this.deviceCellWidth,a=l.style.inverse?l.fgColor??t.foreground:l.bgColor??t.background,f=l.style.inverse?l.bgColor??t.background:l.fgColor??t.foreground,x=l.widthKind==="wide"?this.deviceCellWidth*2:this.deviceCellWidth;if((a.r!==t.background.r||a.g!==t.background.g||a.b!==t.background.b)&&(this.mainContext.fillStyle=this.toCss(a),this.mainContext.fillRect(u,s,x,this.deviceCellHeight)),!l.text||l.style.invisible)continue;this.mainContext.fillStyle=this.toCss(f);const R=l.codepoints.length===1&&Cn(l.codepoints[0])?l.codepoints[0]:null;R!==null?this.drawBlockElement(R,u,s,x,this.deviceCellHeight):(this.mainContext.font=this.resolveFont(l.style),this.mainContext.fillText(l.text,u,s)),l.style.underline>0&&this.mainContext.fillRect(u,s+this.deviceCellHeight-2*o,Math.max(x-o,o),o),l.style.strikethrough&&this.mainContext.fillRect(u,Math.round(s+this.deviceCellHeight*.55),Math.max(x-o,o),o),l.style.overline&&this.mainContext.fillRect(u,s+o,Math.max(x-o,o),o)}}drawBlockElement(e,t,s,i,r){const o=this.mainContext,l=b=>Math.round(i*b/8),u=b=>Math.round(r*b/8),a=(b,E,K,y)=>{o.fillRect(t+b,s+E,K-b,y-E)};if(e===9600){a(0,0,i,u(4));return}if(e>=9601&&e<=9608){a(0,u(8-(e-9600)),i,r);return}if(e>=9609&&e<=9615){a(0,0,l(9616-e),r);return}if(e===9616){a(l(4),0,i,r);return}const f=Rn.get(e);if(f!==void 0){const b=o.globalAlpha;o.globalAlpha=b*f,a(0,0,i,r),o.globalAlpha=b;return}if(e===9620){a(0,0,i,u(1));return}if(e===9621){a(l(7),0,i,r);return}const x=En.get(e)??0,R=l(4),k=u(4);x&1&&a(0,0,R,k),x&2&&a(R,0,i,k),x&4&&a(0,k,R,r),x&8&&a(R,k,i,r)}drawCursor(e){const t=e.colors,s=e.cursor,i=this.lastCursor;if(this.cursorContext.clearRect(0,0,this.cursorCanvas.width,this.cursorCanvas.height),!s.visible||s.x===null||s.y===null){this.lastCursor=null,this.stopCursorBlink();return}const r=s.x*this.deviceCellWidth,o=s.y*this.deviceCellHeight,l=s.wideTail?this.deviceCellWidth*2:this.deviceCellWidth,u=Math.max(1,Math.round(this.dpr)),a=t.cursor??t.foreground,f=this.toCss(a);this.cursorContext.fillStyle=f,this.cursorContext.strokeStyle=f,this.cursorContext.globalAlpha=.7,this.cursorContext.fillRect(r,o+this.deviceCellHeight-2*u,Math.max(l-u,u),2*u),this.cursorContext.globalAlpha=1,this.startCursorBlink(),this.lastCursor={x:s.x,y:s.y,style:s.style},i&&(i.x!==this.lastCursor.x||i.y!==this.lastCursor.y||i.style!==this.lastCursor.style)&&this.lastDrawnRows.push(i.y)}resolveFont(e){const t=this.fontSize*this.dpr,s=[e.italic?"italic":"normal",e.bold?"700":"400",`${t}px`,this.fontFamily].join("|"),i=this.fontCache.get(s);if(i)return i;const r=`${e.italic?"italic ":""}${e.bold?"700 ":""}${t}px ${this.fontFamily}`;return this.fontCache.set(s,r),r}toCss(e){const t=`${e.r},${e.g},${e.b}`,s=this.colorCache.get(t);if(s)return s;const i=Tn(e);return this.colorCache.set(t,i),i}}const Mn=0,Dn={Backquote:1,Backslash:2,BracketLeft:3,BracketRight:4,Comma:5,Digit0:6,Digit1:7,Digit2:8,Digit3:9,Digit4:10,Digit5:11,Digit6:12,Digit7:13,Digit8:14,Digit9:15,Equal:16,IntlBackslash:17,IntlRo:18,IntlYen:19,KeyA:20,KeyB:21,KeyC:22,KeyD:23,KeyE:24,KeyF:25,KeyG:26,KeyH:27,KeyI:28,KeyJ:29,KeyK:30,KeyL:31,KeyM:32,KeyN:33,KeyO:34,KeyP:35,KeyQ:36,KeyR:37,KeyS:38,KeyT:39,KeyU:40,KeyV:41,KeyW:42,KeyX:43,KeyY:44,KeyZ:45,Minus:46,Period:47,Quote:48,Semicolon:49,Slash:50,AltLeft:51,AltRight:52,Backspace:53,CapsLock:54,ContextMenu:55,ControlLeft:56,ControlRight:57,Enter:58,MetaLeft:59,MetaRight:60,ShiftLeft:61,ShiftRight:62,Space:63,Tab:64,Convert:65,KanaMode:66,NonConvert:67,Delete:68,End:69,Help:70,Home:71,Insert:72,PageDown:73,PageUp:74,ArrowDown:75,ArrowLeft:76,ArrowRight:77,ArrowUp:78,NumLock:79,Numpad0:80,Numpad1:81,Numpad2:82,Numpad3:83,Numpad4:84,Numpad5:85,Numpad6:86,Numpad7:87,Numpad8:88,Numpad9:89,NumpadAdd:90,NumpadBackspace:91,NumpadClear:92,NumpadClearEntry:93,NumpadComma:94,NumpadDecimal:95,NumpadDivide:96,NumpadEnter:97,NumpadEqual:98,NumpadMemoryAdd:99,NumpadMemoryClear:100,NumpadMemoryRecall:101,NumpadMemoryStore:102,NumpadMemorySubtract:103,NumpadMultiply:104,NumpadParenLeft:105,NumpadParenRight:106,NumpadSubtract:107,NumpadSeparator:108,NumpadUp:109,NumpadDown:110,NumpadRight:111,NumpadLeft:112,NumpadBegin:113,NumpadHome:114,NumpadEnd:115,NumpadInsert:116,NumpadDelete:117,NumpadPageUp:118,NumpadPageDown:119,Escape:120,F1:121,F2:122,F3:123,F4:124,F5:125,F6:126,F7:127,F8:128,F9:129,F10:130,F11:131,F12:132,F13:133,F14:134,F15:135,F16:136,F17:137,F18:138,F19:139,F20:140,F21:141,F22:142,F23:143,F24:144,F25:145,Fn:146,FnLock:147,PrintScreen:148,ScrollLock:149,Pause:150,BrowserBack:151,BrowserFavorites:152,BrowserForward:153,BrowserHome:154,BrowserRefresh:155,BrowserSearch:156,BrowserStop:157,Eject:158,LaunchApp1:159,LaunchApp2:160,LaunchMail:161,MediaPlayPause:162,MediaSelect:163,MediaStop:164,MediaTrackNext:165,MediaTrackPrevious:166,Power:167,Sleep:168,AudioVolumeDown:169,AudioVolumeMute:170,AudioVolumeUp:171,WakeUp:172,Copy:173,Cut:174,Paste:175},lt={Backquote:"`",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Comma:",",Equal:"=",Minus:"-",Period:".",Quote:"'",Semicolon:";",Slash:"/",Space:" ",IntlBackslash:"\\",IntlYen:"¥",IntlRo:"\\"};for(let n=0;n<=9;n+=1)lt[`Digit${n}`]=String(n);for(let n=0;n<26;n+=1){const e=String.fromCharCode(65+n),t=String.fromCharCode(97+n);lt[`Key${e}`]=t}function ht(n){return Dn[n]??Mn}function An(n){const e=lt[n];return e?e.codePointAt(0)??null:null}const be=0,On=-2,kn=1,Hn=2,In=3,Nn=10,Pn=11,Ln=12,Bn=13,Fn=14,Gn=15,Un=16,zn=17,Yn=1,Vn=2,Kn=1,Wn=2,$n=3,jn=4,qn=5,Xn=6,Jn=1,Qn=2,Zn=3,es=4;function at(n){if(n.disposed||n.renderStateHandle===0)throw new Error("render state resources already disposed")}function ts(n){switch(n){case 2:return"full";case 1:return"partial";default:return"clean"}}function ns(n){switch(n){case 0:return"bar";case 2:return"underline";case 3:return"block-hollow";default:return"block"}}function ss(n){switch(n){case 1:return"wide";case 2:return"spacer-tail";case 3:return"spacer-head";default:return"narrow"}}function Re(n,e){return{r:n.view().getUint8(e),g:n.view().getUint8(e+1),b:n.view().getUint8(e+2)}}function ft(n,e){const t=n.bindings.allocStruct("GhosttyColorRgb");try{const s=e(t.ptr);if(s===On)return null;if(s!==be)throw new Error(`ghostty optional color read failed with result ${s}`);return Re(n.bindings,t.ptr)}finally{t.free()}}function ce(n,e){const t=n.bindings.allocU8();try{const s=e(t);if(typeof s=="number"&&s!==be)throw new Error(`ghostty bool read failed with result ${s}`);return n.bindings.readU8(t)!==0}finally{n.bindings.freeU8(t)}}function Ne(n,e){const t=n.bindings.allocBytes(2);try{const s=e(t);if(typeof s=="number"&&s!==be)throw new Error(`ghostty u16 read failed with result ${s}`);return n.bindings.view().getUint16(t,!0)}finally{n.bindings.freeBytes(t,2)}}function rs(n,e){const t=n.bindings.allocBytes(4);try{const s=e(t);if(typeof s=="number"&&s!==be)throw new Error(`ghostty u32 read failed with result ${s}`);return n.bindings.view().getUint32(t,!0)}finally{n.bindings.freeBytes(t,4)}}function nt(n,e){const t=n.bindings.allocBytes(4);try{const s=e(t);if(typeof s=="number"&&s!==be)throw new Error(`ghostty enum read failed with result ${s}`);return n.bindings.view().getInt32(t,!0)}finally{n.bindings.freeBytes(t,4)}}function mt(n,e){const t=n.bindings.allocBytes(8);try{const s=e(t);if(typeof s=="number"&&s!==be)throw new Error(`ghostty u64 read failed with result ${s}`);return n.bindings.readU64(t)}finally{n.bindings.freeBytes(t,8)}}function is(n){const e=n.bindings.allocStruct("GhosttyStyle");try{n.bindings.setField(e.view,"GhosttyStyle","size",n.bindings.typeSize("GhosttyStyle")),n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,Wn,e.ptr);const t=s=>n.bindings.field("GhosttyStyle",s).offset;return{bold:e.view.getUint8(t("bold"))!==0,italic:e.view.getUint8(t("italic"))!==0,faint:e.view.getUint8(t("faint"))!==0,blink:e.view.getUint8(t("blink"))!==0,inverse:e.view.getUint8(t("inverse"))!==0,invisible:e.view.getUint8(t("invisible"))!==0,strikethrough:e.view.getUint8(t("strikethrough"))!==0,overline:e.view.getUint8(t("overline"))!==0,underline:e.view.getInt32(t("underline"),!0)}}finally{e.free()}}function os(n){const e=rs(n,s=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,$n,s));if(e===0)return[];const t=n.bindings.allocBytes(e*4);try{n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,jn,t);const s=[];for(let i=0;i<e;i+=1)s.push(n.bindings.view().getUint32(t+i*4,!0));return s}finally{n.bindings.freeBytes(t,e*4)}}function ls(n){if(n.length===0)return"";try{return String.fromCodePoint(...n)}catch{return""}}function as(n){let e="";for(const t of n)if(!(t.widthKind==="spacer-tail"||t.widthKind==="spacer-head")){if(t.text){e+=t.text;continue}t.widthKind==="narrow"&&(e+=" ")}return e}function cs(n){const e=n.bindings.allocStruct("GhosttyRenderStateColors");try{n.bindings.setField(e.view,"GhosttyRenderStateColors","size",n.bindings.typeSize("GhosttyRenderStateColors")),n.bindings.getRenderStateColors(n.renderStateHandle,e.ptr);const t=n.bindings.field("GhosttyRenderStateColors","palette").offset,s=[];for(let o=0;o<256;o+=1){const l=e.ptr+t+o*3;s.push(Re(n.bindings,l))}const i=e.view.getUint8(n.bindings.field("GhosttyRenderStateColors","cursor_has_value").offset)!==0,r=ce(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Fn,o));return{cols:Ne(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,kn,o)),rows:Ne(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Hn,o)),dirty:ts(nt(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,In,o))),colors:{background:Re(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","background").offset),foreground:Re(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","foreground").offset),cursor:i?Re(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","cursor").offset):null,palette:s},cursor:{style:ns(nt(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Nn,o))),visible:ce(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Pn,o)),blinking:ce(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Ln,o)),passwordInput:ce(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Bn,o)),x:r?Ne(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Gn,o)):null,y:r?Ne(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Un,o)):null,wideTail:r?ce(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,zn,o)):!1}}}finally{e.free()}}function ds(n,e){const t=mt(n,r=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,Vn,r));n.bindings.bindRenderStateRowCells(n.rowIteratorHandle,n.rowCellsHandle);const s=[];let i=0;for(;n.bindings.nextRenderStateRowCell(n.rowCellsHandle);){const r=mt(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Kn,a)),o=os(n),l=ss(nt(n,a=>n.bindings.getRawCellValueResult(r,Zn,a))),u={x:i,text:ls(o),codepoints:o,widthKind:l,hasText:ce(n,a=>n.bindings.getRawCellValueResult(r,es,a)),style:is(n),fgColor:ft(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Xn,a)),bgColor:ft(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,qn,a))};s.push(u),i+=1}return{y:e,dirty:ce(n,r=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,Yn,r)),wrap:ce(n,r=>n.bindings.getRawRowValueResult(t,Jn,r)),wrapContinuation:ce(n,r=>n.bindings.getRawRowValueResult(t,Qn,r)),text:as(s),cells:s}}function pt(n){return{bindings:n,renderStateHandle:n.createRenderState(),rowIteratorHandle:n.createRenderStateRowIterator(),rowCellsHandle:n.createRenderStateRowCells(),snapshotVersion:0,disposed:!1,cachedMeta:null}}function wt(n,e){at(n),n.bindings.updateRenderState(n.renderStateHandle,e),n.bindings.bindRenderStateRowIterator(n.renderStateHandle,n.rowIteratorHandle),n.snapshotVersion+=1,n.cachedMeta=null}function st(n){return at(n),n.cachedMeta||(n.cachedMeta=cs(n)),n.cachedMeta}function*us(n){at(n);const e=st(n);n.bindings.bindRenderStateRowIterator(n.renderStateHandle,n.rowIteratorHandle);let t=0;for(;t<e.rows&&n.bindings.nextRenderStateRowIterator(n.rowIteratorHandle);)yield ds(n,t),t+=1}function Xe(n){n.disposed||(n.disposed=!0,n.rowCellsHandle!==0&&(n.bindings.freeRenderStateRowCells(n.rowCellsHandle),n.rowCellsHandle=0),n.rowIteratorHandle!==0&&(n.bindings.freeRenderStateRowIterator(n.rowIteratorHandle),n.rowIteratorHandle=0),n.renderStateHandle!==0&&(n.bindings.freeRenderState(n.renderStateHandle),n.renderStateHandle=0),n.cachedMeta=null)}const hs={colChars:[],contentCols:0,wrappedToNext:!1};function fs(n){for(let e=n.length-1;e>=0;e-=1){const t=n[e];if(t!==null&&t!==""&&t!==" ")return e+1}return 0}function yt(n,e=!1){const t=[];for(const s of n){if(s.widthKind==="spacer-tail"){t.push(null);continue}if(s.widthKind==="spacer-head"){t.push("");continue}t.push(s.text||" ")}return{colChars:t,contentCols:fs(t),wrappedToNext:e}}function ms(n,e){return Math.max(0,Math.min(Math.max(n.colChars.length-1,0),Math.floor(e)))}function ct(n,e){let t=ms(n,e);for(;t>0&&n.colChars[t]===null;)t-=1;return t}function Je(n,e){let t=e;for(;t>0&&n.colChars[t]===null;)t-=1;return n.colChars[t]||""}function gt(n,e){let t=e;for(;t+1<n.colChars.length&&n.colChars[t+1]===null;)t+=1;return t}function ps(n,e){return n.line<e.line?{start:n,end:e}:n.line>e.line?{start:e,end:n}:n.col<=e.col?{start:n,end:e}:{start:e,end:n}}function ws(n,e,t){if(t.colChars.length===0)return{start:{line:n,col:0},end:{line:n,col:0}};const s=ct(t,e),i=l=>/[\p{L}\p{N}_-]/u.test(l);if(!i(Je(t,s)))return{start:{line:n,col:s},end:{line:n,col:s}};let r=s,o=s;for(;r>0&&i(Je(t,r-1));)r-=1;for(;o+1<t.colChars.length&&i(Je(t,o+1));)o+=1;return{start:{line:n,col:r},end:{line:n,col:o}}}function It(n,e){const t=Math.max(e.contentCols-1,0);return{start:{line:n,col:0},end:{line:n,col:t}}}function Nt(n,e,t){const s=t(n.line);switch(e){case"word":return ws(n.line,n.col,s);case"line":return It(n.line,s);default:{const i=ct(s,n.col);return{start:{line:n.line,col:i},end:{line:n.line,col:i}}}}}function Pt(){return{anchor:null,focus:null,mode:"character"}}function St(n){return!!(n.anchor&&n.focus)}function ys(){return Pt()}function gs(n,e,t){const s=Nt(e,e.mode,t);return{anchor:s.start,focus:s.end,mode:e.mode}}function _t(n,e,t){return n.anchor?n.mode==="line"?{...n,focus:It(e.line,t(e.line)).end}:n.mode==="word"?{...n,focus:Nt(e,"word",t).end}:{...n,focus:{line:e.line,col:ct(t(e.line),e.col)}}:n}function Lt(n){return!n.anchor||!n.focus?null:ps(n.anchor,n.focus)}function Ss(n,e,t){const s=n.wrappedToNext?n.colChars.length-1:n.contentCols-1,i=Math.min(t,s);let r=Math.max(0,e);for(;r>0&&n.colChars[r]===null;)r-=1;if(r>i)return"";let o="";for(let l=r;l<=i;l+=1)o+=n.colChars[l]??"";return o}function _s(n,e){const t=Lt(n);if(!t)return null;let s="";for(let i=t.start.line;i<=t.end.line;i+=1){const r=e(i),o=i===t.start.line?t.start.col:0,l=i===t.end.line?t.end.col:r.colChars.length-1;s+=Ss(r,o,l),i<t.end.line&&!r.wrappedToNext&&(s+=`
|
|
32
|
+
`)}return s}function xs(n,e,t,s){const i=Lt(n);if(!i)return[];const r=e+t-1,o=[];for(let l=Math.max(i.start.line,e);l<=Math.min(i.end.line,r);l+=1){const u=l-e;if(l===i.start.line&&l===i.end.line){const f=s==null?void 0:s(l),x=f?gt(f,i.end.col):i.end.col;o.push({row:u,x:i.start.col,width:x-i.start.col+1});continue}if(l===i.start.line){const f=s?Math.max(s(l).colChars.length-i.start.col,0):Number.MAX_SAFE_INTEGER;o.push({row:u,x:i.start.col,width:f});continue}if(l===i.end.line){const f=s==null?void 0:s(l),x=f?gt(f,i.end.col):i.end.col;o.push({row:u,x:0,width:x+1});continue}const a=s?s(l).colChars.length:Number.MAX_SAFE_INTEGER;o.push({row:u,x:0,width:a})}return o}function Bt(){var e;if(typeof navigator>"u")return!1;const n=((e=navigator.userAgentData)==null?void 0:e.platform)??navigator.platform??"";return/mac|iphone|ipad|ipod/iu.test(n)?!0:/mac os x/iu.test(navigator.userAgent??"")}function bs(n){return n.altKey?!1:!!(Bt()?n.metaKey:n.ctrlKey)}function Ts(n){return bs(n)&&n.key.toLowerCase()==="c"}function Es(n){return n.shiftKey&&n.key==="Insert"&&!n.ctrlKey&&!n.altKey&&!n.metaKey?!0:n.altKey||n.key.toLowerCase()!=="v"?!1:!!(Bt()?n.metaKey:n.ctrlKey)}async function Ft(n){var t;if(!n)return;if(typeof navigator<"u"&&((t=navigator.clipboard)!=null&&t.writeText))try{await navigator.clipboard.writeText(n);return}catch{}if(typeof document>"u"||typeof document.execCommand!="function")throw new Error("clipboard unavailable");const e=document.createElement("textarea");e.value=n,e.setAttribute("readonly","true"),e.style.position="fixed",e.style.left="-9999px",e.style.top="0",document.body.appendChild(e);try{if(e.select(),!document.execCommand("copy"))throw new Error("execCommand copy failed")}finally{e.remove()}}async function Rs(n){n&&await Ft(n)}function Cs(n,e){return!e||!n.clipboardData?!1:(n.clipboardData.setData("text/plain",e),n.preventDefault(),!0)}const vs="/assets/ghostty-vt-BKQMf-5X.wasm",Ge=0,xt=-3,Ms=11,Ds=12,As=13,Os=14,ks=1,Hs=2,Is=9,Ns=1,Ps=0,Ls=1,Bs=2,Fs=0,Gs=1,Us=2,zs=4,Ys=2004,Vs=9,Ks=1e3,Ws=1002,$s=1003,js=1005,bt=1006,qs=1015,Tt=1016;let Qe=null;function O(n,e){if(n!==Ge)throw new Error(`${e} failed with result ${n}`)}function Gt(n){const e=n.trim().replace(/^#/,"");if(e.length!==6)throw new Error(`expected #RRGGBB color, received: ${n}`);return[Number.parseInt(e.slice(0,2),16),Number.parseInt(e.slice(2,4),16),Number.parseInt(e.slice(4,6),16)]}function Xs(n){const t=[...[n.black,n.red,n.green,n.yellow,n.blue,n.magenta,n.cyan,n.white,n.brightBlack,n.brightRed,n.brightGreen,n.brightYellow,n.brightBlue,n.brightMagenta,n.brightCyan,n.brightWhite].map(Gt)],s=[0,95,135,175,215,255];for(const i of s)for(const r of s)for(const o of s)t.push([i,r,o]);for(let i=0;i<24;i+=1){const r=8+i*10;t.push([r,r,r])}return t}function Js(n){let e=0;return n&1&&(e+=4),n&4&&(e+=8),n&2&&(e+=16),e}function Ze(n){return n<0||n>223?null:String.fromCharCode(n+32)}function Qs(n){switch(n){case 1:return 0;case 3:return 1;case 2:return 2;case 4:return 64;case 5:return 65;case 6:return 66;case 7:return 67;case 8:return 128;case 9:return 129;case null:case void 0:return 3;default:return null}}function Ut(n){var t,s;let e=0;return n.shiftKey&&(e|=1),n.ctrlKey&&(e|=2),n.altKey&&(e|=4),n.metaKey&&(e|=8),(t=n.getModifierState)!=null&&t.call(n,"CapsLock")&&(e|=16),(s=n.getModifierState)!=null&&s.call(n,"NumLock")&&(e|=32),e}class Zs{constructor(e,t,s){this.bindings=e,this.typeName=t,this.ptr=s}get view(){return this.bindings.view(this.ptr,this.bindings.typeSize(this.typeName))}free(){this.bindings.freeBytes(this.ptr,this.bindings.typeSize(this.typeName))}}class er{constructor(e,t){m(this,"exports");m(this,"layout");m(this,"decoder",new TextDecoder);m(this,"encoder",new TextEncoder);this.exports=e,this.layout=t}buffer(){return this.exports.memory.buffer}bytes(e=0,t=this.buffer().byteLength-e){return new Uint8Array(this.buffer(),e,t)}view(e=0,t=this.buffer().byteLength-e){return new DataView(this.buffer(),e,t)}typeSize(e){const t=this.layout[e];if(!t)throw new Error(`unknown ghostty type: ${e}`);return t.size}field(e,t){const s=this.layout[e],i=s==null?void 0:s.fields[t];if(!s||!i)throw new Error(`unknown ghostty field: ${e}.${t}`);return i}allocStruct(e){const t=this.allocBytes(this.typeSize(e));return this.bytes(t,this.typeSize(e)).fill(0),new Zs(this,e,t)}allocBytes(e){return this.exports.ghostty_wasm_alloc_u8_array(e)}freeBytes(e,t){this.exports.ghostty_wasm_free_u8_array(e,t)}allocOpaque(){return this.exports.ghostty_wasm_alloc_opaque()}freeOpaque(e){this.exports.ghostty_wasm_free_opaque(e)}allocU8(){return this.exports.ghostty_wasm_alloc_u8()}freeU8(e){this.exports.ghostty_wasm_free_u8(e)}allocUsize(){return this.exports.ghostty_wasm_alloc_usize()}freeUsize(e){this.exports.ghostty_wasm_free_usize(e)}readPointer(e){return this.view().getUint32(e,!0)}readU8(e){return this.view().getUint8(e)}readUsize(e){return this.view().getUint32(e,!0)}readU64(e){return this.view().getBigUint64(e,!0)}setField(e,t,s,i){const r=this.field(t,s),o=r.offset;switch(r.type){case"u8":case"bool":e.setUint8(o,Number(i));return;case"u16":e.setUint16(o,Number(i),!0);return;case"u32":e.setUint32(o,Number(i),!0);return;case"u64":e.setBigUint64(o,BigInt(i),!0);return;case"usize":{e.setUint32(o,Number(i),!0);return}case"i32":case"enum":e.setInt32(o,Number(i),!0);return;default:throw new Error(`unsupported field type ${t}.${s}: ${r.type}`)}}writeString(e){const t=this.encoder.encode(e),s=this.allocBytes(t.length);return this.bytes(s,t.length).set(t),{ptr:s,len:t.length,free:()=>this.freeBytes(s,t.length)}}writeBytes(e){const t=this.allocBytes(e.length);return this.bytes(t,e.length).set(e),{ptr:t,len:e.length,free:()=>this.freeBytes(t,e.length)}}readOwnedUtf8(e,t){return this.decoder.decode(this.bytes(e,t))}createTerminal(e,t,s){const i=this.allocStruct("GhosttyTerminalOptions");this.setField(i.view,"GhosttyTerminalOptions","cols",e),this.setField(i.view,"GhosttyTerminalOptions","rows",t),this.setField(i.view,"GhosttyTerminalOptions","max_scrollback",s);const r=this.allocOpaque();try{return O(this.exports.ghostty_terminal_new(0,r,i.ptr),"ghostty_terminal_new"),this.readPointer(r)}finally{i.free(),this.freeOpaque(r)}}freeTerminal(e){this.exports.ghostty_terminal_free(e)}writeVt(e,t){const s=typeof t=="string"?this.encoder.encode(t):t,i=this.writeBytes(s);try{this.exports.ghostty_terminal_vt_write(e,i.ptr,i.len)}finally{i.free()}}resetTerminal(e){this.exports.ghostty_terminal_reset(e)}resizeTerminal(e,t,s,i){O(this.exports.ghostty_terminal_resize(e,t,s,Math.max(1,Math.round(i.width)),Math.max(1,Math.round(i.height))),"ghostty_terminal_resize")}scrollViewportDelta(e,t){const s=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(s.view,"GhosttyTerminalScrollViewport","tag",Bs),s.view.setBigInt64(this.field("GhosttyTerminalScrollViewport","value").offset,BigInt(t),!0),this.exports.ghostty_terminal_scroll_viewport(e,s.ptr)}finally{s.free()}}scrollViewportTop(e){const t=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(t.view,"GhosttyTerminalScrollViewport","tag",Ps),this.exports.ghostty_terminal_scroll_viewport(e,t.ptr)}finally{t.free()}}scrollViewportBottom(e){const t=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(t.view,"GhosttyTerminalScrollViewport","tag",Ls),this.exports.ghostty_terminal_scroll_viewport(e,t.ptr)}finally{t.free()}}setTerminalTheme(e,t){const s=this.allocStruct("GhosttyColorRgb"),i=this.allocStruct("GhosttyColorRgb"),r=this.allocStruct("GhosttyColorRgb"),o=Xs(t),l=this.allocBytes(o.length*3),u=(f,x)=>{const[R,k,b]=Gt(x);this.setField(f.view,"GhosttyColorRgb","r",R),this.setField(f.view,"GhosttyColorRgb","g",k),this.setField(f.view,"GhosttyColorRgb","b",b)};u(s,t.foreground),u(i,t.background),u(r,t.cursor);const a=this.bytes(l,o.length*3);o.forEach(([f,x,R],k)=>{const b=k*3;a[b]=f,a[b+1]=x,a[b+2]=R});try{O(this.exports.ghostty_terminal_set(e,Ms,s.ptr),"ghostty_terminal_set(foreground)"),O(this.exports.ghostty_terminal_set(e,Ds,i.ptr),"ghostty_terminal_set(background)"),O(this.exports.ghostty_terminal_set(e,As,r.ptr),"ghostty_terminal_set(cursor)"),O(this.exports.ghostty_terminal_set(e,Os,l),"ghostty_terminal_set(palette)")}finally{s.free(),i.free(),r.free(),this.freeBytes(l,o.length*3)}}readTerminalSize(e){const t=this.allocBytes(2),s=this.allocBytes(2);try{return O(this.exports.ghostty_terminal_get(e,ks,t),"ghostty_terminal_get(cols)"),O(this.exports.ghostty_terminal_get(e,Hs,s),"ghostty_terminal_get(rows)"),{cols:this.view().getUint16(t,!0),rows:this.view().getUint16(s,!0)}}finally{this.freeBytes(t,2),this.freeBytes(s,2)}}readScrollbar(e){const t=this.allocStruct("GhosttyTerminalScrollbar");try{return O(this.exports.ghostty_terminal_get(e,Is,t.ptr),"ghostty_terminal_get(scrollbar)"),{total:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","total").offset,!0)),offset:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","offset").offset,!0)),len:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","len").offset,!0))}}finally{t.free()}}isTerminalModeEnabled(e,t){const s=this.allocU8();try{return O(this.exports.ghostty_terminal_mode_get(e,t,s),"ghostty_terminal_mode_get"),this.readU8(s)!==0}finally{this.freeU8(s)}}setTerminalMode(e,t,s){O(this.exports.ghostty_terminal_mode_set(e,t,s?1:0),"ghostty_terminal_mode_set")}createFormatter(e,t,s){const i=this.allocStruct("GhosttyFormatterTerminalOptions"),r=this.field("GhosttyFormatterTerminalOptions","extra").offset,o=this.view(i.ptr+r,this.typeSize("GhosttyFormatterTerminalExtra")),l=this.field("GhosttyFormatterTerminalExtra","screen").offset,u=this.view(i.ptr+r+l,this.typeSize("GhosttyFormatterScreenExtra")),a=this.allocOpaque();try{this.setField(i.view,"GhosttyFormatterTerminalOptions","size",this.typeSize("GhosttyFormatterTerminalOptions")),this.setField(i.view,"GhosttyFormatterTerminalOptions","emit",t),this.setField(i.view,"GhosttyFormatterTerminalOptions","unwrap",s.unwrap),this.setField(i.view,"GhosttyFormatterTerminalOptions","trim",s.trim),this.setField(o,"GhosttyFormatterTerminalExtra","size",this.typeSize("GhosttyFormatterTerminalExtra")),this.setField(o,"GhosttyFormatterTerminalExtra","palette",s.includePalette),this.setField(u,"GhosttyFormatterScreenExtra","size",this.typeSize("GhosttyFormatterScreenExtra"));const f=this.field("GhosttyFormatterTerminalOptions","selection").offset;return i.view.setUint32(f,s.selectionPtr??0,!0),O(this.exports.ghostty_formatter_terminal_new(0,a,e,i.ptr),"ghostty_formatter_terminal_new"),this.readPointer(a)}finally{i.free(),this.freeOpaque(a)}}freeFormatter(e){this.exports.ghostty_formatter_free(e)}resolveViewportGridRef(e,t,s){const i=this.allocStruct("GhosttyPoint"),r=this.allocStruct("GhosttyGridRef");try{this.setField(i.view,"GhosttyPoint","tag",Ns);const o=this.field("GhosttyPoint","value").offset,l=this.view(i.ptr+o,this.typeSize("GhosttyPointCoordinate"));return this.setField(l,"GhosttyPointCoordinate","x",t),this.setField(l,"GhosttyPointCoordinate","y",s),this.exports.ghostty_terminal_grid_ref(e,i.ptr,r.ptr)!==Ge?(r.free(),null):r}finally{i.free()}}createViewportSelection(e,t,s){const i=Math.max(1,Math.floor(t)),r=Math.max(1,Math.floor(s)),o=this.resolveViewportGridRef(e,0,0);if(!o)return null;let l=null;for(let a=r-1;a>=0&&(l=this.resolveViewportGridRef(e,i-1,a),!l);a-=1);if(!l)return o.free(),null;const u=this.allocStruct("GhosttySelection");try{this.setField(u.view,"GhosttySelection","size",this.typeSize("GhosttySelection")),this.setField(u.view,"GhosttySelection","rectangle",!1);const a=this.field("GhosttySelection","start").offset,f=this.field("GhosttySelection","end").offset;return this.bytes(u.ptr+a,this.typeSize("GhosttyGridRef")).set(this.bytes(o.ptr,this.typeSize("GhosttyGridRef"))),this.bytes(u.ptr+f,this.typeSize("GhosttyGridRef")).set(this.bytes(l.ptr,this.typeSize("GhosttyGridRef"))),u}finally{o.free(),l.free()}}formatViewport(e,t,s,i){const r=this.readTerminalSize(e),o=this.createViewportSelection(e,Math.max(1,Math.min(r.cols,i.cols)),Math.max(1,Math.min(r.rows,i.rows))),l=this.createFormatter(e,t,{...s,selectionPtr:(o==null?void 0:o.ptr)??null});try{return this.formatFormatter(l)}finally{this.freeFormatter(l),o==null||o.free()}}formatFormatter(e){const t=this.allocOpaque(),s=this.allocUsize();try{O(this.exports.ghostty_formatter_format_alloc(e,0,t,s),"ghostty_formatter_format_alloc");const i=this.readPointer(t),r=this.readUsize(s),o=this.buffer().byteLength;try{if(r===0||i===0)return"";if(i<0||i>o||r>o-i)throw new Error(`ghostty_formatter_format_alloc returned invalid slice ptr=${i} len=${r} mem=${o}`);return this.readOwnedUtf8(i,r)}finally{r>0&&i!==0&&this.exports.ghostty_free(0,i,r)}}finally{this.freeOpaque(t),this.freeUsize(s)}}createRenderState(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_new(0,e),"ghostty_render_state_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderState(e){this.exports.ghostty_render_state_free(e)}updateRenderState(e,t){O(this.exports.ghostty_render_state_update(e,t),"ghostty_render_state_update")}getRenderStateValueResult(e,t,s){return this.exports.ghostty_render_state_get(e,t,s)}getRenderStateValue(e,t,s){O(this.getRenderStateValueResult(e,t,s),"ghostty_render_state_get")}setRenderStateValue(e,t,s){O(this.exports.ghostty_render_state_set(e,t,s),"ghostty_render_state_set")}getRenderStateColors(e,t){O(this.exports.ghostty_render_state_colors_get(e,t),"ghostty_render_state_colors_get")}createRenderStateRowIterator(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_row_iterator_new(0,e),"ghostty_render_state_row_iterator_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowIterator(e){this.exports.ghostty_render_state_row_iterator_free(e)}bindRenderStateRowIterator(e,t){const s=this.allocOpaque();try{this.view(s,4).setUint32(0,t,!0),this.getRenderStateValue(e,4,s)}finally{this.freeOpaque(s)}}nextRenderStateRowIterator(e){return this.exports.ghostty_render_state_row_iterator_next(e)!==0}getRenderStateRowValueResult(e,t,s){return this.exports.ghostty_render_state_row_get(e,t,s)}getRenderStateRowValue(e,t,s){O(this.getRenderStateRowValueResult(e,t,s),"ghostty_render_state_row_get")}setRenderStateRowValue(e,t,s){O(this.exports.ghostty_render_state_row_set(e,t,s),"ghostty_render_state_row_set")}createRenderStateRowCells(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_row_cells_new(0,e),"ghostty_render_state_row_cells_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowCells(e){this.exports.ghostty_render_state_row_cells_free(e)}bindRenderStateRowCells(e,t){const s=this.allocOpaque();try{this.view(s,4).setUint32(0,t,!0),this.getRenderStateRowValue(e,3,s)}finally{this.freeOpaque(s)}}nextRenderStateRowCell(e){return this.exports.ghostty_render_state_row_cells_next(e)!==0}selectRenderStateRowCell(e,t){O(this.exports.ghostty_render_state_row_cells_select(e,t),"ghostty_render_state_row_cells_select")}getRenderStateRowCellValueResult(e,t,s){return this.exports.ghostty_render_state_row_cells_get(e,t,s)}getRenderStateRowCellValue(e,t,s){O(this.getRenderStateRowCellValueResult(e,t,s),"ghostty_render_state_row_cells_get")}getRawRowValueResult(e,t,s){return this.exports.ghostty_row_get(e,t,s)}getRawRowValue(e,t,s){O(this.getRawRowValueResult(e,t,s),"ghostty_row_get")}getRawCellValueResult(e,t,s){return this.exports.ghostty_cell_get(e,t,s)}getRawCellValue(e,t,s){O(this.getRawCellValueResult(e,t,s),"ghostty_cell_get")}createKeyEncoder(){const e=this.allocOpaque();try{return O(this.exports.ghostty_key_encoder_new(0,e),"ghostty_key_encoder_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeKeyEncoder(e){this.exports.ghostty_key_encoder_free(e)}createMouseEncoder(){const e=this.allocOpaque(),t=this.allocU8();try{O(this.exports.ghostty_mouse_encoder_new(0,e),"ghostty_mouse_encoder_new");const s=this.readPointer(e);return this.view().setUint8(t,1),this.exports.ghostty_mouse_encoder_setopt(s,zs,t),s}finally{this.freeU8(t),this.freeOpaque(e)}}freeMouseEncoder(e){this.exports.ghostty_mouse_encoder_free(e)}resetMouseEncoder(e){this.exports.ghostty_mouse_encoder_reset(e)}encodeMouseEvent(e,t,s){const i=this.isTerminalModeEnabled(t,$s),r=this.isTerminalModeEnabled(t,Ws),o=this.isTerminalModeEnabled(t,Ks),l=this.isTerminalModeEnabled(t,Vs);if(!i&&!r&&!o&&!l||s.action==="motion"&&!(i||r&&s.anyButtonPressed)||l&&s.action!=="press"||!i&&!r&&!l&&s.action==="motion")return null;const u=Qs(s.button);if(u===null)return null;const a=Math.max(1,Math.floor(s.x/Math.max(1,s.cellWidth))+1),f=Math.max(1,Math.floor(s.y/Math.max(1,s.cellHeight))+1),x=Math.round(s.x+1),R=Math.round(s.y+1);let k=s.action==="release"&&!this.isTerminalModeEnabled(t,bt)&&!this.isTerminalModeEnabled(t,Tt)?3:u;if(s.action==="motion"&&(k+=32),k+=Js(s.mods),this.isTerminalModeEnabled(t,Tt)){const b=s.action==="release"?"m":"M";return`\x1B[<${k};${x};${R}${b}`}if(this.isTerminalModeEnabled(t,bt)){const b=s.action==="release"?"m":"M";return`\x1B[<${k};${a};${f}${b}`}if(this.isTerminalModeEnabled(t,qs))return`\x1B[${k};${a};${f}M`;if(this.isTerminalModeEnabled(t,js)||o||r||i||l){const b=Ze(k),E=Ze(a),K=Ze(f);return!b||!E||!K?null:`\x1B[M${b}${E}${K}`}return null}encodeKeyEvent(e,t,s){if(s.keyCode<=0)return null;const i=this.allocOpaque();let r=0,o=null;try{return O(this.exports.ghostty_key_event_new(0,i),"ghostty_key_event_new"),r=this.readPointer(i),this.exports.ghostty_key_encoder_setopt_from_terminal(e,t),this.exports.ghostty_key_event_set_action(r,s.action==="release"?Fs:s.action==="repeat"?Us:Gs),this.exports.ghostty_key_event_set_key(r,s.keyCode),this.exports.ghostty_key_event_set_mods(r,s.mods),this.exports.ghostty_key_event_set_consumed_mods(r,0),this.exports.ghostty_key_event_set_composing(r,s.composing?1:0),s.utf8&&(o=this.writeString(s.utf8),this.exports.ghostty_key_event_set_utf8(r,o.ptr,o.len)),typeof s.unshiftedCodepoint=="number"&&this.exports.ghostty_key_event_set_unshifted_codepoint(r,s.unshiftedCodepoint),this.encodeKeyHandle(e,r)}finally{o==null||o.free(),r!==0&&this.exports.ghostty_key_event_free(r),this.freeOpaque(i)}}encodeKeyHandle(e,t){const s=this.allocUsize();try{const i=this.exports.ghostty_key_encoder_encode(e,t,0,0,s);i!==xt&&i!==Ge&&O(i,"ghostty_key_encoder_encode(size)");const r=Math.max(0,this.readUsize(s));if(r===0)return null;const o=this.allocBytes(r),l=this.allocUsize();try{O(this.exports.ghostty_key_encoder_encode(e,t,o,r,l),"ghostty_key_encoder_encode");const u=this.readUsize(l);return u===0?null:this.readOwnedUtf8(o,u)}finally{this.freeBytes(o,r),this.freeUsize(l)}}finally{this.freeUsize(s)}}encodePaste(e,t){const s=this.writeString(t),i=this.allocUsize();try{const r=this.isTerminalModeEnabled(e,Ys),o=this.exports.ghostty_paste_encode(s.ptr,s.len,r?1:0,0,0,i);o!==xt&&o!==Ge&&O(o,"ghostty_paste_encode(size)");const l=Math.max(0,this.readUsize(i));if(l===0)return"";const u=this.allocBytes(l),a=this.allocUsize();try{return O(this.exports.ghostty_paste_encode(s.ptr,s.len,r?1:0,u,l,a),"ghostty_paste_encode"),this.readOwnedUtf8(u,this.readUsize(a))}finally{this.freeBytes(u,l),this.freeUsize(a)}}finally{s.free(),this.freeUsize(i)}}}async function tr(n){if((n.startsWith("/")||n.startsWith("./")||n.startsWith("../")||/^[A-Za-z]:[\\/]/.test(n))&&typeof Bun<"u")return Bun.file(n).arrayBuffer();const t=await fetch(n);if(!t.ok)throw new Error(`failed to load ghostty wasm: ${t.status} ${t.statusText}`);return t.arrayBuffer()}async function nr(){return Qe||(Qe=(async()=>{const n=await tr(vs),t=(await WebAssembly.instantiate(n,{env:{log(){}}})).instance.exports,s=new Uint8Array(t.memory.buffer),i=t.ghostty_type_json();let r=i;for(;s[r]!==0;)r+=1;const o=JSON.parse(new TextDecoder().decode(s.subarray(i,r)));return new er(t,o)})()),Qe}const Et=80,Ce=24,et=9,Pe=17,sr=48,zt="ghostty-official",Ue=9,ze=1e3,Ye=1002,Ve=1003,tt=1007,Le=1047,Be=1049,rr=[Ue,ze,Ye,Ve],Rt=1,Ct=3,vt=2,ir=4,or=5;class lr{constructor(e){this.content=e}translateToString(e){return e?this.content.replace(/\s+$/u,""):this.content}}class ar{constructor(){m(this,"active",{baseY:0,viewportY:0,length:Ce,getLine:e=>{const t=e-this.active.viewportY,s=this.visibleLines[t];return typeof s=="string"?new lr(s):null}});m(this,"visibleLines",Array.from({length:Ce},()=>""))}setViewport(e,t,s,i){this.active.viewportY=e,this.active.baseY=t,this.active.length=s,this.visibleLines=i}}function cr(n){return!(n.key.length===1&&!n.ctrlKey&&!n.altKey&&!n.metaKey)}function dr(n,e){const t=n.slice(0,e).map(s=>s.text);for(;t.length<e;)t.push("");return t}function Fe(n){return Ut({shiftKey:!!n.shiftKey,ctrlKey:!!n.ctrlKey,altKey:!!n.altKey,metaKey:!!n.metaKey,getModifierState:()=>!1})}class ur{constructor(){m(this,"terminal",null)}activate(e){this.terminal=e instanceof We?e:null}fit(){const e=this.proposeDimensions();!this.terminal||!e||this.terminal.resize(e.cols,e.rows)}proposeDimensions(){var e;return((e=this.terminal)==null?void 0:e.measureSizeFromElement())??null}dispose(){this.terminal=null}}class We{constructor(e,t,s,i,r,o){m(this,"buffer",new ar);m(this,"_core",{_renderService:{dimensions:{css:{cell:{width:et,height:Pe}}}}});m(this,"options");m(this,"element",null);m(this,"textarea",null);m(this,"cols",Et);m(this,"rows",Ce);m(this,"bindings");m(this,"terminalHandle");m(this,"keyEncoderHandle");m(this,"mouseEncoderHandle");m(this,"renderState");m(this,"dataListeners",new Set);m(this,"selectionListeners",new Set);m(this,"lastNotifiedSelectionText",null);m(this,"addons",new Set);m(this,"screenElement",null);m(this,"renderer",null);m(this,"renderRaf",null);m(this,"disposed",!1);m(this,"disableStdin");m(this,"customKeyEventHandler",()=>!0);m(this,"imeIsComposing",!1);m(this,"lastCompositionCommit",null);m(this,"selectionState",Pt());m(this,"lineCache",new Map);m(this,"lastViewportOffset",0);m(this,"lastViewportRows",Ce);m(this,"lastRenderedRows",[]);m(this,"pointerDrag",{active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null});m(this,"autoScrollTimer",null);m(this,"domEventDisposers",[]);m(this,"copyShortcutSuppressed",!1);m(this,"scrollbarThumb",null);m(this,"scrollbarFadeTimer",null);m(this,"pressedMouseButtons",new Set);m(this,"wheelPixelDelta",0);m(this,"mouseDragActive",!1);this.bindings=e,this.terminalHandle=t,this.keyEncoderHandle=s,this.mouseEncoderHandle=i,this.renderState=r,this.options=o,this.disableStdin=!!o.disableStdin}static async create(e){const t=await nr(),s=t.createTerminal(Et,Ce,e.scrollback);let i=0,r=0,o=null;try{return t.setTerminalTheme(s,e.theme),i=t.createKeyEncoder(),r=t.createMouseEncoder(),o=pt(t),new We(t,s,i,r,o,e)}catch(l){throw o&&Xe(o),i!==0&&t.freeKeyEncoder(i),r!==0&&t.freeMouseEncoder(r),t.freeTerminal(s),l}}open(e){if(this.disposed||this.element)return;const t=document.createElement("div");t.className="xterm",t.style.position="absolute",t.style.inset="0",t.style.overflow="hidden",t.style.width="100%",t.style.height="100%",t.style.backgroundColor=this.options.theme.background,t.style.color=this.options.theme.foreground,t.style.fontFamily=this.options.fontFamily,t.style.fontSize=`${this.options.fontSize}px`,t.style.lineHeight="1.2";const s=document.createElement("div");s.className="xterm-viewport",s.style.width="100%",s.style.height="100%",s.style.overflow="hidden",s.style.position="relative";const i=document.createElement("div");i.className="xterm-screen",i.style.width="100%",i.style.height="100%",i.style.position="relative",i.style.userSelect="none",i.style.webkitUserSelect="none",i.style.backgroundColor=this.options.theme.background;const r=document.createElement("div");r.className="xterm-helper-textarea",r.setAttribute("aria-label","Terminal Input"),r.setAttribute("role","textbox"),r.setAttribute("contenteditable","true"),r.setAttribute("autocorrect","off"),r.setAttribute("autocapitalize","off"),r.setAttribute("spellcheck","false"),r.style.position="absolute",r.style.opacity="1",r.style.pointerEvents="none",r.style.left="0",r.style.top="0",r.style.minWidth="1px",r.style.minHeight="1px",r.style.whiteSpace="pre",r.style.border="0",r.style.padding="0",r.style.margin="0",r.style.color=this.options.theme.foreground,r.style.backgroundColor="transparent",r.style.caretColor="transparent",r.style.overflow="visible",r.style.outline="none",r.style.boxShadow="none",r.style.fontFamily=this.options.fontFamily,r.style.fontSize=`${this.options.fontSize}px`,r.style.userSelect="text",r.style.webkitUserSelect="text";const o=document.createElement("div");o.className="xterm-scrollbar-track",o.style.position="absolute",o.style.top="0",o.style.right="0",o.style.width="8px",o.style.height="100%",o.style.backgroundColor="transparent",o.style.pointerEvents="none";const l=document.createElement("div");l.className="xterm-scrollbar-thumb",l.style.position="absolute",l.style.top="0",l.style.right="0",l.style.width="6px",l.style.marginRight="1px",l.style.borderRadius="3px",l.style.backgroundColor="rgba(128, 128, 128, 0.5)",l.style.pointerEvents="none",l.style.transition="opacity 0.15s ease",l.style.opacity="0",o.appendChild(l),s.appendChild(i),t.appendChild(s),t.appendChild(r),t.appendChild(o),e.appendChild(t),this.element=t,this.screenElement=i,this.textarea=r,this.scrollbarThumb=l,this.renderer=new vn({screenElement:i,theme:this.options.theme,fontFamily:this.options.fontFamily,fontSize:this.options.fontSize}),this.syncInputState(),this.bindDomEvents(),this.updateCellDimensions();const u=this.measureSizeFromElement();u?this.resize(u.cols,u.rows):this.render()}loadAddon(e){e.activate(this),this.addons.add(e)}onData(e){return this.dataListeners.add(e),{dispose:()=>{this.dataListeners.delete(e)}}}attachCustomKeyEventHandler(e){this.customKeyEventHandler=e}onSelectionChange(e){return this.selectionListeners.add(e),{dispose:()=>{this.selectionListeners.delete(e)}}}hasSelection(){return St(this.selectionState)}getSelection(){return this.getSelectionText()??""}clearSelection(){this.disposed||this.clearSelectionState()}startTouchSelection(e,t,s="word"){return this.disposed?!1:this.beginSelectionAt(e,t,s)}updateTouchSelection(e,t){this.disposed||this.updateSelectionDrag(e,t)}endTouchSelection(){this.disposed||!this.pointerDrag.active||(this.stopAutoScroll(),this.pointerDrag.active=!1,this.render())}write(e){if(this.disposed)return;const t=this.isAltScreenActive();this.bindings.writeVt(this.terminalHandle,e);const s=this.isAltScreenActive();t&&!s&&this.clearMouseTrackingModes(),this.scheduleRender()}clearMouseTrackingModes(){if(!this.disposed){for(const e of rr)this.bindings.setTerminalMode(this.terminalHandle,e,!1);this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.pressedMouseButtons.clear(),this.mouseDragActive=!1}}isAltScreenActive(){return this.isModeEnabled(Le)||this.isModeEnabled(Be)}reset(){this.disposed||(this.lineCache.clear(),this.clearSelectionState(!1),this.bindings.resetTerminal(this.terminalHandle),this.scheduleRender())}refresh(){this.disposed||this.render()}resize(e,t){if(this.disposed)return;const s=Math.max(2,Math.floor(e)),i=Math.max(2,Math.floor(t));this.cols=s,this.rows=i,this.clearSelectionState(!1),this.bindings.resizeTerminal(this.terminalHandle,s,i,this.cellDimensions()),this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.scheduleRender()}scrollLines(e){this.disposed||e===0||(this.bindings.scrollViewportDelta(this.terminalHandle,e),this.render())}scrollToTop(){this.disposed||(this.bindings.scrollViewportTop(this.terminalHandle),this.render())}scrollToBottom(){this.disposed||(this.bindings.scrollViewportBottom(this.terminalHandle),this.render())}exportModeSnapshot(){return{mouseX10:this.isModeEnabled(Ue),mouseNormal:this.isModeEnabled(ze),mouseButton:this.isModeEnabled(Ye),mouseAny:this.isModeEnabled(Ve),mouseUtf8:this.isModeEnabled(1005),mouseSgr:this.isModeEnabled(1006),mouseSgrPixels:this.isModeEnabled(1016),mouseUrxvt:this.isModeEnabled(1015),altScroll:this.isModeEnabled(tt),altScreen1047:this.isModeEnabled(Le),altScreen1049:this.isModeEnabled(Be)}}restoreModeSnapshot(e){this.bindings.setTerminalMode(this.terminalHandle,Ue,e.mouseX10),this.bindings.setTerminalMode(this.terminalHandle,ze,e.mouseNormal),this.bindings.setTerminalMode(this.terminalHandle,Ye,e.mouseButton),this.bindings.setTerminalMode(this.terminalHandle,Ve,e.mouseAny),this.bindings.setTerminalMode(this.terminalHandle,1005,e.mouseUtf8),this.bindings.setTerminalMode(this.terminalHandle,1006,e.mouseSgr),this.bindings.setTerminalMode(this.terminalHandle,1016,e.mouseSgrPixels),this.bindings.setTerminalMode(this.terminalHandle,1015,e.mouseUrxvt),this.bindings.setTerminalMode(this.terminalHandle,tt,e.altScroll),this.bindings.setTerminalMode(this.terminalHandle,Le,e.altScreen1047),this.bindings.setTerminalMode(this.terminalHandle,Be,e.altScreen1049),this.bindings.resetMouseEncoder(this.mouseEncoderHandle)}handleViewportGesture(e){if(this.disposed||e.deltaY===0)return!1;const t=this.gestureToLines(e);if(t===0)return!1;const s=this.getInputRoutingState();if(s.mouseReporting){const i=t<0?ir:or;let r=!1;for(let o=0;o<Math.abs(t);o+=1)r=this.emitMouseInput({action:"press",button:i,clientX:e.clientX,clientY:e.clientY,mods:Fe(e),anyButtonPressed:this.pressedMouseButtons.size>0})||r;return r}return s.altScroll?this.emitAltScrollInput(t):(this.scrollLines(t),!0)}paste(e){if(this.disposed||this.disableStdin||!e)return;const t=this.bindings.encodePaste(this.terminalHandle,e);t&&this.emitData(t)}focus(){var e;(e=this.textarea)==null||e.focus({preventScroll:!0})}getRendererKind(){var e;return((e=this.renderer)==null?void 0:e.kind)??"unknown"}setTheme(e){var t;this.bindings.setTerminalTheme(this.terminalHandle,e),this.options.theme=e,this.element&&(this.element.style.backgroundColor=e.background,this.element.style.color=e.foreground),this.screenElement&&(this.screenElement.style.backgroundColor=e.background),(t=this.renderer)==null||t.setTheme(e),this.scheduleRender()}setDisableStdin(e){this.disableStdin=e,this.syncInputState()}measureSizeFromElement(){const e=this.element;if(!e)return null;const t=e.getBoundingClientRect(),{width:s,height:i}=this.cellDimensions();return t.width===0||t.height===0||s<=0||i<=0?null:{cols:Math.max(2,Math.floor(t.width/s)),rows:Math.max(2,Math.floor(t.height/i))}}dispose(){var e,t;if(!this.disposed){this.disposed=!0,this.renderRaf!==null&&(cancelAnimationFrame(this.renderRaf),this.renderRaf=null),this.stopAutoScroll(),this.updateSelectionTextProbe(null),this.clearDomEventListeners(),this.scrollbarFadeTimer&&(clearTimeout(this.scrollbarFadeTimer),this.scrollbarFadeTimer=null);for(const s of this.addons)s.dispose();this.addons.clear(),(e=this.renderer)==null||e.dispose(),this.renderer=null,(t=this.element)==null||t.remove(),this.element=null,this.screenElement=null,this.textarea=null,this.scrollbarThumb=null,Xe(this.renderState),this.bindings.freeMouseEncoder(this.mouseEncoderHandle),this.bindings.freeKeyEncoder(this.keyEncoderHandle),this.bindings.freeTerminal(this.terminalHandle)}}cellDimensions(){return this._core._renderService.dimensions.css.cell}syncInputState(){this.textarea&&(this.textarea.readOnly=this.disableStdin,this.textarea.tabIndex=this.disableStdin?-1:0,this.disableStdin&&document.activeElement===this.textarea&&this.textarea.blur())}bindDomEvents(){const e=this.element,t=this.textarea;if(!e||!t)return;e.addEventListener("click",()=>{this.disableStdin||this.focus()}),(this.screenElement??e).addEventListener("mousedown",r=>{if(r instanceof MouseEvent){if(this.disableStdin||this.focus(),this.getInputRoutingState().mouseReporting){const o=this.mouseButtonFromEvent(r);if(o===null)return;this.clearSelectionState(),this.pressedMouseButtons.add(o),this.mouseDragActive=!0,this.emitMouseInput({action:"press",button:o,clientX:r.clientX,clientY:r.clientY,mods:Fe(r),anyButtonPressed:!0}),r.preventDefault();return}r.button===0&&(this.mouseDragActive=!0,this.beginPointerSelection(r),r.preventDefault())}}),e.addEventListener("wheel",r=>{this.handleViewportGesture({source:"wheel",deltaY:r.deltaY,deltaMode:r.deltaMode,clientX:r.clientX,clientY:r.clientY,shiftKey:r.shiftKey,ctrlKey:r.ctrlKey,altKey:r.altKey,metaKey:r.metaKey})&&r.preventDefault()},{passive:!1});const i=typeof window<"u"&&typeof window.addEventListener=="function"?window:null;if(i){const r=l=>{if(this.mouseDragActive){if(this.getInputRoutingState().mouseReporting){this.emitMouseInput({action:"motion",button:this.mouseButtonFromButtons(l.buttons),clientX:l.clientX,clientY:l.clientY,mods:Fe(l),anyButtonPressed:this.pressedMouseButtons.size>0||l.buttons>0});return}this.updatePointerSelection(l)}},o=l=>{if(this.mouseDragActive){if(this.mouseDragActive=!1,this.getInputRoutingState().mouseReporting){const u=this.mouseButtonFromEvent(l);u!==null&&this.pressedMouseButtons.delete(u),this.emitMouseInput({action:"release",button:u,clientX:l.clientX,clientY:l.clientY,mods:Fe(l),anyButtonPressed:this.pressedMouseButtons.size>0});return}this.finishPointerSelection(l)}};i.addEventListener("mousemove",r),i.addEventListener("mouseup",o),this.domEventDisposers.push(()=>{i.removeEventListener("mousemove",r),i.removeEventListener("mouseup",o)})}t.addEventListener("keydown",r=>{const o=this.getSelectionText();if(o&&Ts(r)){r.preventDefault(),Rs(o).catch(()=>{}),this.clearSelectionState(),this.copyShortcutSuppressed=!0,this.clearTextarea();return}if(!this.customKeyEventHandler(r)||this.disableStdin||this.imeIsComposing||r.keyCode===229||Es(r)||!cr(r))return;const l=this.encodeKeyboardEvent(r,r.repeat?"repeat":"press");l&&(r.preventDefault(),this.emitData(l),this.clearTextarea())}),t.addEventListener("keyup",r=>{if(this.copyShortcutSuppressed){const l=r.key.toLowerCase();if(l==="c"){r.preventDefault();return}if(l==="control"||l==="meta"||l==="os"){this.copyShortcutSuppressed=!1,r.preventDefault();return}}if(this.disableStdin||this.imeIsComposing)return;const o=this.encodeKeyboardEvent(r,"release");o&&(r.preventDefault(),this.emitData(o),this.clearTextarea())}),t.addEventListener("compositionstart",()=>{this.imeIsComposing=!0,this.lastCompositionCommit=null,this.syncTextareaPositionToCursor()}),t.addEventListener("compositionupdate",()=>{this.syncTextareaPositionToCursor()}),t.addEventListener("compositionend",r=>{this.imeIsComposing=!1;const o=r.data??"";o&&(this.lastCompositionCommit={data:o,at:Date.now()},this.emitData(o),this.clearTextarea())}),t.addEventListener("beforeinput",r=>{if(this.disableStdin||r.inputType==="insertFromPaste")return;const o=r.data??"";if(!o||r.isComposing||this.imeIsComposing)return;const l=this.lastCompositionCommit;if(l&&l.data===o&&Date.now()-l.at<40){this.lastCompositionCommit=null,r.preventDefault(),this.clearTextarea();return}this.lastCompositionCommit=null,r.preventDefault(),this.emitData(o),this.clearTextarea()}),t.addEventListener("paste",r=>{var l;if(this.disableStdin)return;const o=((l=r.clipboardData)==null?void 0:l.getData("text/plain"))??"";o&&(r.preventDefault(),this.paste(o),this.clearTextarea())}),t.addEventListener("copy",r=>{const o=this.getSelectionText();o&&Cs(r,o)}),t.addEventListener("input",()=>{if(this.disableStdin||this.imeIsComposing)return;const r=t.textContent??"";if(!r){this.clearTextarea();return}const o=this.lastCompositionCommit;if(o&&o.data===r&&Date.now()-o.at<40){this.lastCompositionCommit=null,this.clearTextarea();return}this.lastCompositionCommit=null,this.emitData(r),this.clearTextarea()})}encodeKeyboardEvent(e,t){const s=ht(e.code);if(s===0)return null;const i=e.key.length===1&&!e.ctrlKey&&!e.metaKey?e.key:null;return this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:t,keyCode:s,mods:Ut(e),composing:e.isComposing,utf8:i,unshiftedCodepoint:An(e.code)})}getInputRoutingState(){const e=this.isModeEnabled(Ue)||this.isModeEnabled(ze)||this.isModeEnabled(Ye)||this.isModeEnabled(Ve),t=this.isModeEnabled(Le)||this.isModeEnabled(Be);return{mouseReporting:e,altScroll:!e&&t&&this.isModeEnabled(tt)}}gestureToLines(e){const t=this.cellDimensions().height||Pe;if(e.source==="wheel"){if(e.deltaMode===1)return this.wheelPixelDelta=0,e.deltaY>0?Math.ceil(e.deltaY):Math.floor(e.deltaY);if(e.deltaMode===2){this.wheelPixelDelta=0;const i=Math.max(1,this.rows),r=e.deltaY*i;return r>0?Math.ceil(r):Math.floor(r)}this.wheelPixelDelta+=e.deltaY;const s=this.wheelPixelDelta>0?Math.floor(this.wheelPixelDelta/t):Math.ceil(this.wheelPixelDelta/t);return s!==0&&(this.wheelPixelDelta-=s*t),s}return e.deltaY>0?Math.ceil(e.deltaY/t):Math.floor(e.deltaY/t)}isModeEnabled(e){return this.bindings.isTerminalModeEnabled(this.terminalHandle,e)}mouseButtonFromEvent(e){switch(e.button){case 0:return Rt;case 1:return Ct;case 2:return vt;default:return null}}mouseButtonFromButtons(e){return e&1?Rt:e&4?Ct:e&2?vt:null}pointerPositionFromClient(e,t){var o;const s=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!s)return null;const i=Math.max(1,s.width),r=Math.max(1,s.height);return{x:Math.max(0,Math.min(i-1,e-s.left)),y:Math.max(0,Math.min(r-1,t-s.top))}}emitMouseInput(e){var o;if(this.disableStdin)return!1;const t=this.pointerPositionFromClient(e.clientX,e.clientY);if(!t)return!1;const s=this.cellDimensions(),i=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!i)return!1;const r=this.bindings.encodeMouseEvent(this.mouseEncoderHandle,this.terminalHandle,{action:e.action,button:e.button,mods:e.mods,x:t.x,y:t.y,anyButtonPressed:e.anyButtonPressed,screenWidth:Math.max(1,Math.round(i.width)),screenHeight:Math.max(1,Math.round(i.height)),cellWidth:Math.max(1,Math.round(s.width||et)),cellHeight:Math.max(1,Math.round(s.height||Pe))});return r?(this.emitData(r),!0):!1}emitAltScrollInput(e){const t=ht(e<0?"ArrowUp":"ArrowDown");if(t===0)return!1;let s=!1;for(let i=0;i<Math.abs(e);i+=1){const r=this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:"press",keyCode:t,mods:0,composing:!1,utf8:null,unshiftedCodepoint:null});r&&(this.emitData(r),s=!0)}return s}emitData(e){for(const t of this.dataListeners)t(e)}clearTextarea(){this.textarea&&(this.textarea.textContent="")}syncTextareaPositionToCursor(){const e=this.textarea,t=this.screenElement;if(!e||!t)return;const{width:s,height:i}=this.cellDimensions();if(s<=0||i<=0)return;const r=pt(this.bindings);let o=0,l=0;try{wt(r,this.terminalHandle);const f=st(r);f.cursor.x!==null&&f.cursor.y!==null&&(o=f.cursor.x,l=f.cursor.y)}finally{Xe(r)}const u=o*s,a=l*i;e.style.left=`${u}px`,e.style.top=`${a}px`,e.style.width=`${Math.max(1,s)}px`,e.style.height=`${Math.max(1,i)}px`,e.style.lineHeight=`${i}px`,e.style.fontFamily=this.options.fontFamily,e.style.fontSize=`${this.options.fontSize}px`}scheduleRender(){this.renderRaf===null&&(this.renderRaf=requestAnimationFrame(()=>{this.renderRaf=null,this.render()}))}render(){if(this.disposed||!this.screenElement||!this.renderer)return;const e=this.bindings.readScrollbar(this.terminalHandle),t=Math.max(1,e.len||this.rows);wt(this.renderState,this.terminalHandle);const s=st(this.renderState),i=Array.from(us(this.renderState));this.cols=Math.max(2,s.cols),this.rows=Math.max(2,s.rows||t),this.lastViewportOffset=e.offset,this.lastViewportRows=this.rows,this.lastRenderedRows=i;for(const a of i)this.lineCache.set(e.offset+a.y,yt(a.cells,a.wrap));const r=xs(this.selectionState,this.lastViewportOffset,this.lastViewportRows,a=>this.getLineModel(a)),o=this.getSelectionText();this.renderer.render({meta:s,rows:i,cellDimensions:this.cellDimensions(),selectionRects:r,selectionColor:this.options.theme.selectionBackground});const l=dr(i,this.rows),u=Math.max(0,e.total-e.len);this.buffer.setViewport(e.offset,u,e.total,l),this.updateSelectionTextProbe(o),this.updateScrollbar(e)}updateScrollbar(e){var u;const t=this.scrollbarThumb;if(!t)return;const s=((u=this.screenElement)==null?void 0:u.clientHeight)??0;if(s===0||e.total<=e.len){t.style.opacity="0";return}const i=e.len/e.total,r=Math.max(20,i*s),l=e.offset/Math.max(1,e.total-e.len)*(s-r);t.style.height=`${r}px`,t.style.transform=`translateY(${l}px)`,t.style.opacity="1",this.scrollbarFadeTimer&&clearTimeout(this.scrollbarFadeTimer),this.scrollbarFadeTimer=setTimeout(()=>{t.style.opacity="0"},800)}updateCellDimensions(){if(!this.element)return;const e=document.createElement("span");e.textContent="WWWWWWWWWW",e.style.position="absolute",e.style.visibility="hidden",e.style.whiteSpace="pre",e.style.fontFamily=this.options.fontFamily,e.style.fontSize=`${this.options.fontSize}px`,e.style.lineHeight="1.2",this.element.appendChild(e);const t=e.getBoundingClientRect();e.remove();const s=Math.max(1,globalThis.devicePixelRatio??1),i=t.width>0?t.width/10:et,r=t.height>0?t.height:Pe;this._core._renderService.dimensions.css.cell.width=Math.max(1,Math.round(i*s))/s,this._core._renderService.dimensions.css.cell.height=Math.max(1,Math.round(r*s))/s}clearSelectionState(e=!0){this.selectionState=ys(),this.pressedMouseButtons.clear(),this.wheelPixelDelta=0,this.pointerDrag={active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null},this.copyShortcutSuppressed=!1,this.stopAutoScroll(),this.updateSelectionTextProbe(null),e&&this.screenElement&&this.renderer&&this.render()}beginSelectionAt(e,t,s){const i=this.hitTest(e,t);return i?(this.pointerDrag={active:!0,moved:!1,mode:s,lastClientX:e,lastClientY:t},this.selectionState=gs(this.selectionState,{...i,mode:s},r=>this.getLineModel(r)),this.updateAutoScroll(),this.render(),!0):!1}updateSelectionDrag(e,t){if(!this.pointerDrag.active)return;const s=this.hitTest(e,t);this.pointerDrag.lastClientX=e,this.pointerDrag.lastClientY=t,s&&(this.pointerDrag.moved=!0,this.selectionState=_t(this.selectionState,s,i=>this.getLineModel(i)),this.render()),this.updateAutoScroll()}beginPointerSelection(e){this.beginSelectionAt(e.clientX,e.clientY,this.selectionModeFromClickDetail(e.detail))}updatePointerSelection(e){this.updateSelectionDrag(e.clientX,e.clientY)}finishPointerSelection(e){var s,i,r,o;if(!this.pointerDrag.active||e.button!==0)return;this.pointerDrag.lastClientX=e.clientX,this.pointerDrag.lastClientY=e.clientY,this.stopAutoScroll();const t=this.pointerDrag.mode==="character"&&!this.pointerDrag.moved&&((s=this.selectionState.anchor)==null?void 0:s.line)===((i=this.selectionState.focus)==null?void 0:i.line)&&((r=this.selectionState.anchor)==null?void 0:r.col)===((o=this.selectionState.focus)==null?void 0:o.col);if(this.pointerDrag.active=!1,t){this.clearSelectionState();return}this.render()}selectionModeFromClickDetail(e){return e>=3?"line":e===2?"word":"character"}hitTest(e,t){var R;const s=(R=this.screenElement)==null?void 0:R.getBoundingClientRect();if(!s)return null;const{width:i,height:r}=this.cellDimensions();if(i<=0||r<=0)return null;const o=e-s.left,l=t-s.top,u=Math.max(this.cols-1,0),a=Math.max(this.lastViewportRows-1,0),f=Math.max(0,Math.min(u,Math.floor(o/i))),x=Math.max(0,Math.min(a,Math.floor(l/r)));return{line:this.lastViewportOffset+x,col:f}}getLineModel(e){const t=this.lineCache.get(e);if(t)return t;const s=e-this.lastViewportOffset,i=this.lastRenderedRows[s];return i?yt(i.cells,i.wrap):hs}getSelectionText(){return St(this.selectionState)?_s(this.selectionState,e=>this.getLineModel(e)):null}updateSelectionTextProbe(e){if(globalThis.__tmexE2eTerminalSelectionText=e,e!==this.lastNotifiedSelectionText){this.lastNotifiedSelectionText=e;for(const t of this.selectionListeners)t(e)}}updateAutoScroll(){var s;if(!this.pointerDrag.active||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(s=this.screenElement)==null?void 0:s.getBoundingClientRect();if(!e){this.stopAutoScroll();return}if(!(this.pointerDrag.lastClientY<e.top||this.pointerDrag.lastClientY>e.bottom)){this.stopAutoScroll();return}this.autoScrollTimer===null&&(this.autoScrollTimer=setInterval(()=>{this.stepAutoScroll()},sr))}stepAutoScroll(){var i;if(!this.pointerDrag.active||this.pointerDrag.lastClientX===null||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(i=this.screenElement)==null?void 0:i.getBoundingClientRect();if(!e){this.stopAutoScroll();return}let t=0;if(this.pointerDrag.lastClientY<e.top?t=-1:this.pointerDrag.lastClientY>e.bottom&&(t=1),t===0){this.stopAutoScroll();return}this.bindings.scrollViewportDelta(this.terminalHandle,t),this.render();const s=this.hitTest(this.pointerDrag.lastClientX,this.pointerDrag.lastClientY);s&&(this.selectionState=_t(this.selectionState,s,r=>this.getLineModel(r)),this.pointerDrag.moved=!0,this.render())}stopAutoScroll(){this.autoScrollTimer!==null&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null)}clearDomEventListeners(){for(;this.domEventDisposers.length>0;){const e=this.domEventDisposers.pop();e==null||e()}}}async function hr(n){return We.create(n)}function fr({visible:n,canPaste:e,onCopy:t,onPaste:s,onDismiss:i}){const{t:r}=Ke();if(!n)return null;const o=l=>{l.preventDefault()};return h.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:[h.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:o,onClick:t,"data-testid":"terminal-selection-copy",children:[h.jsx(wn,{className:"h-4 w-4"}),r("terminal.copy")]}),e&&h.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:o,onClick:s,"data-testid":"terminal-selection-paste",children:[h.jsx(mn,{className:"h-4 w-4"}),r("terminal.paste")]}),h.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:o,onClick:i,"aria-label":r("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:h.jsx(jt,{className:"h-4 w-4"})})]})}function Yt(n){if(!n)return n;const e=n.replace(/\r\n/g,`
|
|
33
|
+
`);return(e.endsWith(`
|
|
34
|
+
`)?e.slice(0,-1):e).replace(/\n/g,`\r
|
|
35
|
+
`)}const mr="\x1B[?1049h\x1B[H\x1B[2J";function pr(n){return mr+Yt(n)}function Mt(n,e){let t=e,s=0;for(const l of n)l===10&&!t&&(s+=1),t=l===13;const i=t;if(s===0)return{normalized:n,endedWithCR:i};const r=new Uint8Array(n.length+s);let o=0;t=e;for(const l of n)l===10&&!t&&(r[o]=13,o+=1),r[o]=l,o+=1,t=l===13;return{normalized:r,endedWithCR:i}}const wr=1.3,yr=36,gr=500,Sr=12;function _r(n,e){const t=d.useRef(!1);return d.useEffect(()=>{const s=n.current;if(!s||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;t.current=!0;let r=0,o=null,l=!1,u=0,a=0,f=0,x=null,R=!1;const k=()=>{x!==null&&(clearTimeout(x),x=null)},b=T=>T?!!(T.closest(".scrollbar")||T.closest(".slider")||T.closest(".xterm-scroll-area")):!1,E=(T,v,N)=>{const B=N instanceof Element?N:null;if(b(B))return!0;const V=document.elementFromPoint(T,v);if(b(V))return!0;const S=s.querySelector(".xterm");if(!(S instanceof HTMLElement))return!1;const C=S.getBoundingClientRect(),P=T>=C.left&&T<=C.right,F=v>=C.top&&v<=C.bottom;return!P||!F?!1:T>=C.right-yr},K=()=>[s.querySelector(".xterm-viewport"),s.querySelector(".xterm-scrollable-element")].filter(v=>v instanceof HTMLElement),y=T=>{if(o===null)return null;for(let v=0;v<T.length;v+=1){const N=T.item(v);if(N&&N.identifier===o)return N}return null},U=T=>{if(k(),T.touches.length!==1)return;const v=T.touches.item(0);v&&(o=v.identifier,r=v.clientY,u=0,l=E(v.clientX,v.clientY,T.target),a=v.clientX,f=v.clientY,R=!1,l||(x=setTimeout(()=>{var B;x=null;const N=(e==null?void 0:e())??null;(B=N==null?void 0:N.startTouchSelection)!=null&&B.call(N,a,f,"word")&&(R=!0)},gr)))},H=T=>{var P,F,I,j,Q,te,se,A,ie;const v=y(T.touches)??T.touches.item(0);if(!v)return;if(R){const G=(e==null?void 0:e())??null;(P=G==null?void 0:G.updateTouchSelection)==null||P.call(G,v.clientX,v.clientY),T.cancelable&&T.preventDefault();return}if(x!==null&&Math.hypot(v.clientX-a,v.clientY-f)>Sr&&k(),l||(l=E(v.clientX,v.clientY,T.target),l&&(u=0)),l)return;const N=v.clientY,B=r-N;if(r=N,B===0)return;let V=!1,S=!1;const C=(e==null?void 0:e())??null;if(C){const G=C==null?void 0:C._core,z=((Q=(j=(I=(F=G==null?void 0:G._renderService)==null?void 0:F.dimensions)==null?void 0:I.css)==null?void 0:j.cell)==null?void 0:Q.height)??18;u+=B*wr;const L=u>0?Math.floor(u/z):Math.ceil(u/z);if(typeof C.handleViewportGesture=="function")L!==0&&(V=C.handleViewportGesture({source:"touch",deltaY:L*z,clientX:v.clientX,clientY:v.clientY}),u-=L*z);else if(L!==0){const $=((se=(te=C.buffer)==null?void 0:te.active)==null?void 0:se.viewportY)??0;C.scrollLines(L);const g=((ie=(A=C.buffer)==null?void 0:A.active)==null?void 0:ie.viewportY)??0;V=$!==g,S=L<0&&$<=0&&g<=0,u-=L*z}}else{const G=K();if(G.length===0)return;for(const z of G){const L=z.scrollTop;z.scrollTop+=B;const $=z.scrollTop;Math.abs($-L)>0&&(V=!0),B<0&&$<=0&&(S=!0)}if(!V){const z=s.querySelector(".xterm");if(z instanceof HTMLElement){const L=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:B}),$=z.dispatchEvent(L);V=L.defaultPrevented||!$}}}T.cancelable&&(V||S)&&T.preventDefault()},W=T=>{var N;if(k(),!(o===null||!y(T.changedTouches))&&(o=null,u=0,l=!1,R)){R=!1;const B=(e==null?void 0:e())??null;(N=B==null?void 0:B.endTouchSelection)==null||N.call(B)}},Y=T=>{R&&T.preventDefault()};return s.addEventListener("touchstart",U,{passive:!0}),s.addEventListener("touchmove",H,{passive:!1}),s.addEventListener("touchend",W,{passive:!0}),s.addEventListener("touchcancel",W,{passive:!0}),s.addEventListener("contextmenu",Y),()=>{t.current=!1,k(),s.removeEventListener("touchstart",U),s.removeEventListener("touchmove",H),s.removeEventListener("touchend",W),s.removeEventListener("touchcancel",W),s.removeEventListener("contextmenu",Y)}},[n,e]),t}function xr({now:n,remoteSize:e,pendingLocalSize:t,ttlMs:s=2e3}){return!t||n-t.at>s?!0:t.cols===e.cols&&t.rows===e.rows}function br({currentSize:n,containerSize:e,force:t=!1}){return t?!0:n.cols!==e.cols||n.rows!==e.rows}function Tr({deviceId:n,paneId:e,deviceConnected:t,isSelectionInvalid:s,onResize:i,onSync:r,getContainerRect:o}){const l=d.useRef(null),u=d.useRef(null),a=d.useRef(null),f=d.useRef(null),x=d.useRef(0),R=d.useRef([]),k=d.useRef(null),b=d.useRef(null),E=d.useRef(o),K=d.useRef(!1),y=d.useRef(i),U=d.useRef(r);d.useEffect(()=>{y.current=i},[i]),d.useEffect(()=>{U.current=r},[r]),d.useEffect(()=>{E.current=o},[o]);const H=d.useCallback(()=>{var te,se,A,ie,G,z,L,$,g,_;const S=b.current,C=k.current;if(!S||!C||!S.element)return null;let P;try{const M=C.proposeDimensions();if(!M)throw new Error("fitAddon.proposeDimensions() returned null");P=Math.max(2,M.cols)}catch{const M=S._core,q=((ie=(A=(se=(te=M==null?void 0:M._renderService)==null?void 0:te.dimensions)==null?void 0:se.css)==null?void 0:A.cell)==null?void 0:ie.width)??9,X=(G=E.current)==null?void 0:G.call(E);if(!X||X.width===0)return null;P=Math.max(2,Math.floor(X.width/q))}const F=(z=E.current)==null?void 0:z.call(E);if(!F||F.height===0)return null;const I=S._core,j=((_=(g=($=(L=I==null?void 0:I._renderService)==null?void 0:L.dimensions)==null?void 0:$.css)==null?void 0:g.cell)==null?void 0:_.height)??17,Q=Math.max(2,Math.floor(F.height/j));return{cols:P,rows:Q}},[]),W=d.useCallback((S,C)=>{const P=b.current;P&&(P.cols===S&&P.rows===C||P.resize(S,C))},[]),Y=d.useCallback((S,C=!1)=>{if(!n||!e||!t||s&&S!=="sync"||!C&&Date.now()<x.current||!b.current)return!1;const F=H();if(!F)return!1;const{cols:I,rows:j}=F,Q=a.current;return!C&&Q&&Q.cols===I&&Q.rows===j?(W(I,j),!0):(W(I,j),S==="sync"?U.current(I,j):y.current(I,j),a.current={cols:I,rows:j},f.current={cols:I,rows:j,at:Date.now()},!0)},[W,t,n,s,H,e]),T=d.useCallback((S="resize",C={})=>{const{immediate:P=!1,force:F=!1}=C;u.current!==null&&(window.clearTimeout(u.current),u.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const I=()=>{l.current=requestAnimationFrame(()=>{l.current=null,Y(S,F)})};if(P){I();return}u.current=window.setTimeout(()=>{u.current=null,I()},150)},[Y]),v=d.useCallback(()=>{for(const S of R.current)window.clearTimeout(S);R.current=[]},[]),N=d.useCallback(()=>{var C;v(),T("sync",{immediate:!0,force:!0});const S=window.setTimeout(()=>{T("sync",{immediate:!0,force:!0})},60);R.current.push(S),typeof document<"u"&&"fonts"in document&&((C=document.fonts)!=null&&C.ready)&&document.fonts.ready.then(()=>{T("sync",{immediate:!0,force:!0})}).catch(()=>{})},[v,T]);d.useEffect(()=>{let S=null;const C=()=>{S!==null&&cancelAnimationFrame(S),S=requestAnimationFrame(()=>{S=null,T("resize")})};return window.addEventListener("resize",C),()=>{window.removeEventListener("resize",C),S!==null&&cancelAnimationFrame(S)}},[T]),d.useEffect(()=>{const S=()=>{var te;const I=b.current,j=H();if(!I||!j)return;if(!br({currentSize:{cols:Math.max(2,I.cols),rows:Math.max(2,I.rows)},containerSize:j})){(te=I.refresh)==null||te.call(I);return}T("sync",{force:!0})},C=()=>{if(document.visibilityState!=="visible"){K.current=!0;return}K.current&&(K.current=!1,S())},P=()=>{K.current=!0},F=()=>{K.current&&(K.current=!1,S())};return document.addEventListener("visibilitychange",C),window.addEventListener("blur",P),window.addEventListener("focus",F),()=>{document.removeEventListener("visibilitychange",C),window.removeEventListener("blur",P),window.removeEventListener("focus",F)}},[H,T]),d.useEffect(()=>()=>{v(),u.current!==null&&window.clearTimeout(u.current),l.current!==null&&cancelAnimationFrame(l.current)},[v]);const B=d.useCallback(S=>{k.current=S},[]),V=d.useCallback(S=>{b.current=S},[]);return{scheduleResize:T,runPostSelectResize:N,clearPostSelectResizeTimers:v,setFitAddon:B,setTerminal:V,lastReportedSize:a,pendingLocalSize:f,suppressLocalResizeUntil:x}}const Er={fontFamily:qt,fontSize:13,scrollback:1e4},rt="tmex:terminal-mode-cache";function Rr(n,e){try{const t=sessionStorage.getItem(rt);return t?JSON.parse(t)[`${n}:${e}`]??null:null}catch{return null}}function Cr(n,e,t){try{const s=sessionStorage.getItem(rt),i=s?JSON.parse(s):{},r=`${n}:${e}`;t?i[r]=t:delete i[r],sessionStorage.setItem(rt,JSON.stringify(i))}catch{}}function vr(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function Mr(n,e){if(!e)return n?{...n,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const t=vr();if(!n)return t;const s=n.mouseNormal||n.mouseButton||n.mouseAny;return{...n,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:s?n.mouseNormal:t.mouseNormal}}function Dr(n){var t;const e=globalThis;e.__tmexE2eXterm=n,e.__tmexE2eTerminal=n,e.__tmexE2eTerminalEngine=zt,e.__tmexE2eTerminalRenderer=((t=n.getRendererKind)==null?void 0:t.call(n))??null}function Ar(n){if(!n)return;const e=globalThis;e.__tmexE2eTerminal!==n&&e.__tmexE2eXterm!==n||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const Vt=d.forwardRef(({deviceId:n,paneId:e,theme:t,inputMode:s,deviceConnected:i,isSelectionInvalid:r,onResize:o,onSync:l},u)=>{const[a,f]=d.useState(null),[x,R]=d.useState(!1),k=Z(g=>g.sendInput),{t:b}=Ke(),E=d.useMemo(()=>{switch(t){case"light":return Ot;default:return At}},[t]),K=d.useRef(null),y=d.useRef(null),U=d.useRef(null),H=d.useRef(n),W=d.useRef(e),Y=d.useRef(n),T=d.useRef(e),v=d.useRef(i&&!r),N=d.useRef(s),B=d.useRef(E),V=d.useRef(!1),S=d.useRef(!1),C=d.useRef(null),P=d.useRef(!1),F=d.useCallback((g,_,M)=>{!(g!=null&&g.exportModeSnapshot)||!_||!M||Cr(_,M,g.exportModeSnapshot())},[]),I=d.useCallback(()=>a,[a]);_r(K,I),d.useEffect(()=>{H.current=n,W.current=e,S.current=!1},[n,e]),d.useEffect(()=>{v.current=i&&!r},[i,r]),d.useEffect(()=>{N.current=s},[s]),d.useEffect(()=>{B.current=E},[E]);const j=d.useCallback(g=>{if(!g||s!=="direct"||!v.current)return;const _=H.current,M=W.current;!_||!M||k(_,M,g,!1)},[s,k]),{pendingLocalSize:Q,scheduleResize:te,runPostSelectResize:se,setFitAddon:A,setTerminal:ie}=Tr({deviceId:n,paneId:e,deviceConnected:i,isSelectionInvalid:r,onResize:o,onSync:l,getContainerRect:()=>{const g=K.current;if(!g)return null;const _=g.getBoundingClientRect();return{width:_.width,height:_.height}}});d.useEffect(()=>{let g=!1,_=null;return hr({...Er,theme:B.current,disableStdin:N.current==="editor"}).then(M=>{if(g){M.dispose();return}_=M,y.current&&M.open(y.current),Dr(M),f(M)}),()=>{g=!0,f(null),Ar(_),_==null||_.dispose()}},[]),d.useEffect(()=>{!a||!("setTheme"in a)||a.setTheme(E)},[a,E]),d.useEffect(()=>{!a||!("setDisableStdin"in a)||a.setDisableStdin(s==="editor")},[a,s]),d.useEffect(()=>{!a||s!=="direct"||window.innerWidth<768||"ontouchstart"in window||a.focus()},[a,s]);const G=d.useMemo(()=>a?{onResetTerminal:g=>{H.current===g&&(F(a,Y.current,T.current),P.current=!0,a.reset(),V.current=!1,se())},onApplyHistory:(g,_,M)=>{var J;if(H.current!==g)return;const q=Mr(Rr(H.current,W.current),M);q&&((J=a.restoreModeSnapshot)==null||J.call(a,q));const X=M?pr(_):Yt(_);S.current=!0,a.write(X),P.current=!1,Y.current=H.current,T.current=W.current,F(a,H.current,W.current)},onFlushBuffer:(g,_)=>{if(H.current===g){for(const M of _){const q=Mt(M,V.current);V.current=q.endedWithCR,a.write(q.normalized)}S.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),S.current=!1),Y.current=H.current,T.current=W.current,F(a,H.current,W.current)}},onOutput:(g,_,M)=>{if(H.current!==g||W.current!==_)return;const q=Mt(M,V.current);V.current=q.endedWithCR,a.write(q.normalized),S.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),S.current=!1),Y.current=H.current,T.current=W.current,F(a,H.current,W.current)}}:{},[a,F,se]);d.useEffect(()=>{a?C.current!==a&&(V.current=!1,Y.current=H.current,T.current=W.current,C.current=a):C.current=null},[a]),d.useEffect(()=>{if(!(!a||!n||!e))return()=>{if(P.current){P.current=!1;return}F(a,Y.current,T.current)}},[n,a,e,F]),d.useEffect(()=>{dt(G)},[G]),d.useEffect(()=>()=>{dt({})},[]),d.useEffect(()=>{if(!a){U.current=null,A(null),ie(null);return}const g=new ur;return a.loadAddon(g),U.current=g,A(g),ie(a),se(),()=>{try{g.dispose()}finally{U.current=null,A(null),ie(null)}}},[a,se,A,ie]),d.useEffect(()=>{const g=K.current;if(!g)return;let _=null;const M=new ResizeObserver(()=>{_!==null&&cancelAnimationFrame(_),_=requestAnimationFrame(()=>{_=null,te("resize")})});return M.observe(g),()=>{M.disconnect(),_!==null&&cancelAnimationFrame(_)}},[te]),d.useEffect(()=>{if(!a||!n||!e)return;const g=a.onData(_=>{!i||r||j(_)});return a.attachCustomKeyEventHandler(_=>!i||r||_.type!=="keydown"||s!=="direct"?!0:_.shiftKey&&_.key==="Enter"?(_.preventDefault(),j("\x1B[13;2u"),!1):!0),()=>{g.dispose(),a.attachCustomKeyEventHandler(()=>!0)}},[a,i,r,s,j,n,e]),d.useEffect(()=>{if(!(a!=null&&a.onSelectionChange)){R(!1);return}const g=a.onSelectionChange(_=>{R(!!_)});return()=>{g.dispose(),R(!1)}},[a]);const z=d.useCallback(()=>{var _;if(!a)return;const g=((_=a.getSelection)==null?void 0:_.call(a))??"";g&&Ft(g).then(()=>{_e.success(b("terminal.copied"))}).catch(()=>{_e.error(b("terminal.copyFailed"))}).finally(()=>{var M;(M=a.clearSelection)==null||M.call(a),a.focus()})},[a,b]),L=d.useCallback(()=>{var _;if(!a)return;((_=navigator.clipboard)!=null&&_.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(M=>{var q;M&&a.paste(M),(q=a.clearSelection)==null||q.call(a),a.focus()}).catch(()=>{_e.error(b("terminal.pasteFailed"))})},[a,b]),$=d.useCallback(()=>{var g;(g=a==null?void 0:a.clearSelection)==null||g.call(a),a==null||a.focus()},[a]);return d.useImperativeHandle(u,()=>({write:g=>a==null?void 0:a.write(g),reset:()=>{a==null||a.reset(),V.current=!1},scrollToBottom:()=>a==null?void 0:a.scrollToBottom(),resize:(g,_)=>a==null?void 0:a.resize(g,_),getTerminal:()=>a??null,getSize:()=>a?{cols:Math.max(2,a.cols),rows:Math.max(2,a.rows)}:null,runPostSelectResize:()=>se(),scheduleResize:(g,_)=>te(g,_),calculateSizeFromContainer:()=>{var De,Ae,oe,we,de,le,ee,ye,ue,ge,Te,Oe,ke,He,Ie,Ee;const g=K.current,_=a,M=U.current;if(!g||!_)return null;const q=g.getBoundingClientRect();if(q.width===0||q.height===0)return null;const X=_._core;let J;if(M)try{const c=M.proposeDimensions();if(c)J=Math.max(2,c.cols);else{const p=((we=(oe=(Ae=(De=X==null?void 0:X._renderService)==null?void 0:De.dimensions)==null?void 0:Ae.css)==null?void 0:oe.cell)==null?void 0:we.width)??9;J=Math.max(2,Math.floor(q.width/p))}}catch{const c=((ye=(ee=(le=(de=X==null?void 0:X._renderService)==null?void 0:de.dimensions)==null?void 0:le.css)==null?void 0:ee.cell)==null?void 0:ye.width)??9;J=Math.max(2,Math.floor(q.width/c))}else{const c=((Oe=(Te=(ge=(ue=X==null?void 0:X._renderService)==null?void 0:ue.dimensions)==null?void 0:ge.css)==null?void 0:Te.cell)==null?void 0:Oe.width)??9;J=Math.max(2,Math.floor(q.width/c))}const Me=((Ee=(Ie=(He=(ke=X==null?void 0:X._renderService)==null?void 0:ke.dimensions)==null?void 0:He.css)==null?void 0:Ie.cell)==null?void 0:Ee.height)??17,fe=Math.max(2,Math.floor(q.height/Me));return{cols:J,rows:fe}},getPendingLocalSize:()=>Q.current}),[a,Q,se,te]),h.jsxs("div",{ref:K,className:"h-full w-full relative",style:{backgroundColor:E.background},"data-terminal-engine":zt,children:[h.jsx("div",{ref:y,className:"absolute inset-0"}),h.jsx(fr,{visible:x,canPaste:s==="direct"&&i&&!r,onCopy:z,onPaste:L,onDismiss:$})]})});Vt.displayName="Terminal";const Or=1200,kr=2e3;function he(n,e){return!n||!e?!1:n.windowId===e.windowId&&n.paneId===e.paneId}function Kt(n,e){const t=n.filter(s=>e-s.at<Or);return t.length===0?null:t.reduce((s,i)=>i.at>s.at?i:s)}function ve(n,e=Date.now()){return!n||e-n.at>kr?null:n}function Hr(n){const e=n.now??Date.now(),t=Kt(n.recentSelectRequests,e);if(t&&!he(t,n.activePaneFromEvent)||he(n.currentRoute,n.activePaneFromEvent)||he(n.lastHandledActive,n.activePaneFromEvent))return!0;const s=ve(n.pendingUserSelection,e);return!!(s&&!he(s,n.activePaneFromEvent))}function Ir(n){const e=n.now??Date.now(),t=Kt(n.recentSelectRequests,e),s=ve(n.pendingUserSelection,e);return!!(s&&!he(s,n.snapshotActive)||t&&!he(t,n.snapshotActive))}function Nr(n){const e=n.now??Date.now(),t=ve(n.pendingUserSelection,e);return!(t&&he(t,n.routeTarget)||n.snapshotActive&&he(n.snapshotActive,n.routeTarget))}const Pr=[{key:"enter",label:"ENTER",payload:"\r"},{key:"ctrl-c",label:"CTRL-C",payload:""},{key:"ctrl-d",label:"CTRL-D",payload:""},{key:"up",label:"↑",payload:"\x1B[A"},{key:"down",label:"↓",payload:"\x1B[B"},{key:"left",label:"←",payload:"\x1B[D"},{key:"right",label:"→",payload:"\x1B[C"},{key:"shift-enter",label:"SHIFT+ENTER",payload:"\x1B[13;2u"},{key:"tab",label:"TAB",payload:" "},{key:"backspace",label:"BACKSPACE",payload:"\b"},{key:"esc",label:"ESC",payload:"\x1B"},{key:"delete",label:"DELETE",payload:""},{key:":",label:":",payload:":"},{key:"/",label:"/",payload:"/"},{key:"'",label:"'",payload:"'"},{key:'"',label:'"',payload:'"'},{key:"`",label:"`",payload:"`"}],Dt=d.memo(function({onSend:e,onFocusEditor:t,disabled:s,isMobile:i,inputMode:r}){return h.jsx("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:h.jsx("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Pr.map(o=>h.jsx(pe,{variant:"secondary",size:"sm",className:"h-7 min-w-9 px-2.5 rounded-full text-[11px] font-medium tracking-wide shrink-0 [@media(any-pointer:coarse)]:h-9 [@media(any-pointer:coarse)]:min-w-10 [@media(any-pointer:coarse)]:px-3",title:o.label,"aria-label":o.label,"data-testid":`editor-shortcut-${o.key}`,onMouseDown:l=>l.preventDefault(),onClick:()=>{e(o.payload),i&&r==="editor"&&(t==null||t())},disabled:s,children:o.label},o.key))})})});function Ur(){var Ee;const{t:n}=Ke(),{deviceId:e,windowId:t,paneId:s}=it(),i=Xt(),r=d.useRef(null),o=d.useRef(null),l=d.useRef(null),u=d.useRef(null),a=d.useRef(!1),f=d.useRef(!1),x=d.useRef(null),R=Z(c=>c.selectPane),k=Z(c=>e?c.snapshots[e]:void 0),b=Z(c=>{var p;return e?(p=c.deviceErrors)==null?void 0:p[e]:void 0}),E=Z(c=>{var p;return e?((p=c.deviceConnected)==null?void 0:p[e])??!1:!1}),K=kt(c=>{var p;return((p=c.settings)==null?void 0:p.siteName)??"tmex"}),y=d.useMemo(()=>ot(s),[s]),U=d.useMemo(()=>e&&y?`${e}:${y}`:null,[e,y]),[H,W]=d.useState(!1),[Y,T]=d.useState(""),v=d.useRef(!1),N=!E||!y,[B,V]=d.useState(!1),S=ae(c=>c.inputMode),C=ae(c=>c.theme),P=ae(c=>c.editorSendWithEnter),F=ae(c=>c.setEditorSendWithEnter),I=ae(c=>c.addEditorHistory),j=ae(c=>c.setEditorDraft),Q=ae(c=>c.removeEditorDraft),te=ae(c=>U?c.editorDrafts[U]??"":""),se=d.useMemo(()=>Jt(),[]),A=(Ee=k==null?void 0:k.session)==null?void 0:Ee.windows,ie=C==="light"?Ot:At,{data:G}=Qt({queryKey:["devices"],queryFn:async()=>{const c=await fetch("/api/devices");if(!c.ok)throw new Error("Failed to fetch devices");return c.json()},throwOnError:!1}),z=d.useMemo(()=>{if(e)return G==null?void 0:G.devices.find(c=>c.id===e)},[e,G==null?void 0:G.devices]),L=d.useMemo(()=>{if(!(!t||!A))return A.find(c=>c.id===t)},[t,A]),$=d.useMemo(()=>{if(!(!y||!L))return L.panes.find(c=>c.id===y)},[y,L]),g=!!A,X=!!(g&&!!t&&!L||g&&!!t&&!!y&&!!L&&!$?n("wsError.checkGateway"):null),J=!!(E&&y&&!X),Me=d.useMemo(()=>{if(!L||!$)return null;const c=(z==null?void 0:z.name)??e;return Ht({paneIdx:$.index,windowIdx:L.index,paneTitle:$.title,windowName:L.name,windowCustomName:L.customName,deviceName:c})},[z==null?void 0:z.name,e,$,L]),fe=d.useMemo(()=>{if(!A||A.length===0)return null;const c=A.find(w=>w.active),p=c==null?void 0:c.panes.find(w=>w.active);return!c||!p?null:{windowId:c.id,paneId:p.id}},[A]),De=d.useCallback((c,p)=>{!e||!y||Z.getState().resizePane(e,y,c,p)},[e,y]),Ae=d.useCallback((c,p)=>{!e||!y||Z.getState().syncPaneSize(e,y,c,p)},[e,y]),oe=d.useCallback((c,p)=>{const w=u.current,D=(w==null?void 0:w.calculateSizeFromContainer())??(w==null?void 0:w.getSize())??void 0;if(D)return D;if(!c||!p||!A)return;const ne=A.find(me=>me.id===c),re=ne==null?void 0:ne.panes.find(me=>me.id===p);if(!(!re||re.width<=1||re.height<=1))return{cols:re.width,rows:re.height}},[A]);d.useEffect(()=>{const c=()=>{W(window.innerWidth<768||"ontouchstart"in window)};return c(),window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[]),d.useEffect(()=>{if(!H||!se||f.current)return;f.current=!0;const c=()=>{window.scrollTo(0,1)},p=window.requestAnimationFrame(c),w=window.setTimeout(c,120),D=window.setTimeout(c,420);return()=>{window.cancelAnimationFrame(p),window.clearTimeout(w),window.clearTimeout(D)}},[se,H]),d.useEffect(()=>{e&&(a.current=!1,ye.current=null,ue.current=null,x.current=null,de.current=[])},[e]),d.useEffect(()=>{E||(a.current=!1)},[E]),d.useEffect(()=>{if(!e||!E||!t||!A)return;if(A.length===0){i("/devices",{replace:!0});return}const c=A.find(w=>w.id===t);if(!c)return;if(!y){const w=c.panes.find(D=>D.active)??c.panes[0];w&&i(`/devices/${e}/windows/${t}/panes/${Se(w.id)}`,{replace:!0});return}if(!c.panes.find(w=>w.id===y)){const w=c.panes.find(D=>D.active)??c.panes[0];w&&i(`/devices/${e}/windows/${t}/panes/${Se(w.id)}`,{replace:!0});return}},[e,E,A,t,y,i]),d.useEffect(()=>{if(!e||!E||!A||A.length===0||t&&y||a.current)return;const c=A.find(w=>w.active)??A[0],p=c.panes.find(w=>w.active)??c.panes[0];p&&(a.current=!0,i(`/devices/${e}/windows/${c.id}/panes/${Se(p.id)}`,{replace:!0}))},[E,e,i,y,t,A]);const we=d.useRef(null);d.useEffect(()=>{we.current=null},[e,y]),d.useEffect(()=>{if(!e||!t||!y||N||!E)return;const c=`${e}:${t}:${y}`;if(we.current===c)return;we.current=c;const p=oe(t,y);le(t,y),R(e,t,y,p)},[E,e,oe,N,y,R,t]),d.useEffect(()=>{if(!e||!E||!t||!y)return;const c={windowId:t,paneId:y};Nr({routeTarget:c,snapshotActive:fe,pendingUserSelection:x.current})&&(x.current={windowId:c.windowId,paneId:c.paneId,at:Date.now()})},[E,e,y,fe,t]);const de=d.useRef([]),le=d.useCallback((c,p)=>{const w=Date.now(),D=[...de.current.filter(ne=>w-ne.at<2e3),{windowId:c,paneId:p,at:w}];de.current=D.slice(-8)},[]),ee=Z(c=>e?c.activePaneFromEvent[e]:void 0),ye=d.useRef(null);d.useEffect(()=>{if(!e||!E||!t||!y||!ee)return;const c=Date.now(),p=ve(x.current,c);if(x.current=p,Hr({now:c,pendingUserSelection:p,activePaneFromEvent:ee,currentRoute:{windowId:t,paneId:y},recentSelectRequests:de.current,lastHandledActive:ye.current}))return;ye.current={...ee},p&&p.windowId===ee.windowId&&p.paneId===ee.paneId&&(x.current=null);const w=oe(ee.windowId,ee.paneId);le(ee.windowId,ee.paneId),R(e,ee.windowId,ee.paneId,w),i(`/devices/${e}/windows/${ee.windowId}/panes/${Se(ee.paneId)}`,{replace:!0})},[e,E,t,y,ee,le,oe,R,i]);const ue=d.useRef(null);d.useEffect(()=>{if(!e||!E||!A||A.length===0)return;const c=de.current,p=A.find($e=>$e.active);if(!p)return;const w=p.panes.find($e=>$e.active);if(!w)return;const D={windowId:p.id,paneId:w.id},ne=Date.now(),re=ve(x.current,ne);if(x.current=re,Ir({now:ne,pendingUserSelection:re,snapshotActive:D,recentSelectRequests:c})||ue.current&&ue.current.windowId===D.windowId&&ue.current.paneId===D.paneId||(ue.current={...D},re&&re.windowId===D.windowId&&re.paneId===D.paneId&&(x.current=null),t===D.windowId&&y===D.paneId))return;const me=oe(D.windowId,D.paneId);le(D.windowId,D.paneId),R(e,D.windowId,D.paneId,me),i(`/devices/${e}/windows/${D.windowId}/panes/${Se(D.paneId)}`,{replace:!0})},[e,E,A,t,y,le,oe,R,i]);const ge=Z(c=>e?c.pendingCreateWindowAt[e]:void 0);d.useEffect(()=>{if(!e||!E||!ge)return;const c=5e3,p=Date.now()-ge;if(p>c){Z.getState().clearPendingCreateWindow(e);return}if(!fe){const ne=window.setTimeout(()=>{Z.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(ne)}const w=fe;if(t===w.windowId&&y===w.paneId){const ne=window.setTimeout(()=>{Z.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(ne)}x.current={windowId:w.windowId,paneId:w.paneId,at:Date.now()};const D=oe(w.windowId,w.paneId);le(w.windowId,w.paneId),R(e,w.windowId,w.paneId,D),i(`/devices/${e}/windows/${w.windowId}/panes/${Se(w.paneId)}`,{replace:!0}),Z.getState().clearPendingCreateWindow(e)},[e,E,ge,fe,t,y,le,oe,R,i]),d.useEffect(()=>{if(!J||!$||N)return;const c=u.current,p=c==null?void 0:c.getTerminal();if(!p)return;const w=Math.max(2,Math.floor($.width||0)),D=Math.max(2,Math.floor($.height||0));if(!w||!D)return;const ne=Date.now(),re={cols:w,rows:D},me=(c==null?void 0:c.getPendingLocalSize())??null;xr({now:ne,remoteSize:re,pendingLocalSize:me})&&(p.cols===w&&p.rows===D||p.resize(w,D))},[J,N,$]),d.useEffect(()=>{const c=window.requestAnimationFrame(()=>{var w;(w=u.current)==null||w.scrollToBottom()}),p=window.setTimeout(()=>{var w;(w=u.current)==null||w.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(c),window.clearTimeout(p)}},[S]),d.useEffect(()=>{b!=null&&b.message&&_e.error(b.message)},[b==null?void 0:b.message]),d.useEffect(()=>(document.title=Zt(Me),()=>{document.title=K}),[K,Me]),d.useEffect(()=>{const c=()=>{var p;(p=u.current)==null||p.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",c),()=>{window.removeEventListener("tmex:jump-to-latest",c)}},[]),d.useEffect(()=>{const c=p=>{const{deviceId:w,windowId:D,paneId:ne}=p.detail;w===e&&(x.current={windowId:D,paneId:ne,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",c),()=>{window.removeEventListener("tmex:user-initiated-selection",c)}},[e]),d.useEffect(()=>{T(te)},[te]);const Te=d.useCallback(c=>{if(!e||!y||!J)return;Z.getState().sendInput(e,y,c,!1)},[J,e,y]),Oe=d.useCallback(()=>{if(!J){_e.error(n("wsError.checkGateway"));return}if(!e||!y||!Y.trim())return;V(!0),window.setTimeout(()=>V(!1),150);const c=P?`${Y}\r`:Y;Z.getState().sendInput(e,y,c,!1),I(Y),U&&Q(U),T("")},[I,J,e,U,P,Y,Q,y,n]),ke=d.useCallback(()=>{if(!J){_e.error(n("wsError.checkGateway"));return}if(!e||!y||!Y.trim())return;V(!0),window.setTimeout(()=>V(!1),150);const c=Y.split(/\r?\n/),p=Z.getState();for(const w of c)w.trim()&&p.sendInput(e,y,`${w}\r`,!1);I(Y),U&&Q(U),T("")},[I,J,e,U,Y,Q,y,n]),He=d.useCallback(()=>{var c;(c=l.current)==null||c.focus({preventScroll:!0})},[]);if(!e)return h.jsx("div",{className:"flex h-full items-center justify-center p-4",children:h.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:n("device.noDevices")})});const Ie=!E&&!b;return h.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[h.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${H&&S==="editor"?"pb-1":""}`,children:[h.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:ie.background},children:E&&y?h.jsx("div",{ref:r,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:h.jsx(Vt,{ref:u,deviceId:e,paneId:y,theme:C,inputMode:S,deviceConnected:E,isSelectionInvalid:X,onResize:De,onSync:Ae},`${e}:${y}`)}):h.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:h.jsx("div",{className:"max-w-sm space-y-4",children:E?t?h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx(je,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("terminal.connecting")})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("window.noWindowSelected")}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n("window.selectWindowToStart")})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("device.disconnected")}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n("device.connectToStart")})]})})})}),Ie&&h.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:h.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:[h.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),h.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:n("terminal.connecting")})]})})]}),S==="direct"&&h.jsx("div",{className:"",children:h.jsx(Dt,{onSend:Te,disabled:!J,isMobile:H,inputMode:S})}),S==="editor"&&h.jsxs("div",{ref:o,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[H&&h.jsx(Dt,{onSend:Te,onFocusEditor:He,disabled:!J,isMobile:H,inputMode:S}),h.jsx("textarea",{ref:l,"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:Y,onChange:c=>{const p=c.target.value;if(T(p),!!U){if(p){j(U,p);return}Q(U)}},placeholder:n("terminal.inputPlaceholder"),onCompositionStart:()=>{v.current=!0},onCompositionEnd:()=>{v.current=!1}}),h.jsx("div",{className:"actions mt-2",children:h.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[h.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:[h.jsx(cn,{size:"sm",checked:P,onCheckedChange:c=>F(!!c)}),h.jsx("span",{children:n("terminal.editorSendWithEnter")})]}),h.jsxs(pe,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;T(""),U&&Q(U),H&&S==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},title:n("terminal.clear"),children:[h.jsx(dn,{className:"h-4 w-4"}),n("terminal.clear")]}),h.jsxs(pe,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;ke(),H&&S==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!J||B,children:[B?h.jsx(je,{className:"h-4 w-4 animate-spin"}):h.jsx(ut,{className:"h-4 w-4"}),n("terminal.editorSendLineByLine")]}),h.jsxs(pe,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;Oe(),H&&S==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!J||B,children:[B?h.jsx(je,{className:"h-4 w-4 animate-spin"}):h.jsx(ut,{className:"h-4 w-4"}),n("common.send")]})]})})]})]})}function zr(){const{deviceId:n,windowId:e,paneId:t}=it(),s=t?ot(t):void 0,i=Z(f=>f.snapshots),r=kt(f=>{var x;return((x=f.settings)==null?void 0:x.siteName)??"tmex"}),o=n?i[n]:void 0,l=d.useMemo(()=>{var f;if(!(!e||!((f=o==null?void 0:o.session)!=null&&f.windows)))return o.session.windows.find(x=>x.id===e)},[e,o]),u=d.useMemo(()=>{if(!(!s||!l))return l.panes.find(f=>f.id===s)},[s,l]),a=d.useMemo(()=>l&&u?Ht({paneIdx:u.index,windowIdx:l.index,paneTitle:u.title,windowName:l.name,windowCustomName:l.customName,deviceName:r}):n??"",[l,u,r,n]);return h.jsx(h.Fragment,{children:a})}function Yr(){const{t:n}=Ke(),{deviceId:e,paneId:t}=it(),s=t?ot(t):void 0,i=ae(b=>b.inputMode),r=ae(b=>b.setInputMode),o=Z(b=>{var E;return e?((E=b.deviceConnected)==null?void 0:E[e])??!1:!1}),[l,u]=d.useState(!1),a=!!(s&&o),f=()=>{r(i==="direct"?"editor":"direct")},x=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},R=()=>{u(!0)},k=()=>{window.location.reload()};return h.jsxs(h.Fragment,{children:[h.jsx(pe,{variant:"ghost",size:"icon-sm",onClick:R,"aria-label":n("nav.refreshPage"),title:n("nav.refreshPage"),children:h.jsx(_n,{className:"h-4 w-4"})}),h.jsx(pe,{variant:"ghost",size:"icon-sm",onClick:f,disabled:!a,"data-testid":"terminal-input-mode-toggle","aria-label":n(i==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:n(i==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:i==="direct"?h.jsx(gn,{className:"h-4 w-4"}):h.jsx(bn,{className:"h-4 w-4"})}),h.jsx(pe,{variant:"ghost",size:"icon-sm",onClick:x,disabled:!a,"aria-label":n("nav.jumpToLatest"),title:n("nav.jumpToLatest"),children:h.jsx(hn,{className:"h-4 w-4"})}),h.jsx(en,{open:l,onOpenChange:u,children:h.jsxs(tn,{children:[h.jsxs(nn,{children:[h.jsx(sn,{children:n("nav.refreshPage")}),h.jsx(rn,{children:n("nav.refreshPageConfirm")})]}),h.jsxs(on,{children:[h.jsx(ln,{onClick:()=>u(!1),children:n("common.cancel")}),h.jsx(an,{onClick:k,children:n("common.confirm")})]})]})})]})}export{Yr as PageActions,zr as PageTitle,Ur as default};
|
|
36
|
+
//# sourceMappingURL=DevicePage-CJEjk7rL.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as G,j as e,q as se,u as N,r as g,a as U,e as ae,s as te,M as Z,B as w,P as W,A as ie,h as ne,i as re,v as ce,k as oe,l as de,m as le,n as me,o as he,G as pe,g as v,D as ue,w as xe,x as ve,y as I,z as ye,C as ge,E as z,F as fe,S as je,L as we,H as Ne,J as be,K as De,N as Ce,O as Se,Q as Ee,I as x,R as Me}from"./index-
|
|
1
|
+
import{c as G,j as e,q as se,u as N,r as g,a as U,e as ae,s as te,M as Z,B as w,P as W,A as ie,h as ne,i as re,v as ce,k as oe,l as de,m as le,n as me,o as he,G as pe,g as v,D as ue,w as xe,x as ve,y as I,z as ye,C as ge,E as z,F as fe,S as je,L as we,H as Ne,J as be,K as De,N as Ce,O as Se,Q as Ee,I as x,R as Me}from"./index-YVZKH9DX.js";import{u as M,C as S,c as E,a as ke,b as Pe,h as Ke,S as O,d as B,e as Q,f as _,g as f}from"./select-CD0ieoCm.js";import{T as X}from"./useValueChanged-CFS5t0R_.js";/**
|
|
2
2
|
* @license lucide-react v0.564.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -9,4 +9,4 @@ import{c as G,j as e,q as se,u as N,r as g,a as U,e as ae,s as te,M as Z,B as w,
|
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
11
|
*/const $e=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Te=G("zap",$e);function Fe({className:s,...n}){return e.jsx("textarea",{"data-slot":"textarea",className:se("border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/30 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-2 aria-invalid:ring-2 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50",s),...n})}function p(s){const n=s.trim();return n||void 0}function He(s){return s?{name:s.name,type:s.type,host:s.host??"",port:s.port??22,username:s.username??"",sshConfigRef:s.sshConfigRef??"",session:s.session??"tmex",authMode:s.type==="local"?"auto":s.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"",sshConfigRef:"",session:"tmex",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(s){if(s.type==="local")return{name:s.name.trim(),type:"local",session:p(s.session)??"tmex",authMode:"auto"};const n={name:s.name.trim(),type:"ssh",host:p(s.host),port:s.port,username:p(s.username),sshConfigRef:p(s.sshConfigRef),session:p(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&(n.password=s.password),s.authMode==="key"&&(n.privateKey=s.privateKey,n.privateKeyPassphrase=s.privateKeyPassphrase||void 0),n}function Re(s){if(s.type==="local")return{name:s.name.trim(),session:p(s.session)??"tmex",authMode:"auto"};const n={name:s.name.trim(),host:p(s.host),port:s.port,username:p(s.username),sshConfigRef:p(s.sshConfigRef),session:p(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&s.password&&(n.password=s.password),s.authMode==="key"&&s.privateKey&&(n.privateKey=s.privateKey,n.privateKeyPassphrase=s.privateKeyPassphrase||void 0),n}async function J(s,n){try{return(await s.json()).error??n}catch{return n}}function Qe(){const{t:s}=N(),[n,m]=g.useState(!1),[a,y]=g.useState(null),[r,o]=g.useState(null),l=U();g.useEffect(()=>{const c=()=>m(!0);return window.addEventListener("tmex:open-add-device",c),()=>window.removeEventListener("tmex:open-add-device",c)},[]);const{data:d,isLoading:u,isError:k}=ae({queryKey:["devices"],queryFn:async()=>{const c=await fetch("/api/devices");if(!c.ok)throw new Error(s("device.loadFailed"));return c.json()},throwOnError:!1}),b=te(c=>c.hydrateDeviceErrors);g.useEffect(()=>{d!=null&&d.devices&&b(d.devices.map(c=>({deviceId:c.id,lastError:c.lastError??null,lastErrorType:c.lastErrorType??null})))},[d,b]);const D=M({mutationFn:async c=>{if(!(await fetch(`/api/devices/${c}`,{method:"DELETE"})).ok)throw new Error(s("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),v.success(s("common.success"))},onError:c=>{v.error(c instanceof Error?c.message:s("common.error"))}}),C=(d==null?void 0:d.devices)??[];return e.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:[u?e.jsx(S,{children:e.jsx(E,{className:"py-16 text-center text-sm text-muted-foreground",children:s("common.loading")})}):k?e.jsx(S,{children:e.jsx(E,{className:"py-16 text-center text-sm text-destructive",children:s("device.loadFailed")})}):C.length===0?e.jsx(S,{children:e.jsxs(E,{className:"space-y-4 py-14 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:e.jsx(Z,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-medium",children:s("device.noDevices")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("device.addDevice")})]}),e.jsxs(w,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[e.jsx(W,{className:"h-4 w-4"}),s("device.addDevice")]})]})}):e.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:C.map(c=>e.jsx(qe,{device:c,onEdit:()=>y(c),onDelete:()=>o(c)},c.id))}),n&&e.jsx(V,{mode:"create",onClose:()=>m(!1)}),a&&e.jsx(V,{mode:"edit",device:a,onClose:()=>y(null)}),e.jsx(ie,{open:r!==null,onOpenChange:c=>!c&&o(null),children:e.jsxs(ne,{children:[e.jsxs(re,{children:[e.jsx(ce,{className:"bg-destructive/10",children:e.jsx(X,{className:"h-5 w-5 text-destructive"})}),e.jsx(oe,{children:s("device.deleteConfirm")}),e.jsx(de,{children:s("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),e.jsxs(le,{children:[e.jsx(me,{children:s("common.cancel")}),e.jsx(he,{variant:"destructive",disabled:!r||D.isPending,onClick:()=>{r&&(D.mutate(r.id),o(null))},children:s("common.delete")})]})]})})]})}function qe({device:s,onEdit:n,onDelete:m}){const{t:a}=N(),y=s.type==="local"?e.jsx(Z,{className:"h-4 w-4"}):e.jsx(pe,{className:"h-4 w-4"}),r=s.type==="local"?a("device.typeLocal"):`${s.username??"-"}@${s.host??"-"}:${s.port??22}`,o=M({mutationFn:async()=>{const l=await fetch(`/api/devices/${s.id}/test-connection`,{method:"POST"});let d=null;try{d=await l.json()}catch{d=null}if(!l.ok){const u=d;throw new Error((u==null?void 0:u.error)??a("common.error"))}return d},onSuccess:l=>{v.success(l.message??a("common.success"))},onError:l=>{v.error(l instanceof Error?l.message:a("common.error"))}});return e.jsxs(S,{"data-testid":"device-card","data-device-id":s.id,"data-device-name":s.name,className:"overflow-hidden",children:[e.jsxs(ke,{className:"space-y-2 pb-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.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}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx(Pe,{className:"line-clamp-1 text-sm",title:s.name,children:s.name}),e.jsx(Ke,{className:"line-clamp-1 text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1",children:e.jsxs(ue,{children:[e.jsx(xe,{render:e.jsx(w,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${s.id}`,"aria-label":a("common.edit"),title:a("common.edit")}),children:e.jsx(Ae,{className:"h-4 w-4"})}),e.jsxs(ve,{align:"end",children:[e.jsxs(I,{"data-testid":`device-card-edit-${s.id}`,onClick:n,children:[e.jsx(ye,{className:"h-4 w-4"}),a("common.edit")]}),s.type==="ssh"&&e.jsxs(I,{"data-testid":`device-card-test-${s.id}`,onClick:()=>o.mutate(),disabled:o.isPending,children:[e.jsx(Te,{className:"h-4 w-4"}),a("common.test")]}),e.jsx(ge,{}),e.jsxs(I,{"data-testid":`device-card-delete-${s.id}`,variant:"destructive",onClick:m,children:[e.jsx(X,{className:"h-4 w-4"}),a("common.delete")]})]})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(z,{variant:"outline",className:"text-[11px] font-normal",children:s.type==="local"?a("device.typeLocal"):a("device.typeSSHBadge")}),s.session&&e.jsx(z,{variant:"outline",className:"text-[11px] font-normal",children:s.session}),e.jsx(fe,{deviceId:s.id})]})]}),e.jsxs(E,{className:"pt-0",children:[e.jsx(je,{className:"mb-2"}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(we,{to:`/devices/${s.id}`,"data-testid":`device-card-connect-${s.id}`,className:Ne({variant:"default",size:"sm"}),children:a("device.connect")})})]})]})}function V({mode:s,device:n,onClose:m}){const{t:a}=N(),y=U(),[r,o]=g.useState(He(n)),[l,d]=g.useState(!1),u=s==="edit",k=r.type==="ssh",b=M({mutationFn:async t=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!i.ok)throw new Error(await J(i,a("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(a("common.success")),m()},onError:t=>{v.error(t instanceof Error?t.message:a("common.error"))}}),D=M({mutationFn:async t=>{if(!n)throw new Error(a("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${n.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!i.ok)throw new Error(await J(i,a("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(a("common.success")),m()},onError:t=>{v.error(t instanceof Error?t.message:a("common.error"))}}),C=async t=>{t.preventDefault(),d(!0);try{s==="create"?await b.mutateAsync(Le(r)):await D.mutateAsync(Re(r))}catch{}finally{d(!1)}},c=`${s}-device-name`,P=`${s}-device-type`,A=`${s}-device-host`,$=`${s}-device-port`,T=`${s}-device-username`,F=`${s}-device-session`,H=`${s}-device-auth-mode`,L=`${s}-device-password`,R=`${s}-device-private-key`,q=`${s}-device-private-key-passphrase`,Y={local:a("device.typeLocal"),ssh:a("device.typeSSH")},ee={password:a("device.authPassword"),key:a("device.authKey"),agent:a("device.authAgent"),configRef:"SSH Config"},K=t=>e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:t}),h=(t,i,j)=>e.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:t,children:[i,j&&e.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return e.jsx(be,{open:!0,onOpenChange:t=>!t&&m(),children:e.jsxs(De,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:a(u?"device.editDevice":"device.addDevice")}),e.jsx(Ee,{children:a(u?"device.editDeviceDescription":"device.addDeviceDescription")})]}),e.jsxs("form",{onSubmit:C,className:"space-y-4",children:[e.jsxs("div",{className:"-mr-2 max-h-[min(70vh,720px)] space-y-5 overflow-y-auto pr-2",children:[e.jsxs("section",{className:"space-y-2.5",children:[K(a("device.sectionBasic")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(c,a("device.name"),!0),e.jsx(x,{id:c,"data-testid":"device-name-input",type:"text",value:r.name,onChange:t=>o(i=>({...i,name:t.target.value})),placeholder:a("device.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(P,a("device.type")),e.jsxs(O,{value:r.type,onValueChange:t=>{if(!t)return;const i=t;o(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"password":j.authMode}))},disabled:u,children:[e.jsx(B,{id:P,"data-testid":"device-type-select",className:"w-full",children:e.jsx(Q,{placeholder:a("device.type"),children:t=>Y[t]??""})}),e.jsxs(_,{children:[e.jsx(f,{value:"local",children:a("device.typeLocal")}),e.jsx(f,{value:"ssh",children:a("device.typeSSH")})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(F,a("device.session")),e.jsx(x,{id:F,"data-testid":"device-session-input",type:"text",value:r.session,onChange:t=>o(i=>({...i,session:t.target.value})),placeholder:a("device.sessionPlaceholder")})]})]})]}),k&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2.5",children:[K(a("device.sectionConnection")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(A,a("device.host")),e.jsx(x,{id:A,type:"text",value:r.host,onChange:t=>o(i=>({...i,host:t.target.value})),placeholder:a("device.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[h($,a("device.port")),e.jsx(x,{id:$,type:"number",value:r.port,onChange:t=>o(i=>({...i,port:Number.parseInt(t.target.value||"22",10)})),min:1,max:65535})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(T,a("device.username")),e.jsx(x,{id:T,type:"text",value:r.username,onChange:t=>o(i=>({...i,username:t.target.value})),placeholder:a("device.usernamePlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(`${s}-device-ssh-config-ref`,"SSH Config"),e.jsx(x,{id:`${s}-device-ssh-config-ref`,type:"text",value:r.sshConfigRef,onChange:t=>o(i=>({...i,sshConfigRef:t.target.value})),placeholder:"~/.ssh/config"})]})]})]}),e.jsxs("section",{className:"space-y-2.5",children:[K(a("device.sectionAuth")),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[h(H,a("device.authMode")),e.jsxs(O,{value:r.authMode,onValueChange:t=>{t&&o(i=>({...i,authMode:t}))},children:[e.jsx(B,{id:H,className:"w-full",children:e.jsx(Q,{placeholder:a("device.authMode"),children:t=>ee[t]??""})}),e.jsxs(_,{children:[e.jsx(f,{value:"password",children:a("device.authPassword")}),e.jsx(f,{value:"key",children:a("device.authKey")}),e.jsx(f,{value:"agent",children:a("device.authAgent")}),e.jsx(f,{value:"configRef",children:"SSH Config"})]})]})]}),r.authMode==="password"&&e.jsxs("div",{className:"space-y-1.5",children:[h(L,a("device.password")),e.jsx(x,{id:L,type:"password",value:r.password,onChange:t=>o(i=>({...i,password:t.target.value}))})]}),r.authMode==="key"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[h(R,a("device.privateKey")),e.jsx(Fe,{id:R,value:r.privateKey,onChange:t=>o(i=>({...i,privateKey:t.target.value})),className:"h-28 font-mono text-xs",placeholder:a("device.privateKeyPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(q,a("device.passphrase")),e.jsx(x,{id:q,type:"password",value:r.privateKeyPassphrase,onChange:t=>o(i=>({...i,privateKeyPassphrase:t.target.value}))})]})]})]})]})]})]}),e.jsxs(Me,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:m,children:a("common.cancel")}),e.jsx(w,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:a(l?"common.saving":"common.save")})]})]})]})})}function _e(){const{t:s}=N();return e.jsx(e.Fragment,{children:s("sidebar.manageDevices")})}function Je(){const{t:s}=N(),n=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return e.jsx(w,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:n,"aria-label":s("sidebar.addDevice"),title:s("sidebar.addDevice"),children:e.jsx(W,{className:"h-4 w-4"})})}export{Je as PageActions,_e as PageTitle,Qe as default};
|
|
12
|
-
//# sourceMappingURL=DevicesPage-
|
|
12
|
+
//# sourceMappingURL=DevicesPage-BvCZBCO1.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as u,f as we,t as Ce,g as o,A as Ae,h as $e,i as Ie,k as _e,l as De,m as ze,n as Le,o as Qe,p as Ke}from"./index-
|
|
1
|
+
import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as u,f as we,t as Ce,g as o,A as Ae,h as $e,i as Ie,k as _e,l as De,m as ze,n as Le,o as Qe,p as Ke}from"./index-YVZKH9DX.js";import{u as b,C as $,a as I,b as _,c as D,S as Oe,d as Ue,e as We,f as He,g as Ve}from"./select-CD0ieoCm.js";import{S as f,L as Ne,a as Je}from"./switch-B4Od47H9.js";import{T as Ee}from"./useValueChanged-CFS5t0R_.js";/**
|
|
2
2
|
* @license lucide-react v0.564.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -14,4 +14,4 @@ import{c as Z,u as B,a as ke,b as Se,r as i,d as fe,e as z,j as e,B as d,I as u,
|
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
16
|
*/const Ze=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],ve=Z("shield",Ze),Y=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed"];async function h(t,m){try{return(await t.json()).error??m}catch{return m}}function is(){var xe,pe,be,je;const{t}=B(),m=ke(),{refreshSettings:g}=Se(),[n,r]=i.useState("site"),x=fe(s=>s.theme),v=fe(s=>s.setTheme),w=x==="dark",[j,S]=i.useState("tmex"),[C,E]=i.useState(window.location.origin),[p,y]=i.useState("en_US"),[N,P]=i.useState(6),[M,R]=i.useState(3),[T,q]=i.useState(!0),[F,a]=i.useState(!0),[c,k]=i.useState(!0),[ee,se]=i.useState(!0),[te,ae]=i.useState(2),[ne,ie]=i.useState(10),[Te,Fe]=i.useState(!1),[Q,oe]=i.useState(""),[K,re]=i.useState(""),[Be,Pe]=i.useState(null),[O,le]=i.useState(""),[U,ce]=i.useState(""),[W,de]=i.useState(Y),Me=s=>{const l=s?"dark":"light";v(l),document.documentElement.classList.toggle("dark",l==="dark")},H=z({queryKey:["site-settings"],queryFn:async()=>{const s=await fetch("/api/settings/site");if(!s.ok)throw new Error(await h(s,t("settings.loadFailed")));return await s.json()}}),V=z({queryKey:["telegram-bots"],queryFn:async()=>{const s=await fetch("/api/settings/telegram/bots");if(!s.ok)throw new Error(await h(s,t("telegram.loadBotsFailed")));return await s.json()}});i.useEffect(()=>{var l;const s=(l=H.data)==null?void 0:l.settings;s&&(S(s.siteName),E(s.siteUrl),y(s.language??"en_US"),P(s.bellThrottleSeconds),R(s.notificationThrottleSeconds??3),q(s.enableBrowserBellToast??!0),a(s.enableBrowserNotificationToast??!0),k(s.enableTelegramBellPush??!0),se(s.enableTelegramNotificationPush??!0),ae(s.sshReconnectMaxRetries),ie(s.sshReconnectDelaySeconds))},[(xe=H.data)==null?void 0:xe.settings]);const me=b({mutationFn:async()=>{const l=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:j,siteUrl:C,language:p,bellThrottleSeconds:N,notificationThrottleSeconds:M,enableBrowserBellToast:T,enableBrowserNotificationToast:F,enableTelegramBellPush:c,enableTelegramNotificationPush:ee,sshReconnectMaxRetries:te,sshReconnectDelaySeconds:ne})});if(!l.ok)throw new Error(await h(l,t("settings.saveFailed")))},onSuccess:async()=>{var s,l;await Promise.all([m.invalidateQueries({queryKey:["site-settings"]}),g()]),o.success(t("settings.settingsSaved")),((l=(s=H.data)==null?void 0:s.settings)==null?void 0:l.language)!==p&&(Ke.changeLanguage(p),Fe(!0))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),J=b({mutationFn:async()=>{const s=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Q,token:K,enabled:!0,allowAuthRequests:!0})});if(!s.ok)throw new Error(await h(s,t("telegram.createFailed")))},onSuccess:async()=>{oe(""),re(""),await m.invalidateQueries({queryKey:["telegram-bots"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),he=((pe=V.data)==null?void 0:pe.bots)??[],G=z({queryKey:["webhooks"],queryFn:async()=>{const s=await fetch("/api/webhooks");if(!s.ok)throw new Error(await h(s,t("webhook.loadFailed")));return await s.json()}}),X=b({mutationFn:async()=>{const s=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:O,secret:U,eventMask:W})});if(!s.ok)throw new Error(await h(s,t("webhook.createFailed")))},onSuccess:async()=>{le(""),ce(""),de(Y),await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ue=b({mutationFn:async s=>{const l=await fetch(`/api/webhooks/${s}`,{method:"DELETE"});if(!l.ok)throw new Error(await h(l,t("webhook.deleteFailed")))},onSuccess:async()=>{await m.invalidateQueries({queryKey:["webhooks"]}),o.success(t("common.success"))},onError:s=>{o.error(s instanceof Error?s.message:t("common.error"))}}),ge=((be=G.data)==null?void 0:be.webhooks)??[];return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(d,{type:"button",size:"sm",variant:n==="site"?"default":"outline","data-testid":"settings-tab-site",onClick:()=>r("site"),children:t("settings.siteSettings")}),e.jsx(d,{type:"button",size:"sm",variant:n==="notifications"?"default":"outline","data-testid":"settings-tab-notifications",onClick:()=>r("notifications"),children:t("settings.notificationsTab")}),e.jsx(d,{type:"button",size:"sm",variant:n==="telegram"?"default":"outline","data-testid":"settings-tab-telegram",onClick:()=>r("telegram"),children:t("telegram.title")}),e.jsx(d,{type:"button",size:"sm",variant:n==="webhooks"?"default":"outline","data-testid":"settings-tab-webhooks",onClick:()=>r("webhooks"),children:t("webhook.title")})]}),n==="site"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.siteSettings")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:t("settings.siteName")}),e.jsx(u,{id:"site-name-input",value:j,onChange:s=>S(s.target.value),placeholder:t("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:t("settings.siteUrl")}),e.jsx(u,{id:"site-url-input",value:C,onChange:s=>E(s.target.value),placeholder:t("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:t("settings.language")}),e.jsxs(Oe,{value:p,onValueChange:s=>{s&&y(s)},children:[e.jsx(Ue,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(We,{placeholder:t("settings.language"),children:((je=we.locales.find(s=>s.code===p))==null?void 0:je.nativeName)??p})}),e.jsx(He,{className:"max-h-[var(--tmex-viewport-height)]",children:we.locales.map(s=>e.jsx(Ve,{value:s.code,children:s.nativeName},s.code))})]}),Te&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.theme")})}),e.jsx(f,{checked:w,onCheckedChange:s=>Me(!!s),"data-testid":"settings-theme-toggle"})]})})]})]}),n==="notifications"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("settings.notificationsTab")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserBellToast")})}),e.jsx(f,{checked:T,onCheckedChange:s=>q(!!s),"data-testid":"settings-enable-browser-bell-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramBellPush")})}),e.jsx(f,{checked:c,onCheckedChange:s=>k(!!s),"data-testid":"settings-enable-telegram-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserNotificationToast")})}),e.jsx(f,{checked:F,onCheckedChange:s=>a(!!s),"data-testid":"settings-enable-browser-notification-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableTelegramNotificationPush")})}),e.jsx(f,{checked:ee,onCheckedChange:s=>se(!!s),"data-testid":"settings-enable-telegram-notification-push"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:t("settings.bellThrottle")}),e.jsx(u,{id:"bell-throttle-input",type:"number",value:N,min:0,max:300,onChange:s=>P(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:t("settings.notificationThrottle")}),e.jsx(u,{id:"notification-throttle-input",type:"number",value:M,min:0,max:300,onChange:s=>R(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:t("settings.sshReconnectMaxRetries")}),e.jsx(u,{id:"ssh-reconnect-retries-input",type:"number",value:te,min:0,max:20,onChange:s=>ae(Number(s.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:t("settings.sshReconnectDelay")}),e.jsx(u,{id:"ssh-reconnect-delay-input",type:"number",value:ne,min:1,max:300,onChange:s=>ie(Number(s.target.value)),className:"min-h-10"})]})]})]})]}),n==="telegram"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("telegram.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-name",children:t("telegram.botName")}),e.jsx(u,{id:"new-bot-name",value:Q,onChange:s=>oe(s.target.value),placeholder:t("telegram.botNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"new-bot-token",children:t("telegram.botToken")}),e.jsx(u,{id:"new-bot-token",type:"password",value:K,onChange:s=>re(s.target.value),placeholder:t("telegram.botTokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"telegram-add-bot",onClick:()=>J.mutate(),disabled:J.isPending||!Q.trim()||!K.trim(),children:[J.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("telegram.addBot")]})})]})}),e.jsxs("div",{className:"space-y-3",children:[V.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!V.isLoading&&he.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.addBot")}),he.map(s=>e.jsx(es,{bot:s,expanded:Be===s.id,onToggleExpand:()=>{Pe(l=>l===s.id?null:s.id)}},s.id))]})]})]}),n==="webhooks"&&e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(I,{children:e.jsx(_,{children:t("webhook.title")})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:t("webhook.url")}),e.jsx(u,{id:"webhook-url-input","data-testid":"webhook-url-input",value:O,onChange:s=>le(s.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:t("webhook.secret")}),e.jsx(u,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:U,onChange:s=>ce(s.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(d,{variant:"default",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>X.mutate(),disabled:X.isPending||!O.trim()||!U.trim()||W.length===0,children:[X.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),t("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Y.map(s=>{const l=W.includes(s);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t(`notification.eventType.${s}`)}),e.jsx(f,{checked:l,"data-testid":`webhook-event-${s}`,onCheckedChange:Re=>{de(A=>Re?A.includes(s)?A:[...A,s]:A.filter(qe=>qe!==s))}})]},s)})})]}),e.jsxs("div",{className:"space-y-2",children:[G.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!G.isLoading&&ge.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),ge.map(s=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":s.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(s.createdAt).toLocaleString(Ce(p))})]}),e.jsx(d,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>ue.mutate(s.id),disabled:ue.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(Ee,{className:"h-4 w-4"})})]},s.id))]})]})]}),(n==="site"||n==="notifications")&&e.jsx("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:e.jsxs(d,{variant:"default","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),t("common.save")]})})]})}function es({bot:t,expanded:m,onToggleExpand:g}){var F;const{t:n}=B(),r=ke(),[x,v]=i.useState(t.name),[w,j]=i.useState(""),[S,C]=i.useState(t.enabled),[E,p]=i.useState(t.allowAuthRequests);i.useEffect(()=>{v(t.name),C(t.enabled),p(t.allowAuthRequests)},[t.allowAuthRequests,t.enabled,t.name]);const y=z({queryKey:["telegram-bot-chats",t.id],enabled:m,queryFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}/chats`);if(!a.ok)throw new Error(await h(a,n("telegram.loadChatsFailed")));return await a.json()}}),N=i.useMemo(()=>{var c;const a=((c=y.data)==null?void 0:c.chats)??[];return{pending:a.filter(k=>k.status==="pending"),authorized:a.filter(k=>k.status==="authorized")}},[(F=y.data)==null?void 0:F.chats]),P=b({mutationFn:async()=>{const a={name:x,enabled:S,allowAuthRequests:E};w.trim()&&(a.token=w.trim());const c=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!c.ok)throw new Error(await h(c,n("telegram.updateFailed")))},onSuccess:async()=>{j(""),await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),M=b({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await h(a,n("telegram.deleteFailed")))},onSuccess:async()=>{await r.invalidateQueries({queryKey:["telegram-bots"]}),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),R=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/approve`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.approveFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),T=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}`,{method:"DELETE"});if(!c.ok)throw new Error(await h(c,n("telegram.removeFailed")))},onSuccess:async()=>{await Promise.all([r.invalidateQueries({queryKey:["telegram-bots"]}),r.invalidateQueries({queryKey:["telegram-bot-chats",t.id]})]),o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}}),q=b({mutationFn:async a=>{const c=await fetch(`/api/settings/telegram/bots/${t.id}/chats/${encodeURIComponent(a)}/test`,{method:"POST"});if(!c.ok)throw new Error(await h(c,n("telegram.testMessageFailed")))},onSuccess:()=>{o.success(n("common.success"))},onError:a=>{o.error(a instanceof Error?a.message:n("common.error"))}});return e.jsxs("div",{className:"space-y-4 rounded-md border-0 bg-card p-4","data-testid":`telegram-bot-card-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.authorizedCount," / ",t.pendingCount]})]}),e.jsx(d,{variant:"ghost","data-testid":`telegram-bot-toggle-${t.id}`,onClick:g,children:n(m?"common.collapse":"common.expand")})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-3 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-name-${t.id}`,children:n("telegram.botName")}),e.jsx(u,{id:`bot-name-${t.id}`,value:x,onChange:a=>v(a.target.value),className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:`bot-token-${t.id}`,children:n("telegram.botToken")}),e.jsx(u,{id:`bot-token-${t.id}`,type:"password",value:w,onChange:a=>j(a.target.value),placeholder:n("telegram.tokenPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("common.enabled")}),e.jsx(f,{checked:S,onCheckedChange:a=>C(!!a)})]})}),e.jsx("div",{className:"md:col-span-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("telegram.allowAuthRequests")}),e.jsx(f,{checked:E,onCheckedChange:a=>p(!!a)})]})})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end",children:[e.jsxs(d,{variant:"destructive","data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>M.mutate(),className:"w-full sm:w-auto",children:[e.jsx(Ee,{className:"h-4 w-4"}),n("telegram.deleteBot")]}),e.jsxs(d,{variant:"default","data-testid":`telegram-bot-save-${t.id}`,onClick:()=>P.mutate(),className:"w-full sm:w-auto",children:[e.jsx(L,{className:"h-4 w-4"}),n("common.save")]})]}),m&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 border-t border-border pt-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.pendingChats")]}),N.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.pending.map(a=>e.jsx(ye,{chat:a,pending:!0,onApprove:()=>R.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"h-4 w-4"}),n("telegram.chats")]}),N.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"-"}),N.authorized.map(a=>e.jsx(ye,{chat:a,pending:!1,onTest:()=>q.mutate(a.chatId),onDelete:()=>T.mutate(a.chatId)},`${a.botId}-${a.chatId}`))]}),y.isLoading&&e.jsx("div",{className:"lg:col-span-2 text-xs text-muted-foreground",children:n("common.loading")})]})]})}function ye({chat:t,pending:m,onApprove:g,onDelete:n,onTest:r}){const{t:x}=B(),v=Se(w=>{var j;return((j=w.settings)==null?void 0:j.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[x("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Ce(v))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:m?e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"outline",size:"sm",onClick:n,children:x("telegram.reject")}),e.jsx(d,{variant:"default",size:"sm",onClick:g,children:x("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(d,{variant:"secondary",size:"sm",onClick:r,children:[e.jsx(Je,{className:"h-3.5 w-3.5"}),x("telegram.sendTestMessage")]}),e.jsx(d,{variant:"destructive",size:"sm",onClick:n,children:x("common.delete")})]})})]})}function os(){const{t}=B();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function rs(){const{t}=B(),[m,g]=i.useState(!1),n=b({mutationFn:async()=>{const r=await fetch("/api/settings/restart",{method:"POST"});if(!r.ok)throw new Error(await h(r,t("settings.restartFailed")))},onSuccess:()=>{o.success(t("settings.restartScheduled"))},onError:r=>{o.error(r instanceof Error?r.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(d,{variant:"ghost",size:"icon-sm",onClick:()=>g(!0),disabled:n.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(Ae,{open:m,onOpenChange:g,children:e.jsxs($e,{children:[e.jsxs(Ie,{children:[e.jsx(_e,{children:t("settings.restartGateway")}),e.jsx(De,{children:t("settings.restartConfirm")})]}),e.jsxs(ze,{children:[e.jsx(Le,{onClick:()=>g(!1),children:t("common.cancel")}),e.jsx(Qe,{variant:"destructive",onClick:()=>{n.mutate(),g(!1)},children:t("common.confirm")})]})]})})]})}export{rs as PageActions,os as PageTitle,is as default};
|
|
17
|
-
//# sourceMappingURL=SettingsPage-
|
|
17
|
+
//# sourceMappingURL=SettingsPage-BU-Jjd2f.js.map
|