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