tmex-cli 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/runtime/server.js +718 -186
  2. package/package.json +1 -1
  3. package/resources/fe-dist/assets/DevicePage-n4JoyDed.js +26 -0
  4. package/resources/fe-dist/assets/DevicePage-n4JoyDed.js.map +1 -0
  5. package/resources/fe-dist/assets/DevicesPage-BwLKaiUR.js +17 -0
  6. package/resources/fe-dist/assets/{DevicesPage-CtNzaW_c.js.map → DevicesPage-BwLKaiUR.js.map} +1 -1
  7. package/resources/fe-dist/assets/SettingsPage-hS99lHcp.js +17 -0
  8. package/resources/fe-dist/assets/SettingsPage-hS99lHcp.js.map +1 -0
  9. package/resources/fe-dist/assets/index-CJaX5rlK.css +1 -4527
  10. package/resources/fe-dist/assets/index-CJyFlAt8.js +449 -0
  11. package/resources/fe-dist/assets/index-CJyFlAt8.js.map +1 -0
  12. package/resources/fe-dist/assets/select-DGBwxGiK.js +17 -0
  13. package/resources/fe-dist/assets/{select-BNsiC9zT.js.map → select-DGBwxGiK.js.map} +1 -1
  14. package/resources/fe-dist/assets/switch-CWUBjs7N.js +12 -0
  15. package/resources/fe-dist/assets/{switch-CIU4AisU.js.map → switch-CWUBjs7N.js.map} +1 -1
  16. package/resources/fe-dist/assets/useValueChanged-DwJ_SDCu.js +7 -0
  17. package/resources/fe-dist/assets/{useValueChanged-V23H0VpC.js.map → useValueChanged-DwJ_SDCu.js.map} +1 -1
  18. package/resources/fe-dist/index.html +1 -1
  19. package/resources/gateway-drizzle/0002_broad_vengeance.sql +3 -0
  20. package/resources/gateway-drizzle/meta/0000_snapshot.json +17 -6
  21. package/resources/gateway-drizzle/meta/0001_snapshot.json +17 -6
  22. package/resources/gateway-drizzle/meta/0002_snapshot.json +535 -0
  23. package/resources/gateway-drizzle/meta/_journal.json +8 -1
  24. package/resources/fe-dist/assets/DevicePage-iSkEDEpS.js +0 -4570
  25. package/resources/fe-dist/assets/DevicePage-iSkEDEpS.js.map +0 -1
  26. package/resources/fe-dist/assets/DevicesPage-CtNzaW_c.js +0 -2143
  27. package/resources/fe-dist/assets/SettingsPage-D25_d6j9.js +0 -1144
  28. package/resources/fe-dist/assets/SettingsPage-D25_d6j9.js.map +0 -1
  29. package/resources/fe-dist/assets/index-dsVN7rgz.js +0 -200
  30. package/resources/fe-dist/assets/index-dsVN7rgz.js.map +0 -1
  31. package/resources/fe-dist/assets/select-BNsiC9zT.js +0 -2805
  32. package/resources/fe-dist/assets/switch-CIU4AisU.js +0 -234
  33. package/resources/fe-dist/assets/useValueChanged-V23H0VpC.js +0 -351
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmex-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tmex": "./bin/tmex.js",
@@ -0,0 +1,26 @@
1
+ var Xt=Object.defineProperty;var Jt=(s,e,t)=>e in s?Xt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var g=(s,e,t)=>Jt(s,typeof e!="symbol"?e+"":e,t);import{c as He,r as u,bw as j,bx as dt,j as m,b as nt,u as Nt,by as rt,bz as Qt,bA as it,d as de,e as Zt,bB as we,f as Ke,B as ge}from"./index-CJyFlAt8.js";import{T as es,A as ts,a as ss,b as ns,c as rs,d as is,e as os,f as ls,g as as}from"./useValueChanged-DwJ_SDCu.js";import{L as We,S as cs,a as ht}from"./switch-CWUBjs7N.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 us=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],ds=He("arrow-down-to-line",us);/**
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 hs=[["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"}]],fs=He("keyboard",hs);/**
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 ms=[["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"}]],ps=He("refresh-cw",ms);/**
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 gs=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],ws=He("smartphone",gs);function ys(s){return`rgb(${s.r} ${s.g} ${s.b})`}function je(s){const e=s.getContext("2d");if(!e)throw new Error("2d canvas context unavailable");return e}class bs{constructor(e){g(this,"kind","canvas");g(this,"mainCanvas");g(this,"selectionCanvas");g(this,"cursorCanvas");g(this,"mainContext");g(this,"selectionContext");g(this,"cursorContext");g(this,"theme");g(this,"fontFamily");g(this,"fontSize");g(this,"cellDimensions",{width:9,height:17});g(this,"cols",0);g(this,"rows",0);g(this,"lastCursor",null);g(this,"frameCount",0);g(this,"lastDrawnRows",[]);g(this,"colorCache",new Map);g(this,"fontCache",new Map);g(this,"cursorBlinkVisible",!0);g(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=je(this.mainCanvas),this.selectionContext=je(this.selectionCanvas),this.cursorContext=je(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=ys(e);return this.colorCache.set(t,r),r}}const Ss=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},ot={Backquote:"`",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Comma:",",Equal:"=",Minus:"-",Period:".",Quote:"'",Semicolon:";",Slash:"/",Space:" ",IntlBackslash:"\\",IntlYen:"¥",IntlRo:"\\"};for(let s=0;s<=9;s+=1)ot[`Digit${s}`]=String(s);for(let s=0;s<26;s+=1){const e=String.fromCharCode(65+s),t=String.fromCharCode(97+s);ot[`Key${e}`]=t}function ft(s){return xs[s]??Ss}function _s(s){const e=ot[s];return e?e.codePointAt(0)??null:null}const ye=0,Es=-2,Ts=1,vs=2,Rs=3,Cs=10,Ds=11,Ns=12,Ms=13,ks=14,As=15,Ls=16,Ps=17,Os=1,Is=2,Us=1,Bs=2,Hs=3,Vs=4,Fs=5,Gs=6,zs=1,Ys=2,$s=3,Ks=4;function lt(s){if(s.disposed||s.renderStateHandle===0)throw new Error("render state resources already disposed")}function Ws(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 qs(s){switch(s){case 1:return"wide";case 2:return"spacer-tail";case 3:return"spacer-head";default:return"narrow"}}function Te(s,e){return{r:s.view().getUint8(e),g:s.view().getUint8(e+1),b:s.view().getUint8(e+2)}}function mt(s,e){const t=s.bindings.allocStruct("GhosttyColorRgb");try{const n=e(t.ptr);if(n===Es)return null;if(n!==ye)throw new Error(`ghostty optional color read failed with result ${n}`);return Te(s.bindings,t.ptr)}finally{t.free()}}function fe(s,e){const t=s.bindings.allocU8();try{const n=e(t);if(typeof n=="number"&&n!==ye)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!==ye)throw new Error(`ghostty u16 read failed with result ${n}`);return s.bindings.view().getUint16(t,!0)}finally{s.bindings.freeBytes(t,2)}}function Xs(s,e){const t=s.bindings.allocBytes(4);try{const n=e(t);if(typeof n=="number"&&n!==ye)throw new Error(`ghostty u32 read failed with result ${n}`);return s.bindings.view().getUint32(t,!0)}finally{s.bindings.freeBytes(t,4)}}function et(s,e){const t=s.bindings.allocBytes(4);try{const n=e(t);if(typeof n=="number"&&n!==ye)throw new Error(`ghostty enum read failed with result ${n}`);return s.bindings.view().getInt32(t,!0)}finally{s.bindings.freeBytes(t,4)}}function pt(s,e){const t=s.bindings.allocBytes(8);try{const n=e(t);if(typeof n=="number"&&n!==ye)throw new Error(`ghostty u64 read failed with result ${n}`);return s.bindings.readU64(t)}finally{s.bindings.freeBytes(t,8)}}function Js(s){const e=s.bindings.allocStruct("GhosttyStyle");try{s.bindings.setField(e.view,"GhosttyStyle","size",s.bindings.typeSize("GhosttyStyle")),s.bindings.getRenderStateRowCellValue(s.rowCellsHandle,Bs,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 Qs(s){const e=Xs(s,n=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Hs,n));if(e===0)return[];const t=s.bindings.allocBytes(e*4);try{s.bindings.getRenderStateRowCellValue(s.rowCellsHandle,Vs,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 Zs(s){if(s.length===0)return"";try{return String.fromCodePoint(...s)}catch{return""}}function en(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 tn(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(Te(s.bindings,l))}const r=e.view.getUint8(s.bindings.field("GhosttyRenderStateColors","cursor_has_value").offset)!==0,i=fe(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,ks,o));return{cols:Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ts,o)),rows:Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,vs,o)),dirty:Ws(et(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Rs,o))),colors:{background:Te(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","background").offset),foreground:Te(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","foreground").offset),cursor:r?Te(s.bindings,e.ptr+s.bindings.field("GhosttyRenderStateColors","cursor").offset):null,palette:n},cursor:{style:js(et(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Cs,o))),visible:fe(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ds,o)),blinking:fe(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ns,o)),passwordInput:fe(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ms,o)),x:i?Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,As,o)):null,y:i?Ne(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ls,o)):null,wideTail:i?fe(s,o=>s.bindings.getRenderStateValueResult(s.renderStateHandle,Ps,o)):!1}}}finally{e.free()}}function sn(s,e){const t=pt(s,i=>s.bindings.getRenderStateRowValueResult(s.rowIteratorHandle,Is,i));s.bindings.bindRenderStateRowCells(s.rowIteratorHandle,s.rowCellsHandle);const n=[];let r=0;for(;s.bindings.nextRenderStateRowCell(s.rowCellsHandle);){const i=pt(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Us,c)),o=Qs(s),l=qs(et(s,c=>s.bindings.getRawCellValueResult(i,$s,c))),d={x:r,text:Zs(o),codepoints:o,widthKind:l,hasText:fe(s,c=>s.bindings.getRawCellValueResult(i,Ks,c)),style:Js(s),fgColor:mt(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Gs,c)),bgColor:mt(s,c=>s.bindings.getRenderStateRowCellValueResult(s.rowCellsHandle,Fs,c))};n.push(d),r+=1}return{y:e,dirty:fe(s,i=>s.bindings.getRenderStateRowValueResult(s.rowIteratorHandle,Os,i)),wrap:fe(s,i=>s.bindings.getRawRowValueResult(t,zs,i)),wrapContinuation:fe(s,i=>s.bindings.getRawRowValueResult(t,Ys,i)),text:en(n),cells:n}}function gt(s){return{bindings:s,renderStateHandle:s.createRenderState(),rowIteratorHandle:s.createRenderStateRowIterator(),rowCellsHandle:s.createRenderStateRowCells(),snapshotVersion:0,disposed:!1,cachedMeta:null}}function wt(s,e){lt(s),s.bindings.updateRenderState(s.renderStateHandle,e),s.bindings.bindRenderStateRowIterator(s.renderStateHandle,s.rowIteratorHandle),s.snapshotVersion+=1,s.cachedMeta=null}function tt(s){return lt(s),s.cachedMeta||(s.cachedMeta=tn(s)),s.cachedMeta}function*nn(s){lt(s);const e=tt(s);s.bindings.bindRenderStateRowIterator(s.renderStateHandle,s.rowIteratorHandle);let t=0;for(;t<e.rows&&s.bindings.nextRenderStateRowIterator(s.rowIteratorHandle);)yield sn(s,t),t+=1}function qe(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 at(s,e){return Math.max(0,Math.min(Math.max(s.length-1,0),Math.floor(e)))}function rn(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 on(s,e,t){if(!t)return{start:{line:s,col:0},end:{line:s,col:0}};const n=at(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 on(s.line,s.col,n);case"line":return Mt(s.line,n);default:{const r=at(n,s.col);return{start:{line:s.line,col:r},end:{line:s.line,col:r}}}}}function At(){return{anchor:null,focus:null,mode:"character"}}function ln(s){return!!(s.anchor&&s.focus)}function an(){return At()}function cn(s,e,t){const n=kt(e,e.mode,t);return{anchor:n.start,focus:n.end,mode:e.mode}}function yt(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:at(t(e.line),e.col)}}:s}function Lt(s){return!s.anchor||!s.focus?null:rn(s.anchor,s.focus)}function un(s,e){const t=Lt(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 dn(s,e,t,n){const r=Lt(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 hn(s){return(s.metaKey||s.ctrlKey)&&!s.altKey}function fn(s){return hn(s)&&s.key.toLowerCase()==="c"}async function mn(s){var e;s&&typeof navigator<"u"&&(e=navigator.clipboard)!=null&&e.writeText&&await navigator.clipboard.writeText(s)}function pn(s,e){return!e||!s.clipboardData?!1:(s.clipboardData.setData("text/plain",e),s.preventDefault(),!0)}const gn="/assets/ghostty-vt-BKQMf-5X.wasm",Pe=0,bt=-3,wn=11,yn=12,bn=13,Sn=14,xn=1,_n=2,En=9,Tn=1,vn=0,Rn=1,Cn=2,Dn=0,Nn=1,Mn=2,kn=4,An=2004,Ln=9,Pn=1e3,On=1002,In=1003,Un=1005,St=1006,Bn=1015,xt=1016;let Xe=null;function L(s,e){if(s!==Pe)throw new Error(`${e} failed with result ${s}`)}function Pt(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 Hn(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(Pt)],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 Vn(s){let e=0;return s&1&&(e+=4),s&4&&(e+=8),s&2&&(e+=16),e}function Je(s){return s<0||s>223?null:String.fromCharCode(s+32)}function Fn(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 Ot(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 Gn{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 zn{constructor(e,t){g(this,"exports");g(this,"layout");g(this,"decoder",new TextDecoder);g(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 Gn(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 L(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){L(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",Cn),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",vn),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",Rn),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=Hn(t),l=this.allocBytes(o.length*3),d=(y,D)=>{const[k,I,E]=Pt(D);this.setField(y.view,"GhosttyColorRgb","r",k),this.setField(y.view,"GhosttyColorRgb","g",I),this.setField(y.view,"GhosttyColorRgb","b",E)};d(n,t.foreground),d(r,t.background),d(i,t.cursor);const c=this.bytes(l,o.length*3);o.forEach(([y,D,k],I)=>{const E=I*3;c[E]=y,c[E+1]=D,c[E+2]=k});try{L(this.exports.ghostty_terminal_set(e,wn,n.ptr),"ghostty_terminal_set(foreground)"),L(this.exports.ghostty_terminal_set(e,yn,r.ptr),"ghostty_terminal_set(background)"),L(this.exports.ghostty_terminal_set(e,bn,i.ptr),"ghostty_terminal_set(cursor)"),L(this.exports.ghostty_terminal_set(e,Sn,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 L(this.exports.ghostty_terminal_get(e,xn,t),"ghostty_terminal_get(cols)"),L(this.exports.ghostty_terminal_get(e,_n,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 L(this.exports.ghostty_terminal_get(e,En,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 L(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){L(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),L(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)!==Pe?(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{L(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 L(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){L(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){L(this.getRenderStateValueResult(e,t,n),"ghostty_render_state_get")}setRenderStateValue(e,t,n){L(this.exports.ghostty_render_state_set(e,t,n),"ghostty_render_state_set")}getRenderStateColors(e,t){L(this.exports.ghostty_render_state_colors_get(e,t),"ghostty_render_state_colors_get")}createRenderStateRowIterator(){const e=this.allocOpaque();try{return L(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){L(this.getRenderStateRowValueResult(e,t,n),"ghostty_render_state_row_get")}setRenderStateRowValue(e,t,n){L(this.exports.ghostty_render_state_row_set(e,t,n),"ghostty_render_state_row_set")}createRenderStateRowCells(){const e=this.allocOpaque();try{return L(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){L(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){L(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){L(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){L(this.getRawCellValueResult(e,t,n),"ghostty_cell_get")}createKeyEncoder(){const e=this.allocOpaque();try{return L(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{L(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,kn,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,In),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=Fn(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),D=Math.round(n.x+1),k=Math.round(n.y+1);let I=n.action==="release"&&!this.isTerminalModeEnabled(t,St)&&!this.isTerminalModeEnabled(t,xt)?3:d;if(n.action==="motion"&&(I+=32),I+=Vn(n.mods),this.isTerminalModeEnabled(t,xt)){const E=n.action==="release"?"m":"M";return`\x1B[<${I};${D};${k}${E}`}if(this.isTerminalModeEnabled(t,St)){const E=n.action==="release"?"m":"M";return`\x1B[<${I};${c};${y}${E}`}if(this.isTerminalModeEnabled(t,Bn))return`\x1B[${I};${c};${y}M`;if(this.isTerminalModeEnabled(t,Un)||o||i||r||l){const E=Je(I),x=Je(c),w=Je(y);return!E||!x||!w?null:`\x1B[M${E}${x}${w}`}return null}encodeKeyEvent(e,t,n){if(n.keyCode<=0)return null;const r=this.allocOpaque();let i=0,o=null;try{return L(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"?Dn:n.action==="repeat"?Mn:Nn),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!==bt&&r!==Pe&&L(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{L(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,An),o=this.exports.ghostty_paste_encode(n.ptr,n.len,i?1:0,0,0,r);o!==bt&&o!==Pe&&L(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 L(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 Yn(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 $n(){return Xe||(Xe=(async()=>{const s=await Yn(gn),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 zn(t,o)})()),Xe}const _t=80,ve=24,Qe=9,Me=17,Kn=48,It="ghostty-official",Oe=9,Ie=1e3,Ue=1002,Be=1003,Ze=1007,ke=1047,Ae=1049,Wn=[Oe,Ie,Ue,Be],Et=1,Tt=3,vt=2,jn=4,qn=5;class Xn{constructor(e){this.content=e}translateToString(e){return e?this.content.replace(/\s+$/u,""):this.content}}class Jn{constructor(){g(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 Xn(n):null}});g(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 Qn(s){return!(s.key.length===1&&!s.ctrlKey&&!s.altKey&&!s.metaKey)}function Zn(s,e){const t=s.slice(0,e).map(n=>n.text);for(;t.length<e;)t.push("");return t}function Le(s){return Ot({shiftKey:!!s.shiftKey,ctrlKey:!!s.ctrlKey,altKey:!!s.altKey,metaKey:!!s.metaKey,getModifierState:()=>!1})}class er{constructor(){g(this,"terminal",null)}activate(e){this.terminal=e instanceof Ve?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 Ve{constructor(e,t,n,r,i,o){g(this,"buffer",new Jn);g(this,"_core",{_renderService:{dimensions:{css:{cell:{width:Qe,height:Me}}}}});g(this,"options");g(this,"element",null);g(this,"textarea",null);g(this,"cols",_t);g(this,"rows",ve);g(this,"bindings");g(this,"terminalHandle");g(this,"keyEncoderHandle");g(this,"mouseEncoderHandle");g(this,"renderState");g(this,"dataListeners",new Set);g(this,"addons",new Set);g(this,"screenElement",null);g(this,"renderer",null);g(this,"renderRaf",null);g(this,"disposed",!1);g(this,"disableStdin");g(this,"customKeyEventHandler",()=>!0);g(this,"imeIsComposing",!1);g(this,"lastCompositionCommit",null);g(this,"selectionState",At());g(this,"lineCache",new Map);g(this,"lastViewportOffset",0);g(this,"lastViewportRows",ve);g(this,"lastRenderedRows",[]);g(this,"pointerDrag",{active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null});g(this,"autoScrollTimer",null);g(this,"domEventDisposers",[]);g(this,"copyShortcutSuppressed",!1);g(this,"scrollbarThumb",null);g(this,"scrollbarFadeTimer",null);g(this,"pressedMouseButtons",new Set);g(this,"wheelPixelDelta",0);g(this,"mouseDragActive",!1);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 $n(),n=t.createTerminal(_t,ve,e.scrollback);let r=0,i=0,o=null;try{return t.setTerminalTheme(n,e.theme),r=t.createKeyEncoder(),i=t.createMouseEncoder(),o=gt(t),new Ve(t,n,r,i,o,e)}catch(l){throw o&&qe(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 bs({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){if(this.disposed)return;const t=this.isAltScreenActive();this.bindings.writeVt(this.terminalHandle,e);const n=this.isAltScreenActive();t&&!n&&this.clearMouseTrackingModes(),this.scheduleRender()}clearMouseTrackingModes(){if(!this.disposed){for(const e of Wn)this.bindings.setTerminalMode(this.terminalHandle,e,!1);this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.pressedMouseButtons.clear(),this.mouseDragActive=!1}}isAltScreenActive(){return this.isModeEnabled(ke)||this.isModeEnabled(Ae)}reset(){this.disposed||(this.lineCache.clear(),this.clearSelectionState(!1),this.bindings.resetTerminal(this.terminalHandle),this.scheduleRender())}refresh(){this.disposed||this.render()}resize(e,t){if(this.disposed)return;const 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(Oe),mouseNormal:this.isModeEnabled(Ie),mouseButton:this.isModeEnabled(Ue),mouseAny:this.isModeEnabled(Be),mouseUtf8:this.isModeEnabled(1005),mouseSgr:this.isModeEnabled(1006),mouseSgrPixels:this.isModeEnabled(1016),mouseUrxvt:this.isModeEnabled(1015),altScroll:this.isModeEnabled(Ze),altScreen1047:this.isModeEnabled(ke),altScreen1049:this.isModeEnabled(Ae)}}restoreModeSnapshot(e){this.bindings.setTerminalMode(this.terminalHandle,Oe,e.mouseX10),this.bindings.setTerminalMode(this.terminalHandle,Ie,e.mouseNormal),this.bindings.setTerminalMode(this.terminalHandle,Ue,e.mouseButton),this.bindings.setTerminalMode(this.terminalHandle,Be,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,Ze,e.altScroll),this.bindings.setTerminalMode(this.terminalHandle,ke,e.altScreen1047),this.bindings.setTerminalMode(this.terminalHandle,Ae,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?jn:qn;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:Le(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,qe(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.mouseDragActive=!0,this.emitMouseInput({action:"press",button:o,clientX:i.clientX,clientY:i.clientY,mods:Le(i),anyButtonPressed:!0}),i.preventDefault();return}i.button===0&&(this.mouseDragActive=!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.mouseDragActive){if(this.getInputRoutingState().mouseReporting){this.emitMouseInput({action:"motion",button:this.mouseButtonFromButtons(l.buttons),clientX:l.clientX,clientY:l.clientY,mods:Le(l),anyButtonPressed:this.pressedMouseButtons.size>0||l.buttons>0});return}this.updatePointerSelection(l)}},o=l=>{if(this.mouseDragActive){if(this.mouseDragActive=!1,this.getInputRoutingState().mouseReporting){const d=this.mouseButtonFromEvent(l);d!==null&&this.pressedMouseButtons.delete(d),this.emitMouseInput({action:"release",button:d,clientX:l.clientX,clientY:l.clientY,mods:Le(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&&fn(i)){this.copyShortcutSuppressed=!0,i.preventDefault(),mn(o).catch(()=>{}),this.clearTextarea();return}if(!this.customKeyEventHandler(i)||this.disableStdin||this.imeIsComposing||i.keyCode===229||!Qn(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&&pn(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=ft(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:Ot(e),composing:e.isComposing,utf8:r,unshiftedCodepoint:_s(e.code)})}getInputRoutingState(){const e=this.isModeEnabled(Oe)||this.isModeEnabled(Ie)||this.isModeEnabled(Ue)||this.isModeEnabled(Be),t=this.isModeEnabled(ke)||this.isModeEnabled(Ae);return{mouseReporting:e,altScroll:!e&&t&&this.isModeEnabled(Ze)}}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 Et;case 1:return Tt;case 2:return vt;default:return null}}mouseButtonFromButtons(e){return e&1?Et:e&4?Tt:e&2?vt: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||Qe)),cellHeight:Math.max(1,Math.round(n.height||Me))});return i?(this.emitData(i),!0):!1}emitAltScrollInput(e){const t=ft(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=gt(this.bindings);let o=0,l=0;try{wt(i,this.terminalHandle);const y=tt(i);y.cursor.x!==null&&y.cursor.y!==null&&(o=y.cursor.x,l=y.cursor.y)}finally{qe(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);wt(this.renderState,this.terminalHandle);const n=tt(this.renderState),r=Array.from(nn(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=dn(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=Zn(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:Qe,this._core._renderService.dimensions.css.cell.height=t.height>0?t.height:Me}clearSelectionState(e=!0){this.selectionState=an(),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=cn(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=yt(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 k;const n=(k=this.screenElement)==null?void 0:k.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))),D=Math.max(0,Math.min(c,Math.floor(l/i)));return{line:this.lastViewportOffset+D,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 ln(this.selectionState)?un(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=yt(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 tr(s){return Ve.create(s)}const Ut={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"},sr='"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 Ht(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
+ `)}const nr="\x1B[?1049h\x1B[H\x1B[2J";function rr(s){return nr+Ht(s)}function Rt(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 ir=1.3,or=36;function lr(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=w=>w?!!(w.closest(".scrollbar")||w.closest(".slider")||w.closest(".xterm-scroll-area")):!1,y=(w,h,A)=>{const N=A instanceof Element?A:null;if(c(N))return!0;const q=document.elementFromPoint(w,h);if(c(q))return!0;const H=n.querySelector(".xterm");if(!(H instanceof HTMLElement))return!1;const M=H.getBoundingClientRect(),G=w>=M.left&&w<=M.right,X=h>=M.top&&h<=M.bottom;return!G||!X?!1:w>=M.right-or},D=()=>[n.querySelector(".xterm-viewport"),n.querySelector(".xterm-scrollable-element")].filter(h=>h instanceof HTMLElement),k=w=>{if(o===null)return null;for(let h=0;h<w.length;h+=1){const A=w.item(h);if(A&&A.identifier===o)return A}return null},I=w=>{if(w.touches.length!==1)return;const h=w.touches.item(0);h&&(o=h.identifier,i=h.clientY,d=0,l=y(h.clientX,h.clientY,w.target))},E=w=>{var G,X,oe,Q,_,U,V,Y;const h=k(w.touches)??w.touches.item(0);if(!h||(l||(l=y(h.clientX,h.clientY,w.target),l&&(d=0)),l))return;const A=h.clientY,N=i-A;if(i=A,N===0)return;let q=!1,H=!1;const M=(e==null?void 0:e())??null;if(M){const R=M==null?void 0:M._core,C=((Q=(oe=(X=(G=R==null?void 0:R._renderService)==null?void 0:G.dimensions)==null?void 0:X.css)==null?void 0:oe.cell)==null?void 0:Q.height)??18;d+=N*ir;const T=d>0?Math.floor(d/C):Math.ceil(d/C);if(typeof M.handleViewportGesture=="function")T!==0&&(q=M.handleViewportGesture({source:"touch",deltaY:T*C,clientX:h.clientX,clientY:h.clientY}),d-=T*C);else if(T!==0){const z=((U=(_=M.buffer)==null?void 0:_.active)==null?void 0:U.viewportY)??0;M.scrollLines(T);const te=((Y=(V=M.buffer)==null?void 0:V.active)==null?void 0:Y.viewportY)??0;q=z!==te,H=T<0&&z<=0&&te<=0,d-=T*C}}else{const R=D();if(R.length===0)return;for(const C of R){const T=C.scrollTop;C.scrollTop+=N;const z=C.scrollTop;Math.abs(z-T)>0&&(q=!0),N<0&&z<=0&&(H=!0)}if(!q){const C=n.querySelector(".xterm");if(C instanceof HTMLElement){const T=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:N}),z=C.dispatchEvent(T);q=T.defaultPrevented||!z}}}w.cancelable&&(q||H)&&w.preventDefault()},x=w=>{o===null||!k(w.changedTouches)||(o=null,d=0,l=!1)};return n.addEventListener("touchstart",I,{passive:!0}),n.addEventListener("touchmove",E,{passive:!1}),n.addEventListener("touchend",x,{passive:!0}),n.addEventListener("touchcancel",x,{passive:!0}),()=>{t.current=!1,n.removeEventListener("touchstart",I),n.removeEventListener("touchmove",E),n.removeEventListener("touchend",x),n.removeEventListener("touchcancel",x)}},[s,e]),t}function ar({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 cr({currentSize:s,containerSize:e,force:t=!1}){return t?!0:s.cols!==e.cols||s.rows!==e.rows}function ur({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),D=u.useRef(0),k=u.useRef([]),I=u.useRef(null),E=u.useRef(null),x=u.useRef(o),w=u.useRef(!1),h=u.useRef(r),A=u.useRef(i);u.useEffect(()=>{h.current=r},[r]),u.useEffect(()=>{A.current=i},[i]),u.useEffect(()=>{x.current=o},[o]);const N=u.useCallback(()=>{var z,te,S,b,P,B,$,K,le,O;const _=E.current,U=I.current;if(!_||!U||!_.element)return null;let V;try{const ae=U.proposeDimensions();if(!ae)throw new Error("fitAddon.proposeDimensions() returned null");V=Math.max(2,ae.cols)}catch{const ae=_._core,ce=((b=(S=(te=(z=ae==null?void 0:ae._renderService)==null?void 0:z.dimensions)==null?void 0:te.css)==null?void 0:S.cell)==null?void 0:b.width)??9,ee=(P=x.current)==null?void 0:P.call(x);if(!ee||ee.width===0)return null;V=Math.max(2,Math.floor(ee.width/ce))}const Y=(B=x.current)==null?void 0:B.call(x);if(!Y||Y.height===0)return null;const R=_._core,C=((O=(le=(K=($=R==null?void 0:R._renderService)==null?void 0:$.dimensions)==null?void 0:K.css)==null?void 0:le.cell)==null?void 0:O.height)??17,T=Math.max(2,Math.floor(Y.height/C));return{cols:V,rows:T}},[]),q=u.useCallback((_,U)=>{const V=E.current;V&&(V.cols===_&&V.rows===U||V.resize(_,U))},[]),H=u.useCallback((_,U=!1)=>{if(!s||!e||!t||n&&_!=="sync"||!U&&Date.now()<D.current||!E.current)return!1;const Y=N();if(!Y)return!1;const{cols:R,rows:C}=Y,T=c.current;return!U&&T&&T.cols===R&&T.rows===C?(q(R,C),!0):(q(R,C),_==="sync"?A.current(R,C):h.current(R,C),c.current={cols:R,rows:C},y.current={cols:R,rows:C,at:Date.now()},!0)},[q,t,s,n,N,e]),M=u.useCallback((_="resize",U={})=>{const{immediate:V=!1,force:Y=!1}=U;d.current!==null&&(window.clearTimeout(d.current),d.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const R=()=>{l.current=requestAnimationFrame(()=>{l.current=null,H(_,Y)})};if(V){R();return}d.current=window.setTimeout(()=>{d.current=null,R()},150)},[H]),G=u.useCallback(()=>{for(const _ of k.current)window.clearTimeout(_);k.current=[]},[]),X=u.useCallback(()=>{var U;G(),M("sync",{immediate:!0,force:!0});const _=window.setTimeout(()=>{M("sync",{immediate:!0,force:!0})},60);k.current.push(_),typeof document<"u"&&"fonts"in document&&((U=document.fonts)!=null&&U.ready)&&document.fonts.ready.then(()=>{M("sync",{immediate:!0,force:!0})}).catch(()=>{})},[G,M]);u.useEffect(()=>{let _=null;const U=()=>{_!==null&&cancelAnimationFrame(_),_=requestAnimationFrame(()=>{_=null,M("resize")})};return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),_!==null&&cancelAnimationFrame(_)}},[M]),u.useEffect(()=>{const _=()=>{var z;const R=E.current,C=N();if(!R||!C)return;if(!cr({currentSize:{cols:Math.max(2,R.cols),rows:Math.max(2,R.rows)},containerSize:C})){(z=R.refresh)==null||z.call(R);return}M("sync",{force:!0})},U=()=>{if(document.visibilityState!=="visible"){w.current=!0;return}w.current&&(w.current=!1,_())},V=()=>{w.current=!0},Y=()=>{w.current&&(w.current=!1,_())};return document.addEventListener("visibilitychange",U),window.addEventListener("blur",V),window.addEventListener("focus",Y),()=>{document.removeEventListener("visibilitychange",U),window.removeEventListener("blur",V),window.removeEventListener("focus",Y)}},[N,M]),u.useEffect(()=>()=>{G(),d.current!==null&&window.clearTimeout(d.current),l.current!==null&&cancelAnimationFrame(l.current)},[G]);const oe=u.useCallback(_=>{I.current=_},[]),Q=u.useCallback(_=>{E.current=_},[]);return{scheduleResize:M,runPostSelectResize:X,clearPostSelectResizeTimers:G,setFitAddon:oe,setTerminal:Q,lastReportedSize:c,pendingLocalSize:y,suppressLocalResizeUntil:D}}const dr={fontFamily:sr,fontSize:13,scrollback:1e4},st="tmex:terminal-mode-cache";function hr(s,e){try{const t=sessionStorage.getItem(st);return t?JSON.parse(t)[`${s}:${e}`]??null:null}catch{return null}}function fr(s,e,t){try{const n=sessionStorage.getItem(st),r=n?JSON.parse(n):{},i=`${s}:${e}`;t?r[i]=t:delete r[i],sessionStorage.setItem(st,JSON.stringify(r))}catch{}}function mr(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function pr(s,e){if(!e)return s?{...s,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const t=mr();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,altScreen1047:!1,altScreen1049:!1,mouseNormal:n?s.mouseNormal:t.mouseNormal}}function gr(s){var t;const e=globalThis;e.__tmexE2eXterm=s,e.__tmexE2eTerminal=s,e.__tmexE2eTerminalEngine=It,e.__tmexE2eTerminalRenderer=((t=s.getRendererKind)==null?void 0:t.call(s))??null}function wr(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 Vt=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),D=j(S=>S.sendInput),k=u.useMemo(()=>{switch(t){case"light":return Ut;default:return Bt}},[t]),I=u.useRef(null),E=u.useRef(null),x=u.useRef(null),w=u.useRef(s),h=u.useRef(e),A=u.useRef(s),N=u.useRef(e),q=u.useRef(r&&!i),H=u.useRef(n),M=u.useRef(k),G=u.useRef(!1),X=u.useRef(!1),oe=u.useRef(null),Q=u.useRef(!1),_=u.useCallback((S,b,P)=>{!(S!=null&&S.exportModeSnapshot)||!b||!P||fr(b,P,S.exportModeSnapshot())},[]),U=u.useCallback(()=>c,[c]);lr(I,U),u.useEffect(()=>{w.current=s,h.current=e,X.current=!1},[s,e]),u.useEffect(()=>{q.current=r&&!i},[r,i]),u.useEffect(()=>{H.current=n},[n]),u.useEffect(()=>{M.current=k},[k]);const V=u.useCallback(S=>{if(!S||n!=="direct"||!q.current)return;const b=w.current,P=h.current;!b||!P||D(b,P,S,!1)},[n,D]),{pendingLocalSize:Y,scheduleResize:R,runPostSelectResize:C,setFitAddon:T,setTerminal:z}=ur({deviceId:s,paneId:e,deviceConnected:r,isSelectionInvalid:i,onResize:o,onSync:l,getContainerRect:()=>{const S=I.current;if(!S)return null;const b=S.getBoundingClientRect();return{width:b.width,height:b.height}}});u.useEffect(()=>{let S=!1,b=null;return tr({...dr,theme:M.current,disableStdin:H.current==="editor"}).then(P=>{if(S){P.dispose();return}b=P,E.current&&P.open(E.current),gr(P),y(P)}),()=>{S=!0,y(null),wr(b),b==null||b.dispose()}},[]),u.useEffect(()=>{!c||!("setTheme"in c)||c.setTheme(k)},[c,k]),u.useEffect(()=>{!c||!("setDisableStdin"in c)||c.setDisableStdin(n==="editor")},[c,n]);const te=u.useMemo(()=>c?{onResetTerminal:S=>{w.current===S&&(_(c,A.current,N.current),Q.current=!0,c.reset(),G.current=!1,C())},onApplyHistory:(S,b,P)=>{var K;if(w.current!==S)return;const B=pr(hr(w.current,h.current),P);B&&((K=c.restoreModeSnapshot)==null||K.call(c,B));const $=P?rr(b):Ht(b);X.current=!0,c.write($),Q.current=!1,A.current=w.current,N.current=h.current,_(c,w.current,h.current)},onFlushBuffer:(S,b)=>{if(w.current===S){for(const P of b){const B=Rt(P,G.current);G.current=B.endedWithCR,c.write(B.normalized)}X.current&&(c.buffer.active.baseY<=1&&c.scrollToTop(),X.current=!1),A.current=w.current,N.current=h.current,_(c,w.current,h.current)}},onOutput:(S,b,P)=>{if(w.current!==S||h.current!==b)return;const B=Rt(P,G.current);G.current=B.endedWithCR,c.write(B.normalized),X.current&&(c.buffer.active.baseY<=1&&c.scrollToTop(),X.current=!1),A.current=w.current,N.current=h.current,_(c,w.current,h.current)}}:{},[c,_,C]);return u.useEffect(()=>{c?oe.current!==c&&(G.current=!1,A.current=w.current,N.current=h.current,oe.current=c):oe.current=null},[c]),u.useEffect(()=>{if(!(!c||!s||!e))return()=>{if(Q.current){Q.current=!1;return}_(c,A.current,N.current)}},[s,c,e,_]),u.useEffect(()=>{dt(te)},[te]),u.useEffect(()=>()=>{dt({})},[]),u.useEffect(()=>{if(!c){x.current=null,T(null),z(null);return}const S=new er;return c.loadAddon(S),x.current=S,T(S),z(c),C(),()=>{try{S.dispose()}finally{x.current=null,T(null),z(null)}}},[c,C,T,z]),u.useEffect(()=>{const S=I.current;if(!S)return;let b=null;const P=new ResizeObserver(()=>{b!==null&&cancelAnimationFrame(b),b=requestAnimationFrame(()=>{b=null,R("resize")})});return P.observe(S),()=>{P.disconnect(),b!==null&&cancelAnimationFrame(b)}},[R]),u.useEffect(()=>{if(!c||!s||!e)return;const S=c.onData(b=>{!r||i||V(b)});return c.attachCustomKeyEventHandler(b=>!r||i||b.type!=="keydown"||n!=="direct"?!0:b.shiftKey&&b.key==="Enter"?(b.preventDefault(),V("\x1B[13;2u"),!1):!0),()=>{S.dispose(),c.attachCustomKeyEventHandler(()=>!0)}},[c,r,i,n,V,s,e]),u.useImperativeHandle(d,()=>({write:S=>c==null?void 0:c.write(S),reset:()=>{c==null||c.reset(),G.current=!1},scrollToBottom:()=>c==null?void 0:c.scrollToBottom(),resize:(S,b)=>c==null?void 0:c.resize(S,b),getTerminal:()=>c??null,getSize:()=>c?{cols:Math.max(2,c.cols),rows:Math.max(2,c.rows)}:null,runPostSelectResize:()=>C(),scheduleResize:(S,b)=>R(S,b),calculateSizeFromContainer:()=>{var ae,ce,ee,se,ne,be,Fe,Ge,ze,Se,J,xe,me,Ce,De,ue;const S=I.current,b=c,P=x.current;if(!S||!b)return null;const B=S.getBoundingClientRect();if(B.width===0||B.height===0)return null;const $=b._core;let K;if(P)try{const re=P.proposeDimensions();if(re)K=Math.max(2,re.cols);else{const he=((se=(ee=(ce=(ae=$==null?void 0:$._renderService)==null?void 0:ae.dimensions)==null?void 0:ce.css)==null?void 0:ee.cell)==null?void 0:se.width)??9;K=Math.max(2,Math.floor(B.width/he))}}catch{const re=((Ge=(Fe=(be=(ne=$==null?void 0:$._renderService)==null?void 0:ne.dimensions)==null?void 0:be.css)==null?void 0:Fe.cell)==null?void 0:Ge.width)??9;K=Math.max(2,Math.floor(B.width/re))}else{const re=((xe=(J=(Se=(ze=$==null?void 0:$._renderService)==null?void 0:ze.dimensions)==null?void 0:Se.css)==null?void 0:J.cell)==null?void 0:xe.width)??9;K=Math.max(2,Math.floor(B.width/re))}const le=((ue=(De=(Ce=(me=$==null?void 0:$._renderService)==null?void 0:me.dimensions)==null?void 0:Ce.css)==null?void 0:De.cell)==null?void 0:ue.height)??17,O=Math.max(2,Math.floor(B.height/le));return{cols:K,rows:O}},getPendingLocalSize:()=>Y.current}),[c,Y,C,R]),m.jsxDEV("div",{ref:I,className:"h-full w-full relative",style:{backgroundColor:k.background},"data-terminal-engine":It,children:m.jsxDEV("div",{ref:E,className:"absolute inset-0"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/components/terminal/Terminal.tsx",lineNumber:550,columnNumber:9},void 0)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/components/terminal/Terminal.tsx",lineNumber:544,columnNumber:7},void 0)});Vt.displayName="Terminal";const yr=1200,br=2e3;function pe(s,e){return!s||!e?!1:s.windowId===e.windowId&&s.paneId===e.paneId}function Ft(s,e){const t=s.filter(n=>e-n.at<yr);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>br?null:s}function Sr(s){const e=s.now??Date.now(),t=Ft(s.recentSelectRequests,e);if(t&&!pe(t,s.activePaneFromEvent)||pe(s.currentRoute,s.activePaneFromEvent)||pe(s.lastHandledActive,s.activePaneFromEvent))return!0;const n=Re(s.pendingUserSelection,e);return!!(n&&!pe(n,s.activePaneFromEvent))}function xr(s){const e=s.now??Date.now(),t=Ft(s.recentSelectRequests,e),n=Re(s.pendingUserSelection,e);return!!(n&&!pe(n,s.snapshotActive)||t&&!pe(t,s.snapshotActive))}function _r(s){const e=s.now??Date.now(),t=Re(s.pendingUserSelection,e);return!(t&&pe(t,s.routeTarget)||s.snapshotActive&&pe(s.snapshotActive,s.routeTarget))}function Er(){const s=nt.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 Gt({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 Tr(s){const e=Er();return s!=null&&s.trim()?`[${e}]${s}`:e}function vr(){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 Rr=[{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 m.jsxDEV("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:m.jsxDEV("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Rr.map(o=>m.jsxDEV(ge,{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 kr(){var ut;const{t:s}=Nt(),{deviceId:e,windowId:t,paneId:n}=rt(),r=Qt(),i=u.useRef(null),o=u.useRef(null),l=u.useRef(null),d=u.useRef(null),c=u.useRef(!1),y=u.useRef(!1),D=u.useRef(null),k=j(a=>a.selectPane),I=j(a=>e?a.snapshots[e]:void 0),E=j(a=>{var p;return e?(p=a.deviceErrors)==null?void 0:p[e]:void 0}),x=j(a=>{var p;return e?((p=a.deviceConnected)==null?void 0:p[e])??!1:!1}),w=nt(a=>{var p;return((p=a.settings)==null?void 0:p.siteName)??"tmex"}),h=u.useMemo(()=>it(n),[n]),A=u.useMemo(()=>e&&h?`${e}:${h}`:null,[e,h]),[N,q]=u.useState(!1),[H,M]=u.useState(""),[G,X]=u.useState(!1),oe=u.useRef(!1),Q=!x||!h,[_,U]=u.useState(0),[V,Y]=u.useState(0),[R,C]=u.useState(!1),T=de(a=>a.inputMode),z=de(a=>a.theme),te=de(a=>a.editorSendWithEnter),S=de(a=>a.setEditorSendWithEnter),b=de(a=>a.addEditorHistory),P=de(a=>a.setEditorDraft),B=de(a=>a.removeEditorDraft),$=de(a=>A?a.editorDrafts[A]??"":""),K=u.useMemo(()=>vr(),[]),le=N&&T==="editor"&&K&&G,O=(ut=I==null?void 0:I.session)==null?void 0:ut.windows,ae=z==="light"?Ut:Bt,{data:ce}=Zt({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}),ee=u.useMemo(()=>{if(e)return ce==null?void 0:ce.devices.find(a=>a.id===e)},[e,ce==null?void 0:ce.devices]),se=u.useMemo(()=>{if(!(!t||!O))return O.find(a=>a.id===t)},[t,O]),ne=u.useMemo(()=>{if(!(!h||!se))return se.panes.find(a=>a.id===h)},[h,se]),be=!!O,Se=!!(be&&!!t&&!se||be&&!!t&&!!h&&!!se&&!ne?s("wsError.checkGateway"):null),J=!!(x&&h&&!Se),xe=u.useMemo(()=>{if(!se||!ne)return null;const a=(ee==null?void 0:ee.name)??e;return Gt({paneIdx:ne.index,windowIdx:se.index,paneTitle:ne.title,windowName:se.name,deviceName:a})},[ee==null?void 0:ee.name,e,ne,se]),me=u.useMemo(()=>{if(!O||O.length===0)return null;const a=O.find(f=>f.active),p=a==null?void 0:a.panes.find(f=>f.active);return!a||!p?null:{windowId:a.id,paneId:p.id}},[O]),Ce=u.useCallback((a,p)=>{!e||!h||j.getState().resizePane(e,h,a,p)},[e,h]),De=u.useCallback((a,p)=>{!e||!h||j.getState().syncPaneSize(e,h,a,p)},[e,h]),ue=u.useCallback((a,p)=>{const f=d.current,v=(f==null?void 0:f.calculateSizeFromContainer())??(f==null?void 0:f.getSize())??void 0;if(v)return v;if(!a||!p||!O)return;const W=O.find(ie=>ie.id===a),F=W==null?void 0:W.panes.find(ie=>ie.id===p);if(!(!F||F.width<=1||F.height<=1))return{cols:F.width,rows:F.height}},[O]);u.useEffect(()=>{const a=()=>{q(window.innerWidth<768||"ontouchstart"in window)};return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),u.useEffect(()=>{if(!N||!K||y.current)return;y.current=!0;const a=()=>{window.scrollTo(0,1)},p=window.requestAnimationFrame(a),f=window.setTimeout(a,120),v=window.setTimeout(a,420);return()=>{window.cancelAnimationFrame(p),window.clearTimeout(f),window.clearTimeout(v)}},[K,N]),u.useEffect(()=>{T!=="editor"&&X(!1)},[T]),u.useEffect(()=>{var v,W;if(!(N&&K&&T==="editor"&&G)){U(0);return}let a=null;const p=()=>{const F=window.visualViewport,ie=(F==null?void 0:F.height)??window.innerHeight,Ee=(F==null?void 0:F.offsetTop)??0,qt=Math.max(0,Math.round(window.innerHeight-ie-Ee));U(qt)},f=()=>{a===null&&(a=window.requestAnimationFrame(()=>{a=null,p()}))};return p(),(v=window.visualViewport)==null||v.addEventListener("resize",f),(W=window.visualViewport)==null||W.addEventListener("scroll",f),window.addEventListener("resize",f),()=>{var F,ie;(F=window.visualViewport)==null||F.removeEventListener("resize",f),(ie=window.visualViewport)==null||ie.removeEventListener("scroll",f),window.removeEventListener("resize",f),a!==null&&window.cancelAnimationFrame(a)}},[T,G,K,N]),u.useEffect(()=>{if(!le){Y(0);return}const a=o.current;if(!a)return;const p=()=>{Y(Math.ceil(a.getBoundingClientRect().height))};p();const f=new ResizeObserver(p);return f.observe(a),()=>f.disconnect()},[le]),u.useEffect(()=>{e&&(c.current=!1,Ye.current=null,_e.current=null,D.current=null,re.current=[])},[e]),u.useEffect(()=>{x||(c.current=!1)},[x]),u.useEffect(()=>{if(!e||!x||!t||!O)return;if(O.length===0){r("/devices",{replace:!0});return}const a=O.find(f=>f.id===t);if(!a)return;if(!h){const f=a.panes.find(v=>v.active)??a.panes[0];f&&r(`/devices/${e}/windows/${t}/panes/${we(f.id)}`,{replace:!0});return}if(!a.panes.find(f=>f.id===h)){const f=a.panes.find(v=>v.active)??a.panes[0];f&&r(`/devices/${e}/windows/${t}/panes/${we(f.id)}`,{replace:!0});return}},[e,x,O,t,h,r]),u.useEffect(()=>{if(!e||!x||!O||O.length===0||t&&h||c.current)return;const a=O.find(f=>f.active)??O[0],p=a.panes.find(f=>f.active)??a.panes[0];p&&(c.current=!0,r(`/devices/${e}/windows/${a.id}/panes/${we(p.id)}`,{replace:!0}))},[x,e,r,h,t,O]),u.useEffect(()=>{if(!e||!t||!h||Q||!x)return;const a=j.getState().selectedPanes[e];if(a&&a.windowId===t&&a.paneId===h)return;const p=ue(t,h);he(t,h),k(e,t,h,p)},[x,e,ue,Q,h,k,t]),u.useEffect(()=>{if(!e||!x||!t||!h)return;const a={windowId:t,paneId:h};_r({routeTarget:a,snapshotActive:me,pendingUserSelection:D.current})&&(D.current={windowId:a.windowId,paneId:a.paneId,at:Date.now()})},[x,e,h,me,t]);const re=u.useRef([]),he=u.useCallback((a,p)=>{const f=Date.now(),v=[...re.current.filter(W=>f-W.at<2e3),{windowId:a,paneId:p,at:f}];re.current=v.slice(-8)},[]),Z=j(a=>e?a.activePaneFromEvent[e]:void 0),Ye=u.useRef(null);u.useEffect(()=>{if(!e||!x||!t||!h||!Z)return;const a=Date.now(),p=Re(D.current,a);if(D.current=p,Sr({now:a,pendingUserSelection:p,activePaneFromEvent:Z,currentRoute:{windowId:t,paneId:h},recentSelectRequests:re.current,lastHandledActive:Ye.current}))return;Ye.current={...Z},p&&p.windowId===Z.windowId&&p.paneId===Z.paneId&&(D.current=null);const f=ue(Z.windowId,Z.paneId);he(Z.windowId,Z.paneId),k(e,Z.windowId,Z.paneId,f),r(`/devices/${e}/windows/${Z.windowId}/panes/${we(Z.paneId)}`,{replace:!0})},[e,x,t,h,Z,he,ue,k,r]);const _e=u.useRef(null);u.useEffect(()=>{if(!e||!x||!O||O.length===0)return;const a=re.current,p=O.find(Ee=>Ee.active);if(!p)return;const f=p.panes.find(Ee=>Ee.active);if(!f)return;const v={windowId:p.id,paneId:f.id},W=Date.now(),F=Re(D.current,W);if(D.current=F,xr({now:W,pendingUserSelection:F,snapshotActive:v,recentSelectRequests:a})||_e.current&&_e.current.windowId===v.windowId&&_e.current.paneId===v.paneId||(_e.current={...v},F&&F.windowId===v.windowId&&F.paneId===v.paneId&&(D.current=null),t===v.windowId&&h===v.paneId))return;const ie=ue(v.windowId,v.paneId);he(v.windowId,v.paneId),k(e,v.windowId,v.paneId,ie),r(`/devices/${e}/windows/${v.windowId}/panes/${we(v.paneId)}`,{replace:!0})},[e,x,O,t,h,he,ue,k,r]);const $e=j(a=>e?a.pendingCreateWindowAt[e]:void 0);u.useEffect(()=>{if(!e||!x||!$e)return;const a=5e3,p=Date.now()-$e;if(p>a){j.getState().clearPendingCreateWindow(e);return}if(!me){const W=window.setTimeout(()=>{j.getState().clearPendingCreateWindow(e)},a-p);return()=>window.clearTimeout(W)}const f=me;if(t===f.windowId&&h===f.paneId){const W=window.setTimeout(()=>{j.getState().clearPendingCreateWindow(e)},a-p);return()=>window.clearTimeout(W)}D.current={windowId:f.windowId,paneId:f.paneId,at:Date.now()};const v=ue(f.windowId,f.paneId);he(f.windowId,f.paneId),k(e,f.windowId,f.paneId,v),r(`/devices/${e}/windows/${f.windowId}/panes/${we(f.paneId)}`,{replace:!0}),j.getState().clearPendingCreateWindow(e)},[e,x,$e,me,t,h,he,ue,k,r]),u.useEffect(()=>{if(!J||!ne||Q)return;const a=d.current,p=a==null?void 0:a.getTerminal();if(!p)return;const f=Math.max(2,Math.floor(ne.width||0)),v=Math.max(2,Math.floor(ne.height||0));if(!f||!v)return;const W=Date.now(),F={cols:f,rows:v},ie=(a==null?void 0:a.getPendingLocalSize())??null;ar({now:W,remoteSize:F,pendingLocalSize:ie})&&(p.cols===f&&p.rows===v||p.resize(f,v))},[J,Q,ne]),u.useEffect(()=>{const a=window.requestAnimationFrame(()=>{var f;(f=d.current)==null||f.scrollToBottom()}),p=window.setTimeout(()=>{var f;(f=d.current)==null||f.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(a),window.clearTimeout(p)}},[T]),u.useEffect(()=>{E!=null&&E.message&&Ke.error(E.message)},[E==null?void 0:E.message]),u.useEffect(()=>(document.title=Tr(xe),()=>{document.title=w}),[w,xe]),u.useEffect(()=>{const a=()=>{var p;(p=d.current)==null||p.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",a),()=>{window.removeEventListener("tmex:jump-to-latest",a)}},[]),u.useEffect(()=>{const a=p=>{const{deviceId:f,windowId:v,paneId:W}=p.detail;f===e&&(D.current={windowId:v,paneId:W,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",a),()=>{window.removeEventListener("tmex:user-initiated-selection",a)}},[e]),u.useEffect(()=>{M($)},[$]);const ct=u.useCallback(a=>{if(!e||!h||!J)return;j.getState().sendInput(e,h,a,!1)},[J,e,h]),zt=u.useCallback(()=>{if(!J){Ke.error(s("wsError.checkGateway"));return}if(!e||!h||!H.trim())return;C(!0),window.setTimeout(()=>C(!1),150);const a=te?`${H}\r`:H;j.getState().sendInput(e,h,a,!1),b(H),A&&B(A),M("")},[b,J,e,A,te,H,B,h,s]),Yt=u.useCallback(()=>{if(!J){Ke.error(s("wsError.checkGateway"));return}if(!e||!h||!H.trim())return;C(!0),window.setTimeout(()=>C(!1),150);const a=H.split(/\r?\n/),p=j.getState();for(const f of a)f.trim()&&p.sendInput(e,h,`${f}\r`,!1);b(H),A&&B(A),M("")},[b,J,e,A,H,B,h,s]),$t=u.useCallback(a=>{if(X(!0),!(N&&K))return;const p=a.currentTarget;window.requestAnimationFrame(()=>{p.scrollIntoView({block:"nearest",inline:"nearest"})}),window.setTimeout(()=>{window.scrollTo(0,1)},60)},[K,N]),Kt=u.useCallback(()=>{X(!1)},[]),Wt=u.useCallback(()=>{var a;(a=l.current)==null||a.focus({preventScroll:!0})},[]);if(!e)return m.jsxDEV("div",{className:"flex h-full items-center justify-center p-4",children:m.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:976,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:975,columnNumber:7},this);const jt=!x&&!E;return m.jsxDEV("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[m.jsxDEV("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${N&&T==="editor"&&!le?"pb-1":""}`,style:{paddingBottom:le?`${V+60}px`:void 0},children:[m.jsxDEV("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:ae.background},children:x&&h?m.jsxDEV("div",{ref:i,className:"flex-1 h-full min-h-0 w-full",children:m.jsxDEV(Vt,{ref:d,deviceId:e,paneId:h,theme:z,inputMode:T,deviceConnected:x,isSelectionInvalid:Se,onResize:Ce,onSync:De},`${e}:${h}`,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1001,columnNumber:15},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1e3,columnNumber:13},this):m.jsxDEV("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:m.jsxDEV("div",{className:"max-w-sm space-y-4",children:x?t?m.jsxDEV(m.Fragment,{children:[m.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:m.jsxDEV(We,{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:1038,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1037,columnNumber:21},this),m.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:1040,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1036,columnNumber:19},this):m.jsxDEV(m.Fragment,{children:[m.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:m.jsxDEV("span",{className:"text-2xl text-muted-foreground",children:"📋"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1028,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1027,columnNumber:21},this),m.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:1030,columnNumber:21},this),m.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:1031,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1026,columnNumber:19},this):m.jsxDEV(m.Fragment,{children:[m.jsxDEV("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:m.jsxDEV("span",{className:"text-2xl text-muted-foreground",children:"🔌"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1020,columnNumber:23},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1019,columnNumber:21},this),m.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:1022,columnNumber:21},this),m.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:1023,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1018,columnNumber:19},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1016,columnNumber:15},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1015,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:995,columnNumber:9},this),jt&&m.jsxDEV("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:m.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:[m.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:1054,columnNumber:15},this),m.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:1055,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1053,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1049,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:987,columnNumber:7},this),T==="direct"&&m.jsxDEV("div",{className:"",children:m.jsxDEV(Dt,{onSend:ct,disabled:!J,isMobile:N,inputMode:T},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1066,columnNumber:11},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1065,columnNumber:9},this),T==="editor"&&m.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:`${_}px`}:void 0,children:[N&&m.jsxDEV(Dt,{onSend:ct,onFocusEditor:Wt,disabled:!J,isMobile:N,inputMode:T},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1085,columnNumber:13},this),m.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:H,onChange:a=>{const p=a.target.value;if(M(p),!!A){if(p){P(A,p);return}B(A)}},placeholder:s("terminal.inputPlaceholder"),onFocus:$t,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:1093,columnNumber:11},this),m.jsxDEV("div",{className:"actions mt-2",children:m.jsxDEV("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[m.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:[m.jsxDEV(cs,{size:"sm",checked:te,onCheckedChange:a=>S(!!a)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1129,columnNumber:17},this),m.jsxDEV("span",{children:s("terminal.editorSendWithEnter")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1134,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1125,columnNumber:15},this),m.jsxDEV(ge,{variant:"outline",size:"sm","data-testid":"editor-clear",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;M(""),A&&B(A),N&&T==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},title:s("terminal.clear"),children:[m.jsxDEV(es,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1152,columnNumber:17},this),s("terminal.clear")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1136,columnNumber:15},this),m.jsxDEV(ge,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;Yt(),N&&T==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},disabled:!J||R,children:[R?m.jsxDEV(We,{className:"h-4 w-4 animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1169,columnNumber:19},this):m.jsxDEV(ht,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1171,columnNumber:19},this),s("terminal.editorSendLineByLine")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1155,columnNumber:15},this),m.jsxDEV(ge,{variant:"default",size:"sm","data-testid":"editor-send",onPointerDown:a=>a.preventDefault(),onClick:()=>{var a;zt(),N&&T==="editor"&&((a=l.current)==null||a.focus({preventScroll:!0}))},disabled:!J||R,children:[R?m.jsxDEV(We,{className:"h-4 w-4 animate-spin"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1189,columnNumber:19},this):m.jsxDEV(ht,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1191,columnNumber:19},this),s("common.send")]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1175,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1121,columnNumber:13},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1120,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1076,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:986,columnNumber:5},this)}function Ar(){const{deviceId:s,windowId:e,paneId:t}=rt(),n=t?it(t):void 0,r=j(y=>y.snapshots),i=nt(y=>{var D;return((D=y.settings)==null?void 0:D.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(D=>D.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?Gt({paneIdx:d.index,windowIdx:l.index,paneTitle:d.title,windowName:l.name,deviceName:i}):s??"",[l,d,i,s]);return m.jsxDEV(m.Fragment,{children:c},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1234,columnNumber:10},this)}function Lr(){const{t:s}=Nt(),{deviceId:e,paneId:t}=rt(),n=t?it(t):void 0,r=de(E=>E.inputMode),i=de(E=>E.setInputMode),o=j(E=>{var x;return e?((x=E.deviceConnected)==null?void 0:x[e])??!1:!1}),[l,d]=u.useState(!1),c=!!(n&&o),y=()=>{i(r==="direct"?"editor":"direct")},D=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},k=()=>{d(!0)},I=()=>{window.location.reload()};return m.jsxDEV(m.Fragment,{children:[m.jsxDEV(ge,{variant:"ghost",size:"icon-sm",onClick:k,"aria-label":s("nav.refreshPage"),title:s("nav.refreshPage"),children:m.jsxDEV(ps,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1278,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1271,columnNumber:7},this),m.jsxDEV(ge,{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"?m.jsxDEV(fs,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1290,columnNumber:11},this):m.jsxDEV(ws,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1292,columnNumber:11},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1280,columnNumber:7},this),m.jsxDEV(ge,{variant:"ghost",size:"icon-sm",onClick:D,disabled:!c,"aria-label":s("nav.jumpToLatest"),title:s("nav.jumpToLatest"),children:m.jsxDEV(ds,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1303,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1295,columnNumber:7},this),m.jsxDEV(ts,{open:l,onOpenChange:d,children:m.jsxDEV(ss,{children:[m.jsxDEV(ns,{children:[m.jsxDEV(rs,{children:s("nav.refreshPage")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1309,columnNumber:13},this),m.jsxDEV(is,{children:s("nav.refreshPageConfirm")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1310,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1308,columnNumber:11},this),m.jsxDEV(os,{children:[m.jsxDEV(ls,{onClick:()=>d(!1),children:s("common.cancel")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1313,columnNumber:13},this),m.jsxDEV(as,{onClick:I,children:s("common.confirm")},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1316,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1312,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1307,columnNumber:9},this)},void 0,!1,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1306,columnNumber:7},this)]},void 0,!0,{fileName:"/Users/krhougs/LocalCodes/tmex/apps/fe/src/pages/DevicePage.tsx",lineNumber:1270,columnNumber:5},this)}export{Lr as PageActions,Ar as PageTitle,kr as default};
26
+ //# sourceMappingURL=DevicePage-n4JoyDed.js.map