sibujs 4.5.0 → 4.6.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 (109) hide show
  1. package/dist/browser.cjs +309 -129
  2. package/dist/browser.d.cts +46 -14
  3. package/dist/browser.d.ts +46 -14
  4. package/dist/browser.js +8 -6
  5. package/dist/build.cjs +184 -72
  6. package/dist/build.js +15 -16
  7. package/dist/cdn.dev.global.js +12 -12
  8. package/dist/cdn.full.dev.global.js +11 -11
  9. package/dist/cdn.full.global.js +10 -10
  10. package/dist/cdn.global.js +12 -12
  11. package/dist/{chunk-IXKSNWV5.js → chunk-2INLLLMZ.js} +1 -1
  12. package/dist/chunk-3ISI6ACU.js +44 -0
  13. package/dist/{chunk-ONOHFDLG.js → chunk-47M47FOM.js} +3 -3
  14. package/dist/chunk-5HZXGZ6T.js +24 -0
  15. package/dist/{chunk-KKLW7YWL.js → chunk-5MT6SJ3P.js} +275 -144
  16. package/dist/{chunk-UGRX3S57.js → chunk-5Q4R7HCL.js} +12 -3
  17. package/dist/{chunk-S373NSMK.js → chunk-7GQCWFOE.js} +150 -59
  18. package/dist/{chunk-FTIR4QW2.js → chunk-7NCARGJW.js} +6 -8
  19. package/dist/{chunk-5DXA2J44.js → chunk-7XHATCIH.js} +5 -2
  20. package/dist/{chunk-VZKNK2V7.js → chunk-AIF3Z2T7.js} +296 -38
  21. package/dist/{chunk-4PMLNECI.js → chunk-BAAG6ZTI.js} +98 -29
  22. package/dist/{chunk-XZZOBQAY.js → chunk-D33YTSX5.js} +2 -2
  23. package/dist/{chunk-TBYTO6BS.js → chunk-DKGBBKOF.js} +136 -80
  24. package/dist/{chunk-NIOYEGBQ.js → chunk-HURREPU2.js} +27 -13
  25. package/dist/{chunk-GW3SCCZG.js → chunk-HYXDKS4N.js} +153 -110
  26. package/dist/chunk-J6FW5TV6.js +233 -0
  27. package/dist/{chunk-PCT43HW3.js → chunk-JSXPZCET.js} +1 -1
  28. package/dist/chunk-NYNYSPK7.js +318 -0
  29. package/dist/{chunk-RJE2BNI4.js → chunk-ORMZXBKQ.js} +108 -45
  30. package/dist/{chunk-OMJJM3KM.js → chunk-OXUY2A6L.js} +287 -130
  31. package/dist/{chunk-3JZ4L5TJ.js → chunk-PK6FK2G2.js} +181 -66
  32. package/dist/{chunk-RBTPLM32.js → chunk-QE4TTDU3.js} +2 -2
  33. package/dist/{chunk-2DCGACUU.js → chunk-SXXVZMKZ.js} +251 -66
  34. package/dist/{chunk-R25EFXXC.js → chunk-TUCPL2HB.js} +3 -3
  35. package/dist/{chunk-7LN645I6.js → chunk-UZQ6ALFS.js} +3 -3
  36. package/dist/{chunk-KEISJXBU.js → chunk-VVWPJ543.js} +6 -8
  37. package/dist/{chunk-RIXRAYIU.js → chunk-XC4MEKGA.js} +3 -3
  38. package/dist/{chunk-B3WHI2QA.js → chunk-XRRZKZYX.js} +55 -31
  39. package/dist/{contracts-DBdg9J_a.d.cts → contracts-DRIuclVT.d.cts} +10 -2
  40. package/dist/{contracts-DBdg9J_a.d.ts → contracts-DRIuclVT.d.ts} +10 -2
  41. package/dist/{customElement-OB9CIsc5.d.cts → customElement-MmInOW1U.d.cts} +21 -0
  42. package/dist/{customElement-OB9CIsc5.d.ts → customElement-MmInOW1U.d.ts} +21 -0
  43. package/dist/data.cjs +213 -117
  44. package/dist/data.d.cts +47 -9
  45. package/dist/data.d.ts +47 -9
  46. package/dist/data.js +12 -9
  47. package/dist/devtools.cjs +81 -57
  48. package/dist/devtools.js +7 -8
  49. package/dist/dispose-GEIG2KOF.js +28 -0
  50. package/dist/ecosystem.cjs +309 -104
  51. package/dist/ecosystem.d.cts +19 -3
  52. package/dist/ecosystem.d.ts +19 -3
  53. package/dist/ecosystem.js +12 -12
  54. package/dist/extras.cjs +2133 -863
  55. package/dist/extras.d.cts +10 -9
  56. package/dist/extras.d.ts +10 -9
  57. package/dist/extras.js +39 -28
  58. package/dist/index.cjs +184 -72
  59. package/dist/index.d.cts +22 -5
  60. package/dist/index.d.ts +22 -5
  61. package/dist/index.js +24 -27
  62. package/dist/motion.cjs +107 -41
  63. package/dist/motion.js +5 -5
  64. package/dist/patterns.cjs +317 -39
  65. package/dist/patterns.d.cts +27 -9
  66. package/dist/patterns.d.ts +27 -9
  67. package/dist/patterns.js +8 -8
  68. package/dist/performance.cjs +308 -216
  69. package/dist/performance.d.cts +2 -2
  70. package/dist/performance.d.ts +2 -2
  71. package/dist/performance.js +8 -9
  72. package/dist/plugin-DVgSnTfK.d.cts +112 -0
  73. package/dist/plugin-DVgSnTfK.d.ts +112 -0
  74. package/dist/plugins.cjs +549 -202
  75. package/dist/plugins.d.cts +3 -3
  76. package/dist/plugins.d.ts +3 -3
  77. package/dist/plugins.js +35 -23
  78. package/dist/signal-EotCj4hS.d.cts +110 -0
  79. package/dist/signal-EotCj4hS.d.ts +110 -0
  80. package/dist/{ssr-BiPRdZ6n.d.cts → ssr-Bli9XRW5.d.cts} +5 -0
  81. package/dist/{ssr-BiPRdZ6n.d.ts → ssr-Bli9XRW5.d.ts} +5 -0
  82. package/dist/{ssr-Y7XOEPEN.js → ssr-XOTUASDO.js} +4 -5
  83. package/dist/ssr.cjs +176 -72
  84. package/dist/ssr.d.cts +9 -3
  85. package/dist/ssr.d.ts +9 -3
  86. package/dist/ssr.js +11 -12
  87. package/dist/{startup-BMpaiMhP.d.ts → startup-BLfSeL15.d.cts} +73 -22
  88. package/dist/{startup-BMpaiMhP.d.cts → startup-BLfSeL15.d.ts} +73 -22
  89. package/dist/{tagFactory-DVoDpHye.d.ts → tagFactory-DFstCLQV.d.cts} +2 -100
  90. package/dist/{tagFactory-DVoDpHye.d.cts → tagFactory-DkaNVUNV.d.ts} +2 -100
  91. package/dist/testing.cjs +2484 -2185
  92. package/dist/testing.d.cts +56 -5
  93. package/dist/testing.d.ts +56 -5
  94. package/dist/testing.js +580 -307
  95. package/dist/ui.cjs +707 -317
  96. package/dist/ui.d.cts +40 -7
  97. package/dist/ui.d.ts +40 -7
  98. package/dist/ui.js +151 -56
  99. package/dist/widgets.cjs +246 -278
  100. package/dist/widgets.js +9 -10
  101. package/package.json +1 -1
  102. package/dist/chunk-2WLZ6757.js +0 -149
  103. package/dist/chunk-CCSJMTRN.js +0 -15
  104. package/dist/chunk-QKRPLZ2V.js +0 -108
  105. package/dist/chunk-VUF4ALSW.js +0 -60
  106. package/dist/chunk-WWV3SJ3L.js +0 -131
  107. package/dist/dispose-46BOMMQJ.js +0 -19
  108. package/dist/plugin-D30wlGW5.d.cts +0 -71
  109. package/dist/plugin-D30wlGW5.d.ts +0 -71
@@ -6,29 +6,30 @@ import {
6
6
  import {
7
7
  div,
8
8
  span
9
- } from "./chunk-PCT43HW3.js";
9
+ } from "./chunk-JSXPZCET.js";
10
10
  import {
11
11
  STATIC_VALUE_RESOLVER,
12
12
  planHeadElementEntry,
13
13
  planMetaEntry
14
- } from "./chunk-NIOYEGBQ.js";
14
+ } from "./chunk-HURREPU2.js";
15
15
  import {
16
16
  sanitizeUrl
17
- } from "./chunk-IXKSNWV5.js";
17
+ } from "./chunk-2INLLLMZ.js";
18
18
  import {
19
19
  globalSingleton
20
20
  } from "./chunk-7ZHH77QA.js";
21
21
  import {
22
22
  effect
23
- } from "./chunk-RIXRAYIU.js";
24
- import {
25
- registerDisposer,
26
- replaceChildrenSafely
27
- } from "./chunk-QKRPLZ2V.js";
23
+ } from "./chunk-XC4MEKGA.js";
28
24
  import {
29
25
  batch,
30
26
  signal
31
- } from "./chunk-XZZOBQAY.js";
27
+ } from "./chunk-D33YTSX5.js";
28
+ import {
29
+ registerDisposer,
30
+ replaceChildrenSafely,
31
+ reportError
32
+ } from "./chunk-NYNYSPK7.js";
32
33
 
33
34
  // src/platform/head.ts
34
35
  function escapeScriptJsonLocal(json) {
@@ -96,7 +97,7 @@ function Head(props) {
96
97
  };
97
98
  const apply = () => {
98
99
  cleanup();
99
- if (props.title) {
100
+ if (props.title != null) {
100
101
  if (typeof props.title === "function") {
101
102
  const getter = props.title;
102
103
  let lease = null;
@@ -151,13 +152,14 @@ function Head(props) {
151
152
  return anchor;
152
153
  }
153
154
  function setStructuredData(data) {
154
- const existing = document.head.querySelector('script[type="application/ld+json"][data-sibu]');
155
- if (existing) existing.remove();
155
+ const json = escapeScriptJsonLocal(JSON.stringify(data));
156
156
  const script = document.createElement("script");
157
157
  script.type = "application/ld+json";
158
158
  script.setAttribute("data-sibu", "true");
159
- script.textContent = escapeScriptJsonLocal(JSON.stringify(data));
160
- document.head.appendChild(script);
159
+ script.textContent = json;
160
+ const existing = document.head.querySelector('script[type="application/ld+json"][data-sibu]');
161
+ if (existing) existing.replaceWith(script);
162
+ else document.head.appendChild(script);
161
163
  }
162
164
  function setCanonical(url) {
163
165
  let link = document.head.querySelector('link[rel="canonical"]');
@@ -172,6 +174,11 @@ function setCanonical(url) {
172
174
  }
173
175
 
174
176
  // src/platform/worker.ts
177
+ function toError(err) {
178
+ if (err instanceof Error) return err;
179
+ if (err !== null && typeof err === "object" && "name" in err && "message" in err) return err;
180
+ return new Error(String(err));
181
+ }
175
182
  function worker(workerFn2) {
176
183
  const [result, setResult] = signal(null);
177
184
  const [error, setError] = signal(null);
@@ -194,8 +201,11 @@ function worker(workerFn2) {
194
201
  worker2 = new Worker(blobUrl);
195
202
  worker2.addEventListener("message", (e) => {
196
203
  revokeBlobUrl();
197
- setResult(e.data);
198
- setLoading(false);
204
+ batch(() => {
205
+ setResult(e.data);
206
+ setError(null);
207
+ setLoading(false);
208
+ });
199
209
  });
200
210
  worker2.addEventListener("error", (e) => {
201
211
  revokeBlobUrl();
@@ -212,10 +222,17 @@ function worker(workerFn2) {
212
222
  }
213
223
  function post(data) {
214
224
  if (!worker2) return;
215
- setLoading(true);
216
- setError(null);
217
- setResult(null);
218
- worker2.postMessage(data);
225
+ try {
226
+ worker2.postMessage(data);
227
+ } catch (err) {
228
+ setError(toError(err));
229
+ return;
230
+ }
231
+ batch(() => {
232
+ setLoading(true);
233
+ setError(null);
234
+ setResult(null);
235
+ });
219
236
  }
220
237
  function terminate() {
221
238
  if (!worker2) return;
@@ -279,9 +296,14 @@ function workerFn(fn) {
279
296
  reject(new Error("Worker is not available"));
280
297
  return;
281
298
  }
282
- setLoading(true);
299
+ try {
300
+ worker2.postMessage(args);
301
+ } catch (err) {
302
+ reject(toError(err));
303
+ return;
304
+ }
283
305
  queue.push({ resolve, reject });
284
- worker2.postMessage(args);
306
+ setLoading(true);
285
307
  });
286
308
  }
287
309
  function terminate() {
@@ -311,7 +333,11 @@ function createWorkerPool(workerFn2, poolSize) {
311
333
  }
312
334
  };
313
335
  function dispatchNext(idx) {
314
- if (!alive || inflight[idx] || queues[idx].length === 0) return;
336
+ while (alive && !inflight[idx] && queues[idx].length > 0) {
337
+ dispatchOne(idx);
338
+ }
339
+ }
340
+ function dispatchOne(idx) {
315
341
  const w = workers[idx];
316
342
  const slot = queues[idx].shift();
317
343
  const onMsg = (e) => {
@@ -336,10 +362,15 @@ function createWorkerPool(workerFn2, poolSize) {
336
362
  slot.reject(new Error(e.message || "Worker error"));
337
363
  dispatchNext(idx);
338
364
  };
365
+ try {
366
+ w.postMessage(slot.data);
367
+ } catch (err) {
368
+ slot.reject(toError(err));
369
+ return;
370
+ }
339
371
  inflight[idx] = { ...slot, onMsg, onErr };
340
372
  w.addEventListener("message", onMsg);
341
373
  w.addEventListener("error", onErr);
342
- w.postMessage(slot.data);
343
374
  }
344
375
  try {
345
376
  if (typeof Worker === "undefined") {
@@ -668,13 +699,13 @@ function createSharedScope(initialState) {
668
699
  for (const key of Object.keys(initialState)) {
669
700
  const [get2, set2] = signal(initialState[key]);
670
701
  signals.set(key, { get: get2, set: set2 });
671
- subscribers.set(key, /* @__PURE__ */ new Set());
702
+ subscribers.set(key, /* @__PURE__ */ new Map());
672
703
  }
673
704
  function ensureSignal(key) {
674
705
  if (!signals.has(key)) {
675
706
  const [get2, set2] = signal(void 0);
676
707
  signals.set(key, { get: get2, set: set2 });
677
- subscribers.set(key, /* @__PURE__ */ new Set());
708
+ subscribers.set(key, /* @__PURE__ */ new Map());
678
709
  }
679
710
  }
680
711
  function get(key) {
@@ -685,9 +716,14 @@ function createSharedScope(initialState) {
685
716
  ensureSignal(key);
686
717
  signals.get(key)?.set(value);
687
718
  const subs = subscribers.get(key);
688
- if (subs) {
689
- for (const cb of subs) {
690
- cb(value);
719
+ if (subs && subs.size > 0) {
720
+ for (const subscription of Array.from(subs.values())) {
721
+ if (!subscription.active) continue;
722
+ try {
723
+ subscription.callback(value);
724
+ } catch (err) {
725
+ reportError(err, { phase: "event", name: `sharedScope(${String(key)})` });
726
+ }
691
727
  }
692
728
  }
693
729
  }
@@ -698,9 +734,17 @@ function createSharedScope(initialState) {
698
734
  return () => {
699
735
  };
700
736
  }
701
- subs.add(callback);
737
+ const cb = callback;
738
+ let subscription = subs.get(cb);
739
+ if (!subscription) {
740
+ subscription = { callback: cb, active: true };
741
+ subs.set(cb, subscription);
742
+ }
743
+ const own = subscription;
702
744
  return () => {
703
- subs.delete(callback);
745
+ if (subs.get(cb) !== own) return;
746
+ own.active = false;
747
+ subs.delete(cb);
704
748
  };
705
749
  }
706
750
  return { get, set, subscribe };
@@ -852,15 +896,31 @@ async function generateStaticSite(options) {
852
896
  // src/platform/incrementalRegeneration.ts
853
897
  function createISR(options) {
854
898
  const { revalidateAfter, fetcher, initialData } = options;
899
+ if (!Number.isFinite(revalidateAfter) || revalidateAfter <= 0) {
900
+ throw new RangeError(`[SibuJS ISR] revalidateAfter must be a positive finite number, got ${revalidateAfter}`);
901
+ }
855
902
  const [data, setData] = signal(initialData);
856
- const [timestamp, setTimestamp] = signal(initialData !== void 0 ? Date.now() : 0);
903
+ const [stale, setStale] = signal(initialData === void 0);
857
904
  const controller = new AbortController();
858
905
  let inFlight = false;
859
906
  let disposed = false;
860
- const isStale = () => {
861
- const ts = timestamp();
862
- if (ts === 0) return true;
863
- return Date.now() - ts >= revalidateAfter;
907
+ let deadline;
908
+ const clearDeadline = () => {
909
+ if (deadline !== void 0) {
910
+ clearTimeout(deadline);
911
+ deadline = void 0;
912
+ }
913
+ };
914
+ const armDeadline = () => {
915
+ clearDeadline();
916
+ deadline = setTimeout(() => {
917
+ deadline = void 0;
918
+ if (disposed) return;
919
+ setStale(true);
920
+ revalidate().catch((err) => {
921
+ if (typeof console !== "undefined") console.warn("[SibuJS ISR] revalidate failed", err);
922
+ });
923
+ }, revalidateAfter);
864
924
  };
865
925
  const revalidate = async () => {
866
926
  if (disposed || inFlight) return;
@@ -869,8 +929,14 @@ function createISR(options) {
869
929
  try {
870
930
  const result = await fetcher({ signal: controller.signal });
871
931
  if (disposed || controller.signal.aborted) return;
872
- setData(result);
873
- setTimestamp(Date.now());
932
+ batch(() => {
933
+ setData(result);
934
+ setStale(false);
935
+ });
936
+ armDeadline();
937
+ } catch (err) {
938
+ if (!disposed && !controller.signal.aborted) armDeadline();
939
+ throw err;
874
940
  } finally {
875
941
  inFlight = false;
876
942
  }
@@ -879,19 +945,16 @@ function createISR(options) {
879
945
  revalidate().catch((err) => {
880
946
  if (typeof console !== "undefined") console.warn("[SibuJS ISR] initial fetch failed", err);
881
947
  });
948
+ } else {
949
+ armDeadline();
882
950
  }
883
- const intervalId = setInterval(() => {
884
- revalidate().catch((err) => {
885
- if (typeof console !== "undefined") console.warn("[SibuJS ISR] revalidate failed", err);
886
- });
887
- }, revalidateAfter);
888
951
  const dispose = () => {
889
952
  if (disposed) return;
890
953
  disposed = true;
891
- clearInterval(intervalId);
954
+ clearDeadline();
892
955
  controller.abort();
893
956
  };
894
- return { data, isStale, revalidate, dispose };
957
+ return { data, isStale: stale, revalidate, dispose };
895
958
  }
896
959
 
897
960
  // src/platform/routeActions.ts