UNPKG

1.59 kBJavaScriptView Raw
1import{r as t,c as e,h as s,g as r}from"./p-c69e1c21.js";import{A as i}from"./p-cab953ae.js";import{m as o}from"./p-8fc41abb.js";import"./p-d2e78d53.js";const c=()=>((1e17*Math.random()).toString().match(/.{4}/g)||[]).join("-"),l=(t,e,s)=>o(t,{path:e,exact:s,strict:!0}),a=t=>"STENCIL-ROUTE"===t.tagName;class n{constructor(s){t(this,s),this.group=c(),this.subscribers=[],this.queue=e(this,"queue")}componentWillLoad(){null!=this.location&&this.regenerateSubscribers(this.location)}async regenerateSubscribers(t){if(null==t)return;let e=-1;if(this.subscribers=Array.prototype.slice.call(this.el.children).filter(a).map((s,r)=>{const i=l(t.pathname,s.url,s.exact);return i&&-1===e&&(e=r),{el:s,match:i}}),-1===e)return;if(this.activeIndex===e)return void(this.subscribers[e].el.match=this.subscribers[e].match);this.activeIndex=e;const s=this.subscribers[this.activeIndex];this.scrollTopOffset&&(s.el.scrollTopOffset=this.scrollTopOffset),s.el.group=this.group,s.el.match=s.match,s.el.componentUpdated=t=>{this.queue.write(()=>{this.subscribers.forEach((t,e)=>{if(t.el.componentUpdated=void 0,e===this.activeIndex)return t.el.style.display="";this.scrollTopOffset&&(t.el.scrollTopOffset=this.scrollTopOffset),t.el.group=this.group,t.el.match=null,t.el.style.display="none"})}),this.routeViewsUpdated&&this.routeViewsUpdated(Object.assign({scrollTopOffset:this.scrollTopOffset},t))}}render(){return s("slot",null)}get el(){return r(this)}static get watchers(){return{location:["regenerateSubscribers"]}}}i.injectProps(n,["location","routeViewsUpdated"]);export{n as stencil_route_switch};
\No newline at end of file