@kbve/droid 0.0.6 → 0.1.1

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.
Files changed (108) hide show
  1. package/comlink.js +1 -7
  2. package/droid.mjs +191 -61
  3. package/index.d.ts +29 -0
  4. package/index.js +9054 -2763
  5. package/lib/gateway/SupabaseGateway.d.ts +38 -0
  6. package/lib/gateway/SupabaseGateway.d.ts.map +1 -0
  7. package/lib/gateway/WorkerCommunication.d.ts +39 -0
  8. package/lib/gateway/WorkerCommunication.d.ts.map +1 -0
  9. package/lib/gateway/WorkerPool.d.ts +55 -0
  10. package/lib/gateway/WorkerPool.d.ts.map +1 -0
  11. package/lib/gateway/capabilities.d.ts +23 -0
  12. package/lib/gateway/capabilities.d.ts.map +1 -0
  13. package/lib/gateway/index.d.ts +9 -0
  14. package/lib/gateway/index.d.ts.map +1 -0
  15. package/lib/gateway/strategies/DirectStrategy.d.ts +52 -0
  16. package/lib/gateway/strategies/DirectStrategy.d.ts.map +1 -0
  17. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts +46 -0
  18. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts.map +1 -0
  19. package/lib/gateway/strategies/WebWorkerStrategy.d.ts +45 -0
  20. package/lib/gateway/strategies/WebWorkerStrategy.d.ts.map +1 -0
  21. package/lib/gateway/types.d.ts +81 -0
  22. package/lib/gateway/types.d.ts.map +1 -0
  23. package/lib/workers/canvas-ui-renderer.d.ts +25 -0
  24. package/lib/workers/canvas-ui-renderer.d.ts.map +1 -0
  25. package/lib/workers/canvas-worker.d.ts +14 -0
  26. package/lib/workers/canvas-worker.d.ts.map +1 -0
  27. package/lib/workers/canvas-worker.js +291 -145
  28. package/lib/workers/data.d.ts +40 -0
  29. package/lib/workers/data.d.ts.map +1 -0
  30. package/lib/workers/db-worker.d.ts +69 -0
  31. package/lib/workers/db-worker.d.ts.map +1 -0
  32. package/lib/workers/db-worker.js +2680 -2147
  33. package/lib/workers/events.d.ts +11 -0
  34. package/lib/workers/events.d.ts.map +1 -0
  35. package/lib/workers/flexbuilder.d.ts +4 -0
  36. package/lib/workers/flexbuilder.d.ts.map +1 -0
  37. package/lib/workers/init.d.ts +11 -0
  38. package/lib/workers/init.d.ts.map +1 -0
  39. package/lib/workers/main.d.ts +107 -0
  40. package/lib/workers/main.d.ts.map +1 -0
  41. package/lib/workers/supabase-db-worker.d.ts +2 -0
  42. package/lib/workers/supabase-db-worker.d.ts.map +1 -0
  43. package/lib/workers/supabase-db-worker.js +9337 -0
  44. package/lib/workers/supabase-shared-worker.d.ts +2 -0
  45. package/lib/workers/supabase-shared-worker.d.ts.map +1 -0
  46. package/lib/workers/supabase-shared-worker.js +12635 -0
  47. package/lib/workers/tools.d.ts +4 -0
  48. package/lib/workers/tools.d.ts.map +1 -0
  49. package/lib/workers/validate.d.ts +15 -0
  50. package/lib/workers/validate.d.ts.map +1 -0
  51. package/lib/workers/ws-worker.d.ts +11 -0
  52. package/lib/workers/ws-worker.d.ts.map +1 -0
  53. package/lib/workers/ws-worker.js +174 -115
  54. package/main.js +4875 -0
  55. package/package.json +17 -6
  56. package/reference.js +688 -228
  57. package/src/index.ts +38 -13
  58. package/src/lib/droid.spec.ts +14 -19
  59. package/src/lib/droid.ts +48 -4
  60. package/src/lib/gateway/SupabaseGateway.ts +183 -0
  61. package/src/lib/gateway/WorkerCommunication.ts +132 -0
  62. package/src/lib/gateway/WorkerPool.ts +304 -0
  63. package/src/lib/gateway/capabilities.ts +80 -0
  64. package/src/lib/gateway/index.ts +15 -0
  65. package/src/lib/gateway/strategies/DirectStrategy.ts +443 -0
  66. package/src/lib/gateway/strategies/SharedWorkerStrategy.ts +278 -0
  67. package/src/lib/gateway/strategies/WebWorkerStrategy.ts +278 -0
  68. package/src/lib/gateway/types.ts +112 -0
  69. package/src/lib/mod/mod-manager.ts +13 -8
  70. package/src/lib/mod/module/bento/mod-bento.worker.ts +1 -1
  71. package/src/lib/mod/module/supabase/mod-supabase.spec.ts +21 -25
  72. package/src/lib/mod/module/supabase/mod-supabase.ts +68 -0
  73. package/src/lib/mod/module/supabase/mod-supabase.worker.ts +1 -56
  74. package/src/lib/state/auth.spec.ts +58 -0
  75. package/src/lib/state/auth.ts +30 -0
  76. package/src/lib/state/index.ts +34 -0
  77. package/src/lib/state/overlay-manager.ts +125 -0
  78. package/src/lib/state/router.ts +24 -0
  79. package/src/lib/state/theme-sync.ts +75 -0
  80. package/src/lib/state/toasts.spec.ts +106 -0
  81. package/src/lib/state/toasts.ts +34 -0
  82. package/src/lib/state/ui.spec.ts +148 -0
  83. package/src/lib/state/ui.ts +45 -0
  84. package/src/lib/state/welcome-toast.ts +76 -0
  85. package/src/lib/types/bento.spec.ts +116 -0
  86. package/src/lib/types/bento.ts +94 -55
  87. package/src/lib/types/event-types.spec.ts +93 -0
  88. package/src/lib/types/event-types.ts +39 -3
  89. package/src/lib/types/modules.ts +12 -5
  90. package/src/lib/types/ui-event-types.ts +66 -0
  91. package/src/lib/workers/canvas-ui-renderer.ts +266 -0
  92. package/src/lib/workers/canvas-worker.ts +94 -9
  93. package/src/lib/workers/data.ts +59 -36
  94. package/src/lib/workers/db-worker.ts +79 -32
  95. package/src/lib/workers/events.spec.ts +208 -0
  96. package/src/lib/workers/events.ts +27 -14
  97. package/src/lib/workers/flexbuilder.ts +2 -2
  98. package/src/lib/workers/init.ts +25 -17
  99. package/src/lib/workers/main.ts +510 -316
  100. package/src/lib/workers/supabase-db-worker.ts +221 -0
  101. package/src/lib/workers/supabase-shared-worker.ts +572 -0
  102. package/src/lib/workers/validate.ts +64 -0
  103. package/src/lib/workers/ws-worker.ts +156 -25
  104. package/src/setup-vitest.ts +4 -2
  105. package/src/types.ts +30 -0
  106. package/src/vite-env.d.ts +1 -0
  107. package/workers/main.js +10 -1123
  108. package/src/types.d.ts +0 -31
@@ -1,19 +1,14 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- const A = Symbol("Comlink.proxy"), F = Symbol("Comlink.endpoint"), O = Symbol("Comlink.releaseProxy"), k = Symbol("Comlink.finalizer"), d = Symbol("Comlink.thrown"), C = (t) => typeof t == "object" && t !== null || typeof t == "function", z = {
7
- canHandle: (t) => C(t) && t[A],
1
+ const A = /* @__PURE__ */ Symbol("Comlink.proxy"), G = /* @__PURE__ */ Symbol("Comlink.endpoint"), L = /* @__PURE__ */ Symbol("Comlink.releaseProxy"), C = /* @__PURE__ */ Symbol("Comlink.finalizer"), y = /* @__PURE__ */ Symbol("Comlink.thrown"), M = (t) => typeof t == "object" && t !== null || typeof t == "function", U = {
2
+ canHandle: (t) => M(t) && t[A],
8
3
  serialize(t) {
9
- const { port1: e, port2: r } = new MessageChannel();
10
- return S(t, e), [r, [r]];
4
+ const { port1: e, port2: a } = new MessageChannel();
5
+ return E(t, e), [a, [a]];
11
6
  },
12
7
  deserialize(t) {
13
- return t.start(), H(t);
8
+ return t.start(), W(t);
14
9
  }
15
- }, N = {
16
- canHandle: (t) => C(t) && d in t,
10
+ }, z = {
11
+ canHandle: (t) => M(t) && y in t,
17
12
  serialize({ value: t }) {
18
13
  let e;
19
14
  return t instanceof Error ? e = {
@@ -28,196 +23,196 @@ const A = Symbol("Comlink.proxy"), F = Symbol("Comlink.endpoint"), O = Symbol("C
28
23
  deserialize(t) {
29
24
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
30
25
  }
31
- }, P = /* @__PURE__ */ new Map([
32
- ["proxy", z],
33
- ["throw", N]
26
+ }, R = /* @__PURE__ */ new Map([
27
+ ["proxy", U],
28
+ ["throw", z]
34
29
  ]);
35
- function W(t, e) {
36
- for (const r of t)
37
- if (e === r || r === "*" || r instanceof RegExp && r.test(e))
30
+ function D(t, e) {
31
+ for (const a of t)
32
+ if (e === a || a === "*" || a instanceof RegExp && a.test(e))
38
33
  return !0;
39
34
  return !1;
40
35
  }
41
- function S(t, e = globalThis, r = ["*"]) {
42
- e.addEventListener("message", function l(n) {
43
- if (!n || !n.data)
36
+ function E(t, e = globalThis, a = ["*"]) {
37
+ e.addEventListener("message", function n(s) {
38
+ if (!s || !s.data)
44
39
  return;
45
- if (!W(r, n.origin)) {
46
- console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
40
+ if (!D(a, s.origin)) {
41
+ console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
47
42
  return;
48
43
  }
49
- const { id: s, type: m, path: c } = Object.assign({ path: [] }, n.data), u = (n.data.argumentList || []).map(h);
50
- let a;
44
+ const { id: r, type: i, path: o } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(m);
45
+ let c;
51
46
  try {
52
- const o = c.slice(0, -1).reduce((i, y) => i[y], t), f = c.reduce((i, y) => i[y], t);
53
- switch (m) {
47
+ const h = o.slice(0, -1).reduce((f, g) => f[g], t), u = o.reduce((f, g) => f[g], t);
48
+ switch (i) {
54
49
  case "GET":
55
- a = f;
50
+ c = u;
56
51
  break;
57
52
  case "SET":
58
- o[c.slice(-1)[0]] = h(n.data.value), a = !0;
53
+ h[o.slice(-1)[0]] = m(s.data.value), c = !0;
59
54
  break;
60
55
  case "APPLY":
61
- a = f.apply(o, u);
56
+ c = u.apply(h, l);
62
57
  break;
63
58
  case "CONSTRUCT":
64
59
  {
65
- const i = new f(...u);
66
- a = $(i);
60
+ const f = new u(...l);
61
+ c = $(f);
67
62
  }
68
63
  break;
69
64
  case "ENDPOINT":
70
65
  {
71
- const { port1: i, port2: y } = new MessageChannel();
72
- S(t, y), a = _(i, [i]);
66
+ const { port1: f, port2: g } = new MessageChannel();
67
+ E(t, g), c = V(f, [f]);
73
68
  }
74
69
  break;
75
70
  case "RELEASE":
76
- a = void 0;
71
+ c = void 0;
77
72
  break;
78
73
  default:
79
74
  return;
80
75
  }
81
- } catch (o) {
82
- a = { value: o, [d]: 0 };
76
+ } catch (h) {
77
+ c = { value: h, [y]: 0 };
83
78
  }
84
- Promise.resolve(a).catch((o) => ({ value: o, [d]: 0 })).then((o) => {
85
- const [f, i] = b(o);
86
- e.postMessage(Object.assign(Object.assign({}, f), { id: s }), i), m === "RELEASE" && (e.removeEventListener("message", l), R(e), k in t && typeof t[k] == "function" && t[k]());
87
- }).catch((o) => {
88
- const [f, i] = b({
79
+ Promise.resolve(c).catch((h) => ({ value: h, [y]: 0 })).then((h) => {
80
+ const [u, f] = T(h);
81
+ e.postMessage(Object.assign(Object.assign({}, u), { id: r }), f), i === "RELEASE" && (e.removeEventListener("message", n), P(e), C in t && typeof t[C] == "function" && t[C]());
82
+ }).catch((h) => {
83
+ const [u, f] = T({
89
84
  value: new TypeError("Unserializable return value"),
90
- [d]: 0
85
+ [y]: 0
91
86
  });
92
- e.postMessage(Object.assign(Object.assign({}, f), { id: s }), i);
87
+ e.postMessage(Object.assign(Object.assign({}, u), { id: r }), f);
93
88
  });
94
89
  }), e.start && e.start();
95
90
  }
96
- function D(t) {
91
+ function N(t) {
97
92
  return t.constructor.name === "MessagePort";
98
93
  }
99
- function R(t) {
100
- D(t) && t.close();
94
+ function P(t) {
95
+ N(t) && t.close();
101
96
  }
102
- function H(t, e) {
103
- const r = /* @__PURE__ */ new Map();
104
- return t.addEventListener("message", function(n) {
105
- const { data: s } = n;
106
- if (!s || !s.id)
97
+ function W(t, e) {
98
+ const a = /* @__PURE__ */ new Map();
99
+ return t.addEventListener("message", function(s) {
100
+ const { data: r } = s;
101
+ if (!r || !r.id)
107
102
  return;
108
- const m = r.get(s.id);
109
- if (m)
103
+ const i = a.get(r.id);
104
+ if (i)
110
105
  try {
111
- m(s);
106
+ i(r);
112
107
  } finally {
113
- r.delete(s.id);
108
+ a.delete(r.id);
114
109
  }
115
- }), M(t, r, [], e);
110
+ }), k(t, a, [], e);
116
111
  }
117
112
  function w(t) {
118
113
  if (t)
119
114
  throw new Error("Proxy has been released and is not useable");
120
115
  }
121
- function v(t) {
122
- return g(t, /* @__PURE__ */ new Map(), {
116
+ function F(t) {
117
+ return b(t, /* @__PURE__ */ new Map(), {
123
118
  type: "RELEASE"
124
119
  }).then(() => {
125
- R(t);
120
+ P(t);
126
121
  });
127
122
  }
128
- const E = /* @__PURE__ */ new WeakMap(), x = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
129
- const e = (E.get(t) || 0) - 1;
130
- E.set(t, e), e === 0 && v(t);
123
+ const p = /* @__PURE__ */ new WeakMap(), x = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
124
+ const e = (p.get(t) || 0) - 1;
125
+ p.set(t, e), e === 0 && F(t);
131
126
  });
132
- function L(t, e) {
133
- const r = (E.get(e) || 0) + 1;
134
- E.set(e, r), x && x.register(t, e, t);
127
+ function H(t, e) {
128
+ const a = (p.get(e) || 0) + 1;
129
+ p.set(e, a), x && x.register(t, e, t);
135
130
  }
136
- function U(t) {
131
+ function _(t) {
137
132
  x && x.unregister(t);
138
133
  }
139
- function M(t, e, r = [], l = function() {
134
+ function k(t, e, a = [], n = function() {
140
135
  }) {
141
- let n = !1;
142
- const s = new Proxy(l, {
143
- get(m, c) {
144
- if (w(n), c === O)
136
+ let s = !1;
137
+ const r = new Proxy(n, {
138
+ get(i, o) {
139
+ if (w(s), o === L)
145
140
  return () => {
146
- U(s), v(t), e.clear(), n = !0;
141
+ _(r), F(t), e.clear(), s = !0;
147
142
  };
148
- if (c === "then") {
149
- if (r.length === 0)
150
- return { then: () => s };
151
- const u = g(t, e, {
143
+ if (o === "then") {
144
+ if (a.length === 0)
145
+ return { then: () => r };
146
+ const l = b(t, e, {
152
147
  type: "GET",
153
- path: r.map((a) => a.toString())
154
- }).then(h);
155
- return u.then.bind(u);
148
+ path: a.map((c) => c.toString())
149
+ }).then(m);
150
+ return l.then.bind(l);
156
151
  }
157
- return M(t, e, [...r, c]);
152
+ return k(t, e, [...a, o]);
158
153
  },
159
- set(m, c, u) {
160
- w(n);
161
- const [a, o] = b(u);
162
- return g(t, e, {
154
+ set(i, o, l) {
155
+ w(s);
156
+ const [c, h] = T(l);
157
+ return b(t, e, {
163
158
  type: "SET",
164
- path: [...r, c].map((f) => f.toString()),
165
- value: a
166
- }, o).then(h);
159
+ path: [...a, o].map((u) => u.toString()),
160
+ value: c
161
+ }, h).then(m);
167
162
  },
168
- apply(m, c, u) {
169
- w(n);
170
- const a = r[r.length - 1];
171
- if (a === F)
172
- return g(t, e, {
163
+ apply(i, o, l) {
164
+ w(s);
165
+ const c = a[a.length - 1];
166
+ if (c === G)
167
+ return b(t, e, {
173
168
  type: "ENDPOINT"
174
- }).then(h);
175
- if (a === "bind")
176
- return M(t, e, r.slice(0, -1));
177
- const [o, f] = p(u);
178
- return g(t, e, {
169
+ }).then(m);
170
+ if (c === "bind")
171
+ return k(t, e, a.slice(0, -1));
172
+ const [h, u] = v(l);
173
+ return b(t, e, {
179
174
  type: "APPLY",
180
- path: r.map((i) => i.toString()),
181
- argumentList: o
182
- }, f).then(h);
175
+ path: a.map((f) => f.toString()),
176
+ argumentList: h
177
+ }, u).then(m);
183
178
  },
184
- construct(m, c) {
185
- w(n);
186
- const [u, a] = p(c);
187
- return g(t, e, {
179
+ construct(i, o) {
180
+ w(s);
181
+ const [l, c] = v(o);
182
+ return b(t, e, {
188
183
  type: "CONSTRUCT",
189
- path: r.map((o) => o.toString()),
190
- argumentList: u
191
- }, a).then(h);
184
+ path: a.map((h) => h.toString()),
185
+ argumentList: l
186
+ }, c).then(m);
192
187
  }
193
188
  });
194
- return L(s, t), s;
189
+ return H(r, t), r;
195
190
  }
196
- function V(t) {
191
+ function q(t) {
197
192
  return Array.prototype.concat.apply([], t);
198
193
  }
199
- function p(t) {
200
- const e = t.map(b);
201
- return [e.map((r) => r[0]), V(e.map((r) => r[1]))];
194
+ function v(t) {
195
+ const e = t.map(T);
196
+ return [e.map((a) => a[0]), q(e.map((a) => a[1]))];
202
197
  }
203
- const T = /* @__PURE__ */ new WeakMap();
204
- function _(t, e) {
205
- return T.set(t, e), t;
198
+ const O = /* @__PURE__ */ new WeakMap();
199
+ function V(t, e) {
200
+ return O.set(t, e), t;
206
201
  }
207
202
  function $(t) {
208
203
  return Object.assign(t, { [A]: !0 });
209
204
  }
210
- function b(t) {
211
- for (const [e, r] of P)
212
- if (r.canHandle(t)) {
213
- const [l, n] = r.serialize(t);
205
+ function T(t) {
206
+ for (const [e, a] of R)
207
+ if (a.canHandle(t)) {
208
+ const [n, s] = a.serialize(t);
214
209
  return [
215
210
  {
216
211
  type: "HANDLER",
217
212
  name: e,
218
- value: l
213
+ value: n
219
214
  },
220
- n
215
+ s
221
216
  ];
222
217
  }
223
218
  return [
@@ -225,35 +220,152 @@ function b(t) {
225
220
  type: "RAW",
226
221
  value: t
227
222
  },
228
- T.get(t) || []
223
+ O.get(t) || []
229
224
  ];
230
225
  }
231
- function h(t) {
226
+ function m(t) {
232
227
  switch (t.type) {
233
228
  case "HANDLER":
234
- return P.get(t.name).deserialize(t.value);
229
+ return R.get(t.name).deserialize(t.value);
235
230
  case "RAW":
236
231
  return t.value;
237
232
  }
238
233
  }
239
- function g(t, e, r, l) {
240
- return new Promise((n) => {
241
- const s = j();
242
- e.set(s, n), t.start && t.start(), t.postMessage(Object.assign({ id: s }, r), l);
234
+ function b(t, e, a, n) {
235
+ return new Promise((s) => {
236
+ const r = I();
237
+ e.set(r, s), t.start && t.start(), t.postMessage(Object.assign({ id: r }, a), n);
243
238
  });
244
239
  }
245
- function j() {
240
+ function I() {
246
241
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
247
242
  }
248
- const q = {
243
+ const S = {
244
+ success: { bg: "#065f46", border: "#10b981", text: "#d1fae5" },
245
+ warning: { bg: "#78350f", border: "#f59e0b", text: "#fef3c7" },
246
+ error: { bg: "#7f1d1d", border: "#ef4444", text: "#fee2e2" },
247
+ info: { bg: "#1e3a5f", border: "#3b82f6", text: "#dbeafe" }
248
+ };
249
+ class Y {
250
+ ctx = null;
251
+ canvas = null;
252
+ toasts = [];
253
+ tooltip = null;
254
+ modal = null;
255
+ theme = {
256
+ accent: "#8b5cf6",
257
+ accentLow: "#1e1033",
258
+ accentHigh: "#c4b5fd",
259
+ bg: "#0a0a0a",
260
+ bgAccent: "#3b1f6e",
261
+ text: "#e0e0e0",
262
+ textAccent: "#a78bfa",
263
+ border: "#4c1d95",
264
+ white: "#ffffff",
265
+ black: "#000000",
266
+ mode: "dark"
267
+ };
268
+ animFrame = null;
269
+ dbGet = null;
270
+ async bind(e, a) {
271
+ this.canvas = e, this.ctx = e.getContext("2d"), this.dbGet = a, await this.refreshTheme(), this.startLoop();
272
+ }
273
+ async refreshTheme() {
274
+ this.dbGet && (this.theme = {
275
+ accent: await this.dbGet("theme:accent") ?? "#8b5cf6",
276
+ accentLow: await this.dbGet("theme:accent-low") ?? "#1e1033",
277
+ accentHigh: await this.dbGet("theme:accent-high") ?? "#c4b5fd",
278
+ bg: await this.dbGet("theme:bg") ?? "#0a0a0a",
279
+ bgAccent: await this.dbGet("theme:bg-accent") ?? "#3b1f6e",
280
+ text: await this.dbGet("theme:text") ?? "#e0e0e0",
281
+ textAccent: await this.dbGet("theme:text-accent") ?? "#a78bfa",
282
+ border: await this.dbGet("theme:border") ?? "#4c1d95",
283
+ white: await this.dbGet("theme:white") ?? "#ffffff",
284
+ black: await this.dbGet("theme:black") ?? "#000000",
285
+ mode: await this.dbGet("theme:mode") ?? "dark"
286
+ });
287
+ }
288
+ addToast(e) {
289
+ const a = 20 + this.toasts.length * 80;
290
+ this.toasts.push({
291
+ ...e,
292
+ createdAt: Date.now(),
293
+ opacity: 0,
294
+ y: a - 20,
295
+ targetY: a
296
+ });
297
+ }
298
+ removeToast(e) {
299
+ const a = this.toasts.findIndex((n) => n.id === e);
300
+ a !== -1 && this.toasts.splice(a, 1), this.recalcPositions();
301
+ }
302
+ showTooltip(e) {
303
+ this.tooltip = e;
304
+ }
305
+ showModal(e) {
306
+ this.modal = e;
307
+ }
308
+ recalcPositions() {
309
+ this.toasts.forEach((e, a) => {
310
+ e.targetY = 20 + a * 80;
311
+ });
312
+ }
313
+ startLoop() {
314
+ const e = () => {
315
+ this.render(), this.animFrame = requestAnimationFrame(e);
316
+ };
317
+ e();
318
+ }
319
+ render() {
320
+ if (!this.ctx || !this.canvas) return;
321
+ const { width: e, height: a } = this.canvas;
322
+ this.ctx.clearRect(0, 0, e, a);
323
+ const n = Date.now();
324
+ this.toasts = this.toasts.filter((s) => !(s.duration && s.duration > 0 && n - s.createdAt > s.duration)), this.recalcPositions();
325
+ for (const s of this.toasts)
326
+ s.opacity < 1 && (s.opacity = Math.min(1, s.opacity + 0.05)), s.y += (s.targetY - s.y) * 0.15, this.drawToast(s, e);
327
+ this.modal && this.drawModal(e, a);
328
+ }
329
+ drawToast(e, a) {
330
+ if (!this.ctx) return;
331
+ const n = this.ctx, s = 320, r = 64, i = a - s - 20, o = e.y, l = S[e.severity] ?? S.info;
332
+ n.globalAlpha = e.opacity, n.fillStyle = l.bg, this.roundRect(n, i, o, s, r, 8), n.fill(), n.strokeStyle = l.border, n.lineWidth = 1.5, this.roundRect(n, i, o, s, r, 8), n.stroke(), n.fillStyle = l.text, n.font = "14px system-ui, -apple-system, sans-serif", n.fillText(e.message, i + 12, o + 24, s - 24), n.font = "bold 10px system-ui, sans-serif", n.fillStyle = l.border, n.fillText(e.severity.toUpperCase(), i + 12, o + 48), n.globalAlpha = 1;
333
+ }
334
+ drawModal(e, a) {
335
+ if (!this.ctx || !this.modal) return;
336
+ const n = this.ctx;
337
+ n.fillStyle = "rgba(0, 0, 0, 0.5)", n.fillRect(0, 0, e, a);
338
+ const s = Math.min(500, e - 40), r = 300, i = (e - s) / 2, o = (a - r) / 2;
339
+ n.fillStyle = this.theme.bg, this.roundRect(n, i, o, s, r, 12), n.fill(), n.strokeStyle = this.theme.border, n.lineWidth = 1, this.roundRect(n, i, o, s, r, 12), n.stroke(), this.modal.title && (n.fillStyle = this.theme.text, n.font = "bold 18px system-ui, sans-serif", n.fillText(this.modal.title, i + 20, o + 36, s - 40)), n.fillStyle = this.theme.textAccent, n.font = "12px system-ui, sans-serif", n.fillText(this.modal.id, i + 20, o + 60, s - 40);
340
+ }
341
+ roundRect(e, a, n, s, r, i) {
342
+ e.beginPath(), e.moveTo(a + i, n), e.lineTo(a + s - i, n), e.quadraticCurveTo(a + s, n, a + s, n + i), e.lineTo(a + s, n + r - i), e.quadraticCurveTo(a + s, n + r, a + s - i, n + r), e.lineTo(a + i, n + r), e.quadraticCurveTo(a, n + r, a, n + r - i), e.lineTo(a, n + i), e.quadraticCurveTo(a, n, a + i, n), e.closePath();
343
+ }
344
+ unbind() {
345
+ this.animFrame !== null && (cancelAnimationFrame(this.animFrame), this.animFrame = null), this.ctx = null, this.canvas = null, this.toasts = [], this.tooltip = null, this.modal = null;
346
+ }
347
+ }
348
+ const d = new Y();
349
+ try {
350
+ const t = new BroadcastChannel("kbve_theme");
351
+ t.onmessage = () => {
352
+ d.refreshTheme();
353
+ };
354
+ } catch {
355
+ }
356
+ const j = {
249
357
  bindings: /* @__PURE__ */ new Map(),
250
- async bindCanvas(t, e, r = "animated") {
251
- const l = e.getContext("2d");
252
- if (!l) {
253
- console.error(`[CanvasWorker] Failed to get 2D context for panel ${t}`);
358
+ async bindCanvas(t, e, a = "animated") {
359
+ const n = e.getContext("2d");
360
+ if (!n) {
361
+ console.error(
362
+ `[CanvasWorker] Failed to get 2D context for panel ${t}`
363
+ );
254
364
  return;
255
365
  }
256
- console.log(`[CanvasWorker] Successfully bound canvas for panel ${t} with mode ${r}`), this.bindings.set(t, { ctx: l, canvas: e, panelId: t, mode: r }), this.startAnimation(t);
366
+ console.log(
367
+ `[CanvasWorker] Successfully bound canvas for panel ${t} with mode ${a}`
368
+ ), this.bindings.set(t, { ctx: n, canvas: e, panelId: t, mode: a }), this.startAnimation(t);
257
369
  },
258
370
  startAnimation(t) {
259
371
  const e = this.bindings.get(t);
@@ -269,7 +381,9 @@ const q = {
269
381
  this.drawDynamic(e);
270
382
  break;
271
383
  default:
272
- console.warn(`[CanvasWorker] Unknown draw mode for panel ${t}`);
384
+ console.warn(
385
+ `[CanvasWorker] Unknown draw mode for panel ${t}`
386
+ );
273
387
  }
274
388
  },
275
389
  drawStatic(t) {
@@ -277,27 +391,59 @@ const q = {
277
391
  },
278
392
  drawAnimated(t) {
279
393
  let e = 0;
280
- const r = () => {
281
- e = (e + 1) % 360, t.ctx.fillStyle = `hsl(${e}, 100%, 50%)`, t.ctx.fillRect(0, 0, t.canvas.width, t.canvas.height), t.animationFrame = requestAnimationFrame(r);
394
+ const a = () => {
395
+ e = (e + 1) % 360, t.ctx.fillStyle = `hsl(${e}, 100%, 50%)`, t.ctx.fillRect(
396
+ 0,
397
+ 0,
398
+ t.canvas.width,
399
+ t.canvas.height
400
+ ), t.animationFrame = requestAnimationFrame(a);
282
401
  };
283
- r();
402
+ a();
284
403
  },
285
404
  drawDynamic(t) {
286
405
  let e = 0;
287
- const r = () => {
288
- e += 0.05, t.ctx.clearRect(0, 0, t.canvas.width, t.canvas.height), t.ctx.beginPath(), t.ctx.arc(
406
+ const a = () => {
407
+ e += 0.05, t.ctx.clearRect(
408
+ 0,
409
+ 0,
410
+ t.canvas.width,
411
+ t.canvas.height
412
+ ), t.ctx.beginPath(), t.ctx.arc(
289
413
  t.canvas.width / 2 + Math.sin(e) * 50,
290
414
  t.canvas.height / 2 + Math.cos(e) * 50,
291
415
  30,
292
416
  0,
293
417
  Math.PI * 2
294
- ), t.ctx.fillStyle = "orange", t.ctx.fill(), t.animationFrame = requestAnimationFrame(r);
418
+ ), t.ctx.fillStyle = "orange", t.ctx.fill(), t.animationFrame = requestAnimationFrame(a);
295
419
  };
296
- r();
420
+ a();
297
421
  },
298
422
  async unbindCanvas(t) {
299
423
  const e = this.bindings.get(t);
300
424
  e?.animationFrame && cancelAnimationFrame(e.animationFrame), this.bindings.delete(t), console.log(`[CanvasWorker] Unbound canvas for panel ${t}`);
425
+ },
426
+ // ── UI Overlay Canvas ──
427
+ async bindUICanvas(t, e) {
428
+ await d.bind(t, e);
429
+ },
430
+ unbindUICanvas() {
431
+ d.unbind();
432
+ },
433
+ addCanvasToast(t) {
434
+ d.addToast(t);
435
+ },
436
+ removeCanvasToast(t) {
437
+ d.removeToast(t);
438
+ },
439
+ showCanvasTooltip(t) {
440
+ d.showTooltip(t);
441
+ },
442
+ showCanvasModal(t) {
443
+ d.showModal(t);
444
+ },
445
+ refreshUITheme() {
446
+ return d.refreshTheme();
301
447
  }
302
448
  };
303
- S(q);
449
+ E(j);
@@ -0,0 +1,40 @@
1
+ import { PayloadFormat, JediEnvelopeFlex, MessageKind } from '../types/jedi';
2
+ export declare function wrapEnvelope<T extends Record<string, unknown>>(payload: T, kind: number, format: PayloadFormat, metadata?: Uint8Array, version?: number): Uint8Array;
3
+ export declare function unwrapEnvelope<T = unknown>(buffer: Uint8Array | ArrayBuffer): {
4
+ envelope: JediEnvelopeFlex;
5
+ payload: T;
6
+ };
7
+ export declare function unwrapFlexToJson(buffer: Uint8Array): unknown;
8
+ export declare function inspectFlex(buffer: Uint8Array | ArrayBuffer): void;
9
+ export declare function hasKind(kind: number, flag: number): boolean;
10
+ export declare function wrapRedisSet(key: string, value: string): Uint8Array;
11
+ export declare function wrapRedisGet(key: string): Uint8Array;
12
+ export declare function wrapRedisDel(key: string): Uint8Array;
13
+ export declare function parseRedisPayload<T = unknown>(envelopeBytes: Uint8Array): {
14
+ envelope: JediEnvelopeFlex;
15
+ payload: T;
16
+ };
17
+ export declare function wrapRedisXAdd(stream: string, fields: Record<string, string>, id?: string): Uint8Array;
18
+ export declare function wrapRedisXRead(streams: {
19
+ stream: string;
20
+ id: string;
21
+ }[], count?: number, block?: number): Uint8Array;
22
+ export declare const scopeData: {
23
+ wrapEnvelope: typeof wrapEnvelope;
24
+ unwrapEnvelope: typeof unwrapEnvelope;
25
+ MessageKind: typeof MessageKind;
26
+ PayloadFormat: typeof PayloadFormat;
27
+ unwrapFlexToJson: typeof unwrapFlexToJson;
28
+ inspectFlex: typeof inspectFlex;
29
+ hasKind: typeof hasKind;
30
+ redis: {
31
+ wrapRedisSet: typeof wrapRedisSet;
32
+ wrapRedisGet: typeof wrapRedisGet;
33
+ wrapRedisDel: typeof wrapRedisDel;
34
+ wrapRedisXAdd: typeof wrapRedisXAdd;
35
+ wrapRedisXRead: typeof wrapRedisXRead;
36
+ parseRedisPayload: typeof parseRedisPayload;
37
+ };
38
+ };
39
+ export type FlexDataAPI = typeof scopeData;
40
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../../../packages/npm/droid/src/lib/workers/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkB7E,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,OAAO,EAAE,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,UAAU,EACrB,OAAO,SAAI,GACT,UAAU,CA0BZ;AAED,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACzC,MAAM,EAAE,UAAU,GAAG,WAAW,GAC9B;IAAE,QAAQ,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CA4C5C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,WAElD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CASlE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAID,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAMnE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMpD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMpD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC5C,aAAa,EAAE,UAAU,GACvB;IACF,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC;CACX,CAMA;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,EAAE,SAAM,GACN,UAAU,CAMZ;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,EACzC,KAAK,CAAC,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACZ,UAAU,CA2CZ;AAED,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC"}