@lytjs/router 4.2.0 → 5.0.0
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.
- package/dist/index.cjs +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of W(t))!U.call(e,u)&&u!==r&&T(e,u,{get:()=>t[u],enumerable:!(i=S(t,u))||i.enumerable});return e};var D=e=>A(T({},"__esModule",{value:!0}),e);var j={};z(j,{createHashHistory:()=>x,createNavigationGuards:()=>N,createRouteMatcher:()=>m,createRouter:()=>O,createWebHistory:()=>w,runAfterGuards:()=>b,runGuards:()=>y});module.exports=D(j);var p=require("@lytjs/common");function H(e,t=""){let r=(0,p.normalizePath)(t,e.path),{regex:i,paramKeys:u,isWildcard:s}=(0,p.pathToRegex)(r);if(e._regex=i,e._paramKeys=u,e._isWildcard=s,e.children)for(let c of e.children)H(c,r)}function m(e){let t=[];function r(n,a=""){for(let o of n)if(H(o,a),t.push(o),o.children){let d=(0,p.normalizePath)(a,o.path);r(o.children,d)}}r(e);function i(n){let a=n.replace(/\/+$/,"")||"/";for(let o of t){if(!o._regex)continue;let d=a.match(o._regex);if(d){let f={};if(o._paramKeys)for(let g=0;g<o._paramKeys.length;g++){let v=o._paramKeys[g];f[v]=d[g+1]||""}return{record:o,params:f,matchedPath:a}}}return null}function u(n){if(H(n),t.push(n),n.children){let a=(0,p.normalizePath)("",n.path);r(n.children,a)}}function s(n){for(let a=t.length-1;a>=0;a--)t[a].name===n&&t.splice(a,1)}function c(){return[...t]}return{matchRoute:i,addRoute:u,removeRoute:s,getRoutes:c}}function K(e){let t={};if(!e||e==="?")return t;let i=(e.startsWith("?")?e.slice(1):e).split("&");for(let u of i){let s=u.indexOf("=");if(s===-1)t[decodeURIComponent(u)]="";else{let c=decodeURIComponent(u.slice(0,s)),n=decodeURIComponent(u.slice(s+1));t[c]=n}}return t}function q(e){let t=[];for(let r of Object.keys(e)){let i=e[r];i!=null&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(i))}return t.join("&")}function I(e){let t="",r=e,i=e.indexOf("#");i!==-1&&(t=e.slice(i+1),r=e.slice(0,i));let u=r,s={},c=r.indexOf("?");return c!==-1&&(u=r.slice(0,c),s=K(r.slice(c))),{path:u,query:s,hash:t}}function h(e){return e.startsWith("/")||(e="/"+e),e.replace(/\/+/g,"/")}function w(e="/"){let t=h(e),r=[],i=s(window.location.href);function u(n){let a=s(window.location.href);a.fromPopState=!0,a.state=n.state;let o=i;i=a,c(a,o)}function s(n){let a;try{a=new URL(n)}catch(v){a=new URL(n,window.location.origin)}let o=a.pathname;t!=="/"&&o.startsWith(t)&&(o=o.slice(t.length)||"/");let{path:d,query:f,hash:g}=I(o+a.hash);return{path:h(d),fullPath:h(d)+(Object.keys(f).length?"?"+q(f):"")+(g?"#"+g:""),query:f,hash:g,state:a.state||null,fromPopState:!1}}function c(n,a){for(let o of r)o(n,a)}return window.addEventListener("popstate",u),{base:t,get location(){return i},push(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.pushState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},replace(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.replaceState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},go(n){window.history.go(n)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return s(window.location.href)},listen(n){return r.push(n),()=>{let a=r.indexOf(n);a!==-1&&r.splice(a,1)}},destroy(){window.removeEventListener("popstate",u),r.length=0}}}function x(){let e=[],t=i();function r(){let s=i();s.fromPopState=!0;let c=t;t=s,u(s,c)}function i(){let c=window.location.hash.slice(1)||"/",{path:n,query:a,hash:o}=I(c);return{path:h(n),fullPath:h(n)+(Object.keys(a).length?"?"+q(a):"")+(o?"#"+o:""),query:a,hash:o,state:null,fromPopState:!1}}function u(s,c){for(let n of e)n(s,c)}return window.addEventListener("hashchange",r),{base:"",get location(){return t},push(s,c){let n=h(s),a=t;window.location.hash=n,t=i(),u(t,a)},replace(s,c){let n=h(s),a=t;window.location.replace(window.location.pathname+window.location.search+"#"+n),t=i(),u(t,a)},go(s){window.history.go(s)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return i()},listen(s){return e.push(s),()=>{let c=e.indexOf(s);c!==-1&&e.splice(c,1)}},destroy(){window.removeEventListener("hashchange",r),e.length=0}}}function N(){let e=[],t=[],r=[];function i(c){return e.push(c),()=>{let n=e.indexOf(c);n!==-1&&e.splice(n,1)}}function u(c){return t.push(c),()=>{let n=t.indexOf(c);n!==-1&&t.splice(n,1)}}function s(c){return r.push(c),()=>{let n=r.indexOf(c);n!==-1&&r.splice(n,1)}}return{_beforeEachGuards:e,_beforeResolveGuards:t,_afterEachGuards:r,beforeEach:i,beforeResolve:u,afterEach:s}}function y(e,t,r){return new Promise((i,u)=>{let s=0;function c(){let a=!1;return o=>{a||(a=!0,o===!1?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):typeof o=="string"?u(new Error("REDIRECT:"+o)):(s++,n()))}}function n(){if(s>=e.length){i();return}let a=e[s],o=c();try{let d=a(t,r,o);d!=null&&typeof d=="object"&&typeof d.then=="function"&&d.then(()=>{}).catch(f=>{!f||typeof f.message!="string"||!f.message.startsWith("REDIRECT:")?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):u(f)})}catch(d){u(new Error("\u5BFC\u822A\u5B88\u536B\u6267\u884C\u51FA\u9519"))}}n()})}function b(e,t,r){for(let i of e)try{i(t,r)}catch(u){}}var L=require("@lytjs/reactivity");function $(e,t){return{path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash}}function C(e,t){return(0,L.reactive)({path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash,matched:t?[t.record]:[]})}function O(e){let t=m(e.routes),r=e.mode==="hash"?x():w(e.base||"/"),i=N(),u=(0,L.ref)(C(r.location,t.matchRoute(r.location.path))),s=!1,c=r.listen(async(o,d)=>{await n(o.path,d,!0)});async function n(o,d,f=!1){var g,v;if(!s){s=!0;try{let _=t.matchRoute(o),M={path:o,fullPath:o,query:{},hash:"",state:null,fromPopState:f},G=$(M,_),R=u.value,P={path:R.path,fullPath:R.fullPath,params:R.params,name:R.name,meta:R.meta,query:R.query,hash:R.hash};try{await y(i._beforeEachGuards,G,P)}catch(l){if((g=l==null?void 0:l.message)!=null&&g.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}try{await y(i._beforeResolveGuards,G,P)}catch(l){if((v=l==null?void 0:l.message)!=null&&v.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}let k=C(M,_);u.value=k,b(i._afterEachGuards,G,P)}finally{s=!1}}}let a={currentRoute:u,async push(o){r.push(o)},async replace(o){r.replace(o)},go(o){r.go(o)},back(){r.back()},forward(){r.forward()},beforeEach(o){return i.beforeEach(o)},afterEach(o){return i.afterEach(o)},beforeResolve(o){return i.beforeResolve(o)},addRoute(o){t.addRoute(o)},removeRoute(o){t.removeRoute(o)},getRoutes(){return t.getRoutes()},install(o){o.config&&o.config.globalProperties&&(o.config.globalProperties.$router=a,Object.defineProperty(o.config.globalProperties,"$route",{get(){return u.value}})),o.provide&&(o.provide("router",a),o.provide("route",u));let d=t.matchRoute(r.location.path);u.value=C(r.location,d)},destroy(){c(),r.destroy()}};return a}
|
|
1
|
+
"use strict";var T=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of W(t))!U.call(e,u)&&u!==r&&T(e,u,{get:()=>t[u],enumerable:!(i=S(t,u))||i.enumerable});return e};var D=e=>A(T({},"__esModule",{value:!0}),e);var j={};z(j,{createHashHistory:()=>x,createNavigationGuards:()=>N,createRouteMatcher:()=>m,createRouter:()=>O,createWebHistory:()=>w,runAfterGuards:()=>b,runGuards:()=>y});module.exports=D(j);var p=require("@lytjs/common");function H(e,t=""){let r=(0,p.normalizePath)(t,e.path),{regex:i,paramKeys:u,isWildcard:s}=(0,p.pathToRegex)(r);if(e._regex=i,e._paramKeys=u,e._isWildcard=s,e.children)for(let c of e.children)H(c,r)}function m(e){let t=[];function r(n,a=""){for(let o of n)if(H(o,a),t.push(o),o.children){let d=(0,p.normalizePath)(a,o.path);r(o.children,d)}}r(e);function i(n){let a=n.replace(/\/+$/,"")||"/";for(let o of t){if(!o._regex)continue;let d=a.match(o._regex);if(d){let f={};if(o._paramKeys)for(let g=0;g<o._paramKeys.length;g++){let v=o._paramKeys[g];f[v]=d[g+1]||""}return{record:o,params:f,matchedPath:a}}}return null}function u(n){if(H(n),t.push(n),n.children){let a=(0,p.normalizePath)("",n.path);r(n.children,a)}}function s(n){for(let a=t.length-1;a>=0;a--)t[a].name===n&&t.splice(a,1)}function c(){return[...t]}return{matchRoute:i,addRoute:u,removeRoute:s,getRoutes:c}}function K(e){let t={};if(!e||e==="?")return t;let i=(e.startsWith("?")?e.slice(1):e).split("&");for(let u of i){let s=u.indexOf("=");if(s===-1)t[decodeURIComponent(u)]="";else{let c=decodeURIComponent(u.slice(0,s)),n=decodeURIComponent(u.slice(s+1));t[c]=n}}return t}function q(e){let t=[];for(let r of Object.keys(e)){let i=e[r];i!=null&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(i))}return t.join("&")}function I(e){let t="",r=e,i=e.indexOf("#");i!==-1&&(t=e.slice(i+1),r=e.slice(0,i));let u=r,s={},c=r.indexOf("?");return c!==-1&&(u=r.slice(0,c),s=K(r.slice(c))),{path:u,query:s,hash:t}}function h(e){return e.startsWith("/")||(e="/"+e),e.replace(/\/+/g,"/")}function w(e="/"){let t=h(e),r=[],i=s(window.location.href);function u(n){let a=s(window.location.href);a.fromPopState=!0,a.state=n.state;let o=i;i=a,c(a,o)}function s(n){let a;try{a=new URL(n)}catch(v){a=new URL(n,window.location.origin)}let o=a.pathname;t!=="/"&&o.startsWith(t)&&(o=o.slice(t.length)||"/");let{path:d,query:f,hash:g}=I(o+a.hash);return{path:h(d),fullPath:h(d)+(Object.keys(f).length?"?"+q(f):"")+(g?"#"+g:""),query:f,hash:g,state:a.state||null,fromPopState:!1}}function c(n,a){for(let o of r)o(n,a)}return window.addEventListener("popstate",u),{base:t,get location(){return i},push(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.pushState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},replace(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.replaceState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},go(n){window.history.go(n)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return s(window.location.href)},listen(n){return r.push(n),()=>{let a=r.indexOf(n);a!==-1&&r.splice(a,1)}},destroy(){window.removeEventListener("popstate",u),r.length=0}}}function x(){let e=[],t=i();function r(){let s=i();s.fromPopState=!0;let c=t;t=s,u(s,c)}function i(){let c=window.location.hash.slice(1)||"/",{path:n,query:a,hash:o}=I(c);return{path:h(n),fullPath:h(n)+(Object.keys(a).length?"?"+q(a):"")+(o?"#"+o:""),query:a,hash:o,state:null,fromPopState:!1}}function u(s,c){for(let n of e)n(s,c)}return window.addEventListener("hashchange",r),{base:"",get location(){return t},push(s,c){let n=h(s),a=t;window.location.hash=n,t=i(),u(t,a)},replace(s,c){let n=h(s),a=t;window.location.replace(window.location.pathname+window.location.search+"#"+n),t=i(),u(t,a)},go(s){window.history.go(s)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return i()},listen(s){return e.push(s),()=>{let c=e.indexOf(s);c!==-1&&e.splice(c,1)}},destroy(){window.removeEventListener("hashchange",r),e.length=0}}}function N(){let e=[],t=[],r=[];function i(c){return e.push(c),()=>{let n=e.indexOf(c);n!==-1&&e.splice(n,1)}}function u(c){return t.push(c),()=>{let n=t.indexOf(c);n!==-1&&t.splice(n,1)}}function s(c){return r.push(c),()=>{let n=r.indexOf(c);n!==-1&&r.splice(n,1)}}return{_beforeEachGuards:e,_beforeResolveGuards:t,_afterEachGuards:r,beforeEach:i,beforeResolve:u,afterEach:s}}function y(e,t,r){return new Promise((i,u)=>{let s=0;function c(){let a=!1;return o=>{a||(a=!0,o===!1?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):typeof o=="string"?u(new Error("REDIRECT:"+o)):(s++,n()))}}function n(){if(s>=e.length){i();return}let a=e[s],o=c();try{let d=a(t,r,o);d!=null&&typeof d=="object"&&typeof d.then=="function"&&d.then(()=>{}).catch(f=>{!f||typeof f.message!="string"||!f.message.startsWith("REDIRECT:")?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):u(f)})}catch(d){u(new Error("\u5BFC\u822A\u5B88\u536B\u6267\u884C\u51FA\u9519"))}}n()})}function b(e,t,r){for(let i of e)try{i(t,r)}catch(u){}}var L=require("@lytjs/reactivity");function $(e,t){return{path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash}}function C(e,t){return(0,L.reactive)({path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash,matched:t?[t.record]:[]})}function O(e){let t=m(e.routes),r=e.mode==="hash"?x():w(e.base||"/"),i=N(),u=(0,L.ref)(C(r.location,t.matchRoute(r.location.path))),s=!1,c=r.listen(async(o,d)=>{await n(o.path,d,!0)});async function n(o,d,f=!1){var g,v;if(!s){s=!0;try{let _=t.matchRoute(o),M={path:o,fullPath:o,query:{},hash:"",state:null,fromPopState:f},G=$(M,_),R=u.value,P={path:R.path,fullPath:R.fullPath,params:R.params,name:R.name,meta:R.meta,query:R.query,hash:R.hash};try{await y(i._beforeEachGuards,G,P)}catch(l){if((g=l==null?void 0:l.message)!=null&&g.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}try{await y(i._beforeResolveGuards,G,P)}catch(l){if((v=l==null?void 0:l.message)!=null&&v.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}let k=C(M,_);u.value=k,b(i._afterEachGuards,G,P)}finally{s=!1}}}let a={currentRoute:u,async push(o){r.push(o)},async replace(o){r.replace(o)},go(o){r.go(o)},back(){r.back()},forward(){r.forward()},beforeEach(o){return i.beforeEach(o)},afterEach(o){return i.afterEach(o)},beforeResolve(o){return i.beforeResolve(o)},addRoute(o){t.addRoute(o)},removeRoute(o){t.removeRoute(o)},getRoutes(){return t.getRoutes()},install(o){o.config&&o.config.globalProperties&&(o.config.globalProperties.$router=a,Object.defineProperty(o.config.globalProperties,"$route",{get(){return u.value}})),o.provide&&(o.provide("router",a),o.provide("route",u));let d=t.matchRoute(r.location.path);u.value=C(r.location,d)},destroy(){c(),r.destroy()}};return a}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lytjs/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Lyt.js 内置路由 - History/Hash 模式、导航守卫、动态路由",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"hash"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@lytjs/common": "^
|
|
42
|
-
"@lytjs/reactivity": "^
|
|
41
|
+
"@lytjs/common": "^5.0.0",
|
|
42
|
+
"@lytjs/reactivity": "^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=18.0.0"
|