import{a as b}from"./chunk-2COJW6JZ.js";import{a as p,b as w}from"./chunk-L4SPVWCZ.js";import{a as c}from"./chunk-IKDRCVQ7.js";import{M as i,g as o,ga as m,ma as h,n}from"./chunk-6JZDPQRU.js";var d=o(p(),1),a=o(w(),1),l=o(b(),1);var v=(()=>{class e{$ws=h(c);term;io;fitAddon;webLinksAddon;resize;elementResize;constructor(){}destroyTerminal(){this.io.end(),this.term.dispose(),this.resize.complete(),this.elementResize&&this.elementResize.complete()}startTerminal(r,s={},f){this.elementResize=f,this.io=this.$ws.connectToNamespace("platform-tools/terminal"),this.term=new d.Terminal(s),setTimeout(()=>{this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon)}),this.fitAddon=new a.FitAddon,this.webLinksAddon=new l.WebLinksAddon,this.resize=new n,this.term.open(r.nativeElement),setTimeout(()=>{this.fitAddon.activate(this.term),this.fitAddon.fit()}),this.io.connected.pipe(i(200)).subscribe(()=>{this.startSession()}),this.io.socket.on("disconnect",()=>{this.term.write(`
\r
\rTerminal disconnected. Is the server running?
\r
\r`)}),this.io.socket.on("process-exit",()=>{this.io.socket.emit("end"),this.startSession()}),this.resize.pipe(i(500)).subscribe(t=>{this.io.socket.emit("resize",t)}),this.io.socket.on("stdout",t=>{this.term.write(t)}),this.term.onData(t=>{this.io.socket.emit("stdin",t)}),this.term.onResize(t=>{this.resize.next(t)}),this.elementResize&&this.elementResize.pipe(i(100)).subscribe({next:()=>{this.fitAddon.fit()}})}startSession(){this.term.reset(),this.io.socket.emit("start-session",{cols:this.term.cols,rows:this.term.rows}),this.resize.next({cols:this.term.cols,rows:this.term.rows})}static \u0275fac=function(s){return new(s||e)};static \u0275prov=m({token:e,factory:e.\u0275fac,providedIn:"root"})}return e})();export{v as a};
