solid-js 1.9.11 → 2.0.0-beta.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 (82) hide show
  1. package/dist/dev.cjs +733 -1678
  2. package/dist/dev.js +598 -1643
  3. package/dist/server.cjs +769 -703
  4. package/dist/server.js +682 -670
  5. package/dist/solid.cjs +699 -1618
  6. package/dist/solid.js +563 -1582
  7. package/package.json +7 -151
  8. package/types/{render → client}/component.d.ts +1 -38
  9. package/types/client/core.d.ts +65 -0
  10. package/types/client/flow.d.ts +100 -0
  11. package/types/client/hydration.d.ts +76 -0
  12. package/types/index.d.ts +11 -14
  13. package/types/jsx.d.ts +1508 -1633
  14. package/types/server/component.d.ts +66 -0
  15. package/types/server/core.d.ts +44 -0
  16. package/types/server/flow.d.ts +60 -0
  17. package/types/server/hydration.d.ts +21 -0
  18. package/types/server/index.d.ts +12 -3
  19. package/types/server/shared.d.ts +45 -0
  20. package/types/server/signals.d.ts +60 -0
  21. package/h/dist/h.cjs +0 -115
  22. package/h/dist/h.js +0 -113
  23. package/h/jsx-dev-runtime/package.json +0 -8
  24. package/h/jsx-runtime/dist/jsx.cjs +0 -15
  25. package/h/jsx-runtime/dist/jsx.js +0 -10
  26. package/h/jsx-runtime/package.json +0 -8
  27. package/h/jsx-runtime/types/index.d.ts +0 -11
  28. package/h/jsx-runtime/types/jsx.d.ts +0 -4242
  29. package/h/package.json +0 -8
  30. package/h/types/hyperscript.d.ts +0 -20
  31. package/h/types/index.d.ts +0 -3
  32. package/html/dist/html.cjs +0 -583
  33. package/html/dist/html.js +0 -581
  34. package/html/package.json +0 -8
  35. package/html/types/index.d.ts +0 -3
  36. package/html/types/lit.d.ts +0 -41
  37. package/store/dist/dev.cjs +0 -458
  38. package/store/dist/dev.js +0 -449
  39. package/store/dist/server.cjs +0 -126
  40. package/store/dist/server.js +0 -114
  41. package/store/dist/store.cjs +0 -438
  42. package/store/dist/store.js +0 -429
  43. package/store/package.json +0 -46
  44. package/store/types/index.d.ts +0 -12
  45. package/store/types/modifiers.d.ts +0 -6
  46. package/store/types/mutable.d.ts +0 -5
  47. package/store/types/server.d.ts +0 -17
  48. package/store/types/store.d.ts +0 -107
  49. package/types/reactive/array.d.ts +0 -44
  50. package/types/reactive/observable.d.ts +0 -36
  51. package/types/reactive/scheduler.d.ts +0 -10
  52. package/types/reactive/signal.d.ts +0 -577
  53. package/types/render/Suspense.d.ts +0 -26
  54. package/types/render/flow.d.ts +0 -118
  55. package/types/render/hydration.d.ts +0 -24
  56. package/types/render/index.d.ts +0 -4
  57. package/types/server/reactive.d.ts +0 -98
  58. package/types/server/rendering.d.ts +0 -159
  59. package/universal/dist/dev.cjs +0 -245
  60. package/universal/dist/dev.js +0 -243
  61. package/universal/dist/universal.cjs +0 -245
  62. package/universal/dist/universal.js +0 -243
  63. package/universal/package.json +0 -20
  64. package/universal/types/index.d.ts +0 -3
  65. package/universal/types/universal.d.ts +0 -30
  66. package/web/dist/dev.cjs +0 -894
  67. package/web/dist/dev.js +0 -782
  68. package/web/dist/server.cjs +0 -892
  69. package/web/dist/server.js +0 -782
  70. package/web/dist/web.cjs +0 -883
  71. package/web/dist/web.js +0 -771
  72. package/web/package.json +0 -46
  73. package/web/storage/dist/storage.cjs +0 -12
  74. package/web/storage/dist/storage.js +0 -10
  75. package/web/storage/package.json +0 -15
  76. package/web/storage/types/index.d.ts +0 -2
  77. package/web/types/client.d.ts +0 -79
  78. package/web/types/core.d.ts +0 -2
  79. package/web/types/index.d.ts +0 -50
  80. package/web/types/jsx.d.ts +0 -1
  81. package/web/types/server-mock.d.ts +0 -65
  82. package/web/types/server.d.ts +0 -177
package/dist/solid.cjs CHANGED
@@ -1,1439 +1,587 @@
1
1
  'use strict';
2
2
 
3
- let taskIdCounter = 1,
4
- isCallbackScheduled = false,
5
- isPerformingWork = false,
6
- taskQueue = [],
7
- currentTask = null,
8
- shouldYieldToHost = null,
9
- yieldInterval = 5,
10
- deadline = 0,
11
- maxYieldInterval = 300,
12
- maxDeadline = 0,
13
- scheduleCallback = null,
14
- scheduledCallback = null;
15
- const maxSigned31BitInt = 1073741823;
16
- function setupScheduler() {
17
- const channel = new MessageChannel(),
18
- port = channel.port2;
19
- scheduleCallback = () => port.postMessage(null);
20
- channel.port1.onmessage = () => {
21
- if (scheduledCallback !== null) {
22
- const currentTime = performance.now();
23
- deadline = currentTime + yieldInterval;
24
- maxDeadline = currentTime + maxYieldInterval;
25
- try {
26
- const hasMoreWork = scheduledCallback(currentTime);
27
- if (!hasMoreWork) {
28
- scheduledCallback = null;
29
- } else port.postMessage(null);
30
- } catch (error) {
31
- port.postMessage(null);
32
- throw error;
33
- }
34
- }
35
- };
36
- if (navigator && navigator.scheduling && navigator.scheduling.isInputPending) {
37
- const scheduling = navigator.scheduling;
38
- shouldYieldToHost = () => {
39
- const currentTime = performance.now();
40
- if (currentTime >= deadline) {
41
- if (scheduling.isInputPending()) {
42
- return true;
43
- }
44
- return currentTime >= maxDeadline;
45
- } else {
46
- return false;
47
- }
48
- };
49
- } else {
50
- shouldYieldToHost = () => performance.now() >= deadline;
3
+ var signals = require('@solidjs/signals');
4
+
5
+ const $DEVCOMP = Symbol(0);
6
+ function createContext(defaultValue, options) {
7
+ const id = Symbol(options && options.name || "");
8
+ function provider(props) {
9
+ return signals.createRoot(() => {
10
+ signals.setContext(provider, props.value);
11
+ return children(() => props.children);
12
+ });
51
13
  }
14
+ provider.id = id;
15
+ provider.defaultValue = defaultValue;
16
+ return provider;
52
17
  }
53
- function enqueue(taskQueue, task) {
54
- function findIndex() {
55
- let m = 0;
56
- let n = taskQueue.length - 1;
57
- while (m <= n) {
58
- const k = n + m >> 1;
59
- const cmp = task.expirationTime - taskQueue[k].expirationTime;
60
- if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;else return k;
61
- }
62
- return m;
63
- }
64
- taskQueue.splice(findIndex(), 0, task);
18
+ function useContext(context) {
19
+ return signals.getContext(context);
65
20
  }
66
- function requestCallback(fn, options) {
67
- if (!scheduleCallback) setupScheduler();
68
- let startTime = performance.now(),
69
- timeout = maxSigned31BitInt;
70
- if (options && options.timeout) timeout = options.timeout;
71
- const newTask = {
72
- id: taskIdCounter++,
73
- fn,
74
- startTime,
75
- expirationTime: startTime + timeout
21
+ function children(fn) {
22
+ const c = signals.createMemo(fn, undefined, {
23
+ lazy: true
24
+ });
25
+ const memo = signals.createMemo(() => signals.flatten(c()), undefined, {
26
+ lazy: true
27
+ });
28
+ memo.toArray = () => {
29
+ const v = memo();
30
+ return Array.isArray(v) ? v : v != null ? [v] : [];
76
31
  };
77
- enqueue(taskQueue, newTask);
78
- if (!isCallbackScheduled && !isPerformingWork) {
79
- isCallbackScheduled = true;
80
- scheduledCallback = flushWork;
81
- scheduleCallback();
82
- }
83
- return newTask;
84
- }
85
- function cancelCallback(task) {
86
- task.fn = null;
87
- }
88
- function flushWork(initialTime) {
89
- isCallbackScheduled = false;
90
- isPerformingWork = true;
91
- try {
92
- return workLoop(initialTime);
93
- } finally {
94
- currentTask = null;
95
- isPerformingWork = false;
96
- }
97
- }
98
- function workLoop(initialTime) {
99
- let currentTime = initialTime;
100
- currentTask = taskQueue[0] || null;
101
- while (currentTask !== null) {
102
- if (currentTask.expirationTime > currentTime && shouldYieldToHost()) {
103
- break;
104
- }
105
- const callback = currentTask.fn;
106
- if (callback !== null) {
107
- currentTask.fn = null;
108
- const didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
109
- callback(didUserCallbackTimeout);
110
- currentTime = performance.now();
111
- if (currentTask === taskQueue[0]) {
112
- taskQueue.shift();
113
- }
114
- } else taskQueue.shift();
115
- currentTask = taskQueue[0] || null;
116
- }
117
- return currentTask !== null;
32
+ return memo;
118
33
  }
119
34
 
120
35
  const sharedConfig = {
121
- context: undefined,
36
+ hydrating: false,
122
37
  registry: undefined,
123
- effects: undefined,
124
38
  done: false,
125
- getContextId() {
126
- return getContextId(this.context.count);
127
- },
128
39
  getNextContextId() {
129
- return getContextId(this.context.count++);
40
+ const o = signals.getOwner();
41
+ if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
42
+ return signals.getNextChildId(o);
130
43
  }
131
44
  };
132
- function getContextId(count) {
133
- const num = String(count),
134
- len = num.length - 1;
135
- return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
136
- }
137
- function setHydrateContext(context) {
138
- sharedConfig.context = context;
139
- }
140
- function nextHydrateContext() {
141
- return {
142
- ...sharedConfig.context,
143
- id: sharedConfig.getNextContextId(),
144
- count: 0
145
- };
146
- }
147
-
148
- const IS_DEV = false;
149
- const equalFn = (a, b) => a === b;
150
- const $PROXY = Symbol("solid-proxy");
151
- const SUPPORTS_PROXY = typeof Proxy === "function";
152
- const $TRACK = Symbol("solid-track");
153
- const $DEVCOMP = Symbol("solid-dev-component");
154
- const signalOptions = {
155
- equals: equalFn
156
- };
157
- let ERROR = null;
158
- let runEffects = runQueue;
159
- const STALE = 1;
160
- const PENDING = 2;
161
- const UNOWNED = {
162
- owned: null,
163
- cleanups: null,
164
- context: null,
165
- owner: null
166
- };
167
- const NO_INIT = {};
168
- var Owner = null;
169
- let Transition = null;
170
- let Scheduler = null;
171
- let ExternalSourceConfig = null;
172
- let Listener = null;
173
- let Updates = null;
174
- let Effects = null;
175
- let ExecCount = 0;
176
- function createRoot(fn, detachedOwner) {
177
- const listener = Listener,
178
- owner = Owner,
179
- unowned = fn.length === 0,
180
- current = detachedOwner === undefined ? owner : detachedOwner,
181
- root = unowned ? UNOWNED : {
182
- owned: null,
183
- cleanups: null,
184
- context: current ? current.context : null,
185
- owner: current
186
- },
187
- updateFn = unowned ? fn : () => fn(() => untrack(() => cleanNode(root)));
188
- Owner = root;
189
- Listener = null;
190
- try {
191
- return runUpdates(updateFn, true);
192
- } finally {
193
- Listener = listener;
194
- Owner = owner;
195
- }
196
- }
197
- function createSignal(value, options) {
198
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
199
- const s = {
200
- value,
201
- observers: null,
202
- observerSlots: null,
203
- comparator: options.equals || undefined
204
- };
205
- const setter = value => {
206
- if (typeof value === "function") {
207
- if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value);
208
- }
209
- return writeSignal(s, value);
210
- };
211
- return [readSignal.bind(s), setter];
212
- }
213
- function createComputed(fn, value, options) {
214
- const c = createComputation(fn, value, true, STALE);
215
- if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
216
- }
217
- function createRenderEffect(fn, value, options) {
218
- const c = createComputation(fn, value, false, STALE);
219
- if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
220
- }
221
- function createEffect(fn, value, options) {
222
- runEffects = runUserEffects;
223
- const c = createComputation(fn, value, false, STALE),
224
- s = SuspenseContext && useContext(SuspenseContext);
225
- if (s) c.suspense = s;
226
- if (!options || !options.render) c.user = true;
227
- Effects ? Effects.push(c) : updateComputation(c);
228
- }
229
- function createReaction(onInvalidate, options) {
230
- let fn;
231
- const c = createComputation(() => {
232
- fn ? fn() : untrack(onInvalidate);
233
- fn = undefined;
234
- }, undefined, false, 0),
235
- s = SuspenseContext && useContext(SuspenseContext);
236
- if (s) c.suspense = s;
237
- c.user = true;
238
- return tracking => {
239
- fn = tracking;
240
- updateComputation(c);
241
- };
242
- }
243
- function createMemo(fn, value, options) {
244
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
245
- const c = createComputation(fn, value, true, 0);
246
- c.observers = null;
247
- c.observerSlots = null;
248
- c.comparator = options.equals || undefined;
249
- if (Scheduler && Transition && Transition.running) {
250
- c.tState = STALE;
251
- Updates.push(c);
252
- } else updateComputation(c);
253
- return readSignal.bind(c);
254
- }
255
- function isPromise(v) {
256
- return v && typeof v === "object" && "then" in v;
257
- }
258
- function createResource(pSource, pFetcher, pOptions) {
259
- let source;
260
- let fetcher;
261
- let options;
262
- if (typeof pFetcher === "function") {
263
- source = pSource;
264
- fetcher = pFetcher;
265
- options = pOptions || {};
266
- } else {
267
- source = true;
268
- fetcher = pSource;
269
- options = pFetcher || {};
270
- }
271
- let pr = null,
272
- initP = NO_INIT,
273
- id = null,
274
- loadedUnderTransition = false,
275
- scheduled = false,
276
- resolved = "initialValue" in options,
277
- dynamic = typeof source === "function" && createMemo(source);
278
- const contexts = new Set(),
279
- [value, setValue] = (options.storage || createSignal)(options.initialValue),
280
- [error, setError] = createSignal(undefined),
281
- [track, trigger] = createSignal(undefined, {
282
- equals: false
283
- }),
284
- [state, setState] = createSignal(resolved ? "ready" : "unresolved");
285
- if (sharedConfig.context) {
286
- id = sharedConfig.getNextContextId();
287
- if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id);
288
- }
289
- function loadEnd(p, v, error, key) {
290
- if (pr === p) {
291
- pr = null;
292
- key !== undefined && (resolved = true);
293
- if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
294
- value: v
295
- }));
296
- initP = NO_INIT;
297
- if (Transition && p && loadedUnderTransition) {
298
- Transition.promises.delete(p);
299
- loadedUnderTransition = false;
300
- runUpdates(() => {
301
- Transition.running = true;
302
- completeLoad(v, error);
303
- }, false);
304
- } else completeLoad(v, error);
305
- }
306
- return v;
307
- }
308
- function completeLoad(v, err) {
309
- runUpdates(() => {
310
- if (err === undefined) setValue(() => v);
311
- setState(err !== undefined ? "errored" : resolved ? "ready" : "unresolved");
312
- setError(err);
313
- for (const c of contexts.keys()) c.decrement();
314
- contexts.clear();
315
- }, false);
316
- }
317
- function read() {
318
- const c = SuspenseContext && useContext(SuspenseContext),
319
- v = value(),
320
- err = error();
321
- if (err !== undefined && !pr) throw err;
322
- if (Listener && !Listener.user && c) {
323
- createComputed(() => {
324
- track();
325
- if (pr) {
326
- if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr);else if (!contexts.has(c)) {
327
- c.increment();
328
- contexts.add(c);
329
- }
330
- }
331
- });
332
- }
333
- return v;
334
- }
335
- function load(refetching = true) {
336
- if (refetching !== false && scheduled) return;
337
- scheduled = false;
338
- const lookup = dynamic ? dynamic() : source;
339
- loadedUnderTransition = Transition && Transition.running;
340
- if (lookup == null || lookup === false) {
341
- loadEnd(pr, untrack(value));
342
- return;
343
- }
344
- if (Transition && pr) Transition.promises.delete(pr);
345
- let error;
346
- const p = initP !== NO_INIT ? initP : untrack(() => {
347
- try {
348
- return fetcher(lookup, {
349
- value: value(),
350
- refetching
351
- });
352
- } catch (fetcherError) {
353
- error = fetcherError;
354
- }
355
- });
356
- if (error !== undefined) {
357
- loadEnd(pr, undefined, castError(error), lookup);
358
- return;
359
- } else if (!isPromise(p)) {
360
- loadEnd(pr, p, undefined, lookup);
361
- return p;
362
- }
363
- pr = p;
364
- if ("v" in p) {
365
- if (p.s === 1) loadEnd(pr, p.v, undefined, lookup);else loadEnd(pr, undefined, castError(p.v), lookup);
366
- return p;
367
- }
368
- scheduled = true;
369
- queueMicrotask(() => scheduled = false);
370
- runUpdates(() => {
371
- setState(resolved ? "refreshing" : "pending");
372
- trigger();
373
- }, false);
374
- return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup));
375
- }
376
- Object.defineProperties(read, {
377
- state: {
378
- get: () => state()
379
- },
380
- error: {
381
- get: () => error()
382
- },
383
- loading: {
384
- get() {
385
- const s = state();
386
- return s === "pending" || s === "refreshing";
387
- }
388
- },
389
- latest: {
390
- get() {
391
- if (!resolved) return read();
392
- const err = error();
393
- if (err && !pr) throw err;
394
- return value();
395
- }
396
- }
45
+ let _hydrationEndCallbacks = null;
46
+ let _pendingBoundaries = 0;
47
+ let _hydrationDone = false;
48
+ let _snapshotRootOwner = null;
49
+ function markTopLevelSnapshotScope() {
50
+ if (_snapshotRootOwner) return;
51
+ let owner = signals.getOwner();
52
+ if (!owner) return;
53
+ while (owner._parent) owner = owner._parent;
54
+ signals.markSnapshotScope(owner);
55
+ _snapshotRootOwner = owner;
56
+ }
57
+ function drainHydrationCallbacks() {
58
+ if (_hydrationDone) return;
59
+ _hydrationDone = true;
60
+ _doneValue = true;
61
+ signals.clearSnapshots();
62
+ signals.setSnapshotCapture(false);
63
+ signals.flush();
64
+ const cbs = _hydrationEndCallbacks;
65
+ _hydrationEndCallbacks = null;
66
+ if (cbs) for (const cb of cbs) cb();
67
+ setTimeout(() => {
68
+ if (globalThis._$HY) globalThis._$HY.done = true;
397
69
  });
398
- let owner = Owner;
399
- if (dynamic) createComputed(() => (owner = Owner, load(false)));else load(false);
400
- return [read, {
401
- refetch: info => runWithOwner(owner, () => load(info)),
402
- mutate: setValue
403
- }];
404
- }
405
- function createDeferred(source, options) {
406
- let t,
407
- timeout = options ? options.timeoutMs : undefined;
408
- const node = createComputation(() => {
409
- if (!t || !t.fn) t = requestCallback(() => setDeferred(() => node.value), timeout !== undefined ? {
410
- timeout
411
- } : undefined);
412
- return source();
413
- }, undefined, true);
414
- const [deferred, setDeferred] = createSignal(Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, options);
415
- updateComputation(node);
416
- setDeferred(() => Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value);
417
- return deferred;
418
- }
419
- function createSelector(source, fn = equalFn, options) {
420
- const subs = new Map();
421
- const node = createComputation(p => {
422
- const v = source();
423
- for (const [key, val] of subs.entries()) if (fn(key, v) !== fn(key, p)) {
424
- for (const c of val.values()) {
425
- c.state = STALE;
426
- if (c.pure) Updates.push(c);else Effects.push(c);
427
- }
428
- }
429
- return v;
430
- }, undefined, true, STALE);
431
- updateComputation(node);
432
- return key => {
433
- const listener = Listener;
434
- if (listener) {
435
- let l;
436
- if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener]));
437
- onCleanup(() => {
438
- l.delete(listener);
439
- !l.size && subs.delete(key);
440
- });
441
- }
442
- return fn(key, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value);
443
- };
444
70
  }
445
- function batch(fn) {
446
- return runUpdates(fn, false);
71
+ function checkHydrationComplete() {
72
+ if (_pendingBoundaries === 0) drainHydrationCallbacks();
447
73
  }
448
- function untrack(fn) {
449
- if (!ExternalSourceConfig && Listener === null) return fn();
450
- const listener = Listener;
451
- Listener = null;
452
- try {
453
- if (ExternalSourceConfig) return ExternalSourceConfig.untrack(fn);
454
- return fn();
455
- } finally {
456
- Listener = listener;
74
+ let _hydratingValue = false;
75
+ let _doneValue = false;
76
+ let _createMemo;
77
+ let _createSignal;
78
+ let _createErrorBoundary;
79
+ let _createOptimistic;
80
+ let _createProjection;
81
+ let _createStore;
82
+ let _createOptimisticStore;
83
+ let _createRenderEffect;
84
+ let _createEffect;
85
+ class MockPromise {
86
+ static all() {
87
+ return new MockPromise();
457
88
  }
458
- }
459
- function on(deps, fn, options) {
460
- const isArray = Array.isArray(deps);
461
- let prevInput;
462
- let defer = options && options.defer;
463
- return prevValue => {
464
- let input;
465
- if (isArray) {
466
- input = Array(deps.length);
467
- for (let i = 0; i < deps.length; i++) input[i] = deps[i]();
468
- } else input = deps();
469
- if (defer) {
470
- defer = false;
471
- return prevValue;
472
- }
473
- const result = untrack(() => fn(input, prevInput, prevValue));
474
- prevInput = input;
475
- return result;
476
- };
477
- }
478
- function onMount(fn) {
479
- createEffect(() => untrack(fn));
480
- }
481
- function onCleanup(fn) {
482
- if (Owner === null) ;else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
483
- return fn;
484
- }
485
- function catchError(fn, handler) {
486
- ERROR || (ERROR = Symbol("error"));
487
- Owner = createComputation(undefined, undefined, true);
488
- Owner.context = {
489
- ...Owner.context,
490
- [ERROR]: [handler]
491
- };
492
- if (Transition && Transition.running) Transition.sources.add(Owner);
493
- try {
494
- return fn();
495
- } catch (err) {
496
- handleError(err);
497
- } finally {
498
- Owner = Owner.owner;
89
+ static allSettled() {
90
+ return new MockPromise();
499
91
  }
500
- }
501
- function getListener() {
502
- return Listener;
503
- }
504
- function getOwner() {
505
- return Owner;
506
- }
507
- function runWithOwner(o, fn) {
508
- const prev = Owner;
509
- const prevListener = Listener;
510
- Owner = o;
511
- Listener = null;
512
- try {
513
- return runUpdates(fn, true);
514
- } catch (err) {
515
- handleError(err);
516
- } finally {
517
- Owner = prev;
518
- Listener = prevListener;
92
+ static any() {
93
+ return new MockPromise();
519
94
  }
520
- }
521
- function enableScheduling(scheduler = requestCallback) {
522
- Scheduler = scheduler;
523
- }
524
- function startTransition(fn) {
525
- if (Transition && Transition.running) {
526
- fn();
527
- return Transition.done;
95
+ static race() {
96
+ return new MockPromise();
528
97
  }
529
- const l = Listener;
530
- const o = Owner;
531
- return Promise.resolve().then(() => {
532
- Listener = l;
533
- Owner = o;
534
- let t;
535
- if (Scheduler || SuspenseContext) {
536
- t = Transition || (Transition = {
537
- sources: new Set(),
538
- effects: [],
539
- promises: new Set(),
540
- disposed: new Set(),
541
- queue: new Set(),
542
- running: true
543
- });
544
- t.done || (t.done = new Promise(res => t.resolve = res));
545
- t.running = true;
546
- }
547
- runUpdates(fn, false);
548
- Listener = Owner = null;
549
- return t ? t.done : undefined;
550
- });
551
- }
552
- const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
553
- function useTransition() {
554
- return [transPending, startTransition];
555
- }
556
- function resumeEffects(e) {
557
- Effects.push.apply(Effects, e);
558
- e.length = 0;
559
- }
560
- function createContext(defaultValue, options) {
561
- const id = Symbol("context");
562
- return {
563
- id,
564
- Provider: createProvider(id),
565
- defaultValue
566
- };
567
- }
568
- function useContext(context) {
569
- let value;
570
- return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined ? value : context.defaultValue;
571
- }
572
- function children(fn) {
573
- const children = createMemo(fn);
574
- const memo = createMemo(() => resolveChildren(children()));
575
- memo.toArray = () => {
576
- const c = memo();
577
- return Array.isArray(c) ? c : c != null ? [c] : [];
578
- };
579
- return memo;
580
- }
581
- let SuspenseContext;
582
- function getSuspenseContext() {
583
- return SuspenseContext || (SuspenseContext = createContext());
584
- }
585
- function enableExternalSource(factory, untrack = fn => fn()) {
586
- if (ExternalSourceConfig) {
587
- const {
588
- factory: oldFactory,
589
- untrack: oldUntrack
590
- } = ExternalSourceConfig;
591
- ExternalSourceConfig = {
592
- factory: (fn, trigger) => {
593
- const oldSource = oldFactory(fn, trigger);
594
- const source = factory(x => oldSource.track(x), trigger);
595
- return {
596
- track: x => source.track(x),
597
- dispose() {
598
- source.dispose();
599
- oldSource.dispose();
600
- }
601
- };
602
- },
603
- untrack: fn => oldUntrack(() => untrack(fn))
604
- };
605
- } else {
606
- ExternalSourceConfig = {
607
- factory,
608
- untrack
609
- };
98
+ static reject() {
99
+ return new MockPromise();
610
100
  }
611
- }
612
- function readSignal() {
613
- const runningTransition = Transition && Transition.running;
614
- if (this.sources && (runningTransition ? this.tState : this.state)) {
615
- if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);else {
616
- const updates = Updates;
617
- Updates = null;
618
- runUpdates(() => lookUpstream(this), false);
619
- Updates = updates;
620
- }
101
+ static resolve() {
102
+ return new MockPromise();
621
103
  }
622
- if (Listener) {
623
- const sSlot = this.observers ? this.observers.length : 0;
624
- if (!Listener.sources) {
625
- Listener.sources = [this];
626
- Listener.sourceSlots = [sSlot];
627
- } else {
628
- Listener.sources.push(this);
629
- Listener.sourceSlots.push(sSlot);
630
- }
631
- if (!this.observers) {
632
- this.observers = [Listener];
633
- this.observerSlots = [Listener.sources.length - 1];
634
- } else {
635
- this.observers.push(Listener);
636
- this.observerSlots.push(Listener.sources.length - 1);
637
- }
104
+ catch() {
105
+ return new MockPromise();
638
106
  }
639
- if (runningTransition && Transition.sources.has(this)) return this.tValue;
640
- return this.value;
641
- }
642
- function writeSignal(node, value, isComp) {
643
- let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
644
- if (!node.comparator || !node.comparator(current, value)) {
645
- if (Transition) {
646
- const TransitionRunning = Transition.running;
647
- if (TransitionRunning || !isComp && Transition.sources.has(node)) {
648
- Transition.sources.add(node);
649
- node.tValue = value;
650
- }
651
- if (!TransitionRunning) node.value = value;
652
- } else node.value = value;
653
- if (node.observers && node.observers.length) {
654
- runUpdates(() => {
655
- for (let i = 0; i < node.observers.length; i += 1) {
656
- const o = node.observers[i];
657
- const TransitionRunning = Transition && Transition.running;
658
- if (TransitionRunning && Transition.disposed.has(o)) continue;
659
- if (TransitionRunning ? !o.tState : !o.state) {
660
- if (o.pure) Updates.push(o);else Effects.push(o);
661
- if (o.observers) markDownstream(o);
662
- }
663
- if (!TransitionRunning) o.state = STALE;else o.tState = STALE;
664
- }
665
- if (Updates.length > 10e5) {
666
- Updates = [];
667
- if (IS_DEV) ;
668
- throw new Error();
669
- }
670
- }, false);
671
- }
107
+ then() {
108
+ return new MockPromise();
672
109
  }
673
- return value;
674
- }
675
- function updateComputation(node) {
676
- if (!node.fn) return;
677
- cleanNode(node);
678
- const time = ExecCount;
679
- runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time);
680
- if (Transition && !Transition.running && Transition.sources.has(node)) {
681
- queueMicrotask(() => {
682
- runUpdates(() => {
683
- Transition && (Transition.running = true);
684
- Listener = Owner = node;
685
- runComputation(node, node.tValue, time);
686
- Listener = Owner = null;
687
- }, false);
688
- });
110
+ finally() {
111
+ return new MockPromise();
689
112
  }
690
113
  }
691
- function runComputation(node, value, time) {
692
- let nextValue;
693
- const owner = Owner,
694
- listener = Listener;
695
- Listener = Owner = node;
114
+ function subFetch(fn, prev) {
115
+ const ogFetch = fetch;
116
+ const ogPromise = Promise;
696
117
  try {
697
- nextValue = node.fn(value);
698
- } catch (err) {
699
- if (node.pure) {
700
- if (Transition && Transition.running) {
701
- node.tState = STALE;
702
- node.tOwned && node.tOwned.forEach(cleanNode);
703
- node.tOwned = undefined;
704
- } else {
705
- node.state = STALE;
706
- node.owned && node.owned.forEach(cleanNode);
707
- node.owned = null;
708
- }
118
+ window.fetch = () => new MockPromise();
119
+ Promise = MockPromise;
120
+ const result = fn(prev);
121
+ if (result && typeof result[Symbol.asyncIterator] === "function") {
122
+ result[Symbol.asyncIterator]().next();
709
123
  }
710
- node.updatedAt = time + 1;
711
- return handleError(err);
124
+ return result;
712
125
  } finally {
713
- Listener = listener;
714
- Owner = owner;
715
- }
716
- if (!node.updatedAt || node.updatedAt <= time) {
717
- if (node.updatedAt != null && "observers" in node) {
718
- writeSignal(node, nextValue, true);
719
- } else if (Transition && Transition.running && node.pure) {
720
- Transition.sources.add(node);
721
- node.tValue = nextValue;
722
- } else node.value = nextValue;
723
- node.updatedAt = time;
724
- }
725
- }
726
- function createComputation(fn, init, pure, state = STALE, options) {
727
- const c = {
728
- fn,
729
- state: state,
730
- updatedAt: null,
731
- owned: null,
732
- sources: null,
733
- sourceSlots: null,
734
- cleanups: null,
735
- value: init,
736
- owner: Owner,
737
- context: Owner ? Owner.context : null,
738
- pure
739
- };
740
- if (Transition && Transition.running) {
741
- c.state = 0;
742
- c.tState = state;
743
- }
744
- if (Owner === null) ;else if (Owner !== UNOWNED) {
745
- if (Transition && Transition.running && Owner.pure) {
746
- if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c);
126
+ window.fetch = ogFetch;
127
+ Promise = ogPromise;
128
+ }
129
+ }
130
+ function consumeFirstSync(ai) {
131
+ const iter = ai[Symbol.asyncIterator]();
132
+ const r = iter.next();
133
+ const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
134
+ return [value, iter];
135
+ }
136
+ function applyPatches(target, patches) {
137
+ for (const patch of patches) {
138
+ const path = patch[0];
139
+ let current = target;
140
+ for (let i = 0; i < path.length - 1; i++) current = current[path[i]];
141
+ const key = path[path.length - 1];
142
+ if (patch.length === 1) {
143
+ Array.isArray(current) ? current.splice(key, 1) : delete current[key];
144
+ } else if (patch.length === 3) {
145
+ current.splice(key, 0, patch[1]);
747
146
  } else {
748
- if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
147
+ current[key] = patch[1];
749
148
  }
750
149
  }
751
- if (ExternalSourceConfig && c.fn) {
752
- const [track, trigger] = createSignal(undefined, {
753
- equals: false
754
- });
755
- const ordinary = ExternalSourceConfig.factory(c.fn, trigger);
756
- onCleanup(() => ordinary.dispose());
757
- const triggerInTransition = () => startTransition(trigger).then(() => inTransition.dispose());
758
- const inTransition = ExternalSourceConfig.factory(c.fn, triggerInTransition);
759
- c.fn = x => {
760
- track();
761
- return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
762
- };
763
- }
764
- return c;
765
150
  }
766
- function runTop(node) {
767
- const runningTransition = Transition && Transition.running;
768
- if ((runningTransition ? node.tState : node.state) === 0) return;
769
- if ((runningTransition ? node.tState : node.state) === PENDING) return lookUpstream(node);
770
- if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
771
- const ancestors = [node];
772
- while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
773
- if (runningTransition && Transition.disposed.has(node)) return;
774
- if (runningTransition ? node.tState : node.state) ancestors.push(node);
775
- }
776
- for (let i = ancestors.length - 1; i >= 0; i--) {
777
- node = ancestors[i];
778
- if (runningTransition) {
779
- let top = node,
780
- prev = ancestors[i + 1];
781
- while ((top = top.owner) && top !== prev) {
782
- if (Transition.disposed.has(top)) return;
151
+ function scheduleIteratorConsumption(iter, apply) {
152
+ const consume = () => {
153
+ while (true) {
154
+ const n = iter.next();
155
+ if (n instanceof Promise) {
156
+ n.then(r => {
157
+ if (r.done) return;
158
+ apply(r.value);
159
+ consume();
160
+ });
161
+ return;
783
162
  }
163
+ if (n.done) break;
164
+ apply(n.value);
784
165
  }
785
- if ((runningTransition ? node.tState : node.state) === STALE) {
786
- updateComputation(node);
787
- } else if ((runningTransition ? node.tState : node.state) === PENDING) {
788
- const updates = Updates;
789
- Updates = null;
790
- runUpdates(() => lookUpstream(node, ancestors[0]), false);
791
- Updates = updates;
792
- }
793
- }
794
- }
795
- function runUpdates(fn, init) {
796
- if (Updates) return fn();
797
- let wait = false;
798
- if (!init) Updates = [];
799
- if (Effects) wait = true;else Effects = [];
800
- ExecCount++;
801
- try {
802
- const res = fn();
803
- completeUpdates(wait);
804
- return res;
805
- } catch (err) {
806
- if (!wait) Effects = null;
807
- Updates = null;
808
- handleError(err);
809
- }
810
- }
811
- function completeUpdates(wait) {
812
- if (Updates) {
813
- if (Scheduler && Transition && Transition.running) scheduleQueue(Updates);else runQueue(Updates);
814
- Updates = null;
815
- }
816
- if (wait) return;
817
- let res;
818
- if (Transition) {
819
- if (!Transition.promises.size && !Transition.queue.size) {
820
- const sources = Transition.sources;
821
- const disposed = Transition.disposed;
822
- Effects.push.apply(Effects, Transition.effects);
823
- res = Transition.resolve;
824
- for (const e of Effects) {
825
- "tState" in e && (e.state = e.tState);
826
- delete e.tState;
827
- }
828
- Transition = null;
829
- runUpdates(() => {
830
- for (const d of disposed) cleanNode(d);
831
- for (const v of sources) {
832
- v.value = v.tValue;
833
- if (v.owned) {
834
- for (let i = 0, len = v.owned.length; i < len; i++) cleanNode(v.owned[i]);
835
- }
836
- if (v.tOwned) v.owned = v.tOwned;
837
- delete v.tValue;
838
- delete v.tOwned;
839
- v.tState = 0;
166
+ };
167
+ consume();
168
+ }
169
+ function isAsyncIterable(v) {
170
+ return v != null && typeof v[Symbol.asyncIterator] === "function";
171
+ }
172
+ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
173
+ const parent = signals.getOwner();
174
+ const expectedId = signals.peekNextChildId(parent);
175
+ if (!sharedConfig.has(expectedId)) return null;
176
+ const initP = sharedConfig.load(expectedId);
177
+ if (!isAsyncIterable(initP)) return null;
178
+ const [firstValue, iter] = consumeFirstSync(initP);
179
+ const [get, set] = signals.createSignal(firstValue);
180
+ const result = coreFn(() => get(), firstValue, options);
181
+ scheduleIteratorConsumption(iter, v => {
182
+ set(() => v);
183
+ signals.flush();
184
+ });
185
+ return result;
186
+ }
187
+ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
188
+ const parent = signals.getOwner();
189
+ const expectedId = signals.peekNextChildId(parent);
190
+ if (!sharedConfig.has(expectedId)) return null;
191
+ const initP = sharedConfig.load(expectedId);
192
+ if (!isAsyncIterable(initP)) return null;
193
+ const [firstState, iter] = consumeFirstSync(initP);
194
+ const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
195
+ scheduleIteratorConsumption(iter, patches => {
196
+ setStore(d => {
197
+ applyPatches(d, patches);
198
+ });
199
+ });
200
+ return [store, setStore];
201
+ }
202
+ function hydratedCreateMemo(compute, value, options) {
203
+ if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
204
+ markTopLevelSnapshotScope();
205
+ const ssrSource = options?.ssrSource;
206
+ if (ssrSource === "client") {
207
+ const [hydrated, setHydrated] = signals.createSignal(false);
208
+ const memo = signals.createMemo(prev => {
209
+ if (!hydrated()) return prev ?? value;
210
+ return compute(prev);
211
+ }, value, options);
212
+ setHydrated(true);
213
+ return memo;
214
+ }
215
+ if (ssrSource === "initial") {
216
+ return signals.createMemo(prev => {
217
+ if (!sharedConfig.hydrating) return compute(prev);
218
+ subFetch(compute, prev);
219
+ return prev ?? value;
220
+ }, value, options);
221
+ }
222
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
223
+ if (aiResult !== null) return aiResult;
224
+ return signals.createMemo(prev => {
225
+ const o = signals.getOwner();
226
+ if (!sharedConfig.hydrating) return compute(prev);
227
+ let initP;
228
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
229
+ const init = initP?.v ?? initP;
230
+ return init != null ? (subFetch(compute, prev), init) : compute(prev);
231
+ }, value, options);
232
+ }
233
+ function hydratedCreateSignal(fn, second, third) {
234
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
235
+ markTopLevelSnapshotScope();
236
+ const ssrSource = third?.ssrSource;
237
+ if (ssrSource === "client") {
238
+ const [hydrated, setHydrated] = signals.createSignal(false);
239
+ const sig = signals.createSignal(prev => {
240
+ if (!hydrated()) return prev ?? second;
241
+ return fn(prev);
242
+ }, second, third);
243
+ setHydrated(true);
244
+ return sig;
245
+ }
246
+ if (ssrSource === "initial") {
247
+ return signals.createSignal(prev => {
248
+ if (!sharedConfig.hydrating) return fn(prev);
249
+ subFetch(fn, prev);
250
+ return prev ?? second;
251
+ }, second, third);
252
+ }
253
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
254
+ if (aiResult !== null) return aiResult;
255
+ return signals.createSignal(prev => {
256
+ if (!sharedConfig.hydrating) return fn(prev);
257
+ const o = signals.getOwner();
258
+ let initP;
259
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
260
+ const init = initP?.v ?? initP;
261
+ return init != null ? (subFetch(fn, prev), init) : fn(prev);
262
+ }, second, third);
263
+ }
264
+ function hydratedCreateErrorBoundary(fn, fallback) {
265
+ if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
266
+ markTopLevelSnapshotScope();
267
+ const parent = signals.getOwner();
268
+ const expectedId = signals.peekNextChildId(parent);
269
+ if (sharedConfig.has(expectedId)) {
270
+ const err = sharedConfig.load(expectedId);
271
+ if (err !== undefined) {
272
+ let hydrated = true;
273
+ return signals.createErrorBoundary(() => {
274
+ if (hydrated) {
275
+ hydrated = false;
276
+ throw err;
840
277
  }
841
- setTransPending(false);
842
- }, false);
843
- } else if (Transition.running) {
844
- Transition.running = false;
845
- Transition.effects.push.apply(Transition.effects, Effects);
846
- Effects = null;
847
- setTransPending(true);
848
- return;
849
- }
850
- }
851
- const e = Effects;
852
- Effects = null;
853
- if (e.length) runUpdates(() => runEffects(e), false);
854
- if (res) res();
855
- }
856
- function runQueue(queue) {
857
- for (let i = 0; i < queue.length; i++) runTop(queue[i]);
858
- }
859
- function scheduleQueue(queue) {
860
- for (let i = 0; i < queue.length; i++) {
861
- const item = queue[i];
862
- const tasks = Transition.queue;
863
- if (!tasks.has(item)) {
864
- tasks.add(item);
865
- Scheduler(() => {
866
- tasks.delete(item);
867
- runUpdates(() => {
868
- Transition.running = true;
869
- runTop(item);
870
- }, false);
871
- Transition && (Transition.running = false);
872
- });
873
- }
874
- }
875
- }
876
- function runUserEffects(queue) {
877
- let i,
878
- userLength = 0;
879
- for (i = 0; i < queue.length; i++) {
880
- const e = queue[i];
881
- if (!e.user) runTop(e);else queue[userLength++] = e;
882
- }
883
- if (sharedConfig.context) {
884
- if (sharedConfig.count) {
885
- sharedConfig.effects || (sharedConfig.effects = []);
886
- sharedConfig.effects.push(...queue.slice(0, userLength));
887
- return;
888
- }
889
- setHydrateContext();
890
- }
891
- if (sharedConfig.effects && (sharedConfig.done || !sharedConfig.count)) {
892
- queue = [...sharedConfig.effects, ...queue];
893
- userLength += sharedConfig.effects.length;
894
- delete sharedConfig.effects;
278
+ return fn();
279
+ }, fallback);
280
+ }
281
+ }
282
+ return signals.createErrorBoundary(fn, fallback);
283
+ }
284
+ function hydratedCreateOptimistic(fn, second, third) {
285
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
286
+ markTopLevelSnapshotScope();
287
+ const ssrSource = third?.ssrSource;
288
+ if (ssrSource === "client") {
289
+ const [hydrated, setHydrated] = signals.createSignal(false);
290
+ const sig = signals.createOptimistic(prev => {
291
+ if (!hydrated()) return prev ?? second;
292
+ return fn(prev);
293
+ }, second, third);
294
+ setHydrated(true);
295
+ return sig;
296
+ }
297
+ if (ssrSource === "initial") {
298
+ return signals.createOptimistic(prev => {
299
+ if (!sharedConfig.hydrating) return fn(prev);
300
+ subFetch(fn, prev);
301
+ return prev ?? second;
302
+ }, second, third);
303
+ }
304
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
305
+ if (aiResult !== null) return aiResult;
306
+ return signals.createOptimistic(prev => {
307
+ const o = signals.getOwner();
308
+ if (!sharedConfig.hydrating) return fn(prev);
309
+ let initP;
310
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
311
+ const init = initP?.v ?? initP;
312
+ return init != null ? (subFetch(fn, prev), init) : fn(prev);
313
+ }, second, third);
314
+ }
315
+ function wrapStoreFn(fn, ssrSource) {
316
+ if (ssrSource === "initial") {
317
+ return draft => {
318
+ if (!sharedConfig.hydrating) return fn(draft);
319
+ subFetch(fn, draft);
320
+ return undefined;
321
+ };
895
322
  }
896
- for (i = 0; i < userLength; i++) runTop(queue[i]);
323
+ return draft => {
324
+ const o = signals.getOwner();
325
+ if (!sharedConfig.hydrating) return fn(draft);
326
+ let initP;
327
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
328
+ const init = initP?.v ?? initP;
329
+ return init != null ? (subFetch(fn, draft), init) : fn(draft);
330
+ };
897
331
  }
898
- function lookUpstream(node, ignore) {
899
- const runningTransition = Transition && Transition.running;
900
- if (runningTransition) node.tState = 0;else node.state = 0;
901
- for (let i = 0; i < node.sources.length; i += 1) {
902
- const source = node.sources[i];
903
- if (source.sources) {
904
- const state = runningTransition ? source.tState : source.state;
905
- if (state === STALE) {
906
- if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source);
907
- } else if (state === PENDING) lookUpstream(source, ignore);
908
- }
909
- }
332
+ function hydratedCreateStore(first, second, third) {
333
+ if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
334
+ markTopLevelSnapshotScope();
335
+ const ssrSource = third?.ssrSource;
336
+ if (ssrSource === "client" || ssrSource === "initial") {
337
+ return signals.createStore(second ?? {}, undefined, third);
338
+ }
339
+ const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, second ?? {}, third);
340
+ if (aiResult !== null) return aiResult;
341
+ return signals.createStore(wrapStoreFn(first, ssrSource), second, third);
342
+ }
343
+ function hydratedCreateOptimisticStore(first, second, third) {
344
+ if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
345
+ markTopLevelSnapshotScope();
346
+ const ssrSource = third?.ssrSource;
347
+ if (ssrSource === "client" || ssrSource === "initial") {
348
+ return signals.createOptimisticStore(second ?? {}, undefined, third);
349
+ }
350
+ const aiResult = hydrateStoreFromAsyncIterable(signals.createOptimisticStore, second ?? {}, third);
351
+ if (aiResult !== null) return aiResult;
352
+ return signals.createOptimisticStore(wrapStoreFn(first, ssrSource), second, third);
353
+ }
354
+ function hydratedCreateProjection(fn, initialValue, options) {
355
+ if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
356
+ markTopLevelSnapshotScope();
357
+ const ssrSource = options?.ssrSource;
358
+ if (ssrSource === "client" || ssrSource === "initial") {
359
+ return signals.createProjection(draft => draft, initialValue, options);
360
+ }
361
+ const aiResult = hydrateStoreFromAsyncIterable(signals.createStore, initialValue, options);
362
+ if (aiResult !== null) return aiResult[0];
363
+ return signals.createProjection(wrapStoreFn(fn, ssrSource), initialValue, options);
364
+ }
365
+ function hydratedEffect(coreFn, compute, effectFn, value, options) {
366
+ if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
367
+ const ssrSource = options?.ssrSource;
368
+ if (ssrSource === "client") {
369
+ const [hydrated, setHydrated] = signals.createSignal(false);
370
+ let active = false;
371
+ coreFn(prev => {
372
+ if (!hydrated()) return value;
373
+ active = true;
374
+ return compute(prev);
375
+ }, (next, prev) => {
376
+ if (!active) return;
377
+ return effectFn(next, prev);
378
+ }, value, options);
379
+ setHydrated(true);
380
+ return;
381
+ }
382
+ if (ssrSource === "initial") {
383
+ coreFn(prev => {
384
+ if (!sharedConfig.hydrating) return compute(prev);
385
+ subFetch(compute, prev);
386
+ return prev ?? value;
387
+ }, effectFn, value, options);
388
+ return;
389
+ }
390
+ markTopLevelSnapshotScope();
391
+ coreFn(prev => {
392
+ const o = signals.getOwner();
393
+ if (!sharedConfig.hydrating) return compute(prev);
394
+ let initP;
395
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
396
+ const init = initP?.v ?? initP;
397
+ return init != null ? (subFetch(compute, prev), init) : compute(prev);
398
+ }, effectFn, value, options);
399
+ }
400
+ function hydratedCreateRenderEffect(compute, effectFn, value, options) {
401
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
402
+ }
403
+ function hydratedCreateEffect(compute, effectFn, value, options) {
404
+ return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
910
405
  }
911
- function markDownstream(node) {
912
- const runningTransition = Transition && Transition.running;
913
- for (let i = 0; i < node.observers.length; i += 1) {
914
- const o = node.observers[i];
915
- if (runningTransition ? !o.tState : !o.state) {
916
- if (runningTransition) o.tState = PENDING;else o.state = PENDING;
917
- if (o.pure) Updates.push(o);else Effects.push(o);
918
- o.observers && markDownstream(o);
919
- }
920
- }
921
- }
922
- function cleanNode(node) {
923
- let i;
924
- if (node.sources) {
925
- while (node.sources.length) {
926
- const source = node.sources.pop(),
927
- index = node.sourceSlots.pop(),
928
- obs = source.observers;
929
- if (obs && obs.length) {
930
- const n = obs.pop(),
931
- s = source.observerSlots.pop();
932
- if (index < obs.length) {
933
- n.sourceSlots[s] = index;
934
- obs[index] = n;
935
- source.observerSlots[index] = s;
406
+ function enableHydration() {
407
+ _createMemo = hydratedCreateMemo;
408
+ _createSignal = hydratedCreateSignal;
409
+ _createErrorBoundary = hydratedCreateErrorBoundary;
410
+ _createOptimistic = hydratedCreateOptimistic;
411
+ _createProjection = hydratedCreateProjection;
412
+ _createStore = hydratedCreateStore;
413
+ _createOptimisticStore = hydratedCreateOptimisticStore;
414
+ _createRenderEffect = hydratedCreateRenderEffect;
415
+ _createEffect = hydratedCreateEffect;
416
+ _hydratingValue = sharedConfig.hydrating;
417
+ _doneValue = sharedConfig.done;
418
+ Object.defineProperty(sharedConfig, "hydrating", {
419
+ get() {
420
+ return _hydratingValue;
421
+ },
422
+ set(v) {
423
+ const was = _hydratingValue;
424
+ _hydratingValue = v;
425
+ if (!was && v) {
426
+ _hydrationDone = false;
427
+ _doneValue = false;
428
+ _pendingBoundaries = 0;
429
+ signals.setSnapshotCapture(true);
430
+ _snapshotRootOwner = null;
431
+ } else if (was && !v) {
432
+ if (_snapshotRootOwner) {
433
+ signals.releaseSnapshotScope(_snapshotRootOwner);
434
+ _snapshotRootOwner = null;
936
435
  }
436
+ checkHydrationComplete();
937
437
  }
938
- }
939
- }
940
- if (node.tOwned) {
941
- for (i = node.tOwned.length - 1; i >= 0; i--) cleanNode(node.tOwned[i]);
942
- delete node.tOwned;
943
- }
944
- if (Transition && Transition.running && node.pure) {
945
- reset(node, true);
946
- } else if (node.owned) {
947
- for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
948
- node.owned = null;
949
- }
950
- if (node.cleanups) {
951
- for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
952
- node.cleanups = null;
953
- }
954
- if (Transition && Transition.running) node.tState = 0;else node.state = 0;
955
- }
956
- function reset(node, top) {
957
- if (!top) {
958
- node.tState = 0;
959
- Transition.disposed.add(node);
960
- }
961
- if (node.owned) {
962
- for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
963
- }
964
- }
965
- function castError(err) {
966
- if (err instanceof Error) return err;
967
- return new Error(typeof err === "string" ? err : "Unknown error", {
968
- cause: err
438
+ },
439
+ configurable: true,
440
+ enumerable: true
969
441
  });
970
- }
971
- function runErrors(err, fns, owner) {
972
- try {
973
- for (const f of fns) f(err);
974
- } catch (e) {
975
- handleError(e, owner && owner.owner || null);
976
- }
977
- }
978
- function handleError(err, owner = Owner) {
979
- const fns = ERROR && owner && owner.context && owner.context[ERROR];
980
- const error = castError(err);
981
- if (!fns) throw error;
982
- if (Effects) Effects.push({
983
- fn() {
984
- runErrors(error, fns, owner);
442
+ Object.defineProperty(sharedConfig, "done", {
443
+ get() {
444
+ return _doneValue;
985
445
  },
986
- state: STALE
987
- });else runErrors(error, fns, owner);
988
- }
989
- function resolveChildren(children) {
990
- if (typeof children === "function" && !children.length) return resolveChildren(children());
991
- if (Array.isArray(children)) {
992
- const results = [];
993
- for (let i = 0; i < children.length; i++) {
994
- const result = resolveChildren(children[i]);
995
- Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
996
- }
997
- return results;
998
- }
999
- return children;
1000
- }
1001
- function createProvider(id, options) {
1002
- return function provider(props) {
1003
- let res;
1004
- createRenderEffect(() => res = untrack(() => {
1005
- Owner.context = {
1006
- ...Owner.context,
1007
- [id]: props.value
1008
- };
1009
- return children(() => props.children);
1010
- }), undefined);
1011
- return res;
1012
- };
1013
- }
1014
- function onError(fn) {
1015
- ERROR || (ERROR = Symbol("error"));
1016
- if (Owner === null) ;else if (Owner.context === null || !Owner.context[ERROR]) {
1017
- Owner.context = {
1018
- ...Owner.context,
1019
- [ERROR]: [fn]
1020
- };
1021
- mutateContext(Owner, ERROR, [fn]);
1022
- } else Owner.context[ERROR].push(fn);
1023
- }
1024
- function mutateContext(o, key, value) {
1025
- if (o.owned) {
1026
- for (let i = 0; i < o.owned.length; i++) {
1027
- if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
1028
- if (!o.owned[i].context) {
1029
- o.owned[i].context = o.context;
1030
- mutateContext(o.owned[i], key, value);
1031
- } else if (!o.owned[i].context[key]) {
1032
- o.owned[i].context[key] = value;
1033
- mutateContext(o.owned[i], key, value);
1034
- }
1035
- }
1036
- }
446
+ set(v) {
447
+ _doneValue = v;
448
+ if (v) drainHydrationCallbacks();
449
+ },
450
+ configurable: true,
451
+ enumerable: true
452
+ });
1037
453
  }
1038
-
1039
- function observable(input) {
1040
- return {
1041
- subscribe(observer) {
1042
- if (!(observer instanceof Object) || observer == null) {
1043
- throw new TypeError("Expected the observer to be an object.");
1044
- }
1045
- const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
1046
- if (!handler) {
1047
- return {
1048
- unsubscribe() {}
1049
- };
1050
- }
1051
- const dispose = createRoot(disposer => {
1052
- createEffect(() => {
1053
- const v = input();
1054
- untrack(() => handler(v));
1055
- });
1056
- return disposer;
454
+ const createMemo = (...args) => (_createMemo || signals.createMemo)(...args);
455
+ const createSignal = (...args) => (_createSignal || signals.createSignal)(...args);
456
+ const createErrorBoundary = (...args) => (_createErrorBoundary || signals.createErrorBoundary)(...args);
457
+ const createOptimistic = (...args) => (_createOptimistic || signals.createOptimistic)(...args);
458
+ const createProjection = (...args) => (_createProjection || signals.createProjection)(...args);
459
+ const createStore = (...args) => (_createStore || signals.createStore)(...args);
460
+ const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
461
+ const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
462
+ const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
463
+ function loadModuleAssets(mapping) {
464
+ const hy = globalThis._$HY;
465
+ if (!hy) return;
466
+ if (!hy.modules) hy.modules = {};
467
+ if (!hy.loading) hy.loading = {};
468
+ const pending = [];
469
+ for (const moduleUrl in mapping) {
470
+ if (hy.modules[moduleUrl]) continue;
471
+ const entryUrl = mapping[moduleUrl];
472
+ if (!hy.loading[moduleUrl]) {
473
+ hy.loading[moduleUrl] = import(entryUrl).then(mod => {
474
+ hy.modules[moduleUrl] = mod;
1057
475
  });
1058
- if (getOwner()) onCleanup(dispose);
1059
- return {
1060
- unsubscribe() {
1061
- dispose();
1062
- }
1063
- };
1064
- },
1065
- [Symbol.observable || "@@observable"]() {
1066
- return this;
1067
476
  }
1068
- };
477
+ pending.push(hy.loading[moduleUrl]);
478
+ }
479
+ return pending.length ? Promise.all(pending).then(() => {}) : undefined;
1069
480
  }
1070
- function from(producer, initalValue = undefined) {
1071
- const [s, set] = createSignal(initalValue, {
481
+ function createBoundaryTrigger() {
482
+ signals.setSnapshotCapture(false);
483
+ const [s, set] = signals.createSignal(undefined, {
1072
484
  equals: false
1073
485
  });
1074
- if ("subscribe" in producer) {
1075
- const unsub = producer.subscribe(v => set(() => v));
1076
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
1077
- } else {
1078
- const clean = producer(set);
1079
- onCleanup(clean);
1080
- }
1081
- return s;
1082
- }
1083
-
1084
- const FALLBACK = Symbol("fallback");
1085
- function dispose(d) {
1086
- for (let i = 0; i < d.length; i++) d[i]();
1087
- }
1088
- function mapArray(list, mapFn, options = {}) {
1089
- let items = [],
1090
- mapped = [],
1091
- disposers = [],
1092
- len = 0,
1093
- indexes = mapFn.length > 1 ? [] : null;
1094
- onCleanup(() => dispose(disposers));
1095
- return () => {
1096
- let newItems = list() || [],
1097
- newLen = newItems.length,
1098
- i,
1099
- j;
1100
- newItems[$TRACK];
1101
- return untrack(() => {
1102
- let newIndices, newIndicesNext, temp, tempdisposers, tempIndexes, start, end, newEnd, item;
1103
- if (newLen === 0) {
1104
- if (len !== 0) {
1105
- dispose(disposers);
1106
- disposers = [];
1107
- items = [];
1108
- mapped = [];
1109
- len = 0;
1110
- indexes && (indexes = []);
1111
- }
1112
- if (options.fallback) {
1113
- items = [FALLBACK];
1114
- mapped[0] = createRoot(disposer => {
1115
- disposers[0] = disposer;
1116
- return options.fallback();
1117
- });
1118
- len = 1;
1119
- }
486
+ s();
487
+ signals.setSnapshotCapture(true);
488
+ return set;
489
+ }
490
+ function resumeBoundaryHydration(o, id, set) {
491
+ _pendingBoundaries--;
492
+ if (signals.isDisposed(o)) {
493
+ checkHydrationComplete();
494
+ return;
495
+ }
496
+ sharedConfig.gather(id);
497
+ _hydratingValue = true;
498
+ signals.markSnapshotScope(o);
499
+ _snapshotRootOwner = o;
500
+ set();
501
+ signals.flush();
502
+ _snapshotRootOwner = null;
503
+ _hydratingValue = false;
504
+ signals.releaseSnapshotScope(o);
505
+ signals.flush();
506
+ checkHydrationComplete();
507
+ }
508
+ function Loading(props) {
509
+ if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
510
+ return signals.createMemo(() => {
511
+ const o = signals.getOwner();
512
+ const id = o.id;
513
+ let assetPromise;
514
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
515
+ const mapping = sharedConfig.load(id + "_assets");
516
+ if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
517
+ }
518
+ if (sharedConfig.hydrating && sharedConfig.has(id)) {
519
+ let ref = sharedConfig.load(id);
520
+ let p;
521
+ if (ref) {
522
+ if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
1120
523
  }
1121
- else if (len === 0) {
1122
- mapped = new Array(newLen);
1123
- for (j = 0; j < newLen; j++) {
1124
- items[j] = newItems[j];
1125
- mapped[j] = createRoot(mapper);
1126
- }
1127
- len = newLen;
1128
- } else {
1129
- temp = new Array(newLen);
1130
- tempdisposers = new Array(newLen);
1131
- indexes && (tempIndexes = new Array(newLen));
1132
- for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++);
1133
- for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) {
1134
- temp[newEnd] = mapped[end];
1135
- tempdisposers[newEnd] = disposers[end];
1136
- indexes && (tempIndexes[newEnd] = indexes[end]);
1137
- }
1138
- newIndices = new Map();
1139
- newIndicesNext = new Array(newEnd + 1);
1140
- for (j = newEnd; j >= start; j--) {
1141
- item = newItems[j];
1142
- i = newIndices.get(item);
1143
- newIndicesNext[j] = i === undefined ? -1 : i;
1144
- newIndices.set(item, j);
1145
- }
1146
- for (i = start; i <= end; i++) {
1147
- item = items[i];
1148
- j = newIndices.get(item);
1149
- if (j !== undefined && j !== -1) {
1150
- temp[j] = mapped[i];
1151
- tempdisposers[j] = disposers[i];
1152
- indexes && (tempIndexes[j] = indexes[i]);
1153
- j = newIndicesNext[j];
1154
- newIndices.set(item, j);
1155
- } else disposers[i]();
1156
- }
1157
- for (j = start; j < newLen; j++) {
1158
- if (j in temp) {
1159
- mapped[j] = temp[j];
1160
- disposers[j] = tempdisposers[j];
1161
- if (indexes) {
1162
- indexes[j] = tempIndexes[j];
1163
- indexes[j](j);
1164
- }
1165
- } else mapped[j] = createRoot(mapper);
1166
- }
1167
- mapped = mapped.slice(0, len = newLen);
1168
- items = newItems.slice(0);
1169
- }
1170
- return mapped;
1171
- });
1172
- function mapper(disposer) {
1173
- disposers[j] = disposer;
1174
- if (indexes) {
1175
- const [s, set] = createSignal(j);
1176
- indexes[j] = set;
1177
- return mapFn(newItems[j], s);
1178
- }
1179
- return mapFn(newItems[j]);
1180
- }
1181
- };
1182
- }
1183
- function indexArray(list, mapFn, options = {}) {
1184
- let items = [],
1185
- mapped = [],
1186
- disposers = [],
1187
- signals = [],
1188
- len = 0,
1189
- i;
1190
- onCleanup(() => dispose(disposers));
1191
- return () => {
1192
- const newItems = list() || [],
1193
- newLen = newItems.length;
1194
- newItems[$TRACK];
1195
- return untrack(() => {
1196
- if (newLen === 0) {
1197
- if (len !== 0) {
1198
- dispose(disposers);
1199
- disposers = [];
1200
- items = [];
1201
- mapped = [];
1202
- len = 0;
1203
- signals = [];
1204
- }
1205
- if (options.fallback) {
1206
- items = [FALLBACK];
1207
- mapped[0] = createRoot(disposer => {
1208
- disposers[0] = disposer;
1209
- return options.fallback();
524
+ if (p) {
525
+ _pendingBoundaries++;
526
+ signals.onCleanup(() => {
527
+ if (!signals.isDisposed(o)) return;
528
+ sharedConfig.cleanupFragment?.(id);
529
+ });
530
+ const set = createBoundaryTrigger();
531
+ if (p !== "$$f") {
532
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
533
+ waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
534
+ _pendingBoundaries--;
535
+ checkHydrationComplete();
536
+ signals.runWithOwner(o, () => {
537
+ throw err;
538
+ });
1210
539
  });
1211
- len = 1;
1212
- }
1213
- return mapped;
1214
- }
1215
- if (items[0] === FALLBACK) {
1216
- disposers[0]();
1217
- disposers = [];
1218
- items = [];
1219
- mapped = [];
1220
- len = 0;
1221
- }
1222
- for (i = 0; i < newLen; i++) {
1223
- if (i < items.length && items[i] !== newItems[i]) {
1224
- signals[i](() => newItems[i]);
1225
- } else if (i >= items.length) {
1226
- mapped[i] = createRoot(mapper);
540
+ } else {
541
+ const afterAssets = () => {
542
+ _pendingBoundaries--;
543
+ set();
544
+ checkHydrationComplete();
545
+ };
546
+ if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
1227
547
  }
548
+ return props.fallback;
1228
549
  }
1229
- for (; i < items.length; i++) {
1230
- disposers[i]();
1231
- }
1232
- len = signals.length = disposers.length = newLen;
1233
- items = newItems.slice(0);
1234
- return mapped = mapped.slice(0, len);
1235
- });
1236
- function mapper(disposer) {
1237
- disposers[i] = disposer;
1238
- const [s, set] = createSignal(newItems[i]);
1239
- signals[i] = set;
1240
- return mapFn(s, i);
1241
550
  }
1242
- };
551
+ if (assetPromise) {
552
+ _pendingBoundaries++;
553
+ const set = createBoundaryTrigger();
554
+ assetPromise.then(() => resumeBoundaryHydration(o, id, set));
555
+ return undefined;
556
+ }
557
+ return signals.createLoadBoundary(() => props.children, () => props.fallback);
558
+ });
1243
559
  }
1244
560
 
1245
- let hydrationEnabled = false;
1246
- function enableHydration() {
1247
- hydrationEnabled = true;
1248
- }
1249
561
  function createComponent(Comp, props) {
1250
- if (hydrationEnabled) {
1251
- if (sharedConfig.context) {
1252
- const c = sharedConfig.context;
1253
- setHydrateContext(nextHydrateContext());
1254
- const r = untrack(() => Comp(props || {}));
1255
- setHydrateContext(c);
1256
- return r;
1257
- }
1258
- }
1259
- return untrack(() => Comp(props || {}));
1260
- }
1261
- function trueFn() {
1262
- return true;
1263
- }
1264
- const propTraps = {
1265
- get(_, property, receiver) {
1266
- if (property === $PROXY) return receiver;
1267
- return _.get(property);
1268
- },
1269
- has(_, property) {
1270
- if (property === $PROXY) return true;
1271
- return _.has(property);
1272
- },
1273
- set: trueFn,
1274
- deleteProperty: trueFn,
1275
- getOwnPropertyDescriptor(_, property) {
1276
- return {
1277
- configurable: true,
1278
- enumerable: true,
1279
- get() {
1280
- return _.get(property);
1281
- },
1282
- set: trueFn,
1283
- deleteProperty: trueFn
1284
- };
1285
- },
1286
- ownKeys(_) {
1287
- return _.keys();
1288
- }
1289
- };
1290
- function resolveSource(s) {
1291
- return !(s = typeof s === "function" ? s() : s) ? {} : s;
1292
- }
1293
- function resolveSources() {
1294
- for (let i = 0, length = this.length; i < length; ++i) {
1295
- const v = this[i]();
1296
- if (v !== undefined) return v;
1297
- }
1298
- }
1299
- function mergeProps(...sources) {
1300
- let proxy = false;
1301
- for (let i = 0; i < sources.length; i++) {
1302
- const s = sources[i];
1303
- proxy = proxy || !!s && $PROXY in s;
1304
- sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s;
1305
- }
1306
- if (SUPPORTS_PROXY && proxy) {
1307
- return new Proxy({
1308
- get(property) {
1309
- for (let i = sources.length - 1; i >= 0; i--) {
1310
- const v = resolveSource(sources[i])[property];
1311
- if (v !== undefined) return v;
1312
- }
1313
- },
1314
- has(property) {
1315
- for (let i = sources.length - 1; i >= 0; i--) {
1316
- if (property in resolveSource(sources[i])) return true;
1317
- }
1318
- return false;
1319
- },
1320
- keys() {
1321
- const keys = [];
1322
- for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
1323
- return [...new Set(keys)];
1324
- }
1325
- }, propTraps);
1326
- }
1327
- const sourcesMap = {};
1328
- const defined = Object.create(null);
1329
- for (let i = sources.length - 1; i >= 0; i--) {
1330
- const source = sources[i];
1331
- if (!source) continue;
1332
- const sourceKeys = Object.getOwnPropertyNames(source);
1333
- for (let i = sourceKeys.length - 1; i >= 0; i--) {
1334
- const key = sourceKeys[i];
1335
- if (key === "__proto__" || key === "constructor") continue;
1336
- const desc = Object.getOwnPropertyDescriptor(source, key);
1337
- if (!defined[key]) {
1338
- defined[key] = desc.get ? {
1339
- enumerable: true,
1340
- configurable: true,
1341
- get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)])
1342
- } : desc.value !== undefined ? desc : undefined;
1343
- } else {
1344
- const sources = sourcesMap[key];
1345
- if (sources) {
1346
- if (desc.get) sources.push(desc.get.bind(source));else if (desc.value !== undefined) sources.push(() => desc.value);
1347
- }
1348
- }
1349
- }
1350
- }
1351
- const target = {};
1352
- const definedKeys = Object.keys(defined);
1353
- for (let i = definedKeys.length - 1; i >= 0; i--) {
1354
- const key = definedKeys[i],
1355
- desc = defined[key];
1356
- if (desc && desc.get) Object.defineProperty(target, key, desc);else target[key] = desc ? desc.value : undefined;
1357
- }
1358
- return target;
1359
- }
1360
- function splitProps(props, ...keys) {
1361
- const len = keys.length;
1362
- if (SUPPORTS_PROXY && $PROXY in props) {
1363
- const blocked = len > 1 ? keys.flat() : keys[0];
1364
- const res = keys.map(k => {
1365
- return new Proxy({
1366
- get(property) {
1367
- return k.includes(property) ? props[property] : undefined;
1368
- },
1369
- has(property) {
1370
- return k.includes(property) && property in props;
1371
- },
1372
- keys() {
1373
- return k.filter(property => property in props);
1374
- }
1375
- }, propTraps);
1376
- });
1377
- res.push(new Proxy({
1378
- get(property) {
1379
- return blocked.includes(property) ? undefined : props[property];
1380
- },
1381
- has(property) {
1382
- return blocked.includes(property) ? false : property in props;
1383
- },
1384
- keys() {
1385
- return Object.keys(props).filter(k => !blocked.includes(k));
1386
- }
1387
- }, propTraps));
1388
- return res;
1389
- }
1390
- const objects = [];
1391
- for (let i = 0; i <= len; i++) {
1392
- objects[i] = {};
1393
- }
1394
- for (const propName of Object.getOwnPropertyNames(props)) {
1395
- let keyIndex = len;
1396
- for (let i = 0; i < keys.length; i++) {
1397
- if (keys[i].includes(propName)) {
1398
- keyIndex = i;
1399
- break;
1400
- }
1401
- }
1402
- const desc = Object.getOwnPropertyDescriptor(props, propName);
1403
- const isDefaultDesc = !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable;
1404
- isDefaultDesc ? objects[keyIndex][propName] = desc.value : Object.defineProperty(objects[keyIndex], propName, desc);
1405
- }
1406
- return objects;
562
+ return signals.untrack(() => Comp(props || {}));
1407
563
  }
1408
- function lazy(fn) {
564
+ function lazy(fn, moduleUrl) {
1409
565
  let comp;
1410
566
  let p;
1411
567
  const wrap = props => {
1412
- const ctx = sharedConfig.context;
1413
- if (ctx) {
1414
- const [s, set] = createSignal();
1415
- sharedConfig.count || (sharedConfig.count = 0);
1416
- sharedConfig.count++;
1417
- (p || (p = fn())).then(mod => {
1418
- !sharedConfig.done && setHydrateContext(ctx);
1419
- sharedConfig.count--;
1420
- set(() => mod.default);
1421
- setHydrateContext();
568
+ if (sharedConfig.hydrating && moduleUrl) {
569
+ const cached = globalThis._$HY?.modules?.[moduleUrl];
570
+ if (!cached) {
571
+ throw new Error(`lazy() module "${moduleUrl}" was not preloaded before hydration. ` + "Ensure it is inside a Loading boundary.");
572
+ }
573
+ comp = () => cached.default;
574
+ }
575
+ if (!comp) {
576
+ p || (p = fn());
577
+ p.then(mod => {
578
+ comp = () => mod.default;
1422
579
  });
1423
- comp = s;
1424
- } else if (!comp) {
1425
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1426
- comp = s;
580
+ comp = signals.createMemo(() => p.then(mod => mod.default));
1427
581
  }
1428
582
  let Comp;
1429
- return createMemo(() => (Comp = comp()) ? untrack(() => {
1430
- if (IS_DEV) ;
1431
- if (!ctx || sharedConfig.done) return Comp(props);
1432
- const c = sharedConfig.context;
1433
- setHydrateContext(ctx);
1434
- const r = Comp(props);
1435
- setHydrateContext(c);
1436
- return r;
583
+ return signals.createMemo(() => (Comp = comp()) ? signals.untrack(() => {
584
+ return Comp(props);
1437
585
  }) : "");
1438
586
  };
1439
587
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
@@ -1441,317 +589,250 @@ function lazy(fn) {
1441
589
  }
1442
590
  let counter = 0;
1443
591
  function createUniqueId() {
1444
- const ctx = sharedConfig.context;
1445
- return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
592
+ return sharedConfig.hydrating ? sharedConfig.getNextContextId() : `cl-${counter++}`;
1446
593
  }
1447
594
 
1448
595
  const narrowedError = name => `Stale read from <${name}>.`;
1449
596
  function For(props) {
1450
- const fallback = "fallback" in props && {
597
+ const options = "fallback" in props ? {
598
+ keyed: props.keyed,
1451
599
  fallback: () => props.fallback
600
+ } : {
601
+ keyed: props.keyed
1452
602
  };
1453
- return createMemo(mapArray(() => props.each, props.children, fallback || undefined));
603
+ return signals.mapArray(() => props.each, props.children, options);
1454
604
  }
1455
- function Index(props) {
1456
- const fallback = "fallback" in props && {
605
+ function Repeat(props) {
606
+ const options = "fallback" in props ? {
1457
607
  fallback: () => props.fallback
1458
- };
1459
- return createMemo(indexArray(() => props.each, props.children, fallback || undefined));
608
+ } : {};
609
+ options.from = () => props.from;
610
+ return signals.repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
1460
611
  }
1461
612
  function Show(props) {
1462
613
  const keyed = props.keyed;
1463
- const conditionValue = createMemo(() => props.when, undefined, undefined);
1464
- const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
614
+ const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
615
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
1465
616
  equals: (a, b) => !a === !b
1466
617
  });
1467
- return createMemo(() => {
618
+ return signals.createMemo(() => {
1468
619
  const c = condition();
1469
620
  if (c) {
1470
621
  const child = props.children;
1471
622
  const fn = typeof child === "function" && child.length > 0;
1472
- return fn ? untrack(() => child(keyed ? c : () => {
1473
- if (!untrack(condition)) throw narrowedError("Show");
1474
- return conditionValue();
1475
- })) : child;
623
+ return fn ? signals.untrack(() => {
624
+ try {
625
+ return child(() => {
626
+ if (!signals.untrack(condition)) throw narrowedError("Show");
627
+ return conditionValue();
628
+ });
629
+ } finally {
630
+ }
631
+ }) : child;
1476
632
  }
1477
633
  return props.fallback;
1478
634
  }, undefined, undefined);
1479
635
  }
1480
636
  function Switch(props) {
1481
637
  const chs = children(() => props.children);
1482
- const switchFunc = createMemo(() => {
1483
- const ch = chs();
1484
- const mps = Array.isArray(ch) ? ch : [ch];
638
+ const switchFunc = signals.createMemo(() => {
639
+ const mps = chs.toArray();
1485
640
  let func = () => undefined;
1486
641
  for (let i = 0; i < mps.length; i++) {
1487
642
  const index = i;
1488
643
  const mp = mps[i];
1489
644
  const prevFunc = func;
1490
- const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
1491
- const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
645
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
646
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
1492
647
  equals: (a, b) => !a === !b
1493
648
  });
1494
649
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
1495
650
  }
1496
651
  return func;
1497
652
  });
1498
- return createMemo(() => {
653
+ return signals.createMemo(() => {
1499
654
  const sel = switchFunc()();
1500
655
  if (!sel) return props.fallback;
1501
656
  const [index, conditionValue, mp] = sel;
1502
657
  const child = mp.children;
1503
658
  const fn = typeof child === "function" && child.length > 0;
1504
- return fn ? untrack(() => child(mp.keyed ? conditionValue() : () => {
1505
- if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
1506
- return conditionValue();
1507
- })) : child;
659
+ return fn ? signals.untrack(() => {
660
+ try {
661
+ return child(() => {
662
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
663
+ return conditionValue();
664
+ });
665
+ } finally {
666
+ }
667
+ }) : child;
1508
668
  }, undefined, undefined);
1509
669
  }
1510
670
  function Match(props) {
1511
671
  return props;
1512
672
  }
1513
- let Errors;
1514
- function resetErrorBoundaries() {
1515
- Errors && [...Errors].forEach(fn => fn());
1516
- }
1517
- function ErrorBoundary(props) {
1518
- let err;
1519
- if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.getContextId());
1520
- const [errored, setErrored] = createSignal(err, undefined);
1521
- Errors || (Errors = new Set());
1522
- Errors.add(setErrored);
1523
- onCleanup(() => Errors.delete(setErrored));
1524
- return createMemo(() => {
1525
- let e;
1526
- if (e = errored()) {
1527
- const f = props.fallback;
1528
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f;
1529
- }
1530
- return catchError(() => props.children, setErrored);
1531
- }, undefined, undefined);
1532
- }
1533
-
1534
- const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback;
1535
- const SuspenseListContext = /* #__PURE__ */createContext();
1536
- function SuspenseList(props) {
1537
- let [wrapper, setWrapper] = createSignal(() => ({
1538
- inFallback: false
1539
- })),
1540
- show;
1541
- const listContext = useContext(SuspenseListContext);
1542
- const [registry, setRegistry] = createSignal([]);
1543
- if (listContext) {
1544
- show = listContext.register(createMemo(() => wrapper()().inFallback));
1545
- }
1546
- const resolved = createMemo(prev => {
1547
- const reveal = props.revealOrder,
1548
- tail = props.tail,
1549
- {
1550
- showContent = true,
1551
- showFallback = true
1552
- } = show ? show() : {},
1553
- reg = registry(),
1554
- reverse = reveal === "backwards";
1555
- if (reveal === "together") {
1556
- const all = reg.every(inFallback => !inFallback());
1557
- const res = reg.map(() => ({
1558
- showContent: all && showContent,
1559
- showFallback
1560
- }));
1561
- res.inFallback = !all;
1562
- return res;
1563
- }
1564
- let stop = false;
1565
- let inFallback = prev.inFallback;
1566
- const res = [];
1567
- for (let i = 0, len = reg.length; i < len; i++) {
1568
- const n = reverse ? len - i - 1 : i,
1569
- s = reg[n]();
1570
- if (!stop && !s) {
1571
- res[n] = {
1572
- showContent,
1573
- showFallback
1574
- };
1575
- } else {
1576
- const next = !stop;
1577
- if (next) inFallback = true;
1578
- res[n] = {
1579
- showContent: next,
1580
- showFallback: !tail || next && tail === "collapsed" ? showFallback : false
1581
- };
1582
- stop = true;
1583
- }
1584
- }
1585
- if (!stop) inFallback = false;
1586
- res.inFallback = inFallback;
1587
- return res;
1588
- }, {
1589
- inFallback: false
1590
- });
1591
- setWrapper(() => resolved);
1592
- return createComponent(SuspenseListContext.Provider, {
1593
- value: {
1594
- register: inFallback => {
1595
- let index;
1596
- setRegistry(registry => {
1597
- index = registry.length;
1598
- return [...registry, inFallback];
1599
- });
1600
- return createMemo(() => resolved()[index], undefined, {
1601
- equals: suspenseListEquals
1602
- });
1603
- }
1604
- },
1605
- get children() {
1606
- return props.children;
1607
- }
1608
- });
1609
- }
1610
- function Suspense(props) {
1611
- let counter = 0,
1612
- show,
1613
- ctx,
1614
- p,
1615
- flicker,
1616
- error;
1617
- const [inFallback, setFallback] = createSignal(false),
1618
- SuspenseContext = getSuspenseContext(),
1619
- store = {
1620
- increment: () => {
1621
- if (++counter === 1) setFallback(true);
1622
- },
1623
- decrement: () => {
1624
- if (--counter === 0) setFallback(false);
1625
- },
1626
- inFallback,
1627
- effects: [],
1628
- resolved: false
1629
- },
1630
- owner = getOwner();
1631
- if (sharedConfig.context && sharedConfig.load) {
1632
- const key = sharedConfig.getContextId();
1633
- let ref = sharedConfig.load(key);
1634
- if (ref) {
1635
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(key);
1636
- }
1637
- if (p && p !== "$$f") {
1638
- const [s, set] = createSignal(undefined, {
1639
- equals: false
1640
- });
1641
- flicker = s;
1642
- p.then(() => {
1643
- if (sharedConfig.done) return set();
1644
- sharedConfig.gather(key);
1645
- setHydrateContext(ctx);
1646
- set();
1647
- setHydrateContext();
1648
- }, err => {
1649
- error = err;
1650
- set();
1651
- });
1652
- }
1653
- }
1654
- const listContext = useContext(SuspenseListContext);
1655
- if (listContext) show = listContext.register(store.inFallback);
1656
- let dispose;
1657
- onCleanup(() => dispose && dispose());
1658
- return createComponent(SuspenseContext.Provider, {
1659
- value: store,
1660
- get children() {
1661
- return createMemo(() => {
1662
- if (error) throw error;
1663
- ctx = sharedConfig.context;
1664
- if (flicker) {
1665
- flicker();
1666
- return flicker = undefined;
1667
- }
1668
- if (ctx && p === "$$f") setHydrateContext();
1669
- const rendered = createMemo(() => props.children);
1670
- return createMemo(prev => {
1671
- const inFallback = store.inFallback(),
1672
- {
1673
- showContent = true,
1674
- showFallback = true
1675
- } = show ? show() : {};
1676
- if ((!inFallback || p && p !== "$$f") && showContent) {
1677
- store.resolved = true;
1678
- dispose && dispose();
1679
- dispose = ctx = p = undefined;
1680
- resumeEffects(store.effects);
1681
- return rendered();
1682
- }
1683
- if (!showFallback) return;
1684
- if (dispose) return prev;
1685
- return createRoot(disposer => {
1686
- dispose = disposer;
1687
- if (ctx) {
1688
- setHydrateContext({
1689
- id: ctx.id + "F",
1690
- count: 0
1691
- });
1692
- ctx = undefined;
1693
- }
1694
- return props.fallback;
1695
- }, owner);
1696
- });
1697
- });
1698
- }
673
+ function Errored(props) {
674
+ return createErrorBoundary(() => props.children, (err, reset) => {
675
+ const f = props.fallback;
676
+ return typeof f === "function" && f.length ? f(err, reset) : f;
1699
677
  });
1700
678
  }
1701
679
 
680
+ function ssrHandleError() {}
681
+ function ssrRunInScope() {}
1702
682
  const DEV = undefined;
1703
683
 
684
+ Object.defineProperty(exports, "$PROXY", {
685
+ enumerable: true,
686
+ get: function () { return signals.$PROXY; }
687
+ });
688
+ Object.defineProperty(exports, "$TRACK", {
689
+ enumerable: true,
690
+ get: function () { return signals.$TRACK; }
691
+ });
692
+ Object.defineProperty(exports, "NotReadyError", {
693
+ enumerable: true,
694
+ get: function () { return signals.NotReadyError; }
695
+ });
696
+ Object.defineProperty(exports, "action", {
697
+ enumerable: true,
698
+ get: function () { return signals.action; }
699
+ });
700
+ Object.defineProperty(exports, "createOwner", {
701
+ enumerable: true,
702
+ get: function () { return signals.createOwner; }
703
+ });
704
+ Object.defineProperty(exports, "createReaction", {
705
+ enumerable: true,
706
+ get: function () { return signals.createReaction; }
707
+ });
708
+ Object.defineProperty(exports, "createRoot", {
709
+ enumerable: true,
710
+ get: function () { return signals.createRoot; }
711
+ });
712
+ Object.defineProperty(exports, "createTrackedEffect", {
713
+ enumerable: true,
714
+ get: function () { return signals.createTrackedEffect; }
715
+ });
716
+ Object.defineProperty(exports, "deep", {
717
+ enumerable: true,
718
+ get: function () { return signals.deep; }
719
+ });
720
+ Object.defineProperty(exports, "flatten", {
721
+ enumerable: true,
722
+ get: function () { return signals.flatten; }
723
+ });
724
+ Object.defineProperty(exports, "flush", {
725
+ enumerable: true,
726
+ get: function () { return signals.flush; }
727
+ });
728
+ Object.defineProperty(exports, "getNextChildId", {
729
+ enumerable: true,
730
+ get: function () { return signals.getNextChildId; }
731
+ });
732
+ Object.defineProperty(exports, "getObserver", {
733
+ enumerable: true,
734
+ get: function () { return signals.getObserver; }
735
+ });
736
+ Object.defineProperty(exports, "getOwner", {
737
+ enumerable: true,
738
+ get: function () { return signals.getOwner; }
739
+ });
740
+ Object.defineProperty(exports, "isEqual", {
741
+ enumerable: true,
742
+ get: function () { return signals.isEqual; }
743
+ });
744
+ Object.defineProperty(exports, "isPending", {
745
+ enumerable: true,
746
+ get: function () { return signals.isPending; }
747
+ });
748
+ Object.defineProperty(exports, "isRefreshing", {
749
+ enumerable: true,
750
+ get: function () { return signals.isRefreshing; }
751
+ });
752
+ Object.defineProperty(exports, "isWrappable", {
753
+ enumerable: true,
754
+ get: function () { return signals.isWrappable; }
755
+ });
756
+ Object.defineProperty(exports, "latest", {
757
+ enumerable: true,
758
+ get: function () { return signals.latest; }
759
+ });
760
+ Object.defineProperty(exports, "mapArray", {
761
+ enumerable: true,
762
+ get: function () { return signals.mapArray; }
763
+ });
764
+ Object.defineProperty(exports, "merge", {
765
+ enumerable: true,
766
+ get: function () { return signals.merge; }
767
+ });
768
+ Object.defineProperty(exports, "omit", {
769
+ enumerable: true,
770
+ get: function () { return signals.omit; }
771
+ });
772
+ Object.defineProperty(exports, "onCleanup", {
773
+ enumerable: true,
774
+ get: function () { return signals.onCleanup; }
775
+ });
776
+ Object.defineProperty(exports, "onSettled", {
777
+ enumerable: true,
778
+ get: function () { return signals.onSettled; }
779
+ });
780
+ Object.defineProperty(exports, "reconcile", {
781
+ enumerable: true,
782
+ get: function () { return signals.reconcile; }
783
+ });
784
+ Object.defineProperty(exports, "refresh", {
785
+ enumerable: true,
786
+ get: function () { return signals.refresh; }
787
+ });
788
+ Object.defineProperty(exports, "repeat", {
789
+ enumerable: true,
790
+ get: function () { return signals.repeat; }
791
+ });
792
+ Object.defineProperty(exports, "resolve", {
793
+ enumerable: true,
794
+ get: function () { return signals.resolve; }
795
+ });
796
+ Object.defineProperty(exports, "runWithOwner", {
797
+ enumerable: true,
798
+ get: function () { return signals.runWithOwner; }
799
+ });
800
+ Object.defineProperty(exports, "snapshot", {
801
+ enumerable: true,
802
+ get: function () { return signals.snapshot; }
803
+ });
804
+ Object.defineProperty(exports, "storePath", {
805
+ enumerable: true,
806
+ get: function () { return signals.storePath; }
807
+ });
808
+ Object.defineProperty(exports, "untrack", {
809
+ enumerable: true,
810
+ get: function () { return signals.untrack; }
811
+ });
1704
812
  exports.$DEVCOMP = $DEVCOMP;
1705
- exports.$PROXY = $PROXY;
1706
- exports.$TRACK = $TRACK;
1707
813
  exports.DEV = DEV;
1708
- exports.ErrorBoundary = ErrorBoundary;
814
+ exports.Errored = Errored;
1709
815
  exports.For = For;
1710
- exports.Index = Index;
816
+ exports.Loading = Loading;
1711
817
  exports.Match = Match;
818
+ exports.Repeat = Repeat;
1712
819
  exports.Show = Show;
1713
- exports.Suspense = Suspense;
1714
- exports.SuspenseList = SuspenseList;
1715
820
  exports.Switch = Switch;
1716
- exports.batch = batch;
1717
- exports.cancelCallback = cancelCallback;
1718
- exports.catchError = catchError;
1719
821
  exports.children = children;
1720
822
  exports.createComponent = createComponent;
1721
- exports.createComputed = createComputed;
1722
823
  exports.createContext = createContext;
1723
- exports.createDeferred = createDeferred;
1724
824
  exports.createEffect = createEffect;
1725
825
  exports.createMemo = createMemo;
1726
- exports.createReaction = createReaction;
826
+ exports.createOptimistic = createOptimistic;
827
+ exports.createOptimisticStore = createOptimisticStore;
828
+ exports.createProjection = createProjection;
1727
829
  exports.createRenderEffect = createRenderEffect;
1728
- exports.createResource = createResource;
1729
- exports.createRoot = createRoot;
1730
- exports.createSelector = createSelector;
1731
830
  exports.createSignal = createSignal;
831
+ exports.createStore = createStore;
1732
832
  exports.createUniqueId = createUniqueId;
1733
- exports.enableExternalSource = enableExternalSource;
1734
833
  exports.enableHydration = enableHydration;
1735
- exports.enableScheduling = enableScheduling;
1736
- exports.equalFn = equalFn;
1737
- exports.from = from;
1738
- exports.getListener = getListener;
1739
- exports.getOwner = getOwner;
1740
- exports.indexArray = indexArray;
1741
834
  exports.lazy = lazy;
1742
- exports.mapArray = mapArray;
1743
- exports.mergeProps = mergeProps;
1744
- exports.observable = observable;
1745
- exports.on = on;
1746
- exports.onCleanup = onCleanup;
1747
- exports.onError = onError;
1748
- exports.onMount = onMount;
1749
- exports.requestCallback = requestCallback;
1750
- exports.resetErrorBoundaries = resetErrorBoundaries;
1751
- exports.runWithOwner = runWithOwner;
1752
835
  exports.sharedConfig = sharedConfig;
1753
- exports.splitProps = splitProps;
1754
- exports.startTransition = startTransition;
1755
- exports.untrack = untrack;
836
+ exports.ssrHandleError = ssrHandleError;
837
+ exports.ssrRunInScope = ssrRunInScope;
1756
838
  exports.useContext = useContext;
1757
- exports.useTransition = useTransition;