var N=Object.defineProperty,T=Object.defineProperties,b=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,l=(t,r,e)=>r in t?N(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,f=(t,r)=>{for(var e in r||(r={}))y.call(r,e)&&l(t,e,r[e]);if(d)for(var e of d(r))I.call(r,e)&&l(t,e,r[e]);return t},w=(t,r)=>T(t,b(r));const R=t=>r=>{const e=t(r);return r.add(e),e},A=t=>(r,e)=>(t.set(r,e),e),O=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,h=536870912,E=h*2,S=(t,r)=>e=>{const n=r.get(e);let o=n===void 0?e.size:n<E?n+1:0;if(!e.has(o))return t(e,o);if(e.size<h){for(;e.has(o);)o=Math.floor(Math.random()*E);return t(e,o)}if(e.size>O)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;e.has(o);)o=Math.floor(Math.random()*O);return t(e,o)},m=new WeakMap,W=A(m),M=S(W,m),U=R(M),q=t=>typeof t.start=="function",g=new WeakMap,G=t=>w(f({},t),{connect:({call:r})=>async()=>{const{port1:e,port2:n}=new MessageChannel,o=await r("connect",{port:e},[e]);return g.set(n,o),n},disconnect:({call:r})=>async e=>{const n=g.get(e);if(n===void 0)throw new Error("The given port is not connected.");await r("disconnect",{portId:n})},isSupported:({call:r})=>()=>r("isSupported")}),_=new WeakMap,j=t=>{if(_.has(t))return _.get(t);const r=new Map;return _.set(t,r),r},k=t=>{const r=G(t);return e=>{const n=j(e);e.addEventListener("message",({data:s})=>{const{id:a}=s;if(a!==null&&n.has(a)){const{reject:u,resolve:c}=n.get(a);n.delete(a),s.error===void 0?c(s.result):u(new Error(s.error.message))}}),q(e)&&e.start();const o=(s,a=null,u=[])=>new Promise((c,v)=>{const p=M(n);n.set(p,{reject:v,resolve:c}),a===null?e.postMessage({id:p,method:s},u):e.postMessage({id:p,method:s,params:a},u)}),P=(s,a,u=[])=>{e.postMessage({id:null,method:s,params:a},u)};let i={};for(const[s,a]of Object.entries(r))i=w(f({},i),{[s]:a({call:o,notify:P})});return f({},i)}};export{U as a,k as c,M as g};
