-
Notifications
You must be signed in to change notification settings - Fork 4
/
worker.js
1 lines (1 loc) · 1.18 KB
/
worker.js
1
!function(){"use strict";const{assign:e}=Object,s="function"==typeof importScripts;s||(document.currentScript&&document.currentScript.src||new URL("tmp.js",document.baseURI).href).replace(/\/[^/]*$/,"");const t=t=>new Promise(((o,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,o(e)};if(self.exports={},self.module={exports:exports},s)importScripts(t),n();else{const{head:s}=document;e(s.appendChild(document.createElement("script")),{onload(){s.removeChild(this),n()},onerror:r,src:t})}}));let o=null;addEventListener("message",(({data:{id:e,action:s,options:r}})=>{if("init"===s)o||(o=t(r.library).then((({init:e})=>e(r)))),o.then((()=>postMessage({id:e,result:"OK"})),(({message:s})=>postMessage({id:e,error:s})));else if("close"===s)o.then((s=>s.close().then((()=>{postMessage({id:e})}),(({message:s})=>{postMessage({id:e,error:s})}))));else if("create_function"===s)o.then((t=>{try{const[o,n]=r,i=t[s](o,Function("return "+n)());postMessage({id:e,result:i})}catch({message:s}){postMessage({id:e,error:s})}}));else{const{template:t,values:n}=r;o.then((o=>{o[s](t,...n).then((s=>{postMessage({id:e,result:s})}),(({message:s})=>{postMessage({id:e,error:s})}))}))}}))}();