osra 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/build/index.d.ts +75 -54
- package/build/index.js +219 -192
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
[
|
|
1
|
+
const C = "__OSRA_KEY__", de = "__OSRA_DEFAULT_KEY__", M = "__OSRA_BOX__", m = {
|
|
2
|
+
[M]: "revivable",
|
|
3
3
|
type: ""
|
|
4
|
-
},
|
|
4
|
+
}, le = (e, t) => e && typeof e == "object" && M in e && e[M] === "revivable", pe = () => {
|
|
5
5
|
const e = /* @__PURE__ */ new Map(), t = {
|
|
6
6
|
getUniqueUuid: () => {
|
|
7
7
|
let r = globalThis.crypto.randomUUID();
|
|
@@ -33,18 +33,18 @@ const P = "__OSRA_KEY__", ye = "__OSRA_DEFAULT_KEY__", B = "__OSRA_BOX__", u = {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
return t;
|
|
36
|
-
},
|
|
36
|
+
}, K = (e, t) => ue(e) && e[C] === t, ge = ({ listener: e, transport: t, remoteName: r, key: n = C, unregisterSignal: a }) => {
|
|
37
37
|
const s = (o) => {
|
|
38
38
|
if (typeof o == "function")
|
|
39
39
|
o(e);
|
|
40
40
|
else if (O(o) || R(o) || $(o)) {
|
|
41
41
|
const i = (c, y) => {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const l = (p, f) => {
|
|
43
|
+
K(p, n) && (r && p.name !== r || e(p, { port: y, sender: f }));
|
|
44
44
|
};
|
|
45
|
-
c.addListener(
|
|
45
|
+
c.addListener(l), a && a.addEventListener(
|
|
46
46
|
"abort",
|
|
47
|
-
() => c.removeListener(
|
|
47
|
+
() => c.removeListener(l)
|
|
48
48
|
);
|
|
49
49
|
};
|
|
50
50
|
if (R(o)) {
|
|
@@ -58,7 +58,7 @@ const P = "__OSRA_KEY__", ye = "__OSRA_DEFAULT_KEY__", B = "__OSRA_BOX__", u = {
|
|
|
58
58
|
} else $(o) ? i(o) : i(o.onMessage);
|
|
59
59
|
} else {
|
|
60
60
|
const i = (c) => {
|
|
61
|
-
|
|
61
|
+
K(c.data, n) && (r && c.data.name !== r || e(c.data, { receiveTransport: o, source: c.source }));
|
|
62
62
|
};
|
|
63
63
|
o.addEventListener("message", i), a && a.addEventListener(
|
|
64
64
|
"abort",
|
|
@@ -67,15 +67,27 @@ const P = "__OSRA_KEY__", ye = "__OSRA_DEFAULT_KEY__", B = "__OSRA_BOX__", u = {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
J(t) ? s(t.receive) : s(t);
|
|
70
|
-
},
|
|
70
|
+
}, be = (e, t, r = "*", n = []) => {
|
|
71
71
|
const a = (s) => {
|
|
72
|
-
typeof s == "function" ? s(t, n) : O(s) ? s.postMessage(t) : z(s) ? s.postMessage(t, r, n) :
|
|
72
|
+
typeof s == "function" ? s(t, n) : O(s) ? s.postMessage(t) : z(s) ? s.postMessage(t, r, n) : k(s) ? s.send(JSON.stringify(t)) : D(s) ? s.port.postMessage(t, n) : s.postMessage(t, n);
|
|
73
73
|
};
|
|
74
74
|
J(e) ? a(e.emit) : a(e);
|
|
75
75
|
};
|
|
76
76
|
new Int8Array(), new Uint8Array(), new Uint8ClampedArray(), new Int16Array(), new Uint16Array(), new Int32Array(), new Uint32Array(), new Float16Array(), new Float32Array(), new Float64Array(), new BigInt64Array(), new BigUint64Array();
|
|
77
|
-
const
|
|
78
|
-
|
|
77
|
+
const k = (e) => e instanceof WebSocket, Y = (e) => globalThis.ServiceWorkerContainer && e instanceof ServiceWorkerContainer, G = (e) => globalThis.Worker && e instanceof Worker, H = (e) => globalThis.DedicatedWorkerGlobalScope && e instanceof DedicatedWorkerGlobalScope, D = (e) => globalThis.SharedWorker && e instanceof SharedWorker, X = (e) => e instanceof MessagePort, ue = (e) => !!(e && typeof e == "object" && e[C]), me = (e) => !!(globalThis.SharedArrayBuffer && e instanceof globalThis.SharedArrayBuffer), Ae = (e) => globalThis.ArrayBuffer && e instanceof globalThis.ArrayBuffer || globalThis.MessagePort && e instanceof globalThis.MessagePort || globalThis.ReadableStream && e instanceof globalThis.ReadableStream || globalThis.WritableStream && e instanceof globalThis.WritableStream || globalThis.TransformStream && e instanceof globalThis.TransformStream ? !0 : !!(globalThis.ImageBitmap && e instanceof globalThis.ImageBitmap), O = (e, t = !1) => !!(e && typeof e == "object" && !(globalThis.Window && e instanceof globalThis.Window) && "name" in e && "disconnect" in e && "postMessage" in e && (!t || "sender" in e && "onMessage" in e && "onDisconnect" in e)), R = (e) => !!(e && typeof e == "object" && !(globalThis.Window && e instanceof globalThis.Window) && e.addListener && e.hasListener && e.removeListener), $ = (e) => !!(e && typeof e == "object" && !(globalThis.Window && e instanceof globalThis.Window) && e.addListener && e.hasListener && e.removeListener), z = (e) => {
|
|
78
|
+
if (!e || typeof e != "object") return !1;
|
|
79
|
+
try {
|
|
80
|
+
return e.window === e;
|
|
81
|
+
} catch {
|
|
82
|
+
try {
|
|
83
|
+
const t = e;
|
|
84
|
+
return typeof t.closed == "boolean" && typeof t.close == "function";
|
|
85
|
+
} catch {
|
|
86
|
+
return !1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, v = (e) => k(e) || O(e), x = (e) => k(e) || O(e) || R(e) || $(e), S = (e) => "isJson" in e && e.isJson === !0 || v(e) || x(e), B = (e) => z(e) || v(e) || Y(e) || G(e) || H(e) || D(e) || X(e) || Q(e), W = (e) => z(e) || x(e) || Y(e) || G(e) || H(e) || D(e) || X(e) || Z(e), Q = (e) => !!(e && typeof e == "object" && !(globalThis.Window && e instanceof globalThis.Window) && "emit" in e && (B(e.emit) || typeof e.emit == "function")), Z = (e) => !!(e && typeof e == "object" && !(globalThis.Window && e instanceof globalThis.Window) && "receive" in e && (W(e.receive) || typeof e.receive == "function")), J = (e) => Q(e) || Z(e), w = (e) => {
|
|
90
|
+
const t = [], r = (n) => me(n) ? void 0 : Ae(n) ? t.push(n) : Array.isArray(n) ? n.map(r) : n && typeof n == "object" ? Object.values(n).map(r) : void 0;
|
|
79
91
|
return r(e), t;
|
|
80
92
|
}, I = (e, t = !1) => {
|
|
81
93
|
const { port1: r, port2: n } = new MessageChannel(), a = new Promise(
|
|
@@ -84,34 +96,34 @@ const W = (e) => e instanceof WebSocket, K = (e) => globalThis.ServiceWorkerCont
|
|
|
84
96
|
(o) => s(o.data)
|
|
85
97
|
)
|
|
86
98
|
);
|
|
87
|
-
return r.start(), n.postMessage(e, t ?
|
|
88
|
-
},
|
|
99
|
+
return r.start(), n.postMessage(e, t ? w(e) : []), a;
|
|
100
|
+
}, he = async () => {
|
|
89
101
|
const { port1: e } = new MessageChannel();
|
|
90
102
|
return await I(e, !0) instanceof MessagePort;
|
|
91
|
-
},
|
|
103
|
+
}, we = async () => {
|
|
92
104
|
const e = new ArrayBuffer(1);
|
|
93
105
|
return await I(e) instanceof ArrayBuffer;
|
|
94
|
-
},
|
|
106
|
+
}, Ue = async () => {
|
|
95
107
|
const e = new ArrayBuffer(1);
|
|
96
108
|
return await I(e, !0) instanceof ArrayBuffer;
|
|
97
|
-
},
|
|
109
|
+
}, Te = async () => {
|
|
98
110
|
const e = new ReadableStream({
|
|
99
111
|
start(r) {
|
|
100
112
|
r.enqueue(new Uint8Array(1)), r.close();
|
|
101
113
|
}
|
|
102
114
|
});
|
|
103
115
|
return await I(e, !0) instanceof ReadableStream;
|
|
104
|
-
},
|
|
116
|
+
}, Me = async () => {
|
|
105
117
|
const [
|
|
106
118
|
e,
|
|
107
119
|
t,
|
|
108
120
|
r,
|
|
109
121
|
n
|
|
110
122
|
] = await Promise.all([
|
|
111
|
-
ue().catch(() => !1),
|
|
112
|
-
Ae().catch(() => !1),
|
|
113
123
|
he().catch(() => !1),
|
|
114
|
-
|
|
124
|
+
we().catch(() => !1),
|
|
125
|
+
Ue().catch(() => !1),
|
|
126
|
+
Te().catch(() => !1)
|
|
115
127
|
]);
|
|
116
128
|
return {
|
|
117
129
|
jsonOnly: !e && !t && !r && !n,
|
|
@@ -120,38 +132,48 @@ const W = (e) => e instanceof WebSocket, K = (e) => globalThis.ServiceWorkerCont
|
|
|
120
132
|
transferable: r,
|
|
121
133
|
transferableStream: n
|
|
122
134
|
};
|
|
123
|
-
}, N = "arrayBuffer",
|
|
124
|
-
...
|
|
135
|
+
}, N = "arrayBuffer", _e = (e) => e instanceof ArrayBuffer, Be = (e, t) => ({
|
|
136
|
+
...m,
|
|
125
137
|
type: N,
|
|
126
138
|
...S(t.transport) ? { base64Buffer: new Uint8Array(e).toBase64() } : { arrayBuffer: e }
|
|
127
|
-
}),
|
|
139
|
+
}), Pe = (e, t) => "arrayBuffer" in e ? e.arrayBuffer : Uint8Array.fromBase64(e.base64Buffer).buffer, Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
128
140
|
__proto__: null,
|
|
129
141
|
box: Be,
|
|
130
|
-
isType:
|
|
131
|
-
revive:
|
|
142
|
+
isType: _e,
|
|
143
|
+
revive: Pe,
|
|
132
144
|
type: N
|
|
133
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
134
|
-
...
|
|
135
|
-
type:
|
|
145
|
+
}, Symbol.toStringTag, { value: "Module" })), ee = "date", Oe = (e) => e instanceof Date, Se = (e, t) => ({
|
|
146
|
+
...m,
|
|
147
|
+
type: ee,
|
|
136
148
|
ISOString: e.toISOString()
|
|
137
|
-
}),
|
|
149
|
+
}), Ie = (e, t) => new Date(e.ISOString), Ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
138
150
|
__proto__: null,
|
|
139
|
-
box:
|
|
140
|
-
isType:
|
|
141
|
-
revive:
|
|
142
|
-
type:
|
|
143
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
144
|
-
...
|
|
145
|
-
type:
|
|
151
|
+
box: Se,
|
|
152
|
+
isType: Oe,
|
|
153
|
+
revive: Ie,
|
|
154
|
+
type: ee
|
|
155
|
+
}, Symbol.toStringTag, { value: "Module" })), te = "headers", Le = (e) => e instanceof Headers, je = (e, t) => ({
|
|
156
|
+
...m,
|
|
157
|
+
type: te,
|
|
158
|
+
entries: [...e.entries()]
|
|
159
|
+
}), Re = (e, t) => new Headers(e.entries), $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
160
|
+
__proto__: null,
|
|
161
|
+
box: je,
|
|
162
|
+
isType: Le,
|
|
163
|
+
revive: Re,
|
|
164
|
+
type: te
|
|
165
|
+
}, Symbol.toStringTag, { value: "Module" })), re = "error", We = (e) => e instanceof Error, Fe = (e, t) => ({
|
|
166
|
+
...m,
|
|
167
|
+
type: re,
|
|
146
168
|
message: e.message,
|
|
147
169
|
stack: e.stack || e.toString()
|
|
148
|
-
}),
|
|
170
|
+
}), ke = (e, t) => new Error(e.message, { cause: e.stack }), De = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
149
171
|
__proto__: null,
|
|
150
|
-
box:
|
|
151
|
-
isType:
|
|
152
|
-
revive:
|
|
153
|
-
type:
|
|
154
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
172
|
+
box: Fe,
|
|
173
|
+
isType: We,
|
|
174
|
+
revive: ke,
|
|
175
|
+
type: re
|
|
176
|
+
}, Symbol.toStringTag, { value: "Module" })), ne = "typedArray", ze = [
|
|
155
177
|
Int8Array,
|
|
156
178
|
Uint8Array,
|
|
157
179
|
Uint8ClampedArray,
|
|
@@ -166,43 +188,43 @@ const W = (e) => e instanceof WebSocket, K = (e) => globalThis.ServiceWorkerCont
|
|
|
166
188
|
BigUint64Array
|
|
167
189
|
];
|
|
168
190
|
new Int8Array(), new Uint8Array(), new Uint8ClampedArray(), new Int16Array(), new Uint16Array(), new Int32Array(), new Uint32Array(), new Float16Array(), new Float32Array(), new Float64Array(), new BigInt64Array(), new BigUint64Array();
|
|
169
|
-
const
|
|
191
|
+
const se = (e) => {
|
|
170
192
|
const t = e instanceof Int8Array ? "Int8Array" : e instanceof Uint8Array ? "Uint8Array" : e instanceof Uint8ClampedArray ? "Uint8ClampedArray" : e instanceof Int16Array ? "Int16Array" : e instanceof Uint16Array ? "Uint16Array" : e instanceof Int32Array ? "Int32Array" : e instanceof Uint32Array ? "Uint32Array" : e instanceof Float16Array ? "Float16Array" : e instanceof Float32Array ? "Float32Array" : e instanceof Float64Array ? "Float64Array" : e instanceof BigInt64Array ? "BigInt64Array" : e instanceof BigUint64Array ? "BigUint64Array" : void 0;
|
|
171
193
|
if (t === void 0) throw new Error("Unknown typed array type");
|
|
172
194
|
return t;
|
|
173
|
-
},
|
|
195
|
+
}, oe = (e) => {
|
|
174
196
|
const t = e === "Int8Array" ? Int8Array : e === "Uint8Array" ? Uint8Array : e === "Uint8ClampedArray" ? Uint8ClampedArray : e === "Int16Array" ? Int16Array : e === "Uint16Array" ? Uint16Array : e === "Int32Array" ? Int32Array : e === "Uint32Array" ? Uint32Array : e === "Float16Array" ? Float16Array : e === "Float32Array" ? Float32Array : e === "Float64Array" ? Float64Array : e === "BigInt64Array" ? BigInt64Array : e === "BigUint64Array" ? BigUint64Array : void 0;
|
|
175
197
|
if (t === void 0) throw new Error("Unknown typed array type");
|
|
176
198
|
return t;
|
|
177
|
-
},
|
|
178
|
-
...
|
|
179
|
-
type:
|
|
180
|
-
typedArrayType:
|
|
199
|
+
}, Je = (e) => ze.some((t) => e instanceof t), Ve = (e, t) => ({
|
|
200
|
+
...m,
|
|
201
|
+
type: ne,
|
|
202
|
+
typedArrayType: se(e),
|
|
181
203
|
...S(t.transport) ? { base64Buffer: new Uint8Array(e.buffer).toBase64() } : { arrayBuffer: e.buffer }
|
|
182
|
-
}),
|
|
183
|
-
const r =
|
|
204
|
+
}), qe = (e, t) => {
|
|
205
|
+
const r = oe(e.typedArrayType), n = "arrayBuffer" in e ? e.arrayBuffer : Uint8Array.fromBase64(e.base64Buffer).buffer;
|
|
184
206
|
return new r(n);
|
|
185
|
-
},
|
|
207
|
+
}, Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
186
208
|
__proto__: null,
|
|
187
|
-
box:
|
|
188
|
-
isType:
|
|
189
|
-
revive:
|
|
190
|
-
type:
|
|
191
|
-
typedArrayToType:
|
|
192
|
-
typedArrayTypeToTypedArrayConstructor:
|
|
193
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
209
|
+
box: Ve,
|
|
210
|
+
isType: Je,
|
|
211
|
+
revive: qe,
|
|
212
|
+
type: ne,
|
|
213
|
+
typedArrayToType: se,
|
|
214
|
+
typedArrayTypeToTypedArrayConstructor: oe
|
|
215
|
+
}, Symbol.toStringTag, { value: "Module" })), P = new FinalizationRegistry((e) => {
|
|
194
216
|
e.sendMessage({
|
|
195
217
|
type: "message-port-close",
|
|
196
218
|
remoteUuid: e.remoteUuid,
|
|
197
219
|
portId: e.portId
|
|
198
220
|
}), e.cleanup();
|
|
199
|
-
}),
|
|
221
|
+
}), F = "messagePort", Ye = (e) => e instanceof MessagePort, ae = (e) => e !== null && typeof e == "object" && M in e && e[M] === "revivable", E = (e, t) => {
|
|
200
222
|
if (S(t.transport)) {
|
|
201
223
|
let n = function({ data: y }) {
|
|
202
224
|
t.sendMessage({
|
|
203
225
|
type: "message",
|
|
204
226
|
remoteUuid: t.remoteUuid,
|
|
205
|
-
data:
|
|
227
|
+
data: ae(y) ? y : b(y, t),
|
|
206
228
|
portId: s
|
|
207
229
|
});
|
|
208
230
|
};
|
|
@@ -210,19 +232,19 @@ const re = (e) => {
|
|
|
210
232
|
if (y.type === "message-port-close") {
|
|
211
233
|
if (y.portId !== s) return;
|
|
212
234
|
t.messageChannels.free(s);
|
|
213
|
-
const
|
|
214
|
-
|
|
235
|
+
const p = o.deref();
|
|
236
|
+
p && (P.unregister(p), p.close()), t.eventTarget.removeEventListener("message", i);
|
|
215
237
|
return;
|
|
216
238
|
}
|
|
217
239
|
if (y.type !== "message" || y.portId !== s) return;
|
|
218
|
-
const
|
|
219
|
-
if (!
|
|
240
|
+
const l = o.deref();
|
|
241
|
+
if (!l) {
|
|
220
242
|
t.eventTarget.removeEventListener("message", i);
|
|
221
243
|
return;
|
|
222
244
|
}
|
|
223
|
-
|
|
245
|
+
l.postMessage(y.data, w(y.data));
|
|
224
246
|
};
|
|
225
|
-
return
|
|
247
|
+
return P.register(o.deref(), {
|
|
226
248
|
sendMessage: t.sendMessage,
|
|
227
249
|
remoteUuid: t.remoteUuid,
|
|
228
250
|
portId: s,
|
|
@@ -230,14 +252,14 @@ const re = (e) => {
|
|
|
230
252
|
t.messageChannels.free(s), t.eventTarget.removeEventListener("message", i), o.deref()?.removeEventListener("message", n), o.deref()?.close();
|
|
231
253
|
}
|
|
232
254
|
}, o.deref()), o.deref()?.addEventListener("message", n), o.deref()?.start(), t.eventTarget.addEventListener("message", i), {
|
|
233
|
-
...
|
|
234
|
-
type:
|
|
255
|
+
...m,
|
|
256
|
+
type: F,
|
|
235
257
|
portId: s
|
|
236
258
|
};
|
|
237
259
|
}
|
|
238
260
|
return {
|
|
239
|
-
...
|
|
240
|
-
type:
|
|
261
|
+
...m,
|
|
262
|
+
type: F,
|
|
241
263
|
port: e
|
|
242
264
|
};
|
|
243
265
|
}, L = (e, t) => {
|
|
@@ -246,59 +268,59 @@ const re = (e) => {
|
|
|
246
268
|
t.sendMessage({
|
|
247
269
|
type: "message",
|
|
248
270
|
remoteUuid: t.remoteUuid,
|
|
249
|
-
data:
|
|
271
|
+
data: ae(f) ? f : b(f, t),
|
|
250
272
|
portId: n
|
|
251
273
|
});
|
|
252
274
|
};
|
|
253
275
|
const { portId: n } = e, { port1: a, port2: s } = new MessageChannel(), o = t.messageChannels.get(e.portId), { port1: i } = o || t.messageChannels.alloc(e.portId), c = new WeakRef(a), y = ({ detail: f }) => {
|
|
254
276
|
if (f.type !== "message-port-close" || f.portId !== n) return;
|
|
255
277
|
const h = c.deref();
|
|
256
|
-
h &&
|
|
257
|
-
},
|
|
278
|
+
h && P.unregister(h), p();
|
|
279
|
+
}, l = ({ data: f }) => {
|
|
258
280
|
if (f.type !== "message" || f.portId !== n) return;
|
|
259
281
|
const h = c.deref();
|
|
260
282
|
if (!h) {
|
|
261
|
-
|
|
283
|
+
p();
|
|
262
284
|
return;
|
|
263
285
|
}
|
|
264
286
|
if (t.messagePorts.has(h))
|
|
265
287
|
s.postMessage(f.data);
|
|
266
288
|
else {
|
|
267
|
-
const
|
|
268
|
-
s.postMessage(
|
|
289
|
+
const _ = A(f.data, t);
|
|
290
|
+
s.postMessage(_, w(_));
|
|
269
291
|
}
|
|
270
|
-
},
|
|
271
|
-
t.eventTarget.removeEventListener("message", y), i.removeEventListener("message",
|
|
292
|
+
}, p = () => {
|
|
293
|
+
t.eventTarget.removeEventListener("message", y), i.removeEventListener("message", l), s.removeEventListener("message", r), s.close();
|
|
272
294
|
const f = t.messageChannels.get(n);
|
|
273
295
|
f && (f.port1.close(), f.port2 && f.port2.close()), t.messageChannels.free(n);
|
|
274
296
|
};
|
|
275
|
-
return
|
|
297
|
+
return P.register(a, {
|
|
276
298
|
sendMessage: t.sendMessage,
|
|
277
299
|
remoteUuid: t.remoteUuid,
|
|
278
300
|
portId: n,
|
|
279
|
-
cleanup:
|
|
280
|
-
}, a), s.addEventListener("message", r), s.start(), t.eventTarget.addEventListener("message", y), i.addEventListener("message",
|
|
301
|
+
cleanup: p
|
|
302
|
+
}, a), s.addEventListener("message", r), s.start(), t.eventTarget.addEventListener("message", y), i.addEventListener("message", l), i.start(), a;
|
|
281
303
|
}
|
|
282
304
|
return e.port;
|
|
283
|
-
},
|
|
305
|
+
}, Ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
284
306
|
__proto__: null,
|
|
285
307
|
box: E,
|
|
286
|
-
isType:
|
|
308
|
+
isType: Ye,
|
|
287
309
|
revive: L,
|
|
288
|
-
type:
|
|
289
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
310
|
+
type: F
|
|
311
|
+
}, Symbol.toStringTag, { value: "Module" })), ie = "promise", He = (e) => e instanceof Promise, Xe = (e, t) => {
|
|
290
312
|
const r = e, { port1: n, port2: a } = new MessageChannel();
|
|
291
313
|
t.messagePorts.add(a);
|
|
292
314
|
const s = (o) => {
|
|
293
|
-
const i =
|
|
294
|
-
n.postMessage(i,
|
|
315
|
+
const i = b(o, t);
|
|
316
|
+
n.postMessage(i, w(i)), n.close(), t.messagePorts.delete(a);
|
|
295
317
|
};
|
|
296
318
|
return r.then((o) => s({ type: "resolve", data: o })).catch((o) => s({ type: "reject", error: o?.stack ?? String(o) })), {
|
|
297
|
-
...
|
|
298
|
-
type:
|
|
319
|
+
...m,
|
|
320
|
+
type: ie,
|
|
299
321
|
port: E(a, t)
|
|
300
322
|
};
|
|
301
|
-
},
|
|
323
|
+
}, ve = (e, t) => {
|
|
302
324
|
const r = L(e.port, t);
|
|
303
325
|
return t.messagePorts.add(r), new Promise((n, a) => {
|
|
304
326
|
r.addEventListener("message", (s) => {
|
|
@@ -306,13 +328,13 @@ const re = (e) => {
|
|
|
306
328
|
i.type === "resolve" ? n(i.data) : a(i.error), t.messagePorts.delete(r), r.close();
|
|
307
329
|
}, { once: !0 }), r.start();
|
|
308
330
|
});
|
|
309
|
-
},
|
|
331
|
+
}, xe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
310
332
|
__proto__: null,
|
|
311
|
-
box:
|
|
312
|
-
isType:
|
|
313
|
-
revive:
|
|
314
|
-
type:
|
|
315
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
333
|
+
box: Xe,
|
|
334
|
+
isType: He,
|
|
335
|
+
revive: ve,
|
|
336
|
+
type: ie
|
|
337
|
+
}, Symbol.toStringTag, { value: "Module" })), ce = "function", Qe = new FinalizationRegistry((e) => {
|
|
316
338
|
try {
|
|
317
339
|
e.port.postMessage({ __osra_close__: !0 });
|
|
318
340
|
} catch {
|
|
@@ -321,7 +343,7 @@ const re = (e) => {
|
|
|
321
343
|
e.port.close();
|
|
322
344
|
} catch {
|
|
323
345
|
}
|
|
324
|
-
}),
|
|
346
|
+
}), Ze = (e) => typeof e == "function", Ne = (e, t) => {
|
|
325
347
|
const { port1: r, port2: n } = new MessageChannel();
|
|
326
348
|
t.messagePorts.add(n);
|
|
327
349
|
const a = () => {
|
|
@@ -332,49 +354,49 @@ const re = (e) => {
|
|
|
332
354
|
a();
|
|
333
355
|
return;
|
|
334
356
|
}
|
|
335
|
-
const [o, i] = A(s, t), c = (async () => e(...i))(), y =
|
|
336
|
-
o.postMessage(y,
|
|
357
|
+
const [o, i] = A(s, t), c = (async () => e(...i))(), y = b(c, t);
|
|
358
|
+
o.postMessage(y, w(y));
|
|
337
359
|
}), r.start(), {
|
|
338
|
-
...
|
|
339
|
-
type:
|
|
360
|
+
...m,
|
|
361
|
+
type: ce,
|
|
340
362
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
363
|
port: E(n, t)
|
|
342
364
|
};
|
|
343
|
-
},
|
|
365
|
+
}, et = (e, t) => {
|
|
344
366
|
const r = L(e.port, t), n = (...a) => new Promise((s, o) => {
|
|
345
367
|
const { port1: i, port2: c } = new MessageChannel();
|
|
346
368
|
t.messagePorts.add(c);
|
|
347
|
-
const y =
|
|
348
|
-
r.postMessage(y,
|
|
349
|
-
A(
|
|
369
|
+
const y = b([c, a], t);
|
|
370
|
+
r.postMessage(y, w(y)), t.messagePorts.delete(c), i.addEventListener("message", ({ data: l }) => {
|
|
371
|
+
A(l, t).then(s).catch(o).finally(() => {
|
|
350
372
|
i.close();
|
|
351
373
|
});
|
|
352
374
|
}, { once: !0 }), i.start();
|
|
353
375
|
});
|
|
354
|
-
return
|
|
355
|
-
},
|
|
376
|
+
return Qe.register(n, { port: r }, n), n;
|
|
377
|
+
}, tt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
356
378
|
__proto__: null,
|
|
357
|
-
box:
|
|
358
|
-
isType:
|
|
359
|
-
revive:
|
|
360
|
-
type:
|
|
361
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
379
|
+
box: Ne,
|
|
380
|
+
isType: Ze,
|
|
381
|
+
revive: et,
|
|
382
|
+
type: ce
|
|
383
|
+
}, Symbol.toStringTag, { value: "Module" })), ye = "readableStream", rt = (e) => e instanceof ReadableStream, nt = (e, t) => {
|
|
362
384
|
const { port1: r, port2: n } = new MessageChannel();
|
|
363
385
|
t.messagePorts.add(n);
|
|
364
386
|
const a = e.getReader();
|
|
365
387
|
return r.addEventListener("message", async ({ data: s }) => {
|
|
366
388
|
const { type: o } = A(s, t);
|
|
367
389
|
if (o === "pull") {
|
|
368
|
-
const i = a.read(), c =
|
|
369
|
-
r.postMessage(c,
|
|
390
|
+
const i = a.read(), c = b(i, t);
|
|
391
|
+
r.postMessage(c, w(c));
|
|
370
392
|
} else
|
|
371
393
|
a.cancel(), r.close();
|
|
372
394
|
}), r.start(), {
|
|
373
|
-
...
|
|
374
|
-
type:
|
|
395
|
+
...m,
|
|
396
|
+
type: ye,
|
|
375
397
|
port: E(n, t)
|
|
376
398
|
};
|
|
377
|
-
},
|
|
399
|
+
}, st = (e, t) => {
|
|
378
400
|
const r = L(e.port, t);
|
|
379
401
|
return t.messagePorts.add(r), r.start(), new ReadableStream({
|
|
380
402
|
start(n) {
|
|
@@ -385,38 +407,39 @@ const re = (e) => {
|
|
|
385
407
|
A(o, t).then((c) => {
|
|
386
408
|
c.done ? n.close() : n.enqueue(c.value), a();
|
|
387
409
|
}).catch(s);
|
|
388
|
-
}, { once: !0 }), r.postMessage(
|
|
410
|
+
}, { once: !0 }), r.postMessage(b({ type: "pull" }, t));
|
|
389
411
|
});
|
|
390
412
|
},
|
|
391
413
|
cancel() {
|
|
392
|
-
r.postMessage(
|
|
414
|
+
r.postMessage(b({ type: "cancel" }, t)), r.close();
|
|
393
415
|
}
|
|
394
416
|
});
|
|
395
|
-
},
|
|
417
|
+
}, ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
396
418
|
__proto__: null,
|
|
397
|
-
box:
|
|
398
|
-
isType:
|
|
399
|
-
revive:
|
|
400
|
-
type:
|
|
401
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
419
|
+
box: nt,
|
|
420
|
+
isType: rt,
|
|
421
|
+
revive: st,
|
|
422
|
+
type: ye
|
|
423
|
+
}, Symbol.toStringTag, { value: "Module" })), at = [
|
|
424
|
+
Ce,
|
|
425
|
+
Ee,
|
|
426
|
+
$e,
|
|
427
|
+
De,
|
|
406
428
|
Ke,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
429
|
+
xe,
|
|
430
|
+
tt,
|
|
431
|
+
Ge,
|
|
432
|
+
ot
|
|
433
|
+
], b = (e, t) => {
|
|
411
434
|
const r = t.revivableModules.find((n) => n.isType(e));
|
|
412
|
-
return r?.isType(e) ? r.box(e, t) : Array.isArray(e) ? e.map((n) =>
|
|
435
|
+
return r?.isType(e) ? r.box(e, t) : Array.isArray(e) ? e.map((n) => b(n, t)) : e && typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype ? Object.fromEntries(
|
|
413
436
|
Object.entries(e).map(([n, a]) => [
|
|
414
437
|
n,
|
|
415
|
-
|
|
438
|
+
b(a, t)
|
|
416
439
|
])
|
|
417
440
|
) : e;
|
|
418
441
|
}, A = (e, t) => {
|
|
419
|
-
if (
|
|
442
|
+
if (le(e)) {
|
|
420
443
|
const r = t.revivableModules.find((n) => n.type === e.type);
|
|
421
444
|
if (r)
|
|
422
445
|
return r.revive(e, t);
|
|
@@ -427,37 +450,37 @@ const re = (e) => {
|
|
|
427
450
|
A(n, t)
|
|
428
451
|
])
|
|
429
452
|
) : e;
|
|
430
|
-
},
|
|
453
|
+
}, it = ({ transport: e, value: t, uuid: r, remoteUuid: n, platformCapabilities: a, eventTarget: s, send: o, close: i }) => {
|
|
431
454
|
const c = {
|
|
432
455
|
platformCapabilities: a,
|
|
433
456
|
transport: e,
|
|
434
457
|
remoteUuid: n,
|
|
435
458
|
messagePorts: /* @__PURE__ */ new Set(),
|
|
436
|
-
messageChannels:
|
|
459
|
+
messageChannels: pe(),
|
|
437
460
|
sendMessage: o,
|
|
438
461
|
eventTarget: s,
|
|
439
|
-
revivableModules:
|
|
462
|
+
revivableModules: at
|
|
440
463
|
};
|
|
441
464
|
let y;
|
|
442
|
-
const
|
|
443
|
-
y =
|
|
465
|
+
const l = new Promise((p, f) => {
|
|
466
|
+
y = p;
|
|
444
467
|
});
|
|
445
|
-
return s.addEventListener("message", ({ detail:
|
|
446
|
-
if (
|
|
447
|
-
y(
|
|
468
|
+
return s.addEventListener("message", ({ detail: p }) => {
|
|
469
|
+
if (p.type === "init") {
|
|
470
|
+
y(p);
|
|
448
471
|
return;
|
|
449
|
-
} else
|
|
472
|
+
} else p.type === "message" && c.messageChannels.getOrAlloc(p.portId).port2?.postMessage(p);
|
|
450
473
|
}), o({
|
|
451
474
|
type: "init",
|
|
452
475
|
remoteUuid: n,
|
|
453
|
-
data:
|
|
476
|
+
data: b(t, c)
|
|
454
477
|
}), {
|
|
455
478
|
revivableContext: c,
|
|
456
479
|
close: () => {
|
|
457
480
|
},
|
|
458
|
-
remoteValue:
|
|
481
|
+
remoteValue: l.then((p) => A(p.data, c))
|
|
459
482
|
};
|
|
460
|
-
},
|
|
483
|
+
}, ct = ({ value: e, uuid: t, platformCapabilities: r, send: n, close: a }) => ({
|
|
461
484
|
close: () => {
|
|
462
485
|
},
|
|
463
486
|
remoteValueProxy: new Proxy(
|
|
@@ -470,81 +493,85 @@ const re = (e) => {
|
|
|
470
493
|
}
|
|
471
494
|
)
|
|
472
495
|
});
|
|
473
|
-
var
|
|
496
|
+
var yt = class extends EventTarget {
|
|
474
497
|
dispatchTypedEvent(e, t) {
|
|
475
498
|
return super.dispatchEvent(t);
|
|
476
499
|
}
|
|
477
500
|
};
|
|
478
|
-
const
|
|
501
|
+
const ft = async (e, {
|
|
479
502
|
transport: t,
|
|
480
503
|
name: r,
|
|
481
504
|
remoteName: n,
|
|
482
|
-
key: a =
|
|
505
|
+
key: a = de,
|
|
483
506
|
origin: s = "*",
|
|
484
507
|
unregisterSignal: o,
|
|
485
508
|
platformCapabilities: i,
|
|
486
509
|
transferAll: c,
|
|
487
510
|
logger: y
|
|
488
511
|
}) => {
|
|
489
|
-
const
|
|
512
|
+
const l = {
|
|
490
513
|
isJson: "isJson" in t && t.isJson !== void 0 ? t.isJson : S(t),
|
|
491
514
|
...J(t) ? t : {
|
|
492
515
|
emit: t,
|
|
493
516
|
receive: t
|
|
494
517
|
}
|
|
495
|
-
},
|
|
518
|
+
}, p = i ?? await Me(), f = /* @__PURE__ */ new Map();
|
|
496
519
|
let h;
|
|
497
|
-
const
|
|
520
|
+
const _ = new Promise((d) => {
|
|
498
521
|
h = d;
|
|
499
522
|
});
|
|
500
|
-
let
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
523
|
+
let u = globalThis.crypto.randomUUID(), V = !1;
|
|
524
|
+
o && o.addEventListener("abort", () => {
|
|
525
|
+
V = !0;
|
|
526
|
+
});
|
|
527
|
+
const U = (d, T) => {
|
|
528
|
+
if (V) return;
|
|
529
|
+
const g = w(T);
|
|
530
|
+
be(
|
|
504
531
|
d,
|
|
505
532
|
{
|
|
506
|
-
[
|
|
533
|
+
[C]: a,
|
|
507
534
|
name: r,
|
|
508
|
-
uuid:
|
|
509
|
-
...
|
|
535
|
+
uuid: u,
|
|
536
|
+
...T
|
|
510
537
|
},
|
|
511
538
|
s,
|
|
512
539
|
g
|
|
513
540
|
);
|
|
514
|
-
},
|
|
515
|
-
if (d.uuid !==
|
|
516
|
-
if (!
|
|
541
|
+
}, fe = async (d, T) => {
|
|
542
|
+
if (d.uuid !== u) {
|
|
543
|
+
if (!B(l))
|
|
517
544
|
throw new Error("Unidirectional receiving mode not implemented");
|
|
518
545
|
if (d.type === "announce") {
|
|
519
546
|
if (!d.remoteUuid) {
|
|
520
|
-
|
|
547
|
+
U(l, { type: "announce", remoteUuid: d.uuid });
|
|
521
548
|
return;
|
|
522
549
|
}
|
|
523
|
-
if (d.remoteUuid !==
|
|
550
|
+
if (d.remoteUuid !== u || f.has(d.uuid))
|
|
524
551
|
return;
|
|
525
|
-
|
|
526
|
-
const g = new
|
|
552
|
+
U(l, { type: "announce", remoteUuid: d.uuid });
|
|
553
|
+
const g = new yt(), q = {
|
|
527
554
|
type: "bidirectional",
|
|
528
555
|
eventTarget: g,
|
|
529
|
-
connection:
|
|
530
|
-
transport:
|
|
556
|
+
connection: it({
|
|
557
|
+
transport: l,
|
|
531
558
|
value: e,
|
|
532
|
-
uuid:
|
|
559
|
+
uuid: u,
|
|
533
560
|
remoteUuid: d.uuid,
|
|
534
|
-
platformCapabilities:
|
|
561
|
+
platformCapabilities: p,
|
|
535
562
|
eventTarget: g,
|
|
536
|
-
send: (j) =>
|
|
563
|
+
send: (j) => U(l, j),
|
|
537
564
|
close: () => void f.delete(d.uuid)
|
|
538
565
|
})
|
|
539
566
|
};
|
|
540
|
-
f.set(d.uuid,
|
|
567
|
+
f.set(d.uuid, q), q.connection.remoteValue.then(
|
|
541
568
|
(j) => h(j)
|
|
542
569
|
);
|
|
543
570
|
} else if (d.type === "reject-uuid-taken") {
|
|
544
|
-
if (d.remoteUuid !==
|
|
545
|
-
|
|
571
|
+
if (d.remoteUuid !== u) return;
|
|
572
|
+
u = globalThis.crypto.randomUUID(), U(l, { type: "announce" });
|
|
546
573
|
} else if (d.type === "close") {
|
|
547
|
-
if (d.remoteUuid !==
|
|
574
|
+
if (d.remoteUuid !== u) return;
|
|
548
575
|
const g = f.get(d.uuid);
|
|
549
576
|
if (!g) {
|
|
550
577
|
console.warn(`Connection not found for remoteUuid: ${d.uuid}`);
|
|
@@ -552,7 +579,7 @@ const st = async (e, {
|
|
|
552
579
|
}
|
|
553
580
|
g.connection.close(), f.delete(d.uuid);
|
|
554
581
|
} else {
|
|
555
|
-
if (d.remoteUuid !==
|
|
582
|
+
if (d.remoteUuid !== u) return;
|
|
556
583
|
const g = f.get(d.uuid);
|
|
557
584
|
if (!g) {
|
|
558
585
|
console.warn(`Connection not found for remoteUuid: ${d.uuid}`);
|
|
@@ -565,26 +592,26 @@ const st = async (e, {
|
|
|
565
592
|
}
|
|
566
593
|
}
|
|
567
594
|
};
|
|
568
|
-
if (
|
|
569
|
-
listener:
|
|
570
|
-
transport:
|
|
595
|
+
if (W(l) && ge({
|
|
596
|
+
listener: fe,
|
|
597
|
+
transport: l,
|
|
571
598
|
remoteName: n,
|
|
572
599
|
key: a,
|
|
573
600
|
unregisterSignal: o
|
|
574
|
-
}),
|
|
575
|
-
const { remoteValueProxy: d } =
|
|
601
|
+
}), B(l) && U(l, { type: "announce" }), B(l) && !W(l)) {
|
|
602
|
+
const { remoteValueProxy: d } = ct({
|
|
576
603
|
value: e,
|
|
577
|
-
uuid:
|
|
578
|
-
platformCapabilities:
|
|
579
|
-
send: (
|
|
580
|
-
close: () => f.delete(
|
|
604
|
+
uuid: u,
|
|
605
|
+
platformCapabilities: p,
|
|
606
|
+
send: (T) => U(l, T),
|
|
607
|
+
close: () => f.delete(u)
|
|
581
608
|
});
|
|
582
609
|
return d;
|
|
583
610
|
}
|
|
584
|
-
return
|
|
611
|
+
return _;
|
|
585
612
|
};
|
|
586
613
|
export {
|
|
587
|
-
|
|
588
|
-
|
|
614
|
+
m as BoxBase,
|
|
615
|
+
ft as expose
|
|
589
616
|
};
|
|
590
617
|
//# sourceMappingURL=index.js.map
|