sibujs 4.5.0 → 4.7.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 (116) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +326 -133
  3. package/dist/browser.d.cts +46 -14
  4. package/dist/browser.d.ts +46 -14
  5. package/dist/browser.js +8 -6
  6. package/dist/build.cjs +2094 -1033
  7. package/dist/build.d.cts +133 -44
  8. package/dist/build.d.ts +133 -44
  9. package/dist/build.js +1372 -574
  10. package/dist/cdn.dev.global.js +10 -10
  11. package/dist/cdn.full.dev.global.js +11 -11
  12. package/dist/cdn.full.global.js +10 -10
  13. package/dist/cdn.global.js +10 -10
  14. package/dist/{chunk-2DCGACUU.js → chunk-2BPG2XDA.js} +251 -66
  15. package/dist/{chunk-IXKSNWV5.js → chunk-2INLLLMZ.js} +1 -1
  16. package/dist/{chunk-4PMLNECI.js → chunk-3QWBSL5R.js} +98 -29
  17. package/dist/{chunk-KKLW7YWL.js → chunk-4AWA2PVD.js} +275 -144
  18. package/dist/chunk-5HZXGZ6T.js +24 -0
  19. package/dist/{chunk-PCT43HW3.js → chunk-7LUJQAOJ.js} +1 -1
  20. package/dist/{chunk-5DXA2J44.js → chunk-7XHATCIH.js} +5 -2
  21. package/dist/chunk-BC2SECJD.js +44 -0
  22. package/dist/{chunk-TBYTO6BS.js → chunk-BSY63EM6.js} +136 -80
  23. package/dist/{chunk-FTIR4QW2.js → chunk-DKXRACVN.js} +6 -8
  24. package/dist/{chunk-ONOHFDLG.js → chunk-FNJXNGYZ.js} +3 -3
  25. package/dist/{chunk-XZZOBQAY.js → chunk-FQRUXCEE.js} +6 -5
  26. package/dist/{chunk-NIOYEGBQ.js → chunk-HURREPU2.js} +27 -13
  27. package/dist/chunk-J6FW5TV6.js +233 -0
  28. package/dist/{chunk-UGRX3S57.js → chunk-JWKYU5GV.js} +22 -4
  29. package/dist/chunk-NYNYSPK7.js +318 -0
  30. package/dist/{chunk-RBTPLM32.js → chunk-RUSSKG6G.js} +13 -12
  31. package/dist/{chunk-7LN645I6.js → chunk-SLM3IA34.js} +3 -3
  32. package/dist/{chunk-R25EFXXC.js → chunk-TUCPL2HB.js} +3 -3
  33. package/dist/{chunk-B3WHI2QA.js → chunk-UNWRJRKC.js} +55 -31
  34. package/dist/{chunk-KEISJXBU.js → chunk-UOL2ECCS.js} +44 -17
  35. package/dist/{chunk-RJE2BNI4.js → chunk-VZSG24LS.js} +108 -45
  36. package/dist/{chunk-RIXRAYIU.js → chunk-WEQ3DMVL.js} +10 -4
  37. package/dist/{chunk-3JZ4L5TJ.js → chunk-WOLJZUFQ.js} +354 -90
  38. package/dist/{chunk-S373NSMK.js → chunk-XYV3EDB7.js} +283 -123
  39. package/dist/{chunk-VZKNK2V7.js → chunk-XZR4PXRE.js} +296 -38
  40. package/dist/{chunk-GW3SCCZG.js → chunk-Z3OHK6QT.js} +153 -110
  41. package/dist/{chunk-OMJJM3KM.js → chunk-ZVL7TY4K.js} +287 -130
  42. package/dist/{contracts-DBdg9J_a.d.ts → contracts-CLqzJnOV.d.ts} +36 -17
  43. package/dist/{contracts-DBdg9J_a.d.cts → contracts-CTOJXu-x.d.cts} +36 -17
  44. package/dist/{customElement-OB9CIsc5.d.cts → customElement-MmInOW1U.d.cts} +21 -0
  45. package/dist/{customElement-OB9CIsc5.d.ts → customElement-MmInOW1U.d.ts} +21 -0
  46. package/dist/data.cjs +410 -155
  47. package/dist/data.d.cts +166 -12
  48. package/dist/data.d.ts +166 -12
  49. package/dist/data.js +12 -9
  50. package/dist/devtools.cjs +98 -61
  51. package/dist/devtools.js +7 -8
  52. package/dist/dispose-GEIG2KOF.js +28 -0
  53. package/dist/ecosystem.cjs +372 -126
  54. package/dist/ecosystem.d.cts +20 -3
  55. package/dist/ecosystem.d.ts +20 -3
  56. package/dist/ecosystem.js +12 -12
  57. package/dist/extras.cjs +2366 -909
  58. package/dist/extras.d.cts +11 -9
  59. package/dist/extras.d.ts +11 -9
  60. package/dist/extras.js +39 -28
  61. package/dist/index.cjs +421 -158
  62. package/dist/index.d.cts +213 -171
  63. package/dist/index.d.ts +213 -171
  64. package/dist/index.js +24 -27
  65. package/dist/motion.cjs +118 -44
  66. package/dist/motion.js +5 -5
  67. package/dist/patterns.cjs +344 -53
  68. package/dist/patterns.d.cts +28 -9
  69. package/dist/patterns.d.ts +28 -9
  70. package/dist/patterns.js +8 -8
  71. package/dist/performance.cjs +325 -220
  72. package/dist/performance.d.cts +2 -2
  73. package/dist/performance.d.ts +2 -2
  74. package/dist/performance.js +8 -9
  75. package/dist/plugin-DVgSnTfK.d.cts +112 -0
  76. package/dist/plugin-DVgSnTfK.d.ts +112 -0
  77. package/dist/plugins.cjs +664 -233
  78. package/dist/plugins.d.cts +127 -14
  79. package/dist/plugins.d.ts +127 -14
  80. package/dist/plugins.js +96 -42
  81. package/dist/signal-EotCj4hS.d.cts +110 -0
  82. package/dist/signal-EotCj4hS.d.ts +110 -0
  83. package/dist/{ssr-BiPRdZ6n.d.cts → ssr-Bli9XRW5.d.cts} +5 -0
  84. package/dist/{ssr-BiPRdZ6n.d.ts → ssr-Bli9XRW5.d.ts} +5 -0
  85. package/dist/{ssr-Y7XOEPEN.js → ssr-XOTUASDO.js} +4 -5
  86. package/dist/ssr.cjs +229 -84
  87. package/dist/ssr.d.cts +9 -3
  88. package/dist/ssr.d.ts +9 -3
  89. package/dist/ssr.js +11 -12
  90. package/dist/{startup-BMpaiMhP.d.ts → startup-BLfSeL15.d.cts} +73 -22
  91. package/dist/{startup-BMpaiMhP.d.cts → startup-BLfSeL15.d.ts} +73 -22
  92. package/dist/tagFactory-8qL9LCIx.d.cts +156 -0
  93. package/dist/tagFactory-BL2fymez.d.ts +156 -0
  94. package/dist/testing.cjs +2503 -2191
  95. package/dist/testing.d.cts +56 -5
  96. package/dist/testing.d.ts +56 -5
  97. package/dist/testing.js +580 -307
  98. package/dist/types-CJFViL6Q.d.cts +26 -0
  99. package/dist/types-CJFViL6Q.d.ts +26 -0
  100. package/dist/ui.cjs +732 -329
  101. package/dist/ui.d.cts +41 -7
  102. package/dist/ui.d.ts +41 -7
  103. package/dist/ui.js +151 -56
  104. package/dist/widgets.cjs +267 -291
  105. package/dist/widgets.js +9 -10
  106. package/package.json +4 -2
  107. package/dist/chunk-2WLZ6757.js +0 -149
  108. package/dist/chunk-CCSJMTRN.js +0 -15
  109. package/dist/chunk-QKRPLZ2V.js +0 -108
  110. package/dist/chunk-VUF4ALSW.js +0 -60
  111. package/dist/chunk-WWV3SJ3L.js +0 -131
  112. package/dist/dispose-46BOMMQJ.js +0 -19
  113. package/dist/plugin-D30wlGW5.d.cts +0 -71
  114. package/dist/plugin-D30wlGW5.d.ts +0 -71
  115. package/dist/tagFactory-DVoDpHye.d.cts +0 -215
  116. package/dist/tagFactory-DVoDpHye.d.ts +0 -215
@@ -4,25 +4,42 @@ import {
4
4
  } from "./chunk-H3SRKIYX.js";
5
5
  import {
6
6
  derived
7
- } from "./chunk-RBTPLM32.js";
7
+ } from "./chunk-RUSSKG6G.js";
8
8
  import {
9
9
  effect
10
- } from "./chunk-RIXRAYIU.js";
10
+ } from "./chunk-WEQ3DMVL.js";
11
11
  import {
12
12
  batch,
13
13
  signal
14
- } from "./chunk-XZZOBQAY.js";
14
+ } from "./chunk-FQRUXCEE.js";
15
+ import {
16
+ DEV,
17
+ devWarn,
18
+ reportError
19
+ } from "./chunk-NYNYSPK7.js";
15
20
 
16
21
  // src/patterns/machine.ts
17
22
  function machine(config) {
18
23
  const [state, setState] = signal(config.initial);
19
24
  const [context, setContext] = signal(config.context || {});
20
- const initialDef = config.states[config.initial];
21
- if (initialDef?.entry) {
22
- initialDef.entry(context());
25
+ let currentState = config.initial;
26
+ let currentContext = context();
27
+ const queue = [];
28
+ let processing = false;
29
+ function drain() {
30
+ processing = true;
31
+ try {
32
+ while (queue.length > 0) {
33
+ step(queue.shift());
34
+ }
35
+ } catch (err) {
36
+ queue.length = 0;
37
+ throw err;
38
+ } finally {
39
+ processing = false;
40
+ }
23
41
  }
24
- function send(event) {
25
- const currentState = state();
42
+ function step(event) {
26
43
  const stateDef = config.states[currentState];
27
44
  if (!stateDef?.on) return;
28
45
  const transition = stateDef.on[event];
@@ -37,28 +54,51 @@ function machine(config) {
37
54
  guard = transition.guard;
38
55
  action = transition.action;
39
56
  }
40
- const ctx = context();
57
+ const ctx = currentContext;
41
58
  if (guard && !guard(ctx)) return;
42
59
  if (stateDef.exit) {
43
60
  stateDef.exit(ctx);
44
61
  }
62
+ let nextContext = ctx;
45
63
  if (action) {
46
64
  const rawPatch = action(ctx);
47
- const next = { ...ctx, ...stripUnsafeKeys(rawPatch) };
48
- setContext(next);
65
+ nextContext = { ...ctx, ...stripUnsafeKeys(rawPatch) };
49
66
  }
50
- setState(target);
67
+ currentState = target;
68
+ currentContext = nextContext;
69
+ batch(() => {
70
+ if (action) setContext(nextContext);
71
+ setState(target);
72
+ });
51
73
  const targetDef = config.states[target];
52
74
  if (targetDef?.entry) {
53
- targetDef.entry(context());
75
+ targetDef.entry(currentContext);
76
+ }
77
+ }
78
+ function send(event) {
79
+ queue.push(event);
80
+ if (processing) return;
81
+ drain();
82
+ }
83
+ const initialDef = config.states[config.initial];
84
+ if (initialDef?.entry) {
85
+ processing = true;
86
+ try {
87
+ initialDef.entry(currentContext);
88
+ } catch (err) {
89
+ queue.length = 0;
90
+ throw err;
91
+ } finally {
92
+ processing = false;
54
93
  }
94
+ if (queue.length > 0) drain();
55
95
  }
56
96
  function matches(s) {
57
97
  return state() === s;
58
98
  }
59
99
  function can(event) {
60
- const currentState = state();
61
- const stateDef = config.states[currentState];
100
+ const currentState2 = state();
101
+ const stateDef = config.states[currentState2];
62
102
  if (!stateDef?.on) return false;
63
103
  const transition = stateDef.on[event];
64
104
  if (!transition) return false;
@@ -441,6 +481,9 @@ function optimisticList(initialValue) {
441
481
 
442
482
  // src/patterns/timeTravel.ts
443
483
  function timeline(initial, maxHistory = 100) {
484
+ if (!Number.isSafeInteger(maxHistory) || maxHistory < 1) {
485
+ throw new RangeError(`[timeline] maxHistory must be a positive safe integer, got ${maxHistory}`);
486
+ }
444
487
  const [history, setHistory] = signal([initial]);
445
488
  const [index, setIndex] = signal(0);
446
489
  const value = derived(() => history()[index()]);
@@ -495,6 +538,120 @@ function timeline(initial, maxHistory = 100) {
495
538
  return { value, set, undo, redo, canUndo, canRedo, history, index, reset, jumpTo, dispose };
496
539
  }
497
540
 
541
+ // src/utils/adoption.ts
542
+ var nativeThen = Promise.prototype.then;
543
+ function probeNative(target, onRejected, onOpen) {
544
+ let decided = false;
545
+ const decide = (rejected) => {
546
+ if (decided) return;
547
+ decided = true;
548
+ (rejected ? onRejected : onOpen)();
549
+ };
550
+ try {
551
+ Reflect.apply(nativeThen, target, [void 0, () => decide(true)]);
552
+ } catch {
553
+ queueMicrotask(() => decide(true));
554
+ return;
555
+ }
556
+ queueMicrotask(() => decide(false));
557
+ }
558
+ function adopt(value) {
559
+ if (value === null || typeof value !== "object" && typeof value !== "function") return null;
560
+ let then;
561
+ try {
562
+ then = value.then;
563
+ } catch (error) {
564
+ return {
565
+ promise: Promise.reject(error),
566
+ failedEarly: true,
567
+ probe: (onRejected) => queueMicrotask(onRejected)
568
+ };
569
+ }
570
+ if (typeof then !== "function") return null;
571
+ let resolvePromise;
572
+ let rejectPromise;
573
+ const promise = new Promise((resolve, reject) => {
574
+ resolvePromise = resolve;
575
+ rejectPromise = reject;
576
+ });
577
+ let state = "invoking";
578
+ let nativeTarget;
579
+ const waiters = [];
580
+ const transition = (next) => {
581
+ state = next;
582
+ if (next === "invoking") return;
583
+ for (const waiter of waiters.splice(0)) waiter();
584
+ };
585
+ const fulfil = (result) => {
586
+ resolvePromise(result);
587
+ transition("fulfilled");
588
+ };
589
+ const fail = (error) => {
590
+ rejectPromise(error);
591
+ transition("rejected");
592
+ };
593
+ const follow = (result) => {
594
+ if (result === promise) {
595
+ fail(new TypeError("adopt: a thenable resolved to its own adoption"));
596
+ return;
597
+ }
598
+ if (result === null || typeof result !== "object" && typeof result !== "function") {
599
+ fulfil(result);
600
+ return;
601
+ }
602
+ let nextThen;
603
+ try {
604
+ nextThen = result.then;
605
+ } catch (error) {
606
+ fail(error);
607
+ return;
608
+ }
609
+ if (typeof nextThen !== "function") {
610
+ fulfil(result);
611
+ return;
612
+ }
613
+ invokeLater(result, nextThen);
614
+ };
615
+ const invokeLater = (target, targetThen) => {
616
+ if (targetThen === nativeThen) {
617
+ nativeTarget = target;
618
+ transition("native");
619
+ } else {
620
+ transition("invoking");
621
+ }
622
+ queueMicrotask(() => {
623
+ let done = false;
624
+ const onResolve = (result) => {
625
+ if (done) return;
626
+ done = true;
627
+ follow(result);
628
+ };
629
+ const onReject = (error) => {
630
+ if (done) return;
631
+ done = true;
632
+ fail(error);
633
+ };
634
+ try {
635
+ Reflect.apply(targetThen, target, [onResolve, onReject]);
636
+ } catch (error) {
637
+ onReject(error);
638
+ }
639
+ if (!done && state === "invoking") transition("pending");
640
+ });
641
+ };
642
+ invokeLater(value, then);
643
+ const probe = (onRejected, onOpen) => {
644
+ const decide = () => {
645
+ if (state === "native") probeNative(nativeTarget, onRejected, onOpen);
646
+ else (state === "rejected" ? onRejected : onOpen)();
647
+ };
648
+ if (state === "native") probeNative(nativeTarget, onRejected, onOpen);
649
+ else if (state === "invoking") waiters.push(decide);
650
+ else queueMicrotask(state === "rejected" ? onRejected : onOpen);
651
+ };
652
+ return { promise, failedEarly: false, probe };
653
+ }
654
+
498
655
  // src/patterns/globalStore.ts
499
656
  function deepClone(value) {
500
657
  if (typeof structuredClone === "function") {
@@ -529,8 +686,51 @@ function deepClone(value) {
529
686
  function globalStore(config) {
530
687
  const initialState = deepClone(config.state);
531
688
  const [getState, setState] = signal({ ...initialState });
532
- const listeners = /* @__PURE__ */ new Set();
689
+ const subscriptions = /* @__PURE__ */ new Map();
533
690
  const middlewares = config.middleware || [];
691
+ function notifyListeners(state) {
692
+ if (subscriptions.size === 0) return;
693
+ for (const subscription of Array.from(subscriptions.values())) {
694
+ if (!subscription.active) continue;
695
+ try {
696
+ subscription.callback(state);
697
+ } catch (err) {
698
+ reportError(err, { phase: "event", name: "globalStore(subscribe)" });
699
+ }
700
+ }
701
+ }
702
+ const operations = [];
703
+ let running = false;
704
+ function perform(operation, rethrowOwn = true) {
705
+ operations.push(operation);
706
+ if (running) return;
707
+ running = true;
708
+ let callerError;
709
+ let callerFailed = false;
710
+ try {
711
+ let first = true;
712
+ let cursor = 0;
713
+ while (cursor < operations.length) {
714
+ const next = operations[cursor];
715
+ operations[cursor++] = void 0;
716
+ try {
717
+ next();
718
+ } catch (err) {
719
+ if (first && rethrowOwn) {
720
+ callerFailed = true;
721
+ callerError = err;
722
+ } else {
723
+ reportError(err, { phase: "event", name: "globalStore(dispatch)" });
724
+ }
725
+ }
726
+ first = false;
727
+ }
728
+ } finally {
729
+ operations.length = 0;
730
+ running = false;
731
+ }
732
+ if (callerFailed) throw callerError;
733
+ }
534
734
  function dispatch(action, payload) {
535
735
  const actionFn = config.actions[action];
536
736
  if (!actionFn) throw new Error(`Unknown action: ${String(action)}`);
@@ -539,38 +739,96 @@ function globalStore(config) {
539
739
  const rawPatch = actionFn(current, payload);
540
740
  const patch = stripUnsafeKeys(rawPatch);
541
741
  setState({ ...current, ...patch });
542
- const newState = getState();
543
- for (const listener of listeners) {
544
- listener(newState);
545
- }
742
+ notifyListeners(getState());
546
743
  };
547
- if (middlewares.length === 0) {
548
- execute();
549
- return;
550
- }
551
- let index = 0;
552
- const next = () => {
553
- if (index < middlewares.length) {
554
- const mw = middlewares[index++];
555
- mw(getState(), String(action), payload, next);
556
- } else {
744
+ perform(() => {
745
+ if (middlewares.length === 0) {
557
746
  execute();
747
+ return;
558
748
  }
559
- };
560
- next();
749
+ const runFrom = (index) => {
750
+ if (index >= middlewares.length) {
751
+ execute();
752
+ return;
753
+ }
754
+ let called = false;
755
+ let failed = false;
756
+ let synchronous = true;
757
+ const next = () => {
758
+ if (failed && !called) {
759
+ if (DEV)
760
+ devWarn(
761
+ `globalStore: middleware ${index} next() called after it failed for "${String(action)}"; ignored.`
762
+ );
763
+ called = true;
764
+ return;
765
+ }
766
+ if (called) {
767
+ if (DEV)
768
+ devWarn(
769
+ `globalStore: middleware ${index} next() called more than once for "${String(action)}"; ignored.`
770
+ );
771
+ return;
772
+ }
773
+ called = true;
774
+ if (synchronous) {
775
+ runFrom(index + 1);
776
+ return;
777
+ }
778
+ const proceed = () => perform(() => runFrom(index + 1), false);
779
+ if (!adoption) {
780
+ proceed();
781
+ return;
782
+ }
783
+ adoption.probe(() => {
784
+ failed = true;
785
+ if (DEV)
786
+ devWarn(
787
+ `globalStore: middleware ${index} next() called after it failed for "${String(action)}"; ignored.`
788
+ );
789
+ }, proceed);
790
+ };
791
+ let adoption = null;
792
+ try {
793
+ adoption = adopt(middlewares[index](getState(), String(action), payload, next));
794
+ } catch (err) {
795
+ failed = true;
796
+ throw err;
797
+ } finally {
798
+ synchronous = false;
799
+ }
800
+ if (adoption) {
801
+ if (adoption.failedEarly) failed = true;
802
+ adoption.promise.then(void 0, (err) => {
803
+ failed = true;
804
+ reportError(err, { phase: "async", name: "globalStore(middleware)" });
805
+ });
806
+ }
807
+ };
808
+ runFrom(0);
809
+ });
561
810
  }
562
811
  function select(selector) {
563
812
  return () => selector(getState());
564
813
  }
565
814
  function subscribe(callback) {
566
- listeners.add(callback);
567
- return () => listeners.delete(callback);
815
+ let subscription = subscriptions.get(callback);
816
+ if (!subscription) {
817
+ subscription = { callback, active: true };
818
+ subscriptions.set(callback, subscription);
819
+ }
820
+ const own = subscription;
821
+ return () => {
822
+ if (subscriptions.get(callback) !== own) return;
823
+ own.active = false;
824
+ subscriptions.delete(callback);
825
+ };
568
826
  }
569
827
  function reset() {
570
- setState({ ...initialState });
571
- for (const listener of listeners) {
572
- listener(getState());
573
- }
828
+ perform(() => {
829
+ setState({ ...initialState });
830
+ notifyListeners(getState());
831
+ });
574
832
  }
575
833
  return { getState, select, dispatch, subscribe, reset };
576
834
  }