vue-router-c7cbbcaa.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. import{s as e,u as t,av as n,n as r,p as o,d as a,X as s,m as c,af as l,B as i,h as u,i as f}from"./@vue-37836d09.js";
  2. /*!
  3. * vue-router v4.5.0
  4. * (c) 2024 Eduardo San Martin Morote
  5. * @license MIT
  6. */const p="undefined"!=typeof document;
  7. /**
  8. * Allows differentiating lazy components from functional components and vue-class-component
  9. * @internal
  10. *
  11. * @param component
  12. */function h(e){return"object"==typeof e||"displayName"in e||"props"in e||"__vccOpts"in e}const d=Object.assign;function m(e,t){const n={};for(const r in t){const o=t[r];n[r]=v(o)?o.map(e):e(o)}return n}const g=()=>{},v=Array.isArray,y=/#/g,b=/&/g,w=/\//g,E=/=/g,R=/\?/g,k=/\+/g,O=/%5B/g,x=/%5D/g,P=/%5E/g,C=/%60/g,j=/%7B/g,$=/%7C/g,S=/%7D/g,A=/%20/g;
  13. /**
  14. * Typesafe alternative to Array.isArray
  15. * https://github.com/microsoft/TypeScript/pull/48228
  16. */ // }
  17. /**
  18. * Encode characters that need to be encoded on the path, search and hash
  19. * sections of the URL.
  20. *
  21. * @internal
  22. * @param text - string to encode
  23. * @returns encoded string
  24. */
  25. function q(e){return encodeURI(""+e).replace($,"|").replace(O,"[").replace(x,"]")}
  26. /**
  27. * Encode characters that need to be encoded on the hash section of the URL.
  28. *
  29. * @param text - string to encode
  30. * @returns encoded string
  31. */
  32. /**
  33. * Encode characters that need to be encoded query values on the query
  34. * section of the URL.
  35. *
  36. * @param text - string to encode
  37. * @returns encoded string
  38. */
  39. function L(e){return q(e).replace(k,"%2B").replace(A,"+").replace(y,"%23").replace(b,"%26").replace(C,"`").replace(j,"{").replace(S,"}").replace(P,"^")}
  40. /**
  41. * Like `encodeQueryValue` but also encodes the `=` character.
  42. *
  43. * @param text - string to encode
  44. */
  45. /**
  46. * Encode characters that need to be encoded on the path section of the URL as a
  47. * param. This function encodes everything {@link encodePath} does plus the
  48. * slash (`/`) character. If `text` is `null` or `undefined`, returns an empty
  49. * string instead.
  50. *
  51. * @param text - string to encode
  52. * @returns encoded string
  53. */
  54. function M(e){return null==e?"":
  55. /**
  56. * Encode characters that need to be encoded on the path section of the URL.
  57. *
  58. * @param text - string to encode
  59. * @returns encoded string
  60. */
  61. function(e){return q(e).replace(y,"%23").replace(R,"%3F")}(e).replace(w,"%2F")}
  62. /**
  63. * Decode text using `decodeURIComponent`. Returns the original text if it
  64. * fails.
  65. *
  66. * @param text - string to decode
  67. * @returns decoded string
  68. */function B(e){try{return decodeURIComponent(""+e)}catch(t){}return""+e}const G=/\/$/;
  69. /**
  70. * Transforms a URI into a normalized history location
  71. *
  72. * @param parseQuery
  73. * @param location - URI to normalize
  74. * @param currentLocation - current absolute location. Allows resolving relative
  75. * paths. Must start with `/`. Defaults to `/`
  76. * @returns a normalized history location
  77. */
  78. function _(e,t,n="/"){let r,o={},a="",s="";
  79. // Could use URL and URLSearchParams but IE 11 doesn't support it
  80. // TODO: move to new URL()
  81. const c=t.indexOf("#");let l=t.indexOf("?");
  82. // the hash appears before the search, so it's not part of the search string
  83. // empty path means a relative query or hash `?foo=f`, `#thing`
  84. return c<l&&c>=0&&(l=-1),l>-1&&(r=t.slice(0,l),a=t.slice(l+1,c>-1?c:t.length),o=e(a)),c>-1&&(r=r||t.slice(0,c),
  85. // keep the # character
  86. s=t.slice(c,t.length)),
  87. // no search and no query
  88. r=
  89. /**
  90. * Resolves a relative path that starts with `.`.
  91. *
  92. * @param to - path location we are resolving
  93. * @param from - currentLocation.path, should start with `/`
  94. */
  95. function(e,t){if(e.startsWith("/"))return e;if(!e)return t;const n=t.split("/"),r=e.split("/"),o=r[r.length-1];
  96. // make . and ./ the same (../ === .., ../../ === ../..)
  97. // this is the same behavior as new URL()
  98. ".."!==o&&"."!==o||r.push("");let a,s,c=n.length-1;for(a=0;a<r.length;a++)
  99. // we stay on the same position
  100. if(s=r[a],"."!==s){
  101. // go up in the from array
  102. if(".."!==s)break;
  103. // we can't go below zero, but we still need to increment toPosition
  104. c>1&&c--;
  105. // continue
  106. }return n.slice(0,c).join("/")+"/"+r.slice(a).join("/")}
  107. /**
  108. * Initial route location where the router is. Can be used in navigation guards
  109. * to differentiate the initial navigation.
  110. *
  111. * @example
  112. * ```js
  113. * import { START_LOCATION } from 'vue-router'
  114. *
  115. * router.beforeEach((to, from) => {
  116. * if (from === START_LOCATION) {
  117. * // initial navigation
  118. * }
  119. * })
  120. * ```
  121. */(null!=r?r:t,n),{fullPath:r+(a&&"?")+a+s,path:r,query:o,hash:B(s)}}
  122. /**
  123. * Stringifies a URL object
  124. *
  125. * @param stringifyQuery
  126. * @param location
  127. */
  128. /**
  129. * Strips off the base from the beginning of a location.pathname in a non-case-sensitive way.
  130. *
  131. * @param pathname - location.pathname
  132. * @param base - base to strip off
  133. */
  134. function I(e,t){
  135. // no base or base is not found at the beginning
  136. return t&&e.toLowerCase().startsWith(t.toLowerCase())?e.slice(t.length)||"/":e}
  137. /**
  138. * Checks if two RouteLocation are equal. This means that both locations are
  139. * pointing towards the same {@link RouteRecord} and that all `params`, `query`
  140. * parameters and `hash` are the same
  141. *
  142. * @param stringifyQuery - A function that takes a query object of type LocationQueryRaw and returns a string representation of it.
  143. * @param a - first {@link RouteLocation}
  144. * @param b - second {@link RouteLocation}
  145. */
  146. /**
  147. * Check if two `RouteRecords` are equal. Takes into account aliases: they are
  148. * considered equal to the `RouteRecord` they are aliasing.
  149. *
  150. * @param a - first {@link RouteRecord}
  151. * @param b - second {@link RouteRecord}
  152. */
  153. function T(e,t){
  154. // since the original record has an undefined value for aliasOf
  155. // but all aliases point to the original record, this will always compare
  156. // the original record
  157. return(e.aliasOf||e)===(t.aliasOf||t)}function W(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(!D(e[n],t[n]))return!1;return!0}function D(e,t){return v(e)?U(e,t):v(t)?U(t,e):e===t}
  158. /**
  159. * Check if two arrays are the same or if an array with one single entry is the
  160. * same as another primitive value. Used to check query and parameters
  161. *
  162. * @param a - array of values
  163. * @param b - array of values or a single value
  164. */function U(e,t){return v(t)?e.length===t.length&&e.every(((e,n)=>e===t[n])):1===e.length&&e[0]===t}const V={path:"/",
  165. // TODO: could we use a symbol in the future?
  166. name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0};var F,z;
  167. // Generic utils
  168. /**
  169. * Normalizes a base by removing any trailing slash and reading the base tag if
  170. * present.
  171. *
  172. * @param base - base to normalize
  173. */
  174. function K(e){if(!e)if(p){
  175. // respect <base> tag
  176. const t=document.querySelector("base");
  177. // strip full URL origin
  178. e=(e=t&&t.getAttribute("href")||"/").replace(/^\w+:\/\/[^\/]+/,"")}else e="/";
  179. // ensure leading slash when it was removed by the regex above avoid leading
  180. // slash with hash because the file could be read from the disk like file://
  181. // and the leading slash would cause problems
  182. // remove the trailing slash so all other method can just do `base + fullPath`
  183. // to build an href
  184. return"/"!==e[0]&&"#"!==e[0]&&(e="/"+e),e.replace(G,"")}
  185. // remove any character before the hash
  186. !function(e){e.pop="pop",e.push="push"}(F||(F={})),function(e){e.back="back",e.forward="forward",e.unknown=""}(z||(z={}));const H=/^[^#]+#/;function X(e,t){return e.replace(H,"#")+t}const Q=()=>({left:window.scrollX,top:window.scrollY});function Y(e){let t;if("el"in e){const n=e.el,r="string"==typeof n&&n.startsWith("#"),o="string"==typeof n?r?document.getElementById(n.slice(1)):document.querySelector(n):n;if(!o)return;t=function(e,t){const n=document.documentElement.getBoundingClientRect(),r=e.getBoundingClientRect();return{behavior:t.behavior,left:r.left-n.left-(t.left||0),top:r.top-n.top-(t.top||0)}}(o,e)}else t=e;"scrollBehavior"in document.documentElement.style?window.scrollTo(t):window.scrollTo(null!=t.left?t.left:window.scrollX,null!=t.top?t.top:window.scrollY)}function N(e,t){return(history.state?history.state.position-t:-1)+e}const Z=new Map;
  187. // TODO: RFC about how to save scroll position
  188. /**
  189. * ScrollBehavior instance used by the router to compute and restore the scroll
  190. * position when navigating.
  191. */
  192. // export interface ScrollHandler<ScrollPositionEntry extends HistoryStateValue, ScrollPosition extends ScrollPositionEntry> {
  193. // // returns a scroll position that can be saved in history
  194. // compute(): ScrollPositionEntry
  195. // // can take an extended ScrollPositionEntry
  196. // scroll(position: ScrollPosition): void
  197. // }
  198. // export const scrollHandler: ScrollHandler<ScrollPosition> = {
  199. // compute: computeScroll,
  200. // scroll: scrollToPosition,
  201. // }
  202. let J=()=>location.protocol+"//"+location.host
  203. /**
  204. * Creates a normalized history location from a window.location object
  205. * @param base - The base path
  206. * @param location - The window.location object
  207. */;function ee(e,t){const{pathname:n,search:r,hash:o}=t,a=e.indexOf("#");
  208. // allows hash bases like #, /#, #/, #!, #!/, /#!/, or even /folder#end
  209. if(a>-1){let t=o.includes(e.slice(a))?e.slice(a).length:1,n=o.slice(t);
  210. // prepend the starting slash to hash so the url starts with /#
  211. return"/"!==n[0]&&(n="/"+n),I(n,"")}return I(n,e)+r+o}
  212. /**
  213. * Creates a state object
  214. */
  215. function te(e,t,n,r=!1,o=!1){return{back:e,current:t,forward:n,replaced:r,position:window.history.length,scroll:o?Q():null}}
  216. /**
  217. * Creates an HTML5 history. Most common history for single page applications.
  218. *
  219. * @param base -
  220. */
  221. function ne(e){const t=function(e){const{history:t,location:n}=window,r={value:ee(e,n)},o={value:t.state};
  222. // private variables
  223. function a(r,a,s){
  224. /**
  225. * if a base tag is provided, and we are on a normal domain, we have to
  226. * respect the provided `base` attribute because pushState() will use it and
  227. * potentially erase anything before the `#` like at
  228. * https://github.com/vuejs/router/issues/685 where a base of
  229. * `/folder/#` but a base of `/` would erase the `/folder/` section. If
  230. * there is no host, the `<base>` tag makes no sense and if there isn't a
  231. * base tag we can just use everything after the `#`.
  232. */
  233. const c=e.indexOf("#"),l=c>-1?(n.host&&document.querySelector("base")?e:e.slice(c))+r:J()+e+r;try{
  234. // BROWSER QUIRK
  235. // NOTE: Safari throws a SecurityError when calling this function 100 times in 30 seconds
  236. t[s?"replaceState":"pushState"](a,"",l),o.value=a}catch(i){
  237. // Force the navigation, this also resets the call count
  238. n[s?"replace":"assign"](l)}}
  239. // build current history entry as this is a fresh navigation
  240. return o.value||a(r.value,{back:null,current:r.value,forward:null,
  241. // the length is off by one, we need to decrease it
  242. position:t.length-1,replaced:!0,
  243. // don't add a scroll as the user may have an anchor, and we want
  244. // scrollBehavior to be triggered without a saved position
  245. scroll:null},!0),{location:r,state:o,push:function(e,n){
  246. // Add to current entry the information of where we are going
  247. // as well as saving the current position
  248. const s=d({},
  249. // use current history state to gracefully handle a wrong call to
  250. // history.replaceState
  251. // https://github.com/vuejs/router/issues/366
  252. o.value,t.state,{forward:e,scroll:Q()});a(s.current,s,!0),a(e,d({},te(r.value,e,null),{position:s.position+1},n),!1),r.value=e},replace:function(e,n){a(e,d({},t.state,te(o.value.back,
  253. // keep back and forward entries but override current position
  254. e,o.value.forward,!0),n,{position:o.value.position}),!0),r.value=e}}}(e=K(e)),n=function(e,t,n,r){let o=[],a=[],s=null;const c=({state:a})=>{const c=ee(e,location),l=n.value,i=t.value;let u=0;if(a){
  255. // ignore the popstate and reset the pauseState
  256. if(n.value=c,t.value=a,s&&s===l)return void(s=null);u=i?a.position-i.position:0}else r(c);
  257. // Here we could also revert the navigation by calling history.go(-delta)
  258. // this listener will have to be adapted to not trigger again and to wait for the url
  259. // to be updated before triggering the listeners. Some kind of validation function would also
  260. // need to be passed to the listeners so the navigation can be accepted
  261. // call all listeners
  262. o.forEach((e=>{e(n.value,l,{delta:u,type:F.pop,direction:u?u>0?z.forward:z.back:z.unknown})}))};function l(){const{history:e}=window;e.state&&e.replaceState(d({},e.state,{scroll:Q()}),"")}
  263. // set up the listeners and prepare teardown callbacks
  264. return window.addEventListener("popstate",c),
  265. // TODO: could we use 'pagehide' or 'visibilitychange' instead?
  266. // https://developer.chrome.com/blog/page-lifecycle-api/
  267. window.addEventListener("beforeunload",l,{passive:!0}),{pauseListeners:function(){s=n.value},listen:function(e){
  268. // set up the listener and prepare teardown callbacks
  269. o.push(e);const t=()=>{const t=o.indexOf(e);t>-1&&o.splice(t,1)};return a.push(t),t},destroy:function(){for(const e of a)e();a=[],window.removeEventListener("popstate",c),window.removeEventListener("beforeunload",l)}}}(e,t.state,t.location,t.replace);const r=d({
  270. // it's overridden right after
  271. location:"",base:e,go:function(e,t=!0){t||n.pauseListeners(),history.go(e)},createHref:X.bind(null,e)},t,n);return Object.defineProperty(r,"location",{enumerable:!0,get:()=>t.location.value}),Object.defineProperty(r,"state",{enumerable:!0,get:()=>t.state.value}),r}function re(e){return"string"==typeof e||"symbol"==typeof e}const oe=Symbol("");
  272. /**
  273. * Enumeration with all possible types for navigation failures. Can be passed to
  274. * {@link isNavigationFailure} to check for specific failures.
  275. */var ae;
  276. /**
  277. * Creates a typed NavigationFailure object.
  278. * @internal
  279. * @param type - NavigationFailureType
  280. * @param params - { from, to }
  281. */
  282. function se(e,t){return d(new Error,{type:e,[oe]:!0},t)}function ce(e,t){return e instanceof Error&&oe in e&&(null==t||!!(e.type&t))}
  283. // default pattern for a param: non-greedy everything but /
  284. !function(e){
  285. /**
  286. * An aborted navigation is a navigation that failed because a navigation
  287. * guard returned `false` or called `next(false)`
  288. */
  289. e[e.aborted=4]="aborted",
  290. /**
  291. * A cancelled navigation is a navigation that failed because a more recent
  292. * navigation finished started (not necessarily finished).
  293. */
  294. e[e.cancelled=8]="cancelled",
  295. /**
  296. * A duplicated navigation is a navigation that failed because it was
  297. * initiated while already being at the exact same location.
  298. */
  299. e[e.duplicated=16]="duplicated"}(ae||(ae={}));const le="[^/]+?",ie={sensitive:!1,strict:!1,start:!0,end:!0},ue=/[.+*?^${}()[\]/\\]/g;
  300. /**
  301. * Compares an array of numbers as used in PathParser.score and returns a
  302. * number. This function can be used to `sort` an array
  303. *
  304. * @param a - first array of numbers
  305. * @param b - second array of numbers
  306. * @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
  307. * should be sorted first
  308. */
  309. function fe(e,t){let n=0;for(;n<e.length&&n<t.length;){const r=t[n]-e[n];
  310. // only keep going if diff === 0
  311. if(r)return r;n++}
  312. // if the last subsegment was Static, the shorter segments should be sorted first
  313. // otherwise sort the longest segment first
  314. return e.length<t.length?1===e.length&&80/* PathScore.Segment */===e[0]?-1:1:e.length>t.length?1===t.length&&80/* PathScore.Segment */===t[0]?1:-1:0}
  315. /**
  316. * Compare function that can be used with `sort` to sort an array of PathParser
  317. *
  318. * @param a - first PathParser
  319. * @param b - second PathParser
  320. * @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
  321. */function pe(e,t){let n=0;const r=e.score,o=t.score;for(;n<r.length&&n<o.length;){const e=fe(r[n],o[n]);
  322. // do not return if both are equal
  323. if(e)return e;n++}if(1===Math.abs(o.length-r.length)){if(he(r))return 1;if(he(o))return-1}
  324. // if a and b share the same score entries but b has more, sort b first
  325. return o.length-r.length;
  326. // this is the ternary version
  327. // return aScore.length < bScore.length
  328. // ? 1
  329. // : aScore.length > bScore.length
  330. // ? -1
  331. // : 0
  332. }
  333. /**
  334. * This allows detecting splats at the end of a path: /home/:id(.*)*
  335. *
  336. * @param score - score to check
  337. * @returns true if the last entry is negative
  338. */function he(e){const t=e[e.length-1];return e.length>0&&t[t.length-1]<0}const de={type:0/* TokenType.Static */,value:""},me=/[a-zA-Z0-9_]/;function ge(e,t,n){const r=
  339. /**
  340. * Creates a path parser from an array of Segments (a segment is an array of Tokens)
  341. *
  342. * @param segments - array of segments returned by tokenizePath
  343. * @param extraOptions - optional options for the regexp
  344. * @returns a PathParser
  345. */
  346. function(e,t){const n=d({},ie,t),r=[];
  347. // the amount of scores is the same as the length of segments except for the root segment "/"
  348. // the regexp as a string
  349. let o=n.start?"^":"";
  350. // extracted keys
  351. const a=[];for(const l of e){
  352. // the root segment needs special treatment
  353. const e=l.length?[]:[90/* PathScore.Root */];
  354. // allow trailing slash
  355. n.strict&&!l.length&&(o+="/");for(let t=0;t<l.length;t++){const r=l[t];
  356. // resets the score if we are inside a sub-segment /:a-other-:b
  357. let s=40/* PathScore.Segment */+(n.sensitive?.25/* PathScore.BonusCaseSensitive */:0);if(0/* TokenType.Static */===r.type)
  358. // prepend the slash if we are starting a new segment
  359. t||(o+="/"),o+=r.value.replace(ue,"\\$&"),s+=40/* PathScore.Static */;else if(1/* TokenType.Param */===r.type){const{value:e,repeatable:n,optional:i,regexp:u}=r;a.push({name:e,repeatable:n,optional:i});const f=u||le;
  360. // the user provided a custom regexp /:id(\\d+)
  361. if(f!==le){s+=10/* PathScore.BonusCustomRegExp */;
  362. // make sure the regexp is valid before using it
  363. try{new RegExp(`(${f})`)}catch(c){throw new Error(`Invalid custom RegExp for param "${e}" (${f}): `+c.message)}}
  364. // when we repeat we must take care of the repeating leading slash
  365. let p=n?`((?:${f})(?:/(?:${f}))*)`:`(${f})`;
  366. // prepend the slash if we are starting a new segment
  367. t||(p=
  368. // avoid an optional / if there are more segments e.g. /:p?-static
  369. // or /:p?-:p2
  370. i&&l.length<2?`(?:/${p})`:"/"+p),i&&(p+="?"),o+=p,s+=20/* PathScore.Dynamic */,i&&(s+=-8/* PathScore.BonusOptional */),n&&(s+=-20/* PathScore.BonusRepeatable */),".*"===f&&(s+=-50/* PathScore.BonusWildcard */)}e.push(s)}
  371. // an empty array like /home/ -> [[{home}], []]
  372. // if (!segment.length) pattern += '/'
  373. r.push(e)}
  374. // only apply the strict bonus to the last score
  375. if(n.strict&&n.end){const e=r.length-1;r[e][r[e].length-1]+=.7000000000000001/* PathScore.BonusStrict */}
  376. // TODO: dev only warn double trailing slash
  377. n.strict||(o+="/?"),n.end?o+="$":n.strict&&!o.endsWith("/")&&(o+="(?:/|$)");const s=new RegExp(o,n.sensitive?"":"i");return{re:s,score:r,keys:a,parse:function(e){const t=e.match(s),n={};if(!t)return null;for(let r=1;r<t.length;r++){const e=t[r]||"",o=a[r-1];n[o.name]=e&&o.repeatable?e.split("/"):e}return n},stringify:function(t){let n="",r=!1;
  378. // for optional parameters to allow to be empty
  379. for(const o of e){r&&n.endsWith("/")||(n+="/"),r=!1;for(const e of o)if(0/* TokenType.Static */===e.type)n+=e.value;else if(1/* TokenType.Param */===e.type){const{value:a,repeatable:s,optional:c}=e,l=a in t?t[a]:"";if(v(l)&&!s)throw new Error(`Provided param "${a}" is an array but it is not repeatable (* or + modifiers)`);const i=v(l)?l.join("/"):l;if(!i){if(!c)throw new Error(`Missing required param "${a}"`);
  380. // if we have more than one optional param like /:a?-static we don't need to care about the optional param
  381. o.length<2&&(
  382. // remove the last slash as we could be at the end
  383. n.endsWith("/")?n=n.slice(0,-1):r=!0)}n+=i}}
  384. // avoid empty path when we have multiple optional params
  385. return n||"/"}}}(
  386. // After some profiling, the cache seems to be unnecessary because tokenizePath
  387. // (the slowest part of adding a route) is very fast
  388. // const tokenCache = new Map<string, Token[][]>()
  389. function(e){if(!e)return[[]];if("/"===e)return[[de]];if(!e.startsWith("/"))throw new Error(`Invalid path "${e}"`);
  390. // if (tokenCache.has(path)) return tokenCache.get(path)!
  391. function t(e){throw new Error(`ERR (${n})/"${i}": ${e}`)}let n=0/* TokenizerState.Static */,r=n;const o=[];
  392. // the segment will always be valid because we get into the initial state
  393. // with the leading /
  394. let a;function s(){a&&o.push(a),a=[]}
  395. // index on the path
  396. let c,l=0,i="",u="";
  397. // char at index
  398. function f(){i&&(0/* TokenizerState.Static */===n?a.push({type:0/* TokenType.Static */,value:i}):1/* TokenizerState.Param */===n||2/* TokenizerState.ParamRegExp */===n||3/* TokenizerState.ParamRegExpEnd */===n?(a.length>1&&("*"===c||"+"===c)&&t(`A repeatable param (${i}) must be alone in its segment. eg: '/:ids+.`),a.push({type:1/* TokenType.Param */,value:i,regexp:u,repeatable:"*"===c||"+"===c,optional:"*"===c||"?"===c})):t("Invalid state to consume buffer"),i="")}function p(){i+=c}for(;l<e.length;)if(c=e[l++],"\\"!==c||2/* TokenizerState.ParamRegExp */===n)switch(n){case 0/* TokenizerState.Static */:"/"===c?(i&&f(),s()):":"===c?(f(),n=1/* TokenizerState.Param */):p();break;case 4/* TokenizerState.EscapeNext */:p(),n=r;break;case 1/* TokenizerState.Param */:"("===c?n=2/* TokenizerState.ParamRegExp */:me.test(c)?p():(f(),n=0/* TokenizerState.Static */,
  399. // go back one character if we were not modifying
  400. "*"!==c&&"?"!==c&&"+"!==c&&l--);break;case 2/* TokenizerState.ParamRegExp */:
  401. // TODO: is it worth handling nested regexp? like :p(?:prefix_([^/]+)_suffix)
  402. // it already works by escaping the closing )
  403. // https://paths.esm.dev/?p=AAMeJbiAwQEcDKbAoAAkP60PG2R6QAvgNaA6AFACM2ABuQBB#
  404. // is this really something people need since you can also write
  405. // /prefix_:p()_suffix
  406. ")"===c?
  407. // handle the escaped )
  408. "\\"==u[u.length-1]?u=u.slice(0,-1)+c:n=3/* TokenizerState.ParamRegExpEnd */:u+=c;break;case 3/* TokenizerState.ParamRegExpEnd */:
  409. // same as finalizing a param
  410. f(),n=0/* TokenizerState.Static */,
  411. // go back one character if we were not modifying
  412. "*"!==c&&"?"!==c&&"+"!==c&&l--,u="";break;default:t("Unknown state")}else r=n,n=4/* TokenizerState.EscapeNext */;
  413. // tokenCache.set(path, tokens)
  414. return 2/* TokenizerState.ParamRegExp */===n&&t(`Unfinished custom RegExp for param "${i}"`),f(),s(),o}(e.path),n),o=d(r,{record:e,parent:t,
  415. // these needs to be populated by the parent
  416. children:[],alias:[]});return t&&!o.record.aliasOf==!t.record.aliasOf&&t.children.push(o),o}
  417. /**
  418. * Creates a Router Matcher.
  419. *
  420. * @internal
  421. * @param routes - array of initial routes
  422. * @param globalOptions - global route options
  423. */function ve(e,t){
  424. // normalized ordered array of matchers
  425. const n=[],r=new Map;function o(e,n,r){
  426. // used later on to remove by name
  427. const c=!r,l=be(e);
  428. // we might be the child of an alias
  429. l.aliasOf=r&&r.record;const i=ke(t,e),u=[l];
  430. // generate an array of records to correctly handle aliases
  431. if("alias"in e){const t="string"==typeof e.alias?[e.alias]:e.alias;for(const e of t)u.push(
  432. // we need to normalize again to ensure the `mods` property
  433. // being non enumerable
  434. be(d({},l,{
  435. // this allows us to hold a copy of the `components` option
  436. // so that async components cache is hold on the original record
  437. components:r?r.record.components:l.components,path:e,
  438. // we might be the child of an alias
  439. aliasOf:r?r.record:l})))}let f,p;for(const t of u){const{path:u}=t;
  440. // Build up the path for nested routes if the child isn't an absolute
  441. // route. Only add the / delimiter if the child path isn't empty and if the
  442. // parent path doesn't have a trailing slash
  443. if(n&&"/"!==u[0]){const e=n.record.path,r="/"===e[e.length-1]?"":"/";t.path=n.record.path+(u&&r+u)}
  444. // create the object beforehand, so it can be passed to children
  445. if(f=ge(t,n,i),
  446. // if we are an alias we must tell the original record that we exist,
  447. // so we can be removed
  448. r?r.alias.push(f):(
  449. // otherwise, the first record is the original and others are aliases
  450. p=p||f,p!==f&&p.alias.push(f),
  451. // remove the route if named and only for the top record (avoid in nested calls)
  452. // this works because the original record is the first one
  453. c&&e.name&&!Ee(f)&&a(e.name)),
  454. // Avoid adding a record that doesn't display anything. This allows passing through records without a component to
  455. // not be reached and pass through the catch all route
  456. Oe(f)&&s(f),l.children){const e=l.children;for(let t=0;t<e.length;t++)o(e[t],f,r&&r.children[t])}
  457. // if there was no original record, then the first one was not an alias and all
  458. // other aliases (if any) need to reference this record when adding children
  459. r=r||f}return p?()=>{
  460. // since other matchers are aliases, they should be removed by the original matcher
  461. a(p)}:g}function a(e){if(re(e)){const t=r.get(e);t&&(r.delete(e),n.splice(n.indexOf(t),1),t.children.forEach(a),t.alias.forEach(a))}else{const t=n.indexOf(e);t>-1&&(n.splice(t,1),e.record.name&&r.delete(e.record.name),e.children.forEach(a),e.alias.forEach(a))}}function s(e){const t=
  462. /**
  463. * Performs a binary search to find the correct insertion index for a new matcher.
  464. *
  465. * Matchers are primarily sorted by their score. If scores are tied then we also consider parent/child relationships,
  466. * with descendants coming before ancestors. If there's still a tie, new routes are inserted after existing routes.
  467. *
  468. * @param matcher - new matcher to be inserted
  469. * @param matchers - existing matchers
  470. */
  471. function(e,t){
  472. // First phase: binary search based on score
  473. let n=0,r=t.length;for(;n!==r;){const o=n+r>>1;pe(e,t[o])<0?r=o:n=o+1}
  474. // Second phase: check for an ancestor with the same score
  475. const o=function(e){let t=e;for(;t=t.parent;)if(Oe(t)&&0===pe(e,t))return t;return}
  476. /**
  477. * Checks if a matcher can be reachable. This means if it's possible to reach it as a route. For example, routes without
  478. * a component, or name, or redirect, are just used to group other routes.
  479. * @param matcher
  480. * @param matcher.record record of the matcher
  481. * @returns
  482. */(e);o&&(r=t.lastIndexOf(o,r-1));return r}(e,n);n.splice(t,0,e),
  483. // only add the original record to the name map
  484. e.record.name&&!Ee(e)&&r.set(e.record.name,e)}return t=ke({strict:!1,end:!0,sensitive:!1},t),
  485. // add initial routes
  486. e.forEach((e=>o(e))),{addRoute:o,resolve:function(e,t){let o,a,s,c={};if("name"in e&&e.name){if(o=r.get(e.name),!o)throw se(1/* ErrorTypes.MATCHER_NOT_FOUND */,{location:e});s=o.record.name,c=d(
  487. // paramsFromLocation is a new object
  488. ye(t.params,
  489. // only keep params that exist in the resolved location
  490. // only keep optional params coming from a parent record
  491. o.keys.filter((e=>!e.optional)).concat(o.parent?o.parent.keys.filter((e=>e.optional)):[]).map((e=>e.name))),
  492. // discard any existing params in the current location that do not exist here
  493. // #1497 this ensures better active/exact matching
  494. e.params&&ye(e.params,o.keys.map((e=>e.name)))),
  495. // throws if cannot be stringified
  496. a=o.stringify(c)}else if(null!=e.path)
  497. // no need to resolve the path with the matcher as it was provided
  498. // this also allows the user to control the encoding
  499. a=e.path,o=n.find((e=>e.re.test(a))),
  500. // matcher should have a value after the loop
  501. o&&(
  502. // we know the matcher works because we tested the regexp
  503. c=o.parse(a),s=o.record.name);else{if(
  504. // match by name or path of current route
  505. o=t.name?r.get(t.name):n.find((e=>e.re.test(t.path))),!o)throw se(1/* ErrorTypes.MATCHER_NOT_FOUND */,{location:e,currentLocation:t});s=o.record.name,
  506. // since we are navigating to the same location, we don't need to pick the
  507. // params like when `name` is provided
  508. c=d({},t.params,e.params),a=o.stringify(c)}const l=[];let i=o;for(;i;)
  509. // reversed order so parents are at the beginning
  510. l.unshift(i.record),i=i.parent;return{name:s,path:a,params:c,matched:l,meta:Re(l)}},removeRoute:a,clearRoutes:function(){n.length=0,r.clear()},getRoutes:function(){return n},getRecordMatcher:function(e){return r.get(e)}}}function ye(e,t){const n={};for(const r of t)r in e&&(n[r]=e[r]);return n}
  511. /**
  512. * Normalizes a RouteRecordRaw. Creates a copy
  513. *
  514. * @param record
  515. * @returns the normalized version
  516. */function be(e){const t={path:e.path,redirect:e.redirect,name:e.name,meta:e.meta||{},aliasOf:e.aliasOf,beforeEnter:e.beforeEnter,props:we(e),children:e.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},
  517. // must be declared afterwards
  518. // mods: {},
  519. components:"components"in e?e.components||null:e.component&&{default:e.component}};
  520. // mods contain modules and shouldn't be copied,
  521. // logged or anything. It's just used for internal
  522. // advanced use cases like data loaders
  523. return Object.defineProperty(t,"mods",{value:{}}),t}
  524. /**
  525. * Normalize the optional `props` in a record to always be an object similar to
  526. * components. Also accept a boolean for components.
  527. * @param record
  528. */function we(e){const t={},n=e.props||!1;
  529. // props does not exist on redirect records, but we can set false directly
  530. if("component"in e)t.default=n;else
  531. // NOTE: we could also allow a function to be applied to every component.
  532. // Would need user feedback for use cases
  533. for(const r in e.components)t[r]="object"==typeof n?n[r]:n;return t}
  534. /**
  535. * Checks if a record or any of its parent is an alias
  536. * @param record
  537. */function Ee(e){for(;e;){if(e.record.aliasOf)return!0;e=e.parent}return!1}
  538. /**
  539. * Merge meta fields of an array of records
  540. *
  541. * @param matched - array of matched records
  542. */function Re(e){return e.reduce(((e,t)=>d(e,t.meta)),{})}function ke(e,t){const n={};for(const r in e)n[r]=r in t?t[r]:e[r];return n}function Oe({record:e}){return!!(e.name||e.components&&Object.keys(e.components).length||e.redirect)}
  543. /**
  544. * Transforms a queryString into a {@link LocationQuery} object. Accept both, a
  545. * version with the leading `?` and without Should work as URLSearchParams
  546. * @internal
  547. *
  548. * @param search - search string to parse
  549. * @returns a query object
  550. */function xe(e){const t={};
  551. // avoid creating an object with an empty key and empty value
  552. // because of split('&')
  553. if(""===e||"?"===e)return t;const n=("?"===e[0]?e.slice(1):e).split("&");for(let r=0;r<n.length;++r){
  554. // pre decode the + into space
  555. const e=n[r].replace(k," "),o=e.indexOf("="),a=B(o<0?e:e.slice(0,o)),s=o<0?null:B(e.slice(o+1));
  556. // allow the = character
  557. if(a in t){
  558. // an extra variable for ts types
  559. let e=t[a];v(e)||(e=t[a]=[e]),e.push(s)}else t[a]=s}return t}
  560. /**
  561. * Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
  562. * doesn't prepend a `?`
  563. *
  564. * @internal
  565. *
  566. * @param query - query object to stringify
  567. * @returns string version of the query without the leading `?`
  568. */function Pe(e){let t="";for(let n in e){const r=e[n];if(n=L(n).replace(E,"%3D"),null==r){
  569. // only null adds the value
  570. void 0!==r&&(t+=(t.length?"&":"")+n);continue}
  571. // keep null values
  572. (v(r)?r.map((e=>e&&L(e))):[r&&L(r)]).forEach((e=>{
  573. // skip undefined values in arrays as if they were not present
  574. // smaller code than using filter
  575. void 0!==e&&(
  576. // only append & with non-empty search
  577. t+=(t.length?"&":"")+n,null!=e&&(t+="="+e))}))}return t}
  578. /**
  579. * Transforms a {@link LocationQueryRaw} into a {@link LocationQuery} by casting
  580. * numbers into strings, removing keys with an undefined value and replacing
  581. * undefined with null in arrays
  582. *
  583. * @param query - query object to normalize
  584. * @returns a normalized query object
  585. */function Ce(e){const t={};for(const n in e){const r=e[n];void 0!==r&&(t[n]=v(r)?r.map((e=>null==e?null:""+e)):null==r?r:""+r)}return t}
  586. /**
  587. * RouteRecord being rendered by the closest ancestor Router View. Used for
  588. * `onBeforeRouteUpdate` and `onBeforeRouteLeave`. rvlm stands for Router View
  589. * Location Matched
  590. *
  591. * @internal
  592. */const je=Symbol(""),$e=Symbol(""),Se=Symbol(""),Ae=Symbol(""),qe=Symbol("");
  593. /**
  594. * Allows overriding the router view depth to control which component in
  595. * `matched` is rendered. rvd stands for Router View Depth
  596. *
  597. * @internal
  598. */
  599. /**
  600. * Create a list of callbacks that can be reset. Used to create before and after navigation guards list
  601. */
  602. function Le(){let e=[];return{add:function(t){return e.push(t),()=>{const n=e.indexOf(t);n>-1&&e.splice(n,1)}},list:()=>e.slice(),reset:function(){e=[]}}}function Me(e,t,n,r,o,a=e=>e()){
  603. // keep a reference to the enterCallbackArray to prevent pushing callbacks if a new navigation took place
  604. const s=r&&(
  605. // name is defined if record is because of the function overload
  606. r.enterCallbacks[o]=r.enterCallbacks[o]||[]);return()=>new Promise(((c,l)=>{const i=e=>{var a;!1===e?l(se(4/* ErrorTypes.NAVIGATION_ABORTED */,{from:n,to:t})):e instanceof Error?l(e):"string"==typeof(a=e)||a&&"object"==typeof a?l(se(2/* ErrorTypes.NAVIGATION_GUARD_REDIRECT */,{from:t,to:e})):(s&&
  607. // since enterCallbackArray is truthy, both record and name also are
  608. r.enterCallbacks[o]===s&&"function"==typeof e&&s.push(e),c())},u=a((()=>e.call(r&&r.instances[o],t,n,i)));
  609. // wrapping with Promise.resolve allows it to work with both async and sync guards
  610. let f=Promise.resolve(u);e.length<3&&(f=f.then(i)),f.catch((e=>l(e)))}))}function Be(e,t,n,r,o=e=>e()){const a=[];for(const s of e)for(const e in s.components){let c=s.components[e];
  611. // skip update and leave guards if the route component is not mounted
  612. if("beforeRouteEnter"===t||s.instances[e])if(h(c)){
  613. // __vccOpts is added by vue-class-component and contain the regular options
  614. const l=(c.__vccOpts||c)[t];l&&a.push(Me(l,n,r,s,e,o))}else{
  615. // start requesting the chunk already
  616. let l=c();a.push((()=>l.then((a=>{if(!a)throw new Error(`Couldn't resolve component "${e}" at "${s.path}"`);const c=(l=a).__esModule||"Module"===l[Symbol.toStringTag]||
  617. // support CF with dynamic imports that do not
  618. // add the Module string tag
  619. l.default&&h(l.default)?a.default:a;
  620. // keep the resolved module for plugins like data loaders
  621. var l;s.mods[e]=a,
  622. // replace the function with the resolved component
  623. // cannot be null or undefined because we went into the for loop
  624. s.components[e]=c;
  625. // __vccOpts is added by vue-class-component and contain the regular options
  626. const i=(c.__vccOpts||c)[t];return i&&Me(i,n,r,s,e,o)()}))))}}return a}
  627. // TODO: we could allow currentRoute as a prop to expose `isActive` and
  628. // `isExactActive` behavior should go through an RFC
  629. /**
  630. * Returns the internal behavior of a {@link RouterLink} without the rendering part.
  631. *
  632. * @param props - a `to` location and an optional `replace` flag
  633. */function Ge(e){const n=o(Se),r=o(Ae),a=c((()=>{const r=t(e.to);return n.resolve(r)})),s=c((()=>{const{matched:e}=a.value,{length:t}=e,n=e[t-1],o=r.matched;if(!n||!o.length)return-1;const s=o.findIndex(T.bind(null,n));if(s>-1)return s;
  634. // possible parent record
  635. const c=Ie(e[t-2]);
  636. // we are dealing with nested routes
  637. return t>1&&
  638. // if the parent and matched route have the same path, this link is
  639. // referring to the empty child. Or we currently are on a different
  640. // child of the same parent
  641. Ie(n)===c&&
  642. // avoid comparing the child with its parent
  643. o[o.length-1].path!==c?o.findIndex(T.bind(null,e[t-2])):s})),l=c((()=>s.value>-1&&function(e,t){for(const n in t){const r=t[n],o=e[n];if("string"==typeof r){if(r!==o)return!1}else if(!v(o)||o.length!==r.length||r.some(((e,t)=>e!==o[t])))return!1}return!0}
  644. /**
  645. * Get the original path value of a record by following its aliasOf
  646. * @param record
  647. */(r.params,a.value.params))),i=c((()=>s.value>-1&&s.value===r.matched.length-1&&W(r.params,a.value.params)));
  648. /**
  649. * NOTE: update {@link _RouterLinkI}'s `$slots` type when updating this
  650. */
  651. return{route:a,href:c((()=>a.value.href)),isActive:l,isExactActive:i,navigate:function(r={}){if(function(e){
  652. // don't redirect with control keys
  653. if(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)return;
  654. // don't redirect when preventDefault called
  655. if(e.defaultPrevented)return;
  656. // don't redirect on right click
  657. if(void 0!==e.button&&0!==e.button)return;
  658. // don't redirect if `target="_blank"`
  659. // @ts-expect-error getAttribute does exist
  660. if(e.currentTarget&&e.currentTarget.getAttribute){
  661. // @ts-expect-error getAttribute exists
  662. const t=e.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(t))return}
  663. // this may be a Weex event which doesn't have this method
  664. e.preventDefault&&e.preventDefault();return!0}(r)){const r=n[t(e.replace)?"replace":"push"](t(e.to)).catch(g);return e.viewTransition&&"undefined"!=typeof document&&"startViewTransition"in document&&document.startViewTransition((()=>r)),r}return Promise.resolve()}}}const _e=a({name:"RouterLink",compatConfig:{MODE:3},props:{to:{type:[String,Object],required:!0},replace:Boolean,activeClass:String,
  665. // inactiveClass: String,
  666. exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},useLink:Ge,setup(e,{slots:t}){const n=s(Ge(e)),{options:r}=o(Se),a=c((()=>({[Te(e.activeClass,r.linkActiveClass,"router-link-active")]:n.isActive,
  667. // [getLinkClass(
  668. // props.inactiveClass,
  669. // options.linkInactiveClass,
  670. // 'router-link-inactive'
  671. // )]: !link.isExactActive,
  672. [Te(e.exactActiveClass,r.linkExactActiveClass,"router-link-exact-active")]:n.isExactActive})));return()=>{const r=t.default&&(1===(o=t.default(n)).length?o[0]:o);var o;return e.custom?r:l("a",{"aria-current":n.isExactActive?e.ariaCurrentValue:null,href:n.href,
  673. // this would override user added attrs but Vue will still add
  674. // the listener, so we end up triggering both
  675. onClick:n.navigate,class:a.value},r)}}});
  676. // export the public type for h/tsx inference
  677. // also to avoid inline import() in generated d.ts files
  678. /**
  679. * Component to render a link that triggers a navigation on click.
  680. */function Ie(e){return e?e.aliasOf?e.aliasOf.path:e.path:""}
  681. /**
  682. * Utility class to get the active class based on defaults.
  683. * @param propClass
  684. * @param globalClass
  685. * @param defaultClass
  686. */const Te=(e,t,n)=>null!=e?e:null!=t?t:n;function We(e,t){if(!e)return null;const n=e(t);return 1===n.length?n[0]:n}
  687. // export the public type for h/tsx inference
  688. // also to avoid inline import() in generated d.ts files
  689. /**
  690. * Component to display the current route the user is at.
  691. */const De=a({name:"RouterView",
  692. // #674 we manually inherit them
  693. inheritAttrs:!1,props:{name:{type:String,default:"default"},route:Object},
  694. // Better compat for @vue/compat users
  695. // https://github.com/vuejs/router/issues/1315
  696. compatConfig:{MODE:3},setup(e,{attrs:n,slots:r}){const a=o(qe),s=c((()=>e.route||a.value)),p=o($e,0),h=c((()=>{let e=t(p);const{matched:n}=s.value;let r;for(;(r=n[e])&&!r.components;)e++;return e})),m=c((()=>s.value.matched[h.value]));i($e,c((()=>h.value+1))),i(je,m),i(qe,s);const g=u();
  697. // watch at the same time the component instance, the route record we are
  698. // rendering, and the name
  699. return f((()=>[g.value,m.value,e.name]),(([e,t,n],[r,o,a])=>{
  700. // copy reused instances
  701. t&&(
  702. // this will update the instance for new instances as well as reused
  703. // instances when navigating to a new route
  704. t.instances[n]=e,
  705. // the component instance is reused for a different route or name, so
  706. // we copy any saved update or leave guards. With async setup, the
  707. // mounting component will mount before the matchedRoute changes,
  708. // making instance === oldInstance, so we check if guards have been
  709. // added before. This works because we remove guards when
  710. // unmounting/deactivating components
  711. o&&o!==t&&e&&e===r&&(t.leaveGuards.size||(t.leaveGuards=o.leaveGuards),t.updateGuards.size||(t.updateGuards=o.updateGuards))),
  712. // trigger beforeRouteEnter next callbacks
  713. !e||!t||
  714. // if there is no instance but to and from are the same this might be
  715. // the first visit
  716. o&&T(t,o)&&r||(t.enterCallbacks[n]||[]).forEach((t=>t(e)))}),{flush:"post"}),()=>{const t=s.value,o=e.name,a=m.value,c=a&&a.components[o];
  717. // we need the value at the time we render because when we unmount, we
  718. // navigated to a different location so the value is different
  719. if(!c)return We(r.default,{Component:c,route:t});
  720. // props from route configuration
  721. const i=a.props[o],u=i?!0===i?t.params:"function"==typeof i?i(t):i:null,f=l(c,d({},u,n,{onVnodeUnmounted:e=>{
  722. // remove the instance reference to prevent leak
  723. e.component.isUnmounted&&(a.instances[o]=null)},ref:g}));
  724. // pass the vnode to the slot as a prop.
  725. // h and <component :is="..."> both accept vnodes
  726. return We(r.default,{Component:f,route:t})||f}}});
  727. /**
  728. * Creates a Router instance that can be used by a Vue app.
  729. *
  730. * @param options - {@link RouterOptions}
  731. */function Ue(o){const a=ve(o.routes,o),s=o.parseQuery||xe,c=o.stringifyQuery||Pe,l=o.history,i=Le(),u=Le(),f=Le(),h=e(V);let y=V;
  732. // leave the scrollRestoration if no scrollBehavior is provided
  733. p&&o.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const b=m.bind(null,(e=>""+e)),w=m.bind(null,M),E=
  734. // @ts-expect-error: intentionally avoid the type check
  735. m.bind(null,B);function R(e,t){if(
  736. // const resolve: Router['resolve'] = (rawLocation: RouteLocationRaw, currentLocation) => {
  737. // const objectLocation = routerLocationAsObject(rawLocation)
  738. // we create a copy to modify it later
  739. t=d({},t||h.value),"string"==typeof e){const n=_(s,e,t.path),r=a.resolve({path:n.path},t),o=l.createHref(n.fullPath);
  740. // locationNormalized is always a new object
  741. return d(n,r,{params:E(r.params),hash:B(n.hash),redirectedFrom:void 0,href:o})}let n;
  742. // path could be relative in object as well
  743. if(null!=e.path)n=d({},e,{path:_(s,e.path,t.path).path});else{
  744. // remove any nullish param
  745. const r=d({},e.params);for(const e in r)null==r[e]&&delete r[e];
  746. // pass encoded values to the matcher, so it can produce encoded path and fullPath
  747. n=d({},e,{params:w(r)}),
  748. // current location params are decoded, we need to encode them in case the
  749. // matcher merges the params
  750. t.params=w(t.params)}const r=a.resolve(n,t),o=e.hash||"";
  751. // the matcher might have merged current location params, so
  752. // we need to run the decoding again
  753. r.params=b(E(r.params));const i=function(e,t){const n=t.query?e(t.query):"";return t.path+(n&&"?")+n+(t.hash||"")}(c,d({},e,{hash:(u=o,q(u).replace(j,"{").replace(S,"}").replace(P,"^")),path:r.path}));var u;const f=l.createHref(i);return d({fullPath:i,
  754. // keep the hash encoded so fullPath is effectively path + encodedQuery +
  755. // hash
  756. hash:o,query:
  757. // if the user is using a custom query lib like qs, we might have
  758. // nested objects, so we keep the query as is, meaning it can contain
  759. // numbers at `$route.query`, but at the point, the user will have to
  760. // use their own type anyway.
  761. // https://github.com/vuejs/router/issues/328#issuecomment-649481567
  762. c===Pe?Ce(e.query):e.query||{}},r,{redirectedFrom:void 0,href:f})}function k(e){return"string"==typeof e?_(s,e,h.value.path):d({},e)}function O(e,t){if(y!==e)return se(8/* ErrorTypes.NAVIGATION_CANCELLED */,{from:t,to:e})}function x(e){return $(e)}function C(e){const t=e.matched[e.matched.length-1];if(t&&t.redirect){const{redirect:n}=t;let r="function"==typeof n?n(e):n;return"string"==typeof r&&(r=r.includes("?")||r.includes("#")?r=k(r):// force empty params
  763. {path:r},
  764. // @ts-expect-error: force empty params when a string is passed to let
  765. // the router parse them again
  766. r.params={}),d({query:e.query,hash:e.hash,
  767. // avoid transferring params if the redirect has a path
  768. params:null!=r.path?{}:e.params},r)}}function $(e,t){const n=y=R(e),r=h.value,o=e.state,a=e.force,s=!0===e.replace,l=C(n);if(l)return $(d(k(l),{state:"object"==typeof l?d({},o,l.state):o,force:a,replace:s}),
  769. // keep original redirectedFrom if it exists
  770. t||n);
  771. // if it was a redirect we already called `pushWithRedirect` above
  772. const i=n;let u;return i.redirectedFrom=t,!a&&function(e,t,n){const r=t.matched.length-1,o=n.matched.length-1;return r>-1&&r===o&&T(t.matched[r],n.matched[o])&&W(t.params,n.params)&&e(t.query)===e(n.query)&&t.hash===n.hash}(c,r,n)&&(u=se(16/* ErrorTypes.NAVIGATION_DUPLICATED */,{to:i,from:r}),
  773. // trigger scroll to allow scrolling to the same anchor
  774. te(r,r,
  775. // this is a push, the only way for it to be triggered from a
  776. // history.listen is with a redirect, which makes it become a push
  777. !0,
  778. // This cannot be the first navigation because the initial location
  779. // cannot be manually navigated to
  780. !1)),(u?Promise.resolve(u):G(i,r)).catch((e=>ce(e)?// navigation redirects still mark the router as ready
  781. ce(e,2/* ErrorTypes.NAVIGATION_GUARD_REDIRECT */)?e:ee(e):// reject any unknown error
  782. J(e,i,r))).then((e=>{if(e){if(ce(e,2/* ErrorTypes.NAVIGATION_GUARD_REDIRECT */))return $(
  783. // keep options
  784. d({
  785. // preserve an existing replacement but allow the redirect to override it
  786. replace:s},k(e.to),{state:"object"==typeof e.to?d({},o,e.to.state):o,force:a}),
  787. // preserve the original redirectedFrom if any
  788. t||i)}else
  789. // if we fail we don't finalize the navigation
  790. e=D(i,r,!0,s,o);return I(i,r,e),e}))}
  791. /**
  792. * Helper to reject and skip all navigation guards if a new navigation happened
  793. * @param to
  794. * @param from
  795. */function A(e,t){const n=O(e,t);return n?Promise.reject(n):Promise.resolve()}function L(e){const t=ae.values().next().value;
  796. // support Vue < 3.3
  797. return t&&"function"==typeof t.runWithContext?t.runWithContext(e):e()}
  798. // TODO: refactor the whole before guards by internally using router.beforeEach
  799. function G(e,t){let n;const[r,o,a]=function(e,t){const n=[],r=[],o=[],a=Math.max(t.matched.length,e.matched.length);for(let s=0;s<a;s++){const a=t.matched[s];a&&(e.matched.find((e=>T(e,a)))?r.push(a):n.push(a));const c=e.matched[s];c&&(
  800. // the type doesn't matter because we are comparing per reference
  801. t.matched.find((e=>T(e,c)))||o.push(c))}return[n,r,o]}
  802. /**
  803. * Returns the router instance. Equivalent to using `$router` inside
  804. * templates.
  805. */(e,t);
  806. // all components here have been resolved once because we are leaving
  807. n=Be(r.reverse(),"beforeRouteLeave",e,t);
  808. // leavingRecords is already reversed
  809. for(const c of r)c.leaveGuards.forEach((r=>{n.push(Me(r,e,t))}));const s=A.bind(null,e,t);
  810. // run the queue of per route beforeRouteLeave guards
  811. return n.push(s),ie(n).then((()=>{
  812. // check global guards beforeEach
  813. n=[];for(const r of i.list())n.push(Me(r,e,t));return n.push(s),ie(n)})).then((()=>{
  814. // check in components beforeRouteUpdate
  815. n=Be(o,"beforeRouteUpdate",e,t);for(const r of o)r.updateGuards.forEach((r=>{n.push(Me(r,e,t))}));
  816. // run the queue of per route beforeEnter guards
  817. return n.push(s),ie(n)})).then((()=>{
  818. // check the route beforeEnter
  819. n=[];for(const r of a)
  820. // do not trigger beforeEnter on reused views
  821. if(r.beforeEnter)if(v(r.beforeEnter))for(const o of r.beforeEnter)n.push(Me(o,e,t));else n.push(Me(r.beforeEnter,e,t));
  822. // run the queue of per route beforeEnter guards
  823. return n.push(s),ie(n)})).then((()=>(
  824. // NOTE: at this point to.matched is normalized and does not contain any () => Promise<Component>
  825. // clear existing enterCallbacks, these are added by extractComponentsGuards
  826. e.matched.forEach((e=>e.enterCallbacks={})),
  827. // check in-component beforeRouteEnter
  828. n=Be(a,"beforeRouteEnter",e,t,L),n.push(s),ie(n)))).then((()=>{
  829. // check global guards beforeResolve
  830. n=[];for(const r of u.list())n.push(Me(r,e,t));return n.push(s),ie(n)})).catch((e=>ce(e,8/* ErrorTypes.NAVIGATION_CANCELLED */)?e:Promise.reject(e)))}function I(e,t,n){
  831. // navigation is confirmed, call afterGuards
  832. // TODO: wrap with error handlers
  833. f.list().forEach((r=>L((()=>r(e,t,n)))))}
  834. /**
  835. * - Cleans up any navigation guards
  836. * - Changes the url if necessary
  837. * - Calls the scrollBehavior
  838. */function D(e,t,n,r,o){
  839. // a more recent navigation took place
  840. const a=O(e,t);if(a)return a;
  841. // only consider as push if it's not the first navigation
  842. const s=t===V,c=p?history.state:{};
  843. // change URL only if the user did a push/replace and if it's not the initial navigation because
  844. // it's just reflecting the url
  845. n&&(
  846. // on the initial navigation, we want to reuse the scroll position from
  847. // history state if it exists
  848. r||s?l.replace(e.fullPath,d({scroll:s&&c&&c.scroll},o)):l.push(e.fullPath,o)),
  849. // accept current navigation
  850. h.value=e,te(e,t,n,s),ee()}let U;
  851. // attach listener to history to trigger navigations
  852. function z(){
  853. // avoid setting up listeners twice due to an invalid first navigation
  854. U||(U=l.listen(((e,t,n)=>{if(!le.listening)return;
  855. // cannot be a redirect route because it was in history
  856. const r=R(e),o=C(r);
  857. // due to dynamic routing, and to hash history with manual navigation
  858. // (manually changing the url or calling history.hash = '#/somewhere'),
  859. // there could be a redirect record in history
  860. if(o)return void $(d(o,{replace:!0,force:!0}),r).catch(g);y=r;const a=h.value;
  861. // TODO: should be moved to web history?
  862. var s,c;p&&(s=N(a.fullPath,n.delta),c=Q(),Z.set(s,c)),G(r,a).catch((e=>ce(e,12/* ErrorTypes.NAVIGATION_CANCELLED */)?e:ce(e,2/* ErrorTypes.NAVIGATION_GUARD_REDIRECT */)?(
  863. // Here we could call if (info.delta) routerHistory.go(-info.delta,
  864. // false) but this is bug prone as we have no way to wait the
  865. // navigation to be finished before calling pushWithRedirect. Using
  866. // a setTimeout of 16ms seems to work but there is no guarantee for
  867. // it to work on every browser. So instead we do not restore the
  868. // history entry and trigger a new navigation as requested by the
  869. // navigation guard.
  870. // the error is already handled by router.push we just want to avoid
  871. // logging the error
  872. $(d(k(e.to),{force:!0}),r).then((e=>{
  873. // manual change in hash history #916 ending up in the URL not
  874. // changing, but it was changed by the manual url change, so we
  875. // need to manually change it ourselves
  876. ce(e,20/* ErrorTypes.NAVIGATION_DUPLICATED */)&&!n.delta&&n.type===F.pop&&l.go(-1,!1)})).catch(g),Promise.reject()):(
  877. // do not restore history on unknown direction
  878. n.delta&&l.go(-n.delta,!1),J(e,r,a)))).then((e=>{
  879. // revert the navigation
  880. (e=e||D(
  881. // after navigation, all matched components are resolved
  882. r,a,!1))&&(n.delta&&
  883. // a new navigation has been triggered, so we do not want to revert, that will change the current history
  884. // entry while a different route is displayed
  885. !ce(e,8/* ErrorTypes.NAVIGATION_CANCELLED */)?l.go(-n.delta,!1):n.type===F.pop&&ce(e,20/* ErrorTypes.NAVIGATION_DUPLICATED */)&&
  886. // manual change in hash history #916
  887. // it's like a push but lacks the information of the direction
  888. l.go(-1,!1)),I(r,a,e)})).catch(g)})))}
  889. // Initialization and Errors
  890. let K,H=Le(),X=Le();
  891. /**
  892. * Trigger errorListeners added via onError and throws the error as well
  893. *
  894. * @param error - error to throw
  895. * @param to - location we were navigating to when the error happened
  896. * @param from - location we were navigating from when the error happened
  897. * @returns the error as a rejected promise
  898. */
  899. function J(e,t,n){ee(e);const r=X.list();
  900. // reject the error no matter there were error listeners or not
  901. return r.length&&r.forEach((r=>r(e,t,n))),Promise.reject(e)}function ee(e){return K||(
  902. // still not ready if an error happened
  903. K=!e,z(),H.list().forEach((([t,n])=>e?n(e):t())),H.reset()),e}
  904. // Scroll behavior
  905. function te(e,t,n,a){const{scrollBehavior:s}=o;if(!p||!s)return Promise.resolve();const c=!n&&function(e){const t=Z.get(e);
  906. // consume it so it's not used again
  907. return Z.delete(e),t}(N(e.fullPath,0))||(a||!n)&&history.state&&history.state.scroll||null;return r().then((()=>s(e,t,c))).then((e=>e&&Y(e))).catch((n=>J(n,e,t)))}const ne=e=>l.go(e);let oe;const ae=new Set,le={currentRoute:h,listening:!0,addRoute:function(e,t){let n,r;return re(e)?(n=a.getRecordMatcher(e),r=t):r=e,a.addRoute(r,n)},removeRoute:function(e){const t=a.getRecordMatcher(e);t&&a.removeRoute(t)},clearRoutes:a.clearRoutes,hasRoute:function(e){return!!a.getRecordMatcher(e)},getRoutes:function(){return a.getRoutes().map((e=>e.record))},resolve:R,options:o,push:x,replace:function(e){return x(d(k(e),{replace:!0}))},go:ne,back:()=>ne(-1),forward:()=>ne(1),beforeEach:i.add,beforeResolve:u.add,afterEach:f.add,onError:X.add,isReady:function(){return K&&h.value!==V?Promise.resolve():new Promise(((e,t)=>{H.add([e,t])}))},install(e){e.component("RouterLink",_e),e.component("RouterView",De),e.config.globalProperties.$router=this,Object.defineProperty(e.config.globalProperties,"$route",{enumerable:!0,get:()=>t(h)}),
  908. // this initial navigation is only necessary on client, on server it doesn't
  909. // make sense because it will create an extra unnecessary navigation and could
  910. // lead to problems
  911. p&&
  912. // used for the initial navigation client side to avoid pushing
  913. // multiple times when the router is used in multiple apps
  914. !oe&&h.value===V&&(
  915. // see above
  916. oe=!0,x(l.location).catch((e=>{})));const r={};for(const t in V)Object.defineProperty(r,t,{get:()=>h.value[t],enumerable:!0});e.provide(Se,this),e.provide(Ae,n(r)),e.provide(qe,h);const o=e.unmount;ae.add(e),e.unmount=function(){ae.delete(e),
  917. // the router is not attached to an app anymore
  918. ae.size<1&&(
  919. // invalidate the current navigation
  920. y=V,U&&U(),U=null,h.value=V,oe=!1,K=!1),o()}}};
  921. // TODO: type this as NavigationGuardReturn or similar instead of any
  922. function ie(e){return e.reduce(((e,t)=>e.then((()=>L(t)))),Promise.resolve())}return le}function Ve(){return o(Se)}
  923. /**
  924. * Returns the current route location. Equivalent to using `$route` inside
  925. * templates.
  926. */function Fe(e){return o(Ae)}export{ne as a,Fe as b,Ue as c,Ve as u};
  927. //# sourceMappingURL=vue-router-c7cbbcaa.js.map