@pie-element/mc-populated-blank 0.2.13-next.3 → 0.3.0-next.4

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.
@@ -1,14 +1,14 @@
1
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/disclose-version.js
1
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/disclose-version.js
2
2
  if (typeof window !== "undefined") {
3
3
  var _window$__svelte, _window;
4
4
  ((_window$__svelte = (_window = window).__svelte ?? (_window.__svelte = {})).v ?? (_window$__svelte.v = /* @__PURE__ */ new Set())).add("5");
5
5
  }
6
6
  //#endregion
7
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/constants.js
7
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/constants.js
8
8
  var HYDRATION_ERROR = {};
9
9
  var UNINITIALIZED = Symbol("uninitialized");
10
10
  //#endregion
11
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/shared/utils.js
11
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/shared/utils.js
12
12
  var is_array = Array.isArray;
13
13
  var index_of = Array.prototype.indexOf;
14
14
  var includes = Array.prototype.includes;
@@ -44,7 +44,7 @@ function deferred() {
44
44
  };
45
45
  }
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
47
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
48
48
  function _typeof(o) {
49
49
  "@babel/helpers - typeof";
50
50
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -54,7 +54,7 @@ function _typeof(o) {
54
54
  }, _typeof(o);
55
55
  }
56
56
  //#endregion
57
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
57
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
58
58
  function toPrimitive(t, r) {
59
59
  if ("object" != _typeof(t) || !t) return t;
60
60
  var e = t[Symbol.toPrimitive];
@@ -66,13 +66,13 @@ function toPrimitive(t, r) {
66
66
  return ("string" === r ? String : Number)(t);
67
67
  }
68
68
  //#endregion
69
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
69
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
70
70
  function toPropertyKey(t) {
71
71
  var i = toPrimitive(t, "string");
72
72
  return "symbol" == _typeof(i) ? i : i + "";
73
73
  }
74
74
  //#endregion
75
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
75
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
76
76
  function _defineProperty(e, r, t) {
77
77
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
78
78
  value: t,
@@ -191,7 +191,7 @@ function svelte_boundary_reset_noop() {
191
191
  console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
192
192
  }
193
193
  //#endregion
194
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/hydration.js
194
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/hydration.js
195
195
  /** @import { TemplateNode } from '#client' */
196
196
  /**
197
197
  * Use this variable to guard everything related to hydration code so it can be treeshaken out
@@ -250,7 +250,7 @@ function skip_nodes(remove = true) {
250
250
  }
251
251
  }
252
252
  //#endregion
253
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/equality.js
253
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/equality.js
254
254
  /** @import { Equals } from '#client' */
255
255
  /** @type {Equals} */
256
256
  function equals(value) {
@@ -269,13 +269,13 @@ function safe_equals(value) {
269
269
  return !safe_not_equal(value, this.v);
270
270
  }
271
271
  //#endregion
272
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/flags/index.js
272
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/flags/index.js
273
273
  /** True if experimental.async=true */
274
274
  var async_mode_flag = false;
275
275
  /** True if we're not certain that we only have Svelte 5 code in the compilation */
276
276
  var legacy_mode_flag = false;
277
277
  //#endregion
278
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/context.js
278
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/context.js
279
279
  /** @import { ComponentContext, DevStackEntry, Effect } from '#client' */
280
280
  /** @type {ComponentContext | null} */
281
281
  var component_context = null;
@@ -327,7 +327,7 @@ function is_runes() {
327
327
  return !legacy_mode_flag || component_context !== null && component_context.l === null;
328
328
  }
329
329
  //#endregion
330
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/task.js
330
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/task.js
331
331
  /** @type {Array<() => void>} */
332
332
  var micro_tasks = [];
333
333
  function run_micro_tasks() {
@@ -370,6 +370,7 @@ function handle_error(error) {
370
370
  * @param {Effect | null} effect
371
371
  */
372
372
  function invoke_error_boundary(error, effect) {
373
+ if (effect !== null && (effect.f & 16384) !== 0) return;
373
374
  while (effect !== null) {
374
375
  if ((effect.f & 128) !== 0) {
375
376
  if ((effect.f & 32768) === 0) throw error;
@@ -385,7 +386,7 @@ function invoke_error_boundary(error, effect) {
385
386
  throw error;
386
387
  }
387
388
  //#endregion
388
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/status.js
389
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/status.js
389
390
  /** @import { Derived, Signal } from '#client' */
390
391
  var STATUS_MASK = ~(DIRTY | MAYBE_DIRTY | CLEAN);
391
392
  /**
@@ -404,7 +405,7 @@ function update_derived_status(derived) {
404
405
  else set_signal_status(derived, MAYBE_DIRTY);
405
406
  }
406
407
  //#endregion
407
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/utils.js
408
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/utils.js
408
409
  /** @import { Derived, Effect, Value } from '#client' */
409
410
  /**
410
411
  * @param {Value[] | null} deps
@@ -432,7 +433,7 @@ function defer_effect(effect, dirty_effects, maybe_dirty_effects) {
432
433
  set_signal_status(effect, CLEAN);
433
434
  }
434
435
  //#endregion
435
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/store.js
436
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/store.js
436
437
  /**
437
438
  * We set this to `true` when updating a store so that we correctly
438
439
  * schedule effects if the update takes place inside a `$:` effect
@@ -462,1287 +463,1329 @@ function capture_store_binding(fn) {
462
463
  }
463
464
  }
464
465
  //#endregion
465
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/checkPrivateRedeclaration.js
466
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/elements/bindings/shared.js
467
+ /**
468
+ * @template T
469
+ * @param {() => T} fn
470
+ */
471
+ function without_reactive_context(fn) {
472
+ var previous_reaction = active_reaction;
473
+ var previous_effect = active_effect;
474
+ set_active_reaction(null);
475
+ set_active_effect(null);
476
+ try {
477
+ return fn();
478
+ } finally {
479
+ set_active_reaction(previous_reaction);
480
+ set_active_effect(previous_effect);
481
+ }
482
+ }
483
+ //#endregion
484
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/reactivity/create-subscriber.js
485
+ /**
486
+ * Returns a `subscribe` function that integrates external event-based systems with Svelte's reactivity.
487
+ * It's particularly useful for integrating with web APIs like `MediaQuery`, `IntersectionObserver`, or `WebSocket`.
488
+ *
489
+ * If `subscribe` is called inside an effect (including indirectly, for example inside a getter),
490
+ * the `start` callback will be called with an `update` function. Whenever `update` is called, the effect re-runs.
491
+ *
492
+ * If `start` returns a cleanup function, it will be called when the effect is destroyed.
493
+ *
494
+ * If `subscribe` is called in multiple effects, `start` will only be called once as long as the effects
495
+ * are active, and the returned teardown function will only be called when all effects are destroyed.
496
+ *
497
+ * It's best understood with an example. Here's an implementation of [`MediaQuery`](https://svelte.dev/docs/svelte/svelte-reactivity#MediaQuery):
498
+ *
499
+ * ```js
500
+ * import { createSubscriber } from 'svelte/reactivity';
501
+ * import { on } from 'svelte/events';
502
+ *
503
+ * export class MediaQuery {
504
+ * #query;
505
+ * #subscribe;
506
+ *
507
+ * constructor(query) {
508
+ * this.#query = window.matchMedia(`(${query})`);
509
+ *
510
+ * this.#subscribe = createSubscriber((update) => {
511
+ * // when the `change` event occurs, re-run any effects that read `this.current`
512
+ * const off = on(this.#query, 'change', update);
513
+ *
514
+ * // stop listening when all the effects are destroyed
515
+ * return () => off();
516
+ * });
517
+ * }
518
+ *
519
+ * get current() {
520
+ * // This makes the getter reactive, if read in an effect
521
+ * this.#subscribe();
522
+ *
523
+ * // Return the current state of the query, whether or not we're in an effect
524
+ * return this.#query.matches;
525
+ * }
526
+ * }
527
+ * ```
528
+ * @param {(update: () => void) => (() => void) | void} start
529
+ * @since 5.7.0
530
+ */
531
+ function createSubscriber(start) {
532
+ let subscribers = 0;
533
+ let version = source(0);
534
+ /** @type {(() => void) | void} */
535
+ let stop;
536
+ return () => {
537
+ if (effect_tracking()) {
538
+ get(version);
539
+ render_effect(() => {
540
+ if (subscribers === 0) stop = untrack(() => start(() => increment(version)));
541
+ subscribers += 1;
542
+ return () => {
543
+ queue_micro_task(() => {
544
+ subscribers -= 1;
545
+ if (subscribers === 0) {
546
+ stop?.();
547
+ stop = void 0;
548
+ increment(version);
549
+ }
550
+ });
551
+ };
552
+ });
553
+ }
554
+ };
555
+ }
556
+ //#endregion
557
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/checkPrivateRedeclaration.js
466
558
  function _checkPrivateRedeclaration(e, t) {
467
559
  if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
468
560
  }
469
561
  //#endregion
470
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/classPrivateMethodInitSpec.js
562
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/classPrivateMethodInitSpec.js
471
563
  function _classPrivateMethodInitSpec(e, a) {
472
564
  _checkPrivateRedeclaration(e, a), a.add(e);
473
565
  }
474
566
  //#endregion
475
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/classPrivateFieldInitSpec.js
567
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/classPrivateFieldInitSpec.js
476
568
  function _classPrivateFieldInitSpec(e, t, a) {
477
569
  _checkPrivateRedeclaration(e, t), t.set(e, a);
478
570
  }
479
571
  //#endregion
480
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/assertClassBrand.js
572
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/assertClassBrand.js
481
573
  function _assertClassBrand(e, t, n) {
482
574
  if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
483
575
  throw new TypeError("Private element is not present on this object");
484
576
  }
485
577
  //#endregion
486
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/classPrivateFieldSet2.js
578
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/classPrivateFieldSet2.js
487
579
  function _classPrivateFieldSet2(s, a, r) {
488
580
  return s.set(_assertClassBrand(s, a), r), r;
489
581
  }
490
582
  //#endregion
491
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/classPrivateFieldGet2.js
583
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/classPrivateFieldGet2.js
492
584
  function _classPrivateFieldGet2(s, a) {
493
585
  return s.get(_assertClassBrand(s, a));
494
586
  }
495
587
  //#endregion
496
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/batch.js
497
- /** @import { Fork } from 'svelte' */
498
- /** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
499
- var _Batch;
500
- /** @type {Batch | null} */
501
- var first_batch = null;
502
- /** @type {Batch | null} */
503
- var last_batch = null;
504
- /** @type {Batch | null} */
505
- var current_batch = null;
506
- /**
507
- * This is needed to avoid overwriting inputs
508
- * @type {Batch | null}
509
- */
510
- var previous_batch = null;
511
- /**
512
- * When time travelling (i.e. working in one batch, while other batches
513
- * still have ongoing work), we ignore the real values of affected
514
- * signals in favour of their values within the batch
515
- * @type {Map<Value, any> | null}
516
- */
517
- var batch_values = null;
518
- /** @type {Effect | null} */
519
- var last_scheduled_effect = null;
520
- var is_flushing_sync = false;
521
- var is_processing = false;
588
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/blocks/boundary.js
589
+ /** @import { Effect, Source, TemplateNode, } from '#client' */
522
590
  /**
523
- * During traversal, this is an array. Newly created effects are (if not immediately
524
- * executed) pushed to this array, rather than going through the scheduling
525
- * rigamarole that would cause another turn of the flush loop.
526
- * @type {Effect[] | null}
591
+ * @typedef {{
592
+ * onerror?: ((error: unknown, reset: () => void) => void) | null;
593
+ * failed?: ((anchor: Node, error: () => unknown, reset: () => () => void) => void) | null;
594
+ * pending?: ((anchor: Node) => void) | null;
595
+ * }} BoundaryProps
527
596
  */
528
- var collected_effects = null;
597
+ var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
529
598
  /**
530
- * An array of effects that are marked during traversal as a result of a `set`
531
- * (not `internal_set`) call. These will be added to the next batch and
532
- * trigger another `batch.process()`
533
- * @type {Effect[] | null}
534
- * @deprecated when we get rid of legacy mode and stores, we can get rid of this
599
+ * @param {TemplateNode} node
600
+ * @param {BoundaryProps} props
601
+ * @param {((anchor: Node) => void)} children
602
+ * @param {((error: unknown) => unknown) | undefined} [transform_error]
603
+ * @returns {void}
535
604
  */
536
- var legacy_updates = null;
537
- var flush_count = 0;
538
- var uid = 1;
539
- var _started = /* @__PURE__ */ new WeakMap();
540
- var _prev = /* @__PURE__ */ new WeakMap();
541
- var _next = /* @__PURE__ */ new WeakMap();
542
- var _commit_callbacks = /* @__PURE__ */ new WeakMap();
543
- var _discard_callbacks = /* @__PURE__ */ new WeakMap();
544
- var _pending = /* @__PURE__ */ new WeakMap();
545
- var _blocking_pending = /* @__PURE__ */ new WeakMap();
546
- var _deferred = /* @__PURE__ */ new WeakMap();
547
- var _roots = /* @__PURE__ */ new WeakMap();
548
- var _new_effects = /* @__PURE__ */ new WeakMap();
605
+ function boundary(node, props, children, transform_error) {
606
+ new Boundary(node, props, children, transform_error);
607
+ }
608
+ var _anchor = /* @__PURE__ */ new WeakMap();
609
+ var _hydrate_open = /* @__PURE__ */ new WeakMap();
610
+ var _props = /* @__PURE__ */ new WeakMap();
611
+ var _children = /* @__PURE__ */ new WeakMap();
612
+ var _effect = /* @__PURE__ */ new WeakMap();
613
+ var _main_effect = /* @__PURE__ */ new WeakMap();
614
+ var _pending_effect = /* @__PURE__ */ new WeakMap();
615
+ var _failed_effect = /* @__PURE__ */ new WeakMap();
616
+ var _offscreen_fragment = /* @__PURE__ */ new WeakMap();
617
+ var _local_pending_count = /* @__PURE__ */ new WeakMap();
618
+ var _pending_count = /* @__PURE__ */ new WeakMap();
619
+ var _pending_count_update_queued = /* @__PURE__ */ new WeakMap();
549
620
  var _dirty_effects$1 = /* @__PURE__ */ new WeakMap();
550
621
  var _maybe_dirty_effects$1 = /* @__PURE__ */ new WeakMap();
551
- var _skipped_branches = /* @__PURE__ */ new WeakMap();
552
- var _unskipped_branches = /* @__PURE__ */ new WeakMap();
553
- var _decrement_queued = /* @__PURE__ */ new WeakMap();
554
- var _Batch_brand = /* @__PURE__ */ new WeakSet();
555
- var Batch = class Batch {
556
- constructor() {
557
- _classPrivateMethodInitSpec(this, _Batch_brand);
558
- _defineProperty(this, "id", uid++);
559
- _classPrivateFieldInitSpec(this, _started, false);
560
- _defineProperty(this, "linked", true);
561
- _classPrivateFieldInitSpec(this, _prev, null);
562
- _classPrivateFieldInitSpec(this, _next, null);
563
- _defineProperty(
564
- this,
565
- /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
566
- "async_deriveds",
567
- /* @__PURE__ */ new Map()
568
- );
622
+ var _effect_pending = /* @__PURE__ */ new WeakMap();
623
+ var _effect_pending_subscriber = /* @__PURE__ */ new WeakMap();
624
+ var _Boundary_brand = /* @__PURE__ */ new WeakSet();
625
+ var Boundary = class {
626
+ /**
627
+ * @param {TemplateNode} node
628
+ * @param {BoundaryProps} props
629
+ * @param {((anchor: Node) => void)} children
630
+ * @param {((error: unknown) => unknown) | undefined} [transform_error]
631
+ */
632
+ constructor(node, props, children, transform_error) {
633
+ _classPrivateMethodInitSpec(this, _Boundary_brand);
569
634
  _defineProperty(
570
635
  this,
571
- /**
572
- * The current values of any signals that are updated in this batch.
573
- * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
574
- * They keys of this map are identical to `this.#previous`
575
- * @type {Map<Value, [any, boolean]>}
576
- */
577
- "current",
578
- /* @__PURE__ */ new Map()
636
+ /** @type {Boundary | null} */
637
+ "parent",
638
+ void 0
579
639
  );
640
+ _defineProperty(this, "is_pending", false);
580
641
  _defineProperty(
581
642
  this,
582
643
  /**
583
- * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
584
- * They keys of this map are identical to `this.#current`
585
- * @type {Map<Value, any>}
644
+ * API-level transformError transform function. Transforms errors before they reach the `failed` snippet.
645
+ * Inherited from parent boundary, or defaults to identity.
646
+ * @type {(error: unknown) => unknown}
586
647
  */
587
- "previous",
588
- /* @__PURE__ */ new Map()
648
+ "transform_error",
649
+ void 0
589
650
  );
590
- _classPrivateFieldInitSpec(this, _commit_callbacks, /* @__PURE__ */ new Set());
591
- _classPrivateFieldInitSpec(this, _discard_callbacks, /* @__PURE__ */ new Set());
592
- _classPrivateFieldInitSpec(this, _pending, 0);
593
- _classPrivateFieldInitSpec(this, _blocking_pending, /* @__PURE__ */ new Map());
594
- _classPrivateFieldInitSpec(this, _deferred, null);
595
- _classPrivateFieldInitSpec(this, _roots, []);
596
- _classPrivateFieldInitSpec(this, _new_effects, []);
651
+ _classPrivateFieldInitSpec(this, _anchor, void 0);
652
+ _classPrivateFieldInitSpec(this, _hydrate_open, hydrating ? hydrate_node : null);
653
+ _classPrivateFieldInitSpec(this, _props, void 0);
654
+ _classPrivateFieldInitSpec(this, _children, void 0);
655
+ _classPrivateFieldInitSpec(this, _effect, void 0);
656
+ _classPrivateFieldInitSpec(this, _main_effect, null);
657
+ _classPrivateFieldInitSpec(this, _pending_effect, null);
658
+ _classPrivateFieldInitSpec(this, _failed_effect, null);
659
+ _classPrivateFieldInitSpec(this, _offscreen_fragment, null);
660
+ _classPrivateFieldInitSpec(this, _local_pending_count, 0);
661
+ _classPrivateFieldInitSpec(this, _pending_count, 0);
662
+ _classPrivateFieldInitSpec(this, _pending_count_update_queued, false);
597
663
  _classPrivateFieldInitSpec(this, _dirty_effects$1, /* @__PURE__ */ new Set());
598
664
  _classPrivateFieldInitSpec(this, _maybe_dirty_effects$1, /* @__PURE__ */ new Set());
599
- _classPrivateFieldInitSpec(this, _skipped_branches, /* @__PURE__ */ new Map());
600
- _classPrivateFieldInitSpec(this, _unskipped_branches, /* @__PURE__ */ new Set());
601
- _defineProperty(this, "is_fork", false);
602
- _classPrivateFieldInitSpec(this, _decrement_queued, false);
603
- if (last_batch === null) first_batch = last_batch = this;
604
- else {
605
- _classPrivateFieldSet2(_next, last_batch, this);
606
- _classPrivateFieldSet2(_prev, this, last_batch);
607
- }
608
- last_batch = this;
609
- }
610
- /**
611
- * Add an effect to the #skipped_branches map and reset its children
612
- * @param {Effect} effect
613
- */
614
- skip_effect(effect) {
615
- if (!_classPrivateFieldGet2(_skipped_branches, this).has(effect)) _classPrivateFieldGet2(_skipped_branches, this).set(effect, {
616
- d: [],
617
- m: []
618
- });
619
- _classPrivateFieldGet2(_unskipped_branches, this).delete(effect);
665
+ _classPrivateFieldInitSpec(this, _effect_pending, null);
666
+ _classPrivateFieldInitSpec(this, _effect_pending_subscriber, createSubscriber(() => {
667
+ _classPrivateFieldSet2(_effect_pending, this, source(_classPrivateFieldGet2(_local_pending_count, this)));
668
+ return () => {
669
+ _classPrivateFieldSet2(_effect_pending, this, null);
670
+ };
671
+ }));
672
+ _classPrivateFieldSet2(_anchor, this, node);
673
+ _classPrivateFieldSet2(_props, this, props);
674
+ _classPrivateFieldSet2(_children, this, (anchor) => {
675
+ var effect = active_effect;
676
+ effect.b = this;
677
+ effect.f |= 128;
678
+ children(anchor);
679
+ });
680
+ this.parent = active_effect.b;
681
+ this.transform_error = transform_error ?? this.parent?.transform_error ?? ((e) => e);
682
+ _classPrivateFieldSet2(_effect, this, block(() => {
683
+ if (hydrating) {
684
+ const comment = _classPrivateFieldGet2(_hydrate_open, this);
685
+ hydrate_next();
686
+ const server_rendered_pending = comment.data === "[!";
687
+ if (comment.data.startsWith("[?")) {
688
+ const serialized_error = JSON.parse(comment.data.slice(2));
689
+ _assertClassBrand(_Boundary_brand, this, _hydrate_failed_content).call(this, serialized_error);
690
+ } else if (server_rendered_pending) _assertClassBrand(_Boundary_brand, this, _hydrate_pending_content).call(this);
691
+ else _assertClassBrand(_Boundary_brand, this, _hydrate_resolved_content).call(this);
692
+ } else _assertClassBrand(_Boundary_brand, this, _render).call(this);
693
+ }, flags));
694
+ if (hydrating) _classPrivateFieldSet2(_anchor, this, hydrate_node);
620
695
  }
621
696
  /**
622
- * Remove an effect from the #skipped_branches map and reschedule
623
- * any tracked dirty/maybe_dirty child effects
697
+ * Defer an effect inside a pending boundary until the boundary resolves
624
698
  * @param {Effect} effect
625
- * @param {(e: Effect) => void} callback
626
- */
627
- unskip_effect(effect, callback = (e) => this.schedule(e)) {
628
- var tracked = _classPrivateFieldGet2(_skipped_branches, this).get(effect);
629
- if (tracked) {
630
- _classPrivateFieldGet2(_skipped_branches, this).delete(effect);
631
- for (var e of tracked.d) {
632
- set_signal_status(e, DIRTY);
633
- callback(e);
634
- }
635
- for (e of tracked.m) {
636
- set_signal_status(e, MAYBE_DIRTY);
637
- callback(e);
638
- }
639
- }
640
- _classPrivateFieldGet2(_unskipped_branches, this).add(effect);
641
- }
642
- /**
643
- * Associate a change to a given source with the current
644
- * batch, noting its previous and current values
645
- * @param {Value} source
646
- * @param {any} value
647
- * @param {boolean} [is_derived]
648
699
  */
649
- capture(source, value, is_derived = false) {
650
- if (source.v !== UNINITIALIZED && !this.previous.has(source)) this.previous.set(source, source.v);
651
- if ((source.f & 8388608) === 0) {
652
- this.current.set(source, [value, is_derived]);
653
- batch_values?.set(source, value);
654
- }
655
- if (!this.is_fork) source.v = value;
656
- }
657
- activate() {
658
- current_batch = this;
659
- }
660
- deactivate() {
661
- current_batch = null;
662
- batch_values = null;
663
- }
664
- flush() {
665
- try {
666
- is_processing = true;
667
- current_batch = this;
668
- _assertClassBrand(_Batch_brand, this, _process).call(this);
669
- } finally {
670
- flush_count = 0;
671
- last_scheduled_effect = null;
672
- collected_effects = null;
673
- legacy_updates = null;
674
- is_processing = false;
675
- current_batch = null;
676
- batch_values = null;
677
- old_values.clear();
678
- }
679
- }
680
- discard() {
681
- for (const fn of _classPrivateFieldGet2(_discard_callbacks, this)) fn(this);
682
- _classPrivateFieldGet2(_discard_callbacks, this).clear();
683
- _assertClassBrand(_Batch_brand, this, _unlink).call(this);
684
- _classPrivateFieldGet2(_deferred, this)?.resolve();
700
+ defer_effect(effect) {
701
+ defer_effect(effect, _classPrivateFieldGet2(_dirty_effects$1, this), _classPrivateFieldGet2(_maybe_dirty_effects$1, this));
685
702
  }
686
703
  /**
687
- * @param {Effect} effect
704
+ * Returns `false` if the effect exists inside a boundary whose pending snippet is shown
705
+ * @returns {boolean}
688
706
  */
689
- register_created_effect(effect) {
690
- _classPrivateFieldGet2(_new_effects, this).push(effect);
707
+ is_rendered() {
708
+ return !this.is_pending && (!this.parent || this.parent.is_rendered());
691
709
  }
692
- /**
693
- * @param {boolean} blocking
694
- * @param {Effect} effect
695
- */
696
- increment(blocking, effect) {
697
- _classPrivateFieldSet2(_pending, this, _classPrivateFieldGet2(_pending, this) + 1);
698
- if (blocking) {
699
- let blocking_pending_count = _classPrivateFieldGet2(_blocking_pending, this).get(effect) ?? 0;
700
- _classPrivateFieldGet2(_blocking_pending, this).set(effect, blocking_pending_count + 1);
701
- }
710
+ has_pending_snippet() {
711
+ return !!_classPrivateFieldGet2(_props, this).pending;
702
712
  }
703
713
  /**
704
- * @param {boolean} blocking
705
- * @param {Effect} effect
714
+ * Update the source that powers `$effect.pending()` inside this boundary,
715
+ * and controls when the current `pending` snippet (if any) is removed.
716
+ * Do not call from inside the class
717
+ * @param {1 | -1} d
718
+ * @param {Batch} batch
706
719
  */
707
- decrement(blocking, effect) {
708
- _classPrivateFieldSet2(_pending, this, _classPrivateFieldGet2(_pending, this) - 1);
709
- if (blocking) {
710
- let blocking_pending_count = _classPrivateFieldGet2(_blocking_pending, this).get(effect) ?? 0;
711
- if (blocking_pending_count === 1) _classPrivateFieldGet2(_blocking_pending, this).delete(effect);
712
- else _classPrivateFieldGet2(_blocking_pending, this).set(effect, blocking_pending_count - 1);
713
- }
714
- if (_classPrivateFieldGet2(_decrement_queued, this)) return;
715
- _classPrivateFieldSet2(_decrement_queued, this, true);
720
+ update_pending_count(d, batch) {
721
+ _assertClassBrand(_Boundary_brand, this, _update_pending_count).call(this, d, batch);
722
+ _classPrivateFieldSet2(_local_pending_count, this, _classPrivateFieldGet2(_local_pending_count, this) + d);
723
+ if (!_classPrivateFieldGet2(_effect_pending, this) || _classPrivateFieldGet2(_pending_count_update_queued, this)) return;
724
+ _classPrivateFieldSet2(_pending_count_update_queued, this, true);
716
725
  queue_micro_task(() => {
717
- _classPrivateFieldSet2(_decrement_queued, this, false);
718
- if (this.linked) this.flush();
726
+ _classPrivateFieldSet2(_pending_count_update_queued, this, false);
727
+ if (_classPrivateFieldGet2(_effect_pending, this)) internal_set(_classPrivateFieldGet2(_effect_pending, this), _classPrivateFieldGet2(_local_pending_count, this));
719
728
  });
720
729
  }
721
- /**
722
- * @param {Set<Effect>} dirty_effects
723
- * @param {Set<Effect>} maybe_dirty_effects
724
- */
725
- transfer_effects(dirty_effects, maybe_dirty_effects) {
726
- for (const e of dirty_effects) _classPrivateFieldGet2(_dirty_effects$1, this).add(e);
727
- for (const e of maybe_dirty_effects) _classPrivateFieldGet2(_maybe_dirty_effects$1, this).add(e);
728
- dirty_effects.clear();
729
- maybe_dirty_effects.clear();
730
- }
731
- /** @param {(batch: Batch) => void} fn */
732
- oncommit(fn) {
733
- _classPrivateFieldGet2(_commit_callbacks, this).add(fn);
734
- }
735
- /** @param {(batch: Batch) => void} fn */
736
- ondiscard(fn) {
737
- _classPrivateFieldGet2(_discard_callbacks, this).add(fn);
738
- }
739
- settled() {
740
- return (_classPrivateFieldGet2(_deferred, this) ?? _classPrivateFieldSet2(_deferred, this, deferred())).promise;
730
+ get_effect_pending() {
731
+ _classPrivateFieldGet2(_effect_pending_subscriber, this).call(this);
732
+ return get(_classPrivateFieldGet2(_effect_pending, this));
741
733
  }
742
- static ensure() {
743
- if (current_batch === null) {
744
- const batch = current_batch = new Batch();
745
- if (!is_processing && !is_flushing_sync) queue_micro_task(() => {
746
- if (!_classPrivateFieldGet2(_started, batch)) batch.flush();
734
+ /** @param {unknown} error */
735
+ error(error) {
736
+ if (!_classPrivateFieldGet2(_props, this).onerror && !_classPrivateFieldGet2(_props, this).failed) throw error;
737
+ if (current_batch?.is_fork) {
738
+ if (_classPrivateFieldGet2(_main_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_main_effect, this));
739
+ if (_classPrivateFieldGet2(_pending_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_pending_effect, this));
740
+ if (_classPrivateFieldGet2(_failed_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_failed_effect, this));
741
+ current_batch.oncommit(() => {
742
+ _assertClassBrand(_Boundary_brand, this, _handle_error).call(this, error);
747
743
  });
748
- }
749
- return current_batch;
744
+ } else _assertClassBrand(_Boundary_brand, this, _handle_error).call(this, error);
750
745
  }
751
- apply() {
752
- if (!async_mode_flag || !this.is_fork && _classPrivateFieldGet2(_prev, this) === null && _classPrivateFieldGet2(_next, this) === null) {
753
- batch_values = null;
754
- return;
755
- }
756
- batch_values = /* @__PURE__ */ new Map();
757
- for (const [source, [value]] of this.current) batch_values.set(source, value);
758
- for (let batch = first_batch; batch !== null; batch = _classPrivateFieldGet2(_next, batch)) {
759
- if (batch === this || batch.is_fork) continue;
760
- var intersects = false;
761
- if (batch.id < this.id) for (const [source, [, is_derived]] of batch.current) {
762
- if (is_derived) continue;
763
- if (this.current.has(source)) {
764
- intersects = true;
765
- break;
766
- }
767
- }
768
- if (!intersects) {
769
- for (const [source, previous] of batch.previous) if (!batch_values.has(source)) batch_values.set(source, previous);
770
- }
771
- }
746
+ };
747
+ function _hydrate_resolved_content() {
748
+ try {
749
+ _classPrivateFieldSet2(_main_effect, this, branch(() => _classPrivateFieldGet2(_children, this).call(this, _classPrivateFieldGet2(_anchor, this))));
750
+ } catch (error) {
751
+ this.error(error);
772
752
  }
773
- /**
774
- *
775
- * @param {Effect} effect
776
- */
777
- schedule(effect) {
778
- last_scheduled_effect = effect;
779
- if (effect.b?.is_pending && (effect.f & 16777228) !== 0 && (effect.f & 32768) === 0) {
780
- effect.b.defer_effect(effect);
753
+ }
754
+ /**
755
+ * @param {unknown} error The deserialized error from the server's hydration comment
756
+ */
757
+ function _hydrate_failed_content(error) {
758
+ const failed = _classPrivateFieldGet2(_props, this).failed;
759
+ const { reset, invoke_onerror } = _assertClassBrand(_Boundary_brand, this, _create_reset).call(this, error);
760
+ queue_micro_task(invoke_onerror);
761
+ if (!failed) return;
762
+ _classPrivateFieldSet2(_failed_effect, this, branch(() => {
763
+ failed(_classPrivateFieldGet2(_anchor, this), () => error, () => reset);
764
+ }));
765
+ }
766
+ /**
767
+ * Creates the `reset` function for a failed boundary, along with a function
768
+ * that invokes `onerror` with it (if provided)
769
+ * @param {unknown} error
770
+ * @returns {{ reset: () => void, invoke_onerror: () => void }}
771
+ */
772
+ function _create_reset(error) {
773
+ var did_reset = false;
774
+ var calling_on_error = false;
775
+ const reset = () => {
776
+ if (did_reset) {
777
+ svelte_boundary_reset_noop();
781
778
  return;
782
779
  }
783
- var e = effect;
784
- while (e.parent !== null) {
785
- e = e.parent;
786
- var flags = e.f;
787
- if (collected_effects !== null && e === active_effect) {
788
- if (async_mode_flag) return;
789
- if ((active_reaction === null || (active_reaction.f & 2) === 0) && !legacy_is_updating_store) return;
790
- }
791
- if ((flags & 96) !== 0) {
792
- if ((flags & 1024) === 0) return;
793
- e.f ^= CLEAN;
794
- }
780
+ did_reset = true;
781
+ if (calling_on_error) svelte_boundary_reset_onerror();
782
+ if (_classPrivateFieldGet2(_failed_effect, this) !== null) pause_effect(_classPrivateFieldGet2(_failed_effect, this), () => {
783
+ _classPrivateFieldSet2(_failed_effect, this, null);
784
+ });
785
+ _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
786
+ _assertClassBrand(_Boundary_brand, this, _render).call(this);
787
+ });
788
+ };
789
+ const invoke_onerror = () => {
790
+ try {
791
+ calling_on_error = true;
792
+ _classPrivateFieldGet2(_props, this).onerror?.(error, reset);
793
+ calling_on_error = false;
794
+ } catch (err) {
795
+ invoke_error_boundary(err, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent);
795
796
  }
796
- _classPrivateFieldGet2(_roots, this).push(e);
797
- }
798
- };
799
- _Batch = Batch;
800
- function _is_deferred() {
801
- if (this.is_fork) return true;
802
- for (const effect of _classPrivateFieldGet2(_blocking_pending, this).keys()) {
803
- var e = effect;
804
- var skipped = false;
805
- while (e.parent !== null) {
806
- if (_classPrivateFieldGet2(_skipped_branches, this).has(e)) {
807
- skipped = true;
808
- break;
809
- }
810
- e = e.parent;
811
- }
812
- if (!skipped) return true;
813
- }
814
- return false;
815
- }
816
- function _process() {
817
- _classPrivateFieldSet2(_started, this, true);
818
- if (flush_count++ > 1e3) {
819
- _assertClassBrand(_Batch_brand, this, _unlink).call(this);
820
- infinite_loop_guard();
821
- }
822
- for (const e of _classPrivateFieldGet2(_dirty_effects$1, this)) {
823
- _classPrivateFieldGet2(_maybe_dirty_effects$1, this).delete(e);
824
- set_signal_status(e, DIRTY);
825
- this.schedule(e);
826
- }
827
- for (const e of _classPrivateFieldGet2(_maybe_dirty_effects$1, this)) {
828
- set_signal_status(e, MAYBE_DIRTY);
829
- this.schedule(e);
830
- }
831
- const roots = _classPrivateFieldGet2(_roots, this);
832
- _classPrivateFieldSet2(_roots, this, []);
833
- this.apply();
834
- /** @type {Effect[]} */
835
- var effects = collected_effects = [];
836
- /** @type {Effect[]} */
837
- var render_effects = [];
838
- /**
839
- * @type {Effect[]}
840
- * @deprecated when we get rid of legacy mode and stores, we can get rid of this
841
- */
842
- var updates = legacy_updates = [];
843
- for (const root of roots) try {
844
- _assertClassBrand(_Batch_brand, this, _traverse).call(this, root, effects, render_effects);
845
- } catch (e) {
846
- reset_all(root);
847
- if (!_assertClassBrand(_Batch_brand, this, _is_deferred).call(this)) this.discard();
848
- throw e;
849
- }
850
- current_batch = null;
851
- if (updates.length > 0) {
852
- var batch = _Batch.ensure();
853
- for (const e of updates) batch.schedule(e);
854
- }
855
- collected_effects = null;
856
- legacy_updates = null;
857
- if (_assertClassBrand(_Batch_brand, this, _is_deferred).call(this)) {
858
- _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, render_effects);
859
- _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, effects);
860
- for (const [e, t] of _classPrivateFieldGet2(_skipped_branches, this)) reset_branch(e, t);
861
- if (updates.length > 0)
862
- /** @type {Batch} */ _assertClassBrand(_Batch_brand, current_batch, _process).call(current_batch);
863
- return;
864
- }
865
- const earlier_batch = _assertClassBrand(_Batch_brand, this, _find_earlier_batch).call(this);
866
- if (earlier_batch) {
867
- _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, render_effects);
868
- _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, effects);
869
- _assertClassBrand(_Batch_brand, earlier_batch, _merge).call(earlier_batch, this);
870
- return;
871
- }
872
- _classPrivateFieldGet2(_dirty_effects$1, this).clear();
873
- _classPrivateFieldGet2(_maybe_dirty_effects$1, this).clear();
874
- for (const fn of _classPrivateFieldGet2(_commit_callbacks, this)) fn(this);
875
- _classPrivateFieldGet2(_commit_callbacks, this).clear();
876
- previous_batch = this;
877
- flush_queued_effects(render_effects);
878
- flush_queued_effects(effects);
879
- previous_batch = null;
880
- _classPrivateFieldGet2(_deferred, this)?.resolve();
881
- var next_batch = current_batch;
882
- if (_classPrivateFieldGet2(_pending, this) === 0 && (_classPrivateFieldGet2(_roots, this).length === 0 || next_batch !== null)) {
883
- _assertClassBrand(_Batch_brand, this, _unlink).call(this);
884
- if (async_mode_flag) {
885
- _assertClassBrand(_Batch_brand, this, _commit).call(this);
886
- current_batch = next_batch;
887
- }
888
- }
889
- if (_classPrivateFieldGet2(_roots, this).length > 0) if (next_batch !== null) {
890
- const batch = next_batch;
891
- _classPrivateFieldGet2(_roots, batch).push(..._classPrivateFieldGet2(_roots, this).filter((r) => !_classPrivateFieldGet2(_roots, batch).includes(r)));
892
- } else next_batch = this;
893
- if (next_batch !== null) _assertClassBrand(_Batch_brand, next_batch, _process).call(next_batch);
797
+ };
798
+ return {
799
+ reset,
800
+ invoke_onerror
801
+ };
894
802
  }
895
- /**
896
- * Traverse the effect tree, executing effects or stashing
897
- * them for later execution as appropriate
898
- * @param {Effect} root
899
- * @param {Effect[]} effects
900
- * @param {Effect[]} render_effects
901
- */
902
- function _traverse(root, effects, render_effects) {
903
- root.f ^= CLEAN;
904
- var effect = root.first;
905
- while (effect !== null) {
906
- var flags = effect.f;
907
- var is_branch = (flags & 96) !== 0;
908
- if (!(is_branch && (flags & 1024) !== 0 || (flags & 8192) !== 0 || _classPrivateFieldGet2(_skipped_branches, this).has(effect)) && effect.fn !== null) {
909
- if (is_branch) effect.f ^= CLEAN;
910
- else if ((flags & 4) !== 0) effects.push(effect);
911
- else if (async_mode_flag && (flags & 16777224) !== 0) render_effects.push(effect);
912
- else if (is_dirty(effect)) {
913
- if ((flags & 16) !== 0) _classPrivateFieldGet2(_maybe_dirty_effects$1, this).add(effect);
914
- update_effect(effect);
915
- }
916
- var child = effect.first;
917
- if (child !== null) {
918
- effect = child;
919
- continue;
920
- }
921
- }
922
- while (effect !== null) {
923
- var next = effect.next;
924
- if (next !== null) {
925
- effect = next;
926
- break;
927
- }
928
- effect = effect.parent;
803
+ function _hydrate_pending_content() {
804
+ const pending = _classPrivateFieldGet2(_props, this).pending;
805
+ if (!pending) return;
806
+ this.is_pending = true;
807
+ _classPrivateFieldSet2(_pending_effect, this, branch(() => pending(_classPrivateFieldGet2(_anchor, this))));
808
+ queue_micro_task(() => {
809
+ var fragment = _classPrivateFieldSet2(_offscreen_fragment, this, document.createDocumentFragment());
810
+ var anchor = create_text();
811
+ fragment.append(anchor);
812
+ _classPrivateFieldSet2(_main_effect, this, _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
813
+ return branch(() => _classPrivateFieldGet2(_children, this).call(this, anchor));
814
+ }));
815
+ if (_classPrivateFieldGet2(_pending_count, this) === 0) {
816
+ _classPrivateFieldGet2(_anchor, this).before(fragment);
817
+ _classPrivateFieldSet2(_offscreen_fragment, this, null);
818
+ pause_effect(_classPrivateFieldGet2(_pending_effect, this), () => {
819
+ _classPrivateFieldSet2(_pending_effect, this, null);
820
+ });
821
+ _assertClassBrand(_Boundary_brand, this, _resolve).call(this, current_batch);
929
822
  }
930
- }
823
+ });
931
824
  }
932
- function _find_earlier_batch() {
933
- var batch = _classPrivateFieldGet2(_prev, this);
934
- while (batch !== null) {
935
- if (!batch.is_fork) {
936
- for (const [value, [, is_derived]] of this.current) if (batch.current.has(value) && !is_derived) return batch;
937
- }
938
- batch = _classPrivateFieldGet2(_prev, batch);
825
+ function _render() {
826
+ try {
827
+ this.is_pending = this.has_pending_snippet();
828
+ _classPrivateFieldSet2(_pending_count, this, 0);
829
+ _classPrivateFieldSet2(_local_pending_count, this, 0);
830
+ _classPrivateFieldSet2(_main_effect, this, branch(() => {
831
+ _classPrivateFieldGet2(_children, this).call(this, _classPrivateFieldGet2(_anchor, this));
832
+ }));
833
+ if (_classPrivateFieldGet2(_pending_count, this) > 0) {
834
+ var fragment = _classPrivateFieldSet2(_offscreen_fragment, this, document.createDocumentFragment());
835
+ move_effect(_classPrivateFieldGet2(_main_effect, this), fragment);
836
+ const pending = _classPrivateFieldGet2(_props, this).pending;
837
+ _classPrivateFieldSet2(_pending_effect, this, branch(() => pending(_classPrivateFieldGet2(_anchor, this))));
838
+ } else _assertClassBrand(_Boundary_brand, this, _resolve).call(this, current_batch);
839
+ } catch (error) {
840
+ this.error(error);
939
841
  }
940
- return null;
941
842
  }
942
843
  /**
943
844
  * @param {Batch} batch
944
845
  */
945
- function _merge(batch) {
946
- for (const [source, value] of batch.current) {
947
- if (!this.previous.has(source) && batch.previous.has(source)) this.previous.set(source, batch.previous.get(source));
948
- this.current.set(source, value);
949
- }
950
- for (const [effect, deferred] of batch.async_deriveds) {
951
- const d = this.async_deriveds.get(effect);
952
- if (d) deferred.promise.then(d.resolve).catch(d.reject);
953
- }
954
- this.transfer_effects(_classPrivateFieldGet2(_dirty_effects$1, batch), _classPrivateFieldGet2(_maybe_dirty_effects$1, batch));
955
- /**
956
- * mark all effects that depend on `batch.current`, except the
957
- * async effects that we just resolved (TODO unless they depend
958
- * on values in this batch that are NOT in the later batch?).
959
- * Through this we also will populate the correct #skipped_branches,
960
- * oncommit callbacks etc, so we don't need to merge them separately.
961
- * @param {Value} value
962
- */
963
- const mark = (value) => {
964
- var reactions = value.reactions;
965
- if (reactions === null) return;
966
- for (const reaction of reactions) {
967
- var flags = reaction.f;
968
- if ((flags & 2) !== 0) mark(reaction);
969
- else {
970
- var effect = reaction;
971
- if (flags & 4194320 && !this.async_deriveds.has(effect)) {
972
- _classPrivateFieldGet2(_maybe_dirty_effects$1, this).delete(effect);
973
- set_signal_status(effect, DIRTY);
974
- this.schedule(effect);
975
- }
976
- }
977
- }
978
- };
979
- for (const source of this.current.keys()) mark(source);
980
- this.oncommit(() => batch.discard());
981
- _assertClassBrand(_Batch_brand, batch, _unlink).call(batch);
982
- current_batch = this;
983
- _assertClassBrand(_Batch_brand, this, _process).call(this);
984
- }
985
- /**
986
- * @param {Effect[]} effects
987
- */
988
- function _defer_effects(effects) {
989
- for (var i = 0; i < effects.length; i += 1) defer_effect(effects[i], _classPrivateFieldGet2(_dirty_effects$1, this), _classPrivateFieldGet2(_maybe_dirty_effects$1, this));
990
- }
991
- function _commit() {
992
- for (let batch = first_batch; batch !== null; batch = _classPrivateFieldGet2(_next, batch)) {
993
- var is_earlier = batch.id < this.id;
994
- /** @type {Source[]} */
995
- var sources = [];
996
- for (const [source, [value, is_derived]] of this.current) {
997
- if (batch.current.has(source)) {
998
- var batch_value = batch.current.get(source)[0];
999
- if (is_earlier && value !== batch_value) batch.current.set(source, [value, is_derived]);
1000
- else continue;
1001
- }
1002
- sources.push(source);
1003
- }
1004
- if (is_earlier) for (const [effect, deferred] of this.async_deriveds) {
1005
- const d = batch.async_deriveds.get(effect);
1006
- if (d) deferred.promise.then(d.resolve).catch(d.reject);
1007
- }
1008
- if (!_classPrivateFieldGet2(_started, batch)) continue;
1009
- var others = [...batch.current.keys()].filter((s) => !batch.current.get(s)[1] && !this.current.has(s));
1010
- if (others.length === 0) {
1011
- if (is_earlier) batch.discard();
1012
- } else if (sources.length > 0) {
1013
- if (is_earlier) for (const unskipped of _classPrivateFieldGet2(_unskipped_branches, this)) batch.unskip_effect(unskipped, (e) => {
1014
- if ((e.f & 4194320) !== 0) batch.schedule(e);
1015
- else _assertClassBrand(_Batch_brand, batch, _defer_effects).call(batch, [e]);
1016
- });
1017
- batch.activate();
1018
- /** @type {Set<Value>} */
1019
- var marked = /* @__PURE__ */ new Set();
1020
- /** @type {Map<Reaction, boolean>} */
1021
- var checked = /* @__PURE__ */ new Map();
1022
- for (var source of sources) mark_effects(source, others, marked, checked);
1023
- checked = /* @__PURE__ */ new Map();
1024
- var current_unequal = [...batch.current].filter(([c, v1]) => {
1025
- const v2 = this.current.get(c);
1026
- if (!v2) return true;
1027
- return v2[0] !== v1[0] || v2[1] !== v1[1];
1028
- }).map(([c]) => c);
1029
- if (current_unequal.length > 0) {
1030
- for (const effect of _classPrivateFieldGet2(_new_effects, this)) if ((effect.f & 155648) === 0 && depends_on(effect, current_unequal, checked)) if ((effect.f & 4194320) !== 0) {
1031
- set_signal_status(effect, DIRTY);
1032
- batch.schedule(effect);
1033
- } else _classPrivateFieldGet2(_dirty_effects$1, batch).add(effect);
1034
- }
1035
- if (_classPrivateFieldGet2(_roots, batch).length > 0 && !_classPrivateFieldGet2(_decrement_queued, batch)) {
1036
- batch.apply();
1037
- for (var root of _classPrivateFieldGet2(_roots, batch)) _assertClassBrand(_Batch_brand, batch, _traverse).call(batch, root, [], []);
1038
- _classPrivateFieldSet2(_roots, batch, []);
1039
- }
1040
- batch.deactivate();
1041
- }
1042
- }
1043
- }
1044
- function _unlink() {
1045
- if (!this.linked) return;
1046
- var prev = _classPrivateFieldGet2(_prev, this);
1047
- var next = _classPrivateFieldGet2(_next, this);
1048
- if (prev === null) first_batch = next;
1049
- else _classPrivateFieldSet2(_next, prev, next);
1050
- if (next === null) last_batch = prev;
1051
- else _classPrivateFieldSet2(_prev, next, prev);
1052
- this.linked = false;
846
+ function _resolve(batch) {
847
+ this.is_pending = false;
848
+ batch.transfer_effects(_classPrivateFieldGet2(_dirty_effects$1, this), _classPrivateFieldGet2(_maybe_dirty_effects$1, this));
1053
849
  }
1054
850
  /**
1055
- * Synchronously flush any pending updates.
1056
- * Returns void if no callback is provided, otherwise returns the result of calling the callback.
1057
- * @template [T=void]
1058
- * @param {(() => T) | undefined} [fn]
1059
- * @returns {T}
851
+ * @template T
852
+ * @param {() => T} fn
1060
853
  */
1061
- function flushSync(fn) {
1062
- var was_flushing_sync = is_flushing_sync;
1063
- is_flushing_sync = true;
854
+ function _run(fn) {
855
+ var previous_effect = active_effect;
856
+ var previous_reaction = active_reaction;
857
+ var previous_ctx = component_context;
858
+ set_active_effect(_classPrivateFieldGet2(_effect, this));
859
+ set_active_reaction(_classPrivateFieldGet2(_effect, this));
860
+ set_component_context(_classPrivateFieldGet2(_effect, this).ctx);
1064
861
  try {
1065
- var result;
1066
- if (fn) {
1067
- if (current_batch !== null && !current_batch.is_fork) current_batch.flush();
1068
- result = fn();
1069
- }
1070
- while (true) {
1071
- flush_tasks();
1072
- if (current_batch === null) return result;
1073
- current_batch.flush();
1074
- }
862
+ Batch.ensure();
863
+ return fn();
864
+ } catch (e) {
865
+ handle_error(e);
866
+ return null;
1075
867
  } finally {
1076
- is_flushing_sync = was_flushing_sync;
1077
- }
1078
- }
1079
- function infinite_loop_guard() {
1080
- try {
1081
- effect_update_depth_exceeded();
1082
- } catch (error) {
1083
- invoke_error_boundary(error, last_scheduled_effect);
868
+ set_active_effect(previous_effect);
869
+ set_active_reaction(previous_reaction);
870
+ set_component_context(previous_ctx);
1084
871
  }
1085
872
  }
1086
- /** @type {Set<Effect> | null} */
1087
- var eager_block_effects = null;
1088
873
  /**
1089
- * @param {Array<Effect>} effects
1090
- * @returns {void}
874
+ * Updates the pending count associated with the currently visible pending snippet,
875
+ * if any, such that we can replace the snippet with content once work is done
876
+ * @param {1 | -1} d
877
+ * @param {Batch} batch
1091
878
  */
1092
- function flush_queued_effects(effects) {
1093
- var length = effects.length;
1094
- if (length === 0) return;
1095
- var i = 0;
1096
- while (i < length) {
1097
- var effect = effects[i++];
1098
- if ((effect.f & 24576) === 0 && is_dirty(effect)) {
1099
- eager_block_effects = /* @__PURE__ */ new Set();
1100
- update_effect(effect);
1101
- if (effect.deps === null && effect.first === null && effect.nodes === null && effect.teardown === null && effect.ac === null) unlink_effect(effect);
1102
- if (eager_block_effects?.size > 0) {
1103
- old_values.clear();
1104
- for (const e of eager_block_effects) {
1105
- if ((e.f & 24576) !== 0) continue;
1106
- /** @type {Effect[]} */
1107
- const ordered_effects = [e];
1108
- let ancestor = e.parent;
1109
- while (ancestor !== null) {
1110
- if (eager_block_effects.has(ancestor)) {
1111
- eager_block_effects.delete(ancestor);
1112
- ordered_effects.push(ancestor);
1113
- }
1114
- ancestor = ancestor.parent;
1115
- }
1116
- for (let j = ordered_effects.length - 1; j >= 0; j--) {
1117
- const e = ordered_effects[j];
1118
- if ((e.f & 24576) !== 0) continue;
1119
- update_effect(e);
1120
- }
1121
- }
1122
- eager_block_effects.clear();
1123
- }
879
+ function _update_pending_count(d, batch) {
880
+ if (!this.has_pending_snippet()) {
881
+ if (this.parent) {
882
+ var _this$parent;
883
+ _assertClassBrand(_Boundary_brand, _this$parent = this.parent, _update_pending_count).call(_this$parent, d, batch);
884
+ }
885
+ return;
886
+ }
887
+ _classPrivateFieldSet2(_pending_count, this, _classPrivateFieldGet2(_pending_count, this) + d);
888
+ if (_classPrivateFieldGet2(_pending_count, this) === 0) {
889
+ _assertClassBrand(_Boundary_brand, this, _resolve).call(this, batch);
890
+ if (_classPrivateFieldGet2(_pending_effect, this)) pause_effect(_classPrivateFieldGet2(_pending_effect, this), () => {
891
+ _classPrivateFieldSet2(_pending_effect, this, null);
892
+ });
893
+ if (_classPrivateFieldGet2(_offscreen_fragment, this)) {
894
+ _classPrivateFieldGet2(_anchor, this).before(_classPrivateFieldGet2(_offscreen_fragment, this));
895
+ _classPrivateFieldSet2(_offscreen_fragment, this, null);
1124
896
  }
1125
897
  }
1126
- eager_block_effects = null;
1127
898
  }
1128
899
  /**
1129
- * This is similar to `mark_reactions`, but it only marks async/block effects
1130
- * depending on `value` and at least one of the other `sources`, so that
1131
- * these effects can re-run after another batch has been committed
1132
- * @param {Value} value
1133
- * @param {Source[]} sources
1134
- * @param {Set<Value>} marked
1135
- * @param {Map<Reaction, boolean>} checked
900
+ * @param {unknown} error
1136
901
  */
1137
- function mark_effects(value, sources, marked, checked) {
1138
- if (marked.has(value)) return;
1139
- marked.add(value);
1140
- if (value.reactions !== null) for (const reaction of value.reactions) {
1141
- const flags = reaction.f;
1142
- if ((flags & 2) !== 0) mark_effects(reaction, sources, marked, checked);
1143
- else if ((flags & 4194320) !== 0 && (flags & 2048) === 0 && depends_on(reaction, sources, checked)) {
1144
- set_signal_status(reaction, DIRTY);
1145
- schedule_effect(reaction);
1146
- }
902
+ function _handle_error(error) {
903
+ if (_classPrivateFieldGet2(_main_effect, this)) {
904
+ destroy_effect(_classPrivateFieldGet2(_main_effect, this));
905
+ _classPrivateFieldSet2(_main_effect, this, null);
906
+ }
907
+ if (_classPrivateFieldGet2(_pending_effect, this)) {
908
+ destroy_effect(_classPrivateFieldGet2(_pending_effect, this));
909
+ _classPrivateFieldSet2(_pending_effect, this, null);
910
+ }
911
+ if (_classPrivateFieldGet2(_failed_effect, this)) {
912
+ destroy_effect(_classPrivateFieldGet2(_failed_effect, this));
913
+ _classPrivateFieldSet2(_failed_effect, this, null);
1147
914
  }
915
+ if (hydrating) {
916
+ set_hydrate_node(_classPrivateFieldGet2(_hydrate_open, this));
917
+ next();
918
+ set_hydrate_node(skip_nodes());
919
+ }
920
+ let failed = _classPrivateFieldGet2(_props, this).failed;
921
+ /** @param {unknown} transformed_error */
922
+ const handle_error_result = (transformed_error) => {
923
+ const { reset, invoke_onerror } = _assertClassBrand(_Boundary_brand, this, _create_reset).call(this, transformed_error);
924
+ invoke_onerror();
925
+ if (failed) _classPrivateFieldSet2(_failed_effect, this, _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
926
+ try {
927
+ return branch(() => {
928
+ var effect = active_effect;
929
+ effect.b = this;
930
+ effect.f |= 128;
931
+ failed(_classPrivateFieldGet2(_anchor, this), () => transformed_error, () => reset);
932
+ });
933
+ } catch (error) {
934
+ invoke_error_boundary(error, _classPrivateFieldGet2(_effect, this).parent);
935
+ return null;
936
+ }
937
+ }));
938
+ };
939
+ queue_micro_task(() => {
940
+ /** @type {unknown} */
941
+ var result;
942
+ try {
943
+ result = this.transform_error(error);
944
+ } catch (e) {
945
+ invoke_error_boundary(e, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent);
946
+ return;
947
+ }
948
+ if (result !== null && typeof result === "object" && typeof result.then === "function")
949
+ /** @type {any} */ result.then(
950
+ handle_error_result,
951
+ /** @param {unknown} e */
952
+ (e) => invoke_error_boundary(e, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent)
953
+ );
954
+ else handle_error_result(result);
955
+ });
1148
956
  }
1149
957
  /**
1150
- * @param {Reaction} reaction
1151
- * @param {Source[]} sources
1152
- * @param {Map<Reaction, boolean>} checked
958
+ * @template V
959
+ * @param {() => V} fn
960
+ * @returns {Derived<V>}
1153
961
  */
1154
- function depends_on(reaction, sources, checked) {
1155
- const depends = checked.get(reaction);
1156
- if (depends !== void 0) return depends;
1157
- if (reaction.deps !== null) for (const dep of reaction.deps) {
1158
- if (includes.call(sources, dep)) return true;
1159
- if ((dep.f & 2) !== 0 && depends_on(dep, sources, checked)) {
1160
- checked.set(dep, true);
1161
- return true;
1162
- }
1163
- }
1164
- checked.set(reaction, false);
1165
- return false;
962
+ /*#__NO_SIDE_EFFECTS__*/
963
+ function derived(fn) {
964
+ var flags = 2 | DIRTY;
965
+ if (active_effect !== null) active_effect.f |= EFFECT_PRESERVED;
966
+ return {
967
+ ctx: component_context,
968
+ deps: null,
969
+ effects: null,
970
+ equals,
971
+ f: flags,
972
+ fn,
973
+ reactions: null,
974
+ rv: 0,
975
+ v: UNINITIALIZED,
976
+ wv: 0,
977
+ parent: active_effect,
978
+ ac: null
979
+ };
1166
980
  }
981
+ var OBSOLETE = Symbol("obsolete");
1167
982
  /**
1168
- * @param {Effect} effect
1169
- * @returns {void}
983
+ * @template V
984
+ * @param {() => V} fn
985
+ * @returns {Derived<V>}
1170
986
  */
1171
- function schedule_effect(effect) {
1172
- /** @type {Batch} */ current_batch.schedule(effect);
987
+ /*#__NO_SIDE_EFFECTS__*/
988
+ function derived_safe_equal(fn) {
989
+ const signal = /* @__PURE__ */ derived(fn);
990
+ signal.equals = safe_equals;
991
+ return signal;
1173
992
  }
1174
993
  /**
1175
- * Mark all the effects inside a skipped branch CLEAN, so that
1176
- * they can be correctly rescheduled later. Tracks dirty and maybe_dirty
1177
- * effects so they can be rescheduled if the branch survives.
1178
- * @param {Effect} effect
1179
- * @param {{ d: Effect[], m: Effect[] }} tracked
994
+ * @param {Derived} derived
995
+ * @returns {void}
1180
996
  */
1181
- function reset_branch(effect, tracked) {
1182
- if ((effect.f & 32) !== 0 && (effect.f & 1024) !== 0) return;
1183
- if ((effect.f & 2048) !== 0) tracked.d.push(effect);
1184
- else if ((effect.f & 4096) !== 0) tracked.m.push(effect);
1185
- set_signal_status(effect, CLEAN);
1186
- var e = effect.first;
1187
- while (e !== null) {
1188
- reset_branch(e, tracked);
1189
- e = e.next;
997
+ function destroy_derived_effects(derived) {
998
+ var effects = derived.effects;
999
+ if (effects !== null) {
1000
+ derived.effects = null;
1001
+ for (var i = 0; i < effects.length; i += 1) destroy_effect(effects[i]);
1190
1002
  }
1191
1003
  }
1192
1004
  /**
1193
- * Mark an entire effect tree clean following an error
1194
- * @param {Effect} effect
1005
+ * @template T
1006
+ * @param {Derived} derived
1007
+ * @returns {T}
1195
1008
  */
1196
- function reset_all(effect) {
1197
- set_signal_status(effect, CLEAN);
1198
- var e = effect.first;
1199
- while (e !== null) {
1200
- reset_all(e);
1201
- e = e.next;
1009
+ function execute_derived(derived) {
1010
+ var value;
1011
+ var prev_active_effect = active_effect;
1012
+ var parent = derived.parent;
1013
+ if (!is_destroying_effect && parent !== null && derived.v !== UNINITIALIZED && (parent.f & 24576) !== 0) {
1014
+ derived_inert();
1015
+ return derived.v;
1016
+ }
1017
+ set_active_effect(parent);
1018
+ try {
1019
+ derived.f &= ~WAS_MARKED;
1020
+ destroy_derived_effects(derived);
1021
+ value = update_reaction(derived);
1022
+ } finally {
1023
+ set_active_effect(prev_active_effect);
1202
1024
  }
1025
+ return value;
1203
1026
  }
1204
- //#endregion
1205
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/reactivity/create-subscriber.js
1206
1027
  /**
1207
- * Returns a `subscribe` function that integrates external event-based systems with Svelte's reactivity.
1208
- * It's particularly useful for integrating with web APIs like `MediaQuery`, `IntersectionObserver`, or `WebSocket`.
1209
- *
1210
- * If `subscribe` is called inside an effect (including indirectly, for example inside a getter),
1211
- * the `start` callback will be called with an `update` function. Whenever `update` is called, the effect re-runs.
1212
- *
1213
- * If `start` returns a cleanup function, it will be called when the effect is destroyed.
1214
- *
1215
- * If `subscribe` is called in multiple effects, `start` will only be called once as long as the effects
1216
- * are active, and the returned teardown function will only be called when all effects are destroyed.
1217
- *
1218
- * It's best understood with an example. Here's an implementation of [`MediaQuery`](https://svelte.dev/docs/svelte/svelte-reactivity#MediaQuery):
1219
- *
1220
- * ```js
1221
- * import { createSubscriber } from 'svelte/reactivity';
1222
- * import { on } from 'svelte/events';
1223
- *
1224
- * export class MediaQuery {
1225
- * #query;
1226
- * #subscribe;
1227
- *
1228
- * constructor(query) {
1229
- * this.#query = window.matchMedia(`(${query})`);
1230
- *
1231
- * this.#subscribe = createSubscriber((update) => {
1232
- * // when the `change` event occurs, re-run any effects that read `this.current`
1233
- * const off = on(this.#query, 'change', update);
1234
- *
1235
- * // stop listening when all the effects are destroyed
1236
- * return () => off();
1237
- * });
1238
- * }
1239
- *
1240
- * get current() {
1241
- * // This makes the getter reactive, if read in an effect
1242
- * this.#subscribe();
1243
- *
1244
- * // Return the current state of the query, whether or not we're in an effect
1245
- * return this.#query.matches;
1246
- * }
1247
- * }
1248
- * ```
1249
- * @param {(update: () => void) => (() => void) | void} start
1250
- * @since 5.7.0
1028
+ * @param {Derived} derived
1029
+ * @returns {void}
1251
1030
  */
1252
- function createSubscriber(start) {
1253
- let subscribers = 0;
1254
- let version = source(0);
1255
- /** @type {(() => void) | void} */
1256
- let stop;
1257
- return () => {
1258
- if (effect_tracking()) {
1259
- get(version);
1260
- render_effect(() => {
1261
- if (subscribers === 0) stop = untrack(() => start(() => increment(version)));
1262
- subscribers += 1;
1263
- return () => {
1264
- queue_micro_task(() => {
1265
- subscribers -= 1;
1266
- if (subscribers === 0) {
1267
- stop?.();
1268
- stop = void 0;
1269
- increment(version);
1270
- }
1271
- });
1272
- };
1273
- });
1031
+ function update_derived(derived) {
1032
+ var value = execute_derived(derived);
1033
+ if (!derived.equals(value)) {
1034
+ derived.wv = increment_write_version();
1035
+ if (!current_batch?.is_fork || derived.deps === null) {
1036
+ if (current_batch !== null) {
1037
+ current_batch.capture(derived, value, true);
1038
+ previous_batch?.capture(derived, value, true);
1039
+ } else derived.v = value;
1040
+ if (derived.deps === null) {
1041
+ set_signal_status(derived, CLEAN);
1042
+ return;
1043
+ }
1274
1044
  }
1275
- };
1045
+ }
1046
+ if (is_destroying_effect) return;
1047
+ if (batch_values !== null) {
1048
+ if (effect_tracking() || current_batch?.is_fork) batch_values.set(derived, value);
1049
+ } else update_derived_status(derived);
1050
+ }
1051
+ /**
1052
+ * @param {Derived} derived
1053
+ */
1054
+ function freeze_derived_effects(derived) {
1055
+ if (derived.effects === null) return;
1056
+ for (const e of derived.effects) if (e.teardown || e.ac) {
1057
+ e.teardown?.();
1058
+ if (e.ac !== null) without_reactive_context(() => {
1059
+ /** @type {AbortController} */ e.ac.abort(STALE_REACTION);
1060
+ e.ac = null;
1061
+ });
1062
+ if (e.fn !== null) e.teardown = noop;
1063
+ remove_reactions(e, 0);
1064
+ destroy_effect_children(e);
1065
+ }
1066
+ }
1067
+ /**
1068
+ * @param {Derived} derived
1069
+ */
1070
+ function unfreeze_derived_effects(derived) {
1071
+ if (derived.effects === null) return;
1072
+ for (const e of derived.effects) if (e.teardown && e.fn !== null) update_effect(e);
1276
1073
  }
1277
1074
  //#endregion
1278
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/blocks/boundary.js
1279
- /** @import { Effect, Source, TemplateNode, } from '#client' */
1075
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/batch.js
1076
+ /** @import { Fork } from 'svelte' */
1077
+ /** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
1078
+ var _Batch;
1079
+ /** @type {Batch | null} */
1080
+ var first_batch = null;
1081
+ /** @type {Batch | null} */
1082
+ var last_batch = null;
1083
+ /** @type {Batch | null} */
1084
+ var current_batch = null;
1280
1085
  /**
1281
- * @typedef {{
1282
- * onerror?: ((error: unknown, reset: () => void) => void) | null;
1283
- * failed?: ((anchor: Node, error: () => unknown, reset: () => () => void) => void) | null;
1284
- * pending?: ((anchor: Node) => void) | null;
1285
- * }} BoundaryProps
1086
+ * This is needed to avoid overwriting inputs
1087
+ * @type {Batch | null}
1286
1088
  */
1287
- var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
1089
+ var previous_batch = null;
1288
1090
  /**
1289
- * @param {TemplateNode} node
1290
- * @param {BoundaryProps} props
1291
- * @param {((anchor: Node) => void)} children
1292
- * @param {((error: unknown) => unknown) | undefined} [transform_error]
1293
- * @returns {void}
1091
+ * When time travelling (i.e. working in one batch, while other batches
1092
+ * still have ongoing work), we ignore the real values of affected
1093
+ * signals in favour of their values within the batch
1094
+ * @type {Map<Value, any> | null}
1294
1095
  */
1295
- function boundary(node, props, children, transform_error) {
1296
- new Boundary(node, props, children, transform_error);
1297
- }
1298
- var _anchor = /* @__PURE__ */ new WeakMap();
1299
- var _hydrate_open = /* @__PURE__ */ new WeakMap();
1300
- var _props = /* @__PURE__ */ new WeakMap();
1301
- var _children = /* @__PURE__ */ new WeakMap();
1302
- var _effect = /* @__PURE__ */ new WeakMap();
1303
- var _main_effect = /* @__PURE__ */ new WeakMap();
1304
- var _pending_effect = /* @__PURE__ */ new WeakMap();
1305
- var _failed_effect = /* @__PURE__ */ new WeakMap();
1306
- var _offscreen_fragment = /* @__PURE__ */ new WeakMap();
1307
- var _local_pending_count = /* @__PURE__ */ new WeakMap();
1308
- var _pending_count = /* @__PURE__ */ new WeakMap();
1309
- var _pending_count_update_queued = /* @__PURE__ */ new WeakMap();
1096
+ var batch_values = null;
1097
+ /** @type {Effect | null} */
1098
+ var last_scheduled_effect = null;
1099
+ var is_flushing_sync = false;
1100
+ var is_processing = false;
1101
+ /**
1102
+ * During traversal, this is an array. Newly created effects are (if not immediately
1103
+ * executed) pushed to this array, rather than going through the scheduling
1104
+ * rigamarole that would cause another turn of the flush loop.
1105
+ * @type {Effect[] | null}
1106
+ */
1107
+ var collected_effects = null;
1108
+ /**
1109
+ * An array of effects that are marked during traversal as a result of a `set`
1110
+ * (not `internal_set`) call. These will be added to the next batch and
1111
+ * trigger another `batch.process()`
1112
+ * @type {Effect[] | null}
1113
+ * @deprecated when we get rid of legacy mode and stores, we can get rid of this
1114
+ */
1115
+ var legacy_updates = null;
1116
+ var flush_count = 0;
1117
+ var uid = 1;
1118
+ var _started = /* @__PURE__ */ new WeakMap();
1119
+ var _prev = /* @__PURE__ */ new WeakMap();
1120
+ var _next = /* @__PURE__ */ new WeakMap();
1121
+ var _commit_callbacks = /* @__PURE__ */ new WeakMap();
1122
+ var _discard_callbacks = /* @__PURE__ */ new WeakMap();
1123
+ var _pending = /* @__PURE__ */ new WeakMap();
1124
+ var _blocking_pending = /* @__PURE__ */ new WeakMap();
1125
+ var _deferred = /* @__PURE__ */ new WeakMap();
1126
+ var _roots = /* @__PURE__ */ new WeakMap();
1127
+ var _new_effects = /* @__PURE__ */ new WeakMap();
1310
1128
  var _dirty_effects = /* @__PURE__ */ new WeakMap();
1311
1129
  var _maybe_dirty_effects = /* @__PURE__ */ new WeakMap();
1312
- var _effect_pending = /* @__PURE__ */ new WeakMap();
1313
- var _effect_pending_subscriber = /* @__PURE__ */ new WeakMap();
1314
- var _Boundary_brand = /* @__PURE__ */ new WeakSet();
1315
- var Boundary = class {
1316
- /**
1317
- * @param {TemplateNode} node
1318
- * @param {BoundaryProps} props
1319
- * @param {((anchor: Node) => void)} children
1320
- * @param {((error: unknown) => unknown) | undefined} [transform_error]
1321
- */
1322
- constructor(node, props, children, transform_error) {
1323
- _classPrivateMethodInitSpec(this, _Boundary_brand);
1130
+ var _skipped_branches = /* @__PURE__ */ new WeakMap();
1131
+ var _unskipped_branches = /* @__PURE__ */ new WeakMap();
1132
+ var _decrement_queued = /* @__PURE__ */ new WeakMap();
1133
+ var _Batch_brand = /* @__PURE__ */ new WeakSet();
1134
+ var Batch = class Batch {
1135
+ constructor() {
1136
+ _classPrivateMethodInitSpec(this, _Batch_brand);
1137
+ _defineProperty(this, "id", uid++);
1138
+ _classPrivateFieldInitSpec(this, _started, false);
1139
+ _defineProperty(this, "linked", true);
1140
+ _classPrivateFieldInitSpec(this, _prev, null);
1141
+ _classPrivateFieldInitSpec(this, _next, null);
1324
1142
  _defineProperty(
1325
1143
  this,
1326
- /** @type {Boundary | null} */
1327
- "parent",
1328
- void 0
1144
+ /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
1145
+ "async_deriveds",
1146
+ /* @__PURE__ */ new Map()
1329
1147
  );
1330
- _defineProperty(this, "is_pending", false);
1331
1148
  _defineProperty(
1332
1149
  this,
1333
1150
  /**
1334
- * API-level transformError transform function. Transforms errors before they reach the `failed` snippet.
1335
- * Inherited from parent boundary, or defaults to identity.
1336
- * @type {(error: unknown) => unknown}
1151
+ * The current values of any signals that are updated in this batch.
1152
+ * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
1153
+ * They keys of this map are identical to `this.#previous`
1154
+ * @type {Map<Value, [any, boolean]>}
1337
1155
  */
1338
- "transform_error",
1339
- void 0
1156
+ "current",
1157
+ /* @__PURE__ */ new Map()
1340
1158
  );
1341
- _classPrivateFieldInitSpec(this, _anchor, void 0);
1342
- _classPrivateFieldInitSpec(this, _hydrate_open, hydrating ? hydrate_node : null);
1343
- _classPrivateFieldInitSpec(this, _props, void 0);
1344
- _classPrivateFieldInitSpec(this, _children, void 0);
1345
- _classPrivateFieldInitSpec(this, _effect, void 0);
1346
- _classPrivateFieldInitSpec(this, _main_effect, null);
1347
- _classPrivateFieldInitSpec(this, _pending_effect, null);
1348
- _classPrivateFieldInitSpec(this, _failed_effect, null);
1349
- _classPrivateFieldInitSpec(this, _offscreen_fragment, null);
1350
- _classPrivateFieldInitSpec(this, _local_pending_count, 0);
1351
- _classPrivateFieldInitSpec(this, _pending_count, 0);
1352
- _classPrivateFieldInitSpec(this, _pending_count_update_queued, false);
1159
+ _defineProperty(
1160
+ this,
1161
+ /**
1162
+ * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
1163
+ * They keys of this map are identical to `this.#current`
1164
+ * @type {Map<Value, any>}
1165
+ */
1166
+ "previous",
1167
+ /* @__PURE__ */ new Map()
1168
+ );
1169
+ _classPrivateFieldInitSpec(this, _commit_callbacks, /* @__PURE__ */ new Set());
1170
+ _classPrivateFieldInitSpec(this, _discard_callbacks, /* @__PURE__ */ new Set());
1171
+ _classPrivateFieldInitSpec(this, _pending, 0);
1172
+ _classPrivateFieldInitSpec(this, _blocking_pending, /* @__PURE__ */ new Map());
1173
+ _classPrivateFieldInitSpec(this, _deferred, null);
1174
+ _classPrivateFieldInitSpec(this, _roots, []);
1175
+ _classPrivateFieldInitSpec(this, _new_effects, []);
1353
1176
  _classPrivateFieldInitSpec(this, _dirty_effects, /* @__PURE__ */ new Set());
1354
1177
  _classPrivateFieldInitSpec(this, _maybe_dirty_effects, /* @__PURE__ */ new Set());
1355
- _classPrivateFieldInitSpec(this, _effect_pending, null);
1356
- _classPrivateFieldInitSpec(this, _effect_pending_subscriber, createSubscriber(() => {
1357
- _classPrivateFieldSet2(_effect_pending, this, source(_classPrivateFieldGet2(_local_pending_count, this)));
1358
- return () => {
1359
- _classPrivateFieldSet2(_effect_pending, this, null);
1360
- };
1361
- }));
1362
- _classPrivateFieldSet2(_anchor, this, node);
1363
- _classPrivateFieldSet2(_props, this, props);
1364
- _classPrivateFieldSet2(_children, this, (anchor) => {
1365
- var effect = active_effect;
1366
- effect.b = this;
1367
- effect.f |= 128;
1368
- children(anchor);
1178
+ _classPrivateFieldInitSpec(this, _skipped_branches, /* @__PURE__ */ new Map());
1179
+ _classPrivateFieldInitSpec(this, _unskipped_branches, /* @__PURE__ */ new Set());
1180
+ _defineProperty(this, "is_fork", false);
1181
+ _classPrivateFieldInitSpec(this, _decrement_queued, false);
1182
+ if (last_batch === null) first_batch = last_batch = this;
1183
+ else {
1184
+ _classPrivateFieldSet2(_next, last_batch, this);
1185
+ _classPrivateFieldSet2(_prev, this, last_batch);
1186
+ }
1187
+ last_batch = this;
1188
+ }
1189
+ /**
1190
+ * Add an effect to the #skipped_branches map and reset its children
1191
+ * @param {Effect} effect
1192
+ */
1193
+ skip_effect(effect) {
1194
+ if (!_classPrivateFieldGet2(_skipped_branches, this).has(effect)) _classPrivateFieldGet2(_skipped_branches, this).set(effect, {
1195
+ d: [],
1196
+ m: []
1369
1197
  });
1370
- this.parent = active_effect.b;
1371
- this.transform_error = transform_error ?? this.parent?.transform_error ?? ((e) => e);
1372
- _classPrivateFieldSet2(_effect, this, block(() => {
1373
- if (hydrating) {
1374
- const comment = _classPrivateFieldGet2(_hydrate_open, this);
1375
- hydrate_next();
1376
- const server_rendered_pending = comment.data === "[!";
1377
- if (comment.data.startsWith("[?")) {
1378
- const serialized_error = JSON.parse(comment.data.slice(2));
1379
- _assertClassBrand(_Boundary_brand, this, _hydrate_failed_content).call(this, serialized_error);
1380
- } else if (server_rendered_pending) _assertClassBrand(_Boundary_brand, this, _hydrate_pending_content).call(this);
1381
- else _assertClassBrand(_Boundary_brand, this, _hydrate_resolved_content).call(this);
1382
- } else _assertClassBrand(_Boundary_brand, this, _render).call(this);
1383
- }, flags));
1384
- if (hydrating) _classPrivateFieldSet2(_anchor, this, hydrate_node);
1198
+ _classPrivateFieldGet2(_unskipped_branches, this).delete(effect);
1199
+ }
1200
+ /**
1201
+ * Remove an effect from the #skipped_branches map and reschedule
1202
+ * any tracked dirty/maybe_dirty child effects
1203
+ * @param {Effect} effect
1204
+ * @param {(e: Effect) => void} callback
1205
+ */
1206
+ unskip_effect(effect, callback = (e) => this.schedule(e)) {
1207
+ var tracked = _classPrivateFieldGet2(_skipped_branches, this).get(effect);
1208
+ if (tracked) {
1209
+ _classPrivateFieldGet2(_skipped_branches, this).delete(effect);
1210
+ for (var e of tracked.d) {
1211
+ set_signal_status(e, DIRTY);
1212
+ callback(e);
1213
+ }
1214
+ for (e of tracked.m) {
1215
+ set_signal_status(e, MAYBE_DIRTY);
1216
+ callback(e);
1217
+ }
1218
+ }
1219
+ _classPrivateFieldGet2(_unskipped_branches, this).add(effect);
1220
+ }
1221
+ /**
1222
+ * Associate a change to a given source with the current
1223
+ * batch, noting its previous and current values
1224
+ * @param {Value} source
1225
+ * @param {any} value
1226
+ * @param {boolean} [is_derived]
1227
+ */
1228
+ capture(source, value, is_derived = false) {
1229
+ if (source.v !== UNINITIALIZED && !this.previous.has(source)) this.previous.set(source, source.v);
1230
+ if ((source.f & 8388608) === 0) {
1231
+ this.current.set(source, [value, is_derived]);
1232
+ batch_values?.set(source, value);
1233
+ }
1234
+ if (!this.is_fork) source.v = value;
1235
+ }
1236
+ activate() {
1237
+ current_batch = this;
1238
+ }
1239
+ deactivate() {
1240
+ current_batch = null;
1241
+ batch_values = null;
1242
+ }
1243
+ flush() {
1244
+ try {
1245
+ is_processing = true;
1246
+ current_batch = this;
1247
+ _assertClassBrand(_Batch_brand, this, _process).call(this);
1248
+ } finally {
1249
+ flush_count = 0;
1250
+ last_scheduled_effect = null;
1251
+ collected_effects = null;
1252
+ legacy_updates = null;
1253
+ is_processing = false;
1254
+ current_batch = null;
1255
+ batch_values = null;
1256
+ old_values.clear();
1257
+ }
1258
+ }
1259
+ discard() {
1260
+ for (const fn of _classPrivateFieldGet2(_discard_callbacks, this)) fn(this);
1261
+ _classPrivateFieldGet2(_discard_callbacks, this).clear();
1262
+ for (const deferred of this.async_deriveds.values()) deferred.reject(OBSOLETE);
1263
+ _assertClassBrand(_Batch_brand, this, _unlink).call(this);
1264
+ _classPrivateFieldGet2(_deferred, this)?.resolve();
1385
1265
  }
1386
1266
  /**
1387
- * Defer an effect inside a pending boundary until the boundary resolves
1388
1267
  * @param {Effect} effect
1389
1268
  */
1390
- defer_effect(effect) {
1391
- defer_effect(effect, _classPrivateFieldGet2(_dirty_effects, this), _classPrivateFieldGet2(_maybe_dirty_effects, this));
1269
+ register_created_effect(effect) {
1270
+ _classPrivateFieldGet2(_new_effects, this).push(effect);
1392
1271
  }
1393
1272
  /**
1394
- * Returns `false` if the effect exists inside a boundary whose pending snippet is shown
1395
- * @returns {boolean}
1273
+ * @param {boolean} blocking
1274
+ * @param {Effect} effect
1396
1275
  */
1397
- is_rendered() {
1398
- return !this.is_pending && (!this.parent || this.parent.is_rendered());
1399
- }
1400
- has_pending_snippet() {
1401
- return !!_classPrivateFieldGet2(_props, this).pending;
1276
+ increment(blocking, effect) {
1277
+ _classPrivateFieldSet2(_pending, this, _classPrivateFieldGet2(_pending, this) + 1);
1278
+ if (blocking) {
1279
+ let blocking_pending_count = _classPrivateFieldGet2(_blocking_pending, this).get(effect) ?? 0;
1280
+ _classPrivateFieldGet2(_blocking_pending, this).set(effect, blocking_pending_count + 1);
1281
+ }
1402
1282
  }
1403
1283
  /**
1404
- * Update the source that powers `$effect.pending()` inside this boundary,
1405
- * and controls when the current `pending` snippet (if any) is removed.
1406
- * Do not call from inside the class
1407
- * @param {1 | -1} d
1408
- * @param {Batch} batch
1284
+ * @param {boolean} blocking
1285
+ * @param {Effect} effect
1409
1286
  */
1410
- update_pending_count(d, batch) {
1411
- _assertClassBrand(_Boundary_brand, this, _update_pending_count).call(this, d, batch);
1412
- _classPrivateFieldSet2(_local_pending_count, this, _classPrivateFieldGet2(_local_pending_count, this) + d);
1413
- if (!_classPrivateFieldGet2(_effect_pending, this) || _classPrivateFieldGet2(_pending_count_update_queued, this)) return;
1414
- _classPrivateFieldSet2(_pending_count_update_queued, this, true);
1287
+ decrement(blocking, effect) {
1288
+ _classPrivateFieldSet2(_pending, this, _classPrivateFieldGet2(_pending, this) - 1);
1289
+ if (blocking) {
1290
+ let blocking_pending_count = _classPrivateFieldGet2(_blocking_pending, this).get(effect) ?? 0;
1291
+ if (blocking_pending_count === 1) _classPrivateFieldGet2(_blocking_pending, this).delete(effect);
1292
+ else _classPrivateFieldGet2(_blocking_pending, this).set(effect, blocking_pending_count - 1);
1293
+ }
1294
+ if (_classPrivateFieldGet2(_decrement_queued, this)) return;
1295
+ _classPrivateFieldSet2(_decrement_queued, this, true);
1415
1296
  queue_micro_task(() => {
1416
- _classPrivateFieldSet2(_pending_count_update_queued, this, false);
1417
- if (_classPrivateFieldGet2(_effect_pending, this)) internal_set(_classPrivateFieldGet2(_effect_pending, this), _classPrivateFieldGet2(_local_pending_count, this));
1297
+ _classPrivateFieldSet2(_decrement_queued, this, false);
1298
+ if (this.linked) this.flush();
1418
1299
  });
1419
1300
  }
1420
- get_effect_pending() {
1421
- _classPrivateFieldGet2(_effect_pending_subscriber, this).call(this);
1422
- return get(_classPrivateFieldGet2(_effect_pending, this));
1301
+ /**
1302
+ * @param {Set<Effect>} dirty_effects
1303
+ * @param {Set<Effect>} maybe_dirty_effects
1304
+ */
1305
+ transfer_effects(dirty_effects, maybe_dirty_effects) {
1306
+ for (const e of dirty_effects) _classPrivateFieldGet2(_dirty_effects, this).add(e);
1307
+ for (const e of maybe_dirty_effects) _classPrivateFieldGet2(_maybe_dirty_effects, this).add(e);
1308
+ dirty_effects.clear();
1309
+ maybe_dirty_effects.clear();
1423
1310
  }
1424
- /** @param {unknown} error */
1425
- error(error) {
1426
- if (!_classPrivateFieldGet2(_props, this).onerror && !_classPrivateFieldGet2(_props, this).failed) throw error;
1427
- if (current_batch?.is_fork) {
1428
- if (_classPrivateFieldGet2(_main_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_main_effect, this));
1429
- if (_classPrivateFieldGet2(_pending_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_pending_effect, this));
1430
- if (_classPrivateFieldGet2(_failed_effect, this)) current_batch.skip_effect(_classPrivateFieldGet2(_failed_effect, this));
1431
- current_batch.oncommit(() => {
1432
- _assertClassBrand(_Boundary_brand, this, _handle_error).call(this, error);
1311
+ /** @param {(batch: Batch) => void} fn */
1312
+ oncommit(fn) {
1313
+ _classPrivateFieldGet2(_commit_callbacks, this).add(fn);
1314
+ }
1315
+ /** @param {(batch: Batch) => void} fn */
1316
+ ondiscard(fn) {
1317
+ _classPrivateFieldGet2(_discard_callbacks, this).add(fn);
1318
+ }
1319
+ settled() {
1320
+ return (_classPrivateFieldGet2(_deferred, this) ?? _classPrivateFieldSet2(_deferred, this, deferred())).promise;
1321
+ }
1322
+ static ensure() {
1323
+ if (current_batch === null) {
1324
+ const batch = current_batch = new Batch();
1325
+ if (!is_processing && !is_flushing_sync) queue_micro_task(() => {
1326
+ if (!_classPrivateFieldGet2(_started, batch)) batch.flush();
1433
1327
  });
1434
- } else _assertClassBrand(_Boundary_brand, this, _handle_error).call(this, error);
1328
+ }
1329
+ return current_batch;
1330
+ }
1331
+ apply() {
1332
+ if (!async_mode_flag || !this.is_fork && _classPrivateFieldGet2(_prev, this) === null && _classPrivateFieldGet2(_next, this) === null) {
1333
+ batch_values = null;
1334
+ return;
1335
+ }
1336
+ batch_values = /* @__PURE__ */ new Map();
1337
+ for (const [source, [value]] of this.current) batch_values.set(source, value);
1338
+ for (let batch = first_batch; batch !== null; batch = _classPrivateFieldGet2(_next, batch)) {
1339
+ if (batch === this || batch.is_fork) continue;
1340
+ var intersects = false;
1341
+ if (batch.id < this.id) for (const [source, [, is_derived]] of batch.current) {
1342
+ if (is_derived) continue;
1343
+ if (this.current.has(source)) {
1344
+ intersects = true;
1345
+ break;
1346
+ }
1347
+ }
1348
+ if (!intersects) {
1349
+ for (const [source, previous] of batch.previous) if (!batch_values.has(source)) batch_values.set(source, previous);
1350
+ }
1351
+ }
1352
+ }
1353
+ /**
1354
+ *
1355
+ * @param {Effect} effect
1356
+ */
1357
+ schedule(effect) {
1358
+ last_scheduled_effect = effect;
1359
+ if (effect.b?.is_pending && (effect.f & 16777228) !== 0 && (effect.f & 32768) === 0) {
1360
+ effect.b.defer_effect(effect);
1361
+ return;
1362
+ }
1363
+ var e = effect;
1364
+ while (e.parent !== null) {
1365
+ e = e.parent;
1366
+ var flags = e.f;
1367
+ if (collected_effects !== null && e === active_effect) {
1368
+ if (async_mode_flag) return;
1369
+ if ((active_reaction === null || (active_reaction.f & 2) === 0) && !legacy_is_updating_store) return;
1370
+ }
1371
+ if ((flags & 96) !== 0) {
1372
+ if ((flags & 1024) === 0) return;
1373
+ e.f ^= CLEAN;
1374
+ }
1375
+ }
1376
+ _classPrivateFieldGet2(_roots, this).push(e);
1435
1377
  }
1436
1378
  };
1437
- function _hydrate_resolved_content() {
1438
- try {
1439
- _classPrivateFieldSet2(_main_effect, this, branch(() => _classPrivateFieldGet2(_children, this).call(this, _classPrivateFieldGet2(_anchor, this))));
1440
- } catch (error) {
1441
- this.error(error);
1379
+ _Batch = Batch;
1380
+ function _is_deferred() {
1381
+ if (this.is_fork) return true;
1382
+ for (const effect of _classPrivateFieldGet2(_blocking_pending, this).keys()) {
1383
+ var e = effect;
1384
+ var skipped = false;
1385
+ while (e.parent !== null) {
1386
+ if (_classPrivateFieldGet2(_skipped_branches, this).has(e)) {
1387
+ skipped = true;
1388
+ break;
1389
+ }
1390
+ e = e.parent;
1391
+ }
1392
+ if (!skipped) return true;
1442
1393
  }
1394
+ return false;
1443
1395
  }
1444
- /**
1445
- * @param {unknown} error The deserialized error from the server's hydration comment
1446
- */
1447
- function _hydrate_failed_content(error) {
1448
- const failed = _classPrivateFieldGet2(_props, this).failed;
1449
- if (!failed) return;
1450
- _classPrivateFieldSet2(_failed_effect, this, branch(() => {
1451
- failed(_classPrivateFieldGet2(_anchor, this), () => error, () => () => {});
1452
- }));
1453
- }
1454
- function _hydrate_pending_content() {
1455
- const pending = _classPrivateFieldGet2(_props, this).pending;
1456
- if (!pending) return;
1457
- this.is_pending = true;
1458
- _classPrivateFieldSet2(_pending_effect, this, branch(() => pending(_classPrivateFieldGet2(_anchor, this))));
1459
- queue_micro_task(() => {
1460
- var fragment = _classPrivateFieldSet2(_offscreen_fragment, this, document.createDocumentFragment());
1461
- var anchor = create_text();
1462
- fragment.append(anchor);
1463
- _classPrivateFieldSet2(_main_effect, this, _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
1464
- return branch(() => _classPrivateFieldGet2(_children, this).call(this, anchor));
1465
- }));
1466
- if (_classPrivateFieldGet2(_pending_count, this) === 0) {
1467
- _classPrivateFieldGet2(_anchor, this).before(fragment);
1468
- _classPrivateFieldSet2(_offscreen_fragment, this, null);
1469
- pause_effect(_classPrivateFieldGet2(_pending_effect, this), () => {
1470
- _classPrivateFieldSet2(_pending_effect, this, null);
1471
- });
1472
- _assertClassBrand(_Boundary_brand, this, _resolve).call(this, current_batch);
1396
+ function _process() {
1397
+ _classPrivateFieldSet2(_started, this, true);
1398
+ if (flush_count++ > 1e3) {
1399
+ _assertClassBrand(_Batch_brand, this, _unlink).call(this);
1400
+ infinite_loop_guard();
1401
+ }
1402
+ for (const e of _classPrivateFieldGet2(_dirty_effects, this)) {
1403
+ _classPrivateFieldGet2(_maybe_dirty_effects, this).delete(e);
1404
+ set_signal_status(e, DIRTY);
1405
+ this.schedule(e);
1406
+ }
1407
+ for (const e of _classPrivateFieldGet2(_maybe_dirty_effects, this)) {
1408
+ set_signal_status(e, MAYBE_DIRTY);
1409
+ this.schedule(e);
1410
+ }
1411
+ const roots = _classPrivateFieldGet2(_roots, this);
1412
+ _classPrivateFieldSet2(_roots, this, []);
1413
+ this.apply();
1414
+ /** @type {Effect[]} */
1415
+ var effects = collected_effects = [];
1416
+ /** @type {Effect[]} */
1417
+ var render_effects = [];
1418
+ /**
1419
+ * @type {Effect[]}
1420
+ * @deprecated when we get rid of legacy mode and stores, we can get rid of this
1421
+ */
1422
+ var updates = legacy_updates = [];
1423
+ for (const root of roots) try {
1424
+ _assertClassBrand(_Batch_brand, this, _traverse).call(this, root, effects, render_effects);
1425
+ } catch (e) {
1426
+ reset_all(root);
1427
+ if (!_assertClassBrand(_Batch_brand, this, _is_deferred).call(this)) this.discard();
1428
+ throw e;
1429
+ }
1430
+ current_batch = null;
1431
+ if (updates.length > 0) {
1432
+ var batch = _Batch.ensure();
1433
+ for (const e of updates) batch.schedule(e);
1434
+ }
1435
+ collected_effects = null;
1436
+ legacy_updates = null;
1437
+ if (_assertClassBrand(_Batch_brand, this, _is_deferred).call(this)) {
1438
+ _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, render_effects);
1439
+ _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, effects);
1440
+ for (const [e, t] of _classPrivateFieldGet2(_skipped_branches, this)) reset_branch(e, t);
1441
+ if (updates.length > 0)
1442
+ /** @type {Batch} */ _assertClassBrand(_Batch_brand, current_batch, _process).call(current_batch);
1443
+ return;
1444
+ }
1445
+ const earlier_batch = _assertClassBrand(_Batch_brand, this, _find_earlier_batch).call(this);
1446
+ if (earlier_batch) {
1447
+ _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, render_effects);
1448
+ _assertClassBrand(_Batch_brand, this, _defer_effects).call(this, effects);
1449
+ _assertClassBrand(_Batch_brand, earlier_batch, _merge).call(earlier_batch, this);
1450
+ return;
1451
+ }
1452
+ _classPrivateFieldGet2(_dirty_effects, this).clear();
1453
+ _classPrivateFieldGet2(_maybe_dirty_effects, this).clear();
1454
+ for (const fn of _classPrivateFieldGet2(_commit_callbacks, this)) fn(this);
1455
+ _classPrivateFieldGet2(_commit_callbacks, this).clear();
1456
+ previous_batch = this;
1457
+ flush_queued_effects(render_effects);
1458
+ flush_queued_effects(effects);
1459
+ previous_batch = null;
1460
+ _classPrivateFieldGet2(_deferred, this)?.resolve();
1461
+ var next_batch = current_batch;
1462
+ if (_classPrivateFieldGet2(_pending, this) === 0 && (_classPrivateFieldGet2(_roots, this).length === 0 || next_batch !== null)) {
1463
+ _assertClassBrand(_Batch_brand, this, _unlink).call(this);
1464
+ if (async_mode_flag) {
1465
+ _assertClassBrand(_Batch_brand, this, _commit).call(this);
1466
+ current_batch = next_batch;
1473
1467
  }
1474
- });
1475
- }
1476
- function _render() {
1477
- try {
1478
- this.is_pending = this.has_pending_snippet();
1479
- _classPrivateFieldSet2(_pending_count, this, 0);
1480
- _classPrivateFieldSet2(_local_pending_count, this, 0);
1481
- _classPrivateFieldSet2(_main_effect, this, branch(() => {
1482
- _classPrivateFieldGet2(_children, this).call(this, _classPrivateFieldGet2(_anchor, this));
1483
- }));
1484
- if (_classPrivateFieldGet2(_pending_count, this) > 0) {
1485
- var fragment = _classPrivateFieldSet2(_offscreen_fragment, this, document.createDocumentFragment());
1486
- move_effect(_classPrivateFieldGet2(_main_effect, this), fragment);
1487
- const pending = _classPrivateFieldGet2(_props, this).pending;
1488
- _classPrivateFieldSet2(_pending_effect, this, branch(() => pending(_classPrivateFieldGet2(_anchor, this))));
1489
- } else _assertClassBrand(_Boundary_brand, this, _resolve).call(this, current_batch);
1490
- } catch (error) {
1491
- this.error(error);
1492
1468
  }
1469
+ if (_classPrivateFieldGet2(_roots, this).length > 0) if (next_batch !== null) {
1470
+ const batch = next_batch;
1471
+ _classPrivateFieldGet2(_roots, batch).push(..._classPrivateFieldGet2(_roots, this).filter((r) => !_classPrivateFieldGet2(_roots, batch).includes(r)));
1472
+ } else next_batch = this;
1473
+ if (next_batch !== null) _assertClassBrand(_Batch_brand, next_batch, _process).call(next_batch);
1493
1474
  }
1494
1475
  /**
1495
- * @param {Batch} batch
1476
+ * Traverse the effect tree, executing effects or stashing
1477
+ * them for later execution as appropriate
1478
+ * @param {Effect} root
1479
+ * @param {Effect[]} effects
1480
+ * @param {Effect[]} render_effects
1496
1481
  */
1497
- function _resolve(batch) {
1498
- this.is_pending = false;
1499
- batch.transfer_effects(_classPrivateFieldGet2(_dirty_effects, this), _classPrivateFieldGet2(_maybe_dirty_effects, this));
1482
+ function _traverse(root, effects, render_effects) {
1483
+ root.f ^= CLEAN;
1484
+ var effect = root.first;
1485
+ while (effect !== null) {
1486
+ var flags = effect.f;
1487
+ var is_branch = (flags & 96) !== 0;
1488
+ if (!(is_branch && (flags & 1024) !== 0 || (flags & 8192) !== 0 || _classPrivateFieldGet2(_skipped_branches, this).has(effect)) && effect.fn !== null) {
1489
+ if (is_branch) effect.f ^= CLEAN;
1490
+ else if ((flags & 4) !== 0) effects.push(effect);
1491
+ else if (async_mode_flag && (flags & 16777224) !== 0) render_effects.push(effect);
1492
+ else if (is_dirty(effect)) {
1493
+ if ((flags & 16) !== 0) _classPrivateFieldGet2(_maybe_dirty_effects, this).add(effect);
1494
+ update_effect(effect);
1495
+ }
1496
+ var child = effect.first;
1497
+ if (child !== null) {
1498
+ effect = child;
1499
+ continue;
1500
+ }
1501
+ }
1502
+ while (effect !== null) {
1503
+ var next = effect.next;
1504
+ if (next !== null) {
1505
+ effect = next;
1506
+ break;
1507
+ }
1508
+ effect = effect.parent;
1509
+ }
1510
+ }
1500
1511
  }
1501
- /**
1502
- * @template T
1503
- * @param {() => T} fn
1504
- */
1505
- function _run(fn) {
1506
- var previous_effect = active_effect;
1507
- var previous_reaction = active_reaction;
1508
- var previous_ctx = component_context;
1509
- set_active_effect(_classPrivateFieldGet2(_effect, this));
1510
- set_active_reaction(_classPrivateFieldGet2(_effect, this));
1511
- set_component_context(_classPrivateFieldGet2(_effect, this).ctx);
1512
- try {
1513
- Batch.ensure();
1514
- return fn();
1515
- } catch (e) {
1516
- handle_error(e);
1517
- return null;
1518
- } finally {
1519
- set_active_effect(previous_effect);
1520
- set_active_reaction(previous_reaction);
1521
- set_component_context(previous_ctx);
1512
+ function _find_earlier_batch() {
1513
+ var batch = _classPrivateFieldGet2(_prev, this);
1514
+ while (batch !== null) {
1515
+ if (!batch.is_fork) {
1516
+ for (const [value, [, is_derived]] of this.current) if (batch.current.has(value) && !is_derived) return batch;
1517
+ }
1518
+ batch = _classPrivateFieldGet2(_prev, batch);
1522
1519
  }
1520
+ return null;
1523
1521
  }
1524
1522
  /**
1525
- * Updates the pending count associated with the currently visible pending snippet,
1526
- * if any, such that we can replace the snippet with content once work is done
1527
- * @param {1 | -1} d
1528
1523
  * @param {Batch} batch
1529
1524
  */
1530
- function _update_pending_count(d, batch) {
1531
- if (!this.has_pending_snippet()) {
1532
- if (this.parent) {
1533
- var _this$parent;
1534
- _assertClassBrand(_Boundary_brand, _this$parent = this.parent, _update_pending_count).call(_this$parent, d, batch);
1535
- }
1536
- return;
1525
+ function _merge(batch) {
1526
+ for (const [source, value] of batch.current) {
1527
+ if (!this.previous.has(source) && batch.previous.has(source)) this.previous.set(source, batch.previous.get(source));
1528
+ this.current.set(source, value);
1537
1529
  }
1538
- _classPrivateFieldSet2(_pending_count, this, _classPrivateFieldGet2(_pending_count, this) + d);
1539
- if (_classPrivateFieldGet2(_pending_count, this) === 0) {
1540
- _assertClassBrand(_Boundary_brand, this, _resolve).call(this, batch);
1541
- if (_classPrivateFieldGet2(_pending_effect, this)) pause_effect(_classPrivateFieldGet2(_pending_effect, this), () => {
1542
- _classPrivateFieldSet2(_pending_effect, this, null);
1543
- });
1544
- if (_classPrivateFieldGet2(_offscreen_fragment, this)) {
1545
- _classPrivateFieldGet2(_anchor, this).before(_classPrivateFieldGet2(_offscreen_fragment, this));
1546
- _classPrivateFieldSet2(_offscreen_fragment, this, null);
1547
- }
1530
+ for (const [effect, deferred] of batch.async_deriveds) {
1531
+ const d = this.async_deriveds.get(effect);
1532
+ if (d) deferred.promise.then(d.resolve).catch(d.reject);
1548
1533
  }
1534
+ batch.async_deriveds.clear();
1535
+ this.transfer_effects(_classPrivateFieldGet2(_dirty_effects, batch), _classPrivateFieldGet2(_maybe_dirty_effects, batch));
1536
+ /**
1537
+ * mark all effects that depend on `batch.current`, except the
1538
+ * async effects that we just resolved (TODO unless they depend
1539
+ * on values in this batch that are NOT in the later batch?).
1540
+ * Through this we also will populate the correct #skipped_branches,
1541
+ * oncommit callbacks etc, so we don't need to merge them separately.
1542
+ * @param {Value} value
1543
+ */
1544
+ const mark = (value) => {
1545
+ var reactions = value.reactions;
1546
+ if (reactions === null) return;
1547
+ if ((value.f & 2) !== 0 && (value.f & 6144) === 0) return;
1548
+ for (const reaction of reactions) {
1549
+ var flags = reaction.f;
1550
+ if ((flags & 2) !== 0) mark(reaction);
1551
+ else {
1552
+ var effect = reaction;
1553
+ if (flags & 4194320 && !this.async_deriveds.has(effect)) {
1554
+ _classPrivateFieldGet2(_maybe_dirty_effects, this).delete(effect);
1555
+ set_signal_status(effect, DIRTY);
1556
+ this.schedule(effect);
1557
+ }
1558
+ }
1559
+ }
1560
+ };
1561
+ for (const source of this.current.keys()) mark(source);
1562
+ this.oncommit(() => batch.discard());
1563
+ _assertClassBrand(_Batch_brand, batch, _unlink).call(batch);
1564
+ current_batch = this;
1565
+ _assertClassBrand(_Batch_brand, this, _process).call(this);
1549
1566
  }
1550
1567
  /**
1551
- * @param {unknown} error
1568
+ * @param {Effect[]} effects
1552
1569
  */
1553
- function _handle_error(error) {
1554
- if (_classPrivateFieldGet2(_main_effect, this)) {
1555
- destroy_effect(_classPrivateFieldGet2(_main_effect, this));
1556
- _classPrivateFieldSet2(_main_effect, this, null);
1557
- }
1558
- if (_classPrivateFieldGet2(_pending_effect, this)) {
1559
- destroy_effect(_classPrivateFieldGet2(_pending_effect, this));
1560
- _classPrivateFieldSet2(_pending_effect, this, null);
1561
- }
1562
- if (_classPrivateFieldGet2(_failed_effect, this)) {
1563
- destroy_effect(_classPrivateFieldGet2(_failed_effect, this));
1564
- _classPrivateFieldSet2(_failed_effect, this, null);
1565
- }
1566
- if (hydrating) {
1567
- set_hydrate_node(_classPrivateFieldGet2(_hydrate_open, this));
1568
- next();
1569
- set_hydrate_node(skip_nodes());
1570
- }
1571
- var onerror = _classPrivateFieldGet2(_props, this).onerror;
1572
- let failed = _classPrivateFieldGet2(_props, this).failed;
1573
- var did_reset = false;
1574
- var calling_on_error = false;
1575
- const reset = () => {
1576
- if (did_reset) {
1577
- svelte_boundary_reset_noop();
1578
- return;
1570
+ function _defer_effects(effects) {
1571
+ for (var i = 0; i < effects.length; i += 1) defer_effect(effects[i], _classPrivateFieldGet2(_dirty_effects, this), _classPrivateFieldGet2(_maybe_dirty_effects, this));
1572
+ }
1573
+ function _commit() {
1574
+ for (let batch = first_batch; batch !== null; batch = _classPrivateFieldGet2(_next, batch)) {
1575
+ var is_earlier = batch.id < this.id;
1576
+ /** @type {Source[]} */
1577
+ var sources = [];
1578
+ for (const [source, [value, is_derived]] of this.current) {
1579
+ if (batch.current.has(source)) {
1580
+ var batch_value = batch.current.get(source)[0];
1581
+ if (is_earlier && value !== batch_value) batch.current.set(source, [value, is_derived]);
1582
+ else continue;
1583
+ }
1584
+ sources.push(source);
1579
1585
  }
1580
- did_reset = true;
1581
- if (calling_on_error) svelte_boundary_reset_onerror();
1582
- if (_classPrivateFieldGet2(_failed_effect, this) !== null) pause_effect(_classPrivateFieldGet2(_failed_effect, this), () => {
1583
- _classPrivateFieldSet2(_failed_effect, this, null);
1584
- });
1585
- _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
1586
- _assertClassBrand(_Boundary_brand, this, _render).call(this);
1587
- });
1588
- };
1589
- /** @param {unknown} transformed_error */
1590
- const handle_error_result = (transformed_error) => {
1591
- try {
1592
- calling_on_error = true;
1593
- onerror?.(transformed_error, reset);
1594
- calling_on_error = false;
1595
- } catch (error) {
1596
- invoke_error_boundary(error, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent);
1586
+ if (is_earlier) for (const [effect, deferred] of this.async_deriveds) {
1587
+ const d = batch.async_deriveds.get(effect);
1588
+ if (d) deferred.promise.then(d.resolve).catch(d.reject);
1597
1589
  }
1598
- if (failed) _classPrivateFieldSet2(_failed_effect, this, _assertClassBrand(_Boundary_brand, this, _run).call(this, () => {
1599
- try {
1600
- return branch(() => {
1601
- var effect = active_effect;
1602
- effect.b = this;
1603
- effect.f |= 128;
1604
- failed(_classPrivateFieldGet2(_anchor, this), () => transformed_error, () => reset);
1605
- });
1606
- } catch (error) {
1607
- invoke_error_boundary(error, _classPrivateFieldGet2(_effect, this).parent);
1608
- return null;
1590
+ var current = [...batch.current.keys()].filter((source) => !batch.current.get(source)[1]);
1591
+ if (!_classPrivateFieldGet2(_started, batch) || current.length === 0) continue;
1592
+ var others = current.filter((source) => !this.current.has(source));
1593
+ if (others.length === 0) {
1594
+ if (is_earlier) batch.discard();
1595
+ } else if (sources.length > 0) {
1596
+ if (is_earlier) for (const unskipped of _classPrivateFieldGet2(_unskipped_branches, this)) batch.unskip_effect(unskipped, (e) => {
1597
+ if ((e.f & 4194320) !== 0) batch.schedule(e);
1598
+ else _assertClassBrand(_Batch_brand, batch, _defer_effects).call(batch, [e]);
1599
+ });
1600
+ batch.activate();
1601
+ /** @type {Set<Value>} */
1602
+ var marked = /* @__PURE__ */ new Set();
1603
+ /** @type {Map<Reaction, boolean>} */
1604
+ var checked = /* @__PURE__ */ new Map();
1605
+ for (var source of sources) mark_effects(source, others, marked, checked);
1606
+ checked = /* @__PURE__ */ new Map();
1607
+ var current_unequal = [...batch.current].filter(([c, v1]) => {
1608
+ const v2 = this.current.get(c);
1609
+ if (!v2) return true;
1610
+ return v2[0] !== v1[0] || v2[1] !== v1[1];
1611
+ }).map(([c]) => c);
1612
+ if (current_unequal.length > 0) {
1613
+ for (const effect of _classPrivateFieldGet2(_new_effects, this)) if ((effect.f & 155648) === 0 && depends_on(effect, current_unequal, checked)) if ((effect.f & 4194320) !== 0) {
1614
+ set_signal_status(effect, DIRTY);
1615
+ batch.schedule(effect);
1616
+ } else _classPrivateFieldGet2(_dirty_effects, batch).add(effect);
1609
1617
  }
1610
- }));
1611
- };
1612
- queue_micro_task(() => {
1613
- /** @type {unknown} */
1614
- var result;
1615
- try {
1616
- result = this.transform_error(error);
1617
- } catch (e) {
1618
- invoke_error_boundary(e, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent);
1619
- return;
1618
+ if (_classPrivateFieldGet2(_roots, batch).length > 0 && !_classPrivateFieldGet2(_decrement_queued, batch)) {
1619
+ batch.apply();
1620
+ for (var root of _classPrivateFieldGet2(_roots, batch)) _assertClassBrand(_Batch_brand, batch, _traverse).call(batch, root, [], []);
1621
+ _classPrivateFieldSet2(_roots, batch, []);
1622
+ }
1623
+ batch.deactivate();
1620
1624
  }
1621
- if (result !== null && typeof result === "object" && typeof result.then === "function")
1622
- /** @type {any} */ result.then(
1623
- handle_error_result,
1624
- /** @param {unknown} e */
1625
- (e) => invoke_error_boundary(e, _classPrivateFieldGet2(_effect, this) && _classPrivateFieldGet2(_effect, this).parent)
1626
- );
1627
- else handle_error_result(result);
1628
- });
1625
+ }
1629
1626
  }
1630
- /**
1631
- * @template V
1632
- * @param {() => V} fn
1633
- * @returns {Derived<V>}
1634
- */
1635
- /*#__NO_SIDE_EFFECTS__*/
1636
- function derived(fn) {
1637
- var flags = 2 | DIRTY;
1638
- if (active_effect !== null) active_effect.f |= EFFECT_PRESERVED;
1639
- return {
1640
- ctx: component_context,
1641
- deps: null,
1642
- effects: null,
1643
- equals,
1644
- f: flags,
1645
- fn,
1646
- reactions: null,
1647
- rv: 0,
1648
- v: UNINITIALIZED,
1649
- wv: 0,
1650
- parent: active_effect,
1651
- ac: null
1652
- };
1627
+ function _unlink() {
1628
+ if (!this.linked) return;
1629
+ var prev = _classPrivateFieldGet2(_prev, this);
1630
+ var next = _classPrivateFieldGet2(_next, this);
1631
+ if (prev === null) first_batch = next;
1632
+ else _classPrivateFieldSet2(_next, prev, next);
1633
+ if (next === null) last_batch = prev;
1634
+ else _classPrivateFieldSet2(_prev, next, prev);
1635
+ this.linked = false;
1653
1636
  }
1654
1637
  /**
1655
- * @template V
1656
- * @param {() => V} fn
1657
- * @returns {Derived<V>}
1638
+ * Synchronously flush any pending updates.
1639
+ * Returns void if no callback is provided, otherwise returns the result of calling the callback.
1640
+ * @template [T=void]
1641
+ * @param {(() => T) | undefined} [fn]
1642
+ * @returns {T}
1658
1643
  */
1659
- /*#__NO_SIDE_EFFECTS__*/
1660
- function derived_safe_equal(fn) {
1661
- const signal = /* @__PURE__ */ derived(fn);
1662
- signal.equals = safe_equals;
1663
- return signal;
1644
+ function flushSync(fn) {
1645
+ var was_flushing_sync = is_flushing_sync;
1646
+ is_flushing_sync = true;
1647
+ try {
1648
+ var result;
1649
+ if (fn) {
1650
+ if (current_batch !== null && !current_batch.is_fork) current_batch.flush();
1651
+ result = fn();
1652
+ }
1653
+ while (true) {
1654
+ flush_tasks();
1655
+ if (current_batch === null) return result;
1656
+ current_batch.flush();
1657
+ }
1658
+ } finally {
1659
+ is_flushing_sync = was_flushing_sync;
1660
+ }
1661
+ }
1662
+ function infinite_loop_guard() {
1663
+ try {
1664
+ effect_update_depth_exceeded();
1665
+ } catch (error) {
1666
+ invoke_error_boundary(error, last_scheduled_effect);
1667
+ }
1664
1668
  }
1669
+ /** @type {Set<Effect> | null} */
1670
+ var eager_block_effects = null;
1665
1671
  /**
1666
- * @param {Derived} derived
1672
+ * @param {Array<Effect>} effects
1667
1673
  * @returns {void}
1668
1674
  */
1669
- function destroy_derived_effects(derived) {
1670
- var effects = derived.effects;
1671
- if (effects !== null) {
1672
- derived.effects = null;
1673
- for (var i = 0; i < effects.length; i += 1) destroy_effect(effects[i]);
1675
+ function flush_queued_effects(effects) {
1676
+ var length = effects.length;
1677
+ if (length === 0) return;
1678
+ var i = 0;
1679
+ while (i < length) {
1680
+ var effect = effects[i++];
1681
+ if ((effect.f & 24576) === 0 && is_dirty(effect)) {
1682
+ eager_block_effects = /* @__PURE__ */ new Set();
1683
+ update_effect(effect);
1684
+ if (effect.deps === null && effect.first === null && effect.nodes === null && effect.teardown === null && effect.ac === null) unlink_effect(effect);
1685
+ if (eager_block_effects?.size > 0) {
1686
+ old_values.clear();
1687
+ for (const e of eager_block_effects) {
1688
+ if ((e.f & 24576) !== 0) continue;
1689
+ /** @type {Effect[]} */
1690
+ const ordered_effects = [e];
1691
+ let ancestor = e.parent;
1692
+ while (ancestor !== null) {
1693
+ if (eager_block_effects.has(ancestor)) {
1694
+ eager_block_effects.delete(ancestor);
1695
+ ordered_effects.push(ancestor);
1696
+ }
1697
+ ancestor = ancestor.parent;
1698
+ }
1699
+ for (let j = ordered_effects.length - 1; j >= 0; j--) {
1700
+ const e = ordered_effects[j];
1701
+ if ((e.f & 24576) !== 0) continue;
1702
+ update_effect(e);
1703
+ }
1704
+ }
1705
+ eager_block_effects.clear();
1706
+ }
1707
+ }
1674
1708
  }
1709
+ eager_block_effects = null;
1675
1710
  }
1676
1711
  /**
1677
- * @template T
1678
- * @param {Derived} derived
1679
- * @returns {T}
1712
+ * This is similar to `mark_reactions`, but it only marks async/block effects
1713
+ * depending on `value` and at least one of the other `sources`, so that
1714
+ * these effects can re-run after another batch has been committed
1715
+ * @param {Value} value
1716
+ * @param {Source[]} sources
1717
+ * @param {Set<Value>} marked
1718
+ * @param {Map<Reaction, boolean>} checked
1680
1719
  */
1681
- function execute_derived(derived) {
1682
- var value;
1683
- var prev_active_effect = active_effect;
1684
- var parent = derived.parent;
1685
- if (!is_destroying_effect && parent !== null && derived.v !== UNINITIALIZED && (parent.f & 24576) !== 0) {
1686
- derived_inert();
1687
- return derived.v;
1688
- }
1689
- set_active_effect(parent);
1690
- try {
1691
- derived.f &= ~WAS_MARKED;
1692
- destroy_derived_effects(derived);
1693
- value = update_reaction(derived);
1694
- } finally {
1695
- set_active_effect(prev_active_effect);
1720
+ function mark_effects(value, sources, marked, checked) {
1721
+ if (marked.has(value)) return;
1722
+ marked.add(value);
1723
+ if (value.reactions !== null) for (const reaction of value.reactions) {
1724
+ const flags = reaction.f;
1725
+ if ((flags & 2) !== 0) mark_effects(reaction, sources, marked, checked);
1726
+ else if ((flags & 4194320) !== 0 && (flags & 2048) === 0 && depends_on(reaction, sources, checked)) {
1727
+ set_signal_status(reaction, DIRTY);
1728
+ schedule_effect(reaction);
1729
+ }
1696
1730
  }
1697
- return value;
1698
1731
  }
1699
1732
  /**
1700
- * @param {Derived} derived
1701
- * @returns {void}
1733
+ * @param {Reaction} reaction
1734
+ * @param {Source[]} sources
1735
+ * @param {Map<Reaction, boolean>} checked
1702
1736
  */
1703
- function update_derived(derived) {
1704
- var value = execute_derived(derived);
1705
- if (!derived.equals(value)) {
1706
- derived.wv = increment_write_version();
1707
- if (!current_batch?.is_fork || derived.deps === null) {
1708
- if (current_batch !== null) {
1709
- current_batch.capture(derived, value, true);
1710
- previous_batch?.capture(derived, value, true);
1711
- } else derived.v = value;
1712
- if (derived.deps === null) {
1713
- set_signal_status(derived, CLEAN);
1714
- return;
1715
- }
1737
+ function depends_on(reaction, sources, checked) {
1738
+ const depends = checked.get(reaction);
1739
+ if (depends !== void 0) return depends;
1740
+ if (reaction.deps !== null) for (const dep of reaction.deps) {
1741
+ if (includes.call(sources, dep)) return true;
1742
+ if ((dep.f & 2) !== 0 && depends_on(dep, sources, checked)) {
1743
+ checked.set(dep, true);
1744
+ return true;
1716
1745
  }
1717
1746
  }
1718
- if (is_destroying_effect) return;
1719
- if (batch_values !== null) {
1720
- if (effect_tracking() || current_batch?.is_fork) batch_values.set(derived, value);
1721
- } else update_derived_status(derived);
1747
+ checked.set(reaction, false);
1748
+ return false;
1722
1749
  }
1723
1750
  /**
1724
- * @param {Derived} derived
1751
+ * @param {Effect} effect
1752
+ * @returns {void}
1725
1753
  */
1726
- function freeze_derived_effects(derived) {
1727
- if (derived.effects === null) return;
1728
- for (const e of derived.effects) if (e.teardown || e.ac) {
1729
- e.teardown?.();
1730
- e.ac?.abort(STALE_REACTION);
1731
- if (e.fn !== null) e.teardown = noop;
1732
- e.ac = null;
1733
- remove_reactions(e, 0);
1734
- destroy_effect_children(e);
1754
+ function schedule_effect(effect) {
1755
+ /** @type {Batch} */ current_batch.schedule(effect);
1756
+ }
1757
+ /**
1758
+ * Mark all the effects inside a skipped branch CLEAN, so that
1759
+ * they can be correctly rescheduled later. Tracks dirty and maybe_dirty
1760
+ * effects so they can be rescheduled if the branch survives.
1761
+ * @param {Effect} effect
1762
+ * @param {{ d: Effect[], m: Effect[] }} tracked
1763
+ */
1764
+ function reset_branch(effect, tracked) {
1765
+ if ((effect.f & 32) !== 0 && (effect.f & 1024) !== 0) return;
1766
+ if ((effect.f & 2048) !== 0) tracked.d.push(effect);
1767
+ else if ((effect.f & 4096) !== 0) tracked.m.push(effect);
1768
+ set_signal_status(effect, CLEAN);
1769
+ var e = effect.first;
1770
+ while (e !== null) {
1771
+ reset_branch(e, tracked);
1772
+ e = e.next;
1735
1773
  }
1736
1774
  }
1737
1775
  /**
1738
- * @param {Derived} derived
1776
+ * Mark an entire effect tree clean following an error
1777
+ * @param {Effect} effect
1739
1778
  */
1740
- function unfreeze_derived_effects(derived) {
1741
- if (derived.effects === null) return;
1742
- for (const e of derived.effects) if (e.teardown && e.fn !== null) update_effect(e);
1779
+ function reset_all(effect) {
1780
+ set_signal_status(effect, CLEAN);
1781
+ var e = effect.first;
1782
+ while (e !== null) {
1783
+ reset_all(e);
1784
+ e = e.next;
1785
+ }
1743
1786
  }
1744
1787
  //#endregion
1745
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/sources.js
1788
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/sources.js
1746
1789
  /** @import { Derived, Effect, Source, Value } from '#client' */
1747
1790
  /** @type {Set<Effect>} */
1748
1791
  var eager_effects = /* @__PURE__ */ new Set();
@@ -2040,19 +2083,8 @@ function proxy(value) {
2040
2083
  }
2041
2084
  });
2042
2085
  }
2043
- new Set([
2044
- "copyWithin",
2045
- "fill",
2046
- "pop",
2047
- "push",
2048
- "reverse",
2049
- "shift",
2050
- "sort",
2051
- "splice",
2052
- "unshift"
2053
- ]);
2054
2086
  //#endregion
2055
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/operations.js
2087
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/operations.js
2056
2088
  /** @type {Window} */
2057
2089
  var $window;
2058
2090
  /** @type {boolean} */
@@ -2132,25 +2164,7 @@ function create_element(tag, namespace, is) {
2132
2164
  return is ? document.createElementNS(namespace, tag, { is }) : document.createElementNS(namespace, tag);
2133
2165
  }
2134
2166
  //#endregion
2135
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/elements/bindings/shared.js
2136
- /**
2137
- * @template T
2138
- * @param {() => T} fn
2139
- */
2140
- function without_reactive_context(fn) {
2141
- var previous_reaction = active_reaction;
2142
- var previous_effect = active_effect;
2143
- set_active_reaction(null);
2144
- set_active_effect(null);
2145
- try {
2146
- return fn();
2147
- } finally {
2148
- set_active_reaction(previous_reaction);
2149
- set_active_effect(previous_effect);
2150
- }
2151
- }
2152
- //#endregion
2153
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/effects.js
2167
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/effects.js
2154
2168
  /** @import { Blocker, ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
2155
2169
  /**
2156
2170
  * @param {Effect} effect
@@ -2454,15 +2468,18 @@ function move_effect(effect, fragment) {
2454
2468
  }
2455
2469
  }
2456
2470
  //#endregion
2457
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/legacy.js
2471
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/legacy.js
2458
2472
  /**
2459
2473
  * @type {Set<Value> | null}
2460
2474
  * @deprecated
2461
2475
  */
2462
2476
  var captured_signals = null;
2463
2477
  //#endregion
2464
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/runtime.js
2478
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/runtime.js
2465
2479
  /** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
2480
+ /**
2481
+ * True if updating in an effect context that is reactive (i.e. not branch/root effects)
2482
+ */
2466
2483
  var is_updating_effect = false;
2467
2484
  var is_destroying_effect = false;
2468
2485
  /** @param {boolean} value */
@@ -2663,6 +2680,11 @@ function remove_reaction(signal, dependency) {
2663
2680
  derived.f &= ~WAS_MARKED;
2664
2681
  }
2665
2682
  if (derived.v !== UNINITIALIZED) update_derived_status(derived);
2683
+ if (derived.ac !== null) without_reactive_context(() => {
2684
+ /** @type {AbortController} */ derived.ac.abort(STALE_REACTION);
2685
+ derived.ac = null;
2686
+ set_signal_status(derived, DIRTY);
2687
+ });
2666
2688
  freeze_derived_effects(derived);
2667
2689
  remove_reactions(derived, 0);
2668
2690
  }
@@ -2688,7 +2710,7 @@ function update_effect(effect) {
2688
2710
  var previous_effect = active_effect;
2689
2711
  var was_updating_effect = is_updating_effect;
2690
2712
  active_effect = effect;
2691
- is_updating_effect = true;
2713
+ is_updating_effect = (flags & 96) === 0;
2692
2714
  try {
2693
2715
  if ((flags & 16777232) !== 0) destroy_block_effect_children(effect);
2694
2716
  else destroy_effect_children(effect);
@@ -2805,7 +2827,7 @@ function untrack(fn) {
2805
2827
  }
2806
2828
  }
2807
2829
  //#endregion
2808
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/elements/events.js
2830
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/elements/events.js
2809
2831
  /**
2810
2832
  * Used on elements, as a map of event type -> event handler,
2811
2833
  * and on events themselves to track which element handled an event
@@ -2888,7 +2910,7 @@ function handle_event_propagation(event) {
2888
2910
  }
2889
2911
  }
2890
2912
  //#endregion
2891
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/reconciler.js
2913
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/reconciler.js
2892
2914
  var policy = globalThis?.window?.trustedTypes && /* @__PURE__ */ globalThis.window.trustedTypes.createPolicy("svelte-trusted-html", {
2893
2915
  /** @param {string} html */
2894
2916
  createHTML: (html) => {
@@ -2907,7 +2929,7 @@ function create_fragment_from_html(html) {
2907
2929
  return elem.content;
2908
2930
  }
2909
2931
  //#endregion
2910
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/template.js
2932
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/template.js
2911
2933
  /** @import { Effect, EffectNodes, TemplateNode } from '#client' */
2912
2934
  /** @import { TemplateStructure } from './types' */
2913
2935
  /**
@@ -3166,7 +3188,7 @@ function unmount(component, options) {
3166
3188
  return Promise.resolve();
3167
3189
  }
3168
3190
  //#endregion
3169
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/css.js
3191
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/css.js
3170
3192
  /**
3171
3193
  * @param {Node} anchor
3172
3194
  * @param {{ hash: string, code: string }} css
@@ -3184,7 +3206,7 @@ function append_styles(anchor, css) {
3184
3206
  });
3185
3207
  }
3186
3208
  //#endregion
3187
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/elements/bindings/size.js
3209
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/elements/bindings/size.js
3188
3210
  var _ResizeObserverSingleton;
3189
3211
  var _listeners = /* @__PURE__ */ new WeakMap();
3190
3212
  var _observer = /* @__PURE__ */ new WeakMap();
@@ -3236,7 +3258,7 @@ function _getObserver() {
3236
3258
  }
3237
3259
  _defineProperty(ResizeObserverSingleton, "entries", /* @__PURE__ */ new WeakMap());
3238
3260
  //#endregion
3239
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/reactivity/props.js
3261
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/reactivity/props.js
3240
3262
  /** @import { Derived, Effect, Source } from './types.js' */
3241
3263
  /**
3242
3264
  * This function is responsible for synchronizing a possibly bound prop with the inner component state.
@@ -3329,7 +3351,7 @@ function prop(props, key, flags, fallback) {
3329
3351
  });
3330
3352
  }
3331
3353
  //#endregion
3332
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/legacy/legacy-client.js
3354
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/legacy/legacy-client.js
3333
3355
  /** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */
3334
3356
  /**
3335
3357
  * Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
@@ -3448,7 +3470,7 @@ var Svelte4Component = class {
3448
3470
  }
3449
3471
  };
3450
3472
  //#endregion
3451
- //#region ../../../node_modules/.bun/svelte@5.56.1/node_modules/svelte/src/internal/client/dom/elements/custom-element.js
3473
+ //#region ../../../node_modules/.bun/svelte@5.56.8/node_modules/svelte/src/internal/client/dom/elements/custom-element.js
3452
3474
  /**
3453
3475
  * @typedef {Object} CustomElementPropDefinition
3454
3476
  * @property {string} [attribute]