@ionic/core
Version:
Base components for Ionic
4 lines • 3.39 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{d as t}from"./p-ZjP4CjeZ.js";import{MENU_BACK_BUTTON_PRIORITY as e}from"./p-DzH0J0yi.js";import{e as n,m as r}from"./p-B_U9CtaY.js";import{c as s}from"./p-Do-uqmtX.js";import{c as a}from"./p-bNmY-WfR.js";const o=t=>a().duration(t?400:300),i=t=>{let e,r;const s=t.width+8,i=a(),u=a();t.isEndSide?(e=s+"px",r="0px"):(e=-s+"px",r="0px"),i.addElement(t.menuInnerEl).fromTo("transform",`translateX(${e})`,`translateX(${r})`);const c="ios"===n(t),m=c?.2:.25;return u.addElement(t.backdropEl).fromTo("opacity",.01,m),o(c).addAnimation([i,u])},u=t=>{let e,r;const s=n(t),i=t.width;t.isEndSide?(e=-i+"px",r=i+"px"):(e=i+"px",r=-i+"px");const u=a().addElement(t.menuInnerEl).fromTo("transform",`translateX(${r})`,"translateX(0px)"),c=a().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${e})`),m=a().addElement(t.backdropEl).fromTo("opacity",.01,.32);return o("ios"===s).addAnimation([u,c,m])},c=t=>{const e=n(t),r=t.width*(t.isEndSide?-1:1)+"px",s=a().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${r})`);return o("ios"===e).addAnimation(s)},m=(()=>{const n=new Map,a=[],o=async(t,e=!1)=>{if(await d(),"start"===t||"end"===t){const n=a.filter((e=>e.side===t&&!e.disabled));if(n.length>=1)return n.length>1&&e&&r(`menuController queried for a menu on the "${t}" side, but ${n.length} menus were found. The first menu reference will be used. If this is not the behavior you want then pass the ID of the menu instead of its side.`,n.map((t=>t.el))),n[0].el;const s=a.filter((e=>e.side===t));if(s.length>=1)return s.length>1&&e&&r(`menuController queried for a menu on the "${t}" side, but ${s.length} menus were found. The first menu reference will be used. If this is not the behavior you want then pass the ID of the menu instead of its side.`,s.map((t=>t.el))),s[0].el}else if(null!=t)return w((e=>e.menuId===t));return w((t=>!t.disabled))||(a.length>0?a[0].el:void 0)},m=async()=>(await d(),f()),p=(t,e)=>{n.set(t,e)},f=()=>w((t=>t._isOpen)),l=()=>a.some((t=>t.isAnimating)),w=t=>{const e=a.find(t);if(void 0!==e)return e.el},d=()=>Promise.all(Array.from(document.querySelectorAll("ion-menu")).map((t=>new Promise((e=>s(t,e))))));return p("reveal",c),p("push",u),p("overlay",i),null==t||t.addEventListener("ionBackButton",(t=>{const n=f();n&&t.detail.register(e,(()=>n.close()))})),{registerAnimation:p,get:o,getMenus:async()=>(await d(),a.map((t=>t.el))),getOpen:m,isEnabled:async t=>{const e=await o(t);return!!e&&!e.disabled},swipeGesture:async(t,e)=>{const n=await o(e);return n&&(n.swipeGesture=t),n},isAnimating:async()=>(await d(),l()),isOpen:async t=>{if(null!=t){const e=await o(t);return void 0!==e&&e.isOpen()}return void 0!==await m()},enable:async(t,e)=>{const n=await o(e);return n&&(n.disabled=!t),n},toggle:async t=>{const e=await o(t,!0);return!!e&&e.toggle()},close:async t=>{const e=await(void 0!==t?o(t,!0):m());return void 0!==e&&e.close()},open:async t=>{const e=await o(t,!0);return!!e&&e.open()},_getOpenSync:f,_createAnimation:(t,e)=>{const r=n.get(t);if(!r)throw new Error("animation not registered");return r(e)},_register:t=>{a.indexOf(t)<0&&a.push(t)},_unregister:t=>{const e=a.indexOf(t);e>-1&&a.splice(e,1)},_setOpen:async(t,e,n,r)=>{if(l())return!1;if(e){const e=await m();e&&t.el!==e&&await e.setOpen(!1,!1)}return t._setOpen(e,n,r)}}})();export{m}