@kbve/droid 0.0.5 → 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 (109) hide show
  1. package/README.md +3 -1
  2. package/comlink.js +1 -7
  3. package/droid.mjs +191 -61
  4. package/index.d.ts +29 -0
  5. package/index.js +9054 -2763
  6. package/lib/gateway/SupabaseGateway.d.ts +38 -0
  7. package/lib/gateway/SupabaseGateway.d.ts.map +1 -0
  8. package/lib/gateway/WorkerCommunication.d.ts +39 -0
  9. package/lib/gateway/WorkerCommunication.d.ts.map +1 -0
  10. package/lib/gateway/WorkerPool.d.ts +55 -0
  11. package/lib/gateway/WorkerPool.d.ts.map +1 -0
  12. package/lib/gateway/capabilities.d.ts +23 -0
  13. package/lib/gateway/capabilities.d.ts.map +1 -0
  14. package/lib/gateway/index.d.ts +9 -0
  15. package/lib/gateway/index.d.ts.map +1 -0
  16. package/lib/gateway/strategies/DirectStrategy.d.ts +52 -0
  17. package/lib/gateway/strategies/DirectStrategy.d.ts.map +1 -0
  18. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts +46 -0
  19. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts.map +1 -0
  20. package/lib/gateway/strategies/WebWorkerStrategy.d.ts +45 -0
  21. package/lib/gateway/strategies/WebWorkerStrategy.d.ts.map +1 -0
  22. package/lib/gateway/types.d.ts +81 -0
  23. package/lib/gateway/types.d.ts.map +1 -0
  24. package/lib/workers/canvas-ui-renderer.d.ts +25 -0
  25. package/lib/workers/canvas-ui-renderer.d.ts.map +1 -0
  26. package/lib/workers/canvas-worker.d.ts +14 -0
  27. package/lib/workers/canvas-worker.d.ts.map +1 -0
  28. package/lib/workers/canvas-worker.js +291 -145
  29. package/lib/workers/data.d.ts +40 -0
  30. package/lib/workers/data.d.ts.map +1 -0
  31. package/lib/workers/db-worker.d.ts +69 -0
  32. package/lib/workers/db-worker.d.ts.map +1 -0
  33. package/lib/workers/db-worker.js +2680 -2147
  34. package/lib/workers/events.d.ts +11 -0
  35. package/lib/workers/events.d.ts.map +1 -0
  36. package/lib/workers/flexbuilder.d.ts +4 -0
  37. package/lib/workers/flexbuilder.d.ts.map +1 -0
  38. package/lib/workers/init.d.ts +11 -0
  39. package/lib/workers/init.d.ts.map +1 -0
  40. package/lib/workers/main.d.ts +107 -0
  41. package/lib/workers/main.d.ts.map +1 -0
  42. package/lib/workers/supabase-db-worker.d.ts +2 -0
  43. package/lib/workers/supabase-db-worker.d.ts.map +1 -0
  44. package/lib/workers/supabase-db-worker.js +9337 -0
  45. package/lib/workers/supabase-shared-worker.d.ts +2 -0
  46. package/lib/workers/supabase-shared-worker.d.ts.map +1 -0
  47. package/lib/workers/supabase-shared-worker.js +12635 -0
  48. package/lib/workers/tools.d.ts +4 -0
  49. package/lib/workers/tools.d.ts.map +1 -0
  50. package/lib/workers/validate.d.ts +15 -0
  51. package/lib/workers/validate.d.ts.map +1 -0
  52. package/lib/workers/ws-worker.d.ts +11 -0
  53. package/lib/workers/ws-worker.d.ts.map +1 -0
  54. package/lib/workers/ws-worker.js +174 -115
  55. package/main.js +4875 -0
  56. package/package.json +17 -6
  57. package/reference.js +688 -228
  58. package/src/index.ts +38 -13
  59. package/src/lib/droid.spec.ts +14 -19
  60. package/src/lib/droid.ts +48 -4
  61. package/src/lib/gateway/SupabaseGateway.ts +183 -0
  62. package/src/lib/gateway/WorkerCommunication.ts +132 -0
  63. package/src/lib/gateway/WorkerPool.ts +304 -0
  64. package/src/lib/gateway/capabilities.ts +80 -0
  65. package/src/lib/gateway/index.ts +15 -0
  66. package/src/lib/gateway/strategies/DirectStrategy.ts +443 -0
  67. package/src/lib/gateway/strategies/SharedWorkerStrategy.ts +278 -0
  68. package/src/lib/gateway/strategies/WebWorkerStrategy.ts +278 -0
  69. package/src/lib/gateway/types.ts +112 -0
  70. package/src/lib/mod/mod-manager.ts +13 -8
  71. package/src/lib/mod/module/bento/mod-bento.worker.ts +1 -1
  72. package/src/lib/mod/module/supabase/mod-supabase.spec.ts +21 -25
  73. package/src/lib/mod/module/supabase/mod-supabase.ts +68 -0
  74. package/src/lib/mod/module/supabase/mod-supabase.worker.ts +1 -56
  75. package/src/lib/state/auth.spec.ts +58 -0
  76. package/src/lib/state/auth.ts +30 -0
  77. package/src/lib/state/index.ts +34 -0
  78. package/src/lib/state/overlay-manager.ts +125 -0
  79. package/src/lib/state/router.ts +24 -0
  80. package/src/lib/state/theme-sync.ts +75 -0
  81. package/src/lib/state/toasts.spec.ts +106 -0
  82. package/src/lib/state/toasts.ts +34 -0
  83. package/src/lib/state/ui.spec.ts +148 -0
  84. package/src/lib/state/ui.ts +45 -0
  85. package/src/lib/state/welcome-toast.ts +76 -0
  86. package/src/lib/types/bento.spec.ts +116 -0
  87. package/src/lib/types/bento.ts +94 -55
  88. package/src/lib/types/event-types.spec.ts +93 -0
  89. package/src/lib/types/event-types.ts +39 -3
  90. package/src/lib/types/modules.ts +12 -5
  91. package/src/lib/types/ui-event-types.ts +66 -0
  92. package/src/lib/workers/canvas-ui-renderer.ts +266 -0
  93. package/src/lib/workers/canvas-worker.ts +94 -9
  94. package/src/lib/workers/data.ts +59 -36
  95. package/src/lib/workers/db-worker.ts +79 -32
  96. package/src/lib/workers/events.spec.ts +208 -0
  97. package/src/lib/workers/events.ts +27 -14
  98. package/src/lib/workers/flexbuilder.ts +2 -2
  99. package/src/lib/workers/init.ts +25 -17
  100. package/src/lib/workers/main.ts +509 -272
  101. package/src/lib/workers/supabase-db-worker.ts +221 -0
  102. package/src/lib/workers/supabase-shared-worker.ts +572 -0
  103. package/src/lib/workers/validate.ts +64 -0
  104. package/src/lib/workers/ws-worker.ts +156 -25
  105. package/src/setup-vitest.ts +4 -2
  106. package/src/types.ts +30 -0
  107. package/src/vite-env.d.ts +1 -0
  108. package/workers/main.js +10 -1089
  109. package/src/types.d.ts +0 -31
package/main.js ADDED
@@ -0,0 +1,4875 @@
1
+ import { w as ue, p as Ur } from "./comlink.js";
2
+ import { b as jr, r as Ne } from "./reference.js";
3
+ import { g as Nt } from "./WorkerCommunication.js";
4
+ let De = /* @__PURE__ */ Symbol("clean"), N = [], j = 0;
5
+ const fe = 4, Te = /* @__NO_SIDE_EFFECTS__ */ (e) => {
6
+ let t = [], r = {
7
+ get() {
8
+ return r.lc || r.listen(() => {
9
+ })(), r.value;
10
+ },
11
+ lc: 0,
12
+ listen(n) {
13
+ return r.lc = t.push(n), () => {
14
+ for (let i = j + fe; i < N.length; )
15
+ N[i] === n ? N.splice(i, fe) : i += fe;
16
+ let o = t.indexOf(n);
17
+ ~o && (t.splice(o, 1), --r.lc || r.off());
18
+ };
19
+ },
20
+ notify(n, o) {
21
+ let i = !N.length;
22
+ for (let s of t)
23
+ N.push(s, r.value, n, o);
24
+ if (i) {
25
+ for (j = 0; j < N.length; j += fe)
26
+ N[j](
27
+ N[j + 1],
28
+ N[j + 2],
29
+ N[j + 3]
30
+ );
31
+ N.length = 0;
32
+ }
33
+ },
34
+ /* It will be called on last listener unsubscribing.
35
+ We will redefine it in onMount and onStop. */
36
+ off() {
37
+ },
38
+ set(n) {
39
+ let o = r.value;
40
+ o !== n && (r.value = n, r.notify(o));
41
+ },
42
+ subscribe(n) {
43
+ let o = r.listen(n);
44
+ return n(r.value), o;
45
+ },
46
+ value: e
47
+ };
48
+ return process.env.NODE_ENV !== "production" && (r[De] = () => {
49
+ t = [], r.lc = 0, r.off();
50
+ }), r;
51
+ }, Lr = 5, G = 6, he = 10;
52
+ let Mr = (e, t, r, n) => (e.events = e.events || {}, e.events[r + he] || (e.events[r + he] = n((o) => {
53
+ e.events[r].reduceRight((i, s) => (s(i), i), {
54
+ shared: {},
55
+ ...o
56
+ });
57
+ })), e.events[r] = e.events[r] || [], e.events[r].push(t), () => {
58
+ let o = e.events[r], i = o.indexOf(t);
59
+ o.splice(i, 1), o.length || (delete e.events[r], e.events[r + he](), delete e.events[r + he]);
60
+ }), Fr = 1e3, xr = (e, t) => Mr(e, (n) => {
61
+ let o = t(n);
62
+ o && e.events[G].push(o);
63
+ }, Lr, (n) => {
64
+ let o = e.listen;
65
+ e.listen = (...s) => (!e.lc && !e.active && (e.active = !0, n()), o(...s));
66
+ let i = e.off;
67
+ if (e.events[G] = [], e.off = () => {
68
+ i(), setTimeout(() => {
69
+ if (e.active && !e.lc) {
70
+ e.active = !1;
71
+ for (let s of e.events[G]) s();
72
+ e.events[G] = [];
73
+ }
74
+ }, Fr);
75
+ }, process.env.NODE_ENV !== "production") {
76
+ let s = e[De];
77
+ e[De] = () => {
78
+ for (let a of e.events[G]) a();
79
+ e.events[G] = [], e.active = !1, s();
80
+ };
81
+ }
82
+ return () => {
83
+ e.listen = o, e.off = i;
84
+ };
85
+ });
86
+ const Je = /* @__NO_SIDE_EFFECTS__ */ (e = {}) => {
87
+ let t = /* @__PURE__ */ Te(e);
88
+ return t.setKey = function(r, n) {
89
+ let o = t.value;
90
+ typeof n > "u" && r in t.value ? (t.value = { ...t.value }, delete t.value[r], t.notify(o, r)) : t.value[r] !== n && (t.value = {
91
+ ...t.value,
92
+ [r]: n
93
+ }, t.notify(o, r));
94
+ }, t;
95
+ };
96
+ let rt = (e) => e, oe = {}, L = { addEventListener() {
97
+ }, removeEventListener() {
98
+ } };
99
+ function Br() {
100
+ try {
101
+ return typeof localStorage < "u";
102
+ } catch {
103
+ return !1;
104
+ }
105
+ }
106
+ Br() && (oe = localStorage);
107
+ let Jr = {
108
+ addEventListener(e, t, r) {
109
+ window.addEventListener("storage", t), window.addEventListener("pageshow", r);
110
+ },
111
+ removeEventListener(e, t, r) {
112
+ window.removeEventListener("storage", t), window.removeEventListener("pageshow", r);
113
+ }
114
+ };
115
+ typeof window < "u" && (L = Jr);
116
+ function Dt(e, t = {}, r = {}) {
117
+ let n = r.encode || rt, o = r.decode || rt, i = /* @__PURE__ */ Je(), s = i.setKey, a = (d, h) => {
118
+ typeof h > "u" ? (r.listen !== !1 && L.perKey && L.removeEventListener(e + d, u, f), delete oe[e + d]) : (r.listen !== !1 && L.perKey && !(d in i.value) && L.addEventListener(e + d, u, f), oe[e + d] = n(h));
119
+ };
120
+ i.setKey = (d, h) => {
121
+ a(d, h), s(d, h);
122
+ };
123
+ let c = i.set;
124
+ i.set = function(d) {
125
+ for (let h in d)
126
+ a(h, d[h]);
127
+ for (let h in i.value)
128
+ h in d || a(h, void 0);
129
+ c(d);
130
+ };
131
+ function u(d) {
132
+ d.key ? d.key.startsWith(e) && (d.newValue === null ? s(d.key.slice(e.length), void 0) : s(d.key.slice(e.length), o(d.newValue))) : c({});
133
+ }
134
+ function f() {
135
+ let d = { ...t };
136
+ for (let h in oe)
137
+ h.startsWith(e) && (d[h.slice(e.length)] = o(oe[h]));
138
+ for (let h in d)
139
+ i.setKey(h, d[h]);
140
+ }
141
+ return xr(i, () => {
142
+ if (f(), r.listen !== !1)
143
+ return L.addEventListener(e, u, f), () => {
144
+ L.removeEventListener(e, u, f);
145
+ for (let d in i.value)
146
+ L.removeEventListener(e + d, u, f);
147
+ };
148
+ }), i;
149
+ }
150
+ async function Vr(e, {
151
+ version: t,
152
+ i18nPath: r,
153
+ dataPath: n,
154
+ locale: o = "en",
155
+ defaults: i = {
156
+ welcome: "Welcome to the app!"
157
+ }
158
+ }) {
159
+ console.log("[init-worker] Initializing database...");
160
+ try {
161
+ r && (await e.loadI18nFromJSON(r), console.log(`[init-worker] i18n loaded from ${r}`)), await e.dbSet("locale", o);
162
+ for (const [s, a] of Object.entries(i))
163
+ await e.dbSet(s, a);
164
+ await e.setVersion(t), n && e.loadServersFromJSON(n), console.log(`[init-worker] DB initialized to version ${t}`);
165
+ } catch (s) {
166
+ console.error("[init-worker] Initialization failed:", s);
167
+ }
168
+ }
169
+ let pe = null;
170
+ async function Ct(e) {
171
+ if (pe) return pe;
172
+ const t = {};
173
+ async function r(s) {
174
+ const a = e?.(s) ?? s, c = new Worker(a, { type: "module" }), u = ue(c), f = await u.getMeta?.() ?? {
175
+ name: "unknown",
176
+ version: "0.0.1"
177
+ }, d = `${f.name}@${f.version}`;
178
+ console.log(`[mod-manager] ${d} is loaded.`);
179
+ const h = { id: d, worker: c, instance: u, meta: f, url: s };
180
+ return t[d] = h, h;
181
+ }
182
+ function n(s) {
183
+ t[s] && (t[s].worker.terminate(), delete t[s]);
184
+ }
185
+ function o() {
186
+ return Object.values(t).map((s) => s.meta);
187
+ }
188
+ async function i(s) {
189
+ const a = t[s];
190
+ if (!a) throw new Error(`Mod "${s}" not found`);
191
+ return n(s), r(a.url);
192
+ }
193
+ return pe = {
194
+ registry: t,
195
+ load: r,
196
+ unload: n,
197
+ list: o,
198
+ reload: i
199
+ }, pe;
200
+ }
201
+ var C = /* @__PURE__ */ ((e) => (e[e.PAYLOAD_UNKNOWN = 0] = "PAYLOAD_UNKNOWN", e[e.JSON = 1] = "JSON", e[e.FLEX = 2] = "FLEX", e[e.PROTOBUF = 3] = "PROTOBUF", e[e.FLATBUFFER = 4] = "FLATBUFFER", e))(C || {}), $ = /* @__PURE__ */ ((e) => (e[e.UNKNOWN = 0] = "UNKNOWN", e[e.ADD = 1] = "ADD", e[e.READ = 2] = "READ", e[e.GET = 4] = "GET", e[e.SET = 8] = "SET", e[e.DEL = 16] = "DEL", e[e.STREAM = 32] = "STREAM", e[e.GROUP = 64] = "GROUP", e[e.LIST = 128] = "LIST", e[e.ACTION = 256] = "ACTION", e[e.MESSAGE = 512] = "MESSAGE", e[e.INFO = 1024] = "INFO", e[e.DEBUG = 2048] = "DEBUG", e[e.ERROR = 4096] = "ERROR", e[e.AUTH = 8192] = "AUTH", e[e.HEARTBEAT = 16384] = "HEARTBEAT", e[e.CONFIG_UPDATE = 32768] = "CONFIG_UPDATE", e[e.REDIS = 65536] = "REDIS", e[e.SUPABASE = 131072] = "SUPABASE", e[e.FILESYSTEM = 262144] = "FILESYSTEM", e[e.WEBSOCKET = 524288] = "WEBSOCKET", e[e.HTTP_API = 1048576] = "HTTP_API", e[e.LOCAL_CACHE = 2097152] = "LOCAL_CACHE", e[e.AI = 4194304] = "AI", e))($ || {});
202
+ function ke() {
203
+ return new jr.Builder();
204
+ }
205
+ function Gr(e) {
206
+ const t = ke();
207
+ t.startMap();
208
+ for (const [r, n] of Object.entries(e))
209
+ t.addKey(r), t.add(n);
210
+ return t.end(), t.finish();
211
+ }
212
+ function le(e, t, r, n, o = 1) {
213
+ let i;
214
+ if (r === C.FLEX)
215
+ i = Gr(e);
216
+ else if (r === C.JSON)
217
+ i = new TextEncoder().encode(JSON.stringify(e));
218
+ else
219
+ throw new Error("Unsupported format for wrapEnvelope");
220
+ const s = ke();
221
+ return s.startMap(), s.addKey("version"), s.add(o), s.addKey("kind"), s.add(t), s.addKey("format"), s.add(r), s.addKey("payload"), s.add(i), s.addKey("metadata"), s.add(n ?? new Uint8Array()), s.end(), s.finish();
222
+ }
223
+ function Ut(e) {
224
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e), r = Ne.toReference(t.buffer).toObject();
225
+ if (typeof r.version != "number" || typeof r.kind != "number" || typeof r.format != "number" || !r.payload)
226
+ throw console.error("[unwrapEnvelope] Bad root:", r), new Error("[unwrapEnvelope] Invalid envelope structure");
227
+ const n = {
228
+ version: r.version,
229
+ kind: r.kind,
230
+ format: r.format,
231
+ payload: new Uint8Array(r.payload),
232
+ metadata: r.metadata ? new Uint8Array(r.metadata) : void 0
233
+ };
234
+ let o;
235
+ if (n.format === C.FLEX)
236
+ o = Ne.toReference(n.payload.buffer).toObject();
237
+ else if (n.format === C.JSON)
238
+ o = JSON.parse(
239
+ new TextDecoder().decode(n.payload)
240
+ );
241
+ else
242
+ throw new Error(
243
+ `[unwrapEnvelope] Unsupported format: ${n.format}`
244
+ );
245
+ return { envelope: n, payload: o };
246
+ }
247
+ function jt(e) {
248
+ return Ne.toReference(e.buffer).toObject();
249
+ }
250
+ function Hr(e) {
251
+ try {
252
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e), r = jt(t);
253
+ console.log("[FlexObject]", JSON.stringify(r, null, 2));
254
+ } catch (t) {
255
+ console.error("[Flex Decode Error]", t);
256
+ }
257
+ }
258
+ function Lt(e, t) {
259
+ return (e & t) === t;
260
+ }
261
+ function Yr(e, t) {
262
+ return le(
263
+ { key: e, value: t },
264
+ $.SET | $.REDIS,
265
+ C.FLEX
266
+ );
267
+ }
268
+ function Xr(e) {
269
+ return le(
270
+ { key: e },
271
+ $.GET | $.REDIS,
272
+ C.FLEX
273
+ );
274
+ }
275
+ function qr(e) {
276
+ return le(
277
+ { key: e },
278
+ $.DEL | $.REDIS,
279
+ C.FLEX
280
+ );
281
+ }
282
+ function Kr(e) {
283
+ const t = Ut(e);
284
+ if (!Lt(t.envelope.kind, $.REDIS))
285
+ throw new Error("[Redis] Not a Redis envelope");
286
+ return t;
287
+ }
288
+ function Qr(e, t, r = "*") {
289
+ return le(
290
+ { stream: e, id: r, fields: t },
291
+ $.ADD | $.STREAM | $.REDIS,
292
+ C.FLEX
293
+ );
294
+ }
295
+ function en(e, t, r) {
296
+ const n = ke();
297
+ n.startMap(), n.addKey("streams"), n.startVector();
298
+ for (const { stream: s, id: a } of e)
299
+ n.startMap(), n.addKey("stream"), n.add(s), n.addKey("id"), n.add(a), n.end();
300
+ n.end(), t !== void 0 && (n.addKey("count"), n.add(t)), r !== void 0 && (n.addKey("block"), n.add(r)), n.end();
301
+ const o = n.finish(), i = ke();
302
+ return i.startMap(), i.addKey("version"), i.add(1), i.addKey("kind"), i.add($.READ | $.STREAM | $.REDIS), i.addKey("format"), i.add(C.FLEX), i.addKey("payload"), i.add(o), i.addKey("metadata"), i.add(new Uint8Array()), i.end(), i.finish();
303
+ }
304
+ const tn = {
305
+ wrapEnvelope: le,
306
+ unwrapEnvelope: Ut,
307
+ MessageKind: $,
308
+ PayloadFormat: C,
309
+ unwrapFlexToJson: jt,
310
+ inspectFlex: Hr,
311
+ hasKind: Lt,
312
+ redis: {
313
+ wrapRedisSet: Yr,
314
+ wrapRedisGet: Xr,
315
+ wrapRedisDel: qr,
316
+ wrapRedisXAdd: Qr,
317
+ wrapRedisXRead: en,
318
+ parseRedisPayload: Kr
319
+ }
320
+ };
321
+ function Mt(e) {
322
+ typeof queueMicrotask == "function" ? queueMicrotask(e) : setTimeout(e, 0);
323
+ }
324
+ function Ft(e) {
325
+ const t = document.createElement(e.tag);
326
+ if (e.class && (t.className = e.class), e.attrs)
327
+ for (const [r, n] of Object.entries(e.attrs))
328
+ if (typeof n == "function" && r.startsWith("on"))
329
+ t.addEventListener(r.slice(2).toLowerCase(), n);
330
+ else if (r === "style" && typeof n == "object")
331
+ Object.assign(t.style, n);
332
+ else if (r === "dataset" && typeof n == "object")
333
+ for (const [o, i] of Object.entries(n))
334
+ t.dataset[o] = String(i);
335
+ else
336
+ try {
337
+ t.setAttribute(r, String(n));
338
+ } catch {
339
+ }
340
+ if (e.style && Object.assign(t.style, e.style), e.children)
341
+ for (const r of e.children) {
342
+ const n = typeof r == "string" ? document.createTextNode(r) : Ft(r);
343
+ t.appendChild(n);
344
+ }
345
+ return t;
346
+ }
347
+ function l(e, t, r) {
348
+ function n(a, c) {
349
+ if (a._zod || Object.defineProperty(a, "_zod", {
350
+ value: {
351
+ def: c,
352
+ constr: s,
353
+ traits: /* @__PURE__ */ new Set()
354
+ },
355
+ enumerable: !1
356
+ }), a._zod.traits.has(e))
357
+ return;
358
+ a._zod.traits.add(e), t(a, c);
359
+ const u = s.prototype, f = Object.keys(u);
360
+ for (let d = 0; d < f.length; d++) {
361
+ const h = f[d];
362
+ h in a || (a[h] = u[h].bind(a));
363
+ }
364
+ }
365
+ const o = r?.Parent ?? Object;
366
+ class i extends o {
367
+ }
368
+ Object.defineProperty(i, "name", { value: e });
369
+ function s(a) {
370
+ var c;
371
+ const u = r?.Parent ? new i() : this;
372
+ n(u, a), (c = u._zod).deferred ?? (c.deferred = []);
373
+ for (const f of u._zod.deferred)
374
+ f();
375
+ return u;
376
+ }
377
+ return Object.defineProperty(s, "init", { value: n }), Object.defineProperty(s, Symbol.hasInstance, {
378
+ value: (a) => r?.Parent && a instanceof r.Parent ? !0 : a?._zod?.traits?.has(e)
379
+ }), Object.defineProperty(s, "name", { value: e }), s;
380
+ }
381
+ class q extends Error {
382
+ constructor() {
383
+ super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
384
+ }
385
+ }
386
+ class xt extends Error {
387
+ constructor(t) {
388
+ super(`Encountered unidirectional transform during encode: ${t}`), this.name = "ZodEncodeError";
389
+ }
390
+ }
391
+ const Bt = {};
392
+ function M(e) {
393
+ return Bt;
394
+ }
395
+ function Jt(e) {
396
+ const t = Object.values(e).filter((n) => typeof n == "number");
397
+ return Object.entries(e).filter(([n, o]) => t.indexOf(+n) === -1).map(([n, o]) => o);
398
+ }
399
+ function Ce(e, t) {
400
+ return typeof t == "bigint" ? t.toString() : t;
401
+ }
402
+ function Ve(e) {
403
+ return {
404
+ get value() {
405
+ {
406
+ const t = e();
407
+ return Object.defineProperty(this, "value", { value: t }), t;
408
+ }
409
+ }
410
+ };
411
+ }
412
+ function Ge(e) {
413
+ return e == null;
414
+ }
415
+ function He(e) {
416
+ const t = e.startsWith("^") ? 1 : 0, r = e.endsWith("$") ? e.length - 1 : e.length;
417
+ return e.slice(t, r);
418
+ }
419
+ function rn(e, t) {
420
+ const r = (e.toString().split(".")[1] || "").length, n = t.toString();
421
+ let o = (n.split(".")[1] || "").length;
422
+ if (o === 0 && /\d?e-\d?/.test(n)) {
423
+ const c = n.match(/\d?e-(\d?)/);
424
+ c?.[1] && (o = Number.parseInt(c[1]));
425
+ }
426
+ const i = r > o ? r : o, s = Number.parseInt(e.toFixed(i).replace(".", "")), a = Number.parseInt(t.toFixed(i).replace(".", ""));
427
+ return s % a / 10 ** i;
428
+ }
429
+ const nt = /* @__PURE__ */ Symbol("evaluating");
430
+ function w(e, t, r) {
431
+ let n;
432
+ Object.defineProperty(e, t, {
433
+ get() {
434
+ if (n !== nt)
435
+ return n === void 0 && (n = nt, n = r()), n;
436
+ },
437
+ set(o) {
438
+ Object.defineProperty(e, t, {
439
+ value: o
440
+ // configurable: true,
441
+ });
442
+ },
443
+ configurable: !0
444
+ });
445
+ }
446
+ function V(e, t, r) {
447
+ Object.defineProperty(e, t, {
448
+ value: r,
449
+ writable: !0,
450
+ enumerable: !0,
451
+ configurable: !0
452
+ });
453
+ }
454
+ function B(...e) {
455
+ const t = {};
456
+ for (const r of e) {
457
+ const n = Object.getOwnPropertyDescriptors(r);
458
+ Object.assign(t, n);
459
+ }
460
+ return Object.defineProperties({}, t);
461
+ }
462
+ function ot(e) {
463
+ return JSON.stringify(e);
464
+ }
465
+ function nn(e) {
466
+ return e.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
467
+ }
468
+ const Vt = "captureStackTrace" in Error ? Error.captureStackTrace : (...e) => {
469
+ };
470
+ function _e(e) {
471
+ return typeof e == "object" && e !== null && !Array.isArray(e);
472
+ }
473
+ const on = Ve(() => {
474
+ if (typeof navigator < "u" && navigator?.userAgent?.includes("Cloudflare"))
475
+ return !1;
476
+ try {
477
+ const e = Function;
478
+ return new e(""), !0;
479
+ } catch {
480
+ return !1;
481
+ }
482
+ });
483
+ function ee(e) {
484
+ if (_e(e) === !1)
485
+ return !1;
486
+ const t = e.constructor;
487
+ if (t === void 0 || typeof t != "function")
488
+ return !0;
489
+ const r = t.prototype;
490
+ return !(_e(r) === !1 || Object.prototype.hasOwnProperty.call(r, "isPrototypeOf") === !1);
491
+ }
492
+ function Gt(e) {
493
+ return ee(e) ? { ...e } : Array.isArray(e) ? [...e] : e;
494
+ }
495
+ const sn = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
496
+ function $e(e) {
497
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
498
+ }
499
+ function J(e, t, r) {
500
+ const n = new e._zod.constr(t ?? e._zod.def);
501
+ return (!t || r?.parent) && (n._zod.parent = e), n;
502
+ }
503
+ function p(e) {
504
+ const t = e;
505
+ if (!t)
506
+ return {};
507
+ if (typeof t == "string")
508
+ return { error: () => t };
509
+ if (t?.message !== void 0) {
510
+ if (t?.error !== void 0)
511
+ throw new Error("Cannot specify both `message` and `error` params");
512
+ t.error = t.message;
513
+ }
514
+ return delete t.message, typeof t.error == "string" ? { ...t, error: () => t.error } : t;
515
+ }
516
+ function an(e) {
517
+ return Object.keys(e).filter((t) => e[t]._zod.optin === "optional" && e[t]._zod.optout === "optional");
518
+ }
519
+ const cn = {
520
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
521
+ int32: [-2147483648, 2147483647],
522
+ uint32: [0, 4294967295],
523
+ float32: [-34028234663852886e22, 34028234663852886e22],
524
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
525
+ };
526
+ function un(e, t) {
527
+ const r = e._zod.def, n = r.checks;
528
+ if (n && n.length > 0)
529
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
530
+ const i = B(e._zod.def, {
531
+ get shape() {
532
+ const s = {};
533
+ for (const a in t) {
534
+ if (!(a in r.shape))
535
+ throw new Error(`Unrecognized key: "${a}"`);
536
+ t[a] && (s[a] = r.shape[a]);
537
+ }
538
+ return V(this, "shape", s), s;
539
+ },
540
+ checks: []
541
+ });
542
+ return J(e, i);
543
+ }
544
+ function ln(e, t) {
545
+ const r = e._zod.def, n = r.checks;
546
+ if (n && n.length > 0)
547
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
548
+ const i = B(e._zod.def, {
549
+ get shape() {
550
+ const s = { ...e._zod.def.shape };
551
+ for (const a in t) {
552
+ if (!(a in r.shape))
553
+ throw new Error(`Unrecognized key: "${a}"`);
554
+ t[a] && delete s[a];
555
+ }
556
+ return V(this, "shape", s), s;
557
+ },
558
+ checks: []
559
+ });
560
+ return J(e, i);
561
+ }
562
+ function dn(e, t) {
563
+ if (!ee(t))
564
+ throw new Error("Invalid input to extend: expected a plain object");
565
+ const r = e._zod.def.checks;
566
+ if (r && r.length > 0) {
567
+ const i = e._zod.def.shape;
568
+ for (const s in t)
569
+ if (Object.getOwnPropertyDescriptor(i, s) !== void 0)
570
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
571
+ }
572
+ const o = B(e._zod.def, {
573
+ get shape() {
574
+ const i = { ...e._zod.def.shape, ...t };
575
+ return V(this, "shape", i), i;
576
+ }
577
+ });
578
+ return J(e, o);
579
+ }
580
+ function fn(e, t) {
581
+ if (!ee(t))
582
+ throw new Error("Invalid input to safeExtend: expected a plain object");
583
+ const r = B(e._zod.def, {
584
+ get shape() {
585
+ const n = { ...e._zod.def.shape, ...t };
586
+ return V(this, "shape", n), n;
587
+ }
588
+ });
589
+ return J(e, r);
590
+ }
591
+ function hn(e, t) {
592
+ const r = B(e._zod.def, {
593
+ get shape() {
594
+ const n = { ...e._zod.def.shape, ...t._zod.def.shape };
595
+ return V(this, "shape", n), n;
596
+ },
597
+ get catchall() {
598
+ return t._zod.def.catchall;
599
+ },
600
+ checks: []
601
+ // delete existing checks
602
+ });
603
+ return J(e, r);
604
+ }
605
+ function pn(e, t, r) {
606
+ const o = t._zod.def.checks;
607
+ if (o && o.length > 0)
608
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
609
+ const s = B(t._zod.def, {
610
+ get shape() {
611
+ const a = t._zod.def.shape, c = { ...a };
612
+ if (r)
613
+ for (const u in r) {
614
+ if (!(u in a))
615
+ throw new Error(`Unrecognized key: "${u}"`);
616
+ r[u] && (c[u] = e ? new e({
617
+ type: "optional",
618
+ innerType: a[u]
619
+ }) : a[u]);
620
+ }
621
+ else
622
+ for (const u in a)
623
+ c[u] = e ? new e({
624
+ type: "optional",
625
+ innerType: a[u]
626
+ }) : a[u];
627
+ return V(this, "shape", c), c;
628
+ },
629
+ checks: []
630
+ });
631
+ return J(t, s);
632
+ }
633
+ function mn(e, t, r) {
634
+ const n = B(t._zod.def, {
635
+ get shape() {
636
+ const o = t._zod.def.shape, i = { ...o };
637
+ if (r)
638
+ for (const s in r) {
639
+ if (!(s in i))
640
+ throw new Error(`Unrecognized key: "${s}"`);
641
+ r[s] && (i[s] = new e({
642
+ type: "nonoptional",
643
+ innerType: o[s]
644
+ }));
645
+ }
646
+ else
647
+ for (const s in o)
648
+ i[s] = new e({
649
+ type: "nonoptional",
650
+ innerType: o[s]
651
+ });
652
+ return V(this, "shape", i), i;
653
+ }
654
+ });
655
+ return J(t, n);
656
+ }
657
+ function Y(e, t = 0) {
658
+ if (e.aborted === !0)
659
+ return !0;
660
+ for (let r = t; r < e.issues.length; r++)
661
+ if (e.issues[r]?.continue !== !0)
662
+ return !0;
663
+ return !1;
664
+ }
665
+ function X(e, t) {
666
+ return t.map((r) => {
667
+ var n;
668
+ return (n = r).path ?? (n.path = []), r.path.unshift(e), r;
669
+ });
670
+ }
671
+ function me(e) {
672
+ return typeof e == "string" ? e : e?.message;
673
+ }
674
+ function F(e, t, r) {
675
+ const n = { ...e, path: e.path ?? [] };
676
+ if (!e.message) {
677
+ const o = me(e.inst?._zod.def?.error?.(e)) ?? me(t?.error?.(e)) ?? me(r.customError?.(e)) ?? me(r.localeError?.(e)) ?? "Invalid input";
678
+ n.message = o;
679
+ }
680
+ return delete n.inst, delete n.continue, t?.reportInput || delete n.input, n;
681
+ }
682
+ function Ye(e) {
683
+ return Array.isArray(e) ? "array" : typeof e == "string" ? "string" : "unknown";
684
+ }
685
+ function ae(...e) {
686
+ const [t, r, n] = e;
687
+ return typeof t == "string" ? {
688
+ message: t,
689
+ code: "custom",
690
+ input: r,
691
+ inst: n
692
+ } : { ...t };
693
+ }
694
+ const Ht = (e, t) => {
695
+ e.name = "$ZodError", Object.defineProperty(e, "_zod", {
696
+ value: e._zod,
697
+ enumerable: !1
698
+ }), Object.defineProperty(e, "issues", {
699
+ value: t,
700
+ enumerable: !1
701
+ }), e.message = JSON.stringify(t, Ce, 2), Object.defineProperty(e, "toString", {
702
+ value: () => e.message,
703
+ enumerable: !1
704
+ });
705
+ }, Yt = l("$ZodError", Ht), Xt = l("$ZodError", Ht, { Parent: Error });
706
+ function wn(e, t = (r) => r.message) {
707
+ const r = {}, n = [];
708
+ for (const o of e.issues)
709
+ o.path.length > 0 ? (r[o.path[0]] = r[o.path[0]] || [], r[o.path[0]].push(t(o))) : n.push(t(o));
710
+ return { formErrors: n, fieldErrors: r };
711
+ }
712
+ function gn(e, t = (r) => r.message) {
713
+ const r = { _errors: [] }, n = (o) => {
714
+ for (const i of o.issues)
715
+ if (i.code === "invalid_union" && i.errors.length)
716
+ i.errors.map((s) => n({ issues: s }));
717
+ else if (i.code === "invalid_key")
718
+ n({ issues: i.issues });
719
+ else if (i.code === "invalid_element")
720
+ n({ issues: i.issues });
721
+ else if (i.path.length === 0)
722
+ r._errors.push(t(i));
723
+ else {
724
+ let s = r, a = 0;
725
+ for (; a < i.path.length; ) {
726
+ const c = i.path[a];
727
+ a === i.path.length - 1 ? (s[c] = s[c] || { _errors: [] }, s[c]._errors.push(t(i))) : s[c] = s[c] || { _errors: [] }, s = s[c], a++;
728
+ }
729
+ }
730
+ };
731
+ return n(e), r;
732
+ }
733
+ const Xe = (e) => (t, r, n, o) => {
734
+ const i = n ? Object.assign(n, { async: !1 }) : { async: !1 }, s = t._zod.run({ value: r, issues: [] }, i);
735
+ if (s instanceof Promise)
736
+ throw new q();
737
+ if (s.issues.length) {
738
+ const a = new (o?.Err ?? e)(s.issues.map((c) => F(c, i, M())));
739
+ throw Vt(a, o?.callee), a;
740
+ }
741
+ return s.value;
742
+ }, qe = (e) => async (t, r, n, o) => {
743
+ const i = n ? Object.assign(n, { async: !0 }) : { async: !0 };
744
+ let s = t._zod.run({ value: r, issues: [] }, i);
745
+ if (s instanceof Promise && (s = await s), s.issues.length) {
746
+ const a = new (o?.Err ?? e)(s.issues.map((c) => F(c, i, M())));
747
+ throw Vt(a, o?.callee), a;
748
+ }
749
+ return s.value;
750
+ }, Oe = (e) => (t, r, n) => {
751
+ const o = n ? { ...n, async: !1 } : { async: !1 }, i = t._zod.run({ value: r, issues: [] }, o);
752
+ if (i instanceof Promise)
753
+ throw new q();
754
+ return i.issues.length ? {
755
+ success: !1,
756
+ error: new (e ?? Yt)(i.issues.map((s) => F(s, o, M())))
757
+ } : { success: !0, data: i.value };
758
+ }, yn = /* @__PURE__ */ Oe(Xt), Pe = (e) => async (t, r, n) => {
759
+ const o = n ? Object.assign(n, { async: !0 }) : { async: !0 };
760
+ let i = t._zod.run({ value: r, issues: [] }, o);
761
+ return i instanceof Promise && (i = await i), i.issues.length ? {
762
+ success: !1,
763
+ error: new e(i.issues.map((s) => F(s, o, M())))
764
+ } : { success: !0, data: i.value };
765
+ }, vn = /* @__PURE__ */ Pe(Xt), kn = (e) => (t, r, n) => {
766
+ const o = n ? Object.assign(n, { direction: "backward" }) : { direction: "backward" };
767
+ return Xe(e)(t, r, o);
768
+ }, _n = (e) => (t, r, n) => Xe(e)(t, r, n), bn = (e) => async (t, r, n) => {
769
+ const o = n ? Object.assign(n, { direction: "backward" }) : { direction: "backward" };
770
+ return qe(e)(t, r, o);
771
+ }, Sn = (e) => async (t, r, n) => qe(e)(t, r, n), zn = (e) => (t, r, n) => {
772
+ const o = n ? Object.assign(n, { direction: "backward" }) : { direction: "backward" };
773
+ return Oe(e)(t, r, o);
774
+ }, En = (e) => (t, r, n) => Oe(e)(t, r, n), Tn = (e) => async (t, r, n) => {
775
+ const o = n ? Object.assign(n, { direction: "backward" }) : { direction: "backward" };
776
+ return Pe(e)(t, r, o);
777
+ }, $n = (e) => async (t, r, n) => Pe(e)(t, r, n), On = /^[cC][^\s-]{8,}$/, Pn = /^[0-9a-z]+$/, Wn = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/, Zn = /^[0-9a-vA-V]{20}$/, Rn = /^[A-Za-z0-9]{27}$/, In = /^[a-zA-Z0-9_-]{21}$/, An = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/, Nn = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/, st = (e) => e ? new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`) : /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/, Dn = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/, Cn = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
778
+ function Un() {
779
+ return new RegExp(Cn, "u");
780
+ }
781
+ const jn = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, Ln = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/, Mn = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/, Fn = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, xn = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, qt = /^[A-Za-z0-9_-]*$/, Bn = /^\+[1-9]\d{6,14}$/, Kt = "(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))", Jn = /* @__PURE__ */ new RegExp(`^${Kt}$`);
782
+ function Qt(e) {
783
+ const t = "(?:[01]\\d|2[0-3]):[0-5]\\d";
784
+ return typeof e.precision == "number" ? e.precision === -1 ? `${t}` : e.precision === 0 ? `${t}:[0-5]\\d` : `${t}:[0-5]\\d\\.\\d{${e.precision}}` : `${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;
785
+ }
786
+ function Vn(e) {
787
+ return new RegExp(`^${Qt(e)}$`);
788
+ }
789
+ function Gn(e) {
790
+ const t = Qt({ precision: e.precision }), r = ["Z"];
791
+ e.local && r.push(""), e.offset && r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");
792
+ const n = `${t}(?:${r.join("|")})`;
793
+ return new RegExp(`^${Kt}T(?:${n})$`);
794
+ }
795
+ const Hn = (e) => {
796
+ const t = e ? `[\\s\\S]{${e?.minimum ?? 0},${e?.maximum ?? ""}}` : "[\\s\\S]*";
797
+ return new RegExp(`^${t}$`);
798
+ }, Yn = /^-?\d+$/, er = /^-?\d+(?:\.\d+)?$/, Xn = /^(?:true|false)$/i, qn = /^[^A-Z]*$/, Kn = /^[^a-z]*$/, Z = /* @__PURE__ */ l("$ZodCheck", (e, t) => {
799
+ var r;
800
+ e._zod ?? (e._zod = {}), e._zod.def = t, (r = e._zod).onattach ?? (r.onattach = []);
801
+ }), tr = {
802
+ number: "number",
803
+ bigint: "bigint",
804
+ object: "date"
805
+ }, rr = /* @__PURE__ */ l("$ZodCheckLessThan", (e, t) => {
806
+ Z.init(e, t);
807
+ const r = tr[typeof t.value];
808
+ e._zod.onattach.push((n) => {
809
+ const o = n._zod.bag, i = (t.inclusive ? o.maximum : o.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
810
+ t.value < i && (t.inclusive ? o.maximum = t.value : o.exclusiveMaximum = t.value);
811
+ }), e._zod.check = (n) => {
812
+ (t.inclusive ? n.value <= t.value : n.value < t.value) || n.issues.push({
813
+ origin: r,
814
+ code: "too_big",
815
+ maximum: typeof t.value == "object" ? t.value.getTime() : t.value,
816
+ input: n.value,
817
+ inclusive: t.inclusive,
818
+ inst: e,
819
+ continue: !t.abort
820
+ });
821
+ };
822
+ }), nr = /* @__PURE__ */ l("$ZodCheckGreaterThan", (e, t) => {
823
+ Z.init(e, t);
824
+ const r = tr[typeof t.value];
825
+ e._zod.onattach.push((n) => {
826
+ const o = n._zod.bag, i = (t.inclusive ? o.minimum : o.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
827
+ t.value > i && (t.inclusive ? o.minimum = t.value : o.exclusiveMinimum = t.value);
828
+ }), e._zod.check = (n) => {
829
+ (t.inclusive ? n.value >= t.value : n.value > t.value) || n.issues.push({
830
+ origin: r,
831
+ code: "too_small",
832
+ minimum: typeof t.value == "object" ? t.value.getTime() : t.value,
833
+ input: n.value,
834
+ inclusive: t.inclusive,
835
+ inst: e,
836
+ continue: !t.abort
837
+ });
838
+ };
839
+ }), Qn = /* @__PURE__ */ l("$ZodCheckMultipleOf", (e, t) => {
840
+ Z.init(e, t), e._zod.onattach.push((r) => {
841
+ var n;
842
+ (n = r._zod.bag).multipleOf ?? (n.multipleOf = t.value);
843
+ }), e._zod.check = (r) => {
844
+ if (typeof r.value != typeof t.value)
845
+ throw new Error("Cannot mix number and bigint in multiple_of check.");
846
+ (typeof r.value == "bigint" ? r.value % t.value === BigInt(0) : rn(r.value, t.value) === 0) || r.issues.push({
847
+ origin: typeof r.value,
848
+ code: "not_multiple_of",
849
+ divisor: t.value,
850
+ input: r.value,
851
+ inst: e,
852
+ continue: !t.abort
853
+ });
854
+ };
855
+ }), eo = /* @__PURE__ */ l("$ZodCheckNumberFormat", (e, t) => {
856
+ Z.init(e, t), t.format = t.format || "float64";
857
+ const r = t.format?.includes("int"), n = r ? "int" : "number", [o, i] = cn[t.format];
858
+ e._zod.onattach.push((s) => {
859
+ const a = s._zod.bag;
860
+ a.format = t.format, a.minimum = o, a.maximum = i, r && (a.pattern = Yn);
861
+ }), e._zod.check = (s) => {
862
+ const a = s.value;
863
+ if (r) {
864
+ if (!Number.isInteger(a)) {
865
+ s.issues.push({
866
+ expected: n,
867
+ format: t.format,
868
+ code: "invalid_type",
869
+ continue: !1,
870
+ input: a,
871
+ inst: e
872
+ });
873
+ return;
874
+ }
875
+ if (!Number.isSafeInteger(a)) {
876
+ a > 0 ? s.issues.push({
877
+ input: a,
878
+ code: "too_big",
879
+ maximum: Number.MAX_SAFE_INTEGER,
880
+ note: "Integers must be within the safe integer range.",
881
+ inst: e,
882
+ origin: n,
883
+ inclusive: !0,
884
+ continue: !t.abort
885
+ }) : s.issues.push({
886
+ input: a,
887
+ code: "too_small",
888
+ minimum: Number.MIN_SAFE_INTEGER,
889
+ note: "Integers must be within the safe integer range.",
890
+ inst: e,
891
+ origin: n,
892
+ inclusive: !0,
893
+ continue: !t.abort
894
+ });
895
+ return;
896
+ }
897
+ }
898
+ a < o && s.issues.push({
899
+ origin: "number",
900
+ input: a,
901
+ code: "too_small",
902
+ minimum: o,
903
+ inclusive: !0,
904
+ inst: e,
905
+ continue: !t.abort
906
+ }), a > i && s.issues.push({
907
+ origin: "number",
908
+ input: a,
909
+ code: "too_big",
910
+ maximum: i,
911
+ inclusive: !0,
912
+ inst: e,
913
+ continue: !t.abort
914
+ });
915
+ };
916
+ }), to = /* @__PURE__ */ l("$ZodCheckMaxLength", (e, t) => {
917
+ var r;
918
+ Z.init(e, t), (r = e._zod.def).when ?? (r.when = (n) => {
919
+ const o = n.value;
920
+ return !Ge(o) && o.length !== void 0;
921
+ }), e._zod.onattach.push((n) => {
922
+ const o = n._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
923
+ t.maximum < o && (n._zod.bag.maximum = t.maximum);
924
+ }), e._zod.check = (n) => {
925
+ const o = n.value;
926
+ if (o.length <= t.maximum)
927
+ return;
928
+ const s = Ye(o);
929
+ n.issues.push({
930
+ origin: s,
931
+ code: "too_big",
932
+ maximum: t.maximum,
933
+ inclusive: !0,
934
+ input: o,
935
+ inst: e,
936
+ continue: !t.abort
937
+ });
938
+ };
939
+ }), ro = /* @__PURE__ */ l("$ZodCheckMinLength", (e, t) => {
940
+ var r;
941
+ Z.init(e, t), (r = e._zod.def).when ?? (r.when = (n) => {
942
+ const o = n.value;
943
+ return !Ge(o) && o.length !== void 0;
944
+ }), e._zod.onattach.push((n) => {
945
+ const o = n._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
946
+ t.minimum > o && (n._zod.bag.minimum = t.minimum);
947
+ }), e._zod.check = (n) => {
948
+ const o = n.value;
949
+ if (o.length >= t.minimum)
950
+ return;
951
+ const s = Ye(o);
952
+ n.issues.push({
953
+ origin: s,
954
+ code: "too_small",
955
+ minimum: t.minimum,
956
+ inclusive: !0,
957
+ input: o,
958
+ inst: e,
959
+ continue: !t.abort
960
+ });
961
+ };
962
+ }), no = /* @__PURE__ */ l("$ZodCheckLengthEquals", (e, t) => {
963
+ var r;
964
+ Z.init(e, t), (r = e._zod.def).when ?? (r.when = (n) => {
965
+ const o = n.value;
966
+ return !Ge(o) && o.length !== void 0;
967
+ }), e._zod.onattach.push((n) => {
968
+ const o = n._zod.bag;
969
+ o.minimum = t.length, o.maximum = t.length, o.length = t.length;
970
+ }), e._zod.check = (n) => {
971
+ const o = n.value, i = o.length;
972
+ if (i === t.length)
973
+ return;
974
+ const s = Ye(o), a = i > t.length;
975
+ n.issues.push({
976
+ origin: s,
977
+ ...a ? { code: "too_big", maximum: t.length } : { code: "too_small", minimum: t.length },
978
+ inclusive: !0,
979
+ exact: !0,
980
+ input: n.value,
981
+ inst: e,
982
+ continue: !t.abort
983
+ });
984
+ };
985
+ }), We = /* @__PURE__ */ l("$ZodCheckStringFormat", (e, t) => {
986
+ var r, n;
987
+ Z.init(e, t), e._zod.onattach.push((o) => {
988
+ const i = o._zod.bag;
989
+ i.format = t.format, t.pattern && (i.patterns ?? (i.patterns = /* @__PURE__ */ new Set()), i.patterns.add(t.pattern));
990
+ }), t.pattern ? (r = e._zod).check ?? (r.check = (o) => {
991
+ t.pattern.lastIndex = 0, !t.pattern.test(o.value) && o.issues.push({
992
+ origin: "string",
993
+ code: "invalid_format",
994
+ format: t.format,
995
+ input: o.value,
996
+ ...t.pattern ? { pattern: t.pattern.toString() } : {},
997
+ inst: e,
998
+ continue: !t.abort
999
+ });
1000
+ }) : (n = e._zod).check ?? (n.check = () => {
1001
+ });
1002
+ }), oo = /* @__PURE__ */ l("$ZodCheckRegex", (e, t) => {
1003
+ We.init(e, t), e._zod.check = (r) => {
1004
+ t.pattern.lastIndex = 0, !t.pattern.test(r.value) && r.issues.push({
1005
+ origin: "string",
1006
+ code: "invalid_format",
1007
+ format: "regex",
1008
+ input: r.value,
1009
+ pattern: t.pattern.toString(),
1010
+ inst: e,
1011
+ continue: !t.abort
1012
+ });
1013
+ };
1014
+ }), so = /* @__PURE__ */ l("$ZodCheckLowerCase", (e, t) => {
1015
+ t.pattern ?? (t.pattern = qn), We.init(e, t);
1016
+ }), io = /* @__PURE__ */ l("$ZodCheckUpperCase", (e, t) => {
1017
+ t.pattern ?? (t.pattern = Kn), We.init(e, t);
1018
+ }), ao = /* @__PURE__ */ l("$ZodCheckIncludes", (e, t) => {
1019
+ Z.init(e, t);
1020
+ const r = $e(t.includes), n = new RegExp(typeof t.position == "number" ? `^.{${t.position}}${r}` : r);
1021
+ t.pattern = n, e._zod.onattach.push((o) => {
1022
+ const i = o._zod.bag;
1023
+ i.patterns ?? (i.patterns = /* @__PURE__ */ new Set()), i.patterns.add(n);
1024
+ }), e._zod.check = (o) => {
1025
+ o.value.includes(t.includes, t.position) || o.issues.push({
1026
+ origin: "string",
1027
+ code: "invalid_format",
1028
+ format: "includes",
1029
+ includes: t.includes,
1030
+ input: o.value,
1031
+ inst: e,
1032
+ continue: !t.abort
1033
+ });
1034
+ };
1035
+ }), co = /* @__PURE__ */ l("$ZodCheckStartsWith", (e, t) => {
1036
+ Z.init(e, t);
1037
+ const r = new RegExp(`^${$e(t.prefix)}.*`);
1038
+ t.pattern ?? (t.pattern = r), e._zod.onattach.push((n) => {
1039
+ const o = n._zod.bag;
1040
+ o.patterns ?? (o.patterns = /* @__PURE__ */ new Set()), o.patterns.add(r);
1041
+ }), e._zod.check = (n) => {
1042
+ n.value.startsWith(t.prefix) || n.issues.push({
1043
+ origin: "string",
1044
+ code: "invalid_format",
1045
+ format: "starts_with",
1046
+ prefix: t.prefix,
1047
+ input: n.value,
1048
+ inst: e,
1049
+ continue: !t.abort
1050
+ });
1051
+ };
1052
+ }), uo = /* @__PURE__ */ l("$ZodCheckEndsWith", (e, t) => {
1053
+ Z.init(e, t);
1054
+ const r = new RegExp(`.*${$e(t.suffix)}$`);
1055
+ t.pattern ?? (t.pattern = r), e._zod.onattach.push((n) => {
1056
+ const o = n._zod.bag;
1057
+ o.patterns ?? (o.patterns = /* @__PURE__ */ new Set()), o.patterns.add(r);
1058
+ }), e._zod.check = (n) => {
1059
+ n.value.endsWith(t.suffix) || n.issues.push({
1060
+ origin: "string",
1061
+ code: "invalid_format",
1062
+ format: "ends_with",
1063
+ suffix: t.suffix,
1064
+ input: n.value,
1065
+ inst: e,
1066
+ continue: !t.abort
1067
+ });
1068
+ };
1069
+ }), lo = /* @__PURE__ */ l("$ZodCheckOverwrite", (e, t) => {
1070
+ Z.init(e, t), e._zod.check = (r) => {
1071
+ r.value = t.tx(r.value);
1072
+ };
1073
+ });
1074
+ class fo {
1075
+ constructor(t = []) {
1076
+ this.content = [], this.indent = 0, this && (this.args = t);
1077
+ }
1078
+ indented(t) {
1079
+ this.indent += 1, t(this), this.indent -= 1;
1080
+ }
1081
+ write(t) {
1082
+ if (typeof t == "function") {
1083
+ t(this, { execution: "sync" }), t(this, { execution: "async" });
1084
+ return;
1085
+ }
1086
+ const n = t.split(`
1087
+ `).filter((s) => s), o = Math.min(...n.map((s) => s.length - s.trimStart().length)), i = n.map((s) => s.slice(o)).map((s) => " ".repeat(this.indent * 2) + s);
1088
+ for (const s of i)
1089
+ this.content.push(s);
1090
+ }
1091
+ compile() {
1092
+ const t = Function, r = this?.args, o = [...(this?.content ?? [""]).map((i) => ` ${i}`)];
1093
+ return new t(...r, o.join(`
1094
+ `));
1095
+ }
1096
+ }
1097
+ const ho = {
1098
+ major: 4,
1099
+ minor: 3,
1100
+ patch: 6
1101
+ }, g = /* @__PURE__ */ l("$ZodType", (e, t) => {
1102
+ var r;
1103
+ e ?? (e = {}), e._zod.def = t, e._zod.bag = e._zod.bag || {}, e._zod.version = ho;
1104
+ const n = [...e._zod.def.checks ?? []];
1105
+ e._zod.traits.has("$ZodCheck") && n.unshift(e);
1106
+ for (const o of n)
1107
+ for (const i of o._zod.onattach)
1108
+ i(e);
1109
+ if (n.length === 0)
1110
+ (r = e._zod).deferred ?? (r.deferred = []), e._zod.deferred?.push(() => {
1111
+ e._zod.run = e._zod.parse;
1112
+ });
1113
+ else {
1114
+ const o = (s, a, c) => {
1115
+ let u = Y(s), f;
1116
+ for (const d of a) {
1117
+ if (d._zod.def.when) {
1118
+ if (!d._zod.def.when(s))
1119
+ continue;
1120
+ } else if (u)
1121
+ continue;
1122
+ const h = s.issues.length, m = d._zod.check(s);
1123
+ if (m instanceof Promise && c?.async === !1)
1124
+ throw new q();
1125
+ if (f || m instanceof Promise)
1126
+ f = (f ?? Promise.resolve()).then(async () => {
1127
+ await m, s.issues.length !== h && (u || (u = Y(s, h)));
1128
+ });
1129
+ else {
1130
+ if (s.issues.length === h)
1131
+ continue;
1132
+ u || (u = Y(s, h));
1133
+ }
1134
+ }
1135
+ return f ? f.then(() => s) : s;
1136
+ }, i = (s, a, c) => {
1137
+ if (Y(s))
1138
+ return s.aborted = !0, s;
1139
+ const u = o(a, n, c);
1140
+ if (u instanceof Promise) {
1141
+ if (c.async === !1)
1142
+ throw new q();
1143
+ return u.then((f) => e._zod.parse(f, c));
1144
+ }
1145
+ return e._zod.parse(u, c);
1146
+ };
1147
+ e._zod.run = (s, a) => {
1148
+ if (a.skipChecks)
1149
+ return e._zod.parse(s, a);
1150
+ if (a.direction === "backward") {
1151
+ const u = e._zod.parse({ value: s.value, issues: [] }, { ...a, skipChecks: !0 });
1152
+ return u instanceof Promise ? u.then((f) => i(f, s, a)) : i(u, s, a);
1153
+ }
1154
+ const c = e._zod.parse(s, a);
1155
+ if (c instanceof Promise) {
1156
+ if (a.async === !1)
1157
+ throw new q();
1158
+ return c.then((u) => o(u, n, a));
1159
+ }
1160
+ return o(c, n, a);
1161
+ };
1162
+ }
1163
+ w(e, "~standard", () => ({
1164
+ validate: (o) => {
1165
+ try {
1166
+ const i = yn(e, o);
1167
+ return i.success ? { value: i.data } : { issues: i.error?.issues };
1168
+ } catch {
1169
+ return vn(e, o).then((s) => s.success ? { value: s.data } : { issues: s.error?.issues });
1170
+ }
1171
+ },
1172
+ vendor: "zod",
1173
+ version: 1
1174
+ }));
1175
+ }), Ke = /* @__PURE__ */ l("$ZodString", (e, t) => {
1176
+ g.init(e, t), e._zod.pattern = [...e?._zod.bag?.patterns ?? []].pop() ?? Hn(e._zod.bag), e._zod.parse = (r, n) => {
1177
+ if (t.coerce)
1178
+ try {
1179
+ r.value = String(r.value);
1180
+ } catch {
1181
+ }
1182
+ return typeof r.value == "string" || r.issues.push({
1183
+ expected: "string",
1184
+ code: "invalid_type",
1185
+ input: r.value,
1186
+ inst: e
1187
+ }), r;
1188
+ };
1189
+ }), y = /* @__PURE__ */ l("$ZodStringFormat", (e, t) => {
1190
+ We.init(e, t), Ke.init(e, t);
1191
+ }), po = /* @__PURE__ */ l("$ZodGUID", (e, t) => {
1192
+ t.pattern ?? (t.pattern = Nn), y.init(e, t);
1193
+ }), mo = /* @__PURE__ */ l("$ZodUUID", (e, t) => {
1194
+ if (t.version) {
1195
+ const n = {
1196
+ v1: 1,
1197
+ v2: 2,
1198
+ v3: 3,
1199
+ v4: 4,
1200
+ v5: 5,
1201
+ v6: 6,
1202
+ v7: 7,
1203
+ v8: 8
1204
+ }[t.version];
1205
+ if (n === void 0)
1206
+ throw new Error(`Invalid UUID version: "${t.version}"`);
1207
+ t.pattern ?? (t.pattern = st(n));
1208
+ } else
1209
+ t.pattern ?? (t.pattern = st());
1210
+ y.init(e, t);
1211
+ }), wo = /* @__PURE__ */ l("$ZodEmail", (e, t) => {
1212
+ t.pattern ?? (t.pattern = Dn), y.init(e, t);
1213
+ }), go = /* @__PURE__ */ l("$ZodURL", (e, t) => {
1214
+ y.init(e, t), e._zod.check = (r) => {
1215
+ try {
1216
+ const n = r.value.trim(), o = new URL(n);
1217
+ t.hostname && (t.hostname.lastIndex = 0, t.hostname.test(o.hostname) || r.issues.push({
1218
+ code: "invalid_format",
1219
+ format: "url",
1220
+ note: "Invalid hostname",
1221
+ pattern: t.hostname.source,
1222
+ input: r.value,
1223
+ inst: e,
1224
+ continue: !t.abort
1225
+ })), t.protocol && (t.protocol.lastIndex = 0, t.protocol.test(o.protocol.endsWith(":") ? o.protocol.slice(0, -1) : o.protocol) || r.issues.push({
1226
+ code: "invalid_format",
1227
+ format: "url",
1228
+ note: "Invalid protocol",
1229
+ pattern: t.protocol.source,
1230
+ input: r.value,
1231
+ inst: e,
1232
+ continue: !t.abort
1233
+ })), t.normalize ? r.value = o.href : r.value = n;
1234
+ return;
1235
+ } catch {
1236
+ r.issues.push({
1237
+ code: "invalid_format",
1238
+ format: "url",
1239
+ input: r.value,
1240
+ inst: e,
1241
+ continue: !t.abort
1242
+ });
1243
+ }
1244
+ };
1245
+ }), yo = /* @__PURE__ */ l("$ZodEmoji", (e, t) => {
1246
+ t.pattern ?? (t.pattern = Un()), y.init(e, t);
1247
+ }), vo = /* @__PURE__ */ l("$ZodNanoID", (e, t) => {
1248
+ t.pattern ?? (t.pattern = In), y.init(e, t);
1249
+ }), ko = /* @__PURE__ */ l("$ZodCUID", (e, t) => {
1250
+ t.pattern ?? (t.pattern = On), y.init(e, t);
1251
+ }), _o = /* @__PURE__ */ l("$ZodCUID2", (e, t) => {
1252
+ t.pattern ?? (t.pattern = Pn), y.init(e, t);
1253
+ }), bo = /* @__PURE__ */ l("$ZodULID", (e, t) => {
1254
+ t.pattern ?? (t.pattern = Wn), y.init(e, t);
1255
+ }), So = /* @__PURE__ */ l("$ZodXID", (e, t) => {
1256
+ t.pattern ?? (t.pattern = Zn), y.init(e, t);
1257
+ }), zo = /* @__PURE__ */ l("$ZodKSUID", (e, t) => {
1258
+ t.pattern ?? (t.pattern = Rn), y.init(e, t);
1259
+ }), Eo = /* @__PURE__ */ l("$ZodISODateTime", (e, t) => {
1260
+ t.pattern ?? (t.pattern = Gn(t)), y.init(e, t);
1261
+ }), To = /* @__PURE__ */ l("$ZodISODate", (e, t) => {
1262
+ t.pattern ?? (t.pattern = Jn), y.init(e, t);
1263
+ }), $o = /* @__PURE__ */ l("$ZodISOTime", (e, t) => {
1264
+ t.pattern ?? (t.pattern = Vn(t)), y.init(e, t);
1265
+ }), Oo = /* @__PURE__ */ l("$ZodISODuration", (e, t) => {
1266
+ t.pattern ?? (t.pattern = An), y.init(e, t);
1267
+ }), Po = /* @__PURE__ */ l("$ZodIPv4", (e, t) => {
1268
+ t.pattern ?? (t.pattern = jn), y.init(e, t), e._zod.bag.format = "ipv4";
1269
+ }), Wo = /* @__PURE__ */ l("$ZodIPv6", (e, t) => {
1270
+ t.pattern ?? (t.pattern = Ln), y.init(e, t), e._zod.bag.format = "ipv6", e._zod.check = (r) => {
1271
+ try {
1272
+ new URL(`http://[${r.value}]`);
1273
+ } catch {
1274
+ r.issues.push({
1275
+ code: "invalid_format",
1276
+ format: "ipv6",
1277
+ input: r.value,
1278
+ inst: e,
1279
+ continue: !t.abort
1280
+ });
1281
+ }
1282
+ };
1283
+ }), Zo = /* @__PURE__ */ l("$ZodCIDRv4", (e, t) => {
1284
+ t.pattern ?? (t.pattern = Mn), y.init(e, t);
1285
+ }), Ro = /* @__PURE__ */ l("$ZodCIDRv6", (e, t) => {
1286
+ t.pattern ?? (t.pattern = Fn), y.init(e, t), e._zod.check = (r) => {
1287
+ const n = r.value.split("/");
1288
+ try {
1289
+ if (n.length !== 2)
1290
+ throw new Error();
1291
+ const [o, i] = n;
1292
+ if (!i)
1293
+ throw new Error();
1294
+ const s = Number(i);
1295
+ if (`${s}` !== i)
1296
+ throw new Error();
1297
+ if (s < 0 || s > 128)
1298
+ throw new Error();
1299
+ new URL(`http://[${o}]`);
1300
+ } catch {
1301
+ r.issues.push({
1302
+ code: "invalid_format",
1303
+ format: "cidrv6",
1304
+ input: r.value,
1305
+ inst: e,
1306
+ continue: !t.abort
1307
+ });
1308
+ }
1309
+ };
1310
+ });
1311
+ function or(e) {
1312
+ if (e === "")
1313
+ return !0;
1314
+ if (e.length % 4 !== 0)
1315
+ return !1;
1316
+ try {
1317
+ return atob(e), !0;
1318
+ } catch {
1319
+ return !1;
1320
+ }
1321
+ }
1322
+ const Io = /* @__PURE__ */ l("$ZodBase64", (e, t) => {
1323
+ t.pattern ?? (t.pattern = xn), y.init(e, t), e._zod.bag.contentEncoding = "base64", e._zod.check = (r) => {
1324
+ or(r.value) || r.issues.push({
1325
+ code: "invalid_format",
1326
+ format: "base64",
1327
+ input: r.value,
1328
+ inst: e,
1329
+ continue: !t.abort
1330
+ });
1331
+ };
1332
+ });
1333
+ function Ao(e) {
1334
+ if (!qt.test(e))
1335
+ return !1;
1336
+ const t = e.replace(/[-_]/g, (n) => n === "-" ? "+" : "/"), r = t.padEnd(Math.ceil(t.length / 4) * 4, "=");
1337
+ return or(r);
1338
+ }
1339
+ const No = /* @__PURE__ */ l("$ZodBase64URL", (e, t) => {
1340
+ t.pattern ?? (t.pattern = qt), y.init(e, t), e._zod.bag.contentEncoding = "base64url", e._zod.check = (r) => {
1341
+ Ao(r.value) || r.issues.push({
1342
+ code: "invalid_format",
1343
+ format: "base64url",
1344
+ input: r.value,
1345
+ inst: e,
1346
+ continue: !t.abort
1347
+ });
1348
+ };
1349
+ }), Do = /* @__PURE__ */ l("$ZodE164", (e, t) => {
1350
+ t.pattern ?? (t.pattern = Bn), y.init(e, t);
1351
+ });
1352
+ function Co(e, t = null) {
1353
+ try {
1354
+ const r = e.split(".");
1355
+ if (r.length !== 3)
1356
+ return !1;
1357
+ const [n] = r;
1358
+ if (!n)
1359
+ return !1;
1360
+ const o = JSON.parse(atob(n));
1361
+ return !("typ" in o && o?.typ !== "JWT" || !o.alg || t && (!("alg" in o) || o.alg !== t));
1362
+ } catch {
1363
+ return !1;
1364
+ }
1365
+ }
1366
+ const Uo = /* @__PURE__ */ l("$ZodJWT", (e, t) => {
1367
+ y.init(e, t), e._zod.check = (r) => {
1368
+ Co(r.value, t.alg) || r.issues.push({
1369
+ code: "invalid_format",
1370
+ format: "jwt",
1371
+ input: r.value,
1372
+ inst: e,
1373
+ continue: !t.abort
1374
+ });
1375
+ };
1376
+ }), sr = /* @__PURE__ */ l("$ZodNumber", (e, t) => {
1377
+ g.init(e, t), e._zod.pattern = e._zod.bag.pattern ?? er, e._zod.parse = (r, n) => {
1378
+ if (t.coerce)
1379
+ try {
1380
+ r.value = Number(r.value);
1381
+ } catch {
1382
+ }
1383
+ const o = r.value;
1384
+ if (typeof o == "number" && !Number.isNaN(o) && Number.isFinite(o))
1385
+ return r;
1386
+ const i = typeof o == "number" ? Number.isNaN(o) ? "NaN" : Number.isFinite(o) ? void 0 : "Infinity" : void 0;
1387
+ return r.issues.push({
1388
+ expected: "number",
1389
+ code: "invalid_type",
1390
+ input: o,
1391
+ inst: e,
1392
+ ...i ? { received: i } : {}
1393
+ }), r;
1394
+ };
1395
+ }), jo = /* @__PURE__ */ l("$ZodNumberFormat", (e, t) => {
1396
+ eo.init(e, t), sr.init(e, t);
1397
+ }), Lo = /* @__PURE__ */ l("$ZodBoolean", (e, t) => {
1398
+ g.init(e, t), e._zod.pattern = Xn, e._zod.parse = (r, n) => {
1399
+ if (t.coerce)
1400
+ try {
1401
+ r.value = !!r.value;
1402
+ } catch {
1403
+ }
1404
+ const o = r.value;
1405
+ return typeof o == "boolean" || r.issues.push({
1406
+ expected: "boolean",
1407
+ code: "invalid_type",
1408
+ input: o,
1409
+ inst: e
1410
+ }), r;
1411
+ };
1412
+ }), Mo = /* @__PURE__ */ l("$ZodAny", (e, t) => {
1413
+ g.init(e, t), e._zod.parse = (r) => r;
1414
+ }), Fo = /* @__PURE__ */ l("$ZodUnknown", (e, t) => {
1415
+ g.init(e, t), e._zod.parse = (r) => r;
1416
+ }), xo = /* @__PURE__ */ l("$ZodNever", (e, t) => {
1417
+ g.init(e, t), e._zod.parse = (r, n) => (r.issues.push({
1418
+ expected: "never",
1419
+ code: "invalid_type",
1420
+ input: r.value,
1421
+ inst: e
1422
+ }), r);
1423
+ });
1424
+ function it(e, t, r) {
1425
+ e.issues.length && t.issues.push(...X(r, e.issues)), t.value[r] = e.value;
1426
+ }
1427
+ const Bo = /* @__PURE__ */ l("$ZodArray", (e, t) => {
1428
+ g.init(e, t), e._zod.parse = (r, n) => {
1429
+ const o = r.value;
1430
+ if (!Array.isArray(o))
1431
+ return r.issues.push({
1432
+ expected: "array",
1433
+ code: "invalid_type",
1434
+ input: o,
1435
+ inst: e
1436
+ }), r;
1437
+ r.value = Array(o.length);
1438
+ const i = [];
1439
+ for (let s = 0; s < o.length; s++) {
1440
+ const a = o[s], c = t.element._zod.run({
1441
+ value: a,
1442
+ issues: []
1443
+ }, n);
1444
+ c instanceof Promise ? i.push(c.then((u) => it(u, r, s))) : it(c, r, s);
1445
+ }
1446
+ return i.length ? Promise.all(i).then(() => r) : r;
1447
+ };
1448
+ });
1449
+ function be(e, t, r, n, o) {
1450
+ if (e.issues.length) {
1451
+ if (o && !(r in n))
1452
+ return;
1453
+ t.issues.push(...X(r, e.issues));
1454
+ }
1455
+ e.value === void 0 ? r in n && (t.value[r] = void 0) : t.value[r] = e.value;
1456
+ }
1457
+ function ir(e) {
1458
+ const t = Object.keys(e.shape);
1459
+ for (const n of t)
1460
+ if (!e.shape?.[n]?._zod?.traits?.has("$ZodType"))
1461
+ throw new Error(`Invalid element at key "${n}": expected a Zod schema`);
1462
+ const r = an(e.shape);
1463
+ return {
1464
+ ...e,
1465
+ keys: t,
1466
+ keySet: new Set(t),
1467
+ numKeys: t.length,
1468
+ optionalKeys: new Set(r)
1469
+ };
1470
+ }
1471
+ function ar(e, t, r, n, o, i) {
1472
+ const s = [], a = o.keySet, c = o.catchall._zod, u = c.def.type, f = c.optout === "optional";
1473
+ for (const d in t) {
1474
+ if (a.has(d))
1475
+ continue;
1476
+ if (u === "never") {
1477
+ s.push(d);
1478
+ continue;
1479
+ }
1480
+ const h = c.run({ value: t[d], issues: [] }, n);
1481
+ h instanceof Promise ? e.push(h.then((m) => be(m, r, d, t, f))) : be(h, r, d, t, f);
1482
+ }
1483
+ return s.length && r.issues.push({
1484
+ code: "unrecognized_keys",
1485
+ keys: s,
1486
+ input: t,
1487
+ inst: i
1488
+ }), e.length ? Promise.all(e).then(() => r) : r;
1489
+ }
1490
+ const Jo = /* @__PURE__ */ l("$ZodObject", (e, t) => {
1491
+ if (g.init(e, t), !Object.getOwnPropertyDescriptor(t, "shape")?.get) {
1492
+ const a = t.shape;
1493
+ Object.defineProperty(t, "shape", {
1494
+ get: () => {
1495
+ const c = { ...a };
1496
+ return Object.defineProperty(t, "shape", {
1497
+ value: c
1498
+ }), c;
1499
+ }
1500
+ });
1501
+ }
1502
+ const n = Ve(() => ir(t));
1503
+ w(e._zod, "propValues", () => {
1504
+ const a = t.shape, c = {};
1505
+ for (const u in a) {
1506
+ const f = a[u]._zod;
1507
+ if (f.values) {
1508
+ c[u] ?? (c[u] = /* @__PURE__ */ new Set());
1509
+ for (const d of f.values)
1510
+ c[u].add(d);
1511
+ }
1512
+ }
1513
+ return c;
1514
+ });
1515
+ const o = _e, i = t.catchall;
1516
+ let s;
1517
+ e._zod.parse = (a, c) => {
1518
+ s ?? (s = n.value);
1519
+ const u = a.value;
1520
+ if (!o(u))
1521
+ return a.issues.push({
1522
+ expected: "object",
1523
+ code: "invalid_type",
1524
+ input: u,
1525
+ inst: e
1526
+ }), a;
1527
+ a.value = {};
1528
+ const f = [], d = s.shape;
1529
+ for (const h of s.keys) {
1530
+ const m = d[h], S = m._zod.optout === "optional", z = m._zod.run({ value: u[h], issues: [] }, c);
1531
+ z instanceof Promise ? f.push(z.then((I) => be(I, a, h, u, S))) : be(z, a, h, u, S);
1532
+ }
1533
+ return i ? ar(f, u, a, c, n.value, e) : f.length ? Promise.all(f).then(() => a) : a;
1534
+ };
1535
+ }), Vo = /* @__PURE__ */ l("$ZodObjectJIT", (e, t) => {
1536
+ Jo.init(e, t);
1537
+ const r = e._zod.parse, n = Ve(() => ir(t)), o = (h) => {
1538
+ const m = new fo(["shape", "payload", "ctx"]), S = n.value, z = (U) => {
1539
+ const O = ot(U);
1540
+ return `shape[${O}]._zod.run({ value: input[${O}], issues: [] }, ctx)`;
1541
+ };
1542
+ m.write("const input = payload.value;");
1543
+ const I = /* @__PURE__ */ Object.create(null);
1544
+ let Re = 0;
1545
+ for (const U of S.keys)
1546
+ I[U] = `key_${Re++}`;
1547
+ m.write("const newResult = {};");
1548
+ for (const U of S.keys) {
1549
+ const O = I[U], A = ot(U), Cr = h[U]?._zod?.optout === "optional";
1550
+ m.write(`const ${O} = ${z(U)};`), Cr ? m.write(`
1551
+ if (${O}.issues.length) {
1552
+ if (${A} in input) {
1553
+ payload.issues = payload.issues.concat(${O}.issues.map(iss => ({
1554
+ ...iss,
1555
+ path: iss.path ? [${A}, ...iss.path] : [${A}]
1556
+ })));
1557
+ }
1558
+ }
1559
+
1560
+ if (${O}.value === undefined) {
1561
+ if (${A} in input) {
1562
+ newResult[${A}] = undefined;
1563
+ }
1564
+ } else {
1565
+ newResult[${A}] = ${O}.value;
1566
+ }
1567
+
1568
+ `) : m.write(`
1569
+ if (${O}.issues.length) {
1570
+ payload.issues = payload.issues.concat(${O}.issues.map(iss => ({
1571
+ ...iss,
1572
+ path: iss.path ? [${A}, ...iss.path] : [${A}]
1573
+ })));
1574
+ }
1575
+
1576
+ if (${O}.value === undefined) {
1577
+ if (${A} in input) {
1578
+ newResult[${A}] = undefined;
1579
+ }
1580
+ } else {
1581
+ newResult[${A}] = ${O}.value;
1582
+ }
1583
+
1584
+ `);
1585
+ }
1586
+ m.write("payload.value = newResult;"), m.write("return payload;");
1587
+ const Dr = m.compile();
1588
+ return (U, O) => Dr(h, U, O);
1589
+ };
1590
+ let i;
1591
+ const s = _e, a = !Bt.jitless, u = a && on.value, f = t.catchall;
1592
+ let d;
1593
+ e._zod.parse = (h, m) => {
1594
+ d ?? (d = n.value);
1595
+ const S = h.value;
1596
+ return s(S) ? a && u && m?.async === !1 && m.jitless !== !0 ? (i || (i = o(t.shape)), h = i(h, m), f ? ar([], S, h, m, d, e) : h) : r(h, m) : (h.issues.push({
1597
+ expected: "object",
1598
+ code: "invalid_type",
1599
+ input: S,
1600
+ inst: e
1601
+ }), h);
1602
+ };
1603
+ });
1604
+ function at(e, t, r, n) {
1605
+ for (const i of e)
1606
+ if (i.issues.length === 0)
1607
+ return t.value = i.value, t;
1608
+ const o = e.filter((i) => !Y(i));
1609
+ return o.length === 1 ? (t.value = o[0].value, o[0]) : (t.issues.push({
1610
+ code: "invalid_union",
1611
+ input: t.value,
1612
+ inst: r,
1613
+ errors: e.map((i) => i.issues.map((s) => F(s, n, M())))
1614
+ }), t);
1615
+ }
1616
+ const Go = /* @__PURE__ */ l("$ZodUnion", (e, t) => {
1617
+ g.init(e, t), w(e._zod, "optin", () => t.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0), w(e._zod, "optout", () => t.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0), w(e._zod, "values", () => {
1618
+ if (t.options.every((o) => o._zod.values))
1619
+ return new Set(t.options.flatMap((o) => Array.from(o._zod.values)));
1620
+ }), w(e._zod, "pattern", () => {
1621
+ if (t.options.every((o) => o._zod.pattern)) {
1622
+ const o = t.options.map((i) => i._zod.pattern);
1623
+ return new RegExp(`^(${o.map((i) => He(i.source)).join("|")})$`);
1624
+ }
1625
+ });
1626
+ const r = t.options.length === 1, n = t.options[0]._zod.run;
1627
+ e._zod.parse = (o, i) => {
1628
+ if (r)
1629
+ return n(o, i);
1630
+ let s = !1;
1631
+ const a = [];
1632
+ for (const c of t.options) {
1633
+ const u = c._zod.run({
1634
+ value: o.value,
1635
+ issues: []
1636
+ }, i);
1637
+ if (u instanceof Promise)
1638
+ a.push(u), s = !0;
1639
+ else {
1640
+ if (u.issues.length === 0)
1641
+ return u;
1642
+ a.push(u);
1643
+ }
1644
+ }
1645
+ return s ? Promise.all(a).then((c) => at(c, o, e, i)) : at(a, o, e, i);
1646
+ };
1647
+ }), Ho = /* @__PURE__ */ l("$ZodIntersection", (e, t) => {
1648
+ g.init(e, t), e._zod.parse = (r, n) => {
1649
+ const o = r.value, i = t.left._zod.run({ value: o, issues: [] }, n), s = t.right._zod.run({ value: o, issues: [] }, n);
1650
+ return i instanceof Promise || s instanceof Promise ? Promise.all([i, s]).then(([c, u]) => ct(r, c, u)) : ct(r, i, s);
1651
+ };
1652
+ });
1653
+ function Ue(e, t) {
1654
+ if (e === t)
1655
+ return { valid: !0, data: e };
1656
+ if (e instanceof Date && t instanceof Date && +e == +t)
1657
+ return { valid: !0, data: e };
1658
+ if (ee(e) && ee(t)) {
1659
+ const r = Object.keys(t), n = Object.keys(e).filter((i) => r.indexOf(i) !== -1), o = { ...e, ...t };
1660
+ for (const i of n) {
1661
+ const s = Ue(e[i], t[i]);
1662
+ if (!s.valid)
1663
+ return {
1664
+ valid: !1,
1665
+ mergeErrorPath: [i, ...s.mergeErrorPath]
1666
+ };
1667
+ o[i] = s.data;
1668
+ }
1669
+ return { valid: !0, data: o };
1670
+ }
1671
+ if (Array.isArray(e) && Array.isArray(t)) {
1672
+ if (e.length !== t.length)
1673
+ return { valid: !1, mergeErrorPath: [] };
1674
+ const r = [];
1675
+ for (let n = 0; n < e.length; n++) {
1676
+ const o = e[n], i = t[n], s = Ue(o, i);
1677
+ if (!s.valid)
1678
+ return {
1679
+ valid: !1,
1680
+ mergeErrorPath: [n, ...s.mergeErrorPath]
1681
+ };
1682
+ r.push(s.data);
1683
+ }
1684
+ return { valid: !0, data: r };
1685
+ }
1686
+ return { valid: !1, mergeErrorPath: [] };
1687
+ }
1688
+ function ct(e, t, r) {
1689
+ const n = /* @__PURE__ */ new Map();
1690
+ let o;
1691
+ for (const a of t.issues)
1692
+ if (a.code === "unrecognized_keys") {
1693
+ o ?? (o = a);
1694
+ for (const c of a.keys)
1695
+ n.has(c) || n.set(c, {}), n.get(c).l = !0;
1696
+ } else
1697
+ e.issues.push(a);
1698
+ for (const a of r.issues)
1699
+ if (a.code === "unrecognized_keys")
1700
+ for (const c of a.keys)
1701
+ n.has(c) || n.set(c, {}), n.get(c).r = !0;
1702
+ else
1703
+ e.issues.push(a);
1704
+ const i = [...n].filter(([, a]) => a.l && a.r).map(([a]) => a);
1705
+ if (i.length && o && e.issues.push({ ...o, keys: i }), Y(e))
1706
+ return e;
1707
+ const s = Ue(t.value, r.value);
1708
+ if (!s.valid)
1709
+ throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);
1710
+ return e.value = s.data, e;
1711
+ }
1712
+ const Yo = /* @__PURE__ */ l("$ZodRecord", (e, t) => {
1713
+ g.init(e, t), e._zod.parse = (r, n) => {
1714
+ const o = r.value;
1715
+ if (!ee(o))
1716
+ return r.issues.push({
1717
+ expected: "record",
1718
+ code: "invalid_type",
1719
+ input: o,
1720
+ inst: e
1721
+ }), r;
1722
+ const i = [], s = t.keyType._zod.values;
1723
+ if (s) {
1724
+ r.value = {};
1725
+ const a = /* @__PURE__ */ new Set();
1726
+ for (const u of s)
1727
+ if (typeof u == "string" || typeof u == "number" || typeof u == "symbol") {
1728
+ a.add(typeof u == "number" ? u.toString() : u);
1729
+ const f = t.valueType._zod.run({ value: o[u], issues: [] }, n);
1730
+ f instanceof Promise ? i.push(f.then((d) => {
1731
+ d.issues.length && r.issues.push(...X(u, d.issues)), r.value[u] = d.value;
1732
+ })) : (f.issues.length && r.issues.push(...X(u, f.issues)), r.value[u] = f.value);
1733
+ }
1734
+ let c;
1735
+ for (const u in o)
1736
+ a.has(u) || (c = c ?? [], c.push(u));
1737
+ c && c.length > 0 && r.issues.push({
1738
+ code: "unrecognized_keys",
1739
+ input: o,
1740
+ inst: e,
1741
+ keys: c
1742
+ });
1743
+ } else {
1744
+ r.value = {};
1745
+ for (const a of Reflect.ownKeys(o)) {
1746
+ if (a === "__proto__")
1747
+ continue;
1748
+ let c = t.keyType._zod.run({ value: a, issues: [] }, n);
1749
+ if (c instanceof Promise)
1750
+ throw new Error("Async schemas not supported in object keys currently");
1751
+ if (typeof a == "string" && er.test(a) && c.issues.length) {
1752
+ const d = t.keyType._zod.run({ value: Number(a), issues: [] }, n);
1753
+ if (d instanceof Promise)
1754
+ throw new Error("Async schemas not supported in object keys currently");
1755
+ d.issues.length === 0 && (c = d);
1756
+ }
1757
+ if (c.issues.length) {
1758
+ t.mode === "loose" ? r.value[a] = o[a] : r.issues.push({
1759
+ code: "invalid_key",
1760
+ origin: "record",
1761
+ issues: c.issues.map((d) => F(d, n, M())),
1762
+ input: a,
1763
+ path: [a],
1764
+ inst: e
1765
+ });
1766
+ continue;
1767
+ }
1768
+ const f = t.valueType._zod.run({ value: o[a], issues: [] }, n);
1769
+ f instanceof Promise ? i.push(f.then((d) => {
1770
+ d.issues.length && r.issues.push(...X(a, d.issues)), r.value[c.value] = d.value;
1771
+ })) : (f.issues.length && r.issues.push(...X(a, f.issues)), r.value[c.value] = f.value);
1772
+ }
1773
+ }
1774
+ return i.length ? Promise.all(i).then(() => r) : r;
1775
+ };
1776
+ }), Xo = /* @__PURE__ */ l("$ZodEnum", (e, t) => {
1777
+ g.init(e, t);
1778
+ const r = Jt(t.entries), n = new Set(r);
1779
+ e._zod.values = n, e._zod.pattern = new RegExp(`^(${r.filter((o) => sn.has(typeof o)).map((o) => typeof o == "string" ? $e(o) : o.toString()).join("|")})$`), e._zod.parse = (o, i) => {
1780
+ const s = o.value;
1781
+ return n.has(s) || o.issues.push({
1782
+ code: "invalid_value",
1783
+ values: r,
1784
+ input: s,
1785
+ inst: e
1786
+ }), o;
1787
+ };
1788
+ }), qo = /* @__PURE__ */ l("$ZodTransform", (e, t) => {
1789
+ g.init(e, t), e._zod.parse = (r, n) => {
1790
+ if (n.direction === "backward")
1791
+ throw new xt(e.constructor.name);
1792
+ const o = t.transform(r.value, r);
1793
+ if (n.async)
1794
+ return (o instanceof Promise ? o : Promise.resolve(o)).then((s) => (r.value = s, r));
1795
+ if (o instanceof Promise)
1796
+ throw new q();
1797
+ return r.value = o, r;
1798
+ };
1799
+ });
1800
+ function ut(e, t) {
1801
+ return e.issues.length && t === void 0 ? { issues: [], value: void 0 } : e;
1802
+ }
1803
+ const cr = /* @__PURE__ */ l("$ZodOptional", (e, t) => {
1804
+ g.init(e, t), e._zod.optin = "optional", e._zod.optout = "optional", w(e._zod, "values", () => t.innerType._zod.values ? /* @__PURE__ */ new Set([...t.innerType._zod.values, void 0]) : void 0), w(e._zod, "pattern", () => {
1805
+ const r = t.innerType._zod.pattern;
1806
+ return r ? new RegExp(`^(${He(r.source)})?$`) : void 0;
1807
+ }), e._zod.parse = (r, n) => {
1808
+ if (t.innerType._zod.optin === "optional") {
1809
+ const o = t.innerType._zod.run(r, n);
1810
+ return o instanceof Promise ? o.then((i) => ut(i, r.value)) : ut(o, r.value);
1811
+ }
1812
+ return r.value === void 0 ? r : t.innerType._zod.run(r, n);
1813
+ };
1814
+ }), Ko = /* @__PURE__ */ l("$ZodExactOptional", (e, t) => {
1815
+ cr.init(e, t), w(e._zod, "values", () => t.innerType._zod.values), w(e._zod, "pattern", () => t.innerType._zod.pattern), e._zod.parse = (r, n) => t.innerType._zod.run(r, n);
1816
+ }), Qo = /* @__PURE__ */ l("$ZodNullable", (e, t) => {
1817
+ g.init(e, t), w(e._zod, "optin", () => t.innerType._zod.optin), w(e._zod, "optout", () => t.innerType._zod.optout), w(e._zod, "pattern", () => {
1818
+ const r = t.innerType._zod.pattern;
1819
+ return r ? new RegExp(`^(${He(r.source)}|null)$`) : void 0;
1820
+ }), w(e._zod, "values", () => t.innerType._zod.values ? /* @__PURE__ */ new Set([...t.innerType._zod.values, null]) : void 0), e._zod.parse = (r, n) => r.value === null ? r : t.innerType._zod.run(r, n);
1821
+ }), es = /* @__PURE__ */ l("$ZodDefault", (e, t) => {
1822
+ g.init(e, t), e._zod.optin = "optional", w(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (r, n) => {
1823
+ if (n.direction === "backward")
1824
+ return t.innerType._zod.run(r, n);
1825
+ if (r.value === void 0)
1826
+ return r.value = t.defaultValue, r;
1827
+ const o = t.innerType._zod.run(r, n);
1828
+ return o instanceof Promise ? o.then((i) => lt(i, t)) : lt(o, t);
1829
+ };
1830
+ });
1831
+ function lt(e, t) {
1832
+ return e.value === void 0 && (e.value = t.defaultValue), e;
1833
+ }
1834
+ const ts = /* @__PURE__ */ l("$ZodPrefault", (e, t) => {
1835
+ g.init(e, t), e._zod.optin = "optional", w(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (r, n) => (n.direction === "backward" || r.value === void 0 && (r.value = t.defaultValue), t.innerType._zod.run(r, n));
1836
+ }), rs = /* @__PURE__ */ l("$ZodNonOptional", (e, t) => {
1837
+ g.init(e, t), w(e._zod, "values", () => {
1838
+ const r = t.innerType._zod.values;
1839
+ return r ? new Set([...r].filter((n) => n !== void 0)) : void 0;
1840
+ }), e._zod.parse = (r, n) => {
1841
+ const o = t.innerType._zod.run(r, n);
1842
+ return o instanceof Promise ? o.then((i) => dt(i, e)) : dt(o, e);
1843
+ };
1844
+ });
1845
+ function dt(e, t) {
1846
+ return !e.issues.length && e.value === void 0 && e.issues.push({
1847
+ code: "invalid_type",
1848
+ expected: "nonoptional",
1849
+ input: e.value,
1850
+ inst: t
1851
+ }), e;
1852
+ }
1853
+ const ns = /* @__PURE__ */ l("$ZodCatch", (e, t) => {
1854
+ g.init(e, t), w(e._zod, "optin", () => t.innerType._zod.optin), w(e._zod, "optout", () => t.innerType._zod.optout), w(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (r, n) => {
1855
+ if (n.direction === "backward")
1856
+ return t.innerType._zod.run(r, n);
1857
+ const o = t.innerType._zod.run(r, n);
1858
+ return o instanceof Promise ? o.then((i) => (r.value = i.value, i.issues.length && (r.value = t.catchValue({
1859
+ ...r,
1860
+ error: {
1861
+ issues: i.issues.map((s) => F(s, n, M()))
1862
+ },
1863
+ input: r.value
1864
+ }), r.issues = []), r)) : (r.value = o.value, o.issues.length && (r.value = t.catchValue({
1865
+ ...r,
1866
+ error: {
1867
+ issues: o.issues.map((i) => F(i, n, M()))
1868
+ },
1869
+ input: r.value
1870
+ }), r.issues = []), r);
1871
+ };
1872
+ }), os = /* @__PURE__ */ l("$ZodPipe", (e, t) => {
1873
+ g.init(e, t), w(e._zod, "values", () => t.in._zod.values), w(e._zod, "optin", () => t.in._zod.optin), w(e._zod, "optout", () => t.out._zod.optout), w(e._zod, "propValues", () => t.in._zod.propValues), e._zod.parse = (r, n) => {
1874
+ if (n.direction === "backward") {
1875
+ const i = t.out._zod.run(r, n);
1876
+ return i instanceof Promise ? i.then((s) => we(s, t.in, n)) : we(i, t.in, n);
1877
+ }
1878
+ const o = t.in._zod.run(r, n);
1879
+ return o instanceof Promise ? o.then((i) => we(i, t.out, n)) : we(o, t.out, n);
1880
+ };
1881
+ });
1882
+ function we(e, t, r) {
1883
+ return e.issues.length ? (e.aborted = !0, e) : t._zod.run({ value: e.value, issues: e.issues }, r);
1884
+ }
1885
+ const ss = /* @__PURE__ */ l("$ZodReadonly", (e, t) => {
1886
+ g.init(e, t), w(e._zod, "propValues", () => t.innerType._zod.propValues), w(e._zod, "values", () => t.innerType._zod.values), w(e._zod, "optin", () => t.innerType?._zod?.optin), w(e._zod, "optout", () => t.innerType?._zod?.optout), e._zod.parse = (r, n) => {
1887
+ if (n.direction === "backward")
1888
+ return t.innerType._zod.run(r, n);
1889
+ const o = t.innerType._zod.run(r, n);
1890
+ return o instanceof Promise ? o.then(ft) : ft(o);
1891
+ };
1892
+ });
1893
+ function ft(e) {
1894
+ return e.value = Object.freeze(e.value), e;
1895
+ }
1896
+ const is = /* @__PURE__ */ l("$ZodLazy", (e, t) => {
1897
+ g.init(e, t), w(e._zod, "innerType", () => t.getter()), w(e._zod, "pattern", () => e._zod.innerType?._zod?.pattern), w(e._zod, "propValues", () => e._zod.innerType?._zod?.propValues), w(e._zod, "optin", () => e._zod.innerType?._zod?.optin ?? void 0), w(e._zod, "optout", () => e._zod.innerType?._zod?.optout ?? void 0), e._zod.parse = (r, n) => e._zod.innerType._zod.run(r, n);
1898
+ }), as = /* @__PURE__ */ l("$ZodCustom", (e, t) => {
1899
+ Z.init(e, t), g.init(e, t), e._zod.parse = (r, n) => r, e._zod.check = (r) => {
1900
+ const n = r.value, o = t.fn(n);
1901
+ if (o instanceof Promise)
1902
+ return o.then((i) => ht(i, r, n, e));
1903
+ ht(o, r, n, e);
1904
+ };
1905
+ });
1906
+ function ht(e, t, r, n) {
1907
+ if (!e) {
1908
+ const o = {
1909
+ code: "custom",
1910
+ input: r,
1911
+ inst: n,
1912
+ // incorporates params.error into issue reporting
1913
+ path: [...n._zod.def.path ?? []],
1914
+ // incorporates params.error into issue reporting
1915
+ continue: !n._zod.def.abort
1916
+ // params: inst._zod.def.params,
1917
+ };
1918
+ n._zod.def.params && (o.params = n._zod.def.params), t.issues.push(ae(o));
1919
+ }
1920
+ }
1921
+ var pt;
1922
+ class cs {
1923
+ constructor() {
1924
+ this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map();
1925
+ }
1926
+ add(t, ...r) {
1927
+ const n = r[0];
1928
+ return this._map.set(t, n), n && typeof n == "object" && "id" in n && this._idmap.set(n.id, t), this;
1929
+ }
1930
+ clear() {
1931
+ return this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map(), this;
1932
+ }
1933
+ remove(t) {
1934
+ const r = this._map.get(t);
1935
+ return r && typeof r == "object" && "id" in r && this._idmap.delete(r.id), this._map.delete(t), this;
1936
+ }
1937
+ get(t) {
1938
+ const r = t._zod.parent;
1939
+ if (r) {
1940
+ const n = { ...this.get(r) ?? {} };
1941
+ delete n.id;
1942
+ const o = { ...n, ...this._map.get(t) };
1943
+ return Object.keys(o).length ? o : void 0;
1944
+ }
1945
+ return this._map.get(t);
1946
+ }
1947
+ has(t) {
1948
+ return this._map.has(t);
1949
+ }
1950
+ }
1951
+ function us() {
1952
+ return new cs();
1953
+ }
1954
+ (pt = globalThis).__zod_globalRegistry ?? (pt.__zod_globalRegistry = us());
1955
+ const se = globalThis.__zod_globalRegistry;
1956
+ // @__NO_SIDE_EFFECTS__
1957
+ function ls(e, t) {
1958
+ return new e({
1959
+ type: "string",
1960
+ ...p(t)
1961
+ });
1962
+ }
1963
+ // @__NO_SIDE_EFFECTS__
1964
+ function ds(e, t) {
1965
+ return new e({
1966
+ type: "string",
1967
+ format: "email",
1968
+ check: "string_format",
1969
+ abort: !1,
1970
+ ...p(t)
1971
+ });
1972
+ }
1973
+ // @__NO_SIDE_EFFECTS__
1974
+ function mt(e, t) {
1975
+ return new e({
1976
+ type: "string",
1977
+ format: "guid",
1978
+ check: "string_format",
1979
+ abort: !1,
1980
+ ...p(t)
1981
+ });
1982
+ }
1983
+ // @__NO_SIDE_EFFECTS__
1984
+ function fs(e, t) {
1985
+ return new e({
1986
+ type: "string",
1987
+ format: "uuid",
1988
+ check: "string_format",
1989
+ abort: !1,
1990
+ ...p(t)
1991
+ });
1992
+ }
1993
+ // @__NO_SIDE_EFFECTS__
1994
+ function hs(e, t) {
1995
+ return new e({
1996
+ type: "string",
1997
+ format: "uuid",
1998
+ check: "string_format",
1999
+ abort: !1,
2000
+ version: "v4",
2001
+ ...p(t)
2002
+ });
2003
+ }
2004
+ // @__NO_SIDE_EFFECTS__
2005
+ function ps(e, t) {
2006
+ return new e({
2007
+ type: "string",
2008
+ format: "uuid",
2009
+ check: "string_format",
2010
+ abort: !1,
2011
+ version: "v6",
2012
+ ...p(t)
2013
+ });
2014
+ }
2015
+ // @__NO_SIDE_EFFECTS__
2016
+ function ms(e, t) {
2017
+ return new e({
2018
+ type: "string",
2019
+ format: "uuid",
2020
+ check: "string_format",
2021
+ abort: !1,
2022
+ version: "v7",
2023
+ ...p(t)
2024
+ });
2025
+ }
2026
+ // @__NO_SIDE_EFFECTS__
2027
+ function ws(e, t) {
2028
+ return new e({
2029
+ type: "string",
2030
+ format: "url",
2031
+ check: "string_format",
2032
+ abort: !1,
2033
+ ...p(t)
2034
+ });
2035
+ }
2036
+ // @__NO_SIDE_EFFECTS__
2037
+ function gs(e, t) {
2038
+ return new e({
2039
+ type: "string",
2040
+ format: "emoji",
2041
+ check: "string_format",
2042
+ abort: !1,
2043
+ ...p(t)
2044
+ });
2045
+ }
2046
+ // @__NO_SIDE_EFFECTS__
2047
+ function ys(e, t) {
2048
+ return new e({
2049
+ type: "string",
2050
+ format: "nanoid",
2051
+ check: "string_format",
2052
+ abort: !1,
2053
+ ...p(t)
2054
+ });
2055
+ }
2056
+ // @__NO_SIDE_EFFECTS__
2057
+ function vs(e, t) {
2058
+ return new e({
2059
+ type: "string",
2060
+ format: "cuid",
2061
+ check: "string_format",
2062
+ abort: !1,
2063
+ ...p(t)
2064
+ });
2065
+ }
2066
+ // @__NO_SIDE_EFFECTS__
2067
+ function ks(e, t) {
2068
+ return new e({
2069
+ type: "string",
2070
+ format: "cuid2",
2071
+ check: "string_format",
2072
+ abort: !1,
2073
+ ...p(t)
2074
+ });
2075
+ }
2076
+ // @__NO_SIDE_EFFECTS__
2077
+ function _s(e, t) {
2078
+ return new e({
2079
+ type: "string",
2080
+ format: "ulid",
2081
+ check: "string_format",
2082
+ abort: !1,
2083
+ ...p(t)
2084
+ });
2085
+ }
2086
+ // @__NO_SIDE_EFFECTS__
2087
+ function bs(e, t) {
2088
+ return new e({
2089
+ type: "string",
2090
+ format: "xid",
2091
+ check: "string_format",
2092
+ abort: !1,
2093
+ ...p(t)
2094
+ });
2095
+ }
2096
+ // @__NO_SIDE_EFFECTS__
2097
+ function Ss(e, t) {
2098
+ return new e({
2099
+ type: "string",
2100
+ format: "ksuid",
2101
+ check: "string_format",
2102
+ abort: !1,
2103
+ ...p(t)
2104
+ });
2105
+ }
2106
+ // @__NO_SIDE_EFFECTS__
2107
+ function zs(e, t) {
2108
+ return new e({
2109
+ type: "string",
2110
+ format: "ipv4",
2111
+ check: "string_format",
2112
+ abort: !1,
2113
+ ...p(t)
2114
+ });
2115
+ }
2116
+ // @__NO_SIDE_EFFECTS__
2117
+ function Es(e, t) {
2118
+ return new e({
2119
+ type: "string",
2120
+ format: "ipv6",
2121
+ check: "string_format",
2122
+ abort: !1,
2123
+ ...p(t)
2124
+ });
2125
+ }
2126
+ // @__NO_SIDE_EFFECTS__
2127
+ function Ts(e, t) {
2128
+ return new e({
2129
+ type: "string",
2130
+ format: "cidrv4",
2131
+ check: "string_format",
2132
+ abort: !1,
2133
+ ...p(t)
2134
+ });
2135
+ }
2136
+ // @__NO_SIDE_EFFECTS__
2137
+ function $s(e, t) {
2138
+ return new e({
2139
+ type: "string",
2140
+ format: "cidrv6",
2141
+ check: "string_format",
2142
+ abort: !1,
2143
+ ...p(t)
2144
+ });
2145
+ }
2146
+ // @__NO_SIDE_EFFECTS__
2147
+ function Os(e, t) {
2148
+ return new e({
2149
+ type: "string",
2150
+ format: "base64",
2151
+ check: "string_format",
2152
+ abort: !1,
2153
+ ...p(t)
2154
+ });
2155
+ }
2156
+ // @__NO_SIDE_EFFECTS__
2157
+ function Ps(e, t) {
2158
+ return new e({
2159
+ type: "string",
2160
+ format: "base64url",
2161
+ check: "string_format",
2162
+ abort: !1,
2163
+ ...p(t)
2164
+ });
2165
+ }
2166
+ // @__NO_SIDE_EFFECTS__
2167
+ function Ws(e, t) {
2168
+ return new e({
2169
+ type: "string",
2170
+ format: "e164",
2171
+ check: "string_format",
2172
+ abort: !1,
2173
+ ...p(t)
2174
+ });
2175
+ }
2176
+ // @__NO_SIDE_EFFECTS__
2177
+ function Zs(e, t) {
2178
+ return new e({
2179
+ type: "string",
2180
+ format: "jwt",
2181
+ check: "string_format",
2182
+ abort: !1,
2183
+ ...p(t)
2184
+ });
2185
+ }
2186
+ // @__NO_SIDE_EFFECTS__
2187
+ function Rs(e, t) {
2188
+ return new e({
2189
+ type: "string",
2190
+ format: "datetime",
2191
+ check: "string_format",
2192
+ offset: !1,
2193
+ local: !1,
2194
+ precision: null,
2195
+ ...p(t)
2196
+ });
2197
+ }
2198
+ // @__NO_SIDE_EFFECTS__
2199
+ function Is(e, t) {
2200
+ return new e({
2201
+ type: "string",
2202
+ format: "date",
2203
+ check: "string_format",
2204
+ ...p(t)
2205
+ });
2206
+ }
2207
+ // @__NO_SIDE_EFFECTS__
2208
+ function As(e, t) {
2209
+ return new e({
2210
+ type: "string",
2211
+ format: "time",
2212
+ check: "string_format",
2213
+ precision: null,
2214
+ ...p(t)
2215
+ });
2216
+ }
2217
+ // @__NO_SIDE_EFFECTS__
2218
+ function Ns(e, t) {
2219
+ return new e({
2220
+ type: "string",
2221
+ format: "duration",
2222
+ check: "string_format",
2223
+ ...p(t)
2224
+ });
2225
+ }
2226
+ // @__NO_SIDE_EFFECTS__
2227
+ function Ds(e, t) {
2228
+ return new e({
2229
+ type: "number",
2230
+ checks: [],
2231
+ ...p(t)
2232
+ });
2233
+ }
2234
+ // @__NO_SIDE_EFFECTS__
2235
+ function Cs(e, t) {
2236
+ return new e({
2237
+ type: "number",
2238
+ check: "number_format",
2239
+ abort: !1,
2240
+ format: "safeint",
2241
+ ...p(t)
2242
+ });
2243
+ }
2244
+ // @__NO_SIDE_EFFECTS__
2245
+ function Us(e, t) {
2246
+ return new e({
2247
+ type: "boolean",
2248
+ ...p(t)
2249
+ });
2250
+ }
2251
+ // @__NO_SIDE_EFFECTS__
2252
+ function js(e) {
2253
+ return new e({
2254
+ type: "any"
2255
+ });
2256
+ }
2257
+ // @__NO_SIDE_EFFECTS__
2258
+ function Ls(e) {
2259
+ return new e({
2260
+ type: "unknown"
2261
+ });
2262
+ }
2263
+ // @__NO_SIDE_EFFECTS__
2264
+ function Ms(e, t) {
2265
+ return new e({
2266
+ type: "never",
2267
+ ...p(t)
2268
+ });
2269
+ }
2270
+ // @__NO_SIDE_EFFECTS__
2271
+ function wt(e, t) {
2272
+ return new rr({
2273
+ check: "less_than",
2274
+ ...p(t),
2275
+ value: e,
2276
+ inclusive: !1
2277
+ });
2278
+ }
2279
+ // @__NO_SIDE_EFFECTS__
2280
+ function Ie(e, t) {
2281
+ return new rr({
2282
+ check: "less_than",
2283
+ ...p(t),
2284
+ value: e,
2285
+ inclusive: !0
2286
+ });
2287
+ }
2288
+ // @__NO_SIDE_EFFECTS__
2289
+ function gt(e, t) {
2290
+ return new nr({
2291
+ check: "greater_than",
2292
+ ...p(t),
2293
+ value: e,
2294
+ inclusive: !1
2295
+ });
2296
+ }
2297
+ // @__NO_SIDE_EFFECTS__
2298
+ function Ae(e, t) {
2299
+ return new nr({
2300
+ check: "greater_than",
2301
+ ...p(t),
2302
+ value: e,
2303
+ inclusive: !0
2304
+ });
2305
+ }
2306
+ // @__NO_SIDE_EFFECTS__
2307
+ function yt(e, t) {
2308
+ return new Qn({
2309
+ check: "multiple_of",
2310
+ ...p(t),
2311
+ value: e
2312
+ });
2313
+ }
2314
+ // @__NO_SIDE_EFFECTS__
2315
+ function ur(e, t) {
2316
+ return new to({
2317
+ check: "max_length",
2318
+ ...p(t),
2319
+ maximum: e
2320
+ });
2321
+ }
2322
+ // @__NO_SIDE_EFFECTS__
2323
+ function Se(e, t) {
2324
+ return new ro({
2325
+ check: "min_length",
2326
+ ...p(t),
2327
+ minimum: e
2328
+ });
2329
+ }
2330
+ // @__NO_SIDE_EFFECTS__
2331
+ function lr(e, t) {
2332
+ return new no({
2333
+ check: "length_equals",
2334
+ ...p(t),
2335
+ length: e
2336
+ });
2337
+ }
2338
+ // @__NO_SIDE_EFFECTS__
2339
+ function Fs(e, t) {
2340
+ return new oo({
2341
+ check: "string_format",
2342
+ format: "regex",
2343
+ ...p(t),
2344
+ pattern: e
2345
+ });
2346
+ }
2347
+ // @__NO_SIDE_EFFECTS__
2348
+ function xs(e) {
2349
+ return new so({
2350
+ check: "string_format",
2351
+ format: "lowercase",
2352
+ ...p(e)
2353
+ });
2354
+ }
2355
+ // @__NO_SIDE_EFFECTS__
2356
+ function Bs(e) {
2357
+ return new io({
2358
+ check: "string_format",
2359
+ format: "uppercase",
2360
+ ...p(e)
2361
+ });
2362
+ }
2363
+ // @__NO_SIDE_EFFECTS__
2364
+ function Js(e, t) {
2365
+ return new ao({
2366
+ check: "string_format",
2367
+ format: "includes",
2368
+ ...p(t),
2369
+ includes: e
2370
+ });
2371
+ }
2372
+ // @__NO_SIDE_EFFECTS__
2373
+ function Vs(e, t) {
2374
+ return new co({
2375
+ check: "string_format",
2376
+ format: "starts_with",
2377
+ ...p(t),
2378
+ prefix: e
2379
+ });
2380
+ }
2381
+ // @__NO_SIDE_EFFECTS__
2382
+ function Gs(e, t) {
2383
+ return new uo({
2384
+ check: "string_format",
2385
+ format: "ends_with",
2386
+ ...p(t),
2387
+ suffix: e
2388
+ });
2389
+ }
2390
+ // @__NO_SIDE_EFFECTS__
2391
+ function te(e) {
2392
+ return new lo({
2393
+ check: "overwrite",
2394
+ tx: e
2395
+ });
2396
+ }
2397
+ // @__NO_SIDE_EFFECTS__
2398
+ function Hs(e) {
2399
+ return /* @__PURE__ */ te((t) => t.normalize(e));
2400
+ }
2401
+ // @__NO_SIDE_EFFECTS__
2402
+ function Ys() {
2403
+ return /* @__PURE__ */ te((e) => e.trim());
2404
+ }
2405
+ // @__NO_SIDE_EFFECTS__
2406
+ function Xs() {
2407
+ return /* @__PURE__ */ te((e) => e.toLowerCase());
2408
+ }
2409
+ // @__NO_SIDE_EFFECTS__
2410
+ function qs() {
2411
+ return /* @__PURE__ */ te((e) => e.toUpperCase());
2412
+ }
2413
+ // @__NO_SIDE_EFFECTS__
2414
+ function Ks() {
2415
+ return /* @__PURE__ */ te((e) => nn(e));
2416
+ }
2417
+ // @__NO_SIDE_EFFECTS__
2418
+ function Qs(e, t, r) {
2419
+ return new e({
2420
+ type: "array",
2421
+ element: t,
2422
+ // get element() {
2423
+ // return element;
2424
+ // },
2425
+ ...p(r)
2426
+ });
2427
+ }
2428
+ // @__NO_SIDE_EFFECTS__
2429
+ function ei(e, t, r) {
2430
+ return new e({
2431
+ type: "custom",
2432
+ check: "custom",
2433
+ fn: t,
2434
+ ...p(r)
2435
+ });
2436
+ }
2437
+ // @__NO_SIDE_EFFECTS__
2438
+ function ti(e) {
2439
+ const t = /* @__PURE__ */ ri((r) => (r.addIssue = (n) => {
2440
+ if (typeof n == "string")
2441
+ r.issues.push(ae(n, r.value, t._zod.def));
2442
+ else {
2443
+ const o = n;
2444
+ o.fatal && (o.continue = !1), o.code ?? (o.code = "custom"), o.input ?? (o.input = r.value), o.inst ?? (o.inst = t), o.continue ?? (o.continue = !t._zod.def.abort), r.issues.push(ae(o));
2445
+ }
2446
+ }, e(r.value, r)));
2447
+ return t;
2448
+ }
2449
+ // @__NO_SIDE_EFFECTS__
2450
+ function ri(e, t) {
2451
+ const r = new Z({
2452
+ check: "custom",
2453
+ ...p(t)
2454
+ });
2455
+ return r._zod.check = e, r;
2456
+ }
2457
+ function dr(e) {
2458
+ let t = e?.target ?? "draft-2020-12";
2459
+ return t === "draft-4" && (t = "draft-04"), t === "draft-7" && (t = "draft-07"), {
2460
+ processors: e.processors ?? {},
2461
+ metadataRegistry: e?.metadata ?? se,
2462
+ target: t,
2463
+ unrepresentable: e?.unrepresentable ?? "throw",
2464
+ override: e?.override ?? (() => {
2465
+ }),
2466
+ io: e?.io ?? "output",
2467
+ counter: 0,
2468
+ seen: /* @__PURE__ */ new Map(),
2469
+ cycles: e?.cycles ?? "ref",
2470
+ reused: e?.reused ?? "inline",
2471
+ external: e?.external ?? void 0
2472
+ };
2473
+ }
2474
+ function b(e, t, r = { path: [], schemaPath: [] }) {
2475
+ var n;
2476
+ const o = e._zod.def, i = t.seen.get(e);
2477
+ if (i)
2478
+ return i.count++, r.schemaPath.includes(e) && (i.cycle = r.path), i.schema;
2479
+ const s = { schema: {}, count: 1, cycle: void 0, path: r.path };
2480
+ t.seen.set(e, s);
2481
+ const a = e._zod.toJSONSchema?.();
2482
+ if (a)
2483
+ s.schema = a;
2484
+ else {
2485
+ const f = {
2486
+ ...r,
2487
+ schemaPath: [...r.schemaPath, e],
2488
+ path: r.path
2489
+ };
2490
+ if (e._zod.processJSONSchema)
2491
+ e._zod.processJSONSchema(t, s.schema, f);
2492
+ else {
2493
+ const h = s.schema, m = t.processors[o.type];
2494
+ if (!m)
2495
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);
2496
+ m(e, t, h, f);
2497
+ }
2498
+ const d = e._zod.parent;
2499
+ d && (s.ref || (s.ref = d), b(d, t, f), t.seen.get(d).isParent = !0);
2500
+ }
2501
+ const c = t.metadataRegistry.get(e);
2502
+ return c && Object.assign(s.schema, c), t.io === "input" && E(e) && (delete s.schema.examples, delete s.schema.default), t.io === "input" && s.schema._prefault && ((n = s.schema).default ?? (n.default = s.schema._prefault)), delete s.schema._prefault, t.seen.get(e).schema;
2503
+ }
2504
+ function fr(e, t) {
2505
+ const r = e.seen.get(t);
2506
+ if (!r)
2507
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2508
+ const n = /* @__PURE__ */ new Map();
2509
+ for (const s of e.seen.entries()) {
2510
+ const a = e.metadataRegistry.get(s[0])?.id;
2511
+ if (a) {
2512
+ const c = n.get(a);
2513
+ if (c && c !== s[0])
2514
+ throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
2515
+ n.set(a, s[0]);
2516
+ }
2517
+ }
2518
+ const o = (s) => {
2519
+ const a = e.target === "draft-2020-12" ? "$defs" : "definitions";
2520
+ if (e.external) {
2521
+ const d = e.external.registry.get(s[0])?.id, h = e.external.uri ?? ((S) => S);
2522
+ if (d)
2523
+ return { ref: h(d) };
2524
+ const m = s[1].defId ?? s[1].schema.id ?? `schema${e.counter++}`;
2525
+ return s[1].defId = m, { defId: m, ref: `${h("__shared")}#/${a}/${m}` };
2526
+ }
2527
+ if (s[1] === r)
2528
+ return { ref: "#" };
2529
+ const u = `#/${a}/`, f = s[1].schema.id ?? `__schema${e.counter++}`;
2530
+ return { defId: f, ref: u + f };
2531
+ }, i = (s) => {
2532
+ if (s[1].schema.$ref)
2533
+ return;
2534
+ const a = s[1], { ref: c, defId: u } = o(s);
2535
+ a.def = { ...a.schema }, u && (a.defId = u);
2536
+ const f = a.schema;
2537
+ for (const d in f)
2538
+ delete f[d];
2539
+ f.$ref = c;
2540
+ };
2541
+ if (e.cycles === "throw")
2542
+ for (const s of e.seen.entries()) {
2543
+ const a = s[1];
2544
+ if (a.cycle)
2545
+ throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
2546
+
2547
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2548
+ }
2549
+ for (const s of e.seen.entries()) {
2550
+ const a = s[1];
2551
+ if (t === s[0]) {
2552
+ i(s);
2553
+ continue;
2554
+ }
2555
+ if (e.external) {
2556
+ const u = e.external.registry.get(s[0])?.id;
2557
+ if (t !== s[0] && u) {
2558
+ i(s);
2559
+ continue;
2560
+ }
2561
+ }
2562
+ if (e.metadataRegistry.get(s[0])?.id) {
2563
+ i(s);
2564
+ continue;
2565
+ }
2566
+ if (a.cycle) {
2567
+ i(s);
2568
+ continue;
2569
+ }
2570
+ if (a.count > 1 && e.reused === "ref") {
2571
+ i(s);
2572
+ continue;
2573
+ }
2574
+ }
2575
+ }
2576
+ function hr(e, t) {
2577
+ const r = e.seen.get(t);
2578
+ if (!r)
2579
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2580
+ const n = (s) => {
2581
+ const a = e.seen.get(s);
2582
+ if (a.ref === null)
2583
+ return;
2584
+ const c = a.def ?? a.schema, u = { ...c }, f = a.ref;
2585
+ if (a.ref = null, f) {
2586
+ n(f);
2587
+ const h = e.seen.get(f), m = h.schema;
2588
+ if (m.$ref && (e.target === "draft-07" || e.target === "draft-04" || e.target === "openapi-3.0") ? (c.allOf = c.allOf ?? [], c.allOf.push(m)) : Object.assign(c, m), Object.assign(c, u), s._zod.parent === f)
2589
+ for (const z in c)
2590
+ z === "$ref" || z === "allOf" || z in u || delete c[z];
2591
+ if (m.$ref && h.def)
2592
+ for (const z in c)
2593
+ z === "$ref" || z === "allOf" || z in h.def && JSON.stringify(c[z]) === JSON.stringify(h.def[z]) && delete c[z];
2594
+ }
2595
+ const d = s._zod.parent;
2596
+ if (d && d !== f) {
2597
+ n(d);
2598
+ const h = e.seen.get(d);
2599
+ if (h?.schema.$ref && (c.$ref = h.schema.$ref, h.def))
2600
+ for (const m in c)
2601
+ m === "$ref" || m === "allOf" || m in h.def && JSON.stringify(c[m]) === JSON.stringify(h.def[m]) && delete c[m];
2602
+ }
2603
+ e.override({
2604
+ zodSchema: s,
2605
+ jsonSchema: c,
2606
+ path: a.path ?? []
2607
+ });
2608
+ };
2609
+ for (const s of [...e.seen.entries()].reverse())
2610
+ n(s[0]);
2611
+ const o = {};
2612
+ if (e.target === "draft-2020-12" ? o.$schema = "https://json-schema.org/draft/2020-12/schema" : e.target === "draft-07" ? o.$schema = "http://json-schema.org/draft-07/schema#" : e.target === "draft-04" ? o.$schema = "http://json-schema.org/draft-04/schema#" : e.target, e.external?.uri) {
2613
+ const s = e.external.registry.get(t)?.id;
2614
+ if (!s)
2615
+ throw new Error("Schema is missing an `id` property");
2616
+ o.$id = e.external.uri(s);
2617
+ }
2618
+ Object.assign(o, r.def ?? r.schema);
2619
+ const i = e.external?.defs ?? {};
2620
+ for (const s of e.seen.entries()) {
2621
+ const a = s[1];
2622
+ a.def && a.defId && (i[a.defId] = a.def);
2623
+ }
2624
+ e.external || Object.keys(i).length > 0 && (e.target === "draft-2020-12" ? o.$defs = i : o.definitions = i);
2625
+ try {
2626
+ const s = JSON.parse(JSON.stringify(o));
2627
+ return Object.defineProperty(s, "~standard", {
2628
+ value: {
2629
+ ...t["~standard"],
2630
+ jsonSchema: {
2631
+ input: ze(t, "input", e.processors),
2632
+ output: ze(t, "output", e.processors)
2633
+ }
2634
+ },
2635
+ enumerable: !1,
2636
+ writable: !1
2637
+ }), s;
2638
+ } catch {
2639
+ throw new Error("Error converting schema to JSON.");
2640
+ }
2641
+ }
2642
+ function E(e, t) {
2643
+ const r = t ?? { seen: /* @__PURE__ */ new Set() };
2644
+ if (r.seen.has(e))
2645
+ return !1;
2646
+ r.seen.add(e);
2647
+ const n = e._zod.def;
2648
+ if (n.type === "transform")
2649
+ return !0;
2650
+ if (n.type === "array")
2651
+ return E(n.element, r);
2652
+ if (n.type === "set")
2653
+ return E(n.valueType, r);
2654
+ if (n.type === "lazy")
2655
+ return E(n.getter(), r);
2656
+ if (n.type === "promise" || n.type === "optional" || n.type === "nonoptional" || n.type === "nullable" || n.type === "readonly" || n.type === "default" || n.type === "prefault")
2657
+ return E(n.innerType, r);
2658
+ if (n.type === "intersection")
2659
+ return E(n.left, r) || E(n.right, r);
2660
+ if (n.type === "record" || n.type === "map")
2661
+ return E(n.keyType, r) || E(n.valueType, r);
2662
+ if (n.type === "pipe")
2663
+ return E(n.in, r) || E(n.out, r);
2664
+ if (n.type === "object") {
2665
+ for (const o in n.shape)
2666
+ if (E(n.shape[o], r))
2667
+ return !0;
2668
+ return !1;
2669
+ }
2670
+ if (n.type === "union") {
2671
+ for (const o of n.options)
2672
+ if (E(o, r))
2673
+ return !0;
2674
+ return !1;
2675
+ }
2676
+ if (n.type === "tuple") {
2677
+ for (const o of n.items)
2678
+ if (E(o, r))
2679
+ return !0;
2680
+ return !!(n.rest && E(n.rest, r));
2681
+ }
2682
+ return !1;
2683
+ }
2684
+ const ni = (e, t = {}) => (r) => {
2685
+ const n = dr({ ...r, processors: t });
2686
+ return b(e, n), fr(n, e), hr(n, e);
2687
+ }, ze = (e, t, r = {}) => (n) => {
2688
+ const { libraryOptions: o, target: i } = n ?? {}, s = dr({ ...o ?? {}, target: i, io: t, processors: r });
2689
+ return b(e, s), fr(s, e), hr(s, e);
2690
+ }, oi = {
2691
+ guid: "uuid",
2692
+ url: "uri",
2693
+ datetime: "date-time",
2694
+ json_string: "json-string",
2695
+ regex: ""
2696
+ // do not set
2697
+ }, si = (e, t, r, n) => {
2698
+ const o = r;
2699
+ o.type = "string";
2700
+ const { minimum: i, maximum: s, format: a, patterns: c, contentEncoding: u } = e._zod.bag;
2701
+ if (typeof i == "number" && (o.minLength = i), typeof s == "number" && (o.maxLength = s), a && (o.format = oi[a] ?? a, o.format === "" && delete o.format, a === "time" && delete o.format), u && (o.contentEncoding = u), c && c.size > 0) {
2702
+ const f = [...c];
2703
+ f.length === 1 ? o.pattern = f[0].source : f.length > 1 && (o.allOf = [
2704
+ ...f.map((d) => ({
2705
+ ...t.target === "draft-07" || t.target === "draft-04" || t.target === "openapi-3.0" ? { type: "string" } : {},
2706
+ pattern: d.source
2707
+ }))
2708
+ ]);
2709
+ }
2710
+ }, ii = (e, t, r, n) => {
2711
+ const o = r, { minimum: i, maximum: s, format: a, multipleOf: c, exclusiveMaximum: u, exclusiveMinimum: f } = e._zod.bag;
2712
+ typeof a == "string" && a.includes("int") ? o.type = "integer" : o.type = "number", typeof f == "number" && (t.target === "draft-04" || t.target === "openapi-3.0" ? (o.minimum = f, o.exclusiveMinimum = !0) : o.exclusiveMinimum = f), typeof i == "number" && (o.minimum = i, typeof f == "number" && t.target !== "draft-04" && (f >= i ? delete o.minimum : delete o.exclusiveMinimum)), typeof u == "number" && (t.target === "draft-04" || t.target === "openapi-3.0" ? (o.maximum = u, o.exclusiveMaximum = !0) : o.exclusiveMaximum = u), typeof s == "number" && (o.maximum = s, typeof u == "number" && t.target !== "draft-04" && (u <= s ? delete o.maximum : delete o.exclusiveMaximum)), typeof c == "number" && (o.multipleOf = c);
2713
+ }, ai = (e, t, r, n) => {
2714
+ r.type = "boolean";
2715
+ }, ci = (e, t, r, n) => {
2716
+ r.not = {};
2717
+ }, ui = (e, t, r, n) => {
2718
+ }, li = (e, t, r, n) => {
2719
+ }, di = (e, t, r, n) => {
2720
+ const o = e._zod.def, i = Jt(o.entries);
2721
+ i.every((s) => typeof s == "number") && (r.type = "number"), i.every((s) => typeof s == "string") && (r.type = "string"), r.enum = i;
2722
+ }, fi = (e, t, r, n) => {
2723
+ if (t.unrepresentable === "throw")
2724
+ throw new Error("Custom types cannot be represented in JSON Schema");
2725
+ }, hi = (e, t, r, n) => {
2726
+ if (t.unrepresentable === "throw")
2727
+ throw new Error("Transforms cannot be represented in JSON Schema");
2728
+ }, pi = (e, t, r, n) => {
2729
+ const o = r, i = e._zod.def, { minimum: s, maximum: a } = e._zod.bag;
2730
+ typeof s == "number" && (o.minItems = s), typeof a == "number" && (o.maxItems = a), o.type = "array", o.items = b(i.element, t, { ...n, path: [...n.path, "items"] });
2731
+ }, mi = (e, t, r, n) => {
2732
+ const o = r, i = e._zod.def;
2733
+ o.type = "object", o.properties = {};
2734
+ const s = i.shape;
2735
+ for (const u in s)
2736
+ o.properties[u] = b(s[u], t, {
2737
+ ...n,
2738
+ path: [...n.path, "properties", u]
2739
+ });
2740
+ const a = new Set(Object.keys(s)), c = new Set([...a].filter((u) => {
2741
+ const f = i.shape[u]._zod;
2742
+ return t.io === "input" ? f.optin === void 0 : f.optout === void 0;
2743
+ }));
2744
+ c.size > 0 && (o.required = Array.from(c)), i.catchall?._zod.def.type === "never" ? o.additionalProperties = !1 : i.catchall ? i.catchall && (o.additionalProperties = b(i.catchall, t, {
2745
+ ...n,
2746
+ path: [...n.path, "additionalProperties"]
2747
+ })) : t.io === "output" && (o.additionalProperties = !1);
2748
+ }, wi = (e, t, r, n) => {
2749
+ const o = e._zod.def, i = o.inclusive === !1, s = o.options.map((a, c) => b(a, t, {
2750
+ ...n,
2751
+ path: [...n.path, i ? "oneOf" : "anyOf", c]
2752
+ }));
2753
+ i ? r.oneOf = s : r.anyOf = s;
2754
+ }, gi = (e, t, r, n) => {
2755
+ const o = e._zod.def, i = b(o.left, t, {
2756
+ ...n,
2757
+ path: [...n.path, "allOf", 0]
2758
+ }), s = b(o.right, t, {
2759
+ ...n,
2760
+ path: [...n.path, "allOf", 1]
2761
+ }), a = (u) => "allOf" in u && Object.keys(u).length === 1, c = [
2762
+ ...a(i) ? i.allOf : [i],
2763
+ ...a(s) ? s.allOf : [s]
2764
+ ];
2765
+ r.allOf = c;
2766
+ }, yi = (e, t, r, n) => {
2767
+ const o = r, i = e._zod.def;
2768
+ o.type = "object";
2769
+ const s = i.keyType, c = s._zod.bag?.patterns;
2770
+ if (i.mode === "loose" && c && c.size > 0) {
2771
+ const f = b(i.valueType, t, {
2772
+ ...n,
2773
+ path: [...n.path, "patternProperties", "*"]
2774
+ });
2775
+ o.patternProperties = {};
2776
+ for (const d of c)
2777
+ o.patternProperties[d.source] = f;
2778
+ } else
2779
+ (t.target === "draft-07" || t.target === "draft-2020-12") && (o.propertyNames = b(i.keyType, t, {
2780
+ ...n,
2781
+ path: [...n.path, "propertyNames"]
2782
+ })), o.additionalProperties = b(i.valueType, t, {
2783
+ ...n,
2784
+ path: [...n.path, "additionalProperties"]
2785
+ });
2786
+ const u = s._zod.values;
2787
+ if (u) {
2788
+ const f = [...u].filter((d) => typeof d == "string" || typeof d == "number");
2789
+ f.length > 0 && (o.required = f);
2790
+ }
2791
+ }, vi = (e, t, r, n) => {
2792
+ const o = e._zod.def, i = b(o.innerType, t, n), s = t.seen.get(e);
2793
+ t.target === "openapi-3.0" ? (s.ref = o.innerType, r.nullable = !0) : r.anyOf = [i, { type: "null" }];
2794
+ }, ki = (e, t, r, n) => {
2795
+ const o = e._zod.def;
2796
+ b(o.innerType, t, n);
2797
+ const i = t.seen.get(e);
2798
+ i.ref = o.innerType;
2799
+ }, _i = (e, t, r, n) => {
2800
+ const o = e._zod.def;
2801
+ b(o.innerType, t, n);
2802
+ const i = t.seen.get(e);
2803
+ i.ref = o.innerType, r.default = JSON.parse(JSON.stringify(o.defaultValue));
2804
+ }, bi = (e, t, r, n) => {
2805
+ const o = e._zod.def;
2806
+ b(o.innerType, t, n);
2807
+ const i = t.seen.get(e);
2808
+ i.ref = o.innerType, t.io === "input" && (r._prefault = JSON.parse(JSON.stringify(o.defaultValue)));
2809
+ }, Si = (e, t, r, n) => {
2810
+ const o = e._zod.def;
2811
+ b(o.innerType, t, n);
2812
+ const i = t.seen.get(e);
2813
+ i.ref = o.innerType;
2814
+ let s;
2815
+ try {
2816
+ s = o.catchValue(void 0);
2817
+ } catch {
2818
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
2819
+ }
2820
+ r.default = s;
2821
+ }, zi = (e, t, r, n) => {
2822
+ const o = e._zod.def, i = t.io === "input" ? o.in._zod.def.type === "transform" ? o.out : o.in : o.out;
2823
+ b(i, t, n);
2824
+ const s = t.seen.get(e);
2825
+ s.ref = i;
2826
+ }, Ei = (e, t, r, n) => {
2827
+ const o = e._zod.def;
2828
+ b(o.innerType, t, n);
2829
+ const i = t.seen.get(e);
2830
+ i.ref = o.innerType, r.readOnly = !0;
2831
+ }, pr = (e, t, r, n) => {
2832
+ const o = e._zod.def;
2833
+ b(o.innerType, t, n);
2834
+ const i = t.seen.get(e);
2835
+ i.ref = o.innerType;
2836
+ }, Ti = (e, t, r, n) => {
2837
+ const o = e._zod.innerType;
2838
+ b(o, t, n);
2839
+ const i = t.seen.get(e);
2840
+ i.ref = o;
2841
+ }, $i = /* @__PURE__ */ l("ZodISODateTime", (e, t) => {
2842
+ Eo.init(e, t), k.init(e, t);
2843
+ });
2844
+ function Oi(e) {
2845
+ return /* @__PURE__ */ Rs($i, e);
2846
+ }
2847
+ const Pi = /* @__PURE__ */ l("ZodISODate", (e, t) => {
2848
+ To.init(e, t), k.init(e, t);
2849
+ });
2850
+ function Wi(e) {
2851
+ return /* @__PURE__ */ Is(Pi, e);
2852
+ }
2853
+ const Zi = /* @__PURE__ */ l("ZodISOTime", (e, t) => {
2854
+ $o.init(e, t), k.init(e, t);
2855
+ });
2856
+ function Ri(e) {
2857
+ return /* @__PURE__ */ As(Zi, e);
2858
+ }
2859
+ const Ii = /* @__PURE__ */ l("ZodISODuration", (e, t) => {
2860
+ Oo.init(e, t), k.init(e, t);
2861
+ });
2862
+ function Ai(e) {
2863
+ return /* @__PURE__ */ Ns(Ii, e);
2864
+ }
2865
+ const Ni = (e, t) => {
2866
+ Yt.init(e, t), e.name = "ZodError", Object.defineProperties(e, {
2867
+ format: {
2868
+ value: (r) => gn(e, r)
2869
+ // enumerable: false,
2870
+ },
2871
+ flatten: {
2872
+ value: (r) => wn(e, r)
2873
+ // enumerable: false,
2874
+ },
2875
+ addIssue: {
2876
+ value: (r) => {
2877
+ e.issues.push(r), e.message = JSON.stringify(e.issues, Ce, 2);
2878
+ }
2879
+ // enumerable: false,
2880
+ },
2881
+ addIssues: {
2882
+ value: (r) => {
2883
+ e.issues.push(...r), e.message = JSON.stringify(e.issues, Ce, 2);
2884
+ }
2885
+ // enumerable: false,
2886
+ },
2887
+ isEmpty: {
2888
+ get() {
2889
+ return e.issues.length === 0;
2890
+ }
2891
+ // enumerable: false,
2892
+ }
2893
+ });
2894
+ }, R = l("ZodError", Ni, {
2895
+ Parent: Error
2896
+ }), Di = /* @__PURE__ */ Xe(R), Ci = /* @__PURE__ */ qe(R), Ui = /* @__PURE__ */ Oe(R), ji = /* @__PURE__ */ Pe(R), Li = /* @__PURE__ */ kn(R), Mi = /* @__PURE__ */ _n(R), Fi = /* @__PURE__ */ bn(R), xi = /* @__PURE__ */ Sn(R), Bi = /* @__PURE__ */ zn(R), Ji = /* @__PURE__ */ En(R), Vi = /* @__PURE__ */ Tn(R), Gi = /* @__PURE__ */ $n(R), v = /* @__PURE__ */ l("ZodType", (e, t) => (g.init(e, t), Object.assign(e["~standard"], {
2897
+ jsonSchema: {
2898
+ input: ze(e, "input"),
2899
+ output: ze(e, "output")
2900
+ }
2901
+ }), e.toJSONSchema = ni(e, {}), e.def = t, e.type = t.type, Object.defineProperty(e, "_def", { value: t }), e.check = (...r) => e.clone(B(t, {
2902
+ checks: [
2903
+ ...t.checks ?? [],
2904
+ ...r.map((n) => typeof n == "function" ? { _zod: { check: n, def: { check: "custom" }, onattach: [] } } : n)
2905
+ ]
2906
+ }), {
2907
+ parent: !0
2908
+ }), e.with = e.check, e.clone = (r, n) => J(e, r, n), e.brand = () => e, e.register = ((r, n) => (r.add(e, n), e)), e.parse = (r, n) => Di(e, r, n, { callee: e.parse }), e.safeParse = (r, n) => Ui(e, r, n), e.parseAsync = async (r, n) => Ci(e, r, n, { callee: e.parseAsync }), e.safeParseAsync = async (r, n) => ji(e, r, n), e.spa = e.safeParseAsync, e.encode = (r, n) => Li(e, r, n), e.decode = (r, n) => Mi(e, r, n), e.encodeAsync = async (r, n) => Fi(e, r, n), e.decodeAsync = async (r, n) => xi(e, r, n), e.safeEncode = (r, n) => Bi(e, r, n), e.safeDecode = (r, n) => Ji(e, r, n), e.safeEncodeAsync = async (r, n) => Vi(e, r, n), e.safeDecodeAsync = async (r, n) => Gi(e, r, n), e.refine = (r, n) => e.check(Fa(r, n)), e.superRefine = (r) => e.check(xa(r)), e.overwrite = (r) => e.check(/* @__PURE__ */ te(r)), e.optional = () => bt(e), e.exactOptional = () => $a(e), e.nullable = () => St(e), e.nullish = () => bt(St(e)), e.nonoptional = (r) => Ia(e, r), e.array = () => gr(e), e.or = (r) => et([e, r]), e.and = (r) => ba(e, r), e.transform = (r) => zt(e, Ea(r)), e.default = (r) => Wa(e, r), e.prefault = (r) => Ra(e, r), e.catch = (r) => Na(e, r), e.pipe = (r) => zt(e, r), e.readonly = () => Ua(e), e.describe = (r) => {
2909
+ const n = e.clone();
2910
+ return se.add(n, { description: r }), n;
2911
+ }, Object.defineProperty(e, "description", {
2912
+ get() {
2913
+ return se.get(e)?.description;
2914
+ },
2915
+ configurable: !0
2916
+ }), e.meta = (...r) => {
2917
+ if (r.length === 0)
2918
+ return se.get(e);
2919
+ const n = e.clone();
2920
+ return se.add(n, r[0]), n;
2921
+ }, e.isOptional = () => e.safeParse(void 0).success, e.isNullable = () => e.safeParse(null).success, e.apply = (r) => r(e), e)), mr = /* @__PURE__ */ l("_ZodString", (e, t) => {
2922
+ Ke.init(e, t), v.init(e, t), e._zod.processJSONSchema = (n, o, i) => si(e, n, o);
2923
+ const r = e._zod.bag;
2924
+ e.format = r.format ?? null, e.minLength = r.minimum ?? null, e.maxLength = r.maximum ?? null, e.regex = (...n) => e.check(/* @__PURE__ */ Fs(...n)), e.includes = (...n) => e.check(/* @__PURE__ */ Js(...n)), e.startsWith = (...n) => e.check(/* @__PURE__ */ Vs(...n)), e.endsWith = (...n) => e.check(/* @__PURE__ */ Gs(...n)), e.min = (...n) => e.check(/* @__PURE__ */ Se(...n)), e.max = (...n) => e.check(/* @__PURE__ */ ur(...n)), e.length = (...n) => e.check(/* @__PURE__ */ lr(...n)), e.nonempty = (...n) => e.check(/* @__PURE__ */ Se(1, ...n)), e.lowercase = (n) => e.check(/* @__PURE__ */ xs(n)), e.uppercase = (n) => e.check(/* @__PURE__ */ Bs(n)), e.trim = () => e.check(/* @__PURE__ */ Ys()), e.normalize = (...n) => e.check(/* @__PURE__ */ Hs(...n)), e.toLowerCase = () => e.check(/* @__PURE__ */ Xs()), e.toUpperCase = () => e.check(/* @__PURE__ */ qs()), e.slugify = () => e.check(/* @__PURE__ */ Ks());
2925
+ }), Hi = /* @__PURE__ */ l("ZodString", (e, t) => {
2926
+ Ke.init(e, t), mr.init(e, t), e.email = (r) => e.check(/* @__PURE__ */ ds(Yi, r)), e.url = (r) => e.check(/* @__PURE__ */ ws(Xi, r)), e.jwt = (r) => e.check(/* @__PURE__ */ Zs(da, r)), e.emoji = (r) => e.check(/* @__PURE__ */ gs(qi, r)), e.guid = (r) => e.check(/* @__PURE__ */ mt(vt, r)), e.uuid = (r) => e.check(/* @__PURE__ */ fs(ge, r)), e.uuidv4 = (r) => e.check(/* @__PURE__ */ hs(ge, r)), e.uuidv6 = (r) => e.check(/* @__PURE__ */ ps(ge, r)), e.uuidv7 = (r) => e.check(/* @__PURE__ */ ms(ge, r)), e.nanoid = (r) => e.check(/* @__PURE__ */ ys(Ki, r)), e.guid = (r) => e.check(/* @__PURE__ */ mt(vt, r)), e.cuid = (r) => e.check(/* @__PURE__ */ vs(Qi, r)), e.cuid2 = (r) => e.check(/* @__PURE__ */ ks(ea, r)), e.ulid = (r) => e.check(/* @__PURE__ */ _s(ta, r)), e.base64 = (r) => e.check(/* @__PURE__ */ Os(ca, r)), e.base64url = (r) => e.check(/* @__PURE__ */ Ps(ua, r)), e.xid = (r) => e.check(/* @__PURE__ */ bs(ra, r)), e.ksuid = (r) => e.check(/* @__PURE__ */ Ss(na, r)), e.ipv4 = (r) => e.check(/* @__PURE__ */ zs(oa, r)), e.ipv6 = (r) => e.check(/* @__PURE__ */ Es(sa, r)), e.cidrv4 = (r) => e.check(/* @__PURE__ */ Ts(ia, r)), e.cidrv6 = (r) => e.check(/* @__PURE__ */ $s(aa, r)), e.e164 = (r) => e.check(/* @__PURE__ */ Ws(la, r)), e.datetime = (r) => e.check(Oi(r)), e.date = (r) => e.check(Wi(r)), e.time = (r) => e.check(Ri(r)), e.duration = (r) => e.check(Ai(r));
2927
+ });
2928
+ function _(e) {
2929
+ return /* @__PURE__ */ ls(Hi, e);
2930
+ }
2931
+ const k = /* @__PURE__ */ l("ZodStringFormat", (e, t) => {
2932
+ y.init(e, t), mr.init(e, t);
2933
+ }), Yi = /* @__PURE__ */ l("ZodEmail", (e, t) => {
2934
+ wo.init(e, t), k.init(e, t);
2935
+ }), vt = /* @__PURE__ */ l("ZodGUID", (e, t) => {
2936
+ po.init(e, t), k.init(e, t);
2937
+ }), ge = /* @__PURE__ */ l("ZodUUID", (e, t) => {
2938
+ mo.init(e, t), k.init(e, t);
2939
+ }), Xi = /* @__PURE__ */ l("ZodURL", (e, t) => {
2940
+ go.init(e, t), k.init(e, t);
2941
+ }), qi = /* @__PURE__ */ l("ZodEmoji", (e, t) => {
2942
+ yo.init(e, t), k.init(e, t);
2943
+ }), Ki = /* @__PURE__ */ l("ZodNanoID", (e, t) => {
2944
+ vo.init(e, t), k.init(e, t);
2945
+ }), Qi = /* @__PURE__ */ l("ZodCUID", (e, t) => {
2946
+ ko.init(e, t), k.init(e, t);
2947
+ }), ea = /* @__PURE__ */ l("ZodCUID2", (e, t) => {
2948
+ _o.init(e, t), k.init(e, t);
2949
+ }), ta = /* @__PURE__ */ l("ZodULID", (e, t) => {
2950
+ bo.init(e, t), k.init(e, t);
2951
+ }), ra = /* @__PURE__ */ l("ZodXID", (e, t) => {
2952
+ So.init(e, t), k.init(e, t);
2953
+ }), na = /* @__PURE__ */ l("ZodKSUID", (e, t) => {
2954
+ zo.init(e, t), k.init(e, t);
2955
+ }), oa = /* @__PURE__ */ l("ZodIPv4", (e, t) => {
2956
+ Po.init(e, t), k.init(e, t);
2957
+ }), sa = /* @__PURE__ */ l("ZodIPv6", (e, t) => {
2958
+ Wo.init(e, t), k.init(e, t);
2959
+ }), ia = /* @__PURE__ */ l("ZodCIDRv4", (e, t) => {
2960
+ Zo.init(e, t), k.init(e, t);
2961
+ }), aa = /* @__PURE__ */ l("ZodCIDRv6", (e, t) => {
2962
+ Ro.init(e, t), k.init(e, t);
2963
+ }), ca = /* @__PURE__ */ l("ZodBase64", (e, t) => {
2964
+ Io.init(e, t), k.init(e, t);
2965
+ }), ua = /* @__PURE__ */ l("ZodBase64URL", (e, t) => {
2966
+ No.init(e, t), k.init(e, t);
2967
+ }), la = /* @__PURE__ */ l("ZodE164", (e, t) => {
2968
+ Do.init(e, t), k.init(e, t);
2969
+ }), da = /* @__PURE__ */ l("ZodJWT", (e, t) => {
2970
+ Uo.init(e, t), k.init(e, t);
2971
+ }), wr = /* @__PURE__ */ l("ZodNumber", (e, t) => {
2972
+ sr.init(e, t), v.init(e, t), e._zod.processJSONSchema = (n, o, i) => ii(e, n, o), e.gt = (n, o) => e.check(/* @__PURE__ */ gt(n, o)), e.gte = (n, o) => e.check(/* @__PURE__ */ Ae(n, o)), e.min = (n, o) => e.check(/* @__PURE__ */ Ae(n, o)), e.lt = (n, o) => e.check(/* @__PURE__ */ wt(n, o)), e.lte = (n, o) => e.check(/* @__PURE__ */ Ie(n, o)), e.max = (n, o) => e.check(/* @__PURE__ */ Ie(n, o)), e.int = (n) => e.check(kt(n)), e.safe = (n) => e.check(kt(n)), e.positive = (n) => e.check(/* @__PURE__ */ gt(0, n)), e.nonnegative = (n) => e.check(/* @__PURE__ */ Ae(0, n)), e.negative = (n) => e.check(/* @__PURE__ */ wt(0, n)), e.nonpositive = (n) => e.check(/* @__PURE__ */ Ie(0, n)), e.multipleOf = (n, o) => e.check(/* @__PURE__ */ yt(n, o)), e.step = (n, o) => e.check(/* @__PURE__ */ yt(n, o)), e.finite = () => e;
2973
+ const r = e._zod.bag;
2974
+ e.minValue = Math.max(r.minimum ?? Number.NEGATIVE_INFINITY, r.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null, e.maxValue = Math.min(r.maximum ?? Number.POSITIVE_INFINITY, r.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null, e.isInt = (r.format ?? "").includes("int") || Number.isSafeInteger(r.multipleOf ?? 0.5), e.isFinite = !0, e.format = r.format ?? null;
2975
+ });
2976
+ function x(e) {
2977
+ return /* @__PURE__ */ Ds(wr, e);
2978
+ }
2979
+ const fa = /* @__PURE__ */ l("ZodNumberFormat", (e, t) => {
2980
+ jo.init(e, t), wr.init(e, t);
2981
+ });
2982
+ function kt(e) {
2983
+ return /* @__PURE__ */ Cs(fa, e);
2984
+ }
2985
+ const ha = /* @__PURE__ */ l("ZodBoolean", (e, t) => {
2986
+ Lo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => ai(e, r, n);
2987
+ });
2988
+ function je(e) {
2989
+ return /* @__PURE__ */ Us(ha, e);
2990
+ }
2991
+ const pa = /* @__PURE__ */ l("ZodAny", (e, t) => {
2992
+ Mo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => ui();
2993
+ });
2994
+ function Qe() {
2995
+ return /* @__PURE__ */ js(pa);
2996
+ }
2997
+ const ma = /* @__PURE__ */ l("ZodUnknown", (e, t) => {
2998
+ Fo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => li();
2999
+ });
3000
+ function _t() {
3001
+ return /* @__PURE__ */ Ls(ma);
3002
+ }
3003
+ const wa = /* @__PURE__ */ l("ZodNever", (e, t) => {
3004
+ xo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => ci(e, r, n);
3005
+ });
3006
+ function ga(e) {
3007
+ return /* @__PURE__ */ Ms(wa, e);
3008
+ }
3009
+ const ya = /* @__PURE__ */ l("ZodArray", (e, t) => {
3010
+ Bo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => pi(e, r, n, o), e.element = t.element, e.min = (r, n) => e.check(/* @__PURE__ */ Se(r, n)), e.nonempty = (r) => e.check(/* @__PURE__ */ Se(1, r)), e.max = (r, n) => e.check(/* @__PURE__ */ ur(r, n)), e.length = (r, n) => e.check(/* @__PURE__ */ lr(r, n)), e.unwrap = () => e.element;
3011
+ });
3012
+ function gr(e, t) {
3013
+ return /* @__PURE__ */ Qs(ya, e, t);
3014
+ }
3015
+ const va = /* @__PURE__ */ l("ZodObject", (e, t) => {
3016
+ Vo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => mi(e, r, n, o), w(e, "shape", () => t.shape), e.keyof = () => de(Object.keys(e._zod.def.shape)), e.catchall = (r) => e.clone({ ...e._zod.def, catchall: r }), e.passthrough = () => e.clone({ ...e._zod.def, catchall: _t() }), e.loose = () => e.clone({ ...e._zod.def, catchall: _t() }), e.strict = () => e.clone({ ...e._zod.def, catchall: ga() }), e.strip = () => e.clone({ ...e._zod.def, catchall: void 0 }), e.extend = (r) => dn(e, r), e.safeExtend = (r) => fn(e, r), e.merge = (r) => hn(e, r), e.pick = (r) => un(e, r), e.omit = (r) => ln(e, r), e.partial = (...r) => pn(yr, e, r[0]), e.required = (...r) => mn(vr, e, r[0]);
3017
+ });
3018
+ function W(e, t) {
3019
+ const r = {
3020
+ type: "object",
3021
+ shape: e ?? {},
3022
+ ...p(t)
3023
+ };
3024
+ return new va(r);
3025
+ }
3026
+ const ka = /* @__PURE__ */ l("ZodUnion", (e, t) => {
3027
+ Go.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => wi(e, r, n, o), e.options = t.options;
3028
+ });
3029
+ function et(e, t) {
3030
+ return new ka({
3031
+ type: "union",
3032
+ options: e,
3033
+ ...p(t)
3034
+ });
3035
+ }
3036
+ const _a = /* @__PURE__ */ l("ZodIntersection", (e, t) => {
3037
+ Ho.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => gi(e, r, n, o);
3038
+ });
3039
+ function ba(e, t) {
3040
+ return new _a({
3041
+ type: "intersection",
3042
+ left: e,
3043
+ right: t
3044
+ });
3045
+ }
3046
+ const Sa = /* @__PURE__ */ l("ZodRecord", (e, t) => {
3047
+ Yo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => yi(e, r, n, o), e.keyType = t.keyType, e.valueType = t.valueType;
3048
+ });
3049
+ function Le(e, t, r) {
3050
+ return new Sa({
3051
+ type: "record",
3052
+ keyType: e,
3053
+ valueType: t,
3054
+ ...p(r)
3055
+ });
3056
+ }
3057
+ const Me = /* @__PURE__ */ l("ZodEnum", (e, t) => {
3058
+ Xo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (n, o, i) => di(e, n, o), e.enum = t.entries, e.options = Object.values(t.entries);
3059
+ const r = new Set(Object.keys(t.entries));
3060
+ e.extract = (n, o) => {
3061
+ const i = {};
3062
+ for (const s of n)
3063
+ if (r.has(s))
3064
+ i[s] = t.entries[s];
3065
+ else
3066
+ throw new Error(`Key ${s} not found in enum`);
3067
+ return new Me({
3068
+ ...t,
3069
+ checks: [],
3070
+ ...p(o),
3071
+ entries: i
3072
+ });
3073
+ }, e.exclude = (n, o) => {
3074
+ const i = { ...t.entries };
3075
+ for (const s of n)
3076
+ if (r.has(s))
3077
+ delete i[s];
3078
+ else
3079
+ throw new Error(`Key ${s} not found in enum`);
3080
+ return new Me({
3081
+ ...t,
3082
+ checks: [],
3083
+ ...p(o),
3084
+ entries: i
3085
+ });
3086
+ };
3087
+ });
3088
+ function de(e, t) {
3089
+ const r = Array.isArray(e) ? Object.fromEntries(e.map((n) => [n, n])) : e;
3090
+ return new Me({
3091
+ type: "enum",
3092
+ entries: r,
3093
+ ...p(t)
3094
+ });
3095
+ }
3096
+ const za = /* @__PURE__ */ l("ZodTransform", (e, t) => {
3097
+ qo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => hi(e, r), e._zod.parse = (r, n) => {
3098
+ if (n.direction === "backward")
3099
+ throw new xt(e.constructor.name);
3100
+ r.addIssue = (i) => {
3101
+ if (typeof i == "string")
3102
+ r.issues.push(ae(i, r.value, t));
3103
+ else {
3104
+ const s = i;
3105
+ s.fatal && (s.continue = !1), s.code ?? (s.code = "custom"), s.input ?? (s.input = r.value), s.inst ?? (s.inst = e), r.issues.push(ae(s));
3106
+ }
3107
+ };
3108
+ const o = t.transform(r.value, r);
3109
+ return o instanceof Promise ? o.then((i) => (r.value = i, r)) : (r.value = o, r);
3110
+ };
3111
+ });
3112
+ function Ea(e) {
3113
+ return new za({
3114
+ type: "transform",
3115
+ transform: e
3116
+ });
3117
+ }
3118
+ const yr = /* @__PURE__ */ l("ZodOptional", (e, t) => {
3119
+ cr.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => pr(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3120
+ });
3121
+ function bt(e) {
3122
+ return new yr({
3123
+ type: "optional",
3124
+ innerType: e
3125
+ });
3126
+ }
3127
+ const Ta = /* @__PURE__ */ l("ZodExactOptional", (e, t) => {
3128
+ Ko.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => pr(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3129
+ });
3130
+ function $a(e) {
3131
+ return new Ta({
3132
+ type: "optional",
3133
+ innerType: e
3134
+ });
3135
+ }
3136
+ const Oa = /* @__PURE__ */ l("ZodNullable", (e, t) => {
3137
+ Qo.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => vi(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3138
+ });
3139
+ function St(e) {
3140
+ return new Oa({
3141
+ type: "nullable",
3142
+ innerType: e
3143
+ });
3144
+ }
3145
+ const Pa = /* @__PURE__ */ l("ZodDefault", (e, t) => {
3146
+ es.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => _i(e, r, n, o), e.unwrap = () => e._zod.def.innerType, e.removeDefault = e.unwrap;
3147
+ });
3148
+ function Wa(e, t) {
3149
+ return new Pa({
3150
+ type: "default",
3151
+ innerType: e,
3152
+ get defaultValue() {
3153
+ return typeof t == "function" ? t() : Gt(t);
3154
+ }
3155
+ });
3156
+ }
3157
+ const Za = /* @__PURE__ */ l("ZodPrefault", (e, t) => {
3158
+ ts.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => bi(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3159
+ });
3160
+ function Ra(e, t) {
3161
+ return new Za({
3162
+ type: "prefault",
3163
+ innerType: e,
3164
+ get defaultValue() {
3165
+ return typeof t == "function" ? t() : Gt(t);
3166
+ }
3167
+ });
3168
+ }
3169
+ const vr = /* @__PURE__ */ l("ZodNonOptional", (e, t) => {
3170
+ rs.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => ki(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3171
+ });
3172
+ function Ia(e, t) {
3173
+ return new vr({
3174
+ type: "nonoptional",
3175
+ innerType: e,
3176
+ ...p(t)
3177
+ });
3178
+ }
3179
+ const Aa = /* @__PURE__ */ l("ZodCatch", (e, t) => {
3180
+ ns.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => Si(e, r, n, o), e.unwrap = () => e._zod.def.innerType, e.removeCatch = e.unwrap;
3181
+ });
3182
+ function Na(e, t) {
3183
+ return new Aa({
3184
+ type: "catch",
3185
+ innerType: e,
3186
+ catchValue: typeof t == "function" ? t : () => t
3187
+ });
3188
+ }
3189
+ const Da = /* @__PURE__ */ l("ZodPipe", (e, t) => {
3190
+ os.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => zi(e, r, n, o), e.in = t.in, e.out = t.out;
3191
+ });
3192
+ function zt(e, t) {
3193
+ return new Da({
3194
+ type: "pipe",
3195
+ in: e,
3196
+ out: t
3197
+ // ...util.normalizeParams(params),
3198
+ });
3199
+ }
3200
+ const Ca = /* @__PURE__ */ l("ZodReadonly", (e, t) => {
3201
+ ss.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => Ei(e, r, n, o), e.unwrap = () => e._zod.def.innerType;
3202
+ });
3203
+ function Ua(e) {
3204
+ return new Ca({
3205
+ type: "readonly",
3206
+ innerType: e
3207
+ });
3208
+ }
3209
+ const ja = /* @__PURE__ */ l("ZodLazy", (e, t) => {
3210
+ is.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => Ti(e, r, n, o), e.unwrap = () => e._zod.def.getter();
3211
+ });
3212
+ function La(e) {
3213
+ return new ja({
3214
+ type: "lazy",
3215
+ getter: e
3216
+ });
3217
+ }
3218
+ const Ma = /* @__PURE__ */ l("ZodCustom", (e, t) => {
3219
+ as.init(e, t), v.init(e, t), e._zod.processJSONSchema = (r, n, o) => fi(e, r);
3220
+ });
3221
+ function Fa(e, t = {}) {
3222
+ return /* @__PURE__ */ ei(Ma, e, t);
3223
+ }
3224
+ function xa(e) {
3225
+ return /* @__PURE__ */ ti(e);
3226
+ }
3227
+ const Ba = de(["top", "right", "bottom", "left"]), Ja = W({
3228
+ width: x(),
3229
+ height: x(),
3230
+ mode: de(["static", "animated", "dynamic"]).optional()
3231
+ }), Sc = W({
3232
+ rawHtml: _().optional(),
3233
+ needsCanvas: je().optional(),
3234
+ canvasOptions: Ja.optional()
3235
+ }), Ze = La(
3236
+ () => W({
3237
+ tag: _(),
3238
+ id: _().optional(),
3239
+ key: _().optional(),
3240
+ class: _().optional(),
3241
+ attrs: Le(_(), Qe()).optional(),
3242
+ style: Le(_(), _()).optional(),
3243
+ children: gr(et([_(), Ze])).optional()
3244
+ })
3245
+ ), Va = de([
3246
+ "success",
3247
+ "warning",
3248
+ "error",
3249
+ "info"
3250
+ ]), Fe = W({
3251
+ id: _(),
3252
+ message: _(),
3253
+ severity: Va,
3254
+ duration: x().positive().optional(),
3255
+ vnode: Ze.optional()
3256
+ }), Ga = de([
3257
+ "top",
3258
+ "bottom",
3259
+ "left",
3260
+ "right",
3261
+ "auto"
3262
+ ]), xe = W({
3263
+ id: _(),
3264
+ content: et([_(), Ze]).optional(),
3265
+ position: Ga.optional(),
3266
+ anchor: _().optional()
3267
+ }), Be = W({
3268
+ id: _(),
3269
+ content: Ze.optional(),
3270
+ title: _().optional(),
3271
+ metadata: Le(_(), Qe()).optional()
3272
+ }), Ha = W({
3273
+ name: _(),
3274
+ version: _().optional()
3275
+ }), Ya = W({
3276
+ meta: Ha.optional(),
3277
+ timestamp: x()
3278
+ }), Et = W({
3279
+ id: Ba,
3280
+ payload: Qe().optional()
3281
+ }), Xa = W({
3282
+ timestamp: x()
3283
+ }), qa = W({
3284
+ timestamp: x(),
3285
+ workersFirst: W({
3286
+ db: je(),
3287
+ ws: je()
3288
+ })
3289
+ }), Ka = W({
3290
+ timestamp: x(),
3291
+ level: _()
3292
+ }), Qa = W({
3293
+ timestamp: x(),
3294
+ level: _()
3295
+ }), ec = {
3296
+ "droid-first-connect": qa,
3297
+ "droid-ready": Xa,
3298
+ "droid-mod-ready": Ya,
3299
+ "droid-downscale": Ka,
3300
+ "droid-upscale": Qa,
3301
+ "panel-open": Et,
3302
+ "panel-close": Et,
3303
+ "toast-added": Fe,
3304
+ "toast-removed": Fe.pick({ id: !0 }),
3305
+ "tooltip-opened": xe,
3306
+ "tooltip-closed": xe.pick({ id: !0 }),
3307
+ "modal-opened": Be,
3308
+ "modal-closed": Be.pick({ id: !0 })
3309
+ };
3310
+ class tc {
3311
+ listeners = /* @__PURE__ */ new Map();
3312
+ on(t, r) {
3313
+ let n = this.listeners.get(t);
3314
+ n || (n = /* @__PURE__ */ new Set(), this.listeners.set(t, n)), n.add(r);
3315
+ }
3316
+ off(t, r) {
3317
+ this.listeners.get(t)?.delete(r);
3318
+ }
3319
+ emit(t, r) {
3320
+ const n = ec[t];
3321
+ if (n)
3322
+ try {
3323
+ n.parse(r);
3324
+ } catch (o) {
3325
+ console.error(
3326
+ `[DroidEventBus] Invalid payload for ${t}:`,
3327
+ o
3328
+ );
3329
+ return;
3330
+ }
3331
+ window.dispatchEvent(new CustomEvent(t, { detail: r }));
3332
+ for (const o of this.listeners.get(t) ?? [])
3333
+ try {
3334
+ o(r);
3335
+ } catch (i) {
3336
+ console.error(
3337
+ `[DroidEventBus] Listener error for ${t}:`,
3338
+ i
3339
+ );
3340
+ }
3341
+ }
3342
+ wait(t) {
3343
+ return new Promise((r) => {
3344
+ const n = (o) => {
3345
+ this.off(t, n), r(o);
3346
+ };
3347
+ this.on(t, n);
3348
+ });
3349
+ }
3350
+ }
3351
+ const D = new tc(), Ee = /* @__PURE__ */ Je({});
3352
+ function kr() {
3353
+ return window.__kbveToastQueue === null ? null : (window.__kbveToastQueue || (window.__kbveToastQueue = []), window.__kbveToastQueue);
3354
+ }
3355
+ function ie(e) {
3356
+ Ee.set({ ...Ee.get(), [e.id]: e }), kr()?.push(e), D.emit("toast-added", e);
3357
+ }
3358
+ function _r(e) {
3359
+ const t = { ...Ee.get() };
3360
+ delete t[e], Ee.set(t);
3361
+ const r = kr();
3362
+ if (r) {
3363
+ const n = r.findIndex((o) => o.id === e);
3364
+ n !== -1 && r.splice(n, 1);
3365
+ }
3366
+ D.emit("toast-removed", { id: e });
3367
+ }
3368
+ const K = /* @__PURE__ */ Te(null), tt = /* @__PURE__ */ Te(!1), ve = /* @__PURE__ */ Te(null);
3369
+ function br(e) {
3370
+ K.set(e), D.emit("tooltip-opened", { id: e });
3371
+ }
3372
+ function Sr(e) {
3373
+ if (e && K.get() !== e) return;
3374
+ const t = K.get();
3375
+ K.set(null), t && D.emit("tooltip-closed", { id: t });
3376
+ }
3377
+ function zc() {
3378
+ tt.set(!0), K.set(null);
3379
+ }
3380
+ function Ec() {
3381
+ tt.set(!1);
3382
+ }
3383
+ function zr(e) {
3384
+ ve.set(e), tt.set(!1), K.set(null), D.emit("modal-opened", { id: e });
3385
+ }
3386
+ function Er(e) {
3387
+ if (e && ve.get() !== e) return;
3388
+ const t = ve.get();
3389
+ ve.set(null), t && D.emit("modal-closed", { id: t });
3390
+ }
3391
+ function Tr() {
3392
+ if (typeof window > "u")
3393
+ return {
3394
+ hasSharedWorker: !1,
3395
+ hasWorker: !1,
3396
+ hasBroadcastChannel: !1,
3397
+ isAndroid: !1,
3398
+ isSafari: !1
3399
+ };
3400
+ const e = navigator.userAgent || "";
3401
+ return {
3402
+ hasSharedWorker: typeof SharedWorker < "u",
3403
+ hasWorker: typeof Worker < "u",
3404
+ hasBroadcastChannel: typeof BroadcastChannel < "u",
3405
+ isAndroid: /Android/i.test(e),
3406
+ isSafari: /Safari/i.test(e) && !/Chrome/i.test(e)
3407
+ };
3408
+ }
3409
+ function rc(e) {
3410
+ const t = e || Tr();
3411
+ return t.hasSharedWorker && t.hasBroadcastChannel && !t.isAndroid ? "shared-worker" : t.hasWorker && t.hasBroadcastChannel ? "web-worker" : "direct";
3412
+ }
3413
+ function nc(e) {
3414
+ console.log("[SupabaseGateway] Browser capabilities:", {
3415
+ SharedWorker: e.hasSharedWorker ? "yes" : "no",
3416
+ Worker: e.hasWorker ? "yes" : "no",
3417
+ BroadcastChannel: e.hasBroadcastChannel ? "yes" : "no",
3418
+ Platform: e.isAndroid ? "Android" : e.isSafari ? "Safari" : "Desktop"
3419
+ });
3420
+ }
3421
+ function Tt(e) {
3422
+ switch (e) {
3423
+ case "shared-worker":
3424
+ return "SharedWorker + DB Worker Pool (optimal for desktop)";
3425
+ case "web-worker":
3426
+ return "WebSocket Worker + DB Worker Pool (optimized for mobile)";
3427
+ case "direct":
3428
+ return "Direct/Main thread (compatibility fallback)";
3429
+ }
3430
+ }
3431
+ class $r {
3432
+ workers = [];
3433
+ poolSize;
3434
+ roundRobinIndex = 0;
3435
+ pending = /* @__PURE__ */ new Map();
3436
+ workerUrl;
3437
+ workerRetryCount = /* @__PURE__ */ new Map();
3438
+ workerRetryTimers = /* @__PURE__ */ new Map();
3439
+ MAX_RETRY_ATTEMPTS = 3;
3440
+ BASE_RETRY_DELAY_MS = 1e3;
3441
+ MAX_RETRY_DELAY_MS = 8e3;
3442
+ REQUEST_TIMEOUT_MS = 3e4;
3443
+ constructor(t) {
3444
+ this.poolSize = t.size, this.workerUrl = t.workerUrl;
3445
+ }
3446
+ /**
3447
+ * Initialize the worker pool
3448
+ */
3449
+ async init() {
3450
+ console.log(
3451
+ `[WorkerPool] Initializing pool with ${this.poolSize} workers`
3452
+ );
3453
+ for (let t = 0; t < this.poolSize; t++)
3454
+ try {
3455
+ const r = new Worker(this.workerUrl, {
3456
+ type: "module",
3457
+ name: `db-worker-${t}`
3458
+ });
3459
+ r.onmessage = (n) => this.handleMessage(n.data, t), r.onerror = (n) => this.handleError(n, t), this.workers.push(r), console.log(`[WorkerPool] Worker ${t} initialized`);
3460
+ } catch (r) {
3461
+ throw console.error(
3462
+ `[WorkerPool] Failed to create worker ${t}:`,
3463
+ r
3464
+ ), r;
3465
+ }
3466
+ await Promise.all(
3467
+ this.workers.map(
3468
+ (t, r) => this.sendToWorker(r, {
3469
+ id: crypto.randomUUID(),
3470
+ type: "ping",
3471
+ payload: {}
3472
+ })
3473
+ )
3474
+ ), console.log("[WorkerPool] All workers ready");
3475
+ }
3476
+ getNextWorker() {
3477
+ const t = this.roundRobinIndex;
3478
+ return this.roundRobinIndex = (this.roundRobinIndex + 1) % this.poolSize, t;
3479
+ }
3480
+ sendToWorker(t, r) {
3481
+ return new Promise((n, o) => {
3482
+ const i = this.workers[t];
3483
+ if (!i)
3484
+ return o(new Error(`Worker ${t} not available`));
3485
+ const s = setTimeout(() => {
3486
+ this.pending.has(r.id) && (this.pending.delete(r.id), o(
3487
+ new Error(
3488
+ `Worker ${t} request ${r.type} timed out after ${this.REQUEST_TIMEOUT_MS}ms`
3489
+ )
3490
+ ));
3491
+ }, this.REQUEST_TIMEOUT_MS);
3492
+ this.pending.set(r.id, {
3493
+ resolve: (a) => {
3494
+ clearTimeout(s), n(a);
3495
+ },
3496
+ reject: (a) => {
3497
+ clearTimeout(s), o(a);
3498
+ },
3499
+ workerId: t
3500
+ });
3501
+ try {
3502
+ i.postMessage(r);
3503
+ } catch (a) {
3504
+ clearTimeout(s), this.pending.delete(r.id), o(a);
3505
+ }
3506
+ });
3507
+ }
3508
+ /**
3509
+ * Send message to next available worker (round-robin)
3510
+ */
3511
+ send(t, r) {
3512
+ const n = this.getNextWorker(), i = { id: crypto.randomUUID(), type: t, payload: r };
3513
+ return this.sendToWorker(n, i);
3514
+ }
3515
+ handleMessage(t, r) {
3516
+ const { id: n, ok: o, data: i, error: s } = t;
3517
+ if (!n) {
3518
+ console.warn(
3519
+ `[WorkerPool] Worker ${r} sent message without ID:`,
3520
+ t
3521
+ );
3522
+ return;
3523
+ }
3524
+ const a = this.pending.get(n);
3525
+ if (!a) {
3526
+ console.warn(
3527
+ `[WorkerPool] Received response for unknown request ${n}`
3528
+ );
3529
+ return;
3530
+ }
3531
+ this.pending.delete(n), o ? a.resolve(i) : a.reject(new Error(s || "Worker request failed"));
3532
+ }
3533
+ handleError(t, r) {
3534
+ console.error(`[WorkerPool] Worker ${r} error:`, t);
3535
+ const n = [];
3536
+ for (const [o, i] of this.pending.entries())
3537
+ i.workerId === r && (i.reject(
3538
+ new Error(`Worker ${r} crashed: ${t.message}`)
3539
+ ), n.push(o));
3540
+ n.forEach((o) => this.pending.delete(o)), this.scheduleWorkerRecreation(r);
3541
+ }
3542
+ scheduleWorkerRecreation(t) {
3543
+ const r = this.workerRetryCount.get(t) || 0;
3544
+ if (r >= this.MAX_RETRY_ATTEMPTS) {
3545
+ console.error(
3546
+ `[WorkerPool] Worker ${t} has failed ${r} times. Giving up.`
3547
+ ), this.workerRetryCount.delete(t);
3548
+ return;
3549
+ }
3550
+ const n = Math.min(
3551
+ this.BASE_RETRY_DELAY_MS * Math.pow(2, r),
3552
+ this.MAX_RETRY_DELAY_MS
3553
+ );
3554
+ console.log(
3555
+ `[WorkerPool] Scheduling worker ${t} recreation in ${n}ms (attempt ${r + 1}/${this.MAX_RETRY_ATTEMPTS})`
3556
+ );
3557
+ const o = this.workerRetryTimers.get(t);
3558
+ o && clearTimeout(o);
3559
+ const i = setTimeout(() => {
3560
+ this.workerRetryTimers.delete(t), this.recreateWorker(t);
3561
+ }, n);
3562
+ this.workerRetryTimers.set(t, i), this.workerRetryCount.set(t, r + 1);
3563
+ }
3564
+ async recreateWorker(t) {
3565
+ const r = this.workerRetryCount.get(t) || 0;
3566
+ console.log(
3567
+ `[WorkerPool] Attempting to recreate worker ${t} (attempt ${r}/${this.MAX_RETRY_ATTEMPTS})`
3568
+ );
3569
+ try {
3570
+ const n = new Worker(this.workerUrl, {
3571
+ type: "module",
3572
+ name: `db-worker-${t}`
3573
+ });
3574
+ n.onmessage = (o) => this.handleMessage(o.data, t), n.onerror = (o) => this.handleError(o, t), this.workers[t] = n, await this.sendToWorker(t, {
3575
+ id: crypto.randomUUID(),
3576
+ type: "ping",
3577
+ payload: {}
3578
+ }), console.log(
3579
+ `[WorkerPool] Worker ${t} recreated successfully`
3580
+ ), this.workerRetryCount.delete(t);
3581
+ } catch (n) {
3582
+ console.error(
3583
+ `[WorkerPool] Failed to recreate worker ${t}:`,
3584
+ n
3585
+ );
3586
+ }
3587
+ }
3588
+ /**
3589
+ * Terminate all workers
3590
+ */
3591
+ terminate() {
3592
+ console.log("[WorkerPool] Terminating all workers"), this.workerRetryTimers.forEach((t) => clearTimeout(t)), this.workerRetryTimers.clear(), this.workerRetryCount.clear(), this.workers.forEach((t, r) => {
3593
+ try {
3594
+ t.terminate();
3595
+ } catch (n) {
3596
+ console.error(
3597
+ `[WorkerPool] Error terminating worker ${r}:`,
3598
+ n
3599
+ );
3600
+ }
3601
+ }), this.workers = [], this.pending.clear();
3602
+ }
3603
+ /**
3604
+ * Get pool statistics
3605
+ */
3606
+ getStats() {
3607
+ return {
3608
+ size: this.poolSize,
3609
+ activeWorkers: this.workers.length,
3610
+ pendingRequests: this.pending.size,
3611
+ nextWorker: this.roundRobinIndex
3612
+ };
3613
+ }
3614
+ }
3615
+ class oc {
3616
+ worker;
3617
+ port;
3618
+ workerPool;
3619
+ pending = /* @__PURE__ */ new Map();
3620
+ listeners = /* @__PURE__ */ new Map();
3621
+ comm = Nt();
3622
+ sharedWorkerUrl;
3623
+ dbWorkerUrl;
3624
+ poolSize;
3625
+ constructor(t, r, n = 3) {
3626
+ if (this.sharedWorkerUrl = t, this.dbWorkerUrl = r, this.poolSize = n, !(typeof window > "u") && !("SharedWorker" in window))
3627
+ throw new Error("SharedWorker not supported");
3628
+ }
3629
+ async init(t, r, n) {
3630
+ console.log("[SharedWorkerStrategy] Initializing..."), this.worker = new SharedWorker(this.sharedWorkerUrl, {
3631
+ type: "module",
3632
+ name: "supabase-shared"
3633
+ }), this.port = this.worker.port, this.port.onmessage = (s) => this.onMessage(s.data), this.port.start(), this.workerPool = new $r({
3634
+ size: this.poolSize,
3635
+ workerUrl: this.dbWorkerUrl
3636
+ }), await this.workerPool.init();
3637
+ const o = this.send("init", {
3638
+ url: t,
3639
+ anonKey: r,
3640
+ options: n
3641
+ }), i = Array.from(
3642
+ { length: this.poolSize },
3643
+ () => this.workerPool?.send("init", { url: t, anonKey: r, options: n })
3644
+ );
3645
+ return await Promise.all([o, ...i]), console.log(
3646
+ `[SharedWorkerStrategy] Initialized (SharedWorker + ${this.poolSize} DB workers)`
3647
+ ), o;
3648
+ }
3649
+ onMessage(t) {
3650
+ if (t?.type === "ready" || t?.type === "auth") {
3651
+ this.emit(t.type, t);
3652
+ return;
3653
+ }
3654
+ if (t?.type === "realtime" && t.key) {
3655
+ this.emit(`realtime:${t.key}`, t.payload);
3656
+ return;
3657
+ }
3658
+ if (t?.type === "ws.message") {
3659
+ this.emit("ws.message", t.data);
3660
+ return;
3661
+ }
3662
+ if (t?.type === "ws.status") {
3663
+ this.emit("ws.status", t);
3664
+ return;
3665
+ }
3666
+ const { id: r, ok: n, data: o, error: i } = t ?? {};
3667
+ if (r && this.pending.has(r)) {
3668
+ const s = this.pending.get(r);
3669
+ if (!s) return;
3670
+ const { resolve: a, reject: c } = s;
3671
+ this.pending.delete(r), n ? a(o) : c(new Error(i));
3672
+ }
3673
+ }
3674
+ send(t, r) {
3675
+ const n = crypto.randomUUID();
3676
+ return new Promise((o, i) => {
3677
+ if (!this.port)
3678
+ return i(new Error("SharedWorker unavailable"));
3679
+ this.pending.set(n, {
3680
+ resolve: o,
3681
+ reject: i
3682
+ }), this.port.postMessage({ id: n, type: t, payload: r });
3683
+ });
3684
+ }
3685
+ on(t, r) {
3686
+ return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t)?.add(r), () => {
3687
+ const n = this.listeners.get(t);
3688
+ n && (n.delete(r), n.size === 0 && this.listeners.delete(t));
3689
+ };
3690
+ }
3691
+ emit(t, r) {
3692
+ this.listeners.get(t)?.forEach((n) => n(r));
3693
+ }
3694
+ // Auth (via SharedWorker)
3695
+ getSession() {
3696
+ return this.send("getSession");
3697
+ }
3698
+ signInWithPassword(t, r) {
3699
+ return this.send("signInWithPassword", {
3700
+ email: t,
3701
+ password: r
3702
+ });
3703
+ }
3704
+ signOut() {
3705
+ return this.send("signOut");
3706
+ }
3707
+ // Database (via worker pool)
3708
+ select(t, r) {
3709
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3710
+ return this.workerPool.send("from.select", { table: t, ...r ?? {} });
3711
+ }
3712
+ insert(t, r) {
3713
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3714
+ return this.workerPool.send("from.insert", { table: t, data: r });
3715
+ }
3716
+ update(t, r, n) {
3717
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3718
+ return this.workerPool.send("from.update", { table: t, data: r, match: n });
3719
+ }
3720
+ upsert(t, r) {
3721
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3722
+ return this.workerPool.send("from.upsert", { table: t, data: r });
3723
+ }
3724
+ delete(t, r) {
3725
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3726
+ return this.workerPool.send("from.delete", { table: t, match: r });
3727
+ }
3728
+ rpc(t, r) {
3729
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3730
+ return this.workerPool.send("rpc", { fn: t, args: r });
3731
+ }
3732
+ // Realtime (via SharedWorker)
3733
+ subscribePostgres(t, r, n) {
3734
+ const o = this.on(`realtime:${t}`, n);
3735
+ return this.send("realtime.subscribe", { key: t, params: r }).catch((i) => {
3736
+ o(), console.error(i);
3737
+ }), () => {
3738
+ o(), this.send("realtime.unsubscribe", { key: t }).catch(() => {
3739
+ });
3740
+ };
3741
+ }
3742
+ // WebSocket (via SharedWorker)
3743
+ connectWebSocket(t) {
3744
+ return this.send("ws.connect", { wsUrl: t });
3745
+ }
3746
+ disconnectWebSocket() {
3747
+ return this.send("ws.disconnect");
3748
+ }
3749
+ sendWebSocketMessage(t) {
3750
+ return this.send("ws.send", { data: t });
3751
+ }
3752
+ getWebSocketStatus() {
3753
+ return this.send("ws.status");
3754
+ }
3755
+ onWebSocketMessage(t) {
3756
+ return this.on("ws.message", t);
3757
+ }
3758
+ onWebSocketStatus(t) {
3759
+ return this.on(
3760
+ "ws.status",
3761
+ (r) => t(r)
3762
+ );
3763
+ }
3764
+ terminate() {
3765
+ this.workerPool?.terminate(), this.comm.close(), this.listeners.clear(), this.pending.clear();
3766
+ }
3767
+ }
3768
+ class sc {
3769
+ wsWorker;
3770
+ workerPool;
3771
+ pending = /* @__PURE__ */ new Map();
3772
+ listeners = /* @__PURE__ */ new Map();
3773
+ comm = Nt();
3774
+ wsWorkerUrl;
3775
+ dbWorkerUrl;
3776
+ poolSize;
3777
+ constructor(t, r, n = 3) {
3778
+ if (this.wsWorkerUrl = t, this.dbWorkerUrl = r, this.poolSize = n, !(typeof window > "u") && !("Worker" in window))
3779
+ throw new Error("Worker not supported");
3780
+ }
3781
+ async init(t, r, n) {
3782
+ console.log("[WebWorkerStrategy] Initializing..."), this.wsWorker = new Worker(this.wsWorkerUrl, {
3783
+ type: "module",
3784
+ name: "websocket-worker"
3785
+ }), this.wsWorker.onmessage = (s) => this.onMessage(s.data), this.wsWorker.onerror = (s) => console.error("[WebWorkerStrategy] WebSocket worker error:", s), this.workerPool = new $r({
3786
+ size: this.poolSize,
3787
+ workerUrl: this.dbWorkerUrl
3788
+ }), await this.workerPool.init();
3789
+ const o = this.send("init", {
3790
+ url: t,
3791
+ anonKey: r,
3792
+ options: n
3793
+ }), i = Array.from(
3794
+ { length: this.poolSize },
3795
+ () => this.workerPool?.send("init", { url: t, anonKey: r, options: n })
3796
+ );
3797
+ return await Promise.all([o, ...i]), console.log(
3798
+ `[WebWorkerStrategy] Initialized (WebSocket worker + ${this.poolSize} DB workers)`
3799
+ ), o;
3800
+ }
3801
+ onMessage(t) {
3802
+ const r = t;
3803
+ if (r?.type === "ready" || r?.type === "auth") {
3804
+ this.emit(r.type, r);
3805
+ return;
3806
+ }
3807
+ if (r?.type === "realtime" && r.key) {
3808
+ this.emit(`realtime:${r.key}`, r.payload);
3809
+ return;
3810
+ }
3811
+ if (r?.type === "ws.message") {
3812
+ this.emit("ws.message", r.data);
3813
+ return;
3814
+ }
3815
+ if (r?.type === "ws.status") {
3816
+ this.emit("ws.status", r);
3817
+ return;
3818
+ }
3819
+ const n = r?.id, o = r?.ok, i = r?.data, s = r?.error;
3820
+ if (n && this.pending.has(n)) {
3821
+ const a = this.pending.get(n);
3822
+ if (!a) return;
3823
+ const { resolve: c, reject: u } = a;
3824
+ this.pending.delete(n), o ? c(i) : u(new Error(s));
3825
+ }
3826
+ }
3827
+ send(t, r) {
3828
+ const n = crypto.randomUUID();
3829
+ return new Promise((o, i) => {
3830
+ if (!this.wsWorker)
3831
+ return i(new Error("WebSocket worker unavailable"));
3832
+ this.pending.set(n, {
3833
+ resolve: o,
3834
+ reject: i
3835
+ }), this.wsWorker.postMessage({ id: n, type: t, payload: r });
3836
+ });
3837
+ }
3838
+ on(t, r) {
3839
+ return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t)?.add(r), () => {
3840
+ const n = this.listeners.get(t);
3841
+ n && (n.delete(r), n.size === 0 && this.listeners.delete(t));
3842
+ };
3843
+ }
3844
+ emit(t, r) {
3845
+ this.listeners.get(t)?.forEach((n) => n(r));
3846
+ }
3847
+ // Auth (via WebSocket worker)
3848
+ getSession() {
3849
+ return this.send("getSession");
3850
+ }
3851
+ signInWithPassword(t, r) {
3852
+ return this.send("signInWithPassword", {
3853
+ email: t,
3854
+ password: r
3855
+ });
3856
+ }
3857
+ signOut() {
3858
+ return this.send("signOut");
3859
+ }
3860
+ // Database (via worker pool)
3861
+ select(t, r) {
3862
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3863
+ return this.workerPool.send("from.select", { table: t, ...r ?? {} });
3864
+ }
3865
+ insert(t, r) {
3866
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3867
+ return this.workerPool.send("from.insert", { table: t, data: r });
3868
+ }
3869
+ update(t, r, n) {
3870
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3871
+ return this.workerPool.send("from.update", { table: t, data: r, match: n });
3872
+ }
3873
+ upsert(t, r) {
3874
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3875
+ return this.workerPool.send("from.upsert", { table: t, data: r });
3876
+ }
3877
+ delete(t, r) {
3878
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3879
+ return this.workerPool.send("from.delete", { table: t, match: r });
3880
+ }
3881
+ rpc(t, r) {
3882
+ if (!this.workerPool) throw new Error("Worker pool not initialized");
3883
+ return this.workerPool.send("rpc", { fn: t, args: r });
3884
+ }
3885
+ // Realtime (via WebSocket worker)
3886
+ subscribePostgres(t, r, n) {
3887
+ const o = this.on(`realtime:${t}`, n);
3888
+ return this.send("realtime.subscribe", { key: t, params: r }).catch((i) => {
3889
+ o(), console.error(i);
3890
+ }), () => {
3891
+ o(), this.send("realtime.unsubscribe", { key: t }).catch(() => {
3892
+ });
3893
+ };
3894
+ }
3895
+ // WebSocket (via dedicated worker)
3896
+ connectWebSocket(t) {
3897
+ return this.send("ws.connect", { wsUrl: t });
3898
+ }
3899
+ disconnectWebSocket() {
3900
+ return this.send("ws.disconnect");
3901
+ }
3902
+ sendWebSocketMessage(t) {
3903
+ return this.send("ws.send", { data: t });
3904
+ }
3905
+ getWebSocketStatus() {
3906
+ return this.send("ws.status");
3907
+ }
3908
+ onWebSocketMessage(t) {
3909
+ return this.on("ws.message", t);
3910
+ }
3911
+ onWebSocketStatus(t) {
3912
+ return this.on("ws.status", t);
3913
+ }
3914
+ terminate() {
3915
+ this.wsWorker?.terminate(), this.workerPool?.terminate(), this.comm.close(), this.listeners.clear(), this.pending.clear();
3916
+ }
3917
+ }
3918
+ class ic {
3919
+ client = null;
3920
+ ws = null;
3921
+ wsReconnectTimer = null;
3922
+ wsReconnectAttempts = 0;
3923
+ wsHeartbeatTimer = null;
3924
+ wsLastPongTime = 0;
3925
+ subscriptions = /* @__PURE__ */ new Map();
3926
+ listeners = /* @__PURE__ */ new Map();
3927
+ WS_MAX_RECONNECT_ATTEMPTS = 5;
3928
+ WS_RECONNECT_DELAY_MS = 3e3;
3929
+ WS_HEARTBEAT_INTERVAL_MS = 3e4;
3930
+ WS_HEARTBEAT_TIMEOUT_MS = 6e4;
3931
+ async init(t, r, n) {
3932
+ console.log("[DirectStrategy] Initializing...");
3933
+ const { createClient: o } = await import("./index.js"), i = n?.auth && typeof n.auth == "object" ? n.auth : {};
3934
+ this.client = o(t, r, {
3935
+ ...n,
3936
+ auth: {
3937
+ ...i,
3938
+ autoRefreshToken: !0,
3939
+ persistSession: !0,
3940
+ detectSessionInUrl: !1
3941
+ }
3942
+ }), this.client.auth.onAuthStateChange((c, u) => {
3943
+ this.emit("auth", { session: u });
3944
+ });
3945
+ const {
3946
+ data: { session: s },
3947
+ error: a
3948
+ } = await this.client.auth.getSession();
3949
+ return a && console.error("[DirectStrategy] Session error:", a), console.log("[DirectStrategy] Initialized"), {
3950
+ session: s,
3951
+ user: s?.user || null
3952
+ };
3953
+ }
3954
+ on(t, r) {
3955
+ return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t)?.add(r), () => {
3956
+ const n = this.listeners.get(t);
3957
+ n && (n.delete(r), n.size === 0 && this.listeners.delete(t));
3958
+ };
3959
+ }
3960
+ emit(t, r) {
3961
+ this.listeners.get(t)?.forEach((n) => {
3962
+ try {
3963
+ n(r);
3964
+ } catch (o) {
3965
+ console.error(
3966
+ `[DirectStrategy] Listener error for ${t}:`,
3967
+ o
3968
+ );
3969
+ }
3970
+ });
3971
+ }
3972
+ // Auth
3973
+ async getSession() {
3974
+ if (!this.client) throw new Error("Client not initialized");
3975
+ const { data: t, error: r } = await this.client.auth.getSession();
3976
+ if (r) throw r;
3977
+ return t;
3978
+ }
3979
+ async signInWithPassword(t, r) {
3980
+ if (!this.client) throw new Error("Client not initialized");
3981
+ const { data: n, error: o } = await this.client.auth.signInWithPassword({
3982
+ email: t,
3983
+ password: r
3984
+ });
3985
+ if (o) throw o;
3986
+ return n;
3987
+ }
3988
+ async signOut() {
3989
+ if (!this.client) throw new Error("Client not initialized");
3990
+ const { error: t } = await this.client.auth.signOut();
3991
+ if (t) throw t;
3992
+ }
3993
+ // Database
3994
+ async select(t, r) {
3995
+ if (!this.client) throw new Error("Client not initialized");
3996
+ let n = this.client.from(t).select(r?.columns || "*");
3997
+ if (r?.match)
3998
+ for (const [s, a] of Object.entries(r.match))
3999
+ n = n.eq(s, a);
4000
+ r?.limit && (n = n.limit(r.limit));
4001
+ const { data: o, error: i } = await n;
4002
+ if (i) throw i;
4003
+ return o;
4004
+ }
4005
+ async insert(t, r) {
4006
+ if (!this.client) throw new Error("Client not initialized");
4007
+ const { data: n, error: o } = await this.client.from(t).insert(r).select();
4008
+ if (o) throw o;
4009
+ return n;
4010
+ }
4011
+ async update(t, r, n) {
4012
+ if (!this.client) throw new Error("Client not initialized");
4013
+ let o = this.client.from(t).update(r);
4014
+ for (const [a, c] of Object.entries(n))
4015
+ o = o.eq(a, c);
4016
+ const { data: i, error: s } = await o.select();
4017
+ if (s) throw s;
4018
+ return i;
4019
+ }
4020
+ async upsert(t, r) {
4021
+ if (!this.client) throw new Error("Client not initialized");
4022
+ const { data: n, error: o } = await this.client.from(t).upsert(r).select();
4023
+ if (o) throw o;
4024
+ return n;
4025
+ }
4026
+ async delete(t, r) {
4027
+ if (!this.client) throw new Error("Client not initialized");
4028
+ let n = this.client.from(t).delete();
4029
+ for (const [s, a] of Object.entries(r))
4030
+ n = n.eq(s, a);
4031
+ const { data: o, error: i } = await n.select();
4032
+ if (i) throw i;
4033
+ return o;
4034
+ }
4035
+ async rpc(t, r) {
4036
+ if (!this.client) throw new Error("Client not initialized");
4037
+ const { data: n, error: o } = await this.client.rpc(t, r || {});
4038
+ if (o) throw o;
4039
+ return n;
4040
+ }
4041
+ // Realtime
4042
+ subscribePostgres(t, r, n) {
4043
+ if (!this.client) throw new Error("Client not initialized");
4044
+ const o = this.client.channel(t).on(
4045
+ "postgres_changes",
4046
+ r,
4047
+ (s) => {
4048
+ this.emit(`realtime:${t}`, s);
4049
+ }
4050
+ );
4051
+ o.subscribe(), this.subscriptions.set(t, {
4052
+ unsubscribe: async () => {
4053
+ await o.unsubscribe();
4054
+ }
4055
+ });
4056
+ const i = this.on(`realtime:${t}`, n);
4057
+ return () => {
4058
+ i();
4059
+ const s = this.subscriptions.get(t);
4060
+ s && (s.unsubscribe(), this.subscriptions.delete(t));
4061
+ };
4062
+ }
4063
+ // WebSocket
4064
+ async connectWebSocket(t) {
4065
+ if (this.ws && (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN))
4066
+ return this.getWebSocketStatus();
4067
+ if (!this.client) throw new Error("Client not initialized");
4068
+ const {
4069
+ data: { session: r },
4070
+ error: n
4071
+ } = await this.client.auth.getSession();
4072
+ if (n || !r?.access_token)
4073
+ throw new Error("No active session");
4074
+ const o = t || this.getDefaultWebSocketUrl(), i = `${o}?token=${encodeURIComponent(r.access_token)}`;
4075
+ return console.log("[DirectStrategy] Connecting to WebSocket:", o), this.ws = new WebSocket(i), this.ws.onopen = () => {
4076
+ this.wsReconnectAttempts = 0, this.wsLastPongTime = Date.now(), this.startHeartbeat(), this.emit("ws.status", { status: "connected", url: o });
4077
+ }, this.ws.onmessage = (s) => {
4078
+ try {
4079
+ const a = JSON.parse(s.data);
4080
+ if (a.type === "pong") {
4081
+ this.wsLastPongTime = Date.now();
4082
+ return;
4083
+ }
4084
+ this.emit("ws.message", a);
4085
+ } catch (a) {
4086
+ console.error(
4087
+ "[DirectStrategy] Failed to parse message:",
4088
+ a
4089
+ );
4090
+ }
4091
+ }, this.ws.onerror = () => {
4092
+ this.emit("ws.status", {
4093
+ status: "error",
4094
+ error: "Connection error"
4095
+ });
4096
+ }, this.ws.onclose = (s) => {
4097
+ this.ws = null, this.stopHeartbeat(), this.emit("ws.status", {
4098
+ status: "disconnected",
4099
+ code: s.code,
4100
+ reason: s.reason
4101
+ }), s.code !== 1e3 && this.wsReconnectAttempts < this.WS_MAX_RECONNECT_ATTEMPTS && (this.wsReconnectAttempts++, this.wsReconnectTimer = setTimeout(() => {
4102
+ this.connectWebSocket(t).catch(() => {
4103
+ });
4104
+ }, this.WS_RECONNECT_DELAY_MS));
4105
+ }, this.getWebSocketStatus();
4106
+ }
4107
+ async disconnectWebSocket() {
4108
+ this.wsReconnectTimer && (clearTimeout(this.wsReconnectTimer), this.wsReconnectTimer = null), this.stopHeartbeat(), this.ws && (this.ws.close(1e3, "Client request"), this.ws = null, this.wsReconnectAttempts = 0, this.emit("ws.status", { status: "disconnected" }));
4109
+ }
4110
+ async sendWebSocketMessage(t) {
4111
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN)
4112
+ throw new Error("WebSocket not connected");
4113
+ const r = typeof t == "string" ? t : JSON.stringify(t);
4114
+ this.ws.send(r);
4115
+ }
4116
+ async getWebSocketStatus() {
4117
+ return this.ws ? {
4118
+ status: {
4119
+ [WebSocket.CONNECTING]: "connecting",
4120
+ [WebSocket.OPEN]: "connected",
4121
+ [WebSocket.CLOSING]: "disconnected",
4122
+ [WebSocket.CLOSED]: "disconnected"
4123
+ }[this.ws.readyState] || "disconnected",
4124
+ readyState: this.ws.readyState
4125
+ } : { status: "disconnected", readyState: null };
4126
+ }
4127
+ onWebSocketMessage(t) {
4128
+ return this.on("ws.message", t);
4129
+ }
4130
+ onWebSocketStatus(t) {
4131
+ return this.on("ws.status", t);
4132
+ }
4133
+ // Helpers
4134
+ getDefaultWebSocketUrl() {
4135
+ if (typeof window > "u") return "ws://localhost:4321/ws";
4136
+ const t = window.location.protocol === "https:" ? "wss:" : "ws:", n = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" ? "4321" : window.location.port, o = window.location.hostname;
4137
+ return `${t}//${o}${n ? ":" + n : ""}/ws`;
4138
+ }
4139
+ startHeartbeat() {
4140
+ this.stopHeartbeat(), this.wsHeartbeatTimer = setInterval(() => {
4141
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
4142
+ this.stopHeartbeat();
4143
+ return;
4144
+ }
4145
+ if (this.wsLastPongTime > 0 && Date.now() - this.wsLastPongTime > this.WS_HEARTBEAT_TIMEOUT_MS) {
4146
+ console.warn("[DirectStrategy] Heartbeat timeout"), this.stopHeartbeat(), this.ws.close(1001, "Heartbeat timeout");
4147
+ return;
4148
+ }
4149
+ try {
4150
+ this.ws.send(JSON.stringify({ type: "ping" }));
4151
+ } catch (t) {
4152
+ console.error(
4153
+ "[DirectStrategy] Failed to send heartbeat:",
4154
+ t
4155
+ );
4156
+ }
4157
+ }, this.WS_HEARTBEAT_INTERVAL_MS);
4158
+ }
4159
+ stopHeartbeat() {
4160
+ this.wsHeartbeatTimer && (clearInterval(this.wsHeartbeatTimer), this.wsHeartbeatTimer = null);
4161
+ }
4162
+ terminate() {
4163
+ this.disconnectWebSocket(), this.subscriptions.forEach((t) => t.unsubscribe()), this.subscriptions.clear(), this.listeners.clear();
4164
+ }
4165
+ }
4166
+ const $t = "/lib/workers/supabase-shared-worker.js", Ot = "/lib/workers/supabase-db-worker.js";
4167
+ class Or {
4168
+ strategy;
4169
+ strategyType;
4170
+ constructor(t = {}) {
4171
+ const r = Tr();
4172
+ nc(r), this.strategyType = t.forceStrategy || rc(r), console.log(
4173
+ `[SupabaseGateway] Selected strategy: ${Tt(this.strategyType)}`
4174
+ );
4175
+ const n = t.poolSize ?? 3, o = t.workerUrls ?? {};
4176
+ switch (this.strategyType) {
4177
+ case "shared-worker": {
4178
+ const i = o.sharedWorker ?? $t, s = o.dbWorker ?? Ot;
4179
+ this.strategy = new oc(
4180
+ i,
4181
+ s,
4182
+ n
4183
+ );
4184
+ break;
4185
+ }
4186
+ case "web-worker": {
4187
+ const i = o.webSocketWorker ?? $t, s = o.dbWorker ?? Ot;
4188
+ this.strategy = new sc(i, s, n);
4189
+ break;
4190
+ }
4191
+ case "direct":
4192
+ this.strategy = new ic();
4193
+ break;
4194
+ }
4195
+ }
4196
+ getStrategyType() {
4197
+ return this.strategyType;
4198
+ }
4199
+ getStrategyDescription() {
4200
+ return Tt(this.strategyType);
4201
+ }
4202
+ // Delegate all methods to the selected strategy
4203
+ init(t, r, n) {
4204
+ return this.strategy.init(t, r, n);
4205
+ }
4206
+ on(t, r) {
4207
+ return this.strategy.on(t, r);
4208
+ }
4209
+ getSession() {
4210
+ return this.strategy.getSession();
4211
+ }
4212
+ signInWithPassword(t, r) {
4213
+ return this.strategy.signInWithPassword(t, r);
4214
+ }
4215
+ signOut() {
4216
+ return this.strategy.signOut();
4217
+ }
4218
+ select(t, r) {
4219
+ return this.strategy.select(t, r);
4220
+ }
4221
+ insert(t, r) {
4222
+ return this.strategy.insert(t, r);
4223
+ }
4224
+ update(t, r, n) {
4225
+ return this.strategy.update(t, r, n);
4226
+ }
4227
+ upsert(t, r) {
4228
+ return this.strategy.upsert(t, r);
4229
+ }
4230
+ delete(t, r) {
4231
+ return this.strategy.delete(t, r);
4232
+ }
4233
+ rpc(t, r) {
4234
+ return this.strategy.rpc(t, r);
4235
+ }
4236
+ subscribePostgres(t, r, n) {
4237
+ return this.strategy.subscribePostgres(t, r, n);
4238
+ }
4239
+ connectWebSocket(t) {
4240
+ return this.strategy.connectWebSocket(t);
4241
+ }
4242
+ disconnectWebSocket() {
4243
+ return this.strategy.disconnectWebSocket();
4244
+ }
4245
+ sendWebSocketMessage(t) {
4246
+ return this.strategy.sendWebSocketMessage(t);
4247
+ }
4248
+ getWebSocketStatus() {
4249
+ return this.strategy.getWebSocketStatus();
4250
+ }
4251
+ onWebSocketMessage(t) {
4252
+ return this.strategy.onWebSocketMessage(t);
4253
+ }
4254
+ onWebSocketStatus(t) {
4255
+ return this.strategy.onWebSocketStatus(t);
4256
+ }
4257
+ terminate() {
4258
+ this.strategy.terminate();
4259
+ }
4260
+ }
4261
+ const ac = [
4262
+ "accent",
4263
+ "accent-low",
4264
+ "accent-high",
4265
+ "bg",
4266
+ "bg-accent",
4267
+ "text",
4268
+ "text-accent",
4269
+ "border",
4270
+ "white",
4271
+ "black"
4272
+ ];
4273
+ async function Pt(e) {
4274
+ const t = document.documentElement, r = getComputedStyle(t), n = t.dataset.theme ?? "dark";
4275
+ await e.dbSet("theme:mode", n);
4276
+ for (const o of ac) {
4277
+ const i = r.getPropertyValue(`--sl-color-${o}`).trim();
4278
+ i && await e.dbSet(`theme:${o}`, i);
4279
+ }
4280
+ }
4281
+ function cc() {
4282
+ try {
4283
+ const e = new BroadcastChannel("kbve_theme");
4284
+ e.postMessage({ type: "theme-sync", timestamp: Date.now() }), e.close();
4285
+ } catch {
4286
+ }
4287
+ }
4288
+ function uc(e) {
4289
+ new MutationObserver(async (r) => {
4290
+ for (const n of r)
4291
+ n.type === "attributes" && n.attributeName === "data-theme" && (await Pt(e), cc());
4292
+ }).observe(document.documentElement, {
4293
+ attributes: !0,
4294
+ attributeFilter: ["data-theme"]
4295
+ }), Pt(e);
4296
+ }
4297
+ class Pr {
4298
+ path;
4299
+ canvasWorker;
4300
+ canvasBound = !1;
4301
+ constructor(t) {
4302
+ this.path = t.preferredPath, this.canvasWorker = t.canvasWorker ?? null;
4303
+ }
4304
+ get effectivePath() {
4305
+ return this.path === "canvas" && this.canvasBound && this.canvasWorker || this.path === "auto" && this.canvasBound && this.canvasWorker ? "canvas" : "dom";
4306
+ }
4307
+ /**
4308
+ * Bind a <canvas> element for off-thread overlay rendering.
4309
+ * Must be called before canvas path can be used.
4310
+ */
4311
+ async bindCanvas(t, r) {
4312
+ if (!this.canvasWorker) {
4313
+ console.warn("[OverlayManager] No canvas worker available");
4314
+ return;
4315
+ }
4316
+ const n = t.transferControlToOffscreen();
4317
+ await this.canvasWorker.bindUICanvas(n, r), this.canvasBound = !0;
4318
+ }
4319
+ // ── Toast ──
4320
+ toast(t) {
4321
+ this.effectivePath === "canvas" && this.canvasWorker?.addCanvasToast(t), ie(t);
4322
+ }
4323
+ dismissToast(t) {
4324
+ this.effectivePath === "canvas" && this.canvasWorker?.removeCanvasToast(t), _r(t);
4325
+ }
4326
+ // ── Tooltip ──
4327
+ showTooltip(t) {
4328
+ this.effectivePath === "canvas" && this.canvasWorker?.showCanvasTooltip(t), br(t.id);
4329
+ }
4330
+ hideTooltip(t) {
4331
+ this.effectivePath === "canvas" && this.canvasWorker?.showCanvasTooltip(null), Sr(t);
4332
+ }
4333
+ // ── Modal ──
4334
+ showModal(t) {
4335
+ this.effectivePath === "canvas" && this.canvasWorker?.showCanvasModal(t), zr(t.id);
4336
+ }
4337
+ hideModal(t) {
4338
+ this.effectivePath === "canvas" && this.canvasWorker?.showCanvasModal(null), Er(t);
4339
+ }
4340
+ /** Switch rendering path at runtime */
4341
+ setPath(t) {
4342
+ this.path = t;
4343
+ }
4344
+ /** Unbind canvas and clean up */
4345
+ async destroy() {
4346
+ this.canvasBound && this.canvasWorker && (await this.canvasWorker.unbindUICanvas(), this.canvasBound = !1);
4347
+ }
4348
+ }
4349
+ const Wr = {
4350
+ tone: "loading",
4351
+ name: "",
4352
+ avatar: void 0,
4353
+ id: "",
4354
+ error: void 0
4355
+ }, Q = /* @__PURE__ */ Je({ ...Wr });
4356
+ function Tc(e) {
4357
+ const t = Q.get();
4358
+ Q.set({ ...t, ...e });
4359
+ }
4360
+ function $c() {
4361
+ Q.set({ ...Wr, tone: "anon" });
4362
+ }
4363
+ const Zr = "kbve:welcome-shown";
4364
+ function Wt() {
4365
+ try {
4366
+ return sessionStorage.getItem(Zr) === "1";
4367
+ } catch {
4368
+ return !1;
4369
+ }
4370
+ }
4371
+ function ye() {
4372
+ try {
4373
+ sessionStorage.setItem(Zr, "1");
4374
+ } catch {
4375
+ }
4376
+ }
4377
+ function lc() {
4378
+ if (Wt()) return;
4379
+ const e = () => {
4380
+ const n = Q.get();
4381
+ return n.tone === "auth" && n.name ? (ye(), ie({
4382
+ id: `welcome-${Date.now()}`,
4383
+ message: `Welcome back, ${n.name}`,
4384
+ severity: "success",
4385
+ duration: 4e3
4386
+ }), !0) : n.tone === "anon" ? (ye(), ie({
4387
+ id: `welcome-${Date.now()}`,
4388
+ message: "Welcome!",
4389
+ severity: "info",
4390
+ duration: 3e3
4391
+ }), !0) : n.tone === "error" ? (ye(), !0) : !1;
4392
+ };
4393
+ if (e()) return;
4394
+ const t = setTimeout(() => {
4395
+ r(), Wt() || (ye(), ie({
4396
+ id: `welcome-${Date.now()}`,
4397
+ message: "Welcome!",
4398
+ severity: "info",
4399
+ duration: 3e3
4400
+ }));
4401
+ }, 1e4), r = Q.subscribe(() => {
4402
+ Q.get().tone !== "loading" && (clearTimeout(t), r(), e());
4403
+ });
4404
+ }
4405
+ const Zt = "1.0.3";
4406
+ let Rt = !1, re = null, ce = "full";
4407
+ const T = {};
4408
+ function dc() {
4409
+ return ce;
4410
+ }
4411
+ async function fc() {
4412
+ if (ce === "minimal") {
4413
+ console.log("[DROID] Already in minimal mode");
4414
+ return;
4415
+ }
4416
+ if (console.log("[DROID] Downscaling to minimal mode..."), window.kbve?.overlay) {
4417
+ try {
4418
+ await window.kbve.overlay.destroy();
4419
+ } catch (e) {
4420
+ console.warn("[DROID] Overlay destroy error:", e);
4421
+ }
4422
+ delete window.kbve.overlay;
4423
+ }
4424
+ if (window.kbve?.mod) {
4425
+ const e = window.kbve.mod;
4426
+ for (const t of Object.values(e.registry))
4427
+ try {
4428
+ e.unload(t.id);
4429
+ } catch (r) {
4430
+ console.warn("[DROID] Mod unload error:", r);
4431
+ }
4432
+ }
4433
+ if (window.kbve?.gateway) {
4434
+ try {
4435
+ window.kbve.gateway.terminate();
4436
+ } catch (e) {
4437
+ console.warn("[DROID] Gateway terminate error:", e);
4438
+ }
4439
+ delete window.kbve.gateway;
4440
+ }
4441
+ if (T.canvasWorkerRaw) {
4442
+ try {
4443
+ T.canvasWorkerRaw.terminate();
4444
+ } catch (e) {
4445
+ console.warn("[DROID] Canvas worker terminate error:", e);
4446
+ }
4447
+ T.canvasWorkerRaw = void 0, T.canvasWorkerProxy = void 0, window.kbve?.uiux && (window.kbve.uiux.worker = void 0);
4448
+ }
4449
+ ce = "minimal", window.kbve?.events?.emit("droid-downscale", {
4450
+ timestamp: Date.now(),
4451
+ level: "minimal"
4452
+ }), console.log("[DROID] Downscaled to minimal mode (DB + WS workers active)");
4453
+ }
4454
+ async function hc() {
4455
+ if (ce === "full") {
4456
+ console.log("[DROID] Already in full mode");
4457
+ return;
4458
+ }
4459
+ console.log("[DROID] Upscaling to full mode...");
4460
+ try {
4461
+ const e = Ar(
4462
+ "canvas-worker",
4463
+ T.canvasWorkerOpts
4464
+ );
4465
+ T.canvasWorkerRaw = e;
4466
+ const t = ue(e);
4467
+ if (T.canvasWorkerProxy = t, window.kbve?.uiux && (window.kbve.uiux.worker = t), window.kbve?.mod) {
4468
+ const n = await Ct(T.modInitOpts?.resolver);
4469
+ window.kbve.mod = n;
4470
+ }
4471
+ if (T.gatewayConfig) {
4472
+ const n = new Or(T.gatewayConfig);
4473
+ window.kbve.gateway = n;
4474
+ }
4475
+ const r = new Pr({
4476
+ preferredPath: "auto",
4477
+ canvasWorker: t
4478
+ });
4479
+ window.kbve.overlay = r, ce = "full", window.kbve?.events?.emit("droid-upscale", {
4480
+ timestamp: Date.now(),
4481
+ level: "full"
4482
+ }), console.log("[DROID] Upscaled to full mode");
4483
+ } catch (e) {
4484
+ throw console.error("[DROID] Upscale failed:", e), e;
4485
+ }
4486
+ }
4487
+ function Rr(e, t) {
4488
+ if (!e)
4489
+ throw new Error("[resolveWorkerURL] Worker name must be defined");
4490
+ if (typeof window < "u") {
4491
+ const r = window.kbveWorkerURLs;
4492
+ if (r?.[e]) return r[e];
4493
+ }
4494
+ return t ?? `/workers/${e}`;
4495
+ }
4496
+ function Ir(e, t) {
4497
+ if (t?.workerRef)
4498
+ return t.workerRef.port.start(), t.workerRef;
4499
+ const r = t?.workerURL ?? Rr(e), n = new SharedWorker(r, { type: "module" });
4500
+ return n.port.start(), window.addEventListener("beforeunload", () => {
4501
+ n.port.postMessage({ type: "close" });
4502
+ }), n;
4503
+ }
4504
+ function Ar(e, t) {
4505
+ if (t?.workerRef) return t.workerRef;
4506
+ const r = t?.workerURL ?? Rr(e);
4507
+ return new Worker(r, { type: "module" });
4508
+ }
4509
+ function Nr(e) {
4510
+ return new Promise((t) => {
4511
+ const r = (n) => {
4512
+ n.data?.type === "first-connect" ? (t(!0), e.removeEventListener("message", r)) : n.data?.type === "reconnect" && (t(!1), e.removeEventListener("message", r));
4513
+ };
4514
+ e.addEventListener("message", r), setTimeout(() => {
4515
+ e.removeEventListener("message", r), t(!1);
4516
+ }, 5e3);
4517
+ });
4518
+ }
4519
+ async function pc(e) {
4520
+ const t = Ir("db-worker", e), r = Nr(t.port), n = ue(t.port), o = await gc(n, {
4521
+ i18nPath: e?.i18nPath,
4522
+ dataPath: e?.dataPath
4523
+ }), i = await r;
4524
+ return { api: o, isFirstConnection: i };
4525
+ }
4526
+ async function mc(e) {
4527
+ const t = Ir("ws-worker", e), r = Nr(t.port), n = ue(t.port), o = await r;
4528
+ return { ws: n, isFirstConnection: o };
4529
+ }
4530
+ async function wc(e) {
4531
+ const t = Ar("canvas-worker", e);
4532
+ return { proxy: ue(t), raw: t };
4533
+ }
4534
+ async function gc(e, t) {
4535
+ return await e.getVersion() !== Zt && await Vr(e, {
4536
+ version: Zt,
4537
+ i18nPath: t?.i18nPath,
4538
+ dataPath: t?.dataPath,
4539
+ locale: "en",
4540
+ defaults: { welcome: "Welcome!", theme: "dark" }
4541
+ }), e;
4542
+ }
4543
+ const P = Dt(
4544
+ "uiux-state",
4545
+ {
4546
+ panelManager: {
4547
+ top: { open: !1 },
4548
+ right: { open: !1 },
4549
+ bottom: { open: !1 },
4550
+ left: { open: !1 }
4551
+ },
4552
+ themeManager: { theme: "auto" },
4553
+ toastManager: {},
4554
+ scrollY: 0
4555
+ },
4556
+ {
4557
+ encode: JSON.stringify,
4558
+ decode: JSON.parse
4559
+ }
4560
+ ), It = {
4561
+ state: P,
4562
+ openPanel(e, t) {
4563
+ const r = { ...P.get().panelManager };
4564
+ r[e] = { open: !0, payload: t }, P.setKey("panelManager", r), D.emit("panel-open", { id: e, payload: t });
4565
+ },
4566
+ closePanel(e) {
4567
+ const t = { ...P.get().panelManager };
4568
+ t[e] = { open: !1, payload: void 0 }, P.setKey("panelManager", t), D.emit("panel-close", { id: e });
4569
+ },
4570
+ togglePanel(e, t) {
4571
+ const r = { ...P.get().panelManager }, n = r[e]?.open ?? !1;
4572
+ r[e] = { open: !n, payload: n ? void 0 : t }, P.setKey("panelManager", r), n ? D.emit("panel-close", { id: e }) : D.emit("panel-open", { id: e, payload: t });
4573
+ },
4574
+ setTheme(e) {
4575
+ P.setKey("themeManager", { theme: e });
4576
+ },
4577
+ /** @deprecated Use addToast() from '@kbve/droid' state exports instead. */
4578
+ addToast(e, t) {
4579
+ console.warn(
4580
+ "[KBVE] uiux.addToast is deprecated. Use addToast() from @kbve/droid."
4581
+ );
4582
+ const r = { ...P.get().toastManager, [e]: t };
4583
+ P.setKey("toastManager", r);
4584
+ },
4585
+ /** @deprecated Use removeToast() from '@kbve/droid' state exports instead. */
4586
+ removeToast(e) {
4587
+ console.warn(
4588
+ "[KBVE] uiux.removeToast is deprecated. Use removeToast() from @kbve/droid."
4589
+ );
4590
+ const t = { ...P.get().toastManager };
4591
+ delete t[e], P.setKey("toastManager", t);
4592
+ },
4593
+ async dispatchCanvasRequest(e, t, r = "animated") {
4594
+ const n = t.transferControlToOffscreen();
4595
+ await window.kbve?.uiux?.worker?.bindCanvas(e, n, r);
4596
+ },
4597
+ closeAllPanels() {
4598
+ const e = { ...P.get().panelManager };
4599
+ for (const t of Object.keys(e))
4600
+ e[t] = { open: !1, payload: void 0 };
4601
+ P.setKey("panelManager", e);
4602
+ },
4603
+ emitFromWorker(e) {
4604
+ if (e.type === "injectVNode") {
4605
+ const t = e.vnode;
4606
+ if (!t) return;
4607
+ Mt(() => {
4608
+ const r = document.getElementById("bento-grid-inject");
4609
+ if (!r) {
4610
+ console.warn(
4611
+ "[KBVE] No injection target found: #bento-grid-inject"
4612
+ );
4613
+ return;
4614
+ }
4615
+ const n = Ft(t);
4616
+ if (n.classList.add("animate-fade-in"), t.id) {
4617
+ const o = document.getElementById(t.id);
4618
+ o && o.remove();
4619
+ }
4620
+ r.appendChild(n);
4621
+ });
4622
+ return;
4623
+ }
4624
+ if (e.type === "toast" && e.payload) {
4625
+ const t = Fe.safeParse(e.payload);
4626
+ if (!t.success) {
4627
+ console.error(
4628
+ "[KBVE] Invalid toast payload from worker:",
4629
+ t.error
4630
+ );
4631
+ return;
4632
+ }
4633
+ ie(t.data);
4634
+ return;
4635
+ }
4636
+ if (e.type === "toast-remove") {
4637
+ const t = e.payload;
4638
+ t?.id && _r(t.id);
4639
+ return;
4640
+ }
4641
+ if (e.type === "tooltip-open" && e.payload) {
4642
+ const t = xe.safeParse(e.payload);
4643
+ if (!t.success) {
4644
+ console.error(
4645
+ "[KBVE] Invalid tooltip payload from worker:",
4646
+ t.error
4647
+ );
4648
+ return;
4649
+ }
4650
+ br(t.data.id);
4651
+ return;
4652
+ }
4653
+ if (e.type === "tooltip-close") {
4654
+ const t = e.payload;
4655
+ Sr(t?.id);
4656
+ return;
4657
+ }
4658
+ if (e.type === "modal-open" && e.payload) {
4659
+ const t = Be.safeParse(e.payload);
4660
+ if (!t.success) {
4661
+ console.error(
4662
+ "[KBVE] Invalid modal payload from worker:",
4663
+ t.error
4664
+ );
4665
+ return;
4666
+ }
4667
+ zr(t.data.id);
4668
+ return;
4669
+ }
4670
+ if (e.type === "modal-close") {
4671
+ const t = e.payload;
4672
+ Er(t?.id);
4673
+ return;
4674
+ }
4675
+ console.warn("[KBVE] Unknown worker UI message type:", e.type);
4676
+ }
4677
+ }, H = Dt(
4678
+ "i18n-cache",
4679
+ {},
4680
+ {
4681
+ encode: JSON.stringify,
4682
+ decode: JSON.parse
4683
+ }
4684
+ ), ne = {
4685
+ store: H,
4686
+ api: null,
4687
+ ready: Promise.resolve(),
4688
+ get(e) {
4689
+ return H.get()[e] ?? `[${e}]`;
4690
+ },
4691
+ async getAsync(e) {
4692
+ const t = H.get()[e];
4693
+ if (t !== void 0) return t;
4694
+ if (!this.api) return `[${e}]`;
4695
+ const r = await this.api.getTranslation(e);
4696
+ return r !== null ? (H.setKey(e, r), r) : `[${e}]`;
4697
+ },
4698
+ set(e, t) {
4699
+ H.setKey(e, t);
4700
+ },
4701
+ async hydrate(e, t) {
4702
+ this.api = e;
4703
+ for (const r of t) {
4704
+ const n = await e.getTranslation(r);
4705
+ n !== null && H.setKey(r, n);
4706
+ }
4707
+ },
4708
+ async hydrateLocale(e = "en") {
4709
+ if (!this.api) return;
4710
+ const r = (await this.api.getAllI18nKeys()).filter(
4711
+ (o) => o.startsWith(`${e}:`)
4712
+ ), n = await this.api.getTranslations(r);
4713
+ for (const [o, i] of Object.entries(n))
4714
+ this.store.setKey(o, i);
4715
+ }
4716
+ };
4717
+ function At() {
4718
+ if (!navigator.serviceWorker?.controller) return;
4719
+ const e = new MessageChannel();
4720
+ navigator.serviceWorker.controller.postMessage(e.port2, [
4721
+ e.port2
4722
+ ]), e.port1.start();
4723
+ }
4724
+ function yc(e, t) {
4725
+ const r = Ur(async (n) => {
4726
+ typeof n != "string" && Mt(() => {
4727
+ const o = `ws:${Date.now()}`;
4728
+ t.storeWsMessage(o, n);
4729
+ });
4730
+ });
4731
+ e.onMessage(r);
4732
+ }
4733
+ async function Oc(e) {
4734
+ if (console.log("[DROID]: Main<T>"), Rt || (Rt = !0, navigator.serviceWorker?.controller ? At() : navigator.serviceWorker?.addEventListener(
4735
+ "controllerchange",
4736
+ At
4737
+ )), re) {
4738
+ await re;
4739
+ return;
4740
+ }
4741
+ !window.kbve?.api || !window.kbve?.i18n || !window.kbve?.uiux ? (lc(), re = (async () => {
4742
+ try {
4743
+ console.log("[DROID] Initializing workers...");
4744
+ const r = {
4745
+ workerRef: e?.workerRefs?.canvasWorker,
4746
+ workerURL: e?.workerURLs?.canvasWorker
4747
+ }, { proxy: n, raw: o } = await wc(r);
4748
+ T.canvasWorkerRaw = o, T.canvasWorkerProxy = n, T.canvasWorkerOpts = r;
4749
+ const { api: i, isFirstConnection: s } = await pc({
4750
+ workerURL: typeof e?.workerURLs?.dbWorker == "string" ? e.workerURLs.dbWorker : void 0,
4751
+ workerRef: e?.workerRefs?.dbWorker,
4752
+ i18nPath: e?.i18nPath,
4753
+ dataPath: e?.dataPath
4754
+ }), { ws: a, isFirstConnection: c } = await mc({
4755
+ workerRef: e?.workerRefs?.wsWorker,
4756
+ workerURL: e?.workerURLs?.wsWorker
4757
+ }), u = s && c;
4758
+ console.log("[DROID] Initializing mod manager...");
4759
+ const f = (I) => e?.workerURLs?.[I] ?? I;
4760
+ T.modInitOpts = { resolver: f };
4761
+ const d = await Ct(f), h = D;
4762
+ for (const I of Object.values(d.registry))
4763
+ typeof I.instance.init == "function" && await I.instance.init({
4764
+ emitFromWorker: (Re) => It.emitFromWorker(Re)
4765
+ }), h.emit("droid-mod-ready", {
4766
+ meta: I.meta,
4767
+ timestamp: Date.now()
4768
+ });
4769
+ yc(a, i);
4770
+ const m = tn;
4771
+ ne.api = i, ne.ready = ne.hydrateLocale("en");
4772
+ let S;
4773
+ e?.gateway && (console.log("[DROID] Initializing SupabaseGateway..."), T.gatewayConfig = e.gateway, S = new Or(e.gateway));
4774
+ const z = new Pr({
4775
+ preferredPath: "auto",
4776
+ canvasWorker: n
4777
+ });
4778
+ window.kbve = {
4779
+ ...window.kbve || {},
4780
+ api: i,
4781
+ i18n: ne,
4782
+ uiux: { ...It, worker: n },
4783
+ ws: a,
4784
+ data: m,
4785
+ mod: d,
4786
+ events: h,
4787
+ overlay: z,
4788
+ downscale: fc,
4789
+ upscale: hc,
4790
+ scaleLevel: dc,
4791
+ ...S ? { gateway: S } : {}
4792
+ }, uc(i), await ne.ready, window.kbve.events.emit("droid-ready", {
4793
+ timestamp: Date.now()
4794
+ }), document.addEventListener("astro:page-load", () => {
4795
+ console.debug(
4796
+ "[KBVE] Re-dispatched droid-ready after astro:page-load"
4797
+ ), window.kbve?.events.emit("droid-ready", {
4798
+ timestamp: Date.now()
4799
+ });
4800
+ }), u && h.emit("droid-first-connect", {
4801
+ timestamp: Date.now(),
4802
+ workersFirst: { db: s, ws: c }
4803
+ }), console.log("[KBVE] Global API ready");
4804
+ } catch (r) {
4805
+ throw re = null, console.error("[DROID] Initialization error:", r), r;
4806
+ }
4807
+ })(), await re) : console.log("[KBVE] Already initialized");
4808
+ }
4809
+ export {
4810
+ K as $,
4811
+ Ga as A,
4812
+ $r as B,
4813
+ Ja as C,
4814
+ ic as D,
4815
+ ie as E,
4816
+ cc as F,
4817
+ Ec as G,
4818
+ Er as H,
4819
+ Sr as I,
4820
+ Tr as J,
4821
+ fc as K,
4822
+ dc as L,
4823
+ Be as M,
4824
+ Tt as N,
4825
+ Pr as O,
4826
+ Et as P,
4827
+ nc as Q,
4828
+ uc as R,
4829
+ oc as S,
4830
+ xe as T,
4831
+ zc as U,
4832
+ Ze as V,
4833
+ sc as W,
4834
+ zr as X,
4835
+ br as Y,
4836
+ _r as Z,
4837
+ de as _,
4838
+ Qe as a,
4839
+ $c as a0,
4840
+ rc as a1,
4841
+ Tc as a2,
4842
+ lc as a3,
4843
+ Pt as a4,
4844
+ hc as a5,
4845
+ yc as a6,
4846
+ ne as a7,
4847
+ Oc as a8,
4848
+ Rr as a9,
4849
+ It as aa,
4850
+ je as b,
4851
+ Te as c,
4852
+ Fe as d,
4853
+ Ot as e,
4854
+ $t as f,
4855
+ Q as g,
4856
+ tt as h,
4857
+ ve as i,
4858
+ Ee as j,
4859
+ Ka as k,
4860
+ ec as l,
4861
+ D as m,
4862
+ x as n,
4863
+ W as o,
4864
+ qa as p,
4865
+ Ya as q,
4866
+ Le as r,
4867
+ _ as s,
4868
+ Xa as t,
4869
+ Qa as u,
4870
+ Ha as v,
4871
+ Ba as w,
4872
+ Sc as x,
4873
+ Or as y,
4874
+ Va as z
4875
+ };