what-core 0.14.0 → 0.15.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
@@ -0,0 +1,918 @@
1
+ // src/data.js
2
+ import {
3
+ signal as ne,
4
+ effect as re,
5
+ computed as O,
6
+ untrack as y,
7
+ onCleanup as $e,
8
+ getOwner as Je,
9
+ createRoot as Be,
10
+ runWithOwner as Ye,
11
+ _detached as Xe,
12
+ _asyncComputed as se,
13
+ _refresh as Ze,
14
+ _asyncStatus as B,
15
+ _asyncError as ce,
16
+ _setAsyncValue as ke,
17
+ _installSeedOps as en,
18
+ _isNotReady as xe
19
+ } from "./reactive.min.js";
20
+ import { _seedFor as nn, getResource as Ee, getResourceError as tn, _errorFromRecord as rn, _loadedResource as ln } from "./hydration-data.min.js";
21
+ import { getServerContext as S, _isServerProcess as un } from "./server-context.min.js";
22
+ import { _enableSuspense as on, isHydrating as sn } from "./render.min.js";
23
+ var x = 0, Y = 1, E = /* @__PURE__ */ Object.freeze({ toString: () => "[what] no data" }), an = 1, _e = 2, ie = 300 * 1e3;
24
+ function m() {
25
+ }
26
+ function fe(e) {
27
+ return e && typeof e.unref == "function" && e.unref(), e;
28
+ }
29
+ function $(e) {
30
+ return Array.isArray(e) && e.some((n) => typeof n == "function") ? e.map((n) => typeof n == "function" ? n() : n) : e;
31
+ }
32
+ function K(e) {
33
+ return e = $(e), Array.isArray(e) ? e.map((n) => typeof n == "string" ? n : JSON.stringify(n) ?? String(n)).map((n) => n.replace(/([\\:])/g, "\\$1")).join(":") : String(e);
34
+ }
35
+ var C = "query:", de = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()], te = /* @__PURE__ */ new WeakMap();
36
+ function Fe(e) {
37
+ let n = S();
38
+ if (n === null)
39
+ return un() ? /* @__PURE__ */ new Map() : de[e];
40
+ let t = te.get(n);
41
+ return t === void 0 && te.set(n, t = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()]), t[e];
42
+ }
43
+ var ue = /* @__PURE__ */ new Set(), Re = !0;
44
+ function cn(e) {
45
+ if (!Re || ue.has(e)) return null;
46
+ let n = Ee(C + e);
47
+ if (n !== void 0)
48
+ return ue.add(e), { value: n, track: !1 };
49
+ let t = tn(C + e);
50
+ return t === void 0 ? null : (ue.add(e), { error: rn(t), track: !1 });
51
+ }
52
+ function he(e, n, t, r) {
53
+ let i = Fe(e), l = i.get(n);
54
+ return l === void 0 && (l = fn(e, n, t, i, r), i.set(n, l)), l;
55
+ }
56
+ function fn(e, n, t, r, i) {
57
+ let l = {
58
+ kind: e,
59
+ hash: n,
60
+ key: t,
61
+ cache: r,
62
+ /** @type {any} */
63
+ node: null,
64
+ dispose: m,
65
+ /** @type {any} */
66
+ flight: null,
67
+ next: 0,
68
+ /** @type {any} */
69
+ error: void 0,
70
+ version: 0,
71
+ updatedAt: 0,
72
+ fetchedAt: 0,
73
+ fetches: 0,
74
+ /** @type {any} */
75
+ last: null,
76
+ hydrated: !1,
77
+ /** @type {Set<any>} */
78
+ observers: /* @__PURE__ */ new Set(),
79
+ gcTime: ie,
80
+ /** @type {any} */
81
+ timer: null,
82
+ /** @type {any} */
83
+ conf: i !== null ? i.conf : null,
84
+ /** @type {any} */
85
+ src: null,
86
+ /** @type {any} */
87
+ by: null,
88
+ /** @type {any} */
89
+ op: null,
90
+ /** @type {Set<string> | null} */
91
+ paths: null,
92
+ dir: e === Y ? ne(
93
+ /** @type {string | null} */
94
+ null
95
+ ) : null,
96
+ // Moves at every landing: query() reads it, not the node, while the entry
97
+ // has no data, so the engine never sees "a value being refetched" there.
98
+ tick: ne(0),
99
+ /** @type {{ promise: Promise<any>, resolve: (v: any) => void, reject: (e: any) => void } | null} */
100
+ arrival: null,
101
+ dropped: !1
102
+ }, u = S(), o;
103
+ if (u !== null)
104
+ o = nn(C + n, !1);
105
+ else if (o = e === x ? cn(n) : null, o !== null)
106
+ l.hydrated = !0, l.updatedAt = Date.now(), "error" in o && (l.error = o.error), queueMicrotask(() => {
107
+ l.hydrated = !1;
108
+ });
109
+ else if (i !== null && i.initialData !== void 0) {
110
+ let c = typeof i.initialData == "function" ? i.initialData() : i.initialData;
111
+ o = { value: c === void 0 ? E : c, track: !1 }, c !== void 0 && (l.updatedAt = i.initialDataUpdatedAt ?? Date.now());
112
+ } else
113
+ o = { value: E, track: !1 };
114
+ en();
115
+ let w = () => Be((c) => {
116
+ l.dispose = c, l.node = se(dn(l), o);
117
+ });
118
+ return u !== null && u.owner ? Ye(u.owner, w) : Xe(w), l;
119
+ }
120
+ function dn(e) {
121
+ return () => {
122
+ let n = e.next;
123
+ if (e.next = 0, n === _e && e.flight !== null) return e.flight.promise;
124
+ if (n === 0) {
125
+ if (!hn(e)) {
126
+ if (e.error !== void 0) throw e.error;
127
+ return y(() => e.node.peek());
128
+ }
129
+ e.by = Ve(e);
130
+ }
131
+ return pn(e).promise;
132
+ };
133
+ }
134
+ function Oe(e) {
135
+ if (e === null || typeof e != "object") return !1;
136
+ let n = Object.getPrototypeOf(e);
137
+ return n === Object.prototype || n === null;
138
+ }
139
+ function qe(e, n) {
140
+ if (e === n) return e;
141
+ let t = Array.isArray(e) && Array.isArray(n);
142
+ if (!t && !(Oe(e) && Oe(n))) return n;
143
+ let r = t ? null : Object.keys(e), i = r === null ? e.length : r.length, l = t ? null : Object.keys(n), u = l === null ? n.length : l.length, o = t ? new Array(u) : {}, w = 0;
144
+ for (let c = 0; c < u; c++) {
145
+ let p = l === null ? c : l[c], d = e[p], f = t || Object.prototype.hasOwnProperty.call(e, p) ? qe(d, n[p]) : n[p];
146
+ o[p] = f, f === d && (t ? c < i : Object.prototype.hasOwnProperty.call(e, p)) && w++;
147
+ }
148
+ return i === u && w === i ? e : o;
149
+ }
150
+ function pe(e) {
151
+ return e === !1 || e == null ? null : typeof e == "function" ? e : qe;
152
+ }
153
+ function hn(e) {
154
+ if (S() !== null) return !0;
155
+ for (let n of e.observers) if (n.active()) return !0;
156
+ return !1;
157
+ }
158
+ function P(e) {
159
+ let n = y(() => e.node.peek());
160
+ return n === E ? void 0 : n;
161
+ }
162
+ function pn(e) {
163
+ let n = e.flight;
164
+ n !== null && ge(e, n, !0);
165
+ let t = new AbortController(), r = e.op;
166
+ e.op = null;
167
+ let i = gn(e), l = {
168
+ ac: t,
169
+ dead: !1,
170
+ superseded: !1,
171
+ by: e.by,
172
+ conf: i.conf,
173
+ key: i.key,
174
+ // A prefetchQuery waits on it (it started it, joined it, or a flight it
175
+ // waited on was superseded by this one): no reader unmounting cancels it.
176
+ keep: i.keep === !0 || n !== null && n.keep,
177
+ op: r,
178
+ /** @type {any} */
179
+ promise: null,
180
+ failed: !1,
181
+ /** @type {any} */
182
+ result: void 0,
183
+ /** @type {any} */
184
+ page: void 0,
185
+ started: Date.now(),
186
+ /** @type {(() => void) | null} */
187
+ onKill: null,
188
+ /** @type {any} */
189
+ at: null
190
+ };
191
+ l.at = { e, f: l }, e.by = null, e.flight = l, e.fetchedAt = l.started, e.fetches++;
192
+ let u;
193
+ try {
194
+ u = Ie(e, l);
195
+ } catch (o) {
196
+ throw e.flight = null, l.dead = !0, xe(o) ? e.version++ : Me(e, l, o, !0), o;
197
+ }
198
+ return l.promise = vn(l.at, u), yn(l.at, l.promise), l;
199
+ }
200
+ function gn(e) {
201
+ for (let n of [e.by, e.src])
202
+ if (n != null && (n.hash === void 0 || y(n.hash) === e.hash)) return n;
203
+ return e;
204
+ }
205
+ function yn(e, n) {
206
+ n.then((t) => {
207
+ e.f !== null && Se(e.e, e.f, t, !1);
208
+ }, (t) => {
209
+ e.f !== null && Se(e.e, e.f, t, !0);
210
+ }), n.then(m, m).then(() => {
211
+ e.f !== null && Sn(e.e, e.f);
212
+ });
213
+ }
214
+ function mn(e, n) {
215
+ return n.then((t) => {
216
+ if (e.f === null) return t;
217
+ let r = e.f.conf.share;
218
+ return r(P(e.e), t);
219
+ });
220
+ }
221
+ function Ie(e, n) {
222
+ let t = n.conf;
223
+ if (e.kind === x) {
224
+ let u = t.run(n.key, n.ac.signal), o = t.share;
225
+ return o == null ? u : u != null && typeof u.then == "function" ? mn(n.at, u) : o(P(e), u);
226
+ }
227
+ let r = P(e) ?? { pages: [], pageParams: [] }, i = n.op || { param: t.initialPageParam, place: "first" }, l = n.at;
228
+ return Promise.resolve(t.run(n.key, i.param, n.ac.signal)).then((u) => (l.f !== null && (l.f.page = u), i.place === "next" ? { pages: [...r.pages, u], pageParams: [...r.pageParams, i.param] } : i.place === "previous" ? { pages: [u, ...r.pages], pageParams: [i.param, ...r.pageParams] } : { pages: [u], pageParams: [i.param] }));
229
+ }
230
+ async function vn(e, n) {
231
+ let t = n;
232
+ for (let r = 1; ; r++)
233
+ try {
234
+ return await t;
235
+ } catch (i) {
236
+ if (e.f === null || r >= wn(e.f.conf.retry, r, i) || (await Pn(e.f.conf.retryDelay(r), e.f.ac.signal), e.f === null)) throw i;
237
+ t = Ie(e.e, e.f);
238
+ }
239
+ }
240
+ function wn(e, n, t) {
241
+ return typeof e == "function" ? e(n - 1, t) ? n + 1 : n : e === !0 ? 1 / 0 : e === !1 ? 1 : Math.max(1, Number(e) || 0);
242
+ }
243
+ function Pn(e, n) {
244
+ return new Promise((t, r) => {
245
+ let i = fe(setTimeout(t, e));
246
+ n.addEventListener("abort", () => {
247
+ clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
248
+ }, { once: !0 });
249
+ });
250
+ }
251
+ function Se(e, n, t, r) {
252
+ n.failed = r, n.result = t, !n.dead && (e.flight === n && (e.flight = null), Me(e, n, t, r), n.keep && le(e), e.tick((i) => i + 1));
253
+ }
254
+ function Me(e, n, t, r) {
255
+ e.version++;
256
+ let i = Date.now();
257
+ e.updatedAt = i, e.error = r ? t : void 0, e.last = { at: i, ms: i - n.started, ok: !r }, e.dir !== null && e.dir(null), Ne(e, t, r);
258
+ }
259
+ function bn(e, n, t) {
260
+ Ne(e, n, t), e.tick((r) => r + 1);
261
+ }
262
+ function Ne(e, n, t) {
263
+ let r = e.arrival;
264
+ r !== null && (e.arrival = null, (t ? r.reject : r.resolve)(n));
265
+ }
266
+ function Dn(e) {
267
+ if (e.arrival === null) {
268
+ let n = m, t = m, r = new Promise((i, l) => {
269
+ n = i, t = l;
270
+ });
271
+ e.arrival = { promise: r, resolve: n, reject: t };
272
+ }
273
+ return e.arrival.promise;
274
+ }
275
+ function ge(e, n, t) {
276
+ n.dead || (n.dead = !0, n.superseded = t, n.at.e = n.at.f = null, n.ac.abort(On()), e.flight === n && (e.flight = null), n.onKill !== null && n.onKill());
277
+ }
278
+ function On() {
279
+ let e = new DOMException("The query was dropped.", "AbortError");
280
+ return e.stack, e;
281
+ }
282
+ function Sn(e, n) {
283
+ if (n.dead) return;
284
+ let t = n.by;
285
+ if (!(t === null || !t.alive))
286
+ if (n.failed)
287
+ t.onError && t.onError(n.result, n.key), t.onSettled && t.onSettled(null, n.result);
288
+ else {
289
+ let r = e.kind === Y ? n.page : n.result;
290
+ t.onSuccess && t.onSuccess(r, n.key), t.onSettled && t.onSettled(r, null);
291
+ }
292
+ }
293
+ function R(e, n) {
294
+ if (n.dead) return Promise.resolve(Te(e, n));
295
+ let t = Tn(n.at, n.promise), r = new Promise((i) => {
296
+ let l = n.onKill;
297
+ n.onKill = () => {
298
+ l !== null && l(), i(void 0);
299
+ };
300
+ }).then(() => Te(e, n));
301
+ return Promise.race([t, r]);
302
+ }
303
+ function Te(e, n) {
304
+ return n.superseded && e.flight !== null ? R(e, e.flight) : void 0;
305
+ }
306
+ function Tn(e, n) {
307
+ return n.then(
308
+ (t) => e.f === null ? new Promise(m) : e.e.kind === Y ? e.f.page : t,
309
+ (t) => e.f === null ? new Promise(m) : Promise.reject(t)
310
+ );
311
+ }
312
+ function q(e, n, t) {
313
+ e.by = n, e.op = t || null, e.next = an, e.dir !== null && e.dir(t ? t.dir : "next");
314
+ let r = je(e);
315
+ return e.next = 0, e.by = null, e.op = null, r;
316
+ }
317
+ function je(e) {
318
+ let n = Ze(e.node);
319
+ return n.then(m, m), n;
320
+ }
321
+ function z(e, n, t) {
322
+ return q(e, n, t), e.flight !== null ? R(e, e.flight) : Promise.resolve(P(e));
323
+ }
324
+ function ye(e, n) {
325
+ e.flight !== null && ge(e, e.flight, !1), e.dir !== null && e.dir(null), e.version++, ke(e.node, n), n !== E ? bn(e, n, !1) : e.tick((t) => t + 1);
326
+ }
327
+ function me(e, n) {
328
+ e.updatedAt = Date.now(), e.error = void 0, ye(e, n);
329
+ }
330
+ function Ke(e) {
331
+ e.dropped || (e.dropped = !0, e.timer !== null && clearTimeout(e.timer), e.flight !== null && ge(e, e.flight, !1), e.cache.get(e.hash) === e && e.cache.delete(e.hash), e.dispose());
332
+ }
333
+ var ee = (
334
+ /** @type {string | null} */
335
+ null
336
+ ), An = /* @__PURE__ */ Symbol.for("what.router.path.v1");
337
+ function Ln(e, n) {
338
+ let t = ee;
339
+ ee = e;
340
+ try {
341
+ return n();
342
+ } finally {
343
+ ee = t;
344
+ }
345
+ }
346
+ function kn(e) {
347
+ let n = [];
348
+ for (let t of F())
349
+ t.flight !== null && t.paths !== null && t.paths.has(e) && t.error === void 0 && P(t) === void 0 && n.push(R(t, t.flight).then(m, m));
350
+ return n.length === 0 ? Promise.resolve() : Promise.all(n).then(() => kn(e));
351
+ }
352
+ function xn(e, n) {
353
+ e.dropped && (e.dropped = !1, e.cache.has(e.hash) || e.cache.set(e.hash, e)), e.timer !== null && (clearTimeout(e.timer), e.timer = null), e.gcTime = e.observers.size === 0 ? n.gcTime : Math.max(e.gcTime, n.gcTime), e.observers.add(n), e.src = n, e.conf = n.conf, e.key = n.key;
354
+ let t = n.path ?? /** @type {any} */
355
+ globalThis[An]?.() ?? (typeof location < "u" ? location.pathname : null);
356
+ t != null && (e.paths || (e.paths = /* @__PURE__ */ new Set())).add(t);
357
+ }
358
+ function En(e, n) {
359
+ e.observers.delete(n) && (e.src === n && (e.src = null), !(e.observers.size > 0) && (e.flight !== null && !e.flight.keep && ye(e, y(() => e.node.peek())), le(e)));
360
+ }
361
+ function le(e) {
362
+ e.cache !== de[e.kind] || e.observers.size > 0 || e.dropped || (e.timer !== null && clearTimeout(e.timer), e.timer = !e.flight?.keep && Number.isFinite(e.gcTime) ? fe(setTimeout(() => {
363
+ e.timer = null, e.observers.size === 0 && Ke(e);
364
+ }, e.gcTime)) : null);
365
+ }
366
+ function ae(e, n) {
367
+ for (let t of e.entries)
368
+ t !== n && (e.entries.delete(t), En(t, e));
369
+ n !== null && Ce(e, n), e.entry = n;
370
+ }
371
+ function Ce(e, n) {
372
+ e.entries.has(n) || (e.entries.add(n), xn(n, e));
373
+ }
374
+ function _n(e, n) {
375
+ S() !== null || !e.alive || (Ce(e, n), e.entries.size > 1 && !e.sweeping && (e.sweeping = !0, queueMicrotask(() => {
376
+ e.sweeping = !1, e.alive && ae(e, y(e.current));
377
+ })));
378
+ }
379
+ function Fn(e, n) {
380
+ if (!n) return $(e());
381
+ try {
382
+ return $(e());
383
+ } catch {
384
+ return null;
385
+ }
386
+ }
387
+ function X(e, n, t, r) {
388
+ let i = {
389
+ kind: e,
390
+ conf: t,
391
+ alive: !0,
392
+ /** @type {any} */
393
+ entry: null,
394
+ /** @type {Set<any>} */
395
+ entries: /* @__PURE__ */ new Set(),
396
+ /** @type {any} */
397
+ previous: null,
398
+ sweeping: !1,
399
+ gate: r.gate || null,
400
+ staleTime: r.staleTime ?? 0,
401
+ gcTime: r.gcTime ?? ie,
402
+ initialData: r.initialData,
403
+ initialDataUpdatedAt: r.initialDataUpdatedAt,
404
+ onSuccess: r.onSuccess,
405
+ onError: r.onError,
406
+ onSettled: r.onSettled,
407
+ path: ee,
408
+ active: () => i.alive && (i.gate === null || i.gate.peek()),
409
+ /** @type {() => any} */
410
+ current: m,
411
+ // The key as this observer wrote it last: a new spelling of the same
412
+ // entry ('q:a', then ['q', 'a']) moves it without moving the entry.
413
+ /** @type {any} */
414
+ key: null,
415
+ /** @type {() => string | null} */
416
+ hash: () => null
417
+ }, l = typeof n == "function" ? n : () => n, u = O(() => {
418
+ let c = Fn(l, r.lenient);
419
+ return i.key = c, c == null || c === !1 ? null : K(c);
420
+ });
421
+ i.hash = u;
422
+ let o = null;
423
+ if (i.current = O(() => {
424
+ let c = u(), p = c === null ? null : he(e, c, i.key, i);
425
+ return p !== o && (o !== null && (i.previous = o), o = p), p;
426
+ }), S() !== null) return i;
427
+ let w = !1;
428
+ return re(() => {
429
+ let c = i.current(), p = i.gate === null || i.gate();
430
+ y(() => {
431
+ let d = c !== null && !i.entries.has(c), f = p && !w;
432
+ w = p, ae(i, c), c !== null && p && (d || f) && L(c, i) && q(c, i);
433
+ });
434
+ }), Je() !== null && $e(() => {
435
+ i.alive = !1, ae(i, null);
436
+ }), i;
437
+ }
438
+ function L(e, n) {
439
+ return e.flight !== null || e.hydrated ? !1 : e.error !== void 0 || P(e) === void 0 ? !0 : Date.now() - e.updatedAt >= n.staleTime;
440
+ }
441
+ function v(e) {
442
+ if (S() !== null || sn()) return Rn(e);
443
+ let n = e.current();
444
+ if (n === null) return { value: void 0, error: null, fetching: !1, first: !1, e: n };
445
+ let t = n.node, r = B(t);
446
+ try {
447
+ t();
448
+ } catch {
449
+ }
450
+ let i = t.peek();
451
+ return {
452
+ value: i === E ? void 0 : i,
453
+ error: r === "errored" ? ce(t) : null,
454
+ fetching: r === "pending" || r === "unresolved",
455
+ first: !1,
456
+ e: n
457
+ };
458
+ }
459
+ var Ae = /* @__PURE__ */ ne(0), oe = !1, ze = /* @__PURE__ */ new WeakMap();
460
+ function Rn(e) {
461
+ let n = S();
462
+ n === null && (Ae(), oe || (oe = !0, queueMicrotask(() => {
463
+ oe = !1, Ae((i) => i + 1);
464
+ })));
465
+ let t = y(e.hash);
466
+ if (t !== null && (n !== null ? ze.get(n)?.has(t) : ln(C + t)))
467
+ return { value: n !== null ? P(y(e.current)) : Ee(C + t), error: null, fetching: !1, first: !1, e: null };
468
+ let r = e.initialData;
469
+ return { value: typeof r == "function" ? y(r) : r, error: null, fetching: !1, first: !0, e: null };
470
+ }
471
+ function Qn(e) {
472
+ let n = /* @__PURE__ */ new Set();
473
+ for (let [t, r] of te.get(e)?.[x] ?? [])
474
+ r.flight === null && r.error === void 0 && P(r) !== void 0 && n.add(t);
475
+ return ze.set(e, n), [...n].map((t) => C + t);
476
+ }
477
+ function Le(e) {
478
+ let n = typeof e == "function" ? e : () => e, t = ne(y(() => !!n()));
479
+ return S() === null && re(() => {
480
+ t(!!n());
481
+ }), t;
482
+ }
483
+ function J(e, n, t) {
484
+ S() !== null || typeof window > "u" || re(() => {
485
+ let r = () => {
486
+ if (n[0] === "visibilitychange" && document.visibilityState !== "visible") return;
487
+ let l = e.entry;
488
+ l !== null && e.active() && t(l) && q(l, e);
489
+ }, i = n[0] === "visibilitychange" ? document : window;
490
+ return i.addEventListener(n[0], r), () => i.removeEventListener(n[0], r);
491
+ });
492
+ }
493
+ function ve(e, n) {
494
+ !n || S() !== null || re(() => {
495
+ let t = fe(setInterval(() => {
496
+ let r = e.entry;
497
+ r !== null && e.active() && r.flight === null && q(r, e);
498
+ }, n));
499
+ return () => clearInterval(t);
500
+ });
501
+ }
502
+ function Qe(e) {
503
+ return Array.isArray(e) ? e : [e];
504
+ }
505
+ var Q = (e) => Math.min(1e3 * 2 ** e, 3e4);
506
+ function Un(e, n, t = {}) {
507
+ on();
508
+ let r = X(x, e, {
509
+ run: (l, u) => n(l, { signal: u }),
510
+ retry: t.retry ?? 1,
511
+ retryDelay: t.retryDelay ?? Q
512
+ }, {
513
+ staleTime: t.staleTime,
514
+ gcTime: t.gcTime,
515
+ initialData: t.initialData
516
+ });
517
+ if (S() !== null) {
518
+ let l = y(r.current);
519
+ return l === null ? se(m, { value: void 0, track: !1 }) : (y(() => B(l.node)), l.node);
520
+ }
521
+ let i = null;
522
+ return se(() => {
523
+ let l = r.current();
524
+ if (l === null) {
525
+ i = null;
526
+ return;
527
+ }
528
+ _n(r, l);
529
+ let u = i !== null && i.e === l && i.version === l.version;
530
+ if (i = { e: l, version: l.version }, y(() => l.node.peek()) === E) {
531
+ if (l.tick(), (u || l.flight === null && l.error === void 0) && q(l, r), i.version = l.version, l.error !== void 0 && l.flight === null) throw l.error;
532
+ return Dn(l);
533
+ }
534
+ u && q(l, r), i.version = l.version;
535
+ let o = qn(l.node);
536
+ if (o.waiting !== null) return o.waiting.then(() => In(l));
537
+ if (o.failed) throw o.value;
538
+ return o.value;
539
+ }, null);
540
+ }
541
+ function qn(e) {
542
+ try {
543
+ return { value: e(), waiting: null, failed: !1 };
544
+ } catch (n) {
545
+ return xe(n) ? { value: void 0, waiting: n, failed: !1 } : { value: n, waiting: null, failed: !0 };
546
+ }
547
+ }
548
+ function In(e) {
549
+ return y(() => {
550
+ let n = e.node;
551
+ if (B(n) === "errored") throw ce(n);
552
+ let t = n.peek();
553
+ return t === E ? void 0 : t;
554
+ });
555
+ }
556
+ function Vn(e) {
557
+ let {
558
+ queryKey: n,
559
+ queryFn: t,
560
+ enabled: r = !0,
561
+ staleTime: i = 0,
562
+ cacheTime: l,
563
+ gcTime: u = l ?? ie,
564
+ refetchOnWindowFocus: o = !0,
565
+ refetchOnReconnect: w = !0,
566
+ refetchInterval: c = !1,
567
+ retry: p = 3,
568
+ retryDelay: d = Q,
569
+ onSuccess: f,
570
+ onError: A,
571
+ onSettled: I,
572
+ select: _,
573
+ placeholderData: k,
574
+ keepPreviousData: U = !1,
575
+ initialData: M,
576
+ initialDataUpdatedAt: a,
577
+ structuralSharing: b = !0
578
+ } = e, T = Le(r), g = X(x, n, {
579
+ run: (h, G) => t({ queryKey: Qe(h), signal: G }),
580
+ share: pe(b),
581
+ retry: p,
582
+ retryDelay: d
583
+ }, { gate: T, staleTime: i, gcTime: u, initialData: M, initialDataUpdatedAt: a, onSuccess: f, onError: A, onSettled: I });
584
+ o && J(g, ["visibilitychange"], (h) => L(h, g)), w && J(g, ["online"], (h) => L(h, g)), ve(g, c);
585
+ let N = E, j, s = (h) => _ ? (h !== N && (N = h, j = _(h)), j) : h, D = () => {
586
+ let h = v(g);
587
+ if (h.value != null) return { data: s(h.value), placeholder: !1, s: h };
588
+ let G = g.previous !== null && g.previous !== h.e ? P(g.previous) : void 0;
589
+ if (G != null && (U || typeof k == "function")) {
590
+ let De = _ ? _(G) : G;
591
+ return { data: typeof k == "function" ? k(De) : De, placeholder: !0, s: h };
592
+ }
593
+ let be = typeof k == "function" ? k(void 0) : k;
594
+ return { data: be, placeholder: be !== void 0, s: h };
595
+ }, V = () => {
596
+ let h = v(g);
597
+ return h.error != null ? "error" : h.value != null ? "success" : h.fetching || h.first && T.peek() ? "loading" : "idle";
598
+ }, Z = O(() => D().data), We = O(() => D().placeholder), W = O(V), Ge = O(() => v(g).error), Pe = O(() => v(g).fetching), He = O(() => {
599
+ let h = v(g).e;
600
+ return h !== null ? h.updatedAt : 0;
601
+ });
602
+ return {
603
+ data: () => Z(),
604
+ error: () => Ge(),
605
+ status: () => W(),
606
+ fetchStatus: () => Pe() ? "fetching" : "idle",
607
+ isLoading: () => W() === "loading",
608
+ isError: () => W() === "error",
609
+ isSuccess: () => W() === "success",
610
+ isIdle: () => W() === "idle",
611
+ isFetching: () => Pe(),
612
+ isPlaceholderData: () => We(),
613
+ isEnabled: () => T(),
614
+ dataUpdatedAt: () => He(),
615
+ // An explicit request: never gated by `enabled`, never answered from the
616
+ // freshness window. Resolves with the data it fetched.
617
+ refetch: () => {
618
+ let h = y(g.current);
619
+ return h === null ? Promise.resolve(void 0) : z(h, g);
620
+ }
621
+ };
622
+ }
623
+ function Wn(e, n, t = {}) {
624
+ let {
625
+ revalidateOnFocus: r = !0,
626
+ revalidateOnReconnect: i = !0,
627
+ refreshInterval: l = 0,
628
+ dedupingInterval: u = 2e3,
629
+ fallbackData: o,
630
+ keepPreviousData: w = !1,
631
+ onSuccess: c,
632
+ onError: p,
633
+ structuralSharing: d = !0
634
+ } = t, f = X(x, e, {
635
+ run: (a, b) => n(a, { signal: b }),
636
+ share: pe(d),
637
+ retry: 1,
638
+ retryDelay: Q
639
+ }, { staleTime: u, onSuccess: c, onError: p, lenient: !0 });
640
+ r && J(f, ["visibilitychange"], (a) => L(a, f)), i && J(f, ["online"], (a) => L(a, f)), ve(f, l);
641
+ let A = () => {
642
+ let a = v(f);
643
+ if (a.value != null) return a.value;
644
+ if (w && f.previous !== null && f.previous !== a.e) {
645
+ let b = P(f.previous);
646
+ if (b != null) return b;
647
+ }
648
+ return o ?? null;
649
+ }, I = () => {
650
+ let a = y(f.current);
651
+ return a === null ? Promise.resolve(void 0) : a.flight !== null ? R(a, a.flight) : z(a, f);
652
+ }, _ = O(A), k = O(() => v(f).error), U = O(() => {
653
+ let a = v(f);
654
+ return a.value == null && a.fetching;
655
+ }), M = O(() => v(f).fetching);
656
+ return {
657
+ data: () => _(),
658
+ error: () => k(),
659
+ isLoading: () => U(),
660
+ isValidating: () => M(),
661
+ // mutate(data, shouldRevalidate = true): put data in the cache for every
662
+ // reader of the key, then fetch it again. mutate() alone revalidates.
663
+ mutate: (...a) => {
664
+ if (a.length === 0) return I();
665
+ let [b, T = !0] = a, g = y(f.current);
666
+ return g === null ? Promise.resolve(void 0) : (me(g, typeof b == "function" ? b(P(g) ?? null) : b), T ? z(g, f) : Promise.resolve(P(g)));
667
+ },
668
+ revalidate: I
669
+ };
670
+ }
671
+ function Gn(e) {
672
+ let {
673
+ queryKey: n,
674
+ queryFn: t,
675
+ getNextPageParam: r,
676
+ getPreviousPageParam: i,
677
+ initialPageParam: l,
678
+ enabled: u = !0,
679
+ staleTime: o = 0,
680
+ cacheTime: w,
681
+ gcTime: c = w ?? ie,
682
+ refetchOnWindowFocus: p = !1,
683
+ refetchInterval: d = !1,
684
+ select: f,
685
+ retry: A = 3,
686
+ retryDelay: I = Q,
687
+ onSuccess: _,
688
+ onError: k,
689
+ onSettled: U
690
+ } = e, M = Le(u), a = X(Y, n, {
691
+ run: (s, D, V) => t({ queryKey: Qe(s), pageParam: D, signal: V }),
692
+ retry: A,
693
+ retryDelay: I,
694
+ initialPageParam: l
695
+ }, { gate: M, staleTime: o, gcTime: c, onSuccess: _, onError: k, onSettled: U });
696
+ p && J(a, ["visibilitychange"], (s) => L(s, a)), ve(a, d);
697
+ let b = (s) => s.value != null ? s.value : { pages: [], pageParams: [] }, T = () => {
698
+ let s = v(a);
699
+ return s.error != null ? "error" : s.value != null && s.value.pages.length > 0 ? "success" : s.fetching ? "loading" : "idle";
700
+ }, g = (s) => {
701
+ let D = v(a);
702
+ return D.fetching && D.e !== null && D.e.dir() === s;
703
+ }, N = (s, D, V) => {
704
+ let Z = y(a.current);
705
+ return Z === null ? Promise.resolve(void 0) : z(Z, a, { place: s, dir: D, param: V });
706
+ }, j = (s) => N("first", s, l);
707
+ return {
708
+ data: () => {
709
+ let s = b(v(a));
710
+ return f ? f(s) : s;
711
+ },
712
+ error: () => v(a).error,
713
+ status: T,
714
+ isLoading: () => T() === "loading",
715
+ isError: () => T() === "error",
716
+ isSuccess: () => T() === "success",
717
+ isIdle: () => T() === "idle",
718
+ isFetching: () => v(a).fetching,
719
+ isEnabled: () => M(),
720
+ hasNextPage: () => {
721
+ let { pages: s } = b(v(a));
722
+ return s.length === 0 || (r ? r(s[s.length - 1], s) !== void 0 : !1);
723
+ },
724
+ hasPreviousPage: () => {
725
+ let { pages: s } = b(v(a));
726
+ return s.length > 0 && i ? i(s[0], s) !== void 0 : !1;
727
+ },
728
+ isFetchingNextPage: () => g("next"),
729
+ isFetchingPreviousPage: () => g("previous"),
730
+ // An empty list has no last page to ask getNextPageParam about: the next
731
+ // page of nothing is the first page.
732
+ fetchNextPage: async () => {
733
+ let { pages: s } = b(y(() => v(a)));
734
+ if (s.length === 0) return j("next");
735
+ let D = r?.(s[s.length - 1], s);
736
+ if (D !== void 0) return N("next", "next", D);
737
+ },
738
+ fetchPreviousPage: async () => {
739
+ let { pages: s } = b(y(() => v(a)));
740
+ if (s.length === 0) return j("previous");
741
+ let D = i?.(s[0], s);
742
+ if (D !== void 0) return N("previous", "previous", D);
743
+ },
744
+ refetch: () => j("next")
745
+ };
746
+ }
747
+ function Hn(e, n = {}) {
748
+ let {
749
+ method: t = "GET",
750
+ body: r,
751
+ headers: i = {},
752
+ transform: l = (d) => d,
753
+ initialData: u = null,
754
+ fetch: o = globalThis.fetch
755
+ } = n, w = (d) => d == null ? null : ["what:fetch", t, d, r ?? null], c = typeof e == "function" ? () => w(e()) : w(e), p = X(x, c, {
756
+ run: async (d, f) => {
757
+ let A = await o(d[2], {
758
+ method: t,
759
+ headers: { "Content-Type": "application/json", ...i },
760
+ body: r ? JSON.stringify(r) : void 0,
761
+ signal: f
762
+ });
763
+ if (!A.ok) throw new Error(`HTTP ${A.status}: ${A.statusText}`);
764
+ return l(await A.json());
765
+ },
766
+ retry: 1,
767
+ retryDelay: Q
768
+ }, {});
769
+ return {
770
+ data: () => v(p).value ?? u,
771
+ error: () => v(p).error,
772
+ isLoading: () => {
773
+ let d = v(p);
774
+ return d.fetching || d.e !== null && d.value === void 0 && d.error === null && d.e.fetches === 0;
775
+ },
776
+ // Never rejects: a failure shows in error().
777
+ refetch: () => {
778
+ let d = y(p.current);
779
+ return d === null ? Promise.resolve() : z(d, p).then(m, m);
780
+ },
781
+ mutate: (d) => {
782
+ let f = y(p.current);
783
+ f !== null && me(f, d);
784
+ }
785
+ };
786
+ }
787
+ function F() {
788
+ let e = S(), n = e === null ? de : te.get(e) || [], t = [];
789
+ for (let r of n) for (let i of r.values()) t.push(i);
790
+ return t;
791
+ }
792
+ function Ue(e, n) {
793
+ let t = [];
794
+ if (typeof e == "function")
795
+ for (let r of F()) e(r.hash) && t.push(r);
796
+ else if (Array.isArray(e) && !n) {
797
+ let r = K(e), i = r + ":";
798
+ for (let l of F()) (l.hash === r || l.hash.startsWith(i)) && t.push(l);
799
+ } else {
800
+ let r = K(e);
801
+ for (let i of F()) i.hash === r && t.push(i);
802
+ }
803
+ return t;
804
+ }
805
+ function Ve(e) {
806
+ let n = null;
807
+ for (let t of e.observers) t.active() && y(t.hash) === e.hash && (n = t);
808
+ return n;
809
+ }
810
+ function we(e, n) {
811
+ if (e.updatedAt = 0, n) {
812
+ let r = e.flight;
813
+ e.version++, e.error = void 0, ke(e.node, null), r !== null && !r.dead && (e.next = _e, je(e), e.next = 0);
814
+ }
815
+ let t = Ve(e);
816
+ return t === null ? e.flight !== null ? R(e, e.flight).then(m, m) : Promise.resolve() : n && e.flight !== null ? R(e, e.flight).then(m, m) : z(e, t).then(m, m);
817
+ }
818
+ function $n(e, n = {}) {
819
+ let { hard: t = !1, exact: r = !1 } = n, i = Ue(e, r);
820
+ return Promise.all(i.map((l) => we(l, t))).then(m);
821
+ }
822
+ var H = /* @__PURE__ */ new Map();
823
+ function Jn(e, n) {
824
+ return H.has(e) || H.set(e, /* @__PURE__ */ new Set()), H.get(e).add(n), () => {
825
+ H.get(e)?.delete(n);
826
+ };
827
+ }
828
+ function Bn(e) {
829
+ let n = H.get(e);
830
+ if (n)
831
+ for (let r of n)
832
+ try {
833
+ r();
834
+ } catch (i) {
835
+ console.error("[what] Revalidation error:", i);
836
+ }
837
+ let t = [];
838
+ for (let r of F()) r.paths !== null && r.paths.has(e) && t.push(we(r, !1));
839
+ return Promise.all(t).then(m);
840
+ }
841
+ function Yn(e, n, t = {}) {
842
+ e = $(e);
843
+ let r = he(x, K(e), e, null), i = { conf: { run: (o, w) => n(o, { signal: w }), share: pe(t.structuralSharing ?? !0), retry: t.retry ?? 1, retryDelay: Q }, key: e, keep: !0 };
844
+ r.observers.size === 0 && (r.conf = i.conf, r.key = e);
845
+ let l = P(r), u;
846
+ if (r.flight !== null)
847
+ r.flight.keep = !0, u = R(r, r.flight);
848
+ else if (l !== void 0 && r.error === void 0 && Date.now() - r.updatedAt <= (t.staleTime ?? 0)) u = Promise.resolve(l);
849
+ else {
850
+ let o = q(r, i);
851
+ u = r.flight !== null ? R(r, r.flight) : o;
852
+ }
853
+ return le(r), u;
854
+ }
855
+ function Xn(e, n) {
856
+ e = $(e);
857
+ let t = he(x, K(e), e, null);
858
+ me(t, typeof n == "function" ? n(P(t)) : n), le(t);
859
+ }
860
+ function Zn(e) {
861
+ let n = Fe(x).get(K(e));
862
+ return n === void 0 ? void 0 : P(n);
863
+ }
864
+ function et() {
865
+ Re = !1;
866
+ for (let e of F())
867
+ e.observers.size > 0 ? (e.error = void 0, e.updatedAt = 0, ye(e, E)) : Ke(e);
868
+ }
869
+ function Mn(e) {
870
+ return e == null ? null : String(e && e.message || e);
871
+ }
872
+ function Nn(e) {
873
+ let n = B(e.node);
874
+ if (n === "errored") return "error";
875
+ let t = P(e);
876
+ return n === "pending" || n === "unresolved" ? t == null ? "loading" : "refreshing" : t == null ? "idle" : "success";
877
+ }
878
+ function nt() {
879
+ return y(() => F().map((e) => ({
880
+ key: e.hash,
881
+ kind: e.kind === Y ? "infinite" : "query",
882
+ status: Nn(e),
883
+ data: P(e),
884
+ error: Mn(e.error !== void 0 ? e.error : B(e.node) === "errored" ? ce(e.node) : null),
885
+ isValidating: e.flight !== null,
886
+ observers: e.observers.size,
887
+ updatedAt: e.updatedAt || null,
888
+ fetches: e.fetches,
889
+ lastFetch: e.last,
890
+ version: e.version,
891
+ paths: e.paths !== null ? [...e.paths] : []
892
+ })));
893
+ }
894
+ function tt(e) {
895
+ let n = e == null ? F() : Ue(e, !1);
896
+ for (let t of n) we(t, !1);
897
+ return n.map((t) => t.hash);
898
+ }
899
+ export {
900
+ nt as __getCacheSnapshot,
901
+ tt as __invalidateFromDevtools,
902
+ Qn as _loadedQueries,
903
+ kn as _pathLoaded,
904
+ Ln as _tagQueries,
905
+ et as clearCache,
906
+ Zn as getQueryData,
907
+ Bn as invalidatePath,
908
+ $n as invalidateQueries,
909
+ Jn as onRevalidate,
910
+ Yn as prefetchQuery,
911
+ Un as query,
912
+ qe as replaceEqualDeep,
913
+ Xn as setQueryData,
914
+ Hn as useFetch,
915
+ Gn as useInfiniteQuery,
916
+ Vn as useQuery,
917
+ Wn as useSWR
918
+ };