text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.router5={})}(this,function(e){"use strict";var t=function(e){return void 0===e&&(e={}),{arrayFormat:e.arrayFormat||"none",booleanFormat:e.booleanFormat||"none",nullFormat:e.nullFormat||"default"}},n=function(e){return encodeURIComponent(e)},r=function(e){return decodeURIComponent(e)},a=function(e,t,r){return null===t?function(e,t){return"hidden"===t.nullFormat?"":"string"===t.nullFormat?e+"=null":e}(e,r):"boolean"==typeof t?function(e,t,n){return"empty-true"===n.booleanFormat&&t?e:e+"="+("unicode"===n.booleanFormat?t?"✓":"✗":t.toString())}(e,t,r):Array.isArray(t)?function(e,t,r){var a=function(e){return"index"===e.arrayFormat?function(e,t){return e+"["+t+"]"}:"brackets"===e.arrayFormat?function(e){return e+"[]"}:function(e){return e}}(r);return t.map(function(t,r){return a(e,r)+"="+n(t)}).join("&")}(e,t,r):e+"="+n(t)},o=function(e){var t=e.indexOf("?");return-1===t?e:e.slice(t+1)},i=function(e){var t=e.indexOf("["),n=-1!==t;return{hasBrackets:n,name:n?e.slice(0,t):e}},u=function(e,n){var a=t(n);return o(e).split("&").reduce(function(e,t){var n=t.split("="),o=n[0],u=n[1],s=i(o),c=s.hasBrackets,l=s.name,f=e[l],d=function(e,t){if(void 0===e)return"empty-true"===t.booleanFormat||null;if("string"===t.booleanFormat){if("true"===e)return!0;if("false"===e)return!1}else if("unicode"===t.booleanFormat){if("✓"===r(e))return!0;if("✗"===r(e))return!1}else if("string"===t.nullFormat&&"null"===e)return null;return r(e)}(u,a);return e[l]=void 0===f?c?[d]:d:[].concat(f,d),e},{})},s=function(e,n){var r=t(n);return Object.keys(e).filter(function(t){return void 0!==e[t]}).map(function(t){return a(t,e[t],r)}).filter(Boolean).join("&")},c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},l=function(e){return"("+(e?e.replace(/(^<|>$)/g,""):"[a-zA-Z0-9-_.~%':|=+\\*@]+")+")"},f=[{name:"url-parameter",pattern:/^:([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(e){return new RegExp(l(e[2]))}},{name:"url-parameter-splat",pattern:/^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(e){return new RegExp(";"+e[1]+"="+l(e[2]))}},{name:"query-parameter",pattern:/^(?:\?|&)(?::)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/},{name:"delimiter",pattern:/^(\/|\?)/,regex:function(e){return new RegExp("\\"+e[0])}},{name:"sub-delimiter",pattern:/^(!|&|-|_|\.|;)/,regex:function(e){return new RegExp(e[0])}},{name:"fragment",pattern:/^([0-9a-zA-Z]+)/,regex:function(e){return new RegExp(e[0])}}],d=function e(t,n){if(void 0===n&&(n=[]),!f.some(function(r){var a=t.match(r.pattern);return!!a&&(n.push({type:r.name,match:a[0],val:a.slice(1,2),otherVal:a.slice(2),regex:r.regex instanceof Function?r.regex(a):r.regex}),a[0].length<t.length&&(n=e(t.substr(a[0].length),n)),!0)}))throw new Error("Could not parse path '"+t+"'");return n},h=function(e){return e},p=function(e){return void 0!==e&&null!==e},m=function(){function e(e){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.tokens=d(e),this.hasUrlParams=this.tokens.filter(function(e){return/^url-parameter/.test(e.type)}).length>0,this.hasSpatParam=this.tokens.filter(function(e){return/splat$/.test(e.type)}).length>0,this.hasMatrixParams=this.tokens.filter(function(e){return/matrix$/.test(e.type)}).length>0,this.hasQueryParams=this.tokens.filter(function(e){return/^query-parameter/.test(e.type)}).length>0,this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=this.urlParams.concat(this.queryParams),this.source=this.tokens.filter(function(e){return void 0!==e.regex}).map(function(e){return e.regex.source}).join("")}return e.createPath=function(t){return new e(t)},e.prototype.isQueryParam=function(e){return-1!==this.queryParams.indexOf(e)},e.prototype.test=function(e,t){var n=this,r=c({strictTrailingSlash:!1,queryParams:{}},t),a=function(e,t){return t?e:"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?"}(this.source,r.strictTrailingSlash),o=this.urlTest(e,a+(this.hasQueryParams?"(\\?.*$|$)":"$"),t);if(!o||!this.hasQueryParams)return o;var i=u(e,r.queryParams);return 0===Object.keys(i).filter(function(e){return!n.isQueryParam(e)}).length?(Object.keys(i).forEach(function(e){return o[e]=i[e]}),o):null},e.prototype.partialTest=function(e,t){var n=this,r=c({delimited:!0,queryParams:{}},t),a=function(e,t){return t?/(\/)$/.test(e)?e:e+"(\\/|\\?|\\.|;|$)":e}(this.source,r.delimited),o=this.urlTest(e,a,r);if(!o)return o;if(!this.hasQueryParams)return o;var i=u(e,r.queryParams);return Object.keys(i).filter(function(e){return n.isQueryParam(e)}).forEach(function(e){return function(e,t,n){void 0===n&&(n="");var r=e[t];return e[t]=void 0===r?n:Array.isArray(r)?r.concat(n):[r,n],e}(o,e,i[e])}),o},e.prototype.build=function(e,t){var n=this;void 0===e&&(e={});var r=c({ignoreConstraints:!1,ignoreSearch:!1,queryParams:{}},t),a=Object.keys(e).filter(function(e){return!n.isQueryParam(e)}).reduce(function(t,r){if(!p(e[r]))return t;var a=e[r],o=n.isQueryParam(r)?h:encodeURI;return"boolean"==typeof a?t[r]=a:Array.isArray(a)?t[r]=a.map(o):t[r]=o(a),t},{});if(this.urlParams.some(function(t){return!p(e[t])})){var o=this.urlParams.filter(function(t){return!p(e[t])});throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+o.join(", ")+" }")}if(!r.ignoreConstraints&&!this.tokens.filter(function(e){return/^url-parameter/.test(e.type)&&!/-splat$/.test(e.type)}).every(function(e){return new RegExp("^"+l(e.otherVal[0])+"$").test(a[e.val])}))throw new Error("Some parameters of '"+this.path+"' are of invalid format");var i=this.tokens.filter(function(e){return!1===/^query-parameter/.test(e.type)}).map(function(e){return"url-parameter-matrix"===e.type?";"+e.val+"="+a[e.val[0]]:/^url-parameter/.test(e.type)?a[e.val[0]]:e.match}).join("");if(r.ignoreSearch)return i;var u=this.queryParams.filter(function(t){return-1!==Object.keys(e).indexOf(t)}).reduce(function(t,n){return t[n]=e[n],t},{}),f=s(u,r.queryParams);return f?i+"?"+f:i},e.prototype.getParams=function(e){var t=e instanceof RegExp?function(t){return e.test(t.type)}:function(t){return t.type===e};return this.tokens.filter(t).map(function(e){return e.val[0]})},e.prototype.urlTest=function(e,t,n){var r=this,a=(void 0===n?{}:n).caseSensitive,o=new RegExp("^"+t,void 0!==a&&a?"":"i"),i=e.match(o);return i?this.urlParams.length?i.slice(1,this.urlParams.length+1).reduce(function(e,t,n){return e[r.urlParams[n]]=decodeURIComponent(t),e},{}):{}:null},e}(),v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},T=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,a=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(r=(i=u.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){a=!0,o=e}finally{try{!r&&u.return&&u.return()}finally{if(a)throw o}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),S=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},O=function(e){var t="";return e.reduce(function(e,n){var r=n.parser.urlParams.reduce(function(e,t){return e[t]="url",e},{}),a=n.parser.queryParams.reduce(function(e,t){return e[t]="query",e},r);return void 0!==n.name&&(e[t=t?t+"."+n.name:n.name]=a),e},{})},b=function e(n,r,a,s,c){void 0===s&&(s={});for(var l=s.queryParamsMode,f=void 0===l?"default":l,d=s.strictTrailingSlash,h=void 0!==d&&d,p=s.strongMatching,m=void 0===p||p,g=s.caseSensitive,y=void 0!==g&&g,T=1===n.length&&""===n[0].name,S=function(n){var l,d,p=void 0,v=r;if("/"===c&&"/"===n.path&&(v="/"+r),n.children.length||(l=n.parser.test(v,{caseSensitive:y,strictTrailingSlash:h,queryParams:s.queryParams})),l||(l=n.parser.partialTest(v,{delimited:m,caseSensitive:y,queryParams:s.queryParams})),l){var g=n.parser.build(l,{ignoreSearch:!0});h||n.children.length||(g=g.replace(/\/$/,"")),p=v.replace(new RegExp("^"+g,"i"),""),h||n.children.length||(p=p.replace(/^\/\?/,"?"));var S=function(e,n,r){var a=t(r);if(""===o(e))return{querystring:"",removedParams:{}};var s=e.split("&").reduce(function(e,t){var r=e[0],a=e[1],o=t.split("=")[0],u=i(o).name;return-1===n.indexOf(u)?[r.concat(t),a]:[r,a.concat(t)]},[[],[]]),c=s[0],l=s[1];return{querystring:c.join("&"),removedParams:u(l.join("&"),a)}}((d=v.replace(g,""),d.split("?")[1]||""),n.parser.queryParams,s.queryParams).querystring;if(p=function(e){return e.split("?")[0]}(p)+(S?"?"+S:""),h||T||"/"!==p||/\/$/.test(g)||(p=""),a.segments.push(n),Object.keys(l).forEach(function(e){return a.params[e]=l[e]}),!T&&!p.length)return{value:a};if(!T&&"strict"!==f&&0===p.indexOf("?")){var P=u(p.slice(1),s.queryParams);return Object.keys(P).forEach(function(e){return a.params[e]=P[e]}),{value:a}}var O=n.getNonAbsoluteChildren();return O.length?{value:e(O,p,a,s,g)}:{value:null}}},P=0,O=n;P<O.length;P++){var b=S(O[P]);if("object"===(void 0===b?"undefined":v(b)))return b.value}return null};var E=function(e){return function(t,n){var r=t.path.replace(/<.*?>/g,"").split("?")[0].replace(/(.+)\/$/,"$1"),a=n.path.replace(/<.*?>/g,"").split("?")[0].replace(/(.+)\/$/,"$1");if("/"===r)return 1;if("/"===a)return-1;if(t.parser.hasSpatParam)return 1;if(n.parser.hasSpatParam)return-1;var o=(r.match(/\//g)||[]).length,i=(a.match(/\//g)||[]).length;if(o<i)return 1;if(o>i)return-1;var u=t.parser.urlParams.length,s=n.parser.urlParams.length;if(u<s)return-1;if(u>s)return 1;var c=(r.split("/").slice(-1)[0]||"").length,l=(a.split("/").slice(-1)[0]||"").length;return c<l?1:c>l?-1:e.indexOf(t)-e.indexOf(n)}},N=(P({},{queryParamsMode:"default",trailingSlashMode:"default"},{strongMatching:!0}),function(){function e(e,t,n,r,a,o,i){return void 0===e&&(e=""),void 0===t&&(t=""),void 0===n&&(n=[]),void 0===o&&(o=!0),this.name=e,this.absolute=/^~/.test(t),this.path=this.absolute?t.slice(1):t,this.parser=this.path?new m(this.path):null,this.children=[],this.parent=a,this.checkParents(),this.add(n,r,!o&&!1!==i),o&&this.sortDescendants(),this}return e.prototype.getParentSegments=function(e){return void 0===e&&(e=[]),this.parent&&this.parent.parser?this.parent.getParentSegments(e.concat(this.parent)):e.reverse()},e.prototype.setParent=function(e){this.parent=e,this.checkParents()},e.prototype.setPath=function(e){void 0===e&&(e=""),this.path=e,this.parser=e?new m(e):null},e.prototype.add=function(t,n,r){var a=this;if(void 0===r&&(r=!0),void 0!==t&&null!==t){if(!(t instanceof Array)){if(!(t instanceof e||t instanceof Object))throw new Error("RouteNode.add() expects routes to be an Object or an instance of RouteNode.");if(t instanceof e)t.setParent(this),this.addRouteNode(t,r);else{if(!t.name||!t.path)throw new Error("RouteNode.add() expects routes to have a name and a path defined.");var o=new e(t.name,t.path,t.children,n,this,!1,r),i=o.getParentSegments([o]).map(function(e){return e.name}).join(".");n&&n(P({},t,{name:i})),this.addRouteNode(o,r)}return this}t.forEach(function(e){return a.add(e,n,r)})}},e.prototype.addNode=function(t,n){return this.add(new e(t,n)),this},e.prototype.getPath=function(e){return(t=this.getSegmentsByName(e))?t.map(function(e){return e.path}).join(""):null;var t},e.prototype.getNonAbsoluteChildren=function(){return this.children.filter(function(e){return!e.absolute})},e.prototype.sortChildren=function(){var e,t;this.children.length&&(e=this.children,t=e.slice(0),e.sort(E(t)))},e.prototype.sortDescendants=function(){this.sortChildren(),this.children.forEach(function(e){return e.sortDescendants()})},e.prototype.buildPath=function(e,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),function(e,t,n){if(void 0===t&&(t={}),void 0===n&&(n={}),!e)return null;for(var r=n.queryParamsMode,a=void 0===r?"default":r,o=(n.trailingSlashMode,[]),i=[],u=0,c=e;u<c.length;u++){var l=c[u].parser;o.push.apply(o,l.queryParams),i.push.apply(i,l.urlParams),i.push.apply(i,l.spatParams)}if("loose"===a){var f=Object.keys(t).reduce(function(e,t){return-1===o.indexOf(t)&&-1===i.indexOf(t)?e.concat(t):e},[]);o.push.apply(o,f)}var d=o.reduce(function(e,n){return-1!==Object.keys(t).indexOf(n)&&(e[n]=t[n]),e},{}),h=s(d,n.queryParams),p=e.reduce(function(e,r){var a=r.parser.build(t,{ignoreSearch:!0,queryParams:n.queryParams});return r.absolute?a:e+a},"").replace(/\/\/{1,}/g,"/"),m=p;return"always"===n.trailingSlashMode?m=/\/$/.test(p)?p:p+"/":"never"===n.trailingSlashMode&&"/"!==p&&(m=/\/$/.test(p)?p.slice(0,-1):p),m+(h?"?"+h:"")}(this.getSegmentsByName(e),t,n)},e.prototype.buildState=function(e,t){void 0===t&&(t={});var n=this.getSegmentsByName(e);return n&&n.length?{name:e,params:t,meta:O(n)}:null},e.prototype.matchPath=function(e,t){void 0===t&&(t={}),""!==e||t.strictTrailingSlash||(e="/");var n=this.getSegmentsMatchingPath(e,t);if(n){var r=n.segments;if(r[0].absolute){var a=r[0].getParentSegments();r.reverse(),r.push.apply(r,a),r.reverse()}var o=r[r.length-1].findSlashChild();o&&r.push(o)}return function(e){return e&&e.segments&&e.segments.length?{name:e.segments.map(function(e){return e.name}).filter(function(e){return e}).join("."),params:e.params,meta:O(e.segments)}:null}(n)},e.prototype.addRouteNode=function(e,t){void 0===t&&(t=!0);var n=e.name.split(".");if(1===n.length){if(-1!==this.children.map(function(e){return e.name}).indexOf(e.name))throw new Error('Alias "'+e.name+'" is already defined in route node');if(-1!==this.children.map(function(e){return e.path}).indexOf(e.path))throw new Error('Path "'+e.path+'" is already defined in route node');this.children.push(e),t&&this.sortChildren()}else{var r=this.getSegmentsByName(n.slice(0,-1).join("."));if(!r)throw new Error("Could not add route named '"+e.name+"', parent is missing.");e.name=n[n.length-1],r[r.length-1].add(e)}return this},e.prototype.checkParents=function(){if(this.absolute&&this.hasParentsParams())throw new Error("[RouteNode] A RouteNode with an abolute path cannot have parents with route parameters")},e.prototype.hasParentsParams=function(){if(this.parent&&this.parent.parser){var e=this.parent.parser;return e.hasUrlParams||e.hasSpatParam||e.hasMatrixParams||e.hasQueryParams||this.parent.hasParentsParams()}return!1},e.prototype.findAbsoluteChildren=function(){return this.children.reduce(function(e,t){return e.concat(t.absolute?t:[]).concat(t.findAbsoluteChildren())},[])},e.prototype.findSlashChild=function(){return this.getNonAbsoluteChildren().filter(function(e){return e.parser&&/^\/(\?|$)/.test(e.parser.path)})[0]},e.prototype.getSegmentsByName=function(e){var t=[],n=this.parser?[this]:this.children;return(this.parser?[""]:[]).concat(e.split(".")).every(function(e){var r=function(e,t){var n=t.filter(function(t){return t.name===e});return n.length?n[0]:void 0}(e,n);return!!r&&(n=r.children,t.push(r),!0)})?t:null},e.prototype.getSegmentsMatchingPath=function(e,t){var n=(this.parser?[this]:this.children).reduce(function(e,t){return e.concat(t,t.findAbsoluteChildren())},[]),r=b(n,e,{segments:[],params:{}},t);return r&&1===r.segments.length&&""===r.segments[0].name?null:r},e}()),A={ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED"},R={UNKNOWN_ROUTE:"@@router5/UNKNOWN_ROUTE",ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"};var _=function(){};function w(e){var t=!1;e.isStarted=function(){return t},e.start=function(){var n,r=e.getOptions(),a=(n=arguments.length-1,arguments.length<=n?void 0:arguments[n]),o="function"==typeof a?a:_,i="function"!=typeof(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:void 0;if(t)return o({code:A.ROUTER_ALREADY_STARTED}),e;var u=void 0,s=void 0;t=!0,e.invokeEventListeners(R.ROUTER_START);var c=function(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t||e.invokeEventListeners(R.TRANSITION_SUCCESS,n,null,{replace:!0}),t&&r&&e.invokeEventListeners(R.TRANSITION_ERROR,n,null,t),o(t,n)};if(void 0===i&&!r.defaultRoute)return c({code:A.NO_START_PATH_OR_STATE});"string"==typeof i?u=i:"object"===(void 0===i?"undefined":v(i))&&(s=i);if(s)e.setState(s),c(null,s);else{var l=function(){return e.navigateToDefault({replace:!0},o)},f=function(t){e.transitionToState(t,e.getState(),{},function(t,n){var a;t?t.redirect?(a=t.redirect,e.navigate(a.name,a.params,{replace:!0,reload:!0,redirected:!0},o)):r.defaultRoute?l():c(t,null,!1):c(null,n)})};(s=void 0===u?null:e.matchPath(u))?f(s):r.defaultRoute?l():r.allowNotFound?f(e.makeNotFoundState(u,{replace:!0})):c({code:A.ROUTE_NOT_FOUND,path:u},null)}return e},e.stop=function(){t&&(e.setState(null),t=!1,e.invokeEventListeners(R.ROUTER_STOP));return e}}var C="function"==typeof Symbol&&"symbol"===v(Symbol.iterator)?function(e){return void 0===e?"undefined":v(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":v(e)};function j(e){return e.split(".").reduce(function(e,t){return e.concat(e.length?e[e.length-1]+"."+t:t)},[])}function k(e){return e&&e.meta&&e.meta.params}function x(e,t){return void 0===(n=t.meta.params[e])||null===n?{}:Object.keys(t.meta.params[e]).reduce(function(e,n){return e[n]=t.params[n],e},{});var n}function I(e,t){var n=t?j(t.name):[],r=j(e.name),a=Math.min(n.length,r.length);var o=void 0;o=t&&(k(t)||k(e))?function(){var o=void 0,i=function(){var a=n[o],i=r[o];if(a!==i)return{v:o};var u=x(a,e),s=x(i,t);return u.length!==s.length?{v:o}:0===u.length?"continue":Object.keys(u).some(function(e){return s[e]!==u[e]})?{v:o}:void 0};for(o=0;o<a;o+=1){var u=i();switch(u){case"continue":continue;default:if("object"===(void 0===u?"undefined":C(u)))return u.v}}return o}():0;var i=n.slice(o).reverse(),u=r.slice(o);return{intersection:t&&o>0?n[o-1]:"",toDeactivate:i,toActivate:u}}function q(e,t,n){var r=t.isCancelled,a=t.toState,o=t.fromState,i=t.errorKey,u=Array.isArray(e)?e:Object.keys(e),s=function(e){return"object"===(void 0===e?"undefined":v(e))&&void 0!==e.name&&void 0!==e.params&&void 0!==e.path},c=function(e,t,n,a){var i=function(e,t){var r,o;e?a(e):t&&t!==n&&s(t)?(r=t,((o=n).name!==r.name||o.params!==r.params||o.path!==r.path)&&console.error("[router5][transition] Warning: state values (name, params, path) were changed during transition process."),a(null,function(e,t){return y({},t,e,{meta:y({},t.meta,e.meta)})}(t,n))):a(null,n)},u=e.call(null,n,o,i);r()?i(null):"boolean"==typeof u?i(u?null:t):s(u)?i(null,u):u&&"function"==typeof u.then&&u.then(function(e){e instanceof Error?i({error:e},null):i(null,e)},function(e){e instanceof Error?(console.error(e.stack||e),i(y({},t,{promiseError:e}),null)):i("object"===(void 0===e?"undefined":v(e))?y({},t,e):t,null)})};!function t(a,o){if(r())n();else if(a)n(a);else if(u.length){var s="string"==typeof u[0],l=i&&s?g({},i,u[0]):{},f=s?e[u[0]]:u[0];u=u.slice(1),c(f,l,o,t)}else n(null,o)}(null,a)}var F=function(){};function U(e){var t=void 0;function n(){return t&&(t("navigate"),t=null),e}function r(){var t,n=arguments.length<=0?void 0:arguments[0],o=(t=arguments.length-1,arguments.length<=t?void 0:arguments[t]),i="function"==typeof o?o:F,u="object"===v(arguments.length<=1?void 0:arguments[1])?arguments.length<=1?void 0:arguments[1]:{},s="object"===v(arguments.length<=2?void 0:arguments[2])?arguments.length<=2?void 0:arguments[2]:{};if(e.isStarted()){var c=e.buildState(n,u);if(!c){var l={code:A.ROUTE_NOT_FOUND};return i(l),void e.invokeEventListeners(R.TRANSITION_ERROR,null,e.getState(),l)}var f=e.makeState(c.name,c.params,e.buildPath(c.name,c.params),{params:c.meta,options:s}),d=!!e.getState()&&e.areStatesEqual(e.getState(),f,!1);if(d&&!s.reload&&!s.force){var h={code:A.SAME_STATES};return i(h),void e.invokeEventListeners(R.TRANSITION_ERROR,f,e.getState(),h)}var p=d||s.reload?null:e.getState();return s.skipTransition?(i(null,f),F):a(f,p,s,function(t,n){if(t)if(t.redirect){var a=t.redirect;r(a.name,a.params,y({},s,{force:!0,redirected:!0}),i)}else i(t);else e.invokeEventListeners(R.TRANSITION_SUCCESS,n,p,s),i(null,n)})}i({code:A.ROUTER_NOT_STARTED})}function a(r,a){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:F;return n(),e.invokeEventListeners(R.TRANSITION_START,r,a),t=function(e,t,n,r,a){var o=!1,i=!1,u=e.getOptions(),s=e.getLifecycleFunctions(),c=T(s,2),l=c[0],f=c[1],d=e.getMiddlewareFunctions(),h=function(){return o},p=function(e,t){return y({},e,t instanceof Object?t:{error:t})},m=t.name===R.UNKNOWN_ROUTE,v={isCancelled:h,toState:t,fromState:n},S=I(t,n),P=S.toDeactivate,O=S.toActivate,b=!n||r.forceDeactivate?[]:function(e,t,n){q(P.filter(function(e){return l[e]}).reduce(function(e,t){return y({},e,g({},t,l[t]))},{}),y({},v,{errorKey:"segment"}),function(e){return n(e?p({code:A.CANNOT_DEACTIVATE},e):null)})},E=m?[]:function(e,t,n){q(O.filter(function(e){return f[e]}).reduce(function(e,t){return y({},e,g({},t,f[t]))},{}),y({},v,{errorKey:"segment"}),function(e){return n(e?p({code:A.CANNOT_ACTIVATE},e):null)})},N=d.length?function(e,t,n){return q(d,y({},v),function(t,r){return n(t?p({code:A.TRANSITION_ERR},t):null,r||e)})}:[];return q([].concat(b).concat(E).concat(N),v,function(n,r){if(i=!0,!h()){if(!n&&u.autoCleanUp){var o=j(t.name);Object.keys(l).forEach(function(t){-1===o.indexOf(t)&&e.clearCanDeactivate(t)})}a(n,r||t)}}),function(){o||i||(o=!0,a({code:A.TRANSITION_CANCELLED},null))}}(e,r,a,o,function(n,o){t=null,o=o||r,n?(n.code===A.TRANSITION_CANCELLED?e.invokeEventListeners(R.TRANSITION_CANCEL,r,a):e.invokeEventListeners(R.TRANSITION_ERROR,r,a,n),i(n)):(e.setState(o),i(null,o))})}e.config.forwardMap={},e.navigate=r,e.navigateToDefault=function(){var t="object"===v(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:{},n=2===arguments.length?arguments.length<=1?void 0:arguments[1]:"function"==typeof(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:F,a=e.getOptions();if(a.defaultRoute)return r(a.defaultRoute,a.defaultParams,t,n);return function(){}},e.transitionToState=a,e.cancel=n,e.forward=function(t,n){return e.config.forwardMap[t]=n,e}}var D=function(e){var t,n=e.Symbol;return"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable",t}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")());function M(e){var t=[];function n(e){var n="object"===(void 0===e?"undefined":v(e)),r=n?e.next.bind(e):e;t=t.concat(r);var a=function(){var e;(e=r)&&(t=t.filter(function(t){return t!==e}))};return n?{unsubscribe:a}:a}return e.subscribe=n,e[D]=function(){return g({subscribe:function(e){if("object"!==(void 0===e?"undefined":v(e))||null===e)throw new TypeError("Expected the observer to be an object.");return n(e)}},D,function(){return this})},{onTransitionSuccess:function(e,n){t.forEach(function(t){return t({route:e,previousRoute:n})})}}}M.pluginName="OBSERVABLE_PLUGIN";var L=["onStart","onStop","onTransitionSuccess","onTransitionStart","onTransitionError","onTransitionCancel"];function $(e){var t=[],n=[];function r(r){a(r)||(t.push(r),function(t){var r=e.executeFactory(t),a=L.map(function(t){if(r[t])return e.addEventListener(t.toLowerCase().replace(/^on/,"$$").replace(/transition/,"$$"),r[t])}).filter(Boolean);n.push.apply(n,S(a))}(r))}function a(e){return t.filter(function(t){return t.pluginName===e||t.name===e}).length>0}e.usePlugin=function(){for(var t=arguments.length,n=Array(t),a=0;a<t;a++)n[a]=arguments[a];return n.forEach(r),e},e.hasPlugin=a,e.getPlugins=function(){return t}}var B=function(e){return"function"==typeof e?e:function(){return function(){return e}}};var z={trailingSlashMode:"default",queryParamsMode:"default",strictTrailingSlash:!1,autoCleanUp:!0,allowNotFound:!1,strongMatching:!0,rewritePathOnMatch:!0,caseSensitive:!1};function Q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,r=0,a={},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=y({},z);Object.keys(t).forEach(function(e){return d(e,t[e])});var u={config:{decoders:{},encoders:{},defaultParams:{}},rootNode:c,getOptions:function(){return i},setOption:d,getState:function(){return n},setState:function(e){n=e,e&&e.meta&&"number"==typeof e.meta.id&&(r=e.meta.id)},makeState:f,makeNotFoundState:function(e,t){return f(R.UNKNOWN_ROUTE,{path:e},e,{options:t})},setDependency:function(e,t){return o[e]=t,u},setDependencies:function(e){return Object.keys(e).forEach(function(t){o[t]=e[t]}),u},getDependencies:h,add:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];c.add(e,l,!t),t&&c.sortDescendants();return u},addNode:function(e,t,n){u.rootNode.addNode(e,t),n&&u.canActivate(e,n);return u},executeFactory:function(e){return e.apply(void 0,S([u,h()]))},addEventListener:function(e,t){return a[e]=(a[e]||[]).concat(t),function(){return s(e,t)}},removeEventListener:s,invokeEventListeners:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];(a[e]||[]).forEach(function(e){return e.apply(void 0,n)})}};function s(e,t){a[e]=a[e].filter(function(e){return e!==t})}!function(e){function t(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(t.name!==n.name)return!1;var a=function(t){return e.rootNode.getSegmentsByName(t).map(function(e){return e.parser.urlParams}).reduce(function(e,t){return e.concat(t)},[])},o=r?a(t.name):Object.keys(t.params),i=r?a(n.name):Object.keys(n.params);return o.length===i.length&&o.every(function(e){return t.params[e]===n.params[e]})}function n(e,t){return!!new RegExp("^"+e.name+"\\.(.*)$").test(t.name)&&Object.keys(e.params).every(function(n){return e.params[n]===t.params[n]})}function r(t,n){var r=e.config.forwardMap[t]||t;return{name:r,params:y({},e.config.defaultParams[t],e.config.defaultParams[r],n)}}e.isActive=function(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=e.getState();return!!u&&(o||u.name===r?t(e.makeState(r,a),u,i):n(e.makeState(r,a),u))},e.areStatesEqual=t,e.areStatesDescendants=n,e.buildPath=function(t,n){if(t===R.UNKNOWN_ROUTE)return n.path;var r=e.getOptions(),a=r.trailingSlashMode,o=r.queryParamsMode,i=r.queryParams,u=e.config.encoders[t]?e.config.encoders[t](n):n;return e.rootNode.buildPath(t,u,{trailingSlashMode:a,queryParamsMode:o,queryParams:i})},e.buildState=function(t,n){var a=r(t,n),o=a.name,i=a.params;return e.rootNode.buildState(o,i)},e.matchPath=function(t,n){var a=e.getOptions(),o=e.rootNode.matchPath(t,a);if(o){var i=o.name,u=o.params,s=o.meta,c=e.config.decoders[i]?e.config.decoders[i](u):u,l=r(i,c),f=l.name,d=l.params,h=!1===a.rewritePathOnMatch?t:e.buildPath(f,d);return e.makeState(f,d,h,{params:s,source:n})}return null},e.setRootPath=function(t){e.rootNode.setPath(t)}}(u),$(u),function(e){var t=[],n=[];function r(r){t.push(r),n.push(e.executeFactory(r))}e.useMiddleware=function(){for(var t=arguments.length,n=Array(t),a=0;a<t;a++)n[a]=arguments[a];return n.forEach(r),e},e.getMiddlewareFactories=function(){return t},e.getMiddlewareFunctions=function(){return n},e.clearMiddleware=function(){return t=[],n=[],e}}(u),function(e){e.usePlugin(M)}(u),function(e){var t={},n={},r={},a={};e.canDeactivate=function(n,a){var o=B(a);return t[n]=o,r[n]=e.executeFactory(o),e},e.canActivate=function(t,r){var o=B(r);return n[t]=o,a[t]=e.executeFactory(o),e},e.getLifecycleFactories=function(){return[t,n]},e.getLifecycleFunctions=function(){return[r,a]},e.clearCanDeactivate=function(n){return t[n]=void 0,r[n]=void 0,e}}(u),w(u),U(u),function(e,t){e.clone=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=y({},e.getDependencies(),n),a=t(e.rootNode,e.getOptions(),r);a.useMiddleware.apply(a,S(e.getMiddlewareFactories())),a.usePlugin.apply(a,S(e.getPlugins())),a.config=e.config;var o=e.getLifecycleFactories(),i=T(o,2),u=i[0],s=i[1];return Object.keys(u).forEach(function(e){return a.canDeactivate(e,u[e])}),Object.keys(s).forEach(function(e){return a.canActivate(e,s[e])}),a}}(u,Q);var c=e instanceof N?e:new N("","",e,l);return u.rootNode=c,u;function l(e){e.canActivate&&u.canActivate(e.name,e.canActivate),e.forwardTo&&u.forward(e.name,e.forwardTo),e.decodeParams&&(u.config.decoders[e.name]=e.decodeParams),e.encodeParams&&(u.config.encoders[e.name]=e.encodeParams),e.defaultParams&&(u.config.defaultParams[e.name]=e.defaultParams)}function f(e,t,n,a,o){var i={},u=function(e,t){return Object.defineProperty(i,e,{value:t,enumerable:!0})};if(u("name",e),u("params",t),u("path",n),a){var s=void 0;s=void 0===o?r+=1:o,u("meta",y({},a,{id:s}))}return i}function d(e,t){return i[e]=t,u}function h(){return o}}var Z=function(){};function V(){var e=void 0,t=void 0;return console.groupCollapsed?(e=function(e){return console.groupCollapsed(e)},t=function(){return console.groupEnd()}):console.group?(e=function(e){return console.group(e)},t=function(){return console.groupEnd()}):(e=Z,t=Z),console.info("Router started"),{onStop:function(){console.info("Router stopped")},onTransitionStart:function(n,r){t(),e("Router transition"),console.log("Transition started from state"),console.log(r),console.log("To state"),console.log(n)},onTransitionCancel:function(){console.warn("Transition cancelled")},onTransitionError:function(e,n,r){console.warn("Transition error with code "+r.code),t()},onTransitionSuccess:function(){console.log("Transition success"),t()}}}V.pluginName="LOGGER_PLUGIN",e.default=Q,e.createRouter=Q,e.RouteNode=N,e.loggerPlugin=V,e.errorCodes=A,e.transitionPath=I,e.constants=R,Object.defineProperty(e,"__esModule",{value:!0})});
  