import { __require as e } from "../../../_virtual/_rolldown/runtime.mjs";
import { isNode as t } from "../constants/vite.constants.mjs";
import { workerNodeURL as n } from "./worker.registry.mjs";
import { WorkerWrapper as r } from "./WorkerWrapper.mjs";
//#region libs/shared/common/src/webworker/workerFactory.ts
var i = class i {
	static rnWorkerFactory = null;
	constructor() {}
	static resolveWorkerURL = async (e) => {
		let { getWorkerViteURL: t } = await import("./viteWorkerURL.constant.mjs");
		return (await t())[e];
	};
	static async createBrowserWorker(e) {
		let t = await i.resolveWorkerURL(e);
		return new Worker(t, { type: "module" });
	}
	static async createNodeWorker(t) {
		let { Worker: r } = e("worker_threads"), i = e("path"), { existsSync: a } = e("fs"), o = i.join(__dirname, n[t]), s = o.replace(".js", ".cjs");
		return new r(a(s) ? s : o);
	}
	static async createWorker(e) {
		return t ? i.createNodeWorker(e) : i.createBrowserWorker(e);
	}
	static async getWebWorker(e) {
		return i.rnWorkerFactory ? (console.log("using rnWorkerFactory"), console.log("WorkerFactory.rnWorkerFactory", i.rnWorkerFactory), new r(i.rnWorkerFactory(e))) : (console.log("creating worker from createWorker"), new r(await i.createWorker(e)));
	}
};
//#endregion
export { i as WorkerFactory };
