reflected 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/async-CM1iXZPW.js +44 -0
  2. package/dist/async-OLiknCrf.js +41 -0
  3. package/dist/async.js +856 -1
  4. package/dist/broadcast-B4sl9DBp.js +24 -0
  5. package/dist/broadcast-eR5_7TCY.js +15 -0
  6. package/dist/broadcast.js +850 -1
  7. package/dist/ffi/async-0Q0H4a_N.js +41 -0
  8. package/dist/ffi/async-CbwemiL2.js +41 -0
  9. package/dist/ffi/async-D6Zj6i_Q.js +44 -0
  10. package/dist/ffi/async-DLrN8K6M.js +44 -0
  11. package/dist/ffi/broadcast-CKNplfox.js +15 -0
  12. package/dist/ffi/broadcast-CbbtYobq.js +25 -0
  13. package/dist/ffi/broadcast-DIucqhL0.js +25 -0
  14. package/dist/ffi/broadcast-uydYnG6E.js +15 -0
  15. package/dist/ffi/global-DzpOeFX2.js +14 -0
  16. package/dist/ffi/global-LTfnrHcF.js +11 -0
  17. package/dist/ffi/i32-Cw-Rqr5y.js +13 -0
  18. package/dist/ffi/main.js +650 -1
  19. package/dist/ffi/message-2Dqj3uZ3.js +15 -0
  20. package/dist/ffi/message-Co0Oew7f.js +25 -0
  21. package/dist/ffi/message-Cxjrx_su.js +25 -0
  22. package/dist/ffi/message-mK0eTb54.js +15 -0
  23. package/dist/ffi/sender-B7Xmjz4q.js +194 -0
  24. package/dist/ffi/sender-C0gu9RzR.js +194 -0
  25. package/dist/ffi/shared-5Nhc4gvB.js +175 -0
  26. package/dist/ffi/shared-B3KmQkGh.js +425 -0
  27. package/dist/ffi/shared-CjWXp6-D.js +171 -0
  28. package/dist/ffi/shared-Czh3AlGt.js +53 -0
  29. package/dist/ffi/shared-DZdgWBc6.js +53 -0
  30. package/dist/ffi/shared-array-buffer-BQgQXQvC.js +28 -0
  31. package/dist/ffi/shared-ddawRQD0.js +425 -0
  32. package/dist/ffi/views-C3SJnvMr.js +48 -0
  33. package/dist/ffi/views-DBBYng9N.js +52 -0
  34. package/dist/ffi/worker.js +616 -1
  35. package/dist/ffi/xhr-Be-3qHQb.js +101 -0
  36. package/dist/ffi/xhr-CKhf21P8.js +41 -0
  37. package/dist/ffi/xhr-CRJGE1xP.js +41 -0
  38. package/dist/ffi/xhr-DSsSGsb-.js +101 -0
  39. package/dist/i32-UV5fM9Tw.js +12 -0
  40. package/dist/index.js +57 -1
  41. package/dist/message-D_SM4ST4.js +24 -0
  42. package/dist/message-vCWcUEmt.js +15 -0
  43. package/dist/message.js +843 -1
  44. package/dist/proxy/main/async-8J3q5T6q.js +41 -0
  45. package/dist/proxy/main/async-Di4MuQWe.js +44 -0
  46. package/dist/proxy/main/broadcast-CR8vlkKk.js +24 -0
  47. package/dist/proxy/main/broadcast-LNW6nFVD.js +15 -0
  48. package/dist/proxy/main/channel-NcnPEVL4.js +110 -0
  49. package/dist/proxy/main/i32-UV5fM9Tw.js +12 -0
  50. package/dist/proxy/main/message-j-4BYSZ4.js +24 -0
  51. package/dist/proxy/main/message-uirwoNUQ.js +15 -0
  52. package/dist/proxy/main/proxy.js +106 -1
  53. package/dist/proxy/main/sender-Dkjjbv2Y.js +194 -0
  54. package/dist/proxy/main/shared-C3U1MNPd.js +53 -0
  55. package/dist/proxy/main/shared-CV7CPYuP.js +43 -0
  56. package/dist/proxy/main/shared-DdPca9Ke.js +431 -0
  57. package/dist/proxy/main/shared-array-buffer-BQgQXQvC.js +28 -0
  58. package/dist/proxy/main/xhr-BUjEbkCh.js +100 -0
  59. package/dist/proxy/main/xhr-WnkM0dVo.js +41 -0
  60. package/dist/proxy/worker/async-CZJaURwO.js +41 -0
  61. package/dist/proxy/worker/async-DaSAye0a.js +44 -0
  62. package/dist/proxy/worker/broadcast-DRVfswix.js +24 -0
  63. package/dist/proxy/worker/broadcast-fWsZlH8v.js +15 -0
  64. package/dist/proxy/worker/channel-NcnPEVL4.js +110 -0
  65. package/dist/proxy/worker/i32-UV5fM9Tw.js +12 -0
  66. package/dist/proxy/worker/message-Bots8UXM.js +15 -0
  67. package/dist/proxy/worker/message-sej0J6k5.js +24 -0
  68. package/dist/proxy/worker/proxy.js +79 -1
  69. package/dist/proxy/worker/sender-D5Lm-DmC.js +194 -0
  70. package/dist/proxy/worker/shared-CgOGpfKJ.js +431 -0
  71. package/dist/proxy/worker/shared-Cn1K0k8G.js +53 -0
  72. package/dist/proxy/worker/shared-DR7YYduq.js +41 -0
  73. package/dist/proxy/worker/shared-array-buffer-BQgQXQvC.js +28 -0
  74. package/dist/proxy/worker/xhr-CQDzS28h.js +100 -0
  75. package/dist/proxy/worker/xhr-DAgmljtu.js +41 -0
  76. package/dist/sender-BSx3lj4w.js +193 -0
  77. package/dist/shared-Ccm1cPah.js +125 -0
  78. package/dist/shared-DVDPRDN_.js +53 -0
  79. package/dist/shared-L0wiAfqu.js +431 -0
  80. package/dist/shared-array-buffer-BQgQXQvC.js +28 -0
  81. package/dist/sw.js +155 -1
  82. package/dist/with-resolvers-DsO_nhbc.js +24 -0
  83. package/dist/xhr-BZOjL92j.js +100 -0
  84. package/dist/xhr-Crh-419R.js +41 -0
  85. package/dist/xhr.js +909 -1
  86. package/package.json +1 -1
  87. package/reflected.tar.gz +0 -0
  88. package/dist/async-C2eqvaGm.js +0 -1
  89. package/dist/async-s2VCmNNG.js +0 -1
  90. package/dist/broadcast-CArZGSOF.js +0 -1
  91. package/dist/broadcast-f7NecPmf.js +0 -1
  92. package/dist/ffi/async-B_TI4xaG.js +0 -1
  93. package/dist/ffi/async-BeKYhv9s.js +0 -1
  94. package/dist/ffi/async-Dl9wCRDA.js +0 -1
  95. package/dist/ffi/async-F0rxZjV9.js +0 -1
  96. package/dist/ffi/broadcast-CBUwPa0e.js +0 -1
  97. package/dist/ffi/broadcast-Ce_cOurt.js +0 -1
  98. package/dist/ffi/broadcast-D0jZEoUb.js +0 -1
  99. package/dist/ffi/broadcast-D7p6b88J.js +0 -1
  100. package/dist/ffi/global-B3nXXiRL.js +0 -1
  101. package/dist/ffi/global-Bs8RLRoX.js +0 -1
  102. package/dist/ffi/i32-BkNtpHwD.js +0 -1
  103. package/dist/ffi/message-BdbPt0y5.js +0 -1
  104. package/dist/ffi/message-DNbm1E-6.js +0 -1
  105. package/dist/ffi/message-DW2TgKPr.js +0 -1
  106. package/dist/ffi/message-TyU9xCIl.js +0 -1
  107. package/dist/ffi/sender-C5EHIpuL.js +0 -1
  108. package/dist/ffi/sender-DBFDKow4.js +0 -1
  109. package/dist/ffi/shared-BfrghvHB.js +0 -1
  110. package/dist/ffi/shared-C2XCOXcu.js +0 -1
  111. package/dist/ffi/shared-Cs1s8cy4.js +0 -1
  112. package/dist/ffi/shared-DsgUjYDJ.js +0 -1
  113. package/dist/ffi/shared-DwSbyGXy.js +0 -1
  114. package/dist/ffi/shared-DyOzpRO0.js +0 -1
  115. package/dist/ffi/shared-array-buffer-cwdMr2mc.js +0 -1
  116. package/dist/ffi/views-CdOIrBQR.js +0 -1
  117. package/dist/ffi/views-Cr2pQ4B-.js +0 -1
  118. package/dist/ffi/xhr-BkOoxiJZ.js +0 -1
  119. package/dist/ffi/xhr-C598zZcp.js +0 -1
  120. package/dist/ffi/xhr-CasCWs_z.js +0 -1
  121. package/dist/ffi/xhr-DHyu_Jz0.js +0 -1
  122. package/dist/i32-C78nBJH2.js +0 -1
  123. package/dist/message-RcKwy8Ib.js +0 -1
  124. package/dist/message-l7W12V0c.js +0 -1
  125. package/dist/proxy/main/async-Bc0QcTaC.js +0 -1
  126. package/dist/proxy/main/async-CyZdYOvJ.js +0 -1
  127. package/dist/proxy/main/broadcast-BX9FmxMK.js +0 -1
  128. package/dist/proxy/main/broadcast-DXhTouQy.js +0 -1
  129. package/dist/proxy/main/channel-DQBWE7_E.js +0 -1
  130. package/dist/proxy/main/i32-C78nBJH2.js +0 -1
  131. package/dist/proxy/main/message-CbPHeJAY.js +0 -1
  132. package/dist/proxy/main/message-DxRlOVN7.js +0 -1
  133. package/dist/proxy/main/sender-CNwZwCuI.js +0 -1
  134. package/dist/proxy/main/shared-BoatDt-V.js +0 -1
  135. package/dist/proxy/main/shared-FMegJ6yb.js +0 -1
  136. package/dist/proxy/main/shared-array-buffer-cwdMr2mc.js +0 -1
  137. package/dist/proxy/main/shared-z_jGYqUa.js +0 -1
  138. package/dist/proxy/main/xhr-BaBkekSn.js +0 -1
  139. package/dist/proxy/main/xhr-Fg-l74MV.js +0 -1
  140. package/dist/proxy/worker/async-Do59YjcF.js +0 -1
  141. package/dist/proxy/worker/async-fqI-s7gn.js +0 -1
  142. package/dist/proxy/worker/broadcast-Bdt9gmj_.js +0 -1
  143. package/dist/proxy/worker/broadcast-D7rjohJL.js +0 -1
  144. package/dist/proxy/worker/channel-DQBWE7_E.js +0 -1
  145. package/dist/proxy/worker/i32-C78nBJH2.js +0 -1
  146. package/dist/proxy/worker/message-BvU2dKHz.js +0 -1
  147. package/dist/proxy/worker/message-DhtuceT9.js +0 -1
  148. package/dist/proxy/worker/sender-CWhM7QKB.js +0 -1
  149. package/dist/proxy/worker/shared-DDIlHBz4.js +0 -1
  150. package/dist/proxy/worker/shared-NtUlwI0Z.js +0 -1
  151. package/dist/proxy/worker/shared-QrUiXPgc.js +0 -1
  152. package/dist/proxy/worker/shared-array-buffer-cwdMr2mc.js +0 -1
  153. package/dist/proxy/worker/xhr-CK-Z6L0B.js +0 -1
  154. package/dist/proxy/worker/xhr-JKtROQ3y.js +0 -1
  155. package/dist/sender-D7tfUn3T.js +0 -1
  156. package/dist/shared-BCEcO4-0.js +0 -1
  157. package/dist/shared-BWvJKuCK.js +0 -1
  158. package/dist/shared-BhhIigP4.js +0 -1
  159. package/dist/shared-array-buffer-cwdMr2mc.js +0 -1
  160. package/dist/with-resolvers-CHEvl4oe.js +0 -1
  161. package/dist/xhr-Bd0lMv0-.js +0 -1
  162. package/dist/xhr-DaixJn9d.js +0 -1
package/dist/async.js CHANGED
@@ -1 +1,856 @@
1
- const e=Promise.withResolvers||function(){var e,t,s=new this((s,n)=>{e=s,t=n});return{resolve:e,reject:t,promise:s}};var t=e.bind(Promise),s=e=>{const t=new Int32Array(1);return()=>t[0]++},n="fc260aad-4404-43b8-ae9d-2c06554bb294";const r=2*Int32Array.BYTES_PER_ELEMENT;let a=!0;try{crypto.randomUUID()}catch(e){a=!1}const o=e=>e,c=a?()=>crypto.randomUUID():()=>(Date.now()+Math.random()).toString(36),{isArray:i}=Array;class u extends Worker{#e;#t;constructor(e,t){const r=t.onsend??o;super(e,t),this.#e=s(),this.#t=new Map,super.addEventListener("message",async e=>{const{data:t}=e;if(i(t)&&2===t.length&&t[0]===n){e.stopImmediatePropagation(),e.preventDefault();const[s,n]=t[1],a=this.#t.get(s);this.#t.delete(s),a(await r(n))}})}send(e,...s){const r=this.#e(),{promise:a,resolve:o}=t();return this.#t.set(r,o),super.postMessage([n,[r,e]],...s),a}}let{SharedArrayBuffer:l}=globalThis;try{new l(4,{maxByteLength:8})}catch(e){l=class extends ArrayBuffer{get growable(){return super.resizable}grow(e){super.resize(e)}}}let h=0;const p=h++,f=h++,y=h++,g=h++,d=h++,b=h++,w=h++,m=h++,v=h++,A=h++,k=h++,S=h++,B=h++,U=h++,M=h++,x=h++,E=h++,L=h++,I=h++,T=h++,O=h++,D=h++,P=h++,F=h++,N=h++,R=h++,j=h++,q=h++;const z=globalThis.ImageData||class{};class _{static push(e,t){e.sync(!1),e._(t,t.length)}constructor(e,t){const s=[];this.l=0,this.o=s,this.v=new Uint8Array(e,t),this.push=s.push.bind(s)}get length(){return this.l+this.o.length}sync(e){const t=this.o,s=t.length;s&&this._(e?t:t.splice(0),s)}_(e,t){const{buffer:s,byteOffset:n}=this.v,r=this.l;this.l+=t,t+=n+r,s.byteLength<t&&s.grow(t),this.v.set(e,r)}}const $=new Map(Reflect.ownKeys(Symbol).map(e=>[Symbol[e],`@${String(e)}`])),C=e=>$.get(e)||((e,t)=>void 0===t?"?":void 0===Symbol.keyFor(e)?`!${t}`:`#${t}`)(e,e.description),J=Object.defineProperty,K=Array.isArray,V=ArrayBuffer.isView,W=new TextDecoder,Y=new TextEncoder,G=new ArrayBuffer(8),H=new DataView(G),Q=new Uint8Array(G),{getPrototypeOf:X}=Object,{construct:Z}=Reflect,{toStringTag:ee}=Symbol,te=(e,t=e[ee])=>t in globalThis?t:te(Z(X(e.constructor),[0])),{isNaN:se,isFinite:ne,isInteger:re}=Number,{ownKeys:ae}=Reflect,{is:oe}=Object,ce=(e,t,s)=>{const n=s.get(e),r=!n;return r?(H.setUint32(0,t.length,!0),s.set(e,[Q[0],Q[1],Q[2],Q[3]])):t.push(q,n[0],n[1],n[2],n[3]),r},ie=(e,t,s)=>{H.setUint32(0,s,!0),e.push(t,Q[0],Q[1],Q[2],Q[3])},ue=(e,t,s)=>{switch(typeof e){case"number":e&&ne(e)?re(e)&&e<256&&-1<e?t.push(b,e):(H.setFloat64(0,e,!0),t.push(d,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6],Q[7])):se(e)?t.push(w):e?t.push(e<0?v:m):t.push(oe(e,0)?A:k);break;case"object":switch(!0){case null===e:t.push(g);break;case!ce(e,t,s):break;case K(e):{const n=e.length;ie(t,x,n);for(let r=0;r<n;r++)ue(e[r],t,s);break}case V(e):if(t.push(F),ue(te(e),t,s),e=e.buffer,!ce(e,t,s))break;case e instanceof ArrayBuffer:{const s=new Uint8Array(e);ie(t,E,s.length),he(t,s);break}case e instanceof Date:t.push(L),ue(e.getTime(),t,s);break;case e instanceof Map:ie(t,T,e.size);for(const[n,r]of e)ue(n,t,s),ue(r,t,s);break;case e instanceof Set:ie(t,P,e.size);for(const n of e)ue(n,t,s);break;case e instanceof Error:t.push(I),ue(e.name,t,s),ue(e.message,t,s),ue(e.stack,t,s);break;case e instanceof z:t.push(N),ue(e.data,t,s),ue(e.width,t,s),ue(e.height,t,s),ue(e.colorSpace,t,s),ue(e.pixelFormat,t,s);break;case e instanceof RegExp:t.push(D),ue(e.source,t,s),ue(e.flags,t,s);break;case e instanceof File:t.push(j),ue(e.name,t,s),ue(e.lastModified,t,s);case e instanceof Blob:{const n=e.size;t.push(R),ue(e.type,t,s),ue(n,t,s);const r=t.length;he(t,new Uint8Array(n)),le.push(e.arrayBuffer().then(e=>[r,e]));break}default:if("toJSON"in e){const n=e.toJSON();ue(n===e?null:n,t,s)}else{const n=ae(e),r=n.length;ie(t,O,r);for(let a=0;a<r;a++){const r=n[a];ue(r,t,s),ue(e[r],t,s)}}}break;case"string":if(ce(e,t,s)){const s=Y.encode(e);ie(t,U,s.length),he(t,s)}break;case"boolean":t.push(e?f:p);break;case"symbol":t.push(M),ue(C(e),t,s);break;case"bigint":{let s=S;9223372036854775807n<e?(H.setBigUint64(0,e,!0),s=B):H.setBigInt64(0,e,!0),t.push(s,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6],Q[7]);break}default:t.push(y)}},le=[];let he=(e,t)=>{for(let s=e.push,n=0,r=t.length;n<r;n+=32767)s.apply(e,t.subarray(n,n+32767))};const pe=({byteOffset:e=0,Array:t=_}={})=>(s,n)=>{const r=new t(n,e);he=t.push,ue(s,r,new Map);const a=r.length;return r.sync(!0),le.length?Promise.all(le.splice(0)).then(t=>{const s=new Uint8Array(n,e);for(const[e,n]of t)s.set(new Uint8Array(n),e);return a}):a},fe=(e,t,s)=>{const n=new Int32Array(e),a=(t.encoder??pe)({byteOffset:r}),c=t.onsync??o,i=e=>{n[1]=e,n[0]=1};return async({data:t})=>(t=>{const s=a(t,e);return"number"==typeof s?i(s):s.then(i)})(await c(t))},ye=e=>{switch(typeof e){case"symbol":case"function":return!1}return!0},ge="async";var de=(e=>(s,n)=>{const{promise:r,resolve:a}=t();return new e(s,n,a),r})(class extends u{constructor(e,t,s){const n=c(),a=new BroadcastChannel(n),o=(({initByteLength:e=1024,maxByteLength:t=8192})=>new l(r+e,{maxByteLength:r+t}))(t),i=new Int32Array(o),u=fe(o,t);a.addEventListener("message",async({data:[e,t]})=>{await u({data:t}),a.postMessage([e,new Uint8Array(o,r,i[1])])}),super(...((e,t,s)=>{const n=new URL(e,location.href);return n.searchParams.set("reflected",t),[n,{...s,type:"module"}]})(e,ge,t)),super.addEventListener("message",()=>s(this),{once:!0}),super.postMessage(((e,t)=>{const s={};for(const e in t){const n=t[e];ye(e)&&ye(n)&&(s[e]=n)}return[e,s]})(o,t).concat(n))}get channel(){return ge}});const be=(e,t,s)=>(e.set(t,s),s),we=e=>{Q[0]=e[Ae++],Q[1]=e[Ae++],Q[2]=e[Ae++],Q[3]=e[Ae++],Q[4]=e[Ae++],Q[5]=e[Ae++],Q[6]=e[Ae++],Q[7]=e[Ae++]},me=e=>(Q[0]=e[Ae++],Q[1]=e[Ae++],Q[2]=e[Ae++],Q[3]=e[Ae++],H.getUint32(0,!0)),ve=(e,t)=>{switch(e[Ae++]){case d:return we(e),H.getFloat64(0,!0);case b:return e[Ae++];case O:{const s=be(t,Ae-1,{});for(let n=0,r=me(e);n<r;n++)s[ve(e,t)]=ve(e,t);return s}case x:{const s=be(t,Ae-1,[]);for(let n=0,r=me(e);n<r;n++)s.push(ve(e,t));return s}case F:{const s=Ae-1,n=ve(e,t);return be(t,s,new globalThis[n](ve(e,t)))}case E:{const s=Ae-1,n=me(e);return be(t,s,e.slice(Ae,Ae+=n).buffer)}case U:{const s=Ae-1,n=me(e);return be(t,s,W.decode(e.slice(Ae,Ae+=n)))}case L:return be(t,Ae-1,new Date(ve(e,t)));case T:{const s=be(t,Ae-1,new Map);for(let n=0,r=me(e);n<r;n++)s.set(ve(e,t),ve(e,t));return s}case P:{const s=be(t,Ae-1,new Set);for(let n=0,r=me(e);n<r;n++)s.add(ve(e,t));return s}case I:{const s=Ae-1,n=ve(e,t),r=ve(e,t),a=ve(e,t),o=new(globalThis[n]||Error)(r);return be(t,s,J(o,"stack",{value:a}))}case N:{const s=Ae-1,n=ve(e,t),r=ve(e,t),a=ve(e,t),o=ve(e,t),c=ve(e,t);return be(t,s,new z(n,r,a,{colorSpace:o,pixelFormat:c}))}case D:{const s=Ae-1,n=ve(e,t),r=ve(e,t);return be(t,s,new RegExp(n,r))}case p:return!1;case f:return!0;case w:return NaN;case m:return 1/0;case v:return-1/0;case A:return 0;case k:return-0;case g:return null;case S:return we(e),H.getBigInt64(0,!0);case B:return we(e),H.getBigUint64(0,!0);case M:return(e=>{switch(e[0]){case"@":return Symbol[e.slice(1)];case"#":return Symbol.for(e.slice(1));case"!":return Symbol(e.slice(1));default:return Symbol()}})(ve(e,t));case q:return t.get(me(e));case R:{const s=Ae-1,n=ve(e,t),r=ve(e,t);return be(t,s,new Blob([e.slice(Ae,Ae+=r)],{type:n}))}case j:{const s=Ae-1,n=ve(e,t),r=ve(e,t),a=ve(e,t);return be(t,s,new File([a],n,{type:a.type,lastModified:r}))}default:return}};let Ae=0;const ke=({byteOffset:e=0}={})=>(t,s)=>{return n=new Uint8Array(s,e,t),Ae=0,ve(n,new Map);var n},{isArray:Se}=Array;const{promise:Be,resolve:Ue}=t();addEventListener("message",({data:[e,t,s]})=>Ue([t,s]),{once:!0});const Me="async";var xe="importScripts"in globalThis?e=>Be.then(([a,c])=>(postMessage(1),((e,n)=>{const a=new BroadcastChannel(e),c=s(),i=(n.decoder??ke)({byteOffset:r}),u=n.onsync??o,l=new Map;return a.addEventListener("message",({data:[e,{length:t,buffer:s}]})=>{l.get(e)(u(t?i(t,s):void 0)),l.delete(e)}),(e,...s)=>{const{promise:n,resolve:r}=t(),o=c();return l.set(o,r),a.postMessage([o,e],...s),n}})(c,(e=>{const t=e.onsend??o;return addEventListener("message",async e=>{const{data:s}=e;if(Se(s)&&s[0]===n){e.stopImmediatePropagation(),e.preventDefault();const[r,a]=s[1];postMessage([n,[r,await t(a)]])}}),e})({...a,...e})))):de;export{Me as channel,xe as default};
1
+ //@ts-check
2
+
3
+ /**
4
+ * @template T
5
+ * @typedef {{promise: Promise<T>, resolve: (value: T) => void, reject: (reason?: any) => void}} Resolvers
6
+ */
7
+
8
+ // fallback for Android WebView
9
+ //@ts-ignore
10
+ const withResolvers = Promise.withResolvers || function withResolvers() {
11
+ var a, b, c = new this((resolve, reject) => {
12
+ a = resolve;
13
+ b = reject;
14
+ });
15
+ return {resolve: a, reject: b, promise: c};
16
+ };
17
+
18
+ /**
19
+ * @template T
20
+ * @type {() => Resolvers<T>}
21
+ */
22
+ var withResolvers$1 = withResolvers.bind(Promise);
23
+
24
+ // @ts-check
25
+
26
+ /**
27
+ * @param {number} [start]
28
+ * @returns {() => number}
29
+ */
30
+ var i32 = start => {
31
+ const i32 = new Int32Array(1);
32
+ return () => i32[0]++;
33
+ };
34
+
35
+ // shorter: 'fc260aad-4404-43b8-ae9d-2c06554bb294'.split('-').map(s => parseInt(s, 16)).reduce((p, c) => p + c).toString(16)
36
+ var SHARED_CHANNEL = 'fc260aad-4404-43b8-ae9d-2c06554bb294';
37
+
38
+ const byteOffset = Int32Array.BYTES_PER_ELEMENT * 2;
39
+
40
+ let hasRandomUUID = true;
41
+ try {
42
+ crypto.randomUUID();
43
+ } catch (_) {
44
+ hasRandomUUID = false;
45
+ }
46
+
47
+ const identity = value => value;
48
+
49
+ const randomUUID = hasRandomUUID ?
50
+ (() => crypto.randomUUID() ):
51
+ (() => (Date.now() + Math.random()).toString(36));
52
+
53
+ const { isArray: isArray$2 } = Array;
54
+
55
+ class Sender extends Worker {
56
+ #next;
57
+ #requests;
58
+ constructor(scriptURL, options) {
59
+ const onsend = options.onsend ?? identity;
60
+ super(scriptURL, options);
61
+ this.#next = i32();
62
+ this.#requests = new Map;
63
+ super.addEventListener('message', async event => {
64
+ const { data } = event;
65
+ if (isArray$2(data) && data.length === 2 && data[0] === SHARED_CHANNEL) {
66
+ event.stopImmediatePropagation();
67
+ event.preventDefault();
68
+ const [id, payload] = data[1];
69
+ const resolve = this.#requests.get(id);
70
+ this.#requests.delete(id);
71
+ resolve(await onsend(payload));
72
+ }
73
+ });
74
+ }
75
+
76
+ send(payload, ...rest) {
77
+ const id = this.#next();
78
+ const { promise, resolve } = withResolvers$1();
79
+ this.#requests.set(id, resolve);
80
+ super.postMessage([SHARED_CHANNEL, [id, payload]], ...rest);
81
+ return promise;
82
+ }
83
+ }
84
+
85
+ //@ts-check
86
+
87
+ let { SharedArrayBuffer: SAB$1 } = globalThis;
88
+
89
+ try {
90
+ //@ts-ignore due valid options not recognized
91
+ new SAB$1(4, { maxByteLength: 8 });
92
+ }
93
+ catch (_) {
94
+ SAB$1 = /** @type {SharedArrayBufferConstructor} */(
95
+ /** @type {unknown} */(
96
+ class SharedArrayBuffer extends ArrayBuffer {
97
+ get growable() {
98
+ //@ts-ignore due valid property not recognized
99
+ return super.resizable;
100
+ }
101
+ /** @param {number} newLength */
102
+ grow(newLength) {
103
+ //@ts-ignore due valid method not recognized
104
+ super.resize(newLength);
105
+ }
106
+ }
107
+ )
108
+ );
109
+ }
110
+
111
+ var SAB = ({
112
+ initByteLength = 1024,
113
+ maxByteLength = (1024 * 8)
114
+ }) =>
115
+ new SAB$1(
116
+ byteOffset + initByteLength,
117
+ { maxByteLength: byteOffset + maxByteLength }
118
+ );
119
+
120
+ let i$1 = 0;
121
+
122
+ const FALSE = i$1++;
123
+ const TRUE = i$1++;
124
+
125
+ const UNDEFINED = i$1++;
126
+ const NULL = i$1++;
127
+
128
+ const NUMBER = i$1++;
129
+ const UI8 = i$1++;
130
+ const NAN = i$1++;
131
+ const INFINITY = i$1++;
132
+ const N_INFINITY = i$1++;
133
+ const ZERO = i$1++;
134
+ const N_ZERO = i$1++;
135
+
136
+ const BIGINT = i$1++;
137
+ const BIGUINT = i$1++;
138
+
139
+ const STRING = i$1++;
140
+
141
+ const SYMBOL = i$1++;
142
+
143
+ const ARRAY = i$1++;
144
+ const BUFFER = i$1++;
145
+ const DATE = i$1++;
146
+ const ERROR = i$1++;
147
+ const MAP = i$1++;
148
+ const OBJECT = i$1++;
149
+ const REGEXP = i$1++;
150
+ const SET = i$1++;
151
+ const VIEW = i$1++;
152
+
153
+ const IMAGE_DATA = i$1++;
154
+ const BLOB = i$1++;
155
+ const FILE = i$1++;
156
+
157
+ const RECURSION = i$1++;
158
+
159
+ class Never {}
160
+
161
+ const ImageData = globalThis.ImageData || /** @type {typeof ImageData} */(Never);
162
+
163
+ // This is an Array facade for the encoder.
164
+
165
+ class Stack {
166
+ /**
167
+ * @param {Stack} self
168
+ * @param {Uint8Array} value
169
+ */
170
+ static push(self, value) {
171
+ self.sync(false);
172
+ self._(value, value.length);
173
+ }
174
+
175
+ /**
176
+ * @param {ArrayBufferLike} buffer
177
+ * @param {number} offset
178
+ */
179
+ constructor(buffer, offset) {
180
+ /** @type {number[]} */
181
+ const output = [];
182
+
183
+ /** @private length */
184
+ this.l = 0;
185
+
186
+ /** @private output */
187
+ this.o = output;
188
+
189
+ /** @private view */
190
+ this.v = new Uint8Array(buffer, offset);
191
+
192
+ /** @type {typeof Array.prototype.push} */
193
+ this.push = output.push.bind(output);
194
+ }
195
+
196
+ /**
197
+ * @type {number}
198
+ */
199
+ get length() {
200
+ return this.l + this.o.length;
201
+ }
202
+
203
+ /**
204
+ * Sync all entries in the output to the buffer.
205
+ * @param {boolean} last `true` if it's the last sync.
206
+ */
207
+ sync(last) {
208
+ const output = this.o;
209
+ const length = output.length;
210
+ if (length) this._(last ? output : output.splice(0), length);
211
+ }
212
+
213
+ /**
214
+ * Set a value to the buffer
215
+ * @private
216
+ * @param {Uint8Array|number[]} value
217
+ * @param {number} byteLength
218
+ */
219
+ _(value, byteLength) {
220
+ const { buffer, byteOffset } = this.v;
221
+ const offset = this.l;
222
+ this.l += byteLength;
223
+ byteLength += byteOffset + offset;
224
+ if (buffer.byteLength < byteLength)
225
+ /** @type {SharedArrayBuffer} */(buffer).grow(byteLength);
226
+ this.v.set(value, offset);
227
+ }
228
+ }
229
+
230
+ /** @type {Map<symbol, string>} */
231
+ const symbols = new Map(
232
+ Reflect.ownKeys(Symbol).map(
233
+ key => [Symbol[key], `@${String(key)}`]
234
+ )
235
+ );
236
+
237
+ /**
238
+ * @param {symbol} value
239
+ * @param {string} description
240
+ * @returns {string}
241
+ */
242
+ const asSymbol = (value, description) => (
243
+ description === void 0 ? '?' :
244
+ (Symbol.keyFor(value) === void 0 ? `!${description}` : `#${description}`)
245
+ );
246
+
247
+ /**
248
+ * Extract the value from a pair of type and value.
249
+ * @param {string} name
250
+ * @returns {symbol}
251
+ */
252
+ const fromSymbol = name => {
253
+ switch (name[0]) {
254
+ case '@': return Symbol[name.slice(1)];
255
+ case '#': return Symbol.for(name.slice(1));
256
+ case '!': return Symbol(name.slice(1));
257
+ default: return Symbol();
258
+ }
259
+ };
260
+
261
+ /**
262
+ * Create the name of a symbol.
263
+ * @param {symbol} value
264
+ * @returns {string}
265
+ */
266
+ const toSymbol = value => symbols.get(value) || asSymbol(value, value.description);
267
+
268
+ const defineProperty = Object.defineProperty;
269
+
270
+ const isArray$1 = Array.isArray;
271
+
272
+ const isView = ArrayBuffer.isView;
273
+
274
+ const MAX_ARGS = 0x7FFF;
275
+
276
+ /**
277
+ * @param {number[]} output
278
+ * @param {Uint8Array} value
279
+ */
280
+ const push = (output, value) => {
281
+ for (let $ = output.push, i = 0, length = value.length; i < length; i += MAX_ARGS)
282
+ $.apply(output, value.subarray(i, i + MAX_ARGS));
283
+ };
284
+
285
+ const decoder$1 = new TextDecoder;
286
+
287
+ const encoder$1 = new TextEncoder;
288
+
289
+ const buffer = new ArrayBuffer(8);
290
+ const dv = new DataView(buffer);
291
+ const u8a8 = new Uint8Array(buffer);
292
+
293
+ const { getPrototypeOf } = Object;
294
+ const { construct } = Reflect;
295
+ const { toStringTag } = Symbol;
296
+
297
+ const toTag = (ref, name = ref[toStringTag]) =>
298
+ name in globalThis ? name : toTag(construct(getPrototypeOf(ref.constructor),[0]));
299
+
300
+ //@ts-check
301
+
302
+
303
+ /** @typedef {Map<number, number[]>} Cache */
304
+
305
+ const { isNaN, isFinite, isInteger } = Number;
306
+ const { ownKeys } = Reflect;
307
+ const { is } = Object;
308
+
309
+ /**
310
+ * @param {any} input
311
+ * @param {number[]|Stack} output
312
+ * @param {Cache} cache
313
+ * @returns {boolean}
314
+ */
315
+ const process = (input, output, cache) => {
316
+ const value = cache.get(input);
317
+ const unknown = !value;
318
+ if (unknown) {
319
+ dv.setUint32(0, output.length, true);
320
+ cache.set(input, [u8a8[0], u8a8[1], u8a8[2], u8a8[3]]);
321
+ }
322
+ else
323
+ output.push(RECURSION, value[0], value[1], value[2], value[3]);
324
+ return unknown;
325
+ };
326
+
327
+ /**
328
+ * @param {number[]|Stack} output
329
+ * @param {number} type
330
+ * @param {number} length
331
+ */
332
+ const set = (output, type, length) => {
333
+ dv.setUint32(0, length, true);
334
+ output.push(type, u8a8[0], u8a8[1], u8a8[2], u8a8[3]);
335
+ };
336
+
337
+ /**
338
+ * @param {any} input
339
+ * @param {number[]|Stack} output
340
+ * @param {Cache} cache
341
+ */
342
+ const inflate = (input, output, cache) => {
343
+ switch (typeof input) {
344
+ case 'number': {
345
+ if (input && isFinite(input)) {
346
+ if (isInteger(input) && input < 256 && -1 < input)
347
+ output.push(UI8, input);
348
+ else {
349
+ dv.setFloat64(0, input, true);
350
+ output.push(NUMBER, u8a8[0], u8a8[1], u8a8[2], u8a8[3], u8a8[4], u8a8[5], u8a8[6], u8a8[7]);
351
+ }
352
+ }
353
+ else if (isNaN(input)) output.push(NAN);
354
+ else if (!input) output.push(is(input, 0) ? ZERO : N_ZERO);
355
+ else output.push(input < 0 ? N_INFINITY : INFINITY);
356
+ break;
357
+ }
358
+ case 'object': {
359
+ switch (true) {
360
+ case input === null:
361
+ output.push(NULL);
362
+ break;
363
+ case !process(input, output, cache): break;
364
+ case isArray$1(input): {
365
+ const length = input.length;
366
+ set(output, ARRAY, length);
367
+ for (let i = 0; i < length; i++)
368
+ inflate(input[i], output, cache);
369
+ break;
370
+ }
371
+ case isView(input): {
372
+ output.push(VIEW);
373
+ inflate(toTag(input), output, cache);
374
+ input = input.buffer;
375
+ if (!process(input, output, cache)) break;
376
+ // fallthrough
377
+ }
378
+ case input instanceof ArrayBuffer: {
379
+ const ui8a = new Uint8Array(input);
380
+ set(output, BUFFER, ui8a.length);
381
+ //@ts-ignore
382
+ pushView(output, ui8a);
383
+ break;
384
+ }
385
+ case input instanceof Date:
386
+ output.push(DATE);
387
+ inflate(input.getTime(), output, cache);
388
+ break;
389
+ case input instanceof Map: {
390
+ set(output, MAP, input.size);
391
+ for (const [key, value] of input) {
392
+ inflate(key, output, cache);
393
+ inflate(value, output, cache);
394
+ }
395
+ break;
396
+ }
397
+ case input instanceof Set: {
398
+ set(output, SET, input.size);
399
+ for (const value of input)
400
+ inflate(value, output, cache);
401
+ break;
402
+ }
403
+ case input instanceof Error:
404
+ output.push(ERROR);
405
+ inflate(input.name, output, cache);
406
+ inflate(input.message, output, cache);
407
+ inflate(input.stack, output, cache);
408
+ break;
409
+ /* c8 ignore start */
410
+ case input instanceof ImageData:
411
+ output.push(IMAGE_DATA);
412
+ inflate(input.data, output, cache);
413
+ inflate(input.width, output, cache);
414
+ inflate(input.height, output, cache);
415
+ inflate(input.colorSpace, output, cache);
416
+ //@ts-ignore
417
+ inflate(input.pixelFormat, output, cache);
418
+ break;
419
+ /* c8 ignore stop */
420
+ case input instanceof RegExp:
421
+ output.push(REGEXP);
422
+ inflate(input.source, output, cache);
423
+ inflate(input.flags, output, cache);
424
+ break;
425
+ case input instanceof File: {
426
+ output.push(FILE);
427
+ inflate(input.name, output, cache);
428
+ inflate(input.lastModified, output, cache);
429
+ // fallthrough
430
+ }
431
+ case input instanceof Blob: {
432
+ const size = input.size;
433
+ output.push(BLOB);
434
+ inflate(input.type, output, cache);
435
+ inflate(size, output, cache);
436
+ const length = output.length;
437
+ //@ts-ignore
438
+ pushView(output, new Uint8Array(size));
439
+ blobs.push(input.arrayBuffer().then(buffer => [length, buffer]));
440
+ break;
441
+ }
442
+ default: {
443
+ if ('toJSON' in input) {
444
+ const json = input.toJSON();
445
+ inflate(json === input ? null : json, output, cache);
446
+ }
447
+ else {
448
+ const keys = ownKeys(input);
449
+ const length = keys.length;
450
+ set(output, OBJECT, length);
451
+ for (let i = 0; i < length; i++) {
452
+ const key = keys[i];
453
+ inflate(key, output, cache);
454
+ inflate(input[key], output, cache);
455
+ }
456
+ }
457
+ break;
458
+ }
459
+ }
460
+ break;
461
+ }
462
+ case 'string': {
463
+ if (process(input, output, cache)) {
464
+ const encoded = encoder$1.encode(input);
465
+ set(output, STRING, encoded.length);
466
+ //@ts-ignore
467
+ pushView(output, encoded);
468
+ }
469
+ break;
470
+ }
471
+ case 'boolean': {
472
+ output.push(input ? TRUE : FALSE);
473
+ break;
474
+ }
475
+ case 'symbol': {
476
+ output.push(SYMBOL);
477
+ inflate(toSymbol(input), output, cache);
478
+ break;
479
+ }
480
+ case 'bigint': {
481
+ let type = BIGINT;
482
+ if (9223372036854775807n < input) {
483
+ dv.setBigUint64(0, input, true);
484
+ type = BIGUINT;
485
+ }
486
+ else dv.setBigInt64(0, input, true);
487
+ output.push(type, u8a8[0], u8a8[1], u8a8[2], u8a8[3], u8a8[4], u8a8[5], u8a8[6], u8a8[7]);
488
+ break;
489
+ }
490
+ // this covers functions too
491
+ default: {
492
+ output.push(UNDEFINED);
493
+ break;
494
+ }
495
+ }
496
+ };
497
+
498
+ const blobs = [];
499
+
500
+ /** @type {typeof push|typeof Stack.push} */
501
+ let pushView = push;
502
+
503
+ /**
504
+ * @param {{ byteOffset?: number, Array?: typeof Stack }} [options]
505
+ * @returns {(value: any, buffer: ArrayBufferLike) => number | Promise<number>}
506
+ */
507
+ const encoder = ({ byteOffset = 0, Array = Stack } = {}) => (value, buffer) => {
508
+ const output = new Array(buffer, byteOffset);
509
+ pushView = Array.push;
510
+ inflate(value, output, new Map);
511
+ const length = output.length;
512
+ output.sync(true);
513
+ return blobs.length ?
514
+ Promise.all(blobs.splice(0)).then(entries => {
515
+ const ui8a = new Uint8Array(buffer, byteOffset);
516
+ for (const [len, buff] of entries)
517
+ ui8a.set(new Uint8Array(buff), len);
518
+ return length;
519
+ }) :
520
+ length;
521
+ };
522
+
523
+ /**
524
+ * @typedef {Object} ServiceWorkerOptions see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#options
525
+ * @property {string} [url] will use the `serviceWorker` value if that is a `string`, otherwise it refers to where the service worker file is located.
526
+ * @property {'classic' | 'module'} [type]
527
+ * @property {'all' | 'imports' | 'none'} [updateViaCache]
528
+ */
529
+
530
+ /**
531
+ * @typedef {Object} Options
532
+ * @property {(payload: unknown) => Int32Array | Promise<Int32Array>} [onsync] invoked when the worker expect a response as `Int32Array` to populate the SharedArrayBuffer with.
533
+ * @property {(payload: unknown) => unknown | Promise<unknown>} [onsend] invoked when the worker replies to a `worker.send(data)` call.
534
+ * @property {string} [ws] the WebSocket URL to use for worker <-> server communication.
535
+ * @property {number} [initByteLength=1024] defines the initial byte length of the SharedArrayBuffer.
536
+ * @property {number} [maxByteLength=8192] defines the maximum byte length (growth) of the SharedArrayBuffer.
537
+ * @property {string | ServiceWorkerOptions} [serviceWorker] defines the service worker to use as fallback if SharedArrayBuffer is not supported. If not defined, the `async` fallback will be used so that no `sync` operations from the worker will be possible.
538
+ * @property {import('reflected-ffi/encoder').encoder} [encoder] defines the encoder function to use to encode the result into the SharedArrayBuffer.
539
+ */
540
+
541
+ /**
542
+ * Initialize the worker channel communication and resolves with the worker instance.
543
+ * @template T
544
+ * @param {T} Worker
545
+ * @returns
546
+ */
547
+ const bootstrap = Worker => {
548
+ /**
549
+ * @param {string} scriptURL
550
+ * @param {Options} options
551
+ * @returns
552
+ */
553
+ return (scriptURL, options) => {
554
+ const { promise, resolve } = withResolvers$1();
555
+ // @ts-ignore
556
+ new Worker(scriptURL, options, resolve);
557
+ return /** @type {Promise<T>} */(promise);
558
+ };
559
+ };
560
+
561
+ const handler = (sab, options, useAtomics) => {
562
+ const i32a = new Int32Array(sab);
563
+ const encode = (options.encoder ?? encoder)({ byteOffset });
564
+ const onsync = options.onsync ?? identity;
565
+
566
+ const resolve = (length => {
567
+ i32a[1] = length;
568
+ i32a[0] = 1;
569
+ });
570
+
571
+ const process = result => {
572
+ const length = encode(result, sab);
573
+ return typeof length === 'number' ? resolve(length) : length.then(resolve);
574
+ };
575
+
576
+ return async ({ data }) => process(await onsync(data));
577
+ };
578
+
579
+ const isOK = value => {
580
+ switch (typeof value) {
581
+ case 'symbol':
582
+ case 'function':
583
+ return false;
584
+ }
585
+ return true;
586
+ };
587
+
588
+ const post = (sab, options) => {
589
+ const opts = {};
590
+ for (const key in options) {
591
+ const value = options[key];
592
+ if (isOK(key) && isOK(value)) opts[key] = value;
593
+ }
594
+ return [sab, opts];
595
+ };
596
+
597
+ const url = (scriptURL, reflected, options) => {
598
+ const url = new URL(scriptURL, location.href);
599
+ url.searchParams.set('reflected', reflected);
600
+ return [url, { ...options, type: 'module' }];
601
+ };
602
+
603
+ const CHANNEL = 'async';
604
+
605
+ let Worker$1 = class Worker extends Sender {
606
+ constructor(scriptURL, options, resolve) {
607
+ const channel = randomUUID();
608
+ const bc = new BroadcastChannel(channel);
609
+ const sab = SAB(options);
610
+ const i32a = new Int32Array(sab);
611
+ const handle = handler(sab, options);
612
+ bc.addEventListener('message', async ({ data: [id, payload] }) => {
613
+ await handle({ data: payload });
614
+ bc.postMessage([id, new Uint8Array(sab, byteOffset, i32a[1])]);
615
+ });
616
+ super(...url(scriptURL, CHANNEL, options));
617
+ super.addEventListener('message', () => resolve(this), { once: true });
618
+ super.postMessage(post(sab, options).concat(channel));
619
+ }
620
+
621
+ get channel() {
622
+ return CHANNEL;
623
+ }
624
+ };
625
+ var main = bootstrap(Worker$1);
626
+
627
+ //@ts-check
628
+
629
+
630
+ /** @typedef {Map<number, any>} Cache */
631
+
632
+ /**
633
+ * @param {Cache} cache
634
+ * @param {number} index
635
+ * @param {any} value
636
+ * @returns {any}
637
+ */
638
+ const $ = (cache, index, value) => {
639
+ cache.set(index, value);
640
+ return value;
641
+ };
642
+
643
+ /**
644
+ * @param {Uint8Array} input
645
+ */
646
+ const number = input => {
647
+ u8a8[0] = input[i++];
648
+ u8a8[1] = input[i++];
649
+ u8a8[2] = input[i++];
650
+ u8a8[3] = input[i++];
651
+ u8a8[4] = input[i++];
652
+ u8a8[5] = input[i++];
653
+ u8a8[6] = input[i++];
654
+ u8a8[7] = input[i++];
655
+ };
656
+
657
+ /**
658
+ * @param {Uint8Array} input
659
+ * @returns {number}
660
+ */
661
+ const size = input => {
662
+ u8a8[0] = input[i++];
663
+ u8a8[1] = input[i++];
664
+ u8a8[2] = input[i++];
665
+ u8a8[3] = input[i++];
666
+ return dv.getUint32(0, true);
667
+ };
668
+
669
+ /**
670
+ * @param {Uint8Array} input
671
+ * @param {Cache} cache
672
+ * @returns {any}
673
+ */
674
+ const deflate = (input, cache) => {
675
+ switch (input[i++]) {
676
+ case NUMBER: {
677
+ number(input);
678
+ return dv.getFloat64(0, true);
679
+ }
680
+ case UI8: return input[i++];
681
+ case OBJECT: {
682
+ const object = $(cache, i - 1, {});
683
+ for (let j = 0, length = size(input); j < length; j++)
684
+ object[deflate(input, cache)] = deflate(input, cache);
685
+ return object;
686
+ }
687
+ case ARRAY: {
688
+ const array = $(cache, i - 1, []);
689
+ for (let j = 0, length = size(input); j < length; j++)
690
+ array.push(deflate(input, cache));
691
+ return array;
692
+ }
693
+ case VIEW: {
694
+ const index = i - 1;
695
+ const name = deflate(input, cache);
696
+ return $(cache, index, new globalThis[name](deflate(input, cache)));
697
+ }
698
+ case BUFFER: {
699
+ const index = i - 1;
700
+ const length = size(input);
701
+ return $(cache, index, input.slice(i, i += length).buffer);
702
+ }
703
+ case STRING: {
704
+ const index = i - 1;
705
+ const length = size(input);
706
+ // this could be a subarray but it's not supported on the Web and
707
+ // it wouldn't work with arrays instead of typed arrays.
708
+ return $(cache, index, decoder$1.decode(input.slice(i, i += length)));
709
+ }
710
+ case DATE: {
711
+ return $(cache, i - 1, new Date(deflate(input, cache)));
712
+ }
713
+ case MAP: {
714
+ const map = $(cache, i - 1, new Map);
715
+ for (let j = 0, length = size(input); j < length; j++)
716
+ map.set(deflate(input, cache), deflate(input, cache));
717
+ return map;
718
+ }
719
+ case SET: {
720
+ const set = $(cache, i - 1, new Set);
721
+ for (let j = 0, length = size(input); j < length; j++)
722
+ set.add(deflate(input, cache));
723
+ return set;
724
+ }
725
+ case ERROR: {
726
+ const index = i - 1;
727
+ const name = deflate(input, cache);
728
+ const message = deflate(input, cache);
729
+ const stack = deflate(input, cache);
730
+ const Class = globalThis[name] || Error;
731
+ const error = new Class(message);
732
+ return $(cache, index, defineProperty(error, 'stack', { value: stack }));
733
+ }
734
+ /* c8 ignore start */
735
+ case IMAGE_DATA: {
736
+ const index = i - 1;
737
+ const data = deflate(input, cache);
738
+ const width = deflate(input, cache);
739
+ const height = deflate(input, cache);
740
+ const colorSpace = deflate(input, cache);
741
+ const pixelFormat = deflate(input, cache);
742
+ const settings = { colorSpace, pixelFormat };
743
+ return $(cache, index, new ImageData(data, width, height, settings));
744
+ }
745
+ /* c8 ignore stop */
746
+ case REGEXP: {
747
+ const index = i - 1;
748
+ const source = deflate(input, cache);
749
+ const flags = deflate(input, cache);
750
+ return $(cache, index, new RegExp(source, flags));
751
+ }
752
+ case FALSE: return false;
753
+ case TRUE: return true;
754
+ case NAN: return NaN;
755
+ case INFINITY: return Infinity;
756
+ case N_INFINITY: return -Infinity;
757
+ case ZERO: return 0;
758
+ case N_ZERO: return -0;
759
+ case NULL: return null;
760
+ case BIGINT: return (number(input), dv.getBigInt64(0, true));
761
+ case BIGUINT: return (number(input), dv.getBigUint64(0, true));
762
+ case SYMBOL: return fromSymbol(deflate(input, cache));
763
+ case RECURSION: return cache.get(size(input));
764
+ case BLOB: {
765
+ const index = i - 1;
766
+ const type = deflate(input, cache);
767
+ const size = deflate(input, cache);
768
+ return $(cache, index, new Blob([input.slice(i, i += size)], { type }));
769
+ }
770
+ case FILE: {
771
+ const index = i - 1;
772
+ const name = deflate(input, cache);
773
+ const lastModified = deflate(input, cache);
774
+ const blob = deflate(input, cache);
775
+ return $(cache, index, new File([blob], name, { type: blob.type, lastModified }));
776
+ }
777
+ // this covers functions too
778
+ default: return undefined;
779
+ }
780
+ };
781
+
782
+ let i = 0;
783
+
784
+ /**
785
+ * @param {Uint8Array} value
786
+ * @returns {any}
787
+ */
788
+ const decode = value => {
789
+ i = 0;
790
+ return deflate(value, new Map);
791
+ };
792
+
793
+ /**
794
+ * @param {{ byteOffset?: number }} [options]
795
+ * @returns {(length: number, buffer: ArrayBufferLike) => any}
796
+ */
797
+ const decoder = ({ byteOffset = 0 } = {}) => (length, buffer) => decode(
798
+ new Uint8Array(buffer, byteOffset, length)
799
+ );
800
+
801
+ const { isArray } = Array;
802
+
803
+ var sender = options => {
804
+ const onsend = options.onsend ?? identity;
805
+ addEventListener('message', async event => {
806
+ const { data } = event;
807
+ if (isArray(data) && data[0] === SHARED_CHANNEL) {
808
+ event.stopImmediatePropagation();
809
+ event.preventDefault();
810
+ const [id, payload] = data[1];
811
+ postMessage([SHARED_CHANNEL, [id, await onsend(payload)]]);
812
+ }
813
+ });
814
+ return options;
815
+ };
816
+
817
+ const { promise, resolve } = withResolvers$1();
818
+
819
+ addEventListener(
820
+ 'message',
821
+ ({ data: [_, main, channel] }) => resolve([main, channel]),
822
+ { once: true }
823
+ );
824
+
825
+ const channel = 'async';
826
+
827
+ const handle = (channel, options) => {
828
+ const bc = new BroadcastChannel(channel);
829
+ const next = i32();
830
+ const decode = (options.decoder ?? decoder)({ byteOffset });
831
+ const onsync = options.onsync ?? identity;
832
+ const map = new Map;
833
+ bc.addEventListener('message', ({ data: [id, { length, buffer }] }) => {
834
+ map.get(id)(onsync(length ? decode(length, buffer) : void 0));
835
+ map.delete(id);
836
+ });
837
+ return (payload, ...rest) => {
838
+ const { promise, resolve } = withResolvers$1();
839
+ const id = next();
840
+ map.set(id, resolve);
841
+ // @ts-ignore
842
+ bc.postMessage([id, payload], ...rest);
843
+ return promise;
844
+ };
845
+ };
846
+
847
+ var worker = options => promise.then(([main, channel]) => {
848
+ postMessage(1);
849
+ return handle(channel, sender({ ...main, ...options }));
850
+ });
851
+
852
+ var async = (
853
+ 'importScripts' in globalThis ? worker : main
854
+ );
855
+
856
+ export { channel, async as default };