@vaadin/router
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -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||!l(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,c=["component","redirect","bundle"];if(!(f(t.action)||Array.isArray(t.children)||f(t.children)||h(s)||c.some(e=>l(t[e]))))throw new Error(e(`Expected route config "${t.path}" to include either "${c.join('", "')}" `+'or "action" function but none found.'));if(s)if(l(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 c(e){t(e).forEach(t=>s(t))}function u(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){return!window.dispatchEvent(new CustomEvent(`vaadin-router-${t}`,{cancelable:"go"===t,detail:e}))}function h(t){return"object"==typeof t&&!!t}function f(t){return"function"==typeof t}function l(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 p=new class{};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;if(!e||"a"!==e.nodeName.toLowerCase())return;if(e.target&&"_self"!==e.target.toLowerCase())return;if(e.hasAttribute("download"))return;if(e.pathname===window.location.pathname&&""!==e.hash)return;if((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)return;const{pathname:r,search:o,hash:i}=e;a("go",{pathname:r,search:o,hash:i})&&t.preventDefault()}const m={activate(){window.document.addEventListener("click",w)},inactivate(){window.document.removeEventListener("click",w)}};function v(t){if("vaadin-router-ignore"===t.state)return;const{pathname:e,search:n,hash:r}=window.location;a("go",{pathname:e,search:n,hash:r})}/Trident/.test(navigator.userAgent)&&!f(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 b={activate(){window.addEventListener("popstate",v)},inactivate(){window.removeEventListener("popstate",v)}};var y=B,_=R,g=function(t,e){return P(R(t,e))},E=P,$=T,O="/",j="./",x=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function R(t,e){for(var n,r=[],o=0,i=0,s="",c=e&&e.delimiter||O,u=e&&e.delimiters||j,a=!1;null!==(n=x.exec(t));){var h=n[0],f=n[1],l=n.index;if(s+=t.slice(i,l),i=l+h.length,f)s+=f[1],a=!0;else{var d="",p=t[i],w=n[2],m=n[3],v=n[4],b=n[5];if(!a&&s.length){var y=s.length-1;u.indexOf(s[y])>-1&&(d=s[y],s=s.slice(0,y))}s&&(r.push(s),s="",a=!1);var _=""!==d&&void 0!==p&&p!==d,g="+"===b||"*"===b,E="?"===b||"*"===b,$=d||c,R=m||v;r.push({name:w||o++,prefix:d,delimiter:$,optional:E,repeat:g,partial:_,pattern:R?A(R):"[^"+k($)+"]+?"})}}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 c=t[s];if("string"!=typeof c){var u,a=n?n[c.name]:void 0;if(Array.isArray(a)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but got array');if(0===a.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var h=0;h<a.length;h++){if(u=i(a[h],c),!e[s].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'"');o+=(0===h?c.prefix:c.delimiter)+u}}else if("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a){if(!c.optional)throw new TypeError('Expected "'+c.name+'" to be '+(c.repeat?"an array":"a string"));c.partial&&(o+=c.prefix)}else{if(u=i(String(a),c),!e[s].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but got "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function k(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function A(t){return t.replace(/([=!:$/()])/g,"\\$1")}function C(t){return t&&t.sensitive?"":"i"}function T(t,e,n){for(var r=(n=n||{}).strict,o=!1!==n.start,i=!1!==n.end,s=k(n.delimiter||O),c=n.delimiters||j,u=[].concat(n.endsWith||[]).map(k).concat("$").join("|"),a=o?"^":"",h=0===t.length,f=0;f<t.length;f++){var l=t[f];if("string"==typeof l)a+=k(l),h=f===t.length-1&&c.indexOf(l[l.length-1])>-1;else{var d=l.repeat?"(?:"+l.pattern+")(?:"+k(l.delimiter)+"(?:"+l.pattern+"))*":l.pattern;e&&e.push(l),l.optional?l.partial?a+=k(l.prefix)+"("+d+")?":a+="(?:"+k(l.prefix)+"("+d+"))?":a+=k(l.prefix)+"("+d+")"}}return i?(r||(a+="(?:"+s+")?"),a+="$"===u?"$":"(?="+u+")"):(r||(a+="(?:"+s+"(?="+u+"))?"),h||(a+="(?="+s+"|"+u+")")),new RegExp(a,C(n))}function B(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(B(t[o],e,n).source);return new RegExp("(?:"+r.join("|")+")",C(n))}(t,e,n):function(t,e,n){return T(R(t,n),e,n)}(t,e,n)}y.parse=_,y.compile=g,y.tokensToFunction=E,y.tokensToRegExp=$;const{hasOwnProperty:M}=Object.prototype,S=new Map;function U(t){try{return decodeURIComponent(t)}catch(e){return t}}function I(t,e,n,r,o){let i,s,c=0,u=t.path||"";return"/"===u.charAt(0)&&(n&&(u=u.substr(1)),n=!0),{next(a){if(t===a)return{done:!0};const h=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 c=s.pattern.exec(e);if(!c)return null;const u=Object.assign({},o);for(let t=1;t<c.length;t++){const e=s.keys[t-1],n=e.name,r=c[t];void 0===r&&M.call(u,n)||(e.repeat?u[n]=r?r.split(e.delimiter).map(U):[]:u[n]=r?U(r):r)}return{path:c[0],keys:(r||[]).concat(s.keys),params:u}}(u,e,!h,r,o)))return{done:!1,value:{route:t,keys:i.keys,params:i.params,path:i.path}};if(i&&h)for(;c<h.length;){if(!s){const r=h[c];r.parent=t;let o=i.path.length;o>0&&"/"===e.charAt(o)&&(o+=1),s=I(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,c++}return{done:!0}}}}function L(t){if(f(t.route.action))return t.route.action(t)}S.set("|false",{keys:[],pattern:/(?:)/});class D{constructor(t,e={}){if(Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=e.baseUrl||"",this.errorHandler=e.errorHandler,this.resolveRoute=e.resolveRoute||L,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){c(e);const n=[...t(e)];this.root.o=n}addRoutes(e){return c(e),this.root.o.push(...t(e)),this.getRoutes()}removeRoutes(){this.setRoutes([])}resolve(t){const e=Object.assign({},this.context,l(t)?{pathname:t}:t),n=I(this.root,this.s(e.pathname),this.baseUrl),r=this.resolveRoute;let o=null,i=null,s=e;function c(t,u=o.value.route,a){const h=null===a&&o.value.route;return o=i||n.next(h),i=null,t||!o.done&&function(t,e){let n=e;for(;n;)if((n=n.parent)===t)return!0;return!1}(u,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!==p?(s.result=e.result||e,s):c(t,u,e))):(i=o,Promise.resolve(p))}return e.next=c,Promise.resolve().then(()=>c(!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})}static u(t,e){return new URL(t,e)}get h(){return this.baseUrl?this.constructor.u(this.baseUrl,document.baseURI||document.URL).href.replace(/[^\/]*$/,""):""}s(t){if(!this.baseUrl)return t;const e=this.h,n=this.constructor.u(t,e).href;return n.slice(0,e.length)===e?n.slice(e.length):void 0}}D.pathToRegexp=y;const{pathToRegexp:F}=D,N=new Map;function H(t,e){const n=t.get(e);if(n&&n.length>1)throw new Error(`Duplicate route with name "${e}".`+" Try seting unique 'name' route properties.");return n&&n[0]}function W(t){let e=t.path;return void 0!==(e=Array.isArray(e)?e[0]:e)?e:""}function q(t,e={}){if(!(t instanceof D))throw new TypeError("An instance of Resolver is expected");const n=new Map;return(r,o)=>{let i=H(n,r);if(!(i||(n.clear(),function t(e,n,r){const o=n.name||n.component;if(o&&(e.has(o)?e.get(o).push(n):e.set(o,[n])),Array.isArray(r))for(let o=0;o<r.length;o++){const i=r[o];i.parent=n,t(e,i,i.o||i.children)}}(n,t.root,t.root.o),i=H(n,r))))throw new Error(`Route "${r}" not found`);let s=N.get(i.fullPath);if(!s){let t=W(i),e=i.parent;for(;e;){const n=W(e);n&&(t=n.replace(/\/$/,"")+"/"+t.replace(/^\//,"")),e=e.parent}const n=F.parse(t),r=F.tokensToFunction(n),o=Object.create(null);for(let t=0;t<n.length;t++)l(n[t])||(o[n[t].name]=!0);s={toPath:r,keys:o},N.set(t,s),i.fullPath=t}let c=s.toPath(o,e)||"/";if(e.stringifyQueryParams&&o){const t={},n=Object.keys(o);for(let e=0;e<n.length;e++){const r=n[e];s.keys[r]||(t[r]=o[r])}const r=e.stringifyQueryParams(t);r&&(c+="?"===r.charAt(0)?r:`?${r}`)}return c}}let z=[];function J(t){z.forEach(t=>t.inactivate()),t.forEach(t=>t.activate()),z=t}const K=t=>{const e=getComputedStyle(t).getPropertyValue("animation-name");return e&&"none"!==e},V=(t,e)=>{const n=()=>{t.removeEventListener("animationend",n),e()};t.addEventListener("animationend",n)};function G(t,e){return t.classList.add(e),new Promise(n=>{if(K(t)){const r=t.getBoundingClientRect(),o=`height: ${r.bottom-r.top}px; width: ${r.right-r.left}px`;t.setAttribute("style",`position: absolute; ${o}`),V(t,()=>{t.classList.remove(e),t.removeAttribute("style"),n()})}else t.classList.remove(e),n()})}const Q=256;function X(t){return null!==t&&void 0!==t}function Y({pathname:t="",search:e="",hash:n="",chain:r=[],params:o={},redirectFrom:i,resolver:s},c){const u=r.map(t=>t.route);return{baseUrl:s&&s.baseUrl||"",pathname:t,search:e,hash:n,routes:u,route:c||u.length&&u[u.length-1]||null,params:o,redirectFrom:i,getUrl:(t={})=>rt(it.pathToRegexp.compile(ot(u))(Object.assign({},o,t)),s)}}function Z(t,e){const n=Object.assign({},t.params);return{redirect:{pathname:e,from:t.pathname,params:n}}}function tt(t,e,n){if(f(t))return t.apply(n,e)}function et(t,e,n){return r=>r&&(r.cancel||r.redirect)?r:n?tt(n[t],e,n):void 0}function nt(t){if(t&&t.length){const e=t[0].parentNode;for(let n=0;n<t.length;n++)e.removeChild(t[n])}}function rt(t,e){const n=e.h;return n?e.constructor.u(t.replace(/^\//,""),n).pathname:t}function ot(t){return t.map(t=>t.path).reduce((t,e)=>e.length?t.replace(/\/$/,"")+"/"+e.replace(/^\//,""):t,"")}class it extends D{constructor(t,e){const n=document.head.querySelector("base");super([],Object.assign({baseUrl:n&&n.getAttribute("href")},e)),this.resolveRoute=(t=>this.l(t));const r=it.NavigationTrigger;it.setTriggers.apply(it,Object.keys(r).map(t=>r[t])),this.baseUrl,this.ready,this.ready=Promise.resolve(t),this.location,this.location=Y({resolver:this}),this.p=0,this.m=this.v.bind(this),this.setOutlet(t),this.subscribe(),this._=new WeakMap,this.g=new WeakMap}l(n){const r=n.route;let i=Promise.resolve();f(r.children)&&(i=i.then(()=>r.children(function(t){const e=Object.assign({},t);return delete e.next,e}(n))).then(n=>{X(n)||f(r.children)||(n=r.children),function(n,r){if(!Array.isArray(n)&&!h(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 c={redirect:t=>Z(n,t),component:t=>{const e=document.createElement(t);return this._.set(e,!0),e}};return i.then(()=>{if(this.$(n))return tt(r.action,[n,c],r)}).then(t=>X(t)&&(t instanceof HTMLElement||t.redirect||t===p)?t:l(r.redirect)?c.redirect(r.redirect):r.bundle?(a=r.bundle,l(a)?u(a):Promise.race(o.filter(t=>t in a).map(t=>u(a[t],t)))).then(()=>{},()=>{throw new Error(e(`Bundle not found: ${r.bundle}. Check if the file name is correct`))}):void 0).then(t=>X(t)?t:l(r.component)?c.component(r.component):void 0);var a}setOutlet(t){t&&this.O(t),this.j=t}getOutlet(){return this.j}setRoutes(t,e=!1){return this.R=void 0,this.P=void 0,super.setRoutes(t),e||this.v(),this.ready}render(t,e){const n=++this.p,r=Object.assign({search:"",hash:""},l(t)?{pathname:t}:t,{k:n});return this.ready=this.resolve(r).then(t=>this.A(t)).then(t=>{if(this.$(t)){const n=this.R;if(t===n)return this.C(n,!0),this.location;if(this.location=Y(t),a("location-changed",{router:this,location:this.location}),e&&this.C(t,t.redirectFrom),t.T)return this.B(t,n),this.R=t,this.location;this.M(t,n);const r=this.S(t);return this.U(t),this.I(t,n),r.then(()=>{if(this.$(t))return this.L(),this.R=t,this.location})}}).catch(t=>{if(n===this.p)throw e&&this.C(r),nt(this.j&&this.j.children),this.location=Y(Object.assign(r,{resolver:this})),a("error",Object.assign({router:this,error:t},r)),t}),this.ready}A(t,e=t){return this.D(e).then(n=>{const r=n!==e?n:t;return n.next().then(t=>{if(null===t||t===p){if(rt(ot(n.chain),n.resolver)!==n.pathname)throw d(r)}return t&&t!==p?this.A(r,t):this.F(n)})})}D(t){const n=t.result;return n instanceof HTMLElement?(function(t,e){e.location=Y(t);const n=t.chain.map(t=>t.route).indexOf(t.route);t.chain[n].element=e}(t,n),Promise.resolve(t)):n.redirect?this.N(n.redirect,t.H,t.k).then(t=>this.D(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.")))}F(t){return this.W(t).then(e=>e===this.R||e===t?e:this.A(e))}W(t){const e=this.R||{},n=e.chain||[],r=t.chain;let o=Promise.resolve();const i=()=>({cancel:!0}),s=e=>Z(t,e);if(t.q=0,t.T=!1,n.length){for(let e=0;e<Math.min(n.length,r.length)&&(n[e].route===r[e].route&&(n[e].path===r[e].path||n[e].element===r[e].element)&&this.J(n[e].element,r[e].element));e=++t.q);if(t.T=r.length===n.length&&t.q==r.length&&this.J(t.result,e.result),t.T){for(let s=r.length-1;s>=0;s--)n[s].path===r[s].path&&t.search===e.search||(o=this.K(o,t,{prevent:i},n[s]));for(let c=0;c<r.length;c++)n[c].path===r[c].path&&t.search===e.search||(o=this.V(o,t,{prevent:i,redirect:s},r[c])),n[c].element.location=Y(t,n[c].route)}else for(let e=n.length-1;e>=t.q;e--)o=this.K(o,t,{prevent:i},n[e])}for(let e=t.q;!t.T&&e<r.length;e++)o=this.V(o,t,{prevent:i,redirect:s},r[e]);return o.then(e=>{if(e){if(e.cancel)return this.R.k=t.k,this.R;if(e.redirect)return this.N(e.redirect,t.H,t.k)}return t})}K(t,e,n,r){const o=Y(e);return t.then(t=>{if(this.$(e)){return et("onBeforeLeave",[o,n,this],r.element)(t)}}).then(t=>{if(!(t||{}).redirect)return t})}V(t,e,n,r){const o=Y(e,r.route);return t.then(t=>{if(this.$(e)){return et("onBeforeEnter",[o,n,this],r.element)(t)}})}J(t,e){return!(!t||!e)&&(this._.get(t)&&this._.get(e)?t.localName===e.localName:t===e)}$(t){return t.k===this.p}N(t,n,r){if(n>Q)throw new Error(e(`Too many redirects when rendering ${t.from}`));return this.resolve({pathname:this.urlForPath(t.pathname,t.params),redirectFrom:t.from,H:(n||0)+1,k:r})}O(t=this.j){if(!(t instanceof Node))throw new TypeError(e(`Expected router outlet to be a valid DOM Node (but got ${t})`))}C({pathname:t,search:e="",hash:n=""},r){if(window.location.pathname!==t||window.location.search!==e||window.location.hash!==n){const o=r?"replaceState":"pushState";window.history[o](null,document.title,t+e+n),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}B(t,e){let n=this.j;for(let r=0;r<t.q;r++){const o=e&&e.chain[r].element;if(o){if(o.parentNode!==n)break;t.chain[r].element=o,n=o}}return n}M(t,e){this.O(),this.G();const n=this.B(t,e);this.X=[],this.Y=Array.from(n.children).filter(e=>this.g.get(e)&&e!==t.result);let r=n;for(let e=t.q;e<t.chain.length;e++){const o=t.chain[e].element;o&&(r.appendChild(o),this.g.set(o,!0),r===n&&this.X.push(o),r=o)}}L(){this.Y&&nt(this.Y),this.Y=null,this.X=null}G(){this.Y&&this.X&&(nt(this.X),this.Y=null,this.X=null)}I(t,e){if(e)for(let n=e.chain.length-1;n>=t.q&&this.$(t);n--){const r=e.chain[n].element;if(r)try{const n=Y(t);tt(r.onAfterLeave,[n,{},e.resolver],r)}finally{this.Y.indexOf(r)>-1&&nt(r.children)}}}U(t){for(let e=t.q;e<t.chain.length&&this.$(t);e++){const n=t.chain[e].element||{},r=Y(t,t.chain[e].route);tt(n.onAfterEnter,[r,{},t.resolver],n)}}S(t){const e=(this.Y||[])[0],n=(this.X||[])[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=h(i)&&i.leave||"leaving",o=h(i)&&i.enter||"entering";r.push(G(e,t)),r.push(G(n,o))}return Promise.all(r).then(()=>t)}subscribe(){window.addEventListener("vaadin-router-go",this.m)}unsubscribe(){window.removeEventListener("vaadin-router-go",this.m)}v(t){const{pathname:e,search:n,hash:r}=t?t.detail:window.location;l(this.s(e))&&(t&&t.preventDefault&&t.preventDefault(),this.render({pathname:e,search:n,hash:r},!0))}static setTriggers(...t){J(t)}urlForName(t,e){return this.P||(this.P=q(this)),rt(this.P(t,e),this)}urlForPath(t,e){return rt(it.pathToRegexp.compile(t)(e),this)}static go(t){const{pathname:e,search:n,hash:r}=l(t)?this.u(t,"http://a"):t;return a("go",{pathname:e,search:n,hash:r})}}const st=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,ct=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function ut(t,e){if("function"!=typeof t)return;const n=st.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 at=function(t,e){if(window.Vaadin.developmentMode)return ut(t,e)};function ht(){}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&&(ct?!function(){if(ct){const t=Object.keys(ct).map(t=>ct[t]).filter(t=>t.productionMode);if(t.length>0)return!0}return!1}():!ut(function(){return!0}))}catch(t){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.5.0"}),at(ht),it.NavigationTrigger={POPSTATE:b,CLICK:m};export{D as Resolver,it as Router}; | ||
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||!l(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,c=["component","redirect","bundle"];if(!(f(t.action)||Array.isArray(t.children)||f(t.children)||h(s)||c.some(e=>l(t[e]))))throw new Error(e(`Expected route config "${t.path}" to include either "${c.join('", "')}" `+'or "action" function but none found.'));if(s)if(l(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 c(e){t(e).forEach(t=>s(t))}function u(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){return!window.dispatchEvent(new CustomEvent(`vaadin-router-${t}`,{cancelable:"go"===t,detail:e}))}function h(t){return"object"==typeof t&&!!t}function f(t){return"function"==typeof t}function l(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 p=new class{};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;if(!e||"a"!==e.nodeName.toLowerCase())return;if(e.target&&"_self"!==e.target.toLowerCase())return;if(e.hasAttribute("download"))return;if(e.pathname===window.location.pathname&&""!==e.hash)return;if((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)return;const{pathname:r,search:o,hash:i}=e;a("go",{pathname:r,search:o,hash:i})&&t.preventDefault()}const m={activate(){window.document.addEventListener("click",w)},inactivate(){window.document.removeEventListener("click",w)}};function v(t){if("vaadin-router-ignore"===t.state)return;const{pathname:e,search:n,hash:r}=window.location;a("go",{pathname:e,search:n,hash:r})}/Trident/.test(navigator.userAgent)&&!f(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 b={activate(){window.addEventListener("popstate",v)},inactivate(){window.removeEventListener("popstate",v)}};var y=B,_=R,g=function(t,e){return P(R(t,e))},E=P,$=T,O="/",j="./",x=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function R(t,e){for(var n,r=[],o=0,i=0,s="",c=e&&e.delimiter||O,u=e&&e.delimiters||j,a=!1;null!==(n=x.exec(t));){var h=n[0],f=n[1],l=n.index;if(s+=t.slice(i,l),i=l+h.length,f)s+=f[1],a=!0;else{var d="",p=t[i],w=n[2],m=n[3],v=n[4],b=n[5];if(!a&&s.length){var y=s.length-1;u.indexOf(s[y])>-1&&(d=s[y],s=s.slice(0,y))}s&&(r.push(s),s="",a=!1);var _=""!==d&&void 0!==p&&p!==d,g="+"===b||"*"===b,E="?"===b||"*"===b,$=d||c,R=m||v;r.push({name:w||o++,prefix:d,delimiter:$,optional:E,repeat:g,partial:_,pattern:R?A(R):"[^"+k($)+"]+?"})}}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 c=t[s];if("string"!=typeof c){var u,a=n?n[c.name]:void 0;if(Array.isArray(a)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but got array');if(0===a.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var h=0;h<a.length;h++){if(u=i(a[h],c),!e[s].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'"');o+=(0===h?c.prefix:c.delimiter)+u}}else if("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a){if(!c.optional)throw new TypeError('Expected "'+c.name+'" to be '+(c.repeat?"an array":"a string"));c.partial&&(o+=c.prefix)}else{if(u=i(String(a),c),!e[s].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but got "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function k(t){return t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function A(t){return t.replace(/([=!:$/()])/g,"\\$1")}function C(t){return t&&t.sensitive?"":"i"}function T(t,e,n){for(var r=(n=n||{}).strict,o=!1!==n.start,i=!1!==n.end,s=k(n.delimiter||O),c=n.delimiters||j,u=[].concat(n.endsWith||[]).map(k).concat("$").join("|"),a=o?"^":"",h=0===t.length,f=0;f<t.length;f++){var l=t[f];if("string"==typeof l)a+=k(l),h=f===t.length-1&&c.indexOf(l[l.length-1])>-1;else{var d=l.repeat?"(?:"+l.pattern+")(?:"+k(l.delimiter)+"(?:"+l.pattern+"))*":l.pattern;e&&e.push(l),l.optional?l.partial?a+=k(l.prefix)+"("+d+")?":a+="(?:"+k(l.prefix)+"("+d+"))?":a+=k(l.prefix)+"("+d+")"}}return i?(r||(a+="(?:"+s+")?"),a+="$"===u?"$":"(?="+u+")"):(r||(a+="(?:"+s+"(?="+u+"))?"),h||(a+="(?="+s+"|"+u+")")),new RegExp(a,C(n))}function B(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(B(t[o],e,n).source);return new RegExp("(?:"+r.join("|")+")",C(n))}(t,e,n):function(t,e,n){return T(R(t,n),e,n)}(t,e,n)}y.parse=_,y.compile=g,y.tokensToFunction=E,y.tokensToRegExp=$;const{hasOwnProperty:M}=Object.prototype,S=new Map;function U(t){try{return decodeURIComponent(t)}catch(e){return t}}function I(t,e,n,r,o){let i,s,c=0,u=t.path||"";return"/"===u.charAt(0)&&(n&&(u=u.substr(1)),n=!0),{next(a){if(t===a)return{done:!0};const h=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 c=s.pattern.exec(e);if(!c)return null;const u=Object.assign({},o);for(let t=1;t<c.length;t++){const e=s.keys[t-1],n=e.name,r=c[t];void 0===r&&M.call(u,n)||(e.repeat?u[n]=r?r.split(e.delimiter).map(U):[]:u[n]=r?U(r):r)}return{path:c[0],keys:(r||[]).concat(s.keys),params:u}}(u,e,!h,r,o)))return{done:!1,value:{route:t,keys:i.keys,params:i.params,path:i.path}};if(i&&h)for(;c<h.length;){if(!s){const r=h[c];r.parent=t;let o=i.path.length;o>0&&"/"===e.charAt(o)&&(o+=1),s=I(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,c++}return{done:!0}}}}function L(t){if(f(t.route.action))return t.route.action(t)}S.set("|false",{keys:[],pattern:/(?:)/});class D{constructor(t,e={}){if(Object(t)!==t)throw new TypeError("Invalid routes");this.baseUrl=e.baseUrl||"",this.errorHandler=e.errorHandler,this.resolveRoute=e.resolveRoute||L,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){c(e);const n=[...t(e)];this.root.o=n}addRoutes(e){return c(e),this.root.o.push(...t(e)),this.getRoutes()}removeRoutes(){this.setRoutes([])}resolve(t){const e=Object.assign({},this.context,l(t)?{pathname:t}:t),n=I(this.root,this.s(e.pathname),this.baseUrl),r=this.resolveRoute;let o=null,i=null,s=e;function c(t,u=o.value.route,a){const h=null===a&&o.value.route;return o=i||n.next(h),i=null,t||!o.done&&function(t,e){let n=e;for(;n;)if((n=n.parent)===t)return!0;return!1}(u,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!==p?(s.result=e.result||e,s):c(t,u,e))):(i=o,Promise.resolve(p))}return e.next=c,Promise.resolve().then(()=>c(!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})}static u(t,e){return new URL(t,e)}get h(){return this.baseUrl?this.constructor.u(this.baseUrl,document.baseURI||document.URL).href.replace(/[^\/]*$/,""):""}s(t){if(!this.baseUrl)return t;const e=this.h,n=this.constructor.u(t,e).href;return n.slice(0,e.length)===e?n.slice(e.length):void 0}}D.pathToRegexp=y;const{pathToRegexp:F}=D,N=new Map;function H(t,e){const n=t.get(e);if(n&&n.length>1)throw new Error(`Duplicate route with name "${e}".`+" Try seting unique 'name' route properties.");return n&&n[0]}function W(t){let e=t.path;return void 0!==(e=Array.isArray(e)?e[0]:e)?e:""}function q(t,e={}){if(!(t instanceof D))throw new TypeError("An instance of Resolver is expected");const n=new Map;return(r,o)=>{let i=H(n,r);if(!(i||(n.clear(),function t(e,n,r){const o=n.name||n.component;if(o&&(e.has(o)?e.get(o).push(n):e.set(o,[n])),Array.isArray(r))for(let o=0;o<r.length;o++){const i=r[o];i.parent=n,t(e,i,i.o||i.children)}}(n,t.root,t.root.o),i=H(n,r))))throw new Error(`Route "${r}" not found`);let s=N.get(i.fullPath);if(!s){let t=W(i),e=i.parent;for(;e;){const n=W(e);n&&(t=n.replace(/\/$/,"")+"/"+t.replace(/^\//,"")),e=e.parent}const n=F.parse(t),r=F.tokensToFunction(n),o=Object.create(null);for(let t=0;t<n.length;t++)l(n[t])||(o[n[t].name]=!0);s={toPath:r,keys:o},N.set(t,s),i.fullPath=t}let c=s.toPath(o,e)||"/";if(e.stringifyQueryParams&&o){const t={},n=Object.keys(o);for(let e=0;e<n.length;e++){const r=n[e];s.keys[r]||(t[r]=o[r])}const r=e.stringifyQueryParams(t);r&&(c+="?"===r.charAt(0)?r:`?${r}`)}return c}}let z=[];function J(t){z.forEach(t=>t.inactivate()),t.forEach(t=>t.activate()),z=t}const K=t=>{const e=getComputedStyle(t).getPropertyValue("animation-name");return e&&"none"!==e},V=(t,e)=>{const n=()=>{t.removeEventListener("animationend",n),e()};t.addEventListener("animationend",n)};function G(t,e){return t.classList.add(e),new Promise(n=>{if(K(t)){const r=t.getBoundingClientRect(),o=`height: ${r.bottom-r.top}px; width: ${r.right-r.left}px`;t.setAttribute("style",`position: absolute; ${o}`),V(t,()=>{t.classList.remove(e),t.removeAttribute("style"),n()})}else t.classList.remove(e),n()})}const Q=256;function X(t){return null!==t&&void 0!==t}function Y({pathname:t="",search:e="",hash:n="",chain:r=[],params:o={},redirectFrom:i,resolver:s},c){const u=r.map(t=>t.route);return{baseUrl:s&&s.baseUrl||"",pathname:t,search:e,hash:n,routes:u,route:c||u.length&&u[u.length-1]||null,params:o,redirectFrom:i,getUrl:(t={})=>rt(it.pathToRegexp.compile(ot(u))(Object.assign({},o,t)),s)}}function Z(t,e){const n=Object.assign({},t.params);return{redirect:{pathname:e,from:t.pathname,params:n}}}function tt(t,e,n){if(f(t))return t.apply(n,e)}function et(t,e,n){return r=>r&&(r.cancel||r.redirect)?r:n?tt(n[t],e,n):void 0}function nt(t){if(t&&t.length){const e=t[0].parentNode;for(let n=0;n<t.length;n++)e.removeChild(t[n])}}function rt(t,e){const n=e.h;return n?e.constructor.u(t.replace(/^\//,""),n).pathname:t}function ot(t){return t.map(t=>t.path).reduce((t,e)=>e.length?t.replace(/\/$/,"")+"/"+e.replace(/^\//,""):t,"")}class it extends D{constructor(t,e){const n=document.head.querySelector("base");super([],Object.assign({baseUrl:n&&n.getAttribute("href")},e)),this.resolveRoute=(t=>this.l(t));const r=it.NavigationTrigger;it.setTriggers.apply(it,Object.keys(r).map(t=>r[t])),this.baseUrl,this.ready,this.ready=Promise.resolve(t),this.location,this.location=Y({resolver:this}),this.p=0,this.m=this.v.bind(this),this.setOutlet(t),this.subscribe(),this._=new WeakMap,this.g=new WeakMap}l(n){const r=n.route;let i=Promise.resolve();f(r.children)&&(i=i.then(()=>r.children(function(t){const e=Object.assign({},t);return delete e.next,e}(n))).then(n=>{X(n)||f(r.children)||(n=r.children),function(n,r){if(!Array.isArray(n)&&!h(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 c={redirect:t=>Z(n,t),component:t=>{const e=document.createElement(t);return this._.set(e,!0),e}};return i.then(()=>{if(this.$(n))return tt(r.action,[n,c],r)}).then(t=>X(t)&&(t instanceof HTMLElement||t.redirect||t===p)?t:l(r.redirect)?c.redirect(r.redirect):r.bundle?(a=r.bundle,l(a)?u(a):Promise.race(o.filter(t=>t in a).map(t=>u(a[t],t)))).then(()=>{},()=>{throw new Error(e(`Bundle not found: ${r.bundle}. Check if the file name is correct`))}):void 0).then(t=>X(t)?t:l(r.component)?c.component(r.component):void 0);var a}setOutlet(t){t&&this.O(t),this.j=t}getOutlet(){return this.j}setRoutes(t,e=!1){return this.R=void 0,this.P=void 0,super.setRoutes(t),e||this.v(),this.ready}render(t,e){const n=++this.p,r=Object.assign({search:"",hash:""},l(t)?{pathname:t}:t,{k:n});return this.ready=this.resolve(r).then(t=>this.A(t)).then(t=>{if(this.$(t)){const r=this.R;if(t===r)return this.C(r,!0),this.location;if(this.location=Y(t),e&&this.C(t,1===n),a("location-changed",{router:this,location:this.location}),t.T)return this.B(t,r),this.R=t,this.location;this.M(t,r);const o=this.S(t);return this.U(t),this.I(t,r),o.then(()=>{if(this.$(t))return this.L(),this.R=t,this.location})}}).catch(t=>{if(n===this.p)throw e&&this.C(r),nt(this.j&&this.j.children),this.location=Y(Object.assign(r,{resolver:this})),a("error",Object.assign({router:this,error:t},r)),t}),this.ready}A(t,e=t){return this.D(e).then(n=>{const r=n!==e?n:t;return n.next().then(t=>{if(null===t||t===p){if(rt(ot(n.chain),n.resolver)!==n.pathname)throw d(r)}return t&&t!==p?this.A(r,t):this.F(n)})})}D(t){const n=t.result;return n instanceof HTMLElement?(function(t,e){e.location=Y(t);const n=t.chain.map(t=>t.route).indexOf(t.route);t.chain[n].element=e}(t,n),Promise.resolve(t)):n.redirect?this.N(n.redirect,t.H,t.k).then(t=>this.D(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.")))}F(t){return this.W(t).then(e=>e===this.R||e===t?e:this.A(e))}W(t){const e=this.R||{},n=e.chain||[],r=t.chain;let o=Promise.resolve();const i=()=>({cancel:!0}),s=e=>Z(t,e);if(t.q=0,t.T=!1,n.length){for(let e=0;e<Math.min(n.length,r.length)&&(n[e].route===r[e].route&&(n[e].path===r[e].path||n[e].element===r[e].element)&&this.J(n[e].element,r[e].element));e=++t.q);if(t.T=r.length===n.length&&t.q==r.length&&this.J(t.result,e.result),t.T){for(let s=r.length-1;s>=0;s--)n[s].path===r[s].path&&t.search===e.search||(o=this.K(o,t,{prevent:i},n[s]));for(let c=0;c<r.length;c++)n[c].path===r[c].path&&t.search===e.search||(o=this.V(o,t,{prevent:i,redirect:s},r[c])),n[c].element.location=Y(t,n[c].route)}else for(let e=n.length-1;e>=t.q;e--)o=this.K(o,t,{prevent:i},n[e])}for(let e=t.q;!t.T&&e<r.length;e++)o=this.V(o,t,{prevent:i,redirect:s},r[e]);return o.then(e=>{if(e){if(e.cancel)return this.R.k=t.k,this.R;if(e.redirect)return this.N(e.redirect,t.H,t.k)}return t})}K(t,e,n,r){const o=Y(e);return t.then(t=>{if(this.$(e)){return et("onBeforeLeave",[o,n,this],r.element)(t)}}).then(t=>{if(!(t||{}).redirect)return t})}V(t,e,n,r){const o=Y(e,r.route);return t.then(t=>{if(this.$(e)){return et("onBeforeEnter",[o,n,this],r.element)(t)}})}J(t,e){return!(!t||!e)&&(this._.get(t)&&this._.get(e)?t.localName===e.localName:t===e)}$(t){return t.k===this.p}N(t,n,r){if(n>Q)throw new Error(e(`Too many redirects when rendering ${t.from}`));return this.resolve({pathname:this.urlForPath(t.pathname,t.params),redirectFrom:t.from,H:(n||0)+1,k:r})}O(t=this.j){if(!(t instanceof Node))throw new TypeError(e(`Expected router outlet to be a valid DOM Node (but got ${t})`))}C({pathname:t,search:e="",hash:n=""},r){if(window.location.pathname!==t||window.location.search!==e||window.location.hash!==n){const o=r?"replaceState":"pushState";window.history[o](null,document.title,t+e+n),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}B(t,e){let n=this.j;for(let r=0;r<t.q;r++){const o=e&&e.chain[r].element;if(o){if(o.parentNode!==n)break;t.chain[r].element=o,n=o}}return n}M(t,e){this.O(),this.G();const n=this.B(t,e);this.X=[],this.Y=Array.from(n.children).filter(e=>this.g.get(e)&&e!==t.result);let r=n;for(let e=t.q;e<t.chain.length;e++){const o=t.chain[e].element;o&&(r.appendChild(o),this.g.set(o,!0),r===n&&this.X.push(o),r=o)}}L(){this.Y&&nt(this.Y),this.Y=null,this.X=null}G(){this.Y&&this.X&&(nt(this.X),this.Y=null,this.X=null)}I(t,e){if(e)for(let n=e.chain.length-1;n>=t.q&&this.$(t);n--){const r=e.chain[n].element;if(r)try{const n=Y(t);tt(r.onAfterLeave,[n,{},e.resolver],r)}finally{this.Y.indexOf(r)>-1&&nt(r.children)}}}U(t){for(let e=t.q;e<t.chain.length&&this.$(t);e++){const n=t.chain[e].element||{},r=Y(t,t.chain[e].route);tt(n.onAfterEnter,[r,{},t.resolver],n)}}S(t){const e=(this.Y||[])[0],n=(this.X||[])[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=h(i)&&i.leave||"leaving",o=h(i)&&i.enter||"entering";r.push(G(e,t)),r.push(G(n,o))}return Promise.all(r).then(()=>t)}subscribe(){window.addEventListener("vaadin-router-go",this.m)}unsubscribe(){window.removeEventListener("vaadin-router-go",this.m)}v(t){const{pathname:e,search:n,hash:r}=t?t.detail:window.location;l(this.s(e))&&(t&&t.preventDefault&&t.preventDefault(),this.render({pathname:e,search:n,hash:r},!0))}static setTriggers(...t){J(t)}urlForName(t,e){return this.P||(this.P=q(this)),rt(this.P(t,e),this)}urlForPath(t,e){return rt(it.pathToRegexp.compile(t)(e),this)}static go(t){const{pathname:e,search:n,hash:r}=l(t)?this.u(t,"http://a"):t;return a("go",{pathname:e,search:n,hash:r})}}const st=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,ct=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function ut(t,e){if("function"!=typeof t)return;const n=st.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 at=function(t,e){if(window.Vaadin.developmentMode)return ut(t,e)};function ht(){}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&&(ct?!function(){if(ct){const t=Object.keys(ct).map(t=>ct[t]).filter(t=>t.productionMode);if(t.length>0)return!0}return!1}():!ut(function(){return!0}))}catch(t){return!1}}());window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.5.1"}),at(ht),it.NavigationTrigger={POPSTATE:b,CLICK:m};export{D as Resolver,it as Router}; |
@@ -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=e||self).Vaadin=e.Vaadin||{})}(this,function(e){"use strict";function t(e){return(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})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=a(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(n):o.value}})(e,t,n||e)}function l(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function s(e){return e=e||[],Array.isArray(e)?e:[e]}function h(e){return"[Vaadin.Router] ".concat(e)}var f="module",d="nomodule",p=[f,d];function v(e){if(!e.match(/.+\.[m]?js$/))throw new Error(h('Unsupported type for bundle "'.concat(e,'": .js or .mjs expected.')))}function _(e){if(!e||!E(e.path))throw new Error(h('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(!(b(e.action)||Array.isArray(e.children)||b(e.children)||w(t)||n.some(function(t){return E(e[t])})))throw new Error(h('Expected route config "'.concat(e.path,'" to include either "').concat(n.join('", "'),'" ')+'or "action" function but none found.'));if(t)if(E(t))v(t);else{if(!p.some(function(e){return e in t}))throw new Error(h('Expected route bundle to include either "'+d+'" or "'+f+'" keys, or both'));p.forEach(function(e){return e in t&&v(t[e])})}e.redirect&&["bundle","component"].forEach(function(t){t in e&&console.warn(h('Route config "'.concat(e.path,'" has both "redirect" and "').concat(t,'" properties, ')+'and "redirect" will always override the latter. Did you mean to only use "'.concat(t,'"?')))})}function m(e){s(e).forEach(function(e){return _(e)})}function g(e,t){var n=document.head.querySelector('script[src="'+e+'"][async]');return n||((n=document.createElement("script")).setAttribute("src",e),t===f?n.setAttribute("type",f):t===d&&n.setAttribute(d,""),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 y(e,t){return!window.dispatchEvent(new CustomEvent("vaadin-router-".concat(e),{cancelable:"go"===e,detail:t}))}function w(e){return"object"===t(e)&&!!e}function b(e){return"function"==typeof e}function E(e){return"string"==typeof e}function k(e){var t=new Error(h("Page not found (".concat(e.pathname,")")));return t.context=e,t.code=404,t}var C=new function e(){n(this,e)};function x(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)if((t.origin||function(e){var t=e.port,n=e.protocol,r="http:"===n&&"80"===t||"https:"===n&&"443"===t?e.hostname:e.host;return"".concat(n,"//").concat(r)}(t))===window.location.origin){var a=t;y("go",{pathname:a.pathname,search:a.search,hash:a.hash})&&e.preventDefault()}}}var O={activate:function(){window.document.addEventListener("click",x)},inactivate:function(){window.document.removeEventListener("click",x)}};function R(e){if("vaadin-router-ignore"!==e.state){var t=window.location;y("go",{pathname:t.pathname,search:t.search,hash:t.hash})}}/Trident/.test(navigator.userAgent)&&!b(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 A={activate:function(){window.addEventListener("popstate",R)},inactivate:function(){window.removeEventListener("popstate",R)}},j=$,P=N,L=function(e,t){return M(N(e,t))},I=M,U=D,T="/",B="./",S=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function N(e,t){for(var n,r=[],o=0,a=0,i="",c=t&&t.delimiter||T,u=t&&t.delimiters||B,l=!1;null!==(n=S.exec(e));){var s=n[0],h=n[1],f=n.index;if(i+=e.slice(a,f),a=f+s.length,h)i+=h[1],l=!0;else{var d="",p=e[a],v=n[2],_=n[3],m=n[4],g=n[5];if(!l&&i.length){var y=i.length-1;u.indexOf(i[y])>-1&&(d=i[y],i=i.slice(0,y))}i&&(r.push(i),i="",l=!1);var w=""!==d&&void 0!==p&&p!==d,b="+"===g||"*"===g,E="?"===g||"*"===g,k=d||c,C=_||m;r.push({name:v||o++,prefix:d,delimiter:k,optional:E,repeat:b,partial:w,pattern:C?F(C):"[^"+V(k)+"]+?"})}}return(i||a<e.length)&&r.push(i+e.substr(a)),r}function M(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="",a=r&&r.encode||encodeURIComponent,i=0;i<e.length;i++){var c=e[i];if("string"!=typeof c){var u,l=t?t[c.name]:void 0;if(Array.isArray(l)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but got array');if(0===l.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var s=0;s<l.length;s++){if(u=a(l[s],c),!n[i].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'"');o+=(0===s?c.prefix:c.delimiter)+u}}else if("string"!=typeof l&&"number"!=typeof l&&"boolean"!=typeof l){if(!c.optional)throw new TypeError('Expected "'+c.name+'" to be '+(c.repeat?"an array":"a string"));c.partial&&(o+=c.prefix)}else{if(u=a(String(l),c),!n[i].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but got "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function V(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function F(e){return e.replace(/([=!:$/()])/g,"\\$1")}function H(e){return e&&e.sensitive?"":"i"}function D(e,t,n){for(var r=(n=n||{}).strict,o=!1!==n.start,a=!1!==n.end,i=V(n.delimiter||T),c=n.delimiters||B,u=[].concat(n.endsWith||[]).map(V).concat("$").join("|"),l=o?"^":"",s=0===e.length,h=0;h<e.length;h++){var f=e[h];if("string"==typeof f)l+=V(f),s=h===e.length-1&&c.indexOf(f[f.length-1])>-1;else{var d=f.repeat?"(?:"+f.pattern+")(?:"+V(f.delimiter)+"(?:"+f.pattern+"))*":f.pattern;t&&t.push(f),f.optional?f.partial?l+=V(f.prefix)+"("+d+")?":l+="(?:"+V(f.prefix)+"("+d+"))?":l+=V(f.prefix)+"("+d+")"}}return a?(r||(l+="(?:"+i+")?"),l+="$"===u?"$":"(?="+u+")"):(r||(l+="(?:"+i+"(?="+u+"))?"),s||(l+="(?="+i+"|"+u+")")),new RegExp(l,H(n))}function $(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($(e[o],t,n).source);return new RegExp("(?:"+r.join("|")+")",H(n))}(e,t,n):function(e,t,n){return D(N(e,n),t,n)}(e,t,n)}j.parse=P,j.compile=L,j.tokensToFunction=I,j.tokensToRegExp=U;var K=Object.prototype.hasOwnProperty,W=new Map;function q(e){try{return decodeURIComponent(e)}catch(t){return e}}function z(e,t,n,r,o){var a,i,c=0,u=e.path||"";return"/"===u.charAt(0)&&(n&&(u=u.substr(1)),n=!0),{next:function(l){if(e===l)return{done:!0};var s=e.__children=e.__children||e.children;if(!a&&(a=function(e,t,n,r,o){n=!!n;var a="".concat(e,"|").concat(n),i=W.get(a);if(!i){var c=[];i={keys:c,pattern:j(e,c,{end:n,strict:""===e})},W.set(a,i)}var u=i.pattern.exec(t);if(!u)return null;for(var l=Object.assign({},o),s=1;s<u.length;s++){var h=i.keys[s-1],f=h.name,d=u[s];void 0===d&&K.call(l,f)||(h.repeat?l[f]=d?d.split(h.delimiter).map(q):[]:l[f]=d?q(d):d)}return{path:u[0],keys:(r||[]).concat(i.keys),params:l}}(u,t,!s,r,o)))return{done:!1,value:{route:e,keys:a.keys,params:a.params,path:a.path}};if(a&&s)for(;c<s.length;){if(!i){var h=s[c];h.parent=e;var f=a.path.length;f>0&&"/"===t.charAt(f)&&(f+=1),i=z(h,t.substr(f),n,a.keys,a.params)}var d=i.next(l);if(!d.done)return{done:!1,value:d.value};i=null,c++}return{done:!0}}}}function Q(e){if(b(e.route.action))return e.route.action(e)}W.set("|false",{keys:[],pattern:/(?:)/});var J=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||Q,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 o(e,[{key:"getRoutes",value:function(){return l(this.root.__children)}},{key:"setRoutes",value:function(e){m(e);var t=l(s(e));this.root.__children=t}},{key:"addRoutes",value:function(e){var t;return m(e),(t=this.root.__children).push.apply(t,l(s(e))),this.getRoutes()}},{key:"removeRoutes",value:function(){this.setRoutes([])}},{key:"resolve",value:function(e){var t=this,n=Object.assign({},this.context,E(e)?{pathname:e}:e),r=z(this.root,this.__normalizePathname(n.pathname),this.baseUrl),o=this.resolveRoute,a=null,i=null,c=n;function u(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a.value.route,l=null===(arguments.length>2?arguments[2]:void 0)&&a.value.route;return a=i||r.next(l),i=null,e||!a.done&&function(e,t){for(var n=t;n;)if((n=n.parent)===e)return!0;return!1}(t,a.value.route)?a.done?Promise.reject(k(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,a.value),c=Object.assign({},n,a.value),Promise.resolve(o(c)).then(function(n){return null!==n&&void 0!==n&&n!==C?(c.result=n.result||n,c):u(e,t,n)})):(i=a,Promise.resolve(C))}return n.next=u,Promise.resolve().then(function(){return u(!0,t.root)}).catch(function(e){var n=function(e){var t="Path '".concat(e.pathname,"' is not properly resolved due to an error."),n=(e.route||{}).path;return n&&(t+=" Resolution had failed on route: '".concat(n,"'")),t}(c);if(e?console.warn(n):e=new Error(n),e.context=e.context||c,e instanceof DOMException||(e.code=e.code||500),t.errorHandler)return c.result=t.errorHandler(e),c;throw e})}},{key:"__normalizePathname",value:function(e){if(!this.baseUrl)return e;var t=this.__effectiveBaseUrl,n=this.constructor.__createUrl(e,t).href;return n.slice(0,t.length)===t?n.slice(t.length):void 0}},{key:"__effectiveBaseUrl",get:function(){return this.baseUrl?this.constructor.__createUrl(this.baseUrl,document.baseURI||document.URL).href.replace(/[^\/]*$/,""):""}}],[{key:"__createUrl",value:function(e,t){return new URL(e,t)}}]),e}();J.pathToRegexp=j;var G=J.pathToRegexp,X=new Map;function Y(e,t){var n=e.get(t);if(n&&n.length>1)throw new Error('Duplicate route with name "'.concat(t,'".')+" Try seting unique 'name' route properties.");return n&&n[0]}function Z(e){var t=e.path;return void 0!==(t=Array.isArray(t)?t[0]:t)?t:""}function ee(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(e instanceof J))throw new TypeError("An instance of Resolver is expected");var n=new Map;return function(r,o){var a=Y(n,r);if(!(a||(n.clear(),function e(t,n,r){var o=n.name||n.component;if(o&&(t.has(o)?t.get(o).push(n):t.set(o,[n])),Array.isArray(r))for(var a=0;a<r.length;a++){var i=r[a];i.parent=n,e(t,i,i.__children||i.children)}}(n,e.root,e.root.__children),a=Y(n,r))))throw new Error('Route "'.concat(r,'" not found'));var i=X.get(a.fullPath);if(!i){for(var c=Z(a),u=a.parent;u;){var l=Z(u);l&&(c=l.replace(/\/$/,"")+"/"+c.replace(/^\//,"")),u=u.parent}for(var s=G.parse(c),h=G.tokensToFunction(s),f=Object.create(null),d=0;d<s.length;d++)E(s[d])||(f[s[d].name]=!0);i={toPath:h,keys:f},X.set(c,i),a.fullPath=c}var p=i.toPath(o,t)||"/";if(t.stringifyQueryParams&&o){for(var v={},_=Object.keys(o),m=0;m<_.length;m++){var g=_[m];i.keys[g]||(v[g]=o[g])}var y=t.stringifyQueryParams(v);y&&(p+="?"===y.charAt(0)?y:"?".concat(y))}return p}}var te=[];function ne(e){te.forEach(function(e){return e.inactivate()}),e.forEach(function(e){return e.activate()}),te=e}var re=function(e){var t=getComputedStyle(e).getPropertyValue("animation-name");return t&&"none"!==t},oe=function(e,t){e.addEventListener("animationend",function n(){e.removeEventListener("animationend",n),t()})};function ae(e,t){return e.classList.add(t),new Promise(function(n){if(re(e)){var r=e.getBoundingClientRect(),o="height: ".concat(r.bottom-r.top,"px; width: ").concat(r.right-r.left,"px");e.setAttribute("style","position: absolute; ".concat(o)),oe(e,function(){e.classList.remove(t),e.removeAttribute("style"),n()})}else e.classList.remove(t),n()})}function ie(e){return null!==e&&void 0!==e}function ce(e,t){var n=e.pathname,r=void 0===n?"":n,o=e.search,a=void 0===o?"":o,i=e.hash,c=void 0===i?"":i,u=e.chain,l=void 0===u?[]:u,s=e.params,h=void 0===s?{}:s,f=e.redirectFrom,d=e.resolver,p=l.map(function(e){return e.route});return{baseUrl:d&&d.baseUrl||"",pathname:r,search:a,hash:c,routes:p,route:t||p.length&&p[p.length-1]||null,params:h,redirectFrom:f,getUrl:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return fe(pe.pathToRegexp.compile(de(p))(Object.assign({},h,e)),d)}}}function ue(e,t){var n=Object.assign({},e.params);return{redirect:{pathname:t,from:e.pathname,params:n}}}function le(e,t,n){if(b(e))return e.apply(n,t)}function se(e,t,n){return function(r){return r&&(r.cancel||r.redirect)?r:n?le(n[e],t,n):void 0}}function he(e){if(e&&e.length)for(var t=e[0].parentNode,n=0;n<e.length;n++)t.removeChild(e[n])}function fe(e,t){var n=t.__effectiveBaseUrl;return n?t.constructor.__createUrl(e.replace(/^\//,""),n).pathname:e}function de(e){return e.map(function(e){return e.path}).reduce(function(e,t){return t.length?e.replace(/\/$/,"")+"/"+t.replace(/^\//,""):e},"")}var pe=function(e){function r(e,t){var o;n(this,r);var i,u,l=document.head.querySelector("base");i=this,u=a(r).call(this,[],Object.assign({baseUrl:l&&l.getAttribute("href")},t)),(o=!u||"object"!=typeof u&&"function"!=typeof u?c(i):u).resolveRoute=function(e){return o.__resolveRoute(e)};var s=r.NavigationTrigger;return r.setTriggers.apply(r,Object.keys(s).map(function(e){return s[e]})),o.baseUrl,o.ready,o.ready=Promise.resolve(e),o.location,o.location=ce({resolver:c(o)}),o.__lastStartedRenderId=0,o.__navigationEventHandler=o.__onNavigationEvent.bind(c(o)),o.setOutlet(e),o.subscribe(),o.__createdByRouter=new WeakMap,o.__addedByRouter=new WeakMap,o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}(r,J),o(r,[{key:"__resolveRoute",value:function(e){var t=this,n=e.route,r=Promise.resolve();b(n.children)&&(r=r.then(function(){return n.children(function(e){var t=Object.assign({},e);return delete t.next,t}(e))}).then(function(e){ie(e)||b(n.children)||(e=n.children),function(e,t){if(!Array.isArray(e)&&!w(e))throw new Error(h('Incorrect "children" value for the route '.concat(t.path,": expected array or object, but got ").concat(e)));t.__children=[];for(var n=s(e),r=0;r<n.length;r++)_(n[r]),t.__children.push(n[r])}(e,n)}));var o={redirect:function(t){return ue(e,t)},component:function(e){var n=document.createElement(e);return t.__createdByRouter.set(n,!0),n}};return r.then(function(){if(t.__isLatestRender(e))return le(n.action,[e,o],n)}).then(function(e){return ie(e)&&(e instanceof HTMLElement||e.redirect||e===C)?e:E(n.redirect)?o.redirect(n.redirect):n.bundle?(t=n.bundle,E(t)?g(t):Promise.race(p.filter(function(e){return e in t}).map(function(e){return g(t[e],e)}))).then(function(){},function(){throw new Error(h("Bundle not found: ".concat(n.bundle,". Check if the file name is correct")))}):void 0;var t}).then(function(e){return ie(e)?e:E(n.component)?o.component(n.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){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.__previousContext=void 0,this.__urlForName=void 0,u(a(r.prototype),"setRoutes",this).call(this,e),t||this.__onNavigationEvent(),this.ready}},{key:"render",value:function(e,t){var n=this,r=++this.__lastStartedRenderId,o=Object.assign({search:"",hash:""},E(e)?{pathname:e}:e,{__renderId:r});return this.ready=this.resolve(o).then(function(e){return n.__fullyResolveChain(e)}).then(function(e){if(n.__isLatestRender(e)){var r=n.__previousContext;if(e===r)return n.__updateBrowserHistory(r,!0),n.location;if(n.location=ce(e),y("location-changed",{router:n,location:n.location}),t&&n.__updateBrowserHistory(e,e.redirectFrom),e.__skipAttach)return n.__copyUnchangedElements(e,r),n.__previousContext=e,n.location;n.__addAppearingContent(e,r);var o=n.__animateIfNeeded(e);return n.__runOnAfterEnterCallbacks(e),n.__runOnAfterLeaveCallbacks(e,r),o.then(function(){if(n.__isLatestRender(e))return n.__removeDisappearingContent(),n.__previousContext=e,n.location})}}).catch(function(e){if(r===n.__lastStartedRenderId)throw t&&n.__updateBrowserHistory(o),he(n.__outlet&&n.__outlet.children),n.location=ce(Object.assign(o,{resolver:n})),y("error",Object.assign({router:n,error:e},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.__findComponentContextAfterAllRedirects(n).then(function(r){var o=r!==n?r:e;return r.next().then(function(e){if((null===e||e===C)&&fe(de(r.chain),r.resolver)!==r.pathname)throw k(o);return e&&e!==C?t.__fullyResolveChain(o,e):t.__amendWithOnBeforeCallbacks(r)})})}},{key:"__findComponentContextAfterAllRedirects",value:function(e){var n=this,r=e.result;return r instanceof HTMLElement?(function(e,t){t.location=ce(e);var n=e.chain.map(function(e){return e.route}).indexOf(e.route);e.chain[n].element=t}(e,r),Promise.resolve(e)):r.redirect?this.__redirect(r.redirect,e.__redirectCount,e.__renderId).then(function(e){return n.__findComponentContextAfterAllRedirects(e)}):r instanceof Error?Promise.reject(r):Promise.reject(new Error(h('Invalid route resolution result for path "'.concat(e.pathname,'". ')+'Expected redirect object or HTML element, but got: "'.concat(function(e){if("object"!==t(e))return String(e);var n=Object.prototype.toString.call(e).match(/ (.*)\]$/)[1];return"Object"===n||"Array"===n?"".concat(n," ").concat(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||{},r=n.chain||[],o=e.chain,a=Promise.resolve(),i=function(){return{cancel:!0}},c=function(t){return ue(e,t)};if(e.__divergedChainIndex=0,e.__skipAttach=!1,r.length){for(var u=0;u<Math.min(r.length,o.length)&&(r[u].route===o[u].route&&(r[u].path===o[u].path||r[u].element===o[u].element)&&this.__isReusableElement(r[u].element,o[u].element));u=++e.__divergedChainIndex);if(e.__skipAttach=o.length===r.length&&e.__divergedChainIndex==o.length&&this.__isReusableElement(e.result,n.result),e.__skipAttach){for(var l=o.length-1;l>=0;l--)r[l].path===o[l].path&&e.search===n.search||(a=this.__runOnBeforeLeaveCallbacks(a,e,{prevent:i},r[l]));for(var s=0;s<o.length;s++)r[s].path===o[s].path&&e.search===n.search||(a=this.__runOnBeforeEnterCallbacks(a,e,{prevent:i,redirect:c},o[s])),r[s].element.location=ce(e,r[s].route)}else for(var h=r.length-1;h>=e.__divergedChainIndex;h--)a=this.__runOnBeforeLeaveCallbacks(a,e,{prevent:i},r[h])}for(var f=e.__divergedChainIndex;!e.__skipAttach&&f<o.length;f++)a=this.__runOnBeforeEnterCallbacks(a,e,{prevent:i,redirect:c},o[f]);return a.then(function(n){if(n){if(n.cancel)return t.__previousContext.__renderId=e.__renderId,t.__previousContext;if(n.redirect)return t.__redirect(n.redirect,e.__redirectCount,e.__renderId)}return e})}},{key:"__runOnBeforeLeaveCallbacks",value:function(e,t,n,r){var o=this,a=ce(t);return e.then(function(e){if(o.__isLatestRender(t))return se("onBeforeLeave",[a,n,o],r.element)(e)}).then(function(e){if(!(e||{}).redirect)return e})}},{key:"__runOnBeforeEnterCallbacks",value:function(e,t,n,r){var o=this,a=ce(t,r.route);return e.then(function(e){if(o.__isLatestRender(t))return se("onBeforeEnter",[a,n,o],r.element)(e)})}},{key:"__isReusableElement",value:function(e,t){return!(!e||!t)&&(this.__createdByRouter.get(e)&&this.__createdByRouter.get(t)?e.localName===t.localName:e===t)}},{key:"__isLatestRender",value:function(e){return e.__renderId===this.__lastStartedRenderId}},{key:"__redirect",value:function(e,t,n){if(t>256)throw new Error(h("Too many redirects when rendering ".concat(e.from)));return this.resolve({pathname:this.urlForPath(e.pathname,e.params),redirectFrom:e.from,__redirectCount:(t||0)+1,__renderId:n})}},{key:"__ensureOutlet",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.__outlet;if(!(e instanceof Node))throw new TypeError(h("Expected router outlet to be a valid DOM Node (but got ".concat(e,")")))}},{key:"__updateBrowserHistory",value:function(e,t){var n=e.pathname,r=e.search,o=void 0===r?"":r,a=e.hash,i=void 0===a?"":a;if(window.location.pathname!==n||window.location.search!==o||window.location.hash!==i){var c=t?"replaceState":"pushState";window.history[c](null,document.title,n+o+i),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}},{key:"__copyUnchangedElements",value:function(e,t){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}}return n}},{key:"__addAppearingContent",value:function(e,t){var n=this;this.__ensureOutlet(),this.__removeAppearingContent();var r=this.__copyUnchangedElements(e,t);this.__appearingContent=[],this.__disappearingContent=Array.from(r.children).filter(function(t){return n.__addedByRouter.get(t)&&t!==e.result});for(var o=r,a=e.__divergedChainIndex;a<e.chain.length;a++){var i=e.chain[a].element;i&&(o.appendChild(i),this.__addedByRouter.set(i,!0),o===r&&this.__appearingContent.push(i),o=i)}}},{key:"__removeDisappearingContent",value:function(){this.__disappearingContent&&he(this.__disappearingContent),this.__disappearingContent=null,this.__appearingContent=null}},{key:"__removeAppearingContent",value:function(){this.__disappearingContent&&this.__appearingContent&&(he(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&&this.__isLatestRender(e);n--){var r=t.chain[n].element;if(r)try{var o=ce(e);le(r.onAfterLeave,[o,{},t.resolver],r)}finally{this.__disappearingContent.indexOf(r)>-1&&he(r.children)}}}},{key:"__runOnAfterEnterCallbacks",value:function(e){for(var t=e.__divergedChainIndex;t<e.chain.length&&this.__isLatestRender(e);t++){var n=e.chain[t].element||{},r=ce(e,e.chain[t].route);le(n.onAfterEnter,[r,{},e.resolver],n)}}},{key:"__animateIfNeeded",value:function(e){for(var t,n=(this.__disappearingContent||[])[0],r=(this.__appearingContent||[])[0],o=[],a=e.chain,i=a.length;i>0;i--)if(a[i-1].route.animate){t=a[i-1].route.animate;break}if(n&&r&&t){var c=w(t)&&t.leave||"leaving",u=w(t)&&t.enter||"entering";o.push(ae(n,c)),o.push(ae(r,u))}return Promise.all(o).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:window.location,n=t.pathname,r=t.search,o=t.hash;E(this.__normalizePathname(n))&&(e&&e.preventDefault&&e.preventDefault(),this.render({pathname:n,search:r,hash:o},!0))}},{key:"urlForName",value:function(e,t){return this.__urlForName||(this.__urlForName=ee(this)),fe(this.__urlForName(e,t),this)}},{key:"urlForPath",value:function(e,t){return fe(r.pathToRegexp.compile(e)(t),this)}}],[{key:"setTriggers",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];ne(t)}},{key:"go",value:function(e){var t=E(e)?this.__createUrl(e,"http://a"):e;return y("go",{pathname:t.pathname,search:t.search,hash:t.hash})}}]),r}(),ve=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,_e=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function me(e,t){if("function"==typeof e){var n=ve.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 ge=function(e,t){if(window.Vaadin.developmentMode)return me(e,t)};function ye(){}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&&(_e?!function(){if(_e){var e=Object.keys(_e).map(function(e){return _e[e]}).filter(function(e){return e.productionMode});if(e.length>0)return!0}return!1}():!me(function(){return!0}))}catch(e){return!1}}());var we,be,Ee,ke;window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.5.0"}),ge(ye),pe.NavigationTrigger={POPSTATE:A,CLICK:O},J.__ensureUrlAvailableOrPolyfilled=function(){if(void 0===we){try{var e=new URL("b","http://a");e.pathname="c",we="http://a/c"===e.href}catch(e){we=!1}if(!we&&(be=document.implementation.createHTMLDocument("url"),Ee=be.createElement("base"),be.head.appendChild(Ee),!(ke=be.createElement("a")).origin)){Object.defineProperty(ke,"origin",{get:function(){var e=ke.protocol,t=ke.port,n="http:"===e&&"80"===t||"https:"===e&&"443"===t?ke.hostname:ke.host;return"".concat(e,"//").concat(n)}});var t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ke),"pathname").get;Object.defineProperty(ke,"pathname",{get:function(){var e=t.apply(ke);return"/"!==e.charAt(0)?"/"+e:e}})}}},J.__createUrl=function(e,t){return J.__ensureUrlAvailableOrPolyfilled(),we?new URL(e,t):(Ee.href=t,ke.href=e.replace(/ /g,"%20"),ke.href=ke.href,ke)},e.Resolver=J,e.Router=pe,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=e||self).Vaadin=e.Vaadin||{})}(this,function(e){"use strict";function t(e){return(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})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t,n){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=a(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(n):o.value}})(e,t,n||e)}function l(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function s(e){return e=e||[],Array.isArray(e)?e:[e]}function h(e){return"[Vaadin.Router] ".concat(e)}var f="module",d="nomodule",p=[f,d];function v(e){if(!e.match(/.+\.[m]?js$/))throw new Error(h('Unsupported type for bundle "'.concat(e,'": .js or .mjs expected.')))}function _(e){if(!e||!E(e.path))throw new Error(h('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(!(b(e.action)||Array.isArray(e.children)||b(e.children)||w(t)||n.some(function(t){return E(e[t])})))throw new Error(h('Expected route config "'.concat(e.path,'" to include either "').concat(n.join('", "'),'" ')+'or "action" function but none found.'));if(t)if(E(t))v(t);else{if(!p.some(function(e){return e in t}))throw new Error(h('Expected route bundle to include either "'+d+'" or "'+f+'" keys, or both'));p.forEach(function(e){return e in t&&v(t[e])})}e.redirect&&["bundle","component"].forEach(function(t){t in e&&console.warn(h('Route config "'.concat(e.path,'" has both "redirect" and "').concat(t,'" properties, ')+'and "redirect" will always override the latter. Did you mean to only use "'.concat(t,'"?')))})}function m(e){s(e).forEach(function(e){return _(e)})}function g(e,t){var n=document.head.querySelector('script[src="'+e+'"][async]');return n||((n=document.createElement("script")).setAttribute("src",e),t===f?n.setAttribute("type",f):t===d&&n.setAttribute(d,""),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 y(e,t){return!window.dispatchEvent(new CustomEvent("vaadin-router-".concat(e),{cancelable:"go"===e,detail:t}))}function w(e){return"object"===t(e)&&!!e}function b(e){return"function"==typeof e}function E(e){return"string"==typeof e}function k(e){var t=new Error(h("Page not found (".concat(e.pathname,")")));return t.context=e,t.code=404,t}var C=new function e(){n(this,e)};function x(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)if((t.origin||function(e){var t=e.port,n=e.protocol,r="http:"===n&&"80"===t||"https:"===n&&"443"===t?e.hostname:e.host;return"".concat(n,"//").concat(r)}(t))===window.location.origin){var a=t;y("go",{pathname:a.pathname,search:a.search,hash:a.hash})&&e.preventDefault()}}}var O={activate:function(){window.document.addEventListener("click",x)},inactivate:function(){window.document.removeEventListener("click",x)}};function R(e){if("vaadin-router-ignore"!==e.state){var t=window.location;y("go",{pathname:t.pathname,search:t.search,hash:t.hash})}}/Trident/.test(navigator.userAgent)&&!b(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 A={activate:function(){window.addEventListener("popstate",R)},inactivate:function(){window.removeEventListener("popstate",R)}},j=$,P=N,L=function(e,t){return M(N(e,t))},I=M,U=D,T="/",B="./",S=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");function N(e,t){for(var n,r=[],o=0,a=0,i="",c=t&&t.delimiter||T,u=t&&t.delimiters||B,l=!1;null!==(n=S.exec(e));){var s=n[0],h=n[1],f=n.index;if(i+=e.slice(a,f),a=f+s.length,h)i+=h[1],l=!0;else{var d="",p=e[a],v=n[2],_=n[3],m=n[4],g=n[5];if(!l&&i.length){var y=i.length-1;u.indexOf(i[y])>-1&&(d=i[y],i=i.slice(0,y))}i&&(r.push(i),i="",l=!1);var w=""!==d&&void 0!==p&&p!==d,b="+"===g||"*"===g,E="?"===g||"*"===g,k=d||c,C=_||m;r.push({name:v||o++,prefix:d,delimiter:k,optional:E,repeat:b,partial:w,pattern:C?F(C):"[^"+V(k)+"]+?"})}}return(i||a<e.length)&&r.push(i+e.substr(a)),r}function M(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="",a=r&&r.encode||encodeURIComponent,i=0;i<e.length;i++){var c=e[i];if("string"!=typeof c){var u,l=t?t[c.name]:void 0;if(Array.isArray(l)){if(!c.repeat)throw new TypeError('Expected "'+c.name+'" to not repeat, but got array');if(0===l.length){if(c.optional)continue;throw new TypeError('Expected "'+c.name+'" to not be empty')}for(var s=0;s<l.length;s++){if(u=a(l[s],c),!n[i].test(u))throw new TypeError('Expected all "'+c.name+'" to match "'+c.pattern+'"');o+=(0===s?c.prefix:c.delimiter)+u}}else if("string"!=typeof l&&"number"!=typeof l&&"boolean"!=typeof l){if(!c.optional)throw new TypeError('Expected "'+c.name+'" to be '+(c.repeat?"an array":"a string"));c.partial&&(o+=c.prefix)}else{if(u=a(String(l),c),!n[i].test(u))throw new TypeError('Expected "'+c.name+'" to match "'+c.pattern+'", but got "'+u+'"');o+=c.prefix+u}}else o+=c}return o}}function V(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function F(e){return e.replace(/([=!:$/()])/g,"\\$1")}function H(e){return e&&e.sensitive?"":"i"}function D(e,t,n){for(var r=(n=n||{}).strict,o=!1!==n.start,a=!1!==n.end,i=V(n.delimiter||T),c=n.delimiters||B,u=[].concat(n.endsWith||[]).map(V).concat("$").join("|"),l=o?"^":"",s=0===e.length,h=0;h<e.length;h++){var f=e[h];if("string"==typeof f)l+=V(f),s=h===e.length-1&&c.indexOf(f[f.length-1])>-1;else{var d=f.repeat?"(?:"+f.pattern+")(?:"+V(f.delimiter)+"(?:"+f.pattern+"))*":f.pattern;t&&t.push(f),f.optional?f.partial?l+=V(f.prefix)+"("+d+")?":l+="(?:"+V(f.prefix)+"("+d+"))?":l+=V(f.prefix)+"("+d+")"}}return a?(r||(l+="(?:"+i+")?"),l+="$"===u?"$":"(?="+u+")"):(r||(l+="(?:"+i+"(?="+u+"))?"),s||(l+="(?="+i+"|"+u+")")),new RegExp(l,H(n))}function $(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($(e[o],t,n).source);return new RegExp("(?:"+r.join("|")+")",H(n))}(e,t,n):function(e,t,n){return D(N(e,n),t,n)}(e,t,n)}j.parse=P,j.compile=L,j.tokensToFunction=I,j.tokensToRegExp=U;var K=Object.prototype.hasOwnProperty,W=new Map;function q(e){try{return decodeURIComponent(e)}catch(t){return e}}function z(e,t,n,r,o){var a,i,c=0,u=e.path||"";return"/"===u.charAt(0)&&(n&&(u=u.substr(1)),n=!0),{next:function(l){if(e===l)return{done:!0};var s=e.__children=e.__children||e.children;if(!a&&(a=function(e,t,n,r,o){n=!!n;var a="".concat(e,"|").concat(n),i=W.get(a);if(!i){var c=[];i={keys:c,pattern:j(e,c,{end:n,strict:""===e})},W.set(a,i)}var u=i.pattern.exec(t);if(!u)return null;for(var l=Object.assign({},o),s=1;s<u.length;s++){var h=i.keys[s-1],f=h.name,d=u[s];void 0===d&&K.call(l,f)||(h.repeat?l[f]=d?d.split(h.delimiter).map(q):[]:l[f]=d?q(d):d)}return{path:u[0],keys:(r||[]).concat(i.keys),params:l}}(u,t,!s,r,o)))return{done:!1,value:{route:e,keys:a.keys,params:a.params,path:a.path}};if(a&&s)for(;c<s.length;){if(!i){var h=s[c];h.parent=e;var f=a.path.length;f>0&&"/"===t.charAt(f)&&(f+=1),i=z(h,t.substr(f),n,a.keys,a.params)}var d=i.next(l);if(!d.done)return{done:!1,value:d.value};i=null,c++}return{done:!0}}}}function Q(e){if(b(e.route.action))return e.route.action(e)}W.set("|false",{keys:[],pattern:/(?:)/});var J=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||Q,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 o(e,[{key:"getRoutes",value:function(){return l(this.root.__children)}},{key:"setRoutes",value:function(e){m(e);var t=l(s(e));this.root.__children=t}},{key:"addRoutes",value:function(e){var t;return m(e),(t=this.root.__children).push.apply(t,l(s(e))),this.getRoutes()}},{key:"removeRoutes",value:function(){this.setRoutes([])}},{key:"resolve",value:function(e){var t=this,n=Object.assign({},this.context,E(e)?{pathname:e}:e),r=z(this.root,this.__normalizePathname(n.pathname),this.baseUrl),o=this.resolveRoute,a=null,i=null,c=n;function u(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a.value.route,l=null===(arguments.length>2?arguments[2]:void 0)&&a.value.route;return a=i||r.next(l),i=null,e||!a.done&&function(e,t){for(var n=t;n;)if((n=n.parent)===e)return!0;return!1}(t,a.value.route)?a.done?Promise.reject(k(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,a.value),c=Object.assign({},n,a.value),Promise.resolve(o(c)).then(function(n){return null!==n&&void 0!==n&&n!==C?(c.result=n.result||n,c):u(e,t,n)})):(i=a,Promise.resolve(C))}return n.next=u,Promise.resolve().then(function(){return u(!0,t.root)}).catch(function(e){var n=function(e){var t="Path '".concat(e.pathname,"' is not properly resolved due to an error."),n=(e.route||{}).path;return n&&(t+=" Resolution had failed on route: '".concat(n,"'")),t}(c);if(e?console.warn(n):e=new Error(n),e.context=e.context||c,e instanceof DOMException||(e.code=e.code||500),t.errorHandler)return c.result=t.errorHandler(e),c;throw e})}},{key:"__normalizePathname",value:function(e){if(!this.baseUrl)return e;var t=this.__effectiveBaseUrl,n=this.constructor.__createUrl(e,t).href;return n.slice(0,t.length)===t?n.slice(t.length):void 0}},{key:"__effectiveBaseUrl",get:function(){return this.baseUrl?this.constructor.__createUrl(this.baseUrl,document.baseURI||document.URL).href.replace(/[^\/]*$/,""):""}}],[{key:"__createUrl",value:function(e,t){return new URL(e,t)}}]),e}();J.pathToRegexp=j;var G=J.pathToRegexp,X=new Map;function Y(e,t){var n=e.get(t);if(n&&n.length>1)throw new Error('Duplicate route with name "'.concat(t,'".')+" Try seting unique 'name' route properties.");return n&&n[0]}function Z(e){var t=e.path;return void 0!==(t=Array.isArray(t)?t[0]:t)?t:""}function ee(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(e instanceof J))throw new TypeError("An instance of Resolver is expected");var n=new Map;return function(r,o){var a=Y(n,r);if(!(a||(n.clear(),function e(t,n,r){var o=n.name||n.component;if(o&&(t.has(o)?t.get(o).push(n):t.set(o,[n])),Array.isArray(r))for(var a=0;a<r.length;a++){var i=r[a];i.parent=n,e(t,i,i.__children||i.children)}}(n,e.root,e.root.__children),a=Y(n,r))))throw new Error('Route "'.concat(r,'" not found'));var i=X.get(a.fullPath);if(!i){for(var c=Z(a),u=a.parent;u;){var l=Z(u);l&&(c=l.replace(/\/$/,"")+"/"+c.replace(/^\//,"")),u=u.parent}for(var s=G.parse(c),h=G.tokensToFunction(s),f=Object.create(null),d=0;d<s.length;d++)E(s[d])||(f[s[d].name]=!0);i={toPath:h,keys:f},X.set(c,i),a.fullPath=c}var p=i.toPath(o,t)||"/";if(t.stringifyQueryParams&&o){for(var v={},_=Object.keys(o),m=0;m<_.length;m++){var g=_[m];i.keys[g]||(v[g]=o[g])}var y=t.stringifyQueryParams(v);y&&(p+="?"===y.charAt(0)?y:"?".concat(y))}return p}}var te=[];function ne(e){te.forEach(function(e){return e.inactivate()}),e.forEach(function(e){return e.activate()}),te=e}var re=function(e){var t=getComputedStyle(e).getPropertyValue("animation-name");return t&&"none"!==t},oe=function(e,t){e.addEventListener("animationend",function n(){e.removeEventListener("animationend",n),t()})};function ae(e,t){return e.classList.add(t),new Promise(function(n){if(re(e)){var r=e.getBoundingClientRect(),o="height: ".concat(r.bottom-r.top,"px; width: ").concat(r.right-r.left,"px");e.setAttribute("style","position: absolute; ".concat(o)),oe(e,function(){e.classList.remove(t),e.removeAttribute("style"),n()})}else e.classList.remove(t),n()})}function ie(e){return null!==e&&void 0!==e}function ce(e,t){var n=e.pathname,r=void 0===n?"":n,o=e.search,a=void 0===o?"":o,i=e.hash,c=void 0===i?"":i,u=e.chain,l=void 0===u?[]:u,s=e.params,h=void 0===s?{}:s,f=e.redirectFrom,d=e.resolver,p=l.map(function(e){return e.route});return{baseUrl:d&&d.baseUrl||"",pathname:r,search:a,hash:c,routes:p,route:t||p.length&&p[p.length-1]||null,params:h,redirectFrom:f,getUrl:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return fe(pe.pathToRegexp.compile(de(p))(Object.assign({},h,e)),d)}}}function ue(e,t){var n=Object.assign({},e.params);return{redirect:{pathname:t,from:e.pathname,params:n}}}function le(e,t,n){if(b(e))return e.apply(n,t)}function se(e,t,n){return function(r){return r&&(r.cancel||r.redirect)?r:n?le(n[e],t,n):void 0}}function he(e){if(e&&e.length)for(var t=e[0].parentNode,n=0;n<e.length;n++)t.removeChild(e[n])}function fe(e,t){var n=t.__effectiveBaseUrl;return n?t.constructor.__createUrl(e.replace(/^\//,""),n).pathname:e}function de(e){return e.map(function(e){return e.path}).reduce(function(e,t){return t.length?e.replace(/\/$/,"")+"/"+t.replace(/^\//,""):e},"")}var pe=function(e){function r(e,t){var o;n(this,r);var i,u,l=document.head.querySelector("base");i=this,u=a(r).call(this,[],Object.assign({baseUrl:l&&l.getAttribute("href")},t)),(o=!u||"object"!=typeof u&&"function"!=typeof u?c(i):u).resolveRoute=function(e){return o.__resolveRoute(e)};var s=r.NavigationTrigger;return r.setTriggers.apply(r,Object.keys(s).map(function(e){return s[e]})),o.baseUrl,o.ready,o.ready=Promise.resolve(e),o.location,o.location=ce({resolver:c(o)}),o.__lastStartedRenderId=0,o.__navigationEventHandler=o.__onNavigationEvent.bind(c(o)),o.setOutlet(e),o.subscribe(),o.__createdByRouter=new WeakMap,o.__addedByRouter=new WeakMap,o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}(r,J),o(r,[{key:"__resolveRoute",value:function(e){var t=this,n=e.route,r=Promise.resolve();b(n.children)&&(r=r.then(function(){return n.children(function(e){var t=Object.assign({},e);return delete t.next,t}(e))}).then(function(e){ie(e)||b(n.children)||(e=n.children),function(e,t){if(!Array.isArray(e)&&!w(e))throw new Error(h('Incorrect "children" value for the route '.concat(t.path,": expected array or object, but got ").concat(e)));t.__children=[];for(var n=s(e),r=0;r<n.length;r++)_(n[r]),t.__children.push(n[r])}(e,n)}));var o={redirect:function(t){return ue(e,t)},component:function(e){var n=document.createElement(e);return t.__createdByRouter.set(n,!0),n}};return r.then(function(){if(t.__isLatestRender(e))return le(n.action,[e,o],n)}).then(function(e){return ie(e)&&(e instanceof HTMLElement||e.redirect||e===C)?e:E(n.redirect)?o.redirect(n.redirect):n.bundle?(t=n.bundle,E(t)?g(t):Promise.race(p.filter(function(e){return e in t}).map(function(e){return g(t[e],e)}))).then(function(){},function(){throw new Error(h("Bundle not found: ".concat(n.bundle,". Check if the file name is correct")))}):void 0;var t}).then(function(e){return ie(e)?e:E(n.component)?o.component(n.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){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.__previousContext=void 0,this.__urlForName=void 0,u(a(r.prototype),"setRoutes",this).call(this,e),t||this.__onNavigationEvent(),this.ready}},{key:"render",value:function(e,t){var n=this,r=++this.__lastStartedRenderId,o=Object.assign({search:"",hash:""},E(e)?{pathname:e}:e,{__renderId:r});return this.ready=this.resolve(o).then(function(e){return n.__fullyResolveChain(e)}).then(function(e){if(n.__isLatestRender(e)){var o=n.__previousContext;if(e===o)return n.__updateBrowserHistory(o,!0),n.location;if(n.location=ce(e),t&&n.__updateBrowserHistory(e,1===r),y("location-changed",{router:n,location:n.location}),e.__skipAttach)return n.__copyUnchangedElements(e,o),n.__previousContext=e,n.location;n.__addAppearingContent(e,o);var a=n.__animateIfNeeded(e);return n.__runOnAfterEnterCallbacks(e),n.__runOnAfterLeaveCallbacks(e,o),a.then(function(){if(n.__isLatestRender(e))return n.__removeDisappearingContent(),n.__previousContext=e,n.location})}}).catch(function(e){if(r===n.__lastStartedRenderId)throw t&&n.__updateBrowserHistory(o),he(n.__outlet&&n.__outlet.children),n.location=ce(Object.assign(o,{resolver:n})),y("error",Object.assign({router:n,error:e},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.__findComponentContextAfterAllRedirects(n).then(function(r){var o=r!==n?r:e;return r.next().then(function(e){if((null===e||e===C)&&fe(de(r.chain),r.resolver)!==r.pathname)throw k(o);return e&&e!==C?t.__fullyResolveChain(o,e):t.__amendWithOnBeforeCallbacks(r)})})}},{key:"__findComponentContextAfterAllRedirects",value:function(e){var n=this,r=e.result;return r instanceof HTMLElement?(function(e,t){t.location=ce(e);var n=e.chain.map(function(e){return e.route}).indexOf(e.route);e.chain[n].element=t}(e,r),Promise.resolve(e)):r.redirect?this.__redirect(r.redirect,e.__redirectCount,e.__renderId).then(function(e){return n.__findComponentContextAfterAllRedirects(e)}):r instanceof Error?Promise.reject(r):Promise.reject(new Error(h('Invalid route resolution result for path "'.concat(e.pathname,'". ')+'Expected redirect object or HTML element, but got: "'.concat(function(e){if("object"!==t(e))return String(e);var n=Object.prototype.toString.call(e).match(/ (.*)\]$/)[1];return"Object"===n||"Array"===n?"".concat(n," ").concat(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||{},r=n.chain||[],o=e.chain,a=Promise.resolve(),i=function(){return{cancel:!0}},c=function(t){return ue(e,t)};if(e.__divergedChainIndex=0,e.__skipAttach=!1,r.length){for(var u=0;u<Math.min(r.length,o.length)&&(r[u].route===o[u].route&&(r[u].path===o[u].path||r[u].element===o[u].element)&&this.__isReusableElement(r[u].element,o[u].element));u=++e.__divergedChainIndex);if(e.__skipAttach=o.length===r.length&&e.__divergedChainIndex==o.length&&this.__isReusableElement(e.result,n.result),e.__skipAttach){for(var l=o.length-1;l>=0;l--)r[l].path===o[l].path&&e.search===n.search||(a=this.__runOnBeforeLeaveCallbacks(a,e,{prevent:i},r[l]));for(var s=0;s<o.length;s++)r[s].path===o[s].path&&e.search===n.search||(a=this.__runOnBeforeEnterCallbacks(a,e,{prevent:i,redirect:c},o[s])),r[s].element.location=ce(e,r[s].route)}else for(var h=r.length-1;h>=e.__divergedChainIndex;h--)a=this.__runOnBeforeLeaveCallbacks(a,e,{prevent:i},r[h])}for(var f=e.__divergedChainIndex;!e.__skipAttach&&f<o.length;f++)a=this.__runOnBeforeEnterCallbacks(a,e,{prevent:i,redirect:c},o[f]);return a.then(function(n){if(n){if(n.cancel)return t.__previousContext.__renderId=e.__renderId,t.__previousContext;if(n.redirect)return t.__redirect(n.redirect,e.__redirectCount,e.__renderId)}return e})}},{key:"__runOnBeforeLeaveCallbacks",value:function(e,t,n,r){var o=this,a=ce(t);return e.then(function(e){if(o.__isLatestRender(t))return se("onBeforeLeave",[a,n,o],r.element)(e)}).then(function(e){if(!(e||{}).redirect)return e})}},{key:"__runOnBeforeEnterCallbacks",value:function(e,t,n,r){var o=this,a=ce(t,r.route);return e.then(function(e){if(o.__isLatestRender(t))return se("onBeforeEnter",[a,n,o],r.element)(e)})}},{key:"__isReusableElement",value:function(e,t){return!(!e||!t)&&(this.__createdByRouter.get(e)&&this.__createdByRouter.get(t)?e.localName===t.localName:e===t)}},{key:"__isLatestRender",value:function(e){return e.__renderId===this.__lastStartedRenderId}},{key:"__redirect",value:function(e,t,n){if(t>256)throw new Error(h("Too many redirects when rendering ".concat(e.from)));return this.resolve({pathname:this.urlForPath(e.pathname,e.params),redirectFrom:e.from,__redirectCount:(t||0)+1,__renderId:n})}},{key:"__ensureOutlet",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.__outlet;if(!(e instanceof Node))throw new TypeError(h("Expected router outlet to be a valid DOM Node (but got ".concat(e,")")))}},{key:"__updateBrowserHistory",value:function(e,t){var n=e.pathname,r=e.search,o=void 0===r?"":r,a=e.hash,i=void 0===a?"":a;if(window.location.pathname!==n||window.location.search!==o||window.location.hash!==i){var c=t?"replaceState":"pushState";window.history[c](null,document.title,n+o+i),window.dispatchEvent(new PopStateEvent("popstate",{state:"vaadin-router-ignore"}))}}},{key:"__copyUnchangedElements",value:function(e,t){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}}return n}},{key:"__addAppearingContent",value:function(e,t){var n=this;this.__ensureOutlet(),this.__removeAppearingContent();var r=this.__copyUnchangedElements(e,t);this.__appearingContent=[],this.__disappearingContent=Array.from(r.children).filter(function(t){return n.__addedByRouter.get(t)&&t!==e.result});for(var o=r,a=e.__divergedChainIndex;a<e.chain.length;a++){var i=e.chain[a].element;i&&(o.appendChild(i),this.__addedByRouter.set(i,!0),o===r&&this.__appearingContent.push(i),o=i)}}},{key:"__removeDisappearingContent",value:function(){this.__disappearingContent&&he(this.__disappearingContent),this.__disappearingContent=null,this.__appearingContent=null}},{key:"__removeAppearingContent",value:function(){this.__disappearingContent&&this.__appearingContent&&(he(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&&this.__isLatestRender(e);n--){var r=t.chain[n].element;if(r)try{var o=ce(e);le(r.onAfterLeave,[o,{},t.resolver],r)}finally{this.__disappearingContent.indexOf(r)>-1&&he(r.children)}}}},{key:"__runOnAfterEnterCallbacks",value:function(e){for(var t=e.__divergedChainIndex;t<e.chain.length&&this.__isLatestRender(e);t++){var n=e.chain[t].element||{},r=ce(e,e.chain[t].route);le(n.onAfterEnter,[r,{},e.resolver],n)}}},{key:"__animateIfNeeded",value:function(e){for(var t,n=(this.__disappearingContent||[])[0],r=(this.__appearingContent||[])[0],o=[],a=e.chain,i=a.length;i>0;i--)if(a[i-1].route.animate){t=a[i-1].route.animate;break}if(n&&r&&t){var c=w(t)&&t.leave||"leaving",u=w(t)&&t.enter||"entering";o.push(ae(n,c)),o.push(ae(r,u))}return Promise.all(o).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:window.location,n=t.pathname,r=t.search,o=t.hash;E(this.__normalizePathname(n))&&(e&&e.preventDefault&&e.preventDefault(),this.render({pathname:n,search:r,hash:o},!0))}},{key:"urlForName",value:function(e,t){return this.__urlForName||(this.__urlForName=ee(this)),fe(this.__urlForName(e,t),this)}},{key:"urlForPath",value:function(e,t){return fe(r.pathToRegexp.compile(e)(t),this)}}],[{key:"setTriggers",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];ne(t)}},{key:"go",value:function(e){var t=E(e)?this.__createUrl(e,"http://a"):e;return y("go",{pathname:t.pathname,search:t.search,hash:t.hash})}}]),r}(),ve=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,_e=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function me(e,t){if("function"==typeof e){var n=ve.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 ge=function(e,t){if(window.Vaadin.developmentMode)return me(e,t)};function ye(){}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&&(_e?!function(){if(_e){var e=Object.keys(_e).map(function(e){return _e[e]}).filter(function(e){return e.productionMode});if(e.length>0)return!0}return!1}():!me(function(){return!0}))}catch(e){return!1}}());var we,be,Ee,ke;window.Vaadin=window.Vaadin||{},window.Vaadin.registrations=window.Vaadin.registrations||[],window.Vaadin.registrations.push({is:"@vaadin/router",version:"1.5.1"}),ge(ye),pe.NavigationTrigger={POPSTATE:A,CLICK:O},J.__ensureUrlAvailableOrPolyfilled=function(){if(void 0===we){try{var e=new URL("b","http://a");e.pathname="c",we="http://a/c"===e.href}catch(e){we=!1}if(!we&&(be=document.implementation.createHTMLDocument("url"),Ee=be.createElement("base"),be.head.appendChild(Ee),!(ke=be.createElement("a")).origin)){Object.defineProperty(ke,"origin",{get:function(){var e=ke.protocol,t=ke.port,n="http:"===e&&"80"===t||"https:"===e&&"443"===t?ke.hostname:ke.host;return"".concat(e,"//").concat(n)}});var t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(ke),"pathname").get;Object.defineProperty(ke,"pathname",{get:function(){var e=t.apply(ke);return"/"!==e.charAt(0)?"/"+e:e}})}}},J.__createUrl=function(e,t){return J.__ensureUrlAvailableOrPolyfilled(),we?new URL(e,t):(Ee.href=t,ke.href=e.replace(/ /g,"%20"),ke.href=ke.href,ke)},e.Resolver=J,e.Router=pe,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=vaadin-router.umd.min.js.map |
{ | ||
"name": "@vaadin/router", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Small and powerful client-side router for Web Components. Framework-agnostic.", | ||
@@ -5,0 +5,0 @@ "main": "dist/vaadin-router.js", |
@@ -8,5 +8,5 @@ import {usageStatistics} from '@vaadin/vaadin-usage-statistics/vaadin-usage-statistics.js'; | ||
is: '@vaadin/router', | ||
version: '1.5.0', | ||
version: '1.5.1', | ||
}); | ||
usageStatistics(); |
@@ -480,8 +480,11 @@ import Resolver from './resolver/resolver.js'; | ||
this.location = createLocation(context); | ||
fireRouterEvent('location-changed', {router: this, location: this.location}); | ||
if (shouldUpdateHistory) { | ||
this.__updateBrowserHistory(context, context.redirectFrom); | ||
// Replace only if first render redirects, so that we don’t leave | ||
// the redirecting record in the history | ||
this.__updateBrowserHistory(context, renderId === 1); | ||
} | ||
fireRouterEvent('location-changed', {router: this, location: this.location}); | ||
// Skip detaching/re-attaching there are no render changes | ||
@@ -488,0 +491,0 @@ if (context.__skipAttach) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
849964
8036