sibujs 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/browser.cjs +230 -40
  2. package/dist/browser.js +5 -5
  3. package/dist/build.cjs +240 -108
  4. package/dist/build.js +13 -13
  5. package/dist/cdn.global.js +7 -7
  6. package/dist/{chunk-BEIKESVL.js → chunk-2ARSB7NG.js} +36 -13
  7. package/dist/{chunk-X3NHE2DK.js → chunk-4NJEAPLI.js} +83 -17
  8. package/dist/{chunk-JBXNCZSC.js → chunk-5VH3GIDX.js} +1 -1
  9. package/dist/{chunk-6G6UNHZI.js → chunk-62V653X2.js} +16 -21
  10. package/dist/{chunk-S4FHR5ZZ.js → chunk-655B7MMR.js} +3 -3
  11. package/dist/{chunk-24DBWDTK.js → chunk-6TCOWMGY.js} +1 -1
  12. package/dist/{chunk-USDR2GFV.js → chunk-A7CZH3GN.js} +3 -3
  13. package/dist/{chunk-SLCUP2EK.js → chunk-AEOLHSSQ.js} +3 -3
  14. package/dist/chunk-CCSJMTRN.js +15 -0
  15. package/dist/{chunk-R3QEDXFS.js → chunk-EX77FXTT.js} +1 -1
  16. package/dist/{chunk-ZUVLC7TM.js → chunk-FJIRS3FM.js} +1 -1
  17. package/dist/{chunk-4WXWJ4SW.js → chunk-FJO2ZL4Q.js} +4 -4
  18. package/dist/{chunk-CVMMULHO.js → chunk-G6N3LMO2.js} +4 -4
  19. package/dist/{chunk-XQ7XSGYP.js → chunk-IQJ36UTJ.js} +1 -1
  20. package/dist/{chunk-5K72I3UQ.js → chunk-JCQG2I2G.js} +21 -4
  21. package/dist/{chunk-7JHWAGRQ.js → chunk-N5TQVEKE.js} +2 -2
  22. package/dist/{chunk-IHBVTURX.js → chunk-P7C7SEJV.js} +4 -4
  23. package/dist/{chunk-M6WSIGYW.js → chunk-Q46YIQYW.js} +2 -2
  24. package/dist/{chunk-Q2ERM6NT.js → chunk-QCFBIVIQ.js} +1 -1
  25. package/dist/{chunk-F4UM7QBJ.js → chunk-RLTFJYDN.js} +2 -2
  26. package/dist/{chunk-GOJMFRBL.js → chunk-S3NFJO6L.js} +20 -14
  27. package/dist/{chunk-MWZFOIBG.js → chunk-YUBEOWII.js} +5 -5
  28. package/dist/{chunk-WVJJUFPC.js → chunk-YUR5SX7F.js} +2 -2
  29. package/dist/{chunk-NUWKIEHE.js → chunk-ZEUP4TUD.js} +2 -2
  30. package/dist/data.cjs +181 -37
  31. package/dist/data.js +7 -7
  32. package/dist/devtools.cjs +265 -45
  33. package/dist/devtools.js +5 -5
  34. package/dist/ecosystem.cjs +203 -59
  35. package/dist/ecosystem.js +8 -8
  36. package/dist/extras.cjs +216 -116
  37. package/dist/extras.js +22 -22
  38. package/dist/index.cjs +242 -108
  39. package/dist/index.d.cts +78 -14
  40. package/dist/index.d.ts +78 -14
  41. package/dist/index.js +17 -13
  42. package/dist/motion.cjs +329 -13
  43. package/dist/motion.js +3 -3
  44. package/dist/patterns.cjs +181 -37
  45. package/dist/patterns.js +6 -6
  46. package/dist/performance.cjs +278 -37
  47. package/dist/performance.js +6 -6
  48. package/dist/plugins.cjs +353 -153
  49. package/dist/plugins.js +95 -94
  50. package/dist/{ssr-6D67RAVB.js → ssr-2PPULEK2.js} +2 -2
  51. package/dist/ssr.cjs +203 -58
  52. package/dist/ssr.js +9 -9
  53. package/dist/testing.cjs +416 -19
  54. package/dist/testing.js +3 -3
  55. package/dist/ui.cjs +256 -65
  56. package/dist/ui.js +8 -8
  57. package/dist/widgets.cjs +166 -40
  58. package/dist/widgets.js +7 -7
  59. package/package.json +1 -1
  60. package/dist/chunk-YT6HQ6AM.js +0 -14
package/dist/patterns.cjs CHANGED
@@ -65,7 +65,7 @@ function devWarn(message) {
65
65
  }
66
66
  }
67
67
 
68
- // src/reactivity/track.ts
68
+ // src/reactivity/track-core.ts
69
69
  var _isDev2 = isDev();
70
70
  var POOL_MAX = 4096;
71
71
  var nodePool = [];
@@ -149,6 +149,7 @@ function unlinkSub(node) {
149
149
  else sub.depsTail = prev;
150
150
  }
151
151
  var currentSubscriber = null;
152
+ var suspendSavedSub = null;
152
153
  var notifyDepth = 0;
153
154
  var pendingQueue = [];
154
155
  var pendingSet = /* @__PURE__ */ new Set();
@@ -160,7 +161,35 @@ function safeInvoke(sub) {
160
161
  if (_isDev2) devWarn(`Subscriber threw during notification: ${err instanceof Error ? err.message : String(err)}`);
161
162
  }
162
163
  }
164
+ var suspendDepth = 0;
163
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
+ }
164
193
  var subscriberEpochCounter = 0;
165
194
  function retrack(effectFn, subscriber) {
166
195
  const prev = currentSubscriber;
@@ -270,6 +299,16 @@ function cleanup(subscriber) {
270
299
  var maxSubscriberRepeats = 50;
271
300
  var maxDrainIterations = 1e6;
272
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
+ }
273
312
  function tickRepeat(sub) {
274
313
  const s = sub;
275
314
  if (s._runEpoch !== drainEpoch) {
@@ -418,11 +457,90 @@ function notifySubscribers(signal2) {
418
457
  }
419
458
  }
420
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 = true ? "3.3.2" : "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;
421
539
 
422
540
  // src/reactivity/batch.ts
423
541
  var batchDepth = 0;
424
542
  var pendingSignals = /* @__PURE__ */ new Set();
425
- function batch(fn) {
543
+ function batchImpl(fn) {
426
544
  batchDepth++;
427
545
  try {
428
546
  return fn();
@@ -433,25 +551,45 @@ function batch(fn) {
433
551
  }
434
552
  }
435
553
  }
436
- function enqueueBatchedSignal(signal2) {
554
+ function enqueueBatchedSignalImpl(signal2) {
437
555
  if (batchDepth === 0) return false;
438
556
  pendingSignals.add(signal2);
439
557
  return true;
440
558
  }
559
+ function isBatchingImpl() {
560
+ return batchDepth > 0;
561
+ }
441
562
  function flushBatch() {
442
563
  try {
443
564
  for (const signal2 of pendingSignals) {
444
- queueSignalNotification(signal2);
565
+ queueSignalNotification2(signal2);
445
566
  }
446
567
  } finally {
447
568
  pendingSignals.clear();
448
569
  }
449
- drainNotificationQueue();
570
+ drainNotificationQueue2();
450
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;
584
+ }
585
+ var API2 = resolveBatchApi();
586
+ var batch = API2.batch;
587
+ var enqueueBatchedSignal = API2.enqueueBatchedSignal;
588
+ var isBatching = API2.isBatching;
451
589
 
452
590
  // src/core/signals/signal.ts
453
591
  var _g = globalThis;
454
- var _isDev3 = isDev();
592
+ var _isDev4 = isDev();
455
593
  function signal(initial, options) {
456
594
  const state = {
457
595
  value: initial,
@@ -462,11 +600,11 @@ function signal(initial, options) {
462
600
  __activeNode: null,
463
601
  __name: void 0
464
602
  };
465
- const debugName = _isDev3 ? options?.name : void 0;
603
+ const debugName = _isDev4 ? options?.name : void 0;
466
604
  const equalsFn = options?.equals;
467
605
  if (debugName) state.__name = debugName;
468
606
  function get() {
469
- recordDependency(state);
607
+ recordDependency2(state);
470
608
  return state.value;
471
609
  }
472
610
  get.__signal = state;
@@ -479,15 +617,15 @@ function signal(initial, options) {
479
617
  if (equalsFn(prev, newValue)) return;
480
618
  state.value = newValue;
481
619
  state.__v++;
482
- if (_isDev3) {
620
+ if (_isDev4) {
483
621
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
484
622
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
485
623
  }
486
624
  if (!enqueueBatchedSignal(state)) {
487
- notifySubscribers(state);
625
+ notifySubscribers2(state);
488
626
  }
489
627
  };
490
- } else if (_isDev3) {
628
+ } else if (_isDev4) {
491
629
  set = (next) => {
492
630
  const prev = state.value;
493
631
  const newValue = typeof next === "function" ? next(prev) : next;
@@ -497,7 +635,7 @@ function signal(initial, options) {
497
635
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
498
636
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
499
637
  if (!enqueueBatchedSignal(state)) {
500
- notifySubscribers(state);
638
+ notifySubscribers2(state);
501
639
  }
502
640
  };
503
641
  } else {
@@ -508,11 +646,11 @@ function signal(initial, options) {
508
646
  state.value = newValue;
509
647
  state.__v++;
510
648
  if (!enqueueBatchedSignal(state)) {
511
- notifySubscribers(state);
649
+ notifySubscribers2(state);
512
650
  }
513
651
  };
514
652
  }
515
- if (_isDev3) {
653
+ if (_isDev4) {
516
654
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
517
655
  if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
518
656
  }
@@ -591,23 +729,29 @@ function machine(config) {
591
729
  }
592
730
 
593
731
  // src/core/ssr-context.ts
594
- var als = null;
595
- try {
596
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
597
- let mod = null;
598
- const getBuiltin = process.getBuiltinModule;
599
- if (typeof getBuiltin === "function") {
600
- mod = getBuiltin("node:async_hooks");
601
- } else {
602
- const req = Function("return typeof require==='function'?require:null")();
603
- if (req) mod = req("node:async_hooks");
732
+ var SSR_KEY = /* @__PURE__ */ Symbol.for("sibujs.ssr.v1");
733
+ function detectSSRShared() {
734
+ let detected = null;
735
+ try {
736
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
737
+ let mod = null;
738
+ const getBuiltin = process.getBuiltinModule;
739
+ if (typeof getBuiltin === "function") {
740
+ mod = getBuiltin("node:async_hooks");
741
+ } else {
742
+ const req = Function("return typeof require==='function'?require:null")();
743
+ if (req) mod = req("node:async_hooks");
744
+ }
745
+ if (mod) detected = new mod.AsyncLocalStorage();
604
746
  }
605
- if (mod) als = new mod.AsyncLocalStorage();
747
+ } catch {
748
+ detected = null;
606
749
  }
607
- } catch {
608
- als = null;
750
+ return { als: detected, fallbackStore: { ssr: false, suspenseIdCounter: 0 } };
609
751
  }
610
- var fallbackStore = { ssr: false, suspenseIdCounter: 0 };
752
+ var _shared = globalThis[SSR_KEY] ?? (globalThis[SSR_KEY] = detectSSRShared());
753
+ var als = _shared.als;
754
+ var fallbackStore = _shared.fallbackStore;
611
755
  function getSSRStore() {
612
756
  if (als) {
613
757
  const s = als.getStore();
@@ -639,7 +783,7 @@ function drainReruns(ctx) {
639
783
  do {
640
784
  ctx.rerunPending = false;
641
785
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
642
- retrack(ctx.bodyFn, ctx.subscriber);
786
+ retrack2(ctx.bodyFn, ctx.subscriber);
643
787
  } while (ctx.rerunPending && ++reruns <= MAX_RERUNS);
644
788
  if (ctx.rerunPending) {
645
789
  ctx.rerunPending = false;
@@ -668,7 +812,7 @@ function disposeEffect(ctx) {
668
812
  }
669
813
  }
670
814
  try {
671
- cleanup(ctx.subscriber);
815
+ cleanup2(ctx.subscriber);
672
816
  } catch (err) {
673
817
  if (typeof console !== "undefined") {
674
818
  console.warn("[SibuJS effect] dispose threw:", err);
@@ -713,7 +857,7 @@ function effect(effectFn, options) {
713
857
  try {
714
858
  ctx.rerunPending = false;
715
859
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
716
- retrack(ctx.bodyFn, sub);
860
+ retrack2(ctx.bodyFn, sub);
717
861
  if (ctx.rerunPending) drainReruns(ctx);
718
862
  } finally {
719
863
  ctx.running = false;
@@ -729,7 +873,7 @@ function effect(effectFn, options) {
729
873
  ctx.subscriber = sub;
730
874
  ctx.running = true;
731
875
  try {
732
- retrack(ctx.bodyFn, ctx.subscriber);
876
+ retrack2(ctx.bodyFn, ctx.subscriber);
733
877
  if (ctx.rerunPending) drainReruns(ctx);
734
878
  } finally {
735
879
  ctx.running = false;
@@ -981,7 +1125,7 @@ function derived(getter, options) {
981
1125
  cs._d = false;
982
1126
  cs._init = true;
983
1127
  };
984
- track(() => {
1128
+ track2(() => {
985
1129
  let threw = true;
986
1130
  try {
987
1131
  cs._v = getter();
@@ -1000,12 +1144,12 @@ function derived(getter, options) {
1000
1144
  `[SibuJS] Circular dependency detected in derived${debugName ? ` "${debugName}"` : ""}. A derived signal cannot read itself (directly or through a chain).`
1001
1145
  );
1002
1146
  }
1003
- if (trackingSuspended) {
1147
+ if (isTrackingSuspended2()) {
1004
1148
  if (cs._d) {
1005
1149
  const prev = cs._v;
1006
1150
  evaluating = true;
1007
1151
  try {
1008
- retrack(recompute, markDirty);
1152
+ retrack2(recompute, markDirty);
1009
1153
  if (!Object.is(prev, cs._v)) cs.__v++;
1010
1154
  } finally {
1011
1155
  evaluating = false;
@@ -1013,12 +1157,12 @@ function derived(getter, options) {
1013
1157
  }
1014
1158
  return cs._v;
1015
1159
  }
1016
- recordDependency(cs);
1160
+ recordDependency2(cs);
1017
1161
  if (cs._d) {
1018
1162
  const oldValue = cs._v;
1019
1163
  evaluating = true;
1020
1164
  try {
1021
- retrack(recompute, markDirty);
1165
+ retrack2(recompute, markDirty);
1022
1166
  if (!Object.is(oldValue, cs._v)) cs.__v++;
1023
1167
  } finally {
1024
1168
  evaluating = false;
package/dist/patterns.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  optimisticList,
6
6
  persisted,
7
7
  timeline
8
- } from "./chunk-S4FHR5ZZ.js";
8
+ } from "./chunk-655B7MMR.js";
9
9
  import {
10
10
  RenderProp,
11
11
  assertType,
@@ -23,11 +23,11 @@ import {
23
23
  withWrapper
24
24
  } from "./chunk-VJE6DDYM.js";
25
25
  import "./chunk-H3SRKIYX.js";
26
- import "./chunk-CVMMULHO.js";
27
- import "./chunk-7JHWAGRQ.js";
28
- import "./chunk-GOJMFRBL.js";
29
- import "./chunk-5K72I3UQ.js";
30
- import "./chunk-X3NHE2DK.js";
26
+ import "./chunk-G6N3LMO2.js";
27
+ import "./chunk-N5TQVEKE.js";
28
+ import "./chunk-S3NFJO6L.js";
29
+ import "./chunk-JCQG2I2G.js";
30
+ import "./chunk-4NJEAPLI.js";
31
31
  import "./chunk-COY6PUD2.js";
32
32
  export {
33
33
  RenderProp,