kdu-router 3.1.3 → 3.1.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.
@@ -1,6 +1,11 @@
1
- /**
2
- * Kdu-router v3.1.3
3
- * (c) 2022 NKDuy
4
- * @license MIT
5
- */
6
- var t,e;t=this,e=function(){"use strict";function t(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function e(t,e){return e instanceof t||e&&(e.name===t.name||e._name===t._name)}function r(t,e){for(var r in e)t[r]=e[r];return t}var n={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,o=e.children,i=e.parent,a=e.data;a.routerView=!0;for(var c=i.$createElement,u=n.name,s=i.$route,p=i._routerViewCache||(i._routerViewCache={}),f=0,h=!1;i&&i._routerRoot!==i;){var l=i.$vnode&&i.$vnode.data;l&&(l.routerView&&f++,l.keepAlive&&i._inactive&&(h=!0)),i=i.$parent}if(a.routerViewDepth=f,h)return c(p[u],a,o);var d=s.matched[f];if(!d)return p[u]=null,c();var v=p[u]=d.components[u];a.registerRouteInstance=function(t,e){var r=d.instances[u];(e&&r!==t||!e&&r===t)&&(d.instances[u]=e)},(a.hook||(a.hook={})).prepatch=function(t,e){d.instances[u]=e.componentInstance},a.hook.init=function(t){t.data.keepAlive&&t.componentInstance&&t.componentInstance!==d.instances[u]&&(d.instances[u]=t.componentInstance)};var y=a.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}}(s,d.props&&d.props[u]);if(y){y=a.props=r({},y);var m=a.attrs=a.attrs||{};for(var g in y)v.props&&g in v.props||(m[g]=y[g],delete y[g])}return c(v,a,o)}},o=/[!'()*]/g,i=function(t){return"%"+t.charCodeAt(0).toString(16)},a=/%2C/g,c=function(t){return encodeURIComponent(t).replace(o,i).replace(a,",")},u=decodeURIComponent;function s(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=u(r.shift()),o=r.length>0?u(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]}),e):e}function p(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return c(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(c(e)):n.push(c(e)+"="+c(t)))}),n.join("&")}return c(e)+"="+c(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}var f=/\/?$/;function h(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=l(i)}catch(t){}var a={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?v(t):[]};return r&&(a.redirectedFrom=y(r,o)),Object.freeze(a)}function l(t){if(Array.isArray(t))return t.map(l);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=l(t[r]);return e}return t}var d=h(null,{path:"/"});function v(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function y(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;return void 0===o&&(o=""),(r||"/")+(e||p)(n)+o}function m(t,e){return e===d?t===e:!!e&&(t.path&&e.path?t.path.replace(f,"")===e.path.replace(f,"")&&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(void 0===t&&(t={}),void 0===e&&(e={}),!t||!e)return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(r){var n=t[r],o=e[r];return"object"==typeof n&&"object"==typeof o?g(n,o):String(n)===String(o)})}function b(t,e,r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;var o=e.split("/");r&&o[o.length-1]||o.pop();for(var i=t.replace(/^\//,"").split("/"),a=0;a<i.length;a++){var c=i[a];".."===c?o.pop():"."!==c&&o.push(c)}return""!==o[0]&&o.unshift(""),o.join("/")}function w(t){return t.replace(/\/\//g,"/")}var x=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},k=U,R=j,E=function(t,e){return S(j(t,e))},O=S,_=q,A=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function j(t,e){for(var r,n=[],o=0,i=0,a="",c=e&&e.delimiter||"/";null!=(r=A.exec(t));){var u=r[0],s=r[1],p=r.index;if(a+=t.slice(i,p),i=p+u.length,s)a+=s[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],v=r[5],y=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,b="+"===y||"*"===y,w="?"===y||"*"===y,x=r[2]||c,k=d||v;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:w,repeat:b,partial:g,asterisk:!!m,pattern:k?T(k):m?".*":"[^"+$(x)+"]+?"})}}return i<t.length&&(a+=t.substr(i)),a&&n.push(a),n}function C(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function S(t){for(var e=new Array(t.length),r=0;r<t.length;r++)"object"==typeof t[r]&&(e[r]=new RegExp("^(?:"+t[r].pattern+")$"));return function(r,n){for(var o="",i=r||{},a=(n||{}).pretty?C:encodeURIComponent,c=0;c<t.length;c++){var u=t[c];if("string"!=typeof u){var s,p=i[u.name];if(null==p){if(u.optional){u.partial&&(o+=u.prefix);continue}throw new TypeError('Expected "'+u.name+'" to be defined')}if(x(p)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but received `'+JSON.stringify(p)+"`");if(0===p.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var f=0;f<p.length;f++){if(s=a(p[f]),!e[c].test(s))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'", but received `'+JSON.stringify(s)+"`");o+=(0===f?u.prefix:u.delimiter)+s}}else{if(s=u.asterisk?encodeURI(p).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}):a(p),!e[c].test(s))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but received "'+s+'"');o+=u.prefix+s}}else o+=u}return o}}function $(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function T(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function P(t,e){return t.keys=e,t}function L(t){return t.sensitive?"":"i"}function q(t,e,r){x(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,o=!1!==r.end,i="",a=0;a<t.length;a++){var c=t[a];if("string"==typeof c)i+=$(c);else{var u=$(c.prefix),s="(?:"+c.pattern+")";e.push(c),c.repeat&&(s+="(?:"+u+s+")*"),i+=s=c.optional?c.partial?u+"("+s+")?":"(?:"+u+"("+s+"))?":u+"("+s+")"}}var p=$(r.delimiter||"/"),f=i.slice(-p.length)===p;return n||(i=(f?i.slice(0,-p.length):i)+"(?:"+p+"(?=$))?"),i+=o?"$":n&&f?"":"(?="+p+"|$)",P(new RegExp("^"+i,L(r)),e)}function U(t,e,r){return x(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp?function(t,e){var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return P(t,e)}(t,e):x(t)?function(t,e,r){for(var n=[],o=0;o<t.length;o++)n.push(U(t[o],e,r).source);return P(new RegExp("(?:"+n.join("|")+")",L(r)),e)}(t,e,r):function(t,e,r){return q(j(t,r),e,r)}(t,e,r)}k.parse=R,k.compile=E,k.tokensToFunction=O,k.tokensToRegExp=_;var I=Object.create(null);function M(t,e,r){e=e||{};try{var n=I[t]||(I[t]=k.compile(t));return e.pathMatch&&(e[0]=e.pathMatch),n(e,{pretty:!0})}catch(t){return""}finally{delete e[0]}}function V(t,e,n,o){var i="string"==typeof t?{path:t}:t;if(i._normalized)return i;if(i.name)return r({},t);if(!i.path&&i.params&&e){(i=r({},i))._normalized=!0;var a=r(r({},e.params),i.params);if(e.name)i.name=e.name,i.params=a;else if(e.matched.length){var c=e.matched[e.matched.length-1].path;i.path=M(c,a,e.path)}return i}var u=function(t){var e="",r="",n=t.indexOf("#");n>=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}(i.path||""),p=e&&e.path||"/",f=u.path?b(u.path,p,n||i.append):p,h=function(t,e,r){void 0===e&&(e={});var n,o=r||s;try{n=o(t||"")}catch(t){n={}}for(var i in e)n[i]=e[i];return n}(u.query,i.query,o&&o.options.parseQuery),l=i.hash||u.hash;return l&&"#"!==l.charAt(0)&&(l="#"+l),{_normalized:!0,path:f,query:h,hash:l}}var B,H=[String,Object],z=[String,Array],D=function(){},F={name:"RouterLink",props:{to:{type:H,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:z,default:"click"}},render:function(t){var e=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,c=i.route,u=i.href,s={},p=n.options.linkActiveClass,l=n.options.linkExactActiveClass,d=null==p?"router-link-active":p,v=null==l?"router-link-exact-active":l,y=null==this.activeClass?d:this.activeClass,g=null==this.exactActiveClass?v:this.exactActiveClass,b=c.redirectedFrom?h(null,V(c.redirectedFrom),null,n):c;s[g]=m(o,b),s[y]=this.exact?s[g]:function(t,e){return 0===t.path.replace(f,"/").indexOf(e.path.replace(f,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}(o,b);var w=function(t){N(t)&&(e.replace?n.replace(a,D):n.push(a,D))},x={click:N};Array.isArray(this.event)?this.event.forEach(function(t){x[t]=w}):x[this.event]=w;var k={class:s},R=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:u,route:c,navigate:w,isActive:s[y],isExactActive:s[g]});if(R){if(1===R.length)return R[0];if(R.length>1||!R.length)return 0===R.length?t():t("span",{},R)}if("a"===this.tag)k.on=x,k.attrs={href:u};else{var E=function t(e){if(e)for(var r,n=0;n<e.length;n++){if("a"===(r=e[n]).tag)return r;if(r.children&&(r=t(r.children)))return r}}(this.$slots.default);if(E){E.isStatic=!1;var O=E.data=r({},E.data);for(var _ in O.on=O.on||{},O.on){var A=O.on[_];_ in x&&(O.on[_]=Array.isArray(A)?A:[A])}for(var j in x)j in O.on?O.on[j].push(x[j]):O.on[j]=w;(E.data.attrs=r({},E.data.attrs)).href=u}else k.on=x}return t(this.tag,k,this.$slots.default)}};function N(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}var K="undefined"!=typeof window;function J(t,e,r,n){var o=e||[],i=r||Object.create(null),a=n||Object.create(null);t.forEach(function(t){!function t(e,r,n,o,i,a){var c=o.path,u=o.name,s=o.pathToRegexpOptions||{},p=function(t,e,r){return r||(t=t.replace(/\/$/,"")),"/"===t[0]?t:null==e?t:w(e.path+"/"+t)}(c,i,s.strict);"boolean"==typeof o.caseSensitive&&(s.sensitive=o.caseSensitive);var f={path:p,regex:Q(p,s),components:o.components||{default:o.component},instances:{},name:u,parent:i,matchAs:a,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};if(o.children&&o.children.forEach(function(o){var i=a?w(a+"/"+o.path):void 0;t(e,r,n,o,f,i)}),r[f.path]||(e.push(f.path),r[f.path]=f),void 0!==o.alias)for(var h=Array.isArray(o.alias)?o.alias:[o.alias],l=0;l<h.length;++l){var d=h[l],v={path:d,children:o.children};t(e,r,n,v,i,f.path||"/")}u&&(n[u]||(n[u]=f))}(o,i,a,t)});for(var c=0,u=o.length;c<u;c++)"*"===o[c]&&(o.push(o.splice(c,1)[0]),u--,c--);return{pathList:o,pathMap:i,nameMap:a}}function Q(t,e){return k(t,[],e)}function X(t,e){var r=J(t),n=r.pathList,o=r.pathMap,i=r.nameMap;function a(t,r,a){var c=V(t,r,!1,e),s=c.name;if(s){var p=i[s];if(!p)return u(null,c);var f=p.regex.keys.filter(function(t){return!t.optional}).map(function(t){return t.name});if("object"!=typeof c.params&&(c.params={}),r&&"object"==typeof r.params)for(var h in r.params)!(h in c.params)&&f.indexOf(h)>-1&&(c.params[h]=r.params[h]);return c.path=M(p.path,c.params),u(p,c,a)}if(c.path){c.params={};for(var l=0;l<n.length;l++){var d=n[l],v=o[d];if(Y(v.regex,c.path,c.params))return u(v,c,a)}}return u(null,c)}function c(t,r){var n=t.redirect,o="function"==typeof n?n(h(t,r,null,e)):n;if("string"==typeof o&&(o={path:o}),!o||"object"!=typeof o)return u(null,r);var c=o,s=c.name,p=c.path,f=r.query,l=r.hash,d=r.params;return f=c.hasOwnProperty("query")?c.query:f,l=c.hasOwnProperty("hash")?c.hash:l,d=c.hasOwnProperty("params")?c.params:d,s?(i[s],a({_normalized:!0,name:s,query:f,hash:l,params:d},void 0,r)):p?a({_normalized:!0,path:M(function(t,e){return b(t,e.parent?e.parent.path:"/",!0)}(p,t),d),query:f,hash:l},void 0,r):u(null,r)}function u(t,r,n){return t&&t.redirect?c(t,n||r):t&&t.matchAs?function(t,e,r){var n=a({_normalized:!0,path:M(r,e.params)});if(n){var o=n.matched,i=o[o.length-1];return e.params=n.params,u(i,e)}return u(null,e)}(0,r,t.matchAs):h(t,r,n,e)}return{match:a,addRoutes:function(t){J(t,n,o,i)}}}function Y(t,e,r){var n=e.match(t);if(!n)return!1;if(!r)return!0;for(var o=1,i=n.length;o<i;++o){var a=t.keys[o-1],c="string"==typeof n[o]?decodeURIComponent(n[o]):n[o];a&&(r[a.name||"pathMatch"]=c)}return!0}var W=K&&window.performance&&window.performance.now?window.performance:Date;function G(){return W.now().toFixed(3)}var Z=G();function tt(){return Z}function et(t){return Z=t}var rt=Object.create(null);function nt(){var t=window.location.protocol+"//"+window.location.host,e=window.location.href.replace(t,"");window.history.replaceState({key:tt()},"",e),window.addEventListener("popstate",function(t){it(),t.state&&t.state.key&&et(t.state.key)})}function ot(t,e,r,n){if(t.app){var o=t.options.scrollBehavior;o&&t.app.$nextTick(function(){var i=function(){var t=tt();if(t)return rt[t]}(),a=o.call(t,e,r,n?i:null);a&&("function"==typeof a.then?a.then(function(t){pt(t,i)}).catch(function(t){}):pt(a,i))})}}function it(){var t=tt();t&&(rt[t]={x:window.pageXOffset,y:window.pageYOffset})}function at(t){return ut(t.x)||ut(t.y)}function ct(t){return{x:ut(t.x)?t.x:window.pageXOffset,y:ut(t.y)?t.y:window.pageYOffset}}function ut(t){return"number"==typeof t}var st=/^#\d/;function pt(t,e){var r,n="object"==typeof t;if(n&&"string"==typeof t.selector){var o=st.test(t.selector)?document.getElementById(t.selector.slice(1)):document.querySelector(t.selector);if(o){var i=t.offset&&"object"==typeof t.offset?t.offset:{};e=function(t,e){var r=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-r.left-e.x,y:n.top-r.top-e.y}}(o,i={x:ut((r=i).x)?r.x:0,y:ut(r.y)?r.y:0})}else at(t)&&(e=ct(t))}else n&&at(t)&&(e=ct(t));e&&window.scrollTo(e.x,e.y)}var ft,ht=K&&(-1===(ft=window.navigator.userAgent).indexOf("Android 2.")&&-1===ft.indexOf("Android 4.0")||-1===ft.indexOf("Mobile Safari")||-1!==ft.indexOf("Chrome")||-1!==ft.indexOf("Windows Phone"))&&window.history&&"pushState"in window.history;function lt(t,e){it();var r=window.history;try{e?r.replaceState({key:tt()},"",t):r.pushState({key:et(G())},"",t)}catch(r){window.location[e?"replace":"assign"](t)}}function dt(t){lt(t,!0)}function vt(t,e,r){var n=function(o){o>=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}function yt(e){return function(r,n,o){var i=!1,a=0,c=null;mt(e,function(e,r,n,u){if("function"==typeof e&&void 0===e.cid){i=!0,a++;var s,p=wt(function(t){var r;((r=t).__esModule||bt&&"Module"===r[Symbol.toStringTag])&&(t=t.default),e.resolved="function"==typeof t?t:B.extend(t),n.components[u]=t,--a<=0&&o()}),f=wt(function(e){var r="Failed to resolve async component "+u+": "+e;c||(c=t(e)?e:new Error(r),o(c))});try{s=e(p,f)}catch(t){f(t)}if(s)if("function"==typeof s.then)s.then(p,f);else{var h=s.component;h&&"function"==typeof h.then&&h.then(p,f)}}}),i||o()}}function mt(t,e){return gt(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function gt(t){return Array.prototype.concat.apply([],t)}var bt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function wt(t){var e=!1;return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}var xt=function(t){function e(e){t.call(this),this.name=this._name="NavigationDuplicated",this.message='Navigating to current location ("'+e.fullPath+'") is not allowed',Object.defineProperty(this,"stack",{value:(new t).stack,writable:!0,configurable:!0})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Error);xt._name="NavigationDuplicated";var kt=function(t,e){this.router=t,this.base=function(t){if(!t)if(K){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}(e),this.current=d,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};function Rt(t,e,r,n){var o=mt(t,function(t,n,o,i){var a=function(t,e){return"function"!=typeof t&&(t=B.extend(t)),t.options[e]}(t,e);if(a)return Array.isArray(a)?a.map(function(t){return r(t,n,o,i)}):r(a,n,o,i)});return gt(n?o.reverse():o)}function Et(t,e){if(e)return function(){return t.apply(e,arguments)}}kt.prototype.listen=function(t){this.cb=t},kt.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},kt.prototype.onError=function(t){this.errorCbs.push(t)},kt.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(t){r&&r(t),t&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(e){e(t)}))})},kt.prototype.confirmTransition=function(r,n,o){var i=this,a=this.current,c=function(r){!e(xt,r)&&t(r)&&(i.errorCbs.length?i.errorCbs.forEach(function(t){t(r)}):console.error(r)),o&&o(r)};if(m(r,a)&&r.matched.length===a.matched.length)return this.ensureURL(),c(new xt(r));var u=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r<n&&t[r]===e[r];r++);return{updated:e.slice(0,r),activated:e.slice(r),deactivated:t.slice(r)}}(this.current.matched,r.matched),s=u.updated,p=u.deactivated,f=u.activated,h=[].concat(function(t){return Rt(t,"beforeRouteLeave",Et,!0)}(p),this.router.beforeHooks,function(t){return Rt(t,"beforeRouteUpdate",Et)}(s),f.map(function(t){return t.beforeEnter}),yt(f));this.pending=r;var l=function(e,n){if(i.pending!==r)return c();try{e(r,a,function(e){!1===e||t(e)?(i.ensureURL(!0),c(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(c(),"object"==typeof e&&e.replace?i.replace(e):i.push(e)):n(e)})}catch(t){c(t)}};vt(h,l,function(){var t=[];vt(function(t,e,r){return Rt(t,"beforeRouteEnter",function(t,n,o,i){return function(t,e,r,n,o){return function(i,a,c){return t(i,a,function(t){"function"==typeof t&&n.push(function(){!function t(e,r,n,o){r[n]&&!r[n]._isBeingDestroyed?e(r[n]):o()&&setTimeout(function(){t(e,r,n,o)},16)}(t,e.instances,r,o)}),c(t)})}}(t,o,i,e,r)})}(f,t,function(){return i.current===r}).concat(i.router.resolveHooks),l,function(){if(i.pending!==r)return c();i.pending=null,n(r),i.router.app&&i.router.app.$nextTick(function(){t.forEach(function(t){t()})})})})},kt.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(r){r&&r(t,e)})};var Ot=function(t){function e(e,r){var n=this;t.call(this,e,r);var o=e.options.scrollBehavior,i=ht&&o;i&&nt();var a=_t(this.base);window.addEventListener("popstate",function(t){var r=n.current,o=_t(n.base);n.current===d&&o===a||n.transitionTo(o,function(t){i&&ot(e,t,r,!0)})})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){lt(w(n.base+t.fullPath)),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){dt(w(n.base+t.fullPath)),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(_t(this.base)!==this.current.fullPath){var e=w(this.base+this.current.fullPath);t?lt(e):dt(e)}},e.prototype.getCurrentLocation=function(){return _t(this.base)},e}(kt);function _t(t){var e=decodeURI(window.location.pathname);return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}var At=function(t){function e(e,r,n){t.call(this,e,r),n&&function(t){var e=_t(t);if(!/^\/#/.test(e))return window.location.replace(w(t+"/#"+e)),!0}(this.base)||jt()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this,e=this.router.options.scrollBehavior,r=ht&&e;r&&nt(),window.addEventListener(ht?"popstate":"hashchange",function(){var e=t.current;jt()&&t.transitionTo(Ct(),function(n){r&&ot(t.router,n,e,!0),ht||Tt(n.fullPath)})})},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){$t(t.fullPath),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Tt(t.fullPath),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;Ct()!==e&&(t?$t(e):Tt(e))},e.prototype.getCurrentLocation=function(){return Ct()},e}(kt);function jt(){var t=Ct();return"/"===t.charAt(0)||(Tt("/"+t),!1)}function Ct(){var t=window.location.href,e=t.indexOf("#");if(e<0)return"";var r=(t=t.slice(e+1)).indexOf("?");if(r<0){var n=t.indexOf("#");t=n>-1?decodeURI(t.slice(0,n))+t.slice(n):decodeURI(t)}else r>-1&&(t=decodeURI(t.slice(0,r))+t.slice(r));return t}function St(t){var e=window.location.href,r=e.indexOf("#");return(r>=0?e.slice(0,r):e)+"#"+t}function $t(t){ht?lt(St(t)):window.location.hash=t}function Tt(t){ht?dt(St(t)):window.location.replace(St(t))}var Pt=function(t){function r(e,r){t.call(this,e,r),this.stack=[],this.index=-1}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.push=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)},r)},r.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)},r)},r.prototype.go=function(t){var r=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var o=this.stack[n];this.confirmTransition(o,function(){r.index=n,r.updateRoute(o)},function(t){e(xt,t)&&(r.index=n)})}},r.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},r.prototype.ensureURL=function(){},r}(kt),Lt=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=X(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!ht&&!1!==t.fallback,this.fallback&&(e="hash"),K||(e="abstract"),this.mode=e,e){case"history":this.history=new Ot(this,t.base);break;case"hash":this.history=new At(this,t.base,this.fallback);break;case"abstract":this.history=new Pt(this,t.base)}},qt={currentRoute:{configurable:!0}};function Ut(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}return Lt.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},qt.currentRoute.get=function(){return this.history&&this.history.current},Lt.prototype.init=function(t){var e=this;if(this.apps.push(t),t.$once("hook:destroyed",function(){var r=e.apps.indexOf(t);r>-1&&e.apps.splice(r,1),e.app===t&&(e.app=e.apps[0]||null)}),!this.app){this.app=t;var r=this.history;if(r instanceof Ot)r.transitionTo(r.getCurrentLocation());else if(r instanceof At){var n=function(){r.setupListeners()};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},Lt.prototype.beforeEach=function(t){return Ut(this.beforeHooks,t)},Lt.prototype.beforeResolve=function(t){return Ut(this.resolveHooks,t)},Lt.prototype.afterEach=function(t){return Ut(this.afterHooks,t)},Lt.prototype.onReady=function(t,e){this.history.onReady(t,e)},Lt.prototype.onError=function(t){this.history.onError(t)},Lt.prototype.push=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.push(t,e,r)});this.history.push(t,e,r)},Lt.prototype.replace=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.replace(t,e,r)});this.history.replace(t,e,r)},Lt.prototype.go=function(t){this.history.go(t)},Lt.prototype.back=function(){this.go(-1)},Lt.prototype.forward=function(){this.go(1)},Lt.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Lt.prototype.resolve=function(t,e,r){var n=V(t,e=e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:function(t,e,r){var n="hash"===r?"#"+e:e;return t?w(t+"/"+n):n}(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Lt.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==d&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Lt.prototype,qt),Lt.install=function t(e){if(!t.installed||B!==e){t.installed=!0,B=e;var r=function(t){return void 0!==t},o=function(t,e){var n=t.$options._parentVnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate:function(){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:function(){o(this)}}),Object.defineProperty(e.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get:function(){return this._routerRoot._route}}),e.component("RouterView",n),e.component("RouterLink",F);var i=e.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created}},Lt.version="3.1.3",K&&window.Kdu&&window.Kdu.use(Lt),Lt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).KduRouter=e();
1
+ /*!
2
+ * kdu-router v3.1.7
3
+ * (c) 2022 NKDuy
4
+ * @license MIT
5
+ */
6
+ /*!
7
+ * kdu-router v3.1.7
8
+ * (c) 2022 NKDuy
9
+ * @license MIT
10
+ */
11
+ var t,e;t=this,e=function(){"use strict";function t(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function e(t,e){return e instanceof t||e&&(e.name===t.name||e._name===t._name)}function r(t,e){for(var r in e)t[r]=e[r];return t}var n={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,i=e.children,a=e.parent,c=e.data;c.routerView=!0;for(var u=a.$createElement,s=n.name,p=a.$route,f=a._routerViewCache||(a._routerViewCache={}),h=0,l=!1;a&&a._routerRoot!==a;){var d=a.$knode?a.$knode.data:{};d.routerView&&h++,d.keepAlive&&a._directInactive&&a._inactive&&(l=!0),a=a.$parent}if(c.routerViewDepth=h,l){var v=f[s],y=v&&v.component;return y?(v.configProps&&o(y,c,v.route,v.configProps),u(y,c,i)):u()}var m=p.matched[h],g=m&&m.components[s];if(!m||!g)return f[s]=null,u();f[s]={component:g},c.registerRouteInstance=function(t,e){var r=m.instances[s];(e&&r!==t||!e&&r===t)&&(m.instances[s]=e)},(c.hook||(c.hook={})).prepatch=function(t,e){m.instances[s]=e.componentInstance},c.hook.init=function(t){t.data.keepAlive&&t.componentInstance&&t.componentInstance!==m.instances[s]&&(m.instances[s]=t.componentInstance)};var b=m.props&&m.props[s];return b&&(r(f[s],{route:p,configProps:b}),o(g,c,p,b)),u(g,c,i)}};function o(t,e,n,o){var i=e.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(n,o);if(i){i=e.props=r({},i);var a=e.attrs=e.attrs||{};for(var c in i)t.props&&c in t.props||(a[c]=i[c],delete i[c])}}var i=/[!'()*]/g,a=function(t){return"%"+t.charCodeAt(0).toString(16)},c=/%2C/g,u=function(t){return encodeURIComponent(t).replace(i,a).replace(c,",")},s=decodeURIComponent;function p(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach((function(t){var r=t.replace(/\+/g," ").split("="),n=s(r.shift()),o=r.length>0?s(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]})),e):e}function f(t){var e=t?Object.keys(t).map((function(e){var r=t[e];if(void 0===r)return"";if(null===r)return u(e);if(Array.isArray(r)){var n=[];return r.forEach((function(t){void 0!==t&&(null===t?n.push(u(e)):n.push(u(e)+"="+u(t)))})),n.join("&")}return u(e)+"="+u(r)})).filter((function(t){return t.length>0})).join("&"):null;return e?"?"+e:""}var h=/\/?$/;function l(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=d(i)}catch(t){}var a={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:m(e,o),matched:t?y(t):[]};return r&&(a.redirectedFrom=m(r,o)),Object.freeze(a)}function d(t){if(Array.isArray(t))return t.map(d);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=d(t[r]);return e}return t}var v=l(null,{path:"/"});function y(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function m(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;return void 0===o&&(o=""),(r||"/")+(e||f)(n)+o}function g(t,e){return e===v?t===e:!!e&&(t.path&&e.path?t.path.replace(h,"")===e.path.replace(h,"")&&t.hash===e.hash&&b(t.query,e.query):!(!t.name||!e.name)&&t.name===e.name&&t.hash===e.hash&&b(t.query,e.query)&&b(t.params,e.params))}function b(t,e){if(void 0===t&&(t={}),void 0===e&&(e={}),!t||!e)return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every((function(r){var n=t[r],o=e[r];return"object"==typeof n&&"object"==typeof o?b(n,o):String(n)===String(o)}))}function w(t,e,r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;var o=e.split("/");r&&o[o.length-1]||o.pop();for(var i=t.replace(/^\//,"").split("/"),a=0;a<i.length;a++){var c=i[a];".."===c?o.pop():"."!==c&&o.push(c)}return""!==o[0]&&o.unshift(""),o.join("/")}function x(t){return t.replace(/\/\//g,"/")}var k=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},R=I,E=C,O=function(t,e){return $(C(t,e),e)},_=$,A=U,j=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function C(t,e){for(var r,n=[],o=0,i=0,a="",c=e&&e.delimiter||"/";null!=(r=j.exec(t));){var u=r[0],s=r[1],p=r.index;if(a+=t.slice(i,p),i=p+u.length,s)a+=s[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],v=r[5],y=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,b="+"===y||"*"===y,w="?"===y||"*"===y,x=r[2]||c,k=d||v;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:w,repeat:b,partial:g,asterisk:!!m,pattern:k?P(k):m?".*":"[^"+T(x)+"]+?"})}}return i<t.length&&(a+=t.substr(i)),a&&n.push(a),n}function S(t){return encodeURI(t).replace(/[\/?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}))}function $(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(r[n]=new RegExp("^(?:"+t[n].pattern+")$",q(e)));return function(e,n){for(var o="",i=e||{},a=(n||{}).pretty?S:encodeURIComponent,c=0;c<t.length;c++){var u=t[c];if("string"!=typeof u){var s,p=i[u.name];if(null==p){if(u.optional){u.partial&&(o+=u.prefix);continue}throw new TypeError('Expected "'+u.name+'" to be defined')}if(k(p)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but received `'+JSON.stringify(p)+"`");if(0===p.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var f=0;f<p.length;f++){if(s=a(p[f]),!r[c].test(s))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'", but received `'+JSON.stringify(s)+"`");o+=(0===f?u.prefix:u.delimiter)+s}}else{if(s=u.asterisk?encodeURI(p).replace(/[?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})):a(p),!r[c].test(s))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but received "'+s+'"');o+=u.prefix+s}}else o+=u}return o}}function T(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function P(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function L(t,e){return t.keys=e,t}function q(t){return t&&t.sensitive?"":"i"}function U(t,e,r){k(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,o=!1!==r.end,i="",a=0;a<t.length;a++){var c=t[a];if("string"==typeof c)i+=T(c);else{var u=T(c.prefix),s="(?:"+c.pattern+")";e.push(c),c.repeat&&(s+="(?:"+u+s+")*"),i+=s=c.optional?c.partial?u+"("+s+")?":"(?:"+u+"("+s+"))?":u+"("+s+")"}}var p=T(r.delimiter||"/"),f=i.slice(-p.length)===p;return n||(i=(f?i.slice(0,-p.length):i)+"(?:"+p+"(?=$))?"),i+=o?"$":n&&f?"":"(?="+p+"|$)",L(new RegExp("^"+i,q(r)),e)}function I(t,e,r){return k(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp?function(t,e){var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return L(t,e)}(t,e):k(t)?function(t,e,r){for(var n=[],o=0;o<t.length;o++)n.push(I(t[o],e,r).source);return L(new RegExp("(?:"+n.join("|")+")",q(r)),e)}(t,e,r):function(t,e,r){return U(C(t,r),e,r)}(t,e,r)}R.parse=E,R.compile=O,R.tokensToFunction=_,R.tokensToRegExp=A;var M=Object.create(null);function B(t,e,r){e=e||{};try{var n=M[t]||(M[t]=R.compile(t));return"string"==typeof e.pathMatch&&(e[0]=e.pathMatch),n(e,{pretty:!0})}catch(t){return""}finally{delete e[0]}}function H(t,e,n,o){var i="string"==typeof t?{path:t}:t;if(i._normalized)return i;if(i.name){var a=(i=r({},t)).params;return a&&"object"==typeof a&&(i.params=r({},a)),i}if(!i.path&&i.params&&e){(i=r({},i))._normalized=!0;var c=r(r({},e.params),i.params);if(e.name)i.name=e.name,i.params=c;else if(e.matched.length){var u=e.matched[e.matched.length-1].path;i.path=B(u,c,e.path)}return i}var s=function(t){var e="",r="",n=t.indexOf("#");n>=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}(i.path||""),f=e&&e.path||"/",h=s.path?w(s.path,f,n||i.append):f,l=function(t,e,r){void 0===e&&(e={});var n,o=r||p;try{n=o(t||"")}catch(t){n={}}for(var i in e)n[i]=e[i];return n}(s.query,i.query,o&&o.options.parseQuery),d=i.hash||s.hash;return d&&"#"!==d.charAt(0)&&(d="#"+d),{_normalized:!0,path:h,query:l,hash:d}}var z,K=function(){},D={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:function(t){var e=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,c=i.route,u=i.href,s={},p=n.options.linkActiveClass,f=n.options.linkExactActiveClass,d=null==p?"router-link-active":p,v=null==f?"router-link-exact-active":f,y=null==this.activeClass?d:this.activeClass,m=null==this.exactActiveClass?v:this.exactActiveClass,b=c.redirectedFrom?l(null,H(c.redirectedFrom),null,n):c;s[m]=g(o,b),s[y]=this.exact?s[m]:function(t,e){return 0===t.path.replace(h,"/").indexOf(e.path.replace(h,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}(o,b);var w=function(t){F(t)&&(e.replace?n.replace(a,K):n.push(a,K))},x={click:F};Array.isArray(this.event)?this.event.forEach((function(t){x[t]=w})):x[this.event]=w;var k={class:s},R=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:u,route:c,navigate:w,isActive:s[y],isExactActive:s[m]});if(R){if(1===R.length)return R[0];if(R.length>1||!R.length)return 0===R.length?t():t("span",{},R)}if("a"===this.tag)k.on=x,k.attrs={href:u};else{var E=function t(e){var r;if(e)for(var n=0;n<e.length;n++){if("a"===(r=e[n]).tag)return r;if(r.children&&(r=t(r.children)))return r}}(this.$slots.default);if(E){E.isStatic=!1;var O=E.data=r({},E.data);for(var _ in O.on=O.on||{},O.on){var A=O.on[_];_ in x&&(O.on[_]=Array.isArray(A)?A:[A])}for(var j in x)j in O.on?O.on[j].push(x[j]):O.on[j]=w;(E.data.attrs=r({},E.data.attrs)).href=u}else k.on=x}return t(this.tag,k,this.$slots.default)}};function F(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}var V="undefined"!=typeof window;function N(t,e,r,n){var o=e||[],i=r||Object.create(null),a=n||Object.create(null);t.forEach((function(t){!function t(e,r,n,o,i,a){var c=o.path,u=o.name,s=o.pathToRegexpOptions||{},p=function(t,e,r){return r||(t=t.replace(/\/$/,"")),"/"===t[0]||null==e?t:x(e.path+"/"+t)}(c,i,s.strict);"boolean"==typeof o.caseSensitive&&(s.sensitive=o.caseSensitive);var f={path:p,regex:J(p,s),components:o.components||{default:o.component},instances:{},name:u,parent:i,matchAs:a,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};if(o.children&&o.children.forEach((function(o){var i=a?x(a+"/"+o.path):void 0;t(e,r,n,o,f,i)})),r[f.path]||(e.push(f.path),r[f.path]=f),void 0!==o.alias)for(var h=Array.isArray(o.alias)?o.alias:[o.alias],l=0;l<h.length;++l){var d={path:h[l],children:o.children};t(e,r,n,d,i,f.path||"/")}u&&(n[u]||(n[u]=f))}(o,i,a,t)}));for(var c=0,u=o.length;c<u;c++)"*"===o[c]&&(o.push(o.splice(c,1)[0]),u--,c--);return{pathList:o,pathMap:i,nameMap:a}}function J(t,e){return R(t,[],e)}function Q(t,e){var r=N(t),n=r.pathList,o=r.pathMap,i=r.nameMap;function a(t,r,a){var c=H(t,r,!1,e),s=c.name;if(s){var p=i[s];if(!p)return u(null,c);var f=p.regex.keys.filter((function(t){return!t.optional})).map((function(t){return t.name}));if("object"!=typeof c.params&&(c.params={}),r&&"object"==typeof r.params)for(var h in r.params)!(h in c.params)&&f.indexOf(h)>-1&&(c.params[h]=r.params[h]);return c.path=B(p.path,c.params),u(p,c,a)}if(c.path){c.params={};for(var l=0;l<n.length;l++){var d=n[l],v=o[d];if(X(v.regex,c.path,c.params))return u(v,c,a)}}return u(null,c)}function c(t,r){var n=t.redirect,o="function"==typeof n?n(l(t,r,null,e)):n;if("string"==typeof o&&(o={path:o}),!o||"object"!=typeof o)return u(null,r);var c=o,s=c.name,p=c.path,f=r.query,h=r.hash,d=r.params;return f=c.hasOwnProperty("query")?c.query:f,h=c.hasOwnProperty("hash")?c.hash:h,d=c.hasOwnProperty("params")?c.params:d,s?(i[s],a({_normalized:!0,name:s,query:f,hash:h,params:d},void 0,r)):p?a({_normalized:!0,path:B(function(t,e){return w(t,e.parent?e.parent.path:"/",!0)}(p,t),d),query:f,hash:h},void 0,r):u(null,r)}function u(t,r,n){return t&&t.redirect?c(t,n||r):t&&t.matchAs?function(t,e,r){var n=a({_normalized:!0,path:B(r,e.params)});if(n){var o=n.matched,i=o[o.length-1];return e.params=n.params,u(i,e)}return u(null,e)}(0,r,t.matchAs):l(t,r,n,e)}return{match:a,addRoutes:function(t){N(t,n,o,i)}}}function X(t,e,r){var n=e.match(t);if(!n)return!1;if(!r)return!0;for(var o=1,i=n.length;o<i;++o){var a=t.keys[o-1],c="string"==typeof n[o]?decodeURIComponent(n[o]):n[o];a&&(r[a.name||"pathMatch"]=c)}return!0}var Y=V&&window.performance&&window.performance.now?window.performance:Date;function W(){return Y.now().toFixed(3)}var G=W();function Z(){return G}function tt(t){return G=t}var et=Object.create(null);function rt(){var t=window.location.protocol+"//"+window.location.host,e=window.location.href.replace(t,""),n=r({},window.history.state);n.key=Z(),window.history.replaceState(n,"",e),window.addEventListener("popstate",(function(t){ot(),t.state&&t.state.key&&tt(t.state.key)}))}function nt(t,e,r,n){if(t.app){var o=t.options.scrollBehavior;o&&t.app.$nextTick((function(){var i=function(){var t=Z();if(t)return et[t]}(),a=o.call(t,e,r,n?i:null);a&&("function"==typeof a.then?a.then((function(t){st(t,i)})).catch((function(t){})):st(a,i))}))}}function ot(){var t=Z();t&&(et[t]={x:window.pageXOffset,y:window.pageYOffset})}function it(t){return ct(t.x)||ct(t.y)}function at(t){return{x:ct(t.x)?t.x:window.pageXOffset,y:ct(t.y)?t.y:window.pageYOffset}}function ct(t){return"number"==typeof t}var ut=/^#\d/;function st(t,e){var r,n="object"==typeof t;if(n&&"string"==typeof t.selector){var o=ut.test(t.selector)?document.getElementById(t.selector.slice(1)):document.querySelector(t.selector);if(o){var i=t.offset&&"object"==typeof t.offset?t.offset:{};e=function(t,e){var r=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-r.left-e.x,y:n.top-r.top-e.y}}(o,i={x:ct((r=i).x)?r.x:0,y:ct(r.y)?r.y:0})}else it(t)&&(e=at(t))}else n&&it(t)&&(e=at(t));e&&window.scrollTo(e.x,e.y)}var pt,ft=V&&(-1===(pt=window.navigator.userAgent).indexOf("Android 2.")&&-1===pt.indexOf("Android 4.0")||-1===pt.indexOf("Mobile Safari")||-1!==pt.indexOf("Chrome")||-1!==pt.indexOf("Windows Phone"))&&window.history&&"pushState"in window.history;function ht(t,e){ot();var n=window.history;try{if(e){var o=r({},n.state);o.key=Z(),n.replaceState(o,"",t)}else n.pushState({key:tt(W())},"",t)}catch(r){window.location[e?"replace":"assign"](t)}}function lt(t){ht(t,!0)}function dt(t,e,r){var n=function(o){o>=t.length?r():t[o]?e(t[o],(function(){n(o+1)})):n(o+1)};n(0)}function vt(e){return function(r,n,o){var i=!1,a=0,c=null;yt(e,(function(e,r,n,u){if("function"==typeof e&&void 0===e.cid){i=!0,a++;var s,p=bt((function(t){var r;((r=t).__esModule||gt&&"Module"===r[Symbol.toStringTag])&&(t=t.default),e.resolved="function"==typeof t?t:z.extend(t),n.components[u]=t,--a<=0&&o()})),f=bt((function(e){var r="Failed to resolve async component "+u+": "+e;c||(c=t(e)?e:new Error(r),o(c))}));try{s=e(p,f)}catch(t){f(t)}if(s)if("function"==typeof s.then)s.then(p,f);else{var h=s.component;h&&"function"==typeof h.then&&h.then(p,f)}}})),i||o()}}function yt(t,e){return mt(t.map((function(t){return Object.keys(t.components).map((function(r){return e(t.components[r],t.instances[r],t,r)}))})))}function mt(t){return Array.prototype.concat.apply([],t)}var gt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function bt(t){var e=!1;return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}var wt=function(t){function e(e){t.call(this),this.name=this._name="NavigationDuplicated",this.message='Navigating to current location ("'+e.fullPath+'") is not allowed',Object.defineProperty(this,"stack",{value:(new t).stack,writable:!0,configurable:!0})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Error);wt._name="NavigationDuplicated";var xt=function(t,e){this.router=t,this.base=function(t){if(!t)if(V){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}(e),this.current=v,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};function kt(t,e,r,n){var o=yt(t,(function(t,n,o,i){var a=function(t,e){return"function"!=typeof t&&(t=z.extend(t)),t.options[e]}(t,e);if(a)return Array.isArray(a)?a.map((function(t){return r(t,n,o,i)})):r(a,n,o,i)}));return mt(n?o.reverse():o)}function Rt(t,e){if(e)return function(){return t.apply(e,arguments)}}xt.prototype.listen=function(t){this.cb=t},xt.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},xt.prototype.onError=function(t){this.errorCbs.push(t)},xt.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,(function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach((function(t){t(o)})))}),(function(t){r&&r(t),t&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach((function(e){e(t)})))}))},xt.prototype.confirmTransition=function(r,n,o){var i=this,a=this.current,c=function(r){!e(wt,r)&&t(r)&&(i.errorCbs.length?i.errorCbs.forEach((function(t){t(r)})):console.error(r)),o&&o(r)};if(g(r,a)&&r.matched.length===a.matched.length)return this.ensureURL(),c(new wt(r));var u=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r<n&&t[r]===e[r];r++);return{updated:e.slice(0,r),activated:e.slice(r),deactivated:t.slice(r)}}(this.current.matched,r.matched),s=u.updated,p=u.deactivated,f=u.activated,h=[].concat(function(t){return kt(t,"beforeRouteLeave",Rt,!0)}(p),this.router.beforeHooks,function(t){return kt(t,"beforeRouteUpdate",Rt)}(s),f.map((function(t){return t.beforeEnter})),vt(f));this.pending=r;var l=function(e,n){if(i.pending!==r)return c();try{e(r,a,(function(e){!1===e||t(e)?(i.ensureURL(!0),c(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(c(),"object"==typeof e&&e.replace?i.replace(e):i.push(e)):n(e)}))}catch(t){c(t)}};dt(h,l,(function(){var t=[];dt(function(t,e,r){return kt(t,"beforeRouteEnter",(function(t,n,o,i){return function(t,e,r,n,o){return function(i,a,c){return t(i,a,(function(t){"function"==typeof t&&n.push((function(){!function t(e,r,n,o){r[n]&&!r[n]._isBeingDestroyed?e(r[n]):o()&&setTimeout((function(){t(e,r,n,o)}),16)}(t,e.instances,r,o)})),c(t)}))}}(t,o,i,e,r)}))}(f,t,(function(){return i.current===r})).concat(i.router.resolveHooks),l,(function(){if(i.pending!==r)return c();i.pending=null,n(r),i.router.app&&i.router.app.$nextTick((function(){t.forEach((function(t){t()}))}))}))}))},xt.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach((function(r){r&&r(t,e)}))};var Et=function(t){function e(e,r){var n=this;t.call(this,e,r);var o=e.options.scrollBehavior,i=ft&&o;i&&rt();var a=Ot(this.base);window.addEventListener("popstate",(function(t){var r=n.current,o=Ot(n.base);n.current===v&&o===a||n.transitionTo(o,(function(t){i&&nt(e,t,r,!0)}))}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){ht(x(n.base+t.fullPath)),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){lt(x(n.base+t.fullPath)),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.ensureURL=function(t){if(Ot(this.base)!==this.current.fullPath){var e=x(this.base+this.current.fullPath);t?ht(e):lt(e)}},e.prototype.getCurrentLocation=function(){return Ot(this.base)},e}(xt);function Ot(t){var e=decodeURI(window.location.pathname);return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}var _t=function(t){function e(e,r,n){t.call(this,e,r),n&&function(t){var e=Ot(t);if(!/^\/#/.test(e))return window.location.replace(x(t+"/#"+e)),!0}(this.base)||At()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this,e=this.router.options.scrollBehavior,r=ft&&e;r&&rt(),window.addEventListener(ft?"popstate":"hashchange",(function(){var e=t.current;At()&&t.transitionTo(jt(),(function(n){r&&nt(t.router,n,e,!0),ft||$t(n.fullPath)}))}))},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){St(t.fullPath),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){$t(t.fullPath),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;jt()!==e&&(t?St(e):$t(e))},e.prototype.getCurrentLocation=function(){return jt()},e}(xt);function At(){var t=jt();return"/"===t.charAt(0)||($t("/"+t),!1)}function jt(){var t=window.location.href,e=t.indexOf("#");if(e<0)return"";var r=(t=t.slice(e+1)).indexOf("?");if(r<0){var n=t.indexOf("#");t=n>-1?decodeURI(t.slice(0,n))+t.slice(n):decodeURI(t)}else t=decodeURI(t.slice(0,r))+t.slice(r);return t}function Ct(t){var e=window.location.href,r=e.indexOf("#");return(r>=0?e.slice(0,r):e)+"#"+t}function St(t){ft?ht(Ct(t)):window.location.hash=t}function $t(t){ft?lt(Ct(t)):window.location.replace(Ct(t))}var Tt=function(t){function r(e,r){t.call(this,e,r),this.stack=[],this.index=-1}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.push=function(t,e,r){var n=this;this.transitionTo(t,(function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)}),r)},r.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,(function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)}),r)},r.prototype.go=function(t){var r=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var o=this.stack[n];this.confirmTransition(o,(function(){r.index=n,r.updateRoute(o)}),(function(t){e(wt,t)&&(r.index=n)}))}},r.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},r.prototype.ensureURL=function(){},r}(xt),Pt=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=Q(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!ft&&!1!==t.fallback,this.fallback&&(e="hash"),V||(e="abstract"),this.mode=e,e){case"history":this.history=new Et(this,t.base);break;case"hash":this.history=new _t(this,t.base,this.fallback);break;case"abstract":this.history=new Tt(this,t.base)}},Lt={currentRoute:{configurable:!0}};function qt(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}return Pt.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},Lt.currentRoute.get=function(){return this.history&&this.history.current},Pt.prototype.init=function(t){var e=this;if(this.apps.push(t),t.$once("hook:destroyed",(function(){var r=e.apps.indexOf(t);r>-1&&e.apps.splice(r,1),e.app===t&&(e.app=e.apps[0]||null)})),!this.app){this.app=t;var r=this.history;if(r instanceof Et)r.transitionTo(r.getCurrentLocation());else if(r instanceof _t){var n=function(){r.setupListeners()};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen((function(t){e.apps.forEach((function(e){e._route=t}))}))}},Pt.prototype.beforeEach=function(t){return qt(this.beforeHooks,t)},Pt.prototype.beforeResolve=function(t){return qt(this.resolveHooks,t)},Pt.prototype.afterEach=function(t){return qt(this.afterHooks,t)},Pt.prototype.onReady=function(t,e){this.history.onReady(t,e)},Pt.prototype.onError=function(t){this.history.onError(t)},Pt.prototype.push=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise((function(e,r){n.history.push(t,e,r)}));this.history.push(t,e,r)},Pt.prototype.replace=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise((function(e,r){n.history.replace(t,e,r)}));this.history.replace(t,e,r)},Pt.prototype.go=function(t){this.history.go(t)},Pt.prototype.back=function(){this.go(-1)},Pt.prototype.forward=function(){this.go(1)},Pt.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map((function(t){return Object.keys(t.components).map((function(e){return t.components[e]}))}))):[]},Pt.prototype.resolve=function(t,e,r){var n=H(t,e=e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:function(t,e,r){var n="hash"===r?"#"+e:e;return t?x(t+"/"+n):n}(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Pt.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==v&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Pt.prototype,Lt),Pt.install=function t(e){if(!t.installed||z!==e){t.installed=!0,z=e;var r=function(t){return void 0!==t},o=function(t,e){var n=t.$options._parentKnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate:function(){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:function(){o(this)}}),Object.defineProperty(e.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get:function(){return this._routerRoot._route}}),e.component("RouterView",n),e.component("RouterLink",D);var i=e.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created}},Pt.version="3.1.7",V&&window.Kdu&&window.Kdu.use(Pt),Pt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).KduRouter=e();
package/package.json CHANGED
@@ -1,107 +1,81 @@
1
- {
2
- "name": "kdu-router",
3
- "version": "3.1.3",
4
- "description": "Official router for Kdu",
5
- "author": "NKDuy",
6
- "license": "MIT",
7
- "main": "dist/kdu-router.common.js",
8
- "module": "dist/kdu-router.esm.js",
9
- "unpkg": "dist/kdu-router.js",
10
- "jsdelivr": "dist/kdu-router.js",
11
- "sideEffects": false,
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/khanhduy1407/kdu-router.git"
15
- },
16
- "typings": "types/index.d.ts",
17
- "files": [
18
- "src/*.js",
19
- "dist/*.js",
20
- "types/*.d.ts"
21
- ],
22
- "keywords": [
23
- "kdu",
24
- "router",
25
- "routing"
26
- ],
27
- "scripts": {
28
- "dev": "node examples/server.js",
29
- "dev:dist": "rollup -wm -c build/rollup.dev.config.js",
30
- "build": "node build/build.js",
31
- "lint": "eslint src examples test",
32
- "test": "npm run lint && npm run flow && npm run test:unit && npm run test:e2e && npm run test:types",
33
- "flow": "flow check",
34
- "test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
35
- "test:e2e": "node test/e2e/runner.js",
36
- "test:e2e:ci": "node test/e2e/runner.js --local -e ie,android44 -c test/e2e/nightwatch.browserstack.js test/e2e/specs/active-links.js",
37
- "test:e2e:ff": "node test/e2e/runner.js -e firefox -c test/e2e/nightwatch.config.js",
38
- "test:e2e:ie9": "node test/e2e/runner.js --local -e ie9 -c test/e2e/nightwatch.browserstack.js --skiptags history,ie9-fail",
39
- "test:types": "tsc -p types/test",
40
- "docs": "kdupress dev docs",
41
- "docs:build": "kdupress build docs",
42
- "changelog": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s",
43
- "release": "bash scripts/release.sh"
44
- },
45
- "gitHooks": {
46
- "pre-commit": "lint-staged",
47
- "commit-msg": "node scripts/verifyCommitMsg.js"
48
- },
49
- "lint-staged": {
50
- "*.{js,kdu}": [
51
- "eslint --fix",
52
- "git add"
53
- ]
54
- },
55
- "devDependencies": {
56
- "axios": "^0.19.0",
57
- "babel-core": "^6.24.1",
58
- "babel-eslint": "^10.0.2",
59
- "babel-loader": "^7.1.3",
60
- "babel-plugin-syntax-dynamic-import": "^6.18.0",
61
- "babel-preset-env": "^1.6.1",
62
- "babel-preset-flow-kdu": "^1.0.0",
63
- "browserstack-local": "^1.4.0",
64
- "buble": "^0.19.8",
65
- "chromedriver": "^76.0.0",
66
- "conventional-changelog-cli": "^2.0.11",
67
- "cross-spawn": "^6.0.5",
68
- "css-loader": "^2.1.1",
69
- "dotenv": "^8.0.0",
70
- "es6-promise": "^4.2.8",
71
- "eslint": "^4.19.1",
72
- "eslint-plugin-flowtype": "^2.46.1",
73
- "eslint-plugin-jasmine": "^2.10.1",
74
- "eslint-plugin-kdu-libs": "^3.0.0",
75
- "express": "^4.17.1",
76
- "express-urlrewrite": "^1.2.0",
77
- "flow-bin": "^0.66.0",
78
- "geckodriver": "^1.16.2",
79
- "jasmine": "2.8.0",
80
- "lint-staged": "^8.2.0",
81
- "nightwatch": "^1.1.13",
82
- "nightwatch-helpers": "^1.0.0",
83
- "path-to-regexp": "^1.7.0",
84
- "rollup": "^1.20.1",
85
- "rollup-plugin-buble": "^0.19.8",
86
- "rollup-plugin-commonjs": "^10.0.2",
87
- "rollup-plugin-flow-no-whitespace": "^1.0.0",
88
- "rollup-plugin-node-resolve": "^5.2.0",
89
- "rollup-plugin-replace": "^2.0.0",
90
- "rollup-watch": "^4.0.0",
91
- "selenium-server": "^3.141.59",
92
- "terser": "^4.2.0",
93
- "typescript": "^3.5.2",
94
- "kdu": "^2.5.17",
95
- "kdu-loader": "^13.5.0",
96
- "kdu-template-compiler": "^2.5.17",
97
- "kdupress": "^1.5.1",
98
- "@nkduy/theme-kdu": "^1.5.1",
99
- "webpack": "^4.35.2",
100
- "webpack-dev-middleware": "^3.7.0",
101
- "yorkie": "^2.0.0"
102
- },
103
- "bugs": {
104
- "url": "https://github.com/khanhduy1407/kdu-router/issues"
105
- },
106
- "homepage": "https://github.com/khanhduy1407/kdu-router#readme"
107
- }
1
+ {
2
+ "name": "kdu-router",
3
+ "version": "3.1.7",
4
+ "description": "Official router for Kdu.js 2",
5
+ "author": "NKDuy",
6
+ "license": "MIT",
7
+ "main": "dist/kdu-router.common.js",
8
+ "module": "dist/kdu-router.esm.js",
9
+ "unpkg": "dist/kdu-router.js",
10
+ "jsdelivr": "dist/kdu-router.js",
11
+ "sideEffects": false,
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/kdujs/kdu-router.git"
15
+ },
16
+ "typings": "types/index.d.ts",
17
+ "files": [
18
+ "src",
19
+ "dist/*.js",
20
+ "types/*.d.ts"
21
+ ],
22
+ "keywords": [
23
+ "kdu",
24
+ "router",
25
+ "routing"
26
+ ],
27
+ "scripts": {
28
+ "dev:dist": "rollup -wm -c build/rollup.dev.config.js",
29
+ "build": "node build/build.js",
30
+ "lint": "eslint src",
31
+ "release": "bash scripts/release.sh"
32
+ },
33
+ "gitHooks": {
34
+ "commit-msg": "node scripts/verifyCommitMsg.js"
35
+ },
36
+ "devDependencies": {
37
+ "axios": "^0.19.0",
38
+ "babel-core": "^6.24.1",
39
+ "babel-eslint": "^10.0.2",
40
+ "babel-loader": "^7.1.3",
41
+ "babel-plugin-syntax-dynamic-import": "^6.18.0",
42
+ "babel-preset-env": "^1.6.1",
43
+ "babel-preset-flow-kdu": "^1.0.0",
44
+ "browserstack-local": "^1.4.0",
45
+ "buble": "^0.19.8",
46
+ "chromedriver": "^79.0.0",
47
+ "cross-spawn": "^6.0.5",
48
+ "css-loader": "^2.1.1",
49
+ "dotenv": "^8.0.0",
50
+ "es6-promise": "^4.2.8",
51
+ "eslint": "^4.19.1",
52
+ "eslint-plugin-flowtype": "^2.46.1",
53
+ "eslint-plugin-jasmine": "^2.10.1",
54
+ "eslint-plugin-kdu-libs": "^2.1.0",
55
+ "express": "^4.17.1",
56
+ "express-urlrewrite": "^1.2.0",
57
+ "flow-bin": "^0.66.0",
58
+ "geckodriver": "^1.16.2",
59
+ "jasmine": "2.8.0",
60
+ "kdu": "^2.5.24",
61
+ "lint-staged": "^8.2.0",
62
+ "path-to-regexp": "^1.7.0",
63
+ "rollup": "^1.20.1",
64
+ "rollup-plugin-buble": "^0.19.8",
65
+ "rollup-plugin-commonjs": "^10.0.2",
66
+ "rollup-plugin-flow-no-whitespace": "^1.0.0",
67
+ "rollup-plugin-node-resolve": "^5.2.0",
68
+ "rollup-plugin-replace": "^2.0.0",
69
+ "rollup-watch": "^4.0.0",
70
+ "selenium-server": "^3.141.59",
71
+ "terser": "^4.2.0",
72
+ "typescript": "^3.5.2",
73
+ "webpack": "^4.35.2",
74
+ "webpack-dev-middleware": "^3.7.0",
75
+ "yorkie": "^2.0.0"
76
+ },
77
+ "bugs": {
78
+ "url": "https://github.com/kdujs/kdu-router/issues"
79
+ },
80
+ "homepage": "https://github.com/kdujs/kdu-router#readme"
81
+ }
@@ -0,0 +1,190 @@
1
+ /* @flow */
2
+
3
+ import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
4
+ import { extend } from '../util/misc'
5
+ import { normalizeLocation } from '../util/location'
6
+ import { warn } from '../util/warn'
7
+
8
+ // work around weird flow bug
9
+ const toTypes: Array<Function> = [String, Object]
10
+ const eventTypes: Array<Function> = [String, Array]
11
+
12
+ const noop = () => {}
13
+
14
+ export default {
15
+ name: 'RouterLink',
16
+ props: {
17
+ to: {
18
+ type: toTypes,
19
+ required: true
20
+ },
21
+ tag: {
22
+ type: String,
23
+ default: 'a'
24
+ },
25
+ exact: Boolean,
26
+ append: Boolean,
27
+ replace: Boolean,
28
+ activeClass: String,
29
+ exactActiveClass: String,
30
+ event: {
31
+ type: eventTypes,
32
+ default: 'click'
33
+ }
34
+ },
35
+ render (h: Function) {
36
+ const router = this.$router
37
+ const current = this.$route
38
+ const { location, route, href } = router.resolve(
39
+ this.to,
40
+ current,
41
+ this.append
42
+ )
43
+
44
+ const classes = {}
45
+ const globalActiveClass = router.options.linkActiveClass
46
+ const globalExactActiveClass = router.options.linkExactActiveClass
47
+ // Support global empty active class
48
+ const activeClassFallback =
49
+ globalActiveClass == null ? 'router-link-active' : globalActiveClass
50
+ const exactActiveClassFallback =
51
+ globalExactActiveClass == null
52
+ ? 'router-link-exact-active'
53
+ : globalExactActiveClass
54
+ const activeClass =
55
+ this.activeClass == null ? activeClassFallback : this.activeClass
56
+ const exactActiveClass =
57
+ this.exactActiveClass == null
58
+ ? exactActiveClassFallback
59
+ : this.exactActiveClass
60
+
61
+ const compareTarget = route.redirectedFrom
62
+ ? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
63
+ : route
64
+
65
+ classes[exactActiveClass] = isSameRoute(current, compareTarget)
66
+ classes[activeClass] = this.exact
67
+ ? classes[exactActiveClass]
68
+ : isIncludedRoute(current, compareTarget)
69
+
70
+ const handler = e => {
71
+ if (guardEvent(e)) {
72
+ if (this.replace) {
73
+ router.replace(location, noop)
74
+ } else {
75
+ router.push(location, noop)
76
+ }
77
+ }
78
+ }
79
+
80
+ const on = { click: guardEvent }
81
+ if (Array.isArray(this.event)) {
82
+ this.event.forEach(e => {
83
+ on[e] = handler
84
+ })
85
+ } else {
86
+ on[this.event] = handler
87
+ }
88
+
89
+ const data: any = { class: classes }
90
+
91
+ const scopedSlot =
92
+ !this.$scopedSlots.$hasNormal &&
93
+ this.$scopedSlots.default &&
94
+ this.$scopedSlots.default({
95
+ href,
96
+ route,
97
+ navigate: handler,
98
+ isActive: classes[activeClass],
99
+ isExactActive: classes[exactActiveClass]
100
+ })
101
+
102
+ if (scopedSlot) {
103
+ if (scopedSlot.length === 1) {
104
+ return scopedSlot[0]
105
+ } else if (scopedSlot.length > 1 || !scopedSlot.length) {
106
+ if (process.env.NODE_ENV !== 'production') {
107
+ warn(
108
+ false,
109
+ `RouterLink with to="${
110
+ this.to
111
+ }" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element.`
112
+ )
113
+ }
114
+ return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot)
115
+ }
116
+ }
117
+
118
+ if (this.tag === 'a') {
119
+ data.on = on
120
+ data.attrs = { href }
121
+ } else {
122
+ // find the first <a> child and apply listener and href
123
+ const a = findAnchor(this.$slots.default)
124
+ if (a) {
125
+ // in case the <a> is a static node
126
+ a.isStatic = false
127
+ const aData = (a.data = extend({}, a.data))
128
+ aData.on = aData.on || {}
129
+ // transform existing events in both objects into arrays so we can push later
130
+ for (const event in aData.on) {
131
+ const handler = aData.on[event]
132
+ if (event in on) {
133
+ aData.on[event] = Array.isArray(handler) ? handler : [handler]
134
+ }
135
+ }
136
+ // append new listeners for router-link
137
+ for (const event in on) {
138
+ if (event in aData.on) {
139
+ // on[event] is always a function
140
+ aData.on[event].push(on[event])
141
+ } else {
142
+ aData.on[event] = handler
143
+ }
144
+ }
145
+
146
+ const aAttrs = (a.data.attrs = extend({}, a.data.attrs))
147
+ aAttrs.href = href
148
+ } else {
149
+ // doesn't have <a> child, apply listener to self
150
+ data.on = on
151
+ }
152
+ }
153
+
154
+ return h(this.tag, data, this.$slots.default)
155
+ }
156
+ }
157
+
158
+ function guardEvent (e) {
159
+ // don't redirect with control keys
160
+ if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return
161
+ // don't redirect when preventDefault called
162
+ if (e.defaultPrevented) return
163
+ // don't redirect on right click
164
+ if (e.button !== undefined && e.button !== 0) return
165
+ // don't redirect if `target="_blank"`
166
+ if (e.currentTarget && e.currentTarget.getAttribute) {
167
+ const target = e.currentTarget.getAttribute('target')
168
+ if (/\b_blank\b/i.test(target)) return
169
+ }
170
+ // this may be a Weex event which doesn't have this method
171
+ if (e.preventDefault) {
172
+ e.preventDefault()
173
+ }
174
+ return true
175
+ }
176
+
177
+ function findAnchor (children) {
178
+ if (children) {
179
+ let child
180
+ for (let i = 0; i < children.length; i++) {
181
+ child = children[i]
182
+ if (child.tag === 'a') {
183
+ return child
184
+ }
185
+ if (child.children && (child = findAnchor(child.children))) {
186
+ return child
187
+ }
188
+ }
189
+ }
190
+ }