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/browser.cjs CHANGED
@@ -61,7 +61,13 @@ module.exports = __toCommonJS(browser_exports);
61
61
 
62
62
  // src/core/dev.ts
63
63
  function isDev() {
64
- return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
64
+ return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
65
+ // The bare `__SIBU_DEV__` is a bundler define that only exists in
66
+ // production builds; under the test runner it is always undefined, so
67
+ // this branch is unreachable here.
68
+ /* v8 ignore next 2 */
69
+ typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
70
+ );
65
71
  }
66
72
  var _isDev = isDev();
67
73
  function devAssert(condition, message) {
@@ -75,7 +81,7 @@ function devWarn(message) {
75
81
  }
76
82
  }
77
83
 
78
- // src/reactivity/track.ts
84
+ // src/reactivity/track-core.ts
79
85
  var _isDev2 = isDev();
80
86
  var POOL_MAX = 4096;
81
87
  var nodePool = [];
@@ -159,6 +165,7 @@ function unlinkSub(node) {
159
165
  else sub.depsTail = prev;
160
166
  }
161
167
  var currentSubscriber = null;
168
+ var suspendSavedSub = null;
162
169
  var notifyDepth = 0;
163
170
  var pendingQueue = [];
164
171
  var pendingSet = /* @__PURE__ */ new Set();
@@ -170,6 +177,35 @@ function safeInvoke(sub) {
170
177
  if (_isDev2) devWarn(`Subscriber threw during notification: ${err instanceof Error ? err.message : String(err)}`);
171
178
  }
172
179
  }
180
+ var suspendDepth = 0;
181
+ var trackingSuspended = false;
182
+ function suspendTracking() {
183
+ if (suspendDepth === 0) {
184
+ suspendSavedSub = currentSubscriber;
185
+ currentSubscriber = null;
186
+ trackingSuspended = true;
187
+ }
188
+ suspendDepth++;
189
+ }
190
+ function resumeTracking() {
191
+ suspendDepth--;
192
+ if (suspendDepth === 0) {
193
+ currentSubscriber = suspendSavedSub;
194
+ suspendSavedSub = null;
195
+ trackingSuspended = false;
196
+ }
197
+ }
198
+ function isTrackingSuspended() {
199
+ return trackingSuspended;
200
+ }
201
+ function untracked(fn) {
202
+ suspendTracking();
203
+ try {
204
+ return fn();
205
+ } finally {
206
+ resumeTracking();
207
+ }
208
+ }
173
209
  var subscriberEpochCounter = 0;
174
210
  function retrack(effectFn, subscriber) {
175
211
  const prev = currentSubscriber;
@@ -202,6 +238,51 @@ function retrack(effectFn, subscriber) {
202
238
  }
203
239
  }
204
240
  }
241
+ function track(effectFn, subscriber) {
242
+ if (!subscriber) return reactiveBinding(effectFn);
243
+ cleanup(subscriber);
244
+ const prev = currentSubscriber;
245
+ currentSubscriber = subscriber;
246
+ try {
247
+ effectFn();
248
+ } finally {
249
+ currentSubscriber = prev;
250
+ const sub2 = subscriber;
251
+ for (let n = sub2.depsHead ?? null; n !== null; n = n.subNext) {
252
+ const sig = n.sig;
253
+ sig.__activeNode = n.prevActive;
254
+ n.prevActive = null;
255
+ }
256
+ }
257
+ const sub = subscriber;
258
+ return sub._dispose ?? (sub._dispose = () => cleanup(subscriber));
259
+ }
260
+ function reactiveBinding(commit) {
261
+ const run = () => {
262
+ const s = subscriber;
263
+ if (s._disposed || s._reentrant) return;
264
+ s._reentrant = true;
265
+ try {
266
+ retrack(commit, subscriber);
267
+ } finally {
268
+ s._reentrant = false;
269
+ }
270
+ };
271
+ const subscriber = run;
272
+ subscriber.depsHead = null;
273
+ subscriber.depsTail = null;
274
+ subscriber._epoch = 0;
275
+ subscriber._structDirty = false;
276
+ subscriber._runEpoch = 0;
277
+ subscriber._runs = 0;
278
+ subscriber._reentrant = false;
279
+ subscriber._disposed = false;
280
+ run();
281
+ return subscriber._dispose ?? (subscriber._dispose = () => {
282
+ subscriber._disposed = true;
283
+ cleanup(subscriber);
284
+ });
285
+ }
205
286
  function recordDependency(signal2) {
206
287
  if (!currentSubscriber) return;
207
288
  const sub = currentSubscriber;
@@ -234,6 +315,16 @@ function cleanup(subscriber) {
234
315
  var maxSubscriberRepeats = 50;
235
316
  var maxDrainIterations = 1e6;
236
317
  var drainEpoch = 0;
318
+ function setMaxSubscriberRepeats(n) {
319
+ const prev = maxSubscriberRepeats;
320
+ if (Number.isFinite(n) && n > 0) maxSubscriberRepeats = Math.floor(n);
321
+ return prev;
322
+ }
323
+ function setMaxDrainIterations(n) {
324
+ const prev = maxDrainIterations;
325
+ if (Number.isFinite(n) && n > 0) maxDrainIterations = Math.floor(n);
326
+ return prev;
327
+ }
237
328
  function tickRepeat(sub) {
238
329
  const s = sub;
239
330
  if (s._runEpoch !== drainEpoch) {
@@ -382,11 +473,90 @@ function notifySubscribers(signal2) {
382
473
  }
383
474
  }
384
475
  }
476
+ function getSubscriberCount(signal2) {
477
+ return signal2.__sc ?? 0;
478
+ }
479
+ function getSubscriberDeps(subscriber) {
480
+ const sub = subscriber;
481
+ const out = [];
482
+ let node = sub.depsHead ?? null;
483
+ while (node) {
484
+ if (node.sig) out.push(node.sig);
485
+ node = node.subNext;
486
+ }
487
+ return out;
488
+ }
489
+ function forEachSubscriber(signal2, visit) {
490
+ let node = signal2.subsHead ?? null;
491
+ while (node) {
492
+ const s = node.sub;
493
+ if (s) visit(s);
494
+ node = node.sigNext;
495
+ }
496
+ }
497
+
498
+ // src/reactivity/track.ts
499
+ var _isDev3 = isDev();
500
+ var _runtimeVersion = typeof __SIBU_VERSION__ !== "undefined" ? __SIBU_VERSION__ : "dev";
501
+ var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
502
+ function resolveReactiveApi() {
503
+ const g = globalThis;
504
+ const existing = g[REGISTRY_KEY];
505
+ if (existing) {
506
+ if (_isDev3 && !existing.__dupWarned) {
507
+ existing.__dupWarned = true;
508
+ devWarn(
509
+ `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']).`
510
+ );
511
+ }
512
+ return existing;
513
+ }
514
+ const local = {
515
+ suspendTracking,
516
+ resumeTracking,
517
+ isTrackingSuspended,
518
+ untracked,
519
+ retrack,
520
+ track,
521
+ reactiveBinding,
522
+ recordDependency,
523
+ cleanup,
524
+ setMaxSubscriberRepeats,
525
+ setMaxDrainIterations,
526
+ drainNotificationQueue,
527
+ queueSignalNotification,
528
+ notifySubscribers,
529
+ getSubscriberCount,
530
+ getSubscriberDeps,
531
+ forEachSubscriber,
532
+ version: _runtimeVersion
533
+ };
534
+ g[REGISTRY_KEY] = local;
535
+ return local;
536
+ }
537
+ var API = resolveReactiveApi();
538
+ var suspendTracking2 = API.suspendTracking;
539
+ var resumeTracking2 = API.resumeTracking;
540
+ var isTrackingSuspended2 = API.isTrackingSuspended;
541
+ var untracked2 = API.untracked;
542
+ var retrack2 = API.retrack;
543
+ var track2 = API.track;
544
+ var reactiveBinding2 = API.reactiveBinding;
545
+ var recordDependency2 = API.recordDependency;
546
+ var cleanup2 = API.cleanup;
547
+ var setMaxSubscriberRepeats2 = API.setMaxSubscriberRepeats;
548
+ var setMaxDrainIterations2 = API.setMaxDrainIterations;
549
+ var drainNotificationQueue2 = API.drainNotificationQueue;
550
+ var queueSignalNotification2 = API.queueSignalNotification;
551
+ var notifySubscribers2 = API.notifySubscribers;
552
+ var getSubscriberCount2 = API.getSubscriberCount;
553
+ var getSubscriberDeps2 = API.getSubscriberDeps;
554
+ var forEachSubscriber2 = API.forEachSubscriber;
385
555
 
386
556
  // src/reactivity/batch.ts
387
557
  var batchDepth = 0;
388
558
  var pendingSignals = /* @__PURE__ */ new Set();
389
- function batch(fn) {
559
+ function batchImpl(fn) {
390
560
  batchDepth++;
391
561
  try {
392
562
  return fn();
@@ -397,25 +567,45 @@ function batch(fn) {
397
567
  }
398
568
  }
399
569
  }
400
- function enqueueBatchedSignal(signal2) {
570
+ function enqueueBatchedSignalImpl(signal2) {
401
571
  if (batchDepth === 0) return false;
402
572
  pendingSignals.add(signal2);
403
573
  return true;
404
574
  }
575
+ function isBatchingImpl() {
576
+ return batchDepth > 0;
577
+ }
405
578
  function flushBatch() {
406
579
  try {
407
580
  for (const signal2 of pendingSignals) {
408
- queueSignalNotification(signal2);
581
+ queueSignalNotification2(signal2);
409
582
  }
410
583
  } finally {
411
584
  pendingSignals.clear();
412
585
  }
413
- drainNotificationQueue();
586
+ drainNotificationQueue2();
587
+ }
588
+ var BATCH_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.batch.v1");
589
+ function resolveBatchApi() {
590
+ const g = globalThis;
591
+ const existing = g[BATCH_REGISTRY_KEY];
592
+ if (existing) return existing;
593
+ const local = {
594
+ batch: batchImpl,
595
+ enqueueBatchedSignal: enqueueBatchedSignalImpl,
596
+ isBatching: isBatchingImpl
597
+ };
598
+ g[BATCH_REGISTRY_KEY] = local;
599
+ return local;
414
600
  }
601
+ var API2 = resolveBatchApi();
602
+ var batch = API2.batch;
603
+ var enqueueBatchedSignal = API2.enqueueBatchedSignal;
604
+ var isBatching = API2.isBatching;
415
605
 
416
606
  // src/core/signals/signal.ts
417
607
  var _g = globalThis;
418
- var _isDev3 = isDev();
608
+ var _isDev4 = isDev();
419
609
  function signal(initial, options) {
420
610
  const state = {
421
611
  value: initial,
@@ -426,11 +616,11 @@ function signal(initial, options) {
426
616
  __activeNode: null,
427
617
  __name: void 0
428
618
  };
429
- const debugName = _isDev3 ? options?.name : void 0;
619
+ const debugName = _isDev4 ? options?.name : void 0;
430
620
  const equalsFn = options?.equals;
431
621
  if (debugName) state.__name = debugName;
432
622
  function get() {
433
- recordDependency(state);
623
+ recordDependency2(state);
434
624
  return state.value;
435
625
  }
436
626
  get.__signal = state;
@@ -443,15 +633,15 @@ function signal(initial, options) {
443
633
  if (equalsFn(prev, newValue)) return;
444
634
  state.value = newValue;
445
635
  state.__v++;
446
- if (_isDev3) {
636
+ if (_isDev4) {
447
637
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
448
638
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
449
639
  }
450
640
  if (!enqueueBatchedSignal(state)) {
451
- notifySubscribers(state);
641
+ notifySubscribers2(state);
452
642
  }
453
643
  };
454
- } else if (_isDev3) {
644
+ } else if (_isDev4) {
455
645
  set = (next) => {
456
646
  const prev = state.value;
457
647
  const newValue = typeof next === "function" ? next(prev) : next;
@@ -461,7 +651,7 @@ function signal(initial, options) {
461
651
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
462
652
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue: prev, newValue });
463
653
  if (!enqueueBatchedSignal(state)) {
464
- notifySubscribers(state);
654
+ notifySubscribers2(state);
465
655
  }
466
656
  };
467
657
  } else {
@@ -472,11 +662,11 @@ function signal(initial, options) {
472
662
  state.value = newValue;
473
663
  state.__v++;
474
664
  if (!enqueueBatchedSignal(state)) {
475
- notifySubscribers(state);
665
+ notifySubscribers2(state);
476
666
  }
477
667
  };
478
668
  }
479
- if (_isDev3) {
669
+ if (_isDev4) {
480
670
  const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
481
671
  if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
482
672
  }
@@ -551,7 +741,7 @@ function drainReruns(ctx) {
551
741
  do {
552
742
  ctx.rerunPending = false;
553
743
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
554
- retrack(ctx.bodyFn, ctx.subscriber);
744
+ retrack2(ctx.bodyFn, ctx.subscriber);
555
745
  } while (ctx.rerunPending && ++reruns <= MAX_RERUNS);
556
746
  if (ctx.rerunPending) {
557
747
  ctx.rerunPending = false;
@@ -580,7 +770,7 @@ function disposeEffect(ctx) {
580
770
  }
581
771
  }
582
772
  try {
583
- cleanup(ctx.subscriber);
773
+ cleanup2(ctx.subscriber);
584
774
  } catch (err) {
585
775
  if (typeof console !== "undefined") {
586
776
  console.warn("[SibuJS effect] dispose threw:", err);
@@ -625,7 +815,7 @@ function effect(effectFn, options) {
625
815
  try {
626
816
  ctx.rerunPending = false;
627
817
  if (ctx.userCleanups.length > 0) flushUserCleanups(ctx);
628
- retrack(ctx.bodyFn, sub);
818
+ retrack2(ctx.bodyFn, sub);
629
819
  if (ctx.rerunPending) drainReruns(ctx);
630
820
  } finally {
631
821
  ctx.running = false;
@@ -641,7 +831,7 @@ function effect(effectFn, options) {
641
831
  ctx.subscriber = sub;
642
832
  ctx.running = true;
643
833
  try {
644
- retrack(ctx.bodyFn, ctx.subscriber);
834
+ retrack2(ctx.bodyFn, ctx.subscriber);
645
835
  if (ctx.rerunPending) drainReruns(ctx);
646
836
  } finally {
647
837
  ctx.running = false;
@@ -665,7 +855,7 @@ function resize(target) {
665
855
  } };
666
856
  }
667
857
  const getter = resolveTarget(target);
668
- const cleanup2 = effect(() => {
858
+ const cleanup3 = effect(() => {
669
859
  const el = getter();
670
860
  if (observer) {
671
861
  observer.disconnect();
@@ -684,7 +874,7 @@ function resize(target) {
684
874
  observer.observe(el);
685
875
  });
686
876
  function dispose() {
687
- cleanup2();
877
+ cleanup3();
688
878
  if (observer) {
689
879
  observer.disconnect();
690
880
  observer = null;
@@ -961,7 +1151,7 @@ function draggable(element, data) {
961
1151
  let onDragStart = null;
962
1152
  let onDragEnd = null;
963
1153
  const getter = resolveTarget2(element);
964
- const cleanup2 = effect(() => {
1154
+ const cleanup3 = effect(() => {
965
1155
  if (currentEl && onDragStart && onDragEnd) {
966
1156
  currentEl.removeEventListener("dragstart", onDragStart);
967
1157
  currentEl.removeEventListener("dragend", onDragEnd);
@@ -983,7 +1173,7 @@ function draggable(element, data) {
983
1173
  el.addEventListener("dragend", onDragEnd);
984
1174
  });
985
1175
  function dispose() {
986
- cleanup2();
1176
+ cleanup3();
987
1177
  if (currentEl && onDragStart && onDragEnd) {
988
1178
  currentEl.removeEventListener("dragstart", onDragStart);
989
1179
  currentEl.removeEventListener("dragend", onDragEnd);
@@ -1004,7 +1194,7 @@ function dropZone(element, options) {
1004
1194
  let onDragLeave = null;
1005
1195
  let onDrop = null;
1006
1196
  const getter = resolveTarget2(element);
1007
- const cleanup2 = effect(() => {
1197
+ const cleanup3 = effect(() => {
1008
1198
  if (currentEl && onDragOver && onDragEnter && onDragLeave && onDrop) {
1009
1199
  currentEl.removeEventListener("dragover", onDragOver);
1010
1200
  currentEl.removeEventListener("dragenter", onDragEnter);
@@ -1046,7 +1236,7 @@ function dropZone(element, options) {
1046
1236
  el.addEventListener("drop", onDrop);
1047
1237
  });
1048
1238
  function dispose() {
1049
- cleanup2();
1239
+ cleanup3();
1050
1240
  if (currentEl && onDragOver && onDragEnter && onDragLeave && onDrop) {
1051
1241
  currentEl.removeEventListener("dragover", onDragOver);
1052
1242
  currentEl.removeEventListener("dragenter", onDragEnter);
@@ -1066,11 +1256,11 @@ function title(value) {
1066
1256
  }
1067
1257
  const previousTitle = document.title;
1068
1258
  if (typeof value === "function") {
1069
- const cleanup2 = effect(() => {
1259
+ const cleanup3 = effect(() => {
1070
1260
  document.title = value();
1071
1261
  });
1072
1262
  return () => {
1073
- cleanup2();
1263
+ cleanup3();
1074
1264
  document.title = previousTitle;
1075
1265
  };
1076
1266
  }
package/dist/browser.js CHANGED
@@ -35,13 +35,13 @@ import {
35
35
  visibility,
36
36
  wakeLock,
37
37
  windowSize
38
- } from "./chunk-GOUM4JCT.js";
38
+ } from "./chunk-VOVVTOEA.js";
39
39
  import "./chunk-H3SRKIYX.js";
40
- import "./chunk-FDY42FIU.js";
40
+ import "./chunk-MHBCEJQO.js";
41
41
  import "./chunk-GOJMFRBL.js";
42
- import "./chunk-C427DVQF.js";
43
- import "./chunk-Z2FWAE4B.js";
44
- import "./chunk-LMLD24FC.js";
42
+ import "./chunk-WZG2SZOT.js";
43
+ import "./chunk-TEFZT5PJ.js";
44
+ import "./chunk-COY6PUD2.js";
45
45
  export {
46
46
  animationFrame,
47
47
  battery,