@kbve/droid 0.0.3 → 0.0.5
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 +16 -6
- package/{droid.es.js → droid.mjs} +1 -1
- package/index.js +2972 -0
- package/lib/workers/canvas-worker.js +303 -0
- package/lib/workers/db-worker.js +3639 -0
- package/lib/workers/ws-worker.js +274 -0
- package/package.json +13 -9
- package/workers/main.js +147 -147
- package/assets/canvas-worker-DbsoY2Xv.js +0 -5
- package/assets/db-worker-CjXS52DQ.js +0 -14
- package/assets/ws-worker-FssAQgaD.js +0 -5
- /package/{comlink-CC72iIUO.js → comlink.js} +0 -0
- /package/{reference-Dk_1njEH.js → reference.js} +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
const T = Symbol("Comlink.proxy"), N = Symbol("Comlink.endpoint"), H = Symbol("Comlink.releaseProxy"), k = Symbol("Comlink.finalizer"), h = Symbol("Comlink.thrown"), C = (e) => typeof e == "object" && e !== null || typeof e == "function", I = {
|
|
7
|
+
canHandle: (e) => C(e) && e[T],
|
|
8
|
+
serialize(e) {
|
|
9
|
+
const { port1: t, port2: n } = new MessageChannel();
|
|
10
|
+
return M(e, t), [n, [n]];
|
|
11
|
+
},
|
|
12
|
+
deserialize(e) {
|
|
13
|
+
return e.start(), D(e);
|
|
14
|
+
}
|
|
15
|
+
}, L = {
|
|
16
|
+
canHandle: (e) => C(e) && h in e,
|
|
17
|
+
serialize({ value: e }) {
|
|
18
|
+
let t;
|
|
19
|
+
return e instanceof Error ? t = {
|
|
20
|
+
isError: !0,
|
|
21
|
+
value: {
|
|
22
|
+
message: e.message,
|
|
23
|
+
name: e.name,
|
|
24
|
+
stack: e.stack
|
|
25
|
+
}
|
|
26
|
+
} : t = { isError: !1, value: e }, [t, []];
|
|
27
|
+
},
|
|
28
|
+
deserialize(e) {
|
|
29
|
+
throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
|
|
30
|
+
}
|
|
31
|
+
}, R = /* @__PURE__ */ new Map([
|
|
32
|
+
["proxy", I],
|
|
33
|
+
["throw", L]
|
|
34
|
+
]);
|
|
35
|
+
function V(e, t) {
|
|
36
|
+
for (const n of e)
|
|
37
|
+
if (t === n || n === "*" || n instanceof RegExp && n.test(t))
|
|
38
|
+
return !0;
|
|
39
|
+
return !1;
|
|
40
|
+
}
|
|
41
|
+
function M(e, t = globalThis, n = ["*"]) {
|
|
42
|
+
t.addEventListener("message", function y(r) {
|
|
43
|
+
if (!r || !r.data)
|
|
44
|
+
return;
|
|
45
|
+
if (!V(n, r.origin)) {
|
|
46
|
+
console.warn(`Invalid origin '${r.origin}' for comlink proxy`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { id: a, type: g, path: c } = Object.assign({ path: [] }, r.data), u = (r.data.argumentList || []).map(d);
|
|
50
|
+
let s;
|
|
51
|
+
try {
|
|
52
|
+
const o = c.slice(0, -1).reduce((i, w) => i[w], e), f = c.reduce((i, w) => i[w], e);
|
|
53
|
+
switch (g) {
|
|
54
|
+
case "GET":
|
|
55
|
+
s = f;
|
|
56
|
+
break;
|
|
57
|
+
case "SET":
|
|
58
|
+
o[c.slice(-1)[0]] = d(r.data.value), s = !0;
|
|
59
|
+
break;
|
|
60
|
+
case "APPLY":
|
|
61
|
+
s = f.apply(o, u);
|
|
62
|
+
break;
|
|
63
|
+
case "CONSTRUCT":
|
|
64
|
+
{
|
|
65
|
+
const i = new f(...u);
|
|
66
|
+
s = Y(i);
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case "ENDPOINT":
|
|
70
|
+
{
|
|
71
|
+
const { port1: i, port2: w } = new MessageChannel();
|
|
72
|
+
M(e, w), s = G(i, [i]);
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case "RELEASE":
|
|
76
|
+
s = void 0;
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
} catch (o) {
|
|
82
|
+
s = { value: o, [h]: 0 };
|
|
83
|
+
}
|
|
84
|
+
Promise.resolve(s).catch((o) => ({ value: o, [h]: 0 })).then((o) => {
|
|
85
|
+
const [f, i] = S(o);
|
|
86
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: a }), i), g === "RELEASE" && (t.removeEventListener("message", y), O(t), k in e && typeof e[k] == "function" && e[k]());
|
|
87
|
+
}).catch((o) => {
|
|
88
|
+
const [f, i] = S({
|
|
89
|
+
value: new TypeError("Unserializable return value"),
|
|
90
|
+
[h]: 0
|
|
91
|
+
});
|
|
92
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: a }), i);
|
|
93
|
+
});
|
|
94
|
+
}), t.start && t.start();
|
|
95
|
+
}
|
|
96
|
+
function _(e) {
|
|
97
|
+
return e.constructor.name === "MessagePort";
|
|
98
|
+
}
|
|
99
|
+
function O(e) {
|
|
100
|
+
_(e) && e.close();
|
|
101
|
+
}
|
|
102
|
+
function D(e, t) {
|
|
103
|
+
const n = /* @__PURE__ */ new Map();
|
|
104
|
+
return e.addEventListener("message", function(r) {
|
|
105
|
+
const { data: a } = r;
|
|
106
|
+
if (!a || !a.id)
|
|
107
|
+
return;
|
|
108
|
+
const g = n.get(a.id);
|
|
109
|
+
if (g)
|
|
110
|
+
try {
|
|
111
|
+
g(a);
|
|
112
|
+
} finally {
|
|
113
|
+
n.delete(a.id);
|
|
114
|
+
}
|
|
115
|
+
}), P(e, n, [], t);
|
|
116
|
+
}
|
|
117
|
+
function b(e) {
|
|
118
|
+
if (e)
|
|
119
|
+
throw new Error("Proxy has been released and is not useable");
|
|
120
|
+
}
|
|
121
|
+
function W(e) {
|
|
122
|
+
return m(e, /* @__PURE__ */ new Map(), {
|
|
123
|
+
type: "RELEASE"
|
|
124
|
+
}).then(() => {
|
|
125
|
+
O(e);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const E = /* @__PURE__ */ new WeakMap(), p = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
|
|
129
|
+
const t = (E.get(e) || 0) - 1;
|
|
130
|
+
E.set(e, t), t === 0 && W(e);
|
|
131
|
+
});
|
|
132
|
+
function F(e, t) {
|
|
133
|
+
const n = (E.get(t) || 0) + 1;
|
|
134
|
+
E.set(t, n), p && p.register(e, t, e);
|
|
135
|
+
}
|
|
136
|
+
function j(e) {
|
|
137
|
+
p && p.unregister(e);
|
|
138
|
+
}
|
|
139
|
+
function P(e, t, n = [], y = function() {
|
|
140
|
+
}) {
|
|
141
|
+
let r = !1;
|
|
142
|
+
const a = new Proxy(y, {
|
|
143
|
+
get(g, c) {
|
|
144
|
+
if (b(r), c === H)
|
|
145
|
+
return () => {
|
|
146
|
+
j(a), W(e), t.clear(), r = !0;
|
|
147
|
+
};
|
|
148
|
+
if (c === "then") {
|
|
149
|
+
if (n.length === 0)
|
|
150
|
+
return { then: () => a };
|
|
151
|
+
const u = m(e, t, {
|
|
152
|
+
type: "GET",
|
|
153
|
+
path: n.map((s) => s.toString())
|
|
154
|
+
}).then(d);
|
|
155
|
+
return u.then.bind(u);
|
|
156
|
+
}
|
|
157
|
+
return P(e, t, [...n, c]);
|
|
158
|
+
},
|
|
159
|
+
set(g, c, u) {
|
|
160
|
+
b(r);
|
|
161
|
+
const [s, o] = S(u);
|
|
162
|
+
return m(e, t, {
|
|
163
|
+
type: "SET",
|
|
164
|
+
path: [...n, c].map((f) => f.toString()),
|
|
165
|
+
value: s
|
|
166
|
+
}, o).then(d);
|
|
167
|
+
},
|
|
168
|
+
apply(g, c, u) {
|
|
169
|
+
b(r);
|
|
170
|
+
const s = n[n.length - 1];
|
|
171
|
+
if (s === N)
|
|
172
|
+
return m(e, t, {
|
|
173
|
+
type: "ENDPOINT"
|
|
174
|
+
}).then(d);
|
|
175
|
+
if (s === "bind")
|
|
176
|
+
return P(e, t, n.slice(0, -1));
|
|
177
|
+
const [o, f] = x(u);
|
|
178
|
+
return m(e, t, {
|
|
179
|
+
type: "APPLY",
|
|
180
|
+
path: n.map((i) => i.toString()),
|
|
181
|
+
argumentList: o
|
|
182
|
+
}, f).then(d);
|
|
183
|
+
},
|
|
184
|
+
construct(g, c) {
|
|
185
|
+
b(r);
|
|
186
|
+
const [u, s] = x(c);
|
|
187
|
+
return m(e, t, {
|
|
188
|
+
type: "CONSTRUCT",
|
|
189
|
+
path: n.map((o) => o.toString()),
|
|
190
|
+
argumentList: u
|
|
191
|
+
}, s).then(d);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return F(a, e), a;
|
|
195
|
+
}
|
|
196
|
+
function U(e) {
|
|
197
|
+
return Array.prototype.concat.apply([], e);
|
|
198
|
+
}
|
|
199
|
+
function x(e) {
|
|
200
|
+
const t = e.map(S);
|
|
201
|
+
return [t.map((n) => n[0]), U(t.map((n) => n[1]))];
|
|
202
|
+
}
|
|
203
|
+
const z = /* @__PURE__ */ new WeakMap();
|
|
204
|
+
function G(e, t) {
|
|
205
|
+
return z.set(e, t), e;
|
|
206
|
+
}
|
|
207
|
+
function Y(e) {
|
|
208
|
+
return Object.assign(e, { [T]: !0 });
|
|
209
|
+
}
|
|
210
|
+
function S(e) {
|
|
211
|
+
for (const [t, n] of R)
|
|
212
|
+
if (n.canHandle(e)) {
|
|
213
|
+
const [y, r] = n.serialize(e);
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
type: "HANDLER",
|
|
217
|
+
name: t,
|
|
218
|
+
value: y
|
|
219
|
+
},
|
|
220
|
+
r
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
return [
|
|
224
|
+
{
|
|
225
|
+
type: "RAW",
|
|
226
|
+
value: e
|
|
227
|
+
},
|
|
228
|
+
z.get(e) || []
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
function d(e) {
|
|
232
|
+
switch (e.type) {
|
|
233
|
+
case "HANDLER":
|
|
234
|
+
return R.get(e.name).deserialize(e.value);
|
|
235
|
+
case "RAW":
|
|
236
|
+
return e.value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function m(e, t, n, y) {
|
|
240
|
+
return new Promise((r) => {
|
|
241
|
+
const a = q();
|
|
242
|
+
t.set(a, r), e.start && e.start(), e.postMessage(Object.assign({ id: a }, n), y);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function q() {
|
|
246
|
+
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
|
+
}
|
|
248
|
+
let l = null, A = null;
|
|
249
|
+
const v = {
|
|
250
|
+
async connect(e) {
|
|
251
|
+
l || (l = new WebSocket(e), l.binaryType = "arraybuffer", l.onopen = () => console.log("[WS] Connected:", e), l.onmessage = (t) => {
|
|
252
|
+
try {
|
|
253
|
+
console.log("[WS] Received binary message"), t.data instanceof ArrayBuffer && A?.(t.data);
|
|
254
|
+
} catch (n) {
|
|
255
|
+
console.error("[WS] Failed to forward message", n);
|
|
256
|
+
}
|
|
257
|
+
}, l.onerror = (t) => console.error("[WS] Error:", t), l.onclose = () => {
|
|
258
|
+
console.log("[WS] Disconnected"), l = null;
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
async send(e) {
|
|
262
|
+
l?.readyState === WebSocket.OPEN ? l.send(e) : console.warn("[WS] Tried to send while disconnected");
|
|
263
|
+
},
|
|
264
|
+
async close() {
|
|
265
|
+
l?.close(), l = null;
|
|
266
|
+
},
|
|
267
|
+
onMessage(e) {
|
|
268
|
+
A = e;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
self.onconnect = (e) => {
|
|
272
|
+
const t = e.ports[0];
|
|
273
|
+
t.start(), M(v, t);
|
|
274
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kbve/droid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A manager for web, shared and service workers, aimming to make it as modular and upgradable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"workers",
|
|
@@ -17,24 +17,28 @@
|
|
|
17
17
|
"author": "KBVE <hello@kbve.com>",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"type": "module",
|
|
20
|
-
"main": "./droid.
|
|
21
|
-
"module": "./droid.
|
|
20
|
+
"main": "./droid.mjs",
|
|
21
|
+
"module": "./droid.mjs",
|
|
22
22
|
"types": "./index.d.ts",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"import": "./droid.
|
|
26
|
-
"require": "./droid.
|
|
27
|
-
}
|
|
25
|
+
"import": "./droid.mjs",
|
|
26
|
+
"require": "./droid.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./lib/workers/canvas-worker": "./lib/workers/canvas-worker.js",
|
|
29
|
+
"./lib/workers/db-worker": "./lib/workers/db-worker.js",
|
|
30
|
+
"./lib/workers/ws-worker": "./lib/workers/ws-worker.js"
|
|
28
31
|
},
|
|
29
32
|
"files": [
|
|
30
33
|
"workers/",
|
|
34
|
+
"lib/workers/",
|
|
31
35
|
"assets/",
|
|
32
36
|
"src/",
|
|
33
37
|
"comlink*.js",
|
|
34
|
-
"reference
|
|
35
|
-
"droid
|
|
38
|
+
"reference*.js",
|
|
39
|
+
"droid.mjs",
|
|
36
40
|
"main.js",
|
|
37
|
-
"index
|
|
41
|
+
"index.js",
|
|
38
42
|
"index.d.ts",
|
|
39
43
|
"*.md",
|
|
40
44
|
"LICENSE",
|