tmex-cli 0.4.4 → 0.5.0

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 (22) hide show
  1. package/dist/runtime/server.js +384 -37
  2. package/package.json +1 -1
  3. package/resources/fe-dist/assets/DevicePage-c0xvFVOR.js +36 -0
  4. package/resources/fe-dist/assets/DevicePage-c0xvFVOR.js.map +1 -0
  5. package/resources/fe-dist/assets/{DevicesPage-dj7Pel6f.js → DevicesPage-Bos2klmd.js} +2 -2
  6. package/resources/fe-dist/assets/{DevicesPage-dj7Pel6f.js.map → DevicesPage-Bos2klmd.js.map} +1 -1
  7. package/resources/fe-dist/assets/{SettingsPage-DwpbDA_e.js → SettingsPage-3wTqyDjG.js} +2 -2
  8. package/resources/fe-dist/assets/{SettingsPage-DwpbDA_e.js.map → SettingsPage-3wTqyDjG.js.map} +1 -1
  9. package/resources/fe-dist/assets/{index-61hq_aNX.js → index-Ct9A2pvj.js} +8 -8
  10. package/resources/fe-dist/assets/index-Ct9A2pvj.js.map +1 -0
  11. package/resources/fe-dist/assets/index-otkzncJS.css +1 -0
  12. package/resources/fe-dist/assets/{select-DI4HQZd4.js → select-C4GOQfW-.js} +2 -2
  13. package/resources/fe-dist/assets/{select-DI4HQZd4.js.map → select-C4GOQfW-.js.map} +1 -1
  14. package/resources/fe-dist/assets/{switch-DsfDIUrU.js → switch-B99WcFEc.js} +2 -2
  15. package/resources/fe-dist/assets/{switch-DsfDIUrU.js.map → switch-B99WcFEc.js.map} +1 -1
  16. package/resources/fe-dist/assets/{useValueChanged-AVaPYvln.js → useValueChanged-C4_y3Agi.js} +2 -2
  17. package/resources/fe-dist/assets/{useValueChanged-AVaPYvln.js.map → useValueChanged-C4_y3Agi.js.map} +1 -1
  18. package/resources/fe-dist/index.html +2 -2
  19. package/resources/fe-dist/assets/DevicePage-Di11uzbS.js +0 -26
  20. package/resources/fe-dist/assets/DevicePage-Di11uzbS.js.map +0 -1
  21. package/resources/fe-dist/assets/index-40zyi_9K.css +0 -1
  22. package/resources/fe-dist/assets/index-61hq_aNX.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ var en=Object.defineProperty;var tn=(n,e,t)=>e in n?en(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var w=(n,e,t)=>tn(n,typeof e!="symbol"?e+"":e,t);import{c as Te,u as Ke,j as h,X as nn,r as d,aN as ee,by as ft,f as xe,b as ot,bz as lt,bA as sn,bB as at,d as he,e as rn,bC as be,B as ge}from"./index-Ct9A2pvj.js";import{T as on,A as ln,a as an,b as cn,c as dn,d as un,e as hn,f as fn,g as mn}from"./useValueChanged-C4_y3Agi.js";import{L as Xe,S as pn,a as mt}from"./switch-B99WcFEc.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 wn=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],yn=Te("arrow-down-to-line",wn);/**
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 gn=[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]],Sn=Te("clipboard-paste",gn);/**
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 _n=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],bn=Te("copy",_n);/**
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 xn=[["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"}]],Tn=Te("keyboard",xn);/**
22
+ * @license lucide-react v0.564.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const En=[["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"}]],Rn=Te("refresh-cw",En);/**
27
+ * @license lucide-react v0.564.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const Cn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],vn=Te("smartphone",Cn);function Mn(n){return`rgb(${n.r} ${n.g} ${n.b})`}function Je(n){const e=n.getContext("2d");if(!e)throw new Error("2d canvas context unavailable");return e}class Dn{constructor(e){w(this,"kind","canvas");w(this,"mainCanvas");w(this,"selectionCanvas");w(this,"cursorCanvas");w(this,"mainContext");w(this,"selectionContext");w(this,"cursorContext");w(this,"theme");w(this,"fontFamily");w(this,"fontSize");w(this,"cellDimensions",{width:9,height:17});w(this,"cols",0);w(this,"rows",0);w(this,"lastCursor",null);w(this,"frameCount",0);w(this,"lastDrawnRows",[]);w(this,"colorCache",new Map);w(this,"fontCache",new Map);w(this,"cursorBlinkVisible",!0);w(this,"cursorBlinkTimer",null);this.theme=e.theme,this.fontFamily=e.fontFamily,this.fontSize=e.fontSize,e.screenElement.style.position="relative",e.screenElement.style.overflow="hidden",this.mainCanvas=document.createElement("canvas"),this.selectionCanvas=document.createElement("canvas"),this.cursorCanvas=document.createElement("canvas");for(const[t,s]of[[this.mainCanvas,"main"],[this.selectionCanvas,"selection"],[this.cursorCanvas,"cursor"]])t.dataset.layer=s,t.style.position="absolute",t.style.inset="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",e.screenElement.appendChild(t);this.mainContext=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 s=e.meta.dirty==="full"?e.rows:e.rows.filter(r=>r.dirty);for(const r of s)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 s=Math.max(1,e),r=Math.max(1,t),i=s*this.cellDimensions.width,o=r*this.cellDimensions.height,l=Math.max(1,globalThis.devicePixelRatio??1);if(this.cols===s&&this.rows===r){const u=`${i}px`,a=`${o}px`;if(this.mainCanvas.style.width===u&&this.mainCanvas.style.height===a)return}this.cols=s,this.rows=r;for(const u of[this.mainCanvas,this.selectionCanvas,this.cursorCanvas])u.width=Math.max(1,Math.ceil(i*l)),u.height=Math.max(1,Math.ceil(o*l)),u.style.width=`${i}px`,u.style.height=`${o}px`;for(const u of[this.mainContext,this.selectionContext,this.cursorContext])u.setTransform(l,0,0,l,0,0),u.textBaseline="top",u.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 s of e)this.selectionContext.fillRect(s.x*this.cellDimensions.width,s.row*this.cellDimensions.height,s.width*this.cellDimensions.width,this.cellDimensions.height)}}drawRow(e,t){const s=e.y*this.cellDimensions.height,r=this.cols*this.cellDimensions.width,i=this.toCss(t.background);this.mainContext.clearRect(0,s,r,this.cellDimensions.height),this.mainContext.fillStyle=i,this.mainContext.fillRect(0,s,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,u=o.style.inverse?o.fgColor??t.foreground:o.bgColor??t.background,a=o.style.inverse?o.bgColor??t.background:o.fgColor??t.foreground,_=o.widthKind==="wide"?this.cellDimensions.width*2:this.cellDimensions.width;(u.r!==t.background.r||u.g!==t.background.g||u.b!==t.background.b)&&(this.mainContext.fillStyle=this.toCss(u),this.mainContext.fillRect(l,s,_,this.cellDimensions.height)),!(!o.text||o.style.invisible)&&(this.mainContext.font=this.resolveFont(o.style),this.mainContext.fillStyle=this.toCss(a),this.mainContext.fillText(o.text,l,s),o.style.underline>0&&this.mainContext.fillRect(l,s+this.cellDimensions.height-2,Math.max(_-1,1),1),o.style.strikethrough&&this.mainContext.fillRect(l,s+this.cellDimensions.height*.55,Math.max(_-1,1),1),o.style.overline&&this.mainContext.fillRect(l,s+1,Math.max(_-1,1),1))}}drawCursor(e){const t=e.colors,s=e.cursor,r=this.lastCursor;if(this.cursorContext.clearRect(0,0,this.cols*this.cellDimensions.width,this.rows*this.cellDimensions.height),!s.visible||s.x===null||s.y===null){this.lastCursor=null,this.stopCursorBlink();return}const i=s.x*this.cellDimensions.width,o=s.y*this.cellDimensions.height,l=s.wideTail?this.cellDimensions.width*2:this.cellDimensions.width,u=t.cursor??t.foreground,a=this.toCss(u);this.cursorContext.fillStyle=a,this.cursorContext.strokeStyle=a,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:s.x,y:s.y,style:s.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("|"),s=this.fontCache.get(t);if(s)return s;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}`,s=this.colorCache.get(t);if(s)return s;const r=Mn(e);return this.colorCache.set(t,r),r}}const An=0,On={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},ct={Backquote:"`",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Comma:",",Equal:"=",Minus:"-",Period:".",Quote:"'",Semicolon:";",Slash:"/",Space:" ",IntlBackslash:"\\",IntlYen:"¥",IntlRo:"\\"};for(let n=0;n<=9;n+=1)ct[`Digit${n}`]=String(n);for(let n=0;n<26;n+=1){const e=String.fromCharCode(65+n),t=String.fromCharCode(97+n);ct[`Key${e}`]=t}function pt(n){return On[n]??An}function kn(n){const e=ct[n];return e?e.codePointAt(0)??null:null}const Ee=0,In=-2,Nn=1,Pn=2,Ln=3,Bn=10,Hn=11,Fn=12,Gn=13,Un=14,zn=15,Yn=16,Vn=17,Kn=1,$n=2,jn=1,Wn=2,qn=3,Xn=4,Jn=5,Qn=6,Zn=1,es=2,ts=3,ns=4;function dt(n){if(n.disposed||n.renderStateHandle===0)throw new Error("render state resources already disposed")}function ss(n){switch(n){case 2:return"full";case 1:return"partial";default:return"clean"}}function rs(n){switch(n){case 0:return"bar";case 2:return"underline";case 3:return"block-hollow";default:return"block"}}function is(n){switch(n){case 1:return"wide";case 2:return"spacer-tail";case 3:return"spacer-head";default:return"narrow"}}function Me(n,e){return{r:n.view().getUint8(e),g:n.view().getUint8(e+1),b:n.view().getUint8(e+2)}}function wt(n,e){const t=n.bindings.allocStruct("GhosttyColorRgb");try{const s=e(t.ptr);if(s===In)return null;if(s!==Ee)throw new Error(`ghostty optional color read failed with result ${s}`);return Me(n.bindings,t.ptr)}finally{t.free()}}function fe(n,e){const t=n.bindings.allocU8();try{const s=e(t);if(typeof s=="number"&&s!==Ee)throw new Error(`ghostty bool read failed with result ${s}`);return n.bindings.readU8(t)!==0}finally{n.bindings.freeU8(t)}}function Pe(n,e){const t=n.bindings.allocBytes(2);try{const s=e(t);if(typeof s=="number"&&s!==Ee)throw new Error(`ghostty u16 read failed with result ${s}`);return n.bindings.view().getUint16(t,!0)}finally{n.bindings.freeBytes(t,2)}}function os(n,e){const t=n.bindings.allocBytes(4);try{const s=e(t);if(typeof s=="number"&&s!==Ee)throw new Error(`ghostty u32 read failed with result ${s}`);return n.bindings.view().getUint32(t,!0)}finally{n.bindings.freeBytes(t,4)}}function st(n,e){const t=n.bindings.allocBytes(4);try{const s=e(t);if(typeof s=="number"&&s!==Ee)throw new Error(`ghostty enum read failed with result ${s}`);return n.bindings.view().getInt32(t,!0)}finally{n.bindings.freeBytes(t,4)}}function yt(n,e){const t=n.bindings.allocBytes(8);try{const s=e(t);if(typeof s=="number"&&s!==Ee)throw new Error(`ghostty u64 read failed with result ${s}`);return n.bindings.readU64(t)}finally{n.bindings.freeBytes(t,8)}}function ls(n){const e=n.bindings.allocStruct("GhosttyStyle");try{n.bindings.setField(e.view,"GhosttyStyle","size",n.bindings.typeSize("GhosttyStyle")),n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,Wn,e.ptr);const t=s=>n.bindings.field("GhosttyStyle",s).offset;return{bold:e.view.getUint8(t("bold"))!==0,italic:e.view.getUint8(t("italic"))!==0,faint:e.view.getUint8(t("faint"))!==0,blink:e.view.getUint8(t("blink"))!==0,inverse:e.view.getUint8(t("inverse"))!==0,invisible:e.view.getUint8(t("invisible"))!==0,strikethrough:e.view.getUint8(t("strikethrough"))!==0,overline:e.view.getUint8(t("overline"))!==0,underline:e.view.getInt32(t("underline"),!0)}}finally{e.free()}}function as(n){const e=os(n,s=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,qn,s));if(e===0)return[];const t=n.bindings.allocBytes(e*4);try{n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,Xn,t);const s=[];for(let r=0;r<e;r+=1)s.push(n.bindings.view().getUint32(t+r*4,!0));return s}finally{n.bindings.freeBytes(t,e*4)}}function cs(n){if(n.length===0)return"";try{return String.fromCodePoint(...n)}catch{return""}}function ds(n){let e="";for(const t of n)if(!(t.widthKind==="spacer-tail"||t.widthKind==="spacer-head")){if(t.text){e+=t.text;continue}t.widthKind==="narrow"&&(e+=" ")}return e}function us(n){const e=n.bindings.allocStruct("GhosttyRenderStateColors");try{n.bindings.setField(e.view,"GhosttyRenderStateColors","size",n.bindings.typeSize("GhosttyRenderStateColors")),n.bindings.getRenderStateColors(n.renderStateHandle,e.ptr);const t=n.bindings.field("GhosttyRenderStateColors","palette").offset,s=[];for(let o=0;o<256;o+=1){const l=e.ptr+t+o*3;s.push(Me(n.bindings,l))}const r=e.view.getUint8(n.bindings.field("GhosttyRenderStateColors","cursor_has_value").offset)!==0,i=fe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Un,o));return{cols:Pe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Nn,o)),rows:Pe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Pn,o)),dirty:ss(st(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Ln,o))),colors:{background:Me(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","background").offset),foreground:Me(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","foreground").offset),cursor:r?Me(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","cursor").offset):null,palette:s},cursor:{style:rs(st(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Bn,o))),visible:fe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Hn,o)),blinking:fe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Fn,o)),passwordInput:fe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Gn,o)),x:i?Pe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,zn,o)):null,y:i?Pe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Yn,o)):null,wideTail:i?fe(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Vn,o)):!1}}}finally{e.free()}}function hs(n,e){const t=yt(n,i=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,$n,i));n.bindings.bindRenderStateRowCells(n.rowIteratorHandle,n.rowCellsHandle);const s=[];let r=0;for(;n.bindings.nextRenderStateRowCell(n.rowCellsHandle);){const i=yt(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,jn,a)),o=as(n),l=is(st(n,a=>n.bindings.getRawCellValueResult(i,ts,a))),u={x:r,text:cs(o),codepoints:o,widthKind:l,hasText:fe(n,a=>n.bindings.getRawCellValueResult(i,ns,a)),style:ls(n),fgColor:wt(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Qn,a)),bgColor:wt(n,a=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Jn,a))};s.push(u),r+=1}return{y:e,dirty:fe(n,i=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,Kn,i)),wrap:fe(n,i=>n.bindings.getRawRowValueResult(t,Zn,i)),wrapContinuation:fe(n,i=>n.bindings.getRawRowValueResult(t,es,i)),text:ds(s),cells:s}}function gt(n){return{bindings:n,renderStateHandle:n.createRenderState(),rowIteratorHandle:n.createRenderStateRowIterator(),rowCellsHandle:n.createRenderStateRowCells(),snapshotVersion:0,disposed:!1,cachedMeta:null}}function St(n,e){dt(n),n.bindings.updateRenderState(n.renderStateHandle,e),n.bindings.bindRenderStateRowIterator(n.renderStateHandle,n.rowIteratorHandle),n.snapshotVersion+=1,n.cachedMeta=null}function rt(n){return dt(n),n.cachedMeta||(n.cachedMeta=us(n)),n.cachedMeta}function*fs(n){dt(n);const e=rt(n);n.bindings.bindRenderStateRowIterator(n.renderStateHandle,n.rowIteratorHandle);let t=0;for(;t<e.rows&&n.bindings.nextRenderStateRowIterator(n.rowIteratorHandle);)yield hs(n,t),t+=1}function Qe(n){n.disposed||(n.disposed=!0,n.rowCellsHandle!==0&&(n.bindings.freeRenderStateRowCells(n.rowCellsHandle),n.rowCellsHandle=0),n.rowIteratorHandle!==0&&(n.bindings.freeRenderStateRowIterator(n.rowIteratorHandle),n.rowIteratorHandle=0),n.renderStateHandle!==0&&(n.bindings.freeRenderState(n.renderStateHandle),n.renderStateHandle=0),n.cachedMeta=null)}function ut(n,e){return Math.max(0,Math.min(Math.max(n.length-1,0),Math.floor(e)))}function ms(n,e){return n.line<e.line?{start:n,end:e}:n.line>e.line?{start:e,end:n}:n.col<=e.col?{start:n,end:e}:{start:e,end:n}}function ps(n,e,t){if(!t)return{start:{line:n,col:0},end:{line:n,col:0}};const s=ut(t,e),r=u=>/[\p{L}\p{N}_-]/u.test(u),i=t[s]??"";if(!r(i))return{start:{line:n,col:s},end:{line:n,col:s}};let o=s,l=s;for(;o>0&&r(t[o-1]??"");)o-=1;for(;l+1<t.length&&r(t[l+1]??"");)l+=1;return{start:{line:n,col:o},end:{line:n,col:l}}}function kt(n,e){const t=Math.max(e.length-1,0);return{start:{line:n,col:0},end:{line:n,col:t}}}function It(n,e,t){const s=t(n.line);switch(e){case"word":return ps(n.line,n.col,s);case"line":return kt(n.line,s);default:{const r=ut(s,n.col);return{start:{line:n.line,col:r},end:{line:n.line,col:r}}}}}function Nt(){return{anchor:null,focus:null,mode:"character"}}function _t(n){return!!(n.anchor&&n.focus)}function ws(){return Nt()}function ys(n,e,t){const s=It(e,e.mode,t);return{anchor:s.start,focus:s.end,mode:e.mode}}function bt(n,e,t){return n.anchor?n.mode==="line"?{...n,focus:kt(e.line,t(e.line)).end}:n.mode==="word"?{...n,focus:It(e,"word",t).end}:{...n,focus:{line:e.line,col:ut(t(e.line),e.col)}}:n}function Pt(n){return!n.anchor||!n.focus?null:ms(n.anchor,n.focus)}function gs(n,e){const t=Pt(n);if(!t)return null;const s=[];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){s.push(i.slice(t.start.col,t.end.col+1));continue}if(r===t.start.line){s.push(i.slice(t.start.col));continue}if(r===t.end.line){s.push(i.slice(0,t.end.col+1));continue}s.push(i)}return s.join(`
32
+ `)}function Ss(n,e,t,s){const r=Pt(n);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 u=l-e;if(l===r.start.line&&l===r.end.line){o.push({row:u,x:r.start.col,width:r.end.col-r.start.col+1});continue}if(l===r.start.line){const _=s?Math.max(s(l).length-r.start.col,0):Number.MAX_SAFE_INTEGER;o.push({row:u,x:r.start.col,width:_});continue}if(l===r.end.line){o.push({row:u,x:0,width:r.end.col+1});continue}const a=s?s(l).length:Number.MAX_SAFE_INTEGER;o.push({row:u,x:0,width:a})}return o}function Lt(){var e;if(typeof navigator>"u")return!1;const n=((e=navigator.userAgentData)==null?void 0:e.platform)??navigator.platform??"";return/mac|iphone|ipad|ipod/iu.test(n)?!0:/mac os x/iu.test(navigator.userAgent??"")}function _s(n){return n.altKey?!1:!!(Lt()?n.metaKey:n.ctrlKey)}function bs(n){return _s(n)&&n.key.toLowerCase()==="c"}function xs(n){return n.shiftKey&&n.key==="Insert"&&!n.ctrlKey&&!n.altKey&&!n.metaKey?!0:n.altKey||n.key.toLowerCase()!=="v"?!1:!!(Lt()?n.metaKey:n.ctrlKey)}async function Bt(n){var t;if(!n)return;if(typeof navigator<"u"&&((t=navigator.clipboard)!=null&&t.writeText))try{await navigator.clipboard.writeText(n);return}catch{}if(typeof document>"u"||typeof document.execCommand!="function")throw new Error("clipboard unavailable");const e=document.createElement("textarea");e.value=n,e.setAttribute("readonly","true"),e.style.position="fixed",e.style.left="-9999px",e.style.top="0",document.body.appendChild(e);try{if(e.select(),!document.execCommand("copy"))throw new Error("execCommand copy failed")}finally{e.remove()}}async function Ts(n){n&&await Bt(n)}function Es(n,e){return!e||!n.clipboardData?!1:(n.clipboardData.setData("text/plain",e),n.preventDefault(),!0)}const Rs="/assets/ghostty-vt-BKQMf-5X.wasm",Ge=0,xt=-3,Cs=11,vs=12,Ms=13,Ds=14,As=1,Os=2,ks=9,Is=1,Ns=0,Ps=1,Ls=2,Bs=0,Hs=1,Fs=2,Gs=4,Us=2004,zs=9,Ys=1e3,Vs=1002,Ks=1003,$s=1005,Tt=1006,js=1015,Et=1016;let Ze=null;function O(n,e){if(n!==Ge)throw new Error(`${e} failed with result ${n}`)}function Ht(n){const e=n.trim().replace(/^#/,"");if(e.length!==6)throw new Error(`expected #RRGGBB color, received: ${n}`);return[Number.parseInt(e.slice(0,2),16),Number.parseInt(e.slice(2,4),16),Number.parseInt(e.slice(4,6),16)]}function Ws(n){const t=[...[n.black,n.red,n.green,n.yellow,n.blue,n.magenta,n.cyan,n.white,n.brightBlack,n.brightRed,n.brightGreen,n.brightYellow,n.brightBlue,n.brightMagenta,n.brightCyan,n.brightWhite].map(Ht)],s=[0,95,135,175,215,255];for(const r of s)for(const i of s)for(const o of s)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 qs(n){let e=0;return n&1&&(e+=4),n&4&&(e+=8),n&2&&(e+=16),e}function et(n){return n<0||n>223?null:String.fromCharCode(n+32)}function Xs(n){switch(n){case 1:return 0;case 3:return 1;case 2:return 2;case 4:return 64;case 5:return 65;case 6:return 66;case 7:return 67;case 8:return 128;case 9:return 129;case null:case void 0:return 3;default:return null}}function Ft(n){var t,s;let e=0;return n.shiftKey&&(e|=1),n.ctrlKey&&(e|=2),n.altKey&&(e|=4),n.metaKey&&(e|=8),(t=n.getModifierState)!=null&&t.call(n,"CapsLock")&&(e|=16),(s=n.getModifierState)!=null&&s.call(n,"NumLock")&&(e|=32),e}class Js{constructor(e,t,s){this.bindings=e,this.typeName=t,this.ptr=s}get view(){return this.bindings.view(this.ptr,this.bindings.typeSize(this.typeName))}free(){this.bindings.freeBytes(this.ptr,this.bindings.typeSize(this.typeName))}}class Qs{constructor(e,t){w(this,"exports");w(this,"layout");w(this,"decoder",new TextDecoder);w(this,"encoder",new TextEncoder);this.exports=e,this.layout=t}buffer(){return this.exports.memory.buffer}bytes(e=0,t=this.buffer().byteLength-e){return new Uint8Array(this.buffer(),e,t)}view(e=0,t=this.buffer().byteLength-e){return new DataView(this.buffer(),e,t)}typeSize(e){const t=this.layout[e];if(!t)throw new Error(`unknown ghostty type: ${e}`);return t.size}field(e,t){const s=this.layout[e],r=s==null?void 0:s.fields[t];if(!s||!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 Js(this,e,t)}allocBytes(e){return this.exports.ghostty_wasm_alloc_u8_array(e)}freeBytes(e,t){this.exports.ghostty_wasm_free_u8_array(e,t)}allocOpaque(){return this.exports.ghostty_wasm_alloc_opaque()}freeOpaque(e){this.exports.ghostty_wasm_free_opaque(e)}allocU8(){return this.exports.ghostty_wasm_alloc_u8()}freeU8(e){this.exports.ghostty_wasm_free_u8(e)}allocUsize(){return this.exports.ghostty_wasm_alloc_usize()}freeUsize(e){this.exports.ghostty_wasm_free_usize(e)}readPointer(e){return this.view().getUint32(e,!0)}readU8(e){return this.view().getUint8(e)}readUsize(e){return this.view().getUint32(e,!0)}readU64(e){return this.view().getBigUint64(e,!0)}setField(e,t,s,r){const i=this.field(t,s),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}.${s}: ${i.type}`)}}writeString(e){const t=this.encoder.encode(e),s=this.allocBytes(t.length);return this.bytes(s,t.length).set(t),{ptr:s,len:t.length,free:()=>this.freeBytes(s,t.length)}}writeBytes(e){const t=this.allocBytes(e.length);return this.bytes(t,e.length).set(e),{ptr:t,len:e.length,free:()=>this.freeBytes(t,e.length)}}readOwnedUtf8(e,t){return this.decoder.decode(this.bytes(e,t))}createTerminal(e,t,s){const 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",s);const i=this.allocOpaque();try{return O(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 s=typeof t=="string"?this.encoder.encode(t):t,r=this.writeBytes(s);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,s,r){O(this.exports.ghostty_terminal_resize(e,t,s,Math.max(1,Math.round(r.width)),Math.max(1,Math.round(r.height))),"ghostty_terminal_resize")}scrollViewportDelta(e,t){const s=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(s.view,"GhosttyTerminalScrollViewport","tag",Ls),s.view.setBigInt64(this.field("GhosttyTerminalScrollViewport","value").offset,BigInt(t),!0),this.exports.ghostty_terminal_scroll_viewport(e,s.ptr)}finally{s.free()}}scrollViewportTop(e){const t=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(t.view,"GhosttyTerminalScrollViewport","tag",Ns),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",Ps),this.exports.ghostty_terminal_scroll_viewport(e,t.ptr)}finally{t.free()}}setTerminalTheme(e,t){const s=this.allocStruct("GhosttyColorRgb"),r=this.allocStruct("GhosttyColorRgb"),i=this.allocStruct("GhosttyColorRgb"),o=Ws(t),l=this.allocBytes(o.length*3),u=(_,M)=>{const[A,N,T]=Ht(M);this.setField(_.view,"GhosttyColorRgb","r",A),this.setField(_.view,"GhosttyColorRgb","g",N),this.setField(_.view,"GhosttyColorRgb","b",T)};u(s,t.foreground),u(r,t.background),u(i,t.cursor);const a=this.bytes(l,o.length*3);o.forEach(([_,M,A],N)=>{const T=N*3;a[T]=_,a[T+1]=M,a[T+2]=A});try{O(this.exports.ghostty_terminal_set(e,Cs,s.ptr),"ghostty_terminal_set(foreground)"),O(this.exports.ghostty_terminal_set(e,vs,r.ptr),"ghostty_terminal_set(background)"),O(this.exports.ghostty_terminal_set(e,Ms,i.ptr),"ghostty_terminal_set(cursor)"),O(this.exports.ghostty_terminal_set(e,Ds,l),"ghostty_terminal_set(palette)")}finally{s.free(),r.free(),i.free(),this.freeBytes(l,o.length*3)}}readTerminalSize(e){const t=this.allocBytes(2),s=this.allocBytes(2);try{return O(this.exports.ghostty_terminal_get(e,As,t),"ghostty_terminal_get(cols)"),O(this.exports.ghostty_terminal_get(e,Os,s),"ghostty_terminal_get(rows)"),{cols:this.view().getUint16(t,!0),rows:this.view().getUint16(s,!0)}}finally{this.freeBytes(t,2),this.freeBytes(s,2)}}readScrollbar(e){const t=this.allocStruct("GhosttyTerminalScrollbar");try{return O(this.exports.ghostty_terminal_get(e,ks,t.ptr),"ghostty_terminal_get(scrollbar)"),{total:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","total").offset,!0)),offset:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","offset").offset,!0)),len:Number(t.view.getBigUint64(this.field("GhosttyTerminalScrollbar","len").offset,!0))}}finally{t.free()}}isTerminalModeEnabled(e,t){const s=this.allocU8();try{return O(this.exports.ghostty_terminal_mode_get(e,t,s),"ghostty_terminal_mode_get"),this.readU8(s)!==0}finally{this.freeU8(s)}}setTerminalMode(e,t,s){O(this.exports.ghostty_terminal_mode_set(e,t,s?1:0),"ghostty_terminal_mode_set")}createFormatter(e,t,s){const 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,u=this.view(r.ptr+i+l,this.typeSize("GhosttyFormatterScreenExtra")),a=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",s.unwrap),this.setField(r.view,"GhosttyFormatterTerminalOptions","trim",s.trim),this.setField(o,"GhosttyFormatterTerminalExtra","size",this.typeSize("GhosttyFormatterTerminalExtra")),this.setField(o,"GhosttyFormatterTerminalExtra","palette",s.includePalette),this.setField(u,"GhosttyFormatterScreenExtra","size",this.typeSize("GhosttyFormatterScreenExtra"));const _=this.field("GhosttyFormatterTerminalOptions","selection").offset;return r.view.setUint32(_,s.selectionPtr??0,!0),O(this.exports.ghostty_formatter_terminal_new(0,a,e,r.ptr),"ghostty_formatter_terminal_new"),this.readPointer(a)}finally{r.free(),this.freeOpaque(a)}}freeFormatter(e){this.exports.ghostty_formatter_free(e)}resolveViewportGridRef(e,t,s){const r=this.allocStruct("GhosttyPoint"),i=this.allocStruct("GhosttyGridRef");try{this.setField(r.view,"GhosttyPoint","tag",Is);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",s),this.exports.ghostty_terminal_grid_ref(e,r.ptr,i.ptr)!==Ge?(i.free(),null):i}finally{r.free()}}createViewportSelection(e,t,s){const r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(s)),o=this.resolveViewportGridRef(e,0,0);if(!o)return null;let l=null;for(let a=i-1;a>=0&&(l=this.resolveViewportGridRef(e,r-1,a),!l);a-=1);if(!l)return o.free(),null;const u=this.allocStruct("GhosttySelection");try{this.setField(u.view,"GhosttySelection","size",this.typeSize("GhosttySelection")),this.setField(u.view,"GhosttySelection","rectangle",!1);const a=this.field("GhosttySelection","start").offset,_=this.field("GhosttySelection","end").offset;return this.bytes(u.ptr+a,this.typeSize("GhosttyGridRef")).set(this.bytes(o.ptr,this.typeSize("GhosttyGridRef"))),this.bytes(u.ptr+_,this.typeSize("GhosttyGridRef")).set(this.bytes(l.ptr,this.typeSize("GhosttyGridRef"))),u}finally{o.free(),l.free()}}formatViewport(e,t,s,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,{...s,selectionPtr:(o==null?void 0:o.ptr)??null});try{return this.formatFormatter(l)}finally{this.freeFormatter(l),o==null||o.free()}}formatFormatter(e){const t=this.allocOpaque(),s=this.allocUsize();try{O(this.exports.ghostty_formatter_format_alloc(e,0,t,s),"ghostty_formatter_format_alloc");const r=this.readPointer(t),i=this.readUsize(s),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(s)}}createRenderState(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_new(0,e),"ghostty_render_state_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderState(e){this.exports.ghostty_render_state_free(e)}updateRenderState(e,t){O(this.exports.ghostty_render_state_update(e,t),"ghostty_render_state_update")}getRenderStateValueResult(e,t,s){return this.exports.ghostty_render_state_get(e,t,s)}getRenderStateValue(e,t,s){O(this.getRenderStateValueResult(e,t,s),"ghostty_render_state_get")}setRenderStateValue(e,t,s){O(this.exports.ghostty_render_state_set(e,t,s),"ghostty_render_state_set")}getRenderStateColors(e,t){O(this.exports.ghostty_render_state_colors_get(e,t),"ghostty_render_state_colors_get")}createRenderStateRowIterator(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_row_iterator_new(0,e),"ghostty_render_state_row_iterator_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowIterator(e){this.exports.ghostty_render_state_row_iterator_free(e)}bindRenderStateRowIterator(e,t){const s=this.allocOpaque();try{this.view(s,4).setUint32(0,t,!0),this.getRenderStateValue(e,4,s)}finally{this.freeOpaque(s)}}nextRenderStateRowIterator(e){return this.exports.ghostty_render_state_row_iterator_next(e)!==0}getRenderStateRowValueResult(e,t,s){return this.exports.ghostty_render_state_row_get(e,t,s)}getRenderStateRowValue(e,t,s){O(this.getRenderStateRowValueResult(e,t,s),"ghostty_render_state_row_get")}setRenderStateRowValue(e,t,s){O(this.exports.ghostty_render_state_row_set(e,t,s),"ghostty_render_state_row_set")}createRenderStateRowCells(){const e=this.allocOpaque();try{return O(this.exports.ghostty_render_state_row_cells_new(0,e),"ghostty_render_state_row_cells_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowCells(e){this.exports.ghostty_render_state_row_cells_free(e)}bindRenderStateRowCells(e,t){const s=this.allocOpaque();try{this.view(s,4).setUint32(0,t,!0),this.getRenderStateRowValue(e,3,s)}finally{this.freeOpaque(s)}}nextRenderStateRowCell(e){return this.exports.ghostty_render_state_row_cells_next(e)!==0}selectRenderStateRowCell(e,t){O(this.exports.ghostty_render_state_row_cells_select(e,t),"ghostty_render_state_row_cells_select")}getRenderStateRowCellValueResult(e,t,s){return this.exports.ghostty_render_state_row_cells_get(e,t,s)}getRenderStateRowCellValue(e,t,s){O(this.getRenderStateRowCellValueResult(e,t,s),"ghostty_render_state_row_cells_get")}getRawRowValueResult(e,t,s){return this.exports.ghostty_row_get(e,t,s)}getRawRowValue(e,t,s){O(this.getRawRowValueResult(e,t,s),"ghostty_row_get")}getRawCellValueResult(e,t,s){return this.exports.ghostty_cell_get(e,t,s)}getRawCellValue(e,t,s){O(this.getRawCellValueResult(e,t,s),"ghostty_cell_get")}createKeyEncoder(){const e=this.allocOpaque();try{return O(this.exports.ghostty_key_encoder_new(0,e),"ghostty_key_encoder_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeKeyEncoder(e){this.exports.ghostty_key_encoder_free(e)}createMouseEncoder(){const e=this.allocOpaque(),t=this.allocU8();try{O(this.exports.ghostty_mouse_encoder_new(0,e),"ghostty_mouse_encoder_new");const s=this.readPointer(e);return this.view().setUint8(t,1),this.exports.ghostty_mouse_encoder_setopt(s,Gs,t),s}finally{this.freeU8(t),this.freeOpaque(e)}}freeMouseEncoder(e){this.exports.ghostty_mouse_encoder_free(e)}resetMouseEncoder(e){this.exports.ghostty_mouse_encoder_reset(e)}encodeMouseEvent(e,t,s){const r=this.isTerminalModeEnabled(t,Ks),i=this.isTerminalModeEnabled(t,Vs),o=this.isTerminalModeEnabled(t,Ys),l=this.isTerminalModeEnabled(t,zs);if(!r&&!i&&!o&&!l||s.action==="motion"&&!(r||i&&s.anyButtonPressed)||l&&s.action!=="press"||!r&&!i&&!l&&s.action==="motion")return null;const u=Xs(s.button);if(u===null)return null;const a=Math.max(1,Math.floor(s.x/Math.max(1,s.cellWidth))+1),_=Math.max(1,Math.floor(s.y/Math.max(1,s.cellHeight))+1),M=Math.round(s.x+1),A=Math.round(s.y+1);let N=s.action==="release"&&!this.isTerminalModeEnabled(t,Tt)&&!this.isTerminalModeEnabled(t,Et)?3:u;if(s.action==="motion"&&(N+=32),N+=qs(s.mods),this.isTerminalModeEnabled(t,Et)){const T=s.action==="release"?"m":"M";return`\x1B[<${N};${M};${A}${T}`}if(this.isTerminalModeEnabled(t,Tt)){const T=s.action==="release"?"m":"M";return`\x1B[<${N};${a};${_}${T}`}if(this.isTerminalModeEnabled(t,js))return`\x1B[${N};${a};${_}M`;if(this.isTerminalModeEnabled(t,$s)||o||i||r||l){const T=et(N),b=et(a),q=et(_);return!T||!b||!q?null:`\x1B[M${T}${b}${q}`}return null}encodeKeyEvent(e,t,s){if(s.keyCode<=0)return null;const r=this.allocOpaque();let i=0,o=null;try{return O(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,s.action==="release"?Bs:s.action==="repeat"?Fs:Hs),this.exports.ghostty_key_event_set_key(i,s.keyCode),this.exports.ghostty_key_event_set_mods(i,s.mods),this.exports.ghostty_key_event_set_consumed_mods(i,0),this.exports.ghostty_key_event_set_composing(i,s.composing?1:0),s.utf8&&(o=this.writeString(s.utf8),this.exports.ghostty_key_event_set_utf8(i,o.ptr,o.len)),typeof s.unshiftedCodepoint=="number"&&this.exports.ghostty_key_event_set_unshifted_codepoint(i,s.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 s=this.allocUsize();try{const r=this.exports.ghostty_key_encoder_encode(e,t,0,0,s);r!==xt&&r!==Ge&&O(r,"ghostty_key_encoder_encode(size)");const i=Math.max(0,this.readUsize(s));if(i===0)return null;const o=this.allocBytes(i),l=this.allocUsize();try{O(this.exports.ghostty_key_encoder_encode(e,t,o,i,l),"ghostty_key_encoder_encode");const u=this.readUsize(l);return u===0?null:this.readOwnedUtf8(o,u)}finally{this.freeBytes(o,i),this.freeUsize(l)}}finally{this.freeUsize(s)}}encodePaste(e,t){const s=this.writeString(t),r=this.allocUsize();try{const i=this.isTerminalModeEnabled(e,Us),o=this.exports.ghostty_paste_encode(s.ptr,s.len,i?1:0,0,0,r);o!==xt&&o!==Ge&&O(o,"ghostty_paste_encode(size)");const l=Math.max(0,this.readUsize(r));if(l===0)return"";const u=this.allocBytes(l),a=this.allocUsize();try{return O(this.exports.ghostty_paste_encode(s.ptr,s.len,i?1:0,u,l,a),"ghostty_paste_encode"),this.readOwnedUtf8(u,this.readUsize(a))}finally{this.freeBytes(u,l),this.freeUsize(a)}}finally{s.free(),this.freeUsize(r)}}}async function Zs(n){if((n.startsWith("/")||n.startsWith("./")||n.startsWith("../")||/^[A-Za-z]:[\\/]/.test(n))&&typeof Bun<"u")return Bun.file(n).arrayBuffer();const t=await fetch(n);if(!t.ok)throw new Error(`failed to load ghostty wasm: ${t.status} ${t.statusText}`);return t.arrayBuffer()}async function er(){return Ze||(Ze=(async()=>{const n=await Zs(Rs),t=(await WebAssembly.instantiate(n,{env:{log(){}}})).instance.exports,s=new Uint8Array(t.memory.buffer),r=t.ghostty_type_json();let i=r;for(;s[i]!==0;)i+=1;const o=JSON.parse(new TextDecoder().decode(s.subarray(r,i)));return new Qs(t,o)})()),Ze}const Rt=80,De=24,tt=9,Le=17,tr=48,Gt="ghostty-official",Ue=9,ze=1e3,Ye=1002,Ve=1003,nt=1007,Be=1047,He=1049,nr=[Ue,ze,Ye,Ve],Ct=1,vt=3,Mt=2,sr=4,rr=5;class ir{constructor(e){this.content=e}translateToString(e){return e?this.content.replace(/\s+$/u,""):this.content}}class or{constructor(){w(this,"active",{baseY:0,viewportY:0,length:De,getLine:e=>{const t=e-this.active.viewportY,s=this.visibleLines[t];return typeof s=="string"?new ir(s):null}});w(this,"visibleLines",Array.from({length:De},()=>""))}setViewport(e,t,s,r){this.active.viewportY=e,this.active.baseY=t,this.active.length=s,this.visibleLines=r}}function lr(n){return!(n.key.length===1&&!n.ctrlKey&&!n.altKey&&!n.metaKey)}function ar(n,e){const t=n.slice(0,e).map(s=>s.text);for(;t.length<e;)t.push("");return t}function Fe(n){return Ft({shiftKey:!!n.shiftKey,ctrlKey:!!n.ctrlKey,altKey:!!n.altKey,metaKey:!!n.metaKey,getModifierState:()=>!1})}class cr{constructor(){w(this,"terminal",null)}activate(e){this.terminal=e instanceof $e?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 $e{constructor(e,t,s,r,i,o){w(this,"buffer",new or);w(this,"_core",{_renderService:{dimensions:{css:{cell:{width:tt,height:Le}}}}});w(this,"options");w(this,"element",null);w(this,"textarea",null);w(this,"cols",Rt);w(this,"rows",De);w(this,"bindings");w(this,"terminalHandle");w(this,"keyEncoderHandle");w(this,"mouseEncoderHandle");w(this,"renderState");w(this,"dataListeners",new Set);w(this,"selectionListeners",new Set);w(this,"lastNotifiedSelectionText",null);w(this,"addons",new Set);w(this,"screenElement",null);w(this,"renderer",null);w(this,"renderRaf",null);w(this,"disposed",!1);w(this,"disableStdin");w(this,"customKeyEventHandler",()=>!0);w(this,"imeIsComposing",!1);w(this,"lastCompositionCommit",null);w(this,"selectionState",Nt());w(this,"lineCache",new Map);w(this,"lastViewportOffset",0);w(this,"lastViewportRows",De);w(this,"lastRenderedRows",[]);w(this,"pointerDrag",{active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null});w(this,"autoScrollTimer",null);w(this,"domEventDisposers",[]);w(this,"copyShortcutSuppressed",!1);w(this,"scrollbarThumb",null);w(this,"scrollbarFadeTimer",null);w(this,"pressedMouseButtons",new Set);w(this,"wheelPixelDelta",0);w(this,"mouseDragActive",!1);this.bindings=e,this.terminalHandle=t,this.keyEncoderHandle=s,this.mouseEncoderHandle=r,this.renderState=i,this.options=o,this.disableStdin=!!o.disableStdin}static async create(e){const t=await er(),s=t.createTerminal(Rt,De,e.scrollback);let r=0,i=0,o=null;try{return t.setTerminalTheme(s,e.theme),r=t.createKeyEncoder(),i=t.createMouseEncoder(),o=gt(t),new $e(t,s,r,i,o,e)}catch(l){throw o&&Qe(o),r!==0&&t.freeKeyEncoder(r),i!==0&&t.freeMouseEncoder(i),t.freeTerminal(s),l}}open(e){if(this.disposed||this.element)return;const t=document.createElement("div");t.className="xterm",t.style.position="absolute",t.style.inset="0",t.style.overflow="hidden",t.style.width="100%",t.style.height="100%",t.style.backgroundColor=this.options.theme.background,t.style.color=this.options.theme.foreground,t.style.fontFamily=this.options.fontFamily,t.style.fontSize=`${this.options.fontSize}px`,t.style.lineHeight="1.2";const s=document.createElement("div");s.className="xterm-viewport",s.style.width="100%",s.style.height="100%",s.style.overflow="hidden",s.style.position="relative";const 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),s.appendChild(r),t.appendChild(s),t.appendChild(i),t.appendChild(o),e.appendChild(t),this.element=t,this.screenElement=r,this.textarea=i,this.scrollbarThumb=l,this.renderer=new Dn({screenElement:r,theme:this.options.theme,fontFamily:this.options.fontFamily,fontSize:this.options.fontSize}),this.syncInputState(),this.bindDomEvents(),this.updateCellDimensions();const u=this.measureSizeFromElement();u?this.resize(u.cols,u.rows):this.render()}loadAddon(e){e.activate(this),this.addons.add(e)}onData(e){return this.dataListeners.add(e),{dispose:()=>{this.dataListeners.delete(e)}}}attachCustomKeyEventHandler(e){this.customKeyEventHandler=e}onSelectionChange(e){return this.selectionListeners.add(e),{dispose:()=>{this.selectionListeners.delete(e)}}}hasSelection(){return _t(this.selectionState)}getSelection(){return this.getSelectionText()??""}clearSelection(){this.disposed||this.clearSelectionState()}startTouchSelection(e,t,s="word"){return this.disposed?!1:this.beginSelectionAt(e,t,s)}updateTouchSelection(e,t){this.disposed||this.updateSelectionDrag(e,t)}endTouchSelection(){this.disposed||!this.pointerDrag.active||(this.stopAutoScroll(),this.pointerDrag.active=!1,this.render())}write(e){if(this.disposed)return;const t=this.isAltScreenActive();this.bindings.writeVt(this.terminalHandle,e);const s=this.isAltScreenActive();t&&!s&&this.clearMouseTrackingModes(),this.scheduleRender()}clearMouseTrackingModes(){if(!this.disposed){for(const e of nr)this.bindings.setTerminalMode(this.terminalHandle,e,!1);this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.pressedMouseButtons.clear(),this.mouseDragActive=!1}}isAltScreenActive(){return this.isModeEnabled(Be)||this.isModeEnabled(He)}reset(){this.disposed||(this.lineCache.clear(),this.clearSelectionState(!1),this.bindings.resetTerminal(this.terminalHandle),this.scheduleRender())}refresh(){this.disposed||this.render()}resize(e,t){if(this.disposed)return;const s=Math.max(2,Math.floor(e)),r=Math.max(2,Math.floor(t));this.cols=s,this.rows=r,this.clearSelectionState(!1),this.bindings.resizeTerminal(this.terminalHandle,s,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(Ue),mouseNormal:this.isModeEnabled(ze),mouseButton:this.isModeEnabled(Ye),mouseAny:this.isModeEnabled(Ve),mouseUtf8:this.isModeEnabled(1005),mouseSgr:this.isModeEnabled(1006),mouseSgrPixels:this.isModeEnabled(1016),mouseUrxvt:this.isModeEnabled(1015),altScroll:this.isModeEnabled(nt),altScreen1047:this.isModeEnabled(Be),altScreen1049:this.isModeEnabled(He)}}restoreModeSnapshot(e){this.bindings.setTerminalMode(this.terminalHandle,Ue,e.mouseX10),this.bindings.setTerminalMode(this.terminalHandle,ze,e.mouseNormal),this.bindings.setTerminalMode(this.terminalHandle,Ye,e.mouseButton),this.bindings.setTerminalMode(this.terminalHandle,Ve,e.mouseAny),this.bindings.setTerminalMode(this.terminalHandle,1005,e.mouseUtf8),this.bindings.setTerminalMode(this.terminalHandle,1006,e.mouseSgr),this.bindings.setTerminalMode(this.terminalHandle,1016,e.mouseSgrPixels),this.bindings.setTerminalMode(this.terminalHandle,1015,e.mouseUrxvt),this.bindings.setTerminalMode(this.terminalHandle,nt,e.altScroll),this.bindings.setTerminalMode(this.terminalHandle,Be,e.altScreen1047),this.bindings.setTerminalMode(this.terminalHandle,He,e.altScreen1049),this.bindings.resetMouseEncoder(this.mouseEncoderHandle)}handleViewportGesture(e){if(this.disposed||e.deltaY===0)return!1;const t=this.gestureToLines(e);if(t===0)return!1;const s=this.getInputRoutingState();if(s.mouseReporting){const r=t<0?sr:rr;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:Fe(e),anyButtonPressed:this.pressedMouseButtons.size>0})||i;return i}return s.altScroll?this.emitAltScrollInput(t):(this.scrollLines(t),!0)}paste(e){if(this.disposed||this.disableStdin||!e)return;const t=this.bindings.encodePaste(this.terminalHandle,e);t&&this.emitData(t)}focus(){var e;(e=this.textarea)==null||e.focus({preventScroll:!0})}getRendererKind(){var e;return((e=this.renderer)==null?void 0:e.kind)??"unknown"}setTheme(e){var t;this.bindings.setTerminalTheme(this.terminalHandle,e),this.options.theme=e,this.element&&(this.element.style.backgroundColor=e.background,this.element.style.color=e.foreground),this.screenElement&&(this.screenElement.style.backgroundColor=e.background),(t=this.renderer)==null||t.setTheme(e),this.scheduleRender()}setDisableStdin(e){this.disableStdin=e,this.syncInputState()}measureSizeFromElement(){const e=this.element;if(!e)return null;const t=e.getBoundingClientRect(),{width:s,height:r}=this.cellDimensions();return t.width===0||t.height===0||s<=0||r<=0?null:{cols:Math.max(2,Math.floor(t.width/s)),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 s of this.addons)s.dispose();this.addons.clear(),(e=this.renderer)==null||e.dispose(),this.renderer=null,(t=this.element)==null||t.remove(),this.element=null,this.screenElement=null,this.textarea=null,this.scrollbarThumb=null,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:Fe(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:Fe(l),anyButtonPressed:this.pressedMouseButtons.size>0||l.buttons>0});return}this.updatePointerSelection(l)}},o=l=>{if(this.mouseDragActive){if(this.mouseDragActive=!1,this.getInputRoutingState().mouseReporting){const u=this.mouseButtonFromEvent(l);u!==null&&this.pressedMouseButtons.delete(u),this.emitMouseInput({action:"release",button:u,clientX:l.clientX,clientY:l.clientY,mods:Fe(l),anyButtonPressed:this.pressedMouseButtons.size>0});return}this.finishPointerSelection(l)}};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&&bs(i)){i.preventDefault(),Ts(o).catch(()=>{}),this.clearSelectionState(),this.copyShortcutSuppressed=!0,this.clearTextarea();return}if(!this.customKeyEventHandler(i)||this.disableStdin||this.imeIsComposing||i.keyCode===229||xs(i)||!lr(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&&Es(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 s=pt(e.code);if(s===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:s,mods:Ft(e),composing:e.isComposing,utf8:r,unshiftedCodepoint:kn(e.code)})}getInputRoutingState(){const e=this.isModeEnabled(Ue)||this.isModeEnabled(ze)||this.isModeEnabled(Ye)||this.isModeEnabled(Ve),t=this.isModeEnabled(Be)||this.isModeEnabled(He);return{mouseReporting:e,altScroll:!e&&t&&this.isModeEnabled(nt)}}gestureToLines(e){const t=this.cellDimensions().height||Le;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 s=this.wheelPixelDelta>0?Math.floor(this.wheelPixelDelta/t):Math.ceil(this.wheelPixelDelta/t);return s!==0&&(this.wheelPixelDelta-=s*t),s}return e.deltaY>0?Math.ceil(e.deltaY/t):Math.floor(e.deltaY/t)}isModeEnabled(e){return this.bindings.isTerminalModeEnabled(this.terminalHandle,e)}mouseButtonFromEvent(e){switch(e.button){case 0:return Ct;case 1:return vt;case 2:return Mt;default:return null}}mouseButtonFromButtons(e){return e&1?Ct:e&4?vt:e&2?Mt:null}pointerPositionFromClient(e,t){var o;const s=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!s)return null;const r=Math.max(1,s.width),i=Math.max(1,s.height);return{x:Math.max(0,Math.min(r-1,e-s.left)),y:Math.max(0,Math.min(i-1,t-s.top))}}emitMouseInput(e){var o;if(this.disableStdin)return!1;const t=this.pointerPositionFromClient(e.clientX,e.clientY);if(!t)return!1;const s=this.cellDimensions(),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(s.width||tt)),cellHeight:Math.max(1,Math.round(s.height||Le))});return i?(this.emitData(i),!0):!1}emitAltScrollInput(e){const t=pt(e<0?"ArrowUp":"ArrowDown");if(t===0)return!1;let s=!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),s=!0)}return s}emitData(e){for(const t of this.dataListeners)t(e)}clearTextarea(){this.textarea&&(this.textarea.textContent="")}syncTextareaPositionToCursor(){const e=this.textarea,t=this.screenElement;if(!e||!t)return;const{width:s,height:r}=this.cellDimensions();if(s<=0||r<=0)return;const i=gt(this.bindings);let o=0,l=0;try{St(i,this.terminalHandle);const _=rt(i);_.cursor.x!==null&&_.cursor.y!==null&&(o=_.cursor.x,l=_.cursor.y)}finally{Qe(i)}const u=o*s,a=l*r;e.style.left=`${u}px`,e.style.top=`${a}px`,e.style.width=`${Math.max(1,s)}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);St(this.renderState,this.terminalHandle);const s=rt(this.renderState),r=Array.from(fs(this.renderState));this.cols=Math.max(2,s.cols),this.rows=Math.max(2,s.rows||t),this.lastViewportOffset=e.offset,this.lastViewportRows=this.rows,this.lastRenderedRows=r;for(const a of r)this.lineCache.set(e.offset+a.y,a.text);const i=Ss(this.selectionState,this.lastViewportOffset,this.lastViewportRows,a=>this.getLineText(a)),o=this.getSelectionText();this.renderer.render({meta:s,rows:r,cellDimensions:this.cellDimensions(),selectionRects:i,selectionColor:this.options.theme.selectionBackground});const l=ar(r,this.rows),u=Math.max(0,e.total-e.len);this.buffer.setViewport(e.offset,u,e.total,l),this.updateSelectionTextProbe(o),this.updateScrollbar(e)}updateScrollbar(e){var u;const t=this.scrollbarThumb;if(!t)return;const s=((u=this.screenElement)==null?void 0:u.clientHeight)??0;if(s===0||e.total<=e.len){t.style.opacity="0";return}const r=e.len/e.total,i=Math.max(20,r*s),l=e.offset/Math.max(1,e.total-e.len)*(s-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:tt,this._core._renderService.dimensions.css.cell.height=t.height>0?t.height:Le}clearSelectionState(e=!0){this.selectionState=ws(),this.pressedMouseButtons.clear(),this.wheelPixelDelta=0,this.pointerDrag={active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null},this.copyShortcutSuppressed=!1,this.stopAutoScroll(),this.updateSelectionTextProbe(null),e&&this.screenElement&&this.renderer&&this.render()}beginSelectionAt(e,t,s){const r=this.hitTest(e,t);return r?(this.pointerDrag={active:!0,moved:!1,mode:s,lastClientX:e,lastClientY:t},this.selectionState=ys(this.selectionState,{...r,mode:s},i=>this.getLineText(i)),this.updateAutoScroll(),this.render(),!0):!1}updateSelectionDrag(e,t){if(!this.pointerDrag.active)return;const s=this.hitTest(e,t);this.pointerDrag.lastClientX=e,this.pointerDrag.lastClientY=t,s&&(this.pointerDrag.moved=!0,this.selectionState=bt(this.selectionState,s,r=>this.getLineText(r)),this.render()),this.updateAutoScroll()}beginPointerSelection(e){this.beginSelectionAt(e.clientX,e.clientY,this.selectionModeFromClickDetail(e.detail))}updatePointerSelection(e){this.updateSelectionDrag(e.clientX,e.clientY)}finishPointerSelection(e){var s,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&&((s=this.selectionState.anchor)==null?void 0:s.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 A;const s=(A=this.screenElement)==null?void 0:A.getBoundingClientRect();if(!s)return null;const{width:r,height:i}=this.cellDimensions();if(r<=0||i<=0)return null;const o=e-s.left,l=t-s.top,u=Math.max(this.cols-1,0),a=Math.max(this.lastViewportRows-1,0),_=Math.max(0,Math.min(u,Math.floor(o/r))),M=Math.max(0,Math.min(a,Math.floor(l/i)));return{line:this.lastViewportOffset+M,col:_}}getLineText(e){const t=this.lineCache.get(e);if(typeof t=="string")return t;const s=e-this.lastViewportOffset,r=this.lastRenderedRows[s];return(r==null?void 0:r.text)??""}getSelectionText(){return _t(this.selectionState)?gs(this.selectionState,e=>this.getLineText(e)):null}updateSelectionTextProbe(e){if(globalThis.__tmexE2eTerminalSelectionText=e,e!==this.lastNotifiedSelectionText){this.lastNotifiedSelectionText=e;for(const t of this.selectionListeners)t(e)}}updateAutoScroll(){var s;if(!this.pointerDrag.active||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(s=this.screenElement)==null?void 0:s.getBoundingClientRect();if(!e){this.stopAutoScroll();return}if(!(this.pointerDrag.lastClientY<e.top||this.pointerDrag.lastClientY>e.bottom)){this.stopAutoScroll();return}this.autoScrollTimer===null&&(this.autoScrollTimer=setInterval(()=>{this.stepAutoScroll()},tr))}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 s=this.hitTest(this.pointerDrag.lastClientX,this.pointerDrag.lastClientY);s&&(this.selectionState=bt(this.selectionState,s,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 dr(n){return $e.create(n)}function ur({visible:n,canPaste:e,onCopy:t,onPaste:s,onDismiss:r}){const{t:i}=Ke();if(!n)return null;const o=l=>{l.preventDefault()};return h.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[h.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:o,onClick:t,"data-testid":"terminal-selection-copy",children:[h.jsx(bn,{className:"h-4 w-4"}),i("terminal.copy")]}),e&&h.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:o,onClick:s,"data-testid":"terminal-selection-paste",children:[h.jsx(Sn,{className:"h-4 w-4"}),i("terminal.paste")]}),h.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:o,onClick:r,"aria-label":i("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:h.jsx(nn,{className:"h-4 w-4"})})]})}function Ut(n){if(!n)return n;const e=n.replace(/\r\n/g,`
33
+ `);return(e.endsWith(`
34
+ `)?e.slice(0,-1):e).replace(/\n/g,`\r
35
+ `)}const hr="\x1B[?1049h\x1B[H\x1B[2J";function fr(n){return hr+Ut(n)}function Dt(n,e){let t=e,s=0;for(const l of n)l===10&&!t&&(s+=1),t=l===13;const r=t;if(s===0)return{normalized:n,endedWithCR:r};const i=new Uint8Array(n.length+s);let o=0;t=e;for(const l of n)l===10&&!t&&(i[o]=13,o+=1),i[o]=l,o+=1,t=l===13;return{normalized:i,endedWithCR:r}}const zt={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"},Yt={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"},mr='"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',pr=1.3,wr=36,yr=500,gr=12;function Sr(n,e){const t=d.useRef(!1);return d.useEffect(()=>{const s=n.current;if(!s||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;t.current=!0;let i=0,o=null,l=!1,u=0,a=0,_=0,M=null,A=!1;const N=()=>{M!==null&&(clearTimeout(M),M=null)},T=S=>S?!!(S.closest(".scrollbar")||S.closest(".slider")||S.closest(".xterm-scroll-area")):!1,b=(S,E,P)=>{const U=P instanceof Element?P:null;if(T(U))return!0;const K=document.elementFromPoint(S,E);if(T(K))return!0;const x=s.querySelector(".xterm");if(!(x instanceof HTMLElement))return!1;const R=x.getBoundingClientRect(),H=S>=R.left&&S<=R.right,L=E>=R.top&&E<=R.bottom;return!H||!L?!1:S>=R.right-wr},q=()=>[s.querySelector(".xterm-viewport"),s.querySelector(".xterm-scrollable-element")].filter(E=>E instanceof HTMLElement),g=S=>{if(o===null)return null;for(let E=0;E<S.length;E+=1){const P=S.item(E);if(P&&P.identifier===o)return P}return null},G=S=>{if(N(),S.touches.length!==1)return;const E=S.touches.item(0);E&&(o=E.identifier,i=E.clientY,u=0,l=b(E.clientX,E.clientY,S.target),a=E.clientX,_=E.clientY,A=!1,l||(M=setTimeout(()=>{var U;M=null;const P=(e==null?void 0:e())??null;(U=P==null?void 0:P.startTouchSelection)!=null&&U.call(P,a,_,"word")&&(A=!0)},yr)))},D=S=>{var H,L,k,z,I,ne,se,oe,re;const E=g(S.touches)??S.touches.item(0);if(!E)return;if(A){const W=(e==null?void 0:e())??null;(H=W==null?void 0:W.updateTouchSelection)==null||H.call(W,E.clientX,E.clientY),S.cancelable&&S.preventDefault();return}if(M!==null&&Math.hypot(E.clientX-a,E.clientY-_)>gr&&N(),l||(l=b(E.clientX,E.clientY,S.target),l&&(u=0)),l)return;const P=E.clientY,U=i-P;if(i=P,U===0)return;let K=!1,x=!1;const R=(e==null?void 0:e())??null;if(R){const W=R==null?void 0:R._core,Y=((I=(z=(k=(L=W==null?void 0:W._renderService)==null?void 0:L.dimensions)==null?void 0:k.css)==null?void 0:z.cell)==null?void 0:I.height)??18;u+=U*pr;const X=u>0?Math.floor(u/Y):Math.ceil(u/Y);if(typeof R.handleViewportGesture=="function")X!==0&&(K=R.handleViewportGesture({source:"touch",deltaY:X*Y,clientX:E.clientX,clientY:E.clientY}),u-=X*Y);else if(X!==0){const J=((se=(ne=R.buffer)==null?void 0:ne.active)==null?void 0:se.viewportY)??0;R.scrollLines(X);const y=((re=(oe=R.buffer)==null?void 0:oe.active)==null?void 0:re.viewportY)??0;K=J!==y,x=X<0&&J<=0&&y<=0,u-=X*Y}}else{const W=q();if(W.length===0)return;for(const Y of W){const X=Y.scrollTop;Y.scrollTop+=U;const J=Y.scrollTop;Math.abs(J-X)>0&&(K=!0),U<0&&J<=0&&(x=!0)}if(!K){const Y=s.querySelector(".xterm");if(Y instanceof HTMLElement){const X=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:U}),J=Y.dispatchEvent(X);K=X.defaultPrevented||!J}}}S.cancelable&&(K||x)&&S.preventDefault()},j=S=>{var P;if(N(),!(o===null||!g(S.changedTouches))&&(o=null,u=0,l=!1,A)){A=!1;const U=(e==null?void 0:e())??null;(P=U==null?void 0:U.endTouchSelection)==null||P.call(U)}},V=S=>{A&&S.preventDefault()};return s.addEventListener("touchstart",G,{passive:!0}),s.addEventListener("touchmove",D,{passive:!1}),s.addEventListener("touchend",j,{passive:!0}),s.addEventListener("touchcancel",j,{passive:!0}),s.addEventListener("contextmenu",V),()=>{t.current=!1,N(),s.removeEventListener("touchstart",G),s.removeEventListener("touchmove",D),s.removeEventListener("touchend",j),s.removeEventListener("touchcancel",j),s.removeEventListener("contextmenu",V)}},[n,e]),t}function _r({now:n,remoteSize:e,pendingLocalSize:t,ttlMs:s=2e3}){return!t||n-t.at>s?!0:t.cols===e.cols&&t.rows===e.rows}function br({currentSize:n,containerSize:e,force:t=!1}){return t?!0:n.cols!==e.cols||n.rows!==e.rows}function xr({deviceId:n,paneId:e,deviceConnected:t,isSelectionInvalid:s,onResize:r,onSync:i,getContainerRect:o}){const l=d.useRef(null),u=d.useRef(null),a=d.useRef(null),_=d.useRef(null),M=d.useRef(0),A=d.useRef([]),N=d.useRef(null),T=d.useRef(null),b=d.useRef(o),q=d.useRef(!1),g=d.useRef(r),G=d.useRef(i);d.useEffect(()=>{g.current=r},[r]),d.useEffect(()=>{G.current=i},[i]),d.useEffect(()=>{b.current=o},[o]);const D=d.useCallback(()=>{var ne,se,oe,re,W,Y,X,J,y,f;const x=T.current,R=N.current;if(!x||!R||!x.element)return null;let H;try{const C=R.proposeDimensions();if(!C)throw new Error("fitAddon.proposeDimensions() returned null");H=Math.max(2,C.cols)}catch{const C=x._core,B=((re=(oe=(se=(ne=C==null?void 0:C._renderService)==null?void 0:ne.dimensions)==null?void 0:se.css)==null?void 0:oe.cell)==null?void 0:re.width)??9,F=(W=b.current)==null?void 0:W.call(b);if(!F||F.width===0)return null;H=Math.max(2,Math.floor(F.width/B))}const L=(Y=b.current)==null?void 0:Y.call(b);if(!L||L.height===0)return null;const k=x._core,z=((f=(y=(J=(X=k==null?void 0:k._renderService)==null?void 0:X.dimensions)==null?void 0:J.css)==null?void 0:y.cell)==null?void 0:f.height)??17,I=Math.max(2,Math.floor(L.height/z));return{cols:H,rows:I}},[]),j=d.useCallback((x,R)=>{const H=T.current;H&&(H.cols===x&&H.rows===R||H.resize(x,R))},[]),V=d.useCallback((x,R=!1)=>{if(!n||!e||!t||s&&x!=="sync"||!R&&Date.now()<M.current||!T.current)return!1;const L=D();if(!L)return!1;const{cols:k,rows:z}=L,I=a.current;return!R&&I&&I.cols===k&&I.rows===z?(j(k,z),!0):(j(k,z),x==="sync"?G.current(k,z):g.current(k,z),a.current={cols:k,rows:z},_.current={cols:k,rows:z,at:Date.now()},!0)},[j,t,n,s,D,e]),S=d.useCallback((x="resize",R={})=>{const{immediate:H=!1,force:L=!1}=R;u.current!==null&&(window.clearTimeout(u.current),u.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const k=()=>{l.current=requestAnimationFrame(()=>{l.current=null,V(x,L)})};if(H){k();return}u.current=window.setTimeout(()=>{u.current=null,k()},150)},[V]),E=d.useCallback(()=>{for(const x of A.current)window.clearTimeout(x);A.current=[]},[]),P=d.useCallback(()=>{var R;E(),S("sync",{immediate:!0,force:!0});const x=window.setTimeout(()=>{S("sync",{immediate:!0,force:!0})},60);A.current.push(x),typeof document<"u"&&"fonts"in document&&((R=document.fonts)!=null&&R.ready)&&document.fonts.ready.then(()=>{S("sync",{immediate:!0,force:!0})}).catch(()=>{})},[E,S]);d.useEffect(()=>{let x=null;const R=()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,S("resize")})};return window.addEventListener("resize",R),()=>{window.removeEventListener("resize",R),x!==null&&cancelAnimationFrame(x)}},[S]),d.useEffect(()=>{const x=()=>{var ne;const k=T.current,z=D();if(!k||!z)return;if(!br({currentSize:{cols:Math.max(2,k.cols),rows:Math.max(2,k.rows)},containerSize:z})){(ne=k.refresh)==null||ne.call(k);return}S("sync",{force:!0})},R=()=>{if(document.visibilityState!=="visible"){q.current=!0;return}q.current&&(q.current=!1,x())},H=()=>{q.current=!0},L=()=>{q.current&&(q.current=!1,x())};return document.addEventListener("visibilitychange",R),window.addEventListener("blur",H),window.addEventListener("focus",L),()=>{document.removeEventListener("visibilitychange",R),window.removeEventListener("blur",H),window.removeEventListener("focus",L)}},[D,S]),d.useEffect(()=>()=>{E(),u.current!==null&&window.clearTimeout(u.current),l.current!==null&&cancelAnimationFrame(l.current)},[E]);const U=d.useCallback(x=>{N.current=x},[]),K=d.useCallback(x=>{T.current=x},[]);return{scheduleResize:S,runPostSelectResize:P,clearPostSelectResizeTimers:E,setFitAddon:U,setTerminal:K,lastReportedSize:a,pendingLocalSize:_,suppressLocalResizeUntil:M}}const Tr={fontFamily:mr,fontSize:13,scrollback:1e4},it="tmex:terminal-mode-cache";function Er(n,e){try{const t=sessionStorage.getItem(it);return t?JSON.parse(t)[`${n}:${e}`]??null:null}catch{return null}}function Rr(n,e,t){try{const s=sessionStorage.getItem(it),r=s?JSON.parse(s):{},i=`${n}:${e}`;t?r[i]=t:delete r[i],sessionStorage.setItem(it,JSON.stringify(r))}catch{}}function Cr(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function vr(n,e){if(!e)return n?{...n,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const t=Cr();if(!n)return t;const s=n.mouseNormal||n.mouseButton||n.mouseAny;return{...n,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:s?n.mouseNormal:t.mouseNormal}}function Mr(n){var t;const e=globalThis;e.__tmexE2eXterm=n,e.__tmexE2eTerminal=n,e.__tmexE2eTerminalEngine=Gt,e.__tmexE2eTerminalRenderer=((t=n.getRendererKind)==null?void 0:t.call(n))??null}function Dr(n){if(!n)return;const e=globalThis;e.__tmexE2eTerminal!==n&&e.__tmexE2eXterm!==n||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const Vt=d.forwardRef(({deviceId:n,paneId:e,theme:t,inputMode:s,deviceConnected:r,isSelectionInvalid:i,onResize:o,onSync:l},u)=>{const[a,_]=d.useState(null),[M,A]=d.useState(!1),N=ee(y=>y.sendInput),{t:T}=Ke(),b=d.useMemo(()=>{switch(t){case"light":return zt;default:return Yt}},[t]),q=d.useRef(null),g=d.useRef(null),G=d.useRef(null),D=d.useRef(n),j=d.useRef(e),V=d.useRef(n),S=d.useRef(e),E=d.useRef(r&&!i),P=d.useRef(s),U=d.useRef(b),K=d.useRef(!1),x=d.useRef(!1),R=d.useRef(null),H=d.useRef(!1),L=d.useCallback((y,f,C)=>{!(y!=null&&y.exportModeSnapshot)||!f||!C||Rr(f,C,y.exportModeSnapshot())},[]),k=d.useCallback(()=>a,[a]);Sr(q,k),d.useEffect(()=>{D.current=n,j.current=e,x.current=!1},[n,e]),d.useEffect(()=>{E.current=r&&!i},[r,i]),d.useEffect(()=>{P.current=s},[s]),d.useEffect(()=>{U.current=b},[b]);const z=d.useCallback(y=>{if(!y||s!=="direct"||!E.current)return;const f=D.current,C=j.current;!f||!C||N(f,C,y,!1)},[s,N]),{pendingLocalSize:I,scheduleResize:ne,runPostSelectResize:se,setFitAddon:oe,setTerminal:re}=xr({deviceId:n,paneId:e,deviceConnected:r,isSelectionInvalid:i,onResize:o,onSync:l,getContainerRect:()=>{const y=q.current;if(!y)return null;const f=y.getBoundingClientRect();return{width:f.width,height:f.height}}});d.useEffect(()=>{let y=!1,f=null;return dr({...Tr,theme:U.current,disableStdin:P.current==="editor"}).then(C=>{if(y){C.dispose();return}f=C,g.current&&C.open(g.current),Mr(C),_(C)}),()=>{y=!0,_(null),Dr(f),f==null||f.dispose()}},[]),d.useEffect(()=>{!a||!("setTheme"in a)||a.setTheme(b)},[a,b]),d.useEffect(()=>{!a||!("setDisableStdin"in a)||a.setDisableStdin(s==="editor")},[a,s]);const W=d.useMemo(()=>a?{onResetTerminal:y=>{D.current===y&&(L(a,V.current,S.current),H.current=!0,a.reset(),K.current=!1,se())},onApplyHistory:(y,f,C)=>{var Z;if(D.current!==y)return;const B=vr(Er(D.current,j.current),C);B&&((Z=a.restoreModeSnapshot)==null||Z.call(a,B));const F=C?fr(f):Ut(f);x.current=!0,a.write(F),H.current=!1,V.current=D.current,S.current=j.current,L(a,D.current,j.current)},onFlushBuffer:(y,f)=>{if(D.current===y){for(const C of f){const B=Dt(C,K.current);K.current=B.endedWithCR,a.write(B.normalized)}x.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),x.current=!1),V.current=D.current,S.current=j.current,L(a,D.current,j.current)}},onOutput:(y,f,C)=>{if(D.current!==y||j.current!==f)return;const B=Dt(C,K.current);K.current=B.endedWithCR,a.write(B.normalized),x.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),x.current=!1),V.current=D.current,S.current=j.current,L(a,D.current,j.current)}}:{},[a,L,se]);d.useEffect(()=>{a?R.current!==a&&(K.current=!1,V.current=D.current,S.current=j.current,R.current=a):R.current=null},[a]),d.useEffect(()=>{if(!(!a||!n||!e))return()=>{if(H.current){H.current=!1;return}L(a,V.current,S.current)}},[n,a,e,L]),d.useEffect(()=>{ft(W)},[W]),d.useEffect(()=>()=>{ft({})},[]),d.useEffect(()=>{if(!a){G.current=null,oe(null),re(null);return}const y=new cr;return a.loadAddon(y),G.current=y,oe(y),re(a),se(),()=>{try{y.dispose()}finally{G.current=null,oe(null),re(null)}}},[a,se,oe,re]),d.useEffect(()=>{const y=q.current;if(!y)return;let f=null;const C=new ResizeObserver(()=>{f!==null&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,ne("resize")})});return C.observe(y),()=>{C.disconnect(),f!==null&&cancelAnimationFrame(f)}},[ne]),d.useEffect(()=>{if(!a||!n||!e)return;const y=a.onData(f=>{!r||i||z(f)});return a.attachCustomKeyEventHandler(f=>!r||i||f.type!=="keydown"||s!=="direct"?!0:f.shiftKey&&f.key==="Enter"?(f.preventDefault(),z("\x1B[13;2u"),!1):!0),()=>{y.dispose(),a.attachCustomKeyEventHandler(()=>!0)}},[a,r,i,s,z,n,e]),d.useEffect(()=>{if(!(a!=null&&a.onSelectionChange)){A(!1);return}const y=a.onSelectionChange(f=>{A(!!f)});return()=>{y.dispose(),A(!1)}},[a]);const Y=d.useCallback(()=>{var f;if(!a)return;const y=((f=a.getSelection)==null?void 0:f.call(a))??"";y&&Bt(y).then(()=>{xe.success(T("terminal.copied"))}).catch(()=>{xe.error(T("terminal.copyFailed"))}).finally(()=>{var C;(C=a.clearSelection)==null||C.call(a),a.focus()})},[a,T]),X=d.useCallback(()=>{var f;if(!a)return;((f=navigator.clipboard)!=null&&f.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(C=>{var B;C&&a.paste(C),(B=a.clearSelection)==null||B.call(a),a.focus()}).catch(()=>{xe.error(T("terminal.pasteFailed"))})},[a,T]),J=d.useCallback(()=>{var y;(y=a==null?void 0:a.clearSelection)==null||y.call(a),a==null||a.focus()},[a]);return d.useImperativeHandle(u,()=>({write:y=>a==null?void 0:a.write(y),reset:()=>{a==null||a.reset(),K.current=!1},scrollToBottom:()=>a==null?void 0:a.scrollToBottom(),resize:(y,f)=>a==null?void 0:a.resize(y,f),getTerminal:()=>a??null,getSize:()=>a?{cols:Math.max(2,a.cols),rows:Math.max(2,a.rows)}:null,runPostSelectResize:()=>se(),scheduleResize:(y,f)=>ne(y,f),calculateSizeFromContainer:()=>{var je,We,qe,Re,ie,Ce,me,ke,Ie,ce,Se,pe,de,te,_e,we;const y=q.current,f=a,C=G.current;if(!y||!f)return null;const B=y.getBoundingClientRect();if(B.width===0||B.height===0)return null;const F=f._core;let Z;if(C)try{const ue=C.proposeDimensions();if(ue)Z=Math.max(2,ue.cols);else{const Ne=((Re=(qe=(We=(je=F==null?void 0:F._renderService)==null?void 0:je.dimensions)==null?void 0:We.css)==null?void 0:qe.cell)==null?void 0:Re.width)??9;Z=Math.max(2,Math.floor(B.width/Ne))}}catch{const ue=((ke=(me=(Ce=(ie=F==null?void 0:F._renderService)==null?void 0:ie.dimensions)==null?void 0:Ce.css)==null?void 0:me.cell)==null?void 0:ke.width)??9;Z=Math.max(2,Math.floor(B.width/ue))}else{const ue=((pe=(Se=(ce=(Ie=F==null?void 0:F._renderService)==null?void 0:Ie.dimensions)==null?void 0:ce.css)==null?void 0:Se.cell)==null?void 0:pe.width)??9;Z=Math.max(2,Math.floor(B.width/ue))}const ae=((we=(_e=(te=(de=F==null?void 0:F._renderService)==null?void 0:de.dimensions)==null?void 0:te.css)==null?void 0:_e.cell)==null?void 0:we.height)??17,Oe=Math.max(2,Math.floor(B.height/ae));return{cols:Z,rows:Oe}},getPendingLocalSize:()=>I.current}),[a,I,se,ne]),h.jsxs("div",{ref:q,className:"h-full w-full relative",style:{backgroundColor:b.background},"data-terminal-engine":Gt,children:[h.jsx("div",{ref:g,className:"absolute inset-0"}),h.jsx(ur,{visible:M,canPaste:s==="direct"&&r&&!i,onCopy:Y,onPaste:X,onDismiss:J})]})});Vt.displayName="Terminal";const Ar=1200,Or=2e3;function ye(n,e){return!n||!e?!1:n.windowId===e.windowId&&n.paneId===e.paneId}function Kt(n,e){const t=n.filter(s=>e-s.at<Ar);return t.length===0?null:t.reduce((s,r)=>r.at>s.at?r:s)}function Ae(n,e=Date.now()){return!n||e-n.at>Or?null:n}function kr(n){const e=n.now??Date.now(),t=Kt(n.recentSelectRequests,e);if(t&&!ye(t,n.activePaneFromEvent)||ye(n.currentRoute,n.activePaneFromEvent)||ye(n.lastHandledActive,n.activePaneFromEvent))return!0;const s=Ae(n.pendingUserSelection,e);return!!(s&&!ye(s,n.activePaneFromEvent))}function Ir(n){const e=n.now??Date.now(),t=Kt(n.recentSelectRequests,e),s=Ae(n.pendingUserSelection,e);return!!(s&&!ye(s,n.snapshotActive)||t&&!ye(t,n.snapshotActive))}function Nr(n){const e=n.now??Date.now(),t=Ae(n.pendingUserSelection,e);return!(t&&ye(t,n.routeTarget)||n.snapshotActive&&ye(n.snapshotActive,n.routeTarget))}function Pr(){const n=ot.getState().settings;return(n==null?void 0:n.siteName)||"tmex"}function At(n){const e=n==null?void 0:n.trim();return e&&e.length>0?e:"?"}function $t({paneIdx:n,windowIdx:e,paneTitle:t,windowName:s,deviceName:r}){const i=e??"?",o=n??"?",l=At(t??s),u=At(r);return`${i}/${o}: ${l}@${u}`}function Lr(n){const e=Pr();return n!=null&&n.trim()?`[${e}]${n}`:e}function Br(){if(typeof navigator>"u")return!1;const n=navigator.userAgent,e=/iPad|iPhone|iPod/.test(n),t=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return e||t}const Hr=[{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:"`"}],Ot=d.memo(function({onSend:e,onFocusEditor:t,disabled:s,isMobile:r,inputMode:i}){return h.jsx("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:h.jsx("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Hr.map(o=>h.jsx(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:s,children:o.label},o.key))})})});function Yr(){var ht;const{t:n}=Ke(),{deviceId:e,windowId:t,paneId:s}=lt(),r=sn(),i=d.useRef(null),o=d.useRef(null),l=d.useRef(null),u=d.useRef(null),a=d.useRef(!1),_=d.useRef(!1),M=d.useRef(null),A=ee(c=>c.selectPane),N=ee(c=>e?c.snapshots[e]:void 0),T=ee(c=>{var p;return e?(p=c.deviceErrors)==null?void 0:p[e]:void 0}),b=ee(c=>{var p;return e?((p=c.deviceConnected)==null?void 0:p[e])??!1:!1}),q=ot(c=>{var p;return((p=c.settings)==null?void 0:p.siteName)??"tmex"}),g=d.useMemo(()=>at(s),[s]),G=d.useMemo(()=>e&&g?`${e}:${g}`:null,[e,g]),[D,j]=d.useState(!1),[V,S]=d.useState(""),[E,P]=d.useState(!1),U=d.useRef(!1),K=!b||!g,[x,R]=d.useState(0),[H,L]=d.useState(0),[k,z]=d.useState(!1),I=he(c=>c.inputMode),ne=he(c=>c.theme),se=he(c=>c.editorSendWithEnter),oe=he(c=>c.setEditorSendWithEnter),re=he(c=>c.addEditorHistory),W=he(c=>c.setEditorDraft),Y=he(c=>c.removeEditorDraft),X=he(c=>G?c.editorDrafts[G]??"":""),J=d.useMemo(()=>Br(),[]),y=D&&I==="editor"&&J&&E,f=(ht=N==null?void 0:N.session)==null?void 0:ht.windows,C=ne==="light"?zt:Yt,{data:B}=rn({queryKey:["devices"],queryFn:async()=>{const c=await fetch("/api/devices");if(!c.ok)throw new Error("Failed to fetch devices");return c.json()},throwOnError:!1}),F=d.useMemo(()=>{if(e)return B==null?void 0:B.devices.find(c=>c.id===e)},[e,B==null?void 0:B.devices]),Z=d.useMemo(()=>{if(!(!t||!f))return f.find(c=>c.id===t)},[t,f]),ae=d.useMemo(()=>{if(!(!g||!Z))return Z.panes.find(c=>c.id===g)},[g,Z]),Oe=!!f,Re=!!(Oe&&!!t&&!Z||Oe&&!!t&&!!g&&!!Z&&!ae?n("wsError.checkGateway"):null),ie=!!(b&&g&&!Re),Ce=d.useMemo(()=>{if(!Z||!ae)return null;const c=(F==null?void 0:F.name)??e;return $t({paneIdx:ae.index,windowIdx:Z.index,paneTitle:ae.title,windowName:Z.name,deviceName:c})},[F==null?void 0:F.name,e,ae,Z]),me=d.useMemo(()=>{if(!f||f.length===0)return null;const c=f.find(m=>m.active),p=c==null?void 0:c.panes.find(m=>m.active);return!c||!p?null:{windowId:c.id,paneId:p.id}},[f]),ke=d.useCallback((c,p)=>{!e||!g||ee.getState().resizePane(e,g,c,p)},[e,g]),Ie=d.useCallback((c,p)=>{!e||!g||ee.getState().syncPaneSize(e,g,c,p)},[e,g]),ce=d.useCallback((c,p)=>{const m=u.current,v=(m==null?void 0:m.calculateSizeFromContainer())??(m==null?void 0:m.getSize())??void 0;if(v)return v;if(!c||!p||!f)return;const Q=f.find(le=>le.id===c),$=Q==null?void 0:Q.panes.find(le=>le.id===p);if(!(!$||$.width<=1||$.height<=1))return{cols:$.width,rows:$.height}},[f]);d.useEffect(()=>{const c=()=>{j(window.innerWidth<768||"ontouchstart"in window)};return c(),window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[]),d.useEffect(()=>{if(!D||!J||_.current)return;_.current=!0;const c=()=>{window.scrollTo(0,1)},p=window.requestAnimationFrame(c),m=window.setTimeout(c,120),v=window.setTimeout(c,420);return()=>{window.cancelAnimationFrame(p),window.clearTimeout(m),window.clearTimeout(v)}},[J,D]),d.useEffect(()=>{I!=="editor"&&P(!1)},[I]),d.useEffect(()=>{var v,Q;if(!(D&&J&&I==="editor"&&E)){R(0);return}let c=null;const p=()=>{const $=window.visualViewport,le=($==null?void 0:$.height)??window.innerHeight,ve=($==null?void 0:$.offsetTop)??0,Zt=Math.max(0,Math.round(window.innerHeight-le-ve));R(Zt)},m=()=>{c===null&&(c=window.requestAnimationFrame(()=>{c=null,p()}))};return p(),(v=window.visualViewport)==null||v.addEventListener("resize",m),(Q=window.visualViewport)==null||Q.addEventListener("scroll",m),window.addEventListener("resize",m),()=>{var $,le;($=window.visualViewport)==null||$.removeEventListener("resize",m),(le=window.visualViewport)==null||le.removeEventListener("scroll",m),window.removeEventListener("resize",m),c!==null&&window.cancelAnimationFrame(c)}},[I,E,J,D]),d.useEffect(()=>{if(!y){L(0);return}const c=o.current;if(!c)return;const p=()=>{L(Math.ceil(c.getBoundingClientRect().height))};p();const m=new ResizeObserver(p);return m.observe(c),()=>m.disconnect()},[y]),d.useEffect(()=>{e&&(a.current=!1,_e.current=null,we.current=null,M.current=null,pe.current=[])},[e]),d.useEffect(()=>{b||(a.current=!1)},[b]),d.useEffect(()=>{if(!e||!b||!t||!f)return;if(f.length===0){r("/devices",{replace:!0});return}const c=f.find(m=>m.id===t);if(!c)return;if(!g){const m=c.panes.find(v=>v.active)??c.panes[0];m&&r(`/devices/${e}/windows/${t}/panes/${be(m.id)}`,{replace:!0});return}if(!c.panes.find(m=>m.id===g)){const m=c.panes.find(v=>v.active)??c.panes[0];m&&r(`/devices/${e}/windows/${t}/panes/${be(m.id)}`,{replace:!0});return}},[e,b,f,t,g,r]),d.useEffect(()=>{if(!e||!b||!f||f.length===0||t&&g||a.current)return;const c=f.find(m=>m.active)??f[0],p=c.panes.find(m=>m.active)??c.panes[0];p&&(a.current=!0,r(`/devices/${e}/windows/${c.id}/panes/${be(p.id)}`,{replace:!0}))},[b,e,r,g,t,f]);const Se=d.useRef(null);d.useEffect(()=>{Se.current=null},[e,g]),d.useEffect(()=>{if(!e||!t||!g||K||!b)return;const c=`${e}:${t}:${g}`;if(Se.current===c)return;Se.current=c;const p=ce(t,g);de(t,g),A(e,t,g,p)},[b,e,ce,K,g,A,t]),d.useEffect(()=>{if(!e||!b||!t||!g)return;const c={windowId:t,paneId:g};Nr({routeTarget:c,snapshotActive:me,pendingUserSelection:M.current})&&(M.current={windowId:c.windowId,paneId:c.paneId,at:Date.now()})},[b,e,g,me,t]);const pe=d.useRef([]),de=d.useCallback((c,p)=>{const m=Date.now(),v=[...pe.current.filter(Q=>m-Q.at<2e3),{windowId:c,paneId:p,at:m}];pe.current=v.slice(-8)},[]),te=ee(c=>e?c.activePaneFromEvent[e]:void 0),_e=d.useRef(null);d.useEffect(()=>{if(!e||!b||!t||!g||!te)return;const c=Date.now(),p=Ae(M.current,c);if(M.current=p,kr({now:c,pendingUserSelection:p,activePaneFromEvent:te,currentRoute:{windowId:t,paneId:g},recentSelectRequests:pe.current,lastHandledActive:_e.current}))return;_e.current={...te},p&&p.windowId===te.windowId&&p.paneId===te.paneId&&(M.current=null);const m=ce(te.windowId,te.paneId);de(te.windowId,te.paneId),A(e,te.windowId,te.paneId,m),r(`/devices/${e}/windows/${te.windowId}/panes/${be(te.paneId)}`,{replace:!0})},[e,b,t,g,te,de,ce,A,r]);const we=d.useRef(null);d.useEffect(()=>{if(!e||!b||!f||f.length===0)return;const c=pe.current,p=f.find(ve=>ve.active);if(!p)return;const m=p.panes.find(ve=>ve.active);if(!m)return;const v={windowId:p.id,paneId:m.id},Q=Date.now(),$=Ae(M.current,Q);if(M.current=$,Ir({now:Q,pendingUserSelection:$,snapshotActive:v,recentSelectRequests:c})||we.current&&we.current.windowId===v.windowId&&we.current.paneId===v.paneId||(we.current={...v},$&&$.windowId===v.windowId&&$.paneId===v.paneId&&(M.current=null),t===v.windowId&&g===v.paneId))return;const le=ce(v.windowId,v.paneId);de(v.windowId,v.paneId),A(e,v.windowId,v.paneId,le),r(`/devices/${e}/windows/${v.windowId}/panes/${be(v.paneId)}`,{replace:!0})},[e,b,f,t,g,de,ce,A,r]);const ue=ee(c=>e?c.pendingCreateWindowAt[e]:void 0);d.useEffect(()=>{if(!e||!b||!ue)return;const c=5e3,p=Date.now()-ue;if(p>c){ee.getState().clearPendingCreateWindow(e);return}if(!me){const Q=window.setTimeout(()=>{ee.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(Q)}const m=me;if(t===m.windowId&&g===m.paneId){const Q=window.setTimeout(()=>{ee.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(Q)}M.current={windowId:m.windowId,paneId:m.paneId,at:Date.now()};const v=ce(m.windowId,m.paneId);de(m.windowId,m.paneId),A(e,m.windowId,m.paneId,v),r(`/devices/${e}/windows/${m.windowId}/panes/${be(m.paneId)}`,{replace:!0}),ee.getState().clearPendingCreateWindow(e)},[e,b,ue,me,t,g,de,ce,A,r]),d.useEffect(()=>{if(!ie||!ae||K)return;const c=u.current,p=c==null?void 0:c.getTerminal();if(!p)return;const m=Math.max(2,Math.floor(ae.width||0)),v=Math.max(2,Math.floor(ae.height||0));if(!m||!v)return;const Q=Date.now(),$={cols:m,rows:v},le=(c==null?void 0:c.getPendingLocalSize())??null;_r({now:Q,remoteSize:$,pendingLocalSize:le})&&(p.cols===m&&p.rows===v||p.resize(m,v))},[ie,K,ae]),d.useEffect(()=>{const c=window.requestAnimationFrame(()=>{var m;(m=u.current)==null||m.scrollToBottom()}),p=window.setTimeout(()=>{var m;(m=u.current)==null||m.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(c),window.clearTimeout(p)}},[I]),d.useEffect(()=>{T!=null&&T.message&&xe.error(T.message)},[T==null?void 0:T.message]),d.useEffect(()=>(document.title=Lr(Ce),()=>{document.title=q}),[q,Ce]),d.useEffect(()=>{const c=()=>{var p;(p=u.current)==null||p.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",c),()=>{window.removeEventListener("tmex:jump-to-latest",c)}},[]),d.useEffect(()=>{const c=p=>{const{deviceId:m,windowId:v,paneId:Q}=p.detail;m===e&&(M.current={windowId:v,paneId:Q,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",c),()=>{window.removeEventListener("tmex:user-initiated-selection",c)}},[e]),d.useEffect(()=>{S(X)},[X]);const Ne=d.useCallback(c=>{if(!e||!g||!ie)return;ee.getState().sendInput(e,g,c,!1)},[ie,e,g]),jt=d.useCallback(()=>{if(!ie){xe.error(n("wsError.checkGateway"));return}if(!e||!g||!V.trim())return;z(!0),window.setTimeout(()=>z(!1),150);const c=se?`${V}\r`:V;ee.getState().sendInput(e,g,c,!1),re(V),G&&Y(G),S("")},[re,ie,e,G,se,V,Y,g,n]),Wt=d.useCallback(()=>{if(!ie){xe.error(n("wsError.checkGateway"));return}if(!e||!g||!V.trim())return;z(!0),window.setTimeout(()=>z(!1),150);const c=V.split(/\r?\n/),p=ee.getState();for(const m of c)m.trim()&&p.sendInput(e,g,`${m}\r`,!1);re(V),G&&Y(G),S("")},[re,ie,e,G,V,Y,g,n]),qt=d.useCallback(c=>{if(P(!0),!(D&&J))return;const p=c.currentTarget;window.requestAnimationFrame(()=>{p.scrollIntoView({block:"nearest",inline:"nearest"})}),window.setTimeout(()=>{window.scrollTo(0,1)},60)},[J,D]),Xt=d.useCallback(()=>{P(!1)},[]),Jt=d.useCallback(()=>{var c;(c=l.current)==null||c.focus({preventScroll:!0})},[]);if(!e)return h.jsx("div",{className:"flex h-full items-center justify-center p-4",children:h.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:n("device.noDevices")})});const Qt=!b&&!T;return h.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[h.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${D&&I==="editor"&&!y?"pb-1":""}`,style:{paddingBottom:y?`${H+60}px`:void 0},children:[h.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:C.background},children:b&&g?h.jsx("div",{ref:i,className:"flex-1 h-full min-h-0 w-full",children:h.jsx(Vt,{ref:u,deviceId:e,paneId:g,theme:ne,inputMode:I,deviceConnected:b,isSelectionInvalid:Re,onResize:ke,onSync:Ie},`${e}:${g}`)}):h.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:h.jsx("div",{className:"max-w-sm space-y-4",children:b?t?h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx(Xe,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("terminal.connecting")})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("window.noWindowSelected")}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n("window.selectWindowToStart")})]}):h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:h.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),h.jsx("h3",{className:"text-lg font-medium",children:n("device.disconnected")}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n("device.connectToStart")})]})})})}),Qt&&h.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:h.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[h.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),h.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:n("terminal.connecting")})]})})]}),I==="direct"&&h.jsx("div",{className:"",children:h.jsx(Ot,{onSend:Ne,disabled:!ie,isMobile:D,inputMode:I})}),I==="editor"&&h.jsxs("div",{ref:o,className:`editor-mode-input bg-card/85 backdrop-blur-sm ${y?"fixed left-0 right-0 z-50":""}`,style:y?{bottom:`${x}px`}:void 0,children:[D&&h.jsx(Ot,{onSend:Ne,onFocusEditor:Jt,disabled:!ie,isMobile:D,inputMode:I}),h.jsx("textarea",{ref:l,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:V,onChange:c=>{const p=c.target.value;if(S(p),!!G){if(p){W(G,p);return}Y(G)}},placeholder:n("terminal.inputPlaceholder"),onFocus:qt,onBlur:Xt,onCompositionStart:()=>{U.current=!0},onCompositionEnd:()=>{U.current=!1}}),h.jsx("div",{className:"actions mt-2",children:h.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[h.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[h.jsx(pn,{size:"sm",checked:se,onCheckedChange:c=>oe(!!c)}),h.jsx("span",{children:n("terminal.editorSendWithEnter")})]}),h.jsxs(ge,{variant:"outline",size:"sm","data-testid":"editor-clear",onPointerDown:c=>c.preventDefault(),onClick:()=>{var c;S(""),G&&Y(G),D&&I==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},title:n("terminal.clear"),children:[h.jsx(on,{className:"h-4 w-4"}),n("terminal.clear")]}),h.jsxs(ge,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onPointerDown:c=>c.preventDefault(),onClick:()=>{var c;Wt(),D&&I==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!ie||k,children:[k?h.jsx(Xe,{className:"h-4 w-4 animate-spin"}):h.jsx(mt,{className:"h-4 w-4"}),n("terminal.editorSendLineByLine")]}),h.jsxs(ge,{variant:"default",size:"sm","data-testid":"editor-send",onPointerDown:c=>c.preventDefault(),onClick:()=>{var c;jt(),D&&I==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!ie||k,children:[k?h.jsx(Xe,{className:"h-4 w-4 animate-spin"}):h.jsx(mt,{className:"h-4 w-4"}),n("common.send")]})]})})]})]})}function Vr(){const{deviceId:n,windowId:e,paneId:t}=lt(),s=t?at(t):void 0,r=ee(_=>_.snapshots),i=ot(_=>{var M;return((M=_.settings)==null?void 0:M.siteName)??"tmex"}),o=n?r[n]:void 0,l=d.useMemo(()=>{var _;if(!(!e||!((_=o==null?void 0:o.session)!=null&&_.windows)))return o.session.windows.find(M=>M.id===e)},[e,o]),u=d.useMemo(()=>{if(!(!s||!l))return l.panes.find(_=>_.id===s)},[s,l]),a=d.useMemo(()=>l&&u?$t({paneIdx:u.index,windowIdx:l.index,paneTitle:u.title,windowName:l.name,deviceName:i}):n??"",[l,u,i,n]);return h.jsx(h.Fragment,{children:a})}function Kr(){const{t:n}=Ke(),{deviceId:e,paneId:t}=lt(),s=t?at(t):void 0,r=he(T=>T.inputMode),i=he(T=>T.setInputMode),o=ee(T=>{var b;return e?((b=T.deviceConnected)==null?void 0:b[e])??!1:!1}),[l,u]=d.useState(!1),a=!!(s&&o),_=()=>{i(r==="direct"?"editor":"direct")},M=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},A=()=>{u(!0)},N=()=>{window.location.reload()};return h.jsxs(h.Fragment,{children:[h.jsx(ge,{variant:"ghost",size:"icon-sm",onClick:A,"aria-label":n("nav.refreshPage"),title:n("nav.refreshPage"),children:h.jsx(Rn,{className:"h-4 w-4"})}),h.jsx(ge,{variant:"ghost",size:"icon-sm",onClick:_,disabled:!a,"data-testid":"terminal-input-mode-toggle","aria-label":n(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:n(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:r==="direct"?h.jsx(Tn,{className:"h-4 w-4"}):h.jsx(vn,{className:"h-4 w-4"})}),h.jsx(ge,{variant:"ghost",size:"icon-sm",onClick:M,disabled:!a,"aria-label":n("nav.jumpToLatest"),title:n("nav.jumpToLatest"),children:h.jsx(yn,{className:"h-4 w-4"})}),h.jsx(ln,{open:l,onOpenChange:u,children:h.jsxs(an,{children:[h.jsxs(cn,{children:[h.jsx(dn,{children:n("nav.refreshPage")}),h.jsx(un,{children:n("nav.refreshPageConfirm")})]}),h.jsxs(hn,{children:[h.jsx(fn,{onClick:()=>u(!1),children:n("common.cancel")}),h.jsx(mn,{onClick:N,children:n("common.confirm")})]})]})})]})}export{Kr as PageActions,Vr as PageTitle,Yr as default};
36
+ //# sourceMappingURL=DevicePage-c0xvFVOR.js.map