@tanstack/router-core 0.0.1-beta.194 → 0.0.1-beta.195
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/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/history.js +88 -15
- package/build/cjs/history.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/utils.js +2 -0
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +90 -15
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +126 -126
- package/build/types/history.d.ts +17 -0
- package/build/types/route.d.ts +21 -21
- package/build/types/routeInfo.d.ts +1 -1
- package/build/types/router.d.ts +3 -3
- package/build/umd/index.development.js +90 -15
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +1 -8
- package/src/history.ts +113 -15
- package/src/route.ts +5 -47
- package/src/routeInfo.ts +1 -3
- package/src/router.ts +0 -3
- package/src/utils.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n InferFullSearchSchema,\n UpdatableRouteOptions,\n Route,\n AnyPathParams,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n} from './route'\nimport { DeepMergeAll, Expand, IsAny } from './utils'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : Replace<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? string\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TLoaderContext extends RouteConstraints['TLoaderContext'] = {},\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never\n ? AnyPathParams\n : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TContext extends RouteConstraints['TAllContext'] = Expand<\n DeepMergeAll<\n [\n IsAny<TParentRoute['types']['context'], {}>,\n TLoaderContext,\n TRouteContext,\n ]\n >\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TContext\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions
|
|
1
|
+
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n InferFullSearchSchema,\n UpdatableRouteOptions,\n Route,\n AnyPathParams,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n} from './route'\nimport { DeepMergeAll, Expand, IsAny } from './utils'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : Replace<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? string\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TLoaderContext extends RouteConstraints['TLoaderContext'] = {},\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never\n ? AnyPathParams\n : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TContext extends RouteConstraints['TAllContext'] = Expand<\n DeepMergeAll<\n [\n IsAny<TParentRoute['types']['context'], {}>,\n TLoaderContext,\n TRouteContext,\n ]\n >\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TContext\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TContext>,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TContext,\n TRouterContext,\n TChildren,\n TRouteTree\n > => {\n const route = new Route(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n"],"names":["FileRoute","constructor","path","createRoute","options","route","Route","isRoot"],"mappings":";;;;;;;;;;;;;;;;AAwEO,MAAMA,SAAS,CAYpB;EACAC,WAAWA,CAAQC,IAAe,EAAE;IAAA,IAAjBA,CAAAA,IAAe,GAAfA,IAAe,CAAA;AAAG,GAAA;EAErCC,WAAW,GA6BTC,OAgByE,IAkBtE;AACH,IAAA,MAAMC,OAAK,GAAG,IAAIC,WAAK,CAACF,OAAc,CAAC,CAAA;IACrCC,OAAK,CAASE,MAAM,GAAG,KAAK,CAAA;AAC9B,IAAA,OAAOF,OAAK,CAAA;GACb,CAAA;AACH;;;;"}
|
package/build/cjs/history.js
CHANGED
|
@@ -77,13 +77,13 @@ function createHistory(opts) {
|
|
|
77
77
|
push: (path, state) => {
|
|
78
78
|
assignKey(state);
|
|
79
79
|
queueTask(() => {
|
|
80
|
-
opts.pushState(path, state);
|
|
80
|
+
opts.pushState(path, state, onUpdate);
|
|
81
81
|
});
|
|
82
82
|
},
|
|
83
83
|
replace: (path, state) => {
|
|
84
84
|
assignKey(state);
|
|
85
85
|
queueTask(() => {
|
|
86
|
-
opts.replaceState(path, state);
|
|
86
|
+
opts.replaceState(path, state, onUpdate);
|
|
87
87
|
});
|
|
88
88
|
},
|
|
89
89
|
go: index => {
|
|
@@ -115,7 +115,8 @@ function createHistory(opts) {
|
|
|
115
115
|
stopBlocking();
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
}
|
|
118
|
+
},
|
|
119
|
+
flush: () => opts.flush?.()
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
function assignKey(state) {
|
|
@@ -128,25 +129,100 @@ function assignKey(state) {
|
|
|
128
129
|
// }
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Creates a history object that can be used to interact with the browser's
|
|
134
|
+
* navigation. This is a lightweight API wrapping the browser's native methods.
|
|
135
|
+
* It is designed to work with TanStack Router, but could be used as a standalone API as well.
|
|
136
|
+
* IMPORTANT: This API implements history throttling via a microtask to prevent
|
|
137
|
+
* excessive calls to the history API. In some browsers, calling history.pushState or
|
|
138
|
+
* history.replaceState in quick succession can cause the browser to ignore subsequent
|
|
139
|
+
* calls. This API smooths out those differences and ensures that your application
|
|
140
|
+
* state will *eventually* match the browser state. In most cases, this is not a problem,
|
|
141
|
+
* but if you need to ensure that the browser state is up to date, you can use the
|
|
142
|
+
* `history.flush` method to immediately flush all pending state changes to the browser URL.
|
|
143
|
+
* @param opts
|
|
144
|
+
* @param opts.getHref A function that returns the current href (path + search + hash)
|
|
145
|
+
* @param opts.createHref A function that takes a path and returns a href (path + search + hash)
|
|
146
|
+
* @returns A history instance
|
|
147
|
+
*/
|
|
131
148
|
function createBrowserHistory(opts) {
|
|
132
149
|
const getHref = opts?.getHref ?? (() => `${window.location.pathname}${window.location.search}${window.location.hash}`);
|
|
133
150
|
const createHref = opts?.createHref ?? (path => path);
|
|
134
|
-
|
|
151
|
+
let currentLocation = parseLocation(getHref(), window.history.state);
|
|
152
|
+
const getLocation = () => currentLocation;
|
|
153
|
+
let next;
|
|
154
|
+
|
|
155
|
+
// Because we are proactively updating the location
|
|
156
|
+
// in memory before actually updating the browser history,
|
|
157
|
+
// we need to track when we are doing this so we don't
|
|
158
|
+
// notify subscribers twice on the last update.
|
|
159
|
+
let tracking = true;
|
|
160
|
+
|
|
161
|
+
// We need to track the current scheduled update to prevent
|
|
162
|
+
// multiple updates from being scheduled at the same time.
|
|
163
|
+
let scheduled;
|
|
164
|
+
|
|
165
|
+
// This function is a wrapper to prevent any of the callback's
|
|
166
|
+
// side effects from causing a subscriber notification
|
|
167
|
+
const untrack = fn => {
|
|
168
|
+
tracking = false;
|
|
169
|
+
fn();
|
|
170
|
+
tracking = true;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// This function flushes the next update to the browser history
|
|
174
|
+
const flush = () => {
|
|
175
|
+
// Do not notify subscribers about this push/replace call
|
|
176
|
+
untrack(() => {
|
|
177
|
+
if (!next) return;
|
|
178
|
+
window.history[next.isPush ? 'pushState' : 'replaceState'](next.state, '', next.href);
|
|
179
|
+
// Reset the nextIsPush flag and clear the scheduled update
|
|
180
|
+
next = undefined;
|
|
181
|
+
scheduled = undefined;
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// This function queues up a call to update the browser history
|
|
186
|
+
const queueHistoryAction = (type, path, state, onUpdate) => {
|
|
187
|
+
const href = createHref(path);
|
|
188
|
+
|
|
189
|
+
// Update the location in memory
|
|
190
|
+
currentLocation = parseLocation(href, state);
|
|
191
|
+
|
|
192
|
+
// Keep track of the next location we need to flush to the URL
|
|
193
|
+
next = {
|
|
194
|
+
href,
|
|
195
|
+
state,
|
|
196
|
+
isPush: next?.isPush || type === 'push'
|
|
197
|
+
};
|
|
198
|
+
// Notify subscribers
|
|
199
|
+
onUpdate();
|
|
200
|
+
if (!scheduled) {
|
|
201
|
+
// Schedule an update to the browser history
|
|
202
|
+
scheduled = Promise.resolve().then(() => flush());
|
|
203
|
+
}
|
|
204
|
+
};
|
|
135
205
|
return createHistory({
|
|
136
206
|
getLocation,
|
|
137
207
|
subscriber: onUpdate => {
|
|
138
|
-
window.addEventListener(pushStateEvent,
|
|
139
|
-
|
|
208
|
+
window.addEventListener(pushStateEvent, () => {
|
|
209
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
210
|
+
onUpdate();
|
|
211
|
+
});
|
|
212
|
+
window.addEventListener(popStateEvent, () => {
|
|
213
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
214
|
+
onUpdate();
|
|
215
|
+
});
|
|
140
216
|
var pushState = window.history.pushState;
|
|
141
217
|
window.history.pushState = function () {
|
|
142
218
|
let res = pushState.apply(history, arguments);
|
|
143
|
-
onUpdate();
|
|
219
|
+
if (tracking) onUpdate();
|
|
144
220
|
return res;
|
|
145
221
|
};
|
|
146
222
|
var replaceState = window.history.replaceState;
|
|
147
223
|
window.history.replaceState = function () {
|
|
148
224
|
let res = replaceState.apply(history, arguments);
|
|
149
|
-
onUpdate();
|
|
225
|
+
if (tracking) onUpdate();
|
|
150
226
|
return res;
|
|
151
227
|
};
|
|
152
228
|
return () => {
|
|
@@ -156,16 +232,13 @@ function createBrowserHistory(opts) {
|
|
|
156
232
|
window.removeEventListener(popStateEvent, onUpdate);
|
|
157
233
|
};
|
|
158
234
|
},
|
|
159
|
-
pushState: (path, state) =>
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
replaceState: (path, state) => {
|
|
163
|
-
window.history.replaceState(state, '', createHref(path));
|
|
164
|
-
},
|
|
235
|
+
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
|
|
236
|
+
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
|
|
165
237
|
back: () => window.history.back(),
|
|
166
238
|
forward: () => window.history.forward(),
|
|
167
239
|
go: n => window.history.go(n),
|
|
168
|
-
createHref: path => createHref(path)
|
|
240
|
+
createHref: path => createHref(path),
|
|
241
|
+
flush
|
|
169
242
|
});
|
|
170
243
|
}
|
|
171
244
|
function createHashHistory() {
|
package/build/cjs/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sources":["../../src/history.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n __tempLocation?: HistoryLocation\n __tempKey?: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n subscriber: false | ((onUpdate: () => void) => () => void)\n pushState: (path: string, state: any) => void\n replaceState: (path: string, state: any) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n}): RouterHistory {\n let location = opts.getLocation()\n let unsub = () => {}\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const tryFlush = () => {\n if (blockers.length) {\n blockers[0]?.(tryFlush, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n if (!opts.subscriber) {\n onUpdate()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryFlush()\n }\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n if (subscribers.size === 0) {\n unsub =\n typeof opts.subscriber === 'function'\n ? opts.subscriber(onUpdate)\n : () => {}\n }\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n if (subscribers.size === 0) {\n unsub()\n }\n }\n },\n push: (path: string, state: any) => {\n assignKey(state)\n queueTask(() => {\n opts.pushState(path, state)\n })\n },\n replace: (path: string, state: any) => {\n assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n }\n}\n\nfunction assignKey(state: HistoryState) {\n state.key = createRandomKey()\n // if (state.__actualLocation) {\n // state.__actualLocation.state = {\n // ...state.__actualLocation.state,\n // key,\n // }\n // }\n}\n\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n const getLocation = () => parseLocation(getHref(), window.history.state)\n\n return createHistory({\n getLocation,\n subscriber: (onUpdate) => {\n window.addEventListener(pushStateEvent, onUpdate)\n window.addEventListener(popStateEvent, onUpdate)\n\n var pushState = window.history.pushState\n window.history.pushState = function () {\n let res = pushState.apply(history, arguments as any)\n onUpdate()\n return res\n }\n var replaceState = window.history.replaceState\n window.history.replaceState = function () {\n let res = replaceState.apply(history, arguments as any)\n onUpdate()\n return res\n }\n\n return () => {\n window.history.pushState = pushState\n window.history.replaceState = replaceState\n window.removeEventListener(pushStateEvent, onUpdate)\n window.removeEventListener(popStateEvent, onUpdate)\n }\n },\n pushState: (path, state) => {\n window.history.pushState(state, '', createHref(path))\n },\n replaceState: (path, state) => {\n window.history.replaceState(state, '', createHref(path))\n },\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n })\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n subscriber: false,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","unsub","subscribers","Set","blockers","queue","tryFlush","length","shift","subscriber","onUpdate","queueTask","task","push","forEach","subscribe","cb","size","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","parseLocation","history","res","apply","arguments","n","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","href","hashIndex","indexOf","searchIndex","slice","undefined","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAiCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAStB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;AACjC,EAAA,IAAIC,KAAK,GAAGA,MAAM,EAAE,CAAA;AACpB,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;EACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;EAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;EAE9B,MAAMC,QAAQ,GAAGA,MAAM;IACrB,IAAIF,QAAQ,CAACG,MAAM,EAAE;AACnBH,MAAAA,QAAQ,CAAC,CAAC,CAAC,GAAGE,QAAQ,EAAE,MAAM;AAC5BF,QAAAA,QAAQ,GAAG,EAAE,CAAA;AACbV,QAAAA,YAAY,EAAE,CAAA;AAChB,OAAC,CAAC,CAAA;AACF,MAAA,OAAA;AACF,KAAA;IAEA,OAAOW,KAAK,CAACE,MAAM,EAAE;AACnBF,MAAAA,KAAK,CAACG,KAAK,EAAE,IAAI,CAAA;A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CAAC,CAAA;AACtD;;;;;;"}
|
|
1
|
+
{"version":3,"file":"history.js","sources":["../../src/history.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n __tempLocation?: HistoryLocation\n __tempKey?: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n subscriber: false | ((onUpdate: () => void) => () => void)\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let unsub = () => {}\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const tryFlush = () => {\n if (blockers.length) {\n blockers[0]?.(tryFlush, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n if (!opts.subscriber) {\n onUpdate()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryFlush()\n }\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n if (subscribers.size === 0) {\n unsub =\n typeof opts.subscriber === 'function'\n ? opts.subscriber(onUpdate)\n : () => {}\n }\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n if (subscribers.size === 0) {\n unsub()\n }\n }\n },\n push: (path: string, state: any) => {\n assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n }\n}\n\nfunction assignKey(state: HistoryState) {\n state.key = createRandomKey()\n // if (state.__actualLocation) {\n // state.__actualLocation.state = {\n // ...state.__actualLocation.state,\n // key,\n // }\n // }\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n return createHistory({\n getLocation,\n subscriber: (onUpdate) => {\n window.addEventListener(pushStateEvent, () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n onUpdate()\n })\n window.addEventListener(popStateEvent, () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n onUpdate()\n })\n\n var pushState = window.history.pushState\n window.history.pushState = function () {\n let res = pushState.apply(history, arguments as any)\n if (tracking) onUpdate()\n return res\n }\n var replaceState = window.history.replaceState\n window.history.replaceState = function () {\n let res = replaceState.apply(history, arguments as any)\n if (tracking) onUpdate()\n return res\n }\n\n return () => {\n window.history.pushState = pushState\n window.history.replaceState = replaceState\n window.removeEventListener(pushStateEvent, onUpdate)\n window.removeEventListener(popStateEvent, onUpdate)\n }\n },\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n })\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n subscriber: false,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","unsub","subscribers","Set","blockers","queue","tryFlush","length","shift","subscriber","onUpdate","queueTask","task","push","forEach","subscribe","cb","size","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","res","apply","arguments","n","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW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["import invariant from 'tiny-invariant'\nimport { RoutePaths } from './routeInfo'\nimport { joinPaths, trimPath } from './path'\nimport { AnyRouter, RouteMatch, AnyRouteMatch } from './router'\nimport {\n DeepMerge,\n DeepMergeAll,\n Expand,\n IsAny,\n NoInfer,\n PickRequired,\n UnionToIntersection,\n} from './utils'\nimport { ParsePathParams, ToSubOptions } from './link'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport type AnyContext = {}\nexport interface RouteMeta {}\nexport interface RouteContext {}\nexport interface RegisterRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // RouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // ErrorRouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterPendingRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // PendingRouteComponent: unknown // This is registered by the framework\n}\n\nexport interface RegisterRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // RouteProps: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // ErrorRouteProps: unknown // This is registered by the framework\n}\n\nexport interface RegisterPendingRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // PendingRouteProps: unknown // This is registered by the framework\n}\n\nexport type RegisteredRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n RouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredErrorRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n ErrorRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredPendingRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n PendingRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n RouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredErrorRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n ErrorRouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredPendingRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TRouteContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n> extends {\n PendingRouteProps: infer T\n}\n ? T\n : {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n> &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\ntype Prefix<T extends string, U extends string> = U extends `${T}${infer _}`\n ? U\n : never\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = {},\n TAllParams = ParamsFallback<TPath, TParams>,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> & {\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema>\n loaderContext?: (opts: { search: TFullSearchSchema }) => TLoaderContext\n} & (keyof PickRequired<RouteContext> extends never\n ? // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n {\n beforeLoad?: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n NoInfer<TLoaderContext>,\n TRouteContext\n >\n }\n : {\n beforeLoad: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n NoInfer<TLoaderContext>,\n TRouteContext\n >\n }) & {\n loader?: LoaderFn<\n TLoader,\n TAllParams,\n NoInfer<TLoaderContext>,\n NoInfer<TAllContext>,\n NoInfer<TRouteContext>\n >\n } & ([TLoader] extends [never]\n ? {\n loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.'\n }\n : {}) &\n (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n )\n\ntype BeforeLoadFn<\n TParentRoute extends AnyRoute,\n TAllParams,\n TLoaderContext,\n TRouteContext,\n> = (opts: {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: Expand<TParentRoute['types']['context'] & TLoaderContext>\n}) => Promise<TRouteContext> | TRouteContext | void\n\nexport type UpdatableRouteOptions<\n TLoader,\n TSearchSchema extends Record<string, any>,\n TFullSearchSchema extends Record<string, any>,\n TAllParams extends AnyPathParams,\n TRouteContext extends Record<string, any>,\n TAllContext extends Record<string, any>,\n> = MetaOptions & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RegisteredRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n // The content to be rendered when the route encounters an error\n errorComponent?: RegisteredErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n > //\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: RegisteredPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // If set, preload matches of this route will be considered fresh for this many milliseconds.\n preloadMaxAge?: number\n // If set, a match of this route will be considered fresh for this many milliseconds.\n maxAge?: number\n // If set, a match of this route that becomes inactive (or unused) will be garbage collected after this many milliseconds\n gcMaxAge?: number\n onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (match: AnyRouteMatch) => void\n onTransition?: (match: AnyRouteMatch) => void\n onLeave?: (match: AnyRouteMatch) => void\n // Set this to true or false to specifically set whether or not this route should be preloaded. If unset, will\n // default to router.options.reloadOnWindowFocus\n reloadOnWindowFocus?: boolean\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn> =\n | SearchSchemaValidatorObj<TReturn>\n | SearchSchemaValidatorFn<TReturn>\n\nexport type SearchSchemaValidatorObj<TReturn> = {\n parse?: SearchSchemaValidatorFn<TReturn>\n}\n\nexport type SearchSchemaValidatorFn<TReturn> = (\n searchObj: Record<string, unknown>,\n) => TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TLoader = unknown,\n TAllParams = {},\n TLoaderContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> = (\n match: LoaderContext<\n TAllParams,\n TLoaderContext,\n TAllContext,\n TRouteContext\n > & {\n parentMatchPromise?: Promise<void>\n },\n) => Promise<TLoader> | TLoader\n\nexport interface LoaderContext<\n TAllParams = {},\n TLoaderContext = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>\n}\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<\n DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>\n>\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeFromFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type UseLoaderResult<T> = T\n// T extends Record<PropertyKey, infer U>\n// ? {\n// [K in keyof T]: UseLoaderResultPromise<T[K]>\n// }\n// : UseLoaderResultPromise<T>\n\n// export type UseLoaderResultPromise<T> = T extends Promise<infer U>\n// ? StreamedPromise<U>\n// : T\n\nexport type StreamedPromise<T> = {\n promise: Promise<T>\n status: 'resolved' | 'pending'\n data: T\n resolve: (value: T) => void\n}\n\nexport type ResolveAllParams<\n TParentRoute extends AnyRoute,\n TParams extends AnyPathParams,\n> = Record<never, string> extends TParentRoute['types']['allParams']\n ? TParams\n : Expand<\n UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}\n >\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TLoaderContext: Record<string, any>\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TLoaderContext extends RouteConstraints['TLoaderContext'] = {},\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<\n TParentRoute,\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends RouteConstraints['TAllContext'] = Expand<\n DeepMergeAll<\n [\n IsAny<TParentRoute['types']['context'], {}>,\n TLoaderContext,\n TRouteContext,\n ]\n >\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n loader: TLoader\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n routeContext: TRouteContext\n context: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n }\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n Route.__onInit(this)\n }\n\n init = (opts: { originalIndex: number; router: AnyRouter }) => {\n this.originalIndex = opts.originalIndex\n this.router = opts.router\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (\n options: UpdatableRouteOptions<\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TAllParams,\n TRouteContext,\n TAllContext\n >,\n ) => {\n Object.assign(this.options, options)\n return this\n }\n\n static __onInit = (route: any) => {\n // This is a dummy static method that should get\n // replaced by a framework specific implementation if necessary\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport class RouterContext<TRouterContext extends {}> {\n constructor() {}\n\n createRootRoute = <\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]> // TAllContext\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ): RootRoute<\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TRouteContext,\n TRouterContext\n > => {\n return new RootRoute(options) as any\n }\n}\n\nexport class RootRoute<\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>, // TAllContext\n TRouterContext, // TRouterContext\n any, // TChildren\n any // TRouteTree\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]> // TAllContext\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToSubOptions<TRouteTree, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n"],"names":["rootRouteId","Route","constructor","options","isRoot","getParentRoute","__onInit","init","opts","originalIndex","router","path","id","parentRoute","invariant","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","route","RouterContext","createRootRoute","RootRoute","createRouteMask"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeO,MAAMA,WAAW,GAAG,WAAmB;;AAyX9C;;AAgGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AAqCO,MAAMC,KAAK,CAwChB;AAkCA;;AAGA;;AAKA;;EAMAC,WAAWA,CACTC,OAoBG,EACH;AACA,IAAA,IAAI,CAACA,OAAO,GAAIA,OAAO,IAAY,EAAE,CAAA;AACrC,IAAA,IAAI,CAACC,MAAM,GAAG,CAACD,OAAO,EAAEE,cAAqB,CAAA;AAC7CJ,IAAAA,KAAK,CAACK,QAAQ,CAAC,IAAI,CAAC,CAAA;AACtB,GAAA;EAEAC,IAAI,GAAIC,IAAkD,IAAK;AAC7D,IAAA,IAAI,CAACC,aAAa,GAAGD,IAAI,CAACC,aAAa,CAAA;AACvC,IAAA,IAAI,CAACC,MAAM,GAAGF,IAAI,CAACE,MAAM,CAAA;AAEzB,IAAA,MAAMP,OAAO,GAAG,IAAI,CAACA,OAa2B,CAAA;IAEhD,MAAMC,M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,CAACC,EAAE,GAAGA,EAAS,CAAA;AACnB;IACA,IAAI,CAACM,QAAQ,GAAGA,QAAqB,CAAA;IACrC,IAAI,CAACC,EAAE,GAAGD,QAAoC,CAAA;GAC/C,CAAA;EAEDE,WAAW,GACTC,QAAsB,IAkBnB;IACH,IAAI,CAACA,QAAQ,GAAGA,QAAe,CAAA;AAC/B,IAAA,OAAO,IAAI,CAAA;GACZ,CAAA;EAEDC,MAAM,GACJnB,OAOC,IACE;IACHoB,MAAM,CAACC,MAAM,CAAC,IAAI,CAACrB,OAAO,EAAEA,OAAO,CAAC,CAAA;AACpC,IAAA,OAAO,IAAI,CAAA;GACZ,CAAA;EAED,OAAOG,QAAQ,GAAImB,KAAU,IAAK;AAChC;AACA;GACD,CAAA;AACH,CAAA;AAIO,MAAMC,aAAa,CAA4B;EACpDxB,WAAWA,GAAG,EAAC;EAEfyB,eAAe,GAMbxB,OAoBC,IAOE;AACH,IAAA,OAAO,IAAIyB,SAAS,CAACzB,OAAO,CAAC,CAAA;GAC9B,CAAA;AACH,CAAA;AAEO,MAAMyB,SAAS,SAMZ3B,KAAK,CAiBb;EACAC,WAAWA,CACTC,OAoBC,EACD;IACA,KAAK,CAACA,OAAc,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAkDO,SAAS0B,eAAeA,CAK7BrB,IAEwC,EACjB;AACvB,EAAA,OAAOA,IAAI,CAAA;AACb;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { RoutePaths } from './routeInfo'\nimport { joinPaths, trimPath } from './path'\nimport { AnyRouter, RouteMatch, AnyRouteMatch } from './router'\nimport {\n DeepMerge,\n DeepMergeAll,\n Expand,\n IsAny,\n NoInfer,\n PickRequired,\n UnionToIntersection,\n} from './utils'\nimport { ParsePathParams, ToSubOptions } from './link'\n\nexport const rootRouteId = '__root__' as const\nexport type RootRouteId = typeof rootRouteId\nexport type AnyPathParams = {}\nexport type AnySearchSchema = {}\nexport type AnyContext = {}\nexport interface RouteMeta {}\nexport interface RouteContext {}\nexport interface RegisterRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // RouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // ErrorRouteComponent: unknown // This is registered by the framework\n}\nexport interface RegisterPendingRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // PendingRouteComponent: unknown // This is registered by the framework\n}\n\nexport interface RegisterRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // RouteProps: unknown // This is registered by the framework\n}\nexport interface RegisterErrorRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // ErrorRouteProps: unknown // This is registered by the framework\n}\n\nexport interface RegisterPendingRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> {\n // PendingRouteProps: unknown // This is registered by the framework\n}\n\nexport type RegisteredRouteComponent<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TAllContext\n> extends {\n RouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredErrorRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TAllContext\n> extends {\n ErrorRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredPendingRouteComponent<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TAllContext\n> extends {\n PendingRouteComponent: infer T\n}\n ? T\n : () => unknown\n\nexport type RegisteredRouteProps<\n TLoader = unknown,\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TAllContext\n> extends {\n RouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredErrorRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<TFullSearchSchema, TAllParams, TAllContext> extends {\n ErrorRouteProps: infer T\n}\n ? T\n : {}\n\nexport type RegisteredPendingRouteProps<\n TFullSearchSchema extends Record<string, any> = AnySearchSchema,\n TAllParams extends AnyPathParams = AnyPathParams,\n TAllContext extends Record<string, any> = AnyContext,\n> = RegisterRouteProps<TFullSearchSchema, TAllParams, TAllContext> extends {\n PendingRouteProps: infer T\n}\n ? T\n : {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> =\n UnionToIntersection<RoutePathOptions<TCustomId, TPath>>\n\nexport type MetaOptions = keyof PickRequired<RouteMeta> extends never\n ? {\n meta?: RouteMeta\n }\n : {\n meta: RouteMeta\n }\n\nexport type AnyRouteProps = RegisteredRouteProps<any, any, any, any>\n\nexport type RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = AnyPathParams,\n TAllParams extends AnyPathParams = TParams,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n> &\n UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>\n\nexport type ParamsFallback<\n TPath extends string,\n TParams,\n> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams\n\ntype Prefix<T extends string, U extends string> = U extends `${T}${infer _}`\n ? U\n : never\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TFullSearchSchema extends Record<string, any> = TSearchSchema,\n TParams extends AnyPathParams = {},\n TAllParams = ParamsFallback<TPath, TParams>,\n TRouteContext extends RouteContext = RouteContext,\n TAllContext extends Record<string, any> = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> & {\n getParentRoute: () => TParentRoute\n validateSearch?: SearchSchemaValidator<TSearchSchema>\n loaderContext?: (opts: { search: TFullSearchSchema }) => TLoaderContext\n} & (keyof PickRequired<RouteContext> extends never\n ? // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n {\n beforeLoad?: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n NoInfer<TLoaderContext>,\n TRouteContext\n >\n }\n : {\n beforeLoad: BeforeLoadFn<\n TParentRoute,\n TAllParams,\n NoInfer<TLoaderContext>,\n TRouteContext\n >\n }) & {\n loader?: LoaderFn<\n TLoader,\n TAllParams,\n NoInfer<TLoaderContext>,\n NoInfer<TAllContext>,\n NoInfer<TRouteContext>\n >\n } & ([TLoader] extends [never]\n ? {\n loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.'\n }\n : {}) &\n (\n | {\n // Both or none\n parseParams?: (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n ) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n stringifyParams?: (\n params: NoInfer<ParamsFallback<TPath, TParams>>,\n ) => Record<ParsePathParams<TPath>, string>\n }\n | {\n stringifyParams?: never\n parseParams?: never\n }\n )\n\ntype BeforeLoadFn<\n TParentRoute extends AnyRoute,\n TAllParams,\n TLoaderContext,\n TRouteContext,\n> = (opts: {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: Expand<TParentRoute['types']['context'] & TLoaderContext>\n}) => Promise<TRouteContext> | TRouteContext | void\n\nexport type UpdatableRouteOptions<\n TLoader,\n TFullSearchSchema extends Record<string, any>,\n TAllParams extends AnyPathParams,\n TAllContext extends Record<string, any>,\n> = MetaOptions & {\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RegisteredRouteComponent<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TAllContext\n >\n // The content to be rendered when the route encounters an error\n errorComponent?: RegisteredErrorRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TAllContext\n > //\n // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render\n pendingComponent?: RegisteredPendingRouteComponent<\n TFullSearchSchema,\n TAllParams,\n TAllContext\n >\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: SearchFilter<TFullSearchSchema>[]\n // If set, preload matches of this route will be considered fresh for this many milliseconds.\n preloadMaxAge?: number\n // If set, a match of this route will be considered fresh for this many milliseconds.\n maxAge?: number\n // If set, a match of this route that becomes inactive (or unused) will be garbage collected after this many milliseconds\n gcMaxAge?: number\n onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (match: AnyRouteMatch) => void\n onTransition?: (match: AnyRouteMatch) => void\n onLeave?: (match: AnyRouteMatch) => void\n // Set this to true or false to specifically set whether or not this route should be preloaded. If unset, will\n // default to router.options.reloadOnWindowFocus\n reloadOnWindowFocus?: boolean\n}\n\nexport type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<\n TPath,\n TParams\n>\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : 'parseParams must return an object'\n\nexport type ParseParamsObj<TPath extends string, TParams> = {\n parse?: ParseParamsFn<TPath, TParams>\n}\n\n// The parse type here allows a zod schema to be passed directly to the validator\nexport type SearchSchemaValidator<TReturn> =\n | SearchSchemaValidatorObj<TReturn>\n | SearchSchemaValidatorFn<TReturn>\n\nexport type SearchSchemaValidatorObj<TReturn> = {\n parse?: SearchSchemaValidatorFn<TReturn>\n}\n\nexport type SearchSchemaValidatorFn<TReturn> = (\n searchObj: Record<string, unknown>,\n) => TReturn\n\nexport type DefinedPathParamWarning =\n 'Path params cannot be redefined by child routes!'\n\nexport type ParentParams<TParentParams> = AnyPathParams extends TParentParams\n ? {}\n : {\n [Key in keyof TParentParams]?: DefinedPathParamWarning\n }\n\nexport type LoaderFn<\n TLoader = unknown,\n TAllParams = {},\n TLoaderContext extends Record<string, any> = AnyContext,\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> = (\n match: LoaderContext<\n TAllParams,\n TLoaderContext,\n TAllContext,\n TRouteContext\n > & {\n parentMatchPromise?: Promise<void>\n },\n) => Promise<TLoader> | TLoader\n\nexport interface LoaderContext<\n TAllParams = {},\n TLoaderContext = {},\n TAllContext extends Record<string, any> = AnyContext,\n TRouteContext extends Record<string, any> = AnyContext,\n> {\n abortController: AbortController\n preload: boolean\n params: TAllParams\n context: Expand<DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>>\n}\n\nexport type SearchFilter<T, U = T> = (prev: T) => U\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<\n DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>\n>\n\nexport interface AnyRoute\n extends Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > {}\n\nexport type MergeFromFromParent<T, U> = IsAny<T, U, T & U>\n\nexport type UseLoaderResult<T> = T\n// T extends Record<PropertyKey, infer U>\n// ? {\n// [K in keyof T]: UseLoaderResultPromise<T[K]>\n// }\n// : UseLoaderResultPromise<T>\n\n// export type UseLoaderResultPromise<T> = T extends Promise<infer U>\n// ? StreamedPromise<U>\n// : T\n\nexport type StreamedPromise<T> = {\n promise: Promise<T>\n status: 'resolved' | 'pending'\n data: T\n resolve: (value: T) => void\n}\n\nexport type ResolveAllParams<\n TParentRoute extends AnyRoute,\n TParams extends AnyPathParams,\n> = Record<never, string> extends TParentRoute['types']['allParams']\n ? TParams\n : Expand<\n UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}\n >\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TLoaderContext: Record<string, any>\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport class Route<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TLoaderContext extends RouteConstraints['TLoaderContext'] = {},\n TLoader = unknown,\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<\n TParentRoute,\n TParams\n >,\n TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,\n TAllContext extends RouteConstraints['TAllContext'] = Expand<\n DeepMergeAll<\n [\n IsAny<TParentRoute['types']['context'], {}>,\n TLoaderContext,\n TRouteContext,\n ]\n >\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n> {\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n loader: TLoader\n searchSchema: TSearchSchema\n fullSearchSchema: TFullSearchSchema\n params: TParams\n allParams: TAllParams\n routeContext: TRouteContext\n context: TAllContext\n children: TChildren\n routeTree: TRouteTree\n routerContext: TRouterContext\n }\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n\n constructor(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n > &\n UpdatableRouteOptions<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TAllContext\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n Route.__onInit(this)\n }\n\n init = (opts: { originalIndex: number; router: AnyRouter }) => {\n this.originalIndex = opts.originalIndex\n this.router = opts.router\n\n const options = this.options as RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPath(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n (this.parentRoute.id as any) === rootRouteId\n ? ''\n : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this.path = path as TPath\n this.id = id as TId\n // this.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren = <TNewChildren extends AnyRoute[]>(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TNewChildren,\n TRouteTree\n > => {\n this.children = children as any\n return this as any\n }\n\n update = (\n options: UpdatableRouteOptions<\n TLoader,\n TFullSearchSchema,\n TAllParams,\n TAllContext\n >,\n ) => {\n Object.assign(this.options, options)\n return this\n }\n\n static __onInit = (route: any) => {\n // This is a dummy static method that should get\n // replaced by a framework specific implementation if necessary\n }\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any>\n\nexport class RouterContext<TRouterContext extends {}> {\n constructor() {}\n\n createRootRoute = <\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n >(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]> // TAllContext\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ): RootRoute<\n TLoaderContext,\n TLoader,\n TSearchSchema,\n TRouteContext,\n TRouterContext\n > => {\n return new RootRoute(options) as any\n }\n}\n\nexport class RootRoute<\n TLoaderContext extends Record<string, any> = AnyContext,\n TLoader = unknown,\n TSearchSchema extends Record<string, any> = {},\n TRouteContext extends RouteContext = RouteContext,\n TRouterContext extends {} = {},\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>, // TAllContext\n TRouterContext, // TRouterContext\n any, // TChildren\n any // TRouteTree\n> {\n constructor(\n options?: Omit<\n RouteOptions<\n AnyRoute, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TLoaderContext, // TLoaderContext\n TLoader, // TLoader\n TSearchSchema, // TSearchSchema\n TSearchSchema, // TFullSearchSchema\n {}, // TParams\n {}, // TAllParams\n TRouteContext, // TRouteContext\n DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]> // TAllContext\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n >,\n ) {\n super(options as any)\n }\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToSubOptions<TRouteTree, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n"],"names":["rootRouteId","Route","constructor","options","isRoot","getParentRoute","__onInit","init","opts","originalIndex","router","path","id","parentRoute","invariant","trimPath","customId","joinPaths","fullPath","to","addChildren","children","update","Object","assign","route","RouterContext","createRootRoute","RootRoute","createRouteMask"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeO,MAAMA,WAAW,GAAG,WAAmB;;AAmV9C;;AAgGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AAqCO,MAAMC,KAAK,CAwChB;AAkCA;;AAGA;;AAKA;;EAMAC,WAAWA,CACTC,OAkBG,EACH;AACA,IAAA,IAAI,CAACA,OAAO,GAAIA,OAAO,IAAY,EAAE,CAAA;AACrC,IAAA,IAAI,CAAC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