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