Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vaadin/router

Package Overview
Dependencies
Maintainers
14
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vaadin/router - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-pre.1

2

dist/vaadin-router.min.js

@@ -1,1 +0,1 @@

function t(t){return t=t||[],Array.isArray(t)?t:[t]}function e(t){return`[Vaadin.Router] ${t}`}const n="module",r="nomodule",o=[n,r];function i(t){if(!t.match(/.+\.[m]?js$/))throw new Error(e(`Unsupported type for bundle "${t}": .js or .mjs expected.`))}function s(t){if(!t||!h(t.path))throw new Error(e('Expected route config to be an object with a "path" string property, or an array of such objects'));const s=t.bundle,u=["component","redirect","bundle"];if(!(l(t.action)||Array.isArray(t.children)||l(t.children)||f(s)||u.some(e=>h(t[e]))))throw new Error(e(`Expected route config "${t.path}" to include either "${u.join('", "')}" `+'or "action" function but none found.'));if(s)if(h(s))i(s);else{if(!o.some(t=>t in s))throw new Error(e('Expected route bundle to include either "'+r+'" or "'+n+'" keys, or both'));o.forEach(t=>t in s&&i(s[t]))}t.redirect&&["bundle","component"].forEach(n=>{n in t&&console.warn(e(`Route config "${t.path}" has both "redirect" and "${n}" properties, `+`and "redirect" will always override the latter. Did you mean to only use "${n}"?`))})}function u(e){t(e).forEach(t=>s(t))}function c(t,e){let o=document.head.querySelector('script[src="'+t+'"][async]');return o||((o=document.createElement("script")).setAttribute("src",t),e===n?o.setAttribute("type",n):e===r&&o.setAttribute(r,""),o.async=!0),new Promise((t,e)=>{o.onreadystatechange=o.onload=(e=>{o.t=!0,t(e)}),o.onerror=(t=>{o.parentNode&&o.parentNode.removeChild(o),e(t)}),null===o.parentNode?document.head.appendChild(o):o.t&&t()})}function a(t,e){window.dispatchEvent(new CustomEvent(`vaadin-router-${t}`,{detail:e}))}function f(t){return"object"==typeof t&&!!t}function l(t){return"function"==typeof t}function h(t){return"string"==typeof t}function d(t){const n=new Error(e(`Page not found (${t.pathname})`));return n.context=t,n.code=404,n}function w(t){if(t.defaultPrevented)return;if(0!==t.button)return;if(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)return;let e=t.target;const n=t.composedPath?t.composedPath():t.path||[];for(let t=0;t<n.length;t++){const r=n[t];if(r.nodeName&&"a"===r.nodeName.toLowerCase()){e=r;break}}for(;e&&"a"!==e.nodeName.toLowerCase();)e=e.parentNode;e&&"a"===e.nodeName.toLowerCase()&&(e.target&&"_self"!==e.target.toLowerCase()||e.hasAttribute("download")||e.pathname===window.location.pathname&&""!==e.hash||(e.origin||function(t){const e=t.port,n=t.protocol;return`${n}//${"http:"===n&&"80"===e||"https:"===n&&"443"===e?t.hostname:t.host}`}(e))===window.location.origin&&(t.preventDefault(),a("go",{pathname:e.pathname})))}const p={activate(){window.document.addEventListener("click",w)},inactivate(){window.document.removeEventListener("click",w)}};function m(t){"vaadin-router-ignore"!==t.state&&a("go",{pathname:window.location.pathname})}/Trident/.test(navigator.userAgent)&&!l(window.PopStateEvent)&&(window.PopStateEvent=function(t,e){e=e||{};var n=document.createEvent("Event");return n.initEvent(t,Boolean(e.bubbles),Boolean(e.cancelable)),n.state=e.state||null,n},window.PopStateEvent.prototype=window.Event.prototype);const v={activate(){window.addEventListener("popstate",m)},inactivate(){window.removeEventListener("popstate",m)}};var y=T,g=j,b=function(t,e){return P(j(t,e))},E=P,_=A,$="/",x="./",O=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function j(t,e){for(var n,r=[],o=0,i=0,s="",u=e&&e.delimiter||$,c=e&&e.delimiters||x,a=!1;null!==(n=O.exec(t));){var f=n[0],l=n[1],h=n.index;if(s+=t.slice(i,h),i=h+f.length,l)s+=l[1],a=!0;else{var d="",w=t[i],p=n[2],m=n[3],v=n[4],y=n[5];if(!a&&s.length){var g=s.length-1;c.indexOf(s[g])>-1&&(d=s[g],s=s.slice(0,g))}s&&(r.push(s),s="",a=!1);var b=""!==d&&void 0!==w&&w!==d,E="+"===y||"*"===y,_="?"===y||"*"===y,j=d||u,P=m||v;r.push({name:p||o++,prefix:d,delimiter:j,optional:_,repeat:E,partial:b,pattern:P?k(P):"[^"+R(j)+"]+?"})}}return(s||i<t.length)&&r.push(s+t.substr(i)),r}function P(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,r){for(var o="",i=r&&r.encode||encodeURIComponent,s=0;s<t.length;s++){var u=t[s];if("string"!=typeof u){var c,a=n?n[u.name]:void 0;if(Array.isArray(a)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===a.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var f=0;f<a.length;f++){if(c=i(a[f],u),!e[s].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===f?u.prefix:u.delimiter)+c}}else if("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(c=i(String(a),u),!e[s].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');o+=u.prefix+c}}else o+=u}return o}}function R(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function k(t){return t.replace(/([=!:$/()])/g,"\\$1")}function C(t){return t&&t.sensitive?"":"i"}function A(t,e,n){for(var r=(n=n||{}).strict,o=!1!==n.end,i=R(n.delimiter||$),s=n.delimiters||x,u=[].concat(n.endsWith||[]).map(R).concat("$").join("|"),c="",a=0===t.length,f=0;f<t.length;f++){var l=t[f];if("string"==typeof l)c+=R(l),a=f===t.length-1&&s.indexOf(l[l.length-1])>-1;else{var h=R(l.prefix),d=l.repeat?"(?:"+l.pattern+")(?:"+h+"(?:"+l.pattern+"))*":l.pattern;e&&e.push(l),l.optional?l.partial?c+=h+"("+d+")?":c+="(?:"+h+"("+d+"))?":c+=h+"("+d+")"}}return o?(r||(c+="(?:"+i+")?"),c+="$"===u?"$":"(?="+u+")"):(r||(c+="(?:"+i+"(?="+u+"))?"),a||(c+="(?="+i+"|"+u+")")),new RegExp("^"+c,C(n))}function T(t,e,n){return t instanceof RegExp?function(t,e){if(!e)return t;var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return t}(t,e):Array.isArray(t)?function(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(T(t[o],e,n).source);return new RegExp("(?:"+r.join("|")+")",C(n))}(t,e,n):function(t,e,n){return A(j(t,n),e,n)}(t,e,n)}y.parse=g,y.compile=b,y.tokensToFunction=E,y.tokensToRegExp=_;const{hasOwnProperty:B}=Object.prototype,S=new Map;function I(t){try{return decodeURIComponent(t)}catch(e){return t}}function M(t,e,n,r,o){let i,s,u=0,c=t.path||"";return"/"===c.charAt(0)&&(n&&(c=c.substr(1)),n=!0),{next(a){if(t===a)return{done:!0};const f=t.o=t.o||t.children;if(!i&&(i=function(t,e,n,r,o){const i=`${t}|${n=!!n}`;let s=S.get(i);if(!s){const e=[];s={keys:e,pattern:y(t,e,{end:n,strict:""===t})},S.set(i,s)}const u=s.pattern.exec(e);if(!u)return null;const c=Object.assign({},o);for(let t=1;t<u.length;t++){const e=s.keys[t-1],n=e.name,r=u[t];void 0===r&&B.call(c,n)||(e.repeat?c[n]=r?r.split(e.delimiter).map(I):[]:c[n]=r?I(r):r)}return{path:u[0],keys:(r||[]).concat(s.keys),params:c}}(c,e,!f,r,o)))return{done:!1,value:{route:t,keys:i.keys,params:i.params,path:i.path}};if(i&&f)for(;u<f.length;){if(!s){const r=f[u];r.parent=t;let o=i.path.length;o>0&&"/"===e.charAt(o)&&(o+=1),s=M(r,e.substr(o),n,i.keys,i.params)}const r=s.next(a);if(!r.done)return{done:!1,value:r.value};s=null,u++}return{done:!0}}}}function D(t){if(l(t.route.action))return t.route.action(t)}S.set("|false",{keys:[],pattern:/(?:)/});class L{constructor(t,e={}){if(Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=e.baseUrl||"",this.errorHandler=e.errorHandler,this.resolveRoute=e.resolveRoute||D,this.context=Object.assign({resolver:this},e.context),this.root=Array.isArray(t)?{path:"",o:t,parent:null,i:!0}:t,this.root.parent=null}getRoutes(){return[...this.root.o]}setRoutes(e){u(e);const n=[...t(e)];this.root.o=n}addRoutes(e){return u(e),this.root.o.push(...t(e)),this.getRoutes()}removeRoutes(){this.setRoutes([])}resolve(t){const e=Object.assign({},this.context,h(t)?{pathname:t}:t),n=M(this.root,e.pathname.substr(this.baseUrl.length)),r=this.resolveRoute;let o=null,i=null,s=e;function u(t,c=o.value.route,a){const f=null===a&&o.value.route;return o=i||n.next(f),i=null,t||!o.done&&function(t,e){let n=e;for(;n;)if((n=n.parent)===t)return!0;return!1}(c,o.value.route)?o.done?Promise.reject(d(e)):(function(t,e){const{route:n,path:r}=e;if(n&&!n.i){const e={path:r,route:n};!function(t,e){return!e.parent||!t||!t.length||t[t.length-1].route!==e.parent}(t.chain,n)?t.chain.push(e):t.chain=[e]}}(e,o.value),s=Object.assign({},e,o.value),Promise.resolve(r(s)).then(e=>null!==e&&void 0!==e?(s.result=e.result||e,s):u(t,c,e))):(i=o,Promise.resolve(null))}return e.next=u,Promise.resolve().then(()=>u(!0,this.root)).catch(t=>{const e=function(t){let e=`Path '${t.pathname}' is not properly resolved due to an error.`;const n=(t.route||{}).path;return n&&(e+=` Resolution had failed on route: '${n}'`),e}(s);if(t?console.warn(e):t=new Error(e),t.context=t.context||s,t instanceof DOMException||(t.code=t.code||500),this.errorHandler)return s.result=this.errorHandler(t),s;throw t})}}L.pathToRegexp=y;let F=[];function N(t){F.forEach(t=>t.inactivate()),t.forEach(t=>t.activate()),F=t}const H=t=>{const e=getComputedStyle(t).getPropertyValue("animation-name");return e&&"none"!==e},U=(t,e)=>{const n=()=>{t.removeEventListener("animationend",n),e()};t.addEventListener("animationend",n)};function W(t,e){return t.classList.add(e),new Promise(n=>{if(H(t)){const r=t.getBoundingClientRect(),o=`height: ${r.bottom-r.top}px; width: ${r.right-r.left}px`;t.setAttribute("style",`position: absolute; ${o}`),U(t,()=>{t.classList.remove(e),t.removeAttribute("style"),n()})}else t.classList.remove(e),n()})}const K=256;function V(t){return null!==t&&void 0!==t}function q({pathname:t="",chain:e=[],params:n={},redirectFrom:r},o){return{pathname:t,routes:e.map(t=>t.route),route:!o&&e.length&&e[e.length-1].route||o,params:n,redirectFrom:r}}function z(t,e){const n=Object.assign({},t.params);return{redirect:{pathname:e,from:t.pathname,params:n}}}function G(t,e,n){if(l(t))return t.apply(n,e)}function J(t,e,n){return r=>r&&(r.cancel||r.redirect)?r:n?G(n[t],e,n):void 0}function Q(t){if(t&&t.length){const e=t[0].parentNode;for(let n=0;n<t.length;n++)e.removeChild(t[n])}}class X extends L{constructor(t,e){super([],Object.assign({},e)),this.resolveRoute=(t=>this.s(t));const n=X.NavigationTrigger;X.setTriggers.apply(X,Object.keys(n).map(t=>n[t])),this.ready,this.ready=Promise.resolve(t),this.location,this.location=q({}),this.u=0,this.l=this.h.bind(this),this.setOutlet(t),this.subscribe()}s(n){const r=n.route,i={redirect:t=>z(n,t),component:t=>(function(t,e){const n=document.createElement(e);n.location=q(t);const r=t.chain.map(t=>t.route).indexOf(t.route);return t.chain[r].element=n,n})(n,t)},u=G(r.action,[n,i],r);if(V(u))return u;if(h(r.redirect))return i.redirect(r.redirect);let a=Promise.resolve();var d;return r.bundle&&(a=a.then(()=>(d=r.bundle,h(d)?c(d):Promise.race(o.filter(t=>t in d).map(t=>c(d[t],t))))).catch(()=>{throw new Error(e(`Bundle not found: ${r.bundle}. Check if the file name is correct`))})),l(r.children)&&(a=a.then(()=>r.children(function(t){const e=Object.assign({},t);return delete e.next,e}(n))).then(n=>{V(n)||l(r.children)||(n=r.children),function(n,r){if(!Array.isArray(n)&&!f(n))throw new Error(e(`Incorrect "children" value for the route ${r.path}: expected array or object, but got ${n}`));r.o=[];const o=t(n);for(let t=0;t<o.length;t++)s(o[t]),r.o.push(o[t])}(n,r)})),a.then(()=>{if(h(r.component))return i.component(r.component)})}setOutlet(t){t&&this.p(t),this.m=t}getOutlet(){return this.m}setRoutes(t){super.setRoutes(t),this.h()}render(t,e){const n=++this.u,r=t.pathname||t;return this.ready=this.resolve(t).then(t=>this.v(t)).then(t=>{if(n===this.u){const r=this.g;if(t===r)return this.location;e&&this._(t.pathname,t.redirectFrom),this.$(t,r);const o=this.O(t);return this.j(t),this.P(t,r),o.then(()=>{if(n===this.u)return this.R(),this.g=t,this.location=q(t),a("location-changed",{router:this,location:this.location}),this.location})}}).catch(t=>{if(n===this.u)throw e&&this._(r),Q(this.m&&this.m.children),this.location=q({pathname:r}),a("error",{router:this,error:t,pathname:r}),t}),this.ready}v(t,e=t){return this.k(e).then(n=>{const r=n!==e?n:t;return n.next().then(t=>{if(null===t&&n.pathname!==n.chain.map(t=>t.path).reduce((t,e)=>e.length?t+("/"===t.charAt(t.length-1)?"":"/")+e:t))throw d(r);return t?this.v(r,t):this.C(r)})})}k(t){const n=t.result;return n instanceof HTMLElement?Promise.resolve(t):n.redirect?this.A(n.redirect,t.T).then(t=>this.k(t)):n instanceof Error?Promise.reject(n):Promise.reject(new Error(e(`Invalid route resolution result for path "${t.pathname}". `+`Expected redirect object or HTML element, but got: "${n}". `+"Double check the action return value for the route.")))}C(t){return this.B(t).then(e=>e===this.g||e===t?e:this.v(e))}B(t){const e=(this.g||{}).chain||[],n=t.chain;let r=Promise.resolve();const o=()=>({cancel:!0}),i=e=>z(t,e);if(t.S=0,e.length){for(let r=0;r<Math.min(e.length,n.length)&&(e[r].route===n[r].route&&e[r].path===n[r].path);r=++t.S);for(let n=e.length-1;n>=t.S;n--){const i=q(t);r=r.then(J("onBeforeLeave",[i,{prevent:o},this],e[n].element)).then(t=>{if(!(t||{}).redirect)return t})}}for(let e=t.S;e<n.length;e++){const s=q(t,n[e].route);r=r.then(J("onBeforeEnter",[s,{prevent:o,redirect:i},this],n[e].element))}return r.then(e=>{if(e){if(e.cancel)return this.g;if(e.redirect)return this.A(e.redirect,t.T)}return t})}A(t,n){if(n>K)throw new Error(e(`Too many redirects when rendering ${t.from}`));return this.resolve({pathname:X.pathToRegexp.compile(t.pathname)(t.params),redirectFrom:t.from,T:(n||0)+1})}p(t=this.m){if(!(t instanceof Node))throw new TypeError(e(`Expected router outlet to be a valid DOM Node (but got ${t})`))}_(t,e){if(window.location.pathname!==t){const n=e?"replaceState":"pushState";window.history[n](null,document.title,t),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}$(t,e){this.p(),this.I();let n=this.m;for(let r=0;r<t.S;r++){const o=e&&e.chain[r].element;if(o){if(o.parentNode!==n)break;t.chain[r].element=o,n=o}}this.M=Array.from(n.children),this.D=[];let r=n;for(let e=t.S;e<t.chain.length;e++){const o=t.chain[e].element;o&&(r.appendChild(o),r===n&&this.D.push(o),r=o)}}R(){this.M&&Q(this.M),this.M=null,this.D=null}I(){this.M&&this.D&&(Q(this.D),this.M=null,this.D=null)}P(t,e){if(e)for(let n=e.chain.length-1;n>=t.S;n--){const r=e.chain[n].element;if(r)try{const n=q(t);G(r.onAfterLeave,[n,{},e.resolver],r)}finally{Q(r.children)}}}j(t){for(let e=t.S;e<t.chain.length;e++){const n=t.chain[e].element||{},r=q(t,t.chain[e].route);G(n.onAfterEnter,[r,{},t.resolver],n)}}O(t){const e=(this.M||[])[0],n=(this.D||[])[0],r=[],o=t.chain;let i;for(let t=o.length;t>0;t--)if(o[t-1].route.animate){i=o[t-1].route.animate;break}if(e&&n&&i){const t=f(i)&&i.leave||"leaving",o=f(i)&&i.enter||"entering";r.push(W(e,t)),r.push(W(n,o))}return Promise.all(r).then(()=>t)}subscribe(){window.addEventListener("vaadin-router-go",this.l)}unsubscribe(){window.removeEventListener("vaadin-router-go",this.l)}h(t){const e=t?t.detail.pathname:window.location.pathname;this.render(e,!0)}static setTriggers(...t){N(t)}static go(t){a("go",{pathname:t})}}const Y=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i;function Z(t,e){if("function"!=typeof t)return;const n=Y.exec(t.toString());if(n)try{t=new Function(n[1])}catch(t){console.log("vaadin-development-mode-detector: uncommentAndRun() failed",t)}return t(e)}window.Vaadin=window.Vaadin||{};const tt=function(t,e){if(window.Vaadin.developmentMode)return Z(t,e)};function et(){}void 0===window.Vaadin.developmentMode&&(window.Vaadin.developmentMode=function(){try{return localStorage.getItem("vaadin.developmentmode.force")||["localhost","127.0.0.1"].indexOf(window.location.hostname)>=0&&!Z(function(){return!0})&&!function(){if(window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients){const t=Object.keys(window.Vaadin.Flow.clients).map(t=>window.Vaadin.Flow.clients[t]).filter(t=>t.productionMode);if(t.length>0)return!0}return!1}()}catch(t){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.1.0"}),tt(et),X.NavigationTrigger={POPSTATE:v,CLICK:p};export{X as Router,L as Resolver};
function t(t){return t=t||[],Array.isArray(t)?t:[t]}function e(t){return`[Vaadin.Router] ${t}`}const n="module",r="nomodule",o=[n,r];function i(t){if(!t.match(/.+\.[m]?js$/))throw new Error(e(`Unsupported type for bundle "${t}": .js or .mjs expected.`))}function s(t){if(!t||!h(t.path))throw new Error(e('Expected route config to be an object with a "path" string property, or an array of such objects'));const s=t.bundle,u=["component","redirect","bundle"];if(!(l(t.action)||Array.isArray(t.children)||l(t.children)||f(s)||u.some(e=>h(t[e]))))throw new Error(e(`Expected route config "${t.path}" to include either "${u.join('", "')}" `+'or "action" function but none found.'));if(s)if(h(s))i(s);else{if(!o.some(t=>t in s))throw new Error(e('Expected route bundle to include either "'+r+'" or "'+n+'" keys, or both'));o.forEach(t=>t in s&&i(s[t]))}t.redirect&&["bundle","component"].forEach(n=>{n in t&&console.warn(e(`Route config "${t.path}" has both "redirect" and "${n}" properties, `+`and "redirect" will always override the latter. Did you mean to only use "${n}"?`))})}function u(e){t(e).forEach(t=>s(t))}function c(t,e){let o=document.head.querySelector('script[src="'+t+'"][async]');return o||((o=document.createElement("script")).setAttribute("src",t),e===n?o.setAttribute("type",n):e===r&&o.setAttribute(r,""),o.async=!0),new Promise((t,e)=>{o.onreadystatechange=o.onload=(e=>{o.t=!0,t(e)}),o.onerror=(t=>{o.parentNode&&o.parentNode.removeChild(o),e(t)}),null===o.parentNode?document.head.appendChild(o):o.t&&t()})}function a(t,e){window.dispatchEvent(new CustomEvent(`vaadin-router-${t}`,{detail:e}))}function f(t){return"object"==typeof t&&!!t}function l(t){return"function"==typeof t}function h(t){return"string"==typeof t}function d(t){const n=new Error(e(`Page not found (${t.pathname})`));return n.context=t,n.code=404,n}const w=new class{};function p(t){if(t.defaultPrevented)return;if(0!==t.button)return;if(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)return;let e=t.target;const n=t.composedPath?t.composedPath():t.path||[];for(let t=0;t<n.length;t++){const r=n[t];if(r.nodeName&&"a"===r.nodeName.toLowerCase()){e=r;break}}for(;e&&"a"!==e.nodeName.toLowerCase();)e=e.parentNode;e&&"a"===e.nodeName.toLowerCase()&&(e.target&&"_self"!==e.target.toLowerCase()||e.hasAttribute("download")||e.pathname===window.location.pathname&&""!==e.hash||(e.origin||function(t){const e=t.port,n=t.protocol;return`${n}//${"http:"===n&&"80"===e||"https:"===n&&"443"===e?t.hostname:t.host}`}(e))===window.location.origin&&(t.preventDefault(),a("go",{pathname:e.pathname})))}const m={activate(){window.document.addEventListener("click",p)},inactivate(){window.document.removeEventListener("click",p)}};function v(t){"vaadin-router-ignore"!==t.state&&a("go",{pathname:window.location.pathname})}/Trident/.test(navigator.userAgent)&&!l(window.PopStateEvent)&&(window.PopStateEvent=function(t,e){e=e||{};var n=document.createEvent("Event");return n.initEvent(t,Boolean(e.bubbles),Boolean(e.cancelable)),n.state=e.state||null,n},window.PopStateEvent.prototype=window.Event.prototype);const y={activate(){window.addEventListener("popstate",v)},inactivate(){window.removeEventListener("popstate",v)}};var b=S,g=P,E=function(t,e){return R(P(t,e))},$=R,_=T,x="/",O="./",j=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function P(t,e){for(var n,r=[],o=0,i=0,s="",u=e&&e.delimiter||x,c=e&&e.delimiters||O,a=!1;null!==(n=j.exec(t));){var f=n[0],l=n[1],h=n.index;if(s+=t.slice(i,h),i=h+f.length,l)s+=l[1],a=!0;else{var d="",w=t[i],p=n[2],m=n[3],v=n[4],y=n[5];if(!a&&s.length){var b=s.length-1;c.indexOf(s[b])>-1&&(d=s[b],s=s.slice(0,b))}s&&(r.push(s),s="",a=!1);var g=""!==d&&void 0!==w&&w!==d,E="+"===y||"*"===y,$="?"===y||"*"===y,_=d||u,P=m||v;r.push({name:p||o++,prefix:d,delimiter:_,optional:$,repeat:E,partial:g,pattern:P?C(P):"[^"+k(_)+"]+?"})}}return(s||i<t.length)&&r.push(s+t.substr(i)),r}function R(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,r){for(var o="",i=r&&r.encode||encodeURIComponent,s=0;s<t.length;s++){var u=t[s];if("string"!=typeof u){var c,a=n?n[u.name]:void 0;if(Array.isArray(a)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===a.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var f=0;f<a.length;f++){if(c=i(a[f],u),!e[s].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===f?u.prefix:u.delimiter)+c}}else if("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(c=i(String(a),u),!e[s].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');o+=u.prefix+c}}else o+=u}return o}}function k(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function C(t){return t.replace(/([=!:$/()])/g,"\\$1")}function A(t){return t&&t.sensitive?"":"i"}function T(t,e,n){for(var r=(n=n||{}).strict,o=!1!==n.end,i=k(n.delimiter||x),s=n.delimiters||O,u=[].concat(n.endsWith||[]).map(k).concat("$").join("|"),c="",a=0===t.length,f=0;f<t.length;f++){var l=t[f];if("string"==typeof l)c+=k(l),a=f===t.length-1&&s.indexOf(l[l.length-1])>-1;else{var h=k(l.prefix),d=l.repeat?"(?:"+l.pattern+")(?:"+h+"(?:"+l.pattern+"))*":l.pattern;e&&e.push(l),l.optional?l.partial?c+=h+"("+d+")?":c+="(?:"+h+"("+d+"))?":c+=h+"("+d+")"}}return o?(r||(c+="(?:"+i+")?"),c+="$"===u?"$":"(?="+u+")"):(r||(c+="(?:"+i+"(?="+u+"))?"),a||(c+="(?="+i+"|"+u+")")),new RegExp("^"+c,A(n))}function S(t,e,n){return t instanceof RegExp?function(t,e){if(!e)return t;var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return t}(t,e):Array.isArray(t)?function(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(S(t[o],e,n).source);return new RegExp("(?:"+r.join("|")+")",A(n))}(t,e,n):function(t,e,n){return T(P(t,n),e,n)}(t,e,n)}b.parse=g,b.compile=E,b.tokensToFunction=$,b.tokensToRegExp=_;const{hasOwnProperty:B}=Object.prototype,I=new Map;function M(t){try{return decodeURIComponent(t)}catch(e){return t}}function L(t,e,n,r,o){let i,s,u=0,c=t.path||"";return"/"===c.charAt(0)&&(n&&(c=c.substr(1)),n=!0),{next(a){if(t===a)return{done:!0};const f=t.o=t.o||t.children;if(!i&&(i=function(t,e,n,r,o){const i=`${t}|${n=!!n}`;let s=I.get(i);if(!s){const e=[];s={keys:e,pattern:b(t,e,{end:n,strict:""===t})},I.set(i,s)}const u=s.pattern.exec(e);if(!u)return null;const c=Object.assign({},o);for(let t=1;t<u.length;t++){const e=s.keys[t-1],n=e.name,r=u[t];void 0===r&&B.call(c,n)||(e.repeat?c[n]=r?r.split(e.delimiter).map(M):[]:c[n]=r?M(r):r)}return{path:u[0],keys:(r||[]).concat(s.keys),params:c}}(c,e,!f,r,o)))return{done:!1,value:{route:t,keys:i.keys,params:i.params,path:i.path}};if(i&&f)for(;u<f.length;){if(!s){const r=f[u];r.parent=t;let o=i.path.length;o>0&&"/"===e.charAt(o)&&(o+=1),s=L(r,e.substr(o),n,i.keys,i.params)}const r=s.next(a);if(!r.done)return{done:!1,value:r.value};s=null,u++}return{done:!0}}}}function D(t){if(l(t.route.action))return t.route.action(t)}I.set("|false",{keys:[],pattern:/(?:)/});class F{constructor(t,e={}){if(Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=e.baseUrl||"",this.errorHandler=e.errorHandler,this.resolveRoute=e.resolveRoute||D,this.context=Object.assign({resolver:this},e.context),this.root=Array.isArray(t)?{path:"",o:t,parent:null,i:!0}:t,this.root.parent=null}getRoutes(){return[...this.root.o]}setRoutes(e){u(e);const n=[...t(e)];this.root.o=n}addRoutes(e){return u(e),this.root.o.push(...t(e)),this.getRoutes()}removeRoutes(){this.setRoutes([])}resolve(t){const e=Object.assign({},this.context,h(t)?{pathname:t}:t),n=L(this.root,e.pathname.substr(this.baseUrl.length)),r=this.resolveRoute;let o=null,i=null,s=e;function u(t,c=o.value.route,a){const f=null===a&&o.value.route;return o=i||n.next(f),i=null,t||!o.done&&function(t,e){let n=e;for(;n;)if((n=n.parent)===t)return!0;return!1}(c,o.value.route)?o.done?Promise.reject(d(e)):(function(t,e){const{route:n,path:r}=e;if(n&&!n.i){const e={path:r,route:n};!function(t,e){return!e.parent||!t||!t.length||t[t.length-1].route!==e.parent}(t.chain,n)?t.chain.push(e):t.chain=[e]}}(e,o.value),s=Object.assign({},e,o.value),Promise.resolve(r(s)).then(e=>null!==e&&void 0!==e&&e!==w?(s.result=e.result||e,s):u(t,c,e))):(i=o,Promise.resolve(w))}return e.next=u,Promise.resolve().then(()=>u(!0,this.root)).catch(t=>{const e=function(t){let e=`Path '${t.pathname}' is not properly resolved due to an error.`;const n=(t.route||{}).path;return n&&(e+=` Resolution had failed on route: '${n}'`),e}(s);if(t?console.warn(e):t=new Error(e),t.context=t.context||s,t instanceof DOMException||(t.code=t.code||500),this.errorHandler)return s.result=this.errorHandler(t),s;throw t})}}F.pathToRegexp=b;let N=[];function H(t){N.forEach(t=>t.inactivate()),t.forEach(t=>t.activate()),N=t}const U=t=>{const e=getComputedStyle(t).getPropertyValue("animation-name");return e&&"none"!==e},W=(t,e)=>{const n=()=>{t.removeEventListener("animationend",n),e()};t.addEventListener("animationend",n)};function J(t,e){return t.classList.add(e),new Promise(n=>{if(U(t)){const r=t.getBoundingClientRect(),o=`height: ${r.bottom-r.top}px; width: ${r.right-r.left}px`;t.setAttribute("style",`position: absolute; ${o}`),W(t,()=>{t.classList.remove(e),t.removeAttribute("style"),n()})}else t.classList.remove(e),n()})}const K=256;function V(t){return null!==t&&void 0!==t}function q({pathname:t="",chain:e=[],params:n={},redirectFrom:r},o){return{pathname:t,routes:e.map(t=>t.route),route:!o&&e.length&&e[e.length-1].route||o,params:n,redirectFrom:r}}function z(t,e){const n=Object.assign({},t.params);return{redirect:{pathname:e,from:t.pathname,params:n}}}function G(t,e,n){if(l(t))return t.apply(n,e)}function Q(t,e,n){return r=>r&&(r.cancel||r.redirect)?r:n?G(n[t],e,n):void 0}function X(t){if(t&&t.length){const e=t[0].parentNode;for(let n=0;n<t.length;n++)e.removeChild(t[n])}}class Y extends F{constructor(t,e){super([],Object.assign({},e)),this.resolveRoute=(t=>this.s(t));const n=Y.NavigationTrigger;Y.setTriggers.apply(Y,Object.keys(n).map(t=>n[t])),this.ready,this.ready=Promise.resolve(t),this.location,this.location=q({}),this.u=0,this.l=this.h.bind(this),this.setOutlet(t),this.subscribe()}s(n){const r=n.route;let i=Promise.resolve();l(r.children)&&(i=i.then(()=>r.children(function(t){const e=Object.assign({},t);return delete e.next,e}(n))).then(n=>{V(n)||l(r.children)||(n=r.children),function(n,r){if(!Array.isArray(n)&&!f(n))throw new Error(e(`Incorrect "children" value for the route ${r.path}: expected array or object, but got ${n}`));r.o=[];const o=t(n);for(let t=0;t<o.length;t++)s(o[t]),r.o.push(o[t])}(n,r)}));const u={redirect:t=>z(n,t),component:t=>(function(t,e){const n=document.createElement(e);n.location=q(t);const r=t.chain.map(t=>t.route).indexOf(t.route);return t.chain[r].element=n,n})(n,t)};return i.then(()=>G(r.action,[n,u],r)).then(t=>V(t)&&(t instanceof HTMLElement||t.redirect||t===w)?t:h(r.redirect)?u.redirect(r.redirect):r.bundle?(a=r.bundle,h(a)?c(a):Promise.race(o.filter(t=>t in a).map(t=>c(a[t],t)))).then(()=>{},()=>{throw new Error(e(`Bundle not found: ${r.bundle}. Check if the file name is correct`))}):void 0).then(t=>V(t)?t:h(r.component)?u.component(r.component):void 0);var a}setOutlet(t){t&&this.p(t),this.m=t}getOutlet(){return this.m}setRoutes(t){super.setRoutes(t),this.h()}render(t,e){const n=++this.u,r=t.pathname||t;return this.ready=this.resolve(t).then(t=>this.v(t)).then(t=>{if(n===this.u){const r=this.g;if(t===r)return this.location;e&&this.$(t.pathname,t.redirectFrom),this._(t,r);const o=this.O(t);return this.j(t),this.P(t,r),o.then(()=>{if(n===this.u)return this.R(),this.g=t,this.location=q(t),a("location-changed",{router:this,location:this.location}),this.location})}}).catch(t=>{if(n===this.u)throw e&&this.$(r),X(this.m&&this.m.children),this.location=q({pathname:r}),a("error",{router:this,error:t,pathname:r}),t}),this.ready}v(t,e=t){return this.k(e).then(n=>{const r=n!==e?n:t;return n.next().then(t=>{if((null===t||t===w)&&n.pathname!==n.chain.map(t=>t.path).reduce((t,e)=>e.length?t+("/"===t.charAt(t.length-1)?"":"/")+e:t))throw d(r);return t&&t!==w?this.v(r,t):this.C(r)})})}k(t){const n=t.result;return n instanceof HTMLElement?Promise.resolve(t):n.redirect?this.A(n.redirect,t.T).then(t=>this.k(t)):n instanceof Error?Promise.reject(n):Promise.reject(new Error(e(`Invalid route resolution result for path "${t.pathname}". `+`Expected redirect object or HTML element, but got: "${function(t){if("object"!=typeof t)return String(t);const e=Object.prototype.toString.call(t).match(/ (.*)\]$/)[1];return"Object"===e||"Array"===e?`${e} ${JSON.stringify(t)}`:e}(n)}". `+"Double check the action return value for the route.")))}C(t){return this.S(t).then(e=>e===this.g||e===t?e:this.v(e))}S(t){const e=(this.g||{}).chain||[],n=t.chain;let r=Promise.resolve();const o=()=>({cancel:!0}),i=e=>z(t,e);if(t.B=0,e.length){for(let r=0;r<Math.min(e.length,n.length)&&(e[r].route===n[r].route&&e[r].path===n[r].path&&(e[r].element&&e[r].element.localName)===(n[r].element&&n[r].element.localName));r=++t.B);for(let n=e.length-1;n>=t.B;n--){const i=q(t);r=r.then(Q("onBeforeLeave",[i,{prevent:o},this],e[n].element)).then(t=>{if(!(t||{}).redirect)return t})}}for(let e=t.B;e<n.length;e++){const s=q(t,n[e].route);r=r.then(Q("onBeforeEnter",[s,{prevent:o,redirect:i},this],n[e].element))}return r.then(e=>{if(e){if(e.cancel)return this.g;if(e.redirect)return this.A(e.redirect,t.T)}return t})}A(t,n){if(n>K)throw new Error(e(`Too many redirects when rendering ${t.from}`));return this.resolve({pathname:this.constructor.urlForPath(t.pathname,t.params),redirectFrom:t.from,T:(n||0)+1})}p(t=this.m){if(!(t instanceof Node))throw new TypeError(e(`Expected router outlet to be a valid DOM Node (but got ${t})`))}$(t,e){if(window.location.pathname!==t){const n=e?"replaceState":"pushState";window.history[n](null,document.title,t),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}_(t,e){this.p(),this.I();let n=this.m;for(let r=0;r<t.B;r++){const o=e&&e.chain[r].element;if(o){if(o.parentNode!==n)break;t.chain[r].element=o,n=o}}this.M=Array.from(n.children),this.L=[];let r=n;for(let e=t.B;e<t.chain.length;e++){const o=t.chain[e].element;o&&(r.appendChild(o),r===n&&this.L.push(o),r=o)}}R(){this.M&&X(this.M),this.M=null,this.L=null}I(){this.M&&this.L&&(X(this.L),this.M=null,this.L=null)}P(t,e){if(e)for(let n=e.chain.length-1;n>=t.B;n--){const r=e.chain[n].element;if(r)try{const n=q(t);G(r.onAfterLeave,[n,{},e.resolver],r)}finally{X(r.children)}}}j(t){for(let e=t.B;e<t.chain.length;e++){const n=t.chain[e].element||{},r=q(t,t.chain[e].route);G(n.onAfterEnter,[r,{},t.resolver],n)}}O(t){const e=(this.M||[])[0],n=(this.L||[])[0],r=[],o=t.chain;let i;for(let t=o.length;t>0;t--)if(o[t-1].route.animate){i=o[t-1].route.animate;break}if(e&&n&&i){const t=f(i)&&i.leave||"leaving",o=f(i)&&i.enter||"entering";r.push(J(e,t)),r.push(J(n,o))}return Promise.all(r).then(()=>t)}subscribe(){window.addEventListener("vaadin-router-go",this.l)}unsubscribe(){window.removeEventListener("vaadin-router-go",this.l)}h(t){const e=t?t.detail.pathname:window.location.pathname;this.render(e,!0)}static setTriggers(...t){H(t)}static urlForPath(t,e){return Y.pathToRegexp.compile(t)(e)}static go(t){a("go",{pathname:t})}}const Z=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i;function tt(t,e){if("function"!=typeof t)return;const n=Z.exec(t.toString());if(n)try{t=new Function(n[1])}catch(t){console.log("vaadin-development-mode-detector: uncommentAndRun() failed",t)}return t(e)}window.Vaadin=window.Vaadin||{};const et=function(t,e){if(window.Vaadin.developmentMode)return tt(t,e)};function nt(){}void 0===window.Vaadin.developmentMode&&(window.Vaadin.developmentMode=function(){try{return localStorage.getItem("vaadin.developmentmode.force")||["localhost","127.0.0.1"].indexOf(window.location.hostname)>=0&&!tt(function(){return!0})&&!function(){if(window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients){const t=Object.keys(window.Vaadin.Flow.clients).map(t=>window.Vaadin.Flow.clients[t]).filter(t=>t.productionMode);if(t.length>0)return!0}return!1}()}catch(t){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.1.0"}),et(nt),Y.NavigationTrigger={POPSTATE:y,CLICK:m};export{Y as Router,F as Resolver};

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Vaadin=e.Vaadin||{})}(this,function(e){"use strict";var t="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},n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},i=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)};function a(e){return e=e||[],Array.isArray(e)?e:[e]}function u(e){return"[Vaadin.Router] "+e}var c="module",l="nomodule",s=[c,l];function d(e){if(!e.match(/.+\.[m]?js$/))throw new Error(u('Unsupported type for bundle "'+e+'": .js or .mjs expected.'))}function f(e){if(!e||!g(e.path))throw new Error(u('Expected route config to be an object with a "path" string property, or an array of such objects'));var t=e.bundle,n=["component","redirect","bundle"];if(!(m(e.action)||Array.isArray(e.children)||m(e.children)||_(t)||n.some(function(t){return g(e[t])})))throw new Error(u('Expected route config "'+e.path+'" to include either "'+n.join('", "')+'" or "action" function but none found.'));if(t)if(g(t))d(t);else{if(!s.some(function(e){return e in t}))throw new Error(u('Expected route bundle to include either "'+l+'" or "'+c+'" keys, or both'));s.forEach(function(e){return e in t&&d(t[e])})}e.redirect&&["bundle","component"].forEach(function(t){t in e&&console.warn(u('Route config "'+e.path+'" has both "redirect" and "'+t+'" properties, and "redirect" will always override the latter. Did you mean to only use "'+t+'"?'))})}function h(e){a(e).forEach(function(e){return f(e)})}function p(e,t){var n=document.head.querySelector('script[src="'+e+'"][async]');return n||((n=document.createElement("script")).setAttribute("src",e),t===c?n.setAttribute("type",c):t===l&&n.setAttribute(l,""),n.async=!0),new Promise(function(e,t){n.onreadystatechange=n.onload=function(t){n.__dynamicImportLoaded=!0,e(t)},n.onerror=function(e){n.parentNode&&n.parentNode.removeChild(n),t(e)},null===n.parentNode?document.head.appendChild(n):n.__dynamicImportLoaded&&e()})}function v(e,t){window.dispatchEvent(new CustomEvent("vaadin-router-"+e,{detail:t}))}function _(e){return"object"===(void 0===e?"undefined":t(e))&&!!e}function m(e){return"function"==typeof e}function g(e){return"string"==typeof e}function y(e){var t=new Error(u("Page not found ("+e.pathname+")"));return t.context=e,t.code=404,t}function w(e){if(!e.defaultPrevented&&0===e.button&&!(e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){for(var t=e.target,n=e.composedPath?e.composedPath():e.path||[],r=0;r<n.length;r++){var o=n[r];if(o.nodeName&&"a"===o.nodeName.toLowerCase()){t=o;break}}for(;t&&"a"!==t.nodeName.toLowerCase();)t=t.parentNode;if(t&&"a"===t.nodeName.toLowerCase())if(!t.target||"_self"===t.target.toLowerCase())if(!t.hasAttribute("download"))if(t.pathname!==window.location.pathname||""===t.hash)(t.origin||function(e){var t=e.port,n=e.protocol;return n+"//"+("http:"===n&&"80"===t||"https:"===n&&"443"===t?e.hostname:e.host)}(t))===window.location.origin&&(e.preventDefault(),v("go",{pathname:t.pathname}))}}var b={activate:function(){window.document.addEventListener("click",w)},inactivate:function(){window.document.removeEventListener("click",w)}};function E(e){"vaadin-router-ignore"!==e.state&&v("go",{pathname:window.location.pathname})}/Trident/.test(navigator.userAgent)&&!m(window.PopStateEvent)&&(window.PopStateEvent=function(e,t){t=t||{};var n=document.createEvent("Event");return n.initEvent(e,Boolean(t.bubbles),Boolean(t.cancelable)),n.state=t.state||null,n},window.PopStateEvent.prototype=window.Event.prototype);var x={activate:function(){window.addEventListener("popstate",E)},inactivate:function(){window.removeEventListener("popstate",E)}},C=H,k=L,O=function(e,t){return S(L(e,t))},R=S,A=B,j="/",P="./",I=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function L(e,t){for(var n,r=[],o=0,i=0,a="",u=t&&t.delimiter||j,c=t&&t.delimiters||P,l=!1;null!==(n=I.exec(e));){var s=n[0],d=n[1],f=n.index;if(a+=e.slice(i,f),i=f+s.length,d)a+=d[1],l=!0;else{var h="",p=e[i],v=n[2],_=n[3],m=n[4],g=n[5];if(!l&&a.length){var y=a.length-1;c.indexOf(a[y])>-1&&(h=a[y],a=a.slice(0,y))}a&&(r.push(a),a="",l=!1);var w=""!==h&&void 0!==p&&p!==h,b="+"===g||"*"===g,E="?"===g||"*"===g,x=h||u,C=_||m;r.push({name:v||o++,prefix:h,delimiter:x,optional:E,repeat:b,partial:w,pattern:C?N(C):"[^"+T(x)+"]+?"})}}return(a||i<e.length)&&r.push(a+e.substr(i)),r}function S(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"===t(e[r])&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(t,r){for(var o="",i=r&&r.encode||encodeURIComponent,a=0;a<e.length;a++){var u=e[a];if("string"!=typeof u){var c,l=t?t[u.name]:void 0;if(Array.isArray(l)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===l.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var s=0;s<l.length;s++){if(c=i(l[s],u),!n[a].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===s?u.prefix:u.delimiter)+c}}else if("string"!=typeof l&&"number"!=typeof l&&"boolean"!=typeof l){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(c=i(String(l),u),!n[a].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');o+=u.prefix+c}}else o+=u}return o}}function T(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function N(e){return e.replace(/([=!:$/()])/g,"\\$1")}function V(e){return e&&e.sensitive?"":"i"}function B(e,t,n){for(var r=(n=n||{}).strict,o=!1!==n.end,i=T(n.delimiter||j),a=n.delimiters||P,u=[].concat(n.endsWith||[]).map(T).concat("$").join("|"),c="",l=0===e.length,s=0;s<e.length;s++){var d=e[s];if("string"==typeof d)c+=T(d),l=s===e.length-1&&a.indexOf(d[d.length-1])>-1;else{var f=T(d.prefix),h=d.repeat?"(?:"+d.pattern+")(?:"+f+"(?:"+d.pattern+"))*":d.pattern;t&&t.push(d),d.optional?d.partial?c+=f+"("+h+")?":c+="(?:"+f+"("+h+"))?":c+=f+"("+h+")"}}return o?(r||(c+="(?:"+i+")?"),c+="$"===u?"$":"(?="+u+")"):(r||(c+="(?:"+i+"(?="+u+"))?"),l||(c+="(?="+i+"|"+u+")")),new RegExp("^"+c,V(n))}function H(e,t,n){return e instanceof RegExp?function(e,t){if(!t)return e;var n=e.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)t.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}(e,t):Array.isArray(e)?function(e,t,n){for(var r=[],o=0;o<e.length;o++)r.push(H(e[o],t,n).source);return new RegExp("(?:"+r.join("|")+")",V(n))}(e,t,n):function(e,t,n){return B(L(e,n),t,n)}(e,t,n)}C.parse=k,C.compile=O,C.tokensToFunction=R,C.tokensToRegExp=A;var F=Object.prototype.hasOwnProperty,M=new Map;function $(e){try{return decodeURIComponent(e)}catch(t){return e}}function D(e,t,n,r,o){var i=void 0,a=void 0,u=0,c=e.path||"";return"/"===c.charAt(0)&&(n&&(c=c.substr(1)),n=!0),{next:function(l){if(e===l)return{done:!0};var s=e.__children=e.__children||e.children;if(!i&&(i=function(e,t,n,r,o){var i=e+"|"+(n=!!n),a=M.get(i);if(!a){var u=[];a={keys:u,pattern:C(e,u,{end:n,strict:""===e})},M.set(i,a)}var c=a.pattern.exec(t);if(!c)return null;for(var l=Object.assign({},o),s=1;s<c.length;s++){var d=a.keys[s-1],f=d.name,h=c[s];void 0===h&&F.call(l,f)||(d.repeat?l[f]=h?h.split(d.delimiter).map($):[]:l[f]=h?$(h):h)}return{path:c[0],keys:(r||[]).concat(a.keys),params:l}}(c,t,!s,r,o)))return{done:!1,value:{route:e,keys:i.keys,params:i.params,path:i.path}};if(i&&s)for(;u<s.length;){if(!a){var d=s[u];d.parent=e;var f=i.path.length;f>0&&"/"===t.charAt(f)&&(f+=1),a=D(d,t.substr(f),n,i.keys,i.params)}var h=a.next(l);if(!h.done)return{done:!1,value:h.value};a=null,u++}return{done:!0}}}}function U(e){if(m(e.route.action))return e.route.action(e)}M.set("|false",{keys:[],pattern:/(?:)/});var W=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.errorHandler=r.errorHandler,this.resolveRoute=r.resolveRoute||U,this.context=Object.assign({resolver:this},r.context),this.root=Array.isArray(t)?{path:"",__children:t,parent:null,__synthetic:!0}:t,this.root.parent=null}return r(e,[{key:"getRoutes",value:function(){return[].concat(i(this.root.__children))}},{key:"setRoutes",value:function(e){h(e);var t=[].concat(i(a(e)));this.root.__children=t}},{key:"addRoutes",value:function(e){var t;return h(e),(t=this.root.__children).push.apply(t,i(a(e))),this.getRoutes()}},{key:"removeRoutes",value:function(){this.setRoutes([])}},{key:"resolve",value:function(e){var t=this,n=Object.assign({},this.context,g(e)?{pathname:e}:e),r=D(this.root,n.pathname.substr(this.baseUrl.length)),o=this.resolveRoute,i=null,a=null,u=n;function c(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i.value.route,l=null===arguments[2]&&i.value.route;return i=a||r.next(l),a=null,e||!i.done&&function(e,t){for(var n=t;n;)if((n=n.parent)===e)return!0;return!1}(t,i.value.route)?i.done?Promise.reject(y(n)):(function(e,t){var n=t.route,r=t.path;if(n&&!n.__synthetic){var o={path:r,route:n};!function(e,t){return!t.parent||!e||!e.length||e[e.length-1].route!==t.parent}(e.chain,n)?e.chain.push(o):e.chain=[o]}}(n,i.value),u=Object.assign({},n,i.value),Promise.resolve(o(u)).then(function(n){return null!==n&&void 0!==n?(u.result=n.result||n,u):c(e,t,n)})):(a=i,Promise.resolve(null))}return n.next=c,Promise.resolve().then(function(){return c(!0,t.root)}).catch(function(e){var n=function(e){var t="Path '"+e.pathname+"' is not properly resolved due to an error.",n=(e.route||{}).path;return n&&(t+=" Resolution had failed on route: '"+n+"'"),t}(u);if(e?console.warn(n):e=new Error(n),e.context=e.context||u,e instanceof DOMException||(e.code=e.code||500),t.errorHandler)return u.result=t.errorHandler(e),u;throw e})}}]),e}();W.pathToRegexp=C;var K=[];function q(e){K.forEach(function(e){return e.inactivate()}),e.forEach(function(e){return e.activate()}),K=e}var z=function(e){var t=getComputedStyle(e).getPropertyValue("animation-name");return t&&"none"!==t},G=function(e,t){e.addEventListener("animationend",function n(){e.removeEventListener("animationend",n),t()})};function J(e,t){return e.classList.add(t),new Promise(function(n){if(z(e)){var r=e.getBoundingClientRect(),o="height: "+(r.bottom-r.top)+"px; width: "+(r.right-r.left)+"px";e.setAttribute("style","position: absolute; "+o),G(e,function(){e.classList.remove(t),e.removeAttribute("style"),n()})}else e.classList.remove(t),n()})}function Q(e){return null!==e&&void 0!==e}function X(e,t){var n=e.pathname,r=void 0===n?"":n,o=e.chain,i=void 0===o?[]:o,a=e.params,u=void 0===a?{}:a,c=e.redirectFrom;return{pathname:r,routes:i.map(function(e){return e.route}),route:!t&&i.length&&i[i.length-1].route||t,params:u,redirectFrom:c}}function Y(e,t){var n=Object.assign({},e.params);return{redirect:{pathname:t,from:e.pathname,params:n}}}function Z(e,t,n){if(m(e))return e.apply(n,t)}function ee(e,t,n){return function(r){return r&&(r.cancel||r.redirect)?r:n?Z(n[e],t,n):void 0}}function te(e){if(e&&e.length)for(var t=e[0].parentNode,n=0;n<e.length;n++)t.removeChild(e[n])}var ne=function(e){function t(e,r){n(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,[],Object.assign({},r)));i.resolveRoute=function(e){return i.__resolveRoute(e)};var a=t.NavigationTrigger;return t.setTriggers.apply(t,Object.keys(a).map(function(e){return a[e]})),i.ready,i.ready=Promise.resolve(e),i.location,i.location=X({}),i.__lastStartedRenderId=0,i.__navigationEventHandler=i.__onNavigationEvent.bind(i),i.setOutlet(e),i.subscribe(),i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,W),r(t,[{key:"__resolveRoute",value:function(e){var t=e.route,n={redirect:function(t){return Y(e,t)},component:function(t){return function(e,t){var n=document.createElement(t);n.location=X(e);var r=e.chain.map(function(e){return e.route}).indexOf(e.route);return e.chain[r].element=n,n}(e,t)}},r=Z(t.action,[e,n],t);if(Q(r))return r;if(g(t.redirect))return n.redirect(t.redirect);var o=Promise.resolve();return t.bundle&&(o=o.then(function(){return g(e=t.bundle)?p(e):Promise.race(s.filter(function(t){return t in e}).map(function(t){return p(e[t],t)}));var e}).catch(function(){throw new Error(u("Bundle not found: "+t.bundle+". Check if the file name is correct"))})),m(t.children)&&(o=o.then(function(){return t.children(function(e){var t=Object.assign({},e);return delete t.next,t}(e))}).then(function(e){Q(e)||m(t.children)||(e=t.children),function(e,t){if(!Array.isArray(e)&&!_(e))throw new Error(u('Incorrect "children" value for the route '+t.path+": expected array or object, but got "+e));t.__children=[];for(var n=a(e),r=0;r<n.length;r++)f(n[r]),t.__children.push(n[r])}(e,t)})),o.then(function(){if(g(t.component))return n.component(t.component)})}},{key:"setOutlet",value:function(e){e&&this.__ensureOutlet(e),this.__outlet=e}},{key:"getOutlet",value:function(){return this.__outlet}},{key:"setRoutes",value:function(e){(function e(t,n,r){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,r)}if("value"in o)return o.value;var a=o.get;return void 0!==a?a.call(r):void 0})(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"setRoutes",this).call(this,e),this.__onNavigationEvent()}},{key:"render",value:function(e,t){var n=this,r=++this.__lastStartedRenderId,o=e.pathname||e;return this.ready=this.resolve(e).then(function(e){return n.__fullyResolveChain(e)}).then(function(e){if(r===n.__lastStartedRenderId){var o=n.__previousContext;if(e===o)return n.location;t&&n.__updateBrowserHistory(e.pathname,e.redirectFrom),n.__addAppearingContent(e,o);var i=n.__animateIfNeeded(e);return n.__runOnAfterEnterCallbacks(e),n.__runOnAfterLeaveCallbacks(e,o),i.then(function(){if(r===n.__lastStartedRenderId)return n.__removeDisappearingContent(),n.__previousContext=e,n.location=X(e),v("location-changed",{router:n,location:n.location}),n.location})}}).catch(function(e){if(r===n.__lastStartedRenderId)throw t&&n.__updateBrowserHistory(o),te(n.__outlet&&n.__outlet.children),n.location=X({pathname:o}),v("error",{router:n,error:e,pathname:o}),e}),this.ready}},{key:"__fullyResolveChain",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return this.__amendWithResolutionResult(n).then(function(r){var o=r!==n?r:e;return r.next().then(function(e){if(null===e&&r.pathname!==r.chain.map(function(e){return e.path}).reduce(function(e,t){return t.length?e+("/"===e.charAt(e.length-1)?"":"/")+t:e}))throw y(o);return e?t.__fullyResolveChain(o,e):t.__amendWithOnBeforeCallbacks(o)})})}},{key:"__amendWithResolutionResult",value:function(e){var t=this,n=e.result;return n instanceof HTMLElement?Promise.resolve(e):n.redirect?this.__redirect(n.redirect,e.__redirectCount).then(function(e){return t.__amendWithResolutionResult(e)}):n instanceof Error?Promise.reject(n):Promise.reject(new Error(u('Invalid route resolution result for path "'+e.pathname+'". Expected redirect object or HTML element, but got: "'+n+'". Double check the action return value for the route.')))}},{key:"__amendWithOnBeforeCallbacks",value:function(e){var t=this;return this.__runOnBeforeCallbacks(e).then(function(n){return n===t.__previousContext||n===e?n:t.__fullyResolveChain(n)})}},{key:"__runOnBeforeCallbacks",value:function(e){var t=this,n=(this.__previousContext||{}).chain||[],r=e.chain,o=Promise.resolve(),i=function(){return{cancel:!0}},a=function(t){return Y(e,t)};if(e.__divergedChainIndex=0,n.length){for(var u=0;u<Math.min(n.length,r.length)&&(n[u].route===r[u].route&&n[u].path===r[u].path);u=++e.__divergedChainIndex);for(var c=n.length-1;c>=e.__divergedChainIndex;c--){var l=X(e);o=o.then(ee("onBeforeLeave",[l,{prevent:i},this],n[c].element)).then(function(e){if(!(e||{}).redirect)return e})}}for(var s=e.__divergedChainIndex;s<r.length;s++){var d=X(e,r[s].route);o=o.then(ee("onBeforeEnter",[d,{prevent:i,redirect:a},this],r[s].element))}return o.then(function(n){if(n){if(n.cancel)return t.__previousContext;if(n.redirect)return t.__redirect(n.redirect,e.__redirectCount)}return e})}},{key:"__redirect",value:function(e,n){if(n>256)throw new Error(u("Too many redirects when rendering "+e.from));return this.resolve({pathname:t.pathToRegexp.compile(e.pathname)(e.params),redirectFrom:e.from,__redirectCount:(n||0)+1})}},{key:"__ensureOutlet",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.__outlet;if(!(e instanceof Node))throw new TypeError(u("Expected router outlet to be a valid DOM Node (but got "+e+")"))}},{key:"__updateBrowserHistory",value:function(e,t){if(window.location.pathname!==e){var n=t?"replaceState":"pushState";window.history[n](null,document.title,e),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}},{key:"__addAppearingContent",value:function(e,t){this.__ensureOutlet(),this.__removeAppearingContent();for(var n=this.__outlet,r=0;r<e.__divergedChainIndex;r++){var o=t&&t.chain[r].element;if(o){if(o.parentNode!==n)break;e.chain[r].element=o,n=o}}this.__disappearingContent=Array.from(n.children),this.__appearingContent=[];for(var i=n,a=e.__divergedChainIndex;a<e.chain.length;a++){var u=e.chain[a].element;u&&(i.appendChild(u),i===n&&this.__appearingContent.push(u),i=u)}}},{key:"__removeDisappearingContent",value:function(){this.__disappearingContent&&te(this.__disappearingContent),this.__disappearingContent=null,this.__appearingContent=null}},{key:"__removeAppearingContent",value:function(){this.__disappearingContent&&this.__appearingContent&&(te(this.__appearingContent),this.__disappearingContent=null,this.__appearingContent=null)}},{key:"__runOnAfterLeaveCallbacks",value:function(e,t){if(t)for(var n=t.chain.length-1;n>=e.__divergedChainIndex;n--){var r=t.chain[n].element;if(r)try{var o=X(e);Z(r.onAfterLeave,[o,{},t.resolver],r)}finally{te(r.children)}}}},{key:"__runOnAfterEnterCallbacks",value:function(e){for(var t=e.__divergedChainIndex;t<e.chain.length;t++){var n=e.chain[t].element||{},r=X(e,e.chain[t].route);Z(n.onAfterEnter,[r,{},e.resolver],n)}}},{key:"__animateIfNeeded",value:function(e){for(var t=(this.__disappearingContent||[])[0],n=(this.__appearingContent||[])[0],r=[],o=e.chain,i=void 0,a=o.length;a>0;a--)if(o[a-1].route.animate){i=o[a-1].route.animate;break}if(t&&n&&i){var u=_(i)&&i.leave||"leaving",c=_(i)&&i.enter||"entering";r.push(J(t,u)),r.push(J(n,c))}return Promise.all(r).then(function(){return e})}},{key:"subscribe",value:function(){window.addEventListener("vaadin-router-go",this.__navigationEventHandler)}},{key:"unsubscribe",value:function(){window.removeEventListener("vaadin-router-go",this.__navigationEventHandler)}},{key:"__onNavigationEvent",value:function(e){var t=e?e.detail.pathname:window.location.pathname;this.render(t,!0)}}],[{key:"setTriggers",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];q(t)}},{key:"go",value:function(e){v("go",{pathname:e})}}]),t}(),re=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i;function oe(e,t){if("function"==typeof e){var n=re.exec(e.toString());if(n)try{e=new Function(n[1])}catch(e){console.log("vaadin-development-mode-detector: uncommentAndRun() failed",e)}return e(t)}}window.Vaadin=window.Vaadin||{};var ie=function(e,t){if(window.Vaadin.developmentMode)return oe(e,t)};function ae(){}void 0===window.Vaadin.developmentMode&&(window.Vaadin.developmentMode=function(){try{return localStorage.getItem("vaadin.developmentmode.force")||["localhost","127.0.0.1"].indexOf(window.location.hostname)>=0&&!oe(function(){return!0})&&!function(){if(window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients){var e=Object.keys(window.Vaadin.Flow.clients).map(function(e){return window.Vaadin.Flow.clients[e]}).filter(function(e){return e.productionMode});if(e.length>0)return!0}return!1}()}catch(e){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.1.0"}),ie(ae),ne.NavigationTrigger={POPSTATE:x,CLICK:b},e.Router=ne,e.Resolver=W,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Vaadin=e.Vaadin||{})}(this,function(e){"use strict";var t="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},n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},i=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)};function a(e){return e=e||[],Array.isArray(e)?e:[e]}function u(e){return"[Vaadin.Router] "+e}var c="module",l="nomodule",s=[c,l];function d(e){if(!e.match(/.+\.[m]?js$/))throw new Error(u('Unsupported type for bundle "'+e+'": .js or .mjs expected.'))}function f(e){if(!e||!g(e.path))throw new Error(u('Expected route config to be an object with a "path" string property, or an array of such objects'));var t=e.bundle,n=["component","redirect","bundle"];if(!(_(e.action)||Array.isArray(e.children)||_(e.children)||m(t)||n.some(function(t){return g(e[t])})))throw new Error(u('Expected route config "'+e.path+'" to include either "'+n.join('", "')+'" or "action" function but none found.'));if(t)if(g(t))d(t);else{if(!s.some(function(e){return e in t}))throw new Error(u('Expected route bundle to include either "'+l+'" or "'+c+'" keys, or both'));s.forEach(function(e){return e in t&&d(t[e])})}e.redirect&&["bundle","component"].forEach(function(t){t in e&&console.warn(u('Route config "'+e.path+'" has both "redirect" and "'+t+'" properties, and "redirect" will always override the latter. Did you mean to only use "'+t+'"?'))})}function h(e){a(e).forEach(function(e){return f(e)})}function p(e,t){var n=document.head.querySelector('script[src="'+e+'"][async]');return n||((n=document.createElement("script")).setAttribute("src",e),t===c?n.setAttribute("type",c):t===l&&n.setAttribute(l,""),n.async=!0),new Promise(function(e,t){n.onreadystatechange=n.onload=function(t){n.__dynamicImportLoaded=!0,e(t)},n.onerror=function(e){n.parentNode&&n.parentNode.removeChild(n),t(e)},null===n.parentNode?document.head.appendChild(n):n.__dynamicImportLoaded&&e()})}function v(e,t){window.dispatchEvent(new CustomEvent("vaadin-router-"+e,{detail:t}))}function m(e){return"object"===(void 0===e?"undefined":t(e))&&!!e}function _(e){return"function"==typeof e}function g(e){return"string"==typeof e}function y(e){var t=new Error(u("Page not found ("+e.pathname+")"));return t.context=e,t.code=404,t}var w=new function e(){n(this,e)};function b(e){if(!e.defaultPrevented&&0===e.button&&!(e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){for(var t=e.target,n=e.composedPath?e.composedPath():e.path||[],r=0;r<n.length;r++){var o=n[r];if(o.nodeName&&"a"===o.nodeName.toLowerCase()){t=o;break}}for(;t&&"a"!==t.nodeName.toLowerCase();)t=t.parentNode;if(t&&"a"===t.nodeName.toLowerCase())if(!t.target||"_self"===t.target.toLowerCase())if(!t.hasAttribute("download"))if(t.pathname!==window.location.pathname||""===t.hash)(t.origin||function(e){var t=e.port,n=e.protocol;return n+"//"+("http:"===n&&"80"===t||"https:"===n&&"443"===t?e.hostname:e.host)}(t))===window.location.origin&&(e.preventDefault(),v("go",{pathname:t.pathname}))}}var E={activate:function(){window.document.addEventListener("click",b)},inactivate:function(){window.document.removeEventListener("click",b)}};function x(e){"vaadin-router-ignore"!==e.state&&v("go",{pathname:window.location.pathname})}/Trident/.test(navigator.userAgent)&&!_(window.PopStateEvent)&&(window.PopStateEvent=function(e,t){t=t||{};var n=document.createEvent("Event");return n.initEvent(e,Boolean(t.bubbles),Boolean(t.cancelable)),n.state=t.state||null,n},window.PopStateEvent.prototype=window.Event.prototype);var C={activate:function(){window.addEventListener("popstate",x)},inactivate:function(){window.removeEventListener("popstate",x)}},k=H,O=I,R=function(e,t){return T(I(e,t))},A=T,j=F,P="/",S="./",L=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function I(e,t){for(var n,r=[],o=0,i=0,a="",u=t&&t.delimiter||P,c=t&&t.delimiters||S,l=!1;null!==(n=L.exec(e));){var s=n[0],d=n[1],f=n.index;if(a+=e.slice(i,f),i=f+s.length,d)a+=d[1],l=!0;else{var h="",p=e[i],v=n[2],m=n[3],_=n[4],g=n[5];if(!l&&a.length){var y=a.length-1;c.indexOf(a[y])>-1&&(h=a[y],a=a.slice(0,y))}a&&(r.push(a),a="",l=!1);var w=""!==h&&void 0!==p&&p!==h,b="+"===g||"*"===g,E="?"===g||"*"===g,x=h||u,C=m||_;r.push({name:v||o++,prefix:h,delimiter:x,optional:E,repeat:b,partial:w,pattern:C?V(C):"[^"+N(x)+"]+?"})}}return(a||i<e.length)&&r.push(a+e.substr(i)),r}function T(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"===t(e[r])&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(t,r){for(var o="",i=r&&r.encode||encodeURIComponent,a=0;a<e.length;a++){var u=e[a];if("string"!=typeof u){var c,l=t?t[u.name]:void 0;if(Array.isArray(l)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===l.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var s=0;s<l.length;s++){if(c=i(l[s],u),!n[a].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');o+=(0===s?u.prefix:u.delimiter)+c}}else if("string"!=typeof l&&"number"!=typeof l&&"boolean"!=typeof l){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(o+=u.prefix)}else{if(c=i(String(l),u),!n[a].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');o+=u.prefix+c}}else o+=u}return o}}function N(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function V(e){return e.replace(/([=!:$/()])/g,"\\$1")}function B(e){return e&&e.sensitive?"":"i"}function F(e,t,n){for(var r=(n=n||{}).strict,o=!1!==n.end,i=N(n.delimiter||P),a=n.delimiters||S,u=[].concat(n.endsWith||[]).map(N).concat("$").join("|"),c="",l=0===e.length,s=0;s<e.length;s++){var d=e[s];if("string"==typeof d)c+=N(d),l=s===e.length-1&&a.indexOf(d[d.length-1])>-1;else{var f=N(d.prefix),h=d.repeat?"(?:"+d.pattern+")(?:"+f+"(?:"+d.pattern+"))*":d.pattern;t&&t.push(d),d.optional?d.partial?c+=f+"("+h+")?":c+="(?:"+f+"("+h+"))?":c+=f+"("+h+")"}}return o?(r||(c+="(?:"+i+")?"),c+="$"===u?"$":"(?="+u+")"):(r||(c+="(?:"+i+"(?="+u+"))?"),l||(c+="(?="+i+"|"+u+")")),new RegExp("^"+c,B(n))}function H(e,t,n){return e instanceof RegExp?function(e,t){if(!t)return e;var n=e.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)t.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}(e,t):Array.isArray(e)?function(e,t,n){for(var r=[],o=0;o<e.length;o++)r.push(H(e[o],t,n).source);return new RegExp("(?:"+r.join("|")+")",B(n))}(e,t,n):function(e,t,n){return F(I(e,n),t,n)}(e,t,n)}k.parse=O,k.compile=R,k.tokensToFunction=A,k.tokensToRegExp=j;var M=Object.prototype.hasOwnProperty,$=new Map;function D(e){try{return decodeURIComponent(e)}catch(t){return e}}function U(e,t,n,r,o){var i=void 0,a=void 0,u=0,c=e.path||"";return"/"===c.charAt(0)&&(n&&(c=c.substr(1)),n=!0),{next:function(l){if(e===l)return{done:!0};var s=e.__children=e.__children||e.children;if(!i&&(i=function(e,t,n,r,o){var i=e+"|"+(n=!!n),a=$.get(i);if(!a){var u=[];a={keys:u,pattern:k(e,u,{end:n,strict:""===e})},$.set(i,a)}var c=a.pattern.exec(t);if(!c)return null;for(var l=Object.assign({},o),s=1;s<c.length;s++){var d=a.keys[s-1],f=d.name,h=c[s];void 0===h&&M.call(l,f)||(d.repeat?l[f]=h?h.split(d.delimiter).map(D):[]:l[f]=h?D(h):h)}return{path:c[0],keys:(r||[]).concat(a.keys),params:l}}(c,t,!s,r,o)))return{done:!1,value:{route:e,keys:i.keys,params:i.params,path:i.path}};if(i&&s)for(;u<s.length;){if(!a){var d=s[u];d.parent=e;var f=i.path.length;f>0&&"/"===t.charAt(f)&&(f+=1),a=U(d,t.substr(f),n,i.keys,i.params)}var h=a.next(l);if(!h.done)return{done:!1,value:h.value};a=null,u++}return{done:!0}}}}function W(e){if(_(e.route.action))return e.route.action(e)}$.set("|false",{keys:[],pattern:/(?:)/});var K=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n(this,e),Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=r.baseUrl||"",this.errorHandler=r.errorHandler,this.resolveRoute=r.resolveRoute||W,this.context=Object.assign({resolver:this},r.context),this.root=Array.isArray(t)?{path:"",__children:t,parent:null,__synthetic:!0}:t,this.root.parent=null}return r(e,[{key:"getRoutes",value:function(){return[].concat(i(this.root.__children))}},{key:"setRoutes",value:function(e){h(e);var t=[].concat(i(a(e)));this.root.__children=t}},{key:"addRoutes",value:function(e){var t;return h(e),(t=this.root.__children).push.apply(t,i(a(e))),this.getRoutes()}},{key:"removeRoutes",value:function(){this.setRoutes([])}},{key:"resolve",value:function(e){var t=this,n=Object.assign({},this.context,g(e)?{pathname:e}:e),r=U(this.root,n.pathname.substr(this.baseUrl.length)),o=this.resolveRoute,i=null,a=null,u=n;function c(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i.value.route,l=null===arguments[2]&&i.value.route;return i=a||r.next(l),a=null,e||!i.done&&function(e,t){for(var n=t;n;)if((n=n.parent)===e)return!0;return!1}(t,i.value.route)?i.done?Promise.reject(y(n)):(function(e,t){var n=t.route,r=t.path;if(n&&!n.__synthetic){var o={path:r,route:n};!function(e,t){return!t.parent||!e||!e.length||e[e.length-1].route!==t.parent}(e.chain,n)?e.chain.push(o):e.chain=[o]}}(n,i.value),u=Object.assign({},n,i.value),Promise.resolve(o(u)).then(function(n){return null!==n&&void 0!==n&&n!==w?(u.result=n.result||n,u):c(e,t,n)})):(a=i,Promise.resolve(w))}return n.next=c,Promise.resolve().then(function(){return c(!0,t.root)}).catch(function(e){var n=function(e){var t="Path '"+e.pathname+"' is not properly resolved due to an error.",n=(e.route||{}).path;return n&&(t+=" Resolution had failed on route: '"+n+"'"),t}(u);if(e?console.warn(n):e=new Error(n),e.context=e.context||u,e instanceof DOMException||(e.code=e.code||500),t.errorHandler)return u.result=t.errorHandler(e),u;throw e})}}]),e}();K.pathToRegexp=k;var q=[];function J(e){q.forEach(function(e){return e.inactivate()}),e.forEach(function(e){return e.activate()}),q=e}var z=function(e){var t=getComputedStyle(e).getPropertyValue("animation-name");return t&&"none"!==t},G=function(e,t){e.addEventListener("animationend",function n(){e.removeEventListener("animationend",n),t()})};function Q(e,t){return e.classList.add(t),new Promise(function(n){if(z(e)){var r=e.getBoundingClientRect(),o="height: "+(r.bottom-r.top)+"px; width: "+(r.right-r.left)+"px";e.setAttribute("style","position: absolute; "+o),G(e,function(){e.classList.remove(t),e.removeAttribute("style"),n()})}else e.classList.remove(t),n()})}function X(e){return null!==e&&void 0!==e}function Y(e,t){var n=e.pathname,r=void 0===n?"":n,o=e.chain,i=void 0===o?[]:o,a=e.params,u=void 0===a?{}:a,c=e.redirectFrom;return{pathname:r,routes:i.map(function(e){return e.route}),route:!t&&i.length&&i[i.length-1].route||t,params:u,redirectFrom:c}}function Z(e,t){var n=Object.assign({},e.params);return{redirect:{pathname:t,from:e.pathname,params:n}}}function ee(e,t,n){if(_(e))return e.apply(n,t)}function te(e,t,n){return function(r){return r&&(r.cancel||r.redirect)?r:n?ee(n[e],t,n):void 0}}function ne(e){if(e&&e.length)for(var t=e[0].parentNode,n=0;n<e.length;n++)t.removeChild(e[n])}var re=function(e){function i(e,t){n(this,i);var r=o(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,[],Object.assign({},t)));r.resolveRoute=function(e){return r.__resolveRoute(e)};var a=i.NavigationTrigger;return i.setTriggers.apply(i,Object.keys(a).map(function(e){return a[e]})),r.ready,r.ready=Promise.resolve(e),r.location,r.location=Y({}),r.__lastStartedRenderId=0,r.__navigationEventHandler=r.__onNavigationEvent.bind(r),r.setOutlet(e),r.subscribe(),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(i,K),r(i,[{key:"__resolveRoute",value:function(e){var t=e.route,n=Promise.resolve();_(t.children)&&(n=n.then(function(){return t.children(function(e){var t=Object.assign({},e);return delete t.next,t}(e))}).then(function(e){X(e)||_(t.children)||(e=t.children),function(e,t){if(!Array.isArray(e)&&!m(e))throw new Error(u('Incorrect "children" value for the route '+t.path+": expected array or object, but got "+e));t.__children=[];for(var n=a(e),r=0;r<n.length;r++)f(n[r]),t.__children.push(n[r])}(e,t)}));var r={redirect:function(t){return Z(e,t)},component:function(t){return function(e,t){var n=document.createElement(t);n.location=Y(e);var r=e.chain.map(function(e){return e.route}).indexOf(e.route);return e.chain[r].element=n,n}(e,t)}};return n.then(function(){return ee(t.action,[e,r],t)}).then(function(e){return X(e)&&(e instanceof HTMLElement||e.redirect||e===w)?e:g(t.redirect)?r.redirect(t.redirect):t.bundle?(n=t.bundle,g(n)?p(n):Promise.race(s.filter(function(e){return e in n}).map(function(e){return p(n[e],e)}))).then(function(){},function(){throw new Error(u("Bundle not found: "+t.bundle+". Check if the file name is correct"))}):void 0;var n}).then(function(e){return X(e)?e:g(t.component)?r.component(t.component):void 0})}},{key:"setOutlet",value:function(e){e&&this.__ensureOutlet(e),this.__outlet=e}},{key:"getOutlet",value:function(){return this.__outlet}},{key:"setRoutes",value:function(e){(function e(t,n,r){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,r)}if("value"in o)return o.value;var a=o.get;return void 0!==a?a.call(r):void 0})(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"setRoutes",this).call(this,e),this.__onNavigationEvent()}},{key:"render",value:function(e,t){var n=this,r=++this.__lastStartedRenderId,o=e.pathname||e;return this.ready=this.resolve(e).then(function(e){return n.__fullyResolveChain(e)}).then(function(e){if(r===n.__lastStartedRenderId){var o=n.__previousContext;if(e===o)return n.location;t&&n.__updateBrowserHistory(e.pathname,e.redirectFrom),n.__addAppearingContent(e,o);var i=n.__animateIfNeeded(e);return n.__runOnAfterEnterCallbacks(e),n.__runOnAfterLeaveCallbacks(e,o),i.then(function(){if(r===n.__lastStartedRenderId)return n.__removeDisappearingContent(),n.__previousContext=e,n.location=Y(e),v("location-changed",{router:n,location:n.location}),n.location})}}).catch(function(e){if(r===n.__lastStartedRenderId)throw t&&n.__updateBrowserHistory(o),ne(n.__outlet&&n.__outlet.children),n.location=Y({pathname:o}),v("error",{router:n,error:e,pathname:o}),e}),this.ready}},{key:"__fullyResolveChain",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return this.__amendWithResolutionResult(n).then(function(r){var o=r!==n?r:e;return r.next().then(function(e){if((null===e||e===w)&&r.pathname!==r.chain.map(function(e){return e.path}).reduce(function(e,t){return t.length?e+("/"===e.charAt(e.length-1)?"":"/")+t:e}))throw y(o);return e&&e!==w?t.__fullyResolveChain(o,e):t.__amendWithOnBeforeCallbacks(o)})})}},{key:"__amendWithResolutionResult",value:function(e){var n=this,r=e.result;return r instanceof HTMLElement?Promise.resolve(e):r.redirect?this.__redirect(r.redirect,e.__redirectCount).then(function(e){return n.__amendWithResolutionResult(e)}):r instanceof Error?Promise.reject(r):Promise.reject(new Error(u('Invalid route resolution result for path "'+e.pathname+'". Expected redirect object or HTML element, but got: "'+function(e){if("object"!==(void 0===e?"undefined":t(e)))return String(e);var n=Object.prototype.toString.call(e).match(/ (.*)\]$/)[1];return"Object"===n||"Array"===n?n+" "+JSON.stringify(e):n}(r)+'". Double check the action return value for the route.')))}},{key:"__amendWithOnBeforeCallbacks",value:function(e){var t=this;return this.__runOnBeforeCallbacks(e).then(function(n){return n===t.__previousContext||n===e?n:t.__fullyResolveChain(n)})}},{key:"__runOnBeforeCallbacks",value:function(e){var t=this,n=(this.__previousContext||{}).chain||[],r=e.chain,o=Promise.resolve(),i=function(){return{cancel:!0}},a=function(t){return Z(e,t)};if(e.__divergedChainIndex=0,n.length){for(var u=0;u<Math.min(n.length,r.length)&&(n[u].route===r[u].route&&n[u].path===r[u].path&&(n[u].element&&n[u].element.localName)===(r[u].element&&r[u].element.localName));u=++e.__divergedChainIndex);for(var c=n.length-1;c>=e.__divergedChainIndex;c--){var l=Y(e);o=o.then(te("onBeforeLeave",[l,{prevent:i},this],n[c].element)).then(function(e){if(!(e||{}).redirect)return e})}}for(var s=e.__divergedChainIndex;s<r.length;s++){var d=Y(e,r[s].route);o=o.then(te("onBeforeEnter",[d,{prevent:i,redirect:a},this],r[s].element))}return o.then(function(n){if(n){if(n.cancel)return t.__previousContext;if(n.redirect)return t.__redirect(n.redirect,e.__redirectCount)}return e})}},{key:"__redirect",value:function(e,t){if(t>256)throw new Error(u("Too many redirects when rendering "+e.from));return this.resolve({pathname:this.constructor.urlForPath(e.pathname,e.params),redirectFrom:e.from,__redirectCount:(t||0)+1})}},{key:"__ensureOutlet",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.__outlet;if(!(e instanceof Node))throw new TypeError(u("Expected router outlet to be a valid DOM Node (but got "+e+")"))}},{key:"__updateBrowserHistory",value:function(e,t){if(window.location.pathname!==e){var n=t?"replaceState":"pushState";window.history[n](null,document.title,e),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}},{key:"__addAppearingContent",value:function(e,t){this.__ensureOutlet(),this.__removeAppearingContent();for(var n=this.__outlet,r=0;r<e.__divergedChainIndex;r++){var o=t&&t.chain[r].element;if(o){if(o.parentNode!==n)break;e.chain[r].element=o,n=o}}this.__disappearingContent=Array.from(n.children),this.__appearingContent=[];for(var i=n,a=e.__divergedChainIndex;a<e.chain.length;a++){var u=e.chain[a].element;u&&(i.appendChild(u),i===n&&this.__appearingContent.push(u),i=u)}}},{key:"__removeDisappearingContent",value:function(){this.__disappearingContent&&ne(this.__disappearingContent),this.__disappearingContent=null,this.__appearingContent=null}},{key:"__removeAppearingContent",value:function(){this.__disappearingContent&&this.__appearingContent&&(ne(this.__appearingContent),this.__disappearingContent=null,this.__appearingContent=null)}},{key:"__runOnAfterLeaveCallbacks",value:function(e,t){if(t)for(var n=t.chain.length-1;n>=e.__divergedChainIndex;n--){var r=t.chain[n].element;if(r)try{var o=Y(e);ee(r.onAfterLeave,[o,{},t.resolver],r)}finally{ne(r.children)}}}},{key:"__runOnAfterEnterCallbacks",value:function(e){for(var t=e.__divergedChainIndex;t<e.chain.length;t++){var n=e.chain[t].element||{},r=Y(e,e.chain[t].route);ee(n.onAfterEnter,[r,{},e.resolver],n)}}},{key:"__animateIfNeeded",value:function(e){for(var t=(this.__disappearingContent||[])[0],n=(this.__appearingContent||[])[0],r=[],o=e.chain,i=void 0,a=o.length;a>0;a--)if(o[a-1].route.animate){i=o[a-1].route.animate;break}if(t&&n&&i){var u=m(i)&&i.leave||"leaving",c=m(i)&&i.enter||"entering";r.push(Q(t,u)),r.push(Q(n,c))}return Promise.all(r).then(function(){return e})}},{key:"subscribe",value:function(){window.addEventListener("vaadin-router-go",this.__navigationEventHandler)}},{key:"unsubscribe",value:function(){window.removeEventListener("vaadin-router-go",this.__navigationEventHandler)}},{key:"__onNavigationEvent",value:function(e){var t=e?e.detail.pathname:window.location.pathname;this.render(t,!0)}}],[{key:"setTriggers",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];J(t)}},{key:"urlForPath",value:function(e,t){return i.pathToRegexp.compile(e)(t)}},{key:"go",value:function(e){v("go",{pathname:e})}}]),i}(),oe=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i;function ie(e,t){if("function"==typeof e){var n=oe.exec(e.toString());if(n)try{e=new Function(n[1])}catch(e){console.log("vaadin-development-mode-detector: uncommentAndRun() failed",e)}return e(t)}}window.Vaadin=window.Vaadin||{};var ae=function(e,t){if(window.Vaadin.developmentMode)return ie(e,t)};function ue(){}void 0===window.Vaadin.developmentMode&&(window.Vaadin.developmentMode=function(){try{return localStorage.getItem("vaadin.developmentmode.force")||["localhost","127.0.0.1"].indexOf(window.location.hostname)>=0&&!ie(function(){return!0})&&!function(){if(window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients){var e=Object.keys(window.Vaadin.Flow.clients).map(function(e){return window.Vaadin.Flow.clients[e]}).filter(function(e){return e.productionMode});if(e.length>0)return!0}return!1}()}catch(e){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.1.0"}),ae(ue),re.NavigationTrigger={POPSTATE:C,CLICK:E},e.Router=re,e.Resolver=K,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=vaadin-router.umd.min.js.map
{
"name": "@vaadin/router",
"version": "1.1.0",
"version": "1.2.0-pre.1",
"description": "Small and powerful client-side router for Web Components. Framework-agnostic.",

@@ -47,3 +47,3 @@ "main": "dist/vaadin-router.js",

"path": "dist/vaadin-router.min.js",
"maxSize": "6.5 kB"
"maxSize": "7 kB"
}

@@ -50,0 +50,0 @@ ],

@@ -48,7 +48,12 @@ /**

*
* If a `Promise` is returned by any of the callbacks, it is resolved before proceeding further.
* Any of the `onBefore...` callbacks have a possibility to cancel the navigation and fall back
* to the previous navigation result (if there is no result and this is the first resolution, an exception is thrown).
* `onAfter...` callbacks are considered as non-cancellable, and their return value is ignored.
* If a `Promise` is returned by any of the callbacks, it is resolved before
* proceeding further.
*
* Any of the `onBefore...` callbacks have a possibility to prevent
* the navigation and fall back to the previous navigation result. If there is
* no result and this is the first resolution, an exception is thrown.
*
* `onAfter...` callbacks are considered as non-preventable, and their return
* value is ignored.
*
* Other examples can be found in the

@@ -61,26 +66,36 @@ * [live demos](#/classes/Vaadin.Router/demos/demo/index.html) and tests.

/**
* Method that gets executed when user navigates away from the component that had defined the method.
* The user can prevent the navigation by returning `context.cancel()` from the method or same value wrapped in `Promise`.
* This effectively means that the corresponding component should be resolved by the router before the method can be executed.
* If the router navigates to the same path twice in a row, in the second time the method is not called.
* The WebComponent instance on which the callback has been invoked is available inside the callback through the `this` reference.
* Method that gets executed when user navigates away from the component
* that had defined the method. The user can prevent the navigation
* by returning `commands.prevent()` from the method or same value wrapped
* in `Promise`. This effectively means that the corresponding component
* should be resolved by the router before the method can be executed.
* If the router navigates to the same path twice in a row, and this results
* in rendering the same component name, in the second time the method
* is not called. The WebComponent instance on which the callback
* has been invoked is available inside the callback through
* the `this` reference.
*
* @param context the context object with the following properties:
* Return values:
*
* * if the `commands.prevent()` result is returned (immediately or
* as a Promise), the navigation is aborted and the outlet contents
* is not updated.
* * any other return value is ignored and Vaadin Router proceeds with
* the navigation.
*
* Arguments:
*
* @param location the `Router.Location` object
* @param commands the commands object with the following methods:
*
* | Property | Description
* | -------------------|-------------
* | `context.pathname` | string with the pathname being rendered.
* | `context.params` | object with route parameters, contains string keys for named and numeric keys for unnamed parameters.
* | `context.route` | object that holds the route being rendered.
* | `context.cancel()` | function that creates a special object that can be returned to abort the current navigation and fall back to the last one. If there is no existing one, an exception is thrown.
* | `commands.prevent()` | function that creates a special object that can be returned to abort the current navigation and fall back to the last one. If there is no existing one, an exception is thrown.
*
* Return values:
*
* * if `context.cancel()` is returned (immediately or as a Promise), the navigation is aborted and the outlet contents is not updated.
* * any other return value is ignored and Vaadin Router proceeds with the navigation.
* @param router the `Router` instance
*/
onBeforeLeave(context) {
onBeforeLeave(location, commands, router) {
// user implementation example:
if (this.hasUnfinishedChanges()) {
return context.cancel();
return commands.prevent();
}

@@ -90,24 +105,35 @@ }

/**
* Method that gets executed before the outlet contents is updated with the new element.
* The user can prevent the navigation by returning `context.cancel()` from the method or same value wrapped in `Promise`.
* If the router navigates to the same path twice in a row, in the second time the method is not called.
* the WebComponent instance on which the callback has been invoked is available inside the callback through the `this` reference.
* Method that gets executed before the outlet contents is updated with
* the new element. The user can prevent the navigation by returning
* `commands.prevent()` from the method or same value wrapped in `Promise`.
* If the router navigates to the same path twice in a row, and this results
* in rendering the same component name, in the second time the method
* is not called. The WebComponent instance on which the callback
* has been invoked is available inside the callback through
* the `this` reference.
*
* @param context the context object with the following properties:
* Return values:
*
* * if the `commands.prevent()` result is returned (immediately or
* as a Promise), the navigation is aborted and the outlet contents
* is not updated.
* * if the `commands.redirect(path)` result is returned (immediately or
* as a Promise), Vaadin Router ends navigation to the current path, and
* starts a new navigation cycle to the new path.
* * any other return value is ignored and Vaadin Router proceeds with
* the navigation.
*
* Arguments:
*
* @param location the `Router.Location` object
* @param commands the commands object with the following methods:
*
* | Property | Description
* | -------------------------|-------------
* | `context.pathname` | string with the pathname being rendered.
* | `context.params` | object with route parameters, contains string keys for named and numeric keys for unnamed parameters.
* | `context.route` | object that holds the route being rendered.
* | `context.redirect(path)` | function that creates a redirect data for the path specified, to use as a return value from the callback.
* | `context.cancel()` | function that creates a special object that can be returned to abort the current navigation and fall back to the last one. If there is no existing one, an exception is thrown.
* | `commands.redirect(path)` | function that creates a redirect data for the path specified, to use as a return value from the callback.
* | `commands.prevent()` | function that creates a special object that can be returned to abort the current navigation and fall back to the last one. If there is no existing one, an exception is thrown.
*
* Return values:
*
* * if a `context.cancel()` object is returned (immediately or as a Promise), the navigation is aborted and the outlet contents is not updated.
* * if a `context.redirect(path)` object is returned (immediately or as a Promise), Vaadin Router ends navigation to the current path, and starts a new navigation cycle to the new path.
* * any other return value is ignored and Vaadin Router proceeds with the navigation.
* @param router the `Router` instance
*/
onBeforeEnter(context) {
onBeforeEnter(location, commands, router) {
// user implementation example:

@@ -120,19 +146,23 @@ if (context.params.userName === 'admin') {

/**
* Method that gets executed when user navigates away from the component that had defined the method, just before the element is to be removed from the DOM.
* The difference between this method and `onBeforeLeave` is that when this method is executed, there is no way to abort the navigation.
* This effectively means that the corresponding component should be resolved by the router before the method can be executed.
* If the router navigates to the same path twice in a row, in the second time the method is not called.
* The WebComponent instance on which the callback has been invoked is available inside the callback through the `this` reference.
* Method that gets executed when user navigates away from the component that
* had defined the method, just before the element is to be removed
* from the DOM. The difference between this method and `onBeforeLeave`
* is that when this method is executed, there is no way to abort
* the navigation. This effectively means that the corresponding component
* should be resolved by the router before the method can be executed.
* If the router navigates to the same path twice in a row, and this results
* in rendering the same component name, in the second time the method
* is not called. The WebComponent instance on which the callback
* has been invoked is available inside the callback through
* the `this` reference.
*
* @param context the context object with the following properties:
* Return values: any return value is ignored and Vaadin Router proceeds with the navigation.
*
* | Property | Description
* | ------------------ |-------------
* | `context.pathname` | string with the pathname being rendered.
* | `context.params` | object with route parameters, contains string keys for named and numeric keys for unnamed parameters.
* | `context.route` | object that holds the route being rendered.
* Arguments:
*
* Return values: any return value is ignored and Vaadin Router proceeds with the navigation.
* @param location the `Router.Location` object
* @param commands empty object
* @param router the `Router` instance
*/
onAfterLeave(context) {
onAfterLeave(location, commands, router) {
// user implementation example:

@@ -143,5 +173,8 @@ storeTimeSpentOnTheView();

/**
* Method that gets executed after the outlet contents is updated with the new element.
* If the router navigates to the same path twice in a row, in the second time the method is not called.
* The WebComponent instance on which the callback has been invoked is available inside the callback through the `this` reference.
* Method that gets executed after the outlet contents is updated with the new
* element. If the router navigates to the same path twice in a row, and
* this results in rendering the same component name, in the second time
* the method is not called. The WebComponent instance on which the callback
* has been invoked is available inside the callback through
* the `this` reference.
*

@@ -152,13 +185,11 @@ * This callback is called asynchronously after the native

*
* @param context the context object with the following properties:
* Return values: any return value is ignored and Vaadin Router proceeds with the navigation.
*
* | Property | Description
* | ------------------ |-------------
* | `context.pathname` | string with the pathname being rendered.
* | `context.params` | object with route parameters, contains string keys for named and numeric keys for unnamed parameters.
* | `context.route` | object that holds the route being rendered.
* Arguments:
*
* Return values: any return value is ignored and Vaadin Router proceeds with the navigation.
* @param location the `Router.Location` object
* @param commands empty object
* @param router the `Router` instance
*/
onAfterEnter(context) {
onAfterEnter(location, commands, router) {
// user implementation example:

@@ -165,0 +196,0 @@ sendVisitStatistics();

@@ -13,3 +13,3 @@ /**

import resolveRoute from './resolveRoute.js';
import {toArray, ensureRoutes, isString, getNotFoundError} from '../utils.js';
import {toArray, ensureRoutes, isString, getNotFoundError, notFoundResult} from '../utils.js';

@@ -154,3 +154,3 @@ function isChildRoute(parentRoute, childRoute) {

nextMatches = matches;
return Promise.resolve(null);
return Promise.resolve(notFoundResult);
}

@@ -167,3 +167,3 @@ }

return Promise.resolve(resolve(currentContext)).then(resolution => {
if (resolution !== null && resolution !== undefined) {
if (resolution !== null && resolution !== undefined && resolution !== notFoundResult) {
currentContext.result = resolution.result || resolution;

@@ -170,0 +170,0 @@ return currentContext;

@@ -8,5 +8,5 @@ import {usageStatistics} from '@vaadin/vaadin-usage-statistics/vaadin-usage-statistics.js';

is: '@vaadin/router',
version: '1.1.0',
version: '1.2.0-pre.1',
});
usageStatistics();

@@ -9,2 +9,3 @@ import Resolver from './resolver/resolver.js';

log,
logValue,
toArray,

@@ -15,2 +16,3 @@ isFunction,

getNotFoundError,
notFoundResult,
} from './utils.js';

@@ -190,24 +192,4 @@

const commands = {
redirect: path => createRedirect(context, path),
component: component => renderComponent(context, component)
};
const actionResult = runCallbackIfPossible(route.action, [context, commands], route);
if (isResultNotEmpty(actionResult)) {
return actionResult;
}
if (isString(route.redirect)) {
return commands.redirect(route.redirect);
}
let callbacks = Promise.resolve();
if (route.bundle) {
callbacks = callbacks.then(() => loadBundle(route.bundle))
.catch(() => {
throw new Error(log(`Bundle not found: ${route.bundle}. Check if the file name is correct`));
});
}
if (isFunction(route.children)) {

@@ -226,7 +208,40 @@ callbacks = callbacks

return callbacks.then(() => {
if (isString(route.component)) {
return commands.component(route.component);
}
});
const commands = {
redirect: path => createRedirect(context, path),
component: component => renderComponent(context, component)
};
return callbacks
.then(() => runCallbackIfPossible(route.action, [context, commands], route))
.then(result => {
if (isResultNotEmpty(result)) {
// Actions like `() => import('my-view.js')` are not expected to
// end the resolution, despite the result is not empty. Checking
// the result with a whitelist of values that end the resulution.
if (result instanceof HTMLElement ||
result.redirect ||
result === notFoundResult) {
return result;
}
}
if (isString(route.redirect)) {
return commands.redirect(route.redirect);
}
if (route.bundle) {
return loadBundle(route.bundle)
.then(() => {}, () => {
throw new Error(log(`Bundle not found: ${route.bundle}. Check if the file name is correct`));
});
}
})
.then(result => {
if (isResultNotEmpty(result)) {
return result;
}
if (isString(route.component)) {
return commands.component(route.component);
}
});
}

@@ -269,6 +284,23 @@

*
* * `children` – an array of nested routes or a function that provides this
* array at the render time. The function can be synchronous or asynchronous:
* in the latter case the render is delayed until the returned promise is
* resolved. The `children` function is executed every time when this route is
* being rendered. This allows for dynamic route structures (e.g. backend-defined),
* but it might have a performance impact as well. In order to avoid calling
* the function on subsequent renders, you can override the `children` property
* of the route object and save the calculated array there
* (via `context.route.children = [ route1, route2, ...];`).
* Parent routes are fully resolved before resolving the children. Children
* 'path' values are relative to the parent ones.
*
* * `action` – the action that is executed before the route is resolved.
* The value for this property should be a function, accepting a `context` parameter described below.
* If present, this function is always invoked first, disregarding of the other properties' presence.
* If the action returns a non-empty result, current route resolution is finished and other route config properties are ignored.
* The value for this property should be a function, accepting `context`
* and `commands` parameters described below. If present, this function is
* always invoked first, disregarding of the other properties' presence.
* The action can return a result directly or within a `Promise`, which
* resolves to the result. If the action result is an `HTMLElement` instance,
* a `commands.component(name)` result, a `commands.redirect(path)` result,
* or a `context.next()` result, the current route resolution is finished,
* and other route config properties are ignored.
* See also **Route Actions** section in [Live Examples](#/classes/Vaadin.Router/demos/demo/index.html).

@@ -288,14 +320,2 @@ *

*
* * `children` – an array of nested routes or a function that provides this
* array at the render time. The function can be synchronous or asynchronous:
* in the latter case the render is delayed until the returned promise is
* resolved. The `children` function is executed every time when this route is
* being rendered. This allows for dynamic route structures (e.g. backend-defined),
* but it might have a performance impact as well. In order to avoid calling
* the function on subsequent renders, you can override the `children` property
* of the route object and save the calculated array there
* (via `context.route.children = [ route1, route2, ...];`).
* Parent routes are fully resolved before resolving the children. Children
* 'path' values are relative to the parent ones.
*
* * `component` – the tag name of the Web Component to resolve the route to.

@@ -318,8 +338,14 @@ * The property is ignored when either an `action` returns the result or `redirect` property is present.

*
* * `context.next()` – function for asynchronously getting the next route contents from the resolution chain (if any)
* * `context.next()` – function for asynchronously getting the next route
* contents from the resolution chain (if any)
*
* * `context.redirect(path)` – function that creates a redirect data for the path specified.
* `commands` object that is passed to `action` function has
* the following methods:
*
* * `context.component(component)` – function that creates a new HTMLElement with current context
* * `commands.redirect(path)` – function that creates a redirect data
* for the path specified.
*
* * `commands.component(component)` – function that creates a new HTMLElement
* with current context
*
* @param {!Array<!Object>|!Object} routes a single route or an array of those

@@ -417,3 +443,3 @@ */

.then(nextContext => {
if (nextContext === null) {
if (nextContext === null || nextContext === notFoundResult) {
if (amendedContext.pathname !== getMatchedPath(amendedContext.chain)) {

@@ -423,3 +449,3 @@ throw getNotFoundError(initialContext);

}
return nextContext
return nextContext && nextContext !== notFoundResult
? this.__fullyResolveChain(initialContext, nextContext)

@@ -445,3 +471,3 @@ : this.__amendWithOnBeforeCallbacks(initialContext);

`Invalid route resolution result for path "${context.pathname}". ` +
`Expected redirect object or HTML element, but got: "${result}". ` +
`Expected redirect object or HTML element, but got: "${logValue(result)}". ` +
`Double check the action return value for the route.`

@@ -474,3 +500,7 @@ )

for (let i = 0; i < Math.min(previousChain.length, newChain.length); i = ++newContext.__divergedChainIndex) {
if (previousChain[i].route !== newChain[i].route || previousChain[i].path !== newChain[i].path) {
if (previousChain[i].route !== newChain[i].route
|| previousChain[i].path !== newChain[i].path
|| (previousChain[i].element && previousChain[i].element.localName)
!== (newChain[i].element && newChain[i].element.localName)
) {
break;

@@ -477,0 +507,0 @@ }

@@ -10,2 +10,15 @@ export function toArray(objectOrArray) {

export function logValue(value) {
if (typeof value !== 'object') {
return String(value);
}
const stringType = Object.prototype.toString.call(value).match(/ (.*)\]$/)[1];
if (stringType === 'Object' || stringType === 'Array') {
return `${stringType} ${JSON.stringify(value)}`;
} else {
return stringType;
}
}
const MODULE = 'module';

@@ -146,1 +159,3 @@ const NOMODULE = 'nomodule';

}
export const notFoundResult = new (class NotFoundResult {})();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc