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