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,25 @@
1
+ import { b as bootstrap, S as Sender, a as SAB, h as handler, u as url, p as post } from './shared-B3KmQkGh.js';
2
+ import './shared-CjWXp6-D.js';
3
+ import './i32-Cw-Rqr5y.js';
4
+ import './views-DBBYng9N.js';
5
+ import './global-DzpOeFX2.js';
6
+
7
+ const CHANNEL = 'message';
8
+
9
+ var message = bootstrap(class Worker extends Sender {
10
+ constructor(scriptURL, options, resolve) {
11
+ const { port1, port2 } = new MessageChannel;
12
+ const sab = SAB(options);
13
+ port1.addEventListener(CHANNEL, handler(sab, options, true));
14
+ port1.start();
15
+ super(...url(scriptURL, CHANNEL, options));
16
+ super.addEventListener(CHANNEL, () => resolve(this), { once: true });
17
+ super.postMessage(post(sab, options), [port2]);
18
+ }
19
+
20
+ get channel() {
21
+ return CHANNEL;
22
+ }
23
+ });
24
+
25
+ export { message as default };
@@ -0,0 +1,15 @@
1
+ import { w as withResolvers } from './shared-CjWXp6-D.js';
2
+ import { h as handler } from './shared-Czh3AlGt.js';
3
+ import './sender-C0gu9RzR.js';
4
+ import './views-DBBYng9N.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,194 @@
1
+ import { F as FILE, B as BLOB, R as RECURSION, S as SYMBOL, 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, f as NAN, T as TRUE, g as FALSE, h as REGEXP, i as IMAGE_DATA, E as ERROR, j as SET, M as MAP, D as DATE, k as STRING, l as decoder$1, m as BUFFER, V as VIEW, A as ARRAY, O as OBJECT, U as UI8, n as NUMBER, u as u8a8 } from './views-C3SJnvMr.js';
2
+ import { e as fromSymbol, I as ImageData, v as defineProperty, S as SHARED_CHANNEL, u as identity } from './shared-5Nhc4gvB.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 };
@@ -0,0 +1,194 @@
1
+ import { F as FILE, B as BLOB, R as RECURSION, S as SYMBOL, 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, f as NAN, T as TRUE, g as FALSE, h as REGEXP, i as IMAGE_DATA, j as ImageData, E as ERROR, k as SET, M as MAP, D as DATE, l as STRING, m as decoder$1, n as BUFFER, V as VIEW, A as ARRAY, O as OBJECT, U as UI8, o as NUMBER, u as u8a8 } from './views-DBBYng9N.js';
2
+ import { f as fromSymbol, u as defineProperty, S as SHARED_CHANNEL, s as identity } from './shared-CjWXp6-D.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 };
@@ -0,0 +1,175 @@
1
+ // shorter: 'fc260aad-4404-43b8-ae9d-2c06554bb294'.split('-').map(s => parseInt(s, 16)).reduce((p, c) => p + c).toString(16)
2
+ var SHARED_CHANNEL = 'fc260aad-4404-43b8-ae9d-2c06554bb294';
3
+
4
+ const DIRECT = 0;
5
+ const REMOTE = 1 << 0;
6
+ const OBJECT = 1 << 1;
7
+ const ARRAY = 1 << 2;
8
+ const FUNCTION = 1 << 3;
9
+ const SYMBOL = 1 << 4;
10
+ const BIGINT = 1 << 5;
11
+ const BUFFER = 1 << 6;
12
+
13
+ const VIEW = BUFFER | ARRAY;
14
+ const REMOTE_OBJECT = REMOTE | OBJECT;
15
+ const REMOTE_ARRAY = REMOTE | ARRAY;
16
+ const REMOTE_FUNCTION = REMOTE | FUNCTION;
17
+
18
+ class Never {}
19
+
20
+ const ImageData = globalThis.ImageData || /** @type {typeof ImageData} */(Never);
21
+
22
+ /** @type {Map<symbol, string>} */
23
+ const symbols = new Map(
24
+ Reflect.ownKeys(Symbol).map(
25
+ key => [Symbol[key], `@${String(key)}`]
26
+ )
27
+ );
28
+
29
+ /**
30
+ * @param {symbol} value
31
+ * @param {string} description
32
+ * @returns {string}
33
+ */
34
+ const asSymbol = (value, description) => (
35
+ description === void 0 ? '?' :
36
+ (Symbol.keyFor(value) === void 0 ? `!${description}` : `#${description}`)
37
+ );
38
+
39
+ /**
40
+ * Extract the value from a pair of type and value.
41
+ * @param {string} name
42
+ * @returns {symbol}
43
+ */
44
+ const fromSymbol = name => {
45
+ switch (name[0]) {
46
+ case '@': return Symbol[name.slice(1)];
47
+ case '#': return Symbol.for(name.slice(1));
48
+ case '!': return Symbol(name.slice(1));
49
+ default: return Symbol();
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Create the name of a symbol.
55
+ * @param {symbol} value
56
+ * @returns {string}
57
+ */
58
+ const toSymbol = value => symbols.get(value) || asSymbol(value, value.description);
59
+
60
+ const defineProperty = Object.defineProperty;
61
+
62
+ const assign$1 = Object.assign;
63
+
64
+ const fromArray = Array.from;
65
+
66
+ const isArray = Array.isArray;
67
+
68
+ const isView = ArrayBuffer.isView;
69
+
70
+ /**
71
+ * A type/value pair.
72
+ * @typedef {[number, any]} TypeValue
73
+ */
74
+
75
+ /**
76
+ * Create a type/value pair.
77
+ * @param {number} type
78
+ * @param {any} value
79
+ * @returns {TypeValue}
80
+ */
81
+ const tv = (type, value) => [type, value];
82
+
83
+ const identity$1 = value => value;
84
+ const object = {};
85
+ /* c8 ignore stop */
86
+
87
+ /**
88
+ * Create a function that loops through an array and applies a function to each value.
89
+ * @param {(value:any, cache?:Map<any, any>) => any} asValue
90
+ * @returns
91
+ */
92
+ const loopValues = asValue => (
93
+ /**
94
+ * Loop through an array and apply a function to each value.
95
+ * @param {any[]} arr
96
+ * @param {Map} [cache]
97
+ * @returns
98
+ */
99
+ (arr, cache = new Map) => {
100
+ for (let i = 0, length = arr.length; i < length; i++)
101
+ arr[i] = asValue(arr[i], cache);
102
+ return arr;
103
+ }
104
+ );
105
+
106
+ /**
107
+ * Extract the value from a pair of type and value.
108
+ * @param {TypeValue} pair
109
+ * @returns {string|symbol}
110
+ */
111
+ const fromKey = ([type, value]) => type === DIRECT ? value : fromSymbol(value);
112
+
113
+ /**
114
+ * Associate a key with an optionally transformed value.
115
+ * @param {string|symbol} value
116
+ * @returns {TypeValue}
117
+ */
118
+ const toKey = value => typeof value === 'string' ?
119
+ tv(DIRECT, value) : tv(SYMBOL, toSymbol(value))
120
+ ;
121
+
122
+ const MAX_ARGS = 0x7FFF;
123
+
124
+ /**
125
+ * @param {number[]} output
126
+ * @param {Uint8Array} value
127
+ */
128
+ const push = (output, value) => {
129
+ for (let $ = output.push, i = 0, length = value.length; i < length; i += MAX_ARGS)
130
+ $.apply(output, value.subarray(i, i + MAX_ARGS));
131
+ };
132
+
133
+ //@ts-check
134
+
135
+ /**
136
+ * @template T
137
+ * @typedef {{promise: Promise<T>, resolve: (value: T) => void, reject: (reason?: any) => void}} Resolvers
138
+ */
139
+
140
+ // fallback for Android WebView
141
+ //@ts-ignore
142
+ const withResolvers = Promise.withResolvers || function withResolvers() {
143
+ var a, b, c = new this((resolve, reject) => {
144
+ a = resolve;
145
+ b = reject;
146
+ });
147
+ return {resolve: a, reject: b, promise: c};
148
+ };
149
+
150
+ /**
151
+ * @template T
152
+ * @type {() => Resolvers<T>}
153
+ */
154
+ var withResolvers$1 = withResolvers.bind(Promise);
155
+
156
+ const assign = Object.assign;
157
+
158
+ const create = Object.create;
159
+
160
+ const byteOffset = Int32Array.BYTES_PER_ELEMENT * 2;
161
+
162
+ let hasRandomUUID = true;
163
+ try {
164
+ crypto.randomUUID();
165
+ } catch (_) {
166
+ hasRandomUUID = false;
167
+ }
168
+
169
+ const identity = value => value;
170
+
171
+ const randomUUID = hasRandomUUID ?
172
+ (() => crypto.randomUUID() ):
173
+ (() => (Date.now() + Math.random()).toString(36));
174
+
175
+ export { ARRAY as A, BIGINT as B, DIRECT as D, FUNCTION as F, ImageData as I, OBJECT as O, REMOTE as R, SHARED_CHANNEL as S, VIEW as V, assign$1 as a, fromKey as b, isArray as c, SYMBOL as d, fromSymbol as e, fromArray as f, toSymbol as g, REMOTE_FUNCTION as h, identity$1 as i, isView as j, BUFFER as k, REMOTE_ARRAY as l, REMOTE_OBJECT as m, loopValues as n, object as o, toKey as p, assign as q, create as r, byteOffset as s, tv as t, identity as u, defineProperty as v, withResolvers$1 as w, randomUUID as x, push as y };