@lazycatcloud/vue-router-stack 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 o=(Y[e]??0)+1;return Y[e]=o,`${e}-${o}`}const Q="slide",oe="cubic-bezier(0.3, 0, 0.66, 1)";function ne(e){return e}const ae=({direction:e})=>e==="back"?{leaving:[{transform:"translateX(0)"},{transform:"translateX(100%)"}]}:{entering:[{transform:"translateX(100%)"},{transform:"translateX(0)"}]},ce=()=>({entering:[{opacity:0},{opacity:1}],leaving:[{opacity:1},{opacity:0}]}),ie=({direction:e})=>{const o=e==="back";return{entering:o?[{transform:"scale(0.98)",opacity:0},{transform:"scale(1)",opacity:1}]:[{transform:"scale(1.04)",opacity:0},{transform:"scale(1)",opacity:1}],leaving:o?[{transform:"scale(1)",opacity:1},{transform:"scale(1.04)",opacity:0}]:[{transform:"scale(1)",opacity:1},{transform:"scale(0.98)",opacity:0}]}},se=()=>({}),ue={slide:ae,fade:ce,scale:ie,none:se};function le(e,o){const c=o[e];return c||o[Q]}function Z(e,o,c){if(!o||!e.animate||Number(c.duration)<=0)return Promise.resolve();const l=e.animate(o,c);return l.finished.then(()=>l.cancel())}async function de(e,o){const c=e(o),l={duration:o.duration,easing:o.easing,fill:"both",...c.options};await Promise.all([Z(o.enteringElement,c.entering,l),Z(o.leavingElement,c.leaving,l)])}const C=Symbol("stack-router");function fe(){const e=window.history.state;return typeof(e==null?void 0:e.position)=="number"?e.position:window.history.length}function q(e,o){return o||(e==="pop"?"back":e==="replace"?"none":"forward")}function he(e){const o=k.createRouter(e),c=[],l=u.shallowRef(),f=e.transitionDuration??210,T=e.transitionEasing??oe,w=e.transition??Q,y={...ue,...e.transitions},P=e.maxStackSize??30;let h=-1,s,E=!1;const b=(a,r,i,d,m=!1,R="stack")=>{s={action:a,direction:q(a,r),source:R,delta:i,reuse:d==null?void 0:d.reuse,transition:d==null?void 0:d.transition,duration:d==null?void 0:d.duration,easing:d==null?void 0:d.easing,resetRoot:m}},K=(a,r)=>{const i=(s==null?void 0:s.action)??"push",d=q(i,s==null?void 0:s.direction),m=l.value,R=i==="push"&&d==="forward",M=g(a);return{id:X("route"),key:a.fullPath,fullPath:a.fullPath,pathname:a.path,params:a.params,query:a.query,action:i,direction:d,reuse:(s==null?void 0:s.reuse)??!1,source:(s==null?void 0:s.source)??"stack",entryDirection:d,lastPathname:(m==null?void 0:m.pathname)||(r.name?r.path:void 0),pushedByRoute:R?m==null?void 0:m.pathname:m==null?void 0:m.pushedByRoute,position:fe(),delta:s==null?void 0:s.delta,transition:(s==null?void 0:s.transition)??w,transitionDuration:(s==null?void 0:s.duration)??f,transitionEasing:(s==null?void 0:s.easing)??T,cache:M}},g=a=>{const r=a.meta.stack;return a.meta.stackCache!==!1&&(r==null?void 0:r.cache)!==!1},W=()=>{if(P<=0||c.length<=P)return;const a=c.length-P;c.splice(0,a),h=Math.max(0,h-a)},G=a=>{if(a.action==="pop"){let r=-1;if(a.direction==="forward"||(a.delta??0)>0){for(let i=h+1;i<c.length;i++)if(c[i].key===a.key){r=i;break}}else for(let i=h-1;i>=0;i--)if(c[i].key===a.key){r=i;break}if(r>=0){const i=c[r];c[r]={...i,...a,id:i.id,reuse:i.reuse,source:a.source,entryDirection:i.entryDirection,transition:i.transition,transitionDuration:i.transitionDuration,transitionEasing:i.transitionEasing},h=r}else c.push({...a,direction:"none",entryDirection:"none",transition:"none",isStackFallback:!0}),h=c.length-1}else if(a.action==="replace"){if(s!=null&&s.resetRoot){c.splice(0,c.length,a),h=0,l.value=c[h];return}h>=0?c[h]=a:(c.push(a),h=0)}else h<c.length-1&&c.splice(h+1),c.push(a),h=c.length-1;W(),l.value=c[h]};e.history.listen((a,r,i)=>{const d="delta"in i?i.delta:void 0,m=i.direction==="back"?"back":i.direction==="forward"?"forward":void 0;s?(s.delta=d,s.direction=q(s.action,s.direction??m)):b(i.type==="pop"?"pop":i.type,m,d,void 0,!1,"external")}),o.beforeEach(a=>!((s==null?void 0:s.action)==="pop"&&E&&!c.some(r=>r.fullPath===a.fullPath))),o.afterEach((a,r,i)=>{if(i){s=void 0;return}G(K(a,r)),s=void 0});const L=o.push.bind(o),I=o.replace.bind(o),$=o.back.bind(o),x=o.forward.bind(o),z=o.go.bind(o),A=(a,r)=>(b("push",(r==null?void 0:r.direction)??"forward",void 0,r),L(a)),j=(a,r)=>(b("replace",(r==null?void 0:r.direction)??"root",void 0,r),I(a)),B=(a,r)=>{const i=o.resolve(a).fullPath;let d=-1;for(let R=h;R>=0;R--)if(c[R].fullPath===i){d=R;break}if(d<0)return!1;const m=d-h;return m===0||(b("pop",(r==null?void 0:r.direction)??"back",m,r),z(m)),!0},H=(a,r)=>{const i=o.resolve(a).fullPath;if(h>=0&&o.currentRoute.value.fullPath===i){const d=c[h],m={...d,id:X("route"),action:"replace",direction:(r==null?void 0:r.direction)??"root",source:"stack",entryDirection:(r==null?void 0:r.direction)??"root",delta:void 0,reuse:(r==null?void 0:r.reuse)??d.reuse,transition:(r==null?void 0:r.transition)??d.transition,transitionDuration:(r==null?void 0:r.duration)??d.transitionDuration,transitionEasing:(r==null?void 0:r.easing)??d.transitionEasing,cache:!0,isStackFallback:!1};return c.splice(0,c.length,m),h=0,E=!0,l.value=m,Promise.resolve(void 0)}return b("replace",(r==null?void 0:r.direction)??"root",void 0,r,!0),E=!0,I(a)},V=()=>{b("pop","back",-1),$()},_=()=>{b("pop","forward",1),x()},p=o;p.push=A,p.replace=j,p.popTo=B,p.resetRoot=H,p.back=V,p.forward=_;const t={router:p,transitionDuration:f,transitionEasing:T,transition:w,transitions:y,maxStackSize:P,shouldTransition:e.shouldTransition,current:l,get history(){return c},canGoBack:(a=1)=>h-a>=0,push:A,replace:j,popTo:B,resetRoot:H,back:V,forward:_},n=o.install.bind(o);return o.install=a=>{a.provide(C,t),n(a)},p}const v="onPageWillEnter",J="onPageDidEnter",N="onPageWillLeave",O="onPageDidLeave";function me(e,o,c){if(!c)throw new Error(`${e} must be called inside setup().`);const l=c.proxy,f=l[e]??[];f.push(()=>{c.isUnmounted||o()}),l[e]=f,c.exposed&&(c.exposed[e]=f)}function F(e){return(o,c=u.getCurrentInstance())=>me(e,o,c)}const ye=F(v),ke=F(J),Re=F(N),be=F(O);function pe(){const e=u.inject(C);if(!e)throw new Error("useStackRouter must be used after createStackRouter().");return{router:e.router,canGoBack:e.canGoBack,push:e.push,replace:e.replace,popTo:e.popTo,resetRoot:e.resetRoot,back:e.back,forward:e.forward}}function ee(){const e=u.inject(C);if(!e)throw new Error("RouterOutlet must be used with createStackRouter().");return e}function S(e,o){const c=e.value;if(!c)return;const l=c[o];Array.isArray(l)?l.forEach(f=>f()):typeof l=="function"&&l.call(c)}function D(e){e.classList.remove("rs-page-hidden","rs-page-invisible"),e.removeAttribute("aria-hidden")}function U(e){const o=e.ownerDocument.activeElement;o instanceof HTMLElement&&e.contains(o)&&o.blur(),e.classList.add("rs-page-hidden"),e.setAttribute("aria-hidden","true")}function te(e){var o;return(o=e.components)==null?void 0:o.default}function Pe(e){const o=te(e);return o!==void 0&&typeof o=="object"&&"name"in o&&o.name==="RouterView"}const we=u.defineComponent({name:"RouterOutlet",setup(){const e=ee(),o=k.useRoute(),c=u.inject(k.routeLocationKey),l=u.inject(k.matchedRouteKey,void 0),f=u.computed(()=>{const t=l==null?void 0:l.value;if(!t)return 0;const n=o.matched.findIndex(a=>a===t);return n>=0?n+1:0}),T=u.computed(()=>o.matched[f.value]),w=u.computed(()=>{for(let t=f.value;t<o.matched.length;t++){const n=o.matched[t];if(!Pe(n))return n}return T.value}),y=u.shallowRef([]),P=u.ref("");let h=0;u.provide(k.matchedRouteKey,w);const s=t=>y.value.find(n=>n.id===t),E=t=>y.value.find(n=>n.routeIds.has(t)),b=t=>y.value.find(n=>n.routeKey===t),K=t=>t.action==="push"&&t.direction==="forward"&&!t.reuse&&y.value.some(n=>n.routeKey===t.key),g=t=>{y.value.forEach(n=>{n.pageElement&&(n===t?D(n.pageElement):U(n.pageElement))})},W=t=>{const n=e.history.findIndex(r=>r.id===t.routeInfo.id);if(n<0)return;const a=new Set(e.history.slice(0,n+1).map(r=>r.id));y.value.forEach(r=>{r.routeIds=new Set([...r.routeIds].filter(i=>a.has(i)))}),y.value=y.value.filter(r=>r===t||r.routeIds.size>0)},G=t=>{y.value=y.value.filter(n=>n!==t)},L=t=>{const n=new Set(e.history.map(a=>a.id));y.value.forEach(a=>{a.routeIds=new Set([...a.routeIds].filter(r=>n.has(r)))}),y.value=y.value.filter(a=>a===t||a.routeInfo.cache&&a.routeIds.size>0)},I=t=>{var a;const n=t.props.default;return n?n===!0?((a=e.current.value)==null?void 0:a.params)??{}:typeof n=="function"?n(c):n:{}},$=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transition??t.routeInfo.transition??e.transition:t.routeInfo.transition??e.transition,x=t=>t.entryDirection==="none"||t.entryDirection==="root"||t.transition==="none",z=(t,n)=>t.routeInfo.direction==="forward"?x(t.routeInfo):x(n.routeInfo),A=(t,n)=>!(t.routeInfo.isStackFallback||t.routeInfo.direction==="none"||t.routeInfo.direction==="root"||t.routeInfo.action==="pop"&&z(t,n)),j=(t,n)=>{var r;const a=A(t,n);return((r=e.shouldTransition)==null?void 0:r.call(e,{action:t.routeInfo.action,direction:t.routeInfo.direction,source:t.routeInfo.source,entering:t.routeInfo,leaving:n.routeInfo,defaultResult:a}))??a},B=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transitionDuration??t.routeInfo.transitionDuration??e.transitionDuration:t.routeInfo.transitionDuration??e.transitionDuration,H=(t,n)=>t.routeInfo.action==="pop"?n.routeInfo.transitionEasing??t.routeInfo.transitionEasing??e.transitionEasing:t.routeInfo.transitionEasing??e.transitionEasing,V=async(t,n)=>{const a=++h;await u.nextTick();const r=t.pageElement;if(!r)return;if(S(t.componentRef,v),!n||n===t||!n.pageElement){D(r),S(t.componentRef,J),L(t),g(t);return}const i=n.pageElement,d=j(t,n),m=d?$(t,n):"none",R=d?B(t,n):0,M=H(t,n),re=le(m||Q,e.transitions);S(n.componentRef,N),D(r),D(i),await de(re,{direction:t.routeInfo.direction,action:t.routeInfo.action,routeInfo:t.routeInfo,enteringElement:r,leavingElement:i,duration:R,easing:M}),a===h&&(U(i),S(n.componentRef,O),S(t.componentRef,J),t.routeInfo.action==="pop"?W(t):t.routeInfo.action==="replace"&&G(n),L(t),g(t))},_=async()=>{const t=w.value,n=e.current.value;if(!t||!n)return;const a=te(t);if(!a)return;const r=s(P.value);let i=E(n.id);!i&&!K(n)&&(i=b(n.key)),i?(i.routeIds.add(n.id),i.routeKey=n.key,i.routeInfo=n,i.matchedRoute=t,i.component=a,i.props=I(t),i.mounted=!0):(i={id:X("view"),routeKey:n.key,routeIds:new Set([n.id]),routeInfo:n,matchedRoute:t,component:a,props:I(t),componentRef:u.ref(),mounted:!0},y.value=[...y.value,i]),P.value=i.id,await V(i,r)};return u.watch(()=>{var t;return[(t=e.current.value)==null?void 0:t.id,w.value]},()=>{_()},{immediate:!0}),u.onUnmounted(()=>{h++,y.value=[]}),{injectedRoute:c,viewItems:y,registerStackPage:(t,n)=>{t.pageElement=n,t.id===P.value?D(n):U(n)}}},render(){return u.h("div",{class:"rs-outlet"},this.viewItems.filter(e=>e.mounted).map(e=>u.h(e.component,{key:e.id,ref:e.componentRef,...e.props,registerStackPage:o=>this.registerStackPage(e,o)})))}}),Ee=u.defineComponent({name:"RouterPage",props:{registerStackPage:{type:Function,default:void 0}},setup(e,{attrs:o,slots:c}){const l=u.ref();return u.onMounted(()=>{var f;l.value&&((f=e.registerStackPage)==null||f.call(e,l.value))}),()=>{var f;return u.h("section",{...o,ref:l,class:["rs-page",o.class]},(f=c.default)==null?void 0:f.call(c))}}}),Ie=u.defineComponent({name:"StackRouterDebugPanel",props:{initialOpen:{type:Boolean,default:!1}},setup(e){const o=ee(),c=u.ref(e.initialOpen);return()=>{const l=o.current.value;return u.h("aside",{class:"rs-debug-panel"},[u.h("button",{class:"rs-debug-toggle",type:"button",onClick:()=>{c.value=!c.value}},c.value?"Stack x":"Stack"),c.value?u.h("section",{class:"rs-debug-body"},[u.h("header",[u.h("strong","Router Stack"),u.h("span",`${o.history.length} pages`)]),u.h("dl",[u.h("dt","current"),u.h("dd",(l==null?void 0:l.fullPath)??"-"),u.h("dt","canGoBack"),u.h("dd",String(o.canGoBack()))]),u.h("ol",o.history.map(f=>u.h("li",{key:f.id,class:{"rs-debug-active":f.id===(l==null?void 0:l.id),"rs-debug-no-cache":!f.cache}},[u.h("code",f.fullPath),u.h("span",[`${f.action}/${f.direction}`,` source:${f.source}`,` entry:${f.entryDirection}`,` cache:${f.cache?"yes":"no"}`,` transition:${f.transition??"-"}`])])))]):void 0])}}});Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>k.RouterLink});Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>k.RouterView});Object.defineProperty(exports,"createMemoryHistory",{enumerable:!0,get:()=>k.createMemoryHistory});Object.defineProperty(exports,"createWebHashHistory",{enumerable:!0,get:()=>k.createWebHashHistory});Object.defineProperty(exports,"createWebHistory",{enumerable:!0,get:()=>k.createWebHistory});Object.defineProperty(exports,"useRoute",{enumerable:!0,get:()=>k.useRoute});Object.defineProperty(exports,"useRouter",{enumerable:!0,get:()=>k.useRouter});exports.RouterOutlet=we;exports.RouterPage=Ee;exports.StackRouterDebugPanel=Ie;exports.createStackRouter=he;exports.defineStackTransition=ne;exports.onPageDidEnter=ke;exports.onPageDidLeave=be;exports.onPageWillEnter=ye;exports.onPageWillLeave=Re;exports.stackRouterKey=C;exports.useStackRouter=pe;
@@ -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 U, 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 Me, createMemoryHistory as Ue, createWebHashHistory as Xe, 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 o = (O[e] ?? 0) + 1;
7
+ return O[e] = o, `${e}-${o}`;
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 o = e === "back";
28
28
  return {
29
- entering: n ? [
29
+ entering: o ? [
30
30
  { transform: "scale(0.98)", opacity: 0 },
31
31
  { transform: "scale(1)", opacity: 1 }
32
32
  ] : [
33
33
  { transform: "scale(1.04)", opacity: 0 },
34
34
  { transform: "scale(1)", opacity: 1 }
35
35
  ],
36
- leaving: n ? [
36
+ leaving: o ? [
37
37
  { transform: "scale(1)", opacity: 1 },
38
38
  { transform: "scale(1.04)", opacity: 0 }
39
39
  ] : [
@@ -41,62 +41,62 @@ 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, o) {
51
+ const c = o[e];
52
+ return c || o[Z];
53
53
  }
54
- function ee(t, n, c) {
55
- if (!n || !t.animate || Number(c.duration) <= 0)
54
+ function ee(e, o, c) {
55
+ if (!o || !e.animate || Number(c.duration) <= 0)
56
56
  return Promise.resolve();
57
- const u = t.animate(n, c);
57
+ const u = e.animate(o, 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, o) {
61
+ const c = e(o), u = {
62
+ duration: o.duration,
63
+ easing: o.easing,
64
64
  fill: "both",
65
65
  ...c.options
66
66
  };
67
67
  await Promise.all([
68
- ee(n.enteringElement, c.entering, u),
69
- ee(n.leavingElement, c.leaving, u)
68
+ ee(o.enteringElement, c.entering, u),
69
+ ee(o.leavingElement, c.leaving, u)
70
70
  ]);
71
71
  }
72
72
  const N = Symbol("stack-router");
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 X(e, o) {
78
+ return o || (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 = {
80
+ function Be(e) {
81
+ const o = 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 = (a, r, s, l, h = !1, k = "stack") => {
87
+ i = {
88
88
  action: a,
89
- direction: M(a, r),
90
- source: R,
91
- delta: i,
89
+ direction: X(a, 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 = (a, r) => {
99
+ const s = (i == null ? void 0 : i.action) ?? "push", l = X(s, i == null ? void 0 : i.direction), h = u.value, k = s === "push" && l === "forward", M = T(a);
100
100
  return {
101
101
  id: J("route"),
102
102
  key: a.fullPath,
@@ -104,55 +104,55 @@ function Ae(t) {
104
104
  pathname: a.path,
105
105
  params: a.params,
106
106
  query: a.query,
107
- action: i,
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,
119
- cache: U
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
+ cache: M
120
120
  };
121
121
  }, T = (a) => {
122
122
  const r = a.meta.stack;
123
123
  return a.meta.stackCache !== !1 && (r == null ? void 0 : r.cache) !== !1;
124
- }, K = () => {
124
+ }, $ = () => {
125
125
  if (w <= 0 || c.length <= w) return;
126
126
  const a = c.length - w;
127
- c.splice(0, a), h = Math.max(0, h - a);
128
- }, $ = (a) => {
127
+ c.splice(0, a), f = Math.max(0, f - a);
128
+ }, W = (a) => {
129
129
  if (a.action === "pop") {
130
130
  let r = -1;
131
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;
132
+ for (let s = f + 1; s < c.length; s++)
133
+ if (c[s].key === a.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 === a.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,
146
+ ...s,
147
147
  ...a,
148
- id: i.id,
149
- reuse: i.reuse,
148
+ id: s.id,
149
+ reuse: s.reuse,
150
150
  source: a.source,
151
- entryDirection: i.entryDirection,
152
- transition: i.transition,
153
- transitionDuration: i.transitionDuration,
154
- transitionEasing: i.transitionEasing
155
- }, h = r;
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
158
  ...a,
@@ -160,67 +160,67 @@ function Ae(t) {
160
160
  entryDirection: "none",
161
161
  transition: "none",
162
162
  isStackFallback: !0
163
- }), h = c.length - 1;
163
+ }), f = c.length - 1;
164
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];
165
+ if (i != null && i.resetRoot) {
166
+ c.splice(0, c.length, a), 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] = a : (c.push(a), 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(a), 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((a, 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 = X(
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
+ }), o.beforeEach((a) => !((i == null ? void 0 : i.action) === "pop" && b && !c.some((r) => r.fullPath === a.fullPath))), o.afterEach((a, r, s) => {
188
+ if (s) {
189
+ i = void 0;
190
190
  return;
191
191
  }
192
- $(H(a, r)), s = void 0;
192
+ W(K(a, 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 = o.push.bind(o), I = o.replace.bind(o), z = o.back.bind(o), x = o.forward.bind(o), j = o.go.bind(o), L = (a, r) => (R(
195
195
  "push",
196
196
  (r == null ? void 0 : r.direction) ?? "forward",
197
197
  void 0,
198
198
  r
199
- ), g(a)), A = (a, r) => (p(
199
+ ), g(a)), A = (a, r) => (R(
200
200
  "replace",
201
201
  (r == null ? void 0 : r.direction) ?? "root",
202
202
  void 0,
203
203
  r
204
204
  ), I(a)), B = (a, r) => {
205
- const i = n.resolve(a).fullPath;
205
+ const s = o.resolve(a).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;
219
+ ), j(h)), !0;
220
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 = {
221
+ const s = o.resolve(a).fullPath;
222
+ if (f >= 0 && o.currentRoute.value.fullPath === s) {
223
+ const l = c[f], h = {
224
224
  ...l,
225
225
  id: J("route"),
226
226
  action: "replace",
@@ -235,9 +235,9 @@ 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,
@@ -245,231 +245,232 @@ function Ae(t) {
245
245
  !0
246
246
  ), b = !0, I(a);
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 = o;
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: (a = 1) => f - a >= 0,
266
266
  push: L,
267
267
  replace: A,
268
268
  popTo: B,
269
269
  resetRoot: _,
270
270
  back: V,
271
- 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
+ }, n = o.install.bind(o);
273
+ return o.install = (a) => {
274
+ a.provide(N, t), n(a);
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, o, 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 || o();
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 (o, c = ie()) => Te(e, o, 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, o) {
312
+ const c = e.value;
313
313
  if (!c) return;
314
- const u = c[n];
314
+ const u = c[o];
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
+ const o = e.ownerDocument.activeElement;
322
+ o instanceof HTMLElement && e.contains(o) && o.blur(), e.classList.add("rs-page-hidden"), e.setAttribute("aria-hidden", "true");
322
323
  }
323
- function ce(t) {
324
- var n;
325
- return (n = t.components) == null ? void 0 : n.default;
324
+ function ce(e) {
325
+ var o;
326
+ return (o = e.components) == null ? void 0 : o.default;
326
327
  }
327
- function Te(t) {
328
- const n = ce(t);
329
- return n !== void 0 && typeof n == "object" && "name" in n && n.name === "RouterView";
328
+ function ge(e) {
329
+ const o = ce(e);
330
+ return o !== void 0 && typeof o == "object" && "name" in o && o.name === "RouterView";
330
331
  }
331
- const Ge = Y({
332
+ const He = Y({
332
333
  name: "RouterOutlet",
333
334
  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
335
+ const e = ae(), o = ye(), c = C(ke), u = C(v, void 0), d = U(() => {
336
+ const t = u == null ? void 0 : u.value;
337
+ if (!t) return 0;
338
+ const n = o.matched.findIndex(
339
+ (a) => a === t
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))
345
- return o;
341
+ return n >= 0 ? n + 1 : 0;
342
+ }), D = U(() => o.matched[d.value]), E = U(() => {
343
+ for (let t = d.value; t < o.matched.length; t++) {
344
+ const n = o.matched[t];
345
+ if (!ge(n))
346
+ return n;
346
347
  }
347
348
  return D.value;
348
- }), 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));
349
+ }), m = te([]), w = G("");
350
+ let f = 0;
351
+ ue(v, E);
352
+ const i = (t) => m.value.find((n) => n.id === t), b = (t) => m.value.find((n) => n.routeIds.has(t)), R = (t) => m.value.find((n) => n.routeKey === t), K = (t) => t.action === "push" && t.direction === "forward" && !t.reuse && m.value.some((n) => n.routeKey === t.key), T = (t) => {
353
+ m.value.forEach((n) => {
354
+ n.pageElement && (n === t ? S(n.pageElement) : q(n.pageElement));
354
355
  });
355
- }, K = (e) => {
356
- const o = t.history.findIndex(
357
- (a) => a.id === e.routeInfo.id
356
+ }, $ = (t) => {
357
+ const n = e.history.findIndex(
358
+ (r) => r.id === t.routeInfo.id
358
359
  );
359
- if (o < 0) return;
360
- const f = new Set(
361
- t.history.slice(0, o + 1).map((a) => a.id)
360
+ if (n < 0) return;
361
+ const a = new Set(
362
+ e.history.slice(0, n + 1).map((r) => r.id)
362
363
  );
363
- y.value.forEach((a) => {
364
- a.routeIds = new Set(
365
- [...a.routeIds].filter((r) => f.has(r))
364
+ m.value.forEach((r) => {
365
+ r.routeIds = new Set(
366
+ [...r.routeIds].filter((s) => a.has(s))
366
367
  );
367
- }), y.value = y.value.filter(
368
- (a) => a === e || a.routeIds.size > 0
368
+ }), m.value = m.value.filter(
369
+ (r) => r === t || r.routeIds.size > 0
369
370
  );
370
- }, $ = (e) => {
371
- y.value = y.value.filter((o) => o !== e);
372
- }, g = (e) => {
373
- const o = new Set(
374
- t.history.map((f) => f.id)
371
+ }, W = (t) => {
372
+ m.value = m.value.filter((n) => n !== t);
373
+ }, g = (t) => {
374
+ const n = new Set(
375
+ e.history.map((a) => a.id)
375
376
  );
376
- y.value.forEach((f) => {
377
- f.routeIds = new Set(
378
- [...f.routeIds].filter((a) => o.has(a))
377
+ m.value.forEach((a) => {
378
+ a.routeIds = new Set(
379
+ [...a.routeIds].filter((r) => n.has(r))
379
380
  );
380
- }), y.value = y.value.filter(
381
- (f) => f === e || f.routeInfo.cache && f.routeIds.size > 0
381
+ }), m.value = m.value.filter(
382
+ (a) => a === t || a.routeInfo.cache && a.routeIds.size > 0
382
383
  );
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) => {
384
+ }, I = (t) => {
388
385
  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,
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);
386
+ const n = t.props.default;
387
+ return n ? n === !0 ? ((a = e.current.value) == null ? void 0 : a.params) ?? {} : typeof n == "function" ? n(c) : n : {};
388
+ }, z = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transition ?? t.routeInfo.transition ?? e.transition : t.routeInfo.transition ?? e.transition, x = (t) => t.entryDirection === "none" || t.entryDirection === "root" || t.transition === "none", j = (t, n) => t.routeInfo.direction === "forward" ? x(t.routeInfo) : x(n.routeInfo), L = (t, n) => !(t.routeInfo.isStackFallback || t.routeInfo.direction === "none" || t.routeInfo.direction === "root" || t.routeInfo.action === "pop" && j(t, n)), A = (t, n) => {
389
+ var r;
390
+ const a = L(t, n);
391
+ return ((r = e.shouldTransition) == null ? void 0 : r.call(e, {
392
+ action: t.routeInfo.action,
393
+ direction: t.routeInfo.direction,
394
+ source: t.routeInfo.source,
395
+ entering: t.routeInfo,
396
+ leaving: n.routeInfo,
397
+ defaultResult: a
398
+ })) ?? a;
399
+ }, B = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transitionDuration ?? t.routeInfo.transitionDuration ?? e.transitionDuration : t.routeInfo.transitionDuration ?? e.transitionDuration, _ = (t, n) => t.routeInfo.action === "pop" ? n.routeInfo.transitionEasing ?? t.routeInfo.transitionEasing ?? e.transitionEasing : t.routeInfo.transitionEasing ?? e.transitionEasing, V = async (t, n) => {
400
+ const a = ++f;
401
+ await fe();
402
+ const r = t.pageElement;
403
+ if (!r) return;
404
+ if (P(t.componentRef, re), !n || n === t || !n.pageElement) {
405
+ S(r), P(t.componentRef, Q), g(t), T(t);
405
406
  return;
406
407
  }
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
408
+ const s = n.pageElement, l = A(t, n), h = l ? z(t, n) : "none", k = l ? B(t, n) : 0, M = _(t, n), se = Pe(
409
+ h || Z,
410
+ e.transitions
410
411
  );
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 = {
412
+ P(n.componentRef, oe), S(r), S(s), await Se(se, {
413
+ direction: t.routeInfo.direction,
414
+ action: t.routeInfo.action,
415
+ routeInfo: t.routeInfo,
416
+ enteringElement: r,
417
+ leavingElement: s,
418
+ duration: k,
419
+ easing: M
420
+ }), a === f && (q(s), P(n.componentRef, ne), P(t.componentRef, Q), t.routeInfo.action === "pop" ? $(t) : t.routeInfo.action === "replace" && W(n), g(t), T(t));
421
+ }, F = async () => {
422
+ const t = E.value, n = e.current.value;
423
+ if (!t || !n) return;
424
+ const a = ce(t);
425
+ if (!a) return;
426
+ const r = i(w.value);
427
+ let s = b(n.id);
428
+ !s && !K(n) && (s = R(n.key)), s ? (s.routeIds.add(n.id), s.routeKey = n.key, s.routeInfo = n, s.matchedRoute = t, s.component = a, s.props = I(t), s.mounted = !0) : (s = {
428
429
  id: J("view"),
429
- routeKey: o.key,
430
- routeIds: /* @__PURE__ */ new Set([o.id]),
431
- routeInfo: o,
432
- matchedRoute: e,
433
- component: f,
434
- props: I(e),
435
- componentRef: C(),
430
+ routeKey: n.key,
431
+ routeIds: /* @__PURE__ */ new Set([n.id]),
432
+ routeInfo: n,
433
+ matchedRoute: t,
434
+ component: a,
435
+ props: I(t),
436
+ componentRef: G(),
436
437
  mounted: !0
437
- }, y.value = [...y.value, r]), w.value = r.id, await _(r, a);
438
+ }, m.value = [...m.value, s]), w.value = s.id, await V(s, r);
438
439
  };
439
- return ue(
440
+ return le(
440
441
  () => {
441
- var e;
442
- return [(e = t.current.value) == null ? void 0 : e.id, E.value];
442
+ var t;
443
+ return [(t = e.current.value) == null ? void 0 : t.id, E.value];
443
444
  },
444
445
  () => {
445
- V();
446
+ F();
446
447
  },
447
448
  { immediate: !0 }
448
- ), le(() => {
449
- h++, y.value = [];
449
+ ), de(() => {
450
+ f++, m.value = [];
450
451
  }), {
451
452
  injectedRoute: c,
452
- viewItems: y,
453
- registerStackPage: (e, o) => {
454
- e.pageElement = o, e.id === w.value ? S(o) : q(o);
453
+ viewItems: m,
454
+ registerStackPage: (t, n) => {
455
+ t.pageElement = n, t.id === w.value ? S(n) : q(n);
455
456
  }
456
457
  };
457
458
  },
458
459
  render() {
459
- return k(
460
+ return y(
460
461
  "div",
461
462
  { 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)
463
+ this.viewItems.filter((e) => e.mounted).map(
464
+ (e) => y(e.component, {
465
+ key: e.id,
466
+ ref: e.componentRef,
467
+ ...e.props,
468
+ registerStackPage: (o) => this.registerStackPage(e, o)
468
469
  })
469
470
  )
470
471
  );
471
472
  }
472
- }), He = Y({
473
+ }), Ke = Y({
473
474
  name: "RouterPage",
474
475
  props: {
475
476
  registerStackPage: {
@@ -477,25 +478,25 @@ const Ge = Y({
477
478
  default: void 0
478
479
  }
479
480
  },
480
- setup(t, { attrs: n, slots: c }) {
481
- const u = C();
482
- return fe(() => {
481
+ setup(e, { attrs: o, slots: c }) {
482
+ const u = G();
483
+ return he(() => {
483
484
  var d;
484
- u.value && ((d = t.registerStackPage) == null || d.call(t, u.value));
485
+ u.value && ((d = e.registerStackPage) == null || d.call(e, u.value));
485
486
  }), () => {
486
487
  var d;
487
- return k(
488
+ return y(
488
489
  "section",
489
490
  {
490
- ...n,
491
+ ...o,
491
492
  ref: u,
492
- class: ["rs-page", n.class]
493
+ class: ["rs-page", o.class]
493
494
  },
494
495
  (d = c.default) == null ? void 0 : d.call(c)
495
496
  );
496
497
  };
497
498
  }
498
- }), Ke = Y({
499
+ }), $e = Y({
499
500
  name: "StackRouterDebugPanel",
500
501
  props: {
501
502
  initialOpen: {
@@ -503,12 +504,12 @@ const Ge = Y({
503
504
  default: !1
504
505
  }
505
506
  },
506
- setup(t) {
507
- const n = ae(), c = C(t.initialOpen);
507
+ setup(e) {
508
+ const o = ae(), c = G(e.initialOpen);
508
509
  return () => {
509
- const u = n.current.value;
510
- return k("aside", { class: "rs-debug-panel" }, [
511
- k(
510
+ const u = o.current.value;
511
+ return y("aside", { class: "rs-debug-panel" }, [
512
+ y(
512
513
  "button",
513
514
  {
514
515
  class: "rs-debug-toggle",
@@ -519,21 +520,21 @@ const Ge = Y({
519
520
  },
520
521
  c.value ? "Stack x" : "Stack"
521
522
  ),
522
- c.value ? k("section", { class: "rs-debug-body" }, [
523
- k("header", [
524
- k("strong", "Router Stack"),
525
- k("span", `${n.history.length} pages`)
523
+ c.value ? y("section", { class: "rs-debug-body" }, [
524
+ y("header", [
525
+ y("strong", "Router Stack"),
526
+ y("span", `${o.history.length} pages`)
526
527
  ]),
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()))
528
+ y("dl", [
529
+ y("dt", "current"),
530
+ y("dd", (u == null ? void 0 : u.fullPath) ?? "-"),
531
+ y("dt", "canGoBack"),
532
+ y("dd", String(o.canGoBack()))
532
533
  ]),
533
- k(
534
+ y(
534
535
  "ol",
535
- n.history.map(
536
- (d) => k(
536
+ o.history.map(
537
+ (d) => y(
537
538
  "li",
538
539
  {
539
540
  key: d.id,
@@ -543,8 +544,8 @@ const Ge = Y({
543
544
  }
544
545
  },
545
546
  [
546
- k("code", d.fullPath),
547
- k("span", [
547
+ y("code", d.fullPath),
548
+ y("span", [
548
549
  `${d.action}/${d.direction}`,
549
550
  ` source:${d.source}`,
550
551
  ` entry:${d.entryDirection}`,
@@ -561,22 +562,22 @@ const Ge = Y({
561
562
  }
562
563
  });
563
564
  export {
564
- ze as RouterLink,
565
- Ge as RouterOutlet,
566
- He as RouterPage,
567
- je as RouterView,
568
- Ke as StackRouterDebugPanel,
565
+ je as RouterLink,
566
+ He as RouterOutlet,
567
+ Ke as RouterPage,
568
+ Me as RouterView,
569
+ $e as StackRouterDebugPanel,
569
570
  Ue as createMemoryHistory,
570
- Ae as createStackRouter,
571
+ Be as createStackRouter,
571
572
  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,
573
+ qe as createWebHistory,
574
+ Ae as defineStackTransition,
575
+ Ve as onPageDidEnter,
576
+ Ce as onPageDidLeave,
577
+ _e as onPageWillEnter,
578
+ Fe as onPageWillLeave,
578
579
  N as stackRouterKey,
579
- qe as useRoute,
580
- Je as useRouter,
581
- Ce as useStackRouter
580
+ Je as useRoute,
581
+ Qe as useRouter,
582
+ Ge as useStackRouter
582
583
  };
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.7",
4
4
  "description": "Page stack, caching, transitions, and lifecycle utilities built on vue-router.",
5
5
  "private": false,
6
6
  "type": "module",