osra 0.2.2 → 0.2.4

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