sibujs 4.14.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/browser.cjs +297 -45
  2. package/dist/browser.js +6 -7
  3. package/dist/build.cjs +2189 -573
  4. package/dist/build.js +16 -15
  5. package/dist/cdn.dev.global.js +13 -12
  6. package/dist/cdn.full.dev.global.js +14 -13
  7. package/dist/cdn.full.global.js +12 -12
  8. package/dist/cdn.global.js +12 -12
  9. package/dist/{chunk-RVR5NPFL.js → chunk-2VKTFA7C.js} +1 -1
  10. package/dist/{chunk-7ILEHTVX.js → chunk-4AEFGRYW.js} +1 -1
  11. package/dist/{chunk-4TQDTWWN.js → chunk-6IV5ZRG6.js} +5 -7
  12. package/dist/{chunk-GVAMIU6K.js → chunk-75EAQH3U.js} +2 -2
  13. package/dist/{chunk-TLS4NVIB.js → chunk-7JO7DPSS.js} +4 -4
  14. package/dist/{chunk-SVULV7O4.js → chunk-AQH7WDSE.js} +6 -8
  15. package/dist/{chunk-S37PZD6I.js → chunk-BF3WBJJQ.js} +60 -10
  16. package/dist/{chunk-LJMX4SQ7.js → chunk-BG4BP44S.js} +3 -3
  17. package/dist/{chunk-N7A6FKWW.js → chunk-D44TAGCT.js} +2 -2
  18. package/dist/{chunk-CCKUNHVU.js → chunk-DAEXQJQA.js} +1 -1
  19. package/dist/chunk-DNCQDFJJ.js +22 -0
  20. package/dist/{chunk-BKZ5N6NK.js → chunk-DNCT2UXB.js} +4 -4
  21. package/dist/{chunk-BOYKGGVD.js → chunk-DRWOD7RZ.js} +4 -4
  22. package/dist/chunk-DS5V2PRE.js +64 -0
  23. package/dist/{chunk-VM2U5LEL.js → chunk-EHSJESRN.js} +595 -123
  24. package/dist/{chunk-MIRKTVH4.js → chunk-GFM5WWPU.js} +252 -5
  25. package/dist/{chunk-52XFPGSN.js → chunk-HTPOIAAL.js} +1 -1
  26. package/dist/{chunk-3HEX6QJQ.js → chunk-I2R5QALY.js} +2 -4
  27. package/dist/{chunk-4FJSAUKB.js → chunk-IUBV5WO5.js} +1 -1
  28. package/dist/{chunk-A454RAEK.js → chunk-KIDETDMU.js} +5 -7
  29. package/dist/{chunk-JTFQ7IL4.js → chunk-KPAXG5IR.js} +7 -9
  30. package/dist/{chunk-AE32RGWX.js → chunk-LGUXYHTZ.js} +3 -3
  31. package/dist/{chunk-Y4LUM2XS.js → chunk-LQWLPQOK.js} +6 -8
  32. package/dist/{chunk-CNPT6NKV.js → chunk-MINLMJUY.js} +48 -9
  33. package/dist/{chunk-BNXRWZZV.js → chunk-OURTGOJT.js} +8 -10
  34. package/dist/{chunk-F67F77IA.js → chunk-TQ24Y3IV.js} +2 -2
  35. package/dist/{chunk-2TTRW2TE.js → chunk-UM3M5PXS.js} +8 -8
  36. package/dist/{chunk-CJ7KS3DF.js → chunk-VSTX3XSX.js} +205 -15
  37. package/dist/{chunk-HQIAL7F2.js → chunk-XPDZ2LDR.js} +2 -2
  38. package/dist/{chunk-UUIKJJIK.js → chunk-Y7JM7GY2.js} +5 -7
  39. package/dist/{chunk-QS6GMWDD.js → chunk-YAFITBOK.js} +1269 -162
  40. package/dist/data.cjs +285 -33
  41. package/dist/data.js +6 -7
  42. package/dist/devtools.cjs +289 -39
  43. package/dist/devtools.js +5 -6
  44. package/dist/{dispose-EIHHHDC7.js → dispose-3WDBYJMH.js} +3 -1
  45. package/dist/ecosystem.cjs +345 -61
  46. package/dist/ecosystem.d.cts +1 -1
  47. package/dist/ecosystem.d.ts +1 -1
  48. package/dist/ecosystem.js +10 -10
  49. package/dist/extras.cjs +568 -248
  50. package/dist/extras.d.cts +1 -1
  51. package/dist/extras.d.ts +1 -1
  52. package/dist/extras.js +27 -27
  53. package/dist/index.cjs +2134 -515
  54. package/dist/index.d.cts +628 -211
  55. package/dist/index.d.ts +628 -211
  56. package/dist/index.js +22 -15
  57. package/dist/motion.cjs +286 -30
  58. package/dist/motion.js +4 -4
  59. package/dist/patterns.cjs +301 -43
  60. package/dist/patterns.js +6 -6
  61. package/dist/performance.cjs +286 -36
  62. package/dist/performance.js +9 -9
  63. package/dist/plugins.cjs +1237 -291
  64. package/dist/plugins.d.cts +3 -1
  65. package/dist/plugins.d.ts +3 -1
  66. package/dist/plugins.js +20 -19
  67. package/dist/{renderRoute-fxgsm2Ir.d.ts → renderRoute-B84MONaO.d.cts} +2 -2
  68. package/dist/{renderRoute-DP20XwMS.d.cts → renderRoute-_yxPuEQY.d.ts} +2 -2
  69. package/dist/{routeHead-CE9SV-cH.d.cts → routeHead-DLxlq15W.d.cts} +94 -0
  70. package/dist/{routeHead-DzVxPviY.d.ts → routeHead-w8nANZ3M.d.ts} +94 -0
  71. package/dist/{ssr-NECEU4X4.js → ssr-EF3IUHTE.js} +6 -6
  72. package/dist/ssr-dom.cjs +64 -9
  73. package/dist/ssr-dom.d.cts +2 -0
  74. package/dist/ssr-dom.d.ts +2 -0
  75. package/dist/ssr-dom.js +2 -1
  76. package/dist/ssr.cjs +850 -170
  77. package/dist/ssr.d.cts +5 -3
  78. package/dist/ssr.d.ts +5 -3
  79. package/dist/ssr.js +16 -15
  80. package/dist/{tagFactory-DkytnJws.d.cts → tagFactory-BfEh69VF.d.cts} +7 -0
  81. package/dist/{tagFactory-Bnd_Nph9.d.ts → tagFactory-pSYiLYyh.d.ts} +7 -0
  82. package/dist/testing.cjs +817 -132
  83. package/dist/testing.d.cts +4 -2
  84. package/dist/testing.d.ts +4 -2
  85. package/dist/testing.js +18 -17
  86. package/dist/track-core-0edROAF5.d.ts +187 -0
  87. package/dist/track-core-DN5fYLWi.d.cts +187 -0
  88. package/dist/ui.cjs +293 -43
  89. package/dist/ui.js +10 -12
  90. package/dist/widgets.cjs +285 -27
  91. package/dist/widgets.js +7 -7
  92. package/package.json +1 -1
  93. package/dist/chunk-7ZHH77QA.js +0 -9
package/dist/ssr.cjs CHANGED
@@ -84,6 +84,12 @@ __export(ssr_exports, {
84
84
  });
85
85
  module.exports = __toCommonJS(ssr_exports);
86
86
 
87
+ // src/utils/globalSingleton.ts
88
+ function globalSingleton(key, create) {
89
+ const g2 = globalThis;
90
+ return g2[key] ?? (g2[key] = create());
91
+ }
92
+
87
93
  // src/core/dev.ts
88
94
  var DEV = typeof __SIBU_DEV__ !== "undefined" ? !!__SIBU_DEV__ : typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
89
95
  // safe default: off in browser, on in test/dev Node
@@ -324,7 +330,12 @@ function beginHydration() {
324
330
  }
325
331
 
326
332
  // src/core/rendering/dispose.ts
327
- var elementDisposers = /* @__PURE__ */ new WeakMap();
333
+ var state2 = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.disposers.v1"), () => ({
334
+ disposers: /* @__PURE__ */ new WeakMap(),
335
+ captures: [],
336
+ bindings: { count: 0 }
337
+ }));
338
+ var elementDisposers = state2.disposers;
328
339
  var MAX_DRAIN_TEARDOWNS = 1e4;
329
340
  function reportDrainRunaway(label2, executed, remaining) {
330
341
  if (typeof console === "undefined") return;
@@ -333,13 +344,13 @@ function reportDrainRunaway(label2, executed, remaining) {
333
344
  { executed, remaining }
334
345
  );
335
346
  }
336
- var activeBindingCount = 0;
347
+ var bindings = state2.bindings;
337
348
  function resolveCapture(capture) {
338
349
  let frame = capture;
339
350
  while (frame?.closed) frame = frame.forwardTo;
340
351
  return frame ?? null;
341
352
  }
342
- var registrationCaptures = [];
353
+ var registrationCaptures = state2.captures;
343
354
  function currentDisposerCapture() {
344
355
  return resolveCapture(registrationCaptures[registrationCaptures.length - 1]);
345
356
  }
@@ -358,7 +369,7 @@ function registerDisposer(node, teardown) {
358
369
  elementDisposers.set(node, disposers);
359
370
  }
360
371
  disposers.push(teardown);
361
- if (DEV) activeBindingCount++;
372
+ if (DEV) bindings.count++;
362
373
  const capture = resolveCapture(registrationCaptures[registrationCaptures.length - 1]);
363
374
  if (capture) capture.entries.push([node, teardown]);
364
375
  }
@@ -382,17 +393,17 @@ function disposeNodeOwn(node) {
382
393
  let executed = 0;
383
394
  let runaway = false;
384
395
  while (!runaway) {
385
- const pending = elementDisposers.get(node);
386
- if (!pending || pending.length === 0) break;
387
- const snapshot = pending.slice();
396
+ const pending2 = elementDisposers.get(node);
397
+ if (!pending2 || pending2.length === 0) break;
398
+ const snapshot = pending2.slice();
388
399
  elementDisposers.delete(node);
389
- if (DEV) activeBindingCount -= snapshot.length;
400
+ if (DEV) bindings.count -= snapshot.length;
390
401
  for (let i2 = 0; i2 < snapshot.length; i2++) {
391
402
  if (executed >= MAX_DRAIN_TEARDOWNS) {
392
403
  const rest = snapshot.slice(i2);
393
404
  const added = elementDisposers.get(node);
394
405
  elementDisposers.set(node, added ? rest.concat(added) : rest);
395
- if (DEV) activeBindingCount += rest.length;
406
+ if (DEV) bindings.count += rest.length;
396
407
  reportDrainRunaway("dispose", executed, rest.length + (added?.length ?? 0));
397
408
  runaway = true;
398
409
  break;
@@ -595,6 +606,201 @@ function bindOwnerScope(fn) {
595
606
  return (...args) => runWithOwnerScope(scope, () => fn(...args));
596
607
  }
597
608
  var currentStructOwner = null;
609
+ var frozenOwners = 0;
610
+ var ACTIVE = 0;
611
+ var PAUSED = 1;
612
+ var ENDED = 2;
613
+ var NOOP = () => {
614
+ };
615
+ var skippedWhileHeld = /* @__PURE__ */ new Set();
616
+ var waiters = /* @__PURE__ */ new Set();
617
+ var heldRoots = /* @__PURE__ */ new Set();
618
+ function ownerState(tok) {
619
+ let state5 = ACTIVE;
620
+ for (let t = tok; t !== null; ) {
621
+ const o = t.sub;
622
+ if (o === null) return ENDED;
623
+ if (o._frozen === true) state5 = PAUSED;
624
+ t = o._owner ?? null;
625
+ }
626
+ return state5;
627
+ }
628
+ var endWatchers = /* @__PURE__ */ new Set();
629
+ var stateWatchers = /* @__PURE__ */ new Set();
630
+ var stateCheckQueued = false;
631
+ function queueStateCheck() {
632
+ if (stateCheckQueued || stateWatchers.size === 0) return;
633
+ stateCheckQueued = true;
634
+ queueMicrotask(() => {
635
+ stateCheckQueued = false;
636
+ for (const watcher of [...stateWatchers]) {
637
+ if (!stateWatchers.has(watcher)) continue;
638
+ const state5 = watcher.check.state();
639
+ if (state5 === ENDED) stateWatchers.delete(watcher);
640
+ if (state5 === ENDED || state5 === watcher.last) continue;
641
+ watcher.last = state5;
642
+ try {
643
+ watcher.listener(state5);
644
+ } catch (err) {
645
+ reportError(err, { phase: "effect" });
646
+ }
647
+ }
648
+ });
649
+ }
650
+ var ALWAYS_ACTIVE = Object.assign(() => false, {
651
+ state: () => ACTIVE,
652
+ wait: (onActive) => {
653
+ onActive();
654
+ return NOOP;
655
+ },
656
+ onEnd: () => NOOP,
657
+ run: (fn) => fn(),
658
+ onChange: () => NOOP,
659
+ within: () => false
660
+ });
661
+ function captureFrozen() {
662
+ const tok = currentStructOwner;
663
+ if (tok === null) return ALWAYS_ACTIVE;
664
+ const state5 = () => ownerState(tok);
665
+ const check = Object.assign(() => state5() !== ACTIVE, {
666
+ state: state5,
667
+ wait: (onActive, onEnd) => {
668
+ const now = state5();
669
+ if (now !== PAUSED) {
670
+ (now === ACTIVE ? onActive : onEnd)();
671
+ return NOOP;
672
+ }
673
+ const waiter = { check, onActive, onEnd };
674
+ waiters.add(waiter);
675
+ return () => {
676
+ waiters.delete(waiter);
677
+ };
678
+ },
679
+ onEnd: (onEnd) => {
680
+ if (state5() === ENDED) {
681
+ onEnd();
682
+ return NOOP;
683
+ }
684
+ const watcher = { check, onActive: NOOP, onEnd };
685
+ endWatchers.add(watcher);
686
+ return () => {
687
+ endWatchers.delete(watcher);
688
+ };
689
+ },
690
+ run: (fn) => {
691
+ const prev = currentStructOwner;
692
+ currentStructOwner = tok.sub === null ? null : tok;
693
+ try {
694
+ return fn();
695
+ } finally {
696
+ currentStructOwner = prev;
697
+ }
698
+ },
699
+ onChange: (listener) => {
700
+ const last = state5();
701
+ if (last === ENDED) return NOOP;
702
+ const watcher = { check, last, listener };
703
+ stateWatchers.add(watcher);
704
+ return () => {
705
+ stateWatchers.delete(watcher);
706
+ };
707
+ },
708
+ within: (owner) => {
709
+ const target = owner.run(() => currentStructOwner);
710
+ if (target === null) return false;
711
+ for (let t = tok; t !== null; ) {
712
+ if (t === target) return true;
713
+ const o = t.sub;
714
+ if (o === null) return false;
715
+ t = o._owner ?? null;
716
+ }
717
+ return false;
718
+ }
719
+ });
720
+ return check;
721
+ }
722
+ function holdSubtree(root) {
723
+ heldRoots.add(root);
724
+ return () => {
725
+ if (heldRoots.delete(root)) settleHeld();
726
+ };
727
+ }
728
+ function isHeld(sub2) {
729
+ if (frozenOwners !== 0 && hasFrozenOwner(sub2)) return true;
730
+ if (heldRoots.size !== 0) {
731
+ const node = sub2._errorNode;
732
+ if (node != null) {
733
+ for (const root of heldRoots) if (root.contains(node)) return true;
734
+ }
735
+ }
736
+ return false;
737
+ }
738
+ function notifyEnded() {
739
+ for (const watcher of stateWatchers) if (watcher.check.state() === ENDED) stateWatchers.delete(watcher);
740
+ let ended = null;
741
+ for (const watcher of endWatchers) {
742
+ if (watcher.check.state() !== ENDED) continue;
743
+ endWatchers.delete(watcher);
744
+ (ended ?? (ended = [])).push(watcher);
745
+ }
746
+ if (ended === null) return;
747
+ for (const watcher of ended) {
748
+ try {
749
+ watcher.onEnd();
750
+ } catch (err) {
751
+ reportError(err, { phase: "cleanup" });
752
+ }
753
+ }
754
+ }
755
+ function dropReleasedSkipped() {
756
+ for (const sub2 of skippedWhileHeld) {
757
+ if (sub2._disposed === true || sub2.depsHead == null) skippedWhileHeld.delete(sub2);
758
+ }
759
+ }
760
+ function settleHeld() {
761
+ for (const sub2 of skippedWhileHeld) {
762
+ if (sub2._disposed === true) skippedWhileHeld.delete(sub2);
763
+ else if (!isHeld(sub2)) {
764
+ skippedWhileHeld.delete(sub2);
765
+ if (!pendingSet.has(sub2)) {
766
+ pendingSet.add(sub2);
767
+ pendingQueue.push(sub2);
768
+ }
769
+ }
770
+ }
771
+ if (frozenOwners === 0 && heldRoots.size === 0) skippedWhileHeld.clear();
772
+ let ready = null;
773
+ for (const waiter of waiters) {
774
+ if (waiter.check.state() === PAUSED) continue;
775
+ waiters.delete(waiter);
776
+ (ready ?? (ready = [])).push(waiter);
777
+ }
778
+ if (ready !== null) {
779
+ const settle = ready;
780
+ queueMicrotask(() => {
781
+ for (const waiter of settle) {
782
+ const state5 = waiter.check.state();
783
+ if (state5 === PAUSED) waiters.add(waiter);
784
+ else
785
+ try {
786
+ (state5 === ACTIVE ? waiter.onActive : waiter.onEnd)();
787
+ } catch (err) {
788
+ reportError(err, { phase: "effect" });
789
+ }
790
+ }
791
+ });
792
+ }
793
+ if (pendingQueue.length > 0) drainNotificationQueue();
794
+ }
795
+ function hasFrozenOwner(sub2) {
796
+ for (let t = sub2._owner ?? null; t !== null; ) {
797
+ const o = t.sub;
798
+ if (o === null) return false;
799
+ if (o._frozen === true) return true;
800
+ t = o._owner ?? null;
801
+ }
802
+ return false;
803
+ }
598
804
  var subscriberEpochCounter = 0;
599
805
  function retrack(effectFn, subscriber) {
600
806
  const prev = currentSubscriber;
@@ -702,6 +908,20 @@ function structuralBinding(commit, ownerNode) {
702
908
  } finally {
703
909
  currentStructOwner = prev;
704
910
  }
911
+ },
912
+ freeze: () => {
913
+ const s2 = sub2;
914
+ if (s2._disposed || s2._frozen) return;
915
+ s2._frozen = true;
916
+ frozenOwners++;
917
+ queueStateCheck();
918
+ },
919
+ thaw: () => {
920
+ if (!sub2._frozen) return;
921
+ sub2._frozen = false;
922
+ frozenOwners--;
923
+ queueStateCheck();
924
+ settleHeld();
705
925
  }
706
926
  };
707
927
  }
@@ -730,20 +950,34 @@ function createBinding(commit, ownerNode, structural) {
730
950
  subscriber._errorNode = ownerNode;
731
951
  subscriber._tok = null;
732
952
  subscriber._owner = null;
953
+ subscriber._frozen = false;
733
954
  if (structural) subscriber._tok = { sub: subscriber };
734
955
  try {
735
956
  run();
736
957
  } catch (err) {
737
958
  subscriber._disposed = true;
738
959
  subscriber._errorNode = void 0;
739
- if (subscriber._tok != null) subscriber._tok.sub = null;
960
+ if (subscriber._tok != null) {
961
+ subscriber._tok.sub = null;
962
+ if (endWatchers.size !== 0 || stateWatchers.size !== 0) notifyEnded();
963
+ }
740
964
  cleanup(subscriber);
741
965
  throw err;
742
966
  }
743
967
  subscriber._dispose = () => {
744
968
  subscriber._disposed = true;
969
+ const wasFrozen = subscriber._frozen === true;
970
+ if (wasFrozen) {
971
+ subscriber._frozen = false;
972
+ frozenOwners--;
973
+ }
745
974
  subscriber._errorNode = void 0;
746
- if (subscriber._tok != null) subscriber._tok.sub = null;
975
+ if (subscriber._tok != null) {
976
+ subscriber._tok.sub = null;
977
+ if (endWatchers.size !== 0 || stateWatchers.size !== 0) notifyEnded();
978
+ if (skippedWhileHeld.size !== 0) dropReleasedSkipped();
979
+ if (wasFrozen || waiters.size !== 0) settleHeld();
980
+ }
747
981
  cleanup(subscriber);
748
982
  };
749
983
  return subscriber;
@@ -853,6 +1087,10 @@ function runPendingOwners(sub2) {
853
1087
  }
854
1088
  }
855
1089
  function runQueued(sub2) {
1090
+ if ((frozenOwners !== 0 || heldRoots.size !== 0) && isHeld(sub2)) {
1091
+ skippedWhileHeld.add(sub2);
1092
+ return;
1093
+ }
856
1094
  if (quarantined.size > 0 && quarantined.has(sub2)) return;
857
1095
  if (sub2._hasComputedDep === true && !depsChanged(sub2)) return;
858
1096
  if (tickRepeat(sub2)) {
@@ -1000,7 +1238,7 @@ function forEachSubscriber(signal2, visit) {
1000
1238
  }
1001
1239
 
1002
1240
  // src/reactivity/track.ts
1003
- var _runtimeVersion = true ? "4.14.0" : "dev";
1241
+ var _runtimeVersion = true ? "4.15.0" : "dev";
1004
1242
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
1005
1243
  function resolveReactiveApi() {
1006
1244
  const g2 = globalThis;
@@ -1036,6 +1274,8 @@ function resolveReactiveApi() {
1036
1274
  runWithOwnerScope,
1037
1275
  bindOwnerScope,
1038
1276
  structuralBinding,
1277
+ captureFrozen,
1278
+ holdSubtree,
1039
1279
  version: _runtimeVersion
1040
1280
  };
1041
1281
  g2[REGISTRY_KEY] = local;
@@ -1063,6 +1303,22 @@ var getOwnerScope2 = API.getOwnerScope ?? getOwnerScope;
1063
1303
  var runWithOwnerScope2 = API.runWithOwnerScope ?? runWithOwnerScope;
1064
1304
  var bindOwnerScope2 = API.bindOwnerScope ?? bindOwnerScope;
1065
1305
  var structuralBinding2 = API.structuralBinding ?? ((commit, ownerNode) => ({ stop: API.reactiveBinding(commit, ownerNode), run: (fn) => fn() }));
1306
+ var captureFrozen2 = API.captureFrozen ?? (() => Object.assign(() => false, {
1307
+ state: () => 0,
1308
+ wait: (onActive) => {
1309
+ onActive();
1310
+ return () => {
1311
+ };
1312
+ },
1313
+ onEnd: () => () => {
1314
+ },
1315
+ run: (fn) => fn(),
1316
+ onChange: () => () => {
1317
+ },
1318
+ within: () => false
1319
+ }));
1320
+ var holdSubtree2 = API.holdSubtree ?? (() => () => {
1321
+ });
1066
1322
 
1067
1323
  // src/core/devtoolsHook.ts
1068
1324
  function emitDevtools(hook, event, payload) {
@@ -1191,14 +1447,14 @@ function runInSSRContext(fn) {
1191
1447
  }
1192
1448
  function trackPending(promise, label2, hydration = true) {
1193
1449
  const store = getRequestStore();
1194
- const pending = store?.pending;
1195
- const sessions = pending || !hydration ? [] : hydrationOwners();
1196
- if (!pending && sessions.length === 0) return promise;
1450
+ const pending2 = store?.pending;
1451
+ const sessions = pending2 || !hydration ? [] : hydrationOwners();
1452
+ if (!pending2 && sessions.length === 0) return promise;
1197
1453
  const entry = { label: label2, since: Date.now(), boundary: currentBoundary() ?? void 0 };
1198
- pending?.add(entry);
1454
+ pending2?.add(entry);
1199
1455
  const release = holdHydration(sessions, entry);
1200
1456
  const done = () => {
1201
- pending?.delete(entry);
1457
+ pending2?.delete(entry);
1202
1458
  store?.wake?.();
1203
1459
  release();
1204
1460
  };
@@ -1344,12 +1600,6 @@ function effect(effectFn, options) {
1344
1600
  return () => disposeEffect(ctx);
1345
1601
  }
1346
1602
 
1347
- // src/utils/globalSingleton.ts
1348
- function globalSingleton(key, create) {
1349
- const g2 = globalThis;
1350
- return g2[key] ?? (g2[key] = create());
1351
- }
1352
-
1353
1603
  // src/utils/singletonResource.ts
1354
1604
  function singletonResource(io) {
1355
1605
  let original = null;
@@ -2258,6 +2508,25 @@ function collectTransfer() {
2258
2508
  return out;
2259
2509
  }
2260
2510
 
2511
+ // src/utils/styleKey.ts
2512
+ var EXCEPTIONS = { cssFloat: "float" };
2513
+ var VENDOR_PREFIX = /^(webkit|moz|ms|o)-/;
2514
+ var cache = /* @__PURE__ */ new Map();
2515
+ var CACHE_MAX = 1e3;
2516
+ function styleKeyToProperty(key) {
2517
+ let name = cache.get(key);
2518
+ if (name !== void 0) return name;
2519
+ if (key.startsWith("--")) name = key;
2520
+ else if (Object.hasOwn(EXCEPTIONS, key)) name = EXCEPTIONS[key];
2521
+ else {
2522
+ name = key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
2523
+ if (VENDOR_PREFIX.test(name)) name = `-${name}`;
2524
+ }
2525
+ if (cache.size >= CACHE_MAX) cache.clear();
2526
+ cache.set(key, name);
2527
+ return name;
2528
+ }
2529
+
2261
2530
  // src/platform/serverDom.ts
2262
2531
  var HTML_NS = "http://www.w3.org/1999/xhtml";
2263
2532
  var SVG_NS = "http://www.w3.org/2000/svg";
@@ -2888,9 +3157,15 @@ var ServerAttr = class {
2888
3157
  get nodeValue() {
2889
3158
  return this._value;
2890
3159
  }
3160
+ set nodeValue(v) {
3161
+ this.value = v;
3162
+ }
2891
3163
  get textContent() {
2892
3164
  return this._value;
2893
3165
  }
3166
+ set textContent(v) {
3167
+ this.value = v;
3168
+ }
2894
3169
  };
2895
3170
  var ServerNamedNodeMap = class extends Array {
2896
3171
  static get [Symbol.species]() {
@@ -2927,12 +3202,6 @@ function splitDeclarations(text2) {
2927
3202
  out.push(text2.slice(start));
2928
3203
  return out;
2929
3204
  }
2930
- var CAMEL_EXCEPTIONS = { cssFloat: "float" };
2931
- function toKebab(prop) {
2932
- if (prop.startsWith("--")) return prop;
2933
- if (Object.hasOwn(CAMEL_EXCEPTIONS, prop)) return CAMEL_EXCEPTIONS[prop];
2934
- return prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).replace(/^(webkit|moz|ms)-/, "-$1-");
2935
- }
2936
3205
  var ServerStyle = class {
2937
3206
  constructor(el) {
2938
3207
  this.el = el;
@@ -3027,13 +3296,13 @@ function styleProxy(style2) {
3027
3296
  get(target, key, receiver) {
3028
3297
  if (typeof key === "string" && !(key in target)) {
3029
3298
  if (/^\d+$/.test(key)) return target.item(Number(key));
3030
- return target.getPropertyValue(toKebab(key));
3299
+ return target.getPropertyValue(styleKeyToProperty(key));
3031
3300
  }
3032
3301
  return Reflect.get(target, key, receiver);
3033
3302
  },
3034
3303
  set(target, key, value, receiver) {
3035
3304
  if (typeof key === "string" && !(key in target)) {
3036
- target.setProperty(toKebab(key), value == null ? "" : String(value));
3305
+ target.setProperty(styleKeyToProperty(key), value == null ? "" : String(value));
3037
3306
  return true;
3038
3307
  }
3039
3308
  return Reflect.set(target, key, value, receiver);
@@ -3438,6 +3707,10 @@ var ServerInputElement = class extends ServerHTMLElement {
3438
3707
  get defaultChecked() {
3439
3708
  return this.hasAttribute("checked");
3440
3709
  }
3710
+ /** Reflects to the `checked` attribute; `checked` follows it until written (dirty checkedness). */
3711
+ set defaultChecked(v) {
3712
+ this.toggleAttribute("checked", !!v);
3713
+ }
3441
3714
  get type() {
3442
3715
  return (this.getAttribute("type") ?? "text").toLowerCase();
3443
3716
  }
@@ -3495,8 +3768,10 @@ reflectDisabled(ServerTextAreaElement.prototype);
3495
3768
  var ServerOptionElement = class extends ServerHTMLElement {
3496
3769
  constructor() {
3497
3770
  super(...arguments);
3498
- /** @internal */
3771
+ /** Selectedness; `null` while it follows the `selected` attribute. @internal */
3499
3772
  this._selected = null;
3773
+ /** Set by a `selected` write: the attribute no longer decides selectedness. @internal */
3774
+ this._dirty = false;
3500
3775
  }
3501
3776
  get value() {
3502
3777
  return this.getAttribute("value") ?? this.text;
@@ -3513,18 +3788,48 @@ var ServerOptionElement = class extends ServerHTMLElement {
3513
3788
  get label() {
3514
3789
  return this.getAttribute("label") ?? this.text;
3515
3790
  }
3791
+ set label(v) {
3792
+ this.setAttribute("label", v);
3793
+ }
3516
3794
  get selected() {
3517
3795
  return this._selected ?? this.hasAttribute("selected");
3518
3796
  }
3519
3797
  set selected(v) {
3520
3798
  this._selected = !!v;
3799
+ this._dirty = true;
3800
+ const select2 = singleSelectOf(this);
3801
+ if (select2 && v) {
3802
+ for (const o of select2.options) if (o !== this) o._selected = false;
3803
+ }
3521
3804
  }
3522
3805
  get defaultSelected() {
3523
3806
  return this.hasAttribute("selected");
3524
3807
  }
3808
+ /** Reflects to the `selected` attribute; `selected` follows it unless written. */
3809
+ set defaultSelected(v) {
3810
+ this.toggleAttribute("selected", !!v);
3811
+ if (this._dirty) return;
3812
+ this._selected = null;
3813
+ const select2 = singleSelectOf(this);
3814
+ if (!select2) return;
3815
+ let last = null;
3816
+ for (const o of select2.options) if (o.selected) last = o;
3817
+ for (const o of select2.options) if (o !== last && o.selected) o._selected = false;
3818
+ }
3525
3819
  };
3820
+ function singleSelectOf(option2) {
3821
+ let parent = option2.parentNode;
3822
+ if (parent instanceof ServerElement && parent.localName === "optgroup") parent = parent.parentNode;
3823
+ return parent instanceof ServerSelectElement && !parent.hasAttribute("multiple") ? parent : null;
3824
+ }
3526
3825
  reflectDisabled(ServerOptionElement.prototype);
3527
3826
  var ServerSelectElement = class extends ServerHTMLElement {
3827
+ get multiple() {
3828
+ return this.hasAttribute("multiple");
3829
+ }
3830
+ set multiple(v) {
3831
+ this.toggleAttribute("multiple", !!v);
3832
+ }
3528
3833
  get options() {
3529
3834
  return this.querySelectorAll("option");
3530
3835
  }
@@ -3829,21 +4134,21 @@ function compileSelector(selector) {
3829
4134
  const tokens = text2.match(/(?:\\.|\[[^\]]*\]|[^\s>])+|>/g) ?? [];
3830
4135
  const compounds = [];
3831
4136
  const combinators = [];
3832
- let pending = " ";
4137
+ let pending2 = " ";
3833
4138
  let scoped = false;
3834
4139
  for (const token of tokens) {
3835
4140
  if (token === ">") {
3836
- pending = ">";
4141
+ pending2 = ">";
3837
4142
  continue;
3838
4143
  }
3839
4144
  if (token === ":scope") {
3840
4145
  scoped = true;
3841
- pending = " ";
4146
+ pending2 = " ";
3842
4147
  continue;
3843
4148
  }
3844
- if (compounds.length > 0) combinators.unshift(pending);
4149
+ if (compounds.length > 0) combinators.unshift(pending2);
3845
4150
  compounds.unshift(parseCompound(token, selector));
3846
- pending = " ";
4151
+ pending2 = " ";
3847
4152
  }
3848
4153
  if (compounds.length === 0) throw syntaxError(selector);
3849
4154
  groups.push({ compounds, combinators, scoped });
@@ -4213,14 +4518,14 @@ function isForbiddenMetaSnapshot(attributes) {
4213
4518
  }
4214
4519
 
4215
4520
  // src/utils/embedPolicy.ts
4216
- var state2 = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.embed.v2"), () => ({
4521
+ var state3 = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.embed.v2"), () => ({
4217
4522
  allowed: [],
4218
4523
  frames: /* @__PURE__ */ new WeakMap()
4219
4524
  }));
4220
4525
  var REQUEST_CACHE = "embed";
4221
4526
  function currentEmbedAllowlist() {
4222
4527
  const scoped = getRequestStore()?.caches?.get(REQUEST_CACHE)?.get("allowed");
4223
- return scoped ?? state2.allowed;
4528
+ return scoped ?? state3.allowed;
4224
4529
  }
4225
4530
  function resolveEmbedSrc(value, allowed = currentEmbedAllowlist()) {
4226
4531
  if (typeof value !== "string" || sanitizeUrl(value) === "") return null;
@@ -4280,7 +4585,7 @@ function narrowEmbedAllow(value) {
4280
4585
  return granted.filter((feature) => !denied.includes(feature)).join("; ");
4281
4586
  }
4282
4587
  function getEmbedRecord(frame) {
4283
- return state2.frames.get(frame);
4588
+ return state3.frames.get(frame);
4284
4589
  }
4285
4590
  function intersect(current2, permitted, separator) {
4286
4591
  const allowed = permitted.split(separator);
@@ -4332,9 +4637,9 @@ function installHook() {
4332
4637
  if (hookInstalled) return;
4333
4638
  hookInstalled = true;
4334
4639
  setBoundaryHook((container) => {
4335
- const state3 = requestSlot("stream");
4640
+ const state5 = requestSlot("stream");
4336
4641
  const store = getRequestStore();
4337
- if (!state3 || !store) return null;
4642
+ if (!state5 || !store) return null;
4338
4643
  const id = `sibu-sus-${store.suspenseIdCounter++}`;
4339
4644
  container.setAttribute("data-sibu-suspense-id", id);
4340
4645
  const record = {
@@ -4345,8 +4650,8 @@ function installHook() {
4345
4650
  fallbackHtml: null,
4346
4651
  api: {
4347
4652
  enter: (fn) => {
4348
- if (record.fallbackHtml === null && state3.serialize) {
4349
- record.fallbackHtml = Array.from(container.childNodes, (n) => state3.serialize?.(n) ?? "").join("");
4653
+ if (record.fallbackHtml === null && state5.serialize) {
4654
+ record.fallbackHtml = Array.from(container.childNodes, (n) => state5.serialize?.(n) ?? "").join("");
4350
4655
  }
4351
4656
  return runInBoundary(record.api, fn);
4352
4657
  },
@@ -4356,7 +4661,7 @@ function installHook() {
4356
4661
  }
4357
4662
  }
4358
4663
  };
4359
- state3.boundaries.push(record);
4664
+ state5.boundaries.push(record);
4360
4665
  return record.api;
4361
4666
  });
4362
4667
  }
@@ -4441,9 +4746,9 @@ async function waitFor(ready, deadline, stop2) {
4441
4746
  });
4442
4747
  }
4443
4748
  }
4444
- function pendingFor(pending, boundary) {
4445
- if (!pending) return false;
4446
- for (const work of pending) if (work.boundary === boundary) return true;
4749
+ function pendingFor(pending2, boundary) {
4750
+ if (!pending2) return false;
4751
+ for (const work of pending2) if (work.boundary === boundary) return true;
4447
4752
  return false;
4448
4753
  }
4449
4754
  function streamPage(input2, options = {}) {
@@ -4456,8 +4761,8 @@ function streamPage(input2, options = {}) {
4456
4761
  const MARK_END = "<sibu-stream-end>";
4457
4762
  void runInSSRContext(async () => {
4458
4763
  const store = getRequestStore();
4459
- const state3 = { boundaries: [], serialize: null };
4460
- requestSlot("stream", () => state3);
4764
+ const state5 = { boundaries: [], serialize: null };
4765
+ requestSlot("stream", () => state5);
4461
4766
  const errors = [];
4462
4767
  if (store) store.errors = errors;
4463
4768
  let holder = null;
@@ -4478,13 +4783,13 @@ function streamPage(input2, options = {}) {
4478
4783
  throw explainServerError(err);
4479
4784
  }
4480
4785
  const serialize = (node) => renderToStringWith(node, { marker: options.marker ?? "root", ids });
4481
- state3.serialize = serialize;
4786
+ state5.serialize = serialize;
4482
4787
  holder = document.createDocumentFragment();
4483
4788
  holder.appendChild(root);
4484
4789
  const ready = (b2) => b2.done && !pendingFor(store?.pending, b2.api);
4485
4790
  const serializeWithFallbacks = (node) => {
4486
4791
  const held = [];
4487
- for (const b2 of state3.boundaries) {
4792
+ for (const b2 of state5.boundaries) {
4488
4793
  if (ready(b2) || b2.container === node || !node.contains(b2.container)) continue;
4489
4794
  if (held.some((h) => h.b.container.contains(b2.container))) continue;
4490
4795
  const nodes = Array.from(b2.container.childNodes);
@@ -4506,9 +4811,9 @@ function streamPage(input2, options = {}) {
4506
4811
  await waitFor(() => !pendingFor(store?.pending, void 0), shellDeadline, stopWaiting);
4507
4812
  failIfErrored();
4508
4813
  if (channel.cancelled) return;
4509
- for (const b2 of state3.boundaries) {
4814
+ for (const b2 of state5.boundaries) {
4510
4815
  const inline = (x) => x.done && !pendingFor(store?.pending, x.api);
4511
- const enclosing = state3.boundaries.filter((a2) => a2 !== b2 && a2.container.contains(b2.container));
4816
+ const enclosing = state5.boundaries.filter((a2) => a2 !== b2 && a2.container.contains(b2.container));
4512
4817
  if (inline(b2) && enclosing.every(inline)) b2.emitted = true;
4513
4818
  }
4514
4819
  const shell = serializeWithFallbacks(holder);
@@ -4529,8 +4834,8 @@ function streamPage(input2, options = {}) {
4529
4834
  if (channel.cancelled) return;
4530
4835
  failIfErrored();
4531
4836
  const deadline = Date.now() + (options.timeout ?? 1e4);
4532
- const outstanding = () => state3.boundaries.filter((b2) => !b2.emitted);
4533
- const ancestorsOf = (b2) => state3.boundaries.filter((a2) => a2 !== b2 && a2.container.contains(b2.container));
4837
+ const outstanding = () => state5.boundaries.filter((b2) => !b2.emitted);
4838
+ const ancestorsOf = (b2) => state5.boundaries.filter((a2) => a2 !== b2 && a2.container.contains(b2.container));
4534
4839
  const emittable = (b2) => ready(b2) && ancestorsOf(b2).every((a2) => a2.emitted);
4535
4840
  let bodyClosed = false;
4536
4841
  for (; ; ) {
@@ -4554,7 +4859,7 @@ function streamPage(input2, options = {}) {
4554
4859
  if (channel.cancelled) return;
4555
4860
  failIfErrored();
4556
4861
  }
4557
- for (const b2 of state3.boundaries) {
4862
+ for (const b2 of state5.boundaries) {
4558
4863
  if (b2 === next || !next.container.contains(b2.container) || !ready(b2)) continue;
4559
4864
  const between2 = ancestorsOf(b2).filter((a2) => a2 !== next && next.container.contains(a2.container));
4560
4865
  if (between2.every(ready)) b2.emitted = true;
@@ -5253,12 +5558,12 @@ function escapeScriptJson(json) {
5253
5558
  }
5254
5559
  var DEFAULT_MAX_SSR_BYTES = 1024 * 1024;
5255
5560
  var SAFE_GLOBAL_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5256
- function serializeState(state3, nonce, options) {
5561
+ function serializeState(state5, nonce, options) {
5257
5562
  const globalName = options?.global ?? SSR_DATA_ATTR;
5258
5563
  if (!SAFE_GLOBAL_NAME.test(globalName)) {
5259
5564
  throw new Error(`[SibuJS SSR] serializeState: global must be an identifier (got: ${JSON.stringify(globalName)})`);
5260
5565
  }
5261
- const rawJson = JSON.stringify(state3);
5566
+ const rawJson = JSON.stringify(state5);
5262
5567
  const maxBytes = options?.maxBytes ?? DEFAULT_MAX_SSR_BYTES;
5263
5568
  const byteLen = typeof TextEncoder !== "undefined" ? new TextEncoder().encode(rawJson).byteLength : Buffer.byteLength(rawJson, "utf8");
5264
5569
  if (byteLen > maxBytes) {
@@ -5302,14 +5607,14 @@ async function settled(_root, options = {}) {
5302
5607
  const deadline = Date.now() + timeout;
5303
5608
  for (; ; ) {
5304
5609
  await macrotask2();
5305
- const pending = store?.pending;
5306
- if (!pending || pending.size === 0) {
5610
+ const pending2 = store?.pending;
5611
+ if (!pending2 || pending2.size === 0) {
5307
5612
  await macrotask2();
5308
- if (!pending || pending.size === 0) return { timedOut: false, pending: [] };
5613
+ if (!pending2 || pending2.size === 0) return { timedOut: false, pending: [] };
5309
5614
  continue;
5310
5615
  }
5311
5616
  const remaining = deadline - Date.now();
5312
- if (remaining <= 0) return { timedOut: true, pending: describePending(pending) };
5617
+ if (remaining <= 0) return { timedOut: true, pending: describePending(pending2) };
5313
5618
  await new Promise((resolve) => {
5314
5619
  const done = () => {
5315
5620
  clearTimeout(timer);
@@ -5321,9 +5626,9 @@ async function settled(_root, options = {}) {
5321
5626
  });
5322
5627
  }
5323
5628
  }
5324
- function describePending(pending) {
5629
+ function describePending(pending2) {
5325
5630
  const now = Date.now();
5326
- return Array.from(pending, (work) => `${work.label} (${now - work.since} ms)`);
5631
+ return Array.from(pending2, (work) => `${work.label} (${now - work.since} ms)`);
5327
5632
  }
5328
5633
  function formatRenderDiagnostics(d, label2 = "render") {
5329
5634
  const lines = [
@@ -5451,7 +5756,7 @@ async function renderCore(input2, options) {
5451
5756
  releaseTree();
5452
5757
  throw err;
5453
5758
  }
5454
- let state3 = "";
5759
+ let state5 = "";
5455
5760
  let stateData = null;
5456
5761
  let stateBytes = 0;
5457
5762
  let largestState = [];
@@ -5460,7 +5765,7 @@ async function renderCore(input2, options) {
5460
5765
  const collected = collectTransfer();
5461
5766
  if (collected) {
5462
5767
  const built = buildTransfer(collected, options.maxStateBytes ?? DEFAULT_TRANSFER_MAX_BYTES, options.nonce);
5463
- state3 = built.script;
5768
+ state5 = built.script;
5464
5769
  stateData = built.data;
5465
5770
  stateBytes = built.bytes;
5466
5771
  largestState = built.largest;
@@ -5481,7 +5786,7 @@ async function renderCore(input2, options) {
5481
5786
  if (DEV && options.log) {
5482
5787
  console.info(formatRenderDiagnostics(diagnostics, typeof options.log === "string" ? options.log : void 0));
5483
5788
  }
5484
- return { content, result: { head: head2, state: state3, stateData, status: 200, diagnostics } };
5789
+ return { content, result: { head: head2, state: state5, stateData, status: 200, diagnostics } };
5485
5790
  }
5486
5791
  function inRequest(api, fn) {
5487
5792
  try {
@@ -6025,12 +6330,12 @@ async function hydrateAdopt(component, container, options = {}) {
6025
6330
  inScope(rootScope, () => session.place(container, tree));
6026
6331
  }
6027
6332
  const deadline = Date.now() + (options.timeout ?? 1e4);
6028
- const { pending, wake } = hydration;
6333
+ const { pending: pending2, wake } = hydration;
6029
6334
  for (; ; ) {
6030
6335
  await macrotask3();
6031
- if (pending.size === 0) {
6336
+ if (pending2.size === 0) {
6032
6337
  await macrotask3();
6033
- if (pending.size === 0) break;
6338
+ if (pending2.size === 0) break;
6034
6339
  continue;
6035
6340
  }
6036
6341
  const remaining = deadline - Date.now();
@@ -6179,7 +6484,7 @@ var isBatching = API2.isBatching;
6179
6484
  // src/core/signals/signal.ts
6180
6485
  var _g2 = globalThis;
6181
6486
  function signal(initial, options) {
6182
- const state3 = {
6487
+ const state5 = {
6183
6488
  value: initial,
6184
6489
  __v: 0,
6185
6490
  __sc: 0,
@@ -6192,57 +6497,57 @@ function signal(initial, options) {
6192
6497
  };
6193
6498
  const debugName = DEV ? options?.name : void 0;
6194
6499
  const equalsFn = options?.equals;
6195
- if (debugName) state3.__name = debugName;
6500
+ if (debugName) state5.__name = debugName;
6196
6501
  function get() {
6197
- recordDependency2(state3);
6198
- return state3.value;
6502
+ recordDependency2(state5);
6503
+ return state5.value;
6199
6504
  }
6200
- get.__signal = state3;
6505
+ get.__signal = state5;
6201
6506
  if (debugName) get.__name = debugName;
6202
6507
  let set;
6203
6508
  if (equalsFn) {
6204
6509
  set = (next) => {
6205
- const prev = state3.value;
6510
+ const prev = state5.value;
6206
6511
  const newValue = typeof next === "function" ? next(prev) : next;
6207
6512
  if (equalsFn(prev, newValue)) return;
6208
- state3.value = newValue;
6209
- state3.__v++;
6513
+ state5.value = newValue;
6514
+ state5.__v++;
6210
6515
  if (DEV) {
6211
6516
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
6212
- if (hook) emitDevtools(hook, "signal:update", { signal: state3, name: debugName, oldValue: prev, newValue });
6517
+ if (hook) emitDevtools(hook, "signal:update", { signal: state5, name: debugName, oldValue: prev, newValue });
6213
6518
  }
6214
- if (!enqueueBatchedSignal(state3)) {
6215
- notifySubscribers2(state3);
6519
+ if (!enqueueBatchedSignal(state5)) {
6520
+ notifySubscribers2(state5);
6216
6521
  }
6217
6522
  };
6218
6523
  } else if (DEV) {
6219
6524
  set = (next) => {
6220
- const prev = state3.value;
6525
+ const prev = state5.value;
6221
6526
  const newValue = typeof next === "function" ? next(prev) : next;
6222
6527
  if (Object.is(newValue, prev)) return;
6223
- state3.value = newValue;
6224
- state3.__v++;
6528
+ state5.value = newValue;
6529
+ state5.__v++;
6225
6530
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
6226
- if (hook) emitDevtools(hook, "signal:update", { signal: state3, name: debugName, oldValue: prev, newValue });
6227
- if (!enqueueBatchedSignal(state3)) {
6228
- notifySubscribers2(state3);
6531
+ if (hook) emitDevtools(hook, "signal:update", { signal: state5, name: debugName, oldValue: prev, newValue });
6532
+ if (!enqueueBatchedSignal(state5)) {
6533
+ notifySubscribers2(state5);
6229
6534
  }
6230
6535
  };
6231
6536
  } else {
6232
6537
  set = (next) => {
6233
- const prev = state3.value;
6538
+ const prev = state5.value;
6234
6539
  const newValue = typeof next === "function" ? next(prev) : next;
6235
6540
  if (Object.is(newValue, prev)) return;
6236
- state3.value = newValue;
6237
- state3.__v++;
6238
- if (!enqueueBatchedSignal(state3)) {
6239
- notifySubscribers2(state3);
6541
+ state5.value = newValue;
6542
+ state5.__v++;
6543
+ if (!enqueueBatchedSignal(state5)) {
6544
+ notifySubscribers2(state5);
6240
6545
  }
6241
6546
  };
6242
6547
  }
6243
6548
  if (DEV) {
6244
6549
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
6245
- if (hook) emitDevtools(hook, "signal:create", { signal: state3, name: debugName, getter: get, initial });
6550
+ if (hook) emitDevtools(hook, "signal:create", { signal: state5, name: debugName, getter: get, initial });
6246
6551
  }
6247
6552
  return [get, set];
6248
6553
  }
@@ -6381,8 +6686,8 @@ function commitSafeAttribute(el, name, value, options) {
6381
6686
  else el.removeAttribute(name);
6382
6687
  return false;
6383
6688
  }
6384
- const pending = value == null || value === false ? null : value === true ? "" : String(value);
6385
- const refusal = contextualAttributeRefusal(el, name, pending, options.reactive ? "reactive" : "runtime");
6689
+ const pending2 = value == null || value === false ? null : value === true ? "" : String(value);
6690
+ const refusal = contextualAttributeRefusal(el, name, pending2, options.reactive ? "reactive" : "runtime");
6386
6691
  if (refusal !== ContextualRefusal.None) {
6387
6692
  warnContextualRefusal(options.label ?? "setSafeAttribute", name, refusal);
6388
6693
  if (ns) el.removeAttributeNS(ns, localName);
@@ -6540,7 +6845,7 @@ function restoreFocusWithin(snapshot, nodes, where, policy) {
6540
6845
  const active = document.activeElement;
6541
6846
  if (active === snapshot.el) return;
6542
6847
  if (active && active !== document.body && active !== document.documentElement) return;
6543
- if (snapshot.el.isConnected) {
6848
+ if (snapshot.el.isConnected && !snapshot.el.closest("[inert]")) {
6544
6849
  refocus(snapshot.el, snapshot);
6545
6850
  return;
6546
6851
  }
@@ -6567,8 +6872,78 @@ function restoreFocusWithin(snapshot, nodes, where, policy) {
6567
6872
  });
6568
6873
  }
6569
6874
 
6875
+ // src/core/rendering/range.ts
6876
+ var state4 = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.ranges.v1"), () => ({
6877
+ ends: /* @__PURE__ */ new WeakMap(),
6878
+ pending: /* @__PURE__ */ new WeakMap(),
6879
+ registrations: /* @__PURE__ */ new Set(),
6880
+ listeners: /* @__PURE__ */ new Set(),
6881
+ notice: { queued: false, batch: [] }
6882
+ }));
6883
+ var ends = state4.ends;
6884
+ function registerRange(start, last) {
6885
+ ends.set(start, last);
6886
+ }
6887
+ var pending = state4.pending;
6888
+ var NOTHING = () => {
6889
+ };
6890
+ var registrations = state4.registrations;
6891
+ var loadListeners = state4.listeners;
6892
+ var notice = state4.notice;
6893
+ function notifyLoad(settled2) {
6894
+ if (loadListeners.size === 0) return;
6895
+ if (settled2 !== null) notice.batch.push(settled2);
6896
+ if (notice.queued) return;
6897
+ notice.queued = true;
6898
+ queueMicrotask(() => {
6899
+ notice.queued = false;
6900
+ const batch2 = notice.batch;
6901
+ notice.batch = [];
6902
+ for (const listener of [...loadListeners]) listener(batch2);
6903
+ });
6904
+ }
6905
+ function beginPending(at, held) {
6906
+ const entry = { at, held, settled: false, cancelled: false, committed: null };
6907
+ registrations.add(entry);
6908
+ notifyLoad(null);
6909
+ const settle = (cancelled, committed) => {
6910
+ if (entry.settled) return;
6911
+ entry.settled = true;
6912
+ entry.cancelled = cancelled;
6913
+ entry.committed = committed;
6914
+ registrations.delete(entry);
6915
+ notifyLoad(entry);
6916
+ };
6917
+ return {
6918
+ entry,
6919
+ done: (committed) => settle(false, committed ?? null),
6920
+ cancel: () => settle(true, null)
6921
+ };
6922
+ }
6923
+ var INERT = { done: NOTHING, cancel: NOTHING };
6924
+ function beginLoading(anchor) {
6925
+ if (isServer()) return INERT;
6926
+ const { done, cancel } = beginPending(anchor, null);
6927
+ return { done: () => done(), cancel };
6928
+ }
6929
+ function registerNodesRange(anchor, nodes) {
6930
+ registerRange(anchor, () => {
6931
+ const parent = anchor.parentNode;
6932
+ const wanted = nodes().filter((n) => n !== null && n.parentNode === parent);
6933
+ let last = null;
6934
+ let left = wanted.length;
6935
+ for (let n = anchor.nextSibling; n !== null && left > 0; n = n.nextSibling) {
6936
+ if (wanted.includes(n)) {
6937
+ last = n;
6938
+ left--;
6939
+ }
6940
+ }
6941
+ return last;
6942
+ });
6943
+ }
6944
+
6570
6945
  // src/reactivity/bindChildNode.ts
6571
- function bindChildNode(placeholder, getter) {
6946
+ function bindChildNode(placeholder, getter, exposeNodes) {
6572
6947
  let lastNodes = [];
6573
6948
  const scope = captureScope();
6574
6949
  function commit() {
@@ -6639,6 +7014,12 @@ function bindChildNode(placeholder, getter) {
6639
7014
  lastNodes = newNodes;
6640
7015
  restoreFocusWithin(focused, newNodes, "bindChildNode");
6641
7016
  }
7017
+ if (exposeNodes) {
7018
+ registerRange(placeholder, () => {
7019
+ for (let i2 = lastNodes.length - 1; i2 >= 0; i2--) if (lastNodes[i2].parentNode !== null) return lastNodes[i2];
7020
+ return null;
7021
+ });
7022
+ }
6642
7023
  return reactiveBinding2(commit, placeholder, true);
6643
7024
  }
6644
7025
 
@@ -6667,14 +7048,6 @@ var CLOBBER_RISKY_IDS = /* @__PURE__ */ new Set([
6667
7048
  var warnedLoneStrings = /* @__PURE__ */ new Set();
6668
7049
  var MAX_WARNED_LONE_STRINGS = 100;
6669
7050
  var loneStringCapAnnounced = false;
6670
- var kebabCache = /* @__PURE__ */ new Map();
6671
- function toKebab2(prop) {
6672
- let cached = kebabCache.get(prop);
6673
- if (cached !== void 0) return cached;
6674
- cached = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
6675
- kebabCache.set(prop, cached);
6676
- return cached;
6677
- }
6678
7051
  function applyStyle(el, style2) {
6679
7052
  if (typeof style2 === "function") {
6680
7053
  const getter = style2;
@@ -6698,7 +7071,7 @@ function applyStyle(el, style2) {
6698
7071
  if (!Object.hasOwn(value, prop)) continue;
6699
7072
  const val = value[prop];
6700
7073
  if (val == null) continue;
6701
- const name = toKebab2(prop);
7074
+ const name = styleKeyToProperty(prop);
6702
7075
  next.push(name);
6703
7076
  decl.setProperty(name, sanitizeCSSDeclaration(name, String(val), { element: el }));
6704
7077
  }
@@ -6718,7 +7091,7 @@ function applyStyle(el, style2) {
6718
7091
  for (const prop in style2) {
6719
7092
  if (!Object.hasOwn(style2, prop)) continue;
6720
7093
  const val = style2[prop];
6721
- const name = toKebab2(prop);
7094
+ const name = styleKeyToProperty(prop);
6722
7095
  if (typeof val === "function") {
6723
7096
  const getter = val;
6724
7097
  const teardown = reactiveBinding2(() => {
@@ -7341,8 +7714,8 @@ function scrollRestoration(options) {
7341
7714
  nativeModeLease = acquireScrollRestorationMode("manual");
7342
7715
  if (currentKey !== null) tagCurrentEntry(currentKey);
7343
7716
  popstateHandler = (event) => {
7344
- const state3 = event.state ?? null;
7345
- const rawDestination = state3 ? state3[stateKey] : void 0;
7717
+ const state5 = event.state ?? null;
7718
+ const rawDestination = state5 ? state5[stateKey] : void 0;
7346
7719
  const destination = typeof rawDestination === "string" ? rawDestination : null;
7347
7720
  let outgoing = currentKey;
7348
7721
  if (outgoing === null && options?.getKey) {
@@ -7495,6 +7868,63 @@ function serviceWorker(scriptUrl, options) {
7495
7868
  return { registration, isReady, isUpdateAvailable, error, update, unregister };
7496
7869
  }
7497
7870
 
7871
+ // src/core/rendering/heldCommit.ts
7872
+ var NOOP2 = () => {
7873
+ };
7874
+ function commitWhenActive(slot4, c) {
7875
+ let over = false;
7876
+ let unhold = null;
7877
+ let drop = NOOP2;
7878
+ const finish = () => {
7879
+ over = true;
7880
+ if (slot4.cancel === cancel) slot4.cancel = NOOP2;
7881
+ drop();
7882
+ drop = NOOP2;
7883
+ };
7884
+ const cancel = () => {
7885
+ if (over) return;
7886
+ finish();
7887
+ const release = unhold;
7888
+ unhold = null;
7889
+ try {
7890
+ c.discard();
7891
+ } finally {
7892
+ release?.();
7893
+ }
7894
+ };
7895
+ const attempt = () => {
7896
+ drop = NOOP2;
7897
+ let clean = false;
7898
+ while (!over) {
7899
+ const state5 = c.held.state();
7900
+ if (state5 === 2 || c.owned !== void 0 && !c.owned()) {
7901
+ cancel();
7902
+ return;
7903
+ }
7904
+ if (state5 === 1) {
7905
+ if (c.node !== null && unhold === null) unhold = holdSubtree2(c.node);
7906
+ drop = c.held.wait(attempt, attempt);
7907
+ return;
7908
+ }
7909
+ if (unhold !== null) {
7910
+ const release = unhold;
7911
+ unhold = null;
7912
+ release();
7913
+ continue;
7914
+ }
7915
+ if (!clean) {
7916
+ clean = c.teardown?.() !== true;
7917
+ continue;
7918
+ }
7919
+ finish();
7920
+ c.insert();
7921
+ return;
7922
+ }
7923
+ };
7924
+ slot4.cancel = cancel;
7925
+ attempt();
7926
+ }
7927
+
7498
7928
  // src/utils/prerenderHook.ts
7499
7929
  var HOST_KEY = /* @__PURE__ */ Symbol.for("sibujs.prerender.v1");
7500
7930
  function host() {
@@ -8320,15 +8750,15 @@ var _ComponentLoader = class _ComponentLoader {
8320
8750
  const cached = this.planCache.get(cacheKey);
8321
8751
  if (cached && cached.kind === "factory") return cached.component;
8322
8752
  this.assertNotHot(cacheKey);
8323
- let pending = this.moduleLoads.get(cacheKey);
8324
- const owner = pending === void 0;
8325
- if (pending === void 0) {
8326
- pending = plan.load();
8327
- this.moduleLoads.set(cacheKey, pending);
8753
+ let pending2 = this.moduleLoads.get(cacheKey);
8754
+ const owner = pending2 === void 0;
8755
+ if (pending2 === void 0) {
8756
+ pending2 = plan.load();
8757
+ this.moduleLoads.set(cacheKey, pending2);
8328
8758
  }
8329
8759
  let resolved;
8330
8760
  try {
8331
- resolved = await pending;
8761
+ resolved = await pending2;
8332
8762
  } catch (error) {
8333
8763
  this.noteError(cacheKey);
8334
8764
  throw error;
@@ -8350,7 +8780,14 @@ var _ComponentLoader = class _ComponentLoader {
8350
8780
  * is a configuration error, not something to chase.
8351
8781
  */
8352
8782
  async instantiateFactory(component, route2, routePath, scope, depth = 0) {
8353
- const build = () => scope ? runWithOwnerScope2(scope, component) : component();
8783
+ const gate = scope?.gate;
8784
+ if (gate) {
8785
+ while (gate.held()) if (!await gate.until()) throw gate.cancellation();
8786
+ if (scope?.current?.() === false) throw gate.cancellation();
8787
+ }
8788
+ const owner = scope?.owner;
8789
+ const invoke = () => scope ? runWithOwnerScope2(scope, component) : component();
8790
+ const build = owner ? () => owner.run(invoke) : invoke;
8354
8791
  const result = scope?.adopt ? inScope(scope.adopt, build) : build();
8355
8792
  const value = this.isThenable(result) ? await result : result;
8356
8793
  if (this.isElement(value)) return value;
@@ -8559,7 +8996,7 @@ var _SibuRouter = class _SibuRouter {
8559
8996
  return this.loadedPromise;
8560
8997
  }
8561
8998
  createInitialRoute() {
8562
- return {
8999
+ const route2 = {
8563
9000
  path: "/",
8564
9001
  params: {},
8565
9002
  query: {},
@@ -8568,6 +9005,8 @@ var _SibuRouter = class _SibuRouter {
8568
9005
  meta: {},
8569
9006
  matched: []
8570
9007
  };
9008
+ bootstrapRoutes.add(route2);
9009
+ return route2;
8571
9010
  }
8572
9011
  handleLocationChange(skipHistory = true, initialResolution = false) {
8573
9012
  const path2 = this.getCurrentPath();
@@ -8608,8 +9047,31 @@ var _SibuRouter = class _SibuRouter {
8608
9047
  matched
8609
9048
  };
8610
9049
  }
9050
+ /**
9051
+ * Once no navigation is in flight: if the route is still the placeholder
9052
+ * the router started with — every navigation that could have replaced it
9053
+ * was cancelled by a guard, failed, or was a duplicate — that IS the
9054
+ * outcome, and the outlets that rendered nothing for it settle (see
9055
+ * `settleEmpty`). Checked when a navigation has definitively completed,
9056
+ * never from `isReady` (set before the guards run). A navigation still
9057
+ * pending — a newer one, or a guard that never resolves — keeps them
9058
+ * pending; an outlet's enter is bounded by its own deadline then.
9059
+ */
9060
+ settleBootstrap() {
9061
+ if (this.destroyed || this.navigator.isNavigating) return;
9062
+ const current2 = untracked2(() => this.currentRouteGetter());
9063
+ if (!bootstrapRoutes.delete(current2)) return;
9064
+ const waiting = bootstrapWaiters.get(current2);
9065
+ bootstrapWaiters.delete(current2);
9066
+ if (waiting) for (const settle of waiting) settle();
9067
+ }
8611
9068
  // Public API
8612
9069
  async navigate(to, options = {}) {
9070
+ const result = await this.attemptNavigation(to, options);
9071
+ this.settleBootstrap();
9072
+ return result;
9073
+ }
9074
+ async attemptNavigation(to, options) {
8613
9075
  try {
8614
9076
  await this.navigator.navigate(async (signal2) => {
8615
9077
  const targetPath = this.resolvePath(to);
@@ -8863,6 +9325,13 @@ var _SibuRouter = class _SibuRouter {
8863
9325
  /**
8864
9326
  * Create exactly one real instance from an already-resolved plan. With a
8865
9327
  * `scope`, the factory runs in it (see `RouteScope`).
9328
+ *
9329
+ * When the scope belongs to an outlet whose branch is paused (playing a
9330
+ * leave it may still be taken back from), a lazy module that resolves does
9331
+ * not run its factory yet: the promise stays pending and continues once the
9332
+ * branch resumes. If the branch ends, or the outlet's pass was superseded
9333
+ * meanwhile, it rejects with a `DOMException` named `"AbortError"`. Genuine
9334
+ * loader and component failures reject with their own error, as before.
8866
9335
  */
8867
9336
  async instantiateComponent(plan, route2, routePath, scope) {
8868
9337
  return prerenderWait(this.loader.instantiate(plan, route2, routePath, scope), `router:render ${route2.path}`);
@@ -9107,6 +9576,21 @@ var RouteScope = class {
9107
9576
  constructor(route2) {
9108
9577
  /** Creation scope the instance is built in (adopting hydration); see `adoptScope`. */
9109
9578
  this.adopt = null;
9579
+ /**
9580
+ * The outlet's pause gate: while the branch holding the outlet is paused (it
9581
+ * began a leave and may still be taken back), a lazy module that resolves
9582
+ * does not get its factory invoked yet; instantiation waits for the branch
9583
+ * to resume, and is cancelled if it ends.
9584
+ */
9585
+ this.gate = null;
9586
+ /** Whether the outlet pass this instance is for is still the current one. */
9587
+ this.current = null;
9588
+ /**
9589
+ * The instance's structural owner, nested under the outlet's: its factory
9590
+ * runs as it, so what it creates is paused with the branch holding the
9591
+ * outlet, and ends (`lifecycleScope()` work included) with the instance.
9592
+ */
9593
+ this.owner = null;
9110
9594
  this.released = false;
9111
9595
  const [get, set] = signal(route2);
9112
9596
  this.get = get;
@@ -9133,6 +9617,112 @@ var RouteScope = class {
9133
9617
  queueMicrotask(() => this.set(null));
9134
9618
  }
9135
9619
  };
9620
+ var NOOP3 = () => {
9621
+ };
9622
+ var bootstrapRoutes = /* @__PURE__ */ new WeakSet();
9623
+ var bootstrapWaiters = /* @__PURE__ */ new WeakMap();
9624
+ function settleEmpty(route2, loaded, current2) {
9625
+ if (!bootstrapRoutes.has(route2)) {
9626
+ loaded.done();
9627
+ return;
9628
+ }
9629
+ let waiting = bootstrapWaiters.get(route2);
9630
+ if (waiting === void 0) bootstrapWaiters.set(route2, waiting = /* @__PURE__ */ new Set());
9631
+ waiting.add(() => {
9632
+ if (current2()) loaded.done();
9633
+ });
9634
+ }
9635
+ var cancellations = /* @__PURE__ */ new WeakSet();
9636
+ function pauseGate(frozen) {
9637
+ let closed = false;
9638
+ const pending2 = /* @__PURE__ */ new Set();
9639
+ return {
9640
+ held: () => closed || frozen(),
9641
+ until: () => {
9642
+ if (closed) return Promise.resolve(false);
9643
+ return new Promise((resolve) => {
9644
+ const settle = (active) => {
9645
+ pending2.delete(cancel);
9646
+ resolve(active && !closed);
9647
+ };
9648
+ const drop = frozen.wait(
9649
+ () => settle(true),
9650
+ () => settle(false)
9651
+ );
9652
+ const cancel = () => {
9653
+ drop();
9654
+ settle(false);
9655
+ };
9656
+ pending2.add(cancel);
9657
+ });
9658
+ },
9659
+ cancellation: () => {
9660
+ const error = new DOMException("Route instantiation cancelled: its branch was released", "AbortError");
9661
+ cancellations.add(error);
9662
+ return error;
9663
+ },
9664
+ close: () => {
9665
+ closed = true;
9666
+ for (const cancel of [...pending2]) cancel();
9667
+ },
9668
+ run: frozen.run,
9669
+ frozen,
9670
+ closed: () => closed,
9671
+ onClose: (fn) => {
9672
+ pending2.add(fn);
9673
+ return () => {
9674
+ pending2.delete(fn);
9675
+ };
9676
+ }
9677
+ };
9678
+ }
9679
+ function whenActive(gate, fn) {
9680
+ if (!gate.held()) fn();
9681
+ else
9682
+ void gate.until().then((active) => {
9683
+ if (active) whenActive(gate, fn);
9684
+ });
9685
+ }
9686
+ function commitPass(gate, c) {
9687
+ const frozen = gate.frozen;
9688
+ const held = {
9689
+ state: frozen.state,
9690
+ wait: (onActive, onEnd) => {
9691
+ let live = true;
9692
+ const later = (fn) => () => {
9693
+ void Promise.resolve().then(() => {
9694
+ if (live) fn();
9695
+ });
9696
+ };
9697
+ const drop = frozen.wait(later(onActive), later(onEnd));
9698
+ return () => {
9699
+ live = false;
9700
+ drop();
9701
+ };
9702
+ }
9703
+ };
9704
+ return new Promise((resolve, reject) => {
9705
+ const slot4 = { cancel: NOOP3 };
9706
+ const untrack = gate.onClose(() => slot4.cancel());
9707
+ const settle = (fn) => () => {
9708
+ untrack();
9709
+ try {
9710
+ fn();
9711
+ resolve();
9712
+ } catch (error) {
9713
+ reject(error);
9714
+ }
9715
+ };
9716
+ commitWhenActive(slot4, {
9717
+ held,
9718
+ node: c.node,
9719
+ owned: () => !gate.closed() && c.owned(),
9720
+ teardown: c.teardown,
9721
+ insert: settle(c.insert),
9722
+ discard: settle(c.discard)
9723
+ });
9724
+ });
9725
+ }
9136
9726
  function activeRouteScope() {
9137
9727
  const scope = getOwnerScope2();
9138
9728
  return scope instanceof RouteScope ? scope : null;
@@ -9146,14 +9736,27 @@ function scopedRoute(router) {
9146
9736
  return router.currentRoute;
9147
9737
  }
9148
9738
  var instanceScopes = /* @__PURE__ */ new WeakMap();
9149
- async function instantiateScoped(router, plan, routeDef, routePath, route2, adopt = null) {
9739
+ async function instantiateScoped(router, plan, routeDef, routePath, route2, adopt = null, gate = null, current2 = null) {
9150
9740
  const scope = new RouteScope(route2);
9151
9741
  scope.adopt = adopt;
9152
- const node = await router.instantiateComponent(plan, routeDef, routePath, scope);
9742
+ scope.gate = gate;
9743
+ scope.current = current2;
9744
+ const owner = gate ? gate.run(() => structuralBinding2(NOOP3)) : structuralBinding2(NOOP3);
9745
+ scope.owner = owner;
9746
+ let node;
9747
+ try {
9748
+ node = await router.instantiateComponent(plan, routeDef, routePath, scope);
9749
+ } catch (error) {
9750
+ owner.stop();
9751
+ throw error;
9752
+ }
9153
9753
  if (node) {
9154
9754
  instanceScopes.set(node, scope);
9155
- registerDisposer(node, () => scope.release());
9156
- }
9755
+ registerDisposer(node, () => {
9756
+ owner.stop();
9757
+ scope.release();
9758
+ });
9759
+ } else owner.stop();
9157
9760
  return node;
9158
9761
  }
9159
9762
  function updateInstanceRoute(node, route2) {
@@ -9196,6 +9799,8 @@ function instanceKey(owner, records, route2) {
9196
9799
  function Route() {
9197
9800
  const anchor = document.createComment("route-outlet");
9198
9801
  const adoptScope = captureScope();
9802
+ const frozen = captureFrozen2();
9803
+ const gate = pauseGate(frozen);
9199
9804
  let currentNode = null;
9200
9805
  let loadingNode = null;
9201
9806
  let errorNode = null;
@@ -9203,6 +9808,7 @@ function Route() {
9203
9808
  let currentTopRoute = null;
9204
9809
  let currentKey = null;
9205
9810
  let routeTorn = false;
9811
+ const loaded = beginLoading(anchor);
9206
9812
  const commitTarget = (seq) => routeTorn || seq !== navSeq ? null : anchor.parentNode;
9207
9813
  const retryIfDetached = (seq) => {
9208
9814
  if (!routeTorn && seq === navSeq && !anchor.parentNode) attachWait.request();
@@ -9247,24 +9853,54 @@ function Route() {
9247
9853
  loadingNode = null;
9248
9854
  }
9249
9855
  };
9250
- const showError = (error, routeDef) => {
9856
+ const showError = (seq, error, routeDef) => {
9251
9857
  if (!anchor.parentNode) return;
9252
- cleanupNodes();
9253
- errorNode = document.createElement("div");
9254
- errorNode.className = "route-error";
9255
- errorNode.setAttribute("role", "alert");
9256
- errorNode.setAttribute("aria-live", "assertive");
9858
+ const view = errorView(error, routeDef);
9859
+ void commitPass(gate, {
9860
+ node: view,
9861
+ owned: () => !routeTorn && seq === navSeq,
9862
+ discard: () => dispose(view),
9863
+ teardown: () => {
9864
+ if (!anchor.parentNode || !(currentNode || loadingNode || errorNode)) return false;
9865
+ cleanupNodes();
9866
+ return true;
9867
+ },
9868
+ insert: () => {
9869
+ const parent = anchor.parentNode;
9870
+ if (!parent) {
9871
+ dispose(view);
9872
+ unshownFailure = { seq, error, routeDef };
9873
+ attachWait.request();
9874
+ return;
9875
+ }
9876
+ errorNode = view;
9877
+ try {
9878
+ parent.insertBefore(view, anchor.nextSibling);
9879
+ } catch (err) {
9880
+ if (errorNode === view) errorNode = null;
9881
+ release(view);
9882
+ throw err;
9883
+ }
9884
+ if (!routeTorn && seq === navSeq) loaded.done();
9885
+ }
9886
+ }).catch((err) => console.error("[Route] Error view failed:", err));
9887
+ };
9888
+ const errorView = (error, routeDef) => {
9889
+ const errorNode2 = document.createElement("div");
9890
+ errorNode2.className = "route-error";
9891
+ errorNode2.setAttribute("role", "alert");
9892
+ errorNode2.setAttribute("aria-live", "assertive");
9257
9893
  if (routeDef && "component" in routeDef) {
9258
9894
  const src = routeDef.component.toString();
9259
9895
  const importMatch = src.match(/import\(["']([^"']+)["']\)/);
9260
9896
  if (importMatch) {
9261
- errorNode.setAttribute("data-component-source", importMatch[1]);
9897
+ errorNode2.setAttribute("data-component-source", importMatch[1]);
9262
9898
  }
9263
9899
  if (routeDef.component.name) {
9264
- errorNode.setAttribute("data-component-name", routeDef.component.name);
9900
+ errorNode2.setAttribute("data-component-name", routeDef.component.name);
9265
9901
  }
9266
9902
  }
9267
- errorNode.__routeError = error;
9903
+ errorNode2.__routeError = error;
9268
9904
  const title2 = document.createElement("h3");
9269
9905
  title2.textContent = "Route Error";
9270
9906
  title2.className = "route-error-title";
@@ -9283,10 +9919,10 @@ function Route() {
9283
9919
  };
9284
9920
  retryButton.addEventListener("click", onRetryClick);
9285
9921
  registerDisposer(retryButton, () => retryButton.removeEventListener("click", onRetryClick));
9286
- errorNode.appendChild(title2);
9287
- errorNode.appendChild(message);
9288
- errorNode.appendChild(retryButton);
9289
- anchor.parentNode.insertBefore(errorNode, anchor.nextSibling);
9922
+ errorNode2.appendChild(title2);
9923
+ errorNode2.appendChild(message);
9924
+ errorNode2.appendChild(retryButton);
9925
+ return errorNode2;
9290
9926
  };
9291
9927
  const update = async () => {
9292
9928
  routerRevision();
@@ -9299,12 +9935,14 @@ function Route() {
9299
9935
  currentTopRoute = null;
9300
9936
  currentKey = null;
9301
9937
  cleanupNodes();
9938
+ settleEmpty(route2, loaded, () => !routeTorn && seq === navSeq);
9302
9939
  return;
9303
9940
  }
9304
9941
  const routeDef = match.matched[0] || match.route;
9305
9942
  const key = instanceKey(routeDef, [routeDef], route2);
9306
9943
  if (routeDef === currentTopRoute && key === currentKey && currentNode) {
9307
9944
  updateInstanceRoute(currentNode, route2);
9945
+ loaded.done();
9308
9946
  return;
9309
9947
  }
9310
9948
  if ("redirect" in routeDef) {
@@ -9323,6 +9961,7 @@ function Route() {
9323
9961
  showLoading();
9324
9962
  }
9325
9963
  const plan = await _routerRef.current.loadPlan(routeDef, route2.path);
9964
+ while (gate.held()) if (!await gate.until()) return;
9326
9965
  if (!commitTarget(seq)) {
9327
9966
  retryIfDetached(seq);
9328
9967
  return;
@@ -9333,28 +9972,57 @@ function Route() {
9333
9972
  routeDef,
9334
9973
  route2.path,
9335
9974
  route2,
9336
- keyedScope(adoptScope, routeDef.path)
9975
+ keyedScope(adoptScope, routeDef.path),
9976
+ gate,
9977
+ () => commitTarget(seq) !== null
9337
9978
  );
9338
- const parent = commitTarget(seq);
9339
- if (!parent) {
9340
- release(node);
9341
- retryIfDetached(seq);
9342
- return;
9343
- }
9344
- if (node) {
9345
- currentTopRoute = routeDef;
9346
- currentKey = key;
9347
- cleanupNodes();
9348
- parent.insertBefore(node, anchor.nextSibling);
9349
- currentNode = node;
9350
- }
9979
+ await commitPass(gate, {
9980
+ node,
9981
+ owned: () => !routeTorn && seq === navSeq,
9982
+ discard: () => release(node),
9983
+ // The outgoing views go first — only when there is a page to
9984
+ // show, and a parent to show it in.
9985
+ teardown: () => {
9986
+ if (!node || !anchor.parentNode || !(currentNode || loadingNode || errorNode)) return false;
9987
+ cleanupNodes();
9988
+ return true;
9989
+ },
9990
+ insert: () => {
9991
+ const parent = commitTarget(seq);
9992
+ if (!parent) {
9993
+ release(node);
9994
+ retryIfDetached(seq);
9995
+ return;
9996
+ }
9997
+ if (node) {
9998
+ currentTopRoute = routeDef;
9999
+ currentKey = key;
10000
+ currentNode = node;
10001
+ try {
10002
+ parent.insertBefore(node, anchor.nextSibling);
10003
+ } catch (error) {
10004
+ if (currentNode === node) {
10005
+ currentNode = null;
10006
+ currentTopRoute = null;
10007
+ currentKey = null;
10008
+ }
10009
+ release(node);
10010
+ throw error;
10011
+ }
10012
+ }
10013
+ if (!routeTorn && seq === navSeq) loaded.done();
10014
+ }
10015
+ });
9351
10016
  } catch (error) {
10017
+ if (cancellations.has(error)) return;
9352
10018
  if (routeTorn || seq !== navSeq) return;
9353
- hideLoading();
9354
10019
  console.error("[Route] Component error:", error);
10020
+ while (gate.held()) if (!await gate.until()) return;
10021
+ if (routeTorn || seq !== navSeq) return;
10022
+ hideLoading();
9355
10023
  fail(seq, error, routeDef);
9356
10024
  }
9357
- }
10025
+ } else settleEmpty(route2, loaded, () => !routeTorn && seq === navSeq);
9358
10026
  } catch (error) {
9359
10027
  if (seq !== navSeq) return;
9360
10028
  if (routeTorn) return;
@@ -9366,16 +10034,20 @@ function Route() {
9366
10034
  const fail = (seq, error, routeDef) => {
9367
10035
  const err = error instanceof Error ? error : new Error(String(error));
9368
10036
  if (anchor.parentNode) {
9369
- showError(err, routeDef);
10037
+ showError(seq, err, routeDef);
9370
10038
  return;
9371
10039
  }
9372
10040
  unshownFailure = { seq, error: err, routeDef };
9373
10041
  attachWait.request();
9374
10042
  };
9375
10043
  const onAttached = () => {
10044
+ if (gate.held()) {
10045
+ void gate.until().then((active) => active && onAttached());
10046
+ return;
10047
+ }
9376
10048
  const failure = unshownFailure;
9377
10049
  unshownFailure = null;
9378
- if (failure && failure.seq === navSeq) showError(failure.error, failure.routeDef);
10050
+ if (failure && failure.seq === navSeq) showError(failure.seq, failure.error, failure.routeDef);
9379
10051
  else update();
9380
10052
  };
9381
10053
  let routeInitialized = false;
@@ -9385,11 +10057,16 @@ function Route() {
9385
10057
  routeInitialized = true;
9386
10058
  };
9387
10059
  const attachWait = attachRetry(anchor, onAttached);
9388
- const routeTeardown = track2(wrappedUpdate);
10060
+ const routeTeardown = reactiveBinding2(wrappedUpdate, anchor);
9389
10061
  if (!routeInitialized) {
9390
10062
  queueMicrotask(
9391
10063
  bindOwnerScope2(() => {
9392
- if (!routeInitialized && anchor.parentNode) wrappedUpdate();
10064
+ whenActive(
10065
+ gate,
10066
+ bindOwnerScope2(() => {
10067
+ if (!routeInitialized && anchor.parentNode) wrappedUpdate();
10068
+ })
10069
+ );
9393
10070
  })
9394
10071
  );
9395
10072
  }
@@ -9397,6 +10074,8 @@ function Route() {
9397
10074
  if (routeTorn) return;
9398
10075
  routeTorn = true;
9399
10076
  navSeq++;
10077
+ gate.close();
10078
+ loaded.cancel();
9400
10079
  routeTeardown();
9401
10080
  attachWait.cancel();
9402
10081
  unshownFailure = null;
@@ -9404,6 +10083,7 @@ function Route() {
9404
10083
  currentTopRoute = null;
9405
10084
  currentKey = null;
9406
10085
  };
10086
+ registerNodesRange(anchor, () => [currentNode, loadingNode, errorNode]);
9407
10087
  registerDisposer(anchor, routeCleanup);
9408
10088
  routeCleanups.push(routeCleanup);
9409
10089
  return anchor;
@@ -9480,17 +10160,17 @@ function renderRoute(routes, url, options = {}) {
9480
10160
  const started = Date.now();
9481
10161
  const deadline = started + (options.timeout ?? DEFAULT_SETTLE_TIMEOUT);
9482
10162
  const router = createRouter(routes, { ...options.router, mode: "memory", url });
9483
- const wrap = (body2, headHtml, state3) => options.document ? assembleDocument(body2, options.document, headHtml, state3) : body2;
10163
+ const wrap = (body2, headHtml, state5) => options.document ? assembleDocument(body2, options.document, headHtml, state5) : body2;
9484
10164
  const timedOut = (phase) => {
9485
10165
  const now = Date.now();
9486
- const pending = [
10166
+ const pending2 = [
9487
10167
  `${phase} (${now - started} ms)`,
9488
10168
  ...Array.from(getRequestStore()?.pending ?? [], (work) => `${work.label} (${now - work.since} ms)`)
9489
10169
  ];
9490
- const diagnostics = { ...emptyDiagnostics(), timedOut: true, pending, durationMs: now - started };
10170
+ const diagnostics = { ...emptyDiagnostics(), timedOut: true, pending: pending2, durationMs: now - started };
9491
10171
  if (DEV) {
9492
10172
  console.warn(
9493
- `[SibuJS SSR] ${url}: the route did not render within ${options.timeout ?? DEFAULT_SETTLE_TIMEOUT} ms; pending: ${pending.join(", ")}`
10173
+ `[SibuJS SSR] ${url}: the route did not render within ${options.timeout ?? DEFAULT_SETTLE_TIMEOUT} ms; pending: ${pending2.join(", ")}`
9494
10174
  );
9495
10175
  }
9496
10176
  return {
@@ -9621,12 +10301,12 @@ function defaultCacheControl(result) {
9621
10301
  return "no-store";
9622
10302
  }
9623
10303
  function createRenderHandler(routes, options = {}) {
9624
- const { cache, cacheControl = defaultCacheControl, ...renderOptions } = options;
10304
+ const { cache: cache2, cacheControl = defaultCacheControl, ...renderOptions } = options;
9625
10305
  const document2 = renderOptions.document ?? {};
9626
- const store = cache ? /* @__PURE__ */ new Map() : null;
9627
- const max = cache?.max ?? 500;
9628
- const ttl = cache?.ttl ?? 6e4;
9629
- const maxBytes = cache?.maxBytes ?? 32 * 1024 * 1024;
10306
+ const store = cache2 ? /* @__PURE__ */ new Map() : null;
10307
+ const max = cache2?.max ?? 500;
10308
+ const ttl = cache2?.ttl ?? 6e4;
10309
+ const maxBytes = cache2?.maxBytes ?? 32 * 1024 * 1024;
9630
10310
  let cachedBytes = 0;
9631
10311
  const evict = (key) => {
9632
10312
  const entry = store?.get(key);
@@ -9645,7 +10325,7 @@ function createRenderHandler(routes, options = {}) {
9645
10325
  }
9646
10326
  const url = new URL(request.url);
9647
10327
  const path2 = url.pathname + url.search;
9648
- const key = store ? `${cache?.version?.() ?? ""}\0${path2}` : "";
10328
+ const key = store ? `${cache2?.version?.() ?? ""}\0${path2}` : "";
9649
10329
  const head2 = method === "HEAD";
9650
10330
  if (store) {
9651
10331
  const hit = store.get(key);
@@ -9785,16 +10465,16 @@ async function loadWasmModuleWithOptions(source2, opts = {}) {
9785
10465
  if (cachedInstance) return cachedInstance;
9786
10466
  const inFlight = inFlightCache.get(key);
9787
10467
  if (inFlight) return inFlight;
9788
- const pending = instantiateWasm(source2, opts.imports, key, generation).then((instance) => {
10468
+ const pending2 = instantiateWasm(source2, opts.imports, key, generation).then((instance) => {
9789
10469
  if (isCurrentGeneration(generation)) instanceCache.set(key, instance);
9790
10470
  return instance;
9791
10471
  });
9792
- inFlightCache.set(key, pending);
9793
- void pending.catch(() => {
10472
+ inFlightCache.set(key, pending2);
10473
+ void pending2.catch(() => {
9794
10474
  }).then(() => {
9795
- if (inFlightCache.get(key) === pending) inFlightCache.delete(key);
10475
+ if (inFlightCache.get(key) === pending2) inFlightCache.delete(key);
9796
10476
  });
9797
- return pending;
10477
+ return pending2;
9798
10478
  }
9799
10479
  async function instantiateWasm(source2, wasmImports, key, generation) {
9800
10480
  const cachedModule = key ? moduleCache2.get(key) : void 0;