kdu-router 3.0.1 → 3.0.7

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.
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * kdu-router v3.0.7
3
+ * (c) 2022 NKDuy
4
+ * @license MIT
5
+ */
6
+ /*!
7
+ * kdu-router v3.0.7
8
+ * (c) 2022 NKDuy
9
+ * @license MIT
10
+ */
11
+ function t(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function e(t,e){for(const n in e)t[n]=e[n];return t}var n={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render(t,{props:n,children:r,parent:o,data:i}){i.routerView=!0;const s=o.$createElement,a=n.name,c=o.$route,u=o._routerViewCache||(o._routerViewCache={});let h=0,p=!1;for(;o&&o._routerRoot!==o;){const t=o.$knode&&o.$knode.data;t&&(t.routerView&&h++,t.keepAlive&&o._inactive&&(p=!0)),o=o.$parent}if(i.routerViewDepth=h,p)return s(u[a],i,r);const l=c.matched[h];if(!l)return u[a]=null,s();const f=u[a]=l.components[a];i.registerRouteInstance=(t,e)=>{const n=l.instances[a];(e&&n!==t||!e&&n===t)&&(l.instances[a]=e)},(i.hook||(i.hook={})).prepatch=(t,e)=>{l.instances[a]=e.componentInstance},i.hook.init=t=>{t.data.keepAlive&&t.componentInstance&&t.componentInstance!==l.instances[a]&&(l.instances[a]=t.componentInstance)};let d=i.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(c,l.props&&l.props[a]);if(d){d=i.props=e({},d);const t=i.attrs=i.attrs||{};for(const e in d)f.props&&e in f.props||(t[e]=d[e],delete d[e])}return s(f,i,r)}};const r=/[!'()*]/g,o=t=>"%"+t.charCodeAt(0).toString(16),i=/%2C/g,s=t=>encodeURIComponent(t).replace(r,o).replace(i,","),a=decodeURIComponent;function c(t){const e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(t=>{const n=t.replace(/\+/g," ").split("="),r=a(n.shift()),o=n.length>0?a(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){const e=t?Object.keys(t).map(e=>{const n=t[e];if(void 0===n)return"";if(null===n)return s(e);if(Array.isArray(n)){const t=[];return n.forEach(n=>{void 0!==n&&(null===n?t.push(s(e)):t.push(s(e)+"="+s(n)))}),t.join("&")}return s(e)+"="+s(n)}).filter(t=>t.length>0).join("&"):null;return e?"?"+e:""}const h=/\/?$/;function p(t,e,n,r){const o=r&&r.options.stringifyQuery;let i=e.query||{};try{i=l(i)}catch(t){}const s={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:y(e,o),matched:t?d(t):[]};return n&&(s.redirectedFrom=y(n,o)),Object.freeze(s)}function l(t){if(Array.isArray(t))return t.map(l);if(t&&"object"==typeof t){const e={};for(const n in t)e[n]=l(t[n]);return e}return t}const f=p(null,{path:"/"});function d(t){const e=[];for(;t;)e.unshift(t),t=t.parent;return e}function y({path:t,query:e={},hash:n=""},r){return(t||"/")+(r||u)(e)+n}function m(t,e){return e===f?t===e:!!e&&(t.path&&e.path?t.path.replace(h,"")===e.path.replace(h,"")&&t.hash===e.hash&&g(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&g(t.query,e.query)&&g(t.params,e.params)))}function g(t={},e={}){if(!t||!e)return t===e;const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(n=>{const r=t[n],o=e[n];return"object"==typeof r&&"object"==typeof o?g(r,o):String(r)===String(o)})}var w={name:"RouterLink",props:{to:{type:[String,Object],required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:[String,Array],default:"click"}},render(t){const n=this.$router,r=this.$route,{location:o,route:i,href:s}=n.resolve(this.to,r,this.append),a={},c=n.options.linkActiveClass,u=n.options.linkExactActiveClass,l=null==c?"router-link-active":c,f=null==u?"router-link-exact-active":u,d=null==this.activeClass?l:this.activeClass,y=null==this.exactActiveClass?f:this.exactActiveClass,g=o.path?p(null,o,null,n):i;a[y]=m(r,g),a[d]=this.exact?a[y]:function(t,e){return 0===t.path.replace(h,"/").indexOf(e.path.replace(h,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(const n in e)if(!(n in t))return!1;return!0}(t.query,e.query)}(r,g);const w=t=>{b(t)&&(this.replace?n.replace(o):n.push(o))},v={click:b};Array.isArray(this.event)?this.event.forEach(t=>{v[t]=w}):v[this.event]=w;const x={class:a};if("a"===this.tag)x.on=v,x.attrs={href:s};else{const t=function t(e){if(e){let n;for(let r=0;r<e.length;r++){if(n=e[r],"a"===n.tag)return n;if(n.children&&(n=t(n.children)))return n}}}(this.$slots.default);if(t){t.isStatic=!1;(t.data=e({},t.data)).on=v;(t.data.attrs=e({},t.data.attrs)).href=s}else x.on=v}return t(this.tag,x,this.$slots.default)}};function b(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){const e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}let v;const x="undefined"!=typeof window;function k(t,e,n){const r=t.charAt(0);if("/"===r)return t;if("?"===r||"#"===r)return e+t;const o=e.split("/");n&&o[o.length-1]||o.pop();const i=t.replace(/^\//,"").split("/");for(let t=0;t<i.length;t++){const e=i[t];".."===e?o.pop():"."!==e&&o.push(e)}return""!==o[0]&&o.unshift(""),o.join("/")}function R(t){return t.replace(/\/\//g,"/")}var E=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},O=B,A=S,C=function(t,e){return L(S(t,e),e)},$=L,j=M,T=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function S(t,e){for(var n,r=[],o=0,i=0,s="",a=e&&e.delimiter||"/";null!=(n=T.exec(t));){var c=n[0],u=n[1],h=n.index;if(s+=t.slice(i,h),i=h+c.length,u)s+=u[1];else{var p=t[i],l=n[2],f=n[3],d=n[4],y=n[5],m=n[6],g=n[7];s&&(r.push(s),s="");var w=null!=l&&null!=p&&p!==l,b="+"===m||"*"===m,v="?"===m||"*"===m,x=n[2]||a,k=d||y;r.push({name:f||o++,prefix:l||"",delimiter:x,optional:v,repeat:b,partial:w,asterisk:!!g,pattern:k?U(k):g?".*":"[^"+q(x)+"]+?"})}}return i<t.length&&(s+=t.substr(i)),s&&r.push(s),r}function _(t){return encodeURI(t).replace(/[\/?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}))}function L(t,e){for(var n=new Array(t.length),r=0;r<t.length;r++)"object"==typeof t[r]&&(n[r]=new RegExp("^(?:"+t[r].pattern+")$",I(e)));return function(e,r){for(var o="",i=e||{},s=(r||{}).pretty?_:encodeURIComponent,a=0;a<t.length;a++){var c=t[a];if("string"!=typeof c){var u,h=i[c.name];if(null==h){if(c.optional){c.partial&&(o+=c.prefix);continue}throw new TypeError('Expected "'+c.name+'" to be defined')}if(E(h)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but received `'+JSON.stringify(h)+"`");if(0===h.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var p=0;p<h.length;p++){if(u=s(h[p]),!n[a].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'", but received `'+JSON.stringify(u)+"`");o+=(0===p?c.prefix:c.delimiter)+u}}else{if(u=c.asterisk?encodeURI(h).replace(/[?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})):s(h),!n[a].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but received "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function q(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function U(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function P(t,e){return t.keys=e,t}function I(t){return t&&t.sensitive?"":"i"}function M(t,e,n){E(e)||(n=e||n,e=[]);for(var r=(n=n||{}).strict,o=!1!==n.end,i="",s=0;s<t.length;s++){var a=t[s];if("string"==typeof a)i+=q(a);else{var c=q(a.prefix),u="(?:"+a.pattern+")";e.push(a),a.repeat&&(u+="(?:"+c+u+")*"),i+=u=a.optional?a.partial?c+"("+u+")?":"(?:"+c+"("+u+"))?":c+"("+u+")"}}var h=q(n.delimiter||"/"),p=i.slice(-h.length)===h;return r||(i=(p?i.slice(0,-h.length):i)+"(?:"+h+"(?=$))?"),i+=o?"$":r&&p?"":"(?="+h+"|$)",P(new RegExp("^"+i,I(n)),e)}function B(t,e,n){return E(e)||(n=e||n,e=[]),n=n||{},t instanceof RegExp?function(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return P(t,e)}(t,e):E(t)?function(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(B(t[o],e,n).source);return P(new RegExp("(?:"+r.join("|")+")",I(n)),e)}(t,e,n):function(t,e,n){return M(S(t,n),e,n)}(t,e,n)}O.parse=A,O.compile=C,O.tokensToFunction=$,O.tokensToRegExp=j;const H=Object.create(null);function z(t,e,n){e=e||{};try{const n=H[t]||(H[t]=O.compile(t));return e.pathMatch&&(e[0]=e.pathMatch),n(e,{pretty:!0})}catch(t){return""}finally{delete e[0]}}function K(t,e,n,r){const o=e||[],i=n||Object.create(null),s=r||Object.create(null);t.forEach(t=>{!function t(e,n,r,o,i,s){const{path:a,name:c}=o,u=o.pathToRegexpOptions||{},h=function(t,e,n){n||(t=t.replace(/\/$/,""));return"/"===t[0]||null==e?t:R(`${e.path}/${t}`)}(a,i,u.strict);"boolean"==typeof o.caseSensitive&&(u.sensitive=o.caseSensitive);const p={path:h,regex:V(h,u),components:o.components||{default:o.component},instances:{},name:c,parent:i,matchAs:s,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};o.children&&o.children.forEach(o=>{const i=s?R(`${s}/${o.path}`):void 0;t(e,n,r,o,p,i)});if(void 0!==o.alias){(Array.isArray(o.alias)?o.alias:[o.alias]).forEach(s=>{const a={path:s,children:o.children};t(e,n,r,a,i,p.path||"/")})}n[p.path]||(e.push(p.path),n[p.path]=p);c&&(r[c]||(r[c]=p))}(o,i,s,t)});for(let t=0,e=o.length;t<e;t++)"*"===o[t]&&(o.push(o.splice(t,1)[0]),e--,t--);return{pathList:o,pathMap:i,nameMap:s}}function V(t,e){return O(t,[],e)}function D(t,n,r,o){let i="string"==typeof t?{path:t}:t;if(i._normalized)return i;if(i.name)return e({},t);if(!i.path&&i.params&&n){i=e({},i),i._normalized=!0;const t=e(e({},n.params),i.params);if(n.name)i.name=n.name,i.params=t;else if(n.matched.length){const e=n.matched[n.matched.length-1].path;i.path=z(e,t,n.path)}return i}const s=function(t){let e="",n="";const r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));const o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}(i.path||""),a=n&&n.path||"/",u=s.path?k(s.path,a,r||i.append):a,h=function(t,e={},n){const r=n||c;let o;try{o=r(t||"")}catch(t){o={}}for(const t in e)o[t]=e[t];return o}(s.query,i.query,o&&o.options.parseQuery);let p=i.hash||s.hash;return p&&"#"!==p.charAt(0)&&(p="#"+p),{_normalized:!0,path:u,query:h,hash:p}}function F(t,e){const{pathList:n,pathMap:r,nameMap:o}=K(t);function i(t,i,s){const c=D(t,i,!1,e),{name:u}=c;if(u){const t=o[u];if(!t)return a(null,c);const e=t.regex.keys.filter(t=>!t.optional).map(t=>t.name);if("object"!=typeof c.params&&(c.params={}),i&&"object"==typeof i.params)for(const t in i.params)!(t in c.params)&&e.indexOf(t)>-1&&(c.params[t]=i.params[t]);return c.path=z(t.path,c.params),a(t,c,s)}if(c.path){c.params={};for(let t=0;t<n.length;t++){const e=n[t],o=r[e];if(J(o.regex,c.path,c.params))return a(o,c,s)}}return a(null,c)}function s(t,n){const r=t.redirect;let s="function"==typeof r?r(p(t,n,null,e)):r;if("string"==typeof s&&(s={path:s}),!s||"object"!=typeof s)return a(null,n);const c=s,{name:u,path:h}=c;let{query:l,hash:f,params:d}=n;if(l=c.hasOwnProperty("query")?c.query:l,f=c.hasOwnProperty("hash")?c.hash:f,d=c.hasOwnProperty("params")?c.params:d,u){o[u];return i({_normalized:!0,name:u,query:l,hash:f,params:d},void 0,n)}if(h){const e=function(t,e){return k(t,e.parent?e.parent.path:"/",!0)}(h,t);return i({_normalized:!0,path:z(e,d),query:l,hash:f},void 0,n)}return a(null,n)}function a(t,n,r){return t&&t.redirect?s(t,r||n):t&&t.matchAs?function(t,e,n){const r=i({_normalized:!0,path:z(n,e.params)});if(r){const t=r.matched,n=t[t.length-1];return e.params=r.params,a(n,e)}return a(null,e)}(0,n,t.matchAs):p(t,n,r,e)}return{match:i,addRoutes:function(t){K(t,n,r,o)}}}function J(t,e,n){const r=e.match(t);if(!r)return!1;if(!n)return!0;for(let e=1,o=r.length;e<o;++e){const o=t.keys[e-1],i="string"==typeof r[e]?decodeURIComponent(r[e]):r[e];o&&(n[o.name||"pathMatch"]=i)}return!0}const N=Object.create(null);function Q(){const t=window.location.protocol+"//"+window.location.host,e=window.location.href.replace(t,"");window.history.replaceState({key:it()},"",e),window.addEventListener("popstate",t=>{var e;Y(),t.state&&t.state.key&&(e=t.state.key,rt=e)})}function X(t,e,n,r){if(!t.app)return;const o=t.options.scrollBehavior;o&&t.app.$nextTick(()=>{const i=function(){const t=it();if(t)return N[t]}(),s=o.call(t,e,n,r?i:null);s&&("function"==typeof s.then?s.then(t=>{tt(t,i)}).catch(t=>{}):tt(s,i))})}function Y(){const t=it();t&&(N[t]={x:window.pageXOffset,y:window.pageYOffset})}function W(t){return Z(t.x)||Z(t.y)}function G(t){return{x:Z(t.x)?t.x:window.pageXOffset,y:Z(t.y)?t.y:window.pageYOffset}}function Z(t){return"number"==typeof t}function tt(t,e){const n="object"==typeof t;if(n&&"string"==typeof t.selector){const n=document.querySelector(t.selector);if(n){let o=t.offset&&"object"==typeof t.offset?t.offset:{};o={x:Z((r=o).x)?r.x:0,y:Z(r.y)?r.y:0},e=function(t,e){const n=document.documentElement.getBoundingClientRect(),r=t.getBoundingClientRect();return{x:r.left-n.left-e.x,y:r.top-n.top-e.y}}(n,o)}else W(t)&&(e=G(t))}else n&&W(t)&&(e=G(t));var r;e&&window.scrollTo(e.x,e.y)}const et=x&&function(){const t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)}(),nt=x&&window.performance&&window.performance.now?window.performance:Date;let rt=ot();function ot(){return nt.now().toFixed(3)}function it(){return rt}function st(t,e){Y();const n=window.history;try{e?n.replaceState({key:rt},"",t):(rt=ot(),n.pushState({key:rt},"",t))}catch(n){window.location[e?"replace":"assign"](t)}}function at(t){st(t,!0)}function ct(t,e,n){const r=o=>{o>=t.length?n():t[o]?e(t[o],()=>{r(o+1)}):r(o+1)};r(0)}function ut(e){return(n,r,o)=>{let i=!1,s=0,a=null;ht(e,(e,n,r,c)=>{if("function"==typeof e&&void 0===e.cid){i=!0,s++;const n=ft(t=>{var n;((n=t).__esModule||lt&&"Module"===n[Symbol.toStringTag])&&(t=t.default),e.resolved="function"==typeof t?t:v.extend(t),r.components[c]=t,s--,s<=0&&o()}),u=ft(e=>{const n=`Failed to resolve async component ${c}: ${e}`;a||(a=t(e)?e:new Error(n),o(a))});let h;try{h=e(n,u)}catch(t){u(t)}if(h)if("function"==typeof h.then)h.then(n,u);else{const t=h.component;t&&"function"==typeof t.then&&t.then(n,u)}}}),i||o()}}function ht(t,e){return pt(t.map(t=>Object.keys(t.components).map(n=>e(t.components[n],t.instances[n],t,n))))}function pt(t){return Array.prototype.concat.apply([],t)}const lt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function ft(t){let e=!1;return function(...n){if(!e)return e=!0,t.apply(this,n)}}class dt{constructor(t,e){this.router=t,this.base=function(t){if(!t)if(x){const e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=f,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]}listen(t){this.cb=t}onReady(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))}onError(t){this.errorCbs.push(t)}transitionTo(t,e,n){const r=this.router.match(t,this.current);this.confirmTransition(r,()=>{this.updateRoute(r),e&&e(r),this.ensureURL(),this.ready||(this.ready=!0,this.readyCbs.forEach(t=>{t(r)}))},t=>{n&&n(t),t&&!this.ready&&(this.ready=!0,this.readyErrorCbs.forEach(e=>{e(t)}))})}confirmTransition(e,n,r){const o=this.current,i=e=>{t(e)&&(this.errorCbs.length?this.errorCbs.forEach(t=>{t(e)}):console.error(e)),r&&r(e)};if(m(e,o)&&e.matched.length===o.matched.length)return this.ensureURL(),i();const{updated:s,deactivated:a,activated:c}=function(t,e){let n;const r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{updated:e.slice(0,n),activated:e.slice(n),deactivated:t.slice(n)}}(this.current.matched,e.matched),u=[].concat(function(t){return yt(t,"beforeRouteLeave",mt,!0)}(a),this.router.beforeHooks,function(t){return yt(t,"beforeRouteUpdate",mt)}(s),c.map(t=>t.beforeEnter),ut(c));this.pending=e;const h=(n,r)=>{if(this.pending!==e)return i();try{n(e,o,e=>{!1===e||t(e)?(this.ensureURL(!0),i(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(i(),"object"==typeof e&&e.replace?this.replace(e):this.push(e)):r(e)})}catch(t){i(t)}};ct(u,h,()=>{const t=[];ct(function(t,e,n){return yt(t,"beforeRouteEnter",(t,r,o,i)=>function(t,e,n,r,o){return function(i,s,a){return t(i,s,t=>{"function"==typeof t&&r.push(()=>{!function t(e,n,r,o){n[r]&&!n[r]._isBeingDestroyed?e(n[r]):o()&&setTimeout(()=>{t(e,n,r,o)},16)}(t,e.instances,n,o)}),a(t)})}}(t,o,i,e,n))}(c,t,()=>this.current===e).concat(this.router.resolveHooks),h,()=>{if(this.pending!==e)return i();this.pending=null,n(e),this.router.app&&this.router.app.$nextTick(()=>{t.forEach(t=>{t()})})})})}updateRoute(t){const e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(n=>{n&&n(t,e)})}}function yt(t,e,n,r){const o=ht(t,(t,r,o,i)=>{const s=function(t,e){"function"!=typeof t&&(t=v.extend(t));return t.options[e]}(t,e);if(s)return Array.isArray(s)?s.map(t=>n(t,r,o,i)):n(s,r,o,i)});return pt(r?o.reverse():o)}function mt(t,e){if(e)return function(){return t.apply(e,arguments)}}class gt extends dt{constructor(t,e){super(t,e);const n=t.options.scrollBehavior,r=et&&n;r&&Q();const o=wt(this.base);window.addEventListener("popstate",e=>{const n=this.current,i=wt(this.base);this.current===f&&i===o||this.transitionTo(i,e=>{r&&X(t,e,n,!0)})})}go(t){window.history.go(t)}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{st(R(this.base+t.fullPath)),X(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{at(R(this.base+t.fullPath)),X(this.router,t,r,!1),e&&e(t)},n)}ensureURL(t){if(wt(this.base)!==this.current.fullPath){const e=R(this.base+this.current.fullPath);t?st(e):at(e)}}getCurrentLocation(){return wt(this.base)}}function wt(t){let e=decodeURI(window.location.pathname);return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}class bt extends dt{constructor(t,e,n){super(t,e),n&&function(t){const e=wt(t);if(!/^\/#/.test(e))return window.location.replace(R(t+"/#"+e)),!0}(this.base)||vt()}setupListeners(){const t=this.router.options.scrollBehavior,e=et&&t;e&&Q(),window.addEventListener(et?"popstate":"hashchange",()=>{const t=this.current;vt()&&this.transitionTo(xt(),n=>{e&&X(this.router,n,t,!0),et||Et(n.fullPath)})})}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Rt(t.fullPath),X(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Et(t.fullPath),X(this.router,t,r,!1),e&&e(t)},n)}go(t){window.history.go(t)}ensureURL(t){const e=this.current.fullPath;xt()!==e&&(t?Rt(e):Et(e))}getCurrentLocation(){return xt()}}function vt(){const t=xt();return"/"===t.charAt(0)||(Et("/"+t),!1)}function xt(){let t=window.location.href;const e=t.indexOf("#");if(e<0)return"";t=t.slice(e+1);const n=t.indexOf("?");if(n<0){const e=t.indexOf("#");t=e>-1?decodeURI(t.slice(0,e))+t.slice(e):decodeURI(t)}else n>-1&&(t=decodeURI(t.slice(0,n))+t.slice(n));return t}function kt(t){const e=window.location.href,n=e.indexOf("#");return`${n>=0?e.slice(0,n):e}#${t}`}function Rt(t){et?st(kt(t)):window.location.hash=t}function Et(t){et?at(kt(t)):window.location.replace(kt(t))}class Ot extends dt{constructor(t,e){super(t,e),this.stack=[],this.index=-1}push(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index+1).concat(t),this.index++,e&&e(t)},n)}replace(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index).concat(t),e&&e(t)},n)}go(t){const e=this.index+t;if(e<0||e>=this.stack.length)return;const n=this.stack[e];this.confirmTransition(n,()=>{this.index=e,this.updateRoute(n)})}getCurrentLocation(){const t=this.stack[this.stack.length-1];return t?t.fullPath:"/"}ensureURL(){}}class At{constructor(t={}){this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=F(t.routes||[],this);let e=t.mode||"hash";switch(this.fallback="history"===e&&!et&&!1!==t.fallback,this.fallback&&(e="hash"),x||(e="abstract"),this.mode=e,e){case"history":this.history=new gt(this,t.base);break;case"hash":this.history=new bt(this,t.base,this.fallback);break;case"abstract":this.history=new Ot(this,t.base)}}match(t,e,n){return this.matcher.match(t,e,n)}get currentRoute(){return this.history&&this.history.current}init(t){if(this.apps.push(t),t.$once("hook:destroyed",()=>{const e=this.apps.indexOf(t);e>-1&&this.apps.splice(e,1),this.app===t&&(this.app=this.apps[0]||null)}),this.app)return;this.app=t;const e=this.history;if(e instanceof gt)e.transitionTo(e.getCurrentLocation());else if(e instanceof bt){const t=()=>{e.setupListeners()};e.transitionTo(e.getCurrentLocation(),t,t)}e.listen(t=>{this.apps.forEach(e=>{e._route=t})})}beforeEach(t){return Ct(this.beforeHooks,t)}beforeResolve(t){return Ct(this.resolveHooks,t)}afterEach(t){return Ct(this.afterHooks,t)}onReady(t,e){this.history.onReady(t,e)}onError(t){this.history.onError(t)}push(t,e,n){this.history.push(t,e,n)}replace(t,e,n){this.history.replace(t,e,n)}go(t){this.history.go(t)}back(){this.go(-1)}forward(){this.go(1)}getMatchedComponents(t){const e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(t=>Object.keys(t.components).map(e=>t.components[e]))):[]}resolve(t,e,n){const r=D(t,e=e||this.history.current,n,this),o=this.match(r,e),i=o.redirectedFrom||o.fullPath;return{location:r,route:o,href:function(t,e,n){var r="hash"===n?"#"+e:e;return t?R(t+"/"+r):r}(this.history.base,i,this.mode),normalizedTo:r,resolved:o}}addRoutes(t){this.matcher.addRoutes(t),this.history.current!==f&&this.history.transitionTo(this.history.getCurrentLocation())}}function Ct(t,e){return t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)}}At.install=function t(e){if(t.installed&&v===e)return;t.installed=!0,v=e;const r=t=>void 0!==t,o=(t,e)=>{let n=t.$options._parentKnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate(){r(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),e.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,o(this,this)},destroyed(){o(this)}}),Object.defineProperty(e.prototype,"$router",{get(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get(){return this._routerRoot._route}}),e.component("RouterView",n),e.component("RouterLink",w);const i=e.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created},At.version="3.0.7",x&&window.Kdu&&window.Kdu.use(At);export default At;
@@ -1,5 +1,5 @@
1
- /**
2
- * kdu-router v3.0.1
1
+ /*!
2
+ * kdu-router v3.0.7
3
3
  * (c) 2022 NKDuy
4
4
  * @license MIT
5
5
  */
@@ -21,8 +21,15 @@ function isError (err) {
21
21
  return Object.prototype.toString.call(err).indexOf('Error') > -1
22
22
  }
23
23
 
24
+ function extend (a, b) {
25
+ for (var key in b) {
26
+ a[key] = b[key];
27
+ }
28
+ return a
29
+ }
30
+
24
31
  var View = {
25
- name: 'router-view',
32
+ name: 'RouterView',
26
33
  functional: true,
27
34
  props: {
28
35
  name: {
@@ -36,6 +43,7 @@ var View = {
36
43
  var parent = ref.parent;
37
44
  var data = ref.data;
38
45
 
46
+ // used by devtools to display a router-view badge
39
47
  data.routerView = true;
40
48
 
41
49
  // directly use parent context's createElement() function
@@ -50,11 +58,14 @@ var View = {
50
58
  var depth = 0;
51
59
  var inactive = false;
52
60
  while (parent && parent._routerRoot !== parent) {
53
- if (parent.$knode && parent.$knode.data.routerView) {
54
- depth++;
55
- }
56
- if (parent._inactive) {
57
- inactive = true;
61
+ var knodeData = parent.$knode && parent.$knode.data;
62
+ if (knodeData) {
63
+ if (knodeData.routerView) {
64
+ depth++;
65
+ }
66
+ if (knodeData.keepAlive && parent._inactive) {
67
+ inactive = true;
68
+ }
58
69
  }
59
70
  parent = parent.$parent;
60
71
  }
@@ -93,6 +104,17 @@ var View = {
93
104
  matched.instances[name] = knode.componentInstance;
94
105
  };
95
106
 
107
+ // register instance in init hook
108
+ // in case kept-alive component be actived when routes changed
109
+ data.hook.init = function (knode) {
110
+ if (knode.data.keepAlive &&
111
+ knode.componentInstance &&
112
+ knode.componentInstance !== matched.instances[name]
113
+ ) {
114
+ matched.instances[name] = knode.componentInstance;
115
+ }
116
+ };
117
+
96
118
  // resolve props
97
119
  var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]);
98
120
  if (propsToPass) {
@@ -110,7 +132,7 @@ var View = {
110
132
 
111
133
  return h(component, data, children)
112
134
  }
113
- };
135
+ }
114
136
 
115
137
  function resolveProps (route, config) {
116
138
  switch (typeof config) {
@@ -133,13 +155,6 @@ function resolveProps (route, config) {
133
155
  }
134
156
  }
135
157
 
136
- function extend (to, from) {
137
- for (var key in from) {
138
- to[key] = from[key];
139
- }
140
- return to
141
- }
142
-
143
158
  /* */
144
159
 
145
160
  var encodeReserveRE = /[!'()*]/g;
@@ -238,7 +253,6 @@ function stringifyQuery (obj) {
238
253
 
239
254
  /* */
240
255
 
241
-
242
256
  var trailingSlashRE = /\/?$/;
243
257
 
244
258
  function createRoute (
@@ -381,7 +395,7 @@ var toTypes = [String, Object];
381
395
  var eventTypes = [String, Array];
382
396
 
383
397
  var Link = {
384
- name: 'router-link',
398
+ name: 'RouterLink',
385
399
  props: {
386
400
  to: {
387
401
  type: toTypes,
@@ -416,17 +430,17 @@ var Link = {
416
430
  var globalExactActiveClass = router.options.linkExactActiveClass;
417
431
  // Support global empty active class
418
432
  var activeClassFallback = globalActiveClass == null
419
- ? 'router-link-active'
420
- : globalActiveClass;
433
+ ? 'router-link-active'
434
+ : globalActiveClass;
421
435
  var exactActiveClassFallback = globalExactActiveClass == null
422
- ? 'router-link-exact-active'
423
- : globalExactActiveClass;
436
+ ? 'router-link-exact-active'
437
+ : globalExactActiveClass;
424
438
  var activeClass = this.activeClass == null
425
- ? activeClassFallback
426
- : this.activeClass;
439
+ ? activeClassFallback
440
+ : this.activeClass;
427
441
  var exactActiveClass = this.exactActiveClass == null
428
- ? exactActiveClassFallback
429
- : this.exactActiveClass;
442
+ ? exactActiveClassFallback
443
+ : this.exactActiveClass;
430
444
  var compareTarget = location.path
431
445
  ? createRoute(null, location, null, router)
432
446
  : route;
@@ -466,7 +480,6 @@ var Link = {
466
480
  if (a) {
467
481
  // in case the <a> is a static node
468
482
  a.isStatic = false;
469
- var extend = _Kdu.util.extend;
470
483
  var aData = a.data = extend({}, a.data);
471
484
  aData.on = on;
472
485
  var aAttrs = a.data.attrs = extend({}, a.data.attrs);
@@ -479,7 +492,7 @@ var Link = {
479
492
 
480
493
  return h(this.tag, data, this.$slots.default)
481
494
  }
482
- };
495
+ }
483
496
 
484
497
  function guardEvent (e) {
485
498
  // don't redirect with control keys
@@ -557,8 +570,8 @@ function install (Kdu) {
557
570
  get: function get () { return this._routerRoot._route }
558
571
  });
559
572
 
560
- Kdu.component('router-view', View);
561
- Kdu.component('router-link', Link);
573
+ Kdu.component('RouterView', View);
574
+ Kdu.component('RouterLink', Link);
562
575
 
563
576
  var strats = Kdu.config.optionMergeStrategies;
564
577
  // use the same hook merging strategy for route hooks
@@ -1068,7 +1081,6 @@ function pathToRegexp (path, keys, options) {
1068
1081
 
1069
1082
  return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
1070
1083
  }
1071
-
1072
1084
  pathToRegexp_1.parse = parse_1;
1073
1085
  pathToRegexp_1.compile = compile_1;
1074
1086
  pathToRegexp_1.tokensToFunction = tokensToFunction_1;
@@ -1084,16 +1096,24 @@ function fillParams (
1084
1096
  params,
1085
1097
  routeMsg
1086
1098
  ) {
1099
+ params = params || {};
1087
1100
  try {
1088
1101
  var filler =
1089
1102
  regexpCompileCache[path] ||
1090
1103
  (regexpCompileCache[path] = pathToRegexp_1.compile(path));
1091
- return filler(params || {}, { pretty: true })
1104
+
1105
+ // Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }}
1106
+ if (params.pathMatch) { params[0] = params.pathMatch; }
1107
+
1108
+ return filler(params, { pretty: true })
1092
1109
  } catch (e) {
1093
1110
  if (process.env.NODE_ENV !== 'production') {
1094
1111
  warn(false, ("missing param for " + routeMsg + ": " + (e.message)));
1095
1112
  }
1096
1113
  return ''
1114
+ } finally {
1115
+ // delete the 0 if it was added
1116
+ delete params[0];
1097
1117
  }
1098
1118
  }
1099
1119
 
@@ -1264,7 +1284,6 @@ function normalizePath (path, parent, strict) {
1264
1284
 
1265
1285
  /* */
1266
1286
 
1267
-
1268
1287
  function normalizeLocation (
1269
1288
  raw,
1270
1289
  current,
@@ -1273,15 +1292,17 @@ function normalizeLocation (
1273
1292
  ) {
1274
1293
  var next = typeof raw === 'string' ? { path: raw } : raw;
1275
1294
  // named target
1276
- if (next.name || next._normalized) {
1295
+ if (next._normalized) {
1277
1296
  return next
1297
+ } else if (next.name) {
1298
+ return extend({}, raw)
1278
1299
  }
1279
1300
 
1280
1301
  // relative params
1281
1302
  if (!next.path && next.params && current) {
1282
- next = assign({}, next);
1303
+ next = extend({}, next);
1283
1304
  next._normalized = true;
1284
- var params = assign(assign({}, current.params), next.params);
1305
+ var params = extend(extend({}, current.params), next.params);
1285
1306
  if (current.name) {
1286
1307
  next.name = current.name;
1287
1308
  next.params = params;
@@ -1319,16 +1340,10 @@ function normalizeLocation (
1319
1340
  }
1320
1341
  }
1321
1342
 
1322
- function assign (a, b) {
1323
- for (var key in b) {
1324
- a[key] = b[key];
1325
- }
1326
- return a
1327
- }
1328
-
1329
1343
  /* */
1330
1344
 
1331
1345
 
1346
+
1332
1347
  function createMatcher (
1333
1348
  routes,
1334
1349
  router
@@ -1372,10 +1387,8 @@ function createMatcher (
1372
1387
  }
1373
1388
  }
1374
1389
 
1375
- if (record) {
1376
- location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1377
- return _createRoute(record, location, redirectedFrom)
1378
- }
1390
+ location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1391
+ return _createRoute(record, location, redirectedFrom)
1379
1392
  } else if (location.path) {
1380
1393
  location.params = {};
1381
1394
  for (var i = 0; i < pathList.length; i++) {
@@ -1396,8 +1409,8 @@ function createMatcher (
1396
1409
  ) {
1397
1410
  var originalRedirect = record.redirect;
1398
1411
  var redirect = typeof originalRedirect === 'function'
1399
- ? originalRedirect(createRoute(record, location, null, router))
1400
- : originalRedirect;
1412
+ ? originalRedirect(createRoute(record, location, null, router))
1413
+ : originalRedirect;
1401
1414
 
1402
1415
  if (typeof redirect === 'string') {
1403
1416
  redirect = { path: redirect };
@@ -1511,7 +1524,8 @@ function matchRoute (
1511
1524
  var key = regex.keys[i - 1];
1512
1525
  var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i];
1513
1526
  if (key) {
1514
- params[key.name] = val;
1527
+ // Fix #1994: using * with props: true generates a param named 0
1528
+ params[key.name || 'pathMatch'] = val;
1515
1529
  }
1516
1530
  }
1517
1531
 
@@ -1524,12 +1538,17 @@ function resolveRecordPath (path, record) {
1524
1538
 
1525
1539
  /* */
1526
1540
 
1527
-
1528
1541
  var positionStore = Object.create(null);
1529
1542
 
1530
1543
  function setupScroll () {
1531
1544
  // Fix for #1585 for Firefox
1532
- window.history.replaceState({ key: getStateKey() }, '');
1545
+ // Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1546
+ // Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1547
+ // window.location.protocol + '//' + window.location.host
1548
+ // location.host contains the port and location.hostname doesn't
1549
+ var protocolAndPath = window.location.protocol + '//' + window.location.host;
1550
+ var absolutePath = window.location.href.replace(protocolAndPath, '');
1551
+ window.history.replaceState({ key: getStateKey() }, '', absolutePath);
1533
1552
  window.addEventListener('popstate', function (e) {
1534
1553
  saveScrollPosition();
1535
1554
  if (e.state && e.state.key) {
@@ -1560,7 +1579,7 @@ function handleScroll (
1560
1579
  // wait until re-render finishes before scrolling
1561
1580
  router.app.$nextTick(function () {
1562
1581
  var position = getScrollPosition();
1563
- var shouldScroll = behavior(to, from, isPop ? position : null);
1582
+ var shouldScroll = behavior.call(router, to, from, isPop ? position : null);
1564
1583
 
1565
1584
  if (!shouldScroll) {
1566
1585
  return
@@ -2101,7 +2120,6 @@ function bindEnterGuard (
2101
2120
  ) {
2102
2121
  return function routeEnterGuard (to, from, next) {
2103
2122
  return guard(to, from, function (cb) {
2104
- next(cb);
2105
2123
  if (typeof cb === 'function') {
2106
2124
  cbs.push(function () {
2107
2125
  // #750
@@ -2112,6 +2130,7 @@ function bindEnterGuard (
2112
2130
  poll(cb, match.instances, key, isValid);
2113
2131
  });
2114
2132
  }
2133
+ next(cb);
2115
2134
  })
2116
2135
  }
2117
2136
  }
@@ -2122,7 +2141,10 @@ function poll (
2122
2141
  key,
2123
2142
  isValid
2124
2143
  ) {
2125
- if (instances[key]) {
2144
+ if (
2145
+ instances[key] &&
2146
+ !instances[key]._isBeingDestroyed // do not reuse being destroyed instance
2147
+ ) {
2126
2148
  cb(instances[key]);
2127
2149
  } else if (isValid()) {
2128
2150
  setTimeout(function () {
@@ -2133,16 +2155,16 @@ function poll (
2133
2155
 
2134
2156
  /* */
2135
2157
 
2136
-
2137
- var HTML5History = (function (History$$1) {
2158
+ var HTML5History = /*@__PURE__*/(function (History$$1) {
2138
2159
  function HTML5History (router, base) {
2139
2160
  var this$1 = this;
2140
2161
 
2141
2162
  History$$1.call(this, router, base);
2142
2163
 
2143
2164
  var expectScroll = router.options.scrollBehavior;
2165
+ var supportsScroll = supportsPushState && expectScroll;
2144
2166
 
2145
- if (expectScroll) {
2167
+ if (supportsScroll) {
2146
2168
  setupScroll();
2147
2169
  }
2148
2170
 
@@ -2158,7 +2180,7 @@ var HTML5History = (function (History$$1) {
2158
2180
  }
2159
2181
 
2160
2182
  this$1.transitionTo(location, function (route) {
2161
- if (expectScroll) {
2183
+ if (supportsScroll) {
2162
2184
  handleScroll(router, route, current, true);
2163
2185
  }
2164
2186
  });
@@ -2212,7 +2234,7 @@ var HTML5History = (function (History$$1) {
2212
2234
  }(History));
2213
2235
 
2214
2236
  function getLocation (base) {
2215
- var path = window.location.pathname;
2237
+ var path = decodeURI(window.location.pathname);
2216
2238
  if (base && path.indexOf(base) === 0) {
2217
2239
  path = path.slice(base.length);
2218
2240
  }
@@ -2221,8 +2243,7 @@ function getLocation (base) {
2221
2243
 
2222
2244
  /* */
2223
2245
 
2224
-
2225
- var HashHistory = (function (History$$1) {
2246
+ var HashHistory = /*@__PURE__*/(function (History$$1) {
2226
2247
  function HashHistory (router, base, fallback) {
2227
2248
  History$$1.call(this, router, base);
2228
2249
  // check history fallback deeplinking
@@ -2331,7 +2352,22 @@ function getHash () {
2331
2352
  // consistent across browsers - Firefox will pre-decode it!
2332
2353
  var href = window.location.href;
2333
2354
  var index = href.indexOf('#');
2334
- return index === -1 ? '' : href.slice(index + 1)
2355
+ // empty path
2356
+ if (index < 0) { return '' }
2357
+
2358
+ href = href.slice(index + 1);
2359
+ // decode the hash but not the search or hash
2360
+ // as search(query) is already decoded
2361
+ var searchIndex = href.indexOf('?');
2362
+ if (searchIndex < 0) {
2363
+ var hashIndex = href.indexOf('#');
2364
+ if (hashIndex > -1) { href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); }
2365
+ else { href = decodeURI(href); }
2366
+ } else {
2367
+ if (searchIndex > -1) { href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); }
2368
+ }
2369
+
2370
+ return href
2335
2371
  }
2336
2372
 
2337
2373
  function getUrl (path) {
@@ -2359,8 +2395,7 @@ function replaceHash (path) {
2359
2395
 
2360
2396
  /* */
2361
2397
 
2362
-
2363
- var AbstractHistory = (function (History$$1) {
2398
+ var AbstractHistory = /*@__PURE__*/(function (History$$1) {
2364
2399
  function AbstractHistory (router, base) {
2365
2400
  History$$1.call(this, router, base);
2366
2401
  this.stack = [];
@@ -2418,6 +2453,8 @@ var AbstractHistory = (function (History$$1) {
2418
2453
 
2419
2454
  /* */
2420
2455
 
2456
+
2457
+
2421
2458
  var KduRouter = function KduRouter (options) {
2422
2459
  if ( options === void 0 ) options = {};
2423
2460
 
@@ -2481,7 +2518,18 @@ KduRouter.prototype.init = function init (app /* Kdu component instance */) {
2481
2518
 
2482
2519
  this.apps.push(app);
2483
2520
 
2484
- // main app already initialized.
2521
+ // set up app destroyed handler
2522
+ app.$once('hook:destroyed', function () {
2523
+ // clean out app from this.apps array once destroyed
2524
+ var index = this$1.apps.indexOf(app);
2525
+ if (index > -1) { this$1.apps.splice(index, 1); }
2526
+ // ensure we still have a main app or null if no apps
2527
+ // we do not release the router so it can be reused
2528
+ if (this$1.app === app) { this$1.app = this$1.apps[0] || null; }
2529
+ });
2530
+
2531
+ // main app previously initialized
2532
+ // return as we don't need to set up new history listener
2485
2533
  if (this.app) {
2486
2534
  return
2487
2535
  }
@@ -2571,9 +2619,10 @@ KduRouter.prototype.resolve = function resolve (
2571
2619
  current,
2572
2620
  append
2573
2621
  ) {
2622
+ current = current || this.history.current;
2574
2623
  var location = normalizeLocation(
2575
2624
  to,
2576
- current || this.history.current,
2625
+ current,
2577
2626
  append,
2578
2627
  this
2579
2628
  );
@@ -2614,7 +2663,7 @@ function createHref (base, fullPath, mode) {
2614
2663
  }
2615
2664
 
2616
2665
  KduRouter.install = install;
2617
- KduRouter.version = '3.0.1';
2666
+ KduRouter.version = '3.0.7';
2618
2667
 
2619
2668
  if (inBrowser && window.Kdu) {
2620
2669
  window.Kdu.use(KduRouter);