diff --git a/src/webterm/static/js/terminal.js b/src/webterm/static/js/terminal.js index fbe58e1..0643ffe 100644 --- a/src/webterm/static/js/terminal.js +++ b/src/webterm/static/js/terminal.js @@ -10,7 +10,7 @@ Example: For tests, pass a Ghostty instance directly: import { Ghostty, Terminal } from "ghostty-web"; const ghostty = await Ghostty.load(); - const term = new Terminal({ ghostty });`);return s}var Z0='ui-monospace, "SFMono-Regular", "FiraCode Nerd Font", "FiraMono Nerd Font", "Fira Code", "Roboto Mono", Menlo, Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace',S={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#555753",black:"#2e3436",red:"#cc0000",green:"#4e9a06",yellow:"#c4a000",blue:"#3465a4",magenta:"#75507b",cyan:"#06989a",white:"#d3d7cf",brightBlack:"#555753",brightRed:"#ef2929",brightGreen:"#8ae234",brightYellow:"#fce94f",brightBlue:"#729fcf",brightMagenta:"#ad7fa8",brightCyan:"#34e2e2",brightWhite:"#eeeeec"},xterm:{background:"#000000",foreground:"#e5e5e5",cursor:"#e5e5e5",cursorAccent:"#000000",selectionBackground:"#d4d4d4",black:"#000000",red:"#cd0000",green:"#00cd00",yellow:"#cdcd00",blue:"#0000cd",magenta:"#cd00cd",cyan:"#00cdcd",white:"#e5e5e5",brightBlack:"#4d4d4d",brightRed:"#ff0000",brightGreen:"#00ff00",brightYellow:"#ffff00",brightBlue:"#0000ff",brightMagenta:"#ff00ff",brightCyan:"#00ffff",brightWhite:"#ffffff"},monokai:{background:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#5b595c",black:"#403e41",red:"#ff6188",green:"#a9dc76",yellow:"#ffd866",blue:"#fc9867",magenta:"#ab9df2",cyan:"#78dce8",white:"#fcfcfa",brightBlack:"#727072",brightRed:"#ff6188",brightGreen:"#a9dc76",brightYellow:"#ffd866",brightBlue:"#fc9867",brightMagenta:"#ab9df2",brightCyan:"#78dce8",brightWhite:"#fcfcfa"},ristretto:{background:"#2d2525",foreground:"#fff1f3",cursor:"#fff1f3",cursorAccent:"#2d2525",selectionBackground:"#403838",black:"#2c2525",red:"#fd6883",green:"#adda78",yellow:"#f9cc6c",blue:"#f38d70",magenta:"#a8a9eb",cyan:"#85dacc",white:"#f9f8f5",brightBlack:"#655761",brightRed:"#fd6883",brightGreen:"#adda78",brightYellow:"#f9cc6c",brightBlue:"#f38d70",brightMagenta:"#a8a9eb",brightCyan:"#85dacc",brightWhite:"#f9f8f5"},dark:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#aeafad",cursorAccent:"#1e1e1e",selectionBackground:"#264f78",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"},light:{background:"#ffffff",foreground:"#383a42",cursor:"#526eff",cursorAccent:"#ffffff",selectionBackground:"#add6ff",black:"#000000",red:"#e45649",green:"#50a14f",yellow:"#c18401",blue:"#4078f2",magenta:"#a626a4",cyan:"#0184bc",white:"#a0a1a7",brightBlack:"#5c6370",brightRed:"#e06c75",brightGreen:"#98c379",brightYellow:"#d19a66",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"},dracula:{background:"#282a36",foreground:"#f8f8f2",cursor:"#f8f8f2",cursorAccent:"#282a36",selectionBackground:"#44475a",black:"#21222c",red:"#ff5555",green:"#50fa7b",yellow:"#f1fa8c",blue:"#bd93f9",magenta:"#ff79c6",cyan:"#8be9fd",white:"#f8f8f2",brightBlack:"#6272a4",brightRed:"#ff6e6e",brightGreen:"#69ff94",brightYellow:"#ffffa5",brightBlue:"#d6acff",brightMagenta:"#ff92df",brightCyan:"#a4ffff",brightWhite:"#ffffff"},catppuccin:{background:"#1e1e2e",foreground:"#cdd6f4",cursor:"#f5e0dc",cursorAccent:"#1e1e2e",selectionBackground:"#45475a",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#f5c2e7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#f5c2e7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},nord:{background:"#2e3440",foreground:"#d8dee9",cursor:"#d8dee9",cursorAccent:"#2e3440",selectionBackground:"#434c5e",black:"#3b4252",red:"#bf616a",green:"#a3be8c",yellow:"#ebcb8b",blue:"#81a1c1",magenta:"#b48ead",cyan:"#88c0d0",white:"#e5e9f0",brightBlack:"#4c566a",brightRed:"#bf616a",brightGreen:"#a3be8c",brightYellow:"#ebcb8b",brightBlue:"#81a1c1",brightMagenta:"#b48ead",brightCyan:"#8fbcbb",brightWhite:"#eceff4"},gruvbox:{background:"#282828",foreground:"#ebdbb2",cursor:"#ebdbb2",cursorAccent:"#282828",selectionBackground:"#504945",black:"#282828",red:"#cc241d",green:"#98971a",yellow:"#d79921",blue:"#458588",magenta:"#b16286",cyan:"#689d6a",white:"#a89984",brightBlack:"#928374",brightRed:"#fb4934",brightGreen:"#b8bb26",brightYellow:"#fabd2f",brightBlue:"#83a598",brightMagenta:"#d3869b",brightCyan:"#8ec07c",brightWhite:"#ebdbb2"},solarized:{background:"#002b36",foreground:"#839496",cursor:"#839496",cursorAccent:"#002b36",selectionBackground:"#073642",black:"#073642",red:"#dc322f",green:"#859900",yellow:"#b58900",blue:"#268bd2",magenta:"#d33682",cyan:"#2aa198",white:"#eee8d5",brightBlack:"#586e75",brightRed:"#cb4b16",brightGreen:"#586e75",brightYellow:"#657b83",brightBlue:"#839496",brightMagenta:"#6c71c4",brightCyan:"#93a1a1",brightWhite:"#fdf6e3"},tokyo:{background:"#1a1b26",foreground:"#a9b1d6",cursor:"#c0caf5",cursorAccent:"#1a1b26",selectionBackground:"#33467c",black:"#15161e",red:"#f7768e",green:"#9ece6a",yellow:"#e0af68",blue:"#7aa2f7",magenta:"#bb9af7",cyan:"#7dcfff",white:"#a9b1d6",brightBlack:"#414868",brightRed:"#f7768e",brightGreen:"#9ece6a",brightYellow:"#e0af68",brightBlue:"#7aa2f7",brightMagenta:"#bb9af7",brightCyan:"#7dcfff",brightWhite:"#c0caf5"}};function G0(V){console.log("[webterm:parseConfig] Parsing config from element");let j={};if(V.dataset.fontFamily){let Z=V.dataset.fontFamily;if(Z.startsWith("var(")){let $=Z.match(/var\(([^)]+)\)/);if($){let P=$[1].trim(),X=getComputedStyle(document.documentElement).getPropertyValue(P).trim();if(X)Z=X,console.log(`[webterm:parseConfig] Resolved CSS variable ${P} to: "${Z}"`);else console.warn(`[webterm:parseConfig] CSS variable ${P} not found, using default font`),Z=Z0}}j.fontFamily=Z,console.log(`[webterm:parseConfig] fontFamily: "${j.fontFamily}"`)}if(V.dataset.fontSize)j.fontSize=parseInt(V.dataset.fontSize,10),console.log(`[webterm:parseConfig] fontSize: ${j.fontSize}`);if(V.dataset.scrollback)j.scrollback=parseInt(V.dataset.scrollback,10),console.log(`[webterm:parseConfig] scrollback: ${j.scrollback}`);if(V.dataset.theme){let Z=V.dataset.theme.toLowerCase();if(console.log(`[webterm:parseConfig] theme attribute: "${V.dataset.theme}" -> normalized: "${Z}"`),console.log(`[webterm:parseConfig] Available themes: ${Object.keys(S).join(", ")}`),console.log(`[webterm:parseConfig] Theme "${Z}" in THEMES? ${Z in S}`),Z in S)j.theme=S[Z],console.log(`[webterm:parseConfig] Using built-in theme "${Z}":`,JSON.stringify(j.theme,null,2));else{console.log("[webterm:parseConfig] Theme not found in THEMES, trying JSON parse...");try{j.theme=JSON.parse(V.dataset.theme),console.log("[webterm:parseConfig] Parsed custom JSON theme:",j.theme)}catch($){console.warn(`[webterm:parseConfig] Unknown theme "${V.dataset.theme}", JSON parse failed:`,$)}}}else console.log("[webterm:parseConfig] No theme attribute found on element");return console.log("[webterm:parseConfig] Final config:",j),j}function p0(){let V=document.querySelectorAll('script[src*="terminal.js"]');if(V.length>0){let j=V[0].src;return j.substring(0,j.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function A(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}class m{terminal;fitAddon;socket=null;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;messageQueue=[];lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;shiftActive=!1;pendingCtrl=!1;pendingShift=!1;fontFamily;fontSize;constructor(V,j,Z,$,P,X){this.element=V,this.wsUrl=j,this.terminal=Z,this.fitAddon=$,this.fontFamily=P,this.fontSize=X}static async create(V,j,Z){console.log("[webterm:create] WebTerminal.create() called"),console.log("[webterm:create] Container:",V),console.log("[webterm:create] wsUrl:",j),console.log("[webterm:create] Config received:",JSON.stringify(Z,null,2));let $=p0();console.log("[webterm:create] WASM path:",$),console.log("[webterm:create] Loading Ghostty WASM...");let P=await U.load($);console.log("[webterm:create] Ghostty loaded:",P);let X=Z.theme??S.tango;console.log("[webterm:create] Theme to use (config.theme ?? THEMES.xterm):",JSON.stringify(X,null,2));let R=Z.fontFamily?.trim()||Z0,K=Z.fontSize??16,O={fontFamily:R,fontSize:K,scrollback:Z.scrollback??1000,cursorBlink:!0,cursorStyle:"block",theme:X,ghostty:P};console.log("[webterm:create] Full ITerminalOptions:",JSON.stringify(O,null,2)),console.log("[webterm:create] Creating ghostty-web Terminal instance...");let Y=new h(O);console.log("[webterm:create] Terminal created:",Y),console.log("[webterm:create] Terminal.options:",Y.options),console.log("[webterm:create] Creating FitAddon...");let _=new d;console.log("[webterm:create] Loading FitAddon into terminal..."),Y.loadAddon(_),console.log("[webterm:create] Calling terminal.open(container)..."),Y.open(V),console.log("[webterm:create] terminal.open() completed");let H=Y;if(console.log("[webterm:create] Terminal internal keys:",Object.keys(H)),H.renderer){console.log("[webterm:create] Renderer exists:",H.renderer);let z=H.renderer;if(console.log("[webterm:create] Renderer keys:",Object.keys(z)),z.theme)console.log("[webterm:create] Renderer.theme:",z.theme);if(z.palette)console.log("[webterm:create] Renderer.palette:",z.palette)}let W=new m(V,j,Y,_,R,K);return console.log("[webterm:create] WebTerminal instance created"),W.initialize(),console.log("[webterm:create] WebTerminal initialized"),W}initialize(){console.log("[webterm:init] initialize() called");let V=this.element.querySelector("canvas");if(console.log("[webterm:init] Canvas element:",V),V)console.log("[webterm:init] Canvas dimensions:",{width:V.width,height:V.height,clientWidth:V.clientWidth,clientHeight:V.clientHeight,style:V.style.cssText});if(console.log("[webterm:init] Container dimensions:",{clientWidth:this.element.clientWidth,clientHeight:this.element.clientHeight}),this.waitForFonts().then(()=>{if(console.log("[webterm:init] Fonts loaded, triggering font reload..."),typeof this.terminal.loadFonts==="function")this.terminal.loadFonts(),console.log("[webterm:init] terminal.loadFonts() called");this.fit(),console.log("[webterm:init] fit() completed");let Z=this.element.querySelector("canvas");if(Z)console.log("[webterm:init] Canvas after fit:",{width:Z.width,height:Z.height,clientWidth:Z.clientWidth,clientHeight:Z.clientHeight})}),this.setupResizeObserver(),window.addEventListener("resize",()=>{this.fit()}),this.terminal.onData((Z)=>{this.send(["stdin",Z])}),this.terminal.onResize((Z)=>{if(this.isValidSize(Z.cols,Z.rows))this.lastValidSize={cols:Z.cols,rows:Z.rows},this.send(["resize",{width:Z.cols,height:Z.rows}])}),this.setupMobileKeyboard(),A())this.setupMobileKeybar();this.connect();let j=()=>{if(A())this.focusMobileInput();else this.terminal.focus()};document.addEventListener("visibilitychange",()=>{if(!document.hidden)j()}),window.addEventListener("focus",()=>{j()}),window.addEventListener("pageshow",()=>{j()})}setupMobileKeyboard(){let V=document.createElement("textarea");V.setAttribute("autocapitalize","off"),V.setAttribute("autocomplete","off"),V.setAttribute("autocorrect","off"),V.setAttribute("spellcheck","false"),V.setAttribute("inputmode","text"),V.setAttribute("enterkeyhint","send"),V.style.cssText=` + const term = new Terminal({ ghostty });`);return s}var Z0='ui-monospace, "SFMono-Regular", "FiraCode Nerd Font", "FiraMono Nerd Font", "Fira Code", "Roboto Mono", Menlo, Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace',S={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#555753",black:"#2e3436",red:"#cc0000",green:"#4e9a06",yellow:"#c4a000",blue:"#3465a4",magenta:"#75507b",cyan:"#06989a",white:"#d3d7cf",brightBlack:"#555753",brightRed:"#ef2929",brightGreen:"#8ae234",brightYellow:"#fce94f",brightBlue:"#729fcf",brightMagenta:"#ad7fa8",brightCyan:"#34e2e2",brightWhite:"#eeeeec"},xterm:{background:"#000000",foreground:"#e5e5e5",cursor:"#e5e5e5",cursorAccent:"#000000",selectionBackground:"#d4d4d4",selectionForeground:"#000000",black:"#000000",red:"#cd0000",green:"#00cd00",yellow:"#cdcd00",blue:"#0000cd",magenta:"#cd00cd",cyan:"#00cdcd",white:"#e5e5e5",brightBlack:"#4d4d4d",brightRed:"#ff0000",brightGreen:"#00ff00",brightYellow:"#ffff00",brightBlue:"#0000ff",brightMagenta:"#ff00ff",brightCyan:"#00ffff",brightWhite:"#ffffff"},monokai:{background:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#5b595c",black:"#403e41",red:"#ff6188",green:"#a9dc76",yellow:"#ffd866",blue:"#fc9867",magenta:"#ab9df2",cyan:"#78dce8",white:"#fcfcfa",brightBlack:"#727072",brightRed:"#ff6188",brightGreen:"#a9dc76",brightYellow:"#ffd866",brightBlue:"#fc9867",brightMagenta:"#ab9df2",brightCyan:"#78dce8",brightWhite:"#fcfcfa"},ristretto:{background:"#2d2525",foreground:"#fff1f3",cursor:"#fff1f3",cursorAccent:"#2d2525",selectionBackground:"#403838",black:"#2c2525",red:"#fd6883",green:"#adda78",yellow:"#f9cc6c",blue:"#f38d70",magenta:"#a8a9eb",cyan:"#85dacc",white:"#f9f8f5",brightBlack:"#655761",brightRed:"#fd6883",brightGreen:"#adda78",brightYellow:"#f9cc6c",brightBlue:"#f38d70",brightMagenta:"#a8a9eb",brightCyan:"#85dacc",brightWhite:"#f9f8f5"},dark:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#aeafad",cursorAccent:"#1e1e1e",selectionBackground:"#264f78",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"},light:{background:"#ffffff",foreground:"#383a42",cursor:"#526eff",cursorAccent:"#ffffff",selectionBackground:"#add6ff",black:"#000000",red:"#e45649",green:"#50a14f",yellow:"#c18401",blue:"#4078f2",magenta:"#a626a4",cyan:"#0184bc",white:"#a0a1a7",brightBlack:"#5c6370",brightRed:"#e06c75",brightGreen:"#98c379",brightYellow:"#d19a66",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"},dracula:{background:"#282a36",foreground:"#f8f8f2",cursor:"#f8f8f2",cursorAccent:"#282a36",selectionBackground:"#44475a",black:"#21222c",red:"#ff5555",green:"#50fa7b",yellow:"#f1fa8c",blue:"#bd93f9",magenta:"#ff79c6",cyan:"#8be9fd",white:"#f8f8f2",brightBlack:"#6272a4",brightRed:"#ff6e6e",brightGreen:"#69ff94",brightYellow:"#ffffa5",brightBlue:"#d6acff",brightMagenta:"#ff92df",brightCyan:"#a4ffff",brightWhite:"#ffffff"},catppuccin:{background:"#1e1e2e",foreground:"#cdd6f4",cursor:"#f5e0dc",cursorAccent:"#1e1e2e",selectionBackground:"#45475a",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#f5c2e7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#f5c2e7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},nord:{background:"#2e3440",foreground:"#d8dee9",cursor:"#d8dee9",cursorAccent:"#2e3440",selectionBackground:"#434c5e",black:"#3b4252",red:"#bf616a",green:"#a3be8c",yellow:"#ebcb8b",blue:"#81a1c1",magenta:"#b48ead",cyan:"#88c0d0",white:"#e5e9f0",brightBlack:"#4c566a",brightRed:"#bf616a",brightGreen:"#a3be8c",brightYellow:"#ebcb8b",brightBlue:"#81a1c1",brightMagenta:"#b48ead",brightCyan:"#8fbcbb",brightWhite:"#eceff4"},gruvbox:{background:"#282828",foreground:"#ebdbb2",cursor:"#ebdbb2",cursorAccent:"#282828",selectionBackground:"#504945",black:"#282828",red:"#cc241d",green:"#98971a",yellow:"#d79921",blue:"#458588",magenta:"#b16286",cyan:"#689d6a",white:"#a89984",brightBlack:"#928374",brightRed:"#fb4934",brightGreen:"#b8bb26",brightYellow:"#fabd2f",brightBlue:"#83a598",brightMagenta:"#d3869b",brightCyan:"#8ec07c",brightWhite:"#ebdbb2"},solarized:{background:"#002b36",foreground:"#839496",cursor:"#839496",cursorAccent:"#002b36",selectionBackground:"#586e75",selectionForeground:"#fdf6e3",black:"#073642",red:"#dc322f",green:"#859900",yellow:"#b58900",blue:"#268bd2",magenta:"#d33682",cyan:"#2aa198",white:"#eee8d5",brightBlack:"#586e75",brightRed:"#cb4b16",brightGreen:"#586e75",brightYellow:"#657b83",brightBlue:"#839496",brightMagenta:"#6c71c4",brightCyan:"#93a1a1",brightWhite:"#fdf6e3"},tokyo:{background:"#1a1b26",foreground:"#a9b1d6",cursor:"#c0caf5",cursorAccent:"#1a1b26",selectionBackground:"#4c5e90",selectionForeground:"#dfe3f7",black:"#15161e",red:"#f7768e",green:"#9ece6a",yellow:"#e0af68",blue:"#7aa2f7",magenta:"#bb9af7",cyan:"#7dcfff",white:"#a9b1d6",brightBlack:"#414868",brightRed:"#f7768e",brightGreen:"#9ece6a",brightYellow:"#e0af68",brightBlue:"#7aa2f7",brightMagenta:"#bb9af7",brightCyan:"#7dcfff",brightWhite:"#c0caf5"}};function G0(V){console.log("[webterm:parseConfig] Parsing config from element");let j={};if(V.dataset.fontFamily){let Z=V.dataset.fontFamily;if(Z.startsWith("var(")){let $=Z.match(/var\(([^)]+)\)/);if($){let P=$[1].trim(),X=getComputedStyle(document.documentElement).getPropertyValue(P).trim();if(X)Z=X,console.log(`[webterm:parseConfig] Resolved CSS variable ${P} to: "${Z}"`);else console.warn(`[webterm:parseConfig] CSS variable ${P} not found, using default font`),Z=Z0}}j.fontFamily=Z,console.log(`[webterm:parseConfig] fontFamily: "${j.fontFamily}"`)}if(V.dataset.fontSize)j.fontSize=parseInt(V.dataset.fontSize,10),console.log(`[webterm:parseConfig] fontSize: ${j.fontSize}`);if(V.dataset.scrollback)j.scrollback=parseInt(V.dataset.scrollback,10),console.log(`[webterm:parseConfig] scrollback: ${j.scrollback}`);if(V.dataset.theme){let Z=V.dataset.theme.toLowerCase();if(console.log(`[webterm:parseConfig] theme attribute: "${V.dataset.theme}" -> normalized: "${Z}"`),console.log(`[webterm:parseConfig] Available themes: ${Object.keys(S).join(", ")}`),console.log(`[webterm:parseConfig] Theme "${Z}" in THEMES? ${Z in S}`),Z in S)j.theme=S[Z],console.log(`[webterm:parseConfig] Using built-in theme "${Z}":`,JSON.stringify(j.theme,null,2));else{console.log("[webterm:parseConfig] Theme not found in THEMES, trying JSON parse...");try{j.theme=JSON.parse(V.dataset.theme),console.log("[webterm:parseConfig] Parsed custom JSON theme:",j.theme)}catch($){console.warn(`[webterm:parseConfig] Unknown theme "${V.dataset.theme}", JSON parse failed:`,$)}}}else console.log("[webterm:parseConfig] No theme attribute found on element");return console.log("[webterm:parseConfig] Final config:",j),j}function p0(){let V=document.querySelectorAll('script[src*="terminal.js"]');if(V.length>0){let j=V[0].src;return j.substring(0,j.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function A(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}class m{terminal;fitAddon;socket=null;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;messageQueue=[];lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;shiftActive=!1;pendingCtrl=!1;pendingShift=!1;fontFamily;fontSize;constructor(V,j,Z,$,P,X){this.element=V,this.wsUrl=j,this.terminal=Z,this.fitAddon=$,this.fontFamily=P,this.fontSize=X}static async create(V,j,Z){console.log("[webterm:create] WebTerminal.create() called"),console.log("[webterm:create] Container:",V),console.log("[webterm:create] wsUrl:",j),console.log("[webterm:create] Config received:",JSON.stringify(Z,null,2));let $=p0();console.log("[webterm:create] WASM path:",$),console.log("[webterm:create] Loading Ghostty WASM...");let P=await U.load($);console.log("[webterm:create] Ghostty loaded:",P);let X=Z.theme??S.tango;console.log("[webterm:create] Theme to use (config.theme ?? THEMES.xterm):",JSON.stringify(X,null,2));let R=Z.fontFamily?.trim()||Z0,K=Z.fontSize??16,O={fontFamily:R,fontSize:K,scrollback:Z.scrollback??1000,cursorBlink:!0,cursorStyle:"block",theme:X,ghostty:P};console.log("[webterm:create] Full ITerminalOptions:",JSON.stringify(O,null,2)),console.log("[webterm:create] Creating ghostty-web Terminal instance...");let Y=new h(O);console.log("[webterm:create] Terminal created:",Y),console.log("[webterm:create] Terminal.options:",Y.options),console.log("[webterm:create] Creating FitAddon...");let _=new d;console.log("[webterm:create] Loading FitAddon into terminal..."),Y.loadAddon(_),console.log("[webterm:create] Calling terminal.open(container)..."),Y.open(V),console.log("[webterm:create] terminal.open() completed");let H=Y;if(console.log("[webterm:create] Terminal internal keys:",Object.keys(H)),H.renderer){console.log("[webterm:create] Renderer exists:",H.renderer);let z=H.renderer;if(console.log("[webterm:create] Renderer keys:",Object.keys(z)),z.theme)console.log("[webterm:create] Renderer.theme:",z.theme);if(z.palette)console.log("[webterm:create] Renderer.palette:",z.palette)}let W=new m(V,j,Y,_,R,K);return console.log("[webterm:create] WebTerminal instance created"),W.initialize(),console.log("[webterm:create] WebTerminal initialized"),W}initialize(){console.log("[webterm:init] initialize() called");let V=this.element.querySelector("canvas");if(console.log("[webterm:init] Canvas element:",V),V)console.log("[webterm:init] Canvas dimensions:",{width:V.width,height:V.height,clientWidth:V.clientWidth,clientHeight:V.clientHeight,style:V.style.cssText});if(console.log("[webterm:init] Container dimensions:",{clientWidth:this.element.clientWidth,clientHeight:this.element.clientHeight}),this.waitForFonts().then(()=>{if(console.log("[webterm:init] Fonts loaded, triggering font reload..."),typeof this.terminal.loadFonts==="function")this.terminal.loadFonts(),console.log("[webterm:init] terminal.loadFonts() called");this.fit(),console.log("[webterm:init] fit() completed");let Z=this.element.querySelector("canvas");if(Z)console.log("[webterm:init] Canvas after fit:",{width:Z.width,height:Z.height,clientWidth:Z.clientWidth,clientHeight:Z.clientHeight})}),this.setupResizeObserver(),window.addEventListener("resize",()=>{this.fit()}),this.terminal.onData((Z)=>{this.send(["stdin",Z])}),this.terminal.onResize((Z)=>{if(this.isValidSize(Z.cols,Z.rows))this.lastValidSize={cols:Z.cols,rows:Z.rows},this.send(["resize",{width:Z.cols,height:Z.rows}])}),this.setupMobileKeyboard(),A())this.setupMobileKeybar();this.connect();let j=()=>{if(A())this.focusMobileInput();else this.terminal.focus()};document.addEventListener("visibilitychange",()=>{if(!document.hidden)j()}),window.addEventListener("focus",()=>{j()}),window.addEventListener("pageshow",()=>{j()})}setupMobileKeyboard(){let V=document.createElement("textarea");V.setAttribute("autocapitalize","off"),V.setAttribute("autocomplete","off"),V.setAttribute("autocorrect","off"),V.setAttribute("spellcheck","false"),V.setAttribute("inputmode","text"),V.setAttribute("enterkeyhint","send"),V.style.cssText=` position: absolute; left: 0; top: 0;