function p(n){if(typeof WorkerGlobalScope>"u"){console.error("Expose not called in worker thread");return}const i=function(t,e){postMessage({id:t.id,type:"success",payload:e})},c=function(t,e){postMessage({id:t.id,type:"error",payload:e})},s=function(){return Object.keys(n).filter(t=>typeof n[t]=="function")},l=function(t){const e=n[t.action],o=t.payload,r=e(...o);return r instanceof Promise?r:Promise.resolve(r)};onmessage=async function(t){const e=t.data;try{let o;e.action==="getFunctionality"?o=s():o=await l(e),i(e,o)}catch(o){c(e,o)}}}async function d(n){let i=0;const c=[],s=function(e){const o={...e,id:i++},r=new Promise((a,u)=>{c.push({request:o,resolve:a,reject:u})});return n.postMessage(o),r};n.onmessage=function(e){const o=e.data,r=c.findIndex(a=>a.request.id==o.id);if(r<0){console.error("Worker responded to nonexistent job"),console.warn("Worker's response:",o);return}else{const a=c.splice(r,1)[0];o.type=="success"?a.resolve(o.payload):a.reject(o.payload)}},n.onerror=function(e){console.error("Uncaught error in worker:",e),c.splice(0,c.length).forEach(o=>o.reject(e))};const l=await s({action:"getFunctionality",payload:[]}),t={};return l.forEach(e=>t[e]=(...o)=>s({action:e,payload:o})),t.terminate=()=>n.terminate(),t}export{p as e,d as w};