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"),r=URL.createObjectURL(new Blob([e],{type:"application/javascript"}));try{await import(r)}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"],r=t["exportType"];self.devicePixelRatio=t["devicePixelRatio"];const n=[];self.runOnStartup=function(t){if("function"!=typeof t)throw new Error("runOnStartup called without a function");n.push(t)};const i=t["runtimeScriptList"].map((t=>new URL(t,location.href).toString()));try{await LoadScripts([...i])}catch(t){return void console.error("[C3 runtime] Failed to load all engine scripts in worker: ",t)}const a=t["projectMainScriptPath"],o=t["javaScriptInEventsPath"],s=t["typeScriptInEventsPath"],c=new URL(a,location.href).toString(),l=new URL(o,location.href).toString(),p=new URL(s,location.href).toString();if(a)try{if(await LoadScripts([c]),"preview"===r&&!globalThis.C3_ProjectMainScriptOK)throw new Error("main script did not run to completion")}catch(t){console.error("Error loading project main script: ",t);const r=`Failed to load the project main script (${a}). 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":r})}if(o)try{if(await LoadScripts([l]),"preview"===r&&!globalThis.C3.JavaScriptInEvents)throw new Error("JavaScript in events did not run to completion")}catch(t){console.error("Error loading JavaScript in events: ",t);const r="Failed to load JavaScript 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":r})}if(s)try{if(await LoadScripts([p]),"preview"===r&&!globalThis.C3.TypeScriptInEvents)throw new Error("TypeScript in events did not run to completion")}catch(t){console.error("Error loading TypeScript in events: ",t);const r="Failed to load TypeScript in events. Check all your TypeScript 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":r})}t["runOnStartupFunctions"]=n,e.postMessage({"type":"creating-runtime"}),runtime=self["C3_CreateRuntime"](t),await self["C3_InitRuntime"](runtime,t)}self.addEventListener("message",HandleInitRuntimeMessage);