/*! * (C) Ionic http://ionicframework.com - MIT License */ import{r as t,d as o,f as n,h as e,H as i}from"./p-f419feca.js";import{c as r,q as s}from"./p-1b3ffb2f.js";import{o as a,c}from"./p-47794def.js";import{b as h}from"./p-2389b3f9.js";const u=class{constructor(n){t(this,n),this.ionRouteDataChanged=o(this,"ionRouteDataChanged",7),this.url="",this.component=void 0,this.componentProps=void 0,this.beforeLeave=void 0,this.beforeEnter=void 0}onUpdate(t){this.ionRouteDataChanged.emit(t)}onComponentProps(t,o){if(t===o)return;const n=t?Object.keys(t):[],e=o?Object.keys(o):[];if(n.length===e.length){for(const e of n)if(t[e]!==o[e])return void this.onUpdate(t)}else this.onUpdate(t)}connectedCallback(){this.ionRouteDataChanged.emit()}static get watchers(){return{url:["onUpdate"],component:["onUpdate"],componentProps:["onComponentProps"]}}},l=class{constructor(n){t(this,n),this.ionRouteRedirectChanged=o(this,"ionRouteRedirectChanged",7),this.from=void 0,this.to=void 0}propDidChange(){this.ionRouteRedirectChanged.emit()}connectedCallback(){this.ionRouteRedirectChanged.emit()}static get watchers(){return{from:["propDidChange"],to:["propDidChange"]}}},f="root",d="forward",w=t=>"/"+t.filter((t=>t.length>0)).join("/"),p=t=>{let o,n=[""];if(null!=t){const e=t.indexOf("?");e>-1&&(o=t.substring(e+1),t=t.substring(0,e)),n=t.split("/").map((t=>t.trim())).filter((t=>t.length>0)),0===n.length&&(n=[""])}return{segments:n,queryString:o}},m=async(t,o,n,e,i=!1,s)=>{try{const a=v(t);if(e>=o.length||!a)return i;await new Promise((t=>r(a,t)));const c=o[e],h=await a.setRouteId(c.id,c.params,n,s);return h.changed&&(n=f,i=!0),i=await m(h.element,o,n,e+1,i,s),h.markVisible&&await h.markVisible(),i}catch(t){return console.error(t),!1}},b=":not([no-router]) ion-nav, :not([no-router]) ion-tabs, :not([no-router]) ion-router-outlet",v=t=>{if(!t)return;if(t.matches(b))return t;const o=t.querySelector(b);return null!=o?o:void 0},g=(t,o)=>o.find((o=>((t,o)=>{const{from:n,to:e}=o;if(void 0===e)return!1;if(n.length>t.length)return!1;for(let o=0;o{const n=Math.min(t.length,o.length);let e=0;for(let i=0;i`:${t}`));for(let t=0;t{const n=new O(t);let e,i=!1;for(let t=0;t({id:t.id,segments:t.segments,params:C(t.params,e[o]),beforeEnter:t.beforeEnter,beforeLeave:t.beforeLeave}))):o},C=(t,o)=>t||o?Object.assign(Object.assign({},t),o):void 0,k=(t,o)=>{let n=null,e=0;for(const i of o){const o=R(t,i);if(null!==o){const t=j(o);t>e&&(e=t,n=o)}}return n},j=t=>{let o=1,n=1;for(const e of t)for(const t of e.segments)":"===t[0]?o+=Math.pow(1,n):""!==t&&(o+=Math.pow(2,n)),n++;return o};class O{constructor(t){this.segments=t.slice()}next(){return this.segments.length>0?this.segments.shift():""}}const D=(t,o)=>o in t?t[o]:t.hasAttribute(o)?t.getAttribute(o):null,E=t=>Array.from(t.children).filter((t=>"ION-ROUTE-REDIRECT"===t.tagName)).map((t=>{const o=D(t,"to");return{from:p(D(t,"from")).segments,to:null==o?void 0:p(o)}})),S=t=>L($(t)),$=t=>Array.from(t.children).filter((t=>"ION-ROUTE"===t.tagName&&t.component)).map((t=>{const o=D(t,"component");return{segments:p(D(t,"url")).segments,id:o.toLowerCase(),params:t.componentProps,beforeLeave:t.beforeLeave,beforeEnter:t.beforeEnter,children:$(t)}})),L=t=>{const o=[];for(const n of t)P([],o,n);return o},P=(t,o,n)=>{if(t=[...t,{id:n.id,segments:n.segments,params:n.params,beforeLeave:n.beforeLeave,beforeEnter:n.beforeEnter}],0!==n.children.length)for(const e of n.children)P(t,o,e);else o.push(t)},U=class{constructor(n){t(this,n),this.ionRouteWillChange=o(this,"ionRouteWillChange",7),this.ionRouteDidChange=o(this,"ionRouteDidChange",7),this.previousPath=null,this.busy=!1,this.state=0,this.lastState=0,this.root="/",this.useHash=!0}async componentWillLoad(){await(v(document.body)?Promise.resolve():new Promise((t=>{window.addEventListener("ionNavWillLoad",(()=>t()),{once:!0})})));const t=await this.runGuards(this.getSegments());if(!0!==t){if("object"==typeof t){const{redirect:o}=t,n=p(o);this.setSegments(n.segments,f,n.queryString),await this.writeNavStateRoot(n.segments,f)}}else await this.onRoutesChanged()}componentDidLoad(){window.addEventListener("ionRouteRedirectChanged",s(this.onRedirectChanged.bind(this),10)),window.addEventListener("ionRouteDataChanged",s(this.onRoutesChanged.bind(this),100))}async onPopState(){const t=this.historyDirection();let o=this.getSegments();const n=await this.runGuards(o);if(!0!==n){if("object"!=typeof n)return!1;o=p(n.redirect).segments}return this.writeNavStateRoot(o,t)}onBackButton(t){t.detail.register(0,(t=>{this.back(),t()}))}async canTransition(){const t=await this.runGuards();return!0===t||"object"==typeof t&&t.redirect}async push(t,o="forward",n){var e;if(t.startsWith(".")){const o=null!==(e=this.previousPath)&&void 0!==e?e:"/",n=new URL(t,`https://host/${o}`);t=n.pathname+n.search}let i=p(t);const r=await this.runGuards(i.segments);if(!0!==r){if("object"!=typeof r)return!1;i=p(r.redirect)}return this.setSegments(i.segments,o,i.queryString),this.writeNavStateRoot(i.segments,o,n)}back(){return window.history.back(),Promise.resolve(this.waitPromise)}async printDebug(){(t=>{console.group(`[ion-core] ROUTES[${t.length}]`);for(const o of t){const t=[];o.forEach((o=>t.push(...o.segments)));const n=o.map((t=>t.id));console.debug(`%c ${w(t)}`,"font-weight: bold; padding-left: 20px","=>\t",`(${n.join(", ")})`)}console.groupEnd()})(S(this.el)),(t=>{console.group(`[ion-core] REDIRECTS[${t.length}]`);for(const o of t)o.to&&console.debug("FROM: ",`$c ${w(o.from)}`,"font-weight: bold"," TO: ",`$c ${w(o.to.segments)}`,"font-weight: bold");console.groupEnd()})(E(this.el))}async navChanged(t){if(this.busy)return console.warn("[ion-router] router is busy, navChanged was cancelled"),!1;const{ids:o,outlet:n}=await(async()=>{const t=[];let o,n=window.document.body;for(;o=v(n);){const e=await o.getRouteId();if(!e)break;n=e.element,e.element=void 0,t.push(e)}return{ids:t,outlet:o}})(),e=((t,o)=>{let n=null,e=0;for(const i of o){const o=y(t,i);o>e&&(n=i,e=o)}return n?n.map(((o,n)=>{var e;return{id:o.id,segments:o.segments,params:C(o.params,null===(e=t[n])||void 0===e?void 0:e.params)}})):null})(o,S(this.el));if(!e)return console.warn("[ion-router] no matching URL for ",o.map((t=>t.id))),!1;const i=(t=>{const o=[];for(const n of t)for(const t of n.segments)if(":"===t[0]){const e=n.params&&n.params[t.slice(1)];if(!e)return null;o.push(e)}else""!==t&&o.push(t);return o})(e);return i?(this.setSegments(i,t),await this.safeWriteNavState(n,e,f,i,null,o.length),!0):(console.warn("[ion-router] router could not match path because some required param is missing"),!1)}onRedirectChanged(){const t=this.getSegments();t&&g(t,E(this.el))&&this.writeNavStateRoot(t,f)}onRoutesChanged(){return this.writeNavStateRoot(this.getSegments(),f)}historyDirection(){var t;const o=window;null===o.history.state&&(this.state++,o.history.replaceState(this.state,o.document.title,null===(t=o.document.location)||void 0===t?void 0:t.href));const n=o.history.state,e=this.lastState;return this.lastState=n,n>e||n>=e&&e>0?d:no=t)),void 0!==t&&await t,o}async runGuards(t=this.getSegments(),o){if(void 0===o&&(o=p(this.previousPath).segments),!t||!o)return!0;const n=S(this.el),e=k(o,n),i=e&&e[e.length-1].beforeLeave,r=!i||await i();if(!1===r||"object"==typeof r)return r;const s=k(t,n),a=s&&s[s.length-1].beforeEnter;return!a||a()}async writeNavState(t,o,n,e,i,r=0,s){if(this.busy)return console.warn("[ion-router] router is busy, transition was cancelled"),!1;this.busy=!0;const a=this.routeChangeEvent(e,i);a&&this.ionRouteWillChange.emit(a);const c=await m(t,o,n,r,!1,s);return this.busy=!1,a&&this.ionRouteDidChange.emit(a),c}setSegments(t,o,n){this.state++,((t,o,n,e,i,r,s)=>{const a=((t,o,n)=>{let e=w(t);return o&&(e="#"+e),void 0!==n&&(e+="?"+n),e})([...p(o).segments,...e],n,s);i===d?t.pushState(r,"",a):t.replaceState(r,"",a)})(window.history,this.root,this.useHash,t,o,this.state,n)}getSegments(){return((t,o,n)=>{const e=p(this.root).segments,i=n?t.hash.slice(1):t.pathname;return((t,o)=>{if(t.length>o.length)return null;if(t.length<=1&&""===t[0])return o;for(let n=0;n{a(this.href,t,this.routerDirection,this.routerAnimation)},this.color=void 0,this.href=void 0,this.rel=void 0,this.routerDirection="forward",this.routerAnimation=void 0,this.target=void 0}render(){const t=h(this),o={href:this.href,rel:this.rel,target:this.target};return e(i,{key:"ca8b357234ae511a20f6a47487bb86cbaaa5f5ef",onClick:this.onClick,class:c(this.color,{[t]:!0,"ion-activatable":!0})},e("a",Object.assign({key:"f590738389776d480014f18f599d753c68840e49"},o),e("slot",{key:"525ff073d71ede310e9f790b49f7414bf5a0919b"})))}};x.style=":host{--background:transparent;--color:var(--ion-color-primary, #3880ff);background:var(--background);color:var(--color)}:host(.ion-color){color:var(--ion-color-base)}a{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit}";export{u as ion_route,l as ion_route_redirect,U as ion_router,x as ion_router_link}