wherever-dev 0.2.0 → 0.3.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 (68) hide show
  1. package/dist/index.js +119 -15
  2. package/dist/index.js.map +1 -1
  3. package/dist/protocol.d.ts +13 -0
  4. package/dist/protocol.d.ts.map +1 -1
  5. package/dist/protocol.js +5 -1
  6. package/dist/protocol.js.map +1 -1
  7. package/dist/session-pool.d.ts +24 -0
  8. package/dist/session-pool.d.ts.map +1 -1
  9. package/dist/session-pool.js +106 -2
  10. package/dist/session-pool.js.map +1 -1
  11. package/package.json +1 -1
  12. package/public/_app/immutable/assets/0.q9wI9TO7.css +1 -0
  13. package/public/_app/immutable/chunks/6X7J6WvW.js +2 -0
  14. package/public/_app/immutable/chunks/{_lppinj8.js.map → 6X7J6WvW.js.map} +1 -1
  15. package/public/_app/immutable/chunks/Bd0XWRPL.js +2 -0
  16. package/public/_app/immutable/chunks/{BqMutrfe.js.map → Bd0XWRPL.js.map} +1 -1
  17. package/public/_app/immutable/chunks/BmiXjuDY.js +2 -0
  18. package/public/_app/immutable/chunks/{DiYtJzYU.js.map → BmiXjuDY.js.map} +1 -1
  19. package/public/_app/immutable/chunks/Bx-JhvcJ.js +2 -0
  20. package/public/_app/immutable/chunks/{BEWoN05F.js.map → Bx-JhvcJ.js.map} +1 -1
  21. package/public/_app/immutable/chunks/DRkv8Frb.js +2 -0
  22. package/public/_app/immutable/chunks/{B5WJGjcR.js.map → DRkv8Frb.js.map} +1 -1
  23. package/public/_app/immutable/chunks/D_-ITvkp.js +2 -0
  24. package/public/_app/immutable/chunks/D_-ITvkp.js.map +1 -0
  25. package/public/_app/immutable/chunks/Db42-KyD.js +3 -0
  26. package/public/_app/immutable/chunks/{DFxBx2vA.js.map → Db42-KyD.js.map} +1 -1
  27. package/public/_app/immutable/entry/app.BCW_w5jE.js +3 -0
  28. package/public/_app/immutable/entry/app.BCW_w5jE.js.map +1 -0
  29. package/public/_app/immutable/entry/start.B21iffdh.js +2 -0
  30. package/public/_app/immutable/entry/start.B21iffdh.js.map +1 -0
  31. package/public/_app/immutable/nodes/0.DzrPFEHh.js +4 -0
  32. package/public/_app/immutable/nodes/{0.BzvDOlXz.js.map → 0.DzrPFEHh.js.map} +1 -1
  33. package/public/_app/immutable/nodes/1.BiDjgup0.js +2 -0
  34. package/public/_app/immutable/nodes/{1.DMtW3tA5.js.map → 1.BiDjgup0.js.map} +1 -1
  35. package/public/_app/immutable/nodes/2.0Tnfs-pB.js +25 -0
  36. package/public/_app/immutable/nodes/2.0Tnfs-pB.js.map +1 -0
  37. package/public/_app/version.json +1 -1
  38. package/public/index.html +16 -16
  39. package/public/pwa/apple-touch-icon.png +0 -0
  40. package/public/pwa/favicon-192.png +0 -0
  41. package/public/pwa/favicon-512.png +0 -0
  42. package/public/pwa/favicon.ico +0 -0
  43. package/public/pwa/favicon.svg +1 -0
  44. package/public/pwa/manifest.webmanifest +31 -7
  45. package/public/pwa/maskable-192.png +0 -0
  46. package/public/pwa/maskable-512.png +0 -0
  47. package/public/pwa/screenshot-desktop.png +0 -0
  48. package/public/pwa/screenshot-mobile.png +0 -0
  49. package/public/robots.txt +5 -0
  50. package/public/service-worker.js +1 -305
  51. package/public/_app/immutable/assets/0.DvZxoQjW.css +0 -2754
  52. package/public/_app/immutable/chunks/B5WJGjcR.js +0 -23
  53. package/public/_app/immutable/chunks/BEWoN05F.js +0 -110
  54. package/public/_app/immutable/chunks/BqMutrfe.js +0 -2129
  55. package/public/_app/immutable/chunks/DFxBx2vA.js +0 -897
  56. package/public/_app/immutable/chunks/DiYtJzYU.js +0 -396
  57. package/public/_app/immutable/chunks/_lppinj8.js +0 -879
  58. package/public/_app/immutable/chunks/rMw82gDs.js +0 -3048
  59. package/public/_app/immutable/chunks/rMw82gDs.js.map +0 -1
  60. package/public/_app/immutable/entry/app.BFki2czn.js +0 -309
  61. package/public/_app/immutable/entry/app.BFki2czn.js.map +0 -1
  62. package/public/_app/immutable/entry/start.BceUuq27.js +0 -6
  63. package/public/_app/immutable/entry/start.BceUuq27.js.map +0 -1
  64. package/public/_app/immutable/nodes/0.BzvDOlXz.js +0 -546
  65. package/public/_app/immutable/nodes/1.DMtW3tA5.js +0 -24
  66. package/public/_app/immutable/nodes/2.CnZp8abw.js +0 -5152
  67. package/public/_app/immutable/nodes/2.CnZp8abw.js.map +0 -1
  68. package/public/icon.png +0 -0
@@ -1,3048 +0,0 @@
1
- const DEV = false;
2
- var is_array = Array.isArray;
3
- var index_of = Array.prototype.indexOf;
4
- var includes = Array.prototype.includes;
5
- var array_from = Array.from;
6
- var define_property = Object.defineProperty;
7
- var get_descriptor = Object.getOwnPropertyDescriptor;
8
- var get_descriptors = Object.getOwnPropertyDescriptors;
9
- var object_prototype = Object.prototype;
10
- var array_prototype = Array.prototype;
11
- var get_prototype_of = Object.getPrototypeOf;
12
- var is_extensible = Object.isExtensible;
13
- function is_function(thing) {
14
- return typeof thing === "function";
15
- }
16
- const noop = () => {
17
- };
18
- function run(fn) {
19
- return fn();
20
- }
21
- function run_all(arr) {
22
- for (var i = 0; i < arr.length; i++) {
23
- arr[i]();
24
- }
25
- }
26
- function deferred() {
27
- var resolve;
28
- var reject;
29
- var promise = new Promise((res, rej) => {
30
- resolve = res;
31
- reject = rej;
32
- });
33
- return { promise, resolve, reject };
34
- }
35
- const DERIVED = 1 << 1;
36
- const EFFECT = 1 << 2;
37
- const RENDER_EFFECT = 1 << 3;
38
- const MANAGED_EFFECT = 1 << 24;
39
- const BLOCK_EFFECT = 1 << 4;
40
- const BRANCH_EFFECT = 1 << 5;
41
- const ROOT_EFFECT = 1 << 6;
42
- const BOUNDARY_EFFECT = 1 << 7;
43
- const CONNECTED = 1 << 9;
44
- const CLEAN = 1 << 10;
45
- const DIRTY = 1 << 11;
46
- const MAYBE_DIRTY = 1 << 12;
47
- const INERT = 1 << 13;
48
- const DESTROYED = 1 << 14;
49
- const REACTION_RAN = 1 << 15;
50
- const DESTROYING = 1 << 25;
51
- const EFFECT_TRANSPARENT = 1 << 16;
52
- const EAGER_EFFECT = 1 << 17;
53
- const HEAD_EFFECT = 1 << 18;
54
- const EFFECT_PRESERVED = 1 << 19;
55
- const USER_EFFECT = 1 << 20;
56
- const EFFECT_OFFSCREEN = 1 << 25;
57
- const WAS_MARKED = 1 << 16;
58
- const REACTION_IS_UPDATING = 1 << 21;
59
- const ASYNC = 1 << 22;
60
- const ERROR_VALUE = 1 << 23;
61
- const STATE_SYMBOL = /* @__PURE__ */ Symbol("$state");
62
- const LEGACY_PROPS = /* @__PURE__ */ Symbol("legacy props");
63
- const LOADING_ATTR_SYMBOL = /* @__PURE__ */ Symbol("");
64
- const ATTRIBUTES_CACHE = /* @__PURE__ */ Symbol("attributes");
65
- const CLASS_CACHE = /* @__PURE__ */ Symbol("class");
66
- const STYLE_CACHE = /* @__PURE__ */ Symbol("style");
67
- const TEXT_CACHE = /* @__PURE__ */ Symbol("text");
68
- const FORM_RESET_HANDLER = /* @__PURE__ */ Symbol("form reset");
69
- const STALE_REACTION = new class StaleReactionError extends Error {
70
- name = "StaleReactionError";
71
- message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
72
- }();
73
- const IS_XHTML = (
74
- // We gotta write it like this because after downleveling the pure comment may end up in the wrong location
75
- !!globalThis.document?.contentType && /* @__PURE__ */ globalThis.document.contentType.includes("xml")
76
- );
77
- const TEXT_NODE = 3;
78
- const COMMENT_NODE = 8;
79
- function lifecycle_outside_component(name) {
80
- {
81
- throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
82
- }
83
- }
84
- function async_derived_orphan() {
85
- {
86
- throw new Error(`https://svelte.dev/e/async_derived_orphan`);
87
- }
88
- }
89
- function each_key_duplicate(a, b, value) {
90
- {
91
- throw new Error(`https://svelte.dev/e/each_key_duplicate`);
92
- }
93
- }
94
- function effect_in_teardown(rune) {
95
- {
96
- throw new Error(`https://svelte.dev/e/effect_in_teardown`);
97
- }
98
- }
99
- function effect_in_unowned_derived() {
100
- {
101
- throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
102
- }
103
- }
104
- function effect_orphan(rune) {
105
- {
106
- throw new Error(`https://svelte.dev/e/effect_orphan`);
107
- }
108
- }
109
- function effect_update_depth_exceeded() {
110
- {
111
- throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
112
- }
113
- }
114
- function hydration_failed() {
115
- {
116
- throw new Error(`https://svelte.dev/e/hydration_failed`);
117
- }
118
- }
119
- function props_invalid_value(key) {
120
- {
121
- throw new Error(`https://svelte.dev/e/props_invalid_value`);
122
- }
123
- }
124
- function state_descriptors_fixed() {
125
- {
126
- throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
127
- }
128
- }
129
- function state_prototype_fixed() {
130
- {
131
- throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
132
- }
133
- }
134
- function state_unsafe_mutation() {
135
- {
136
- throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
137
- }
138
- }
139
- function svelte_boundary_reset_onerror() {
140
- {
141
- throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
142
- }
143
- }
144
- const EACH_ITEM_REACTIVE = 1;
145
- const EACH_INDEX_REACTIVE = 1 << 1;
146
- const EACH_IS_CONTROLLED = 1 << 2;
147
- const EACH_IS_ANIMATED = 1 << 3;
148
- const EACH_ITEM_IMMUTABLE = 1 << 4;
149
- const PROPS_IS_IMMUTABLE = 1;
150
- const PROPS_IS_RUNES = 1 << 1;
151
- const PROPS_IS_UPDATED = 1 << 2;
152
- const PROPS_IS_BINDABLE = 1 << 3;
153
- const PROPS_IS_LAZY_INITIAL = 1 << 4;
154
- const TRANSITION_GLOBAL = 1 << 2;
155
- const TEMPLATE_FRAGMENT = 1;
156
- const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
157
- const HYDRATION_START = "[";
158
- const HYDRATION_START_ELSE = "[!";
159
- const HYDRATION_START_FAILED = "[?";
160
- const HYDRATION_END = "]";
161
- const HYDRATION_ERROR = {};
162
- const UNINITIALIZED = /* @__PURE__ */ Symbol("uninitialized");
163
- const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
164
- function derived_inert() {
165
- {
166
- console.warn(`https://svelte.dev/e/derived_inert`);
167
- }
168
- }
169
- function hydration_mismatch(location) {
170
- {
171
- console.warn(`https://svelte.dev/e/hydration_mismatch`);
172
- }
173
- }
174
- function select_multiple_invalid_value() {
175
- {
176
- console.warn(`https://svelte.dev/e/select_multiple_invalid_value`);
177
- }
178
- }
179
- function svelte_boundary_reset_noop() {
180
- {
181
- console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
182
- }
183
- }
184
- let hydrating = false;
185
- function set_hydrating(value) {
186
- hydrating = value;
187
- }
188
- let hydrate_node;
189
- function set_hydrate_node(node) {
190
- if (node === null) {
191
- hydration_mismatch();
192
- throw HYDRATION_ERROR;
193
- }
194
- return hydrate_node = node;
195
- }
196
- function hydrate_next() {
197
- return set_hydrate_node(/* @__PURE__ */ get_next_sibling(hydrate_node));
198
- }
199
- function reset(node) {
200
- if (!hydrating) return;
201
- if (/* @__PURE__ */ get_next_sibling(hydrate_node) !== null) {
202
- hydration_mismatch();
203
- throw HYDRATION_ERROR;
204
- }
205
- hydrate_node = node;
206
- }
207
- function next(count = 1) {
208
- if (hydrating) {
209
- var i = count;
210
- var node = hydrate_node;
211
- while (i--) {
212
- node = /** @type {TemplateNode} */
213
- /* @__PURE__ */ get_next_sibling(node);
214
- }
215
- hydrate_node = node;
216
- }
217
- }
218
- function skip_nodes(remove = true) {
219
- var depth = 0;
220
- var node = hydrate_node;
221
- while (true) {
222
- if (node.nodeType === COMMENT_NODE) {
223
- var data = (
224
- /** @type {Comment} */
225
- node.data
226
- );
227
- if (data === HYDRATION_END) {
228
- if (depth === 0) return node;
229
- depth -= 1;
230
- } else if (data === HYDRATION_START || data === HYDRATION_START_ELSE || // "[1", "[2", etc. for if blocks
231
- data[0] === "[" && !isNaN(Number(data.slice(1)))) {
232
- depth += 1;
233
- }
234
- }
235
- var next2 = (
236
- /** @type {TemplateNode} */
237
- /* @__PURE__ */ get_next_sibling(node)
238
- );
239
- if (remove) node.remove();
240
- node = next2;
241
- }
242
- }
243
- function read_hydration_instruction(node) {
244
- if (!node || node.nodeType !== COMMENT_NODE) {
245
- hydration_mismatch();
246
- throw HYDRATION_ERROR;
247
- }
248
- return (
249
- /** @type {Comment} */
250
- node.data
251
- );
252
- }
253
- function equals(value) {
254
- return value === this.v;
255
- }
256
- function safe_not_equal(a, b) {
257
- return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
258
- }
259
- function safe_equals(value) {
260
- return !safe_not_equal(value, this.v);
261
- }
262
- let legacy_mode_flag = false;
263
- let tracing_mode_flag = false;
264
- function enable_legacy_mode_flag() {
265
- legacy_mode_flag = true;
266
- }
267
- let component_context = null;
268
- function set_component_context(context) {
269
- component_context = context;
270
- }
271
- function push(props, runes = false, fn) {
272
- component_context = {
273
- p: component_context,
274
- i: false,
275
- c: null,
276
- e: null,
277
- s: props,
278
- x: null,
279
- r: (
280
- /** @type {Effect} */
281
- active_effect
282
- ),
283
- l: legacy_mode_flag && !runes ? { s: null, u: null, $: [] } : null
284
- };
285
- }
286
- function pop(component) {
287
- var context = (
288
- /** @type {ComponentContext} */
289
- component_context
290
- );
291
- var effects = context.e;
292
- if (effects !== null) {
293
- context.e = null;
294
- for (var fn of effects) {
295
- create_user_effect(fn);
296
- }
297
- }
298
- if (component !== void 0) {
299
- context.x = component;
300
- }
301
- context.i = true;
302
- component_context = context.p;
303
- return component ?? /** @type {T} */
304
- {};
305
- }
306
- function is_runes() {
307
- return !legacy_mode_flag || component_context !== null && component_context.l === null;
308
- }
309
- let micro_tasks = [];
310
- function run_micro_tasks() {
311
- var tasks = micro_tasks;
312
- micro_tasks = [];
313
- run_all(tasks);
314
- }
315
- function queue_micro_task(fn) {
316
- if (micro_tasks.length === 0 && !is_flushing_sync) {
317
- var tasks = micro_tasks;
318
- queueMicrotask(() => {
319
- if (tasks === micro_tasks) run_micro_tasks();
320
- });
321
- }
322
- micro_tasks.push(fn);
323
- }
324
- function flush_tasks() {
325
- while (micro_tasks.length > 0) {
326
- run_micro_tasks();
327
- }
328
- }
329
- function handle_error(error) {
330
- var effect2 = active_effect;
331
- if (effect2 === null) {
332
- active_reaction.f |= ERROR_VALUE;
333
- return error;
334
- }
335
- if ((effect2.f & REACTION_RAN) === 0 && (effect2.f & EFFECT) === 0) {
336
- throw error;
337
- }
338
- invoke_error_boundary(error, effect2);
339
- }
340
- function invoke_error_boundary(error, effect2) {
341
- while (effect2 !== null) {
342
- if ((effect2.f & BOUNDARY_EFFECT) !== 0) {
343
- if ((effect2.f & REACTION_RAN) === 0) {
344
- throw error;
345
- }
346
- try {
347
- effect2.b.error(error);
348
- return;
349
- } catch (e) {
350
- error = e;
351
- }
352
- }
353
- effect2 = effect2.parent;
354
- }
355
- throw error;
356
- }
357
- const STATUS_MASK = -7169;
358
- function set_signal_status(signal, status) {
359
- signal.f = signal.f & STATUS_MASK | status;
360
- }
361
- function update_derived_status(derived2) {
362
- if ((derived2.f & CONNECTED) !== 0 || derived2.deps === null) {
363
- set_signal_status(derived2, CLEAN);
364
- } else {
365
- set_signal_status(derived2, MAYBE_DIRTY);
366
- }
367
- }
368
- function clear_marked(deps) {
369
- if (deps === null) return;
370
- for (const dep of deps) {
371
- if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) {
372
- continue;
373
- }
374
- dep.f ^= WAS_MARKED;
375
- clear_marked(
376
- /** @type {Derived} */
377
- dep.deps
378
- );
379
- }
380
- }
381
- function defer_effect(effect2, dirty_effects, maybe_dirty_effects) {
382
- if ((effect2.f & DIRTY) !== 0) {
383
- dirty_effects.add(effect2);
384
- } else if ((effect2.f & MAYBE_DIRTY) !== 0) {
385
- maybe_dirty_effects.add(effect2);
386
- }
387
- clear_marked(effect2.deps);
388
- set_signal_status(effect2, CLEAN);
389
- }
390
- function subscribe_to_store(store, run2, invalidate) {
391
- if (store == null) {
392
- run2(void 0);
393
- if (invalidate) invalidate(void 0);
394
- return noop;
395
- }
396
- const unsub = untrack(
397
- () => store.subscribe(
398
- run2,
399
- // @ts-expect-error
400
- invalidate
401
- )
402
- );
403
- return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
404
- }
405
- const subscriber_queue = [];
406
- function readable(value, start) {
407
- return {
408
- subscribe: writable(value, start).subscribe
409
- };
410
- }
411
- function writable(value, start = noop) {
412
- let stop = null;
413
- const subscribers = /* @__PURE__ */ new Set();
414
- function set2(new_value) {
415
- if (safe_not_equal(value, new_value)) {
416
- value = new_value;
417
- if (stop) {
418
- const run_queue = !subscriber_queue.length;
419
- for (const subscriber of subscribers) {
420
- subscriber[1]();
421
- subscriber_queue.push(subscriber, value);
422
- }
423
- if (run_queue) {
424
- for (let i = 0; i < subscriber_queue.length; i += 2) {
425
- subscriber_queue[i][0](subscriber_queue[i + 1]);
426
- }
427
- subscriber_queue.length = 0;
428
- }
429
- }
430
- }
431
- }
432
- function update(fn) {
433
- set2(fn(
434
- /** @type {T} */
435
- value
436
- ));
437
- }
438
- function subscribe(run2, invalidate = noop) {
439
- const subscriber = [run2, invalidate];
440
- subscribers.add(subscriber);
441
- if (subscribers.size === 1) {
442
- stop = start(set2, update) || noop;
443
- }
444
- run2(
445
- /** @type {T} */
446
- value
447
- );
448
- return () => {
449
- subscribers.delete(subscriber);
450
- if (subscribers.size === 0 && stop) {
451
- stop();
452
- stop = null;
453
- }
454
- };
455
- }
456
- return { set: set2, update, subscribe };
457
- }
458
- function derived$1(stores, fn, initial_value) {
459
- const single = !Array.isArray(stores);
460
- const stores_array = single ? [stores] : stores;
461
- if (!stores_array.every(Boolean)) {
462
- throw new Error("derived() expects stores as input, got a falsy value");
463
- }
464
- const auto = fn.length < 2;
465
- return readable(initial_value, (set2, update) => {
466
- let started = false;
467
- const values = [];
468
- let pending = 0;
469
- let cleanup = noop;
470
- const sync = () => {
471
- if (pending) {
472
- return;
473
- }
474
- cleanup();
475
- const result = fn(single ? values[0] : values, set2, update);
476
- if (auto) {
477
- set2(result);
478
- } else {
479
- cleanup = typeof result === "function" ? result : noop;
480
- }
481
- };
482
- const unsubscribers = stores_array.map(
483
- (store, i) => subscribe_to_store(
484
- store,
485
- (value) => {
486
- values[i] = value;
487
- pending &= ~(1 << i);
488
- if (started) {
489
- sync();
490
- }
491
- },
492
- () => {
493
- pending |= 1 << i;
494
- }
495
- )
496
- );
497
- started = true;
498
- sync();
499
- return function stop() {
500
- run_all(unsubscribers);
501
- cleanup();
502
- started = false;
503
- };
504
- });
505
- }
506
- function get$1(store) {
507
- let value;
508
- subscribe_to_store(store, (_) => value = _)();
509
- return value;
510
- }
511
- let first_batch = null;
512
- let last_batch = null;
513
- let current_batch = null;
514
- let previous_batch = null;
515
- let batch_values = null;
516
- let last_scheduled_effect = null;
517
- let is_flushing_sync = false;
518
- let is_processing = false;
519
- let collected_effects = null;
520
- let legacy_updates = null;
521
- var flush_count = 0;
522
- var source_stacks = /* @__PURE__ */ new Set();
523
- let uid = 1;
524
- class Batch {
525
- id = uid++;
526
- /** True as soon as `#process` was called */
527
- #started = false;
528
- linked = true;
529
- /** @type {Batch | null} */
530
- #prev = null;
531
- /** @type {Batch | null} */
532
- #next = null;
533
- /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
534
- async_deriveds = /* @__PURE__ */ new Map();
535
- /**
536
- * The current values of any signals that are updated in this batch.
537
- * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
538
- * They keys of this map are identical to `this.#previous`
539
- * @type {Map<Value, [any, boolean]>}
540
- */
541
- current = /* @__PURE__ */ new Map();
542
- /**
543
- * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
544
- * They keys of this map are identical to `this.#current`
545
- * @type {Map<Value, any>}
546
- */
547
- previous = /* @__PURE__ */ new Map();
548
- /**
549
- * Async effects which this batch doesn't take into account anymore when calculating blockers,
550
- * as it has a value for it already.
551
- * @type {Set<Effect>}
552
- */
553
- unblocked = /* @__PURE__ */ new Set();
554
- /**
555
- * When the batch is committed (and the DOM is updated), we need to remove old branches
556
- * and append new ones by calling the functions added inside (if/each/key/etc) blocks
557
- * @type {Set<(batch: Batch) => void>}
558
- */
559
- #commit_callbacks = /* @__PURE__ */ new Set();
560
- /**
561
- * If a fork is discarded, we need to destroy any effects that are no longer needed
562
- * @type {Set<(batch: Batch) => void>}
563
- */
564
- #discard_callbacks = /* @__PURE__ */ new Set();
565
- /**
566
- * Callbacks that should run only when a fork is committed.
567
- * @type {Set<(batch: Batch) => void>}
568
- */
569
- #fork_commit_callbacks = /* @__PURE__ */ new Set();
570
- /**
571
- * The number of async effects that are currently in flight
572
- */
573
- #pending = 0;
574
- /**
575
- * Async effects that are currently in flight, _not_ inside a pending boundary
576
- * @type {Map<Effect, number>}
577
- */
578
- #blocking_pending = /* @__PURE__ */ new Map();
579
- /**
580
- * A deferred that resolves when the batch is committed, used with `settled()`
581
- * TODO replace with Promise.withResolvers once supported widely enough
582
- * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
583
- */
584
- #deferred = null;
585
- /**
586
- * The root effects that need to be flushed
587
- * @type {Effect[]}
588
- */
589
- #roots = [];
590
- /**
591
- * Effects created while this batch was active.
592
- * @type {Effect[]}
593
- */
594
- #new_effects = [];
595
- /**
596
- * Deferred effects (which run after async work has completed) that are DIRTY
597
- * @type {Set<Effect>}
598
- */
599
- #dirty_effects = /* @__PURE__ */ new Set();
600
- /**
601
- * Deferred effects that are MAYBE_DIRTY
602
- * @type {Set<Effect>}
603
- */
604
- #maybe_dirty_effects = /* @__PURE__ */ new Set();
605
- /**
606
- * A map of branches that still exist, but will be destroyed when this batch
607
- * is committed — we skip over these during `process`.
608
- * The value contains child effects that were dirty/maybe_dirty before being reset,
609
- * so they can be rescheduled if the branch survives.
610
- * @type {Map<Effect, { d: Effect[], m: Effect[] }>}
611
- */
612
- #skipped_branches = /* @__PURE__ */ new Map();
613
- /**
614
- * Inverse of #skipped_branches which we need to tell prior batches to unskip them when committing
615
- * @type {Set<Effect>}
616
- */
617
- #unskipped_branches = /* @__PURE__ */ new Set();
618
- is_fork = false;
619
- #decrement_queued = false;
620
- #is_deferred() {
621
- if (this.is_fork) return true;
622
- for (const effect2 of this.#blocking_pending.keys()) {
623
- var e = effect2;
624
- var skipped = false;
625
- while (e.parent !== null) {
626
- if (this.#skipped_branches.has(e)) {
627
- skipped = true;
628
- break;
629
- }
630
- e = e.parent;
631
- }
632
- if (!skipped) {
633
- return true;
634
- }
635
- }
636
- return false;
637
- }
638
- /**
639
- * Add an effect to the #skipped_branches map and reset its children
640
- * @param {Effect} effect
641
- */
642
- skip_effect(effect2) {
643
- if (!this.#skipped_branches.has(effect2)) {
644
- this.#skipped_branches.set(effect2, { d: [], m: [] });
645
- }
646
- this.#unskipped_branches.delete(effect2);
647
- }
648
- /**
649
- * Remove an effect from the #skipped_branches map and reschedule
650
- * any tracked dirty/maybe_dirty child effects
651
- * @param {Effect} effect
652
- * @param {(e: Effect) => void} callback
653
- */
654
- unskip_effect(effect2, callback = (e) => this.schedule(e)) {
655
- var tracked = this.#skipped_branches.get(effect2);
656
- if (tracked) {
657
- this.#skipped_branches.delete(effect2);
658
- for (var e of tracked.d) {
659
- set_signal_status(e, DIRTY);
660
- callback(e);
661
- }
662
- for (e of tracked.m) {
663
- set_signal_status(e, MAYBE_DIRTY);
664
- callback(e);
665
- }
666
- }
667
- this.#unskipped_branches.add(effect2);
668
- }
669
- #process() {
670
- this.#started = true;
671
- if (flush_count++ > 1e3) {
672
- this.#unlink();
673
- infinite_loop_guard();
674
- }
675
- if (!this.#is_deferred()) {
676
- for (const e of this.#dirty_effects) {
677
- this.#maybe_dirty_effects.delete(e);
678
- set_signal_status(e, DIRTY);
679
- this.schedule(e);
680
- }
681
- for (const e of this.#maybe_dirty_effects) {
682
- set_signal_status(e, MAYBE_DIRTY);
683
- this.schedule(e);
684
- }
685
- }
686
- const roots = this.#roots;
687
- this.#roots = [];
688
- this.apply();
689
- var effects = collected_effects = [];
690
- var render_effects = [];
691
- var updates = legacy_updates = [];
692
- for (const root of roots) {
693
- try {
694
- this.#traverse(root, effects, render_effects);
695
- } catch (e) {
696
- reset_all(root);
697
- throw e;
698
- }
699
- }
700
- current_batch = null;
701
- if (updates.length > 0) {
702
- var batch = Batch.ensure();
703
- for (const e of updates) {
704
- batch.schedule(e);
705
- }
706
- }
707
- collected_effects = null;
708
- legacy_updates = null;
709
- if (this.#is_deferred()) {
710
- this.#defer_effects(render_effects);
711
- this.#defer_effects(effects);
712
- for (const [e, t] of this.#skipped_branches) {
713
- reset_branch(e, t);
714
- }
715
- if (updates.length > 0) {
716
- /** @type {unknown} */
717
- current_batch.#process();
718
- }
719
- return;
720
- }
721
- const earlier_batch = this.#find_earlier_batch();
722
- if (earlier_batch) {
723
- earlier_batch.#merge(this);
724
- return;
725
- }
726
- this.#dirty_effects.clear();
727
- this.#maybe_dirty_effects.clear();
728
- for (const fn of this.#commit_callbacks) fn(this);
729
- this.#commit_callbacks.clear();
730
- previous_batch = this;
731
- flush_queued_effects(render_effects);
732
- flush_queued_effects(effects);
733
- previous_batch = null;
734
- this.#deferred?.resolve();
735
- var next_batch = (
736
- /** @type {Batch | null} */
737
- /** @type {unknown} */
738
- current_batch
739
- );
740
- if (this.linked && this.#pending === 0) {
741
- this.#unlink();
742
- }
743
- if (this.#roots.length > 0) {
744
- if (next_batch === null) {
745
- next_batch = this;
746
- this.#link();
747
- }
748
- const batch2 = next_batch;
749
- batch2.#roots.push(...this.#roots.filter((r) => !batch2.#roots.includes(r)));
750
- }
751
- if (next_batch !== null) {
752
- next_batch.#process();
753
- }
754
- }
755
- /**
756
- * Traverse the effect tree, executing effects or stashing
757
- * them for later execution as appropriate
758
- * @param {Effect} root
759
- * @param {Effect[]} effects
760
- * @param {Effect[]} render_effects
761
- */
762
- #traverse(root, effects, render_effects) {
763
- root.f ^= CLEAN;
764
- var effect2 = root.first;
765
- while (effect2 !== null) {
766
- var flags = effect2.f;
767
- var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
768
- var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
769
- var skip = is_skippable_branch || (flags & INERT) !== 0 || this.#skipped_branches.has(effect2);
770
- if (!skip && effect2.fn !== null) {
771
- if (is_branch) {
772
- effect2.f ^= CLEAN;
773
- } else if ((flags & EFFECT) !== 0) {
774
- effects.push(effect2);
775
- } else if (is_dirty(effect2)) {
776
- if ((flags & BLOCK_EFFECT) !== 0) this.#maybe_dirty_effects.add(effect2);
777
- update_effect(effect2);
778
- }
779
- var child2 = effect2.first;
780
- if (child2 !== null) {
781
- effect2 = child2;
782
- continue;
783
- }
784
- }
785
- while (effect2 !== null) {
786
- var next2 = effect2.next;
787
- if (next2 !== null) {
788
- effect2 = next2;
789
- break;
790
- }
791
- effect2 = effect2.parent;
792
- }
793
- }
794
- }
795
- #find_earlier_batch() {
796
- var batch = this.#prev;
797
- while (batch !== null) {
798
- if (!batch.is_fork) {
799
- for (const [value, [, is_derived]] of this.current) {
800
- if (batch.current.has(value) && !is_derived) {
801
- return batch;
802
- }
803
- }
804
- }
805
- batch = batch.#prev;
806
- }
807
- return null;
808
- }
809
- /**
810
- * @param {Batch} batch
811
- */
812
- #merge(batch) {
813
- for (const [source2, value] of batch.current) {
814
- if (!this.previous.has(source2) && batch.previous.has(source2)) {
815
- this.previous.set(source2, batch.previous.get(source2));
816
- }
817
- this.current.set(source2, value);
818
- }
819
- for (const [effect2, deferred2] of batch.async_deriveds) {
820
- const d = this.async_deriveds.get(effect2);
821
- if (d) deferred2.promise.then(d.resolve);
822
- }
823
- const mark = (value) => {
824
- var reactions = value.reactions;
825
- if (reactions === null) return;
826
- for (const reaction of reactions) {
827
- var flags = reaction.f;
828
- if ((flags & DERIVED) !== 0) {
829
- mark(
830
- /** @type {Derived} */
831
- reaction
832
- );
833
- } else {
834
- var effect2 = (
835
- /** @type {Effect} */
836
- reaction
837
- );
838
- if (flags & (ASYNC | BLOCK_EFFECT) && !this.async_deriveds.has(effect2)) {
839
- this.#maybe_dirty_effects.delete(effect2);
840
- set_signal_status(effect2, DIRTY);
841
- this.schedule(effect2);
842
- }
843
- }
844
- }
845
- };
846
- for (const source2 of this.current.keys()) {
847
- mark(source2);
848
- }
849
- this.oncommit(() => batch.discard());
850
- batch.#unlink();
851
- current_batch = this;
852
- this.#process();
853
- }
854
- /**
855
- * @param {Effect[]} effects
856
- */
857
- #defer_effects(effects) {
858
- for (var i = 0; i < effects.length; i += 1) {
859
- defer_effect(effects[i], this.#dirty_effects, this.#maybe_dirty_effects);
860
- }
861
- }
862
- /**
863
- * Associate a change to a given source with the current
864
- * batch, noting its previous and current values
865
- * @param {Value} source
866
- * @param {any} value
867
- * @param {boolean} [is_derived]
868
- */
869
- capture(source2, value, is_derived = false) {
870
- if (source2.v !== UNINITIALIZED && !this.previous.has(source2)) {
871
- this.previous.set(source2, source2.v);
872
- }
873
- if ((source2.f & ERROR_VALUE) === 0) {
874
- this.current.set(source2, [value, is_derived]);
875
- batch_values?.set(source2, value);
876
- }
877
- if (!this.is_fork) {
878
- source2.v = value;
879
- }
880
- }
881
- activate() {
882
- current_batch = this;
883
- }
884
- deactivate() {
885
- current_batch = null;
886
- batch_values = null;
887
- }
888
- flush() {
889
- try {
890
- if (DEV) ;
891
- is_processing = true;
892
- current_batch = this;
893
- this.#process();
894
- } finally {
895
- flush_count = 0;
896
- last_scheduled_effect = null;
897
- collected_effects = null;
898
- legacy_updates = null;
899
- is_processing = false;
900
- current_batch = null;
901
- batch_values = null;
902
- old_values.clear();
903
- }
904
- }
905
- discard() {
906
- for (const fn of this.#discard_callbacks) fn(this);
907
- this.#discard_callbacks.clear();
908
- this.#fork_commit_callbacks.clear();
909
- this.#unlink();
910
- }
911
- /**
912
- * @param {Effect} effect
913
- */
914
- register_created_effect(effect2) {
915
- this.#new_effects.push(effect2);
916
- }
917
- #commit() {
918
- this.#unlink();
919
- for (let batch = first_batch; batch !== null; batch = batch.#next) {
920
- var is_earlier = batch.id < this.id;
921
- var sources = [];
922
- for (const [source3, [value, is_derived]] of this.current) {
923
- if (batch.current.has(source3)) {
924
- var batch_value = (
925
- /** @type {[any, boolean]} */
926
- batch.current.get(source3)[0]
927
- );
928
- if (is_earlier && value !== batch_value) {
929
- batch.current.set(source3, [value, is_derived]);
930
- } else {
931
- continue;
932
- }
933
- }
934
- sources.push(source3);
935
- }
936
- if (is_earlier) {
937
- for (const [effect2, deferred2] of this.async_deriveds) {
938
- const d = batch.async_deriveds.get(effect2);
939
- if (d) deferred2.promise.then(d.resolve);
940
- }
941
- }
942
- if (!batch.#started) continue;
943
- var others = [...batch.current.keys()].filter((s) => !this.current.has(s));
944
- if (others.length === 0) {
945
- if (is_earlier) {
946
- batch.discard();
947
- }
948
- } else if (sources.length > 0) {
949
- if (is_earlier) {
950
- for (const unskipped of this.#unskipped_branches) {
951
- batch.unskip_effect(unskipped, (e) => {
952
- if ((e.f & (BLOCK_EFFECT | ASYNC)) !== 0) {
953
- batch.schedule(e);
954
- } else {
955
- batch.#defer_effects([e]);
956
- }
957
- });
958
- }
959
- }
960
- batch.activate();
961
- var marked = /* @__PURE__ */ new Set();
962
- var checked = /* @__PURE__ */ new Map();
963
- for (var source2 of sources) {
964
- mark_effects(source2, others, marked, checked);
965
- }
966
- checked = /* @__PURE__ */ new Map();
967
- var current_unequal = [...batch.current.keys()].filter(
968
- (c) => this.current.has(c) ? (
969
- /** @type {[any, boolean]} */
970
- this.current.get(c)[0] !== c.v
971
- ) : true
972
- );
973
- if (current_unequal.length > 0) {
974
- for (const effect2 of this.#new_effects) {
975
- if ((effect2.f & (DESTROYED | INERT | EAGER_EFFECT)) === 0 && depends_on(effect2, current_unequal, checked)) {
976
- if ((effect2.f & (ASYNC | BLOCK_EFFECT)) !== 0) {
977
- set_signal_status(effect2, DIRTY);
978
- batch.schedule(effect2);
979
- } else {
980
- batch.#dirty_effects.add(effect2);
981
- }
982
- }
983
- }
984
- }
985
- if (batch.#roots.length > 0 && !batch.#decrement_queued) {
986
- batch.apply();
987
- for (var root of batch.#roots) {
988
- batch.#traverse(root, [], []);
989
- }
990
- batch.#roots = [];
991
- }
992
- batch.deactivate();
993
- }
994
- }
995
- }
996
- /**
997
- * @param {boolean} blocking
998
- * @param {Effect} effect
999
- */
1000
- increment(blocking, effect2) {
1001
- this.#pending += 1;
1002
- if (blocking) {
1003
- let blocking_pending_count = this.#blocking_pending.get(effect2) ?? 0;
1004
- this.#blocking_pending.set(effect2, blocking_pending_count + 1);
1005
- }
1006
- }
1007
- /**
1008
- * @param {boolean} blocking
1009
- * @param {Effect} effect
1010
- */
1011
- decrement(blocking, effect2) {
1012
- this.#pending -= 1;
1013
- if (blocking) {
1014
- let blocking_pending_count = this.#blocking_pending.get(effect2) ?? 0;
1015
- if (blocking_pending_count === 1) {
1016
- this.#blocking_pending.delete(effect2);
1017
- } else {
1018
- this.#blocking_pending.set(effect2, blocking_pending_count - 1);
1019
- }
1020
- }
1021
- if (this.#decrement_queued) return;
1022
- this.#decrement_queued = true;
1023
- queue_micro_task(() => {
1024
- this.#decrement_queued = false;
1025
- if (this.linked) {
1026
- this.flush();
1027
- }
1028
- });
1029
- }
1030
- /**
1031
- * @param {Set<Effect>} dirty_effects
1032
- * @param {Set<Effect>} maybe_dirty_effects
1033
- */
1034
- transfer_effects(dirty_effects, maybe_dirty_effects) {
1035
- for (const e of dirty_effects) {
1036
- this.#dirty_effects.add(e);
1037
- }
1038
- for (const e of maybe_dirty_effects) {
1039
- this.#maybe_dirty_effects.add(e);
1040
- }
1041
- dirty_effects.clear();
1042
- maybe_dirty_effects.clear();
1043
- }
1044
- /** @param {(batch: Batch) => void} fn */
1045
- oncommit(fn) {
1046
- this.#commit_callbacks.add(fn);
1047
- }
1048
- /** @param {(batch: Batch) => void} fn */
1049
- ondiscard(fn) {
1050
- this.#discard_callbacks.add(fn);
1051
- }
1052
- /** @param {(batch: Batch) => void} fn */
1053
- on_fork_commit(fn) {
1054
- this.#fork_commit_callbacks.add(fn);
1055
- }
1056
- run_fork_commit_callbacks() {
1057
- for (const fn of this.#fork_commit_callbacks) fn(this);
1058
- this.#fork_commit_callbacks.clear();
1059
- }
1060
- settled() {
1061
- return (this.#deferred ??= deferred()).promise;
1062
- }
1063
- static ensure() {
1064
- if (current_batch === null) {
1065
- const batch = current_batch = new Batch();
1066
- batch.#link();
1067
- if (!is_processing && !is_flushing_sync) {
1068
- queue_micro_task(() => {
1069
- if (!batch.#started) {
1070
- batch.flush();
1071
- }
1072
- });
1073
- }
1074
- }
1075
- return current_batch;
1076
- }
1077
- apply() {
1078
- {
1079
- batch_values = null;
1080
- return;
1081
- }
1082
- }
1083
- /**
1084
- *
1085
- * @param {Effect} effect
1086
- */
1087
- schedule(effect2) {
1088
- last_scheduled_effect = effect2;
1089
- if (effect2.b?.is_pending && (effect2.f & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0 && (effect2.f & REACTION_RAN) === 0) {
1090
- effect2.b.defer_effect(effect2);
1091
- return;
1092
- }
1093
- var e = effect2;
1094
- while (e.parent !== null) {
1095
- e = e.parent;
1096
- var flags = e.f;
1097
- if (collected_effects !== null && e === active_effect) {
1098
- if ((active_reaction === null || (active_reaction.f & DERIVED) === 0) && true) {
1099
- return;
1100
- }
1101
- }
1102
- if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
1103
- if ((flags & CLEAN) === 0) {
1104
- return;
1105
- }
1106
- e.f ^= CLEAN;
1107
- }
1108
- }
1109
- this.#roots.push(e);
1110
- }
1111
- #link() {
1112
- if (last_batch === null) {
1113
- first_batch = last_batch = this;
1114
- } else {
1115
- last_batch.#next = this;
1116
- this.#prev = last_batch;
1117
- }
1118
- last_batch = this;
1119
- }
1120
- #unlink() {
1121
- var prev = this.#prev;
1122
- var next2 = this.#next;
1123
- if (prev === null) {
1124
- first_batch = next2;
1125
- } else {
1126
- prev.#next = next2;
1127
- }
1128
- if (next2 === null) {
1129
- last_batch = prev;
1130
- } else {
1131
- next2.#prev = prev;
1132
- }
1133
- this.linked = false;
1134
- }
1135
- }
1136
- function flushSync(fn) {
1137
- var was_flushing_sync = is_flushing_sync;
1138
- is_flushing_sync = true;
1139
- try {
1140
- var result;
1141
- if (fn) ;
1142
- while (true) {
1143
- flush_tasks();
1144
- if (current_batch === null) {
1145
- return (
1146
- /** @type {T} */
1147
- result
1148
- );
1149
- }
1150
- current_batch.flush();
1151
- }
1152
- } finally {
1153
- is_flushing_sync = was_flushing_sync;
1154
- }
1155
- }
1156
- function infinite_loop_guard() {
1157
- try {
1158
- effect_update_depth_exceeded();
1159
- } catch (error) {
1160
- invoke_error_boundary(error, last_scheduled_effect);
1161
- }
1162
- }
1163
- let eager_block_effects = null;
1164
- function flush_queued_effects(effects) {
1165
- var length = effects.length;
1166
- if (length === 0) return;
1167
- var i = 0;
1168
- while (i < length) {
1169
- var effect2 = effects[i++];
1170
- if ((effect2.f & (DESTROYED | INERT)) === 0 && is_dirty(effect2)) {
1171
- eager_block_effects = /* @__PURE__ */ new Set();
1172
- update_effect(effect2);
1173
- if (effect2.deps === null && effect2.first === null && effect2.nodes === null && effect2.teardown === null && effect2.ac === null) {
1174
- unlink_effect(effect2);
1175
- }
1176
- if (eager_block_effects?.size > 0) {
1177
- old_values.clear();
1178
- for (const e of eager_block_effects) {
1179
- if ((e.f & (DESTROYED | INERT)) !== 0) continue;
1180
- const ordered_effects = [e];
1181
- let ancestor = e.parent;
1182
- while (ancestor !== null) {
1183
- if (eager_block_effects.has(ancestor)) {
1184
- eager_block_effects.delete(ancestor);
1185
- ordered_effects.push(ancestor);
1186
- }
1187
- ancestor = ancestor.parent;
1188
- }
1189
- for (let j = ordered_effects.length - 1; j >= 0; j--) {
1190
- const e2 = ordered_effects[j];
1191
- if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
1192
- update_effect(e2);
1193
- }
1194
- }
1195
- eager_block_effects.clear();
1196
- }
1197
- }
1198
- }
1199
- eager_block_effects = null;
1200
- }
1201
- function mark_effects(value, sources, marked, checked) {
1202
- if (marked.has(value)) return;
1203
- marked.add(value);
1204
- if (value.reactions !== null) {
1205
- for (const reaction of value.reactions) {
1206
- const flags = reaction.f;
1207
- if ((flags & DERIVED) !== 0) {
1208
- mark_effects(
1209
- /** @type {Derived} */
1210
- reaction,
1211
- sources,
1212
- marked,
1213
- checked
1214
- );
1215
- } else if ((flags & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
1216
- set_signal_status(reaction, DIRTY);
1217
- schedule_effect(
1218
- /** @type {Effect} */
1219
- reaction
1220
- );
1221
- }
1222
- }
1223
- }
1224
- }
1225
- function depends_on(reaction, sources, checked) {
1226
- const depends = checked.get(reaction);
1227
- if (depends !== void 0) return depends;
1228
- if (reaction.deps !== null) {
1229
- for (const dep of reaction.deps) {
1230
- if (includes.call(sources, dep)) {
1231
- return true;
1232
- }
1233
- if ((dep.f & DERIVED) !== 0 && depends_on(
1234
- /** @type {Derived} */
1235
- dep,
1236
- sources,
1237
- checked
1238
- )) {
1239
- checked.set(
1240
- /** @type {Derived} */
1241
- dep,
1242
- true
1243
- );
1244
- return true;
1245
- }
1246
- }
1247
- }
1248
- checked.set(reaction, false);
1249
- return false;
1250
- }
1251
- function schedule_effect(effect2) {
1252
- current_batch.schedule(effect2);
1253
- }
1254
- function reset_branch(effect2, tracked) {
1255
- if ((effect2.f & BRANCH_EFFECT) !== 0 && (effect2.f & CLEAN) !== 0) {
1256
- return;
1257
- }
1258
- if ((effect2.f & DIRTY) !== 0) {
1259
- tracked.d.push(effect2);
1260
- } else if ((effect2.f & MAYBE_DIRTY) !== 0) {
1261
- tracked.m.push(effect2);
1262
- }
1263
- set_signal_status(effect2, CLEAN);
1264
- var e = effect2.first;
1265
- while (e !== null) {
1266
- reset_branch(e, tracked);
1267
- e = e.next;
1268
- }
1269
- }
1270
- function reset_all(effect2) {
1271
- set_signal_status(effect2, CLEAN);
1272
- var e = effect2.first;
1273
- while (e !== null) {
1274
- reset_all(e);
1275
- e = e.next;
1276
- }
1277
- }
1278
- function flatten(blockers, sync, async, fn) {
1279
- const d = is_runes() ? derived : derived_safe_equal;
1280
- var pending = blockers.filter((b) => !b.settled);
1281
- if (async.length === 0 && pending.length === 0) {
1282
- fn(sync.map(d));
1283
- return;
1284
- }
1285
- var parent = (
1286
- /** @type {Effect} */
1287
- active_effect
1288
- );
1289
- var restore = capture();
1290
- var blocker_promise = pending.length === 1 ? pending[0].promise : pending.length > 1 ? Promise.all(pending.map((b) => b.promise)) : null;
1291
- function finish(values) {
1292
- if ((parent.f & DESTROYED) !== 0) {
1293
- return;
1294
- }
1295
- restore();
1296
- try {
1297
- fn(values);
1298
- } catch (error) {
1299
- invoke_error_boundary(error, parent);
1300
- }
1301
- unset_context();
1302
- }
1303
- var decrement_pending = increment_pending();
1304
- if (async.length === 0) {
1305
- blocker_promise.then(() => finish(sync.map(d))).finally(decrement_pending);
1306
- return;
1307
- }
1308
- function run2() {
1309
- Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then((result) => finish([...sync.map(d), ...result])).catch((error) => invoke_error_boundary(error, parent)).finally(decrement_pending);
1310
- }
1311
- if (blocker_promise) {
1312
- blocker_promise.then(() => {
1313
- restore();
1314
- run2();
1315
- unset_context();
1316
- });
1317
- } else {
1318
- run2();
1319
- }
1320
- }
1321
- function capture() {
1322
- var previous_effect = (
1323
- /** @type {Effect} */
1324
- active_effect
1325
- );
1326
- var previous_reaction = active_reaction;
1327
- var previous_component_context = component_context;
1328
- var previous_batch2 = (
1329
- /** @type {Batch} */
1330
- current_batch
1331
- );
1332
- return function restore(activate_batch = true) {
1333
- set_active_effect(previous_effect);
1334
- set_active_reaction(previous_reaction);
1335
- set_component_context(previous_component_context);
1336
- if (activate_batch && (previous_effect.f & DESTROYED) === 0) {
1337
- previous_batch2?.activate();
1338
- previous_batch2?.apply();
1339
- }
1340
- };
1341
- }
1342
- function unset_context(deactivate_batch = true) {
1343
- set_active_effect(null);
1344
- set_active_reaction(null);
1345
- set_component_context(null);
1346
- if (deactivate_batch) current_batch?.deactivate();
1347
- }
1348
- function increment_pending() {
1349
- var effect2 = (
1350
- /** @type {Effect} */
1351
- active_effect
1352
- );
1353
- var boundary = (
1354
- /** @type {Boundary} */
1355
- effect2.b
1356
- );
1357
- var batch = (
1358
- /** @type {Batch} */
1359
- current_batch
1360
- );
1361
- var blocking = boundary.is_rendered();
1362
- boundary.update_pending_count(1, batch);
1363
- batch.increment(blocking, effect2);
1364
- return () => {
1365
- boundary.update_pending_count(-1, batch);
1366
- batch.decrement(blocking, effect2);
1367
- };
1368
- }
1369
- // @__NO_SIDE_EFFECTS__
1370
- function derived(fn) {
1371
- var flags = DERIVED | DIRTY;
1372
- if (active_effect !== null) {
1373
- active_effect.f |= EFFECT_PRESERVED;
1374
- }
1375
- const signal = {
1376
- ctx: component_context,
1377
- deps: null,
1378
- effects: null,
1379
- equals,
1380
- f: flags,
1381
- fn,
1382
- reactions: null,
1383
- rv: 0,
1384
- v: (
1385
- /** @type {V} */
1386
- UNINITIALIZED
1387
- ),
1388
- wv: 0,
1389
- parent: active_effect,
1390
- ac: null
1391
- };
1392
- return signal;
1393
- }
1394
- const OBSOLETE = /* @__PURE__ */ Symbol("obsolete");
1395
- // @__NO_SIDE_EFFECTS__
1396
- function async_derived(fn, label, location) {
1397
- let parent = (
1398
- /** @type {Effect | null} */
1399
- active_effect
1400
- );
1401
- if (parent === null) {
1402
- async_derived_orphan();
1403
- }
1404
- var promise = (
1405
- /** @type {Promise<V>} */
1406
- /** @type {unknown} */
1407
- void 0
1408
- );
1409
- var signal = source(
1410
- /** @type {V} */
1411
- UNINITIALIZED
1412
- );
1413
- var should_suspend = !active_reaction;
1414
- var deferreds = /* @__PURE__ */ new Set();
1415
- async_effect(() => {
1416
- var effect2 = (
1417
- /** @type {Effect} */
1418
- active_effect
1419
- );
1420
- var d = deferred();
1421
- promise = d.promise;
1422
- try {
1423
- Promise.resolve(fn()).then(d.resolve, (e) => {
1424
- if (e !== STALE_REACTION) d.reject(e);
1425
- }).finally(unset_context);
1426
- } catch (error) {
1427
- d.reject(error);
1428
- unset_context();
1429
- }
1430
- var batch = (
1431
- /** @type {Batch} */
1432
- current_batch
1433
- );
1434
- if (should_suspend) {
1435
- if ((effect2.f & REACTION_RAN) !== 0) {
1436
- var decrement_pending = increment_pending();
1437
- }
1438
- if (
1439
- /** @type {Boundary} */
1440
- parent.b.is_rendered()
1441
- ) {
1442
- batch.async_deriveds.get(effect2)?.reject(OBSOLETE);
1443
- } else {
1444
- for (const d2 of deferreds.values()) {
1445
- d2.reject(OBSOLETE);
1446
- }
1447
- }
1448
- deferreds.add(d);
1449
- batch.async_deriveds.set(effect2, d);
1450
- }
1451
- const handler = (value, error = void 0) => {
1452
- decrement_pending?.();
1453
- deferreds.delete(d);
1454
- if (error === OBSOLETE) return;
1455
- batch.activate();
1456
- if (error) {
1457
- signal.f |= ERROR_VALUE;
1458
- internal_set(signal, error);
1459
- } else {
1460
- if ((signal.f & ERROR_VALUE) !== 0) {
1461
- signal.f ^= ERROR_VALUE;
1462
- }
1463
- internal_set(signal, value);
1464
- }
1465
- batch.deactivate();
1466
- };
1467
- d.promise.then(handler, (e) => handler(null, e || "unknown"));
1468
- });
1469
- teardown(() => {
1470
- for (const d of deferreds) {
1471
- d.reject(OBSOLETE);
1472
- }
1473
- });
1474
- return new Promise((fulfil) => {
1475
- function next2(p) {
1476
- function go() {
1477
- if (p === promise) {
1478
- fulfil(signal);
1479
- } else {
1480
- next2(promise);
1481
- }
1482
- }
1483
- p.then(go, go);
1484
- }
1485
- next2(promise);
1486
- });
1487
- }
1488
- // @__NO_SIDE_EFFECTS__
1489
- function user_derived(fn) {
1490
- const d = /* @__PURE__ */ derived(fn);
1491
- push_reaction_value(d);
1492
- return d;
1493
- }
1494
- // @__NO_SIDE_EFFECTS__
1495
- function derived_safe_equal(fn) {
1496
- const signal = /* @__PURE__ */ derived(fn);
1497
- signal.equals = safe_equals;
1498
- return signal;
1499
- }
1500
- function destroy_derived_effects(derived2) {
1501
- var effects = derived2.effects;
1502
- if (effects !== null) {
1503
- derived2.effects = null;
1504
- for (var i = 0; i < effects.length; i += 1) {
1505
- destroy_effect(
1506
- /** @type {Effect} */
1507
- effects[i]
1508
- );
1509
- }
1510
- }
1511
- }
1512
- function execute_derived(derived2) {
1513
- var value;
1514
- var prev_active_effect = active_effect;
1515
- var parent = derived2.parent;
1516
- if (!is_destroying_effect && parent !== null && derived2.v !== UNINITIALIZED && // if it was never evaluated before, it's guaranteed to fail downstream, so we try to execute instead
1517
- (parent.f & (DESTROYED | INERT)) !== 0) {
1518
- derived_inert();
1519
- return derived2.v;
1520
- }
1521
- set_active_effect(parent);
1522
- {
1523
- try {
1524
- derived2.f &= ~WAS_MARKED;
1525
- destroy_derived_effects(derived2);
1526
- value = update_reaction(derived2);
1527
- } finally {
1528
- set_active_effect(prev_active_effect);
1529
- }
1530
- }
1531
- return value;
1532
- }
1533
- function update_derived(derived2) {
1534
- var value = execute_derived(derived2);
1535
- if (!derived2.equals(value)) {
1536
- derived2.wv = increment_write_version();
1537
- if (!current_batch?.is_fork || derived2.deps === null) {
1538
- if (current_batch !== null) {
1539
- current_batch.capture(derived2, value, true);
1540
- previous_batch?.capture(derived2, value, true);
1541
- } else {
1542
- derived2.v = value;
1543
- }
1544
- if (derived2.deps === null) {
1545
- set_signal_status(derived2, CLEAN);
1546
- return;
1547
- }
1548
- }
1549
- }
1550
- if (is_destroying_effect) {
1551
- return;
1552
- }
1553
- if (batch_values !== null) {
1554
- if (effect_tracking() || current_batch?.is_fork) {
1555
- batch_values.set(derived2, value);
1556
- }
1557
- } else {
1558
- update_derived_status(derived2);
1559
- }
1560
- }
1561
- function freeze_derived_effects(derived2) {
1562
- if (derived2.effects === null) return;
1563
- for (const e of derived2.effects) {
1564
- if (e.teardown || e.ac) {
1565
- e.teardown?.();
1566
- e.ac?.abort(STALE_REACTION);
1567
- if (e.fn !== null) e.teardown = noop;
1568
- e.ac = null;
1569
- remove_reactions(e, 0);
1570
- destroy_effect_children(e);
1571
- }
1572
- }
1573
- }
1574
- function unfreeze_derived_effects(derived2) {
1575
- if (derived2.effects === null) return;
1576
- for (const e of derived2.effects) {
1577
- if (e.teardown && e.fn !== null) {
1578
- update_effect(e);
1579
- }
1580
- }
1581
- }
1582
- let eager_effects = /* @__PURE__ */ new Set();
1583
- const old_values = /* @__PURE__ */ new Map();
1584
- let eager_effects_deferred = false;
1585
- function source(v, stack) {
1586
- var signal = {
1587
- f: 0,
1588
- // TODO ideally we could skip this altogether, but it causes type errors
1589
- v,
1590
- reactions: null,
1591
- equals,
1592
- rv: 0,
1593
- wv: 0
1594
- };
1595
- return signal;
1596
- }
1597
- // @__NO_SIDE_EFFECTS__
1598
- function state(v, stack) {
1599
- const s = source(v);
1600
- push_reaction_value(s);
1601
- return s;
1602
- }
1603
- // @__NO_SIDE_EFFECTS__
1604
- function mutable_source(initial_value, immutable = false, trackable = true) {
1605
- const s = source(initial_value);
1606
- if (!immutable) {
1607
- s.equals = safe_equals;
1608
- }
1609
- if (legacy_mode_flag && trackable && component_context !== null && component_context.l !== null) {
1610
- (component_context.l.s ??= []).push(s);
1611
- }
1612
- return s;
1613
- }
1614
- function set(source2, value, should_proxy = false) {
1615
- if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
1616
- // to ensure we error if state is set inside an inspect effect
1617
- (!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 && (current_sources === null || !includes.call(current_sources, source2))) {
1618
- state_unsafe_mutation();
1619
- }
1620
- let new_value = should_proxy ? proxy(value) : value;
1621
- return internal_set(source2, new_value, legacy_updates);
1622
- }
1623
- function internal_set(source2, value, updated_during_traversal = null) {
1624
- if (!source2.equals(value)) {
1625
- old_values.set(source2, is_destroying_effect ? value : source2.v);
1626
- var batch = Batch.ensure();
1627
- batch.capture(source2, value);
1628
- if ((source2.f & DERIVED) !== 0) {
1629
- const derived2 = (
1630
- /** @type {Derived} */
1631
- source2
1632
- );
1633
- if ((source2.f & DIRTY) !== 0) {
1634
- execute_derived(derived2);
1635
- }
1636
- if (batch_values === null) {
1637
- update_derived_status(derived2);
1638
- }
1639
- }
1640
- source2.wv = increment_write_version();
1641
- mark_reactions(source2, DIRTY, updated_during_traversal);
1642
- if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
1643
- if (untracked_writes === null) {
1644
- set_untracked_writes([source2]);
1645
- } else {
1646
- untracked_writes.push(source2);
1647
- }
1648
- }
1649
- if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
1650
- flush_eager_effects();
1651
- }
1652
- }
1653
- return value;
1654
- }
1655
- function flush_eager_effects() {
1656
- eager_effects_deferred = false;
1657
- for (const effect2 of eager_effects) {
1658
- if ((effect2.f & CLEAN) !== 0) {
1659
- set_signal_status(effect2, MAYBE_DIRTY);
1660
- }
1661
- let dirty;
1662
- try {
1663
- dirty = is_dirty(effect2);
1664
- } catch {
1665
- dirty = true;
1666
- }
1667
- if (dirty) {
1668
- update_effect(effect2);
1669
- }
1670
- }
1671
- eager_effects.clear();
1672
- }
1673
- function increment(source2) {
1674
- set(source2, source2.v + 1);
1675
- }
1676
- function mark_reactions(signal, status, updated_during_traversal) {
1677
- var reactions = signal.reactions;
1678
- if (reactions === null) return;
1679
- var runes = is_runes();
1680
- var length = reactions.length;
1681
- for (var i = 0; i < length; i++) {
1682
- var reaction = reactions[i];
1683
- var flags = reaction.f;
1684
- if (!runes && reaction === active_effect) continue;
1685
- var not_dirty = (flags & DIRTY) === 0;
1686
- if (not_dirty) {
1687
- set_signal_status(reaction, status);
1688
- }
1689
- if ((flags & EAGER_EFFECT) !== 0) {
1690
- eager_effects.add(
1691
- /** @type {Effect} */
1692
- reaction
1693
- );
1694
- } else if ((flags & DERIVED) !== 0) {
1695
- var derived2 = (
1696
- /** @type {Derived} */
1697
- reaction
1698
- );
1699
- batch_values?.delete(derived2);
1700
- if ((flags & WAS_MARKED) === 0) {
1701
- if (flags & CONNECTED && (active_effect === null || (active_effect.f & REACTION_IS_UPDATING) === 0)) {
1702
- reaction.f |= WAS_MARKED;
1703
- }
1704
- mark_reactions(derived2, MAYBE_DIRTY, updated_during_traversal);
1705
- }
1706
- } else if (not_dirty) {
1707
- var effect2 = (
1708
- /** @type {Effect} */
1709
- reaction
1710
- );
1711
- if ((flags & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1712
- eager_block_effects.add(effect2);
1713
- }
1714
- if (updated_during_traversal !== null) {
1715
- updated_during_traversal.push(effect2);
1716
- } else {
1717
- schedule_effect(effect2);
1718
- }
1719
- }
1720
- }
1721
- }
1722
- function proxy(value) {
1723
- if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
1724
- return value;
1725
- }
1726
- const prototype = get_prototype_of(value);
1727
- if (prototype !== object_prototype && prototype !== array_prototype) {
1728
- return value;
1729
- }
1730
- var sources = /* @__PURE__ */ new Map();
1731
- var is_proxied_array = is_array(value);
1732
- var version = /* @__PURE__ */ state(0);
1733
- var parent_version = update_version;
1734
- var with_parent = (fn) => {
1735
- if (update_version === parent_version) {
1736
- return fn();
1737
- }
1738
- var reaction = active_reaction;
1739
- var version2 = update_version;
1740
- set_active_reaction(null);
1741
- set_update_version(parent_version);
1742
- var result = fn();
1743
- set_active_reaction(reaction);
1744
- set_update_version(version2);
1745
- return result;
1746
- };
1747
- if (is_proxied_array) {
1748
- sources.set("length", /* @__PURE__ */ state(
1749
- /** @type {any[]} */
1750
- value.length
1751
- ));
1752
- }
1753
- return new Proxy(
1754
- /** @type {any} */
1755
- value,
1756
- {
1757
- defineProperty(_, prop, descriptor) {
1758
- if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
1759
- state_descriptors_fixed();
1760
- }
1761
- var s = sources.get(prop);
1762
- if (s === void 0) {
1763
- with_parent(() => {
1764
- var s2 = /* @__PURE__ */ state(descriptor.value);
1765
- sources.set(prop, s2);
1766
- return s2;
1767
- });
1768
- } else {
1769
- set(s, descriptor.value, true);
1770
- }
1771
- return true;
1772
- },
1773
- deleteProperty(target, prop) {
1774
- var s = sources.get(prop);
1775
- if (s === void 0) {
1776
- if (prop in target) {
1777
- const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1778
- sources.set(prop, s2);
1779
- increment(version);
1780
- }
1781
- } else {
1782
- set(s, UNINITIALIZED);
1783
- increment(version);
1784
- }
1785
- return true;
1786
- },
1787
- get(target, prop, receiver) {
1788
- if (prop === STATE_SYMBOL) {
1789
- return value;
1790
- }
1791
- var s = sources.get(prop);
1792
- var exists = prop in target;
1793
- if (s === void 0 && (!exists || get_descriptor(target, prop)?.writable)) {
1794
- s = with_parent(() => {
1795
- var p = proxy(exists ? target[prop] : UNINITIALIZED);
1796
- var s2 = /* @__PURE__ */ state(p);
1797
- return s2;
1798
- });
1799
- sources.set(prop, s);
1800
- }
1801
- if (s !== void 0) {
1802
- var v = get(s);
1803
- return v === UNINITIALIZED ? void 0 : v;
1804
- }
1805
- return Reflect.get(target, prop, receiver);
1806
- },
1807
- getOwnPropertyDescriptor(target, prop) {
1808
- var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
1809
- if (descriptor && "value" in descriptor) {
1810
- var s = sources.get(prop);
1811
- if (s) descriptor.value = get(s);
1812
- } else if (descriptor === void 0) {
1813
- var source2 = sources.get(prop);
1814
- var value2 = source2?.v;
1815
- if (source2 !== void 0 && value2 !== UNINITIALIZED) {
1816
- return {
1817
- enumerable: true,
1818
- configurable: true,
1819
- value: value2,
1820
- writable: true
1821
- };
1822
- }
1823
- }
1824
- return descriptor;
1825
- },
1826
- has(target, prop) {
1827
- if (prop === STATE_SYMBOL) {
1828
- return true;
1829
- }
1830
- var s = sources.get(prop);
1831
- var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop);
1832
- if (s !== void 0 || active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) {
1833
- if (s === void 0) {
1834
- s = with_parent(() => {
1835
- var p = has ? proxy(target[prop]) : UNINITIALIZED;
1836
- var s2 = /* @__PURE__ */ state(p);
1837
- return s2;
1838
- });
1839
- sources.set(prop, s);
1840
- }
1841
- var value2 = get(s);
1842
- if (value2 === UNINITIALIZED) {
1843
- return false;
1844
- }
1845
- }
1846
- return has;
1847
- },
1848
- set(target, prop, value2, receiver) {
1849
- var s = sources.get(prop);
1850
- var has = prop in target;
1851
- if (is_proxied_array && prop === "length") {
1852
- for (var i = value2; i < /** @type {Source<number>} */
1853
- s.v; i += 1) {
1854
- var other_s = sources.get(i + "");
1855
- if (other_s !== void 0) {
1856
- set(other_s, UNINITIALIZED);
1857
- } else if (i in target) {
1858
- other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1859
- sources.set(i + "", other_s);
1860
- }
1861
- }
1862
- }
1863
- if (s === void 0) {
1864
- if (!has || get_descriptor(target, prop)?.writable) {
1865
- s = with_parent(() => /* @__PURE__ */ state(void 0));
1866
- set(s, proxy(value2));
1867
- sources.set(prop, s);
1868
- }
1869
- } else {
1870
- has = s.v !== UNINITIALIZED;
1871
- var p = with_parent(() => proxy(value2));
1872
- set(s, p);
1873
- }
1874
- var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
1875
- if (descriptor?.set) {
1876
- descriptor.set.call(receiver, value2);
1877
- }
1878
- if (!has) {
1879
- if (is_proxied_array && typeof prop === "string") {
1880
- var ls = (
1881
- /** @type {Source<number>} */
1882
- sources.get("length")
1883
- );
1884
- var n = Number(prop);
1885
- if (Number.isInteger(n) && n >= ls.v) {
1886
- set(ls, n + 1);
1887
- }
1888
- }
1889
- increment(version);
1890
- }
1891
- return true;
1892
- },
1893
- ownKeys(target) {
1894
- get(version);
1895
- var own_keys = Reflect.ownKeys(target).filter((key2) => {
1896
- var source3 = sources.get(key2);
1897
- return source3 === void 0 || source3.v !== UNINITIALIZED;
1898
- });
1899
- for (var [key, source2] of sources) {
1900
- if (source2.v !== UNINITIALIZED && !(key in target)) {
1901
- own_keys.push(key);
1902
- }
1903
- }
1904
- return own_keys;
1905
- },
1906
- setPrototypeOf() {
1907
- state_prototype_fixed();
1908
- }
1909
- }
1910
- );
1911
- }
1912
- function get_proxied_value(value) {
1913
- try {
1914
- if (value !== null && typeof value === "object" && STATE_SYMBOL in value) {
1915
- return value[STATE_SYMBOL];
1916
- }
1917
- } catch {
1918
- }
1919
- return value;
1920
- }
1921
- function is(a, b) {
1922
- return Object.is(get_proxied_value(a), get_proxied_value(b));
1923
- }
1924
- var $window;
1925
- var $document;
1926
- var is_firefox;
1927
- var first_child_getter;
1928
- var next_sibling_getter;
1929
- function init_operations() {
1930
- if ($window !== void 0) {
1931
- return;
1932
- }
1933
- $window = window;
1934
- $document = document;
1935
- is_firefox = /Firefox/.test(navigator.userAgent);
1936
- var element_prototype = Element.prototype;
1937
- var node_prototype = Node.prototype;
1938
- var text_prototype = Text.prototype;
1939
- first_child_getter = get_descriptor(node_prototype, "firstChild").get;
1940
- next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
1941
- if (is_extensible(element_prototype)) {
1942
- element_prototype[CLASS_CACHE] = void 0;
1943
- element_prototype[ATTRIBUTES_CACHE] = null;
1944
- element_prototype[STYLE_CACHE] = void 0;
1945
- element_prototype.__e = void 0;
1946
- }
1947
- if (is_extensible(text_prototype)) {
1948
- text_prototype[TEXT_CACHE] = void 0;
1949
- }
1950
- }
1951
- function create_text(value = "") {
1952
- return document.createTextNode(value);
1953
- }
1954
- // @__NO_SIDE_EFFECTS__
1955
- function get_first_child(node) {
1956
- return (
1957
- /** @type {TemplateNode | null} */
1958
- first_child_getter.call(node)
1959
- );
1960
- }
1961
- // @__NO_SIDE_EFFECTS__
1962
- function get_next_sibling(node) {
1963
- return (
1964
- /** @type {TemplateNode | null} */
1965
- next_sibling_getter.call(node)
1966
- );
1967
- }
1968
- function child(node, is_text) {
1969
- if (!hydrating) {
1970
- return /* @__PURE__ */ get_first_child(node);
1971
- }
1972
- var child2 = /* @__PURE__ */ get_first_child(hydrate_node);
1973
- if (child2 === null) {
1974
- child2 = hydrate_node.appendChild(create_text());
1975
- } else if (is_text && child2.nodeType !== TEXT_NODE) {
1976
- var text = create_text();
1977
- child2?.before(text);
1978
- set_hydrate_node(text);
1979
- return text;
1980
- }
1981
- if (is_text) {
1982
- merge_text_nodes(
1983
- /** @type {Text} */
1984
- child2
1985
- );
1986
- }
1987
- set_hydrate_node(child2);
1988
- return child2;
1989
- }
1990
- function first_child(node, is_text = false) {
1991
- if (!hydrating) {
1992
- var first = /* @__PURE__ */ get_first_child(node);
1993
- if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
1994
- return first;
1995
- }
1996
- if (is_text) {
1997
- if (hydrate_node?.nodeType !== TEXT_NODE) {
1998
- var text = create_text();
1999
- hydrate_node?.before(text);
2000
- set_hydrate_node(text);
2001
- return text;
2002
- }
2003
- merge_text_nodes(
2004
- /** @type {Text} */
2005
- hydrate_node
2006
- );
2007
- }
2008
- return hydrate_node;
2009
- }
2010
- function sibling(node, count = 1, is_text = false) {
2011
- let next_sibling = hydrating ? hydrate_node : node;
2012
- var last_sibling;
2013
- while (count--) {
2014
- last_sibling = next_sibling;
2015
- next_sibling = /** @type {TemplateNode} */
2016
- /* @__PURE__ */ get_next_sibling(next_sibling);
2017
- }
2018
- if (!hydrating) {
2019
- return next_sibling;
2020
- }
2021
- if (is_text) {
2022
- if (next_sibling?.nodeType !== TEXT_NODE) {
2023
- var text = create_text();
2024
- if (next_sibling === null) {
2025
- last_sibling?.after(text);
2026
- } else {
2027
- next_sibling.before(text);
2028
- }
2029
- set_hydrate_node(text);
2030
- return text;
2031
- }
2032
- merge_text_nodes(
2033
- /** @type {Text} */
2034
- next_sibling
2035
- );
2036
- }
2037
- set_hydrate_node(next_sibling);
2038
- return next_sibling;
2039
- }
2040
- function clear_text_content(node) {
2041
- node.textContent = "";
2042
- }
2043
- function should_defer_append() {
2044
- return false;
2045
- }
2046
- function create_element(tag, namespace, is2) {
2047
- let options = void 0;
2048
- return (
2049
- /** @type {T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : Element} */
2050
- document.createElementNS(NAMESPACE_HTML, tag, options)
2051
- );
2052
- }
2053
- function merge_text_nodes(text) {
2054
- if (
2055
- /** @type {string} */
2056
- text.nodeValue.length < 65536
2057
- ) {
2058
- return;
2059
- }
2060
- let next2 = text.nextSibling;
2061
- while (next2 !== null && next2.nodeType === TEXT_NODE) {
2062
- next2.remove();
2063
- text.nodeValue += /** @type {string} */
2064
- next2.nodeValue;
2065
- next2 = text.nextSibling;
2066
- }
2067
- }
2068
- function remove_textarea_child(dom) {
2069
- if (hydrating && /* @__PURE__ */ get_first_child(dom) !== null) {
2070
- clear_text_content(dom);
2071
- }
2072
- }
2073
- let listening_to_form_reset = false;
2074
- function add_form_reset_listener() {
2075
- if (!listening_to_form_reset) {
2076
- listening_to_form_reset = true;
2077
- document.addEventListener(
2078
- "reset",
2079
- (evt) => {
2080
- Promise.resolve().then(() => {
2081
- if (!evt.defaultPrevented) {
2082
- for (
2083
- const e of
2084
- /**@type {HTMLFormElement} */
2085
- evt.target.elements
2086
- ) {
2087
- e[FORM_RESET_HANDLER]?.();
2088
- }
2089
- }
2090
- });
2091
- },
2092
- // In the capture phase to guarantee we get noticed of it (no possibility of stopPropagation)
2093
- { capture: true }
2094
- );
2095
- }
2096
- }
2097
- function without_reactive_context(fn) {
2098
- var previous_reaction = active_reaction;
2099
- var previous_effect = active_effect;
2100
- set_active_reaction(null);
2101
- set_active_effect(null);
2102
- try {
2103
- return fn();
2104
- } finally {
2105
- set_active_reaction(previous_reaction);
2106
- set_active_effect(previous_effect);
2107
- }
2108
- }
2109
- function listen_to_event_and_reset_event(element, event, handler, on_reset = handler) {
2110
- element.addEventListener(event, () => without_reactive_context(handler));
2111
- const prev = (
2112
- /** @type {any} */
2113
- element[FORM_RESET_HANDLER]
2114
- );
2115
- if (prev) {
2116
- element[FORM_RESET_HANDLER] = () => {
2117
- prev();
2118
- on_reset(true);
2119
- };
2120
- } else {
2121
- element[FORM_RESET_HANDLER] = () => on_reset(true);
2122
- }
2123
- add_form_reset_listener();
2124
- }
2125
- function validate_effect(rune) {
2126
- if (active_effect === null) {
2127
- if (active_reaction === null) {
2128
- effect_orphan();
2129
- }
2130
- effect_in_unowned_derived();
2131
- }
2132
- if (is_destroying_effect) {
2133
- effect_in_teardown();
2134
- }
2135
- }
2136
- function push_effect(effect2, parent_effect) {
2137
- var parent_last = parent_effect.last;
2138
- if (parent_last === null) {
2139
- parent_effect.last = parent_effect.first = effect2;
2140
- } else {
2141
- parent_last.next = effect2;
2142
- effect2.prev = parent_last;
2143
- parent_effect.last = effect2;
2144
- }
2145
- }
2146
- function create_effect(type, fn) {
2147
- var parent = active_effect;
2148
- if (parent !== null && (parent.f & INERT) !== 0) {
2149
- type |= INERT;
2150
- }
2151
- var effect2 = {
2152
- ctx: component_context,
2153
- deps: null,
2154
- nodes: null,
2155
- f: type | DIRTY | CONNECTED,
2156
- first: null,
2157
- fn,
2158
- last: null,
2159
- next: null,
2160
- parent,
2161
- b: parent && parent.b,
2162
- prev: null,
2163
- teardown: null,
2164
- wv: 0,
2165
- ac: null
2166
- };
2167
- current_batch?.register_created_effect(effect2);
2168
- var e = effect2;
2169
- if ((type & EFFECT) !== 0) {
2170
- if (collected_effects !== null) {
2171
- collected_effects.push(effect2);
2172
- } else {
2173
- Batch.ensure().schedule(effect2);
2174
- }
2175
- } else if (fn !== null) {
2176
- try {
2177
- update_effect(effect2);
2178
- } catch (e2) {
2179
- destroy_effect(effect2);
2180
- throw e2;
2181
- }
2182
- if (e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
2183
- (e.f & EFFECT_PRESERVED) === 0) {
2184
- e = e.first;
2185
- if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
2186
- e.f |= EFFECT_TRANSPARENT;
2187
- }
2188
- }
2189
- }
2190
- if (e !== null) {
2191
- e.parent = parent;
2192
- if (parent !== null) {
2193
- push_effect(e, parent);
2194
- }
2195
- if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
2196
- var derived2 = (
2197
- /** @type {Derived} */
2198
- active_reaction
2199
- );
2200
- (derived2.effects ??= []).push(e);
2201
- }
2202
- }
2203
- return effect2;
2204
- }
2205
- function effect_tracking() {
2206
- return active_reaction !== null && !untracking;
2207
- }
2208
- function teardown(fn) {
2209
- const effect2 = create_effect(RENDER_EFFECT, null);
2210
- set_signal_status(effect2, CLEAN);
2211
- effect2.teardown = fn;
2212
- return effect2;
2213
- }
2214
- function user_effect(fn) {
2215
- validate_effect();
2216
- var flags = (
2217
- /** @type {Effect} */
2218
- active_effect.f
2219
- );
2220
- var defer = !active_reaction && (flags & BRANCH_EFFECT) !== 0 && (flags & REACTION_RAN) === 0;
2221
- if (defer) {
2222
- var context = (
2223
- /** @type {ComponentContext} */
2224
- component_context
2225
- );
2226
- (context.e ??= []).push(fn);
2227
- } else {
2228
- return create_user_effect(fn);
2229
- }
2230
- }
2231
- function create_user_effect(fn) {
2232
- return create_effect(EFFECT | USER_EFFECT, fn);
2233
- }
2234
- function user_pre_effect(fn) {
2235
- validate_effect();
2236
- return create_effect(RENDER_EFFECT | USER_EFFECT, fn);
2237
- }
2238
- function component_root(fn) {
2239
- Batch.ensure();
2240
- const effect2 = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn);
2241
- return (options = {}) => {
2242
- return new Promise((fulfil) => {
2243
- if (options.outro) {
2244
- pause_effect(effect2, () => {
2245
- destroy_effect(effect2);
2246
- fulfil(void 0);
2247
- });
2248
- } else {
2249
- destroy_effect(effect2);
2250
- fulfil(void 0);
2251
- }
2252
- });
2253
- };
2254
- }
2255
- function effect(fn) {
2256
- return create_effect(EFFECT, fn);
2257
- }
2258
- function async_effect(fn) {
2259
- return create_effect(ASYNC | EFFECT_PRESERVED, fn);
2260
- }
2261
- function render_effect(fn, flags = 0) {
2262
- return create_effect(RENDER_EFFECT | flags, fn);
2263
- }
2264
- function template_effect(fn, sync = [], async = [], blockers = []) {
2265
- flatten(blockers, sync, async, (values) => {
2266
- create_effect(RENDER_EFFECT, () => fn(...values.map(get)));
2267
- });
2268
- }
2269
- function deferred_template_effect(fn, sync = [], async = [], blockers = []) {
2270
- flatten(blockers, sync, async, (values) => {
2271
- create_effect(EFFECT, () => fn(...values.map(get)));
2272
- });
2273
- }
2274
- function block(fn, flags = 0) {
2275
- var effect2 = create_effect(BLOCK_EFFECT | flags, fn);
2276
- return effect2;
2277
- }
2278
- function branch(fn) {
2279
- return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn);
2280
- }
2281
- function execute_effect_teardown(effect2) {
2282
- var teardown2 = effect2.teardown;
2283
- if (teardown2 !== null) {
2284
- const previously_destroying_effect = is_destroying_effect;
2285
- const previous_reaction = active_reaction;
2286
- set_is_destroying_effect(true);
2287
- set_active_reaction(null);
2288
- try {
2289
- teardown2.call(null);
2290
- } finally {
2291
- set_is_destroying_effect(previously_destroying_effect);
2292
- set_active_reaction(previous_reaction);
2293
- }
2294
- }
2295
- }
2296
- function destroy_effect_children(signal, remove_dom = false) {
2297
- var effect2 = signal.first;
2298
- signal.first = signal.last = null;
2299
- while (effect2 !== null) {
2300
- const controller = effect2.ac;
2301
- if (controller !== null) {
2302
- without_reactive_context(() => {
2303
- controller.abort(STALE_REACTION);
2304
- });
2305
- }
2306
- var next2 = effect2.next;
2307
- if ((effect2.f & ROOT_EFFECT) !== 0) {
2308
- effect2.parent = null;
2309
- } else {
2310
- destroy_effect(effect2, remove_dom);
2311
- }
2312
- effect2 = next2;
2313
- }
2314
- }
2315
- function destroy_block_effect_children(signal) {
2316
- var effect2 = signal.first;
2317
- while (effect2 !== null) {
2318
- var next2 = effect2.next;
2319
- if ((effect2.f & BRANCH_EFFECT) === 0) {
2320
- destroy_effect(effect2);
2321
- }
2322
- effect2 = next2;
2323
- }
2324
- }
2325
- function destroy_effect(effect2, remove_dom = true) {
2326
- var removed = false;
2327
- if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes !== null && effect2.nodes.end !== null) {
2328
- remove_effect_dom(
2329
- effect2.nodes.start,
2330
- /** @type {TemplateNode} */
2331
- effect2.nodes.end
2332
- );
2333
- removed = true;
2334
- }
2335
- set_signal_status(effect2, DESTROYING);
2336
- destroy_effect_children(effect2, remove_dom && !removed);
2337
- remove_reactions(effect2, 0);
2338
- var transitions = effect2.nodes && effect2.nodes.t;
2339
- if (transitions !== null) {
2340
- for (const transition of transitions) {
2341
- transition.stop();
2342
- }
2343
- }
2344
- execute_effect_teardown(effect2);
2345
- effect2.f ^= DESTROYING;
2346
- effect2.f |= DESTROYED;
2347
- var parent = effect2.parent;
2348
- if (parent !== null && parent.first !== null) {
2349
- unlink_effect(effect2);
2350
- }
2351
- effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes = effect2.ac = effect2.b = null;
2352
- }
2353
- function remove_effect_dom(node, end) {
2354
- while (node !== null) {
2355
- var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2356
- node.remove();
2357
- node = next2;
2358
- }
2359
- }
2360
- function unlink_effect(effect2) {
2361
- var parent = effect2.parent;
2362
- var prev = effect2.prev;
2363
- var next2 = effect2.next;
2364
- if (prev !== null) prev.next = next2;
2365
- if (next2 !== null) next2.prev = prev;
2366
- if (parent !== null) {
2367
- if (parent.first === effect2) parent.first = next2;
2368
- if (parent.last === effect2) parent.last = prev;
2369
- }
2370
- }
2371
- function pause_effect(effect2, callback, destroy = true) {
2372
- var transitions = [];
2373
- pause_children(effect2, transitions, true);
2374
- var fn = () => {
2375
- if (destroy) destroy_effect(effect2);
2376
- if (callback) callback();
2377
- };
2378
- var remaining = transitions.length;
2379
- if (remaining > 0) {
2380
- var check = () => --remaining || fn();
2381
- for (var transition of transitions) {
2382
- transition.out(check);
2383
- }
2384
- } else {
2385
- fn();
2386
- }
2387
- }
2388
- function pause_children(effect2, transitions, local) {
2389
- if ((effect2.f & INERT) !== 0) return;
2390
- effect2.f ^= INERT;
2391
- var t = effect2.nodes && effect2.nodes.t;
2392
- if (t !== null) {
2393
- for (const transition of t) {
2394
- if (transition.is_global || local) {
2395
- transitions.push(transition);
2396
- }
2397
- }
2398
- }
2399
- var child2 = effect2.first;
2400
- while (child2 !== null) {
2401
- var sibling2 = child2.next;
2402
- if ((child2.f & ROOT_EFFECT) === 0) {
2403
- var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
2404
- // it means the parent block effect was pruned. In that case,
2405
- // transparency information was transferred to the branch effect.
2406
- (child2.f & BRANCH_EFFECT) !== 0 && (effect2.f & BLOCK_EFFECT) !== 0;
2407
- pause_children(child2, transitions, transparent ? local : false);
2408
- }
2409
- child2 = sibling2;
2410
- }
2411
- }
2412
- function resume_effect(effect2) {
2413
- resume_children(effect2, true);
2414
- }
2415
- function resume_children(effect2, local) {
2416
- if ((effect2.f & INERT) === 0) return;
2417
- effect2.f ^= INERT;
2418
- if ((effect2.f & CLEAN) === 0) {
2419
- set_signal_status(effect2, DIRTY);
2420
- Batch.ensure().schedule(effect2);
2421
- }
2422
- var child2 = effect2.first;
2423
- while (child2 !== null) {
2424
- var sibling2 = child2.next;
2425
- var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
2426
- resume_children(child2, transparent ? local : false);
2427
- child2 = sibling2;
2428
- }
2429
- var t = effect2.nodes && effect2.nodes.t;
2430
- if (t !== null) {
2431
- for (const transition of t) {
2432
- if (transition.is_global || local) {
2433
- transition.in();
2434
- }
2435
- }
2436
- }
2437
- }
2438
- function move_effect(effect2, fragment) {
2439
- if (!effect2.nodes) return;
2440
- var node = effect2.nodes.start;
2441
- var end = effect2.nodes.end;
2442
- while (node !== null) {
2443
- var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2444
- fragment.append(node);
2445
- node = next2;
2446
- }
2447
- }
2448
- let is_updating_effect = false;
2449
- let is_destroying_effect = false;
2450
- function set_is_destroying_effect(value) {
2451
- is_destroying_effect = value;
2452
- }
2453
- let active_reaction = null;
2454
- let untracking = false;
2455
- function set_active_reaction(reaction) {
2456
- active_reaction = reaction;
2457
- }
2458
- let active_effect = null;
2459
- function set_active_effect(effect2) {
2460
- active_effect = effect2;
2461
- }
2462
- let current_sources = null;
2463
- function push_reaction_value(value) {
2464
- if (active_reaction !== null && true) {
2465
- if (current_sources === null) {
2466
- current_sources = [value];
2467
- } else {
2468
- current_sources.push(value);
2469
- }
2470
- }
2471
- }
2472
- let new_deps = null;
2473
- let skipped_deps = 0;
2474
- let untracked_writes = null;
2475
- function set_untracked_writes(value) {
2476
- untracked_writes = value;
2477
- }
2478
- let write_version = 1;
2479
- let read_version = 0;
2480
- let update_version = read_version;
2481
- function set_update_version(value) {
2482
- update_version = value;
2483
- }
2484
- function increment_write_version() {
2485
- return ++write_version;
2486
- }
2487
- function is_dirty(reaction) {
2488
- var flags = reaction.f;
2489
- if ((flags & DIRTY) !== 0) {
2490
- return true;
2491
- }
2492
- if (flags & DERIVED) {
2493
- reaction.f &= ~WAS_MARKED;
2494
- }
2495
- if ((flags & MAYBE_DIRTY) !== 0) {
2496
- var dependencies = (
2497
- /** @type {Value[]} */
2498
- reaction.deps
2499
- );
2500
- var length = dependencies.length;
2501
- for (var i = 0; i < length; i++) {
2502
- var dependency = dependencies[i];
2503
- if (is_dirty(
2504
- /** @type {Derived} */
2505
- dependency
2506
- )) {
2507
- update_derived(
2508
- /** @type {Derived} */
2509
- dependency
2510
- );
2511
- }
2512
- if (dependency.wv > reaction.wv) {
2513
- return true;
2514
- }
2515
- }
2516
- if ((flags & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
2517
- // traversal of the graph in the other batches still happens
2518
- batch_values === null) {
2519
- set_signal_status(reaction, CLEAN);
2520
- }
2521
- }
2522
- return false;
2523
- }
2524
- function schedule_possible_effect_self_invalidation(signal, effect2, root = true) {
2525
- var reactions = signal.reactions;
2526
- if (reactions === null) return;
2527
- if (current_sources !== null && includes.call(current_sources, signal)) {
2528
- return;
2529
- }
2530
- for (var i = 0; i < reactions.length; i++) {
2531
- var reaction = reactions[i];
2532
- if ((reaction.f & DERIVED) !== 0) {
2533
- schedule_possible_effect_self_invalidation(
2534
- /** @type {Derived} */
2535
- reaction,
2536
- effect2,
2537
- false
2538
- );
2539
- } else if (effect2 === reaction) {
2540
- if (root) {
2541
- set_signal_status(reaction, DIRTY);
2542
- } else if ((reaction.f & CLEAN) !== 0) {
2543
- set_signal_status(reaction, MAYBE_DIRTY);
2544
- }
2545
- schedule_effect(
2546
- /** @type {Effect} */
2547
- reaction
2548
- );
2549
- }
2550
- }
2551
- }
2552
- function update_reaction(reaction) {
2553
- var previous_deps = new_deps;
2554
- var previous_skipped_deps = skipped_deps;
2555
- var previous_untracked_writes = untracked_writes;
2556
- var previous_reaction = active_reaction;
2557
- var previous_sources = current_sources;
2558
- var previous_component_context = component_context;
2559
- var previous_untracking = untracking;
2560
- var previous_update_version = update_version;
2561
- var flags = reaction.f;
2562
- new_deps = /** @type {null | Value[]} */
2563
- null;
2564
- skipped_deps = 0;
2565
- untracked_writes = null;
2566
- active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
2567
- current_sources = null;
2568
- set_component_context(reaction.ctx);
2569
- untracking = false;
2570
- update_version = ++read_version;
2571
- if (reaction.ac !== null) {
2572
- without_reactive_context(() => {
2573
- reaction.ac.abort(STALE_REACTION);
2574
- });
2575
- reaction.ac = null;
2576
- }
2577
- try {
2578
- reaction.f |= REACTION_IS_UPDATING;
2579
- var fn = (
2580
- /** @type {Function} */
2581
- reaction.fn
2582
- );
2583
- var result = fn();
2584
- reaction.f |= REACTION_RAN;
2585
- var deps = reaction.deps;
2586
- var is_fork = current_batch?.is_fork;
2587
- if (new_deps !== null) {
2588
- var i;
2589
- if (!is_fork) {
2590
- remove_reactions(reaction, skipped_deps);
2591
- }
2592
- if (deps !== null && skipped_deps > 0) {
2593
- deps.length = skipped_deps + new_deps.length;
2594
- for (i = 0; i < new_deps.length; i++) {
2595
- deps[skipped_deps + i] = new_deps[i];
2596
- }
2597
- } else {
2598
- reaction.deps = deps = new_deps;
2599
- }
2600
- if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
2601
- for (i = skipped_deps; i < deps.length; i++) {
2602
- (deps[i].reactions ??= []).push(reaction);
2603
- }
2604
- }
2605
- } else if (!is_fork && deps !== null && skipped_deps < deps.length) {
2606
- remove_reactions(reaction, skipped_deps);
2607
- deps.length = skipped_deps;
2608
- }
2609
- if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
2610
- for (i = 0; i < /** @type {Source[]} */
2611
- untracked_writes.length; i++) {
2612
- schedule_possible_effect_self_invalidation(
2613
- untracked_writes[i],
2614
- /** @type {Effect} */
2615
- reaction
2616
- );
2617
- }
2618
- }
2619
- if (previous_reaction !== null && previous_reaction !== reaction) {
2620
- read_version++;
2621
- if (previous_reaction.deps !== null) {
2622
- for (let i2 = 0; i2 < previous_skipped_deps; i2 += 1) {
2623
- previous_reaction.deps[i2].rv = read_version;
2624
- }
2625
- }
2626
- if (previous_deps !== null) {
2627
- for (const dep of previous_deps) {
2628
- dep.rv = read_version;
2629
- }
2630
- }
2631
- if (untracked_writes !== null) {
2632
- if (previous_untracked_writes === null) {
2633
- previous_untracked_writes = untracked_writes;
2634
- } else {
2635
- previous_untracked_writes.push(.../** @type {Source[]} */
2636
- untracked_writes);
2637
- }
2638
- }
2639
- }
2640
- if ((reaction.f & ERROR_VALUE) !== 0) {
2641
- reaction.f ^= ERROR_VALUE;
2642
- }
2643
- return result;
2644
- } catch (error) {
2645
- return handle_error(error);
2646
- } finally {
2647
- reaction.f ^= REACTION_IS_UPDATING;
2648
- new_deps = previous_deps;
2649
- skipped_deps = previous_skipped_deps;
2650
- untracked_writes = previous_untracked_writes;
2651
- active_reaction = previous_reaction;
2652
- current_sources = previous_sources;
2653
- set_component_context(previous_component_context);
2654
- untracking = previous_untracking;
2655
- update_version = previous_update_version;
2656
- }
2657
- }
2658
- function remove_reaction(signal, dependency) {
2659
- let reactions = dependency.reactions;
2660
- if (reactions !== null) {
2661
- var index = index_of.call(reactions, signal);
2662
- if (index !== -1) {
2663
- var new_length = reactions.length - 1;
2664
- if (new_length === 0) {
2665
- reactions = dependency.reactions = null;
2666
- } else {
2667
- reactions[index] = reactions[new_length];
2668
- reactions.pop();
2669
- }
2670
- }
2671
- }
2672
- if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
2673
- // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
2674
- // allows us to skip the expensive work of disconnecting and immediately reconnecting it
2675
- (new_deps === null || !includes.call(new_deps, dependency))) {
2676
- var derived2 = (
2677
- /** @type {Derived} */
2678
- dependency
2679
- );
2680
- if ((derived2.f & CONNECTED) !== 0) {
2681
- derived2.f ^= CONNECTED;
2682
- derived2.f &= ~WAS_MARKED;
2683
- }
2684
- if (derived2.v !== UNINITIALIZED) {
2685
- update_derived_status(derived2);
2686
- }
2687
- freeze_derived_effects(derived2);
2688
- remove_reactions(derived2, 0);
2689
- }
2690
- }
2691
- function remove_reactions(signal, start_index) {
2692
- var dependencies = signal.deps;
2693
- if (dependencies === null) return;
2694
- for (var i = start_index; i < dependencies.length; i++) {
2695
- remove_reaction(signal, dependencies[i]);
2696
- }
2697
- }
2698
- function update_effect(effect2) {
2699
- var flags = effect2.f;
2700
- if ((flags & DESTROYED) !== 0) {
2701
- return;
2702
- }
2703
- set_signal_status(effect2, CLEAN);
2704
- var previous_effect = active_effect;
2705
- var was_updating_effect = is_updating_effect;
2706
- active_effect = effect2;
2707
- is_updating_effect = true;
2708
- try {
2709
- if ((flags & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
2710
- destroy_block_effect_children(effect2);
2711
- } else {
2712
- destroy_effect_children(effect2);
2713
- }
2714
- execute_effect_teardown(effect2);
2715
- var teardown2 = update_reaction(effect2);
2716
- effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
2717
- effect2.wv = write_version;
2718
- var dep;
2719
- if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && effect2.deps !== null) ;
2720
- } finally {
2721
- is_updating_effect = was_updating_effect;
2722
- active_effect = previous_effect;
2723
- }
2724
- }
2725
- async function tick() {
2726
- await Promise.resolve();
2727
- flushSync();
2728
- }
2729
- function settled() {
2730
- return Batch.ensure().settled();
2731
- }
2732
- function get(signal) {
2733
- var flags = signal.f;
2734
- var is_derived = (flags & DERIVED) !== 0;
2735
- if (active_reaction !== null && !untracking) {
2736
- var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
2737
- if (!destroyed && (current_sources === null || !includes.call(current_sources, signal))) {
2738
- var deps = active_reaction.deps;
2739
- if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
2740
- if (signal.rv < read_version) {
2741
- signal.rv = read_version;
2742
- if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
2743
- skipped_deps++;
2744
- } else if (new_deps === null) {
2745
- new_deps = [signal];
2746
- } else {
2747
- new_deps.push(signal);
2748
- }
2749
- }
2750
- } else {
2751
- active_reaction.deps ??= [];
2752
- if (!includes.call(active_reaction.deps, signal)) {
2753
- active_reaction.deps.push(signal);
2754
- }
2755
- var reactions = signal.reactions;
2756
- if (reactions === null) {
2757
- signal.reactions = [active_reaction];
2758
- } else if (!includes.call(reactions, active_reaction)) {
2759
- reactions.push(active_reaction);
2760
- }
2761
- }
2762
- }
2763
- }
2764
- if (is_destroying_effect && old_values.has(signal)) {
2765
- return old_values.get(signal);
2766
- }
2767
- if (is_derived) {
2768
- var derived2 = (
2769
- /** @type {Derived} */
2770
- signal
2771
- );
2772
- if (is_destroying_effect) {
2773
- var value = derived2.v;
2774
- if ((derived2.f & CLEAN) === 0 && derived2.reactions !== null || depends_on_old_values(derived2)) {
2775
- value = execute_derived(derived2);
2776
- }
2777
- old_values.set(derived2, value);
2778
- return value;
2779
- }
2780
- var should_connect = (derived2.f & CONNECTED) === 0 && !untracking && active_reaction !== null && (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
2781
- var is_new = (derived2.f & REACTION_RAN) === 0;
2782
- if (is_dirty(derived2)) {
2783
- if (should_connect) {
2784
- derived2.f |= CONNECTED;
2785
- }
2786
- update_derived(derived2);
2787
- }
2788
- if (should_connect && !is_new) {
2789
- unfreeze_derived_effects(derived2);
2790
- reconnect(derived2);
2791
- }
2792
- }
2793
- if (batch_values?.has(signal)) {
2794
- return batch_values.get(signal);
2795
- }
2796
- if ((signal.f & ERROR_VALUE) !== 0) {
2797
- throw signal.v;
2798
- }
2799
- return signal.v;
2800
- }
2801
- function reconnect(derived2) {
2802
- derived2.f |= CONNECTED;
2803
- if (derived2.deps === null) return;
2804
- for (const dep of derived2.deps) {
2805
- (dep.reactions ??= []).push(derived2);
2806
- if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
2807
- unfreeze_derived_effects(
2808
- /** @type {Derived} */
2809
- dep
2810
- );
2811
- reconnect(
2812
- /** @type {Derived} */
2813
- dep
2814
- );
2815
- }
2816
- }
2817
- }
2818
- function depends_on_old_values(derived2) {
2819
- if (derived2.v === UNINITIALIZED) return true;
2820
- if (derived2.deps === null) return false;
2821
- for (const dep of derived2.deps) {
2822
- if (old_values.has(dep)) {
2823
- return true;
2824
- }
2825
- if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
2826
- /** @type {Derived} */
2827
- dep
2828
- )) {
2829
- return true;
2830
- }
2831
- }
2832
- return false;
2833
- }
2834
- function untrack(fn) {
2835
- var previous_untracking = untracking;
2836
- try {
2837
- untracking = true;
2838
- return fn();
2839
- } finally {
2840
- untracking = previous_untracking;
2841
- }
2842
- }
2843
- function deep_read_state(value) {
2844
- if (typeof value !== "object" || !value || value instanceof EventTarget) {
2845
- return;
2846
- }
2847
- if (STATE_SYMBOL in value) {
2848
- deep_read(value);
2849
- } else if (!Array.isArray(value)) {
2850
- for (let key in value) {
2851
- const prop = value[key];
2852
- if (typeof prop === "object" && prop && STATE_SYMBOL in prop) {
2853
- deep_read(prop);
2854
- }
2855
- }
2856
- }
2857
- }
2858
- function deep_read(value, visited = /* @__PURE__ */ new Set()) {
2859
- if (typeof value === "object" && value !== null && // We don't want to traverse DOM elements
2860
- !(value instanceof EventTarget) && !visited.has(value)) {
2861
- visited.add(value);
2862
- if (value instanceof Date) {
2863
- value.getTime();
2864
- }
2865
- for (let key in value) {
2866
- try {
2867
- deep_read(value[key], visited);
2868
- } catch (e) {
2869
- }
2870
- }
2871
- const proto = get_prototype_of(value);
2872
- if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
2873
- const descriptors = get_descriptors(proto);
2874
- for (let key in descriptors) {
2875
- const get2 = descriptors[key].get;
2876
- if (get2) {
2877
- try {
2878
- get2.call(value);
2879
- } catch (e) {
2880
- }
2881
- }
2882
- }
2883
- }
2884
- }
2885
- }
2886
- function onMount(fn) {
2887
- if (component_context === null) {
2888
- lifecycle_outside_component();
2889
- }
2890
- if (legacy_mode_flag && component_context.l !== null) {
2891
- init_update_callbacks(component_context).m.push(fn);
2892
- } else {
2893
- user_effect(() => {
2894
- const cleanup = untrack(fn);
2895
- if (typeof cleanup === "function") return (
2896
- /** @type {() => void} */
2897
- cleanup
2898
- );
2899
- });
2900
- }
2901
- }
2902
- function init_update_callbacks(context) {
2903
- var l = (
2904
- /** @type {ComponentContextLegacy} */
2905
- context.l
2906
- );
2907
- return l.u ??= { a: [], b: [], m: [] };
2908
- }
2909
- export {
2910
- $document as $,
2911
- ATTRIBUTES_CACHE as A,
2912
- BLOCK_EFFECT as B,
2913
- CLASS_CACHE as C,
2914
- DESTROYED as D,
2915
- EACH_INDEX_REACTIVE as E,
2916
- FORM_RESET_HANDLER as F,
2917
- TRANSITION_GLOBAL as G,
2918
- HEAD_EFFECT as H,
2919
- INERT as I,
2920
- active_effect as J,
2921
- active_reaction as K,
2922
- LEGACY_PROPS as L,
2923
- add_form_reset_listener as M,
2924
- NAMESPACE_HTML as N,
2925
- array_from as O,
2926
- PROPS_IS_BINDABLE as P,
2927
- block as Q,
2928
- REACTION_RAN as R,
2929
- STATE_SYMBOL as S,
2930
- TEMPLATE_FRAGMENT as T,
2931
- branch as U,
2932
- child as V,
2933
- clear_text_content as W,
2934
- component_context as X,
2935
- component_root as Y,
2936
- create_element as Z,
2937
- create_text as _,
2938
- BOUNDARY_EFFECT as a,
2939
- set_hydrate_node as a$,
2940
- current_batch as a0,
2941
- deep_read_state as a1,
2942
- defer_effect as a2,
2943
- deferred_template_effect as a3,
2944
- define_property as a4,
2945
- derived as a5,
2946
- derived$1 as a6,
2947
- derived_safe_equal as a7,
2948
- destroy_effect as a8,
2949
- each_key_duplicate as a9,
2950
- is_function as aA,
2951
- legacy_mode_flag as aB,
2952
- listen_to_event_and_reset_event as aC,
2953
- merge_text_nodes as aD,
2954
- move_effect as aE,
2955
- mutable_source as aF,
2956
- next as aG,
2957
- noop as aH,
2958
- onMount as aI,
2959
- pause_effect as aJ,
2960
- pop as aK,
2961
- props_invalid_value as aL,
2962
- proxy as aM,
2963
- push as aN,
2964
- queue_micro_task as aO,
2965
- read_hydration_instruction as aP,
2966
- remove_textarea_child as aQ,
2967
- render_effect as aR,
2968
- reset as aS,
2969
- resume_effect as aT,
2970
- run as aU,
2971
- run_all as aV,
2972
- select_multiple_invalid_value as aW,
2973
- set as aX,
2974
- set_active_effect as aY,
2975
- set_active_reaction as aZ,
2976
- set_component_context as a_,
2977
- effect as aa,
2978
- effect_tracking as ab,
2979
- enable_legacy_mode_flag as ac,
2980
- first_child as ad,
2981
- flushSync as ae,
2982
- get$1 as af,
2983
- get as ag,
2984
- get_descriptor as ah,
2985
- get_descriptors as ai,
2986
- get_first_child as aj,
2987
- get_next_sibling as ak,
2988
- get_prototype_of as al,
2989
- handle_error as am,
2990
- hydrate_next as an,
2991
- hydrate_node as ao,
2992
- hydrating as ap,
2993
- hydration_failed as aq,
2994
- hydration_mismatch as ar,
2995
- increment as as,
2996
- init_operations as at,
2997
- internal_set as au,
2998
- invoke_error_boundary as av,
2999
- is as aw,
3000
- is_array as ax,
3001
- is_destroying_effect as ay,
3002
- is_firefox as az,
3003
- BRANCH_EFFECT as b,
3004
- set_hydrating as b0,
3005
- settled as b1,
3006
- should_defer_append as b2,
3007
- sibling as b3,
3008
- skip_nodes as b4,
3009
- source as b5,
3010
- state as b6,
3011
- subscribe_to_store as b7,
3012
- svelte_boundary_reset_noop as b8,
3013
- svelte_boundary_reset_onerror as b9,
3014
- teardown as ba,
3015
- template_effect as bb,
3016
- tick as bc,
3017
- untrack as bd,
3018
- user_derived as be,
3019
- user_effect as bf,
3020
- user_pre_effect as bg,
3021
- without_reactive_context as bh,
3022
- writable as bi,
3023
- Batch as c,
3024
- COMMENT_NODE as d,
3025
- DESTROYING as e,
3026
- EACH_IS_ANIMATED as f,
3027
- EACH_IS_CONTROLLED as g,
3028
- EACH_ITEM_IMMUTABLE as h,
3029
- EACH_ITEM_REACTIVE as i,
3030
- EFFECT_OFFSCREEN as j,
3031
- EFFECT_PRESERVED as k,
3032
- EFFECT_TRANSPARENT as l,
3033
- HYDRATION_END as m,
3034
- HYDRATION_ERROR as n,
3035
- HYDRATION_START as o,
3036
- HYDRATION_START_ELSE as p,
3037
- HYDRATION_START_FAILED as q,
3038
- IS_XHTML as r,
3039
- LOADING_ATTR_SYMBOL as s,
3040
- PROPS_IS_IMMUTABLE as t,
3041
- PROPS_IS_LAZY_INITIAL as u,
3042
- PROPS_IS_RUNES as v,
3043
- PROPS_IS_UPDATED as w,
3044
- TEMPLATE_USE_IMPORT_NODE as x,
3045
- TEXT_CACHE as y,
3046
- TEXT_NODE as z
3047
- };
3048
- //# sourceMappingURL=rMw82gDs.js.map