"use strict";
function sanitizeWorkerId(value) {
    if (!value)
        return "demo";
    return /^[A-Za-z0-9_-]{1,64}$/.test(value) ? value : "demo";
}
function resolveWsPath() {
    const params = new URLSearchParams(window.location.search);
    const workerId = sanitizeWorkerId(params.get("worker_id"));
    const roleParam = params.get("role");
    const role = roleParam === "browser" ? "browser" : "raw";
    return `/ws/${role}/${workerId}/term`;
}
function initTerminalPage() {
    const container = document.getElementById("app");
    if (!(container instanceof HTMLElement)) {
        throw new Error("Missing #app container");
    }
    const TerminalWidget = window.UndefTerminal;
    if (typeof TerminalWidget !== "function") {
        throw new Error("UndefTerminal is not available");
    }
    window.demoTerminal = new TerminalWidget(container, {
        wsUrl: resolveWsPath(),
        title: "Undef Terminal Cloudflare",
    });
}
initTerminalPage();
