let hasInitialised=!1,runtime=null;function HandleInitRuntimeMessage(t){const e=t.data;e&&"init-runtime"===e["type"]&&(InitRuntime(e),self.removeEventListener("message",HandleInitRuntimeMessage))}function IsAbsoluteURL(t){return/^(?:[a-z\-]+:)?\/\//.test(t)||"data:"===t.substr(0,5)||"blob:"===t.substr(0,5)}function IsRelativeURL(t){return!IsAbsoluteURL(t)}async function LoadScripts(t){if(1===t.length){const e=t[0];await import((IsRelativeURL(e)?"./":"")+e)}else{const e=t.map((t=>`import "${IsRelativeURL(t)?"./":""}${t}";`)).join("\n"),n=URL.createObjectURL(new Blob([e],{type:"application/javascript"}));try{await import(n)}catch(e){console.warn("[Construct] Unable to import script from blob: URL. Falling back to loading scripts sequentially, which could significantly increase loading time. Make sure blob: URLs are allowed for best performance.",e);for(const e of t)await import((IsRelativeURL(e)?"./":"")+e)}}}async function InitRuntime(t){if(hasInitialised)throw new Error("already initialised");hasInitialised=!0;const e=t["messagePort"],n=t["exportType"];self.devicePixelRatio=t["devicePixelRatio"];const i=[];self.runOnStartup=function(t){if("function"!=typeof t)throw new Error("runOnStartup called without a function");i.push(t)};const r=t["runtimeScriptList"].map((t=>new URL(t,location.href).toString()));try{await LoadScripts([...r])}catch(t){return void console.error("[C3 runtime] Failed to load all engine scripts in worker: ",t)}const o=t["projectMainScriptPath"],a=t["scriptsInEventsPath"],s=new URL(o,location.href).toString(),c=new URL(a,location.href).toString();if(o)try{if(await LoadScripts([s]),"preview"===n&&!globalThis.C3_ProjectMainScriptOK)throw new Error("main script did not run to completion")}catch(t){console.error("Error loading project main script: ",t);const n=`Failed to load the project main script (${o}). Check all your JavaScript code has valid syntax, all imports are written correctly, and that an exception was not thrown running the script. Press F12 and check the console for error details.`;e.postMessage({"type":"alert-error","message":n})}if(a)try{if(await LoadScripts([c]),"preview"===n&&!globalThis.C3.ScriptsInEvents)throw new Error("scripts in events did not run to completion")}catch(t){console.error("Error loading scripts in events: ",t);const n="Failed to load scripts in events. Check all your JavaScript code has valid syntax, all imports are written correctly, and that an exception was not thrown running the 'Imports for events' script. Press F12 and check the console for error details.";e.postMessage({"type":"alert-error","message":n})}t["runOnStartupFunctions"]=i,e.postMessage({"type":"creating-runtime"}),runtime=self["C3_CreateRuntime"](t),await self["C3_InitRuntime"](runtime,t)}self.addEventListener("message",HandleInitRuntimeMessage);