const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["../assets/xterm.DFuMZ0ql.css"])))=>i.map(i=>d[i]);
import{_ as u}from"./PPVm8Dsz.js";async function D(e){const{Terminal:m}=await u(async()=>{const{Terminal:t}=await import("./BTGVxaYV.js").then(i=>i.x);return{Terminal:t}},[],import.meta.url),{FitAddon:h}=await u(async()=>{const{FitAddon:t}=await import("./BlxrFPDK.js").then(i=>i.a);return{FitAddon:t}},[],import.meta.url),{WebLinksAddon:S}=await u(async()=>{const{WebLinksAddon:t}=await import("./DLu6yJIZ.js").then(i=>i.a);return{WebLinksAddon:t}},[],import.meta.url);await u(()=>Promise.resolve({}),__vite__mapDeps([0]),import.meta.url);const d=new h,a=new m({allowTransparency:!0,cursorBlink:!0,cursorStyle:"block",fontFamily:"'SF Mono', 'Fira Code', 'Cascadia Code', 'Menlo', monospace",fontSize:e.fontSize||14,theme:{background:"#0a0a0f",black:"#0a0a0f",blue:"#3b82f6",brightBlack:"#64748b",brightBlue:"#60a5fa",brightCyan:"#67e8f9",brightGreen:"#4ade80",brightMagenta:"#c4b5fd",brightRed:"#f87171",brightWhite:"#f8fafc",brightYellow:"#fbbf24",cursor:"#e2e8f0",cursorAccent:"#0a0a0f",cyan:"#38bdf8",foreground:"#e2e8f0",green:"#22c55e",magenta:"#a78bfa",red:"#ef4444",selectionBackground:"rgba(99, 102, 241, 0.3)",white:"#e2e8f0",yellow:"#f59e0b"}});a.loadAddon(d),a.loadAddon(new S),a.open(e.container),d.fit();const _=new Set(["f","g","h","j","n","o","p","q","s","t","u","w"]);a.attachCustomKeyEventHandler(t=>{const i=t.key.toLowerCase();return t.metaKey?i==="c"||i==="v"?!0:!_.has(i):!0});let f=null;if(e.terminalId&&e.apiKey){const t=e.terminalId,i=e.apiKey;f=r=>{(async()=>{try{if(!r.clipboardData)return;const w=Array.from(r.clipboardData.items).find(b=>b.type.startsWith("image/"));if(!w)return;const g=w.getAsFile();if(!g)return;r.preventDefault();const l=new FileReader,O=await new Promise((b,A)=>{l.onload=()=>{b(l.result)},l.onerror=A,l.readAsDataURL(g)});(await fetch(`/api/terminals/${t}/paste-image`,{body:JSON.stringify({image:O}),headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},method:"POST"})).ok&&n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({data:"",type:"input"}))}catch{}})()},e.container.addEventListener("paste",f)}let n=null,c=null,o=1e3,s=!1;async function y(){if(s)return;let t;try{t=await e.getTicket()}catch{s||(e.onDisconnect?.(),c=setTimeout(()=>{o=Math.min(o*2,3e4),y()},o));return}s||(n=new WebSocket(`${e.wsUrl}?ticket=${t}`),n.onopen=()=>{o=1e3,e.onReconnect?.()},n.onmessage=i=>{const r=JSON.parse(i.data);r.type==="output"||r.type==="scrollback"?a.write(r.data):r.type==="exit"?(a.write(`\r
\x1B[90m[Process exited with code ${r.code}]\x1B[0m\r
`),s=!0,c&&clearTimeout(c),e.onExit?.(r.code)):r.type==="output-dropped"?a.write(`\r
\x1B[33m[${r.bytes} bytes dropped]\x1B[0m\r
`):r.type==="activity"?e.onActivity?.(r.active):r.type==="cwd"&&e.onCwd?.(r.path)},n.onclose=()=>{s||(e.onDisconnect?.(),c=setTimeout(()=>{o=Math.min(o*2,3e4),y()},o))})}y(),a.onData(t=>{n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({data:t,type:"input"}))});const p=new ResizeObserver(()=>{!e.container.offsetWidth||!e.container.offsetHeight||(d.fit(),n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({cols:a.cols,rows:a.rows,type:"resize"})))});p.observe(e.container);function k(){s=!0,c&&clearTimeout(c),f&&e.container.removeEventListener("paste",f),p.disconnect(),n?.close(),a.dispose()}function v(t){n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({data:t,type:"input"}))}return{dispose:k,fitAddon:d,sendInput:v,term:a}}function N(e,m){e.readyState===WebSocket.OPEN&&e.send(JSON.stringify({signal:m,type:"signal"}))}export{D as createTerminal,N as sendSignal};
