@lazycatcloud/vue-router-stack 0.0.2 → 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
- key: string;
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 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 q(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??210,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:q(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}},C=(c,a)=>{const u=(s==null?void 0:s.action)??"push",h=q(u,s==null?void 0:s.direction),k=l.value,w=u==="push"&&h==="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: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)},F=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=q(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}F(C(c,a)),s=void 0});const W=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),W(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: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)??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},M=r.install.bind(r);return r.install=c=>{c.provide(H,_),M(c)},y}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,f=l[e]??[];f.push(()=>{n.isUnmounted||r()}),l[e]=f,n.exposed&&(n.exposed[e]=f)}function B(e){return(r,n=i.getCurrentInstance())=>he(e,r,n)}const me=B(Y),ye=B(X),ke=B(Z),pe=B(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 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),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):z(o.pageElement))})},P=t=>{const o=p.value.findIndex(m=>m===t);o>=0&&(p.value=p.value.slice(0,o+1))},C=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:{}},F=(t,o)=>t.routeInfo.action==="pop"?o.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,W=(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=W(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,X),L(t),g(t);return}const y=o.pageElement,_=A(t,o),M=_?F(t,o):"none",c=_?G(t,o):0,a=V(t,o),u=ue(M||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&&(z(y),D(o.componentRef,N),D(t.componentRef,X),t.routeInfo.action==="pop"?P(t):t.routeInfo.action==="replace"&&C(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:U("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):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 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"),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;
@@ -1,16 +1,16 @@
1
- import { shallowRef as tt, getCurrentInstance as it, inject as B, defineComponent as Q, h as y, computed as U, ref as F, provide as st, watch as ut, onUnmounted as lt, nextTick as ft, onMounted as dt } 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
- const N = {};
5
- function q(t = "route") {
6
- const o = (N[t] ?? 0) + 1;
7
- return N[t] = o, `${t}-${o}`;
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", yt = "cubic-bezier(0.3, 0, 0.66, 1)";
10
- function Lt(t) {
11
- return t;
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: t }) => t === "back" ? {
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
- }), bt = ({ direction: t }) => {
27
- const o = t === "back";
26
+ }), Et = ({ direction: e }) => {
27
+ const n = e === "back";
28
28
  return {
29
- entering: o ? [
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: o ? [
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
- }, Et = () => ({}), Pt = {
44
+ }, wt = () => ({}), bt = {
45
45
  slide: pt,
46
46
  fade: Rt,
47
- scale: bt,
48
- none: Et
47
+ scale: Et,
48
+ none: wt
49
49
  };
50
- function wt(t, o) {
51
- const n = o[t];
52
- return n || o[Y];
50
+ function Pt(e, n) {
51
+ const a = n[e];
52
+ return a || n[Y];
53
53
  }
54
- function O(t, o, n) {
55
- if (!o || !t.animate || Number(n.duration) <= 0)
54
+ function tt(e, n, a) {
55
+ if (!n || !e.animate || Number(a.duration) <= 0)
56
56
  return Promise.resolve();
57
- const u = t.animate(o, n);
57
+ const u = e.animate(n, a);
58
58
  return u.finished.then(() => u.cancel());
59
59
  }
60
- async function It(t, o) {
61
- const n = t(o), u = {
62
- duration: o.duration,
63
- easing: o.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
- ...n.options
65
+ ...a.options
66
66
  };
67
67
  await Promise.all([
68
- O(o.enteringElement, n.entering, u),
69
- O(o.leavingElement, n.leaving, u)
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 t = window.history.state;
75
- return typeof (t == null ? void 0 : t.position) == "number" ? t.position : window.history.length;
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 X(t, o) {
78
- return o || (t === "pop" ? "back" : t === "replace" ? "none" : "forward");
77
+ function M(e, n) {
78
+ return n || (e === "pop" ? "back" : e === "replace" ? "none" : "forward");
79
79
  }
80
- function At(t) {
81
- const o = ht(t), n = [], u = tt(), l = t.transitionDuration ?? 210, T = t.transitionEasing ?? yt, w = t.transition ?? Y, p = {
82
- ...Pt,
83
- ...t.transitions
84
- }, E = t.maxStackSize ?? 30;
85
- let f = -1, i, I = !1;
86
- const b = (c, a, s, d, k = !1, P = "stack") => {
87
- i = {
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: X(c, a),
90
- source: P,
91
- delta: s,
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
- resetRoot: k
95
+ resetRoot: m
96
96
  };
97
- }, C = (c, a) => {
98
- const s = (i == null ? void 0 : i.action) ?? "push", d = X(s, i == null ? void 0 : i.direction), k = u.value, P = s === "push" && d === "forward", ct = g(c);
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: q("route"),
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: s,
106
+ action: i,
107
107
  direction: d,
108
- source: (i == null ? void 0 : i.source) ?? "stack",
108
+ source: (s == null ? void 0 : s.source) ?? "stack",
109
109
  entryDirection: d,
110
- lastPathname: (k == null ? void 0 : k.pathname) || (a.name ? a.path : void 0),
111
- pushedByRoute: P ? k == null ? void 0 : k.pathname : k == null ? void 0 : k.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: 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,
117
- cache: ct
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
- }, g = (c) => {
120
- const a = c.meta.stack;
121
- return c.meta.stackCache !== !1 && (a == null ? void 0 : a.cache) !== !1;
122
- }, x = () => {
123
- if (E <= 0 || n.length <= E) return;
124
- const c = n.length - E;
125
- n.splice(0, c), f = Math.max(0, f - c);
126
- }, H = (c) => {
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
+ }, $ = (c) => {
127
127
  if (c.action === "pop") {
128
- let a = -1;
128
+ let o = -1;
129
129
  if (c.direction === "forward" || (c.delta ?? 0) > 0) {
130
- for (let s = f + 1; s < n.length; s++)
131
- if (n[s].key === c.key) {
132
- a = s;
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 s = f - 1; s >= 0; s--)
137
- if (n[s].key === c.key) {
138
- a = s;
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 (a >= 0) {
142
- const s = n[a];
143
- n[a] = {
144
- ...s,
141
+ if (o >= 0) {
142
+ const i = a[o];
143
+ a[o] = {
144
+ ...i,
145
145
  ...c,
146
- id: s.id,
146
+ id: i.id,
147
147
  source: c.source,
148
- entryDirection: s.entryDirection,
149
- transition: s.transition,
150
- transitionDuration: s.transitionDuration,
151
- transitionEasing: s.transitionEasing
152
- }, f = a;
148
+ entryDirection: i.entryDirection,
149
+ transition: i.transition,
150
+ transitionDuration: i.transitionDuration,
151
+ transitionEasing: i.transitionEasing
152
+ }, h = o;
153
153
  } else
154
- n.push({
154
+ a.push({
155
155
  ...c,
156
156
  direction: "none",
157
157
  entryDirection: "none",
158
158
  transition: "none",
159
159
  isStackFallback: !0
160
- }), f = n.length - 1;
160
+ }), h = a.length - 1;
161
161
  } else if (c.action === "replace") {
162
- if (i != null && i.resetRoot) {
163
- n.splice(0, n.length, c), f = 0, u.value = n[f];
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
- f >= 0 ? n[f] = c : (n.push(c), f = 0);
166
+ h >= 0 ? a[h] = c : (a.push(c), h = 0);
167
167
  } else
168
- f < n.length - 1 && n.splice(f + 1), n.push(c), f = n.length - 1;
169
- x(), u.value = n[f];
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
- t.history.listen((c, a, s) => {
172
- const d = "delta" in s ? s.delta : void 0, k = s.direction === "back" ? "back" : s.direction === "forward" ? "forward" : void 0;
173
- i ? (i.delta = d, i.direction = X(
174
- i.action,
175
- i.direction ?? k
176
- )) : b(
177
- s.type === "pop" ? "pop" : s.type,
178
- k,
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
+ m,
179
179
  d,
180
180
  void 0,
181
181
  !1,
182
182
  "external"
183
183
  );
184
- }), o.beforeEach((c) => !((i == null ? void 0 : i.action) === "pop" && I && !n.some((a) => a.fullPath === c.fullPath))), o.afterEach((c, a, s) => {
185
- if (s) {
186
- i = void 0;
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
- H(C(c, a)), i = void 0;
189
+ $(H(c, o)), s = void 0;
190
190
  });
191
- const V = o.push.bind(o), L = o.replace.bind(o), $ = o.back.bind(o), W = o.forward.bind(o), K = o.go.bind(o), A = (c, a) => (b(
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
- (a == null ? void 0 : a.direction) ?? "forward",
193
+ (o == null ? void 0 : o.direction) ?? "forward",
194
194
  void 0,
195
- a
196
- ), V(c)), j = (c, a) => (b(
195
+ o
196
+ ), g(c)), A = (c, o) => (R(
197
197
  "replace",
198
- (a == null ? void 0 : a.direction) ?? "root",
198
+ (o == null ? void 0 : o.direction) ?? "root",
199
199
  void 0,
200
- a
201
- ), L(c)), e = (c, a) => {
202
- const s = o.resolve(c).fullPath;
200
+ o
201
+ ), P(c)), B = (c, o) => {
202
+ const i = n.resolve(c).fullPath;
203
203
  let d = -1;
204
- for (let P = f; P >= 0; P--)
205
- if (n[P].fullPath === s) {
206
- d = P;
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 k = d - f;
211
- return k === 0 || (b(
210
+ const m = d - h;
211
+ return m === 0 || (R(
212
212
  "pop",
213
- (a == null ? void 0 : a.direction) ?? "back",
214
- k,
215
- a
216
- ), K(k)), !0;
217
- }, r = (c, a) => {
218
- const s = o.resolve(c).fullPath;
219
- if (f >= 0 && o.currentRoute.value.fullPath === s) {
220
- const d = n[f], k = {
213
+ (o == null ? void 0 : o.direction) ?? "back",
214
+ m,
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: q("route"),
222
+ id: v("route"),
223
223
  action: "replace",
224
- direction: (a == null ? void 0 : a.direction) ?? "root",
224
+ direction: (o == null ? void 0 : o.direction) ?? "root",
225
225
  source: "stack",
226
- entryDirection: (a == null ? void 0 : a.direction) ?? "root",
226
+ entryDirection: (o == null ? void 0 : o.direction) ?? "root",
227
227
  delta: void 0,
228
- transition: (a == null ? void 0 : a.transition) ?? d.transition,
229
- transitionDuration: (a == null ? void 0 : a.duration) ?? d.transitionDuration,
230
- transitionEasing: (a == null ? void 0 : a.easing) ?? d.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 n.splice(0, n.length, k), f = 0, I = !0, u.value = k, Promise.resolve(void 0);
234
+ return a.splice(0, a.length, m), h = 0, b = !0, u.value = m, Promise.resolve(void 0);
235
235
  }
236
- return b(
236
+ return R(
237
237
  "replace",
238
- (a == null ? void 0 : a.direction) ?? "root",
238
+ (o == null ? void 0 : o.direction) ?? "root",
239
239
  void 0,
240
- a,
240
+ o,
241
241
  !0
242
- ), I = !0, L(c);
243
- }, h = () => {
244
- b("pop", "back", -1), $();
245
- }, R = () => {
246
- b("pop", "forward", 1), W();
247
- }, m = o;
248
- m.push = A, m.replace = j, m.popTo = e, m.resetRoot = r, m.back = h, m.forward = R;
249
- const _ = {
250
- router: m,
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: T,
252
+ transitionEasing: D,
253
253
  transition: w,
254
- transitions: p,
254
+ transitions: y,
255
255
  maxStackSize: E,
256
- shouldTransition: t.shouldTransition,
256
+ shouldTransition: e.shouldTransition,
257
257
  current: u,
258
258
  get history() {
259
- return n;
259
+ return a;
260
260
  },
261
- canGoBack: (c = 1) => f - c >= 0,
262
- push: A,
263
- replace: j,
264
- popTo: e,
265
- resetRoot: r,
266
- back: h,
267
- forward: R
268
- }, z = o.install.bind(o);
269
- return o.install = (c) => {
270
- c.provide(Z, _), z(c);
271
- }, m;
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 et = "onPageWillEnter", J = "onPageDidEnter", ot = "onPageWillLeave", rt = "onPageDidLeave";
274
- function Dt(t, o, n) {
275
- if (!n)
276
- throw new Error(`${t} must be called inside setup().`);
277
- const u = n.proxy, l = u[t] ?? [];
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
- n.isUnmounted || o();
280
- }), u[t] = l, n.exposed && (n.exposed[t] = l);
279
+ a.isUnmounted || n();
280
+ }), u[e] = l, a.exposed && (a.exposed[e] = l);
281
281
  }
282
- function G(t) {
283
- return (o, n = it()) => Dt(t, o, n);
282
+ function G(e) {
283
+ return (n, a = it()) => Dt(e, n, a);
284
284
  }
285
- const _t = G(et), Bt = G(J), Ft = G(ot), Gt = G(rt);
285
+ const Bt = G(ot), _t = G(J), Vt = G(rt), Ft = G(nt);
286
286
  function Ct() {
287
- const t = B(Z);
288
- if (!t)
287
+ const e = F(Z);
288
+ if (!e)
289
289
  throw new Error("useStackRouter must be used after createStackRouter().");
290
290
  return {
291
- router: t.router,
292
- canGoBack: t.canGoBack,
293
- push: t.push,
294
- replace: t.replace,
295
- popTo: t.popTo,
296
- resetRoot: t.resetRoot,
297
- back: t.back,
298
- forward: t.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 nt() {
302
- const t = B(Z);
303
- if (!t)
301
+ function at() {
302
+ const e = F(Z);
303
+ if (!e)
304
304
  throw new Error("RouterOutlet must be used with createStackRouter().");
305
- return t;
305
+ return e;
306
306
  }
307
- function S(t, o) {
308
- const n = t.value;
309
- if (!n) return;
310
- const u = n[o];
311
- Array.isArray(u) ? u.forEach((l) => l()) : typeof u == "function" && u.call(n);
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 D(t) {
314
- t.classList.remove("rs-page-hidden", "rs-page-invisible"), t.removeAttribute("aria-hidden");
313
+ function S(e) {
314
+ e.classList.remove("rs-page-hidden", "rs-page-invisible"), e.removeAttribute("aria-hidden");
315
315
  }
316
- function M(t) {
317
- t.classList.add("rs-page-hidden"), t.setAttribute("aria-hidden", "true");
316
+ function q(e) {
317
+ e.classList.add("rs-page-hidden"), e.setAttribute("aria-hidden", "true");
318
318
  }
319
- function at(t) {
320
- var o;
321
- return (o = t.components) == null ? void 0 : o.default;
319
+ function ct(e) {
320
+ var n;
321
+ return (n = e.components) == null ? void 0 : n.default;
322
322
  }
323
- function Tt(t) {
324
- const o = at(t);
325
- return o !== void 0 && typeof o == "object" && "name" in o && o.name === "RouterView";
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 Ht = Q({
327
+ const Gt = Q({
328
328
  name: "RouterOutlet",
329
329
  setup() {
330
- const t = nt(), o = mt(), n = B(kt), u = B(v, void 0), l = U(() => {
331
- const e = u == null ? void 0 : u.value;
332
- if (!e) return 0;
333
- const r = o.matched.findIndex(
334
- (h) => h === e
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
336
  return r >= 0 ? r + 1 : 0;
337
- }), T = U(() => o.matched[l.value]), w = U(() => {
338
- for (let e = l.value; e < o.matched.length; e++) {
339
- const r = o.matched[e];
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
340
  if (!Tt(r))
341
341
  return r;
342
342
  }
343
- return T.value;
344
- }), p = tt([]), E = F("");
345
- let f = 0;
346
- st(v, w);
347
- const i = (e) => p.value.find((r) => r.key === e), I = (e) => {
348
- p.value.forEach((r) => {
349
- r.pageElement && (r === e ? D(r.pageElement) : M(r.pageElement));
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
- }, b = (e) => {
352
- const r = p.value.findIndex((h) => h === e);
353
- r >= 0 && (p.value = p.value.slice(0, r + 1));
354
- }, C = (e) => {
355
- p.value = p.value.filter((r) => r !== e);
356
- }, g = (e) => {
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
357
  const r = new Set(
358
- t.history.map((h) => h.key)
358
+ e.history.map((f) => f.id)
359
359
  );
360
- p.value = p.value.filter(
361
- (h) => h === e || h.routeInfo.cache && r.has(h.key)
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
- }, x = (e) => {
364
- var h;
365
- const r = e.props.default;
366
- return r ? r === !0 ? ((h = t.current.value) == null ? void 0 : h.params) ?? {} : typeof r == "function" ? r(n) : r : {};
367
- }, H = (e, r) => e.routeInfo.action === "pop" ? r.routeInfo.transition ?? e.routeInfo.transition ?? t.transition : e.routeInfo.transition ?? t.transition, V = (e, r) => !(e.routeInfo.isStackFallback || e.routeInfo.direction === "none" || e.routeInfo.direction === "root" || e.routeInfo.action === "pop" && (r.routeInfo.entryDirection === "none" || r.routeInfo.entryDirection === "root" || r.routeInfo.transition === "none")), L = (e, r) => {
368
- var R;
369
- const h = V(e, r);
370
- return ((R = t.shouldTransition) == null ? void 0 : R.call(t, {
371
- action: e.routeInfo.action,
372
- direction: e.routeInfo.direction,
373
- source: e.routeInfo.source,
374
- entering: e.routeInfo,
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,
375
379
  leaving: r.routeInfo,
376
- defaultResult: h
377
- })) ?? h;
378
- }, $ = (e, r) => e.routeInfo.action === "pop" ? r.routeInfo.transitionDuration ?? e.routeInfo.transitionDuration ?? t.transitionDuration : e.routeInfo.transitionDuration ?? t.transitionDuration, W = (e, r) => e.routeInfo.action === "pop" ? r.routeInfo.transitionEasing ?? e.routeInfo.transitionEasing ?? t.transitionEasing : e.routeInfo.transitionEasing ?? t.transitionEasing, K = async (e, r) => {
379
- const h = ++f;
380
- await ft();
381
- const R = e.pageElement;
382
- if (!R) return;
383
- if (S(e.componentRef, et), !r || r === e || !r.pageElement) {
384
- D(R), S(e.componentRef, J), g(e), I(e);
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;
384
+ await dt();
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 m = r.pageElement, _ = L(e, r), z = _ ? H(e, r) : "none", c = _ ? $(e, r) : 0, a = W(e, r), s = wt(
388
- z || Y,
389
- t.transitions
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
- S(r.componentRef, ot), D(R), D(m), await It(s, {
392
- direction: e.routeInfo.direction,
393
- action: e.routeInfo.action,
394
- routeInfo: e.routeInfo,
395
- enteringElement: R,
396
- leavingElement: m,
397
- duration: c,
398
- easing: a
399
- }), h === f && (M(m), S(r.componentRef, rt), S(e.componentRef, J), e.routeInfo.action === "pop" ? b(e) : e.routeInfo.action === "replace" && C(r), g(e), I(e));
400
- }, A = async () => {
401
- const e = w.value, r = t.current.value;
402
- if (!e || !r) return;
403
- const h = at(e);
404
- if (!h) return;
405
- const R = i(E.value);
406
- let m = i(r.key);
407
- m ? (m.routeInfo = r, m.matchedRoute = e, m.component = h, m.props = x(e), m.mounted = !0) : (m = {
408
- id: q("view"),
409
- key: r.key,
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]),
410
415
  routeInfo: r,
411
- matchedRoute: e,
412
- component: h,
413
- props: x(e),
414
- componentRef: F(),
416
+ matchedRoute: t,
417
+ component: f,
418
+ props: P(t),
419
+ componentRef: C(),
415
420
  mounted: !0
416
- }, p.value = [...p.value, m]), E.value = m.key, await K(m, R);
421
+ }, y.value = [...y.value, o]), E.value = o.id, await _(o, c);
417
422
  };
418
423
  return ut(
419
424
  () => {
420
- var e;
421
- return [(e = t.current.value) == null ? void 0 : e.id, w.value];
425
+ var t;
426
+ return [(t = e.current.value) == null ? void 0 : t.id, w.value];
422
427
  },
423
428
  () => {
424
- A();
429
+ V();
425
430
  },
426
431
  { immediate: !0 }
427
432
  ), lt(() => {
428
- f++, p.value = [];
433
+ h++, y.value = [];
429
434
  }), {
430
- injectedRoute: n,
431
- viewItems: p,
432
- registerStackPage: (e, r) => {
433
- e.pageElement = r, e.key === E.value ? D(r) : M(r);
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 y(
443
+ return k(
439
444
  "div",
440
445
  { class: "rs-outlet" },
441
- this.viewItems.filter((t) => t.mounted).map(
442
- (t) => y(t.component, {
443
- key: t.id,
444
- ref: t.componentRef,
445
- ...t.props,
446
- registerStackPage: (o) => this.registerStackPage(t, o)
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
- }), Vt = Q({
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(t, { attrs: o, slots: n }) {
460
- const u = F();
461
- return dt(() => {
464
+ setup(e, { attrs: n, slots: a }) {
465
+ const u = C();
466
+ return ft(() => {
462
467
  var l;
463
- u.value && ((l = t.registerStackPage) == null || l.call(t, u.value));
468
+ u.value && ((l = e.registerStackPage) == null || l.call(e, u.value));
464
469
  }), () => {
465
470
  var l;
466
- return y(
471
+ return k(
467
472
  "section",
468
473
  {
469
- ...o,
474
+ ...n,
470
475
  ref: u,
471
- class: ["rs-page", o.class]
476
+ class: ["rs-page", n.class]
472
477
  },
473
- (l = n.default) == null ? void 0 : l.call(n)
478
+ (l = a.default) == null ? void 0 : l.call(a)
474
479
  );
475
480
  };
476
481
  }
477
- }), $t = Q({
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(t) {
486
- const o = nt(), n = F(t.initialOpen);
490
+ setup(e) {
491
+ const n = at(), a = C(e.initialOpen);
487
492
  return () => {
488
- const u = o.current.value;
489
- return y("aside", { class: "rs-debug-panel" }, [
490
- y(
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
- n.value = !n.value;
501
+ a.value = !a.value;
497
502
  }
498
503
  },
499
- n.value ? "Stack x" : "Stack"
504
+ a.value ? "Stack x" : "Stack"
500
505
  ),
501
- n.value ? y("section", { class: "rs-debug-body" }, [
502
- y("header", [
503
- y("strong", "Router Stack"),
504
- y("span", `${o.history.length} pages`)
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
- y("dl", [
507
- y("dt", "current"),
508
- y("dd", (u == null ? void 0 : u.fullPath) ?? "-"),
509
- y("dt", "canGoBack"),
510
- y("dd", String(o.canGoBack()))
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
- y(
517
+ k(
513
518
  "ol",
514
- o.history.map(
515
- (l) => y(
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
- y("code", l.fullPath),
526
- y("span", [
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
- jt as RouterLink,
544
- Ht as RouterOutlet,
545
- Vt as RouterPage,
546
- zt as RouterView,
547
- $t as StackRouterDebugPanel,
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
- Bt as onPageDidEnter,
554
- Gt as onPageDidLeave,
555
- _t as onPageWillEnter,
556
- Ft as onPageWillLeave,
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
- Jt as useRouter,
564
+ vt as useRouter,
560
565
  Ct as useStackRouter
561
566
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazycatcloud/vue-router-stack",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Page stack, caching, transitions, and lifecycle utilities built on vue-router.",
5
5
  "private": false,
6
6
  "type": "module",