UNPKG

@0x30/vue-navigation

Version:
2 lines (1 loc) 8.79 kB
(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.vueNavigation={},a.Vue))})(this,function(a,c){"use strict";const j=()=>document.querySelector("#___disable_all_pointerevents"),P=()=>{const e=j();e.style.display="block"},A=()=>{const e=j();e.style.display="none"},ie=()=>{const e=document.createElement("div");e.id="___disable_all_pointerevents",e.style.position="fixed",e.style.top="0",e.style.right="0",e.style.bottom="0",e.style.left="0",e.style.opacity="0",e.style.display="none",e.style.zIndex="99999999",document.body.appendChild(e)},T=()=>`_${Math.random().toString(32).slice(2)}`,O=(e,n)=>{e==null||e.forEach(t=>t==null?void 0:t(...n??[]))},$=T(),l=[];let J;const I=e=>J=e,K=()=>J;let W;const U=e=>W=e,pe=()=>W,B=()=>l[l.length-1],N={},le=(e,n)=>{U(e),N[e]=()=>{delete N[e],W=void 0,n()}},de=e=>{var n;e&&((n=N[e])==null||n.apply(null))};var s=(e=>(e.onEnter="_vn_oe",e.onLeave="_vn_ol",e.close="_vn_c",e.onLeaveBefore="_vn_olb",e.onWillAppear="_vn_owa",e.onWillDisappear="_vn_owd",e.onDidAppear="_vn_oda",e.onDidDisappear="_vn_odd",e.cancelBatchId="_vn_cbi",e.ExtData="_vn_ed",e.onAfterEnter="_vn_oae",e.onAfterLeave="_vn_oal",e.onBeforeEnter="_vn_obe",e.onBeforeLeave="_vn_obl",e.ProgressExitAnimated="_vn_p_e_a",e))(s||{});const v=(e,n,t)=>{e&&(e[n]=t)},m=(e,n,t)=>{if(e){const r=e[n]??[];e[n]=[...r,t]}},y=(e,n)=>{if(e)return e[n]},X=(e,n)=>{const t=V(e)??{};v(e,"_vn_ed",{...t,...n})},V=e=>y(e,"_vn_ed"),ue=e=>{var n;v((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onLeaveBefore,e)},Y=e=>y(e,s.onLeaveBefore),fe=(e,n)=>v(e,s.onLeaveBefore,n),_e=()=>{var e;X((e=c.getCurrentInstance())==null?void 0:e.appContext,{__is_quiet_page:!0})},L=e=>{var n;return((n=V(e))==null?void 0:n.__is_quiet_page)===!0},Ce=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onWillAppear,e)},he=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onWillDisappear,e)},ge=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onDidAppear,e)},ve=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onDidDisappear,e)},w=(e,n,t)=>{const r=y(e,n);O(r,[t])},me=e=>{var r;const n=(r=c.getCurrentInstance())==null?void 0:r.appContext,t=x(n)??{};X(n,{__pageMateInfo:{...t,...e}})},x=e=>{var n;return(n=V(e))==null?void 0:n.__pageMateInfo},z=new Set,ye=(e,n)=>{const t=[e,n];return z.add(t),()=>z.delete(t)},Z=(e,n)=>{z.forEach(([t,r])=>{const i=x(e),p=x(n);(((r==null?void 0:r.isEvery)??!1)||i!==void 0&&p!==void 0)&&t.apply(null,[i,p])})},we=()=>{var e;return x((e=B())==null?void 0:e._context)},Be=(e,n)=>(v(e,s.cancelBatchId,n),n),Ee=e=>y(e,s.cancelBatchId),Pe=e=>{var n;v((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onEnter,e)},Ae=e=>{var n;v((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onLeave,e)},Ie=(e,n)=>{v(e,s.close,n)},be=e=>y(e,s.close),H=(e,n,t,r)=>new Promise(i=>{const p=y(n,e);p?p==null||p.apply(null,[{from:t,to:r},i]):i()}),Le=(e,n,t)=>H(s.onEnter,e,n,t),xe=(e,n,t)=>H(s.onLeave,e,n,t),q=e=>{window.dispatchEvent(new CustomEvent("onNativateIosScreenEdgePanEvent",{detail:e}))};function ee(){window.ScreenEdgePanGestureRecognizerStart=()=>{P(),q({state:0})},window.ScreenEdgePanGestureRecognizerChange=n=>{q({state:1,progress:n})},window.ScreenEdgePanGestureRecognizerEnded=n=>{q({state:2,isFinish:n}),A()};const e=n=>(n==null?void 0:n.childElementCount)===1?n.children[0]:n;window.addEventListener("onNativateIosScreenEdgePanEvent",n=>{if(l.length<2)return;const t=l[l.length-1],r=Y(t._context);if(r!==void 0){const d=r();if(d===!1||typeof d=="function")return}const i=e(t._container),p=e(l[l.length-2]._container);switch(n.detail.state){case 0:break;case 1:ne({from:i,to:p},n.detail.progress);break;default:ne({from:i,to:p},0,n.detail.isFinish);break}})}const De=e=>{var n;v((n=c.getCurrentInstance())==null?void 0:n.appContext,s.ProgressExitAnimated,e)},ne=(e,n,t)=>{var i;const r=y((i=l[l.length-1])==null?void 0:i._context,s.ProgressExitAnimated);r==null||r.apply(null,[e,n,t])},ke=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onAfterEnter,e)},Se=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onAfterLeave,e)},Me=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onBeforeEnter,e)},Te=e=>{var n;m((n=c.getCurrentInstance())==null?void 0:n.appContext,s.onBeforeLeave,e)},D=(e,n)=>{const t=y(e,n);O(t)};let k;const We=e=>{k=e},G=(e,n,t,r)=>{var p;if(t===void 0)return;const i=()=>{var d;t.unmount(),t._container instanceof Element&&((d=t._container.parentElement)==null||d.removeChild(t._container)),n&&(A(),de(r))};e?(p=be(t._context))==null||p(()=>i()):i()},te=e=>(e==null?void 0:e.childElementCount)===1?e.children[0]:e,oe=(e,n,t)=>new Promise(r=>{const i=document.createElement("div");document.body.appendChild(i);const p=()=>{n!==!1&&G(!1,!1,l.splice(l.length-2,1)[0])},{onAfterEnter:d,onAfterLeave:C,onBeforeEnter:h,onBeforeLeave:g,..._}=t??{},f=c.createApp({setup:()=>{var ce;const E=c.ref(!0);let b;const M=(ce=B())==null?void 0:ce._context;let o=c.getCurrentInstance();return c.onMounted(()=>{o=c.getCurrentInstance(),Ie(o==null?void 0:o.appContext,u=>{b=u,E.value=!1})}),()=>c.createVNode(c.Transition,c.mergeProps({appear:!0,onEnter:async(u,F)=>{const Q=te(M.app._container);await Le(o==null?void 0:o.appContext,Q,u),p(),r(f),F()},onLeave:async(u,F)=>{P();const Q=te(B()._container);await xe(o==null?void 0:o.appContext,u,Q),b?b():A(),F()},onBeforeEnter:u=>{h==null||h(u),D(o==null?void 0:o.appContext,s.onBeforeEnter),!L(o==null?void 0:o.appContext)&&(w(M,s.onWillDisappear),w(o==null?void 0:o.appContext,s.onWillAppear,!0))},onAfterEnter:u=>{d==null||d(u),D(o==null?void 0:o.appContext,s.onAfterEnter),!L(o==null?void 0:o.appContext)&&(w(M,s.onDidDisappear),w(o==null?void 0:o.appContext,s.onDidAppear,!0),Z(o==null?void 0:o.appContext,M))},onBeforeLeave:u=>{g==null||g(u),D(o==null?void 0:o.appContext,s.onBeforeLeave),!L(o==null?void 0:o.appContext)&&(w(o==null?void 0:o.appContext,s.onWillDisappear),w(B()._context,s.onWillAppear,!1))},onAfterLeave:u=>{C==null||C(u),D(o==null?void 0:o.appContext,s.onAfterLeave),!L(o==null?void 0:o.appContext)&&(w(o==null?void 0:o.appContext,s.onDidDisappear),w(B()._context,s.onDidAppear,!1),Z(o==null?void 0:o.appContext,B()._context))}},_),{default:()=>[E.value?e:null]})}});k==null||k(f),f.mount(i),n===!1&&window.history.pushState(I({index:l.length,session:$}),""),l.push(f)}),Ne=(e,n)=>{const t=B(),r=t==null?void 0:t._context,i=Be(r,T()),p=()=>Ee(r)===i,d=Y(r);if(d===void 0)return Promise.resolve();const{index:C,session:h}=K(),g=C-e+1;for(let _=0;_<e;_++)window.history.pushState(I({index:g+_,session:h}),"");return new Promise(async()=>{const _=()=>{U(n),fe(r,void 0),window.history.go(-e)},f=d();typeof f=="boolean"?f&&p()&&_():await f===!0&&p()&&_()})};let R=!1;const Ve=()=>{R=!0},ae=(e,n=!1)=>{ie(),l.push(e);const t=I({index:0,session:$});n?window.history.replaceState(t,""):window.history.pushState(t,"");const r=async i=>{const p=K();if(!p||i.state.session!==p.session)return;const d=i.state.index-p.index;if(d===0)return;if(d>0)return window.history.go(-d);const C=pe();if(R){R=!1;const h=Math.abs(d),g=l.length-h-1;l.splice(g,h).forEach((f,E,b)=>{G(!1,E===b.length-1,f,C)})}else await Ne(-d,C),l.splice(l.length-Math.abs(d)).forEach((g,_,f)=>{const E=_===f.length-1;G(E,E,g,C)});l.length===0?I():I(window.history.state)};return{add:()=>window.addEventListener("popstate",r),remove:()=>window.removeEventListener("popstate",r)}},se=async(e,n)=>{P();const t=await oe(e,!1,n);return A(),t},re=async(e,n)=>{P();const t=await oe(e,!0,n);return A(),t},S=(e=1)=>(P(),new Promise(n=>{le(T(),n);const t=typeof e=="number"?e:1;window.history.go(-Math.abs(t))})),ze=()=>S(1),qe=e=>e?re:se,Ge=async e=>{Ve(),await S(e)},Re=async()=>{await S(l.length-1)},Fe=c.defineComponent({name:"NavigatorController",setup:(e,{slots:n})=>{const{add:t}=ae(c.getCurrentInstance().appContext.app,!0);return c.onMounted(t),c.onMounted(ee),()=>{var r;return(r=n.default)==null?void 0:r.call(n)}}}),Qe={install(e){const{add:n}=ae(e,!0);n(),ee()}};a.Navigator=Fe,a.back=ze,a.backToHome=Re,a.blackBoxBack=Ge,a.disableBodyPointerEvents=P,a.enableBodyPointerEvents=A,a.getCurrentPageMate=we,a.goBack=S,a.navigation=Qe,a.onDidAppear=ge,a.onDidDisappear=ve,a.onPageAfterEnter=ke,a.onPageAfterLeave=Se,a.onPageBeforeEnter=Me,a.onPageBeforeLeave=Te,a.onPageChange=ye,a.onWillAppear=Ce,a.onWillDisappear=he,a.push=se,a.replace=re,a.to=qe,a.useAppBeforeMount=We,a.useLeaveBefore=ue,a.usePageMate=me,a.useProgressExitAnimated=De,a.useQuietPage=_e,a.useTransitionEnter=Pe,a.useTransitionLeave=Ae,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});