@tanstack/router-core 0.0.1-alpha.0 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +33 -0
  2. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +1 -0
  3. package/build/cjs/node_modules/history/index.js +815 -0
  4. package/build/cjs/node_modules/history/index.js.map +1 -0
  5. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +30 -0
  6. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +1 -0
  7. package/build/cjs/packages/router-core/src/index.js +35 -1421
  8. package/build/cjs/packages/router-core/src/index.js.map +1 -1
  9. package/build/cjs/packages/router-core/src/path.js +222 -0
  10. package/build/cjs/packages/router-core/src/path.js.map +1 -0
  11. package/build/cjs/packages/router-core/src/qss.js +1 -1
  12. package/build/cjs/packages/router-core/src/qss.js.map +1 -1
  13. package/build/cjs/packages/router-core/src/route.js +126 -0
  14. package/build/cjs/packages/router-core/src/route.js.map +1 -0
  15. package/build/cjs/packages/router-core/src/routeConfig.js +69 -0
  16. package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -0
  17. package/build/cjs/packages/router-core/src/routeMatch.js +247 -0
  18. package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -0
  19. package/build/cjs/packages/router-core/src/router.js +809 -0
  20. package/build/cjs/packages/router-core/src/router.js.map +1 -0
  21. package/build/cjs/packages/router-core/src/searchParams.js +70 -0
  22. package/build/cjs/packages/router-core/src/searchParams.js.map +1 -0
  23. package/build/cjs/packages/router-core/src/utils.js +118 -0
  24. package/build/cjs/packages/router-core/src/utils.js.map +1 -0
  25. package/build/esm/index.js +1350 -1231
  26. package/build/esm/index.js.map +1 -1
  27. package/build/stats-html.html +1 -1
  28. package/build/stats-react.json +388 -46
  29. package/build/types/index.d.ts +401 -343
  30. package/build/umd/index.development.js +1218 -1091
  31. package/build/umd/index.development.js.map +1 -1
  32. package/build/umd/index.production.js +1 -1
  33. package/build/umd/index.production.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/frameworks.ts +13 -0
  36. package/src/index.ts +15 -2969
  37. package/src/link.ts +291 -0
  38. package/src/path.ts +236 -0
  39. package/src/qss.ts +1 -1
  40. package/src/route.ts +181 -0
  41. package/src/routeConfig.ts +523 -0
  42. package/src/routeInfo.ts +228 -0
  43. package/src/routeMatch.ts +340 -0
  44. package/src/router.ts +1211 -0
  45. package/src/searchParams.ts +54 -0
  46. package/src/utils.ts +157 -0
  47. package/build/cjs/packages/location-core/src/index.js +0 -1313
  48. package/build/cjs/packages/location-core/src/index.js.map +0 -1
  49. package/build/cjs/packages/location-core/src/qss.js +0 -70
  50. package/build/cjs/packages/location-core/src/qss.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/createRoutes.js +0 -106
  52. package/build/cjs/packages/router-core/src/createRoutes.js.map +0 -1
  53. package/build/cjs/packages/router-core/src/createRoutes.test.js +0 -160
  54. package/build/cjs/packages/router-core/src/createRoutes.test.js.map +0 -1
  55. package/build/types/createRoutes.d.ts +0 -10
  56. package/build/types/createRoutes.test.d.ts +0 -1
  57. package/build/types/qss.d.ts +0 -2
  58. package/build/types/react-router/src/createRoutes.test.d.ts +0 -0
  59. package/build/types/react-router/src/index.d.ts +0 -59
  60. package/build/types/router-core/src/createRoutes.test.d.ts +0 -1
  61. package/build/types/router-core/src/index.d.ts +0 -504
  62. package/build/types/router-core/src/qss.d.ts +0 -2
  63. package/src/createRoutes.test.ts +0 -318
  64. package/src/package.json +0 -48
@@ -12,1433 +12,47 @@
12
12
 
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
- var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
16
15
  var index = require('../../../node_modules/history/index.js');
16
+ var tinyInvariant = require('../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js');
17
+ var path = require('./path.js');
17
18
  var qss = require('./qss.js');
19
+ var route = require('./route.js');
20
+ var routeConfig = require('./routeConfig.js');
21
+ var routeMatch = require('./routeMatch.js');
22
+ var router = require('./router.js');
23
+ var searchParams = require('./searchParams.js');
24
+ var utils = require('./utils.js');
18
25
 
19
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
20
- if (options === void 0) {
21
- options = {};
22
- }
23
26
 
24
- if (isRoot === void 0) {
25
- isRoot = true;
26
- }
27
-
28
- if (isRoot) {
29
- options.path = rootRouteId;
30
- } else {
31
- warning(!options.path, 'Routes must have a path property.');
32
- } // Strip the root from parentIds
33
-
34
-
35
- if (parentId === rootRouteId) {
36
- parentId = '';
37
- }
38
-
39
- let path = String(isRoot ? rootRouteId : options.path); // If the path is anything other than an index path, trim it up
40
-
41
- if (path !== '/') {
42
- path = trimPath(path);
43
- }
44
-
45
- let id = joinPaths([parentId, path]);
46
-
47
- if (path === rootRouteId) {
48
- path = '/';
49
- }
50
-
51
- if (id !== rootRouteId) {
52
- id = joinPaths(['/', id]);
53
- }
54
-
55
- const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
56
- return {
57
- id: id,
58
- path: path,
59
- fullPath: fullPath,
60
- options: options,
61
- children,
62
- addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
63
- };
64
- };
65
- const rootRouteId = '__root__';
66
- // Source
67
- // Detect if we're in the DOM
68
- const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement); // This is the default history object if none is defined
69
-
70
- const createDefaultHistory = () => isDOM ? index.createBrowserHistory() : index.createMemoryHistory();
71
-
72
- function createRouter(userOptions) {
73
- var _userOptions$stringif, _userOptions$parseSea;
74
-
75
- const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
76
-
77
- const originalOptions = _rollupPluginBabelHelpers["extends"]({}, userOptions, {
78
- stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
79
- parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
80
- });
81
-
82
- let router = {
83
- options: originalOptions,
84
- listeners: [],
85
- // Resolved after construction
86
- basepath: '',
87
- routeTree: undefined,
88
- routesById: {},
89
- location: undefined,
90
- allRouteInfo: undefined,
91
- //
92
- navigationPromise: Promise.resolve(),
93
- resolveNavigation: () => {},
94
- preloadCache: {},
95
- state: {
96
- status: 'idle',
97
- location: null,
98
- matches: [],
99
- actions: {},
100
- loaderData: {},
101
- lastUpdated: Date.now()
102
- },
103
- startedLoadingAt: Date.now(),
104
- subscribe: listener => {
105
- router.listeners.push(listener);
106
- return () => {
107
- router.listeners = router.listeners.filter(x => x !== listener);
108
- };
109
- },
110
- getRoute: id => {
111
- return router.routesById[id];
112
- },
113
- notify: () => {
114
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state);
115
- router.listeners.forEach(listener => listener());
116
- },
117
- mount: () => {
118
- const next = router.buildLocation({
119
- to: '.',
120
- search: true,
121
- hash: true
122
- }); // If the current location isn't updated, trigger a navigation
123
- // to the current location. Otherwise, load the current location.
124
-
125
- if (next.href !== router.location.href) {
126
- return router.commitLocation(next, true);
127
- } else {
128
- return router.loadLocation();
129
- }
130
- },
131
- update: opts => {
132
- Object.assign(router.options, opts);
133
- const {
134
- basepath,
135
- routeConfig
136
- } = router.options;
137
- router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
138
-
139
- if (routeConfig) {
140
- router.routesById = {};
141
- router.routeTree = router.buildRouteTree(routeConfig);
142
- }
143
-
144
- return router;
145
- },
146
- destroy: history.listen(event => {
147
- router.loadLocation(router.parseLocation(event.location, router.location));
148
- }),
149
- buildRouteTree: rootRouteConfig => {
150
- const recurseRoutes = (routeConfigs, parent) => {
151
- return routeConfigs.map(routeConfig => {
152
- const routeOptions = routeConfig.options;
153
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
154
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
155
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
156
- // }
157
-
158
- const existingRoute = router.routesById[route.routeId];
159
-
160
- if (existingRoute) {
161
- if (process.env.NODE_ENV !== 'production') {
162
- console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
163
- }
164
-
165
- throw new Error();
166
- }
167
- router.routesById[route.routeId] = route;
168
- const children = routeConfig.children;
169
- route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
170
- return route;
171
- });
172
- };
173
-
174
- const routes = recurseRoutes([rootRouteConfig]);
175
- return routes[0];
176
- },
177
- parseLocation: (location, previousLocation) => {
178
- var _location$hash$split$;
179
-
180
- const parsedSearch = router.options.parseSearch(location.search);
181
- return {
182
- pathname: location.pathname,
183
- searchStr: location.search,
184
- search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
185
- hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
186
- href: "" + location.pathname + location.search + location.hash,
187
- state: location.state,
188
- key: location.key
189
- };
190
- },
191
- buildLocation: function buildLocation(dest) {
192
- var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
193
-
194
- if (dest === void 0) {
195
- dest = {};
196
- }
197
-
198
- // const resolvedFrom: Location = {
199
- // ...router.location,
200
- const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
201
-
202
- let pathname = _resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
203
-
204
- const fromMatches = router.matchRoutes(router.location.pathname, {
205
- strictParseParams: true
206
- });
207
- const toMatches = router.matchRoutes(pathname);
208
- const prevParams = (_last = last(fromMatches)) == null ? void 0 : _last.params;
209
- let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
210
-
211
- if (nextParams) {
212
- toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
213
- Object.assign(nextParams, fn(nextParams));
214
- });
215
- }
216
-
217
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
218
-
219
- const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
220
-
221
- const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
222
- : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
223
- : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
224
- : {}; // Then post filters
225
-
226
- const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
227
- const search = replaceEqualDeep(router.location.search, postFilteredSearch);
228
- const searchStr = router.options.stringifySearch(search);
229
- let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
230
- hash = hash ? "#" + hash : '';
231
- return {
232
- pathname,
233
- search,
234
- searchStr,
235
- state: router.location.state,
236
- hash,
237
- href: "" + pathname + searchStr + hash,
238
- key: dest.key
239
- };
240
- },
241
- commitLocation: (next, replace) => {
242
- const id = '' + Date.now() + Math.random();
243
- if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
244
- let nextAction = 'replace';
245
-
246
- if (!replace) {
247
- nextAction = 'push';
248
- }
249
-
250
- const isSameUrl = router.parseLocation(history.location).href === next.href;
251
-
252
- if (isSameUrl && !next.key) {
253
- nextAction = 'replace';
254
- }
255
-
256
- if (nextAction === 'replace') {
257
- history.replace({
258
- pathname: next.pathname,
259
- hash: next.hash,
260
- search: next.searchStr
261
- }, {
262
- id
263
- });
264
- } else {
265
- history.push({
266
- pathname: next.pathname,
267
- hash: next.hash,
268
- search: next.searchStr
269
- }, {
270
- id
271
- });
272
- }
273
-
274
- router.navigationPromise = new Promise(resolve => {
275
- const previousNavigationResolve = router.resolveNavigation;
276
-
277
- router.resolveNavigation = () => {
278
- previousNavigationResolve();
279
- resolve();
280
- };
281
- });
282
- return router.navigationPromise;
283
- },
284
- buildNext: opts => {
285
- const next = router.buildLocation(opts);
286
- const matches = router.matchRoutes(next.pathname);
287
-
288
- const __preSearchFilters = matches.map(match => {
289
- var _match$options$preSea;
290
-
291
- return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
292
- }).flat().filter(Boolean);
293
-
294
- const __postSearchFilters = matches.map(match => {
295
- var _match$options$postSe;
296
-
297
- return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
298
- }).flat().filter(Boolean);
299
-
300
- return router.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
301
- __preSearchFilters,
302
- __postSearchFilters
303
- }));
304
- },
305
- cancelMatches: () => {
306
- var _router$state$pending, _router$state$pending2;
307
- [...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
308
- match.cancel();
309
- });
310
- },
311
- loadLocation: async next => {
312
- const id = Math.random();
313
- router.startedLoadingAt = id;
314
-
315
- if (next) {
316
- // Ingest the new location
317
- router.location = next;
318
- } // Cancel any pending matches
319
-
320
-
321
- router.cancelMatches(); // Match the routes
322
-
323
- const unloadedMatches = router.matchRoutes(location.pathname, {
324
- strictParseParams: true
325
- });
326
- unloadedMatches.forEach((match, index) => {
327
- const parent = unloadedMatches[index - 1];
328
- const child = unloadedMatches[index + 1];
329
- if (parent) match.__.setParentMatch(parent);
330
- if (child) match.__.addChildMatch(child);
331
- });
332
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
333
- pending: {
334
- matches: unloadedMatches,
335
- location: router.location
336
- }
337
- });
338
- router.notify(); // Load the matches
339
-
340
- const matches = await router.loadMatches(unloadedMatches, {
341
- withPending: true
342
- });
343
-
344
- if (router.startedLoadingAt !== id) {
345
- // Ignore side-effects of match loading
346
- return router.navigationPromise;
347
- }
348
-
349
- const previousMatches = router.state.matches;
350
- previousMatches.filter(d => {
351
- return !matches.find(dd => dd.matchId === d.matchId);
352
- }).forEach(d => {
353
- d.__.onExit == null ? void 0 : d.__.onExit({
354
- params: d.params,
355
- search: d.routeSearch
356
- });
357
- });
358
- previousMatches.filter(d => {
359
- return matches.find(dd => dd.matchId === d.matchId);
360
- }).forEach(d => {
361
- d.options.onTransition == null ? void 0 : d.options.onTransition({
362
- params: d.params,
363
- search: d.routeSearch
364
- });
365
- });
366
- matches.filter(d => {
367
- return !previousMatches.find(dd => dd.matchId === d.matchId);
368
- }).forEach(d => {
369
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
370
- params: d.params,
371
- search: d.search
372
- });
373
- });
374
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
375
- location: router.location,
376
- matches,
377
- pending: undefined
378
- });
379
-
380
- if (matches.some(d => d.status === 'loading')) {
381
- router.notify();
382
- await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
383
- }
384
-
385
- if (router.startedLoadingAt !== id) {
386
- // Ignore side-effects of match loading
387
- return;
388
- }
389
-
390
- router.notify();
391
- router.resolveNavigation();
392
- },
393
- cleanPreloadCache: () => {
394
- const now = Date.now();
395
- Object.keys(router.preloadCache).forEach(matchId => {
396
- const entry = router.preloadCache[matchId]; // Don't remove loading matches
397
-
398
- if (entry.match.status === 'loading') {
399
- return;
400
- } // Do not remove successful matches that are still valid
401
-
402
-
403
- if (entry.match.updatedAt && entry.match.updatedAt + entry.maxAge > now) {
404
- return;
405
- } // Everything else gets removed
406
-
407
-
408
- delete router.preloadCache[matchId];
409
- });
410
- },
411
- loadRoute: async function loadRoute(navigateOpts, loaderOpts) {
412
- if (navigateOpts === void 0) {
413
- navigateOpts = router.location;
414
- }
415
-
416
- const next = router.buildNext(navigateOpts);
417
- const matches = router.matchRoutes(next.pathname, {
418
- strictParseParams: true
419
- });
420
- await router.loadMatches(matches, {
421
- preload: true,
422
- maxAge: loaderOpts.maxAge
423
- });
424
- return matches;
425
- },
426
- matchRoutes: (pathname, opts) => {
427
- var _router$state$pending3, _router$state$pending4;
428
-
429
- router.cleanPreloadCache();
430
- const matches = [];
431
-
432
- if (!router.routeTree) {
433
- return matches;
434
- }
435
-
436
- const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
437
-
438
- const recurse = async (routes, parentMatch) => {
439
- var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
440
-
441
- let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
442
- const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
443
- const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
444
- var _route$childRoutes, _route$options$caseSe;
445
-
446
- const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
447
- const matchParams = matchPathname(pathname, {
448
- to: route.fullPath,
449
- fuzzy,
450
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
451
- });
452
-
453
- if (matchParams) {
454
- let parsedParams;
455
-
456
- try {
457
- var _route$options$parseP;
458
-
459
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
460
- } catch (err) {
461
- if (opts != null && opts.strictParseParams) {
462
- throw err;
463
- }
464
- }
465
-
466
- params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
467
- }
468
-
469
- return !!matchParams;
470
- });
471
-
472
- if (!route) {
473
- return;
474
- }
475
-
476
- const interpolatedPath = interpolatePath(route.routePath, params);
477
- const matchId = interpolatePath(route.routeId, params, true);
478
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
479
- matchId,
480
- params,
481
- pathname: joinPaths([pathname, interpolatedPath])
482
- });
483
- matches.push(match);
484
-
485
- if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
486
- recurse(route.childRoutes, match);
487
- }
488
- };
489
-
490
- recurse([router.routeTree]);
491
- return matches;
492
- },
493
- loadMatches: async (resolvedMatches, loaderOpts) => {
494
- const matchPromises = resolvedMatches.map(async match => {
495
- // Validate the match (loads search params etc)
496
- match.__.validate(); // If this is a preload, add it to the preload cache
497
-
498
-
499
- if (loaderOpts != null && loaderOpts.preload) {
500
- router.preloadCache[match.matchId] = {
501
- maxAge: loaderOpts == null ? void 0 : loaderOpts.maxAge,
502
- match
503
- };
504
- } // If the match is invalid, errored or idle, trigger it to load
505
-
506
-
507
- if (match.status === 'success' && match.isInvalid || match.status === 'error' || match.status === 'idle') {
508
- match.load();
509
- } // If requested, start the pending timers
510
-
511
-
512
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
513
- // This might be completion, error, or a pending state
514
-
515
- await match.__.loadPromise;
516
- });
517
- router.notify();
518
- await Promise.all(matchPromises);
519
- return resolvedMatches;
520
- },
521
- invalidateRoute: opts => {
522
- var _router$state$pending5, _router$state$pending6;
523
-
524
- const next = router.buildNext(opts);
525
- const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
526
- [...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
527
- if (unloadedMatchIds.includes(match.matchId)) {
528
- match.isInvalid = true;
529
- }
530
- });
531
- },
532
- reload: () => router._navigate({
533
- fromCurrent: true,
534
- replace: true,
535
- search: true
536
- }),
537
- resolvePath: (from, path) => {
538
- return _resolvePath(router.basepath, from, cleanPath(path));
539
- },
540
- matchRoute: (location, opts) => {
541
- var _location$from;
542
-
543
- // const location = router.buildNext(opts)
544
- location = _rollupPluginBabelHelpers["extends"]({}, location, {
545
- to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
546
- });
547
- const next = router.buildNext(location);
548
-
549
- if (opts != null && opts.pending) {
550
- var _router$state$pending7;
551
-
552
- if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
553
- return false;
554
- }
555
-
556
- return !!matchPathname(router.state.pending.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
557
- to: next.pathname
558
- }));
559
- }
560
-
561
- return !!matchPathname(router.state.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
562
- to: next.pathname
563
- }));
564
- },
565
- _navigate: location => {
566
- const next = router.buildNext(location);
567
- return router.commitLocation(next, location.replace);
568
- },
569
- navigate: async _ref => {
570
- let {
571
- from,
572
- to = '.',
573
- search,
574
- hash,
575
- replace
576
- } = _ref;
577
- // If this link simply reloads the current route,
578
- // make sure it has a new key so it will trigger a data refresh
579
- // If this `to` is a valid external URL, return
580
- // null for LinkUtils
581
- const toString = String(to);
582
- const fromString = String(from);
583
- let isExternal;
584
-
585
- try {
586
- new URL("" + toString);
587
- isExternal = true;
588
- } catch (e) {}
589
-
590
- if (isExternal) {
591
- if (process.env.NODE_ENV !== 'production') {
592
- throw new Error('Attempting to navigate to external url with router.navigate!');
593
- }
594
-
595
- return;
596
- }
597
-
598
- return router._navigate({
599
- from: fromString,
600
- to: toString,
601
- search,
602
- hash
603
- });
604
- },
605
- buildLink: _ref2 => {
606
- var _preload, _ref3, _ref4;
607
-
608
- let {
609
- from,
610
- to = '.',
611
- search,
612
- params,
613
- hash,
614
- target,
615
- replace,
616
- activeOptions,
617
- preload,
618
- preloadMaxAge: userPreloadMaxAge,
619
- preloadDelay: userPreloadDelay,
620
- disabled
621
- } = _ref2;
622
-
623
- // If this link simply reloads the current route,
624
- // make sure it has a new key so it will trigger a data refresh
625
- // If this `to` is a valid external URL, return
626
- // null for LinkUtils
627
- try {
628
- new URL("" + to);
629
- return {
630
- type: 'external',
631
- href: to
632
- };
633
- } catch (e) {}
634
-
635
- const nextOpts = {
636
- from,
637
- to,
638
- search,
639
- params,
640
- hash,
641
- replace
642
- };
643
- const next = router.buildNext(nextOpts);
644
- preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
645
- const preloadMaxAge = (_ref3 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref3 : 2000;
646
- const preloadDelay = (_ref4 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref4 : 50; // Compare path/hash for matches
647
-
648
- const pathIsEqual = router.state.location.pathname === next.pathname;
649
- const currentPathSplit = router.state.location.pathname.split('/');
650
- const nextPathSplit = next.pathname.split('/');
651
- const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
652
- const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
653
-
654
- const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
655
- const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
656
-
657
- const isActive = pathTest && hashTest; // The click handler
658
-
659
- const handleClick = e => {
660
- if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
661
- e.preventDefault();
662
-
663
- if (pathIsEqual && !search && !hash) {
664
- router.invalidateRoute(nextOpts);
665
- } // All is well? Navigate!)
666
-
667
-
668
- router._navigate(nextOpts);
669
- }
670
- }; // The click handler
671
-
672
-
673
- const handleFocus = e => {
674
- if (preload && preloadMaxAge > 0) {
675
- router.loadRoute(nextOpts, {
676
- maxAge: preloadMaxAge
677
- });
678
- }
679
- };
680
-
681
- const handleEnter = e => {
682
- const target = e.target || {};
683
-
684
- if (preload && preloadMaxAge > 0) {
685
- if (target.preloadTimeout) {
686
- return;
687
- }
688
-
689
- target.preloadTimeout = setTimeout(() => {
690
- target.preloadTimeout = null;
691
- router.loadRoute(nextOpts, {
692
- maxAge: preloadMaxAge
693
- });
694
- }, preloadDelay);
695
- }
696
- };
697
-
698
- const handleLeave = e => {
699
- const target = e.target || {};
700
-
701
- if (target.preloadTimeout) {
702
- clearTimeout(target.preloadTimeout);
703
- target.preloadTimeout = null;
704
- }
705
- };
706
-
707
- return {
708
- type: 'internal',
709
- next,
710
- handleFocus,
711
- handleClick,
712
- handleEnter,
713
- handleLeave,
714
- isActive,
715
- disabled
716
- };
717
- },
718
- __experimental__createSnapshot: () => {
719
- return _rollupPluginBabelHelpers["extends"]({}, router.state, {
720
- matches: router.state.matches.map(_ref5 => {
721
- let {
722
- routeLoaderData: loaderData,
723
- matchId
724
- } = _ref5;
725
- return {
726
- matchId,
727
- loaderData
728
- };
729
- })
730
- });
731
- }
732
- };
733
- router.location = router.parseLocation(history.location); // router.state.location = __experimental__snapshot?.location ?? router.location
734
-
735
- router.state.location = router.location;
736
- router.update(userOptions); // Allow frameworks to hook into the router creation
737
-
738
- router.options.createRouter == null ? void 0 : router.options.createRouter(router); // router.mount()
739
-
740
- return router;
741
- }
742
- function createRoute(routeConfig, options, parent, router) {
743
- // const id = (
744
- // options.path === rootRouteId
745
- // ? rootRouteId
746
- // : joinPaths([
747
- // parent!.id,
748
- // `${options.path?.replace(/(.)\/$/, '$1')}`,
749
- // ]).replace(new RegExp(`^${rootRouteId}`), '')
750
- // ) as TRouteInfo['id']
751
- const {
752
- id: routeId,
753
- path: routePath,
754
- fullPath
755
- } = routeConfig;
756
-
757
- const action = router.state.actions[routeId] || (() => {
758
- router.state.actions[routeId] = {
759
- pending: [],
760
- submit: async (submission, actionOpts) => {
761
- var _actionOpts$invalidat;
762
-
763
- if (!route) {
764
- return;
765
- }
766
-
767
- const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
768
- const actionState = {
769
- submittedAt: Date.now(),
770
- status: 'pending',
771
- submission
772
- };
773
- action.latest = actionState;
774
- action.pending.push(actionState);
775
- router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
776
- action: actionState
777
- });
778
- router.notify();
779
-
780
- try {
781
- const res = await (route.options.action == null ? void 0 : route.options.action(submission));
782
- actionState.data = res;
783
-
784
- if (invalidate) {
785
- router.invalidateRoute({
786
- to: '.',
787
- fromCurrent: true
788
- });
789
- await router.reload();
790
- }
791
-
792
- actionState.status = 'success';
793
- return res;
794
- } catch (err) {
795
- console.error(err);
796
- actionState.error = err;
797
- actionState.status = 'error';
798
- } finally {
799
- action.pending = action.pending.filter(d => d !== actionState);
800
-
801
- if (actionState === router.state.action) {
802
- router.state.action = undefined;
803
- }
804
-
805
- router.notify();
806
- }
807
- }
808
- };
809
- return router.state.actions[routeId];
810
- })();
811
-
812
- let route = {
813
- routeId,
814
- routePath,
815
- fullPath,
816
- options,
817
- router,
818
- childRoutes: undefined,
819
- parentRoute: parent,
820
- action,
821
- buildLink: options => {
822
- return router.buildLink(_rollupPluginBabelHelpers["extends"]({}, options, {
823
- from: fullPath
824
- }));
825
- },
826
- navigate: options => {
827
- return router.navigate(_rollupPluginBabelHelpers["extends"]({}, options, {
828
- from: fullPath
829
- }));
830
- },
831
- matchRoute: (matchLocation, opts) => {
832
- return router.matchRoute(_rollupPluginBabelHelpers["extends"]({}, matchLocation, {
833
- from: fullPath
834
- }), opts);
835
- }
836
- };
837
- router.options.createRoute == null ? void 0 : router.options.createRoute({
838
- router,
839
- route
840
- });
841
- return route;
842
- }
843
- function createRouteMatch(router, route, opts) {
844
- const routeMatch = _rollupPluginBabelHelpers["extends"]({}, route, opts, {
845
- router,
846
- routeSearch: {},
847
- search: {},
848
- childMatches: [],
849
- status: 'idle',
850
- routeLoaderData: {},
851
- loaderData: {},
852
- isPending: false,
853
- isFetching: false,
854
- isInvalid: false,
855
- __: {
856
- abortController: new AbortController(),
857
- latestId: '',
858
- resolve: () => {},
859
- notify: () => {
860
- routeMatch.__.resolve();
861
-
862
- routeMatch.router.notify();
863
- },
864
- startPending: () => {
865
- var _routeMatch$options$p, _routeMatch$options$p2;
866
-
867
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
868
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
869
-
870
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
871
- return;
872
- }
873
-
874
- routeMatch.__.pendingTimeout = setTimeout(() => {
875
- routeMatch.isPending = true;
876
-
877
- routeMatch.__.resolve();
878
-
879
- if (typeof pendingMinMs !== 'undefined') {
880
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
881
- }
882
- }, pendingMs);
883
- },
884
- cancelPending: () => {
885
- routeMatch.isPending = false;
886
- clearTimeout(routeMatch.__.pendingTimeout);
887
- clearTimeout(routeMatch.__.pendingMinTimeout);
888
- delete routeMatch.__.pendingMinPromise;
889
- },
890
- setParentMatch: parentMatch => {
891
- routeMatch.parentMatch = parentMatch;
892
- },
893
- addChildMatch: childMatch => {
894
- if (routeMatch.childMatches.find(d => d.matchId === childMatch.matchId)) {
895
- return;
896
- }
897
-
898
- routeMatch.childMatches.push(childMatch);
899
- },
900
- validate: () => {
901
- var _routeMatch$parentMat, _routeMatch$parentMat2;
902
-
903
- // Validate the search params and stabilize them
904
- const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
905
-
906
- try {
907
- const prevSearch = routeMatch.routeSearch;
908
- let nextSearch = replaceEqualDeep(prevSearch, routeMatch.options.validateSearch == null ? void 0 : routeMatch.options.validateSearch(parentSearch)); // Invalidate route matches when search param stability changes
909
-
910
- if (prevSearch !== nextSearch) {
911
- routeMatch.isInvalid = true;
912
- }
913
-
914
- routeMatch.routeSearch = nextSearch;
915
- routeMatch.search = replaceEqualDeep(parentSearch, _rollupPluginBabelHelpers["extends"]({}, parentSearch, nextSearch));
916
- } catch (err) {
917
- console.error(err);
918
- const error = new Error('Invalid search params found', {
919
- cause: err
920
- });
921
- error.code = 'INVALID_SEARCH_PARAMS';
922
- routeMatch.status = 'error';
923
- routeMatch.error = error; // Do not proceed with loading the route
924
-
925
- return;
926
- }
927
- }
928
- },
929
- cancel: () => {
930
- var _routeMatch$__$abortC;
931
-
932
- (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
933
-
934
- routeMatch.__.cancelPending();
935
- },
936
- load: async () => {
937
- const id = '' + Date.now() + Math.random();
938
- routeMatch.__.latestId = id; // If the match was in an error state, set it
939
- // to a loading state again. Otherwise, keep it
940
- // as loading or resolved
941
-
942
- if (routeMatch.status === 'error' || routeMatch.status === 'idle') {
943
- routeMatch.status = 'loading';
944
- } // We started loading the route, so it's no longer invalid
945
-
946
-
947
- routeMatch.isInvalid = false;
948
- routeMatch.__.loadPromise = new Promise(async resolve => {
949
- // We are now fetching, even if it's in the background of a
950
- // resolved state
951
- routeMatch.isFetching = true;
952
- routeMatch.__.resolve = resolve;
953
-
954
- const loaderPromise = (async () => {
955
- const importer = routeMatch.options.import; // First, run any importers
956
-
957
- if (importer) {
958
- routeMatch.__.importPromise = importer({
959
- params: routeMatch.params // search: routeMatch.search,
960
-
961
- }).then(imported => {
962
- routeMatch.__ = _rollupPluginBabelHelpers["extends"]({}, routeMatch.__, imported);
963
- });
964
- } // Wait for the importer to finish before
965
- // attempting to load elements and data
966
-
967
-
968
- await routeMatch.__.importPromise; // Next, load the elements and data in parallel
969
-
970
- routeMatch.__.elementsPromise = (async () => {
971
- // then run all element and data loaders in parallel
972
- // For each element type, potentially load it asynchronously
973
- const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
974
- await Promise.all(elementTypes.map(async type => {
975
- const routeElement = routeMatch.options[type];
976
-
977
- if (routeMatch.__[type]) {
978
- return;
979
- }
980
-
981
- if (typeof routeElement === 'function') {
982
- const res = await routeElement(routeMatch);
983
- routeMatch.__[type] = res;
984
- } else {
985
- routeMatch.__[type] = routeMatch.options[type];
986
- }
987
- }));
988
- })();
989
-
990
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
991
- try {
992
- const data = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
993
- params: routeMatch.params,
994
- search: routeMatch.routeSearch,
995
- signal: routeMatch.__.abortController.signal
996
- }));
997
-
998
- if (id !== routeMatch.__.latestId) {
999
- return routeMatch.__.loaderPromise;
1000
- }
1001
-
1002
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1003
- cascadeLoaderData(routeMatch);
1004
- routeMatch.error = undefined;
1005
- routeMatch.status = 'success';
1006
- routeMatch.updatedAt = Date.now();
1007
- } catch (err) {
1008
- if (id !== routeMatch.__.latestId) {
1009
- return routeMatch.__.loaderPromise;
1010
- }
1011
-
1012
- if (process.env.NODE_ENV !== 'production') {
1013
- console.error(err);
1014
- }
1015
-
1016
- routeMatch.error = err;
1017
- routeMatch.status = 'error';
1018
- routeMatch.updatedAt = Date.now();
1019
- }
1020
- });
1021
-
1022
- try {
1023
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1024
-
1025
- if (id !== routeMatch.__.latestId) {
1026
- return routeMatch.__.loaderPromise;
1027
- }
1028
-
1029
- if (routeMatch.__.pendingMinPromise) {
1030
- await routeMatch.__.pendingMinPromise;
1031
- delete routeMatch.__.pendingMinPromise;
1032
- }
1033
- } finally {
1034
- if (id !== routeMatch.__.latestId) {
1035
- return routeMatch.__.loaderPromise;
1036
- }
1037
-
1038
- routeMatch.__.cancelPending();
1039
-
1040
- routeMatch.isPending = false;
1041
- routeMatch.isFetching = false;
1042
-
1043
- routeMatch.__.notify();
1044
- }
1045
- })();
1046
-
1047
- routeMatch.__.loaderPromise = loaderPromise;
1048
- await loaderPromise;
1049
-
1050
- if (id !== routeMatch.__.latestId) {
1051
- return routeMatch.__.loaderPromise;
1052
- }
1053
-
1054
- delete routeMatch.__.loaderPromise;
1055
- });
1056
- return await routeMatch.__.loadPromise;
1057
- }
1058
- });
1059
-
1060
- return routeMatch;
1061
- }
1062
-
1063
- function cascadeLoaderData(routeMatch) {
1064
- if (routeMatch.parentMatch) {
1065
- routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _rollupPluginBabelHelpers["extends"]({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
1066
- }
1067
-
1068
- if (routeMatch.childMatches.length) {
1069
- routeMatch.childMatches.forEach(childMatch => {
1070
- cascadeLoaderData(childMatch);
1071
- });
1072
- }
1073
- }
1074
-
1075
- function matchPathname(currentPathname, matchLocation) {
1076
- const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1077
-
1078
- if (matchLocation.to && !pathParams) {
1079
- return;
1080
- } // if (matchLocation.search && !searchMatched) {
1081
- // return
1082
- // }
1083
-
1084
-
1085
- return pathParams != null ? pathParams : {};
1086
- }
1087
-
1088
- function interpolatePath(path, params, leaveWildcard) {
1089
- const interpolatedPathSegments = parsePathname(path);
1090
- return joinPaths(interpolatedPathSegments.map(segment => {
1091
- if (segment.value === '*' && !leaveWildcard) {
1092
- return '';
1093
- }
1094
-
1095
- if (segment.type === 'param') {
1096
- var _segment$value$substr;
1097
-
1098
- return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1099
- }
1100
-
1101
- return segment.value;
1102
- }));
1103
- }
1104
-
1105
- function warning(cond, message) {
1106
- if (cond) {
1107
- if (typeof console !== 'undefined') console.warn(message);
1108
-
1109
- try {
1110
- throw new Error(message);
1111
- } catch (_unused) {}
1112
- }
1113
-
1114
- return true;
1115
- }
1116
-
1117
- function isFunction(d) {
1118
- return typeof d === 'function';
1119
- }
1120
-
1121
- function functionalUpdate(updater, previous) {
1122
- if (isFunction(updater)) {
1123
- return updater(previous);
1124
- }
1125
-
1126
- return updater;
1127
- }
1128
-
1129
- function joinPaths(paths) {
1130
- return cleanPath(paths.filter(Boolean).join('/'));
1131
- }
1132
-
1133
- function cleanPath(path) {
1134
- // remove double slashes
1135
- return path.replace(/\/{2,}/g, '/');
1136
- }
1137
-
1138
- function trimPathLeft(path) {
1139
- return path === '/' ? path : path.replace(/^\/{1,}/, '');
1140
- }
1141
-
1142
- function trimPathRight(path) {
1143
- return path === '/' ? path : path.replace(/\/{1,}$/, '');
1144
- }
1145
-
1146
- function trimPath(path) {
1147
- return trimPathRight(trimPathLeft(path));
1148
- }
1149
-
1150
- function matchByPath(from, matchLocation) {
1151
- var _matchLocation$to;
1152
-
1153
- const baseSegments = parsePathname(from);
1154
- const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
1155
- const params = {};
1156
-
1157
- let isMatch = (() => {
1158
- for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
1159
- const baseSegment = baseSegments[i];
1160
- const routeSegment = routeSegments[i];
1161
- const isLastRouteSegment = i === routeSegments.length - 1;
1162
- const isLastBaseSegment = i === baseSegments.length - 1;
1163
-
1164
- if (routeSegment) {
1165
- if (routeSegment.type === 'wildcard') {
1166
- if (baseSegment != null && baseSegment.value) {
1167
- params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
1168
- return true;
1169
- }
1170
-
1171
- return false;
1172
- }
1173
-
1174
- if (routeSegment.type === 'pathname') {
1175
- if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
1176
- return true;
1177
- }
1178
-
1179
- if (baseSegment) {
1180
- if (matchLocation.caseSensitive) {
1181
- if (routeSegment.value !== baseSegment.value) {
1182
- return false;
1183
- }
1184
- } else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
1185
- return false;
1186
- }
1187
- }
1188
- }
1189
-
1190
- if (!baseSegment) {
1191
- return false;
1192
- }
1193
-
1194
- if (routeSegment.type === 'param') {
1195
- if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
1196
- return false;
1197
- }
1198
-
1199
- if (!baseSegment.value.startsWith(':')) {
1200
- params[routeSegment.value.substring(1)] = baseSegment.value;
1201
- }
1202
- }
1203
- }
1204
-
1205
- if (isLastRouteSegment && !isLastBaseSegment) {
1206
- return !!matchLocation.fuzzy;
1207
- }
1208
- }
1209
-
1210
- return true;
1211
- })();
1212
-
1213
- return isMatch ? params : undefined;
1214
- } // function matchBySearch(
1215
- // search: SearchSchema,
1216
- // matchLocation: MatchLocation,
1217
- // ) {
1218
- // return !!(matchLocation.search && matchLocation.search(search))
1219
- // }
1220
-
1221
- function parsePathname(pathname) {
1222
- if (!pathname) {
1223
- return [];
1224
- }
1225
-
1226
- pathname = cleanPath(pathname);
1227
- const segments = [];
1228
-
1229
- if (pathname.slice(0, 1) === '/') {
1230
- pathname = pathname.substring(1);
1231
- segments.push({
1232
- type: 'pathname',
1233
- value: '/'
1234
- });
1235
- }
1236
-
1237
- if (!pathname) {
1238
- return segments;
1239
- } // Remove empty segments and '.' segments
1240
-
1241
-
1242
- const split = pathname.split('/').filter(Boolean);
1243
- segments.push(...split.map(part => {
1244
- if (part.startsWith('*')) {
1245
- return {
1246
- type: 'wildcard',
1247
- value: part
1248
- };
1249
- }
1250
-
1251
- if (part.charAt(0) === ':') {
1252
- return {
1253
- type: 'param',
1254
- value: part
1255
- };
1256
- }
1257
-
1258
- return {
1259
- type: 'pathname',
1260
- value: part
1261
- };
1262
- }));
1263
-
1264
- if (pathname.slice(-1) === '/') {
1265
- pathname = pathname.substring(1);
1266
- segments.push({
1267
- type: 'pathname',
1268
- value: '/'
1269
- });
1270
- }
1271
-
1272
- return segments;
1273
- }
1274
-
1275
- function _resolvePath(basepath, base, to) {
1276
- base = base.replace(new RegExp("^" + basepath), '/');
1277
- to = to.replace(new RegExp("^" + basepath), '/');
1278
- let baseSegments = parsePathname(base);
1279
- const toSegments = parsePathname(to);
1280
- toSegments.forEach((toSegment, index) => {
1281
- if (toSegment.value === '/') {
1282
- if (!index) {
1283
- // Leading slash
1284
- baseSegments = [toSegment];
1285
- } else if (index === toSegments.length - 1) {
1286
- // Trailing Slash
1287
- baseSegments.push(toSegment);
1288
- } else ;
1289
- } else if (toSegment.value === '..') {
1290
- var _last2;
1291
-
1292
- // Extra trailing slash? pop it off
1293
- if (baseSegments.length > 1 && ((_last2 = last(baseSegments)) == null ? void 0 : _last2.value) === '/') {
1294
- baseSegments.pop();
1295
- }
1296
-
1297
- baseSegments.pop();
1298
- } else if (toSegment.value === '.') {
1299
- return;
1300
- } else {
1301
- baseSegments.push(toSegment);
1302
- }
1303
- });
1304
- const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
1305
- return cleanPath(joined);
1306
- }
1307
- function replaceEqualDeep(prev, next) {
1308
- if (prev === next) {
1309
- return prev;
1310
- }
1311
-
1312
- const array = Array.isArray(prev) && Array.isArray(next);
1313
-
1314
- if (array || isPlainObject(prev) && isPlainObject(next)) {
1315
- const aSize = array ? prev.length : Object.keys(prev).length;
1316
- const bItems = array ? next : Object.keys(next);
1317
- const bSize = bItems.length;
1318
- const copy = array ? [] : {};
1319
- let equalItems = 0;
1320
-
1321
- for (let i = 0; i < bSize; i++) {
1322
- const key = array ? i : bItems[i];
1323
- copy[key] = replaceEqualDeep(prev[key], next[key]);
1324
-
1325
- if (copy[key] === prev[key]) {
1326
- equalItems++;
1327
- }
1328
- }
1329
-
1330
- return aSize === bSize && equalItems === aSize ? prev : copy;
1331
- }
1332
-
1333
- return next;
1334
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
1335
-
1336
- function isPlainObject(o) {
1337
- if (!hasObjectPrototype(o)) {
1338
- return false;
1339
- } // If has modified constructor
1340
-
1341
-
1342
- const ctor = o.constructor;
1343
-
1344
- if (typeof ctor === 'undefined') {
1345
- return true;
1346
- } // If has modified prototype
1347
-
1348
-
1349
- const prot = ctor.prototype;
1350
-
1351
- if (!hasObjectPrototype(prot)) {
1352
- return false;
1353
- } // If constructor does not have an Object-specific method
1354
-
1355
-
1356
- if (!prot.hasOwnProperty('isPrototypeOf')) {
1357
- return false;
1358
- } // Most likely a plain Object
1359
-
1360
-
1361
- return true;
1362
- }
1363
-
1364
- function hasObjectPrototype(o) {
1365
- return Object.prototype.toString.call(o) === '[object Object]';
1366
- }
1367
-
1368
- const defaultParseSearch = parseSearchWith(JSON.parse);
1369
- const defaultStringifySearch = stringifySearchWith(JSON.stringify);
1370
- function parseSearchWith(parser) {
1371
- return searchStr => {
1372
- if (searchStr.substring(0, 1) === '?') {
1373
- searchStr = searchStr.substring(1);
1374
- }
1375
-
1376
- let query = qss.decode(searchStr); // Try to parse any query params that might be json
1377
-
1378
- for (let key in query) {
1379
- const value = query[key];
1380
-
1381
- if (typeof value === 'string') {
1382
- try {
1383
- query[key] = parser(value);
1384
- } catch (err) {//
1385
- }
1386
- }
1387
- }
1388
-
1389
- return query;
1390
- };
1391
- }
1392
- function stringifySearchWith(stringify) {
1393
- return search => {
1394
- search = _rollupPluginBabelHelpers["extends"]({}, search);
1395
-
1396
- if (search) {
1397
- Object.keys(search).forEach(key => {
1398
- const val = search[key];
1399
-
1400
- if (typeof val === 'undefined' || val === undefined) {
1401
- delete search[key];
1402
- } else if (val && typeof val === 'object' && val !== null) {
1403
- try {
1404
- search[key] = stringify(val);
1405
- } catch (err) {// silent
1406
- }
1407
- }
1408
- });
1409
- }
1410
-
1411
- const searchStr = qss.encode(search).toString();
1412
- return searchStr ? "?" + searchStr : '';
1413
- };
1414
- }
1415
-
1416
- function isCtrlEvent(e) {
1417
- return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1418
- }
1419
-
1420
- function last(arr) {
1421
- return arr[arr.length - 1];
1422
- }
1423
27
 
1424
28
  exports.createBrowserHistory = index.createBrowserHistory;
1425
29
  exports.createHashHistory = index.createHashHistory;
1426
30
  exports.createMemoryHistory = index.createMemoryHistory;
1427
- exports.createRoute = createRoute;
1428
- exports.createRouteConfig = createRouteConfig;
1429
- exports.createRouteMatch = createRouteMatch;
1430
- exports.createRouter = createRouter;
1431
- exports.defaultParseSearch = defaultParseSearch;
1432
- exports.defaultStringifySearch = defaultStringifySearch;
1433
- exports.functionalUpdate = functionalUpdate;
1434
- exports.last = last;
1435
- exports.matchByPath = matchByPath;
1436
- exports.matchPathname = matchPathname;
1437
- exports.parsePathname = parsePathname;
1438
- exports.parseSearchWith = parseSearchWith;
1439
- exports.replaceEqualDeep = replaceEqualDeep;
1440
- exports.resolvePath = _resolvePath;
1441
- exports.rootRouteId = rootRouteId;
1442
- exports.stringifySearchWith = stringifySearchWith;
1443
- exports.warning = warning;
31
+ exports.invariant = tinyInvariant["default"];
32
+ exports.cleanPath = path.cleanPath;
33
+ exports.interpolatePath = path.interpolatePath;
34
+ exports.joinPaths = path.joinPaths;
35
+ exports.matchByPath = path.matchByPath;
36
+ exports.matchPathname = path.matchPathname;
37
+ exports.parsePathname = path.parsePathname;
38
+ exports.resolvePath = path.resolvePath;
39
+ exports.trimPath = path.trimPath;
40
+ exports.trimPathLeft = path.trimPathLeft;
41
+ exports.trimPathRight = path.trimPathRight;
42
+ exports.decode = qss.decode;
43
+ exports.encode = qss.encode;
44
+ exports.cascadeLoaderData = route.cascadeLoaderData;
45
+ exports.createRoute = route.createRoute;
46
+ exports.createRouteConfig = routeConfig.createRouteConfig;
47
+ exports.rootRouteId = routeConfig.rootRouteId;
48
+ exports.createRouteMatch = routeMatch.createRouteMatch;
49
+ exports.createRouter = router.createRouter;
50
+ exports.defaultParseSearch = searchParams.defaultParseSearch;
51
+ exports.defaultStringifySearch = searchParams.defaultStringifySearch;
52
+ exports.parseSearchWith = searchParams.parseSearchWith;
53
+ exports.stringifySearchWith = searchParams.stringifySearchWith;
54
+ exports.functionalUpdate = utils.functionalUpdate;
55
+ exports.last = utils.last;
56
+ exports.replaceEqualDeep = utils.replaceEqualDeep;
57
+ exports.warning = utils.warning;
1444
58
  //# sourceMappingURL=index.js.map