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
@@ -0,0 +1,24 @@
1
+ import { b as bootstrap, S as Sender, a as SAB, h as handler, u as url, p as post } from './shared-CgOGpfKJ.js';
2
+ import { r as randomUUID } from './shared-DR7YYduq.js';
3
+ import './i32-UV5fM9Tw.js';
4
+ import './channel-NcnPEVL4.js';
5
+
6
+ const CHANNEL = 'broadcast';
7
+
8
+ var broadcast = bootstrap(class Worker extends Sender {
9
+ constructor(scriptURL, options, resolve) {
10
+ const channel = randomUUID();
11
+ const bc = new BroadcastChannel(channel);
12
+ const sab = SAB(options);
13
+ bc.addEventListener('message', handler(sab, options, true));
14
+ super(...url(scriptURL, CHANNEL, options));
15
+ super.addEventListener('message', () => resolve(this), { once: true });
16
+ super.postMessage(post(sab, options).concat(channel));
17
+ }
18
+
19
+ get channel() {
20
+ return CHANNEL;
21
+ }
22
+ });
23
+
24
+ export { broadcast as default };
@@ -0,0 +1,15 @@
1
+ import { w as withResolvers } from './shared-DR7YYduq.js';
2
+ import { h as handler } from './shared-Cn1K0k8G.js';
3
+ import './sender-D5Lm-DmC.js';
4
+ import './channel-NcnPEVL4.js';
5
+
6
+ const { promise, resolve } = withResolvers();
7
+
8
+ const channel = 'broadcast';
9
+
10
+ var broadcast = handler(
11
+ promise,
12
+ ({ data: [sab, main, channel] }) => resolve([sab, main, new BroadcastChannel(channel)]),
13
+ );
14
+
15
+ export { channel, broadcast as default };
@@ -0,0 +1,110 @@
1
+ let i = 0;
2
+
3
+ const FALSE = i++;
4
+ const TRUE = i++;
5
+
6
+ const UNDEFINED = i++;
7
+ const NULL = i++;
8
+
9
+ const NUMBER = i++;
10
+ const UI8 = i++;
11
+ const NAN = i++;
12
+ const INFINITY = i++;
13
+ const N_INFINITY = i++;
14
+ const ZERO = i++;
15
+ const N_ZERO = i++;
16
+
17
+ const BIGINT = i++;
18
+ const BIGUINT = i++;
19
+
20
+ const STRING = i++;
21
+
22
+ const SYMBOL = i++;
23
+
24
+ const ARRAY = i++;
25
+ const BUFFER = i++;
26
+ const DATE = i++;
27
+ const ERROR = i++;
28
+ const MAP = i++;
29
+ const OBJECT = i++;
30
+ const REGEXP = i++;
31
+ const SET = i++;
32
+ const VIEW = i++;
33
+
34
+ const IMAGE_DATA = i++;
35
+ const BLOB = i++;
36
+ const FILE = i++;
37
+
38
+ const RECURSION = i++;
39
+
40
+ class Never {}
41
+
42
+ const ImageData = globalThis.ImageData || /** @type {typeof ImageData} */(Never);
43
+
44
+ const decoder = new TextDecoder;
45
+
46
+ const encoder = new TextEncoder;
47
+
48
+ /** @type {Map<symbol, string>} */
49
+ const symbols = new Map(
50
+ Reflect.ownKeys(Symbol).map(
51
+ key => [Symbol[key], `@${String(key)}`]
52
+ )
53
+ );
54
+
55
+ /**
56
+ * @param {symbol} value
57
+ * @param {string} description
58
+ * @returns {string}
59
+ */
60
+ const asSymbol = (value, description) => (
61
+ description === void 0 ? '?' :
62
+ (Symbol.keyFor(value) === void 0 ? `!${description}` : `#${description}`)
63
+ );
64
+
65
+ /**
66
+ * Extract the value from a pair of type and value.
67
+ * @param {string} name
68
+ * @returns {symbol}
69
+ */
70
+ const fromSymbol = name => {
71
+ switch (name[0]) {
72
+ case '@': return Symbol[name.slice(1)];
73
+ case '#': return Symbol.for(name.slice(1));
74
+ case '!': return Symbol(name.slice(1));
75
+ default: return Symbol();
76
+ }
77
+ };
78
+
79
+ /**
80
+ * Create the name of a symbol.
81
+ * @param {symbol} value
82
+ * @returns {string}
83
+ */
84
+ const toSymbol = value => symbols.get(value) || asSymbol(value, value.description);
85
+
86
+ const defineProperty = Object.defineProperty;
87
+
88
+ const isArray = Array.isArray;
89
+
90
+ const isView = ArrayBuffer.isView;
91
+
92
+ const MAX_ARGS = 0x7FFF;
93
+
94
+ /**
95
+ * @param {number[]} output
96
+ * @param {Uint8Array} value
97
+ */
98
+ const push = (output, value) => {
99
+ for (let $ = output.push, i = 0, length = value.length; i < length; i += MAX_ARGS)
100
+ $.apply(output, value.subarray(i, i + MAX_ARGS));
101
+ };
102
+
103
+ const buffer = new ArrayBuffer(8);
104
+ const dv = new DataView(buffer);
105
+ const u8a8 = new Uint8Array(buffer);
106
+
107
+ // shorter: 'fc260aad-4404-43b8-ae9d-2c06554bb294'.split('-').map(s => parseInt(s, 16)).reduce((p, c) => p + c).toString(16)
108
+ var SHARED_CHANNEL = 'fc260aad-4404-43b8-ae9d-2c06554bb294';
109
+
110
+ export { ARRAY as A, BLOB as B, DATE as D, ERROR as E, FILE as F, INFINITY as I, MAP as M, NULL as N, OBJECT as O, RECURSION as R, SYMBOL as S, TRUE as T, UI8 as U, VIEW as V, ZERO as Z, BIGUINT as a, BIGINT as b, N_ZERO as c, dv as d, N_INFINITY as e, fromSymbol as f, NAN as g, FALSE as h, REGEXP as i, IMAGE_DATA as j, ImageData as k, defineProperty as l, SET as m, STRING as n, decoder as o, BUFFER as p, NUMBER as q, SHARED_CHANNEL as r, UNDEFINED as s, toSymbol as t, u8a8 as u, encoder as v, isView as w, isArray as x, push as y };
@@ -0,0 +1,12 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @param {number} [start]
5
+ * @returns {() => number}
6
+ */
7
+ var i32 = start => {
8
+ const i32 = new Int32Array(1);
9
+ return () => i32[0]++;
10
+ };
11
+
12
+ export { i32 as i };
@@ -0,0 +1,15 @@
1
+ import { w as withResolvers } from './shared-DR7YYduq.js';
2
+ import { h as handler } from './shared-Cn1K0k8G.js';
3
+ import './sender-D5Lm-DmC.js';
4
+ import './channel-NcnPEVL4.js';
5
+
6
+ const { promise, resolve } = withResolvers();
7
+
8
+ const channel = 'message';
9
+
10
+ var message = handler(
11
+ promise,
12
+ ({ data: [sab, main], ports: [channel] }) => resolve([sab, main, channel])
13
+ );
14
+
15
+ export { channel, message as default };
@@ -0,0 +1,24 @@
1
+ import { b as bootstrap, S as Sender, a as SAB, h as handler, u as url, p as post } from './shared-CgOGpfKJ.js';
2
+ import './shared-DR7YYduq.js';
3
+ import './i32-UV5fM9Tw.js';
4
+ import './channel-NcnPEVL4.js';
5
+
6
+ const CHANNEL = 'message';
7
+
8
+ var message = bootstrap(class Worker extends Sender {
9
+ constructor(scriptURL, options, resolve) {
10
+ const { port1, port2 } = new MessageChannel;
11
+ const sab = SAB(options);
12
+ port1.addEventListener(CHANNEL, handler(sab, options, true));
13
+ port1.start();
14
+ super(...url(scriptURL, CHANNEL, options));
15
+ super.addEventListener(CHANNEL, () => resolve(this), { once: true });
16
+ super.postMessage(post(sab, options), [port2]);
17
+ }
18
+
19
+ get channel() {
20
+ return CHANNEL;
21
+ }
22
+ });
23
+
24
+ export { message as default };
@@ -1 +1,79 @@
1
- import{w as a,c as t}from"./shared-DDIlHBz4.js";import{n as e}from"./shared-array-buffer-cwdMr2mc.js";let s,r;if("importScripts"in globalThis){let t;const{promise:e,resolve:n}=a(),o=new URL(location).searchParams.get("reflected");s=o,t="message"===o?import("./message-BvU2dKHz.js"):"broadcast"===o?import("./broadcast-Bdt9gmj_.js"):"xhr"===o?import("./xhr-JKtROQ3y.js"):import("./async-fqI-s7gn.js"),r=async a=>{const{data:s,ports:r}=await e,{default:n}=await t,o=new Event("message");return o.data=s,o.ports=r,dispatchEvent(o),n(a)},addEventListener("message",n,{once:!0})}else e?"InstallTrigger"in globalThis?(s="broadcast",r=(await import("./broadcast-D7rjohJL.js")).default):(s="message",r=(await import("./message-DhtuceT9.js")).default):navigator.serviceWorker?(s="xhr",r=(await import("./xhr-CK-Z6L0B.js")).default):(s="async",r=(await import("./async-Do59YjcF.js").then(function(a){return a.a})).default);var n=r,o=async a=>{const e=t(null),s=await n({...a,onsend:([a,t])=>e[a](...t)});return new Proxy(e,{get(a,t){if("then"!==t)return a[t]??(a[t]=(...a)=>s([t,a]))},set(a,t,e){const s="then"!==t;return s&&(a[t]=e),s}})};export{s as channel,o as default};
1
+ import { w as withResolvers, c as create } from './shared-DR7YYduq.js';
2
+ import { n as native } from './shared-array-buffer-BQgQXQvC.js';
3
+
4
+ /** @typedef {import('./main/shared.js').Options} MainOptions */
5
+ /** @typedef {import('./worker/shared.js').Options} WorkerOptions */
6
+
7
+ /** @type {string} */
8
+ let channel;
9
+
10
+ /** @type {Function} */
11
+ let module$1;
12
+
13
+ if ('importScripts' in globalThis) {
14
+ let get;
15
+ const { promise, resolve } = withResolvers();
16
+ // @ts-ignore
17
+ const reflected = new URL(location).searchParams.get('reflected');
18
+ channel = reflected;
19
+ if (reflected === 'message') get = import(/* webpackIgnore: true */'./message-Bots8UXM.js');
20
+ else if (reflected === 'broadcast') get = import(/* webpackIgnore: true */'./broadcast-fWsZlH8v.js');
21
+ else if (reflected === 'xhr') get = import(/* webpackIgnore: true */'./xhr-DAgmljtu.js');
22
+ else get = import(/* webpackIgnore: true */'./async-CZJaURwO.js');
23
+ module$1 = async options => {
24
+ const { data, ports } = await promise;
25
+ const { default: reflect } = await get;
26
+ const event = new Event('message');
27
+ // @ts-ignore
28
+ event.data = data;
29
+ // @ts-ignore
30
+ event.ports = ports;
31
+ dispatchEvent(event);
32
+ return reflect(options);
33
+ };
34
+ addEventListener('message', resolve, { once: true });
35
+ }
36
+ else if (native) {
37
+ if ('InstallTrigger' in globalThis) {
38
+ channel = 'broadcast';
39
+ module$1 = (await import(/* webpackIgnore: true */'./broadcast-DRVfswix.js')).default;
40
+ }
41
+ else {
42
+ channel = 'message';
43
+ module$1 = (await import(/* webpackIgnore: true */'./message-sej0J6k5.js')).default;
44
+ }
45
+ }
46
+ else if (navigator.serviceWorker) {
47
+ channel = 'xhr';
48
+ module$1 = (await import(/* webpackIgnore: true */'./xhr-CQDzS28h.js')).default;
49
+ }
50
+ else {
51
+ channel = 'async';
52
+ module$1 = (await import(/* webpackIgnore: true */'./async-DaSAye0a.js').then(function (n) { return n.a; })).default;
53
+ }
54
+
55
+ var reflected = module$1;
56
+
57
+ var proxy = async options => {
58
+ const target = create(null);
59
+ const send = await reflected({
60
+ ...options,
61
+ onsend: ([name, args]) => target[name](...args),
62
+ });
63
+ return new Proxy(target, {
64
+ get(target, name) {
65
+ // the curse of potentially awaiting proxies in the wild
66
+ // requires this ugly guard around `then`
67
+ if (name === 'then') return;
68
+ return target[name] ?? (target[name] = (...args) => send([name, args]));
69
+ },
70
+ // @ts-ignore
71
+ set(target, name, value) {
72
+ const ok = name !== 'then';
73
+ if (ok) target[name] = value;
74
+ return ok;
75
+ },
76
+ });
77
+ };
78
+
79
+ export { channel, proxy as default };
@@ -0,0 +1,194 @@
1
+ import { F as FILE, B as BLOB, R as RECURSION, S as SYMBOL, f as fromSymbol, a as BIGUINT, d as dv, b as BIGINT, N as NULL, c as N_ZERO, Z as ZERO, e as N_INFINITY, I as INFINITY, g as NAN, T as TRUE, h as FALSE, i as REGEXP, j as IMAGE_DATA, k as ImageData, E as ERROR, l as defineProperty, m as SET, M as MAP, D as DATE, n as STRING, o as decoder$1, p as BUFFER, V as VIEW, A as ARRAY, O as OBJECT, U as UI8, q as NUMBER, u as u8a8, r as SHARED_CHANNEL } from './channel-NcnPEVL4.js';
2
+ import { i as identity } from './shared-DR7YYduq.js';
3
+
4
+ //@ts-check
5
+
6
+
7
+ /** @typedef {Map<number, any>} Cache */
8
+
9
+ /**
10
+ * @param {Cache} cache
11
+ * @param {number} index
12
+ * @param {any} value
13
+ * @returns {any}
14
+ */
15
+ const $ = (cache, index, value) => {
16
+ cache.set(index, value);
17
+ return value;
18
+ };
19
+
20
+ /**
21
+ * @param {Uint8Array} input
22
+ */
23
+ const number = input => {
24
+ u8a8[0] = input[i++];
25
+ u8a8[1] = input[i++];
26
+ u8a8[2] = input[i++];
27
+ u8a8[3] = input[i++];
28
+ u8a8[4] = input[i++];
29
+ u8a8[5] = input[i++];
30
+ u8a8[6] = input[i++];
31
+ u8a8[7] = input[i++];
32
+ };
33
+
34
+ /**
35
+ * @param {Uint8Array} input
36
+ * @returns {number}
37
+ */
38
+ const size = input => {
39
+ u8a8[0] = input[i++];
40
+ u8a8[1] = input[i++];
41
+ u8a8[2] = input[i++];
42
+ u8a8[3] = input[i++];
43
+ return dv.getUint32(0, true);
44
+ };
45
+
46
+ /**
47
+ * @param {Uint8Array} input
48
+ * @param {Cache} cache
49
+ * @returns {any}
50
+ */
51
+ const deflate = (input, cache) => {
52
+ switch (input[i++]) {
53
+ case NUMBER: {
54
+ number(input);
55
+ return dv.getFloat64(0, true);
56
+ }
57
+ case UI8: return input[i++];
58
+ case OBJECT: {
59
+ const object = $(cache, i - 1, {});
60
+ for (let j = 0, length = size(input); j < length; j++)
61
+ object[deflate(input, cache)] = deflate(input, cache);
62
+ return object;
63
+ }
64
+ case ARRAY: {
65
+ const array = $(cache, i - 1, []);
66
+ for (let j = 0, length = size(input); j < length; j++)
67
+ array.push(deflate(input, cache));
68
+ return array;
69
+ }
70
+ case VIEW: {
71
+ const index = i - 1;
72
+ const name = deflate(input, cache);
73
+ return $(cache, index, new globalThis[name](deflate(input, cache)));
74
+ }
75
+ case BUFFER: {
76
+ const index = i - 1;
77
+ const length = size(input);
78
+ return $(cache, index, input.slice(i, i += length).buffer);
79
+ }
80
+ case STRING: {
81
+ const index = i - 1;
82
+ const length = size(input);
83
+ // this could be a subarray but it's not supported on the Web and
84
+ // it wouldn't work with arrays instead of typed arrays.
85
+ return $(cache, index, decoder$1.decode(input.slice(i, i += length)));
86
+ }
87
+ case DATE: {
88
+ return $(cache, i - 1, new Date(deflate(input, cache)));
89
+ }
90
+ case MAP: {
91
+ const map = $(cache, i - 1, new Map);
92
+ for (let j = 0, length = size(input); j < length; j++)
93
+ map.set(deflate(input, cache), deflate(input, cache));
94
+ return map;
95
+ }
96
+ case SET: {
97
+ const set = $(cache, i - 1, new Set);
98
+ for (let j = 0, length = size(input); j < length; j++)
99
+ set.add(deflate(input, cache));
100
+ return set;
101
+ }
102
+ case ERROR: {
103
+ const index = i - 1;
104
+ const name = deflate(input, cache);
105
+ const message = deflate(input, cache);
106
+ const stack = deflate(input, cache);
107
+ const Class = globalThis[name] || Error;
108
+ const error = new Class(message);
109
+ return $(cache, index, defineProperty(error, 'stack', { value: stack }));
110
+ }
111
+ /* c8 ignore start */
112
+ case IMAGE_DATA: {
113
+ const index = i - 1;
114
+ const data = deflate(input, cache);
115
+ const width = deflate(input, cache);
116
+ const height = deflate(input, cache);
117
+ const colorSpace = deflate(input, cache);
118
+ const pixelFormat = deflate(input, cache);
119
+ const settings = { colorSpace, pixelFormat };
120
+ return $(cache, index, new ImageData(data, width, height, settings));
121
+ }
122
+ /* c8 ignore stop */
123
+ case REGEXP: {
124
+ const index = i - 1;
125
+ const source = deflate(input, cache);
126
+ const flags = deflate(input, cache);
127
+ return $(cache, index, new RegExp(source, flags));
128
+ }
129
+ case FALSE: return false;
130
+ case TRUE: return true;
131
+ case NAN: return NaN;
132
+ case INFINITY: return Infinity;
133
+ case N_INFINITY: return -Infinity;
134
+ case ZERO: return 0;
135
+ case N_ZERO: return -0;
136
+ case NULL: return null;
137
+ case BIGINT: return (number(input), dv.getBigInt64(0, true));
138
+ case BIGUINT: return (number(input), dv.getBigUint64(0, true));
139
+ case SYMBOL: return fromSymbol(deflate(input, cache));
140
+ case RECURSION: return cache.get(size(input));
141
+ case BLOB: {
142
+ const index = i - 1;
143
+ const type = deflate(input, cache);
144
+ const size = deflate(input, cache);
145
+ return $(cache, index, new Blob([input.slice(i, i += size)], { type }));
146
+ }
147
+ case FILE: {
148
+ const index = i - 1;
149
+ const name = deflate(input, cache);
150
+ const lastModified = deflate(input, cache);
151
+ const blob = deflate(input, cache);
152
+ return $(cache, index, new File([blob], name, { type: blob.type, lastModified }));
153
+ }
154
+ // this covers functions too
155
+ default: return undefined;
156
+ }
157
+ };
158
+
159
+ let i = 0;
160
+
161
+ /**
162
+ * @param {Uint8Array} value
163
+ * @returns {any}
164
+ */
165
+ const decode = value => {
166
+ i = 0;
167
+ return deflate(value, new Map);
168
+ };
169
+
170
+ /**
171
+ * @param {{ byteOffset?: number }} [options]
172
+ * @returns {(length: number, buffer: ArrayBufferLike) => any}
173
+ */
174
+ const decoder = ({ byteOffset = 0 } = {}) => (length, buffer) => decode(
175
+ new Uint8Array(buffer, byteOffset, length)
176
+ );
177
+
178
+ const { isArray } = Array;
179
+
180
+ var sender = options => {
181
+ const onsend = options.onsend ?? identity;
182
+ addEventListener('message', async event => {
183
+ const { data } = event;
184
+ if (isArray(data) && data[0] === SHARED_CHANNEL) {
185
+ event.stopImmediatePropagation();
186
+ event.preventDefault();
187
+ const [id, payload] = data[1];
188
+ postMessage([SHARED_CHANNEL, [id, await onsend(payload)]]);
189
+ }
190
+ });
191
+ return options;
192
+ };
193
+
194
+ export { decoder as d, sender as s };