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.
- package/dist/async-CM1iXZPW.js +44 -0
- package/dist/async-OLiknCrf.js +41 -0
- package/dist/async.js +856 -1
- package/dist/broadcast-B4sl9DBp.js +24 -0
- package/dist/broadcast-eR5_7TCY.js +15 -0
- package/dist/broadcast.js +850 -1
- package/dist/ffi/async-0Q0H4a_N.js +41 -0
- package/dist/ffi/async-CbwemiL2.js +41 -0
- package/dist/ffi/async-D6Zj6i_Q.js +44 -0
- package/dist/ffi/async-DLrN8K6M.js +44 -0
- package/dist/ffi/broadcast-CKNplfox.js +15 -0
- package/dist/ffi/broadcast-CbbtYobq.js +25 -0
- package/dist/ffi/broadcast-DIucqhL0.js +25 -0
- package/dist/ffi/broadcast-uydYnG6E.js +15 -0
- package/dist/ffi/global-DzpOeFX2.js +14 -0
- package/dist/ffi/global-LTfnrHcF.js +11 -0
- package/dist/ffi/i32-Cw-Rqr5y.js +13 -0
- package/dist/ffi/main.js +650 -1
- package/dist/ffi/message-2Dqj3uZ3.js +15 -0
- package/dist/ffi/message-Co0Oew7f.js +25 -0
- package/dist/ffi/message-Cxjrx_su.js +25 -0
- package/dist/ffi/message-mK0eTb54.js +15 -0
- package/dist/ffi/sender-B7Xmjz4q.js +194 -0
- package/dist/ffi/sender-C0gu9RzR.js +194 -0
- package/dist/ffi/shared-5Nhc4gvB.js +175 -0
- package/dist/ffi/shared-B3KmQkGh.js +425 -0
- package/dist/ffi/shared-CjWXp6-D.js +171 -0
- package/dist/ffi/shared-Czh3AlGt.js +53 -0
- package/dist/ffi/shared-DZdgWBc6.js +53 -0
- package/dist/ffi/shared-array-buffer-BQgQXQvC.js +28 -0
- package/dist/ffi/shared-ddawRQD0.js +425 -0
- package/dist/ffi/views-C3SJnvMr.js +48 -0
- package/dist/ffi/views-DBBYng9N.js +52 -0
- package/dist/ffi/worker.js +616 -1
- package/dist/ffi/xhr-Be-3qHQb.js +101 -0
- package/dist/ffi/xhr-CKhf21P8.js +41 -0
- package/dist/ffi/xhr-CRJGE1xP.js +41 -0
- package/dist/ffi/xhr-DSsSGsb-.js +101 -0
- package/dist/i32-UV5fM9Tw.js +12 -0
- package/dist/index.js +57 -1
- package/dist/message-D_SM4ST4.js +24 -0
- package/dist/message-vCWcUEmt.js +15 -0
- package/dist/message.js +843 -1
- package/dist/proxy/main/async-8J3q5T6q.js +41 -0
- package/dist/proxy/main/async-Di4MuQWe.js +44 -0
- package/dist/proxy/main/broadcast-CR8vlkKk.js +24 -0
- package/dist/proxy/main/broadcast-LNW6nFVD.js +15 -0
- package/dist/proxy/main/channel-NcnPEVL4.js +110 -0
- package/dist/proxy/main/i32-UV5fM9Tw.js +12 -0
- package/dist/proxy/main/message-j-4BYSZ4.js +24 -0
- package/dist/proxy/main/message-uirwoNUQ.js +15 -0
- package/dist/proxy/main/proxy.js +106 -1
- package/dist/proxy/main/sender-Dkjjbv2Y.js +194 -0
- package/dist/proxy/main/shared-C3U1MNPd.js +53 -0
- package/dist/proxy/main/shared-CV7CPYuP.js +43 -0
- package/dist/proxy/main/shared-DdPca9Ke.js +431 -0
- package/dist/proxy/main/shared-array-buffer-BQgQXQvC.js +28 -0
- package/dist/proxy/main/xhr-BUjEbkCh.js +100 -0
- package/dist/proxy/main/xhr-WnkM0dVo.js +41 -0
- package/dist/proxy/worker/async-CZJaURwO.js +41 -0
- package/dist/proxy/worker/async-DaSAye0a.js +44 -0
- package/dist/proxy/worker/broadcast-DRVfswix.js +24 -0
- package/dist/proxy/worker/broadcast-fWsZlH8v.js +15 -0
- package/dist/proxy/worker/channel-NcnPEVL4.js +110 -0
- package/dist/proxy/worker/i32-UV5fM9Tw.js +12 -0
- package/dist/proxy/worker/message-Bots8UXM.js +15 -0
- package/dist/proxy/worker/message-sej0J6k5.js +24 -0
- package/dist/proxy/worker/proxy.js +79 -1
- package/dist/proxy/worker/sender-D5Lm-DmC.js +194 -0
- package/dist/proxy/worker/shared-CgOGpfKJ.js +431 -0
- package/dist/proxy/worker/shared-Cn1K0k8G.js +53 -0
- package/dist/proxy/worker/shared-DR7YYduq.js +41 -0
- package/dist/proxy/worker/shared-array-buffer-BQgQXQvC.js +28 -0
- package/dist/proxy/worker/xhr-CQDzS28h.js +100 -0
- package/dist/proxy/worker/xhr-DAgmljtu.js +41 -0
- package/dist/sender-BSx3lj4w.js +193 -0
- package/dist/shared-Ccm1cPah.js +125 -0
- package/dist/shared-DVDPRDN_.js +53 -0
- package/dist/shared-L0wiAfqu.js +431 -0
- package/dist/shared-array-buffer-BQgQXQvC.js +28 -0
- package/dist/sw.js +155 -1
- package/dist/with-resolvers-DsO_nhbc.js +24 -0
- package/dist/xhr-BZOjL92j.js +100 -0
- package/dist/xhr-Crh-419R.js +41 -0
- package/dist/xhr.js +909 -1
- package/package.json +1 -1
- package/reflected.tar.gz +0 -0
- package/dist/async-C2eqvaGm.js +0 -1
- package/dist/async-s2VCmNNG.js +0 -1
- package/dist/broadcast-CArZGSOF.js +0 -1
- package/dist/broadcast-f7NecPmf.js +0 -1
- package/dist/ffi/async-B_TI4xaG.js +0 -1
- package/dist/ffi/async-BeKYhv9s.js +0 -1
- package/dist/ffi/async-Dl9wCRDA.js +0 -1
- package/dist/ffi/async-F0rxZjV9.js +0 -1
- package/dist/ffi/broadcast-CBUwPa0e.js +0 -1
- package/dist/ffi/broadcast-Ce_cOurt.js +0 -1
- package/dist/ffi/broadcast-D0jZEoUb.js +0 -1
- package/dist/ffi/broadcast-D7p6b88J.js +0 -1
- package/dist/ffi/global-B3nXXiRL.js +0 -1
- package/dist/ffi/global-Bs8RLRoX.js +0 -1
- package/dist/ffi/i32-BkNtpHwD.js +0 -1
- package/dist/ffi/message-BdbPt0y5.js +0 -1
- package/dist/ffi/message-DNbm1E-6.js +0 -1
- package/dist/ffi/message-DW2TgKPr.js +0 -1
- package/dist/ffi/message-TyU9xCIl.js +0 -1
- package/dist/ffi/sender-C5EHIpuL.js +0 -1
- package/dist/ffi/sender-DBFDKow4.js +0 -1
- package/dist/ffi/shared-BfrghvHB.js +0 -1
- package/dist/ffi/shared-C2XCOXcu.js +0 -1
- package/dist/ffi/shared-Cs1s8cy4.js +0 -1
- package/dist/ffi/shared-DsgUjYDJ.js +0 -1
- package/dist/ffi/shared-DwSbyGXy.js +0 -1
- package/dist/ffi/shared-DyOzpRO0.js +0 -1
- package/dist/ffi/shared-array-buffer-cwdMr2mc.js +0 -1
- package/dist/ffi/views-CdOIrBQR.js +0 -1
- package/dist/ffi/views-Cr2pQ4B-.js +0 -1
- package/dist/ffi/xhr-BkOoxiJZ.js +0 -1
- package/dist/ffi/xhr-C598zZcp.js +0 -1
- package/dist/ffi/xhr-CasCWs_z.js +0 -1
- package/dist/ffi/xhr-DHyu_Jz0.js +0 -1
- package/dist/i32-C78nBJH2.js +0 -1
- package/dist/message-RcKwy8Ib.js +0 -1
- package/dist/message-l7W12V0c.js +0 -1
- package/dist/proxy/main/async-Bc0QcTaC.js +0 -1
- package/dist/proxy/main/async-CyZdYOvJ.js +0 -1
- package/dist/proxy/main/broadcast-BX9FmxMK.js +0 -1
- package/dist/proxy/main/broadcast-DXhTouQy.js +0 -1
- package/dist/proxy/main/channel-DQBWE7_E.js +0 -1
- package/dist/proxy/main/i32-C78nBJH2.js +0 -1
- package/dist/proxy/main/message-CbPHeJAY.js +0 -1
- package/dist/proxy/main/message-DxRlOVN7.js +0 -1
- package/dist/proxy/main/sender-CNwZwCuI.js +0 -1
- package/dist/proxy/main/shared-BoatDt-V.js +0 -1
- package/dist/proxy/main/shared-FMegJ6yb.js +0 -1
- package/dist/proxy/main/shared-array-buffer-cwdMr2mc.js +0 -1
- package/dist/proxy/main/shared-z_jGYqUa.js +0 -1
- package/dist/proxy/main/xhr-BaBkekSn.js +0 -1
- package/dist/proxy/main/xhr-Fg-l74MV.js +0 -1
- package/dist/proxy/worker/async-Do59YjcF.js +0 -1
- package/dist/proxy/worker/async-fqI-s7gn.js +0 -1
- package/dist/proxy/worker/broadcast-Bdt9gmj_.js +0 -1
- package/dist/proxy/worker/broadcast-D7rjohJL.js +0 -1
- package/dist/proxy/worker/channel-DQBWE7_E.js +0 -1
- package/dist/proxy/worker/i32-C78nBJH2.js +0 -1
- package/dist/proxy/worker/message-BvU2dKHz.js +0 -1
- package/dist/proxy/worker/message-DhtuceT9.js +0 -1
- package/dist/proxy/worker/sender-CWhM7QKB.js +0 -1
- package/dist/proxy/worker/shared-DDIlHBz4.js +0 -1
- package/dist/proxy/worker/shared-NtUlwI0Z.js +0 -1
- package/dist/proxy/worker/shared-QrUiXPgc.js +0 -1
- package/dist/proxy/worker/shared-array-buffer-cwdMr2mc.js +0 -1
- package/dist/proxy/worker/xhr-CK-Z6L0B.js +0 -1
- package/dist/proxy/worker/xhr-JKtROQ3y.js +0 -1
- package/dist/sender-D7tfUn3T.js +0 -1
- package/dist/shared-BCEcO4-0.js +0 -1
- package/dist/shared-BWvJKuCK.js +0 -1
- package/dist/shared-BhhIigP4.js +0 -1
- package/dist/shared-array-buffer-cwdMr2mc.js +0 -1
- package/dist/with-resolvers-CHEvl4oe.js +0 -1
- package/dist/xhr-Bd0lMv0-.js +0 -1
- package/dist/xhr-DaixJn9d.js +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
|
|
3
|
+
let { SharedArrayBuffer: SAB } = globalThis, native = true;
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
//@ts-ignore due valid options not recognized
|
|
7
|
+
new SAB(4, { maxByteLength: 8 });
|
|
8
|
+
}
|
|
9
|
+
catch (_) {
|
|
10
|
+
native = false;
|
|
11
|
+
SAB = /** @type {SharedArrayBufferConstructor} */(
|
|
12
|
+
/** @type {unknown} */(
|
|
13
|
+
class SharedArrayBuffer extends ArrayBuffer {
|
|
14
|
+
get growable() {
|
|
15
|
+
//@ts-ignore due valid property not recognized
|
|
16
|
+
return super.resizable;
|
|
17
|
+
}
|
|
18
|
+
/** @param {number} newLength */
|
|
19
|
+
grow(newLength) {
|
|
20
|
+
//@ts-ignore due valid method not recognized
|
|
21
|
+
super.resize(newLength);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { SAB as S, native as n };
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { u as identity, S as SHARED_CHANNEL, w as withResolvers, g as toSymbol, I as ImageData, j as isView, c as isArray$1, y as push, s as byteOffset } from './shared-5Nhc4gvB.js';
|
|
2
|
+
import { i as i32 } from './i32-Cw-Rqr5y.js';
|
|
3
|
+
import { o as UNDEFINED, d as dv, b as BIGINT, u as u8a8, S as SYMBOL, T as TRUE, g as FALSE, p as encoder$1, k as STRING, B as BLOB, F as FILE, h as REGEXP, i as IMAGE_DATA, E as ERROR, j as SET, M as MAP, D as DATE, m as BUFFER, V as VIEW, N as NULL, U as UI8, n as NUMBER, f as NAN, Z as ZERO, c as N_ZERO, e as N_INFINITY, I as INFINITY, R as RECURSION, a as BIGUINT, O as OBJECT, A as ARRAY } from './views-C3SJnvMr.js';
|
|
4
|
+
import { t as toTag } from './global-LTfnrHcF.js';
|
|
5
|
+
|
|
6
|
+
const { isArray } = Array;
|
|
7
|
+
|
|
8
|
+
class Sender extends Worker {
|
|
9
|
+
#next;
|
|
10
|
+
#requests;
|
|
11
|
+
constructor(scriptURL, options) {
|
|
12
|
+
const onsend = options.onsend ?? identity;
|
|
13
|
+
super(scriptURL, options);
|
|
14
|
+
this.#next = i32();
|
|
15
|
+
this.#requests = new Map;
|
|
16
|
+
super.addEventListener('message', async event => {
|
|
17
|
+
const { data } = event;
|
|
18
|
+
if (isArray(data) && data.length === 2 && data[0] === SHARED_CHANNEL) {
|
|
19
|
+
event.stopImmediatePropagation();
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
const [id, payload] = data[1];
|
|
22
|
+
const resolve = this.#requests.get(id);
|
|
23
|
+
this.#requests.delete(id);
|
|
24
|
+
resolve(await onsend(payload));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
send(payload, ...rest) {
|
|
30
|
+
const id = this.#next();
|
|
31
|
+
const { promise, resolve } = withResolvers();
|
|
32
|
+
this.#requests.set(id, resolve);
|
|
33
|
+
super.postMessage([SHARED_CHANNEL, [id, payload]], ...rest);
|
|
34
|
+
return promise;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// This is an Array facade for the encoder.
|
|
39
|
+
|
|
40
|
+
class Stack {
|
|
41
|
+
/**
|
|
42
|
+
* @param {Stack} self
|
|
43
|
+
* @param {Uint8Array} value
|
|
44
|
+
*/
|
|
45
|
+
static push(self, value) {
|
|
46
|
+
self.sync(false);
|
|
47
|
+
self._(value, value.length);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {ArrayBufferLike} buffer
|
|
52
|
+
* @param {number} offset
|
|
53
|
+
*/
|
|
54
|
+
constructor(buffer, offset) {
|
|
55
|
+
/** @type {number[]} */
|
|
56
|
+
const output = [];
|
|
57
|
+
|
|
58
|
+
/** @private length */
|
|
59
|
+
this.l = 0;
|
|
60
|
+
|
|
61
|
+
/** @private output */
|
|
62
|
+
this.o = output;
|
|
63
|
+
|
|
64
|
+
/** @private view */
|
|
65
|
+
this.v = new Uint8Array(buffer, offset);
|
|
66
|
+
|
|
67
|
+
/** @type {typeof Array.prototype.push} */
|
|
68
|
+
this.push = output.push.bind(output);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @type {number}
|
|
73
|
+
*/
|
|
74
|
+
get length() {
|
|
75
|
+
return this.l + this.o.length;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Sync all entries in the output to the buffer.
|
|
80
|
+
* @param {boolean} last `true` if it's the last sync.
|
|
81
|
+
*/
|
|
82
|
+
sync(last) {
|
|
83
|
+
const output = this.o;
|
|
84
|
+
const length = output.length;
|
|
85
|
+
if (length) this._(last ? output : output.splice(0), length);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set a value to the buffer
|
|
90
|
+
* @private
|
|
91
|
+
* @param {Uint8Array|number[]} value
|
|
92
|
+
* @param {number} byteLength
|
|
93
|
+
*/
|
|
94
|
+
_(value, byteLength) {
|
|
95
|
+
const { buffer, byteOffset } = this.v;
|
|
96
|
+
const offset = this.l;
|
|
97
|
+
this.l += byteLength;
|
|
98
|
+
byteLength += byteOffset + offset;
|
|
99
|
+
if (buffer.byteLength < byteLength)
|
|
100
|
+
/** @type {SharedArrayBuffer} */(buffer).grow(byteLength);
|
|
101
|
+
this.v.set(value, offset);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//@ts-check
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/** @typedef {Map<number, number[]>} Cache */
|
|
109
|
+
|
|
110
|
+
const { isNaN, isFinite, isInteger } = Number;
|
|
111
|
+
const { ownKeys } = Reflect;
|
|
112
|
+
const { is } = Object;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {any} input
|
|
116
|
+
* @param {number[]|Stack} output
|
|
117
|
+
* @param {Cache} cache
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
*/
|
|
120
|
+
const process = (input, output, cache) => {
|
|
121
|
+
const value = cache.get(input);
|
|
122
|
+
const unknown = !value;
|
|
123
|
+
if (unknown) {
|
|
124
|
+
dv.setUint32(0, output.length, true);
|
|
125
|
+
cache.set(input, [u8a8[0], u8a8[1], u8a8[2], u8a8[3]]);
|
|
126
|
+
}
|
|
127
|
+
else
|
|
128
|
+
output.push(RECURSION, value[0], value[1], value[2], value[3]);
|
|
129
|
+
return unknown;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {number[]|Stack} output
|
|
134
|
+
* @param {number} type
|
|
135
|
+
* @param {number} length
|
|
136
|
+
*/
|
|
137
|
+
const set = (output, type, length) => {
|
|
138
|
+
dv.setUint32(0, length, true);
|
|
139
|
+
output.push(type, u8a8[0], u8a8[1], u8a8[2], u8a8[3]);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {any} input
|
|
144
|
+
* @param {number[]|Stack} output
|
|
145
|
+
* @param {Cache} cache
|
|
146
|
+
*/
|
|
147
|
+
const inflate = (input, output, cache) => {
|
|
148
|
+
switch (typeof input) {
|
|
149
|
+
case 'number': {
|
|
150
|
+
if (input && isFinite(input)) {
|
|
151
|
+
if (isInteger(input) && input < 256 && -1 < input)
|
|
152
|
+
output.push(UI8, input);
|
|
153
|
+
else {
|
|
154
|
+
dv.setFloat64(0, input, true);
|
|
155
|
+
output.push(NUMBER, u8a8[0], u8a8[1], u8a8[2], u8a8[3], u8a8[4], u8a8[5], u8a8[6], u8a8[7]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (isNaN(input)) output.push(NAN);
|
|
159
|
+
else if (!input) output.push(is(input, 0) ? ZERO : N_ZERO);
|
|
160
|
+
else output.push(input < 0 ? N_INFINITY : INFINITY);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case 'object': {
|
|
164
|
+
switch (true) {
|
|
165
|
+
case input === null:
|
|
166
|
+
output.push(NULL);
|
|
167
|
+
break;
|
|
168
|
+
case !process(input, output, cache): break;
|
|
169
|
+
case isArray$1(input): {
|
|
170
|
+
const length = input.length;
|
|
171
|
+
set(output, ARRAY, length);
|
|
172
|
+
for (let i = 0; i < length; i++)
|
|
173
|
+
inflate(input[i], output, cache);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case isView(input): {
|
|
177
|
+
output.push(VIEW);
|
|
178
|
+
inflate(toTag(input), output, cache);
|
|
179
|
+
input = input.buffer;
|
|
180
|
+
if (!process(input, output, cache)) break;
|
|
181
|
+
// fallthrough
|
|
182
|
+
}
|
|
183
|
+
case input instanceof ArrayBuffer: {
|
|
184
|
+
const ui8a = new Uint8Array(input);
|
|
185
|
+
set(output, BUFFER, ui8a.length);
|
|
186
|
+
//@ts-ignore
|
|
187
|
+
pushView(output, ui8a);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case input instanceof Date:
|
|
191
|
+
output.push(DATE);
|
|
192
|
+
inflate(input.getTime(), output, cache);
|
|
193
|
+
break;
|
|
194
|
+
case input instanceof Map: {
|
|
195
|
+
set(output, MAP, input.size);
|
|
196
|
+
for (const [key, value] of input) {
|
|
197
|
+
inflate(key, output, cache);
|
|
198
|
+
inflate(value, output, cache);
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case input instanceof Set: {
|
|
203
|
+
set(output, SET, input.size);
|
|
204
|
+
for (const value of input)
|
|
205
|
+
inflate(value, output, cache);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case input instanceof Error:
|
|
209
|
+
output.push(ERROR);
|
|
210
|
+
inflate(input.name, output, cache);
|
|
211
|
+
inflate(input.message, output, cache);
|
|
212
|
+
inflate(input.stack, output, cache);
|
|
213
|
+
break;
|
|
214
|
+
/* c8 ignore start */
|
|
215
|
+
case input instanceof ImageData:
|
|
216
|
+
output.push(IMAGE_DATA);
|
|
217
|
+
inflate(input.data, output, cache);
|
|
218
|
+
inflate(input.width, output, cache);
|
|
219
|
+
inflate(input.height, output, cache);
|
|
220
|
+
inflate(input.colorSpace, output, cache);
|
|
221
|
+
//@ts-ignore
|
|
222
|
+
inflate(input.pixelFormat, output, cache);
|
|
223
|
+
break;
|
|
224
|
+
/* c8 ignore stop */
|
|
225
|
+
case input instanceof RegExp:
|
|
226
|
+
output.push(REGEXP);
|
|
227
|
+
inflate(input.source, output, cache);
|
|
228
|
+
inflate(input.flags, output, cache);
|
|
229
|
+
break;
|
|
230
|
+
case input instanceof File: {
|
|
231
|
+
output.push(FILE);
|
|
232
|
+
inflate(input.name, output, cache);
|
|
233
|
+
inflate(input.lastModified, output, cache);
|
|
234
|
+
// fallthrough
|
|
235
|
+
}
|
|
236
|
+
case input instanceof Blob: {
|
|
237
|
+
const size = input.size;
|
|
238
|
+
output.push(BLOB);
|
|
239
|
+
inflate(input.type, output, cache);
|
|
240
|
+
inflate(size, output, cache);
|
|
241
|
+
const length = output.length;
|
|
242
|
+
//@ts-ignore
|
|
243
|
+
pushView(output, new Uint8Array(size));
|
|
244
|
+
blobs.push(input.arrayBuffer().then(buffer => [length, buffer]));
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
default: {
|
|
248
|
+
if ('toJSON' in input) {
|
|
249
|
+
const json = input.toJSON();
|
|
250
|
+
inflate(json === input ? null : json, output, cache);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
const keys = ownKeys(input);
|
|
254
|
+
const length = keys.length;
|
|
255
|
+
set(output, OBJECT, length);
|
|
256
|
+
for (let i = 0; i < length; i++) {
|
|
257
|
+
const key = keys[i];
|
|
258
|
+
inflate(key, output, cache);
|
|
259
|
+
inflate(input[key], output, cache);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case 'string': {
|
|
268
|
+
if (process(input, output, cache)) {
|
|
269
|
+
const encoded = encoder$1.encode(input);
|
|
270
|
+
set(output, STRING, encoded.length);
|
|
271
|
+
//@ts-ignore
|
|
272
|
+
pushView(output, encoded);
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'boolean': {
|
|
277
|
+
output.push(input ? TRUE : FALSE);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case 'symbol': {
|
|
281
|
+
output.push(SYMBOL);
|
|
282
|
+
inflate(toSymbol(input), output, cache);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case 'bigint': {
|
|
286
|
+
let type = BIGINT;
|
|
287
|
+
if (9223372036854775807n < input) {
|
|
288
|
+
dv.setBigUint64(0, input, true);
|
|
289
|
+
type = BIGUINT;
|
|
290
|
+
}
|
|
291
|
+
else dv.setBigInt64(0, input, true);
|
|
292
|
+
output.push(type, u8a8[0], u8a8[1], u8a8[2], u8a8[3], u8a8[4], u8a8[5], u8a8[6], u8a8[7]);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
// this covers functions too
|
|
296
|
+
default: {
|
|
297
|
+
output.push(UNDEFINED);
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const blobs = [];
|
|
304
|
+
|
|
305
|
+
/** @type {typeof push|typeof Stack.push} */
|
|
306
|
+
let pushView = push;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @param {{ byteOffset?: number, Array?: typeof Stack }} [options]
|
|
310
|
+
* @returns {(value: any, buffer: ArrayBufferLike) => number | Promise<number>}
|
|
311
|
+
*/
|
|
312
|
+
const encoder = ({ byteOffset = 0, Array = Stack } = {}) => (value, buffer) => {
|
|
313
|
+
const output = new Array(buffer, byteOffset);
|
|
314
|
+
pushView = Array.push;
|
|
315
|
+
inflate(value, output, new Map);
|
|
316
|
+
const length = output.length;
|
|
317
|
+
output.sync(true);
|
|
318
|
+
return blobs.length ?
|
|
319
|
+
Promise.all(blobs.splice(0)).then(entries => {
|
|
320
|
+
const ui8a = new Uint8Array(buffer, byteOffset);
|
|
321
|
+
for (const [len, buff] of entries)
|
|
322
|
+
ui8a.set(new Uint8Array(buff), len);
|
|
323
|
+
return length;
|
|
324
|
+
}) :
|
|
325
|
+
length;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const { notify, store } = Atomics;
|
|
329
|
+
|
|
330
|
+
const SAB = ({
|
|
331
|
+
initByteLength = 1024,
|
|
332
|
+
maxByteLength = (1024 * 8)
|
|
333
|
+
}) =>
|
|
334
|
+
new SharedArrayBuffer(
|
|
335
|
+
byteOffset + initByteLength,
|
|
336
|
+
{ maxByteLength: byteOffset + maxByteLength }
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @typedef {Object} ServiceWorkerOptions see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#options
|
|
341
|
+
* @property {string} [url] will use the `serviceWorker` value if that is a `string`, otherwise it refers to where the service worker file is located.
|
|
342
|
+
* @property {'classic' | 'module'} [type]
|
|
343
|
+
* @property {'all' | 'imports' | 'none'} [updateViaCache]
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @typedef {Object} Options
|
|
348
|
+
* @property {(payload: unknown) => Int32Array | Promise<Int32Array>} [onsync] invoked when the worker expect a response as `Int32Array` to populate the SharedArrayBuffer with.
|
|
349
|
+
* @property {(payload: unknown) => unknown | Promise<unknown>} [onsend] invoked when the worker replies to a `worker.send(data)` call.
|
|
350
|
+
* @property {string} [ws] the WebSocket URL to use for worker <-> server communication.
|
|
351
|
+
* @property {number} [initByteLength=1024] defines the initial byte length of the SharedArrayBuffer.
|
|
352
|
+
* @property {number} [maxByteLength=8192] defines the maximum byte length (growth) of the SharedArrayBuffer.
|
|
353
|
+
* @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.
|
|
354
|
+
* @property {import('reflected-ffi/encoder').encoder} [encoder] defines the encoder function to use to encode the result into the SharedArrayBuffer.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Initialize the worker channel communication and resolves with the worker instance.
|
|
359
|
+
* @template T
|
|
360
|
+
* @param {T} Worker
|
|
361
|
+
* @returns
|
|
362
|
+
*/
|
|
363
|
+
const bootstrap = Worker => {
|
|
364
|
+
/**
|
|
365
|
+
* @param {string} scriptURL
|
|
366
|
+
* @param {Options} options
|
|
367
|
+
* @returns
|
|
368
|
+
*/
|
|
369
|
+
return (scriptURL, options) => {
|
|
370
|
+
const { promise, resolve } = withResolvers();
|
|
371
|
+
// @ts-ignore
|
|
372
|
+
new Worker(scriptURL, options, resolve);
|
|
373
|
+
return /** @type {Promise<T>} */(promise);
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const handler = (sab, options, useAtomics) => {
|
|
378
|
+
const i32a = new Int32Array(sab);
|
|
379
|
+
const encode = (options.encoder ?? encoder)({ byteOffset });
|
|
380
|
+
const onsync = options.onsync ?? identity;
|
|
381
|
+
|
|
382
|
+
const resolve = useAtomics ?
|
|
383
|
+
(length => {
|
|
384
|
+
store(i32a, 1, length);
|
|
385
|
+
store(i32a, 0, 1);
|
|
386
|
+
notify(i32a, 0);
|
|
387
|
+
}) :
|
|
388
|
+
(length => {
|
|
389
|
+
i32a[1] = length;
|
|
390
|
+
i32a[0] = 1;
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const process = result => {
|
|
394
|
+
const length = encode(result, sab);
|
|
395
|
+
return typeof length === 'number' ? resolve(length) : length.then(resolve);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
return async ({ data }) => process(await onsync(data));
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const isOK = value => {
|
|
402
|
+
switch (typeof value) {
|
|
403
|
+
case 'symbol':
|
|
404
|
+
case 'function':
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
return true;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const post = (sab, options) => {
|
|
411
|
+
const opts = {};
|
|
412
|
+
for (const key in options) {
|
|
413
|
+
const value = options[key];
|
|
414
|
+
if (isOK(key) && isOK(value)) opts[key] = value;
|
|
415
|
+
}
|
|
416
|
+
return [sab, opts];
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const url = (scriptURL, reflected, options) => {
|
|
420
|
+
const url = new URL(scriptURL, location.href);
|
|
421
|
+
url.searchParams.set('reflected', reflected);
|
|
422
|
+
return [url, { ...options, type: 'module' }];
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
export { Sender as S, SAB as a, bootstrap as b, handler as h, post as p, url as u };
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const decoder = new TextDecoder;
|
|
41
|
+
|
|
42
|
+
const encoder = new TextEncoder;
|
|
43
|
+
|
|
44
|
+
const buffer = new ArrayBuffer(8);
|
|
45
|
+
const dv = new DataView(buffer);
|
|
46
|
+
const u8a8 = new Uint8Array(buffer);
|
|
47
|
+
|
|
48
|
+
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, NAN as f, FALSE as g, REGEXP as h, IMAGE_DATA as i, SET as j, STRING as k, decoder as l, BUFFER as m, NUMBER as n, UNDEFINED as o, encoder as p, u8a8 as u };
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
const buffer = new ArrayBuffer(8);
|
|
49
|
+
const dv = new DataView(buffer);
|
|
50
|
+
const u8a8 = new Uint8Array(buffer);
|
|
51
|
+
|
|
52
|
+
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, NAN as f, FALSE as g, REGEXP as h, IMAGE_DATA as i, ImageData as j, SET as k, STRING as l, decoder as m, BUFFER as n, NUMBER as o, UNDEFINED as p, encoder as q, u8a8 as u };
|