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