@pubinfo/devtools 2.2.0-beta.2 → 2.2.0-beta.4
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/dist/client/assets/{Navbar-CqbUKmrp.js → Navbar-3Cn9PFp9.js} +4 -3
- package/dist/client/assets/{PanelGrids-rTFcKhN6.js → PanelGrids-D-e1HMGu.js} +1 -1
- package/dist/client/assets/{SelectTabs-DgkHH3x0.js → SelectTabs-BVqh8LZU.js} +2 -2
- package/dist/client/assets/{component-BYrUuLxe.js → component-B7OC6axd.js} +3 -3
- package/dist/client/assets/{core-CrqZ8qrs.js → core-DiI9pThV.js} +1 -2
- package/dist/client/assets/css-Cjj0epyT.js +2 -0
- package/dist/client/assets/html-CFrcqZWa.js +2 -0
- package/dist/client/assets/{html-B5Ny8iin.js → html-DWiEGJDI.js} +2 -2
- package/dist/client/assets/{import-DKZiGsnA.js → import-C7KwSxxY.js} +3 -3
- package/dist/client/assets/index-BWYGlTlC.js +2528 -0
- package/dist/client/assets/{issue-5N1NVPuz.js → issue-BSGRP6QK.js} +3 -3
- package/dist/client/assets/javascript-BJm8fXxP.js +2 -0
- package/dist/client/assets/json-Brw1dQFm.js +2 -0
- package/dist/client/assets/{pages-CJAbU-aU.js → pages-CTRaZwAP.js} +5 -5
- package/dist/client/assets/preload-helper-DwCkpwrd.js +61 -0
- package/dist/client/assets/runtime-dom.esm-bundler-CEsf3eAe.js +719 -0
- package/dist/client/assets/{server-router-DJjewR1Y.js → server-router-C8joyG3R.js} +16 -15
- package/dist/client/assets/typescript-DIFxt4Fk.js +2 -0
- package/dist/client/assets/{vue-BvqQiUzU.js → vue-Aaycm_fY.js} +5 -5
- package/dist/client/assets/vue-router-CA-EVYVL.js +1907 -0
- package/dist/client/index.html +4 -1
- package/package.json +3 -3
- package/dist/client/assets/css-mRoPUXX2.js +0 -2
- package/dist/client/assets/html-g0uz4re7.js +0 -2
- package/dist/client/assets/index-gGaEqL_2.js +0 -5208
- package/dist/client/assets/javascript-yBXmlTMV.js +0 -2
- package/dist/client/assets/json-CDHOIUIc.js +0 -2
- package/dist/client/assets/typescript-jte7_wp4.js +0 -2
- /package/dist/client/assets/{_plugin-vue_export-helper-Ctigiz3_.js → _plugin-vue_export-helper-CQkuo_9D.js} +0 -0
- /package/dist/client/assets/{css-3PrNsnPt.js → css-Bovntqw-.js} +0 -0
- /package/dist/client/assets/{engine-oniguruma-C1mOz3PQ.js → engine-oniguruma-BRR1aDSJ.js} +0 -0
- /package/dist/client/assets/{fetch-Bz1BNH1Z.js → fetch-YItqmMVJ.js} +0 -0
- /package/dist/client/assets/{javascript-D9OtNJpI.js → javascript-DlyTQa1O.js} +0 -0
- /package/dist/client/assets/{json-DFv6u-UA.js → json-BxC7veKF.js} +0 -0
- /package/dist/client/assets/{typescript-C6a_X60d.js → typescript-DOns-J1e.js} +0 -0
- /package/dist/client/assets/{vitesse-dark-Dd6LUkEf.js → vitesse-dark-B-kHMmlr.js} +0 -0
- /package/dist/client/assets/{vitesse-light-LEkeIfQx.js → vitesse-light-BUD2Pvc-.js} +0 -0
- /package/dist/client/assets/{wasm-bCjRd0-o.js → wasm-DEqiGDhb.js} +0 -0
|
@@ -0,0 +1,1907 @@
|
|
|
1
|
+
import { C as nextTick, L as watch, O as provide, Q as shallowRef, X as shallowReactive, Y as ref, b as inject, g as defineComponent, nt as unref, q as reactive, s as computed, y as h } from "./runtime-core.esm-bundler-CsZVtwV7.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/vue-router@5.0.2_@vue+compiler-sfc@3.5.28_pinia@3.0.4_typescript@5.9.3_vue@3.5.28_types_f65a914d470f0fd222b36c46614a5c60/node_modules/vue-router/dist/useApi-o-nPpLEi.mjs
|
|
3
|
+
var isBrowser = typeof document !== "undefined";
|
|
4
|
+
/**
|
|
5
|
+
* Allows differentiating lazy components from functional components and vue-class-component
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* @param component
|
|
9
|
+
*/
|
|
10
|
+
function isRouteComponent(component) {
|
|
11
|
+
return typeof component === "object" || "displayName" in component || "props" in component || "__vccOpts" in component;
|
|
12
|
+
}
|
|
13
|
+
function isESModule(obj) {
|
|
14
|
+
return obj.__esModule || obj[Symbol.toStringTag] === "Module" || obj.default && isRouteComponent(obj.default);
|
|
15
|
+
}
|
|
16
|
+
var assign = Object.assign;
|
|
17
|
+
function applyToParams(fn, params) {
|
|
18
|
+
const newParams = {};
|
|
19
|
+
for (const key in params) {
|
|
20
|
+
const value = params[key];
|
|
21
|
+
newParams[key] = isArray(value) ? value.map(fn) : fn(value);
|
|
22
|
+
}
|
|
23
|
+
return newParams;
|
|
24
|
+
}
|
|
25
|
+
var noop = () => {};
|
|
26
|
+
/**
|
|
27
|
+
* Typesafe alternative to Array.isArray
|
|
28
|
+
* https://github.com/microsoft/TypeScript/pull/48228
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
var isArray = Array.isArray;
|
|
33
|
+
function mergeOptions(defaults, partialOptions) {
|
|
34
|
+
const options = {};
|
|
35
|
+
for (const key in defaults) options[key] = key in partialOptions ? partialOptions[key] : defaults[key];
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Flags so we can combine them when checking for multiple errors. This is the internal version of
|
|
40
|
+
* {@link NavigationFailureType}.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
var ErrorTypes = /* @__PURE__ */ function(ErrorTypes) {
|
|
45
|
+
ErrorTypes[ErrorTypes["MATCHER_NOT_FOUND"] = 1] = "MATCHER_NOT_FOUND";
|
|
46
|
+
ErrorTypes[ErrorTypes["NAVIGATION_GUARD_REDIRECT"] = 2] = "NAVIGATION_GUARD_REDIRECT";
|
|
47
|
+
ErrorTypes[ErrorTypes["NAVIGATION_ABORTED"] = 4] = "NAVIGATION_ABORTED";
|
|
48
|
+
ErrorTypes[ErrorTypes["NAVIGATION_CANCELLED"] = 8] = "NAVIGATION_CANCELLED";
|
|
49
|
+
ErrorTypes[ErrorTypes["NAVIGATION_DUPLICATED"] = 16] = "NAVIGATION_DUPLICATED";
|
|
50
|
+
return ErrorTypes;
|
|
51
|
+
}({});
|
|
52
|
+
var NavigationFailureSymbol = Symbol("");
|
|
53
|
+
ErrorTypes.MATCHER_NOT_FOUND, ErrorTypes.NAVIGATION_GUARD_REDIRECT, ErrorTypes.NAVIGATION_ABORTED, ErrorTypes.NAVIGATION_CANCELLED, ErrorTypes.NAVIGATION_DUPLICATED;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a typed NavigationFailure object.
|
|
56
|
+
* @internal
|
|
57
|
+
* @param type - NavigationFailureType
|
|
58
|
+
* @param params - { from, to }
|
|
59
|
+
*/
|
|
60
|
+
function createRouterError(type, params) {
|
|
61
|
+
return assign(/* @__PURE__ */ new Error(), {
|
|
62
|
+
type,
|
|
63
|
+
[NavigationFailureSymbol]: true
|
|
64
|
+
}, params);
|
|
65
|
+
}
|
|
66
|
+
function isNavigationFailure(error, type) {
|
|
67
|
+
return error instanceof Error && NavigationFailureSymbol in error && (type == null || !!(error.type & type));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* RouteRecord being rendered by the closest ancestor Router View. Used for
|
|
71
|
+
* `onBeforeRouteUpdate` and `onBeforeRouteLeave`. rvlm stands for Router View
|
|
72
|
+
* Location Matched
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
var matchedRouteKey = Symbol("");
|
|
77
|
+
/**
|
|
78
|
+
* Allows overriding the router view depth to control which component in
|
|
79
|
+
* `matched` is rendered. rvd stands for Router View Depth
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
var viewDepthKey = Symbol("");
|
|
84
|
+
/**
|
|
85
|
+
* Allows overriding the router instance returned by `useRouter` in tests. r
|
|
86
|
+
* stands for router
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
var routerKey = Symbol("");
|
|
91
|
+
/**
|
|
92
|
+
* Allows overriding the current route returned by `useRoute` in tests. rl
|
|
93
|
+
* stands for route location
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
var routeLocationKey = Symbol("");
|
|
98
|
+
/**
|
|
99
|
+
* Allows overriding the current route used by router-view. Internally this is
|
|
100
|
+
* used when the `route` prop is passed.
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
var routerViewLocationKey = Symbol("");
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region ../../node_modules/.pnpm/vue-router@5.0.2_@vue+compiler-sfc@3.5.28_pinia@3.0.4_typescript@5.9.3_vue@3.5.28_types_f65a914d470f0fd222b36c46614a5c60/node_modules/vue-router/dist/devtools-CQC1vVRY.mjs
|
|
107
|
+
/*!
|
|
108
|
+
* vue-router v5.0.2
|
|
109
|
+
* (c) 2026 Eduardo San Martin Morote
|
|
110
|
+
* @license MIT
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Encoding Rules (␣ = Space)
|
|
114
|
+
* - Path: ␣ " < > # ? { }
|
|
115
|
+
* - Query: ␣ " < > # & =
|
|
116
|
+
* - Hash: ␣ " < > `
|
|
117
|
+
*
|
|
118
|
+
* On top of that, the RFC3986 (https://tools.ietf.org/html/rfc3986#section-2.2)
|
|
119
|
+
* defines some extra characters to be encoded. Most browsers do not encode them
|
|
120
|
+
* in encodeURI https://github.com/whatwg/url/issues/369, so it may be safer to
|
|
121
|
+
* also encode `!'()*`. Leaving un-encoded only ASCII alphanumeric(`a-zA-Z0-9`)
|
|
122
|
+
* plus `-._~`. This extra safety should be applied to query by patching the
|
|
123
|
+
* string returned by encodeURIComponent encodeURI also encodes `[\]^`. `\`
|
|
124
|
+
* should be encoded to avoid ambiguity. Browsers (IE, FF, C) transform a `\`
|
|
125
|
+
* into a `/` if directly typed in. The _backtick_ (`````) should also be
|
|
126
|
+
* encoded everywhere because some browsers like FF encode it when directly
|
|
127
|
+
* written while others don't. Safari and IE don't encode ``"<>{}``` in hash.
|
|
128
|
+
*/
|
|
129
|
+
var HASH_RE = /#/g;
|
|
130
|
+
var AMPERSAND_RE = /&/g;
|
|
131
|
+
var SLASH_RE = /\//g;
|
|
132
|
+
var EQUAL_RE = /=/g;
|
|
133
|
+
var IM_RE = /\?/g;
|
|
134
|
+
var PLUS_RE = /\+/g;
|
|
135
|
+
/**
|
|
136
|
+
* NOTE: It's not clear to me if we should encode the + symbol in queries, it
|
|
137
|
+
* seems to be less flexible than not doing so and I can't find out the legacy
|
|
138
|
+
* systems requiring this for regular requests like text/html. In the standard,
|
|
139
|
+
* the encoding of the plus character is only mentioned for
|
|
140
|
+
* application/x-www-form-urlencoded
|
|
141
|
+
* (https://url.spec.whatwg.org/#urlencoded-parsing) and most browsers seems lo
|
|
142
|
+
* leave the plus character as is in queries. To be more flexible, we allow the
|
|
143
|
+
* plus character on the query, but it can also be manually encoded by the user.
|
|
144
|
+
*
|
|
145
|
+
* Resources:
|
|
146
|
+
* - https://url.spec.whatwg.org/#urlencoded-parsing
|
|
147
|
+
* - https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
|
|
148
|
+
*/
|
|
149
|
+
var ENC_BRACKET_OPEN_RE = /%5B/g;
|
|
150
|
+
var ENC_BRACKET_CLOSE_RE = /%5D/g;
|
|
151
|
+
var ENC_CARET_RE = /%5E/g;
|
|
152
|
+
var ENC_BACKTICK_RE = /%60/g;
|
|
153
|
+
var ENC_CURLY_OPEN_RE = /%7B/g;
|
|
154
|
+
var ENC_PIPE_RE = /%7C/g;
|
|
155
|
+
var ENC_CURLY_CLOSE_RE = /%7D/g;
|
|
156
|
+
var ENC_SPACE_RE = /%20/g;
|
|
157
|
+
/**
|
|
158
|
+
* Encode characters that need to be encoded on the path, search and hash
|
|
159
|
+
* sections of the URL.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
* @param text - string to encode
|
|
163
|
+
* @returns encoded string
|
|
164
|
+
*/
|
|
165
|
+
function commonEncode(text) {
|
|
166
|
+
return text == null ? "" : encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Encode characters that need to be encoded on the hash section of the URL.
|
|
170
|
+
*
|
|
171
|
+
* @param text - string to encode
|
|
172
|
+
* @returns encoded string
|
|
173
|
+
*/
|
|
174
|
+
function encodeHash(text) {
|
|
175
|
+
return commonEncode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Encode characters that need to be encoded query values on the query
|
|
179
|
+
* section of the URL.
|
|
180
|
+
*
|
|
181
|
+
* @param text - string to encode
|
|
182
|
+
* @returns encoded string
|
|
183
|
+
*/
|
|
184
|
+
function encodeQueryValue(text) {
|
|
185
|
+
return commonEncode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Like `encodeQueryValue` but also encodes the `=` character.
|
|
189
|
+
*
|
|
190
|
+
* @param text - string to encode
|
|
191
|
+
*/
|
|
192
|
+
function encodeQueryKey(text) {
|
|
193
|
+
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Encode characters that need to be encoded on the path section of the URL.
|
|
197
|
+
*
|
|
198
|
+
* @param text - string to encode
|
|
199
|
+
* @returns encoded string
|
|
200
|
+
*/
|
|
201
|
+
function encodePath(text) {
|
|
202
|
+
return commonEncode(text).replace(HASH_RE, "%23").replace(IM_RE, "%3F");
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Encode characters that need to be encoded on the path section of the URL as a
|
|
206
|
+
* param. This function encodes everything {@link encodePath} does plus the
|
|
207
|
+
* slash (`/`) character. If `text` is `null` or `undefined`, returns an empty
|
|
208
|
+
* string instead.
|
|
209
|
+
*
|
|
210
|
+
* @param text - string to encode
|
|
211
|
+
* @returns encoded string
|
|
212
|
+
*/
|
|
213
|
+
function encodeParam(text) {
|
|
214
|
+
return encodePath(text).replace(SLASH_RE, "%2F");
|
|
215
|
+
}
|
|
216
|
+
function decode(text) {
|
|
217
|
+
if (text == null) return null;
|
|
218
|
+
try {
|
|
219
|
+
return decodeURIComponent("" + text);
|
|
220
|
+
} catch (err) {}
|
|
221
|
+
return "" + text;
|
|
222
|
+
}
|
|
223
|
+
var TRAILING_SLASH_RE = /\/$/;
|
|
224
|
+
var removeTrailingSlash = (path) => path.replace(TRAILING_SLASH_RE, "");
|
|
225
|
+
/**
|
|
226
|
+
* Transforms a URI into a normalized history location
|
|
227
|
+
*
|
|
228
|
+
* @param parseQuery
|
|
229
|
+
* @param location - URI to normalize
|
|
230
|
+
* @param currentLocation - current absolute location. Allows resolving relative
|
|
231
|
+
* paths. Must start with `/`. Defaults to `/`
|
|
232
|
+
* @returns a normalized history location
|
|
233
|
+
*/
|
|
234
|
+
function parseURL(parseQuery, location, currentLocation = "/") {
|
|
235
|
+
let path, query = {}, searchString = "", hash = "";
|
|
236
|
+
const hashPos = location.indexOf("#");
|
|
237
|
+
let searchPos = location.indexOf("?");
|
|
238
|
+
searchPos = hashPos >= 0 && searchPos > hashPos ? -1 : searchPos;
|
|
239
|
+
if (searchPos >= 0) {
|
|
240
|
+
path = location.slice(0, searchPos);
|
|
241
|
+
searchString = location.slice(searchPos, hashPos > 0 ? hashPos : location.length);
|
|
242
|
+
query = parseQuery(searchString.slice(1));
|
|
243
|
+
}
|
|
244
|
+
if (hashPos >= 0) {
|
|
245
|
+
path = path || location.slice(0, hashPos);
|
|
246
|
+
hash = location.slice(hashPos, location.length);
|
|
247
|
+
}
|
|
248
|
+
path = resolveRelativePath(path != null ? path : location, currentLocation);
|
|
249
|
+
return {
|
|
250
|
+
fullPath: path + searchString + hash,
|
|
251
|
+
path,
|
|
252
|
+
query,
|
|
253
|
+
hash: decode(hash)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Stringifies a URL object
|
|
258
|
+
*
|
|
259
|
+
* @param stringifyQuery
|
|
260
|
+
* @param location
|
|
261
|
+
*/
|
|
262
|
+
function stringifyURL(stringifyQuery, location) {
|
|
263
|
+
const query = location.query ? stringifyQuery(location.query) : "";
|
|
264
|
+
return location.path + (query && "?") + query + (location.hash || "");
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Strips off the base from the beginning of a location.pathname in a non-case-sensitive way.
|
|
268
|
+
*
|
|
269
|
+
* @param pathname - location.pathname
|
|
270
|
+
* @param base - base to strip off
|
|
271
|
+
*/
|
|
272
|
+
function stripBase(pathname, base) {
|
|
273
|
+
if (!base || !pathname.toLowerCase().startsWith(base.toLowerCase())) return pathname;
|
|
274
|
+
return pathname.slice(base.length) || "/";
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Checks if two RouteLocation are equal. This means that both locations are
|
|
278
|
+
* pointing towards the same {@link RouteRecord} and that all `params`, `query`
|
|
279
|
+
* parameters and `hash` are the same
|
|
280
|
+
*
|
|
281
|
+
* @param stringifyQuery - A function that takes a query object of type LocationQueryRaw and returns a string representation of it.
|
|
282
|
+
* @param a - first {@link RouteLocation}
|
|
283
|
+
* @param b - second {@link RouteLocation}
|
|
284
|
+
*/
|
|
285
|
+
function isSameRouteLocation(stringifyQuery, a, b) {
|
|
286
|
+
const aLastIndex = a.matched.length - 1;
|
|
287
|
+
const bLastIndex = b.matched.length - 1;
|
|
288
|
+
return aLastIndex > -1 && aLastIndex === bLastIndex && isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) && isSameRouteLocationParams(a.params, b.params) && stringifyQuery(a.query) === stringifyQuery(b.query) && a.hash === b.hash;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Check if two `RouteRecords` are equal. Takes into account aliases: they are
|
|
292
|
+
* considered equal to the `RouteRecord` they are aliasing.
|
|
293
|
+
*
|
|
294
|
+
* @param a - first {@link RouteRecord}
|
|
295
|
+
* @param b - second {@link RouteRecord}
|
|
296
|
+
*/
|
|
297
|
+
function isSameRouteRecord(a, b) {
|
|
298
|
+
return (a.aliasOf || a) === (b.aliasOf || b);
|
|
299
|
+
}
|
|
300
|
+
function isSameRouteLocationParams(a, b) {
|
|
301
|
+
if (Object.keys(a).length !== Object.keys(b).length) return false;
|
|
302
|
+
for (var key in a) if (!isSameRouteLocationParamsValue(a[key], b[key])) return false;
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
function isSameRouteLocationParamsValue(a, b) {
|
|
306
|
+
return isArray(a) ? isEquivalentArray(a, b) : isArray(b) ? isEquivalentArray(b, a) : (a && a.valueOf()) === (b && b.valueOf());
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Check if two arrays are the same or if an array with one single entry is the
|
|
310
|
+
* same as another primitive value. Used to check query and parameters
|
|
311
|
+
*
|
|
312
|
+
* @param a - array of values
|
|
313
|
+
* @param b - array of values or a single value
|
|
314
|
+
*/
|
|
315
|
+
function isEquivalentArray(a, b) {
|
|
316
|
+
return isArray(b) ? a.length === b.length && a.every((value, i) => value === b[i]) : a.length === 1 && a[0] === b;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Resolves a relative path that starts with `.`.
|
|
320
|
+
*
|
|
321
|
+
* @param to - path location we are resolving
|
|
322
|
+
* @param from - currentLocation.path, should start with `/`
|
|
323
|
+
*/
|
|
324
|
+
function resolveRelativePath(to, from) {
|
|
325
|
+
if (to.startsWith("/")) return to;
|
|
326
|
+
if (!to) return from;
|
|
327
|
+
const fromSegments = from.split("/");
|
|
328
|
+
const toSegments = to.split("/");
|
|
329
|
+
const lastToSegment = toSegments[toSegments.length - 1];
|
|
330
|
+
if (lastToSegment === ".." || lastToSegment === ".") toSegments.push("");
|
|
331
|
+
let position = fromSegments.length - 1;
|
|
332
|
+
let toPosition;
|
|
333
|
+
let segment;
|
|
334
|
+
for (toPosition = 0; toPosition < toSegments.length; toPosition++) {
|
|
335
|
+
segment = toSegments[toPosition];
|
|
336
|
+
if (segment === ".") continue;
|
|
337
|
+
if (segment === "..") {
|
|
338
|
+
if (position > 1) position--;
|
|
339
|
+
} else break;
|
|
340
|
+
}
|
|
341
|
+
return fromSegments.slice(0, position).join("/") + "/" + toSegments.slice(toPosition).join("/");
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Initial route location where the router is. Can be used in navigation guards
|
|
345
|
+
* to differentiate the initial navigation.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```js
|
|
349
|
+
* import { START_LOCATION } from 'vue-router'
|
|
350
|
+
*
|
|
351
|
+
* router.beforeEach((to, from) => {
|
|
352
|
+
* if (from === START_LOCATION) {
|
|
353
|
+
* // initial navigation
|
|
354
|
+
* }
|
|
355
|
+
* })
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
var START_LOCATION_NORMALIZED = {
|
|
359
|
+
path: "/",
|
|
360
|
+
name: void 0,
|
|
361
|
+
params: {},
|
|
362
|
+
query: {},
|
|
363
|
+
hash: "",
|
|
364
|
+
fullPath: "/",
|
|
365
|
+
matched: [],
|
|
366
|
+
meta: {},
|
|
367
|
+
redirectedFrom: void 0
|
|
368
|
+
};
|
|
369
|
+
var NavigationType = /* @__PURE__ */ function(NavigationType) {
|
|
370
|
+
NavigationType["pop"] = "pop";
|
|
371
|
+
NavigationType["push"] = "push";
|
|
372
|
+
return NavigationType;
|
|
373
|
+
}({});
|
|
374
|
+
var NavigationDirection = /* @__PURE__ */ function(NavigationDirection) {
|
|
375
|
+
NavigationDirection["back"] = "back";
|
|
376
|
+
NavigationDirection["forward"] = "forward";
|
|
377
|
+
NavigationDirection["unknown"] = "";
|
|
378
|
+
return NavigationDirection;
|
|
379
|
+
}({});
|
|
380
|
+
/**
|
|
381
|
+
* Normalizes a base by removing any trailing slash and reading the base tag if
|
|
382
|
+
* present.
|
|
383
|
+
*
|
|
384
|
+
* @param base - base to normalize
|
|
385
|
+
*/
|
|
386
|
+
function normalizeBase(base) {
|
|
387
|
+
if (!base) if (isBrowser) {
|
|
388
|
+
const baseEl = document.querySelector("base");
|
|
389
|
+
base = baseEl && baseEl.getAttribute("href") || "/";
|
|
390
|
+
base = base.replace(/^\w+:\/\/[^\/]+/, "");
|
|
391
|
+
} else base = "/";
|
|
392
|
+
if (base[0] !== "/" && base[0] !== "#") base = "/" + base;
|
|
393
|
+
return removeTrailingSlash(base);
|
|
394
|
+
}
|
|
395
|
+
var BEFORE_HASH_RE = /^[^#]+#/;
|
|
396
|
+
function createHref(base, location) {
|
|
397
|
+
return base.replace(BEFORE_HASH_RE, "#") + location;
|
|
398
|
+
}
|
|
399
|
+
function getElementPosition(el, offset) {
|
|
400
|
+
const docRect = document.documentElement.getBoundingClientRect();
|
|
401
|
+
const elRect = el.getBoundingClientRect();
|
|
402
|
+
return {
|
|
403
|
+
behavior: offset.behavior,
|
|
404
|
+
left: elRect.left - docRect.left - (offset.left || 0),
|
|
405
|
+
top: elRect.top - docRect.top - (offset.top || 0)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
var computeScrollPosition = () => ({
|
|
409
|
+
left: window.scrollX,
|
|
410
|
+
top: window.scrollY
|
|
411
|
+
});
|
|
412
|
+
function scrollToPosition(position) {
|
|
413
|
+
let scrollToOptions;
|
|
414
|
+
if ("el" in position) {
|
|
415
|
+
const positionEl = position.el;
|
|
416
|
+
const isIdSelector = typeof positionEl === "string" && positionEl.startsWith("#");
|
|
417
|
+
const el = typeof positionEl === "string" ? isIdSelector ? document.getElementById(positionEl.slice(1)) : document.querySelector(positionEl) : positionEl;
|
|
418
|
+
if (!el) return;
|
|
419
|
+
scrollToOptions = getElementPosition(el, position);
|
|
420
|
+
} else scrollToOptions = position;
|
|
421
|
+
if ("scrollBehavior" in document.documentElement.style) window.scrollTo(scrollToOptions);
|
|
422
|
+
else window.scrollTo(scrollToOptions.left != null ? scrollToOptions.left : window.scrollX, scrollToOptions.top != null ? scrollToOptions.top : window.scrollY);
|
|
423
|
+
}
|
|
424
|
+
function getScrollKey(path, delta) {
|
|
425
|
+
return (history.state ? history.state.position - delta : -1) + path;
|
|
426
|
+
}
|
|
427
|
+
var scrollPositions = /* @__PURE__ */ new Map();
|
|
428
|
+
function saveScrollPosition(key, scrollPosition) {
|
|
429
|
+
scrollPositions.set(key, scrollPosition);
|
|
430
|
+
}
|
|
431
|
+
function getSavedScrollPosition(key) {
|
|
432
|
+
const scroll = scrollPositions.get(key);
|
|
433
|
+
scrollPositions.delete(key);
|
|
434
|
+
return scroll;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* ScrollBehavior instance used by the router to compute and restore the scroll
|
|
438
|
+
* position when navigating.
|
|
439
|
+
*/
|
|
440
|
+
function isRouteLocation(route) {
|
|
441
|
+
return typeof route === "string" || route && typeof route === "object";
|
|
442
|
+
}
|
|
443
|
+
function isRouteName(name) {
|
|
444
|
+
return typeof name === "string" || typeof name === "symbol";
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Transforms a queryString into a {@link LocationQuery} object. Accept both, a
|
|
448
|
+
* version with the leading `?` and without Should work as URLSearchParams
|
|
449
|
+
|
|
450
|
+
* @internal
|
|
451
|
+
*
|
|
452
|
+
* @param search - search string to parse
|
|
453
|
+
* @returns a query object
|
|
454
|
+
*/
|
|
455
|
+
function parseQuery(search) {
|
|
456
|
+
const query = {};
|
|
457
|
+
if (search === "" || search === "?") return query;
|
|
458
|
+
const searchParams = (search[0] === "?" ? search.slice(1) : search).split("&");
|
|
459
|
+
for (let i = 0; i < searchParams.length; ++i) {
|
|
460
|
+
const searchParam = searchParams[i].replace(PLUS_RE, " ");
|
|
461
|
+
const eqPos = searchParam.indexOf("=");
|
|
462
|
+
const key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
|
|
463
|
+
const value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1));
|
|
464
|
+
if (key in query) {
|
|
465
|
+
let currentValue = query[key];
|
|
466
|
+
if (!isArray(currentValue)) currentValue = query[key] = [currentValue];
|
|
467
|
+
currentValue.push(value);
|
|
468
|
+
} else query[key] = value;
|
|
469
|
+
}
|
|
470
|
+
return query;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
|
|
474
|
+
* doesn't prepend a `?`
|
|
475
|
+
*
|
|
476
|
+
* @internal
|
|
477
|
+
*
|
|
478
|
+
* @param query - query object to stringify
|
|
479
|
+
* @returns string version of the query without the leading `?`
|
|
480
|
+
*/
|
|
481
|
+
function stringifyQuery(query) {
|
|
482
|
+
let search = "";
|
|
483
|
+
for (let key in query) {
|
|
484
|
+
const value = query[key];
|
|
485
|
+
key = encodeQueryKey(key);
|
|
486
|
+
if (value == null) {
|
|
487
|
+
if (value !== void 0) search += (search.length ? "&" : "") + key;
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
(isArray(value) ? value.map((v) => v && encodeQueryValue(v)) : [value && encodeQueryValue(value)]).forEach((value) => {
|
|
491
|
+
if (value !== void 0) {
|
|
492
|
+
search += (search.length ? "&" : "") + key;
|
|
493
|
+
if (value != null) search += "=" + value;
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return search;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Transforms a {@link LocationQueryRaw} into a {@link LocationQuery} by casting
|
|
501
|
+
* numbers into strings, removing keys with an undefined value and replacing
|
|
502
|
+
* undefined with null in arrays
|
|
503
|
+
*
|
|
504
|
+
* @param query - query object to normalize
|
|
505
|
+
* @returns a normalized query object
|
|
506
|
+
*/
|
|
507
|
+
function normalizeQuery(query) {
|
|
508
|
+
const normalizedQuery = {};
|
|
509
|
+
for (const key in query) {
|
|
510
|
+
const value = query[key];
|
|
511
|
+
if (value !== void 0) normalizedQuery[key] = isArray(value) ? value.map((v) => v == null ? null : "" + v) : value == null ? value : "" + value;
|
|
512
|
+
}
|
|
513
|
+
return normalizedQuery;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Create a list of callbacks that can be reset. Used to create before and after navigation guards list
|
|
517
|
+
*/
|
|
518
|
+
function useCallbacks() {
|
|
519
|
+
let handlers = [];
|
|
520
|
+
function add(handler) {
|
|
521
|
+
handlers.push(handler);
|
|
522
|
+
return () => {
|
|
523
|
+
const i = handlers.indexOf(handler);
|
|
524
|
+
if (i > -1) handlers.splice(i, 1);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function reset() {
|
|
528
|
+
handlers = [];
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
add,
|
|
532
|
+
list: () => handlers.slice(),
|
|
533
|
+
reset
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function guardToPromiseFn(guard, to, from, record, name, runWithContext = (fn) => fn()) {
|
|
537
|
+
const enterCallbackArray = record && (record.enterCallbacks[name] = record.enterCallbacks[name] || []);
|
|
538
|
+
return () => new Promise((resolve, reject) => {
|
|
539
|
+
const next = (valid) => {
|
|
540
|
+
if (valid === false) reject(createRouterError(ErrorTypes.NAVIGATION_ABORTED, {
|
|
541
|
+
from,
|
|
542
|
+
to
|
|
543
|
+
}));
|
|
544
|
+
else if (valid instanceof Error) reject(valid);
|
|
545
|
+
else if (isRouteLocation(valid)) reject(createRouterError(ErrorTypes.NAVIGATION_GUARD_REDIRECT, {
|
|
546
|
+
from: to,
|
|
547
|
+
to: valid
|
|
548
|
+
}));
|
|
549
|
+
else {
|
|
550
|
+
if (enterCallbackArray && record.enterCallbacks[name] === enterCallbackArray && typeof valid === "function") enterCallbackArray.push(valid);
|
|
551
|
+
resolve();
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
const guardReturn = runWithContext(() => guard.call(record && record.instances[name], to, from, next));
|
|
555
|
+
let guardCall = Promise.resolve(guardReturn);
|
|
556
|
+
if (guard.length < 3) guardCall = guardCall.then(next);
|
|
557
|
+
guardCall.catch((err) => reject(err));
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
function extractComponentsGuards(matched, guardType, to, from, runWithContext = (fn) => fn()) {
|
|
561
|
+
const guards = [];
|
|
562
|
+
for (const record of matched) for (const name in record.components) {
|
|
563
|
+
let rawComponent = record.components[name];
|
|
564
|
+
if (guardType !== "beforeRouteEnter" && !record.instances[name]) continue;
|
|
565
|
+
if (isRouteComponent(rawComponent)) {
|
|
566
|
+
const guard = (rawComponent.__vccOpts || rawComponent)[guardType];
|
|
567
|
+
guard && guards.push(guardToPromiseFn(guard, to, from, record, name, runWithContext));
|
|
568
|
+
} else {
|
|
569
|
+
let componentPromise = rawComponent();
|
|
570
|
+
guards.push(() => componentPromise.then((resolved) => {
|
|
571
|
+
if (!resolved) throw new Error(`Couldn't resolve component "${name}" at "${record.path}"`);
|
|
572
|
+
const resolvedComponent = isESModule(resolved) ? resolved.default : resolved;
|
|
573
|
+
record.mods[name] = resolved;
|
|
574
|
+
record.components[name] = resolvedComponent;
|
|
575
|
+
const guard = (resolvedComponent.__vccOpts || resolvedComponent)[guardType];
|
|
576
|
+
return guard && guardToPromiseFn(guard, to, from, record, name, runWithContext)();
|
|
577
|
+
}));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return guards;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Split the leaving, updating, and entering records.
|
|
584
|
+
* @internal
|
|
585
|
+
*
|
|
586
|
+
* @param to - Location we are navigating to
|
|
587
|
+
* @param from - Location we are navigating from
|
|
588
|
+
*/
|
|
589
|
+
function extractChangingRecords(to, from) {
|
|
590
|
+
const leavingRecords = [];
|
|
591
|
+
const updatingRecords = [];
|
|
592
|
+
const enteringRecords = [];
|
|
593
|
+
const len = Math.max(from.matched.length, to.matched.length);
|
|
594
|
+
for (let i = 0; i < len; i++) {
|
|
595
|
+
const recordFrom = from.matched[i];
|
|
596
|
+
if (recordFrom) if (to.matched.find((record) => isSameRouteRecord(record, recordFrom))) updatingRecords.push(recordFrom);
|
|
597
|
+
else leavingRecords.push(recordFrom);
|
|
598
|
+
const recordTo = to.matched[i];
|
|
599
|
+
if (recordTo) {
|
|
600
|
+
if (!from.matched.find((record) => isSameRouteRecord(record, recordTo))) enteringRecords.push(recordTo);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return [
|
|
604
|
+
leavingRecords,
|
|
605
|
+
updatingRecords,
|
|
606
|
+
enteringRecords
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region ../../node_modules/.pnpm/vue-router@5.0.2_@vue+compiler-sfc@3.5.28_pinia@3.0.4_typescript@5.9.3_vue@3.5.28_types_f65a914d470f0fd222b36c46614a5c60/node_modules/vue-router/dist/vue-router.mjs
|
|
611
|
+
/*!
|
|
612
|
+
* vue-router v5.0.2
|
|
613
|
+
* (c) 2026 Eduardo San Martin Morote
|
|
614
|
+
* @license MIT
|
|
615
|
+
*/
|
|
616
|
+
var createBaseLocation = () => location.protocol + "//" + location.host;
|
|
617
|
+
/**
|
|
618
|
+
* Creates a normalized history location from a window.location object
|
|
619
|
+
* @param base - The base path
|
|
620
|
+
* @param location - The window.location object
|
|
621
|
+
*/
|
|
622
|
+
function createCurrentLocation(base, location) {
|
|
623
|
+
const { pathname, search, hash } = location;
|
|
624
|
+
const hashPos = base.indexOf("#");
|
|
625
|
+
if (hashPos > -1) {
|
|
626
|
+
let slicePos = hash.includes(base.slice(hashPos)) ? base.slice(hashPos).length : 1;
|
|
627
|
+
let pathFromHash = hash.slice(slicePos);
|
|
628
|
+
if (pathFromHash[0] !== "/") pathFromHash = "/" + pathFromHash;
|
|
629
|
+
return stripBase(pathFromHash, "");
|
|
630
|
+
}
|
|
631
|
+
return stripBase(pathname, base) + search + hash;
|
|
632
|
+
}
|
|
633
|
+
function useHistoryListeners(base, historyState, currentLocation, replace) {
|
|
634
|
+
let listeners = [];
|
|
635
|
+
let teardowns = [];
|
|
636
|
+
let pauseState = null;
|
|
637
|
+
const popStateHandler = ({ state }) => {
|
|
638
|
+
const to = createCurrentLocation(base, location);
|
|
639
|
+
const from = currentLocation.value;
|
|
640
|
+
const fromState = historyState.value;
|
|
641
|
+
let delta = 0;
|
|
642
|
+
if (state) {
|
|
643
|
+
currentLocation.value = to;
|
|
644
|
+
historyState.value = state;
|
|
645
|
+
if (pauseState && pauseState === from) {
|
|
646
|
+
pauseState = null;
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
delta = fromState ? state.position - fromState.position : 0;
|
|
650
|
+
} else replace(to);
|
|
651
|
+
listeners.forEach((listener) => {
|
|
652
|
+
listener(currentLocation.value, from, {
|
|
653
|
+
delta,
|
|
654
|
+
type: NavigationType.pop,
|
|
655
|
+
direction: delta ? delta > 0 ? NavigationDirection.forward : NavigationDirection.back : NavigationDirection.unknown
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
};
|
|
659
|
+
function pauseListeners() {
|
|
660
|
+
pauseState = currentLocation.value;
|
|
661
|
+
}
|
|
662
|
+
function listen(callback) {
|
|
663
|
+
listeners.push(callback);
|
|
664
|
+
const teardown = () => {
|
|
665
|
+
const index = listeners.indexOf(callback);
|
|
666
|
+
if (index > -1) listeners.splice(index, 1);
|
|
667
|
+
};
|
|
668
|
+
teardowns.push(teardown);
|
|
669
|
+
return teardown;
|
|
670
|
+
}
|
|
671
|
+
function beforeUnloadListener() {
|
|
672
|
+
if (document.visibilityState === "hidden") {
|
|
673
|
+
const { history } = window;
|
|
674
|
+
if (!history.state) return;
|
|
675
|
+
history.replaceState(assign({}, history.state, { scroll: computeScrollPosition() }), "");
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function destroy() {
|
|
679
|
+
for (const teardown of teardowns) teardown();
|
|
680
|
+
teardowns = [];
|
|
681
|
+
window.removeEventListener("popstate", popStateHandler);
|
|
682
|
+
window.removeEventListener("pagehide", beforeUnloadListener);
|
|
683
|
+
document.removeEventListener("visibilitychange", beforeUnloadListener);
|
|
684
|
+
}
|
|
685
|
+
window.addEventListener("popstate", popStateHandler);
|
|
686
|
+
window.addEventListener("pagehide", beforeUnloadListener);
|
|
687
|
+
document.addEventListener("visibilitychange", beforeUnloadListener);
|
|
688
|
+
return {
|
|
689
|
+
pauseListeners,
|
|
690
|
+
listen,
|
|
691
|
+
destroy
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Creates a state object
|
|
696
|
+
*/
|
|
697
|
+
function buildState(back, current, forward, replaced = false, computeScroll = false) {
|
|
698
|
+
return {
|
|
699
|
+
back,
|
|
700
|
+
current,
|
|
701
|
+
forward,
|
|
702
|
+
replaced,
|
|
703
|
+
position: window.history.length,
|
|
704
|
+
scroll: computeScroll ? computeScrollPosition() : null
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function useHistoryStateNavigation(base) {
|
|
708
|
+
const { history, location } = window;
|
|
709
|
+
const currentLocation = { value: createCurrentLocation(base, location) };
|
|
710
|
+
const historyState = { value: history.state };
|
|
711
|
+
if (!historyState.value) changeLocation(currentLocation.value, {
|
|
712
|
+
back: null,
|
|
713
|
+
current: currentLocation.value,
|
|
714
|
+
forward: null,
|
|
715
|
+
position: history.length - 1,
|
|
716
|
+
replaced: true,
|
|
717
|
+
scroll: null
|
|
718
|
+
}, true);
|
|
719
|
+
function changeLocation(to, state, replace) {
|
|
720
|
+
/**
|
|
721
|
+
* if a base tag is provided, and we are on a normal domain, we have to
|
|
722
|
+
* respect the provided `base` attribute because pushState() will use it and
|
|
723
|
+
* potentially erase anything before the `#` like at
|
|
724
|
+
* https://github.com/vuejs/router/issues/685 where a base of
|
|
725
|
+
* `/folder/#` but a base of `/` would erase the `/folder/` section. If
|
|
726
|
+
* there is no host, the `<base>` tag makes no sense and if there isn't a
|
|
727
|
+
* base tag we can just use everything after the `#`.
|
|
728
|
+
*/
|
|
729
|
+
const hashIndex = base.indexOf("#");
|
|
730
|
+
const url = hashIndex > -1 ? (location.host && document.querySelector("base") ? base : base.slice(hashIndex)) + to : createBaseLocation() + base + to;
|
|
731
|
+
try {
|
|
732
|
+
history[replace ? "replaceState" : "pushState"](state, "", url);
|
|
733
|
+
historyState.value = state;
|
|
734
|
+
} catch (err) {
|
|
735
|
+
console.error(err);
|
|
736
|
+
location[replace ? "replace" : "assign"](url);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function replace(to, data) {
|
|
740
|
+
changeLocation(to, assign({}, history.state, buildState(historyState.value.back, to, historyState.value.forward, true), data, { position: historyState.value.position }), true);
|
|
741
|
+
currentLocation.value = to;
|
|
742
|
+
}
|
|
743
|
+
function push(to, data) {
|
|
744
|
+
const currentState = assign({}, historyState.value, history.state, {
|
|
745
|
+
forward: to,
|
|
746
|
+
scroll: computeScrollPosition()
|
|
747
|
+
});
|
|
748
|
+
changeLocation(currentState.current, currentState, true);
|
|
749
|
+
changeLocation(to, assign({}, buildState(currentLocation.value, to, null), { position: currentState.position + 1 }, data), false);
|
|
750
|
+
currentLocation.value = to;
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
location: currentLocation,
|
|
754
|
+
state: historyState,
|
|
755
|
+
push,
|
|
756
|
+
replace
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Creates an HTML5 history. Most common history for single page applications.
|
|
761
|
+
*
|
|
762
|
+
* @param base -
|
|
763
|
+
*/
|
|
764
|
+
function createWebHistory(base) {
|
|
765
|
+
base = normalizeBase(base);
|
|
766
|
+
const historyNavigation = useHistoryStateNavigation(base);
|
|
767
|
+
const historyListeners = useHistoryListeners(base, historyNavigation.state, historyNavigation.location, historyNavigation.replace);
|
|
768
|
+
function go(delta, triggerListeners = true) {
|
|
769
|
+
if (!triggerListeners) historyListeners.pauseListeners();
|
|
770
|
+
history.go(delta);
|
|
771
|
+
}
|
|
772
|
+
const routerHistory = assign({
|
|
773
|
+
location: "",
|
|
774
|
+
base,
|
|
775
|
+
go,
|
|
776
|
+
createHref: createHref.bind(null, base)
|
|
777
|
+
}, historyNavigation, historyListeners);
|
|
778
|
+
Object.defineProperty(routerHistory, "location", {
|
|
779
|
+
enumerable: true,
|
|
780
|
+
get: () => historyNavigation.location.value
|
|
781
|
+
});
|
|
782
|
+
Object.defineProperty(routerHistory, "state", {
|
|
783
|
+
enumerable: true,
|
|
784
|
+
get: () => historyNavigation.state.value
|
|
785
|
+
});
|
|
786
|
+
return routerHistory;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Creates a hash history. Useful for web applications with no host (e.g. `file://`) or when configuring a server to
|
|
790
|
+
* handle any URL is not possible.
|
|
791
|
+
*
|
|
792
|
+
* @param base - optional base to provide. Defaults to `location.pathname + location.search` If there is a `<base>` tag
|
|
793
|
+
* in the `head`, its value will be ignored in favor of this parameter **but note it affects all the history.pushState()
|
|
794
|
+
* calls**, meaning that if you use a `<base>` tag, it's `href` value **has to match this parameter** (ignoring anything
|
|
795
|
+
* after the `#`).
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```js
|
|
799
|
+
* // at https://example.com/folder
|
|
800
|
+
* createWebHashHistory() // gives a url of `https://example.com/folder#`
|
|
801
|
+
* createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
|
|
802
|
+
* // if the `#` is provided in the base, it won't be added by `createWebHashHistory`
|
|
803
|
+
* createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
|
|
804
|
+
* // you should avoid doing this because it changes the original url and breaks copying urls
|
|
805
|
+
* createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
|
|
806
|
+
*
|
|
807
|
+
* // at file:///usr/etc/folder/index.html
|
|
808
|
+
* // for locations with no `host`, the base is ignored
|
|
809
|
+
* createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
function createWebHashHistory(base) {
|
|
813
|
+
base = location.host ? base || location.pathname + location.search : "";
|
|
814
|
+
if (!base.includes("#")) base += "#";
|
|
815
|
+
return createWebHistory(base);
|
|
816
|
+
}
|
|
817
|
+
var TokenType = /* @__PURE__ */ function(TokenType) {
|
|
818
|
+
TokenType[TokenType["Static"] = 0] = "Static";
|
|
819
|
+
TokenType[TokenType["Param"] = 1] = "Param";
|
|
820
|
+
TokenType[TokenType["Group"] = 2] = "Group";
|
|
821
|
+
return TokenType;
|
|
822
|
+
}({});
|
|
823
|
+
var TokenizerState = /* @__PURE__ */ function(TokenizerState) {
|
|
824
|
+
TokenizerState[TokenizerState["Static"] = 0] = "Static";
|
|
825
|
+
TokenizerState[TokenizerState["Param"] = 1] = "Param";
|
|
826
|
+
TokenizerState[TokenizerState["ParamRegExp"] = 2] = "ParamRegExp";
|
|
827
|
+
TokenizerState[TokenizerState["ParamRegExpEnd"] = 3] = "ParamRegExpEnd";
|
|
828
|
+
TokenizerState[TokenizerState["EscapeNext"] = 4] = "EscapeNext";
|
|
829
|
+
return TokenizerState;
|
|
830
|
+
}(TokenizerState || {});
|
|
831
|
+
var ROOT_TOKEN = {
|
|
832
|
+
type: TokenType.Static,
|
|
833
|
+
value: ""
|
|
834
|
+
};
|
|
835
|
+
var VALID_PARAM_RE = /[a-zA-Z0-9_]/;
|
|
836
|
+
function tokenizePath(path) {
|
|
837
|
+
if (!path) return [[]];
|
|
838
|
+
if (path === "/") return [[ROOT_TOKEN]];
|
|
839
|
+
if (!path.startsWith("/")) throw new Error(`Invalid path "${path}"`);
|
|
840
|
+
function crash(message) {
|
|
841
|
+
throw new Error(`ERR (${state})/"${buffer}": ${message}`);
|
|
842
|
+
}
|
|
843
|
+
let state = TokenizerState.Static;
|
|
844
|
+
let previousState = state;
|
|
845
|
+
const tokens = [];
|
|
846
|
+
let segment;
|
|
847
|
+
function finalizeSegment() {
|
|
848
|
+
if (segment) tokens.push(segment);
|
|
849
|
+
segment = [];
|
|
850
|
+
}
|
|
851
|
+
let i = 0;
|
|
852
|
+
let char;
|
|
853
|
+
let buffer = "";
|
|
854
|
+
let customRe = "";
|
|
855
|
+
function consumeBuffer() {
|
|
856
|
+
if (!buffer) return;
|
|
857
|
+
if (state === TokenizerState.Static) segment.push({
|
|
858
|
+
type: TokenType.Static,
|
|
859
|
+
value: buffer
|
|
860
|
+
});
|
|
861
|
+
else if (state === TokenizerState.Param || state === TokenizerState.ParamRegExp || state === TokenizerState.ParamRegExpEnd) {
|
|
862
|
+
if (segment.length > 1 && (char === "*" || char === "+")) crash(`A repeatable param (${buffer}) must be alone in its segment. eg: '/:ids+.`);
|
|
863
|
+
segment.push({
|
|
864
|
+
type: TokenType.Param,
|
|
865
|
+
value: buffer,
|
|
866
|
+
regexp: customRe,
|
|
867
|
+
repeatable: char === "*" || char === "+",
|
|
868
|
+
optional: char === "*" || char === "?"
|
|
869
|
+
});
|
|
870
|
+
} else crash("Invalid state to consume buffer");
|
|
871
|
+
buffer = "";
|
|
872
|
+
}
|
|
873
|
+
function addCharToBuffer() {
|
|
874
|
+
buffer += char;
|
|
875
|
+
}
|
|
876
|
+
while (i < path.length) {
|
|
877
|
+
char = path[i++];
|
|
878
|
+
if (char === "\\" && state !== TokenizerState.ParamRegExp) {
|
|
879
|
+
previousState = state;
|
|
880
|
+
state = TokenizerState.EscapeNext;
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
switch (state) {
|
|
884
|
+
case TokenizerState.Static:
|
|
885
|
+
if (char === "/") {
|
|
886
|
+
if (buffer) consumeBuffer();
|
|
887
|
+
finalizeSegment();
|
|
888
|
+
} else if (char === ":") {
|
|
889
|
+
consumeBuffer();
|
|
890
|
+
state = TokenizerState.Param;
|
|
891
|
+
} else addCharToBuffer();
|
|
892
|
+
break;
|
|
893
|
+
case TokenizerState.EscapeNext:
|
|
894
|
+
addCharToBuffer();
|
|
895
|
+
state = previousState;
|
|
896
|
+
break;
|
|
897
|
+
case TokenizerState.Param:
|
|
898
|
+
if (char === "(") state = TokenizerState.ParamRegExp;
|
|
899
|
+
else if (VALID_PARAM_RE.test(char)) addCharToBuffer();
|
|
900
|
+
else {
|
|
901
|
+
consumeBuffer();
|
|
902
|
+
state = TokenizerState.Static;
|
|
903
|
+
if (char !== "*" && char !== "?" && char !== "+") i--;
|
|
904
|
+
}
|
|
905
|
+
break;
|
|
906
|
+
case TokenizerState.ParamRegExp:
|
|
907
|
+
if (char === ")") if (customRe[customRe.length - 1] == "\\") customRe = customRe.slice(0, -1) + char;
|
|
908
|
+
else state = TokenizerState.ParamRegExpEnd;
|
|
909
|
+
else customRe += char;
|
|
910
|
+
break;
|
|
911
|
+
case TokenizerState.ParamRegExpEnd:
|
|
912
|
+
consumeBuffer();
|
|
913
|
+
state = TokenizerState.Static;
|
|
914
|
+
if (char !== "*" && char !== "?" && char !== "+") i--;
|
|
915
|
+
customRe = "";
|
|
916
|
+
break;
|
|
917
|
+
default:
|
|
918
|
+
crash("Unknown state");
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
if (state === TokenizerState.ParamRegExp) crash(`Unfinished custom RegExp for param "${buffer}"`);
|
|
923
|
+
consumeBuffer();
|
|
924
|
+
finalizeSegment();
|
|
925
|
+
return tokens;
|
|
926
|
+
}
|
|
927
|
+
var BASE_PARAM_PATTERN = "[^/]+?";
|
|
928
|
+
var BASE_PATH_PARSER_OPTIONS = {
|
|
929
|
+
sensitive: false,
|
|
930
|
+
strict: false,
|
|
931
|
+
start: true,
|
|
932
|
+
end: true
|
|
933
|
+
};
|
|
934
|
+
var PathScore = /* @__PURE__ */ function(PathScore) {
|
|
935
|
+
PathScore[PathScore["_multiplier"] = 10] = "_multiplier";
|
|
936
|
+
PathScore[PathScore["Root"] = 90] = "Root";
|
|
937
|
+
PathScore[PathScore["Segment"] = 40] = "Segment";
|
|
938
|
+
PathScore[PathScore["SubSegment"] = 30] = "SubSegment";
|
|
939
|
+
PathScore[PathScore["Static"] = 40] = "Static";
|
|
940
|
+
PathScore[PathScore["Dynamic"] = 20] = "Dynamic";
|
|
941
|
+
PathScore[PathScore["BonusCustomRegExp"] = 10] = "BonusCustomRegExp";
|
|
942
|
+
PathScore[PathScore["BonusWildcard"] = -50] = "BonusWildcard";
|
|
943
|
+
PathScore[PathScore["BonusRepeatable"] = -20] = "BonusRepeatable";
|
|
944
|
+
PathScore[PathScore["BonusOptional"] = -8] = "BonusOptional";
|
|
945
|
+
PathScore[PathScore["BonusStrict"] = .7000000000000001] = "BonusStrict";
|
|
946
|
+
PathScore[PathScore["BonusCaseSensitive"] = .25] = "BonusCaseSensitive";
|
|
947
|
+
return PathScore;
|
|
948
|
+
}(PathScore || {});
|
|
949
|
+
var REGEX_CHARS_RE = /[.+*?^${}()[\]/\\]/g;
|
|
950
|
+
/**
|
|
951
|
+
* Creates a path parser from an array of Segments (a segment is an array of Tokens)
|
|
952
|
+
*
|
|
953
|
+
* @param segments - array of segments returned by tokenizePath
|
|
954
|
+
* @param extraOptions - optional options for the regexp
|
|
955
|
+
* @returns a PathParser
|
|
956
|
+
*/
|
|
957
|
+
function tokensToParser(segments, extraOptions) {
|
|
958
|
+
const options = assign({}, BASE_PATH_PARSER_OPTIONS, extraOptions);
|
|
959
|
+
const score = [];
|
|
960
|
+
let pattern = options.start ? "^" : "";
|
|
961
|
+
const keys = [];
|
|
962
|
+
for (const segment of segments) {
|
|
963
|
+
const segmentScores = segment.length ? [] : [PathScore.Root];
|
|
964
|
+
if (options.strict && !segment.length) pattern += "/";
|
|
965
|
+
for (let tokenIndex = 0; tokenIndex < segment.length; tokenIndex++) {
|
|
966
|
+
const token = segment[tokenIndex];
|
|
967
|
+
let subSegmentScore = PathScore.Segment + (options.sensitive ? PathScore.BonusCaseSensitive : 0);
|
|
968
|
+
if (token.type === TokenType.Static) {
|
|
969
|
+
if (!tokenIndex) pattern += "/";
|
|
970
|
+
pattern += token.value.replace(REGEX_CHARS_RE, "\\$&");
|
|
971
|
+
subSegmentScore += PathScore.Static;
|
|
972
|
+
} else if (token.type === TokenType.Param) {
|
|
973
|
+
const { value, repeatable, optional, regexp } = token;
|
|
974
|
+
keys.push({
|
|
975
|
+
name: value,
|
|
976
|
+
repeatable,
|
|
977
|
+
optional
|
|
978
|
+
});
|
|
979
|
+
const re = regexp ? regexp : BASE_PARAM_PATTERN;
|
|
980
|
+
if (re !== BASE_PARAM_PATTERN) {
|
|
981
|
+
subSegmentScore += PathScore.BonusCustomRegExp;
|
|
982
|
+
try {
|
|
983
|
+
new RegExp(`(${re})`);
|
|
984
|
+
} catch (err) {
|
|
985
|
+
throw new Error(`Invalid custom RegExp for param "${value}" (${re}): ` + err.message);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
let subPattern = repeatable ? `((?:${re})(?:/(?:${re}))*)` : `(${re})`;
|
|
989
|
+
if (!tokenIndex) subPattern = optional && segment.length < 2 ? `(?:/${subPattern})` : "/" + subPattern;
|
|
990
|
+
if (optional) subPattern += "?";
|
|
991
|
+
pattern += subPattern;
|
|
992
|
+
subSegmentScore += PathScore.Dynamic;
|
|
993
|
+
if (optional) subSegmentScore += PathScore.BonusOptional;
|
|
994
|
+
if (repeatable) subSegmentScore += PathScore.BonusRepeatable;
|
|
995
|
+
if (re === ".*") subSegmentScore += PathScore.BonusWildcard;
|
|
996
|
+
}
|
|
997
|
+
segmentScores.push(subSegmentScore);
|
|
998
|
+
}
|
|
999
|
+
score.push(segmentScores);
|
|
1000
|
+
}
|
|
1001
|
+
if (options.strict && options.end) {
|
|
1002
|
+
const i = score.length - 1;
|
|
1003
|
+
score[i][score[i].length - 1] += PathScore.BonusStrict;
|
|
1004
|
+
}
|
|
1005
|
+
if (!options.strict) pattern += "/?";
|
|
1006
|
+
if (options.end) pattern += "$";
|
|
1007
|
+
else if (options.strict && !pattern.endsWith("/")) pattern += "(?:/|$)";
|
|
1008
|
+
const re = new RegExp(pattern, options.sensitive ? "" : "i");
|
|
1009
|
+
function parse(path) {
|
|
1010
|
+
const match = path.match(re);
|
|
1011
|
+
const params = {};
|
|
1012
|
+
if (!match) return null;
|
|
1013
|
+
for (let i = 1; i < match.length; i++) {
|
|
1014
|
+
const value = match[i] || "";
|
|
1015
|
+
const key = keys[i - 1];
|
|
1016
|
+
params[key.name] = value && key.repeatable ? value.split("/") : value;
|
|
1017
|
+
}
|
|
1018
|
+
return params;
|
|
1019
|
+
}
|
|
1020
|
+
function stringify(params) {
|
|
1021
|
+
let path = "";
|
|
1022
|
+
let avoidDuplicatedSlash = false;
|
|
1023
|
+
for (const segment of segments) {
|
|
1024
|
+
if (!avoidDuplicatedSlash || !path.endsWith("/")) path += "/";
|
|
1025
|
+
avoidDuplicatedSlash = false;
|
|
1026
|
+
for (const token of segment) if (token.type === TokenType.Static) path += token.value;
|
|
1027
|
+
else if (token.type === TokenType.Param) {
|
|
1028
|
+
const { value, repeatable, optional } = token;
|
|
1029
|
+
const param = value in params ? params[value] : "";
|
|
1030
|
+
if (isArray(param) && !repeatable) throw new Error(`Provided param "${value}" is an array but it is not repeatable (* or + modifiers)`);
|
|
1031
|
+
const text = isArray(param) ? param.join("/") : param;
|
|
1032
|
+
if (!text) if (optional) {
|
|
1033
|
+
if (segment.length < 2) if (path.endsWith("/")) path = path.slice(0, -1);
|
|
1034
|
+
else avoidDuplicatedSlash = true;
|
|
1035
|
+
} else throw new Error(`Missing required param "${value}"`);
|
|
1036
|
+
path += text;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return path || "/";
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
re,
|
|
1043
|
+
score,
|
|
1044
|
+
keys,
|
|
1045
|
+
parse,
|
|
1046
|
+
stringify
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Compares an array of numbers as used in PathParser.score and returns a
|
|
1051
|
+
* number. This function can be used to `sort` an array
|
|
1052
|
+
*
|
|
1053
|
+
* @param a - first array of numbers
|
|
1054
|
+
* @param b - second array of numbers
|
|
1055
|
+
* @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
|
|
1056
|
+
* should be sorted first
|
|
1057
|
+
*/
|
|
1058
|
+
function compareScoreArray(a, b) {
|
|
1059
|
+
let i = 0;
|
|
1060
|
+
while (i < a.length && i < b.length) {
|
|
1061
|
+
const diff = b[i] - a[i];
|
|
1062
|
+
if (diff) return diff;
|
|
1063
|
+
i++;
|
|
1064
|
+
}
|
|
1065
|
+
if (a.length < b.length) return a.length === 1 && a[0] === PathScore.Static + PathScore.Segment ? -1 : 1;
|
|
1066
|
+
else if (a.length > b.length) return b.length === 1 && b[0] === PathScore.Static + PathScore.Segment ? 1 : -1;
|
|
1067
|
+
return 0;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Compare function that can be used with `sort` to sort an array of PathParser
|
|
1071
|
+
*
|
|
1072
|
+
* @param a - first PathParser
|
|
1073
|
+
* @param b - second PathParser
|
|
1074
|
+
* @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
|
|
1075
|
+
*/
|
|
1076
|
+
function comparePathParserScore(a, b) {
|
|
1077
|
+
let i = 0;
|
|
1078
|
+
const aScore = a.score;
|
|
1079
|
+
const bScore = b.score;
|
|
1080
|
+
while (i < aScore.length && i < bScore.length) {
|
|
1081
|
+
const comp = compareScoreArray(aScore[i], bScore[i]);
|
|
1082
|
+
if (comp) return comp;
|
|
1083
|
+
i++;
|
|
1084
|
+
}
|
|
1085
|
+
if (Math.abs(bScore.length - aScore.length) === 1) {
|
|
1086
|
+
if (isLastScoreNegative(aScore)) return 1;
|
|
1087
|
+
if (isLastScoreNegative(bScore)) return -1;
|
|
1088
|
+
}
|
|
1089
|
+
return bScore.length - aScore.length;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* This allows detecting splats at the end of a path: /home/:id(.*)*
|
|
1093
|
+
*
|
|
1094
|
+
* @param score - score to check
|
|
1095
|
+
* @returns true if the last entry is negative
|
|
1096
|
+
*/
|
|
1097
|
+
function isLastScoreNegative(score) {
|
|
1098
|
+
const last = score[score.length - 1];
|
|
1099
|
+
return score.length > 0 && last[last.length - 1] < 0;
|
|
1100
|
+
}
|
|
1101
|
+
var PATH_PARSER_OPTIONS_DEFAULTS = {
|
|
1102
|
+
strict: false,
|
|
1103
|
+
end: true,
|
|
1104
|
+
sensitive: false
|
|
1105
|
+
};
|
|
1106
|
+
function createRouteRecordMatcher(record, parent, options) {
|
|
1107
|
+
const matcher = assign(tokensToParser(tokenizePath(record.path), options), {
|
|
1108
|
+
record,
|
|
1109
|
+
parent,
|
|
1110
|
+
children: [],
|
|
1111
|
+
alias: []
|
|
1112
|
+
});
|
|
1113
|
+
if (parent) {
|
|
1114
|
+
if (!matcher.record.aliasOf === !parent.record.aliasOf) parent.children.push(matcher);
|
|
1115
|
+
}
|
|
1116
|
+
return matcher;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Creates a Router Matcher.
|
|
1120
|
+
*
|
|
1121
|
+
* @internal
|
|
1122
|
+
* @param routes - array of initial routes
|
|
1123
|
+
* @param globalOptions - global route options
|
|
1124
|
+
*/
|
|
1125
|
+
function createRouterMatcher(routes, globalOptions) {
|
|
1126
|
+
const matchers = [];
|
|
1127
|
+
const matcherMap = /* @__PURE__ */ new Map();
|
|
1128
|
+
globalOptions = mergeOptions(PATH_PARSER_OPTIONS_DEFAULTS, globalOptions);
|
|
1129
|
+
function getRecordMatcher(name) {
|
|
1130
|
+
return matcherMap.get(name);
|
|
1131
|
+
}
|
|
1132
|
+
function addRoute(record, parent, originalRecord) {
|
|
1133
|
+
const isRootAdd = !originalRecord;
|
|
1134
|
+
const mainNormalizedRecord = normalizeRouteRecord(record);
|
|
1135
|
+
mainNormalizedRecord.aliasOf = originalRecord && originalRecord.record;
|
|
1136
|
+
const options = mergeOptions(globalOptions, record);
|
|
1137
|
+
const normalizedRecords = [mainNormalizedRecord];
|
|
1138
|
+
if ("alias" in record) {
|
|
1139
|
+
const aliases = typeof record.alias === "string" ? [record.alias] : record.alias;
|
|
1140
|
+
for (const alias of aliases) normalizedRecords.push(normalizeRouteRecord(assign({}, mainNormalizedRecord, {
|
|
1141
|
+
components: originalRecord ? originalRecord.record.components : mainNormalizedRecord.components,
|
|
1142
|
+
path: alias,
|
|
1143
|
+
aliasOf: originalRecord ? originalRecord.record : mainNormalizedRecord
|
|
1144
|
+
})));
|
|
1145
|
+
}
|
|
1146
|
+
let matcher;
|
|
1147
|
+
let originalMatcher;
|
|
1148
|
+
for (const normalizedRecord of normalizedRecords) {
|
|
1149
|
+
const { path } = normalizedRecord;
|
|
1150
|
+
if (parent && path[0] !== "/") {
|
|
1151
|
+
const parentPath = parent.record.path;
|
|
1152
|
+
const connectingSlash = parentPath[parentPath.length - 1] === "/" ? "" : "/";
|
|
1153
|
+
normalizedRecord.path = parent.record.path + (path && connectingSlash + path);
|
|
1154
|
+
}
|
|
1155
|
+
matcher = createRouteRecordMatcher(normalizedRecord, parent, options);
|
|
1156
|
+
if (originalRecord) originalRecord.alias.push(matcher);
|
|
1157
|
+
else {
|
|
1158
|
+
originalMatcher = originalMatcher || matcher;
|
|
1159
|
+
if (originalMatcher !== matcher) originalMatcher.alias.push(matcher);
|
|
1160
|
+
if (isRootAdd && record.name && !isAliasRecord(matcher)) removeRoute(record.name);
|
|
1161
|
+
}
|
|
1162
|
+
if (isMatchable(matcher)) insertMatcher(matcher);
|
|
1163
|
+
if (mainNormalizedRecord.children) {
|
|
1164
|
+
const children = mainNormalizedRecord.children;
|
|
1165
|
+
for (let i = 0; i < children.length; i++) addRoute(children[i], matcher, originalRecord && originalRecord.children[i]);
|
|
1166
|
+
}
|
|
1167
|
+
originalRecord = originalRecord || matcher;
|
|
1168
|
+
}
|
|
1169
|
+
return originalMatcher ? () => {
|
|
1170
|
+
removeRoute(originalMatcher);
|
|
1171
|
+
} : noop;
|
|
1172
|
+
}
|
|
1173
|
+
function removeRoute(matcherRef) {
|
|
1174
|
+
if (isRouteName(matcherRef)) {
|
|
1175
|
+
const matcher = matcherMap.get(matcherRef);
|
|
1176
|
+
if (matcher) {
|
|
1177
|
+
matcherMap.delete(matcherRef);
|
|
1178
|
+
matchers.splice(matchers.indexOf(matcher), 1);
|
|
1179
|
+
matcher.children.forEach(removeRoute);
|
|
1180
|
+
matcher.alias.forEach(removeRoute);
|
|
1181
|
+
}
|
|
1182
|
+
} else {
|
|
1183
|
+
const index = matchers.indexOf(matcherRef);
|
|
1184
|
+
if (index > -1) {
|
|
1185
|
+
matchers.splice(index, 1);
|
|
1186
|
+
if (matcherRef.record.name) matcherMap.delete(matcherRef.record.name);
|
|
1187
|
+
matcherRef.children.forEach(removeRoute);
|
|
1188
|
+
matcherRef.alias.forEach(removeRoute);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
function getRoutes() {
|
|
1193
|
+
return matchers;
|
|
1194
|
+
}
|
|
1195
|
+
function insertMatcher(matcher) {
|
|
1196
|
+
const index = findInsertionIndex(matcher, matchers);
|
|
1197
|
+
matchers.splice(index, 0, matcher);
|
|
1198
|
+
if (matcher.record.name && !isAliasRecord(matcher)) matcherMap.set(matcher.record.name, matcher);
|
|
1199
|
+
}
|
|
1200
|
+
function resolve(location, currentLocation) {
|
|
1201
|
+
let matcher;
|
|
1202
|
+
let params = {};
|
|
1203
|
+
let path;
|
|
1204
|
+
let name;
|
|
1205
|
+
if ("name" in location && location.name) {
|
|
1206
|
+
matcher = matcherMap.get(location.name);
|
|
1207
|
+
if (!matcher) throw createRouterError(ErrorTypes.MATCHER_NOT_FOUND, { location });
|
|
1208
|
+
name = matcher.record.name;
|
|
1209
|
+
params = assign(pickParams(currentLocation.params, matcher.keys.filter((k) => !k.optional).concat(matcher.parent ? matcher.parent.keys.filter((k) => k.optional) : []).map((k) => k.name)), location.params && pickParams(location.params, matcher.keys.map((k) => k.name)));
|
|
1210
|
+
path = matcher.stringify(params);
|
|
1211
|
+
} else if (location.path != null) {
|
|
1212
|
+
path = location.path;
|
|
1213
|
+
matcher = matchers.find((m) => m.re.test(path));
|
|
1214
|
+
if (matcher) {
|
|
1215
|
+
params = matcher.parse(path);
|
|
1216
|
+
name = matcher.record.name;
|
|
1217
|
+
}
|
|
1218
|
+
} else {
|
|
1219
|
+
matcher = currentLocation.name ? matcherMap.get(currentLocation.name) : matchers.find((m) => m.re.test(currentLocation.path));
|
|
1220
|
+
if (!matcher) throw createRouterError(ErrorTypes.MATCHER_NOT_FOUND, {
|
|
1221
|
+
location,
|
|
1222
|
+
currentLocation
|
|
1223
|
+
});
|
|
1224
|
+
name = matcher.record.name;
|
|
1225
|
+
params = assign({}, currentLocation.params, location.params);
|
|
1226
|
+
path = matcher.stringify(params);
|
|
1227
|
+
}
|
|
1228
|
+
const matched = [];
|
|
1229
|
+
let parentMatcher = matcher;
|
|
1230
|
+
while (parentMatcher) {
|
|
1231
|
+
matched.unshift(parentMatcher.record);
|
|
1232
|
+
parentMatcher = parentMatcher.parent;
|
|
1233
|
+
}
|
|
1234
|
+
return {
|
|
1235
|
+
name,
|
|
1236
|
+
path,
|
|
1237
|
+
params,
|
|
1238
|
+
matched,
|
|
1239
|
+
meta: mergeMetaFields(matched)
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
routes.forEach((route) => addRoute(route));
|
|
1243
|
+
function clearRoutes() {
|
|
1244
|
+
matchers.length = 0;
|
|
1245
|
+
matcherMap.clear();
|
|
1246
|
+
}
|
|
1247
|
+
return {
|
|
1248
|
+
addRoute,
|
|
1249
|
+
resolve,
|
|
1250
|
+
removeRoute,
|
|
1251
|
+
clearRoutes,
|
|
1252
|
+
getRoutes,
|
|
1253
|
+
getRecordMatcher
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Picks an object param to contain only specified keys.
|
|
1258
|
+
*
|
|
1259
|
+
* @param params - params object to pick from
|
|
1260
|
+
* @param keys - keys to pick
|
|
1261
|
+
*/
|
|
1262
|
+
function pickParams(params, keys) {
|
|
1263
|
+
const newParams = {};
|
|
1264
|
+
for (const key of keys) if (key in params) newParams[key] = params[key];
|
|
1265
|
+
return newParams;
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Normalizes a RouteRecordRaw. Creates a copy
|
|
1269
|
+
*
|
|
1270
|
+
* @param record
|
|
1271
|
+
* @returns the normalized version
|
|
1272
|
+
*/
|
|
1273
|
+
function normalizeRouteRecord(record) {
|
|
1274
|
+
const normalized = {
|
|
1275
|
+
path: record.path,
|
|
1276
|
+
redirect: record.redirect,
|
|
1277
|
+
name: record.name,
|
|
1278
|
+
meta: record.meta || {},
|
|
1279
|
+
aliasOf: record.aliasOf,
|
|
1280
|
+
beforeEnter: record.beforeEnter,
|
|
1281
|
+
props: normalizeRecordProps(record),
|
|
1282
|
+
children: record.children || [],
|
|
1283
|
+
instances: {},
|
|
1284
|
+
leaveGuards: /* @__PURE__ */ new Set(),
|
|
1285
|
+
updateGuards: /* @__PURE__ */ new Set(),
|
|
1286
|
+
enterCallbacks: {},
|
|
1287
|
+
components: "components" in record ? record.components || null : record.component && { default: record.component }
|
|
1288
|
+
};
|
|
1289
|
+
Object.defineProperty(normalized, "mods", { value: {} });
|
|
1290
|
+
return normalized;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Normalize the optional `props` in a record to always be an object similar to
|
|
1294
|
+
* components. Also accept a boolean for components.
|
|
1295
|
+
* @param record
|
|
1296
|
+
*/
|
|
1297
|
+
function normalizeRecordProps(record) {
|
|
1298
|
+
const propsObject = {};
|
|
1299
|
+
const props = record.props || false;
|
|
1300
|
+
if ("component" in record) propsObject.default = props;
|
|
1301
|
+
else for (const name in record.components) propsObject[name] = typeof props === "object" ? props[name] : props;
|
|
1302
|
+
return propsObject;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Checks if a record or any of its parent is an alias
|
|
1306
|
+
* @param record
|
|
1307
|
+
*/
|
|
1308
|
+
function isAliasRecord(record) {
|
|
1309
|
+
while (record) {
|
|
1310
|
+
if (record.record.aliasOf) return true;
|
|
1311
|
+
record = record.parent;
|
|
1312
|
+
}
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Merge meta fields of an array of records
|
|
1317
|
+
*
|
|
1318
|
+
* @param matched - array of matched records
|
|
1319
|
+
*/
|
|
1320
|
+
function mergeMetaFields(matched) {
|
|
1321
|
+
return matched.reduce((meta, record) => assign(meta, record.meta), {});
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Performs a binary search to find the correct insertion index for a new matcher.
|
|
1325
|
+
*
|
|
1326
|
+
* Matchers are primarily sorted by their score. If scores are tied then we also consider parent/child relationships,
|
|
1327
|
+
* with descendants coming before ancestors. If there's still a tie, new routes are inserted after existing routes.
|
|
1328
|
+
*
|
|
1329
|
+
* @param matcher - new matcher to be inserted
|
|
1330
|
+
* @param matchers - existing matchers
|
|
1331
|
+
*/
|
|
1332
|
+
function findInsertionIndex(matcher, matchers) {
|
|
1333
|
+
let lower = 0;
|
|
1334
|
+
let upper = matchers.length;
|
|
1335
|
+
while (lower !== upper) {
|
|
1336
|
+
const mid = lower + upper >> 1;
|
|
1337
|
+
if (comparePathParserScore(matcher, matchers[mid]) < 0) upper = mid;
|
|
1338
|
+
else lower = mid + 1;
|
|
1339
|
+
}
|
|
1340
|
+
const insertionAncestor = getInsertionAncestor(matcher);
|
|
1341
|
+
if (insertionAncestor) upper = matchers.lastIndexOf(insertionAncestor, upper - 1);
|
|
1342
|
+
return upper;
|
|
1343
|
+
}
|
|
1344
|
+
function getInsertionAncestor(matcher) {
|
|
1345
|
+
let ancestor = matcher;
|
|
1346
|
+
while (ancestor = ancestor.parent) if (isMatchable(ancestor) && comparePathParserScore(matcher, ancestor) === 0) return ancestor;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Checks if a matcher can be reachable. This means if it's possible to reach it as a route. For example, routes without
|
|
1350
|
+
* a component, or name, or redirect, are just used to group other routes.
|
|
1351
|
+
* @param matcher
|
|
1352
|
+
* @param matcher.record record of the matcher
|
|
1353
|
+
* @returns
|
|
1354
|
+
*/
|
|
1355
|
+
function isMatchable({ record }) {
|
|
1356
|
+
return !!(record.name || record.components && Object.keys(record.components).length || record.redirect);
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Returns the internal behavior of a {@link RouterLink} without the rendering part.
|
|
1360
|
+
*
|
|
1361
|
+
* @param props - a `to` location and an optional `replace` flag
|
|
1362
|
+
*/
|
|
1363
|
+
function useLink(props) {
|
|
1364
|
+
const router = inject(routerKey);
|
|
1365
|
+
const currentRoute = inject(routeLocationKey);
|
|
1366
|
+
const route = computed(() => {
|
|
1367
|
+
const to = unref(props.to);
|
|
1368
|
+
return router.resolve(to);
|
|
1369
|
+
});
|
|
1370
|
+
const activeRecordIndex = computed(() => {
|
|
1371
|
+
const { matched } = route.value;
|
|
1372
|
+
const { length } = matched;
|
|
1373
|
+
const routeMatched = matched[length - 1];
|
|
1374
|
+
const currentMatched = currentRoute.matched;
|
|
1375
|
+
if (!routeMatched || !currentMatched.length) return -1;
|
|
1376
|
+
const index = currentMatched.findIndex(isSameRouteRecord.bind(null, routeMatched));
|
|
1377
|
+
if (index > -1) return index;
|
|
1378
|
+
const parentRecordPath = getOriginalPath(matched[length - 2]);
|
|
1379
|
+
return length > 1 && getOriginalPath(routeMatched) === parentRecordPath && currentMatched[currentMatched.length - 1].path !== parentRecordPath ? currentMatched.findIndex(isSameRouteRecord.bind(null, matched[length - 2])) : index;
|
|
1380
|
+
});
|
|
1381
|
+
const isActive = computed(() => activeRecordIndex.value > -1 && includesParams(currentRoute.params, route.value.params));
|
|
1382
|
+
const isExactActive = computed(() => activeRecordIndex.value > -1 && activeRecordIndex.value === currentRoute.matched.length - 1 && isSameRouteLocationParams(currentRoute.params, route.value.params));
|
|
1383
|
+
function navigate(e = {}) {
|
|
1384
|
+
if (guardEvent(e)) {
|
|
1385
|
+
const p = router[unref(props.replace) ? "replace" : "push"](unref(props.to)).catch(noop);
|
|
1386
|
+
if (props.viewTransition && typeof document !== "undefined" && "startViewTransition" in document) document.startViewTransition(() => p);
|
|
1387
|
+
return p;
|
|
1388
|
+
}
|
|
1389
|
+
return Promise.resolve();
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* NOTE: update {@link _RouterLinkI}'s `$slots` type when updating this
|
|
1393
|
+
*/
|
|
1394
|
+
return {
|
|
1395
|
+
route,
|
|
1396
|
+
href: computed(() => route.value.href),
|
|
1397
|
+
isActive,
|
|
1398
|
+
isExactActive,
|
|
1399
|
+
navigate
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
function preferSingleVNode(vnodes) {
|
|
1403
|
+
return vnodes.length === 1 ? vnodes[0] : vnodes;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Component to render a link that triggers a navigation on click.
|
|
1407
|
+
*/
|
|
1408
|
+
var RouterLink = /* @__PURE__ */ defineComponent({
|
|
1409
|
+
name: "RouterLink",
|
|
1410
|
+
compatConfig: { MODE: 3 },
|
|
1411
|
+
props: {
|
|
1412
|
+
to: {
|
|
1413
|
+
type: [String, Object],
|
|
1414
|
+
required: true
|
|
1415
|
+
},
|
|
1416
|
+
replace: Boolean,
|
|
1417
|
+
activeClass: String,
|
|
1418
|
+
exactActiveClass: String,
|
|
1419
|
+
custom: Boolean,
|
|
1420
|
+
ariaCurrentValue: {
|
|
1421
|
+
type: String,
|
|
1422
|
+
default: "page"
|
|
1423
|
+
},
|
|
1424
|
+
viewTransition: Boolean
|
|
1425
|
+
},
|
|
1426
|
+
useLink,
|
|
1427
|
+
setup(props, { slots }) {
|
|
1428
|
+
const link = reactive(useLink(props));
|
|
1429
|
+
const { options } = inject(routerKey);
|
|
1430
|
+
const elClass = computed(() => ({
|
|
1431
|
+
[getLinkClass(props.activeClass, options.linkActiveClass, "router-link-active")]: link.isActive,
|
|
1432
|
+
[getLinkClass(props.exactActiveClass, options.linkExactActiveClass, "router-link-exact-active")]: link.isExactActive
|
|
1433
|
+
}));
|
|
1434
|
+
return () => {
|
|
1435
|
+
const children = slots.default && preferSingleVNode(slots.default(link));
|
|
1436
|
+
return props.custom ? children : h("a", {
|
|
1437
|
+
"aria-current": link.isExactActive ? props.ariaCurrentValue : null,
|
|
1438
|
+
href: link.href,
|
|
1439
|
+
onClick: link.navigate,
|
|
1440
|
+
class: elClass.value
|
|
1441
|
+
}, children);
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
function guardEvent(e) {
|
|
1446
|
+
if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return;
|
|
1447
|
+
if (e.defaultPrevented) return;
|
|
1448
|
+
if (e.button !== void 0 && e.button !== 0) return;
|
|
1449
|
+
if (e.currentTarget && e.currentTarget.getAttribute) {
|
|
1450
|
+
const target = e.currentTarget.getAttribute("target");
|
|
1451
|
+
if (/\b_blank\b/i.test(target)) return;
|
|
1452
|
+
}
|
|
1453
|
+
if (e.preventDefault) e.preventDefault();
|
|
1454
|
+
return true;
|
|
1455
|
+
}
|
|
1456
|
+
function includesParams(outer, inner) {
|
|
1457
|
+
for (const key in inner) {
|
|
1458
|
+
const innerValue = inner[key];
|
|
1459
|
+
const outerValue = outer[key];
|
|
1460
|
+
if (typeof innerValue === "string") {
|
|
1461
|
+
if (innerValue !== outerValue) return false;
|
|
1462
|
+
} else if (!isArray(outerValue) || outerValue.length !== innerValue.length || innerValue.some((value, i) => value.valueOf() !== outerValue[i].valueOf())) return false;
|
|
1463
|
+
}
|
|
1464
|
+
return true;
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Get the original path value of a record by following its aliasOf
|
|
1468
|
+
* @param record
|
|
1469
|
+
*/
|
|
1470
|
+
function getOriginalPath(record) {
|
|
1471
|
+
return record ? record.aliasOf ? record.aliasOf.path : record.path : "";
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Utility class to get the active class based on defaults.
|
|
1475
|
+
* @param propClass
|
|
1476
|
+
* @param globalClass
|
|
1477
|
+
* @param defaultClass
|
|
1478
|
+
*/
|
|
1479
|
+
var getLinkClass = (propClass, globalClass, defaultClass) => propClass != null ? propClass : globalClass != null ? globalClass : defaultClass;
|
|
1480
|
+
var RouterViewImpl = /* @__PURE__ */ defineComponent({
|
|
1481
|
+
name: "RouterView",
|
|
1482
|
+
inheritAttrs: false,
|
|
1483
|
+
props: {
|
|
1484
|
+
name: {
|
|
1485
|
+
type: String,
|
|
1486
|
+
default: "default"
|
|
1487
|
+
},
|
|
1488
|
+
route: Object
|
|
1489
|
+
},
|
|
1490
|
+
compatConfig: { MODE: 3 },
|
|
1491
|
+
setup(props, { attrs, slots }) {
|
|
1492
|
+
const injectedRoute = inject(routerViewLocationKey);
|
|
1493
|
+
const routeToDisplay = computed(() => props.route || injectedRoute.value);
|
|
1494
|
+
const injectedDepth = inject(viewDepthKey, 0);
|
|
1495
|
+
const depth = computed(() => {
|
|
1496
|
+
let initialDepth = unref(injectedDepth);
|
|
1497
|
+
const { matched } = routeToDisplay.value;
|
|
1498
|
+
let matchedRoute;
|
|
1499
|
+
while ((matchedRoute = matched[initialDepth]) && !matchedRoute.components) initialDepth++;
|
|
1500
|
+
return initialDepth;
|
|
1501
|
+
});
|
|
1502
|
+
const matchedRouteRef = computed(() => routeToDisplay.value.matched[depth.value]);
|
|
1503
|
+
provide(viewDepthKey, computed(() => depth.value + 1));
|
|
1504
|
+
provide(matchedRouteKey, matchedRouteRef);
|
|
1505
|
+
provide(routerViewLocationKey, routeToDisplay);
|
|
1506
|
+
const viewRef = ref();
|
|
1507
|
+
watch(() => [
|
|
1508
|
+
viewRef.value,
|
|
1509
|
+
matchedRouteRef.value,
|
|
1510
|
+
props.name
|
|
1511
|
+
], ([instance, to, name], [oldInstance, from, oldName]) => {
|
|
1512
|
+
if (to) {
|
|
1513
|
+
to.instances[name] = instance;
|
|
1514
|
+
if (from && from !== to && instance && instance === oldInstance) {
|
|
1515
|
+
if (!to.leaveGuards.size) to.leaveGuards = from.leaveGuards;
|
|
1516
|
+
if (!to.updateGuards.size) to.updateGuards = from.updateGuards;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if (instance && to && (!from || !isSameRouteRecord(to, from) || !oldInstance)) (to.enterCallbacks[name] || []).forEach((callback) => callback(instance));
|
|
1520
|
+
}, { flush: "post" });
|
|
1521
|
+
return () => {
|
|
1522
|
+
const route = routeToDisplay.value;
|
|
1523
|
+
const currentName = props.name;
|
|
1524
|
+
const matchedRoute = matchedRouteRef.value;
|
|
1525
|
+
const ViewComponent = matchedRoute && matchedRoute.components[currentName];
|
|
1526
|
+
if (!ViewComponent) return normalizeSlot(slots.default, {
|
|
1527
|
+
Component: ViewComponent,
|
|
1528
|
+
route
|
|
1529
|
+
});
|
|
1530
|
+
const routePropsOption = matchedRoute.props[currentName];
|
|
1531
|
+
const routeProps = routePropsOption ? routePropsOption === true ? route.params : typeof routePropsOption === "function" ? routePropsOption(route) : routePropsOption : null;
|
|
1532
|
+
const onVnodeUnmounted = (vnode) => {
|
|
1533
|
+
if (vnode.component.isUnmounted) matchedRoute.instances[currentName] = null;
|
|
1534
|
+
};
|
|
1535
|
+
const component = h(ViewComponent, assign({}, routeProps, attrs, {
|
|
1536
|
+
onVnodeUnmounted,
|
|
1537
|
+
ref: viewRef
|
|
1538
|
+
}));
|
|
1539
|
+
return normalizeSlot(slots.default, {
|
|
1540
|
+
Component: component,
|
|
1541
|
+
route
|
|
1542
|
+
}) || component;
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
function normalizeSlot(slot, data) {
|
|
1547
|
+
if (!slot) return null;
|
|
1548
|
+
const slotContent = slot(data);
|
|
1549
|
+
return slotContent.length === 1 ? slotContent[0] : slotContent;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Component to display the current route the user is at.
|
|
1553
|
+
*/
|
|
1554
|
+
var RouterView = RouterViewImpl;
|
|
1555
|
+
/**
|
|
1556
|
+
* Creates a Router instance that can be used by a Vue app.
|
|
1557
|
+
*
|
|
1558
|
+
* @param options - {@link RouterOptions}
|
|
1559
|
+
*/
|
|
1560
|
+
function createRouter(options) {
|
|
1561
|
+
const matcher = createRouterMatcher(options.routes, options);
|
|
1562
|
+
const parseQuery$1 = options.parseQuery || parseQuery;
|
|
1563
|
+
const stringifyQuery$1 = options.stringifyQuery || stringifyQuery;
|
|
1564
|
+
const routerHistory = options.history;
|
|
1565
|
+
const beforeGuards = useCallbacks();
|
|
1566
|
+
const beforeResolveGuards = useCallbacks();
|
|
1567
|
+
const afterGuards = useCallbacks();
|
|
1568
|
+
const currentRoute = shallowRef(START_LOCATION_NORMALIZED);
|
|
1569
|
+
let pendingLocation = START_LOCATION_NORMALIZED;
|
|
1570
|
+
if (isBrowser && options.scrollBehavior && "scrollRestoration" in history) history.scrollRestoration = "manual";
|
|
1571
|
+
const normalizeParams = applyToParams.bind(null, (paramValue) => "" + paramValue);
|
|
1572
|
+
const encodeParams = applyToParams.bind(null, encodeParam);
|
|
1573
|
+
const decodeParams = applyToParams.bind(null, decode);
|
|
1574
|
+
function addRoute(parentOrRoute, route) {
|
|
1575
|
+
let parent;
|
|
1576
|
+
let record;
|
|
1577
|
+
if (isRouteName(parentOrRoute)) {
|
|
1578
|
+
parent = matcher.getRecordMatcher(parentOrRoute);
|
|
1579
|
+
record = route;
|
|
1580
|
+
} else record = parentOrRoute;
|
|
1581
|
+
return matcher.addRoute(record, parent);
|
|
1582
|
+
}
|
|
1583
|
+
function removeRoute(name) {
|
|
1584
|
+
const recordMatcher = matcher.getRecordMatcher(name);
|
|
1585
|
+
if (recordMatcher) matcher.removeRoute(recordMatcher);
|
|
1586
|
+
}
|
|
1587
|
+
function getRoutes() {
|
|
1588
|
+
return matcher.getRoutes().map((routeMatcher) => routeMatcher.record);
|
|
1589
|
+
}
|
|
1590
|
+
function hasRoute(name) {
|
|
1591
|
+
return !!matcher.getRecordMatcher(name);
|
|
1592
|
+
}
|
|
1593
|
+
function resolve(rawLocation, currentLocation) {
|
|
1594
|
+
currentLocation = assign({}, currentLocation || currentRoute.value);
|
|
1595
|
+
if (typeof rawLocation === "string") {
|
|
1596
|
+
const locationNormalized = parseURL(parseQuery$1, rawLocation, currentLocation.path);
|
|
1597
|
+
const matchedRoute = matcher.resolve({ path: locationNormalized.path }, currentLocation);
|
|
1598
|
+
const href = routerHistory.createHref(locationNormalized.fullPath);
|
|
1599
|
+
return assign(locationNormalized, matchedRoute, {
|
|
1600
|
+
params: decodeParams(matchedRoute.params),
|
|
1601
|
+
hash: decode(locationNormalized.hash),
|
|
1602
|
+
redirectedFrom: void 0,
|
|
1603
|
+
href
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
let matcherLocation;
|
|
1607
|
+
if (rawLocation.path != null) matcherLocation = assign({}, rawLocation, { path: parseURL(parseQuery$1, rawLocation.path, currentLocation.path).path });
|
|
1608
|
+
else {
|
|
1609
|
+
const targetParams = assign({}, rawLocation.params);
|
|
1610
|
+
for (const key in targetParams) if (targetParams[key] == null) delete targetParams[key];
|
|
1611
|
+
matcherLocation = assign({}, rawLocation, { params: encodeParams(targetParams) });
|
|
1612
|
+
currentLocation.params = encodeParams(currentLocation.params);
|
|
1613
|
+
}
|
|
1614
|
+
const matchedRoute = matcher.resolve(matcherLocation, currentLocation);
|
|
1615
|
+
const hash = rawLocation.hash || "";
|
|
1616
|
+
matchedRoute.params = normalizeParams(decodeParams(matchedRoute.params));
|
|
1617
|
+
const fullPath = stringifyURL(stringifyQuery$1, assign({}, rawLocation, {
|
|
1618
|
+
hash: encodeHash(hash),
|
|
1619
|
+
path: matchedRoute.path
|
|
1620
|
+
}));
|
|
1621
|
+
const href = routerHistory.createHref(fullPath);
|
|
1622
|
+
return assign({
|
|
1623
|
+
fullPath,
|
|
1624
|
+
hash,
|
|
1625
|
+
query: stringifyQuery$1 === stringifyQuery ? normalizeQuery(rawLocation.query) : rawLocation.query || {}
|
|
1626
|
+
}, matchedRoute, {
|
|
1627
|
+
redirectedFrom: void 0,
|
|
1628
|
+
href
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
function locationAsObject(to) {
|
|
1632
|
+
return typeof to === "string" ? parseURL(parseQuery$1, to, currentRoute.value.path) : assign({}, to);
|
|
1633
|
+
}
|
|
1634
|
+
function checkCanceledNavigation(to, from) {
|
|
1635
|
+
if (pendingLocation !== to) return createRouterError(ErrorTypes.NAVIGATION_CANCELLED, {
|
|
1636
|
+
from,
|
|
1637
|
+
to
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
function push(to) {
|
|
1641
|
+
return pushWithRedirect(to);
|
|
1642
|
+
}
|
|
1643
|
+
function replace(to) {
|
|
1644
|
+
return push(assign(locationAsObject(to), { replace: true }));
|
|
1645
|
+
}
|
|
1646
|
+
function handleRedirectRecord(to, from) {
|
|
1647
|
+
const lastMatched = to.matched[to.matched.length - 1];
|
|
1648
|
+
if (lastMatched && lastMatched.redirect) {
|
|
1649
|
+
const { redirect } = lastMatched;
|
|
1650
|
+
let newTargetLocation = typeof redirect === "function" ? redirect(to, from) : redirect;
|
|
1651
|
+
if (typeof newTargetLocation === "string") {
|
|
1652
|
+
newTargetLocation = newTargetLocation.includes("?") || newTargetLocation.includes("#") ? newTargetLocation = locationAsObject(newTargetLocation) : { path: newTargetLocation };
|
|
1653
|
+
newTargetLocation.params = {};
|
|
1654
|
+
}
|
|
1655
|
+
return assign({
|
|
1656
|
+
query: to.query,
|
|
1657
|
+
hash: to.hash,
|
|
1658
|
+
params: newTargetLocation.path != null ? {} : to.params
|
|
1659
|
+
}, newTargetLocation);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function pushWithRedirect(to, redirectedFrom) {
|
|
1663
|
+
const targetLocation = pendingLocation = resolve(to);
|
|
1664
|
+
const from = currentRoute.value;
|
|
1665
|
+
const data = to.state;
|
|
1666
|
+
const force = to.force;
|
|
1667
|
+
const replace = to.replace === true;
|
|
1668
|
+
const shouldRedirect = handleRedirectRecord(targetLocation, from);
|
|
1669
|
+
if (shouldRedirect) return pushWithRedirect(assign(locationAsObject(shouldRedirect), {
|
|
1670
|
+
state: typeof shouldRedirect === "object" ? assign({}, data, shouldRedirect.state) : data,
|
|
1671
|
+
force,
|
|
1672
|
+
replace
|
|
1673
|
+
}), redirectedFrom || targetLocation);
|
|
1674
|
+
const toLocation = targetLocation;
|
|
1675
|
+
toLocation.redirectedFrom = redirectedFrom;
|
|
1676
|
+
let failure;
|
|
1677
|
+
if (!force && isSameRouteLocation(stringifyQuery$1, from, targetLocation)) {
|
|
1678
|
+
failure = createRouterError(ErrorTypes.NAVIGATION_DUPLICATED, {
|
|
1679
|
+
to: toLocation,
|
|
1680
|
+
from
|
|
1681
|
+
});
|
|
1682
|
+
handleScroll(from, from, true, false);
|
|
1683
|
+
}
|
|
1684
|
+
return (failure ? Promise.resolve(failure) : navigate(toLocation, from)).catch((error) => isNavigationFailure(error) ? isNavigationFailure(error, ErrorTypes.NAVIGATION_GUARD_REDIRECT) ? error : markAsReady(error) : triggerError(error, toLocation, from)).then((failure) => {
|
|
1685
|
+
if (failure) {
|
|
1686
|
+
if (isNavigationFailure(failure, ErrorTypes.NAVIGATION_GUARD_REDIRECT)) return pushWithRedirect(assign({ replace }, locationAsObject(failure.to), {
|
|
1687
|
+
state: typeof failure.to === "object" ? assign({}, data, failure.to.state) : data,
|
|
1688
|
+
force
|
|
1689
|
+
}), redirectedFrom || toLocation);
|
|
1690
|
+
} else failure = finalizeNavigation(toLocation, from, true, replace, data);
|
|
1691
|
+
triggerAfterEach(toLocation, from, failure);
|
|
1692
|
+
return failure;
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Helper to reject and skip all navigation guards if a new navigation happened
|
|
1697
|
+
* @param to
|
|
1698
|
+
* @param from
|
|
1699
|
+
*/
|
|
1700
|
+
function checkCanceledNavigationAndReject(to, from) {
|
|
1701
|
+
const error = checkCanceledNavigation(to, from);
|
|
1702
|
+
return error ? Promise.reject(error) : Promise.resolve();
|
|
1703
|
+
}
|
|
1704
|
+
function runWithContext(fn) {
|
|
1705
|
+
const app = installedApps.values().next().value;
|
|
1706
|
+
return app && typeof app.runWithContext === "function" ? app.runWithContext(fn) : fn();
|
|
1707
|
+
}
|
|
1708
|
+
function navigate(to, from) {
|
|
1709
|
+
let guards;
|
|
1710
|
+
const [leavingRecords, updatingRecords, enteringRecords] = extractChangingRecords(to, from);
|
|
1711
|
+
guards = extractComponentsGuards(leavingRecords.reverse(), "beforeRouteLeave", to, from);
|
|
1712
|
+
for (const record of leavingRecords) record.leaveGuards.forEach((guard) => {
|
|
1713
|
+
guards.push(guardToPromiseFn(guard, to, from));
|
|
1714
|
+
});
|
|
1715
|
+
const canceledNavigationCheck = checkCanceledNavigationAndReject.bind(null, to, from);
|
|
1716
|
+
guards.push(canceledNavigationCheck);
|
|
1717
|
+
return runGuardQueue(guards).then(() => {
|
|
1718
|
+
guards = [];
|
|
1719
|
+
for (const guard of beforeGuards.list()) guards.push(guardToPromiseFn(guard, to, from));
|
|
1720
|
+
guards.push(canceledNavigationCheck);
|
|
1721
|
+
return runGuardQueue(guards);
|
|
1722
|
+
}).then(() => {
|
|
1723
|
+
guards = extractComponentsGuards(updatingRecords, "beforeRouteUpdate", to, from);
|
|
1724
|
+
for (const record of updatingRecords) record.updateGuards.forEach((guard) => {
|
|
1725
|
+
guards.push(guardToPromiseFn(guard, to, from));
|
|
1726
|
+
});
|
|
1727
|
+
guards.push(canceledNavigationCheck);
|
|
1728
|
+
return runGuardQueue(guards);
|
|
1729
|
+
}).then(() => {
|
|
1730
|
+
guards = [];
|
|
1731
|
+
for (const record of enteringRecords) if (record.beforeEnter) if (isArray(record.beforeEnter)) for (const beforeEnter of record.beforeEnter) guards.push(guardToPromiseFn(beforeEnter, to, from));
|
|
1732
|
+
else guards.push(guardToPromiseFn(record.beforeEnter, to, from));
|
|
1733
|
+
guards.push(canceledNavigationCheck);
|
|
1734
|
+
return runGuardQueue(guards);
|
|
1735
|
+
}).then(() => {
|
|
1736
|
+
to.matched.forEach((record) => record.enterCallbacks = {});
|
|
1737
|
+
guards = extractComponentsGuards(enteringRecords, "beforeRouteEnter", to, from, runWithContext);
|
|
1738
|
+
guards.push(canceledNavigationCheck);
|
|
1739
|
+
return runGuardQueue(guards);
|
|
1740
|
+
}).then(() => {
|
|
1741
|
+
guards = [];
|
|
1742
|
+
for (const guard of beforeResolveGuards.list()) guards.push(guardToPromiseFn(guard, to, from));
|
|
1743
|
+
guards.push(canceledNavigationCheck);
|
|
1744
|
+
return runGuardQueue(guards);
|
|
1745
|
+
}).catch((err) => isNavigationFailure(err, ErrorTypes.NAVIGATION_CANCELLED) ? err : Promise.reject(err));
|
|
1746
|
+
}
|
|
1747
|
+
function triggerAfterEach(to, from, failure) {
|
|
1748
|
+
afterGuards.list().forEach((guard) => runWithContext(() => guard(to, from, failure)));
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* - Cleans up any navigation guards
|
|
1752
|
+
* - Changes the url if necessary
|
|
1753
|
+
* - Calls the scrollBehavior
|
|
1754
|
+
*/
|
|
1755
|
+
function finalizeNavigation(toLocation, from, isPush, replace, data) {
|
|
1756
|
+
const error = checkCanceledNavigation(toLocation, from);
|
|
1757
|
+
if (error) return error;
|
|
1758
|
+
const isFirstNavigation = from === START_LOCATION_NORMALIZED;
|
|
1759
|
+
const state = !isBrowser ? {} : history.state;
|
|
1760
|
+
if (isPush) if (replace || isFirstNavigation) routerHistory.replace(toLocation.fullPath, assign({ scroll: isFirstNavigation && state && state.scroll }, data));
|
|
1761
|
+
else routerHistory.push(toLocation.fullPath, data);
|
|
1762
|
+
currentRoute.value = toLocation;
|
|
1763
|
+
handleScroll(toLocation, from, isPush, isFirstNavigation);
|
|
1764
|
+
markAsReady();
|
|
1765
|
+
}
|
|
1766
|
+
let removeHistoryListener;
|
|
1767
|
+
function setupListeners() {
|
|
1768
|
+
if (removeHistoryListener) return;
|
|
1769
|
+
removeHistoryListener = routerHistory.listen((to, _from, info) => {
|
|
1770
|
+
if (!router.listening) return;
|
|
1771
|
+
const toLocation = resolve(to);
|
|
1772
|
+
const shouldRedirect = handleRedirectRecord(toLocation, router.currentRoute.value);
|
|
1773
|
+
if (shouldRedirect) {
|
|
1774
|
+
pushWithRedirect(assign(shouldRedirect, {
|
|
1775
|
+
replace: true,
|
|
1776
|
+
force: true
|
|
1777
|
+
}), toLocation).catch(noop);
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
pendingLocation = toLocation;
|
|
1781
|
+
const from = currentRoute.value;
|
|
1782
|
+
if (isBrowser) saveScrollPosition(getScrollKey(from.fullPath, info.delta), computeScrollPosition());
|
|
1783
|
+
navigate(toLocation, from).catch((error) => {
|
|
1784
|
+
if (isNavigationFailure(error, ErrorTypes.NAVIGATION_ABORTED | ErrorTypes.NAVIGATION_CANCELLED)) return error;
|
|
1785
|
+
if (isNavigationFailure(error, ErrorTypes.NAVIGATION_GUARD_REDIRECT)) {
|
|
1786
|
+
pushWithRedirect(assign(locationAsObject(error.to), { force: true }), toLocation).then((failure) => {
|
|
1787
|
+
if (isNavigationFailure(failure, ErrorTypes.NAVIGATION_ABORTED | ErrorTypes.NAVIGATION_DUPLICATED) && !info.delta && info.type === NavigationType.pop) routerHistory.go(-1, false);
|
|
1788
|
+
}).catch(noop);
|
|
1789
|
+
return Promise.reject();
|
|
1790
|
+
}
|
|
1791
|
+
if (info.delta) routerHistory.go(-info.delta, false);
|
|
1792
|
+
return triggerError(error, toLocation, from);
|
|
1793
|
+
}).then((failure) => {
|
|
1794
|
+
failure = failure || finalizeNavigation(toLocation, from, false);
|
|
1795
|
+
if (failure) {
|
|
1796
|
+
if (info.delta && !isNavigationFailure(failure, ErrorTypes.NAVIGATION_CANCELLED)) routerHistory.go(-info.delta, false);
|
|
1797
|
+
else if (info.type === NavigationType.pop && isNavigationFailure(failure, ErrorTypes.NAVIGATION_ABORTED | ErrorTypes.NAVIGATION_DUPLICATED)) routerHistory.go(-1, false);
|
|
1798
|
+
}
|
|
1799
|
+
triggerAfterEach(toLocation, from, failure);
|
|
1800
|
+
}).catch(noop);
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
let readyHandlers = useCallbacks();
|
|
1804
|
+
let errorListeners = useCallbacks();
|
|
1805
|
+
let ready;
|
|
1806
|
+
/**
|
|
1807
|
+
* Trigger errorListeners added via onError and throws the error as well
|
|
1808
|
+
*
|
|
1809
|
+
* @param error - error to throw
|
|
1810
|
+
* @param to - location we were navigating to when the error happened
|
|
1811
|
+
* @param from - location we were navigating from when the error happened
|
|
1812
|
+
* @returns the error as a rejected promise
|
|
1813
|
+
*/
|
|
1814
|
+
function triggerError(error, to, from) {
|
|
1815
|
+
markAsReady(error);
|
|
1816
|
+
const list = errorListeners.list();
|
|
1817
|
+
if (list.length) list.forEach((handler) => handler(error, to, from));
|
|
1818
|
+
else console.error(error);
|
|
1819
|
+
return Promise.reject(error);
|
|
1820
|
+
}
|
|
1821
|
+
function isReady() {
|
|
1822
|
+
if (ready && currentRoute.value !== START_LOCATION_NORMALIZED) return Promise.resolve();
|
|
1823
|
+
return new Promise((resolve, reject) => {
|
|
1824
|
+
readyHandlers.add([resolve, reject]);
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
function markAsReady(err) {
|
|
1828
|
+
if (!ready) {
|
|
1829
|
+
ready = !err;
|
|
1830
|
+
setupListeners();
|
|
1831
|
+
readyHandlers.list().forEach(([resolve, reject]) => err ? reject(err) : resolve());
|
|
1832
|
+
readyHandlers.reset();
|
|
1833
|
+
}
|
|
1834
|
+
return err;
|
|
1835
|
+
}
|
|
1836
|
+
function handleScroll(to, from, isPush, isFirstNavigation) {
|
|
1837
|
+
const { scrollBehavior } = options;
|
|
1838
|
+
if (!isBrowser || !scrollBehavior) return Promise.resolve();
|
|
1839
|
+
const scrollPosition = !isPush && getSavedScrollPosition(getScrollKey(to.fullPath, 0)) || (isFirstNavigation || !isPush) && history.state && history.state.scroll || null;
|
|
1840
|
+
return nextTick().then(() => scrollBehavior(to, from, scrollPosition)).then((position) => position && scrollToPosition(position)).catch((err) => triggerError(err, to, from));
|
|
1841
|
+
}
|
|
1842
|
+
const go = (delta) => routerHistory.go(delta);
|
|
1843
|
+
let started;
|
|
1844
|
+
const installedApps = /* @__PURE__ */ new Set();
|
|
1845
|
+
const router = {
|
|
1846
|
+
currentRoute,
|
|
1847
|
+
listening: true,
|
|
1848
|
+
addRoute,
|
|
1849
|
+
removeRoute,
|
|
1850
|
+
clearRoutes: matcher.clearRoutes,
|
|
1851
|
+
hasRoute,
|
|
1852
|
+
getRoutes,
|
|
1853
|
+
resolve,
|
|
1854
|
+
options,
|
|
1855
|
+
push,
|
|
1856
|
+
replace,
|
|
1857
|
+
go,
|
|
1858
|
+
back: () => go(-1),
|
|
1859
|
+
forward: () => go(1),
|
|
1860
|
+
beforeEach: beforeGuards.add,
|
|
1861
|
+
beforeResolve: beforeResolveGuards.add,
|
|
1862
|
+
afterEach: afterGuards.add,
|
|
1863
|
+
onError: errorListeners.add,
|
|
1864
|
+
isReady,
|
|
1865
|
+
install(app) {
|
|
1866
|
+
app.component("RouterLink", RouterLink);
|
|
1867
|
+
app.component("RouterView", RouterView);
|
|
1868
|
+
app.config.globalProperties.$router = router;
|
|
1869
|
+
Object.defineProperty(app.config.globalProperties, "$route", {
|
|
1870
|
+
enumerable: true,
|
|
1871
|
+
get: () => unref(currentRoute)
|
|
1872
|
+
});
|
|
1873
|
+
if (isBrowser && !started && currentRoute.value === START_LOCATION_NORMALIZED) {
|
|
1874
|
+
started = true;
|
|
1875
|
+
push(routerHistory.location).catch((err) => {});
|
|
1876
|
+
}
|
|
1877
|
+
const reactiveRoute = {};
|
|
1878
|
+
for (const key in START_LOCATION_NORMALIZED) Object.defineProperty(reactiveRoute, key, {
|
|
1879
|
+
get: () => currentRoute.value[key],
|
|
1880
|
+
enumerable: true
|
|
1881
|
+
});
|
|
1882
|
+
app.provide(routerKey, router);
|
|
1883
|
+
app.provide(routeLocationKey, shallowReactive(reactiveRoute));
|
|
1884
|
+
app.provide(routerViewLocationKey, currentRoute);
|
|
1885
|
+
const unmountApp = app.unmount;
|
|
1886
|
+
installedApps.add(app);
|
|
1887
|
+
app.unmount = function() {
|
|
1888
|
+
installedApps.delete(app);
|
|
1889
|
+
if (installedApps.size < 1) {
|
|
1890
|
+
pendingLocation = START_LOCATION_NORMALIZED;
|
|
1891
|
+
removeHistoryListener && removeHistoryListener();
|
|
1892
|
+
removeHistoryListener = null;
|
|
1893
|
+
currentRoute.value = START_LOCATION_NORMALIZED;
|
|
1894
|
+
started = false;
|
|
1895
|
+
ready = false;
|
|
1896
|
+
}
|
|
1897
|
+
unmountApp();
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
function runGuardQueue(guards) {
|
|
1902
|
+
return guards.reduce((promise, guard) => promise.then(() => runWithContext(guard)), Promise.resolve());
|
|
1903
|
+
}
|
|
1904
|
+
return router;
|
|
1905
|
+
}
|
|
1906
|
+
//#endregion
|
|
1907
|
+
export { createRouter as n, createWebHashHistory as r, RouterLink as t };
|