sibujs 1.4.0 → 2.0.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 (190) hide show
  1. package/README.md +105 -119
  2. package/dist/browser.cjs +288 -80
  3. package/dist/browser.d.cts +19 -9
  4. package/dist/browser.d.ts +19 -9
  5. package/dist/browser.js +6 -6
  6. package/dist/build.cjs +1019 -313
  7. package/dist/build.d.cts +1 -1
  8. package/dist/build.d.ts +1 -1
  9. package/dist/build.js +15 -13
  10. package/dist/cdn.global.js +17 -16
  11. package/dist/chunk-2RA7SHDA.js +65 -0
  12. package/dist/chunk-2UPRY23K.js +80 -0
  13. package/dist/chunk-3JHCYHWN.js +125 -0
  14. package/dist/{chunk-ZWKZCBO6.js → chunk-3LR7GLWQ.js} +154 -33
  15. package/dist/{chunk-3AIRKM3B.js → chunk-3NSGB5JN.js} +115 -34
  16. package/dist/{chunk-3ARAQO7B.js → chunk-52YJLLRO.js} +29 -6
  17. package/dist/chunk-54EDRCEF.js +93 -0
  18. package/dist/chunk-7JDB7I65.js +1327 -0
  19. package/dist/{chunk-WZSPOOER.js → chunk-CC65Y57T.js} +8 -5
  20. package/dist/{chunk-23VV7YD3.js → chunk-DFPFITST.js} +25 -30
  21. package/dist/{chunk-WR5D4EGH.js → chunk-GTBNNBJ6.js} +14 -2
  22. package/dist/chunk-HB24TBAF.js +121 -0
  23. package/dist/{chunk-CZUGLNJS.js → chunk-ITX6OO3F.js} +3 -3
  24. package/dist/{chunk-JAKHTMQU.js → chunk-JA6667UN.js} +206 -46
  25. package/dist/{chunk-77L6NL3X.js → chunk-JXMMDLBY.js} +306 -183
  26. package/dist/{chunk-3X2YG6YM.js → chunk-JYD2PWXH.js} +59 -28
  27. package/dist/{chunk-F3FA4F32.js → chunk-KLRMB5ZS.js} +135 -79
  28. package/dist/{chunk-5X6PP2UK.js → chunk-LMLD24FC.js} +2 -2
  29. package/dist/{chunk-M4NLBH4I.js → chunk-LYTCUZ7H.js} +3 -2
  30. package/dist/{chunk-TSOKIX5Z.js → chunk-MIUAXB7K.js} +126 -74
  31. package/dist/{chunk-QWZG56ET.js → chunk-ND2664SF.js} +558 -190
  32. package/dist/{chunk-JCI5M6U6.js → chunk-O2MNQFLP.js} +261 -79
  33. package/dist/{chunk-EWFVA3TJ.js → chunk-R73P76YZ.js} +1 -1
  34. package/dist/{chunk-2BYQDGN3.js → chunk-SAHNHTFC.js} +234 -63
  35. package/dist/chunk-UCS6AMJ7.js +79 -0
  36. package/dist/{chunk-ZD6OAMTH.js → chunk-VLPPXTYG.js} +90 -35
  37. package/dist/{chunk-OUZZEE4S.js → chunk-WOMYAHHI.js} +17 -11
  38. package/dist/{contracts-xo5ckdRP.d.cts → contracts-ey_Qh8ef.d.cts} +7 -8
  39. package/dist/{contracts-xo5ckdRP.d.ts → contracts-ey_Qh8ef.d.ts} +7 -8
  40. package/dist/{customElement-D2DJp_xn.d.cts → customElement-CPfIrbvg.d.cts} +18 -9
  41. package/dist/{customElement-D2DJp_xn.d.ts → customElement-CPfIrbvg.d.ts} +18 -9
  42. package/dist/data.cjs +452 -100
  43. package/dist/data.d.cts +20 -2
  44. package/dist/data.d.ts +20 -2
  45. package/dist/data.js +11 -9
  46. package/dist/devtools.cjs +535 -247
  47. package/dist/devtools.d.cts +1 -1
  48. package/dist/devtools.d.ts +1 -1
  49. package/dist/devtools.js +34 -30
  50. package/dist/ecosystem.cjs +499 -143
  51. package/dist/ecosystem.d.cts +13 -11
  52. package/dist/ecosystem.d.ts +13 -11
  53. package/dist/ecosystem.js +12 -11
  54. package/dist/extras.cjs +3639 -1629
  55. package/dist/extras.d.cts +11 -11
  56. package/dist/extras.d.ts +11 -11
  57. package/dist/extras.js +58 -45
  58. package/dist/index.cjs +1023 -313
  59. package/dist/index.d.cts +128 -55
  60. package/dist/index.d.ts +128 -55
  61. package/dist/index.js +28 -16
  62. package/dist/{introspect-BumjnBKr.d.cts → introspect-BWNjNw64.d.cts} +22 -2
  63. package/dist/{introspect-CZrlcaYy.d.ts → introspect-cY2pg9pW.d.ts} +22 -2
  64. package/dist/motion.cjs +90 -36
  65. package/dist/motion.d.cts +1 -1
  66. package/dist/motion.d.ts +1 -1
  67. package/dist/motion.js +4 -4
  68. package/dist/patterns.cjs +414 -81
  69. package/dist/patterns.d.cts +53 -20
  70. package/dist/patterns.d.ts +53 -20
  71. package/dist/patterns.js +7 -7
  72. package/dist/performance.cjs +364 -108
  73. package/dist/performance.d.cts +29 -17
  74. package/dist/performance.d.ts +29 -17
  75. package/dist/performance.js +13 -6
  76. package/dist/plugin-D30wlGW5.d.cts +71 -0
  77. package/dist/plugin-D30wlGW5.d.ts +71 -0
  78. package/dist/plugins.cjs +652 -271
  79. package/dist/plugins.d.cts +13 -6
  80. package/dist/plugins.d.ts +13 -6
  81. package/dist/plugins.js +116 -50
  82. package/dist/{ssr-Do_SiVoL.d.cts → ssr-CrVNy6Pa.d.cts} +9 -15
  83. package/dist/{ssr-Do_SiVoL.d.ts → ssr-CrVNy6Pa.d.ts} +9 -15
  84. package/dist/{ssr-4PBXAOO3.js → ssr-FXD2PPMC.js} +4 -3
  85. package/dist/ssr.cjs +648 -219
  86. package/dist/ssr.d.cts +27 -7
  87. package/dist/ssr.d.ts +27 -7
  88. package/dist/ssr.js +12 -11
  89. package/dist/{tagFactory-DaJ0YWX6.d.ts → tagFactory-S17H2qxu.d.cts} +9 -1
  90. package/dist/{tagFactory-DaJ0YWX6.d.cts → tagFactory-S17H2qxu.d.ts} +9 -1
  91. package/dist/testing.cjs +252 -63
  92. package/dist/testing.d.cts +17 -4
  93. package/dist/testing.d.ts +17 -4
  94. package/dist/testing.js +100 -44
  95. package/dist/ui.cjs +576 -168
  96. package/dist/ui.d.cts +13 -16
  97. package/dist/ui.d.ts +13 -16
  98. package/dist/ui.js +20 -17
  99. package/dist/widgets.cjs +1001 -93
  100. package/dist/widgets.d.cts +104 -2
  101. package/dist/widgets.d.ts +104 -2
  102. package/dist/widgets.js +9 -7
  103. package/package.json +8 -2
  104. package/dist/chunk-32DY64NT.js +0 -282
  105. package/dist/chunk-3CRQALYP.js +0 -877
  106. package/dist/chunk-4EI4AG32.js +0 -482
  107. package/dist/chunk-4MYMUBRS.js +0 -21
  108. package/dist/chunk-6HLLIF3K.js +0 -398
  109. package/dist/chunk-6LSNVCS2.js +0 -937
  110. package/dist/chunk-6SA3QQES.js +0 -61
  111. package/dist/chunk-7BF6TK55.js +0 -1097
  112. package/dist/chunk-7TQKR4PP.js +0 -294
  113. package/dist/chunk-7V26P53V.js +0 -712
  114. package/dist/chunk-AZ3ISID5.js +0 -298
  115. package/dist/chunk-B7SWRFUT.js +0 -332
  116. package/dist/chunk-BGN5ZMP4.js +0 -26
  117. package/dist/chunk-BTU3TJDS.js +0 -365
  118. package/dist/chunk-BW3WT46K.js +0 -937
  119. package/dist/chunk-C6KFWOFV.js +0 -616
  120. package/dist/chunk-CHF5OHIA.js +0 -61
  121. package/dist/chunk-CHJ27IGK.js +0 -26
  122. package/dist/chunk-CMBFNA7L.js +0 -27
  123. package/dist/chunk-DAHRH4ON.js +0 -331
  124. package/dist/chunk-DKOHBI74.js +0 -924
  125. package/dist/chunk-DTCOOBMX.js +0 -725
  126. package/dist/chunk-EBGIRKQY.js +0 -616
  127. package/dist/chunk-EUZND3CB.js +0 -27
  128. package/dist/chunk-EVCZO745.js +0 -365
  129. package/dist/chunk-FGOEVHY3.js +0 -60
  130. package/dist/chunk-G3BOQPVO.js +0 -365
  131. package/dist/chunk-GCOK2LC3.js +0 -282
  132. package/dist/chunk-HGMJFBC7.js +0 -654
  133. package/dist/chunk-K5ZUMYVS.js +0 -89
  134. package/dist/chunk-KQPDEVVS.js +0 -398
  135. package/dist/chunk-L6JRBDNS.js +0 -60
  136. package/dist/chunk-LA6KQEDU.js +0 -712
  137. package/dist/chunk-MDVXJWFN.js +0 -304
  138. package/dist/chunk-MEZVEBPN.js +0 -2008
  139. package/dist/chunk-MK4ERFYL.js +0 -2249
  140. package/dist/chunk-MLKGABMK.js +0 -9
  141. package/dist/chunk-MQ5GOYPH.js +0 -2249
  142. package/dist/chunk-N6IZB6KJ.js +0 -567
  143. package/dist/chunk-NEKUBFPT.js +0 -60
  144. package/dist/chunk-NHUC2QWH.js +0 -282
  145. package/dist/chunk-NMRUZALC.js +0 -1097
  146. package/dist/chunk-NYVAC6P5.js +0 -37
  147. package/dist/chunk-OF7UZIVB.js +0 -725
  148. package/dist/chunk-P6W3STU4.js +0 -2249
  149. package/dist/chunk-PBHF5WKN.js +0 -616
  150. package/dist/chunk-PTQJDMRT.js +0 -146
  151. package/dist/chunk-PZEGYCF5.js +0 -61
  152. package/dist/chunk-QBMDLBU2.js +0 -975
  153. package/dist/chunk-RQGQSLQK.js +0 -725
  154. package/dist/chunk-SDLZDHKP.js +0 -107
  155. package/dist/chunk-TNQWPPE6.js +0 -37
  156. package/dist/chunk-UHNL42EF.js +0 -2730
  157. package/dist/chunk-UNXCEF6S.js +0 -21
  158. package/dist/chunk-V2XTI523.js +0 -347
  159. package/dist/chunk-VAU366PN.js +0 -2241
  160. package/dist/chunk-VMVDTCXB.js +0 -712
  161. package/dist/chunk-VRW3FULF.js +0 -725
  162. package/dist/chunk-WADYRCO2.js +0 -304
  163. package/dist/chunk-WILQZRO4.js +0 -282
  164. package/dist/chunk-WUHJISPP.js +0 -298
  165. package/dist/chunk-XYU6TZOW.js +0 -182
  166. package/dist/chunk-Y6GP4QGG.js +0 -276
  167. package/dist/chunk-YECR7UIA.js +0 -347
  168. package/dist/chunk-YUTWTI4B.js +0 -654
  169. package/dist/chunk-Z65KYU7I.js +0 -26
  170. package/dist/chunk-Z6POF5YC.js +0 -975
  171. package/dist/chunk-ZBJP6WFL.js +0 -482
  172. package/dist/contracts-DDrwxvJ-.d.cts +0 -245
  173. package/dist/contracts-DDrwxvJ-.d.ts +0 -245
  174. package/dist/contracts-DOrhwbke.d.cts +0 -245
  175. package/dist/contracts-DOrhwbke.d.ts +0 -245
  176. package/dist/customElement-BKQfbSZQ.d.cts +0 -262
  177. package/dist/customElement-BKQfbSZQ.d.ts +0 -262
  178. package/dist/customElement-yz8uyk-0.d.cts +0 -308
  179. package/dist/customElement-yz8uyk-0.d.ts +0 -308
  180. package/dist/introspect-Cb0zgpi2.d.cts +0 -477
  181. package/dist/introspect-Y2xNXGSf.d.ts +0 -477
  182. package/dist/plugin-Bek4RhJY.d.cts +0 -43
  183. package/dist/plugin-Bek4RhJY.d.ts +0 -43
  184. package/dist/ssr-3RXHP5ES.js +0 -38
  185. package/dist/ssr-6GIMY5MX.js +0 -38
  186. package/dist/ssr-BA6sxxUd.d.cts +0 -135
  187. package/dist/ssr-BA6sxxUd.d.ts +0 -135
  188. package/dist/ssr-WKUPVSSK.js +0 -36
  189. package/dist/tagFactory-Dl8QCLga.d.cts +0 -23
  190. package/dist/tagFactory-Dl8QCLga.d.ts +0 -23
@@ -30,8 +30,8 @@ __export(performance_exports, {
30
30
  deferredValue: () => deferredValue,
31
31
  denormalize: () => denormalize,
32
32
  devOnly: () => devOnly,
33
- domPool: () => domPool,
34
33
  flushScheduler: () => flushScheduler,
34
+ getDOMPool: () => getDOMPool,
35
35
  hoistable: () => hoistable,
36
36
  lazyChunk: () => lazyChunk,
37
37
  noSideEffect: () => noSideEffect,
@@ -52,6 +52,7 @@ __export(performance_exports, {
52
52
  startTransition: () => startTransition,
53
53
  staticTemplate: () => staticTemplate,
54
54
  transitionState: () => transitionState,
55
+ trustHTML: () => trustHTML,
55
56
  uniqueId: () => uniqueId,
56
57
  yieldToMain: () => yieldToMain
57
58
  });
@@ -68,7 +69,9 @@ var Priority = {
68
69
  var taskIdCounter = 0;
69
70
  var taskQueue = [];
70
71
  var isProcessing = false;
71
- var frameId = null;
72
+ var scheduledKind = null;
73
+ var scheduledHandle = null;
74
+ var microtaskScheduled = false;
72
75
  function insertTask(task) {
73
76
  let i = taskQueue.length;
74
77
  while (i > 0 && taskQueue[i - 1].priority > task.priority) {
@@ -103,30 +106,38 @@ function processQueue() {
103
106
  }
104
107
  }
105
108
  function scheduleFrame() {
106
- if (frameId !== null) return;
109
+ if (scheduledKind !== null || microtaskScheduled) return;
107
110
  const nextTask = taskQueue.find((t) => !t.cancelled);
108
111
  if (!nextTask) return;
109
112
  if (nextTask.priority <= Priority.USER_BLOCKING) {
113
+ microtaskScheduled = true;
114
+ scheduledKind = "microtask";
110
115
  queueMicrotask(() => {
111
- frameId = null;
116
+ microtaskScheduled = false;
117
+ scheduledKind = null;
112
118
  processQueue();
113
119
  });
114
- frameId = -1;
115
120
  } else if (nextTask.priority === Priority.IDLE) {
116
121
  if (typeof requestIdleCallback !== "undefined") {
117
- frameId = requestIdleCallback(() => {
118
- frameId = null;
122
+ scheduledKind = "idle";
123
+ scheduledHandle = requestIdleCallback(() => {
124
+ scheduledKind = null;
125
+ scheduledHandle = null;
119
126
  processQueue();
120
127
  });
121
128
  } else {
122
- frameId = setTimeout(() => {
123
- frameId = null;
129
+ scheduledKind = "timeout";
130
+ scheduledHandle = setTimeout(() => {
131
+ scheduledKind = null;
132
+ scheduledHandle = null;
124
133
  processQueue();
125
134
  }, 50);
126
135
  }
127
136
  } else {
128
- frameId = requestAnimationFrame(() => {
129
- frameId = null;
137
+ scheduledKind = "frame";
138
+ scheduledHandle = requestAnimationFrame(() => {
139
+ scheduledKind = null;
140
+ scheduledHandle = null;
130
141
  processQueue();
131
142
  });
132
143
  }
@@ -154,6 +165,15 @@ function scheduleUpdate(priority, callback) {
154
165
  };
155
166
  }
156
167
  function flushScheduler() {
168
+ if (scheduledHandle !== null) {
169
+ if (scheduledKind === "frame") cancelAnimationFrame(scheduledHandle);
170
+ else if (scheduledKind === "idle" && typeof cancelIdleCallback !== "undefined") {
171
+ cancelIdleCallback(scheduledHandle);
172
+ } else if (scheduledKind === "timeout") clearTimeout(scheduledHandle);
173
+ }
174
+ scheduledHandle = null;
175
+ scheduledKind = null;
176
+ microtaskScheduled = false;
157
177
  while (taskQueue.length > 0) {
158
178
  const task = taskQueue.shift();
159
179
  if (!task) break;
@@ -162,7 +182,6 @@ function flushScheduler() {
162
182
  }
163
183
  }
164
184
  isProcessing = false;
165
- frameId = null;
166
185
  }
167
186
  function pendingTasks() {
168
187
  return taskQueue.filter((t) => !t.cancelled).length;
@@ -189,21 +208,28 @@ function isDev() {
189
208
  return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
190
209
  }
191
210
  var _isDev = isDev();
211
+ function devAssert(condition, message) {
212
+ if (_isDev && !condition) {
213
+ throw new Error(`[SibuJS] ${message}`);
214
+ }
215
+ }
192
216
  function devWarn(message) {
193
217
  if (_isDev) {
194
- console.warn(`[Sibu] ${message}`);
218
+ console.warn(`[SibuJS] ${message}`);
195
219
  }
196
220
  }
197
221
 
198
222
  // src/reactivity/track.ts
199
223
  var _isDev2 = isDev();
200
224
  var subscriberStack = new Array(32);
225
+ var stackCapacity = 32;
226
+ var stackTop = -1;
201
227
  var currentSubscriber = null;
202
- var signalSubscribers = /* @__PURE__ */ new WeakMap();
203
228
  var SUBS = "__s";
204
229
  var notifyDepth = 0;
205
230
  var pendingQueue = [];
206
231
  var pendingSet = /* @__PURE__ */ new Set();
232
+ var propagateStack = [];
207
233
  function safeInvoke(sub) {
208
234
  try {
209
235
  sub();
@@ -211,6 +237,24 @@ function safeInvoke(sub) {
211
237
  if (_isDev2) devWarn(`Subscriber threw during notification: ${err instanceof Error ? err.message : String(err)}`);
212
238
  }
213
239
  }
240
+ function track(effectFn, subscriber) {
241
+ if (!subscriber) subscriber = effectFn;
242
+ cleanup(subscriber);
243
+ ++stackTop;
244
+ if (stackTop >= stackCapacity) {
245
+ stackCapacity *= 2;
246
+ subscriberStack.length = stackCapacity;
247
+ }
248
+ subscriberStack[stackTop] = subscriber;
249
+ currentSubscriber = subscriber;
250
+ try {
251
+ effectFn();
252
+ } finally {
253
+ stackTop--;
254
+ currentSubscriber = stackTop >= 0 ? subscriberStack[stackTop] : null;
255
+ }
256
+ return () => cleanup(subscriber);
257
+ }
214
258
  function recordDependency(signal2) {
215
259
  if (!currentSubscriber) return;
216
260
  const sub = currentSubscriber;
@@ -231,7 +275,6 @@ function recordDependency(signal2) {
231
275
  let subs = signal2[SUBS];
232
276
  if (!subs) {
233
277
  subs = /* @__PURE__ */ new Set();
234
- signalSubscribers.set(signal2, subs);
235
278
  signal2[SUBS] = subs;
236
279
  }
237
280
  subs.add(currentSubscriber);
@@ -241,42 +284,46 @@ function recordDependency(signal2) {
241
284
  signal2.__f = void 0;
242
285
  }
243
286
  }
287
+ var maxDrainIterations = 1e5;
244
288
  function propagateDirty(sub) {
245
289
  sub();
246
- let sig = sub._sig;
247
- while (sig) {
290
+ const rootSig = sub._sig;
291
+ if (!rootSig) return;
292
+ const stack = propagateStack;
293
+ const baseLen = stack.length;
294
+ stack.push(rootSig);
295
+ while (stack.length > baseLen) {
296
+ const sig = stack.pop();
248
297
  const first = sig.__f;
249
298
  if (first) {
250
299
  if (first._c) {
251
300
  const nSig = first._sig;
252
- nSig._d = true;
253
- sig = nSig;
254
- continue;
255
- }
256
- if (!pendingSet.has(first)) {
301
+ if (!nSig._d) {
302
+ nSig._d = true;
303
+ stack.push(nSig);
304
+ }
305
+ } else if (!pendingSet.has(first)) {
257
306
  pendingSet.add(first);
258
307
  pendingQueue.push(first);
259
308
  }
260
- break;
309
+ continue;
261
310
  }
262
311
  const subs = sig[SUBS];
263
- if (!subs) break;
264
- let nextSig;
312
+ if (!subs) continue;
265
313
  for (const s of subs) {
266
314
  if (s._c) {
267
- s();
268
315
  const nSig = s._sig;
269
- if (nSig && !nextSig) {
270
- nextSig = nSig;
271
- } else if (nSig) {
272
- propagateDirty(s);
316
+ if (nSig && !nSig._d) {
317
+ nSig._d = true;
318
+ stack.push(nSig);
319
+ } else if (!nSig) {
320
+ s();
273
321
  }
274
322
  } else if (!pendingSet.has(s)) {
275
323
  pendingSet.add(s);
276
324
  pendingQueue.push(s);
277
325
  }
278
326
  }
279
- sig = nextSig;
280
327
  }
281
328
  }
282
329
  function notifySubscribers(signal2) {
@@ -300,13 +347,23 @@ function notifySubscribers(signal2) {
300
347
  }
301
348
  let i = 0;
302
349
  while (i < pendingQueue.length) {
350
+ if (i >= maxDrainIterations) {
351
+ if (typeof console !== "undefined") {
352
+ console.error(
353
+ `[SibuJS] Notification queue exceeded ${maxDrainIterations} iterations \u2014 likely an effect that writes to a signal it reads. Breaking to prevent infinite loop.`
354
+ );
355
+ }
356
+ break;
357
+ }
303
358
  safeInvoke(pendingQueue[i]);
304
359
  i++;
305
360
  }
306
361
  } finally {
307
- pendingQueue.length = 0;
308
- pendingSet.clear();
309
362
  notifyDepth--;
363
+ if (notifyDepth === 0) {
364
+ pendingQueue.length = 0;
365
+ pendingSet.clear();
366
+ }
310
367
  }
311
368
  return;
312
369
  }
@@ -326,32 +383,196 @@ function notifySubscribers(signal2) {
326
383
  notifyDepth++;
327
384
  try {
328
385
  let directCount = 0;
386
+ let hasComputedSub = false;
329
387
  for (const sub of subs) {
388
+ if (sub._c) hasComputedSub = true;
330
389
  pendingQueue[directCount++] = sub;
331
390
  }
332
- for (let i2 = 0; i2 < directCount; i2++) {
333
- if (pendingQueue[i2]._c) {
334
- propagateDirty(pendingQueue[i2]);
391
+ if (!hasComputedSub) {
392
+ for (let i2 = 0; i2 < directCount; i2++) {
393
+ safeInvoke(pendingQueue[i2]);
335
394
  }
336
- }
337
- for (let i2 = 0; i2 < directCount; i2++) {
338
- if (!pendingQueue[i2]._c) {
339
- if (!pendingSet.has(pendingQueue[i2])) {
340
- safeInvoke(pendingQueue[i2]);
395
+ } else {
396
+ for (let i2 = 0; i2 < directCount; i2++) {
397
+ if (pendingQueue[i2]._c) {
398
+ propagateDirty(pendingQueue[i2]);
399
+ }
400
+ }
401
+ for (let i2 = 0; i2 < directCount; i2++) {
402
+ const sub = pendingQueue[i2];
403
+ if (!sub._c && !pendingSet.has(sub)) {
404
+ pendingSet.add(sub);
405
+ safeInvoke(sub);
341
406
  }
342
407
  }
343
408
  }
344
409
  let i = directCount;
345
410
  while (i < pendingQueue.length) {
411
+ if (i - directCount >= maxDrainIterations) {
412
+ if (typeof console !== "undefined") {
413
+ console.error(
414
+ `[SibuJS] Notification queue exceeded ${maxDrainIterations} iterations \u2014 likely an effect that writes to a signal it reads. Breaking to prevent infinite loop.`
415
+ );
416
+ }
417
+ break;
418
+ }
346
419
  safeInvoke(pendingQueue[i]);
347
420
  i++;
348
421
  }
349
422
  } finally {
350
- pendingQueue.length = 0;
351
- pendingSet.clear();
352
423
  notifyDepth--;
424
+ if (notifyDepth === 0) {
425
+ pendingQueue.length = 0;
426
+ pendingSet.clear();
427
+ }
353
428
  }
354
429
  }
430
+ function cleanup(subscriber) {
431
+ const sub = subscriber;
432
+ const singleDep = sub._dep;
433
+ if (singleDep !== void 0) {
434
+ const subs = singleDep[SUBS];
435
+ if (subs) {
436
+ subs.delete(subscriber);
437
+ if (singleDep.__f === subscriber) {
438
+ singleDep.__f = subs.size === 1 ? subs.values().next().value : void 0;
439
+ } else if (subs.size === 1 && singleDep.__f === void 0) {
440
+ singleDep.__f = subs.values().next().value;
441
+ }
442
+ }
443
+ sub._dep = void 0;
444
+ return;
445
+ }
446
+ const deps = sub._deps;
447
+ if (!deps || deps.size === 0) return;
448
+ for (const signal2 of deps) {
449
+ const subs = signal2[SUBS];
450
+ if (subs) {
451
+ subs.delete(subscriber);
452
+ if (signal2.__f === subscriber) {
453
+ signal2.__f = subs.size === 1 ? subs.values().next().value : void 0;
454
+ } else if (subs.size === 1 && signal2.__f === void 0) {
455
+ signal2.__f = subs.values().next().value;
456
+ }
457
+ }
458
+ }
459
+ deps.clear();
460
+ }
461
+
462
+ // src/core/ssr-context.ts
463
+ var als = null;
464
+ try {
465
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
466
+ const req = Function("return typeof require==='function'?require:null")();
467
+ if (req) {
468
+ const mod = req("node:async_hooks");
469
+ als = new mod.AsyncLocalStorage();
470
+ }
471
+ }
472
+ } catch {
473
+ als = null;
474
+ }
475
+ var fallbackStore = { ssr: false, suspenseIdCounter: 0 };
476
+ function getSSRStore() {
477
+ if (als) {
478
+ const s = als.getStore();
479
+ if (s) return s;
480
+ }
481
+ return fallbackStore;
482
+ }
483
+ function isSSR() {
484
+ return getSSRStore().ssr;
485
+ }
486
+
487
+ // src/core/signals/effect.ts
488
+ var _g = globalThis;
489
+ function effect(effectFn, options) {
490
+ devAssert(typeof effectFn === "function", "effect: argument must be a function.");
491
+ if (isSSR()) return () => {
492
+ };
493
+ const onError = options?.onError;
494
+ let userCleanups = [];
495
+ const onCleanup = (fn) => {
496
+ userCleanups.push(fn);
497
+ };
498
+ const runUserCleanups = () => {
499
+ if (userCleanups.length === 0) return;
500
+ const list = userCleanups;
501
+ userCleanups = [];
502
+ for (let i = list.length - 1; i >= 0; i--) {
503
+ try {
504
+ list[i]();
505
+ } catch (err) {
506
+ if (typeof console !== "undefined") {
507
+ console.warn("[SibuJS effect] onCleanup threw:", err);
508
+ }
509
+ }
510
+ }
511
+ };
512
+ const invokeBody = () => effectFn(onCleanup);
513
+ const wrappedFn = onError ? () => {
514
+ try {
515
+ invokeBody();
516
+ } catch (err) {
517
+ onError(err);
518
+ }
519
+ } : invokeBody;
520
+ let cleanupHandle = () => {
521
+ };
522
+ let running = false;
523
+ const subscriber = () => {
524
+ if (running) {
525
+ if (_g.__SIBU_DEV_WARN__ !== false && typeof console !== "undefined") {
526
+ console.warn(
527
+ "[SibuJS] effect re-entered itself while running \u2014 the triggering update will be ignored. Wrap mutual writes in `batch()` or split the effect to avoid this."
528
+ );
529
+ }
530
+ return;
531
+ }
532
+ running = true;
533
+ try {
534
+ runUserCleanups();
535
+ cleanupHandle();
536
+ cleanupHandle = track(wrappedFn, subscriber);
537
+ } finally {
538
+ running = false;
539
+ }
540
+ };
541
+ running = true;
542
+ try {
543
+ cleanupHandle = track(wrappedFn, subscriber);
544
+ } finally {
545
+ running = false;
546
+ }
547
+ const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
548
+ if (hook) hook.emit("effect:create", { effectFn });
549
+ let disposed = false;
550
+ return () => {
551
+ if (disposed) return;
552
+ disposed = true;
553
+ const h = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
554
+ if (h) {
555
+ try {
556
+ h.emit("effect:destroy", { effectFn });
557
+ } catch {
558
+ }
559
+ }
560
+ try {
561
+ runUserCleanups();
562
+ } catch (err) {
563
+ if (typeof console !== "undefined") {
564
+ console.warn("[SibuJS effect] onCleanup threw during dispose:", err);
565
+ }
566
+ }
567
+ try {
568
+ cleanupHandle();
569
+ } catch (err) {
570
+ if (typeof console !== "undefined") {
571
+ console.warn("[SibuJS effect] dispose threw:", err);
572
+ }
573
+ }
574
+ };
575
+ }
355
576
 
356
577
  // src/reactivity/batch.ts
357
578
  var batchDepth = 0;
@@ -363,7 +584,7 @@ function enqueueBatchedSignal(signal2) {
363
584
  }
364
585
 
365
586
  // src/core/signals/signal.ts
366
- var _g = globalThis;
587
+ var _g2 = globalThis;
367
588
  var _isDev3 = isDev();
368
589
  function signal(initial, options) {
369
590
  const state = { value: initial };
@@ -384,7 +605,7 @@ function signal(initial, options) {
384
605
  if (_isDev3) {
385
606
  const oldValue = state.value;
386
607
  state.value = newValue;
387
- const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
608
+ const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
388
609
  if (hook) hook.emit("signal:update", { signal: state, name: debugName, oldValue, newValue });
389
610
  } else {
390
611
  state.value = newValue;
@@ -394,7 +615,7 @@ function signal(initial, options) {
394
615
  }
395
616
  }
396
617
  if (_isDev3) {
397
- const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
618
+ const hook = _g2.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
398
619
  if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
399
620
  }
400
621
  return [get, set];
@@ -406,15 +627,12 @@ function startTransition(callback) {
406
627
  }
407
628
  function deferredValue(getter) {
408
629
  const [deferred, setDeferred] = signal(getter());
409
- const sync = () => {
410
- const current = getter();
411
- setDeferred(current);
412
- };
413
- scheduleUpdate(Priority.LOW, sync);
414
- return () => {
415
- scheduleUpdate(Priority.LOW, sync);
416
- return deferred();
417
- };
630
+ let latest = deferred();
631
+ effect(() => {
632
+ latest = getter();
633
+ scheduleUpdate(Priority.LOW, () => setDeferred(latest));
634
+ });
635
+ return deferred;
418
636
  }
419
637
  function transitionState() {
420
638
  const [isPending, setIsPending] = signal(false);
@@ -443,6 +661,7 @@ function uniqueId(suffix) {
443
661
  }
444
662
 
445
663
  // src/performance/domRecycler.ts
664
+ var _isDev4 = isDev();
446
665
  var DOMPool = class {
447
666
  constructor(maxSize = 50) {
448
667
  this.pools = /* @__PURE__ */ new Map();
@@ -462,8 +681,18 @@ var DOMPool = class {
462
681
  /**
463
682
  * Return an element to the pool for reuse.
464
683
  * Clears attributes, children, and event listeners.
684
+ *
685
+ * Contract: the caller MUST detach the element from the DOM (and run any
686
+ * `dispose()` on bound reactive subscriptions) BEFORE calling `release()`.
687
+ * Releasing a connected element leaves it visible while it is mutated and
688
+ * is almost certainly a bug.
465
689
  */
466
690
  release(element) {
691
+ if (_isDev4 && element.isConnected) {
692
+ devWarn(
693
+ "DOMPool.release() called on a still-connected element. Detach it from the DOM first (remove() / dispose())."
694
+ );
695
+ }
467
696
  const tag = element.tagName.toLowerCase();
468
697
  let pool = this.pools.get(tag);
469
698
  if (!pool) {
@@ -499,7 +728,11 @@ var DOMPool = class {
499
728
  return result;
500
729
  }
501
730
  };
502
- var domPool = new DOMPool();
731
+ var _defaultPool = null;
732
+ function getDOMPool() {
733
+ if (_defaultPool === null) _defaultPool = new DOMPool();
734
+ return _defaultPool;
735
+ }
503
736
  var preloadedResources = /* @__PURE__ */ new Set();
504
737
  function preloadResource(url, type = "fetch") {
505
738
  if (preloadedResources.has(url)) return;
@@ -562,6 +795,13 @@ function noSideEffect(fn) {
562
795
  return fn;
563
796
  }
564
797
 
798
+ // src/platform/ssr.ts
799
+ var _isDev5 = isDev();
800
+ function trustHTML(html) {
801
+ return html;
802
+ }
803
+ var DEFAULT_MAX_SSR_BYTES = 1024 * 1024;
804
+
565
805
  // src/performance/compiled.ts
566
806
  function staticTemplate(html) {
567
807
  const template = document.createElement("template");
@@ -729,31 +969,45 @@ function createChunkRegistry(config = {}) {
729
969
  const pending = /* @__PURE__ */ new Map();
730
970
  const preloaded = /* @__PURE__ */ new Set();
731
971
  function evict() {
732
- if (cache.size < maxCacheSize) return;
733
- let oldest = null;
734
- let oldestTime = Infinity;
735
- for (const [key, entry] of cache) {
736
- if (entry.timestamp < oldestTime) {
737
- oldestTime = entry.timestamp;
738
- oldest = key;
972
+ while (cache.size >= maxCacheSize) {
973
+ let lru = null;
974
+ let lruTime = Infinity;
975
+ for (const [key, entry] of cache) {
976
+ if (entry.lastAccess < lruTime) {
977
+ lruTime = entry.lastAccess;
978
+ lru = key;
979
+ }
739
980
  }
981
+ if (!lru) return;
982
+ cache.delete(lru);
740
983
  }
741
- if (oldest) cache.delete(oldest);
742
984
  }
743
985
  function isValid(entry) {
744
986
  if (cacheTTL === 0) return true;
745
987
  return Date.now() - entry.timestamp < cacheTTL;
746
988
  }
747
989
  async function loadWithRetry(id, loader, attempt = 0) {
990
+ let timeoutHandle = null;
748
991
  try {
749
- const result = await (timeout > 0 ? Promise.race([
750
- loader(),
751
- new Promise(
752
- (_, reject) => setTimeout(() => reject(new Error(`Chunk '${id}' loading timed out after ${timeout}ms`)), timeout)
753
- )
754
- ]) : loader());
992
+ const result = await (timeout > 0 ? new Promise((resolve, reject) => {
993
+ timeoutHandle = setTimeout(
994
+ () => reject(new Error(`Chunk '${id}' loading timed out after ${timeout}ms`)),
995
+ timeout
996
+ );
997
+ loader().then(
998
+ (v) => {
999
+ if (timeoutHandle !== null) clearTimeout(timeoutHandle);
1000
+ resolve(v);
1001
+ },
1002
+ (e) => {
1003
+ if (timeoutHandle !== null) clearTimeout(timeoutHandle);
1004
+ reject(e);
1005
+ }
1006
+ );
1007
+ }) : loader());
755
1008
  return result;
756
1009
  } catch (err) {
1010
+ if (timeoutHandle !== null) clearTimeout(timeoutHandle);
757
1011
  if (attempt < retries) {
758
1012
  await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
759
1013
  return loadWithRetry(id, loader, attempt + 1);
@@ -761,49 +1015,48 @@ function createChunkRegistry(config = {}) {
761
1015
  throw err;
762
1016
  }
763
1017
  }
1018
+ async function loadFn(id, loader) {
1019
+ const cached = cache.get(id);
1020
+ if (cached && isValid(cached)) {
1021
+ cached.accessCount++;
1022
+ cached.lastAccess = Date.now();
1023
+ return cached.value;
1024
+ }
1025
+ const pendingLoad = pending.get(id);
1026
+ if (pendingLoad) return pendingLoad;
1027
+ onLoadStart?.(id);
1028
+ const loadPromise = loadWithRetry(id, loader).then((value) => {
1029
+ evict();
1030
+ const now = Date.now();
1031
+ cache.set(id, { value, timestamp: now, lastAccess: now, accessCount: 1 });
1032
+ pending.delete(id);
1033
+ onLoadEnd?.(id);
1034
+ return value;
1035
+ }).catch((err) => {
1036
+ pending.delete(id);
1037
+ const error = err instanceof Error ? err : new Error(String(err));
1038
+ onLoadError?.(id, error);
1039
+ throw error;
1040
+ });
1041
+ pending.set(id, loadPromise);
1042
+ return loadPromise;
1043
+ }
1044
+ function preloadFn(id, loader) {
1045
+ if (cache.has(id) || pending.has(id) || preloaded.has(id)) return;
1046
+ preloaded.add(id);
1047
+ loadFn(id, loader).catch(() => {
1048
+ preloaded.delete(id);
1049
+ });
1050
+ }
764
1051
  return {
765
- /**
766
- * Load a chunk by ID. Uses cache if available, otherwise loads via the provided loader.
767
- */
768
- async load(id, loader) {
769
- const cached = cache.get(id);
770
- if (cached && isValid(cached)) {
771
- cached.accessCount++;
772
- return cached.value;
773
- }
774
- const pendingLoad = pending.get(id);
775
- if (pendingLoad) return pendingLoad;
776
- onLoadStart?.(id);
777
- const loadPromise = loadWithRetry(id, loader).then((value) => {
778
- evict();
779
- cache.set(id, { value, timestamp: Date.now(), accessCount: 1 });
780
- pending.delete(id);
781
- onLoadEnd?.(id);
782
- return value;
783
- }).catch((err) => {
784
- pending.delete(id);
785
- const error = err instanceof Error ? err : new Error(String(err));
786
- onLoadError?.(id, error);
787
- throw error;
788
- });
789
- pending.set(id, loadPromise);
790
- return loadPromise;
791
- },
792
- /**
793
- * Preload a chunk without blocking. Silently caches for later use.
794
- */
795
- preload(id, loader) {
796
- if (cache.has(id) || pending.has(id) || preloaded.has(id)) return;
797
- preloaded.add(id);
798
- this.load(id, loader).catch(() => {
799
- });
800
- },
1052
+ load: loadFn,
1053
+ preload: preloadFn,
801
1054
  /**
802
1055
  * Preload multiple chunks in parallel.
803
1056
  */
804
1057
  preloadAll(entries) {
805
1058
  for (const entry of entries) {
806
- this.preload(entry.id, entry.loader);
1059
+ preloadFn(entry.id, entry.loader);
807
1060
  }
808
1061
  },
809
1062
  /**
@@ -820,6 +1073,7 @@ function createChunkRegistry(config = {}) {
820
1073
  const entry = cache.get(id);
821
1074
  if (entry && isValid(entry)) {
822
1075
  entry.accessCount++;
1076
+ entry.lastAccess = Date.now();
823
1077
  return entry.value;
824
1078
  }
825
1079
  return void 0;
@@ -829,6 +1083,7 @@ function createChunkRegistry(config = {}) {
829
1083
  */
830
1084
  invalidate(id) {
831
1085
  cache.delete(id);
1086
+ preloaded.delete(id);
832
1087
  },
833
1088
  /**
834
1089
  * Clear all cached chunks.
@@ -898,8 +1153,8 @@ function preloadModules(urls) {
898
1153
  deferredValue,
899
1154
  denormalize,
900
1155
  devOnly,
901
- domPool,
902
1156
  flushScheduler,
1157
+ getDOMPool,
903
1158
  hoistable,
904
1159
  lazyChunk,
905
1160
  noSideEffect,
@@ -920,6 +1175,7 @@ function preloadModules(urls) {
920
1175
  startTransition,
921
1176
  staticTemplate,
922
1177
  transitionState,
1178
+ trustHTML,
923
1179
  uniqueId,
924
1180
  yieldToMain
925
1181
  });