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.
Files changed (107) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +15 -2
  3. package/dist/browser.js +9 -7
  4. package/dist/build.cjs +880 -281
  5. package/dist/build.d.cts +68 -3
  6. package/dist/build.d.ts +68 -3
  7. package/dist/build.js +88 -30
  8. package/dist/cdn.dev.global.js +12 -12
  9. package/dist/cdn.full.dev.global.js +13 -13
  10. package/dist/cdn.full.global.js +12 -12
  11. package/dist/cdn.global.js +12 -12
  12. package/dist/{chunk-7K7W4AA5.js → chunk-2TTRW2TE.js} +6 -6
  13. package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
  14. package/dist/chunk-3HZOSMPX.js +90 -0
  15. package/dist/{chunk-GNSRXK34.js → chunk-4FJSAUKB.js} +11 -3
  16. package/dist/{chunk-IV74C2YX.js → chunk-4TQDTWWN.js} +6 -5
  17. package/dist/{chunk-L3QHS4O4.js → chunk-7ILEHTVX.js} +1 -1
  18. package/dist/{chunk-CK5F2IR5.js → chunk-A454RAEK.js} +4 -4
  19. package/dist/{chunk-BRRRVLHQ.js → chunk-AE32RGWX.js} +10 -6
  20. package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
  21. package/dist/{chunk-F4W7WYXY.js → chunk-BKZ5N6NK.js} +8 -6
  22. package/dist/{chunk-MNEITZ27.js → chunk-BNXRWZZV.js} +49 -8
  23. package/dist/chunk-BOYKGGVD.js +2015 -0
  24. package/dist/{chunk-G6366I2A.js → chunk-CCKUNHVU.js} +2 -2
  25. package/dist/{chunk-346BYZL2.js → chunk-CJ7KS3DF.js} +16 -10
  26. package/dist/chunk-CNPT6NKV.js +1859 -0
  27. package/dist/{chunk-ENFRHCMK.js → chunk-F67F77IA.js} +2 -2
  28. package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
  29. package/dist/chunk-GVAMIU6K.js +195 -0
  30. package/dist/{chunk-HDKDBC6V.js → chunk-HQIAL7F2.js} +8 -6
  31. package/dist/{chunk-ZE5LF44R.js → chunk-JTFQ7IL4.js} +8 -8
  32. package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
  33. package/dist/{chunk-HVVRXRGO.js → chunk-MIRKTVH4.js} +7 -14
  34. package/dist/{chunk-YJ57VR6Y.js → chunk-N7A6FKWW.js} +5 -3
  35. package/dist/chunk-NT3ZYB5S.js +167 -0
  36. package/dist/{chunk-Z3EZX6DZ.js → chunk-QS6GMWDD.js} +151 -86
  37. package/dist/chunk-R5U7XKVJ.js +16 -0
  38. package/dist/{chunk-3C56VNCK.js → chunk-RVR5NPFL.js} +3 -3
  39. package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
  40. package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
  41. package/dist/{chunk-QV5WEOFD.js → chunk-SVULV7O4.js} +119 -26
  42. package/dist/{chunk-C2FAO6VQ.js → chunk-TLS4NVIB.js} +5 -5
  43. package/dist/{chunk-M25RIH6Y.js → chunk-UUIKJJIK.js} +10 -8
  44. package/dist/chunk-UYTYNCMZ.js +199 -0
  45. package/dist/chunk-VM2U5LEL.js +2596 -0
  46. package/dist/{chunk-24L5RDPS.js → chunk-Y4LUM2XS.js} +8 -6
  47. package/dist/data.cjs +265 -35
  48. package/dist/data.d.cts +31 -1
  49. package/dist/data.d.ts +31 -1
  50. package/dist/data.js +16 -10
  51. package/dist/devtools.cjs +15 -2
  52. package/dist/devtools.js +9 -7
  53. package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
  54. package/dist/ecosystem.cjs +62 -23
  55. package/dist/ecosystem.js +14 -12
  56. package/dist/extras.cjs +3520 -270
  57. package/dist/extras.d.cts +3 -3
  58. package/dist/extras.d.ts +3 -3
  59. package/dist/extras.js +39 -29
  60. package/dist/index.cjs +442 -253
  61. package/dist/index.d.cts +93 -283
  62. package/dist/index.d.ts +93 -283
  63. package/dist/index.js +26 -16
  64. package/dist/motion.cjs +12 -1
  65. package/dist/motion.js +6 -4
  66. package/dist/patterns.cjs +15 -2
  67. package/dist/patterns.js +10 -8
  68. package/dist/performance.cjs +36 -2
  69. package/dist/performance.d.cts +2 -2
  70. package/dist/performance.d.ts +2 -2
  71. package/dist/performance.js +14 -10
  72. package/dist/plugins.cjs +5225 -1807
  73. package/dist/plugins.d.cts +8 -834
  74. package/dist/plugins.d.ts +8 -834
  75. package/dist/plugins.js +64 -2329
  76. package/dist/prerenderServer-MXJEVWA3.js +350 -0
  77. package/dist/renderRoute-DP20XwMS.d.cts +86 -0
  78. package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
  79. package/dist/routeHead-CE9SV-cH.d.cts +995 -0
  80. package/dist/routeHead-DzVxPviY.d.ts +995 -0
  81. package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
  82. package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
  83. package/dist/ssr-JpGpHnpC.d.cts +841 -0
  84. package/dist/ssr-JpGpHnpC.d.ts +841 -0
  85. package/dist/{ssr-VBM6J5SJ.js → ssr-NECEU4X4.js} +15 -6
  86. package/dist/ssr-dom.cjs +1862 -0
  87. package/dist/ssr-dom.d.cts +341 -0
  88. package/dist/ssr-dom.d.ts +341 -0
  89. package/dist/ssr-dom.js +19 -0
  90. package/dist/ssr.cjs +7630 -2064
  91. package/dist/ssr.d.cts +63 -5
  92. package/dist/ssr.d.ts +63 -5
  93. package/dist/ssr.js +136 -14
  94. package/dist/testing.cjs +6543 -87
  95. package/dist/testing.d.cts +80 -1
  96. package/dist/testing.d.ts +80 -1
  97. package/dist/testing.js +117 -4
  98. package/dist/ui.cjs +36 -2
  99. package/dist/ui.js +17 -14
  100. package/dist/widgets.cjs +14 -1
  101. package/dist/widgets.js +11 -9
  102. package/package.json +9 -2
  103. package/dist/chunk-2F4PSJ5Z.js +0 -765
  104. package/dist/chunk-7XHATCIH.js +0 -121
  105. package/dist/chunk-B36ADEIR.js +0 -21
  106. package/dist/ssr-Db0Sgdu3.d.cts +0 -245
  107. package/dist/ssr-Db0Sgdu3.d.ts +0 -245
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-5HZXGZ6T.js";
4
4
  import {
5
5
  signal
6
- } from "./chunk-GNSRXK34.js";
6
+ } from "./chunk-4FJSAUKB.js";
7
7
  import {
8
8
  registerDisposer,
9
9
  reportError
10
- } from "./chunk-NYNYSPK7.js";
10
+ } from "./chunk-S37PZD6I.js";
11
11
 
12
12
  // src/ui/transition.ts
13
13
  function transition(element, options = {}) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DEV,
3
3
  devWarn
4
- } from "./chunk-NYNYSPK7.js";
4
+ } from "./chunk-NT3ZYB5S.js";
5
5
 
6
6
  // src/patterns/hoc.ts
7
7
  function withWrapper(WrappedComponent, wrapper) {
@@ -0,0 +1,195 @@
1
+ import {
2
+ Route,
3
+ createRouter,
4
+ route
5
+ } from "./chunk-VM2U5LEL.js";
6
+ import {
7
+ DEFAULT_SETTLE_TIMEOUT,
8
+ assembleDocument,
9
+ collectServerHead,
10
+ renderToStringAsync
11
+ } from "./chunk-BOYKGGVD.js";
12
+ import {
13
+ assertRequestIsolation,
14
+ getRequestStore,
15
+ runInSSRContext
16
+ } from "./chunk-UYTYNCMZ.js";
17
+ import {
18
+ DEV
19
+ } from "./chunk-NT3ZYB5S.js";
20
+
21
+ // src/platform/renderRoute.ts
22
+ function deepest(matched, key) {
23
+ for (let i = matched.length - 1; i >= 0; i--) {
24
+ const value = matched[i][key];
25
+ if (value !== void 0) return value;
26
+ }
27
+ return void 0;
28
+ }
29
+ function encodeUrlPart(part) {
30
+ return part.replace(/%(?![0-9A-Fa-f]{2})|[^A-Za-z0-9\-._~!$&'()*+,;=:@/?%]/gu, (c) => {
31
+ try {
32
+ return encodeURIComponent(c);
33
+ } catch {
34
+ return "%EF%BF%BD";
35
+ }
36
+ });
37
+ }
38
+ function before(work, deadline) {
39
+ return new Promise((resolve) => {
40
+ const timer = setTimeout(() => resolve(false), Math.max(0, deadline - Date.now()));
41
+ const done = () => {
42
+ clearTimeout(timer);
43
+ resolve(true);
44
+ };
45
+ work.then(done, done);
46
+ });
47
+ }
48
+ function emptyDiagnostics() {
49
+ return {
50
+ timedOut: false,
51
+ pending: [],
52
+ browserApis: [],
53
+ stateBytes: 0,
54
+ largestState: [],
55
+ droppedState: [],
56
+ durationMs: 0
57
+ };
58
+ }
59
+ function renderRoute(routes, url, options = {}) {
60
+ try {
61
+ assertRequestIsolation("renderRoute()");
62
+ } catch (err) {
63
+ return Promise.reject(err);
64
+ }
65
+ return runInSSRContext(async () => {
66
+ const started = Date.now();
67
+ const deadline = started + (options.timeout ?? DEFAULT_SETTLE_TIMEOUT);
68
+ const router = createRouter(routes, { ...options.router, mode: "memory", url });
69
+ const wrap = (body, headHtml, state) => options.document ? assembleDocument(body, options.document, headHtml, state) : body;
70
+ const timedOut = (phase) => {
71
+ const now = Date.now();
72
+ const pending = [
73
+ `${phase} (${now - started} ms)`,
74
+ ...Array.from(getRequestStore()?.pending ?? [], (work) => `${work.label} (${now - work.since} ms)`)
75
+ ];
76
+ const diagnostics = { ...emptyDiagnostics(), timedOut: true, pending, durationMs: now - started };
77
+ if (DEV) {
78
+ console.warn(
79
+ `[SibuJS SSR] ${url}: the route did not render within ${options.timeout ?? DEFAULT_SETTLE_TIMEOUT} ms; pending: ${pending.join(", ")}`
80
+ );
81
+ }
82
+ return {
83
+ html: wrap("", "", ""),
84
+ head: "",
85
+ state: "",
86
+ stateData: null,
87
+ status: 503,
88
+ location: null,
89
+ route: null,
90
+ render: "default",
91
+ noindex: false,
92
+ failure: "timeout",
93
+ redirectBy: null,
94
+ diagnostics
95
+ };
96
+ };
97
+ try {
98
+ if (!await before(router.whenNavigated(), deadline)) return timedOut("route:navigation");
99
+ const { result, redirectStatus, redirectBy } = router.initialOutcome;
100
+ const committed = route();
101
+ const matched = committed.matched;
102
+ const base = options.router?.base ?? "";
103
+ const head = () => collectServerHead();
104
+ if (result && !result.success) {
105
+ const reason = result.reason ?? "error";
106
+ const status2 = reason === "guard" ? options.rejectStatus ?? 403 : 500;
107
+ const headHtml = head();
108
+ return {
109
+ html: wrap("", headHtml, ""),
110
+ head: headHtml,
111
+ state: "",
112
+ stateData: null,
113
+ status: status2,
114
+ location: null,
115
+ route: null,
116
+ render: "default",
117
+ noindex: false,
118
+ failure: reason,
119
+ redirectBy: null,
120
+ diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
121
+ };
122
+ }
123
+ const search = new URLSearchParams();
124
+ for (const [key, values] of Object.entries(committed.queryAll)) for (const v of values) search.append(key, v);
125
+ const locationPath = encodeUrlPart(committed.path) + (search.size > 0 ? `?${search}` : "") + (committed.hash ? `#${encodeUrlPart(committed.hash)}` : "");
126
+ const routeInfo = {
127
+ path: committed.path,
128
+ params: { ...committed.params },
129
+ query: { ...committed.query },
130
+ hash: committed.hash,
131
+ name: matched.length > 0 ? matched[matched.length - 1].name ?? null : null
132
+ };
133
+ const headHtml0 = head();
134
+ const noindex = /<meta name="robots" content="[^"]*noindex/i.test(headHtml0);
135
+ if (redirectStatus !== null) {
136
+ return {
137
+ html: "",
138
+ head: headHtml0,
139
+ state: "",
140
+ stateData: null,
141
+ status: redirectStatus,
142
+ location: encodeUrlPart(base) + locationPath,
143
+ route: routeInfo,
144
+ render: "default",
145
+ noindex,
146
+ failure: null,
147
+ redirectBy,
148
+ diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
149
+ };
150
+ }
151
+ const leaf = matched[matched.length - 1];
152
+ const status = deepest(matched, "status") ?? (!leaf || leaf.path === "*" ? 404 : 200);
153
+ const render = deepest(matched, "render") ?? "default";
154
+ if (render === "client" || options.headOnly?.includes(render)) {
155
+ return {
156
+ html: wrap("", headHtml0, ""),
157
+ head: headHtml0,
158
+ state: "",
159
+ stateData: null,
160
+ status,
161
+ location: null,
162
+ route: routeInfo,
163
+ render,
164
+ noindex,
165
+ failure: null,
166
+ redirectBy: null,
167
+ diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
168
+ };
169
+ }
170
+ if (!await before(router.whenReady(), deadline)) return timedOut("route:components");
171
+ const rendered = await renderToStringAsync(options.app ?? (() => Route()), {
172
+ ...options,
173
+ timeout: Math.max(0, deadline - Date.now()),
174
+ log: options.log === true ? url : options.log
175
+ });
176
+ return {
177
+ ...rendered,
178
+ html: wrap(rendered.html, rendered.head, rendered.state),
179
+ status,
180
+ location: null,
181
+ route: routeInfo,
182
+ render,
183
+ noindex: /<meta name="robots" content="[^"]*noindex/i.test(rendered.head),
184
+ failure: null,
185
+ redirectBy: null
186
+ };
187
+ } finally {
188
+ router.destroy();
189
+ }
190
+ });
191
+ }
192
+
193
+ export {
194
+ renderRoute
195
+ };
@@ -2,21 +2,23 @@ import {
2
2
  ContextualRefusal,
3
3
  contextualAttributeRefusal,
4
4
  settleAttributeProvenance
5
- } from "./chunk-F2UWOZ6J.js";
5
+ } from "./chunk-RVWJGWCL.js";
6
6
  import {
7
7
  isEventHandlerAttr,
8
8
  isHtmlContentAttribute,
9
9
  resolveAttributeValue
10
- } from "./chunk-EXXSN3BW.js";
10
+ } from "./chunk-B3HOT4TK.js";
11
11
  import {
12
12
  reactiveBinding
13
- } from "./chunk-HVVRXRGO.js";
13
+ } from "./chunk-MIRKTVH4.js";
14
+ import {
15
+ reportError
16
+ } from "./chunk-S37PZD6I.js";
14
17
  import {
15
18
  DEV,
16
19
  devWarn,
17
- devWarnLazy,
18
- reportError
19
- } from "./chunk-NYNYSPK7.js";
20
+ devWarnLazy
21
+ } from "./chunk-NT3ZYB5S.js";
20
22
 
21
23
  // src/utils/setSafeAttribute.ts
22
24
  var HTML_NS = "http://www.w3.org/1999/xhtml";
@@ -3,34 +3,34 @@ import {
3
3
  } from "./chunk-N5TBYXHW.js";
4
4
  import {
5
5
  domBinding
6
- } from "./chunk-G6366I2A.js";
6
+ } from "./chunk-CCKUNHVU.js";
7
7
  import {
8
8
  bindAttribute,
9
9
  setSafeAttribute
10
- } from "./chunk-HDKDBC6V.js";
10
+ } from "./chunk-HQIAL7F2.js";
11
11
  import {
12
12
  isBlockedElement
13
- } from "./chunk-F2UWOZ6J.js";
13
+ } from "./chunk-RVWJGWCL.js";
14
14
  import {
15
15
  derived
16
- } from "./chunk-YJ57VR6Y.js";
16
+ } from "./chunk-N7A6FKWW.js";
17
17
  import {
18
18
  globalSingleton
19
19
  } from "./chunk-7ZHH77QA.js";
20
20
  import {
21
21
  isEventHandlerAttr,
22
22
  sanitizeStylesheetText
23
- } from "./chunk-EXXSN3BW.js";
23
+ } from "./chunk-B3HOT4TK.js";
24
24
  import {
25
25
  adoptThenable
26
26
  } from "./chunk-5HZXGZ6T.js";
27
27
  import {
28
28
  signal
29
- } from "./chunk-GNSRXK34.js";
29
+ } from "./chunk-4FJSAUKB.js";
30
30
  import {
31
31
  reactiveBinding,
32
32
  track
33
- } from "./chunk-HVVRXRGO.js";
33
+ } from "./chunk-MIRKTVH4.js";
34
34
  import {
35
35
  dispose,
36
36
  disposeNodeOwn,
@@ -39,7 +39,7 @@ import {
39
39
  reportError,
40
40
  unregisterDisposer,
41
41
  withDisposerRollback
42
- } from "./chunk-NYNYSPK7.js";
42
+ } from "./chunk-S37PZD6I.js";
43
43
 
44
44
  // src/ui/form.ts
45
45
  function required(message = "This field is required") {
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-7ZHH77QA.js";
4
4
  import {
5
5
  sanitizeUrl
6
- } from "./chunk-EXXSN3BW.js";
6
+ } from "./chunk-B3HOT4TK.js";
7
7
  import {
8
8
  getRequestStore
9
- } from "./chunk-7XHATCIH.js";
9
+ } from "./chunk-UYTYNCMZ.js";
10
10
 
11
11
  // src/utils/embedPolicy.ts
12
12
  var state = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.embed.v2"), () => ({
@@ -1,11 +1,13 @@
1
1
  import {
2
- DEV,
3
2
  beginDisposerCapture,
4
3
  currentDisposerCapture,
5
- devWarn,
6
4
  endDisposerCapture,
7
5
  reportError
8
- } from "./chunk-NYNYSPK7.js";
6
+ } from "./chunk-S37PZD6I.js";
7
+ import {
8
+ DEV,
9
+ devWarn
10
+ } from "./chunk-NT3ZYB5S.js";
9
11
 
10
12
  // src/reactivity/track-core.ts
11
13
  var POOL_MAX = 4096;
@@ -575,7 +577,7 @@ function forEachSubscriber(signal, visit) {
575
577
  }
576
578
 
577
579
  // src/reactivity/track.ts
578
- var _runtimeVersion = true ? "4.13.0" : "dev";
580
+ var _runtimeVersion = true ? "4.14.0" : "dev";
579
581
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
580
582
  function resolveReactiveApi() {
581
583
  const g = globalThis;
@@ -639,14 +641,6 @@ var runWithOwnerScope2 = API.runWithOwnerScope ?? runWithOwnerScope;
639
641
  var bindOwnerScope2 = API.bindOwnerScope ?? bindOwnerScope;
640
642
  var structuralBinding2 = API.structuralBinding ?? ((commit, ownerNode) => ({ stop: API.reactiveBinding(commit, ownerNode), run: (fn) => fn() }));
641
643
 
642
- // src/core/devtoolsHook.ts
643
- function emitDevtools(hook, event, payload) {
644
- try {
645
- hook.emit(event, payload);
646
- } catch {
647
- }
648
- }
649
-
650
644
  export {
651
645
  suspendTracking2 as suspendTracking,
652
646
  resumeTracking2 as resumeTracking,
@@ -667,6 +661,5 @@ export {
667
661
  getOwnerScope2 as getOwnerScope,
668
662
  runWithOwnerScope2 as runWithOwnerScope,
669
663
  bindOwnerScope2 as bindOwnerScope,
670
- structuralBinding2 as structuralBinding,
671
- emitDevtools
664
+ structuralBinding2 as structuralBinding
672
665
  };
@@ -1,14 +1,16 @@
1
+ import {
2
+ emitDevtools
3
+ } from "./chunk-4FJSAUKB.js";
1
4
  import {
2
5
  cleanup,
3
- emitDevtools,
4
6
  isTrackingSuspended,
5
7
  recordDependency,
6
8
  retrack,
7
9
  track
8
- } from "./chunk-HVVRXRGO.js";
10
+ } from "./chunk-MIRKTVH4.js";
9
11
  import {
10
12
  devAssert
11
- } from "./chunk-NYNYSPK7.js";
13
+ } from "./chunk-NT3ZYB5S.js";
12
14
 
13
15
  // src/core/signals/derived.ts
14
16
  function derived(getter, options) {
@@ -0,0 +1,167 @@
1
+ // src/core/dev.ts
2
+ var DEV = typeof __SIBU_DEV__ !== "undefined" ? !!__SIBU_DEV__ : typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
3
+ // safe default: off in browser, on in test/dev Node
4
+ typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
5
+ );
6
+ function isDev() {
7
+ if (typeof globalThis.__SIBU_DEV__ !== "undefined") return !!globalThis.__SIBU_DEV__;
8
+ if (typeof __SIBU_DEV__ !== "undefined") return !!__SIBU_DEV__;
9
+ return typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
10
+ }
11
+ function devAssert(condition, message) {
12
+ if ((typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : DEV) && !condition) {
13
+ throw new Error(`[SibuJS] ${message}`);
14
+ }
15
+ }
16
+ function devWarnLazy(build) {
17
+ if (typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : DEV) {
18
+ const message = build();
19
+ if (message) console.warn(`[SibuJS] ${message}`);
20
+ }
21
+ }
22
+ function devWarn(message) {
23
+ if (typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : DEV) {
24
+ console.warn(`[SibuJS] ${message}`);
25
+ }
26
+ }
27
+
28
+ // src/core/rendering/adoptScope.ts
29
+ var current = null;
30
+ function inAdoptScope() {
31
+ return current?.s.on === true;
32
+ }
33
+ function currentSink() {
34
+ return current?.s.on ? current.s : null;
35
+ }
36
+ function createScopedElement(tag, ns) {
37
+ const c = current;
38
+ if (c?.s.on) {
39
+ const el = c.s.el(tag, ns, c.p + (c.n++).toString(36));
40
+ if (el) return el;
41
+ }
42
+ return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
43
+ }
44
+ function captureScope() {
45
+ const c = current;
46
+ return c?.s.on ? { p: `${c.p}${(c.n++).toString(36)}.`, n: 0, s: c.s } : null;
47
+ }
48
+ function keyedScope(scope, key) {
49
+ if (!scope?.s.on) return null;
50
+ const type = typeof key;
51
+ if (type !== "string" && type !== "number") {
52
+ throw new TypeError(`[SibuJS] adopt: a key must be a string or a number, not ${type}`);
53
+ }
54
+ const text = String(key).replace(/[^\w-]/g, (c) => `~${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
55
+ return { p: `${scope.p}${type === "string" ? "_" : "-"}${text}.`, n: 0, s: scope.s };
56
+ }
57
+ function inScope(scope, fn) {
58
+ const prev = current;
59
+ if (!scope && !prev) return fn();
60
+ current = scope?.s.on ? { p: scope.p, n: 0, s: scope.s } : null;
61
+ try {
62
+ return fn();
63
+ } finally {
64
+ current = prev;
65
+ }
66
+ }
67
+
68
+ // src/core/rendering/hydrationHooks.ts
69
+ var _a;
70
+ var slot = globalThis[_a = /* @__PURE__ */ Symbol.for("sibujs.hydration.v2")] ?? (globalThis[_a] = { a: /* @__PURE__ */ new Set(), c: null });
71
+ function isHydrating() {
72
+ return slot.a.size > 0;
73
+ }
74
+ function ownSession() {
75
+ return currentSink()?.h ?? slot.c;
76
+ }
77
+ function hydrationOwners() {
78
+ const own = ownSession();
79
+ return own ? own.open ? [own] : [] : Array.from(slot.a);
80
+ }
81
+ function afterHydration(fn) {
82
+ const owners = hydrationOwners();
83
+ let left = owners.length;
84
+ const once = () => {
85
+ if (--left < 1) fn();
86
+ };
87
+ if (left) for (const s of owners) s.done.push(once);
88
+ else fn();
89
+ }
90
+ function notify(session) {
91
+ for (const wake of Array.from(session.wake)) wake();
92
+ }
93
+ function holdHydration(sessions, entry) {
94
+ for (const s of sessions) s.pending.add(entry);
95
+ return () => {
96
+ for (const s of sessions) if (s.pending.delete(entry)) notify(s);
97
+ };
98
+ }
99
+ function inHydration(session, fn) {
100
+ const prev = slot.c;
101
+ slot.c = session;
102
+ try {
103
+ return fn();
104
+ } finally {
105
+ slot.c = prev;
106
+ }
107
+ }
108
+ function beginHydration() {
109
+ const own = ownSession();
110
+ const session = {
111
+ done: [],
112
+ pending: /* @__PURE__ */ new Set(),
113
+ wake: /* @__PURE__ */ new Set(),
114
+ up: own?.open ? own : null,
115
+ open: true,
116
+ end() {
117
+ if (!session.open) return;
118
+ session.open = false;
119
+ slot.a.delete(session);
120
+ session.pending.clear();
121
+ notify(session);
122
+ const up = session.up;
123
+ session.up = null;
124
+ const callbacks = session.done.splice(0);
125
+ if (up?.open) {
126
+ up.done.push(...callbacks);
127
+ if (up.pending.delete(session)) notify(up);
128
+ return;
129
+ }
130
+ let failed = false;
131
+ let error;
132
+ inHydration(session, () => {
133
+ for (const fn of callbacks) {
134
+ try {
135
+ fn();
136
+ } catch (err) {
137
+ if (!failed) error = err;
138
+ failed = true;
139
+ }
140
+ }
141
+ });
142
+ if (failed) throw error;
143
+ }
144
+ };
145
+ if (session.up) session.up.pending.add(session);
146
+ slot.a.add(session);
147
+ return session;
148
+ }
149
+
150
+ export {
151
+ DEV,
152
+ isDev,
153
+ devAssert,
154
+ devWarnLazy,
155
+ devWarn,
156
+ inAdoptScope,
157
+ createScopedElement,
158
+ captureScope,
159
+ keyedScope,
160
+ inScope,
161
+ isHydrating,
162
+ hydrationOwners,
163
+ afterHydration,
164
+ holdHydration,
165
+ inHydration,
166
+ beginHydration
167
+ };