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