@lazycatcloud/vue-router-stack 0.0.1 → 0.0.3
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.
|
@@ -3,7 +3,7 @@ import type { RouteLocationMatched } from "vue-router";
|
|
|
3
3
|
import type { RouteInfo } from "../router/types";
|
|
4
4
|
interface ViewItem {
|
|
5
5
|
id: string;
|
|
6
|
-
|
|
6
|
+
stackEntryId: string;
|
|
7
7
|
routeInfo: RouteInfo;
|
|
8
8
|
matchedRoute: RouteLocationMatched;
|
|
9
9
|
component: Component;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StackTransitionContext, StackTransitionFactory, StackTransitionName, StackTransitionRegistry } from "./types";
|
|
2
2
|
export declare const DEFAULT_STACK_TRANSITION = "slide";
|
|
3
|
-
export declare const DEFAULT_STACK_TRANSITION_EASING = "cubic-bezier(0.
|
|
3
|
+
export declare const DEFAULT_STACK_TRANSITION_EASING = "cubic-bezier(0.3, 0, 0.66, 1)";
|
|
4
4
|
export declare function defineStackTransition(factory: StackTransitionFactory): StackTransitionFactory;
|
|
5
5
|
export declare const builtinStackTransitions: StackTransitionRegistry;
|
|
6
6
|
export declare function resolveStackTransition(name: StackTransitionName, transitions: StackTransitionRegistry): StackTransitionFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),b=require("vue-router"),J={};function z(e="route"){const r=(J[e]??0)+1;return J[e]=r,`${e}-${r}`}const v="slide",re="cubic-bezier(0.2, 0, 0, 1)";function oe(e){return e}const ne=({direction:e})=>{const r=e==="back";return{entering:r?[{transform:"translateX(-18%)",opacity:.96},{transform:"translateX(0)",opacity:1}]:[{transform:"translateX(100%)"},{transform:"translateX(0)"}],leaving:r?[{transform:"translateX(0)",opacity:1},{transform:"translateX(100%)",opacity:1}]:[{transform:"translateX(0)",opacity:1},{transform:"translateX(-18%)",opacity:.96}]}},ae=()=>({entering:[{opacity:0},{opacity:1}],leaving:[{opacity:1},{opacity:0}]}),ce=({direction:e})=>{const r=e==="back";return{entering:r?[{transform:"scale(0.98)",opacity:0},{transform:"scale(1)",opacity:1}]:[{transform:"scale(1.04)",opacity:0},{transform:"scale(1)",opacity:1}],leaving:r?[{transform:"scale(1)",opacity:1},{transform:"scale(1.04)",opacity:0}]:[{transform:"scale(1)",opacity:1},{transform:"scale(0.98)",opacity:0}]}},ie=()=>({}),se={slide:ne,fade:ae,scale:ce,none:ie};function ue(e,r){const n=r[e];return n||r[v]}function Q(e,r,n){if(!r||!e.animate||Number(n.duration)<=0)return Promise.resolve();const l=e.animate(r,n);return l.finished.then(()=>l.cancel())}async function le(e,r){const n=e(r),l={duration:r.duration,easing:r.easing,fill:"both",...n.options};await Promise.all([Q(r.enteringElement,n.entering,l),Q(r.leavingElement,n.leaving,l)])}const H=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 M(e,r){return r||(e==="pop"?"back":e==="replace"?"none":"forward")}function de(e){const r=b.createRouter(e),n=[],l=i.shallowRef(),f=e.transitionDuration??240,T=e.transitionEasing??re,S=e.transition??v,p={...se,...e.transitions},E=e.maxStackSize??30;let d=-1,s,g=!1;const P=(c,a,u,h,k=!1,w="stack")=>{s={action:c,direction:M(c,a),source:w,delta:u,transition:h==null?void 0:h.transition,duration:h==null?void 0:h.duration,easing:h==null?void 0:h.easing,resetRoot:k}},F=(c,a)=>{const u=(s==null?void 0:s.action)??"push",h=M(u,s==null?void 0:s.direction),k=l.value,w=u==="push"&&h==="forward",te=L(c);return{id:z("route"),key:c.fullPath,fullPath:c.fullPath,pathname:c.path,params:c.params,query:c.query,action:u,direction:h,source:(s==null?void 0:s.source)??"stack",entryDirection:h,lastPathname:(k==null?void 0:k.pathname)||(a.name?a.path:void 0),pushedByRoute:w?k==null?void 0:k.pathname:k==null?void 0:k.pushedByRoute,position:fe(),delta:s==null?void 0:s.delta,transition:(s==null?void 0:s.transition)??S,transitionDuration:(s==null?void 0:s.duration)??f,transitionEasing:(s==null?void 0:s.easing)??T,cache:te}},L=c=>{const a=c.meta.stack;return c.meta.stackCache!==!1&&(a==null?void 0:a.cache)!==!1},x=()=>{if(E<=0||n.length<=E)return;const c=n.length-E;n.splice(0,c),d=Math.max(0,d-c)},W=c=>{if(c.action==="pop"){let a=-1;if(c.direction==="forward"||(c.delta??0)>0){for(let u=d+1;u<n.length;u++)if(n[u].key===c.key){a=u;break}}else for(let u=d-1;u>=0;u--)if(n[u].key===c.key){a=u;break}if(a>=0){const u=n[a];n[a]={...u,...c,id:u.id,source:c.source,entryDirection:u.entryDirection,transition:u.transition,transitionDuration:u.transitionDuration,transitionEasing:u.transitionEasing},d=a}else n.push({...c,direction:"none",entryDirection:"none",transition:"none",isStackFallback:!0}),d=n.length-1}else if(c.action==="replace"){if(s!=null&&s.resetRoot){n.splice(0,n.length,c),d=0,l.value=n[d];return}d>=0?n[d]=c:(n.push(c),d=0)}else d<n.length-1&&n.splice(d+1),n.push(c),d=n.length-1;x(),l.value=n[d]};e.history.listen((c,a,u)=>{const h="delta"in u?u.delta:void 0,k=u.direction==="back"?"back":u.direction==="forward"?"forward":void 0;s?(s.delta=h,s.direction=M(s.action,s.direction??k)):P(u.type==="pop"?"pop":u.type,k,h,void 0,!1,"external")}),r.beforeEach(c=>!((s==null?void 0:s.action)==="pop"&&g&&!n.some(a=>a.fullPath===c.fullPath))),r.afterEach((c,a,u)=>{if(u){s=void 0;return}W(F(c,a)),s=void 0});const B=r.push.bind(r),A=r.replace.bind(r),G=r.back.bind(r),V=r.forward.bind(r),$=r.go.bind(r),j=(c,a)=>(P("push",(a==null?void 0:a.direction)??"forward",void 0,a),B(c)),K=(c,a)=>(P("replace",(a==null?void 0:a.direction)??"root",void 0,a),A(c)),t=(c,a)=>{const u=r.resolve(c).fullPath;let h=-1;for(let w=d;w>=0;w--)if(n[w].fullPath===u){h=w;break}if(h<0)return!1;const k=h-d;return k===0||(P("pop",(a==null?void 0:a.direction)??"back",k,a),$(k)),!0},o=(c,a)=>{const u=r.resolve(c).fullPath;if(d>=0&&r.currentRoute.value.fullPath===u){const h=n[d],k={...h,id:z("route"),action:"replace",direction:(a==null?void 0:a.direction)??"root",source:"stack",entryDirection:(a==null?void 0:a.direction)??"root",delta:void 0,transition:(a==null?void 0:a.transition)??h.transition,transitionDuration:(a==null?void 0:a.duration)??h.transitionDuration,transitionEasing:(a==null?void 0:a.easing)??h.transitionEasing,cache:!0,isStackFallback:!1};return n.splice(0,n.length,k),d=0,g=!0,l.value=k,Promise.resolve(void 0)}return P("replace",(a==null?void 0:a.direction)??"root",void 0,a,!0),g=!0,A(c)},m=()=>{P("pop","back",-1),G()},R=()=>{P("pop","forward",1),V()},y=r;y.push=j,y.replace=K,y.popTo=t,y.resetRoot=o,y.back=m,y.forward=R;const _={router:y,transitionDuration:f,transitionEasing:T,transition:S,transitions:p,maxStackSize:E,shouldTransition:e.shouldTransition,current:l,get history(){return n},canGoBack:(c=1)=>d-c>=0,push:j,replace:K,popTo:t,resetRoot:o,back:m,forward:R},X=r.install.bind(r);return r.install=c=>{c.provide(H,_),X(c)},y}const Y="onPageWillEnter",U="onPageDidEnter",Z="onPageWillLeave",N="onPageDidLeave";function he(e,r,n){if(!n)throw new Error(`${e} must be called inside setup().`);const l=n.proxy,f=l[e]??[];f.push(()=>{n.isUnmounted||r()}),l[e]=f,n.exposed&&(n.exposed[e]=f)}function C(e){return(r,n=i.getCurrentInstance())=>he(e,r,n)}const me=C(Y),ye=C(U),ke=C(Z),pe=C(N);function Re(){const e=i.inject(H);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 O(){const e=i.inject(H);if(!e)throw new Error("RouterOutlet must be used with createStackRouter().");return e}function D(e,r){const n=e.value;if(!n)return;const l=n[r];Array.isArray(l)?l.forEach(f=>f()):typeof l=="function"&&l.call(n)}function I(e){e.classList.remove("rs-page-hidden","rs-page-invisible"),e.removeAttribute("aria-hidden")}function q(e){e.classList.add("rs-page-hidden"),e.setAttribute("aria-hidden","true")}function ee(e){var r;return(r=e.components)==null?void 0:r.default}function be(e){const r=ee(e);return r!==void 0&&typeof r=="object"&&"name"in r&&r.name==="RouterView"}const Pe=i.defineComponent({name:"RouterOutlet",setup(){const e=O(),r=b.useRoute(),n=i.inject(b.routeLocationKey),l=i.inject(b.matchedRouteKey,void 0),f=i.computed(()=>{const t=l==null?void 0:l.value;if(!t)return 0;const o=r.matched.findIndex(m=>m===t);return o>=0?o+1:0}),T=i.computed(()=>r.matched[f.value]),S=i.computed(()=>{for(let t=f.value;t<r.matched.length;t++){const o=r.matched[t];if(!be(o))return o}return T.value}),p=i.shallowRef([]),E=i.ref("");let d=0;i.provide(b.matchedRouteKey,S);const s=t=>p.value.find(o=>o.key===t),g=t=>{p.value.forEach(o=>{o.pageElement&&(o===t?I(o.pageElement):q(o.pageElement))})},P=t=>{const o=p.value.findIndex(m=>m===t);o>=0&&(p.value=p.value.slice(0,o+1))},F=t=>{p.value=p.value.filter(o=>o!==t)},L=t=>{const o=new Set(e.history.map(m=>m.key));p.value=p.value.filter(m=>m===t||m.routeInfo.cache&&o.has(m.key))},x=t=>{var m;const o=t.props.default;return o?o===!0?((m=e.current.value)==null?void 0:m.params)??{}:typeof o=="function"?o(n):o:{}},W=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,B=(t,o)=>!(t.routeInfo.isStackFallback||t.routeInfo.direction==="none"||t.routeInfo.direction==="root"||t.routeInfo.action==="pop"&&(o.routeInfo.entryDirection==="none"||o.routeInfo.entryDirection==="root"||o.routeInfo.transition==="none")),A=(t,o)=>{var R;const m=B(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:m}))??m},G=(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 m=++d;await i.nextTick();const R=t.pageElement;if(!R)return;if(D(t.componentRef,Y),!o||o===t||!o.pageElement){I(R),D(t.componentRef,U),L(t),g(t);return}const y=o.pageElement,_=A(t,o),X=_?W(t,o):"none",c=_?G(t,o):0,a=V(t,o),u=ue(X||v,e.transitions);D(o.componentRef,Z),I(R),I(y),await le(u,{direction:t.routeInfo.direction,action:t.routeInfo.action,routeInfo:t.routeInfo,enteringElement:R,leavingElement:y,duration:c,easing:a}),m===d&&(q(y),D(o.componentRef,N),D(t.componentRef,U),t.routeInfo.action==="pop"?P(t):t.routeInfo.action==="replace"&&F(o),L(t),g(t))},j=async()=>{const t=S.value,o=e.current.value;if(!t||!o)return;const m=ee(t);if(!m)return;const R=s(E.value);let y=s(o.key);y?(y.routeInfo=o,y.matchedRoute=t,y.component=m,y.props=x(t),y.mounted=!0):(y={id:z("view"),key:o.key,routeInfo:o,matchedRoute:t,component:m,props:x(t),componentRef:i.ref(),mounted:!0},p.value=[...p.value,y]),E.value=y.key,await $(y,R)};return i.watch(()=>{var t;return[(t=e.current.value)==null?void 0:t.id,S.value]},()=>{j()},{immediate:!0}),i.onUnmounted(()=>{d++,p.value=[]}),{injectedRoute:n,viewItems:p,registerStackPage:(t,o)=>{t.pageElement=o,t.key===E.value?I(o):q(o)}}},render(){return i.h("div",{class:"rs-outlet"},this.viewItems.filter(e=>e.mounted).map(e=>i.h(e.component,{key:e.id,ref:e.componentRef,...e.props,registerStackPage:r=>this.registerStackPage(e,r)})))}}),Ee=i.defineComponent({name:"RouterPage",props:{registerStackPage:{type:Function,default:void 0}},setup(e,{attrs:r,slots:n}){const l=i.ref();return i.onMounted(()=>{var f;l.value&&((f=e.registerStackPage)==null||f.call(e,l.value))}),()=>{var f;return i.h("section",{...r,ref:l,class:["rs-page",r.class]},(f=n.default)==null?void 0:f.call(n))}}}),we=i.defineComponent({name:"StackRouterDebugPanel",props:{initialOpen:{type:Boolean,default:!1}},setup(e){const r=O(),n=i.ref(e.initialOpen);return()=>{const l=r.current.value;return i.h("aside",{class:"rs-debug-panel"},[i.h("button",{class:"rs-debug-toggle",type:"button",onClick:()=>{n.value=!n.value}},n.value?"Stack x":"Stack"),n.value?i.h("section",{class:"rs-debug-body"},[i.h("header",[i.h("strong","Router Stack"),i.h("span",`${r.history.length} pages`)]),i.h("dl",[i.h("dt","current"),i.h("dd",(l==null?void 0:l.fullPath)??"-"),i.h("dt","canGoBack"),i.h("dd",String(r.canGoBack()))]),i.h("ol",r.history.map(f=>i.h("li",{key:f.id,class:{"rs-debug-active":f.id===(l==null?void 0:l.id),"rs-debug-no-cache":!f.cache}},[i.h("code",f.fullPath),i.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:()=>b.RouterLink});Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>b.RouterView});Object.defineProperty(exports,"createMemoryHistory",{enumerable:!0,get:()=>b.createMemoryHistory});Object.defineProperty(exports,"createWebHashHistory",{enumerable:!0,get:()=>b.createWebHashHistory});Object.defineProperty(exports,"createWebHistory",{enumerable:!0,get:()=>b.createWebHistory});Object.defineProperty(exports,"useRoute",{enumerable:!0,get:()=>b.useRoute});Object.defineProperty(exports,"useRouter",{enumerable:!0,get:()=>b.useRouter});exports.RouterOutlet=Pe;exports.RouterPage=Ee;exports.StackRouterDebugPanel=we;exports.createStackRouter=de;exports.defineStackTransition=oe;exports.onPageDidEnter=ye;exports.onPageDidLeave=pe;exports.onPageWillEnter=me;exports.onPageWillLeave=ke;exports.stackRouterKey=H;exports.useStackRouter=Re;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),b=require("vue-router"),J={};function U(e="route"){const r=(J[e]??0)+1;return J[e]=r,`${e}-${r}`}const v="slide",re="cubic-bezier(0.3, 0, 0.66, 1)";function oe(e){return e}const ne=({direction:e})=>e==="back"?{leaving:[{transform:"translateX(0)"},{transform:"translateX(100%)"}]}:{entering:[{transform:"translateX(100%)"},{transform:"translateX(0)"}]},ae=()=>({entering:[{opacity:0},{opacity:1}],leaving:[{opacity:1},{opacity:0}]}),ce=({direction:e})=>{const r=e==="back";return{entering:r?[{transform:"scale(0.98)",opacity:0},{transform:"scale(1)",opacity:1}]:[{transform:"scale(1.04)",opacity:0},{transform:"scale(1)",opacity:1}],leaving:r?[{transform:"scale(1)",opacity:1},{transform:"scale(1.04)",opacity:0}]:[{transform:"scale(1)",opacity:1},{transform:"scale(0.98)",opacity:0}]}},ie=()=>({}),se={slide:ne,fade:ae,scale:ce,none:ie};function ue(e,r){const n=r[e];return n||r[v]}function Q(e,r,n){if(!r||!e.animate||Number(n.duration)<=0)return Promise.resolve();const l=e.animate(r,n);return l.finished.then(()=>l.cancel())}async function le(e,r){const n=e(r),l={duration:r.duration,easing:r.easing,fill:"both",...n.options};await Promise.all([Q(r.enteringElement,n.entering,l),Q(r.leavingElement,n.leaving,l)])}const C=Symbol("stack-router");function de(){const e=window.history.state;return typeof(e==null?void 0:e.position)=="number"?e.position:window.history.length}function q(e,r){return r||(e==="pop"?"back":e==="replace"?"none":"forward")}function fe(e){const r=b.createRouter(e),n=[],l=i.shallowRef(),d=e.transitionDuration??210,T=e.transitionEasing??re,S=e.transition??v,R={...se,...e.transitions},E=e.maxStackSize??30;let h=-1,s,g=!1;const P=(c,a,u,f,y=!1,w="stack")=>{s={action:c,direction:q(c,a),source:w,delta:u,transition:f==null?void 0:f.transition,duration:f==null?void 0:f.duration,easing:f==null?void 0:f.easing,resetRoot:y}},W=(c,a)=>{const u=(s==null?void 0:s.action)??"push",f=q(u,s==null?void 0:s.direction),y=l.value,w=u==="push"&&f==="forward",te=L(c);return{id:U("route"),key:c.fullPath,fullPath:c.fullPath,pathname:c.path,params:c.params,query:c.query,action:u,direction:f,source:(s==null?void 0:s.source)??"stack",entryDirection:f,lastPathname:(y==null?void 0:y.pathname)||(a.name?a.path:void 0),pushedByRoute:w?y==null?void 0:y.pathname:y==null?void 0:y.pushedByRoute,position:de(),delta:s==null?void 0:s.delta,transition:(s==null?void 0:s.transition)??S,transitionDuration:(s==null?void 0:s.duration)??d,transitionEasing:(s==null?void 0:s.easing)??T,cache:te}},L=c=>{const a=c.meta.stack;return c.meta.stackCache!==!1&&(a==null?void 0:a.cache)!==!1},x=()=>{if(E<=0||n.length<=E)return;const c=n.length-E;n.splice(0,c),h=Math.max(0,h-c)},G=c=>{if(c.action==="pop"){let a=-1;if(c.direction==="forward"||(c.delta??0)>0){for(let u=h+1;u<n.length;u++)if(n[u].key===c.key){a=u;break}}else for(let u=h-1;u>=0;u--)if(n[u].key===c.key){a=u;break}if(a>=0){const u=n[a];n[a]={...u,...c,id:u.id,source:c.source,entryDirection:u.entryDirection,transition:u.transition,transitionDuration:u.transitionDuration,transitionEasing:u.transitionEasing},h=a}else n.push({...c,direction:"none",entryDirection:"none",transition:"none",isStackFallback:!0}),h=n.length-1}else if(c.action==="replace"){if(s!=null&&s.resetRoot){n.splice(0,n.length,c),h=0,l.value=n[h];return}h>=0?n[h]=c:(n.push(c),h=0)}else h<n.length-1&&n.splice(h+1),n.push(c),h=n.length-1;x(),l.value=n[h]};e.history.listen((c,a,u)=>{const f="delta"in u?u.delta:void 0,y=u.direction==="back"?"back":u.direction==="forward"?"forward":void 0;s?(s.delta=f,s.direction=q(s.action,s.direction??y)):P(u.type==="pop"?"pop":u.type,y,f,void 0,!1,"external")}),r.beforeEach(c=>!((s==null?void 0:s.action)==="pop"&&g&&!n.some(a=>a.fullPath===c.fullPath))),r.afterEach((c,a,u)=>{if(u){s=void 0;return}G(W(c,a)),s=void 0});const A=r.push.bind(r),j=r.replace.bind(r),V=r.back.bind(r),$=r.forward.bind(r),K=r.go.bind(r),_=(c,a)=>(P("push",(a==null?void 0:a.direction)??"forward",void 0,a),A(c)),H=(c,a)=>(P("replace",(a==null?void 0:a.direction)??"root",void 0,a),j(c)),M=(c,a)=>{const u=r.resolve(c).fullPath;let f=-1;for(let w=h;w>=0;w--)if(n[w].fullPath===u){f=w;break}if(f<0)return!1;const y=f-h;return y===0||(P("pop",(a==null?void 0:a.direction)??"back",y,a),K(y)),!0},t=(c,a)=>{const u=r.resolve(c).fullPath;if(h>=0&&r.currentRoute.value.fullPath===u){const f=n[h],y={...f,id:U("route"),action:"replace",direction:(a==null?void 0:a.direction)??"root",source:"stack",entryDirection:(a==null?void 0:a.direction)??"root",delta:void 0,transition:(a==null?void 0:a.transition)??f.transition,transitionDuration:(a==null?void 0:a.duration)??f.transitionDuration,transitionEasing:(a==null?void 0:a.easing)??f.transitionEasing,cache:!0,isStackFallback:!1};return n.splice(0,n.length,y),h=0,g=!0,l.value=y,Promise.resolve(void 0)}return P("replace",(a==null?void 0:a.direction)??"root",void 0,a,!0),g=!0,j(c)},o=()=>{P("pop","back",-1),V()},m=()=>{P("pop","forward",1),$()},k=r;k.push=_,k.replace=H,k.popTo=M,k.resetRoot=t,k.back=o,k.forward=m;const p={router:k,transitionDuration:d,transitionEasing:T,transition:S,transitions:R,maxStackSize:E,shouldTransition:e.shouldTransition,current:l,get history(){return n},canGoBack:(c=1)=>h-c>=0,push:_,replace:H,popTo:M,resetRoot:t,back:o,forward:m},B=r.install.bind(r);return r.install=c=>{c.provide(C,p),B(c)},k}const Y="onPageWillEnter",X="onPageDidEnter",Z="onPageWillLeave",N="onPageDidLeave";function he(e,r,n){if(!n)throw new Error(`${e} must be called inside setup().`);const l=n.proxy,d=l[e]??[];d.push(()=>{n.isUnmounted||r()}),l[e]=d,n.exposed&&(n.exposed[e]=d)}function F(e){return(r,n=i.getCurrentInstance())=>he(e,r,n)}const me=F(Y),ye=F(X),ke=F(Z),pe=F(N);function Re(){const e=i.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 O(){const e=i.inject(C);if(!e)throw new Error("RouterOutlet must be used with createStackRouter().");return e}function I(e,r){const n=e.value;if(!n)return;const l=n[r];Array.isArray(l)?l.forEach(d=>d()):typeof l=="function"&&l.call(n)}function D(e){e.classList.remove("rs-page-hidden","rs-page-invisible"),e.removeAttribute("aria-hidden")}function z(e){e.classList.add("rs-page-hidden"),e.setAttribute("aria-hidden","true")}function ee(e){var r;return(r=e.components)==null?void 0:r.default}function be(e){const r=ee(e);return r!==void 0&&typeof r=="object"&&"name"in r&&r.name==="RouterView"}const Pe=i.defineComponent({name:"RouterOutlet",setup(){const e=O(),r=b.useRoute(),n=i.inject(b.routeLocationKey),l=i.inject(b.matchedRouteKey,void 0),d=i.computed(()=>{const t=l==null?void 0:l.value;if(!t)return 0;const o=r.matched.findIndex(m=>m===t);return o>=0?o+1:0}),T=i.computed(()=>r.matched[d.value]),S=i.computed(()=>{for(let t=d.value;t<r.matched.length;t++){const o=r.matched[t];if(!be(o))return o}return T.value}),R=i.shallowRef([]),E=i.ref("");let h=0;i.provide(b.matchedRouteKey,S);const s=t=>R.value.find(o=>o.stackEntryId===t),g=t=>{R.value.forEach(o=>{o.pageElement&&(o===t?D(o.pageElement):z(o.pageElement))})},P=t=>{const o=R.value.findIndex(m=>m===t);o>=0&&(R.value=R.value.slice(0,o+1))},W=t=>{R.value=R.value.filter(o=>o!==t)},L=t=>{const o=new Set(e.history.map(m=>m.id));R.value=R.value.filter(m=>m===t||m.routeInfo.cache&&o.has(m.stackEntryId))},x=t=>{var m;const o=t.props.default;return o?o===!0?((m=e.current.value)==null?void 0:m.params)??{}:typeof o=="function"?o(n):o:{}},G=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,A=t=>t.entryDirection==="none"||t.entryDirection==="root"||t.transition==="none",j=(t,o)=>!(t.routeInfo.isStackFallback||t.routeInfo.direction==="none"||t.routeInfo.direction==="root"||t.routeInfo.action==="pop"&&(A(t.routeInfo)||A(o.routeInfo))),V=(t,o)=>{var k;const m=j(t,o);return((k=e.shouldTransition)==null?void 0:k.call(e,{action:t.routeInfo.action,direction:t.routeInfo.direction,source:t.routeInfo.source,entering:t.routeInfo,leaving:o.routeInfo,defaultResult:m}))??m},$=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transitionDuration??t.routeInfo.transitionDuration??e.transitionDuration:t.routeInfo.transitionDuration??e.transitionDuration,K=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transitionEasing??t.routeInfo.transitionEasing??e.transitionEasing:t.routeInfo.transitionEasing??e.transitionEasing,_=async(t,o)=>{const m=++h;await i.nextTick();const k=t.pageElement;if(!k)return;if(I(t.componentRef,Y),!o||o===t||!o.pageElement){D(k),I(t.componentRef,X),L(t),g(t);return}const p=o.pageElement,B=V(t,o),c=B?G(t,o):"none",a=B?$(t,o):0,u=K(t,o),f=ue(c||v,e.transitions);I(o.componentRef,Z),D(k),D(p),await le(f,{direction:t.routeInfo.direction,action:t.routeInfo.action,routeInfo:t.routeInfo,enteringElement:k,leavingElement:p,duration:a,easing:u}),m===h&&(z(p),I(o.componentRef,N),I(t.componentRef,X),t.routeInfo.action==="pop"?P(t):t.routeInfo.action==="replace"&&W(o),L(t),g(t))},H=async()=>{const t=S.value,o=e.current.value;if(!t||!o)return;const m=ee(t);if(!m)return;const k=s(E.value);let p=s(o.id);p?(p.routeInfo=o,p.matchedRoute=t,p.component=m,p.props=x(t),p.mounted=!0):(p={id:U("view"),stackEntryId:o.id,routeInfo:o,matchedRoute:t,component:m,props:x(t),componentRef:i.ref(),mounted:!0},R.value=[...R.value,p]),E.value=p.stackEntryId,await _(p,k)};return i.watch(()=>{var t;return[(t=e.current.value)==null?void 0:t.id,S.value]},()=>{H()},{immediate:!0}),i.onUnmounted(()=>{h++,R.value=[]}),{injectedRoute:n,viewItems:R,registerStackPage:(t,o)=>{t.pageElement=o,t.stackEntryId===E.value?D(o):z(o)}}},render(){return i.h("div",{class:"rs-outlet"},this.viewItems.filter(e=>e.mounted).map(e=>i.h(e.component,{key:e.id,ref:e.componentRef,...e.props,registerStackPage:r=>this.registerStackPage(e,r)})))}}),Ee=i.defineComponent({name:"RouterPage",props:{registerStackPage:{type:Function,default:void 0}},setup(e,{attrs:r,slots:n}){const l=i.ref();return i.onMounted(()=>{var d;l.value&&((d=e.registerStackPage)==null||d.call(e,l.value))}),()=>{var d;return i.h("section",{...r,ref:l,class:["rs-page",r.class]},(d=n.default)==null?void 0:d.call(n))}}}),we=i.defineComponent({name:"StackRouterDebugPanel",props:{initialOpen:{type:Boolean,default:!1}},setup(e){const r=O(),n=i.ref(e.initialOpen);return()=>{const l=r.current.value;return i.h("aside",{class:"rs-debug-panel"},[i.h("button",{class:"rs-debug-toggle",type:"button",onClick:()=>{n.value=!n.value}},n.value?"Stack x":"Stack"),n.value?i.h("section",{class:"rs-debug-body"},[i.h("header",[i.h("strong","Router Stack"),i.h("span",`${r.history.length} pages`)]),i.h("dl",[i.h("dt","current"),i.h("dd",(l==null?void 0:l.fullPath)??"-"),i.h("dt","canGoBack"),i.h("dd",String(r.canGoBack()))]),i.h("ol",r.history.map(d=>i.h("li",{key:d.id,class:{"rs-debug-active":d.id===(l==null?void 0:l.id),"rs-debug-no-cache":!d.cache}},[i.h("code",d.fullPath),i.h("span",[`${d.action}/${d.direction}`,` source:${d.source}`,` entry:${d.entryDirection}`,` cache:${d.cache?"yes":"no"}`,` transition:${d.transition??"-"}`])])))]):void 0])}}});Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>b.RouterLink});Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>b.RouterView});Object.defineProperty(exports,"createMemoryHistory",{enumerable:!0,get:()=>b.createMemoryHistory});Object.defineProperty(exports,"createWebHashHistory",{enumerable:!0,get:()=>b.createWebHashHistory});Object.defineProperty(exports,"createWebHistory",{enumerable:!0,get:()=>b.createWebHistory});Object.defineProperty(exports,"useRoute",{enumerable:!0,get:()=>b.useRoute});Object.defineProperty(exports,"useRouter",{enumerable:!0,get:()=>b.useRouter});exports.RouterOutlet=Pe;exports.RouterPage=Ee;exports.StackRouterDebugPanel=we;exports.createStackRouter=fe;exports.defineStackTransition=oe;exports.onPageDidEnter=ye;exports.onPageDidLeave=pe;exports.onPageWillEnter=me;exports.onPageWillLeave=ke;exports.stackRouterKey=C;exports.useStackRouter=Re;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.rs-outlet{position:relative;display:block;width:100%;height:100%;overflow:hidden;contain:layout size style}.rs-page{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;min-width:0;min-height:0;flex-direction:column;overflow:hidden;
|
|
1
|
+
.rs-outlet{position:relative;display:block;width:100%;height:100%;overflow:hidden;contain:layout size style}.rs-page{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;min-width:0;min-height:0;flex-direction:column;overflow:hidden;z-index:0}.rs-page-hidden,[hidden].rs-page{display:none!important}.rs-page-invisible{opacity:0}.rs-debug-panel{position:fixed;right:12px;bottom:12px;z-index:9999;color:#d9e5ef;font:12px/1.45 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,monospace}.rs-debug-toggle{min-width:72px;border:0;border-radius:6px;padding:8px 10px;color:#f8fafc;background:#111827;cursor:pointer}.rs-debug-body{width:min(420px,calc(100vw - 24px));max-height:min(520px,calc(100vh - 96px));overflow:auto;margin-top:8px;border:1px solid rgb(148 163 184 / 28%);border-radius:8px;padding:12px;background:#0f172af0;box-shadow:0 18px 48px #0f172a4d}.rs-debug-body header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px}.rs-debug-body dl{display:grid;grid-template-columns:auto minmax(0,1fr);gap:4px 10px;margin:0 0 10px}.rs-debug-body dt{color:#94a3b8}.rs-debug-body dd{min-width:0;margin:0;overflow-wrap:anywhere}.rs-debug-body ol{display:grid;gap:6px;margin:0;padding:0;list-style:none}.rs-debug-body li{display:grid;gap:3px;border-radius:6px;padding:7px;background:#ffffff0f}.rs-debug-body code{overflow-wrap:anywhere;color:#f8fafc}.rs-debug-body li span{color:#a7b7c8}.rs-debug-body .rs-debug-active{background:#14b8a638}.rs-debug-body .rs-debug-no-cache{outline:1px solid rgb(248 113 113 / 55%)}
|
package/dist/vue-router-stack.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
import { shallowRef as tt, getCurrentInstance as
|
|
2
|
-
import { createRouter as ht, useRoute as mt, routeLocationKey as
|
|
3
|
-
import { RouterLink as
|
|
1
|
+
import { shallowRef as tt, getCurrentInstance as it, inject as G, defineComponent as Q, h as y, computed as U, ref as C, provide as st, watch as ut, onUnmounted as lt, nextTick as dt, onMounted as ft } from "vue";
|
|
2
|
+
import { createRouter as ht, useRoute as mt, routeLocationKey as kt, matchedRouteKey as v } from "vue-router";
|
|
3
|
+
import { RouterLink as jt, RouterView as zt, createMemoryHistory as Ut, createWebHashHistory as Xt, createWebHistory as Mt, useRoute as qt, useRouter as Jt } from "vue-router";
|
|
4
4
|
const N = {};
|
|
5
5
|
function q(t = "route") {
|
|
6
6
|
const r = (N[t] ?? 0) + 1;
|
|
7
7
|
return N[t] = r, `${t}-${r}`;
|
|
8
8
|
}
|
|
9
|
-
const Y = "slide",
|
|
9
|
+
const Y = "slide", yt = "cubic-bezier(0.3, 0, 0.66, 1)";
|
|
10
10
|
function Lt(t) {
|
|
11
11
|
return t;
|
|
12
12
|
}
|
|
13
|
-
const pt = ({ direction: t }) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
] : [
|
|
24
|
-
{ transform: "translateX(0)", opacity: 1 },
|
|
25
|
-
{ transform: "translateX(-18%)", opacity: 0.96 }
|
|
26
|
-
]
|
|
27
|
-
};
|
|
13
|
+
const pt = ({ direction: t }) => t === "back" ? {
|
|
14
|
+
leaving: [
|
|
15
|
+
{ transform: "translateX(0)" },
|
|
16
|
+
{ transform: "translateX(100%)" }
|
|
17
|
+
]
|
|
18
|
+
} : {
|
|
19
|
+
entering: [
|
|
20
|
+
{ transform: "translateX(100%)" },
|
|
21
|
+
{ transform: "translateX(0)" }
|
|
22
|
+
]
|
|
28
23
|
}, Rt = () => ({
|
|
29
24
|
entering: [{ opacity: 0 }, { opacity: 1 }],
|
|
30
25
|
leaving: [{ opacity: 1 }, { opacity: 0 }]
|
|
31
|
-
}),
|
|
26
|
+
}), Et = ({ direction: t }) => {
|
|
32
27
|
const r = t === "back";
|
|
33
28
|
return {
|
|
34
29
|
entering: r ? [
|
|
@@ -46,11 +41,11 @@ const pt = ({ direction: t }) => {
|
|
|
46
41
|
{ transform: "scale(0.98)", opacity: 0 }
|
|
47
42
|
]
|
|
48
43
|
};
|
|
49
|
-
},
|
|
44
|
+
}, bt = () => ({}), Pt = {
|
|
50
45
|
slide: pt,
|
|
51
46
|
fade: Rt,
|
|
52
|
-
scale:
|
|
53
|
-
none:
|
|
47
|
+
scale: Et,
|
|
48
|
+
none: bt
|
|
54
49
|
};
|
|
55
50
|
function wt(t, r) {
|
|
56
51
|
const n = r[t];
|
|
@@ -79,28 +74,28 @@ function St() {
|
|
|
79
74
|
const t = window.history.state;
|
|
80
75
|
return typeof (t == null ? void 0 : t.position) == "number" ? t.position : window.history.length;
|
|
81
76
|
}
|
|
82
|
-
function
|
|
77
|
+
function X(t, r) {
|
|
83
78
|
return r || (t === "pop" ? "back" : t === "replace" ? "none" : "forward");
|
|
84
79
|
}
|
|
85
80
|
function At(t) {
|
|
86
|
-
const r = ht(t), n = [], u = tt(), l = t.transitionDuration ??
|
|
81
|
+
const r = ht(t), n = [], u = tt(), l = t.transitionDuration ?? 210, T = t.transitionEasing ?? yt, w = t.transition ?? Y, R = {
|
|
87
82
|
...Pt,
|
|
88
83
|
...t.transitions
|
|
89
|
-
},
|
|
90
|
-
let f = -1,
|
|
91
|
-
const
|
|
92
|
-
|
|
84
|
+
}, b = t.maxStackSize ?? 30;
|
|
85
|
+
let f = -1, i, I = !1;
|
|
86
|
+
const E = (c, a, s, d, m = !1, P = "stack") => {
|
|
87
|
+
i = {
|
|
93
88
|
action: c,
|
|
94
|
-
direction:
|
|
89
|
+
direction: X(c, a),
|
|
95
90
|
source: P,
|
|
96
|
-
delta:
|
|
91
|
+
delta: s,
|
|
97
92
|
transition: d == null ? void 0 : d.transition,
|
|
98
93
|
duration: d == null ? void 0 : d.duration,
|
|
99
94
|
easing: d == null ? void 0 : d.easing,
|
|
100
|
-
resetRoot:
|
|
95
|
+
resetRoot: m
|
|
101
96
|
};
|
|
102
|
-
},
|
|
103
|
-
const
|
|
97
|
+
}, V = (c, a) => {
|
|
98
|
+
const s = (i == null ? void 0 : i.action) ?? "push", d = X(s, i == null ? void 0 : i.direction), m = u.value, P = s === "push" && d === "forward", ct = g(c);
|
|
104
99
|
return {
|
|
105
100
|
id: q("route"),
|
|
106
101
|
key: c.fullPath,
|
|
@@ -108,52 +103,52 @@ function At(t) {
|
|
|
108
103
|
pathname: c.path,
|
|
109
104
|
params: c.params,
|
|
110
105
|
query: c.query,
|
|
111
|
-
action:
|
|
106
|
+
action: s,
|
|
112
107
|
direction: d,
|
|
113
|
-
source: (
|
|
108
|
+
source: (i == null ? void 0 : i.source) ?? "stack",
|
|
114
109
|
entryDirection: d,
|
|
115
|
-
lastPathname: (
|
|
116
|
-
pushedByRoute: P ?
|
|
110
|
+
lastPathname: (m == null ? void 0 : m.pathname) || (a.name ? a.path : void 0),
|
|
111
|
+
pushedByRoute: P ? m == null ? void 0 : m.pathname : m == null ? void 0 : m.pushedByRoute,
|
|
117
112
|
position: St(),
|
|
118
|
-
delta:
|
|
119
|
-
transition: (
|
|
120
|
-
transitionDuration: (
|
|
121
|
-
transitionEasing: (
|
|
113
|
+
delta: i == null ? void 0 : i.delta,
|
|
114
|
+
transition: (i == null ? void 0 : i.transition) ?? w,
|
|
115
|
+
transitionDuration: (i == null ? void 0 : i.duration) ?? l,
|
|
116
|
+
transitionEasing: (i == null ? void 0 : i.easing) ?? T,
|
|
122
117
|
cache: ct
|
|
123
118
|
};
|
|
124
119
|
}, g = (c) => {
|
|
125
120
|
const a = c.meta.stack;
|
|
126
121
|
return c.meta.stackCache !== !1 && (a == null ? void 0 : a.cache) !== !1;
|
|
127
122
|
}, x = () => {
|
|
128
|
-
if (
|
|
129
|
-
const c = n.length -
|
|
123
|
+
if (b <= 0 || n.length <= b) return;
|
|
124
|
+
const c = n.length - b;
|
|
130
125
|
n.splice(0, c), f = Math.max(0, f - c);
|
|
131
|
-
},
|
|
126
|
+
}, $ = (c) => {
|
|
132
127
|
if (c.action === "pop") {
|
|
133
128
|
let a = -1;
|
|
134
129
|
if (c.direction === "forward" || (c.delta ?? 0) > 0) {
|
|
135
|
-
for (let
|
|
136
|
-
if (n[
|
|
137
|
-
a =
|
|
130
|
+
for (let s = f + 1; s < n.length; s++)
|
|
131
|
+
if (n[s].key === c.key) {
|
|
132
|
+
a = s;
|
|
138
133
|
break;
|
|
139
134
|
}
|
|
140
135
|
} else
|
|
141
|
-
for (let
|
|
142
|
-
if (n[
|
|
143
|
-
a =
|
|
136
|
+
for (let s = f - 1; s >= 0; s--)
|
|
137
|
+
if (n[s].key === c.key) {
|
|
138
|
+
a = s;
|
|
144
139
|
break;
|
|
145
140
|
}
|
|
146
141
|
if (a >= 0) {
|
|
147
|
-
const
|
|
142
|
+
const s = n[a];
|
|
148
143
|
n[a] = {
|
|
149
|
-
...
|
|
144
|
+
...s,
|
|
150
145
|
...c,
|
|
151
|
-
id:
|
|
146
|
+
id: s.id,
|
|
152
147
|
source: c.source,
|
|
153
|
-
entryDirection:
|
|
154
|
-
transition:
|
|
155
|
-
transitionDuration:
|
|
156
|
-
transitionEasing:
|
|
148
|
+
entryDirection: s.entryDirection,
|
|
149
|
+
transition: s.transition,
|
|
150
|
+
transitionDuration: s.transitionDuration,
|
|
151
|
+
transitionEasing: s.transitionEasing
|
|
157
152
|
}, f = a;
|
|
158
153
|
} else
|
|
159
154
|
n.push({
|
|
@@ -164,7 +159,7 @@ function At(t) {
|
|
|
164
159
|
isStackFallback: !0
|
|
165
160
|
}), f = n.length - 1;
|
|
166
161
|
} else if (c.action === "replace") {
|
|
167
|
-
if (
|
|
162
|
+
if (i != null && i.resetRoot) {
|
|
168
163
|
n.splice(0, n.length, c), f = 0, u.value = n[f];
|
|
169
164
|
return;
|
|
170
165
|
}
|
|
@@ -173,56 +168,56 @@ function At(t) {
|
|
|
173
168
|
f < n.length - 1 && n.splice(f + 1), n.push(c), f = n.length - 1;
|
|
174
169
|
x(), u.value = n[f];
|
|
175
170
|
};
|
|
176
|
-
t.history.listen((c, a,
|
|
177
|
-
const d = "delta" in
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
)) :
|
|
182
|
-
|
|
183
|
-
|
|
171
|
+
t.history.listen((c, a, s) => {
|
|
172
|
+
const d = "delta" in s ? s.delta : void 0, m = s.direction === "back" ? "back" : s.direction === "forward" ? "forward" : void 0;
|
|
173
|
+
i ? (i.delta = d, i.direction = X(
|
|
174
|
+
i.action,
|
|
175
|
+
i.direction ?? m
|
|
176
|
+
)) : E(
|
|
177
|
+
s.type === "pop" ? "pop" : s.type,
|
|
178
|
+
m,
|
|
184
179
|
d,
|
|
185
180
|
void 0,
|
|
186
181
|
!1,
|
|
187
182
|
"external"
|
|
188
183
|
);
|
|
189
|
-
}), r.beforeEach((c) => !((
|
|
190
|
-
if (
|
|
191
|
-
|
|
184
|
+
}), r.beforeEach((c) => !((i == null ? void 0 : i.action) === "pop" && I && !n.some((a) => a.fullPath === c.fullPath))), r.afterEach((c, a, s) => {
|
|
185
|
+
if (s) {
|
|
186
|
+
i = void 0;
|
|
192
187
|
return;
|
|
193
188
|
}
|
|
194
|
-
|
|
189
|
+
$(V(c, a)), i = void 0;
|
|
195
190
|
});
|
|
196
|
-
const
|
|
191
|
+
const L = r.push.bind(r), A = r.replace.bind(r), W = r.back.bind(r), K = r.forward.bind(r), j = r.go.bind(r), _ = (c, a) => (E(
|
|
197
192
|
"push",
|
|
198
193
|
(a == null ? void 0 : a.direction) ?? "forward",
|
|
199
194
|
void 0,
|
|
200
195
|
a
|
|
201
|
-
),
|
|
196
|
+
), L(c)), B = (c, a) => (E(
|
|
202
197
|
"replace",
|
|
203
198
|
(a == null ? void 0 : a.direction) ?? "root",
|
|
204
199
|
void 0,
|
|
205
200
|
a
|
|
206
|
-
),
|
|
207
|
-
const
|
|
201
|
+
), A(c)), z = (c, a) => {
|
|
202
|
+
const s = r.resolve(c).fullPath;
|
|
208
203
|
let d = -1;
|
|
209
204
|
for (let P = f; P >= 0; P--)
|
|
210
|
-
if (n[P].fullPath ===
|
|
205
|
+
if (n[P].fullPath === s) {
|
|
211
206
|
d = P;
|
|
212
207
|
break;
|
|
213
208
|
}
|
|
214
209
|
if (d < 0) return !1;
|
|
215
|
-
const
|
|
216
|
-
return
|
|
210
|
+
const m = d - f;
|
|
211
|
+
return m === 0 || (E(
|
|
217
212
|
"pop",
|
|
218
213
|
(a == null ? void 0 : a.direction) ?? "back",
|
|
219
|
-
|
|
214
|
+
m,
|
|
220
215
|
a
|
|
221
|
-
),
|
|
222
|
-
},
|
|
223
|
-
const
|
|
224
|
-
if (f >= 0 && r.currentRoute.value.fullPath ===
|
|
225
|
-
const d = n[f],
|
|
216
|
+
), j(m)), !0;
|
|
217
|
+
}, e = (c, a) => {
|
|
218
|
+
const s = r.resolve(c).fullPath;
|
|
219
|
+
if (f >= 0 && r.currentRoute.value.fullPath === s) {
|
|
220
|
+
const d = n[f], m = {
|
|
226
221
|
...d,
|
|
227
222
|
id: q("route"),
|
|
228
223
|
action: "replace",
|
|
@@ -236,44 +231,44 @@ function At(t) {
|
|
|
236
231
|
cache: !0,
|
|
237
232
|
isStackFallback: !1
|
|
238
233
|
};
|
|
239
|
-
return n.splice(0, n.length,
|
|
234
|
+
return n.splice(0, n.length, m), f = 0, I = !0, u.value = m, Promise.resolve(void 0);
|
|
240
235
|
}
|
|
241
|
-
return
|
|
236
|
+
return E(
|
|
242
237
|
"replace",
|
|
243
238
|
(a == null ? void 0 : a.direction) ?? "root",
|
|
244
239
|
void 0,
|
|
245
240
|
a,
|
|
246
241
|
!0
|
|
247
|
-
), I = !0,
|
|
242
|
+
), I = !0, A(c);
|
|
243
|
+
}, o = () => {
|
|
244
|
+
E("pop", "back", -1), W();
|
|
248
245
|
}, h = () => {
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const _ = {
|
|
255
|
-
router: m,
|
|
246
|
+
E("pop", "forward", 1), K();
|
|
247
|
+
}, k = r;
|
|
248
|
+
k.push = _, k.replace = B, k.popTo = z, k.resetRoot = e, k.back = o, k.forward = h;
|
|
249
|
+
const p = {
|
|
250
|
+
router: k,
|
|
256
251
|
transitionDuration: l,
|
|
257
252
|
transitionEasing: T,
|
|
258
253
|
transition: w,
|
|
259
|
-
transitions:
|
|
260
|
-
maxStackSize:
|
|
254
|
+
transitions: R,
|
|
255
|
+
maxStackSize: b,
|
|
261
256
|
shouldTransition: t.shouldTransition,
|
|
262
257
|
current: u,
|
|
263
258
|
get history() {
|
|
264
259
|
return n;
|
|
265
260
|
},
|
|
266
261
|
canGoBack: (c = 1) => f - c >= 0,
|
|
267
|
-
push:
|
|
268
|
-
replace:
|
|
269
|
-
popTo:
|
|
270
|
-
resetRoot:
|
|
271
|
-
back:
|
|
272
|
-
forward:
|
|
273
|
-
},
|
|
262
|
+
push: _,
|
|
263
|
+
replace: B,
|
|
264
|
+
popTo: z,
|
|
265
|
+
resetRoot: e,
|
|
266
|
+
back: o,
|
|
267
|
+
forward: h
|
|
268
|
+
}, F = r.install.bind(r);
|
|
274
269
|
return r.install = (c) => {
|
|
275
|
-
c.provide(Z,
|
|
276
|
-
},
|
|
270
|
+
c.provide(Z, p), F(c);
|
|
271
|
+
}, k;
|
|
277
272
|
}
|
|
278
273
|
const et = "onPageWillEnter", J = "onPageDidEnter", rt = "onPageWillLeave", ot = "onPageDidLeave";
|
|
279
274
|
function Dt(t, r, n) {
|
|
@@ -284,12 +279,12 @@ function Dt(t, r, n) {
|
|
|
284
279
|
n.isUnmounted || r();
|
|
285
280
|
}), u[t] = l, n.exposed && (n.exposed[t] = l);
|
|
286
281
|
}
|
|
287
|
-
function
|
|
288
|
-
return (r, n =
|
|
282
|
+
function H(t) {
|
|
283
|
+
return (r, n = it()) => Dt(t, r, n);
|
|
289
284
|
}
|
|
290
|
-
const _t =
|
|
285
|
+
const _t = H(et), Bt = H(J), Ft = H(rt), Gt = H(ot);
|
|
291
286
|
function Ct() {
|
|
292
|
-
const t =
|
|
287
|
+
const t = G(Z);
|
|
293
288
|
if (!t)
|
|
294
289
|
throw new Error("useStackRouter must be used after createStackRouter().");
|
|
295
290
|
return {
|
|
@@ -304,7 +299,7 @@ function Ct() {
|
|
|
304
299
|
};
|
|
305
300
|
}
|
|
306
301
|
function nt() {
|
|
307
|
-
const t =
|
|
302
|
+
const t = G(Z);
|
|
308
303
|
if (!t)
|
|
309
304
|
throw new Error("RouterOutlet must be used with createStackRouter().");
|
|
310
305
|
return t;
|
|
@@ -332,47 +327,47 @@ function Tt(t) {
|
|
|
332
327
|
const Ht = Q({
|
|
333
328
|
name: "RouterOutlet",
|
|
334
329
|
setup() {
|
|
335
|
-
const t = nt(), r = mt(), n =
|
|
330
|
+
const t = nt(), r = mt(), n = G(kt), u = G(v, void 0), l = U(() => {
|
|
336
331
|
const e = u == null ? void 0 : u.value;
|
|
337
332
|
if (!e) return 0;
|
|
338
333
|
const o = r.matched.findIndex(
|
|
339
334
|
(h) => h === e
|
|
340
335
|
);
|
|
341
336
|
return o >= 0 ? o + 1 : 0;
|
|
342
|
-
}), T =
|
|
337
|
+
}), T = U(() => r.matched[l.value]), w = U(() => {
|
|
343
338
|
for (let e = l.value; e < r.matched.length; e++) {
|
|
344
339
|
const o = r.matched[e];
|
|
345
340
|
if (!Tt(o))
|
|
346
341
|
return o;
|
|
347
342
|
}
|
|
348
343
|
return T.value;
|
|
349
|
-
}),
|
|
344
|
+
}), R = tt([]), b = C("");
|
|
350
345
|
let f = 0;
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
346
|
+
st(v, w);
|
|
347
|
+
const i = (e) => R.value.find((o) => o.stackEntryId === e), I = (e) => {
|
|
348
|
+
R.value.forEach((o) => {
|
|
354
349
|
o.pageElement && (o === e ? D(o.pageElement) : M(o.pageElement));
|
|
355
350
|
});
|
|
356
|
-
},
|
|
357
|
-
const o =
|
|
358
|
-
o >= 0 && (
|
|
359
|
-
},
|
|
360
|
-
|
|
351
|
+
}, E = (e) => {
|
|
352
|
+
const o = R.value.findIndex((h) => h === e);
|
|
353
|
+
o >= 0 && (R.value = R.value.slice(0, o + 1));
|
|
354
|
+
}, V = (e) => {
|
|
355
|
+
R.value = R.value.filter((o) => o !== e);
|
|
361
356
|
}, g = (e) => {
|
|
362
357
|
const o = new Set(
|
|
363
|
-
t.history.map((h) => h.
|
|
358
|
+
t.history.map((h) => h.id)
|
|
364
359
|
);
|
|
365
|
-
|
|
366
|
-
(h) => h === e || h.routeInfo.cache && o.has(h.
|
|
360
|
+
R.value = R.value.filter(
|
|
361
|
+
(h) => h === e || h.routeInfo.cache && o.has(h.stackEntryId)
|
|
367
362
|
);
|
|
368
363
|
}, x = (e) => {
|
|
369
364
|
var h;
|
|
370
365
|
const o = e.props.default;
|
|
371
366
|
return o ? o === !0 ? ((h = t.current.value) == null ? void 0 : h.params) ?? {} : typeof o == "function" ? o(n) : o : {};
|
|
372
|
-
},
|
|
373
|
-
var
|
|
374
|
-
const h =
|
|
375
|
-
return ((
|
|
367
|
+
}, $ = (e, o) => e.routeInfo.action === "pop" ? o.routeInfo.transition ?? e.routeInfo.transition ?? t.transition : e.routeInfo.transition ?? t.transition, L = (e) => e.entryDirection === "none" || e.entryDirection === "root" || e.transition === "none", A = (e, o) => !(e.routeInfo.isStackFallback || e.routeInfo.direction === "none" || e.routeInfo.direction === "root" || e.routeInfo.action === "pop" && (L(e.routeInfo) || L(o.routeInfo))), W = (e, o) => {
|
|
368
|
+
var k;
|
|
369
|
+
const h = A(e, o);
|
|
370
|
+
return ((k = t.shouldTransition) == null ? void 0 : k.call(t, {
|
|
376
371
|
action: e.routeInfo.action,
|
|
377
372
|
direction: e.routeInfo.direction,
|
|
378
373
|
source: e.routeInfo.source,
|
|
@@ -380,45 +375,45 @@ const Ht = Q({
|
|
|
380
375
|
leaving: o.routeInfo,
|
|
381
376
|
defaultResult: h
|
|
382
377
|
})) ?? h;
|
|
383
|
-
},
|
|
378
|
+
}, K = (e, o) => e.routeInfo.action === "pop" ? o.routeInfo.transitionDuration ?? e.routeInfo.transitionDuration ?? t.transitionDuration : e.routeInfo.transitionDuration ?? t.transitionDuration, j = (e, o) => e.routeInfo.action === "pop" ? o.routeInfo.transitionEasing ?? e.routeInfo.transitionEasing ?? t.transitionEasing : e.routeInfo.transitionEasing ?? t.transitionEasing, _ = async (e, o) => {
|
|
384
379
|
const h = ++f;
|
|
385
|
-
await
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
380
|
+
await dt();
|
|
381
|
+
const k = e.pageElement;
|
|
382
|
+
if (!k) return;
|
|
388
383
|
if (S(e.componentRef, et), !o || o === e || !o.pageElement) {
|
|
389
|
-
D(
|
|
384
|
+
D(k), S(e.componentRef, J), g(e), I(e);
|
|
390
385
|
return;
|
|
391
386
|
}
|
|
392
|
-
const
|
|
393
|
-
|
|
387
|
+
const p = o.pageElement, F = W(e, o), c = F ? $(e, o) : "none", a = F ? K(e, o) : 0, s = j(e, o), d = wt(
|
|
388
|
+
c || Y,
|
|
394
389
|
t.transitions
|
|
395
390
|
);
|
|
396
|
-
S(o.componentRef, rt), D(
|
|
391
|
+
S(o.componentRef, rt), D(k), D(p), await It(d, {
|
|
397
392
|
direction: e.routeInfo.direction,
|
|
398
393
|
action: e.routeInfo.action,
|
|
399
394
|
routeInfo: e.routeInfo,
|
|
400
|
-
enteringElement:
|
|
401
|
-
leavingElement:
|
|
402
|
-
duration:
|
|
403
|
-
easing:
|
|
404
|
-
}), h === f && (M(
|
|
405
|
-
},
|
|
395
|
+
enteringElement: k,
|
|
396
|
+
leavingElement: p,
|
|
397
|
+
duration: a,
|
|
398
|
+
easing: s
|
|
399
|
+
}), h === f && (M(p), S(o.componentRef, ot), S(e.componentRef, J), e.routeInfo.action === "pop" ? E(e) : e.routeInfo.action === "replace" && V(o), g(e), I(e));
|
|
400
|
+
}, B = async () => {
|
|
406
401
|
const e = w.value, o = t.current.value;
|
|
407
402
|
if (!e || !o) return;
|
|
408
403
|
const h = at(e);
|
|
409
404
|
if (!h) return;
|
|
410
|
-
const
|
|
411
|
-
let
|
|
412
|
-
|
|
405
|
+
const k = i(b.value);
|
|
406
|
+
let p = i(o.id);
|
|
407
|
+
p ? (p.routeInfo = o, p.matchedRoute = e, p.component = h, p.props = x(e), p.mounted = !0) : (p = {
|
|
413
408
|
id: q("view"),
|
|
414
|
-
|
|
409
|
+
stackEntryId: o.id,
|
|
415
410
|
routeInfo: o,
|
|
416
411
|
matchedRoute: e,
|
|
417
412
|
component: h,
|
|
418
413
|
props: x(e),
|
|
419
|
-
componentRef:
|
|
414
|
+
componentRef: C(),
|
|
420
415
|
mounted: !0
|
|
421
|
-
},
|
|
416
|
+
}, R.value = [...R.value, p]), b.value = p.stackEntryId, await _(p, k);
|
|
422
417
|
};
|
|
423
418
|
return ut(
|
|
424
419
|
() => {
|
|
@@ -426,25 +421,25 @@ const Ht = Q({
|
|
|
426
421
|
return [(e = t.current.value) == null ? void 0 : e.id, w.value];
|
|
427
422
|
},
|
|
428
423
|
() => {
|
|
429
|
-
|
|
424
|
+
B();
|
|
430
425
|
},
|
|
431
426
|
{ immediate: !0 }
|
|
432
427
|
), lt(() => {
|
|
433
|
-
f++,
|
|
428
|
+
f++, R.value = [];
|
|
434
429
|
}), {
|
|
435
430
|
injectedRoute: n,
|
|
436
|
-
viewItems:
|
|
431
|
+
viewItems: R,
|
|
437
432
|
registerStackPage: (e, o) => {
|
|
438
|
-
e.pageElement = o, e.
|
|
433
|
+
e.pageElement = o, e.stackEntryId === b.value ? D(o) : M(o);
|
|
439
434
|
}
|
|
440
435
|
};
|
|
441
436
|
},
|
|
442
437
|
render() {
|
|
443
|
-
return
|
|
438
|
+
return y(
|
|
444
439
|
"div",
|
|
445
440
|
{ class: "rs-outlet" },
|
|
446
441
|
this.viewItems.filter((t) => t.mounted).map(
|
|
447
|
-
(t) =>
|
|
442
|
+
(t) => y(t.component, {
|
|
448
443
|
key: t.id,
|
|
449
444
|
ref: t.componentRef,
|
|
450
445
|
...t.props,
|
|
@@ -462,13 +457,13 @@ const Ht = Q({
|
|
|
462
457
|
}
|
|
463
458
|
},
|
|
464
459
|
setup(t, { attrs: r, slots: n }) {
|
|
465
|
-
const u =
|
|
466
|
-
return
|
|
460
|
+
const u = C();
|
|
461
|
+
return ft(() => {
|
|
467
462
|
var l;
|
|
468
463
|
u.value && ((l = t.registerStackPage) == null || l.call(t, u.value));
|
|
469
464
|
}), () => {
|
|
470
465
|
var l;
|
|
471
|
-
return
|
|
466
|
+
return y(
|
|
472
467
|
"section",
|
|
473
468
|
{
|
|
474
469
|
...r,
|
|
@@ -488,11 +483,11 @@ const Ht = Q({
|
|
|
488
483
|
}
|
|
489
484
|
},
|
|
490
485
|
setup(t) {
|
|
491
|
-
const r = nt(), n =
|
|
486
|
+
const r = nt(), n = C(t.initialOpen);
|
|
492
487
|
return () => {
|
|
493
488
|
const u = r.current.value;
|
|
494
|
-
return
|
|
495
|
-
|
|
489
|
+
return y("aside", { class: "rs-debug-panel" }, [
|
|
490
|
+
y(
|
|
496
491
|
"button",
|
|
497
492
|
{
|
|
498
493
|
class: "rs-debug-toggle",
|
|
@@ -503,21 +498,21 @@ const Ht = Q({
|
|
|
503
498
|
},
|
|
504
499
|
n.value ? "Stack x" : "Stack"
|
|
505
500
|
),
|
|
506
|
-
n.value ?
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
501
|
+
n.value ? y("section", { class: "rs-debug-body" }, [
|
|
502
|
+
y("header", [
|
|
503
|
+
y("strong", "Router Stack"),
|
|
504
|
+
y("span", `${r.history.length} pages`)
|
|
510
505
|
]),
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
506
|
+
y("dl", [
|
|
507
|
+
y("dt", "current"),
|
|
508
|
+
y("dd", (u == null ? void 0 : u.fullPath) ?? "-"),
|
|
509
|
+
y("dt", "canGoBack"),
|
|
510
|
+
y("dd", String(r.canGoBack()))
|
|
516
511
|
]),
|
|
517
|
-
|
|
512
|
+
y(
|
|
518
513
|
"ol",
|
|
519
514
|
r.history.map(
|
|
520
|
-
(l) =>
|
|
515
|
+
(l) => y(
|
|
521
516
|
"li",
|
|
522
517
|
{
|
|
523
518
|
key: l.id,
|
|
@@ -527,8 +522,8 @@ const Ht = Q({
|
|
|
527
522
|
}
|
|
528
523
|
},
|
|
529
524
|
[
|
|
530
|
-
|
|
531
|
-
|
|
525
|
+
y("code", l.fullPath),
|
|
526
|
+
y("span", [
|
|
532
527
|
`${l.action}/${l.direction}`,
|
|
533
528
|
` source:${l.source}`,
|
|
534
529
|
` entry:${l.entryDirection}`,
|
|
@@ -545,20 +540,20 @@ const Ht = Q({
|
|
|
545
540
|
}
|
|
546
541
|
});
|
|
547
542
|
export {
|
|
548
|
-
|
|
543
|
+
jt as RouterLink,
|
|
549
544
|
Ht as RouterOutlet,
|
|
550
545
|
Vt as RouterPage,
|
|
551
|
-
|
|
546
|
+
zt as RouterView,
|
|
552
547
|
$t as StackRouterDebugPanel,
|
|
553
|
-
|
|
548
|
+
Ut as createMemoryHistory,
|
|
554
549
|
At as createStackRouter,
|
|
555
|
-
|
|
550
|
+
Xt as createWebHashHistory,
|
|
556
551
|
Mt as createWebHistory,
|
|
557
552
|
Lt as defineStackTransition,
|
|
558
|
-
|
|
553
|
+
Bt as onPageDidEnter,
|
|
559
554
|
Gt as onPageDidLeave,
|
|
560
555
|
_t as onPageWillEnter,
|
|
561
|
-
|
|
556
|
+
Ft as onPageWillLeave,
|
|
562
557
|
Z as stackRouterKey,
|
|
563
558
|
qt as useRoute,
|
|
564
559
|
Jt as useRouter,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazycatcloud/vue-router-stack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Page stack, caching, transitions, and lifecycle utilities built on vue-router.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -32,13 +32,17 @@
|
|
|
32
32
|
"keep-alive"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"dev": "vite --config demo/vite.config.ts --port
|
|
35
|
+
"dev": "vite --config demo/vite.config.ts --port 2389 --host",
|
|
36
36
|
"build": "pnpm run type-check && pnpm run build:lib && pnpm run build:demo",
|
|
37
37
|
"build:lib": "vite build && vue-tsc --declaration --emitDeclarationOnly -p tsconfig.build.json",
|
|
38
38
|
"build:demo": "vite build --config demo/vite.config.ts",
|
|
39
39
|
"type-check": "vue-tsc --noEmit -p tsconfig.app.json",
|
|
40
40
|
"test": "vitest run"
|
|
41
41
|
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"registry": "https://registry.npmjs.org/"
|
|
45
|
+
},
|
|
42
46
|
"peerDependencies": {
|
|
43
47
|
"vue": "^3.3.0",
|
|
44
48
|
"vue-router": "^4.2.0"
|