@autogames/sdk 1.2.3 → 1.4.0

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.
@@ -1,2748 +0,0 @@
1
- import { jsx as l, jsxs as M } from "react/jsx-runtime";
2
- import * as $ from "react";
3
- import { forwardRef as It, createElement as bt, useMemo as Tt, useRef as j, useReducer as Qe, useLayoutEffect as xt, useEffect as wt, useImperativeHandle as $e, memo as Le, useState as oe, useCallback as Kt, StrictMode as qe } from "react";
4
- import { c as Ue } from "./client-CgE37lov.js";
5
- import { flushSync as _e } from "react-dom";
6
- import { a as Ft, A as ce, u as gt } from "./main-BGvL9KWK.js";
7
- var et = class {
8
- constructor() {
9
- this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
10
- }
11
- subscribe(t) {
12
- return this.listeners.add(t), this.onSubscribe(), () => {
13
- this.listeners.delete(t), this.onUnsubscribe();
14
- };
15
- }
16
- hasListeners() {
17
- return this.listeners.size > 0;
18
- }
19
- onSubscribe() {
20
- }
21
- onUnsubscribe() {
22
- }
23
- }, je = {
24
- // We need the wrapper function syntax below instead of direct references to
25
- // global setTimeout etc.
26
- //
27
- // BAD: `setTimeout: setTimeout`
28
- // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
29
- //
30
- // If we use direct references here, then anything that wants to spy on or
31
- // replace the global setTimeout (like tests) won't work since we'll already
32
- // have a hard reference to the original implementation at the time when this
33
- // file was imported.
34
- setTimeout: (t, e) => setTimeout(t, e),
35
- clearTimeout: (t) => clearTimeout(t),
36
- setInterval: (t, e) => setInterval(t, e),
37
- clearInterval: (t) => clearInterval(t)
38
- }, Ke = class {
39
- // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
40
- // type at app boot; and if we leave that type, then any new timer provider
41
- // would need to support ReturnType<typeof setTimeout>, which is infeasible.
42
- //
43
- // We settle for type safety for the TimeoutProvider type, and accept that
44
- // this class is unsafe internally to allow for extension.
45
- #t = je;
46
- #e = !1;
47
- setTimeoutProvider(t) {
48
- this.#t = t;
49
- }
50
- setTimeout(t, e) {
51
- return this.#t.setTimeout(t, e);
52
- }
53
- clearTimeout(t) {
54
- this.#t.clearTimeout(t);
55
- }
56
- setInterval(t, e) {
57
- return this.#t.setInterval(t, e);
58
- }
59
- clearInterval(t) {
60
- this.#t.clearInterval(t);
61
- }
62
- }, V = new Ke();
63
- function ze(t) {
64
- setTimeout(t, 0);
65
- }
66
- var X = typeof window > "u" || "Deno" in globalThis;
67
- function U() {
68
- }
69
- function Be(t, e) {
70
- return typeof t == "function" ? t(e) : t;
71
- }
72
- function Ct(t) {
73
- return typeof t == "number" && t >= 0 && t !== 1 / 0;
74
- }
75
- function ue(t, e) {
76
- return Math.max(t + (e || 0) - Date.now(), 0);
77
- }
78
- function W(t, e) {
79
- return typeof t == "function" ? t(e) : t;
80
- }
81
- function z(t, e) {
82
- return typeof t == "function" ? t(e) : t;
83
- }
84
- function zt(t, e) {
85
- const {
86
- type: s = "all",
87
- exact: r,
88
- fetchStatus: i,
89
- predicate: n,
90
- queryKey: o,
91
- stale: a
92
- } = t;
93
- if (o) {
94
- if (r) {
95
- if (e.queryHash !== At(o, e.options))
96
- return !1;
97
- } else if (!it(e.queryKey, o))
98
- return !1;
99
- }
100
- if (s !== "all") {
101
- const u = e.isActive();
102
- if (s === "active" && !u || s === "inactive" && u)
103
- return !1;
104
- }
105
- return !(typeof a == "boolean" && e.isStale() !== a || i && i !== e.state.fetchStatus || n && !n(e));
106
- }
107
- function Bt(t, e) {
108
- const { exact: s, status: r, predicate: i, mutationKey: n } = t;
109
- if (n) {
110
- if (!e.options.mutationKey)
111
- return !1;
112
- if (s) {
113
- if (J(e.options.mutationKey) !== J(n))
114
- return !1;
115
- } else if (!it(e.options.mutationKey, n))
116
- return !1;
117
- }
118
- return !(r && e.state.status !== r || i && !i(e));
119
- }
120
- function At(t, e) {
121
- return (e?.queryKeyHashFn || J)(t);
122
- }
123
- function J(t) {
124
- return JSON.stringify(
125
- t,
126
- (e, s) => St(s) ? Object.keys(s).sort().reduce((r, i) => (r[i] = s[i], r), {}) : s
127
- );
128
- }
129
- function it(t, e) {
130
- return t === e ? !0 : typeof t != typeof e ? !1 : t && e && typeof t == "object" && typeof e == "object" ? Object.keys(e).every((s) => it(t[s], e[s])) : !1;
131
- }
132
- var He = Object.prototype.hasOwnProperty;
133
- function he(t, e) {
134
- if (t === e)
135
- return t;
136
- const s = Ht(t) && Ht(e);
137
- if (!s && !(St(t) && St(e))) return e;
138
- const i = (s ? t : Object.keys(t)).length, n = s ? e : Object.keys(e), o = n.length, a = s ? new Array(o) : {};
139
- let u = 0;
140
- for (let h = 0; h < o; h++) {
141
- const c = s ? h : n[h], f = t[c], d = e[c];
142
- if (f === d) {
143
- a[c] = f, (s ? h < i : He.call(t, c)) && u++;
144
- continue;
145
- }
146
- if (f === null || d === null || typeof f != "object" || typeof d != "object") {
147
- a[c] = d;
148
- continue;
149
- }
150
- const C = he(f, d);
151
- a[c] = C, C === f && u++;
152
- }
153
- return i === o && u === i ? t : a;
154
- }
155
- function lt(t, e) {
156
- if (!e || Object.keys(t).length !== Object.keys(e).length)
157
- return !1;
158
- for (const s in t)
159
- if (t[s] !== e[s])
160
- return !1;
161
- return !0;
162
- }
163
- function Ht(t) {
164
- return Array.isArray(t) && t.length === Object.keys(t).length;
165
- }
166
- function St(t) {
167
- if (!Gt(t))
168
- return !1;
169
- const e = t.constructor;
170
- if (e === void 0)
171
- return !0;
172
- const s = e.prototype;
173
- return !(!Gt(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(t) !== Object.prototype);
174
- }
175
- function Gt(t) {
176
- return Object.prototype.toString.call(t) === "[object Object]";
177
- }
178
- function Ge(t) {
179
- return new Promise((e) => {
180
- V.setTimeout(e, t);
181
- });
182
- }
183
- function Ot(t, e, s) {
184
- return typeof s.structuralSharing == "function" ? s.structuralSharing(t, e) : s.structuralSharing !== !1 ? he(t, e) : e;
185
- }
186
- function We(t, e, s = 0) {
187
- const r = [...t, e];
188
- return s && r.length > s ? r.slice(1) : r;
189
- }
190
- function Ve(t, e, s = 0) {
191
- const r = [e, ...t];
192
- return s && r.length > s ? r.slice(0, -1) : r;
193
- }
194
- var Dt = Symbol();
195
- function le(t, e) {
196
- return !t.queryFn && e?.initialPromise ? () => e.initialPromise : !t.queryFn || t.queryFn === Dt ? () => Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)) : t.queryFn;
197
- }
198
- function de(t, e) {
199
- return typeof t == "function" ? t(...e) : !!t;
200
- }
201
- var Ye = class extends et {
202
- #t;
203
- #e;
204
- #s;
205
- constructor() {
206
- super(), this.#s = (t) => {
207
- if (!X && window.addEventListener) {
208
- const e = () => t();
209
- return window.addEventListener("visibilitychange", e, !1), () => {
210
- window.removeEventListener("visibilitychange", e);
211
- };
212
- }
213
- };
214
- }
215
- onSubscribe() {
216
- this.#e || this.setEventListener(this.#s);
217
- }
218
- onUnsubscribe() {
219
- this.hasListeners() || (this.#e?.(), this.#e = void 0);
220
- }
221
- setEventListener(t) {
222
- this.#s = t, this.#e?.(), this.#e = t((e) => {
223
- typeof e == "boolean" ? this.setFocused(e) : this.onFocus();
224
- });
225
- }
226
- setFocused(t) {
227
- this.#t !== t && (this.#t = t, this.onFocus());
228
- }
229
- onFocus() {
230
- const t = this.isFocused();
231
- this.listeners.forEach((e) => {
232
- e(t);
233
- });
234
- }
235
- isFocused() {
236
- return typeof this.#t == "boolean" ? this.#t : globalThis.document?.visibilityState !== "hidden";
237
- }
238
- }, Qt = new Ye();
239
- function kt() {
240
- let t, e;
241
- const s = new Promise((i, n) => {
242
- t = i, e = n;
243
- });
244
- s.status = "pending", s.catch(() => {
245
- });
246
- function r(i) {
247
- Object.assign(s, i), delete s.resolve, delete s.reject;
248
- }
249
- return s.resolve = (i) => {
250
- r({
251
- status: "fulfilled",
252
- value: i
253
- }), t(i);
254
- }, s.reject = (i) => {
255
- r({
256
- status: "rejected",
257
- reason: i
258
- }), e(i);
259
- }, s;
260
- }
261
- var Xe = ze;
262
- function Je() {
263
- let t = [], e = 0, s = (a) => {
264
- a();
265
- }, r = (a) => {
266
- a();
267
- }, i = Xe;
268
- const n = (a) => {
269
- e ? t.push(a) : i(() => {
270
- s(a);
271
- });
272
- }, o = () => {
273
- const a = t;
274
- t = [], a.length && i(() => {
275
- r(() => {
276
- a.forEach((u) => {
277
- s(u);
278
- });
279
- });
280
- });
281
- };
282
- return {
283
- batch: (a) => {
284
- let u;
285
- e++;
286
- try {
287
- u = a();
288
- } finally {
289
- e--, e || o();
290
- }
291
- return u;
292
- },
293
- /**
294
- * All calls to the wrapped function will be batched.
295
- */
296
- batchCalls: (a) => (...u) => {
297
- n(() => {
298
- a(...u);
299
- });
300
- },
301
- schedule: n,
302
- /**
303
- * Use this method to set a custom notify function.
304
- * This can be used to for example wrap notifications with `React.act` while running tests.
305
- */
306
- setNotifyFunction: (a) => {
307
- s = a;
308
- },
309
- /**
310
- * Use this method to set a custom function to batch notifications together into a single tick.
311
- * By default React Query will use the batch function provided by ReactDOM or React Native.
312
- */
313
- setBatchNotifyFunction: (a) => {
314
- r = a;
315
- },
316
- setScheduler: (a) => {
317
- i = a;
318
- }
319
- };
320
- }
321
- var A = Je(), Ze = class extends et {
322
- #t = !0;
323
- #e;
324
- #s;
325
- constructor() {
326
- super(), this.#s = (t) => {
327
- if (!X && window.addEventListener) {
328
- const e = () => t(!0), s = () => t(!1);
329
- return window.addEventListener("online", e, !1), window.addEventListener("offline", s, !1), () => {
330
- window.removeEventListener("online", e), window.removeEventListener("offline", s);
331
- };
332
- }
333
- };
334
- }
335
- onSubscribe() {
336
- this.#e || this.setEventListener(this.#s);
337
- }
338
- onUnsubscribe() {
339
- this.hasListeners() || (this.#e?.(), this.#e = void 0);
340
- }
341
- setEventListener(t) {
342
- this.#s = t, this.#e?.(), this.#e = t(this.setOnline.bind(this));
343
- }
344
- setOnline(t) {
345
- this.#t !== t && (this.#t = t, this.listeners.forEach((s) => {
346
- s(t);
347
- }));
348
- }
349
- isOnline() {
350
- return this.#t;
351
- }
352
- }, dt = new Ze();
353
- function ts(t) {
354
- return Math.min(1e3 * 2 ** t, 3e4);
355
- }
356
- function fe(t) {
357
- return (t ?? "online") === "online" ? dt.isOnline() : !0;
358
- }
359
- var Pt = class extends Error {
360
- constructor(t) {
361
- super("CancelledError"), this.revert = t?.revert, this.silent = t?.silent;
362
- }
363
- };
364
- function pe(t) {
365
- let e = !1, s = 0, r;
366
- const i = kt(), n = () => i.status !== "pending", o = (p) => {
367
- if (!n()) {
368
- const y = new Pt(p);
369
- d(y), t.onCancel?.(y);
370
- }
371
- }, a = () => {
372
- e = !0;
373
- }, u = () => {
374
- e = !1;
375
- }, h = () => Qt.isFocused() && (t.networkMode === "always" || dt.isOnline()) && t.canRun(), c = () => fe(t.networkMode) && t.canRun(), f = (p) => {
376
- n() || (r?.(), i.resolve(p));
377
- }, d = (p) => {
378
- n() || (r?.(), i.reject(p));
379
- }, C = () => new Promise((p) => {
380
- r = (y) => {
381
- (n() || h()) && p(y);
382
- }, t.onPause?.();
383
- }).then(() => {
384
- r = void 0, n() || t.onContinue?.();
385
- }), g = () => {
386
- if (n())
387
- return;
388
- let p;
389
- const y = s === 0 ? t.initialPromise : void 0;
390
- try {
391
- p = y ?? t.fn();
392
- } catch (b) {
393
- p = Promise.reject(b);
394
- }
395
- Promise.resolve(p).then(f).catch((b) => {
396
- if (n())
397
- return;
398
- const R = t.retry ?? (X ? 0 : 3), P = t.retryDelay ?? ts, D = typeof P == "function" ? P(s, b) : P, L = R === !0 || typeof R == "number" && s < R || typeof R == "function" && R(s, b);
399
- if (e || !L) {
400
- d(b);
401
- return;
402
- }
403
- s++, t.onFail?.(s, b), Ge(D).then(() => h() ? void 0 : C()).then(() => {
404
- e ? d(b) : g();
405
- });
406
- });
407
- };
408
- return {
409
- promise: i,
410
- status: () => i.status,
411
- cancel: o,
412
- continue: () => (r?.(), i),
413
- cancelRetry: a,
414
- continueRetry: u,
415
- canStart: c,
416
- start: () => (c() ? g() : C().then(g), i)
417
- };
418
- }
419
- var me = class {
420
- #t;
421
- destroy() {
422
- this.clearGcTimeout();
423
- }
424
- scheduleGc() {
425
- this.clearGcTimeout(), Ct(this.gcTime) && (this.#t = V.setTimeout(() => {
426
- this.optionalRemove();
427
- }, this.gcTime));
428
- }
429
- updateGcTime(t) {
430
- this.gcTime = Math.max(
431
- this.gcTime || 0,
432
- t ?? (X ? 1 / 0 : 300 * 1e3)
433
- );
434
- }
435
- clearGcTimeout() {
436
- this.#t && (V.clearTimeout(this.#t), this.#t = void 0);
437
- }
438
- }, es = class extends me {
439
- #t;
440
- #e;
441
- #s;
442
- #i;
443
- #r;
444
- #a;
445
- #o;
446
- constructor(t) {
447
- super(), this.#o = !1, this.#a = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#i = t.client, this.#s = this.#i.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#t = Vt(this.options), this.state = t.state ?? this.#t, this.scheduleGc();
448
- }
449
- get meta() {
450
- return this.options.meta;
451
- }
452
- get promise() {
453
- return this.#r?.promise;
454
- }
455
- setOptions(t) {
456
- if (this.options = { ...this.#a, ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
457
- const e = Vt(this.options);
458
- e.data !== void 0 && (this.setState(
459
- Wt(e.data, e.dataUpdatedAt)
460
- ), this.#t = e);
461
- }
462
- }
463
- optionalRemove() {
464
- !this.observers.length && this.state.fetchStatus === "idle" && this.#s.remove(this);
465
- }
466
- setData(t, e) {
467
- const s = Ot(this.state.data, t, this.options);
468
- return this.#n({
469
- data: s,
470
- type: "success",
471
- dataUpdatedAt: e?.updatedAt,
472
- manual: e?.manual
473
- }), s;
474
- }
475
- setState(t, e) {
476
- this.#n({ type: "setState", state: t, setStateOptions: e });
477
- }
478
- cancel(t) {
479
- const e = this.#r?.promise;
480
- return this.#r?.cancel(t), e ? e.then(U).catch(U) : Promise.resolve();
481
- }
482
- destroy() {
483
- super.destroy(), this.cancel({ silent: !0 });
484
- }
485
- reset() {
486
- this.destroy(), this.setState(this.#t);
487
- }
488
- isActive() {
489
- return this.observers.some(
490
- (t) => z(t.options.enabled, this) !== !1
491
- );
492
- }
493
- isDisabled() {
494
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === Dt || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
495
- }
496
- isStatic() {
497
- return this.getObserversCount() > 0 ? this.observers.some(
498
- (t) => W(t.options.staleTime, this) === "static"
499
- ) : !1;
500
- }
501
- isStale() {
502
- return this.getObserversCount() > 0 ? this.observers.some(
503
- (t) => t.getCurrentResult().isStale
504
- ) : this.state.data === void 0 || this.state.isInvalidated;
505
- }
506
- isStaleByTime(t = 0) {
507
- return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !ue(this.state.dataUpdatedAt, t);
508
- }
509
- onFocus() {
510
- this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#r?.continue();
511
- }
512
- onOnline() {
513
- this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#r?.continue();
514
- }
515
- addObserver(t) {
516
- this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#s.notify({ type: "observerAdded", query: this, observer: t }));
517
- }
518
- removeObserver(t) {
519
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#r && (this.#o ? this.#r.cancel({ revert: !0 }) : this.#r.cancelRetry()), this.scheduleGc()), this.#s.notify({ type: "observerRemoved", query: this, observer: t }));
520
- }
521
- getObserversCount() {
522
- return this.observers.length;
523
- }
524
- invalidate() {
525
- this.state.isInvalidated || this.#n({ type: "invalidate" });
526
- }
527
- async fetch(t, e) {
528
- if (this.state.fetchStatus !== "idle" && // If the promise in the retyer is already rejected, we have to definitely
529
- // re-start the fetch; there is a chance that the query is still in a
530
- // pending state when that happens
531
- this.#r?.status() !== "rejected") {
532
- if (this.state.data !== void 0 && e?.cancelRefetch)
533
- this.cancel({ silent: !0 });
534
- else if (this.#r)
535
- return this.#r.continueRetry(), this.#r.promise;
536
- }
537
- if (t && this.setOptions(t), !this.options.queryFn) {
538
- const a = this.observers.find((u) => u.options.queryFn);
539
- a && this.setOptions(a.options);
540
- }
541
- const s = new AbortController(), r = (a) => {
542
- Object.defineProperty(a, "signal", {
543
- enumerable: !0,
544
- get: () => (this.#o = !0, s.signal)
545
- });
546
- }, i = () => {
547
- const a = le(this.options, e), h = (() => {
548
- const c = {
549
- client: this.#i,
550
- queryKey: this.queryKey,
551
- meta: this.meta
552
- };
553
- return r(c), c;
554
- })();
555
- return this.#o = !1, this.options.persister ? this.options.persister(
556
- a,
557
- h,
558
- this
559
- ) : a(h);
560
- }, o = (() => {
561
- const a = {
562
- fetchOptions: e,
563
- options: this.options,
564
- queryKey: this.queryKey,
565
- client: this.#i,
566
- state: this.state,
567
- fetchFn: i
568
- };
569
- return r(a), a;
570
- })();
571
- this.options.behavior?.onFetch(o, this), this.#e = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== o.fetchOptions?.meta) && this.#n({ type: "fetch", meta: o.fetchOptions?.meta }), this.#r = pe({
572
- initialPromise: e?.initialPromise,
573
- fn: o.fetchFn,
574
- onCancel: (a) => {
575
- a instanceof Pt && a.revert && this.setState({
576
- ...this.#e,
577
- fetchStatus: "idle"
578
- }), s.abort();
579
- },
580
- onFail: (a, u) => {
581
- this.#n({ type: "failed", failureCount: a, error: u });
582
- },
583
- onPause: () => {
584
- this.#n({ type: "pause" });
585
- },
586
- onContinue: () => {
587
- this.#n({ type: "continue" });
588
- },
589
- retry: o.options.retry,
590
- retryDelay: o.options.retryDelay,
591
- networkMode: o.options.networkMode,
592
- canRun: () => !0
593
- });
594
- try {
595
- const a = await this.#r.start();
596
- if (a === void 0)
597
- throw new Error(`${this.queryHash} data is undefined`);
598
- return this.setData(a), this.#s.config.onSuccess?.(a, this), this.#s.config.onSettled?.(
599
- a,
600
- this.state.error,
601
- this
602
- ), a;
603
- } catch (a) {
604
- if (a instanceof Pt) {
605
- if (a.silent)
606
- return this.#r.promise;
607
- if (a.revert) {
608
- if (this.state.data === void 0)
609
- throw a;
610
- return this.state.data;
611
- }
612
- }
613
- throw this.#n({
614
- type: "error",
615
- error: a
616
- }), this.#s.config.onError?.(
617
- a,
618
- this
619
- ), this.#s.config.onSettled?.(
620
- this.state.data,
621
- a,
622
- this
623
- ), a;
624
- } finally {
625
- this.scheduleGc();
626
- }
627
- }
628
- #n(t) {
629
- const e = (s) => {
630
- switch (t.type) {
631
- case "failed":
632
- return {
633
- ...s,
634
- fetchFailureCount: t.failureCount,
635
- fetchFailureReason: t.error
636
- };
637
- case "pause":
638
- return {
639
- ...s,
640
- fetchStatus: "paused"
641
- };
642
- case "continue":
643
- return {
644
- ...s,
645
- fetchStatus: "fetching"
646
- };
647
- case "fetch":
648
- return {
649
- ...s,
650
- ...ge(s.data, this.options),
651
- fetchMeta: t.meta ?? null
652
- };
653
- case "success":
654
- const r = {
655
- ...s,
656
- ...Wt(t.data, t.dataUpdatedAt),
657
- dataUpdateCount: s.dataUpdateCount + 1,
658
- ...!t.manual && {
659
- fetchStatus: "idle",
660
- fetchFailureCount: 0,
661
- fetchFailureReason: null
662
- }
663
- };
664
- return this.#e = t.manual ? r : void 0, r;
665
- case "error":
666
- const i = t.error;
667
- return {
668
- ...s,
669
- error: i,
670
- errorUpdateCount: s.errorUpdateCount + 1,
671
- errorUpdatedAt: Date.now(),
672
- fetchFailureCount: s.fetchFailureCount + 1,
673
- fetchFailureReason: i,
674
- fetchStatus: "idle",
675
- status: "error"
676
- };
677
- case "invalidate":
678
- return {
679
- ...s,
680
- isInvalidated: !0
681
- };
682
- case "setState":
683
- return {
684
- ...s,
685
- ...t.state
686
- };
687
- }
688
- };
689
- this.state = e(this.state), A.batch(() => {
690
- this.observers.forEach((s) => {
691
- s.onQueryUpdate();
692
- }), this.#s.notify({ query: this, type: "updated", action: t });
693
- });
694
- }
695
- };
696
- function ge(t, e) {
697
- return {
698
- fetchFailureCount: 0,
699
- fetchFailureReason: null,
700
- fetchStatus: fe(e.networkMode) ? "fetching" : "paused",
701
- ...t === void 0 && {
702
- error: null,
703
- status: "pending"
704
- }
705
- };
706
- }
707
- function Wt(t, e) {
708
- return {
709
- data: t,
710
- dataUpdatedAt: e ?? Date.now(),
711
- error: null,
712
- isInvalidated: !1,
713
- status: "success"
714
- };
715
- }
716
- function Vt(t) {
717
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = e !== void 0, r = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
718
- return {
719
- data: e,
720
- dataUpdateCount: 0,
721
- dataUpdatedAt: s ? r ?? Date.now() : 0,
722
- error: null,
723
- errorUpdateCount: 0,
724
- errorUpdatedAt: 0,
725
- fetchFailureCount: 0,
726
- fetchFailureReason: null,
727
- fetchMeta: null,
728
- isInvalidated: !1,
729
- status: s ? "success" : "pending",
730
- fetchStatus: "idle"
731
- };
732
- }
733
- var ye = class extends et {
734
- constructor(t, e) {
735
- super(), this.options = e, this.#t = t, this.#n = null, this.#o = kt(), this.bindMethods(), this.setOptions(e);
736
- }
737
- #t;
738
- #e = void 0;
739
- #s = void 0;
740
- #i = void 0;
741
- #r;
742
- #a;
743
- #o;
744
- #n;
745
- #m;
746
- #d;
747
- // This property keeps track of the last query with defined data.
748
- // It will be used to pass the previous data and query to the placeholder function between renders.
749
- #f;
750
- #u;
751
- #h;
752
- #c;
753
- #p = /* @__PURE__ */ new Set();
754
- bindMethods() {
755
- this.refetch = this.refetch.bind(this);
756
- }
757
- onSubscribe() {
758
- this.listeners.size === 1 && (this.#e.addObserver(this), Yt(this.#e, this.options) ? this.#l() : this.updateResult(), this.#b());
759
- }
760
- onUnsubscribe() {
761
- this.hasListeners() || this.destroy();
762
- }
763
- shouldFetchOnReconnect() {
764
- return Rt(
765
- this.#e,
766
- this.options,
767
- this.options.refetchOnReconnect
768
- );
769
- }
770
- shouldFetchOnWindowFocus() {
771
- return Rt(
772
- this.#e,
773
- this.options,
774
- this.options.refetchOnWindowFocus
775
- );
776
- }
777
- destroy() {
778
- this.listeners = /* @__PURE__ */ new Set(), this.#x(), this.#w(), this.#e.removeObserver(this);
779
- }
780
- setOptions(t) {
781
- const e = this.options, s = this.#e;
782
- if (this.options = this.#t.defaultQueryOptions(t), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof z(this.options.enabled, this.#e) != "boolean")
783
- throw new Error(
784
- "Expected enabled to be a boolean or a callback that returns a boolean"
785
- );
786
- this.#C(), this.#e.setOptions(this.options), e._defaulted && !lt(this.options, e) && this.#t.getQueryCache().notify({
787
- type: "observerOptionsUpdated",
788
- query: this.#e,
789
- observer: this
790
- });
791
- const r = this.hasListeners();
792
- r && Xt(
793
- this.#e,
794
- s,
795
- this.options,
796
- e
797
- ) && this.#l(), this.updateResult(), r && (this.#e !== s || z(this.options.enabled, this.#e) !== z(e.enabled, this.#e) || W(this.options.staleTime, this.#e) !== W(e.staleTime, this.#e)) && this.#g();
798
- const i = this.#y();
799
- r && (this.#e !== s || z(this.options.enabled, this.#e) !== z(e.enabled, this.#e) || i !== this.#c) && this.#v(i);
800
- }
801
- getOptimisticResult(t) {
802
- const e = this.#t.getQueryCache().build(this.#t, t), s = this.createResult(e, t);
803
- return rs(this, s) && (this.#i = s, this.#a = this.options, this.#r = this.#e.state), s;
804
- }
805
- getCurrentResult() {
806
- return this.#i;
807
- }
808
- trackResult(t, e) {
809
- return new Proxy(t, {
810
- get: (s, r) => (this.trackProp(r), e?.(r), r === "promise" && (this.trackProp("data"), !this.options.experimental_prefetchInRender && this.#o.status === "pending" && this.#o.reject(
811
- new Error(
812
- "experimental_prefetchInRender feature flag is not enabled"
813
- )
814
- )), Reflect.get(s, r))
815
- });
816
- }
817
- trackProp(t) {
818
- this.#p.add(t);
819
- }
820
- getCurrentQuery() {
821
- return this.#e;
822
- }
823
- refetch({ ...t } = {}) {
824
- return this.fetch({
825
- ...t
826
- });
827
- }
828
- fetchOptimistic(t) {
829
- const e = this.#t.defaultQueryOptions(t), s = this.#t.getQueryCache().build(this.#t, e);
830
- return s.fetch().then(() => this.createResult(s, e));
831
- }
832
- fetch(t) {
833
- return this.#l({
834
- ...t,
835
- cancelRefetch: t.cancelRefetch ?? !0
836
- }).then(() => (this.updateResult(), this.#i));
837
- }
838
- #l(t) {
839
- this.#C();
840
- let e = this.#e.fetch(
841
- this.options,
842
- t
843
- );
844
- return t?.throwOnError || (e = e.catch(U)), e;
845
- }
846
- #g() {
847
- this.#x();
848
- const t = W(
849
- this.options.staleTime,
850
- this.#e
851
- );
852
- if (X || this.#i.isStale || !Ct(t))
853
- return;
854
- const s = ue(this.#i.dataUpdatedAt, t) + 1;
855
- this.#u = V.setTimeout(() => {
856
- this.#i.isStale || this.updateResult();
857
- }, s);
858
- }
859
- #y() {
860
- return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#e) : this.options.refetchInterval) ?? !1;
861
- }
862
- #v(t) {
863
- this.#w(), this.#c = t, !(X || z(this.options.enabled, this.#e) === !1 || !Ct(this.#c) || this.#c === 0) && (this.#h = V.setInterval(() => {
864
- (this.options.refetchIntervalInBackground || Qt.isFocused()) && this.#l();
865
- }, this.#c));
866
- }
867
- #b() {
868
- this.#g(), this.#v(this.#y());
869
- }
870
- #x() {
871
- this.#u && (V.clearTimeout(this.#u), this.#u = void 0);
872
- }
873
- #w() {
874
- this.#h && (V.clearInterval(this.#h), this.#h = void 0);
875
- }
876
- createResult(t, e) {
877
- const s = this.#e, r = this.options, i = this.#i, n = this.#r, o = this.#a, u = t !== s ? t.state : this.#s, { state: h } = t;
878
- let c = { ...h }, f = !1, d;
879
- if (e._optimisticResults) {
880
- const E = this.hasListeners(), N = !E && Yt(t, e), q = E && Xt(t, s, e, r);
881
- (N || q) && (c = {
882
- ...c,
883
- ...ge(h.data, t.options)
884
- }), e._optimisticResults === "isRestoring" && (c.fetchStatus = "idle");
885
- }
886
- let { error: C, errorUpdatedAt: g, status: p } = c;
887
- d = c.data;
888
- let y = !1;
889
- if (e.placeholderData !== void 0 && d === void 0 && p === "pending") {
890
- let E;
891
- i?.isPlaceholderData && e.placeholderData === o?.placeholderData ? (E = i.data, y = !0) : E = typeof e.placeholderData == "function" ? e.placeholderData(
892
- this.#f?.state.data,
893
- this.#f
894
- ) : e.placeholderData, E !== void 0 && (p = "success", d = Ot(
895
- i?.data,
896
- E,
897
- e
898
- ), f = !0);
899
- }
900
- if (e.select && d !== void 0 && !y)
901
- if (i && d === n?.data && e.select === this.#m)
902
- d = this.#d;
903
- else
904
- try {
905
- this.#m = e.select, d = e.select(d), d = Ot(i?.data, d, e), this.#d = d, this.#n = null;
906
- } catch (E) {
907
- this.#n = E;
908
- }
909
- this.#n && (C = this.#n, d = this.#d, g = Date.now(), p = "error");
910
- const b = c.fetchStatus === "fetching", R = p === "pending", P = p === "error", D = R && b, L = d !== void 0, T = {
911
- status: p,
912
- fetchStatus: c.fetchStatus,
913
- isPending: R,
914
- isSuccess: p === "success",
915
- isError: P,
916
- isInitialLoading: D,
917
- isLoading: D,
918
- data: d,
919
- dataUpdatedAt: c.dataUpdatedAt,
920
- error: C,
921
- errorUpdatedAt: g,
922
- failureCount: c.fetchFailureCount,
923
- failureReason: c.fetchFailureReason,
924
- errorUpdateCount: c.errorUpdateCount,
925
- isFetched: c.dataUpdateCount > 0 || c.errorUpdateCount > 0,
926
- isFetchedAfterMount: c.dataUpdateCount > u.dataUpdateCount || c.errorUpdateCount > u.errorUpdateCount,
927
- isFetching: b,
928
- isRefetching: b && !R,
929
- isLoadingError: P && !L,
930
- isPaused: c.fetchStatus === "paused",
931
- isPlaceholderData: f,
932
- isRefetchError: P && L,
933
- isStale: $t(t, e),
934
- refetch: this.refetch,
935
- promise: this.#o,
936
- isEnabled: z(e.enabled, t) !== !1
937
- };
938
- if (this.options.experimental_prefetchInRender) {
939
- const E = (K) => {
940
- T.status === "error" ? K.reject(T.error) : T.data !== void 0 && K.resolve(T.data);
941
- }, N = () => {
942
- const K = this.#o = T.promise = kt();
943
- E(K);
944
- }, q = this.#o;
945
- switch (q.status) {
946
- case "pending":
947
- t.queryHash === s.queryHash && E(q);
948
- break;
949
- case "fulfilled":
950
- (T.status === "error" || T.data !== q.value) && N();
951
- break;
952
- case "rejected":
953
- (T.status !== "error" || T.error !== q.reason) && N();
954
- break;
955
- }
956
- }
957
- return T;
958
- }
959
- updateResult() {
960
- const t = this.#i, e = this.createResult(this.#e, this.options);
961
- if (this.#r = this.#e.state, this.#a = this.options, this.#r.data !== void 0 && (this.#f = this.#e), lt(e, t))
962
- return;
963
- this.#i = e;
964
- const s = () => {
965
- if (!t)
966
- return !0;
967
- const { notifyOnChangeProps: r } = this.options, i = typeof r == "function" ? r() : r;
968
- if (i === "all" || !i && !this.#p.size)
969
- return !0;
970
- const n = new Set(
971
- i ?? this.#p
972
- );
973
- return this.options.throwOnError && n.add("error"), Object.keys(this.#i).some((o) => {
974
- const a = o;
975
- return this.#i[a] !== t[a] && n.has(a);
976
- });
977
- };
978
- this.#S({ listeners: s() });
979
- }
980
- #C() {
981
- const t = this.#t.getQueryCache().build(this.#t, this.options);
982
- if (t === this.#e)
983
- return;
984
- const e = this.#e;
985
- this.#e = t, this.#s = t.state, this.hasListeners() && (e?.removeObserver(this), t.addObserver(this));
986
- }
987
- onQueryUpdate() {
988
- this.updateResult(), this.hasListeners() && this.#b();
989
- }
990
- #S(t) {
991
- A.batch(() => {
992
- t.listeners && this.listeners.forEach((e) => {
993
- e(this.#i);
994
- }), this.#t.getQueryCache().notify({
995
- query: this.#e,
996
- type: "observerResultsUpdated"
997
- });
998
- });
999
- }
1000
- };
1001
- function ss(t, e) {
1002
- return z(e.enabled, t) !== !1 && t.state.data === void 0 && !(t.state.status === "error" && e.retryOnMount === !1);
1003
- }
1004
- function Yt(t, e) {
1005
- return ss(t, e) || t.state.data !== void 0 && Rt(t, e, e.refetchOnMount);
1006
- }
1007
- function Rt(t, e, s) {
1008
- if (z(e.enabled, t) !== !1 && W(e.staleTime, t) !== "static") {
1009
- const r = typeof s == "function" ? s(t) : s;
1010
- return r === "always" || r !== !1 && $t(t, e);
1011
- }
1012
- return !1;
1013
- }
1014
- function Xt(t, e, s, r) {
1015
- return (t !== e || z(r.enabled, t) === !1) && (!s.suspense || t.state.status !== "error") && $t(t, s);
1016
- }
1017
- function $t(t, e) {
1018
- return z(e.enabled, t) !== !1 && t.isStaleByTime(W(e.staleTime, t));
1019
- }
1020
- function rs(t, e) {
1021
- return !lt(t.getCurrentResult(), e);
1022
- }
1023
- function ft(t) {
1024
- return {
1025
- onFetch: (e, s) => {
1026
- const r = e.options, i = e.fetchOptions?.meta?.fetchMore?.direction, n = e.state.data?.pages || [], o = e.state.data?.pageParams || [];
1027
- let a = { pages: [], pageParams: [] }, u = 0;
1028
- const h = async () => {
1029
- let c = !1;
1030
- const f = (g) => {
1031
- Object.defineProperty(g, "signal", {
1032
- enumerable: !0,
1033
- get: () => (e.signal.aborted ? c = !0 : e.signal.addEventListener("abort", () => {
1034
- c = !0;
1035
- }), e.signal)
1036
- });
1037
- }, d = le(e.options, e.fetchOptions), C = async (g, p, y) => {
1038
- if (c)
1039
- return Promise.reject();
1040
- if (p == null && g.pages.length)
1041
- return Promise.resolve(g);
1042
- const R = (() => {
1043
- const O = {
1044
- client: e.client,
1045
- queryKey: e.queryKey,
1046
- pageParam: p,
1047
- direction: y ? "backward" : "forward",
1048
- meta: e.options.meta
1049
- };
1050
- return f(O), O;
1051
- })(), P = await d(R), { maxPages: D } = e.options, L = y ? Ve : We;
1052
- return {
1053
- pages: L(g.pages, P, D),
1054
- pageParams: L(g.pageParams, p, D)
1055
- };
1056
- };
1057
- if (i && n.length) {
1058
- const g = i === "backward", p = g ? ve : Et, y = {
1059
- pages: n,
1060
- pageParams: o
1061
- }, b = p(r, y);
1062
- a = await C(y, b, g);
1063
- } else {
1064
- const g = t ?? n.length;
1065
- do {
1066
- const p = u === 0 ? o[0] ?? r.initialPageParam : Et(r, a);
1067
- if (u > 0 && p == null)
1068
- break;
1069
- a = await C(a, p), u++;
1070
- } while (u < g);
1071
- }
1072
- return a;
1073
- };
1074
- e.options.persister ? e.fetchFn = () => e.options.persister?.(
1075
- h,
1076
- {
1077
- client: e.client,
1078
- queryKey: e.queryKey,
1079
- meta: e.options.meta,
1080
- signal: e.signal
1081
- },
1082
- s
1083
- ) : e.fetchFn = h;
1084
- }
1085
- };
1086
- }
1087
- function Et(t, { pages: e, pageParams: s }) {
1088
- const r = e.length - 1;
1089
- return e.length > 0 ? t.getNextPageParam(
1090
- e[r],
1091
- e,
1092
- s[r],
1093
- s
1094
- ) : void 0;
1095
- }
1096
- function ve(t, { pages: e, pageParams: s }) {
1097
- return e.length > 0 ? t.getPreviousPageParam?.(e[0], e, s[0], s) : void 0;
1098
- }
1099
- function is(t, e) {
1100
- return e ? Et(t, e) != null : !1;
1101
- }
1102
- function ns(t, e) {
1103
- return !e || !t.getPreviousPageParam ? !1 : ve(t, e) != null;
1104
- }
1105
- var as = class extends ye {
1106
- constructor(t, e) {
1107
- super(t, e);
1108
- }
1109
- bindMethods() {
1110
- super.bindMethods(), this.fetchNextPage = this.fetchNextPage.bind(this), this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
1111
- }
1112
- setOptions(t) {
1113
- super.setOptions({
1114
- ...t,
1115
- behavior: ft()
1116
- });
1117
- }
1118
- getOptimisticResult(t) {
1119
- return t.behavior = ft(), super.getOptimisticResult(t);
1120
- }
1121
- fetchNextPage(t) {
1122
- return this.fetch({
1123
- ...t,
1124
- meta: {
1125
- fetchMore: { direction: "forward" }
1126
- }
1127
- });
1128
- }
1129
- fetchPreviousPage(t) {
1130
- return this.fetch({
1131
- ...t,
1132
- meta: {
1133
- fetchMore: { direction: "backward" }
1134
- }
1135
- });
1136
- }
1137
- createResult(t, e) {
1138
- const { state: s } = t, r = super.createResult(t, e), { isFetching: i, isRefetching: n, isError: o, isRefetchError: a } = r, u = s.fetchMeta?.fetchMore?.direction, h = o && u === "forward", c = i && u === "forward", f = o && u === "backward", d = i && u === "backward";
1139
- return {
1140
- ...r,
1141
- fetchNextPage: this.fetchNextPage,
1142
- fetchPreviousPage: this.fetchPreviousPage,
1143
- hasNextPage: is(e, s.data),
1144
- hasPreviousPage: ns(e, s.data),
1145
- isFetchNextPageError: h,
1146
- isFetchingNextPage: c,
1147
- isFetchPreviousPageError: f,
1148
- isFetchingPreviousPage: d,
1149
- isRefetchError: a && !h && !f,
1150
- isRefetching: n && !c && !d
1151
- };
1152
- }
1153
- }, os = class extends me {
1154
- #t;
1155
- #e;
1156
- #s;
1157
- #i;
1158
- constructor(t) {
1159
- super(), this.#t = t.client, this.mutationId = t.mutationId, this.#s = t.mutationCache, this.#e = [], this.state = t.state || be(), this.setOptions(t.options), this.scheduleGc();
1160
- }
1161
- setOptions(t) {
1162
- this.options = t, this.updateGcTime(this.options.gcTime);
1163
- }
1164
- get meta() {
1165
- return this.options.meta;
1166
- }
1167
- addObserver(t) {
1168
- this.#e.includes(t) || (this.#e.push(t), this.clearGcTimeout(), this.#s.notify({
1169
- type: "observerAdded",
1170
- mutation: this,
1171
- observer: t
1172
- }));
1173
- }
1174
- removeObserver(t) {
1175
- this.#e = this.#e.filter((e) => e !== t), this.scheduleGc(), this.#s.notify({
1176
- type: "observerRemoved",
1177
- mutation: this,
1178
- observer: t
1179
- });
1180
- }
1181
- optionalRemove() {
1182
- this.#e.length || (this.state.status === "pending" ? this.scheduleGc() : this.#s.remove(this));
1183
- }
1184
- continue() {
1185
- return this.#i?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
1186
- this.execute(this.state.variables);
1187
- }
1188
- async execute(t) {
1189
- const e = () => {
1190
- this.#r({ type: "continue" });
1191
- }, s = {
1192
- client: this.#t,
1193
- meta: this.options.meta,
1194
- mutationKey: this.options.mutationKey
1195
- };
1196
- this.#i = pe({
1197
- fn: () => this.options.mutationFn ? this.options.mutationFn(t, s) : Promise.reject(new Error("No mutationFn found")),
1198
- onFail: (n, o) => {
1199
- this.#r({ type: "failed", failureCount: n, error: o });
1200
- },
1201
- onPause: () => {
1202
- this.#r({ type: "pause" });
1203
- },
1204
- onContinue: e,
1205
- retry: this.options.retry ?? 0,
1206
- retryDelay: this.options.retryDelay,
1207
- networkMode: this.options.networkMode,
1208
- canRun: () => this.#s.canRun(this)
1209
- });
1210
- const r = this.state.status === "pending", i = !this.#i.canStart();
1211
- try {
1212
- if (r)
1213
- e();
1214
- else {
1215
- this.#r({ type: "pending", variables: t, isPaused: i }), await this.#s.config.onMutate?.(
1216
- t,
1217
- this,
1218
- s
1219
- );
1220
- const o = await this.options.onMutate?.(
1221
- t,
1222
- s
1223
- );
1224
- o !== this.state.context && this.#r({
1225
- type: "pending",
1226
- context: o,
1227
- variables: t,
1228
- isPaused: i
1229
- });
1230
- }
1231
- const n = await this.#i.start();
1232
- return await this.#s.config.onSuccess?.(
1233
- n,
1234
- t,
1235
- this.state.context,
1236
- this,
1237
- s
1238
- ), await this.options.onSuccess?.(
1239
- n,
1240
- t,
1241
- this.state.context,
1242
- s
1243
- ), await this.#s.config.onSettled?.(
1244
- n,
1245
- null,
1246
- this.state.variables,
1247
- this.state.context,
1248
- this,
1249
- s
1250
- ), await this.options.onSettled?.(
1251
- n,
1252
- null,
1253
- t,
1254
- this.state.context,
1255
- s
1256
- ), this.#r({ type: "success", data: n }), n;
1257
- } catch (n) {
1258
- try {
1259
- throw await this.#s.config.onError?.(
1260
- n,
1261
- t,
1262
- this.state.context,
1263
- this,
1264
- s
1265
- ), await this.options.onError?.(
1266
- n,
1267
- t,
1268
- this.state.context,
1269
- s
1270
- ), await this.#s.config.onSettled?.(
1271
- void 0,
1272
- n,
1273
- this.state.variables,
1274
- this.state.context,
1275
- this,
1276
- s
1277
- ), await this.options.onSettled?.(
1278
- void 0,
1279
- n,
1280
- t,
1281
- this.state.context,
1282
- s
1283
- ), n;
1284
- } finally {
1285
- this.#r({ type: "error", error: n });
1286
- }
1287
- } finally {
1288
- this.#s.runNext(this);
1289
- }
1290
- }
1291
- #r(t) {
1292
- const e = (s) => {
1293
- switch (t.type) {
1294
- case "failed":
1295
- return {
1296
- ...s,
1297
- failureCount: t.failureCount,
1298
- failureReason: t.error
1299
- };
1300
- case "pause":
1301
- return {
1302
- ...s,
1303
- isPaused: !0
1304
- };
1305
- case "continue":
1306
- return {
1307
- ...s,
1308
- isPaused: !1
1309
- };
1310
- case "pending":
1311
- return {
1312
- ...s,
1313
- context: t.context,
1314
- data: void 0,
1315
- failureCount: 0,
1316
- failureReason: null,
1317
- error: null,
1318
- isPaused: t.isPaused,
1319
- status: "pending",
1320
- variables: t.variables,
1321
- submittedAt: Date.now()
1322
- };
1323
- case "success":
1324
- return {
1325
- ...s,
1326
- data: t.data,
1327
- failureCount: 0,
1328
- failureReason: null,
1329
- error: null,
1330
- status: "success",
1331
- isPaused: !1
1332
- };
1333
- case "error":
1334
- return {
1335
- ...s,
1336
- data: void 0,
1337
- error: t.error,
1338
- failureCount: s.failureCount + 1,
1339
- failureReason: t.error,
1340
- isPaused: !1,
1341
- status: "error"
1342
- };
1343
- }
1344
- };
1345
- this.state = e(this.state), A.batch(() => {
1346
- this.#e.forEach((s) => {
1347
- s.onMutationUpdate(t);
1348
- }), this.#s.notify({
1349
- mutation: this,
1350
- type: "updated",
1351
- action: t
1352
- });
1353
- });
1354
- }
1355
- };
1356
- function be() {
1357
- return {
1358
- context: void 0,
1359
- data: void 0,
1360
- error: null,
1361
- failureCount: 0,
1362
- failureReason: null,
1363
- isPaused: !1,
1364
- status: "idle",
1365
- variables: void 0,
1366
- submittedAt: 0
1367
- };
1368
- }
1369
- var cs = class extends et {
1370
- constructor(t = {}) {
1371
- super(), this.config = t, this.#t = /* @__PURE__ */ new Set(), this.#e = /* @__PURE__ */ new Map(), this.#s = 0;
1372
- }
1373
- #t;
1374
- #e;
1375
- #s;
1376
- build(t, e, s) {
1377
- const r = new os({
1378
- client: t,
1379
- mutationCache: this,
1380
- mutationId: ++this.#s,
1381
- options: t.defaultMutationOptions(e),
1382
- state: s
1383
- });
1384
- return this.add(r), r;
1385
- }
1386
- add(t) {
1387
- this.#t.add(t);
1388
- const e = ut(t);
1389
- if (typeof e == "string") {
1390
- const s = this.#e.get(e);
1391
- s ? s.push(t) : this.#e.set(e, [t]);
1392
- }
1393
- this.notify({ type: "added", mutation: t });
1394
- }
1395
- remove(t) {
1396
- if (this.#t.delete(t)) {
1397
- const e = ut(t);
1398
- if (typeof e == "string") {
1399
- const s = this.#e.get(e);
1400
- if (s)
1401
- if (s.length > 1) {
1402
- const r = s.indexOf(t);
1403
- r !== -1 && s.splice(r, 1);
1404
- } else s[0] === t && this.#e.delete(e);
1405
- }
1406
- }
1407
- this.notify({ type: "removed", mutation: t });
1408
- }
1409
- canRun(t) {
1410
- const e = ut(t);
1411
- if (typeof e == "string") {
1412
- const r = this.#e.get(e)?.find(
1413
- (i) => i.state.status === "pending"
1414
- );
1415
- return !r || r === t;
1416
- } else
1417
- return !0;
1418
- }
1419
- runNext(t) {
1420
- const e = ut(t);
1421
- return typeof e == "string" ? this.#e.get(e)?.find((r) => r !== t && r.state.isPaused)?.continue() ?? Promise.resolve() : Promise.resolve();
1422
- }
1423
- clear() {
1424
- A.batch(() => {
1425
- this.#t.forEach((t) => {
1426
- this.notify({ type: "removed", mutation: t });
1427
- }), this.#t.clear(), this.#e.clear();
1428
- });
1429
- }
1430
- getAll() {
1431
- return Array.from(this.#t);
1432
- }
1433
- find(t) {
1434
- const e = { exact: !0, ...t };
1435
- return this.getAll().find(
1436
- (s) => Bt(e, s)
1437
- );
1438
- }
1439
- findAll(t = {}) {
1440
- return this.getAll().filter((e) => Bt(t, e));
1441
- }
1442
- notify(t) {
1443
- A.batch(() => {
1444
- this.listeners.forEach((e) => {
1445
- e(t);
1446
- });
1447
- });
1448
- }
1449
- resumePausedMutations() {
1450
- const t = this.getAll().filter((e) => e.state.isPaused);
1451
- return A.batch(
1452
- () => Promise.all(
1453
- t.map((e) => e.continue().catch(U))
1454
- )
1455
- );
1456
- }
1457
- };
1458
- function ut(t) {
1459
- return t.options.scope?.id;
1460
- }
1461
- var us = class extends et {
1462
- #t;
1463
- #e = void 0;
1464
- #s;
1465
- #i;
1466
- constructor(e, s) {
1467
- super(), this.#t = e, this.setOptions(s), this.bindMethods(), this.#r();
1468
- }
1469
- bindMethods() {
1470
- this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
1471
- }
1472
- setOptions(e) {
1473
- const s = this.options;
1474
- this.options = this.#t.defaultMutationOptions(e), lt(this.options, s) || this.#t.getMutationCache().notify({
1475
- type: "observerOptionsUpdated",
1476
- mutation: this.#s,
1477
- observer: this
1478
- }), s?.mutationKey && this.options.mutationKey && J(s.mutationKey) !== J(this.options.mutationKey) ? this.reset() : this.#s?.state.status === "pending" && this.#s.setOptions(this.options);
1479
- }
1480
- onUnsubscribe() {
1481
- this.hasListeners() || this.#s?.removeObserver(this);
1482
- }
1483
- onMutationUpdate(e) {
1484
- this.#r(), this.#a(e);
1485
- }
1486
- getCurrentResult() {
1487
- return this.#e;
1488
- }
1489
- reset() {
1490
- this.#s?.removeObserver(this), this.#s = void 0, this.#r(), this.#a();
1491
- }
1492
- mutate(e, s) {
1493
- return this.#i = s, this.#s?.removeObserver(this), this.#s = this.#t.getMutationCache().build(this.#t, this.options), this.#s.addObserver(this), this.#s.execute(e);
1494
- }
1495
- #r() {
1496
- const e = this.#s?.state ?? be();
1497
- this.#e = {
1498
- ...e,
1499
- isPending: e.status === "pending",
1500
- isSuccess: e.status === "success",
1501
- isError: e.status === "error",
1502
- isIdle: e.status === "idle",
1503
- mutate: this.mutate,
1504
- reset: this.reset
1505
- };
1506
- }
1507
- #a(e) {
1508
- A.batch(() => {
1509
- if (this.#i && this.hasListeners()) {
1510
- const s = this.#e.variables, r = this.#e.context, i = {
1511
- client: this.#t,
1512
- meta: this.options.meta,
1513
- mutationKey: this.options.mutationKey
1514
- };
1515
- e?.type === "success" ? (this.#i.onSuccess?.(
1516
- e.data,
1517
- s,
1518
- r,
1519
- i
1520
- ), this.#i.onSettled?.(
1521
- e.data,
1522
- null,
1523
- s,
1524
- r,
1525
- i
1526
- )) : e?.type === "error" && (this.#i.onError?.(
1527
- e.error,
1528
- s,
1529
- r,
1530
- i
1531
- ), this.#i.onSettled?.(
1532
- void 0,
1533
- e.error,
1534
- s,
1535
- r,
1536
- i
1537
- ));
1538
- }
1539
- this.listeners.forEach((s) => {
1540
- s(this.#e);
1541
- });
1542
- });
1543
- }
1544
- }, hs = class extends et {
1545
- constructor(t = {}) {
1546
- super(), this.config = t, this.#t = /* @__PURE__ */ new Map();
1547
- }
1548
- #t;
1549
- build(t, e, s) {
1550
- const r = e.queryKey, i = e.queryHash ?? At(r, e);
1551
- let n = this.get(i);
1552
- return n || (n = new es({
1553
- client: t,
1554
- queryKey: r,
1555
- queryHash: i,
1556
- options: t.defaultQueryOptions(e),
1557
- state: s,
1558
- defaultOptions: t.getQueryDefaults(r)
1559
- }), this.add(n)), n;
1560
- }
1561
- add(t) {
1562
- this.#t.has(t.queryHash) || (this.#t.set(t.queryHash, t), this.notify({
1563
- type: "added",
1564
- query: t
1565
- }));
1566
- }
1567
- remove(t) {
1568
- const e = this.#t.get(t.queryHash);
1569
- e && (t.destroy(), e === t && this.#t.delete(t.queryHash), this.notify({ type: "removed", query: t }));
1570
- }
1571
- clear() {
1572
- A.batch(() => {
1573
- this.getAll().forEach((t) => {
1574
- this.remove(t);
1575
- });
1576
- });
1577
- }
1578
- get(t) {
1579
- return this.#t.get(t);
1580
- }
1581
- getAll() {
1582
- return [...this.#t.values()];
1583
- }
1584
- find(t) {
1585
- const e = { exact: !0, ...t };
1586
- return this.getAll().find(
1587
- (s) => zt(e, s)
1588
- );
1589
- }
1590
- findAll(t = {}) {
1591
- const e = this.getAll();
1592
- return Object.keys(t).length > 0 ? e.filter((s) => zt(t, s)) : e;
1593
- }
1594
- notify(t) {
1595
- A.batch(() => {
1596
- this.listeners.forEach((e) => {
1597
- e(t);
1598
- });
1599
- });
1600
- }
1601
- onFocus() {
1602
- A.batch(() => {
1603
- this.getAll().forEach((t) => {
1604
- t.onFocus();
1605
- });
1606
- });
1607
- }
1608
- onOnline() {
1609
- A.batch(() => {
1610
- this.getAll().forEach((t) => {
1611
- t.onOnline();
1612
- });
1613
- });
1614
- }
1615
- }, ls = class {
1616
- #t;
1617
- #e;
1618
- #s;
1619
- #i;
1620
- #r;
1621
- #a;
1622
- #o;
1623
- #n;
1624
- constructor(t = {}) {
1625
- this.#t = t.queryCache || new hs(), this.#e = t.mutationCache || new cs(), this.#s = t.defaultOptions || {}, this.#i = /* @__PURE__ */ new Map(), this.#r = /* @__PURE__ */ new Map(), this.#a = 0;
1626
- }
1627
- mount() {
1628
- this.#a++, this.#a === 1 && (this.#o = Qt.subscribe(async (t) => {
1629
- t && (await this.resumePausedMutations(), this.#t.onFocus());
1630
- }), this.#n = dt.subscribe(async (t) => {
1631
- t && (await this.resumePausedMutations(), this.#t.onOnline());
1632
- }));
1633
- }
1634
- unmount() {
1635
- this.#a--, this.#a === 0 && (this.#o?.(), this.#o = void 0, this.#n?.(), this.#n = void 0);
1636
- }
1637
- isFetching(t) {
1638
- return this.#t.findAll({ ...t, fetchStatus: "fetching" }).length;
1639
- }
1640
- isMutating(t) {
1641
- return this.#e.findAll({ ...t, status: "pending" }).length;
1642
- }
1643
- /**
1644
- * Imperative (non-reactive) way to retrieve data for a QueryKey.
1645
- * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
1646
- *
1647
- * Hint: Do not use this function inside a component, because it won't receive updates.
1648
- * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1649
- */
1650
- getQueryData(t) {
1651
- const e = this.defaultQueryOptions({ queryKey: t });
1652
- return this.#t.get(e.queryHash)?.state.data;
1653
- }
1654
- ensureQueryData(t) {
1655
- const e = this.defaultQueryOptions(t), s = this.#t.build(this, e), r = s.state.data;
1656
- return r === void 0 ? this.fetchQuery(t) : (t.revalidateIfStale && s.isStaleByTime(W(e.staleTime, s)) && this.prefetchQuery(e), Promise.resolve(r));
1657
- }
1658
- getQueriesData(t) {
1659
- return this.#t.findAll(t).map(({ queryKey: e, state: s }) => {
1660
- const r = s.data;
1661
- return [e, r];
1662
- });
1663
- }
1664
- setQueryData(t, e, s) {
1665
- const r = this.defaultQueryOptions({ queryKey: t }), n = this.#t.get(
1666
- r.queryHash
1667
- )?.state.data, o = Be(e, n);
1668
- if (o !== void 0)
1669
- return this.#t.build(this, r).setData(o, { ...s, manual: !0 });
1670
- }
1671
- setQueriesData(t, e, s) {
1672
- return A.batch(
1673
- () => this.#t.findAll(t).map(({ queryKey: r }) => [
1674
- r,
1675
- this.setQueryData(r, e, s)
1676
- ])
1677
- );
1678
- }
1679
- getQueryState(t) {
1680
- const e = this.defaultQueryOptions({ queryKey: t });
1681
- return this.#t.get(
1682
- e.queryHash
1683
- )?.state;
1684
- }
1685
- removeQueries(t) {
1686
- const e = this.#t;
1687
- A.batch(() => {
1688
- e.findAll(t).forEach((s) => {
1689
- e.remove(s);
1690
- });
1691
- });
1692
- }
1693
- resetQueries(t, e) {
1694
- const s = this.#t;
1695
- return A.batch(() => (s.findAll(t).forEach((r) => {
1696
- r.reset();
1697
- }), this.refetchQueries(
1698
- {
1699
- type: "active",
1700
- ...t
1701
- },
1702
- e
1703
- )));
1704
- }
1705
- cancelQueries(t, e = {}) {
1706
- const s = { revert: !0, ...e }, r = A.batch(
1707
- () => this.#t.findAll(t).map((i) => i.cancel(s))
1708
- );
1709
- return Promise.all(r).then(U).catch(U);
1710
- }
1711
- invalidateQueries(t, e = {}) {
1712
- return A.batch(() => (this.#t.findAll(t).forEach((s) => {
1713
- s.invalidate();
1714
- }), t?.refetchType === "none" ? Promise.resolve() : this.refetchQueries(
1715
- {
1716
- ...t,
1717
- type: t?.refetchType ?? t?.type ?? "active"
1718
- },
1719
- e
1720
- )));
1721
- }
1722
- refetchQueries(t, e = {}) {
1723
- const s = {
1724
- ...e,
1725
- cancelRefetch: e.cancelRefetch ?? !0
1726
- }, r = A.batch(
1727
- () => this.#t.findAll(t).filter((i) => !i.isDisabled() && !i.isStatic()).map((i) => {
1728
- let n = i.fetch(void 0, s);
1729
- return s.throwOnError || (n = n.catch(U)), i.state.fetchStatus === "paused" ? Promise.resolve() : n;
1730
- })
1731
- );
1732
- return Promise.all(r).then(U);
1733
- }
1734
- fetchQuery(t) {
1735
- const e = this.defaultQueryOptions(t);
1736
- e.retry === void 0 && (e.retry = !1);
1737
- const s = this.#t.build(this, e);
1738
- return s.isStaleByTime(
1739
- W(e.staleTime, s)
1740
- ) ? s.fetch(e) : Promise.resolve(s.state.data);
1741
- }
1742
- prefetchQuery(t) {
1743
- return this.fetchQuery(t).then(U).catch(U);
1744
- }
1745
- fetchInfiniteQuery(t) {
1746
- return t.behavior = ft(t.pages), this.fetchQuery(t);
1747
- }
1748
- prefetchInfiniteQuery(t) {
1749
- return this.fetchInfiniteQuery(t).then(U).catch(U);
1750
- }
1751
- ensureInfiniteQueryData(t) {
1752
- return t.behavior = ft(t.pages), this.ensureQueryData(t);
1753
- }
1754
- resumePausedMutations() {
1755
- return dt.isOnline() ? this.#e.resumePausedMutations() : Promise.resolve();
1756
- }
1757
- getQueryCache() {
1758
- return this.#t;
1759
- }
1760
- getMutationCache() {
1761
- return this.#e;
1762
- }
1763
- getDefaultOptions() {
1764
- return this.#s;
1765
- }
1766
- setDefaultOptions(t) {
1767
- this.#s = t;
1768
- }
1769
- setQueryDefaults(t, e) {
1770
- this.#i.set(J(t), {
1771
- queryKey: t,
1772
- defaultOptions: e
1773
- });
1774
- }
1775
- getQueryDefaults(t) {
1776
- const e = [...this.#i.values()], s = {};
1777
- return e.forEach((r) => {
1778
- it(t, r.queryKey) && Object.assign(s, r.defaultOptions);
1779
- }), s;
1780
- }
1781
- setMutationDefaults(t, e) {
1782
- this.#r.set(J(t), {
1783
- mutationKey: t,
1784
- defaultOptions: e
1785
- });
1786
- }
1787
- getMutationDefaults(t) {
1788
- const e = [...this.#r.values()], s = {};
1789
- return e.forEach((r) => {
1790
- it(t, r.mutationKey) && Object.assign(s, r.defaultOptions);
1791
- }), s;
1792
- }
1793
- defaultQueryOptions(t) {
1794
- if (t._defaulted)
1795
- return t;
1796
- const e = {
1797
- ...this.#s.queries,
1798
- ...this.getQueryDefaults(t.queryKey),
1799
- ...t,
1800
- _defaulted: !0
1801
- };
1802
- return e.queryHash || (e.queryHash = At(
1803
- e.queryKey,
1804
- e
1805
- )), e.refetchOnReconnect === void 0 && (e.refetchOnReconnect = e.networkMode !== "always"), e.throwOnError === void 0 && (e.throwOnError = !!e.suspense), !e.networkMode && e.persister && (e.networkMode = "offlineFirst"), e.queryFn === Dt && (e.enabled = !1), e;
1806
- }
1807
- defaultMutationOptions(t) {
1808
- return t?._defaulted ? t : {
1809
- ...this.#s.mutations,
1810
- ...t?.mutationKey && this.getMutationDefaults(t.mutationKey),
1811
- ...t,
1812
- _defaulted: !0
1813
- };
1814
- }
1815
- clear() {
1816
- this.#t.clear(), this.#e.clear();
1817
- }
1818
- }, xe = $.createContext(
1819
- void 0
1820
- ), Lt = (t) => {
1821
- const e = $.useContext(xe);
1822
- if (!e)
1823
- throw new Error("No QueryClient set, use QueryClientProvider to set one");
1824
- return e;
1825
- }, ds = ({
1826
- client: t,
1827
- children: e
1828
- }) => ($.useEffect(() => (t.mount(), () => {
1829
- t.unmount();
1830
- }), [t]), /* @__PURE__ */ l(xe.Provider, { value: t, children: e })), we = $.createContext(!1), fs = () => $.useContext(we);
1831
- we.Provider;
1832
- function ps() {
1833
- let t = !1;
1834
- return {
1835
- clearReset: () => {
1836
- t = !1;
1837
- },
1838
- reset: () => {
1839
- t = !0;
1840
- },
1841
- isReset: () => t
1842
- };
1843
- }
1844
- var ms = $.createContext(ps()), gs = () => $.useContext(ms), ys = (t, e) => {
1845
- (t.suspense || t.throwOnError || t.experimental_prefetchInRender) && (e.isReset() || (t.retryOnMount = !1));
1846
- }, vs = (t) => {
1847
- $.useEffect(() => {
1848
- t.clearReset();
1849
- }, [t]);
1850
- }, bs = ({
1851
- result: t,
1852
- errorResetBoundary: e,
1853
- throwOnError: s,
1854
- query: r,
1855
- suspense: i
1856
- }) => t.isError && !e.isReset() && !t.isFetching && r && (i && t.data === void 0 || de(s, [t.error, r])), xs = (t) => {
1857
- if (t.suspense) {
1858
- const s = (i) => i === "static" ? i : Math.max(i ?? 1e3, 1e3), r = t.staleTime;
1859
- t.staleTime = typeof r == "function" ? (...i) => s(r(...i)) : s(r), typeof t.gcTime == "number" && (t.gcTime = Math.max(
1860
- t.gcTime,
1861
- 1e3
1862
- ));
1863
- }
1864
- }, ws = (t, e) => t.isLoading && t.isFetching && !e, Cs = (t, e) => t?.suspense && e.isPending, Jt = (t, e, s) => e.fetchOptimistic(t).catch(() => {
1865
- s.clearReset();
1866
- });
1867
- function Ce(t, e, s) {
1868
- const r = fs(), i = gs(), n = Lt(), o = n.defaultQueryOptions(t);
1869
- n.getDefaultOptions().queries?._experimental_beforeQuery?.(
1870
- o
1871
- ), o._optimisticResults = r ? "isRestoring" : "optimistic", xs(o), ys(o, i), vs(i);
1872
- const a = !n.getQueryCache().get(o.queryHash), [u] = $.useState(
1873
- () => new e(
1874
- n,
1875
- o
1876
- )
1877
- ), h = u.getOptimisticResult(o), c = !r && t.subscribed !== !1;
1878
- if ($.useSyncExternalStore(
1879
- $.useCallback(
1880
- (f) => {
1881
- const d = c ? u.subscribe(A.batchCalls(f)) : U;
1882
- return u.updateResult(), d;
1883
- },
1884
- [u, c]
1885
- ),
1886
- () => u.getCurrentResult(),
1887
- () => u.getCurrentResult()
1888
- ), $.useEffect(() => {
1889
- u.setOptions(o);
1890
- }, [o, u]), Cs(o, h))
1891
- throw Jt(o, u, i);
1892
- if (bs({
1893
- result: h,
1894
- errorResetBoundary: i,
1895
- throwOnError: o.throwOnError,
1896
- query: n.getQueryCache().get(o.queryHash),
1897
- suspense: o.suspense
1898
- }))
1899
- throw h.error;
1900
- return n.getDefaultOptions().queries?._experimental_afterQuery?.(
1901
- o,
1902
- h
1903
- ), o.experimental_prefetchInRender && !X && ws(h, r) && (a ? (
1904
- // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
1905
- Jt(o, u, i)
1906
- ) : (
1907
- // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
1908
- n.getQueryCache().get(o.queryHash)?.promise
1909
- ))?.catch(U).finally(() => {
1910
- u.updateResult();
1911
- }), o.notifyOnChangeProps ? h : u.trackResult(h);
1912
- }
1913
- function Ss(t, e) {
1914
- return Ce(t, ye);
1915
- }
1916
- function Os(t, e) {
1917
- const s = Lt(), [r] = $.useState(
1918
- () => new us(
1919
- s,
1920
- t
1921
- )
1922
- );
1923
- $.useEffect(() => {
1924
- r.setOptions(t);
1925
- }, [r, t]);
1926
- const i = $.useSyncExternalStore(
1927
- $.useCallback(
1928
- (o) => r.subscribe(A.batchCalls(o)),
1929
- [r]
1930
- ),
1931
- () => r.getCurrentResult(),
1932
- () => r.getCurrentResult()
1933
- ), n = $.useCallback(
1934
- (o, a) => {
1935
- r.mutate(o, a).catch(U);
1936
- },
1937
- [r]
1938
- );
1939
- if (i.error && de(r.options.throwOnError, [i.error]))
1940
- throw i.error;
1941
- return { ...i, mutate: n, mutateAsync: i.mutate };
1942
- }
1943
- function ks(t, e) {
1944
- return Ce(
1945
- t,
1946
- as
1947
- );
1948
- }
1949
- const Ps = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), Rs = (t) => t.replace(
1950
- /^([A-Z])|[\s-_]+(\w)/g,
1951
- (e, s, r) => r ? r.toUpperCase() : s.toLowerCase()
1952
- ), Zt = (t) => {
1953
- const e = Rs(t);
1954
- return e.charAt(0).toUpperCase() + e.slice(1);
1955
- }, Se = (...t) => t.filter((e, s, r) => !!e && e.trim() !== "" && r.indexOf(e) === s).join(" ").trim(), Es = (t) => {
1956
- for (const e in t)
1957
- if (e.startsWith("aria-") || e === "role" || e === "title")
1958
- return !0;
1959
- };
1960
- var Ms = {
1961
- xmlns: "http://www.w3.org/2000/svg",
1962
- width: 24,
1963
- height: 24,
1964
- viewBox: "0 0 24 24",
1965
- fill: "none",
1966
- stroke: "currentColor",
1967
- strokeWidth: 2,
1968
- strokeLinecap: "round",
1969
- strokeLinejoin: "round"
1970
- };
1971
- const Ns = It(
1972
- ({
1973
- color: t = "currentColor",
1974
- size: e = 24,
1975
- strokeWidth: s = 2,
1976
- absoluteStrokeWidth: r,
1977
- className: i = "",
1978
- children: n,
1979
- iconNode: o,
1980
- ...a
1981
- }, u) => bt(
1982
- "svg",
1983
- {
1984
- ref: u,
1985
- ...Ms,
1986
- width: e,
1987
- height: e,
1988
- stroke: t,
1989
- strokeWidth: r ? Number(s) * 24 / Number(e) : s,
1990
- className: Se("lucide", i),
1991
- ...!n && !Es(a) && { "aria-hidden": "true" },
1992
- ...a
1993
- },
1994
- [
1995
- ...o.map(([h, c]) => bt(h, c)),
1996
- ...Array.isArray(n) ? n : [n]
1997
- ]
1998
- )
1999
- );
2000
- const at = (t, e) => {
2001
- const s = It(
2002
- ({ className: r, ...i }, n) => bt(Ns, {
2003
- ref: n,
2004
- iconNode: e,
2005
- className: Se(
2006
- `lucide-${Ps(Zt(t))}`,
2007
- `lucide-${t}`,
2008
- r
2009
- ),
2010
- ...i
2011
- })
2012
- );
2013
- return s.displayName = Zt(t), s;
2014
- };
2015
- const Is = [
2016
- ["path", { d: "m5 12 7-7 7 7", key: "hav0vg" }],
2017
- ["path", { d: "M12 19V5", key: "x0mq9r" }]
2018
- ], Ts = at("arrow-up", Is);
2019
- const Fs = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]], As = at("chevron-down", Fs);
2020
- const Ds = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], Mt = at("loader-circle", Ds);
2021
- const Qs = [
2022
- [
2023
- "path",
2024
- {
2025
- d: "M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",
2026
- key: "18887p"
2027
- }
2028
- ],
2029
- ["path", { d: "M7 11h10", key: "1twpyw" }],
2030
- ["path", { d: "M7 15h6", key: "d9of3u" }],
2031
- ["path", { d: "M7 7h8", key: "af5zfr" }]
2032
- ], te = at("message-square-text", Qs);
2033
- const $s = [
2034
- ["path", { d: "M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8", key: "1p45f6" }],
2035
- ["path", { d: "M21 3v5h-5", key: "1q7to0" }]
2036
- ], ee = at("rotate-cw", $s), nt = null, { min: Y, max: B, abs: se, floor: Ls } = Math, Oe = (t, e, s) => Y(s, B(e, t)), ke = (t) => [...t].sort(((e, s) => e - s)), Pe = typeof queueMicrotask == "function" ? queueMicrotask : (t) => {
2037
- Promise.resolve().then(t);
2038
- }, Nt = () => {
2039
- let t;
2040
- return [new Promise(((e) => {
2041
- t = e;
2042
- })), t];
2043
- }, Re = (t) => {
2044
- let e;
2045
- return () => (t && (e = t(), t = void 0), e);
2046
- }, rt = (t, e, s) => {
2047
- const r = s ? "unshift" : "push";
2048
- for (let i = 0; i < e; i++) t[r](-1);
2049
- return t;
2050
- }, Ee = (t, e) => {
2051
- const s = t.t[e];
2052
- return s === -1 ? t.o : s;
2053
- }, qs = (t, e, s) => {
2054
- const r = t.t[e] === -1;
2055
- return t.t[e] = s, t.i = Y(e, t.i), r;
2056
- }, ht = (t, e) => {
2057
- if (!t.l) return 0;
2058
- if (t.i >= e) return t.u[e];
2059
- t.i < 0 && (t.u[0] = 0, t.i = 0);
2060
- let s = t.i, r = t.u[s];
2061
- for (; s < e; ) r += Ee(t, s), t.u[++s] = r;
2062
- return t.i = e, r;
2063
- }, Z = (t, e, s = 0, r = t.l - 1) => {
2064
- let i = s;
2065
- for (; s <= r; ) {
2066
- const n = Ls((s + r) / 2);
2067
- ht(t, n) <= e ? (i = n, s = n + 1) : r = n - 1;
2068
- }
2069
- return Oe(i, 0, t.l - 1);
2070
- }, re = (t, e, s) => {
2071
- const r = e - t.l;
2072
- return t.i = s ? -1 : Y(e - 1, t.i), t.l = e, r > 0 ? (rt(t.u, r), rt(t.t, r, s), t.o * r) : (t.u.splice(r), (s ? t.t.splice(0, -r) : t.t.splice(r)).reduce(((i, n) => i - (n === -1 ? t.o : n)), 0));
2073
- }, Us = typeof window < "u", _s = (t) => t.documentElement, js = (t) => t.ownerDocument, Ks = (t) => t.defaultView, Me = /* @__PURE__ */ Re((() => !!/iP(hone|od|ad)/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 0)), zs = /* @__PURE__ */ Re((() => "scrollBehavior" in _s(document).style)), Bs = (t) => B(t.h(), t.p()), Hs = (t, e = 40, s = 0, r, i = !1) => {
2074
- let n = !!s, o = 1, a = 0, u = 0, h = 0, c = 0, f = 0, d = 0, C = 0, g = 0, p = nt, y = [0, n ? B(s - 1, 0) : -1], b = 0, R = !1;
2075
- const P = ((x, m, S) => ({ o: m, t: S ? rt(S.slice(0, Y(x, S.length)), B(0, x - S.length)) : rt([], x), l: x, i: -1, u: rt([], x + 1) }))(t, r ? r[1] : e, r && r[0]), D = /* @__PURE__ */ new Set(), L = () => h - u, O = () => L() + f + c, T = (x, m) => ((S, F, I, k) => {
2076
- if (k = Y(k, S.l - 1), ht(S, k) <= F) {
2077
- const v = Z(S, I, k);
2078
- return [Z(S, F, k, v), v];
2079
- }
2080
- {
2081
- const v = Z(S, F, void 0, k);
2082
- return [v, Z(S, I, v)];
2083
- }
2084
- })(P, x, m, y[0]), E = () => ht(P, P.l), N = (x, m) => {
2085
- const S = ht(P, x) - f;
2086
- return m ? E() - S - q(x) : S;
2087
- }, q = (x) => Ee(P, x), K = (x, m = -1) => P.t[x] === m, G = (x) => {
2088
- x && (Me() && C !== 0 || p && g === 1 ? f += x : c += x);
2089
- };
2090
- return { v: () => {
2091
- D.clear();
2092
- }, m: () => o, _: () => ((x) => [x.t.slice(), x.o])(P), S: (x = 200) => {
2093
- if (!R || n) return y;
2094
- let m, S;
2095
- if (d) [m, S] = y;
2096
- else {
2097
- let F = B(0, O()), I = F + a;
2098
- i || (x = B(0, x), C !== 1 && (F -= x), C !== 2 && (I += x)), [m, S] = y = T(B(0, F), B(0, I)), p && (m = Y(m, p[0]), S = B(S, p[1]));
2099
- }
2100
- return [B(m, 0), Y(S, P.l - 1)];
2101
- }, $: (x) => Z(P, x - u), I: K, k: N, R: q, T: () => P.l, C: () => h, M: () => C !== 0, p: () => a, O: () => u, h: E, H: () => (d = c, c = 0, [d, g === 2]), W: (x, m) => {
2102
- const S = [x, m];
2103
- return D.add(S), () => {
2104
- D.delete(S);
2105
- };
2106
- }, B: (x, m) => {
2107
- let S, F, I = 0;
2108
- switch (x) {
2109
- case 1: {
2110
- if (m === h && g === 0) break;
2111
- const k = d;
2112
- d = 0;
2113
- const v = m - h, Q = se(v);
2114
- k && Q < se(k) + 1 || g !== 0 || (C = v < 0 ? 2 : 1), n && (n = !1), h = m, I = 4;
2115
- const H = L();
2116
- H >= -a && H <= E() && (I += 1, F = Q > a);
2117
- break;
2118
- }
2119
- case 2:
2120
- I = 8, C !== 0 && (S = !0, I += 1), C = 0, g = 0, p = nt;
2121
- break;
2122
- case 3: {
2123
- const k = m.filter((([v, Q]) => !K(v, Q)));
2124
- if (!k.length) break;
2125
- G(k.reduce(((v, [Q, H]) => ((g === 2 || (p && g === 1 ? Q < p[0] : N(Q + (C === 0 && g === 0 ? 1 : 0)) < L())) && (v += H - q(Q)), v)), 0));
2126
- for (const [v, Q] of k) {
2127
- const H = q(v), ot = qs(P, v, Q);
2128
- i && (b += ot ? Q : Q - H);
2129
- }
2130
- i && a && b > a && (G(((v, Q) => {
2131
- let H = 0;
2132
- const ot = [];
2133
- v.t.forEach(((jt, De) => {
2134
- jt !== -1 && (ot.push(jt), De < Q && H++);
2135
- })), v.i = -1;
2136
- const ct = ke(ot), _t = ct.length, mt = _t / 2 | 0, Fe = _t % 2 == 0 ? (ct[mt - 1] + ct[mt]) / 2 : ct[mt], Ae = v.o;
2137
- return ((v.o = Fe) - Ae) * B(Q - H, 0);
2138
- })(P, Z(P, O()))), i = !1), I = 3, F = !0;
2139
- break;
2140
- }
2141
- case 4:
2142
- a !== m && (a || (R = F = !0), a = m, I = 3);
2143
- break;
2144
- case 5:
2145
- m[1] ? (G(re(P, m[0], !0)), g = 2, I = 1) : (re(P, m[0]), I = 1);
2146
- break;
2147
- case 6:
2148
- u = m;
2149
- break;
2150
- case 7:
2151
- g = 1;
2152
- break;
2153
- case 8:
2154
- p = T(m, m + a), I = 1;
2155
- }
2156
- I && (o = 1 + (2147483647 & o), S && f && (c += f, f = 0), D.forEach((([k, v]) => {
2157
- I & k && v(F);
2158
- })));
2159
- } };
2160
- }, qt = setTimeout, yt = (t, e) => e ? -t : t, Gs = (t, e, s, r, i, n) => {
2161
- const o = Date.now;
2162
- let a = 0, u = !1, h = !1, c = !1, f = !1;
2163
- const d = (() => {
2164
- let b;
2165
- const R = () => {
2166
- b != nt && clearTimeout(b);
2167
- }, P = () => {
2168
- R(), b = qt((() => {
2169
- b = nt, (() => {
2170
- if (u || h) return u = !1, void d();
2171
- c = !1, t.B(2);
2172
- })();
2173
- }), 150);
2174
- };
2175
- return P.J = R, P;
2176
- })(), C = () => {
2177
- a = o(), c && (f = !0), t.B(1, r()), d();
2178
- }, g = (b) => {
2179
- if (u || !t.M() || b.ctrlKey) return;
2180
- const R = o() - a;
2181
- 150 > R && 50 < R && (s ? b.deltaX : b.deltaY) && (u = !0);
2182
- }, p = () => {
2183
- h = !0, c = f = !1;
2184
- }, y = () => {
2185
- h = !1, Me() && (c = !0);
2186
- };
2187
- return e.addEventListener("scroll", C), e.addEventListener("wheel", g, { passive: !0 }), e.addEventListener("touchstart", p, { passive: !0 }), e.addEventListener("touchend", y, { passive: !0 }), { A: () => {
2188
- e.removeEventListener("scroll", C), e.removeEventListener("wheel", g), e.removeEventListener("touchstart", p), e.removeEventListener("touchend", y), d.J();
2189
- }, L: () => {
2190
- const [b, R] = t.H();
2191
- b && (i(b, R, f), f = !1, R && t.p() > t.h() && t.B(1, r()));
2192
- } };
2193
- }, Ws = (t, e, s) => {
2194
- let r;
2195
- return [async (i, n) => {
2196
- if (!await e()) return;
2197
- r && r();
2198
- const o = () => {
2199
- const [a, u] = Nt();
2200
- return r = () => {
2201
- u(!1);
2202
- }, t.p() && qt(r, 150), [a, t.W(2, (() => {
2203
- u(!0);
2204
- }))];
2205
- };
2206
- if (n && zs()) t.B(8, i()), Pe((async () => {
2207
- for (; ; ) {
2208
- let a = !0;
2209
- for (let [c, f] = t.S(); c <= f; c++) if (t.I(c)) {
2210
- a = !1;
2211
- break;
2212
- }
2213
- if (a) break;
2214
- const [u, h] = o();
2215
- try {
2216
- if (!await u) return;
2217
- } finally {
2218
- h();
2219
- }
2220
- }
2221
- t.B(7), s(i(), n);
2222
- }));
2223
- else for (; ; ) {
2224
- const [a, u] = o();
2225
- try {
2226
- if (t.B(7), s(i()), !await a) return;
2227
- } finally {
2228
- u();
2229
- }
2230
- }
2231
- }, () => {
2232
- r && r();
2233
- }];
2234
- }, Vs = (t, e) => {
2235
- let s, r, i = Nt(), n = !1;
2236
- const o = e ? "scrollLeft" : "scrollTop", a = e ? "overflowX" : "overflowY", [u, h] = Ws(t, (() => i[0]), ((c, f) => {
2237
- c = yt(c, n), f ? s.scrollTo({ [e ? "left" : "top"]: c, behavior: "smooth" }) : s[o] = c;
2238
- }));
2239
- return { N(c) {
2240
- s = c, e && (n = getComputedStyle(c).direction === "rtl"), r = Gs(t, c, e, (() => yt(c[o], n)), ((f, d, C) => {
2241
- if (C) {
2242
- const g = c.style, p = g[a];
2243
- g[a] = "hidden", qt((() => {
2244
- g[a] = p;
2245
- }));
2246
- }
2247
- c[o] = yt(t.C() + f, n), d && h();
2248
- })), i[1](!0);
2249
- }, v() {
2250
- r && r.A(), i[1](!1), i = Nt();
2251
- }, P: () => n, V(c) {
2252
- u((() => c));
2253
- }, X(c) {
2254
- c += t.C(), u((() => c));
2255
- }, Y(c, { align: f, smooth: d, offset: C = 0 } = {}) {
2256
- if (c = Oe(c, 0, t.T() - 1), f === "nearest") {
2257
- const g = t.k(c), p = t.C();
2258
- if (g < p) f = "start";
2259
- else {
2260
- if (!(g + t.R(c) > p + t.p())) return;
2261
- f = "end";
2262
- }
2263
- }
2264
- u((() => C + t.O() + t.k(c) + (f === "end" ? t.R(c) - t.p() : f === "center" ? (t.R(c) - t.p()) / 2 : 0)), d);
2265
- }, q: () => {
2266
- r && r.L();
2267
- } };
2268
- }, Ys = (t) => {
2269
- let e;
2270
- return { D(s) {
2271
- (e || (e = new (Ks(js(s))).ResizeObserver(t))).observe(s);
2272
- }, j(s) {
2273
- e.unobserve(s);
2274
- }, A() {
2275
- e && e.disconnect();
2276
- } };
2277
- }, Xs = (t, e) => {
2278
- let s;
2279
- const r = e ? "width" : "height", i = /* @__PURE__ */ new WeakMap(), n = Ys(((o) => {
2280
- const a = [];
2281
- for (const { target: u, contentRect: h } of o) if (u.offsetParent) if (u === s) t.B(4, h[r]);
2282
- else {
2283
- const c = i.get(u);
2284
- c != nt && a.push([c, h[r]]);
2285
- }
2286
- a.length && t.B(3, a);
2287
- }));
2288
- return { G(o) {
2289
- n.D(s = o);
2290
- }, U: (o, a) => (i.set(o, a), n.D(o), () => {
2291
- i.delete(o), n.j(o);
2292
- }), v: n.A };
2293
- }, pt = Us ? xt : wt, _ = "current", Ne = (t, e) => {
2294
- if (Array.isArray(t)) for (const s of t) Ne(s, e);
2295
- else t == null || typeof t == "boolean" || e.push(t);
2296
- }, Js = (t, e) => {
2297
- const s = t.key;
2298
- return s ?? "_" + e;
2299
- }, Zs = (t) => {
2300
- const e = j(null);
2301
- return e[_] || (e[_] = t());
2302
- }, ie = (t) => {
2303
- const e = j(t);
2304
- return pt((() => {
2305
- e[_] = t;
2306
- }), [t]), e;
2307
- }, tr = /* @__PURE__ */ Le((({ Z: t, ee: e, te: s, oe: r, ne: i, re: n, se: o, ie: a }) => {
2308
- const u = j(null);
2309
- pt((() => e(u[_], s)), [s]);
2310
- const h = Tt((() => {
2311
- const c = { contain: "layout style", position: i && a ? void 0 : "absolute", [o ? "height" : "width"]: "100%", [o ? "top" : "left"]: 0, [o ? "left" : "top"]: r, visibility: !i || a ? void 0 : "hidden" };
2312
- return o && (c.display = "inline-flex"), c;
2313
- }), [r, i, a, o]);
2314
- return l(n, typeof n == "string" ? { ref: u, style: h, children: t } : { ref: u, style: h, index: s, children: t });
2315
- })), er = (t, e) => Tt((() => {
2316
- if (typeof t == "function") return [(r) => t(e[r], r), e.length];
2317
- const s = ((r) => {
2318
- const i = [];
2319
- return Ne(r, i), i;
2320
- })(t);
2321
- return [(r) => s[r], s.length];
2322
- }), [t, e]), sr = /* @__PURE__ */ It((({ children: t, data: e, bufferSize: s, itemSize: r, shift: i, horizontal: n, keepMounted: o, cache: a, startMargin: u = 0, ssrCount: h, as: c = "div", item: f = "div", scrollRef: d, onScroll: C, onScrollEnd: g }, p) => {
2323
- const [y, b] = er(t, e), R = j(null), P = j(!!h), D = ie(C), L = ie(g), [O, T, E, N] = Zs((() => {
2324
- const k = !!n, v = Hs(b, r, h, a, !r);
2325
- return [v, Xs(v, k), Vs(v, k), k];
2326
- }));
2327
- b !== O.T() && O.B(5, [b, i]), u !== O.O() && O.B(6, u);
2328
- const [q, K] = Qe(O.m, void 0, O.m), G = O.M(), x = O.h(), m = E.P(), S = !N && m ? "unshift" : "push", F = [], I = (k) => {
2329
- const v = y(k);
2330
- return l(tr, { ee: T.U, te: k, oe: O.k(k, m), ne: O.I(k), re: f, Z: v, se: N, ie: P[_] }, Js(v, k));
2331
- };
2332
- if (pt((() => {
2333
- P[_] = !1, O.W(1, ((v) => {
2334
- v ? _e(K) : K();
2335
- })), O.W(4, (() => {
2336
- D[_] && D[_](O.C());
2337
- })), O.W(8, (() => {
2338
- L[_] && L[_]();
2339
- }));
2340
- const k = (v) => {
2341
- T.G(v), E.N(v);
2342
- };
2343
- return d ? Pe((() => {
2344
- d[_] && k(d[_]);
2345
- })) : k(R[_].parentElement), () => {
2346
- O.v(), T.v(), E.v();
2347
- };
2348
- }), []), pt((() => {
2349
- E.q();
2350
- }), [q]), $e(p, (() => ({ get cache() {
2351
- return O._();
2352
- }, get scrollOffset() {
2353
- return O.C();
2354
- }, get scrollSize() {
2355
- return Bs(O);
2356
- }, get viewportSize() {
2357
- return O.p();
2358
- }, findItemIndex: O.$, getItemOffset: O.k, getItemSize: O.R, scrollToIndex: E.Y, scrollTo: E.V, scrollBy: E.X })), []), o) {
2359
- const k = new Set(o);
2360
- for (let [v, Q] = O.S(s); v <= Q; v++) k.add(v);
2361
- ke([...k]).forEach(((v) => {
2362
- F[S](I(v));
2363
- }));
2364
- } else for (let [k, v] = O.S(s); k <= v; k++) F[S](I(k));
2365
- return l(c, { ref: R, style: { contain: "size style", overflowAnchor: "none", flex: "none", position: "relative", width: N ? x : "100%", height: N ? "100%" : x, pointerEvents: G ? "none" : void 0 }, children: F });
2366
- }));
2367
- async function rr(t, e) {
2368
- return (await Ft.get(`/chats/${t}/entries`, {
2369
- params: e
2370
- })).data?.entries ?? [];
2371
- }
2372
- const ne = 50, Ie = "chat-messages", ir = (t, e = { limit: ne }) => {
2373
- const s = e.limit ?? ne;
2374
- return {
2375
- queryKey: [Ie, t ? Number(t) : null, { limit: s }],
2376
- enabled: t !== null,
2377
- initialPageParam: null,
2378
- refetchInterval: 5e3,
2379
- // Fetch new messages every 5 seconds
2380
- queryFn: async ({ pageParam: r }) => {
2381
- if (!t) throw new Error("Chat ID is required");
2382
- return rr(t, {
2383
- limit: s,
2384
- prev_message: r ? JSON.stringify(r) : void 0
2385
- });
2386
- },
2387
- getNextPageParam: (r) => !r || r.length !== s ? null : r[r.length - 1]
2388
- };
2389
- };
2390
- function nr(t, e) {
2391
- return ks(ir(t, e));
2392
- }
2393
- async function ar(t) {
2394
- try {
2395
- return (await Ft.get(`/games/${t}`)).data.game;
2396
- } catch (e) {
2397
- if (e instanceof ce && e.response?.status === 404)
2398
- return null;
2399
- throw e;
2400
- }
2401
- }
2402
- const or = "game", cr = (t) => ({
2403
- queryKey: [or, Number(t)],
2404
- queryFn: async () => ar(t),
2405
- staleTime: 1 / 0
2406
- });
2407
- function ur(t) {
2408
- return Ss(cr(t));
2409
- }
2410
- class Te extends Error {
2411
- constructor(e = "You are sending messages too quickly. Please wait a moment.") {
2412
- super(e), this.name = "RateLimitError";
2413
- }
2414
- }
2415
- async function hr(t) {
2416
- try {
2417
- return (await Ft.post(`/chats/${t.chatID}/messages`, {
2418
- chatID: t.chatID,
2419
- content: t.content
2420
- })).data;
2421
- } catch (e) {
2422
- throw e instanceof ce && e.response?.status === 429 ? new Te() : e;
2423
- }
2424
- }
2425
- function lr(t) {
2426
- const e = Lt(), { onSettled: s, onError: r, ...i } = t ?? {};
2427
- return Os({
2428
- mutationFn: (n) => hr(n),
2429
- onError: (n, ...o) => {
2430
- n instanceof Te && console.error(n.message), r?.(n, ...o);
2431
- },
2432
- onSettled: (n, ...o) => {
2433
- n && e.invalidateQueries({ queryKey: [Ie, n.entry.ChatID] }), s?.(n, ...o);
2434
- },
2435
- ...i
2436
- });
2437
- }
2438
- const vt = 255;
2439
- function dr({ chatId: t, onMessageSent: e }) {
2440
- const [s, r] = oe(""), i = j(null), n = gt((y) => y.user), o = gt((y) => y.isAuthenticated), a = gt((y) => y.login), { mutate: u, isPending: h } = lr({
2441
- onSuccess: () => {
2442
- r(""), e?.();
2443
- }
2444
- }), c = () => {
2445
- const y = s.trim();
2446
- if (!(!y || h)) {
2447
- if (!o) {
2448
- a();
2449
- return;
2450
- }
2451
- u({ chatID: t, content: y });
2452
- }
2453
- }, f = (y) => {
2454
- y.key === "Enter" && !y.shiftKey && (y.preventDefault(), c());
2455
- }, d = s.length > vt, C = h || !s.trim() || d, g = n?.SolanaAddress || n?.ID?.toString() || "anonymous", p = n?.ImageURL || `https://api.dicebear.com/7.x/avataaars/svg?seed=${g}`;
2456
- return /* @__PURE__ */ l("div", { className: "chat-input-container", children: /* @__PURE__ */ M("div", { className: "chat-input-wrapper", children: [
2457
- /* @__PURE__ */ l(
2458
- "textarea",
2459
- {
2460
- ref: i,
2461
- value: s,
2462
- onChange: (y) => r(y.target.value),
2463
- onKeyDown: f,
2464
- placeholder: o ? "Write a message..." : "Login to send messages...",
2465
- className: "chat-input-textarea",
2466
- disabled: h,
2467
- maxLength: vt + 50
2468
- }
2469
- ),
2470
- /* @__PURE__ */ M("div", { className: "chat-input-footer", children: [
2471
- o && n && /* @__PURE__ */ l("div", { className: "chat-input-avatar", children: /* @__PURE__ */ l("img", { src: p, alt: "You", className: "chat-input-avatar-img" }) }),
2472
- /* @__PURE__ */ M("span", { className: `chat-input-counter ${d ? "chat-input-counter--error" : ""}`, children: [
2473
- s.length,
2474
- "/",
2475
- vt
2476
- ] }),
2477
- /* @__PURE__ */ l("div", { className: "chat-input-divider" }),
2478
- /* @__PURE__ */ l(
2479
- "button",
2480
- {
2481
- type: "button",
2482
- onClick: c,
2483
- disabled: C,
2484
- className: "chat-input-button",
2485
- "aria-label": o ? "Send message" : "Login to send",
2486
- children: h ? /* @__PURE__ */ l(Mt, { className: "chat-input-spinner" }) : /* @__PURE__ */ l(Ts, { className: "chat-input-icon" })
2487
- }
2488
- )
2489
- ] })
2490
- ] }) });
2491
- }
2492
- function ae(t, e = 4) {
2493
- return !t || t.length < e * 2 + 3 ? t : `${t.slice(0, e)}...${t.slice(-e)}`;
2494
- }
2495
- function Ut(t) {
2496
- const e = new Date(t), r = (/* @__PURE__ */ new Date()).getTime() - e.getTime(), i = Math.floor(r / 1e3), n = Math.floor(i / 60), o = Math.floor(n / 60), a = Math.floor(o / 24);
2497
- return i < 60 ? "now" : n < 60 ? `${n}m` : o < 24 ? `${o}h` : a < 7 ? `${a}d` : e.toLocaleDateString();
2498
- }
2499
- function fr({ entry: t }) {
2500
- if (t.EntryType !== "user_message" || !t.UserMessage) return null;
2501
- const { UserMessage: e } = t, s = e.User, r = s.SolanaAddress || s.ID.toString(), i = s.ImageURL || `https://api.dicebear.com/7.x/avataaars/svg?seed=${r}`;
2502
- return /* @__PURE__ */ M("div", { className: "chat-message-card", "data-entry-id": t.ID, "data-entry-type": "user_message", children: [
2503
- /* @__PURE__ */ l("div", { className: "chat-message-avatar", children: /* @__PURE__ */ l(
2504
- "img",
2505
- {
2506
- src: i,
2507
- alt: ae(s.SolanaAddress),
2508
- className: "chat-message-avatar-img"
2509
- }
2510
- ) }),
2511
- /* @__PURE__ */ M("div", { className: "chat-message-content", children: [
2512
- /* @__PURE__ */ M("div", { className: "chat-message-header", children: [
2513
- /* @__PURE__ */ l("span", { className: "chat-message-username", children: ae(s.SolanaAddress) }),
2514
- /* @__PURE__ */ l("span", { className: "chat-message-time", children: Ut(t.CreatedAt) })
2515
- ] }),
2516
- /* @__PURE__ */ l("p", { className: "chat-message-text", children: e.Content })
2517
- ] })
2518
- ] });
2519
- }
2520
- function pr({ entry: t }) {
2521
- if (t.EntryType !== "game_event" || !t.GameEvent) return null;
2522
- const { GameEvent: e } = t, s = e.Game;
2523
- return /* @__PURE__ */ l(
2524
- "div",
2525
- {
2526
- className: "chat-message-card chat-message-card--event",
2527
- "data-entry-id": t.ID,
2528
- "data-entry-type": "game_event",
2529
- children: /* @__PURE__ */ M("div", { className: "chat-message-content", children: [
2530
- /* @__PURE__ */ M("div", { className: "chat-message-header", children: [
2531
- s && /* @__PURE__ */ l("span", { className: "chat-message-username chat-message-username--link", children: e.Title }),
2532
- !s && /* @__PURE__ */ l("span", { className: "chat-message-username", children: e.Title }),
2533
- /* @__PURE__ */ l("span", { className: "chat-message-time", children: Ut(t.CreatedAt) })
2534
- ] }),
2535
- /* @__PURE__ */ M("div", { className: "chat-message-event-content", children: [
2536
- /* @__PURE__ */ l("p", { className: "chat-message-text chat-message-text--title", children: e.Title }),
2537
- e.ShortSummary && /* @__PURE__ */ l("p", { className: "chat-message-text chat-message-text--summary", children: e.ShortSummary }),
2538
- e.Description && /* @__PURE__ */ l("p", { className: "chat-message-text", children: e.Description })
2539
- ] })
2540
- ] })
2541
- }
2542
- );
2543
- }
2544
- function mr({ entry: t }) {
2545
- if (t.EntryType !== "token_event" || !t.TokenEvent) return null;
2546
- const { TokenEvent: e } = t, s = e.Token;
2547
- return /* @__PURE__ */ l(
2548
- "div",
2549
- {
2550
- className: "chat-message-card chat-message-card--event",
2551
- "data-entry-id": t.ID,
2552
- "data-entry-type": "token_event",
2553
- children: /* @__PURE__ */ M("div", { className: "chat-message-content", children: [
2554
- /* @__PURE__ */ M("div", { className: "chat-message-header", children: [
2555
- s && /* @__PURE__ */ M("span", { className: "chat-message-username chat-message-username--link", children: [
2556
- e.Title,
2557
- " (",
2558
- e.Token?.Ticker,
2559
- ")"
2560
- ] }),
2561
- !s && /* @__PURE__ */ l("span", { className: "chat-message-username", children: e.Title }),
2562
- /* @__PURE__ */ l("span", { className: "chat-message-time", children: Ut(t.CreatedAt) })
2563
- ] }),
2564
- /* @__PURE__ */ M("div", { className: "chat-message-event-content", children: [
2565
- /* @__PURE__ */ l("p", { className: "chat-message-text chat-message-text--title", children: e.Title }),
2566
- e.ShortSummary && /* @__PURE__ */ l("p", { className: "chat-message-text chat-message-text--summary", children: e.ShortSummary }),
2567
- e.Description && /* @__PURE__ */ l("p", { className: "chat-message-text", children: e.Description })
2568
- ] })
2569
- ] })
2570
- }
2571
- );
2572
- }
2573
- function gr({ entry: t }) {
2574
- switch (t.EntryType) {
2575
- case "user_message":
2576
- return /* @__PURE__ */ l(fr, { entry: t });
2577
- case "game_event":
2578
- return /* @__PURE__ */ l(pr, { entry: t });
2579
- case "token_event":
2580
- return /* @__PURE__ */ l(mr, { entry: t });
2581
- default:
2582
- return null;
2583
- }
2584
- }
2585
- const yr = new ls({
2586
- defaultOptions: {
2587
- queries: {
2588
- staleTime: 1e3 * 60,
2589
- // 1 minute
2590
- refetchOnWindowFocus: !1
2591
- }
2592
- }
2593
- });
2594
- function vr({ gameId: t, onOpenChange: e }) {
2595
- const [s, r] = oe(!1), i = j(!1), n = j(!1), o = j(!1), a = j(!1), u = j(!0), h = j(!1), c = j(null), {
2596
- data: f,
2597
- isLoading: d,
2598
- isError: C,
2599
- error: g,
2600
- refetch: p
2601
- } = ur(t), y = f?.ChatID ?? null, {
2602
- data: b,
2603
- fetchNextPage: R,
2604
- hasNextPage: P,
2605
- isFetchingNextPage: D,
2606
- isLoading: L,
2607
- isFetching: O,
2608
- isError: T,
2609
- refetch: E
2610
- } = nr(y), N = Tt(() => b ? b.pages.flat().reverse() : [], [b]), q = Kt(() => {
2611
- u.current = !0, n.current = !0;
2612
- }, []), K = Kt(() => {
2613
- i.current || !P || D || (i.current = !0, a.current = !0, R().finally(() => {
2614
- i.current = !1;
2615
- }));
2616
- }, [P, D, R]);
2617
- xt(() => {
2618
- a.current = !1;
2619
- }), wt(() => {
2620
- if (!c.current) return;
2621
- const m = c.current, S = N.length - 1;
2622
- u.current && S >= 0 && m.scrollToIndex(S, { align: "end" });
2623
- }, [N.length]), xt(() => {
2624
- if (s && c.current && N.length > 0 && !h.current) {
2625
- const m = c.current, S = N.length - 1;
2626
- m.scrollToIndex(S, { align: "end" }), u.current = !0, h.current = !0;
2627
- }
2628
- s || (h.current = !1);
2629
- }, [s, N.length]), wt(() => {
2630
- const m = c.current;
2631
- if (!m) return;
2632
- const S = o.current && !O;
2633
- if (n.current && S) {
2634
- const F = N.length - 1;
2635
- F >= 0 && m.scrollToIndex(F, { align: "end" }), n.current = !1;
2636
- }
2637
- o.current = O;
2638
- }, [O, N.length]);
2639
- const G = () => {
2640
- const m = !s;
2641
- r(m), e?.(m);
2642
- }, x = () => d ? /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2643
- /* @__PURE__ */ l("div", { className: "chat-empty-icon", children: /* @__PURE__ */ l(Mt, { className: "chat-spinner" }) }),
2644
- /* @__PURE__ */ l("p", { className: "chat-empty-text", children: "Loading game data..." })
2645
- ] }) : C ? /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2646
- /* @__PURE__ */ l("p", { className: "chat-empty-title", children: "Failed to load game" }),
2647
- /* @__PURE__ */ l("p", { className: "chat-empty-text", children: g instanceof Error ? g.message : "Unknown error occurred" }),
2648
- /* @__PURE__ */ M("button", { type: "button", onClick: () => p(), className: "chat-retry-button", children: [
2649
- /* @__PURE__ */ l(ee, { className: "chat-retry-icon" }),
2650
- "Retry"
2651
- ] })
2652
- ] }) : y ? L ? /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2653
- /* @__PURE__ */ l("div", { className: "chat-empty-icon", children: /* @__PURE__ */ l(Mt, { className: "chat-spinner" }) }),
2654
- /* @__PURE__ */ l("p", { className: "chat-empty-text", children: "Loading messages..." })
2655
- ] }) : T ? /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2656
- /* @__PURE__ */ l("p", { className: "chat-empty-title", children: "Failed to load messages" }),
2657
- /* @__PURE__ */ M("button", { type: "button", onClick: () => E(), className: "chat-retry-button", children: [
2658
- /* @__PURE__ */ l(ee, { className: "chat-retry-icon" }),
2659
- "Retry"
2660
- ] })
2661
- ] }) : N.length === 0 ? /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2662
- /* @__PURE__ */ l("div", { className: "chat-empty-icon", children: /* @__PURE__ */ l(te, { className: "chat-empty-svg" }) }),
2663
- /* @__PURE__ */ l("p", { className: "chat-empty-title", children: "No messages yet" }),
2664
- /* @__PURE__ */ l("p", { className: "chat-empty-text", children: "Be the first to start the conversation!" })
2665
- ] }) : /* @__PURE__ */ M("div", { className: "chat-messages-container", children: [
2666
- /* @__PURE__ */ l("div", { className: "chat-messages-spacer" }),
2667
- /* @__PURE__ */ l(
2668
- sr,
2669
- {
2670
- ref: c,
2671
- shift: a.current,
2672
- onScroll: (m) => {
2673
- c.current && (u.current = m - c.current.scrollSize + c.current.viewportSize >= -1.5, m < 100 && (a.current = !0, K()));
2674
- },
2675
- children: N.map((m) => /* @__PURE__ */ l(gr, { entry: m }, m.ID))
2676
- }
2677
- )
2678
- ] }) : /* @__PURE__ */ M("div", { className: "chat-empty", children: [
2679
- /* @__PURE__ */ l("p", { className: "chat-empty-title", children: "Chat not available" }),
2680
- /* @__PURE__ */ l("p", { className: "chat-empty-text", children: "This game does not have a chat configured." })
2681
- ] });
2682
- return s ? /* @__PURE__ */ M("div", { className: "chat-widget", children: [
2683
- /* @__PURE__ */ l("div", { className: "chat-widget-header", children: /* @__PURE__ */ l(
2684
- "button",
2685
- {
2686
- type: "button",
2687
- className: "chat-widget-header-button",
2688
- onClick: G,
2689
- "aria-label": "Minimize chat",
2690
- children: /* @__PURE__ */ l(As, { className: "chat-widget-header-icon" })
2691
- }
2692
- ) }),
2693
- /* @__PURE__ */ l("div", { className: "chat-widget-body", children: x() }),
2694
- y && /* @__PURE__ */ l(dr, { chatId: y, onMessageSent: q })
2695
- ] }) : /* @__PURE__ */ l(
2696
- "button",
2697
- {
2698
- type: "button",
2699
- className: "chat-widget-bubble",
2700
- onClick: G,
2701
- "aria-label": "Open chat",
2702
- children: /* @__PURE__ */ l(te, { className: "chat-widget-bubble-icon" })
2703
- }
2704
- );
2705
- }
2706
- function br(t) {
2707
- return /* @__PURE__ */ l(ds, { client: yr, children: /* @__PURE__ */ l(vr, { ...t }) });
2708
- }
2709
- const xr = ":host{--chat-position-offset-x: 20px;--chat-position-offset-y: 20px;position:fixed;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;font-size:14px;line-height:1.5;color:#fffffff2;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;inset:auto}:host:not([data-side]):not([data-vertical]){left:auto;right:var(--chat-position-offset-x, 20px);top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-side=left][data-vertical=top]{left:var(--chat-position-offset-x, 20px);right:auto;top:var(--chat-position-offset-y, 20px);bottom:auto}:host[data-side=right][data-vertical=top]{left:auto;right:var(--chat-position-offset-x, 20px);top:var(--chat-position-offset-y, 20px);bottom:auto}:host[data-side=left][data-vertical=bottom]{left:var(--chat-position-offset-x, 20px);right:auto;top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-side=right][data-vertical=bottom]{left:auto;right:var(--chat-position-offset-x, 20px);top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-side=left]{left:var(--chat-position-offset-x, 20px);right:auto}:host[data-side=right]{left:auto;right:var(--chat-position-offset-x, 20px)}:host[data-vertical=top]{top:var(--chat-position-offset-y, 20px);bottom:auto}:host[data-vertical=bottom]{top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-vertical=middle]{top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-vertical=middle].chat-widget-open{top:50%;bottom:auto;transform:translateY(-50%)}:host[data-side=left][data-vertical=middle]{left:var(--chat-position-offset-x, 20px);right:auto;top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-side=left][data-vertical=middle].chat-widget-open{left:var(--chat-position-offset-x, 20px);right:auto;top:50%;bottom:auto;transform:translateY(-50%)}:host[data-side=right][data-vertical=middle]{left:auto;right:var(--chat-position-offset-x, 20px);top:auto;bottom:var(--chat-position-offset-y, 20px)}:host[data-side=right][data-vertical=middle].chat-widget-open{left:auto;right:var(--chat-position-offset-x, 20px);top:50%;bottom:auto;transform:translateY(-50%)}.chat-widget-bubble{display:flex;align-items:center;justify-content:center;width:56px;height:56px;border-radius:50%;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);color:#fffffff2;border:.5px solid rgba(255,255,255,.1);cursor:pointer;box-shadow:0 4px 12px #00000026;will-change:transform;transition:transform .2s ease,box-shadow .2s ease,background .2s ease}.chat-widget-bubble:hover{transform:scale(1.05);box-shadow:0 6px 16px #0003}.chat-widget-bubble:active{transform:scale(.98)}.chat-widget-bubble-icon{width:24px;height:24px}.chat-widget{display:flex;flex-direction:column;width:380px;height:520px;max-width:calc(100vw - 40px);max-height:calc(100vh - 100px);background:transparent;border:none;border-radius:16px;overflow:hidden;animation:chat-widget-open .2s ease-out}@keyframes chat-widget-open{0%{opacity:0;transform:translateY(10px) scale(.95)}to{opacity:1;transform:translateY(0) scale(1)}}.chat-widget-header{display:flex;align-items:center;justify-content:flex-end;padding:6px;background:transparent;border-bottom:none}.chat-widget-header-button{display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:50%;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);color:#fffffff2;border:.5px solid rgba(255,255,255,.1);cursor:pointer;box-shadow:0 4px 12px #00000026;will-change:transform;transition:transform .2s ease,box-shadow .2s ease,background .2s ease}.chat-widget-header-button:hover{transform:scale(1.05);background:#11111180;box-shadow:0 6px 16px #0003}.chat-widget-header-button:active{transform:scale(.98)}.chat-widget-header-icon{width:20px;height:20px}.chat-widget-body{flex:1;overflow:hidden;display:flex;flex-direction:column}.chat-messages-container{flex:1;overflow-y:auto;overflow-anchor:none;overscroll-behavior:contain;display:flex;flex-direction:column;padding:12px 12px 0}.chat-messages-spacer{flex-grow:1}.chat-message-card{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;margin-bottom:8px;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-radius:16px;border:.5px solid rgba(255,255,255,.1)}.chat-message-avatar{flex-shrink:0}.chat-message-avatar-img{width:36px;height:36px;border-radius:50%;background:#ffffff1a;object-fit:cover}.chat-message-content{flex:1;min-width:0}.chat-message-header{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:4px}.chat-message-username{font-size:13px;font-weight:500;color:#ffffffb3}.chat-message-time{font-size:11px;color:#fff9;flex-shrink:0}.chat-message-text{margin:0;font-size:14px;color:#fffffff2;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word}.chat-message-text--title{font-weight:600;margin-bottom:4px}.chat-message-text--summary{color:#ffffffb3;margin-bottom:4px}.chat-message-username--link{cursor:pointer;text-decoration:underline;text-decoration-color:transparent;transition:text-decoration-color .15s ease}.chat-message-username--link:hover{text-decoration-color:currentColor}.chat-message-card--event{padding-left:12px}.chat-message-event-content{display:flex;flex-direction:column;gap:4px}.chat-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;flex:1;padding:32px;text-align:center;margin:12px;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-radius:16px;border:.5px solid rgba(255,255,255,.1)}.chat-empty-icon{margin-bottom:12px}.chat-empty-svg{width:40px;height:40px;color:#ffffffb3}.chat-empty-title{margin:0 0 4px;font-size:15px;font-weight:600;color:#fffffff2}.chat-empty-text{margin:0;font-size:13px;color:#ffffffb3}.chat-retry-button{display:inline-flex;align-items:center;gap:6px;margin-top:12px;padding:8px 14px;font-size:13px;font-weight:500;color:#fffffff2;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:.5px solid rgba(255,255,255,.1);border-radius:8px;cursor:pointer;transition:border-color .15s ease}.chat-retry-button:hover{border-color:#fff3}.chat-retry-icon{width:14px;height:14px}.chat-spinner{width:24px;height:24px;color:#fffffff2;animation:chat-spinner-rotate 1s linear infinite}@keyframes chat-spinner-rotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.chat-input-container{border-top:none;background:transparent}.chat-input-wrapper{display:flex;flex-direction:column;background:#000000a6;background-blend-mode:overlay;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:.5px solid rgba(255,255,255,.1);border-radius:16px;overflow:hidden;transition:border-color .15s ease;min-width:0;max-width:100%}.chat-input-wrapper:focus-within{border-color:#fff3}.chat-input-textarea{width:100%;min-height:80px;max-height:120px;padding:10px 12px;font-size:16px;font-family:inherit;line-height:1.5;color:#fffffff2;background:transparent;border:none;resize:none;outline:none;box-sizing:border-box;overflow-wrap:break-word;word-wrap:break-word;overflow-x:hidden}.chat-input-textarea::placeholder{color:#ffffff80}.chat-input-textarea:disabled{opacity:.6;cursor:not-allowed}.chat-input-footer{display:flex;align-items:center;gap:8px;padding:8px 12px;background:transparent;border-top:1px solid rgba(255,255,255,.1)}.chat-input-avatar{flex-shrink:0}.chat-input-avatar-img{width:28px;height:28px;border-radius:50%;background:#ffffff1a;object-fit:cover}.chat-input-counter{font-size:12px;color:#ffffffb3;margin-left:auto}.chat-input-counter--error{color:#ff5757e6}.chat-input-divider{width:1px;height:16px;background:#ffffff1a}.chat-input-button{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;border-radius:50%;background:#4fff7e;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);color:#000000e6;cursor:pointer;transition:opacity .15s ease,transform .15s ease,background .15s ease}.chat-input-button:hover:not(:disabled){background:#3fe66a;opacity:1}.chat-input-button:active:not(:disabled){transform:scale(.95)}.chat-input-button:disabled{opacity:.5;cursor:not-allowed}.chat-input-icon{width:16px;height:16px}.chat-input-spinner{width:16px;height:16px;animation:chat-spinner-rotate 1s linear infinite}@media(max-width:480px){:host{inset:auto 10px 10px}:host .chat-widget{width:100%;max-width:none;height:calc(100vh - 80px);transform:none;top:auto;bottom:10px}.chat-widget-bubble{width:48px;height:48px}.chat-widget-bubble-icon{width:20px;height:20px}}";
2710
- let tt = null, w = null, st = null;
2711
- function Er(t, e) {
2712
- if (tt) {
2713
- console.warn("Chat widget already mounted");
2714
- return;
2715
- }
2716
- w = document.createElement("div"), w.id = "autogames-chat-widget", document.body.appendChild(w);
2717
- const s = e?.position || {}, r = s.side || "right", i = s.vertical || "bottom", n = s.offsetX ?? 20, o = s.offsetY ?? 20, a = w.attachShadow({ mode: "open" });
2718
- w.setAttribute("data-side", r), w.setAttribute("data-vertical", i), w.style.setProperty("--chat-position-offset-x", `${n}px`), w.style.setProperty("--chat-position-offset-y", `${o}px`), w.style.position = "fixed", w.style.zIndex = "9999", w.style.left = "auto", w.style.right = "auto", w.style.top = "auto", w.style.bottom = "auto", r === "left" ? (w.style.left = `${n}px`, w.style.right = "auto") : (w.style.left = "auto", w.style.right = `${n}px`), i === "top" ? (w.style.top = `${o}px`, w.style.bottom = "auto") : (i === "bottom" || i === "middle") && (w.style.top = "auto", w.style.bottom = `${o}px`);
2719
- const u = document.createElement("style");
2720
- u.textContent = xr, a.appendChild(u);
2721
- const h = document.createElement("div");
2722
- h.id = "chat-widget-root", a.appendChild(h), st = h, tt = Ue.createRoot(h), tt.render(
2723
- /* @__PURE__ */ l(qe, { children: /* @__PURE__ */ l(
2724
- br,
2725
- {
2726
- gameId: t,
2727
- onClose: () => wr(),
2728
- onOpenChange: (c) => {
2729
- if (st && (c ? st.classList.add("chat-widget-open") : st.classList.remove("chat-widget-open")), w) {
2730
- if (c)
2731
- w.classList.add("chat-widget-open"), w.getAttribute("data-vertical") === "middle" && (w.style.top = "50%", w.style.bottom = "auto", w.style.transform = "translateY(-50%)");
2732
- else if (w.classList.remove("chat-widget-open"), w.getAttribute("data-vertical") === "middle") {
2733
- const C = w.style.getPropertyValue("--chat-position-offset-y") || "20px";
2734
- w.style.top = "auto", w.style.bottom = C, w.style.transform = "none";
2735
- }
2736
- }
2737
- }
2738
- }
2739
- ) })
2740
- );
2741
- }
2742
- function wr() {
2743
- tt && (tt.unmount(), tt = null), w && (w.remove(), w = null), st = null;
2744
- }
2745
- export {
2746
- Er as mountChatWidget,
2747
- wr as unmountChatWidget
2748
- };