@lazycatcloud/vue-router-stack 0.0.5 → 0.0.6

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