solid-js 1.10.0-beta.0 → 2.0.0-beta.1

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 +750 -1723
  2. package/dist/dev.js +612 -1688
  3. package/dist/server.cjs +804 -702
  4. package/dist/server.js +714 -669
  5. package/dist/solid.cjs +715 -1666
  6. package/dist/solid.js +577 -1631
  7. package/package.json +7 -151
  8. package/types/{render → client}/component.d.ts +2 -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 +92 -0
  12. package/types/index.d.ts +11 -14
  13. package/types/jsx.d.ts +1508 -1633
  14. package/types/server/component.d.ts +67 -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 +38 -0
  18. package/types/server/index.d.ts +12 -3
  19. package/types/server/shared.d.ts +46 -0
  20. package/types/server/signals.d.ts +62 -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,1587 +1,689 @@
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, createOwner, 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
 
62
+ const NoHydrateContext = {
63
+ id: Symbol("NoHydrateContext"),
64
+ defaultValue: false
65
+ };
118
66
  const sharedConfig = {
119
- context: undefined,
67
+ hydrating: false,
120
68
  registry: undefined,
121
- effects: undefined,
122
69
  done: false,
123
- getContextId() {
124
- return getContextId(this.context.count);
125
- },
126
70
  getNextContextId() {
127
- return getContextId(this.context.count++);
71
+ const o = getOwner();
72
+ if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
73
+ if (getContext(NoHydrateContext)) return undefined;
74
+ return getNextChildId(o);
128
75
  }
129
76
  };
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;
77
+ let _hydrationEndCallbacks = null;
78
+ let _pendingBoundaries = 0;
79
+ let _hydrationDone = false;
80
+ let _snapshotRootOwner = null;
81
+ function markTopLevelSnapshotScope() {
82
+ if (_snapshotRootOwner) return;
83
+ let owner = getOwner();
84
+ if (!owner) return;
85
+ while (owner._parent) owner = owner._parent;
86
+ markSnapshotScope(owner);
87
+ _snapshotRootOwner = owner;
88
+ }
89
+ function drainHydrationCallbacks() {
90
+ if (_hydrationDone) return;
91
+ _hydrationDone = true;
92
+ _doneValue = true;
93
+ clearSnapshots();
94
+ setSnapshotCapture(false);
95
+ flush();
96
+ const cbs = _hydrationEndCallbacks;
97
+ _hydrationEndCallbacks = null;
98
+ if (cbs) for (const cb of cbs) cb();
99
+ setTimeout(() => {
100
+ if (sharedConfig.verifyHydration) sharedConfig.verifyHydration();
101
+ if (globalThis._$HY) globalThis._$HY.done = true;
102
+ });
137
103
  }
138
- function nextHydrateContext() {
139
- return {
140
- ...sharedConfig.context,
141
- id: sharedConfig.getNextContextId(),
142
- count: 0
143
- };
104
+ function checkHydrationComplete() {
105
+ if (_pendingBoundaries === 0) drainHydrationCallbacks();
144
106
  }
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;
107
+ let _hydratingValue = false;
108
+ let _doneValue = false;
109
+ let _createMemo;
110
+ let _createSignal;
111
+ let _createErrorBoundary;
112
+ let _createOptimistic;
113
+ let _createProjection;
114
+ let _createStore;
115
+ let _createOptimisticStore;
116
+ let _createRenderEffect;
117
+ let _createEffect;
118
+ class MockPromise {
119
+ static all() {
120
+ return new MockPromise();
203
121
  }
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
- }
122
+ static allSettled() {
123
+ return new MockPromise();
221
124
  }
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 || {};
125
+ static any() {
126
+ return new MockPromise();
287
127
  }
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);
128
+ static race() {
129
+ return new MockPromise();
305
130
  }
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;
131
+ static reject() {
132
+ return new MockPromise();
324
133
  }
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);
134
+ static resolve() {
135
+ return new MockPromise();
333
136
  }
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;
137
+ catch() {
138
+ return new MockPromise();
351
139
  }
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));
140
+ then() {
141
+ return new MockPromise();
392
142
  }
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;
143
+ finally() {
144
+ return new MockPromise();
474
145
  }
475
146
  }
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;
147
+ function subFetch(fn, prev) {
148
+ const ogFetch = fetch;
149
+ const ogPromise = Promise;
150
+ try {
151
+ window.fetch = () => new MockPromise();
152
+ Promise = MockPromise;
153
+ const result = fn(prev);
154
+ if (result && typeof result[Symbol.asyncIterator] === "function") {
155
+ result[Symbol.asyncIterator]().next();
489
156
  }
490
- const result = untrack(() => fn(input, prevInput, prevValue));
491
- prevInput = input;
492
157
  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
158
  } 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;
159
+ window.fetch = ogFetch;
160
+ Promise = ogPromise;
161
+ }
162
+ }
163
+ function consumeFirstSync(ai) {
164
+ const iter = ai[Symbol.asyncIterator]();
165
+ const r = iter.next();
166
+ const value = !(r instanceof Promise) && !r.done ? r.value : undefined;
167
+ return [value, iter];
168
+ }
169
+ function applyPatches(target, patches) {
170
+ for (const patch of patches) {
171
+ const path = patch[0];
172
+ let current = target;
173
+ for (let i = 0; i < path.length - 1; i++) current = current[path[i]];
174
+ const key = path[path.length - 1];
175
+ if (patch.length === 1) {
176
+ Array.isArray(current) ? current.splice(key, 1) : delete current[key];
177
+ } else if (patch.length === 3) {
178
+ current.splice(key, 0, patch[1]);
179
+ } else {
180
+ current[key] = patch[1];
181
+ }
536
182
  }
537
183
  }
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;
184
+ function scheduleIteratorConsumption(iter, apply) {
185
+ const consume = () => {
186
+ while (true) {
187
+ const n = iter.next();
188
+ if (n instanceof Promise) {
189
+ n.then(r => {
190
+ if (r.done) return;
191
+ apply(r.value);
192
+ consume();
193
+ });
194
+ return;
195
+ }
196
+ if (n.done) break;
197
+ apply(n.value);
563
198
  }
564
- runUpdates(fn, false);
565
- Listener = Owner = null;
566
- return t ? t.done : undefined;
199
+ };
200
+ consume();
201
+ }
202
+ function isAsyncIterable(v) {
203
+ return v != null && typeof v[Symbol.asyncIterator] === "function";
204
+ }
205
+ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
206
+ const parent = getOwner();
207
+ const expectedId = peekNextChildId(parent);
208
+ if (!sharedConfig.has(expectedId)) return null;
209
+ const initP = sharedConfig.load(expectedId);
210
+ if (!isAsyncIterable(initP)) return null;
211
+ const [firstValue, iter] = consumeFirstSync(initP);
212
+ const [get, set] = createSignal$1(firstValue);
213
+ const result = coreFn(() => get(), firstValue, options);
214
+ scheduleIteratorConsumption(iter, v => {
215
+ set(() => v);
216
+ flush();
567
217
  });
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
218
+ return result;
219
+ }
220
+ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
221
+ const parent = getOwner();
222
+ const expectedId = peekNextChildId(parent);
223
+ if (!sharedConfig.has(expectedId)) return null;
224
+ const initP = sharedConfig.load(expectedId);
225
+ if (!isAsyncIterable(initP)) return null;
226
+ const [firstState, iter] = consumeFirstSync(initP);
227
+ const [store, setStore] = coreFn(() => {}, firstState ?? initialValue, options);
228
+ scheduleIteratorConsumption(iter, patches => {
229
+ setStore(d => {
230
+ applyPatches(d, patches);
581
231
  });
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
232
+ });
233
+ return [store, setStore];
234
+ }
235
+ function hydratedCreateMemo(compute, value, options) {
236
+ if (!sharedConfig.hydrating) return createMemo$1(compute, value, options);
237
+ markTopLevelSnapshotScope();
238
+ const ssrSource = options?.ssrSource;
239
+ if (ssrSource === "client") {
240
+ const [hydrated, setHydrated] = createSignal$1(false);
241
+ const memo = createMemo$1(prev => {
242
+ if (!hydrated()) return prev ?? value;
243
+ return compute(prev);
244
+ }, value, options);
245
+ setHydrated(true);
246
+ return memo;
247
+ }
248
+ if (ssrSource === "initial") {
249
+ return createMemo$1(prev => {
250
+ if (!sharedConfig.hydrating) return compute(prev);
251
+ subFetch(compute, prev);
252
+ return prev ?? value;
253
+ }, value, options);
254
+ }
255
+ const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, value, options);
256
+ if (aiResult !== null) return aiResult;
257
+ return createMemo$1(prev => {
258
+ const o = getOwner();
259
+ if (!sharedConfig.hydrating) return compute(prev);
260
+ let initP;
261
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
262
+ const init = initP?.v ?? initP;
263
+ return init != null ? (subFetch(compute, prev), init) : compute(prev);
264
+ }, value, options);
265
+ }
266
+ function hydratedCreateSignal(fn, second, third) {
267
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second, third);
268
+ markTopLevelSnapshotScope();
269
+ const ssrSource = third?.ssrSource;
270
+ if (ssrSource === "client") {
271
+ const [hydrated, setHydrated] = createSignal$1(false);
272
+ const sig = createSignal$1(prev => {
273
+ if (!hydrated()) return prev ?? second;
274
+ return fn(prev);
275
+ }, second, third);
276
+ setHydrated(true);
277
+ return sig;
278
+ }
279
+ if (ssrSource === "initial") {
280
+ return createSignal$1(prev => {
281
+ if (!sharedConfig.hydrating) return fn(prev);
282
+ subFetch(fn, prev);
283
+ return prev ?? second;
284
+ }, second, third);
285
+ }
286
+ const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second, third);
287
+ if (aiResult !== null) return aiResult;
288
+ return createSignal$1(prev => {
289
+ if (!sharedConfig.hydrating) return fn(prev);
290
+ const o = getOwner();
291
+ let initP;
292
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
293
+ const init = initP?.v ?? initP;
294
+ return init != null ? (subFetch(fn, prev), init) : fn(prev);
295
+ }, second, third);
296
+ }
297
+ function hydratedCreateErrorBoundary(fn, fallback) {
298
+ if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
299
+ markTopLevelSnapshotScope();
300
+ const parent = getOwner();
301
+ const expectedId = peekNextChildId(parent);
302
+ if (sharedConfig.has(expectedId)) {
303
+ const err = sharedConfig.load(expectedId);
304
+ if (err !== undefined) {
305
+ let hydrated = true;
306
+ return createErrorBoundary$1(() => {
307
+ if (hydrated) {
308
+ hydrated = false;
309
+ throw err;
310
+ }
311
+ return fn();
312
+ }, fallback);
313
+ }
314
+ }
315
+ return createErrorBoundary$1(fn, fallback);
316
+ }
317
+ function hydratedCreateOptimistic(fn, second, third) {
318
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return createOptimistic$1(fn, second, third);
319
+ markTopLevelSnapshotScope();
320
+ const ssrSource = third?.ssrSource;
321
+ if (ssrSource === "client") {
322
+ const [hydrated, setHydrated] = createSignal$1(false);
323
+ const sig = createOptimistic$1(prev => {
324
+ if (!hydrated()) return prev ?? second;
325
+ return fn(prev);
326
+ }, second, third);
327
+ setHydrated(true);
328
+ return sig;
329
+ }
330
+ if (ssrSource === "initial") {
331
+ return createOptimistic$1(prev => {
332
+ if (!sharedConfig.hydrating) return fn(prev);
333
+ subFetch(fn, prev);
334
+ return prev ?? second;
335
+ }, second, third);
336
+ }
337
+ const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second, third);
338
+ if (aiResult !== null) return aiResult;
339
+ return createOptimistic$1(prev => {
340
+ const o = getOwner();
341
+ if (!sharedConfig.hydrating) return fn(prev);
342
+ let initP;
343
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
344
+ const init = initP?.v ?? initP;
345
+ return init != null ? (subFetch(fn, prev), init) : fn(prev);
346
+ }, second, third);
347
+ }
348
+ function wrapStoreFn(fn, ssrSource) {
349
+ if (ssrSource === "initial") {
350
+ return draft => {
351
+ if (!sharedConfig.hydrating) return fn(draft);
352
+ subFetch(fn, draft);
353
+ return undefined;
650
354
  };
651
355
  }
356
+ return draft => {
357
+ const o = getOwner();
358
+ if (!sharedConfig.hydrating) return fn(draft);
359
+ let initP;
360
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
361
+ const init = initP?.v ?? initP;
362
+ return init != null ? (subFetch(fn, draft), init) : fn(draft);
363
+ };
652
364
  }
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) {
365
+ function hydratedCreateStore(first, second, third) {
366
+ if (typeof first !== "function" || !sharedConfig.hydrating) return createStore$1(first, second, third);
367
+ markTopLevelSnapshotScope();
368
+ const ssrSource = third?.ssrSource;
369
+ if (ssrSource === "client" || ssrSource === "initial") {
370
+ return createStore$1(second ?? {}, undefined, third);
371
+ }
372
+ const aiResult = hydrateStoreFromAsyncIterable(createStore$1, second ?? {}, third);
373
+ if (aiResult !== null) return aiResult;
374
+ return createStore$1(wrapStoreFn(first, ssrSource), second, third);
375
+ }
376
+ function hydratedCreateOptimisticStore(first, second, third) {
377
+ if (typeof first !== "function" || !sharedConfig.hydrating) return createOptimisticStore$1(first, second, third);
378
+ markTopLevelSnapshotScope();
379
+ const ssrSource = third?.ssrSource;
380
+ if (ssrSource === "client" || ssrSource === "initial") {
381
+ return createOptimisticStore$1(second ?? {}, undefined, third);
382
+ }
383
+ const aiResult = hydrateStoreFromAsyncIterable(createOptimisticStore$1, second ?? {}, third);
384
+ if (aiResult !== null) return aiResult;
385
+ return createOptimisticStore$1(wrapStoreFn(first, ssrSource), second, third);
386
+ }
387
+ function hydratedCreateProjection(fn, initialValue, options) {
388
+ if (!sharedConfig.hydrating) return createProjection$1(fn, initialValue, options);
389
+ markTopLevelSnapshotScope();
390
+ const ssrSource = options?.ssrSource;
391
+ if (ssrSource === "client" || ssrSource === "initial") {
392
+ return createProjection$1(draft => draft, initialValue, options);
393
+ }
394
+ const aiResult = hydrateStoreFromAsyncIterable(createStore$1, initialValue, options);
395
+ if (aiResult !== null) return aiResult[0];
396
+ return createProjection$1(wrapStoreFn(fn, ssrSource), initialValue, options);
397
+ }
398
+ function hydratedEffect(coreFn, compute, effectFn, value, options) {
399
+ if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
400
+ const ssrSource = options?.ssrSource;
401
+ if (ssrSource === "client") {
402
+ const [hydrated, setHydrated] = createSignal$1(false);
403
+ let active = false;
404
+ coreFn(prev => {
405
+ if (!hydrated()) return value;
406
+ active = true;
407
+ return compute(prev);
408
+ }, (next, prev) => {
409
+ if (!active) return;
410
+ return effectFn(next, prev);
411
+ }, value, options);
412
+ setHydrated(true);
672
413
  return;
673
414
  }
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;
415
+ if (ssrSource === "initial") {
416
+ coreFn(prev => {
417
+ if (!sharedConfig.hydrating) return compute(prev);
418
+ subFetch(compute, prev);
419
+ return prev ?? value;
420
+ }, effectFn, value, options);
679
421
  return;
680
422
  }
681
- const prevObserver = source.observersTail;
682
- if (prevObserver !== null && prevObserver.version === observer.relinkTime && prevObserver.observer === observer) {
683
- return;
684
- }
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
- }
703
- }
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
- }
423
+ markTopLevelSnapshotScope();
424
+ coreFn(prev => {
425
+ const o = getOwner();
426
+ if (!sharedConfig.hydrating) return compute(prev);
427
+ let initP;
428
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
429
+ const init = initP?.v ?? initP;
430
+ return init != null ? (subFetch(compute, prev), init) : compute(prev);
431
+ }, effectFn, value, options);
756
432
  }
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
- }
433
+ function hydratedCreateRenderEffect(compute, effectFn, value, options) {
434
+ return hydratedEffect(createRenderEffect$1, compute, effectFn, value, options);
863
435
  }
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
- }
436
+ function hydratedCreateEffect(compute, effectFn, value, options) {
437
+ return hydratedEffect(createEffect$1, compute, effectFn, value, options);
879
438
  }
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;
439
+ function enableHydration() {
440
+ _createMemo = hydratedCreateMemo;
441
+ _createSignal = hydratedCreateSignal;
442
+ _createErrorBoundary = hydratedCreateErrorBoundary;
443
+ _createOptimistic = hydratedCreateOptimistic;
444
+ _createProjection = hydratedCreateProjection;
445
+ _createStore = hydratedCreateStore;
446
+ _createOptimisticStore = hydratedCreateOptimisticStore;
447
+ _createRenderEffect = hydratedCreateRenderEffect;
448
+ _createEffect = hydratedCreateEffect;
449
+ _hydratingValue = sharedConfig.hydrating;
450
+ _doneValue = sharedConfig.done;
451
+ Object.defineProperty(sharedConfig, "hydrating", {
452
+ get() {
453
+ return _hydratingValue;
454
+ },
455
+ set(v) {
456
+ const was = _hydratingValue;
457
+ _hydratingValue = v;
458
+ if (!was && v) {
459
+ _hydrationDone = false;
460
+ _doneValue = false;
461
+ _pendingBoundaries = 0;
462
+ setSnapshotCapture(true);
463
+ _snapshotRootOwner = null;
464
+ } else if (was && !v) {
465
+ if (_snapshotRootOwner) {
466
+ releaseSnapshotScope(_snapshotRootOwner);
467
+ _snapshotRootOwner = null;
909
468
  }
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
469
+ checkHydrationComplete();
470
+ }
471
+ },
472
+ configurable: true,
473
+ enumerable: true
1064
474
  });
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);
475
+ Object.defineProperty(sharedConfig, "done", {
476
+ get() {
477
+ return _doneValue;
1080
478
  },
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
- }
479
+ set(v) {
480
+ _doneValue = v;
481
+ if (v) drainHydrationCallbacks();
482
+ },
483
+ configurable: true,
484
+ enumerable: true
485
+ });
1133
486
  }
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;
487
+ const createMemo = (...args) => (_createMemo || createMemo$1)(...args);
488
+ const createSignal = (...args) => (_createSignal || createSignal$1)(...args);
489
+ const createErrorBoundary = (...args) => (_createErrorBoundary || createErrorBoundary$1)(...args);
490
+ const createOptimistic = (...args) => (_createOptimistic || createOptimistic$1)(...args);
491
+ const createProjection = (...args) => (_createProjection || createProjection$1)(...args);
492
+ const createStore = (...args) => (_createStore || createStore$1)(...args);
493
+ const createOptimisticStore = (...args) => (_createOptimisticStore || createOptimisticStore$1)(...args);
494
+ const createRenderEffect = (...args) => (_createRenderEffect || createRenderEffect$1)(...args);
495
+ const createEffect = (...args) => (_createEffect || createEffect$1)(...args);
496
+ function loadModuleAssets(mapping) {
497
+ const hy = globalThis._$HY;
498
+ if (!hy) return;
499
+ if (!hy.modules) hy.modules = {};
500
+ if (!hy.loading) hy.loading = {};
501
+ const pending = [];
502
+ for (const moduleUrl in mapping) {
503
+ if (hy.modules[moduleUrl]) continue;
504
+ const entryUrl = mapping[moduleUrl];
505
+ if (!hy.loading[moduleUrl]) {
506
+ hy.loading[moduleUrl] = import(entryUrl).then(mod => {
507
+ hy.modules[moduleUrl] = mod;
1153
508
  });
1154
- if (getOwner()) onCleanup(dispose);
1155
- return {
1156
- unsubscribe() {
1157
- dispose();
1158
- }
1159
- };
1160
- },
1161
- [Symbol.observable || "@@observable"]() {
1162
- return this;
1163
509
  }
1164
- };
510
+ pending.push(hy.loading[moduleUrl]);
511
+ }
512
+ return pending.length ? Promise.all(pending).then(() => {}) : undefined;
1165
513
  }
1166
- function from(producer, initalValue = undefined) {
1167
- const [s, set] = createSignal(initalValue, {
514
+ function createBoundaryTrigger() {
515
+ setSnapshotCapture(false);
516
+ const [s, set] = createSignal$1(undefined, {
1168
517
  equals: false
1169
518
  });
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);
519
+ s();
520
+ setSnapshotCapture(true);
521
+ return set;
522
+ }
523
+ function resumeBoundaryHydration(o, id, set) {
524
+ _pendingBoundaries--;
525
+ if (isDisposed(o)) {
526
+ checkHydrationComplete();
527
+ return;
1176
528
  }
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
- }
529
+ sharedConfig.gather(id);
530
+ _hydratingValue = true;
531
+ markSnapshotScope(o);
532
+ _snapshotRootOwner = o;
533
+ set();
534
+ flush();
535
+ _snapshotRootOwner = null;
536
+ _hydratingValue = false;
537
+ releaseSnapshotScope(o);
538
+ flush();
539
+ checkHydrationComplete();
540
+ }
541
+ function Loading(props) {
542
+ if (!sharedConfig.hydrating) return createLoadBoundary(() => props.children, () => props.fallback);
543
+ return createMemo$1(() => {
544
+ const o = getOwner();
545
+ const id = o.id;
546
+ let assetPromise;
547
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
548
+ const mapping = sharedConfig.load(id + "_assets");
549
+ if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
550
+ }
551
+ if (sharedConfig.hydrating && sharedConfig.has(id)) {
552
+ let ref = sharedConfig.load(id);
553
+ let p;
554
+ if (ref) {
555
+ if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
1216
556
  }
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);
1276
- }
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();
557
+ if (p) {
558
+ _pendingBoundaries++;
559
+ onCleanup(() => {
560
+ if (!isDisposed(o)) return;
561
+ sharedConfig.cleanupFragment?.(id);
562
+ });
563
+ const set = createBoundaryTrigger();
564
+ if (p !== "$$f") {
565
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
566
+ waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
567
+ _pendingBoundaries--;
568
+ checkHydrationComplete();
569
+ runWithOwner(o, () => {
570
+ throw err;
571
+ });
1308
572
  });
1309
- len = 1;
573
+ } else {
574
+ const afterAssets = () => {
575
+ _pendingBoundaries--;
576
+ set();
577
+ checkHydrationComplete();
578
+ };
579
+ if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
1310
580
  }
1311
- return mapped;
1312
- }
1313
- if (items[0] === FALLBACK) {
1314
- disposers[0]();
1315
- disposers = [];
1316
- items = [];
1317
- mapped = [];
1318
- len = 0;
581
+ return props.fallback;
1319
582
  }
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
583
  }
1342
- };
1343
- }
1344
-
1345
- let hydrationEnabled = false;
1346
- function enableHydration() {
1347
- hydrationEnabled = true;
1348
- }
1349
- 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;
584
+ if (assetPromise) {
585
+ _pendingBoundaries++;
586
+ const set = createBoundaryTrigger();
587
+ assetPromise.then(() => resumeBoundaryHydration(o, id, set));
588
+ return undefined;
1357
589
  }
1358
- }
1359
- return devComponent(Comp, props || {});
1360
- }
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;
590
+ return createLoadBoundary(() => props.children, () => props.fallback);
591
+ });
1392
592
  }
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
- }
593
+ function NoHydration(props) {
594
+ const o = createOwner();
595
+ return runWithOwner(o, () => {
596
+ setContext(NoHydrateContext, true);
597
+ if (sharedConfig.hydrating) return undefined;
598
+ return props.children;
599
+ });
1398
600
  }
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;
601
+ function Hydration(props) {
602
+ return props.children;
1459
603
  }
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;
604
+
605
+ function createComponent(Comp, props) {
606
+ return devComponent(Comp, props || {});
1507
607
  }
1508
- function lazy(fn) {
608
+ function lazy(fn, moduleUrl) {
1509
609
  let comp;
1510
610
  let p;
1511
611
  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();
612
+ if (sharedConfig.hydrating && moduleUrl) {
613
+ const cached = globalThis._$HY?.modules?.[moduleUrl];
614
+ if (!cached) {
615
+ throw new Error(`lazy() module "${moduleUrl}" was not preloaded before hydration. ` + "Ensure it is inside a Loading boundary.");
616
+ }
617
+ comp = () => cached.default;
618
+ }
619
+ if (!comp) {
620
+ p || (p = fn());
621
+ p.then(mod => {
622
+ comp = () => mod.default;
1522
623
  });
1523
- comp = s;
1524
- } else if (!comp) {
1525
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1526
- comp = s;
624
+ comp = createMemo$1(() => p.then(mod => mod.default));
1527
625
  }
1528
626
  let Comp;
1529
- return createMemo(() => (Comp = comp()) ? untrack(() => {
1530
- if (IS_DEV) Object.assign(Comp, {
627
+ return createMemo$1(() => (Comp = comp()) ? untrack(() => {
628
+ Object.assign(Comp, {
1531
629
  [$DEVCOMP]: true
1532
630
  });
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;
631
+ return Comp(props);
1539
632
  }) : "");
1540
633
  };
1541
634
  wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
635
+ wrap.moduleUrl = moduleUrl;
1542
636
  return wrap;
1543
637
  }
1544
638
  let counter = 0;
1545
639
  function createUniqueId() {
1546
- const ctx = sharedConfig.context;
1547
- return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
640
+ return sharedConfig.hydrating ? sharedConfig.getNextContextId() : `cl-${counter++}`;
1548
641
  }
1549
642
 
1550
643
  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
644
  function For(props) {
1552
- const fallback = "fallback" in props && {
645
+ const options = "fallback" in props ? {
646
+ keyed: props.keyed,
1553
647
  fallback: () => props.fallback
648
+ } : {
649
+ keyed: props.keyed
1554
650
  };
1555
- return createMemo(mapArray(() => props.each, props.children, fallback || undefined), undefined, {
1556
- name: "value"
1557
- }) ;
651
+ options.name = "<For>";
652
+ return mapArray(() => props.each, props.children, options);
1558
653
  }
1559
- function Index(props) {
1560
- const fallback = "fallback" in props && {
654
+ function Repeat(props) {
655
+ const options = "fallback" in props ? {
1561
656
  fallback: () => props.fallback
1562
- };
1563
- return createMemo(indexArray(() => props.each, props.children, fallback || undefined), undefined, {
1564
- name: "value"
1565
- }) ;
657
+ } : {};
658
+ options.from = () => props.from;
659
+ options.name = "<Repeat>";
660
+ return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
1566
661
  }
1567
662
  function Show(props) {
1568
663
  const keyed = props.keyed;
1569
- const conditionValue = createMemo(() => props.when, undefined, {
664
+ const conditionValue = createMemo$1(() => props.when, undefined, {
1570
665
  name: "condition value"
1571
666
  } );
1572
- const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
667
+ const condition = keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
1573
668
  equals: (a, b) => !a === !b,
1574
669
  name: "condition"
1575
670
  } );
1576
- return createMemo(() => {
671
+ return createMemo$1(() => {
1577
672
  const c = condition();
1578
673
  if (c) {
1579
674
  const child = props.children;
1580
675
  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;
676
+ return fn ? untrack(() => {
677
+ setStrictRead("<Show>");
678
+ try {
679
+ return child(() => {
680
+ if (!untrack(condition)) throw narrowedError("Show");
681
+ return conditionValue();
682
+ });
683
+ } finally {
684
+ setStrictRead(false);
685
+ }
686
+ }) : child;
1585
687
  }
1586
688
  return props.fallback;
1587
689
  }, undefined, {
@@ -1590,18 +692,17 @@ function Show(props) {
1590
692
  }
1591
693
  function Switch(props) {
1592
694
  const chs = children(() => props.children);
1593
- const switchFunc = createMemo(() => {
1594
- const ch = chs();
1595
- const mps = Array.isArray(ch) ? ch : [ch];
695
+ const switchFunc = createMemo$1(() => {
696
+ const mps = chs.toArray();
1596
697
  let func = () => undefined;
1597
698
  for (let i = 0; i < mps.length; i++) {
1598
699
  const index = i;
1599
700
  const mp = mps[i];
1600
701
  const prevFunc = func;
1601
- const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
702
+ const conditionValue = createMemo$1(() => prevFunc() ? undefined : mp.when, undefined, {
1602
703
  name: "condition value"
1603
704
  } );
1604
- const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
705
+ const condition = mp.keyed ? conditionValue : createMemo$1(conditionValue, undefined, {
1605
706
  equals: (a, b) => !a === !b,
1606
707
  name: "condition"
1607
708
  } );
@@ -1609,16 +710,23 @@ function Switch(props) {
1609
710
  }
1610
711
  return func;
1611
712
  });
1612
- return createMemo(() => {
713
+ return createMemo$1(() => {
1613
714
  const sel = switchFunc()();
1614
715
  if (!sel) return props.fallback;
1615
716
  const [index, conditionValue, mp] = sel;
1616
717
  const child = mp.children;
1617
718
  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;
719
+ return fn ? untrack(() => {
720
+ setStrictRead("<Match>");
721
+ try {
722
+ return child(() => {
723
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
724
+ return conditionValue();
725
+ });
726
+ } finally {
727
+ setStrictRead(false);
728
+ }
729
+ }) : child;
1622
730
  }, undefined, {
1623
731
  name: "eval conditions"
1624
732
  } );
@@ -1626,207 +734,23 @@ function Switch(props) {
1626
734
  function Match(props) {
1627
735
  return props;
1628
736
  }
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
- }
737
+ function Errored(props) {
738
+ return createErrorBoundary(() => props.children, (err, reset) => {
739
+ const f = props.fallback;
740
+ if ((typeof f !== "function" || f.length == 0)) console.error(err);
741
+ return typeof f === "function" && f.length ? f(err, reset) : f;
1820
742
  });
1821
743
  }
1822
744
 
745
+ function ssrHandleError() {}
746
+ function ssrRunInScope() {}
747
+ const DevHooks = {};
1823
748
  const DEV = {
1824
749
  hooks: DevHooks,
1825
- writeSignal,
1826
750
  registerGraph
1827
751
  } ;
1828
752
  if (globalThis) {
1829
753
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
1830
754
  }
1831
755
 
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 };
756
+ export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Show, Switch, children, createComponent, createContext, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createRenderEffect, createSignal, createStore, createUniqueId, enableHydration, lazy, sharedConfig, ssrHandleError, ssrRunInScope, useContext };