@tanstack/router-core 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +33 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/packages/location-core/src/index.js +1313 -0
  4. package/build/cjs/packages/location-core/src/index.js.map +1 -0
  5. package/build/cjs/packages/location-core/src/qss.js +70 -0
  6. package/build/cjs/packages/location-core/src/qss.js.map +1 -0
  7. package/build/cjs/packages/router-core/src/createRoutes.js +106 -0
  8. package/build/cjs/packages/router-core/src/createRoutes.js.map +1 -0
  9. package/build/cjs/packages/router-core/src/createRoutes.test.js +160 -0
  10. package/build/cjs/packages/router-core/src/createRoutes.test.js.map +1 -0
  11. package/build/cjs/packages/router-core/src/index.js +1444 -0
  12. package/build/cjs/packages/router-core/src/index.js.map +1 -0
  13. package/build/cjs/packages/router-core/src/qss.js +70 -0
  14. package/build/cjs/packages/router-core/src/qss.js.map +1 -0
  15. package/build/esm/index.js +2297 -0
  16. package/build/esm/index.js.map +1 -0
  17. package/build/stats-html.html +4034 -0
  18. package/build/stats-react.json +157 -0
  19. package/build/types/createRoutes.d.ts +10 -0
  20. package/build/types/createRoutes.test.d.ts +1 -0
  21. package/build/types/index.d.ts +517 -0
  22. package/build/types/qss.d.ts +2 -0
  23. package/build/types/react-router/src/createRoutes.test.d.ts +0 -0
  24. package/build/types/react-router/src/index.d.ts +59 -0
  25. package/build/types/router-core/src/createRoutes.test.d.ts +1 -0
  26. package/build/types/router-core/src/index.d.ts +504 -0
  27. package/build/types/router-core/src/qss.d.ts +2 -0
  28. package/build/umd/index.development.js +2322 -0
  29. package/build/umd/index.development.js.map +1 -0
  30. package/build/umd/index.production.js +12 -0
  31. package/build/umd/index.production.js.map +1 -0
  32. package/package.json +48 -0
  33. package/src/createRoutes.test.ts +318 -0
  34. package/src/index.ts +2974 -0
  35. package/src/package.json +48 -0
  36. package/src/qss.ts +53 -0
@@ -0,0 +1,2297 @@
1
+ /**
2
+ * router-core
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ function _extends$1() {
12
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
13
+ for (var i = 1; i < arguments.length; i++) {
14
+ var source = arguments[i];
15
+
16
+ for (var key in source) {
17
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
18
+ target[key] = source[key];
19
+ }
20
+ }
21
+ }
22
+
23
+ return target;
24
+ };
25
+ return _extends$1.apply(this, arguments);
26
+ }
27
+
28
+ function _extends() {
29
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
30
+ for (var i = 1; i < arguments.length; i++) {
31
+ var source = arguments[i];
32
+
33
+ for (var key in source) {
34
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
35
+ target[key] = source[key];
36
+ }
37
+ }
38
+ }
39
+
40
+ return target;
41
+ };
42
+ return _extends.apply(this, arguments);
43
+ }
44
+
45
+ /**
46
+ * Actions represent the type of change to a location value.
47
+ *
48
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
49
+ */
50
+ var Action;
51
+
52
+ (function (Action) {
53
+ /**
54
+ * A POP indicates a change to an arbitrary index in the history stack, such
55
+ * as a back or forward navigation. It does not describe the direction of the
56
+ * navigation, only that the current index changed.
57
+ *
58
+ * Note: This is the default action for newly created history objects.
59
+ */
60
+ Action["Pop"] = "POP";
61
+ /**
62
+ * A PUSH indicates a new entry being added to the history stack, such as when
63
+ * a link is clicked and a new page loads. When this happens, all subsequent
64
+ * entries in the stack are lost.
65
+ */
66
+
67
+ Action["Push"] = "PUSH";
68
+ /**
69
+ * A REPLACE indicates the entry at the current index in the history stack
70
+ * being replaced by a new one.
71
+ */
72
+
73
+ Action["Replace"] = "REPLACE";
74
+ })(Action || (Action = {}));
75
+
76
+ var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
77
+ return Object.freeze(obj);
78
+ } : function (obj) {
79
+ return obj;
80
+ };
81
+
82
+ function warning$1(cond, message) {
83
+ if (!cond) {
84
+ // eslint-disable-next-line no-console
85
+ if (typeof console !== 'undefined') console.warn(message);
86
+
87
+ try {
88
+ // Welcome to debugging history!
89
+ //
90
+ // This error is thrown as a convenience so you can more easily
91
+ // find the source for a warning that appears in the console by
92
+ // enabling "pause on exceptions" in your JavaScript debugger.
93
+ throw new Error(message); // eslint-disable-next-line no-empty
94
+ } catch (e) {}
95
+ }
96
+ }
97
+
98
+ var BeforeUnloadEventType = 'beforeunload';
99
+ var HashChangeEventType = 'hashchange';
100
+ var PopStateEventType = 'popstate';
101
+ /**
102
+ * Browser history stores the location in regular URLs. This is the standard for
103
+ * most web apps, but it requires some configuration on the server to ensure you
104
+ * serve the same app at multiple URLs.
105
+ *
106
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
107
+ */
108
+
109
+ function createBrowserHistory(options) {
110
+ if (options === void 0) {
111
+ options = {};
112
+ }
113
+
114
+ var _options = options,
115
+ _options$window = _options.window,
116
+ window = _options$window === void 0 ? document.defaultView : _options$window;
117
+ var globalHistory = window.history;
118
+
119
+ function getIndexAndLocation() {
120
+ var _window$location = window.location,
121
+ pathname = _window$location.pathname,
122
+ search = _window$location.search,
123
+ hash = _window$location.hash;
124
+ var state = globalHistory.state || {};
125
+ return [state.idx, readOnly({
126
+ pathname: pathname,
127
+ search: search,
128
+ hash: hash,
129
+ state: state.usr || null,
130
+ key: state.key || 'default'
131
+ })];
132
+ }
133
+
134
+ var blockedPopTx = null;
135
+
136
+ function handlePop() {
137
+ if (blockedPopTx) {
138
+ blockers.call(blockedPopTx);
139
+ blockedPopTx = null;
140
+ } else {
141
+ var nextAction = Action.Pop;
142
+
143
+ var _getIndexAndLocation = getIndexAndLocation(),
144
+ nextIndex = _getIndexAndLocation[0],
145
+ nextLocation = _getIndexAndLocation[1];
146
+
147
+ if (blockers.length) {
148
+ if (nextIndex != null) {
149
+ var delta = index - nextIndex;
150
+
151
+ if (delta) {
152
+ // Revert the POP
153
+ blockedPopTx = {
154
+ action: nextAction,
155
+ location: nextLocation,
156
+ retry: function retry() {
157
+ go(delta * -1);
158
+ }
159
+ };
160
+ go(delta);
161
+ }
162
+ } else {
163
+ // Trying to POP to a location with no index. We did not create
164
+ // this location, so we can't effectively block the navigation.
165
+ process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
166
+ // detail and link to it here so people can understand better what
167
+ // is going on and how to avoid it.
168
+ "You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
169
+ }
170
+ } else {
171
+ applyTx(nextAction);
172
+ }
173
+ }
174
+ }
175
+
176
+ window.addEventListener(PopStateEventType, handlePop);
177
+ var action = Action.Pop;
178
+
179
+ var _getIndexAndLocation2 = getIndexAndLocation(),
180
+ index = _getIndexAndLocation2[0],
181
+ location = _getIndexAndLocation2[1];
182
+
183
+ var listeners = createEvents();
184
+ var blockers = createEvents();
185
+
186
+ if (index == null) {
187
+ index = 0;
188
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
189
+ idx: index
190
+ }), '');
191
+ }
192
+
193
+ function createHref(to) {
194
+ return typeof to === 'string' ? to : createPath(to);
195
+ } // state defaults to `null` because `window.history.state` does
196
+
197
+
198
+ function getNextLocation(to, state) {
199
+ if (state === void 0) {
200
+ state = null;
201
+ }
202
+
203
+ return readOnly(_extends({
204
+ pathname: location.pathname,
205
+ hash: '',
206
+ search: ''
207
+ }, typeof to === 'string' ? parsePath(to) : to, {
208
+ state: state,
209
+ key: createKey()
210
+ }));
211
+ }
212
+
213
+ function getHistoryStateAndUrl(nextLocation, index) {
214
+ return [{
215
+ usr: nextLocation.state,
216
+ key: nextLocation.key,
217
+ idx: index
218
+ }, createHref(nextLocation)];
219
+ }
220
+
221
+ function allowTx(action, location, retry) {
222
+ return !blockers.length || (blockers.call({
223
+ action: action,
224
+ location: location,
225
+ retry: retry
226
+ }), false);
227
+ }
228
+
229
+ function applyTx(nextAction) {
230
+ action = nextAction;
231
+
232
+ var _getIndexAndLocation3 = getIndexAndLocation();
233
+
234
+ index = _getIndexAndLocation3[0];
235
+ location = _getIndexAndLocation3[1];
236
+ listeners.call({
237
+ action: action,
238
+ location: location
239
+ });
240
+ }
241
+
242
+ function push(to, state) {
243
+ var nextAction = Action.Push;
244
+ var nextLocation = getNextLocation(to, state);
245
+
246
+ function retry() {
247
+ push(to, state);
248
+ }
249
+
250
+ if (allowTx(nextAction, nextLocation, retry)) {
251
+ var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
252
+ historyState = _getHistoryStateAndUr[0],
253
+ url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
254
+ // try...catch because iOS limits us to 100 pushState calls :/
255
+
256
+
257
+ try {
258
+ globalHistory.pushState(historyState, '', url);
259
+ } catch (error) {
260
+ // They are going to lose state here, but there is no real
261
+ // way to warn them about it since the page will refresh...
262
+ window.location.assign(url);
263
+ }
264
+
265
+ applyTx(nextAction);
266
+ }
267
+ }
268
+
269
+ function replace(to, state) {
270
+ var nextAction = Action.Replace;
271
+ var nextLocation = getNextLocation(to, state);
272
+
273
+ function retry() {
274
+ replace(to, state);
275
+ }
276
+
277
+ if (allowTx(nextAction, nextLocation, retry)) {
278
+ var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
279
+ historyState = _getHistoryStateAndUr2[0],
280
+ url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
281
+
282
+
283
+ globalHistory.replaceState(historyState, '', url);
284
+ applyTx(nextAction);
285
+ }
286
+ }
287
+
288
+ function go(delta) {
289
+ globalHistory.go(delta);
290
+ }
291
+
292
+ var history = {
293
+ get action() {
294
+ return action;
295
+ },
296
+
297
+ get location() {
298
+ return location;
299
+ },
300
+
301
+ createHref: createHref,
302
+ push: push,
303
+ replace: replace,
304
+ go: go,
305
+ back: function back() {
306
+ go(-1);
307
+ },
308
+ forward: function forward() {
309
+ go(1);
310
+ },
311
+ listen: function listen(listener) {
312
+ return listeners.push(listener);
313
+ },
314
+ block: function block(blocker) {
315
+ var unblock = blockers.push(blocker);
316
+
317
+ if (blockers.length === 1) {
318
+ window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
319
+ }
320
+
321
+ return function () {
322
+ unblock(); // Remove the beforeunload listener so the document may
323
+ // still be salvageable in the pagehide event.
324
+ // See https://html.spec.whatwg.org/#unloading-documents
325
+
326
+ if (!blockers.length) {
327
+ window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
328
+ }
329
+ };
330
+ }
331
+ };
332
+ return history;
333
+ }
334
+ /**
335
+ * Hash history stores the location in window.location.hash. This makes it ideal
336
+ * for situations where you don't want to send the location to the server for
337
+ * some reason, either because you do cannot configure it or the URL space is
338
+ * reserved for something else.
339
+ *
340
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
341
+ */
342
+
343
+ function createHashHistory(options) {
344
+ if (options === void 0) {
345
+ options = {};
346
+ }
347
+
348
+ var _options2 = options,
349
+ _options2$window = _options2.window,
350
+ window = _options2$window === void 0 ? document.defaultView : _options2$window;
351
+ var globalHistory = window.history;
352
+
353
+ function getIndexAndLocation() {
354
+ var _parsePath = parsePath(window.location.hash.substr(1)),
355
+ _parsePath$pathname = _parsePath.pathname,
356
+ pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
357
+ _parsePath$search = _parsePath.search,
358
+ search = _parsePath$search === void 0 ? '' : _parsePath$search,
359
+ _parsePath$hash = _parsePath.hash,
360
+ hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
361
+
362
+ var state = globalHistory.state || {};
363
+ return [state.idx, readOnly({
364
+ pathname: pathname,
365
+ search: search,
366
+ hash: hash,
367
+ state: state.usr || null,
368
+ key: state.key || 'default'
369
+ })];
370
+ }
371
+
372
+ var blockedPopTx = null;
373
+
374
+ function handlePop() {
375
+ if (blockedPopTx) {
376
+ blockers.call(blockedPopTx);
377
+ blockedPopTx = null;
378
+ } else {
379
+ var nextAction = Action.Pop;
380
+
381
+ var _getIndexAndLocation4 = getIndexAndLocation(),
382
+ nextIndex = _getIndexAndLocation4[0],
383
+ nextLocation = _getIndexAndLocation4[1];
384
+
385
+ if (blockers.length) {
386
+ if (nextIndex != null) {
387
+ var delta = index - nextIndex;
388
+
389
+ if (delta) {
390
+ // Revert the POP
391
+ blockedPopTx = {
392
+ action: nextAction,
393
+ location: nextLocation,
394
+ retry: function retry() {
395
+ go(delta * -1);
396
+ }
397
+ };
398
+ go(delta);
399
+ }
400
+ } else {
401
+ // Trying to POP to a location with no index. We did not create
402
+ // this location, so we can't effectively block the navigation.
403
+ process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
404
+ // detail and link to it here so people can understand better
405
+ // what is going on and how to avoid it.
406
+ "You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
407
+ }
408
+ } else {
409
+ applyTx(nextAction);
410
+ }
411
+ }
412
+ }
413
+
414
+ window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
415
+ // https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
416
+
417
+ window.addEventListener(HashChangeEventType, function () {
418
+ var _getIndexAndLocation5 = getIndexAndLocation(),
419
+ nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
420
+
421
+
422
+ if (createPath(nextLocation) !== createPath(location)) {
423
+ handlePop();
424
+ }
425
+ });
426
+ var action = Action.Pop;
427
+
428
+ var _getIndexAndLocation6 = getIndexAndLocation(),
429
+ index = _getIndexAndLocation6[0],
430
+ location = _getIndexAndLocation6[1];
431
+
432
+ var listeners = createEvents();
433
+ var blockers = createEvents();
434
+
435
+ if (index == null) {
436
+ index = 0;
437
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
438
+ idx: index
439
+ }), '');
440
+ }
441
+
442
+ function getBaseHref() {
443
+ var base = document.querySelector('base');
444
+ var href = '';
445
+
446
+ if (base && base.getAttribute('href')) {
447
+ var url = window.location.href;
448
+ var hashIndex = url.indexOf('#');
449
+ href = hashIndex === -1 ? url : url.slice(0, hashIndex);
450
+ }
451
+
452
+ return href;
453
+ }
454
+
455
+ function createHref(to) {
456
+ return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
457
+ }
458
+
459
+ function getNextLocation(to, state) {
460
+ if (state === void 0) {
461
+ state = null;
462
+ }
463
+
464
+ return readOnly(_extends({
465
+ pathname: location.pathname,
466
+ hash: '',
467
+ search: ''
468
+ }, typeof to === 'string' ? parsePath(to) : to, {
469
+ state: state,
470
+ key: createKey()
471
+ }));
472
+ }
473
+
474
+ function getHistoryStateAndUrl(nextLocation, index) {
475
+ return [{
476
+ usr: nextLocation.state,
477
+ key: nextLocation.key,
478
+ idx: index
479
+ }, createHref(nextLocation)];
480
+ }
481
+
482
+ function allowTx(action, location, retry) {
483
+ return !blockers.length || (blockers.call({
484
+ action: action,
485
+ location: location,
486
+ retry: retry
487
+ }), false);
488
+ }
489
+
490
+ function applyTx(nextAction) {
491
+ action = nextAction;
492
+
493
+ var _getIndexAndLocation7 = getIndexAndLocation();
494
+
495
+ index = _getIndexAndLocation7[0];
496
+ location = _getIndexAndLocation7[1];
497
+ listeners.call({
498
+ action: action,
499
+ location: location
500
+ });
501
+ }
502
+
503
+ function push(to, state) {
504
+ var nextAction = Action.Push;
505
+ var nextLocation = getNextLocation(to, state);
506
+
507
+ function retry() {
508
+ push(to, state);
509
+ }
510
+
511
+ process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
512
+
513
+ if (allowTx(nextAction, nextLocation, retry)) {
514
+ var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
515
+ historyState = _getHistoryStateAndUr3[0],
516
+ url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
517
+ // try...catch because iOS limits us to 100 pushState calls :/
518
+
519
+
520
+ try {
521
+ globalHistory.pushState(historyState, '', url);
522
+ } catch (error) {
523
+ // They are going to lose state here, but there is no real
524
+ // way to warn them about it since the page will refresh...
525
+ window.location.assign(url);
526
+ }
527
+
528
+ applyTx(nextAction);
529
+ }
530
+ }
531
+
532
+ function replace(to, state) {
533
+ var nextAction = Action.Replace;
534
+ var nextLocation = getNextLocation(to, state);
535
+
536
+ function retry() {
537
+ replace(to, state);
538
+ }
539
+
540
+ process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
541
+
542
+ if (allowTx(nextAction, nextLocation, retry)) {
543
+ var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
544
+ historyState = _getHistoryStateAndUr4[0],
545
+ url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
546
+
547
+
548
+ globalHistory.replaceState(historyState, '', url);
549
+ applyTx(nextAction);
550
+ }
551
+ }
552
+
553
+ function go(delta) {
554
+ globalHistory.go(delta);
555
+ }
556
+
557
+ var history = {
558
+ get action() {
559
+ return action;
560
+ },
561
+
562
+ get location() {
563
+ return location;
564
+ },
565
+
566
+ createHref: createHref,
567
+ push: push,
568
+ replace: replace,
569
+ go: go,
570
+ back: function back() {
571
+ go(-1);
572
+ },
573
+ forward: function forward() {
574
+ go(1);
575
+ },
576
+ listen: function listen(listener) {
577
+ return listeners.push(listener);
578
+ },
579
+ block: function block(blocker) {
580
+ var unblock = blockers.push(blocker);
581
+
582
+ if (blockers.length === 1) {
583
+ window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
584
+ }
585
+
586
+ return function () {
587
+ unblock(); // Remove the beforeunload listener so the document may
588
+ // still be salvageable in the pagehide event.
589
+ // See https://html.spec.whatwg.org/#unloading-documents
590
+
591
+ if (!blockers.length) {
592
+ window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
593
+ }
594
+ };
595
+ }
596
+ };
597
+ return history;
598
+ }
599
+ /**
600
+ * Memory history stores the current location in memory. It is designed for use
601
+ * in stateful non-browser environments like tests and React Native.
602
+ *
603
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
604
+ */
605
+
606
+ function createMemoryHistory(options) {
607
+ if (options === void 0) {
608
+ options = {};
609
+ }
610
+
611
+ var _options3 = options,
612
+ _options3$initialEntr = _options3.initialEntries,
613
+ initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
614
+ initialIndex = _options3.initialIndex;
615
+ var entries = initialEntries.map(function (entry) {
616
+ var location = readOnly(_extends({
617
+ pathname: '/',
618
+ search: '',
619
+ hash: '',
620
+ state: null,
621
+ key: createKey()
622
+ }, typeof entry === 'string' ? parsePath(entry) : entry));
623
+ process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") : void 0;
624
+ return location;
625
+ });
626
+ var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
627
+ var action = Action.Pop;
628
+ var location = entries[index];
629
+ var listeners = createEvents();
630
+ var blockers = createEvents();
631
+
632
+ function createHref(to) {
633
+ return typeof to === 'string' ? to : createPath(to);
634
+ }
635
+
636
+ function getNextLocation(to, state) {
637
+ if (state === void 0) {
638
+ state = null;
639
+ }
640
+
641
+ return readOnly(_extends({
642
+ pathname: location.pathname,
643
+ search: '',
644
+ hash: ''
645
+ }, typeof to === 'string' ? parsePath(to) : to, {
646
+ state: state,
647
+ key: createKey()
648
+ }));
649
+ }
650
+
651
+ function allowTx(action, location, retry) {
652
+ return !blockers.length || (blockers.call({
653
+ action: action,
654
+ location: location,
655
+ retry: retry
656
+ }), false);
657
+ }
658
+
659
+ function applyTx(nextAction, nextLocation) {
660
+ action = nextAction;
661
+ location = nextLocation;
662
+ listeners.call({
663
+ action: action,
664
+ location: location
665
+ });
666
+ }
667
+
668
+ function push(to, state) {
669
+ var nextAction = Action.Push;
670
+ var nextLocation = getNextLocation(to, state);
671
+
672
+ function retry() {
673
+ push(to, state);
674
+ }
675
+
676
+ process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") : void 0;
677
+
678
+ if (allowTx(nextAction, nextLocation, retry)) {
679
+ index += 1;
680
+ entries.splice(index, entries.length, nextLocation);
681
+ applyTx(nextAction, nextLocation);
682
+ }
683
+ }
684
+
685
+ function replace(to, state) {
686
+ var nextAction = Action.Replace;
687
+ var nextLocation = getNextLocation(to, state);
688
+
689
+ function retry() {
690
+ replace(to, state);
691
+ }
692
+
693
+ process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") : void 0;
694
+
695
+ if (allowTx(nextAction, nextLocation, retry)) {
696
+ entries[index] = nextLocation;
697
+ applyTx(nextAction, nextLocation);
698
+ }
699
+ }
700
+
701
+ function go(delta) {
702
+ var nextIndex = clamp(index + delta, 0, entries.length - 1);
703
+ var nextAction = Action.Pop;
704
+ var nextLocation = entries[nextIndex];
705
+
706
+ function retry() {
707
+ go(delta);
708
+ }
709
+
710
+ if (allowTx(nextAction, nextLocation, retry)) {
711
+ index = nextIndex;
712
+ applyTx(nextAction, nextLocation);
713
+ }
714
+ }
715
+
716
+ var history = {
717
+ get index() {
718
+ return index;
719
+ },
720
+
721
+ get action() {
722
+ return action;
723
+ },
724
+
725
+ get location() {
726
+ return location;
727
+ },
728
+
729
+ createHref: createHref,
730
+ push: push,
731
+ replace: replace,
732
+ go: go,
733
+ back: function back() {
734
+ go(-1);
735
+ },
736
+ forward: function forward() {
737
+ go(1);
738
+ },
739
+ listen: function listen(listener) {
740
+ return listeners.push(listener);
741
+ },
742
+ block: function block(blocker) {
743
+ return blockers.push(blocker);
744
+ }
745
+ };
746
+ return history;
747
+ } ////////////////////////////////////////////////////////////////////////////////
748
+ // UTILS
749
+ ////////////////////////////////////////////////////////////////////////////////
750
+
751
+ function clamp(n, lowerBound, upperBound) {
752
+ return Math.min(Math.max(n, lowerBound), upperBound);
753
+ }
754
+
755
+ function promptBeforeUnload(event) {
756
+ // Cancel the event.
757
+ event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
758
+
759
+ event.returnValue = '';
760
+ }
761
+
762
+ function createEvents() {
763
+ var handlers = [];
764
+ return {
765
+ get length() {
766
+ return handlers.length;
767
+ },
768
+
769
+ push: function push(fn) {
770
+ handlers.push(fn);
771
+ return function () {
772
+ handlers = handlers.filter(function (handler) {
773
+ return handler !== fn;
774
+ });
775
+ };
776
+ },
777
+ call: function call(arg) {
778
+ handlers.forEach(function (fn) {
779
+ return fn && fn(arg);
780
+ });
781
+ }
782
+ };
783
+ }
784
+
785
+ function createKey() {
786
+ return Math.random().toString(36).substr(2, 8);
787
+ }
788
+ /**
789
+ * Creates a string URL path from the given pathname, search, and hash components.
790
+ *
791
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
792
+ */
793
+
794
+
795
+ function createPath(_ref) {
796
+ var _ref$pathname = _ref.pathname,
797
+ pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
798
+ _ref$search = _ref.search,
799
+ search = _ref$search === void 0 ? '' : _ref$search,
800
+ _ref$hash = _ref.hash,
801
+ hash = _ref$hash === void 0 ? '' : _ref$hash;
802
+ if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
803
+ if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
804
+ return pathname;
805
+ }
806
+ /**
807
+ * Parses a string URL path into its separate pathname, search, and hash components.
808
+ *
809
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
810
+ */
811
+
812
+ function parsePath(path) {
813
+ var parsedPath = {};
814
+
815
+ if (path) {
816
+ var hashIndex = path.indexOf('#');
817
+
818
+ if (hashIndex >= 0) {
819
+ parsedPath.hash = path.substr(hashIndex);
820
+ path = path.substr(0, hashIndex);
821
+ }
822
+
823
+ var searchIndex = path.indexOf('?');
824
+
825
+ if (searchIndex >= 0) {
826
+ parsedPath.search = path.substr(searchIndex);
827
+ path = path.substr(0, searchIndex);
828
+ }
829
+
830
+ if (path) {
831
+ parsedPath.pathname = path;
832
+ }
833
+ }
834
+
835
+ return parsedPath;
836
+ }
837
+
838
+ // @ts-nocheck
839
+ // We're inlining qss here for compression's sake, but we've included it as a hard dependency for the MIT license it requires.
840
+ function encode(obj, pfx) {
841
+ var k,
842
+ i,
843
+ tmp,
844
+ str = '';
845
+
846
+ for (k in obj) {
847
+ if ((tmp = obj[k]) !== void 0) {
848
+ if (Array.isArray(tmp)) {
849
+ for (i = 0; i < tmp.length; i++) {
850
+ str && (str += '&');
851
+ str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
852
+ }
853
+ } else {
854
+ str && (str += '&');
855
+ str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
856
+ }
857
+ }
858
+ }
859
+
860
+ return (pfx || '') + str;
861
+ }
862
+
863
+ function toValue(mix) {
864
+ if (!mix) return '';
865
+ var str = decodeURIComponent(mix);
866
+ if (str === 'false') return false;
867
+ if (str === 'true') return true;
868
+ return +str * 0 === 0 ? +str : str;
869
+ }
870
+
871
+ function decode(str) {
872
+ var tmp,
873
+ k,
874
+ out = {},
875
+ arr = str.split('&');
876
+
877
+ while (tmp = arr.shift()) {
878
+ tmp = tmp.split('=');
879
+ k = tmp.shift();
880
+
881
+ if (out[k] !== void 0) {
882
+ out[k] = [].concat(out[k], toValue(tmp.shift()));
883
+ } else {
884
+ out[k] = toValue(tmp.shift());
885
+ }
886
+ }
887
+
888
+ return out;
889
+ }
890
+
891
+ const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
892
+ if (options === void 0) {
893
+ options = {};
894
+ }
895
+
896
+ if (isRoot === void 0) {
897
+ isRoot = true;
898
+ }
899
+
900
+ if (isRoot) {
901
+ options.path = rootRouteId;
902
+ } else {
903
+ warning(!options.path, 'Routes must have a path property.');
904
+ } // Strip the root from parentIds
905
+
906
+
907
+ if (parentId === rootRouteId) {
908
+ parentId = '';
909
+ }
910
+
911
+ let path = String(isRoot ? rootRouteId : options.path); // If the path is anything other than an index path, trim it up
912
+
913
+ if (path !== '/') {
914
+ path = trimPath(path);
915
+ }
916
+
917
+ let id = joinPaths([parentId, path]);
918
+
919
+ if (path === rootRouteId) {
920
+ path = '/';
921
+ }
922
+
923
+ if (id !== rootRouteId) {
924
+ id = joinPaths(['/', id]);
925
+ }
926
+
927
+ const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
928
+ return {
929
+ id: id,
930
+ path: path,
931
+ fullPath: fullPath,
932
+ options: options,
933
+ children,
934
+ addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
935
+ };
936
+ };
937
+ const rootRouteId = '__root__';
938
+ // Source
939
+ // Detect if we're in the DOM
940
+ const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement); // This is the default history object if none is defined
941
+
942
+ const createDefaultHistory = () => isDOM ? createBrowserHistory() : createMemoryHistory();
943
+
944
+ function createRouter(userOptions) {
945
+ var _userOptions$stringif, _userOptions$parseSea;
946
+
947
+ const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
948
+
949
+ const originalOptions = _extends$1({}, userOptions, {
950
+ stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
951
+ parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
952
+ });
953
+
954
+ let router = {
955
+ options: originalOptions,
956
+ listeners: [],
957
+ // Resolved after construction
958
+ basepath: '',
959
+ routeTree: undefined,
960
+ routesById: {},
961
+ location: undefined,
962
+ allRouteInfo: undefined,
963
+ //
964
+ navigationPromise: Promise.resolve(),
965
+ resolveNavigation: () => {},
966
+ preloadCache: {},
967
+ state: {
968
+ status: 'idle',
969
+ location: null,
970
+ matches: [],
971
+ actions: {},
972
+ loaderData: {},
973
+ lastUpdated: Date.now()
974
+ },
975
+ startedLoadingAt: Date.now(),
976
+ subscribe: listener => {
977
+ router.listeners.push(listener);
978
+ return () => {
979
+ router.listeners = router.listeners.filter(x => x !== listener);
980
+ };
981
+ },
982
+ getRoute: id => {
983
+ return router.routesById[id];
984
+ },
985
+ notify: () => {
986
+ router.state = _extends$1({}, router.state);
987
+ router.listeners.forEach(listener => listener());
988
+ },
989
+ mount: () => {
990
+ const next = router.buildLocation({
991
+ to: '.',
992
+ search: true,
993
+ hash: true
994
+ }); // If the current location isn't updated, trigger a navigation
995
+ // to the current location. Otherwise, load the current location.
996
+
997
+ if (next.href !== router.location.href) {
998
+ return router.commitLocation(next, true);
999
+ } else {
1000
+ return router.loadLocation();
1001
+ }
1002
+ },
1003
+ update: opts => {
1004
+ Object.assign(router.options, opts);
1005
+ const {
1006
+ basepath,
1007
+ routeConfig
1008
+ } = router.options;
1009
+ router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
1010
+
1011
+ if (routeConfig) {
1012
+ router.routesById = {};
1013
+ router.routeTree = router.buildRouteTree(routeConfig);
1014
+ }
1015
+
1016
+ return router;
1017
+ },
1018
+ destroy: history.listen(event => {
1019
+ router.loadLocation(router.parseLocation(event.location, router.location));
1020
+ }),
1021
+ buildRouteTree: rootRouteConfig => {
1022
+ const recurseRoutes = (routeConfigs, parent) => {
1023
+ return routeConfigs.map(routeConfig => {
1024
+ const routeOptions = routeConfig.options;
1025
+ const route = createRoute(routeConfig, routeOptions, parent, router); // {
1026
+ // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
1027
+ // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
1028
+ // }
1029
+
1030
+ const existingRoute = router.routesById[route.routeId];
1031
+
1032
+ if (existingRoute) {
1033
+ if (process.env.NODE_ENV !== 'production') {
1034
+ console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
1035
+ }
1036
+
1037
+ throw new Error();
1038
+ }
1039
+ router.routesById[route.routeId] = route;
1040
+ const children = routeConfig.children;
1041
+ route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
1042
+ return route;
1043
+ });
1044
+ };
1045
+
1046
+ const routes = recurseRoutes([rootRouteConfig]);
1047
+ return routes[0];
1048
+ },
1049
+ parseLocation: (location, previousLocation) => {
1050
+ var _location$hash$split$;
1051
+
1052
+ const parsedSearch = router.options.parseSearch(location.search);
1053
+ return {
1054
+ pathname: location.pathname,
1055
+ searchStr: location.search,
1056
+ search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
1057
+ hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
1058
+ href: "" + location.pathname + location.search + location.hash,
1059
+ state: location.state,
1060
+ key: location.key
1061
+ };
1062
+ },
1063
+ buildLocation: function buildLocation(dest) {
1064
+ var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
1065
+
1066
+ if (dest === void 0) {
1067
+ dest = {};
1068
+ }
1069
+
1070
+ // const resolvedFrom: Location = {
1071
+ // ...router.location,
1072
+ const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
1073
+
1074
+ let pathname = _resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
1075
+
1076
+ const fromMatches = router.matchRoutes(router.location.pathname, {
1077
+ strictParseParams: true
1078
+ });
1079
+ const toMatches = router.matchRoutes(pathname);
1080
+ const prevParams = (_last = last(fromMatches)) == null ? void 0 : _last.params;
1081
+ let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
1082
+
1083
+ if (nextParams) {
1084
+ toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
1085
+ Object.assign(nextParams, fn(nextParams));
1086
+ });
1087
+ }
1088
+
1089
+ pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
1090
+
1091
+ 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
1092
+
1093
+ const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
1094
+ : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
1095
+ : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
1096
+ : {}; // Then post filters
1097
+
1098
+ const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
1099
+ const search = replaceEqualDeep(router.location.search, postFilteredSearch);
1100
+ const searchStr = router.options.stringifySearch(search);
1101
+ let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
1102
+ hash = hash ? "#" + hash : '';
1103
+ return {
1104
+ pathname,
1105
+ search,
1106
+ searchStr,
1107
+ state: router.location.state,
1108
+ hash,
1109
+ href: "" + pathname + searchStr + hash,
1110
+ key: dest.key
1111
+ };
1112
+ },
1113
+ commitLocation: (next, replace) => {
1114
+ const id = '' + Date.now() + Math.random();
1115
+ if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
1116
+ let nextAction = 'replace';
1117
+
1118
+ if (!replace) {
1119
+ nextAction = 'push';
1120
+ }
1121
+
1122
+ const isSameUrl = router.parseLocation(history.location).href === next.href;
1123
+
1124
+ if (isSameUrl && !next.key) {
1125
+ nextAction = 'replace';
1126
+ }
1127
+
1128
+ if (nextAction === 'replace') {
1129
+ history.replace({
1130
+ pathname: next.pathname,
1131
+ hash: next.hash,
1132
+ search: next.searchStr
1133
+ }, {
1134
+ id
1135
+ });
1136
+ } else {
1137
+ history.push({
1138
+ pathname: next.pathname,
1139
+ hash: next.hash,
1140
+ search: next.searchStr
1141
+ }, {
1142
+ id
1143
+ });
1144
+ }
1145
+
1146
+ router.navigationPromise = new Promise(resolve => {
1147
+ const previousNavigationResolve = router.resolveNavigation;
1148
+
1149
+ router.resolveNavigation = () => {
1150
+ previousNavigationResolve();
1151
+ resolve();
1152
+ };
1153
+ });
1154
+ return router.navigationPromise;
1155
+ },
1156
+ buildNext: opts => {
1157
+ const next = router.buildLocation(opts);
1158
+ const matches = router.matchRoutes(next.pathname);
1159
+
1160
+ const __preSearchFilters = matches.map(match => {
1161
+ var _match$options$preSea;
1162
+
1163
+ return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
1164
+ }).flat().filter(Boolean);
1165
+
1166
+ const __postSearchFilters = matches.map(match => {
1167
+ var _match$options$postSe;
1168
+
1169
+ return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
1170
+ }).flat().filter(Boolean);
1171
+
1172
+ return router.buildLocation(_extends$1({}, opts, {
1173
+ __preSearchFilters,
1174
+ __postSearchFilters
1175
+ }));
1176
+ },
1177
+ cancelMatches: () => {
1178
+ var _router$state$pending, _router$state$pending2;
1179
+ [...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 => {
1180
+ match.cancel();
1181
+ });
1182
+ },
1183
+ loadLocation: async next => {
1184
+ const id = Math.random();
1185
+ router.startedLoadingAt = id;
1186
+
1187
+ if (next) {
1188
+ // Ingest the new location
1189
+ router.location = next;
1190
+ } // Cancel any pending matches
1191
+
1192
+
1193
+ router.cancelMatches(); // Match the routes
1194
+
1195
+ const unloadedMatches = router.matchRoutes(location.pathname, {
1196
+ strictParseParams: true
1197
+ });
1198
+ unloadedMatches.forEach((match, index) => {
1199
+ const parent = unloadedMatches[index - 1];
1200
+ const child = unloadedMatches[index + 1];
1201
+ if (parent) match.__.setParentMatch(parent);
1202
+ if (child) match.__.addChildMatch(child);
1203
+ });
1204
+ router.state = _extends$1({}, router.state, {
1205
+ pending: {
1206
+ matches: unloadedMatches,
1207
+ location: router.location
1208
+ }
1209
+ });
1210
+ router.notify(); // Load the matches
1211
+
1212
+ const matches = await router.loadMatches(unloadedMatches, {
1213
+ withPending: true
1214
+ });
1215
+
1216
+ if (router.startedLoadingAt !== id) {
1217
+ // Ignore side-effects of match loading
1218
+ return router.navigationPromise;
1219
+ }
1220
+
1221
+ const previousMatches = router.state.matches;
1222
+ previousMatches.filter(d => {
1223
+ return !matches.find(dd => dd.matchId === d.matchId);
1224
+ }).forEach(d => {
1225
+ d.__.onExit == null ? void 0 : d.__.onExit({
1226
+ params: d.params,
1227
+ search: d.routeSearch
1228
+ });
1229
+ });
1230
+ previousMatches.filter(d => {
1231
+ return matches.find(dd => dd.matchId === d.matchId);
1232
+ }).forEach(d => {
1233
+ d.options.onTransition == null ? void 0 : d.options.onTransition({
1234
+ params: d.params,
1235
+ search: d.routeSearch
1236
+ });
1237
+ });
1238
+ matches.filter(d => {
1239
+ return !previousMatches.find(dd => dd.matchId === d.matchId);
1240
+ }).forEach(d => {
1241
+ d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1242
+ params: d.params,
1243
+ search: d.search
1244
+ });
1245
+ });
1246
+ router.state = _extends$1({}, router.state, {
1247
+ location: router.location,
1248
+ matches,
1249
+ pending: undefined
1250
+ });
1251
+
1252
+ if (matches.some(d => d.status === 'loading')) {
1253
+ router.notify();
1254
+ await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
1255
+ }
1256
+
1257
+ if (router.startedLoadingAt !== id) {
1258
+ // Ignore side-effects of match loading
1259
+ return;
1260
+ }
1261
+
1262
+ router.notify();
1263
+ router.resolveNavigation();
1264
+ },
1265
+ cleanPreloadCache: () => {
1266
+ const now = Date.now();
1267
+ Object.keys(router.preloadCache).forEach(matchId => {
1268
+ const entry = router.preloadCache[matchId]; // Don't remove loading matches
1269
+
1270
+ if (entry.match.status === 'loading') {
1271
+ return;
1272
+ } // Do not remove successful matches that are still valid
1273
+
1274
+
1275
+ if (entry.match.updatedAt && entry.match.updatedAt + entry.maxAge > now) {
1276
+ return;
1277
+ } // Everything else gets removed
1278
+
1279
+
1280
+ delete router.preloadCache[matchId];
1281
+ });
1282
+ },
1283
+ loadRoute: async function loadRoute(navigateOpts, loaderOpts) {
1284
+ if (navigateOpts === void 0) {
1285
+ navigateOpts = router.location;
1286
+ }
1287
+
1288
+ const next = router.buildNext(navigateOpts);
1289
+ const matches = router.matchRoutes(next.pathname, {
1290
+ strictParseParams: true
1291
+ });
1292
+ await router.loadMatches(matches, {
1293
+ preload: true,
1294
+ maxAge: loaderOpts.maxAge
1295
+ });
1296
+ return matches;
1297
+ },
1298
+ matchRoutes: (pathname, opts) => {
1299
+ var _router$state$pending3, _router$state$pending4;
1300
+
1301
+ router.cleanPreloadCache();
1302
+ const matches = [];
1303
+
1304
+ if (!router.routeTree) {
1305
+ return matches;
1306
+ }
1307
+
1308
+ 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 : [])];
1309
+
1310
+ const recurse = async (routes, parentMatch) => {
1311
+ var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
1312
+
1313
+ let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
1314
+ const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
1315
+ const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
1316
+ var _route$childRoutes, _route$options$caseSe;
1317
+
1318
+ const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
1319
+ const matchParams = matchPathname(pathname, {
1320
+ to: route.fullPath,
1321
+ fuzzy,
1322
+ caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
1323
+ });
1324
+
1325
+ if (matchParams) {
1326
+ let parsedParams;
1327
+
1328
+ try {
1329
+ var _route$options$parseP;
1330
+
1331
+ parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
1332
+ } catch (err) {
1333
+ if (opts != null && opts.strictParseParams) {
1334
+ throw err;
1335
+ }
1336
+ }
1337
+
1338
+ params = _extends$1({}, params, parsedParams);
1339
+ }
1340
+
1341
+ return !!matchParams;
1342
+ });
1343
+
1344
+ if (!route) {
1345
+ return;
1346
+ }
1347
+
1348
+ const interpolatedPath = interpolatePath(route.routePath, params);
1349
+ const matchId = interpolatePath(route.routeId, params, true);
1350
+ const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
1351
+ matchId,
1352
+ params,
1353
+ pathname: joinPaths([pathname, interpolatedPath])
1354
+ });
1355
+ matches.push(match);
1356
+
1357
+ if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
1358
+ recurse(route.childRoutes, match);
1359
+ }
1360
+ };
1361
+
1362
+ recurse([router.routeTree]);
1363
+ return matches;
1364
+ },
1365
+ loadMatches: async (resolvedMatches, loaderOpts) => {
1366
+ const matchPromises = resolvedMatches.map(async match => {
1367
+ // Validate the match (loads search params etc)
1368
+ match.__.validate(); // If this is a preload, add it to the preload cache
1369
+
1370
+
1371
+ if (loaderOpts != null && loaderOpts.preload) {
1372
+ router.preloadCache[match.matchId] = {
1373
+ maxAge: loaderOpts == null ? void 0 : loaderOpts.maxAge,
1374
+ match
1375
+ };
1376
+ } // If the match is invalid, errored or idle, trigger it to load
1377
+
1378
+
1379
+ if (match.status === 'success' && match.isInvalid || match.status === 'error' || match.status === 'idle') {
1380
+ match.load();
1381
+ } // If requested, start the pending timers
1382
+
1383
+
1384
+ if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
1385
+ // This might be completion, error, or a pending state
1386
+
1387
+ await match.__.loadPromise;
1388
+ });
1389
+ router.notify();
1390
+ await Promise.all(matchPromises);
1391
+ return resolvedMatches;
1392
+ },
1393
+ invalidateRoute: opts => {
1394
+ var _router$state$pending5, _router$state$pending6;
1395
+
1396
+ const next = router.buildNext(opts);
1397
+ const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
1398
+ [...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 => {
1399
+ if (unloadedMatchIds.includes(match.matchId)) {
1400
+ match.isInvalid = true;
1401
+ }
1402
+ });
1403
+ },
1404
+ reload: () => router._navigate({
1405
+ fromCurrent: true,
1406
+ replace: true,
1407
+ search: true
1408
+ }),
1409
+ resolvePath: (from, path) => {
1410
+ return _resolvePath(router.basepath, from, cleanPath(path));
1411
+ },
1412
+ matchRoute: (location, opts) => {
1413
+ var _location$from;
1414
+
1415
+ // const location = router.buildNext(opts)
1416
+ location = _extends$1({}, location, {
1417
+ to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
1418
+ });
1419
+ const next = router.buildNext(location);
1420
+
1421
+ if (opts != null && opts.pending) {
1422
+ var _router$state$pending7;
1423
+
1424
+ if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
1425
+ return false;
1426
+ }
1427
+
1428
+ return !!matchPathname(router.state.pending.location.pathname, _extends$1({}, opts, {
1429
+ to: next.pathname
1430
+ }));
1431
+ }
1432
+
1433
+ return !!matchPathname(router.state.location.pathname, _extends$1({}, opts, {
1434
+ to: next.pathname
1435
+ }));
1436
+ },
1437
+ _navigate: location => {
1438
+ const next = router.buildNext(location);
1439
+ return router.commitLocation(next, location.replace);
1440
+ },
1441
+ navigate: async _ref => {
1442
+ let {
1443
+ from,
1444
+ to = '.',
1445
+ search,
1446
+ hash,
1447
+ replace
1448
+ } = _ref;
1449
+ // If this link simply reloads the current route,
1450
+ // make sure it has a new key so it will trigger a data refresh
1451
+ // If this `to` is a valid external URL, return
1452
+ // null for LinkUtils
1453
+ const toString = String(to);
1454
+ const fromString = String(from);
1455
+ let isExternal;
1456
+
1457
+ try {
1458
+ new URL("" + toString);
1459
+ isExternal = true;
1460
+ } catch (e) {}
1461
+
1462
+ if (isExternal) {
1463
+ if (process.env.NODE_ENV !== 'production') {
1464
+ throw new Error('Attempting to navigate to external url with router.navigate!');
1465
+ }
1466
+
1467
+ return;
1468
+ }
1469
+
1470
+ return router._navigate({
1471
+ from: fromString,
1472
+ to: toString,
1473
+ search,
1474
+ hash
1475
+ });
1476
+ },
1477
+ buildLink: _ref2 => {
1478
+ var _preload, _ref3, _ref4;
1479
+
1480
+ let {
1481
+ from,
1482
+ to = '.',
1483
+ search,
1484
+ params,
1485
+ hash,
1486
+ target,
1487
+ replace,
1488
+ activeOptions,
1489
+ preload,
1490
+ preloadMaxAge: userPreloadMaxAge,
1491
+ preloadDelay: userPreloadDelay,
1492
+ disabled
1493
+ } = _ref2;
1494
+
1495
+ // If this link simply reloads the current route,
1496
+ // make sure it has a new key so it will trigger a data refresh
1497
+ // If this `to` is a valid external URL, return
1498
+ // null for LinkUtils
1499
+ try {
1500
+ new URL("" + to);
1501
+ return {
1502
+ type: 'external',
1503
+ href: to
1504
+ };
1505
+ } catch (e) {}
1506
+
1507
+ const nextOpts = {
1508
+ from,
1509
+ to,
1510
+ search,
1511
+ params,
1512
+ hash,
1513
+ replace
1514
+ };
1515
+ const next = router.buildNext(nextOpts);
1516
+ preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
1517
+ const preloadMaxAge = (_ref3 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref3 : 2000;
1518
+ const preloadDelay = (_ref4 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref4 : 50; // Compare path/hash for matches
1519
+
1520
+ const pathIsEqual = router.state.location.pathname === next.pathname;
1521
+ const currentPathSplit = router.state.location.pathname.split('/');
1522
+ const nextPathSplit = next.pathname.split('/');
1523
+ const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
1524
+ const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
1525
+
1526
+ const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
1527
+ const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
1528
+
1529
+ const isActive = pathTest && hashTest; // The click handler
1530
+
1531
+ const handleClick = e => {
1532
+ if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
1533
+ e.preventDefault();
1534
+
1535
+ if (pathIsEqual && !search && !hash) {
1536
+ router.invalidateRoute(nextOpts);
1537
+ } // All is well? Navigate!)
1538
+
1539
+
1540
+ router._navigate(nextOpts);
1541
+ }
1542
+ }; // The click handler
1543
+
1544
+
1545
+ const handleFocus = e => {
1546
+ if (preload && preloadMaxAge > 0) {
1547
+ router.loadRoute(nextOpts, {
1548
+ maxAge: preloadMaxAge
1549
+ });
1550
+ }
1551
+ };
1552
+
1553
+ const handleEnter = e => {
1554
+ const target = e.target || {};
1555
+
1556
+ if (preload && preloadMaxAge > 0) {
1557
+ if (target.preloadTimeout) {
1558
+ return;
1559
+ }
1560
+
1561
+ target.preloadTimeout = setTimeout(() => {
1562
+ target.preloadTimeout = null;
1563
+ router.loadRoute(nextOpts, {
1564
+ maxAge: preloadMaxAge
1565
+ });
1566
+ }, preloadDelay);
1567
+ }
1568
+ };
1569
+
1570
+ const handleLeave = e => {
1571
+ const target = e.target || {};
1572
+
1573
+ if (target.preloadTimeout) {
1574
+ clearTimeout(target.preloadTimeout);
1575
+ target.preloadTimeout = null;
1576
+ }
1577
+ };
1578
+
1579
+ return {
1580
+ type: 'internal',
1581
+ next,
1582
+ handleFocus,
1583
+ handleClick,
1584
+ handleEnter,
1585
+ handleLeave,
1586
+ isActive,
1587
+ disabled
1588
+ };
1589
+ },
1590
+ __experimental__createSnapshot: () => {
1591
+ return _extends$1({}, router.state, {
1592
+ matches: router.state.matches.map(_ref5 => {
1593
+ let {
1594
+ routeLoaderData: loaderData,
1595
+ matchId
1596
+ } = _ref5;
1597
+ return {
1598
+ matchId,
1599
+ loaderData
1600
+ };
1601
+ })
1602
+ });
1603
+ }
1604
+ };
1605
+ router.location = router.parseLocation(history.location); // router.state.location = __experimental__snapshot?.location ?? router.location
1606
+
1607
+ router.state.location = router.location;
1608
+ router.update(userOptions); // Allow frameworks to hook into the router creation
1609
+
1610
+ router.options.createRouter == null ? void 0 : router.options.createRouter(router); // router.mount()
1611
+
1612
+ return router;
1613
+ }
1614
+ function createRoute(routeConfig, options, parent, router) {
1615
+ // const id = (
1616
+ // options.path === rootRouteId
1617
+ // ? rootRouteId
1618
+ // : joinPaths([
1619
+ // parent!.id,
1620
+ // `${options.path?.replace(/(.)\/$/, '$1')}`,
1621
+ // ]).replace(new RegExp(`^${rootRouteId}`), '')
1622
+ // ) as TRouteInfo['id']
1623
+ const {
1624
+ id: routeId,
1625
+ path: routePath,
1626
+ fullPath
1627
+ } = routeConfig;
1628
+
1629
+ const action = router.state.actions[routeId] || (() => {
1630
+ router.state.actions[routeId] = {
1631
+ pending: [],
1632
+ submit: async (submission, actionOpts) => {
1633
+ var _actionOpts$invalidat;
1634
+
1635
+ if (!route) {
1636
+ return;
1637
+ }
1638
+
1639
+ const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1640
+ const actionState = {
1641
+ submittedAt: Date.now(),
1642
+ status: 'pending',
1643
+ submission
1644
+ };
1645
+ action.latest = actionState;
1646
+ action.pending.push(actionState);
1647
+ router.state = _extends$1({}, router.state, {
1648
+ action: actionState
1649
+ });
1650
+ router.notify();
1651
+
1652
+ try {
1653
+ const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1654
+ actionState.data = res;
1655
+
1656
+ if (invalidate) {
1657
+ router.invalidateRoute({
1658
+ to: '.',
1659
+ fromCurrent: true
1660
+ });
1661
+ await router.reload();
1662
+ }
1663
+
1664
+ actionState.status = 'success';
1665
+ return res;
1666
+ } catch (err) {
1667
+ console.error(err);
1668
+ actionState.error = err;
1669
+ actionState.status = 'error';
1670
+ } finally {
1671
+ action.pending = action.pending.filter(d => d !== actionState);
1672
+
1673
+ if (actionState === router.state.action) {
1674
+ router.state.action = undefined;
1675
+ }
1676
+
1677
+ router.notify();
1678
+ }
1679
+ }
1680
+ };
1681
+ return router.state.actions[routeId];
1682
+ })();
1683
+
1684
+ let route = {
1685
+ routeId,
1686
+ routePath,
1687
+ fullPath,
1688
+ options,
1689
+ router,
1690
+ childRoutes: undefined,
1691
+ parentRoute: parent,
1692
+ action,
1693
+ buildLink: options => {
1694
+ return router.buildLink(_extends$1({}, options, {
1695
+ from: fullPath
1696
+ }));
1697
+ },
1698
+ navigate: options => {
1699
+ return router.navigate(_extends$1({}, options, {
1700
+ from: fullPath
1701
+ }));
1702
+ },
1703
+ matchRoute: (matchLocation, opts) => {
1704
+ return router.matchRoute(_extends$1({}, matchLocation, {
1705
+ from: fullPath
1706
+ }), opts);
1707
+ }
1708
+ };
1709
+ router.options.createRoute == null ? void 0 : router.options.createRoute({
1710
+ router,
1711
+ route
1712
+ });
1713
+ return route;
1714
+ }
1715
+ function createRouteMatch(router, route, opts) {
1716
+ const routeMatch = _extends$1({}, route, opts, {
1717
+ router,
1718
+ routeSearch: {},
1719
+ search: {},
1720
+ childMatches: [],
1721
+ status: 'idle',
1722
+ routeLoaderData: {},
1723
+ loaderData: {},
1724
+ isPending: false,
1725
+ isFetching: false,
1726
+ isInvalid: false,
1727
+ __: {
1728
+ abortController: new AbortController(),
1729
+ latestId: '',
1730
+ resolve: () => {},
1731
+ notify: () => {
1732
+ routeMatch.__.resolve();
1733
+
1734
+ routeMatch.router.notify();
1735
+ },
1736
+ startPending: () => {
1737
+ var _routeMatch$options$p, _routeMatch$options$p2;
1738
+
1739
+ const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
1740
+ const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
1741
+
1742
+ if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
1743
+ return;
1744
+ }
1745
+
1746
+ routeMatch.__.pendingTimeout = setTimeout(() => {
1747
+ routeMatch.isPending = true;
1748
+
1749
+ routeMatch.__.resolve();
1750
+
1751
+ if (typeof pendingMinMs !== 'undefined') {
1752
+ routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
1753
+ }
1754
+ }, pendingMs);
1755
+ },
1756
+ cancelPending: () => {
1757
+ routeMatch.isPending = false;
1758
+ clearTimeout(routeMatch.__.pendingTimeout);
1759
+ clearTimeout(routeMatch.__.pendingMinTimeout);
1760
+ delete routeMatch.__.pendingMinPromise;
1761
+ },
1762
+ setParentMatch: parentMatch => {
1763
+ routeMatch.parentMatch = parentMatch;
1764
+ },
1765
+ addChildMatch: childMatch => {
1766
+ if (routeMatch.childMatches.find(d => d.matchId === childMatch.matchId)) {
1767
+ return;
1768
+ }
1769
+
1770
+ routeMatch.childMatches.push(childMatch);
1771
+ },
1772
+ validate: () => {
1773
+ var _routeMatch$parentMat, _routeMatch$parentMat2;
1774
+
1775
+ // Validate the search params and stabilize them
1776
+ const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1777
+
1778
+ try {
1779
+ const prevSearch = routeMatch.routeSearch;
1780
+ let nextSearch = replaceEqualDeep(prevSearch, routeMatch.options.validateSearch == null ? void 0 : routeMatch.options.validateSearch(parentSearch)); // Invalidate route matches when search param stability changes
1781
+
1782
+ if (prevSearch !== nextSearch) {
1783
+ routeMatch.isInvalid = true;
1784
+ }
1785
+
1786
+ routeMatch.routeSearch = nextSearch;
1787
+ routeMatch.search = replaceEqualDeep(parentSearch, _extends$1({}, parentSearch, nextSearch));
1788
+ } catch (err) {
1789
+ console.error(err);
1790
+ const error = new Error('Invalid search params found', {
1791
+ cause: err
1792
+ });
1793
+ error.code = 'INVALID_SEARCH_PARAMS';
1794
+ routeMatch.status = 'error';
1795
+ routeMatch.error = error; // Do not proceed with loading the route
1796
+
1797
+ return;
1798
+ }
1799
+ }
1800
+ },
1801
+ cancel: () => {
1802
+ var _routeMatch$__$abortC;
1803
+
1804
+ (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1805
+
1806
+ routeMatch.__.cancelPending();
1807
+ },
1808
+ load: async () => {
1809
+ const id = '' + Date.now() + Math.random();
1810
+ routeMatch.__.latestId = id; // If the match was in an error state, set it
1811
+ // to a loading state again. Otherwise, keep it
1812
+ // as loading or resolved
1813
+
1814
+ if (routeMatch.status === 'error' || routeMatch.status === 'idle') {
1815
+ routeMatch.status = 'loading';
1816
+ } // We started loading the route, so it's no longer invalid
1817
+
1818
+
1819
+ routeMatch.isInvalid = false;
1820
+ routeMatch.__.loadPromise = new Promise(async resolve => {
1821
+ // We are now fetching, even if it's in the background of a
1822
+ // resolved state
1823
+ routeMatch.isFetching = true;
1824
+ routeMatch.__.resolve = resolve;
1825
+
1826
+ const loaderPromise = (async () => {
1827
+ const importer = routeMatch.options.import; // First, run any importers
1828
+
1829
+ if (importer) {
1830
+ routeMatch.__.importPromise = importer({
1831
+ params: routeMatch.params // search: routeMatch.search,
1832
+
1833
+ }).then(imported => {
1834
+ routeMatch.__ = _extends$1({}, routeMatch.__, imported);
1835
+ });
1836
+ } // Wait for the importer to finish before
1837
+ // attempting to load elements and data
1838
+
1839
+
1840
+ await routeMatch.__.importPromise; // Next, load the elements and data in parallel
1841
+
1842
+ routeMatch.__.elementsPromise = (async () => {
1843
+ // then run all element and data loaders in parallel
1844
+ // For each element type, potentially load it asynchronously
1845
+ const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
1846
+ await Promise.all(elementTypes.map(async type => {
1847
+ const routeElement = routeMatch.options[type];
1848
+
1849
+ if (routeMatch.__[type]) {
1850
+ return;
1851
+ }
1852
+
1853
+ if (typeof routeElement === 'function') {
1854
+ const res = await routeElement(routeMatch);
1855
+ routeMatch.__[type] = res;
1856
+ } else {
1857
+ routeMatch.__[type] = routeMatch.options[type];
1858
+ }
1859
+ }));
1860
+ })();
1861
+
1862
+ routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1863
+ try {
1864
+ const data = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
1865
+ params: routeMatch.params,
1866
+ search: routeMatch.routeSearch,
1867
+ signal: routeMatch.__.abortController.signal
1868
+ }));
1869
+
1870
+ if (id !== routeMatch.__.latestId) {
1871
+ return routeMatch.__.loaderPromise;
1872
+ }
1873
+
1874
+ routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1875
+ cascadeLoaderData(routeMatch);
1876
+ routeMatch.error = undefined;
1877
+ routeMatch.status = 'success';
1878
+ routeMatch.updatedAt = Date.now();
1879
+ } catch (err) {
1880
+ if (id !== routeMatch.__.latestId) {
1881
+ return routeMatch.__.loaderPromise;
1882
+ }
1883
+
1884
+ if (process.env.NODE_ENV !== 'production') {
1885
+ console.error(err);
1886
+ }
1887
+
1888
+ routeMatch.error = err;
1889
+ routeMatch.status = 'error';
1890
+ routeMatch.updatedAt = Date.now();
1891
+ }
1892
+ });
1893
+
1894
+ try {
1895
+ await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1896
+
1897
+ if (id !== routeMatch.__.latestId) {
1898
+ return routeMatch.__.loaderPromise;
1899
+ }
1900
+
1901
+ if (routeMatch.__.pendingMinPromise) {
1902
+ await routeMatch.__.pendingMinPromise;
1903
+ delete routeMatch.__.pendingMinPromise;
1904
+ }
1905
+ } finally {
1906
+ if (id !== routeMatch.__.latestId) {
1907
+ return routeMatch.__.loaderPromise;
1908
+ }
1909
+
1910
+ routeMatch.__.cancelPending();
1911
+
1912
+ routeMatch.isPending = false;
1913
+ routeMatch.isFetching = false;
1914
+
1915
+ routeMatch.__.notify();
1916
+ }
1917
+ })();
1918
+
1919
+ routeMatch.__.loaderPromise = loaderPromise;
1920
+ await loaderPromise;
1921
+
1922
+ if (id !== routeMatch.__.latestId) {
1923
+ return routeMatch.__.loaderPromise;
1924
+ }
1925
+
1926
+ delete routeMatch.__.loaderPromise;
1927
+ });
1928
+ return await routeMatch.__.loadPromise;
1929
+ }
1930
+ });
1931
+
1932
+ return routeMatch;
1933
+ }
1934
+
1935
+ function cascadeLoaderData(routeMatch) {
1936
+ if (routeMatch.parentMatch) {
1937
+ routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _extends$1({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
1938
+ }
1939
+
1940
+ if (routeMatch.childMatches.length) {
1941
+ routeMatch.childMatches.forEach(childMatch => {
1942
+ cascadeLoaderData(childMatch);
1943
+ });
1944
+ }
1945
+ }
1946
+
1947
+ function matchPathname(currentPathname, matchLocation) {
1948
+ const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1949
+
1950
+ if (matchLocation.to && !pathParams) {
1951
+ return;
1952
+ } // if (matchLocation.search && !searchMatched) {
1953
+ // return
1954
+ // }
1955
+
1956
+
1957
+ return pathParams != null ? pathParams : {};
1958
+ }
1959
+
1960
+ function interpolatePath(path, params, leaveWildcard) {
1961
+ const interpolatedPathSegments = parsePathname(path);
1962
+ return joinPaths(interpolatedPathSegments.map(segment => {
1963
+ if (segment.value === '*' && !leaveWildcard) {
1964
+ return '';
1965
+ }
1966
+
1967
+ if (segment.type === 'param') {
1968
+ var _segment$value$substr;
1969
+
1970
+ return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1971
+ }
1972
+
1973
+ return segment.value;
1974
+ }));
1975
+ }
1976
+
1977
+ function warning(cond, message) {
1978
+ if (cond) {
1979
+ if (typeof console !== 'undefined') console.warn(message);
1980
+
1981
+ try {
1982
+ throw new Error(message);
1983
+ } catch (_unused) {}
1984
+ }
1985
+
1986
+ return true;
1987
+ }
1988
+
1989
+ function isFunction(d) {
1990
+ return typeof d === 'function';
1991
+ }
1992
+
1993
+ function functionalUpdate(updater, previous) {
1994
+ if (isFunction(updater)) {
1995
+ return updater(previous);
1996
+ }
1997
+
1998
+ return updater;
1999
+ }
2000
+
2001
+ function joinPaths(paths) {
2002
+ return cleanPath(paths.filter(Boolean).join('/'));
2003
+ }
2004
+
2005
+ function cleanPath(path) {
2006
+ // remove double slashes
2007
+ return path.replace(/\/{2,}/g, '/');
2008
+ }
2009
+
2010
+ function trimPathLeft(path) {
2011
+ return path === '/' ? path : path.replace(/^\/{1,}/, '');
2012
+ }
2013
+
2014
+ function trimPathRight(path) {
2015
+ return path === '/' ? path : path.replace(/\/{1,}$/, '');
2016
+ }
2017
+
2018
+ function trimPath(path) {
2019
+ return trimPathRight(trimPathLeft(path));
2020
+ }
2021
+
2022
+ function matchByPath(from, matchLocation) {
2023
+ var _matchLocation$to;
2024
+
2025
+ const baseSegments = parsePathname(from);
2026
+ const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
2027
+ const params = {};
2028
+
2029
+ let isMatch = (() => {
2030
+ for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
2031
+ const baseSegment = baseSegments[i];
2032
+ const routeSegment = routeSegments[i];
2033
+ const isLastRouteSegment = i === routeSegments.length - 1;
2034
+ const isLastBaseSegment = i === baseSegments.length - 1;
2035
+
2036
+ if (routeSegment) {
2037
+ if (routeSegment.type === 'wildcard') {
2038
+ if (baseSegment != null && baseSegment.value) {
2039
+ params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
2040
+ return true;
2041
+ }
2042
+
2043
+ return false;
2044
+ }
2045
+
2046
+ if (routeSegment.type === 'pathname') {
2047
+ if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
2048
+ return true;
2049
+ }
2050
+
2051
+ if (baseSegment) {
2052
+ if (matchLocation.caseSensitive) {
2053
+ if (routeSegment.value !== baseSegment.value) {
2054
+ return false;
2055
+ }
2056
+ } else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
2057
+ return false;
2058
+ }
2059
+ }
2060
+ }
2061
+
2062
+ if (!baseSegment) {
2063
+ return false;
2064
+ }
2065
+
2066
+ if (routeSegment.type === 'param') {
2067
+ if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
2068
+ return false;
2069
+ }
2070
+
2071
+ if (!baseSegment.value.startsWith(':')) {
2072
+ params[routeSegment.value.substring(1)] = baseSegment.value;
2073
+ }
2074
+ }
2075
+ }
2076
+
2077
+ if (isLastRouteSegment && !isLastBaseSegment) {
2078
+ return !!matchLocation.fuzzy;
2079
+ }
2080
+ }
2081
+
2082
+ return true;
2083
+ })();
2084
+
2085
+ return isMatch ? params : undefined;
2086
+ } // function matchBySearch(
2087
+ // search: SearchSchema,
2088
+ // matchLocation: MatchLocation,
2089
+ // ) {
2090
+ // return !!(matchLocation.search && matchLocation.search(search))
2091
+ // }
2092
+
2093
+ function parsePathname(pathname) {
2094
+ if (!pathname) {
2095
+ return [];
2096
+ }
2097
+
2098
+ pathname = cleanPath(pathname);
2099
+ const segments = [];
2100
+
2101
+ if (pathname.slice(0, 1) === '/') {
2102
+ pathname = pathname.substring(1);
2103
+ segments.push({
2104
+ type: 'pathname',
2105
+ value: '/'
2106
+ });
2107
+ }
2108
+
2109
+ if (!pathname) {
2110
+ return segments;
2111
+ } // Remove empty segments and '.' segments
2112
+
2113
+
2114
+ const split = pathname.split('/').filter(Boolean);
2115
+ segments.push(...split.map(part => {
2116
+ if (part.startsWith('*')) {
2117
+ return {
2118
+ type: 'wildcard',
2119
+ value: part
2120
+ };
2121
+ }
2122
+
2123
+ if (part.charAt(0) === ':') {
2124
+ return {
2125
+ type: 'param',
2126
+ value: part
2127
+ };
2128
+ }
2129
+
2130
+ return {
2131
+ type: 'pathname',
2132
+ value: part
2133
+ };
2134
+ }));
2135
+
2136
+ if (pathname.slice(-1) === '/') {
2137
+ pathname = pathname.substring(1);
2138
+ segments.push({
2139
+ type: 'pathname',
2140
+ value: '/'
2141
+ });
2142
+ }
2143
+
2144
+ return segments;
2145
+ }
2146
+
2147
+ function _resolvePath(basepath, base, to) {
2148
+ base = base.replace(new RegExp("^" + basepath), '/');
2149
+ to = to.replace(new RegExp("^" + basepath), '/');
2150
+ let baseSegments = parsePathname(base);
2151
+ const toSegments = parsePathname(to);
2152
+ toSegments.forEach((toSegment, index) => {
2153
+ if (toSegment.value === '/') {
2154
+ if (!index) {
2155
+ // Leading slash
2156
+ baseSegments = [toSegment];
2157
+ } else if (index === toSegments.length - 1) {
2158
+ // Trailing Slash
2159
+ baseSegments.push(toSegment);
2160
+ } else ;
2161
+ } else if (toSegment.value === '..') {
2162
+ var _last2;
2163
+
2164
+ // Extra trailing slash? pop it off
2165
+ if (baseSegments.length > 1 && ((_last2 = last(baseSegments)) == null ? void 0 : _last2.value) === '/') {
2166
+ baseSegments.pop();
2167
+ }
2168
+
2169
+ baseSegments.pop();
2170
+ } else if (toSegment.value === '.') {
2171
+ return;
2172
+ } else {
2173
+ baseSegments.push(toSegment);
2174
+ }
2175
+ });
2176
+ const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
2177
+ return cleanPath(joined);
2178
+ }
2179
+ function replaceEqualDeep(prev, next) {
2180
+ if (prev === next) {
2181
+ return prev;
2182
+ }
2183
+
2184
+ const array = Array.isArray(prev) && Array.isArray(next);
2185
+
2186
+ if (array || isPlainObject(prev) && isPlainObject(next)) {
2187
+ const aSize = array ? prev.length : Object.keys(prev).length;
2188
+ const bItems = array ? next : Object.keys(next);
2189
+ const bSize = bItems.length;
2190
+ const copy = array ? [] : {};
2191
+ let equalItems = 0;
2192
+
2193
+ for (let i = 0; i < bSize; i++) {
2194
+ const key = array ? i : bItems[i];
2195
+ copy[key] = replaceEqualDeep(prev[key], next[key]);
2196
+
2197
+ if (copy[key] === prev[key]) {
2198
+ equalItems++;
2199
+ }
2200
+ }
2201
+
2202
+ return aSize === bSize && equalItems === aSize ? prev : copy;
2203
+ }
2204
+
2205
+ return next;
2206
+ } // Copied from: https://github.com/jonschlinkert/is-plain-object
2207
+
2208
+ function isPlainObject(o) {
2209
+ if (!hasObjectPrototype(o)) {
2210
+ return false;
2211
+ } // If has modified constructor
2212
+
2213
+
2214
+ const ctor = o.constructor;
2215
+
2216
+ if (typeof ctor === 'undefined') {
2217
+ return true;
2218
+ } // If has modified prototype
2219
+
2220
+
2221
+ const prot = ctor.prototype;
2222
+
2223
+ if (!hasObjectPrototype(prot)) {
2224
+ return false;
2225
+ } // If constructor does not have an Object-specific method
2226
+
2227
+
2228
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
2229
+ return false;
2230
+ } // Most likely a plain Object
2231
+
2232
+
2233
+ return true;
2234
+ }
2235
+
2236
+ function hasObjectPrototype(o) {
2237
+ return Object.prototype.toString.call(o) === '[object Object]';
2238
+ }
2239
+
2240
+ const defaultParseSearch = parseSearchWith(JSON.parse);
2241
+ const defaultStringifySearch = stringifySearchWith(JSON.stringify);
2242
+ function parseSearchWith(parser) {
2243
+ return searchStr => {
2244
+ if (searchStr.substring(0, 1) === '?') {
2245
+ searchStr = searchStr.substring(1);
2246
+ }
2247
+
2248
+ let query = decode(searchStr); // Try to parse any query params that might be json
2249
+
2250
+ for (let key in query) {
2251
+ const value = query[key];
2252
+
2253
+ if (typeof value === 'string') {
2254
+ try {
2255
+ query[key] = parser(value);
2256
+ } catch (err) {//
2257
+ }
2258
+ }
2259
+ }
2260
+
2261
+ return query;
2262
+ };
2263
+ }
2264
+ function stringifySearchWith(stringify) {
2265
+ return search => {
2266
+ search = _extends$1({}, search);
2267
+
2268
+ if (search) {
2269
+ Object.keys(search).forEach(key => {
2270
+ const val = search[key];
2271
+
2272
+ if (typeof val === 'undefined' || val === undefined) {
2273
+ delete search[key];
2274
+ } else if (val && typeof val === 'object' && val !== null) {
2275
+ try {
2276
+ search[key] = stringify(val);
2277
+ } catch (err) {// silent
2278
+ }
2279
+ }
2280
+ });
2281
+ }
2282
+
2283
+ const searchStr = encode(search).toString();
2284
+ return searchStr ? "?" + searchStr : '';
2285
+ };
2286
+ }
2287
+
2288
+ function isCtrlEvent(e) {
2289
+ return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2290
+ }
2291
+
2292
+ function last(arr) {
2293
+ return arr[arr.length - 1];
2294
+ }
2295
+
2296
+ export { createBrowserHistory, createHashHistory, createMemoryHistory, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith, warning };
2297
+ //# sourceMappingURL=index.js.map