import{r as t,g as r,h as e,a as i}from"./p-47897087.js";import{e as s,a as n}from"./p-e070304f.js";const a=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g"),o=t=>t.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1"),l=t=>t.replace(/([=!:$/()])/g,"\\$1"),h=t=>t&&t.sensitive?"":"i",u=(t,r,e)=>{for(var i=(e=e||{}).strict,s=!1!==e.end,n=o(e.delimiter||"/"),a=e.delimiters||"./",l=[].concat(e.endsWith||[]).map(o).concat("$").join("|"),u="",c=!1,p=0;p<t.length;p++){var f=t[p];if("string"==typeof f)u+=o(f),c=p===t.length-1&&a.indexOf(f[f.length-1])>-1;else{var g=o(f.prefix||""),m=f.repeat?"(?:"+f.pattern+")(?:"+g+"(?:"+f.pattern+"))*":f.pattern;r&&r.push(f),u+=f.optional?f.partial?g+"("+m+")?":"(?:"+g+"("+m+"))?":g+"("+m+")"}}return s?(i||(u+="(?:"+n+")?"),u+="$"===l?"$":"(?="+l+")"):(i||(u+="(?:"+n+"(?="+l+"))?"),c||(u+="(?="+n+"|"+l+")")),new RegExp("^"+u,h(e))},c=(t,r,e)=>t instanceof RegExp?((t,r)=>{if(!r)return t;var e=t.source.match(/\((?!\?)/g);if(e)for(var i=0;i<e.length;i++)r.push({name:i,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return t})(t,r):Array.isArray(t)?((t,r,e)=>{for(var i=[],s=0;s<t.length;s++)i.push(c(t[s],r,e).source);return new RegExp("(?:"+i.join("|")+")",h(e))})(t,r,e):((t,r,e)=>u(((t,r)=>{for(var e,i=[],s=0,n=0,h="",u=r&&r.delimiter||"/",c=r&&r.delimiters||"./",p=!1;null!==(e=a.exec(t));){var f=e[0],g=e[1],m=e.index;if(h+=t.slice(n,m),n=m+f.length,g)h+=g[1],p=!0;else{var v="",d=t[n],x=e[2],w=e[3],y=e[4],$=e[5];if(!p&&h.length){var b=h.length-1;c.indexOf(h[b])>-1&&(v=h[b],h=h.slice(0,b))}h&&(i.push(h),h="",p=!1);var E=v||u,R=w||y;i.push({name:x||s++,prefix:v,delimiter:E,optional:"?"===$||"*"===$,repeat:"+"===$||"*"===$,partial:""!==v&&void 0!==d&&d!==v,pattern:R?l(R):"[^"+o(E)+"]+?"})}}return(h||n<t.length)&&i.push(h+t.substr(n)),i})(t,e),r,e))(t,r,e);let p=0;const f={},g=t=>"STENCIL-ROUTE"===t.tagName,m=class{constructor(e){t(this,e),this.group=((1e17*Math.random()).toString().match(/.{4}/g)||[]).join("-"),this.subscribers=[],this.queue=r(this,"queue")}componentWillLoad(){null!=this.location?this.regenerateSubscribers(this.location):console.warn('<animated-route-switch> requires the "location" prop in order to be wired to Stencil Router.')}async regenerateSubscribers(t){if(console.log(t),null==t)return;let r=-1;if(this.subscribers=Array.prototype.slice.call(this.el.children).filter(g).map(((e,i)=>{const s=((t,r={})=>{"string"==typeof r&&(r={path:r});const{path:e="/",exact:i=!1,strict:s=!1}=r,{re:n,keys:a}=((t,r)=>{const e=`${r.end}${r.strict}`,i=f[e]||(f[e]={}),s=JSON.stringify(t);if(i[s])return i[s];const n=[],a={re:c(t,n,r),keys:n};return p<1e4&&(i[s]=a,p+=1),a})(e,{end:i,strict:s}),o=n.exec(t);if(!o)return null;const[l,...h]=o,u=t===l;return i&&!u?null:{path:e,url:"/"===e&&""===l?"/":l,isExact:u,params:a.reduce(((t,r,e)=>(t[r.name]=h[e],t)),{})}})(t.pathname,{path:e.url,exact:e.exact,strict:!0});return s&&-1===r&&(r=i),{el:e,match:s}})),-1===r)return;if(this.activeIndex===r)return void(this.subscribers[r].el.match=this.subscribers[r].match);this.prevIndex=this.activeIndex,this.activeIndex=r;const e=this.subscribers[this.prevIndex];e&&await s(e.el);const i=this.subscribers[this.activeIndex];"number"==typeof this.scrollTopOffset&&(i.el.scrollTopOffset=this.scrollTopOffset),i.el.group=this.group,i.el.match=i.match,i.el.componentUpdated=t=>{this.queue.write((()=>{this.subscribers.forEach(((t,r)=>{if(t.el.componentUpdated=void 0,r===this.activeIndex)return t.el.style.display="",n(t.el);"number"==typeof 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 e("slot",null)}get el(){return i(this)}static get watchers(){return{location:["regenerateSubscribers"]}}};export{m as animated_route_switch}