osra 0.2.0 → 0.2.2

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