sibujs 3.2.2 → 3.3.1

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 (60) hide show
  1. package/dist/browser.cjs +217 -27
  2. package/dist/browser.js +5 -5
  3. package/dist/build.cjs +236 -105
  4. package/dist/build.js +14 -14
  5. package/dist/cdn.global.js +7 -7
  6. package/dist/{chunk-5N74TKLD.js → chunk-37BUKSLH.js} +1 -1
  7. package/dist/{chunk-BGNLPNGV.js → chunk-4UUMSLSL.js} +4 -4
  8. package/dist/{chunk-2UPRY23K.js → chunk-5VGSK6D2.js} +1 -1
  9. package/dist/{chunk-OYLPZO4N.js → chunk-6LTFHJQG.js} +4 -4
  10. package/dist/{chunk-VOCE4NNK.js → chunk-AMIKDMLP.js} +5 -5
  11. package/dist/{chunk-LMLD24FC.js → chunk-COY6PUD2.js} +7 -1
  12. package/dist/{chunk-YFDGQWDA.js → chunk-F7FXQ3QS.js} +1 -1
  13. package/dist/{chunk-V2MTG5FT.js → chunk-IKLYI3RF.js} +33 -16
  14. package/dist/{chunk-HMJFCBRR.js → chunk-L3GAGWCC.js} +10 -1
  15. package/dist/{chunk-X67UYC74.js → chunk-LU2MQXQQ.js} +14 -24
  16. package/dist/{chunk-4JCAUOLN.js → chunk-M5KBNOSJ.js} +22 -12
  17. package/dist/{chunk-FDY42FIU.js → chunk-MHBCEJQO.js} +2 -2
  18. package/dist/{chunk-RLUJL2MV.js → chunk-NHKQKKZU.js} +6 -7
  19. package/dist/{chunk-HXMS4SNP.js → chunk-R3QEDXFS.js} +2 -2
  20. package/dist/{chunk-NPIEEKPT.js → chunk-RYMOSG5B.js} +6 -6
  21. package/dist/{chunk-H6PCHJZQ.js → chunk-SLMFA3ZZ.js} +11 -3
  22. package/dist/{chunk-Z2FWAE4B.js → chunk-TEFZT5PJ.js} +84 -16
  23. package/dist/{chunk-7XDYVJLE.js → chunk-ULLTNDRA.js} +6 -6
  24. package/dist/{chunk-GOUM4JCT.js → chunk-VOVVTOEA.js} +2 -2
  25. package/dist/{chunk-FOI23UJL.js → chunk-WL7BIR6O.js} +1 -1
  26. package/dist/{chunk-JYXOEYI4.js → chunk-WW6DAGGR.js} +5 -5
  27. package/dist/{chunk-C427DVQF.js → chunk-WZG2SZOT.js} +22 -5
  28. package/dist/{chunk-NFYWLRUO.js → chunk-XH2RTYEQ.js} +3 -3
  29. package/dist/{chunk-2C4E3HBM.js → chunk-Z37APKBV.js} +5 -5
  30. package/dist/{chunk-RDRSWYNP.js → chunk-ZUVLC7TM.js} +1 -1
  31. package/dist/data.cjs +168 -24
  32. package/dist/data.js +8 -8
  33. package/dist/devtools.cjs +252 -32
  34. package/dist/devtools.js +7 -7
  35. package/dist/ecosystem.cjs +205 -64
  36. package/dist/ecosystem.js +10 -10
  37. package/dist/extras.cjs +245 -112
  38. package/dist/extras.js +24 -24
  39. package/dist/index.cjs +236 -105
  40. package/dist/index.d.cts +72 -8
  41. package/dist/index.d.ts +72 -8
  42. package/dist/index.js +14 -14
  43. package/dist/motion.cjs +336 -14
  44. package/dist/motion.js +4 -4
  45. package/dist/patterns.cjs +168 -24
  46. package/dist/patterns.js +6 -6
  47. package/dist/performance.cjs +305 -32
  48. package/dist/performance.js +8 -8
  49. package/dist/plugins.cjs +268 -69
  50. package/dist/plugins.js +12 -12
  51. package/dist/{ssr-2QDQ27EV.js → ssr-6D67RAVB.js} +3 -3
  52. package/dist/ssr.cjs +205 -63
  53. package/dist/ssr.js +11 -11
  54. package/dist/testing.cjs +415 -12
  55. package/dist/testing.js +16 -10
  56. package/dist/ui.cjs +248 -36
  57. package/dist/ui.js +9 -9
  58. package/dist/widgets.cjs +176 -26
  59. package/dist/widgets.js +8 -8
  60. package/package.json +1 -1
package/dist/data.cjs CHANGED
@@ -46,7 +46,13 @@ module.exports = __toCommonJS(data_exports);
46
46
 
47
47
  // src/core/dev.ts
48
48
  function isDev() {
49
- return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
49
+ return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
50
+ // The bare `__SIBU_DEV__` is a bundler define that only exists in
51
+ // production builds; under the test runner it is always undefined, so
52
+ // this branch is unreachable here.
53
+ /* v8 ignore next 2 */
54
+ typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
55
+ );
50
56
  }
51
57
  var _isDev = isDev();
52
58
  function devAssert(condition, message) {
@@ -60,7 +66,7 @@ function devWarn(message) {
60
66
  }
61
67
  }
62
68
 
63
- // src/reactivity/track.ts
69
+ // src/reactivity/track-core.ts
64
70
  var _isDev2 = isDev();
65
71
  var POOL_MAX = 4096;
66
72
  var nodePool = [];
@@ -144,6 +150,7 @@ function unlinkSub(node) {
144
150
  else sub.depsTail = prev;
145
151
  }
146
152
  var currentSubscriber = null;
153
+ var suspendSavedSub = null;
147
154
  var notifyDepth = 0;
148
155
  var pendingQueue = [];
149
156
  var pendingSet = /* @__PURE__ */ new Set();
@@ -155,7 +162,35 @@ function safeInvoke(sub) {
155
162
  if (_isDev2) devWarn(`Subscriber threw during notification: ${err instanceof Error ? err.message : String(err)}`);
156
163
  }
157
164
  }
165
+ var suspendDepth = 0;
158
166
  var trackingSuspended = false;
167
+ function suspendTracking() {
168
+ if (suspendDepth === 0) {
169
+ suspendSavedSub = currentSubscriber;
170
+ currentSubscriber = null;
171
+ trackingSuspended = true;
172
+ }
173
+ suspendDepth++;
174
+ }
175
+ function resumeTracking() {
176
+ suspendDepth--;
177
+ if (suspendDepth === 0) {
178
+ currentSubscriber = suspendSavedSub;
179
+ suspendSavedSub = null;
180
+ trackingSuspended = false;
181
+ }
182
+ }
183
+ function isTrackingSuspended() {
184
+ return trackingSuspended;
185
+ }
186
+ function untracked(fn) {
187
+ suspendTracking();
188
+ try {
189
+ return fn();
190
+ } finally {
191
+ resumeTracking();
192
+ }
193
+ }
159
194
  var subscriberEpochCounter = 0;
160
195
  function retrack(effectFn, subscriber) {
161
196
  const prev = currentSubscriber;
@@ -265,6 +300,16 @@ function cleanup(subscriber) {
265
300
  var maxSubscriberRepeats = 50;
266
301
  var maxDrainIterations = 1e6;
267
302
  var drainEpoch = 0;
303
+ function setMaxSubscriberRepeats(n) {
304
+ const prev = maxSubscriberRepeats;
305
+ if (Number.isFinite(n) && n > 0) maxSubscriberRepeats = Math.floor(n);
306
+ return prev;
307
+ }
308
+ function setMaxDrainIterations(n) {
309
+ const prev = maxDrainIterations;
310
+ if (Number.isFinite(n) && n > 0) maxDrainIterations = Math.floor(n);
311
+ return prev;
312
+ }
268
313
  function tickRepeat(sub) {
269
314
  const s = sub;
270
315
  if (s._runEpoch !== drainEpoch) {
@@ -413,6 +458,85 @@ function notifySubscribers(signal2) {
413
458
  }
414
459
  }
415
460
  }
461
+ function getSubscriberCount(signal2) {
462
+ return signal2.__sc ?? 0;
463
+ }
464
+ function getSubscriberDeps(subscriber) {
465
+ const sub = subscriber;
466
+ const out = [];
467
+ let node = sub.depsHead ?? null;
468
+ while (node) {
469
+ if (node.sig) out.push(node.sig);
470
+ node = node.subNext;
471
+ }
472
+ return out;
473
+ }
474
+ function forEachSubscriber(signal2, visit) {
475
+ let node = signal2.subsHead ?? null;
476
+ while (node) {
477
+ const s = node.sub;
478
+ if (s) visit(s);
479
+ node = node.sigNext;
480
+ }
481
+ }
482
+
483
+ // src/reactivity/track.ts
484
+ var _isDev3 = isDev();
485
+ var _runtimeVersion = typeof __SIBU_VERSION__ !== "undefined" ? __SIBU_VERSION__ : "dev";
486
+ var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
487
+ function resolveReactiveApi() {
488
+ const g = globalThis;
489
+ const existing = g[REGISTRY_KEY];
490
+ if (existing) {
491
+ if (_isDev3 && !existing.__dupWarned) {
492
+ existing.__dupWarned = true;
493
+ devWarn(
494
+ `Multiple instances of the reactive runtime detected on this page (active: ${existing.version}, duplicate: ${_runtimeVersion}). Reactivity still works \u2014 all copies share the first one \u2014 but de-duplicate sibujs in your bundler (e.g. Vite optimizeDeps.exclude: ['sibujs'] or resolve.dedupe: ['sibujs']).`
495
+ );
496
+ }
497
+ return existing;
498
+ }
499
+ const local = {
500
+ suspendTracking,
501
+ resumeTracking,
502
+ isTrackingSuspended,
503
+ untracked,
504
+ retrack,
505
+ track,
506
+ reactiveBinding,
507
+ recordDependency,
508
+ cleanup,
509
+ setMaxSubscriberRepeats,
510
+ setMaxDrainIterations,
511
+ drainNotificationQueue,
512
+ queueSignalNotification,
513
+ notifySubscribers,
514
+ getSubscriberCount,
515
+ getSubscriberDeps,
516
+ forEachSubscriber,
517
+ version: _runtimeVersion
518
+ };
519
+ g[REGISTRY_KEY] = local;
520
+ return local;
521
+ }
522
+ var API = resolveReactiveApi();
523
+ var suspendTracking2 = API.suspendTracking;
524
+ var resumeTracking2 = API.resumeTracking;
525
+ var isTrackingSuspended2 = API.isTrackingSuspended;
526
+ var untracked2 = API.untracked;
527
+ var retrack2 = API.retrack;
528
+ var track2 = API.track;
529
+ var reactiveBinding2 = API.reactiveBinding;
530
+ var recordDependency2 = API.recordDependency;
531
+ var cleanup2 = API.cleanup;
532
+ var setMaxSubscriberRepeats2 = API.setMaxSubscriberRepeats;
533
+ var setMaxDrainIterations2 = API.setMaxDrainIterations;
534
+ var drainNotificationQueue2 = API.drainNotificationQueue;
535
+ var queueSignalNotification2 = API.queueSignalNotification;
536
+ var notifySubscribers2 = API.notifySubscribers;
537
+ var getSubscriberCount2 = API.getSubscriberCount;
538
+ var getSubscriberDeps2 = API.getSubscriberDeps;
539
+ var forEachSubscriber2 = API.forEachSubscriber;
416
540
 
417
541
  // src/core/signals/derived.ts
418
542
  function derived(getter, options) {
@@ -436,7 +560,7 @@ function derived(getter, options) {
436
560
  cs._d = false;
437
561
  cs._init = true;
438
562
  };
439
- track(() => {
563
+ track2(() => {
440
564
  let threw = true;
441
565
  try {
442
566
  cs._v = getter();
@@ -455,12 +579,12 @@ function derived(getter, options) {
455
579
  `[SibuJS] Circular dependency detected in derived${debugName ? ` "${debugName}"` : ""}. A derived signal cannot read itself (directly or through a chain).`
456
580
  );
457
581
  }
458
- if (trackingSuspended) {
582
+ if (isTrackingSuspended2()) {
459
583
  if (cs._d) {
460
584
  const prev = cs._v;
461
585
  evaluating = true;
462
586
  try {
463
- retrack(recompute, markDirty);
587
+ retrack2(recompute, markDirty);
464
588
  if (!Object.is(prev, cs._v)) cs.__v++;
465
589
  } finally {
466
590
  evaluating = false;
@@ -468,12 +592,12 @@ function derived(getter, options) {
468
592
  }
469
593
  return cs._v;
470
594
  }
471
- recordDependency(cs);
595
+ recordDependency2(cs);
472
596
  if (cs._d) {
473
597
  const oldValue = cs._v;
474
598
  evaluating = true;
475
599
  try {
476
- retrack(recompute, markDirty);
600
+ retrack2(recompute, markDirty);
477
601
  if (!Object.is(oldValue, cs._v)) cs.__v++;
478
602
  } finally {
479
603
  evaluating = false;
@@ -553,7 +677,7 @@ function drainReruns(ctx) {
553
677
  do {
554
678
  ctx.rerunPending = false;
555
679
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
556
- retrack(ctx.bodyFn, ctx.subscriber);
680
+ retrack2(ctx.bodyFn, ctx.subscriber);
557
681
  } while (ctx.rerunPending && ++reruns <= MAX_RERUNS);
558
682
  if (ctx.rerunPending) {
559
683
  ctx.rerunPending = false;
@@ -582,7 +706,7 @@ function disposeEffect(ctx) {
582
706
  }
583
707
  }
584
708
  try {
585
- cleanup(ctx.subscriber);
709
+ cleanup2(ctx.subscriber);
586
710
  } catch (err) {
587
711
  if (typeof console !== "undefined") {
588
712
  console.warn("[SibuJS effect] dispose threw:", err);
@@ -627,7 +751,7 @@ function effect(effectFn, options) {
627
751
  try {
628
752
  ctx.rerunPending = false;
629
753
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
630
- retrack(ctx.bodyFn, sub);
754
+ retrack2(ctx.bodyFn, sub);
631
755
  if (ctx.rerunPending) drainReruns(ctx);
632
756
  } finally {
633
757
  ctx.running = false;
@@ -643,7 +767,7 @@ function effect(effectFn, options) {
643
767
  ctx.subscriber = sub;
644
768
  ctx.running = true;
645
769
  try {
646
- retrack(ctx.bodyFn, ctx.subscriber);
770
+ retrack2(ctx.bodyFn, ctx.subscriber);
647
771
  if (ctx.rerunPending) drainReruns(ctx);
648
772
  } finally {
649
773
  ctx.running = false;
@@ -657,7 +781,7 @@ function effect(effectFn, options) {
657
781
  // src/reactivity/batch.ts
658
782
  var batchDepth = 0;
659
783
  var pendingSignals = /* @__PURE__ */ new Set();
660
- function batch(fn) {
784
+ function batchImpl(fn) {
661
785
  batchDepth++;
662
786
  try {
663
787
  return fn();
@@ -668,25 +792,45 @@ function batch(fn) {
668
792
  }
669
793
  }
670
794
  }
671
- function enqueueBatchedSignal(signal2) {
795
+ function enqueueBatchedSignalImpl(signal2) {
672
796
  if (batchDepth === 0) return false;
673
797
  pendingSignals.add(signal2);
674
798
  return true;
675
799
  }
800
+ function isBatchingImpl() {
801
+ return batchDepth > 0;
802
+ }
676
803
  function flushBatch() {
677
804
  try {
678
805
  for (const signal2 of pendingSignals) {
679
- queueSignalNotification(signal2);
806
+ queueSignalNotification2(signal2);
680
807
  }
681
808
  } finally {
682
809
  pendingSignals.clear();
683
810
  }
684
- drainNotificationQueue();
811
+ drainNotificationQueue2();
812
+ }
813
+ var BATCH_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.batch.v1");
814
+ function resolveBatchApi() {
815
+ const g = globalThis;
816
+ const existing = g[BATCH_REGISTRY_KEY];
817
+ if (existing) return existing;
818
+ const local = {
819
+ batch: batchImpl,
820
+ enqueueBatchedSignal: enqueueBatchedSignalImpl,
821
+ isBatching: isBatchingImpl
822
+ };
823
+ g[BATCH_REGISTRY_KEY] = local;
824
+ return local;
685
825
  }
826
+ var API2 = resolveBatchApi();
827
+ var batch = API2.batch;
828
+ var enqueueBatchedSignal = API2.enqueueBatchedSignal;
829
+ var isBatching = API2.isBatching;
686
830
 
687
831
  // src/core/signals/signal.ts
688
832
  var _g2 = globalThis;
689
- var _isDev3 = isDev();
833
+ var _isDev4 = isDev();
690
834
  function signal(initial, options) {
691
835
  const state = {
692
836
  value: initial,
@@ -697,11 +841,11 @@ function signal(initial, options) {
697
841
  __activeNode: null,
698
842
  __name: void 0
699
843
  };
700
- const debugName = _isDev3 ? options?.name : void 0;
844
+ const debugName = _isDev4 ? options?.name : void 0;
701
845
  const equalsFn = options?.equals;
702
846
  if (debugName) state.__name = debugName;
703
847
  function get() {
704
- recordDependency(state);
848
+ recordDependency2(state);
705
849
  return state.value;
706
850
  }
707
851
  get.__signal = state;
@@ -714,15 +858,15 @@ function signal(initial, options) {
714
858
  if (equalsFn(prev, newValue)) return;
715
859
  state.value = newValue;
716
860
  state.__v++;
717
- if (_isDev3) {
861
+ if (_isDev4) {
718
862
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
719
863
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
720
864
  }
721
865
  if (!enqueueBatchedSignal(state)) {
722
- notifySubscribers(state);
866
+ notifySubscribers2(state);
723
867
  }
724
868
  };
725
- } else if (_isDev3) {
869
+ } else if (_isDev4) {
726
870
  set = (next) => {
727
871
  const prev = state.value;
728
872
  const newValue = typeof next === "function" ? next(prev) : next;
@@ -732,7 +876,7 @@ function signal(initial, options) {
732
876
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
733
877
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
734
878
  if (!enqueueBatchedSignal(state)) {
735
- notifySubscribers(state);
879
+ notifySubscribers2(state);
736
880
  }
737
881
  };
738
882
  } else {
@@ -743,11 +887,11 @@ function signal(initial, options) {
743
887
  state.value = newValue;
744
888
  state.__v++;
745
889
  if (!enqueueBatchedSignal(state)) {
746
- notifySubscribers(state);
890
+ notifySubscribers2(state);
747
891
  }
748
892
  };
749
893
  }
750
- if (_isDev3) {
894
+ if (_isDev4) {
751
895
  const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
752
896
  if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
753
897
  }
package/dist/data.js CHANGED
@@ -20,15 +20,15 @@ import {
20
20
  syncAdapter,
21
21
  throttle,
22
22
  withRetry
23
- } from "./chunk-VOCE4NNK.js";
24
- import "./chunk-YFDGQWDA.js";
25
- import "./chunk-JYXOEYI4.js";
26
- import "./chunk-HMJFCBRR.js";
27
- import "./chunk-FDY42FIU.js";
23
+ } from "./chunk-AMIKDMLP.js";
24
+ import "./chunk-F7FXQ3QS.js";
25
+ import "./chunk-WW6DAGGR.js";
26
+ import "./chunk-L3GAGWCC.js";
27
+ import "./chunk-MHBCEJQO.js";
28
28
  import "./chunk-GOJMFRBL.js";
29
- import "./chunk-C427DVQF.js";
30
- import "./chunk-Z2FWAE4B.js";
31
- import "./chunk-LMLD24FC.js";
29
+ import "./chunk-WZG2SZOT.js";
30
+ import "./chunk-TEFZT5PJ.js";
31
+ import "./chunk-COY6PUD2.js";
32
32
  export {
33
33
  __resetQueryCache,
34
34
  calculateDelay,