p-c2160d8c.entry.js 11 KB

1234
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import{r as t,c as o,f as n,h as e,e as i}from"./p-66a5d6a8.js";import{c as r,p as s}from"./p-94551927.js";import{d as a,p as c}from"./p-17e21141.js";import{o as h,c as u}from"./p-47794def.js";import{b as l}from"./p-dabe3bd4.js";const f=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"]}}},d=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"]}}},p="root",w="forward",m=t=>"/"+t.filter((t=>t.length>0)).join("/"),b=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}},v=async(t,o,n,e,i=!1,s)=>{try{const a=y(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=p,i=!0),i=await v(h.element,o,n,e+1,i,s),h.markVisible&&await h.markVisible(),i}catch(t){return a("[ion-router] - Exception in writeNavState:",t),!1}},g=":not([no-router]) ion-nav, :not([no-router]) ion-tabs, :not([no-router]) ion-router-outlet",y=t=>{if(!t)return;if(t.matches(g))return t;const o=t.querySelector(g);return null!=o?o:void 0},R=(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<n.length;o++){const e=n[o];if("*"===e)return!0;if(e!==t[o])return!1}return n.length===t.length})(t,o))),C=(t,o)=>{const n=Math.min(t.length,o.length);let e=0;for(let i=0;i<n;i++){const n=t[i],r=o[i];if(n.id.toLowerCase()!==r.id)break;if(n.params){const t=Object.keys(n.params);if(t.length===r.segments.length){const o=t.map((t=>`:${t}`));for(let t=0;t<o.length&&o[t].toLowerCase()===r.segments[t];t++)e++}}e++}return e},j=(t,o)=>{const n=new S(t);let e,i=!1;for(let t=0;t<o.length;t++){const r=o[t].segments;if(""===r[0])i=!0;else{for(const o of r){const i=n.next();if(":"===o[0]){if(""===i)return null;e=e||[],(e[t]||(e[t]={}))[o.slice(1)]=i}else if(i!==o)return null}i=!1}}return i&&i!==(""===n.next())?null:e?o.map(((t,o)=>({id:t.id,segments:t.segments,params:k(t.params,e[o]),beforeEnter:t.beforeEnter,beforeLeave:t.beforeLeave}))):o},k=(t,o)=>t||o?Object.assign(Object.assign({},t),o):void 0,E=(t,o)=>{let n=null,e=0;for(const i of o){const o=j(t,i);if(null!==o){const t=O(o);t>e&&(e=t,n=o)}}return n},O=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 S{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,x=t=>Array.from(t.children).filter((t=>"ION-ROUTE-REDIRECT"===t.tagName)).map((t=>{const o=D(t,"to");return{from:b(D(t,"from")).segments,to:null==o?void 0:b(o)}})),$=t=>N(L(t)),L=t=>Array.from(t.children).filter((t=>"ION-ROUTE"===t.tagName&&t.component)).map((t=>{const o=D(t,"component");return{segments:b(D(t,"url")).segments,id:o.toLowerCase(),params:t.componentProps,beforeLeave:t.beforeLeave,beforeEnter:t.beforeEnter,children:L(t)}})),N=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(y(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=b(o);this.setSegments(n.segments,p,n.queryString),await this.writeNavStateRoot(n.segments,p)}}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=b(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=b(t);const r=await this.runGuards(i.segments);if(!0!==r){if("object"!=typeof r)return!1;i=b(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 ${m(t)}`,"font-weight: bold; padding-left: 20px","=>\t",`(${n.join(", ")})`)}console.groupEnd()})($(this.el)),(t=>{console.group(`[ion-core] REDIRECTS[${t.length}]`);for(const o of t)o.to&&console.debug("FROM: ",`$c ${m(o.from)}`,"font-weight: bold"," TO: ",`$c ${m(o.to.segments)}`,"font-weight: bold");console.groupEnd()})(x(this.el))}async navChanged(t){if(this.busy)return c("[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=y(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=C(t,i);o>e&&(n=i,e=o)}return n?n.map(((o,n)=>{var e;return{id:o.id,segments:o.segments,params:k(o.params,null===(e=t[n])||void 0===e?void 0:e.params)}})):null})(o,$(this.el));if(!e)return c("[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,p,i,null,o.length),!0):(c("[ion-router] - Router could not match path because some required param is missing."),!1)}onRedirectChanged(){const t=this.getSegments();t&&R(t,x(this.el))&&this.writeNavStateRoot(t,p)}onRoutesChanged(){return this.writeNavStateRoot(this.getSegments(),p)}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?w:n<e?"back":p}async writeNavStateRoot(t,o,n){if(!t)return a("[ion-router] - URL is not part of the routing set."),!1;const e=x(this.el),i=R(t,e);let r=null;if(i){const{segments:n,queryString:e}=i.to;this.setSegments(n,o,e),r=i.from,t=n}const s=$(this.el),c=E(t,s);return c?this.safeWriteNavState(document.body,c,o,t,r,0,n):(a("[ion-router] - The path does not match any route."),!1)}async safeWriteNavState(t,o,n,e,i,r=0,s){const c=await this.lock();let h=!1;try{h=await this.writeNavState(t,o,n,e,i,r,s)}catch(t){a("[ion-router] - Exception in safeWriteNavState:",t)}return c(),h}async lock(){const t=this.waitPromise;let o;return this.waitPromise=new Promise((t=>o=t)),void 0!==t&&await t,o}async runGuards(t=this.getSegments(),o){if(void 0===o&&(o=b(this.previousPath).segments),!t||!o)return!0;const n=$(this.el),e=E(o,n),i=e&&e[e.length-1].beforeLeave,r=!i||await i();if(!1===r||"object"==typeof r)return r;const s=E(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 c("[ion-router] - Router is busy, transition was cancelled."),!1;this.busy=!0;const a=this.routeChangeEvent(e,i);a&&this.ionRouteWillChange.emit(a);const h=await v(t,o,n,r,!1,s);return this.busy=!1,a&&this.ionRouteDidChange.emit(a),h}setSegments(t,o,n){this.state++,((t,o,n,e,i,r,s)=>{const a=((t,o,n)=>{let e=m(t);return o&&(e="#"+e),void 0!==n&&(e+="?"+n),e})([...b(o).segments,...e],n,s);i===w?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=b(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<t.length;n++)if(t[n]!==o[n])return null;return o.length===t.length?[""]:o.slice(t.length)})(e,b(i).segments)})(window.location,0,this.useHash)}routeChangeEvent(t,o){const n=this.previousPath,e=m(t);return this.previousPath=e,e===n?null:{from:n,redirectedFrom:o?m(o):null,to:e}}get el(){return n(this)}},T=class{constructor(o){t(this,o),this.onClick=t=>{h(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=l(this),o={href:this.href,rel:this.rel,target:this.target};return e(i,{key:"11183264fb6ae0db9a7a47c71b6862d60001b834",onClick:this.onClick,class:u(this.color,{[t]:!0,"ion-activatable":!0})},e("a",Object.assign({key:"3e0e5242161cb0df593d6d573e51b8ba750065a1"},o),e("slot",{key:"5bd808e98a4627bb1236f0d955f4b32971355417"})))}};T.style=":host{--background:transparent;--color:var(--ion-color-primary, #0054e9);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{f as ion_route,d as ion_route_redirect,U as ion_router,T as ion_router_link}