@kbve/droid 0.0.2 → 0.0.3

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.
@@ -0,0 +1,259 @@
1
+ var T = /* @__PURE__ */ ((t) => (t[t.WIDTH8 = 0] = "WIDTH8", t[t.WIDTH16 = 1] = "WIDTH16", t[t.WIDTH32 = 2] = "WIDTH32", t[t.WIDTH64 = 3] = "WIDTH64", t))(T || {});
2
+ function S(t) {
3
+ return 1 << t;
4
+ }
5
+ function K(t) {
6
+ return t >= -128 && t <= 127 ? T.WIDTH8 : t >= -32768 && t <= 32767 ? T.WIDTH16 : t >= -2147483648 && t <= 2147483647 ? T.WIDTH32 : T.WIDTH64;
7
+ }
8
+ function $(t) {
9
+ return t === Math.fround(t) ? T.WIDTH32 : T.WIDTH64;
10
+ }
11
+ function x(t) {
12
+ return t <= 255 ? T.WIDTH8 : t <= 65535 ? T.WIDTH16 : t <= 4294967295 ? T.WIDTH32 : T.WIDTH64;
13
+ }
14
+ function f(t) {
15
+ return t === 1 ? T.WIDTH8 : t === 2 ? T.WIDTH16 : t === 4 ? T.WIDTH32 : T.WIDTH64;
16
+ }
17
+ function G(t, i) {
18
+ return ~t + 1 & i - 1;
19
+ }
20
+ function U(t) {
21
+ return new TextDecoder().decode(t);
22
+ }
23
+ function p(t) {
24
+ return new TextEncoder().encode(t);
25
+ }
26
+ var e = /* @__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))(e || {});
27
+ function M(t) {
28
+ return t === e.BOOL || t <= e.FLOAT;
29
+ }
30
+ function B(t) {
31
+ return t >= e.INT && t <= e.FLOAT;
32
+ }
33
+ function F(t) {
34
+ return t >= e.INDIRECT_INT && t <= e.INDIRECT_FLOAT;
35
+ }
36
+ function P(t) {
37
+ return t === e.BOOL || t >= e.INT && t <= e.STRING;
38
+ }
39
+ function A(t) {
40
+ return t === e.VECTOR_BOOL || t >= e.VECTOR_INT && t <= e.VECTOR_STRING_DEPRECATED;
41
+ }
42
+ function a(t) {
43
+ return t >= e.VECTOR_INT2 && t <= e.VECTOR_FLOAT4;
44
+ }
45
+ function g(t) {
46
+ return A(t) || a(t) || t === e.VECTOR;
47
+ }
48
+ function Y(t, i) {
49
+ if (i === 0) return t - e.INT + e.VECTOR_INT;
50
+ if (i === 2) return t - e.INT + e.VECTOR_INT2;
51
+ if (i === 3) return t - e.INT + e.VECTOR_INT3;
52
+ if (i === 4) return t - e.INT + e.VECTOR_INT4;
53
+ throw "Unexpected length " + i;
54
+ }
55
+ function H(t) {
56
+ return t - e.VECTOR_INT + e.INT;
57
+ }
58
+ function m(t) {
59
+ return (t - e.VECTOR_INT2) % 3 + e.INT;
60
+ }
61
+ function w(t) {
62
+ return ((t - e.VECTOR_INT2) / 3 >> 0) + 2;
63
+ }
64
+ function b(t, i) {
65
+ return i | t << 2;
66
+ }
67
+ function C(t, i, n) {
68
+ return n < 2 ? n < 1 ? t.getInt8(i) : t.getInt16(i, !0) : n < 3 ? t.getInt32(i, !0) : t.setBigInt64 === void 0 ? BigInt(t.getUint32(i, !0)) + (BigInt(t.getUint32(i + 4, !0)) << BigInt(32)) : t.getBigInt64(i, !0);
69
+ }
70
+ function c(t, i, n) {
71
+ return n < 2 ? n < 1 ? t.getUint8(i) : t.getUint16(i, !0) : n < 3 ? t.getUint32(i, !0) : t.getBigUint64 === void 0 ? BigInt(t.getUint32(i, !0)) + (BigInt(t.getUint32(i + 4, !0)) << BigInt(32)) : t.getBigUint64(i, !0);
72
+ }
73
+ function D(t, i, n) {
74
+ if (n < T.WIDTH32)
75
+ throw "Bad width: " + n;
76
+ return n === T.WIDTH32 ? t.getFloat32(i, !0) : t.getFloat64(i, !0);
77
+ }
78
+ function I(t, i, n) {
79
+ const r = c(t, i, n);
80
+ return i - r;
81
+ }
82
+ function V(t, i, n, r, s, h) {
83
+ const o = p(t), u = I(i, n, r) - s * 3, O = f(s), N = u - Number(c(i, u, O)), E = Number(c(i, u + s, O));
84
+ let d = 0, l = h - 1;
85
+ for (; d <= l; ) {
86
+ const _ = l + d >> 1, W = v(o, _, i, N, E);
87
+ if (W === 0) return _;
88
+ W < 0 ? l = _ - 1 : d = _ + 1;
89
+ }
90
+ return null;
91
+ }
92
+ function v(t, i, n, r, s) {
93
+ const h = r + i * s, o = h - Number(c(n, h, f(s)));
94
+ for (let u = 0; u < t.length; u++) {
95
+ const O = t[u] - n.getUint8(o + u);
96
+ if (O !== 0)
97
+ return O;
98
+ }
99
+ return n.getUint8(o + t.length) === 0 ? 0 : -1;
100
+ }
101
+ function y(t, i, n, r, s) {
102
+ const h = I(i, n, r) - s * 3, o = f(s), u = h - Number(c(i, h, o)), O = Number(c(i, h + s, o)), N = u + t * O, E = N - Number(c(i, N, f(O)));
103
+ let d = 0;
104
+ for (; i.getUint8(E + d) !== 0; )
105
+ d++;
106
+ return U(new Uint8Array(i.buffer, E, d));
107
+ }
108
+ function j(t) {
109
+ const i = t.byteLength;
110
+ if (i < 3)
111
+ throw "Buffer needs to be bigger than 3";
112
+ const n = new DataView(t), r = n.getUint8(i - 1), s = n.getUint8(i - 2), h = f(r), o = i - r - 2;
113
+ return new R(n, o, h, s, "/");
114
+ }
115
+ function L(t, i, n, r, s, h, o, u) {
116
+ const O = I(n, r, s), N = O + t * h, E = n.getUint8(O + o * h + t);
117
+ return new R(n, N, f(h), E, `${u}/${i}`);
118
+ }
119
+ class R {
120
+ constructor(i, n, r, s, h) {
121
+ this.dataView = i, this.offset = n, this.parentWidth = r, this.packedType = s, this.path = h, this._length = -1, this.byteWidth = 1 << (s & 3), this.valueType = s >> 2;
122
+ }
123
+ isNull() {
124
+ return this.valueType === e.NULL;
125
+ }
126
+ isNumber() {
127
+ return B(this.valueType) || F(this.valueType);
128
+ }
129
+ isFloat() {
130
+ return e.FLOAT === this.valueType || e.INDIRECT_FLOAT === this.valueType;
131
+ }
132
+ isInt() {
133
+ return this.isNumber() && !this.isFloat();
134
+ }
135
+ isString() {
136
+ return e.STRING === this.valueType || e.KEY === this.valueType;
137
+ }
138
+ isBool() {
139
+ return e.BOOL === this.valueType;
140
+ }
141
+ isBlob() {
142
+ return e.BLOB === this.valueType;
143
+ }
144
+ isVector() {
145
+ return g(this.valueType);
146
+ }
147
+ isMap() {
148
+ return e.MAP === this.valueType;
149
+ }
150
+ boolValue() {
151
+ return this.isBool() ? C(this.dataView, this.offset, this.parentWidth) > 0 : null;
152
+ }
153
+ intValue() {
154
+ return this.valueType === e.INT ? C(this.dataView, this.offset, this.parentWidth) : this.valueType === e.UINT ? c(this.dataView, this.offset, this.parentWidth) : this.valueType === e.INDIRECT_INT ? C(this.dataView, I(this.dataView, this.offset, this.parentWidth), f(this.byteWidth)) : this.valueType === e.INDIRECT_UINT ? c(this.dataView, I(this.dataView, this.offset, this.parentWidth), f(this.byteWidth)) : null;
155
+ }
156
+ floatValue() {
157
+ return this.valueType === e.FLOAT ? D(this.dataView, this.offset, this.parentWidth) : this.valueType === e.INDIRECT_FLOAT ? D(this.dataView, I(this.dataView, this.offset, this.parentWidth), f(this.byteWidth)) : null;
158
+ }
159
+ numericValue() {
160
+ return this.floatValue() || this.intValue();
161
+ }
162
+ stringValue() {
163
+ if (this.valueType === e.STRING || this.valueType === e.KEY) {
164
+ const i = I(this.dataView, this.offset, this.parentWidth);
165
+ return U(new Uint8Array(this.dataView.buffer, i, this.length()));
166
+ }
167
+ return null;
168
+ }
169
+ blobValue() {
170
+ if (this.isBlob()) {
171
+ const i = I(this.dataView, this.offset, this.parentWidth);
172
+ return new Uint8Array(this.dataView.buffer, i, this.length());
173
+ }
174
+ return null;
175
+ }
176
+ get(i) {
177
+ const n = this.length();
178
+ if (Number.isInteger(i) && g(this.valueType)) {
179
+ if (i >= n || i < 0)
180
+ throw `Key: [${i}] is not applicable on ${this.path} of ${this.valueType} length: ${n}`;
181
+ const r = I(this.dataView, this.offset, this.parentWidth), s = r + i * this.byteWidth;
182
+ let h = this.dataView.getUint8(r + n * this.byteWidth + i);
183
+ if (A(this.valueType)) {
184
+ const o = H(this.valueType);
185
+ h = b(o, T.WIDTH8);
186
+ } else if (a(this.valueType)) {
187
+ const o = m(this.valueType);
188
+ h = b(o, T.WIDTH8);
189
+ }
190
+ return new R(this.dataView, s, f(this.byteWidth), h, `${this.path}[${i}]`);
191
+ }
192
+ if (typeof i == "string") {
193
+ const r = V(i, this.dataView, this.offset, this.parentWidth, this.byteWidth, n);
194
+ if (r !== null)
195
+ return L(r, i, this.dataView, this.offset, this.parentWidth, this.byteWidth, n, this.path);
196
+ }
197
+ throw `Key [${i}] is not applicable on ${this.path} of ${this.valueType}`;
198
+ }
199
+ length() {
200
+ let i;
201
+ if (this._length > -1)
202
+ return this._length;
203
+ if (a(this.valueType))
204
+ this._length = w(this.valueType);
205
+ else if (this.valueType === e.BLOB || this.valueType === e.MAP || g(this.valueType))
206
+ this._length = c(this.dataView, I(this.dataView, this.offset, this.parentWidth) - this.byteWidth, f(this.byteWidth));
207
+ else if (this.valueType === e.NULL)
208
+ this._length = 0;
209
+ else if (this.valueType === e.STRING) {
210
+ const n = I(this.dataView, this.offset, this.parentWidth);
211
+ let r = this.byteWidth;
212
+ for (i = c(this.dataView, n - r, f(this.byteWidth)); this.dataView.getInt8(n + i) !== 0; )
213
+ r <<= 1, i = c(this.dataView, n - r, f(this.byteWidth));
214
+ this._length = i;
215
+ } else if (this.valueType === e.KEY) {
216
+ const n = I(this.dataView, this.offset, this.parentWidth);
217
+ for (i = 1; this.dataView.getInt8(n + i) !== 0; )
218
+ i++;
219
+ this._length = i;
220
+ } else
221
+ this._length = 1;
222
+ return Number(this._length);
223
+ }
224
+ toObject() {
225
+ const i = this.length();
226
+ if (this.isVector()) {
227
+ const n = [];
228
+ for (let r = 0; r < i; r++)
229
+ n.push(this.get(r).toObject());
230
+ return n;
231
+ }
232
+ if (this.isMap()) {
233
+ const n = {};
234
+ for (let r = 0; r < i; r++) {
235
+ const s = y(r, this.dataView, this.offset, this.parentWidth, this.byteWidth);
236
+ n[s] = L(r, s, this.dataView, this.offset, this.parentWidth, this.byteWidth, i, this.path).toObject();
237
+ }
238
+ return n;
239
+ }
240
+ return this.isNull() ? null : this.isBool() ? this.boolValue() : this.isNumber() ? this.numericValue() : this.blobValue() || this.stringValue();
241
+ }
242
+ }
243
+ export {
244
+ T as B,
245
+ e as V,
246
+ G as a,
247
+ p as b,
248
+ P as c,
249
+ B as d,
250
+ Y as e,
251
+ f,
252
+ K as g,
253
+ $ as h,
254
+ M as i,
255
+ j,
256
+ b as p,
257
+ S as t,
258
+ x as u
259
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,21 @@
1
1
  export * from './lib/droid';
2
2
  export * from './lib/types/bento';
3
3
  export * from './lib/mod/mod-urls';
4
+
5
+ export const workerURLs = {
6
+ canvasWorker: new URL(
7
+ './lib/workers/canvas-worker.js',
8
+ import.meta.url,
9
+ ),
10
+ dbWorker: new URL('./lib/workers/db-worker.js', import.meta.url),
11
+ wsWorker: new URL('./lib/workers/ws-worker.js', import.meta.url),
12
+ };
13
+
14
+ export const workerStrings = {
15
+ canvasWorker: new URL(
16
+ './lib/workers/canvas-worker.js',
17
+ import.meta.url,
18
+ ).toString(),
19
+ dbWorker: new URL('./lib/workers/db-worker.js', import.meta.url).toString(),
20
+ wsWorker: new URL('./lib/workers/ws-worker.js', import.meta.url).toString(),
21
+ };
package/src/lib/droid.ts CHANGED
@@ -1,5 +1,7 @@
1
- export async function droid(opts?: { canvas?: boolean }): Promise<{ initialized: boolean }> {
2
- const { main } = await import('./workers/main');
3
- await main();
1
+ export async function droid(opts?: { workerURLs?: Record<string, string> }): Promise<{ initialized: boolean }> {
2
+ console.log('[DROID]: droid<T>');
3
+ const { main } = await import('./workers/main.js');
4
+ await main({ workerURLs: opts?.workerURLs });
5
+ console.log('[DROID]: droid<T> => await WorkerURLs');
4
6
  return { initialized: true };
5
7
  }
@@ -5,13 +5,14 @@ import type { KBVEGlobal } from '../../types';
5
5
 
6
6
  let _modManager: ModManager | null = null;
7
7
 
8
- export async function getModManager(): Promise<ModManager> {
8
+ export async function getModManager(modWorkerResolver?: (url: string) => string): Promise<ModManager> {
9
9
  if (_modManager) return _modManager;
10
10
 
11
11
  const registry: Record<string, ModHandle> = {};
12
12
 
13
13
  async function load(url: string): Promise<ModHandle> {
14
- const worker = new Worker(url, { type: 'module' });
14
+ const resolvedURL = modWorkerResolver?.(url) ?? url;
15
+ const worker = new Worker(resolvedURL, { type: 'module' });
15
16
  const instance = wrap<BaseModAPI>(worker);
16
17
 
17
18
  const meta: ModMeta = await instance.getMeta?.() ?? {