@kbve/droid 0.0.2 → 0.0.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.
- package/README.md +17 -7
- package/comlink.js +253 -0
- package/package.json +8 -4
- package/src/index.ts +18 -0
- package/src/lib/droid.ts +5 -3
- package/src/lib/mod/mod-manager.ts +3 -2
- package/src/lib/workers/main.ts +256 -81
- package/workers/main.js +1091 -0
- 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/droid.cjs.js +0 -1
- package/droid.es.js +0 -14
- package/index-DSyyyiLP.js +0 -3034
- package/main-BYzQVPCs.js +0 -1455
package/workers/main.js
ADDED
|
@@ -0,0 +1,1091 @@
|
|
|
1
|
+
import { w as b, p as Z, t as tt } from "../comlink.js";
|
|
2
|
+
import { i as P, u as T, V as d, B as O, f as N, p as et, a as Y, t as it, b as j, c as st, d as ot, e as nt, g as rt, h as at, j as C } from "../reference.js";
|
|
3
|
+
import { z as k } from "../index.js";
|
|
4
|
+
let F = Symbol("clean"), y = [], lt = (e, t) => {
|
|
5
|
+
let i = [], s = {
|
|
6
|
+
get() {
|
|
7
|
+
return s.lc || s.listen(() => {
|
|
8
|
+
})(), s.value;
|
|
9
|
+
},
|
|
10
|
+
l: 0,
|
|
11
|
+
lc: 0,
|
|
12
|
+
listen(o, n) {
|
|
13
|
+
return s.lc = i.push(o, n || s.l) / 2, () => {
|
|
14
|
+
let r = i.indexOf(o);
|
|
15
|
+
~r && (i.splice(r, 2), --s.lc || s.off());
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
notify(o) {
|
|
19
|
+
let n = !y.length;
|
|
20
|
+
for (let r = 0; r < i.length; r += 2)
|
|
21
|
+
y.push(
|
|
22
|
+
i[r],
|
|
23
|
+
i[r + 1],
|
|
24
|
+
s.value,
|
|
25
|
+
o
|
|
26
|
+
);
|
|
27
|
+
if (n) {
|
|
28
|
+
for (let r = 0; r < y.length; r += 4) {
|
|
29
|
+
let h;
|
|
30
|
+
for (let c = r + 1; !h && (c += 4) < y.length; )
|
|
31
|
+
y[c] < y[r + 1] && (h = y.push(
|
|
32
|
+
y[r],
|
|
33
|
+
y[r + 1],
|
|
34
|
+
y[r + 2],
|
|
35
|
+
y[r + 3]
|
|
36
|
+
));
|
|
37
|
+
h || y[r](y[r + 2], y[r + 3]);
|
|
38
|
+
}
|
|
39
|
+
y.length = 0;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
off() {
|
|
43
|
+
},
|
|
44
|
+
/* It will be called on last listener unsubscribing.
|
|
45
|
+
We will redefine it in onMount and onStop. */
|
|
46
|
+
set(o) {
|
|
47
|
+
s.value !== o && (s.value = o, s.notify());
|
|
48
|
+
},
|
|
49
|
+
subscribe(o, n) {
|
|
50
|
+
let r = s.listen(o, n);
|
|
51
|
+
return o(s.value), r;
|
|
52
|
+
},
|
|
53
|
+
value: e
|
|
54
|
+
};
|
|
55
|
+
return process.env.NODE_ENV !== "production" && (s[F] = () => {
|
|
56
|
+
i = [], s.lc = 0, s.off();
|
|
57
|
+
}), s;
|
|
58
|
+
};
|
|
59
|
+
const ft = 5, S = 6, V = 10;
|
|
60
|
+
let ct = (e, t, i, s) => (e.events = e.events || {}, e.events[i + V] || (e.events[i + V] = s((o) => {
|
|
61
|
+
e.events[i].reduceRight((n, r) => (r(n), n), {
|
|
62
|
+
shared: {},
|
|
63
|
+
...o
|
|
64
|
+
});
|
|
65
|
+
})), e.events[i] = e.events[i] || [], e.events[i].push(t), () => {
|
|
66
|
+
let o = e.events[i], n = o.indexOf(t);
|
|
67
|
+
o.splice(n, 1), o.length || (delete e.events[i], e.events[i + V](), delete e.events[i + V]);
|
|
68
|
+
}), ht = 1e3, dt = (e, t) => ct(e, (s) => {
|
|
69
|
+
let o = t(s);
|
|
70
|
+
o && e.events[S].push(o);
|
|
71
|
+
}, ft, (s) => {
|
|
72
|
+
let o = e.listen;
|
|
73
|
+
e.listen = (...r) => (!e.lc && !e.active && (e.active = !0, s()), o(...r));
|
|
74
|
+
let n = e.off;
|
|
75
|
+
if (e.events[S] = [], e.off = () => {
|
|
76
|
+
n(), setTimeout(() => {
|
|
77
|
+
if (e.active && !e.lc) {
|
|
78
|
+
e.active = !1;
|
|
79
|
+
for (let r of e.events[S]) r();
|
|
80
|
+
e.events[S] = [];
|
|
81
|
+
}
|
|
82
|
+
}, ht);
|
|
83
|
+
}, process.env.NODE_ENV !== "production") {
|
|
84
|
+
let r = e[F];
|
|
85
|
+
e[F] = () => {
|
|
86
|
+
for (let h of e.events[S]) h();
|
|
87
|
+
e.events[S] = [], e.active = !1, r();
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return () => {
|
|
91
|
+
e.listen = o, e.off = n;
|
|
92
|
+
};
|
|
93
|
+
}), ut = (e = {}) => {
|
|
94
|
+
let t = lt(e);
|
|
95
|
+
return t.setKey = function(i, s) {
|
|
96
|
+
typeof s > "u" ? i in t.value && (t.value = { ...t.value }, delete t.value[i], t.notify(i)) : t.value[i] !== s && (t.value = {
|
|
97
|
+
...t.value,
|
|
98
|
+
[i]: s
|
|
99
|
+
}, t.notify(i));
|
|
100
|
+
}, t;
|
|
101
|
+
}, H = (e) => e, U = {}, v = { addEventListener() {
|
|
102
|
+
}, removeEventListener() {
|
|
103
|
+
} };
|
|
104
|
+
function wt() {
|
|
105
|
+
try {
|
|
106
|
+
return typeof localStorage < "u";
|
|
107
|
+
} catch {
|
|
108
|
+
return !1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
wt() && (U = localStorage);
|
|
112
|
+
let pt = {
|
|
113
|
+
addEventListener(e, t, i) {
|
|
114
|
+
window.addEventListener("storage", t), window.addEventListener("pageshow", i);
|
|
115
|
+
},
|
|
116
|
+
removeEventListener(e, t, i) {
|
|
117
|
+
window.removeEventListener("storage", t), window.removeEventListener("pageshow", i);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
typeof window < "u" && (v = pt);
|
|
121
|
+
function G(e, t = {}, i = {}) {
|
|
122
|
+
let s = i.encode || H, o = i.decode || H, n = ut(), r = n.setKey;
|
|
123
|
+
n.setKey = (a, l) => {
|
|
124
|
+
typeof l > "u" ? (i.listen !== !1 && v.perKey && v.removeEventListener(e + a, c, u), delete U[e + a]) : (i.listen !== !1 && v.perKey && !(a in n.value) && v.addEventListener(e + a, c, u), U[e + a] = s(l)), r(a, l);
|
|
125
|
+
};
|
|
126
|
+
let h = n.set;
|
|
127
|
+
n.set = function(a) {
|
|
128
|
+
for (let l in a)
|
|
129
|
+
n.setKey(l, a[l]);
|
|
130
|
+
for (let l in n.value)
|
|
131
|
+
l in a || n.setKey(l);
|
|
132
|
+
};
|
|
133
|
+
function c(a) {
|
|
134
|
+
a.key ? a.key.startsWith(e) && (a.newValue === null ? r(a.key.slice(e.length), void 0) : r(a.key.slice(e.length), o(a.newValue))) : h({});
|
|
135
|
+
}
|
|
136
|
+
function u() {
|
|
137
|
+
let a = { ...t };
|
|
138
|
+
for (let l in U)
|
|
139
|
+
l.startsWith(e) && (a[l.slice(e.length)] = o(U[l]));
|
|
140
|
+
n.set(a);
|
|
141
|
+
}
|
|
142
|
+
return dt(n, () => {
|
|
143
|
+
if (u(), i.listen !== !1)
|
|
144
|
+
return v.addEventListener(e, c, u), () => {
|
|
145
|
+
v.removeEventListener(e, c, u);
|
|
146
|
+
for (let a in n.value)
|
|
147
|
+
v.removeEventListener(e + a, c, u);
|
|
148
|
+
};
|
|
149
|
+
}), n;
|
|
150
|
+
}
|
|
151
|
+
async function kt(e, {
|
|
152
|
+
version: t,
|
|
153
|
+
i18nPath: i = "https://discord.sh/i18n/db.json",
|
|
154
|
+
locale: s = "en",
|
|
155
|
+
defaults: o = {
|
|
156
|
+
welcome: "Welcome to the app!"
|
|
157
|
+
}
|
|
158
|
+
}) {
|
|
159
|
+
console.log("[init-worker] Initializing database...");
|
|
160
|
+
try {
|
|
161
|
+
await e.loadI18nFromJSON(i), console.log(`[init-worker] i18n loaded from ${i}`), await e.dbSet("locale", s);
|
|
162
|
+
for (const [n, r] of Object.entries(o))
|
|
163
|
+
await e.dbSet(n, r);
|
|
164
|
+
await e.setVersion(t), e.loadServersFromJSON(), console.log(`[init-worker] DB initialized to version ${t}`);
|
|
165
|
+
} catch (n) {
|
|
166
|
+
console.error("[init-worker] Initialization failed:", n);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let W = null;
|
|
170
|
+
async function yt(e) {
|
|
171
|
+
if (W) return W;
|
|
172
|
+
const t = {};
|
|
173
|
+
async function i(r) {
|
|
174
|
+
const h = e?.(r) ?? r, c = new Worker(h, { type: "module" }), u = b(c), a = await u.getMeta?.() ?? {
|
|
175
|
+
name: "unknown",
|
|
176
|
+
version: "0.0.1"
|
|
177
|
+
}, l = `${a.name}@${a.version}`;
|
|
178
|
+
console.log(`[mod-manager] ${l} is loaded.`);
|
|
179
|
+
const f = { id: l, worker: c, instance: u, meta: a, url: r };
|
|
180
|
+
return t[l] = f, f;
|
|
181
|
+
}
|
|
182
|
+
function s(r) {
|
|
183
|
+
t[r] && (t[r].worker.terminate(), delete t[r]);
|
|
184
|
+
}
|
|
185
|
+
function o() {
|
|
186
|
+
return Object.values(t).map((r) => r.meta);
|
|
187
|
+
}
|
|
188
|
+
async function n(r) {
|
|
189
|
+
const h = t[r];
|
|
190
|
+
if (!h) throw new Error(`Mod "${r}" not found`);
|
|
191
|
+
return s(r), i(h.url);
|
|
192
|
+
}
|
|
193
|
+
return W = {
|
|
194
|
+
registry: t,
|
|
195
|
+
load: i,
|
|
196
|
+
unload: s,
|
|
197
|
+
list: o,
|
|
198
|
+
reload: n
|
|
199
|
+
}, W;
|
|
200
|
+
}
|
|
201
|
+
var E = /* @__PURE__ */ ((e) => (e[e.PAYLOAD_UNKNOWN = 0] = "PAYLOAD_UNKNOWN", e[e.JSON = 1] = "JSON", e[e.FLEX = 2] = "FLEX", e[e.PROTOBUF = 3] = "PROTOBUF", e[e.FLATBUFFER = 4] = "FLATBUFFER", e))(E || {}), m = /* @__PURE__ */ ((e) => (e[e.UNKNOWN = 0] = "UNKNOWN", e[e.ADD = 1] = "ADD", e[e.READ = 2] = "READ", e[e.GET = 4] = "GET", e[e.SET = 8] = "SET", e[e.DEL = 16] = "DEL", e[e.STREAM = 32] = "STREAM", e[e.GROUP = 64] = "GROUP", e[e.LIST = 128] = "LIST", e[e.ACTION = 256] = "ACTION", e[e.MESSAGE = 512] = "MESSAGE", e[e.INFO = 1024] = "INFO", e[e.DEBUG = 2048] = "DEBUG", e[e.ERROR = 4096] = "ERROR", e[e.AUTH = 8192] = "AUTH", e[e.HEARTBEAT = 16384] = "HEARTBEAT", e[e.CONFIG_UPDATE = 32768] = "CONFIG_UPDATE", e[e.REDIS = 65536] = "REDIS", e[e.SUPABASE = 131072] = "SUPABASE", e[e.FILESYSTEM = 262144] = "FILESYSTEM", e[e.WEBSOCKET = 524288] = "WEBSOCKET", e[e.HTTP_API = 1048576] = "HTTP_API", e[e.LOCAL_CACHE = 2097152] = "LOCAL_CACHE", e[e.AI = 4194304] = "AI", e))(m || {});
|
|
202
|
+
class R {
|
|
203
|
+
constructor(t, i, s, o = null, n = 0) {
|
|
204
|
+
this.builder = t, this.type = i, this.width = s, this.value = o, this.offset = n;
|
|
205
|
+
}
|
|
206
|
+
elementWidth(t, i) {
|
|
207
|
+
if (P(this.type)) return this.width;
|
|
208
|
+
for (let s = 0; s < 4; s++) {
|
|
209
|
+
const o = 1 << s, r = t + Y(t, o) + i * o - this.offset, h = T(r);
|
|
210
|
+
if (1 << h === o)
|
|
211
|
+
return h;
|
|
212
|
+
}
|
|
213
|
+
throw `Element is unknown. Size: ${t} at index: ${i}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
|
|
214
|
+
}
|
|
215
|
+
writeToBuffer(t) {
|
|
216
|
+
const i = this.builder.computeOffset(t);
|
|
217
|
+
if (this.type === d.FLOAT)
|
|
218
|
+
this.width === O.WIDTH32 ? this.builder.view.setFloat32(this.builder.offset, this.value, !0) : this.builder.view.setFloat64(this.builder.offset, this.value, !0);
|
|
219
|
+
else if (this.type === d.INT) {
|
|
220
|
+
const s = N(t);
|
|
221
|
+
this.builder.pushInt(this.value, s);
|
|
222
|
+
} else if (this.type === d.UINT) {
|
|
223
|
+
const s = N(t);
|
|
224
|
+
this.builder.pushUInt(this.value, s);
|
|
225
|
+
} else if (this.type === d.NULL)
|
|
226
|
+
this.builder.pushInt(0, this.width);
|
|
227
|
+
else if (this.type === d.BOOL)
|
|
228
|
+
this.builder.pushInt(this.value ? 1 : 0, this.width);
|
|
229
|
+
else
|
|
230
|
+
throw `Unexpected type: ${this.type}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
|
|
231
|
+
this.offset = i;
|
|
232
|
+
}
|
|
233
|
+
storedWidth(t = O.WIDTH8) {
|
|
234
|
+
return P(this.type) ? Math.max(t, this.width) : this.width;
|
|
235
|
+
}
|
|
236
|
+
storedPackedType(t = O.WIDTH8) {
|
|
237
|
+
return et(this.type, this.storedWidth(t));
|
|
238
|
+
}
|
|
239
|
+
isOffset() {
|
|
240
|
+
return !P(this.type);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
class mt {
|
|
244
|
+
constructor(t = 2048, i = !0, s = !0, o = !0) {
|
|
245
|
+
this.dedupStrings = i, this.dedupKeys = s, this.dedupKeyVectors = o, this.stack = [], this.stackPointers = [], this.offset = 0, this.finished = !1, this.stringLookup = {}, this.keyLookup = {}, this.keyVectorLookup = {}, this.indirectIntLookup = {}, this.indirectUIntLookup = {}, this.indirectFloatLookup = {}, this.buffer = new ArrayBuffer(t > 0 ? t : 2048), this.view = new DataView(this.buffer);
|
|
246
|
+
}
|
|
247
|
+
align(t) {
|
|
248
|
+
const i = it(t);
|
|
249
|
+
return this.offset += Y(this.offset, i), i;
|
|
250
|
+
}
|
|
251
|
+
computeOffset(t) {
|
|
252
|
+
const i = this.offset + t;
|
|
253
|
+
let s = this.buffer.byteLength;
|
|
254
|
+
const o = s;
|
|
255
|
+
for (; s < i; )
|
|
256
|
+
s <<= 1;
|
|
257
|
+
if (o < s) {
|
|
258
|
+
const n = this.buffer;
|
|
259
|
+
this.buffer = new ArrayBuffer(s), this.view = new DataView(this.buffer), new Uint8Array(this.buffer).set(new Uint8Array(n), 0);
|
|
260
|
+
}
|
|
261
|
+
return i;
|
|
262
|
+
}
|
|
263
|
+
pushInt(t, i) {
|
|
264
|
+
if (i === O.WIDTH8)
|
|
265
|
+
this.view.setInt8(this.offset, t);
|
|
266
|
+
else if (i === O.WIDTH16)
|
|
267
|
+
this.view.setInt16(this.offset, t, !0);
|
|
268
|
+
else if (i === O.WIDTH32)
|
|
269
|
+
this.view.setInt32(this.offset, t, !0);
|
|
270
|
+
else if (i === O.WIDTH64)
|
|
271
|
+
this.view.setBigInt64(this.offset, BigInt(t), !0);
|
|
272
|
+
else
|
|
273
|
+
throw `Unexpected width: ${i} for value: ${t}`;
|
|
274
|
+
}
|
|
275
|
+
pushUInt(t, i) {
|
|
276
|
+
if (i === O.WIDTH8)
|
|
277
|
+
this.view.setUint8(this.offset, t);
|
|
278
|
+
else if (i === O.WIDTH16)
|
|
279
|
+
this.view.setUint16(this.offset, t, !0);
|
|
280
|
+
else if (i === O.WIDTH32)
|
|
281
|
+
this.view.setUint32(this.offset, t, !0);
|
|
282
|
+
else if (i === O.WIDTH64)
|
|
283
|
+
this.view.setBigUint64(this.offset, BigInt(t), !0);
|
|
284
|
+
else
|
|
285
|
+
throw `Unexpected width: ${i} for value: ${t}`;
|
|
286
|
+
}
|
|
287
|
+
writeInt(t, i) {
|
|
288
|
+
const s = this.computeOffset(i);
|
|
289
|
+
this.pushInt(t, N(i)), this.offset = s;
|
|
290
|
+
}
|
|
291
|
+
writeUInt(t, i) {
|
|
292
|
+
const s = this.computeOffset(i);
|
|
293
|
+
this.pushUInt(t, N(i)), this.offset = s;
|
|
294
|
+
}
|
|
295
|
+
writeBlob(t) {
|
|
296
|
+
const i = t.byteLength, s = T(i), o = this.align(s);
|
|
297
|
+
this.writeUInt(i, o);
|
|
298
|
+
const n = this.offset, r = this.computeOffset(i);
|
|
299
|
+
new Uint8Array(this.buffer).set(new Uint8Array(t), n), this.stack.push(this.offsetStackValue(n, d.BLOB, s)), this.offset = r;
|
|
300
|
+
}
|
|
301
|
+
writeString(t) {
|
|
302
|
+
if (this.dedupStrings && Object.prototype.hasOwnProperty.call(this.stringLookup, t)) {
|
|
303
|
+
this.stack.push(this.stringLookup[t]);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const i = j(t), s = i.length, o = T(s), n = this.align(o);
|
|
307
|
+
this.writeUInt(s, n);
|
|
308
|
+
const r = this.offset, h = this.computeOffset(s + 1);
|
|
309
|
+
new Uint8Array(this.buffer).set(i, r);
|
|
310
|
+
const c = this.offsetStackValue(r, d.STRING, o);
|
|
311
|
+
this.stack.push(c), this.dedupStrings && (this.stringLookup[t] = c), this.offset = h;
|
|
312
|
+
}
|
|
313
|
+
writeKey(t) {
|
|
314
|
+
if (this.dedupKeys && Object.prototype.hasOwnProperty.call(this.keyLookup, t)) {
|
|
315
|
+
this.stack.push(this.keyLookup[t]);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const i = j(t), s = i.length, o = this.computeOffset(s + 1);
|
|
319
|
+
new Uint8Array(this.buffer).set(i, this.offset);
|
|
320
|
+
const n = this.offsetStackValue(this.offset, d.KEY, O.WIDTH8);
|
|
321
|
+
this.stack.push(n), this.dedupKeys && (this.keyLookup[t] = n), this.offset = o;
|
|
322
|
+
}
|
|
323
|
+
writeStackValue(t, i) {
|
|
324
|
+
const s = this.computeOffset(i);
|
|
325
|
+
if (t.isOffset()) {
|
|
326
|
+
const o = this.offset - t.offset;
|
|
327
|
+
if (i === 8 || BigInt(o) < BigInt(1) << BigInt(i * 8))
|
|
328
|
+
this.writeUInt(o, i);
|
|
329
|
+
else
|
|
330
|
+
throw `Unexpected size ${i}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
|
|
331
|
+
} else
|
|
332
|
+
t.writeToBuffer(i);
|
|
333
|
+
this.offset = s;
|
|
334
|
+
}
|
|
335
|
+
integrityCheckOnValueAddition() {
|
|
336
|
+
if (this.finished)
|
|
337
|
+
throw "Adding values after finish is prohibited";
|
|
338
|
+
if (this.stackPointers.length !== 0 && this.stackPointers[this.stackPointers.length - 1].isVector === !1 && this.stack[this.stack.length - 1].type !== d.KEY)
|
|
339
|
+
throw "Adding value to a map before adding a key is prohibited";
|
|
340
|
+
}
|
|
341
|
+
integrityCheckOnKeyAddition() {
|
|
342
|
+
if (this.finished)
|
|
343
|
+
throw "Adding values after finish is prohibited";
|
|
344
|
+
if (this.stackPointers.length === 0 || this.stackPointers[this.stackPointers.length - 1].isVector)
|
|
345
|
+
throw "Adding key before starting a map is prohibited";
|
|
346
|
+
}
|
|
347
|
+
startVector() {
|
|
348
|
+
this.stackPointers.push({ stackPosition: this.stack.length, isVector: !0 });
|
|
349
|
+
}
|
|
350
|
+
startMap(t = !1) {
|
|
351
|
+
this.stackPointers.push({ stackPosition: this.stack.length, isVector: !1, presorted: t });
|
|
352
|
+
}
|
|
353
|
+
endVector(t) {
|
|
354
|
+
const i = this.stack.length - t.stackPosition, s = this.createVector(t.stackPosition, i, 1);
|
|
355
|
+
this.stack.splice(t.stackPosition, i), this.stack.push(s);
|
|
356
|
+
}
|
|
357
|
+
endMap(t) {
|
|
358
|
+
t.presorted || this.sort(t);
|
|
359
|
+
let i = "";
|
|
360
|
+
for (let r = t.stackPosition; r < this.stack.length; r += 2)
|
|
361
|
+
i += `,${this.stack[r].offset}`;
|
|
362
|
+
const s = this.stack.length - t.stackPosition >> 1;
|
|
363
|
+
this.dedupKeyVectors && !Object.prototype.hasOwnProperty.call(this.keyVectorLookup, i) && (this.keyVectorLookup[i] = this.createVector(t.stackPosition, s, 2));
|
|
364
|
+
const o = this.dedupKeyVectors ? this.keyVectorLookup[i] : this.createVector(t.stackPosition, s, 2), n = this.createVector(t.stackPosition + 1, s, 2, o);
|
|
365
|
+
this.stack.splice(t.stackPosition, s << 1), this.stack.push(n);
|
|
366
|
+
}
|
|
367
|
+
sort(t) {
|
|
368
|
+
const i = this.view, s = this.stack;
|
|
369
|
+
function o(a, l) {
|
|
370
|
+
if (a.type !== d.KEY || l.type !== d.KEY)
|
|
371
|
+
throw `Stack values are not keys ${a} | ${l}. Check if you combined [addKey] with add... method calls properly.`;
|
|
372
|
+
let f, w, p = 0;
|
|
373
|
+
do {
|
|
374
|
+
if (f = i.getUint8(a.offset + p), w = i.getUint8(l.offset + p), w < f) return !0;
|
|
375
|
+
if (f < w) return !1;
|
|
376
|
+
p += 1;
|
|
377
|
+
} while (f !== 0 && w !== 0);
|
|
378
|
+
return !1;
|
|
379
|
+
}
|
|
380
|
+
function n(a, l, f) {
|
|
381
|
+
if (l === f) return;
|
|
382
|
+
const w = a[l], p = a[l + 1];
|
|
383
|
+
a[l] = a[f], a[l + 1] = a[f + 1], a[f] = w, a[f + 1] = p;
|
|
384
|
+
}
|
|
385
|
+
function r() {
|
|
386
|
+
for (let a = t.stackPosition; a < s.length; a += 2) {
|
|
387
|
+
let l = a;
|
|
388
|
+
for (let f = a + 2; f < s.length; f += 2)
|
|
389
|
+
o(s[l], s[f]) && (l = f);
|
|
390
|
+
l !== a && n(s, l, a);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function h(a, l) {
|
|
394
|
+
if (a.type !== d.KEY || l.type !== d.KEY)
|
|
395
|
+
throw `Stack values are not keys ${a} | ${l}. Check if you combined [addKey] with add... method calls properly.`;
|
|
396
|
+
if (a.offset === l.offset)
|
|
397
|
+
return !1;
|
|
398
|
+
let f, w, p = 0;
|
|
399
|
+
do {
|
|
400
|
+
if (f = i.getUint8(a.offset + p), w = i.getUint8(l.offset + p), f < w) return !0;
|
|
401
|
+
if (w < f) return !1;
|
|
402
|
+
p += 1;
|
|
403
|
+
} while (f !== 0 && w !== 0);
|
|
404
|
+
return !1;
|
|
405
|
+
}
|
|
406
|
+
function c(a, l) {
|
|
407
|
+
if (a < l) {
|
|
408
|
+
const f = a + (l - a >> 2) * 2, w = s[f];
|
|
409
|
+
let p = a, I = l;
|
|
410
|
+
do {
|
|
411
|
+
for (; h(s[p], w); )
|
|
412
|
+
p += 2;
|
|
413
|
+
for (; h(w, s[I]); )
|
|
414
|
+
I -= 2;
|
|
415
|
+
p <= I && (n(s, p, I), p += 2, I -= 2);
|
|
416
|
+
} while (p <= I);
|
|
417
|
+
c(a, I), c(p, l);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
let u = !0;
|
|
421
|
+
for (let a = t.stackPosition; a < this.stack.length - 2; a += 2)
|
|
422
|
+
if (o(this.stack[a], this.stack[a + 2])) {
|
|
423
|
+
u = !1;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
u || (this.stack.length - t.stackPosition > 40 ? c(t.stackPosition, this.stack.length - 2) : r());
|
|
427
|
+
}
|
|
428
|
+
end() {
|
|
429
|
+
if (this.stackPointers.length < 1) return;
|
|
430
|
+
const t = this.stackPointers.pop();
|
|
431
|
+
t.isVector ? this.endVector(t) : this.endMap(t);
|
|
432
|
+
}
|
|
433
|
+
createVector(t, i, s, o = null) {
|
|
434
|
+
let n = T(i), r = 1;
|
|
435
|
+
if (o !== null) {
|
|
436
|
+
const f = o.elementWidth(this.offset, 0);
|
|
437
|
+
f > n && (n = f), r += 2;
|
|
438
|
+
}
|
|
439
|
+
let h = d.KEY, c = o === null;
|
|
440
|
+
for (let f = t; f < this.stack.length; f += s) {
|
|
441
|
+
const w = this.stack[f].elementWidth(this.offset, f + r);
|
|
442
|
+
w > n && (n = w), f === t ? (h = this.stack[f].type, c = c && st(h)) : h !== this.stack[f].type && (c = !1);
|
|
443
|
+
}
|
|
444
|
+
const u = this.align(n), a = c && ot(h) && i >= 2 && i <= 4;
|
|
445
|
+
o !== null && (this.writeStackValue(o, u), this.writeUInt(1 << o.width, u)), a || this.writeUInt(i, u);
|
|
446
|
+
const l = this.offset;
|
|
447
|
+
for (let f = t; f < this.stack.length; f += s)
|
|
448
|
+
this.writeStackValue(this.stack[f], u);
|
|
449
|
+
if (!c)
|
|
450
|
+
for (let f = t; f < this.stack.length; f += s)
|
|
451
|
+
this.writeUInt(this.stack[f].storedPackedType(), 1);
|
|
452
|
+
if (o !== null)
|
|
453
|
+
return this.offsetStackValue(l, d.MAP, n);
|
|
454
|
+
if (c) {
|
|
455
|
+
const f = nt(h, a ? i : 0);
|
|
456
|
+
return this.offsetStackValue(l, f, n);
|
|
457
|
+
}
|
|
458
|
+
return this.offsetStackValue(l, d.VECTOR, n);
|
|
459
|
+
}
|
|
460
|
+
nullStackValue() {
|
|
461
|
+
return new R(this, d.NULL, O.WIDTH8);
|
|
462
|
+
}
|
|
463
|
+
boolStackValue(t) {
|
|
464
|
+
return new R(this, d.BOOL, O.WIDTH8, t);
|
|
465
|
+
}
|
|
466
|
+
intStackValue(t) {
|
|
467
|
+
return new R(this, d.INT, rt(t), t);
|
|
468
|
+
}
|
|
469
|
+
uintStackValue(t) {
|
|
470
|
+
return new R(this, d.UINT, T(t), t);
|
|
471
|
+
}
|
|
472
|
+
floatStackValue(t) {
|
|
473
|
+
return new R(this, d.FLOAT, at(t), t);
|
|
474
|
+
}
|
|
475
|
+
offsetStackValue(t, i, s) {
|
|
476
|
+
return new R(this, i, s, null, t);
|
|
477
|
+
}
|
|
478
|
+
finishBuffer() {
|
|
479
|
+
if (this.stack.length !== 1)
|
|
480
|
+
throw `Stack has to be exactly 1, but it is ${this.stack.length}. You have to end all started vectors and maps before calling [finish]`;
|
|
481
|
+
const t = this.stack[0], i = this.align(t.elementWidth(this.offset, 0));
|
|
482
|
+
this.writeStackValue(t, i), this.writeUInt(t.storedPackedType(), 1), this.writeUInt(i, 1), this.finished = !0;
|
|
483
|
+
}
|
|
484
|
+
add(t) {
|
|
485
|
+
if (this.integrityCheckOnValueAddition(), typeof t > "u")
|
|
486
|
+
throw "You need to provide a value";
|
|
487
|
+
if (t === null)
|
|
488
|
+
this.stack.push(this.nullStackValue());
|
|
489
|
+
else if (typeof t == "boolean")
|
|
490
|
+
this.stack.push(this.boolStackValue(t));
|
|
491
|
+
else if (typeof t == "bigint")
|
|
492
|
+
this.stack.push(this.intStackValue(t));
|
|
493
|
+
else if (typeof t == "number")
|
|
494
|
+
Number.isInteger(t) ? this.stack.push(this.intStackValue(t)) : this.stack.push(this.floatStackValue(t));
|
|
495
|
+
else if (ArrayBuffer.isView(t))
|
|
496
|
+
this.writeBlob(t.buffer);
|
|
497
|
+
else if (typeof t == "string" || t instanceof String)
|
|
498
|
+
this.writeString(t);
|
|
499
|
+
else if (Array.isArray(t)) {
|
|
500
|
+
this.startVector();
|
|
501
|
+
for (let i = 0; i < t.length; i++)
|
|
502
|
+
this.add(t[i]);
|
|
503
|
+
this.end();
|
|
504
|
+
} else if (typeof t == "object") {
|
|
505
|
+
const i = Object.getOwnPropertyNames(t).sort();
|
|
506
|
+
this.startMap(!0);
|
|
507
|
+
for (let s = 0; s < i.length; s++) {
|
|
508
|
+
const o = i[s];
|
|
509
|
+
this.addKey(o), this.add(t[o]);
|
|
510
|
+
}
|
|
511
|
+
this.end();
|
|
512
|
+
} else
|
|
513
|
+
throw `Unexpected value input ${t}`;
|
|
514
|
+
}
|
|
515
|
+
finish() {
|
|
516
|
+
this.finished || this.finishBuffer();
|
|
517
|
+
const t = this.buffer.slice(0, this.offset);
|
|
518
|
+
return new Uint8Array(t);
|
|
519
|
+
}
|
|
520
|
+
isFinished() {
|
|
521
|
+
return this.finished;
|
|
522
|
+
}
|
|
523
|
+
addKey(t) {
|
|
524
|
+
this.integrityCheckOnKeyAddition(), this.writeKey(t);
|
|
525
|
+
}
|
|
526
|
+
addInt(t, i = !1, s = !1) {
|
|
527
|
+
if (this.integrityCheckOnValueAddition(), !i) {
|
|
528
|
+
this.stack.push(this.intStackValue(t));
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (s && Object.prototype.hasOwnProperty.call(this.indirectIntLookup, t)) {
|
|
532
|
+
this.stack.push(this.indirectIntLookup[t]);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const o = this.intStackValue(t), n = this.align(o.width), r = this.computeOffset(n), h = this.offset;
|
|
536
|
+
o.writeToBuffer(n);
|
|
537
|
+
const c = this.offsetStackValue(h, d.INDIRECT_INT, o.width);
|
|
538
|
+
this.stack.push(c), this.offset = r, s && (this.indirectIntLookup[t] = c);
|
|
539
|
+
}
|
|
540
|
+
addUInt(t, i = !1, s = !1) {
|
|
541
|
+
if (this.integrityCheckOnValueAddition(), !i) {
|
|
542
|
+
this.stack.push(this.uintStackValue(t));
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (s && Object.prototype.hasOwnProperty.call(this.indirectUIntLookup, t)) {
|
|
546
|
+
this.stack.push(this.indirectUIntLookup[t]);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const o = this.uintStackValue(t), n = this.align(o.width), r = this.computeOffset(n), h = this.offset;
|
|
550
|
+
o.writeToBuffer(n);
|
|
551
|
+
const c = this.offsetStackValue(h, d.INDIRECT_UINT, o.width);
|
|
552
|
+
this.stack.push(c), this.offset = r, s && (this.indirectUIntLookup[t] = c);
|
|
553
|
+
}
|
|
554
|
+
addFloat(t, i = !1, s = !1) {
|
|
555
|
+
if (this.integrityCheckOnValueAddition(), !i) {
|
|
556
|
+
this.stack.push(this.floatStackValue(t));
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (s && Object.prototype.hasOwnProperty.call(this.indirectFloatLookup, t)) {
|
|
560
|
+
this.stack.push(this.indirectFloatLookup[t]);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const o = this.floatStackValue(t), n = this.align(o.width), r = this.computeOffset(n), h = this.offset;
|
|
564
|
+
o.writeToBuffer(n);
|
|
565
|
+
const c = this.offsetStackValue(h, d.INDIRECT_FLOAT, o.width);
|
|
566
|
+
this.stack.push(c), this.offset = r, s && (this.indirectFloatLookup[t] = c);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function B() {
|
|
570
|
+
return new mt();
|
|
571
|
+
}
|
|
572
|
+
function gt(e) {
|
|
573
|
+
const t = B();
|
|
574
|
+
t.startMap();
|
|
575
|
+
for (const [i, s] of Object.entries(e))
|
|
576
|
+
t.addKey(i), t.add(s);
|
|
577
|
+
return t.end(), t.finish();
|
|
578
|
+
}
|
|
579
|
+
function A(e, t, i, s, o = 1) {
|
|
580
|
+
let n;
|
|
581
|
+
if (i === E.FLEX)
|
|
582
|
+
n = gt(e);
|
|
583
|
+
else if (i === E.JSON)
|
|
584
|
+
n = new TextEncoder().encode(JSON.stringify(e));
|
|
585
|
+
else
|
|
586
|
+
throw new Error("Unsupported format for wrapEnvelope");
|
|
587
|
+
const r = B();
|
|
588
|
+
return r.startMap(), r.addKey("version"), r.add(o), r.addKey("kind"), r.add(t), r.addKey("format"), r.add(i), r.addKey("payload"), r.add(n), r.addKey("metadata"), r.add(s ?? new Uint8Array()), r.end(), r.finish();
|
|
589
|
+
}
|
|
590
|
+
function J(e) {
|
|
591
|
+
const t = e instanceof Uint8Array ? e : new Uint8Array(e), i = C(t.buffer).toObject();
|
|
592
|
+
if (typeof i.version != "number" || typeof i.kind != "number" || typeof i.format != "number" || !i.payload)
|
|
593
|
+
throw console.error("[unwrapEnvelope] Bad root:", i), new Error("[unwrapEnvelope] Invalid envelope structure");
|
|
594
|
+
const s = {
|
|
595
|
+
version: i.version,
|
|
596
|
+
kind: i.kind,
|
|
597
|
+
format: i.format,
|
|
598
|
+
payload: new Uint8Array(i.payload),
|
|
599
|
+
metadata: i.metadata ? new Uint8Array(i.metadata) : void 0
|
|
600
|
+
};
|
|
601
|
+
let o;
|
|
602
|
+
if (s.format === E.FLEX)
|
|
603
|
+
o = C(s.payload.buffer).toObject();
|
|
604
|
+
else if (s.format === E.JSON)
|
|
605
|
+
o = JSON.parse(new TextDecoder().decode(s.payload));
|
|
606
|
+
else
|
|
607
|
+
throw new Error(`[unwrapEnvelope] Unsupported format: ${s.format}`);
|
|
608
|
+
return { envelope: s, payload: o };
|
|
609
|
+
}
|
|
610
|
+
function X(e) {
|
|
611
|
+
return C(e.buffer).toObject();
|
|
612
|
+
}
|
|
613
|
+
function Ot(e) {
|
|
614
|
+
try {
|
|
615
|
+
const t = e instanceof Uint8Array ? e : new Uint8Array(e), i = X(t);
|
|
616
|
+
console.log("[FlexObject]", JSON.stringify(i, null, 2));
|
|
617
|
+
} catch (t) {
|
|
618
|
+
console.error("[Flex Decode Error]", t);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function $(e, t) {
|
|
622
|
+
return (e & t) === t;
|
|
623
|
+
}
|
|
624
|
+
function bt(e, t) {
|
|
625
|
+
return A(
|
|
626
|
+
{ key: e, value: t },
|
|
627
|
+
m.SET | m.REDIS,
|
|
628
|
+
E.FLEX
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
function Et(e) {
|
|
632
|
+
return A(
|
|
633
|
+
{ key: e },
|
|
634
|
+
m.GET | m.REDIS,
|
|
635
|
+
E.FLEX
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
function vt(e) {
|
|
639
|
+
return A(
|
|
640
|
+
{ key: e },
|
|
641
|
+
m.DEL | m.REDIS,
|
|
642
|
+
E.FLEX
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
function It(e) {
|
|
646
|
+
const t = J(e);
|
|
647
|
+
if (!$(t.envelope.kind, m.REDIS))
|
|
648
|
+
throw new Error("[Redis] Not a Redis envelope");
|
|
649
|
+
return t;
|
|
650
|
+
}
|
|
651
|
+
function St(e, t, i = "*") {
|
|
652
|
+
return A(
|
|
653
|
+
{ stream: e, id: i, fields: t },
|
|
654
|
+
m.ADD | m.STREAM | m.REDIS,
|
|
655
|
+
E.FLEX
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
function Rt(e, t, i) {
|
|
659
|
+
const s = B();
|
|
660
|
+
s.startMap(), s.addKey("streams"), s.startVector();
|
|
661
|
+
for (const { stream: r, id: h } of e)
|
|
662
|
+
s.startMap(), s.addKey("stream"), s.add(r), s.addKey("id"), s.add(h), s.end();
|
|
663
|
+
s.end(), t !== void 0 && (s.addKey("count"), s.add(t)), i !== void 0 && (s.addKey("block"), s.add(i)), s.end();
|
|
664
|
+
const o = s.finish(), n = B();
|
|
665
|
+
return n.startMap(), n.addKey("version"), n.add(1), n.addKey("kind"), n.add(m.READ | m.STREAM | m.REDIS), n.addKey("format"), n.add(E.FLEX), n.addKey("payload"), n.add(o), n.addKey("metadata"), n.add(new Uint8Array()), n.end(), n.finish();
|
|
666
|
+
}
|
|
667
|
+
const Dt = {
|
|
668
|
+
wrapEnvelope: A,
|
|
669
|
+
unwrapEnvelope: J,
|
|
670
|
+
MessageKind: m,
|
|
671
|
+
PayloadFormat: E,
|
|
672
|
+
unwrapFlexToJson: X,
|
|
673
|
+
inspectFlex: Ot,
|
|
674
|
+
hasKind: $,
|
|
675
|
+
redis: {
|
|
676
|
+
wrapRedisSet: bt,
|
|
677
|
+
wrapRedisGet: Et,
|
|
678
|
+
wrapRedisDel: vt,
|
|
679
|
+
wrapRedisXAdd: St,
|
|
680
|
+
wrapRedisXRead: Rt,
|
|
681
|
+
parseRedisPayload: It
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
function q(e) {
|
|
685
|
+
typeof queueMicrotask == "function" ? queueMicrotask(e) : setTimeout(e, 0);
|
|
686
|
+
}
|
|
687
|
+
function Q(e) {
|
|
688
|
+
const t = document.createElement(e.tag);
|
|
689
|
+
if (e.class && (t.className = e.class), e.attrs)
|
|
690
|
+
for (const [i, s] of Object.entries(e.attrs))
|
|
691
|
+
if (typeof s == "function" && i.startsWith("on"))
|
|
692
|
+
t.addEventListener(i.slice(2).toLowerCase(), s);
|
|
693
|
+
else if (i === "style" && typeof s == "object")
|
|
694
|
+
Object.assign(t.style, s);
|
|
695
|
+
else if (i === "dataset" && typeof s == "object")
|
|
696
|
+
for (const [o, n] of Object.entries(s))
|
|
697
|
+
t.dataset[o] = String(n);
|
|
698
|
+
else
|
|
699
|
+
try {
|
|
700
|
+
t.setAttribute(i, String(s));
|
|
701
|
+
} catch {
|
|
702
|
+
}
|
|
703
|
+
if (e.style && Object.assign(t.style, e.style), e.children)
|
|
704
|
+
for (const i of e.children) {
|
|
705
|
+
const s = typeof i == "string" ? document.createTextNode(i) : Q(i);
|
|
706
|
+
t.appendChild(s);
|
|
707
|
+
}
|
|
708
|
+
return t;
|
|
709
|
+
}
|
|
710
|
+
const Lt = k.enum(["top", "right", "bottom", "left"]), Tt = k.object({
|
|
711
|
+
width: k.number(),
|
|
712
|
+
height: k.number(),
|
|
713
|
+
mode: k.enum(["static", "animated", "dynamic"]).optional()
|
|
714
|
+
});
|
|
715
|
+
k.object({
|
|
716
|
+
rawHtml: k.string().optional(),
|
|
717
|
+
needsCanvas: k.boolean().optional(),
|
|
718
|
+
canvasOptions: Tt.optional()
|
|
719
|
+
});
|
|
720
|
+
const Ut = k.object({
|
|
721
|
+
name: k.string(),
|
|
722
|
+
version: k.string().optional()
|
|
723
|
+
}), At = k.object({
|
|
724
|
+
meta: Ut.optional(),
|
|
725
|
+
timestamp: k.number()
|
|
726
|
+
}), _ = k.object({
|
|
727
|
+
id: Lt,
|
|
728
|
+
payload: k.any().optional()
|
|
729
|
+
}), Vt = k.object({
|
|
730
|
+
timestamp: k.number()
|
|
731
|
+
}), Wt = {
|
|
732
|
+
"droid-ready": Vt,
|
|
733
|
+
"droid-mod-ready": At,
|
|
734
|
+
"panel-open": _,
|
|
735
|
+
"panel-close": _
|
|
736
|
+
};
|
|
737
|
+
class Nt {
|
|
738
|
+
listeners = /* @__PURE__ */ new Map();
|
|
739
|
+
on(t, i) {
|
|
740
|
+
let s = this.listeners.get(t);
|
|
741
|
+
s || (s = /* @__PURE__ */ new Set(), this.listeners.set(t, s)), s.add(i);
|
|
742
|
+
}
|
|
743
|
+
off(t, i) {
|
|
744
|
+
this.listeners.get(t)?.delete(i);
|
|
745
|
+
}
|
|
746
|
+
emit(t, i) {
|
|
747
|
+
const s = Wt[t];
|
|
748
|
+
if (s)
|
|
749
|
+
try {
|
|
750
|
+
s.parse(i);
|
|
751
|
+
} catch (o) {
|
|
752
|
+
console.error(`[DroidEventBus] Invalid payload for ${t}:`, o);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
window.dispatchEvent(new CustomEvent(t, { detail: i }));
|
|
756
|
+
for (const o of this.listeners.get(t) ?? [])
|
|
757
|
+
o(i);
|
|
758
|
+
}
|
|
759
|
+
wait(t) {
|
|
760
|
+
return new Promise((i) => {
|
|
761
|
+
const s = (o) => {
|
|
762
|
+
this.off(t, s), i(o);
|
|
763
|
+
};
|
|
764
|
+
this.on(t, s);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const Bt = new Nt(), M = "1.0.3";
|
|
769
|
+
let x = !1;
|
|
770
|
+
function xt(e, t) {
|
|
771
|
+
if (!e)
|
|
772
|
+
throw new Error("[resolveWorkerURL] Worker name must be defined");
|
|
773
|
+
if (typeof window < "u") {
|
|
774
|
+
const i = window.kbveWorkerURLs;
|
|
775
|
+
if (i?.[e]) return i[e];
|
|
776
|
+
}
|
|
777
|
+
return t ?? `/workers/${e}`;
|
|
778
|
+
}
|
|
779
|
+
async function Pt(e) {
|
|
780
|
+
let t = null;
|
|
781
|
+
try {
|
|
782
|
+
const i = new SharedWorker(new URL(
|
|
783
|
+
/* @vite-ignore */
|
|
784
|
+
"/lib/workers/ws-worker.js",
|
|
785
|
+
import.meta.url
|
|
786
|
+
), {
|
|
787
|
+
type: "module"
|
|
788
|
+
});
|
|
789
|
+
i.port.start(), t = b(i.port);
|
|
790
|
+
} catch (i) {
|
|
791
|
+
console.warn("[DROID] ws-worker import.meta fallback failed:", i);
|
|
792
|
+
}
|
|
793
|
+
if (!t)
|
|
794
|
+
try {
|
|
795
|
+
const i = new SharedWorker("/ws-worker.js", { type: "module" });
|
|
796
|
+
i.port.start(), t = b(i.port);
|
|
797
|
+
} catch (i) {
|
|
798
|
+
console.warn("[DROID] ws-worker hardcoded fallback failed:", i);
|
|
799
|
+
}
|
|
800
|
+
if (!t && e?.workerRef)
|
|
801
|
+
try {
|
|
802
|
+
e.workerRef.port.start(), t = b(e.workerRef.port);
|
|
803
|
+
} catch (i) {
|
|
804
|
+
console.warn("[DROID] ws-worker workerRef failed:", i);
|
|
805
|
+
}
|
|
806
|
+
if (!t && e?.workerURL)
|
|
807
|
+
try {
|
|
808
|
+
const i = new SharedWorker(e.workerURL, { type: "module" });
|
|
809
|
+
i.port.start(), t = b(i.port);
|
|
810
|
+
} catch (i) {
|
|
811
|
+
console.warn("[DROID] ws-worker workerURL failed:", i);
|
|
812
|
+
}
|
|
813
|
+
if (!t)
|
|
814
|
+
throw console.error("[DROID] No WS Worker Comlink Initialized"), new Error("[DROID] Failed to initialize ws-worker");
|
|
815
|
+
return t;
|
|
816
|
+
}
|
|
817
|
+
const g = G(
|
|
818
|
+
"uiux-state",
|
|
819
|
+
{
|
|
820
|
+
panelManager: {
|
|
821
|
+
top: { open: !1 },
|
|
822
|
+
right: { open: !1 },
|
|
823
|
+
bottom: { open: !1 },
|
|
824
|
+
left: { open: !1 }
|
|
825
|
+
},
|
|
826
|
+
themeManager: { theme: "auto" },
|
|
827
|
+
toastManager: {},
|
|
828
|
+
scrollY: 0
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
encode: JSON.stringify,
|
|
832
|
+
decode: JSON.parse
|
|
833
|
+
}
|
|
834
|
+
);
|
|
835
|
+
async function Ct(e) {
|
|
836
|
+
try {
|
|
837
|
+
const t = new Worker(
|
|
838
|
+
new URL(
|
|
839
|
+
/* @vite-ignore */
|
|
840
|
+
"/lib/workers/canvas-worker.js",
|
|
841
|
+
import.meta.url
|
|
842
|
+
),
|
|
843
|
+
{ type: "module" }
|
|
844
|
+
);
|
|
845
|
+
return b(t);
|
|
846
|
+
} catch (t) {
|
|
847
|
+
console.warn("[DROID] Vite-style canvas-worker import failed:", t);
|
|
848
|
+
}
|
|
849
|
+
try {
|
|
850
|
+
const t = new Worker("./canvas-worker.js", { type: "module" });
|
|
851
|
+
return b(t);
|
|
852
|
+
} catch (t) {
|
|
853
|
+
console.warn("[DROID] Fallback /canvas-worker.js failed:", t);
|
|
854
|
+
}
|
|
855
|
+
if (e?.workerRef)
|
|
856
|
+
try {
|
|
857
|
+
return b(e.workerRef);
|
|
858
|
+
} catch (t) {
|
|
859
|
+
console.warn("[DROID] Provided workerRef failed:", t);
|
|
860
|
+
}
|
|
861
|
+
if (e?.workerURL)
|
|
862
|
+
try {
|
|
863
|
+
const t = new Worker(e.workerURL, { type: "module" });
|
|
864
|
+
return b(t);
|
|
865
|
+
} catch (t) {
|
|
866
|
+
console.warn("[DROID] Provided workerURL failed:", t);
|
|
867
|
+
}
|
|
868
|
+
throw console.error("[DROID] No Canvas Comlink Initialized"), new Error("[DROID] Failed to initialize canvas worker");
|
|
869
|
+
}
|
|
870
|
+
const z = {
|
|
871
|
+
state: g,
|
|
872
|
+
openPanel(e, t) {
|
|
873
|
+
const i = { ...g.get().panelManager };
|
|
874
|
+
i[e] = { open: !0, payload: t }, g.setKey("panelManager", i);
|
|
875
|
+
},
|
|
876
|
+
closePanel(e) {
|
|
877
|
+
const t = { ...g.get().panelManager };
|
|
878
|
+
t[e] = { open: !1, payload: void 0 }, g.setKey("panelManager", t);
|
|
879
|
+
},
|
|
880
|
+
togglePanel(e, t) {
|
|
881
|
+
const i = { ...g.get().panelManager }, s = i[e]?.open ?? !1;
|
|
882
|
+
i[e] = { open: !s, payload: s ? void 0 : t }, g.setKey("panelManager", i);
|
|
883
|
+
},
|
|
884
|
+
setTheme(e) {
|
|
885
|
+
g.setKey("themeManager", { theme: e });
|
|
886
|
+
},
|
|
887
|
+
addToast(e, t) {
|
|
888
|
+
const i = { ...g.get().toastManager, [e]: t };
|
|
889
|
+
g.setKey("toastManager", i);
|
|
890
|
+
},
|
|
891
|
+
removeToast(e) {
|
|
892
|
+
const t = { ...g.get().toastManager };
|
|
893
|
+
delete t[e], g.setKey("toastManager", t);
|
|
894
|
+
},
|
|
895
|
+
async dispatchCanvasRequest(e, t, i = "animated") {
|
|
896
|
+
const s = t.transferControlToOffscreen();
|
|
897
|
+
await window.kbve?.uiux?.worker?.bindCanvas(e, s, i);
|
|
898
|
+
},
|
|
899
|
+
closeAllPanels() {
|
|
900
|
+
const e = { ...g.get().panelManager };
|
|
901
|
+
console.log("error panel is closing");
|
|
902
|
+
for (const t of Object.keys(e))
|
|
903
|
+
e[t] = { open: !1, payload: void 0 };
|
|
904
|
+
g.setKey("panelManager", e);
|
|
905
|
+
},
|
|
906
|
+
emitFromWorker(e) {
|
|
907
|
+
e.type === "injectVNode" && e.vnode && q(() => {
|
|
908
|
+
const t = document.getElementById("bento-grid-inject");
|
|
909
|
+
if (!t) {
|
|
910
|
+
console.warn(
|
|
911
|
+
"[KBVE] No injection target found: #bento-grid-inject"
|
|
912
|
+
);
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
const i = Q(e.vnode);
|
|
916
|
+
if (i.classList.add("animate-fade-in"), e.vnode.id) {
|
|
917
|
+
const s = document.getElementById(e.vnode.id);
|
|
918
|
+
s && s.remove();
|
|
919
|
+
}
|
|
920
|
+
t.appendChild(i);
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
}, D = G(
|
|
924
|
+
"i18n-cache",
|
|
925
|
+
{},
|
|
926
|
+
{
|
|
927
|
+
encode: JSON.stringify,
|
|
928
|
+
decode: JSON.parse
|
|
929
|
+
}
|
|
930
|
+
), L = {
|
|
931
|
+
store: D,
|
|
932
|
+
api: null,
|
|
933
|
+
ready: Promise.resolve(),
|
|
934
|
+
get(e) {
|
|
935
|
+
return D.get()[e] ?? `[${e}]`;
|
|
936
|
+
},
|
|
937
|
+
async getAsync(e) {
|
|
938
|
+
const t = D.get()[e];
|
|
939
|
+
if (t !== void 0) return t;
|
|
940
|
+
if (!this.api) return `[${e}]`;
|
|
941
|
+
const i = await this.api.getTranslation(e);
|
|
942
|
+
return i !== null ? (D.setKey(e, i), i) : `[${e}]`;
|
|
943
|
+
},
|
|
944
|
+
set(e, t) {
|
|
945
|
+
D.setKey(e, t);
|
|
946
|
+
},
|
|
947
|
+
async hydrate(e, t) {
|
|
948
|
+
this.api = e;
|
|
949
|
+
for (const i of t) {
|
|
950
|
+
const s = await e.getTranslation(i);
|
|
951
|
+
s !== null && D.setKey(i, s);
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
async hydrateLocale(e = "en") {
|
|
955
|
+
if (!this.api) return;
|
|
956
|
+
const i = (await this.api.getAllI18nKeys()).filter(
|
|
957
|
+
(o) => o.startsWith(`${e}:`)
|
|
958
|
+
), s = await this.api.getTranslations(i);
|
|
959
|
+
for (const [o, n] of Object.entries(s))
|
|
960
|
+
console.log(`[i18n.setKey] ${o} = ${n}`), this.store.setKey(o, n);
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
function K() {
|
|
964
|
+
if (!navigator.serviceWorker?.controller) return;
|
|
965
|
+
const e = new MessageChannel();
|
|
966
|
+
navigator.serviceWorker.controller.postMessage(e.port2, [
|
|
967
|
+
e.port2
|
|
968
|
+
]), e.port1.start();
|
|
969
|
+
}
|
|
970
|
+
async function Ft(e) {
|
|
971
|
+
let t = null;
|
|
972
|
+
try {
|
|
973
|
+
const s = new SharedWorker(
|
|
974
|
+
new URL(
|
|
975
|
+
/* @vite-ignore */
|
|
976
|
+
"/lib/workers/db-worker.js",
|
|
977
|
+
import.meta.url
|
|
978
|
+
),
|
|
979
|
+
{
|
|
980
|
+
type: "module"
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
s.port.start(), t = b(s.port);
|
|
984
|
+
} catch (s) {
|
|
985
|
+
console.warn("[DROID] db-worker import.meta fallback failed:", s);
|
|
986
|
+
}
|
|
987
|
+
if (!t)
|
|
988
|
+
try {
|
|
989
|
+
const s = new SharedWorker("/db-worker.js", {
|
|
990
|
+
type: "module"
|
|
991
|
+
});
|
|
992
|
+
s.port.start(), t = b(s.port);
|
|
993
|
+
} catch (s) {
|
|
994
|
+
console.warn("[DROID] db-worker hardcoded fallback failed:", s);
|
|
995
|
+
}
|
|
996
|
+
if (!t && e?.workerRef)
|
|
997
|
+
try {
|
|
998
|
+
e.workerRef.port.start(), t = b(e.workerRef.port);
|
|
999
|
+
} catch (s) {
|
|
1000
|
+
console.warn("[DROID] db-worker workerRef failed:", s);
|
|
1001
|
+
}
|
|
1002
|
+
if (!t && e?.workerURL)
|
|
1003
|
+
try {
|
|
1004
|
+
const s = new SharedWorker(e.workerURL, { type: "module" });
|
|
1005
|
+
s.port.start(), t = b(s.port);
|
|
1006
|
+
} catch (s) {
|
|
1007
|
+
console.warn("[DROID] db-worker workerURL failed:", s);
|
|
1008
|
+
}
|
|
1009
|
+
if (!t)
|
|
1010
|
+
throw console.error("[DROID] No DB Worker Comlink Initialized"), new Error("[DROID] Failed to initialize db-worker");
|
|
1011
|
+
return await t.getVersion() !== M && await kt(t, {
|
|
1012
|
+
version: M,
|
|
1013
|
+
i18nPath: "https://discord.sh/i18n/db.json",
|
|
1014
|
+
locale: "en",
|
|
1015
|
+
defaults: { welcome: "Welcome!", theme: "dark" }
|
|
1016
|
+
}), t;
|
|
1017
|
+
}
|
|
1018
|
+
function jt(e, t) {
|
|
1019
|
+
const i = Z(async (s) => {
|
|
1020
|
+
q(() => {
|
|
1021
|
+
const o = `ws:${Date.now()}`;
|
|
1022
|
+
t.storeWsMessage(o, s);
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
e.onMessage(tt(i, [0]));
|
|
1026
|
+
}
|
|
1027
|
+
async function zt(e) {
|
|
1028
|
+
if (console.log("[DROID]: Main<T>"), x || (x = !0, navigator.serviceWorker?.controller ? K() : navigator.serviceWorker?.addEventListener(
|
|
1029
|
+
"controllerchange",
|
|
1030
|
+
K
|
|
1031
|
+
)), console.log("[DROID] Main<T> => Worker URLs", e?.workerURLs), !window.kbve?.api || !window.kbve?.i18n || !window.kbve?.uiux)
|
|
1032
|
+
try {
|
|
1033
|
+
console.log("[DROID] Main<T> => Worker => CanvasComlink");
|
|
1034
|
+
const i = await Ct({
|
|
1035
|
+
workerRef: e?.workerRefs?.canvasWorker,
|
|
1036
|
+
workerURL: e?.workerURLs?.canvasWorker
|
|
1037
|
+
});
|
|
1038
|
+
console.log("[DROID] Main<T> => Worker => StorageComlink");
|
|
1039
|
+
const s = await Ft({
|
|
1040
|
+
workerURL: typeof e?.workerURLs?.dbWorker == "string" ? e.workerURLs.dbWorker : void 0,
|
|
1041
|
+
workerRef: e?.workerRefs?.dbWorker
|
|
1042
|
+
});
|
|
1043
|
+
console.log("[DROID] Main<T> => Worker => WsComlink");
|
|
1044
|
+
const o = await Pt({
|
|
1045
|
+
workerRef: e?.workerRefs?.wsWorker,
|
|
1046
|
+
workerURL: e?.workerURLs?.wsWorker
|
|
1047
|
+
});
|
|
1048
|
+
console.log("[DROID] Main<T> => Worker => ModManager");
|
|
1049
|
+
const n = await yt(
|
|
1050
|
+
(c) => e?.workerURLs?.[c] ?? c
|
|
1051
|
+
), r = Bt;
|
|
1052
|
+
for (const c of Object.values(n.registry))
|
|
1053
|
+
typeof c.instance.init == "function" && await c.instance.init({
|
|
1054
|
+
emitFromWorker: z.emitFromWorker
|
|
1055
|
+
}), console.log("[Event] -> Fire Mod Ready"), r.emit("droid-mod-ready", {
|
|
1056
|
+
meta: c.meta,
|
|
1057
|
+
timestamp: Date.now()
|
|
1058
|
+
});
|
|
1059
|
+
jt(o, s);
|
|
1060
|
+
const h = Dt;
|
|
1061
|
+
L.api = s, L.ready = L.hydrateLocale("en"), window.kbve = {
|
|
1062
|
+
...window.kbve || {},
|
|
1063
|
+
api: s,
|
|
1064
|
+
i18n: L,
|
|
1065
|
+
uiux: { ...z, worker: i },
|
|
1066
|
+
ws: o,
|
|
1067
|
+
data: h,
|
|
1068
|
+
mod: n,
|
|
1069
|
+
events: r
|
|
1070
|
+
}, await L.ready, window.kbve.events.emit("droid-ready", {
|
|
1071
|
+
timestamp: Date.now()
|
|
1072
|
+
}), document.addEventListener("astro:page-load", () => {
|
|
1073
|
+
console.debug(
|
|
1074
|
+
"[KBVE] Re-dispatched droid-ready after astro:page-load"
|
|
1075
|
+
), window.kbve?.events.emit("droid-ready", {
|
|
1076
|
+
timestamp: Date.now()
|
|
1077
|
+
});
|
|
1078
|
+
}), console.log("[KBVE] Global API ready");
|
|
1079
|
+
} catch (i) {
|
|
1080
|
+
throw console.error("[DROID] Initialization error:", i), i;
|
|
1081
|
+
}
|
|
1082
|
+
else
|
|
1083
|
+
console.log("[KBVE] Already initialized");
|
|
1084
|
+
}
|
|
1085
|
+
export {
|
|
1086
|
+
jt as bridgeWsToDb,
|
|
1087
|
+
L as i18n,
|
|
1088
|
+
zt as main,
|
|
1089
|
+
xt as resolveWorkerURL,
|
|
1090
|
+
z as uiux
|
|
1091
|
+
};
|