reflected 0.2.4 → 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,193 @@
1
+ import { F as FILE, B as BLOB, R as RECURSION, S as SYMBOL, f as fromSymbol, a as BIGUINT, d as dv, c as BIGINT, N as NULL, e as N_ZERO, Z as ZERO, g as N_INFINITY, I as INFINITY, h as NAN, T as TRUE, j as FALSE, k as REGEXP, l as IMAGE_DATA, m as ImageData, E as ERROR, n as defineProperty, o as SET, M as MAP, D as DATE, p as STRING, q as decoder$1, r as BUFFER, V as VIEW, A as ARRAY, O as OBJECT, U as UI8, s as NUMBER, u as u8a8, t as SHARED_CHANNEL, i as identity } from './shared-Ccm1cPah.js';
2
+
3
+ //@ts-check
4
+
5
+
6
+ /** @typedef {Map<number, any>} Cache */
7
+
8
+ /**
9
+ * @param {Cache} cache
10
+ * @param {number} index
11
+ * @param {any} value
12
+ * @returns {any}
13
+ */
14
+ const $ = (cache, index, value) => {
15
+ cache.set(index, value);
16
+ return value;
17
+ };
18
+
19
+ /**
20
+ * @param {Uint8Array} input
21
+ */
22
+ const number = input => {
23
+ u8a8[0] = input[i++];
24
+ u8a8[1] = input[i++];
25
+ u8a8[2] = input[i++];
26
+ u8a8[3] = input[i++];
27
+ u8a8[4] = input[i++];
28
+ u8a8[5] = input[i++];
29
+ u8a8[6] = input[i++];
30
+ u8a8[7] = input[i++];
31
+ };
32
+
33
+ /**
34
+ * @param {Uint8Array} input
35
+ * @returns {number}
36
+ */
37
+ const size = input => {
38
+ u8a8[0] = input[i++];
39
+ u8a8[1] = input[i++];
40
+ u8a8[2] = input[i++];
41
+ u8a8[3] = input[i++];
42
+ return dv.getUint32(0, true);
43
+ };
44
+
45
+ /**
46
+ * @param {Uint8Array} input
47
+ * @param {Cache} cache
48
+ * @returns {any}
49
+ */
50
+ const deflate = (input, cache) => {
51
+ switch (input[i++]) {
52
+ case NUMBER: {
53
+ number(input);
54
+ return dv.getFloat64(0, true);
55
+ }
56
+ case UI8: return input[i++];
57
+ case OBJECT: {
58
+ const object = $(cache, i - 1, {});
59
+ for (let j = 0, length = size(input); j < length; j++)
60
+ object[deflate(input, cache)] = deflate(input, cache);
61
+ return object;
62
+ }
63
+ case ARRAY: {
64
+ const array = $(cache, i - 1, []);
65
+ for (let j = 0, length = size(input); j < length; j++)
66
+ array.push(deflate(input, cache));
67
+ return array;
68
+ }
69
+ case VIEW: {
70
+ const index = i - 1;
71
+ const name = deflate(input, cache);
72
+ return $(cache, index, new globalThis[name](deflate(input, cache)));
73
+ }
74
+ case BUFFER: {
75
+ const index = i - 1;
76
+ const length = size(input);
77
+ return $(cache, index, input.slice(i, i += length).buffer);
78
+ }
79
+ case STRING: {
80
+ const index = i - 1;
81
+ const length = size(input);
82
+ // this could be a subarray but it's not supported on the Web and
83
+ // it wouldn't work with arrays instead of typed arrays.
84
+ return $(cache, index, decoder$1.decode(input.slice(i, i += length)));
85
+ }
86
+ case DATE: {
87
+ return $(cache, i - 1, new Date(deflate(input, cache)));
88
+ }
89
+ case MAP: {
90
+ const map = $(cache, i - 1, new Map);
91
+ for (let j = 0, length = size(input); j < length; j++)
92
+ map.set(deflate(input, cache), deflate(input, cache));
93
+ return map;
94
+ }
95
+ case SET: {
96
+ const set = $(cache, i - 1, new Set);
97
+ for (let j = 0, length = size(input); j < length; j++)
98
+ set.add(deflate(input, cache));
99
+ return set;
100
+ }
101
+ case ERROR: {
102
+ const index = i - 1;
103
+ const name = deflate(input, cache);
104
+ const message = deflate(input, cache);
105
+ const stack = deflate(input, cache);
106
+ const Class = globalThis[name] || Error;
107
+ const error = new Class(message);
108
+ return $(cache, index, defineProperty(error, 'stack', { value: stack }));
109
+ }
110
+ /* c8 ignore start */
111
+ case IMAGE_DATA: {
112
+ const index = i - 1;
113
+ const data = deflate(input, cache);
114
+ const width = deflate(input, cache);
115
+ const height = deflate(input, cache);
116
+ const colorSpace = deflate(input, cache);
117
+ const pixelFormat = deflate(input, cache);
118
+ const settings = { colorSpace, pixelFormat };
119
+ return $(cache, index, new ImageData(data, width, height, settings));
120
+ }
121
+ /* c8 ignore stop */
122
+ case REGEXP: {
123
+ const index = i - 1;
124
+ const source = deflate(input, cache);
125
+ const flags = deflate(input, cache);
126
+ return $(cache, index, new RegExp(source, flags));
127
+ }
128
+ case FALSE: return false;
129
+ case TRUE: return true;
130
+ case NAN: return NaN;
131
+ case INFINITY: return Infinity;
132
+ case N_INFINITY: return -Infinity;
133
+ case ZERO: return 0;
134
+ case N_ZERO: return -0;
135
+ case NULL: return null;
136
+ case BIGINT: return (number(input), dv.getBigInt64(0, true));
137
+ case BIGUINT: return (number(input), dv.getBigUint64(0, true));
138
+ case SYMBOL: return fromSymbol(deflate(input, cache));
139
+ case RECURSION: return cache.get(size(input));
140
+ case BLOB: {
141
+ const index = i - 1;
142
+ const type = deflate(input, cache);
143
+ const size = deflate(input, cache);
144
+ return $(cache, index, new Blob([input.slice(i, i += size)], { type }));
145
+ }
146
+ case FILE: {
147
+ const index = i - 1;
148
+ const name = deflate(input, cache);
149
+ const lastModified = deflate(input, cache);
150
+ const blob = deflate(input, cache);
151
+ return $(cache, index, new File([blob], name, { type: blob.type, lastModified }));
152
+ }
153
+ // this covers functions too
154
+ default: return undefined;
155
+ }
156
+ };
157
+
158
+ let i = 0;
159
+
160
+ /**
161
+ * @param {Uint8Array} value
162
+ * @returns {any}
163
+ */
164
+ const decode = value => {
165
+ i = 0;
166
+ return deflate(value, new Map);
167
+ };
168
+
169
+ /**
170
+ * @param {{ byteOffset?: number }} [options]
171
+ * @returns {(length: number, buffer: ArrayBufferLike) => any}
172
+ */
173
+ const decoder = ({ byteOffset = 0 } = {}) => (length, buffer) => decode(
174
+ new Uint8Array(buffer, byteOffset, length)
175
+ );
176
+
177
+ const { isArray } = Array;
178
+
179
+ var sender = options => {
180
+ const onsend = options.onsend ?? identity;
181
+ addEventListener('message', async event => {
182
+ const { data } = event;
183
+ if (isArray(data) && data[0] === SHARED_CHANNEL) {
184
+ event.stopImmediatePropagation();
185
+ event.preventDefault();
186
+ const [id, payload] = data[1];
187
+ postMessage([SHARED_CHANNEL, [id, await onsend(payload)]]);
188
+ }
189
+ });
190
+ return options;
191
+ };
192
+
193
+ export { decoder as d, sender as s };
@@ -0,0 +1,125 @@
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
+ const byteOffset = Int32Array.BYTES_PER_ELEMENT * 2;
111
+
112
+ let hasRandomUUID = true;
113
+ try {
114
+ crypto.randomUUID();
115
+ } catch (_) {
116
+ hasRandomUUID = false;
117
+ }
118
+
119
+ const identity = value => value;
120
+
121
+ const randomUUID = hasRandomUUID ?
122
+ (() => crypto.randomUUID() ):
123
+ (() => (Date.now() + Math.random()).toString(36));
124
+
125
+ export { ARRAY as A, BLOB as B, isArray as C, DATE as D, ERROR as E, FILE as F, push as G, 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, byteOffset as b, BIGINT as c, dv as d, N_ZERO as e, fromSymbol as f, N_INFINITY as g, NAN as h, identity as i, FALSE as j, REGEXP as k, IMAGE_DATA as l, ImageData as m, defineProperty as n, SET as o, STRING as p, decoder as q, BUFFER as r, NUMBER as s, SHARED_CHANNEL as t, u8a8 as u, randomUUID as v, UNDEFINED as w, toSymbol as x, encoder as y, isView as z };
@@ -0,0 +1,53 @@
1
+ import { s as sender, d as decoder } from './sender-BSx3lj4w.js';
2
+ import { b as byteOffset, i as identity } from './shared-Ccm1cPah.js';
3
+
4
+ const { load, store, wait } = Atomics;
5
+
6
+ /**
7
+ * @typedef {Object} Options
8
+ * @property {(payload: Int32Array) => unknown} [onsync] transforms the resulting `Int32Array` from *main* thread into a value usable within the worker.
9
+ * @property {(payload: unknown) => unknown |Promise<unknown>} onsend invoked to define what to return to the *main* thread when it calls `worker.send(payload)`.
10
+ * @property {import('reflected-ffi/decoder').decoder} [decoder] defines the decoder function to use to decode the result from the SharedArrayBuffer.
11
+ */
12
+
13
+ /**
14
+ * @param {MessageChannel | BroadcastChannel} channel
15
+ * @param {Int32Array} i32a
16
+ * @param {Options} options
17
+ * @returns {(payload: unknown, ...rest: unknown[]) => unknown}
18
+ */
19
+ const handle = (channel, i32a, options) => {
20
+ const decode = (options.decoder ?? decoder)({ byteOffset });
21
+ const onsync = options.onsync ?? identity;
22
+ const { buffer } = i32a;
23
+ return (payload, ...rest) => {
24
+ // @ts-ignore
25
+ channel.postMessage(payload, ...rest);
26
+ wait(i32a, 0, 0);
27
+ store(i32a, 0, 0);
28
+ const length = load(i32a, 1);
29
+ return onsync(length ? decode(length, buffer) : void 0);
30
+ };
31
+ };
32
+
33
+ /**
34
+ *
35
+ * @param {Promise<[SharedArrayBuffer, Options, MessageChannel | BroadcastChannel]>} promise
36
+ * @param {(event:MessageEvent) => void} listener
37
+ * @returns
38
+ */
39
+ const handler = (promise, listener) => {
40
+ addEventListener('message', listener, { once: true });
41
+ /**
42
+ * @param {Options} options
43
+ * @returns
44
+ */
45
+ return options => promise.then(
46
+ ([sab, main, channel]) => {
47
+ postMessage(1);
48
+ return handle(channel, new Int32Array(sab), sender({ ...main, ...options }));
49
+ }
50
+ );
51
+ };
52
+
53
+ export { handler as h };