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/patterns.cjs CHANGED
@@ -45,7 +45,13 @@ module.exports = __toCommonJS(patterns_exports);
45
45
 
46
46
  // src/core/dev.ts
47
47
  function isDev() {
48
- return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
48
+ return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
49
+ // The bare `__SIBU_DEV__` is a bundler define that only exists in
50
+ // production builds; under the test runner it is always undefined, so
51
+ // this branch is unreachable here.
52
+ /* v8 ignore next 2 */
53
+ typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
54
+ );
49
55
  }
50
56
  var _isDev = isDev();
51
57
  function devAssert(condition, message) {
@@ -59,7 +65,7 @@ function devWarn(message) {
59
65
  }
60
66
  }
61
67
 
62
- // src/reactivity/track.ts
68
+ // src/reactivity/track-core.ts
63
69
  var _isDev2 = isDev();
64
70
  var POOL_MAX = 4096;
65
71
  var nodePool = [];
@@ -143,6 +149,7 @@ function unlinkSub(node) {
143
149
  else sub.depsTail = prev;
144
150
  }
145
151
  var currentSubscriber = null;
152
+ var suspendSavedSub = null;
146
153
  var notifyDepth = 0;
147
154
  var pendingQueue = [];
148
155
  var pendingSet = /* @__PURE__ */ new Set();
@@ -154,7 +161,35 @@ function safeInvoke(sub) {
154
161
  if (_isDev2) devWarn(`Subscriber threw during notification: ${err instanceof Error ? err.message : String(err)}`);
155
162
  }
156
163
  }
164
+ var suspendDepth = 0;
157
165
  var trackingSuspended = false;
166
+ function suspendTracking() {
167
+ if (suspendDepth === 0) {
168
+ suspendSavedSub = currentSubscriber;
169
+ currentSubscriber = null;
170
+ trackingSuspended = true;
171
+ }
172
+ suspendDepth++;
173
+ }
174
+ function resumeTracking() {
175
+ suspendDepth--;
176
+ if (suspendDepth === 0) {
177
+ currentSubscriber = suspendSavedSub;
178
+ suspendSavedSub = null;
179
+ trackingSuspended = false;
180
+ }
181
+ }
182
+ function isTrackingSuspended() {
183
+ return trackingSuspended;
184
+ }
185
+ function untracked(fn) {
186
+ suspendTracking();
187
+ try {
188
+ return fn();
189
+ } finally {
190
+ resumeTracking();
191
+ }
192
+ }
158
193
  var subscriberEpochCounter = 0;
159
194
  function retrack(effectFn, subscriber) {
160
195
  const prev = currentSubscriber;
@@ -264,6 +299,16 @@ function cleanup(subscriber) {
264
299
  var maxSubscriberRepeats = 50;
265
300
  var maxDrainIterations = 1e6;
266
301
  var drainEpoch = 0;
302
+ function setMaxSubscriberRepeats(n) {
303
+ const prev = maxSubscriberRepeats;
304
+ if (Number.isFinite(n) && n > 0) maxSubscriberRepeats = Math.floor(n);
305
+ return prev;
306
+ }
307
+ function setMaxDrainIterations(n) {
308
+ const prev = maxDrainIterations;
309
+ if (Number.isFinite(n) && n > 0) maxDrainIterations = Math.floor(n);
310
+ return prev;
311
+ }
267
312
  function tickRepeat(sub) {
268
313
  const s = sub;
269
314
  if (s._runEpoch !== drainEpoch) {
@@ -412,11 +457,90 @@ function notifySubscribers(signal2) {
412
457
  }
413
458
  }
414
459
  }
460
+ function getSubscriberCount(signal2) {
461
+ return signal2.__sc ?? 0;
462
+ }
463
+ function getSubscriberDeps(subscriber) {
464
+ const sub = subscriber;
465
+ const out = [];
466
+ let node = sub.depsHead ?? null;
467
+ while (node) {
468
+ if (node.sig) out.push(node.sig);
469
+ node = node.subNext;
470
+ }
471
+ return out;
472
+ }
473
+ function forEachSubscriber(signal2, visit) {
474
+ let node = signal2.subsHead ?? null;
475
+ while (node) {
476
+ const s = node.sub;
477
+ if (s) visit(s);
478
+ node = node.sigNext;
479
+ }
480
+ }
481
+
482
+ // src/reactivity/track.ts
483
+ var _isDev3 = isDev();
484
+ var _runtimeVersion = typeof __SIBU_VERSION__ !== "undefined" ? __SIBU_VERSION__ : "dev";
485
+ var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
486
+ function resolveReactiveApi() {
487
+ const g = globalThis;
488
+ const existing = g[REGISTRY_KEY];
489
+ if (existing) {
490
+ if (_isDev3 && !existing.__dupWarned) {
491
+ existing.__dupWarned = true;
492
+ devWarn(
493
+ `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']).`
494
+ );
495
+ }
496
+ return existing;
497
+ }
498
+ const local = {
499
+ suspendTracking,
500
+ resumeTracking,
501
+ isTrackingSuspended,
502
+ untracked,
503
+ retrack,
504
+ track,
505
+ reactiveBinding,
506
+ recordDependency,
507
+ cleanup,
508
+ setMaxSubscriberRepeats,
509
+ setMaxDrainIterations,
510
+ drainNotificationQueue,
511
+ queueSignalNotification,
512
+ notifySubscribers,
513
+ getSubscriberCount,
514
+ getSubscriberDeps,
515
+ forEachSubscriber,
516
+ version: _runtimeVersion
517
+ };
518
+ g[REGISTRY_KEY] = local;
519
+ return local;
520
+ }
521
+ var API = resolveReactiveApi();
522
+ var suspendTracking2 = API.suspendTracking;
523
+ var resumeTracking2 = API.resumeTracking;
524
+ var isTrackingSuspended2 = API.isTrackingSuspended;
525
+ var untracked2 = API.untracked;
526
+ var retrack2 = API.retrack;
527
+ var track2 = API.track;
528
+ var reactiveBinding2 = API.reactiveBinding;
529
+ var recordDependency2 = API.recordDependency;
530
+ var cleanup2 = API.cleanup;
531
+ var setMaxSubscriberRepeats2 = API.setMaxSubscriberRepeats;
532
+ var setMaxDrainIterations2 = API.setMaxDrainIterations;
533
+ var drainNotificationQueue2 = API.drainNotificationQueue;
534
+ var queueSignalNotification2 = API.queueSignalNotification;
535
+ var notifySubscribers2 = API.notifySubscribers;
536
+ var getSubscriberCount2 = API.getSubscriberCount;
537
+ var getSubscriberDeps2 = API.getSubscriberDeps;
538
+ var forEachSubscriber2 = API.forEachSubscriber;
415
539
 
416
540
  // src/reactivity/batch.ts
417
541
  var batchDepth = 0;
418
542
  var pendingSignals = /* @__PURE__ */ new Set();
419
- function batch(fn) {
543
+ function batchImpl(fn) {
420
544
  batchDepth++;
421
545
  try {
422
546
  return fn();
@@ -427,25 +551,45 @@ function batch(fn) {
427
551
  }
428
552
  }
429
553
  }
430
- function enqueueBatchedSignal(signal2) {
554
+ function enqueueBatchedSignalImpl(signal2) {
431
555
  if (batchDepth === 0) return false;
432
556
  pendingSignals.add(signal2);
433
557
  return true;
434
558
  }
559
+ function isBatchingImpl() {
560
+ return batchDepth > 0;
561
+ }
435
562
  function flushBatch() {
436
563
  try {
437
564
  for (const signal2 of pendingSignals) {
438
- queueSignalNotification(signal2);
565
+ queueSignalNotification2(signal2);
439
566
  }
440
567
  } finally {
441
568
  pendingSignals.clear();
442
569
  }
443
- drainNotificationQueue();
570
+ drainNotificationQueue2();
571
+ }
572
+ var BATCH_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.batch.v1");
573
+ function resolveBatchApi() {
574
+ const g = globalThis;
575
+ const existing = g[BATCH_REGISTRY_KEY];
576
+ if (existing) return existing;
577
+ const local = {
578
+ batch: batchImpl,
579
+ enqueueBatchedSignal: enqueueBatchedSignalImpl,
580
+ isBatching: isBatchingImpl
581
+ };
582
+ g[BATCH_REGISTRY_KEY] = local;
583
+ return local;
444
584
  }
585
+ var API2 = resolveBatchApi();
586
+ var batch = API2.batch;
587
+ var enqueueBatchedSignal = API2.enqueueBatchedSignal;
588
+ var isBatching = API2.isBatching;
445
589
 
446
590
  // src/core/signals/signal.ts
447
591
  var _g = globalThis;
448
- var _isDev3 = isDev();
592
+ var _isDev4 = isDev();
449
593
  function signal(initial, options) {
450
594
  const state = {
451
595
  value: initial,
@@ -456,11 +600,11 @@ function signal(initial, options) {
456
600
  __activeNode: null,
457
601
  __name: void 0
458
602
  };
459
- const debugName = _isDev3 ? options?.name : void 0;
603
+ const debugName = _isDev4 ? options?.name : void 0;
460
604
  const equalsFn = options?.equals;
461
605
  if (debugName) state.__name = debugName;
462
606
  function get() {
463
- recordDependency(state);
607
+ recordDependency2(state);
464
608
  return state.value;
465
609
  }
466
610
  get.__signal = state;
@@ -473,15 +617,15 @@ function signal(initial, options) {
473
617
  if (equalsFn(prev, newValue)) return;
474
618
  state.value = newValue;
475
619
  state.__v++;
476
- if (_isDev3) {
620
+ if (_isDev4) {
477
621
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
478
622
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
479
623
  }
480
624
  if (!enqueueBatchedSignal(state)) {
481
- notifySubscribers(state);
625
+ notifySubscribers2(state);
482
626
  }
483
627
  };
484
- } else if (_isDev3) {
628
+ } else if (_isDev4) {
485
629
  set = (next) => {
486
630
  const prev = state.value;
487
631
  const newValue = typeof next === "function" ? next(prev) : next;
@@ -491,7 +635,7 @@ function signal(initial, options) {
491
635
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
492
636
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
493
637
  if (!enqueueBatchedSignal(state)) {
494
- notifySubscribers(state);
638
+ notifySubscribers2(state);
495
639
  }
496
640
  };
497
641
  } else {
@@ -502,11 +646,11 @@ function signal(initial, options) {
502
646
  state.value = newValue;
503
647
  state.__v++;
504
648
  if (!enqueueBatchedSignal(state)) {
505
- notifySubscribers(state);
649
+ notifySubscribers2(state);
506
650
  }
507
651
  };
508
652
  }
509
- if (_isDev3) {
653
+ if (_isDev4) {
510
654
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
511
655
  if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
512
656
  }
@@ -633,7 +777,7 @@ function drainReruns(ctx) {
633
777
  do {
634
778
  ctx.rerunPending = false;
635
779
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
636
- retrack(ctx.bodyFn, ctx.subscriber);
780
+ retrack2(ctx.bodyFn, ctx.subscriber);
637
781
  } while (ctx.rerunPending && ++reruns <= MAX_RERUNS);
638
782
  if (ctx.rerunPending) {
639
783
  ctx.rerunPending = false;
@@ -662,7 +806,7 @@ function disposeEffect(ctx) {
662
806
  }
663
807
  }
664
808
  try {
665
- cleanup(ctx.subscriber);
809
+ cleanup2(ctx.subscriber);
666
810
  } catch (err) {
667
811
  if (typeof console !== "undefined") {
668
812
  console.warn("[SibuJS effect] dispose threw:", err);
@@ -707,7 +851,7 @@ function effect(effectFn, options) {
707
851
  try {
708
852
  ctx.rerunPending = false;
709
853
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
710
- retrack(ctx.bodyFn, sub);
854
+ retrack2(ctx.bodyFn, sub);
711
855
  if (ctx.rerunPending) drainReruns(ctx);
712
856
  } finally {
713
857
  ctx.running = false;
@@ -723,7 +867,7 @@ function effect(effectFn, options) {
723
867
  ctx.subscriber = sub;
724
868
  ctx.running = true;
725
869
  try {
726
- retrack(ctx.bodyFn, ctx.subscriber);
870
+ retrack2(ctx.bodyFn, ctx.subscriber);
727
871
  if (ctx.rerunPending) drainReruns(ctx);
728
872
  } finally {
729
873
  ctx.running = false;
@@ -975,7 +1119,7 @@ function derived(getter, options) {
975
1119
  cs._d = false;
976
1120
  cs._init = true;
977
1121
  };
978
- track(() => {
1122
+ track2(() => {
979
1123
  let threw = true;
980
1124
  try {
981
1125
  cs._v = getter();
@@ -994,12 +1138,12 @@ function derived(getter, options) {
994
1138
  `[SibuJS] Circular dependency detected in derived${debugName ? ` "${debugName}"` : ""}. A derived signal cannot read itself (directly or through a chain).`
995
1139
  );
996
1140
  }
997
- if (trackingSuspended) {
1141
+ if (isTrackingSuspended2()) {
998
1142
  if (cs._d) {
999
1143
  const prev = cs._v;
1000
1144
  evaluating = true;
1001
1145
  try {
1002
- retrack(recompute, markDirty);
1146
+ retrack2(recompute, markDirty);
1003
1147
  if (!Object.is(prev, cs._v)) cs.__v++;
1004
1148
  } finally {
1005
1149
  evaluating = false;
@@ -1007,12 +1151,12 @@ function derived(getter, options) {
1007
1151
  }
1008
1152
  return cs._v;
1009
1153
  }
1010
- recordDependency(cs);
1154
+ recordDependency2(cs);
1011
1155
  if (cs._d) {
1012
1156
  const oldValue = cs._v;
1013
1157
  evaluating = true;
1014
1158
  try {
1015
- retrack(recompute, markDirty);
1159
+ retrack2(recompute, markDirty);
1016
1160
  if (!Object.is(oldValue, cs._v)) cs.__v++;
1017
1161
  } finally {
1018
1162
  evaluating = false;
package/dist/patterns.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  optimisticList,
6
6
  persisted,
7
7
  timeline
8
- } from "./chunk-NFYWLRUO.js";
8
+ } from "./chunk-XH2RTYEQ.js";
9
9
  import {
10
10
  RenderProp,
11
11
  assertType,
@@ -23,12 +23,12 @@ import {
23
23
  withWrapper
24
24
  } from "./chunk-VJE6DDYM.js";
25
25
  import "./chunk-H3SRKIYX.js";
26
- import "./chunk-JYXOEYI4.js";
27
- import "./chunk-FDY42FIU.js";
26
+ import "./chunk-WW6DAGGR.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
  RenderProp,
34
34
  assertType,