what-core 0.13.11 → 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,3334 @@
1
+ // src/reactive.js
2
+ import { report, _setOwnerSource, _thrownMessage, nextBinding, clearNextBinding } from "./diagnostics.js";
3
+ import { __DEV__ as __DEV__2 } from "./env.js";
4
+ var __devtools = null;
5
+ var devtoolsSlot = (process.env.NODE_ENV !== "production") ? (
6
+ /** @type {any} */
7
+ globalThis[/* @__PURE__ */ Symbol.for("what.devtools.v1")] ??= { hooks: null, tiers: /* @__PURE__ */ new Set() }
8
+ ) : null;
9
+ if ((process.env.NODE_ENV !== "production")) {
10
+ devtoolsSlot.tiers.add((hooks) => {
11
+ __devtools = hooks;
12
+ });
13
+ __devtools = devtoolsSlot.hooks;
14
+ }
15
+ function __setDevToolsHooks(hooks) {
16
+ if ((process.env.NODE_ENV !== "production")) {
17
+ devtoolsSlot.hooks = hooks;
18
+ for (const install of devtoolsSlot.tiers) install(hooks);
19
+ }
20
+ }
21
+ var COMPUTED = 1;
22
+ var EFFECT = 2;
23
+ var DIRTY = 4;
24
+ var PENDING = 8;
25
+ var RUNNING = 16;
26
+ var QUEUED = 32;
27
+ var DISPOSED = 64;
28
+ var ERRORED = 128;
29
+ var STABLE = 256;
30
+ var USER = 512;
31
+ var SELECTOR = 1024;
32
+ var KEYED = 2048;
33
+ var RELEASE = 4096;
34
+ var ASYNC = 8192;
35
+ var WAITING = 16384;
36
+ var NOT_READY = 32768;
37
+ var NO_VALUE = 65536;
38
+ var CAPABLE = 131072;
39
+ var ASKS = 262144;
40
+ var HELD = 524288;
41
+ var STAGED = 1048576;
42
+ var OWNS_USER = 2097152;
43
+ var RERUN_OWNER = 4194304;
44
+ var activeSub = null;
45
+ var currentOwner = null;
46
+ var ownerRun = null;
47
+ var runningEffect = null;
48
+ var batchDepth = 0;
49
+ var cycle = 0;
50
+ var queue = [];
51
+ var queueLen = 0;
52
+ var userQueue = [];
53
+ var userQueueLen = 0;
54
+ var flushing = false;
55
+ var flushScheduled = false;
56
+ var MAX_FLUSH_ROUNDS = 100;
57
+ var devRan = [];
58
+ var devRanLen = 0;
59
+ var devWrote = [];
60
+ var devWroteLen = 0;
61
+ var MAX_EVAL_DEPTH = 1e3;
62
+ var evalDepth = 0;
63
+ var deferred = [];
64
+ var DEFER = /* @__PURE__ */ Object.freeze({ toString: () => "[what] deferred evaluation" });
65
+ var pushStack = [];
66
+ var selectorQueue = [];
67
+ var settlingSelectors = false;
68
+ var selectorOps = null;
69
+ var releaseQueue = [];
70
+ var pullOps = null;
71
+ function installPull() {
72
+ if (pullOps === null) pullOps = { mark: markPending, check: checkEffect, unwatched, dispose: disposeComputed, settle: settleInputs, refresh: refreshUntracked };
73
+ }
74
+ var asyncOps = null;
75
+ var txOps = null;
76
+ var currentTx = null;
77
+ var onWrite = null;
78
+ var latestSub = null;
79
+ var devSeq = 0;
80
+ function link(dep, sub) {
81
+ const prevDep = sub.depTail;
82
+ if (prevDep !== null && prevDep.dep === dep) return;
83
+ const nextDep = prevDep !== null ? prevDep.nextDep : sub.depHead;
84
+ if (nextDep !== null && nextDep.dep === dep) {
85
+ nextDep.version = cycle;
86
+ sub.depTail = nextDep;
87
+ return;
88
+ }
89
+ const prevSub = dep.subTail;
90
+ if (prevSub !== null && prevSub.version === cycle && prevSub.sub === sub) return;
91
+ const l = { dep, sub, version: cycle, prevDep, nextDep, prevSub, nextSub: null };
92
+ sub.depTail = l;
93
+ dep.subTail = l;
94
+ if (nextDep !== null) nextDep.prevDep = l;
95
+ if (prevDep !== null) prevDep.nextDep = l;
96
+ else sub.depHead = l;
97
+ if (prevSub !== null) prevSub.nextSub = l;
98
+ else dep.subHead = l;
99
+ }
100
+ function unlink(l) {
101
+ const { dep, sub, prevDep, nextDep, prevSub, nextSub } = l;
102
+ l.version = -1;
103
+ if (nextDep !== null) nextDep.prevDep = prevDep;
104
+ else sub.depTail = prevDep;
105
+ if (prevDep !== null) prevDep.nextDep = nextDep;
106
+ else sub.depHead = nextDep;
107
+ if (nextSub !== null) nextSub.prevSub = prevSub;
108
+ else dep.subTail = prevSub;
109
+ if (prevSub !== null) prevSub.nextSub = nextSub;
110
+ else if ((dep.subHead = nextSub) === null && dep.flags & (COMPUTED | KEYED)) {
111
+ if (dep.flags & KEYED) selectorOps.release(dep);
112
+ else pullOps.unwatched(dep);
113
+ }
114
+ return nextDep;
115
+ }
116
+ var unwatchedQueue = [];
117
+ var unwatching = false;
118
+ function unwatched(c) {
119
+ if (c.depHead === null) return;
120
+ unwatchedQueue.push(c);
121
+ if (unwatching) return;
122
+ unwatching = true;
123
+ try {
124
+ while (unwatchedQueue.length > 0) {
125
+ const node = (
126
+ /** @type {WhatComputedNode} */
127
+ unwatchedQueue.pop()
128
+ );
129
+ if (node.subHead !== null) continue;
130
+ if (node.flags & RUNNING) {
131
+ if ((node.flags & RELEASE) === 0) scheduleRelease(node);
132
+ continue;
133
+ }
134
+ node.flags = node.flags & ~PENDING | DIRTY;
135
+ let d = node.depHead;
136
+ while (d !== null) d = unlink(d);
137
+ }
138
+ } finally {
139
+ unwatching = false;
140
+ }
141
+ }
142
+ function scheduleRelease(c) {
143
+ c.flags |= RELEASE;
144
+ if (releaseQueue.push(c) === 1) queueMicrotask(releaseUnobserved);
145
+ }
146
+ function releaseUnobserved() {
147
+ if (flushScheduled) {
148
+ queueMicrotask(releaseUnobserved);
149
+ return;
150
+ }
151
+ for (let i = 0; i < releaseQueue.length; i++) {
152
+ const c = releaseQueue[i];
153
+ const f = c.flags &= ~RELEASE;
154
+ if (f & DISPOSED) {
155
+ for (let l = c.subHead; l !== null; ) {
156
+ const next = l.nextSub;
157
+ unlink(l);
158
+ l = next;
159
+ }
160
+ } else if (c.subHead === null && (f & RUNNING) === 0 && ((f & SELECTOR) === 0 || c.keys.size === 0)) {
161
+ unwatched(c);
162
+ }
163
+ }
164
+ releaseQueue.length = 0;
165
+ }
166
+ function purgeDeps(sub) {
167
+ const tail = sub.depTail;
168
+ let l = tail !== null ? tail.nextDep : sub.depHead;
169
+ while (l !== null) l = unlink(l);
170
+ }
171
+ function unlinkAllDeps(sub) {
172
+ let l = sub.depHead;
173
+ while (l !== null) l = unlink(l);
174
+ }
175
+ function propagate(l) {
176
+ do {
177
+ const sub = l.sub;
178
+ const f = sub.flags;
179
+ if ((f & (DIRTY | DISPOSED)) === 0) {
180
+ sub.flags = f | DIRTY;
181
+ if ((f & PENDING) === 0) {
182
+ if (f & EFFECT) enqueue(sub);
183
+ else if (sub.subHead !== null) pullOps.mark(sub.subHead);
184
+ else if (f & SELECTOR) selectorQueue.push(sub);
185
+ }
186
+ }
187
+ } while ((l = l.nextSub) !== null);
188
+ }
189
+ function markPending(l) {
190
+ let sp = 0;
191
+ for (; ; ) {
192
+ const sub = l.sub;
193
+ const f = sub.flags;
194
+ if ((f & (DIRTY | PENDING | DISPOSED)) === 0) {
195
+ sub.flags = f | PENDING;
196
+ if (f & EFFECT) enqueue(sub);
197
+ else if (sub.subHead !== null) {
198
+ if (l.nextSub !== null) pushStack[sp++] = l.nextSub;
199
+ l = sub.subHead;
200
+ continue;
201
+ } else if (f & SELECTOR) {
202
+ selectorQueue.push(sub);
203
+ }
204
+ }
205
+ if ((l = l.nextSub) !== null) continue;
206
+ if (sp === 0) return;
207
+ l = pushStack[--sp];
208
+ pushStack[sp] = void 0;
209
+ }
210
+ }
211
+ function shallowPropagate(l) {
212
+ do {
213
+ const sub = l.sub;
214
+ const f = sub.flags;
215
+ if ((f & (PENDING | DIRTY)) === PENDING) sub.flags = f | DIRTY;
216
+ } while ((l = l.nextSub) !== null);
217
+ }
218
+ function checkDirty(l, sub) {
219
+ let stack = null;
220
+ let sp = 0;
221
+ let dirty = false;
222
+ top: for (; ; ) {
223
+ const dep = l.dep;
224
+ const df = dep.flags;
225
+ if (sub.flags & DIRTY) {
226
+ dirty = true;
227
+ } else if ((df & (COMPUTED | DIRTY | RUNNING)) === (COMPUTED | DIRTY)) {
228
+ if (updateComputed(dep)) {
229
+ if (l.version === -1) return stopWalk(dep, sub);
230
+ if (dep.subHead.nextSub !== null) shallowPropagate(dep.subHead);
231
+ dirty = true;
232
+ } else if (l.version === -1) {
233
+ return true;
234
+ }
235
+ } else if ((df & (COMPUTED | PENDING)) === (COMPUTED | PENDING)) {
236
+ if (stack === null) stack = [];
237
+ stack[sp++] = l;
238
+ l = dep.depHead;
239
+ sub = dep;
240
+ continue;
241
+ }
242
+ if (!dirty && l.nextDep !== null) {
243
+ l = l.nextDep;
244
+ continue;
245
+ }
246
+ while (sp > 0) {
247
+ l = /** @type {any[]} */
248
+ stack[--sp];
249
+ if (dirty) {
250
+ if ((sub.flags & (RUNNING | DISPOSED)) === 0 && updateComputed(sub)) {
251
+ if (l.version === -1) return stopWalk(sub, l.sub);
252
+ if (sub.subHead.nextSub !== null) shallowPropagate(sub.subHead);
253
+ sub = l.sub;
254
+ continue;
255
+ }
256
+ if (l.version === -1) return true;
257
+ dirty = false;
258
+ } else {
259
+ if (l.version === -1) return true;
260
+ sub.flags &= ~PENDING;
261
+ }
262
+ sub = l.sub;
263
+ if (l.nextDep !== null) {
264
+ l = l.nextDep;
265
+ continue top;
266
+ }
267
+ }
268
+ return dirty;
269
+ }
270
+ }
271
+ function stopWalk(changed, walker) {
272
+ if (changed.subHead !== null) shallowPropagate(changed.subHead);
273
+ walker.flags |= DIRTY;
274
+ return true;
275
+ }
276
+ function updateComputed(c) {
277
+ const causes = (process.env.NODE_ENV !== "production") && devTracksCauses() ? devCauses(c) : null;
278
+ const seen = (process.env.NODE_ENV !== "production") ? c.devSeen : void 0;
279
+ if ((process.env.NODE_ENV !== "production")) c.devSeen = devSeq;
280
+ if (c.owned !== null) disposeRun(c);
281
+ const prevSub = activeSub;
282
+ const mark = deferred.length;
283
+ const oldFlags = c.flags;
284
+ activeSub = c;
285
+ ++cycle;
286
+ const depth = evalDepth++;
287
+ c.depTail = null;
288
+ c.flags = oldFlags & ~(DIRTY | PENDING | ERRORED | NOT_READY) | RUNNING;
289
+ let value;
290
+ let threw = false;
291
+ try {
292
+ value = (oldFlags & CAPABLE) === 0 ? c.fn() : asyncOps.run(c, oldFlags);
293
+ } catch (err) {
294
+ value = err;
295
+ threw = true;
296
+ }
297
+ activeSub = prevSub;
298
+ evalDepth = depth;
299
+ if (c.flags & DISPOSED) {
300
+ unlinkAllDeps(c);
301
+ if (c.owned !== null) disposeRun(c);
302
+ return false;
303
+ }
304
+ purgeDeps(c);
305
+ if (deferred.length !== mark) {
306
+ c.flags = c.flags & ~RUNNING | DIRTY | oldFlags & ERRORED;
307
+ if ((process.env.NODE_ENV !== "production")) c.devSeen = seen;
308
+ throw DEFER;
309
+ }
310
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectRun", c, { causes });
311
+ const old = c.value;
312
+ if (threw) {
313
+ if (asyncOps !== null) {
314
+ const changed = asyncOps.caught(c, value, oldFlags);
315
+ if (changed !== void 0) return changed;
316
+ }
317
+ c.flags = c.flags & ~RUNNING | ERRORED;
318
+ if (oldFlags & ERRORED && old === value) return false;
319
+ } else {
320
+ c.flags &= ~(RUNNING | NO_VALUE);
321
+ if ((oldFlags & (ERRORED | NOT_READY)) === 0 && (old === value ? old !== 0 || 1 / old === 1 / value : old !== old && value !== value)) {
322
+ if ((process.env.NODE_ENV !== "production") && __devtools?.trace) devHook("onComputedEqual", c);
323
+ return false;
324
+ }
325
+ }
326
+ c.value = value;
327
+ if ((process.env.NODE_ENV !== "production")) {
328
+ c.devSeq = ++devSeq;
329
+ if (__devtools?.trace) devHook("onComputedChange", c);
330
+ }
331
+ if (c.flags & SELECTOR) selectorOps.notify(c, old, oldFlags);
332
+ return true;
333
+ }
334
+ function refresh(c) {
335
+ if (evalDepth === 0) {
336
+ deferred.push(c);
337
+ settleDeferred();
338
+ } else if (evalDepth >= MAX_EVAL_DEPTH) {
339
+ c.flags |= RUNNING;
340
+ deferred.push(c);
341
+ throw DEFER;
342
+ } else {
343
+ refreshOne(c);
344
+ }
345
+ if (activeSub === null && c.subHead === null && (c.flags & (RELEASE | SELECTOR)) === 0 && c.depHead !== null) {
346
+ scheduleRelease(c);
347
+ }
348
+ }
349
+ function refreshOne(c) {
350
+ const f = c.flags;
351
+ if (f & DIRTY || f & PENDING && checkDirty(c.depHead, c) && (c.flags & DISPOSED) === 0) {
352
+ if (updateComputed(c) && c.subHead !== null) shallowPropagate(c.subHead);
353
+ } else {
354
+ c.flags &= ~PENDING;
355
+ }
356
+ }
357
+ function settleDeferred() {
358
+ while (deferred.length > 0) {
359
+ const n = deferred.length;
360
+ const node = deferred[n - 1];
361
+ const isEffect = (node.flags & EFFECT) !== 0;
362
+ if (!isEffect) node.flags &= ~RUNNING;
363
+ try {
364
+ if (isEffect) {
365
+ if (node.flags & PENDING && checkDirty(node.depHead, node)) node.flags |= DIRTY;
366
+ } else if (node.flags & (DIRTY | PENDING) && !(node.flags & DISPOSED)) {
367
+ refreshOne(node);
368
+ }
369
+ } catch (err) {
370
+ if (err !== DEFER) {
371
+ for (const waiting of deferred) if (!(waiting.flags & EFFECT)) waiting.flags &= ~RUNNING;
372
+ deferred.length = 0;
373
+ throw err;
374
+ }
375
+ if (!isEffect) node.flags |= RUNNING;
376
+ continue;
377
+ }
378
+ deferred.length = n - 1;
379
+ }
380
+ }
381
+ function checkEffect(e) {
382
+ try {
383
+ return checkDirty(e.depHead, e);
384
+ } catch (err) {
385
+ if (err !== DEFER) throw err;
386
+ deferred.unshift(e);
387
+ settleDeferred();
388
+ return (e.flags & DIRTY) !== 0 || (e.flags & PENDING) !== 0 && checkDirty(e.depHead, e);
389
+ }
390
+ }
391
+ function refreshRead(c) {
392
+ if (c.flags & RUNNING) throw cycleError(c);
393
+ refresh(c);
394
+ }
395
+ function cycleError(node) {
396
+ return Object.assign(new Error((process.env.NODE_ENV !== "production") ? _thrownMessage("ERR_COMPUTED_CYCLE", `Computed "${devName(node)}" reads its own value, directly or through computeds that read it.`) : "[what] Cycle detected: a computed reads its own value"), { code: "ERR_COMPUTED_CYCLE" });
397
+ }
398
+ var NODE = /* @__PURE__ */ Symbol("what.node");
399
+ function lazyMethod(name, make) {
400
+ return {
401
+ configurable: true,
402
+ /** @this {any} */
403
+ get() {
404
+ const f = make(this);
405
+ Object.defineProperty(this, name, { value: f, writable: true, configurable: true });
406
+ return f;
407
+ },
408
+ /** @this {any} */
409
+ set(v) {
410
+ Object.defineProperty(this, name, { value: v, writable: true, configurable: true });
411
+ }
412
+ };
413
+ }
414
+ var signalProto = null;
415
+ var computedProto = null;
416
+ function signalPrototype() {
417
+ if (signalProto === null) {
418
+ signalProto = Object.create(Function.prototype, {
419
+ _signal: { value: true, writable: true, configurable: true },
420
+ set: lazyMethod("set", (s) => (next) => s(next)),
421
+ peek: lazyMethod("peek", (s) => {
422
+ const node = s[NODE];
423
+ return () => node.value;
424
+ }),
425
+ subscribe: lazyMethod("subscribe", (s) => (fn) => effect(() => fn(s()))),
426
+ mutate: lazyMethod("mutate", (s) => {
427
+ const node = s[NODE];
428
+ return (fn) => mutateSignal(s, node, fn);
429
+ })
430
+ });
431
+ }
432
+ return signalProto;
433
+ }
434
+ function computedPrototype() {
435
+ if (computedProto === null) {
436
+ computedProto = Object.create(Function.prototype, {
437
+ _signal: { value: true, writable: true, configurable: true },
438
+ peek: lazyMethod("peek", (read) => () => untrack(read))
439
+ });
440
+ }
441
+ return computedProto;
442
+ }
443
+ function writeSignal(sig, node, next) {
444
+ if ((process.env.NODE_ENV !== "production") && activeSub !== null && activeSub.flags & COMPUTED) devWriteInComputed(sig, activeSub);
445
+ const prev = node.value;
446
+ if (typeof next === "function") next = next(prev);
447
+ if (prev === next ? prev !== 0 || 1 / prev === 1 / next : prev !== prev && next !== next) return;
448
+ node.value = next;
449
+ notify(sig, node, prev);
450
+ }
451
+ function mutateSignal(sig, node, fn) {
452
+ if ((process.env.NODE_ENV !== "production") && activeSub !== null && activeSub.flags & COMPUTED) devWriteInComputed(sig, activeSub);
453
+ fn(node.value);
454
+ notify(sig, node, node.value);
455
+ }
456
+ function notify(sig, node, prev) {
457
+ if ((process.env.NODE_ENV !== "production")) {
458
+ node.devSeq = ++devSeq;
459
+ if (flushing && runningEffect !== null && devWrote[devWroteLen - 1] !== runningEffect) devWrote[devWroteLen++] = runningEffect;
460
+ if (txOps !== null) devWriteAfterAwait(sig, node);
461
+ if (__devtools) devHook("onSignalUpdate", sig, node.value, prev);
462
+ }
463
+ if (node.subHead !== null) {
464
+ if (onWrite !== null) onWrite(node);
465
+ propagate(node.subHead);
466
+ if (selectorQueue.length !== 0) selectorOps.settle();
467
+ if (batchDepth === 0 && !flushing) scheduleFlush();
468
+ }
469
+ }
470
+ function signal(initial, debugName) {
471
+ const node = { value: initial, subHead: null, subTail: null, flags: 0 };
472
+ function sig(next) {
473
+ if (arguments.length === 0) {
474
+ if (activeSub !== null) link(node, activeSub);
475
+ return node.value;
476
+ }
477
+ writeSignal(sig, node, next);
478
+ }
479
+ sig[NODE] = node;
480
+ Object.setPrototypeOf(sig, signalPrototype());
481
+ if ((process.env.NODE_ENV !== "production")) devSignal(sig, node, devNamed(debugName, arguments[2]));
482
+ return (
483
+ /** @type {WhatSignalFunction} */
484
+ /** @type {unknown} */
485
+ sig
486
+ );
487
+ }
488
+ function _rowItem(item) {
489
+ return { value: item, subHead: null, subTail: null, flags: 0, builder: activeSub, building: true, taken: false, keys: null, fields: null };
490
+ }
491
+ var readingKey;
492
+ var propField;
493
+ var propCell = null;
494
+ var propProbe = (process.env.NODE_ENV !== "production") ? { flags: DISPOSED, depHead: null, depTail: null } : null;
495
+ function _readRowItem(node, key) {
496
+ if (node.building && (activeSub === null || activeSub === node.builder || (process.env.NODE_ENV !== "production") && activeSub === propProbe)) {
497
+ const field = key !== void 0 ? key : readingKey;
498
+ if (field === void 0 && propField !== void 0 && propCell === null) propCell = node;
499
+ else recordRead(node, field);
500
+ } else if (activeSub !== null) link(node, activeSub);
501
+ return node.value;
502
+ }
503
+ function recordRead(node, field) {
504
+ if (node.taken || field === null) return;
505
+ if (field === void 0) node.taken = true;
506
+ else if (node.keys === null) node.keys = [field];
507
+ else if (!node.keys.includes(field)) node.keys.push(field);
508
+ }
509
+ function _propField(props, name, key, record) {
510
+ const outerField = propField;
511
+ const outerCell = propCell;
512
+ const outerSub = activeSub;
513
+ const outerRun = ownerRun;
514
+ const probing = (process.env.NODE_ENV !== "production") && record !== void 0 && !record.seen && outerSub === null;
515
+ if (probing) {
516
+ activeSub = ownerRun = propProbe;
517
+ ++cycle;
518
+ }
519
+ propField = key;
520
+ propCell = null;
521
+ let value;
522
+ let cell;
523
+ let reactive = true;
524
+ try {
525
+ value = props[name];
526
+ } finally {
527
+ cell = propCell;
528
+ propField = outerField;
529
+ propCell = outerCell;
530
+ if (probing) {
531
+ activeSub = outerSub;
532
+ ownerRun = outerRun;
533
+ reactive = propProbe.depHead !== null;
534
+ unlinkAllDeps(propProbe);
535
+ }
536
+ }
537
+ if (cell !== null) recordRead(cell, value === cell.value ? key : void 0);
538
+ else if ((process.env.NODE_ENV !== "production") && record !== void 0 && !record.seen && reactive) {
539
+ record.seen = true;
540
+ report(record.code, { data: record.data, loc: record.loc, subject: { kind: "component", name: record.data.component, id: record.loc } });
541
+ }
542
+ return value[key];
543
+ }
544
+ function _readKey(key, read) {
545
+ const outer = readingKey;
546
+ readingKey = key;
547
+ try {
548
+ return read();
549
+ } finally {
550
+ readingKey = outer;
551
+ }
552
+ }
553
+ function sameKeys(keys, prev, next) {
554
+ if (prev == null || next == null) return false;
555
+ for (let i = 0; i < keys.length; i++) {
556
+ if (!Object.is(prev[keys[i]], next[keys[i]])) return false;
557
+ }
558
+ return true;
559
+ }
560
+ function _setRowItem(node, item, rebuildTaken) {
561
+ const prev = node.value;
562
+ if (prev === item) return false;
563
+ if (rebuildTaken && (node.taken || node.keys !== null && !sameKeys(node.keys, prev, item))) return true;
564
+ node.value = item;
565
+ const fields = node.fields;
566
+ if (fields !== null) {
567
+ for (let i = 0; i < fields.length; i += 5) {
568
+ if (!fields[i + 2](fields, i, item, node) && rebuildTaken) return true;
569
+ }
570
+ }
571
+ notify(node, node, prev);
572
+ return false;
573
+ }
574
+ function _livesWithRow(cell, owner) {
575
+ const scope = cell.building;
576
+ for (let o = owner; o !== scope; o = o.owner) {
577
+ if (o == null || o.Component === void 0) return false;
578
+ }
579
+ return true;
580
+ }
581
+ var probe = { flags: DISPOSED, depHead: null, depTail: null };
582
+ function _readAlone(read, cell) {
583
+ const prevSub = activeSub;
584
+ const { builder, building: building2, taken } = cell;
585
+ cell.builder = activeSub = probe;
586
+ cell.building = cell.taken = true;
587
+ ++cycle;
588
+ try {
589
+ const value = read();
590
+ return probe.depHead === null ? value : _readAlone;
591
+ } finally {
592
+ activeSub = prevSub;
593
+ cell.builder = builder;
594
+ cell.building = building2;
595
+ cell.taken = taken;
596
+ unlinkAllDeps(probe);
597
+ }
598
+ }
599
+ function createComputedNode(fn) {
600
+ installPull();
601
+ const node = {
602
+ value: void 0,
603
+ subHead: null,
604
+ subTail: null,
605
+ depHead: null,
606
+ depTail: null,
607
+ flags: COMPUTED | DIRTY | NO_VALUE,
608
+ fn,
609
+ owner: null,
610
+ owned: null
611
+ };
612
+ return node;
613
+ }
614
+ function own(node) {
615
+ const now = ownerNow();
616
+ if (now === null) return;
617
+ const o = scopeOf(now);
618
+ node.owner = o;
619
+ if ((o.flags & DISPOSED) === 0) o.disposals.push(node);
620
+ }
621
+ function computedReader(node) {
622
+ function read() {
623
+ const f = node.flags;
624
+ if (f & (DIRTY | PENDING | DISPOSED | RUNNING)) {
625
+ if (f & DISPOSED) {
626
+ if (f & ERRORED) throw node.value;
627
+ return node.value;
628
+ }
629
+ refreshRead(node);
630
+ }
631
+ if (activeSub !== null) link(node, activeSub);
632
+ if (node.flags & (ERRORED | NOT_READY)) return readFailed(node);
633
+ return node.value;
634
+ }
635
+ Object.setPrototypeOf(read, computedPrototype());
636
+ if ((process.env.NODE_ENV !== "production")) devComputed(read, node);
637
+ return (
638
+ /** @type {WhatComputedFunction} */
639
+ /** @type {unknown} */
640
+ read
641
+ );
642
+ }
643
+ function readFailed(node) {
644
+ if (asyncOps !== null) return asyncOps.read(node);
645
+ throw node.value;
646
+ }
647
+ function computed(fn) {
648
+ const node = createComputedNode(fn);
649
+ if ((process.env.NODE_ENV !== "production") && arguments[1]) node.devName = arguments[1];
650
+ own(node);
651
+ return computedReader(node);
652
+ }
653
+ function memo(fn) {
654
+ const node = createComputedNode(fn);
655
+ const read = computedReader(node);
656
+ const now = ownerNow();
657
+ if (now !== null) node.owner = scopeOf(now);
658
+ refresh(node);
659
+ if (node.flags & ERRORED) {
660
+ disposeComputed(node);
661
+ throw node.value;
662
+ }
663
+ own(node);
664
+ if ((node.flags & RELEASE) === 0 && node.depHead !== null) scheduleRelease(node);
665
+ return read;
666
+ }
667
+ function disposeComputed(c) {
668
+ if (c.flags & DISPOSED) return;
669
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectDispose", c);
670
+ c.flags = DISPOSED | c.flags & (ERRORED | RELEASE);
671
+ unlinkAllDeps(c);
672
+ if (c.owned !== null) disposeRun(c);
673
+ if (c.subHead !== null && (c.flags & RELEASE) === 0) scheduleRelease(c);
674
+ }
675
+ function _createSelector(source) {
676
+ if (selectorOps === null) selectorOps = { notify: notifyKeys, settle: settleSelectors, release: releaseKey };
677
+ installPull();
678
+ const s = {
679
+ value: void 0,
680
+ subHead: null,
681
+ subTail: null,
682
+ depHead: null,
683
+ depTail: null,
684
+ flags: COMPUTED | SELECTOR | DIRTY,
685
+ fn: source,
686
+ owner: null,
687
+ owned: null,
688
+ keys: /* @__PURE__ */ new Map()
689
+ };
690
+ own(s);
691
+ return function isSelected(key) {
692
+ const f = s.flags;
693
+ if (f & (DIRTY | PENDING | DISPOSED | RUNNING)) {
694
+ if ((f & DISPOSED) === 0) refreshRead(s);
695
+ }
696
+ if (activeSub !== null) {
697
+ if ((s.flags & DISPOSED) === 0) {
698
+ let k = s.keys.get(key);
699
+ if (k === void 0) {
700
+ const node = { value: key, subHead: null, subTail: null, flags: KEYED, sel: s };
701
+ s.keys.set(key, k = node);
702
+ }
703
+ link(k, activeSub);
704
+ }
705
+ } else if (s.keys.size === 0 && (s.flags & (RELEASE | DISPOSED)) === 0 && s.depHead !== null) {
706
+ scheduleRelease(s);
707
+ }
708
+ if (s.flags & ERRORED) throw s.value;
709
+ return key === s.value;
710
+ };
711
+ }
712
+ function notifyKeys(s, old, oldFlags) {
713
+ const keys = s.keys;
714
+ if (keys.size === 0) return;
715
+ if ((oldFlags | s.flags) & ERRORED) {
716
+ for (const k of keys.values()) if (k.subHead !== null) propagate(k.subHead);
717
+ } else {
718
+ let k = keys.get(old);
719
+ if (k !== void 0 && k.subHead !== null) propagate(k.subHead);
720
+ k = keys.get(s.value);
721
+ if (k !== void 0 && k.subHead !== null) propagate(k.subHead);
722
+ }
723
+ if (selectorQueue.length !== 0) settleSelectors();
724
+ if (batchDepth === 0 && !flushing) scheduleFlush();
725
+ }
726
+ function settleSelectors() {
727
+ if (settlingSelectors) return;
728
+ settlingSelectors = true;
729
+ try {
730
+ for (let i = 0; i < selectorQueue.length; i++) {
731
+ const s = selectorQueue[i];
732
+ if ((s.flags & (DIRTY | PENDING)) !== 0 && (s.flags & (RUNNING | DISPOSED)) === 0) {
733
+ try {
734
+ refresh(s);
735
+ } catch (err) {
736
+ if (err !== DEFER) throw err;
737
+ }
738
+ }
739
+ }
740
+ } finally {
741
+ selectorQueue.length = 0;
742
+ settlingSelectors = false;
743
+ }
744
+ }
745
+ function releaseKey(k) {
746
+ const s = k.sel;
747
+ if (s.keys.get(k.value) === k) s.keys.delete(k.value);
748
+ if (s.keys.size === 0 && (s.flags & (RELEASE | DISPOSED)) === 0 && s.depHead !== null) scheduleRelease(s);
749
+ }
750
+ var NotReady = class {
751
+ /** @param {any} node */
752
+ constructor(node) {
753
+ this.node = node;
754
+ this.done = false;
755
+ this.promise = null;
756
+ this.resolve = null;
757
+ }
758
+ get name() {
759
+ return "NotReady";
760
+ }
761
+ get message() {
762
+ return "[what] An async value was read before it settled.";
763
+ }
764
+ /** @param {any} [onFulfilled] @param {any} [onRejected] */
765
+ then(onFulfilled, onRejected) {
766
+ if (this.promise === null) {
767
+ this.promise = new Promise((resolve) => {
768
+ if (this.done) resolve();
769
+ else this.resolve = resolve;
770
+ });
771
+ }
772
+ return this.promise.then(onFulfilled, onRejected);
773
+ }
774
+ };
775
+ function settleWait(w) {
776
+ w.done = true;
777
+ if (w.resolve !== null) w.resolve();
778
+ }
779
+ function _isNotReady(value) {
780
+ return value instanceof NotReady;
781
+ }
782
+ var inFlight = 0;
783
+ var streams = 0;
784
+ var tracked = 0;
785
+ var waitsOf = null;
786
+ var companionOf = null;
787
+ var pendingReaders = null;
788
+ var pendsOf = null;
789
+ var sourcesOf = null;
790
+ var thrownError;
791
+ var thrownFrom = null;
792
+ function forgetThrown() {
793
+ thrownError = void 0;
794
+ thrownFrom = null;
795
+ }
796
+ var quietHooks = null;
797
+ var quietQueued = false;
798
+ var STARTED = /* @__PURE__ */ Object.freeze({});
799
+ function installAsync() {
800
+ if (asyncOps !== null) return;
801
+ waitsOf = /* @__PURE__ */ new WeakMap();
802
+ companionOf = /* @__PURE__ */ new WeakMap();
803
+ pendingReaders = /* @__PURE__ */ new WeakSet();
804
+ pendsOf = /* @__PURE__ */ new WeakMap();
805
+ sourcesOf = /* @__PURE__ */ new WeakMap();
806
+ quietHooks = /* @__PURE__ */ new Set();
807
+ asyncOps = {
808
+ run: capableRun,
809
+ caught: asyncCaught,
810
+ read: readAsync,
811
+ held: holdEffect
812
+ };
813
+ }
814
+ function newRecord() {
815
+ return {
816
+ run: 0,
817
+ /** @type {AbortController | null} */
818
+ ac: null,
819
+ /** @type {{ c: any, iter: any } | null} */
820
+ flight: null,
821
+ /** @type {NotReady | null} */
822
+ wait: null,
823
+ /** @type {NotReady | null} */
824
+ upstream: null,
825
+ /** @type {any} */
826
+ error: void 0,
827
+ /** @type {{ node: any, run: number } | null} */
828
+ failure: null,
829
+ /** @type {any} */
830
+ pend: null,
831
+ /** @type {any} */
832
+ tx: null,
833
+ /** @type {any} */
834
+ before: void 0,
835
+ viewed: false,
836
+ /** @type {Array<[(v: any) => void, (e: any) => void]> | null} */
837
+ waiters: null,
838
+ tracking: false,
839
+ /** @type {Map<any, any> | null} */
840
+ store: null,
841
+ /** @type {any} */
842
+ key: null,
843
+ owner: "",
844
+ /** @type {(() => void) | null} */
845
+ stored: null,
846
+ /** @type {any} */
847
+ companion: null
848
+ };
849
+ }
850
+ function recordOf(c) {
851
+ return c.a !== null ? c.a : c.a = newRecord();
852
+ }
853
+ function capableRun(c, oldFlags) {
854
+ const mark = deferred.length;
855
+ ++evalDepth;
856
+ const value = oldFlags & ASKS ? c.fn(runArg(c)) : c.fn();
857
+ --evalDepth;
858
+ if (value !== null && (typeof value === "object" || typeof value === "function")) {
859
+ const thenable = typeof value.then === "function";
860
+ const make = thenable ? void 0 : value[Symbol.asyncIterator];
861
+ if (thenable || typeof make === "function") {
862
+ startRun(c, value, thenable ? null : make.call(value));
863
+ throw STARTED;
864
+ }
865
+ }
866
+ if ((oldFlags & (WAITING | NOT_READY | NO_VALUE)) !== 0 && deferred.length === mark) answeredNow(c, value);
867
+ return value;
868
+ }
869
+ function answeredNow(c, value) {
870
+ const a = c.a;
871
+ if (a === null) return;
872
+ if (c.flags & WAITING) {
873
+ endFlight(a);
874
+ inFlight--;
875
+ c.flags &= ~WAITING;
876
+ statusChanged(c);
877
+ reach(c.subHead);
878
+ }
879
+ if ((process.env.NODE_ENV !== "production")) devAsyncState(c, "ready");
880
+ if (a.store !== null && (c.flags & ASKS) !== 0) seedOps.settled(a, value, false);
881
+ settleOutcome(a, value, false);
882
+ if (a.tx !== null) txOps.answered(c);
883
+ }
884
+ function makeAsync(c) {
885
+ const a = recordOf(c);
886
+ c.flags |= ASYNC;
887
+ if (a.companion !== null) return;
888
+ const o = c.owner;
889
+ if (o !== null && o.flags & DISPOSED) return;
890
+ const e = { fn: noop, depHead: null, depTail: null, flags: EFFECT | ASYNC, cleanup: null, owner: o, parent: null, owned: null };
891
+ e.fn = () => {
892
+ link(c, e);
893
+ };
894
+ a.companion = e;
895
+ companionOf.set(e, c);
896
+ link(c, e);
897
+ if (o !== null) o.disposals.push(() => {
898
+ disposeEffect(e);
899
+ asyncDisposed(c);
900
+ });
901
+ }
902
+ function runArg(c) {
903
+ const a = recordOf(c);
904
+ if (a.ac !== null) a.ac.abort();
905
+ const ac = a.ac = new AbortController();
906
+ if (a.tracking) ac.abort();
907
+ return { signal: ac.signal };
908
+ }
909
+ function startRun(c, promise, iter) {
910
+ const a = recordOf(c);
911
+ endFlight(a);
912
+ a.run++;
913
+ if ((c.flags & WAITING) === 0) inFlight++;
914
+ makeAsync(c);
915
+ c.flags |= WAITING;
916
+ if ((process.env.NODE_ENV !== "production")) devAsyncState(c, c.flags & NO_VALUE ? "unresolved" : "pending", a.run);
917
+ if (txOps !== null) txOps.attribute(c, a);
918
+ if (a.store !== null) seedOps.pending(a);
919
+ const f = a.flight = { c, iter };
920
+ if (iter !== null) {
921
+ streams++;
922
+ pump(f, iter);
923
+ } else {
924
+ Promise.resolve(promise).then((v) => land(f, v, false, false), (e) => land(f, e, true, false));
925
+ }
926
+ }
927
+ function pump(f, iter) {
928
+ let step;
929
+ try {
930
+ step = iter.next();
931
+ } catch (err) {
932
+ step = Promise.reject(err);
933
+ }
934
+ Promise.resolve(step).then((s) => {
935
+ const c = f.c;
936
+ if (c === null) return;
937
+ if (s.done) {
938
+ if (c.flags & WAITING) land(f, void 0, false, false);
939
+ else {
940
+ endFlight(c.a);
941
+ quietSoon();
942
+ }
943
+ return;
944
+ }
945
+ land(f, s.value, false, true);
946
+ if (f.c !== null) pump(f, iter);
947
+ }, (err) => land(f, err, true, false));
948
+ }
949
+ function endFlight(a) {
950
+ const f = a.flight;
951
+ if (f === null) return;
952
+ a.flight = null;
953
+ f.c = null;
954
+ if (f.iter !== null) {
955
+ const iter = f.iter;
956
+ f.iter = null;
957
+ streams--;
958
+ closeIterator(iter);
959
+ }
960
+ }
961
+ function closeIterator(iter) {
962
+ try {
963
+ if (typeof iter.return === "function") Promise.resolve(iter.return()).catch(noop);
964
+ } catch {
965
+ }
966
+ }
967
+ function noop() {
968
+ }
969
+ function asyncCaught(c, err, oldFlags) {
970
+ if (err === STARTED) {
971
+ c.flags &= ~RUNNING;
972
+ if ((oldFlags & (WAITING | NOT_READY)) === 0) statusChanged(c);
973
+ return false;
974
+ }
975
+ if (err instanceof NotReady) {
976
+ if (oldFlags & WAITING) {
977
+ endFlight(c.a);
978
+ inFlight--;
979
+ if ((process.env.NODE_ENV !== "production")) c.devFlight = null;
980
+ }
981
+ c.flags = c.flags & ~(RUNNING | WAITING) | NOT_READY;
982
+ if (c.a !== void 0) recordOf(c).upstream = err;
983
+ else waitsOf.set(c, err);
984
+ if ((oldFlags & (WAITING | NOT_READY)) === 0) statusChanged(c);
985
+ return (oldFlags & ERRORED) !== 0;
986
+ }
987
+ if ((c.flags & ASYNC) === 0) {
988
+ if (err === thrownError && thrownFrom !== null) sourcesOf.set(c, thrownFrom);
989
+ return void 0;
990
+ }
991
+ if (oldFlags & WAITING) {
992
+ endFlight(c.a);
993
+ inFlight--;
994
+ }
995
+ c.flags = c.flags & ~(RUNNING | WAITING) | ERRORED;
996
+ failed(c, err);
997
+ if (oldFlags & WAITING) {
998
+ statusChanged(c);
999
+ reach(c.subHead);
1000
+ }
1001
+ if (c.a.store !== null) seedOps.settled(c.a, err, true);
1002
+ settleOutcome(c.a, err, true);
1003
+ if (c.a.tx !== null) txOps.answered(c);
1004
+ return true;
1005
+ }
1006
+ function failed(c, err) {
1007
+ const a = c.a;
1008
+ a.error = err;
1009
+ a.failure = { node: c, run: a.run };
1010
+ if ((process.env.NODE_ENV !== "production")) {
1011
+ devAsyncState(c, "errored", void 0, err);
1012
+ if (__devtools) _devError(err, { type: "async", effect: c });
1013
+ }
1014
+ }
1015
+ function settleOutcome(a, result, isError) {
1016
+ const waiters = a.waiters;
1017
+ if (waiters !== null) {
1018
+ a.waiters = null;
1019
+ for (const [resolve, reject] of waiters) (isError ? reject : resolve)(result);
1020
+ }
1021
+ if (a.wait !== null) {
1022
+ settleWait(a.wait);
1023
+ a.wait = null;
1024
+ }
1025
+ }
1026
+ function land(f, result, isError, more) {
1027
+ const c = f.c;
1028
+ if (c === null) return;
1029
+ const a = c.a;
1030
+ if (!more) endFlight(a);
1031
+ settleOutcome(a, result, isError);
1032
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "async:land", c, { run: a.run, errored: isError });
1033
+ if (a.tx !== null) txOps.land(c, result, isError);
1034
+ else apply(c, result, isError);
1035
+ }
1036
+ function apply(c, result, isError) {
1037
+ const a = c.a;
1038
+ const f = c.flags;
1039
+ if (f & WAITING) inFlight--;
1040
+ if (isError) {
1041
+ c.flags = f & ~(WAITING | NOT_READY) | ERRORED;
1042
+ failed(c, result);
1043
+ } else {
1044
+ c.flags = f & ~(WAITING | NOT_READY | NO_VALUE | ERRORED);
1045
+ c.value = result;
1046
+ if ((process.env.NODE_ENV !== "production")) devAsyncState(c, "ready");
1047
+ }
1048
+ if ((process.env.NODE_ENV !== "production")) {
1049
+ c.devSeq = ++devSeq;
1050
+ if (__devtools?.trace) devHook("onAsyncLanding", c);
1051
+ }
1052
+ if (a.store !== null) seedOps.settled(a, result, isError);
1053
+ reach(c.subHead);
1054
+ reach(a.pend !== null ? a.pend.subHead : null);
1055
+ quietSoon();
1056
+ }
1057
+ function statusChanged(c) {
1058
+ const p = c.a != null ? c.a.pend : (
1059
+ /** @type {WeakMap<any, any>} */
1060
+ pendsOf.get(c)
1061
+ );
1062
+ if (p != null) reach(p.subHead);
1063
+ }
1064
+ function reach(head) {
1065
+ if (head === null) return;
1066
+ propagate(head);
1067
+ for (let l = head; l !== null; l = l.nextSub) {
1068
+ const s = l.sub;
1069
+ if ((s.flags & (EFFECT | DIRTY | QUEUED | RUNNING | DISPOSED)) === (EFFECT | DIRTY)) enqueue(s);
1070
+ }
1071
+ if (batchDepth === 0 && !flushing) scheduleFlush();
1072
+ }
1073
+ function readAsync(node) {
1074
+ const f = node.flags;
1075
+ if (f & (WAITING | NOT_READY)) {
1076
+ if (f & NO_VALUE) throw notReady(node, f);
1077
+ if (activeSub !== null && activeSub !== latestSub) throw waitOf(node, f);
1078
+ } else if (f & ERRORED) {
1079
+ if (f & ASYNC) {
1080
+ thrownError = node.a.error;
1081
+ thrownFrom = node.a.failure;
1082
+ } else {
1083
+ thrownError = node.value;
1084
+ thrownFrom = /** @type {WeakMap<any, any>} */
1085
+ sourcesOf.get(node) || null;
1086
+ }
1087
+ if (thrownFrom !== null) queueMicrotask(forgetThrown);
1088
+ throw thrownError;
1089
+ } else if (f & NO_VALUE) {
1090
+ throw notReady(node, f);
1091
+ }
1092
+ if (f & STAGED && activeSub !== null && activeSub === latestSub) {
1093
+ node.a.viewed = true;
1094
+ return node.a.before;
1095
+ }
1096
+ return node.value;
1097
+ }
1098
+ function notReady(node, f) {
1099
+ const w = waitOf(node, f);
1100
+ const src = w.node;
1101
+ if (activeSub === null && src.owner !== null && src.owner === ownerNow() && src.owner.Component !== void 0 && (src.a == null || src.a.store === null)) {
1102
+ const c = src.owner.Component;
1103
+ const component = c.displayName || c.name || "Anonymous";
1104
+ if ((process.env.NODE_ENV !== "production")) report("ERR_ASYNC_READ_IN_BODY", { data: { component } });
1105
+ throw Object.assign(new Error((process.env.NODE_ENV !== "production") ? _thrownMessage("ERR_ASYNC_READ_IN_BODY", `Component "${component}" read an async value it made in its own body before the value landed. Read it in JSX, or make it outside the component.`) : "[what] async value read in the body that made it"), { code: "ERR_ASYNC_READ_IN_BODY" });
1106
+ }
1107
+ return w;
1108
+ }
1109
+ function waitOf(node, f) {
1110
+ if (f & NOT_READY) return node.a === void 0 ? (
1111
+ /** @type {WeakMap<any, any>} */
1112
+ waitsOf.get(node)
1113
+ ) : node.a.upstream;
1114
+ const a = recordOf(node);
1115
+ return a.wait !== null ? a.wait : a.wait = new NotReady(node);
1116
+ }
1117
+ function holdEffect(e, err) {
1118
+ if (!(err instanceof NotReady)) return false;
1119
+ if ((e.flags & HELD) === 0) {
1120
+ for (let o = e.owner; o != null; o = o.owner) {
1121
+ if ((o.flags & DISPOSED) === 0 && typeof o._onPending === "function") {
1122
+ const release = o._onPending(e);
1123
+ if (typeof release === "function") countHeld(e, release);
1124
+ break;
1125
+ }
1126
+ }
1127
+ }
1128
+ return true;
1129
+ }
1130
+ function countHeld(e, release) {
1131
+ e.flags |= HELD;
1132
+ const fn = e.fn;
1133
+ const done = () => {
1134
+ if ((e.flags & HELD) === 0) return;
1135
+ e.flags &= ~HELD;
1136
+ e.fn = fn;
1137
+ release(e);
1138
+ };
1139
+ const held2 = () => {
1140
+ let out;
1141
+ try {
1142
+ out = fn();
1143
+ } catch (err) {
1144
+ if (!(err instanceof NotReady)) done();
1145
+ throw err;
1146
+ }
1147
+ done();
1148
+ return out;
1149
+ };
1150
+ if ((process.env.NODE_ENV !== "production")) held2.inner = fn;
1151
+ held2.release = done;
1152
+ e.fn = held2;
1153
+ if (e.owner !== null) scopeOf(e.owner).disposals.push(done);
1154
+ }
1155
+ function asyncDisposed(c) {
1156
+ const a = c.a;
1157
+ if (c.flags & WAITING) {
1158
+ c.flags &= ~WAITING;
1159
+ inFlight--;
1160
+ }
1161
+ if (a.ac !== null) {
1162
+ a.ac.abort();
1163
+ a.ac = null;
1164
+ }
1165
+ endFlight(a);
1166
+ settleOutcome(a, c.value, false);
1167
+ if (a.tx !== null) txOps.drop(c);
1168
+ quietSoon();
1169
+ }
1170
+ function quietSoon() {
1171
+ const hooks = (
1172
+ /** @type {Set<() => void>} */
1173
+ quietHooks
1174
+ );
1175
+ if (quietQueued || hooks.size === 0) return;
1176
+ quietQueued = true;
1177
+ queueMicrotask(() => {
1178
+ quietQueued = false;
1179
+ for (const hook of [...hooks]) hook();
1180
+ });
1181
+ }
1182
+ function storePending(a) {
1183
+ a.store.set(a.key, {
1184
+ status: "pending",
1185
+ owner: a.owner,
1186
+ promise: new Promise((resolve) => {
1187
+ a.stored = resolve;
1188
+ })
1189
+ });
1190
+ }
1191
+ function storeSettled(a, result, isError) {
1192
+ a.store.set(a.key, isError ? { status: "error", error: result, owner: a.owner } : { status: "ready", value: result, owner: a.owner });
1193
+ if (a.stored !== null) {
1194
+ const done = a.stored;
1195
+ a.stored = null;
1196
+ done();
1197
+ }
1198
+ }
1199
+ function pendOf(c) {
1200
+ if (c.a === void 0) {
1201
+ const map = (
1202
+ /** @type {WeakMap<any, any>} */
1203
+ pendsOf
1204
+ );
1205
+ let p = map.get(c);
1206
+ if (p === void 0) map.set(c, p = { value: false, subHead: null, subTail: null, flags: 0 });
1207
+ return p;
1208
+ }
1209
+ const a = recordOf(c);
1210
+ return a.pend !== null ? a.pend : a.pend = { value: false, subHead: null, subTail: null, flags: 0 };
1211
+ }
1212
+ function refreshUntracked(c) {
1213
+ const sub = activeSub;
1214
+ activeSub = null;
1215
+ try {
1216
+ refresh(c);
1217
+ } finally {
1218
+ activeSub = sub;
1219
+ }
1220
+ }
1221
+ function anyRefreshing(start, sub) {
1222
+ let found = false;
1223
+ const seen = /* @__PURE__ */ new Set();
1224
+ const stack = start.slice();
1225
+ while (stack.length > 0) {
1226
+ const n = stack.pop();
1227
+ if ((n.flags & COMPUTED) === 0 || seen.has(n)) continue;
1228
+ seen.add(n);
1229
+ if (sub !== null) link(pendOf(n), sub);
1230
+ if (n.flags & ASYNC) {
1231
+ if (n.flags & (DIRTY | PENDING) && (n.flags & (RUNNING | DISPOSED)) === 0) refreshUntracked(n);
1232
+ if ((n.flags & (WAITING | NOT_READY)) !== 0 && (n.flags & NO_VALUE) === 0) found = true;
1233
+ }
1234
+ for (let l = n.depHead; l !== null; l = l.nextDep) stack.push(l.dep);
1235
+ }
1236
+ return found;
1237
+ }
1238
+ function readsPending() {
1239
+ if (activeSub !== null && activeSub.flags & EFFECT) pendingReaders.add(activeSub);
1240
+ }
1241
+ function pendingOf(node) {
1242
+ if ((process.env.NODE_ENV !== "production") && activeSub === null) devUntrackedPending("pending()");
1243
+ readsPending();
1244
+ if (node.flags & (DIRTY | PENDING) && (node.flags & (RUNNING | DISPOSED)) === 0) {
1245
+ try {
1246
+ refreshUntracked(node);
1247
+ } catch (err) {
1248
+ if (err === DEFER) throw err;
1249
+ }
1250
+ }
1251
+ if (activeSub !== null) link(node, activeSub);
1252
+ return anyRefreshing([node], activeSub);
1253
+ }
1254
+ function _isPending(fn) {
1255
+ if ((process.env.NODE_ENV !== "production") && activeSub === null) devUntrackedPending("isPending()");
1256
+ readsPending();
1257
+ const sub = activeSub;
1258
+ const probe2 = createComputedNode(fn);
1259
+ const prevLatest = latestSub;
1260
+ latestSub = probe2;
1261
+ try {
1262
+ refreshUntracked(probe2);
1263
+ } finally {
1264
+ latestSub = prevLatest;
1265
+ }
1266
+ const start = [];
1267
+ for (let l = probe2.depHead; l !== null; l = l.nextDep) {
1268
+ start.push(l.dep);
1269
+ if (sub !== null) link(l.dep, sub);
1270
+ }
1271
+ disposeComputed(probe2);
1272
+ return anyRefreshing(start, sub);
1273
+ }
1274
+ function asyncCapableNode(fn) {
1275
+ installPull();
1276
+ return {
1277
+ value: void 0,
1278
+ subHead: null,
1279
+ subTail: null,
1280
+ depHead: null,
1281
+ depTail: null,
1282
+ flags: COMPUTED | DIRTY | NO_VALUE | CAPABLE | (fn.length > 0 ? ASKS : 0),
1283
+ fn,
1284
+ owner: null,
1285
+ owned: null,
1286
+ /** @type {any} */
1287
+ a: null
1288
+ };
1289
+ }
1290
+ var asyncProto = null;
1291
+ function asyncPrototype() {
1292
+ if (asyncProto === null) {
1293
+ asyncProto = Object.create(Function.prototype, {
1294
+ _signal: { value: true, writable: true, configurable: true },
1295
+ peek: lazyMethod("peek", (read) => {
1296
+ const node = read[NODE];
1297
+ return () => peekAsync(node);
1298
+ }),
1299
+ pending: lazyMethod("pending", (read) => {
1300
+ const node = read[NODE];
1301
+ return () => pendingOf(node);
1302
+ })
1303
+ });
1304
+ }
1305
+ return asyncProto;
1306
+ }
1307
+ function peekAsync(node) {
1308
+ if (node.flags & (DIRTY | PENDING) && (node.flags & (RUNNING | DISPOSED)) === 0) {
1309
+ try {
1310
+ refreshUntracked(node);
1311
+ } catch (err) {
1312
+ if (err === DEFER) throw err;
1313
+ }
1314
+ }
1315
+ const f = node.flags;
1316
+ if ((f & (ASYNC | NOT_READY)) === 0 && f & ERRORED) throw node.value;
1317
+ return node.value;
1318
+ }
1319
+ function asyncReader(node) {
1320
+ function read() {
1321
+ const f = node.flags;
1322
+ if (f & (DIRTY | PENDING | DISPOSED | RUNNING)) {
1323
+ if (f & DISPOSED) {
1324
+ if (f & ERRORED && node.a === null) throw node.value;
1325
+ return node.value;
1326
+ }
1327
+ refreshRead(node);
1328
+ }
1329
+ if (activeSub !== null) link(node, activeSub);
1330
+ if (node.flags & (ERRORED | NOT_READY | WAITING | NO_VALUE | STAGED)) return readAsync(node);
1331
+ return node.value;
1332
+ }
1333
+ read[NODE] = node;
1334
+ Object.setPrototypeOf(read, asyncPrototype());
1335
+ if ((process.env.NODE_ENV !== "production")) devComputed(read, node);
1336
+ return (
1337
+ /** @type {WhatComputedFunction} */
1338
+ /** @type {unknown} */
1339
+ read
1340
+ );
1341
+ }
1342
+ var ASYNC_FN = /^Async(?:Generator)?Function$/;
1343
+ function _asyncComputed(fn, seed) {
1344
+ installAsync();
1345
+ const node = asyncCapableNode(fn);
1346
+ if ((process.env.NODE_ENV !== "production") && arguments[2]) node.devName = arguments[2];
1347
+ own(node);
1348
+ const read = asyncReader(node);
1349
+ if ((seed == null || !seedOps.seed(node, seed, fn)) && (fn.length > 0 || ASYNC_FN.test(fn.constructor.name))) {
1350
+ refreshUntracked(node);
1351
+ }
1352
+ return read;
1353
+ }
1354
+ var seedOps = null;
1355
+ function _installSeedOps() {
1356
+ if (seedOps === null) seedOps = { seed: seedFrom, store: null, pending: null, settled: null };
1357
+ }
1358
+ function _installStoreSeedOps() {
1359
+ _installSeedOps();
1360
+ seedOps.store = seedFromStore;
1361
+ seedOps.pending = storePending;
1362
+ seedOps.settled = storeSettled;
1363
+ }
1364
+ function seedFrom(c, seed, fn) {
1365
+ if (seed.store !== void 0) return seedOps.store(c, seed);
1366
+ adopt(c, seed, fn);
1367
+ return true;
1368
+ }
1369
+ function adopt(c, seed, fn) {
1370
+ const a = recordOf(c);
1371
+ c.flags &= ~DIRTY;
1372
+ makeAsync(c);
1373
+ if ("error" in seed) {
1374
+ c.flags |= ERRORED;
1375
+ a.error = seed.error;
1376
+ a.failure = { node: c, run: a.run };
1377
+ if ((process.env.NODE_ENV !== "production")) devAsyncState(c, "errored", void 0, seed.error);
1378
+ } else {
1379
+ c.flags &= ~NO_VALUE;
1380
+ c.value = seed.value;
1381
+ if ((process.env.NODE_ENV !== "production")) devAsyncState(c, "ready");
1382
+ }
1383
+ if (seed.track !== false) trackRun(c, fn);
1384
+ }
1385
+ function trackRun(c, fn) {
1386
+ const a = recordOf(c);
1387
+ a.tracking = true;
1388
+ const prevSub = activeSub;
1389
+ activeSub = c;
1390
+ ++cycle;
1391
+ c.depTail = null;
1392
+ c.flags |= RUNNING;
1393
+ try {
1394
+ const value = fn.length > 0 ? fn(runArg(c)) : fn();
1395
+ if (value !== null && typeof value === "object") {
1396
+ if (typeof value.then === "function") {
1397
+ Promise.resolve(value).catch(noop);
1398
+ } else if (typeof value[Symbol.asyncIterator] === "function") {
1399
+ const iter = value[Symbol.asyncIterator]();
1400
+ Promise.resolve(iter.next()).then(() => closeIterator(iter), noop);
1401
+ }
1402
+ }
1403
+ } catch {
1404
+ }
1405
+ activeSub = prevSub;
1406
+ c.flags &= ~RUNNING;
1407
+ a.tracking = false;
1408
+ purgeDeps(c);
1409
+ }
1410
+ function seedFromStore(c, { store, key, owner }) {
1411
+ const a = recordOf(c);
1412
+ a.store = store;
1413
+ a.key = key;
1414
+ a.owner = owner;
1415
+ const entry = store.get(key);
1416
+ if (entry === void 0) return false;
1417
+ c.flags &= ~DIRTY;
1418
+ makeAsync(c);
1419
+ if (entry.status === "pending") {
1420
+ a.run++;
1421
+ c.flags |= WAITING;
1422
+ inFlight++;
1423
+ const f = a.flight = { c, iter: null };
1424
+ entry.promise.then(() => {
1425
+ const done = store.get(key);
1426
+ land(f, done.status === "ready" ? done.value : done.error, done.status !== "ready", false);
1427
+ });
1428
+ return true;
1429
+ }
1430
+ if (entry.status === "ready") {
1431
+ c.flags &= ~NO_VALUE;
1432
+ c.value = entry.value;
1433
+ } else {
1434
+ c.flags |= ERRORED;
1435
+ a.error = entry.error;
1436
+ a.failure = { node: c, run: a.run };
1437
+ }
1438
+ return true;
1439
+ }
1440
+ function _refresh(read) {
1441
+ const node = typeof read === "function" ? read[NODE] : void 0;
1442
+ if (node === void 0 || (node.flags & COMPUTED) === 0) {
1443
+ throw new TypeError((process.env.NODE_ENV !== "production") ? "[what] refresh(x) needs a computed made by computed() from what-framework, e.g. refresh(users)." : "[what] refresh: not a computed");
1444
+ }
1445
+ if (node.flags & (DISPOSED | RUNNING)) return Promise.resolve(node.value);
1446
+ node.flags |= DIRTY;
1447
+ if (node.subHead !== null) {
1448
+ markPending(node.subHead);
1449
+ if (batchDepth === 0 && !flushing) scheduleFlush();
1450
+ }
1451
+ refreshUntracked(node);
1452
+ const f = node.flags;
1453
+ if ((f & (WAITING | NOT_READY)) === 0 || node.a === void 0) {
1454
+ if (f & ERRORED) return Promise.reject(f & ASYNC ? node.a.error : node.value);
1455
+ return Promise.resolve(node.value);
1456
+ }
1457
+ const a = recordOf(node);
1458
+ return new Promise((resolve, reject) => {
1459
+ (a.waiters || (a.waiters = [])).push([resolve, reject]);
1460
+ });
1461
+ }
1462
+ function _asyncStatus(read) {
1463
+ const node = read[NODE];
1464
+ if (node.flags & (DIRTY | PENDING) && (node.flags & (RUNNING | DISPOSED)) === 0) {
1465
+ try {
1466
+ refreshUntracked(node);
1467
+ } catch (err) {
1468
+ if (err === DEFER) throw err;
1469
+ }
1470
+ }
1471
+ if (activeSub !== null) link(pendOf(node), activeSub);
1472
+ const f = node.flags;
1473
+ if (f & (WAITING | NOT_READY)) return f & NO_VALUE ? "unresolved" : "pending";
1474
+ if (f & ERRORED) return "errored";
1475
+ return f & NO_VALUE ? "unresolved" : "ready";
1476
+ }
1477
+ function _asyncError(read) {
1478
+ const node = read[NODE];
1479
+ return node.flags & ERRORED ? node.flags & ASYNC ? node.a.error : node.value : null;
1480
+ }
1481
+ function _setAsyncValue(read, value) {
1482
+ const node = read[NODE];
1483
+ if (node.flags & DISPOSED) return;
1484
+ makeAsync(node);
1485
+ const a = node.a;
1486
+ if (node.flags & WAITING) {
1487
+ if (a.ac !== null) a.ac.abort();
1488
+ endFlight(a);
1489
+ }
1490
+ settleOutcome(a, value, false);
1491
+ if (a.tx !== null) txOps.drop(node);
1492
+ apply(node, value, false);
1493
+ }
1494
+ function _errorSource(err) {
1495
+ return err === thrownError ? thrownFrom : null;
1496
+ }
1497
+ function _retryErrors(sources) {
1498
+ if (pullOps === null) return;
1499
+ for (const s of sources) {
1500
+ const node = s.node;
1501
+ if ((node.flags & (ERRORED | DISPOSED)) === ERRORED && node.a.run === s.run) {
1502
+ node.flags |= DIRTY;
1503
+ pullOps.refresh(node);
1504
+ }
1505
+ }
1506
+ }
1507
+ function _beginWork() {
1508
+ installAsync();
1509
+ tracked++;
1510
+ let open = true;
1511
+ return () => {
1512
+ if (!open) return;
1513
+ open = false;
1514
+ tracked--;
1515
+ quietSoon();
1516
+ };
1517
+ }
1518
+ function _trackWork(promise) {
1519
+ const done = _beginWork();
1520
+ promise.then(done, done);
1521
+ }
1522
+ function _onQuiet(hook) {
1523
+ installAsync();
1524
+ const hooks = (
1525
+ /** @type {Set<() => void>} */
1526
+ quietHooks
1527
+ );
1528
+ hooks.add(hook);
1529
+ return () => {
1530
+ hooks.delete(hook);
1531
+ };
1532
+ }
1533
+ function _busy() {
1534
+ if (inFlight !== 0 || streams !== 0 || tracked !== 0 || opened.size !== 0) return 2;
1535
+ if (queueLen === 0 && userQueueLen === 0 && !flushScheduled && !flushing) return 0;
1536
+ if (batchDepth === 0 && !flushing) scheduleFlush();
1537
+ return 1;
1538
+ }
1539
+ function _latestComputed(fn) {
1540
+ const node = createComputedNode(fn);
1541
+ node.fn = () => {
1542
+ const prev = latestSub;
1543
+ latestSub = node;
1544
+ try {
1545
+ return fn();
1546
+ } finally {
1547
+ latestSub = prev;
1548
+ }
1549
+ };
1550
+ own(node);
1551
+ const read = computedReader(node);
1552
+ read[NODE] = node;
1553
+ return read;
1554
+ }
1555
+ var opened = /* @__PURE__ */ new Set();
1556
+ var urgent = /* @__PURE__ */ new Set();
1557
+ var actionTxs = /* @__PURE__ */ new Set();
1558
+ var heldIn = null;
1559
+ var devCommitting = 0;
1560
+ function installTx() {
1561
+ if (txOps !== null) return;
1562
+ installAsync();
1563
+ heldIn = /* @__PURE__ */ new WeakMap();
1564
+ onWrite = wrote;
1565
+ txOps = { attribute, land: txLand, drop: txDrop, answered };
1566
+ }
1567
+ function newTx() {
1568
+ const t = {
1569
+ /** @type {Set<any>} */
1570
+ pending: /* @__PURE__ */ new Set(),
1571
+ /** @type {Set<any>} */
1572
+ held: /* @__PURE__ */ new Set(),
1573
+ /** @type {Set<any>} */
1574
+ staged: /* @__PURE__ */ new Set(),
1575
+ /** @type {Set<any>} */
1576
+ writes: /* @__PURE__ */ new Set(),
1577
+ /** @type {Array<() => void>} */
1578
+ onCommit: [],
1579
+ /** @type {any[]} */
1580
+ calls: [],
1581
+ open: 0,
1582
+ actions: 0,
1583
+ /** @type {any} */
1584
+ into: null,
1585
+ done: false,
1586
+ committing: false
1587
+ };
1588
+ opened.add(t);
1589
+ return t;
1590
+ }
1591
+ function txRoot(t) {
1592
+ while (t.into !== null) t = t.into;
1593
+ return t;
1594
+ }
1595
+ function merge(a, b) {
1596
+ a = txRoot(a);
1597
+ b = txRoot(b);
1598
+ if (a === b) return a;
1599
+ for (const c of b.pending) a.pending.add(c);
1600
+ for (const e of b.held) a.held.add(e);
1601
+ for (const c of b.staged) a.staged.add(c);
1602
+ for (const n of b.writes) a.writes.add(n);
1603
+ a.onCommit.push(...b.onCommit);
1604
+ a.calls.push(...b.calls);
1605
+ a.open += b.open;
1606
+ a.actions += b.actions;
1607
+ if (actionTxs.delete(b) && a.actions > 0) actionTxs.add(a);
1608
+ b.into = a;
1609
+ opened.delete(b);
1610
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:merged", b, { into: a });
1611
+ return a;
1612
+ }
1613
+ function wrote(node) {
1614
+ if (currentTx !== null) txRoot(currentTx).writes.add(node);
1615
+ }
1616
+ function attribute(c, a) {
1617
+ let t = a.tx !== null ? txRoot(a.tx) : null;
1618
+ if (t !== null && t.done) t = null;
1619
+ if (currentTx !== null) t = t === null ? txRoot(currentTx) : merge(t, currentTx);
1620
+ for (const w of actionTxs) t = t === null ? w : merge(t, w);
1621
+ if (t !== null) t = txRoot(t);
1622
+ a.tx = t;
1623
+ if (t !== null) {
1624
+ t.pending.add(c);
1625
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:held", t, t);
1626
+ }
1627
+ }
1628
+ function txLand(c, result, isError) {
1629
+ const a = c.a;
1630
+ const t = txRoot(a.tx);
1631
+ a.tx = null;
1632
+ if (t.done) {
1633
+ apply(c, result, isError);
1634
+ return;
1635
+ }
1636
+ if (!isError && (c.flags & (NO_VALUE | STAGED)) === 0) {
1637
+ a.before = c.value;
1638
+ c.flags |= STAGED;
1639
+ t.staged.add(c);
1640
+ }
1641
+ capture(t, () => apply(c, result, isError));
1642
+ t.pending.delete(c);
1643
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:held", t, t);
1644
+ maybeCommit(t);
1645
+ }
1646
+ function txDrop(c) {
1647
+ const a = c.a;
1648
+ const t = txRoot(a.tx);
1649
+ a.tx = null;
1650
+ t.pending.delete(c);
1651
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:held", t, t);
1652
+ maybeCommit(t);
1653
+ }
1654
+ function answered(c) {
1655
+ if ((c.flags & (WAITING | NOT_READY)) === 0) txDrop(c);
1656
+ }
1657
+ function capture(t, fn) {
1658
+ const fromRender = queueLen;
1659
+ const fromUser = userQueueLen;
1660
+ const prev = currentTx;
1661
+ currentTx = t;
1662
+ batchDepth++;
1663
+ try {
1664
+ fn();
1665
+ } finally {
1666
+ batchDepth--;
1667
+ currentTx = prev;
1668
+ t = txRoot(t);
1669
+ queueLen = keep(t, queue, fromRender, queueLen);
1670
+ userQueueLen = keep(t, userQueue, fromUser, userQueueLen);
1671
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:held", t, t);
1672
+ if (batchDepth === 0) urgent.clear();
1673
+ if (batchDepth === 0 && !flushing) scheduleFlush();
1674
+ }
1675
+ }
1676
+ function keep(t, list, from, to) {
1677
+ let n = from;
1678
+ for (let i = from; i < to; i++) {
1679
+ const e = list[i];
1680
+ if (urgent.has(e) || /** @type {WeakSet<any>} */
1681
+ pendingReaders.has(e)) {
1682
+ list[n++] = e;
1683
+ } else if (e.flags & ASYNC) {
1684
+ const node = (
1685
+ /** @type {WeakMap<any, any>} */
1686
+ companionOf.get(e)
1687
+ );
1688
+ const a = node.a;
1689
+ a.tx = a.tx === null || txRoot(a.tx).done ? t : merge(a.tx, t);
1690
+ list[n++] = e;
1691
+ } else {
1692
+ t.held.add(e);
1693
+ heldIn.set(e, t);
1694
+ }
1695
+ }
1696
+ for (let i = n; i < to; i++) list[i] = void 0;
1697
+ return n;
1698
+ }
1699
+ function maybeCommit(t) {
1700
+ if (t.done || t.committing || t.pending.size > 0) return;
1701
+ if (t.open > 0) {
1702
+ if (t.open === t.actions) settleJoined(t);
1703
+ return;
1704
+ }
1705
+ t.committing = true;
1706
+ queueMicrotask(() => {
1707
+ t.committing = false;
1708
+ commit(t);
1709
+ });
1710
+ }
1711
+ function settleJoined(t) {
1712
+ let n = 0;
1713
+ for (const call of t.calls) {
1714
+ if (call.acting || call.failed) t.calls[n++] = call;
1715
+ else call.settle();
1716
+ }
1717
+ t.calls.length = n;
1718
+ }
1719
+ function commit(t) {
1720
+ if (t.done || t.into !== null || t.open > 0 || t.pending.size > 0) return;
1721
+ discover(t);
1722
+ if (t.open > 0 || t.pending.size > 0) return;
1723
+ if (opened.size > 1) {
1724
+ const other = entangled(t);
1725
+ if (other !== null) {
1726
+ maybeCommit(merge(t, other));
1727
+ return;
1728
+ }
1729
+ }
1730
+ t.done = true;
1731
+ opened.delete(t);
1732
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:commit", t, t);
1733
+ if ((process.env.NODE_ENV !== "production")) devCommitting++;
1734
+ try {
1735
+ batch(() => {
1736
+ for (const fn of t.onCommit) fn();
1737
+ for (const c of t.staged) unstage(c);
1738
+ for (const e of t.held) e.flags &= ~QUEUED;
1739
+ for (const e of t.held) {
1740
+ if ((e.flags & (DISPOSED | QUEUED)) === 0 && e.flags & (DIRTY | PENDING)) enqueue(e);
1741
+ }
1742
+ });
1743
+ } finally {
1744
+ if ((process.env.NODE_ENV !== "production")) devCommitting--;
1745
+ }
1746
+ for (const call of t.calls) call.settle();
1747
+ quietSoon();
1748
+ }
1749
+ function discover(t) {
1750
+ capture(t, () => {
1751
+ for (const e of t.held) {
1752
+ if (e.flags & DISPOSED) continue;
1753
+ for (let l = e.depHead; l !== null; l = l.nextDep) {
1754
+ const d = l.dep;
1755
+ if ((d.flags & COMPUTED) !== 0 && (d.flags & (DIRTY | PENDING)) !== 0 && (d.flags & (RUNNING | DISPOSED)) === 0) {
1756
+ try {
1757
+ refresh(d);
1758
+ } catch (err) {
1759
+ if (err !== DEFER) throw err;
1760
+ }
1761
+ }
1762
+ }
1763
+ }
1764
+ });
1765
+ const seen = /* @__PURE__ */ new Set();
1766
+ for (const e of txRoot(t).held) {
1767
+ if (e.flags & DISPOSED) continue;
1768
+ const stack = [e];
1769
+ while (stack.length > 0) {
1770
+ const n = stack.pop();
1771
+ for (let l = n.depHead; l !== null; l = l.nextDep) {
1772
+ const d = l.dep;
1773
+ if ((d.flags & COMPUTED) === 0 || seen.has(d)) continue;
1774
+ seen.add(d);
1775
+ if (d.flags & WAITING) {
1776
+ const a = d.a;
1777
+ const u = a.tx !== null ? txRoot(a.tx) : null;
1778
+ const r = txRoot(t);
1779
+ if (u === null || u.done) {
1780
+ a.tx = r;
1781
+ r.pending.add(d);
1782
+ } else if (u !== r) {
1783
+ merge(r, u);
1784
+ }
1785
+ }
1786
+ stack.push(d);
1787
+ }
1788
+ }
1789
+ }
1790
+ }
1791
+ function entangled(t) {
1792
+ for (const u of opened) {
1793
+ if (u === t) continue;
1794
+ if (u.writes.size > 0 && holdsReader(t, u.writes)) return u;
1795
+ if (t.writes.size > 0 && holdsReader(u, t.writes)) return u;
1796
+ }
1797
+ return null;
1798
+ }
1799
+ function holdsReader(t, nodes) {
1800
+ const seen = /* @__PURE__ */ new Set();
1801
+ for (const e of t.held) {
1802
+ if (e.flags & DISPOSED) continue;
1803
+ const stack = [e];
1804
+ while (stack.length > 0) {
1805
+ const n = stack.pop();
1806
+ for (let l = n.depHead; l !== null; l = l.nextDep) {
1807
+ const d = l.dep;
1808
+ if (nodes.has(d)) return true;
1809
+ if ((d.flags & COMPUTED) !== 0 && !seen.has(d)) {
1810
+ seen.add(d);
1811
+ stack.push(d);
1812
+ }
1813
+ }
1814
+ }
1815
+ }
1816
+ return false;
1817
+ }
1818
+ function unstage(c) {
1819
+ const a = c.a;
1820
+ c.flags &= ~STAGED;
1821
+ a.before = void 0;
1822
+ if (a.viewed) {
1823
+ a.viewed = false;
1824
+ reach(c.subHead);
1825
+ }
1826
+ }
1827
+ function _startTransition(fn, onStart) {
1828
+ installTx();
1829
+ const outer = currentTx;
1830
+ if (outer === null && !flushing && batchDepth === 0 && runningEffect === null && evalDepth === 0) flush();
1831
+ const t = outer !== null ? txRoot(outer) : newTx();
1832
+ if ((process.env.NODE_ENV !== "production") && outer === null && __devtools?.onRecord) devHook("onRecord", "transition:open", t, ownerNow());
1833
+ t.open++;
1834
+ const call = { error: void 0, failed: false, acting: false, gone: false, owner: null, settle: noop, abandon: noop };
1835
+ const done = new Promise((resolve, reject) => {
1836
+ call.settle = () => {
1837
+ if (!call.failed) {
1838
+ resolve(void 0);
1839
+ return;
1840
+ }
1841
+ if (call.owner !== null && _handleError(call.owner, call.error) === HANDLED) done.catch(noop);
1842
+ reject(call.error);
1843
+ };
1844
+ });
1845
+ const link2 = { call };
1846
+ call.abandon = () => {
1847
+ link2.call = null;
1848
+ call.gone = true;
1849
+ if (!call.acting) return;
1850
+ call.acting = false;
1851
+ endAction(t);
1852
+ };
1853
+ t.calls.push(call);
1854
+ if (onStart !== void 0) _urgent(() => onStart(t, call));
1855
+ let result;
1856
+ try {
1857
+ capture(t, () => {
1858
+ result = fn();
1859
+ });
1860
+ } catch (err) {
1861
+ queueMicrotask(() => closeTx(t));
1862
+ throw err;
1863
+ }
1864
+ let thenable;
1865
+ try {
1866
+ thenable = result != null && typeof result.then === "function";
1867
+ } catch (err) {
1868
+ result = Promise.reject(err);
1869
+ thenable = true;
1870
+ }
1871
+ if (thenable) {
1872
+ settleWith(result, link2);
1873
+ if (!call.gone) {
1874
+ const r = txRoot(t);
1875
+ r.open++;
1876
+ r.actions++;
1877
+ actionTxs.add(r);
1878
+ call.acting = true;
1879
+ }
1880
+ }
1881
+ queueMicrotask(() => closeTx(t));
1882
+ return done;
1883
+ }
1884
+ function settleWith(result, link2) {
1885
+ Promise.resolve(result).then(() => {
1886
+ if (link2.call !== null) link2.call.abandon();
1887
+ }, (err) => {
1888
+ const call = link2.call;
1889
+ if (call === null) return;
1890
+ call.failed = true;
1891
+ call.error = err;
1892
+ call.abandon();
1893
+ });
1894
+ }
1895
+ function closeTx(t) {
1896
+ const r = txRoot(t);
1897
+ r.open--;
1898
+ maybeCommit(r);
1899
+ }
1900
+ function endAction(t) {
1901
+ const r = txRoot(t);
1902
+ r.open--;
1903
+ if (--r.actions === 0) actionTxs.delete(r);
1904
+ maybeCommit(r);
1905
+ }
1906
+ function _currentTransition() {
1907
+ return currentTx;
1908
+ }
1909
+ function _onCommit(t, fn) {
1910
+ txRoot(t).onCommit.push(fn);
1911
+ }
1912
+ function _urgent(fn) {
1913
+ const prev = currentTx;
1914
+ const fromRender = queueLen;
1915
+ const fromUser = userQueueLen;
1916
+ currentTx = null;
1917
+ try {
1918
+ return fn();
1919
+ } finally {
1920
+ currentTx = prev;
1921
+ if (prev !== null) {
1922
+ for (let i = fromRender; i < queueLen; i++) urgent.add(queue[i]);
1923
+ for (let i = fromUser; i < userQueueLen; i++) urgent.add(userQueue[i]);
1924
+ }
1925
+ }
1926
+ }
1927
+ function _runHeldReaders(read) {
1928
+ if (heldIn === null) return;
1929
+ const held2 = heldIn;
1930
+ const seen = /* @__PURE__ */ new Set();
1931
+ const stack = [read[NODE]];
1932
+ while (stack.length > 0) {
1933
+ const n = stack.pop();
1934
+ for (let l = n.subHead; l !== null; l = l.nextSub) {
1935
+ const s = l.sub;
1936
+ if (s.flags & EFFECT) {
1937
+ const t = held2.get(s);
1938
+ if (t === void 0) continue;
1939
+ const r = txRoot(t);
1940
+ held2.delete(s);
1941
+ if (r.done || !r.held.delete(s)) continue;
1942
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "transition:held", r, r);
1943
+ s.flags &= ~QUEUED;
1944
+ if ((s.flags & DISPOSED) === 0) enqueue(s);
1945
+ } else if ((s.flags & COMPUTED) !== 0 && !seen.has(s)) {
1946
+ seen.add(s);
1947
+ stack.push(s);
1948
+ }
1949
+ }
1950
+ }
1951
+ if (batchDepth === 0 && !flushing) scheduleFlush();
1952
+ }
1953
+ function _committingTransition() {
1954
+ return (process.env.NODE_ENV !== "production") && devCommitting > 0;
1955
+ }
1956
+ var noopDispose = () => {
1957
+ };
1958
+ function effect(fn, opts) {
1959
+ const parent = runningEffect;
1960
+ const createdUnder = ownerNow();
1961
+ const e = {
1962
+ fn,
1963
+ depHead: null,
1964
+ depTail: null,
1965
+ flags: EFFECT | RUNNING,
1966
+ cleanup: null,
1967
+ owner: createdUnder,
1968
+ parent,
1969
+ owned: null
1970
+ };
1971
+ if (opts != null && opts.phase === "user" || parent !== null && parent.flags & USER) e.flags |= USER;
1972
+ if ((process.env.NODE_ENV !== "production")) {
1973
+ if (nextBinding !== null) {
1974
+ e.devName = nextBinding.name;
1975
+ e.devBinding = nextBinding.binding;
1976
+ clearNextBinding();
1977
+ }
1978
+ if (opts != null) {
1979
+ if (opts.name) e.devName = opts.name;
1980
+ if (opts.binding) e.devBinding = opts.binding;
1981
+ }
1982
+ if (arguments[2]) e.devName = devNamed(e.devName, arguments[2]);
1983
+ devCreated("effects", e);
1984
+ if (__devtools?.trace) devHook("onEffectBegin", e, null, parent);
1985
+ e.devSeen = devSeq;
1986
+ }
1987
+ const prevSub = activeSub;
1988
+ activeSub = e;
1989
+ runningEffect = e;
1990
+ ++cycle;
1991
+ try {
1992
+ const result = fn();
1993
+ if (typeof result === "function") e.cleanup = result;
1994
+ else if ((process.env.NODE_ENV !== "production")) devAsyncEffect(e, result);
1995
+ } catch (err) {
1996
+ if (asyncOps === null || !asyncOps.held(e, err)) {
1997
+ activeSub = prevSub;
1998
+ runningEffect = parent;
1999
+ e.flags &= ~RUNNING;
2000
+ if ((process.env.NODE_ENV !== "production") && __devtools) _devError(err, { type: "effect", effect: e });
2001
+ disposeEffect(e);
2002
+ throw err;
2003
+ }
2004
+ }
2005
+ activeSub = prevSub;
2006
+ runningEffect = parent;
2007
+ e.flags &= ~RUNNING;
2008
+ if (opts != null && opts.stable) e.flags |= STABLE;
2009
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectRun", e);
2010
+ if (e.depHead === null && e.cleanup === null && e.owned === null) {
2011
+ e.flags |= DISPOSED;
2012
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectDispose", e);
2013
+ return noopDispose;
2014
+ }
2015
+ if (createdUnder !== null) {
2016
+ const o = scopeOf(createdUnder);
2017
+ e.owner = o;
2018
+ if (o.flags & DISPOSED) {
2019
+ disposeEffect(e);
2020
+ return noopDispose;
2021
+ }
2022
+ o.disposals.push(e);
2023
+ } else if ((process.env.NODE_ENV !== "production")) {
2024
+ devOrphan(e);
2025
+ }
2026
+ return () => dropEffect(e);
2027
+ }
2028
+ function _effectWhenNeeded(read, bind, a, b, opts) {
2029
+ const owner = ownerNow();
2030
+ let run = null;
2031
+ effect(() => {
2032
+ if (run !== null) return run();
2033
+ const e = (
2034
+ /** @type {WhatEffectNode} */
2035
+ activeSub
2036
+ );
2037
+ const value = read();
2038
+ const l = e.depHead;
2039
+ run = bind(value, l === null ? null : l === e.depTail && /** @type {any} */
2040
+ l.dep.builder !== void 0 ? l.dep : e, read, a, b, owner);
2041
+ if (run === null) unlinkAllDeps(e);
2042
+ }, opts);
2043
+ }
2044
+ function _userEffect(fn) {
2045
+ const now = ownerNow();
2046
+ const o = now === null ? null : scopeOf(now);
2047
+ if (o !== null && o.flags & DISPOSED) return;
2048
+ userOps = USER_OPS;
2049
+ for (let a = o; a != null && (a.flags & OWNS_USER) === 0; a = a.owner) {
2050
+ if ((a.flags & (EFFECT | COMPUTED)) === 0) a.flags |= OWNS_USER;
2051
+ }
2052
+ const e = {
2053
+ fn,
2054
+ depHead: null,
2055
+ depTail: null,
2056
+ flags: EFFECT | USER | DIRTY,
2057
+ cleanup: null,
2058
+ owner: o,
2059
+ parent: runningEffect,
2060
+ owned: null,
2061
+ queued: 0
2062
+ };
2063
+ if ((process.env.NODE_ENV !== "production")) {
2064
+ if (arguments[1]) e.devName = arguments[1];
2065
+ devCreated("effects", e);
2066
+ }
2067
+ if (o !== null) o.disposals.push(e);
2068
+ if (building > 0) held.push(e);
2069
+ else queueUser(e);
2070
+ }
2071
+ function queueUser(e) {
2072
+ if (e.flags & DISPOSED) return;
2073
+ e.queued = ++queuedCount;
2074
+ if (userEffectGate !== null && userEffectGate(e)) return;
2075
+ enqueue(e);
2076
+ if (batchDepth === 0 && !flushing) scheduleFlush();
2077
+ }
2078
+ var building = 0;
2079
+ var held = [];
2080
+ function _holdUser() {
2081
+ building++;
2082
+ return held.length;
2083
+ }
2084
+ function _releaseUser(mark) {
2085
+ building--;
2086
+ if (held.length > mark) userOps.release(mark);
2087
+ }
2088
+ function releaseHeld(mark) {
2089
+ for (let i = mark; i < held.length; i++) queueUser(held[i]);
2090
+ held.length = mark;
2091
+ }
2092
+ var userOps = null;
2093
+ var queuedCount = 0;
2094
+ function orderUserRound(round, len) {
2095
+ let reruns = 0;
2096
+ for (let i = 0; i < len; i++) {
2097
+ const e = round[i];
2098
+ if (!(e.queued > 0)) return;
2099
+ if (e.depHead !== null) reruns++;
2100
+ }
2101
+ if (reruns === 0) return;
2102
+ for (let i = 0; i < len; i++) {
2103
+ const e = round[i];
2104
+ if (e.depHead !== null && e.owner !== null) e.owner.flags |= RERUN_OWNER;
2105
+ }
2106
+ let below = false;
2107
+ let sorted = true;
2108
+ for (let i = 0; i < len && !below; i++) {
2109
+ if (i > 0 && round[i].queued < round[i - 1].queued) sorted = false;
2110
+ for (let a = round[i].owner?.owner; a != null && !below; a = a.owner) below = (a.flags & RERUN_OWNER) !== 0;
2111
+ }
2112
+ for (let i = 0; i < len; i++) {
2113
+ const o = round[i].owner;
2114
+ if (o !== null) o.flags &= ~RERUN_OWNER;
2115
+ }
2116
+ if (below || !sorted) {
2117
+ const order = below ? orderNested(round, len) : round.slice(0, len).sort((p, q) => p.queued - q.queued);
2118
+ for (let i = 0; i < len; i++) round[i] = order[i];
2119
+ }
2120
+ for (let i = 0; i < len; i++) {
2121
+ const e = round[i];
2122
+ let f = e.flags;
2123
+ if ((f & (DIRTY | DISPOSED)) === 0 && f & PENDING && /** @type {any} */
2124
+ pullOps.check(e)) e.flags = f = e.flags | DIRTY;
2125
+ if ((f & (DIRTY | DISPOSED)) !== DIRTY) continue;
2126
+ if (e.owned !== null) disposeRun(e);
2127
+ if (e.cleanup !== null && (e.flags & DISPOSED) === 0) runCleanup(e);
2128
+ }
2129
+ }
2130
+ function orderNested(round, len) {
2131
+ const last = /* @__PURE__ */ new Map();
2132
+ for (let i = 0; i < len; i++) {
2133
+ const e = round[i];
2134
+ if (e.depHead !== null) last.set(e.owner, 0);
2135
+ }
2136
+ const rows = [];
2137
+ for (let i = 0; i < len; i++) {
2138
+ const e = round[i];
2139
+ const at = (
2140
+ /** @type {number} */
2141
+ e.queued
2142
+ );
2143
+ let depth = 0;
2144
+ for (let a = e.owner; a != null; a = a.owner) if (++depth > 1 && /** @type {number} */
2145
+ last.get(a) < at) last.set(a, at);
2146
+ rows.push([e, at, depth]);
2147
+ }
2148
+ const key = ([e, at]) => e.depHead !== null ? Math.max(
2149
+ at,
2150
+ /** @type {number} */
2151
+ last.get(e.owner)
2152
+ ) : at;
2153
+ return rows.sort((p, q) => key(p) - key(q) || q[2] - p[2] || p[1] - q[1]).map((row) => row[0]);
2154
+ }
2155
+ function userCleanups(o) {
2156
+ o.flags &= ~OWNS_USER;
2157
+ for (const d of o.disposals) if (d.flags & USER) disposeEffect(d);
2158
+ for (let c = o.firstChild; c !== null; c = c.nextSibling) {
2159
+ if (c.flags & OWNS_USER) {
2160
+ c.flags |= DISPOSED;
2161
+ userCleanups(c);
2162
+ c.flags &= ~DISPOSED;
2163
+ }
2164
+ }
2165
+ }
2166
+ var USER_OPS = { order: orderUserRound, release: releaseHeld, clean: userCleanups };
2167
+ var userEffectGate = null;
2168
+ function _setUserEffectGate(gate) {
2169
+ userEffectGate = gate;
2170
+ }
2171
+ function _releaseUserEffect(e) {
2172
+ if (e.flags & (DISPOSED | QUEUED)) return;
2173
+ enqueue(e);
2174
+ if (batchDepth === 0 && !flushing) scheduleFlush();
2175
+ }
2176
+ function enqueue(e) {
2177
+ let p = e.parent;
2178
+ if (p !== null && (p.flags & (QUEUED | RUNNING | DISPOSED)) === 0) {
2179
+ const chain = [];
2180
+ do {
2181
+ chain.push(p);
2182
+ p = p.parent;
2183
+ } while (p !== null && (p.flags & (QUEUED | RUNNING | DISPOSED)) === 0);
2184
+ for (let i = chain.length - 1; i >= 0; i--) push(chain[i]);
2185
+ }
2186
+ push(e);
2187
+ }
2188
+ function push(e) {
2189
+ e.flags |= QUEUED;
2190
+ if (e.flags & USER) userQueue[userQueueLen++] = e;
2191
+ else queue[queueLen++] = e;
2192
+ }
2193
+ function runEffect(e) {
2194
+ const f = e.flags;
2195
+ if (f & DISPOSED) return;
2196
+ let dirty = (f & DIRTY) !== 0;
2197
+ if (!dirty && f & PENDING) {
2198
+ dirty = /** @type {any} */
2199
+ pullOps.check(e);
2200
+ if (e.flags & DISPOSED) return;
2201
+ }
2202
+ if (dirty) executeEffect(e);
2203
+ else {
2204
+ if ((process.env.NODE_ENV !== "production") && f & PENDING && __devtools?.trace) devHook("onEffectSkip", e);
2205
+ e.flags &= ~PENDING;
2206
+ }
2207
+ }
2208
+ function executeEffect(e) {
2209
+ const causes = (process.env.NODE_ENV !== "production") && devTracksCauses() ? devCauses(e) : null;
2210
+ const held2 = (process.env.NODE_ENV !== "production") && e.owned !== null ? devStatefulComponents(e.owned) : null;
2211
+ if (e.owned !== null) {
2212
+ disposeRun(e);
2213
+ if (e.flags & DISPOSED) return;
2214
+ }
2215
+ if (e.cleanup !== null) {
2216
+ runCleanup(e);
2217
+ if (e.flags & DISPOSED) return;
2218
+ }
2219
+ const prevSub = activeSub;
2220
+ const prevRunning = runningEffect;
2221
+ runningEffect = e;
2222
+ e.flags = e.flags & ~(DIRTY | PENDING) | RUNNING;
2223
+ if (e.flags & STABLE) {
2224
+ activeSub = null;
2225
+ } else {
2226
+ e.depTail = null;
2227
+ activeSub = e;
2228
+ ++cycle;
2229
+ }
2230
+ if ((process.env.NODE_ENV !== "production")) {
2231
+ e.devSeen = devSeq;
2232
+ e.devNew = false;
2233
+ if (__devtools?.trace) devHook("onEffectBegin", e, causes);
2234
+ if (flushing) devRan[devRanLen++] = e;
2235
+ }
2236
+ try {
2237
+ const result = e.fn();
2238
+ if (typeof result === "function") e.cleanup = result;
2239
+ else if ((process.env.NODE_ENV !== "production")) devAsyncEffect(e, result);
2240
+ } catch (err) {
2241
+ handleEffectError(e, err, false);
2242
+ }
2243
+ activeSub = prevSub;
2244
+ runningEffect = prevRunning;
2245
+ e.flags &= ~RUNNING;
2246
+ if (e.flags & DISPOSED) {
2247
+ unlinkAllDeps(e);
2248
+ if (e.owned !== null) disposeRun(e);
2249
+ if (e.cleanup !== null) runCleanup(e);
2250
+ } else if ((e.flags & STABLE) === 0) {
2251
+ purgeDeps(e);
2252
+ }
2253
+ if ((process.env.NODE_ENV !== "production") && held2 !== null && (e.flags & DISPOSED) === 0 && !e.devNew) devRebuilt(e, held2);
2254
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectRun", e, { causes });
2255
+ }
2256
+ function runCleanup(e) {
2257
+ const fn = (
2258
+ /** @type {() => void} */
2259
+ e.cleanup
2260
+ );
2261
+ e.cleanup = null;
2262
+ const prevSub = activeSub;
2263
+ activeSub = null;
2264
+ try {
2265
+ fn();
2266
+ } catch (err) {
2267
+ handleEffectError(e, err, true);
2268
+ }
2269
+ activeSub = prevSub;
2270
+ }
2271
+ function disposeEffect(e) {
2272
+ if (e.flags & DISPOSED) return;
2273
+ e.flags = e.flags & ~(DIRTY | PENDING) | DISPOSED;
2274
+ e.parent = null;
2275
+ if ((process.env.NODE_ENV !== "production") && __devtools) devHook("onEffectDispose", e);
2276
+ unlinkAllDeps(e);
2277
+ if (e.owned !== null) disposeRun(e);
2278
+ if (e.cleanup !== null) runCleanup(e);
2279
+ }
2280
+ function dropEffect(e) {
2281
+ if (e.flags & DISPOSED) return;
2282
+ if (e.flags & HELD) e.fn.release();
2283
+ disposeEffect(e);
2284
+ const o = e.owner;
2285
+ if (o !== null && (o.flags & DISPOSED) === 0 && ++o.dropped > 16 && o.dropped * 2 > o.disposals.length) {
2286
+ const list = o.disposals;
2287
+ let n = 0;
2288
+ for (let i = 0; i < list.length; i++) {
2289
+ const d = list[i];
2290
+ if (typeof d === "function" || (d.flags & DISPOSED) === 0) list[n++] = d;
2291
+ }
2292
+ list.length = n;
2293
+ o.dropped = 0;
2294
+ }
2295
+ }
2296
+ function handleEffectError(e, err, inCleanup, ofComputed) {
2297
+ if (!inCleanup && asyncOps !== null && asyncOps.held(e, err)) return;
2298
+ if ((process.env.NODE_ENV !== "production") && __devtools) _devError(err, ofComputed ? { type: "cleanup" } : { type: inCleanup ? "effect-cleanup" : "effect", effect: e });
2299
+ const left = _handleError(e.owner, err);
2300
+ if (left === HANDLED) return;
2301
+ try {
2302
+ console.error(`[what] Uncaught error in ${ofComputed ? "cleanup" : inCleanup ? "effect cleanup" : "effect during update"}:`, left);
2303
+ } catch {
2304
+ }
2305
+ }
2306
+ var HANDLED = /* @__PURE__ */ Object.freeze({});
2307
+ function _handleError(owner, err) {
2308
+ for (let o = owner; o != null; o = o.owner) {
2309
+ if ((o.flags & DISPOSED) === 0 && typeof o._onError === "function") {
2310
+ try {
2311
+ o._onError(err);
2312
+ return HANDLED;
2313
+ } catch (next) {
2314
+ err = next;
2315
+ }
2316
+ }
2317
+ }
2318
+ return err;
2319
+ }
2320
+ function scheduleFlush() {
2321
+ if (!flushScheduled && (queueLen > 0 || userQueueLen > 0)) {
2322
+ flushScheduled = true;
2323
+ queueMicrotask(microtaskFlush);
2324
+ }
2325
+ }
2326
+ function microtaskFlush() {
2327
+ flushScheduled = false;
2328
+ flush();
2329
+ }
2330
+ function flush() {
2331
+ flushing = true;
2332
+ const prevOwner = currentOwner;
2333
+ const prevRun = ownerRun;
2334
+ currentOwner = null;
2335
+ ownerRun = null;
2336
+ let rounds = 0;
2337
+ let round = null;
2338
+ let i = 0;
2339
+ let len = 0;
2340
+ try {
2341
+ while (queueLen > 0 || userQueueLen > 0) {
2342
+ if (++rounds > MAX_FLUSH_ROUNDS) {
2343
+ stopLoop();
2344
+ break;
2345
+ }
2346
+ if (queueLen > 0) {
2347
+ round = queue;
2348
+ len = queueLen;
2349
+ queue = [];
2350
+ queueLen = 0;
2351
+ } else {
2352
+ round = userQueue;
2353
+ len = userQueueLen;
2354
+ userQueue = [];
2355
+ userQueueLen = 0;
2356
+ if (userOps !== null) userOps.order(round, len);
2357
+ }
2358
+ for (i = 0; i < len; i++) {
2359
+ const e = round[i];
2360
+ e.flags &= ~QUEUED;
2361
+ runEffect(e);
2362
+ }
2363
+ round = null;
2364
+ }
2365
+ } finally {
2366
+ flushing = false;
2367
+ if ((process.env.NODE_ENV !== "production")) {
2368
+ devRan.fill(null, 0, devRanLen);
2369
+ devWrote.fill(null, 0, devWroteLen);
2370
+ devRanLen = devWroteLen = 0;
2371
+ }
2372
+ currentOwner = prevOwner;
2373
+ ownerRun = prevRun;
2374
+ if (round !== null) {
2375
+ round[i].flags &= ~(DIRTY | PENDING);
2376
+ for (let j = i + 1; j < len; j++) push(round[j]);
2377
+ }
2378
+ if (queueLen > 0 || userQueueLen > 0) scheduleFlush();
2379
+ }
2380
+ }
2381
+ function stopLoop() {
2382
+ if ((process.env.NODE_ENV !== "production")) devReportLoop();
2383
+ else {
2384
+ try {
2385
+ console.warn("[what] Possible infinite effect loop detected");
2386
+ } catch {
2387
+ }
2388
+ }
2389
+ for (let pass = 0; queueLen > 0 || userQueueLen > 0; pass++) {
2390
+ const dropped = queue.slice(0, queueLen).concat(userQueue.slice(0, userQueueLen));
2391
+ queue = [];
2392
+ queueLen = 0;
2393
+ userQueue = [];
2394
+ userQueueLen = 0;
2395
+ for (const e of dropped) {
2396
+ e.flags &= ~QUEUED;
2397
+ if (pass < MAX_FLUSH_ROUNDS && pullOps !== null) pullOps.settle(e);
2398
+ e.flags &= ~(DIRTY | PENDING);
2399
+ }
2400
+ }
2401
+ }
2402
+ function settleInputs(e) {
2403
+ for (let l = e.depHead; l !== null; l = l.nextDep) {
2404
+ const dep = l.dep;
2405
+ if (dep.flags & COMPUTED && dep.flags & (DIRTY | PENDING)) {
2406
+ refresh(dep);
2407
+ if (l.version === -1) return;
2408
+ }
2409
+ }
2410
+ }
2411
+ function batch(fn) {
2412
+ batchDepth++;
2413
+ try {
2414
+ return fn();
2415
+ } finally {
2416
+ if (--batchDepth === 0 && !flushing) {
2417
+ if (runningEffect === null && evalDepth === 0) flush();
2418
+ else scheduleFlush();
2419
+ }
2420
+ }
2421
+ }
2422
+ function flushSync() {
2423
+ if (flushing || runningEffect !== null || evalDepth !== 0) {
2424
+ if ((process.env.NODE_ENV !== "production")) devNestedFlush();
2425
+ return;
2426
+ }
2427
+ flush();
2428
+ }
2429
+ function untrack(fn) {
2430
+ const prev = activeSub;
2431
+ if (prev === null) return fn();
2432
+ const prevOwner = currentOwner;
2433
+ const prevRun = ownerRun;
2434
+ if (prev !== ownerRun) currentOwner = prev;
2435
+ activeSub = null;
2436
+ ownerRun = runningEffect;
2437
+ try {
2438
+ return fn();
2439
+ } finally {
2440
+ activeSub = prev;
2441
+ currentOwner = prevOwner;
2442
+ ownerRun = prevRun;
2443
+ }
2444
+ }
2445
+ function scopeOf(o) {
2446
+ if ((o.flags & (EFFECT | COMPUTED)) === 0) return o;
2447
+ return o.owned !== null ? o.owned : o.owned = createOwner(o, o.flags & DISPOSED);
2448
+ }
2449
+ var ownerFallback = null;
2450
+ var fallbackSet = false;
2451
+ function _setOwnerFallback(fn) {
2452
+ ownerFallback = fn;
2453
+ fallbackSet = true;
2454
+ }
2455
+ var _engine = { root: () => createOwner(null, 0), dispose: (root) => disposeOwner(root) };
2456
+ function runNow() {
2457
+ return activeSub !== null ? activeSub : runningEffect;
2458
+ }
2459
+ function ownerNow() {
2460
+ const run = activeSub !== null ? activeSub : runningEffect;
2461
+ if (run !== null && run !== ownerRun) return run;
2462
+ if (currentOwner !== null) return currentOwner;
2463
+ if (!fallbackSet) globalThis[_serverStoreKey]?.adopt?.(_setOwnerFallback, _engine);
2464
+ return ownerFallback === null ? null : ownerFallback();
2465
+ }
2466
+ var _serverStoreKey = /* @__PURE__ */ Symbol.for("what.serverContext.v1");
2467
+ function _detached(fn) {
2468
+ const prevOwner = currentOwner;
2469
+ const prevRun = ownerRun;
2470
+ const prevFallback = ownerFallback;
2471
+ currentOwner = null;
2472
+ ownerRun = runNow();
2473
+ ownerFallback = null;
2474
+ try {
2475
+ return fn();
2476
+ } finally {
2477
+ currentOwner = prevOwner;
2478
+ ownerRun = prevRun;
2479
+ ownerFallback = prevFallback;
2480
+ }
2481
+ }
2482
+ function disposeRun(node) {
2483
+ const o = node.owned;
2484
+ node.owned = null;
2485
+ disposeOwner(o, node);
2486
+ }
2487
+ function cleanupFailed(node, err) {
2488
+ handleEffectError(node, err, true, (node.flags & EFFECT) === 0);
2489
+ }
2490
+ function _handlePending(owner, waiting) {
2491
+ for (let o = owner; o != null; o = o.owner) {
2492
+ if ((o.flags & DISPOSED) === 0 && typeof o._onPending === "function") {
2493
+ o._onPending(waiting);
2494
+ return true;
2495
+ }
2496
+ }
2497
+ return false;
2498
+ }
2499
+ function getOwner() {
2500
+ const now = ownerNow();
2501
+ return now === null ? null : scopeOf(now);
2502
+ }
2503
+ function _ownerRecord(o) {
2504
+ return o === null ? null : scopeOf(o);
2505
+ }
2506
+ function runWithOwner(owner, fn) {
2507
+ const prev = currentOwner;
2508
+ const prevRun = ownerRun;
2509
+ currentOwner = owner;
2510
+ ownerRun = runNow();
2511
+ try {
2512
+ return fn();
2513
+ } finally {
2514
+ currentOwner = prev;
2515
+ ownerRun = prevRun;
2516
+ }
2517
+ }
2518
+ function createOwner(parent, flags) {
2519
+ const owner = {
2520
+ flags,
2521
+ owner: parent,
2522
+ disposals: [],
2523
+ firstChild: null,
2524
+ lastChild: null,
2525
+ prevSibling: null,
2526
+ nextSibling: null,
2527
+ dropped: 0
2528
+ };
2529
+ return owner;
2530
+ }
2531
+ function linkChild(parent, child) {
2532
+ const last = parent.lastChild;
2533
+ child.prevSibling = last;
2534
+ if (last !== null) last.nextSibling = child;
2535
+ else parent.firstChild = child;
2536
+ parent.lastChild = child;
2537
+ }
2538
+ function createRoot(fn) {
2539
+ const now = ownerNow();
2540
+ const parent = now === null ? null : scopeOf(now);
2541
+ const root = createOwner(parent, 0);
2542
+ if (parent !== null && (parent.flags & DISPOSED) === 0) linkChild(parent, root);
2543
+ return runOwned(root, parent, fn);
2544
+ }
2545
+ function _createItemScope(fn, cell) {
2546
+ const scope = _itemScope(cell, [], 0);
2547
+ return runOwned(scope, scope.owner, fn);
2548
+ }
2549
+ function _itemScope(cell, disposeArr, slot) {
2550
+ const parent = ownerNow();
2551
+ const scope = (process.env.NODE_ENV !== "production") ? devRow(createOwner(parent, 0)) : createOwner(parent, 0);
2552
+ if (cell !== void 0) cell.building = scope;
2553
+ disposeArr[slot] = () => disposeOwner(scope);
2554
+ return scope;
2555
+ }
2556
+ function _runScope(scope, build, a, b, c, finish) {
2557
+ const parent = scope.owner;
2558
+ const prev = currentOwner;
2559
+ const prevRun = ownerRun;
2560
+ currentOwner = scope;
2561
+ ownerRun = runNow();
2562
+ let result;
2563
+ try {
2564
+ result = finish(build(a, b, c));
2565
+ } catch (err) {
2566
+ currentOwner = prev;
2567
+ ownerRun = prevRun;
2568
+ try {
2569
+ disposeOwner(scope);
2570
+ } catch {
2571
+ }
2572
+ throw err;
2573
+ }
2574
+ currentOwner = prev;
2575
+ ownerRun = prevRun;
2576
+ if (parent !== null && parent.flags & DISPOSED) disposeOwner(scope);
2577
+ return result;
2578
+ }
2579
+ function devRow(row) {
2580
+ row.devScope = "row";
2581
+ return row;
2582
+ }
2583
+ function runOwned(scope, parent, fn) {
2584
+ const prev = currentOwner;
2585
+ const prevRun = ownerRun;
2586
+ currentOwner = scope;
2587
+ ownerRun = runNow();
2588
+ let result;
2589
+ try {
2590
+ result = fn(() => disposeOwner(scope));
2591
+ } catch (err) {
2592
+ currentOwner = prev;
2593
+ ownerRun = prevRun;
2594
+ try {
2595
+ disposeOwner(scope);
2596
+ } catch {
2597
+ }
2598
+ throw err;
2599
+ }
2600
+ currentOwner = prev;
2601
+ ownerRun = prevRun;
2602
+ if (parent !== null && parent.flags & DISPOSED) disposeOwner(scope);
2603
+ return result;
2604
+ }
2605
+ function _componentOwner(Component, props) {
2606
+ const now = ownerNow();
2607
+ const parent = now === null ? null : scopeOf(now);
2608
+ const owner = {
2609
+ flags: parent !== null ? parent.flags & DISPOSED : 0,
2610
+ owner: parent,
2611
+ disposals: [],
2612
+ firstChild: null,
2613
+ lastChild: null,
2614
+ prevSibling: null,
2615
+ nextSibling: null,
2616
+ dropped: 0,
2617
+ Component,
2618
+ props,
2619
+ hooks: null,
2620
+ hookIndex: 0,
2621
+ context: null
2622
+ };
2623
+ if (parent !== null && (parent.flags & DISPOSED) === 0) linkChild(parent, owner);
2624
+ return owner;
2625
+ }
2626
+ function _serverComponentOwner(Component, under) {
2627
+ const now = under != null ? under : ownerNow();
2628
+ const parent = now === null ? null : scopeOf(now);
2629
+ const owner = {
2630
+ flags: parent !== null ? parent.flags & DISPOSED : 0,
2631
+ owner: parent,
2632
+ disposals: [],
2633
+ firstChild: null,
2634
+ lastChild: null,
2635
+ prevSibling: null,
2636
+ nextSibling: null,
2637
+ dropped: 0,
2638
+ Component,
2639
+ props: void 0,
2640
+ hooks: null,
2641
+ hookIndex: 0,
2642
+ context: null,
2643
+ _parentCtx: null,
2644
+ _outerOwner: null,
2645
+ _outerRun: null,
2646
+ _ownerPath: void 0,
2647
+ _ownerChildren: void 0,
2648
+ _row: void 0,
2649
+ _places: void 0
2650
+ };
2651
+ if (parent !== null && (parent.flags & DISPOSED) === 0) linkChild(parent, owner);
2652
+ return (
2653
+ /** @type {any} */
2654
+ owner
2655
+ );
2656
+ }
2657
+ function _enterFrame(frame) {
2658
+ frame._outerOwner = currentOwner;
2659
+ frame._outerRun = ownerRun;
2660
+ currentOwner = frame;
2661
+ ownerRun = runNow();
2662
+ }
2663
+ function _exitFrame(frame) {
2664
+ currentOwner = frame._outerOwner;
2665
+ ownerRun = frame._outerRun;
2666
+ frame._outerOwner = null;
2667
+ frame._outerRun = null;
2668
+ }
2669
+ function _runOwned(owner, fn, a, b, c) {
2670
+ const prevOwner = currentOwner;
2671
+ const prevRun = ownerRun;
2672
+ const prevSub = activeSub;
2673
+ activeSub = null;
2674
+ currentOwner = owner;
2675
+ ownerRun = runningEffect;
2676
+ try {
2677
+ return fn(a, b, c);
2678
+ } finally {
2679
+ currentOwner = prevOwner;
2680
+ ownerRun = prevRun;
2681
+ activeSub = prevSub;
2682
+ }
2683
+ }
2684
+ function _adoptOwner(o) {
2685
+ const now = ownerNow();
2686
+ if (now === null || o.owner !== null || o.flags & DISPOSED) return;
2687
+ const parent = scopeOf(now);
2688
+ o.owner = parent;
2689
+ if (parent.flags & DISPOSED) disposeOwner(o);
2690
+ else linkChild(parent, o);
2691
+ }
2692
+ function _disposeOwner(owner) {
2693
+ disposeOwner(owner);
2694
+ }
2695
+ function _enterOwner(owner) {
2696
+ const saved = { owner: currentOwner, run: ownerRun };
2697
+ currentOwner = owner;
2698
+ ownerRun = runNow();
2699
+ return saved;
2700
+ }
2701
+ function _exitOwner(saved) {
2702
+ currentOwner = saved.owner;
2703
+ ownerRun = saved.run;
2704
+ }
2705
+ function _tracking() {
2706
+ return activeSub !== null && activeSub.depHead !== null;
2707
+ }
2708
+ function _isDisposed(owner) {
2709
+ return (owner.flags & DISPOSED) !== 0;
2710
+ }
2711
+ function _contextOf(key) {
2712
+ for (let o = ownerNow(); o != null; o = o.owner) {
2713
+ const map = o.context;
2714
+ if (map != null && map.has(key)) return map;
2715
+ }
2716
+ return null;
2717
+ }
2718
+ function _provide(key, value) {
2719
+ const o = ownerNow();
2720
+ if (o !== null) (o.context ??= /* @__PURE__ */ new Map()).set(key, value);
2721
+ }
2722
+ function _currentComponent() {
2723
+ for (let o = ownerNow(); o != null; o = o.owner) {
2724
+ if (o.Component !== void 0) return o;
2725
+ }
2726
+ return null;
2727
+ }
2728
+ function _symbolChild(value, path) {
2729
+ if (!(process.env.NODE_ENV !== "production")) return;
2730
+ const owner = _currentComponent();
2731
+ const component = owner ? owner.Component.displayName || owner.Component.name || "Anonymous" : "root";
2732
+ const symbol = String(value);
2733
+ report("ERR_SYMBOL_CHILD", { data: { symbol, component, path }, subject: { kind: "component", name: component, id: `${path}|${component}|${symbol}` } });
2734
+ }
2735
+ function onCleanup(fn) {
2736
+ const now = ownerNow();
2737
+ if (now === null) return;
2738
+ const o = scopeOf(now);
2739
+ if (o.flags & DISPOSED) untrack(fn);
2740
+ else o.disposals.push(fn);
2741
+ }
2742
+ function unlinkChild(parent, child) {
2743
+ const prev = child.prevSibling;
2744
+ const next = child.nextSibling;
2745
+ if (prev !== null) prev.nextSibling = next;
2746
+ else parent.firstChild = next;
2747
+ if (next !== null) next.prevSibling = prev;
2748
+ else parent.lastChild = prev;
2749
+ child.prevSibling = null;
2750
+ child.nextSibling = null;
2751
+ }
2752
+ function disposeOwner(root, runNode) {
2753
+ if (root.flags & DISPOSED) return;
2754
+ root.flags |= DISPOSED;
2755
+ if (root.flags & OWNS_USER) userOps.clean(root);
2756
+ let failed2 = false;
2757
+ let firstError;
2758
+ const prevSub = activeSub;
2759
+ activeSub = null;
2760
+ for (let child = root.lastChild; child !== null; child = root.lastChild) {
2761
+ unlinkChild(root, child);
2762
+ if (child.firstChild === null && child.disposals.length === 0 && (child.flags & OWNS_USER) === 0) {
2763
+ child.flags |= DISPOSED;
2764
+ continue;
2765
+ }
2766
+ try {
2767
+ disposeOwner(child, runNode);
2768
+ } catch (err) {
2769
+ if (!failed2) {
2770
+ failed2 = true;
2771
+ firstError = err;
2772
+ }
2773
+ }
2774
+ }
2775
+ const disposals = root.disposals;
2776
+ for (let i = disposals.length - 1; i >= 0; i--) {
2777
+ const d = disposals[i];
2778
+ try {
2779
+ if (typeof d === "function") d();
2780
+ else if (d.flags & EFFECT) disposeEffect(d);
2781
+ else pullOps.dispose(d);
2782
+ } catch (err) {
2783
+ if (runNode !== void 0) {
2784
+ cleanupFailed(runNode, err);
2785
+ } else {
2786
+ if ((process.env.NODE_ENV !== "production") && __devtools) _devError(err, { type: "cleanup" });
2787
+ if (!failed2) {
2788
+ failed2 = true;
2789
+ firstError = err;
2790
+ }
2791
+ }
2792
+ }
2793
+ }
2794
+ disposals.length = 0;
2795
+ activeSub = prevSub;
2796
+ const parent = root.owner;
2797
+ if (root.prevSibling !== null || parent !== null && parent.firstChild === root) unlinkChild(parent, root);
2798
+ if (failed2) throw firstError;
2799
+ }
2800
+ var PREINSTALL_CAP = 2e3;
2801
+ var preinstall = (process.env.NODE_ENV !== "production") && typeof WeakRef !== "undefined" ? { signals: /* @__PURE__ */ new Set(), effects: /* @__PURE__ */ new Set(), components: /* @__PURE__ */ new Set(), dropped: { signals: 0, effects: 0, components: 0 } } : null;
2802
+ function devWatched(kind) {
2803
+ return __devtools !== null || preinstall !== null && preinstall[kind].size < PREINSTALL_CAP;
2804
+ }
2805
+ function devCreated(kind, x) {
2806
+ if (__devtools !== null) devHook(kind === "signals" ? "onSignalCreate" : "onEffectCreate", x);
2807
+ else if (preinstall !== null) {
2808
+ if (preinstall[kind].size < PREINSTALL_CAP) preinstall[kind].add(new WeakRef(x));
2809
+ else preinstall.dropped[kind]++;
2810
+ }
2811
+ }
2812
+ function _devMounted(owner) {
2813
+ if (!(process.env.NODE_ENV !== "production")) return;
2814
+ if (__devtools !== null) devHook("onComponentMount", owner);
2815
+ else if (preinstall !== null) {
2816
+ if (preinstall.components.size < PREINSTALL_CAP) preinstall.components.add(owner);
2817
+ else preinstall.dropped.components++;
2818
+ }
2819
+ owner.disposals.push(() => {
2820
+ if (__devtools !== null) devHook("onComponentUnmount", owner);
2821
+ preinstall?.components.delete(owner);
2822
+ });
2823
+ }
2824
+ function devHook(name, a, b, c) {
2825
+ const hooks = __devtools;
2826
+ const fn = hooks !== null ? hooks[name] : void 0;
2827
+ if (typeof fn !== "function") return;
2828
+ try {
2829
+ fn.call(hooks, a, b, c);
2830
+ } catch (err) {
2831
+ try {
2832
+ console.error(`[what] devtools hook ${name} threw:`, err);
2833
+ } catch {
2834
+ }
2835
+ }
2836
+ }
2837
+ var devReported = /* @__PURE__ */ new WeakSet();
2838
+ function _devError(err, context) {
2839
+ if (!(process.env.NODE_ENV !== "production")) return;
2840
+ if (err !== null && (typeof err === "object" || typeof err === "function")) {
2841
+ if (devReported.has(err)) return;
2842
+ devReported.add(err);
2843
+ }
2844
+ devHook("onError", err, context);
2845
+ }
2846
+ function devSignal(sig, node, debugName) {
2847
+ node.sig = sig;
2848
+ const where = ownerNow();
2849
+ devMarkState(where);
2850
+ if (where !== null && typeof WeakRef !== "undefined") node.devOwnerRef = new WeakRef(where);
2851
+ if (debugName) sig._debugName = debugName;
2852
+ if (devSplit(debugName)[1] === null) sig._devLoc = devSplit(_devCallSite("", signal, "signals"))[1];
2853
+ devCreated("signals", sig);
2854
+ }
2855
+ function devComputed(read, node) {
2856
+ read[NODE] = node;
2857
+ node.sig = read;
2858
+ if (node.owner === null) node.devOwner = ownerNow();
2859
+ devCreated("effects", node);
2860
+ }
2861
+ function devName(node) {
2862
+ return devLabel(node) || String(devFn(node)).slice(0, 60);
2863
+ }
2864
+ function devAsyncState(c, status, run, error) {
2865
+ c.devAsync = status;
2866
+ if (run !== void 0) {
2867
+ c.devFlight = { run, startedAt: Date.now() };
2868
+ } else {
2869
+ c.devFlight = null;
2870
+ }
2871
+ if (status === "errored") {
2872
+ try {
2873
+ c.devLastError = String(error?.message ?? error).slice(0, 300);
2874
+ } catch {
2875
+ c.devLastError = "Error could not be displayed";
2876
+ }
2877
+ }
2878
+ if (__devtools?.onRecord) devHook("onRecord", `async:${run !== void 0 ? "start" : status}`, c);
2879
+ }
2880
+ function devLabel(node) {
2881
+ const meta = node.devName ? devSplit(node.devName)[0] : "";
2882
+ const name = devFn(node).name;
2883
+ return meta && !(meta === (node.flags & EFFECT ? "effect" : "computed") && name) ? meta : name;
2884
+ }
2885
+ function devFn(node) {
2886
+ const fn = node.fn;
2887
+ return fn.inner !== void 0 ? fn.inner : fn;
2888
+ }
2889
+ function _devAction(data) {
2890
+ if ((process.env.NODE_ENV !== "production") && __devtools?.onRecord) devHook("onRecord", "action", null, data);
2891
+ }
2892
+ function _devCallSite(name, primitive, kind = "effects") {
2893
+ if (!(process.env.NODE_ENV !== "production") || !devWatched(kind) || devSplit(name)[1] !== null) return name;
2894
+ const loc = _devStackLoc(primitive);
2895
+ return loc === null ? name : `${name || ""}@${loc}`;
2896
+ }
2897
+ function _devStackLoc(primitive) {
2898
+ if (!(process.env.NODE_ENV !== "production") || typeof window === "undefined") return null;
2899
+ const error = new Error();
2900
+ const capture2 = (
2901
+ /** @type {{ captureStackTrace?: (error: Error, skip: Function) => void }} */
2902
+ Error.captureStackTrace
2903
+ );
2904
+ if (capture2) capture2(error, primitive);
2905
+ let stack;
2906
+ try {
2907
+ stack = error.stack;
2908
+ } catch {
2909
+ return null;
2910
+ }
2911
+ if (typeof stack !== "string") return null;
2912
+ const frames = stack.split("\n");
2913
+ const caller = capture2 ? frames[1] : frames[frames.findIndex((line) => line.startsWith(primitive.name + "@")) + 1];
2914
+ const loc = caller?.trim().match(/(?:^at (?:.*? \()?|@)((?:https?:|file:|\/).+?:\d+:\d+)\)?$/)?.[1];
2915
+ if (!loc || /\/(?:node_modules|packages\/(?:core|router|server)\/src)\//.test(loc)) return null;
2916
+ const [, file, pos] = (
2917
+ /** @type {RegExpMatchArray} */
2918
+ loc.match(/^(.*?)(:\d+:\d+)$/)
2919
+ );
2920
+ const page = file.match(/^https?:\/\/[^/]+\/([^?#]*)/);
2921
+ if (page === null) return loc;
2922
+ return (page[1].startsWith("@fs/") ? page[1].slice(3) : page[1]) + pos;
2923
+ }
2924
+ function devNamed(name, meta) {
2925
+ if (!meta || !name || devSplit(name)[1] !== null) return name || meta;
2926
+ return `${name}@${devSplit(meta)[1]}`;
2927
+ }
2928
+ function devSplit(meta) {
2929
+ if (typeof meta !== "string") return ["", null];
2930
+ const at = /@(?=[^\n]+:\d+:\d+$)/.exec(meta)?.index ?? -1;
2931
+ return at === -1 ? [meta, null] : [meta.slice(0, at), meta.slice(at + 1)];
2932
+ }
2933
+ if ((process.env.NODE_ENV !== "production")) {
2934
+ const readGuard = (kind) => ({
2935
+ configurable: true,
2936
+ writable: true,
2937
+ /** @this {any} */
2938
+ value: function toString() {
2939
+ const text = Function.prototype.toString.call(this);
2940
+ const node = this[NODE];
2941
+ const rawName = this._debugName;
2942
+ const name = rawName ? devSplit(rawName)[0] : kind === "computed" && node ? devName(node) : "(unnamed)";
2943
+ report("ERR_MISSING_SIGNAL_READ", {
2944
+ data: { signalName: name, createdAt: __ownerPath(this).loc },
2945
+ subject: { kind, id: (kind === "computed" ? node : this)?._devId, name },
2946
+ loc: _devStackLoc(toString)
2947
+ });
2948
+ return text;
2949
+ }
2950
+ });
2951
+ Object.defineProperty(signalPrototype(), "toString", readGuard("signal"));
2952
+ Object.defineProperty(computedPrototype(), "toString", readGuard("computed"));
2953
+ Object.defineProperty(asyncPrototype(), "toString", readGuard("computed"));
2954
+ }
2955
+ function devWriteInComputed(sig, c) {
2956
+ const computedName = devName(c);
2957
+ report("ERR_SIGNAL_WRITE_IN_COMPUTED", {
2958
+ data: { computedName, signalName: sig._debugName ? devSplit(sig._debugName)[0] : "(unnamed)" },
2959
+ subject: { kind: "computed", id: c._devId, name: computedName }
2960
+ });
2961
+ }
2962
+ function devReportLoop() {
2963
+ const stuck = queueLen > 0 ? queue.slice(0, queueLen) : userQueue.slice(0, userQueueLen);
2964
+ const writers = stuck.filter((e) => devWrote.includes(e));
2965
+ for (const e of writers.length > 0 ? writers : stuck) {
2966
+ const effectName = devName(e);
2967
+ const where = __ownerPath(e);
2968
+ report("ERR_INFINITE_EFFECT", {
2969
+ data: { effectName, rounds: devRunsOf(e) },
2970
+ subject: { kind: "effect", id: e._devId, name: effectName },
2971
+ owner: where,
2972
+ loc: where.loc
2973
+ });
2974
+ }
2975
+ }
2976
+ function devRunsOf(e) {
2977
+ let runs = 0;
2978
+ for (let i = 0; i < devRanLen; i++) if (devRan[i] === e) runs++;
2979
+ return runs;
2980
+ }
2981
+ function devUntrackedPending(call) {
2982
+ const now = ownerNow();
2983
+ if (now !== null && now.Component !== void 0 && now._inBody !== false) report("ERR_PENDING_READ_UNTRACKED", { data: { call } });
2984
+ }
2985
+ function devAsyncEffect(e, result) {
2986
+ if (result == null || typeof result.then !== "function") return;
2987
+ const effectName = devName(e);
2988
+ report("ERR_ASYNC_EFFECT", {
2989
+ data: { effectName },
2990
+ subject: { kind: "effect", id: e._devId, name: effectName }
2991
+ });
2992
+ }
2993
+ function devWriteAfterAwait(sig, node) {
2994
+ if (currentTx !== null) {
2995
+ txRoot(currentTx).writes.add(node);
2996
+ return;
2997
+ }
2998
+ if (actionTxs.size === 0 || runningEffect !== null) return;
2999
+ const view = typeof window !== "undefined" ? (
3000
+ /** @type {any} */
3001
+ window
3002
+ ) : null;
3003
+ if (view !== null && view.event !== void 0) return;
3004
+ for (const t of actionTxs) {
3005
+ if (t.writes.has(node)) {
3006
+ report("ERR_WRITE_AFTER_AWAIT", { data: { signalName: sig._debugName || "(unnamed)" } });
3007
+ return;
3008
+ }
3009
+ }
3010
+ }
3011
+ function devNestedFlush() {
3012
+ const context = activeSub !== null && activeSub.flags & COMPUTED ? `computed "${devName(activeSub)}"` : evalDepth !== 0 ? "a computed" : runningEffect !== null ? `effect "${devName(runningEffect)}"` : "an effect flush";
3013
+ report("ERR_NESTED_FLUSH_SYNC", { data: { context } });
3014
+ }
3015
+ function devHandle(node) {
3016
+ return node.flags & (COMPUTED | EFFECT | KEYED) ? node : node.sig;
3017
+ }
3018
+ function devTracksCauses() {
3019
+ return __devtools !== null && __devtools.trace !== false;
3020
+ }
3021
+ function devCauses(sub) {
3022
+ const out = [];
3023
+ const seen = sub.devSeen;
3024
+ if (seen === void 0) return out;
3025
+ for (let l = sub.depHead; l !== null; l = l.nextDep) {
3026
+ if ((l.dep.devSeq ?? 0) > seen) out.push(devHandle(l.dep));
3027
+ }
3028
+ return out;
3029
+ }
3030
+ function devNodeOf(x) {
3031
+ return typeof x === "function" ? x[NODE] : x;
3032
+ }
3033
+ function __depsOf(x) {
3034
+ const out = [];
3035
+ if (!(process.env.NODE_ENV !== "production")) return out;
3036
+ const node = devNodeOf(x);
3037
+ if (node == null || !(node.flags & (COMPUTED | EFFECT))) return out;
3038
+ for (let l = node.depHead; l !== null; l = l.nextDep) {
3039
+ const h = devHandle(l.dep);
3040
+ if (!out.includes(h)) out.push(h);
3041
+ }
3042
+ return out;
3043
+ }
3044
+ function __subsOf(x) {
3045
+ const out = [];
3046
+ if (!(process.env.NODE_ENV !== "production")) return out;
3047
+ const node = devNodeOf(x);
3048
+ if (node == null || node.subHead === void 0) return out;
3049
+ for (let l = node.subHead; l !== null; l = l.nextSub) {
3050
+ if (!out.includes(l.sub)) out.push(l.sub);
3051
+ }
3052
+ return out;
3053
+ }
3054
+ function __currentEffect() {
3055
+ return (process.env.NODE_ENV !== "production") ? runningEffect : null;
3056
+ }
3057
+ function __ownerOf(x) {
3058
+ if (!(process.env.NODE_ENV !== "production") || x == null) return null;
3059
+ if (typeof x === "object" && typeof x.nodeType === "number") return devDomOwner(x);
3060
+ const node = devNodeOf(x);
3061
+ return node?.owner ?? node?.devOwner ?? node?.devOwnerRef?.deref() ?? null;
3062
+ }
3063
+ function __ownerPath(x) {
3064
+ const path = (
3065
+ /** @type {string[] & { loc: string | null }} */
3066
+ Object.assign([], { loc: null })
3067
+ );
3068
+ if (!(process.env.NODE_ENV !== "production") || x == null) return path;
3069
+ let o = typeof x === "object" && typeof x.nodeType === "number" ? devDomOwner(x) : devNodeOf(x);
3070
+ for (; o != null; o = o.owner ?? o.devOwner ?? o.devOwnerRef?.deref()) {
3071
+ let meta = null;
3072
+ if (o.Component !== void 0) {
3073
+ meta = o.devLoc ? devSplit(o.devLoc) : null;
3074
+ path.push(`<${meta && meta[0] || o.Component.displayName || o.Component.name || "Anonymous"}>`);
3075
+ } else if (o.flags & (EFFECT | COMPUTED)) {
3076
+ meta = o.devName ? devSplit(o.devName) : null;
3077
+ const kind = o.devBinding ? "binding" : o.flags & EFFECT ? "effect" : "computed";
3078
+ const name = devLabel(o);
3079
+ if (name) path.push(name !== kind ? `${kind} "${name}"` : kind);
3080
+ } else if (o.sig?._debugName) {
3081
+ meta = devSplit(o.sig._debugName);
3082
+ } else if (o.devScope) {
3083
+ path.push(o.devScope);
3084
+ }
3085
+ if (path.loc === null && meta && meta[1]) path.loc = meta[1];
3086
+ }
3087
+ path.reverse();
3088
+ return path;
3089
+ }
3090
+ var devAnchors = /* @__PURE__ */ new WeakMap();
3091
+ function _devAnchor(node, owner, inner) {
3092
+ if (!(process.env.NODE_ENV !== "production") || !node) return;
3093
+ if (inner) {
3094
+ const held2 = devAnchors.get(node);
3095
+ if (held2 !== void 0 && (held2.flags & DISPOSED) === 0) return;
3096
+ }
3097
+ devAnchors.set(node, owner);
3098
+ }
3099
+ function devDomOwner(node) {
3100
+ let skip = 0;
3101
+ let enclosing = true;
3102
+ for (let n = node; n != null; ) {
3103
+ const owner = devAnchors.get(n);
3104
+ if (n.nodeType === 8) {
3105
+ if (n.data === "c:end" && n !== node) skip++;
3106
+ else if (owner !== void 0) {
3107
+ if (skip > 0) skip--;
3108
+ else if ((owner.flags & DISPOSED) === 0) return owner;
3109
+ }
3110
+ } else if (owner !== void 0 && enclosing && (owner.flags & DISPOSED) === 0) {
3111
+ return owner;
3112
+ }
3113
+ if (n.previousSibling != null) {
3114
+ n = n.previousSibling;
3115
+ enclosing = false;
3116
+ } else {
3117
+ n = n.parentNode;
3118
+ enclosing = true;
3119
+ skip = 0;
3120
+ }
3121
+ }
3122
+ return null;
3123
+ }
3124
+ var devAsyncOwners = null;
3125
+ function _devAsyncWork(owner, promise) {
3126
+ if (!(process.env.NODE_ENV !== "production") || owner == null) return;
3127
+ if (devAsyncOwners === null) devAsyncOwners = /* @__PURE__ */ new Map();
3128
+ const pending = devAsyncOwners;
3129
+ pending.set(owner, (pending.get(owner) || 0) + 1);
3130
+ const done = () => {
3131
+ const n = (pending.get(owner) || 1) - 1;
3132
+ if (n === 0) pending.delete(owner);
3133
+ else pending.set(owner, n);
3134
+ };
3135
+ promise.then(done, (err) => {
3136
+ done();
3137
+ throw err;
3138
+ });
3139
+ }
3140
+ function devMarkState(where) {
3141
+ for (let o = where; o != null; o = o.owner) {
3142
+ if (o.Component !== void 0) {
3143
+ o.devState = true;
3144
+ return;
3145
+ }
3146
+ }
3147
+ }
3148
+ function _devHoldsState() {
3149
+ if ((process.env.NODE_ENV !== "production")) devMarkState(ownerNow());
3150
+ }
3151
+ var _devHot = (
3152
+ /** @type {any} */
3153
+ (process.env.NODE_ENV !== "production") ? { move: devMoveOwner, adopt: devAdoptState } : null
3154
+ );
3155
+ function devMoveOwner(o, to) {
3156
+ const from = o.owner;
3157
+ if (from !== null && (o.prevSibling !== null || from.firstChild === o)) unlinkChild(from, o);
3158
+ o.owner = to;
3159
+ if (to.flags & DISPOSED) disposeOwner(o);
3160
+ else linkChild(to, o);
3161
+ }
3162
+ function devAdoptState(sig) {
3163
+ const node = devNodeOf(sig);
3164
+ const where = ownerNow();
3165
+ if (node == null || where === null) return;
3166
+ devMarkState(where);
3167
+ if (typeof WeakRef !== "undefined") node.devOwnerRef = new WeakRef(where);
3168
+ }
3169
+ function _devNewContent() {
3170
+ if ((process.env.NODE_ENV !== "production") && runningEffect !== null) runningEffect.devNew = true;
3171
+ }
3172
+ function _devDropped(sig) {
3173
+ if ((process.env.NODE_ENV !== "production") && __devtools !== null) devHook("onSignalDrop", sig);
3174
+ }
3175
+ function devHeldState(o) {
3176
+ if (o.devState === true) return true;
3177
+ for (let c = o.firstChild; c !== null; c = c.nextSibling) if (devHeldState(c)) return true;
3178
+ return false;
3179
+ }
3180
+ function devStatefulComponents(record) {
3181
+ let list = null;
3182
+ for (let o = record.firstChild; o !== null; o = o.nextSibling) {
3183
+ if (o.Component !== void 0 && devHeldState(o)) (list ??= []).push(o.Component);
3184
+ }
3185
+ return list;
3186
+ }
3187
+ function devRebuilt(e, held2) {
3188
+ const record = e.owned;
3189
+ if (record === null) return;
3190
+ for (let o = record.firstChild; o !== null; o = o.nextSibling) {
3191
+ if (o.Component === void 0 || !held2.includes(o.Component)) continue;
3192
+ const component = o.Component.displayName || o.Component.name || "Component";
3193
+ const region = devName(e);
3194
+ const where = __ownerPath(o);
3195
+ report("ERR_REBUILT_COMPONENT", {
3196
+ data: { component, region },
3197
+ subject: { kind: "effect", name: region },
3198
+ owner: where,
3199
+ loc: e.devName ? devSplit(e.devName)[1] : where.loc
3200
+ });
3201
+ return;
3202
+ }
3203
+ }
3204
+ function devOrphan(e) {
3205
+ if (devAsyncOwners === null || devAsyncOwners.size === 0) return;
3206
+ let meant = null;
3207
+ for (const owner of devAsyncOwners.keys()) meant = owner;
3208
+ const effectName = devName(e);
3209
+ const where = __ownerPath(meant);
3210
+ report("ERR_ORPHAN_EFFECT", {
3211
+ data: { effectName },
3212
+ subject: { kind: "effect", name: effectName },
3213
+ owner: where,
3214
+ loc: e.devName ? devSplit(e.devName)[1] : where.loc
3215
+ });
3216
+ }
3217
+ if ((process.env.NODE_ENV !== "production")) _setOwnerSource(() => __ownerPath(ownerNow()));
3218
+ function __drainPreinstallBuffer() {
3219
+ const out = { signals: [], effects: [], components: [] };
3220
+ if (!(process.env.NODE_ENV !== "production") || preinstall === null) return out;
3221
+ for (const ref of preinstall.signals) {
3222
+ const v = ref.deref();
3223
+ if (v) out.signals.push(v);
3224
+ }
3225
+ for (const ref of preinstall.effects) {
3226
+ const v = ref.deref();
3227
+ if (v && !(v.flags & DISPOSED)) out.effects.push(v);
3228
+ }
3229
+ for (const ctx of preinstall.components) out.components.push(ctx);
3230
+ const { dropped } = preinstall;
3231
+ if (dropped.signals + dropped.effects + dropped.components > 0) {
3232
+ out.dropped = { ...dropped };
3233
+ dropped.signals = dropped.effects = dropped.components = 0;
3234
+ }
3235
+ preinstall.signals.clear();
3236
+ preinstall.effects.clear();
3237
+ preinstall.components.clear();
3238
+ return out;
3239
+ }
3240
+ export {
3241
+ HANDLED,
3242
+ __DEV__2 as __DEV__,
3243
+ __currentEffect,
3244
+ __depsOf,
3245
+ __devtools,
3246
+ __drainPreinstallBuffer,
3247
+ __ownerOf,
3248
+ __ownerPath,
3249
+ __setDevToolsHooks,
3250
+ __subsOf,
3251
+ _adoptOwner,
3252
+ _asyncComputed,
3253
+ _asyncError,
3254
+ _asyncStatus,
3255
+ _beginWork,
3256
+ _busy,
3257
+ _committingTransition,
3258
+ _componentOwner,
3259
+ _contextOf,
3260
+ _createItemScope,
3261
+ _createSelector,
3262
+ _currentComponent,
3263
+ _currentTransition,
3264
+ _detached,
3265
+ _devAction,
3266
+ _devAnchor,
3267
+ _devAsyncWork,
3268
+ _devCallSite,
3269
+ _devDropped,
3270
+ _devError,
3271
+ _devHoldsState,
3272
+ _devHot,
3273
+ _devMounted,
3274
+ _devNewContent,
3275
+ _devStackLoc,
3276
+ _disposeOwner,
3277
+ _effectWhenNeeded,
3278
+ _engine,
3279
+ _enterFrame,
3280
+ _enterOwner,
3281
+ _errorSource,
3282
+ _exitFrame,
3283
+ _exitOwner,
3284
+ _handleError,
3285
+ _handlePending,
3286
+ _holdUser,
3287
+ _installSeedOps,
3288
+ _installStoreSeedOps,
3289
+ _isDisposed,
3290
+ _isNotReady,
3291
+ _isPending,
3292
+ _itemScope,
3293
+ _latestComputed,
3294
+ _livesWithRow,
3295
+ _onCommit,
3296
+ _onQuiet,
3297
+ _ownerRecord,
3298
+ _propField,
3299
+ _provide,
3300
+ _readAlone,
3301
+ _readKey,
3302
+ _readRowItem,
3303
+ _refresh,
3304
+ _releaseUser,
3305
+ _releaseUserEffect,
3306
+ _retryErrors,
3307
+ _rowItem,
3308
+ _runHeldReaders,
3309
+ _runOwned,
3310
+ _runScope,
3311
+ _serverComponentOwner,
3312
+ _serverStoreKey,
3313
+ _setAsyncValue,
3314
+ _setOwnerFallback,
3315
+ _setRowItem,
3316
+ _setUserEffectGate,
3317
+ _startTransition,
3318
+ _symbolChild,
3319
+ _trackWork,
3320
+ _tracking,
3321
+ _urgent,
3322
+ _userEffect,
3323
+ batch,
3324
+ computed,
3325
+ createRoot,
3326
+ effect,
3327
+ flushSync,
3328
+ getOwner,
3329
+ memo,
3330
+ onCleanup,
3331
+ runWithOwner,
3332
+ signal,
3333
+ untrack
3334
+ };