UNPKG

@zoff-tech/zt-bottom-drawer

Version:
14 lines 35.8 kB
import{r as t,d as e,h as i,e as n,H as s}from"./p-f6c816ce.js";import{getTimeGivenProgression as r}from"@utils/animation/cubic-bezier";import{assert as o,shallowEqualStringMap as a}from"@utils/helpers";import"@utils/logging";import{lifecycle as h,transition as f,setPageHidden as l}from"@utils/transition";import{g as u,c}from"./p-0b9b2444.js";import{attachComponent as d}from"@utils/framework-delegate";import{w as m}from"./p-c8e8aee0.js";import{r as w}from"./p-a75a9102.js";import{createGesture as v}from"./p-0c0b0519.js"; /*! * (C) Ionic http://ionicframework.com - MIT License */const p="ionViewWillLeave";const y="ionViewDidLeave";const g="ionViewWillUnload"; /*! * (C) Ionic http://ionicframework.com - MIT License */const b=1;const C=2;const T=3;class E{constructor(t,e){this.component=t;this.params=e;this.state=b}async init(t){this.state=C;if(!this.element){const e=this.component;this.element=await d(this.delegate,t,e,["ion-page","ion-page-invisible"],this.params)}}_destroy(){o(this.state!==T,"view state must be ATTACHED");const t=this.element;if(t){if(this.delegate){this.delegate.removeViewFromDom(t.parentElement,t)}else{t.remove()}}this.nav=undefined;this.state=T}}const N=(t,e,i)=>{if(!t){return false}if(t.component!==e){return false}return a(t.params,i)};const P=(t,e)=>{if(!t){return null}if(t instanceof E){return t}return new E(t,e)};const k=t=>t.map((t=>{if(t instanceof E){return t}if("component"in t){return P(t.component,t.componentProps===null?undefined:t.componentProps)}return P(t,undefined)})).filter((t=>t!==null));const A=":host{left:0;right:0;top:0;bottom:0;position:absolute;contain:layout size style;overflow:hidden;z-index:0}";const S=class{constructor(i){t(this,i);this.ionNavWillLoad=e(this,"ionNavWillLoad",7);this.ionNavWillChange=e(this,"ionNavWillChange",3);this.ionNavDidChange=e(this,"ionNavDidChange",3);this.transInstr=[];this.animationEnabled=true;this.useRouter=false;this.isTransitioning=false;this.destroyed=false;this.views=[];this.didLoad=false;this.delegate=undefined;this.swipeGesture=undefined;this.animated=true;this.animation=undefined;this.rootParams=undefined;this.root=undefined}swipeGestureChanged(){if(this.gesture){this.gesture.enable(this.swipeGesture===true)}}rootChanged(){if(this.root===undefined){return}if(this.didLoad===false){return}if(!this.useRouter){if(this.root!==undefined){this.setRoot(this.root,this.rootParams)}}}componentWillLoad(){this.useRouter=document.querySelector("ion-router")!==null&&this.el.closest("[no-router]")===null;if(this.swipeGesture===undefined){const t=u(this);this.swipeGesture=c.getBoolean("swipeBackEnabled",t==="ios")}this.ionNavWillLoad.emit()}async componentDidLoad(){this.didLoad=true;this.rootChanged();this.gesture=(await import("./p-83368520.js")).createSwipeBackGesture(this.el,this.canStart.bind(this),this.onStart.bind(this),this.onMove.bind(this),this.onEnd.bind(this));this.swipeGestureChanged()}connectedCallback(){this.destroyed=false}disconnectedCallback(){for(const t of this.views){h(t.element,g);t._destroy()}if(this.gesture){this.gesture.destroy();this.gesture=undefined}this.transInstr.length=0;this.views.length=0;this.destroyed=true}push(t,e,i,n){return this.insert(-1,t,e,i,n)}insert(t,e,i,n,s){return this.insertPages(t,[{component:e,componentProps:i}],n,s)}insertPages(t,e,i,n){return this.queueTrns({insertStart:t,insertViews:e,opts:i},n)}pop(t,e){return this.removeIndex(-1,1,t,e)}popTo(t,e,i){const n={removeStart:-1,removeCount:-1,opts:e};if(typeof t==="object"&&t.component){n.removeView=t;n.removeStart=1}else if(typeof t==="number"){n.removeStart=t+1}return this.queueTrns(n,i)}popToRoot(t,e){return this.removeIndex(1,-1,t,e)}removeIndex(t,e=1,i,n){return this.queueTrns({removeStart:t,removeCount:e,opts:i},n)}setRoot(t,e,i,n){return this.setPages([{component:t,componentProps:e}],i,n)}setPages(t,e,i){e!==null&&e!==void 0?e:e={};if(e.animated!==true){e.animated=false}return this.queueTrns({insertStart:0,insertViews:t,removeStart:0,removeCount:-1,opts:e},i)}setRouteId(t,e,i,n){const s=this.getActiveSync();if(N(s,t,e)){return Promise.resolve({changed:false,element:s.element})}let r;const o=new Promise((t=>r=t));let a;const h={updateURL:false,viewIsReady:t=>{let e;const i=new Promise((t=>e=t));r({changed:true,element:t,markVisible:async()=>{e();await a}});return i}};if(i==="root"){a=this.setRoot(t,e,h)}else{const s=this.views.find((i=>N(i,t,e)));if(s){a=this.popTo(s,Object.assign(Object.assign({},h),{direction:"back",animationBuilder:n}))}else if(i==="forward"){a=this.push(t,e,Object.assign(Object.assign({},h),{animationBuilder:n}))}else if(i==="back"){a=this.setRoot(t,e,Object.assign(Object.assign({},h),{direction:"back",animated:true,animationBuilder:n}))}}return o}async getRouteId(){const t=this.getActiveSync();if(t){return{id:t.element.tagName,params:t.params,element:t.element}}return undefined}async getActive(){return this.getActiveSync()}async getByIndex(t){return this.views[t]}async canGoBack(t){return this.canGoBackSync(t)}async getPrevious(t){return this.getPreviousSync(t)}getLength(){return this.views.length}getActiveSync(){return this.views[this.views.length-1]}canGoBackSync(t=this.getActiveSync()){return!!(t&&this.getPreviousSync(t))}getPreviousSync(t=this.getActiveSync()){if(!t){return undefined}const e=this.views;const i=e.indexOf(t);return i>0?e[i-1]:undefined}async queueTrns(t,e){var i,n;if(this.isTransitioning&&((i=t.opts)===null||i===void 0?void 0:i.skipIfBusy)){return false}const s=new Promise(((e,i)=>{t.resolve=e;t.reject=i}));t.done=e;if(t.opts&&t.opts.updateURL!==false&&this.useRouter){const e=document.querySelector("ion-router");if(e){const i=await e.canTransition();if(i===false){return false}if(typeof i==="string"){e.push(i,t.opts.direction||"back");return false}}}if(((n=t.insertViews)===null||n===void 0?void 0:n.length)===0){t.insertViews=undefined}this.transInstr.push(t);this.nextTrns();return s}success(t,e){if(this.destroyed){this.fireError("nav controller was destroyed",e);return}if(e.done){e.done(t.hasCompleted,t.requiresTransition,t.enteringView,t.leavingView,t.direction)}e.resolve(t.hasCompleted);if(e.opts.updateURL!==false&&this.useRouter){const e=document.querySelector("ion-router");if(e){const i=t.direction==="back"?"back":"forward";e.navChanged(i)}}}failed(t,e){if(this.destroyed){this.fireError("nav controller was destroyed",e);return}this.transInstr.length=0;this.fireError(t,e)}fireError(t,e){if(e.done){e.done(false,false,t)}if(e.reject&&!this.destroyed){e.reject(t)}else{e.resolve(false)}}nextTrns(){if(this.isTransitioning){return false}const t=this.transInstr.shift();if(!t){return false}this.runTransition(t);return true}async runTransition(t){try{this.ionNavWillChange.emit();this.isTransitioning=true;this.prepareTI(t);const e=this.getActiveSync();const i=this.getEnteringView(t,e);if(!e&&!i){throw new Error("no views in the stack to be removed")}if(i&&i.state===b){await i.init(this.el)}this.postViewInit(i,e,t);const n=(t.enteringRequiresTransition||t.leavingRequiresTransition)&&i!==e;if(n&&t.opts&&e){const n=t.opts.direction==="back";if(n){t.opts.animationBuilder=t.opts.animationBuilder||(i===null||i===void 0?void 0:i.animationBuilder)}e.animationBuilder=t.opts.animationBuilder}let s;if(n){s=await this.transition(i,e,t)}else{s={hasCompleted:true,requiresTransition:false}}this.success(s,t);this.ionNavDidChange.emit()}catch(e){this.failed(e,t)}this.isTransitioning=false;this.nextTrns()}prepareTI(t){var e,i;var n;const s=this.views.length;(e=t.opts)!==null&&e!==void 0?e:t.opts={};(i=(n=t.opts).delegate)!==null&&i!==void 0?i:n.delegate=this.delegate;if(t.removeView!==undefined){o(t.removeStart!==undefined,"removeView needs removeStart");o(t.removeCount!==undefined,"removeView needs removeCount");const e=this.views.indexOf(t.removeView);if(e<0){throw new Error("removeView was not found")}t.removeStart+=e}if(t.removeStart!==undefined){if(t.removeStart<0){t.removeStart=s-1}if(t.removeCount<0){t.removeCount=s-t.removeStart}t.leavingRequiresTransition=t.removeCount>0&&t.removeStart+t.removeCount===s}if(t.insertViews){if(t.insertStart<0||t.insertStart>s){t.insertStart=s}t.enteringRequiresTransition=t.insertStart===s}const r=t.insertViews;if(!r){return}o(r.length>0,"length can not be zero");const a=k(r);if(a.length===0){throw new Error("invalid views to insert")}for(const e of a){e.delegate=t.opts.delegate;const i=e.nav;if(i&&i!==this){throw new Error("inserted view was already inserted")}if(e.state===T){throw new Error("inserted view was already destroyed")}}t.insertViews=a}getEnteringView(t,e){const i=t.insertViews;if(i!==undefined){return i[i.length-1]}const n=t.removeStart;if(n!==undefined){const i=this.views;const s=n+t.removeCount;for(let t=i.length-1;t>=0;t--){const r=i[t];if((t<n||t>=s)&&r!==e){return r}}}return undefined}postViewInit(t,e,i){var n,s,r;o(e||t,"Both leavingView and enteringView are null");o(i.resolve,"resolve must be valid");o(i.reject,"reject must be valid");const a=i.opts;const{insertViews:f,removeStart:l,removeCount:u}=i;let c;if(l!==undefined&&u!==undefined){o(l>=0,"removeStart can not be negative");o(u>=0,"removeCount can not be negative");c=[];for(let i=l;i<l+u;i++){const n=this.views[i];if(n!==undefined&&n!==t&&n!==e){c.push(n)}}(n=a.direction)!==null&&n!==void 0?n:a.direction="back"}const d=this.views.length+((s=f===null||f===void 0?void 0:f.length)!==null&&s!==void 0?s:0)-(u!==null&&u!==void 0?u:0);o(d>=0,"final balance can not be negative");if(d===0){console.warn(`You can't remove all the pages in the navigation stack. nav.pop() is probably called too many times.`,this,this.el);throw new Error("navigation stack needs at least one root page")}if(f){let t=i.insertStart;for(const e of f){this.insertViewAt(e,t);t++}if(i.enteringRequiresTransition){(r=a.direction)!==null&&r!==void 0?r:a.direction="forward"}}if(c&&c.length>0){for(const t of c){h(t.element,p);h(t.element,y);h(t.element,g)}for(const t of c){this.destroyView(t)}}}async transition(t,e,i){const n=i.opts;const s=n.progressAnimation?t=>this.sbAni=t:undefined;const r=u(this);const o=t.element;const a=e&&e.element;const h=Object.assign(Object.assign({mode:r,showGoBack:this.canGoBackSync(t),baseEl:this.el,progressCallback:s,animated:this.animated&&c.getBoolean("animated",true),enteringEl:o,leavingEl:a},n),{animationBuilder:n.animationBuilder||this.animation||c.get("navAnimation")});const{hasCompleted:l}=await f(h);return this.transitionFinish(l,t,e,n)}transitionFinish(t,e,i,n){const s=t?e:i;if(s){this.unmountInactiveViews(s)}return{hasCompleted:t,requiresTransition:true,enteringView:e,leavingView:i,direction:n.direction}}insertViewAt(t,e){const i=this.views;const n=i.indexOf(t);if(n>-1){o(t.nav===this,"view is not part of the nav");i.splice(n,1);i.splice(e,0,t)}else{o(!t.nav,"nav is used");t.nav=this;i.splice(e,0,t)}}removeView(t){o(t.state===C||t.state===T,"view state should be loaded or destroyed");const e=this.views;const i=e.indexOf(t);o(i>-1,"view must be part of the stack");if(i>=0){e.splice(i,1)}}destroyView(t){t._destroy();this.removeView(t)}unmountInactiveViews(t){if(this.destroyed){return}const e=this.views;const i=e.indexOf(t);for(let t=e.length-1;t>=0;t--){const n=e[t];const s=n.element;if(s){if(t>i){h(s,g);this.destroyView(n)}else if(t<i){l(s,true)}}}}canStart(){return!!this.swipeGesture&&!this.isTransitioning&&this.transInstr.length===0&&this.animationEnabled&&this.canGoBackSync()}onStart(){this.pop({direction:"back",progressAnimation:true})}onMove(t){if(this.sbAni){this.sbAni.progressStep(t)}}onEnd(t,e,i){if(this.sbAni){this.animationEnabled=false;this.sbAni.onFinish((()=>{this.animationEnabled=true}),{oneTimeCallback:true});let n=t?-.001:.001;if(!t){this.sbAni.easing("cubic-bezier(1, 0, 0.68, 0.28)");n+=r([0,0],[1,0],[.68,.28],[1,1],e)[0]}else{n+=r([0,0],[.32,.72],[0,1],[1,1],e)[0]}this.sbAni.progressEnd(t?1:0,n,i)}}render(){return i("slot",null)}get el(){return n(this)}static get watchers(){return{swipeGesture:["swipeGestureChanged"],root:["rootChanged"]}}};S.style=A; /*! * (C) Ionic http://ionicframework.com - MIT License */let O;const $=t=>{t.forEach((t=>{for(const e in t){if(t.hasOwnProperty(e)){const i=t[e];if(e==="easing"){const n="animation-timing-function";t[n]=i;delete t[e]}else{const n=j(e);if(n!==e){t[n]=i;delete t[e]}}}}}));return t};const j=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();const B=t=>{if(O===undefined){const e=t.style.animationName!==undefined;const i=t.style.webkitAnimationName!==undefined;O=!e&&i?"-webkit-":""}return O};const z=(t,e,i)=>{const n=e.startsWith("animation")?B(t):"";t.style.setProperty(n+e,i)};const D=(t,e)=>{const i=e.startsWith("animation")?B(t):"";t.style.removeProperty(i+e)};const I=(t,e)=>{let i;const n={passive:true};const s=()=>{if(i){i()}};const r=i=>{if(t===i.target){s();e(i)}};if(t){t.addEventListener("webkitAnimationEnd",r,n);t.addEventListener("animationend",r,n);i=()=>{t.removeEventListener("webkitAnimationEnd",r,n);t.removeEventListener("animationend",r,n)}}return s};const V=(t=[])=>t.map((t=>{const e=t.offset;const i=[];for(const e in t){if(t.hasOwnProperty(e)&&e!=="offset"){i.push(`${e}: ${t[e]};`)}}return`${e*100}% { ${i.join(" ")} }`})).join(" ");const x=[];const M=t=>{let e=x.indexOf(t);if(e<0){e=x.push(t)-1}return`ion-animation-${e}`};const W=t=>{const e=t.getRootNode!==undefined?t.getRootNode():t;return e.head||e};const R=(t,e,i)=>{var n;const s=W(i);const r=B(i);const o=s.querySelector("#"+t);if(o){return o}const a=((n=i.ownerDocument)!==null&&n!==void 0?n:document).createElement("style");a.id=t;a.textContent=`@${r}keyframes ${t} { ${e} } @${r}keyframes ${t}-alt { ${e} }`;s.appendChild(a);return a};const G=(t=[],e)=>{if(e!==undefined){const i=Array.isArray(e)?e:[e];return[...t,...i]}return t}; /*! * (C) Ionic http://ionicframework.com - MIT License */const L=t=>{let e;let i;let n;let s;let r;let o;let a=[];let h=[];let f=[];let l=false;let u;let c={};let d=[];let v=[];let p={};let y=0;let g=false;let b=false;let C;let T;let E;let N;let P=true;let k=false;let A=true;let S;let O;let j=false;const B=t;const x=[];const W=[];const L=[];const H=[];const F=[];const Y=[];const _=[];const q=[];const U=[];const X=[];const K=typeof AnimationEffect==="function"||m!==undefined&&typeof m.AnimationEffect==="function";const Z=typeof Element==="function"&&typeof Element.prototype.animate==="function"&&K;const J=100;const Q=()=>X;const tt=t=>{H.forEach((e=>{e.destroy(t)}));et(t);L.length=0;H.length=0;a.length=0;rt();l=false;A=true;return O};const et=t=>{ot();if(t){at()}};const it=()=>{g=false;b=false;A=true;T=undefined;E=undefined;N=undefined;y=0;k=false;P=true;j=false};const nt=()=>y!==0&&!j;const st=(t,e)=>{const i=(e===null||e===void 0?void 0:e.oneTimeCallback)?W:x;i.push({c:t,o:e});return O};const rt=()=>{x.length=0;W.length=0;return O};const ot=()=>{if(Z){X.forEach((t=>{t.cancel()}));X.length=0}else{const t=L.slice();w((()=>{t.forEach((t=>{D(t,"animation-name");D(t,"animation-duration");D(t,"animation-timing-function");D(t,"animation-iteration-count");D(t,"animation-delay");D(t,"animation-play-state");D(t,"animation-fill-mode");D(t,"animation-direction")}))}))}};const at=()=>{F.forEach((t=>{if(t===null||t===void 0?void 0:t.parentNode){t.parentNode.removeChild(t)}}));F.length=0};const ht=t=>{Y.push(t);return O};const ft=t=>{_.push(t);return O};const lt=t=>{q.push(t);return O};const ut=t=>{U.push(t);return O};const ct=t=>{h=G(h,t);return O};const dt=t=>{f=G(f,t);return O};const mt=(t={})=>{c=t;return O};const wt=(t=[])=>{for(const e of t){c[e]=""}return O};const vt=t=>{d=G(d,t);return O};const pt=t=>{v=G(v,t);return O};const yt=(t={})=>{p=t;return O};const gt=(t=[])=>{for(const e of t){p[e]=""}return O};const bt=()=>{if(r!==undefined){return r}if(u){return u.getFill()}return"both"};const Ct=()=>{if(T!==undefined){return T}if(o!==undefined){return o}if(u){return u.getDirection()}return"normal"};const Tt=()=>{if(g){return"linear"}if(n!==undefined){return n}if(u){return u.getEasing()}return"linear"};const Et=()=>{if(b){return 0}if(E!==undefined){return E}if(i!==undefined){return i}if(u){return u.getDuration()}return 0};const Nt=()=>{if(s!==undefined){return s}if(u){return u.getIterations()}return 1};const Pt=()=>{if(N!==undefined){return N}if(e!==undefined){return e}if(u){return u.getDelay()}return 0};const kt=()=>a;const At=t=>{o=t;qt(true);return O};const St=t=>{r=t;qt(true);return O};const Ot=t=>{e=t;qt(true);return O};const $t=t=>{n=t;qt(true);return O};const jt=t=>{if(!Z&&t===0){t=1}i=t;qt(true);return O};const Bt=t=>{s=t;qt(true);return O};const zt=t=>{u=t;return O};const Dt=t=>{if(t!=null){if(t.nodeType===1){L.push(t)}else if(t.length>=0){for(let e=0;e<t.length;e++){L.push(t[e])}}else{console.error("Invalid addElement value")}}return O};const It=t=>{if(t!=null){if(Array.isArray(t)){for(const e of t){e.parent(O);H.push(e)}}else{t.parent(O);H.push(t)}}return O};const Vt=t=>{const e=a!==t;a=t;if(e){xt(a)}return O};const xt=t=>{if(Z){Q().forEach((e=>{if(e.effect.setKeyframes){e.effect.setKeyframes(t)}else{const i=new KeyframeEffect(e.effect.target,t,e.effect.getTiming());e.effect=i}}))}else{Gt()}};const Mt=()=>{Y.forEach((t=>t()));_.forEach((t=>t()));const t=h;const e=f;const i=c;L.forEach((n=>{const s=n.classList;t.forEach((t=>s.add(t)));e.forEach((t=>s.remove(t)));for(const t in i){if(i.hasOwnProperty(t)){z(n,t,i[t])}}}))};const Wt=()=>{te();q.forEach((t=>t()));U.forEach((t=>t()));const t=P?1:0;const e=d;const i=v;const n=p;L.forEach((t=>{const s=t.classList;e.forEach((t=>s.add(t)));i.forEach((t=>s.remove(t)));for(const e in n){if(n.hasOwnProperty(e)){z(t,e,n[e])}}}));x.forEach((e=>e.c(t,O)));W.forEach((e=>e.c(t,O)));W.length=0;A=true;if(P){k=true}P=true};const Rt=()=>{if(y===0){return}y--;if(y===0){Wt();if(u){u.animationFinish()}}};const Gt=(e=true)=>{at();const i=$(a);L.forEach((n=>{if(i.length>0){const s=V(i);S=t!==undefined?t:M(s);const r=R(S,s,n);F.push(r);z(n,"animation-duration",`${Et()}ms`);z(n,"animation-timing-function",Tt());z(n,"animation-delay",`${Pt()}ms`);z(n,"animation-fill-mode",bt());z(n,"animation-direction",Ct());const o=Nt()===Infinity?"infinite":Nt().toString();z(n,"animation-iteration-count",o);z(n,"animation-play-state","paused");if(e){z(n,"animation-name",`${r.id}-alt`)}w((()=>{z(n,"animation-name",r.id||null)}))}}))};const Lt=()=>{L.forEach((t=>{const e=t.animate(a,{id:B,delay:Pt(),duration:Et(),easing:Tt(),iterations:Nt(),fill:bt(),direction:Ct()});e.pause();X.push(e)}));if(X.length>0){X[0].onfinish=()=>{Rt()}}};const Ht=(t=true)=>{Mt();if(a.length>0){if(Z){Lt()}else{Gt(t)}}l=true};const Ft=t=>{t=Math.min(Math.max(t,0),.9999);if(Z){X.forEach((e=>{e.currentTime=e.effect.getComputedTiming().delay+Et()*t;e.pause()}))}else{const e=`-${Et()*t}ms`;L.forEach((t=>{if(a.length>0){z(t,"animation-delay",e);z(t,"animation-play-state","paused")}}))}};const Yt=t=>{X.forEach((t=>{t.effect.updateTiming({delay:Pt(),duration:Et(),easing:Tt(),iterations:Nt(),fill:bt(),direction:Ct()})}));if(t!==undefined){Ft(t)}};const _t=(t=true,e)=>{w((()=>{L.forEach((i=>{z(i,"animation-name",S||null);z(i,"animation-duration",`${Et()}ms`);z(i,"animation-timing-function",Tt());z(i,"animation-delay",e!==undefined?`-${e*Et()}ms`:`${Pt()}ms`);z(i,"animation-fill-mode",bt()||null);z(i,"animation-direction",Ct()||null);const n=Nt()===Infinity?"infinite":Nt().toString();z(i,"animation-iteration-count",n);if(t){z(i,"animation-name",`${S}-alt`)}w((()=>{z(i,"animation-name",S||null)}))}))}))};const qt=(t=false,e=true,i)=>{if(t){H.forEach((n=>{n.update(t,e,i)}))}if(Z){Yt(i)}else{_t(e,i)}return O};const Ut=(t=false,e)=>{H.forEach((i=>{i.progressStart(t,e)}));Zt();g=t;if(!l){Ht()}qt(false,true,e);return O};const Xt=t=>{H.forEach((e=>{e.progressStep(t)}));Ft(t);return O};const Kt=(t,e,i)=>{g=false;H.forEach((n=>{n.progressEnd(t,e,i)}));if(i!==undefined){E=i}k=false;P=true;if(t===0){T=Ct()==="reverse"?"normal":"reverse";if(T==="reverse"){P=false}if(Z){qt();Ft(1-e)}else{N=(1-e)*Et()*-1;qt(false,false)}}else if(t===1){if(Z){qt();Ft(e)}else{N=e*Et()*-1;qt(false,false)}}if(t!==undefined){st((()=>{E=undefined;T=undefined;N=undefined}),{oneTimeCallback:true});if(!u){re()}}return O};const Zt=()=>{if(l){if(Z){X.forEach((t=>{t.pause()}))}else{L.forEach((t=>{z(t,"animation-play-state","paused")}))}j=true}};const Jt=()=>{H.forEach((t=>{t.pause()}));Zt();return O};const Qt=()=>{C=undefined;Rt()};const te=()=>{if(C){clearTimeout(C)}};const ee=()=>{te();w((()=>{L.forEach((t=>{if(a.length>0){z(t,"animation-play-state","running")}}))}));if(a.length===0||L.length===0){Rt()}else{const t=Pt()||0;const e=Et()||0;const i=Nt()||1;if(isFinite(i)){C=setTimeout(Qt,t+e*i+J)}I(L[0],(()=>{te();w((()=>{ie();w(Rt)}))}))}};const ie=()=>{L.forEach((t=>{D(t,"animation-duration");D(t,"animation-delay");D(t,"animation-play-state")}))};const ne=()=>{X.forEach((t=>{t.play()}));if(a.length===0||L.length===0){Rt()}};const se=()=>{if(Z){Ft(0);Yt()}else{_t()}};const re=t=>new Promise((e=>{if(t===null||t===void 0?void 0:t.sync){b=true;st((()=>b=false),{oneTimeCallback:true})}if(!l){Ht()}if(k){se();k=false}if(A){y=H.length+1;A=false}st((()=>e()),{oneTimeCallback:true});H.forEach((t=>{t.play()}));if(Z){ne()}else{ee()}j=false}));const oe=()=>{H.forEach((t=>{t.stop()}));if(l){ot();l=false}it()};const ae=(t,e)=>{const i=a[0];if(i!==undefined&&(i.offset===undefined||i.offset===0)){i[t]=e}else{a=[{offset:0,[t]:e},...a]}return O};const he=(t,e)=>{const i=a[a.length-1];if(i!==undefined&&(i.offset===undefined||i.offset===1)){i[t]=e}else{a=[...a,{offset:1,[t]:e}]}return O};const fe=(t,e,i)=>ae(t,e).to(t,i);return O={parentAnimation:u,elements:L,childAnimations:H,id:B,animationFinish:Rt,from:ae,to:he,fromTo:fe,parent:zt,play:re,pause:Jt,stop:oe,destroy:tt,keyframes:Vt,addAnimation:It,addElement:Dt,update:qt,fill:St,direction:At,iterations:Bt,duration:jt,easing:$t,delay:Ot,getWebAnimations:Q,getKeyframes:kt,getFill:bt,getDirection:Ct,getDelay:Pt,getIterations:Nt,getEasing:Tt,getDuration:Et,afterAddRead:lt,afterAddWrite:ut,afterClearStyles:gt,afterStyles:yt,afterRemoveClass:pt,afterAddClass:vt,beforeAddRead:ht,beforeAddWrite:ft,beforeClearStyles:wt,beforeStyles:mt,beforeRemoveClass:dt,beforeAddClass:ct,onFinish:st,isRunning:nt,progressStart:Ut,progressStep:Xt,progressEnd:Kt}};const H="zt-bottom-drawer{--zt-sat:env(safe-area-inset-top);--zt-sar:env(safe-area-inset-right);--zt-sab:env(safe-area-inset-bottom);--zt-sal:env(safe-area-inset-left);position:absolute;width:100%;height:100%}zt-bottom-drawer ion-nav ion-header ion-toolbar:first-of-type{padding-top:0px}";const F=class{constructor(i){t(this,i);this.ztChangePositionEvent=e(this,"ztChangePositionEvent",7);this.ztHideEvent=e(this,"ztHideEvent",7);this.ztNavDidChange=e(this,"ztNavDidChange",7);this.ztNavWillChange=e(this,"ztNavWillChange",7);this.navegando=false;this.deltaChangeSate=5;this.enTouchMove=false;this.cancelMove=false;this.windowh=-1;this.ultimoValuePosY=0;this.positionName=undefined;this.hideOnPositionZero=false;this.fixCurrentPosition=false;this.disableGesture=false;this.allowScroll=true;this.positions="close-b-10,bottom-b-200,middle-b-450,top-t-60";this.hidden=false;this.coefAnimationTime=40;this.safeAreaTop=undefined;this.safeAreaBottom=undefined}setDisableGesture(t){if(!t&&!this.gesture&&this._htmlElements.gestureTarget){this.gesture=v({el:this._htmlElements.gestureTarget,threshold:0,gestureName:"drawer-drag",disableScroll:true,passive:true,direction:"y",onStart:t=>this.onStart(t),onMove:t=>{this.onMove(t)},onEnd:t=>{this.onEnd(t)}})}if(this.gesture)this.gesture.enable(!t)}setAllowScroll(t){if(this.ionContent){this.ionContent.scrollY=t;this.ionContent.scrollEvents=t}}async getNav(){return this.nav}async goBack(t,e,i){if(t){t=t-1;const e=this.el.firstChild.childNodes.length;if(t<e){await this.nav.removeIndex(e-t-1,t)}else{return await this.nav.popToRoot()}}return this.nav.pop(e,i)}async goBackToRoot(t,e){return this.nav.popToRoot(t,e)}async goBackToIndex(t,e,i){return this.nav.popTo(t,e,i)}async getNavActive(){return this.nav.getActive()}async getNavCurrentComponent(){return this.currentComponent}isElement(t){return typeof HTMLElement==="object"?t instanceof HTMLElement:t&&typeof t==="object"&&t!==null&&t.nodeType===1&&typeof t.nodeName==="string"}async saveStateInActiveComponent(){let t=await this.nav.getActive();t.component.__zt_navDrawer.options.allowScroll=this.allowScroll;t.component.__zt_navDrawer.options.disableGesture=this.disableGesture;t.component.__zt_navDrawer.options.positionName=this.positionName;t.component.__zt_navDrawer.options.positions=this.positions;t.component.__zt_navDrawer.options.fixCurrentPosition=this.fixCurrentPosition}async pushNav(t,e,i){if(this.navegando)throw new Error("The Bottom Drawer is navigating, wait after call again. Please use the promise.");if(!i){i={}}if(!i.positions&&!this.positions)throw new Error("The position by default or in the options are required.");this.navegando=true;await new Promise((async(n,s)=>{if(i&&!i.selectorContent){i.selectorContent="ion-content"}if(typeof t=="string")t=document.createElement(t);if(this.isElement(t)){t.__zt_navDrawer={resolve:n,reject:s,options:i};console.log(i);this.nav.push(t,e)}}));this.navegando=false;this.setHeightContainer("CONTENT");return true}async getActiveComponentTagName(){return this._tagNameComponetActive}async getCurrentIndex(){return this.el.firstChild.childNodes.length}async navDidChange(){let t=await this.nav.getActive();this._tagNameComponetActive=t.component.tagName;const e=t.component.__zt_navDrawer.options;if(e.allowScroll!=undefined)this.allowScroll=e.allowScroll;if(e.disableGesture!=undefined)this.disableGesture=e.disableGesture;await Promise.all([this.initActiveContentNav(t),new Promise((async t=>{if(e.positions){this.setPositions(e.positions)}if(e.positionName){await this.setPositionByName(e.positionName,true)}if(e.fixCurrentPosition!=undefined)this.fixCurrentPosition=e.fixCurrentPosition;t()}))]);t.component.__zt_navDrawer.resolve(true);this.ztNavDidChange.emit(t)}async initActiveContentNav(t){if(t){const e=t.component.__zt_navDrawer.options;this.currentComponent=t.element;this._htmlElements.content=this.currentComponent.querySelector(e.selectorContent);if(!this._htmlElements.content)throw new Error(`Bottom Drawer - Error - The selector ${e.selectorContent} not found any element`);let i=t.element;if(e.selectorGesture)i=t.element.querySelector(e.selectorGesture);this.addGesture(i);if(this._htmlElements&&this._htmlElements.content&&this._htmlElements.content.nodeName=="ION-CONTENT"){this.ionContent=this._htmlElements.content;this.ionContent.scrollY=this.allowScroll;this.ionContent.scrollEvents=this.allowScroll}else{this.ionContent=this._htmlElements.content}}}async componentDidLoad(){var t,e;this._htmlElements={drawer:null,gestureTarget:null,content:null};this._htmlElements.drawer=this.el;this.safeAreaTop=Number(((t=getComputedStyle(this.el).getPropertyValue("--zt-sat"))!==null&&t!==void 0?t:"0").replace("px",""));this.safeAreaBottom=Number(((e=getComputedStyle(this.el).getPropertyValue("--zt-sab"))!==null&&e!==void 0?e:"0").replace("px",""));this.el.style.setProperty("height",this.getWHWindow().height+"px");this.setPositions(this.positions);this.setAnimation()}addGesture(t){if(this.gesture){this.gesture.destroy()}this.gesture=v({el:t,threshold:0,gestureName:"drawer-drag",disableScroll:true,passive:false,direction:"y",onStart:t=>{this.onStart(t)},onMove:t=>{this.onMove(t)},onEnd:t=>{this.onEnd(t)}});if(this.gesture)this.gesture.enable(!this.disableGesture)}setPositions(t){let e=[];let i=1;let n=t.toLowerCase().split(",");let s=this.getWHWindow();let r;n.forEach((t=>{var n,o;let a=t.split("-");if(a.length===3){try{let t={index:i,name:a[0],distanceTo:a[1].toLowerCase()==="t"?"TOP":"BOTTOM",distance:Number.parseInt(a[2]),distanceToTop:0,previousPosition:null,nextPosition:null};if(t.distanceTo==="TOP"){t.distanceToTop=t.distance+((n=this.safeAreaTop)!==null&&n!==void 0?n:0)}else{t.distanceToTop=s.height-((o=this.safeAreaBottom)!==null&&o!==void 0?o:0)-t.distance}if(r){t.previousPosition=r;r.nextPosition=t}r=t;i=i+1;e.push(t)}catch(e){throw Error("ZTBottomDrawer - Positions is invalid : "+t+" must be name:string-[t|b]:string-distance:number ")}}}));e.forEach((t=>{if(!t.nextPosition){this.maxTop=t.distanceToTop}}));this._positions=e}async setAnimation(){this.animation=L().addElement(this.el);this.animation.duration(1e3).fromTo("transform",`translateY(${this.getWHWindow().height}px)`,`translateY(0px)`);this.animation.progressStart(true,.1);if(this._position){this.animation.progressStep(1-this._position.distanceToTop/this.getWHWindow().height)}}async getCurrrentPositionDto(){return Object.assign({},this._position)}async getPositionByName(t){return this._positions.find((e=>e.name==t))}async getPositionByIndex(t){let e=this._positions.find((e=>e.index==t));return e}async hide(){this.gesture.enable(false);this.hidden=true;let t=this.getWHWindow().height+10;await this.setTranslateY(t,true);this.el.style.setProperty("display","none")}async show(t){if(!t){return}this.el.style.setProperty("display","inline");let e=await this.getPositionByName(t);if(!e){return}await this.setPosition(e);this.hidden=false}getPositionByPosY(t,e){let i={newPosition:null,close:false};i.newPosition=this._positions.find((i=>{if(e==="UP"){if(i.previousPosition&&t<i.previousPosition.distanceToTop+this.deltaChangeSate&&(!i.nextPosition||i.nextPosition&&t>i.distanceToTop-this.deltaChangeSate))return i;if(!i.previousPosition&&t>i.distanceToTop-this.deltaChangeSate)return i}if(e==="DOWN"){if(i.nextPosition&&t>i.nextPosition.distanceToTop+this.deltaChangeSate&&(!i.previousPosition||i.previousPosition&&t<i.distanceToTop+this.deltaChangeSate))return i;if(!i.nextPosition&&t<i.distanceToTop+this.deltaChangeSate)return i}}));if(t>this.getWHWindow().height){i.close=true;return i}return i}onStart(t){if(this.fixCurrentPosition){this.cancelMove=true;return}if(t.event.path){let e=t.event.path;let i=e.find((t=>t===this._htmlElements.content));if(i){this.cancelMove=true;return}}this.cancelMove=false;if(this.ionContent){this.ionContent.scrollToTop(0);if(this.allowScroll){this.ionContent.scrollY=false;this.ionContent.scrollEvents=false}}this.setHeightContainer("MAX");this.startPosTopMove=this._htmlElements.drawer.getBoundingClientRect().top;this.lastPositionY=this.startPosTopMove}async onMove(t){if(this.cancelMove)return;if(this.moveFastAnimationProgress)await this.moveFastAnimationProgress;this.lastCalc=this.startPosTopMove+t.deltaY;if(this.lastCalc<this.maxTop)this.lastCalc=this.maxTop;this.previusPositionY=this.lastPositionY;this.lastPositionY=t.currentY;this.setTranslateY(this.lastCalc)}async onEnd(t){if(this.cancelMove)return;this.moveFast=false;this.gesture.enable(false);if(this.ionContent&&this.allowScroll){this.ionContent.scrollY=true;this.ionContent.scrollEvents=true}this.changeStateByGesture(t);this.startPosTopMove=0;this.setDisableGesture(this.disableGesture);return true}getDirectionGesture(){let t=this.lastPositionY-this.previusPositionY;if(t/Math.abs(t)*-1>0)return"UP";else return"DOWN"}async changeStateByGesture(t){if(Math.abs(t.deltaY)==0){let t=this._position.distanceToTop;await this.setTranslateY(t);this.setHeightContainer("CONTENT");return}if(this.gesture)this.gesture.enable(false);let e=this._position;let i=this.startPosTopMove+t.deltaY;let n=this.getPositionByPosY(i,this.getDirectionGesture());if(n.close){if(this.hideOnPositionZero){this.ztHideEvent.emit();return this.hide()}}if(n.newPosition){e=n.newPosition}if(e!=this._position){await this.setPosition(e);return}await this.setTranslateY(this._position.distanceToTop,true);this.setDisableGesture(this.disableGesture);this.setHeightContainer("CONTENT")}getWHWindow(t=false){let e=this.windowh;if(t){e=window._zt_wh||window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}if(e===-1){e=this.windowh=window._zt_wh||window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}return{height:e,width:window._zt_wh||window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth}}async setPositionByName(t,e=false){if(this.fixCurrentPosition&&!e)throw new Error("The CurentPosition of the bottom drawer is fixed");let i=await this.getPositionByName(t);if(i&&(e||(!this._position||this._position&&this._position.name!==i.name))){return await this.setPosition(i,e)}}async setPosition(t,e=false){if(!t)return;if(this.fixCurrentPosition&&!e)throw new Error("The CurentPosition of the bottom drawer is fixed");if(this.gesture)this.gesture.enable(false);const i=this._position?this._position.name:undefined;if(!this._position||e||this._position&&t.name!==this._position.name){this._position=t;this.positionName=this._position.name;this.ztChangePositionEvent.emit({positionName:this.positionName,lastPositionName:i,htmlElements:this._htmlElements})}if(!t.distanceToTop){let e=this.getWHWindow();if(t.distanceTo==="TOP"){t.distanceToTop=t.distance}else{t.distanceToTop=e.height-t.distance}}this.setHeightContainer("MAX");if(this.ionContent){this.ionContent.scrollToTop(0)}await this.setTranslateY(t.distanceToTop,true);this.setHeightContainer("CONTENT");this.setDisableGesture(this.disableGesture)}getDuration(t){let e=t/1e3*this.coefAnimationTime;return e}async animateRolo(t,e){if(this.animateRoloPromise)return this.animateRoloPromise;const i=Math.abs(t-e);const n=i/this.getDuration(i);const s=t>e?-1:1;this.posyAnimate=t;this.animateRoloPromise=new Promise((t=>{this.intervalAnimation=setInterval((()=>{this.posyAnimate=this.posyAnimate+n*s;this.animation.progressStep(1-this.posyAnimate/this.getWHWindow().height);if(s>0&&this.posyAnimate>e||s<0&&this.posyAnimate<e){this.animation.progressStep(1-e/this.getWHWindow().height);clearInterval(this.intervalAnimation);t()}}),this.getDuration(i))}));await this.animateRoloPromise;this.animateRoloPromise=undefined}async setTranslateY(t,e=false){return new Promise((async i=>{if(this.ultimoValuePosY===t){return i()}if(!this.ultimoValuePosY){this.animation.progressStep(1-t/this.getWHWindow().height)}else{if(e)await this.animateRolo(this.ultimoValuePosY,t);else{this.animation.progressStep(1-t/this.getWHWindow().height)}}this.ultimoValuePosY=t;i()}))}setHeightContainer(t,e=false){const i=this.getWHWindow(e).height;let n=i;if(t==="MAX"){n=n-this.maxTop}else{if(!this.ionContent||this.navegando)return;const t=this.ionContent.getBoundingClientRect();const e=t.top;const s=this.el.getBoundingClientRect().top;if(i>e){n=n-s}}this.nav.style.setProperty("height",n-this.safeAreaBottom+"px")}async refreshSizeContent(){return this.setHeightContainer("CONTENT",true)}async setScrollToTop(t=200){if(this.ionContent){return this.ionContent.scrollToTop(t)}}render(){return i(s,null,i("ion-nav",{onIonNavWillChange:()=>{this.navWillchange()},onIonNavDidChange:()=>{this.navDidChange()},ref:t=>this.nav=t}))}navWillchange(){this.ztNavWillChange.emit()}get el(){return n(this)}static get watchers(){return{disableGesture:["setDisableGesture"],allowScroll:["setAllowScroll"],positions:["setPositions"]}}};F.style=H;const Y=class{constructor(e){t(this,e)}async getNav(){return this.nav}async getActive(){return this.nav.getActive()}isElement(t){return typeof HTMLElement==="object"?t instanceof HTMLElement:t&&typeof t==="object"&&t!==null&&t.nodeType===1&&typeof t.nodeName==="string"}async pushNav(t,e,i,n){if(typeof t=="string")t=document.createElement(t);if(this.isElement(t)){if(this.currentComponent&&this.currentComponent.canDeactivate){let i=await this.currentComponent.canDeactivate(e,t);if(!i){return false}}if(t.canActivate){let i=await t.canActivate(e,this.currentComponent);if(!i){return false}}this.currentComponent=t;await this.nav.push(t,e,i,n);return true}return false}render(){return i("ion-nav",{ref:t=>this.nav=t})}get el(){return n(this)}};export{S as ion_nav,F as zt_bottom_drawer,Y as zt_nav}; //# sourceMappingURL=p-6ba51645.entry.js.map