kdu-router 2.7.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2 -25
- package/dist/kdu-router.common.js +176 -58
- package/dist/kdu-router.esm.js +176 -58
- package/dist/kdu-router.js +176 -58
- package/dist/kdu-router.min.js +2 -2
- package/package.json +22 -37
- package/types/index.d.ts +13 -18
- package/types/kdu.d.ts +2 -3
- package/types/router.d.ts +5 -5
- package/src/components/link.js +0 -138
- package/src/components/view.js +0 -96
- package/src/create-matcher.js +0 -201
- package/src/create-route-map.js +0 -165
- package/src/history/abstract.js +0 -51
- package/src/history/base.js +0 -328
- package/src/history/hash.js +0 -97
- package/src/history/html5.js +0 -69
- package/src/index.js +0 -235
- package/src/install.js +0 -52
- package/src/util/async.js +0 -18
- package/src/util/dom.js +0 -3
- package/src/util/location.js +0 -68
- package/src/util/params.js +0 -26
- package/src/util/path.js +0 -74
- package/src/util/push-state.js +0 -59
- package/src/util/query.js +0 -96
- package/src/util/resolve-components.js +0 -100
- package/src/util/route.js +0 -110
- package/src/util/scroll.js +0 -111
- package/src/util/warn.js +0 -17
package/dist/kdu-router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* kdu-router
|
|
2
|
+
* kdu-router v3.0.1
|
|
3
3
|
* (c) 2022 NKDuy
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -56,7 +56,7 @@ var View = {
|
|
|
56
56
|
var depth = 0;
|
|
57
57
|
var inactive = false;
|
|
58
58
|
while (parent && parent._routerRoot !== parent) {
|
|
59
|
-
if (parent.$
|
|
59
|
+
if (parent.$knode && parent.$knode.data.routerView) {
|
|
60
60
|
depth++;
|
|
61
61
|
}
|
|
62
62
|
if (parent._inactive) {
|
|
@@ -93,14 +93,26 @@ var View = {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
// also
|
|
96
|
+
// also register instance in prepatch hook
|
|
97
97
|
// in case the same component instance is reused across different routes
|
|
98
|
-
;(data.hook || (data.hook = {})).prepatch = function (_,
|
|
99
|
-
matched.instances[name] =
|
|
98
|
+
;(data.hook || (data.hook = {})).prepatch = function (_, knode) {
|
|
99
|
+
matched.instances[name] = knode.componentInstance;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
// resolve props
|
|
103
|
-
data.props = resolveProps(route, matched.props && matched.props[name]);
|
|
103
|
+
var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]);
|
|
104
|
+
if (propsToPass) {
|
|
105
|
+
// clone to prevent mutation
|
|
106
|
+
propsToPass = data.props = extend({}, propsToPass);
|
|
107
|
+
// pass non-declared props as attrs
|
|
108
|
+
var attrs = data.attrs = data.attrs || {};
|
|
109
|
+
for (var key in propsToPass) {
|
|
110
|
+
if (!component.props || !(key in component.props)) {
|
|
111
|
+
attrs[key] = propsToPass[key];
|
|
112
|
+
delete propsToPass[key];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
104
116
|
|
|
105
117
|
return h(component, data, children)
|
|
106
118
|
}
|
|
@@ -127,6 +139,13 @@ function resolveProps (route, config) {
|
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
|
|
142
|
+
function extend (to, from) {
|
|
143
|
+
for (var key in from) {
|
|
144
|
+
to[key] = from[key];
|
|
145
|
+
}
|
|
146
|
+
return to
|
|
147
|
+
}
|
|
148
|
+
|
|
130
149
|
/* */
|
|
131
150
|
|
|
132
151
|
var encodeReserveRE = /[!'()*]/g;
|
|
@@ -158,8 +177,7 @@ function resolveQuery (
|
|
|
158
177
|
parsedQuery = {};
|
|
159
178
|
}
|
|
160
179
|
for (var key in extraQuery) {
|
|
161
|
-
|
|
162
|
-
parsedQuery[key] = Array.isArray(val) ? val.slice() : val;
|
|
180
|
+
parsedQuery[key] = extraQuery[key];
|
|
163
181
|
}
|
|
164
182
|
return parsedQuery
|
|
165
183
|
}
|
|
@@ -236,12 +254,18 @@ function createRoute (
|
|
|
236
254
|
router
|
|
237
255
|
) {
|
|
238
256
|
var stringifyQuery$$1 = router && router.options.stringifyQuery;
|
|
257
|
+
|
|
258
|
+
var query = location.query || {};
|
|
259
|
+
try {
|
|
260
|
+
query = clone(query);
|
|
261
|
+
} catch (e) {}
|
|
262
|
+
|
|
239
263
|
var route = {
|
|
240
264
|
name: location.name || (record && record.name),
|
|
241
265
|
meta: (record && record.meta) || {},
|
|
242
266
|
path: location.path || '/',
|
|
243
267
|
hash: location.hash || '',
|
|
244
|
-
query:
|
|
268
|
+
query: query,
|
|
245
269
|
params: location.params || {},
|
|
246
270
|
fullPath: getFullPath(location, stringifyQuery$$1),
|
|
247
271
|
matched: record ? formatMatch(record) : []
|
|
@@ -252,6 +276,20 @@ function createRoute (
|
|
|
252
276
|
return Object.freeze(route)
|
|
253
277
|
}
|
|
254
278
|
|
|
279
|
+
function clone (value) {
|
|
280
|
+
if (Array.isArray(value)) {
|
|
281
|
+
return value.map(clone)
|
|
282
|
+
} else if (value && typeof value === 'object') {
|
|
283
|
+
var res = {};
|
|
284
|
+
for (var key in value) {
|
|
285
|
+
res[key] = clone(value[key]);
|
|
286
|
+
}
|
|
287
|
+
return res
|
|
288
|
+
} else {
|
|
289
|
+
return value
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
255
293
|
// the starting route that represents the initial state
|
|
256
294
|
var START = createRoute(null, {
|
|
257
295
|
path: '/'
|
|
@@ -305,6 +343,8 @@ function isObjectEqual (a, b) {
|
|
|
305
343
|
if ( a === void 0 ) a = {};
|
|
306
344
|
if ( b === void 0 ) b = {};
|
|
307
345
|
|
|
346
|
+
// handle null value #1566
|
|
347
|
+
if (!a || !b) { return a === b }
|
|
308
348
|
var aKeys = Object.keys(a);
|
|
309
349
|
var bKeys = Object.keys(b);
|
|
310
350
|
if (aKeys.length !== bKeys.length) {
|
|
@@ -484,7 +524,7 @@ function findAnchor (children) {
|
|
|
484
524
|
var _Kdu;
|
|
485
525
|
|
|
486
526
|
function install (Kdu) {
|
|
487
|
-
if (install.installed) { return }
|
|
527
|
+
if (install.installed && _Kdu === Kdu) { return }
|
|
488
528
|
install.installed = true;
|
|
489
529
|
|
|
490
530
|
_Kdu = Kdu;
|
|
@@ -492,7 +532,7 @@ function install (Kdu) {
|
|
|
492
532
|
var isDef = function (v) { return v !== undefined; };
|
|
493
533
|
|
|
494
534
|
var registerInstance = function (vm, callVal) {
|
|
495
|
-
var i = vm.$options.
|
|
535
|
+
var i = vm.$options._parentKnode;
|
|
496
536
|
if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
|
|
497
537
|
i(vm, callVal);
|
|
498
538
|
}
|
|
@@ -606,14 +646,14 @@ function cleanPath (path) {
|
|
|
606
646
|
return path.replace(/\/\//g, '/')
|
|
607
647
|
}
|
|
608
648
|
|
|
609
|
-
var
|
|
649
|
+
var isarray = Array.isArray || function (arr) {
|
|
610
650
|
return Object.prototype.toString.call(arr) == '[object Array]';
|
|
611
651
|
};
|
|
612
652
|
|
|
613
653
|
/**
|
|
614
654
|
* Expose `pathToRegexp`.
|
|
615
655
|
*/
|
|
616
|
-
var
|
|
656
|
+
var pathToRegexp_1 = pathToRegexp;
|
|
617
657
|
var parse_1 = parse;
|
|
618
658
|
var compile_1 = compile;
|
|
619
659
|
var tokensToFunction_1 = tokensToFunction;
|
|
@@ -718,7 +758,7 @@ function parse (str, options) {
|
|
|
718
758
|
* @return {!function(Object=, Object=)}
|
|
719
759
|
*/
|
|
720
760
|
function compile (str, options) {
|
|
721
|
-
return tokensToFunction(parse(str, options))
|
|
761
|
+
return tokensToFunction(parse(str, options), options)
|
|
722
762
|
}
|
|
723
763
|
|
|
724
764
|
/**
|
|
@@ -748,14 +788,14 @@ function encodeAsterisk (str) {
|
|
|
748
788
|
/**
|
|
749
789
|
* Expose a method for transforming tokens into the path function.
|
|
750
790
|
*/
|
|
751
|
-
function tokensToFunction (tokens) {
|
|
791
|
+
function tokensToFunction (tokens, options) {
|
|
752
792
|
// Compile all the tokens into regexps.
|
|
753
793
|
var matches = new Array(tokens.length);
|
|
754
794
|
|
|
755
795
|
// Compile all the patterns before compilation.
|
|
756
796
|
for (var i = 0; i < tokens.length; i++) {
|
|
757
797
|
if (typeof tokens[i] === 'object') {
|
|
758
|
-
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$');
|
|
798
|
+
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options));
|
|
759
799
|
}
|
|
760
800
|
}
|
|
761
801
|
|
|
@@ -790,7 +830,7 @@ function tokensToFunction (tokens) {
|
|
|
790
830
|
}
|
|
791
831
|
}
|
|
792
832
|
|
|
793
|
-
if (
|
|
833
|
+
if (isarray(value)) {
|
|
794
834
|
if (!token.repeat) {
|
|
795
835
|
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
|
|
796
836
|
}
|
|
@@ -868,7 +908,7 @@ function attachKeys (re, keys) {
|
|
|
868
908
|
* @return {string}
|
|
869
909
|
*/
|
|
870
910
|
function flags (options) {
|
|
871
|
-
return options.sensitive ? '' : 'i'
|
|
911
|
+
return options && options.sensitive ? '' : 'i'
|
|
872
912
|
}
|
|
873
913
|
|
|
874
914
|
/**
|
|
@@ -941,7 +981,7 @@ function stringToRegexp (path, keys, options) {
|
|
|
941
981
|
* @return {!RegExp}
|
|
942
982
|
*/
|
|
943
983
|
function tokensToRegExp (tokens, keys, options) {
|
|
944
|
-
if (!
|
|
984
|
+
if (!isarray(keys)) {
|
|
945
985
|
options = /** @type {!Object} */ (keys || options);
|
|
946
986
|
keys = [];
|
|
947
987
|
}
|
|
@@ -1017,7 +1057,7 @@ function tokensToRegExp (tokens, keys, options) {
|
|
|
1017
1057
|
* @return {!RegExp}
|
|
1018
1058
|
*/
|
|
1019
1059
|
function pathToRegexp (path, keys, options) {
|
|
1020
|
-
if (!
|
|
1060
|
+
if (!isarray(keys)) {
|
|
1021
1061
|
options = /** @type {!Object} */ (keys || options);
|
|
1022
1062
|
keys = [];
|
|
1023
1063
|
}
|
|
@@ -1028,20 +1068,21 @@ function pathToRegexp (path, keys, options) {
|
|
|
1028
1068
|
return regexpToRegexp(path, /** @type {!Array} */ (keys))
|
|
1029
1069
|
}
|
|
1030
1070
|
|
|
1031
|
-
if (
|
|
1071
|
+
if (isarray(path)) {
|
|
1032
1072
|
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
|
|
1033
1073
|
}
|
|
1034
1074
|
|
|
1035
1075
|
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
|
|
1036
1076
|
}
|
|
1037
1077
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1078
|
+
pathToRegexp_1.parse = parse_1;
|
|
1079
|
+
pathToRegexp_1.compile = compile_1;
|
|
1080
|
+
pathToRegexp_1.tokensToFunction = tokensToFunction_1;
|
|
1081
|
+
pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
|
|
1042
1082
|
|
|
1043
1083
|
/* */
|
|
1044
1084
|
|
|
1085
|
+
// $flow-disable-line
|
|
1045
1086
|
var regexpCompileCache = Object.create(null);
|
|
1046
1087
|
|
|
1047
1088
|
function fillParams (
|
|
@@ -1052,7 +1093,7 @@ function fillParams (
|
|
|
1052
1093
|
try {
|
|
1053
1094
|
var filler =
|
|
1054
1095
|
regexpCompileCache[path] ||
|
|
1055
|
-
(regexpCompileCache[path] =
|
|
1096
|
+
(regexpCompileCache[path] = pathToRegexp_1.compile(path));
|
|
1056
1097
|
return filler(params || {}, { pretty: true })
|
|
1057
1098
|
} catch (e) {
|
|
1058
1099
|
{
|
|
@@ -1072,7 +1113,9 @@ function createRouteMap (
|
|
|
1072
1113
|
) {
|
|
1073
1114
|
// the path list is used to control path matching priority
|
|
1074
1115
|
var pathList = oldPathList || [];
|
|
1116
|
+
// $flow-disable-line
|
|
1075
1117
|
var pathMap = oldPathMap || Object.create(null);
|
|
1118
|
+
// $flow-disable-line
|
|
1076
1119
|
var nameMap = oldNameMap || Object.create(null);
|
|
1077
1120
|
|
|
1078
1121
|
routes.forEach(function (route) {
|
|
@@ -1114,8 +1157,12 @@ function addRouteRecord (
|
|
|
1114
1157
|
);
|
|
1115
1158
|
}
|
|
1116
1159
|
|
|
1117
|
-
var normalizedPath = normalizePath(path, parent);
|
|
1118
1160
|
var pathToRegexpOptions = route.pathToRegexpOptions || {};
|
|
1161
|
+
var normalizedPath = normalizePath(
|
|
1162
|
+
path,
|
|
1163
|
+
parent,
|
|
1164
|
+
pathToRegexpOptions.strict
|
|
1165
|
+
);
|
|
1119
1166
|
|
|
1120
1167
|
if (typeof route.caseSensitive === 'boolean') {
|
|
1121
1168
|
pathToRegexpOptions.sensitive = route.caseSensitive;
|
|
@@ -1203,9 +1250,9 @@ function addRouteRecord (
|
|
|
1203
1250
|
}
|
|
1204
1251
|
|
|
1205
1252
|
function compileRouteRegex (path, pathToRegexpOptions) {
|
|
1206
|
-
var regex =
|
|
1253
|
+
var regex = pathToRegexp_1(path, [], pathToRegexpOptions);
|
|
1207
1254
|
{
|
|
1208
|
-
var keys =
|
|
1255
|
+
var keys = Object.create(null);
|
|
1209
1256
|
regex.keys.forEach(function (key) {
|
|
1210
1257
|
warn(!keys[key.name], ("Duplicate param keys in route with path: \"" + path + "\""));
|
|
1211
1258
|
keys[key.name] = true;
|
|
@@ -1214,8 +1261,8 @@ function compileRouteRegex (path, pathToRegexpOptions) {
|
|
|
1214
1261
|
return regex
|
|
1215
1262
|
}
|
|
1216
1263
|
|
|
1217
|
-
function normalizePath (path, parent) {
|
|
1218
|
-
path = path.replace(/\/$/, '');
|
|
1264
|
+
function normalizePath (path, parent, strict) {
|
|
1265
|
+
if (!strict) { path = path.replace(/\/$/, ''); }
|
|
1219
1266
|
if (path[0] === '/') { return path }
|
|
1220
1267
|
if (parent == null) { return path }
|
|
1221
1268
|
return cleanPath(((parent.path) + "/" + path))
|
|
@@ -1487,6 +1534,8 @@ function resolveRecordPath (path, record) {
|
|
|
1487
1534
|
var positionStore = Object.create(null);
|
|
1488
1535
|
|
|
1489
1536
|
function setupScroll () {
|
|
1537
|
+
// Fix for #1585 for Firefox
|
|
1538
|
+
window.history.replaceState({ key: getStateKey() }, '');
|
|
1490
1539
|
window.addEventListener('popstate', function (e) {
|
|
1491
1540
|
saveScrollPosition();
|
|
1492
1541
|
if (e.state && e.state.key) {
|
|
@@ -1518,25 +1567,21 @@ function handleScroll (
|
|
|
1518
1567
|
router.app.$nextTick(function () {
|
|
1519
1568
|
var position = getScrollPosition();
|
|
1520
1569
|
var shouldScroll = behavior(to, from, isPop ? position : null);
|
|
1570
|
+
|
|
1521
1571
|
if (!shouldScroll) {
|
|
1522
1572
|
return
|
|
1523
1573
|
}
|
|
1524
|
-
var isObject = typeof shouldScroll === 'object';
|
|
1525
|
-
if (isObject && typeof shouldScroll.selector === 'string') {
|
|
1526
|
-
var el = document.querySelector(shouldScroll.selector);
|
|
1527
|
-
if (el) {
|
|
1528
|
-
var offset = shouldScroll.offset && typeof shouldScroll.offset === 'object' ? shouldScroll.offset : {};
|
|
1529
|
-
offset = normalizeOffset(offset);
|
|
1530
|
-
position = getElementPosition(el, offset);
|
|
1531
|
-
} else if (isValidPosition(shouldScroll)) {
|
|
1532
|
-
position = normalizePosition(shouldScroll);
|
|
1533
|
-
}
|
|
1534
|
-
} else if (isObject && isValidPosition(shouldScroll)) {
|
|
1535
|
-
position = normalizePosition(shouldScroll);
|
|
1536
|
-
}
|
|
1537
1574
|
|
|
1538
|
-
if (
|
|
1539
|
-
|
|
1575
|
+
if (typeof shouldScroll.then === 'function') {
|
|
1576
|
+
shouldScroll.then(function (shouldScroll) {
|
|
1577
|
+
scrollToPosition((shouldScroll), position);
|
|
1578
|
+
}).catch(function (err) {
|
|
1579
|
+
{
|
|
1580
|
+
assert(false, err.toString());
|
|
1581
|
+
}
|
|
1582
|
+
});
|
|
1583
|
+
} else {
|
|
1584
|
+
scrollToPosition(shouldScroll, position);
|
|
1540
1585
|
}
|
|
1541
1586
|
});
|
|
1542
1587
|
}
|
|
@@ -1590,6 +1635,26 @@ function isNumber (v) {
|
|
|
1590
1635
|
return typeof v === 'number'
|
|
1591
1636
|
}
|
|
1592
1637
|
|
|
1638
|
+
function scrollToPosition (shouldScroll, position) {
|
|
1639
|
+
var isObject = typeof shouldScroll === 'object';
|
|
1640
|
+
if (isObject && typeof shouldScroll.selector === 'string') {
|
|
1641
|
+
var el = document.querySelector(shouldScroll.selector);
|
|
1642
|
+
if (el) {
|
|
1643
|
+
var offset = shouldScroll.offset && typeof shouldScroll.offset === 'object' ? shouldScroll.offset : {};
|
|
1644
|
+
offset = normalizeOffset(offset);
|
|
1645
|
+
position = getElementPosition(el, offset);
|
|
1646
|
+
} else if (isValidPosition(shouldScroll)) {
|
|
1647
|
+
position = normalizePosition(shouldScroll);
|
|
1648
|
+
}
|
|
1649
|
+
} else if (isObject && isValidPosition(shouldScroll)) {
|
|
1650
|
+
position = normalizePosition(shouldScroll);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
if (position) {
|
|
1654
|
+
window.scrollTo(position.x, position.y);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1593
1658
|
/* */
|
|
1594
1659
|
|
|
1595
1660
|
var supportsPushState = inBrowser && (function () {
|
|
@@ -1685,7 +1750,7 @@ function resolveAsyncComponents (matched) {
|
|
|
1685
1750
|
pending++;
|
|
1686
1751
|
|
|
1687
1752
|
var resolve = once(function (resolvedDef) {
|
|
1688
|
-
if (resolvedDef
|
|
1753
|
+
if (isESModule(resolvedDef)) {
|
|
1689
1754
|
resolvedDef = resolvedDef.default;
|
|
1690
1755
|
}
|
|
1691
1756
|
// save resolved on async factory in case it's used elsewhere
|
|
@@ -1720,7 +1785,7 @@ function resolveAsyncComponents (matched) {
|
|
|
1720
1785
|
if (typeof res.then === 'function') {
|
|
1721
1786
|
res.then(resolve, reject);
|
|
1722
1787
|
} else {
|
|
1723
|
-
// new syntax in Kdu
|
|
1788
|
+
// new syntax in Kdu 2.3
|
|
1724
1789
|
var comp = res.component;
|
|
1725
1790
|
if (comp && typeof comp.then === 'function') {
|
|
1726
1791
|
comp.then(resolve, reject);
|
|
@@ -1751,6 +1816,14 @@ function flatten (arr) {
|
|
|
1751
1816
|
return Array.prototype.concat.apply([], arr)
|
|
1752
1817
|
}
|
|
1753
1818
|
|
|
1819
|
+
var hasSymbol =
|
|
1820
|
+
typeof Symbol === 'function' &&
|
|
1821
|
+
typeof Symbol.toStringTag === 'symbol';
|
|
1822
|
+
|
|
1823
|
+
function isESModule (obj) {
|
|
1824
|
+
return obj.__esModule || (hasSymbol && obj[Symbol.toStringTag] === 'Module')
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1754
1827
|
// in Webpack 2, require.ensure now also returns a Promise
|
|
1755
1828
|
// so the resolve/reject functions may get called an extra time
|
|
1756
1829
|
// if the user uses an arrow function shorthand that happens to
|
|
@@ -2079,9 +2152,18 @@ var HTML5History = (function (History$$1) {
|
|
|
2079
2152
|
setupScroll();
|
|
2080
2153
|
}
|
|
2081
2154
|
|
|
2155
|
+
var initLocation = getLocation(this.base);
|
|
2082
2156
|
window.addEventListener('popstate', function (e) {
|
|
2083
2157
|
var current = this$1.current;
|
|
2084
|
-
|
|
2158
|
+
|
|
2159
|
+
// Avoiding first `popstate` event dispatched in some browsers but first
|
|
2160
|
+
// history route not updated since async guard at the same time.
|
|
2161
|
+
var location = getLocation(this$1.base);
|
|
2162
|
+
if (this$1.current === START && location === initLocation) {
|
|
2163
|
+
return
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
this$1.transitionTo(location, function (route) {
|
|
2085
2167
|
if (expectScroll) {
|
|
2086
2168
|
handleScroll(router, route, current, true);
|
|
2087
2169
|
}
|
|
@@ -2165,26 +2247,50 @@ var HashHistory = (function (History$$1) {
|
|
|
2165
2247
|
HashHistory.prototype.setupListeners = function setupListeners () {
|
|
2166
2248
|
var this$1 = this;
|
|
2167
2249
|
|
|
2168
|
-
|
|
2250
|
+
var router = this.router;
|
|
2251
|
+
var expectScroll = router.options.scrollBehavior;
|
|
2252
|
+
var supportsScroll = supportsPushState && expectScroll;
|
|
2253
|
+
|
|
2254
|
+
if (supportsScroll) {
|
|
2255
|
+
setupScroll();
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
window.addEventListener(supportsPushState ? 'popstate' : 'hashchange', function () {
|
|
2259
|
+
var current = this$1.current;
|
|
2169
2260
|
if (!ensureSlash()) {
|
|
2170
2261
|
return
|
|
2171
2262
|
}
|
|
2172
2263
|
this$1.transitionTo(getHash(), function (route) {
|
|
2173
|
-
|
|
2264
|
+
if (supportsScroll) {
|
|
2265
|
+
handleScroll(this$1.router, route, current, true);
|
|
2266
|
+
}
|
|
2267
|
+
if (!supportsPushState) {
|
|
2268
|
+
replaceHash(route.fullPath);
|
|
2269
|
+
}
|
|
2174
2270
|
});
|
|
2175
2271
|
});
|
|
2176
2272
|
};
|
|
2177
2273
|
|
|
2178
2274
|
HashHistory.prototype.push = function push (location, onComplete, onAbort) {
|
|
2275
|
+
var this$1 = this;
|
|
2276
|
+
|
|
2277
|
+
var ref = this;
|
|
2278
|
+
var fromRoute = ref.current;
|
|
2179
2279
|
this.transitionTo(location, function (route) {
|
|
2180
2280
|
pushHash(route.fullPath);
|
|
2281
|
+
handleScroll(this$1.router, route, fromRoute, false);
|
|
2181
2282
|
onComplete && onComplete(route);
|
|
2182
2283
|
}, onAbort);
|
|
2183
2284
|
};
|
|
2184
2285
|
|
|
2185
2286
|
HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
|
|
2287
|
+
var this$1 = this;
|
|
2288
|
+
|
|
2289
|
+
var ref = this;
|
|
2290
|
+
var fromRoute = ref.current;
|
|
2186
2291
|
this.transitionTo(location, function (route) {
|
|
2187
2292
|
replaceHash(route.fullPath);
|
|
2293
|
+
handleScroll(this$1.router, route, fromRoute, false);
|
|
2188
2294
|
onComplete && onComplete(route);
|
|
2189
2295
|
}, onAbort);
|
|
2190
2296
|
};
|
|
@@ -2234,15 +2340,27 @@ function getHash () {
|
|
|
2234
2340
|
return index === -1 ? '' : href.slice(index + 1)
|
|
2235
2341
|
}
|
|
2236
2342
|
|
|
2343
|
+
function getUrl (path) {
|
|
2344
|
+
var href = window.location.href;
|
|
2345
|
+
var i = href.indexOf('#');
|
|
2346
|
+
var base = i >= 0 ? href.slice(0, i) : href;
|
|
2347
|
+
return (base + "#" + path)
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2237
2350
|
function pushHash (path) {
|
|
2238
|
-
|
|
2351
|
+
if (supportsPushState) {
|
|
2352
|
+
pushState(getUrl(path));
|
|
2353
|
+
} else {
|
|
2354
|
+
window.location.hash = path;
|
|
2355
|
+
}
|
|
2239
2356
|
}
|
|
2240
2357
|
|
|
2241
2358
|
function replaceHash (path) {
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2359
|
+
if (supportsPushState) {
|
|
2360
|
+
replaceState(getUrl(path));
|
|
2361
|
+
} else {
|
|
2362
|
+
window.location.replace(getUrl(path));
|
|
2363
|
+
}
|
|
2246
2364
|
}
|
|
2247
2365
|
|
|
2248
2366
|
/* */
|
|
@@ -2344,7 +2462,7 @@ var KduRouter = function KduRouter (options) {
|
|
|
2344
2462
|
}
|
|
2345
2463
|
};
|
|
2346
2464
|
|
|
2347
|
-
var prototypeAccessors = { currentRoute: {} };
|
|
2465
|
+
var prototypeAccessors = { currentRoute: { configurable: true } };
|
|
2348
2466
|
|
|
2349
2467
|
KduRouter.prototype.match = function match (
|
|
2350
2468
|
raw,
|
|
@@ -2502,7 +2620,7 @@ function createHref (base, fullPath, mode) {
|
|
|
2502
2620
|
}
|
|
2503
2621
|
|
|
2504
2622
|
KduRouter.install = install;
|
|
2505
|
-
KduRouter.version = '
|
|
2623
|
+
KduRouter.version = '3.0.1';
|
|
2506
2624
|
|
|
2507
2625
|
if (inBrowser && window.Kdu) {
|
|
2508
2626
|
window.Kdu.use(KduRouter);
|
package/dist/kdu-router.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* kdu-router v3.0.1
|
|
3
3
|
* (c) 2022 NKDuy
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.KduRouter=e()}(this,function(){"use strict";function t(t, e){}function e(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function r(t, e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}function n(t, e, r){void 0===e&&(e={});var n,i=r||o;try{n=i(t||"")}catch(t){n={}}for(var a in e){var u=e[a];n[a]=Array.isArray(u)?u.slice():u}return n}function o(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=$t(r.shift()),o=r.length>0?$t(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]}),e):e}function i(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return Tt(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(Tt(e)):n.push(Tt(e)+"="+Tt(t)))}),n.join("&")}return Tt(e)+"="+Tt(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function a(t, e, r, n){var o=n&&n.options.stringifyQuery,i={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:c(e,o),matched:t?u(t):[]};return r&&(i.redirectedFrom=c(r,o)),Object.freeze(i)}function u(t){for(var e=[]; t;)e.unshift(t),t=t.parent;return e}function c(t, e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;void 0===o&&(o="");var a=e||i;return(r||"/")+a(n)+o}function s(t, e){return e===qt?t===e:!!e&&(t.path&&e.path?t.path.replace(St,"")===e.path.replace(St,"")&&t.hash===e.hash&&p(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&p(t.query,e.query)&&p(t.params,e.params)))}function p(t, e){void 0===t&&(t={}),void 0===e&&(e={});var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(r){var n=t[r],o=e[r];return"object"==typeof n&&"object"==typeof o?p(n,o):String(n)===String(o)})}function f(t, e){return 0===t.path.replace(St,"/").indexOf(e.path.replace(St,"/"))&&(!e.hash||t.hash===e.hash)&&h(t.query,e.query)}function h(t, e){for(var r in e)if(!(r in t))return!1;return!0}function l(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function d(t){if(t)for(var e,r=0; r<t.length; r++){if("a"===(e=t[r]).tag)return e;if(e.children&&(e=d(e.children)))return e}}function y(t){if(!y.installed){y.installed=!0,Ot=t;var e=function(t){return void 0!==t},r=function(t, r){var n=t.$options._parentVnode;e(n)&&e(n=n.data)&&e(n=n.registerRouteInstance)&&n(t,r)};t.mixin({beforeCreate:function(){e(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),t.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,r(this,this)},destroyed:function(){r(this)}}),Object.defineProperty(t.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this._routerRoot._route}}),t.component("router-view",Ct),t.component("router-link",Ut);var n=t.config.optionMergeStrategies;n.beforeRouteEnter=n.beforeRouteLeave=n.beforeRouteUpdate=n.created}}function v(t, e, r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;var o=e.split("/");r&&o[o.length-1]||o.pop();for(var i=t.replace(/^\//,"").split("/"),a=0; a<i.length; a++){var u=i[a];".."===u?o.pop():"."!==u&&o.push(u)}return""!==o[0]&&o.unshift(""),o.join("/")}function m(t){var e="",r="",n=t.indexOf("#");n>=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}function g(t){return t.replace(/\/\//g,"/")}function b(t, e){for(var r,n=[],o=0,i=0,a="",u=e&&e.delimiter||"/"; null!=(r=Ft.exec(t));){var c=r[0],s=r[1],p=r.index;if(a+=t.slice(i,p),i=p+c.length,s)a+=s[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],y=r[5],v=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,b="+"===v||"*"===v,w="?"===v||"*"===v,x=r[2]||u,k=d||y;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:w,repeat:b,partial:g,asterisk:!!m,pattern:k?E(k):m?".*":"[^"+R(x)+"]+?"})}}return i<t.length&&(a+=t.substr(i)),a&&n.push(a),n}function w(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function x(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function k(t){for(var e=new Array(t.length),r=0; r<t.length; r++)"object"==typeof t[r]&&(e[r]=new RegExp("^(?:"+t[r].pattern+")$"));return function(r, n){for(var o="",i=r||{},a=(n||{}).pretty?w:encodeURIComponent,u=0; u<t.length; u++){var c=t[u];if("string"!=typeof c){var s,p=i[c.name];if(null==p){if(c.optional){c.partial&&(o+=c.prefix);continue}throw new TypeError('Expected "'+c.name+'" to be defined')}if(It(p)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but received `'+JSON.stringify(p)+"`");if(0===p.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var f=0; f<p.length; f++){if(s=a(p[f]),!e[u].test(s))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'", but received `'+JSON.stringify(s)+"`");o+=(0===f?c.prefix:c.delimiter)+s}}else{if(s=c.asterisk?x(p):a(p),!e[u].test(s))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but received "'+s+'"');o+=c.prefix+s}}else o+=c}return o}}function R(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function E(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function O(t, e){return t.keys=e,t}function C(t){return t.sensitive?"":"i"}function A(t, e){var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0; n<r.length; n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return O(t,e)}function j(t, e, r){for(var n=[],o=0; o<t.length; o++)n.push($(t[o],e,r).source);return O(new RegExp("(?:"+n.join("|")+")",C(r)),e)}function _(t, e, r){return T(b(t,r),e,r)}function T(t, e, r){It(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,o=!1!==r.end,i="",a=0; a<t.length; a++){var u=t[a];if("string"==typeof u)i+=R(u);else{var c=R(u.prefix),s="(?:"+u.pattern+")";e.push(u),u.repeat&&(s+="(?:"+c+s+")*"),i+=s=u.optional?u.partial?c+"("+s+")?":"(?:"+c+"("+s+"))?":c+"("+s+")"}}var p=R(r.delimiter||"/"),f=i.slice(-p.length)===p;return n||(i=(f?i.slice(0,-p.length):i)+"(?:"+p+"(?=$))?"),i+=o?"$":n&&f?"":"(?="+p+"|$)",O(new RegExp("^"+i,C(r)),e)}function $(t, e, r){return It(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp?A(t,e):It(t)?j(t,e,r):_(t,e,r)}function S(t, e, r){try{return(Dt[t]||(Dt[t]=Mt.compile(t)))(e||{},{pretty:!0})}catch(t){return""}}function q(t, e, r, n){var o=e||[],i=r||Object.create(null),a=n||Object.create(null);t.forEach(function(t){L(o,i,a,t)});for(var u=0,c=o.length; u<c; u++)"*"===o[u]&&(o.push(o.splice(u,1)[0]),c--,u--);return{pathList:o,pathMap:i,nameMap:a}}function L(t, e, r, n, o, i){var a=n.path,u=n.name,c=U(a,o),s=n.pathToRegexpOptions||{};"boolean"==typeof n.caseSensitive&&(s.sensitive=n.caseSensitive);var p={path:c,regex:P(c,s),components:n.components||{default:n.component},instances:{},name:u,parent:o,matchAs:i,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{},props:null==n.props?{}:n.components?n.props:{default:n.props}};n.children&&n.children.forEach(function(n){var o=i?g(i+"/"+n.path):void 0;L(t,e,r,n,p,o)}),void 0!==n.alias&&(Array.isArray(n.alias)?n.alias:[n.alias]).forEach(function(i){var a={path:i,children:n.children};L(t,e,r,a,o,p.path||"/")}),e[p.path]||(t.push(p.path),e[p.path]=p),u&&(r[u]||(r[u]=p))}function P(t, e){return Mt(t,[],e)}function U(t, e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:g(e.path+"/"+t)}function H(t, e, r, o){var i="string"==typeof t?{path:t}:t;if(i.name||i._normalized)return i;if(!i.path&&i.params&&e){(i=I({},i))._normalized=!0;var a=I(I({},e.params),i.params);if(e.name)i.name=e.name,i.params=a;else if(e.matched.length){var u=e.matched[e.matched.length-1].path;i.path=S(u,a,"path "+e.path)}return i}var c=m(i.path||""),s=e&&e.path||"/",p=c.path?v(c.path,s,r||i.append):s,f=n(c.query,i.query,o&&o.options.parseQuery),h=i.hash||c.hash;return h&&"#"!==h.charAt(0)&&(h="#"+h),{_normalized:!0,path:p,query:f,hash:h}}function I(t, e){for(var r in e)t[r]=e[r];return t}function M(t, e){function r(t, r, n){var o=H(t,r,!1,e),a=o.name;if(a){var u=p[a];if(!u)return i(null,o);var f=u.regex.keys.filter(function(t){return!t.optional}).map(function(t){return t.name});if("object"!=typeof o.params&&(o.params={}),r&&"object"==typeof r.params)for(var h in r.params)!(h in o.params)&&f.indexOf(h)>-1&&(o.params[h]=r.params[h]);if(u)return o.path=S(u.path,o.params,'named route "'+a+'"'),i(u,o,n)}else if(o.path){o.params={};for(var l=0; l<c.length; l++){var d=c[l],y=s[d];if(V(y.regex,o.path,o.params))return i(y,o,n)}}return i(null,o)}function n(t, n){var o=t.redirect,u="function"==typeof o?o(a(t,n,null,e)):o;if("string"==typeof u&&(u={path:u}),!u||"object"!=typeof u)return i(null,n);var c=u,s=c.name,f=c.path,h=n.query,l=n.hash,d=n.params;if(h=c.hasOwnProperty("query")?c.query:h,l=c.hasOwnProperty("hash")?c.hash:l,d=c.hasOwnProperty("params")?c.params:d,s){p[s];return r({_normalized:!0,name:s,query:h,hash:l,params:d},void 0,n)}if(f){var y=z(f,t);return r({_normalized:!0,path:S(y,d,'redirect route with path "'+y+'"'),query:h,hash:l},void 0,n)}return i(null,n)}function o(t, e, n){var o=r({_normalized:!0,path:S(n,e.params,'aliased route with path "'+n+'"')});if(o){var a=o.matched,u=a[a.length-1];return e.params=o.params,i(u,e)}return i(null,e)}function i(t, r, i){return t&&t.redirect?n(t,i||r):t&&t.matchAs?o(t,r,t.matchAs):a(t,r,i,e)}var u=q(t),c=u.pathList,s=u.pathMap,p=u.nameMap;return{match:r,addRoutes:function(t){q(t,c,s,p)}}}function V(t, e, r){var n=e.match(t);if(!n)return!1;if(!r)return!0;for(var o=1,i=n.length; o<i; ++o){var a=t.keys[o-1],u="string"==typeof n[o]?decodeURIComponent(n[o]):n[o];a&&(r[a.name]=u)}return!0}function z(t, e){return v(t,e.parent?e.parent.path:"/",!0)}function B(){window.addEventListener("popstate",function(t){D(),t.state&&t.state.key&&Z(t.state.key)})}function F(t, e, r, n){if(t.app){var o=t.options.scrollBehavior;o&&t.app.$nextTick(function(){var t=K(),i=o(e,r,n?t:null);if(i){var a="object"==typeof i;if(a&&"string"==typeof i.selector){var u=document.querySelector(i.selector);if(u){var c=i.offset&&"object"==typeof i.offset?i.offset:{};t=J(u,c=X(c))}else N(i)&&(t=Q(i))}else a&&N(i)&&(t=Q(i));t&&window.scrollTo(t.x,t.y)}})}}function D(){var t=G();t&&(Kt[t]={x:window.pageXOffset,y:window.pageYOffset})}function K(){var t=G();if(t)return Kt[t]}function J(t, e){var r=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-r.left-e.x,y:n.top-r.top-e.y}}function N(t){return Y(t.x)||Y(t.y)}function Q(t){return{x:Y(t.x)?t.x:window.pageXOffset,y:Y(t.y)?t.y:window.pageYOffset}}function X(t){return{x:Y(t.x)?t.x:0,y:Y(t.y)?t.y:0}}function Y(t){return"number"==typeof t}function W(){return Nt.now().toFixed(3)}function G(){return Qt}function Z(t){Qt=t}function tt(t, e){D();var r=window.history;try{e?r.replaceState({key:Qt},"",t):(Qt=W(),r.pushState({key:Qt},"",t))}catch(r){window.location[e?"replace":"assign"](t)}}function et(t){tt(t,!0)}function rt(t, e, r){var n=function(o){o>=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}function nt(t){return function(r, n, o){var i=!1,a=0,u=null;ot(t,function(t, r, n, c){if("function"==typeof t&&void 0===t.cid){i=!0,a++;var s,p=at(function(e){e.__esModule&&e.default&&(e=e.default),t.resolved="function"==typeof e?e:Ot.extend(e),n.components[c]=e,--a<=0&&o()}),f=at(function(t){var r="Failed to resolve async component "+c+": "+t;u||(u=e(t)?t:new Error(r),o(u))});try{s=t(p,f)}catch(t){f(t)}if(s)if("function"==typeof s.then)s.then(p,f);else{var h=s.component;h&&"function"==typeof h.then&&h.then(p,f)}}}),i||o()}}function ot(t, e){return it(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function it(t){return Array.prototype.concat.apply([],t)}function at(t){var e=!1;return function(){for(var r=[],n=arguments.length; n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}function ut(t){if(!t)if(Ht){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function ct(t, e){var r,n=Math.max(t.length,e.length);for(r=0; r<n&&t[r]===e[r]; r++);return{updated:e.slice(0,r),activated:e.slice(r),deactivated:t.slice(r)}}function st(t, e, r, n){var o=ot(t,function(t, n, o, i){var a=pt(t,e);if(a)return Array.isArray(a)?a.map(function(t){return r(t,n,o,i)}):r(a,n,o,i)});return it(n?o.reverse():o)}function pt(t, e){return"function"!=typeof t&&(t=Ot.extend(t)),t.options[e]}function ft(t){return st(t,"beforeRouteLeave",lt,!0)}function ht(t){return st(t,"beforeRouteUpdate",lt)}function lt(t, e){if(e)return function(){return t.apply(e,arguments)}}function dt(t, e, r){return st(t,"beforeRouteEnter",function(t, n, o, i){return yt(t,o,i,e,r)})}function yt(t, e, r, n, o){return function(i, a, u){return t(i,a,function(t){u(t),"function"==typeof t&&n.push(function(){vt(t,e.instances,r,o)})})}}function vt(t, e, r, n){e[r]?t(e[r]):n()&&setTimeout(function(){vt(t,e,r,n)},16)}function mt(t){var e=window.location.pathname;return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}function gt(t){var e=mt(t);if(!/^\/#/.test(e))return window.location.replace(g(t+"/#"+e)),!0}function bt(){var t=wt();return"/"===t.charAt(0)||(kt("/"+t),!1)}function wt(){var t=window.location.href,e=t.indexOf("#");return-1===e?"":t.slice(e+1)}function xt(t){window.location.hash=t}function kt(t){var e=window.location.href,r=e.indexOf("#"),n=r>=0?e.slice(0,r):e;window.location.replace(n+"#"+t)}function Rt(t, e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}function Et(t, e, r){var n="hash"===r?"#"+e:e;return t?g(t+"/"+n):n}var Ot,Ct={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t, e){var n=e.props,o=e.children,i=e.parent,a=e.data;a.routerView=!0;for(var u=i.$createElement,c=n.name,s=i.$route,p=i._routerViewCache||(i._routerViewCache={}),f=0,h=!1; i&&i._routerRoot!==i;)i.$vnode&&i.$vnode.data.routerView&&f++,i._inactive&&(h=!0),i=i.$parent;if(a.routerViewDepth=f,h)return u(p[c],a,o);var l=s.matched[f];if(!l)return p[c]=null,u();var d=p[c]=l.components[c];return a.registerRouteInstance=function(t, e){var r=l.instances[c];(e&&r!==t||!e&&r===t)&&(l.instances[c]=e)},(a.hook||(a.hook={})).prepatch=function(t, e){l.instances[c]=e.componentInstance},a.props=r(s,l.props&&l.props[c]),u(d,a,o)}},At=/[!'()*]/g,jt=function(t){return"%"+t.charCodeAt(0).toString(16)},_t=/%2C/g,Tt=function(t){return encodeURIComponent(t).replace(At,jt).replace(_t,",")},$t=decodeURIComponent,St=/\/?$/,qt=a(null,{path:"/"}),Lt=[String,Object],Pt=[String,Array],Ut={name:"router-link",props:{to:{type:Lt,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:Pt,default:"click"}},render:function(t){var e=this,r=this.$router,n=this.$route,o=r.resolve(this.to,n,this.append),i=o.location,u=o.route,c=o.href,p={},h=r.options.linkActiveClass,y=r.options.linkExactActiveClass,v=null==h?"router-link-active":h,m=null==y?"router-link-exact-active":y,g=null==this.activeClass?v:this.activeClass,b=null==this.exactActiveClass?m:this.exactActiveClass,w=i.path?a(null,i,null,r):u;p[b]=s(n,w),p[g]=this.exact?p[b]:f(n,w);var x=function(t){l(t)&&(e.replace?r.replace(i):r.push(i))},k={click:l};Array.isArray(this.event)?this.event.forEach(function(t){k[t]=x}):k[this.event]=x;var R={class:p};if("a"===this.tag)R.on=k,R.attrs={href:c};else{var E=d(this.$slots.default);if(E){E.isStatic=!1;var O=Ot.util.extend;(E.data=O({},E.data)).on=k,(E.data.attrs=O({},E.data.attrs)).href=c}else R.on=k}return t(this.tag,R,this.$slots.default)}},Ht="undefined"!=typeof window,It=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},Mt=$,Vt=b,zt=k,Bt=T,Ft=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");Mt.parse=Vt,Mt.compile=function(t, e){return k(b(t,e))},Mt.tokensToFunction=zt,Mt.tokensToRegExp=Bt;var Dt=Object.create(null),Kt=Object.create(null),Jt=Ht&&function(){var t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)}(),Nt=Ht&&window.performance&&window.performance.now?window.performance:Date,Qt=W(),Xt=function(t, e){this.router=t,this.base=ut(e),this.current=qt,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};Xt.prototype.listen=function(t){this.cb=t},Xt.prototype.onReady=function(t, e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},Xt.prototype.onError=function(t){this.errorCbs.push(t)},Xt.prototype.transitionTo=function(t, e, r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(t){r&&r(t),t&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(e){e(t)}))})},Xt.prototype.confirmTransition=function(r, n, o){var i=this,a=this.current,u=function(r){e(r)&&(i.errorCbs.length?i.errorCbs.forEach(function(t){t(r)}):(t(!1,"uncaught error during route navigation:"),console.error(r))),o&&o(r)};if(s(r,a)&&r.matched.length===a.matched.length)return this.ensureURL(),u();var c=ct(this.current.matched,r.matched),p=c.updated,f=c.deactivated,h=c.activated,l=[].concat(ft(f),this.router.beforeHooks,ht(p),h.map(function(t){return t.beforeEnter}),nt(h));this.pending=r;var d=function(t, n){if(i.pending!==r)return u();try{t(r,a,function(t){!1===t||e(t)?(i.ensureURL(!0),u(t)):"string"==typeof t||"object"==typeof t&&("string"==typeof t.path||"string"==typeof t.name)?(u(),"object"==typeof t&&t.replace?i.replace(t):i.push(t)):n(t)})}catch(t){u(t)}};rt(l,d,function(){var t=[];rt(dt(h,t,function(){return i.current===r}).concat(i.router.resolveHooks),d,function(){if(i.pending!==r)return u();i.pending=null,n(r),i.router.app&&i.router.app.$nextTick(function(){t.forEach(function(t){t()})})})})},Xt.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(r){r&&r(t,e)})};var Yt=function(t){function e(e, r){var n=this;t.call(this,e,r);var o=e.options.scrollBehavior;o&&B(),window.addEventListener("popstate",function(t){var r=n.current;n.transitionTo(mt(n.base),function(t){o&&F(e,t,r,!0)})})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t, e, r){var n=this,o=this.current;this.transitionTo(t,function(t){tt(g(n.base+t.fullPath)),F(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t, e, r){var n=this,o=this.current;this.transitionTo(t,function(t){et(g(n.base+t.fullPath)),F(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(mt(this.base)!==this.current.fullPath){var e=g(this.base+this.current.fullPath);t?tt(e):et(e)}},e.prototype.getCurrentLocation=function(){return mt(this.base)},e}(Xt),Wt=function(t){function e(e, r, n){t.call(this,e,r),n&>(this.base)||bt()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this;window.addEventListener("hashchange",function(){bt()&&t.transitionTo(wt(),function(t){kt(t.fullPath)})})},e.prototype.push=function(t, e, r){this.transitionTo(t,function(t){xt(t.fullPath),e&&e(t)},r)},e.prototype.replace=function(t, e, r){this.transitionTo(t,function(t){kt(t.fullPath),e&&e(t)},r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;wt()!==e&&(t?xt(e):kt(e))},e.prototype.getCurrentLocation=function(){return wt()},e}(Xt),Gt=function(t){function e(e, r){t.call(this,e,r),this.stack=[],this.index=-1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(t, e, r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)},r)},e.prototype.replace=function(t, e, r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)},r)},e.prototype.go=function(t){var e=this,r=this.index+t;if(!(r<0||r>=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,function(){e.index=r,e.updateRoute(n)})}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(Xt),Zt=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=M(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!Jt&&!1!==t.fallback,this.fallback&&(e="hash"),Ht||(e="abstract"),this.mode=e,e){case"history":this.history=new Yt(this,t.base);break;case"hash":this.history=new Wt(this,t.base,this.fallback);break;case"abstract":this.history=new Gt(this,t.base)}},te={currentRoute:{}};return Zt.prototype.match=function(t, e, r){return this.matcher.match(t,e,r)},te.currentRoute.get=function(){return this.history&&this.history.current},Zt.prototype.init=function(t){var e=this;if(this.apps.push(t),!this.app){this.app=t;var r=this.history;if(r instanceof Yt)r.transitionTo(r.getCurrentLocation());else if(r instanceof Wt){var n=function(){r.setupListeners()};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},Zt.prototype.beforeEach=function(t){return Rt(this.beforeHooks,t)},Zt.prototype.beforeResolve=function(t){return Rt(this.resolveHooks,t)},Zt.prototype.afterEach=function(t){return Rt(this.afterHooks,t)},Zt.prototype.onReady=function(t, e){this.history.onReady(t,e)},Zt.prototype.onError=function(t){this.history.onError(t)},Zt.prototype.push=function(t, e, r){this.history.push(t,e,r)},Zt.prototype.replace=function(t, e, r){this.history.replace(t,e,r)},Zt.prototype.go=function(t){this.history.go(t)},Zt.prototype.back=function(){this.go(-1)},Zt.prototype.forward=function(){this.go(1)},Zt.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Zt.prototype.resolve=function(t, e, r){var n=H(t,e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:Et(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Zt.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==qt&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Zt.prototype,te),Zt.install=y,Zt.version="2.7.0",Ht&&window.Kdu&&window.Kdu.use(Zt),Zt});
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.KduRouter=e()}(this,function(){"use strict";function f(t){return-1<Object.prototype.toString.call(t).indexOf("Error")}var U={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){for(var r=e.props,n=e.children,o=e.parent,e=e.data,i=(e.routerView=!0,o.$createElement),a=r.name,r=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o&&o._routerRoot!==o;)o.$knode&&o.$knode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;if(e.routerViewDepth=c,s)return i(u[a],e,n);var p=r.matched[c];if(!p)return u[a]=null,i();var h=u[a]=p.components[a];if(e.registerRouteInstance=function(t,e){var r=p.instances[a];(e&&r!==t||!e&&r===t)&&(p.instances[a]=e)},(e.hook||(e.hook={})).prepatch=function(t,e){p.instances[a]=e.componentInstance},l=e.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(r,p.props&&p.props[a])){var f,l=e.props=function(t,e){for(var r in e)t[r]=e[r];return t}({},l),d=e.attrs=e.attrs||{};for(f in l)h.props&&f in h.props||(d[f]=l[f],delete l[f])}return i(h,e,n)}};function o(t){return encodeURIComponent(t).replace(M,H).replace(I,",")}var M=/[!'()*]/g,H=function(t){return"%"+t.charCodeAt(0).toString(16)},I=/%2C/g,z=decodeURIComponent;function B(t){var r={};return(t=t.trim().replace(/^(\?|#|&)/,""))&&t.split("&").forEach(function(t){var t=t.replace(/\+/g," ").split("="),e=z(t.shift()),t=0<t.length?z(t.join("=")):null;void 0===r[e]?r[e]=t:Array.isArray(r[e])?r[e].push(t):r[e]=[r[e],t]}),r}function K(n){var t=n?Object.keys(n).map(function(e){var r,t=n[e];return void 0===t?"":null===t?o(e):Array.isArray(t)?(r=[],t.forEach(function(t){void 0!==t&&r.push(null===t?o(e):o(e)+"="+o(t))}),r.join("&")):o(e)+"="+o(t)}).filter(function(t){return 0<t.length}).join("&"):null;return t?"?"+t:""}var r=/\/?$/;function d(t,e,r,n){var n=n&&n.options.stringifyQuery,o=e.query||{};try{o=i(o)}catch(t){}o={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:o,params:e.params||{},fullPath:F(e,n),matched:t?function(t){var e=[];for(;t;)e.unshift(t),t=t.parent;return e}(t):[]};return r&&(o.redirectedFrom=F(r,n)),Object.freeze(o)}function i(t){if(Array.isArray(t))return t.map(i);if(t&&"object"==typeof t){var e,r={};for(e in t)r[e]=i(t[e]);return r}return t}var u=d(null,{path:"/"});function F(t,e){var r=t.path,n=t.query,t=t.hash;return void 0===t&&(t=""),(r||"/")+(e||K)(n=void 0===n?{}:n)+t}function V(t,e){return e===u?t===e:!!e&&(t.path&&e.path?t.path.replace(r,"")===e.path.replace(r,"")&&t.hash===e.hash&&a(t.query,e.query):!(!t.name||!e.name)&&t.name===e.name&&t.hash===e.hash&&a(t.query,e.query)&&a(t.params,e.params))}function a(r,n){var t,e;return void 0===n&&(n={}),(r=void 0===r?{}:r)&&n?(t=Object.keys(r),e=Object.keys(n),t.length===e.length&&t.every(function(t){var e=r[t],t=n[t];return"object"==typeof e&&"object"==typeof t?a(e,t):String(e)===String(t)})):r===n}function D(t,e){return 0===t.path.replace(r,"/").indexOf(e.path.replace(r,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}var l,t=[String,Object],e=[String,Array],J={name:"router-link",props:{to:{type:t,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:e,default:"click"}},render:function(t){function e(t){N(t)&&(r.replace?n.replace(a):n.push(a))}var r=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,u=i.route,i=i.href,c={},s=n.options.linkActiveClass,p=n.options.linkExactActiveClass,s=null==this.activeClass?null==s?"router-link-active":s:this.activeClass,p=null==this.exactActiveClass?null==p?"router-link-exact-active":p:this.exactActiveClass,u=a.path?d(null,a,null,n):u,h=(c[p]=V(o,u),c[s]=this.exact?c[p]:D(o,u),{click:N}),s=(Array.isArray(this.event)?this.event.forEach(function(t){h[t]=e}):h[this.event]=e,{class:c});return"a"===this.tag?(s.on=h,s.attrs={href:i}):(p=function t(e){if(e)for(var r,n=0;n<e.length;n++){if("a"===(r=e[n]).tag)return r;if(r.children&&(r=t(r.children)))return r}}(this.$slots.default))?(p.isStatic=!1,o=l.util.extend,(p.data=o({},p.data)).on=h,(p.data.attrs=o({},p.data.attrs)).href=i):s.on=h,t(this.tag,s,this.$slots.default)}};function N(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function c(t){var n,e,r;c.installed&&l===t||(c.installed=!0,n=function(t){return void 0!==t},e=function(t,e){var r=t.$options._parentKnode;n(r)&&n(r=r.data)&&n(r=r.registerRouteInstance)&&r(t,e)},(l=t).mixin({beforeCreate:function(){n(this.$options.router)?((this._routerRoot=this)._router=this.$options.router,this._router.init(this),t.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,e(this,this)},destroyed:function(){e(this)}}),Object.defineProperty(t.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this._routerRoot._route}}),t.component("router-view",U),t.component("router-link",J),(r=t.config.optionMergeStrategies).beforeRouteEnter=r.beforeRouteLeave=r.beforeRouteUpdate=r.created)}var n="undefined"!=typeof window;function Q(t,e,r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;for(var o=e.split("/"),i=(r&&o[o.length-1]||o.pop(),t.replace(/^\//,"").split("/")),a=0;a<i.length;a++){var u=i[a];".."===u?o.pop():"."!==u&&o.push(u)}return""!==o[0]&&o.unshift(""),o.join("/")}function h(t){return t.replace(/\/\//g,"/")}function X(t,e){return Z(v(t,e),e)}var y=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},s=et,t=v,e=Z,Y=tt,W=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function v(t,e){for(var r=[],n=0,o=0,i="",a=e&&e.delimiter||"/";null!=(h=W.exec(t));){var u,c,s,p,h,f=h[0],l=h[1],d=h.index;i+=t.slice(o,d),o=d+f.length,l?i+=l[1]:(d=t[o],f=h[2],l=h[3],u=h[4],c=h[5],s=h[6],p=h[7],d=(i&&(r.push(i),i=""),null!=f&&null!=d&&d!==f),h=h[2]||a,r.push({name:l||n++,prefix:f||"",delimiter:h,optional:"?"===s||"*"===s,repeat:"+"===s||"*"===s,partial:d,asterisk:!!p,pattern:(l=u||c)?l.replace(/([=!:$\/()])/g,"\\$1"):p?".*":"[^"+m(h)+"]+?"}))}return o<t.length&&(i+=t.substr(o)),i&&r.push(i),r}function G(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function Z(p,t){for(var h=new Array(p.length),e=0;e<p.length;e++)"object"==typeof p[e]&&(h[e]=new RegExp("^(?:"+p[e].pattern+")$",b(t)));return function(t,e){for(var r="",n=t||{},o=(e||{}).pretty?G:encodeURIComponent,i=0;i<p.length;i++){var a=p[i];if("string"==typeof a)r+=a;else{var u,c=n[a.name];if(null==c){if(a.optional){a.partial&&(r+=a.prefix);continue}throw new TypeError('Expected "'+a.name+'" to be defined')}if(y(c)){if(!a.repeat)throw new TypeError('Expected "'+a.name+'" to not repeat, but received `'+JSON.stringify(c)+"`");if(0===c.length){if(a.optional)continue;throw new TypeError('Expected "'+a.name+'" to not be empty')}for(var s=0;s<c.length;s++){if(u=o(c[s]),!h[i].test(u))throw new TypeError('Expected all "'+a.name+'" to match "'+a.pattern+'", but received `'+JSON.stringify(u)+"`");r+=(0===s?a.prefix:a.delimiter)+u}}else{if(u=a.asterisk?encodeURI(c).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}):o(c),!h[i].test(u))throw new TypeError('Expected "'+a.name+'" to match "'+a.pattern+'", but received "'+u+'"');r+=a.prefix+u}}}return r}}function m(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function g(t,e){return t.keys=e,t}function b(t){return t&&t.sensitive?"":"i"}function tt(t,e,r){y(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,o=!1!==r.end,i="",a=0;a<t.length;a++){var u,c,s=t[a];"string"==typeof s?i+=m(s):(u=m(s.prefix),c="(?:"+s.pattern+")",e.push(s),s.repeat&&(c+="(?:"+u+c+")*"),i+=c=s.optional?s.partial?u+"("+c+")?":"(?:"+u+"("+c+"))?":u+"("+c+")")}var p=m(r.delimiter||"/"),h=i.slice(-p.length)===p;return n||(i=(h?i.slice(0,-p.length):i)+"(?:"+p+"(?=$))?"),i+=o?"$":n&&h?"":"(?="+p+"|$)",g(new RegExp("^"+i,b(r)),e)}function et(t,e,r){if(y(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp){var n=t,o=e,i=n.source.match(/\((?!\?)/g);if(i)for(var a=0;a<i.length;a++)o.push({name:a,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return g(n,o)}if(y(t)){for(var u=t,c=e,s=r,p=[],h=0;h<u.length;h++)p.push(et(u[h],c,s).source);return g(new RegExp("(?:"+p.join("|")+")",b(s)),c)}return n=e,tt(v(t,e=r),n,e)}s.parse=t,s.compile=X,s.tokensToFunction=e,s.tokensToRegExp=Y;var rt=Object.create(null);function w(t,e){try{return(rt[t]||(rt[t]=s.compile(t)))(e||{},{pretty:!0})}catch(t){return""}}function nt(t,e,r,n){var o=e||[],i=r||Object.create(null),a=n||Object.create(null);t.forEach(function(t){!function r(n,o,i,e,a,u){var t=e.path;var c=e.name;var s=e.pathToRegexpOptions||{};t=it(t,a,s.strict);"boolean"==typeof e.caseSensitive&&(s.sensitive=e.caseSensitive);var p={path:t,regex:ot(t,s),components:e.components||{default:e.component},instances:{},name:c,parent:a,matchAs:u,redirect:e.redirect,beforeEnter:e.beforeEnter,meta:e.meta||{},props:null==e.props?{}:e.components?e.props:{default:e.props}};e.children&&e.children.forEach(function(t){var e=u?h(u+"/"+t.path):void 0;r(n,o,i,t,p,e)});void 0!==e.alias&&(Array.isArray(e.alias)?e.alias:[e.alias]).forEach(function(t){t={path:t,children:e.children};r(n,o,i,t,a,p.path||"/")});o[p.path]||(n.push(p.path),o[p.path]=p);!c||i[c]||(i[c]=p)}(o,i,a,t)});for(var u=0,c=o.length;u<c;u++)"*"===o[u]&&(o.push(o.splice(u,1)[0]),c--,u--);return{pathList:o,pathMap:i,nameMap:a}}function ot(t,e){return s(t,[],e)}function it(t,e,r){return"/"===(t=r?t:t.replace(/\/$/,""))[0]||null==e?t:h(e.path+"/"+t)}function at(t,e,r,n){var o,i,a,u,t="string"==typeof t?{path:t}:t;return t.name||t._normalized?t:!t.path&&t.params&&e?((t=ut({},t))._normalized=!0,i=ut(ut({},e.params),t.params),e.name?(t.name=e.name,t.params=i):e.matched.length&&(o=e.matched[e.matched.length-1].path,t.path=w(o,i,e.path)),t):(o=t.path||"",u=i="",0<=(a=o.indexOf("#"))&&(i=o.slice(a),o=o.slice(0,a)),0<=(a=o.indexOf("?"))&&(u=o.slice(a+1),o=o.slice(0,a)),a=e&&e.path||"/",{_normalized:!0,path:(e={path:o,query:u,hash:i}).path?Q(e.path,a,r||t.append):a,query:function(t,e,r){void 0===e&&(e={});var n,o,r=r||B;try{n=r(t||"")}catch(t){n={}}for(o in e)n[o]=e[o];return n}(e.query,t.query,n&&n.options.parseQuery),hash:u=(u=t.hash||e.hash)&&"#"!==u.charAt(0)?"#"+u:u})}function ut(t,e){for(var r in e)t[r]=e[r];return t}function ct(t,c){var t=nt(t),s=t.pathList,p=t.pathMap,h=t.nameMap;function f(t,e,r){var n=at(t,e,!1,c),t=n.name;if(t){t=h[t];if(!t)return l(null,n);var o=t.regex.keys.filter(function(t){return!t.optional}).map(function(t){return t.name});if("object"!=typeof n.params&&(n.params={}),e&&"object"==typeof e.params)for(var i in e.params)!(i in n.params)&&-1<o.indexOf(i)&&(n.params[i]=e.params[i]);if(t)return n.path=w(t.path,n.params),l(t,n,r)}else if(n.path){n.params={};for(var a=0;a<s.length;a++){var u=s[a],u=p[u];if(function(t,e,r){var n=e.match(t);{if(!n)return;if(!r)return 1}for(var o=1,i=n.length;o<i;++o){var a=t.keys[o-1],u="string"==typeof n[o]?decodeURIComponent(n[o]):n[o];a&&(r[a.name]=u)}return 1}(u.regex,n.path,n.params))return l(u,n,r)}}return l(null,n)}function a(t,e){var r,n,o,i,a,u=t.redirect,u="function"==typeof u?u(d(t,e,null,c)):u;return(u="string"==typeof u?{path:u}:u)&&"object"==typeof u?(r=(u=u).name,n=u.path,o=e.query,i=e.hash,a=e.params,o=u.hasOwnProperty("query")?u.query:o,i=u.hasOwnProperty("hash")?u.hash:i,a=u.hasOwnProperty("params")?u.params:a,r?f({_normalized:!0,name:r,query:o,hash:i,params:a},void 0,e):n?f({_normalized:!0,path:w(Q(n,(u=t).parent?u.parent.path:"/",!0),a),query:o,hash:i},void 0,e):l(null,e)):l(null,e)}function l(t,e,r){var n,o,i;return t&&t.redirect?a(t,r||e):t&&t.matchAs?(n=e,(o=f({_normalized:!0,path:w(o=t.matchAs,n.params)}))?(i=(i=o.matched)[i.length-1],n.params=o.params,l(i,n)):l(null,n)):d(t,e,r,c)}return{match:f,addRoutes:function(t){nt(t,s,p,h)}}}var st=Object.create(null);function pt(){window.history.replaceState({key:R},""),window.addEventListener("popstate",function(t){ht(),t.state&&t.state.key&&(t=t.state.key,R=t)})}function p(t,r,n,o){var i;t.app&&(i=t.options.scrollBehavior)&&t.app.$nextTick(function(){var e=function(){var t=R;if(t)return st[t]}(),t=i(r,n,o?e:null);t&&("function"==typeof t.then?t.then(function(t){dt(t,e)}).catch(function(t){}):dt(t,e))})}function ht(){R&&(st[R]={x:window.pageXOffset,y:window.pageYOffset})}function ft(t){return x(t.x)||x(t.y)}function lt(t){return{x:x(t.x)?t.x:window.pageXOffset,y:x(t.y)?t.y:window.pageYOffset}}function x(t){return"number"==typeof t}function dt(t,e){var r,n,o,i="object"==typeof t;i&&"string"==typeof t.selector?(r=document.querySelector(t.selector))?(n=t.offset&&"object"==typeof t.offset?t.offset:{},n={x:x((o=n).x)?o.x:0,y:x(o.y)?o.y:0},o=r,r=n,n=document.documentElement.getBoundingClientRect(),e={x:(o=o.getBoundingClientRect()).left-n.left-r.x,y:o.top-n.top-r.y}):ft(t)&&(e=lt(t)):i&&ft(t)&&(e=lt(t)),e&&window.scrollTo(e.x,e.y)}var k=n&&(-1===(t=window.navigator.userAgent).indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&window.history&&"pushState"in window.history,yt=n&&window.performance&&window.performance.now?window.performance:Date,R=vt();function vt(){return yt.now().toFixed(3)}function E(e,r){ht();var t=window.history;try{r?t.replaceState({key:R},"",e):(R=vt(),t.pushState({key:R},"",e))}catch(t){window.location[r?"replace":"assign"](e)}}function mt(t){E(t,!0)}function gt(e,r,n){function o(t){t>=e.length?n():e[t]?r(e[t],function(){o(t+1)}):o(t+1)}o(0)}function bt(r){return function(t,e,u){var c=!1,s=0,p=null;wt(r,function(r,t,n,o){if("function"==typeof r&&void 0===r.cid){c=!0,s++;var e,i=Rt(function(t){var e;((e=t).__esModule||kt&&"Module"===e[Symbol.toStringTag])&&(t=t.default),r.resolved="function"==typeof t?t:l.extend(t),n.components[o]=t,--s<=0&&u()}),a=Rt(function(t){var e="Failed to resolve async component "+o+": "+t;p||(p=f(t)?t:new Error(e),u(p))});try{e=r(i,a)}catch(t){a(t)}e&&("function"==typeof e.then?e.then(i,a):(e=e.component)&&"function"==typeof e.then&&e.then(i,a))}}),c||u()}}function wt(t,r){return xt(t.map(function(e){return Object.keys(e.components).map(function(t){return r(e.components[t],e.instances[t],e,t)})}))}function xt(t){return Array.prototype.concat.apply([],t)}var kt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function Rt(r){var n=!1;return function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!n)return n=!0,r.apply(this,t)}}function O(t,e){this.router=t,this.base=function(t){{var e;t=t||(n?(e=document.querySelector("base"),(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")):"/")}"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=u,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]}function Et(t,o,i,e){t=wt(t,function(t,e,r,n){t=function(t,e){"function"!=typeof t&&(t=l.extend(t));return t.options[e]}(t,o);if(t)return Array.isArray(t)?t.map(function(t){return i(t,e,r,n)}):i(t,e,r,n)});return xt(e?t.reverse():t)}function Ot(t,e){if(e)return function(){return t.apply(e,arguments)}}O.prototype.listen=function(t){this.cb=t},O.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},O.prototype.onError=function(t){this.errorCbs.push(t)},O.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(e){r&&r(e),e&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(t){t(e)}))})},O.prototype.confirmTransition=function(r,e,t){var n=this,o=this.current,i=function(e){f(e)&&(n.errorCbs.length?n.errorCbs.forEach(function(t){t(e)}):console.error(e)),t&&t(e)};if(V(r,o)&&r.matched.length===o.matched.length)return this.ensureURL(),i();function a(t,e){if(n.pending!==r)return i();try{t(r,o,function(t){!1===t||f(t)?(n.ensureURL(!0),i(t)):"string"==typeof t||"object"==typeof t&&("string"==typeof t.path||"string"==typeof t.name)?(i(),"object"==typeof t&&t.replace?n.replace(t):n.push(t)):e(t)})}catch(t){i(t)}}var u=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r<n&&t[r]===e[r];r++);return{updated:e.slice(0,r),activated:e.slice(r),deactivated:t.slice(r)}}(this.current.matched,r.matched),c=u.updated,s=u.deactivated,h=u.activated,u=[].concat(Et(s,"beforeRouteLeave",Ot,!0),this.router.beforeHooks,Et(c,"beforeRouteUpdate",Ot),h.map(function(t){return t.beforeEnter}),bt(h));this.pending=r;gt(u,a,function(){var s,p,t=[];s=t,p=function(){return n.current===r},gt(Et(h,"beforeRouteEnter",function(t,e,r,n){return o=t,i=r,a=n,u=s,c=p,function(t,e,r){return o(t,e,function(t){r(t),"function"==typeof t&&u.push(function(){!function t(e,r,n,o){r[n]?e(r[n]):o()&&setTimeout(function(){t(e,r,n,o)},16)}(t,i.instances,a,c)})})};var o,i,a,u,c}).concat(n.router.resolveHooks),a,function(){if(n.pending!==r)return i();n.pending=null,e(r),n.router.app&&n.router.app.$nextTick(function(){t.forEach(function(t){t()})})})})},O.prototype.updateRoute=function(e){var r=this.current;this.current=e,this.cb&&this.cb(e),this.router.afterHooks.forEach(function(t){t&&t(e,r)})};(C=O)&&(j.__proto__=C),((j.prototype=Object.create(C&&C.prototype)).constructor=j).prototype.go=function(t){window.history.go(t)},j.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){E(h(n.base+t.fullPath)),p(n.router,t,o,!1),e&&e(t)},r)},j.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){mt(h(n.base+t.fullPath)),p(n.router,t,o,!1),e&&e(t)},r)},j.prototype.ensureURL=function(t){A(this.base)!==this.current.fullPath&&(t?E:mt)(h(this.base+this.current.fullPath))},j.prototype.getCurrentLocation=function(){return A(this.base)};var C,Ct=j;function j(n,t){var o=this,i=(C.call(this,n,t),n.options.scrollBehavior),a=(i&&pt(),A(this.base));window.addEventListener("popstate",function(t){var e=o.current,r=A(o.base);o.current===u&&r===a||o.transitionTo(r,function(t){i&&p(n,t,e,!0)})})}function A(t){var e=window.location.pathname;return((e=t&&0===e.indexOf(t)?e.slice(t.length):e)||"/")+window.location.search+window.location.hash}(_=O)&&(T.__proto__=_),((T.prototype=Object.create(_&&_.prototype)).constructor=T).prototype.setupListeners=function(){var r=this,t=this.router.options.scrollBehavior,n=k&&t;n&&pt(),window.addEventListener(k?"popstate":"hashchange",function(){var e=r.current;At()&&r.transitionTo(S(),function(t){n&&p(r.router,t,e,!0),k||$(t.fullPath)})})},T.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Tt(t.fullPath),p(n.router,t,o,!1),e&&e(t)},r)},T.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){$(t.fullPath),p(n.router,t,o,!1),e&&e(t)},r)},T.prototype.go=function(t){window.history.go(t)},T.prototype.ensureURL=function(t){var e=this.current.fullPath;S()!==e&&(t?Tt:$)(e)},T.prototype.getCurrentLocation=S;var _,jt=T;function T(t,e,r){_.call(this,t,e),r&&function(t){var e=A(t);if(!/^\/#/.test(e))return window.location.replace(h(t+"/#"+e)),1}(this.base)||At()}function At(){var t=S();if("/"===t.charAt(0))return 1;$("/"+t)}function S(){var t=window.location.href,e=t.indexOf("#");return-1===e?"":t.slice(e+1)}function _t(t){var e=window.location.href,r=e.indexOf("#");return(0<=r?e.slice(0,r):e)+"#"+t}function Tt(t){k?E(_t(t)):window.location.hash=t}function $(t){k?mt(_t(t)):window.location.replace(_t(t))}(q=O)&&(L.__proto__=q),((L.prototype=Object.create(q&&q.prototype)).constructor=L).prototype.push=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)},r)},L.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)},r)},L.prototype.go=function(t){var e,r=this,n=this.index+t;n<0||n>=this.stack.length||(e=this.stack[n],this.confirmTransition(e,function(){r.index=n,r.updateRoute(e)}))},L.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},L.prototype.ensureURL=function(){};var q,St=L;function L(t,e){q.call(this,t,e),this.stack=[],this.index=-1}function P(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=ct(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!k&&!1!==t.fallback,this.fallback&&(e="hash"),this.mode=e=n?e:"abstract"){case"history":this.history=new Ct(this,t.base);break;case"hash":this.history=new jt(this,t.base,this.fallback);break;case"abstract":this.history=new St(this,t.base)}}e={currentRoute:{configurable:!0}};function $t(e,r){return e.push(r),function(){var t=e.indexOf(r);-1<t&&e.splice(t,1)}}return P.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},e.currentRoute.get=function(){return this.history&&this.history.current},P.prototype.init=function(t){var e,r=this;this.apps.push(t),this.app||(this.app=t,(e=this.history)instanceof Ct?e.transitionTo(e.getCurrentLocation()):e instanceof jt&&(t=function(){e.setupListeners()},e.transitionTo(e.getCurrentLocation(),t,t)),e.listen(function(e){r.apps.forEach(function(t){t._route=e})}))},P.prototype.beforeEach=function(t){return $t(this.beforeHooks,t)},P.prototype.beforeResolve=function(t){return $t(this.resolveHooks,t)},P.prototype.afterEach=function(t){return $t(this.afterHooks,t)},P.prototype.onReady=function(t,e){this.history.onReady(t,e)},P.prototype.onError=function(t){this.history.onError(t)},P.prototype.push=function(t,e,r){this.history.push(t,e,r)},P.prototype.replace=function(t,e,r){this.history.replace(t,e,r)},P.prototype.go=function(t){this.history.go(t)},P.prototype.back=function(){this.go(-1)},P.prototype.forward=function(){this.go(1)},P.prototype.getMatchedComponents=function(t){t=t?t.matched?t:this.resolve(t).route:this.currentRoute;return t?[].concat.apply([],t.matched.map(function(e){return Object.keys(e.components).map(function(t){return e.components[t]})})):[]},P.prototype.resolve=function(t,e,r){t=at(t,e||this.history.current,r,this),r=this.match(t,e),e=r.redirectedFrom||r.fullPath;return{location:t,route:r,href:function(t,e,r){r="hash"===r?"#"+e:e;return t?h(t+"/"+r):r}(this.history.base,e,this.mode),normalizedTo:t,resolved:r}},P.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==u&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(P.prototype,e),P.install=c,P.version="3.0.1",n&&window.Kdu&&window.Kdu.use(P),P});
|