sibujs 1.0.3 → 1.0.4

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 (41) hide show
  1. package/LICENSE +21 -21
  2. package/dist/build.cjs +20 -0
  3. package/dist/build.js +1 -1
  4. package/dist/cdn.global.js +4 -4
  5. package/dist/{chunk-MEZVEBPN.js → chunk-32ZISOLJ.js} +22 -0
  6. package/dist/{chunk-7TQKR4PP.js → chunk-AZ3ISID5.js} +4 -0
  7. package/dist/{chunk-3CRQALYP.js → chunk-DKOHBI74.js} +49 -2
  8. package/dist/{chunk-DTCOOBMX.js → chunk-OF7UZIVB.js} +1 -1
  9. package/dist/{chunk-N6IZB6KJ.js → chunk-PBHF5WKN.js} +56 -7
  10. package/dist/{customElement-BKQfbSZQ.d.ts → customElement-yz8uyk-0.d.cts} +52 -6
  11. package/dist/{customElement-BKQfbSZQ.d.cts → customElement-yz8uyk-0.d.ts} +52 -6
  12. package/dist/extras.cjs +111 -9
  13. package/dist/extras.d.cts +3 -2
  14. package/dist/extras.d.ts +3 -2
  15. package/dist/extras.js +9 -5
  16. package/dist/index.cjs +22 -0
  17. package/dist/index.d.cts +27 -2
  18. package/dist/index.d.ts +27 -2
  19. package/dist/index.js +5 -1
  20. package/dist/patterns.d.cts +8 -2
  21. package/dist/patterns.d.ts +8 -2
  22. package/dist/plugins.cjs +142 -1
  23. package/dist/plugins.d.cts +39 -3
  24. package/dist/plugins.d.ts +39 -3
  25. package/dist/plugins.js +119 -3
  26. package/dist/{ssr-WKUPVSSK.js → ssr-6GIMY5MX.js} +5 -3
  27. package/dist/ssr-BA6sxxUd.d.cts +135 -0
  28. package/dist/ssr-BA6sxxUd.d.ts +135 -0
  29. package/dist/ssr.cjs +5 -0
  30. package/dist/ssr.d.cts +3 -113
  31. package/dist/ssr.d.ts +3 -113
  32. package/dist/ssr.js +4 -2
  33. package/dist/ui.cjs +50 -2
  34. package/dist/ui.d.cts +1 -1
  35. package/dist/ui.d.ts +1 -1
  36. package/dist/ui.js +3 -1
  37. package/dist/widgets.cjs +56 -7
  38. package/dist/widgets.d.cts +4 -2
  39. package/dist/widgets.d.ts +4 -2
  40. package/dist/widgets.js +1 -1
  41. package/package.json +139 -139
package/dist/plugins.cjs CHANGED
@@ -59,7 +59,8 @@ __export(ssr_exports, {
59
59
  resetSSRState: () => resetSSRState,
60
60
  serializeState: () => serializeState,
61
61
  ssrSuspense: () => ssrSuspense,
62
- suspenseSwapScript: () => suspenseSwapScript
62
+ suspenseSwapScript: () => suspenseSwapScript,
63
+ trustHTML: () => trustHTML
63
64
  });
64
65
  function ssrErrorComment(err) {
65
66
  if (_isDev7) {
@@ -122,6 +123,9 @@ function hydrateNode(serverNode, clientNode) {
122
123
  hydrateNode(serverChildren[i2], clientChildren[i2]);
123
124
  }
124
125
  }
126
+ function trustHTML(html2) {
127
+ return html2;
128
+ }
125
129
  function renderToDocument(component, options = {}) {
126
130
  let content;
127
131
  try {
@@ -343,6 +347,7 @@ var init_ssr = __esm({
343
347
  // plugins.ts
344
348
  var plugins_exports = {};
345
349
  __export(plugins_exports, {
350
+ KeepAliveRoute: () => KeepAliveRoute,
346
351
  Outlet: () => Outlet,
347
352
  Route: () => Route,
348
353
  RouterLink: () => RouterLink,
@@ -743,6 +748,27 @@ function registerDisposer(node, teardown) {
743
748
  disposers.push(teardown);
744
749
  if (_isDev5) activeBindingCount++;
745
750
  }
751
+ function dispose(node) {
752
+ const stack = [node];
753
+ const order = [];
754
+ while (stack.length > 0) {
755
+ const current = stack.pop();
756
+ order.push(current);
757
+ const children = current.childNodes;
758
+ for (let i2 = 0; i2 < children.length; i2++) {
759
+ stack.push(children[i2]);
760
+ }
761
+ }
762
+ for (let i2 = order.length - 1; i2 >= 0; i2--) {
763
+ const current = order[i2];
764
+ const disposers = elementDisposers.get(current);
765
+ if (disposers) {
766
+ if (_isDev5) activeBindingCount -= disposers.length;
767
+ for (const d of disposers) d();
768
+ elementDisposers.delete(current);
769
+ }
770
+ }
771
+ }
746
772
 
747
773
  // src/core/rendering/tagFactory.ts
748
774
  var SVG_NS = "http://www.w3.org/2000/svg";
@@ -2096,6 +2122,120 @@ function Route() {
2096
2122
  routeCleanups.push(cleanupNodes);
2097
2123
  return anchor;
2098
2124
  }
2125
+ function KeepAliveRoute(options) {
2126
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
2127
+ const anchor = document.createComment("keep-alive-route");
2128
+ const cache = /* @__PURE__ */ new Map();
2129
+ const lruOrder = [];
2130
+ const routerOpts = globalRouter["options"];
2131
+ const keepAliveOpt = routerOpts.keepAlive;
2132
+ const maxCache = options?.max ?? (typeof keepAliveOpt === "number" ? keepAliveOpt : 20);
2133
+ const includeNames = options?.include ?? (Array.isArray(keepAliveOpt) ? keepAliveOpt : void 0);
2134
+ let currentNode = null;
2135
+ let currentKey = "";
2136
+ let currentCached = false;
2137
+ let isUpdating = false;
2138
+ let pendingUpdate = false;
2139
+ const update = async () => {
2140
+ if (!globalRouter) return;
2141
+ if (isUpdating) {
2142
+ pendingUpdate = true;
2143
+ return;
2144
+ }
2145
+ const route2 = globalRouter.currentRoute;
2146
+ const match = globalRouter["matcher"].match(route2.path);
2147
+ if (!match) return;
2148
+ const { route: routeDef } = match;
2149
+ if ("redirect" in routeDef) {
2150
+ const redirectPath = typeof routeDef.redirect === "function" ? routeDef.redirect(route2) : routeDef.redirect;
2151
+ queueMicrotask(() => globalRouter?.navigate(redirectPath));
2152
+ return;
2153
+ }
2154
+ if (!("component" in routeDef)) return;
2155
+ const cacheKey = route2.path;
2156
+ const shouldCache = !includeNames || routeDef.name != null && includeNames.includes(routeDef.name);
2157
+ if (cacheKey === currentKey && currentNode) return;
2158
+ isUpdating = true;
2159
+ const parent = anchor.parentNode;
2160
+ if (!parent) {
2161
+ isUpdating = false;
2162
+ return;
2163
+ }
2164
+ try {
2165
+ if (currentNode?.parentNode) {
2166
+ parent.removeChild(currentNode);
2167
+ if (!currentCached) {
2168
+ dispose(currentNode);
2169
+ }
2170
+ }
2171
+ if (shouldCache && cache.has(cacheKey)) {
2172
+ currentNode = cache.get(cacheKey);
2173
+ currentCached = true;
2174
+ const idx = lruOrder.indexOf(cacheKey);
2175
+ if (idx !== -1) {
2176
+ lruOrder.splice(idx, 1);
2177
+ }
2178
+ lruOrder.push(cacheKey);
2179
+ } else {
2180
+ const component = await globalRouter.loadComponent(routeDef, route2.path);
2181
+ const node = component();
2182
+ if (!node || route2.path !== globalRouter.currentRoute.path) {
2183
+ isUpdating = false;
2184
+ return;
2185
+ }
2186
+ currentNode = node;
2187
+ currentCached = shouldCache;
2188
+ if (shouldCache) {
2189
+ cache.set(cacheKey, node);
2190
+ lruOrder.push(cacheKey);
2191
+ while (lruOrder.length > maxCache) {
2192
+ const evictKey = lruOrder.shift();
2193
+ const evictNode = cache.get(evictKey);
2194
+ if (evictNode) {
2195
+ dispose(evictNode);
2196
+ if (evictNode.parentNode) evictNode.parentNode.removeChild(evictNode);
2197
+ cache.delete(evictKey);
2198
+ }
2199
+ }
2200
+ }
2201
+ }
2202
+ currentKey = cacheKey;
2203
+ if (currentNode) {
2204
+ parent.insertBefore(currentNode, anchor.nextSibling);
2205
+ }
2206
+ } catch (error) {
2207
+ console.error("[KeepAliveRoute] Component error:", error);
2208
+ } finally {
2209
+ isUpdating = false;
2210
+ if (pendingUpdate) {
2211
+ pendingUpdate = false;
2212
+ update();
2213
+ }
2214
+ }
2215
+ };
2216
+ let initialized = false;
2217
+ const wrappedUpdate = async () => {
2218
+ await update();
2219
+ initialized = true;
2220
+ };
2221
+ track(wrappedUpdate);
2222
+ if (!initialized) {
2223
+ queueMicrotask(() => {
2224
+ if (!initialized && anchor.parentNode) wrappedUpdate();
2225
+ });
2226
+ }
2227
+ routeCleanups.push(() => {
2228
+ for (const node of cache.values()) {
2229
+ dispose(node);
2230
+ if (node.parentNode) node.parentNode.removeChild(node);
2231
+ }
2232
+ cache.clear();
2233
+ lruOrder.length = 0;
2234
+ if (currentNode?.parentNode) currentNode.parentNode.removeChild(currentNode);
2235
+ currentNode = null;
2236
+ });
2237
+ return anchor;
2238
+ }
2099
2239
  function RouterLink(props) {
2100
2240
  if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
2101
2241
  const { to, replace: replace2 = false, activeClass, exactActiveClass, nodes, target, rel, ...attrs } = props;
@@ -3396,6 +3536,7 @@ function createBootSequence() {
3396
3536
  }
3397
3537
  // Annotate the CommonJS export names for ESM import in node:
3398
3538
  0 && (module.exports = {
3539
+ KeepAliveRoute,
3399
3540
  Outlet,
3400
3541
  Route,
3401
3542
  RouterLink,
@@ -1,3 +1,4 @@
1
+ import { T as TrustedHTML } from './ssr-BA6sxxUd.cjs';
1
2
  export { P as PluginContext, S as SibuPlugin, c as createPlugin, i as inject, p as plugin, r as resetPlugins, t as triggerPluginError, a as triggerPluginMount, b as triggerPluginUnmount } from './plugin-Bek4RhJY.cjs';
2
3
  export { M as Migration, S as SemVer, V as VERSION, b as bundlerMetadata, c as checkCompatibility, a as compareSemVer, d as createBootSequence, e as createBundle, f as createMigrationRunner, g as createModuleRegistry, h as createSSRCache, i as createTestHarness, j as deferNonCritical, k as env, l as healthCheck, m as lazyModule, p as packageInfo, n as parseSemVer, o as preloadCritical, q as prerenderRoutes, s as satisfies } from './startup-0Qv6aosO.cjs';
3
4
 
@@ -85,6 +86,13 @@ interface RouterOptions {
85
86
  readonly cacheSize?: number;
86
87
  readonly errorRetryDelay?: number;
87
88
  readonly preloadStrategy?: "none" | "hover" | "visible";
89
+ /**
90
+ * Enable KeepAlive caching for route components.
91
+ * - `true` — cache all routes
92
+ * - string[] — cache only named routes matching these names
93
+ * - number — cache all routes with this max cache size
94
+ */
95
+ readonly keepAlive?: boolean | string[] | number;
88
96
  }
89
97
  type ScrollBehavior = (to: RouteContext, from: RouteContext, savedPosition: ScrollPosition | null) => ScrollPosition | null;
90
98
  interface ScrollPosition {
@@ -200,6 +208,34 @@ declare function beforeEach(guard: NavigationGuard): () => void;
200
208
  declare function beforeResolve(guard: NavigationGuard): () => void;
201
209
  declare function afterEach(hook: (to: RouteContext, from: RouteContext) => void): () => void;
202
210
  declare function Route(): Node;
211
+ /**
212
+ * A route outlet that caches rendered components using KeepAlive.
213
+ * Routes are preserved in the DOM cache so signals, form state, and scroll
214
+ * position survive navigation.
215
+ *
216
+ * Uses the `keepAlive` option from RouterOptions if set, or accepts
217
+ * explicit options.
218
+ *
219
+ * @param options Optional: override the router-level keepAlive setting
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * // Cache all routes (max 10)
224
+ * createRouter(routes, { keepAlive: 10 });
225
+ * mount(() => div({ nodes: [nav, KeepAliveRoute()] }), root);
226
+ *
227
+ * // Or cache specific routes by name
228
+ * createRouter(routes, { keepAlive: ["dashboard", "settings"] });
229
+ * mount(() => div({ nodes: [nav, KeepAliveRoute()] }), root);
230
+ *
231
+ * // Or override per-outlet
232
+ * KeepAliveRoute({ max: 5, include: ["dashboard"] })
233
+ * ```
234
+ */
235
+ declare function KeepAliveRoute(options?: {
236
+ max?: number;
237
+ include?: string[];
238
+ }): Node;
203
239
  declare function RouterLink(props: {
204
240
  to: NavigationTarget;
205
241
  replace?: boolean;
@@ -350,7 +386,7 @@ declare function renderRouteToDocument(url: string, routes: SSRRouteDef[], optio
350
386
  meta?: Record<string, string>[];
351
387
  links?: Record<string, string>[];
352
388
  scripts?: string[];
353
- headExtra?: string;
389
+ headExtra?: TrustedHTML;
354
390
  }): string;
355
391
  /**
356
392
  * Serialize route state for embedding in HTML.
@@ -392,8 +428,8 @@ declare function createSSRRouter(routes: SSRRouteDef[]): {
392
428
  meta?: Record<string, string>[];
393
429
  links?: Record<string, string>[];
394
430
  scripts?: string[];
395
- headExtra?: string;
431
+ headExtra?: TrustedHTML;
396
432
  }) => string;
397
433
  };
398
434
 
399
- export { type AsyncComponent, type AsyncRoute, type Component, type ComponentRoute, type Guard, type GuardResult, type LazyComponent, type NavigationFailure, type NavigationGuard, type NavigationNext, type NavigationResult, type NavigationTarget, Outlet, type Params, type RedirectRoute, Route, type RouteBase, type RouteContext, type RouteDef, type RouteMeta, type RouteTransitionOptions, RouterLink, type RouterOptions, type RouterPlugin, type SSRRouteDef, type SSRRouteState, type ScrollBehavior, type ScrollPosition, SibuRouter, Suspense, Trans, addRoute, afterEach, back, beforeEach, beforeResolve, buildURL, createMemoryRouter, createRouter, createSSRRouter, deserializeRouteState, destroyRouter, forward, getAvailableLocales, getLocale, getRouteInfo, getRouteTransition, go, hasRoute, hasTranslation, hydrateRouter, lazy, navigate, preloadRoute, push, registerTranslations, removeRoute, renderRouteToDocument, renderRouteToString, replace, resolveServerRoute, route, router, routerPlugin, routerState, serializeRouteState, setLocale, setRouteTransition, setRoutes, t };
435
+ export { type AsyncComponent, type AsyncRoute, type Component, type ComponentRoute, type Guard, type GuardResult, KeepAliveRoute, type LazyComponent, type NavigationFailure, type NavigationGuard, type NavigationNext, type NavigationResult, type NavigationTarget, Outlet, type Params, type RedirectRoute, Route, type RouteBase, type RouteContext, type RouteDef, type RouteMeta, type RouteTransitionOptions, RouterLink, type RouterOptions, type RouterPlugin, type SSRRouteDef, type SSRRouteState, type ScrollBehavior, type ScrollPosition, SibuRouter, Suspense, Trans, addRoute, afterEach, back, beforeEach, beforeResolve, buildURL, createMemoryRouter, createRouter, createSSRRouter, deserializeRouteState, destroyRouter, forward, getAvailableLocales, getLocale, getRouteInfo, getRouteTransition, go, hasRoute, hasTranslation, hydrateRouter, lazy, navigate, preloadRoute, push, registerTranslations, removeRoute, renderRouteToDocument, renderRouteToString, replace, resolveServerRoute, route, router, routerPlugin, routerState, serializeRouteState, setLocale, setRouteTransition, setRoutes, t };
package/dist/plugins.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { T as TrustedHTML } from './ssr-BA6sxxUd.js';
1
2
  export { P as PluginContext, S as SibuPlugin, c as createPlugin, i as inject, p as plugin, r as resetPlugins, t as triggerPluginError, a as triggerPluginMount, b as triggerPluginUnmount } from './plugin-Bek4RhJY.js';
2
3
  export { M as Migration, S as SemVer, V as VERSION, b as bundlerMetadata, c as checkCompatibility, a as compareSemVer, d as createBootSequence, e as createBundle, f as createMigrationRunner, g as createModuleRegistry, h as createSSRCache, i as createTestHarness, j as deferNonCritical, k as env, l as healthCheck, m as lazyModule, p as packageInfo, n as parseSemVer, o as preloadCritical, q as prerenderRoutes, s as satisfies } from './startup-0Qv6aosO.js';
3
4
 
@@ -85,6 +86,13 @@ interface RouterOptions {
85
86
  readonly cacheSize?: number;
86
87
  readonly errorRetryDelay?: number;
87
88
  readonly preloadStrategy?: "none" | "hover" | "visible";
89
+ /**
90
+ * Enable KeepAlive caching for route components.
91
+ * - `true` — cache all routes
92
+ * - string[] — cache only named routes matching these names
93
+ * - number — cache all routes with this max cache size
94
+ */
95
+ readonly keepAlive?: boolean | string[] | number;
88
96
  }
89
97
  type ScrollBehavior = (to: RouteContext, from: RouteContext, savedPosition: ScrollPosition | null) => ScrollPosition | null;
90
98
  interface ScrollPosition {
@@ -200,6 +208,34 @@ declare function beforeEach(guard: NavigationGuard): () => void;
200
208
  declare function beforeResolve(guard: NavigationGuard): () => void;
201
209
  declare function afterEach(hook: (to: RouteContext, from: RouteContext) => void): () => void;
202
210
  declare function Route(): Node;
211
+ /**
212
+ * A route outlet that caches rendered components using KeepAlive.
213
+ * Routes are preserved in the DOM cache so signals, form state, and scroll
214
+ * position survive navigation.
215
+ *
216
+ * Uses the `keepAlive` option from RouterOptions if set, or accepts
217
+ * explicit options.
218
+ *
219
+ * @param options Optional: override the router-level keepAlive setting
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * // Cache all routes (max 10)
224
+ * createRouter(routes, { keepAlive: 10 });
225
+ * mount(() => div({ nodes: [nav, KeepAliveRoute()] }), root);
226
+ *
227
+ * // Or cache specific routes by name
228
+ * createRouter(routes, { keepAlive: ["dashboard", "settings"] });
229
+ * mount(() => div({ nodes: [nav, KeepAliveRoute()] }), root);
230
+ *
231
+ * // Or override per-outlet
232
+ * KeepAliveRoute({ max: 5, include: ["dashboard"] })
233
+ * ```
234
+ */
235
+ declare function KeepAliveRoute(options?: {
236
+ max?: number;
237
+ include?: string[];
238
+ }): Node;
203
239
  declare function RouterLink(props: {
204
240
  to: NavigationTarget;
205
241
  replace?: boolean;
@@ -350,7 +386,7 @@ declare function renderRouteToDocument(url: string, routes: SSRRouteDef[], optio
350
386
  meta?: Record<string, string>[];
351
387
  links?: Record<string, string>[];
352
388
  scripts?: string[];
353
- headExtra?: string;
389
+ headExtra?: TrustedHTML;
354
390
  }): string;
355
391
  /**
356
392
  * Serialize route state for embedding in HTML.
@@ -392,8 +428,8 @@ declare function createSSRRouter(routes: SSRRouteDef[]): {
392
428
  meta?: Record<string, string>[];
393
429
  links?: Record<string, string>[];
394
430
  scripts?: string[];
395
- headExtra?: string;
431
+ headExtra?: TrustedHTML;
396
432
  }) => string;
397
433
  };
398
434
 
399
- export { type AsyncComponent, type AsyncRoute, type Component, type ComponentRoute, type Guard, type GuardResult, type LazyComponent, type NavigationFailure, type NavigationGuard, type NavigationNext, type NavigationResult, type NavigationTarget, Outlet, type Params, type RedirectRoute, Route, type RouteBase, type RouteContext, type RouteDef, type RouteMeta, type RouteTransitionOptions, RouterLink, type RouterOptions, type RouterPlugin, type SSRRouteDef, type SSRRouteState, type ScrollBehavior, type ScrollPosition, SibuRouter, Suspense, Trans, addRoute, afterEach, back, beforeEach, beforeResolve, buildURL, createMemoryRouter, createRouter, createSSRRouter, deserializeRouteState, destroyRouter, forward, getAvailableLocales, getLocale, getRouteInfo, getRouteTransition, go, hasRoute, hasTranslation, hydrateRouter, lazy, navigate, preloadRoute, push, registerTranslations, removeRoute, renderRouteToDocument, renderRouteToString, replace, resolveServerRoute, route, router, routerPlugin, routerState, serializeRouteState, setLocale, setRouteTransition, setRoutes, t };
435
+ export { type AsyncComponent, type AsyncRoute, type Component, type ComponentRoute, type Guard, type GuardResult, KeepAliveRoute, type LazyComponent, type NavigationFailure, type NavigationGuard, type NavigationNext, type NavigationResult, type NavigationTarget, Outlet, type Params, type RedirectRoute, Route, type RouteBase, type RouteContext, type RouteDef, type RouteMeta, type RouteTransitionOptions, RouterLink, type RouterOptions, type RouterPlugin, type SSRRouteDef, type SSRRouteState, type ScrollBehavior, type ScrollPosition, SibuRouter, Suspense, Trans, addRoute, afterEach, back, beforeEach, beforeResolve, buildURL, createMemoryRouter, createRouter, createSSRRouter, deserializeRouteState, destroyRouter, forward, getAvailableLocales, getLocale, getRouteInfo, getRouteTransition, go, hasRoute, hasTranslation, hydrateRouter, lazy, navigate, preloadRoute, push, registerTranslations, removeRoute, renderRouteToDocument, renderRouteToString, replace, resolveServerRoute, route, router, routerPlugin, routerState, serializeRouteState, setLocale, setRouteTransition, setRoutes, t };
package/dist/plugins.js CHANGED
@@ -18,10 +18,10 @@ import {
18
18
  preloadCritical,
19
19
  prerenderRoutes,
20
20
  satisfies
21
- } from "./chunk-DTCOOBMX.js";
21
+ } from "./chunk-OF7UZIVB.js";
22
22
  import {
23
23
  renderToString
24
- } from "./chunk-7TQKR4PP.js";
24
+ } from "./chunk-AZ3ISID5.js";
25
25
  import {
26
26
  createPlugin,
27
27
  inject,
@@ -35,6 +35,7 @@ import {
35
35
  span
36
36
  } from "./chunk-EWFVA3TJ.js";
37
37
  import {
38
+ dispose,
38
39
  registerDisposer
39
40
  } from "./chunk-MDVXJWFN.js";
40
41
  import "./chunk-SDLZDHKP.js";
@@ -985,6 +986,120 @@ function Route() {
985
986
  routeCleanups.push(cleanupNodes);
986
987
  return anchor;
987
988
  }
989
+ function KeepAliveRoute(options) {
990
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
991
+ const anchor = document.createComment("keep-alive-route");
992
+ const cache = /* @__PURE__ */ new Map();
993
+ const lruOrder = [];
994
+ const routerOpts = globalRouter["options"];
995
+ const keepAliveOpt = routerOpts.keepAlive;
996
+ const maxCache = options?.max ?? (typeof keepAliveOpt === "number" ? keepAliveOpt : 20);
997
+ const includeNames = options?.include ?? (Array.isArray(keepAliveOpt) ? keepAliveOpt : void 0);
998
+ let currentNode = null;
999
+ let currentKey = "";
1000
+ let currentCached = false;
1001
+ let isUpdating = false;
1002
+ let pendingUpdate = false;
1003
+ const update = async () => {
1004
+ if (!globalRouter) return;
1005
+ if (isUpdating) {
1006
+ pendingUpdate = true;
1007
+ return;
1008
+ }
1009
+ const route2 = globalRouter.currentRoute;
1010
+ const match = globalRouter["matcher"].match(route2.path);
1011
+ if (!match) return;
1012
+ const { route: routeDef } = match;
1013
+ if ("redirect" in routeDef) {
1014
+ const redirectPath = typeof routeDef.redirect === "function" ? routeDef.redirect(route2) : routeDef.redirect;
1015
+ queueMicrotask(() => globalRouter?.navigate(redirectPath));
1016
+ return;
1017
+ }
1018
+ if (!("component" in routeDef)) return;
1019
+ const cacheKey = route2.path;
1020
+ const shouldCache = !includeNames || routeDef.name != null && includeNames.includes(routeDef.name);
1021
+ if (cacheKey === currentKey && currentNode) return;
1022
+ isUpdating = true;
1023
+ const parent = anchor.parentNode;
1024
+ if (!parent) {
1025
+ isUpdating = false;
1026
+ return;
1027
+ }
1028
+ try {
1029
+ if (currentNode?.parentNode) {
1030
+ parent.removeChild(currentNode);
1031
+ if (!currentCached) {
1032
+ dispose(currentNode);
1033
+ }
1034
+ }
1035
+ if (shouldCache && cache.has(cacheKey)) {
1036
+ currentNode = cache.get(cacheKey);
1037
+ currentCached = true;
1038
+ const idx = lruOrder.indexOf(cacheKey);
1039
+ if (idx !== -1) {
1040
+ lruOrder.splice(idx, 1);
1041
+ }
1042
+ lruOrder.push(cacheKey);
1043
+ } else {
1044
+ const component = await globalRouter.loadComponent(routeDef, route2.path);
1045
+ const node = component();
1046
+ if (!node || route2.path !== globalRouter.currentRoute.path) {
1047
+ isUpdating = false;
1048
+ return;
1049
+ }
1050
+ currentNode = node;
1051
+ currentCached = shouldCache;
1052
+ if (shouldCache) {
1053
+ cache.set(cacheKey, node);
1054
+ lruOrder.push(cacheKey);
1055
+ while (lruOrder.length > maxCache) {
1056
+ const evictKey = lruOrder.shift();
1057
+ const evictNode = cache.get(evictKey);
1058
+ if (evictNode) {
1059
+ dispose(evictNode);
1060
+ if (evictNode.parentNode) evictNode.parentNode.removeChild(evictNode);
1061
+ cache.delete(evictKey);
1062
+ }
1063
+ }
1064
+ }
1065
+ }
1066
+ currentKey = cacheKey;
1067
+ if (currentNode) {
1068
+ parent.insertBefore(currentNode, anchor.nextSibling);
1069
+ }
1070
+ } catch (error) {
1071
+ console.error("[KeepAliveRoute] Component error:", error);
1072
+ } finally {
1073
+ isUpdating = false;
1074
+ if (pendingUpdate) {
1075
+ pendingUpdate = false;
1076
+ update();
1077
+ }
1078
+ }
1079
+ };
1080
+ let initialized = false;
1081
+ const wrappedUpdate = async () => {
1082
+ await update();
1083
+ initialized = true;
1084
+ };
1085
+ track(wrappedUpdate);
1086
+ if (!initialized) {
1087
+ queueMicrotask(() => {
1088
+ if (!initialized && anchor.parentNode) wrappedUpdate();
1089
+ });
1090
+ }
1091
+ routeCleanups.push(() => {
1092
+ for (const node of cache.values()) {
1093
+ dispose(node);
1094
+ if (node.parentNode) node.parentNode.removeChild(node);
1095
+ }
1096
+ cache.clear();
1097
+ lruOrder.length = 0;
1098
+ if (currentNode?.parentNode) currentNode.parentNode.removeChild(currentNode);
1099
+ currentNode = null;
1100
+ });
1101
+ return anchor;
1102
+ }
988
1103
  function RouterLink(props) {
989
1104
  if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
990
1105
  const { to, replace: replace2 = false, activeClass, exactActiveClass, nodes, target, rel, ...attrs } = props;
@@ -1474,7 +1589,7 @@ function hydrateRouter(routes, options) {
1474
1589
  if (container && serverState.path) {
1475
1590
  const resolved = resolveServerRoute(serverState.path, routes);
1476
1591
  if (resolved.component) {
1477
- import("./ssr-WKUPVSSK.js").then(({ hydrate }) => {
1592
+ import("./ssr-6GIMY5MX.js").then(({ hydrate }) => {
1478
1593
  if (resolved.component) {
1479
1594
  hydrate(resolved.component, container);
1480
1595
  }
@@ -1502,6 +1617,7 @@ function escapeAttr(str) {
1502
1617
  return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1503
1618
  }
1504
1619
  export {
1620
+ KeepAliveRoute,
1505
1621
  Outlet,
1506
1622
  Route,
1507
1623
  RouterLink,
@@ -13,8 +13,9 @@ import {
13
13
  resetSSRState,
14
14
  serializeState,
15
15
  ssrSuspense,
16
- suspenseSwapScript
17
- } from "./chunk-7TQKR4PP.js";
16
+ suspenseSwapScript,
17
+ trustHTML
18
+ } from "./chunk-AZ3ISID5.js";
18
19
  import "./chunk-4MYMUBRS.js";
19
20
  import "./chunk-MLKGABMK.js";
20
21
  export {
@@ -32,5 +33,6 @@ export {
32
33
  resetSSRState,
33
34
  serializeState,
34
35
  ssrSuspense,
35
- suspenseSwapScript
36
+ suspenseSwapScript,
37
+ trustHTML
36
38
  };
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Converts an HTMLElement tree to an HTML string for server-side rendering.
3
+ */
4
+ declare function renderToString(element: HTMLElement | DocumentFragment | Node): string;
5
+ /**
6
+ * Hydrates a server-rendered DOM tree by attaching event listeners
7
+ * and activating reactive bindings.
8
+ */
9
+ declare function hydrate(component: () => HTMLElement, container: HTMLElement): void;
10
+ /**
11
+ * Branded type for raw HTML that has been explicitly marked as trusted.
12
+ * Use `trustHTML()` to create a value of this type. This prevents
13
+ * accidental injection of unsanitized user input into `headExtra`.
14
+ */
15
+ type TrustedHTML = string & {
16
+ readonly __brand: "TrustedHTML";
17
+ };
18
+ /**
19
+ * Mark an HTML string as trusted for use in contexts that accept raw HTML
20
+ * (e.g. `renderToDocument({ headExtra })`). Only call this on
21
+ * developer-controlled strings — never on user input.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const extra = trustHTML('<link rel="preconnect" href="https://fonts.googleapis.com">');
26
+ * renderToDocument(App, { headExtra: extra });
27
+ * ```
28
+ */
29
+ declare function trustHTML(html: string): TrustedHTML;
30
+ /**
31
+ * Renders a component to a full HTML document string.
32
+ *
33
+ * `headExtra` requires a `TrustedHTML` value created via `trustHTML()`.
34
+ * This prevents accidental injection of unsanitized user input.
35
+ */
36
+ declare function renderToDocument(component: () => HTMLElement, options?: {
37
+ title?: string;
38
+ meta?: Record<string, string>[];
39
+ links?: Record<string, string>[];
40
+ scripts?: string[];
41
+ bodyAttrs?: Record<string, string>;
42
+ /**
43
+ * Raw HTML injected into `<head>`. Must be wrapped in `trustHTML()`
44
+ * to confirm the content is developer-controlled.
45
+ */
46
+ headExtra?: TrustedHTML;
47
+ }): string;
48
+ /**
49
+ * Renders a component tree to an async iterable of HTML chunks.
50
+ * Enables progressive server-side rendering — the consumer can write
51
+ * each chunk to a response stream as it becomes available.
52
+ */
53
+ declare function renderToStream(element: HTMLElement | DocumentFragment | Node): AsyncGenerator<string>;
54
+ /**
55
+ * Collects the full output of renderToStream into a string.
56
+ */
57
+ declare function collectStream(stream: AsyncGenerator<string> | AsyncIterable<string>): Promise<string>;
58
+ /**
59
+ * Renders a component tree to a Web ReadableStream<string>.
60
+ * Compatible with Node 18+, Deno, and edge runtimes.
61
+ * Uses pull-based backpressure — chunks are produced on demand.
62
+ */
63
+ declare function renderToReadableStream(element: HTMLElement | DocumentFragment | Node): ReadableStream<string>;
64
+ /**
65
+ * Marks an element as a hydration island. During partial hydration
66
+ * only elements marked with `data-sibu-island` will be hydrated.
67
+ */
68
+ declare function island(id: string, component: () => HTMLElement): HTMLElement;
69
+ /**
70
+ * Hydrate only elements marked as islands (`data-sibu-island`).
71
+ * Non-island content keeps its server-rendered HTML untouched.
72
+ */
73
+ declare function hydrateIslands(container: HTMLElement, islands: Record<string, () => HTMLElement>): void;
74
+ /**
75
+ * Progressively hydrate islands only when they enter the viewport.
76
+ * Uses IntersectionObserver to defer hydration of off-screen islands,
77
+ * reducing initial JavaScript execution cost.
78
+ *
79
+ * Returns a cleanup function that disconnects all observers.
80
+ */
81
+ declare function hydrateProgressively(container: HTMLElement, islands: Record<string, () => HTMLElement>, options?: IntersectionObserverInit): () => void;
82
+ /**
83
+ * Reset SSR state between requests. Call at the start of each SSR render
84
+ * to prevent ID drift in long-lived server processes.
85
+ */
86
+ declare function resetSSRState(): void;
87
+ /**
88
+ * Create a suspense boundary for SSR streaming.
89
+ * Renders fallback HTML inline and returns a promise for the resolved content.
90
+ *
91
+ * The returned element contains the fallback UI with a `data-sibu-suspense-id`
92
+ * marker. The promise resolves to `{ id, html }` once async content is ready.
93
+ */
94
+ declare function ssrSuspense(props: {
95
+ fallback: () => HTMLElement;
96
+ content: () => Promise<HTMLElement>;
97
+ }): {
98
+ element: HTMLElement;
99
+ promise: Promise<{
100
+ id: string;
101
+ html: string;
102
+ }>;
103
+ };
104
+ /**
105
+ * Generate an inline script that swaps a suspense fallback with resolved content.
106
+ * The id is escaped for both JS string and HTML attribute contexts to prevent injection.
107
+ */
108
+ declare function suspenseSwapScript(id: string, nonce?: string): string;
109
+ /**
110
+ * Renders a component tree with suspense boundaries as a stream.
111
+ * Yields the main tree HTML first (including fallback content for suspended
112
+ * boundaries), then flushes resolved content with inline swap scripts.
113
+ */
114
+ declare function renderToSuspenseStream(element: HTMLElement | DocumentFragment | Node, pendingBoundaries?: Promise<{
115
+ id: string;
116
+ html: string;
117
+ }>[]): AsyncGenerator<string>;
118
+ /**
119
+ * Serialize application state into an HTML script tag for SSR.
120
+ * The serialized data is embedded in the document and picked up
121
+ * on the client with `deserializeState()`.
122
+ */
123
+ declare function serializeState(state: Record<string, unknown>, nonce?: string): string;
124
+ /**
125
+ * Retrieve state that was embedded by `serializeState()` during SSR.
126
+ *
127
+ * When a `validate` function is provided, it acts as a type guard —
128
+ * only data that passes validation is returned. This prevents
129
+ * tampered SSR payloads from being trusted by the client.
130
+ *
131
+ * @param validate Optional type guard to verify data integrity
132
+ */
133
+ declare function deserializeState<T = Record<string, unknown>>(validate?: (data: unknown) => data is T): T | undefined;
134
+
135
+ export { type TrustedHTML as T, hydrateIslands as a, hydrateProgressively as b, collectStream as c, deserializeState as d, renderToReadableStream as e, renderToStream as f, renderToString as g, hydrate as h, island as i, renderToSuspenseStream as j, resetSSRState as k, ssrSuspense as l, suspenseSwapScript as m, renderToDocument as r, serializeState as s, trustHTML as t };