sibujs 4.8.0 → 4.10.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 (66) hide show
  1. package/dist/browser.cjs +44 -6
  2. package/dist/browser.d.cts +3 -2
  3. package/dist/browser.d.ts +3 -2
  4. package/dist/browser.js +4 -4
  5. package/dist/build.cjs +128 -56
  6. package/dist/build.js +10 -10
  7. package/dist/cdn.dev.global.js +14 -14
  8. package/dist/cdn.full.dev.global.js +13 -13
  9. package/dist/cdn.full.global.js +12 -12
  10. package/dist/cdn.global.js +15 -15
  11. package/dist/{chunk-J3YQ457H.js → chunk-2NWHJ2UJ.js} +99 -61
  12. package/dist/{chunk-JUTFX2RM.js → chunk-4DCVJ4YA.js} +42 -15
  13. package/dist/{chunk-QGMSESDD.js → chunk-54F4TPHK.js} +2 -2
  14. package/dist/{chunk-KJ3UKABJ.js → chunk-5PC7OTQW.js} +1 -1
  15. package/dist/{chunk-V3LHZSU5.js → chunk-7WIHYHWD.js} +8 -1
  16. package/dist/{chunk-44MTL7ED.js → chunk-BMCR7TXG.js} +3 -3
  17. package/dist/{chunk-TQQUN4WR.js → chunk-D6HYFOWR.js} +39 -4
  18. package/dist/{chunk-VWT3VXPL.js → chunk-EVI4ZQO3.js} +2 -2
  19. package/dist/{chunk-CZPRSWSS.js → chunk-EVOK663Z.js} +1 -1
  20. package/dist/{chunk-DSID757X.js → chunk-FYUEL5IW.js} +1 -1
  21. package/dist/{chunk-UCNP3HVM.js → chunk-GMMDHJJT.js} +30 -12
  22. package/dist/{chunk-C7AA2CZX.js → chunk-GOL3FU5Q.js} +1 -1
  23. package/dist/{chunk-EGUQLBHE.js → chunk-GTS35FLA.js} +5 -4
  24. package/dist/{chunk-GSGNX35Q.js → chunk-IFRIBZ4O.js} +4 -4
  25. package/dist/{chunk-C5PEWEGH.js → chunk-IL5MMSCL.js} +19 -12
  26. package/dist/{chunk-ZVLHNEEL.js → chunk-ITEL5KPL.js} +6 -6
  27. package/dist/{chunk-RGLPEBDE.js → chunk-JCKUWWHU.js} +3 -3
  28. package/dist/{chunk-Q5J2LVKH.js → chunk-N6U4GOIU.js} +1 -1
  29. package/dist/{chunk-LI4W3U6C.js → chunk-TOPRMXFY.js} +1 -1
  30. package/dist/{chunk-4WMSTZ7J.js → chunk-VWPMWV7O.js} +4 -4
  31. package/dist/{chunk-O6TRVMJI.js → chunk-XUQUQJYE.js} +1 -1
  32. package/dist/data.cjs +67 -12
  33. package/dist/data.d.cts +32 -5
  34. package/dist/data.d.ts +32 -5
  35. package/dist/data.js +5 -5
  36. package/dist/devtools.cjs +41 -4
  37. package/dist/devtools.js +4 -4
  38. package/dist/ecosystem.cjs +41 -4
  39. package/dist/ecosystem.js +7 -7
  40. package/dist/extras.cjs +125 -41
  41. package/dist/extras.js +20 -20
  42. package/dist/index.cjs +128 -56
  43. package/dist/index.d.cts +22 -0
  44. package/dist/index.d.ts +22 -0
  45. package/dist/index.js +10 -10
  46. package/dist/motion.cjs +36 -4
  47. package/dist/motion.js +3 -3
  48. package/dist/patterns.cjs +41 -4
  49. package/dist/patterns.js +5 -5
  50. package/dist/performance.cjs +55 -14
  51. package/dist/performance.js +4 -4
  52. package/dist/plugins.cjs +176 -60
  53. package/dist/plugins.d.cts +62 -2
  54. package/dist/plugins.d.ts +62 -2
  55. package/dist/plugins.js +143 -61
  56. package/dist/ssr.cjs +77 -16
  57. package/dist/ssr.d.cts +4 -0
  58. package/dist/ssr.d.ts +4 -0
  59. package/dist/ssr.js +7 -7
  60. package/dist/testing.cjs +41 -4
  61. package/dist/testing.js +2 -2
  62. package/dist/ui.cjs +42 -5
  63. package/dist/ui.js +7 -7
  64. package/dist/widgets.cjs +36 -4
  65. package/dist/widgets.js +6 -6
  66. package/package.json +1 -1
@@ -135,44 +135,44 @@ import {
135
135
  use,
136
136
  var_,
137
137
  video
138
- } from "./chunk-Q5J2LVKH.js";
138
+ } from "./chunk-N6U4GOIU.js";
139
139
  import {
140
140
  trustHTML
141
141
  } from "./chunk-FC6KCJSA.js";
142
142
  import {
143
143
  watch
144
- } from "./chunk-CZPRSWSS.js";
144
+ } from "./chunk-EVOK663Z.js";
145
145
  import {
146
146
  __resetIdCounter,
147
147
  createId,
148
148
  domBinding
149
- } from "./chunk-C7AA2CZX.js";
149
+ } from "./chunk-GOL3FU5Q.js";
150
150
  import {
151
151
  SVG_NS,
152
152
  bindChildNode,
153
153
  captureFocusWithin,
154
154
  restoreFocusWithin,
155
155
  tagFactory
156
- } from "./chunk-VWT3VXPL.js";
156
+ } from "./chunk-EVI4ZQO3.js";
157
157
  import {
158
158
  bindAttribute,
159
159
  bindDynamic,
160
160
  setSafeAttribute,
161
161
  setTrustedAttribute
162
- } from "./chunk-O6TRVMJI.js";
162
+ } from "./chunk-XUQUQJYE.js";
163
163
  import {
164
164
  isCodeTextElement
165
165
  } from "./chunk-3ACAAQIN.js";
166
166
  import {
167
167
  derived
168
- } from "./chunk-KJ3UKABJ.js";
168
+ } from "./chunk-5PC7OTQW.js";
169
169
  import {
170
170
  globalSingleton
171
171
  } from "./chunk-7ZHH77QA.js";
172
172
  import {
173
173
  effect,
174
174
  on
175
- } from "./chunk-V3LHZSU5.js";
175
+ } from "./chunk-7WIHYHWD.js";
176
176
  import {
177
177
  disableSSR,
178
178
  enableSSR,
@@ -191,19 +191,22 @@ import {
191
191
  external,
192
192
  isBatching,
193
193
  signal
194
- } from "./chunk-DSID757X.js";
194
+ } from "./chunk-FYUEL5IW.js";
195
195
  import {
196
+ bindOwnerScope,
196
197
  emitDevtools,
198
+ getOwnerScope,
197
199
  notifySubscribers,
198
200
  reactiveBinding,
199
201
  recordDependency,
200
202
  resumeTracking,
201
203
  retrack,
204
+ runWithOwnerScope,
202
205
  setMaxDrainIterations,
203
206
  suspendTracking,
204
207
  track,
205
208
  untracked
206
- } from "./chunk-TQQUN4WR.js";
209
+ } from "./chunk-D6HYFOWR.js";
207
210
  import {
208
211
  DEV,
209
212
  MAX_DRAIN_TEARDOWNS,
@@ -487,12 +490,16 @@ function lazy(importFn) {
487
490
  }
488
491
  const container = div({ class: "sibu-lazy" });
489
492
  let disposed = false;
490
- importFn().then((mod) => {
491
- if (disposed) return;
492
- cached = mod.default;
493
- const rendered = cached();
494
- replaceChildrenSafely(container, rendered);
495
- }).catch((err) => {
493
+ importFn().then(
494
+ // The component renders after the import resolves, in the owner scope
495
+ // of whoever rendered the placeholder.
496
+ bindOwnerScope((mod) => {
497
+ if (disposed) return;
498
+ cached = mod.default;
499
+ const rendered = cached();
500
+ replaceChildrenSafely(container, rendered);
501
+ })
502
+ ).catch((err) => {
496
503
  if (disposed) return;
497
504
  const errorObj = err instanceof Error ? err : new Error(String(err));
498
505
  replaceChildrenSafely(
@@ -523,7 +530,7 @@ function Suspense({ nodes, fallback }) {
523
530
  }
524
531
  if (childEl && !container.contains(childEl)) dispose(childEl);
525
532
  });
526
- queueMicrotask(() => {
533
+ const renderContent = bindOwnerScope(() => {
527
534
  if (suspenseDisposed) return;
528
535
  try {
529
536
  const el = nodes();
@@ -551,10 +558,14 @@ function Suspense({ nodes, fallback }) {
551
558
  dispatchPropagate(container, errorObj);
552
559
  }
553
560
  });
561
+ queueMicrotask(renderContent);
554
562
  return container;
555
563
  }
556
564
 
557
565
  // src/core/rendering/lifecycle.ts
566
+ function pinScope(scope, fn) {
567
+ return () => getOwnerScope() === scope ? fn() : runWithOwnerScope(scope, fn);
568
+ }
558
569
  function safeCall(cb, hookName) {
559
570
  try {
560
571
  return cb();
@@ -564,13 +575,14 @@ function safeCall(cb, hookName) {
564
575
  return void 0;
565
576
  }
566
577
  }
567
- function runMountCallback(callback, hookName, element, isDisposed) {
568
- const cleanup = safeCall(callback, hookName);
569
- if (typeof cleanup !== "function") return;
578
+ function runMountCallback(callback, hookName, element, isDisposed, scope) {
579
+ const returned = safeCall(callback, hookName);
580
+ if (typeof returned !== "function") return;
581
+ const cleanup = pinScope(scope, returned);
570
582
  if (isDisposed() || !element.isConnected) {
571
583
  safeCall(cleanup, "onUnmount");
572
584
  } else {
573
- onUnmount(cleanup, element);
585
+ watchUnmount(cleanup, element);
574
586
  }
575
587
  }
576
588
  var mountWatchers = /* @__PURE__ */ new WeakMap();
@@ -730,6 +742,8 @@ function registerUnmountWatcher(element, cb) {
730
742
  }
731
743
  function onMount(callback, element) {
732
744
  if (typeof document === "undefined") return;
745
+ const scope = getOwnerScope();
746
+ callback = pinScope(scope, callback);
733
747
  if (element) {
734
748
  let disposed = false;
735
749
  const isDisposed = () => disposed;
@@ -739,19 +753,19 @@ function onMount(callback, element) {
739
753
  if (element.isConnected) {
740
754
  queueMicrotask(() => {
741
755
  if (disposed) return;
742
- runMountCallback(callback, "onMount", element, isDisposed);
756
+ runMountCallback(callback, "onMount", element, isDisposed, scope);
743
757
  });
744
758
  return;
745
759
  }
746
760
  queueMicrotask(() => {
747
761
  if (disposed) return;
748
762
  if (element.isConnected) {
749
- runMountCallback(callback, "onMount", element, isDisposed);
763
+ runMountCallback(callback, "onMount", element, isDisposed, scope);
750
764
  return;
751
765
  }
752
766
  const unregister = registerMountWatcher(element, () => {
753
767
  if (disposed) return;
754
- runMountCallback(callback, "onMount", element, isDisposed);
768
+ runMountCallback(callback, "onMount", element, isDisposed, scope);
755
769
  });
756
770
  registerDisposer(element, unregister);
757
771
  });
@@ -763,6 +777,9 @@ function onMount(callback, element) {
763
777
  }
764
778
  function onUnmount(callback, element) {
765
779
  if (typeof document === "undefined") return;
780
+ watchUnmount(pinScope(getOwnerScope(), callback), element);
781
+ }
782
+ function watchUnmount(callback, element) {
766
783
  let fired = false;
767
784
  const fireOnce = () => {
768
785
  if (fired) return;
@@ -1463,11 +1480,15 @@ function ErrorBoundary(optionsOrChildren, maybeChildren) {
1463
1480
  return;
1464
1481
  }
1465
1482
  replaceChildrenSafely(asyncContainer, el);
1466
- }).catch((e) => {
1467
- if (asyncDisposed) return;
1468
- const err = handleError(e);
1469
- replaceChildrenSafely(asyncContainer, tryRenderFallback(err));
1470
- });
1483
+ }).catch(
1484
+ // The fallback is rendered later, in the owner scope of the
1485
+ // render that produced the async child.
1486
+ bindOwnerScope((e) => {
1487
+ if (asyncDisposed) return;
1488
+ const err = handleError(e);
1489
+ replaceChildrenSafely(asyncContainer, tryRenderFallback(err));
1490
+ })
1491
+ );
1471
1492
  return asyncContainer;
1472
1493
  }
1473
1494
  return result;
@@ -1637,37 +1658,44 @@ function action(element, action2, param2) {
1637
1658
  }
1638
1659
  }
1639
1660
  var clickOutside = (element, callback) => {
1661
+ const doc = element.ownerDocument;
1640
1662
  const handler = (e) => {
1641
- if (!element.contains(e.target)) {
1642
- callback();
1643
- }
1663
+ const target = e.target;
1664
+ if (!(typeof target?.nodeType === "number" && element.contains(target))) callback();
1644
1665
  };
1645
- document.addEventListener("pointerdown", handler, true);
1646
- return () => document.removeEventListener("pointerdown", handler, true);
1666
+ doc.addEventListener("pointerdown", handler, true);
1667
+ return () => doc.removeEventListener("pointerdown", handler, true);
1647
1668
  };
1669
+ var PRESS_END_EVENTS = ["pointerup", "pointerleave", "pointercancel"];
1648
1670
  var longPress = (element, options) => {
1649
1671
  const duration = options.duration ?? 500;
1650
1672
  let timer = null;
1651
- const start = () => {
1652
- timer = setTimeout(() => {
1653
- options.callback();
1654
- timer = null;
1655
- }, duration);
1656
- };
1673
+ let owner;
1657
1674
  const cancel = () => {
1658
1675
  if (timer !== null) {
1659
1676
  clearTimeout(timer);
1660
1677
  timer = null;
1661
1678
  }
1662
1679
  };
1680
+ const start = (e) => {
1681
+ const id = e.pointerId;
1682
+ if (timer !== null && id !== owner) return;
1683
+ cancel();
1684
+ owner = id;
1685
+ timer = setTimeout(() => {
1686
+ timer = null;
1687
+ options.callback();
1688
+ }, duration);
1689
+ };
1690
+ const end = (e) => {
1691
+ if (timer !== null && e.pointerId === owner) cancel();
1692
+ };
1663
1693
  element.addEventListener("pointerdown", start);
1664
- element.addEventListener("pointerup", cancel);
1665
- element.addEventListener("pointerleave", cancel);
1694
+ for (const type of PRESS_END_EVENTS) element.addEventListener(type, end);
1666
1695
  return () => {
1667
1696
  cancel();
1668
1697
  element.removeEventListener("pointerdown", start);
1669
- element.removeEventListener("pointerup", cancel);
1670
- element.removeEventListener("pointerleave", cancel);
1698
+ for (const type of PRESS_END_EVENTS) element.removeEventListener(type, end);
1671
1699
  };
1672
1700
  };
1673
1701
  var copyOnClick = (element, getText) => {
@@ -1701,10 +1729,11 @@ var trapFocus = (element) => {
1701
1729
  if (elements.length === 0) return;
1702
1730
  const first = elements[0];
1703
1731
  const last = elements[elements.length - 1];
1704
- if (e.shiftKey && document.activeElement === first) {
1732
+ const active = element.ownerDocument.activeElement;
1733
+ if (e.shiftKey && active === first) {
1705
1734
  e.preventDefault();
1706
1735
  last.focus();
1707
- } else if (!e.shiftKey && document.activeElement === last) {
1736
+ } else if (!e.shiftKey && active === last) {
1708
1737
  e.preventDefault();
1709
1738
  first.focus();
1710
1739
  }
@@ -1875,9 +1904,11 @@ function when(condition, thenBranch, elseBranch) {
1875
1904
  currentNode = null;
1876
1905
  });
1877
1906
  if (!initialized) {
1878
- queueMicrotask(() => {
1879
- if (!disposed && !initialized && anchor.parentNode) update();
1880
- });
1907
+ queueMicrotask(
1908
+ bindOwnerScope(() => {
1909
+ if (!disposed && !initialized && anchor.parentNode) update();
1910
+ })
1911
+ );
1881
1912
  }
1882
1913
  return anchor;
1883
1914
  }
@@ -1916,9 +1947,11 @@ function match(value, cases, fallback) {
1916
1947
  currentNode = null;
1917
1948
  });
1918
1949
  if (!initialized) {
1919
- queueMicrotask(() => {
1920
- if (!disposed && !initialized && anchor.parentNode) update();
1921
- });
1950
+ queueMicrotask(
1951
+ bindOwnerScope(() => {
1952
+ if (!disposed && !initialized && anchor.parentNode) update();
1953
+ })
1954
+ );
1922
1955
  }
1923
1956
  return anchor;
1924
1957
  }
@@ -2210,11 +2243,13 @@ function each(getArray, render, options) {
2210
2243
  };
2211
2244
  registerDisposer(anchor, disposeRange);
2212
2245
  if (!initialized) {
2213
- queueMicrotask(() => {
2214
- if (!initialized && !rangeDisposed && anchor.parentNode) {
2215
- update();
2216
- }
2217
- });
2246
+ queueMicrotask(
2247
+ bindOwnerScope(() => {
2248
+ if (!initialized && !rangeDisposed && anchor.parentNode) {
2249
+ update();
2250
+ }
2251
+ })
2252
+ );
2218
2253
  }
2219
2254
  return anchor;
2220
2255
  }
@@ -2662,7 +2697,7 @@ function KeepAlive(activeKey, cases, options) {
2662
2697
  return;
2663
2698
  }
2664
2699
  node = factory();
2665
- if (node instanceof DocumentFragment) {
2700
+ if (node.nodeType === 11) {
2666
2701
  const wrapper = document.createElement("div");
2667
2702
  wrapper.style.display = "contents";
2668
2703
  wrapper.appendChild(node);
@@ -2692,9 +2727,11 @@ function KeepAlive(activeKey, cases, options) {
2692
2727
  };
2693
2728
  const untrack = track(update);
2694
2729
  if (!initialized) {
2695
- queueMicrotask(() => {
2696
- if (!initialized && anchor.parentNode) update();
2697
- });
2730
+ queueMicrotask(
2731
+ bindOwnerScope(() => {
2732
+ if (!initialized && anchor.parentNode) update();
2733
+ })
2734
+ );
2698
2735
  }
2699
2736
  registerDisposer(anchor, () => {
2700
2737
  disposed = true;
@@ -2799,7 +2836,7 @@ function Portal(nodes, target) {
2799
2836
  const container = target || document.body;
2800
2837
  let portalContent = null;
2801
2838
  let disposed = false;
2802
- queueMicrotask(() => {
2839
+ const renderContent = bindOwnerScope(() => {
2803
2840
  if (disposed) return;
2804
2841
  try {
2805
2842
  portalContent = nodes();
@@ -2814,6 +2851,7 @@ function Portal(nodes, target) {
2814
2851
  });
2815
2852
  }
2816
2853
  });
2854
+ queueMicrotask(renderContent);
2817
2855
  registerDisposer(anchor, () => {
2818
2856
  disposed = true;
2819
2857
  if (portalContent) {
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  div,
8
8
  span
9
- } from "./chunk-Q5J2LVKH.js";
9
+ } from "./chunk-N6U4GOIU.js";
10
10
  import {
11
11
  STATIC_VALUE_RESOLVER,
12
12
  planHeadElementEntry,
@@ -17,14 +17,17 @@ import {
17
17
  } from "./chunk-7ZHH77QA.js";
18
18
  import {
19
19
  effect
20
- } from "./chunk-V3LHZSU5.js";
20
+ } from "./chunk-7WIHYHWD.js";
21
21
  import {
22
22
  sanitizeUrl
23
23
  } from "./chunk-EXXSN3BW.js";
24
24
  import {
25
25
  batch,
26
26
  signal
27
- } from "./chunk-DSID757X.js";
27
+ } from "./chunk-FYUEL5IW.js";
28
+ import {
29
+ bindOwnerScope
30
+ } from "./chunk-D6HYFOWR.js";
28
31
  import {
29
32
  registerDisposer,
30
33
  replaceChildrenSafely,
@@ -686,11 +689,15 @@ function defineRemoteComponent(name, loader) {
686
689
  registerDisposer(container, () => {
687
690
  disposed = true;
688
691
  });
689
- loader().then((mod) => {
690
- cached = mod.default;
691
- if (disposed) return;
692
- replaceChildrenSafely(container, cached());
693
- }).catch((err) => {
692
+ loader().then(
693
+ // Instantiated after the module resolves, in the owner scope of the
694
+ // render that asked for it — as `lazy()` does.
695
+ bindOwnerScope((mod) => {
696
+ cached = mod.default;
697
+ if (disposed) return;
698
+ replaceChildrenSafely(container, cached());
699
+ })
700
+ ).catch((err) => {
694
701
  if (disposed) return;
695
702
  const message = err instanceof Error ? err.message : String(err);
696
703
  replaceChildrenSafely(
@@ -910,7 +917,7 @@ function createISR(options) {
910
917
  const [data, setData] = signal(initialData);
911
918
  const [stale, setStale] = signal(initialData === void 0);
912
919
  const controller = new AbortController();
913
- let inFlight = false;
920
+ let inFlight = null;
914
921
  let disposed = false;
915
922
  let deadline;
916
923
  const clearDeadline = () => {
@@ -930,10 +937,7 @@ function createISR(options) {
930
937
  });
931
938
  }, revalidateAfter);
932
939
  };
933
- const revalidate = async () => {
934
- if (disposed || inFlight) return;
935
- if (controller.signal.aborted) return;
936
- inFlight = true;
940
+ const run = async () => {
937
941
  try {
938
942
  const result = await fetcher({ signal: controller.signal });
939
943
  if (disposed || controller.signal.aborted) return;
@@ -945,10 +949,33 @@ function createISR(options) {
945
949
  } catch (err) {
946
950
  if (!disposed && !controller.signal.aborted) armDeadline();
947
951
  throw err;
948
- } finally {
949
- inFlight = false;
950
952
  }
951
953
  };
954
+ const revalidate = () => {
955
+ if (disposed || controller.signal.aborted) return Promise.resolve();
956
+ if (inFlight) return inFlight;
957
+ let resolve;
958
+ let reject;
959
+ const current = new Promise((res, rej) => {
960
+ resolve = res;
961
+ reject = rej;
962
+ });
963
+ inFlight = current;
964
+ const release = () => {
965
+ if (inFlight === current) inFlight = null;
966
+ };
967
+ run().then(
968
+ () => {
969
+ release();
970
+ resolve();
971
+ },
972
+ (err) => {
973
+ release();
974
+ reject(err);
975
+ }
976
+ );
977
+ return current;
978
+ };
952
979
  if (initialData === void 0) {
953
980
  revalidate().catch((err) => {
954
981
  if (typeof console !== "undefined") console.warn("[SibuJS ISR] initial fetch failed", err);
@@ -170,7 +170,7 @@ var CDN_ENTRY_POINTS = {
170
170
  };
171
171
  var packageInfo = {
172
172
  name: "sibujs",
173
- version: true ? "4.8.0" : "dev",
173
+ version: true ? "4.10.0" : "dev",
174
174
  entryPoints: MODULE_ENTRY_POINTS,
175
175
  /**
176
176
  * Generate the package.json `exports` map. Module entries resolve to the
@@ -315,7 +315,7 @@ var env = {
315
315
  };
316
316
 
317
317
  // src/plugins/versioning.ts
318
- var VERSION = true ? "4.8.0" : "dev";
318
+ var VERSION = true ? "4.10.0" : "dev";
319
319
  var NUM = "(?:0|[1-9]\\d*)";
320
320
  var PRE_ID = `(?:${NUM}|\\d*[a-zA-Z-][0-9a-zA-Z-]*)`;
321
321
  var BUILD_ID = "[0-9a-zA-Z-]+";
@@ -5,7 +5,7 @@ import {
5
5
  recordDependency,
6
6
  retrack,
7
7
  track
8
- } from "./chunk-TQQUN4WR.js";
8
+ } from "./chunk-D6HYFOWR.js";
9
9
  import {
10
10
  devAssert
11
11
  } from "./chunk-NYNYSPK7.js";
@@ -4,9 +4,11 @@ import {
4
4
  import {
5
5
  cleanup,
6
6
  emitDevtools,
7
+ getOwnerScope,
7
8
  retrack,
9
+ runWithOwnerScope,
8
10
  untracked
9
- } from "./chunk-TQQUN4WR.js";
11
+ } from "./chunk-D6HYFOWR.js";
10
12
  import {
11
13
  devAssert,
12
14
  reportError
@@ -35,6 +37,11 @@ function flushUserCleanups(ctx) {
35
37
  const list = ctx.userCleanups;
36
38
  if (list.length === 0) return;
37
39
  ctx.userCleanups = [];
40
+ const scope = ctx.subscriber._scope ?? null;
41
+ if (scope === getOwnerScope()) runCleanups(list);
42
+ else runWithOwnerScope(scope, () => runCleanups(list));
43
+ }
44
+ function runCleanups(list) {
38
45
  for (let i = list.length - 1; i >= 0; i--) {
39
46
  try {
40
47
  list[i]();
@@ -3,18 +3,18 @@ import {
3
3
  } from "./chunk-7ZHH77QA.js";
4
4
  import {
5
5
  effect
6
- } from "./chunk-V3LHZSU5.js";
6
+ } from "./chunk-7WIHYHWD.js";
7
7
  import {
8
8
  stripHtml
9
9
  } from "./chunk-EXXSN3BW.js";
10
10
  import {
11
11
  signal
12
- } from "./chunk-DSID757X.js";
12
+ } from "./chunk-FYUEL5IW.js";
13
13
  import {
14
14
  forEachSubscriber,
15
15
  getSubscriberCount,
16
16
  getSubscriberDeps
17
- } from "./chunk-TQQUN4WR.js";
17
+ } from "./chunk-D6HYFOWR.js";
18
18
  import {
19
19
  dispose,
20
20
  isDev
@@ -151,6 +151,24 @@ function untracked(fn) {
151
151
  resumeTracking();
152
152
  }
153
153
  }
154
+ var currentOwnerScope = null;
155
+ function getOwnerScope() {
156
+ return currentOwnerScope;
157
+ }
158
+ function runWithOwnerScope(scope, fn) {
159
+ const prev = currentOwnerScope;
160
+ currentOwnerScope = scope;
161
+ try {
162
+ return fn();
163
+ } finally {
164
+ currentOwnerScope = prev;
165
+ }
166
+ }
167
+ function bindOwnerScope(fn) {
168
+ const scope = currentOwnerScope;
169
+ if (scope === null) return fn;
170
+ return (...args) => runWithOwnerScope(scope, () => fn(...args));
171
+ }
154
172
  var subscriberEpochCounter = 0;
155
173
  function retrack(effectFn, subscriber) {
156
174
  const prev = currentSubscriber;
@@ -166,6 +184,10 @@ function retrack(effectFn, subscriber) {
166
184
  currentSubscriber = subscriber;
167
185
  const sub = subscriber;
168
186
  if (sub._cap === void 0) sub._cap = currentDisposerCapture();
187
+ const prevScope = currentOwnerScope;
188
+ if (prevScope !== null && !sub._epoch && sub._scope === void 0) sub._scope = prevScope;
189
+ const scope = sub._scope === void 0 ? null : sub._scope;
190
+ if (scope !== prevScope) currentOwnerScope = scope;
169
191
  const epoch = ++subscriberEpochCounter;
170
192
  sub._epoch = epoch;
171
193
  sub._structDirty = false;
@@ -178,6 +200,7 @@ function retrack(effectFn, subscriber) {
178
200
  effectFn();
179
201
  } finally {
180
202
  currentSubscriber = prev;
203
+ currentOwnerScope = prevScope;
181
204
  if (savedDepth !== 0) {
182
205
  suspendDepth = savedDepth;
183
206
  suspendSavedSub = savedSuspendSub;
@@ -212,23 +235,26 @@ function track(effectFn, subscriber) {
212
235
  trackingSuspended = false;
213
236
  }
214
237
  currentSubscriber = subscriber;
238
+ const sub = subscriber;
239
+ if (sub._scope === void 0) sub._scope = currentOwnerScope;
240
+ const prevScope = currentOwnerScope;
241
+ currentOwnerScope = sub._scope;
215
242
  try {
216
243
  effectFn();
217
244
  } finally {
218
245
  currentSubscriber = prev;
246
+ currentOwnerScope = prevScope;
219
247
  if (savedDepth !== 0) {
220
248
  suspendDepth = savedDepth;
221
249
  suspendSavedSub = savedSuspendSub;
222
250
  trackingSuspended = true;
223
251
  }
224
- const sub2 = subscriber;
225
- for (let n = sub2.depsHead ?? null; n !== null; n = n.subNext) {
252
+ for (let n = sub.depsHead ?? null; n !== null; n = n.subNext) {
226
253
  const sig = n.sig;
227
254
  sig.__activeNode = n.prevActive;
228
255
  n.prevActive = null;
229
256
  }
230
257
  }
231
- const sub = subscriber;
232
258
  return sub._dispose ?? (sub._dispose = () => cleanup(subscriber));
233
259
  }
234
260
  function reactiveBinding(commit, ownerNode) {
@@ -498,7 +524,7 @@ function forEachSubscriber(signal, visit) {
498
524
  }
499
525
 
500
526
  // src/reactivity/track.ts
501
- var _runtimeVersion = true ? "4.8.0" : "dev";
527
+ var _runtimeVersion = true ? "4.10.0" : "dev";
502
528
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
503
529
  function resolveReactiveApi() {
504
530
  const g = globalThis;
@@ -530,6 +556,9 @@ function resolveReactiveApi() {
530
556
  getSubscriberCount,
531
557
  getSubscriberDeps,
532
558
  forEachSubscriber,
559
+ getOwnerScope,
560
+ runWithOwnerScope,
561
+ bindOwnerScope,
533
562
  version: _runtimeVersion
534
563
  };
535
564
  g[REGISTRY_KEY] = local;
@@ -553,6 +582,9 @@ var notifySubscribers2 = API.notifySubscribers;
553
582
  var getSubscriberCount2 = API.getSubscriberCount;
554
583
  var getSubscriberDeps2 = API.getSubscriberDeps;
555
584
  var forEachSubscriber2 = API.forEachSubscriber;
585
+ var getOwnerScope2 = API.getOwnerScope ?? getOwnerScope;
586
+ var runWithOwnerScope2 = API.runWithOwnerScope ?? runWithOwnerScope;
587
+ var bindOwnerScope2 = API.bindOwnerScope ?? bindOwnerScope;
556
588
 
557
589
  // src/core/devtoolsHook.ts
558
590
  function emitDevtools(hook, event, payload) {
@@ -579,5 +611,8 @@ export {
579
611
  getSubscriberCount2 as getSubscriberCount,
580
612
  getSubscriberDeps2 as getSubscriberDeps,
581
613
  forEachSubscriber2 as forEachSubscriber,
614
+ getOwnerScope2 as getOwnerScope,
615
+ runWithOwnerScope2 as runWithOwnerScope,
616
+ bindOwnerScope2 as bindOwnerScope,
582
617
  emitDevtools
583
618
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  bindAttribute,
3
3
  setSafeAttribute
4
- } from "./chunk-O6TRVMJI.js";
4
+ } from "./chunk-XUQUQJYE.js";
5
5
  import {
6
6
  isBlockedElement
7
7
  } from "./chunk-3ACAAQIN.js";
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-EXXSN3BW.js";
13
13
  import {
14
14
  reactiveBinding
15
- } from "./chunk-TQQUN4WR.js";
15
+ } from "./chunk-D6HYFOWR.js";
16
16
  import {
17
17
  DEV,
18
18
  devWarn,
@@ -5,7 +5,7 @@ import {
5
5
  resumeTracking,
6
6
  suspendTracking,
7
7
  track
8
- } from "./chunk-TQQUN4WR.js";
8
+ } from "./chunk-D6HYFOWR.js";
9
9
  import {
10
10
  devAssert
11
11
  } from "./chunk-NYNYSPK7.js";