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