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,295 @@
1
+ // src/animation.js
2
+ import { signal as v, effect as C, batch as A, onCleanup as D, createRoot as I, untrack as $, _userEffect as O } from "./reactive.min.js";
3
+ import { scheduleRead as V, scheduleWrite as P } from "./scheduler.min.js";
4
+ function Q(e, l = {}) {
5
+ let {
6
+ stiffness: o = 100,
7
+ damping: h = 10,
8
+ mass: d = 1,
9
+ precision: s = 0.01
10
+ } = l, i = v(e), r = v(e), n = v(0), g = v(!1), t = null, a = null;
11
+ function X(w) {
12
+ if (a === null) {
13
+ a = w, t = requestAnimationFrame(X);
14
+ return;
15
+ }
16
+ let Y = Math.min((w - a) / 1e3, 0.064);
17
+ a = w;
18
+ let b = i.peek(), E = r.peek(), M = n.peek(), k = b - E, F = -o * k, c = -h * M, f = (F + c) / d, p = M + f * Y, m = b + p * Y;
19
+ if (A(() => {
20
+ n.set(p), i.set(m);
21
+ }), Math.abs(p) < s && Math.abs(k) < s) {
22
+ A(() => {
23
+ i.set(E), n.set(0), g.set(!1);
24
+ }), t = null, a = null;
25
+ return;
26
+ }
27
+ t = requestAnimationFrame(X);
28
+ }
29
+ function x(w) {
30
+ r.set(w), t === null && (g.set(!0), a = null, t = requestAnimationFrame(X));
31
+ }
32
+ function u() {
33
+ t && (cancelAnimationFrame(t), t = null), g.set(!1), a = null;
34
+ }
35
+ function L(w) {
36
+ u(), A(() => {
37
+ i.set(w), r.set(w), n.set(0);
38
+ });
39
+ }
40
+ return D(u), {
41
+ current: () => i(),
42
+ target: () => r(),
43
+ velocity: () => n(),
44
+ isAnimating: () => g(),
45
+ set: x,
46
+ stop: u,
47
+ snap: L,
48
+ subscribe: i.subscribe
49
+ };
50
+ }
51
+ function S(e, l, o = {}) {
52
+ let {
53
+ duration: h = 300,
54
+ easing: d = (u) => u * (2 - u),
55
+ // easeOutQuad
56
+ onUpdate: s,
57
+ onComplete: i
58
+ } = o, r = v(0), n = v(e), g = v(!0), t = null, a = null;
59
+ function X(u) {
60
+ t === null && (t = u);
61
+ let w = u - /** @type {number} */
62
+ t, Y = h > 0 ? Math.min(w / h, 1) : 1, b = d(Y), E = e + (l - e) * b;
63
+ A(() => {
64
+ r.set(Y), n.set(E);
65
+ }), s && s(E, Y), Y < 1 ? a = requestAnimationFrame(X) : (g.set(!1), i && i());
66
+ }
67
+ a = requestAnimationFrame(X);
68
+ function x() {
69
+ a && cancelAnimationFrame(a), g.set(!1);
70
+ }
71
+ return D(x), {
72
+ progress: () => r(),
73
+ value: () => n(),
74
+ isAnimating: () => g(),
75
+ cancel: x,
76
+ subscribe: n.subscribe
77
+ };
78
+ }
79
+ var U = {
80
+ linear: (e) => e,
81
+ easeInQuad: (e) => e * e,
82
+ easeOutQuad: (e) => e * (2 - e),
83
+ easeInOutQuad: (e) => e < 0.5 ? 2 * e * e : -1 + (4 - 2 * e) * e,
84
+ easeInCubic: (e) => e * e * e,
85
+ easeOutCubic: (e) => --e * e * e + 1,
86
+ easeInOutCubic: (e) => e < 0.5 ? 4 * e * e * e : (e - 1) * (2 * e - 2) * (2 * e - 2) + 1,
87
+ easeInElastic: (e) => e === 0 ? 0 : e === 1 ? 1 : -Math.pow(2, 10 * e - 10) * Math.sin((e * 10 - 10.75) * (2 * Math.PI / 3)),
88
+ easeOutElastic: (e) => e === 0 ? 0 : e === 1 ? 1 : Math.pow(2, -10 * e) * Math.sin((e * 10 - 0.75) * (2 * Math.PI / 3)) + 1,
89
+ easeOutBounce: (e) => e < 1 / 2.75 ? 7.5625 * e * e : e < 2 / 2.75 ? 7.5625 * (e -= 1.5 / 2.75) * e + 0.75 : e < 2.5 / 2.75 ? 7.5625 * (e -= 2.25 / 2.75) * e + 0.9375 : 7.5625 * (e -= 2.625 / 2.75) * e + 0.984375
90
+ };
91
+ function H(e = {}) {
92
+ let { duration: l = 300, easing: o = U.easeOutQuad } = e, h = v(!1), d = v(0), s = null, i = () => {
93
+ let n = s;
94
+ n !== null && (s = null, cancelAnimationFrame(n.frame), n.resolve());
95
+ };
96
+ D(i);
97
+ async function r(n) {
98
+ return i(), h.set(!0), d.set(0), /** @type {Promise<void>} */
99
+ new Promise((g) => {
100
+ let t = performance.now(), a = { frame: 0, resolve: g };
101
+ s = a;
102
+ function X(x) {
103
+ if (s !== a) return;
104
+ let u = x - t, L = Math.min(u / l, 1);
105
+ d.set(o(L)), L < 1 ? a.frame = requestAnimationFrame(X) : (s = null, h.set(!1), n && n(), g());
106
+ }
107
+ a.frame = requestAnimationFrame(X);
108
+ });
109
+ }
110
+ return {
111
+ isTransitioning: () => h(),
112
+ progress: () => d(),
113
+ start: r
114
+ };
115
+ }
116
+ function W(e, l = {}) {
117
+ let {
118
+ onDrag: o,
119
+ onDragStart: h,
120
+ onDragEnd: d,
121
+ onPinch: s,
122
+ onSwipe: i,
123
+ onTap: r,
124
+ onLongPress: n,
125
+ preventDefault: g = !1
126
+ // Set to true to allow e.preventDefault() in touch handlers
127
+ } = l, t = {
128
+ isDragging: v(!1),
129
+ startX: 0,
130
+ startY: 0,
131
+ currentX: v(0),
132
+ currentY: v(0),
133
+ deltaX: v(0),
134
+ deltaY: v(0),
135
+ velocity: v({ x: 0, y: 0 })
136
+ }, a = 0, X = 0, x = 0, u = null, L = !1;
137
+ function w(c) {
138
+ let f = c.touches ? c.touches[0] : c;
139
+ t.startX = f.clientX, t.startY = f.clientY, X = f.clientX, x = f.clientY, a = performance.now(), A(() => {
140
+ t.currentX.set(f.clientX), t.currentY.set(f.clientY), t.deltaX.set(0), t.deltaY.set(0), t.velocity.set({ x: 0, y: 0 });
141
+ }), t.isDragging.set(!0), h && h({ x: t.startX, y: t.startY }), L = !1, n && (u = setTimeout(() => {
142
+ u = null, t.isDragging.peek() && (L = !0, n({ x: X, y: x }));
143
+ }, 500));
144
+ }
145
+ function Y(c) {
146
+ if (!t.isDragging.peek()) return;
147
+ let f = c.touches ? c.touches[0] : c, p = f.clientX, m = f.clientY, T = performance.now(), y = T - a;
148
+ A(() => {
149
+ t.currentX.set(p), t.currentY.set(m), t.deltaX.set(p - t.startX), t.deltaY.set(m - t.startY), y > 0 && t.velocity.set({
150
+ x: (p - X) / y * 1e3,
151
+ y: (m - x) / y * 1e3
152
+ });
153
+ }), X = p, x = m, a = T, u && Math.sqrt(t.deltaX.peek() ** 2 + t.deltaY.peek() ** 2) > 10 && (clearTimeout(u), u = null), o && o({
154
+ x: p,
155
+ y: m,
156
+ deltaX: t.deltaX.peek(),
157
+ deltaY: t.deltaY.peek(),
158
+ velocity: t.velocity.peek()
159
+ });
160
+ }
161
+ function b(c) {
162
+ if (!t.isDragging.peek()) return;
163
+ u && (clearTimeout(u), u = null);
164
+ let f = t.deltaX.peek(), p = t.deltaY.peek(), m = t.velocity.peek();
165
+ if (Math.sqrt(f ** 2 + p ** 2) < 10 && r && !L && r({ x: t.startX, y: t.startY }), i && (Math.abs(m.x) > 500 || Math.abs(m.y) > 500)) {
166
+ let y = Math.abs(m.x) > Math.abs(m.y) ? m.x > 0 ? "right" : "left" : m.y > 0 ? "down" : "up";
167
+ i({ direction: y, velocity: m });
168
+ }
169
+ d && d({
170
+ deltaX: f,
171
+ deltaY: p,
172
+ velocity: m
173
+ }), t.isDragging.set(!1);
174
+ }
175
+ let E = null;
176
+ function M(c) {
177
+ if (!s || c.touches.length !== 2) return;
178
+ let f = c.touches[0], p = c.touches[1], m = Math.sqrt(
179
+ (p.clientX - f.clientX) ** 2 + (p.clientY - f.clientY) ** 2
180
+ );
181
+ E === null && (E = m);
182
+ let T = m / E, y = (f.clientX + p.clientX) / 2, q = (f.clientY + p.clientY) / 2;
183
+ s({ scale: T, centerX: y, centerY: q });
184
+ }
185
+ function k() {
186
+ E = null;
187
+ }
188
+ typeof e == "function" || e?.current !== void 0 ? O(() => {
189
+ let c = typeof e == "function" ? e() : e.current;
190
+ if (c)
191
+ return F(c);
192
+ }) : e && D(F(e));
193
+ function F(c) {
194
+ return c.addEventListener("mousedown", w), c.addEventListener("touchstart", w, { passive: !g }), window.addEventListener("mousemove", Y), window.addEventListener("touchmove", M), window.addEventListener("touchmove", Y), window.addEventListener("mouseup", b), window.addEventListener("touchend", b), window.addEventListener("touchend", k), () => {
195
+ c.removeEventListener("mousedown", w), c.removeEventListener("touchstart", w), window.removeEventListener("mousemove", Y), window.removeEventListener("touchmove", M), window.removeEventListener("touchmove", Y), window.removeEventListener("mouseup", b), window.removeEventListener("touchend", b), window.removeEventListener("touchend", k);
196
+ };
197
+ }
198
+ return t;
199
+ }
200
+ function j(e) {
201
+ let l = v(e), o = null, h = () => {
202
+ let s = o;
203
+ o = null, s !== null && s();
204
+ };
205
+ D(h);
206
+ let d = (s) => {
207
+ h();
208
+ let i = I((r) => {
209
+ let n = () => {
210
+ o === n && (o = null), r();
211
+ };
212
+ return $(() => s(n)), n;
213
+ });
214
+ return o = i, { stop: () => {
215
+ o === i && h();
216
+ } };
217
+ };
218
+ return {
219
+ value: () => l(),
220
+ setValue: (s) => l.set(s),
221
+ // Spring to target
222
+ spring(s, i = {}) {
223
+ return d((r) => {
224
+ let n = Q(l.peek(), i);
225
+ n.set(s), C(() => {
226
+ l.set(n.current()), n.isAnimating() || r();
227
+ });
228
+ });
229
+ },
230
+ // Tween to target
231
+ timing(s, i = {}) {
232
+ return d((r) => {
233
+ S(l.peek(), s, {
234
+ ...i,
235
+ onUpdate: (n) => l.set(n),
236
+ onComplete: () => {
237
+ r(), i.onComplete && i.onComplete();
238
+ }
239
+ });
240
+ });
241
+ },
242
+ // Interpolate value
243
+ interpolate(s, i) {
244
+ return () => {
245
+ let r = l();
246
+ for (let n = 0; n < s.length - 1; n++)
247
+ if (r >= s[n] && r <= s[n + 1]) {
248
+ let g = (r - s[n]) / (s[n + 1] - s[n]);
249
+ return i[n] + (i[n + 1] - i[n]) * g;
250
+ }
251
+ return r <= s[0] ? i[0] : i[i.length - 1];
252
+ };
253
+ },
254
+ subscribe: l.subscribe
255
+ };
256
+ }
257
+ function _(e) {
258
+ return {
259
+ enter: `${e}-enter`,
260
+ enterActive: `${e}-enter-active`,
261
+ enterDone: `${e}-enter-done`,
262
+ exit: `${e}-exit`,
263
+ exitActive: `${e}-exit-active`,
264
+ exitDone: `${e}-exit-done`
265
+ };
266
+ }
267
+ async function z(e, l, o = "enter", h = 300) {
268
+ let d = _(l);
269
+ return (
270
+ /** @type {Promise<void>} */
271
+ new Promise((s) => {
272
+ P(() => {
273
+ e.classList.add(d[o]), V(() => {
274
+ e.offsetHeight, P(() => {
275
+ e.classList.add(d[`${o}Active`]), setTimeout(() => {
276
+ P(() => {
277
+ e.classList.remove(d[o], d[`${o}Active`]), e.classList.add(d[`${o}Done`]), s();
278
+ });
279
+ }, h);
280
+ });
281
+ });
282
+ });
283
+ })
284
+ );
285
+ }
286
+ export {
287
+ _ as createTransitionClasses,
288
+ z as cssTransition,
289
+ U as easings,
290
+ Q as spring,
291
+ S as tween,
292
+ j as useAnimatedValue,
293
+ W as useGesture,
294
+ H as useTween
295
+ };
package/dist/async.js ADDED
@@ -0,0 +1,180 @@
1
+ // src/async.js
2
+ import {
3
+ _asyncComputed,
4
+ _devCallSite,
5
+ _refresh,
6
+ _isPending,
7
+ _startTransition,
8
+ _currentTransition,
9
+ _onCommit,
10
+ _urgent,
11
+ _latestComputed,
12
+ _runHeldReaders,
13
+ _busy,
14
+ _onQuiet,
15
+ _currentComponent,
16
+ signal,
17
+ untrack,
18
+ getOwner,
19
+ onCleanup,
20
+ __devtools
21
+ } from "./reactive.js";
22
+ import { _seedFor } from "./hydration-data.js";
23
+ import { _enableSuspense } from "./render.js";
24
+ import { useContext } from "./hooks.js";
25
+ import { report, recordObservation, _thrownMessage } from "./diagnostics.js";
26
+ function computed(fn) {
27
+ _enableSuspense();
28
+ if ((process.env.NODE_ENV !== "production")) return (
29
+ /** @type {any} */
30
+ _asyncComputed(fn, _seedFor(null, true), _devCallSite(arguments[1] || fn.name, computed))
31
+ );
32
+ return _asyncComputed(fn, _seedFor(null, true));
33
+ }
34
+ function refresh(c) {
35
+ return _refresh(c);
36
+ }
37
+ function isPending(fn) {
38
+ return _isPending(fn);
39
+ }
40
+ function startTransition(fn) {
41
+ return _startTransition(fn);
42
+ }
43
+ function useTransition() {
44
+ const open = signal(0);
45
+ const calls = /* @__PURE__ */ new Set();
46
+ const owner = getOwner();
47
+ if (owner !== null) onCleanup(() => {
48
+ for (const call of calls) call.abandon();
49
+ });
50
+ const isPending2 = () => open() > 0;
51
+ const start = (fn) => _startTransition(fn, (t, call) => {
52
+ open((n) => n + 1);
53
+ call.owner = owner;
54
+ calls.add(call);
55
+ _onCommit(t, () => {
56
+ open((n) => n - 1);
57
+ calls.delete(call);
58
+ });
59
+ });
60
+ return [isPending2, start];
61
+ }
62
+ function useOptimistic(state, update) {
63
+ const overlays = signal(
64
+ /** @type {Array<{ value: any }>} */
65
+ []
66
+ );
67
+ const base = typeof state === "function" ? state : () => state;
68
+ const optimistic = _latestComputed(() => {
69
+ let value = base();
70
+ for (const o of overlays()) value = update === void 0 ? o.value : update(value, o.value);
71
+ return value;
72
+ });
73
+ const addOptimistic = (value) => {
74
+ const overlay = { value };
75
+ const place = (t2) => {
76
+ if ((process.env.NODE_ENV !== "production")) recordObservation(__devtools, "optimistic:add", overlay, { transition: t2, owner: getOwner() });
77
+ _urgent(() => {
78
+ overlays((list) => [...list, overlay]);
79
+ _runHeldReaders(optimistic);
80
+ });
81
+ _onCommit(t2, () => overlays((list) => ((process.env.NODE_ENV !== "production") && recordObservation(__devtools, "optimistic:drop", overlay, { transition: t2 }), list.filter((o) => o !== overlay))));
82
+ };
83
+ const t = _currentTransition();
84
+ if (t !== null) {
85
+ place(t);
86
+ return;
87
+ }
88
+ if ((process.env.NODE_ENV !== "production")) report("ERR_OPTIMISTIC_OUTSIDE_TRANSITION");
89
+ _startTransition(noop, place);
90
+ };
91
+ return [optimistic, addOptimistic];
92
+ }
93
+ function noop() {
94
+ }
95
+ var promises = /* @__PURE__ */ new WeakMap();
96
+ function use(x) {
97
+ _enableSuspense();
98
+ if (typeof x === "function") return x.Provider === x ? useContext(x) : untrack(x);
99
+ if (x != null && typeof x.then === "function") {
100
+ let entry = promises.get(x);
101
+ if (entry === void 0) {
102
+ const fresh = { status: (
103
+ /** @type {'pending' | 'fulfilled' | 'rejected'} */
104
+ "pending"
105
+ ), value: void 0, reason: void 0 };
106
+ promises.set(x, entry = fresh);
107
+ x.then((value) => {
108
+ fresh.status = "fulfilled";
109
+ fresh.value = value;
110
+ }, (reason) => {
111
+ fresh.status = "rejected";
112
+ fresh.reason = reason;
113
+ });
114
+ }
115
+ if (entry.status === "fulfilled") {
116
+ readSettled(x);
117
+ return entry.value;
118
+ }
119
+ if (entry.status === "rejected") throw entry.reason;
120
+ suspendOn(x);
121
+ throw x;
122
+ }
123
+ throw new TypeError((process.env.NODE_ENV !== "production") ? "[what] use(x) reads a promise, a context or an accessor; it was given " + (x === null ? "null" : typeof x) + "." : "[what] use: unsupported value");
124
+ }
125
+ var suspensions = /* @__PURE__ */ new WeakMap();
126
+ function suspensionsOf() {
127
+ const frame = _currentComponent();
128
+ if (frame === null) return null;
129
+ const instance = frame.props !== void 0 ? frame.props : frame.Component;
130
+ let d = suspensions.get(instance);
131
+ if (d === void 0) suspensions.set(instance, d = { last: null, strikes: 0 });
132
+ return d;
133
+ }
134
+ function readSettled(x) {
135
+ const d = suspensionsOf();
136
+ if (d !== null && d.last === x) d.strikes = 0;
137
+ }
138
+ function suspendOn(x) {
139
+ const d = suspensionsOf();
140
+ if (d === null) return;
141
+ const prior = d.last !== null ? promises.get(d.last) : void 0;
142
+ if (prior !== void 0 && d.last !== x && prior.status !== "pending" && ++d.strikes >= 3) {
143
+ d.last = null;
144
+ d.strikes = 0;
145
+ const frame = (
146
+ /** @type {any} */
147
+ _currentComponent()
148
+ );
149
+ const component = frame.Component.displayName || frame.Component.name || "Anonymous";
150
+ if ((process.env.NODE_ENV !== "production")) report("ERR_USE_UNCACHED_PROMISE", { data: { component } });
151
+ throw Object.assign(new Error((process.env.NODE_ENV !== "production") ? _thrownMessage("ERR_USE_UNCACHED_PROMISE", `Component "${component}" keeps suspending on a new promise: use() received a promise made in the component body. Make it outside the component, or use computed().`) : "[what] use: a new promise on every run"), { code: "ERR_USE_UNCACHED_PROMISE" });
152
+ }
153
+ d.last = x;
154
+ }
155
+ function settled() {
156
+ return new Promise((resolve) => {
157
+ let stop = noop;
158
+ const check = () => {
159
+ const busy = _busy();
160
+ if (busy === 0) {
161
+ stop();
162
+ resolve(void 0);
163
+ } else if (busy === 1) {
164
+ queueMicrotask(check);
165
+ }
166
+ };
167
+ stop = _onQuiet(check);
168
+ check();
169
+ });
170
+ }
171
+ export {
172
+ computed,
173
+ isPending,
174
+ refresh,
175
+ settled,
176
+ startTransition,
177
+ use,
178
+ useOptimistic,
179
+ useTransition
180
+ };
@@ -0,0 +1,134 @@
1
+ // src/async.js
2
+ import {
3
+ _asyncComputed as h,
4
+ _refresh as O,
5
+ _isPending as S,
6
+ _startTransition as d,
7
+ _currentTransition as R,
8
+ _onCommit as _,
9
+ _urgent as k,
10
+ _latestComputed as D,
11
+ _runHeldReaders as b,
12
+ _busy as M,
13
+ _onQuiet as P,
14
+ _currentComponent as m,
15
+ signal as v,
16
+ untrack as T,
17
+ getOwner as I,
18
+ onCleanup as U
19
+ } from "./reactive.min.js";
20
+ import { _seedFor as V } from "./hydration-data.min.js";
21
+ import { _enableSuspense as w } from "./render.min.js";
22
+ import { useContext as N } from "./hooks.min.js";
23
+ function x(e) {
24
+ return w(), h(e, V(null, !0));
25
+ }
26
+ function z(e) {
27
+ return O(e);
28
+ }
29
+ function B(e) {
30
+ return S(e);
31
+ }
32
+ function G(e) {
33
+ return d(e);
34
+ }
35
+ function J() {
36
+ let e = v(0), n = /* @__PURE__ */ new Set(), t = I();
37
+ return t !== null && U(() => {
38
+ for (let a of n) a.abandon();
39
+ }), [() => e() > 0, (a) => d(a, (s, r) => {
40
+ e((i) => i + 1), r.owner = t, n.add(r), _(s, () => {
41
+ e((i) => i - 1), n.delete(r);
42
+ });
43
+ })];
44
+ }
45
+ function K(e, n) {
46
+ let t = v(
47
+ /** @type {Array<{ value: any }>} */
48
+ []
49
+ ), o = typeof e == "function" ? e : () => e, u = D(() => {
50
+ let s = o();
51
+ for (let r of t()) s = n === void 0 ? r.value : n(s, r.value);
52
+ return s;
53
+ });
54
+ return [u, (s) => {
55
+ let r = { value: s }, i = (g) => {
56
+ k(() => {
57
+ t((c) => [...c, r]), b(u);
58
+ }), _(g, () => t((c) => c.filter((y) => y !== r)));
59
+ }, p = R();
60
+ if (p !== null) {
61
+ i(p);
62
+ return;
63
+ }
64
+ d(E, i);
65
+ }];
66
+ }
67
+ function E() {
68
+ }
69
+ var l = /* @__PURE__ */ new WeakMap();
70
+ function L(e) {
71
+ if (w(), typeof e == "function") return e.Provider === e ? N(e) : T(e);
72
+ if (e != null && typeof e.then == "function") {
73
+ let n = l.get(e);
74
+ if (n === void 0) {
75
+ let t = { status: (
76
+ /** @type {'pending' | 'fulfilled' | 'rejected'} */
77
+ "pending"
78
+ ), value: void 0, reason: void 0 };
79
+ l.set(e, n = t), e.then((o) => {
80
+ t.status = "fulfilled", t.value = o;
81
+ }, (o) => {
82
+ t.status = "rejected", t.reason = o;
83
+ });
84
+ }
85
+ if (n.status === "fulfilled")
86
+ return A(e), n.value;
87
+ throw n.status === "rejected" ? n.reason : (H(e), e);
88
+ }
89
+ throw new TypeError("[what] use: unsupported value");
90
+ }
91
+ var f = /* @__PURE__ */ new WeakMap();
92
+ function C() {
93
+ let e = m();
94
+ if (e === null) return null;
95
+ let n = e.props !== void 0 ? e.props : e.Component, t = f.get(n);
96
+ return t === void 0 && f.set(n, t = { last: null, strikes: 0 }), t;
97
+ }
98
+ function A(e) {
99
+ let n = C();
100
+ n !== null && n.last === e && (n.strikes = 0);
101
+ }
102
+ function H(e) {
103
+ let n = C();
104
+ if (n === null) return;
105
+ let t = n.last !== null ? l.get(n.last) : void 0;
106
+ if (t !== void 0 && n.last !== e && t.status !== "pending" && ++n.strikes >= 3) {
107
+ n.last = null, n.strikes = 0;
108
+ let o = (
109
+ /** @type {any} */
110
+ m()
111
+ ), u = o.Component.displayName || o.Component.name || "Anonymous";
112
+ throw Object.assign(new Error("[what] use: a new promise on every run"), { code: "ERR_USE_UNCACHED_PROMISE" });
113
+ }
114
+ n.last = e;
115
+ }
116
+ function X() {
117
+ return new Promise((e) => {
118
+ let n = E, t = () => {
119
+ let o = M();
120
+ o === 0 ? (n(), e(void 0)) : o === 1 && queueMicrotask(t);
121
+ };
122
+ n = P(t), t();
123
+ });
124
+ }
125
+ export {
126
+ x as computed,
127
+ B as isPending,
128
+ z as refresh,
129
+ X as settled,
130
+ G as startTransition,
131
+ L as use,
132
+ K as useOptimistic,
133
+ J as useTransition
134
+ };