@lazycatcloud/vue-router-stack 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-router-stack.cjs +1 -1
- package/dist/vue-router-stack.js +141 -140
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("vue"),k=require("vue-router"),Y={};function X(e="route"){const a=(Y[e]??0)+1;return Y[e]=a,`${e}-${a}`}const Q="slide",oe="cubic-bezier(0.3, 0, 0.66, 1)";function ne(e){return e}const ae=({direction:e})=>e==="back"?{leaving:[{transform:"translateX(0)"},{transform:"translateX(100%)"}]}:{entering:[{transform:"translateX(100%)"},{transform:"translateX(0)"}]},ce=()=>({entering:[{opacity:0},{opacity:1}],leaving:[{opacity:1},{opacity:0}]}),ie=({direction:e})=>{const a=e==="back";return{entering:a?[{transform:"scale(0.98)",opacity:0},{transform:"scale(1)",opacity:1}]:[{transform:"scale(1.04)",opacity:0},{transform:"scale(1)",opacity:1}],leaving:a?[{transform:"scale(1)",opacity:1},{transform:"scale(1.04)",opacity:0}]:[{transform:"scale(1)",opacity:1},{transform:"scale(0.98)",opacity:0}]}},se=()=>({}),ue={slide:ae,fade:ce,scale:ie,none:se};function le(e,a){const c=a[e];return c||a[Q]}function Z(e,a,c){if(!a||!e.animate||Number(c.duration)<=0)return Promise.resolve();const l=e.animate(a,c);return l.finished.then(()=>l.cancel())}async function de(e,a){const c=e(a),l={duration:a.duration,easing:a.easing,fill:"both",...c.options};await Promise.all([Z(a.enteringElement,c.entering,l),Z(a.leavingElement,c.leaving,l)])}const C=Symbol("stack-router");function fe(){const e=window.history.state;return typeof(e==null?void 0:e.position)=="number"?e.position:window.history.length}function q(e,a){return a||(e==="pop"?"back":e==="replace"?"none":"forward")}function he(e){const a=k.createRouter(e),c=[],l=u.shallowRef(),f=e.transitionDuration??210,g=e.transitionEasing??oe,w=e.transition??Q,y={...ue,...e.transitions},P=e.maxStackSize??30;let h=-1,s,E=!1;const b=(n,r,i,d,m=!1,R="stack")=>{s={action:n,direction:q(n,r),source:R,delta:i,reuse:d==null?void 0:d.reuse,transition:d==null?void 0:d.transition,duration:d==null?void 0:d.duration,easing:d==null?void 0:d.easing,resetRoot:m}},K=(n,r)=>{const i=(s==null?void 0:s.action)??"push",d=q(i,s==null?void 0:s.direction),m=l.value,R=i==="push"&&d==="forward",M=T(n);return{id:X("route"),key:n.fullPath,fullPath:n.fullPath,pathname:n.path,params:n.params,query:n.query,action:i,direction:d,reuse:(s==null?void 0:s.reuse)??!1,source:(s==null?void 0:s.source)??"stack",entryDirection:d,lastPathname:(m==null?void 0:m.pathname)||(r.name?r.path:void 0),pushedByRoute:R?m==null?void 0:m.pathname:m==null?void 0:m.pushedByRoute,position:fe(),delta:s==null?void 0:s.delta,transition:(s==null?void 0:s.transition)??w,transitionDuration:(s==null?void 0:s.duration)??f,transitionEasing:(s==null?void 0:s.easing)??g,cache:M}},T=n=>{const r=n.meta.stack;return n.meta.stackCache!==!1&&(r==null?void 0:r.cache)!==!1},W=()=>{if(P<=0||c.length<=P)return;const n=c.length-P;c.splice(0,n),h=Math.max(0,h-n)},G=n=>{if(n.action==="pop"){let r=-1;if(n.direction==="forward"||(n.delta??0)>0){for(let i=h+1;i<c.length;i++)if(c[i].key===n.key){r=i;break}}else for(let i=h-1;i>=0;i--)if(c[i].key===n.key){r=i;break}if(r>=0){const i=c[r];c[r]={...i,...n,id:i.id,reuse:i.reuse,source:n.source,entryDirection:i.entryDirection,transition:i.transition,transitionDuration:i.transitionDuration,transitionEasing:i.transitionEasing},h=r}else c.push({...n,direction:"none",entryDirection:"none",transition:"none",isStackFallback:!0}),h=c.length-1}else if(n.action==="replace"){if(s!=null&&s.resetRoot){c.splice(0,c.length,n),h=0,l.value=c[h];return}h>=0?c[h]=n:(c.push(n),h=0)}else h<c.length-1&&c.splice(h+1),c.push(n),h=c.length-1;W(),l.value=c[h]};e.history.listen((n,r,i)=>{const d="delta"in i?i.delta:void 0,m=i.direction==="back"?"back":i.direction==="forward"?"forward":void 0;s?(s.delta=d,s.direction=q(s.action,s.direction??m)):b(i.type==="pop"?"pop":i.type,m,d,void 0,!1,"external")}),a.beforeEach(n=>!((s==null?void 0:s.action)==="pop"&&E&&!c.some(r=>r.fullPath===n.fullPath))),a.afterEach((n,r,i)=>{if(i){s=void 0;return}G(K(n,r)),s=void 0});const L=a.push.bind(a),I=a.replace.bind(a),$=a.back.bind(a),x=a.forward.bind(a),z=a.go.bind(a),A=(n,r)=>(b("push",(r==null?void 0:r.direction)??"forward",void 0,r),L(n)),j=(n,r)=>(b("replace",(r==null?void 0:r.direction)??"root",void 0,r),I(n)),B=(n,r)=>{const i=a.resolve(n).fullPath;let d=-1;for(let R=h;R>=0;R--)if(c[R].fullPath===i){d=R;break}if(d<0)return!1;const m=d-h;return m===0||(b("pop",(r==null?void 0:r.direction)??"back",m,r),z(m)),!0},V=(n,r)=>{const i=a.resolve(n).fullPath;if(h>=0&&a.currentRoute.value.fullPath===i){const d=c[h],m={...d,id:X("route"),action:"replace",direction:(r==null?void 0:r.direction)??"root",source:"stack",entryDirection:(r==null?void 0:r.direction)??"root",delta:void 0,reuse:(r==null?void 0:r.reuse)??d.reuse,transition:(r==null?void 0:r.transition)??d.transition,transitionDuration:(r==null?void 0:r.duration)??d.transitionDuration,transitionEasing:(r==null?void 0:r.easing)??d.transitionEasing,cache:!0,isStackFallback:!1};return c.splice(0,c.length,m),h=0,E=!0,l.value=m,Promise.resolve(void 0)}return b("replace",(r==null?void 0:r.direction)??"root",void 0,r,!0),E=!0,I(n)},_=()=>{b("pop","back",-1),$()},H=()=>{b("pop","forward",1),x()},p=a;p.push=A,p.replace=j,p.popTo=B,p.resetRoot=V,p.back=_,p.forward=H;const t={router:p,transitionDuration:f,transitionEasing:g,transition:w,transitions:y,maxStackSize:P,shouldTransition:e.shouldTransition,current:l,get history(){return c},canGoBack:(n=1)=>h-n>=0,push:A,replace:j,popTo:B,resetRoot:V,back:_,forward:H},o=a.install.bind(a);return a.install=n=>{n.provide(C,t),o(n)},p}const v="onPageWillEnter",J="onPageDidEnter",N="onPageWillLeave",O="onPageDidLeave";function me(e,a,c){if(!c)throw new Error(`${e} must be called inside setup().`);const l=c.proxy,f=l[e]??[];f.push(()=>{c.isUnmounted||a()}),l[e]=f,c.exposed&&(c.exposed[e]=f)}function F(e){return(a,c=u.getCurrentInstance())=>me(e,a,c)}const ye=F(v),ke=F(J),Re=F(N),be=F(O);function pe(){const e=u.inject(C);if(!e)throw new Error("useStackRouter must be used after createStackRouter().");return{router:e.router,canGoBack:e.canGoBack,push:e.push,replace:e.replace,popTo:e.popTo,resetRoot:e.resetRoot,back:e.back,forward:e.forward}}function ee(){const e=u.inject(C);if(!e)throw new Error("RouterOutlet must be used with createStackRouter().");return e}function S(e,a){const c=e.value;if(!c)return;const l=c[a];Array.isArray(l)?l.forEach(f=>f()):typeof l=="function"&&l.call(c)}function D(e){e.classList.remove("rs-page-hidden","rs-page-invisible"),e.removeAttribute("aria-hidden")}function U(e){e.classList.add("rs-page-hidden"),e.setAttribute("aria-hidden","true")}function te(e){var a;return(a=e.components)==null?void 0:a.default}function Pe(e){const a=te(e);return a!==void 0&&typeof a=="object"&&"name"in a&&a.name==="RouterView"}const we=u.defineComponent({name:"RouterOutlet",setup(){const e=ee(),a=k.useRoute(),c=u.inject(k.routeLocationKey),l=u.inject(k.matchedRouteKey,void 0),f=u.computed(()=>{const t=l==null?void 0:l.value;if(!t)return 0;const o=a.matched.findIndex(n=>n===t);return o>=0?o+1:0}),g=u.computed(()=>a.matched[f.value]),w=u.computed(()=>{for(let t=f.value;t<a.matched.length;t++){const o=a.matched[t];if(!Pe(o))return o}return g.value}),y=u.shallowRef([]),P=u.ref("");let h=0;u.provide(k.matchedRouteKey,w);const s=t=>y.value.find(o=>o.id===t),E=t=>y.value.find(o=>o.routeIds.has(t)),b=t=>y.value.find(o=>o.routeKey===t),K=t=>t.action==="push"&&t.direction==="forward"&&!t.reuse&&y.value.some(o=>o.routeKey===t.key),T=t=>{y.value.forEach(o=>{o.pageElement&&(o===t?D(o.pageElement):U(o.pageElement))})},W=t=>{const o=e.history.findIndex(r=>r.id===t.routeInfo.id);if(o<0)return;const n=new Set(e.history.slice(0,o+1).map(r=>r.id));y.value.forEach(r=>{r.routeIds=new Set([...r.routeIds].filter(i=>n.has(i)))}),y.value=y.value.filter(r=>r===t||r.routeIds.size>0)},G=t=>{y.value=y.value.filter(o=>o!==t)},L=t=>{const o=new Set(e.history.map(n=>n.id));y.value.forEach(n=>{n.routeIds=new Set([...n.routeIds].filter(r=>o.has(r)))}),y.value=y.value.filter(n=>n===t||n.routeInfo.cache&&n.routeIds.size>0)},I=t=>{var n;const o=t.props.default;return o?o===!0?((n=e.current.value)==null?void 0:n.params)??{}:typeof o=="function"?o(c):o:{}},$=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,x=t=>t.entryDirection==="none"||t.entryDirection==="root"||t.transition==="none",z=(t,o)=>t.routeInfo.direction==="forward"?x(t.routeInfo):x(o.routeInfo),A=(t,o)=>!(t.routeInfo.isStackFallback||t.routeInfo.direction==="none"||t.routeInfo.direction==="root"||t.routeInfo.action==="pop"&&z(t,o)),j=(t,o)=>{var r;const n=A(t,o);return((r=e.shouldTransition)==null?void 0:r.call(e,{action:t.routeInfo.action,direction:t.routeInfo.direction,source:t.routeInfo.source,entering:t.routeInfo,leaving:o.routeInfo,defaultResult:n}))??n},B=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transitionDuration??t.routeInfo.transitionDuration??e.transitionDuration:t.routeInfo.transitionDuration??e.transitionDuration,V=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transitionEasing??t.routeInfo.transitionEasing??e.transitionEasing:t.routeInfo.transitionEasing??e.transitionEasing,_=async(t,o)=>{const n=++h;await u.nextTick();const r=t.pageElement;if(!r)return;if(S(t.componentRef,v),!o||o===t||!o.pageElement){D(r),S(t.componentRef,J),L(t),T(t);return}const i=o.pageElement,d=j(t,o),m=d?$(t,o):"none",R=d?B(t,o):0,M=V(t,o),re=le(m||Q,e.transitions);S(o.componentRef,N),D(r),D(i),await de(re,{direction:t.routeInfo.direction,action:t.routeInfo.action,routeInfo:t.routeInfo,enteringElement:r,leavingElement:i,duration:R,easing:M}),n===h&&(U(i),S(o.componentRef,O),S(t.componentRef,J),t.routeInfo.action==="pop"?W(t):t.routeInfo.action==="replace"&&G(o),L(t),T(t))},H=async()=>{const t=w.value,o=e.current.value;if(!t||!o)return;const n=te(t);if(!n)return;const r=s(P.value);let i=E(o.id);!i&&!K(o)&&(i=b(o.key)),i?(i.routeIds.add(o.id),i.routeKey=o.key,i.routeInfo=o,i.matchedRoute=t,i.component=n,i.props=I(t),i.mounted=!0):(i={id:X("view"),routeKey:o.key,routeIds:new Set([o.id]),routeInfo:o,matchedRoute:t,component:n,props:I(t),componentRef:u.ref(),mounted:!0},y.value=[...y.value,i]),P.value=i.id,await _(i,r)};return u.watch(()=>{var t;return[(t=e.current.value)==null?void 0:t.id,w.value]},()=>{H()},{immediate:!0}),u.onUnmounted(()=>{h++,y.value=[]}),{injectedRoute:c,viewItems:y,registerStackPage:(t,o)=>{t.pageElement=o,t.id===P.value?D(o):U(o)}}},render(){return u.h("div",{class:"rs-outlet"},this.viewItems.filter(e=>e.mounted).map(e=>u.h(e.component,{key:e.id,ref:e.componentRef,...e.props,registerStackPage:a=>this.registerStackPage(e,a)})))}}),Ee=u.defineComponent({name:"RouterPage",props:{registerStackPage:{type:Function,default:void 0}},setup(e,{attrs:a,slots:c}){const l=u.ref();return u.onMounted(()=>{var f;l.value&&((f=e.registerStackPage)==null||f.call(e,l.value))}),()=>{var f;return u.h("section",{...a,ref:l,class:["rs-page",a.class]},(f=c.default)==null?void 0:f.call(c))}}}),Ie=u.defineComponent({name:"StackRouterDebugPanel",props:{initialOpen:{type:Boolean,default:!1}},setup(e){const a=ee(),c=u.ref(e.initialOpen);return()=>{const l=a.current.value;return u.h("aside",{class:"rs-debug-panel"},[u.h("button",{class:"rs-debug-toggle",type:"button",onClick:()=>{c.value=!c.value}},c.value?"Stack x":"Stack"),c.value?u.h("section",{class:"rs-debug-body"},[u.h("header",[u.h("strong","Router Stack"),u.h("span",`${a.history.length} pages`)]),u.h("dl",[u.h("dt","current"),u.h("dd",(l==null?void 0:l.fullPath)??"-"),u.h("dt","canGoBack"),u.h("dd",String(a.canGoBack()))]),u.h("ol",a.history.map(f=>u.h("li",{key:f.id,class:{"rs-debug-active":f.id===(l==null?void 0:l.id),"rs-debug-no-cache":!f.cache}},[u.h("code",f.fullPath),u.h("span",[`${f.action}/${f.direction}`,` source:${f.source}`,` entry:${f.entryDirection}`,` cache:${f.cache?"yes":"no"}`,` transition:${f.transition??"-"}`])])))]):void 0])}}});Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>k.RouterLink});Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>k.RouterView});Object.defineProperty(exports,"createMemoryHistory",{enumerable:!0,get:()=>k.createMemoryHistory});Object.defineProperty(exports,"createWebHashHistory",{enumerable:!0,get:()=>k.createWebHashHistory});Object.defineProperty(exports,"createWebHistory",{enumerable:!0,get:()=>k.createWebHistory});Object.defineProperty(exports,"useRoute",{enumerable:!0,get:()=>k.useRoute});Object.defineProperty(exports,"useRouter",{enumerable:!0,get:()=>k.useRouter});exports.RouterOutlet=we;exports.RouterPage=Ee;exports.StackRouterDebugPanel=Ie;exports.createStackRouter=he;exports.defineStackTransition=ne;exports.onPageDidEnter=ke;exports.onPageDidLeave=be;exports.onPageWillEnter=ye;exports.onPageWillLeave=Re;exports.stackRouterKey=C;exports.useStackRouter=pe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("vue"),k=require("vue-router"),Y={};function X(e="route"){const o=(Y[e]??0)+1;return Y[e]=o,`${e}-${o}`}const Q="slide",oe="cubic-bezier(0.3, 0, 0.66, 1)";function ne(e){return e}const ae=({direction:e})=>e==="back"?{leaving:[{transform:"translateX(0)"},{transform:"translateX(100%)"}]}:{entering:[{transform:"translateX(100%)"},{transform:"translateX(0)"}]},ce=()=>({entering:[{opacity:0},{opacity:1}],leaving:[{opacity:1},{opacity:0}]}),ie=({direction:e})=>{const o=e==="back";return{entering:o?[{transform:"scale(0.98)",opacity:0},{transform:"scale(1)",opacity:1}]:[{transform:"scale(1.04)",opacity:0},{transform:"scale(1)",opacity:1}],leaving:o?[{transform:"scale(1)",opacity:1},{transform:"scale(1.04)",opacity:0}]:[{transform:"scale(1)",opacity:1},{transform:"scale(0.98)",opacity:0}]}},se=()=>({}),ue={slide:ae,fade:ce,scale:ie,none:se};function le(e,o){const c=o[e];return c||o[Q]}function Z(e,o,c){if(!o||!e.animate||Number(c.duration)<=0)return Promise.resolve();const l=e.animate(o,c);return l.finished.then(()=>l.cancel())}async function de(e,o){const c=e(o),l={duration:o.duration,easing:o.easing,fill:"both",...c.options};await Promise.all([Z(o.enteringElement,c.entering,l),Z(o.leavingElement,c.leaving,l)])}const C=Symbol("stack-router");function fe(){const e=window.history.state;return typeof(e==null?void 0:e.position)=="number"?e.position:window.history.length}function q(e,o){return o||(e==="pop"?"back":e==="replace"?"none":"forward")}function he(e){const o=k.createRouter(e),c=[],l=u.shallowRef(),f=e.transitionDuration??210,T=e.transitionEasing??oe,w=e.transition??Q,y={...ue,...e.transitions},P=e.maxStackSize??30;let h=-1,s,E=!1;const b=(a,r,i,d,m=!1,R="stack")=>{s={action:a,direction:q(a,r),source:R,delta:i,reuse:d==null?void 0:d.reuse,transition:d==null?void 0:d.transition,duration:d==null?void 0:d.duration,easing:d==null?void 0:d.easing,resetRoot:m}},K=(a,r)=>{const i=(s==null?void 0:s.action)??"push",d=q(i,s==null?void 0:s.direction),m=l.value,R=i==="push"&&d==="forward",M=g(a);return{id:X("route"),key:a.fullPath,fullPath:a.fullPath,pathname:a.path,params:a.params,query:a.query,action:i,direction:d,reuse:(s==null?void 0:s.reuse)??!1,source:(s==null?void 0:s.source)??"stack",entryDirection:d,lastPathname:(m==null?void 0:m.pathname)||(r.name?r.path:void 0),pushedByRoute:R?m==null?void 0:m.pathname:m==null?void 0:m.pushedByRoute,position:fe(),delta:s==null?void 0:s.delta,transition:(s==null?void 0:s.transition)??w,transitionDuration:(s==null?void 0:s.duration)??f,transitionEasing:(s==null?void 0:s.easing)??T,cache:M}},g=a=>{const r=a.meta.stack;return a.meta.stackCache!==!1&&(r==null?void 0:r.cache)!==!1},W=()=>{if(P<=0||c.length<=P)return;const a=c.length-P;c.splice(0,a),h=Math.max(0,h-a)},G=a=>{if(a.action==="pop"){let r=-1;if(a.direction==="forward"||(a.delta??0)>0){for(let i=h+1;i<c.length;i++)if(c[i].key===a.key){r=i;break}}else for(let i=h-1;i>=0;i--)if(c[i].key===a.key){r=i;break}if(r>=0){const i=c[r];c[r]={...i,...a,id:i.id,reuse:i.reuse,source:a.source,entryDirection:i.entryDirection,transition:i.transition,transitionDuration:i.transitionDuration,transitionEasing:i.transitionEasing},h=r}else c.push({...a,direction:"none",entryDirection:"none",transition:"none",isStackFallback:!0}),h=c.length-1}else if(a.action==="replace"){if(s!=null&&s.resetRoot){c.splice(0,c.length,a),h=0,l.value=c[h];return}h>=0?c[h]=a:(c.push(a),h=0)}else h<c.length-1&&c.splice(h+1),c.push(a),h=c.length-1;W(),l.value=c[h]};e.history.listen((a,r,i)=>{const d="delta"in i?i.delta:void 0,m=i.direction==="back"?"back":i.direction==="forward"?"forward":void 0;s?(s.delta=d,s.direction=q(s.action,s.direction??m)):b(i.type==="pop"?"pop":i.type,m,d,void 0,!1,"external")}),o.beforeEach(a=>!((s==null?void 0:s.action)==="pop"&&E&&!c.some(r=>r.fullPath===a.fullPath))),o.afterEach((a,r,i)=>{if(i){s=void 0;return}G(K(a,r)),s=void 0});const L=o.push.bind(o),I=o.replace.bind(o),$=o.back.bind(o),x=o.forward.bind(o),z=o.go.bind(o),A=(a,r)=>(b("push",(r==null?void 0:r.direction)??"forward",void 0,r),L(a)),j=(a,r)=>(b("replace",(r==null?void 0:r.direction)??"root",void 0,r),I(a)),B=(a,r)=>{const i=o.resolve(a).fullPath;let d=-1;for(let R=h;R>=0;R--)if(c[R].fullPath===i){d=R;break}if(d<0)return!1;const m=d-h;return m===0||(b("pop",(r==null?void 0:r.direction)??"back",m,r),z(m)),!0},H=(a,r)=>{const i=o.resolve(a).fullPath;if(h>=0&&o.currentRoute.value.fullPath===i){const d=c[h],m={...d,id:X("route"),action:"replace",direction:(r==null?void 0:r.direction)??"root",source:"stack",entryDirection:(r==null?void 0:r.direction)??"root",delta:void 0,reuse:(r==null?void 0:r.reuse)??d.reuse,transition:(r==null?void 0:r.transition)??d.transition,transitionDuration:(r==null?void 0:r.duration)??d.transitionDuration,transitionEasing:(r==null?void 0:r.easing)??d.transitionEasing,cache:!0,isStackFallback:!1};return c.splice(0,c.length,m),h=0,E=!0,l.value=m,Promise.resolve(void 0)}return b("replace",(r==null?void 0:r.direction)??"root",void 0,r,!0),E=!0,I(a)},V=()=>{b("pop","back",-1),$()},_=()=>{b("pop","forward",1),x()},p=o;p.push=A,p.replace=j,p.popTo=B,p.resetRoot=H,p.back=V,p.forward=_;const t={router:p,transitionDuration:f,transitionEasing:T,transition:w,transitions:y,maxStackSize:P,shouldTransition:e.shouldTransition,current:l,get history(){return c},canGoBack:(a=1)=>h-a>=0,push:A,replace:j,popTo:B,resetRoot:H,back:V,forward:_},n=o.install.bind(o);return o.install=a=>{a.provide(C,t),n(a)},p}const v="onPageWillEnter",J="onPageDidEnter",N="onPageWillLeave",O="onPageDidLeave";function me(e,o,c){if(!c)throw new Error(`${e} must be called inside setup().`);const l=c.proxy,f=l[e]??[];f.push(()=>{c.isUnmounted||o()}),l[e]=f,c.exposed&&(c.exposed[e]=f)}function F(e){return(o,c=u.getCurrentInstance())=>me(e,o,c)}const ye=F(v),ke=F(J),Re=F(N),be=F(O);function pe(){const e=u.inject(C);if(!e)throw new Error("useStackRouter must be used after createStackRouter().");return{router:e.router,canGoBack:e.canGoBack,push:e.push,replace:e.replace,popTo:e.popTo,resetRoot:e.resetRoot,back:e.back,forward:e.forward}}function ee(){const e=u.inject(C);if(!e)throw new Error("RouterOutlet must be used with createStackRouter().");return e}function S(e,o){const c=e.value;if(!c)return;const l=c[o];Array.isArray(l)?l.forEach(f=>f()):typeof l=="function"&&l.call(c)}function D(e){e.classList.remove("rs-page-hidden","rs-page-invisible"),e.removeAttribute("aria-hidden")}function U(e){const o=e.ownerDocument.activeElement;o instanceof HTMLElement&&e.contains(o)&&o.blur(),e.classList.add("rs-page-hidden"),e.setAttribute("aria-hidden","true")}function te(e){var o;return(o=e.components)==null?void 0:o.default}function Pe(e){const o=te(e);return o!==void 0&&typeof o=="object"&&"name"in o&&o.name==="RouterView"}const we=u.defineComponent({name:"RouterOutlet",setup(){const e=ee(),o=k.useRoute(),c=u.inject(k.routeLocationKey),l=u.inject(k.matchedRouteKey,void 0),f=u.computed(()=>{const t=l==null?void 0:l.value;if(!t)return 0;const n=o.matched.findIndex(a=>a===t);return n>=0?n+1:0}),T=u.computed(()=>o.matched[f.value]),w=u.computed(()=>{for(let t=f.value;t<o.matched.length;t++){const n=o.matched[t];if(!Pe(n))return n}return T.value}),y=u.shallowRef([]),P=u.ref("");let h=0;u.provide(k.matchedRouteKey,w);const s=t=>y.value.find(n=>n.id===t),E=t=>y.value.find(n=>n.routeIds.has(t)),b=t=>y.value.find(n=>n.routeKey===t),K=t=>t.action==="push"&&t.direction==="forward"&&!t.reuse&&y.value.some(n=>n.routeKey===t.key),g=t=>{y.value.forEach(n=>{n.pageElement&&(n===t?D(n.pageElement):U(n.pageElement))})},W=t=>{const n=e.history.findIndex(r=>r.id===t.routeInfo.id);if(n<0)return;const a=new Set(e.history.slice(0,n+1).map(r=>r.id));y.value.forEach(r=>{r.routeIds=new Set([...r.routeIds].filter(i=>a.has(i)))}),y.value=y.value.filter(r=>r===t||r.routeIds.size>0)},G=t=>{y.value=y.value.filter(n=>n!==t)},L=t=>{const n=new Set(e.history.map(a=>a.id));y.value.forEach(a=>{a.routeIds=new Set([...a.routeIds].filter(r=>n.has(r)))}),y.value=y.value.filter(a=>a===t||a.routeInfo.cache&&a.routeIds.size>0)},I=t=>{var a;const n=t.props.default;return n?n===!0?((a=e.current.value)==null?void 0:a.params)??{}:typeof n=="function"?n(c):n:{}},$=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,x=t=>t.entryDirection==="none"||t.entryDirection==="root"||t.transition==="none",z=(t,n)=>t.routeInfo.direction==="forward"?x(t.routeInfo):x(n.routeInfo),A=(t,n)=>!(t.routeInfo.isStackFallback||t.routeInfo.direction==="none"||t.routeInfo.direction==="root"||t.routeInfo.action==="pop"&&z(t,n)),j=(t,n)=>{var r;const a=A(t,n);return((r=e.shouldTransition)==null?void 0:r.call(e,{action:t.routeInfo.action,direction:t.routeInfo.direction,source:t.routeInfo.source,entering:t.routeInfo,leaving:n.routeInfo,defaultResult:a}))??a},B=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transitionDuration??t.routeInfo.transitionDuration??e.transitionDuration:t.routeInfo.transitionDuration??e.transitionDuration,H=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transitionEasing??t.routeInfo.transitionEasing??e.transitionEasing:t.routeInfo.transitionEasing??e.transitionEasing,V=async(t,n)=>{const a=++h;await u.nextTick();const r=t.pageElement;if(!r)return;if(S(t.componentRef,v),!n||n===t||!n.pageElement){D(r),S(t.componentRef,J),L(t),g(t);return}const i=n.pageElement,d=j(t,n),m=d?$(t,n):"none",R=d?B(t,n):0,M=H(t,n),re=le(m||Q,e.transitions);S(n.componentRef,N),D(r),D(i),await de(re,{direction:t.routeInfo.direction,action:t.routeInfo.action,routeInfo:t.routeInfo,enteringElement:r,leavingElement:i,duration:R,easing:M}),a===h&&(U(i),S(n.componentRef,O),S(t.componentRef,J),t.routeInfo.action==="pop"?W(t):t.routeInfo.action==="replace"&&G(n),L(t),g(t))},_=async()=>{const t=w.value,n=e.current.value;if(!t||!n)return;const a=te(t);if(!a)return;const r=s(P.value);let i=E(n.id);!i&&!K(n)&&(i=b(n.key)),i?(i.routeIds.add(n.id),i.routeKey=n.key,i.routeInfo=n,i.matchedRoute=t,i.component=a,i.props=I(t),i.mounted=!0):(i={id:X("view"),routeKey:n.key,routeIds:new Set([n.id]),routeInfo:n,matchedRoute:t,component:a,props:I(t),componentRef:u.ref(),mounted:!0},y.value=[...y.value,i]),P.value=i.id,await V(i,r)};return u.watch(()=>{var t;return[(t=e.current.value)==null?void 0:t.id,w.value]},()=>{_()},{immediate:!0}),u.onUnmounted(()=>{h++,y.value=[]}),{injectedRoute:c,viewItems:y,registerStackPage:(t,n)=>{t.pageElement=n,t.id===P.value?D(n):U(n)}}},render(){return u.h("div",{class:"rs-outlet"},this.viewItems.filter(e=>e.mounted).map(e=>u.h(e.component,{key:e.id,ref:e.componentRef,...e.props,registerStackPage:o=>this.registerStackPage(e,o)})))}}),Ee=u.defineComponent({name:"RouterPage",props:{registerStackPage:{type:Function,default:void 0}},setup(e,{attrs:o,slots:c}){const l=u.ref();return u.onMounted(()=>{var f;l.value&&((f=e.registerStackPage)==null||f.call(e,l.value))}),()=>{var f;return u.h("section",{...o,ref:l,class:["rs-page",o.class]},(f=c.default)==null?void 0:f.call(c))}}}),Ie=u.defineComponent({name:"StackRouterDebugPanel",props:{initialOpen:{type:Boolean,default:!1}},setup(e){const o=ee(),c=u.ref(e.initialOpen);return()=>{const l=o.current.value;return u.h("aside",{class:"rs-debug-panel"},[u.h("button",{class:"rs-debug-toggle",type:"button",onClick:()=>{c.value=!c.value}},c.value?"Stack x":"Stack"),c.value?u.h("section",{class:"rs-debug-body"},[u.h("header",[u.h("strong","Router Stack"),u.h("span",`${o.history.length} pages`)]),u.h("dl",[u.h("dt","current"),u.h("dd",(l==null?void 0:l.fullPath)??"-"),u.h("dt","canGoBack"),u.h("dd",String(o.canGoBack()))]),u.h("ol",o.history.map(f=>u.h("li",{key:f.id,class:{"rs-debug-active":f.id===(l==null?void 0:l.id),"rs-debug-no-cache":!f.cache}},[u.h("code",f.fullPath),u.h("span",[`${f.action}/${f.direction}`,` source:${f.source}`,` entry:${f.entryDirection}`,` cache:${f.cache?"yes":"no"}`,` transition:${f.transition??"-"}`])])))]):void 0])}}});Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>k.RouterLink});Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>k.RouterView});Object.defineProperty(exports,"createMemoryHistory",{enumerable:!0,get:()=>k.createMemoryHistory});Object.defineProperty(exports,"createWebHashHistory",{enumerable:!0,get:()=>k.createWebHashHistory});Object.defineProperty(exports,"createWebHistory",{enumerable:!0,get:()=>k.createWebHistory});Object.defineProperty(exports,"useRoute",{enumerable:!0,get:()=>k.useRoute});Object.defineProperty(exports,"useRouter",{enumerable:!0,get:()=>k.useRouter});exports.RouterOutlet=we;exports.RouterPage=Ee;exports.StackRouterDebugPanel=Ie;exports.createStackRouter=he;exports.defineStackTransition=ne;exports.onPageDidEnter=ke;exports.onPageDidLeave=be;exports.onPageWillEnter=ye;exports.onPageWillLeave=Re;exports.stackRouterKey=C;exports.useStackRouter=pe;
|
package/dist/vue-router-stack.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { shallowRef as te, getCurrentInstance as ie, inject as C, defineComponent as Y, h as y, computed as
|
|
1
|
+
import { shallowRef as te, getCurrentInstance as ie, inject as C, defineComponent as Y, h as y, computed as U, ref as G, provide as ue, watch as le, onUnmounted as de, nextTick as fe, onMounted as he } from "vue";
|
|
2
2
|
import { createRouter as me, useRoute as ye, routeLocationKey as ke, matchedRouteKey as v } from "vue-router";
|
|
3
|
-
import { RouterLink as je, RouterView as
|
|
3
|
+
import { RouterLink as je, RouterView as Me, createMemoryHistory as Ue, createWebHashHistory as Xe, createWebHistory as qe, useRoute as Je, useRouter as Qe } from "vue-router";
|
|
4
4
|
const O = {};
|
|
5
5
|
function J(e = "route") {
|
|
6
|
-
const
|
|
7
|
-
return O[e] =
|
|
6
|
+
const o = (O[e] ?? 0) + 1;
|
|
7
|
+
return O[e] = o, `${e}-${o}`;
|
|
8
8
|
}
|
|
9
9
|
const Z = "slide", Re = "cubic-bezier(0.3, 0, 0.66, 1)";
|
|
10
10
|
function Ae(e) {
|
|
@@ -24,16 +24,16 @@ const pe = ({ direction: e }) => e === "back" ? {
|
|
|
24
24
|
entering: [{ opacity: 0 }, { opacity: 1 }],
|
|
25
25
|
leaving: [{ opacity: 1 }, { opacity: 0 }]
|
|
26
26
|
}), Ee = ({ direction: e }) => {
|
|
27
|
-
const
|
|
27
|
+
const o = e === "back";
|
|
28
28
|
return {
|
|
29
|
-
entering:
|
|
29
|
+
entering: o ? [
|
|
30
30
|
{ transform: "scale(0.98)", opacity: 0 },
|
|
31
31
|
{ transform: "scale(1)", opacity: 1 }
|
|
32
32
|
] : [
|
|
33
33
|
{ transform: "scale(1.04)", opacity: 0 },
|
|
34
34
|
{ transform: "scale(1)", opacity: 1 }
|
|
35
35
|
],
|
|
36
|
-
leaving:
|
|
36
|
+
leaving: o ? [
|
|
37
37
|
{ transform: "scale(1)", opacity: 1 },
|
|
38
38
|
{ transform: "scale(1.04)", opacity: 0 }
|
|
39
39
|
] : [
|
|
@@ -47,26 +47,26 @@ const pe = ({ direction: e }) => e === "back" ? {
|
|
|
47
47
|
scale: Ee,
|
|
48
48
|
none: be
|
|
49
49
|
};
|
|
50
|
-
function Pe(e,
|
|
51
|
-
const c =
|
|
52
|
-
return c ||
|
|
50
|
+
function Pe(e, o) {
|
|
51
|
+
const c = o[e];
|
|
52
|
+
return c || o[Z];
|
|
53
53
|
}
|
|
54
|
-
function ee(e,
|
|
55
|
-
if (!
|
|
54
|
+
function ee(e, o, c) {
|
|
55
|
+
if (!o || !e.animate || Number(c.duration) <= 0)
|
|
56
56
|
return Promise.resolve();
|
|
57
|
-
const u = e.animate(
|
|
57
|
+
const u = e.animate(o, c);
|
|
58
58
|
return u.finished.then(() => u.cancel());
|
|
59
59
|
}
|
|
60
|
-
async function Se(e,
|
|
61
|
-
const c = e(
|
|
62
|
-
duration:
|
|
63
|
-
easing:
|
|
60
|
+
async function Se(e, o) {
|
|
61
|
+
const c = e(o), u = {
|
|
62
|
+
duration: o.duration,
|
|
63
|
+
easing: o.easing,
|
|
64
64
|
fill: "both",
|
|
65
65
|
...c.options
|
|
66
66
|
};
|
|
67
67
|
await Promise.all([
|
|
68
|
-
ee(
|
|
69
|
-
ee(
|
|
68
|
+
ee(o.enteringElement, c.entering, u),
|
|
69
|
+
ee(o.leavingElement, c.leaving, u)
|
|
70
70
|
]);
|
|
71
71
|
}
|
|
72
72
|
const N = Symbol("stack-router");
|
|
@@ -74,19 +74,19 @@ function De() {
|
|
|
74
74
|
const e = window.history.state;
|
|
75
75
|
return typeof (e == null ? void 0 : e.position) == "number" ? e.position : window.history.length;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
77
|
+
function X(e, o) {
|
|
78
|
+
return o || (e === "pop" ? "back" : e === "replace" ? "none" : "forward");
|
|
79
79
|
}
|
|
80
80
|
function Be(e) {
|
|
81
|
-
const
|
|
81
|
+
const o = me(e), c = [], u = te(), d = e.transitionDuration ?? 210, D = e.transitionEasing ?? Re, E = e.transition ?? Z, m = {
|
|
82
82
|
...Ie,
|
|
83
83
|
...e.transitions
|
|
84
84
|
}, w = e.maxStackSize ?? 30;
|
|
85
85
|
let f = -1, i, b = !1;
|
|
86
|
-
const R = (
|
|
86
|
+
const R = (a, r, s, l, h = !1, k = "stack") => {
|
|
87
87
|
i = {
|
|
88
|
-
action:
|
|
89
|
-
direction:
|
|
88
|
+
action: a,
|
|
89
|
+
direction: X(a, r),
|
|
90
90
|
source: k,
|
|
91
91
|
delta: s,
|
|
92
92
|
reuse: l == null ? void 0 : l.reuse,
|
|
@@ -95,15 +95,15 @@ function Be(e) {
|
|
|
95
95
|
easing: l == null ? void 0 : l.easing,
|
|
96
96
|
resetRoot: h
|
|
97
97
|
};
|
|
98
|
-
}, K = (
|
|
99
|
-
const s = (i == null ? void 0 : i.action) ?? "push", l =
|
|
98
|
+
}, K = (a, r) => {
|
|
99
|
+
const s = (i == null ? void 0 : i.action) ?? "push", l = X(s, i == null ? void 0 : i.direction), h = u.value, k = s === "push" && l === "forward", M = T(a);
|
|
100
100
|
return {
|
|
101
101
|
id: J("route"),
|
|
102
|
-
key:
|
|
103
|
-
fullPath:
|
|
104
|
-
pathname:
|
|
105
|
-
params:
|
|
106
|
-
query:
|
|
102
|
+
key: a.fullPath,
|
|
103
|
+
fullPath: a.fullPath,
|
|
104
|
+
pathname: a.path,
|
|
105
|
+
params: a.params,
|
|
106
|
+
query: a.query,
|
|
107
107
|
action: s,
|
|
108
108
|
direction: l,
|
|
109
109
|
reuse: (i == null ? void 0 : i.reuse) ?? !1,
|
|
@@ -116,27 +116,27 @@ function Be(e) {
|
|
|
116
116
|
transition: (i == null ? void 0 : i.transition) ?? E,
|
|
117
117
|
transitionDuration: (i == null ? void 0 : i.duration) ?? d,
|
|
118
118
|
transitionEasing: (i == null ? void 0 : i.easing) ?? D,
|
|
119
|
-
cache:
|
|
119
|
+
cache: M
|
|
120
120
|
};
|
|
121
|
-
}, T = (
|
|
122
|
-
const r =
|
|
123
|
-
return
|
|
121
|
+
}, T = (a) => {
|
|
122
|
+
const r = a.meta.stack;
|
|
123
|
+
return a.meta.stackCache !== !1 && (r == null ? void 0 : r.cache) !== !1;
|
|
124
124
|
}, $ = () => {
|
|
125
125
|
if (w <= 0 || c.length <= w) return;
|
|
126
|
-
const
|
|
127
|
-
c.splice(0,
|
|
128
|
-
}, W = (
|
|
129
|
-
if (
|
|
126
|
+
const a = c.length - w;
|
|
127
|
+
c.splice(0, a), f = Math.max(0, f - a);
|
|
128
|
+
}, W = (a) => {
|
|
129
|
+
if (a.action === "pop") {
|
|
130
130
|
let r = -1;
|
|
131
|
-
if (
|
|
131
|
+
if (a.direction === "forward" || (a.delta ?? 0) > 0) {
|
|
132
132
|
for (let s = f + 1; s < c.length; s++)
|
|
133
|
-
if (c[s].key ===
|
|
133
|
+
if (c[s].key === a.key) {
|
|
134
134
|
r = s;
|
|
135
135
|
break;
|
|
136
136
|
}
|
|
137
137
|
} else
|
|
138
138
|
for (let s = f - 1; s >= 0; s--)
|
|
139
|
-
if (c[s].key ===
|
|
139
|
+
if (c[s].key === a.key) {
|
|
140
140
|
r = s;
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
@@ -144,10 +144,10 @@ function Be(e) {
|
|
|
144
144
|
const s = c[r];
|
|
145
145
|
c[r] = {
|
|
146
146
|
...s,
|
|
147
|
-
...
|
|
147
|
+
...a,
|
|
148
148
|
id: s.id,
|
|
149
149
|
reuse: s.reuse,
|
|
150
|
-
source:
|
|
150
|
+
source: a.source,
|
|
151
151
|
entryDirection: s.entryDirection,
|
|
152
152
|
transition: s.transition,
|
|
153
153
|
transitionDuration: s.transitionDuration,
|
|
@@ -155,25 +155,25 @@ function Be(e) {
|
|
|
155
155
|
}, f = r;
|
|
156
156
|
} else
|
|
157
157
|
c.push({
|
|
158
|
-
...
|
|
158
|
+
...a,
|
|
159
159
|
direction: "none",
|
|
160
160
|
entryDirection: "none",
|
|
161
161
|
transition: "none",
|
|
162
162
|
isStackFallback: !0
|
|
163
163
|
}), f = c.length - 1;
|
|
164
|
-
} else if (
|
|
164
|
+
} else if (a.action === "replace") {
|
|
165
165
|
if (i != null && i.resetRoot) {
|
|
166
|
-
c.splice(0, c.length,
|
|
166
|
+
c.splice(0, c.length, a), f = 0, u.value = c[f];
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
|
-
f >= 0 ? c[f] =
|
|
169
|
+
f >= 0 ? c[f] = a : (c.push(a), f = 0);
|
|
170
170
|
} else
|
|
171
|
-
f < c.length - 1 && c.splice(f + 1), c.push(
|
|
171
|
+
f < c.length - 1 && c.splice(f + 1), c.push(a), f = c.length - 1;
|
|
172
172
|
$(), u.value = c[f];
|
|
173
173
|
};
|
|
174
|
-
e.history.listen((
|
|
174
|
+
e.history.listen((a, r, s) => {
|
|
175
175
|
const l = "delta" in s ? s.delta : void 0, h = s.direction === "back" ? "back" : s.direction === "forward" ? "forward" : void 0;
|
|
176
|
-
i ? (i.delta = l, i.direction =
|
|
176
|
+
i ? (i.delta = l, i.direction = X(
|
|
177
177
|
i.action,
|
|
178
178
|
i.direction ?? h
|
|
179
179
|
)) : R(
|
|
@@ -184,25 +184,25 @@ function Be(e) {
|
|
|
184
184
|
!1,
|
|
185
185
|
"external"
|
|
186
186
|
);
|
|
187
|
-
}),
|
|
187
|
+
}), o.beforeEach((a) => !((i == null ? void 0 : i.action) === "pop" && b && !c.some((r) => r.fullPath === a.fullPath))), o.afterEach((a, r, s) => {
|
|
188
188
|
if (s) {
|
|
189
189
|
i = void 0;
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
W(K(
|
|
192
|
+
W(K(a, r)), i = void 0;
|
|
193
193
|
});
|
|
194
|
-
const g =
|
|
194
|
+
const g = o.push.bind(o), I = o.replace.bind(o), z = o.back.bind(o), x = o.forward.bind(o), j = o.go.bind(o), L = (a, r) => (R(
|
|
195
195
|
"push",
|
|
196
196
|
(r == null ? void 0 : r.direction) ?? "forward",
|
|
197
197
|
void 0,
|
|
198
198
|
r
|
|
199
|
-
), g(
|
|
199
|
+
), g(a)), A = (a, r) => (R(
|
|
200
200
|
"replace",
|
|
201
201
|
(r == null ? void 0 : r.direction) ?? "root",
|
|
202
202
|
void 0,
|
|
203
203
|
r
|
|
204
|
-
), I(
|
|
205
|
-
const s =
|
|
204
|
+
), I(a)), B = (a, r) => {
|
|
205
|
+
const s = o.resolve(a).fullPath;
|
|
206
206
|
let l = -1;
|
|
207
207
|
for (let k = f; k >= 0; k--)
|
|
208
208
|
if (c[k].fullPath === s) {
|
|
@@ -217,9 +217,9 @@ function Be(e) {
|
|
|
217
217
|
h,
|
|
218
218
|
r
|
|
219
219
|
), j(h)), !0;
|
|
220
|
-
}, _ = (
|
|
221
|
-
const s =
|
|
222
|
-
if (f >= 0 &&
|
|
220
|
+
}, _ = (a, r) => {
|
|
221
|
+
const s = o.resolve(a).fullPath;
|
|
222
|
+
if (f >= 0 && o.currentRoute.value.fullPath === s) {
|
|
223
223
|
const l = c[f], h = {
|
|
224
224
|
...l,
|
|
225
225
|
id: J("route"),
|
|
@@ -243,12 +243,12 @@ function Be(e) {
|
|
|
243
243
|
void 0,
|
|
244
244
|
r,
|
|
245
245
|
!0
|
|
246
|
-
), b = !0, I(
|
|
246
|
+
), b = !0, I(a);
|
|
247
247
|
}, V = () => {
|
|
248
248
|
R("pop", "back", -1), z();
|
|
249
249
|
}, F = () => {
|
|
250
250
|
R("pop", "forward", 1), x();
|
|
251
|
-
}, p =
|
|
251
|
+
}, p = o;
|
|
252
252
|
p.push = L, p.replace = A, p.popTo = B, p.resetRoot = _, p.back = V, p.forward = F;
|
|
253
253
|
const t = {
|
|
254
254
|
router: p,
|
|
@@ -262,29 +262,29 @@ function Be(e) {
|
|
|
262
262
|
get history() {
|
|
263
263
|
return c;
|
|
264
264
|
},
|
|
265
|
-
canGoBack: (
|
|
265
|
+
canGoBack: (a = 1) => f - a >= 0,
|
|
266
266
|
push: L,
|
|
267
267
|
replace: A,
|
|
268
268
|
popTo: B,
|
|
269
269
|
resetRoot: _,
|
|
270
270
|
back: V,
|
|
271
271
|
forward: F
|
|
272
|
-
},
|
|
273
|
-
return
|
|
274
|
-
|
|
272
|
+
}, n = o.install.bind(o);
|
|
273
|
+
return o.install = (a) => {
|
|
274
|
+
a.provide(N, t), n(a);
|
|
275
275
|
}, p;
|
|
276
276
|
}
|
|
277
277
|
const re = "onPageWillEnter", Q = "onPageDidEnter", oe = "onPageWillLeave", ne = "onPageDidLeave";
|
|
278
|
-
function Te(e,
|
|
278
|
+
function Te(e, o, c) {
|
|
279
279
|
if (!c)
|
|
280
280
|
throw new Error(`${e} must be called inside setup().`);
|
|
281
281
|
const u = c.proxy, d = u[e] ?? [];
|
|
282
282
|
d.push(() => {
|
|
283
|
-
c.isUnmounted ||
|
|
283
|
+
c.isUnmounted || o();
|
|
284
284
|
}), u[e] = d, c.exposed && (c.exposed[e] = d);
|
|
285
285
|
}
|
|
286
286
|
function H(e) {
|
|
287
|
-
return (
|
|
287
|
+
return (o, c = ie()) => Te(e, o, c);
|
|
288
288
|
}
|
|
289
289
|
const _e = H(re), Ve = H(Q), Fe = H(oe), Ce = H(ne);
|
|
290
290
|
function Ge() {
|
|
@@ -308,129 +308,130 @@ function ae() {
|
|
|
308
308
|
throw new Error("RouterOutlet must be used with createStackRouter().");
|
|
309
309
|
return e;
|
|
310
310
|
}
|
|
311
|
-
function P(e,
|
|
311
|
+
function P(e, o) {
|
|
312
312
|
const c = e.value;
|
|
313
313
|
if (!c) return;
|
|
314
|
-
const u = c[
|
|
314
|
+
const u = c[o];
|
|
315
315
|
Array.isArray(u) ? u.forEach((d) => d()) : typeof u == "function" && u.call(c);
|
|
316
316
|
}
|
|
317
317
|
function S(e) {
|
|
318
318
|
e.classList.remove("rs-page-hidden", "rs-page-invisible"), e.removeAttribute("aria-hidden");
|
|
319
319
|
}
|
|
320
320
|
function q(e) {
|
|
321
|
-
e.
|
|
321
|
+
const o = e.ownerDocument.activeElement;
|
|
322
|
+
o instanceof HTMLElement && e.contains(o) && o.blur(), e.classList.add("rs-page-hidden"), e.setAttribute("aria-hidden", "true");
|
|
322
323
|
}
|
|
323
324
|
function ce(e) {
|
|
324
|
-
var
|
|
325
|
-
return (
|
|
325
|
+
var o;
|
|
326
|
+
return (o = e.components) == null ? void 0 : o.default;
|
|
326
327
|
}
|
|
327
328
|
function ge(e) {
|
|
328
|
-
const
|
|
329
|
-
return
|
|
329
|
+
const o = ce(e);
|
|
330
|
+
return o !== void 0 && typeof o == "object" && "name" in o && o.name === "RouterView";
|
|
330
331
|
}
|
|
331
332
|
const He = Y({
|
|
332
333
|
name: "RouterOutlet",
|
|
333
334
|
setup() {
|
|
334
|
-
const e = ae(),
|
|
335
|
+
const e = ae(), o = ye(), c = C(ke), u = C(v, void 0), d = U(() => {
|
|
335
336
|
const t = u == null ? void 0 : u.value;
|
|
336
337
|
if (!t) return 0;
|
|
337
|
-
const
|
|
338
|
-
(
|
|
338
|
+
const n = o.matched.findIndex(
|
|
339
|
+
(a) => a === t
|
|
339
340
|
);
|
|
340
|
-
return
|
|
341
|
-
}), D =
|
|
342
|
-
for (let t = d.value; t <
|
|
343
|
-
const
|
|
344
|
-
if (!ge(
|
|
345
|
-
return
|
|
341
|
+
return n >= 0 ? n + 1 : 0;
|
|
342
|
+
}), D = U(() => o.matched[d.value]), E = U(() => {
|
|
343
|
+
for (let t = d.value; t < o.matched.length; t++) {
|
|
344
|
+
const n = o.matched[t];
|
|
345
|
+
if (!ge(n))
|
|
346
|
+
return n;
|
|
346
347
|
}
|
|
347
348
|
return D.value;
|
|
348
349
|
}), m = te([]), w = G("");
|
|
349
350
|
let f = 0;
|
|
350
351
|
ue(v, E);
|
|
351
|
-
const i = (t) => m.value.find((
|
|
352
|
-
m.value.forEach((
|
|
353
|
-
|
|
352
|
+
const i = (t) => m.value.find((n) => n.id === t), b = (t) => m.value.find((n) => n.routeIds.has(t)), R = (t) => m.value.find((n) => n.routeKey === t), K = (t) => t.action === "push" && t.direction === "forward" && !t.reuse && m.value.some((n) => n.routeKey === t.key), T = (t) => {
|
|
353
|
+
m.value.forEach((n) => {
|
|
354
|
+
n.pageElement && (n === t ? S(n.pageElement) : q(n.pageElement));
|
|
354
355
|
});
|
|
355
356
|
}, $ = (t) => {
|
|
356
|
-
const
|
|
357
|
+
const n = e.history.findIndex(
|
|
357
358
|
(r) => r.id === t.routeInfo.id
|
|
358
359
|
);
|
|
359
|
-
if (
|
|
360
|
-
const
|
|
361
|
-
e.history.slice(0,
|
|
360
|
+
if (n < 0) return;
|
|
361
|
+
const a = new Set(
|
|
362
|
+
e.history.slice(0, n + 1).map((r) => r.id)
|
|
362
363
|
);
|
|
363
364
|
m.value.forEach((r) => {
|
|
364
365
|
r.routeIds = new Set(
|
|
365
|
-
[...r.routeIds].filter((s) =>
|
|
366
|
+
[...r.routeIds].filter((s) => a.has(s))
|
|
366
367
|
);
|
|
367
368
|
}), m.value = m.value.filter(
|
|
368
369
|
(r) => r === t || r.routeIds.size > 0
|
|
369
370
|
);
|
|
370
371
|
}, W = (t) => {
|
|
371
|
-
m.value = m.value.filter((
|
|
372
|
+
m.value = m.value.filter((n) => n !== t);
|
|
372
373
|
}, g = (t) => {
|
|
373
|
-
const
|
|
374
|
-
e.history.map((
|
|
374
|
+
const n = new Set(
|
|
375
|
+
e.history.map((a) => a.id)
|
|
375
376
|
);
|
|
376
|
-
m.value.forEach((
|
|
377
|
-
|
|
378
|
-
[...
|
|
377
|
+
m.value.forEach((a) => {
|
|
378
|
+
a.routeIds = new Set(
|
|
379
|
+
[...a.routeIds].filter((r) => n.has(r))
|
|
379
380
|
);
|
|
380
381
|
}), m.value = m.value.filter(
|
|
381
|
-
(
|
|
382
|
+
(a) => a === t || a.routeInfo.cache && a.routeIds.size > 0
|
|
382
383
|
);
|
|
383
384
|
}, I = (t) => {
|
|
384
|
-
var
|
|
385
|
-
const
|
|
386
|
-
return
|
|
387
|
-
}, z = (t,
|
|
385
|
+
var a;
|
|
386
|
+
const n = t.props.default;
|
|
387
|
+
return n ? n === !0 ? ((a = e.current.value) == null ? void 0 : a.params) ?? {} : typeof n == "function" ? n(c) : n : {};
|
|
388
|
+
}, z = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transition ?? t.routeInfo.transition ?? e.transition : t.routeInfo.transition ?? e.transition, x = (t) => t.entryDirection === "none" || t.entryDirection === "root" || t.transition === "none", j = (t, n) => t.routeInfo.direction === "forward" ? x(t.routeInfo) : x(n.routeInfo), L = (t, n) => !(t.routeInfo.isStackFallback || t.routeInfo.direction === "none" || t.routeInfo.direction === "root" || t.routeInfo.action === "pop" && j(t, n)), A = (t, n) => {
|
|
388
389
|
var r;
|
|
389
|
-
const
|
|
390
|
+
const a = L(t, n);
|
|
390
391
|
return ((r = e.shouldTransition) == null ? void 0 : r.call(e, {
|
|
391
392
|
action: t.routeInfo.action,
|
|
392
393
|
direction: t.routeInfo.direction,
|
|
393
394
|
source: t.routeInfo.source,
|
|
394
395
|
entering: t.routeInfo,
|
|
395
|
-
leaving:
|
|
396
|
-
defaultResult:
|
|
397
|
-
})) ??
|
|
398
|
-
}, B = (t,
|
|
399
|
-
const
|
|
396
|
+
leaving: n.routeInfo,
|
|
397
|
+
defaultResult: a
|
|
398
|
+
})) ?? a;
|
|
399
|
+
}, B = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transitionDuration ?? t.routeInfo.transitionDuration ?? e.transitionDuration : t.routeInfo.transitionDuration ?? e.transitionDuration, _ = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transitionEasing ?? t.routeInfo.transitionEasing ?? e.transitionEasing : t.routeInfo.transitionEasing ?? e.transitionEasing, V = async (t, n) => {
|
|
400
|
+
const a = ++f;
|
|
400
401
|
await fe();
|
|
401
402
|
const r = t.pageElement;
|
|
402
403
|
if (!r) return;
|
|
403
|
-
if (P(t.componentRef, re), !
|
|
404
|
+
if (P(t.componentRef, re), !n || n === t || !n.pageElement) {
|
|
404
405
|
S(r), P(t.componentRef, Q), g(t), T(t);
|
|
405
406
|
return;
|
|
406
407
|
}
|
|
407
|
-
const s =
|
|
408
|
+
const s = n.pageElement, l = A(t, n), h = l ? z(t, n) : "none", k = l ? B(t, n) : 0, M = _(t, n), se = Pe(
|
|
408
409
|
h || Z,
|
|
409
410
|
e.transitions
|
|
410
411
|
);
|
|
411
|
-
P(
|
|
412
|
+
P(n.componentRef, oe), S(r), S(s), await Se(se, {
|
|
412
413
|
direction: t.routeInfo.direction,
|
|
413
414
|
action: t.routeInfo.action,
|
|
414
415
|
routeInfo: t.routeInfo,
|
|
415
416
|
enteringElement: r,
|
|
416
417
|
leavingElement: s,
|
|
417
418
|
duration: k,
|
|
418
|
-
easing:
|
|
419
|
-
}),
|
|
419
|
+
easing: M
|
|
420
|
+
}), a === f && (q(s), P(n.componentRef, ne), P(t.componentRef, Q), t.routeInfo.action === "pop" ? $(t) : t.routeInfo.action === "replace" && W(n), g(t), T(t));
|
|
420
421
|
}, F = async () => {
|
|
421
|
-
const t = E.value,
|
|
422
|
-
if (!t || !
|
|
423
|
-
const
|
|
424
|
-
if (!
|
|
422
|
+
const t = E.value, n = e.current.value;
|
|
423
|
+
if (!t || !n) return;
|
|
424
|
+
const a = ce(t);
|
|
425
|
+
if (!a) return;
|
|
425
426
|
const r = i(w.value);
|
|
426
|
-
let s = b(
|
|
427
|
-
!s && !K(
|
|
427
|
+
let s = b(n.id);
|
|
428
|
+
!s && !K(n) && (s = R(n.key)), s ? (s.routeIds.add(n.id), s.routeKey = n.key, s.routeInfo = n, s.matchedRoute = t, s.component = a, s.props = I(t), s.mounted = !0) : (s = {
|
|
428
429
|
id: J("view"),
|
|
429
|
-
routeKey:
|
|
430
|
-
routeIds: /* @__PURE__ */ new Set([
|
|
431
|
-
routeInfo:
|
|
430
|
+
routeKey: n.key,
|
|
431
|
+
routeIds: /* @__PURE__ */ new Set([n.id]),
|
|
432
|
+
routeInfo: n,
|
|
432
433
|
matchedRoute: t,
|
|
433
|
-
component:
|
|
434
|
+
component: a,
|
|
434
435
|
props: I(t),
|
|
435
436
|
componentRef: G(),
|
|
436
437
|
mounted: !0
|
|
@@ -450,8 +451,8 @@ const He = Y({
|
|
|
450
451
|
}), {
|
|
451
452
|
injectedRoute: c,
|
|
452
453
|
viewItems: m,
|
|
453
|
-
registerStackPage: (t,
|
|
454
|
-
t.pageElement =
|
|
454
|
+
registerStackPage: (t, n) => {
|
|
455
|
+
t.pageElement = n, t.id === w.value ? S(n) : q(n);
|
|
455
456
|
}
|
|
456
457
|
};
|
|
457
458
|
},
|
|
@@ -464,7 +465,7 @@ const He = Y({
|
|
|
464
465
|
key: e.id,
|
|
465
466
|
ref: e.componentRef,
|
|
466
467
|
...e.props,
|
|
467
|
-
registerStackPage: (
|
|
468
|
+
registerStackPage: (o) => this.registerStackPage(e, o)
|
|
468
469
|
})
|
|
469
470
|
)
|
|
470
471
|
);
|
|
@@ -477,7 +478,7 @@ const He = Y({
|
|
|
477
478
|
default: void 0
|
|
478
479
|
}
|
|
479
480
|
},
|
|
480
|
-
setup(e, { attrs:
|
|
481
|
+
setup(e, { attrs: o, slots: c }) {
|
|
481
482
|
const u = G();
|
|
482
483
|
return he(() => {
|
|
483
484
|
var d;
|
|
@@ -487,9 +488,9 @@ const He = Y({
|
|
|
487
488
|
return y(
|
|
488
489
|
"section",
|
|
489
490
|
{
|
|
490
|
-
...
|
|
491
|
+
...o,
|
|
491
492
|
ref: u,
|
|
492
|
-
class: ["rs-page",
|
|
493
|
+
class: ["rs-page", o.class]
|
|
493
494
|
},
|
|
494
495
|
(d = c.default) == null ? void 0 : d.call(c)
|
|
495
496
|
);
|
|
@@ -504,9 +505,9 @@ const He = Y({
|
|
|
504
505
|
}
|
|
505
506
|
},
|
|
506
507
|
setup(e) {
|
|
507
|
-
const
|
|
508
|
+
const o = ae(), c = G(e.initialOpen);
|
|
508
509
|
return () => {
|
|
509
|
-
const u =
|
|
510
|
+
const u = o.current.value;
|
|
510
511
|
return y("aside", { class: "rs-debug-panel" }, [
|
|
511
512
|
y(
|
|
512
513
|
"button",
|
|
@@ -522,17 +523,17 @@ const He = Y({
|
|
|
522
523
|
c.value ? y("section", { class: "rs-debug-body" }, [
|
|
523
524
|
y("header", [
|
|
524
525
|
y("strong", "Router Stack"),
|
|
525
|
-
y("span", `${
|
|
526
|
+
y("span", `${o.history.length} pages`)
|
|
526
527
|
]),
|
|
527
528
|
y("dl", [
|
|
528
529
|
y("dt", "current"),
|
|
529
530
|
y("dd", (u == null ? void 0 : u.fullPath) ?? "-"),
|
|
530
531
|
y("dt", "canGoBack"),
|
|
531
|
-
y("dd", String(
|
|
532
|
+
y("dd", String(o.canGoBack()))
|
|
532
533
|
]),
|
|
533
534
|
y(
|
|
534
535
|
"ol",
|
|
535
|
-
|
|
536
|
+
o.history.map(
|
|
536
537
|
(d) => y(
|
|
537
538
|
"li",
|
|
538
539
|
{
|
|
@@ -564,11 +565,11 @@ export {
|
|
|
564
565
|
je as RouterLink,
|
|
565
566
|
He as RouterOutlet,
|
|
566
567
|
Ke as RouterPage,
|
|
567
|
-
|
|
568
|
+
Me as RouterView,
|
|
568
569
|
$e as StackRouterDebugPanel,
|
|
569
|
-
|
|
570
|
+
Ue as createMemoryHistory,
|
|
570
571
|
Be as createStackRouter,
|
|
571
|
-
|
|
572
|
+
Xe as createWebHashHistory,
|
|
572
573
|
qe as createWebHistory,
|
|
573
574
|
Ae as defineStackTransition,
|
|
574
575
|
Ve as onPageDidEnter,
|