tmex-cli 0.11.0 → 0.12.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 (66) hide show
  1. package/CHANGELOG.md +36 -12
  2. package/dist/runtime/server.js +685 -41
  3. package/package.json +1 -1
  4. package/resources/fe-dist/assets/DevicePage-B2xsa-ys.js +21 -0
  5. package/resources/fe-dist/assets/DevicesPage-Bm7E9QAf.js +2 -0
  6. package/resources/fe-dist/assets/{FilePage-YWma96aj.js → FilePage-DtXS6Krk.js} +8 -8
  7. package/resources/fe-dist/assets/{SettingsPage-LhUD03Ln.js → SettingsPage-Bxat-d_V.js} +3 -3
  8. package/resources/fe-dist/assets/{arc-DLVa298O.js → arc-CWkT1O24.js} +2 -2
  9. package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-EOUpuRby.js → architectureDiagram-3BPJPVTR-nu1LX68y.js} +2 -2
  10. package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-BTwwkzZh.js → blockDiagram-GPEHLZMM-DLFLNzT_.js} +2 -2
  11. package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-xvTqXxl9.js → c4Diagram-AAUBKEIU-BE8aWxc1.js} +2 -2
  12. package/resources/fe-dist/assets/{card-cbVDy0Xp.js → card-Duis2VHj.js} +2 -2
  13. package/resources/fe-dist/assets/channel-zKL2OH3S.js +2 -0
  14. package/resources/fe-dist/assets/{chunk-2J33WTMH-Blr6l1Nk.js → chunk-2J33WTMH-Dlc3MV0y.js} +2 -2
  15. package/resources/fe-dist/assets/{chunk-4BX2VUAB-D_Y2TeLg.js → chunk-4BX2VUAB-E9XGobks.js} +2 -2
  16. package/resources/fe-dist/assets/{chunk-55IACEB6-CimNoYDH.js → chunk-55IACEB6-Bp7ueFZf.js} +2 -2
  17. package/resources/fe-dist/assets/{chunk-727SXJPM-JPYDN0Cb.js → chunk-727SXJPM-CQrvyHfQ.js} +2 -2
  18. package/resources/fe-dist/assets/{chunk-AQP2D5EJ-Cb3NZBib.js → chunk-AQP2D5EJ-c0B1XNZr.js} +2 -2
  19. package/resources/fe-dist/assets/{chunk-FMBD7UC4-DyZ7Ot2F.js → chunk-FMBD7UC4-BWQBkKWs.js} +2 -2
  20. package/resources/fe-dist/assets/{chunk-ND2GUHAM-SU6Ea3wF.js → chunk-ND2GUHAM-D9TROogS.js} +2 -2
  21. package/resources/fe-dist/assets/{chunk-QZHKN3VN-B6qXX6sU.js → chunk-QZHKN3VN-DRXr6zVP.js} +2 -2
  22. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-Drw216KI.js +2 -0
  23. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-Drw216KI.js +2 -0
  24. package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-BAyMopHS.js → cose-bilkent-S5V4N54A-CBgJRn7g.js} +2 -2
  25. package/resources/fe-dist/assets/{dagre-BM42HDAG-Ckrx9BXZ.js → dagre-BM42HDAG-ClYznWvX.js} +2 -2
  26. package/resources/fe-dist/assets/{diagram-2AECGRRQ-DTnZtf2k.js → diagram-2AECGRRQ-Br_41uIc.js} +2 -2
  27. package/resources/fe-dist/assets/{diagram-5GNKFQAL-DBpgZj4a.js → diagram-5GNKFQAL-BD9o1BrS.js} +2 -2
  28. package/resources/fe-dist/assets/{diagram-KO2AKTUF-CfijYCeY.js → diagram-KO2AKTUF-Diq2zS9Y.js} +2 -2
  29. package/resources/fe-dist/assets/{diagram-LMA3HP47-D7nBmQ-E.js → diagram-LMA3HP47-CLaOalPy.js} +2 -2
  30. package/resources/fe-dist/assets/{diagram-OG6HWLK6-Bi8sHV0O.js → diagram-OG6HWLK6-BcSlvdPy.js} +2 -2
  31. package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-DcoDesO2.js → erDiagram-TEJ5UH35-BNlad0c4.js} +2 -2
  32. package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-Bbcl9kxS.js → flowDiagram-I6XJVG4X-Zb1FLY00.js} +2 -2
  33. package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-BM8Y7jwp.js → ganttDiagram-6RSMTGT7-DPRPR5Is.js} +2 -2
  34. package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-x3wpNQcW.js → gitGraphDiagram-PVQCEYII-BENU2uEN.js} +2 -2
  35. package/resources/fe-dist/assets/index-CRCD4gPw.css +1 -0
  36. package/resources/fe-dist/assets/index-Den36xcn.js +488 -0
  37. package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-Bl6cgwVb.js → infoDiagram-5YYISTIA-NfMlH21e.js} +2 -2
  38. package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-BfQ7aZxN.js → ishikawaDiagram-YF4QCWOH-CzK9-7uY.js} +2 -2
  39. package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-DSwQzmdL.js → journeyDiagram-JHISSGLW-CIX5Ahuw.js} +2 -2
  40. package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-B1aWDl4E.js → kanban-definition-UN3LZRKU-C5Ccl5Cw.js} +2 -2
  41. package/resources/fe-dist/assets/{linear-CfhRC4iX.js → linear-CBC08yeS.js} +2 -2
  42. package/resources/fe-dist/assets/{markdown-preview-CfBRMViB.js → markdown-preview-Drd503bU.js} +4 -4
  43. package/resources/fe-dist/assets/{mermaid.core-M-o4g4TO.js → mermaid.core-DYl6mxS0.js} +6 -6
  44. package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-D976sxOA.js → mindmap-definition-RKZ34NQL-ACR2SUDm.js} +2 -2
  45. package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-PVQ3-EB6.js → pieDiagram-4H26LBE5-BuDDdwwy.js} +2 -2
  46. package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-BNEFhYNq.js → quadrantDiagram-W4KKPZXB-CzM2Ydhy.js} +2 -2
  47. package/resources/fe-dist/assets/{refresh-cw-cfX5JiIH.js → refresh-cw-DhzvbVDA.js} +2 -2
  48. package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-B7Zd2lpN.js → requirementDiagram-4Y6WPE33-BveKh_kW.js} +2 -2
  49. package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-D_Td4j-B.js → sankeyDiagram-5OEKKPKP-BGQ6jtyE.js} +2 -2
  50. package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-DQSVX5mL.js → sequenceDiagram-3UESZ5HK-D2fdqire.js} +2 -2
  51. package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-C0PNCTfs.js → stateDiagram-AJRCARHV-DtuVBIq9.js} +2 -2
  52. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-gun__PvU.js +2 -0
  53. package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-BlMj8Fl1.js → timeline-definition-PNZ67QCA-Dslo0JFS.js} +2 -2
  54. package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-DuGxwZiq.js → vennDiagram-CIIHVFJN-BLcoN4xU.js} +2 -2
  55. package/resources/fe-dist/assets/{wardley-L42UT6IY-4VhWbg10.js → wardley-L42UT6IY-OsbD5r1L.js} +2 -2
  56. package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-Bu4k6xIx.js → wardleyDiagram-YWT4CUSO-B_33zIif.js} +2 -2
  57. package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-Cv88IDWh.js → xychartDiagram-2RQKCTM6-DcB27Ap1.js} +2 -2
  58. package/resources/fe-dist/index.html +2 -2
  59. package/resources/fe-dist/assets/DevicePage-fGI-do8S.js +0 -26
  60. package/resources/fe-dist/assets/DevicesPage-kGrzwhGj.js +0 -2
  61. package/resources/fe-dist/assets/channel-DbG6qNF6.js +0 -2
  62. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-rB1DgxOZ.js +0 -2
  63. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-rB1DgxOZ.js +0 -2
  64. package/resources/fe-dist/assets/index-cfY8KuW7.js +0 -466
  65. package/resources/fe-dist/assets/index-vcS0VPIW.css +0 -1
  66. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-CB5OePKf.js +0 -2
@@ -1,26 +0,0 @@
1
- var qt=Object.defineProperty;var Xt=(n,e,t)=>e in n?qt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>Xt(n,typeof e!="symbol"?e+"":e,t);import{Y as Ye,u as Ke,j as f,$ as Qt,r as d,d as J,a0 as kt,a1 as Lt,a2 as Jt,a3 as ht,o as xe,a4 as Zt,a5 as lt,a6 as en,b as It,a7 as at,a8 as ce,a9 as tn,c as Nt,aa as Ht,ab as _e,ac as nn,ad as je,ae as sn,B as fe,T as rn,af as ft,ag as on,ah as ln,ai as an,A as cn,f as dn,g as un,i as hn,k as fn,l as mn,m as pn,n as wn,aj as yn,ak as gn}from"./index-cfY8KuW7.js";import{R as Sn}from"./refresh-cw-cfX5JiIH.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 _n=[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]],xn=Ye("arrow-down-to-line",_n);/**
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 Tn=[["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"}]],bn=Ye("clipboard-paste",Tn);/**
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 En=[["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"}]],Cn=Ye("copy",En);/**
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 Rn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],vn=Ye("smartphone",Rn);function Mn(n){return`rgb(${n.r} ${n.g} ${n.b})`}const An=new Map([[9622,4],[9623,8],[9624,1],[9625,13],[9626,9],[9627,7],[9628,11],[9629,2],[9630,6],[9631,14]]),Dn=new Map([[9617,.25],[9618,.5],[9619,.75]]);function On(n){return n>=9600&&n<=9631}function qe(n){const e=n.getContext("2d");if(!e)throw new Error("2d canvas context unavailable");return e}class kn{constructor(e){m(this,"kind","canvas");m(this,"mainCanvas");m(this,"selectionCanvas");m(this,"cursorCanvas");m(this,"mainContext");m(this,"selectionContext");m(this,"cursorContext");m(this,"theme");m(this,"fontFamily");m(this,"fontSize");m(this,"cellDimensions",{width:9,height:17});m(this,"deviceCellWidth",9);m(this,"deviceCellHeight",17);m(this,"deviceFontSize",13);m(this,"textOffsetY",0);m(this,"dpr",1);m(this,"cols",0);m(this,"rows",0);m(this,"lastCursor",null);m(this,"frameCount",0);m(this,"lastDrawnRows",[]);m(this,"colorCache",new Map);m(this,"fontCache",new Map);m(this,"cursorBlinkVisible",!0);m(this,"cursorBlinkTimer",null);this.theme=e.theme,this.fontFamily=e.fontFamily,this.fontSize=e.fontSize,e.screenElement.style.position="relative",e.screenElement.style.overflow="hidden",this.mainCanvas=document.createElement("canvas"),this.selectionCanvas=document.createElement("canvas"),this.cursorCanvas=document.createElement("canvas");for(const[t,s]of[[this.mainCanvas,"main"],[this.selectionCanvas,"selection"],[this.cursorCanvas,"cursor"]])t.dataset.layer=s,t.style.position="absolute",t.style.inset="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",e.screenElement.appendChild(t);this.mainContext=qe(this.mainCanvas),this.selectionContext=qe(this.selectionCanvas),this.cursorContext=qe(this.cursorCanvas)}setTheme(e){this.theme=e,this.colorCache.clear()}render(e){if(this.frameCount+=1,this.lastDrawnRows=[],this.cellDimensions=e.cellDimensions,this.resize(e.meta.cols,e.meta.rows),this.drawSelection(e.selectionRects??[],e.selectionColor??this.theme.selectionBackground),e.meta.dirty==="clean"){this.drawCursor(e.meta);return}const s=e.meta.dirty==="full"?e.rows:e.rows.filter(i=>i.dirty);for(const i of s)this.drawRow(i,e.meta.colors),this.lastDrawnRows.push(i.y);this.drawCursor(e.meta)}getDebugState(){return{kind:this.kind,frameCount:this.frameCount,lastDrawnRows:[...this.lastDrawnRows]}}dispose(){this.mainCanvas.remove(),this.selectionCanvas.remove(),this.cursorCanvas.remove(),this.colorCache.clear(),this.fontCache.clear(),this.lastCursor=null,this.stopCursorBlink()}startCursorBlink(){this.cursorBlinkTimer||(this.cursorBlinkTimer=setInterval(()=>{this.cursorBlinkVisible=!this.cursorBlinkVisible,this.cursorCanvas.style.opacity=this.cursorBlinkVisible?"1":"0"},1e3))}stopCursorBlink(){this.cursorBlinkTimer&&(clearInterval(this.cursorBlinkTimer),this.cursorBlinkTimer=null),this.cursorBlinkVisible=!0,this.cursorCanvas.style.opacity="1"}resize(e,t){const s=Math.max(1,e),i=Math.max(1,t),r=Math.max(1,globalThis.devicePixelRatio??1),o=Math.max(1,Math.round(this.cellDimensions.width*r)),l=Math.max(1,Math.round(this.cellDimensions.height*r));if(this.cols===s&&this.rows===i&&this.dpr===r&&this.deviceCellWidth===o&&this.deviceCellHeight===l)return;this.cols=s,this.rows=i,this.dpr=r,this.deviceCellWidth=o,this.deviceCellHeight=l,this.deviceFontSize=this.fontSize*r,this.textOffsetY=Math.max(0,Math.round((l-this.deviceFontSize)/2));const u=s*o,h=i*l;for(const a of[this.mainCanvas,this.selectionCanvas,this.cursorCanvas])a.width=u,a.height=h,a.style.width=`${u/r}px`,a.style.height=`${h/r}px`;for(const a of[this.mainContext,this.selectionContext,this.cursorContext])a.setTransform(1,0,0,1,0,0),a.textBaseline="top",a.imageSmoothingEnabled=!1}drawSelection(e,t){if(this.selectionContext.clearRect(0,0,this.selectionCanvas.width,this.selectionCanvas.height),e.length!==0){this.selectionContext.fillStyle=t;for(const s of e)this.selectionContext.fillRect(s.x*this.deviceCellWidth,s.row*this.deviceCellHeight,s.width*this.deviceCellWidth,this.deviceCellHeight)}}drawRow(e,t){const s=e.y*this.deviceCellHeight,i=this.cols*this.deviceCellWidth,r=this.toCss(t.background),o=Math.max(1,Math.round(this.dpr));this.mainContext.clearRect(0,s,i,this.deviceCellHeight),this.mainContext.fillStyle=r,this.mainContext.fillRect(0,s,i,this.deviceCellHeight);for(const l of e.cells){if(l.widthKind==="spacer-tail"||l.widthKind==="spacer-head")continue;const u=l.x*this.deviceCellWidth,h=l.style.inverse?l.fgColor??t.foreground:l.bgColor??t.background,a=l.style.inverse?l.bgColor??t.background:l.fgColor??t.foreground,_=l.widthKind==="wide"?this.deviceCellWidth*2:this.deviceCellWidth;if((h.r!==t.background.r||h.g!==t.background.g||h.b!==t.background.b)&&(this.mainContext.fillStyle=this.toCss(h),this.mainContext.fillRect(u,s,_,this.deviceCellHeight)),!l.text||l.style.invisible)continue;this.mainContext.fillStyle=this.toCss(a);const v=l.codepoints.length===1&&On(l.codepoints[0])?l.codepoints[0]:null;v!==null?this.drawBlockElement(v,u,s,_,this.deviceCellHeight):(this.mainContext.font=this.resolveFont(l.style),this.mainContext.fillText(l.text,u,s+this.textOffsetY)),l.style.underline>0&&this.mainContext.fillRect(u,Math.min(s+this.textOffsetY+this.deviceFontSize-o,s+this.deviceCellHeight-o),Math.max(_-o,o),o),l.style.strikethrough&&this.mainContext.fillRect(u,Math.round(s+this.textOffsetY+this.deviceFontSize/2),Math.max(_-o,o),o),l.style.overline&&this.mainContext.fillRect(u,s+this.textOffsetY,Math.max(_-o,o),o)}}drawBlockElement(e,t,s,i,r){const o=this.mainContext,l=E=>Math.round(i*E/8),u=E=>Math.round(r*E/8),h=(E,b,z,w)=>{o.fillRect(t+E,s+b,z-E,w-b)};if(e===9600){h(0,0,i,u(4));return}if(e>=9601&&e<=9608){h(0,u(8-(e-9600)),i,r);return}if(e>=9609&&e<=9615){h(0,0,l(9616-e),r);return}if(e===9616){h(l(4),0,i,r);return}const a=Dn.get(e);if(a!==void 0){const E=o.globalAlpha;o.globalAlpha=E*a,h(0,0,i,r),o.globalAlpha=E;return}if(e===9620){h(0,0,i,u(1));return}if(e===9621){h(l(7),0,i,r);return}const _=An.get(e)??0,v=l(4),O=u(4);_&1&&h(0,0,v,O),_&2&&h(v,0,i,O),_&4&&h(0,O,v,r),_&8&&h(v,O,i,r)}drawCursor(e){const t=e.colors,s=e.cursor,i=this.lastCursor;if(this.cursorContext.clearRect(0,0,this.cursorCanvas.width,this.cursorCanvas.height),!s.visible||s.x===null||s.y===null){this.lastCursor=null,this.stopCursorBlink();return}const r=s.x*this.deviceCellWidth,o=s.y*this.deviceCellHeight,l=s.wideTail?this.deviceCellWidth*2:this.deviceCellWidth,u=Math.max(1,Math.round(this.dpr)),h=t.cursor??t.foreground,a=this.toCss(h);this.cursorContext.fillStyle=a,this.cursorContext.strokeStyle=a,this.cursorContext.globalAlpha=.7,this.cursorContext.fillRect(r,o+this.deviceCellHeight-2*u,Math.max(l-u,u),2*u),this.cursorContext.globalAlpha=1,this.startCursorBlink(),this.lastCursor={x:s.x,y:s.y,style:s.style},i&&(i.x!==this.lastCursor.x||i.y!==this.lastCursor.y||i.style!==this.lastCursor.style)&&this.lastDrawnRows.push(i.y)}resolveFont(e){const t=this.deviceFontSize,s=[e.italic?"italic":"normal",e.bold?"700":"400",`${t}px`,this.fontFamily].join("|"),i=this.fontCache.get(s);if(i)return i;const r=`${e.italic?"italic ":""}${e.bold?"700 ":""}${t}px ${this.fontFamily}`;return this.fontCache.set(s,r),r}toCss(e){const t=`${e.r},${e.g},${e.b}`,s=this.colorCache.get(t);if(s)return s;const i=Mn(e);return this.colorCache.set(t,i),i}}const Ln=0,In={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 mt(n){return In[n]??Ln}function Nn(n){const e=ct[n];return e?e.codePointAt(0)??null:null}const Te=0,Hn=-2,Pn=1,Bn=2,Fn=3,Gn=10,Un=11,zn=12,Yn=13,Kn=14,Vn=15,Wn=16,$n=17,jn=1,qn=2,Xn=1,Qn=2,Jn=3,Zn=4,es=5,ts=6,ns=1,ss=2,rs=3,is=4;function dt(n){if(n.disposed||n.renderStateHandle===0)throw new Error("render state resources already disposed")}function os(n){switch(n){case 2:return"full";case 1:return"partial";default:return"clean"}}function ls(n){switch(n){case 0:return"bar";case 2:return"underline";case 3:return"block-hollow";default:return"block"}}function as(n){switch(n){case 1:return"wide";case 2:return"spacer-tail";case 3:return"spacer-head";default:return"narrow"}}function Ce(n,e){return{r:n.view().getUint8(e),g:n.view().getUint8(e+1),b:n.view().getUint8(e+2)}}function pt(n,e){const t=n.bindings.allocStruct("GhosttyColorRgb");try{const s=e(t.ptr);if(s===Hn)return null;if(s!==Te)throw new Error(`ghostty optional color read failed with result ${s}`);return Ce(n.bindings,t.ptr)}finally{t.free()}}function de(n,e){const t=n.bindings.allocU8();try{const s=e(t);if(typeof s=="number"&&s!==Te)throw new Error(`ghostty bool read failed with result ${s}`);return n.bindings.readU8(t)!==0}finally{n.bindings.freeU8(t)}}function Le(n,e){const t=n.bindings.allocBytes(2);try{const s=e(t);if(typeof s=="number"&&s!==Te)throw new Error(`ghostty u16 read failed with result ${s}`);return n.bindings.view().getUint16(t,!0)}finally{n.bindings.freeBytes(t,2)}}function cs(n,e){const t=n.bindings.allocBytes(4);try{const s=e(t);if(typeof s=="number"&&s!==Te)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!==Te)throw new Error(`ghostty enum read failed with result ${s}`);return n.bindings.view().getInt32(t,!0)}finally{n.bindings.freeBytes(t,4)}}function wt(n,e){const t=n.bindings.allocBytes(8);try{const s=e(t);if(typeof s=="number"&&s!==Te)throw new Error(`ghostty u64 read failed with result ${s}`);return n.bindings.readU64(t)}finally{n.bindings.freeBytes(t,8)}}function ds(n){const e=n.bindings.allocStruct("GhosttyStyle");try{n.bindings.setField(e.view,"GhosttyStyle","size",n.bindings.typeSize("GhosttyStyle")),n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,Qn,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 us(n){const e=cs(n,s=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Jn,s));if(e===0)return[];const t=n.bindings.allocBytes(e*4);try{n.bindings.getRenderStateRowCellValue(n.rowCellsHandle,Zn,t);const s=[];for(let i=0;i<e;i+=1)s.push(n.bindings.view().getUint32(t+i*4,!0));return s}finally{n.bindings.freeBytes(t,e*4)}}function hs(n){if(n.length===0)return"";try{return String.fromCodePoint(...n)}catch{return""}}function fs(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 ms(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(Ce(n.bindings,l))}const i=e.view.getUint8(n.bindings.field("GhosttyRenderStateColors","cursor_has_value").offset)!==0,r=de(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Kn,o));return{cols:Le(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Pn,o)),rows:Le(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Bn,o)),dirty:os(st(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Fn,o))),colors:{background:Ce(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","background").offset),foreground:Ce(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","foreground").offset),cursor:i?Ce(n.bindings,e.ptr+n.bindings.field("GhosttyRenderStateColors","cursor").offset):null,palette:s},cursor:{style:ls(st(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Gn,o))),visible:de(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Un,o)),blinking:de(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,zn,o)),passwordInput:de(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Yn,o)),x:r?Le(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Vn,o)):null,y:r?Le(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,Wn,o)):null,wideTail:r?de(n,o=>n.bindings.getRenderStateValueResult(n.renderStateHandle,$n,o)):!1}}}finally{e.free()}}function ps(n,e){const t=wt(n,r=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,qn,r));n.bindings.bindRenderStateRowCells(n.rowIteratorHandle,n.rowCellsHandle);const s=[];let i=0;for(;n.bindings.nextRenderStateRowCell(n.rowCellsHandle);){const r=wt(n,h=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,Xn,h)),o=us(n),l=as(st(n,h=>n.bindings.getRawCellValueResult(r,rs,h))),u={x:i,text:hs(o),codepoints:o,widthKind:l,hasText:de(n,h=>n.bindings.getRawCellValueResult(r,is,h)),style:ds(n),fgColor:pt(n,h=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,ts,h)),bgColor:pt(n,h=>n.bindings.getRenderStateRowCellValueResult(n.rowCellsHandle,es,h))};s.push(u),i+=1}return{y:e,dirty:de(n,r=>n.bindings.getRenderStateRowValueResult(n.rowIteratorHandle,jn,r)),wrap:de(n,r=>n.bindings.getRawRowValueResult(t,ns,r)),wrapContinuation:de(n,r=>n.bindings.getRawRowValueResult(t,ss,r)),text:fs(s),cells:s}}function yt(n){return{bindings:n,renderStateHandle:n.createRenderState(),rowIteratorHandle:n.createRenderStateRowIterator(),rowCellsHandle:n.createRenderStateRowCells(),snapshotVersion:0,disposed:!1,cachedMeta:null}}function gt(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=ms(n)),n.cachedMeta}function*ws(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 ps(n,t),t+=1}function Xe(n){n.disposed||(n.disposed=!0,n.rowCellsHandle!==0&&(n.bindings.freeRenderStateRowCells(n.rowCellsHandle),n.rowCellsHandle=0),n.rowIteratorHandle!==0&&(n.bindings.freeRenderStateRowIterator(n.rowIteratorHandle),n.rowIteratorHandle=0),n.renderStateHandle!==0&&(n.bindings.freeRenderState(n.renderStateHandle),n.renderStateHandle=0),n.cachedMeta=null)}const ys={colChars:[],contentCols:0,wrappedToNext:!1};function gs(n){for(let e=n.length-1;e>=0;e-=1){const t=n[e];if(t!==null&&t!==""&&t!==" ")return e+1}return 0}function St(n,e=!1){const t=[];for(const s of n){if(s.widthKind==="spacer-tail"){t.push(null);continue}if(s.widthKind==="spacer-head"){t.push("");continue}t.push(s.text||" ")}return{colChars:t,contentCols:gs(t),wrappedToNext:e}}function Ss(n,e){return Math.max(0,Math.min(Math.max(n.colChars.length-1,0),Math.floor(e)))}function ut(n,e){let t=Ss(n,e);for(;t>0&&n.colChars[t]===null;)t-=1;return t}function Qe(n,e){let t=e;for(;t>0&&n.colChars[t]===null;)t-=1;return n.colChars[t]||""}function _t(n,e){let t=e;for(;t+1<n.colChars.length&&n.colChars[t+1]===null;)t+=1;return t}function _s(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 xs(n,e,t){if(t.colChars.length===0)return{start:{line:n,col:0},end:{line:n,col:0}};const s=ut(t,e),i=l=>/[\p{L}\p{N}_-]/u.test(l);if(!i(Qe(t,s)))return{start:{line:n,col:s},end:{line:n,col:s}};let r=s,o=s;for(;r>0&&i(Qe(t,r-1));)r-=1;for(;o+1<t.colChars.length&&i(Qe(t,o+1));)o+=1;return{start:{line:n,col:r},end:{line:n,col:o}}}function Pt(n,e){const t=Math.max(e.contentCols-1,0);return{start:{line:n,col:0},end:{line:n,col:t}}}function Bt(n,e,t){const s=t(n.line);switch(e){case"word":return xs(n.line,n.col,s);case"line":return Pt(n.line,s);default:{const i=ut(s,n.col);return{start:{line:n.line,col:i},end:{line:n.line,col:i}}}}}function Ft(){return{anchor:null,focus:null,mode:"character"}}function xt(n){return!!(n.anchor&&n.focus)}function Ts(){return Ft()}function bs(n,e,t){const s=Bt(e,e.mode,t);return{anchor:s.start,focus:s.end,mode:e.mode}}function Tt(n,e,t){return n.anchor?n.mode==="line"?{...n,focus:Pt(e.line,t(e.line)).end}:n.mode==="word"?{...n,focus:Bt(e,"word",t).end}:{...n,focus:{line:e.line,col:ut(t(e.line),e.col)}}:n}function Gt(n){return!n.anchor||!n.focus?null:_s(n.anchor,n.focus)}function Es(n,e,t){const s=n.wrappedToNext?n.colChars.length-1:n.contentCols-1,i=Math.min(t,s);let r=Math.max(0,e);for(;r>0&&n.colChars[r]===null;)r-=1;if(r>i)return"";let o="";for(let l=r;l<=i;l+=1)o+=n.colChars[l]??"";return o}function Cs(n,e){const t=Gt(n);if(!t)return null;let s="";for(let i=t.start.line;i<=t.end.line;i+=1){const r=e(i),o=i===t.start.line?t.start.col:0,l=i===t.end.line?t.end.col:r.colChars.length-1;s+=Es(r,o,l),i<t.end.line&&!r.wrappedToNext&&(s+=`
22
- `)}return s}function Rs(n,e,t,s){const i=Gt(n);if(!i)return[];const r=e+t-1,o=[];for(let l=Math.max(i.start.line,e);l<=Math.min(i.end.line,r);l+=1){const u=l-e;if(l===i.start.line&&l===i.end.line){const a=s==null?void 0:s(l),_=a?_t(a,i.end.col):i.end.col;o.push({row:u,x:i.start.col,width:_-i.start.col+1});continue}if(l===i.start.line){const a=s?Math.max(s(l).colChars.length-i.start.col,0):Number.MAX_SAFE_INTEGER;o.push({row:u,x:i.start.col,width:a});continue}if(l===i.end.line){const a=s==null?void 0:s(l),_=a?_t(a,i.end.col):i.end.col;o.push({row:u,x:0,width:_+1});continue}const h=s?s(l).colChars.length:Number.MAX_SAFE_INTEGER;o.push({row:u,x:0,width:h})}return o}function Ut(){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 it(n){return n.altKey?!1:!!(Ut()?n.metaKey:n.ctrlKey)}function vs(n){return it(n)}function Ms(n){return vs(n)&&n.key.toLowerCase()==="c"}function As(n){return n.shiftKey&&n.key==="Insert"&&!n.ctrlKey&&!n.altKey&&!n.metaKey?!0:n.altKey||n.key.toLowerCase()!=="v"?!1:!!(Ut()?n.metaKey:n.ctrlKey)}async function zt(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 Ds(n){n&&await zt(n)}function Os(n,e){return!e||!n.clipboardData?!1:(n.clipboardData.setData("text/plain",e),n.preventDefault(),!0)}const Je=/https?:\/\/[^\s"'`<>()[\]{}]+/g,ks=/[.,;:!?]+$/;function Ls(n){let e="";const t=[],s=n.colChars.length;for(let i=0;i<s;i+=1){const r=n.colChars[i];if(!(r===null||r===""))for(let o=0;o<r.length;o+=1)e+=r[o],t.push(i)}return{text:e,colOf:t}}function Is(n){let e="";const t=[],s=[];for(let o=0;o<n.length;o+=1){const l=Ls(n[o]);for(let u=0;u<l.text.length;u+=1)e+=l.text[u],t.push(o),s.push(l.colOf[u])}const i=[];Je.lastIndex=0;let r=Je.exec(e);for(;r!==null;){const o=r[0].replace(ks,"");if(o.length>0){const l=r.index,u=l+o.length-1;let h=l;for(let a=l;a<=u;a+=1)(a===u||t[a+1]!==t[a])&&(i.push({lineIndex:t[h],startCol:s[h],endCol:s[a],url:o}),h=a+1)}r=Je.exec(e)}return i}const Ns=new URL("/assets/ghostty-vt-BKQMf-5X.wasm",import.meta.url).href,Be=0,bt=-3,Hs=11,Ps=12,Bs=13,Fs=14,Gs=1,Us=2,zs=9,Ys=1,Ks=0,Vs=1,Ws=2,$s=0,js=1,qs=2,Xs=4,Qs=2004,Js=9,Zs=1e3,er=1002,tr=1003,nr=1005,Et=1006,sr=1015,Ct=1016;let Ze=null;function L(n,e){if(n!==Be)throw new Error(`${e} failed with result ${n}`)}function Yt(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 rr(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(Yt)],s=[0,95,135,175,215,255];for(const i of s)for(const r of s)for(const o of s)t.push([i,r,o]);for(let i=0;i<24;i+=1){const r=8+i*10;t.push([r,r,r])}return t}function ir(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 or(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 Kt(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 lr{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 ar{constructor(e,t){m(this,"exports");m(this,"layout");m(this,"decoder",new TextDecoder);m(this,"encoder",new TextEncoder);this.exports=e,this.layout=t}buffer(){return this.exports.memory.buffer}bytes(e=0,t=this.buffer().byteLength-e){return new Uint8Array(this.buffer(),e,t)}view(e=0,t=this.buffer().byteLength-e){return new DataView(this.buffer(),e,t)}typeSize(e){const t=this.layout[e];if(!t)throw new Error(`unknown ghostty type: ${e}`);return t.size}field(e,t){const s=this.layout[e],i=s==null?void 0:s.fields[t];if(!s||!i)throw new Error(`unknown ghostty field: ${e}.${t}`);return i}allocStruct(e){const t=this.allocBytes(this.typeSize(e));return this.bytes(t,this.typeSize(e)).fill(0),new lr(this,e,t)}allocBytes(e){return this.exports.ghostty_wasm_alloc_u8_array(e)}freeBytes(e,t){this.exports.ghostty_wasm_free_u8_array(e,t)}allocOpaque(){return this.exports.ghostty_wasm_alloc_opaque()}freeOpaque(e){this.exports.ghostty_wasm_free_opaque(e)}allocU8(){return this.exports.ghostty_wasm_alloc_u8()}freeU8(e){this.exports.ghostty_wasm_free_u8(e)}allocUsize(){return this.exports.ghostty_wasm_alloc_usize()}freeUsize(e){this.exports.ghostty_wasm_free_usize(e)}readPointer(e){return this.view().getUint32(e,!0)}readU8(e){return this.view().getUint8(e)}readUsize(e){return this.view().getUint32(e,!0)}readU64(e){return this.view().getBigUint64(e,!0)}setField(e,t,s,i){const r=this.field(t,s),o=r.offset;switch(r.type){case"u8":case"bool":e.setUint8(o,Number(i));return;case"u16":e.setUint16(o,Number(i),!0);return;case"u32":e.setUint32(o,Number(i),!0);return;case"u64":e.setBigUint64(o,BigInt(i),!0);return;case"usize":{e.setUint32(o,Number(i),!0);return}case"i32":case"enum":e.setInt32(o,Number(i),!0);return;default:throw new Error(`unsupported field type ${t}.${s}: ${r.type}`)}}writeString(e){const t=this.encoder.encode(e),s=this.allocBytes(t.length);return this.bytes(s,t.length).set(t),{ptr:s,len:t.length,free:()=>this.freeBytes(s,t.length)}}writeBytes(e){const t=this.allocBytes(e.length);return this.bytes(t,e.length).set(e),{ptr:t,len:e.length,free:()=>this.freeBytes(t,e.length)}}readOwnedUtf8(e,t){return this.decoder.decode(this.bytes(e,t))}createTerminal(e,t,s){const i=this.allocStruct("GhosttyTerminalOptions");this.setField(i.view,"GhosttyTerminalOptions","cols",e),this.setField(i.view,"GhosttyTerminalOptions","rows",t),this.setField(i.view,"GhosttyTerminalOptions","max_scrollback",s);const r=this.allocOpaque();try{return L(this.exports.ghostty_terminal_new(0,r,i.ptr),"ghostty_terminal_new"),this.readPointer(r)}finally{i.free(),this.freeOpaque(r)}}freeTerminal(e){this.exports.ghostty_terminal_free(e)}writeVt(e,t){const s=typeof t=="string"?this.encoder.encode(t):t,i=this.writeBytes(s);try{this.exports.ghostty_terminal_vt_write(e,i.ptr,i.len)}finally{i.free()}}resetTerminal(e){this.exports.ghostty_terminal_reset(e)}resizeTerminal(e,t,s,i){L(this.exports.ghostty_terminal_resize(e,t,s,Math.max(1,Math.round(i.width)),Math.max(1,Math.round(i.height))),"ghostty_terminal_resize")}scrollViewportDelta(e,t){const s=this.allocStruct("GhosttyTerminalScrollViewport");try{this.setField(s.view,"GhosttyTerminalScrollViewport","tag",Ws),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",Ks),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",Vs),this.exports.ghostty_terminal_scroll_viewport(e,t.ptr)}finally{t.free()}}setTerminalTheme(e,t){const s=this.allocStruct("GhosttyColorRgb"),i=this.allocStruct("GhosttyColorRgb"),r=this.allocStruct("GhosttyColorRgb"),o=rr(t),l=this.allocBytes(o.length*3),u=(a,_)=>{const[v,O,E]=Yt(_);this.setField(a.view,"GhosttyColorRgb","r",v),this.setField(a.view,"GhosttyColorRgb","g",O),this.setField(a.view,"GhosttyColorRgb","b",E)};u(s,t.foreground),u(i,t.background),u(r,t.cursor);const h=this.bytes(l,o.length*3);o.forEach(([a,_,v],O)=>{const E=O*3;h[E]=a,h[E+1]=_,h[E+2]=v});try{L(this.exports.ghostty_terminal_set(e,Hs,s.ptr),"ghostty_terminal_set(foreground)"),L(this.exports.ghostty_terminal_set(e,Ps,i.ptr),"ghostty_terminal_set(background)"),L(this.exports.ghostty_terminal_set(e,Bs,r.ptr),"ghostty_terminal_set(cursor)"),L(this.exports.ghostty_terminal_set(e,Fs,l),"ghostty_terminal_set(palette)")}finally{s.free(),i.free(),r.free(),this.freeBytes(l,o.length*3)}}readTerminalSize(e){const t=this.allocBytes(2),s=this.allocBytes(2);try{return L(this.exports.ghostty_terminal_get(e,Gs,t),"ghostty_terminal_get(cols)"),L(this.exports.ghostty_terminal_get(e,Us,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 L(this.exports.ghostty_terminal_get(e,zs,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 L(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){L(this.exports.ghostty_terminal_mode_set(e,t,s?1:0),"ghostty_terminal_mode_set")}createFormatter(e,t,s){const i=this.allocStruct("GhosttyFormatterTerminalOptions"),r=this.field("GhosttyFormatterTerminalOptions","extra").offset,o=this.view(i.ptr+r,this.typeSize("GhosttyFormatterTerminalExtra")),l=this.field("GhosttyFormatterTerminalExtra","screen").offset,u=this.view(i.ptr+r+l,this.typeSize("GhosttyFormatterScreenExtra")),h=this.allocOpaque();try{this.setField(i.view,"GhosttyFormatterTerminalOptions","size",this.typeSize("GhosttyFormatterTerminalOptions")),this.setField(i.view,"GhosttyFormatterTerminalOptions","emit",t),this.setField(i.view,"GhosttyFormatterTerminalOptions","unwrap",s.unwrap),this.setField(i.view,"GhosttyFormatterTerminalOptions","trim",s.trim),this.setField(o,"GhosttyFormatterTerminalExtra","size",this.typeSize("GhosttyFormatterTerminalExtra")),this.setField(o,"GhosttyFormatterTerminalExtra","palette",s.includePalette),this.setField(u,"GhosttyFormatterScreenExtra","size",this.typeSize("GhosttyFormatterScreenExtra"));const a=this.field("GhosttyFormatterTerminalOptions","selection").offset;return i.view.setUint32(a,s.selectionPtr??0,!0),L(this.exports.ghostty_formatter_terminal_new(0,h,e,i.ptr),"ghostty_formatter_terminal_new"),this.readPointer(h)}finally{i.free(),this.freeOpaque(h)}}freeFormatter(e){this.exports.ghostty_formatter_free(e)}resolveViewportGridRef(e,t,s){const i=this.allocStruct("GhosttyPoint"),r=this.allocStruct("GhosttyGridRef");try{this.setField(i.view,"GhosttyPoint","tag",Ys);const o=this.field("GhosttyPoint","value").offset,l=this.view(i.ptr+o,this.typeSize("GhosttyPointCoordinate"));return this.setField(l,"GhosttyPointCoordinate","x",t),this.setField(l,"GhosttyPointCoordinate","y",s),this.exports.ghostty_terminal_grid_ref(e,i.ptr,r.ptr)!==Be?(r.free(),null):r}finally{i.free()}}createViewportSelection(e,t,s){const i=Math.max(1,Math.floor(t)),r=Math.max(1,Math.floor(s)),o=this.resolveViewportGridRef(e,0,0);if(!o)return null;let l=null;for(let h=r-1;h>=0&&(l=this.resolveViewportGridRef(e,i-1,h),!l);h-=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 h=this.field("GhosttySelection","start").offset,a=this.field("GhosttySelection","end").offset;return this.bytes(u.ptr+h,this.typeSize("GhosttyGridRef")).set(this.bytes(o.ptr,this.typeSize("GhosttyGridRef"))),this.bytes(u.ptr+a,this.typeSize("GhosttyGridRef")).set(this.bytes(l.ptr,this.typeSize("GhosttyGridRef"))),u}finally{o.free(),l.free()}}formatViewport(e,t,s,i){const r=this.readTerminalSize(e),o=this.createViewportSelection(e,Math.max(1,Math.min(r.cols,i.cols)),Math.max(1,Math.min(r.rows,i.rows))),l=this.createFormatter(e,t,{...s,selectionPtr:(o==null?void 0:o.ptr)??null});try{return this.formatFormatter(l)}finally{this.freeFormatter(l),o==null||o.free()}}formatFormatter(e){const t=this.allocOpaque(),s=this.allocUsize();try{L(this.exports.ghostty_formatter_format_alloc(e,0,t,s),"ghostty_formatter_format_alloc");const i=this.readPointer(t),r=this.readUsize(s),o=this.buffer().byteLength;try{if(r===0||i===0)return"";if(i<0||i>o||r>o-i)throw new Error(`ghostty_formatter_format_alloc returned invalid slice ptr=${i} len=${r} mem=${o}`);return this.readOwnedUtf8(i,r)}finally{r>0&&i!==0&&this.exports.ghostty_free(0,i,r)}}finally{this.freeOpaque(t),this.freeUsize(s)}}createRenderState(){const e=this.allocOpaque();try{return L(this.exports.ghostty_render_state_new(0,e),"ghostty_render_state_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderState(e){this.exports.ghostty_render_state_free(e)}updateRenderState(e,t){L(this.exports.ghostty_render_state_update(e,t),"ghostty_render_state_update")}getRenderStateValueResult(e,t,s){return this.exports.ghostty_render_state_get(e,t,s)}getRenderStateValue(e,t,s){L(this.getRenderStateValueResult(e,t,s),"ghostty_render_state_get")}setRenderStateValue(e,t,s){L(this.exports.ghostty_render_state_set(e,t,s),"ghostty_render_state_set")}getRenderStateColors(e,t){L(this.exports.ghostty_render_state_colors_get(e,t),"ghostty_render_state_colors_get")}createRenderStateRowIterator(){const e=this.allocOpaque();try{return L(this.exports.ghostty_render_state_row_iterator_new(0,e),"ghostty_render_state_row_iterator_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowIterator(e){this.exports.ghostty_render_state_row_iterator_free(e)}bindRenderStateRowIterator(e,t){const 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){L(this.getRenderStateRowValueResult(e,t,s),"ghostty_render_state_row_get")}setRenderStateRowValue(e,t,s){L(this.exports.ghostty_render_state_row_set(e,t,s),"ghostty_render_state_row_set")}createRenderStateRowCells(){const e=this.allocOpaque();try{return L(this.exports.ghostty_render_state_row_cells_new(0,e),"ghostty_render_state_row_cells_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeRenderStateRowCells(e){this.exports.ghostty_render_state_row_cells_free(e)}bindRenderStateRowCells(e,t){const 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){L(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){L(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){L(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){L(this.getRawCellValueResult(e,t,s),"ghostty_cell_get")}createKeyEncoder(){const e=this.allocOpaque();try{return L(this.exports.ghostty_key_encoder_new(0,e),"ghostty_key_encoder_new"),this.readPointer(e)}finally{this.freeOpaque(e)}}freeKeyEncoder(e){this.exports.ghostty_key_encoder_free(e)}createMouseEncoder(){const e=this.allocOpaque(),t=this.allocU8();try{L(this.exports.ghostty_mouse_encoder_new(0,e),"ghostty_mouse_encoder_new");const s=this.readPointer(e);return this.view().setUint8(t,1),this.exports.ghostty_mouse_encoder_setopt(s,Xs,t),s}finally{this.freeU8(t),this.freeOpaque(e)}}freeMouseEncoder(e){this.exports.ghostty_mouse_encoder_free(e)}resetMouseEncoder(e){this.exports.ghostty_mouse_encoder_reset(e)}encodeMouseEvent(e,t,s){const i=this.isTerminalModeEnabled(t,tr),r=this.isTerminalModeEnabled(t,er),o=this.isTerminalModeEnabled(t,Zs),l=this.isTerminalModeEnabled(t,Js);if(!i&&!r&&!o&&!l||s.action==="motion"&&!(i||r&&s.anyButtonPressed)||l&&s.action!=="press"||!i&&!r&&!l&&s.action==="motion")return null;const u=or(s.button);if(u===null)return null;const h=Math.max(1,Math.floor(s.x/Math.max(1,s.cellWidth))+1),a=Math.max(1,Math.floor(s.y/Math.max(1,s.cellHeight))+1),_=Math.round(s.x+1),v=Math.round(s.y+1);let O=s.action==="release"&&!this.isTerminalModeEnabled(t,Et)&&!this.isTerminalModeEnabled(t,Ct)?3:u;if(s.action==="motion"&&(O+=32),O+=ir(s.mods),this.isTerminalModeEnabled(t,Ct)){const E=s.action==="release"?"m":"M";return`\x1B[<${O};${_};${v}${E}`}if(this.isTerminalModeEnabled(t,Et)){const E=s.action==="release"?"m":"M";return`\x1B[<${O};${h};${a}${E}`}if(this.isTerminalModeEnabled(t,sr))return`\x1B[${O};${h};${a}M`;if(this.isTerminalModeEnabled(t,nr)||o||r||i||l){const E=et(O),b=et(h),z=et(a);return!E||!b||!z?null:`\x1B[M${E}${b}${z}`}return null}encodeKeyEvent(e,t,s){if(s.keyCode<=0)return null;const i=this.allocOpaque();let r=0,o=null;try{return L(this.exports.ghostty_key_event_new(0,i),"ghostty_key_event_new"),r=this.readPointer(i),this.exports.ghostty_key_encoder_setopt_from_terminal(e,t),this.exports.ghostty_key_event_set_action(r,s.action==="release"?$s:s.action==="repeat"?qs:js),this.exports.ghostty_key_event_set_key(r,s.keyCode),this.exports.ghostty_key_event_set_mods(r,s.mods),this.exports.ghostty_key_event_set_consumed_mods(r,0),this.exports.ghostty_key_event_set_composing(r,s.composing?1:0),s.utf8&&(o=this.writeString(s.utf8),this.exports.ghostty_key_event_set_utf8(r,o.ptr,o.len)),typeof s.unshiftedCodepoint=="number"&&this.exports.ghostty_key_event_set_unshifted_codepoint(r,s.unshiftedCodepoint),this.encodeKeyHandle(e,r)}finally{o==null||o.free(),r!==0&&this.exports.ghostty_key_event_free(r),this.freeOpaque(i)}}encodeKeyHandle(e,t){const s=this.allocUsize();try{const i=this.exports.ghostty_key_encoder_encode(e,t,0,0,s);i!==bt&&i!==Be&&L(i,"ghostty_key_encoder_encode(size)");const r=Math.max(0,this.readUsize(s));if(r===0)return null;const o=this.allocBytes(r),l=this.allocUsize();try{L(this.exports.ghostty_key_encoder_encode(e,t,o,r,l),"ghostty_key_encoder_encode");const u=this.readUsize(l);return u===0?null:this.readOwnedUtf8(o,u)}finally{this.freeBytes(o,r),this.freeUsize(l)}}finally{this.freeUsize(s)}}encodePaste(e,t){const s=this.writeString(t),i=this.allocUsize();try{const r=this.isTerminalModeEnabled(e,Qs),o=this.exports.ghostty_paste_encode(s.ptr,s.len,r?1:0,0,0,i);o!==bt&&o!==Be&&L(o,"ghostty_paste_encode(size)");const l=Math.max(0,this.readUsize(i));if(l===0)return"";const u=this.allocBytes(l),h=this.allocUsize();try{return L(this.exports.ghostty_paste_encode(s.ptr,s.len,r?1:0,u,l,h),"ghostty_paste_encode"),this.readOwnedUtf8(u,this.readUsize(h))}finally{this.freeBytes(u,l),this.freeUsize(h)}}finally{s.free(),this.freeUsize(i)}}}async function cr(n){const e=n.startsWith("file://"),t=e?decodeURIComponent(new URL(n).pathname):n;if((e||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")||/^[A-Za-z]:[\\/]/.test(t))&&typeof Bun<"u")return Bun.file(t).arrayBuffer();const i=await fetch(n);if(!i.ok)throw new Error(`failed to load ghostty wasm: ${i.status} ${i.statusText}`);return i.arrayBuffer()}async function dr(){return Ze||(Ze=(async()=>{const n=await cr(Ns),t=(await WebAssembly.instantiate(n,{env:{log(){}}})).instance.exports,s=new Uint8Array(t.memory.buffer),i=t.ghostty_type_json();let r=i;for(;s[r]!==0;)r+=1;const o=JSON.parse(new TextDecoder().decode(s.subarray(i,r)));return new ar(t,o)})()),Ze}const Rt=80,Re=24,tt=9,Ie=17,ur=48,Vt="ghostty-official",Fe=9,Ge=1e3,Ue=1002,ze=1003,nt=1007,Ne=1047,He=1049,hr=[Fe,Ge,Ue,ze],vt=1,Mt=3,At=2,fr=4,mr=5;class pr{constructor(e){this.content=e}translateToString(e){return e?this.content.replace(/\s+$/u,""):this.content}}class wr{constructor(){m(this,"active",{baseY:0,viewportY:0,length:Re,getLine:e=>{const t=e-this.active.viewportY,s=this.visibleLines[t];return typeof s=="string"?new pr(s):null}});m(this,"visibleLines",Array.from({length:Re},()=>""))}setViewport(e,t,s,i){this.active.viewportY=e,this.active.baseY=t,this.active.length=s,this.visibleLines=i}}const yr={deleteContentBackward:"Backspace",deleteContentForward:"Delete",insertLineBreak:"Enter",insertParagraph:"Enter"};function gr(n){return!(n.key.length===1&&!n.ctrlKey&&!n.altKey&&!n.metaKey)}function Sr(n,e){const t=n.slice(0,e).map(s=>s.text);for(;t.length<e;)t.push("");return t}function Pe(n){return Kt({shiftKey:!!n.shiftKey,ctrlKey:!!n.ctrlKey,altKey:!!n.altKey,metaKey:!!n.metaKey,getModifierState:()=>!1})}class _r{constructor(){m(this,"terminal",null)}activate(e){this.terminal=e instanceof Ve?e:null}fit(){const e=this.proposeDimensions();!this.terminal||!e||this.terminal.resize(e.cols,e.rows)}proposeDimensions(){var e;return((e=this.terminal)==null?void 0:e.measureSizeFromElement())??null}dispose(){this.terminal=null}}class Ve{constructor(e,t,s,i,r,o){m(this,"buffer",new wr);m(this,"_core",{_renderService:{dimensions:{css:{cell:{width:tt,height:Ie}}}}});m(this,"options");m(this,"element",null);m(this,"textarea",null);m(this,"cols",Rt);m(this,"rows",Re);m(this,"bindings");m(this,"terminalHandle");m(this,"keyEncoderHandle");m(this,"mouseEncoderHandle");m(this,"renderState");m(this,"dataListeners",new Set);m(this,"selectionListeners",new Set);m(this,"linkListeners",new Set);m(this,"linkCursorActive",!1);m(this,"lastNotifiedSelectionText",null);m(this,"addons",new Set);m(this,"screenElement",null);m(this,"renderer",null);m(this,"renderRaf",null);m(this,"disposed",!1);m(this,"disableStdin");m(this,"customKeyEventHandler",()=>!0);m(this,"imeIsComposing",!1);m(this,"lastCompositionCommit",null);m(this,"selectionState",Ft());m(this,"lineCache",new Map);m(this,"lastViewportOffset",0);m(this,"lastViewportRows",Re);m(this,"lastRenderedRows",[]);m(this,"pointerDrag",{active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null});m(this,"autoScrollTimer",null);m(this,"domEventDisposers",[]);m(this,"copyShortcutSuppressed",!1);m(this,"scrollbarThumb",null);m(this,"scrollbarFadeTimer",null);m(this,"pressedMouseButtons",new Set);m(this,"wheelPixelDelta",0);m(this,"mouseDragActive",!1);this.bindings=e,this.terminalHandle=t,this.keyEncoderHandle=s,this.mouseEncoderHandle=i,this.renderState=r,this.options=o,this.disableStdin=!!o.disableStdin}static async create(e){const t=await dr(),s=t.createTerminal(Rt,Re,e.scrollback);let i=0,r=0,o=null;try{return t.setTerminalTheme(s,e.theme),i=t.createKeyEncoder(),r=t.createMouseEncoder(),o=yt(t),new Ve(t,s,i,r,o,e)}catch(l){throw o&&Xe(o),i!==0&&t.freeKeyEncoder(i),r!==0&&t.freeMouseEncoder(r),t.freeTerminal(s),l}}open(e){if(this.disposed||this.element)return;const t=document.createElement("div");t.className="xterm",t.style.position="absolute",t.style.inset="0",t.style.overflow="hidden",t.style.width="100%",t.style.height="100%",t.style.backgroundColor=this.options.theme.background,t.style.color=this.options.theme.foreground,t.style.fontFamily=this.options.fontFamily,t.style.fontSize=`${this.options.fontSize}px`,t.style.lineHeight="1.2";const s=document.createElement("div");s.className="xterm-viewport",s.style.width="100%",s.style.height="100%",s.style.overflow="hidden",s.style.position="relative";const i=document.createElement("div");i.className="xterm-screen",i.style.width="100%",i.style.height="100%",i.style.position="relative",i.style.userSelect="none",i.style.webkitUserSelect="none",i.style.backgroundColor=this.options.theme.background;const r=document.createElement("div");r.className="xterm-helper-textarea",r.setAttribute("aria-label","Terminal Input"),r.setAttribute("role","textbox"),r.setAttribute("contenteditable","true"),r.setAttribute("autocorrect","off"),r.setAttribute("autocapitalize","off"),r.setAttribute("spellcheck","false"),r.style.position="absolute",r.style.opacity="1",r.style.pointerEvents="none",r.style.left="0",r.style.top="0",r.style.minWidth="1px",r.style.minHeight="1px",r.style.whiteSpace="pre",r.style.border="0",r.style.padding="0",r.style.margin="0",r.style.color=this.options.theme.foreground,r.style.backgroundColor="transparent",r.style.caretColor="transparent",r.style.overflow="visible",r.style.outline="none",r.style.boxShadow="none",r.style.fontFamily=this.options.fontFamily,r.style.fontSize=`${this.options.fontSize}px`,r.style.userSelect="text",r.style.webkitUserSelect="text";const o=document.createElement("div");o.className="xterm-scrollbar-track",o.style.position="absolute",o.style.top="0",o.style.right="0",o.style.width="8px",o.style.height="100%",o.style.backgroundColor="transparent",o.style.pointerEvents="none";const l=document.createElement("div");l.className="xterm-scrollbar-thumb",l.style.position="absolute",l.style.top="0",l.style.right="0",l.style.width="6px",l.style.marginRight="1px",l.style.borderRadius="3px",l.style.backgroundColor="rgba(128, 128, 128, 0.5)",l.style.pointerEvents="none",l.style.transition="opacity 0.15s ease",l.style.opacity="0",o.appendChild(l),s.appendChild(i),t.appendChild(s),t.appendChild(r),t.appendChild(o),e.appendChild(t),this.element=t,this.screenElement=i,this.textarea=r,this.scrollbarThumb=l,this.renderer=new kn({screenElement:i,theme:this.options.theme,fontFamily:this.options.fontFamily,fontSize:this.options.fontSize}),this.syncInputState(),this.bindDomEvents(),this.updateCellDimensions();const u=this.measureSizeFromElement();u?this.resize(u.cols,u.rows):this.render()}loadAddon(e){e.activate(this),this.addons.add(e)}onData(e){return this.dataListeners.add(e),{dispose:()=>{this.dataListeners.delete(e)}}}attachCustomKeyEventHandler(e){this.customKeyEventHandler=e}onSelectionChange(e){return this.selectionListeners.add(e),{dispose:()=>{this.selectionListeners.delete(e)}}}onLinkActivated(e){return this.linkListeners.add(e),{dispose:()=>{this.linkListeners.delete(e)}}}hasSelection(){return xt(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 hr)this.bindings.setTerminalMode(this.terminalHandle,e,!1);this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.pressedMouseButtons.clear(),this.mouseDragActive=!1}}isAltScreenActive(){return this.isModeEnabled(Ne)||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)),i=Math.max(2,Math.floor(t));this.cols=s,this.rows=i,this.clearSelectionState(!1),this.bindings.resizeTerminal(this.terminalHandle,s,i,this.cellDimensions()),this.bindings.resetMouseEncoder(this.mouseEncoderHandle),this.scheduleRender()}scrollLines(e){this.disposed||e===0||(this.bindings.scrollViewportDelta(this.terminalHandle,e),this.render())}scrollToTop(){this.disposed||(this.bindings.scrollViewportTop(this.terminalHandle),this.render())}scrollToBottom(){this.disposed||(this.bindings.scrollViewportBottom(this.terminalHandle),this.render())}exportModeSnapshot(){return{mouseX10:this.isModeEnabled(Fe),mouseNormal:this.isModeEnabled(Ge),mouseButton:this.isModeEnabled(Ue),mouseAny:this.isModeEnabled(ze),mouseUtf8:this.isModeEnabled(1005),mouseSgr:this.isModeEnabled(1006),mouseSgrPixels:this.isModeEnabled(1016),mouseUrxvt:this.isModeEnabled(1015),altScroll:this.isModeEnabled(nt),altScreen1047:this.isModeEnabled(Ne),altScreen1049:this.isModeEnabled(He)}}restoreModeSnapshot(e){this.bindings.setTerminalMode(this.terminalHandle,Fe,e.mouseX10),this.bindings.setTerminalMode(this.terminalHandle,Ge,e.mouseNormal),this.bindings.setTerminalMode(this.terminalHandle,Ue,e.mouseButton),this.bindings.setTerminalMode(this.terminalHandle,ze,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,Ne,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 i=t<0?fr:mr;let r=!1;for(let o=0;o<Math.abs(t);o+=1)r=this.emitMouseInput({action:"press",button:i,clientX:e.clientX,clientY:e.clientY,mods:Pe(e),anyButtonPressed:this.pressedMouseButtons.size>0})||r;return r}return s.altScroll?this.emitAltScrollInput(t):(this.scrollLines(t),!0)}paste(e){if(this.disposed||this.disableStdin||!e)return;const t=this.bindings.encodePaste(this.terminalHandle,e);t&&this.emitData(t)}focus(){var e;(e=this.textarea)==null||e.focus({preventScroll:!0})}getRendererKind(){var e;return((e=this.renderer)==null?void 0:e.kind)??"unknown"}setTheme(e){var t;this.bindings.setTerminalTheme(this.terminalHandle,e),this.options.theme=e,this.element&&(this.element.style.backgroundColor=e.background,this.element.style.color=e.foreground),this.screenElement&&(this.screenElement.style.backgroundColor=e.background),(t=this.renderer)==null||t.setTheme(e),this.scheduleRender()}setDisableStdin(e){this.disableStdin=e,this.syncInputState()}measureSizeFromElement(){const e=this.element;if(!e)return null;const t=e.getBoundingClientRect(),{width:s,height:i}=this.cellDimensions();return t.width===0||t.height===0||s<=0||i<=0?null:{cols:Math.max(2,Math.floor(t.width/s)),rows:Math.max(2,Math.floor(t.height/i))}}dispose(){var e,t;if(!this.disposed){this.disposed=!0,this.renderRaf!==null&&(cancelAnimationFrame(this.renderRaf),this.renderRaf=null),this.stopAutoScroll(),this.updateSelectionTextProbe(null),this.clearDomEventListeners(),this.scrollbarFadeTimer&&(clearTimeout(this.scrollbarFadeTimer),this.scrollbarFadeTimer=null);for(const s of this.addons)s.dispose();this.addons.clear(),(e=this.renderer)==null||e.dispose(),this.renderer=null,(t=this.element)==null||t.remove(),this.element=null,this.screenElement=null,this.textarea=null,this.scrollbarThumb=null,Xe(this.renderState),this.bindings.freeMouseEncoder(this.mouseEncoderHandle),this.bindings.freeKeyEncoder(this.keyEncoderHandle),this.bindings.freeTerminal(this.terminalHandle)}}cellDimensions(){return this._core._renderService.dimensions.css.cell}syncInputState(){this.textarea&&(this.textarea.readOnly=this.disableStdin,this.textarea.tabIndex=this.disableStdin?-1:0,this.disableStdin&&document.activeElement===this.textarea&&this.textarea.blur())}bindDomEvents(){const e=this.element,t=this.textarea;if(!e||!t)return;e.addEventListener("click",()=>{this.disableStdin||this.focus()});const s=this.screenElement??e;s.addEventListener("mousedown",r=>{if(r instanceof MouseEvent){if(this.disableStdin||this.focus(),this.getInputRoutingState().mouseReporting){const o=this.mouseButtonFromEvent(r);if(o===null)return;this.clearSelectionState(),this.pressedMouseButtons.add(o),this.mouseDragActive=!0,this.emitMouseInput({action:"press",button:o,clientX:r.clientX,clientY:r.clientY,mods:Pe(r),anyButtonPressed:!0}),r.preventDefault();return}if(r.button===0&&it(r)){const o=this.linkAtClient(r.clientX,r.clientY);if(o){this.emitLinkActivated(o),r.preventDefault();return}}r.button===0&&(this.mouseDragActive=!0,this.beginPointerSelection(r),r.preventDefault())}}),s.addEventListener("mousemove",r=>{if(!(!(r instanceof MouseEvent)||this.mouseDragActive)){if(this.getInputRoutingState().mouseReporting){this.setLinkCursor(!1);return}this.setLinkCursor(it(r)&&this.linkAtClient(r.clientX,r.clientY)!==null)}}),s.addEventListener("mouseleave",()=>{this.setLinkCursor(!1)}),e.addEventListener("wheel",r=>{this.handleViewportGesture({source:"wheel",deltaY:r.deltaY,deltaMode:r.deltaMode,clientX:r.clientX,clientY:r.clientY,shiftKey:r.shiftKey,ctrlKey:r.ctrlKey,altKey:r.altKey,metaKey:r.metaKey})&&r.preventDefault()},{passive:!1});const i=typeof window<"u"&&typeof window.addEventListener=="function"?window:null;if(i){const r=l=>{if(this.mouseDragActive){if(this.getInputRoutingState().mouseReporting){this.emitMouseInput({action:"motion",button:this.mouseButtonFromButtons(l.buttons),clientX:l.clientX,clientY:l.clientY,mods:Pe(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:Pe(l),anyButtonPressed:this.pressedMouseButtons.size>0});return}this.finishPointerSelection(l)}};i.addEventListener("mousemove",r),i.addEventListener("mouseup",o),this.domEventDisposers.push(()=>{i.removeEventListener("mousemove",r),i.removeEventListener("mouseup",o)})}t.addEventListener("keydown",r=>{const o=this.getSelectionText();if(o&&Ms(r)){r.preventDefault(),Ds(o).catch(()=>{}),this.clearSelectionState(),this.copyShortcutSuppressed=!0,this.clearTextarea();return}if(!this.customKeyEventHandler(r)||this.disableStdin||this.imeIsComposing||r.keyCode===229||As(r)||!gr(r))return;const l=this.encodeKeyboardEvent(r,r.repeat?"repeat":"press");l&&(r.preventDefault(),this.emitData(l),this.clearTextarea())}),t.addEventListener("keyup",r=>{if(this.copyShortcutSuppressed){const l=r.key.toLowerCase();if(l==="c"){r.preventDefault();return}if(l==="control"||l==="meta"||l==="os"){this.copyShortcutSuppressed=!1,r.preventDefault();return}}if(this.disableStdin||this.imeIsComposing)return;const o=this.encodeKeyboardEvent(r,"release");o&&(r.preventDefault(),this.emitData(o),this.clearTextarea())}),t.addEventListener("compositionstart",()=>{this.imeIsComposing=!0,this.lastCompositionCommit=null,this.syncTextareaPositionToCursor()}),t.addEventListener("compositionupdate",()=>{this.syncTextareaPositionToCursor()}),t.addEventListener("compositionend",r=>{this.imeIsComposing=!1;const o=r.data??"";o&&(this.lastCompositionCommit={data:o,at:Date.now()},this.emitData(o),this.clearTextarea())}),t.addEventListener("beforeinput",r=>{if(this.disableStdin||r.inputType==="insertFromPaste"||r.isComposing||this.imeIsComposing)return;const o=yr[r.inputType??""];if(o){r.preventDefault();const h=this.encodeSyntheticKey(o);h&&this.emitData(h),this.clearTextarea();return}const l=r.data??"";if(!l)return;const u=this.lastCompositionCommit;if(u&&u.data===l&&Date.now()-u.at<40){this.lastCompositionCommit=null,r.preventDefault(),this.clearTextarea();return}this.lastCompositionCommit=null,r.preventDefault(),this.emitData(l),this.clearTextarea()}),t.addEventListener("paste",r=>{var l;if(this.disableStdin)return;const o=((l=r.clipboardData)==null?void 0:l.getData("text/plain"))??"";o&&(r.preventDefault(),this.paste(o),this.clearTextarea())}),t.addEventListener("copy",r=>{const o=this.getSelectionText();o&&Os(r,o)}),t.addEventListener("input",()=>{if(this.disableStdin||this.imeIsComposing)return;const r=t.textContent??"";if(!r){this.clearTextarea();return}const o=this.lastCompositionCommit;if(o&&o.data===r&&Date.now()-o.at<40){this.lastCompositionCommit=null,this.clearTextarea();return}this.lastCompositionCommit=null,this.emitData(r),this.clearTextarea()})}encodeKeyboardEvent(e,t){const s=mt(e.code);if(s===0)return null;const i=e.key.length===1&&!e.ctrlKey&&!e.metaKey?e.key:null;return this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:t,keyCode:s,mods:Kt(e),composing:e.isComposing,utf8:i,unshiftedCodepoint:Nn(e.code)})}encodeSyntheticKey(e){const t={code:e,key:e,shiftKey:!1,ctrlKey:!1,altKey:!1,metaKey:!1,repeat:!1,isComposing:!1,getModifierState:()=>!1};return this.encodeKeyboardEvent(t,"press")}getInputRoutingState(){const e=this.isModeEnabled(Fe)||this.isModeEnabled(Ge)||this.isModeEnabled(Ue)||this.isModeEnabled(ze),t=this.isModeEnabled(Ne)||this.isModeEnabled(He);return{mouseReporting:e,altScroll:!e&&t&&this.isModeEnabled(nt)}}gestureToLines(e){const t=this.cellDimensions().height||Ie;if(e.source==="wheel"){if(e.deltaMode===1)return this.wheelPixelDelta=0,e.deltaY>0?Math.ceil(e.deltaY):Math.floor(e.deltaY);if(e.deltaMode===2){this.wheelPixelDelta=0;const i=Math.max(1,this.rows),r=e.deltaY*i;return r>0?Math.ceil(r):Math.floor(r)}this.wheelPixelDelta+=e.deltaY;const s=this.wheelPixelDelta>0?Math.floor(this.wheelPixelDelta/t):Math.ceil(this.wheelPixelDelta/t);return s!==0&&(this.wheelPixelDelta-=s*t),s}return e.deltaY>0?Math.ceil(e.deltaY/t):Math.floor(e.deltaY/t)}isModeEnabled(e){return this.bindings.isTerminalModeEnabled(this.terminalHandle,e)}mouseButtonFromEvent(e){switch(e.button){case 0:return vt;case 1:return Mt;case 2:return At;default:return null}}mouseButtonFromButtons(e){return e&1?vt:e&4?Mt:e&2?At:null}pointerPositionFromClient(e,t){var o;const s=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!s)return null;const i=Math.max(1,s.width),r=Math.max(1,s.height);return{x:Math.max(0,Math.min(i-1,e-s.left)),y:Math.max(0,Math.min(r-1,t-s.top))}}emitMouseInput(e){var o;if(this.disableStdin)return!1;const t=this.pointerPositionFromClient(e.clientX,e.clientY);if(!t)return!1;const s=this.cellDimensions(),i=(o=this.screenElement)==null?void 0:o.getBoundingClientRect();if(!i)return!1;const r=this.bindings.encodeMouseEvent(this.mouseEncoderHandle,this.terminalHandle,{action:e.action,button:e.button,mods:e.mods,x:t.x,y:t.y,anyButtonPressed:e.anyButtonPressed,screenWidth:Math.max(1,Math.round(i.width)),screenHeight:Math.max(1,Math.round(i.height)),cellWidth:Math.max(1,Math.round(s.width||tt)),cellHeight:Math.max(1,Math.round(s.height||Ie))});return r?(this.emitData(r),!0):!1}emitAltScrollInput(e){const t=mt(e<0?"ArrowUp":"ArrowDown");if(t===0)return!1;let s=!1;for(let i=0;i<Math.abs(e);i+=1){const r=this.bindings.encodeKeyEvent(this.keyEncoderHandle,this.terminalHandle,{action:"press",keyCode:t,mods:0,composing:!1,utf8:null,unshiftedCodepoint:null});r&&(this.emitData(r),s=!0)}return s}emitData(e){for(const t of this.dataListeners)t(e)}clearTextarea(){this.textarea&&(this.textarea.textContent="")}syncTextareaPositionToCursor(){const e=this.textarea,t=this.screenElement;if(!e||!t)return;const{width:s,height:i}=this.cellDimensions();if(s<=0||i<=0)return;const r=yt(this.bindings);let o=0,l=0;try{gt(r,this.terminalHandle);const a=rt(r);a.cursor.x!==null&&a.cursor.y!==null&&(o=a.cursor.x,l=a.cursor.y)}finally{Xe(r)}const u=o*s,h=l*i;e.style.left=`${u}px`,e.style.top=`${h}px`,e.style.width=`${Math.max(1,s)}px`,e.style.height=`${Math.max(1,i)}px`,e.style.lineHeight=`${i}px`,e.style.fontFamily=this.options.fontFamily,e.style.fontSize=`${this.options.fontSize}px`}scheduleRender(){this.renderRaf===null&&(this.renderRaf=requestAnimationFrame(()=>{this.renderRaf=null,this.render()}))}render(){if(this.disposed||!this.screenElement||!this.renderer)return;const e=this.bindings.readScrollbar(this.terminalHandle),t=Math.max(1,e.len||this.rows);gt(this.renderState,this.terminalHandle);const s=rt(this.renderState),i=Array.from(ws(this.renderState));this.cols=Math.max(2,s.cols),this.rows=Math.max(2,s.rows||t),this.lastViewportOffset=e.offset,this.lastViewportRows=this.rows,this.lastRenderedRows=i;for(const h of i)this.lineCache.set(e.offset+h.y,St(h.cells,h.wrap));const r=Rs(this.selectionState,this.lastViewportOffset,this.lastViewportRows,h=>this.getLineModel(h)),o=this.getSelectionText();this.renderer.render({meta:s,rows:i,cellDimensions:this.cellDimensions(),selectionRects:r,selectionColor:this.options.theme.selectionBackground});const l=Sr(i,this.rows),u=Math.max(0,e.total-e.len);this.buffer.setViewport(e.offset,u,e.total,l),this.updateSelectionTextProbe(o),this.updateScrollbar(e)}updateScrollbar(e){var u;const t=this.scrollbarThumb;if(!t)return;const s=((u=this.screenElement)==null?void 0:u.clientHeight)??0;if(s===0||e.total<=e.len){t.style.opacity="0";return}const i=e.len/e.total,r=Math.max(20,i*s),l=e.offset/Math.max(1,e.total-e.len)*(s-r);t.style.height=`${r}px`,t.style.transform=`translateY(${l}px)`,t.style.opacity="1",this.scrollbarFadeTimer&&clearTimeout(this.scrollbarFadeTimer),this.scrollbarFadeTimer=setTimeout(()=>{t.style.opacity="0"},800)}updateCellDimensions(){if(!this.element)return;const e=document.createElement("span");e.textContent="WWWWWWWWWW",e.style.position="absolute",e.style.visibility="hidden",e.style.whiteSpace="pre",e.style.fontFamily=this.options.fontFamily,e.style.fontSize=`${this.options.fontSize}px`,e.style.lineHeight="1.2",this.element.appendChild(e);const t=e.getBoundingClientRect();e.remove();const s=Math.max(1,globalThis.devicePixelRatio??1),i=t.width>0?t.width/10:tt,r=t.height>0?t.height:Ie;this._core._renderService.dimensions.css.cell.width=Math.max(1,Math.round(i*s))/s,this._core._renderService.dimensions.css.cell.height=Math.max(1,Math.round(r*s))/s}clearSelectionState(e=!0){this.selectionState=Ts(),this.pressedMouseButtons.clear(),this.wheelPixelDelta=0,this.pointerDrag={active:!1,moved:!1,mode:"character",lastClientX:null,lastClientY:null},this.copyShortcutSuppressed=!1,this.stopAutoScroll(),this.updateSelectionTextProbe(null),e&&this.screenElement&&this.renderer&&this.render()}beginSelectionAt(e,t,s){const i=this.hitTest(e,t);return i?(this.pointerDrag={active:!0,moved:!1,mode:s,lastClientX:e,lastClientY:t},this.selectionState=bs(this.selectionState,{...i,mode:s},r=>this.getLineModel(r)),this.updateAutoScroll(),this.render(),!0):!1}updateSelectionDrag(e,t){if(!this.pointerDrag.active)return;const s=this.hitTest(e,t);this.pointerDrag.lastClientX=e,this.pointerDrag.lastClientY=t,s&&(this.pointerDrag.moved=!0,this.selectionState=Tt(this.selectionState,s,i=>this.getLineModel(i)),this.render()),this.updateAutoScroll()}beginPointerSelection(e){this.beginSelectionAt(e.clientX,e.clientY,this.selectionModeFromClickDetail(e.detail))}updatePointerSelection(e){this.updateSelectionDrag(e.clientX,e.clientY)}finishPointerSelection(e){var s,i,r,o;if(!this.pointerDrag.active||e.button!==0)return;this.pointerDrag.lastClientX=e.clientX,this.pointerDrag.lastClientY=e.clientY,this.stopAutoScroll();const t=this.pointerDrag.mode==="character"&&!this.pointerDrag.moved&&((s=this.selectionState.anchor)==null?void 0:s.line)===((i=this.selectionState.focus)==null?void 0:i.line)&&((r=this.selectionState.anchor)==null?void 0:r.col)===((o=this.selectionState.focus)==null?void 0:o.col);if(this.pointerDrag.active=!1,t){this.clearSelectionState();return}this.render()}selectionModeFromClickDetail(e){return e>=3?"line":e===2?"word":"character"}hitTest(e,t){var v;const s=(v=this.screenElement)==null?void 0:v.getBoundingClientRect();if(!s)return null;const{width:i,height:r}=this.cellDimensions();if(i<=0||r<=0)return null;const o=e-s.left,l=t-s.top,u=Math.max(this.cols-1,0),h=Math.max(this.lastViewportRows-1,0),a=Math.max(0,Math.min(u,Math.floor(o/i))),_=Math.max(0,Math.min(h,Math.floor(l/r)));return{line:this.lastViewportOffset+_,col:a}}getLineModel(e){const t=this.lineCache.get(e);if(t)return t;const s=e-this.lastViewportOffset,i=this.lastRenderedRows[s];return i?St(i.cells,i.wrap):ys}emitLinkActivated(e){for(const t of this.linkListeners)t(e)}setLinkCursor(e){this.linkCursorActive!==e&&(this.linkCursorActive=e,this.screenElement&&(this.screenElement.style.cursor=e?"pointer":""))}linkAtClient(e,t){const s=this.hitTest(e,t);return s?this.linkAtPoint(s.line,s.col):null}linkAtPoint(e,t){if(this.getLineModel(e).colChars.length===0)return null;let s=e;for(;this.getLineModel(s-1).wrappedToNext;)s-=1;let i=e;for(;this.getLineModel(i).wrappedToNext;)i+=1;const r=[];for(let l=s;l<=i;l+=1)r.push(this.getLineModel(l));const o=e-s;for(const l of Is(r))if(l.lineIndex===o&&t>=l.startCol&&t<=l.endCol)return l.url;return null}getSelectionText(){return xt(this.selectionState)?Cs(this.selectionState,e=>this.getLineModel(e)):null}updateSelectionTextProbe(e){if(globalThis.__tmexE2eTerminalSelectionText=e,e!==this.lastNotifiedSelectionText){this.lastNotifiedSelectionText=e;for(const t of this.selectionListeners)t(e)}}updateAutoScroll(){var s;if(!this.pointerDrag.active||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(s=this.screenElement)==null?void 0:s.getBoundingClientRect();if(!e){this.stopAutoScroll();return}if(!(this.pointerDrag.lastClientY<e.top||this.pointerDrag.lastClientY>e.bottom)){this.stopAutoScroll();return}this.autoScrollTimer===null&&(this.autoScrollTimer=setInterval(()=>{this.stepAutoScroll()},ur))}stepAutoScroll(){var i;if(!this.pointerDrag.active||this.pointerDrag.lastClientX===null||this.pointerDrag.lastClientY===null){this.stopAutoScroll();return}const e=(i=this.screenElement)==null?void 0:i.getBoundingClientRect();if(!e){this.stopAutoScroll();return}let t=0;if(this.pointerDrag.lastClientY<e.top?t=-1:this.pointerDrag.lastClientY>e.bottom&&(t=1),t===0){this.stopAutoScroll();return}this.bindings.scrollViewportDelta(this.terminalHandle,t),this.render();const s=this.hitTest(this.pointerDrag.lastClientX,this.pointerDrag.lastClientY);s&&(this.selectionState=Tt(this.selectionState,s,r=>this.getLineModel(r)),this.pointerDrag.moved=!0,this.render())}stopAutoScroll(){this.autoScrollTimer!==null&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null)}clearDomEventListeners(){for(;this.domEventDisposers.length>0;){const e=this.domEventDisposers.pop();e==null||e()}}}async function xr(n){return Ve.create(n)}function Tr({visible:n,canPaste:e,onCopy:t,onPaste:s,onDismiss:i}){const{t:r}=Ke();if(!n)return null;const o=l=>{l.preventDefault()};return f.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:[f.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:[f.jsx(Cn,{className:"h-4 w-4"}),r("terminal.copy")]}),e&&f.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:[f.jsx(bn,{className:"h-4 w-4"}),r("terminal.paste")]}),f.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:o,onClick:i,"aria-label":r("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:f.jsx(Qt,{className:"h-4 w-4"})})]})}function Wt(n){if(!n)return n;const e=n.replace(/\r\n/g,`
23
- `);return(e.endsWith(`
24
- `)?e.slice(0,-1):e).replace(/\n/g,`\r
25
- `)}const br="\x1B[?1049h\x1B[H\x1B[2J";function Er(n){return br+Wt(n)}function Dt(n,e){let t=e,s=0;for(const l of n)l===10&&!t&&(s+=1),t=l===13;const i=t;if(s===0)return{normalized:n,endedWithCR:i};const r=new Uint8Array(n.length+s);let o=0;t=e;for(const l of n)l===10&&!t&&(r[o]=13,o+=1),r[o]=l,o+=1,t=l===13;return{normalized:r,endedWithCR:i}}const Cr=1.3,Rr=36,vr=500,Mr=12;function Ar(n,e){const t=d.useRef(!1);return d.useEffect(()=>{const s=n.current;if(!s||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;t.current=!0;let r=0,o=null,l=!1,u=0,h=0,a=0,_=null,v=!1;const O=()=>{_!==null&&(clearTimeout(_),_=null)},E=T=>T?!!(T.closest(".scrollbar")||T.closest(".slider")||T.closest(".xterm-scroll-area")):!1,b=(T,C,H)=>{const U=H instanceof Element?H:null;if(E(U))return!0;const Q=document.elementFromPoint(T,C);if(E(Q))return!0;const x=s.querySelector(".xterm");if(!(x instanceof HTMLElement))return!1;const R=x.getBoundingClientRect(),F=T>=R.left&&T<=R.right,$=C>=R.top&&C<=R.bottom;return!F||!$?!1:T>=R.right-Rr},z=()=>[s.querySelector(".xterm-viewport"),s.querySelector(".xterm-scrollable-element")].filter(C=>C instanceof HTMLElement),w=T=>{if(o===null)return null;for(let C=0;C<T.length;C+=1){const H=T.item(C);if(H&&H.identifier===o)return H}return null},I=T=>{if(O(),T.touches.length!==1)return;const C=T.touches.item(0);C&&(o=C.identifier,r=C.clientY,u=0,l=b(C.clientX,C.clientY,T.target),h=C.clientX,a=C.clientY,v=!1,l||(_=setTimeout(()=>{var U;_=null;const H=(e==null?void 0:e())??null;(U=H==null?void 0:H.startTouchSelection)!=null&&U.call(H,h,a,"word")&&(v=!0)},vr)))},Y=T=>{var F,$,M,X,q,te,ne,A,re;const C=w(T.touches)??T.touches.item(0);if(!C)return;if(v){const P=(e==null?void 0:e())??null;(F=P==null?void 0:P.updateTouchSelection)==null||F.call(P,C.clientX,C.clientY),T.cancelable&&T.preventDefault();return}if(_!==null&&Math.hypot(C.clientX-h,C.clientY-a)>Mr&&O(),l||(l=b(C.clientX,C.clientY,T.target),l&&(u=0)),l)return;const H=C.clientY,U=r-H;if(r=H,U===0)return;let Q=!1,x=!1;const R=(e==null?void 0:e())??null;if(R){const P=R==null?void 0:R._core,V=((q=(X=(M=($=P==null?void 0:P._renderService)==null?void 0:$.dimensions)==null?void 0:M.css)==null?void 0:X.cell)==null?void 0:q.height)??18;u+=U*Cr;const B=u>0?Math.floor(u/V):Math.ceil(u/V);if(typeof R.handleViewportGesture=="function")B!==0&&(Q=R.handleViewportGesture({source:"touch",deltaY:B*V,clientX:C.clientX,clientY:C.clientY}),u-=B*V);else if(B!==0){const j=((ne=(te=R.buffer)==null?void 0:te.active)==null?void 0:ne.viewportY)??0;R.scrollLines(B);const le=((re=(A=R.buffer)==null?void 0:A.active)==null?void 0:re.viewportY)??0;Q=j!==le,x=B<0&&j<=0&&le<=0,u-=B*V}}else{const P=z();if(P.length===0)return;for(const V of P){const B=V.scrollTop;V.scrollTop+=U;const j=V.scrollTop;Math.abs(j-B)>0&&(Q=!0),U<0&&j<=0&&(x=!0)}if(!Q){const V=s.querySelector(".xterm");if(V instanceof HTMLElement){const B=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:U}),j=V.dispatchEvent(B);Q=B.defaultPrevented||!j}}}T.cancelable&&(Q||x)&&T.preventDefault()},K=T=>{var H;if(O(),!(o===null||!w(T.changedTouches))&&(o=null,u=0,l=!1,v)){v=!1;const U=(e==null?void 0:e())??null;(H=U==null?void 0:U.endTouchSelection)==null||H.call(U)}},N=T=>{v&&T.preventDefault()};return s.addEventListener("touchstart",I,{passive:!0}),s.addEventListener("touchmove",Y,{passive:!1}),s.addEventListener("touchend",K,{passive:!0}),s.addEventListener("touchcancel",K,{passive:!0}),s.addEventListener("contextmenu",N),()=>{t.current=!1,O(),s.removeEventListener("touchstart",I),s.removeEventListener("touchmove",Y),s.removeEventListener("touchend",K),s.removeEventListener("touchcancel",K),s.removeEventListener("contextmenu",N)}},[n,e]),t}function Dr({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 Or({currentSize:n,containerSize:e,force:t=!1}){return t?!0:n.cols!==e.cols||n.rows!==e.rows}function kr({deviceId:n,paneId:e,deviceConnected:t,isSelectionInvalid:s,onResize:i,onSync:r,getContainerRect:o}){const l=d.useRef(null),u=d.useRef(null),h=d.useRef(null),a=d.useRef(null),_=d.useRef(0),v=d.useRef([]),O=d.useRef(null),E=d.useRef(null),b=d.useRef(o),z=d.useRef(!1),w=d.useRef(i),I=d.useRef(r);d.useEffect(()=>{w.current=i},[i]),d.useEffect(()=>{I.current=r},[r]),d.useEffect(()=>{b.current=o},[o]);const Y=d.useCallback(()=>{var te,ne,A,re,P,V,B,j,le,S;const x=E.current,R=O.current;if(!x||!R||!x.element)return null;let F;try{const g=R.proposeDimensions();if(!g)throw new Error("fitAddon.proposeDimensions() returned null");F=Math.max(2,g.cols)}catch{const g=x._core,k=((re=(A=(ne=(te=g==null?void 0:g._renderService)==null?void 0:te.dimensions)==null?void 0:ne.css)==null?void 0:A.cell)==null?void 0:re.width)??9,W=(P=b.current)==null?void 0:P.call(b);if(!W||W.width===0)return null;F=Math.max(2,Math.floor(W.width/k))}const $=(V=b.current)==null?void 0:V.call(b);if(!$||$.height===0)return null;const M=x._core,X=((S=(le=(j=(B=M==null?void 0:M._renderService)==null?void 0:B.dimensions)==null?void 0:j.css)==null?void 0:le.cell)==null?void 0:S.height)??17,q=Math.max(2,Math.floor($.height/X));return{cols:F,rows:q}},[]),K=d.useCallback((x,R)=>{const F=E.current;F&&(F.cols===x&&F.rows===R||F.resize(x,R))},[]),N=d.useCallback((x,R=!1)=>{if(!n||!e||!t||s&&x!=="sync"||!R&&Date.now()<_.current||!E.current)return!1;const $=Y();if(!$)return!1;const{cols:M,rows:X}=$,q=h.current;return!R&&q&&q.cols===M&&q.rows===X?(K(M,X),!0):(K(M,X),x==="sync"?I.current(M,X):w.current(M,X),h.current={cols:M,rows:X},a.current={cols:M,rows:X,at:Date.now()},!0)},[K,t,n,s,Y,e]),T=d.useCallback((x="resize",R={})=>{const{immediate:F=!1,force:$=!1}=R;u.current!==null&&(window.clearTimeout(u.current),u.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const M=()=>{l.current=requestAnimationFrame(()=>{l.current=null,N(x,$)})};if(F){M();return}u.current=window.setTimeout(()=>{u.current=null,M()},150)},[N]),C=d.useCallback(()=>{for(const x of v.current)window.clearTimeout(x);v.current=[]},[]),H=d.useCallback(()=>{var R;C(),T("sync",{immediate:!0,force:!0});const x=window.setTimeout(()=>{T("sync",{immediate:!0,force:!0})},60);v.current.push(x),typeof document<"u"&&"fonts"in document&&((R=document.fonts)!=null&&R.ready)&&document.fonts.ready.then(()=>{T("sync",{immediate:!0,force:!0})}).catch(()=>{})},[C,T]);d.useEffect(()=>{let x=null;const R=()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,T("resize")})};return window.addEventListener("resize",R),()=>{window.removeEventListener("resize",R),x!==null&&cancelAnimationFrame(x)}},[T]),d.useEffect(()=>{const x=()=>{var te;const M=E.current,X=Y();if(!M||!X)return;if(!Or({currentSize:{cols:Math.max(2,M.cols),rows:Math.max(2,M.rows)},containerSize:X})){(te=M.refresh)==null||te.call(M);return}T("sync",{force:!0})},R=()=>{if(document.visibilityState!=="visible"){z.current=!0;return}z.current&&(z.current=!1,x())},F=()=>{z.current=!0},$=()=>{z.current&&(z.current=!1,x())};return document.addEventListener("visibilitychange",R),window.addEventListener("blur",F),window.addEventListener("focus",$),()=>{document.removeEventListener("visibilitychange",R),window.removeEventListener("blur",F),window.removeEventListener("focus",$)}},[Y,T]),d.useEffect(()=>()=>{C(),u.current!==null&&window.clearTimeout(u.current),l.current!==null&&cancelAnimationFrame(l.current)},[C]);const U=d.useCallback(x=>{O.current=x},[]),Q=d.useCallback(x=>{E.current=x},[]);return{scheduleResize:T,runPostSelectResize:H,clearPostSelectResizeTimers:C,setFitAddon:U,setTerminal:Q,lastReportedSize:h,pendingLocalSize:a,suppressLocalResizeUntil:_}}const Lr={fontFamily:Zt,fontSize:13,scrollback:1e4},ot="tmex:terminal-mode-cache";function Ir(n,e){try{const t=sessionStorage.getItem(ot);return t?JSON.parse(t)[`${n}:${e}`]??null:null}catch{return null}}function Nr(n,e,t){try{const s=sessionStorage.getItem(ot),i=s?JSON.parse(s):{},r=`${n}:${e}`;t?i[r]=t:delete i[r],sessionStorage.setItem(ot,JSON.stringify(i))}catch{}}function Hr(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function Pr(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=Hr();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 Br(n){var t;const e=globalThis;e.__tmexE2eXterm=n,e.__tmexE2eTerminal=n,e.__tmexE2eTerminalEngine=Vt,e.__tmexE2eTerminalRenderer=((t=n.getRendererKind)==null?void 0:t.call(n))??null}function Fr(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 $t=d.forwardRef(({deviceId:n,paneId:e,theme:t,inputMode:s,deviceConnected:i,isSelectionInvalid:r,onResize:o,onSync:l,children:u},h)=>{const[a,_]=d.useState(null),[v,O]=d.useState(!1),E=J(S=>S.sendInput),{t:b}=Ke(),z=d.useMemo(()=>{switch(t){case"light":return Lt;default:return kt}},[t]),w=d.useRef(null),I=d.useRef(null),Y=d.useRef(null),K=d.useRef(n),N=d.useRef(e),T=d.useRef(n),C=d.useRef(e),H=d.useRef(i&&!r),U=d.useRef(s),Q=d.useRef(z),x=d.useRef(!1),R=d.useRef(!1),F=d.useRef(null),$=d.useRef(!1),M=d.useCallback((S,g,k)=>{!(S!=null&&S.exportModeSnapshot)||!g||!k||Nr(g,k,S.exportModeSnapshot())},[]),X=d.useCallback(()=>a,[a]);Ar(w,X),d.useEffect(()=>{K.current=n,N.current=e,R.current=!1},[n,e]),d.useEffect(()=>{H.current=i&&!r},[i,r]),d.useEffect(()=>{U.current=s},[s]),d.useEffect(()=>{Q.current=z},[z]);const q=d.useCallback(S=>{if(!S||s!=="direct"||!H.current)return;const g=K.current,k=N.current;!g||!k||E(g,k,S,!1)},[s,E]),{pendingLocalSize:te,scheduleResize:ne,runPostSelectResize:A,setFitAddon:re,setTerminal:P}=kr({deviceId:n,paneId:e,deviceConnected:i,isSelectionInvalid:r,onResize:o,onSync:l,getContainerRect:()=>{const S=w.current;if(!S)return null;const g=S.getBoundingClientRect();return{width:g.width,height:g.height}}});d.useEffect(()=>{let S=!1,g=null;return(async()=>{if(await Jt(),S)return;const k=await xr({...Lr,theme:Q.current,disableStdin:U.current==="editor"});if(S){k.dispose();return}g=k,I.current&&k.open(I.current),Br(k),_(k)})(),()=>{S=!0,_(null),Fr(g),g==null||g.dispose()}},[]),d.useEffect(()=>{!a||!("setTheme"in a)||a.setTheme(z)},[a,z]),d.useEffect(()=>{!a||!("setDisableStdin"in a)||a.setDisableStdin(s==="editor")},[a,s]),d.useEffect(()=>{!a||s!=="direct"||window.innerWidth<768||"ontouchstart"in window||a.focus()},[a,s]);const V=d.useMemo(()=>a?{onResetTerminal:S=>{K.current===S&&(M(a,T.current,C.current),$.current=!0,a.reset(),x.current=!1,A())},onApplyHistory:(S,g,k)=>{var ie;if(K.current!==S)return;const W=Pr(Ir(K.current,N.current),k);W&&((ie=a.restoreModeSnapshot)==null||ie.call(a,W));const G=k?Er(g):Wt(g);R.current=!0,a.write(G),$.current=!1,T.current=K.current,C.current=N.current,M(a,K.current,N.current)},onFlushBuffer:(S,g)=>{if(K.current===S){for(const k of g){const W=Dt(k,x.current);x.current=W.endedWithCR,a.write(W.normalized)}R.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),R.current=!1),T.current=K.current,C.current=N.current,M(a,K.current,N.current)}},onOutput:(S,g,k)=>{if(K.current!==S||N.current!==g)return;const W=Dt(k,x.current);x.current=W.endedWithCR,a.write(W.normalized),R.current&&(a.buffer.active.baseY<=1&&a.scrollToTop(),R.current=!1),T.current=K.current,C.current=N.current,M(a,K.current,N.current)}}:{},[a,M,A]);d.useEffect(()=>{a?F.current!==a&&(x.current=!1,T.current=K.current,C.current=N.current,F.current=a):F.current=null},[a]),d.useEffect(()=>{if(!(!a||!n||!e))return()=>{if($.current){$.current=!1;return}M(a,T.current,C.current)}},[n,a,e,M]),d.useEffect(()=>{ht(V)},[V]),d.useEffect(()=>()=>{ht({})},[]),d.useEffect(()=>{if(!a){Y.current=null,re(null),P(null);return}const S=new _r;return a.loadAddon(S),Y.current=S,re(S),P(a),A(),()=>{try{S.dispose()}finally{Y.current=null,re(null),P(null)}}},[a,A,re,P]),d.useEffect(()=>{const S=w.current;if(!S)return;let g=null;const k=new ResizeObserver(()=>{g!==null&&cancelAnimationFrame(g),g=requestAnimationFrame(()=>{g=null,ne("resize")})});return k.observe(S),()=>{k.disconnect(),g!==null&&cancelAnimationFrame(g)}},[ne]),d.useEffect(()=>{if(!a||!n||!e)return;const S=a.onData(g=>{!i||r||q(g)});return a.attachCustomKeyEventHandler(g=>!i||r||g.type!=="keydown"||s!=="direct"?!0:g.shiftKey&&g.key==="Enter"?(g.preventDefault(),q("\x1B[13;2u"),!1):!0),()=>{S.dispose(),a.attachCustomKeyEventHandler(()=>!0)}},[a,i,r,s,q,n,e]),d.useEffect(()=>{if(!(a!=null&&a.onLinkActivated))return;const S=a.onLinkActivated(g=>{window.open(g,"_blank","noopener,noreferrer")});return()=>S.dispose()},[a]),d.useEffect(()=>{if(!(a!=null&&a.onSelectionChange)){O(!1);return}const S=a.onSelectionChange(g=>{O(!!g)});return()=>{S.dispose(),O(!1)}},[a]);const B=d.useCallback(()=>{var g;if(!a)return;const S=((g=a.getSelection)==null?void 0:g.call(a))??"";S&&zt(S).then(()=>{xe.success(b("terminal.copied"))}).catch(()=>{xe.error(b("terminal.copyFailed"))}).finally(()=>{var k;(k=a.clearSelection)==null||k.call(a),a.focus()})},[a,b]),j=d.useCallback(()=>{var g;if(!a)return;((g=navigator.clipboard)!=null&&g.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(k=>{var W;k&&a.paste(k),(W=a.clearSelection)==null||W.call(a),a.focus()}).catch(()=>{xe.error(b("terminal.pasteFailed"))})},[a,b]),le=d.useCallback(()=>{var S;(S=a==null?void 0:a.clearSelection)==null||S.call(a),a==null||a.focus()},[a]);return d.useImperativeHandle(h,()=>({write:S=>a==null?void 0:a.write(S),reset:()=>{a==null||a.reset(),x.current=!1},scrollToBottom:()=>a==null?void 0:a.scrollToBottom(),resize:(S,g)=>a==null?void 0:a.resize(S,g),getTerminal:()=>a??null,getSize:()=>a?{cols:Math.max(2,a.cols),rows:Math.max(2,a.rows)}:null,runPostSelectResize:()=>A(),scheduleResize:(S,g)=>ne(S,g),calculateSizeFromContainer:()=>{var Me,oe,ye,ue,ae,Z,ge,he,Se,be,Ae,De,Oe,ke,Ee,c;const S=w.current,g=a,k=Y.current;if(!S||!g)return null;const W=S.getBoundingClientRect();if(W.width===0||W.height===0)return null;const G=g._core;let ie;if(k)try{const p=k.proposeDimensions();if(p)ie=Math.max(2,p.cols);else{const y=((ue=(ye=(oe=(Me=G==null?void 0:G._renderService)==null?void 0:Me.dimensions)==null?void 0:oe.css)==null?void 0:ye.cell)==null?void 0:ue.width)??9;ie=Math.max(2,Math.floor(W.width/y))}}catch{const p=((he=(ge=(Z=(ae=G==null?void 0:G._renderService)==null?void 0:ae.dimensions)==null?void 0:Z.css)==null?void 0:ge.cell)==null?void 0:he.width)??9;ie=Math.max(2,Math.floor(W.width/p))}else{const p=((De=(Ae=(be=(Se=G==null?void 0:G._renderService)==null?void 0:Se.dimensions)==null?void 0:be.css)==null?void 0:Ae.cell)==null?void 0:De.width)??9;ie=Math.max(2,Math.floor(W.width/p))}const pe=((c=(Ee=(ke=(Oe=G==null?void 0:G._renderService)==null?void 0:Oe.dimensions)==null?void 0:ke.css)==null?void 0:Ee.cell)==null?void 0:c.height)??17,We=Math.max(2,Math.floor(W.height/pe));return{cols:ie,rows:We}},getPendingLocalSize:()=>te.current}),[a,te,A,ne]),f.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:z.background},"data-terminal-engine":Vt,children:[f.jsxs("div",{ref:w,className:"relative min-h-0 w-full flex-1",children:[f.jsx("div",{ref:I,className:"absolute inset-0"}),f.jsx(Tr,{visible:v,canPaste:s==="direct"&&i&&!r,onCopy:B,onPaste:j,onDismiss:le})]}),u]})});$t.displayName="Terminal";const Gr=1200,Ur=2e3;function me(n,e){return!n||!e?!1:n.windowId===e.windowId&&n.paneId===e.paneId}function jt(n,e){const t=n.filter(s=>e-s.at<Gr);return t.length===0?null:t.reduce((s,i)=>i.at>s.at?i:s)}function ve(n,e=Date.now()){return!n||e-n.at>Ur?null:n}function zr(n){const e=n.now??Date.now(),t=jt(n.recentSelectRequests,e);if(t&&!me(t,n.activePaneFromEvent)||me(n.currentRoute,n.activePaneFromEvent)||me(n.lastHandledActive,n.activePaneFromEvent))return!0;const s=ve(n.pendingUserSelection,e);return!!(s&&!me(s,n.activePaneFromEvent))}function Yr(n){const e=n.now??Date.now(),t=jt(n.recentSelectRequests,e),s=ve(n.pendingUserSelection,e);return!!(s&&!me(s,n.snapshotActive)||t&&!me(t,n.snapshotActive))}function Kr(n){const e=n.now??Date.now(),t=ve(n.pendingUserSelection,e);return!(t&&me(t,n.routeTarget)||n.snapshotActive&&me(n.snapshotActive,n.routeTarget))}const Vr=[{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:i,inputMode:r}){return f.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:f.jsx("div",{className:"shortcut-row flex items-center gap-1.5 py-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Vr.map(o=>f.jsx(fe,{variant:"ghost",size:"sm",className:"terminal-shortcut-btn h-7 min-w-9 px-2.5 rounded-full text-[11px] font-medium tracking-wide shrink-0 [@media(any-pointer:coarse)]:h-9 [@media(any-pointer:coarse)]:min-w-10 [@media(any-pointer:coarse)]:px-3",title:o.label,"aria-label":o.label,"data-testid":`editor-shortcut-${o.key}`,onMouseDown:l=>l.preventDefault(),onClick:()=>{e(o.payload),i&&r==="editor"&&(t==null||t())},disabled:s,children:o.label},o.key))})})});function qr(){var Ee;const{t:n}=Ke(),{deviceId:e,windowId:t,paneId:s}=lt(),i=en(),r=d.useRef(null),o=d.useRef(null),l=d.useRef(null),u=d.useRef(null),h=d.useRef(!1),a=d.useRef(!1),_=d.useRef(null),v=J(c=>c.selectPane),O=J(c=>e?c.snapshots[e]:void 0),E=J(c=>{var p;return e?(p=c.deviceErrors)==null?void 0:p[e]:void 0}),b=J(c=>{var p;return e?((p=c.deviceConnected)==null?void 0:p[e])??!1:!1}),z=It(c=>{var p;return((p=c.settings)==null?void 0:p.siteName)??"tmex"}),w=d.useMemo(()=>at(s),[s]),I=d.useMemo(()=>e&&w?`${e}:${w}`:null,[e,w]),[Y,K]=d.useState(!1),[N,T]=d.useState(""),C=d.useRef(!1),H=!b||!w,[U,Q]=d.useState(!1),x=ce(c=>c.inputMode),R=ce(c=>c.theme),F=ce(c=>c.editorSendWithEnter),$=ce(c=>c.setEditorSendWithEnter),M=ce(c=>c.addEditorHistory),X=ce(c=>c.setEditorDraft),q=ce(c=>c.removeEditorDraft),te=ce(c=>I?c.editorDrafts[I]??"":""),ne=d.useMemo(()=>tn(),[]),A=(Ee=O==null?void 0:O.session)==null?void 0:Ee.windows,re=R==="light"?Lt:kt,{data:P}=Nt({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}),V=d.useMemo(()=>{if(e)return P==null?void 0:P.devices.find(c=>c.id===e)},[e,P==null?void 0:P.devices]),B=d.useMemo(()=>{if(!(!t||!A))return A.find(c=>c.id===t)},[t,A]),j=d.useMemo(()=>{if(!(!w||!B))return B.panes.find(c=>c.id===w)},[w,B]),le=!!A,W=!!(le&&!!t&&!B||le&&!!t&&!!w&&!!B&&!j?n("wsError.checkGateway"):null),G=!!(b&&w&&!W),ie=d.useMemo(()=>{if(!B||!j)return null;const c=(V==null?void 0:V.name)??e;return Ht({paneIdx:j.index,windowIdx:B.index,paneTitle:j.title,windowName:B.name,windowCustomName:B.customName,deviceName:c})},[V==null?void 0:V.name,e,j,B]),pe=d.useMemo(()=>{if(!A||A.length===0)return null;const c=A.find(y=>y.active),p=c==null?void 0:c.panes.find(y=>y.active);return!c||!p?null:{windowId:c.id,paneId:p.id}},[A]),We=d.useCallback((c,p)=>{!e||!w||J.getState().resizePane(e,w,c,p)},[e,w]),Me=d.useCallback((c,p)=>{!e||!w||J.getState().syncPaneSize(e,w,c,p)},[e,w]),oe=d.useCallback((c,p)=>{const y=u.current,D=(y==null?void 0:y.calculateSizeFromContainer())??(y==null?void 0:y.getSize())??void 0;if(D)return D;if(!c||!p||!A)return;const ee=A.find(we=>we.id===c),se=ee==null?void 0:ee.panes.find(we=>we.id===p);if(!(!se||se.width<=1||se.height<=1))return{cols:se.width,rows:se.height}},[A]);d.useEffect(()=>{const c=()=>{K(window.innerWidth<768||"ontouchstart"in window)};return c(),window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[]),d.useEffect(()=>{if(!Y||!ne||a.current)return;a.current=!0;const c=()=>{window.scrollTo(0,1)},p=window.requestAnimationFrame(c),y=window.setTimeout(c,120),D=window.setTimeout(c,420);return()=>{window.cancelAnimationFrame(p),window.clearTimeout(y),window.clearTimeout(D)}},[ne,Y]),d.useEffect(()=>{e&&(h.current=!1,ge.current=null,he.current=null,_.current=null,ue.current=[])},[e]),d.useEffect(()=>{b||(h.current=!1)},[b]),d.useEffect(()=>{if(!e||!b||!t||!A)return;if(A.length===0){i("/devices",{replace:!0});return}const c=A.find(y=>y.id===t);if(!c)return;if(!w){const y=c.panes.find(D=>D.active)??c.panes[0];y&&i(`/devices/${e}/windows/${t}/panes/${_e(y.id)}`,{replace:!0});return}if(!c.panes.find(y=>y.id===w)){const y=c.panes.find(D=>D.active)??c.panes[0];y&&i(`/devices/${e}/windows/${t}/panes/${_e(y.id)}`,{replace:!0});return}},[e,b,A,t,w,i]),d.useEffect(()=>{if(!e||!b||!A||A.length===0||t&&w||h.current)return;const c=A.find(y=>y.active)??A[0],p=c.panes.find(y=>y.active)??c.panes[0];p&&(h.current=!0,i(`/devices/${e}/windows/${c.id}/panes/${_e(p.id)}`,{replace:!0}))},[b,e,i,w,t,A]);const ye=d.useRef(null);d.useEffect(()=>{ye.current=null},[e,w]),d.useEffect(()=>{if(!e||!t||!w||H||!b)return;const c=`${e}:${t}:${w}`;if(ye.current===c)return;ye.current=c;const p=oe(t,w);ae(t,w),v(e,t,w,p)},[b,e,oe,H,w,v,t]),d.useEffect(()=>{if(!e||!b||!t||!w)return;const c={windowId:t,paneId:w};Kr({routeTarget:c,snapshotActive:pe,pendingUserSelection:_.current})&&(_.current={windowId:c.windowId,paneId:c.paneId,at:Date.now()})},[b,e,w,pe,t]);const ue=d.useRef([]),ae=d.useCallback((c,p)=>{const y=Date.now(),D=[...ue.current.filter(ee=>y-ee.at<2e3),{windowId:c,paneId:p,at:y}];ue.current=D.slice(-8)},[]),Z=J(c=>e?c.activePaneFromEvent[e]:void 0),ge=d.useRef(null);d.useEffect(()=>{if(!e||!b||!t||!w||!Z)return;const c=Date.now(),p=ve(_.current,c);if(_.current=p,zr({now:c,pendingUserSelection:p,activePaneFromEvent:Z,currentRoute:{windowId:t,paneId:w},recentSelectRequests:ue.current,lastHandledActive:ge.current}))return;ge.current={...Z},p&&p.windowId===Z.windowId&&p.paneId===Z.paneId&&(_.current=null);const y=oe(Z.windowId,Z.paneId);ae(Z.windowId,Z.paneId),v(e,Z.windowId,Z.paneId,y),i(`/devices/${e}/windows/${Z.windowId}/panes/${_e(Z.paneId)}`,{replace:!0})},[e,b,t,w,Z,ae,oe,v,i]);const he=d.useRef(null);d.useEffect(()=>{if(!e||!b||!A||A.length===0)return;const c=ue.current,p=A.find($e=>$e.active);if(!p)return;const y=p.panes.find($e=>$e.active);if(!y)return;const D={windowId:p.id,paneId:y.id},ee=Date.now(),se=ve(_.current,ee);if(_.current=se,Yr({now:ee,pendingUserSelection:se,snapshotActive:D,recentSelectRequests:c})||he.current&&he.current.windowId===D.windowId&&he.current.paneId===D.paneId||(he.current={...D},se&&se.windowId===D.windowId&&se.paneId===D.paneId&&(_.current=null),t===D.windowId&&w===D.paneId))return;const we=oe(D.windowId,D.paneId);ae(D.windowId,D.paneId),v(e,D.windowId,D.paneId,we),i(`/devices/${e}/windows/${D.windowId}/panes/${_e(D.paneId)}`,{replace:!0})},[e,b,A,t,w,ae,oe,v,i]);const Se=J(c=>e?c.pendingCreateWindowAt[e]:void 0);d.useEffect(()=>{if(!e||!b||!Se)return;const c=5e3,p=Date.now()-Se;if(p>c){J.getState().clearPendingCreateWindow(e);return}if(!pe){const ee=window.setTimeout(()=>{J.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(ee)}const y=pe;if(t===y.windowId&&w===y.paneId){const ee=window.setTimeout(()=>{J.getState().clearPendingCreateWindow(e)},c-p);return()=>window.clearTimeout(ee)}_.current={windowId:y.windowId,paneId:y.paneId,at:Date.now()};const D=oe(y.windowId,y.paneId);ae(y.windowId,y.paneId),v(e,y.windowId,y.paneId,D),i(`/devices/${e}/windows/${y.windowId}/panes/${_e(y.paneId)}`,{replace:!0}),J.getState().clearPendingCreateWindow(e)},[e,b,Se,pe,t,w,ae,oe,v,i]),d.useEffect(()=>{if(!G||!j||H)return;const c=u.current,p=c==null?void 0:c.getTerminal();if(!p)return;const y=Math.max(2,Math.floor(j.width||0)),D=Math.max(2,Math.floor(j.height||0));if(!y||!D)return;const ee=Date.now(),se={cols:y,rows:D},we=(c==null?void 0:c.getPendingLocalSize())??null;Dr({now:ee,remoteSize:se,pendingLocalSize:we})&&(p.cols===y&&p.rows===D||p.resize(y,D))},[G,H,j]),d.useEffect(()=>{const c=window.requestAnimationFrame(()=>{var y;(y=u.current)==null||y.scrollToBottom()}),p=window.setTimeout(()=>{var y;(y=u.current)==null||y.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(c),window.clearTimeout(p)}},[x]),d.useEffect(()=>{E!=null&&E.message&&xe.error(E.message)},[E==null?void 0:E.message]),d.useEffect(()=>(document.title=nn(ie),()=>{document.title=z}),[z,ie]),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:y,windowId:D,paneId:ee}=p.detail;y===e&&(_.current={windowId:D,paneId:ee,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",c),()=>{window.removeEventListener("tmex:user-initiated-selection",c)}},[e]),d.useEffect(()=>{T(te)},[te]);const be=d.useCallback(c=>{if(!e||!w||!G)return;J.getState().sendInput(e,w,c,!1)},[G,e,w]),Ae=d.useCallback(()=>{if(!G){xe.error(n("wsError.checkGateway"));return}if(!e||!w||!N.trim())return;Q(!0),window.setTimeout(()=>Q(!1),150);const c=F?`${N}\r`:N;J.getState().sendInput(e,w,c,!1),M(N),I&&q(I),T("")},[M,G,e,I,F,N,q,w,n]),De=d.useCallback(()=>{if(!G){xe.error(n("wsError.checkGateway"));return}if(!e||!w||!N.trim())return;Q(!0),window.setTimeout(()=>Q(!1),150);const c=N.split(/\r?\n/),p=J.getState();for(const y of c)y.trim()&&p.sendInput(e,w,`${y}\r`,!1);M(N),I&&q(I),T("")},[M,G,e,I,N,q,w,n]),Oe=d.useCallback(()=>{var c;(c=l.current)==null||c.focus({preventScroll:!0})},[]);if(!e)return f.jsx("div",{className:"flex h-full items-center justify-center p-4",children:f.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:n("device.noDevices")})});const ke=!b&&!E;return f.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[f.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${Y&&x==="editor"?"pb-1":""}`,children:[f.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:re.background},children:b&&w?f.jsx("div",{ref:r,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:f.jsx($t,{ref:u,deviceId:e,paneId:w,theme:R,inputMode:x,deviceConnected:b,isSelectionInvalid:W,onResize:We,onSync:Me,children:x==="direct"&&f.jsx(Ot,{onSend:be,disabled:!G,isMobile:Y,inputMode:x})},`${e}:${w}`)}):f.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:f.jsx("div",{className:"max-w-sm space-y-4",children:b?t?f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsx(je,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),f.jsx("h3",{className:"text-lg font-medium",children:n("terminal.connecting")})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),f.jsx("h3",{className:"text-lg font-medium",children:n("window.noWindowSelected")}),f.jsx("p",{className:"text-sm text-muted-foreground",children:n("window.selectWindowToStart")})]}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:f.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),f.jsx("h3",{className:"text-lg font-medium",children:n("device.disconnected")}),f.jsx("p",{className:"text-sm text-muted-foreground",children:n("device.connectToStart")})]})})})}),ke&&f.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:f.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:[f.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),f.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:n("terminal.connecting")})]})})]}),x==="editor"&&f.jsxs("div",{ref:o,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[Y&&f.jsx(Ot,{onSend:be,onFocusEditor:Oe,disabled:!G,isMobile:Y,inputMode:x}),f.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:N,onChange:c=>{const p=c.target.value;if(T(p),!!I){if(p){X(I,p);return}q(I)}},placeholder:n("terminal.inputPlaceholder"),onCompositionStart:()=>{C.current=!0},onCompositionEnd:()=>{C.current=!1}}),f.jsx("div",{className:"actions mt-2",children:f.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[f.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:[f.jsx(sn,{size:"sm",checked:F,onCheckedChange:c=>$(!!c)}),f.jsx("span",{children:n("terminal.editorSendWithEnter")})]}),f.jsxs(fe,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;T(""),I&&q(I),Y&&x==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},title:n("terminal.clear"),children:[f.jsx(rn,{className:"h-4 w-4"}),n("terminal.clear")]}),f.jsxs(fe,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;De(),Y&&x==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!G||U,children:[U?f.jsx(je,{className:"h-4 w-4 animate-spin"}):f.jsx(ft,{className:"h-4 w-4"}),n("terminal.editorSendLineByLine")]}),f.jsxs(fe,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:c=>c.preventDefault(),onClick:()=>{var c;Ae(),Y&&x==="editor"&&((c=l.current)==null||c.focus({preventScroll:!0}))},disabled:!G||U,children:[U?f.jsx(je,{className:"h-4 w-4 animate-spin"}):f.jsx(ft,{className:"h-4 w-4"}),n("common.send")]})]})})]})]})}function Xr(){const{deviceId:n,windowId:e,paneId:t}=lt(),s=t?at(t):void 0,i=J(a=>a.snapshots),r=It(a=>{var _;return((_=a.settings)==null?void 0:_.siteName)??"tmex"}),o=n?i[n]:void 0,l=d.useMemo(()=>{var a;if(!(!e||!((a=o==null?void 0:o.session)!=null&&a.windows)))return o.session.windows.find(_=>_.id===e)},[e,o]),u=d.useMemo(()=>{if(!(!s||!l))return l.panes.find(a=>a.id===s)},[s,l]),h=d.useMemo(()=>l&&u?Ht({paneIdx:u.index,windowIdx:l.index,paneTitle:u.title,windowName:l.name,windowCustomName:l.customName,deviceName:r}):n??"",[l,u,r,n]);return f.jsx(f.Fragment,{children:h})}function Qr(){const{t:n}=Ke(),{deviceId:e,paneId:t}=lt(),s=t?at(t):void 0,i=ce(I=>I.inputMode),r=ce(I=>I.setInputMode),o=J(I=>{var Y;return e?((Y=I.deviceConnected)==null?void 0:Y[e])??!1:!1}),[l,u]=d.useState(!1),[h,a]=d.useState(!1),_=!!(s&&o),O=(Nt({queryKey:gn(e??"",s??""),queryFn:()=>yn(e??"",s??""),enabled:!!(e&&s),throwOnError:!1}).data??[]).some(I=>I.enabled),E=()=>{r(i==="direct"?"editor":"direct")},b=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},z=()=>{u(!0)},w=()=>{window.location.reload()};return f.jsxs(f.Fragment,{children:[f.jsx(fe,{variant:"ghost",size:"icon-sm",onClick:z,"aria-label":n("nav.refreshPage"),title:n("nav.refreshPage"),children:f.jsx(Sn,{className:"h-4 w-4"})}),f.jsx(fe,{variant:"ghost",size:"icon-sm",onClick:E,disabled:!_,"data-testid":"terminal-input-mode-toggle","aria-label":n(i==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:n(i==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:i==="direct"?f.jsx(on,{className:"h-4 w-4"}):f.jsx(vn,{className:"h-4 w-4"})}),f.jsx(fe,{variant:"ghost",size:"icon-sm",onClick:b,disabled:!_,"aria-label":n("nav.jumpToLatest"),title:n("nav.jumpToLatest"),children:f.jsx(xn,{className:"h-4 w-4"})}),f.jsxs(fe,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>a(!0),disabled:!s,"data-testid":"watch-open-button","aria-label":n("watch.title"),title:n("watch.title"),children:[f.jsx(ln,{className:"h-4 w-4"}),O&&f.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),e&&s&&f.jsx(an,{open:h,onOpenChange:a,deviceId:e,paneId:s}),f.jsx(cn,{open:l,onOpenChange:u,children:f.jsxs(dn,{children:[f.jsxs(un,{children:[f.jsx(hn,{children:n("nav.refreshPage")}),f.jsx(fn,{children:n("nav.refreshPageConfirm")})]}),f.jsxs(mn,{children:[f.jsx(pn,{onClick:()=>u(!1),children:n("common.cancel")}),f.jsx(wn,{onClick:w,children:n("common.confirm")})]})]})})]})}export{Qr as PageActions,Xr as PageTitle,qr as default};
26
- //# sourceMappingURL=DevicePage-fGI-do8S.js.map
@@ -1,2 +0,0 @@
1
- import{u as D,r as x,a as W,b as ae,c as ie,d as re,e as K,t as ne,j as e,M as _,B as C,P as X,A as oe,f as ce,g as de,h as le,T as Y,i as me,k as ue,l as he,m as pe,n as xe,G as ve,o as v,D as ye,p as fe,E as ge,q as je,s as $,v as we,Z as Ne,w as Ce,x as Q,y as De,S as be,L as Se,z as Ee,C as Me,F as Pe,H as Ke,I as Ie,J as ke,K as y,N as z,O as V,Q as U,R as J,U as j,V as Ae,W as $e}from"./index-cfY8KuW7.js";import{C as M,a as P,b as Te,c as Re,d as Fe}from"./card-cbVDy0Xp.js";function I(s){const o=s.trim();return o||void 0}function qe(s){return s?{name:s.name,type:s.type,host:s.host??"",port:s.port??22,username:s.username??"",sshConfigRef:s.sshConfigRef??"",session:s.session??"tmex",authMode:s.type==="local"?"auto":s.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"~/.ssh/config",session:"tmex",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(s){if(s.type==="local")return{name:s.name.trim(),type:"local",session:I(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),type:"ssh",host:s.host.trim(),port:s.port,username:s.username.trim(),sshConfigRef:s.sshConfigRef.trim(),session:I(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&(o.password=s.password),s.authMode==="key"&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function He(s){if(s.type==="local")return{name:s.name.trim(),session:I(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),host:s.host.trim(),port:s.port,username:s.username.trim(),sshConfigRef:s.sshConfigRef.trim(),session:I(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&s.password&&(o.password=s.password),s.authMode==="key"&&s.privateKey&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function ee(s){return Number.isInteger(s)&&s>=1&&s<=65535}function Oe(s){return s.type!=="ssh"?null:s.host.trim()?ee(s.port)?s.username.trim()?s.sshConfigRef.trim()?null:"validation.sshConfigRequired":"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(s,o){try{return(await s.json()).error??o}catch{return o}}function Ve(){const{t:s}=D(),[o,m]=x.useState(!1),[t,f]=x.useState(null),[r,d]=x.useState(null),l=W(),h=ae(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});x.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:k,isError:w}=ie({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(s("device.loadFailed"));return n.json()},throwOnError:!1}),b=re(n=>n.hydrateDeviceErrors);x.useEffect(()=>{c!=null&&c.devices&&b(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,b]);const S=K({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(s("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),v.success(s("common.success"))},onError:n=>{v.error(n instanceof Error?n.message:s("common.error"))}}),E=x.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,N)=>p.sortOrder-N.sortOrder||p.name.localeCompare(N.name,ne(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[k?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:s("common.loading")})}):w?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:s("device.loadFailed")})}):E.length===0?e.jsx(M,{children:e.jsxs(P,{className:"space-y-4 py-14 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:e.jsx(_,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-medium",children:s("device.noDevices")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("device.addDevice")})]}),e.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[e.jsx(X,{className:"h-4 w-4"}),s("device.addDevice")]})]})}):e.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>e.jsx(Be,{device:n,onEdit:()=>f(n),onDelete:()=>d(n)},n.id))}),o&&e.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&e.jsx(Z,{mode:"edit",device:t,onClose:()=>f(null)}),e.jsx(oe,{open:r!==null,onOpenChange:n=>!n&&d(null),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(le,{className:"bg-destructive/10",children:e.jsx(Y,{className:"h-5 w-5 text-destructive"})}),e.jsx(me,{children:s("device.deleteConfirm")}),e.jsx(ue,{children:s("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("common.cancel")}),e.jsx(xe,{variant:"destructive",disabled:!r||S.isPending,onClick:()=>{r&&(S.mutate(r.id),d(null))},children:s("common.delete")})]})]})})]})}function Be({device:s,onEdit:o,onDelete:m}){const{t}=D(),f=s.type==="local"?e.jsx(_,{className:"h-4 w-4"}):e.jsx(ve,{className:"h-4 w-4"}),r=s.type==="local"?t("device.typeLocal"):`${s.username??"-"}@${s.host??"-"}:${s.port??22}`,d=K({mutationFn:async()=>{const l=await fetch(`/api/devices/${s.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{v.success(l.message??t("common.success"))},onError:l=>{v.error(l instanceof Error?l.message:t("common.error"))}});return e.jsxs(M,{"data-testid":"device-card","data-device-id":s.id,"data-device-name":s.name,className:"overflow-hidden border-border/50",children:[e.jsxs(Te,{className:"space-y-2 pb-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:f}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx(Re,{className:"line-clamp-1 text-sm",title:s.name,children:s.name}),e.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1",children:e.jsxs(ye,{children:[e.jsx(fe,{render:e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${s.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs(je,{align:"end",children:[e.jsxs($,{"data-testid":`device-card-edit-${s.id}`,onClick:o,children:[e.jsx(we,{className:"h-4 w-4"}),t("common.edit")]}),s.type==="ssh"&&e.jsxs($,{"data-testid":`device-card-test-${s.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[e.jsx(Ne,{className:"h-4 w-4"}),t("common.test")]}),e.jsx(Ce,{}),e.jsxs($,{"data-testid":`device-card-delete-${s.id}`,variant:"destructive",onClick:m,children:[e.jsx(Y,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),s.session&&e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.session}),e.jsx(De,{deviceId:s.id})]})]}),e.jsxs(P,{className:"pt-0",children:[e.jsx(be,{className:"mb-2"}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(Se,{to:`/devices/${s.id}`,"data-testid":`device-card-connect-${s.id}`,className:Ee({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:s,device:o,onClose:m}){const{t}=D(),f=W(),[r,d]=x.useState(qe(o)),[l,h]=x.useState(!1),[c,k]=x.useState(!1),w=s==="edit",b=r.type==="ssh",S=K({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{f.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),E=K({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{f.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),k(!0);const i=Oe(r);if(i){v.error(t(i));return}h(!0);try{s==="create"?await S.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${s}-device-name`,N=`${s}-device-type`,T=`${s}-device-host`,R=`${s}-device-port`,F=`${s}-device-username`,q=`${s}-device-session`,L=`${s}-device-auth-mode`,H=`${s}-device-password`,O=`${s}-device-private-key`,B=`${s}-device-private-key-passphrase`,se={local:t("device.typeLocal"),ssh:t("device.typeSSH")},te={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},A=a=>e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,g)=>e.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,g&&e.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return e.jsx(Me,{open:!0,onOpenChange:a=>!a&&m(),children:e.jsxs(Pe,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[e.jsxs(Ke,{children:[e.jsx(Ie,{children:t(w?"device.editDevice":"device.addDevice")}),e.jsx(ke,{children:t(w?"device.editDeviceDescription":"device.addDeviceDescription")})]}),e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[e.jsxs("section",{className:"space-y-2.5",children:[A(t("device.sectionBasic")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),e.jsx(y,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[u(N,t("device.type")),e.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(g=>({...g,type:i,authMode:i==="local"?"auto":g.authMode==="auto"?"agent":g.authMode}))},disabled:w,children:[e.jsx(V,{id:N,"data-testid":"device-type-select",className:"w-full",children:e.jsx(U,{placeholder:t("device.type"),children:a=>se[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"local",children:t("device.typeLocal")}),e.jsx(j,{value:"ssh",children:t("device.typeSSH")})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[u(q,t("device.session")),e.jsx(y,{id:q,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]})]})]}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2.5",children:[A(t("device.sectionConnection")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(T,t("device.host"),!0),e.jsx(y,{id:T,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),e.jsxs("div",{className:"space-y-1.5",children:[u(R,t("device.port"),!0),e.jsx(y,{id:R,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(g=>({...g,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!ee(r.port)})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),e.jsx(y,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]}),e.jsxs("div",{className:"space-y-1.5",children:[u(`${s}-device-ssh-config-ref`,t("device.authConfigRef"),!0),e.jsx(y,{id:`${s}-device-ssh-config-ref`,type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:"~/.ssh/config","aria-invalid":c&&!r.sshConfigRef.trim()})]})]})]}),e.jsxs("section",{className:"space-y-2.5",children:[A(t("device.sectionAuth")),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),e.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[e.jsx(V,{id:L,className:"w-full",children:e.jsx(U,{placeholder:t("device.authMode"),children:a=>te[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"password",children:t("device.authPassword")}),e.jsx(j,{value:"key",children:t("device.authKey")}),e.jsx(j,{value:"agent",children:t("device.authAgent")}),e.jsx(j,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&e.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),e.jsx(y,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),e.jsx(Ae,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),e.jsx(y,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]})]})]})]})]}),e.jsxs($e,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),e.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Ue(){const{t:s}=D();return e.jsx(e.Fragment,{children:s("sidebar.manageDevices")})}function Je(){const{t:s}=D(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":s("sidebar.addDevice"),title:s("sidebar.addDevice"),children:e.jsx(X,{className:"h-4 w-4"})})}export{Je as PageActions,Ue as PageTitle,Ve as default};
2
- //# sourceMappingURL=DevicesPage-kGrzwhGj.js.map
@@ -1,2 +0,0 @@
1
- import{ai as o,aj as n}from"./mermaid.core-M-o4g4TO.js";const t=(a,r)=>o.lang.round(n.parse(a)[r]);export{t as c};
2
- //# sourceMappingURL=channel-DbG6qNF6.js.map
@@ -1,2 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-727SXJPM-JPYDN0Cb.js";import{_ as i}from"./mermaid.core-M-o4g4TO.js";import"./chunk-FMBD7UC4-DyZ7Ot2F.js";import"./chunk-ND2GUHAM-SU6Ea3wF.js";import"./chunk-55IACEB6-CimNoYDH.js";import"./chunk-2J33WTMH-Blr6l1Nk.js";import"./index-cfY8KuW7.js";var n={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{n as diagram};
2
- //# sourceMappingURL=classDiagram-4FO5ZUOK-rB1DgxOZ.js.map
@@ -1,2 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-727SXJPM-JPYDN0Cb.js";import{_ as i}from"./mermaid.core-M-o4g4TO.js";import"./chunk-FMBD7UC4-DyZ7Ot2F.js";import"./chunk-ND2GUHAM-SU6Ea3wF.js";import"./chunk-55IACEB6-CimNoYDH.js";import"./chunk-2J33WTMH-Blr6l1Nk.js";import"./index-cfY8KuW7.js";var n={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{n as diagram};
2
- //# sourceMappingURL=classDiagram-v2-Q7XG4LA2-rB1DgxOZ.js.map