UNPKG

@ionic/core

Version:
4 lines • 3.47 kB
/*! * (C) Ionic http://ionicframework.com - MIT License */ import{d as t}from"./p-ZjP4CjeZ.js";import{MENU_BACK_BUTTON_PRIORITY as e,addCloseWatcherCondition as n}from"./p-CohRJRIu.js";import{p as r}from"./p-Ct2aBEue.js";import{c as s}from"./p-B4IBdPVJ.js";import{b as a}from"./p-HthJZjZ6.js";import{c as o}from"./p-ChsJlFCQ.js";const i=t=>o().duration(t?400:300),u=t=>{let e,n;const r=t.width+8,s=o(),u=o();t.isEndSide?(e=r+"px",n="0px"):(e=-r+"px",n="0px"),s.addElement(t.menuInnerEl).fromTo("transform",`translateX(${e})`,`translateX(${n})`);const c="ios"===a(t),p=c?.2:.25;return u.addElement(t.backdropEl).fromTo("opacity",.01,p),i(c).addAnimation([s,u])},c=t=>{let e,n;const r=a(t),s=t.width;t.isEndSide?(e=-s+"px",n=s+"px"):(e=s+"px",n=-s+"px");const u=o().addElement(t.menuInnerEl).fromTo("transform",`translateX(${n})`,"translateX(0px)"),c=o().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${e})`),p=o().addElement(t.backdropEl).fromTo("opacity",.01,.32);return i("ios"===r).addAnimation([u,c,p])},p=t=>{const e=a(t),n=t.width*(t.isEndSide?-1:1)+"px",r=o().addElement(t.contentEl).fromTo("transform","translateX(0px)",`translateX(${n})`);return i("ios"===e).addAnimation(r)},m=(()=>{const a=new Map,o=[],i=async(t,e=!1)=>{if(await h(),"start"===t||"end"===t){const n=o.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=o.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))||(o.length>0?o[0].el:void 0)},m=async()=>(await h(),l()),f=(t,e)=>{a.set(t,e)},l=()=>w((t=>t._isOpen)),d=()=>o.some((t=>t.isAnimating)),w=t=>{const e=o.find(t);if(void 0!==e)return e.el},h=()=>Promise.all(Array.from(document.querySelectorAll("ion-menu")).map((t=>new Promise((e=>s(t,e))))));return f("reveal",p),f("push",c),f("overlay",u),n((()=>void 0!==l())),t?.addEventListener("ionBackButton",(t=>{const n=l();n&&t.detail.register(e,(()=>n.close()))})),{registerAnimation:f,get:i,getMenus:async()=>(await h(),o.map((t=>t.el))),getOpen:m,isEnabled:async t=>{const e=await i(t);return!!e&&!e.disabled},swipeGesture:async(t,e)=>{const n=await i(e);return n&&(n.swipeGesture=t),n},isAnimating:async()=>(await h(),d()),isOpen:async t=>{if(null!=t){const e=await i(t);return void 0!==e&&e.isOpen()}return void 0!==await m()},enable:async(t,e)=>{const n=await i(e);return n&&(n.disabled=!t),n},toggle:async t=>{const e=await i(t,!0);return!!e&&e.toggle()},close:async t=>{const e=await(void 0!==t?i(t,!0):m());return void 0!==e&&e.close()},open:async t=>{const e=await i(t,!0);return!!e&&e.open()},_getOpenSync:l,_createAnimation:(t,e)=>{const n=a.get(t);if(!n)throw new Error("animation not registered");return n(e)},_register:t=>{o.indexOf(t)<0&&o.push(t)},_unregister:t=>{const e=o.indexOf(t);e>-1&&o.splice(e,1)},_setOpen:async(t,e,n,r)=>{if(d())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}