sibujs 4.13.0 → 4.14.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.
- package/README.md +1 -1
- package/dist/browser.cjs +15 -2
- package/dist/browser.js +9 -7
- package/dist/build.cjs +880 -281
- package/dist/build.d.cts +68 -3
- package/dist/build.d.ts +68 -3
- package/dist/build.js +88 -30
- package/dist/cdn.dev.global.js +12 -12
- package/dist/cdn.full.dev.global.js +13 -13
- package/dist/cdn.full.global.js +12 -12
- package/dist/cdn.global.js +12 -12
- package/dist/{chunk-7K7W4AA5.js → chunk-2TTRW2TE.js} +6 -6
- package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
- package/dist/chunk-3HZOSMPX.js +90 -0
- package/dist/{chunk-GNSRXK34.js → chunk-4FJSAUKB.js} +11 -3
- package/dist/{chunk-IV74C2YX.js → chunk-4TQDTWWN.js} +6 -5
- package/dist/{chunk-L3QHS4O4.js → chunk-7ILEHTVX.js} +1 -1
- package/dist/{chunk-CK5F2IR5.js → chunk-A454RAEK.js} +4 -4
- package/dist/{chunk-BRRRVLHQ.js → chunk-AE32RGWX.js} +10 -6
- package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
- package/dist/{chunk-F4W7WYXY.js → chunk-BKZ5N6NK.js} +8 -6
- package/dist/{chunk-MNEITZ27.js → chunk-BNXRWZZV.js} +49 -8
- package/dist/chunk-BOYKGGVD.js +2015 -0
- package/dist/{chunk-G6366I2A.js → chunk-CCKUNHVU.js} +2 -2
- package/dist/{chunk-346BYZL2.js → chunk-CJ7KS3DF.js} +16 -10
- package/dist/chunk-CNPT6NKV.js +1859 -0
- package/dist/{chunk-ENFRHCMK.js → chunk-F67F77IA.js} +2 -2
- package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
- package/dist/chunk-GVAMIU6K.js +195 -0
- package/dist/{chunk-HDKDBC6V.js → chunk-HQIAL7F2.js} +8 -6
- package/dist/{chunk-ZE5LF44R.js → chunk-JTFQ7IL4.js} +8 -8
- package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
- package/dist/{chunk-HVVRXRGO.js → chunk-MIRKTVH4.js} +7 -14
- package/dist/{chunk-YJ57VR6Y.js → chunk-N7A6FKWW.js} +5 -3
- package/dist/chunk-NT3ZYB5S.js +167 -0
- package/dist/{chunk-Z3EZX6DZ.js → chunk-QS6GMWDD.js} +151 -86
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/{chunk-3C56VNCK.js → chunk-RVR5NPFL.js} +3 -3
- package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
- package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
- package/dist/{chunk-QV5WEOFD.js → chunk-SVULV7O4.js} +119 -26
- package/dist/{chunk-C2FAO6VQ.js → chunk-TLS4NVIB.js} +5 -5
- package/dist/{chunk-M25RIH6Y.js → chunk-UUIKJJIK.js} +10 -8
- package/dist/chunk-UYTYNCMZ.js +199 -0
- package/dist/chunk-VM2U5LEL.js +2596 -0
- package/dist/{chunk-24L5RDPS.js → chunk-Y4LUM2XS.js} +8 -6
- package/dist/data.cjs +265 -35
- package/dist/data.d.cts +31 -1
- package/dist/data.d.ts +31 -1
- package/dist/data.js +16 -10
- package/dist/devtools.cjs +15 -2
- package/dist/devtools.js +9 -7
- package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
- package/dist/ecosystem.cjs +62 -23
- package/dist/ecosystem.js +14 -12
- package/dist/extras.cjs +3520 -270
- package/dist/extras.d.cts +3 -3
- package/dist/extras.d.ts +3 -3
- package/dist/extras.js +39 -29
- package/dist/index.cjs +442 -253
- package/dist/index.d.cts +93 -283
- package/dist/index.d.ts +93 -283
- package/dist/index.js +26 -16
- package/dist/motion.cjs +12 -1
- package/dist/motion.js +6 -4
- package/dist/patterns.cjs +15 -2
- package/dist/patterns.js +10 -8
- package/dist/performance.cjs +36 -2
- package/dist/performance.d.cts +2 -2
- package/dist/performance.d.ts +2 -2
- package/dist/performance.js +14 -10
- package/dist/plugins.cjs +5225 -1807
- package/dist/plugins.d.cts +8 -834
- package/dist/plugins.d.ts +8 -834
- package/dist/plugins.js +64 -2329
- package/dist/prerenderServer-MXJEVWA3.js +350 -0
- package/dist/renderRoute-DP20XwMS.d.cts +86 -0
- package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
- package/dist/routeHead-CE9SV-cH.d.cts +995 -0
- package/dist/routeHead-DzVxPviY.d.ts +995 -0
- package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
- package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
- package/dist/ssr-JpGpHnpC.d.cts +841 -0
- package/dist/ssr-JpGpHnpC.d.ts +841 -0
- package/dist/{ssr-VBM6J5SJ.js → ssr-NECEU4X4.js} +15 -6
- package/dist/ssr-dom.cjs +1862 -0
- package/dist/ssr-dom.d.cts +341 -0
- package/dist/ssr-dom.d.ts +341 -0
- package/dist/ssr-dom.js +19 -0
- package/dist/ssr.cjs +7630 -2064
- package/dist/ssr.d.cts +63 -5
- package/dist/ssr.d.ts +63 -5
- package/dist/ssr.js +136 -14
- package/dist/testing.cjs +6543 -87
- package/dist/testing.d.cts +80 -1
- package/dist/testing.d.ts +80 -1
- package/dist/testing.js +117 -4
- package/dist/ui.cjs +36 -2
- package/dist/ui.js +17 -14
- package/dist/widgets.cjs +14 -1
- package/dist/widgets.js +11 -9
- package/package.json +9 -2
- package/dist/chunk-2F4PSJ5Z.js +0 -765
- package/dist/chunk-7XHATCIH.js +0 -121
- package/dist/chunk-B36ADEIR.js +0 -21
- package/dist/ssr-Db0Sgdu3.d.cts +0 -245
- package/dist/ssr-Db0Sgdu3.d.ts +0 -245
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ClientOnly: () => ClientOnly,
|
|
23
24
|
DynamicComponent: () => DynamicComponent,
|
|
24
25
|
ErrorBoundary: () => ErrorBoundary,
|
|
25
26
|
ErrorDisplay: () => ErrorDisplay,
|
|
@@ -125,7 +126,9 @@ __export(index_exports, {
|
|
|
125
126
|
input: () => input,
|
|
126
127
|
ins: () => ins,
|
|
127
128
|
isBatching: () => isBatching,
|
|
129
|
+
isClient: () => isClient,
|
|
128
130
|
isSSR: () => isSSR,
|
|
131
|
+
isServer: () => isServer,
|
|
129
132
|
kbd: () => kbd,
|
|
130
133
|
label: () => label,
|
|
131
134
|
lazy: () => lazy,
|
|
@@ -199,7 +202,7 @@ __export(index_exports, {
|
|
|
199
202
|
setRuntimeErrorHandler: () => setRuntimeErrorHandler,
|
|
200
203
|
show: () => show,
|
|
201
204
|
signal: () => signal,
|
|
202
|
-
slot: () =>
|
|
205
|
+
slot: () => slot2,
|
|
203
206
|
small: () => small,
|
|
204
207
|
source: () => source,
|
|
205
208
|
span: () => span,
|
|
@@ -308,12 +311,12 @@ function claimedByBoundary(error, context2) {
|
|
|
308
311
|
}
|
|
309
312
|
function resolveEventTarget(node) {
|
|
310
313
|
const ELEMENT_NODE = 1;
|
|
311
|
-
let
|
|
312
|
-
while (
|
|
313
|
-
if (
|
|
314
|
-
return
|
|
314
|
+
let current2 = node;
|
|
315
|
+
while (current2) {
|
|
316
|
+
if (current2.nodeType === ELEMENT_NODE && typeof current2.dispatchEvent === "function") {
|
|
317
|
+
return current2;
|
|
315
318
|
}
|
|
316
|
-
|
|
319
|
+
current2 = current2.parentNode;
|
|
317
320
|
}
|
|
318
321
|
const self = node;
|
|
319
322
|
return typeof self.dispatchEvent === "function" ? self : null;
|
|
@@ -322,10 +325,21 @@ function defaultReport(error, context2) {
|
|
|
322
325
|
if (typeof console === "undefined") return;
|
|
323
326
|
console.error(`[SibuJS] Uncaught error during ${describe(context2)}: ${error.message}`, error);
|
|
324
327
|
}
|
|
328
|
+
function requestErrorSink() {
|
|
329
|
+
const shared = globalThis[/* @__PURE__ */ Symbol.for("sibujs.ssr.v1")];
|
|
330
|
+
if (!shared) return void 0;
|
|
331
|
+
const store2 = shared.als ? shared.als.getStore() : shared.fallbackDepth > 0 ? shared.fallbackStore : void 0;
|
|
332
|
+
return store2?.errors;
|
|
333
|
+
}
|
|
325
334
|
function reportError(error, context2) {
|
|
326
335
|
const err = normalizeError(error);
|
|
327
336
|
untrackedRun(() => {
|
|
328
337
|
if (claimedByBoundary(err, context2)) return;
|
|
338
|
+
const sink = requestErrorSink();
|
|
339
|
+
if (sink) {
|
|
340
|
+
sink.push({ error: err, context: context2 });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
329
343
|
const s2 = state();
|
|
330
344
|
const handler = s2.handler;
|
|
331
345
|
if (handler && s2.handlerDepth === 0) {
|
|
@@ -373,6 +387,78 @@ function devWarn(message) {
|
|
|
373
387
|
}
|
|
374
388
|
}
|
|
375
389
|
|
|
390
|
+
// src/core/rendering/adoptScope.ts
|
|
391
|
+
var current = null;
|
|
392
|
+
function inAdoptScope() {
|
|
393
|
+
return current?.s.on === true;
|
|
394
|
+
}
|
|
395
|
+
function currentSink() {
|
|
396
|
+
return current?.s.on ? current.s : null;
|
|
397
|
+
}
|
|
398
|
+
function createScopedElement(tag, ns) {
|
|
399
|
+
const c = current;
|
|
400
|
+
if (c?.s.on) {
|
|
401
|
+
const el = c.s.el(tag, ns, c.p + (c.n++).toString(36));
|
|
402
|
+
if (el) return el;
|
|
403
|
+
}
|
|
404
|
+
return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
405
|
+
}
|
|
406
|
+
function captureScope() {
|
|
407
|
+
const c = current;
|
|
408
|
+
return c?.s.on ? { p: `${c.p}${(c.n++).toString(36)}.`, n: 0, s: c.s } : null;
|
|
409
|
+
}
|
|
410
|
+
function keyedScope(scope, key) {
|
|
411
|
+
if (!scope?.s.on) return null;
|
|
412
|
+
const type = typeof key;
|
|
413
|
+
if (type !== "string" && type !== "number") {
|
|
414
|
+
throw new TypeError(`[SibuJS] adopt: a key must be a string or a number, not ${type}`);
|
|
415
|
+
}
|
|
416
|
+
const text2 = String(key).replace(/[^\w-]/g, (c) => `~${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
417
|
+
return { p: `${scope.p}${type === "string" ? "_" : "-"}${text2}.`, n: 0, s: scope.s };
|
|
418
|
+
}
|
|
419
|
+
function inScope(scope, fn) {
|
|
420
|
+
const prev = current;
|
|
421
|
+
if (!scope && !prev) return fn();
|
|
422
|
+
current = scope?.s.on ? { p: scope.p, n: 0, s: scope.s } : null;
|
|
423
|
+
try {
|
|
424
|
+
return fn();
|
|
425
|
+
} finally {
|
|
426
|
+
current = prev;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/core/rendering/hydrationHooks.ts
|
|
431
|
+
var _a;
|
|
432
|
+
var slot = globalThis[_a = /* @__PURE__ */ Symbol.for("sibujs.hydration.v2")] ?? (globalThis[_a] = { a: /* @__PURE__ */ new Set(), c: null });
|
|
433
|
+
function isHydrating() {
|
|
434
|
+
return slot.a.size > 0;
|
|
435
|
+
}
|
|
436
|
+
function ownSession() {
|
|
437
|
+
return currentSink()?.h ?? slot.c;
|
|
438
|
+
}
|
|
439
|
+
function hydrationOwners() {
|
|
440
|
+
const own = ownSession();
|
|
441
|
+
return own ? own.open ? [own] : [] : Array.from(slot.a);
|
|
442
|
+
}
|
|
443
|
+
function afterHydration(fn) {
|
|
444
|
+
const owners = hydrationOwners();
|
|
445
|
+
let left = owners.length;
|
|
446
|
+
const once = () => {
|
|
447
|
+
if (--left < 1) fn();
|
|
448
|
+
};
|
|
449
|
+
if (left) for (const s2 of owners) s2.done.push(once);
|
|
450
|
+
else fn();
|
|
451
|
+
}
|
|
452
|
+
function notify(session) {
|
|
453
|
+
for (const wake of Array.from(session.wake)) wake();
|
|
454
|
+
}
|
|
455
|
+
function holdHydration(sessions, entry) {
|
|
456
|
+
for (const s2 of sessions) s2.pending.add(entry);
|
|
457
|
+
return () => {
|
|
458
|
+
for (const s2 of sessions) if (s2.pending.delete(entry)) notify(s2);
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
376
462
|
// src/core/rendering/dispose.ts
|
|
377
463
|
var elementDisposers = /* @__PURE__ */ new WeakMap();
|
|
378
464
|
var MAX_DRAIN_TEARDOWNS = 1e4;
|
|
@@ -469,9 +555,9 @@ function dispose(node) {
|
|
|
469
555
|
const stack = [node];
|
|
470
556
|
const order = [];
|
|
471
557
|
while (stack.length > 0) {
|
|
472
|
-
const
|
|
473
|
-
order.push(
|
|
474
|
-
const children = Array.from(
|
|
558
|
+
const current2 = stack.pop();
|
|
559
|
+
order.push(current2);
|
|
560
|
+
const children = Array.from(current2.childNodes);
|
|
475
561
|
for (let i2 = 0; i2 < children.length; i2++) {
|
|
476
562
|
stack.push(children[i2]);
|
|
477
563
|
}
|
|
@@ -510,13 +596,27 @@ function disposeNodeOwn(node) {
|
|
|
510
596
|
}
|
|
511
597
|
}
|
|
512
598
|
function replaceChildrenSafely(parent, ...next) {
|
|
599
|
+
if (isHydrating() && next.length > 0 && next[0] === parent.firstChild) {
|
|
600
|
+
let ok = true;
|
|
601
|
+
for (let i2 = 1; i2 < next.length && ok; i2++) ok = next[i2 - 1].nextSibling === next[i2];
|
|
602
|
+
if (ok) {
|
|
603
|
+
let rest = next[next.length - 1].nextSibling;
|
|
604
|
+
while (rest) {
|
|
605
|
+
const following = rest.nextSibling;
|
|
606
|
+
dispose(rest);
|
|
607
|
+
parent.removeChild(rest);
|
|
608
|
+
rest = following;
|
|
609
|
+
}
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
513
613
|
for (let i2 = 0; i2 < next.length; i2++) {
|
|
514
614
|
const node = next[i2];
|
|
515
615
|
node.parentNode?.removeChild(node);
|
|
516
616
|
}
|
|
517
|
-
const
|
|
518
|
-
for (let i2 = 0; i2 <
|
|
519
|
-
dispose(
|
|
617
|
+
const current2 = Array.from(parent.childNodes);
|
|
618
|
+
for (let i2 = 0; i2 < current2.length; i2++) {
|
|
619
|
+
dispose(current2[i2]);
|
|
520
620
|
}
|
|
521
621
|
parent.replaceChildren(...next);
|
|
522
622
|
}
|
|
@@ -588,19 +688,19 @@ function sanitizeSrcset(value) {
|
|
|
588
688
|
if (url.endsWith(",")) {
|
|
589
689
|
url = url.replace(/,+$/, "");
|
|
590
690
|
} else {
|
|
591
|
-
let
|
|
691
|
+
let current2 = "";
|
|
592
692
|
let inParens = false;
|
|
593
693
|
while (i2 < n) {
|
|
594
694
|
const ch = input2[i2];
|
|
595
695
|
if (inParens) {
|
|
596
|
-
|
|
696
|
+
current2 += ch;
|
|
597
697
|
if (ch === ")") inParens = false;
|
|
598
698
|
i2++;
|
|
599
699
|
continue;
|
|
600
700
|
}
|
|
601
701
|
if (isSrcsetWhitespace(ch)) {
|
|
602
|
-
if (
|
|
603
|
-
|
|
702
|
+
if (current2) descriptors.push(current2);
|
|
703
|
+
current2 = "";
|
|
604
704
|
i2++;
|
|
605
705
|
continue;
|
|
606
706
|
}
|
|
@@ -609,10 +709,10 @@ function sanitizeSrcset(value) {
|
|
|
609
709
|
break;
|
|
610
710
|
}
|
|
611
711
|
if (ch === "(") inParens = true;
|
|
612
|
-
|
|
712
|
+
current2 += ch;
|
|
613
713
|
i2++;
|
|
614
714
|
}
|
|
615
|
-
if (
|
|
715
|
+
if (current2) descriptors.push(current2);
|
|
616
716
|
}
|
|
617
717
|
if (url === "") continue;
|
|
618
718
|
if (descriptors.length > 1) continue;
|
|
@@ -1185,8 +1285,8 @@ function commitSafeAttribute(el, name, value, options) {
|
|
|
1185
1285
|
else el.removeAttribute(name);
|
|
1186
1286
|
return true;
|
|
1187
1287
|
}
|
|
1188
|
-
const
|
|
1189
|
-
if (
|
|
1288
|
+
const current2 = ns ? el.getAttributeNS(ns, localName) : el.getAttribute(name);
|
|
1289
|
+
if (current2 === safe) return true;
|
|
1190
1290
|
if (ns) el.setAttributeNS(ns, name, safe);
|
|
1191
1291
|
else el.setAttribute(name, safe);
|
|
1192
1292
|
return true;
|
|
@@ -1774,7 +1874,7 @@ function forEachSubscriber(signal2, visit) {
|
|
|
1774
1874
|
}
|
|
1775
1875
|
|
|
1776
1876
|
// src/reactivity/track.ts
|
|
1777
|
-
var _runtimeVersion = true ? "4.
|
|
1877
|
+
var _runtimeVersion = true ? "4.14.0" : "dev";
|
|
1778
1878
|
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
|
|
1779
1879
|
function resolveReactiveApi() {
|
|
1780
1880
|
const g2 = globalThis;
|
|
@@ -1995,10 +2095,11 @@ function restoreFocusWithin(snapshot, nodes, where, policy) {
|
|
|
1995
2095
|
// src/reactivity/bindChildNode.ts
|
|
1996
2096
|
function bindChildNode(placeholder, getter) {
|
|
1997
2097
|
let lastNodes = [];
|
|
2098
|
+
const scope = captureScope();
|
|
1998
2099
|
function commit() {
|
|
1999
2100
|
let result;
|
|
2000
2101
|
try {
|
|
2001
|
-
result = getter
|
|
2102
|
+
result = inScope(scope, getter);
|
|
2002
2103
|
} catch (err) {
|
|
2003
2104
|
reportError(err, { phase: "binding", name: "bindChildNode", node: placeholder });
|
|
2004
2105
|
return;
|
|
@@ -2257,7 +2358,7 @@ function tagFactory(tag, ns) {
|
|
|
2257
2358
|
throw new Error(`tagFactory: refusing to create <${tag}> \u2014 tag is blocked for security reasons.`);
|
|
2258
2359
|
}
|
|
2259
2360
|
if (typeof document === "undefined") noDocument();
|
|
2260
|
-
const el =
|
|
2361
|
+
const el = createScopedElement(tag, ns);
|
|
2261
2362
|
if (first === void 0) return el;
|
|
2262
2363
|
if (typeof first === "string") {
|
|
2263
2364
|
if (second !== void 0) {
|
|
@@ -2467,7 +2568,7 @@ var details = tagFactory("details");
|
|
|
2467
2568
|
var dialog = tagFactory("dialog");
|
|
2468
2569
|
var menu = tagFactory("menu");
|
|
2469
2570
|
var summary = tagFactory("summary");
|
|
2470
|
-
var
|
|
2571
|
+
var slot2 = tagFactory("slot");
|
|
2471
2572
|
var template = tagFactory("template");
|
|
2472
2573
|
var base = tagFactory("base");
|
|
2473
2574
|
var link = tagFactory("link");
|
|
@@ -2498,6 +2599,152 @@ var font = tagFactory("font");
|
|
|
2498
2599
|
var marquee = tagFactory("marquee");
|
|
2499
2600
|
var customElement = (tagName) => tagFactory(tagName);
|
|
2500
2601
|
|
|
2602
|
+
// src/core/rendering/streamBoundary.ts
|
|
2603
|
+
var _a2;
|
|
2604
|
+
var slot3 = globalThis[_a2 = /* @__PURE__ */ Symbol.for("sibujs.streamBoundary.v1")] ?? (globalThis[_a2] = { hook: null, current: null });
|
|
2605
|
+
function openBoundary(container) {
|
|
2606
|
+
return slot3.hook ? slot3.hook(container) : null;
|
|
2607
|
+
}
|
|
2608
|
+
function currentBoundary() {
|
|
2609
|
+
return slot3.current;
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// src/core/ssr-context.ts
|
|
2613
|
+
var SSR_KEY = /* @__PURE__ */ Symbol.for("sibujs.ssr.v1");
|
|
2614
|
+
function detectSSRShared() {
|
|
2615
|
+
let detected = null;
|
|
2616
|
+
try {
|
|
2617
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
2618
|
+
let mod = null;
|
|
2619
|
+
const getBuiltin = process.getBuiltinModule;
|
|
2620
|
+
if (typeof getBuiltin === "function") {
|
|
2621
|
+
mod = getBuiltin("node:async_hooks");
|
|
2622
|
+
} else if (typeof require === "function") {
|
|
2623
|
+
mod = require("async_hooks");
|
|
2624
|
+
}
|
|
2625
|
+
if (mod) detected = new mod.AsyncLocalStorage();
|
|
2626
|
+
}
|
|
2627
|
+
const globalAls = globalThis.AsyncLocalStorage;
|
|
2628
|
+
if (!detected && typeof globalAls === "function") detected = new globalAls();
|
|
2629
|
+
} catch {
|
|
2630
|
+
detected = null;
|
|
2631
|
+
}
|
|
2632
|
+
return {
|
|
2633
|
+
als: detected,
|
|
2634
|
+
fallbackStore: { ssr: false, suspenseIdCounter: 0, locale: void 0 },
|
|
2635
|
+
fallbackDepth: 0
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
var _shared = globalThis[SSR_KEY] ?? (globalThis[SSR_KEY] = detectSSRShared());
|
|
2639
|
+
var als = _shared.als;
|
|
2640
|
+
var fallbackStore = _shared.fallbackStore;
|
|
2641
|
+
_shared.fallbackDepth ?? (_shared.fallbackDepth = 0);
|
|
2642
|
+
var _alsWarned = false;
|
|
2643
|
+
function warnMissingAsyncLocalStorage() {
|
|
2644
|
+
if (_alsWarned || als) return;
|
|
2645
|
+
const isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
2646
|
+
if (!isNode) return;
|
|
2647
|
+
_alsWarned = true;
|
|
2648
|
+
const version = process.versions.node;
|
|
2649
|
+
devWarn(
|
|
2650
|
+
`SSR request isolation is UNAVAILABLE on this runtime (Node ${version}). AsyncLocalStorage could not be loaded, so concurrent requests share one SSR store: request state and the query cache can bleed between them. Node >= 22.3 is required for isolated SSR under ESM; the CommonJS build works on older versions. A fully synchronous render is unaffected.`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
function getSSRStore() {
|
|
2654
|
+
if (als) {
|
|
2655
|
+
const s2 = als.getStore();
|
|
2656
|
+
if (s2) return s2;
|
|
2657
|
+
}
|
|
2658
|
+
return fallbackStore;
|
|
2659
|
+
}
|
|
2660
|
+
function getRequestStore() {
|
|
2661
|
+
if (als) return als.getStore() ?? null;
|
|
2662
|
+
return _shared.fallbackDepth > 0 ? fallbackStore : null;
|
|
2663
|
+
}
|
|
2664
|
+
function isSSR() {
|
|
2665
|
+
return getSSRStore().ssr;
|
|
2666
|
+
}
|
|
2667
|
+
function getRequestScopedCache(name) {
|
|
2668
|
+
if (!isSSR()) return null;
|
|
2669
|
+
const store2 = getSSRStore();
|
|
2670
|
+
const caches = store2.caches ?? (store2.caches = /* @__PURE__ */ new Map());
|
|
2671
|
+
let c = caches.get(name);
|
|
2672
|
+
if (!c) {
|
|
2673
|
+
c = /* @__PURE__ */ new Map();
|
|
2674
|
+
caches.set(name, c);
|
|
2675
|
+
}
|
|
2676
|
+
return c;
|
|
2677
|
+
}
|
|
2678
|
+
var PRERENDER_HOST = /* @__PURE__ */ Symbol.for("sibujs.prerender.v1");
|
|
2679
|
+
function isServer() {
|
|
2680
|
+
return getSSRStore().ssr || globalThis[PRERENDER_HOST] !== void 0;
|
|
2681
|
+
}
|
|
2682
|
+
function isClient() {
|
|
2683
|
+
return !isServer();
|
|
2684
|
+
}
|
|
2685
|
+
function enableSSR() {
|
|
2686
|
+
getSSRStore().ssr = true;
|
|
2687
|
+
}
|
|
2688
|
+
function disableSSR() {
|
|
2689
|
+
getSSRStore().ssr = false;
|
|
2690
|
+
}
|
|
2691
|
+
function runInSSRContext(fn) {
|
|
2692
|
+
const store2 = {
|
|
2693
|
+
ssr: true,
|
|
2694
|
+
suspenseIdCounter: 0,
|
|
2695
|
+
idCounter: 0,
|
|
2696
|
+
locale: void 0,
|
|
2697
|
+
pending: /* @__PURE__ */ new Set(),
|
|
2698
|
+
wake: null
|
|
2699
|
+
};
|
|
2700
|
+
if (als) {
|
|
2701
|
+
return als.run(store2, fn);
|
|
2702
|
+
}
|
|
2703
|
+
warnMissingAsyncLocalStorage();
|
|
2704
|
+
const prev = { ...fallbackStore };
|
|
2705
|
+
Object.assign(fallbackStore, store2);
|
|
2706
|
+
_shared.fallbackDepth++;
|
|
2707
|
+
try {
|
|
2708
|
+
return fn();
|
|
2709
|
+
} finally {
|
|
2710
|
+
_shared.fallbackDepth--;
|
|
2711
|
+
for (const key of Object.keys(fallbackStore)) {
|
|
2712
|
+
if (!(key in prev)) delete fallbackStore[key];
|
|
2713
|
+
}
|
|
2714
|
+
Object.assign(fallbackStore, prev);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
function trackPending(promise, label2, hydration = true) {
|
|
2718
|
+
const store2 = getRequestStore();
|
|
2719
|
+
const pending = store2?.pending;
|
|
2720
|
+
const sessions = pending || !hydration ? [] : hydrationOwners();
|
|
2721
|
+
if (!pending && sessions.length === 0) return promise;
|
|
2722
|
+
const entry = { label: label2, since: Date.now(), boundary: currentBoundary() ?? void 0 };
|
|
2723
|
+
pending?.add(entry);
|
|
2724
|
+
const release = holdHydration(sessions, entry);
|
|
2725
|
+
const done = () => {
|
|
2726
|
+
pending?.delete(entry);
|
|
2727
|
+
store2?.wake?.();
|
|
2728
|
+
release();
|
|
2729
|
+
};
|
|
2730
|
+
try {
|
|
2731
|
+
Promise.resolve(promise).then(done, done);
|
|
2732
|
+
} catch {
|
|
2733
|
+
done();
|
|
2734
|
+
}
|
|
2735
|
+
return promise;
|
|
2736
|
+
}
|
|
2737
|
+
function withSSR(fn) {
|
|
2738
|
+
const store2 = getSSRStore();
|
|
2739
|
+
const wasSSR = store2.ssr;
|
|
2740
|
+
store2.ssr = true;
|
|
2741
|
+
try {
|
|
2742
|
+
return fn();
|
|
2743
|
+
} finally {
|
|
2744
|
+
if (!wasSSR) store2.ssr = false;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2501
2748
|
// src/core/rendering/lazy.ts
|
|
2502
2749
|
var PENDING_ERROR = "__sibuPendingError";
|
|
2503
2750
|
function dispatchPropagate(node, error) {
|
|
@@ -2524,18 +2771,28 @@ function takePendingError(node) {
|
|
|
2524
2771
|
function lazy(importFn) {
|
|
2525
2772
|
let cached = null;
|
|
2526
2773
|
return function LazyComponent() {
|
|
2527
|
-
if (cached) {
|
|
2774
|
+
if (cached && !inAdoptScope()) {
|
|
2528
2775
|
return cached();
|
|
2529
2776
|
}
|
|
2530
2777
|
const container = div({ class: "sibu-lazy" });
|
|
2778
|
+
const scope = captureScope();
|
|
2779
|
+
const boundary = currentBoundary();
|
|
2531
2780
|
let disposed = false;
|
|
2532
|
-
|
|
2781
|
+
const loading = inScope(null, () => span("sibu-lazy-loading", "Loading..."));
|
|
2782
|
+
if (cached) {
|
|
2783
|
+
const loaded = cached;
|
|
2784
|
+
replaceChildrenSafely(container, inScope(scope, () => loaded()));
|
|
2785
|
+
return container;
|
|
2786
|
+
}
|
|
2787
|
+
trackPending(importFn(), "lazy").then(
|
|
2533
2788
|
// The component renders after the import resolves, in the owner scope
|
|
2534
2789
|
// of whoever rendered the placeholder.
|
|
2535
2790
|
bindOwnerScope2((mod) => {
|
|
2536
2791
|
if (disposed) return;
|
|
2537
2792
|
cached = mod.default;
|
|
2538
|
-
const
|
|
2793
|
+
const component = cached;
|
|
2794
|
+
const build = () => inScope(scope, () => component());
|
|
2795
|
+
const rendered = boundary ? boundary.enter(build) : build();
|
|
2539
2796
|
replaceChildrenSafely(container, rendered);
|
|
2540
2797
|
})
|
|
2541
2798
|
).catch((err) => {
|
|
@@ -2547,7 +2804,7 @@ function lazy(importFn) {
|
|
|
2547
2804
|
);
|
|
2548
2805
|
dispatchPropagate(container, errorObj);
|
|
2549
2806
|
});
|
|
2550
|
-
container.appendChild(
|
|
2807
|
+
if (!(isHydrating() && container.firstChild)) container.appendChild(loading);
|
|
2551
2808
|
registerDisposer(container, () => {
|
|
2552
2809
|
disposed = true;
|
|
2553
2810
|
});
|
|
@@ -2556,8 +2813,15 @@ function lazy(importFn) {
|
|
|
2556
2813
|
}
|
|
2557
2814
|
function Suspense({ nodes, fallback }) {
|
|
2558
2815
|
const container = div({ class: "sibu-suspense" });
|
|
2559
|
-
const
|
|
2560
|
-
container
|
|
2816
|
+
const scope = captureScope();
|
|
2817
|
+
const boundary = openBoundary(container);
|
|
2818
|
+
const commit = (el) => {
|
|
2819
|
+
replaceChildrenSafely(container, el);
|
|
2820
|
+
boundary?.done();
|
|
2821
|
+
};
|
|
2822
|
+
const fallbackEl = inScope(null, fallback);
|
|
2823
|
+
if (isHydrating() && container.firstChild) dispose(fallbackEl);
|
|
2824
|
+
else container.appendChild(fallbackEl);
|
|
2561
2825
|
let suspenseDisposed = false;
|
|
2562
2826
|
let observer = null;
|
|
2563
2827
|
let childEl = null;
|
|
@@ -2572,11 +2836,11 @@ function Suspense({ nodes, fallback }) {
|
|
|
2572
2836
|
const renderContent = bindOwnerScope2(() => {
|
|
2573
2837
|
if (suspenseDisposed) return;
|
|
2574
2838
|
try {
|
|
2575
|
-
const el = nodes();
|
|
2839
|
+
const el = boundary ? boundary.enter(() => inScope(scope, nodes)) : inScope(scope, nodes);
|
|
2576
2840
|
childEl = el;
|
|
2577
2841
|
if (el.classList.contains("sibu-lazy")) {
|
|
2578
2842
|
if (!el.querySelector(".sibu-lazy-loading")) {
|
|
2579
|
-
|
|
2843
|
+
commit(el);
|
|
2580
2844
|
return;
|
|
2581
2845
|
}
|
|
2582
2846
|
observer = new MutationObserver(() => {
|
|
@@ -2585,12 +2849,12 @@ function Suspense({ nodes, fallback }) {
|
|
|
2585
2849
|
if (!loading) {
|
|
2586
2850
|
observer?.disconnect();
|
|
2587
2851
|
observer = null;
|
|
2588
|
-
|
|
2852
|
+
commit(el);
|
|
2589
2853
|
}
|
|
2590
2854
|
});
|
|
2591
2855
|
observer.observe(el, { childList: true, subtree: true });
|
|
2592
2856
|
} else {
|
|
2593
|
-
|
|
2857
|
+
commit(el);
|
|
2594
2858
|
}
|
|
2595
2859
|
} catch (err) {
|
|
2596
2860
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
@@ -2780,7 +3044,7 @@ function registerUnmountWatcher(element, cb) {
|
|
|
2780
3044
|
};
|
|
2781
3045
|
}
|
|
2782
3046
|
function onMount(callback, element) {
|
|
2783
|
-
if (typeof document === "undefined") return;
|
|
3047
|
+
if (typeof document === "undefined" || isSSR()) return;
|
|
2784
3048
|
const scope = getOwnerScope2();
|
|
2785
3049
|
callback = pinScope(scope, callback);
|
|
2786
3050
|
if (element) {
|
|
@@ -2815,7 +3079,7 @@ function onMount(callback, element) {
|
|
|
2815
3079
|
}
|
|
2816
3080
|
}
|
|
2817
3081
|
function onUnmount(callback, element) {
|
|
2818
|
-
if (typeof document === "undefined") return;
|
|
3082
|
+
if (typeof document === "undefined" || isSSR()) return;
|
|
2819
3083
|
watchUnmount(pinScope(getOwnerScope2(), callback), element);
|
|
2820
3084
|
}
|
|
2821
3085
|
function watchUnmount(callback, element) {
|
|
@@ -2852,112 +3116,6 @@ function emitDevtools(hook, event, payload) {
|
|
|
2852
3116
|
}
|
|
2853
3117
|
}
|
|
2854
3118
|
|
|
2855
|
-
// src/core/ssr-context.ts
|
|
2856
|
-
var SSR_KEY = /* @__PURE__ */ Symbol.for("sibujs.ssr.v1");
|
|
2857
|
-
function detectSSRShared() {
|
|
2858
|
-
let detected = null;
|
|
2859
|
-
try {
|
|
2860
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
2861
|
-
let mod = null;
|
|
2862
|
-
const getBuiltin = process.getBuiltinModule;
|
|
2863
|
-
if (typeof getBuiltin === "function") {
|
|
2864
|
-
mod = getBuiltin("node:async_hooks");
|
|
2865
|
-
} else if (typeof require === "function") {
|
|
2866
|
-
mod = require("async_hooks");
|
|
2867
|
-
}
|
|
2868
|
-
if (mod) detected = new mod.AsyncLocalStorage();
|
|
2869
|
-
}
|
|
2870
|
-
} catch {
|
|
2871
|
-
detected = null;
|
|
2872
|
-
}
|
|
2873
|
-
return {
|
|
2874
|
-
als: detected,
|
|
2875
|
-
fallbackStore: { ssr: false, suspenseIdCounter: 0, locale: void 0 },
|
|
2876
|
-
fallbackDepth: 0
|
|
2877
|
-
};
|
|
2878
|
-
}
|
|
2879
|
-
var _shared = globalThis[SSR_KEY] ?? (globalThis[SSR_KEY] = detectSSRShared());
|
|
2880
|
-
var als = _shared.als;
|
|
2881
|
-
var fallbackStore = _shared.fallbackStore;
|
|
2882
|
-
_shared.fallbackDepth ?? (_shared.fallbackDepth = 0);
|
|
2883
|
-
var _alsWarned = false;
|
|
2884
|
-
function warnMissingAsyncLocalStorage() {
|
|
2885
|
-
if (_alsWarned || als) return;
|
|
2886
|
-
const isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
2887
|
-
if (!isNode) return;
|
|
2888
|
-
_alsWarned = true;
|
|
2889
|
-
const version = process.versions.node;
|
|
2890
|
-
devWarn(
|
|
2891
|
-
`SSR request isolation is UNAVAILABLE on this runtime (Node ${version}). AsyncLocalStorage could not be loaded, so concurrent requests share one SSR store: request state and the query cache can bleed between them. Node >= 22.3 is required for isolated SSR under ESM; the CommonJS build works on older versions. A fully synchronous render is unaffected.`
|
|
2892
|
-
);
|
|
2893
|
-
}
|
|
2894
|
-
function getSSRStore() {
|
|
2895
|
-
if (als) {
|
|
2896
|
-
const s2 = als.getStore();
|
|
2897
|
-
if (s2) return s2;
|
|
2898
|
-
}
|
|
2899
|
-
return fallbackStore;
|
|
2900
|
-
}
|
|
2901
|
-
function getRequestStore() {
|
|
2902
|
-
if (als) return als.getStore() ?? null;
|
|
2903
|
-
return _shared.fallbackDepth > 0 ? fallbackStore : null;
|
|
2904
|
-
}
|
|
2905
|
-
function isSSR() {
|
|
2906
|
-
return getSSRStore().ssr;
|
|
2907
|
-
}
|
|
2908
|
-
function getRequestScopedCache(name) {
|
|
2909
|
-
if (!isSSR()) return null;
|
|
2910
|
-
const store2 = getSSRStore();
|
|
2911
|
-
const caches = store2.caches ?? (store2.caches = /* @__PURE__ */ new Map());
|
|
2912
|
-
let c = caches.get(name);
|
|
2913
|
-
if (!c) {
|
|
2914
|
-
c = /* @__PURE__ */ new Map();
|
|
2915
|
-
caches.set(name, c);
|
|
2916
|
-
}
|
|
2917
|
-
return c;
|
|
2918
|
-
}
|
|
2919
|
-
function enableSSR() {
|
|
2920
|
-
getSSRStore().ssr = true;
|
|
2921
|
-
}
|
|
2922
|
-
function disableSSR() {
|
|
2923
|
-
getSSRStore().ssr = false;
|
|
2924
|
-
}
|
|
2925
|
-
function runInSSRContext(fn) {
|
|
2926
|
-
const store2 = { ssr: true, suspenseIdCounter: 0, idCounter: 0, locale: void 0 };
|
|
2927
|
-
if (als) {
|
|
2928
|
-
return als.run(store2, fn);
|
|
2929
|
-
}
|
|
2930
|
-
warnMissingAsyncLocalStorage();
|
|
2931
|
-
const prevSSR = fallbackStore.ssr;
|
|
2932
|
-
const prevCounter = fallbackStore.suspenseIdCounter;
|
|
2933
|
-
const prevIdCounter = fallbackStore.idCounter;
|
|
2934
|
-
const prevLocale = fallbackStore.locale;
|
|
2935
|
-
fallbackStore.ssr = true;
|
|
2936
|
-
fallbackStore.suspenseIdCounter = 0;
|
|
2937
|
-
fallbackStore.idCounter = 0;
|
|
2938
|
-
fallbackStore.locale = void 0;
|
|
2939
|
-
_shared.fallbackDepth++;
|
|
2940
|
-
try {
|
|
2941
|
-
return fn();
|
|
2942
|
-
} finally {
|
|
2943
|
-
_shared.fallbackDepth--;
|
|
2944
|
-
fallbackStore.ssr = prevSSR;
|
|
2945
|
-
fallbackStore.suspenseIdCounter = prevCounter;
|
|
2946
|
-
fallbackStore.idCounter = prevIdCounter;
|
|
2947
|
-
fallbackStore.locale = prevLocale;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
function withSSR(fn) {
|
|
2951
|
-
const store2 = getSSRStore();
|
|
2952
|
-
const wasSSR = store2.ssr;
|
|
2953
|
-
store2.ssr = true;
|
|
2954
|
-
try {
|
|
2955
|
-
return fn();
|
|
2956
|
-
} finally {
|
|
2957
|
-
if (!wasSSR) store2.ssr = false;
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
3119
|
// src/core/signals/effect.ts
|
|
2962
3120
|
var _g = globalThis;
|
|
2963
3121
|
function on(deps, handler) {
|
|
@@ -3038,7 +3196,7 @@ function disposeEffect(ctx) {
|
|
|
3038
3196
|
}
|
|
3039
3197
|
function effect(effectFn, options) {
|
|
3040
3198
|
devAssert(typeof effectFn === "function", "effect: argument must be a function.");
|
|
3041
|
-
if (isSSR()) return () => {
|
|
3199
|
+
if (isSSR() && !options?.server) return () => {
|
|
3042
3200
|
};
|
|
3043
3201
|
const ctx = {
|
|
3044
3202
|
fn: effectFn,
|
|
@@ -3844,21 +4002,21 @@ function ErrorBoundary(optionsOrChildren, maybeChildren) {
|
|
|
3844
4002
|
stopResetKeysWatcher();
|
|
3845
4003
|
let baseline = null;
|
|
3846
4004
|
resetKeysTeardown = effect(() => {
|
|
3847
|
-
const
|
|
4005
|
+
const current2 = readResetKeyValues(keys);
|
|
3848
4006
|
if (baseline === null) {
|
|
3849
|
-
baseline =
|
|
4007
|
+
baseline = current2;
|
|
3850
4008
|
return;
|
|
3851
4009
|
}
|
|
3852
|
-
let changed =
|
|
4010
|
+
let changed = current2.length !== baseline.length;
|
|
3853
4011
|
if (!changed) {
|
|
3854
|
-
for (let i2 = 0; i2 <
|
|
3855
|
-
if (!Object.is(
|
|
4012
|
+
for (let i2 = 0; i2 < current2.length; i2++) {
|
|
4013
|
+
if (!Object.is(current2[i2], baseline[i2])) {
|
|
3856
4014
|
changed = true;
|
|
3857
4015
|
break;
|
|
3858
4016
|
}
|
|
3859
4017
|
}
|
|
3860
4018
|
}
|
|
3861
|
-
baseline =
|
|
4019
|
+
baseline = current2;
|
|
3862
4020
|
if (changed) retry();
|
|
3863
4021
|
});
|
|
3864
4022
|
};
|
|
@@ -4250,68 +4408,6 @@ function setGlobalErrorHandler(handler) {
|
|
|
4250
4408
|
globalErrorHandler = handler;
|
|
4251
4409
|
}
|
|
4252
4410
|
|
|
4253
|
-
// src/core/rendering/context.ts
|
|
4254
|
-
function context(defaultValue) {
|
|
4255
|
-
const [getValue, setValue] = signal(defaultValue);
|
|
4256
|
-
const warnIfSSR = (method) => {
|
|
4257
|
-
if (!DEV || !isSSR()) return;
|
|
4258
|
-
devWarn(
|
|
4259
|
-
`context.${method}() called during SSR. SibuJS context() is application-global \u2014 it is NOT isolated per request, so a concurrent request can observe this value. Do not use context() for request-specific SSR data; pass it explicitly or use request-scoped storage instead.`
|
|
4260
|
-
);
|
|
4261
|
-
};
|
|
4262
|
-
const ctx = {
|
|
4263
|
-
provide(value) {
|
|
4264
|
-
warnIfSSR("provide");
|
|
4265
|
-
const previous = getValue();
|
|
4266
|
-
setValue(value);
|
|
4267
|
-
return () => setValue(previous);
|
|
4268
|
-
},
|
|
4269
|
-
use() {
|
|
4270
|
-
return getValue;
|
|
4271
|
-
},
|
|
4272
|
-
get() {
|
|
4273
|
-
return getValue();
|
|
4274
|
-
},
|
|
4275
|
-
set(value) {
|
|
4276
|
-
warnIfSSR("set");
|
|
4277
|
-
setValue(value);
|
|
4278
|
-
},
|
|
4279
|
-
withContext(value, fn) {
|
|
4280
|
-
warnIfSSR("withContext");
|
|
4281
|
-
const previous = getValue();
|
|
4282
|
-
setValue(value);
|
|
4283
|
-
try {
|
|
4284
|
-
const result = fn();
|
|
4285
|
-
if (DEV && result !== null && typeof result?.then === "function") {
|
|
4286
|
-
devWarn(
|
|
4287
|
-
"context.withContext() received an async callback. Scoping is synchronous only \u2014 the previous value is restored as soon as the callback returns its promise, so anything after an `await` runs outside the scope."
|
|
4288
|
-
);
|
|
4289
|
-
}
|
|
4290
|
-
return result;
|
|
4291
|
-
} finally {
|
|
4292
|
-
setValue(previous);
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
};
|
|
4296
|
-
return ctx;
|
|
4297
|
-
}
|
|
4298
|
-
|
|
4299
|
-
// src/core/rendering/createId.ts
|
|
4300
|
-
var COUNTER_KEY = /* @__PURE__ */ Symbol.for("sibujs.createId.v1");
|
|
4301
|
-
var _counter = globalThis[COUNTER_KEY] ?? (globalThis[COUNTER_KEY] = { n: 0 });
|
|
4302
|
-
function createId(prefix = "sibu") {
|
|
4303
|
-
const request = getRequestStore();
|
|
4304
|
-
if (request) {
|
|
4305
|
-
request.idCounter = (request.idCounter ?? 0) + 1;
|
|
4306
|
-
return `${prefix}-${request.idCounter}`;
|
|
4307
|
-
}
|
|
4308
|
-
_counter.n++;
|
|
4309
|
-
return `${prefix}-${_counter.n}`;
|
|
4310
|
-
}
|
|
4311
|
-
function __resetIdCounter() {
|
|
4312
|
-
_counter.n = 0;
|
|
4313
|
-
}
|
|
4314
|
-
|
|
4315
4411
|
// src/core/rendering/directives.ts
|
|
4316
4412
|
function show(condition, element) {
|
|
4317
4413
|
const resolved = typeof element === "function" ? element() : element;
|
|
@@ -4337,7 +4433,7 @@ function attachBranch(parent, anchor, branch, attachedOnce, where) {
|
|
|
4337
4433
|
() => `${where}: ${handedIn ? "a branch was given as an element rather than a function" : "a branch factory returned a node it had already returned"}, so the SAME node is being re-attached \u2014 any state it accumulated while detached (input value, scroll position, classes set imperatively) comes back with it. Its reactive bindings are left intact rather than disposed, because the node is not this directive's to tear down. Return a FRESH node per call (\`() => div(\u2026)\`) for rebuild semantics, or keep this form deliberately when the reuse is what you want.`
|
|
4338
4434
|
);
|
|
4339
4435
|
}
|
|
4340
|
-
parent.insertBefore(node, anchor.nextSibling);
|
|
4436
|
+
if (anchor.nextSibling !== node) parent.insertBefore(node, anchor.nextSibling);
|
|
4341
4437
|
return { node, owned };
|
|
4342
4438
|
}
|
|
4343
4439
|
function releaseBranchNode(node, owned) {
|
|
@@ -4353,6 +4449,7 @@ function when(condition, thenBranch, elseBranch, options) {
|
|
|
4353
4449
|
const elseNode = elseBranch;
|
|
4354
4450
|
const focusPolicy = options?.focus;
|
|
4355
4451
|
const anchor = document.createComment("when");
|
|
4452
|
+
const scope = captureScope();
|
|
4356
4453
|
let currentNode = null;
|
|
4357
4454
|
let lastCondition;
|
|
4358
4455
|
let initialized = false;
|
|
@@ -4372,7 +4469,7 @@ function when(condition, thenBranch, elseBranch, options) {
|
|
|
4372
4469
|
currentNode = null;
|
|
4373
4470
|
}
|
|
4374
4471
|
const branch = show2 ? thenBranch : elseNode !== void 0 ? elseNode : null;
|
|
4375
|
-
const attached = untracked2(() => attachBranch(parent, anchor, branch, attachedOnce, "when"));
|
|
4472
|
+
const attached = untracked2(() => inScope(scope, () => attachBranch(parent, anchor, branch, attachedOnce, "when")));
|
|
4376
4473
|
currentNode = attached.node;
|
|
4377
4474
|
currentNodeOwned = attached.owned;
|
|
4378
4475
|
restoreFocusWithin(focused, currentNode ? [currentNode] : [], "when", focusPolicy);
|
|
@@ -4403,6 +4500,7 @@ function match(value, cases, fallback, options) {
|
|
|
4403
4500
|
const fallbackNode = fallback;
|
|
4404
4501
|
const focusPolicy = options?.focus;
|
|
4405
4502
|
const anchor = document.createComment("match");
|
|
4503
|
+
const scope = captureScope();
|
|
4406
4504
|
let currentNode = null;
|
|
4407
4505
|
let lastKey;
|
|
4408
4506
|
let initialized = false;
|
|
@@ -4422,7 +4520,9 @@ function match(value, cases, fallback, options) {
|
|
|
4422
4520
|
currentNode = null;
|
|
4423
4521
|
}
|
|
4424
4522
|
const branch = Object.hasOwn(cases, key) ? cases[key] : fallbackNode;
|
|
4425
|
-
const attached = untracked2(
|
|
4523
|
+
const attached = untracked2(
|
|
4524
|
+
() => inScope(scope, () => attachBranch(parent, anchor, branch ?? null, attachedOnce, "match"))
|
|
4525
|
+
);
|
|
4426
4526
|
currentNode = attached.node;
|
|
4427
4527
|
currentNodeOwned = attached.owned;
|
|
4428
4528
|
restoreFocusWithin(focused, currentNode ? [currentNode] : [], "match", focusPolicy);
|
|
@@ -4445,6 +4545,76 @@ function match(value, cases, fallback, options) {
|
|
|
4445
4545
|
return anchor;
|
|
4446
4546
|
}
|
|
4447
4547
|
|
|
4548
|
+
// src/core/rendering/clientOnly.ts
|
|
4549
|
+
function ClientOnly(content, options = {}) {
|
|
4550
|
+
const server = isServer();
|
|
4551
|
+
const [ready, setReady] = signal(!server && !isHydrating());
|
|
4552
|
+
if (!server && !ready()) afterHydration(() => setReady(true));
|
|
4553
|
+
return when(ready, content, options.fallback);
|
|
4554
|
+
}
|
|
4555
|
+
|
|
4556
|
+
// src/core/rendering/context.ts
|
|
4557
|
+
function context(defaultValue) {
|
|
4558
|
+
const [getValue, setValue] = signal(defaultValue);
|
|
4559
|
+
const warnIfSSR = (method) => {
|
|
4560
|
+
if (!DEV || !isSSR()) return;
|
|
4561
|
+
devWarn(
|
|
4562
|
+
`context.${method}() called during SSR. SibuJS context() is application-global \u2014 it is NOT isolated per request, so a concurrent request can observe this value. Do not use context() for request-specific SSR data; pass it explicitly or use request-scoped storage instead.`
|
|
4563
|
+
);
|
|
4564
|
+
};
|
|
4565
|
+
const ctx = {
|
|
4566
|
+
provide(value) {
|
|
4567
|
+
warnIfSSR("provide");
|
|
4568
|
+
const previous = getValue();
|
|
4569
|
+
setValue(value);
|
|
4570
|
+
return () => setValue(previous);
|
|
4571
|
+
},
|
|
4572
|
+
use() {
|
|
4573
|
+
return getValue;
|
|
4574
|
+
},
|
|
4575
|
+
get() {
|
|
4576
|
+
return getValue();
|
|
4577
|
+
},
|
|
4578
|
+
set(value) {
|
|
4579
|
+
warnIfSSR("set");
|
|
4580
|
+
setValue(value);
|
|
4581
|
+
},
|
|
4582
|
+
withContext(value, fn) {
|
|
4583
|
+
warnIfSSR("withContext");
|
|
4584
|
+
const previous = getValue();
|
|
4585
|
+
setValue(value);
|
|
4586
|
+
try {
|
|
4587
|
+
const result = fn();
|
|
4588
|
+
if (DEV && result !== null && typeof result?.then === "function") {
|
|
4589
|
+
devWarn(
|
|
4590
|
+
"context.withContext() received an async callback. Scoping is synchronous only \u2014 the previous value is restored as soon as the callback returns its promise, so anything after an `await` runs outside the scope."
|
|
4591
|
+
);
|
|
4592
|
+
}
|
|
4593
|
+
return result;
|
|
4594
|
+
} finally {
|
|
4595
|
+
setValue(previous);
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
return ctx;
|
|
4600
|
+
}
|
|
4601
|
+
|
|
4602
|
+
// src/core/rendering/createId.ts
|
|
4603
|
+
var COUNTER_KEY = /* @__PURE__ */ Symbol.for("sibujs.createId.v1");
|
|
4604
|
+
var _counter = globalThis[COUNTER_KEY] ?? (globalThis[COUNTER_KEY] = { n: 0 });
|
|
4605
|
+
function createId(prefix = "sibu") {
|
|
4606
|
+
const request = getRequestStore();
|
|
4607
|
+
if (request) {
|
|
4608
|
+
request.idCounter = (request.idCounter ?? 0) + 1;
|
|
4609
|
+
return `${prefix}-${request.idCounter}`;
|
|
4610
|
+
}
|
|
4611
|
+
_counter.n++;
|
|
4612
|
+
return `${prefix}-${_counter.n}`;
|
|
4613
|
+
}
|
|
4614
|
+
function __resetIdCounter() {
|
|
4615
|
+
_counter.n = 0;
|
|
4616
|
+
}
|
|
4617
|
+
|
|
4448
4618
|
// src/utils/globalSingleton.ts
|
|
4449
4619
|
function globalSingleton(key, create) {
|
|
4450
4620
|
const g2 = globalThis;
|
|
@@ -4546,6 +4716,7 @@ function each(getArray, render, options) {
|
|
|
4546
4716
|
);
|
|
4547
4717
|
requireDocument();
|
|
4548
4718
|
const anchor = document.createComment("each:anchor");
|
|
4719
|
+
const scope = captureScope();
|
|
4549
4720
|
const end = document.createComment("each:end");
|
|
4550
4721
|
const oldKeysBufA = [];
|
|
4551
4722
|
const oldKeysBufB = [];
|
|
@@ -4575,7 +4746,9 @@ function each(getArray, render, options) {
|
|
|
4575
4746
|
const parent = anchor.parentNode;
|
|
4576
4747
|
if (!parent) return;
|
|
4577
4748
|
if (!sentinelInserted) {
|
|
4578
|
-
|
|
4749
|
+
const serverEnd = isHydrating() ? findServerEnd(anchor) : null;
|
|
4750
|
+
if (serverEnd) parent.replaceChild(end, serverEnd);
|
|
4751
|
+
else parent.insertBefore(end, anchor.nextSibling);
|
|
4579
4752
|
sentinelInserted = true;
|
|
4580
4753
|
}
|
|
4581
4754
|
if (newKeysBuf.length < newLen) {
|
|
@@ -4616,7 +4789,7 @@ function each(getArray, render, options) {
|
|
|
4616
4789
|
try {
|
|
4617
4790
|
suspendTracking2();
|
|
4618
4791
|
try {
|
|
4619
|
-
node = resolveNodeChild(render(itemGetter, indexGetter));
|
|
4792
|
+
node = resolveNodeChild(inScope(keyedScope(scope, key), () => render(itemGetter, indexGetter)));
|
|
4620
4793
|
} finally {
|
|
4621
4794
|
resumeTracking2();
|
|
4622
4795
|
}
|
|
@@ -4750,6 +4923,19 @@ function each(getArray, render, options) {
|
|
|
4750
4923
|
}
|
|
4751
4924
|
return anchor;
|
|
4752
4925
|
}
|
|
4926
|
+
function findServerEnd(anchor) {
|
|
4927
|
+
let depth = 0;
|
|
4928
|
+
for (let n = anchor.nextSibling; n; n = n.nextSibling) {
|
|
4929
|
+
if (n.nodeType !== 8) continue;
|
|
4930
|
+
const data2 = n.data;
|
|
4931
|
+
if (data2 === "each:anchor") depth++;
|
|
4932
|
+
else if (data2 === "each:end") {
|
|
4933
|
+
if (depth === 0) return n;
|
|
4934
|
+
depth--;
|
|
4935
|
+
}
|
|
4936
|
+
}
|
|
4937
|
+
return null;
|
|
4938
|
+
}
|
|
4753
4939
|
|
|
4754
4940
|
// src/core/rendering/fragment.ts
|
|
4755
4941
|
function Fragment(nodes) {
|
|
@@ -4873,19 +5059,19 @@ function parseTemplate(strings) {
|
|
|
4873
5059
|
pos++;
|
|
4874
5060
|
const statics = [];
|
|
4875
5061
|
const exprs = [];
|
|
4876
|
-
let
|
|
5062
|
+
let current2 = "";
|
|
4877
5063
|
while (pos < len && template2[pos] !== quote2) {
|
|
4878
5064
|
const innerIdx = tryExprIdx();
|
|
4879
5065
|
if (innerIdx >= 0) {
|
|
4880
|
-
statics.push(
|
|
4881
|
-
|
|
5066
|
+
statics.push(current2);
|
|
5067
|
+
current2 = "";
|
|
4882
5068
|
exprs.push(innerIdx);
|
|
4883
5069
|
} else {
|
|
4884
|
-
|
|
5070
|
+
current2 += template2[pos++];
|
|
4885
5071
|
}
|
|
4886
5072
|
}
|
|
4887
5073
|
if (pos < len) pos++;
|
|
4888
|
-
statics.push(
|
|
5074
|
+
statics.push(current2);
|
|
4889
5075
|
if (exprs.length === 0) {
|
|
4890
5076
|
return { kind: "static", value: statics[0] };
|
|
4891
5077
|
}
|
|
@@ -4894,20 +5080,20 @@ function parseTemplate(strings) {
|
|
|
4894
5080
|
{
|
|
4895
5081
|
const statics = [];
|
|
4896
5082
|
const exprs = [];
|
|
4897
|
-
let
|
|
5083
|
+
let current2 = "";
|
|
4898
5084
|
while (pos < len) {
|
|
4899
5085
|
const c = template2.charCodeAt(pos);
|
|
4900
5086
|
if (c === 32 || c === 9 || c === 10 || c === 13 || c === 62) break;
|
|
4901
5087
|
const innerIdx = tryExprIdx();
|
|
4902
5088
|
if (innerIdx >= 0) {
|
|
4903
|
-
statics.push(
|
|
4904
|
-
|
|
5089
|
+
statics.push(current2);
|
|
5090
|
+
current2 = "";
|
|
4905
5091
|
exprs.push(innerIdx);
|
|
4906
5092
|
} else {
|
|
4907
|
-
|
|
5093
|
+
current2 += template2[pos++];
|
|
4908
5094
|
}
|
|
4909
5095
|
}
|
|
4910
|
-
statics.push(
|
|
5096
|
+
statics.push(current2);
|
|
4911
5097
|
if (exprs.length === 0) {
|
|
4912
5098
|
return { kind: "static", value: statics[0] };
|
|
4913
5099
|
}
|
|
@@ -5031,7 +5217,7 @@ function parseTemplate(strings) {
|
|
|
5031
5217
|
return parseChildren();
|
|
5032
5218
|
}
|
|
5033
5219
|
function executeElement(tmpl, values) {
|
|
5034
|
-
const el = tmpl.svg ?
|
|
5220
|
+
const el = createScopedElement(tmpl.tag, tmpl.svg ? SVG_NS3 : void 0);
|
|
5035
5221
|
for (let i2 = 0; i2 < tmpl.attrs.length; i2++) {
|
|
5036
5222
|
const attr = tmpl.attrs[i2];
|
|
5037
5223
|
switch (attr.t) {
|
|
@@ -5124,7 +5310,7 @@ function renderTemplate(tmpl, values) {
|
|
|
5124
5310
|
if (tmpl.length === 1 && tmpl[0].t === 0) {
|
|
5125
5311
|
return executeElement(tmpl[0].el, values);
|
|
5126
5312
|
}
|
|
5127
|
-
const wrapper =
|
|
5313
|
+
const wrapper = createScopedElement("div");
|
|
5128
5314
|
for (let i2 = 0; i2 < tmpl.length; i2++) {
|
|
5129
5315
|
const child = tmpl[i2];
|
|
5130
5316
|
switch (child.t) {
|
|
@@ -5368,8 +5554,8 @@ function Portal(nodes, target) {
|
|
|
5368
5554
|
// src/core/rendering/slots.ts
|
|
5369
5555
|
function getSlot(slots, name = "default") {
|
|
5370
5556
|
if (slots == null || !Object.hasOwn(slots, name)) return void 0;
|
|
5371
|
-
const
|
|
5372
|
-
return typeof
|
|
5557
|
+
const slot4 = slots[name];
|
|
5558
|
+
return typeof slot4 === "function" ? slot4 : void 0;
|
|
5373
5559
|
}
|
|
5374
5560
|
|
|
5375
5561
|
// src/core/signals/array.ts
|
|
@@ -5453,7 +5639,7 @@ function reactiveArray(initial = []) {
|
|
|
5453
5639
|
let data2 = [...initial];
|
|
5454
5640
|
let snapshot = null;
|
|
5455
5641
|
const signal2 = { __v: 0 };
|
|
5456
|
-
function
|
|
5642
|
+
function notify2() {
|
|
5457
5643
|
snapshot = null;
|
|
5458
5644
|
signal2.__v++;
|
|
5459
5645
|
if (!enqueueBatchedSignal(signal2)) {
|
|
@@ -5472,52 +5658,52 @@ function reactiveArray(initial = []) {
|
|
|
5472
5658
|
push(...items) {
|
|
5473
5659
|
if (items.length === 0) return;
|
|
5474
5660
|
data2.push(...items);
|
|
5475
|
-
|
|
5661
|
+
notify2();
|
|
5476
5662
|
},
|
|
5477
5663
|
pop() {
|
|
5478
5664
|
if (data2.length === 0) return void 0;
|
|
5479
5665
|
const removed = data2.pop();
|
|
5480
|
-
|
|
5666
|
+
notify2();
|
|
5481
5667
|
return removed;
|
|
5482
5668
|
},
|
|
5483
5669
|
shift() {
|
|
5484
5670
|
if (data2.length === 0) return void 0;
|
|
5485
5671
|
const removed = data2.shift();
|
|
5486
|
-
|
|
5672
|
+
notify2();
|
|
5487
5673
|
return removed;
|
|
5488
5674
|
},
|
|
5489
5675
|
unshift(...items) {
|
|
5490
5676
|
if (items.length === 0) return;
|
|
5491
5677
|
data2.unshift(...items);
|
|
5492
|
-
|
|
5678
|
+
notify2();
|
|
5493
5679
|
},
|
|
5494
5680
|
splice(start, ...rest) {
|
|
5495
5681
|
const removed = nativeSplice(data2, start, rest);
|
|
5496
5682
|
if (removed.length > 0 || rest.length > 1) {
|
|
5497
|
-
|
|
5683
|
+
notify2();
|
|
5498
5684
|
}
|
|
5499
5685
|
return removed;
|
|
5500
5686
|
},
|
|
5501
5687
|
remove(index) {
|
|
5502
5688
|
if (index < 0 || index >= data2.length) return;
|
|
5503
5689
|
data2.splice(index, 1);
|
|
5504
|
-
|
|
5690
|
+
notify2();
|
|
5505
5691
|
},
|
|
5506
5692
|
removeWhere(predicate) {
|
|
5507
5693
|
const idx = data2.findIndex(predicate);
|
|
5508
5694
|
if (idx === -1) return;
|
|
5509
5695
|
data2.splice(idx, 1);
|
|
5510
|
-
|
|
5696
|
+
notify2();
|
|
5511
5697
|
},
|
|
5512
5698
|
set(items) {
|
|
5513
5699
|
data2 = [...items];
|
|
5514
|
-
|
|
5700
|
+
notify2();
|
|
5515
5701
|
},
|
|
5516
5702
|
update(index, value) {
|
|
5517
5703
|
if (index < 0 || index >= data2.length) return;
|
|
5518
5704
|
if (Object.is(data2[index], value)) return;
|
|
5519
5705
|
data2[index] = value;
|
|
5520
|
-
|
|
5706
|
+
notify2();
|
|
5521
5707
|
},
|
|
5522
5708
|
updateWhere(predicate, updater) {
|
|
5523
5709
|
let changed = false;
|
|
@@ -5530,23 +5716,23 @@ function reactiveArray(initial = []) {
|
|
|
5530
5716
|
}
|
|
5531
5717
|
}
|
|
5532
5718
|
}
|
|
5533
|
-
if (changed)
|
|
5719
|
+
if (changed) notify2();
|
|
5534
5720
|
},
|
|
5535
5721
|
sort(compareFn) {
|
|
5536
5722
|
if (data2.length <= 1) return;
|
|
5537
5723
|
data2.sort(compareFn);
|
|
5538
|
-
|
|
5724
|
+
notify2();
|
|
5539
5725
|
},
|
|
5540
5726
|
reverse() {
|
|
5541
5727
|
if (data2.length <= 1) return;
|
|
5542
5728
|
data2.reverse();
|
|
5543
|
-
|
|
5729
|
+
notify2();
|
|
5544
5730
|
},
|
|
5545
5731
|
filter(predicate) {
|
|
5546
5732
|
const filtered = data2.filter(predicate);
|
|
5547
5733
|
if (filtered.length === data2.length) return;
|
|
5548
5734
|
data2 = filtered;
|
|
5549
|
-
|
|
5735
|
+
notify2();
|
|
5550
5736
|
},
|
|
5551
5737
|
map(transform) {
|
|
5552
5738
|
let changed = false;
|
|
@@ -5557,12 +5743,12 @@ function reactiveArray(initial = []) {
|
|
|
5557
5743
|
changed = true;
|
|
5558
5744
|
}
|
|
5559
5745
|
}
|
|
5560
|
-
if (changed)
|
|
5746
|
+
if (changed) notify2();
|
|
5561
5747
|
},
|
|
5562
5748
|
clear() {
|
|
5563
5749
|
if (data2.length === 0) return;
|
|
5564
5750
|
data2 = [];
|
|
5565
|
-
|
|
5751
|
+
notify2();
|
|
5566
5752
|
}
|
|
5567
5753
|
};
|
|
5568
5754
|
return [get, actions];
|
|
@@ -5900,8 +6086,8 @@ function store(initialState) {
|
|
|
5900
6086
|
return snapshot;
|
|
5901
6087
|
};
|
|
5902
6088
|
const setState = (patch) => {
|
|
5903
|
-
const
|
|
5904
|
-
const nextState = typeof patch === "function" ? patch(
|
|
6089
|
+
const current2 = getSnapshot();
|
|
6090
|
+
const nextState = typeof patch === "function" ? patch(current2) : patch;
|
|
5905
6091
|
batch(() => {
|
|
5906
6092
|
Object.entries(nextState).forEach(([key, value]) => {
|
|
5907
6093
|
if (Object.hasOwn(signals, key)) {
|
|
@@ -5938,18 +6124,18 @@ function store(initialState) {
|
|
|
5938
6124
|
let prev;
|
|
5939
6125
|
let first = true;
|
|
5940
6126
|
return effect(() => {
|
|
5941
|
-
const
|
|
6127
|
+
const current2 = signals[key][0]();
|
|
5942
6128
|
if (first) {
|
|
5943
|
-
prev =
|
|
6129
|
+
prev = current2;
|
|
5944
6130
|
first = false;
|
|
5945
6131
|
return;
|
|
5946
6132
|
}
|
|
5947
|
-
if (!Object.is(
|
|
6133
|
+
if (!Object.is(current2, prev)) {
|
|
5948
6134
|
const oldPrev = prev;
|
|
5949
|
-
prev =
|
|
6135
|
+
prev = current2;
|
|
5950
6136
|
suspendTracking2();
|
|
5951
6137
|
try {
|
|
5952
|
-
callback(
|
|
6138
|
+
callback(current2, oldPrev);
|
|
5953
6139
|
} finally {
|
|
5954
6140
|
resumeTracking2();
|
|
5955
6141
|
}
|
|
@@ -6577,6 +6763,7 @@ function nextTick() {
|
|
|
6577
6763
|
}
|
|
6578
6764
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6579
6765
|
0 && (module.exports = {
|
|
6766
|
+
ClientOnly,
|
|
6580
6767
|
DynamicComponent,
|
|
6581
6768
|
ErrorBoundary,
|
|
6582
6769
|
ErrorDisplay,
|
|
@@ -6682,7 +6869,9 @@ function nextTick() {
|
|
|
6682
6869
|
input,
|
|
6683
6870
|
ins,
|
|
6684
6871
|
isBatching,
|
|
6872
|
+
isClient,
|
|
6685
6873
|
isSSR,
|
|
6874
|
+
isServer,
|
|
6686
6875
|
kbd,
|
|
6687
6876
|
label,
|
|
6688
6877
|
lazy,
|