-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkermain.js
More file actions
1 lines (1 loc) · 2.8 KB
/
Copy pathworkermain.js
File metadata and controls
1 lines (1 loc) · 2.8 KB
1
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 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=new URL(t["runtimeMainScript"],location.href).toString();let o,a;try{globalThis["C3_SetInitFunctions"]=(t,e)=>{o=t,a=e,globalThis["C3_SetInitFunctions"]=null},await import(i)}catch(t){return void console.error("[C3 runtime] Failed to load all engine scripts in worker: ",t)}const s=t["projectMainScriptPath"],c=t["javaScriptInEventsPath"],l=t["typeScriptInEventsPath"],p=new URL(s,location.href).toString(),d=new URL(c,location.href).toString(),h=new URL(l,location.href).toString();if(s)try{if(await import(p),"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 (${s}). 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(c)try{if(await import(d),"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(l)try{if(await import(h),"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=o(t),await a(runtime,t)}self.addEventListener("message",HandleInitRuntimeMessage);