@retoo/scena 0.0.1 → 0.0.2

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.
package/dist/scena.es.js CHANGED
@@ -58,6 +58,7 @@ const MAYBE_DIRTY = 1 << 12;
58
58
  const INERT = 1 << 13;
59
59
  const DESTROYED = 1 << 14;
60
60
  const REACTION_RAN = 1 << 15;
61
+ const DESTROYING = 1 << 25;
61
62
  const EFFECT_TRANSPARENT = 1 << 16;
62
63
  const EAGER_EFFECT = 1 << 17;
63
64
  const HEAD_EFFECT = 1 << 18;
@@ -138,6 +139,11 @@ function svelte_boundary_reset_onerror() {
138
139
  throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
139
140
  }
140
141
  }
142
+ function derived_inert() {
143
+ {
144
+ console.warn(`https://svelte.dev/e/derived_inert`);
145
+ }
146
+ }
141
147
  function select_multiple_invalid_value() {
142
148
  {
143
149
  console.warn(`https://svelte.dev/e/select_multiple_invalid_value`);
@@ -203,6 +209,10 @@ function push(props, runes = false, fn) {
203
209
  e: null,
204
210
  s: props,
205
211
  x: null,
212
+ r: (
213
+ /** @type {Effect} */
214
+ active_effect
215
+ ),
206
216
  l: legacy_mode_flag && !runes ? { s: null, u: null, $: [] } : null
207
217
  };
208
218
  }
@@ -322,29 +332,44 @@ function defer_effect(effect2, dirty_effects, maybe_dirty_effects) {
322
332
  clear_marked(effect2.deps);
323
333
  set_signal_status(effect2, CLEAN);
324
334
  }
335
+ let is_store_binding = false;
336
+ function capture_store_binding(fn) {
337
+ var previous_is_store_binding = is_store_binding;
338
+ try {
339
+ is_store_binding = false;
340
+ return [fn(), is_store_binding];
341
+ } finally {
342
+ is_store_binding = previous_is_store_binding;
343
+ }
344
+ }
325
345
  const batches = /* @__PURE__ */ new Set();
326
346
  let current_batch = null;
327
347
  let batch_values = null;
328
- let queued_root_effects = [];
329
348
  let last_scheduled_effect = null;
330
- let is_flushing = false;
349
+ let is_processing = false;
350
+ let collected_effects = null;
351
+ let legacy_updates = null;
352
+ var flush_count = 0;
353
+ let uid = 1;
331
354
  class Batch {
355
+ id = uid++;
332
356
  /**
333
- * The current values of any sources that are updated in this batch
357
+ * The current values of any signals that are updated in this batch.
358
+ * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
334
359
  * They keys of this map are identical to `this.#previous`
335
- * @type {Map<Source, any>}
360
+ * @type {Map<Value, [any, boolean]>}
336
361
  */
337
362
  current = /* @__PURE__ */ new Map();
338
363
  /**
339
- * The values of any sources that are updated in this batch _before_ those updates took place.
364
+ * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
340
365
  * They keys of this map are identical to `this.#current`
341
- * @type {Map<Source, any>}
366
+ * @type {Map<Value, any>}
342
367
  */
343
368
  previous = /* @__PURE__ */ new Map();
344
369
  /**
345
370
  * When the batch is committed (and the DOM is updated), we need to remove old branches
346
371
  * and append new ones by calling the functions added inside (if/each/key/etc) blocks
347
- * @type {Set<() => void>}
372
+ * @type {Set<(batch: Batch) => void>}
348
373
  */
349
374
  #commit_callbacks = /* @__PURE__ */ new Set();
350
375
  /**
@@ -353,19 +378,36 @@ class Batch {
353
378
  */
354
379
  #discard_callbacks = /* @__PURE__ */ new Set();
355
380
  /**
356
- * The number of async effects that are currently in flight
381
+ * Callbacks that should run only when a fork is committed.
382
+ * @type {Set<(batch: Batch) => void>}
383
+ */
384
+ #fork_commit_callbacks = /* @__PURE__ */ new Set();
385
+ /**
386
+ * Async effects that are currently in flight
387
+ * @type {Map<Effect, number>}
357
388
  */
358
- #pending = 0;
389
+ #pending = /* @__PURE__ */ new Map();
359
390
  /**
360
- * The number of async effects that are currently in flight, _not_ inside a pending boundary
391
+ * Async effects that are currently in flight, _not_ inside a pending boundary
392
+ * @type {Map<Effect, number>}
361
393
  */
362
- #blocking_pending = 0;
394
+ #blocking_pending = /* @__PURE__ */ new Map();
363
395
  /**
364
396
  * A deferred that resolves when the batch is committed, used with `settled()`
365
397
  * TODO replace with Promise.withResolvers once supported widely enough
366
398
  * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
367
399
  */
368
400
  #deferred = null;
401
+ /**
402
+ * The root effects that need to be flushed
403
+ * @type {Effect[]}
404
+ */
405
+ #roots = [];
406
+ /**
407
+ * Effects created while this batch was active.
408
+ * @type {Effect[]}
409
+ */
410
+ #new_effects = [];
369
411
  /**
370
412
  * Deferred effects (which run after async work has completed) that are DIRTY
371
413
  * @type {Set<Effect>}
@@ -384,10 +426,36 @@ class Batch {
384
426
  * @type {Map<Effect, { d: Effect[], m: Effect[] }>}
385
427
  */
386
428
  #skipped_branches = /* @__PURE__ */ new Map();
429
+ /**
430
+ * Inverse of #skipped_branches which we need to tell prior batches to unskip them when committing
431
+ * @type {Set<Effect>}
432
+ */
433
+ #unskipped_branches = /* @__PURE__ */ new Set();
387
434
  is_fork = false;
388
435
  #decrement_queued = false;
436
+ /** @type {Set<Batch>} */
437
+ #blockers = /* @__PURE__ */ new Set();
389
438
  #is_deferred() {
390
- return this.is_fork || this.#blocking_pending > 0;
439
+ return this.is_fork || this.#blocking_pending.size > 0;
440
+ }
441
+ #is_blocked() {
442
+ for (const batch of this.#blockers) {
443
+ for (const effect2 of batch.#blocking_pending.keys()) {
444
+ var skipped = false;
445
+ var e = effect2;
446
+ while (e.parent !== null) {
447
+ if (this.#skipped_branches.has(e)) {
448
+ skipped = true;
449
+ break;
450
+ }
451
+ e = e.parent;
452
+ }
453
+ if (!skipped) {
454
+ return true;
455
+ }
456
+ }
457
+ }
458
+ return false;
391
459
  }
392
460
  /**
393
461
  * Add an effect to the #skipped_branches map and reset its children
@@ -397,58 +465,99 @@ class Batch {
397
465
  if (!this.#skipped_branches.has(effect2)) {
398
466
  this.#skipped_branches.set(effect2, { d: [], m: [] });
399
467
  }
468
+ this.#unskipped_branches.delete(effect2);
400
469
  }
401
470
  /**
402
471
  * Remove an effect from the #skipped_branches map and reschedule
403
472
  * any tracked dirty/maybe_dirty child effects
404
473
  * @param {Effect} effect
474
+ * @param {(e: Effect) => void} callback
405
475
  */
406
- unskip_effect(effect2) {
476
+ unskip_effect(effect2, callback = (e) => this.schedule(e)) {
407
477
  var tracked = this.#skipped_branches.get(effect2);
408
478
  if (tracked) {
409
479
  this.#skipped_branches.delete(effect2);
410
480
  for (var e of tracked.d) {
411
481
  set_signal_status(e, DIRTY);
412
- schedule_effect(e);
482
+ callback(e);
413
483
  }
414
484
  for (e of tracked.m) {
415
485
  set_signal_status(e, MAYBE_DIRTY);
416
- schedule_effect(e);
486
+ callback(e);
417
487
  }
418
488
  }
489
+ this.#unskipped_branches.add(effect2);
419
490
  }
420
- /**
421
- *
422
- * @param {Effect[]} root_effects
423
- */
424
- process(root_effects) {
425
- queued_root_effects = [];
491
+ #process() {
492
+ if (flush_count++ > 1e3) {
493
+ batches.delete(this);
494
+ infinite_loop_guard();
495
+ }
496
+ if (!this.#is_deferred()) {
497
+ for (const e of this.#dirty_effects) {
498
+ this.#maybe_dirty_effects.delete(e);
499
+ set_signal_status(e, DIRTY);
500
+ this.schedule(e);
501
+ }
502
+ for (const e of this.#maybe_dirty_effects) {
503
+ set_signal_status(e, MAYBE_DIRTY);
504
+ this.schedule(e);
505
+ }
506
+ }
507
+ const roots = this.#roots;
508
+ this.#roots = [];
426
509
  this.apply();
427
- var effects = [];
510
+ var effects = collected_effects = [];
428
511
  var render_effects = [];
429
- for (const root2 of root_effects) {
430
- this.#traverse_effect_tree(root2, effects, render_effects);
512
+ var updates = legacy_updates = [];
513
+ for (const root2 of roots) {
514
+ try {
515
+ this.#traverse(root2, effects, render_effects);
516
+ } catch (e) {
517
+ reset_all(root2);
518
+ throw e;
519
+ }
520
+ }
521
+ current_batch = null;
522
+ if (updates.length > 0) {
523
+ var batch = Batch.ensure();
524
+ for (const e of updates) {
525
+ batch.schedule(e);
526
+ }
431
527
  }
432
- if (this.#is_deferred()) {
528
+ collected_effects = null;
529
+ legacy_updates = null;
530
+ if (this.#is_deferred() || this.#is_blocked()) {
433
531
  this.#defer_effects(render_effects);
434
532
  this.#defer_effects(effects);
435
533
  for (const [e, t] of this.#skipped_branches) {
436
534
  reset_branch(e, t);
437
535
  }
438
536
  } else {
439
- for (const fn of this.#commit_callbacks) fn();
440
- this.#commit_callbacks.clear();
441
- if (this.#pending === 0) {
442
- this.#commit();
537
+ if (this.#pending.size === 0) {
538
+ batches.delete(this);
443
539
  }
444
- current_batch = null;
445
- flush_queued_effects(render_effects);
446
- flush_queued_effects(effects);
447
540
  this.#dirty_effects.clear();
448
541
  this.#maybe_dirty_effects.clear();
542
+ for (const fn of this.#commit_callbacks) fn(this);
543
+ this.#commit_callbacks.clear();
544
+ flush_queued_effects(render_effects);
545
+ flush_queued_effects(effects);
449
546
  this.#deferred?.resolve();
450
547
  }
451
- batch_values = null;
548
+ var next_batch = (
549
+ /** @type {Batch | null} */
550
+ /** @type {unknown} */
551
+ current_batch
552
+ );
553
+ if (this.#roots.length > 0) {
554
+ const batch2 = next_batch ??= this;
555
+ batch2.#roots.push(...this.#roots.filter((r2) => !batch2.#roots.includes(r2)));
556
+ }
557
+ if (next_batch !== null) {
558
+ batches.add(next_batch);
559
+ next_batch.#process();
560
+ }
452
561
  }
453
562
  /**
454
563
  * Traverse the effect tree, executing effects or stashing
@@ -457,7 +566,7 @@ class Batch {
457
566
  * @param {Effect[]} effects
458
567
  * @param {Effect[]} render_effects
459
568
  */
460
- #traverse_effect_tree(root2, effects, render_effects) {
569
+ #traverse(root2, effects, render_effects) {
461
570
  root2.f ^= CLEAN;
462
571
  var effect2 = root2.first;
463
572
  while (effect2 !== null) {
@@ -501,132 +610,189 @@ class Batch {
501
610
  /**
502
611
  * Associate a change to a given source with the current
503
612
  * batch, noting its previous and current values
504
- * @param {Source} source
613
+ * @param {Value} source
505
614
  * @param {any} value
615
+ * @param {boolean} [is_derived]
506
616
  */
507
- capture(source2, value) {
508
- if (value !== UNINITIALIZED && !this.previous.has(source2)) {
509
- this.previous.set(source2, value);
617
+ capture(source2, value, is_derived = false) {
618
+ if (source2.v !== UNINITIALIZED && !this.previous.has(source2)) {
619
+ this.previous.set(source2, source2.v);
510
620
  }
511
621
  if ((source2.f & ERROR_VALUE) === 0) {
512
- this.current.set(source2, source2.v);
513
- batch_values?.set(source2, source2.v);
622
+ this.current.set(source2, [value, is_derived]);
623
+ batch_values?.set(source2, value);
624
+ }
625
+ if (!this.is_fork) {
626
+ source2.v = value;
514
627
  }
515
628
  }
516
629
  activate() {
517
630
  current_batch = this;
518
- this.apply();
519
631
  }
520
632
  deactivate() {
521
- if (current_batch !== this) return;
522
633
  current_batch = null;
523
634
  batch_values = null;
524
635
  }
525
636
  flush() {
526
- this.activate();
527
- if (queued_root_effects.length > 0) {
528
- flush_effects();
529
- if (current_batch !== null && current_batch !== this) {
530
- return;
531
- }
532
- } else if (this.#pending === 0) {
533
- this.process([]);
637
+ try {
638
+ is_processing = true;
639
+ current_batch = this;
640
+ this.#process();
641
+ } finally {
642
+ flush_count = 0;
643
+ last_scheduled_effect = null;
644
+ collected_effects = null;
645
+ legacy_updates = null;
646
+ is_processing = false;
647
+ current_batch = null;
648
+ batch_values = null;
649
+ old_values.clear();
534
650
  }
535
- this.deactivate();
536
651
  }
537
652
  discard() {
538
653
  for (const fn of this.#discard_callbacks) fn(this);
539
654
  this.#discard_callbacks.clear();
655
+ this.#fork_commit_callbacks.clear();
656
+ batches.delete(this);
657
+ }
658
+ /**
659
+ * @param {Effect} effect
660
+ */
661
+ register_created_effect(effect2) {
662
+ this.#new_effects.push(effect2);
540
663
  }
541
664
  #commit() {
542
- if (batches.size > 1) {
543
- this.previous.clear();
544
- var previous_batch_values = batch_values;
545
- var is_earlier = true;
546
- for (const batch of batches) {
547
- if (batch === this) {
548
- is_earlier = false;
549
- continue;
550
- }
551
- const sources = [];
552
- for (const [source2, value] of this.current) {
553
- if (batch.current.has(source2)) {
554
- if (is_earlier && value !== batch.current.get(source2)) {
555
- batch.current.set(source2, value);
556
- } else {
557
- continue;
558
- }
665
+ for (const batch of batches) {
666
+ var is_earlier = batch.id < this.id;
667
+ var sources = [];
668
+ for (const [source3, [value, is_derived]] of this.current) {
669
+ if (batch.current.has(source3)) {
670
+ var batch_value = (
671
+ /** @type {[any, boolean]} */
672
+ batch.current.get(source3)[0]
673
+ );
674
+ if (is_earlier && value !== batch_value) {
675
+ batch.current.set(source3, [value, is_derived]);
676
+ } else {
677
+ continue;
559
678
  }
560
- sources.push(source2);
561
679
  }
562
- if (sources.length === 0) {
563
- continue;
680
+ sources.push(source3);
681
+ }
682
+ var others = [...batch.current.keys()].filter((s) => !this.current.has(s));
683
+ if (others.length === 0) {
684
+ if (is_earlier) {
685
+ batch.discard();
564
686
  }
565
- const others = [...batch.current.keys()].filter((s) => !this.current.has(s));
566
- if (others.length > 0) {
567
- var prev_queued_root_effects = queued_root_effects;
568
- queued_root_effects = [];
569
- const marked = /* @__PURE__ */ new Set();
570
- const checked = /* @__PURE__ */ new Map();
571
- for (const source2 of sources) {
572
- mark_effects(source2, others, marked, checked);
687
+ } else if (sources.length > 0) {
688
+ if (is_earlier) {
689
+ for (const unskipped of this.#unskipped_branches) {
690
+ batch.unskip_effect(unskipped, (e) => {
691
+ if ((e.f & (BLOCK_EFFECT | ASYNC)) !== 0) {
692
+ batch.schedule(e);
693
+ } else {
694
+ batch.#defer_effects([e]);
695
+ }
696
+ });
573
697
  }
574
- if (queued_root_effects.length > 0) {
575
- current_batch = batch;
576
- batch.apply();
577
- for (const root2 of queued_root_effects) {
578
- batch.#traverse_effect_tree(root2, [], []);
698
+ }
699
+ batch.activate();
700
+ var marked = /* @__PURE__ */ new Set();
701
+ var checked = /* @__PURE__ */ new Map();
702
+ for (var source2 of sources) {
703
+ mark_effects(source2, others, marked, checked);
704
+ }
705
+ checked = /* @__PURE__ */ new Map();
706
+ var current_unequal = [...batch.current.keys()].filter(
707
+ (c) => this.current.has(c) ? (
708
+ /** @type {[any, boolean]} */
709
+ this.current.get(c)[0] !== c
710
+ ) : true
711
+ );
712
+ for (const effect2 of this.#new_effects) {
713
+ if ((effect2.f & (DESTROYED | INERT | EAGER_EFFECT)) === 0 && depends_on(effect2, current_unequal, checked)) {
714
+ if ((effect2.f & (ASYNC | BLOCK_EFFECT)) !== 0) {
715
+ set_signal_status(effect2, DIRTY);
716
+ batch.schedule(effect2);
717
+ } else {
718
+ batch.#dirty_effects.add(effect2);
579
719
  }
580
- batch.deactivate();
581
720
  }
582
- queued_root_effects = prev_queued_root_effects;
721
+ }
722
+ if (batch.#roots.length > 0) {
723
+ batch.apply();
724
+ for (var root2 of batch.#roots) {
725
+ batch.#traverse(root2, [], []);
726
+ }
727
+ batch.#roots = [];
728
+ }
729
+ batch.deactivate();
730
+ }
731
+ }
732
+ for (const batch of batches) {
733
+ if (batch.#blockers.has(this)) {
734
+ batch.#blockers.delete(this);
735
+ if (batch.#blockers.size === 0 && !batch.#is_deferred()) {
736
+ batch.activate();
737
+ batch.#process();
583
738
  }
584
739
  }
585
- current_batch = null;
586
- batch_values = previous_batch_values;
587
740
  }
588
- this.#skipped_branches.clear();
589
- batches.delete(this);
590
741
  }
591
742
  /**
592
- *
593
743
  * @param {boolean} blocking
744
+ * @param {Effect} effect
594
745
  */
595
- increment(blocking) {
596
- this.#pending += 1;
597
- if (blocking) this.#blocking_pending += 1;
746
+ increment(blocking, effect2) {
747
+ let pending_count = this.#pending.get(effect2) ?? 0;
748
+ this.#pending.set(effect2, pending_count + 1);
749
+ if (blocking) {
750
+ let blocking_pending_count = this.#blocking_pending.get(effect2) ?? 0;
751
+ this.#blocking_pending.set(effect2, blocking_pending_count + 1);
752
+ }
598
753
  }
599
754
  /**
600
- *
601
755
  * @param {boolean} blocking
756
+ * @param {Effect} effect
757
+ * @param {boolean} skip - whether to skip updates (because this is triggered by a stale reaction)
602
758
  */
603
- decrement(blocking) {
604
- this.#pending -= 1;
605
- if (blocking) this.#blocking_pending -= 1;
606
- if (this.#decrement_queued) return;
759
+ decrement(blocking, effect2, skip) {
760
+ let pending_count = this.#pending.get(effect2) ?? 0;
761
+ if (pending_count === 1) {
762
+ this.#pending.delete(effect2);
763
+ } else {
764
+ this.#pending.set(effect2, pending_count - 1);
765
+ }
766
+ if (blocking) {
767
+ let blocking_pending_count = this.#blocking_pending.get(effect2) ?? 0;
768
+ if (blocking_pending_count === 1) {
769
+ this.#blocking_pending.delete(effect2);
770
+ } else {
771
+ this.#blocking_pending.set(effect2, blocking_pending_count - 1);
772
+ }
773
+ }
774
+ if (this.#decrement_queued || skip) return;
607
775
  this.#decrement_queued = true;
608
776
  queue_micro_task(() => {
609
777
  this.#decrement_queued = false;
610
- if (!this.#is_deferred()) {
611
- this.revive();
612
- } else if (queued_root_effects.length > 0) {
613
- this.flush();
614
- }
778
+ this.flush();
615
779
  });
616
780
  }
617
- revive() {
618
- for (const e of this.#dirty_effects) {
619
- this.#maybe_dirty_effects.delete(e);
620
- set_signal_status(e, DIRTY);
621
- schedule_effect(e);
781
+ /**
782
+ * @param {Set<Effect>} dirty_effects
783
+ * @param {Set<Effect>} maybe_dirty_effects
784
+ */
785
+ transfer_effects(dirty_effects, maybe_dirty_effects) {
786
+ for (const e of dirty_effects) {
787
+ this.#dirty_effects.add(e);
622
788
  }
623
- for (const e of this.#maybe_dirty_effects) {
624
- set_signal_status(e, MAYBE_DIRTY);
625
- schedule_effect(e);
789
+ for (const e of maybe_dirty_effects) {
790
+ this.#maybe_dirty_effects.add(e);
626
791
  }
627
- this.flush();
792
+ dirty_effects.clear();
793
+ maybe_dirty_effects.clear();
628
794
  }
629
- /** @param {() => void} fn */
795
+ /** @param {(batch: Batch) => void} fn */
630
796
  oncommit(fn) {
631
797
  this.#commit_callbacks.add(fn);
632
798
  }
@@ -634,48 +800,67 @@ class Batch {
634
800
  ondiscard(fn) {
635
801
  this.#discard_callbacks.add(fn);
636
802
  }
803
+ /** @param {(batch: Batch) => void} fn */
804
+ on_fork_commit(fn) {
805
+ this.#fork_commit_callbacks.add(fn);
806
+ }
807
+ run_fork_commit_callbacks() {
808
+ for (const fn of this.#fork_commit_callbacks) fn(this);
809
+ this.#fork_commit_callbacks.clear();
810
+ }
637
811
  settled() {
638
812
  return (this.#deferred ??= deferred()).promise;
639
813
  }
640
814
  static ensure() {
641
815
  if (current_batch === null) {
642
816
  const batch = current_batch = new Batch();
643
- batches.add(current_batch);
644
- {
645
- queue_micro_task(() => {
646
- if (current_batch !== batch) {
647
- return;
648
- }
649
- batch.flush();
650
- });
817
+ if (!is_processing) {
818
+ batches.add(current_batch);
819
+ {
820
+ queue_micro_task(() => {
821
+ if (current_batch !== batch) {
822
+ return;
823
+ }
824
+ batch.flush();
825
+ });
826
+ }
651
827
  }
652
828
  }
653
829
  return current_batch;
654
830
  }
655
831
  apply() {
656
- return;
832
+ {
833
+ batch_values = null;
834
+ return;
835
+ }
657
836
  }
658
- }
659
- function flush_effects() {
660
- is_flushing = true;
661
- var source_stacks = null;
662
- try {
663
- var flush_count = 0;
664
- while (queued_root_effects.length > 0) {
665
- var batch = Batch.ensure();
666
- if (flush_count++ > 1e3) {
667
- var updates, entry;
668
- if (DEV) ;
669
- infinite_loop_guard();
837
+ /**
838
+ *
839
+ * @param {Effect} effect
840
+ */
841
+ schedule(effect2) {
842
+ last_scheduled_effect = effect2;
843
+ if (effect2.b?.is_pending && (effect2.f & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0 && (effect2.f & REACTION_RAN) === 0) {
844
+ effect2.b.defer_effect(effect2);
845
+ return;
846
+ }
847
+ var e = effect2;
848
+ while (e.parent !== null) {
849
+ e = e.parent;
850
+ var flags2 = e.f;
851
+ if (collected_effects !== null && e === active_effect) {
852
+ if ((active_reaction === null || (active_reaction.f & DERIVED) === 0) && true) {
853
+ return;
854
+ }
855
+ }
856
+ if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
857
+ if ((flags2 & CLEAN) === 0) {
858
+ return;
859
+ }
860
+ e.f ^= CLEAN;
670
861
  }
671
- batch.process(queued_root_effects);
672
- old_values.clear();
673
- if (DEV) ;
674
862
  }
675
- } finally {
676
- queued_root_effects = [];
677
- is_flushing = false;
678
- last_scheduled_effect = null;
863
+ this.#roots.push(e);
679
864
  }
680
865
  }
681
866
  function infinite_loop_guard() {
@@ -773,27 +958,8 @@ function depends_on(reaction, sources, checked) {
773
958
  checked.set(reaction, false);
774
959
  return false;
775
960
  }
776
- function schedule_effect(signal) {
777
- var effect2 = last_scheduled_effect = signal;
778
- var boundary2 = effect2.b;
779
- if (boundary2?.is_pending && (signal.f & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0 && (signal.f & REACTION_RAN) === 0) {
780
- boundary2.defer_effect(signal);
781
- return;
782
- }
783
- while (effect2.parent !== null) {
784
- effect2 = effect2.parent;
785
- var flags2 = effect2.f;
786
- if (is_flushing && effect2 === active_effect && (flags2 & BLOCK_EFFECT) !== 0 && (flags2 & HEAD_EFFECT) === 0 && (flags2 & REACTION_RAN) !== 0) {
787
- return;
788
- }
789
- if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
790
- if ((flags2 & CLEAN) === 0) {
791
- return;
792
- }
793
- effect2.f ^= CLEAN;
794
- }
795
- }
796
- queued_root_effects.push(effect2);
961
+ function schedule_effect(effect2) {
962
+ current_batch.schedule(effect2);
797
963
  }
798
964
  function reset_branch(effect2, tracked) {
799
965
  if ((effect2.f & BRANCH_EFFECT) !== 0 && (effect2.f & CLEAN) !== 0) {
@@ -811,6 +977,14 @@ function reset_branch(effect2, tracked) {
811
977
  e = e.next;
812
978
  }
813
979
  }
980
+ function reset_all(effect2) {
981
+ set_signal_status(effect2, CLEAN);
982
+ var e = effect2.first;
983
+ while (e !== null) {
984
+ reset_all(e);
985
+ e = e.next;
986
+ }
987
+ }
814
988
  function createSubscriber(start) {
815
989
  let subscribers = 0;
816
990
  let version = source(0);
@@ -949,7 +1123,6 @@ class Boundary {
949
1123
  var anchor = create_text();
950
1124
  fragment.append(anchor);
951
1125
  this.#main_effect = this.#run(() => {
952
- Batch.ensure();
953
1126
  return branch(() => this.#children(anchor));
954
1127
  });
955
1128
  if (this.#pending_count === 0) {
@@ -962,7 +1135,10 @@ class Boundary {
962
1135
  this.#pending_effect = null;
963
1136
  }
964
1137
  );
965
- this.#resolve();
1138
+ this.#resolve(
1139
+ /** @type {Batch} */
1140
+ current_batch
1141
+ );
966
1142
  }
967
1143
  });
968
1144
  }
@@ -983,24 +1159,21 @@ class Boundary {
983
1159
  );
984
1160
  this.#pending_effect = branch(() => pending(this.#anchor));
985
1161
  } else {
986
- this.#resolve();
1162
+ this.#resolve(
1163
+ /** @type {Batch} */
1164
+ current_batch
1165
+ );
987
1166
  }
988
1167
  } catch (error) {
989
1168
  this.error(error);
990
1169
  }
991
1170
  }
992
- #resolve() {
1171
+ /**
1172
+ * @param {Batch} batch
1173
+ */
1174
+ #resolve(batch) {
993
1175
  this.is_pending = false;
994
- for (const e of this.#dirty_effects) {
995
- set_signal_status(e, DIRTY);
996
- schedule_effect(e);
997
- }
998
- for (const e of this.#maybe_dirty_effects) {
999
- set_signal_status(e, MAYBE_DIRTY);
1000
- schedule_effect(e);
1001
- }
1002
- this.#dirty_effects.clear();
1003
- this.#maybe_dirty_effects.clear();
1176
+ batch.transfer_effects(this.#dirty_effects, this.#maybe_dirty_effects);
1004
1177
  }
1005
1178
  /**
1006
1179
  * Defer an effect inside a pending boundary until the boundary resolves
@@ -1031,6 +1204,7 @@ class Boundary {
1031
1204
  set_active_reaction(this.#effect);
1032
1205
  set_component_context(this.#effect.ctx);
1033
1206
  try {
1207
+ Batch.ensure();
1034
1208
  return fn();
1035
1209
  } catch (e) {
1036
1210
  handle_error(e);
@@ -1045,17 +1219,18 @@ class Boundary {
1045
1219
  * Updates the pending count associated with the currently visible pending snippet,
1046
1220
  * if any, such that we can replace the snippet with content once work is done
1047
1221
  * @param {1 | -1} d
1222
+ * @param {Batch} batch
1048
1223
  */
1049
- #update_pending_count(d) {
1224
+ #update_pending_count(d, batch) {
1050
1225
  if (!this.has_pending_snippet()) {
1051
1226
  if (this.parent) {
1052
- this.parent.#update_pending_count(d);
1227
+ this.parent.#update_pending_count(d, batch);
1053
1228
  }
1054
1229
  return;
1055
1230
  }
1056
1231
  this.#pending_count += d;
1057
1232
  if (this.#pending_count === 0) {
1058
- this.#resolve();
1233
+ this.#resolve(batch);
1059
1234
  if (this.#pending_effect) {
1060
1235
  pause_effect(this.#pending_effect, () => {
1061
1236
  this.#pending_effect = null;
@@ -1072,9 +1247,10 @@ class Boundary {
1072
1247
  * and controls when the current `pending` snippet (if any) is removed.
1073
1248
  * Do not call from inside the class
1074
1249
  * @param {1 | -1} d
1250
+ * @param {Batch} batch
1075
1251
  */
1076
- update_pending_count(d) {
1077
- this.#update_pending_count(d);
1252
+ update_pending_count(d, batch) {
1253
+ this.#update_pending_count(d, batch);
1078
1254
  this.#local_pending_count += d;
1079
1255
  if (!this.#effect_pending || this.#pending_count_update_queued) return;
1080
1256
  this.#pending_count_update_queued = true;
@@ -1094,11 +1270,24 @@ class Boundary {
1094
1270
  }
1095
1271
  /** @param {unknown} error */
1096
1272
  error(error) {
1097
- var onerror = this.#props.onerror;
1098
- let failed = this.#props.failed;
1099
- if (!onerror && !failed) {
1273
+ if (!this.#props.onerror && !this.#props.failed) {
1100
1274
  throw error;
1101
1275
  }
1276
+ if (current_batch?.is_fork) {
1277
+ if (this.#main_effect) current_batch.skip_effect(this.#main_effect);
1278
+ if (this.#pending_effect) current_batch.skip_effect(this.#pending_effect);
1279
+ if (this.#failed_effect) current_batch.skip_effect(this.#failed_effect);
1280
+ current_batch.on_fork_commit(() => {
1281
+ this.#handle_error(error);
1282
+ });
1283
+ } else {
1284
+ this.#handle_error(error);
1285
+ }
1286
+ }
1287
+ /**
1288
+ * @param {unknown} error
1289
+ */
1290
+ #handle_error(error) {
1102
1291
  if (this.#main_effect) {
1103
1292
  destroy_effect(this.#main_effect);
1104
1293
  this.#main_effect = null;
@@ -1111,6 +1300,8 @@ class Boundary {
1111
1300
  destroy_effect(this.#failed_effect);
1112
1301
  this.#failed_effect = null;
1113
1302
  }
1303
+ var onerror = this.#props.onerror;
1304
+ let failed = this.#props.failed;
1114
1305
  var did_reset = false;
1115
1306
  var calling_on_error = false;
1116
1307
  const reset = () => {
@@ -1128,7 +1319,6 @@ class Boundary {
1128
1319
  });
1129
1320
  }
1130
1321
  this.#run(() => {
1131
- Batch.ensure();
1132
1322
  this.#render();
1133
1323
  });
1134
1324
  };
@@ -1142,7 +1332,6 @@ class Boundary {
1142
1332
  }
1143
1333
  if (failed) {
1144
1334
  this.#failed_effect = this.#run(() => {
1145
- Batch.ensure();
1146
1335
  try {
1147
1336
  return branch(() => {
1148
1337
  var effect2 = (
@@ -1217,26 +1406,39 @@ function flatten(blockers, sync, async, fn) {
1217
1406
  blocker_promise.then(() => finish(sync.map(d)));
1218
1407
  return;
1219
1408
  }
1409
+ var decrement_pending = increment_pending();
1220
1410
  function run() {
1221
- restore();
1222
- Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then((result) => finish([...sync.map(d), ...result])).catch((error) => invoke_error_boundary(error, parent));
1411
+ Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then((result) => finish([...sync.map(d), ...result])).catch((error) => invoke_error_boundary(error, parent)).finally(() => decrement_pending());
1223
1412
  }
1224
1413
  if (blocker_promise) {
1225
- blocker_promise.then(run);
1414
+ blocker_promise.then(() => {
1415
+ restore();
1416
+ run();
1417
+ unset_context();
1418
+ });
1226
1419
  } else {
1227
1420
  run();
1228
1421
  }
1229
1422
  }
1230
1423
  function capture() {
1231
- var previous_effect = active_effect;
1424
+ var previous_effect = (
1425
+ /** @type {Effect} */
1426
+ active_effect
1427
+ );
1232
1428
  var previous_reaction = active_reaction;
1233
1429
  var previous_component_context = component_context;
1234
- var previous_batch = current_batch;
1430
+ var previous_batch = (
1431
+ /** @type {Batch} */
1432
+ current_batch
1433
+ );
1235
1434
  return function restore(activate_batch = true) {
1236
1435
  set_active_effect(previous_effect);
1237
1436
  set_active_reaction(previous_reaction);
1238
1437
  set_component_context(previous_component_context);
1239
- if (activate_batch) previous_batch?.activate();
1438
+ if (activate_batch && (previous_effect.f & DESTROYED) === 0) {
1439
+ previous_batch?.activate();
1440
+ previous_batch?.apply();
1441
+ }
1240
1442
  };
1241
1443
  }
1242
1444
  function unset_context(deactivate_batch = true) {
@@ -1246,30 +1448,29 @@ function unset_context(deactivate_batch = true) {
1246
1448
  if (deactivate_batch) current_batch?.deactivate();
1247
1449
  }
1248
1450
  function increment_pending() {
1451
+ var effect2 = (
1452
+ /** @type {Effect} */
1453
+ active_effect
1454
+ );
1249
1455
  var boundary2 = (
1250
1456
  /** @type {Boundary} */
1251
- /** @type {Effect} */
1252
- active_effect.b
1457
+ effect2.b
1253
1458
  );
1254
1459
  var batch = (
1255
1460
  /** @type {Batch} */
1256
1461
  current_batch
1257
1462
  );
1258
1463
  var blocking = boundary2.is_rendered();
1259
- boundary2.update_pending_count(1);
1260
- batch.increment(blocking);
1261
- return () => {
1262
- boundary2.update_pending_count(-1);
1263
- batch.decrement(blocking);
1464
+ boundary2.update_pending_count(1, batch);
1465
+ batch.increment(blocking, effect2);
1466
+ return (skip = false) => {
1467
+ boundary2.update_pending_count(-1, batch);
1468
+ batch.decrement(blocking, effect2, skip);
1264
1469
  };
1265
1470
  }
1266
1471
  // @__NO_SIDE_EFFECTS__
1267
1472
  function derived(fn) {
1268
1473
  var flags2 = DERIVED | DIRTY;
1269
- var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
1270
- /** @type {Derived} */
1271
- active_reaction
1272
- ) : null;
1273
1474
  if (active_effect !== null) {
1274
1475
  active_effect.f |= EFFECT_PRESERVED;
1275
1476
  }
@@ -1287,7 +1488,7 @@ function derived(fn) {
1287
1488
  UNINITIALIZED
1288
1489
  ),
1289
1490
  wv: 0,
1290
- parent: parent_derived ?? active_effect,
1491
+ parent: active_effect,
1291
1492
  ac: null
1292
1493
  };
1293
1494
  return signal;
@@ -1313,6 +1514,10 @@ function async_derived(fn, label, location) {
1313
1514
  var should_suspend = !active_reaction;
1314
1515
  var deferreds = /* @__PURE__ */ new Map();
1315
1516
  async_effect(() => {
1517
+ var effect2 = (
1518
+ /** @type {Effect} */
1519
+ active_effect
1520
+ );
1316
1521
  var d = deferred();
1317
1522
  promise = d.promise;
1318
1523
  try {
@@ -1326,18 +1531,35 @@ function async_derived(fn, label, location) {
1326
1531
  current_batch
1327
1532
  );
1328
1533
  if (should_suspend) {
1329
- var decrement_pending = increment_pending();
1330
- deferreds.get(batch)?.reject(STALE_REACTION);
1331
- deferreds.delete(batch);
1534
+ if ((effect2.f & REACTION_RAN) !== 0) {
1535
+ var decrement_pending = increment_pending();
1536
+ }
1537
+ if (
1538
+ /** @type {Boundary} */
1539
+ parent.b.is_rendered()
1540
+ ) {
1541
+ deferreds.get(batch)?.reject(STALE_REACTION);
1542
+ deferreds.delete(batch);
1543
+ } else {
1544
+ for (const d2 of deferreds.values()) {
1545
+ d2.reject(STALE_REACTION);
1546
+ }
1547
+ deferreds.clear();
1548
+ }
1332
1549
  deferreds.set(batch, d);
1333
1550
  }
1334
1551
  const handler = (value, error = void 0) => {
1552
+ if (decrement_pending) {
1553
+ var skip = error === STALE_REACTION;
1554
+ decrement_pending(skip);
1555
+ }
1556
+ if (error === STALE_REACTION || (effect2.f & DESTROYED) !== 0) {
1557
+ return;
1558
+ }
1335
1559
  batch.activate();
1336
1560
  if (error) {
1337
- if (error !== STALE_REACTION) {
1338
- signal.f |= ERROR_VALUE;
1339
- internal_set(signal, error);
1340
- }
1561
+ signal.f |= ERROR_VALUE;
1562
+ internal_set(signal, error);
1341
1563
  } else {
1342
1564
  if ((signal.f & ERROR_VALUE) !== 0) {
1343
1565
  signal.f ^= ERROR_VALUE;
@@ -1349,9 +1571,7 @@ function async_derived(fn, label, location) {
1349
1571
  d2.reject(STALE_REACTION);
1350
1572
  }
1351
1573
  }
1352
- if (decrement_pending) {
1353
- decrement_pending();
1354
- }
1574
+ batch.deactivate();
1355
1575
  };
1356
1576
  d.promise.then(handler, (e) => handler(null, e || "unknown"));
1357
1577
  });
@@ -1398,23 +1618,15 @@ function destroy_derived_effects(derived2) {
1398
1618
  }
1399
1619
  }
1400
1620
  }
1401
- function get_derived_parent_effect(derived2) {
1402
- var parent = derived2.parent;
1403
- while (parent !== null) {
1404
- if ((parent.f & DERIVED) === 0) {
1405
- return (parent.f & DESTROYED) === 0 ? (
1406
- /** @type {Effect} */
1407
- parent
1408
- ) : null;
1409
- }
1410
- parent = parent.parent;
1411
- }
1412
- return null;
1413
- }
1414
1621
  function execute_derived(derived2) {
1415
1622
  var value;
1416
1623
  var prev_active_effect = active_effect;
1417
- set_active_effect(get_derived_parent_effect(derived2));
1624
+ var parent = derived2.parent;
1625
+ if (!is_destroying_effect && parent !== null && (parent.f & (DESTROYED | INERT)) !== 0) {
1626
+ derived_inert();
1627
+ return derived2.v;
1628
+ }
1629
+ set_active_effect(parent);
1418
1630
  {
1419
1631
  try {
1420
1632
  derived2.f &= ~WAS_MARKED;
@@ -1431,7 +1643,11 @@ function update_derived(derived2) {
1431
1643
  if (!derived2.equals(value)) {
1432
1644
  derived2.wv = increment_write_version();
1433
1645
  if (!current_batch?.is_fork || derived2.deps === null) {
1434
- derived2.v = value;
1646
+ if (current_batch !== null) {
1647
+ current_batch.capture(derived2, value, true);
1648
+ } else {
1649
+ derived2.v = value;
1650
+ }
1435
1651
  if (derived2.deps === null) {
1436
1652
  set_signal_status(derived2, CLEAN);
1437
1653
  return;
@@ -1498,19 +1714,13 @@ function set(source2, value, should_proxy = false) {
1498
1714
  state_unsafe_mutation();
1499
1715
  }
1500
1716
  let new_value = should_proxy ? proxy(value) : value;
1501
- return internal_set(source2, new_value);
1717
+ return internal_set(source2, new_value, legacy_updates);
1502
1718
  }
1503
- function internal_set(source2, value) {
1719
+ function internal_set(source2, value, updated_during_traversal = null) {
1504
1720
  if (!source2.equals(value)) {
1505
- var old_value = source2.v;
1506
- if (is_destroying_effect) {
1507
- old_values.set(source2, value);
1508
- } else {
1509
- old_values.set(source2, old_value);
1510
- }
1511
- source2.v = value;
1721
+ old_values.set(source2, is_destroying_effect ? value : source2.v);
1512
1722
  var batch = Batch.ensure();
1513
- batch.capture(source2, old_value);
1723
+ batch.capture(source2, value);
1514
1724
  if ((source2.f & DERIVED) !== 0) {
1515
1725
  const derived2 = (
1516
1726
  /** @type {Derived} */
@@ -1519,10 +1729,12 @@ function internal_set(source2, value) {
1519
1729
  if ((source2.f & DIRTY) !== 0) {
1520
1730
  execute_derived(derived2);
1521
1731
  }
1522
- update_derived_status(derived2);
1732
+ if (batch_values === null) {
1733
+ update_derived_status(derived2);
1734
+ }
1523
1735
  }
1524
1736
  source2.wv = increment_write_version();
1525
- mark_reactions(source2, DIRTY);
1737
+ mark_reactions(source2, DIRTY, updated_during_traversal);
1526
1738
  if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
1527
1739
  if (untracked_writes === null) {
1528
1740
  set_untracked_writes([source2]);
@@ -1551,7 +1763,7 @@ function flush_eager_effects() {
1551
1763
  function increment(source2) {
1552
1764
  set(source2, source2.v + 1);
1553
1765
  }
1554
- function mark_reactions(signal, status) {
1766
+ function mark_reactions(signal, status, updated_during_traversal) {
1555
1767
  var reactions = signal.reactions;
1556
1768
  if (reactions === null) return;
1557
1769
  var runes = is_runes();
@@ -1571,22 +1783,24 @@ function mark_reactions(signal, status) {
1571
1783
  );
1572
1784
  batch_values?.delete(derived2);
1573
1785
  if ((flags2 & WAS_MARKED) === 0) {
1574
- if (flags2 & CONNECTED) {
1786
+ if (flags2 & CONNECTED && (active_effect === null || (active_effect.f & REACTION_IS_UPDATING) === 0)) {
1575
1787
  reaction.f |= WAS_MARKED;
1576
1788
  }
1577
- mark_reactions(derived2, MAYBE_DIRTY);
1789
+ mark_reactions(derived2, MAYBE_DIRTY, updated_during_traversal);
1578
1790
  }
1579
1791
  } else if (not_dirty) {
1580
- if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1581
- eager_block_effects.add(
1582
- /** @type {Effect} */
1583
- reaction
1584
- );
1585
- }
1586
- schedule_effect(
1792
+ var effect2 = (
1587
1793
  /** @type {Effect} */
1588
1794
  reaction
1589
1795
  );
1796
+ if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1797
+ eager_block_effects.add(effect2);
1798
+ }
1799
+ if (updated_during_traversal !== null) {
1800
+ updated_during_traversal.push(effect2);
1801
+ } else {
1802
+ schedule_effect(effect2);
1803
+ }
1590
1804
  }
1591
1805
  }
1592
1806
  }
@@ -1911,7 +2125,7 @@ function push_effect(effect2, parent_effect) {
1911
2125
  parent_effect.last = effect2;
1912
2126
  }
1913
2127
  }
1914
- function create_effect(type, fn, sync) {
2128
+ function create_effect(type, fn) {
1915
2129
  var parent = active_effect;
1916
2130
  if (parent !== null && (parent.f & INERT) !== 0) {
1917
2131
  type |= INERT;
@@ -1932,22 +2146,27 @@ function create_effect(type, fn, sync) {
1932
2146
  wv: 0,
1933
2147
  ac: null
1934
2148
  };
1935
- if (sync) {
2149
+ current_batch?.register_created_effect(effect2);
2150
+ var e = effect2;
2151
+ if ((type & EFFECT) !== 0) {
2152
+ if (collected_effects !== null) {
2153
+ collected_effects.push(effect2);
2154
+ } else {
2155
+ Batch.ensure().schedule(effect2);
2156
+ }
2157
+ } else if (fn !== null) {
1936
2158
  try {
1937
2159
  update_effect(effect2);
1938
2160
  } catch (e2) {
1939
2161
  destroy_effect(effect2);
1940
2162
  throw e2;
1941
2163
  }
1942
- } else if (fn !== null) {
1943
- schedule_effect(effect2);
1944
- }
1945
- var e = effect2;
1946
- if (sync && e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
1947
- (e.f & EFFECT_PRESERVED) === 0) {
1948
- e = e.first;
1949
- if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
1950
- e.f |= EFFECT_TRANSPARENT;
2164
+ if (e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
2165
+ (e.f & EFFECT_PRESERVED) === 0) {
2166
+ e = e.first;
2167
+ if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
2168
+ e.f |= EFFECT_TRANSPARENT;
2169
+ }
1951
2170
  }
1952
2171
  }
1953
2172
  if (e !== null) {
@@ -1969,7 +2188,7 @@ function effect_tracking() {
1969
2188
  return active_reaction !== null && !untracking;
1970
2189
  }
1971
2190
  function teardown(fn) {
1972
- const effect2 = create_effect(RENDER_EFFECT, null, false);
2191
+ const effect2 = create_effect(RENDER_EFFECT, null);
1973
2192
  set_signal_status(effect2, CLEAN);
1974
2193
  effect2.teardown = fn;
1975
2194
  return effect2;
@@ -1992,15 +2211,15 @@ function user_effect(fn) {
1992
2211
  }
1993
2212
  }
1994
2213
  function create_user_effect(fn) {
1995
- return create_effect(EFFECT | USER_EFFECT, fn, false);
2214
+ return create_effect(EFFECT | USER_EFFECT, fn);
1996
2215
  }
1997
2216
  function user_pre_effect(fn) {
1998
2217
  validate_effect();
1999
- return create_effect(RENDER_EFFECT | USER_EFFECT, fn, true);
2218
+ return create_effect(RENDER_EFFECT | USER_EFFECT, fn);
2000
2219
  }
2001
2220
  function component_root(fn) {
2002
2221
  Batch.ensure();
2003
- const effect2 = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn, true);
2222
+ const effect2 = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn);
2004
2223
  return (options = {}) => {
2005
2224
  return new Promise((fulfil) => {
2006
2225
  if (options.outro) {
@@ -2016,29 +2235,29 @@ function component_root(fn) {
2016
2235
  };
2017
2236
  }
2018
2237
  function effect(fn) {
2019
- return create_effect(EFFECT, fn, false);
2238
+ return create_effect(EFFECT, fn);
2020
2239
  }
2021
2240
  function async_effect(fn) {
2022
- return create_effect(ASYNC | EFFECT_PRESERVED, fn, true);
2241
+ return create_effect(ASYNC | EFFECT_PRESERVED, fn);
2023
2242
  }
2024
2243
  function render_effect(fn, flags2 = 0) {
2025
- return create_effect(RENDER_EFFECT | flags2, fn, true);
2244
+ return create_effect(RENDER_EFFECT | flags2, fn);
2026
2245
  }
2027
2246
  function template_effect(fn, sync = [], async = [], blockers = []) {
2028
2247
  flatten(blockers, sync, async, (values) => {
2029
- create_effect(RENDER_EFFECT, () => fn(...values.map(get)), true);
2248
+ create_effect(RENDER_EFFECT, () => fn(...values.map(get)));
2030
2249
  });
2031
2250
  }
2032
2251
  function block(fn, flags2 = 0) {
2033
- var effect2 = create_effect(BLOCK_EFFECT | flags2, fn, true);
2252
+ var effect2 = create_effect(BLOCK_EFFECT | flags2, fn);
2034
2253
  return effect2;
2035
2254
  }
2036
2255
  function managed(fn, flags2 = 0) {
2037
- var effect2 = create_effect(MANAGED_EFFECT | flags2, fn, true);
2256
+ var effect2 = create_effect(MANAGED_EFFECT | flags2, fn);
2038
2257
  return effect2;
2039
2258
  }
2040
2259
  function branch(fn) {
2041
- return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true);
2260
+ return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn);
2042
2261
  }
2043
2262
  function execute_effect_teardown(effect2) {
2044
2263
  var teardown2 = effect2.teardown;
@@ -2094,9 +2313,9 @@ function destroy_effect(effect2, remove_dom = true) {
2094
2313
  );
2095
2314
  removed = true;
2096
2315
  }
2316
+ set_signal_status(effect2, DESTROYING);
2097
2317
  destroy_effect_children(effect2, remove_dom && !removed);
2098
2318
  remove_reactions(effect2, 0);
2099
- set_signal_status(effect2, DESTROYED);
2100
2319
  var transitions = effect2.nodes && effect2.nodes.t;
2101
2320
  if (transitions !== null) {
2102
2321
  for (const transition of transitions) {
@@ -2104,11 +2323,13 @@ function destroy_effect(effect2, remove_dom = true) {
2104
2323
  }
2105
2324
  }
2106
2325
  execute_effect_teardown(effect2);
2326
+ effect2.f ^= DESTROYING;
2327
+ effect2.f |= DESTROYED;
2107
2328
  var parent = effect2.parent;
2108
2329
  if (parent !== null && parent.first !== null) {
2109
2330
  unlink_effect(effect2);
2110
2331
  }
2111
- effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes = effect2.ac = null;
2332
+ effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes = effect2.ac = effect2.b = null;
2112
2333
  }
2113
2334
  function remove_effect_dom(node, end) {
2114
2335
  while (node !== null) {
@@ -2159,11 +2380,13 @@ function pause_children(effect2, transitions, local) {
2159
2380
  var child2 = effect2.first;
2160
2381
  while (child2 !== null) {
2161
2382
  var sibling2 = child2.next;
2162
- var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
2163
- // it means the parent block effect was pruned. In that case,
2164
- // transparency information was transferred to the branch effect.
2165
- (child2.f & BRANCH_EFFECT) !== 0 && (effect2.f & BLOCK_EFFECT) !== 0;
2166
- pause_children(child2, transitions, transparent ? local : false);
2383
+ if ((child2.f & ROOT_EFFECT) === 0) {
2384
+ var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
2385
+ // it means the parent block effect was pruned. In that case,
2386
+ // transparency information was transferred to the branch effect.
2387
+ (child2.f & BRANCH_EFFECT) !== 0 && (effect2.f & BLOCK_EFFECT) !== 0;
2388
+ pause_children(child2, transitions, transparent ? local : false);
2389
+ }
2167
2390
  child2 = sibling2;
2168
2391
  }
2169
2392
  }
@@ -2175,7 +2398,7 @@ function resume_children(effect2, local) {
2175
2398
  effect2.f ^= INERT;
2176
2399
  if ((effect2.f & CLEAN) === 0) {
2177
2400
  set_signal_status(effect2, DIRTY);
2178
- schedule_effect(effect2);
2401
+ Batch.ensure().schedule(effect2);
2179
2402
  }
2180
2403
  var child2 = effect2.first;
2181
2404
  while (child2 !== null) {
@@ -2439,7 +2662,9 @@ function remove_reaction(signal, dependency) {
2439
2662
  derived2.f ^= CONNECTED;
2440
2663
  derived2.f &= ~WAS_MARKED;
2441
2664
  }
2442
- update_derived_status(derived2);
2665
+ if (derived2.v !== UNINITIALIZED) {
2666
+ update_derived_status(derived2);
2667
+ }
2443
2668
  freeze_derived_effects(derived2);
2444
2669
  remove_reactions(derived2, 0);
2445
2670
  }
@@ -3056,11 +3281,10 @@ class BranchManager {
3056
3281
  this.anchor = anchor;
3057
3282
  this.#transition = transition;
3058
3283
  }
3059
- #commit = () => {
3060
- var batch = (
3061
- /** @type {Batch} */
3062
- current_batch
3063
- );
3284
+ /**
3285
+ * @param {Batch} batch
3286
+ */
3287
+ #commit = (batch) => {
3064
3288
  if (!this.#batches.has(batch)) return;
3065
3289
  var key = (
3066
3290
  /** @type {Key} */
@@ -3173,7 +3397,7 @@ class BranchManager {
3173
3397
  batch.oncommit(this.#commit);
3174
3398
  batch.ondiscard(this.#discard);
3175
3399
  } else {
3176
- this.#commit();
3400
+ this.#commit(batch);
3177
3401
  }
3178
3402
  }
3179
3403
  }
@@ -3226,7 +3450,7 @@ function if_block(node, fn, elseif = false) {
3226
3450
  update_branch(key, fn2);
3227
3451
  });
3228
3452
  if (!has_branch) {
3229
- update_branch(false, null);
3453
+ update_branch(-1, null);
3230
3454
  }
3231
3455
  }, flags2);
3232
3456
  }
@@ -3735,6 +3959,14 @@ function is_bound_this(bound_value, element_or_component) {
3735
3959
  return bound_value === element_or_component || bound_value?.[STATE_SYMBOL] === element_or_component;
3736
3960
  }
3737
3961
  function bind_this(element_or_component = {}, update, get_value, get_parts) {
3962
+ var component_effect = (
3963
+ /** @type {ComponentContext} */
3964
+ component_context.r
3965
+ );
3966
+ var parent = (
3967
+ /** @type {Effect} */
3968
+ active_effect
3969
+ );
3738
3970
  effect(() => {
3739
3971
  var old_parts;
3740
3972
  var parts;
@@ -3751,25 +3983,24 @@ function bind_this(element_or_component = {}, update, get_value, get_parts) {
3751
3983
  });
3752
3984
  });
3753
3985
  return () => {
3754
- queue_micro_task(() => {
3986
+ let p = parent;
3987
+ while (p !== component_effect && p.parent !== null && p.parent.f & DESTROYING) {
3988
+ p = p.parent;
3989
+ }
3990
+ const teardown2 = () => {
3755
3991
  if (parts && is_bound_this(get_value(...parts), element_or_component)) {
3756
3992
  update(null, ...parts);
3757
3993
  }
3758
- });
3994
+ };
3995
+ const original_teardown = p.teardown;
3996
+ p.teardown = () => {
3997
+ teardown2();
3998
+ original_teardown?.();
3999
+ };
3759
4000
  };
3760
4001
  });
3761
4002
  return element_or_component;
3762
4003
  }
3763
- let is_store_binding = false;
3764
- function capture_store_binding(fn) {
3765
- var previous_is_store_binding = is_store_binding;
3766
- try {
3767
- is_store_binding = false;
3768
- return [fn(), is_store_binding];
3769
- } finally {
3770
- is_store_binding = previous_is_store_binding;
3771
- }
3772
- }
3773
4004
  const rest_props_handler = {
3774
4005
  get(target, key) {
3775
4006
  if (target.exclude.includes(key)) return;
@@ -3887,7 +4118,7 @@ function prop(props, key, flags2, fallback) {
3887
4118
  }
3888
4119
  return fallback_value;
3889
4120
  };
3890
- var setter;
4121
+ let setter;
3891
4122
  if (bindable) {
3892
4123
  var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
3893
4124
  setter = get_descriptor(props, key)?.set ?? (is_entry_props && key in props ? (v) => props[key] = v : void 0);
@@ -3982,7 +4213,6 @@ function prop(props, key, flags2, fallback) {
3982
4213
  );
3983
4214
  }
3984
4215
  var ScenaEvent = /* @__PURE__ */ ((ScenaEvent2) => {
3985
- ScenaEvent2["ON_SCENA_MOUNT"] = "scena:on-mount";
3986
4216
  ScenaEvent2["ON_SCENA_DESTROY"] = "scena:on-destroy";
3987
4217
  ScenaEvent2["ON_VIDEO_READY"] = "video:on-ready";
3988
4218
  ScenaEvent2["ON_VIDEO_PLAY"] = "video:on-play";
@@ -4138,6 +4368,9 @@ const formatComponentStyles = (styles) => {
4138
4368
  }
4139
4369
  return Object.entries(styles).map(([property, value]) => `${formatComponentStyleProperty(property)}: ${value}`).join("; ") + ";";
4140
4370
  };
4371
+ const resolveElements = (instance) => {
4372
+ return instance?.getElements() ?? null;
4373
+ };
4141
4374
  const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
4142
4375
  const isPlainObject = (value) => {
4143
4376
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -4192,7 +4425,7 @@ var root$g = /* @__PURE__ */ from_html(`<div><!></div>`);
4192
4425
  function ScenaContainer($$anchor, $$props) {
4193
4426
  push($$props, true);
4194
4427
  let position = prop($$props, "position", 19, () => ComponentPosition.FIXED), placement = prop($$props, "placement", 19, () => ComponentPlacement.BOTTOM_END);
4195
- let rootElement;
4428
+ let rootElement = /* @__PURE__ */ state(null);
4196
4429
  const customPlacements = [ComponentPosition.ABSOLUTE, ComponentPosition.FIXED];
4197
4430
  const isCustomPlacement = /* @__PURE__ */ user_derived(() => customPlacements.includes(position()));
4198
4431
  const rootClasses = /* @__PURE__ */ user_derived(() => [
@@ -4203,7 +4436,7 @@ function ScenaContainer($$anchor, $$props) {
4203
4436
  ]);
4204
4437
  const rootStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.root));
4205
4438
  function getElements() {
4206
- return { root: rootElement };
4439
+ return { root: get(rootElement) };
4207
4440
  }
4208
4441
  var $$exports = { getElements };
4209
4442
  var div = root$g();
@@ -4219,7 +4452,7 @@ function ScenaContainer($$anchor, $$props) {
4219
4452
  if ($$props.children) $$render(consequent);
4220
4453
  });
4221
4454
  }
4222
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
4455
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
4223
4456
  template_effect(() => {
4224
4457
  set_attribute(div, "id", $$props.id);
4225
4458
  set_class(div, 1, clsx(get(rootClasses)));
@@ -4308,10 +4541,10 @@ function ScenaButton($$anchor, $$props) {
4308
4541
  $$props.autosize ? "rs-button--autosize" : `rs-button--${size()}`,
4309
4542
  $$props.customClasses?.root
4310
4543
  ]);
4311
- let rootElement;
4544
+ let rootElement = /* @__PURE__ */ state(null);
4312
4545
  const rootStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.root));
4313
4546
  function getElements() {
4314
- return { root: rootElement };
4547
+ return { root: get(rootElement) };
4315
4548
  }
4316
4549
  var $$exports = { getElements };
4317
4550
  var button = root$a();
@@ -4342,7 +4575,7 @@ function ScenaButton($$anchor, $$props) {
4342
4575
  if ($$props.children) $$render(consequent);
4343
4576
  });
4344
4577
  }
4345
- bind_this(button, ($$value) => rootElement = $$value, () => rootElement);
4578
+ bind_this(button, ($$value) => set(rootElement, $$value), () => get(rootElement));
4346
4579
  append($$anchor, button);
4347
4580
  return pop($$exports);
4348
4581
  }
@@ -4350,17 +4583,17 @@ var root$9 = /* @__PURE__ */ from_svg(`<svg fill="none" focusable="false" aria-h
4350
4583
  function ScenaIcon($$anchor, $$props) {
4351
4584
  push($$props, true);
4352
4585
  let viewBox = prop($$props, "viewBox", 3, "0 0 16 16"), size = prop($$props, "size", 19, () => ComponentSize.MD);
4353
- let rootElement;
4586
+ let rootElement = /* @__PURE__ */ state(null);
4354
4587
  const rootClasses = /* @__PURE__ */ user_derived(() => ["rs-icon", `rs-icon--${size()}`, $$props.customClasses?.root]);
4355
4588
  const rootStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.root));
4356
4589
  function getElements() {
4357
- return { root: rootElement };
4590
+ return { root: get(rootElement) };
4358
4591
  }
4359
4592
  var $$exports = { getElements };
4360
4593
  var svg = root$9();
4361
4594
  var node = child(svg);
4362
4595
  snippet(node, () => $$props.children ?? noop);
4363
- bind_this(svg, ($$value) => rootElement = $$value, () => rootElement);
4596
+ bind_this(svg, ($$value) => set(rootElement, $$value), () => get(rootElement));
4364
4597
  template_effect(() => {
4365
4598
  set_attribute(svg, "id", $$props.id);
4366
4599
  set_class(svg, 0, clsx(get(rootClasses)));
@@ -4375,9 +4608,9 @@ function ScenaCloseButton($$anchor, $$props) {
4375
4608
  push($$props, true);
4376
4609
  let size = prop($$props, "size", 19, () => ComponentSize.MD), shape = prop($$props, "shape", 19, () => ComponentShape.CIRCLE), aria = prop($$props, "aria", 19, () => ({ ariaLabel: "Close" }));
4377
4610
  const { eventEmitter, unmount: unmount2 } = getScenaContext();
4378
- let rootElement;
4379
- let buttonElement;
4380
- let crossElement;
4611
+ let rootElement = /* @__PURE__ */ state(null);
4612
+ let buttonElement = /* @__PURE__ */ state(null);
4613
+ let crossElement = /* @__PURE__ */ state(null);
4381
4614
  const rootClasses = /* @__PURE__ */ user_derived(() => [
4382
4615
  "rs-close-button",
4383
4616
  `rs-close-button--${size()}`,
@@ -4395,9 +4628,9 @@ function ScenaCloseButton($$anchor, $$props) {
4395
4628
  }
4396
4629
  function getElements() {
4397
4630
  return {
4398
- root: rootElement,
4399
- button: buttonElement?.getElements(),
4400
- cross: crossElement?.getElements()
4631
+ root: get(rootElement),
4632
+ button: resolveElements(get(buttonElement)),
4633
+ cross: resolveElements(get(crossElement))
4401
4634
  };
4402
4635
  }
4403
4636
  var $$exports = { getElements };
@@ -4445,18 +4678,18 @@ function ScenaCloseButton($$anchor, $$props) {
4445
4678
  },
4446
4679
  $$slots: { default: true }
4447
4680
  }),
4448
- ($$value) => crossElement = $$value,
4449
- () => crossElement
4681
+ ($$value) => set(crossElement, $$value, true),
4682
+ () => get(crossElement)
4450
4683
  );
4451
4684
  }
4452
4685
  },
4453
4686
  $$slots: { default: true }
4454
4687
  }),
4455
- ($$value) => buttonElement = $$value,
4456
- () => buttonElement
4688
+ ($$value) => set(buttonElement, $$value, true),
4689
+ () => get(buttonElement)
4457
4690
  );
4458
4691
  }
4459
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
4692
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
4460
4693
  template_effect(() => {
4461
4694
  set_attribute(div, "id", $$props.id);
4462
4695
  set_class(div, 1, clsx(get(rootClasses)));
@@ -4479,8 +4712,8 @@ function ScenaCtaButton($$anchor, $$props) {
4479
4712
  }));
4480
4713
  const { eventEmitter } = getScenaContext();
4481
4714
  const currentPlacement = /* @__PURE__ */ user_derived(() => adaptive() && adaptive().sizes.includes(size()) ? adaptive().placement : placement());
4482
- let rootElement;
4483
- let buttonElement;
4715
+ let rootElement = /* @__PURE__ */ state(null);
4716
+ let buttonElement = /* @__PURE__ */ state(null);
4484
4717
  const rootClasses = /* @__PURE__ */ user_derived(() => [
4485
4718
  "rs-cta-button",
4486
4719
  `rs-cta-button--${get(currentPlacement)}`,
@@ -4494,7 +4727,10 @@ function ScenaCtaButton($$anchor, $$props) {
4494
4727
  }
4495
4728
  }
4496
4729
  function getElements() {
4497
- return { root: rootElement, button: buttonElement?.getElements() };
4730
+ return {
4731
+ root: get(rootElement),
4732
+ button: resolveElements(get(buttonElement))
4733
+ };
4498
4734
  }
4499
4735
  var $$exports = { getElements };
4500
4736
  var div = root$7();
@@ -4527,11 +4763,11 @@ function ScenaCtaButton($$anchor, $$props) {
4527
4763
  },
4528
4764
  $$slots: { default: true }
4529
4765
  }),
4530
- ($$value) => buttonElement = $$value,
4531
- () => buttonElement
4766
+ ($$value) => set(buttonElement, $$value, true),
4767
+ () => get(buttonElement)
4532
4768
  );
4533
4769
  }
4534
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
4770
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
4535
4771
  template_effect(() => {
4536
4772
  set_attribute(div, "id", $$props.id);
4537
4773
  set_class(div, 1, clsx(get(rootClasses)));
@@ -4829,7 +5065,7 @@ function ScenaVideo($$anchor, $$props) {
4829
5065
  push($$props, true);
4830
5066
  let preload = prop($$props, "preload", 19, () => ScenaVideoPreload.METADATA), crossorigin = prop($$props, "crossorigin", 19, () => ScenaVideoCrossOrigin.ANONYMOUS), autoplay = prop($$props, "autoplay", 3, true), playsinline = prop($$props, "playsinline", 3, true), loop = prop($$props, "loop", 3, true), muted = prop($$props, "muted", 3, true), controls = prop($$props, "controls", 3, false), volume = prop($$props, "volume", 3, 1), startTime = prop($$props, "startTime", 3, 0);
4831
5067
  const { eventEmitter } = getScenaContext();
4832
- let rootElement;
5068
+ let rootElement = /* @__PURE__ */ state(null);
4833
5069
  let mediaElement;
4834
5070
  const controller = useVideoController({ getVideoElement: () => mediaElement, eventEmitter });
4835
5071
  setScenaVideoContext(controller);
@@ -4845,7 +5081,7 @@ function ScenaVideo($$anchor, $$props) {
4845
5081
  }
4846
5082
  });
4847
5083
  function getElements() {
4848
- return { root: rootElement, video: mediaElement };
5084
+ return { root: get(rootElement), video: mediaElement };
4849
5085
  }
4850
5086
  var $$exports = { controller, getElements };
4851
5087
  var div = root$6();
@@ -4864,7 +5100,7 @@ function ScenaVideo($$anchor, $$props) {
4864
5100
  if ($$props.children) $$render(consequent);
4865
5101
  });
4866
5102
  }
4867
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
5103
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
4868
5104
  template_effect(() => {
4869
5105
  set_attribute(div, "id", $$props.id);
4870
5106
  set_class(div, 1, clsx(get(rootClasses)));
@@ -4933,7 +5169,7 @@ function ScenaVideoContainer($$anchor, $$props) {
4933
5169
  push($$props, true);
4934
5170
  let size = prop($$props, "size", 19, () => ComponentSize.MD), shape = prop($$props, "shape", 19, () => ComponentShape.CIRCLE);
4935
5171
  const { eventEmitter } = getScenaContext();
4936
- let rootElement;
5172
+ let rootElement = /* @__PURE__ */ state(null);
4937
5173
  const rootClasses = /* @__PURE__ */ user_derived(() => [
4938
5174
  "rs-video-container",
4939
5175
  `rs-video-container--${size()}`,
@@ -4951,7 +5187,7 @@ function ScenaVideoContainer($$anchor, $$props) {
4951
5187
  }
4952
5188
  }
4953
5189
  function getElements() {
4954
- return { root: rootElement };
5190
+ return { root: get(rootElement) };
4955
5191
  }
4956
5192
  var $$exports = { getElements };
4957
5193
  var div = root$5();
@@ -4967,7 +5203,7 @@ function ScenaVideoContainer($$anchor, $$props) {
4967
5203
  if ($$props.children) $$render(consequent);
4968
5204
  });
4969
5205
  }
4970
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
5206
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
4971
5207
  template_effect(() => {
4972
5208
  set_attribute(div, "id", $$props.id);
4973
5209
  set_class(div, 1, clsx(get(rootClasses)));
@@ -5006,10 +5242,10 @@ function ScenaVideoControls($$anchor, $$props) {
5006
5242
  function getElements() {
5007
5243
  return {
5008
5244
  root: get(rootElement),
5009
- pauseButton: get(pauseButtonElement)?.getElements(),
5010
- pauseIcon: get(pauseIconElement)?.getElements(),
5011
- playButton: get(playButtonElement)?.getElements(),
5012
- playIcon: get(playIconElement)?.getElements()
5245
+ pauseButton: resolveElements(get(pauseButtonElement)),
5246
+ pauseIcon: resolveElements(get(pauseIconElement)),
5247
+ playButton: resolveElements(get(playButtonElement)),
5248
+ playIcon: resolveElements(get(playIconElement))
5013
5249
  };
5014
5250
  }
5015
5251
  var $$exports = { getElements };
@@ -5160,7 +5396,7 @@ var root$4 = /* @__PURE__ */ from_svg(`<svg viewBox="0 0 24 24" xmlns="http://ww
5160
5396
  function ScenaLoader($$anchor, $$props) {
5161
5397
  push($$props, true);
5162
5398
  let size = prop($$props, "size", 19, () => ComponentSize.MD);
5163
- let rootElement;
5399
+ let rootElement = /* @__PURE__ */ state(null);
5164
5400
  const rootClasses = /* @__PURE__ */ user_derived(() => [
5165
5401
  "rs-loader",
5166
5402
  `rs-loader--${size()}`,
@@ -5168,11 +5404,11 @@ function ScenaLoader($$anchor, $$props) {
5168
5404
  ]);
5169
5405
  const rootStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.root));
5170
5406
  function getElements() {
5171
- return { root: rootElement };
5407
+ return { root: get(rootElement) };
5172
5408
  }
5173
5409
  var $$exports = { getElements };
5174
5410
  var svg = root$4();
5175
- bind_this(svg, ($$value) => rootElement = $$value, () => rootElement);
5411
+ bind_this(svg, ($$value) => set(rootElement, $$value), () => get(rootElement));
5176
5412
  template_effect(() => {
5177
5413
  set_attribute(svg, "id", $$props.id);
5178
5414
  set_class(svg, 0, clsx(get(rootClasses)));
@@ -5186,14 +5422,14 @@ function ScenaVideoLoader($$anchor, $$props) {
5186
5422
  push($$props, true);
5187
5423
  let size = prop($$props, "size", 19, () => ComponentSize.MD);
5188
5424
  const scenaVideoContext = getScenaVideoContext();
5189
- let rootElement;
5425
+ let rootElement = /* @__PURE__ */ state(null);
5190
5426
  let loaderElement = /* @__PURE__ */ state(null);
5191
5427
  const rootClasses = /* @__PURE__ */ user_derived(() => ["rs-video-loader", $$props.customClasses?.root]);
5192
5428
  const rootStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.root));
5193
5429
  function getElements() {
5194
5430
  return {
5195
- root: rootElement,
5196
- loader: get(loaderElement)?.getElements()
5431
+ root: get(rootElement),
5432
+ loader: resolveElements(get(loaderElement))
5197
5433
  };
5198
5434
  }
5199
5435
  var $$exports = { getElements };
@@ -5225,7 +5461,7 @@ function ScenaVideoLoader($$anchor, $$props) {
5225
5461
  if (scenaVideoContext.state === ScenaVideoState.LOADING) $$render(consequent);
5226
5462
  });
5227
5463
  }
5228
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
5464
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
5229
5465
  template_effect(() => {
5230
5466
  set_attribute(div, "id", $$props.id);
5231
5467
  set_class(div, 1, clsx(get(rootClasses)));
@@ -5538,7 +5774,7 @@ var root$2 = /* @__PURE__ */ from_svg(`<svg role="slider" xmlns="http://www.w3.o
5538
5774
  function ScenaProgressCircle($$anchor, $$props) {
5539
5775
  push($$props, true);
5540
5776
  let size = prop($$props, "size", 19, () => ComponentSize.MD), buffer = prop($$props, "buffer", 3, 0), progress = prop($$props, "progress", 3, 0), aria = prop($$props, "aria", 19, () => ({ ariaLabel: "Progress" }));
5541
- let rootElement;
5777
+ let rootElement = /* @__PURE__ */ state(null);
5542
5778
  let trackElement = /* @__PURE__ */ state(null);
5543
5779
  let bufferElement = /* @__PURE__ */ state(null);
5544
5780
  let progressElement = /* @__PURE__ */ state(null);
@@ -5555,7 +5791,7 @@ function ScenaProgressCircle($$anchor, $$props) {
5555
5791
  const progressClasses = /* @__PURE__ */ user_derived(() => ["rs-progress__progress", $$props.customClasses?.progress]);
5556
5792
  const progressStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.progress));
5557
5793
  const progressCircle = useProgressCircle({
5558
- getRootElement: () => rootElement,
5794
+ getRootElement: () => get(rootElement),
5559
5795
  getProgress: () => progress(),
5560
5796
  getBuffer: () => buffer(),
5561
5797
  getSize: () => size(),
@@ -5569,7 +5805,7 @@ function ScenaProgressCircle($$anchor, $$props) {
5569
5805
  });
5570
5806
  function getElements() {
5571
5807
  return {
5572
- root: rootElement,
5808
+ root: get(rootElement),
5573
5809
  track: get(trackElement),
5574
5810
  buffer: get(bufferElement),
5575
5811
  progress: get(progressElement)
@@ -5664,7 +5900,7 @@ function ScenaProgressCircle($$anchor, $$props) {
5664
5900
  if (progressCircle.radialSize) $$render(consequent_1);
5665
5901
  });
5666
5902
  }
5667
- bind_this(svg, ($$value) => rootElement = $$value, () => rootElement);
5903
+ bind_this(svg, ($$value) => set(rootElement, $$value), () => get(rootElement));
5668
5904
  template_effect(
5669
5905
  ($0) => {
5670
5906
  set_attribute(svg, "id", $$props.id);
@@ -5687,7 +5923,7 @@ var root$1 = /* @__PURE__ */ from_html(`<div role="slider"><div><!> <div></div><
5687
5923
  function ScenaProgressLine($$anchor, $$props) {
5688
5924
  push($$props, true);
5689
5925
  let size = prop($$props, "size", 19, () => ComponentSize.MD), buffer = prop($$props, "buffer", 3, 0), progress = prop($$props, "progress", 3, 0), aria = prop($$props, "aria", 19, () => ({ ariaLabel: "Progress" }));
5690
- let rootElement;
5926
+ let rootElement = /* @__PURE__ */ state(null);
5691
5927
  let trackElement;
5692
5928
  let bufferElement = /* @__PURE__ */ state(null);
5693
5929
  let progressElement;
@@ -5705,14 +5941,14 @@ function ScenaProgressLine($$anchor, $$props) {
5705
5941
  const progressStyles = /* @__PURE__ */ user_derived(() => formatComponentStyles($$props.customStyles?.progress));
5706
5942
  function getElements() {
5707
5943
  return {
5708
- root: rootElement,
5944
+ root: get(rootElement),
5709
5945
  track: trackElement,
5710
5946
  buffer: get(bufferElement),
5711
5947
  progress: progressElement
5712
5948
  };
5713
5949
  }
5714
5950
  const progressLine = useProgressLine({
5715
- getRootElement: () => rootElement,
5951
+ getRootElement: () => get(rootElement),
5716
5952
  getProgress: () => progress(),
5717
5953
  getSize: () => size(),
5718
5954
  onSeek: (progress2, event2) => $$props.onSeek?.(progress2, event2),
@@ -5754,7 +5990,7 @@ function ScenaProgressLine($$anchor, $$props) {
5754
5990
  let styles_1;
5755
5991
  bind_this(div_3, ($$value) => progressElement = $$value, () => progressElement);
5756
5992
  bind_this(div_1, ($$value) => trackElement = $$value, () => trackElement);
5757
- bind_this(div, ($$value) => rootElement = $$value, () => rootElement);
5993
+ bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
5758
5994
  template_effect(
5759
5995
  ($0) => {
5760
5996
  set_attribute(div, "id", $$props.id);
@@ -5804,7 +6040,7 @@ function ScenaVideoProgress($$anchor, $$props) {
5804
6040
  set(previousState, null);
5805
6041
  }
5806
6042
  function getElements() {
5807
- return get(rootElement)?.getElements() ?? null;
6043
+ return { root: get(rootElement)?.getElements() ?? null };
5808
6044
  }
5809
6045
  var $$exports = { getElements };
5810
6046
  var fragment = comment();
@@ -5925,10 +6161,10 @@ function ScenaVideoVolume($$anchor, $$props) {
5925
6161
  function getElements() {
5926
6162
  return {
5927
6163
  root: get(rootElement),
5928
- unmuteButton: get(unmuteButtonElement)?.getElements(),
5929
- unmuteIcon: get(unmuteIconElement)?.getElements(),
5930
- muteButton: get(muteButtonElement)?.getElements(),
5931
- muteIcon: get(muteIconElement)?.getElements()
6164
+ unmuteButton: resolveElements(get(unmuteButtonElement)),
6165
+ unmuteIcon: resolveElements(get(unmuteIconElement)),
6166
+ muteButton: resolveElements(get(muteButtonElement)),
6167
+ muteIcon: resolveElements(get(muteIconElement))
5932
6168
  };
5933
6169
  }
5934
6170
  var $$exports = { getElements };
@@ -5950,7 +6186,7 @@ function ScenaVideoVolume($$anchor, $$props) {
5950
6186
  };
5951
6187
  if_block(node_1, ($$render) => {
5952
6188
  if (scenaVideoContext.isMuted) $$render(consequent);
5953
- else $$render(alternate, false);
6189
+ else $$render(alternate, -1);
5954
6190
  });
5955
6191
  }
5956
6192
  var node_2 = sibling(span, 2);
@@ -6055,7 +6291,7 @@ function ScenaVideoVolume($$anchor, $$props) {
6055
6291
  };
6056
6292
  if_block(node_2, ($$render) => {
6057
6293
  if (scenaVideoContext.isMuted) $$render(consequent_1);
6058
- else $$render(alternate_1, false);
6294
+ else $$render(alternate_1, -1);
6059
6295
  });
6060
6296
  }
6061
6297
  bind_this(div, ($$value) => set(rootElement, $$value), () => get(rootElement));
@@ -6151,7 +6387,6 @@ function Scena($$anchor, $$props) {
6151
6387
  };
6152
6388
  onMount(() => {
6153
6389
  $$props.mount();
6154
- $$props.eventEmitter.emit(ScenaEvent.ON_SCENA_MOUNT);
6155
6390
  });
6156
6391
  onDestroy(() => {
6157
6392
  $$props.eventEmitter.emit(ScenaEvent.ON_SCENA_DESTROY);
@@ -6424,7 +6659,7 @@ function useScena() {
6424
6659
  await unmount(instance.component);
6425
6660
  }
6426
6661
  }
6427
- return { NAME: "@retoo/scena", VERSION: "0.0.0", mount: mount$1, unmount: unmount$1 };
6662
+ return { NAME: "@retoo/scena", VERSION: "0.0.1", mount: mount$1, unmount: unmount$1 };
6428
6663
  }
6429
6664
  function useScenaConfig(initial) {
6430
6665
  let config = /* @__PURE__ */ state(proxy(deepClone(initial)));
@@ -6481,8 +6716,7 @@ class SvelteMap extends Map {
6481
6716
  var sources = this.#sources;
6482
6717
  var s = sources.get(key);
6483
6718
  if (s === void 0) {
6484
- var ret = super.get(key);
6485
- if (ret !== void 0) {
6719
+ if (super.has(key)) {
6486
6720
  s = this.#source(0);
6487
6721
  sources.set(key, s);
6488
6722
  } else {
@@ -6506,8 +6740,7 @@ class SvelteMap extends Map {
6506
6740
  var sources = this.#sources;
6507
6741
  var s = sources.get(key);
6508
6742
  if (s === void 0) {
6509
- var ret = super.get(key);
6510
- if (ret !== void 0) {
6743
+ if (super.has(key)) {
6511
6744
  s = this.#source(0);
6512
6745
  sources.set(key, s);
6513
6746
  } else {
@@ -6555,8 +6788,10 @@ class SvelteMap extends Map {
6555
6788
  var res = super.delete(key);
6556
6789
  if (s !== void 0) {
6557
6790
  sources.delete(key);
6558
- set(this.#size, super.size);
6559
6791
  set(s, -1);
6792
+ }
6793
+ if (res) {
6794
+ set(this.#size, super.size);
6560
6795
  increment(this.#version);
6561
6796
  }
6562
6797
  return res;
@@ -6907,9 +7142,7 @@ function getScenaElement() {
6907
7142
  }
6908
7143
  function defineScenaElement() {
6909
7144
  const customElement = getScenaElement();
6910
- if (customElement) {
6911
- return;
6912
- }
7145
+ if (customElement) return;
6913
7146
  customElements.define(ScenaElement.tagName, ScenaElement);
6914
7147
  }
6915
7148
  if (isBrowser) {