import { SharedWorkerPolyfill as WebWorker , SharedWorkerSupported , } from "@okikio/sharedworker" ; import EMPTY_WORKER_URL from "worker:../workers/empty.ts" ; export const ModuleWorkerTest = ( ) => { let support = false ; const test = { get type ( ) { support = true ; return "module" ; } , } ; try { const worker = new Worker ( EMPTY_WORKER_URL . replace ( /\.js$/ , ".mjs" ) , test as WorkerOptions ) ; worker ?. terminate ( ) ; return support ; } catch ( e ) { console . log ( e ) ; } return false ; } ; export let ModuleWorkerSupported = ModuleWorkerTest ( ) ; export const WorkerType = ModuleWorkerSupported ? "module" : "classic" ; export const WorkerConfig = ( url , name ? ) => { return [ url . toString ( ) . replace ( /\.js$/ , WorkerType == "module" ? ".mjs" : ".js" ) , { name , type : WorkerType } ] as [ string | URL , WorkerOptions ] ; } ; console . log ( `This browser supports ${ WorkerType } workers!` ) ; console . log ( `This browser supports ${ SharedWorkerSupported ? "Shared Web Workers" : "Normal Web Workers" }!` ) ; export { WebWorker } ; export default WebWorker ;