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