sibujs 3.0.0 → 3.2.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 (78) hide show
  1. package/README.md +6 -0
  2. package/dist/browser.cjs +16 -8
  3. package/dist/browser.js +6 -5
  4. package/dist/build.cjs +276 -150
  5. package/dist/build.js +35 -24
  6. package/dist/cdn.global.js +7 -7
  7. package/dist/{chunk-RJIRT46U.js → chunk-2C4E3HBM.js} +5 -5
  8. package/dist/{chunk-XDKP4T7G.js → chunk-4JCAUOLN.js} +45 -23
  9. package/dist/{chunk-VSNLICTS.js → chunk-5N74TKLD.js} +1 -1
  10. package/dist/{chunk-XVYB3J6C.js → chunk-7XDYVJLE.js} +19 -9
  11. package/dist/{chunk-L52H775O.js → chunk-BGNLPNGV.js} +20 -12
  12. package/dist/{chunk-6QZO7MMG.js → chunk-C427DVQF.js} +1 -1
  13. package/dist/{chunk-5WD7BYTZ.js → chunk-FDY42FIU.js} +3 -2
  14. package/dist/{chunk-4YTVESDX.js → chunk-FOI23UJL.js} +11 -1
  15. package/dist/{chunk-2RA7SHDA.js → chunk-GOJMFRBL.js} +20 -4
  16. package/dist/{chunk-2KM2724A.js → chunk-GOUM4JCT.js} +6 -6
  17. package/dist/chunk-H3SRKIYX.js +17 -0
  18. package/dist/{chunk-NEWH4O5U.js → chunk-H6PCHJZQ.js} +2 -2
  19. package/dist/{chunk-UCS6AMJ7.js → chunk-HMJFCBRR.js} +26 -3
  20. package/dist/{chunk-JYD2PWXH.js → chunk-HXMS4SNP.js} +22 -15
  21. package/dist/{chunk-DF3GTP4Q.js → chunk-JYXOEYI4.js} +12 -18
  22. package/dist/{chunk-KZA7ANXP.js → chunk-NFYWLRUO.js} +11 -18
  23. package/dist/{chunk-KH4OE6WY.js → chunk-NPIEEKPT.js} +20 -11
  24. package/dist/{chunk-V65KTDZW.js → chunk-OYLPZO4N.js} +33 -15
  25. package/dist/{chunk-LYTCUZ7H.js → chunk-RDRSWYNP.js} +1 -1
  26. package/dist/{chunk-UKMXT5T6.js → chunk-RLUJL2MV.js} +7 -12
  27. package/dist/{chunk-INBOWHQ3.js → chunk-V2MTG5FT.js} +99 -36
  28. package/dist/{chunk-CNZ35WI2.js → chunk-VJE6DDYM.js} +2 -2
  29. package/dist/{chunk-2JQUV4Y3.js → chunk-VOCE4NNK.js} +157 -75
  30. package/dist/{chunk-STFTTMO2.js → chunk-X67UYC74.js} +31 -12
  31. package/dist/{chunk-YMOIAHWA.js → chunk-YFDGQWDA.js} +1 -1
  32. package/dist/{chunk-L4DAT4WU.js → chunk-Z2FWAE4B.js} +28 -1
  33. package/dist/data.cjs +211 -93
  34. package/dist/data.d.cts +7 -1
  35. package/dist/data.d.ts +7 -1
  36. package/dist/data.js +8 -8
  37. package/dist/devtools.cjs +38 -10
  38. package/dist/devtools.d.cts +1 -1
  39. package/dist/devtools.d.ts +1 -1
  40. package/dist/devtools.js +6 -6
  41. package/dist/ecosystem.cjs +163 -65
  42. package/dist/ecosystem.js +9 -9
  43. package/dist/extras.cjs +420 -198
  44. package/dist/extras.d.cts +2 -2
  45. package/dist/extras.d.ts +2 -2
  46. package/dist/extras.js +27 -24
  47. package/dist/index.cjs +255 -139
  48. package/dist/index.d.cts +15 -2
  49. package/dist/index.d.ts +15 -2
  50. package/dist/index.js +15 -13
  51. package/dist/{introspect-BZWKvQUZ.d.ts → introspect-DOZfmC-4.d.ts} +1 -1
  52. package/dist/{introspect-DsJlDD2T.d.cts → introspect-RjLfIFpL.d.cts} +1 -1
  53. package/dist/motion.cjs +10 -0
  54. package/dist/motion.js +3 -3
  55. package/dist/patterns.cjs +66 -39
  56. package/dist/patterns.js +8 -7
  57. package/dist/performance.cjs +101 -25
  58. package/dist/performance.d.cts +2 -2
  59. package/dist/performance.d.ts +2 -2
  60. package/dist/performance.js +8 -7
  61. package/dist/plugins.cjs +243 -138
  62. package/dist/plugins.d.cts +1 -1
  63. package/dist/plugins.d.ts +1 -1
  64. package/dist/plugins.js +96 -45
  65. package/dist/{ssr-FXD2PPMC.js → ssr-2QDQ27EV.js} +5 -3
  66. package/dist/{ssr-CrVNy6Pa.d.cts → ssr-D62yFwuw.d.cts} +8 -1
  67. package/dist/{ssr-CrVNy6Pa.d.ts → ssr-D62yFwuw.d.ts} +8 -1
  68. package/dist/ssr.cjs +185 -68
  69. package/dist/ssr.d.cts +1 -1
  70. package/dist/ssr.d.ts +1 -1
  71. package/dist/ssr.js +12 -10
  72. package/dist/testing.cjs +9 -4
  73. package/dist/testing.js +3 -3
  74. package/dist/ui.cjs +76 -39
  75. package/dist/ui.js +10 -9
  76. package/dist/widgets.cjs +61 -23
  77. package/dist/widgets.js +8 -8
  78. package/package.json +3 -1
@@ -105,11 +105,26 @@ function processQueue() {
105
105
  scheduleFrame();
106
106
  }
107
107
  }
108
+ var TIER_SPEED = { microtask: 0, frame: 1, timeout: 2, idle: 3 };
109
+ function cancelScheduled() {
110
+ if (scheduledHandle !== null) {
111
+ if (scheduledKind === "frame") cancelAnimationFrame(scheduledHandle);
112
+ else if (scheduledKind === "idle" && typeof cancelIdleCallback !== "undefined") cancelIdleCallback(scheduledHandle);
113
+ else if (scheduledKind === "timeout") clearTimeout(scheduledHandle);
114
+ }
115
+ scheduledHandle = null;
116
+ scheduledKind = null;
117
+ }
108
118
  function scheduleFrame() {
109
- if (scheduledKind !== null || microtaskScheduled) return;
110
119
  const nextTask = taskQueue.find((t) => !t.cancelled);
111
120
  if (!nextTask) return;
112
- if (nextTask.priority <= Priority.USER_BLOCKING) {
121
+ const desired = nextTask.priority <= Priority.USER_BLOCKING ? "microtask" : nextTask.priority === Priority.IDLE ? typeof requestIdleCallback !== "undefined" ? "idle" : "timeout" : "frame";
122
+ if (microtaskScheduled) return;
123
+ if (scheduledKind !== null) {
124
+ if (TIER_SPEED[scheduledKind] <= TIER_SPEED[desired]) return;
125
+ cancelScheduled();
126
+ }
127
+ if (desired === "microtask") {
113
128
  microtaskScheduled = true;
114
129
  scheduledKind = "microtask";
115
130
  queueMicrotask(() => {
@@ -117,22 +132,20 @@ function scheduleFrame() {
117
132
  scheduledKind = null;
118
133
  processQueue();
119
134
  });
120
- } else if (nextTask.priority === Priority.IDLE) {
121
- if (typeof requestIdleCallback !== "undefined") {
122
- scheduledKind = "idle";
123
- scheduledHandle = requestIdleCallback(() => {
124
- scheduledKind = null;
125
- scheduledHandle = null;
126
- processQueue();
127
- });
128
- } else {
129
- scheduledKind = "timeout";
130
- scheduledHandle = setTimeout(() => {
131
- scheduledKind = null;
132
- scheduledHandle = null;
133
- processQueue();
134
- }, 50);
135
- }
135
+ } else if (desired === "idle") {
136
+ scheduledKind = "idle";
137
+ scheduledHandle = requestIdleCallback(() => {
138
+ scheduledKind = null;
139
+ scheduledHandle = null;
140
+ processQueue();
141
+ });
142
+ } else if (desired === "timeout") {
143
+ scheduledKind = "timeout";
144
+ scheduledHandle = setTimeout(() => {
145
+ scheduledKind = null;
146
+ scheduledHandle = null;
147
+ processQueue();
148
+ }, 50);
136
149
  } else {
137
150
  scheduledKind = "frame";
138
151
  scheduledHandle = requestAnimationFrame(() => {
@@ -197,7 +210,7 @@ function yieldToMain() {
197
210
  async function processInChunks(items, processor, chunkSize = 50) {
198
211
  for (let i = 0; i < items.length; i++) {
199
212
  processor(items[i], i);
200
- if (i > 0 && i % chunkSize === 0) {
213
+ if ((i + 1) % chunkSize === 0 && i + 1 < items.length) {
201
214
  await yieldToMain();
202
215
  }
203
216
  }
@@ -501,11 +514,15 @@ function notifySubscribers(signal2) {
501
514
  var als = null;
502
515
  try {
503
516
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
504
- const req = Function("return typeof require==='function'?require:null")();
505
- if (req) {
506
- const mod = req("node:async_hooks");
507
- als = new mod.AsyncLocalStorage();
517
+ let mod = null;
518
+ const getBuiltin = process.getBuiltinModule;
519
+ if (typeof getBuiltin === "function") {
520
+ mod = getBuiltin("node:async_hooks");
521
+ } else {
522
+ const req = Function("return typeof require==='function'?require:null")();
523
+ if (req) mod = req("node:async_hooks");
508
524
  }
525
+ if (mod) als = new mod.AsyncLocalStorage();
509
526
  }
510
527
  } catch {
511
528
  als = null;
@@ -607,6 +624,7 @@ function effect(effectFn, options) {
607
624
  ctx.fn(ctx.onCleanup);
608
625
  };
609
626
  const sub = (() => {
627
+ if (ctx.disposed) return;
610
628
  if (ctx.running) {
611
629
  ctx.rerunPending = true;
612
630
  return;
@@ -1053,7 +1071,65 @@ function denormalize(id, entities, schema) {
1053
1071
  return result;
1054
1072
  }
1055
1073
 
1074
+ // src/core/rendering/dispose.ts
1075
+ var elementDisposers = /* @__PURE__ */ new WeakMap();
1076
+ var _isDev6 = isDev();
1077
+ var activeBindingCount = 0;
1078
+ function dispose(node) {
1079
+ const stack = [node];
1080
+ const order = [];
1081
+ while (stack.length > 0) {
1082
+ const current = stack.pop();
1083
+ order.push(current);
1084
+ const children = Array.from(current.childNodes);
1085
+ for (let i = 0; i < children.length; i++) {
1086
+ stack.push(children[i]);
1087
+ }
1088
+ }
1089
+ for (let i = order.length - 1; i >= 0; i--) {
1090
+ const current = order[i];
1091
+ const disposers = elementDisposers.get(current);
1092
+ if (disposers) {
1093
+ const snapshot = disposers.slice();
1094
+ elementDisposers.delete(current);
1095
+ if (_isDev6) activeBindingCount -= snapshot.length;
1096
+ for (const d of snapshot) {
1097
+ try {
1098
+ d();
1099
+ } catch (err) {
1100
+ if (_isDev6 && typeof console !== "undefined") {
1101
+ console.warn("[SibuJS] Disposer threw during cleanup:", err);
1102
+ }
1103
+ }
1104
+ }
1105
+ let extraPasses = 0;
1106
+ while (extraPasses++ < 8) {
1107
+ const added = elementDisposers.get(current);
1108
+ if (!added || added.length === 0) break;
1109
+ const moreSnapshot = added.slice();
1110
+ elementDisposers.delete(current);
1111
+ if (_isDev6) activeBindingCount -= moreSnapshot.length;
1112
+ for (const d of moreSnapshot) {
1113
+ try {
1114
+ d();
1115
+ } catch (err) {
1116
+ if (_isDev6 && typeof console !== "undefined") {
1117
+ console.warn("[SibuJS] Disposer threw during cleanup:", err);
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+
1056
1126
  // src/performance/chunkLoader.ts
1127
+ function clearChildren(el) {
1128
+ while (el.firstChild) {
1129
+ dispose(el.firstChild);
1130
+ el.removeChild(el.firstChild);
1131
+ }
1132
+ }
1057
1133
  function createChunkRegistry(config = {}) {
1058
1134
  const {
1059
1135
  maxCacheSize = 50,
@@ -1218,10 +1294,10 @@ function lazyChunk(id, loader, registry, fallback) {
1218
1294
  const mod = await loader();
1219
1295
  return typeof mod === "function" ? mod : mod.default;
1220
1296
  }).then((component) => {
1221
- container.innerHTML = "";
1297
+ clearChildren(container);
1222
1298
  container.appendChild(component());
1223
1299
  }).catch((err) => {
1224
- container.innerHTML = "";
1300
+ clearChildren(container);
1225
1301
  const errorEl = document.createElement("div");
1226
1302
  errorEl.textContent = `Failed to load chunk '${id}': ${err.message}`;
1227
1303
  container.appendChild(errorEl);
@@ -1,5 +1,5 @@
1
- import { T as TrustedHTML } from './ssr-CrVNy6Pa.cjs';
2
- export { t as trustHTML } from './ssr-CrVNy6Pa.cjs';
1
+ import { T as TrustedHTML } from './ssr-D62yFwuw.cjs';
2
+ export { t as trustHTML } from './ssr-D62yFwuw.cjs';
3
3
 
4
4
  declare const Priority: {
5
5
  readonly IMMEDIATE: 0;
@@ -1,5 +1,5 @@
1
- import { T as TrustedHTML } from './ssr-CrVNy6Pa.js';
2
- export { t as trustHTML } from './ssr-CrVNy6Pa.js';
1
+ import { T as TrustedHTML } from './ssr-D62yFwuw.js';
2
+ export { t as trustHTML } from './ssr-D62yFwuw.js';
3
3
 
4
4
  declare const Priority: {
5
5
  readonly IMMEDIATE: 0;
@@ -33,15 +33,16 @@ import {
33
33
  transitionState,
34
34
  uniqueId,
35
35
  yieldToMain
36
- } from "./chunk-XDKP4T7G.js";
36
+ } from "./chunk-4JCAUOLN.js";
37
37
  import {
38
38
  trustHTML
39
- } from "./chunk-JYD2PWXH.js";
40
- import "./chunk-UCS6AMJ7.js";
41
- import "./chunk-5WD7BYTZ.js";
42
- import "./chunk-2RA7SHDA.js";
43
- import "./chunk-6QZO7MMG.js";
44
- import "./chunk-L4DAT4WU.js";
39
+ } from "./chunk-HXMS4SNP.js";
40
+ import "./chunk-2UPRY23K.js";
41
+ import "./chunk-HMJFCBRR.js";
42
+ import "./chunk-FDY42FIU.js";
43
+ import "./chunk-GOJMFRBL.js";
44
+ import "./chunk-C427DVQF.js";
45
+ import "./chunk-Z2FWAE4B.js";
45
46
  import "./chunk-LMLD24FC.js";
46
47
  export {
47
48
  DOMPool,