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