osra 0.1.2 → 0.2.1
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/README.md +287 -42
- package/build/extension/background.js +2 -0
- package/build/extension/background.js.map +1 -0
- package/build/extension/chunks/index.js +2 -0
- package/build/extension/chunks/index.js.map +1 -0
- package/build/extension/content.js +2 -0
- package/build/extension/content.js.map +1 -0
- package/build/extension/manifest.json +21 -0
- package/build/extension/popup.html +120 -0
- package/build/extension/popup.js +2 -0
- package/build/extension/popup.js.map +1 -0
- package/build/extension-test/background.js +753 -0
- package/build/extension-test/background.js.map +1 -0
- package/build/extension-test/content.js +4585 -0
- package/build/extension-test/content.js.map +1 -0
- package/build/extension-test/manifest.json +22 -0
- package/build/extension-test/popup.html +106 -0
- package/build/extension-test/popup.js +4610 -0
- package/build/extension-test/popup.js.map +1 -0
- package/build/extension-test-firefox/background.js +5464 -0
- package/build/extension-test-firefox/background.js.map +1 -0
- package/build/extension-test-firefox/content.js +5286 -0
- package/build/extension-test-firefox/content.js.map +1 -0
- package/build/extension-test-firefox/manifest.json +27 -0
- package/build/extension-test-firefox/popup.html +106 -0
- package/build/extension-test-firefox/popup.js +5213 -0
- package/build/extension-test-firefox/popup.js.map +1 -0
- package/build/index.d.ts +155 -8
- package/build/index.js +432 -259
- package/build/index.js.map +1 -1
- package/build/test.js +24021 -2578
- package/build/test.js.map +1 -1
- package/package.json +34 -16
- package/build/types.d.ts +0 -66
- package/build/utils.d.ts +0 -60
package/build/index.js
CHANGED
|
@@ -1,280 +1,453 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!o) throw new Error("No ports received for proxied function");
|
|
31
|
-
const c = (...n) => new Promise((i, f) => {
|
|
32
|
-
const { port1: g, port2: l } = new MessageChannel(), m = y([l, n], t), A = M(m), S = (h) => {
|
|
33
|
-
const b = R(h.data, t);
|
|
34
|
-
if (!(b instanceof Promise)) throw new Error("Proxied function did not return a promise");
|
|
35
|
-
b.then(i).catch(f).finally(() => g.close());
|
|
36
|
-
};
|
|
37
|
-
g.addEventListener("message", S, { once: !0 }), g.start(), o.postMessage(m, { transfer: A });
|
|
38
|
-
});
|
|
39
|
-
return r && t.finalizationRegistry.register(c, Number(r.split("/")[1])), c;
|
|
40
|
-
}, W = (e, t) => {
|
|
41
|
-
const r = t.envCheck.supportsPorts && "port" in e ? e.port : "portId" in e ? t.addIncomingProxiedMessagePort(e.portId) : void 0;
|
|
42
|
-
if (!r) throw new Error("No ports received for proxied message port");
|
|
1
|
+
const M = "__OSRA_KEY__", oe = "__OSRA_DEFAULT_KEY__", E = "__OSRA_BOX__", ae = () => {
|
|
2
|
+
const e = /* @__PURE__ */ new Map(), r = {
|
|
3
|
+
getUniqueUuid: () => {
|
|
4
|
+
let t = globalThis.crypto.randomUUID();
|
|
5
|
+
for (; e.has(t); )
|
|
6
|
+
t = globalThis.crypto.randomUUID();
|
|
7
|
+
return t;
|
|
8
|
+
},
|
|
9
|
+
set: (t, n) => {
|
|
10
|
+
e.set(t, { uuid: t, ...n });
|
|
11
|
+
},
|
|
12
|
+
alloc: (t = r.getUniqueUuid(), n) => {
|
|
13
|
+
if (n)
|
|
14
|
+
return e.set(t, { uuid: t, ...n }), { uuid: t, ...n };
|
|
15
|
+
const o = new MessageChannel(), s = {
|
|
16
|
+
uuid: t,
|
|
17
|
+
port1: o.port1,
|
|
18
|
+
port2: o.port2
|
|
19
|
+
};
|
|
20
|
+
return e.set(t, s), s;
|
|
21
|
+
},
|
|
22
|
+
has: (t) => e.has(t),
|
|
23
|
+
get: (t) => e.get(t),
|
|
24
|
+
free: (t) => e.delete(t),
|
|
25
|
+
getOrAlloc: (t = r.getUniqueUuid(), n) => {
|
|
26
|
+
const o = r.get(t);
|
|
27
|
+
return o || r.alloc(t, n);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
43
30
|
return r;
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
}, $ = (e, r) => le(e) && e[M] === r, ie = ({ listener: e, transport: r, remoteName: t, key: n = M, unregisterSignal: o }) => {
|
|
32
|
+
const s = (a) => {
|
|
33
|
+
if (typeof a == "function")
|
|
34
|
+
a(e);
|
|
35
|
+
else if (I(a) || O(a) || L(a)) {
|
|
36
|
+
const c = (i, l) => {
|
|
37
|
+
const f = (d, g) => {
|
|
38
|
+
$(d, n) && (t && d.name !== t || e(d, { port: l, sender: g }));
|
|
39
|
+
};
|
|
40
|
+
i.addListener(f), o && o.addEventListener(
|
|
41
|
+
"abort",
|
|
42
|
+
() => i.removeListener(f)
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
if (O(a)) {
|
|
46
|
+
const i = (l) => {
|
|
47
|
+
c(l.onMessage, l);
|
|
48
|
+
};
|
|
49
|
+
a.addListener(i), o && o.addEventListener(
|
|
50
|
+
"abort",
|
|
51
|
+
() => a.removeListener(i)
|
|
52
|
+
);
|
|
53
|
+
} else L(a) ? c(a) : c(a.onMessage);
|
|
54
|
+
} else {
|
|
55
|
+
const c = (i) => {
|
|
56
|
+
$(i.data, n) && (t && i.data.name !== t || e(i.data, { receiveTransport: a, source: i.source }));
|
|
57
|
+
};
|
|
58
|
+
a.addEventListener("message", c), o && o.addEventListener(
|
|
59
|
+
"abort",
|
|
60
|
+
() => a.removeEventListener("message", c)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
50
63
|
};
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(r) => {
|
|
56
|
-
if (r.type === "function")
|
|
57
|
-
return K(r, t);
|
|
58
|
-
if (r.type === "error")
|
|
59
|
-
return X(r);
|
|
60
|
-
if (r.type === "messagePort")
|
|
61
|
-
return W(r, t);
|
|
62
|
-
if (r.type === "promise")
|
|
63
|
-
return H(r, t);
|
|
64
|
-
throw new Error(`Unknown incoming proxied type: ${e}`);
|
|
65
|
-
}
|
|
66
|
-
), q = (e, t) => ({
|
|
67
|
-
[w]: !0,
|
|
68
|
-
type: "error",
|
|
69
|
-
message: e.message,
|
|
70
|
-
stack: e.stack
|
|
71
|
-
}), F = (e, t) => ({
|
|
72
|
-
[w]: !0,
|
|
73
|
-
type: "messagePort",
|
|
74
|
-
...t.envCheck.supportsPorts ? { port: e } : { portId: t.addOutgoingProxiedMessagePort(e) }
|
|
75
|
-
}), J = (e, t) => {
|
|
76
|
-
const { port1: r, port2: o } = new MessageChannel(), c = (n) => {
|
|
77
|
-
const i = y(n, t), f = M(i);
|
|
78
|
-
r.postMessage(i, { transfer: f }), r.close();
|
|
64
|
+
K(r) ? s(r.receive) : s(r);
|
|
65
|
+
}, ce = (e, r, t = "*", n = []) => {
|
|
66
|
+
const o = (s) => {
|
|
67
|
+
typeof s == "function" ? s(r, n) : I(s) ? s.postMessage(r) : q(s) ? s.postMessage(r, t, n) : k(s) ? s.send(JSON.stringify(r)) : W(s) ? s.port.postMessage(r, n) : s.postMessage(r, n);
|
|
79
68
|
};
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
K(e) ? o(e.emit) : o(e);
|
|
70
|
+
}, ye = [
|
|
71
|
+
Int8Array,
|
|
72
|
+
Uint8Array,
|
|
73
|
+
Uint8ClampedArray,
|
|
74
|
+
Int16Array,
|
|
75
|
+
Uint16Array,
|
|
76
|
+
Int32Array,
|
|
77
|
+
Uint32Array,
|
|
78
|
+
Float16Array,
|
|
79
|
+
Float32Array,
|
|
80
|
+
Float64Array,
|
|
81
|
+
BigInt64Array,
|
|
82
|
+
BigUint64Array
|
|
83
|
+
];
|
|
84
|
+
new Int8Array(), new Uint8Array(), new Uint8ClampedArray(), new Int16Array(), new Uint16Array(), new Int32Array(), new Uint32Array(), new Float16Array(), new Float32Array(), new Float64Array(), new BigInt64Array(), new BigUint64Array();
|
|
85
|
+
const fe = (e) => {
|
|
86
|
+
const r = 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;
|
|
87
|
+
if (r === void 0) throw new Error("Unknown typed array type");
|
|
88
|
+
return r;
|
|
89
|
+
}, de = (e) => {
|
|
90
|
+
const r = 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;
|
|
91
|
+
if (r === void 0) throw new Error("Unknown typed array type");
|
|
92
|
+
return r;
|
|
93
|
+
}, j = (e) => ye.some((r) => e instanceof r), k = (e) => e instanceof WebSocket, H = (e) => globalThis.ServiceWorkerContainer && e instanceof ServiceWorkerContainer, Q = (e) => globalThis.Worker && e instanceof Worker, Z = (e) => globalThis.DedicatedWorkerGlobalScope && e instanceof DedicatedWorkerGlobalScope, W = (e) => globalThis.SharedWorker && e instanceof SharedWorker, C = (e) => e instanceof MessagePort, D = (e) => e instanceof Promise, _ = (e) => typeof e == "function", T = (e) => e instanceof ArrayBuffer, B = (e) => e instanceof ReadableStream, V = (e) => e instanceof Date, J = (e) => e instanceof Error, pe = (e) => _(e) || D(e) || j(e) || V(e) || J(e), le = (e) => !!(e && typeof e == "object" && e[M]), ge = (e) => !!(globalThis.SharedArrayBuffer && e instanceof globalThis.SharedArrayBuffer), N = (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), I = (e, r = !1) => !!(e && typeof e == "object" && e.name && e.disconnect && e.postMessage && (!r || e.sender && e.onMessage && e.onDisconnect)), O = (e) => !!(e && typeof e == "object" && e.addListener && e.hasListener && e.removeListener), L = (e) => !!(e && typeof e == "object" && e.addListener && e.hasListener && e.removeListener), q = (e) => !!(e && typeof e == "object" && e.document && e.location && e.navigator && e.screen && e.history), x = (e) => k(e) || I(e), v = (e) => k(e) || I(e) || O(e) || L(e), Ae = (e) => x(e) || v(e), P = (e) => x(e) || q(e) || H(e) || Q(e) || Z(e) || W(e) || C(e) || ee(e), F = (e) => v(e) || q(e) || H(e) || Q(e) || Z(e) || W(e) || C(e) || re(e), ee = (e) => !!(e && typeof e == "object" && "emit" in e && (P(e.emit) || typeof e.emit == "function")), re = (e) => !!(e && typeof e == "object" && "receive" in e && (F(e.receive) || typeof e.receive == "function")), K = (e) => ee(e) || re(e), te = (e) => C(e) || _(e) || D(e) || j(e) || T(e) || B(e) || V(e) || J(e), p = (e) => e && typeof e == "object" && E in e && e[E] === "revivable", me = (e) => p(e) && e.type === "messagePort", Y = (e) => p(e) && e.type === "promise", be = (e) => p(e) && e.type === "function", he = (e) => p(e) && e.type === "typedArray", ue = (e) => p(e) && e.type === "arrayBuffer", we = (e) => p(e) && e.type === "readableStream", Ue = (e) => p(e) && e.type === "error", Be = (e) => p(e) && e.type === "date", u = (e) => {
|
|
94
|
+
const r = [], t = (n) => ge(n) ? void 0 : N(n) ? r.push(n) : Array.isArray(n) ? n.map(t) : n && typeof n == "object" ? Object.values(n).map(t) : void 0;
|
|
95
|
+
return t(e), r;
|
|
96
|
+
}, S = (e, r = !1) => {
|
|
97
|
+
const { port1: t, port2: n } = new MessageChannel(), o = new Promise(
|
|
98
|
+
(s) => t.addEventListener(
|
|
99
|
+
"message",
|
|
100
|
+
(a) => s(a.data)
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
return t.start(), n.postMessage(e, r ? u(e) : []), o;
|
|
104
|
+
}, Ce = async () => {
|
|
105
|
+
const { port1: e } = new MessageChannel();
|
|
106
|
+
return await S(e, !0) instanceof MessagePort;
|
|
107
|
+
}, Pe = async () => {
|
|
108
|
+
const e = new ArrayBuffer(1);
|
|
109
|
+
return await S(e) instanceof ArrayBuffer;
|
|
110
|
+
}, Ee = async () => {
|
|
111
|
+
const e = new ArrayBuffer(1);
|
|
112
|
+
return await S(e, !0) instanceof ArrayBuffer;
|
|
113
|
+
}, Me = async () => {
|
|
114
|
+
const e = new ReadableStream({
|
|
115
|
+
start(t) {
|
|
116
|
+
t.enqueue(new Uint8Array(1)), t.close();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return await S(e, !0) instanceof ReadableStream;
|
|
120
|
+
}, Ie = async () => {
|
|
121
|
+
const [
|
|
122
|
+
e,
|
|
123
|
+
r,
|
|
124
|
+
t,
|
|
125
|
+
n
|
|
126
|
+
] = await Promise.all([
|
|
127
|
+
Ce().catch(() => !1),
|
|
128
|
+
Pe().catch(() => !1),
|
|
129
|
+
Ee().catch(() => !1),
|
|
130
|
+
Me().catch(() => !1)
|
|
131
|
+
]);
|
|
132
|
+
return {
|
|
133
|
+
jsonOnly: !e && !r && !t && !n,
|
|
134
|
+
messagePort: e,
|
|
135
|
+
arrayBuffer: r,
|
|
136
|
+
transferable: t,
|
|
137
|
+
transferableStream: n
|
|
138
|
+
};
|
|
139
|
+
}, Se = (e, r) => {
|
|
140
|
+
const t = e, { uuid: n } = r.messageChannels.alloc(void 0, { port1: t });
|
|
141
|
+
return t.addEventListener("message", ({ data: o }) => {
|
|
142
|
+
r.sendMessage({
|
|
143
|
+
type: "message",
|
|
144
|
+
remoteUuid: r.remoteUuid,
|
|
145
|
+
data: p(o) ? o : m(o, r),
|
|
146
|
+
portId: n
|
|
147
|
+
});
|
|
148
|
+
}), t.start(), r.eventTarget.addEventListener("message", function o({ detail: s }) {
|
|
149
|
+
if (s.type === "message-port-close") {
|
|
150
|
+
if (s.portId !== n) return;
|
|
151
|
+
r.eventTarget.removeEventListener("message", o), t.close(), r.messageChannels.free(n);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
s.type !== "message" || s.portId !== n || t.postMessage(s.data, u(s.data));
|
|
155
|
+
}), {
|
|
156
|
+
type: "messagePort",
|
|
157
|
+
portId: n
|
|
158
|
+
};
|
|
159
|
+
}, Re = (e, r) => {
|
|
160
|
+
const { port1: t, port2: n } = new MessageChannel();
|
|
161
|
+
n.addEventListener("message", ({ data: a }) => {
|
|
162
|
+
r.sendMessage({
|
|
163
|
+
type: "message",
|
|
164
|
+
remoteUuid: r.remoteUuid,
|
|
165
|
+
data: p(a) ? a : m(a, r),
|
|
166
|
+
portId: e.portId
|
|
167
|
+
});
|
|
168
|
+
}), n.start();
|
|
169
|
+
const o = r.messageChannels.get(e.portId), { port1: s } = o || r.messageChannels.alloc(e.portId);
|
|
170
|
+
return s.addEventListener("message", function a({ data: c }) {
|
|
171
|
+
if (c.type === "message-port-close") {
|
|
172
|
+
if (c.portId !== e.portId) return;
|
|
173
|
+
s.removeEventListener("message", a), n.close(), r.messageChannels.free(e.portId);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!(c.type !== "message" || c.portId !== e.portId))
|
|
177
|
+
if (r.messagePorts.has(t))
|
|
178
|
+
n.postMessage(c.data);
|
|
179
|
+
else {
|
|
180
|
+
const i = h(c.data, r);
|
|
181
|
+
n.postMessage(i, u(i));
|
|
182
|
+
}
|
|
183
|
+
}), s.start(), t;
|
|
184
|
+
}, Te = (e, r) => {
|
|
185
|
+
const { port1: t, port2: n } = new MessageChannel();
|
|
186
|
+
r.messagePorts.add(n);
|
|
187
|
+
const o = (s) => {
|
|
188
|
+
const a = m(s, r);
|
|
189
|
+
t.postMessage(a, u(a)), t.close();
|
|
190
|
+
};
|
|
191
|
+
return e.then((s) => o({ type: "resolve", data: s })).catch((s) => o({ type: "reject", error: s.stack })), {
|
|
82
192
|
type: "promise",
|
|
83
|
-
port:
|
|
193
|
+
port: n
|
|
84
194
|
};
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
195
|
+
}, Oe = (e, r) => (r.messagePorts.add(e.port), new Promise((t, n) => {
|
|
196
|
+
e.port.addEventListener("message", ({ data: o }) => {
|
|
197
|
+
const s = h(o, r);
|
|
198
|
+
s.type === "resolve" ? t(s.data) : n(s.error), e.port.close();
|
|
199
|
+
}, { once: !0 }), e.port.start();
|
|
200
|
+
})), Le = (e, r) => {
|
|
201
|
+
const { port1: t, port2: n } = new MessageChannel();
|
|
202
|
+
return r.messagePorts.add(n), t.addEventListener("message", ({ data: o }) => {
|
|
203
|
+
const [s, a] = h(o, r), c = (async () => e(...a))(), i = m(c, r);
|
|
204
|
+
s.postMessage(i, u(i));
|
|
205
|
+
}), t.start(), {
|
|
92
206
|
type: "function",
|
|
93
|
-
port:
|
|
207
|
+
port: n
|
|
94
208
|
};
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
(r)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
209
|
+
}, Fe = (e, r) => (...n) => new Promise((o, s) => {
|
|
210
|
+
const { port1: a, port2: c } = new MessageChannel();
|
|
211
|
+
r.messagePorts.add(c);
|
|
212
|
+
const i = m([c, n], r);
|
|
213
|
+
e.port.postMessage(i, u(i)), a.addEventListener("message", ({ data: l }) => {
|
|
214
|
+
if (!Y(l)) throw new Error("Proxied function did not return a promise");
|
|
215
|
+
h(l, r).then(o).catch(s).finally(() => a.close());
|
|
216
|
+
}), a.start();
|
|
217
|
+
}), je = (e, r) => ({
|
|
218
|
+
type: "typedArray",
|
|
219
|
+
typedArrayType: fe(e),
|
|
220
|
+
arrayBuffer: e.buffer
|
|
221
|
+
}), ke = (e, r) => {
|
|
222
|
+
const t = de(e.typedArrayType);
|
|
223
|
+
return new t(e.arrayBuffer);
|
|
224
|
+
}, We = (e, r) => ({
|
|
225
|
+
type: "arrayBuffer",
|
|
226
|
+
base64Buffer: new Uint8Array(e).toBase64()
|
|
227
|
+
}), De = (e, r) => Uint8Array.fromBase64(e.base64Buffer).buffer, _e = (e, r) => ({
|
|
228
|
+
type: "error",
|
|
229
|
+
message: e.message,
|
|
230
|
+
stack: e.stack || e.toString()
|
|
231
|
+
}), Ve = (e, r) => new Error(e.message, { cause: e.stack }), z = (e, r) => {
|
|
232
|
+
const { port1: t, port2: n } = new MessageChannel();
|
|
233
|
+
r.messagePorts.add(n);
|
|
234
|
+
const o = e.getReader();
|
|
235
|
+
return t.addEventListener("message", async ({ data: s }) => {
|
|
236
|
+
const { type: a } = h(s, r);
|
|
237
|
+
if (a === "pull") {
|
|
238
|
+
const c = o.read(), i = m(c, r);
|
|
239
|
+
t.postMessage(i, u(i));
|
|
240
|
+
} else
|
|
241
|
+
o.cancel(), t.close();
|
|
242
|
+
}), t.start(), {
|
|
243
|
+
type: "readableStream",
|
|
244
|
+
port: n
|
|
245
|
+
};
|
|
246
|
+
}, Je = (e, r) => (r.messagePorts.add(e.port), e.port.start(), new ReadableStream({
|
|
247
|
+
start(t) {
|
|
248
|
+
},
|
|
249
|
+
pull(t) {
|
|
250
|
+
return new Promise((n, o) => {
|
|
251
|
+
e.port.addEventListener("message", async ({ data: s }) => {
|
|
252
|
+
if (!Y(s)) throw new Error("Proxied function did not return a promise");
|
|
253
|
+
h(s, r).then((c) => {
|
|
254
|
+
c.done ? t.close() : t.enqueue(c.value), n();
|
|
255
|
+
}).catch(o);
|
|
256
|
+
}, { once: !0 }), e.port.postMessage(m({ type: "pull" }, r));
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
cancel() {
|
|
260
|
+
e.port.postMessage(m({ type: "cancel" }, r)), e.port.close();
|
|
108
261
|
}
|
|
109
|
-
),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
]
|
|
114
|
-
) : e,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
262
|
+
})), qe = (e, r) => ({
|
|
263
|
+
type: "date",
|
|
264
|
+
ISOString: e.toISOString()
|
|
265
|
+
}), Ke = (e, r) => new Date(e.ISOString), Ye = (e, r) => pe(e) || B(e) && !r.platformCapabilities.transferableStream ? {
|
|
266
|
+
[E]: "revivable",
|
|
267
|
+
..._(e) ? Le(e, r) : D(e) ? Te(e, r) : j(e) ? je(e) : B(e) ? z(e, r) : V(e) ? qe(e) : J(e) ? _e(e) : e
|
|
268
|
+
} : {
|
|
269
|
+
[E]: "revivable",
|
|
270
|
+
..."isJson" in r.transport && r.transport.isJson ? C(e) ? Se(e, r) : T(e) ? We(e) : B(e) ? z(e, r) : { type: "unknown", value: e } : {
|
|
271
|
+
type: C(e) ? "messagePort" : T(e) ? "arrayBuffer" : B(e) ? "readableStream" : "unknown",
|
|
272
|
+
value: e
|
|
273
|
+
}
|
|
274
|
+
}, m = (e, r) => {
|
|
275
|
+
const t = te(e) ? Ye(e, r) : e;
|
|
276
|
+
return Array.isArray(t) ? t.map((n) => m(n, r)) : t && typeof t == "object" && Object.getPrototypeOf(t) === Object.prototype ? Object.fromEntries(
|
|
277
|
+
Object.entries(t).map(([n, o]) => [
|
|
278
|
+
n,
|
|
279
|
+
p(t) && t.type === "messagePort" && t.value instanceof MessagePort || p(t) && t.type === "arrayBuffer" && t.value instanceof ArrayBuffer || p(t) && t.type === "readableStream" && t.value instanceof ReadableStream ? o : m(o, r)
|
|
280
|
+
])
|
|
281
|
+
) : t;
|
|
282
|
+
}, Ge = (e, r) => te(e.value) ? e.value : me(e) ? Re(e, r) : be(e) ? Fe(e, r) : Y(e) ? Oe(e, r) : Ue(e) ? Ve(e) : he(e) ? ke(e) : ue(e) ? De(e) : we(e) ? Je(e, r) : Be(e) ? Ke(e) : e, h = (e, r) => {
|
|
283
|
+
const t = N(e) ? e : Array.isArray(e) ? e.map((n) => h(n, r)) : e && typeof e == "object" ? Object.fromEntries(
|
|
284
|
+
Object.entries(e).map(([n, o]) => [
|
|
285
|
+
n,
|
|
286
|
+
h(o, r)
|
|
287
|
+
])
|
|
288
|
+
) : e;
|
|
289
|
+
return p(t) ? Ge(t, r) : t;
|
|
290
|
+
}, Xe = ({ transport: e, value: r, uuid: t, remoteUuid: n, platformCapabilities: o, eventTarget: s, send: a, close: c }) => {
|
|
291
|
+
const i = {
|
|
292
|
+
platformCapabilities: o,
|
|
293
|
+
transport: e,
|
|
294
|
+
remoteUuid: n,
|
|
295
|
+
messagePorts: /* @__PURE__ */ new Set(),
|
|
296
|
+
messageChannels: ae(),
|
|
297
|
+
sendMessage: a,
|
|
298
|
+
eventTarget: s
|
|
130
299
|
};
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
300
|
+
let l;
|
|
301
|
+
const f = new Promise((d, g) => {
|
|
302
|
+
l = d;
|
|
303
|
+
});
|
|
304
|
+
return s.addEventListener("message", ({ detail: d }) => {
|
|
305
|
+
if (d.type === "init") {
|
|
306
|
+
l(d);
|
|
307
|
+
return;
|
|
308
|
+
} else d.type === "message" && i.messageChannels.getOrAlloc(d.portId).port2?.postMessage(d);
|
|
309
|
+
}), a({
|
|
310
|
+
type: "init",
|
|
311
|
+
remoteUuid: n,
|
|
312
|
+
data: m(r, i)
|
|
313
|
+
}), {
|
|
314
|
+
revivableContext: i,
|
|
315
|
+
close: () => {
|
|
137
316
|
},
|
|
138
|
-
|
|
139
|
-
free: (n) => {
|
|
140
|
-
t.delete(n), e.free(n);
|
|
141
|
-
}
|
|
317
|
+
remoteValue: f.then((d) => h(d.data, i))
|
|
142
318
|
};
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
319
|
+
}, $e = ({ value: e, uuid: r, platformCapabilities: t, send: n, close: o }) => ({
|
|
320
|
+
close: () => {
|
|
321
|
+
},
|
|
322
|
+
remoteValueProxy: new Proxy(
|
|
323
|
+
new Function(),
|
|
324
|
+
{
|
|
325
|
+
apply: (s, a, c) => {
|
|
326
|
+
},
|
|
327
|
+
get: (s, a) => {
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
});
|
|
332
|
+
var ze = class extends EventTarget {
|
|
333
|
+
dispatchTypedEvent(e, r) {
|
|
334
|
+
return super.dispatchEvent(r);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const He = async (e, {
|
|
338
|
+
transport: r,
|
|
339
|
+
name: t,
|
|
340
|
+
remoteName: n,
|
|
341
|
+
key: o = oe,
|
|
342
|
+
origin: s = "*",
|
|
343
|
+
unregisterSignal: a,
|
|
344
|
+
platformCapabilities: c,
|
|
345
|
+
transferAll: i,
|
|
346
|
+
logger: l
|
|
148
347
|
}) => {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
[E]: !0,
|
|
166
|
-
key: o,
|
|
167
|
-
type: "message",
|
|
168
|
-
portId: `${n}/${a}`,
|
|
169
|
-
data: y(d.data, h())
|
|
170
|
-
},
|
|
171
|
-
[]
|
|
172
|
-
);
|
|
173
|
-
}), s.addEventListener("close", () => {
|
|
174
|
-
g.free(a), T(
|
|
175
|
-
{
|
|
176
|
-
[E]: !0,
|
|
177
|
-
key: o,
|
|
178
|
-
type: "port-closed",
|
|
179
|
-
portId: `${n}/${a}`
|
|
180
|
-
},
|
|
181
|
-
[]
|
|
182
|
-
);
|
|
183
|
-
}), `${n}/${a}`;
|
|
184
|
-
}, h = () => {
|
|
185
|
-
if (!i) throw new Error("Osra context was accessed before the ready message was received.");
|
|
186
|
-
return {
|
|
187
|
-
addIncomingProxiedMessagePort: A,
|
|
188
|
-
addOutgoingProxiedMessagePort: S,
|
|
189
|
-
envCheck: i,
|
|
190
|
-
finalizationRegistry: f
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
let b;
|
|
194
|
-
const L = new Promise((s, a) => {
|
|
195
|
-
b = s;
|
|
196
|
-
}), U = () => {
|
|
197
|
-
const s = new ArrayBuffer(1), { port1: a } = new MessageChannel();
|
|
198
|
-
T(
|
|
348
|
+
const f = {
|
|
349
|
+
isJson: "isJson" in r && r.isJson !== void 0 ? r.isJson : Ae(r),
|
|
350
|
+
...K(r) ? r : {
|
|
351
|
+
emit: r,
|
|
352
|
+
receive: r
|
|
353
|
+
}
|
|
354
|
+
}, d = c ?? await Ie(), g = /* @__PURE__ */ new Map();
|
|
355
|
+
let G;
|
|
356
|
+
const ne = new Promise((y) => {
|
|
357
|
+
G = y;
|
|
358
|
+
});
|
|
359
|
+
let b = globalThis.crypto.randomUUID();
|
|
360
|
+
const w = (y, U) => {
|
|
361
|
+
const A = u(U);
|
|
362
|
+
ce(
|
|
363
|
+
y,
|
|
199
364
|
{
|
|
200
|
-
[
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
365
|
+
[M]: o,
|
|
366
|
+
name: t,
|
|
367
|
+
uuid: b,
|
|
368
|
+
...U
|
|
204
369
|
},
|
|
205
|
-
|
|
370
|
+
s,
|
|
371
|
+
A
|
|
206
372
|
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} else
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
373
|
+
}, se = async (y, U) => {
|
|
374
|
+
if (y.uuid !== b) {
|
|
375
|
+
if (!P(f))
|
|
376
|
+
throw new Error("Unidirectional receiving mode not implemented");
|
|
377
|
+
if (y.type === "announce") {
|
|
378
|
+
if (!y.remoteUuid) {
|
|
379
|
+
w(f, { type: "announce", remoteUuid: y.uuid });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (y.remoteUuid !== b) return;
|
|
383
|
+
if (g.has(y.uuid)) {
|
|
384
|
+
w(
|
|
385
|
+
f,
|
|
386
|
+
{ type: "reject-uuid-taken", remoteUuid: y.uuid }
|
|
387
|
+
);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const A = new ze(), X = {
|
|
391
|
+
type: "bidirectional",
|
|
392
|
+
eventTarget: A,
|
|
393
|
+
connection: Xe({
|
|
394
|
+
transport: f,
|
|
395
|
+
value: e,
|
|
396
|
+
uuid: b,
|
|
397
|
+
remoteUuid: y.uuid,
|
|
398
|
+
platformCapabilities: d,
|
|
399
|
+
eventTarget: A,
|
|
400
|
+
send: (R) => w(f, R),
|
|
401
|
+
close: () => void g.delete(y.uuid)
|
|
402
|
+
})
|
|
403
|
+
};
|
|
404
|
+
g.set(y.uuid, X), X.connection.remoteValue.then(
|
|
405
|
+
(R) => G(R)
|
|
406
|
+
);
|
|
407
|
+
} else if (y.type === "reject-uuid-taken") {
|
|
408
|
+
if (y.remoteUuid !== b) return;
|
|
409
|
+
b = globalThis.crypto.randomUUID(), w(f, { type: "announce" });
|
|
410
|
+
} else if (y.type === "close") {
|
|
411
|
+
if (y.remoteUuid !== b) return;
|
|
412
|
+
const A = g.get(y.uuid);
|
|
413
|
+
if (!A) {
|
|
414
|
+
console.warn(`Connection not found for remoteUuid: ${y.uuid}`);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
A.connection.close(), g.delete(y.uuid);
|
|
418
|
+
} else {
|
|
419
|
+
if (y.remoteUuid !== b) return;
|
|
420
|
+
const A = g.get(y.uuid);
|
|
421
|
+
if (!A) {
|
|
422
|
+
console.warn(`Connection not found for remoteUuid: ${y.uuid}`);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
A.type !== "unidirectional-emitting" && A.eventTarget.dispatchTypedEvent(
|
|
426
|
+
"message",
|
|
427
|
+
new CustomEvent("message", { detail: y })
|
|
428
|
+
);
|
|
256
429
|
}
|
|
257
430
|
}
|
|
258
|
-
}
|
|
259
|
-
|
|
431
|
+
};
|
|
432
|
+
if (F(f) && ie({
|
|
433
|
+
listener: se,
|
|
434
|
+
transport: f,
|
|
435
|
+
remoteName: n,
|
|
436
|
+
key: o,
|
|
437
|
+
unregisterSignal: a
|
|
438
|
+
}), P(f) && w(f, { type: "announce" }), P(f) && !F(f)) {
|
|
439
|
+
const { remoteValueProxy: y } = $e({
|
|
440
|
+
value: e,
|
|
441
|
+
uuid: b,
|
|
442
|
+
platformCapabilities: d,
|
|
443
|
+
send: (U) => w(f, U),
|
|
444
|
+
close: () => g.delete(b)
|
|
445
|
+
});
|
|
446
|
+
return y;
|
|
447
|
+
}
|
|
448
|
+
return ne;
|
|
260
449
|
};
|
|
261
450
|
export {
|
|
262
|
-
|
|
263
|
-
ee as expose,
|
|
264
|
-
Q as functionToProxiedFunction,
|
|
265
|
-
M as getTransferableObjects,
|
|
266
|
-
x as isClonable,
|
|
267
|
-
B as isTransferable,
|
|
268
|
-
v as makeAllocator,
|
|
269
|
-
Z as makeNumberAllocator,
|
|
270
|
-
F as messagePortToProxiedMessagePort,
|
|
271
|
-
J as promiseToProxiedPromise,
|
|
272
|
-
X as proxiedErrorToError,
|
|
273
|
-
K as proxiedFunctionToFunction,
|
|
274
|
-
W as proxiedMessagePortToMessagePort,
|
|
275
|
-
H as proxiedPromiseToPromise,
|
|
276
|
-
R as replaceIncomingProxiedTypes,
|
|
277
|
-
y as replaceOutgoingProxiedTypes,
|
|
278
|
-
O as replaceRecursive
|
|
451
|
+
He as expose
|
|
279
452
|
};
|
|
280
453
|
//# sourceMappingURL=index.js.map
|