var z=Object.create;var k=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var K=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Q=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var v=(e,t,r,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!_.call(e,n)&&n!==r&&k(e,n,{get:()=>t[n],enumerable:!(l=N(t,n))||l.enumerable});return e};var Z=(e,t,r)=>(r=e!=null?z(V(e)):{},v(t||!e||!e.__esModule?k(r,"default",{value:e,enumerable:!0}):r,e));var x=Symbol("Comlink.proxy"),I=Symbol("Comlink.endpoint"),W=Symbol("Comlink.releaseProxy"),M=Symbol("Comlink.finalizer"),w=Symbol("Comlink.thrown"),T=e=>typeof e=="object"&&e!==null||typeof e=="function",j={canHandle:e=>T(e)&&e[x],serialize(e){let{port1:t,port2:r}=new MessageChannel;return R(e,t),[r,[r]]},deserialize(e){return e.start(),G(e)}},D={canHandle:e=>T(e)&&w in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},A=new Map([["proxy",j],["throw",D]]);function F(e,t){for(let r of e)if(t===r||r==="*"||r instanceof RegExp&&r.test(t))return!0;return!1}function R(e,t=globalThis,r=["*"]){t.addEventListener("message",function l(n){if(!n||!n.data)return;if(!F(r,n.origin)){console.warn(`Invalid origin '${n.origin}' for comlink proxy`);return}let{id:a,type:g,path:c}=Object.assign({path:[]},n.data),u=(n.data.argumentList||[]).map(y),s;try{let o=c.slice(0,-1).reduce((i,m)=>i[m],e),f=c.reduce((i,m)=>i[m],e);switch(g){case"GET":s=f;break;case"SET":o[c.slice(-1)[0]]=y(n.data.value),s=!0;break;case"APPLY":s=f.apply(o,u);break;case"CONSTRUCT":{let i=new f(...u);s=B(i)}break;case"ENDPOINT":{let{port1:i,port2:m}=new MessageChannel;R(e,m),s=$(i,[i])}break;case"RELEASE":s=void 0;break;default:return}}catch(o){s={value:o,[w]:0}}Promise.resolve(s).catch(o=>({value:o,[w]:0})).then(o=>{let[f,i]=p(o);t.postMessage(Object.assign(Object.assign({},f),{id:a}),i),g==="RELEASE"&&(t.removeEventListener("message",l),C(t),M in e&&typeof e[M]=="function"&&e[M]())}).catch(o=>{let[f,i]=p({value:new TypeError("Unserializable return value"),[w]:0});t.postMessage(Object.assign(Object.assign({},f),{id:a}),i)})}),t.start&&t.start()}function U(e){return e.constructor.name==="MessagePort"}function C(e){U(e)&&e.close()}function G(e,t){let r=new Map;return e.addEventListener("message",function(n){let{data:a}=n;if(!a||!a.id)return;let g=r.get(a.id);if(g)try{g(a)}finally{r.delete(a.id)}}),P(e,r,[],t)}function E(e){if(e)throw new Error("Proxy has been released and is not useable")}function O(e){return d(e,new Map,{type:"RELEASE"}).then(()=>{C(e)})}var h=new WeakMap,b="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{let t=(h.get(e)||0)-1;h.set(e,t),t===0&&O(e)});function Y(e,t){let r=(h.get(t)||0)+1;h.set(t,r),b&&b.register(e,t,e)}function q(e){b&&b.unregister(e)}function P(e,t,r=[],l=function(){}){let n=!1,a=new Proxy(l,{get(g,c){if(E(n),c===W)return()=>{q(a),O(e),t.clear(),n=!0};if(c==="then"){if(r.length===0)return{then:()=>a};let u=d(e,t,{type:"GET",path:r.map(s=>s.toString())}).then(y);return u.then.bind(u)}return P(e,t,[...r,c])},set(g,c,u){E(n);let[s,o]=p(u);return d(e,t,{type:"SET",path:[...r,c].map(f=>f.toString()),value:s},o).then(y)},apply(g,c,u){E(n);let s=r[r.length-1];if(s===I)return d(e,t,{type:"ENDPOINT"}).then(y);if(s==="bind")return P(e,t,r.slice(0,-1));let[o,f]=S(u);return d(e,t,{type:"APPLY",path:r.map(i=>i.toString()),argumentList:o},f).then(y)},construct(g,c){E(n);let[u,s]=S(c);return d(e,t,{type:"CONSTRUCT",path:r.map(o=>o.toString()),argumentList:u},s).then(y)}});return Y(a,e),a}function X(e){return Array.prototype.concat.apply([],e)}function S(e){let t=e.map(p);return[t.map(r=>r[0]),X(t.map(r=>r[1]))]}var L=new WeakMap;function $(e,t){return L.set(e,t),e}function B(e){return Object.assign(e,{[x]:!0})}function p(e){for(let[t,r]of A)if(r.canHandle(e)){let[l,n]=r.serialize(e);return[{type:"HANDLER",name:t,value:l},n]}return[{type:"RAW",value:e},L.get(e)||[]]}function y(e){switch(e.type){case"HANDLER":return A.get(e.name).deserialize(e.value);case"RAW":return e.value}}function d(e,t,r,l){return new Promise(n=>{let a=J();t.set(a,n),e.start&&e.start(),e.postMessage(Object.assign({id:a},r),l)})}function J(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}export{K as a,Q as b,Z as c,R as d,$ as e};
/*! Bundled license information:

comlink/dist/esm/comlink.mjs:
  (**
   * @license
   * Copyright 2019 Google LLC
   * SPDX-License-Identifier: Apache-2.0
   *)
*/
