@funstack/router 0.0.7 → 0.0.9
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/dist/docs/ApiComponentsPage.tsx +33 -0
- package/dist/docs/ApiHooksPage.tsx +8 -3
- package/dist/docs/ApiTypesPage.tsx +56 -8
- package/dist/docs/ApiUtilitiesPage.tsx +26 -8
- package/dist/docs/ExamplesPage.tsx +445 -0
- package/dist/docs/GettingStartedPage.tsx +10 -33
- package/dist/docs/LearnNavigationApiPage.tsx +1 -4
- package/dist/docs/LearnNestedRoutesPage.tsx +8 -6
- package/dist/docs/LearnRscPage.tsx +77 -94
- package/dist/docs/LearnSsgPage.tsx +133 -0
- package/dist/docs/{LearnSsrPage.tsx → LearnSsrBasicPage.tsx} +44 -21
- package/dist/docs/LearnSsrWithLoadersPage.tsx +141 -0
- package/dist/docs/LearnTransitionsPage.tsx +80 -6
- package/dist/docs/LearnTypeSafetyPage.tsx +28 -22
- package/dist/docs/index.md +5 -2
- package/dist/index.d.mts +56 -25
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +118 -26
- package/dist/index.mjs.map +1 -1
- package/dist/{route-ClVnhrQD.d.mts → route-DRcgs0Pt.d.mts} +61 -6
- package/dist/route-DRcgs0Pt.d.mts.map +1 -0
- package/dist/route-p_gr5yPI.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/package.json +1 -1
- package/dist/route-ClVnhrQD.d.mts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -61,13 +61,15 @@ function internalRoutes(routes) {
|
|
|
61
61
|
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/core/matchRoutes.ts
|
|
64
|
+
const SKIPPED = Symbol("skipped");
|
|
64
65
|
/**
|
|
65
66
|
* Match a pathname against a route tree, returning the matched route stack.
|
|
66
67
|
* Returns null if no match is found.
|
|
67
68
|
*/
|
|
68
|
-
function matchRoutes(routes, pathname) {
|
|
69
|
+
function matchRoutes(routes, pathname, options) {
|
|
69
70
|
for (const route of routes) {
|
|
70
|
-
const matched = matchRoute(route, pathname);
|
|
71
|
+
const matched = matchRoute(route, pathname, options);
|
|
72
|
+
if (matched === SKIPPED) return null;
|
|
71
73
|
if (matched) return matched;
|
|
72
74
|
}
|
|
73
75
|
return null;
|
|
@@ -75,22 +77,40 @@ function matchRoutes(routes, pathname) {
|
|
|
75
77
|
/**
|
|
76
78
|
* Match a single route and its children recursively.
|
|
77
79
|
*/
|
|
78
|
-
function matchRoute(route, pathname) {
|
|
80
|
+
function matchRoute(route, pathname, options) {
|
|
79
81
|
const hasChildren = Boolean(route.children?.length);
|
|
82
|
+
const skipLoaders = options?.skipLoaders ?? false;
|
|
83
|
+
if ((pathname === null || skipLoaders) && route.loader) {
|
|
84
|
+
if (skipLoaders && pathname !== null) {
|
|
85
|
+
if (route.path === void 0) return SKIPPED;
|
|
86
|
+
const isExact = route.exact ?? !hasChildren;
|
|
87
|
+
const { matched } = matchPath(route.path, pathname, isExact);
|
|
88
|
+
if (matched) return SKIPPED;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
80
92
|
if (route.path === void 0) {
|
|
81
|
-
if (pathname === null && route.loader) return null;
|
|
82
93
|
const result = {
|
|
83
94
|
route,
|
|
84
95
|
params: {},
|
|
85
96
|
pathname: ""
|
|
86
97
|
};
|
|
87
98
|
if (hasChildren) {
|
|
99
|
+
let anySkipped = false;
|
|
88
100
|
for (const child of route.children) {
|
|
89
|
-
const childMatch = matchRoute(child, pathname);
|
|
101
|
+
const childMatch = matchRoute(child, pathname, options);
|
|
102
|
+
if (childMatch === SKIPPED) {
|
|
103
|
+
anySkipped = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
90
106
|
if (childMatch) return [result, ...childMatch];
|
|
91
107
|
}
|
|
108
|
+
if (anySkipped) {
|
|
109
|
+
if (route.component) return [result];
|
|
110
|
+
return SKIPPED;
|
|
111
|
+
}
|
|
92
112
|
if (route.component && route.requireChildren === false) return [result];
|
|
93
|
-
if (pathname === null && route.component) return [result];
|
|
113
|
+
if ((pathname === null || skipLoaders) && route.component) return [result];
|
|
94
114
|
return null;
|
|
95
115
|
}
|
|
96
116
|
return [result];
|
|
@@ -108,8 +128,13 @@ function matchRoute(route, pathname) {
|
|
|
108
128
|
let remainingPathname = pathname.slice(consumedPathname.length);
|
|
109
129
|
if (!remainingPathname.startsWith("/")) remainingPathname = "/" + remainingPathname;
|
|
110
130
|
if (remainingPathname === "") remainingPathname = "/";
|
|
131
|
+
let anyChildSkipped = false;
|
|
111
132
|
for (const child of route.children) {
|
|
112
|
-
const childMatch = matchRoute(child, remainingPathname);
|
|
133
|
+
const childMatch = matchRoute(child, remainingPathname, options);
|
|
134
|
+
if (childMatch === SKIPPED) {
|
|
135
|
+
anyChildSkipped = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
113
138
|
if (childMatch) return [result, ...childMatch.map((m) => ({
|
|
114
139
|
...m,
|
|
115
140
|
params: {
|
|
@@ -118,7 +143,12 @@ function matchRoute(route, pathname) {
|
|
|
118
143
|
}
|
|
119
144
|
}))];
|
|
120
145
|
}
|
|
146
|
+
if (anyChildSkipped) {
|
|
147
|
+
if (route.component) return [result];
|
|
148
|
+
return SKIPPED;
|
|
149
|
+
}
|
|
121
150
|
if (route.component && route.requireChildren === false) return [result];
|
|
151
|
+
if (skipLoaders && route.component) return [result];
|
|
122
152
|
return null;
|
|
123
153
|
}
|
|
124
154
|
return [result];
|
|
@@ -178,16 +208,26 @@ function createLoaderRequest(url) {
|
|
|
178
208
|
return new Request(url.href, { method: "GET" });
|
|
179
209
|
}
|
|
180
210
|
/**
|
|
211
|
+
* Create a Request object for action args (POST with FormData body).
|
|
212
|
+
*/
|
|
213
|
+
function createActionRequest(url, formData) {
|
|
214
|
+
return new Request(url.href, {
|
|
215
|
+
method: "POST",
|
|
216
|
+
body: formData
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
181
220
|
* Execute loaders for matched routes and return routes with data.
|
|
182
221
|
* Results are cached by navigation entry id to prevent duplicate execution.
|
|
183
222
|
*/
|
|
184
|
-
function executeLoaders(matchedRoutes, entryId, request, signal) {
|
|
223
|
+
function executeLoaders(matchedRoutes, entryId, request, signal, actionResult) {
|
|
185
224
|
return matchedRoutes.map((match, index) => {
|
|
186
225
|
const { route, params } = match;
|
|
187
226
|
const data = getOrCreateLoaderResult(entryId, index, route, {
|
|
188
227
|
params,
|
|
189
228
|
request,
|
|
190
|
-
signal
|
|
229
|
+
signal,
|
|
230
|
+
actionResult
|
|
191
231
|
});
|
|
192
232
|
return {
|
|
193
233
|
...match,
|
|
@@ -235,7 +275,9 @@ var NavigationAPIAdapter = class {
|
|
|
235
275
|
}
|
|
236
276
|
subscribe(callback) {
|
|
237
277
|
const controller = new AbortController();
|
|
238
|
-
navigation.addEventListener("currententrychange",
|
|
278
|
+
navigation.addEventListener("currententrychange", (event) => {
|
|
279
|
+
callback(event.navigationType === null ? "state" : "navigation");
|
|
280
|
+
}, { signal: controller.signal });
|
|
239
281
|
this.#subscribeToDisposeEvents(controller.signal);
|
|
240
282
|
navigation.addEventListener("currententrychange", () => this.#subscribeToDisposeEvents(controller.signal), { signal: controller.signal });
|
|
241
283
|
return () => {
|
|
@@ -286,17 +328,30 @@ var NavigationAPIAdapter = class {
|
|
|
286
328
|
if (!event.canIntercept) {
|
|
287
329
|
onNavigate?.(event, {
|
|
288
330
|
matches: [],
|
|
289
|
-
intercepting: false
|
|
331
|
+
intercepting: false,
|
|
332
|
+
formData: event.formData
|
|
290
333
|
});
|
|
291
334
|
return;
|
|
292
335
|
}
|
|
293
336
|
const url = new URL(event.destination.url);
|
|
294
337
|
const matched = matchRoutes(routes, url.pathname);
|
|
338
|
+
const isFormSubmission = event.formData !== null;
|
|
339
|
+
if (isFormSubmission && matched !== null) {
|
|
340
|
+
if (!matched.some((m) => m.route.action)) {
|
|
341
|
+
onNavigate?.(event, {
|
|
342
|
+
matches: matched,
|
|
343
|
+
intercepting: false,
|
|
344
|
+
formData: event.formData
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
295
349
|
const willIntercept = matched !== null && !event.hashChange && event.downloadRequest === null;
|
|
296
350
|
if (onNavigate) {
|
|
297
351
|
onNavigate(event, {
|
|
298
352
|
matches: matched,
|
|
299
|
-
intercepting: willIntercept
|
|
353
|
+
intercepting: willIntercept,
|
|
354
|
+
formData: event.formData
|
|
300
355
|
});
|
|
301
356
|
if (event.defaultPrevented) return;
|
|
302
357
|
}
|
|
@@ -306,10 +361,23 @@ var NavigationAPIAdapter = class {
|
|
|
306
361
|
idleController = null;
|
|
307
362
|
}
|
|
308
363
|
event.intercept({ handler: async () => {
|
|
309
|
-
const request = createLoaderRequest(url);
|
|
310
364
|
const currentEntry = navigation.currentEntry;
|
|
311
365
|
if (!currentEntry) throw new Error("Navigation currentEntry is null during navigation interception");
|
|
312
|
-
|
|
366
|
+
let actionResult = void 0;
|
|
367
|
+
if (isFormSubmission) {
|
|
368
|
+
const actionRoute = findActionRoute(matched);
|
|
369
|
+
if (actionRoute) {
|
|
370
|
+
const actionRequest = createActionRequest(url, event.formData);
|
|
371
|
+
actionResult = await actionRoute.route.action({
|
|
372
|
+
params: actionRoute.params,
|
|
373
|
+
request: actionRequest,
|
|
374
|
+
signal: event.signal
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
clearLoaderCacheForEntry(currentEntry.id);
|
|
378
|
+
}
|
|
379
|
+
const request = createLoaderRequest(url);
|
|
380
|
+
const results = executeLoaders(matched, currentEntry.id, request, event.signal, actionResult);
|
|
313
381
|
await Promise.all(results.map((r) => r.data));
|
|
314
382
|
} });
|
|
315
383
|
};
|
|
@@ -328,6 +396,13 @@ var NavigationAPIAdapter = class {
|
|
|
328
396
|
navigation.updateCurrentEntry({ state });
|
|
329
397
|
}
|
|
330
398
|
};
|
|
399
|
+
/**
|
|
400
|
+
* Find the deepest matched route that has an action defined.
|
|
401
|
+
* Iterates from deepest to shallowest.
|
|
402
|
+
*/
|
|
403
|
+
function findActionRoute(matched) {
|
|
404
|
+
for (let i = matched.length - 1; i >= 0; i--) if (matched[i].route.action) return matched[i];
|
|
405
|
+
}
|
|
331
406
|
|
|
332
407
|
//#endregion
|
|
333
408
|
//#region src/core/StaticAdapter.ts
|
|
@@ -352,7 +427,7 @@ var StaticAdapter = class {
|
|
|
352
427
|
subscribe(_callback) {
|
|
353
428
|
return () => {};
|
|
354
429
|
}
|
|
355
|
-
navigate(
|
|
430
|
+
navigate(_to, _options) {
|
|
356
431
|
console.warn("FUNSTACK Router: navigate() called in static fallback mode. Navigation API is not available in this browser. Links will cause full page loads.");
|
|
357
432
|
}
|
|
358
433
|
async navigateAsync(to, options) {
|
|
@@ -423,7 +498,7 @@ function createAdapter(fallback) {
|
|
|
423
498
|
const serverSnapshotSymbol = Symbol();
|
|
424
499
|
const noopSubscribe = () => () => {};
|
|
425
500
|
const getServerSnapshot = () => serverSnapshotSymbol;
|
|
426
|
-
function Router({ routes: inputRoutes, onNavigate, fallback = "none" }) {
|
|
501
|
+
function Router({ routes: inputRoutes, onNavigate, fallback = "none", ssr }) {
|
|
427
502
|
const routes = internalRoutes(inputRoutes);
|
|
428
503
|
const adapter = useMemo(() => createAdapter(fallback), [fallback]);
|
|
429
504
|
const [blockerRegistry] = useState(() => createBlockerRegistry());
|
|
@@ -433,10 +508,11 @@ function Router({ routes: inputRoutes, onNavigate, fallback = "none" }) {
|
|
|
433
508
|
const locationEntry = locationEntryInternal === serverSnapshotSymbol ? null : locationEntryInternal;
|
|
434
509
|
if (locationEntryInternal === serverSnapshotSymbol && initialEntry !== serverSnapshotSymbol) setLocationEntry(initialEntry);
|
|
435
510
|
useEffect(() => {
|
|
436
|
-
return adapter.subscribe(() => {
|
|
437
|
-
startTransition(() => {
|
|
511
|
+
return adapter.subscribe((changeType) => {
|
|
512
|
+
if (changeType === "navigation") startTransition(() => {
|
|
438
513
|
setLocationEntry(adapter.getSnapshot());
|
|
439
514
|
});
|
|
515
|
+
else setLocationEntry(adapter.getSnapshot());
|
|
440
516
|
});
|
|
441
517
|
}, [adapter, startTransition]);
|
|
442
518
|
useEffect(() => {
|
|
@@ -458,22 +534,22 @@ function Router({ routes: inputRoutes, onNavigate, fallback = "none" }) {
|
|
|
458
534
|
}, [adapter]);
|
|
459
535
|
return useMemo(() => {
|
|
460
536
|
const matchedRoutesWithData = (() => {
|
|
461
|
-
if (locationEntry === null) {
|
|
462
|
-
const matched = matchRoutes(routes, null);
|
|
537
|
+
if (locationEntry === null && !ssr?.runLoaders) {
|
|
538
|
+
const matched = matchRoutes(routes, ssr?.path ?? null, { skipLoaders: true });
|
|
463
539
|
if (!matched) return null;
|
|
464
540
|
return matched.map((m) => ({
|
|
465
541
|
...m,
|
|
466
542
|
data: void 0
|
|
467
543
|
}));
|
|
468
544
|
}
|
|
469
|
-
const
|
|
545
|
+
const url = locationEntry ? locationEntry.url : new URL(ssr.path, "http://localhost");
|
|
470
546
|
const matched = matchRoutes(routes, url.pathname);
|
|
471
547
|
if (!matched) return null;
|
|
472
|
-
return executeLoaders(matched, key, createLoaderRequest(url), adapter.getIdleAbortSignal());
|
|
548
|
+
return executeLoaders(matched, locationEntry?.key ?? "ssr", createLoaderRequest(url), locationEntry ? adapter.getIdleAbortSignal() : new AbortController().signal);
|
|
473
549
|
})();
|
|
474
550
|
const routerContextValue = {
|
|
475
551
|
locationEntry,
|
|
476
|
-
url: locationEntry?.url ?? null,
|
|
552
|
+
url: locationEntry?.url ?? (ssr ? new URL(ssr.path, "http://localhost") : null),
|
|
477
553
|
isPending,
|
|
478
554
|
navigate,
|
|
479
555
|
navigateAsync,
|
|
@@ -498,7 +574,8 @@ function Router({ routes: inputRoutes, onNavigate, fallback = "none" }) {
|
|
|
498
574
|
locationEntry,
|
|
499
575
|
routes,
|
|
500
576
|
adapter,
|
|
501
|
-
blockerRegistry
|
|
577
|
+
blockerRegistry,
|
|
578
|
+
ssr
|
|
502
579
|
]);
|
|
503
580
|
}
|
|
504
581
|
/**
|
|
@@ -543,7 +620,7 @@ function RouteRenderer({ matchedRoutes, index }) {
|
|
|
543
620
|
url,
|
|
544
621
|
navigateAsync
|
|
545
622
|
]);
|
|
546
|
-
const
|
|
623
|
+
const resetStateSync = useCallback(() => {
|
|
547
624
|
if (locationEntry === null) return;
|
|
548
625
|
const newStates = [...locationEntry.state?.__routeStates ?? []];
|
|
549
626
|
newStates[index] = void 0;
|
|
@@ -553,6 +630,20 @@ function RouteRenderer({ matchedRoutes, index }) {
|
|
|
553
630
|
index,
|
|
554
631
|
updateCurrentEntryState
|
|
555
632
|
]);
|
|
633
|
+
const resetState = useCallback(async () => {
|
|
634
|
+
if (locationEntry === null || url === null) return;
|
|
635
|
+
const newStates = [...locationEntry.state?.__routeStates ?? []];
|
|
636
|
+
newStates[index] = void 0;
|
|
637
|
+
await navigateAsync(url.href, {
|
|
638
|
+
replace: true,
|
|
639
|
+
state: { __routeStates: newStates }
|
|
640
|
+
});
|
|
641
|
+
}, [
|
|
642
|
+
locationEntry?.state,
|
|
643
|
+
index,
|
|
644
|
+
url,
|
|
645
|
+
navigateAsync
|
|
646
|
+
]);
|
|
556
647
|
const outlet = index < matchedRoutes.length - 1 ? /* @__PURE__ */ jsx(RouteRenderer, {
|
|
557
648
|
matchedRoutes,
|
|
558
649
|
index: index + 1
|
|
@@ -584,7 +675,8 @@ function RouteRenderer({ matchedRoutes, index }) {
|
|
|
584
675
|
state: routeState,
|
|
585
676
|
setState,
|
|
586
677
|
setStateSync,
|
|
587
|
-
resetState
|
|
678
|
+
resetState,
|
|
679
|
+
resetStateSync
|
|
588
680
|
};
|
|
589
681
|
const info = locationEntry?.info;
|
|
590
682
|
if (route.loader) return /* @__PURE__ */ jsx(Component, {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#cachedEntryId","#cachedSnapshot","#currentNavigationInfo","#subscribeToDisposeEvents","#subscribedEntryIds","#cachedSnapshot","#idleController","#idleController"],"sources":["../src/context/RouterContext.ts","../src/context/RouteContext.ts","../src/context/BlockerContext.ts","../src/types.ts","../src/core/matchRoutes.ts","../src/core/loaderCache.ts","../src/core/NavigationAPIAdapter.ts","../src/core/StaticAdapter.ts","../src/core/NullAdapter.ts","../src/core/createAdapter.ts","../src/Router.tsx","../src/Outlet.tsx","../src/hooks/useNavigate.ts","../src/hooks/useLocation.ts","../src/hooks/useSearchParams.ts","../src/hooks/useBlocker.ts","../src/hooks/useRouteContext.ts","../src/hooks/useRouteParams.ts","../src/hooks/useRouteState.ts","../src/hooks/useRouteData.ts","../src/hooks/useIsPending.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport type { NavigateOptions } from \"../types.js\";\nimport type { LocationEntry } from \"../core/RouterAdapter.js\";\n\nexport type RouterContextValue = {\n /** Current location entry (null during SSR) */\n locationEntry: LocationEntry | null;\n /** Current URL (null during SSR) */\n url: URL | null;\n /** Whether a navigation transition is pending */\n isPending: boolean;\n /** Navigate to a new URL */\n navigate: (to: string, options?: NavigateOptions) => void;\n /** Navigate to a new URL and wait for completion */\n navigateAsync: (to: string, options?: NavigateOptions) => Promise<void>;\n /** Update current entry's state without navigation */\n updateCurrentEntryState: (state: unknown) => void;\n};\n\nexport const RouterContext = createContext<RouterContextValue | null>(null);\n","import { createContext, type ReactNode } from \"react\";\n\nexport type RouteContextValue = {\n /** Route identifier (if provided in route definition) */\n id: string | undefined;\n /** Matched route parameters extracted from URL */\n params: Record<string, string>;\n /** The matched path pattern */\n matchedPath: string;\n /** Navigation state for this route */\n state: unknown;\n /** Data from loader (if route has loader) */\n data: unknown;\n /** Child route element to render via Outlet */\n outlet: ReactNode;\n /** Parent route context (for nested routes) */\n parent: RouteContextValue | null;\n};\n\nexport const RouteContext = createContext<RouteContextValue | null>(null);\n\n/**\n * Find a route context by ID in the ancestor chain.\n * Returns the matching context or null if not found.\n */\nexport function findRouteContextById(\n context: RouteContextValue | null,\n id: string,\n): RouteContextValue | null {\n let current = context;\n while (current !== null) {\n if (current.id === id) return current;\n current = current.parent;\n }\n return null;\n}\n","import { createContext } from \"react\";\n\nexport type BlockerId = string;\n\nexport type BlockerRegistry = {\n /** Register a blocker, returns unregister function */\n register: (id: BlockerId, shouldBlock: () => boolean) => () => void;\n /** Check all blockers - returns true if any blocks */\n checkAll: () => boolean;\n};\n\nexport type BlockerContextValue = {\n registry: BlockerRegistry;\n};\n\n/**\n * Create a new blocker registry.\n * The registry manages registered blockers and provides a way to check if any blocker is active.\n */\nexport function createBlockerRegistry(): BlockerRegistry {\n const blockers = new Map<BlockerId, () => boolean>();\n\n return {\n register(id: BlockerId, shouldBlock: () => boolean): () => void {\n blockers.set(id, shouldBlock);\n return () => {\n blockers.delete(id);\n };\n },\n\n checkAll(): boolean {\n for (const shouldBlock of blockers.values()) {\n if (shouldBlock()) {\n return true;\n }\n }\n return false;\n },\n };\n}\n\nexport const BlockerContext = createContext<BlockerContextValue | null>(null);\n","import type { ComponentType, ReactNode } from \"react\";\nimport type { LoaderArgs, RouteDefinition } from \"./route.js\";\n\nconst InternalRouteDefinitionSymbol = Symbol();\n\n/**\n * Internal structure for storing per-route state in NavigationHistoryEntry.\n * Each route in the matched stack gets its own state slot indexed by match position.\n */\nexport type InternalRouteState = {\n __routeStates: (unknown | undefined)[];\n};\n\n/**\n * Route definition for the router.\n * When a loader is defined, the component receives the loader result as a `data` prop.\n */\nexport type InternalRouteDefinition = {\n [InternalRouteDefinitionSymbol]: never;\n /** Path pattern to match (e.g., \"users/:id\"). If omitted, the route is pathless (always matches, consumes nothing). */\n path?: string;\n /** Child routes for nested routing */\n children?: InternalRouteDefinition[];\n /**\n * Whether this route requires an exact match.\n * - true: Only matches exact pathname\n * - false: Matches as prefix\n * - undefined: Default (exact for leaf, prefix for parent)\n */\n exact?: boolean;\n /**\n * Whether this route requires a child to match when it has children.\n * - true (default): Parent does not match if no child matches\n * - false: Parent can match alone if it has a component, outlet will be null\n */\n requireChildren?: boolean;\n\n // Note: `loader` and `component` may both exist or both not exist.\n // Also, `unknown`s may actually be more specific types. They are guaranteed\n // to be the same type by the `route` helper function.\n /** Data loader function for this route */\n loader?: (args: LoaderArgs<Record<string, string>>) => unknown;\n /** Component to render when this route matches */\n component?:\n | ComponentType<{\n data?: unknown;\n params?: Record<string, string>;\n state?: unknown;\n setState?: (\n state: unknown | ((prev: unknown) => unknown),\n ) => Promise<void>;\n setStateSync?: (state: unknown | ((prev: unknown) => unknown)) => void;\n resetState?: () => void;\n info?: unknown;\n }>\n | ReactNode;\n};\n\n/**\n * Converts user-defined routes to internal route definitions.\n * This function is used internally by the Router.\n *\n * Actually, this function just performs a type assertion since\n * both RouteDefinition and InternalRouteDefinition have the same runtime shape.\n */\nexport function internalRoutes(\n routes: RouteDefinition[],\n): InternalRouteDefinition[] {\n return routes as InternalRouteDefinition[];\n}\n\n/**\n * A matched route with its parameters.\n */\nexport type MatchedRoute = {\n /** The original route definition */\n route: InternalRouteDefinition;\n /** Extracted path parameters */\n params: Record<string, string>;\n /** The matched pathname segment */\n pathname: string;\n};\n\n/**\n * A matched route with loader data.\n */\nexport type MatchedRouteWithData = MatchedRoute & {\n /** Data returned from the loader (undefined if no loader) */\n data: unknown | undefined;\n};\n\n/**\n * Information passed to onNavigate callback.\n */\nexport type OnNavigateInfo = {\n /** Array of matched routes, or null if no routes matched */\n matches: readonly MatchedRoute[] | null;\n /** Whether the router will intercept this navigation (before user's preventDefault() call) */\n intercepting: boolean;\n};\n\n/**\n * Options for navigation.\n */\nexport type NavigateOptions = {\n /** Replace current history entry instead of pushing */\n replace?: boolean;\n /** State to associate with the navigation */\n state?: unknown;\n /** Ephemeral info for this navigation only (not persisted in history) */\n info?: unknown;\n};\n\n/**\n * Location object representing current URL state.\n */\nexport type Location = {\n pathname: string;\n search: string;\n hash: string;\n};\n\n/**\n * Callback invoked before navigation is intercepted.\n * Call `event.preventDefault()` to prevent the router from handling this navigation.\n *\n * @param event - The NavigateEvent from the Navigation API\n * @param info - Information about the navigation including matched routes and whether it will be intercepted\n */\nexport type OnNavigateCallback = (\n event: NavigateEvent,\n info: OnNavigateInfo,\n) => void;\n\n/**\n * Fallback mode when Navigation API is unavailable.\n *\n * - `\"none\"` (default): Render nothing when Navigation API is unavailable\n * - `\"static\"`: Render matched routes without navigation capabilities (MPA behavior)\n */\nexport type FallbackMode =\n | \"none\" // Default: render nothing when Navigation API unavailable\n | \"static\"; // Render matched routes without navigation capabilities\n","import type { InternalRouteDefinition, MatchedRoute } from \"../types.js\";\n\n/**\n * Match a pathname against a route tree, returning the matched route stack.\n * Returns null if no match is found.\n */\nexport function matchRoutes(\n routes: InternalRouteDefinition[],\n pathname: string | null,\n): MatchedRoute[] | null {\n for (const route of routes) {\n const matched = matchRoute(route, pathname);\n if (matched) {\n return matched;\n }\n }\n return null;\n}\n\n/**\n * Match a single route and its children recursively.\n */\nfunction matchRoute(\n route: InternalRouteDefinition,\n pathname: string | null,\n): MatchedRoute[] | null {\n const hasChildren = Boolean(route.children?.length);\n\n // Handle pathless routes - always match, consume nothing\n if (route.path === undefined) {\n // Pathless routes with loaders can't render during SSR (no request context)\n if (pathname === null && route.loader) {\n return null;\n }\n const result: MatchedRoute = {\n route,\n params: {},\n pathname: \"\",\n };\n\n if (hasChildren) {\n for (const child of route.children!) {\n const childMatch = matchRoute(child, pathname);\n if (childMatch) {\n return [result, ...childMatch];\n }\n }\n // No children matched - only valid if requireChildren is false and route has a component\n if (route.component && route.requireChildren === false) {\n return [result];\n }\n // When pathname is null, pathless route with component matches alone (SSR shell)\n if (pathname === null && route.component) {\n return [result];\n }\n return null;\n }\n\n return [result];\n }\n\n // Path-based routes cannot match when pathname is null\n if (pathname === null) {\n return null;\n }\n\n const isExact = route.exact ?? !hasChildren;\n\n const { matched, params, consumedPathname } = matchPath(\n route.path,\n pathname,\n isExact,\n );\n\n if (!matched) {\n return null;\n }\n\n const result: MatchedRoute = {\n route,\n params,\n pathname: consumedPathname,\n };\n\n // If this route has children, try to match them\n if (hasChildren) {\n // Calculate remaining pathname, ensuring it starts with /\n let remainingPathname = pathname.slice(consumedPathname.length);\n if (!remainingPathname.startsWith(\"/\")) {\n remainingPathname = \"/\" + remainingPathname;\n }\n if (remainingPathname === \"\") {\n remainingPathname = \"/\";\n }\n\n for (const child of route.children!) {\n const childMatch = matchRoute(child, remainingPathname);\n if (childMatch) {\n // Merge params from parent into children\n return [\n result,\n ...childMatch.map((m) => ({\n ...m,\n params: { ...params, ...m.params },\n })),\n ];\n }\n }\n\n // If no children matched - only valid if requireChildren is false and route has a component\n if (route.component && route.requireChildren === false) {\n return [result];\n }\n\n return null;\n }\n\n return [result];\n}\n\n/**\n * Match a path pattern against a pathname.\n */\nfunction matchPath(\n pattern: string,\n pathname: string,\n exact: boolean,\n): {\n matched: boolean;\n params: Record<string, string>;\n consumedPathname: string;\n} {\n // Normalize pattern\n const normalizedPattern = pattern.startsWith(\"/\") ? pattern : `/${pattern}`;\n\n // Build URLPattern\n let urlPatternPath: string;\n if (exact) {\n urlPatternPath = normalizedPattern;\n } else if (normalizedPattern === \"/\") {\n // Special case: root path as prefix matches anything\n urlPatternPath = \"/*\";\n } else {\n // For other prefix matches, add optional wildcard suffix\n urlPatternPath = `${normalizedPattern}{/*}?`;\n }\n\n const urlPattern = new URLPattern({ pathname: urlPatternPath });\n\n const match = urlPattern.exec({ pathname });\n if (!match) {\n return { matched: false, params: {}, consumedPathname: \"\" };\n }\n\n // Extract params (excluding the wildcard group \"0\")\n const params: Record<string, string> = {};\n for (const [key, value] of Object.entries(match.pathname.groups)) {\n if (value !== undefined && key !== \"0\") {\n params[key] = value;\n }\n }\n\n // Calculate consumed pathname\n let consumedPathname: string;\n if (exact) {\n consumedPathname = pathname;\n } else if (normalizedPattern === \"/\") {\n // Root pattern consumes just \"/\"\n consumedPathname = \"/\";\n } else {\n // For prefix matches, calculate based on pattern segments\n const patternSegments = normalizedPattern.split(\"/\").filter(Boolean);\n const pathnameSegments = pathname.split(\"/\").filter(Boolean);\n consumedPathname =\n \"/\" + pathnameSegments.slice(0, patternSegments.length).join(\"/\");\n }\n\n return { matched: true, params, consumedPathname };\n}\n","import type { LoaderArgs } from \"../route.js\";\nimport type {\n MatchedRoute,\n MatchedRouteWithData,\n InternalRouteDefinition,\n} from \"../types.js\";\n\n/**\n * Cache for loader results.\n * Key format: `${entryId}:${matchIndex}`\n */\nconst loaderCache = new Map<string, unknown>();\n\n/**\n * Get or create a loader result from cache.\n * If the result is not cached, executes the loader and caches the result.\n */\nfunction getOrCreateLoaderResult(\n entryId: string,\n matchIndex: number,\n route: InternalRouteDefinition,\n args: LoaderArgs<Record<string, string>>,\n): unknown | undefined {\n if (!route.loader) {\n return undefined;\n }\n\n const cacheKey = `${entryId}:${matchIndex}`;\n\n if (!loaderCache.has(cacheKey)) {\n loaderCache.set(cacheKey, route.loader(args));\n }\n\n return loaderCache.get(cacheKey);\n}\n\n/**\n * Create a Request object for loader args.\n */\nexport function createLoaderRequest(url: URL): Request {\n return new Request(url.href, {\n method: \"GET\",\n });\n}\n\n/**\n * Execute loaders for matched routes and return routes with data.\n * Results are cached by navigation entry id to prevent duplicate execution.\n */\nexport function executeLoaders(\n matchedRoutes: MatchedRoute[],\n entryId: string,\n request: Request,\n signal: AbortSignal,\n): MatchedRouteWithData[] {\n return matchedRoutes.map((match, index) => {\n const { route, params } = match;\n const args: LoaderArgs<Record<string, string>> = {\n params,\n request,\n signal,\n };\n const data = getOrCreateLoaderResult(entryId, index, route, args);\n\n return { ...match, data };\n });\n}\n\n/**\n * Clear the loader cache.\n * Mainly used for testing.\n */\nexport function clearLoaderCache(): void {\n loaderCache.clear();\n}\n\n/**\n * Clear loader cache entries for a specific navigation entry.\n * Called when a NavigationHistoryEntry is disposed (removed from history stack).\n */\nexport function clearLoaderCacheForEntry(entryId: string): void {\n const prefix = `${entryId}:`;\n for (const key of loaderCache.keys()) {\n if (key.startsWith(prefix)) {\n loaderCache.delete(key);\n }\n }\n}\n","import type { RouterAdapter, LocationEntry } from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\nimport { matchRoutes } from \"./matchRoutes.js\";\nimport {\n executeLoaders,\n createLoaderRequest,\n clearLoaderCacheForEntry,\n} from \"./loaderCache.js\";\n\n/**\n * Fallback AbortController for data loading initialized outside of a navigation event.\n * Aborted when the next navigation occurs.\n *\n * To save resources, this controller is created only when needed.\n */\nlet idleController: AbortController | null = null;\n\n/**\n * Reset navigation state. Used for testing.\n */\nexport function resetNavigationState(): void {\n idleController?.abort();\n idleController = null;\n}\n\n/**\n * Adapter that uses the Navigation API for full SPA functionality.\n */\nexport class NavigationAPIAdapter implements RouterAdapter {\n // Cache the snapshot to ensure referential stability for useSyncExternalStore\n #cachedSnapshot: LocationEntry | null = null;\n #cachedEntryId: string | null = null;\n // Ephemeral info from the current navigation event (not persisted in history)\n #currentNavigationInfo: unknown = undefined;\n\n getSnapshot(): LocationEntry | null {\n const entry = navigation.currentEntry;\n if (!entry?.url) {\n return null;\n }\n\n // Return cached snapshot if entry hasn't changed\n if (this.#cachedEntryId === entry.id && this.#cachedSnapshot) {\n return this.#cachedSnapshot;\n }\n\n // Create new snapshot and cache it\n this.#cachedEntryId = entry.id;\n this.#cachedSnapshot = {\n url: new URL(entry.url),\n key: entry.id,\n state: entry.getState(),\n info: this.#currentNavigationInfo,\n };\n return this.#cachedSnapshot;\n }\n\n subscribe(callback: () => void): () => void {\n const controller = new AbortController();\n navigation.addEventListener(\"currententrychange\", callback, {\n signal: controller.signal,\n });\n\n // Subscribe to dispose events on all existing entries\n this.#subscribeToDisposeEvents(controller.signal);\n\n // When current entry changes, subscribe to any new entries' dispose events\n navigation.addEventListener(\n \"currententrychange\",\n () => this.#subscribeToDisposeEvents(controller.signal),\n { signal: controller.signal },\n );\n\n return () => {\n controller.abort();\n };\n }\n\n /**\n * Track which entries we've subscribed to dispose events for.\n */\n #subscribedEntryIds = new Set<string>();\n\n /**\n * Subscribe to dispose events on all navigation entries.\n * When an entry is disposed, its cached loader results are cleared.\n */\n #subscribeToDisposeEvents(signal: AbortSignal): void {\n for (const entry of navigation.entries()) {\n if (this.#subscribedEntryIds.has(entry.id)) {\n continue;\n }\n this.#subscribedEntryIds.add(entry.id);\n\n const entryId = entry.id;\n entry.addEventListener(\n \"dispose\",\n () => {\n clearLoaderCacheForEntry(entryId);\n this.#subscribedEntryIds.delete(entryId);\n },\n { signal },\n );\n }\n }\n\n navigate(to: string, options?: NavigateOptions): void {\n navigation.navigate(to, {\n history: options?.replace ? \"replace\" : \"push\",\n state: options?.state,\n info: options?.info,\n });\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n const result = navigation.navigate(to, {\n history: options?.replace ? \"replace\" : \"push\",\n state: options?.state,\n info: options?.info,\n });\n await result.finished;\n }\n\n setupInterception(\n routes: InternalRouteDefinition[],\n onNavigate?: OnNavigateCallback,\n checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n const handleNavigate = (event: NavigateEvent) => {\n // Capture ephemeral info from the navigate event\n // This info is only available during this navigation and resets on the next one\n this.#currentNavigationInfo = event.info;\n // Invalidate cached snapshot to pick up new info\n this.#cachedSnapshot = null;\n\n // Check blockers first - if any blocker returns true, prevent navigation\n if (checkBlockers?.()) {\n event.preventDefault();\n return;\n }\n\n // Only intercept same-origin navigations\n if (!event.canIntercept) {\n onNavigate?.(event, { matches: [], intercepting: false });\n return;\n }\n\n // Check if the URL matches any of our routes\n const url = new URL(event.destination.url);\n const matched = matchRoutes(routes, url.pathname);\n\n // Compute whether we will intercept this navigation (before user's preventDefault)\n const willIntercept =\n matched !== null && !event.hashChange && event.downloadRequest === null;\n\n // Call onNavigate callback if provided (regardless of route match)\n if (onNavigate) {\n onNavigate(event, { matches: matched, intercepting: willIntercept });\n if (event.defaultPrevented) {\n return; // Do not intercept, allow browser default\n }\n }\n\n if (!willIntercept) {\n return;\n }\n\n // Route match, so intercept\n\n // Abort initial load's loaders if this is the first navigation\n if (idleController) {\n idleController.abort();\n idleController = null;\n }\n\n event.intercept({\n handler: async () => {\n const request = createLoaderRequest(url);\n\n // Note: in response to `currententrychange` event, <Router> should already\n // have dispatched data loaders and the results should be cached.\n // Here we run executeLoader to retrieve cached results.\n const currentEntry = navigation.currentEntry;\n if (!currentEntry) {\n throw new Error(\n \"Navigation currentEntry is null during navigation interception\",\n );\n }\n\n const results = executeLoaders(\n matched,\n currentEntry.id,\n request,\n event.signal,\n );\n\n // Delay navigation until async loaders complete\n await Promise.all(results.map((r) => r.data));\n },\n });\n };\n\n const controller = new AbortController();\n navigation.addEventListener(\"navigate\", handleNavigate, {\n signal: controller.signal,\n });\n return () => {\n controller.abort();\n };\n }\n\n getIdleAbortSignal(): AbortSignal {\n idleController ??= new AbortController();\n return idleController.signal;\n }\n\n updateCurrentEntryState(state: unknown): void {\n // Invalidate cached snapshot BEFORE updating, so the subscriber gets fresh state\n this.#cachedSnapshot = null;\n navigation.updateCurrentEntry({ state });\n // Note: updateCurrentEntry fires currententrychange, so subscribers are notified automatically\n }\n}\n","import type { RouterAdapter, LocationEntry } from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\n\n/**\n * Static adapter for fallback mode when Navigation API is unavailable.\n * Provides read-only location access with no SPA navigation capabilities.\n * Links will cause full page loads (MPA behavior).\n */\nexport class StaticAdapter implements RouterAdapter {\n #cachedSnapshot: LocationEntry | null = null;\n #idleController: AbortController | null = null;\n\n getSnapshot(): LocationEntry | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n // Cache the snapshot - it never changes in static mode\n if (!this.#cachedSnapshot) {\n this.#cachedSnapshot = {\n url: new URL(window.location.href),\n key: \"__static__\",\n state: undefined,\n info: undefined,\n };\n }\n return this.#cachedSnapshot;\n }\n\n subscribe(_callback: () => void): () => void {\n // Static mode never fires location change events\n return () => {};\n }\n\n navigate(to: string, _options?: NavigateOptions): void {\n console.warn(\n \"FUNSTACK Router: navigate() called in static fallback mode. \" +\n \"Navigation API is not available in this browser. \" +\n \"Links will cause full page loads.\",\n );\n // Note: We intentionally do NOT do window.location.href = to\n // as that would mask bugs where developers expect SPA behavior.\n // If needed in the future, we could add a \"static-reload\" mode.\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n this.navigate(to, options);\n }\n\n setupInterception(\n _routes: InternalRouteDefinition[],\n _onNavigate?: OnNavigateCallback,\n _checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n // No interception in static mode - links cause full page loads\n return undefined;\n }\n\n getIdleAbortSignal(): AbortSignal {\n this.#idleController ??= new AbortController();\n return this.#idleController.signal;\n }\n\n updateCurrentEntryState(_state: unknown): void {\n // No-op in static mode - state updates require Navigation API\n }\n}\n","import type { RouterAdapter, LocationEntry } from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\n\n/**\n * Null adapter for when Navigation API is unavailable and no fallback is configured.\n * All methods are no-ops that return safe default values.\n */\nexport class NullAdapter implements RouterAdapter {\n #idleController: AbortController | null = null;\n\n getSnapshot(): LocationEntry | null {\n return null;\n }\n\n subscribe(_callback: () => void): () => void {\n return () => {};\n }\n\n navigate(_to: string, _options?: NavigateOptions): void {\n console.warn(\n \"FUNSTACK Router: navigate() called but no adapter is available. \" +\n \"Navigation API is not available in this browser and no fallback mode is configured.\",\n );\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n this.navigate(to, options);\n }\n\n setupInterception(\n _routes: InternalRouteDefinition[],\n _onNavigate?: OnNavigateCallback,\n _checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n return undefined;\n }\n\n getIdleAbortSignal(): AbortSignal {\n this.#idleController ??= new AbortController();\n return this.#idleController.signal;\n }\n\n updateCurrentEntryState(_state: unknown): void {\n // No-op: NullAdapter doesn't support state updates\n }\n}\n","import type { RouterAdapter } from \"./RouterAdapter.js\";\nimport { NavigationAPIAdapter } from \"./NavigationAPIAdapter.js\";\nimport { StaticAdapter } from \"./StaticAdapter.js\";\nimport { NullAdapter } from \"./NullAdapter.js\";\nimport type { FallbackMode } from \"../types.js\";\n\n/**\n * Check if Navigation API is available.\n */\nfunction hasNavigation(): boolean {\n return typeof window !== \"undefined\" && \"navigation\" in window;\n}\n\n/**\n * Create the appropriate router adapter based on browser capabilities\n * and the specified fallback mode.\n *\n * @param fallback - The fallback mode to use when Navigation API is unavailable\n * @returns A RouterAdapter instance\n */\nexport function createAdapter(fallback: FallbackMode): RouterAdapter {\n // Try Navigation API first\n if (hasNavigation()) {\n return new NavigationAPIAdapter();\n }\n\n // Fall back to static mode if enabled\n if (fallback === \"static\") {\n return new StaticAdapter();\n }\n\n // No adapter available (fallback=\"none\" or default)\n return new NullAdapter();\n}\n","import {\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n useTransition,\n} from \"react\";\nimport type { LocationEntry } from \"./core/RouterAdapter.js\";\nimport { RouterContext } from \"./context/RouterContext.js\";\nimport { RouteContext } from \"./context/RouteContext.js\";\nimport {\n BlockerContext,\n createBlockerRegistry,\n} from \"./context/BlockerContext.js\";\nimport {\n type NavigateOptions,\n type MatchedRouteWithData,\n type OnNavigateCallback,\n type FallbackMode,\n type InternalRouteState,\n internalRoutes,\n} from \"./types.js\";\nimport { matchRoutes } from \"./core/matchRoutes.js\";\nimport { createAdapter } from \"./core/createAdapter.js\";\nimport { executeLoaders, createLoaderRequest } from \"./core/loaderCache.js\";\nimport type { RouteDefinition } from \"./route.js\";\n\nexport type RouterProps = {\n routes: RouteDefinition[];\n /**\n * Callback invoked before navigation is intercepted.\n * Call `event.preventDefault()` to prevent the router from handling this navigation.\n *\n * @param event - The NavigateEvent from the Navigation API\n * @param info - Information about the navigation including matched routes and whether it will be intercepted\n */\n onNavigate?: OnNavigateCallback;\n /**\n * Fallback mode when Navigation API is unavailable.\n *\n * - `\"none\"` (default): Render nothing when Navigation API is unavailable\n * - `\"static\"`: Render matched routes without navigation capabilities (MPA behavior)\n */\n fallback?: FallbackMode;\n};\n\n/**\n * Special value returned as server snapshot during SSR/hydration.\n */\nconst serverSnapshotSymbol = Symbol();\n\nconst noopSubscribe = () => () => {};\nconst getServerSnapshot = (): typeof serverSnapshotSymbol =>\n serverSnapshotSymbol;\n\nexport function Router({\n routes: inputRoutes,\n onNavigate,\n fallback = \"none\",\n}: RouterProps): ReactNode {\n const routes = internalRoutes(inputRoutes);\n\n // Create adapter once based on browser capabilities and fallback setting\n const adapter = useMemo(() => createAdapter(fallback), [fallback]);\n\n // Create blocker registry once\n const [blockerRegistry] = useState(() => createBlockerRegistry());\n\n // Hydration-aware initial value: null during SSR/hydration, real on client-only mount\n const getSnapshot = useCallback(() => adapter.getSnapshot(), [adapter]);\n const initialEntry = useSyncExternalStore<\n LocationEntry | null | typeof serverSnapshotSymbol\n >(noopSubscribe, getSnapshot, getServerSnapshot);\n\n const [isPending, startTransition] = useTransition();\n const [locationEntryInternal, setLocationEntry] = useState<\n LocationEntry | null | typeof serverSnapshotSymbol\n >(initialEntry);\n const locationEntry =\n locationEntryInternal === serverSnapshotSymbol\n ? null\n : locationEntryInternal;\n\n if (\n locationEntryInternal === serverSnapshotSymbol &&\n initialEntry !== serverSnapshotSymbol\n ) {\n // On second hydrated render on client, sync state with real snapshot\n // Rendering flow on hydration:\n // 1. Hydrated Render 1: initialEntry = serverSnapshotSymbol, locationEntryInternal = serverSnapshotSymbol\n // 2. Render 1 is committed\n // 3. Hydrated Render 2: initialEntry = client snapshot, locationEntryInternal = serverSnapshotSymbol\n // 4. This `if` block runs, updating state to client snapshot\n // 5. Hydrated Render 2 (retry): initialEntry = client snapshot, locationEntryInternal = client snapshot\n // 6. Render 2 is committed\n setLocationEntry(initialEntry);\n }\n\n // Subscribe to navigation changes (wrapped in transition)\n useEffect(() => {\n return adapter.subscribe(() => {\n startTransition(() => {\n setLocationEntry(adapter.getSnapshot());\n });\n });\n }, [adapter, startTransition]);\n\n // Set up navigation interception via adapter\n useEffect(() => {\n return adapter.setupInterception(\n routes,\n onNavigate,\n blockerRegistry.checkAll,\n );\n }, [adapter, routes, onNavigate, blockerRegistry]);\n\n // Navigate function from adapter\n const navigate = useCallback(\n (to: string, options?: NavigateOptions) => {\n adapter.navigate(to, options);\n },\n [adapter],\n );\n\n // Navigate function that returns a Promise\n const navigateAsync = useCallback(\n (to: string, options?: NavigateOptions) => {\n return adapter.navigateAsync(to, options);\n },\n [adapter],\n );\n\n // Update current entry's state without navigation\n const updateCurrentEntryState = useCallback(\n (state: unknown) => {\n adapter.updateCurrentEntryState(state);\n },\n [adapter],\n );\n\n return useMemo(() => {\n // Match routes and execute loaders\n const matchedRoutesWithData = (() => {\n if (locationEntry === null) {\n // SSR/hydration: match only pathless routes, skip loaders\n const matched = matchRoutes(routes, null);\n if (!matched) return null;\n return matched.map((m) => ({ ...m, data: undefined }));\n }\n\n const { url, key } = locationEntry;\n const matched = matchRoutes(routes, url.pathname);\n if (!matched) return null;\n\n // Execute loaders (results are cached by location entry key)\n const request = createLoaderRequest(url);\n const signal = adapter.getIdleAbortSignal();\n return executeLoaders(matched, key, request, signal);\n })();\n\n const routerContextValue = {\n locationEntry: locationEntry,\n url: locationEntry?.url ?? null,\n isPending,\n navigate,\n navigateAsync,\n updateCurrentEntryState,\n };\n\n const blockerContextValue = { registry: blockerRegistry };\n\n return (\n <BlockerContext.Provider value={blockerContextValue}>\n <RouterContext.Provider value={routerContextValue}>\n {matchedRoutesWithData ? (\n <RouteRenderer matchedRoutes={matchedRoutesWithData} index={0} />\n ) : null}\n </RouterContext.Provider>\n </BlockerContext.Provider>\n );\n }, [\n navigate,\n navigateAsync,\n updateCurrentEntryState,\n isPending,\n locationEntry,\n routes,\n adapter,\n blockerRegistry,\n ]);\n}\n\ntype RouteRendererProps = {\n matchedRoutes: MatchedRouteWithData[];\n index: number;\n};\n\n/**\n * Recursively render matched routes with proper context.\n */\nfunction RouteRenderer({\n matchedRoutes,\n index,\n}: RouteRendererProps): ReactNode {\n // Get parent route context (null for root route)\n const parentRouteContext = useContext(RouteContext);\n\n const match = matchedRoutes[index];\n if (!match) return null;\n\n const { route, params, pathname, data } = match;\n\n const routerContext = useContext(RouterContext);\n if (!routerContext) {\n throw new Error(\"RouteRenderer must be used within RouterContext\");\n }\n const {\n locationEntry,\n url,\n isPending,\n navigateAsync,\n updateCurrentEntryState,\n } = routerContext;\n\n // Extract this route's state from internal structure\n const internalState = locationEntry?.state as InternalRouteState | undefined;\n const routeState = internalState?.__routeStates?.[index];\n\n // Create stable setStateSync callback for this route's slice (synchronous via updateCurrentEntry)\n const setStateSync = useCallback(\n (stateOrUpdater: unknown | ((prev: unknown) => unknown)) => {\n if (locationEntry === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)\n ?.__routeStates ?? [];\n const currentRouteState = currentStates[index];\n\n const newState =\n typeof stateOrUpdater === \"function\"\n ? (stateOrUpdater as (prev: unknown) => unknown)(currentRouteState)\n : stateOrUpdater;\n\n const newStates = [...currentStates];\n newStates[index] = newState;\n updateCurrentEntryState({ __routeStates: newStates });\n },\n [locationEntry?.state, index, updateCurrentEntryState],\n );\n\n // Create stable setState callback for this route's slice (async via replace navigation)\n const setState = useCallback(\n async (\n stateOrUpdater: unknown | ((prev: unknown) => unknown),\n ): Promise<void> => {\n if (locationEntry === null || url === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)\n ?.__routeStates ?? [];\n const currentRouteState = currentStates[index];\n\n const newState =\n typeof stateOrUpdater === \"function\"\n ? (stateOrUpdater as (prev: unknown) => unknown)(currentRouteState)\n : stateOrUpdater;\n\n const newStates = [...currentStates];\n newStates[index] = newState;\n\n await navigateAsync(url.href, {\n replace: true,\n state: { __routeStates: newStates },\n });\n },\n [locationEntry?.state, index, url, navigateAsync],\n );\n\n // Create stable resetState callback\n const resetState = useCallback(() => {\n if (locationEntry === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)?.__routeStates ??\n [];\n const newStates = [...currentStates];\n newStates[index] = undefined;\n updateCurrentEntryState({ __routeStates: newStates });\n }, [locationEntry?.state, index, updateCurrentEntryState]);\n\n // Create outlet for child routes\n const outlet =\n index < matchedRoutes.length - 1 ? (\n <RouteRenderer matchedRoutes={matchedRoutes} index={index + 1} />\n ) : null;\n\n // Extract id from route definition (if available)\n const routeId = (route as { id?: string }).id;\n\n const routeContextValue = useMemo(\n () => ({\n id: routeId,\n params,\n matchedPath: pathname,\n state: routeState,\n data,\n outlet,\n parent: parentRouteContext,\n }),\n [routeId, params, pathname, routeState, data, outlet, parentRouteContext],\n );\n\n // Render component with or without data prop based on loader presence\n // Always pass params, state, setState, resetState, and info props to components\n const renderComponent = () => {\n const componentOrElement = route.component;\n\n if (componentOrElement == null) return outlet;\n\n // Check if it's a component reference (function) or a ReactNode (JSX element)\n if (typeof componentOrElement !== \"function\") {\n // ReactNode (JSX element, string, number, etc.): render as-is without router props\n return componentOrElement;\n }\n\n // Component reference: inject router props (existing behavior)\n const Component = componentOrElement;\n\n const stateProps = {\n state: routeState,\n setState,\n setStateSync,\n resetState,\n };\n\n // Ephemeral info from the current navigation\n const info = locationEntry?.info;\n\n // When loader exists, data is defined and component expects data prop\n // When loader doesn't exist, data is undefined and component doesn't expect data prop\n // TypeScript can't narrow this union, so we use runtime check with type assertion\n if (route.loader) {\n const ComponentWithData = Component as React.ComponentType<{\n data: unknown;\n params: Record<string, string>;\n state: unknown;\n setState: (s: unknown | ((prev: unknown) => unknown)) => Promise<void>;\n setStateSync: (s: unknown | ((prev: unknown) => unknown)) => void;\n resetState: () => void;\n info: unknown;\n isPending: boolean;\n }>;\n return (\n <ComponentWithData\n data={data}\n params={params}\n {...stateProps}\n info={info}\n isPending={isPending}\n />\n );\n }\n const ComponentWithoutData = Component as React.ComponentType<{\n params: Record<string, string>;\n state: unknown;\n setState: (s: unknown | ((prev: unknown) => unknown)) => Promise<void>;\n setStateSync: (s: unknown | ((prev: unknown) => unknown)) => void;\n resetState: () => void;\n info: unknown;\n isPending: boolean;\n }>;\n return (\n <ComponentWithoutData\n params={params}\n {...stateProps}\n info={info}\n isPending={isPending}\n />\n );\n };\n\n return (\n <RouteContext.Provider value={routeContextValue}>\n {renderComponent()}\n </RouteContext.Provider>\n );\n}\n","import { type ReactNode, useContext } from \"react\";\nimport { RouteContext } from \"./context/RouteContext.js\";\n\n/**\n * Renders the matched child route.\n * Used in layout components to specify where child routes should render.\n */\nexport function Outlet(): ReactNode {\n const routeContext = useContext(RouteContext);\n\n if (!routeContext) {\n return null;\n }\n\n return routeContext.outlet;\n}\n","import { useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\nimport type { NavigateOptions } from \"../types.js\";\n\n/**\n * Returns a function for programmatic navigation.\n */\nexport function useNavigate(): (to: string, options?: NavigateOptions) => void {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useNavigate must be used within a Router\");\n }\n\n return context.navigate;\n}\n","import { useContext, useMemo } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\nimport type { Location } from \"../types.js\";\n\n/**\n * Returns the current location object.\n */\nexport function useLocation(): Location {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useLocation must be used within a Router\");\n }\n\n const { url } = context;\n\n if (url === null) {\n throw new Error(\"useLocation: URL is not available during SSR.\");\n }\n\n return useMemo(() => {\n return {\n pathname: url.pathname,\n search: url.search,\n hash: url.hash,\n };\n }, [url]);\n}\n","import { useCallback, useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\n\ntype SetSearchParams = (\n params:\n | URLSearchParams\n | Record<string, string>\n | ((prev: URLSearchParams) => URLSearchParams | Record<string, string>),\n) => void;\n\n/**\n * Returns and allows manipulation of URL search parameters.\n */\nexport function useSearchParams(): [URLSearchParams, SetSearchParams] {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useSearchParams must be used within a Router\");\n }\n\n if (context.url === null) {\n throw new Error(\"useSearchParams: URL is not available during SSR.\");\n }\n\n const currentUrl = context.url;\n const searchParams = currentUrl.searchParams;\n\n const setSearchParams = useCallback<SetSearchParams>(\n (params) => {\n const url = new URL(currentUrl);\n\n let newParams: URLSearchParams;\n if (typeof params === \"function\") {\n const result = params(new URLSearchParams(url.search));\n newParams =\n result instanceof URLSearchParams\n ? result\n : new URLSearchParams(result);\n } else if (params instanceof URLSearchParams) {\n newParams = params;\n } else {\n newParams = new URLSearchParams(params);\n }\n\n url.search = newParams.toString();\n context.navigate(url.pathname + url.search + url.hash, { replace: true });\n },\n [currentUrl, context.navigate],\n );\n\n return [searchParams, setSearchParams];\n}\n","import { useContext, useEffect, useId } from \"react\";\nimport { BlockerContext } from \"../context/BlockerContext.js\";\n\nexport type UseBlockerOptions = {\n /**\n * Function that returns true if navigation should be blocked.\n * Can call `confirm()` inside to show a confirmation dialog.\n */\n shouldBlock: () => boolean;\n};\n\n/**\n * Hook to block navigation away from the current route.\n *\n * This is useful for scenarios like unsaved form data, ongoing file uploads,\n * or any state that would be lost on navigation.\n *\n * @example\n * ```tsx\n * function EditForm() {\n * const [isDirty, setIsDirty] = useState(false);\n *\n * useBlocker({\n * shouldBlock: () => {\n * if (isDirty) {\n * return !confirm(\"You have unsaved changes. Leave anyway?\");\n * }\n * return false;\n * },\n * });\n *\n * return <form>...</form>;\n * }\n * ```\n *\n * Note: This hook only handles SPA navigations (links, programmatic navigation).\n * For hard navigations (tab close, refresh), handle `beforeunload` separately.\n */\nexport function useBlocker(options: UseBlockerOptions): void {\n const context = useContext(BlockerContext);\n\n if (!context) {\n throw new Error(\"useBlocker must be used within a Router\");\n }\n\n const { shouldBlock } = options;\n const blockerId = useId();\n const { registry } = context;\n\n // Register blocker on mount, unregister on unmount\n // Re-registers when shouldBlock function changes\n useEffect(() => {\n return registry.register(blockerId, shouldBlock);\n }, [blockerId, shouldBlock, registry]);\n}\n","import { useContext } from \"react\";\nimport {\n RouteContext,\n findRouteContextById,\n type RouteContextValue,\n} from \"../context/RouteContext.js\";\n\n/**\n * Internal hook that returns the RouteContextValue for the given route.\n * If the route has an ID, it searches the ancestor chain for a matching route.\n * If no ID is provided, it returns the current (nearest) route context.\n *\n * @param hookName - Name of the calling hook (for error messages)\n * @param routeId - Optional route ID to search for in the ancestor chain\n * @returns The matching RouteContextValue\n * @throws If called outside a route component or if the route ID is not found\n * @internal\n */\nexport function useRouteContext(\n hookName: string,\n routeId: string | undefined,\n): RouteContextValue {\n const context = useContext(RouteContext);\n if (!context) {\n throw new Error(`${hookName} must be used within a route component`);\n }\n\n // If no expected ID, use current context (backwards compatible)\n if (routeId === undefined) {\n return context;\n }\n\n // Look for matching route in ancestor chain\n const matchedContext = findRouteContextById(context, routeId);\n if (!matchedContext) {\n throw new Error(\n `${hookName}: Route ID \"${routeId}\" not found in current route hierarchy. ` +\n `Current route is \"${context.id ?? \"(no id)\"}\"`,\n );\n }\n\n return matchedContext;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteParams,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed route parameters for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * const userRoute = route({\n * id: \"user\",\n * path: \"/users/:userId\",\n * component: UserPage,\n * });\n *\n * function UserPage() {\n * const params = useRouteParams(userRoute);\n * // params is typed as { userId: string }\n * return <div>User ID: {params.userId}</div>;\n * }\n * ```\n */\nexport function useRouteParams<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteParams<T> {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteParams\", routeId);\n return context.params as ExtractRouteParams<T>;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteState,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed navigation state for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * type ScrollState = { scrollPos: number };\n * const scrollRoute = routeState<ScrollState>()({\n * id: \"scroll\",\n * path: \"/scroll\",\n * component: ScrollPage,\n * });\n *\n * function ScrollPage() {\n * const state = useRouteState(scrollRoute);\n * // state is typed as ScrollState | undefined\n * return <div>Scroll position: {state?.scrollPos ?? 0}</div>;\n * }\n * ```\n */\nexport function useRouteState<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteState<T> | undefined {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteState\", routeId);\n return context.state as ExtractRouteState<T> | undefined;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteData,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed loader data for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * const userRoute = route({\n * id: \"user\",\n * path: \"/users/:userId\",\n * loader: async ({ params }) => {\n * const res = await fetch(`/api/users/${params.userId}`);\n * return res.json() as Promise<{ name: string; age: number }>;\n * },\n * component: UserPage,\n * });\n *\n * function UserPage() {\n * const data = useRouteData(userRoute);\n * // data is typed as Promise<{ name: string; age: number }>\n * return <div>User: {data.name}</div>;\n * }\n * ```\n */\nexport function useRouteData<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteData<T> {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteData\", routeId);\n return context.data as ExtractRouteData<T>;\n}\n","import { useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\n\n/**\n * Returns whether a navigation transition is currently pending.\n */\nexport function useIsPending(): boolean {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useIsPending must be used within a Router\");\n }\n\n return context.isPending;\n}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AAC;;;;;;;;;;;;;;;;ACnCxC,SAAgB,gBACd,UACA,SACmB;CACnB,MAAM,UAAU,WAAW,aAAa;AACxC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,GAAG,SAAS,wCAAwC;AAItE,KAAI,YAAY,OACd,QAAO;CAIT,MAAM,iBAAiB,qBAAqB,SAAS,QAAQ;AAC7D,KAAI,CAAC,eACH,OAAM,IAAI,MACR,GAAG,SAAS,cAAc,QAAQ,4DACX,QAAQ,MAAM,UAAU,GAChD;AAGH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;ACfT,SAAgB,eAOd,OAAiC;CACjC,MAAM,UAAW,MAA0B;AAE3C,QADgB,gBAAgB,kBAAkB,QAAQ,CAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;ACTjB,SAAgB,cAOd,OAA4C;CAC5C,MAAM,UAAW,MAA0B;AAE3C,QADgB,gBAAgB,iBAAiB,QAAQ,CAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACPjB,SAAgB,aAOd,OAA+B;CAC/B,MAAM,UAAW,MAA0B;AAE3C,QADgB,gBAAgB,gBAAgB,QAAQ,CACzC;;;;;;;;AClCjB,SAAgB,eAAwB;CACtC,MAAM,UAAU,WAAW,cAAc;AAEzC,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,4CAA4C;AAG9D,QAAO,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#cachedEntryId","#cachedSnapshot","#currentNavigationInfo","#subscribeToDisposeEvents","#subscribedEntryIds","#cachedSnapshot","#idleController","#idleController"],"sources":["../src/context/RouterContext.ts","../src/context/RouteContext.ts","../src/context/BlockerContext.ts","../src/types.ts","../src/core/matchRoutes.ts","../src/core/loaderCache.ts","../src/core/NavigationAPIAdapter.ts","../src/core/StaticAdapter.ts","../src/core/NullAdapter.ts","../src/core/createAdapter.ts","../src/Router.tsx","../src/Outlet.tsx","../src/hooks/useNavigate.ts","../src/hooks/useLocation.ts","../src/hooks/useSearchParams.ts","../src/hooks/useBlocker.ts","../src/hooks/useRouteContext.ts","../src/hooks/useRouteParams.ts","../src/hooks/useRouteState.ts","../src/hooks/useRouteData.ts","../src/hooks/useIsPending.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport type { NavigateOptions } from \"../types.js\";\nimport type { LocationEntry } from \"../core/RouterAdapter.js\";\n\nexport type RouterContextValue = {\n /** Current location entry (null during SSR) */\n locationEntry: LocationEntry | null;\n /** Current URL (null during SSR) */\n url: URL | null;\n /** Whether a navigation transition is pending */\n isPending: boolean;\n /** Navigate to a new URL */\n navigate: (to: string, options?: NavigateOptions) => void;\n /** Navigate to a new URL and wait for completion */\n navigateAsync: (to: string, options?: NavigateOptions) => Promise<void>;\n /** Update current entry's state without navigation */\n updateCurrentEntryState: (state: unknown) => void;\n};\n\nexport const RouterContext = createContext<RouterContextValue | null>(null);\n","import { createContext, type ReactNode } from \"react\";\n\nexport type RouteContextValue = {\n /** Route identifier (if provided in route definition) */\n id: string | undefined;\n /** Matched route parameters extracted from URL */\n params: Record<string, string>;\n /** The matched path pattern */\n matchedPath: string;\n /** Navigation state for this route */\n state: unknown;\n /** Data from loader (if route has loader) */\n data: unknown;\n /** Child route element to render via Outlet */\n outlet: ReactNode;\n /** Parent route context (for nested routes) */\n parent: RouteContextValue | null;\n};\n\nexport const RouteContext = createContext<RouteContextValue | null>(null);\n\n/**\n * Find a route context by ID in the ancestor chain.\n * Returns the matching context or null if not found.\n */\nexport function findRouteContextById(\n context: RouteContextValue | null,\n id: string,\n): RouteContextValue | null {\n let current = context;\n while (current !== null) {\n if (current.id === id) return current;\n current = current.parent;\n }\n return null;\n}\n","import { createContext } from \"react\";\n\nexport type BlockerId = string;\n\nexport type BlockerRegistry = {\n /** Register a blocker, returns unregister function */\n register: (id: BlockerId, shouldBlock: () => boolean) => () => void;\n /** Check all blockers - returns true if any blocks */\n checkAll: () => boolean;\n};\n\nexport type BlockerContextValue = {\n registry: BlockerRegistry;\n};\n\n/**\n * Create a new blocker registry.\n * The registry manages registered blockers and provides a way to check if any blocker is active.\n */\nexport function createBlockerRegistry(): BlockerRegistry {\n const blockers = new Map<BlockerId, () => boolean>();\n\n return {\n register(id: BlockerId, shouldBlock: () => boolean): () => void {\n blockers.set(id, shouldBlock);\n return () => {\n blockers.delete(id);\n };\n },\n\n checkAll(): boolean {\n for (const shouldBlock of blockers.values()) {\n if (shouldBlock()) {\n return true;\n }\n }\n return false;\n },\n };\n}\n\nexport const BlockerContext = createContext<BlockerContextValue | null>(null);\n","import type { ComponentType, ReactNode } from \"react\";\nimport type { ActionArgs, LoaderArgs, RouteDefinition } from \"./route.js\";\n\nconst InternalRouteDefinitionSymbol = Symbol();\n\n/**\n * Internal structure for storing per-route state in NavigationHistoryEntry.\n * Each route in the matched stack gets its own state slot indexed by match position.\n */\nexport type InternalRouteState = {\n __routeStates: (unknown | undefined)[];\n};\n\n/**\n * Route definition for the router.\n * When a loader is defined, the component receives the loader result as a `data` prop.\n */\nexport type InternalRouteDefinition = {\n [InternalRouteDefinitionSymbol]: never;\n /** Path pattern to match (e.g., \"users/:id\"). If omitted, the route is pathless (always matches, consumes nothing). */\n path?: string;\n /** Child routes for nested routing */\n children?: InternalRouteDefinition[];\n /**\n * Whether this route requires an exact match.\n * - true: Only matches exact pathname\n * - false: Matches as prefix\n * - undefined: Default (exact for leaf, prefix for parent)\n */\n exact?: boolean;\n /**\n * Whether this route requires a child to match when it has children.\n * - true (default): Parent does not match if no child matches\n * - false: Parent can match alone if it has a component, outlet will be null\n */\n requireChildren?: boolean;\n\n // Note: `loader` and `component` may both exist or both not exist.\n // Also, `unknown`s may actually be more specific types. They are guaranteed\n // to be the same type by the `route` helper function.\n /** Action function for handling form submissions (POST navigations) */\n action?: (args: ActionArgs<Record<string, string>>) => unknown;\n /** Data loader function for this route */\n loader?: (args: LoaderArgs<Record<string, string>, unknown>) => unknown;\n /** Component to render when this route matches */\n component?:\n | ComponentType<{\n data?: unknown;\n params?: Record<string, string>;\n state?: unknown;\n setState?: (\n state: unknown | ((prev: unknown) => unknown),\n ) => Promise<void>;\n setStateSync?: (state: unknown | ((prev: unknown) => unknown)) => void;\n resetState?: () => Promise<void>;\n resetStateSync?: () => void;\n info?: unknown;\n }>\n | ReactNode;\n};\n\n/**\n * Converts user-defined routes to internal route definitions.\n * This function is used internally by the Router.\n *\n * Actually, this function just performs a type assertion since\n * both RouteDefinition and InternalRouteDefinition have the same runtime shape.\n */\nexport function internalRoutes(\n routes: RouteDefinition[],\n): InternalRouteDefinition[] {\n return routes as InternalRouteDefinition[];\n}\n\n/**\n * A matched route with its parameters.\n */\nexport type MatchedRoute = {\n /** The original route definition */\n route: InternalRouteDefinition;\n /** Extracted path parameters */\n params: Record<string, string>;\n /** The matched pathname segment */\n pathname: string;\n};\n\n/**\n * A matched route with loader data.\n */\nexport type MatchedRouteWithData = MatchedRoute & {\n /** Data returned from the loader (undefined if no loader) */\n data: unknown | undefined;\n};\n\n/**\n * Information passed to onNavigate callback.\n */\nexport type OnNavigateInfo = {\n /** Array of matched routes, or null if no routes matched */\n matches: readonly MatchedRoute[] | null;\n /** Whether the router will intercept this navigation (before user's preventDefault() call) */\n intercepting: boolean;\n /** FormData from the NavigateEvent, or null for non-POST navigations */\n formData: FormData | null;\n};\n\n/**\n * Options for navigation.\n */\nexport type NavigateOptions = {\n /** Replace current history entry instead of pushing */\n replace?: boolean;\n /** State to associate with the navigation */\n state?: unknown;\n /** Ephemeral info for this navigation only (not persisted in history) */\n info?: unknown;\n};\n\n/**\n * Location object representing current URL state.\n */\nexport type Location = {\n pathname: string;\n search: string;\n hash: string;\n};\n\n/**\n * Callback invoked before navigation is intercepted.\n * Call `event.preventDefault()` to prevent the router from handling this navigation.\n *\n * @param event - The NavigateEvent from the Navigation API\n * @param info - Information about the navigation including matched routes and whether it will be intercepted\n */\nexport type OnNavigateCallback = (\n event: NavigateEvent,\n info: OnNavigateInfo,\n) => void;\n\n/**\n * Fallback mode when Navigation API is unavailable.\n *\n * - `\"none\"` (default): Render nothing when Navigation API is unavailable\n * - `\"static\"`: Render matched routes without navigation capabilities (MPA behavior)\n */\nexport type FallbackMode =\n | \"none\" // Default: render nothing when Navigation API unavailable\n | \"static\"; // Render matched routes without navigation capabilities\n","import type { InternalRouteDefinition, MatchedRoute } from \"../types.js\";\n\nconst SKIPPED = Symbol(\"skipped\");\ntype MatchRouteInternalResult = MatchedRoute[] | typeof SKIPPED | null;\n\nexport type MatchRoutesOptions = {\n /**\n * When true, routes with loaders are skipped during matching.\n * Used during SSR where loaders cannot be executed.\n */\n skipLoaders?: boolean;\n};\n\n/**\n * Match a pathname against a route tree, returning the matched route stack.\n * Returns null if no match is found.\n */\nexport function matchRoutes(\n routes: InternalRouteDefinition[],\n pathname: string | null,\n options?: MatchRoutesOptions,\n): MatchedRoute[] | null {\n for (const route of routes) {\n const matched = matchRoute(route, pathname, options);\n if (matched === SKIPPED) return null;\n if (matched) {\n return matched;\n }\n }\n return null;\n}\n\n/**\n * Match a single route and its children recursively.\n */\nfunction matchRoute(\n route: InternalRouteDefinition,\n pathname: string | null,\n options?: MatchRoutesOptions,\n): MatchRouteInternalResult {\n const hasChildren = Boolean(route.children?.length);\n const skipLoaders = options?.skipLoaders ?? false;\n\n // Routes with loaders can't render during SSR (no request context)\n if ((pathname === null || skipLoaders) && route.loader) {\n if (skipLoaders && pathname !== null) {\n // This route can't render (loader skipped), but check if it would match.\n // If it would, return SKIPPED to prevent fallback routes from matching.\n if (route.path === undefined) {\n return SKIPPED; // pathless always matches\n }\n const isExact = route.exact ?? !hasChildren;\n const { matched } = matchPath(route.path, pathname, isExact);\n if (matched) return SKIPPED;\n }\n return null;\n }\n\n // Handle pathless routes - always match, consume nothing\n if (route.path === undefined) {\n const result: MatchedRoute = {\n route,\n params: {},\n pathname: \"\",\n };\n\n if (hasChildren) {\n let anySkipped = false;\n for (const child of route.children!) {\n const childMatch = matchRoute(child, pathname, options);\n if (childMatch === SKIPPED) {\n anySkipped = true;\n break;\n }\n if (childMatch) {\n return [result, ...childMatch];\n }\n }\n if (anySkipped) {\n if (route.component) return [result]; // render as shell\n return SKIPPED; // propagate\n }\n // No children matched - only valid if requireChildren is false and route has a component\n if (route.component && route.requireChildren === false) {\n return [result];\n }\n // During SSR, pathless route with component matches alone (SSR shell)\n if ((pathname === null || skipLoaders) && route.component) {\n return [result];\n }\n return null;\n }\n\n return [result];\n }\n\n // Path-based routes cannot match when pathname is null\n if (pathname === null) {\n return null;\n }\n\n const isExact = route.exact ?? !hasChildren;\n\n const { matched, params, consumedPathname } = matchPath(\n route.path,\n pathname,\n isExact,\n );\n\n if (!matched) {\n return null;\n }\n\n const result: MatchedRoute = {\n route,\n params,\n pathname: consumedPathname,\n };\n\n // If this route has children, try to match them\n if (hasChildren) {\n // Calculate remaining pathname, ensuring it starts with /\n let remainingPathname = pathname.slice(consumedPathname.length);\n if (!remainingPathname.startsWith(\"/\")) {\n remainingPathname = \"/\" + remainingPathname;\n }\n if (remainingPathname === \"\") {\n remainingPathname = \"/\";\n }\n\n let anyChildSkipped = false;\n for (const child of route.children!) {\n const childMatch = matchRoute(child, remainingPathname, options);\n if (childMatch === SKIPPED) {\n anyChildSkipped = true;\n break;\n }\n if (childMatch) {\n // Merge params from parent into children\n return [\n result,\n ...childMatch.map((m) => ({\n ...m,\n params: { ...params, ...m.params },\n })),\n ];\n }\n }\n\n if (anyChildSkipped) {\n if (route.component) return [result]; // render as shell\n return SKIPPED; // propagate\n }\n\n // If no children matched - only valid if requireChildren is false and route has a component\n if (route.component && route.requireChildren === false) {\n return [result];\n }\n\n // During SSR, path-based route with component matches alone (SSR shell)\n if (skipLoaders && route.component) {\n return [result];\n }\n\n return null;\n }\n\n return [result];\n}\n\n/**\n * Match a path pattern against a pathname.\n */\nfunction matchPath(\n pattern: string,\n pathname: string,\n exact: boolean,\n): {\n matched: boolean;\n params: Record<string, string>;\n consumedPathname: string;\n} {\n // Normalize pattern\n const normalizedPattern = pattern.startsWith(\"/\") ? pattern : `/${pattern}`;\n\n // Build URLPattern\n let urlPatternPath: string;\n if (exact) {\n urlPatternPath = normalizedPattern;\n } else if (normalizedPattern === \"/\") {\n // Special case: root path as prefix matches anything\n urlPatternPath = \"/*\";\n } else {\n // For other prefix matches, add optional wildcard suffix\n urlPatternPath = `${normalizedPattern}{/*}?`;\n }\n\n const urlPattern = new URLPattern({ pathname: urlPatternPath });\n\n const match = urlPattern.exec({ pathname });\n if (!match) {\n return { matched: false, params: {}, consumedPathname: \"\" };\n }\n\n // Extract params (excluding the wildcard group \"0\")\n const params: Record<string, string> = {};\n for (const [key, value] of Object.entries(match.pathname.groups)) {\n if (value !== undefined && key !== \"0\") {\n params[key] = value;\n }\n }\n\n // Calculate consumed pathname\n let consumedPathname: string;\n if (exact) {\n consumedPathname = pathname;\n } else if (normalizedPattern === \"/\") {\n // Root pattern consumes just \"/\"\n consumedPathname = \"/\";\n } else {\n // For prefix matches, calculate based on pattern segments\n const patternSegments = normalizedPattern.split(\"/\").filter(Boolean);\n const pathnameSegments = pathname.split(\"/\").filter(Boolean);\n consumedPathname =\n \"/\" + pathnameSegments.slice(0, patternSegments.length).join(\"/\");\n }\n\n return { matched: true, params, consumedPathname };\n}\n","import type { LoaderArgs } from \"../route.js\";\nimport type {\n MatchedRoute,\n MatchedRouteWithData,\n InternalRouteDefinition,\n} from \"../types.js\";\n\n/**\n * Cache for loader results.\n * Key format: `${entryId}:${matchIndex}`\n */\nconst loaderCache = new Map<string, unknown>();\n\n/**\n * Get or create a loader result from cache.\n * If the result is not cached, executes the loader and caches the result.\n */\nfunction getOrCreateLoaderResult(\n entryId: string,\n matchIndex: number,\n route: InternalRouteDefinition,\n args: LoaderArgs<Record<string, string>, unknown>,\n): unknown | undefined {\n if (!route.loader) {\n return undefined;\n }\n\n const cacheKey = `${entryId}:${matchIndex}`;\n\n if (!loaderCache.has(cacheKey)) {\n loaderCache.set(cacheKey, route.loader(args));\n }\n\n return loaderCache.get(cacheKey);\n}\n\n/**\n * Create a Request object for loader args.\n */\nexport function createLoaderRequest(url: URL): Request {\n return new Request(url.href, {\n method: \"GET\",\n });\n}\n\n/**\n * Create a Request object for action args (POST with FormData body).\n */\nexport function createActionRequest(url: URL, formData: FormData): Request {\n return new Request(url.href, {\n method: \"POST\",\n body: formData,\n });\n}\n\n/**\n * Execute loaders for matched routes and return routes with data.\n * Results are cached by navigation entry id to prevent duplicate execution.\n */\nexport function executeLoaders(\n matchedRoutes: MatchedRoute[],\n entryId: string,\n request: Request,\n signal: AbortSignal,\n actionResult?: unknown,\n): MatchedRouteWithData[] {\n return matchedRoutes.map((match, index) => {\n const { route, params } = match;\n const args: LoaderArgs<Record<string, string>, unknown> = {\n params,\n request,\n signal,\n actionResult,\n };\n const data = getOrCreateLoaderResult(entryId, index, route, args);\n\n return { ...match, data };\n });\n}\n\n/**\n * Clear the loader cache.\n * Mainly used for testing.\n */\nexport function clearLoaderCache(): void {\n loaderCache.clear();\n}\n\n/**\n * Clear loader cache entries for a specific navigation entry.\n * Called when a NavigationHistoryEntry is disposed (removed from history stack).\n */\nexport function clearLoaderCacheForEntry(entryId: string): void {\n const prefix = `${entryId}:`;\n for (const key of loaderCache.keys()) {\n if (key.startsWith(prefix)) {\n loaderCache.delete(key);\n }\n }\n}\n","import type {\n RouterAdapter,\n LocationEntry,\n EntryChangeType,\n} from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n MatchedRoute,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\nimport { matchRoutes } from \"./matchRoutes.js\";\nimport {\n executeLoaders,\n createLoaderRequest,\n createActionRequest,\n clearLoaderCacheForEntry,\n} from \"./loaderCache.js\";\n\n/**\n * Fallback AbortController for data loading initialized outside of a navigation event.\n * Aborted when the next navigation occurs.\n *\n * To save resources, this controller is created only when needed.\n */\nlet idleController: AbortController | null = null;\n\n/**\n * Reset navigation state. Used for testing.\n */\nexport function resetNavigationState(): void {\n idleController?.abort();\n idleController = null;\n}\n\n/**\n * Adapter that uses the Navigation API for full SPA functionality.\n */\nexport class NavigationAPIAdapter implements RouterAdapter {\n // Cache the snapshot to ensure referential stability for useSyncExternalStore\n #cachedSnapshot: LocationEntry | null = null;\n #cachedEntryId: string | null = null;\n // Ephemeral info from the current navigation event (not persisted in history)\n #currentNavigationInfo: unknown = undefined;\n\n getSnapshot(): LocationEntry | null {\n const entry = navigation.currentEntry;\n if (!entry?.url) {\n return null;\n }\n\n // Return cached snapshot if entry hasn't changed\n if (this.#cachedEntryId === entry.id && this.#cachedSnapshot) {\n return this.#cachedSnapshot;\n }\n\n // Create new snapshot and cache it\n this.#cachedEntryId = entry.id;\n this.#cachedSnapshot = {\n url: new URL(entry.url),\n key: entry.id,\n state: entry.getState(),\n info: this.#currentNavigationInfo,\n };\n return this.#cachedSnapshot;\n }\n\n subscribe(callback: (changeType: EntryChangeType) => void): () => void {\n const controller = new AbortController();\n navigation.addEventListener(\n \"currententrychange\",\n (event) => {\n // NavigationCurrentEntryChangeEvent.navigationType is null\n // when the change was caused by updateCurrentEntry()\n const changeType: EntryChangeType =\n (event as NavigationCurrentEntryChangeEvent).navigationType === null\n ? \"state\"\n : \"navigation\";\n callback(changeType);\n },\n { signal: controller.signal },\n );\n\n // Subscribe to dispose events on all existing entries\n this.#subscribeToDisposeEvents(controller.signal);\n\n // When current entry changes, subscribe to any new entries' dispose events\n navigation.addEventListener(\n \"currententrychange\",\n () => this.#subscribeToDisposeEvents(controller.signal),\n { signal: controller.signal },\n );\n\n return () => {\n controller.abort();\n };\n }\n\n /**\n * Track which entries we've subscribed to dispose events for.\n */\n #subscribedEntryIds = new Set<string>();\n\n /**\n * Subscribe to dispose events on all navigation entries.\n * When an entry is disposed, its cached loader results are cleared.\n */\n #subscribeToDisposeEvents(signal: AbortSignal): void {\n for (const entry of navigation.entries()) {\n if (this.#subscribedEntryIds.has(entry.id)) {\n continue;\n }\n this.#subscribedEntryIds.add(entry.id);\n\n const entryId = entry.id;\n entry.addEventListener(\n \"dispose\",\n () => {\n clearLoaderCacheForEntry(entryId);\n this.#subscribedEntryIds.delete(entryId);\n },\n { signal },\n );\n }\n }\n\n navigate(to: string, options?: NavigateOptions): void {\n navigation.navigate(to, {\n history: options?.replace ? \"replace\" : \"push\",\n state: options?.state,\n info: options?.info,\n });\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n const result = navigation.navigate(to, {\n history: options?.replace ? \"replace\" : \"push\",\n state: options?.state,\n info: options?.info,\n });\n await result.finished;\n }\n\n setupInterception(\n routes: InternalRouteDefinition[],\n onNavigate?: OnNavigateCallback,\n checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n const handleNavigate = (event: NavigateEvent) => {\n // Capture ephemeral info from the navigate event\n // This info is only available during this navigation and resets on the next one\n this.#currentNavigationInfo = event.info;\n // Invalidate cached snapshot to pick up new info\n this.#cachedSnapshot = null;\n\n // Check blockers first - if any blocker returns true, prevent navigation\n if (checkBlockers?.()) {\n event.preventDefault();\n return;\n }\n\n // Only intercept same-origin navigations\n if (!event.canIntercept) {\n onNavigate?.(event, {\n matches: [],\n intercepting: false,\n formData: event.formData,\n });\n return;\n }\n\n // Check if the URL matches any of our routes\n const url = new URL(event.destination.url);\n const matched = matchRoutes(routes, url.pathname);\n\n const isFormSubmission = event.formData !== null;\n\n // For POST form submissions, don't intercept if no matched route has an action\n if (isFormSubmission && matched !== null) {\n const hasAction = matched.some((m) => m.route.action);\n if (!hasAction) {\n // Don't intercept — let browser submit the form normally\n onNavigate?.(event, {\n matches: matched,\n intercepting: false,\n formData: event.formData,\n });\n return;\n }\n }\n\n // Compute whether we will intercept this navigation (before user's preventDefault)\n const willIntercept =\n matched !== null && !event.hashChange && event.downloadRequest === null;\n\n // Call onNavigate callback if provided (regardless of route match)\n if (onNavigate) {\n onNavigate(event, {\n matches: matched,\n intercepting: willIntercept,\n formData: event.formData,\n });\n if (event.defaultPrevented) {\n return; // Do not intercept, allow browser default\n }\n }\n\n if (!willIntercept) {\n return;\n }\n\n // Route match, so intercept\n\n // Abort initial load's loaders if this is the first navigation\n if (idleController) {\n idleController.abort();\n idleController = null;\n }\n\n event.intercept({\n handler: async () => {\n const currentEntry = navigation.currentEntry;\n if (!currentEntry) {\n throw new Error(\n \"Navigation currentEntry is null during navigation interception\",\n );\n }\n\n let actionResult: unknown = undefined;\n\n if (isFormSubmission) {\n // Find the deepest matched route with an action\n const actionRoute = findActionRoute(matched);\n if (actionRoute) {\n const actionRequest = createActionRequest(url, event.formData!);\n actionResult = await actionRoute.route.action!({\n params: actionRoute.params,\n request: actionRequest,\n signal: event.signal,\n });\n }\n // Revalidate loaders after action — clear cache so loaders re-execute\n clearLoaderCacheForEntry(currentEntry.id);\n }\n\n const request = createLoaderRequest(url);\n\n // Note: in response to `currententrychange` event, <Router> should already\n // have dispatched data loaders and the results should be cached.\n // Here we run executeLoader to retrieve cached results.\n // For form submissions, cache was cleared above so loaders re-execute with actionResult.\n const results = executeLoaders(\n matched,\n currentEntry.id,\n request,\n event.signal,\n actionResult,\n );\n\n // Delay navigation until async loaders complete\n await Promise.all(results.map((r) => r.data));\n },\n });\n };\n\n const controller = new AbortController();\n navigation.addEventListener(\"navigate\", handleNavigate, {\n signal: controller.signal,\n });\n return () => {\n controller.abort();\n };\n }\n\n getIdleAbortSignal(): AbortSignal {\n idleController ??= new AbortController();\n return idleController.signal;\n }\n\n updateCurrentEntryState(state: unknown): void {\n // Invalidate cached snapshot BEFORE updating, so the subscriber gets fresh state\n this.#cachedSnapshot = null;\n navigation.updateCurrentEntry({ state });\n // Note: updateCurrentEntry fires currententrychange, so subscribers are notified automatically\n }\n}\n\n/**\n * Find the deepest matched route that has an action defined.\n * Iterates from deepest to shallowest.\n */\nfunction findActionRoute(matched: MatchedRoute[]): MatchedRoute | undefined {\n for (let i = matched.length - 1; i >= 0; i--) {\n if (matched[i].route.action) {\n return matched[i];\n }\n }\n return undefined;\n}\n","import type {\n RouterAdapter,\n LocationEntry,\n EntryChangeType,\n} from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\n\n/**\n * Static adapter for fallback mode when Navigation API is unavailable.\n * Provides read-only location access with no SPA navigation capabilities.\n * Links will cause full page loads (MPA behavior).\n */\nexport class StaticAdapter implements RouterAdapter {\n #cachedSnapshot: LocationEntry | null = null;\n #idleController: AbortController | null = null;\n\n getSnapshot(): LocationEntry | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n // Cache the snapshot - it never changes in static mode\n if (!this.#cachedSnapshot) {\n this.#cachedSnapshot = {\n url: new URL(window.location.href),\n key: \"__static__\",\n state: undefined,\n info: undefined,\n };\n }\n return this.#cachedSnapshot;\n }\n\n subscribe(_callback: (changeType: EntryChangeType) => void): () => void {\n // Static mode never fires location change events\n return () => {};\n }\n\n navigate(_to: string, _options?: NavigateOptions): void {\n console.warn(\n \"FUNSTACK Router: navigate() called in static fallback mode. \" +\n \"Navigation API is not available in this browser. \" +\n \"Links will cause full page loads.\",\n );\n // Note: We intentionally do NOT do window.location.href = to\n // as that would mask bugs where developers expect SPA behavior.\n // If needed in the future, we could add a \"static-reload\" mode.\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n this.navigate(to, options);\n }\n\n setupInterception(\n _routes: InternalRouteDefinition[],\n _onNavigate?: OnNavigateCallback,\n _checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n // No interception in static mode - links cause full page loads\n return undefined;\n }\n\n getIdleAbortSignal(): AbortSignal {\n this.#idleController ??= new AbortController();\n return this.#idleController.signal;\n }\n\n updateCurrentEntryState(_state: unknown): void {\n // No-op in static mode - state updates require Navigation API\n }\n}\n","import type {\n RouterAdapter,\n LocationEntry,\n EntryChangeType,\n} from \"./RouterAdapter.js\";\nimport type {\n InternalRouteDefinition,\n NavigateOptions,\n OnNavigateCallback,\n} from \"../types.js\";\n\n/**\n * Null adapter for when Navigation API is unavailable and no fallback is configured.\n * All methods are no-ops that return safe default values.\n */\nexport class NullAdapter implements RouterAdapter {\n #idleController: AbortController | null = null;\n\n getSnapshot(): LocationEntry | null {\n return null;\n }\n\n subscribe(_callback: (changeType: EntryChangeType) => void): () => void {\n return () => {};\n }\n\n navigate(_to: string, _options?: NavigateOptions): void {\n console.warn(\n \"FUNSTACK Router: navigate() called but no adapter is available. \" +\n \"Navigation API is not available in this browser and no fallback mode is configured.\",\n );\n }\n\n async navigateAsync(to: string, options?: NavigateOptions): Promise<void> {\n this.navigate(to, options);\n }\n\n setupInterception(\n _routes: InternalRouteDefinition[],\n _onNavigate?: OnNavigateCallback,\n _checkBlockers?: () => boolean,\n ): (() => void) | undefined {\n return undefined;\n }\n\n getIdleAbortSignal(): AbortSignal {\n this.#idleController ??= new AbortController();\n return this.#idleController.signal;\n }\n\n updateCurrentEntryState(_state: unknown): void {\n // No-op: NullAdapter doesn't support state updates\n }\n}\n","import type { RouterAdapter } from \"./RouterAdapter.js\";\nimport { NavigationAPIAdapter } from \"./NavigationAPIAdapter.js\";\nimport { StaticAdapter } from \"./StaticAdapter.js\";\nimport { NullAdapter } from \"./NullAdapter.js\";\nimport type { FallbackMode } from \"../types.js\";\n\n/**\n * Check if Navigation API is available.\n */\nfunction hasNavigation(): boolean {\n return typeof window !== \"undefined\" && \"navigation\" in window;\n}\n\n/**\n * Create the appropriate router adapter based on browser capabilities\n * and the specified fallback mode.\n *\n * @param fallback - The fallback mode to use when Navigation API is unavailable\n * @returns A RouterAdapter instance\n */\nexport function createAdapter(fallback: FallbackMode): RouterAdapter {\n // Try Navigation API first\n if (hasNavigation()) {\n return new NavigationAPIAdapter();\n }\n\n // Fall back to static mode if enabled\n if (fallback === \"static\") {\n return new StaticAdapter();\n }\n\n // No adapter available (fallback=\"none\" or default)\n return new NullAdapter();\n}\n","import {\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n useTransition,\n} from \"react\";\nimport type { LocationEntry } from \"./core/RouterAdapter.js\";\nimport { RouterContext } from \"./context/RouterContext.js\";\nimport { RouteContext } from \"./context/RouteContext.js\";\nimport {\n BlockerContext,\n createBlockerRegistry,\n} from \"./context/BlockerContext.js\";\nimport {\n type NavigateOptions,\n type MatchedRouteWithData,\n type OnNavigateCallback,\n type FallbackMode,\n type InternalRouteState,\n internalRoutes,\n} from \"./types.js\";\nimport { matchRoutes } from \"./core/matchRoutes.js\";\nimport { createAdapter } from \"./core/createAdapter.js\";\nimport { executeLoaders, createLoaderRequest } from \"./core/loaderCache.js\";\nimport type { RouteDefinition } from \"./route.js\";\n\n/**\n * SSR configuration for the router.\n */\nexport type SSRConfig = {\n /**\n * Pathname to use for route matching during SSR.\n *\n * The router uses this pathname to match path-based routes during SSR.\n * Route params are extracted normally.\n */\n path: string;\n /**\n * Whether to run loaders during SSR.\n *\n * - When `false` or omitted, routes with loaders are skipped during SSR\n * and the parent route renders as a shell.\n * - When `true`, routes with loaders are matched and their loaders are\n * executed during SSR. The loader results are passed to components as\n * the `data` prop, so server-rendered HTML includes loader content.\n *\n * @default false\n */\n runLoaders?: boolean;\n};\n\nexport type RouterProps = {\n routes: RouteDefinition[];\n /**\n * Callback invoked before navigation is intercepted.\n * Call `event.preventDefault()` to prevent the router from handling this navigation.\n *\n * @param event - The NavigateEvent from the Navigation API\n * @param info - Information about the navigation including matched routes and whether it will be intercepted\n */\n onNavigate?: OnNavigateCallback;\n /**\n * Fallback mode when Navigation API is unavailable.\n *\n * - `\"none\"` (default): Render nothing when Navigation API is unavailable\n * - `\"static\"`: Render matched routes without navigation capabilities (MPA behavior)\n */\n fallback?: FallbackMode;\n /**\n * SSR configuration for the router.\n *\n * By default (no `ssr` prop), during SSR only pathless routes match.\n * When provided, the router uses the given pathname to match path-based\n * routes during SSR as well.\n *\n * This prop is only used when the location entry is not available (during SSR\n * or hydration). Once the client hydrates, the real URL from the Navigation API\n * takes over.\n *\n * @example\n * ```tsx\n * // SSG: match path-based routes, skip loaders\n * <Router routes={routes} ssr={{ path: \"/about\" }} />\n *\n * // SSR with loaders: match path-based routes including those with loaders\n * <Router routes={routes} ssr={{ path: \"/about\", runLoaders: true }} />\n * ```\n */\n ssr?: SSRConfig;\n};\n\n/**\n * Special value returned as server snapshot during SSR/hydration.\n */\nconst serverSnapshotSymbol = Symbol();\n\nconst noopSubscribe = () => () => {};\nconst getServerSnapshot = (): typeof serverSnapshotSymbol =>\n serverSnapshotSymbol;\n\nexport function Router({\n routes: inputRoutes,\n onNavigate,\n fallback = \"none\",\n ssr,\n}: RouterProps): ReactNode {\n const routes = internalRoutes(inputRoutes);\n\n // Create adapter once based on browser capabilities and fallback setting\n const adapter = useMemo(() => createAdapter(fallback), [fallback]);\n\n // Create blocker registry once\n const [blockerRegistry] = useState(() => createBlockerRegistry());\n\n // Hydration-aware initial value: null during SSR/hydration, real on client-only mount\n const getSnapshot = useCallback(() => adapter.getSnapshot(), [adapter]);\n const initialEntry = useSyncExternalStore<\n LocationEntry | null | typeof serverSnapshotSymbol\n >(noopSubscribe, getSnapshot, getServerSnapshot);\n\n const [isPending, startTransition] = useTransition();\n const [locationEntryInternal, setLocationEntry] = useState<\n LocationEntry | null | typeof serverSnapshotSymbol\n >(initialEntry);\n const locationEntry =\n locationEntryInternal === serverSnapshotSymbol\n ? null\n : locationEntryInternal;\n\n if (\n locationEntryInternal === serverSnapshotSymbol &&\n initialEntry !== serverSnapshotSymbol\n ) {\n // On second hydrated render on client, sync state with real snapshot\n // Rendering flow on hydration:\n // 1. Hydrated Render 1: initialEntry = serverSnapshotSymbol, locationEntryInternal = serverSnapshotSymbol\n // 2. Render 1 is committed\n // 3. Hydrated Render 2: initialEntry = client snapshot, locationEntryInternal = serverSnapshotSymbol\n // 4. This `if` block runs, updating state to client snapshot\n // 5. Hydrated Render 2 (retry): initialEntry = client snapshot, locationEntryInternal = client snapshot\n // 6. Render 2 is committed\n setLocationEntry(initialEntry);\n }\n\n // Subscribe to navigation changes (conditionally wrapped in transition)\n useEffect(() => {\n return adapter.subscribe((changeType) => {\n if (changeType === \"navigation\") {\n startTransition(() => {\n setLocationEntry(adapter.getSnapshot());\n });\n } else {\n // State-only update: apply synchronously, no transition\n setLocationEntry(adapter.getSnapshot());\n }\n });\n }, [adapter, startTransition]);\n\n // Set up navigation interception via adapter\n useEffect(() => {\n return adapter.setupInterception(\n routes,\n onNavigate,\n blockerRegistry.checkAll,\n );\n }, [adapter, routes, onNavigate, blockerRegistry]);\n\n // Navigate function from adapter\n const navigate = useCallback(\n (to: string, options?: NavigateOptions) => {\n adapter.navigate(to, options);\n },\n [adapter],\n );\n\n // Navigate function that returns a Promise\n const navigateAsync = useCallback(\n (to: string, options?: NavigateOptions) => {\n return adapter.navigateAsync(to, options);\n },\n [adapter],\n );\n\n // Update current entry's state without navigation\n const updateCurrentEntryState = useCallback(\n (state: unknown) => {\n adapter.updateCurrentEntryState(state);\n },\n [adapter],\n );\n\n return useMemo(() => {\n // Match routes and execute loaders\n const matchedRoutesWithData = (() => {\n if (locationEntry === null && !ssr?.runLoaders) {\n // SSR/hydration without loader execution: match routes, data is undefined.\n // Routes with loaders are skipped (skipLoaders: true).\n const matched = matchRoutes(routes, ssr?.path ?? null, {\n skipLoaders: true,\n });\n if (!matched) return null;\n return matched.map((m) => ({ ...m, data: undefined }));\n }\n\n // Unified path: SSR with loaders or client-side.\n // Both cases match routes normally and execute loaders.\n const url = locationEntry\n ? locationEntry.url\n : new URL(ssr!.path, \"http://localhost\");\n const matched = matchRoutes(routes, url.pathname);\n if (!matched) return null;\n\n const entryKey = locationEntry?.key ?? \"ssr\";\n const request = createLoaderRequest(url);\n const signal = locationEntry\n ? adapter.getIdleAbortSignal()\n : new AbortController().signal;\n return executeLoaders(matched, entryKey, request, signal);\n })();\n\n const routerContextValue = {\n locationEntry: locationEntry,\n url:\n locationEntry?.url ??\n (ssr ? new URL(ssr.path, \"http://localhost\") : null),\n isPending,\n navigate,\n navigateAsync,\n updateCurrentEntryState,\n };\n\n const blockerContextValue = { registry: blockerRegistry };\n\n return (\n <BlockerContext.Provider value={blockerContextValue}>\n <RouterContext.Provider value={routerContextValue}>\n {matchedRoutesWithData ? (\n <RouteRenderer matchedRoutes={matchedRoutesWithData} index={0} />\n ) : null}\n </RouterContext.Provider>\n </BlockerContext.Provider>\n );\n }, [\n navigate,\n navigateAsync,\n updateCurrentEntryState,\n isPending,\n locationEntry,\n routes,\n adapter,\n blockerRegistry,\n ssr,\n ]);\n}\n\ntype RouteRendererProps = {\n matchedRoutes: MatchedRouteWithData[];\n index: number;\n};\n\n/**\n * Recursively render matched routes with proper context.\n */\nfunction RouteRenderer({\n matchedRoutes,\n index,\n}: RouteRendererProps): ReactNode {\n // Get parent route context (null for root route)\n const parentRouteContext = useContext(RouteContext);\n\n const match = matchedRoutes[index];\n if (!match) return null;\n\n const { route, params, pathname, data } = match;\n\n const routerContext = useContext(RouterContext);\n if (!routerContext) {\n throw new Error(\"RouteRenderer must be used within RouterContext\");\n }\n const {\n locationEntry,\n url,\n isPending,\n navigateAsync,\n updateCurrentEntryState,\n } = routerContext;\n\n // Extract this route's state from internal structure\n const internalState = locationEntry?.state as InternalRouteState | undefined;\n const routeState = internalState?.__routeStates?.[index];\n\n // Create stable setStateSync callback for this route's slice (synchronous via updateCurrentEntry)\n const setStateSync = useCallback(\n (stateOrUpdater: unknown | ((prev: unknown) => unknown)) => {\n if (locationEntry === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)\n ?.__routeStates ?? [];\n const currentRouteState = currentStates[index];\n\n const newState =\n typeof stateOrUpdater === \"function\"\n ? (stateOrUpdater as (prev: unknown) => unknown)(currentRouteState)\n : stateOrUpdater;\n\n const newStates = [...currentStates];\n newStates[index] = newState;\n updateCurrentEntryState({ __routeStates: newStates });\n },\n [locationEntry?.state, index, updateCurrentEntryState],\n );\n\n // Create stable setState callback for this route's slice (async via replace navigation)\n const setState = useCallback(\n async (\n stateOrUpdater: unknown | ((prev: unknown) => unknown),\n ): Promise<void> => {\n if (locationEntry === null || url === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)\n ?.__routeStates ?? [];\n const currentRouteState = currentStates[index];\n\n const newState =\n typeof stateOrUpdater === \"function\"\n ? (stateOrUpdater as (prev: unknown) => unknown)(currentRouteState)\n : stateOrUpdater;\n\n const newStates = [...currentStates];\n newStates[index] = newState;\n\n await navigateAsync(url.href, {\n replace: true,\n state: { __routeStates: newStates },\n });\n },\n [locationEntry?.state, index, url, navigateAsync],\n );\n\n // Create stable resetStateSync callback (synchronous via updateCurrentEntry)\n const resetStateSync = useCallback(() => {\n if (locationEntry === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)?.__routeStates ??\n [];\n const newStates = [...currentStates];\n newStates[index] = undefined;\n updateCurrentEntryState({ __routeStates: newStates });\n }, [locationEntry?.state, index, updateCurrentEntryState]);\n\n // Create stable resetState callback (async via replace navigation)\n const resetState = useCallback(async (): Promise<void> => {\n if (locationEntry === null || url === null) return;\n const currentStates =\n (locationEntry.state as InternalRouteState | undefined)?.__routeStates ??\n [];\n const newStates = [...currentStates];\n newStates[index] = undefined;\n\n await navigateAsync(url.href, {\n replace: true,\n state: { __routeStates: newStates },\n });\n }, [locationEntry?.state, index, url, navigateAsync]);\n\n // Create outlet for child routes\n const outlet =\n index < matchedRoutes.length - 1 ? (\n <RouteRenderer matchedRoutes={matchedRoutes} index={index + 1} />\n ) : null;\n\n // Extract id from route definition (if available)\n const routeId = (route as { id?: string }).id;\n\n const routeContextValue = useMemo(\n () => ({\n id: routeId,\n params,\n matchedPath: pathname,\n state: routeState,\n data,\n outlet,\n parent: parentRouteContext,\n }),\n [routeId, params, pathname, routeState, data, outlet, parentRouteContext],\n );\n\n // Render component with or without data prop based on loader presence\n // Always pass params, state, setState, resetState, and info props to components\n const renderComponent = () => {\n const componentOrElement = route.component;\n\n if (componentOrElement == null) return outlet;\n\n // Check if it's a component reference (function) or a ReactNode (JSX element)\n if (typeof componentOrElement !== \"function\") {\n // ReactNode (JSX element, string, number, etc.): render as-is without router props\n return componentOrElement;\n }\n\n // Component reference: inject router props (existing behavior)\n const Component = componentOrElement;\n\n const stateProps = {\n state: routeState,\n setState,\n setStateSync,\n resetState,\n resetStateSync,\n };\n\n // Ephemeral info from the current navigation\n const info = locationEntry?.info;\n\n // When loader exists, data is defined and component expects data prop\n // When loader doesn't exist, data is undefined and component doesn't expect data prop\n // TypeScript can't narrow this union, so we use runtime check with type assertion\n if (route.loader) {\n const ComponentWithData = Component as React.ComponentType<{\n data: unknown;\n params: Record<string, string>;\n state: unknown;\n setState: (s: unknown | ((prev: unknown) => unknown)) => Promise<void>;\n setStateSync: (s: unknown | ((prev: unknown) => unknown)) => void;\n resetState: () => Promise<void>;\n resetStateSync: () => void;\n info: unknown;\n isPending: boolean;\n }>;\n return (\n <ComponentWithData\n data={data}\n params={params}\n {...stateProps}\n info={info}\n isPending={isPending}\n />\n );\n }\n const ComponentWithoutData = Component as React.ComponentType<{\n params: Record<string, string>;\n state: unknown;\n setState: (s: unknown | ((prev: unknown) => unknown)) => Promise<void>;\n setStateSync: (s: unknown | ((prev: unknown) => unknown)) => void;\n resetState: () => Promise<void>;\n resetStateSync: () => void;\n info: unknown;\n isPending: boolean;\n }>;\n return (\n <ComponentWithoutData\n params={params}\n {...stateProps}\n info={info}\n isPending={isPending}\n />\n );\n };\n\n return (\n <RouteContext.Provider value={routeContextValue}>\n {renderComponent()}\n </RouteContext.Provider>\n );\n}\n","import { type ReactNode, useContext } from \"react\";\nimport { RouteContext } from \"./context/RouteContext.js\";\n\n/**\n * Renders the matched child route.\n * Used in layout components to specify where child routes should render.\n */\nexport function Outlet(): ReactNode {\n const routeContext = useContext(RouteContext);\n\n if (!routeContext) {\n return null;\n }\n\n return routeContext.outlet;\n}\n","import { useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\nimport type { NavigateOptions } from \"../types.js\";\n\n/**\n * Returns a function for programmatic navigation.\n */\nexport function useNavigate(): (to: string, options?: NavigateOptions) => void {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useNavigate must be used within a Router\");\n }\n\n return context.navigate;\n}\n","import { useContext, useMemo } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\nimport type { Location } from \"../types.js\";\n\n/**\n * Returns the current location object.\n */\nexport function useLocation(): Location {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useLocation must be used within a Router\");\n }\n\n const { url } = context;\n\n if (url === null) {\n throw new Error(\"useLocation: URL is not available during SSR.\");\n }\n\n return useMemo(() => {\n return {\n pathname: url.pathname,\n search: url.search,\n hash: url.hash,\n };\n }, [url]);\n}\n","import { useCallback, useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\n\ntype SetSearchParams = (\n params:\n | URLSearchParams\n | Record<string, string>\n | ((prev: URLSearchParams) => URLSearchParams | Record<string, string>),\n) => void;\n\n/**\n * Returns and allows manipulation of URL search parameters.\n */\nexport function useSearchParams(): [URLSearchParams, SetSearchParams] {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useSearchParams must be used within a Router\");\n }\n\n if (context.url === null) {\n throw new Error(\"useSearchParams: URL is not available during SSR.\");\n }\n\n const currentUrl = context.url;\n const searchParams = currentUrl.searchParams;\n\n const setSearchParams = useCallback<SetSearchParams>(\n (params) => {\n const url = new URL(currentUrl);\n\n let newParams: URLSearchParams;\n if (typeof params === \"function\") {\n const result = params(new URLSearchParams(url.search));\n newParams =\n result instanceof URLSearchParams\n ? result\n : new URLSearchParams(result);\n } else if (params instanceof URLSearchParams) {\n newParams = params;\n } else {\n newParams = new URLSearchParams(params);\n }\n\n url.search = newParams.toString();\n context.navigate(url.pathname + url.search + url.hash, { replace: true });\n },\n [currentUrl, context.navigate],\n );\n\n return [searchParams, setSearchParams];\n}\n","import { useContext, useEffect, useId } from \"react\";\nimport { BlockerContext } from \"../context/BlockerContext.js\";\n\nexport type UseBlockerOptions = {\n /**\n * Function that returns true if navigation should be blocked.\n * Can call `confirm()` inside to show a confirmation dialog.\n */\n shouldBlock: () => boolean;\n};\n\n/**\n * Hook to block navigation away from the current route.\n *\n * This is useful for scenarios like unsaved form data, ongoing file uploads,\n * or any state that would be lost on navigation.\n *\n * @example\n * ```tsx\n * function EditForm() {\n * const [isDirty, setIsDirty] = useState(false);\n *\n * useBlocker({\n * shouldBlock: () => {\n * if (isDirty) {\n * return !confirm(\"You have unsaved changes. Leave anyway?\");\n * }\n * return false;\n * },\n * });\n *\n * return <form>...</form>;\n * }\n * ```\n *\n * Note: This hook only handles SPA navigations (links, programmatic navigation).\n * For hard navigations (tab close, refresh), handle `beforeunload` separately.\n */\nexport function useBlocker(options: UseBlockerOptions): void {\n const context = useContext(BlockerContext);\n\n if (!context) {\n throw new Error(\"useBlocker must be used within a Router\");\n }\n\n const { shouldBlock } = options;\n const blockerId = useId();\n const { registry } = context;\n\n // Register blocker on mount, unregister on unmount\n // Re-registers when shouldBlock function changes\n useEffect(() => {\n return registry.register(blockerId, shouldBlock);\n }, [blockerId, shouldBlock, registry]);\n}\n","import { useContext } from \"react\";\nimport {\n RouteContext,\n findRouteContextById,\n type RouteContextValue,\n} from \"../context/RouteContext.js\";\n\n/**\n * Internal hook that returns the RouteContextValue for the given route.\n * If the route has an ID, it searches the ancestor chain for a matching route.\n * If no ID is provided, it returns the current (nearest) route context.\n *\n * @param hookName - Name of the calling hook (for error messages)\n * @param routeId - Optional route ID to search for in the ancestor chain\n * @returns The matching RouteContextValue\n * @throws If called outside a route component or if the route ID is not found\n * @internal\n */\nexport function useRouteContext(\n hookName: string,\n routeId: string | undefined,\n): RouteContextValue {\n const context = useContext(RouteContext);\n if (!context) {\n throw new Error(`${hookName} must be used within a route component`);\n }\n\n // If no expected ID, use current context (backwards compatible)\n if (routeId === undefined) {\n return context;\n }\n\n // Look for matching route in ancestor chain\n const matchedContext = findRouteContextById(context, routeId);\n if (!matchedContext) {\n throw new Error(\n `${hookName}: Route ID \"${routeId}\" not found in current route hierarchy. ` +\n `Current route is \"${context.id ?? \"(no id)\"}\"`,\n );\n }\n\n return matchedContext;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteParams,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed route parameters for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * const userRoute = route({\n * id: \"user\",\n * path: \"/users/:userId\",\n * component: UserPage,\n * });\n *\n * function UserPage() {\n * const params = useRouteParams(userRoute);\n * // params is typed as { userId: string }\n * return <div>User ID: {params.userId}</div>;\n * }\n * ```\n */\nexport function useRouteParams<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteParams<T> {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteParams\", routeId);\n return context.params as ExtractRouteParams<T>;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteState,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed navigation state for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * type ScrollState = { scrollPos: number };\n * const scrollRoute = routeState<ScrollState>()({\n * id: \"scroll\",\n * path: \"/scroll\",\n * component: ScrollPage,\n * });\n *\n * function ScrollPage() {\n * const state = useRouteState(scrollRoute);\n * // state is typed as ScrollState | undefined\n * return <div>Scroll position: {state?.scrollPos ?? 0}</div>;\n * }\n * ```\n */\nexport function useRouteState<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteState<T> | undefined {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteState\", routeId);\n return context.state as ExtractRouteState<T> | undefined;\n}\n","import type {\n TypefulOpaqueRouteDefinition,\n ExtractRouteData,\n} from \"../route.js\";\nimport { useRouteContext } from \"./useRouteContext.js\";\n\n/**\n * Returns typed loader data for the given route definition.\n * Throws an error if called outside a matching route or if the route ID is not found\n * in the current route hierarchy.\n *\n * @example\n * ```typescript\n * const userRoute = route({\n * id: \"user\",\n * path: \"/users/:userId\",\n * loader: async ({ params }) => {\n * const res = await fetch(`/api/users/${params.userId}`);\n * return res.json() as Promise<{ name: string; age: number }>;\n * },\n * component: UserPage,\n * });\n *\n * function UserPage() {\n * const data = useRouteData(userRoute);\n * // data is typed as Promise<{ name: string; age: number }>\n * return <div>User: {data.name}</div>;\n * }\n * ```\n */\nexport function useRouteData<\n T extends TypefulOpaqueRouteDefinition<\n string,\n Record<string, string>,\n unknown,\n unknown\n >,\n>(route: T): ExtractRouteData<T> {\n const routeId = (route as { id?: string }).id;\n const context = useRouteContext(\"useRouteData\", routeId);\n return context.data as ExtractRouteData<T>;\n}\n","import { useContext } from \"react\";\nimport { RouterContext } from \"../context/RouterContext.js\";\n\n/**\n * Returns whether a navigation transition is currently pending.\n */\nexport function useIsPending(): boolean {\n const context = useContext(RouterContext);\n\n if (!context) {\n throw new Error(\"useIsPending must be used within a Router\");\n }\n\n return context.isPending;\n}\n"],"mappings":";;;;;;;AAmBA,MAAa,gBAAgB,cAAyC,KAAK;;;;ACA3E,MAAa,eAAe,cAAwC,KAAK;;;;;AAMzE,SAAgB,qBACd,SACA,IAC0B;CAC1B,IAAI,UAAU;AACd,QAAO,YAAY,MAAM;AACvB,MAAI,QAAQ,OAAO,GAAI,QAAO;AAC9B,YAAU,QAAQ;;AAEpB,QAAO;;;;;;;;;ACfT,SAAgB,wBAAyC;CACvD,MAAM,2BAAW,IAAI,KAA+B;AAEpD,QAAO;EACL,SAAS,IAAe,aAAwC;AAC9D,YAAS,IAAI,IAAI,YAAY;AAC7B,gBAAa;AACX,aAAS,OAAO,GAAG;;;EAIvB,WAAoB;AAClB,QAAK,MAAM,eAAe,SAAS,QAAQ,CACzC,KAAI,aAAa,CACf,QAAO;AAGX,UAAO;;EAEV;;AAGH,MAAa,iBAAiB,cAA0C,KAAK;;;;;;;;;;;AC2B7E,SAAgB,eACd,QAC2B;AAC3B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