const is_browser = typeof window != "undefined";
if (!is_browser) throw new Error(`Expected to be running in a browser`);
const out = document.getElementById("out");
const result = document.getElementById("result");
const threads = await import("./ferroui-threads.js").catch(() => null);
if (threads === null) {
result.textContent = "state=failed error=the site was built without threads: scripts/build-browser.sh thread_spawn --threads";
} else {
const register = new URLSearchParams(globalThis.location.search).get("ThreadsServiceWorker") !== "false";
if (await threads.ensureCrossOriginIsolated({ register, element: out })) {
const { default: createRuntime } = await import("./thread_spawn.js");
const runtime = await createRuntime();
globalThis.threadSpawn = runtime;
runtime.threadSpawnStart();
const poll = () => {
const state = runtime.threadSpawnState();
result.textContent = state;
if (state.includes("state=running")) { setTimeout(poll, 20); }
};
poll();
}
}