@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/main-BYzQVPCs.js DELETED
@@ -1,1455 +0,0 @@
1
- import { z as T } from "./index-DSyyyiLP.js";
2
- /**
3
- * @license
4
- * Copyright 2019 Google LLC
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
- const lt = Symbol("Comlink.proxy"), At = Symbol("Comlink.endpoint"), Ut = Symbol("Comlink.releaseProxy"), z = Symbol("Comlink.finalizer"), H = Symbol("Comlink.thrown"), ut = (t) => typeof t == "object" && t !== null || typeof t == "function", Dt = {
8
- canHandle: (t) => ut(t) && t[lt],
9
- serialize(t) {
10
- const { port1: e, port2: i } = new MessageChannel();
11
- return pt(t, e), [i, [i]];
12
- },
13
- deserialize(t) {
14
- return t.start(), V(t);
15
- }
16
- }, Wt = {
17
- canHandle: (t) => ut(t) && H in t,
18
- serialize({ value: t }) {
19
- let e;
20
- return t instanceof Error ? e = {
21
- isError: !0,
22
- value: {
23
- message: t.message,
24
- name: t.name,
25
- stack: t.stack
26
- }
27
- } : e = { isError: !1, value: t }, [e, []];
28
- },
29
- deserialize(t) {
30
- throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
31
- }
32
- }, dt = /* @__PURE__ */ new Map([
33
- ["proxy", Dt],
34
- ["throw", Wt]
35
- ]);
36
- function Ct(t, e) {
37
- for (const i of t)
38
- if (e === i || i === "*" || i instanceof RegExp && i.test(e))
39
- return !0;
40
- return !1;
41
- }
42
- function pt(t, e = globalThis, i = ["*"]) {
43
- e.addEventListener("message", function n(s) {
44
- if (!s || !s.data)
45
- return;
46
- if (!Ct(i, s.origin)) {
47
- console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
48
- return;
49
- }
50
- const { id: r, type: o, path: u } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(R);
51
- let d;
52
- try {
53
- const a = u.slice(0, -1).reduce((h, w) => h[w], t), c = u.reduce((h, w) => h[w], t);
54
- switch (o) {
55
- case "GET":
56
- d = c;
57
- break;
58
- case "SET":
59
- a[u.slice(-1)[0]] = R(s.data.value), d = !0;
60
- break;
61
- case "APPLY":
62
- d = c.apply(a, l);
63
- break;
64
- case "CONSTRUCT":
65
- {
66
- const h = new c(...l);
67
- d = Et(h);
68
- }
69
- break;
70
- case "ENDPOINT":
71
- {
72
- const { port1: h, port2: w } = new MessageChannel();
73
- pt(t, w), d = Tt(h, [h]);
74
- }
75
- break;
76
- case "RELEASE":
77
- d = void 0;
78
- break;
79
- default:
80
- return;
81
- }
82
- } catch (a) {
83
- d = { value: a, [H]: 0 };
84
- }
85
- Promise.resolve(d).catch((a) => ({ value: a, [H]: 0 })).then((a) => {
86
- const [c, h] = M(a);
87
- e.postMessage(Object.assign(Object.assign({}, c), { id: r }), h), o === "RELEASE" && (e.removeEventListener("message", n), wt(e), z in t && typeof t[z] == "function" && t[z]());
88
- }).catch((a) => {
89
- const [c, h] = M({
90
- value: new TypeError("Unserializable return value"),
91
- [H]: 0
92
- });
93
- e.postMessage(Object.assign(Object.assign({}, c), { id: r }), h);
94
- });
95
- }), e.start && e.start();
96
- }
97
- function Vt(t) {
98
- return t.constructor.name === "MessagePort";
99
- }
100
- function wt(t) {
101
- Vt(t) && t.close();
102
- }
103
- function V(t, e) {
104
- const i = /* @__PURE__ */ new Map();
105
- return t.addEventListener("message", function(s) {
106
- const { data: r } = s;
107
- if (!r || !r.id)
108
- return;
109
- const o = i.get(r.id);
110
- if (o)
111
- try {
112
- o(r);
113
- } finally {
114
- i.delete(r.id);
115
- }
116
- }), J(t, i, [], e);
117
- }
118
- function B(t) {
119
- if (t)
120
- throw new Error("Proxy has been released and is not useable");
121
- }
122
- function yt(t) {
123
- return U(t, /* @__PURE__ */ new Map(), {
124
- type: "RELEASE"
125
- }).then(() => {
126
- wt(t);
127
- });
128
- }
129
- const x = /* @__PURE__ */ new WeakMap(), j = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
130
- const e = (x.get(t) || 0) - 1;
131
- x.set(t, e), e === 0 && yt(t);
132
- });
133
- function _t(t, e) {
134
- const i = (x.get(e) || 0) + 1;
135
- x.set(e, i), j && j.register(t, e, t);
136
- }
137
- function Bt(t) {
138
- j && j.unregister(t);
139
- }
140
- function J(t, e, i = [], n = function() {
141
- }) {
142
- let s = !1;
143
- const r = new Proxy(n, {
144
- get(o, u) {
145
- if (B(s), u === Ut)
146
- return () => {
147
- Bt(r), yt(t), e.clear(), s = !0;
148
- };
149
- if (u === "then") {
150
- if (i.length === 0)
151
- return { then: () => r };
152
- const l = U(t, e, {
153
- type: "GET",
154
- path: i.map((d) => d.toString())
155
- }).then(R);
156
- return l.then.bind(l);
157
- }
158
- return J(t, e, [...i, u]);
159
- },
160
- set(o, u, l) {
161
- B(s);
162
- const [d, a] = M(l);
163
- return U(t, e, {
164
- type: "SET",
165
- path: [...i, u].map((c) => c.toString()),
166
- value: d
167
- }, a).then(R);
168
- },
169
- apply(o, u, l) {
170
- B(s);
171
- const d = i[i.length - 1];
172
- if (d === At)
173
- return U(t, e, {
174
- type: "ENDPOINT"
175
- }).then(R);
176
- if (d === "bind")
177
- return J(t, e, i.slice(0, -1));
178
- const [a, c] = it(l);
179
- return U(t, e, {
180
- type: "APPLY",
181
- path: i.map((h) => h.toString()),
182
- argumentList: a
183
- }, c).then(R);
184
- },
185
- construct(o, u) {
186
- B(s);
187
- const [l, d] = it(u);
188
- return U(t, e, {
189
- type: "CONSTRUCT",
190
- path: i.map((a) => a.toString()),
191
- argumentList: l
192
- }, d).then(R);
193
- }
194
- });
195
- return _t(r, t), r;
196
- }
197
- function Pt(t) {
198
- return Array.prototype.concat.apply([], t);
199
- }
200
- function it(t) {
201
- const e = t.map(M);
202
- return [e.map((i) => i[0]), Pt(e.map((i) => i[1]))];
203
- }
204
- const gt = /* @__PURE__ */ new WeakMap();
205
- function Tt(t, e) {
206
- return gt.set(t, e), t;
207
- }
208
- function Et(t) {
209
- return Object.assign(t, { [lt]: !0 });
210
- }
211
- function M(t) {
212
- for (const [e, i] of dt)
213
- if (i.canHandle(t)) {
214
- const [n, s] = i.serialize(t);
215
- return [
216
- {
217
- type: "HANDLER",
218
- name: e,
219
- value: n
220
- },
221
- s
222
- ];
223
- }
224
- return [
225
- {
226
- type: "RAW",
227
- value: t
228
- },
229
- gt.get(t) || []
230
- ];
231
- }
232
- function R(t) {
233
- switch (t.type) {
234
- case "HANDLER":
235
- return dt.get(t.name).deserialize(t.value);
236
- case "RAW":
237
- return t.value;
238
- }
239
- }
240
- function U(t, e, i, n) {
241
- return new Promise((s) => {
242
- const r = Ft();
243
- e.set(r, s), t.start && t.start(), t.postMessage(Object.assign({ id: r }, i), n);
244
- });
245
- }
246
- function Ft() {
247
- return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
248
- }
249
- let q = Symbol("clean"), E = [], Ht = (t, e) => {
250
- let i = [], n = {
251
- get() {
252
- return n.lc || n.listen(() => {
253
- })(), n.value;
254
- },
255
- l: e || 0,
256
- lc: 0,
257
- listen(s, r) {
258
- return n.lc = i.push(s, r || n.l) / 2, () => {
259
- let o = i.indexOf(s);
260
- ~o && (i.splice(o, 2), --n.lc || n.off());
261
- };
262
- },
263
- notify(s) {
264
- let r = !E.length;
265
- for (let o = 0; o < i.length; o += 2)
266
- E.push(
267
- i[o],
268
- i[o + 1],
269
- n.value,
270
- s
271
- );
272
- if (r) {
273
- for (let o = 0; o < E.length; o += 4) {
274
- let u;
275
- for (let l = o + 1; !u && (l += 4) < E.length; )
276
- E[l] < E[o + 1] && (u = E.push(
277
- E[o],
278
- E[o + 1],
279
- E[o + 2],
280
- E[o + 3]
281
- ));
282
- u || E[o](E[o + 2], E[o + 3]);
283
- }
284
- E.length = 0;
285
- }
286
- },
287
- off() {
288
- },
289
- /* It will be called on last listener unsubscribing.
290
- We will redefine it in onMount and onStop. */
291
- set(s) {
292
- n.value !== s && (n.value = s, n.notify());
293
- },
294
- subscribe(s, r) {
295
- let o = n.listen(s, r);
296
- return s(n.value), o;
297
- },
298
- value: t
299
- };
300
- return process.env.NODE_ENV !== "production" && (n[q] = () => {
301
- i = [], n.lc = 0, n.off();
302
- }), n;
303
- };
304
- const xt = 5, v = 6, P = 10;
305
- let jt = (t, e, i, n) => (t.events = t.events || {}, t.events[i + P] || (t.events[i + P] = n((s) => {
306
- t.events[i].reduceRight((r, o) => (o(r), r), {
307
- shared: {},
308
- ...s
309
- });
310
- })), t.events[i] = t.events[i] || [], t.events[i].push(e), () => {
311
- let s = t.events[i], r = s.indexOf(e);
312
- s.splice(r, 1), s.length || (delete t.events[i], t.events[i + P](), delete t.events[i + P]);
313
- }), Mt = 1e3, Kt = (t, e) => jt(t, (n) => {
314
- let s = e(n);
315
- s && t.events[v].push(s);
316
- }, xt, (n) => {
317
- let s = t.listen;
318
- t.listen = (...o) => (!t.lc && !t.active && (t.active = !0, n()), s(...o));
319
- let r = t.off;
320
- if (t.events[v] = [], t.off = () => {
321
- r(), setTimeout(() => {
322
- if (t.active && !t.lc) {
323
- t.active = !1;
324
- for (let o of t.events[v]) o();
325
- t.events[v] = [];
326
- }
327
- }, Mt);
328
- }, process.env.NODE_ENV !== "production") {
329
- let o = t[q];
330
- t[q] = () => {
331
- for (let u of t.events[v]) u();
332
- t.events[v] = [], t.active = !1, o();
333
- };
334
- }
335
- return () => {
336
- t.listen = s, t.off = r;
337
- };
338
- }), Gt = (t = {}) => {
339
- let e = Ht(t);
340
- return e.setKey = function(i, n) {
341
- typeof n > "u" ? i in e.value && (e.value = { ...e.value }, delete e.value[i], e.notify(i)) : e.value[i] !== n && (e.value = {
342
- ...e.value,
343
- [i]: n
344
- }, e.notify(i));
345
- }, e;
346
- }, nt = (t) => t, W = {}, N = { addEventListener() {
347
- }, removeEventListener() {
348
- } };
349
- function zt() {
350
- try {
351
- return typeof localStorage < "u";
352
- } catch {
353
- return !1;
354
- }
355
- }
356
- zt() && (W = localStorage);
357
- let Yt = {
358
- addEventListener(t, e, i) {
359
- window.addEventListener("storage", e), window.addEventListener("pageshow", i);
360
- },
361
- removeEventListener(t, e, i) {
362
- window.removeEventListener("storage", e), window.removeEventListener("pageshow", i);
363
- }
364
- };
365
- typeof window < "u" && (N = Yt);
366
- function Ot(t, e = {}, i = {}) {
367
- let n = i.encode || nt, s = i.decode || nt, r = Gt(), o = r.setKey;
368
- r.setKey = (a, c) => {
369
- typeof c > "u" ? (i.listen !== !1 && N.perKey && N.removeEventListener(t + a, l, d), delete W[t + a]) : (i.listen !== !1 && N.perKey && !(a in r.value) && N.addEventListener(t + a, l, d), W[t + a] = n(c)), o(a, c);
370
- };
371
- let u = r.set;
372
- r.set = function(a) {
373
- for (let c in a)
374
- r.setKey(c, a[c]);
375
- for (let c in r.value)
376
- c in a || r.setKey(c);
377
- };
378
- function l(a) {
379
- a.key ? a.key.startsWith(t) && (a.newValue === null ? o(a.key.slice(t.length), void 0) : o(a.key.slice(t.length), s(a.newValue))) : u({});
380
- }
381
- function d() {
382
- let a = { ...e };
383
- for (let c in W)
384
- c.startsWith(t) && (a[c.slice(t.length)] = s(W[c]));
385
- r.set(a);
386
- }
387
- return Kt(r, () => {
388
- if (d(), i.listen !== !1)
389
- return N.addEventListener(t, l, d), () => {
390
- N.removeEventListener(t, l, d);
391
- for (let a in r.value)
392
- N.removeEventListener(t + a, l, d);
393
- };
394
- }), r;
395
- }
396
- async function $t(t, {
397
- version: e,
398
- i18nPath: i = "https://discord.sh/i18n/db.json",
399
- locale: n = "en",
400
- defaults: s = {
401
- welcome: "Welcome to the app!"
402
- }
403
- }) {
404
- console.log("[init-worker] Initializing database...");
405
- try {
406
- await t.loadI18nFromJSON(i), console.log(`[init-worker] i18n loaded from ${i}`), await t.dbSet("locale", n);
407
- for (const [r, o] of Object.entries(s))
408
- await t.dbSet(r, o);
409
- await t.setVersion(e), t.loadServersFromJSON(), console.log(`[init-worker] DB initialized to version ${e}`);
410
- } catch (r) {
411
- console.error("[init-worker] Initialization failed:", r);
412
- }
413
- }
414
- let F = null;
415
- async function Xt() {
416
- if (F) return F;
417
- const t = {};
418
- async function e(r) {
419
- const o = new Worker(r, { type: "module" }), u = V(o), l = await u.getMeta?.() ?? {
420
- name: "unknown",
421
- version: "0.0.1"
422
- }, d = `${l.name}@${l.version}`;
423
- console.log(`[mod-manager] ${d} is loaded.`);
424
- const a = { id: d, worker: o, instance: u, meta: l, url: r };
425
- return t[d] = a, a;
426
- }
427
- function i(r) {
428
- t[r] && (t[r].worker.terminate(), delete t[r]);
429
- }
430
- function n() {
431
- return Object.values(t).map((r) => r.meta);
432
- }
433
- async function s(r) {
434
- const o = t[r];
435
- if (!o) throw new Error(`Mod "${r}" not found`);
436
- return i(r), e(o.url);
437
- }
438
- return F = {
439
- registry: t,
440
- load: e,
441
- unload: i,
442
- list: n,
443
- reload: s
444
- }, F;
445
- }
446
- var b = /* @__PURE__ */ ((t) => (t[t.PAYLOAD_UNKNOWN = 0] = "PAYLOAD_UNKNOWN", t[t.JSON = 1] = "JSON", t[t.FLEX = 2] = "FLEX", t[t.PROTOBUF = 3] = "PROTOBUF", t[t.FLATBUFFER = 4] = "FLATBUFFER", t))(b || {}), O = /* @__PURE__ */ ((t) => (t[t.UNKNOWN = 0] = "UNKNOWN", t[t.ADD = 1] = "ADD", t[t.READ = 2] = "READ", t[t.GET = 4] = "GET", t[t.SET = 8] = "SET", t[t.DEL = 16] = "DEL", t[t.STREAM = 32] = "STREAM", t[t.GROUP = 64] = "GROUP", t[t.LIST = 128] = "LIST", t[t.ACTION = 256] = "ACTION", t[t.MESSAGE = 512] = "MESSAGE", t[t.INFO = 1024] = "INFO", t[t.DEBUG = 2048] = "DEBUG", t[t.ERROR = 4096] = "ERROR", t[t.AUTH = 8192] = "AUTH", t[t.HEARTBEAT = 16384] = "HEARTBEAT", t[t.CONFIG_UPDATE = 32768] = "CONFIG_UPDATE", t[t.REDIS = 65536] = "REDIS", t[t.SUPABASE = 131072] = "SUPABASE", t[t.FILESYSTEM = 262144] = "FILESYSTEM", t[t.WEBSOCKET = 524288] = "WEBSOCKET", t[t.HTTP_API = 1048576] = "HTTP_API", t[t.LOCAL_CACHE = 2097152] = "LOCAL_CACHE", t[t.AI = 4194304] = "AI", t))(O || {}), p = /* @__PURE__ */ ((t) => (t[t.WIDTH8 = 0] = "WIDTH8", t[t.WIDTH16 = 1] = "WIDTH16", t[t.WIDTH32 = 2] = "WIDTH32", t[t.WIDTH64 = 3] = "WIDTH64", t))(p || {});
447
- function Jt(t) {
448
- return 1 << t;
449
- }
450
- function qt(t) {
451
- return t >= -128 && t <= 127 ? p.WIDTH8 : t >= -32768 && t <= 32767 ? p.WIDTH16 : t >= -2147483648 && t <= 2147483647 ? p.WIDTH32 : p.WIDTH64;
452
- }
453
- function Qt(t) {
454
- return t === Math.fround(t) ? p.WIDTH32 : p.WIDTH64;
455
- }
456
- function C(t) {
457
- return t <= 255 ? p.WIDTH8 : t <= 65535 ? p.WIDTH16 : t <= 4294967295 ? p.WIDTH32 : p.WIDTH64;
458
- }
459
- function g(t) {
460
- return t === 1 ? p.WIDTH8 : t === 2 ? p.WIDTH16 : t === 4 ? p.WIDTH32 : p.WIDTH64;
461
- }
462
- function It(t, e) {
463
- return ~t + 1 & e - 1;
464
- }
465
- function mt(t) {
466
- return new TextDecoder().decode(t);
467
- }
468
- function Q(t) {
469
- return new TextEncoder().encode(t);
470
- }
471
- var f = /* @__PURE__ */ ((t) => (t[t.NULL = 0] = "NULL", t[t.INT = 1] = "INT", t[t.UINT = 2] = "UINT", t[t.FLOAT = 3] = "FLOAT", t[t.KEY = 4] = "KEY", t[t.STRING = 5] = "STRING", t[t.INDIRECT_INT = 6] = "INDIRECT_INT", t[t.INDIRECT_UINT = 7] = "INDIRECT_UINT", t[t.INDIRECT_FLOAT = 8] = "INDIRECT_FLOAT", t[t.MAP = 9] = "MAP", t[t.VECTOR = 10] = "VECTOR", t[t.VECTOR_INT = 11] = "VECTOR_INT", t[t.VECTOR_UINT = 12] = "VECTOR_UINT", t[t.VECTOR_FLOAT = 13] = "VECTOR_FLOAT", t[t.VECTOR_KEY = 14] = "VECTOR_KEY", t[t.VECTOR_STRING_DEPRECATED = 15] = "VECTOR_STRING_DEPRECATED", t[t.VECTOR_INT2 = 16] = "VECTOR_INT2", t[t.VECTOR_UINT2 = 17] = "VECTOR_UINT2", t[t.VECTOR_FLOAT2 = 18] = "VECTOR_FLOAT2", t[t.VECTOR_INT3 = 19] = "VECTOR_INT3", t[t.VECTOR_UINT3 = 20] = "VECTOR_UINT3", t[t.VECTOR_FLOAT3 = 21] = "VECTOR_FLOAT3", t[t.VECTOR_INT4 = 22] = "VECTOR_INT4", t[t.VECTOR_UINT4 = 23] = "VECTOR_UINT4", t[t.VECTOR_FLOAT4 = 24] = "VECTOR_FLOAT4", t[t.BLOB = 25] = "BLOB", t[t.BOOL = 26] = "BOOL", t[t.VECTOR_BOOL = 36] = "VECTOR_BOOL", t))(f || {});
472
- function Y(t) {
473
- return t === f.BOOL || t <= f.FLOAT;
474
- }
475
- function kt(t) {
476
- return t >= f.INT && t <= f.FLOAT;
477
- }
478
- function Zt(t) {
479
- return t >= f.INDIRECT_INT && t <= f.INDIRECT_FLOAT;
480
- }
481
- function te(t) {
482
- return t === f.BOOL || t >= f.INT && t <= f.STRING;
483
- }
484
- function bt(t) {
485
- return t === f.VECTOR_BOOL || t >= f.VECTOR_INT && t <= f.VECTOR_STRING_DEPRECATED;
486
- }
487
- function Z(t) {
488
- return t >= f.VECTOR_INT2 && t <= f.VECTOR_FLOAT4;
489
- }
490
- function $(t) {
491
- return bt(t) || Z(t) || t === f.VECTOR;
492
- }
493
- function ee(t, e) {
494
- if (e === 0) return t - f.INT + f.VECTOR_INT;
495
- if (e === 2) return t - f.INT + f.VECTOR_INT2;
496
- if (e === 3) return t - f.INT + f.VECTOR_INT3;
497
- if (e === 4) return t - f.INT + f.VECTOR_INT4;
498
- throw "Unexpected length " + e;
499
- }
500
- function ie(t) {
501
- return t - f.VECTOR_INT + f.INT;
502
- }
503
- function ne(t) {
504
- return (t - f.VECTOR_INT2) % 3 + f.INT;
505
- }
506
- function se(t) {
507
- return ((t - f.VECTOR_INT2) / 3 >> 0) + 2;
508
- }
509
- function tt(t, e) {
510
- return e | t << 2;
511
- }
512
- class L {
513
- constructor(e, i, n, s = null, r = 0) {
514
- this.builder = e, this.type = i, this.width = n, this.value = s, this.offset = r;
515
- }
516
- elementWidth(e, i) {
517
- if (Y(this.type)) return this.width;
518
- for (let n = 0; n < 4; n++) {
519
- const s = 1 << n, o = e + It(e, s) + i * s - this.offset, u = C(o);
520
- if (1 << u === s)
521
- return u;
522
- }
523
- throw `Element is unknown. Size: ${e} at index: ${i}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
524
- }
525
- writeToBuffer(e) {
526
- const i = this.builder.computeOffset(e);
527
- if (this.type === f.FLOAT)
528
- this.width === p.WIDTH32 ? this.builder.view.setFloat32(this.builder.offset, this.value, !0) : this.builder.view.setFloat64(this.builder.offset, this.value, !0);
529
- else if (this.type === f.INT) {
530
- const n = g(e);
531
- this.builder.pushInt(this.value, n);
532
- } else if (this.type === f.UINT) {
533
- const n = g(e);
534
- this.builder.pushUInt(this.value, n);
535
- } else if (this.type === f.NULL)
536
- this.builder.pushInt(0, this.width);
537
- else if (this.type === f.BOOL)
538
- this.builder.pushInt(this.value ? 1 : 0, this.width);
539
- else
540
- throw `Unexpected type: ${this.type}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
541
- this.offset = i;
542
- }
543
- storedWidth(e = p.WIDTH8) {
544
- return Y(this.type) ? Math.max(e, this.width) : this.width;
545
- }
546
- storedPackedType(e = p.WIDTH8) {
547
- return tt(this.type, this.storedWidth(e));
548
- }
549
- isOffset() {
550
- return !Y(this.type);
551
- }
552
- }
553
- class re {
554
- constructor(e = 2048, i = !0, n = !0, s = !0) {
555
- this.dedupStrings = i, this.dedupKeys = n, this.dedupKeyVectors = s, 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(e > 0 ? e : 2048), this.view = new DataView(this.buffer);
556
- }
557
- align(e) {
558
- const i = Jt(e);
559
- return this.offset += It(this.offset, i), i;
560
- }
561
- computeOffset(e) {
562
- const i = this.offset + e;
563
- let n = this.buffer.byteLength;
564
- const s = n;
565
- for (; n < i; )
566
- n <<= 1;
567
- if (s < n) {
568
- const r = this.buffer;
569
- this.buffer = new ArrayBuffer(n), this.view = new DataView(this.buffer), new Uint8Array(this.buffer).set(new Uint8Array(r), 0);
570
- }
571
- return i;
572
- }
573
- pushInt(e, i) {
574
- if (i === p.WIDTH8)
575
- this.view.setInt8(this.offset, e);
576
- else if (i === p.WIDTH16)
577
- this.view.setInt16(this.offset, e, !0);
578
- else if (i === p.WIDTH32)
579
- this.view.setInt32(this.offset, e, !0);
580
- else if (i === p.WIDTH64)
581
- this.view.setBigInt64(this.offset, BigInt(e), !0);
582
- else
583
- throw `Unexpected width: ${i} for value: ${e}`;
584
- }
585
- pushUInt(e, i) {
586
- if (i === p.WIDTH8)
587
- this.view.setUint8(this.offset, e);
588
- else if (i === p.WIDTH16)
589
- this.view.setUint16(this.offset, e, !0);
590
- else if (i === p.WIDTH32)
591
- this.view.setUint32(this.offset, e, !0);
592
- else if (i === p.WIDTH64)
593
- this.view.setBigUint64(this.offset, BigInt(e), !0);
594
- else
595
- throw `Unexpected width: ${i} for value: ${e}`;
596
- }
597
- writeInt(e, i) {
598
- const n = this.computeOffset(i);
599
- this.pushInt(e, g(i)), this.offset = n;
600
- }
601
- writeUInt(e, i) {
602
- const n = this.computeOffset(i);
603
- this.pushUInt(e, g(i)), this.offset = n;
604
- }
605
- writeBlob(e) {
606
- const i = e.byteLength, n = C(i), s = this.align(n);
607
- this.writeUInt(i, s);
608
- const r = this.offset, o = this.computeOffset(i);
609
- new Uint8Array(this.buffer).set(new Uint8Array(e), r), this.stack.push(this.offsetStackValue(r, f.BLOB, n)), this.offset = o;
610
- }
611
- writeString(e) {
612
- if (this.dedupStrings && Object.prototype.hasOwnProperty.call(this.stringLookup, e)) {
613
- this.stack.push(this.stringLookup[e]);
614
- return;
615
- }
616
- const i = Q(e), n = i.length, s = C(n), r = this.align(s);
617
- this.writeUInt(n, r);
618
- const o = this.offset, u = this.computeOffset(n + 1);
619
- new Uint8Array(this.buffer).set(i, o);
620
- const l = this.offsetStackValue(o, f.STRING, s);
621
- this.stack.push(l), this.dedupStrings && (this.stringLookup[e] = l), this.offset = u;
622
- }
623
- writeKey(e) {
624
- if (this.dedupKeys && Object.prototype.hasOwnProperty.call(this.keyLookup, e)) {
625
- this.stack.push(this.keyLookup[e]);
626
- return;
627
- }
628
- const i = Q(e), n = i.length, s = this.computeOffset(n + 1);
629
- new Uint8Array(this.buffer).set(i, this.offset);
630
- const r = this.offsetStackValue(this.offset, f.KEY, p.WIDTH8);
631
- this.stack.push(r), this.dedupKeys && (this.keyLookup[e] = r), this.offset = s;
632
- }
633
- writeStackValue(e, i) {
634
- const n = this.computeOffset(i);
635
- if (e.isOffset()) {
636
- const s = this.offset - e.offset;
637
- if (i === 8 || BigInt(s) < BigInt(1) << BigInt(i * 8))
638
- this.writeUInt(s, i);
639
- else
640
- throw `Unexpected size ${i}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
641
- } else
642
- e.writeToBuffer(i);
643
- this.offset = n;
644
- }
645
- integrityCheckOnValueAddition() {
646
- if (this.finished)
647
- throw "Adding values after finish is prohibited";
648
- if (this.stackPointers.length !== 0 && this.stackPointers[this.stackPointers.length - 1].isVector === !1 && this.stack[this.stack.length - 1].type !== f.KEY)
649
- throw "Adding value to a map before adding a key is prohibited";
650
- }
651
- integrityCheckOnKeyAddition() {
652
- if (this.finished)
653
- throw "Adding values after finish is prohibited";
654
- if (this.stackPointers.length === 0 || this.stackPointers[this.stackPointers.length - 1].isVector)
655
- throw "Adding key before starting a map is prohibited";
656
- }
657
- startVector() {
658
- this.stackPointers.push({ stackPosition: this.stack.length, isVector: !0 });
659
- }
660
- startMap(e = !1) {
661
- this.stackPointers.push({ stackPosition: this.stack.length, isVector: !1, presorted: e });
662
- }
663
- endVector(e) {
664
- const i = this.stack.length - e.stackPosition, n = this.createVector(e.stackPosition, i, 1);
665
- this.stack.splice(e.stackPosition, i), this.stack.push(n);
666
- }
667
- endMap(e) {
668
- e.presorted || this.sort(e);
669
- let i = "";
670
- for (let o = e.stackPosition; o < this.stack.length; o += 2)
671
- i += `,${this.stack[o].offset}`;
672
- const n = this.stack.length - e.stackPosition >> 1;
673
- this.dedupKeyVectors && !Object.prototype.hasOwnProperty.call(this.keyVectorLookup, i) && (this.keyVectorLookup[i] = this.createVector(e.stackPosition, n, 2));
674
- const s = this.dedupKeyVectors ? this.keyVectorLookup[i] : this.createVector(e.stackPosition, n, 2), r = this.createVector(e.stackPosition + 1, n, 2, s);
675
- this.stack.splice(e.stackPosition, n << 1), this.stack.push(r);
676
- }
677
- sort(e) {
678
- const i = this.view, n = this.stack;
679
- function s(a, c) {
680
- if (a.type !== f.KEY || c.type !== f.KEY)
681
- throw `Stack values are not keys ${a} | ${c}. Check if you combined [addKey] with add... method calls properly.`;
682
- let h, w, y = 0;
683
- do {
684
- if (h = i.getUint8(a.offset + y), w = i.getUint8(c.offset + y), w < h) return !0;
685
- if (h < w) return !1;
686
- y += 1;
687
- } while (h !== 0 && w !== 0);
688
- return !1;
689
- }
690
- function r(a, c, h) {
691
- if (c === h) return;
692
- const w = a[c], y = a[c + 1];
693
- a[c] = a[h], a[c + 1] = a[h + 1], a[h] = w, a[h + 1] = y;
694
- }
695
- function o() {
696
- for (let a = e.stackPosition; a < n.length; a += 2) {
697
- let c = a;
698
- for (let h = a + 2; h < n.length; h += 2)
699
- s(n[c], n[h]) && (c = h);
700
- c !== a && r(n, c, a);
701
- }
702
- }
703
- function u(a, c) {
704
- if (a.type !== f.KEY || c.type !== f.KEY)
705
- throw `Stack values are not keys ${a} | ${c}. Check if you combined [addKey] with add... method calls properly.`;
706
- if (a.offset === c.offset)
707
- return !1;
708
- let h, w, y = 0;
709
- do {
710
- if (h = i.getUint8(a.offset + y), w = i.getUint8(c.offset + y), h < w) return !0;
711
- if (w < h) return !1;
712
- y += 1;
713
- } while (h !== 0 && w !== 0);
714
- return !1;
715
- }
716
- function l(a, c) {
717
- if (a < c) {
718
- const h = a + (c - a >> 2) * 2, w = n[h];
719
- let y = a, S = c;
720
- do {
721
- for (; u(n[y], w); )
722
- y += 2;
723
- for (; u(w, n[S]); )
724
- S -= 2;
725
- y <= S && (r(n, y, S), y += 2, S -= 2);
726
- } while (y <= S);
727
- l(a, S), l(y, c);
728
- }
729
- }
730
- let d = !0;
731
- for (let a = e.stackPosition; a < this.stack.length - 2; a += 2)
732
- if (s(this.stack[a], this.stack[a + 2])) {
733
- d = !1;
734
- break;
735
- }
736
- d || (this.stack.length - e.stackPosition > 40 ? l(e.stackPosition, this.stack.length - 2) : o());
737
- }
738
- end() {
739
- if (this.stackPointers.length < 1) return;
740
- const e = this.stackPointers.pop();
741
- e.isVector ? this.endVector(e) : this.endMap(e);
742
- }
743
- createVector(e, i, n, s = null) {
744
- let r = C(i), o = 1;
745
- if (s !== null) {
746
- const h = s.elementWidth(this.offset, 0);
747
- h > r && (r = h), o += 2;
748
- }
749
- let u = f.KEY, l = s === null;
750
- for (let h = e; h < this.stack.length; h += n) {
751
- const w = this.stack[h].elementWidth(this.offset, h + o);
752
- w > r && (r = w), h === e ? (u = this.stack[h].type, l = l && te(u)) : u !== this.stack[h].type && (l = !1);
753
- }
754
- const d = this.align(r), a = l && kt(u) && i >= 2 && i <= 4;
755
- s !== null && (this.writeStackValue(s, d), this.writeUInt(1 << s.width, d)), a || this.writeUInt(i, d);
756
- const c = this.offset;
757
- for (let h = e; h < this.stack.length; h += n)
758
- this.writeStackValue(this.stack[h], d);
759
- if (!l)
760
- for (let h = e; h < this.stack.length; h += n)
761
- this.writeUInt(this.stack[h].storedPackedType(), 1);
762
- if (s !== null)
763
- return this.offsetStackValue(c, f.MAP, r);
764
- if (l) {
765
- const h = ee(u, a ? i : 0);
766
- return this.offsetStackValue(c, h, r);
767
- }
768
- return this.offsetStackValue(c, f.VECTOR, r);
769
- }
770
- nullStackValue() {
771
- return new L(this, f.NULL, p.WIDTH8);
772
- }
773
- boolStackValue(e) {
774
- return new L(this, f.BOOL, p.WIDTH8, e);
775
- }
776
- intStackValue(e) {
777
- return new L(this, f.INT, qt(e), e);
778
- }
779
- uintStackValue(e) {
780
- return new L(this, f.UINT, C(e), e);
781
- }
782
- floatStackValue(e) {
783
- return new L(this, f.FLOAT, Qt(e), e);
784
- }
785
- offsetStackValue(e, i, n) {
786
- return new L(this, i, n, null, e);
787
- }
788
- finishBuffer() {
789
- if (this.stack.length !== 1)
790
- 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]`;
791
- const e = this.stack[0], i = this.align(e.elementWidth(this.offset, 0));
792
- this.writeStackValue(e, i), this.writeUInt(e.storedPackedType(), 1), this.writeUInt(i, 1), this.finished = !0;
793
- }
794
- add(e) {
795
- if (this.integrityCheckOnValueAddition(), typeof e > "u")
796
- throw "You need to provide a value";
797
- if (e === null)
798
- this.stack.push(this.nullStackValue());
799
- else if (typeof e == "boolean")
800
- this.stack.push(this.boolStackValue(e));
801
- else if (typeof e == "bigint")
802
- this.stack.push(this.intStackValue(e));
803
- else if (typeof e == "number")
804
- Number.isInteger(e) ? this.stack.push(this.intStackValue(e)) : this.stack.push(this.floatStackValue(e));
805
- else if (ArrayBuffer.isView(e))
806
- this.writeBlob(e.buffer);
807
- else if (typeof e == "string" || e instanceof String)
808
- this.writeString(e);
809
- else if (Array.isArray(e)) {
810
- this.startVector();
811
- for (let i = 0; i < e.length; i++)
812
- this.add(e[i]);
813
- this.end();
814
- } else if (typeof e == "object") {
815
- const i = Object.getOwnPropertyNames(e).sort();
816
- this.startMap(!0);
817
- for (let n = 0; n < i.length; n++) {
818
- const s = i[n];
819
- this.addKey(s), this.add(e[s]);
820
- }
821
- this.end();
822
- } else
823
- throw `Unexpected value input ${e}`;
824
- }
825
- finish() {
826
- this.finished || this.finishBuffer();
827
- const e = this.buffer.slice(0, this.offset);
828
- return new Uint8Array(e);
829
- }
830
- isFinished() {
831
- return this.finished;
832
- }
833
- addKey(e) {
834
- this.integrityCheckOnKeyAddition(), this.writeKey(e);
835
- }
836
- addInt(e, i = !1, n = !1) {
837
- if (this.integrityCheckOnValueAddition(), !i) {
838
- this.stack.push(this.intStackValue(e));
839
- return;
840
- }
841
- if (n && Object.prototype.hasOwnProperty.call(this.indirectIntLookup, e)) {
842
- this.stack.push(this.indirectIntLookup[e]);
843
- return;
844
- }
845
- const s = this.intStackValue(e), r = this.align(s.width), o = this.computeOffset(r), u = this.offset;
846
- s.writeToBuffer(r);
847
- const l = this.offsetStackValue(u, f.INDIRECT_INT, s.width);
848
- this.stack.push(l), this.offset = o, n && (this.indirectIntLookup[e] = l);
849
- }
850
- addUInt(e, i = !1, n = !1) {
851
- if (this.integrityCheckOnValueAddition(), !i) {
852
- this.stack.push(this.uintStackValue(e));
853
- return;
854
- }
855
- if (n && Object.prototype.hasOwnProperty.call(this.indirectUIntLookup, e)) {
856
- this.stack.push(this.indirectUIntLookup[e]);
857
- return;
858
- }
859
- const s = this.uintStackValue(e), r = this.align(s.width), o = this.computeOffset(r), u = this.offset;
860
- s.writeToBuffer(r);
861
- const l = this.offsetStackValue(u, f.INDIRECT_UINT, s.width);
862
- this.stack.push(l), this.offset = o, n && (this.indirectUIntLookup[e] = l);
863
- }
864
- addFloat(e, i = !1, n = !1) {
865
- if (this.integrityCheckOnValueAddition(), !i) {
866
- this.stack.push(this.floatStackValue(e));
867
- return;
868
- }
869
- if (n && Object.prototype.hasOwnProperty.call(this.indirectFloatLookup, e)) {
870
- this.stack.push(this.indirectFloatLookup[e]);
871
- return;
872
- }
873
- const s = this.floatStackValue(e), r = this.align(s.width), o = this.computeOffset(r), u = this.offset;
874
- s.writeToBuffer(r);
875
- const l = this.offsetStackValue(u, f.INDIRECT_FLOAT, s.width);
876
- this.stack.push(l), this.offset = o, n && (this.indirectFloatLookup[e] = l);
877
- }
878
- }
879
- function X(t, e, i) {
880
- return i < 2 ? i < 1 ? t.getInt8(e) : t.getInt16(e, !0) : i < 3 ? t.getInt32(e, !0) : t.setBigInt64 === void 0 ? BigInt(t.getUint32(e, !0)) + (BigInt(t.getUint32(e + 4, !0)) << BigInt(32)) : t.getBigInt64(e, !0);
881
- }
882
- function k(t, e, i) {
883
- return i < 2 ? i < 1 ? t.getUint8(e) : t.getUint16(e, !0) : i < 3 ? t.getUint32(e, !0) : t.getBigUint64 === void 0 ? BigInt(t.getUint32(e, !0)) + (BigInt(t.getUint32(e + 4, !0)) << BigInt(32)) : t.getBigUint64(e, !0);
884
- }
885
- function st(t, e, i) {
886
- if (i < p.WIDTH32)
887
- throw "Bad width: " + i;
888
- return i === p.WIDTH32 ? t.getFloat32(e, !0) : t.getFloat64(e, !0);
889
- }
890
- function m(t, e, i) {
891
- const n = k(t, e, i);
892
- return e - n;
893
- }
894
- function oe(t, e, i, n, s, r) {
895
- const o = Q(t), u = m(e, i, n) - s * 3, l = g(s), d = u - Number(k(e, u, l)), a = Number(k(e, u + s, l));
896
- let c = 0, h = r - 1;
897
- for (; c <= h; ) {
898
- const w = h + c >> 1, y = ae(o, w, e, d, a);
899
- if (y === 0) return w;
900
- y < 0 ? h = w - 1 : c = w + 1;
901
- }
902
- return null;
903
- }
904
- function ae(t, e, i, n, s) {
905
- const r = n + e * s, o = r - Number(k(i, r, g(s)));
906
- for (let u = 0; u < t.length; u++) {
907
- const l = t[u] - i.getUint8(o + u);
908
- if (l !== 0)
909
- return l;
910
- }
911
- return i.getUint8(o + t.length) === 0 ? 0 : -1;
912
- }
913
- function fe(t, e, i, n, s) {
914
- const r = m(e, i, n) - s * 3, o = g(s), u = r - Number(k(e, r, o)), l = Number(k(e, r + s, o)), d = u + t * l, a = d - Number(k(e, d, g(l)));
915
- let c = 0;
916
- for (; e.getUint8(a + c) !== 0; )
917
- c++;
918
- return mt(new Uint8Array(e.buffer, a, c));
919
- }
920
- function et(t) {
921
- const e = t.byteLength;
922
- if (e < 3)
923
- throw "Buffer needs to be bigger than 3";
924
- const i = new DataView(t), n = i.getUint8(e - 1), s = i.getUint8(e - 2), r = g(n), o = e - n - 2;
925
- return new G(i, o, r, s, "/");
926
- }
927
- function rt(t, e, i, n, s, r, o, u) {
928
- const l = m(i, n, s), d = l + t * r, a = i.getUint8(l + o * r + t);
929
- return new G(i, d, g(r), a, `${u}/${e}`);
930
- }
931
- class G {
932
- constructor(e, i, n, s, r) {
933
- this.dataView = e, this.offset = i, this.parentWidth = n, this.packedType = s, this.path = r, this._length = -1, this.byteWidth = 1 << (s & 3), this.valueType = s >> 2;
934
- }
935
- isNull() {
936
- return this.valueType === f.NULL;
937
- }
938
- isNumber() {
939
- return kt(this.valueType) || Zt(this.valueType);
940
- }
941
- isFloat() {
942
- return f.FLOAT === this.valueType || f.INDIRECT_FLOAT === this.valueType;
943
- }
944
- isInt() {
945
- return this.isNumber() && !this.isFloat();
946
- }
947
- isString() {
948
- return f.STRING === this.valueType || f.KEY === this.valueType;
949
- }
950
- isBool() {
951
- return f.BOOL === this.valueType;
952
- }
953
- isBlob() {
954
- return f.BLOB === this.valueType;
955
- }
956
- isVector() {
957
- return $(this.valueType);
958
- }
959
- isMap() {
960
- return f.MAP === this.valueType;
961
- }
962
- boolValue() {
963
- return this.isBool() ? X(this.dataView, this.offset, this.parentWidth) > 0 : null;
964
- }
965
- intValue() {
966
- return this.valueType === f.INT ? X(this.dataView, this.offset, this.parentWidth) : this.valueType === f.UINT ? k(this.dataView, this.offset, this.parentWidth) : this.valueType === f.INDIRECT_INT ? X(this.dataView, m(this.dataView, this.offset, this.parentWidth), g(this.byteWidth)) : this.valueType === f.INDIRECT_UINT ? k(this.dataView, m(this.dataView, this.offset, this.parentWidth), g(this.byteWidth)) : null;
967
- }
968
- floatValue() {
969
- return this.valueType === f.FLOAT ? st(this.dataView, this.offset, this.parentWidth) : this.valueType === f.INDIRECT_FLOAT ? st(this.dataView, m(this.dataView, this.offset, this.parentWidth), g(this.byteWidth)) : null;
970
- }
971
- numericValue() {
972
- return this.floatValue() || this.intValue();
973
- }
974
- stringValue() {
975
- if (this.valueType === f.STRING || this.valueType === f.KEY) {
976
- const e = m(this.dataView, this.offset, this.parentWidth);
977
- return mt(new Uint8Array(this.dataView.buffer, e, this.length()));
978
- }
979
- return null;
980
- }
981
- blobValue() {
982
- if (this.isBlob()) {
983
- const e = m(this.dataView, this.offset, this.parentWidth);
984
- return new Uint8Array(this.dataView.buffer, e, this.length());
985
- }
986
- return null;
987
- }
988
- get(e) {
989
- const i = this.length();
990
- if (Number.isInteger(e) && $(this.valueType)) {
991
- if (e >= i || e < 0)
992
- throw `Key: [${e}] is not applicable on ${this.path} of ${this.valueType} length: ${i}`;
993
- const n = m(this.dataView, this.offset, this.parentWidth), s = n + e * this.byteWidth;
994
- let r = this.dataView.getUint8(n + i * this.byteWidth + e);
995
- if (bt(this.valueType)) {
996
- const o = ie(this.valueType);
997
- r = tt(o, p.WIDTH8);
998
- } else if (Z(this.valueType)) {
999
- const o = ne(this.valueType);
1000
- r = tt(o, p.WIDTH8);
1001
- }
1002
- return new G(this.dataView, s, g(this.byteWidth), r, `${this.path}[${e}]`);
1003
- }
1004
- if (typeof e == "string") {
1005
- const n = oe(e, this.dataView, this.offset, this.parentWidth, this.byteWidth, i);
1006
- if (n !== null)
1007
- return rt(n, e, this.dataView, this.offset, this.parentWidth, this.byteWidth, i, this.path);
1008
- }
1009
- throw `Key [${e}] is not applicable on ${this.path} of ${this.valueType}`;
1010
- }
1011
- length() {
1012
- let e;
1013
- if (this._length > -1)
1014
- return this._length;
1015
- if (Z(this.valueType))
1016
- this._length = se(this.valueType);
1017
- else if (this.valueType === f.BLOB || this.valueType === f.MAP || $(this.valueType))
1018
- this._length = k(this.dataView, m(this.dataView, this.offset, this.parentWidth) - this.byteWidth, g(this.byteWidth));
1019
- else if (this.valueType === f.NULL)
1020
- this._length = 0;
1021
- else if (this.valueType === f.STRING) {
1022
- const i = m(this.dataView, this.offset, this.parentWidth);
1023
- let n = this.byteWidth;
1024
- for (e = k(this.dataView, i - n, g(this.byteWidth)); this.dataView.getInt8(i + e) !== 0; )
1025
- n <<= 1, e = k(this.dataView, i - n, g(this.byteWidth));
1026
- this._length = e;
1027
- } else if (this.valueType === f.KEY) {
1028
- const i = m(this.dataView, this.offset, this.parentWidth);
1029
- for (e = 1; this.dataView.getInt8(i + e) !== 0; )
1030
- e++;
1031
- this._length = e;
1032
- } else
1033
- this._length = 1;
1034
- return Number(this._length);
1035
- }
1036
- toObject() {
1037
- const e = this.length();
1038
- if (this.isVector()) {
1039
- const i = [];
1040
- for (let n = 0; n < e; n++)
1041
- i.push(this.get(n).toObject());
1042
- return i;
1043
- }
1044
- if (this.isMap()) {
1045
- const i = {};
1046
- for (let n = 0; n < e; n++) {
1047
- const s = fe(n, this.dataView, this.offset, this.parentWidth, this.byteWidth);
1048
- i[s] = rt(n, s, this.dataView, this.offset, this.parentWidth, this.byteWidth, e, this.path).toObject();
1049
- }
1050
- return i;
1051
- }
1052
- return this.isNull() ? null : this.isBool() ? this.boolValue() : this.isNumber() ? this.numericValue() : this.blobValue() || this.stringValue();
1053
- }
1054
- }
1055
- function K() {
1056
- return new re();
1057
- }
1058
- function ce(t) {
1059
- const e = K();
1060
- e.startMap();
1061
- for (const [i, n] of Object.entries(t))
1062
- e.addKey(i), e.add(n);
1063
- return e.end(), e.finish();
1064
- }
1065
- function _(t, e, i, n, s = 1) {
1066
- let r;
1067
- if (i === b.FLEX)
1068
- r = ce(t);
1069
- else if (i === b.JSON)
1070
- r = new TextEncoder().encode(JSON.stringify(t));
1071
- else
1072
- throw new Error("Unsupported format for wrapEnvelope");
1073
- const o = K();
1074
- return o.startMap(), o.addKey("version"), o.add(s), o.addKey("kind"), o.add(e), o.addKey("format"), o.add(i), o.addKey("payload"), o.add(r), o.addKey("metadata"), o.add(n ?? new Uint8Array()), o.end(), o.finish();
1075
- }
1076
- function Nt(t) {
1077
- const e = t instanceof Uint8Array ? t : new Uint8Array(t), i = et(e.buffer).toObject();
1078
- if (typeof i.version != "number" || typeof i.kind != "number" || typeof i.format != "number" || !i.payload)
1079
- throw console.error("[unwrapEnvelope] Bad root:", i), new Error("[unwrapEnvelope] Invalid envelope structure");
1080
- const n = {
1081
- version: i.version,
1082
- kind: i.kind,
1083
- format: i.format,
1084
- payload: new Uint8Array(i.payload),
1085
- metadata: i.metadata ? new Uint8Array(i.metadata) : void 0
1086
- };
1087
- let s;
1088
- if (n.format === b.FLEX)
1089
- s = et(n.payload.buffer).toObject();
1090
- else if (n.format === b.JSON)
1091
- s = JSON.parse(new TextDecoder().decode(n.payload));
1092
- else
1093
- throw new Error(`[unwrapEnvelope] Unsupported format: ${n.format}`);
1094
- return { envelope: n, payload: s };
1095
- }
1096
- function St(t) {
1097
- return et(t.buffer).toObject();
1098
- }
1099
- function he(t) {
1100
- try {
1101
- const e = t instanceof Uint8Array ? t : new Uint8Array(t), i = St(e);
1102
- console.log("[FlexObject]", JSON.stringify(i, null, 2));
1103
- } catch (e) {
1104
- console.error("[Flex Decode Error]", e);
1105
- }
1106
- }
1107
- function Rt(t, e) {
1108
- return (t & e) === e;
1109
- }
1110
- function le(t, e) {
1111
- return _(
1112
- { key: t, value: e },
1113
- O.SET | O.REDIS,
1114
- b.FLEX
1115
- );
1116
- }
1117
- function ue(t) {
1118
- return _(
1119
- { key: t },
1120
- O.GET | O.REDIS,
1121
- b.FLEX
1122
- );
1123
- }
1124
- function de(t) {
1125
- return _(
1126
- { key: t },
1127
- O.DEL | O.REDIS,
1128
- b.FLEX
1129
- );
1130
- }
1131
- function pe(t) {
1132
- const e = Nt(t);
1133
- if (!Rt(e.envelope.kind, O.REDIS))
1134
- throw new Error("[Redis] Not a Redis envelope");
1135
- return e;
1136
- }
1137
- function we(t, e, i = "*") {
1138
- return _(
1139
- { stream: t, id: i, fields: e },
1140
- O.ADD | O.STREAM | O.REDIS,
1141
- b.FLEX
1142
- );
1143
- }
1144
- function ye(t, e, i) {
1145
- const n = K();
1146
- n.startMap(), n.addKey("streams"), n.startVector();
1147
- for (const { stream: o, id: u } of t)
1148
- n.startMap(), n.addKey("stream"), n.add(o), n.addKey("id"), n.add(u), n.end();
1149
- n.end(), e !== void 0 && (n.addKey("count"), n.add(e)), i !== void 0 && (n.addKey("block"), n.add(i)), n.end();
1150
- const s = n.finish(), r = K();
1151
- return r.startMap(), r.addKey("version"), r.add(1), r.addKey("kind"), r.add(O.READ | O.STREAM | O.REDIS), r.addKey("format"), r.add(b.FLEX), r.addKey("payload"), r.add(s), r.addKey("metadata"), r.add(new Uint8Array()), r.end(), r.finish();
1152
- }
1153
- const ge = {
1154
- wrapEnvelope: _,
1155
- unwrapEnvelope: Nt,
1156
- MessageKind: O,
1157
- PayloadFormat: b,
1158
- unwrapFlexToJson: St,
1159
- inspectFlex: he,
1160
- hasKind: Rt,
1161
- redis: {
1162
- wrapRedisSet: le,
1163
- wrapRedisGet: ue,
1164
- wrapRedisDel: de,
1165
- wrapRedisXAdd: we,
1166
- wrapRedisXRead: ye,
1167
- parseRedisPayload: pe
1168
- }
1169
- };
1170
- function vt(t) {
1171
- typeof queueMicrotask == "function" ? queueMicrotask(t) : setTimeout(t, 0);
1172
- }
1173
- function Lt(t) {
1174
- const e = document.createElement(t.tag);
1175
- if (t.class && (e.className = t.class), t.attrs)
1176
- for (const [i, n] of Object.entries(t.attrs))
1177
- if (typeof n == "function" && i.startsWith("on"))
1178
- e.addEventListener(i.slice(2).toLowerCase(), n);
1179
- else if (i === "style" && typeof n == "object")
1180
- Object.assign(e.style, n);
1181
- else if (i === "dataset" && typeof n == "object")
1182
- for (const [s, r] of Object.entries(n))
1183
- e.dataset[s] = String(r);
1184
- else
1185
- try {
1186
- e.setAttribute(i, String(n));
1187
- } catch {
1188
- }
1189
- if (t.style && Object.assign(e.style, t.style), t.children)
1190
- for (const i of t.children) {
1191
- const n = typeof i == "string" ? document.createTextNode(i) : Lt(i);
1192
- e.appendChild(n);
1193
- }
1194
- return e;
1195
- }
1196
- const Te = T.enum(["top", "right", "bottom", "left"]), Ee = T.object({
1197
- width: T.number(),
1198
- height: T.number(),
1199
- mode: T.enum(["static", "animated", "dynamic"]).optional()
1200
- });
1201
- T.object({
1202
- rawHtml: T.string().optional(),
1203
- needsCanvas: T.boolean().optional(),
1204
- canvasOptions: Ee.optional()
1205
- });
1206
- const Oe = T.object({
1207
- name: T.string(),
1208
- version: T.string().optional()
1209
- }), Ie = T.object({
1210
- meta: Oe.optional(),
1211
- timestamp: T.number()
1212
- }), ot = T.object({
1213
- id: Te,
1214
- payload: T.any().optional()
1215
- }), me = T.object({
1216
- timestamp: T.number()
1217
- }), ke = {
1218
- "droid-ready": me,
1219
- "droid-mod-ready": Ie,
1220
- "panel-open": ot,
1221
- "panel-close": ot
1222
- };
1223
- class be {
1224
- listeners = /* @__PURE__ */ new Map();
1225
- on(e, i) {
1226
- let n = this.listeners.get(e);
1227
- n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), n.add(i);
1228
- }
1229
- off(e, i) {
1230
- this.listeners.get(e)?.delete(i);
1231
- }
1232
- emit(e, i) {
1233
- const n = ke[e];
1234
- if (n)
1235
- try {
1236
- n.parse(i);
1237
- } catch (s) {
1238
- console.error(`[DroidEventBus] Invalid payload for ${e}:`, s);
1239
- return;
1240
- }
1241
- window.dispatchEvent(new CustomEvent(e, { detail: i }));
1242
- for (const s of this.listeners.get(e) ?? [])
1243
- s(i);
1244
- }
1245
- wait(e) {
1246
- return new Promise((i) => {
1247
- const n = (s) => {
1248
- this.off(e, n), i(s);
1249
- };
1250
- this.on(e, n);
1251
- });
1252
- }
1253
- }
1254
- const Ne = new be(), at = "1.0.3";
1255
- async function Se() {
1256
- const t = new SharedWorker(new URL(
1257
- /* @vite-ignore */
1258
- "/assets/ws-worker-FssAQgaD.js",
1259
- import.meta.url
1260
- ), {
1261
- type: "module"
1262
- });
1263
- return t.port.start(), V(t.port);
1264
- }
1265
- const I = Ot(
1266
- "uiux-state",
1267
- {
1268
- panelManager: {
1269
- top: { open: !1 },
1270
- right: { open: !1 },
1271
- bottom: { open: !1 },
1272
- left: { open: !1 }
1273
- },
1274
- themeManager: { theme: "auto" },
1275
- toastManager: {},
1276
- scrollY: 0
1277
- },
1278
- {
1279
- encode: JSON.stringify,
1280
- decode: JSON.parse
1281
- }
1282
- ), Re = V(
1283
- new Worker(new URL(
1284
- /* @vite-ignore */
1285
- "/assets/canvas-worker-DbsoY2Xv.js",
1286
- import.meta.url
1287
- ), { type: "module" })
1288
- ), ft = {
1289
- state: I,
1290
- worker: Re,
1291
- openPanel(t, e) {
1292
- const i = { ...I.get().panelManager };
1293
- i[t] = { open: !0, payload: e }, I.setKey("panelManager", i);
1294
- },
1295
- closePanel(t) {
1296
- const e = { ...I.get().panelManager };
1297
- e[t] = { open: !1, payload: void 0 }, I.setKey("panelManager", e);
1298
- },
1299
- togglePanel(t, e) {
1300
- const i = { ...I.get().panelManager }, n = i[t]?.open ?? !1;
1301
- i[t] = { open: !n, payload: n ? void 0 : e }, I.setKey("panelManager", i);
1302
- },
1303
- setTheme(t) {
1304
- I.setKey("themeManager", { theme: t });
1305
- },
1306
- addToast(t, e) {
1307
- const i = { ...I.get().toastManager, [t]: e };
1308
- I.setKey("toastManager", i);
1309
- },
1310
- removeToast(t) {
1311
- const e = { ...I.get().toastManager };
1312
- delete e[t], I.setKey("toastManager", e);
1313
- },
1314
- async dispatchCanvasRequest(t, e, i = "animated") {
1315
- const n = e.transferControlToOffscreen();
1316
- await this.worker.bindCanvas(t, n, i);
1317
- },
1318
- closeAllPanels() {
1319
- const t = { ...I.get().panelManager };
1320
- console.log("error panel is closing");
1321
- for (const e of Object.keys(t))
1322
- t[e] = { open: !1, payload: void 0 };
1323
- I.setKey("panelManager", t);
1324
- },
1325
- emitFromWorker(t) {
1326
- t.type === "injectVNode" && t.vnode && vt(() => {
1327
- const e = document.getElementById("bento-grid-inject");
1328
- if (!e) {
1329
- console.warn(
1330
- "[KBVE] No injection target found: #bento-grid-inject"
1331
- );
1332
- return;
1333
- }
1334
- const i = Lt(t.vnode);
1335
- if (i.classList.add("animate-fade-in"), t.vnode.id) {
1336
- const n = document.getElementById(t.vnode.id);
1337
- n && n.remove();
1338
- }
1339
- e.appendChild(i);
1340
- });
1341
- }
1342
- }, A = Ot(
1343
- "i18n-cache",
1344
- {},
1345
- {
1346
- encode: JSON.stringify,
1347
- decode: JSON.parse
1348
- }
1349
- ), D = {
1350
- store: A,
1351
- api: null,
1352
- ready: Promise.resolve(),
1353
- get(t) {
1354
- return A.get()[t] ?? `[${t}]`;
1355
- },
1356
- async getAsync(t) {
1357
- const e = A.get()[t];
1358
- if (e !== void 0) return e;
1359
- if (!this.api) return `[${t}]`;
1360
- const i = await this.api.getTranslation(t);
1361
- return i !== null ? (A.setKey(t, i), i) : `[${t}]`;
1362
- },
1363
- set(t, e) {
1364
- A.setKey(t, e);
1365
- },
1366
- async hydrate(t, e) {
1367
- this.api = t;
1368
- for (const i of e) {
1369
- const n = await t.getTranslation(i);
1370
- n !== null && A.setKey(i, n);
1371
- }
1372
- },
1373
- async hydrateLocale(t = "en") {
1374
- if (!this.api) return;
1375
- const i = (await this.api.getAllI18nKeys()).filter(
1376
- (s) => s.startsWith(`${t}:`)
1377
- ), n = await this.api.getTranslations(i);
1378
- for (const [s, r] of Object.entries(n))
1379
- console.log(`[i18n.setKey] ${s} = ${r}`), this.store.setKey(s, r);
1380
- }
1381
- };
1382
- function ct() {
1383
- if (!navigator.serviceWorker?.controller) return;
1384
- const t = new MessageChannel();
1385
- navigator.serviceWorker.controller.postMessage(t.port2, [
1386
- t.port2
1387
- ]), t.port1.start();
1388
- }
1389
- async function ve() {
1390
- const t = new SharedWorker(new URL(
1391
- /* @vite-ignore */
1392
- "/assets/db-worker-CjXS52DQ.js",
1393
- import.meta.url
1394
- ), {
1395
- type: "module"
1396
- });
1397
- t.port.start();
1398
- const e = V(t.port);
1399
- return await e.getVersion() !== at && await $t(e, {
1400
- version: at,
1401
- i18nPath: "https://discord.sh/i18n/db.json",
1402
- locale: "en",
1403
- defaults: { welcome: "Welcome!", theme: "dark" }
1404
- }), e;
1405
- }
1406
- let ht = !1;
1407
- function Le(t, e) {
1408
- const i = Et(async (n) => {
1409
- vt(() => {
1410
- const s = `ws:${Date.now()}`;
1411
- e.storeWsMessage(s, n);
1412
- });
1413
- });
1414
- t.onMessage(Tt(i, [0]));
1415
- }
1416
- async function Ue() {
1417
- if (ht || (ht = !0, navigator.serviceWorker?.controller ? ct() : navigator.serviceWorker?.addEventListener(
1418
- "controllerchange",
1419
- ct
1420
- )), !window.kbve?.api || !window.kbve?.i18n || !window.kbve?.uiux) {
1421
- const e = await ve(), i = await Se(), n = await Xt(), s = Ne;
1422
- for (const o of Object.values(n.registry))
1423
- typeof o.instance.init == "function" && await o.instance.init({
1424
- emitFromWorker: ft.emitFromWorker
1425
- }), console.log("[Event] -> Fire Mod Ready"), s.emit("droid-mod-ready", {
1426
- meta: o.meta,
1427
- timestamp: Date.now()
1428
- });
1429
- Le(i, e);
1430
- const r = ge;
1431
- D.api = e, D.ready = D.hydrateLocale("en"), window.kbve = {
1432
- ...window.kbve || {},
1433
- api: e,
1434
- i18n: D,
1435
- uiux: ft,
1436
- ws: i,
1437
- data: r,
1438
- mod: n,
1439
- events: s
1440
- }, await D.ready, window.kbve.events.emit("droid-ready", {
1441
- timestamp: Date.now()
1442
- }), document.addEventListener("astro:page-load", () => {
1443
- console.debug("[KBVE] Re-dispatched droid-ready after astro:page-load"), window.kbve?.events.emit("droid-ready", {
1444
- timestamp: Date.now()
1445
- });
1446
- }), console.log("[KBVE] Global API ready");
1447
- } else
1448
- console.log("[KBVE] Already initialized");
1449
- }
1450
- export {
1451
- Le as bridgeWsToDb,
1452
- D as i18n,
1453
- Ue as main,
1454
- ft as uiux
1455
- };