tmex-cli 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/server.js +25 -17
- package/package.json +1 -1
- package/resources/fe-dist/assets/DevicePage-BTbDSWYN.js +26 -0
- package/resources/fe-dist/assets/DevicePage-BTbDSWYN.js.map +1 -0
- package/resources/fe-dist/assets/{DevicesPage-BTB6mlBW.js → DevicesPage-C76Xejy5.js} +2 -2
- package/resources/fe-dist/assets/{DevicesPage-BTB6mlBW.js.map → DevicesPage-C76Xejy5.js.map} +1 -1
- package/resources/fe-dist/assets/{SettingsPage-BDVq_Akt.js → SettingsPage-DQ9W4fOo.js} +2 -2
- package/resources/fe-dist/assets/{SettingsPage-BDVq_Akt.js.map → SettingsPage-DQ9W4fOo.js.map} +1 -1
- package/resources/fe-dist/assets/{index-Chps0Pui.js → index-Bmahx5fj.js} +21 -21
- package/resources/fe-dist/assets/index-Bmahx5fj.js.map +1 -0
- package/resources/fe-dist/assets/{select-7tfuDWw3.js → select-Wn7lKWHQ.js} +2 -2
- package/resources/fe-dist/assets/{select-7tfuDWw3.js.map → select-Wn7lKWHQ.js.map} +1 -1
- package/resources/fe-dist/assets/{switch-CNHRGb7-.js → switch-JVIhfemP.js} +2 -2
- package/resources/fe-dist/assets/{switch-CNHRGb7-.js.map → switch-JVIhfemP.js.map} +1 -1
- package/resources/fe-dist/assets/{useValueChanged-Bi_NzPTr.js → useValueChanged-DU---PIl.js} +2 -2
- package/resources/fe-dist/assets/{useValueChanged-Bi_NzPTr.js.map → useValueChanged-DU---PIl.js.map} +1 -1
- package/resources/fe-dist/index.html +1 -1
- package/resources/fe-dist/assets/DevicePage-BE5Hlzny.js +0 -26
- package/resources/fe-dist/assets/DevicePage-BE5Hlzny.js.map +0 -1
- package/resources/fe-dist/assets/index-Chps0Pui.js.map +0 -1
package/dist/runtime/server.js
CHANGED
|
@@ -21687,6 +21687,7 @@ var TermHistorySchema = import_zorsh.b.struct({
|
|
|
21687
21687
|
paneId: import_zorsh.b.string(),
|
|
21688
21688
|
selectToken: import_zorsh.b.bytes(16),
|
|
21689
21689
|
encoding: import_zorsh.b.u8(),
|
|
21690
|
+
alternateScreen: import_zorsh.b.bool(),
|
|
21690
21691
|
data: import_zorsh.b.bytes()
|
|
21691
21692
|
});
|
|
21692
21693
|
var SwitchAckSchema = import_zorsh.b.struct({
|
|
@@ -52151,7 +52152,9 @@ function encoderFromString(value) {
|
|
|
52151
52152
|
}
|
|
52152
52153
|
|
|
52153
52154
|
// ../../apps/gateway/src/tmux-client/local-external-connection.ts
|
|
52154
|
-
|
|
52155
|
+
function hasRenderableTerminalContent(value) {
|
|
52156
|
+
return value.trim().length > 0;
|
|
52157
|
+
}
|
|
52155
52158
|
var BELL_DEDUP_WINDOW_MS = 200;
|
|
52156
52159
|
function shouldIgnoreReaderAbortError(error) {
|
|
52157
52160
|
if (!error || typeof error !== "object") {
|
|
@@ -52475,11 +52478,12 @@ class LocalExternalTmuxConnection {
|
|
|
52475
52478
|
}
|
|
52476
52479
|
async capturePaneHistory(paneId) {
|
|
52477
52480
|
const mode = (await this.runTmux(["display-message", "-p", "-t", paneId, "#{alternate_on}"], true)).stdout.trim();
|
|
52478
|
-
const
|
|
52479
|
-
const
|
|
52480
|
-
const
|
|
52481
|
+
const alternateScreen = mode === "1";
|
|
52482
|
+
const normal = (await this.runTmux(["capture-pane", "-t", paneId, "-S", "-", "-E", "-", "-e", "-p"], true)).stdout;
|
|
52483
|
+
const alternate = (await this.runTmux(["capture-pane", "-t", paneId, "-a", "-S", "-", "-E", "-", "-e", "-p", "-q"], true)).stdout;
|
|
52484
|
+
const history = alternateScreen ? hasRenderableTerminalContent(normal) ? normal : alternate : normal || alternate;
|
|
52481
52485
|
if (history) {
|
|
52482
|
-
this.callbacks.onTerminalHistory(paneId, history);
|
|
52486
|
+
this.callbacks.onTerminalHistory(paneId, history, alternateScreen);
|
|
52483
52487
|
}
|
|
52484
52488
|
}
|
|
52485
52489
|
async requestSnapshotInternal() {
|
|
@@ -52801,7 +52805,9 @@ function parseSshBootstrapOutput(output) {
|
|
|
52801
52805
|
}
|
|
52802
52806
|
|
|
52803
52807
|
// ../../apps/gateway/src/tmux-client/ssh-external-connection.ts
|
|
52804
|
-
|
|
52808
|
+
function hasRenderableTerminalContent2(value) {
|
|
52809
|
+
return value.trim().length > 0;
|
|
52810
|
+
}
|
|
52805
52811
|
var BELL_DEDUP_WINDOW_MS2 = 200;
|
|
52806
52812
|
var COMMAND_SENTINEL = "\x1ETMEX_END ";
|
|
52807
52813
|
|
|
@@ -53263,11 +53269,12 @@ class SshExternalTmuxConnection {
|
|
|
53263
53269
|
}
|
|
53264
53270
|
async capturePaneHistory(paneId) {
|
|
53265
53271
|
const mode = (await this.runTmux(["display-message", "-p", "-t", paneId, "#{alternate_on}"], true)).stdout.trim();
|
|
53266
|
-
const
|
|
53267
|
-
const
|
|
53268
|
-
const
|
|
53272
|
+
const alternateScreen = mode === "1";
|
|
53273
|
+
const normal = (await this.runTmux(["capture-pane", "-t", paneId, "-S", "-", "-E", "-", "-e", "-p"], true, 30000)).stdout;
|
|
53274
|
+
const alternate = (await this.runTmux(["capture-pane", "-t", paneId, "-a", "-S", "-", "-E", "-", "-e", "-p", "-q"], true, 30000)).stdout;
|
|
53275
|
+
const history = alternateScreen ? hasRenderableTerminalContent2(normal) ? normal : alternate : normal || alternate;
|
|
53269
53276
|
if (history) {
|
|
53270
|
-
this.callbacks.onTerminalHistory(paneId, history);
|
|
53277
|
+
this.callbacks.onTerminalHistory(paneId, history, alternateScreen);
|
|
53271
53278
|
}
|
|
53272
53279
|
}
|
|
53273
53280
|
async requestSnapshotInternal() {
|
|
@@ -53680,8 +53687,8 @@ class DeviceSessionRuntime {
|
|
|
53680
53687
|
onTerminalOutput: (paneId, data) => {
|
|
53681
53688
|
this.broadcast((listener) => listener.onTerminalOutput?.(paneId, data));
|
|
53682
53689
|
},
|
|
53683
|
-
onTerminalHistory: (paneId, data) => {
|
|
53684
|
-
this.broadcast((listener) => listener.onTerminalHistory?.(paneId, data));
|
|
53690
|
+
onTerminalHistory: (paneId, data, alternateScreen) => {
|
|
53691
|
+
this.broadcast((listener) => listener.onTerminalHistory?.(paneId, data, alternateScreen));
|
|
53685
53692
|
},
|
|
53686
53693
|
onSnapshot: (payload) => {
|
|
53687
53694
|
this.broadcast((listener) => listener.onSnapshot?.(payload));
|
|
@@ -55053,7 +55060,7 @@ class SwitchBarrier {
|
|
|
55053
55060
|
}
|
|
55054
55061
|
pending.callbacks.onAckSent?.();
|
|
55055
55062
|
}
|
|
55056
|
-
sendTermHistory(ws, deviceId, paneId, historyData) {
|
|
55063
|
+
sendTermHistory(ws, deviceId, paneId, historyData, alternateScreen) {
|
|
55057
55064
|
const pending = this.getPending(ws, deviceId);
|
|
55058
55065
|
if (!pending)
|
|
55059
55066
|
return;
|
|
@@ -55079,6 +55086,7 @@ class SwitchBarrier {
|
|
|
55079
55086
|
paneId: context.paneId,
|
|
55080
55087
|
selectToken: context.selectToken,
|
|
55081
55088
|
encoding: 2,
|
|
55089
|
+
alternateScreen,
|
|
55082
55090
|
data: historyData
|
|
55083
55091
|
}, borshState.seqGen, borshState.maxFrameBytes);
|
|
55084
55092
|
sendToClient(ws, historyMessages);
|
|
@@ -55328,8 +55336,8 @@ class WebSocketServer {
|
|
|
55328
55336
|
onTerminalOutput: (paneId, data) => {
|
|
55329
55337
|
this.broadcastTerminalOutput(deviceId, paneId, data);
|
|
55330
55338
|
},
|
|
55331
|
-
onTerminalHistory: (paneId, data) => {
|
|
55332
|
-
this.broadcastTerminalHistory(deviceId, paneId, data);
|
|
55339
|
+
onTerminalHistory: (paneId, data, alternateScreen) => {
|
|
55340
|
+
this.broadcastTerminalHistory(deviceId, paneId, data, alternateScreen);
|
|
55333
55341
|
},
|
|
55334
55342
|
onSnapshot: (payload) => {
|
|
55335
55343
|
this.broadcastStateSnapshot(deviceId, payload);
|
|
@@ -55863,7 +55871,7 @@ class WebSocketServer {
|
|
|
55863
55871
|
this.sendChunked(client, exports_ws_borsh.KIND_TERM_OUTPUT, payloadBytes);
|
|
55864
55872
|
}
|
|
55865
55873
|
}
|
|
55866
|
-
broadcastTerminalHistory(deviceId, paneId, data) {
|
|
55874
|
+
broadcastTerminalHistory(deviceId, paneId, data, alternateScreen) {
|
|
55867
55875
|
const entry = this.connections.get(deviceId);
|
|
55868
55876
|
if (!entry)
|
|
55869
55877
|
return;
|
|
@@ -55872,7 +55880,7 @@ class WebSocketServer {
|
|
|
55872
55880
|
if (client.data.borshState.selectedPanes[deviceId] !== paneId) {
|
|
55873
55881
|
continue;
|
|
55874
55882
|
}
|
|
55875
|
-
switchBarrier.sendTermHistory(client, deviceId, paneId, historyBytes);
|
|
55883
|
+
switchBarrier.sendTermHistory(client, deviceId, paneId, historyBytes, alternateScreen);
|
|
55876
55884
|
}
|
|
55877
55885
|
}
|
|
55878
55886
|
broadcastError(deviceId, err) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var qt=Object.defineProperty;var Xt=(s,e,t)=>e in s?qt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var p=(s,e,t)=>Xt(s,typeof e!="symbol"?e+"":e,t);import{c as Pe,r as u,bw as Z,bx as ut,j as f,b as st,u as Nt,by as nt,bz as Jt,bA as rt,d as ae,e as Qt,bB as Te,f as He,B as me}from"./index-Bmahx5fj.js";import{T as Zt,A as es,a as ts,b as ss,c as ns,d as rs,e as is,f as os,g as ls}from"./useValueChanged-DU---PIl.js";import{L as Ve,S as as,a as dt}from"./switch-JVIhfemP.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 cs=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],us=Pe("arrow-down-to-line",cs);/**
|
|
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 ds=[["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"}]],hs=Pe("keyboard",ds);/**
|
|
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 fs=[["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"}]],ms=Pe("refresh-cw",fs);/**
|
|
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 ps=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],gs=Pe("smartphone",ps);function ws(s){return`rgb(${s.r} ${s.g} ${s.b})`}function Fe(s){const e=s.getContext("2d");if(!e)throw new Error("2d canvas context unavailable");return e}class ys{constructor(e){p(this,"kind","canvas");p(this,"mainCanvas");p(this,"selectionCanvas");p(this,"cursorCanvas");p(this,"mainContext");p(this,"selectionContext");p(this,"cursorContext");p(this,"theme");p(this,"fontFamily");p(this,"fontSize");p(this,"cellDimensions",{width:9,height:17});p(this,"cols",0);p(this,"rows",0);p(this,"lastCursor",null);p(this,"frameCount",0);p(this,"lastDrawnRows",[]);p(this,"colorCache",new Map);p(this,"fontCache",new Map);p(this,"cursorBlinkVisible",!0);p(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,n]of[[this.mainCanvas,"main"],[this.selectionCanvas,"selection"],[this.cursorCanvas,"cursor"]])t.dataset.layer=n,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=Fe(this.mainCanvas),this.selectionContext=Fe(this.selectionCanvas),this.cursorContext=Fe(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 n=e.meta.dirty==="full"?e.rows:e.rows.filter(r=>r.dirty);for(const r of n)this.drawRow(r,e.meta.colors),this.lastDrawnRows.push(r.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 n=Math.max(1,e),r=Math.max(1,t),i=n*this.cellDimensions.width,o=r*this.cellDimensions.height,l=Math.max(1,globalThis.devicePixelRatio??1);if(this.cols===n&&this.rows===r){const d=`${i}px`,c=`${o}px`;if(this.mainCanvas.style.width===d&&this.mainCanvas.style.height===c)return}this.cols=n,this.rows=r;for(const d of[this.mainCanvas,this.selectionCanvas,this.cursorCanvas])d.width=Math.max(1,Math.ceil(i*l)),d.height=Math.max(1,Math.ceil(o*l)),d.style.width=`${i}px`,d.style.height=`${o}px`;for(const d of[this.mainContext,this.selectionContext,this.cursorContext])d.setTransform(l,0,0,l,0,0),d.textBaseline="top",d.imageSmoothingEnabled=!1}drawSelection(e,t){if(this.selectionContext.clearRect(0,0,this.cols*this.cellDimensions.width,this.rows*this.cellDimensions.height),e.length!==0){this.selectionContext.fillStyle=t;for(const n of e)this.selectionContext.fillRect(n.x*this.cellDimensions.width,n.row*this.cellDimensions.height,n.width*this.cellDimensions.width,this.cellDimensions.height)}}drawRow(e,t){const n=e.y*this.cellDimensions.height,r=this.cols*this.cellDimensions.width,i=this.toCss(t.background);this.mainContext.clearRect(0,n,r,this.cellDimensions.height),this.mainContext.fillStyle=i,this.mainContext.fillRect(0,n,r,this.cellDimensions.height);for(const o of e.cells){if(o.widthKind==="spacer-tail"||o.widthKind==="spacer-head")continue;const l=o.x*this.cellDimensions.width,d=o.style.inverse?o.fgColor??t.foreground:o.bgColor??t.background,c=o.style.inverse?o.bgColor??t.background:o.fgColor??t.foreground,y=o.widthKind==="wide"?this.cellDimensions.width*2:this.cellDimensions.width;(d.r!==t.background.r||d.g!==t.background.g||d.b!==t.background.b)&&(this.mainContext.fillStyle=this.toCss(d),this.mainContext.fillRect(l,n,y,this.cellDimensions.height)),!(!o.text||o.style.invisible)&&(this.mainContext.font=this.resolveFont(o.style),this.mainContext.fillStyle=this.toCss(c),this.mainContext.fillText(o.text,l,n),o.style.underline>0&&this.mainContext.fillRect(l,n+this.cellDimensions.height-2,Math.max(y-1,1),1),o.style.strikethrough&&this.mainContext.fillRect(l,n+this.cellDimensions.height*.55,Math.max(y-1,1),1),o.style.overline&&this.mainContext.fillRect(l,n+1,Math.max(y-1,1),1))}}drawCursor(e){const t=e.colors,n=e.cursor,r=this.lastCursor;if(this.cursorContext.clearRect(0,0,this.cols*this.cellDimensions.width,this.rows*this.cellDimensions.height),!n.visible||n.x===null||n.y===null){this.lastCursor=null,this.stopCursorBlink();return}const i=n.x*this.cellDimensions.width,o=n.y*this.cellDimensions.height,l=n.wideTail?this.cellDimensions.width*2:this.cellDimensions.width,d=t.cursor??t.foreground,c=this.toCss(d);this.cursorContext.fillStyle=c,this.cursorContext.strokeStyle=c,this.cursorContext.globalAlpha=.7,this.cursorContext.fillRect(i,o+this.cellDimensions.height-2,Math.max(l-1,1),2),this.cursorContext.globalAlpha=1,this.startCursorBlink(),this.lastCursor={x:n.x,y:n.y,style:n.style},r&&(r.x!==this.lastCursor.x||r.y!==this.lastCursor.y||r.style!==this.lastCursor.style)&&this.lastDrawnRows.push(r.y)}resolveFont(e){const t=[e.italic?"italic":"normal",e.bold?"700":"400",`${this.fontSize}px`,this.fontFamily].join("|"),n=this.fontCache.get(t);if(n)return n;const r=`${e.italic?"italic ":""}${e.bold?"700 ":""}${this.fontSize}px ${this.fontFamily}`;return this.fontCache.set(t,r),r}toCss(e){const t=`${e.r},${e.g},${e.b}`,n=this.colorCache.get(t);if(n)return n;const r=ws(e);return this.colorCache.set(t,r),r}}const bs=0,xs={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},it={Backquote:"`",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Comma:",",Equal:"=",Minus:"-",Period:".",Quote:"'",Semicolon:";",Slash:"/",Space:" ",IntlBackslash:"\\",IntlYen:"¥",IntlRo:"\\"};for(let s=0;s<=9;s+=1)it[`Digit${s}`]=String(s);for(let s=0;s<26;s+=1){const e=String.fromCharCode(65+s),t=String.fromCharCode(97+s);it[`Key${e}`]=t}function ht(s){return xs[s]??bs}function Ss(s){const e=it[s];return e?e.codePointAt(0)??null:null}const ge=0,_s=-2,Ts=1,Es=2,vs=3,Rs=10,Cs=11,Ds=12,Ns=13,Ms=14,ks=15,Ls=16,Ps=17,Os=1,As=2,Us=1,Is=2,Bs=3,Hs=4,Vs=5,Fs=6,Gs=1,zs=2,Ys=3,Ks=4;function ot(s){if(s.disposed||s.renderStateHandle===0)throw new Error("render state resources already disposed")}function $s(s){switch(s){case 2:return"full";case 1:return"partial";default:return"clean"}}function js(s){switch(s){case 0:return"bar";case 2:return"underline";case 3:return"block-hollow";default:return"block"}}function Ws(s){switch(s){case 1:return"wide";case 2:return"spacer-tail";case 3:return"spacer-head";default:return"narrow"}}function Ee(s,e){return{r:s.view().getUint8(e),g:s.view().getUint8(e+1),b:s.view().getUint8(e+2)}}function ft(s,e){const t=s.bindings.allocStruct("GhosttyColorRgb");try{const n=e(t.ptr);if(n===_s)return null;if(n!==ge)throw new Error(`ghostty optional color read failed with result ${n}`);return Ee(s.bindings,t.ptr)}finally{t.free()}}function de(s,e){const t=s.bindings.allocU8();try{const n=e(t);if(typeof n=="number"&&n!==ge)throw new Error(`ghostty bool read failed with result ${n}`);return s.bindings.readU8(t)!==0}finally{s.bindings.freeU8(t)}}function Ne(s,e){const t=s.bindings.allocBytes(2);try{const n=e(t);if(typeof n=="number"&&n!==ge)throw new Error(`ghostty u16 read failed with result ${n}`);return s.bindings.view().getUint16(t,!0)}finally{s.bindings.freeBytes(t,2)}}function qs(s,e){const t=s.bindings.allocBytes(4);try{const n=e(t);if(typeof n=="number"&&n!==ge)throw new Error(`ghostty u32 read failed with result ${n}`);return s.bindings.view().getUint32(t,!0)}finally{s.bindings.freeBytes(t,4)}}function Ze(s,e){const t=s.bindings.allocBytes(4);try{const n=e(t);if(typeof n=="number"&&n!==ge)throw new Error(`ghostty enum read failed with result ${n}`);return s.bindings.view().getInt32(t,!0)}finally{s.bindings.freeBytes(t,4)}}function mt(s,e){const t=s.bindings.allocBytes(8);try{const n=e(t);if(typeof n=="number"&&n!==ge)throw new Error(`ghostty u64 read failed with result ${n}`);return s.bindings.readU64(t)}finally{s.bindings.freeBytes(t,8)}}function Xs(s){const e=s.bindings.allocStruct("GhosttyStyle");try{s.bindings.setField(e.view,"GhosttyStyle","size",s.bindings.typeSize("GhosttyStyle")),s.bindings.getRenderStateRowCellValue(s.rowCellsHandle,Is,e.ptr);const t=n=>s.bindings.field("GhosttyStyle",n).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 Js(s){const e=qs(s,n=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Bs,n));if(e===0)return[];const t=s.bindings.allocBytes(e*4);try{s.bindings.getRenderStateRowCellValue(s.rowCellsHandle,Hs,t);const n=[];for(let r=0;r<e;r+=1)n.push(s.bindings.view().getUint32(t+r*4,!0));return n}finally{s.bindings.freeBytes(t,e*4)}}function Qs(s){if(s.length===0)return"";try{return String.fromCodePoint(...s)}catch{return""}}function Zs(s){let e="";for(const t of s)if(!(t.widthKind==="spacer-tail"||t.widthKind==="spacer-head")){if(t.text){e+=t.text;continue}t.widthKind==="narrow"&&(e+=" ")}return e}function en(s){const e=s.bindings.allocStruct("GhosttyRenderStateColors");try{s.bindings.setField(e.view,"GhosttyRenderStateColors","size",s.bindings.typeSize("GhosttyRenderStateColors")),s.bindings.getRenderStateColors(s.renderStateHandle,e.ptr);const t=s.bindings.field("GhosttyRenderStateColors","palette").offset,n=[];for(let o=0;o<256;o+=1){const l=e.ptr+t+o*3;n.push(Ee(s.bindings,l))}const r=e.view.getUint8(s.bindings.field("GhosttyRenderStateColors","cursor_has_value").offset)!==0,i=de(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ms,o));return{cols:Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ts,o)),rows:Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Es,o)),dirty:$s(Ze(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,vs,o))),colors:{background:Ee(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","background").offset),foreground:Ee(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","foreground").offset),cursor:r?Ee(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","cursor").offset):null,palette:n},cursor:{style:js(Ze(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Rs,o))),visible:de(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Cs,o)),blinking:de(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ds,o)),passwordInput:de(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ns,o)),x:i?Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,ks,o)):null,y:i?Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ls,o)):null,wideTail:i?de(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ps,o)):!1}}}finally{e.free()}}function tn(s,e){const t=mt(s,i=>s.bindings.getRenderStateRowValueResult(s.rowIteratorHandle,As,i));s.bindings.bindRenderStateRowCells(s.rowIteratorHandle,s.rowCellsHandle);const n=[];let r=0;for(;s.bindings.nextRenderStateRowCell(s.rowCellsHandle);){const i=mt(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Us,c)),o=Js(s),l=Ws(Ze(s,c=>s.bindings.getRawCellValueResult(i,Ys,c))),d={x:r,text:Qs(o),codepoints:o,widthKind:l,hasText:de(s,c=>s.bindings.getRawCellValueResult(i,Ks,c)),style:Xs(s),fgColor:ft(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Fs,c)),bgColor:ft(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Vs,c))};n.push(d),r+=1}return{y:e,dirty:de(s,i=>s.bindings.getRenderStateRowValueResult(s.rowIteratorHandle,Os,i)),wrap:de(s,i=>s.bindings.getRawRowValueResult(t,Gs,i)),wrapContinuation:de(s,i=>s.bindings.getRawRowValueResult(t,zs,i)),text:Zs(n),cells:n}}function pt(s){return{bindings:s,renderStateHandle:s.createRenderState(),rowIteratorHandle:s.createRenderStateRowIterator(),rowCellsHandle:s.createRenderStateRowCells(),snapshotVersion:0,disposed:!1,cachedMeta:null}}function gt(s,e){ot(s),s.bindings.updateRenderState(s.renderStateHandle,e),s.bindings.bindRenderStateRowIterator(s.renderStateHandle,s.rowIteratorHandle),s.snapshotVersion+=1,s.cachedMeta=null}function et(s){return ot(s),s.cachedMeta||(s.cachedMeta=en(s)),s.cachedMeta}function*sn(s){ot(s);const e=et(s);s.bindings.bindRenderStateRowIterator(s.renderStateHandle,s.rowIteratorHandle);let t=0;for(;t<e.rows&&s.bindings.nextRenderStateRowIterator(s.rowIteratorHandle);)yield tn(s,t),t+=1}function Ge(s){s.disposed||(s.disposed=!0,s.rowCellsHandle!==0&&(s.bindings.freeRenderStateRowCells(s.rowCellsHandle),s.rowCellsHandle=0),s.rowIteratorHandle!==0&&(s.bindings.freeRenderStateRowIterator(s.rowIteratorHandle),s.rowIteratorHandle=0),s.renderStateHandle!==0&&(s.bindings.freeRenderState(s.renderStateHandle),s.renderStateHandle=0),s.cachedMeta=null)}function lt(s,e){return Math.max(0,Math.min(Math.max(s.length-1,0),Math.floor(e)))}function nn(s,e){return s.line<e.line?{start:s,end:e}:s.line>e.line?{start:e,end:s}:s.col<=e.col?{start:s,end:e}:{start:e,end:s}}function rn(s,e,t){if(!t)return{start:{line:s,col:0},end:{line:s,col:0}};const n=lt(t,e),r=d=>/[\p{L}\p{N}_-]/u.test(d),i=t[n]??"";if(!r(i))return{start:{line:s,col:n},end:{line:s,col:n}};let o=n,l=n;for(;o>0&&r(t[o-1]??"");)o-=1;for(;l+1<t.length&&r(t[l+1]??"");)l+=1;return{start:{line:s,col:o},end:{line:s,col:l}}}function Mt(s,e){const t=Math.max(e.length-1,0);return{start:{line:s,col:0},end:{line:s,col:t}}}function kt(s,e,t){const n=t(s.line);switch(e){case"word":return rn(s.line,s.col,n);case"line":return Mt(s.line,n);default:{const r=lt(n,s.col);return{start:{line:s.line,col:r},end:{line:s.line,col:r}}}}}function Lt(){return{anchor:null,focus:null,mode:"character"}}function on(s){return!!(s.anchor&&s.focus)}function ln(){return Lt()}function an(s,e,t){const n=kt(e,e.mode,t);return{anchor:n.start,focus:n.end,mode:e.mode}}function wt(s,e,t){return s.anchor?s.mode==="line"?{...s,focus:Mt(e.line,t(e.line)).end}:s.mode==="word"?{...s,focus:kt(e,"word",t).end}:{...s,focus:{line:e.line,col:lt(t(e.line),e.col)}}:s}function Pt(s){return!s.anchor||!s.focus?null:nn(s.anchor,s.focus)}function cn(s,e){const t=Pt(s);if(!t)return null;const n=[];for(let r=t.start.line;r<=t.end.line;r+=1){const i=e(r);if(r===t.start.line&&r===t.end.line){n.push(i.slice(t.start.col,t.end.col+1));continue}if(r===t.start.line){n.push(i.slice(t.start.col));continue}if(r===t.end.line){n.push(i.slice(0,t.end.col+1));continue}n.push(i)}return n.join(`
|
|
22
|
+
`)}function un(s,e,t,n){const r=Pt(s);if(!r)return[];const i=e+t-1,o=[];for(let l=Math.max(r.start.line,e);l<=Math.min(r.end.line,i);l+=1){const d=l-e;if(l===r.start.line&&l===r.end.line){o.push({row:d,x:r.start.col,width:r.end.col-r.start.col+1});continue}if(l===r.start.line){const y=n?Math.max(n(l).length-r.start.col,0):Number.MAX_SAFE_INTEGER;o.push({row:d,x:r.start.col,width:y});continue}if(l===r.end.line){o.push({row:d,x:0,width:r.end.col+1});continue}const c=n?n(l).length:Number.MAX_SAFE_INTEGER;o.push({row:d,x:0,width:c})}return o}function dn(s){return(s.metaKey||s.ctrlKey)&&!s.altKey}function hn(s){return dn(s)&&s.key.toLowerCase()==="c"}async function fn(s){var e;s&&typeof navigator<"u"&&(e=navigator.clipboard)!=null&&e.writeText&&await navigator.clipboard.writeText(s)}function mn(s,e){return!e||!s.clipboardData?!1:(s.clipboardData.setData("text/plain",e),s.preventDefault(),!0)}const pn="/assets/ghostty-vt-BKQMf-5X.wasm",Le=0,yt=-3,gn=11,wn=12,yn=13,bn=14,xn=1,Sn=2,_n=9,Tn=1,En=0,vn=1,Rn=2,Cn=0,Dn=1,Nn=2,Mn=4,kn=2004,Ln=9,Pn=1e3,On=1002,An=1003,Un=1005,bt=1006,In=1015,xt=1016;let ze=null;function M(s,e){if(s!==Le)throw new Error(`${e} failed with result ${s}`)}function Ot(s){const e=s.trim().replace(/^#/,"");if(e.length!==6)throw new Error(`expected #RRGGBB color, received: ${s}`);return[Number.parseInt(e.slice(0,2),16),Number.parseInt(e.slice(2,4),16),Number.parseInt(e.slice(4,6),16)]}function Bn(s){const t=[...[s.black,s.red,s.green,s.yellow,s.blue,s.magenta,s.cyan,s.white,s.brightBlack,s.brightRed,s.brightGreen,s.brightYellow,s.brightBlue,s.brightMagenta,s.brightCyan,s.brightWhite].map(Ot)],n=[0,95,135,175,215,255];for(const r of n)for(const i of n)for(const o of n)t.push([r,i,o]);for(let r=0;r<24;r+=1){const i=8+r*10;t.push([i,i,i])}return t}function Hn(s){let e=0;return s&1&&(e+=4),s&4&&(e+=8),s&2&&(e+=16),e}function Ye(s){return s<0||s>223?null:String.fromCharCode(s+32)}function Vn(s){switch(s){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 At(s){var t,n;let e=0;return s.shiftKey&&(e|=1),s.ctrlKey&&(e|=2),s.altKey&&(e|=4),s.metaKey&&(e|=8),(t=s.getModifierState)!=null&&t.call(s,"CapsLock")&&(e|=16),(n=s.getModifierState)!=null&&n.call(s,"NumLock")&&(e|=32),e}class Fn{constructor(e,t,n){this.bindings=e,this.typeName=t,this.ptr=n}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 Gn{constructor(e,t){p(this,"exports");p(this,"layout");p(this,"decoder",new TextDecoder);p(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 n=this.layout[e],r=n==null?void 0:n.fields[t];if(!n||!r)throw new Error(`unknown ghostty field: ${e}.${t}`);return r}allocStruct(e){const t=this.allocBytes(this.typeSize(e));return this.bytes(t,this.typeSize(e)).fill(0),new Fn(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,n,r){const i=this.field(t,n),o=i.offset;switch(i.type){case"u8":case"bool":e.setUint8(o,Number(r));return;case"u16":e.setUint16(o,Number(r),!0);return;case"u32":e.setUint32(o,Number(r),!0);return;case"u64":e.setBigUint64(o,BigInt(r),!0);return;case"usize":{e.setUint32(o,Number(r),!0);return}case"i32":case"enum":e.setInt32(o,Number(r),!0);return;default:throw new Error(`unsupported field type ${t}.${n}: ${i.type}`)}}writeString(e){const t=this.encoder.encode(e),n=this.allocBytes(t.length);return this.bytes(n,t.length).set(t),{ptr:n,len:t.length,free:()=>this.freeBytes(n,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,n){const r=this.allocStruct("GhosttyTerminalOptions");this.setField(r.view,"GhosttyTerminalOptions","cols",e),this.setField(r.view,"GhosttyTerminalOptions","rows",t),this.setField(r.view,"GhosttyTerminalOptions","max_scrollback",n);const i=this.allocOpaque();try{return M(this.exports.ghostty_terminal_new(0,i,r.ptr),"ghostty_terminal_new"),this.readPointer(i)}finally{r.free(),this.freeOpaque(i)}}freeTerminal(e){this.exports.ghostty_terminal_free(e)}writeVt(e,t){const n=typeof t=="string"?this.encoder.encode(t):t,r=this.writeBytes(n);try{this.exports.ghostty_terminal_vt_write(e,r.ptr,r.len)}finally{r.free()}}resetTerminal(e){this.exports.ghostty_terminal_reset(e)}resizeTerminal(e,t,n,r){M(this.exports.ghostty_terminal_resize(e,t,n,Math.max(1,Math.round(r.width)),Math.max(1,Math.round(r.height))),"ghostty_terminal_resize")}scrollViewportDelta(e,t){const n=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(n.view,"GhosttyTerminalScrollViewport","tag",Rn),n.view.setBigInt64(this.field("GhosttyTerminalScrollViewport","value").offset,BigInt(t),!0),this.exports.ghostty_terminal_scroll_viewport(e,n.ptr)}finally{n.free()}}scrollViewportTop(e){const t=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(t.view,"GhosttyTerminalScrollViewport","tag",En),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",vn),this.exports.ghostty_terminal_scroll_viewport(e,t.ptr)}finally{t.free()}}setTerminalTheme(e,t){const n=this.allocStruct("GhosttyColorRgb"),r=this.allocStruct("GhosttyColorRgb"),i=this.allocStruct("GhosttyColorRgb"),o=Bn(t),l=this.allocBytes(o.length*3),d=(y,C)=>{const[L,U,T]=Ot(C);this.setField(y.view,"GhosttyColorRgb","r",L),this.setField(y.view,"GhosttyColorRgb","g",U),this.setField(y.view,"GhosttyColorRgb","b",T)};d(n,t.foreground),d(r,t.background),d(i,t.cursor);const c=this.bytes(l,o.length*3);o.forEach(([y,C,L],U)=>{const T=U*3;c[T]=y,c[T+1]=C,c[T+2]=L});try{M(this.exports.ghostty_terminal_set(e,gn,n.ptr),"ghostty_terminal_set(foreground)"),M(this.exports.ghostty_terminal_set(e,wn,r.ptr),"ghostty_terminal_set(background)"),M(this.exports.ghostty_terminal_set(e,yn,i.ptr),"ghostty_terminal_set(cursor)"),M(this.exports.ghostty_terminal_set(e,bn,l),"ghostty_terminal_set(palette)")}finally{n.free(),r.free(),i.free(),this.freeBytes(l,o.length*3)}}readTerminalSize(e){const t=this.allocBytes(2),n=this.allocBytes(2);try{return M(this.exports.ghostty_terminal_get(e,xn,t),"ghostty_terminal_get(cols)"),M(this.exports.ghostty_terminal_get(e,Sn,n),"ghostty_terminal_get(rows)"),{cols:this.view().getUint16(t,!0),rows:this.view().getUint16(n,!0)}}finally{this.freeBytes(t,2),this.freeBytes(n,2)}}readScrollbar(e){const t=this.allocStruct("GhosttyTerminalScrollbar");try{return M(this.exports.ghostty_terminal_get(e,_n,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 n=this.allocU8();try{return M(this.exports.ghostty_terminal_mode_get(e,t,n),"ghostty_terminal_mode_get"),this.readU8(n)!==0}finally{this.freeU8(n)}}setTerminalMode(e,t,n){M(this.exports.ghostty_terminal_mode_set(e,t,n?1:0),"ghostty_terminal_mode_set")}createFormatter(e,t,n){const r=this.allocStruct("GhosttyFormatterTerminalOptions"),i=this.field("GhosttyFormatterTerminalOptions","extra").offset,o=this.view(r.ptr+i,this.typeSize("GhosttyFormatterTerminalExtra")),l=this.field("GhosttyFormatterTerminalExtra","screen").offset,d=this.view(r.ptr+i+l,this.typeSize("GhosttyFormatterScreenExtra")),c=this.allocOpaque();try{this.setField(r.view,"GhosttyFormatterTerminalOptions","size",this.typeSize("GhosttyFormatterTerminalOptions")),this.setField(r.view,"GhosttyFormatterTerminalOptions","emit",t),this.setField(r.view,"GhosttyFormatterTerminalOptions","unwrap",n.unwrap),this.setField(r.view,"GhosttyFormatterTerminalOptions","trim",n.trim),this.setField(o,"GhosttyFormatterTerminalExtra","size",this.typeSize("GhosttyFormatterTerminalExtra")),this.setField(o,"GhosttyFormatterTerminalExtra","palette",n.includePalette),this.setField(d,"GhosttyFormatterScreenExtra","size",this.typeSize("GhosttyFormatterScreenExtra"));const y=this.field("GhosttyFormatterTerminalOptions","selection").offset;return r.view.setUint32(y,n.selectionPtr??0,!0),M(this.exports.ghostty_formatter_terminal_new(0,c,e,r.ptr),"ghostty_formatter_terminal_new"),this.readPointer(c)}finally{r.free(),this.freeOpaque(c)}}freeFormatter(e){this.exports.ghostty_formatter_free(e)}resolveViewportGridRef(e,t,n){const r=this.allocStruct("GhosttyPoint"),i=this.allocStruct("GhosttyGridRef");try{this.setField(r.view,"GhosttyPoint","tag",Tn);const o=this.field("GhosttyPoint","value").offset,l=this.view(r.ptr+o,this.typeSize("GhosttyPointCoordinate"));return this.setField(l,"GhosttyPointCoordinate","x",t),this.setField(l,"GhosttyPointCoordinate","y",n),this.exports.ghostty_terminal_grid_ref(e,r.ptr,i.ptr)!==Le?(i.free(),null):i}finally{r.free()}}createViewportSelection(e,t,n){const r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),o=this.resolveViewportGridRef(e,0,0);if(!o)return null;let l=null;for(let c=i-1;c>=0&&(l=this.resolveViewportGridRef(e,r-1,c),!l);c-=1);if(!l)return o.free(),null;const d=this.allocStruct("GhosttySelection");try{this.setField(d.view,"GhosttySelection","size",this.typeSize("GhosttySelection")),this.setField(d.view,"GhosttySelection","rectangle",!1);const c=this.field("GhosttySelection","start").offset,y=this.field("GhosttySelection","end").offset;return this.bytes(d.ptr+c,this.typeSize("GhosttyGridRef")).set(this.bytes(o.ptr,this.typeSize("GhosttyGridRef"))),this.bytes(d.ptr+y,this.typeSize("GhosttyGridRef")).set(this.bytes(l.ptr,this.typeSize("GhosttyGridRef"))),d}finally{o.free(),l.free()}}formatViewport(e,t,n,r){const i=this.readTerminalSize(e),o=this.createViewportSelection(e,Math.max(1,Math.min(i.cols,r.cols)),Math.max(1,Math.min(i.rows,r.rows))),l=this.createFormatter(e,t,{...n,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(),n=this.allocUsize();try{M(this.exports.ghostty_formatter_format_alloc(e,0,t,n),"ghostty_formatter_format_alloc");const r=this.readPointer(t),i=this.readUsize(n),o=this.buffer().byteLength;try{if(i===0||r===0)return"";if(r<0||r>o||i>o-r)throw new Error(`ghostty_formatter_format_alloc returned invalid slice ptr=${r} len=${i} mem=${o}`);return this.readOwnedUtf8(r,i)}finally{i>0&&r!==0&&this.exports.ghostty_free(0,r,i)}}finally{this.freeOpaque(t),this.freeUsize(n)}}createRenderState(){const e=this.allocOpaque();try{return M(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){M(this.exports.ghostty_render_state_update(e,t),"ghostty_render_state_update")}getRenderStateValueResult(e,t,n){return this.exports.ghostty_render_state_get(e,t,n)}getRenderStateValue(e,t,n){M(this.getRenderStateValueResult(e,t,n),"ghostty_render_state_get")}setRenderStateValue(e,t,n){M(this.exports.ghostty_render_state_set(e,t,n),"ghostty_render_state_set")}getRenderStateColors(e,t){M(this.exports.ghostty_render_state_colors_get(e,t),"ghostty_render_state_colors_get")}createRenderStateRowIterator(){const e=this.allocOpaque();try{return M(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 n=this.allocOpaque();try{this.view(n,4).setUint32(0,t,!0),this.getRenderStateValue(e,4,n)}finally{this.freeOpaque(n)}}nextRenderStateRowIterator(e){return this.exports.ghostty_render_state_row_iterator_next(e)!==0}getRenderStateRowValueResult(e,t,n){return this.exports.ghostty_render_state_row_get(e,t,n)}getRenderStateRowValue(e,t,n){M(this.getRenderStateRowValueResult(e,t,n),"ghostty_render_state_row_get")}setRenderStateRowValue(e,t,n){M(this.exports.ghostty_render_state_row_set(e,t,n),"ghostty_render_state_row_set")}createRenderStateRowCells(){const e=this.allocOpaque();try{return M(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 n=this.allocOpaque();try{this.view(n,4).setUint32(0,t,!0),this.getRenderStateRowValue(e,3,n)}finally{this.freeOpaque(n)}}nextRenderStateRowCell(e){return this.exports.ghostty_render_state_row_cells_next(e)!==0}selectRenderStateRowCell(e,t){M(this.exports.ghostty_render_state_row_cells_select(e,t),"ghostty_render_state_row_cells_select")}getRenderStateRowCellValueResult(e,t,n){return this.exports.ghostty_render_state_row_cells_get(e,t,n)}getRenderStateRowCellValue(e,t,n){M(this.getRenderStateRowCellValueResult(e,t,n),"ghostty_render_state_row_cells_get")}getRawRowValueResult(e,t,n){return this.exports.ghostty_row_get(e,t,n)}getRawRowValue(e,t,n){M(this.getRawRowValueResult(e,t,n),"ghostty_row_get")}getRawCellValueResult(e,t,n){return this.exports.ghostty_cell_get(e,t,n)}getRawCellValue(e,t,n){M(this.getRawCellValueResult(e,t,n),"ghostty_cell_get")}createKeyEncoder(){const e=this.allocOpaque();try{return M(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{M(this.exports.ghostty_mouse_encoder_new(0,e),"ghostty_mouse_encoder_new");const n=this.readPointer(e);return this.view().setUint8(t,1),this.exports.ghostty_mouse_encoder_setopt(n,Mn,t),n}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,n){const r=this.isTerminalModeEnabled(t,An),i=this.isTerminalModeEnabled(t,On),o=this.isTerminalModeEnabled(t,Pn),l=this.isTerminalModeEnabled(t,Ln);if(!r&&!i&&!o&&!l||n.action==="motion"&&!(r||i&&n.anyButtonPressed)||l&&n.action!=="press"||!r&&!i&&!l&&n.action==="motion")return null;const d=Vn(n.button);if(d===null)return null;const c=Math.max(1,Math.floor(n.x/Math.max(1,n.cellWidth))+1),y=Math.max(1,Math.floor(n.y/Math.max(1,n.cellHeight))+1),C=Math.round(n.x+1),L=Math.round(n.y+1);let U=n.action==="release"&&!this.isTerminalModeEnabled(t,bt)&&!this.isTerminalModeEnabled(t,xt)?3:d;if(n.action==="motion"&&(U+=32),U+=Hn(n.mods),this.isTerminalModeEnabled(t,xt)){const T=n.action==="release"?"m":"M";return`\x1B[<${U};${C};${L}${T}`}if(this.isTerminalModeEnabled(t,bt)){const T=n.action==="release"?"m":"M";return`\x1B[<${U};${c};${y}${T}`}if(this.isTerminalModeEnabled(t,In))return`\x1B[${U};${c};${y}M`;if(this.isTerminalModeEnabled(t,Un)||o||i||r||l){const T=Ye(U),S=Ye(c),b=Ye(y);return!T||!S||!b?null:`\x1B[M${T}${S}${b}`}return null}encodeKeyEvent(e,t,n){if(n.keyCode<=0)return null;const r=this.allocOpaque();let i=0,o=null;try{return M(this.exports.ghostty_key_event_new(0,r),"ghostty_key_event_new"),i=this.readPointer(r),this.exports.ghostty_key_encoder_setopt_from_terminal(e,t),this.exports.ghostty_key_event_set_action(i,n.action==="release"?Cn:n.action==="repeat"?Nn:Dn),this.exports.ghostty_key_event_set_key(i,n.keyCode),this.exports.ghostty_key_event_set_mods(i,n.mods),this.exports.ghostty_key_event_set_consumed_mods(i,0),this.exports.ghostty_key_event_set_composing(i,n.composing?1:0),n.utf8&&(o=this.writeString(n.utf8),this.exports.ghostty_key_event_set_utf8(i,o.ptr,o.len)),typeof n.unshiftedCodepoint=="number"&&this.exports.ghostty_key_event_set_unshifted_codepoint(i,n.unshiftedCodepoint),this.encodeKeyHandle(e,i)}finally{o==null||o.free(),i!==0&&this.exports.ghostty_key_event_free(i),this.freeOpaque(r)}}encodeKeyHandle(e,t){const n=this.allocUsize();try{const r=this.exports.ghostty_key_encoder_encode(e,t,0,0,n);r!==yt&&r!==Le&&M(r,"ghostty_key_encoder_encode(size)");const i=Math.max(0,this.readUsize(n));if(i===0)return null;const o=this.allocBytes(i),l=this.allocUsize();try{M(this.exports.ghostty_key_encoder_encode(e,t,o,i,l),"ghostty_key_encoder_encode");const d=this.readUsize(l);return d===0?null:this.readOwnedUtf8(o,d)}finally{this.freeBytes(o,i),this.freeUsize(l)}}finally{this.freeUsize(n)}}encodePaste(e,t){const n=this.writeString(t),r=this.allocUsize();try{const i=this.isTerminalModeEnabled(e,kn),o=this.exports.ghostty_paste_encode(n.ptr,n.len,i?1:0,0,0,r);o!==yt&&o!==Le&&M(o,"ghostty_paste_encode(size)");const l=Math.max(0,this.readUsize(r));if(l===0)return"";const d=this.allocBytes(l),c=this.allocUsize();try{return M(this.exports.ghostty_paste_encode(n.ptr,n.len,i?1:0,d,l,c),"ghostty_paste_encode"),this.readOwnedUtf8(d,this.readUsize(c))}finally{this.freeBytes(d,l),this.freeUsize(c)}}finally{n.free(),this.freeUsize(r)}}}async function zn(s){if((s.startsWith("/")||s.startsWith("./")||s.startsWith("../")||/^[A-Za-z]:[\\/]/.test(s))&&typeof Bun<"u")return Bun.file(s).arrayBuffer();const t=await fetch(s);if(!t.ok)throw new Error(`failed to load ghostty wasm: ${t.status} ${t.statusText}`);return t.arrayBuffer()}async function Yn(){return ze||(ze=(async()=>{const s=await zn(pn),t=(await WebAssembly.instantiate(s,{env:{log(){}}})).instance.exports,n=new Uint8Array(t.memory.buffer),r=t.ghostty_type_json();let i=r;for(;n[i]!==0;)i+=1;const o=JSON.parse(new TextDecoder().decode(n.subarray(r,i)));return new Gn(t,o)})()),ze}const St=80,ve=24,Ke=9,Me=17,Kn=48,Ut="ghostty-official",$e=9,je=1e3,We=1002,qe=1003,Xe=1007,Je=1047,Qe=1049,_t=1,Tt=3,Et=2,$n=4,jn=5;class Wn{constructor(e){this.content=e}translateToString(e){return e?this.content.replace(/\s+$/u,""):this.content}}class qn{constructor(){p(this,"active",{baseY:0,viewportY:0,length:ve,getLine:e=>{const t=e-this.active.viewportY,n=this.visibleLines[t];return typeof n=="string"?new Wn(n):null}});p(this,"visibleLines",Array.from({length:ve},()=>""))}setViewport(e,t,n,r){this.active.viewportY=e,this.active.baseY=t,this.active.length=n,this.visibleLines=r}}function Xn(s){return!(s.key.length===1&&!s.ctrlKey&&!s.altKey&&!s.metaKey)}function Jn(s,e){const t=s.slice(0,e).map(n=>n.text);for(;t.length<e;)t.push("");return t}function ke(s){return At({shiftKey:!!s.shiftKey,ctrlKey:!!s.ctrlKey,altKey:!!s.altKey,metaKey:!!s.metaKey,getModifierState:()=>!1})}class Qn{constructor(){p(this,"terminal",null)}activate(e){this.terminal=e instanceof Oe?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 Oe{constructor(e,t,n,r,i,o){p(this,"buffer",new qn);p(this,"_core",{_renderService:{dimensions:{css:{cell:{width:Ke,height:Me}}}}});p(this,"options");p(this,"element",null);p(this,"textarea",null);p(this,"cols",St);p(this,"rows",ve);p(this,"bindings");p(this,"terminalHandle");p(this,"keyEncoderHandle");p(this,"mouseEncoderHandle");p(this,"renderState");p(this,"dataListeners",new Set);p(this,"addons",new Set);p(this,"screenElement",null);p(this,"renderer",null);p(this,"renderRaf",null);p(this,"disposed",!1);p(this,"disableStdin");p(this,"customKeyEventHandler",()=>!0);p(this,"imeIsComposing",!1);p(this,"lastCompositionCommit",null);p(this,"selectionState",Lt());p(this,"lineCache",new Map);p(this,"lastViewportOffset",0);p(this,"lastViewportRows",ve);p(this,"lastRenderedRows",[]);p(this,"pointerDrag",{active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null});p(this,"autoScrollTimer",null);p(this,"domEventDisposers",[]);p(this,"copyShortcutSuppressed",!1);p(this,"scrollbarThumb",null);p(this,"scrollbarFadeTimer",null);p(this,"pressedMouseButtons",new Set);p(this,"wheelPixelDelta",0);this.bindings=e,this.terminalHandle=t,this.keyEncoderHandle=n,this.mouseEncoderHandle=r,this.renderState=i,this.options=o,this.disableStdin=!!o.disableStdin}static async create(e){const t=await Yn(),n=t.createTerminal(St,ve,e.scrollback);let r=0,i=0,o=null;try{return t.setTerminalTheme(n,e.theme),r=t.createKeyEncoder(),i=t.createMouseEncoder(),o=pt(t),new Oe(t,n,r,i,o,e)}catch(l){throw o&&Ge(o),r!==0&&t.freeKeyEncoder(r),i!==0&&t.freeMouseEncoder(i),t.freeTerminal(n),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 n=document.createElement("div");n.className="xterm-viewport",n.style.width="100%",n.style.height="100%",n.style.overflow="hidden",n.style.position="relative";const r=document.createElement("div");r.className="xterm-screen",r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.userSelect="none",r.style.webkitUserSelect="none",r.style.backgroundColor=this.options.theme.background;const i=document.createElement("div");i.className="xterm-helper-textarea",i.setAttribute("aria-label","Terminal Input"),i.setAttribute("role","textbox"),i.setAttribute("contenteditable","true"),i.setAttribute("autocorrect","off"),i.setAttribute("autocapitalize","off"),i.setAttribute("spellcheck","false"),i.style.position="absolute",i.style.opacity="1",i.style.pointerEvents="none",i.style.left="0",i.style.top="0",i.style.minWidth="1px",i.style.minHeight="1px",i.style.whiteSpace="pre",i.style.border="0",i.style.padding="0",i.style.margin="0",i.style.color=this.options.theme.foreground,i.style.backgroundColor="transparent",i.style.caretColor="transparent",i.style.overflow="visible",i.style.outline="none",i.style.boxShadow="none",i.style.fontFamily=this.options.fontFamily,i.style.fontSize=`${this.options.fontSize}px`,i.style.userSelect="text",i.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),n.appendChild(r),t.appendChild(n),t.appendChild(i),t.appendChild(o),e.appendChild(t),this.element=t,this.screenElement=r,this.textarea=i,this.scrollbarThumb=l,this.renderer=new ys({screenElement:r,theme:this.options.theme,fontFamily:this.options.fontFamily,fontSize:this.options.fontSize}),this.syncInputState(),this.bindDomEvents(),this.updateCellDimensions();const d=this.measureSizeFromElement();d?this.resize(d.cols,d.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}write(e){this.disposed||(this.bindings.writeVt(this.terminalHandle,e),this.scheduleRender())}reset(){this.disposed||(this.lineCache.clear(),this.clearSelectionState(!1),this.bindings.resetTerminal(this.terminalHandle),this.scheduleRender())}resize(e,t){if(this.disposed)return;const n=Math.max(2,Math.floor(e)),r=Math.max(2,Math.floor(t));this.cols=n,this.rows=r,this.clearSelectionState(!1),this.bindings.resizeTerminal(this.terminalHandle,n,r,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($e),mouseNormal:this.isModeEnabled(je),mouseButton:this.isModeEnabled(We),mouseAny:this.isModeEnabled(qe),mouseUtf8:this.isModeEnabled(1005),mouseSgr:this.isModeEnabled(1006),mouseSgrPixels:this.isModeEnabled(1016),mouseUrxvt:this.isModeEnabled(1015),altScroll:this.isModeEnabled(Xe),altScreen1047:this.isModeEnabled(Je),altScreen1049:this.isModeEnabled(Qe)}}restoreModeSnapshot(e){this.bindings.setTerminalMode(this.terminalHandle,$e,e.mouseX10),this.bindings.setTerminalMode(this.terminalHandle,je,e.mouseNormal),this.bindings.setTerminalMode(this.terminalHandle,We,e.mouseButton),this.bindings.setTerminalMode(this.terminalHandle,qe,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,Xe,e.altScroll),this.bindings.setTerminalMode(this.terminalHandle,Je,e.altScreen1047),this.bindings.setTerminalMode(this.terminalHandle,Qe,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 n=this.getInputRoutingState();if(n.mouseReporting){const r=t<0?$n:jn;let i=!1;for(let o=0;o<Math.abs(t);o+=1)i=this.emitMouseInput({action:"press",button:r,clientX:e.clientX,clientY:e.clientY,mods:ke(e),anyButtonPressed:this.pressedMouseButtons.size>0})||i;return i}return n.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:n,height:r}=this.cellDimensions();return t.width===0||t.height===0||n<=0||r<=0?null:{cols:Math.max(2,Math.floor(t.width/n)),rows:Math.max(2,Math.floor(t.height/r))}}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 n of this.addons)n.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,Ge(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",i=>{if(i instanceof MouseEvent){if(this.disableStdin||this.focus(),this.getInputRoutingState().mouseReporting){const o=this.mouseButtonFromEvent(i);if(o===null)return;this.clearSelectionState(),this.pressedMouseButtons.add(o),this.emitMouseInput({action:"press",button:o,clientX:i.clientX,clientY:i.clientY,mods:ke(i),anyButtonPressed:!0}),i.preventDefault();return}i.button===0&&(this.beginPointerSelection(i),i.preventDefault())}}),e.addEventListener("wheel",i=>{this.handleViewportGesture({source:"wheel",deltaY:i.deltaY,deltaMode:i.deltaMode,clientX:i.clientX,clientY:i.clientY,shiftKey:i.shiftKey,ctrlKey:i.ctrlKey,altKey:i.altKey,metaKey:i.metaKey})&&i.preventDefault()},{passive:!1});const r=typeof window<"u"&&typeof window.addEventListener=="function"?window:null;if(r){const i=l=>{if(this.getInputRoutingState().mouseReporting){this.emitMouseInput({action:"motion",button:this.mouseButtonFromButtons(l.buttons),clientX:l.clientX,clientY:l.clientY,mods:ke(l),anyButtonPressed:this.pressedMouseButtons.size>0||l.buttons>0});return}this.updatePointerSelection(l)},o=l=>{if(this.getInputRoutingState().mouseReporting){const d=this.mouseButtonFromEvent(l);d!==null&&this.pressedMouseButtons.delete(d),this.emitMouseInput({action:"release",button:d,clientX:l.clientX,clientY:l.clientY,mods:ke(l),anyButtonPressed:this.pressedMouseButtons.size>0});return}this.finishPointerSelection(l)};r.addEventListener("mousemove",i),r.addEventListener("mouseup",o),this.domEventDisposers.push(()=>{r.removeEventListener("mousemove",i),r.removeEventListener("mouseup",o)})}t.addEventListener("keydown",i=>{const o=this.getSelectionText();if(o&&hn(i)){this.copyShortcutSuppressed=!0,i.preventDefault(),fn(o).catch(()=>{}),this.clearTextarea();return}if(!this.customKeyEventHandler(i)||this.disableStdin||this.imeIsComposing||i.keyCode===229||!Xn(i))return;const l=this.encodeKeyboardEvent(i,i.repeat?"repeat":"press");l&&(i.preventDefault(),this.emitData(l),this.clearTextarea())}),t.addEventListener("keyup",i=>{if(this.copyShortcutSuppressed){const l=i.key.toLowerCase();if(l==="c"){i.preventDefault();return}if(l==="control"||l==="meta"||l==="os"){this.copyShortcutSuppressed=!1,i.preventDefault();return}}if(this.disableStdin||this.imeIsComposing)return;const o=this.encodeKeyboardEvent(i,"release");o&&(i.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",i=>{this.imeIsComposing=!1;const o=i.data??"";o&&(this.lastCompositionCommit={data:o,at:Date.now()},this.emitData(o),this.clearTextarea())}),t.addEventListener("beforeinput",i=>{if(this.disableStdin||i.inputType==="insertFromPaste")return;const o=i.data??"";if(!o||i.isComposing||this.imeIsComposing)return;const l=this.lastCompositionCommit;if(l&&l.data===o&&Date.now()-l.at<40){this.lastCompositionCommit=null,i.preventDefault(),this.clearTextarea();return}this.lastCompositionCommit=null,i.preventDefault(),this.emitData(o),this.clearTextarea()}),t.addEventListener("paste",i=>{var l;if(this.disableStdin)return;const o=((l=i.clipboardData)==null?void 0:l.getData("text/plain"))??"";o&&(i.preventDefault(),this.paste(o),this.clearTextarea())}),t.addEventListener("copy",i=>{const o=this.getSelectionText();o&&mn(i,o)}),t.addEventListener("input",()=>{if(this.disableStdin||this.imeIsComposing)return;const i=t.textContent??"";if(!i){this.clearTextarea();return}const o=this.lastCompositionCommit;if(o&&o.data===i&&Date.now()-o.at<40){this.lastCompositionCommit=null,this.clearTextarea();return}this.lastCompositionCommit=null,this.emitData(i),this.clearTextarea()})}encodeKeyboardEvent(e,t){const n=ht(e.code);if(n===0)return null;const r=e.key.length===1&&!e.ctrlKey&&!e.metaKey?e.key:null;return this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:t,keyCode:n,mods:At(e),composing:e.isComposing,utf8:r,unshiftedCodepoint:Ss(e.code)})}getInputRoutingState(){const e=this.isModeEnabled($e)||this.isModeEnabled(je)||this.isModeEnabled(We)||this.isModeEnabled(qe),t=this.isModeEnabled(Je)||this.isModeEnabled(Qe);return{mouseReporting:e,altScroll:!e&&t&&this.isModeEnabled(Xe)}}gestureToLines(e){const t=this.cellDimensions().height||Me;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 r=Math.max(1,this.rows),i=e.deltaY*r;return i>0?Math.ceil(i):Math.floor(i)}this.wheelPixelDelta+=e.deltaY;const n=this.wheelPixelDelta>0?Math.floor(this.wheelPixelDelta/t):Math.ceil(this.wheelPixelDelta/t);return n!==0&&(this.wheelPixelDelta-=n*t),n}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 _t;case 1:return Tt;case 2:return Et;default:return null}}mouseButtonFromButtons(e){return e&1?_t:e&4?Tt:e&2?Et:null}pointerPositionFromClient(e,t){var o;const n=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!n)return null;const r=Math.max(1,n.width),i=Math.max(1,n.height);return{x:Math.max(0,Math.min(r-1,e-n.left)),y:Math.max(0,Math.min(i-1,t-n.top))}}emitMouseInput(e){var o;if(this.disableStdin)return!1;const t=this.pointerPositionFromClient(e.clientX,e.clientY);if(!t)return!1;const n=this.cellDimensions(),r=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!r)return!1;const i=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(r.width)),screenHeight:Math.max(1,Math.round(r.height)),cellWidth:Math.max(1,Math.round(n.width||Ke)),cellHeight:Math.max(1,Math.round(n.height||Me))});return i?(this.emitData(i),!0):!1}emitAltScrollInput(e){const t=ht(e<0?"ArrowUp":"ArrowDown");if(t===0)return!1;let n=!1;for(let r=0;r<Math.abs(e);r+=1){const i=this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:"press",keyCode:t,mods:0,composing:!1,utf8:null,unshiftedCodepoint:null});i&&(this.emitData(i),n=!0)}return n}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:n,height:r}=this.cellDimensions();if(n<=0||r<=0)return;const i=pt(this.bindings);let o=0,l=0;try{gt(i,this.terminalHandle);const y=et(i);y.cursor.x!==null&&y.cursor.y!==null&&(o=y.cursor.x,l=y.cursor.y)}finally{Ge(i)}const d=o*n,c=l*r;e.style.left=`${d}px`,e.style.top=`${c}px`,e.style.width=`${Math.max(1,n)}px`,e.style.height=`${Math.max(1,r)}px`,e.style.lineHeight=`${r}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);gt(this.renderState,this.terminalHandle);const n=et(this.renderState),r=Array.from(sn(this.renderState));this.cols=Math.max(2,n.cols),this.rows=Math.max(2,n.rows||t),this.lastViewportOffset=e.offset,this.lastViewportRows=this.rows,this.lastRenderedRows=r;for(const c of r)this.lineCache.set(e.offset+c.y,c.text);const i=un(this.selectionState,this.lastViewportOffset,this.lastViewportRows,c=>this.getLineText(c)),o=this.getSelectionText();this.renderer.render({meta:n,rows:r,cellDimensions:this.cellDimensions(),selectionRects:i,selectionColor:this.options.theme.selectionBackground});const l=Jn(r,this.rows),d=Math.max(0,e.total-e.len);this.buffer.setViewport(e.offset,d,e.total,l),this.updateSelectionTextProbe(o),this.updateScrollbar(e)}updateScrollbar(e){var d;const t=this.scrollbarThumb;if(!t)return;const n=((d=this.screenElement)==null?void 0:d.clientHeight)??0;if(n===0||e.total<=e.len){t.style.opacity="0";return}const r=e.len/e.total,i=Math.max(20,r*n),l=e.offset/Math.max(1,e.total-e.len)*(n-i);t.style.height=`${i}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(),this._core._renderService.dimensions.css.cell.width=t.width>0?t.width/10:Ke,this._core._renderService.dimensions.css.cell.height=t.height>0?t.height:Me}clearSelectionState(e=!0){this.selectionState=ln(),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()}beginPointerSelection(e){const t=this.hitTest(e.clientX,e.clientY);if(!t)return;const n=this.selectionModeFromClickDetail(e.detail);this.pointerDrag={active:!0,moved:!1,mode:n,lastClientX:e.clientX,lastClientY:e.clientY},this.selectionState=an(this.selectionState,{...t,mode:n},r=>this.getLineText(r)),this.updateAutoScroll(),this.render()}updatePointerSelection(e){if(!this.pointerDrag.active)return;const t=this.hitTest(e.clientX,e.clientY);this.pointerDrag.lastClientX=e.clientX,this.pointerDrag.lastClientY=e.clientY,t&&(this.pointerDrag.moved=!0,this.selectionState=wt(this.selectionState,t,n=>this.getLineText(n)),this.render()),this.updateAutoScroll()}finishPointerSelection(e){var n,r,i,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&&((n=this.selectionState.anchor)==null?void 0:n.line)===((r=this.selectionState.focus)==null?void 0:r.line)&&((i=this.selectionState.anchor)==null?void 0:i.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 L;const n=(L=this.screenElement)==null?void 0:L.getBoundingClientRect();if(!n)return null;const{width:r,height:i}=this.cellDimensions();if(r<=0||i<=0)return null;const o=e-n.left,l=t-n.top,d=Math.max(this.cols-1,0),c=Math.max(this.lastViewportRows-1,0),y=Math.max(0,Math.min(d,Math.floor(o/r))),C=Math.max(0,Math.min(c,Math.floor(l/i)));return{line:this.lastViewportOffset+C,col:y}}getLineText(e){const t=this.lineCache.get(e);if(typeof t=="string")return t;const n=e-this.lastViewportOffset,r=this.lastRenderedRows[n];return(r==null?void 0:r.text)??""}getSelectionText(){return on(this.selectionState)?cn(this.selectionState,e=>this.getLineText(e)):null}updateSelectionTextProbe(e){globalThis.__tmexE2eTerminalSelectionText=e}updateAutoScroll(){var n;if(!this.pointerDrag.active||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(n=this.screenElement)==null?void 0:n.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()},Kn))}stepAutoScroll(){var r;if(!this.pointerDrag.active||this.pointerDrag.lastClientX===null||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(r=this.screenElement)==null?void 0:r.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 n=this.hitTest(this.pointerDrag.lastClientX,this.pointerDrag.lastClientY);n&&(this.selectionState=wt(this.selectionState,n,i=>this.getLineText(i)),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 Zn(s){return Oe.create(s)}const It={background:"#e1e1e1",foreground:"#616161",cursor:"#616161",selectionBackground:"rgba(97, 97, 97, 0.25)",black:"#171717",red:"#bf2172",green:"#009799",yellow:"#9a7200",blue:"#007299",magenta:"#9b1d72",cyan:"#007173",white:"#d9d9d9",brightBlack:"#4e4e4e",brightRed:"#e12672",brightGreen:"#00bddf",brightYellow:"#ffdd00",brightBlue:"#7299bc",brightMagenta:"#e17899",brightCyan:"#6fbcbd",brightWhite:"#f1f1f1"},Bt={background:"#262626",foreground:"#d0d0d0",cursor:"#c5c5c5",selectionBackground:"rgba(197, 197, 197, 0.25)",black:"#000000",red:"#ba3c3c",green:"#5d876d",yellow:"#d5a54e",blue:"#887c8d",magenta:"#cd6d6d",cyan:"#618484",white:"#cfcdc3",brightBlack:"#000000",brightRed:"#ea7171",brightGreen:"#7aab7a",brightYellow:"#d1d194",brightBlue:"#afa3b5",brightMagenta:"#e29f9f",brightCyan:"#a0aea3",brightWhite:"#d0d0d0"},er='"JetBrains Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", "Source Han Mono SC", "Sarasa Mono SC", "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", monospace';function tr(s){if(!s)return s;const e=s.replace(/\r\n/g,`
|
|
23
|
+
`);return(e.endsWith(`
|
|
24
|
+
`)?e.slice(0,-1):e).replace(/\n/g,`\r
|
|
25
|
+
`)}function vt(s,e){let t=e,n=0;for(const l of s)l===10&&!t&&(n+=1),t=l===13;const r=t;if(n===0)return{normalized:s,endedWithCR:r};const i=new Uint8Array(s.length+n);let o=0;t=e;for(const l of s)l===10&&!t&&(i[o]=13,o+=1),i[o]=l,o+=1,t=l===13;return{normalized:i,endedWithCR:r}}const sr=1.3,nr=36;function rr(s,e){const t=u.useRef(!1);return u.useEffect(()=>{const n=s.current;if(!n||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;t.current=!0;let i=0,o=null,l=!1,d=0;const c=b=>b?!!(b.closest(".scrollbar")||b.closest(".slider")||b.closest(".xterm-scroll-area")):!1,y=(b,h,R)=>{const D=R instanceof Element?R:null;if(c(D))return!0;const j=document.elementFromPoint(b,h);if(c(j))return!0;const P=n.querySelector(".xterm");if(!(P instanceof HTMLElement))return!1;const O=P.getBoundingClientRect(),K=b>=O.left&&b<=O.right,W=h>=O.top&&h<=O.bottom;return!K||!W?!1:b>=O.right-nr},C=()=>[n.querySelector(".xterm-viewport"),n.querySelector(".xterm-scrollable-element")].filter(h=>h instanceof HTMLElement),L=b=>{if(o===null)return null;for(let h=0;h<b.length;h+=1){const R=b.item(h);if(R&&R.identifier===o)return R}return null},U=b=>{if(b.touches.length!==1)return;const h=b.touches.item(0);h&&(o=h.identifier,i=h.clientY,d=0,l=y(h.clientX,h.clientY,b.target))},T=b=>{var K,W,oe,_,k,G,z,H;const h=L(b.touches)??b.touches.item(0);if(!h||(l||(l=y(h.clientX,h.clientY,b.target),l&&(d=0)),l))return;const R=h.clientY,D=i-R;if(i=R,D===0)return;let j=!1,P=!1;const O=(e==null?void 0:e())??null;if(O){const B=O==null?void 0:O._core,A=((_=(oe=(W=(K=B==null?void 0:B._renderService)==null?void 0:K.dimensions)==null?void 0:W.css)==null?void 0:oe.cell)==null?void 0:_.height)??18;d+=D*sr;const v=d>0?Math.floor(d/A):Math.ceil(d/A);if(typeof O.handleViewportGesture=="function")v!==0&&(j=O.handleViewportGesture({source:"touch",deltaY:v*A,clientX:h.clientX,clientY:h.clientY}),d-=v*A);else if(v!==0){const $=((G=(k=O.buffer)==null?void 0:k.active)==null?void 0:G.viewportY)??0;O.scrollLines(v);const te=((H=(z=O.buffer)==null?void 0:z.active)==null?void 0:H.viewportY)??0;j=$!==te,P=v<0&&$<=0&&te<=0,d-=v*A}}else{const B=C();if(B.length===0)return;for(const A of B){const v=A.scrollTop;A.scrollTop+=D;const $=A.scrollTop;Math.abs($-v)>0&&(j=!0),D<0&&$<=0&&(P=!0)}if(!j){const A=n.querySelector(".xterm");if(A instanceof HTMLElement){const v=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:D}),$=A.dispatchEvent(v);j=v.defaultPrevented||!$}}}b.cancelable&&(j||P)&&b.preventDefault()},S=b=>{o===null||!L(b.changedTouches)||(o=null,d=0,l=!1)};return n.addEventListener("touchstart",U,{passive:!0}),n.addEventListener("touchmove",T,{passive:!1}),n.addEventListener("touchend",S,{passive:!0}),n.addEventListener("touchcancel",S,{passive:!0}),()=>{t.current=!1,n.removeEventListener("touchstart",U),n.removeEventListener("touchmove",T),n.removeEventListener("touchend",S),n.removeEventListener("touchcancel",S)}},[s,e]),t}function ir({now:s,remoteSize:e,pendingLocalSize:t,ttlMs:n=2e3}){return!t||s-t.at>n?!0:t.cols===e.cols&&t.rows===e.rows}function or({currentSize:s,containerSize:e,force:t=!1}){return t?!0:s.cols!==e.cols||s.rows!==e.rows}function lr({deviceId:s,paneId:e,deviceConnected:t,isSelectionInvalid:n,onResize:r,onSync:i,getContainerRect:o}){const l=u.useRef(null),d=u.useRef(null),c=u.useRef(null),y=u.useRef(null),C=u.useRef(0),L=u.useRef([]),U=u.useRef(null),T=u.useRef(null),S=u.useRef(o),b=u.useRef(r),h=u.useRef(i);u.useEffect(()=>{b.current=r},[r]),u.useEffect(()=>{h.current=i},[i]),u.useEffect(()=>{S.current=o},[o]);const R=u.useCallback(()=>{var v,$,te,x,w,I,V,Y,q,le;const _=T.current,k=U.current;if(!_||!k||!_.element)return null;let G;try{const N=k.proposeDimensions();if(!N)throw new Error("fitAddon.proposeDimensions() returned null");G=Math.max(2,N.cols)}catch{const N=_._core,pe=((x=(te=($=(v=N==null?void 0:N._renderService)==null?void 0:v.dimensions)==null?void 0:$.css)==null?void 0:te.cell)==null?void 0:x.width)??9,ee=(w=S.current)==null?void 0:w.call(S);if(!ee||ee.width===0)return null;G=Math.max(2,Math.floor(ee.width/pe))}const z=(I=S.current)==null?void 0:I.call(S);if(!z||z.height===0)return null;const H=_._core,B=((le=(q=(Y=(V=H==null?void 0:H._renderService)==null?void 0:V.dimensions)==null?void 0:Y.css)==null?void 0:q.cell)==null?void 0:le.height)??17,A=Math.max(2,Math.floor(z.height/B));return{cols:G,rows:A}},[]),D=u.useCallback((_,k)=>{const G=T.current;G&&(G.cols===_&&G.rows===k||G.resize(_,k))},[]),j=u.useCallback((_,k=!1)=>{if(!s||!e||!t||n&&_!=="sync"||!k&&Date.now()<C.current||!T.current)return!1;const z=R();if(!z)return!1;const{cols:H,rows:B}=z,A=c.current;return!k&&A&&A.cols===H&&A.rows===B?(D(H,B),!0):(D(H,B),_==="sync"?h.current(H,B):b.current(H,B),c.current={cols:H,rows:B},y.current={cols:H,rows:B,at:Date.now()},!0)},[D,t,s,n,R,e]),P=u.useCallback((_="resize",k={})=>{const{immediate:G=!1,force:z=!1}=k;d.current!==null&&(window.clearTimeout(d.current),d.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const H=()=>{l.current=requestAnimationFrame(()=>{l.current=null,j(_,z)})};if(G){H();return}d.current=window.setTimeout(()=>{d.current=null,H()},150)},[j]),O=u.useCallback(()=>{for(const _ of L.current)window.clearTimeout(_);L.current=[]},[]),K=u.useCallback(()=>{var k;O(),P("sync",{immediate:!0,force:!0});const _=window.setTimeout(()=>{P("sync",{immediate:!0,force:!0})},60);L.current.push(_),typeof document<"u"&&"fonts"in document&&((k=document.fonts)!=null&&k.ready)&&document.fonts.ready.then(()=>{P("sync",{immediate:!0,force:!0})}).catch(()=>{})},[O,P]);u.useEffect(()=>{let _=null;const k=()=>{_!==null&&cancelAnimationFrame(_),_=requestAnimationFrame(()=>{_=null,P("resize")})};return window.addEventListener("resize",k),()=>{window.removeEventListener("resize",k),_!==null&&cancelAnimationFrame(_)}},[P]),u.useEffect(()=>{const _=()=>{const z=T.current,H=R();!z||!H||!or({currentSize:{cols:Math.max(2,z.cols),rows:Math.max(2,z.rows)},containerSize:H,force:!0})||P("sync",{force:!0})},k=()=>{document.visibilityState==="visible"&&_()},G=()=>{_()};return document.addEventListener("visibilitychange",k),window.addEventListener("focus",G),()=>{document.removeEventListener("visibilitychange",k),window.removeEventListener("focus",G)}},[R,P]),u.useEffect(()=>()=>{O(),d.current!==null&&window.clearTimeout(d.current),l.current!==null&&cancelAnimationFrame(l.current)},[O]);const W=u.useCallback(_=>{U.current=_},[]),oe=u.useCallback(_=>{T.current=_},[]);return{scheduleResize:P,runPostSelectResize:K,clearPostSelectResizeTimers:O,setFitAddon:W,setTerminal:oe,lastReportedSize:c,pendingLocalSize:y,suppressLocalResizeUntil:C}}const ar={fontFamily:er,fontSize:13,scrollback:1e4},tt="tmex:terminal-mode-cache";function Rt(s,e){try{const t=sessionStorage.getItem(tt);return t?JSON.parse(t)[`${s}:${e}`]??null:null}catch{return null}}function cr(s,e,t){try{const n=sessionStorage.getItem(tt),r=n?JSON.parse(n):{},i=`${s}:${e}`;t?r[i]=t:delete r[i],sessionStorage.setItem(tt,JSON.stringify(r))}catch{}}function ur(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!0}}function dr(s,e){if(!e)return s;const t=ur();if(!s)return t;const n=s.mouseNormal||s.mouseButton||s.mouseAny;return{...s,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1049:!0,mouseNormal:n?s.mouseNormal:t.mouseNormal}}function hr(s){var t;const e=globalThis;e.__tmexE2eXterm=s,e.__tmexE2eTerminal=s,e.__tmexE2eTerminalEngine=Ut,e.__tmexE2eTerminalRenderer=((t=s.getRendererKind)==null?void 0:t.call(s))??null}function fr(s){if(!s)return;const e=globalThis;e.__tmexE2eTerminal!==s&&e.__tmexE2eXterm!==s||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const Ht=u.forwardRef(({deviceId:s,paneId:e,theme:t,inputMode:n,deviceConnected:r,isSelectionInvalid:i,onResize:o,onSync:l},d)=>{const[c,y]=u.useState(null),C=Z(x=>x.sendInput),L=u.useMemo(()=>{switch(t){case"light":return It;default:return Bt}},[t]),U=u.useRef(null),T=u.useRef(null),S=u.useRef(null),b=u.useRef(s),h=u.useRef(e),R=u.useRef(s),D=u.useRef(e),j=u.useRef(r&&!i),P=u.useRef(n),O=u.useRef(L),K=u.useRef(!1),W=u.useRef(!1),oe=u.useRef(null),_=u.useRef(!1),k=u.useCallback((x,w,I)=>{!(x!=null&&x.exportModeSnapshot)||!w||!I||cr(w,I,x.exportModeSnapshot())},[]),G=u.useCallback(()=>c,[c]);rr(U,G),u.useEffect(()=>{b.current=s,h.current=e,W.current=!1},[s,e]),u.useEffect(()=>{j.current=r&&!i},[r,i]),u.useEffect(()=>{P.current=n},[n]),u.useEffect(()=>{O.current=L},[L]);const z=u.useCallback(x=>{if(!x||n!=="direct"||!j.current)return;const w=b.current,I=h.current;!w||!I||C(w,I,x,!1)},[n,C]),{pendingLocalSize:H,scheduleResize:B,runPostSelectResize:A,setFitAddon:v,setTerminal:$}=lr({deviceId:s,paneId:e,deviceConnected:r,isSelectionInvalid:i,onResize:o,onSync:l,getContainerRect:()=>{const x=U.current;if(!x)return null;const w=x.getBoundingClientRect();return{width:w.width,height:w.height}}});u.useEffect(()=>{let x=!1,w=null;return Zn({...ar,theme:O.current,disableStdin:P.current==="editor"}).then(I=>{if(x){I.dispose();return}w=I,T.current&&I.open(T.current),hr(I),y(I)}),()=>{x=!0,y(null),fr(w),w==null||w.dispose()}},[]),u.useEffect(()=>{!c||!("setTheme"in c)||c.setTheme(L)},[c,L]),u.useEffect(()=>{!c||!("setDisableStdin"in c)||c.setDisableStdin(n==="editor")},[c,n]);const te=u.useMemo(()=>c?{onResetTerminal:x=>{b.current===x&&(k(c,R.current,D.current),_.current=!0,c.reset(),K.current=!1,A())},onApplyHistory:(x,w,I)=>{var Y;if(b.current!==x)return;const V=dr(Rt(b.current,h.current),I);V&&((Y=c.restoreModeSnapshot)==null||Y.call(c,V)),W.current=!0,c.write(tr(w)),_.current=!1,R.current=b.current,D.current=h.current,k(c,b.current,h.current)},onFlushBuffer:(x,w)=>{if(b.current===x){for(const I of w){const V=vt(I,K.current);K.current=V.endedWithCR,c.write(V.normalized)}W.current&&(c.buffer.active.baseY<=1&&c.scrollToTop(),W.current=!1),R.current=b.current,D.current=h.current,k(c,b.current,h.current)}},onOutput:(x,w,I)=>{if(b.current!==x||h.current!==w||!j.current)return;const V=vt(I,K.current);K.current=V.endedWithCR,c.write(V.normalized),W.current&&(c.buffer.active.baseY<=1&&c.scrollToTop(),W.current=!1),R.current=b.current,D.current=h.current,k(c,b.current,h.current)}}:{},[c,k,A]);return u.useEffect(()=>{var x;if(!c)oe.current=null;else if(oe.current!==c){K.current=!1,c.reset();const w=Rt(b.current,h.current);w&&((x=c.restoreModeSnapshot)==null||x.call(c,w)),R.current=b.current,D.current=h.current,oe.current=c}},[c]),u.useEffect(()=>{if(!(!c||!s||!e))return()=>{if(_.current){_.current=!1;return}k(c,R.current,D.current)}},[s,c,e,k]),u.useEffect(()=>{ut(te)},[te]),u.useEffect(()=>()=>{ut({})},[]),u.useEffect(()=>{if(!c){S.current=null,v(null),$(null);return}const x=new Qn;return c.loadAddon(x),S.current=x,v(x),$(c),A(),()=>{try{x.dispose()}finally{S.current=null,v(null),$(null)}}},[c,A,v,$]),u.useEffect(()=>{const x=U.current;if(!x)return;let w=null;const I=new ResizeObserver(()=>{w!==null&&cancelAnimationFrame(w),w=requestAnimationFrame(()=>{w=null,B("resize")})});return I.observe(x),()=>{I.disconnect(),w!==null&&cancelAnimationFrame(w)}},[B]),u.useEffect(()=>{if(!c||!s||!e)return;const x=c.onData(w=>{!r||i||z(w)});return c.attachCustomKeyEventHandler(w=>!r||i||w.type!=="keydown"||n!=="direct"?!0:w.shiftKey&&w.key==="Enter"?(w.preventDefault(),z("\x1B[13;2u"),!1):!0),()=>{x.dispose(),c.attachCustomKeyEventHandler(()=>!0)}},[c,r,i,n,z,s,e]),u.useImperativeHandle(d,()=>({write:x=>c==null?void 0:c.write(x),reset:()=>{c==null||c.reset(),K.current=!1},scrollToBottom:()=>c==null?void 0:c.scrollToBottom(),resize:(x,w)=>c==null?void 0:c.resize(x,w),getTerminal:()=>c??null,getSize:()=>c?{cols:Math.max(2,c.cols),rows:Math.max(2,c.rows)}:null,runPostSelectResize:()=>A(),scheduleResize:(x,w)=>B(x,w),calculateSizeFromContainer:()=>{var pe,ee,ce,se,ne,we,Ae,Ue,Ie,ye,X,be,xe,Ce,De,ue;const x=U.current,w=c,I=S.current;if(!x||!w)return null;const V=x.getBoundingClientRect();if(V.width===0||V.height===0)return null;const Y=w._core;let q;if(I)try{const re=I.proposeDimensions();if(re)q=Math.max(2,re.cols);else{const fe=((se=(ce=(ee=(pe=Y==null?void 0:Y._renderService)==null?void 0:pe.dimensions)==null?void 0:ee.css)==null?void 0:ce.cell)==null?void 0:se.width)??9;q=Math.max(2,Math.floor(V.width/fe))}}catch{const re=((Ue=(Ae=(we=(ne=Y==null?void 0:Y._renderService)==null?void 0:ne.dimensions)==null?void 0:we.css)==null?void 0:Ae.cell)==null?void 0:Ue.width)??9;q=Math.max(2,Math.floor(V.width/re))}else{const re=((be=(X=(ye=(Ie=Y==null?void 0:Y._renderService)==null?void 0:Ie.dimensions)==null?void 0:ye.css)==null?void 0:X.cell)==null?void 0:be.width)??9;q=Math.max(2,Math.floor(V.width/re))}const le=((ue=(De=(Ce=(xe=Y==null?void 0:Y._renderService)==null?void 0:xe.dimensions)==null?void 0:Ce.css)==null?void 0:De.cell)==null?void 0:ue.height)??17,N=Math.max(2,Math.floor(V.height/le));return{cols:q,rows:N}},getPendingLocalSize:()=>H.current}),[c,H,A,B]),f.jsxDEV("div",{ref:U,className:"h-full w-full relative",style:{backgroundColor:L.background},"data-terminal-engine":Ut,children:f.jsxDEV("div",{ref:T,className:"absolute inset-0"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/components/terminal/Terminal.tsx",lineNumber:536,columnNumber:9},void 0)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/components/terminal/Terminal.tsx",lineNumber:530,columnNumber:7},void 0)});Ht.displayName="Terminal";const mr=1200,pr=2e3;function he(s,e){return!s||!e?!1:s.windowId===e.windowId&&s.paneId===e.paneId}function Vt(s,e){const t=s.filter(n=>e-n.at<mr);return t.length===0?null:t.reduce((n,r)=>r.at>n.at?r:n)}function Re(s,e=Date.now()){return!s||e-s.at>pr?null:s}function gr(s){const e=s.now??Date.now(),t=Vt(s.recentSelectRequests,e);if(t&&!he(t,s.activePaneFromEvent)||he(s.currentRoute,s.activePaneFromEvent)||he(s.lastHandledActive,s.activePaneFromEvent))return!0;const n=Re(s.pendingUserSelection,e);return!!(n&&!he(n,s.activePaneFromEvent))}function wr(s){const e=s.now??Date.now(),t=Vt(s.recentSelectRequests,e),n=Re(s.pendingUserSelection,e);return!!(n&&!he(n,s.snapshotActive)||t&&!he(t,s.snapshotActive))}function yr(s){const e=s.now??Date.now(),t=Re(s.pendingUserSelection,e);return!(t&&he(t,s.routeTarget)||s.snapshotActive&&he(s.snapshotActive,s.routeTarget))}function br(){const s=st.getState().settings;return(s==null?void 0:s.siteName)||"tmex"}function Ct(s){const e=s==null?void 0:s.trim();return e&&e.length>0?e:"?"}function Ft({paneIdx:s,windowIdx:e,paneTitle:t,windowName:n,deviceName:r}){const i=e??"?",o=s??"?",l=Ct(t??n),d=Ct(r);return`${i}/${o}: ${l}@${d}`}function xr(s){const e=br();return s!=null&&s.trim()?`[${e}]${s}`:e}function Sr(){if(typeof navigator>"u")return!1;const s=navigator.userAgent,e=/iPad|iPhone|iPod/.test(s),t=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return e||t}const _r=[{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=u.memo(function({onSend:e,onFocusEditor:t,disabled:n,isMobile:r,inputMode:i}){return f.jsxDEV("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:f.jsxDEV("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:_r.map(o=>f.jsxDEV(me,{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}`,onPointerDown:l=>l.preventDefault(),onClick:()=>{e(o.payload),r&&i==="editor"&&(t==null||t())},disabled:n,children:o.label},o.key,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:107,columnNumber:11},this))},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:102,columnNumber:7},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:98,columnNumber:5},this)});function Cr(){var ct;const{t:s}=Nt(),{deviceId:e,windowId:t,paneId:n}=nt(),r=Jt(),i=u.useRef(null),o=u.useRef(null),l=u.useRef(null),d=u.useRef(null),c=u.useRef(!1),y=u.useRef(!1),C=u.useRef(null),L=Z(a=>a.selectPane),U=Z(a=>e?a.snapshots[e]:void 0),T=Z(a=>{var m;return e?(m=a.deviceErrors)==null?void 0:m[e]:void 0}),S=Z(a=>{var m;return e?((m=a.deviceConnected)==null?void 0:m[e])??!1:!1}),b=st(a=>{var m;return((m=a.settings)==null?void 0:m.siteName)??"tmex"}),h=u.useMemo(()=>rt(n),[n]),R=u.useMemo(()=>e&&h?`${e}:${h}`:null,[e,h]),[D,j]=u.useState(!1),[P,O]=u.useState(""),[K,W]=u.useState(!1),oe=u.useRef(!1),_=!S||!h,[k,G]=u.useState(0),[z,H]=u.useState(0),[B,A]=u.useState(!1),v=ae(a=>a.inputMode),$=ae(a=>a.theme),te=ae(a=>a.editorSendWithEnter),x=ae(a=>a.setEditorSendWithEnter),w=ae(a=>a.addEditorHistory),I=ae(a=>a.setEditorDraft),V=ae(a=>a.removeEditorDraft),Y=ae(a=>R?a.editorDrafts[R]??"":""),q=u.useMemo(()=>Sr(),[]),le=D&&v==="editor"&&q&&K,N=(ct=U==null?void 0:U.session)==null?void 0:ct.windows,pe=$==="light"?It:Bt,{data:ee}=Qt({queryKey:["devices"],queryFn:async()=>{const a=await fetch("/api/devices");if(!a.ok)throw new Error("Failed to fetch devices");return a.json()},throwOnError:!1}),ce=u.useMemo(()=>{if(e)return ee==null?void 0:ee.devices.find(a=>a.id===e)},[e,ee==null?void 0:ee.devices]),se=u.useMemo(()=>{if(!(!t||!N))return N.find(a=>a.id===t)},[t,N]),ne=u.useMemo(()=>{if(!(!h||!se))return se.panes.find(a=>a.id===h)},[h,se]),we=!!N,ye=!!(we&&!!t&&!se||we&&!!t&&!!h&&!!se&&!ne?s("wsError.checkGateway"):null),X=!!(S&&h&&!ye),be=u.useMemo(()=>{if(!se||!ne)return null;const a=(ce==null?void 0:ce.name)??e;return Ft({paneIdx:ne.index,windowIdx:se.index,paneTitle:ne.title,windowName:se.name,deviceName:a})},[ce==null?void 0:ce.name,e,ne,se]),xe=u.useMemo(()=>{if(!N||N.length===0)return null;const a=N.find(g=>g.active),m=a==null?void 0:a.panes.find(g=>g.active);return!a||!m?null:{windowId:a.id,paneId:m.id}},[N]),Ce=u.useCallback((a,m)=>{!e||!h||Z.getState().resizePane(e,h,a,m)},[e,h]),De=u.useCallback((a,m)=>{!e||!h||Z.getState().syncPaneSize(e,h,a,m)},[e,h]),ue=u.useCallback((a,m)=>{const g=d.current,E=(g==null?void 0:g.calculateSizeFromContainer())??(g==null?void 0:g.getSize())??void 0;if(E)return E;if(!a||!m||!N)return;const J=N.find(ie=>ie.id===a),F=J==null?void 0:J.panes.find(ie=>ie.id===m);if(!(!F||F.width<=1||F.height<=1))return{cols:F.width,rows:F.height}},[N]);u.useEffect(()=>{const a=()=>{j(window.innerWidth<768||"ontouchstart"in window)};return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),u.useEffect(()=>{if(!D||!q||y.current)return;y.current=!0;const a=()=>{window.scrollTo(0,1)},m=window.requestAnimationFrame(a),g=window.setTimeout(a,120),E=window.setTimeout(a,420);return()=>{window.cancelAnimationFrame(m),window.clearTimeout(g),window.clearTimeout(E)}},[q,D]),u.useEffect(()=>{v!=="editor"&&W(!1)},[v]),u.useEffect(()=>{var E,J;if(!(D&&q&&v==="editor"&&K)){G(0);return}let a=null;const m=()=>{const F=window.visualViewport,ie=(F==null?void 0:F.height)??window.innerHeight,_e=(F==null?void 0:F.offsetTop)??0,Wt=Math.max(0,Math.round(window.innerHeight-ie-_e));G(Wt)},g=()=>{a===null&&(a=window.requestAnimationFrame(()=>{a=null,m()}))};return m(),(E=window.visualViewport)==null||E.addEventListener("resize",g),(J=window.visualViewport)==null||J.addEventListener("scroll",g),window.addEventListener("resize",g),()=>{var F,ie;(F=window.visualViewport)==null||F.removeEventListener("resize",g),(ie=window.visualViewport)==null||ie.removeEventListener("scroll",g),window.removeEventListener("resize",g),a!==null&&window.cancelAnimationFrame(a)}},[v,K,q,D]),u.useEffect(()=>{if(!le){H(0);return}const a=o.current;if(!a)return;const m=()=>{H(Math.ceil(a.getBoundingClientRect().height))};m();const g=new ResizeObserver(m);return g.observe(a),()=>g.disconnect()},[le]),u.useEffect(()=>{e&&(c.current=!1,Be.current=null,Se.current=null,C.current=null,re.current=[])},[e]),u.useEffect(()=>{S||(c.current=!1)},[S]),u.useEffect(()=>{if(!e||!S||!t||!N)return;if(N.length===0){r("/devices",{replace:!0});return}const a=N.find(g=>g.id===t);if(!a)return;if(!h){const g=a.panes.find(E=>E.active)??a.panes[0];g&&r(`/devices/${e}/windows/${t}/panes/${Te(g.id)}`,{replace:!0});return}if(!a.panes.find(g=>g.id===h)){const g=a.panes.find(E=>E.active)??a.panes[0];g&&r(`/devices/${e}/windows/${t}/panes/${Te(g.id)}`,{replace:!0});return}},[e,S,N,t,h,r]),u.useEffect(()=>{if(!e||!S||!N||N.length===0||t&&h||c.current)return;const a=N.find(g=>g.active)??N[0],m=a.panes.find(g=>g.active)??a.panes[0];m&&(c.current=!0,r(`/devices/${e}/windows/${a.id}/panes/${Te(m.id)}`,{replace:!0}))},[S,e,r,h,t,N]),u.useEffect(()=>{if(!e||!t||!h||_||!S)return;const a=Z.getState().selectedPanes[e];if(a&&a.windowId===t&&a.paneId===h)return;const m=ue(t,h);fe(t,h),L(e,t,h,m)},[S,e,ue,_,h,L,t]),u.useEffect(()=>{if(!e||!S||!t||!h)return;const a={windowId:t,paneId:h};yr({routeTarget:a,snapshotActive:xe,pendingUserSelection:C.current})&&(C.current={windowId:a.windowId,paneId:a.paneId,at:Date.now()})},[S,e,h,xe,t]);const re=u.useRef([]),fe=u.useCallback((a,m)=>{const g=Date.now(),E=[...re.current.filter(J=>g-J.at<2e3),{windowId:a,paneId:m,at:g}];re.current=E.slice(-8)},[]),Q=Z(a=>e?a.activePaneFromEvent[e]:void 0),Be=u.useRef(null);u.useEffect(()=>{if(!e||!S||!t||!h||!Q)return;const a=Date.now(),m=Re(C.current,a);if(C.current=m,gr({now:a,pendingUserSelection:m,activePaneFromEvent:Q,currentRoute:{windowId:t,paneId:h},recentSelectRequests:re.current,lastHandledActive:Be.current}))return;Be.current={...Q},m&&m.windowId===Q.windowId&&m.paneId===Q.paneId&&(C.current=null);const g=ue(Q.windowId,Q.paneId);fe(Q.windowId,Q.paneId),L(e,Q.windowId,Q.paneId,g),r(`/devices/${e}/windows/${Q.windowId}/panes/${Te(Q.paneId)}`,{replace:!0})},[e,S,t,h,Q,fe,ue,L,r]);const Se=u.useRef(null);u.useEffect(()=>{if(!e||!S||!N||N.length===0)return;const a=re.current,m=N.find(_e=>_e.active);if(!m)return;const g=m.panes.find(_e=>_e.active);if(!g)return;const E={windowId:m.id,paneId:g.id},J=Date.now(),F=Re(C.current,J);if(C.current=F,wr({now:J,pendingUserSelection:F,snapshotActive:E,recentSelectRequests:a})||Se.current&&Se.current.windowId===E.windowId&&Se.current.paneId===E.paneId||(Se.current={...E},F&&F.windowId===E.windowId&&F.paneId===E.paneId&&(C.current=null),t===E.windowId&&h===E.paneId))return;const ie=ue(E.windowId,E.paneId);fe(E.windowId,E.paneId),L(e,E.windowId,E.paneId,ie),r(`/devices/${e}/windows/${E.windowId}/panes/${Te(E.paneId)}`,{replace:!0})},[e,S,N,t,h,fe,ue,L,r]),u.useEffect(()=>{if(!X||!ne||_)return;const a=d.current,m=a==null?void 0:a.getTerminal();if(!m)return;const g=Math.max(2,Math.floor(ne.width||0)),E=Math.max(2,Math.floor(ne.height||0));if(!g||!E)return;const J=Date.now(),F={cols:g,rows:E},ie=(a==null?void 0:a.getPendingLocalSize())??null;ir({now:J,remoteSize:F,pendingLocalSize:ie})&&(m.cols===g&&m.rows===E||m.resize(g,E))},[X,_,ne]),u.useEffect(()=>{const a=window.requestAnimationFrame(()=>{var g;(g=d.current)==null||g.scrollToBottom()}),m=window.setTimeout(()=>{var g;(g=d.current)==null||g.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(a),window.clearTimeout(m)}},[v]),u.useEffect(()=>{T!=null&&T.message&&He.error(T.message)},[T==null?void 0:T.message]),u.useEffect(()=>(document.title=xr(be),()=>{document.title=b}),[b,be]),u.useEffect(()=>{const a=()=>{var m;(m=d.current)==null||m.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",a),()=>{window.removeEventListener("tmex:jump-to-latest",a)}},[]),u.useEffect(()=>{const a=m=>{const{deviceId:g,windowId:E,paneId:J}=m.detail;g===e&&(C.current={windowId:E,paneId:J,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",a),()=>{window.removeEventListener("tmex:user-initiated-selection",a)}},[e]),u.useEffect(()=>{O(Y)},[Y]);const at=u.useCallback(a=>{if(!e||!h||!X)return;Z.getState().sendInput(e,h,a,!1)},[X,e,h]),Gt=u.useCallback(()=>{if(!X){He.error(s("wsError.checkGateway"));return}if(!e||!h||!P.trim())return;A(!0),window.setTimeout(()=>A(!1),150);const a=te?`${P}\r`:P;Z.getState().sendInput(e,h,a,!1),w(P),R&&V(R),O("")},[w,X,e,R,te,P,V,h,s]),zt=u.useCallback(()=>{if(!X){He.error(s("wsError.checkGateway"));return}if(!e||!h||!P.trim())return;A(!0),window.setTimeout(()=>A(!1),150);const a=P.split(/\r?\n/),m=Z.getState();for(const g of a)g.trim()&&m.sendInput(e,h,`${g}\r`,!1);w(P),R&&V(R),O("")},[w,X,e,R,P,V,h,s]),Yt=u.useCallback(a=>{if(W(!0),!(D&&q))return;const m=a.currentTarget;window.requestAnimationFrame(()=>{m.scrollIntoView({block:"nearest",inline:"nearest"})}),window.setTimeout(()=>{window.scrollTo(0,1)},60)},[q,D]),Kt=u.useCallback(()=>{W(!1)},[]),$t=u.useCallback(()=>{var a;(a=l.current)==null||a.focus({preventScroll:!0})},[]);if(!e)return f.jsxDEV("div",{className:"flex h-full items-center justify-center p-4",children:f.jsxDEV("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:s("device.noDevices")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:917,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:916,columnNumber:7},this);const jt=!S&&!T;return f.jsxDEV("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[f.jsxDEV("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${D&&v==="editor"&&!le?"pb-1":""}`,style:{paddingBottom:le?`${z+60}px`:void 0},children:[f.jsxDEV("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:pe.background},children:S&&h?f.jsxDEV("div",{ref:i,className:"flex-1 h-full min-h-0 w-full",children:f.jsxDEV(Ht,{ref:d,deviceId:e,paneId:h,theme:$,inputMode:v,deviceConnected:S,isSelectionInvalid:ye,onResize:Ce,onSync:De},`${e}:${h}`,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:942,columnNumber:15},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:941,columnNumber:13},this):f.jsxDEV("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:f.jsxDEV("div",{className:"max-w-sm space-y-4",children:S?t?f.jsxDEV(f.Fragment,{children:[f.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsxDEV(Ve,{className:"h-6 w-6 text-muted-foreground animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:979,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:978,columnNumber:21},this),f.jsxDEV("h3",{className:"text-lg font-medium",children:s("terminal.connecting")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:981,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:977,columnNumber:19},this):f.jsxDEV(f.Fragment,{children:[f.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsxDEV("span",{className:"text-2xl text-muted-foreground",children:"📋"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:969,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:968,columnNumber:21},this),f.jsxDEV("h3",{className:"text-lg font-medium",children:s("window.noWindowSelected")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:971,columnNumber:21},this),f.jsxDEV("p",{className:"text-sm text-muted-foreground",children:s("window.selectWindowToStart")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:972,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:967,columnNumber:19},this):f.jsxDEV(f.Fragment,{children:[f.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsxDEV("span",{className:"text-2xl text-muted-foreground",children:"🔌"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:961,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:960,columnNumber:21},this),f.jsxDEV("h3",{className:"text-lg font-medium",children:s("device.disconnected")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:963,columnNumber:21},this),f.jsxDEV("p",{className:"text-sm text-muted-foreground",children:s("device.connectToStart")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:964,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:959,columnNumber:19},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:957,columnNumber:15},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:956,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:936,columnNumber:9},this),jt&&f.jsxDEV("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:f.jsxDEV("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[f.jsxDEV("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:995,columnNumber:15},this),f.jsxDEV("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:s("terminal.connecting")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:996,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:994,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:990,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:928,columnNumber:7},this),v==="direct"&&f.jsxDEV("div",{className:"",children:f.jsxDEV(Dt,{onSend:at,disabled:!X,isMobile:D,inputMode:v},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1007,columnNumber:11},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1006,columnNumber:9},this),v==="editor"&&f.jsxDEV("div",{ref:o,className:`editor-mode-input bg-card/85 backdrop-blur-sm ${le?"fixed left-0 right-0 z-50":""}`,style:le?{bottom:`${k}px`}:void 0,children:[D&&f.jsxDEV(Dt,{onSend:at,onFocusEditor:$t,disabled:!X,isMobile:D,inputMode:v},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1026,columnNumber:13},this),f.jsxDEV("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:P,onChange:a=>{const m=a.target.value;if(O(m),!!R){if(m){I(R,m);return}V(R)}},placeholder:s("terminal.inputPlaceholder"),onFocus:Yt,onBlur:Kt,onCompositionStart:()=>{oe.current=!0},onCompositionEnd:()=>{oe.current=!1}},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1034,columnNumber:11},this),f.jsxDEV("div",{className:"actions mt-2",children:f.jsxDEV("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[f.jsxDEV("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:[f.jsxDEV(as,{size:"sm",checked:te,onCheckedChange:a=>x(!!a)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1070,columnNumber:17},this),f.jsxDEV("span",{children:s("terminal.editorSendWithEnter")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1075,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1066,columnNumber:15},this),f.jsxDEV(me,{variant:"outline",size:"sm","data-testid":"editor-clear",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;O(""),R&&V(R),D&&v==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},title:s("terminal.clear"),children:[f.jsxDEV(Zt,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1093,columnNumber:17},this),s("terminal.clear")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1077,columnNumber:15},this),f.jsxDEV(me,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;zt(),D&&v==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},disabled:!X||B,children:[B?f.jsxDEV(Ve,{className:"h-4 w-4 animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1110,columnNumber:19},this):f.jsxDEV(dt,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1112,columnNumber:19},this),s("terminal.editorSendLineByLine")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1096,columnNumber:15},this),f.jsxDEV(me,{variant:"default",size:"sm","data-testid":"editor-send",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;Gt(),D&&v==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},disabled:!X||B,children:[B?f.jsxDEV(Ve,{className:"h-4 w-4 animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1130,columnNumber:19},this):f.jsxDEV(dt,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1132,columnNumber:19},this),s("common.send")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1116,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1062,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1061,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1017,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:927,columnNumber:5},this)}function Dr(){const{deviceId:s,windowId:e,paneId:t}=nt(),n=t?rt(t):void 0,r=Z(y=>y.snapshots),i=st(y=>{var C;return((C=y.settings)==null?void 0:C.siteName)??"tmex"}),o=s?r[s]:void 0,l=u.useMemo(()=>{var y;if(!(!e||!((y=o==null?void 0:o.session)!=null&&y.windows)))return o.session.windows.find(C=>C.id===e)},[e,o]),d=u.useMemo(()=>{if(!(!n||!l))return l.panes.find(y=>y.id===n)},[n,l]),c=u.useMemo(()=>l&&d?Ft({paneIdx:d.index,windowIdx:l.index,paneTitle:d.title,windowName:l.name,deviceName:i}):s??"",[l,d,i,s]);return f.jsxDEV(f.Fragment,{children:c},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1175,columnNumber:10},this)}function Nr(){const{t:s}=Nt(),{deviceId:e,paneId:t}=nt(),n=t?rt(t):void 0,r=ae(T=>T.inputMode),i=ae(T=>T.setInputMode),o=Z(T=>{var S;return e?((S=T.deviceConnected)==null?void 0:S[e])??!1:!1}),[l,d]=u.useState(!1),c=!!(n&&o),y=()=>{i(r==="direct"?"editor":"direct")},C=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},L=()=>{d(!0)},U=()=>{window.location.reload()};return f.jsxDEV(f.Fragment,{children:[f.jsxDEV(me,{variant:"ghost",size:"icon-sm",onClick:L,"aria-label":s("nav.refreshPage"),title:s("nav.refreshPage"),children:f.jsxDEV(ms,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1219,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1212,columnNumber:7},this),f.jsxDEV(me,{variant:"ghost",size:"icon-sm",onClick:y,disabled:!c,"data-testid":"terminal-input-mode-toggle","aria-label":s(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:s(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:r==="direct"?f.jsxDEV(hs,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1231,columnNumber:11},this):f.jsxDEV(gs,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1233,columnNumber:11},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1221,columnNumber:7},this),f.jsxDEV(me,{variant:"ghost",size:"icon-sm",onClick:C,disabled:!c,"aria-label":s("nav.jumpToLatest"),title:s("nav.jumpToLatest"),children:f.jsxDEV(us,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1244,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1236,columnNumber:7},this),f.jsxDEV(es,{open:l,onOpenChange:d,children:f.jsxDEV(ts,{children:[f.jsxDEV(ss,{children:[f.jsxDEV(ns,{children:s("nav.refreshPage")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1250,columnNumber:13},this),f.jsxDEV(rs,{children:s("nav.refreshPageConfirm")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1251,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1249,columnNumber:11},this),f.jsxDEV(is,{children:[f.jsxDEV(os,{onClick:()=>d(!1),children:s("common.cancel")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1254,columnNumber:13},this),f.jsxDEV(ls,{onClick:U,children:s("common.confirm")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1257,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1253,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1248,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1247,columnNumber:7},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1211,columnNumber:5},this)}export{Nr as PageActions,Dr as PageTitle,Cr as default};
|
|
26
|
+
//# sourceMappingURL=DevicePage-BTbDSWYN.js.map
|