@wsxjs/wsx-router 0.0.14 → 0.0.16
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/dist/index.js +292 -263
- package/package.json +4 -4
- package/src/WsxLink.wsx +5 -6
- package/src/types/wsx.d.ts +6 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@wsxjs/wsx-core"),nt=":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";var ft;let pt,dt;function X(r,t,e){return(t=mt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function wt(r,t,e,n,v,j){function S(i,c,l){return function(a,o){return l&&l(a),i[c].call(a,o)}}function O(i,c){for(var l=0;l<i.length;l++)i[l].call(c);return c}function y(i,c,l,a){if(typeof i!="function"&&(a||i!==void 0))throw new TypeError(c+" must "+(l||"be")+" a function"+(a?"":" or undefined"));return i}function T(i,c,l,a,o,_,W,L,N,b,g,p,d){function w(u){if(!d(u))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],E=c[3],$=!L;if(!$){l||Array.isArray(x)||(x=[x]);var s={},C=[],m=o===3?"get":o===4||p?"set":"value";b?(g||p?s={get:it(function(){return E(this)},a,"get"),set:function(u){c[4](this,u)}}:s[m]=E,g||it(s[m],a,o===2?"":m)):g||(s=Object.getOwnPropertyDescriptor(i,a))}for(var f=i,P=x.length-1;P>=0;P-=l?2:1){var q=x[P],H=l?x[P-1]:void 0,K={},A={kind:["field","accessor","method","getter","setter","class"][o],name:a,metadata:_,addInitializer:(function(u,R){if(u.v)throw Error("attempted to call addInitializer after decoration was finished");y(R,"An initializer","be",!0),W.push(R)}).bind(null,K)};try{if($)(h=y(q.call(H,f,A),"class decorators","return"))&&(f=h);else{var k,U;A.static=N,A.private=b,b?o===2?k=function(u){return w(u),s.value}:(o<4&&(k=S(s,"get",w)),o!==3&&(U=S(s,"set",w))):(k=function(u){return u[a]},(o<2||o===4)&&(U=function(u,R){u[a]=R}));var Q=A.access={has:b?d.bind():function(u){return a in u}};if(k&&(Q.get=k),U&&(Q.set=U),f=q.call(H,p?{get:s.get,set:s.set}:s[m],A),p){if(typeof f=="object"&&f)(h=y(f.get,"accessor.get"))&&(s.get=h),(h=y(f.set,"accessor.set"))&&(s.set=h),(h=y(f.init,"accessor.init"))&&C.push(h);else if(f!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else y(f,(g?"field":"method")+" decorators","return")&&(g?C.push(f):s[m]=f)}}finally{K.v=!0}}return(g||p)&&L.push(function(u,R){for(var V=C.length-1;V>=0;V--)R=C[V].call(u,R);return R}),g||$||(b?p?L.push(S(s,"get"),S(s,"set")):L.push(o===2?s[m]:S.call.bind(s[m])):Object.defineProperty(i,a,s)),f}function z(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var M=j[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(M??null),G=function(i,c,l,a){var o,_,W=[],L=function(m){return Et(m)===i},N=new Map;function b(m){m&&W.push(O.bind(null,m))}for(var g=0;g<c.length;g++){var p=c[g];if(Array.isArray(p)){var d=p[1],w=p[2],h=p.length>3,x=16&d,E=!!(8&d),$=(d&=7)==0,s=w+"/"+E;if(!$&&!h){var C=N.get(s);if(C===!0||C===3&&d!==4||C===4&&d!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(s,!(d>2)||d)}T(E?i:i.prototype,p,x,h?"#"+w:mt(w),d,a,E?_=_||[]:o=o||[],W,E,h,$,d===1,E&&h?L:l)}}return b(o),b(_),W}(r,t,v,D);return e.length||z(r,D),{e:G,get c(){var i=[];return e.length&&[z(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function mt(r){var t=xt(r,"string");return typeof t=="symbol"?t:t+""}function xt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}function it(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function Et(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}const J=I.createLogger("WsxRouter");dt=[I.autoRegister({tagName:"wsx-router"})];exports.WsxRouter=void 0;class Ct extends I.LightComponent{constructor(){super({styles:nt,styleName:"wsx-router"}),X(this,"_autoStyles",nt),X(this,"views",new Map),X(this,"currentView",null),X(this,"handleRouteChange",()=>{const t=window.location.pathname;J.debug(`Route changed to: ${t}`),this.currentView&&(this.currentView.style.display="none",J.debug("Hiding previous view"));const e=this.matchRoute(t);if(e){e.style.display="block",this.currentView=e,J.debug(`Showing view for route: ${e.getAttribute("route")}`);const n=this.extractParams(e.getAttribute("route")||"/",t);n&&e.setAttribute("params",JSON.stringify(n))}else J.warn(`No view found for path: ${t}`);this.dispatchEvent(new CustomEvent("route-changed",{detail:{path:t,view:e},bubbles:!0,composed:!0}))}),X(this,"interceptLinks",t=>{const e=t.target.closest("a");if(!e)return;const n=e.getAttribute("href");!n||n.startsWith("http")||n.startsWith("#")||(t.preventDefault(),this.navigate(n))})}render(){return I.jsx("div",{class:"router-outlet"})}onConnected(){J.debug("WsxRouter connected to DOM"),this.collectViews(),J.debug("WsxRouter collected views:",this.views.size),window.addEventListener("popstate",this.handleRouteChange),this.addEventListener("click",this.interceptLinks),this.handleRouteChange()}onDisconnected(){window.removeEventListener("popstate",this.handleRouteChange)}collectViews(){const t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()==="wsx-view");J.debug("WsxRouter found views:",t.length),t.forEach(e=>{const n=e.getAttribute("route")||"/";this.views.set(n,e),e.style.display="none",J.debug(`WsxRouter hiding view for route: ${n}`)})}matchRoute(t){if(this.views.has(t))return this.views.get(t);for(const[e,n]of this.views)if(e.includes(":")){const v=e.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${v}$`).test(t))return n}return this.views.get("*")||null}extractParams(t,e){var y;if(!t.includes(":"))return null;const n=((y=t.match(/:([^/]+)/g))==null?void 0:y.map(T=>T.slice(1)))||[],v=t.replace(/:[^/]+/g,"([^/]+)"),j=new RegExp(`^${v}$`),S=e.match(j);if(!S||!n.length)return null;const O={};return n.forEach((T,z)=>{O[T]=S[z+1]}),O}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}ft=Ct;[exports.WsxRouter,pt]=wt(ft,[],dt,0,void 0,I.LightComponent).c;pt();const Rt=":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";var Z,F;let st,gt,at;function Y(r,t,e){return(t=vt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function St(r,t,e,n,v,j){function S(i,c,l){return function(a,o){return l&&l(a),i[c].call(a,o)}}function O(i,c){for(var l=0;l<i.length;l++)i[l].call(c);return c}function y(i,c,l,a){if(typeof i!="function"&&(a||i!==void 0))throw new TypeError(c+" must "+(l||"be")+" a function"+(a?"":" or undefined"));return i}function T(i,c,l,a,o,_,W,L,N,b,g,p,d){function w(u){if(!d(u))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],E=c[3],$=!L;if(!$){l||Array.isArray(x)||(x=[x]);var s={},C=[],m=o===3?"get":o===4||p?"set":"value";b?(g||p?s={get:ot(function(){return E(this)},a,"get"),set:function(u){c[4](this,u)}}:s[m]=E,g||ot(s[m],a,o===2?"":m)):g||(s=Object.getOwnPropertyDescriptor(i,a))}for(var f=i,P=x.length-1;P>=0;P-=l?2:1){var q=x[P],H=l?x[P-1]:void 0,K={},A={kind:["field","accessor","method","getter","setter","class"][o],name:a,metadata:_,addInitializer:(function(u,R){if(u.v)throw Error("attempted to call addInitializer after decoration was finished");y(R,"An initializer","be",!0),W.push(R)}).bind(null,K)};try{if($)(h=y(q.call(H,f,A),"class decorators","return"))&&(f=h);else{var k,U;A.static=N,A.private=b,b?o===2?k=function(u){return w(u),s.value}:(o<4&&(k=S(s,"get",w)),o!==3&&(U=S(s,"set",w))):(k=function(u){return u[a]},(o<2||o===4)&&(U=function(u,R){u[a]=R}));var Q=A.access={has:b?d.bind():function(u){return a in u}};if(k&&(Q.get=k),U&&(Q.set=U),f=q.call(H,p?{get:s.get,set:s.set}:s[m],A),p){if(typeof f=="object"&&f)(h=y(f.get,"accessor.get"))&&(s.get=h),(h=y(f.set,"accessor.set"))&&(s.set=h),(h=y(f.init,"accessor.init"))&&C.push(h);else if(f!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else y(f,(g?"field":"method")+" decorators","return")&&(g?C.push(f):s[m]=f)}}finally{K.v=!0}}return(g||p)&&L.push(function(u,R){for(var V=C.length-1;V>=0;V--)R=C[V].call(u,R);return R}),g||$||(b?p?L.push(S(s,"get"),S(s,"set")):L.push(o===2?s[m]:S.call.bind(s[m])):Object.defineProperty(i,a,s)),f}function z(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var M=j[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(M??null),G=function(i,c,l,a){var o,_,W=[],L=function(m){return Lt(m)===i},N=new Map;function b(m){m&&W.push(O.bind(null,m))}for(var g=0;g<c.length;g++){var p=c[g];if(Array.isArray(p)){var d=p[1],w=p[2],h=p.length>3,x=16&d,E=!!(8&d),$=(d&=7)==0,s=w+"/"+E;if(!$&&!h){var C=N.get(s);if(C===!0||C===3&&d!==4||C===4&&d!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(s,!(d>2)||d)}T(E?i:i.prototype,p,x,h?"#"+w:vt(w),d,a,E?_=_||[]:o=o||[],W,E,h,$,d===1,E&&h?L:l)}}return b(o),b(_),W}(r,t,v,D);return e.length||z(r,D),{e:G,get c(){var i=[];return e.length&&[z(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function vt(r){var t=jt(r,"string");return typeof t=="symbol"?t:t+""}function jt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ot(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function Lt(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function $t(r){return r}const tt=I.createLogger("WsxView");gt=[I.autoRegister({tagName:"wsx-view"})];exports.WsxView=void 0;new(at=(F=class extends I.LightComponent{constructor(){super({styles:Rt,styleName:"wsx-view"}),Y(this,"component",null),Y(this,"params",{}),Y(this,"componentInstance",null)}render(){return I.jsx("div",{class:"route-view"})}onConnected(){const t=this.getAttribute("component");t&&!this.componentInstance&&this.loadComponent(t)}onAttributeChanged(t,e,n){if(t==="component"&&n&&!this.componentInstance)this.loadComponent(n);else if(t==="params"&&this.componentInstance)try{this.params=JSON.parse(n),Object.entries(this.params).forEach(([v,j])=>{this.componentInstance.setAttribute(v,j)})}catch(v){tt.error("Failed to parse params:",v)}}async loadComponent(t){if(this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null),!customElements.get(t)){tt.warn(`Component ${t} not found in customElements registry`);return}this.componentInstance=document.createElement(t),Object.keys(this.params).length>0&&Object.entries(this.params).forEach(([v,j])=>{this.componentInstance.setAttribute(v,j)});const n=this.querySelector(".route-view");n?n.appendChild(this.componentInstance):tt.error("Route view container not found")}onDisconnected(){this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null)}},[exports.WsxView,st]=St(F,[],gt,0,void 0,I.LightComponent).c,F),Z=class extends $t{constructor(){super(exports.WsxView),Y(this,"observedAttributes",["route","component","params"]),st()}},Y(Z,at,void 0),Z);var et,rt;let ct,yt,ut;function B(r,t,e){return(t=bt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function _t(r,t,e,n,v,j){function S(i,c,l){return function(a,o){return l&&l(a),i[c].call(a,o)}}function O(i,c){for(var l=0;l<i.length;l++)i[l].call(c);return c}function y(i,c,l,a){if(typeof i!="function"&&(a||i!==void 0))throw new TypeError(c+" must "+(l||"be")+" a function"+(a?"":" or undefined"));return i}function T(i,c,l,a,o,_,W,L,N,b,g,p,d){function w(u){if(!d(u))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],E=c[3],$=!L;if(!$){l||Array.isArray(x)||(x=[x]);var s={},C=[],m=o===3?"get":o===4||p?"set":"value";b?(g||p?s={get:lt(function(){return E(this)},a,"get"),set:function(u){c[4](this,u)}}:s[m]=E,g||lt(s[m],a,o===2?"":m)):g||(s=Object.getOwnPropertyDescriptor(i,a))}for(var f=i,P=x.length-1;P>=0;P-=l?2:1){var q=x[P],H=l?x[P-1]:void 0,K={},A={kind:["field","accessor","method","getter","setter","class"][o],name:a,metadata:_,addInitializer:(function(u,R){if(u.v)throw Error("attempted to call addInitializer after decoration was finished");y(R,"An initializer","be",!0),W.push(R)}).bind(null,K)};try{if($)(h=y(q.call(H,f,A),"class decorators","return"))&&(f=h);else{var k,U;A.static=N,A.private=b,b?o===2?k=function(u){return w(u),s.value}:(o<4&&(k=S(s,"get",w)),o!==3&&(U=S(s,"set",w))):(k=function(u){return u[a]},(o<2||o===4)&&(U=function(u,R){u[a]=R}));var Q=A.access={has:b?d.bind():function(u){return a in u}};if(k&&(Q.get=k),U&&(Q.set=U),f=q.call(H,p?{get:s.get,set:s.set}:s[m],A),p){if(typeof f=="object"&&f)(h=y(f.get,"accessor.get"))&&(s.get=h),(h=y(f.set,"accessor.set"))&&(s.set=h),(h=y(f.init,"accessor.init"))&&C.push(h);else if(f!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else y(f,(g?"field":"method")+" decorators","return")&&(g?C.push(f):s[m]=f)}}finally{K.v=!0}}return(g||p)&&L.push(function(u,R){for(var V=C.length-1;V>=0;V--)R=C[V].call(u,R);return R}),g||$||(b?p?L.push(S(s,"get"),S(s,"set")):L.push(o===2?s[m]:S.call.bind(s[m])):Object.defineProperty(i,a,s)),f}function z(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var M=j[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(M??null),G=function(i,c,l,a){var o,_,W=[],L=function(m){return At(m)===i},N=new Map;function b(m){m&&W.push(O.bind(null,m))}for(var g=0;g<c.length;g++){var p=c[g];if(Array.isArray(p)){var d=p[1],w=p[2],h=p.length>3,x=16&d,E=!!(8&d),$=(d&=7)==0,s=w+"/"+E;if(!$&&!h){var C=N.get(s);if(C===!0||C===3&&d!==4||C===4&&d!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(s,!(d>2)||d)}T(E?i:i.prototype,p,x,h?"#"+w:bt(w),d,a,E?_=_||[]:o=o||[],W,E,h,$,d===1,E&&h?L:l)}}return b(o),b(_),W}(r,t,v,D);return e.length||z(r,D),{e:G,get c(){var i=[];return e.length&&[z(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function bt(r){var t=Wt(r,"string");return typeof t=="symbol"?t:t+""}function Wt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function lt(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function At(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function kt(r){return r}const ht=I.createLogger("WsxLink");yt=[I.autoRegister({tagName:"wsx-link"})];exports.WsxLink=void 0;new(ut=(rt=class extends I.WebComponent{constructor(...t){super(...t),B(this,"to",""),B(this,"replace",!1),B(this,"activeClass","active"),B(this,"exact",!1),B(this,"handleClick",e=>{if(e.preventDefault(),!this.to){ht.warn("No 'to' attribute specified");return}if(this.isExternalLink(this.to)){window.open(this.to,"_blank");return}this.replace?window.history.replaceState(null,"",this.to):window.history.pushState(null,"",this.to),window.dispatchEvent(new PopStateEvent("popstate")),ht.debug(`Navigated to: ${this.to}`)}),B(this,"updateActiveState",()=>{var j;const e=window.location.pathname,n=this.exact?e===this.to:e.startsWith(this.to)&&this.to!=="/",v=(j=this.shadowRoot)==null?void 0:j.querySelector("a");v&&(n?(v.classList.add(this.activeClass),this.setAttribute("active","")):(v.classList.remove(this.activeClass),this.removeAttribute("active")))})}render(){return I.jsx("a",{href:this.to,class:"wsx-link",onClick:this.handleClick,part:"link"},I.jsx("slot",null))}onConnected(){this.to=this.getAttribute("to")||"",this.replace=this.hasAttribute("replace"),this.activeClass=this.getAttribute("active-class")||"active",this.exact=this.hasAttribute("exact");const t=this.shadowRoot.querySelector(".wsx-link");t&&(t.href=this.to),window.addEventListener("popstate",this.updateActiveState),document.addEventListener("route-changed",this.updateActiveState),this.updateActiveState()}onDisconnected(){window.removeEventListener("popstate",this.updateActiveState),document.removeEventListener("route-changed",this.updateActiveState)}onAttributeChanged(t,e,n){switch(t){case"to":this.to=n||"",this.rerender(),this.updateActiveState();break;case"replace":this.replace=n!==null&&n!=="false";break;case"active-class":this.activeClass=n||"active",this.updateActiveState();break;case"exact":this.exact=n!==null&&n!=="false",this.updateActiveState();break}}isExternalLink(t){return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("mailto:")||t.startsWith("tel:")}navigate(){this.to&&this.handleClick(new MouseEvent("click",{bubbles:!0,cancelable:!0}))}},[exports.WsxLink,ct]=_t(rt,[],yt,0,void 0,I.WebComponent).c,rt),et=class extends kt{constructor(){super(exports.WsxLink),B(this,"observedAttributes",["to","replace","active-class","exact"]),ct()}},B(et,ut,void 0),et);const It=I.createLogger("RouterUtils");class Ot{static navigate(t,e=!1){e?window.history.replaceState(null,"",t):window.history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate")),It.debug(`Navigated to: ${t} (replace: ${e})`)}static getCurrentRoute(){const t=new URL(window.location.href);return{path:t.pathname,params:{},query:Object.fromEntries(t.searchParams.entries()),hash:t.hash.slice(1)}}static parseRoute(t,e){var n;if(t===e)return{route:t,params:{},exact:!0};if(t==="*")return{route:t,params:{},exact:!1};if(t.includes(":")){const v=((n=t.match(/:([^/]+)/g))==null?void 0:n.map(y=>y.slice(1)))||[],j=t.replace(/:[^/]+/g,"([^/]+)"),S=new RegExp(`^${j}$`),O=e.match(S);if(O&&v.length>0){const y={};return v.forEach((T,z)=>{y[T]=O[z+1]}),{route:t,params:y,exact:!0}}}if(t.endsWith("/*")){const v=t.slice(0,-2);if(e.startsWith(v))return{route:t,params:{},exact:!1}}return null}static buildPath(t,e={}){let n=t;return Object.entries(e).forEach(([v,j])=>{n=n.replace(`:${v}`,encodeURIComponent(j))}),n}static isRouteActive(t,e=!1){const n=window.location.pathname;return e?n===t:t==="/"?n==="/":n.startsWith(t)}static getRouteDepth(t){return t.split("/").filter(e=>e.length>0).length}static getParentRoute(t){const e=t.split("/").filter(n=>n.length>0);return e.length<=1?"/":(e.pop(),"/"+e.join("/"))}static joinPaths(...t){return t.map(e=>e.replace(/^\/+|\/+$/g,"")).filter(e=>e.length>0).join("/").replace(/^/,"/")}static isExternalUrl(t){return/^https?:\/\//.test(t)||/^mailto:/.test(t)||/^tel:/.test(t)}static getQueryParam(t){return new URL(window.location.href).searchParams.get(t)}static setQueryParam(t,e,n=!1){const v=new URL(window.location.href);v.searchParams.set(t,e);const j=v.pathname+v.search+v.hash;this.navigate(j,n)}static removeQueryParam(t,e=!1){const n=new URL(window.location.href);n.searchParams.delete(t);const v=n.pathname+n.search+n.hash;this.navigate(v,e)}static goBack(){window.history.back()}static goForward(){window.history.forward()}static replace(t){this.navigate(t,!0)}static getHistoryLength(){return window.history.length}static onRouteChange(t){const e=()=>{const n=this.getCurrentRoute();t(n)};return window.addEventListener("popstate",e),document.addEventListener("route-changed",e),()=>{window.removeEventListener("popstate",e),document.removeEventListener("route-changed",e)}}}exports.RouterUtils=Ot;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@wsxjs/wsx-core"),nt=":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";var ft;let pt,vt;function Y(r,t,e){return(t=gt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function xt(r,t,e,n,m,_){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function P(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function $(i,c,u,s,a,W,A,j,N,y,g,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],R=!j;if(!R){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(g||f?o={get:it(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,g||it(o[v],s,a===2?"":v)):g||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,z=x.length-1;z>=0;z-=u?2:1){var H=x[z],K=u?x[z-1]:void 0,Q={},O={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:W,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),A.push(S)}).bind(null,Q)};try{if(R)(h=b(H.call(K,d,O),"class decorators","return"))&&(d=h);else{var I,U;O.static=N,O.private=y,y?a===2?I=function(l){return w(l),o.value}:(a<4&&(I=C(o,"get",w)),a!==3&&(U=C(o,"set",w))):(I=function(l){return l[s]},(a<2||a===4)&&(U=function(l,S){l[s]=S}));var J=O.access={has:y?p.bind():function(l){return s in l}};if(I&&(J.get=I),U&&(J.set=U),d=H.call(K,f?{get:o.get,set:o.set}:o[v],O),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(g?"field":"method")+" decorators","return")&&(g?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(g||f)&&j.push(function(l,S){for(var M=E.length-1;M>=0;M--)S=E[M].call(l,S);return S}),g||R||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function D(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var V=_[Symbol.metadata||Symbol.for("Symbol.metadata")];var L=Object.create(V??null),X=function(i,c,u,s){var a,W,A=[],j=function(v){return Et(v)===i},N=new Map;function y(v){v&&A.push(P.bind(null,v))}for(var g=0;g<c.length;g++){var f=c[g];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),R=(p&=7)==0,o=w+"/"+k;if(!R&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}$(k?i:i.prototype,f,x,h?"#"+w:gt(w),p,s,k?W=W||[]:a=a||[],A,k,h,R,p===1,k&&h?j:u)}}return y(a),y(W),A}(r,t,m,L);return e.length||D(r,L),{e:X,get c(){var i=[];return e.length&&[D($(r,[e],n,r.name,5,L,i),L),P.bind(null,i,r)]}}}function gt(r){var t=kt(r,"string");return typeof t=="symbol"?t:t+""}function kt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}function it(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function Et(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}const B=T.createLogger("WsxRouter");vt=[T.autoRegister({tagName:"wsx-router"})];exports.WsxRouter=void 0;class St extends T.LightComponent{constructor(){super({styles:nt,styleName:"wsx-router"}),Y(this,"_autoStyles",nt),Y(this,"views",new Map),Y(this,"currentView",null),Y(this,"handleRouteChange",()=>{const t=window.location.pathname;B.debug(`Route changed to: ${t}`),this.currentView&&(this.currentView.style.display="none",B.debug("Hiding previous view"));const e=this.matchRoute(t);if(e){e.style.display="block",this.currentView=e,B.debug(`Showing view for route: ${e.getAttribute("route")}`);const n=this.extractParams(e.getAttribute("route")||"/",t);n&&e.setAttribute("params",JSON.stringify(n))}else B.warn(`No view found for path: ${t}`);this.dispatchEvent(new CustomEvent("route-changed",{detail:{path:t,view:e},bubbles:!0,composed:!0}))}),Y(this,"interceptLinks",t=>{const e=t.target.closest("a");if(!e)return;const n=e.getAttribute("href");!n||n.startsWith("http")||n.startsWith("#")||(t.preventDefault(),this.navigate(n))})}render(){return T.jsx("div",{class:"router-outlet"})}onConnected(){B.debug("WsxRouter connected to DOM"),this.collectViews(),B.debug("WsxRouter collected views:",this.views.size),window.addEventListener("popstate",this.handleRouteChange),this.addEventListener("click",this.interceptLinks),this.handleRouteChange()}onDisconnected(){window.removeEventListener("popstate",this.handleRouteChange)}collectViews(){const t=Array.from(this.children).filter(e=>e.tagName.toLowerCase()==="wsx-view");B.debug("WsxRouter found views:",t.length),t.forEach(e=>{const n=e.getAttribute("route")||"/";this.views.set(n,e),e.style.display="none",B.debug(`WsxRouter hiding view for route: ${n}`)})}matchRoute(t){if(this.views.has(t))return this.views.get(t);for(const[e,n]of this.views)if(e.includes(":")){const m=e.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${m}$`).test(t))return n}return this.views.get("*")||null}extractParams(t,e){var b;if(!t.includes(":"))return null;const n=((b=t.match(/:([^/]+)/g))==null?void 0:b.map($=>$.slice(1)))||[],m=t.replace(/:[^/]+/g,"([^/]+)"),_=new RegExp(`^${m}$`),C=e.match(_);if(!C||!n.length)return null;const P={};return n.forEach(($,D)=>{P[$]=C[D+1]}),P}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}ft=St;[exports.WsxRouter,pt]=xt(ft,[],vt,0,void 0,T.LightComponent).c;pt();const ot=":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";var Z,F;let st,mt,at;function G(r,t,e){return(t=bt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function Ct(r,t,e,n,m,_){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function P(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function $(i,c,u,s,a,W,A,j,N,y,g,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],R=!j;if(!R){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(g||f?o={get:ct(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,g||ct(o[v],s,a===2?"":v)):g||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,z=x.length-1;z>=0;z-=u?2:1){var H=x[z],K=u?x[z-1]:void 0,Q={},O={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:W,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),A.push(S)}).bind(null,Q)};try{if(R)(h=b(H.call(K,d,O),"class decorators","return"))&&(d=h);else{var I,U;O.static=N,O.private=y,y?a===2?I=function(l){return w(l),o.value}:(a<4&&(I=C(o,"get",w)),a!==3&&(U=C(o,"set",w))):(I=function(l){return l[s]},(a<2||a===4)&&(U=function(l,S){l[s]=S}));var J=O.access={has:y?p.bind():function(l){return s in l}};if(I&&(J.get=I),U&&(J.set=U),d=H.call(K,f?{get:o.get,set:o.set}:o[v],O),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(g?"field":"method")+" decorators","return")&&(g?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(g||f)&&j.push(function(l,S){for(var M=E.length-1;M>=0;M--)S=E[M].call(l,S);return S}),g||R||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function D(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var V=_[Symbol.metadata||Symbol.for("Symbol.metadata")];var L=Object.create(V??null),X=function(i,c,u,s){var a,W,A=[],j=function(v){return jt(v)===i},N=new Map;function y(v){v&&A.push(P.bind(null,v))}for(var g=0;g<c.length;g++){var f=c[g];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),R=(p&=7)==0,o=w+"/"+k;if(!R&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}$(k?i:i.prototype,f,x,h?"#"+w:bt(w),p,s,k?W=W||[]:a=a||[],A,k,h,R,p===1,k&&h?j:u)}}return y(a),y(W),A}(r,t,m,L);return e.length||D(r,L),{e:X,get c(){var i=[];return e.length&&[D($(r,[e],n,r.name,5,L,i),L),P.bind(null,i,r)]}}}function bt(r){var t=_t(r,"string");return typeof t=="symbol"?t:t+""}function _t(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ct(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function jt(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function Rt(r){return r}const tt=T.createLogger("WsxView");mt=[T.autoRegister({tagName:"wsx-view"})];exports.WsxView=void 0;new(at=(F=class extends T.LightComponent{constructor(){super({styles:ot,styleName:"wsx-view"}),G(this,"_autoStyles",ot),G(this,"component",null),G(this,"params",{}),G(this,"componentInstance",null)}render(){return T.jsx("div",{class:"route-view"})}onConnected(){const t=this.getAttribute("component");t&&!this.componentInstance&&this.loadComponent(t)}onAttributeChanged(t,e,n){if(t==="component"&&n&&!this.componentInstance)this.loadComponent(n);else if(t==="params"&&this.componentInstance)try{this.params=JSON.parse(n),Object.entries(this.params).forEach(([m,_])=>{this.componentInstance.setAttribute(m,_)})}catch(m){tt.error("Failed to parse params:",m)}}async loadComponent(t){if(this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null),!customElements.get(t)){tt.warn(`Component ${t} not found in customElements registry`);return}this.componentInstance=document.createElement(t),Object.keys(this.params).length>0&&Object.entries(this.params).forEach(([m,_])=>{this.componentInstance.setAttribute(m,_)});const n=this.querySelector(".route-view");n?n.appendChild(this.componentInstance):tt.error("Route view container not found")}onDisconnected(){this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null)}},[exports.WsxView,st]=Ct(F,[],mt,0,void 0,T.LightComponent).c,F),Z=class extends Rt{constructor(){super(exports.WsxView),G(this,"observedAttributes",["route","component","params"]),st()}},G(Z,at,void 0),Z);const $t=':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';var et,rt;let lt,yt,ut;function q(r,t,e){return(t=wt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function Lt(r,t,e,n,m,_){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function P(i,c){for(var u=0;u<i.length;u++)i[u].call(c);return c}function b(i,c,u,s){if(typeof i!="function"&&(s||i!==void 0))throw new TypeError(c+" must "+(u||"be")+" a function"+(s?"":" or undefined"));return i}function $(i,c,u,s,a,W,A,j,N,y,g,f,p){function w(l){if(!p(l))throw new TypeError("Attempted to access private element on non-instance")}var h,x=c[0],k=c[3],R=!j;if(!R){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(g||f?o={get:ht(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,g||ht(o[v],s,a===2?"":v)):g||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,z=x.length-1;z>=0;z-=u?2:1){var H=x[z],K=u?x[z-1]:void 0,Q={},O={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:W,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),A.push(S)}).bind(null,Q)};try{if(R)(h=b(H.call(K,d,O),"class decorators","return"))&&(d=h);else{var I,U;O.static=N,O.private=y,y?a===2?I=function(l){return w(l),o.value}:(a<4&&(I=C(o,"get",w)),a!==3&&(U=C(o,"set",w))):(I=function(l){return l[s]},(a<2||a===4)&&(U=function(l,S){l[s]=S}));var J=O.access={has:y?p.bind():function(l){return s in l}};if(I&&(J.get=I),U&&(J.set=U),d=H.call(K,f?{get:o.get,set:o.set}:o[v],O),f){if(typeof d=="object"&&d)(h=b(d.get,"accessor.get"))&&(o.get=h),(h=b(d.set,"accessor.set"))&&(o.set=h),(h=b(d.init,"accessor.init"))&&E.push(h);else if(d!==void 0)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0")}else b(d,(g?"field":"method")+" decorators","return")&&(g?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(g||f)&&j.push(function(l,S){for(var M=E.length-1;M>=0;M--)S=E[M].call(l,S);return S}),g||R||(y?f?j.push(C(o,"get"),C(o,"set")):j.push(a===2?o[v]:C.call.bind(o[v])):Object.defineProperty(i,s,o)),d}function D(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var V=_[Symbol.metadata||Symbol.for("Symbol.metadata")];var L=Object.create(V??null),X=function(i,c,u,s){var a,W,A=[],j=function(v){return At(v)===i},N=new Map;function y(v){v&&A.push(P.bind(null,v))}for(var g=0;g<c.length;g++){var f=c[g];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),R=(p&=7)==0,o=w+"/"+k;if(!R&&!h){var E=N.get(o);if(E===!0||E===3&&p!==4||E===4&&p!==3)throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+w);N.set(o,!(p>2)||p)}$(k?i:i.prototype,f,x,h?"#"+w:wt(w),p,s,k?W=W||[]:a=a||[],A,k,h,R,p===1,k&&h?j:u)}}return y(a),y(W),A}(r,t,m,L);return e.length||D(r,L),{e:X,get c(){var i=[];return e.length&&[D($(r,[e],n,r.name,5,L,i),L),P.bind(null,i,r)]}}}function wt(r){var t=Wt(r,"string");return typeof t=="symbol"?t:t+""}function Wt(r,t){if(typeof r!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ht(r,t,e){typeof t=="symbol"&&(t=(t=t.description)?"["+t+"]":"");try{Object.defineProperty(r,"name",{configurable:!0,value:e?e+" "+t:t})}catch{}return r}function At(r){if(Object(r)!==r)throw TypeError("right-hand side of 'in' should be an object, got "+(r!==null?typeof r:"null"));return r}function Ot(r){return r}const dt=T.createLogger("WsxLink");yt=[T.autoRegister({tagName:"wsx-link"})];exports.WsxLink=void 0;new(ut=(rt=class extends T.WebComponent{constructor(){super(),q(this,"_autoStyles",$t),q(this,"to",void 0),q(this,"replace",void 0),q(this,"activeClass",void 0),q(this,"exact",void 0),q(this,"handleClick",$=>{if($.preventDefault(),!this.to){dt.warn("No 'to' attribute specified");return}if(this.isExternalLink(this.to)){window.open(this.to,"_blank");return}this.replace?window.history.replaceState(null,"",this.to):window.history.pushState(null,"",this.to),window.dispatchEvent(new PopStateEvent("popstate")),dt.debug(`Navigated to: ${this.to}`)}),q(this,"updateActiveState",()=>{var L;const $=window.location.pathname,D=this.exact?$===this.to:$.startsWith(this.to)&&this.to!=="/",V=(L=this.shadowRoot)==null?void 0:L.querySelector("a");V&&(D?(V.classList.add(this.activeClass),this.setAttribute("active","")):(V.classList.remove(this.activeClass),this.removeAttribute("active")))});const[t,e]=this.useState("to","");Object.defineProperty(this,"to",{get:t,set:e,enumerable:!0,configurable:!0});const[n,m]=this.useState("replace",!1);Object.defineProperty(this,"replace",{get:n,set:m,enumerable:!0,configurable:!0});const[_,C]=this.useState("activeClass","active");Object.defineProperty(this,"activeClass",{get:_,set:C,enumerable:!0,configurable:!0});const[P,b]=this.useState("exact",!1);Object.defineProperty(this,"exact",{get:P,set:b,enumerable:!0,configurable:!0})}render(){return T.jsx("a",{href:this.to,class:"wsx-link",onClick:this.handleClick,part:"link"},T.jsx("slot",null))}onConnected(){this.to=this.getAttribute("to")||"",this.replace=this.hasAttribute("replace"),this.activeClass=this.getAttribute("active-class")||"active",this.exact=this.hasAttribute("exact");const t=this.shadowRoot.querySelector(".wsx-link");t&&(t.href=this.to),window.addEventListener("popstate",this.updateActiveState),document.addEventListener("route-changed",this.updateActiveState),this.updateActiveState()}onDisconnected(){window.removeEventListener("popstate",this.updateActiveState),document.removeEventListener("route-changed",this.updateActiveState)}onAttributeChanged(t,e,n){switch(t){case"to":this.to=n||"",this.updateActiveState();break;case"replace":this.replace=n!==null&&n!=="false";break;case"active-class":this.activeClass=n||"active",this.updateActiveState();break;case"exact":this.exact=n!==null&&n!=="false",this.updateActiveState();break}}isExternalLink(t){return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("mailto:")||t.startsWith("tel:")}navigate(){this.to&&this.handleClick(new MouseEvent("click",{bubbles:!0,cancelable:!0}))}},[exports.WsxLink,lt]=Lt(rt,[],yt,0,void 0,T.WebComponent).c,rt),et=class extends Ot{constructor(){super(exports.WsxLink),q(this,"observedAttributes",["to","replace","active-class","exact"]),lt()}},q(et,ut,void 0),et);const It=T.createLogger("RouterUtils");class Tt{static navigate(t,e=!1){e?window.history.replaceState(null,"",t):window.history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate")),It.debug(`Navigated to: ${t} (replace: ${e})`)}static getCurrentRoute(){const t=new URL(window.location.href);return{path:t.pathname,params:{},query:Object.fromEntries(t.searchParams.entries()),hash:t.hash.slice(1)}}static parseRoute(t,e){var n;if(t===e)return{route:t,params:{},exact:!0};if(t==="*")return{route:t,params:{},exact:!1};if(t.includes(":")){const m=((n=t.match(/:([^/]+)/g))==null?void 0:n.map(b=>b.slice(1)))||[],_=t.replace(/:[^/]+/g,"([^/]+)"),C=new RegExp(`^${_}$`),P=e.match(C);if(P&&m.length>0){const b={};return m.forEach(($,D)=>{b[$]=P[D+1]}),{route:t,params:b,exact:!0}}}if(t.endsWith("/*")){const m=t.slice(0,-2);if(e.startsWith(m))return{route:t,params:{},exact:!1}}return null}static buildPath(t,e={}){let n=t;return Object.entries(e).forEach(([m,_])=>{n=n.replace(`:${m}`,encodeURIComponent(_))}),n}static isRouteActive(t,e=!1){const n=window.location.pathname;return e?n===t:t==="/"?n==="/":n.startsWith(t)}static getRouteDepth(t){return t.split("/").filter(e=>e.length>0).length}static getParentRoute(t){const e=t.split("/").filter(n=>n.length>0);return e.length<=1?"/":(e.pop(),"/"+e.join("/"))}static joinPaths(...t){return t.map(e=>e.replace(/^\/+|\/+$/g,"")).filter(e=>e.length>0).join("/").replace(/^/,"/")}static isExternalUrl(t){return/^https?:\/\//.test(t)||/^mailto:/.test(t)||/^tel:/.test(t)}static getQueryParam(t){return new URL(window.location.href).searchParams.get(t)}static setQueryParam(t,e,n=!1){const m=new URL(window.location.href);m.searchParams.set(t,e);const _=m.pathname+m.search+m.hash;this.navigate(_,n)}static removeQueryParam(t,e=!1){const n=new URL(window.location.href);n.searchParams.delete(t);const m=n.pathname+n.search+n.hash;this.navigate(m,e)}static goBack(){window.history.back()}static goForward(){window.history.forward()}static replace(t){this.navigate(t,!0)}static getHistoryLength(){return window.history.length}static onRouteChange(t){const e=()=>{const n=this.getCurrentRoute();t(n)};return window.addEventListener("popstate",e),document.addEventListener("route-changed",e),()=>{window.removeEventListener("popstate",e),document.removeEventListener("route-changed",e)}}}exports.RouterUtils=Tt;
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { createLogger as F, autoRegister as
|
|
2
|
-
const
|
|
1
|
+
import { createLogger as F, autoRegister as ot, LightComponent as Y, jsx as Z, WebComponent as st } from "@wsxjs/wsx-core";
|
|
2
|
+
const at = ":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";
|
|
3
3
|
var yt;
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
return (t =
|
|
4
|
+
let wt, xt;
|
|
5
|
+
function X(r, t, e) {
|
|
6
|
+
return (t = kt(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
return function(
|
|
11
|
-
return
|
|
8
|
+
function Rt(r, t, e, n, g, C) {
|
|
9
|
+
function S(i, c, u) {
|
|
10
|
+
return function(s, a) {
|
|
11
|
+
return u && u(s), i[c].call(s, a);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
for (var
|
|
14
|
+
function T(i, c) {
|
|
15
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
16
16
|
return c;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
if (typeof i != "function" && (
|
|
18
|
+
function b(i, c, u, s) {
|
|
19
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
20
20
|
return i;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
function w(
|
|
24
|
-
if (!
|
|
22
|
+
function $(i, c, u, s, a, W, L, R, D, y, m, d, p) {
|
|
23
|
+
function w(l) {
|
|
24
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
25
25
|
}
|
|
26
|
-
var h, x = c[0],
|
|
26
|
+
var h, x = c[0], k = c[3], j = !R;
|
|
27
27
|
if (!j) {
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
},
|
|
33
|
-
c[4](this,
|
|
34
|
-
} } :
|
|
28
|
+
u || Array.isArray(x) || (x = [x]);
|
|
29
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
30
|
+
y ? (m || d ? o = { get: ct(function() {
|
|
31
|
+
return k(this);
|
|
32
|
+
}, s, "get"), set: function(l) {
|
|
33
|
+
c[4](this, l);
|
|
34
|
+
} } : o[v] = k, m || ct(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
35
35
|
}
|
|
36
|
-
for (var f = i, N = x.length - 1; N >= 0; N -=
|
|
37
|
-
var
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
}).bind(null,
|
|
36
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
37
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: W, addInitializer: (function(l, _) {
|
|
38
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
39
|
+
b(_, "An initializer", "be", !0), L.push(_);
|
|
40
|
+
}).bind(null, K) };
|
|
41
41
|
try {
|
|
42
|
-
if (j) (h =
|
|
42
|
+
if (j) (h = b(H.call(q, f, O), "class decorators", "return")) && (f = h);
|
|
43
43
|
else {
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
return w(
|
|
47
|
-
} : (
|
|
48
|
-
return
|
|
49
|
-
}, (
|
|
50
|
-
|
|
44
|
+
var I, z;
|
|
45
|
+
O.static = D, O.private = y, y ? a === 2 ? I = function(l) {
|
|
46
|
+
return w(l), o.value;
|
|
47
|
+
} : (a < 4 && (I = S(o, "get", w)), a !== 3 && (z = S(o, "set", w))) : (I = function(l) {
|
|
48
|
+
return l[s];
|
|
49
|
+
}, (a < 2 || a === 4) && (z = function(l, _) {
|
|
50
|
+
l[s] = _;
|
|
51
51
|
}));
|
|
52
|
-
var
|
|
53
|
-
return
|
|
52
|
+
var Q = O.access = { has: y ? p.bind() : function(l) {
|
|
53
|
+
return s in l;
|
|
54
54
|
} };
|
|
55
|
-
if (
|
|
56
|
-
if (typeof f == "object" && f) (h =
|
|
55
|
+
if (I && (Q.get = I), z && (Q.set = z), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], O), d) {
|
|
56
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
57
57
|
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
58
|
-
} else
|
|
58
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
59
59
|
}
|
|
60
60
|
} finally {
|
|
61
|
-
|
|
61
|
+
K.v = !0;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
return (
|
|
65
|
-
for (var
|
|
66
|
-
return
|
|
67
|
-
}),
|
|
64
|
+
return (m || d) && R.push(function(l, _) {
|
|
65
|
+
for (var V = E.length - 1; V >= 0; V--) _ = E[V].call(l, _);
|
|
66
|
+
return _;
|
|
67
|
+
}), m || j || (y ? d ? R.push(S(o, "get"), S(o, "set")) : R.push(a === 2 ? o[v] : S.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function P(i, c) {
|
|
70
70
|
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
71
71
|
}
|
|
72
|
-
if (arguments.length >= 6) var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
return
|
|
72
|
+
if (arguments.length >= 6) var U = C[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
73
|
+
var A = Object.create(U ?? null), G = function(i, c, u, s) {
|
|
74
|
+
var a, W, L = [], R = function(v) {
|
|
75
|
+
return $t(v) === i;
|
|
76
76
|
}, D = /* @__PURE__ */ new Map();
|
|
77
|
-
function
|
|
78
|
-
|
|
77
|
+
function y(v) {
|
|
78
|
+
v && L.push(T.bind(null, v));
|
|
79
79
|
}
|
|
80
|
-
for (var
|
|
81
|
-
var
|
|
82
|
-
if (Array.isArray(
|
|
83
|
-
var
|
|
80
|
+
for (var m = 0; m < c.length; m++) {
|
|
81
|
+
var d = c[m];
|
|
82
|
+
if (Array.isArray(d)) {
|
|
83
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), j = (p &= 7) == 0, o = w + "/" + k;
|
|
84
84
|
if (!j && !h) {
|
|
85
|
-
var
|
|
86
|
-
if (
|
|
87
|
-
D.set(
|
|
85
|
+
var E = D.get(o);
|
|
86
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
87
|
+
D.set(o, !(p > 2) || p);
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
$(k ? i : i.prototype, d, x, h ? "#" + w : kt(w), p, s, k ? W = W || [] : a = a || [], L, k, h, j, p === 1, k && h ? R : u);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
return
|
|
93
|
-
}(r, t, g,
|
|
94
|
-
return e.length ||
|
|
92
|
+
return y(a), y(W), L;
|
|
93
|
+
}(r, t, g, A);
|
|
94
|
+
return e.length || P(r, A), { e: G, get c() {
|
|
95
95
|
var i = [];
|
|
96
|
-
return e.length && [
|
|
96
|
+
return e.length && [P($(r, [e], n, r.name, 5, A, i), A), T.bind(null, i, r)];
|
|
97
97
|
} };
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
var t =
|
|
99
|
+
function kt(r) {
|
|
100
|
+
var t = jt(r, "string");
|
|
101
101
|
return typeof t == "symbol" ? t : t + "";
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function jt(r, t) {
|
|
104
104
|
if (typeof r != "object" || !r) return r;
|
|
105
105
|
var e = r[Symbol.toPrimitive];
|
|
106
106
|
if (e !== void 0) {
|
|
@@ -118,30 +118,30 @@ function ct(r, t, e) {
|
|
|
118
118
|
}
|
|
119
119
|
return r;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function $t(r) {
|
|
122
122
|
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
123
123
|
return r;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
125
|
+
const J = F("WsxRouter");
|
|
126
|
+
xt = [ot({
|
|
127
127
|
tagName: "wsx-router"
|
|
128
128
|
})];
|
|
129
129
|
let At;
|
|
130
130
|
class Wt extends Y {
|
|
131
131
|
constructor() {
|
|
132
132
|
super({
|
|
133
|
-
styles:
|
|
133
|
+
styles: at,
|
|
134
134
|
styleName: "wsx-router"
|
|
135
|
-
}),
|
|
135
|
+
}), X(this, "_autoStyles", at), X(this, "views", /* @__PURE__ */ new Map()), X(this, "currentView", null), X(this, "handleRouteChange", () => {
|
|
136
136
|
const t = window.location.pathname;
|
|
137
|
-
|
|
137
|
+
J.debug(`Route changed to: ${t}`), this.currentView && (this.currentView.style.display = "none", J.debug("Hiding previous view"));
|
|
138
138
|
const e = this.matchRoute(t);
|
|
139
139
|
if (e) {
|
|
140
|
-
e.style.display = "block", this.currentView = e,
|
|
140
|
+
e.style.display = "block", this.currentView = e, J.debug(`Showing view for route: ${e.getAttribute("route")}`);
|
|
141
141
|
const n = this.extractParams(e.getAttribute("route") || "/", t);
|
|
142
142
|
n && e.setAttribute("params", JSON.stringify(n));
|
|
143
143
|
} else
|
|
144
|
-
|
|
144
|
+
J.warn(`No view found for path: ${t}`);
|
|
145
145
|
this.dispatchEvent(new CustomEvent("route-changed", {
|
|
146
146
|
detail: {
|
|
147
147
|
path: t,
|
|
@@ -150,7 +150,7 @@ class Wt extends Y {
|
|
|
150
150
|
bubbles: !0,
|
|
151
151
|
composed: !0
|
|
152
152
|
}));
|
|
153
|
-
}),
|
|
153
|
+
}), X(this, "interceptLinks", (t) => {
|
|
154
154
|
const e = t.target.closest("a");
|
|
155
155
|
if (!e) return;
|
|
156
156
|
const n = e.getAttribute("href");
|
|
@@ -161,16 +161,16 @@ class Wt extends Y {
|
|
|
161
161
|
return /* @__PURE__ */ Z("div", { class: "router-outlet" });
|
|
162
162
|
}
|
|
163
163
|
onConnected() {
|
|
164
|
-
|
|
164
|
+
J.debug("WsxRouter connected to DOM"), this.collectViews(), J.debug("WsxRouter collected views:", this.views.size), window.addEventListener("popstate", this.handleRouteChange), this.addEventListener("click", this.interceptLinks), this.handleRouteChange();
|
|
165
165
|
}
|
|
166
166
|
onDisconnected() {
|
|
167
167
|
window.removeEventListener("popstate", this.handleRouteChange);
|
|
168
168
|
}
|
|
169
169
|
collectViews() {
|
|
170
170
|
const t = Array.from(this.children).filter((e) => e.tagName.toLowerCase() === "wsx-view");
|
|
171
|
-
|
|
171
|
+
J.debug("WsxRouter found views:", t.length), t.forEach((e) => {
|
|
172
172
|
const n = e.getAttribute("route") || "/";
|
|
173
|
-
this.views.set(n, e), e.style.display = "none",
|
|
173
|
+
this.views.set(n, e), e.style.display = "none", J.debug(`WsxRouter hiding view for route: ${n}`);
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
matchRoute(t) {
|
|
@@ -185,14 +185,14 @@ class Wt extends Y {
|
|
|
185
185
|
return this.views.get("*") || null;
|
|
186
186
|
}
|
|
187
187
|
extractParams(t, e) {
|
|
188
|
-
var
|
|
188
|
+
var b;
|
|
189
189
|
if (!t.includes(":")) return null;
|
|
190
|
-
const n = ((
|
|
191
|
-
if (!
|
|
192
|
-
const
|
|
193
|
-
return n.forEach((
|
|
194
|
-
|
|
195
|
-
}),
|
|
190
|
+
const n = ((b = t.match(/:([^/]+)/g)) == null ? void 0 : b.map(($) => $.slice(1))) || [], g = t.replace(/:[^/]+/g, "([^/]+)"), C = new RegExp(`^${g}$`), S = e.match(C);
|
|
191
|
+
if (!S || !n.length) return null;
|
|
192
|
+
const T = {};
|
|
193
|
+
return n.forEach(($, P) => {
|
|
194
|
+
T[$] = S[P + 1];
|
|
195
|
+
}), T;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* 编程式导航 - 使用原生 History API
|
|
@@ -202,110 +202,110 @@ class Wt extends Y {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
yt = Wt;
|
|
205
|
-
[At,
|
|
206
|
-
|
|
207
|
-
const
|
|
205
|
+
[At, wt] = Rt(yt, [], xt, 0, void 0, Y).c;
|
|
206
|
+
wt();
|
|
207
|
+
const lt = ":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";
|
|
208
208
|
var tt, et;
|
|
209
|
-
let ut, Et,
|
|
210
|
-
function
|
|
211
|
-
return (t =
|
|
209
|
+
let ut, Et, ht;
|
|
210
|
+
function B(r, t, e) {
|
|
211
|
+
return (t = _t(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
212
212
|
}
|
|
213
|
-
function
|
|
214
|
-
function
|
|
215
|
-
return function(
|
|
216
|
-
return
|
|
213
|
+
function Lt(r, t, e, n, g, C) {
|
|
214
|
+
function S(i, c, u) {
|
|
215
|
+
return function(s, a) {
|
|
216
|
+
return u && u(s), i[c].call(s, a);
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
function
|
|
220
|
-
for (var
|
|
219
|
+
function T(i, c) {
|
|
220
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
221
221
|
return c;
|
|
222
222
|
}
|
|
223
|
-
function
|
|
224
|
-
if (typeof i != "function" && (
|
|
223
|
+
function b(i, c, u, s) {
|
|
224
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
225
225
|
return i;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
228
|
-
function w(
|
|
229
|
-
if (!
|
|
227
|
+
function $(i, c, u, s, a, W, L, R, D, y, m, d, p) {
|
|
228
|
+
function w(l) {
|
|
229
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
230
230
|
}
|
|
231
|
-
var h, x = c[0],
|
|
231
|
+
var h, x = c[0], k = c[3], j = !R;
|
|
232
232
|
if (!j) {
|
|
233
|
-
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
},
|
|
238
|
-
c[4](this,
|
|
239
|
-
} } :
|
|
233
|
+
u || Array.isArray(x) || (x = [x]);
|
|
234
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
235
|
+
y ? (m || d ? o = { get: ft(function() {
|
|
236
|
+
return k(this);
|
|
237
|
+
}, s, "get"), set: function(l) {
|
|
238
|
+
c[4](this, l);
|
|
239
|
+
} } : o[v] = k, m || ft(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
240
240
|
}
|
|
241
|
-
for (var f = i, N = x.length - 1; N >= 0; N -=
|
|
242
|
-
var
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
}).bind(null,
|
|
241
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
242
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: W, addInitializer: (function(l, _) {
|
|
243
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
244
|
+
b(_, "An initializer", "be", !0), L.push(_);
|
|
245
|
+
}).bind(null, K) };
|
|
246
246
|
try {
|
|
247
|
-
if (j) (h =
|
|
247
|
+
if (j) (h = b(H.call(q, f, O), "class decorators", "return")) && (f = h);
|
|
248
248
|
else {
|
|
249
|
-
var
|
|
250
|
-
|
|
251
|
-
return w(
|
|
252
|
-
} : (
|
|
253
|
-
return
|
|
254
|
-
}, (
|
|
255
|
-
|
|
249
|
+
var I, z;
|
|
250
|
+
O.static = D, O.private = y, y ? a === 2 ? I = function(l) {
|
|
251
|
+
return w(l), o.value;
|
|
252
|
+
} : (a < 4 && (I = S(o, "get", w)), a !== 3 && (z = S(o, "set", w))) : (I = function(l) {
|
|
253
|
+
return l[s];
|
|
254
|
+
}, (a < 2 || a === 4) && (z = function(l, _) {
|
|
255
|
+
l[s] = _;
|
|
256
256
|
}));
|
|
257
|
-
var
|
|
258
|
-
return
|
|
257
|
+
var Q = O.access = { has: y ? p.bind() : function(l) {
|
|
258
|
+
return s in l;
|
|
259
259
|
} };
|
|
260
|
-
if (
|
|
261
|
-
if (typeof f == "object" && f) (h =
|
|
260
|
+
if (I && (Q.get = I), z && (Q.set = z), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], O), d) {
|
|
261
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
262
262
|
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
263
|
-
} else
|
|
263
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
264
264
|
}
|
|
265
265
|
} finally {
|
|
266
|
-
|
|
266
|
+
K.v = !0;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
return (
|
|
270
|
-
for (var
|
|
271
|
-
return
|
|
272
|
-
}),
|
|
269
|
+
return (m || d) && R.push(function(l, _) {
|
|
270
|
+
for (var V = E.length - 1; V >= 0; V--) _ = E[V].call(l, _);
|
|
271
|
+
return _;
|
|
272
|
+
}), m || j || (y ? d ? R.push(S(o, "get"), S(o, "set")) : R.push(a === 2 ? o[v] : S.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function P(i, c) {
|
|
275
275
|
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
276
276
|
}
|
|
277
|
-
if (arguments.length >= 6) var
|
|
278
|
-
var
|
|
279
|
-
var
|
|
280
|
-
return
|
|
277
|
+
if (arguments.length >= 6) var U = C[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
278
|
+
var A = Object.create(U ?? null), G = function(i, c, u, s) {
|
|
279
|
+
var a, W, L = [], R = function(v) {
|
|
280
|
+
return It(v) === i;
|
|
281
281
|
}, D = /* @__PURE__ */ new Map();
|
|
282
|
-
function
|
|
283
|
-
|
|
282
|
+
function y(v) {
|
|
283
|
+
v && L.push(T.bind(null, v));
|
|
284
284
|
}
|
|
285
|
-
for (var
|
|
286
|
-
var
|
|
287
|
-
if (Array.isArray(
|
|
288
|
-
var
|
|
285
|
+
for (var m = 0; m < c.length; m++) {
|
|
286
|
+
var d = c[m];
|
|
287
|
+
if (Array.isArray(d)) {
|
|
288
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), j = (p &= 7) == 0, o = w + "/" + k;
|
|
289
289
|
if (!j && !h) {
|
|
290
|
-
var
|
|
291
|
-
if (
|
|
292
|
-
D.set(
|
|
290
|
+
var E = D.get(o);
|
|
291
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
292
|
+
D.set(o, !(p > 2) || p);
|
|
293
293
|
}
|
|
294
|
-
|
|
294
|
+
$(k ? i : i.prototype, d, x, h ? "#" + w : _t(w), p, s, k ? W = W || [] : a = a || [], L, k, h, j, p === 1, k && h ? R : u);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
return
|
|
298
|
-
}(r, t, g,
|
|
299
|
-
return e.length ||
|
|
297
|
+
return y(a), y(W), L;
|
|
298
|
+
}(r, t, g, A);
|
|
299
|
+
return e.length || P(r, A), { e: G, get c() {
|
|
300
300
|
var i = [];
|
|
301
|
-
return e.length && [
|
|
301
|
+
return e.length && [P($(r, [e], n, r.name, 5, A, i), A), T.bind(null, i, r)];
|
|
302
302
|
} };
|
|
303
303
|
}
|
|
304
|
-
function
|
|
305
|
-
var t =
|
|
304
|
+
function _t(r) {
|
|
305
|
+
var t = Ot(r, "string");
|
|
306
306
|
return typeof t == "symbol" ? t : t + "";
|
|
307
307
|
}
|
|
308
|
-
function
|
|
308
|
+
function Ot(r, t) {
|
|
309
309
|
if (typeof r != "object" || !r) return r;
|
|
310
310
|
var e = r[Symbol.toPrimitive];
|
|
311
311
|
if (e !== void 0) {
|
|
@@ -315,7 +315,7 @@ function It(r, t) {
|
|
|
315
315
|
}
|
|
316
316
|
return (t === "string" ? String : Number)(r);
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function ft(r, t, e) {
|
|
319
319
|
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
320
320
|
try {
|
|
321
321
|
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
@@ -323,7 +323,7 @@ function ht(r, t, e) {
|
|
|
323
323
|
}
|
|
324
324
|
return r;
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function It(r) {
|
|
327
327
|
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
328
328
|
return r;
|
|
329
329
|
}
|
|
@@ -331,16 +331,16 @@ function Tt(r) {
|
|
|
331
331
|
return r;
|
|
332
332
|
}
|
|
333
333
|
const rt = F("WsxView");
|
|
334
|
-
Et = [
|
|
334
|
+
Et = [ot({
|
|
335
335
|
tagName: "wsx-view"
|
|
336
336
|
})];
|
|
337
|
-
let
|
|
338
|
-
new (
|
|
337
|
+
let dt;
|
|
338
|
+
new (ht = (et = class extends Y {
|
|
339
339
|
constructor() {
|
|
340
340
|
super({
|
|
341
|
-
styles:
|
|
341
|
+
styles: lt,
|
|
342
342
|
styleName: "wsx-view"
|
|
343
|
-
}),
|
|
343
|
+
}), B(this, "_autoStyles", lt), B(this, "component", null), B(this, "params", {}), B(this, "componentInstance", null);
|
|
344
344
|
}
|
|
345
345
|
render() {
|
|
346
346
|
return /* @__PURE__ */ Z("div", { class: "route-view" });
|
|
@@ -375,108 +375,109 @@ new (lt = (et = class extends Y {
|
|
|
375
375
|
onDisconnected() {
|
|
376
376
|
this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null);
|
|
377
377
|
}
|
|
378
|
-
}, [
|
|
378
|
+
}, [dt, ut] = Lt(et, [], Et, 0, void 0, Y).c, et), tt = class extends Tt {
|
|
379
379
|
constructor() {
|
|
380
|
-
super(
|
|
380
|
+
super(dt), B(this, "observedAttributes", ["route", "component", "params"]), ut();
|
|
381
381
|
}
|
|
382
|
-
},
|
|
382
|
+
}, B(tt, ht, void 0), tt)();
|
|
383
|
+
const Pt = ':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, #007bff);outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';
|
|
383
384
|
var nt, it;
|
|
384
|
-
let pt, St,
|
|
385
|
-
function
|
|
386
|
-
return (t =
|
|
385
|
+
let pt, St, vt;
|
|
386
|
+
function M(r, t, e) {
|
|
387
|
+
return (t = Ct(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
387
388
|
}
|
|
388
389
|
function Dt(r, t, e, n, g, C) {
|
|
389
|
-
function
|
|
390
|
-
return function(
|
|
391
|
-
return
|
|
390
|
+
function S(i, c, u) {
|
|
391
|
+
return function(s, a) {
|
|
392
|
+
return u && u(s), i[c].call(s, a);
|
|
392
393
|
};
|
|
393
394
|
}
|
|
394
|
-
function
|
|
395
|
-
for (var
|
|
395
|
+
function T(i, c) {
|
|
396
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
396
397
|
return c;
|
|
397
398
|
}
|
|
398
|
-
function
|
|
399
|
-
if (typeof i != "function" && (
|
|
399
|
+
function b(i, c, u, s) {
|
|
400
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
400
401
|
return i;
|
|
401
402
|
}
|
|
402
|
-
function
|
|
403
|
-
function w(
|
|
404
|
-
if (!
|
|
403
|
+
function $(i, c, u, s, a, W, L, R, D, y, m, d, p) {
|
|
404
|
+
function w(l) {
|
|
405
|
+
if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
405
406
|
}
|
|
406
|
-
var h, x = c[0],
|
|
407
|
+
var h, x = c[0], k = c[3], j = !R;
|
|
407
408
|
if (!j) {
|
|
408
|
-
|
|
409
|
-
var
|
|
410
|
-
|
|
411
|
-
return
|
|
412
|
-
},
|
|
413
|
-
c[4](this,
|
|
414
|
-
} } :
|
|
409
|
+
u || Array.isArray(x) || (x = [x]);
|
|
410
|
+
var o = {}, E = [], v = a === 3 ? "get" : a === 4 || d ? "set" : "value";
|
|
411
|
+
y ? (m || d ? o = { get: mt(function() {
|
|
412
|
+
return k(this);
|
|
413
|
+
}, s, "get"), set: function(l) {
|
|
414
|
+
c[4](this, l);
|
|
415
|
+
} } : o[v] = k, m || mt(o[v], s, a === 2 ? "" : v)) : m || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
415
416
|
}
|
|
416
|
-
for (var f = i, N = x.length - 1; N >= 0; N -=
|
|
417
|
-
var
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
}).bind(null,
|
|
417
|
+
for (var f = i, N = x.length - 1; N >= 0; N -= u ? 2 : 1) {
|
|
418
|
+
var H = x[N], q = u ? x[N - 1] : void 0, K = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: W, addInitializer: (function(l, _) {
|
|
419
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
420
|
+
b(_, "An initializer", "be", !0), L.push(_);
|
|
421
|
+
}).bind(null, K) };
|
|
421
422
|
try {
|
|
422
|
-
if (j) (h =
|
|
423
|
+
if (j) (h = b(H.call(q, f, O), "class decorators", "return")) && (f = h);
|
|
423
424
|
else {
|
|
424
|
-
var
|
|
425
|
-
|
|
426
|
-
return w(
|
|
427
|
-
} : (
|
|
428
|
-
return
|
|
429
|
-
}, (
|
|
430
|
-
|
|
425
|
+
var I, z;
|
|
426
|
+
O.static = D, O.private = y, y ? a === 2 ? I = function(l) {
|
|
427
|
+
return w(l), o.value;
|
|
428
|
+
} : (a < 4 && (I = S(o, "get", w)), a !== 3 && (z = S(o, "set", w))) : (I = function(l) {
|
|
429
|
+
return l[s];
|
|
430
|
+
}, (a < 2 || a === 4) && (z = function(l, _) {
|
|
431
|
+
l[s] = _;
|
|
431
432
|
}));
|
|
432
|
-
var
|
|
433
|
-
return
|
|
433
|
+
var Q = O.access = { has: y ? p.bind() : function(l) {
|
|
434
|
+
return s in l;
|
|
434
435
|
} };
|
|
435
|
-
if (
|
|
436
|
-
if (typeof f == "object" && f) (h =
|
|
436
|
+
if (I && (Q.get = I), z && (Q.set = z), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], O), d) {
|
|
437
|
+
if (typeof f == "object" && f) (h = b(f.get, "accessor.get")) && (o.get = h), (h = b(f.set, "accessor.set")) && (o.set = h), (h = b(f.init, "accessor.init")) && E.push(h);
|
|
437
438
|
else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
438
|
-
} else
|
|
439
|
+
} else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
|
|
439
440
|
}
|
|
440
441
|
} finally {
|
|
441
|
-
|
|
442
|
+
K.v = !0;
|
|
442
443
|
}
|
|
443
444
|
}
|
|
444
|
-
return (
|
|
445
|
-
for (var
|
|
446
|
-
return
|
|
447
|
-
}),
|
|
445
|
+
return (m || d) && R.push(function(l, _) {
|
|
446
|
+
for (var V = E.length - 1; V >= 0; V--) _ = E[V].call(l, _);
|
|
447
|
+
return _;
|
|
448
|
+
}), m || j || (y ? d ? R.push(S(o, "get"), S(o, "set")) : R.push(a === 2 ? o[v] : S.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
|
|
448
449
|
}
|
|
449
|
-
function
|
|
450
|
+
function P(i, c) {
|
|
450
451
|
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
451
452
|
}
|
|
452
|
-
if (arguments.length >= 6) var
|
|
453
|
-
var
|
|
454
|
-
var
|
|
455
|
-
return
|
|
453
|
+
if (arguments.length >= 6) var U = C[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
454
|
+
var A = Object.create(U ?? null), G = function(i, c, u, s) {
|
|
455
|
+
var a, W, L = [], R = function(v) {
|
|
456
|
+
return zt(v) === i;
|
|
456
457
|
}, D = /* @__PURE__ */ new Map();
|
|
457
|
-
function
|
|
458
|
-
|
|
458
|
+
function y(v) {
|
|
459
|
+
v && L.push(T.bind(null, v));
|
|
459
460
|
}
|
|
460
|
-
for (var
|
|
461
|
-
var
|
|
462
|
-
if (Array.isArray(
|
|
463
|
-
var
|
|
461
|
+
for (var m = 0; m < c.length; m++) {
|
|
462
|
+
var d = c[m];
|
|
463
|
+
if (Array.isArray(d)) {
|
|
464
|
+
var p = d[1], w = d[2], h = d.length > 3, x = 16 & p, k = !!(8 & p), j = (p &= 7) == 0, o = w + "/" + k;
|
|
464
465
|
if (!j && !h) {
|
|
465
|
-
var
|
|
466
|
-
if (
|
|
467
|
-
D.set(
|
|
466
|
+
var E = D.get(o);
|
|
467
|
+
if (E === !0 || E === 3 && p !== 4 || E === 4 && p !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + w);
|
|
468
|
+
D.set(o, !(p > 2) || p);
|
|
468
469
|
}
|
|
469
|
-
|
|
470
|
+
$(k ? i : i.prototype, d, x, h ? "#" + w : Ct(w), p, s, k ? W = W || [] : a = a || [], L, k, h, j, p === 1, k && h ? R : u);
|
|
470
471
|
}
|
|
471
472
|
}
|
|
472
|
-
return
|
|
473
|
-
}(r, t, g,
|
|
474
|
-
return e.length ||
|
|
473
|
+
return y(a), y(W), L;
|
|
474
|
+
}(r, t, g, A);
|
|
475
|
+
return e.length || P(r, A), { e: G, get c() {
|
|
475
476
|
var i = [];
|
|
476
|
-
return e.length && [
|
|
477
|
+
return e.length && [P($(r, [e], n, r.name, 5, A, i), A), T.bind(null, i, r)];
|
|
477
478
|
} };
|
|
478
479
|
}
|
|
479
|
-
function
|
|
480
|
+
function Ct(r) {
|
|
480
481
|
var t = Nt(r, "string");
|
|
481
482
|
return typeof t == "symbol" ? t : t + "";
|
|
482
483
|
}
|
|
@@ -498,34 +499,62 @@ function mt(r, t, e) {
|
|
|
498
499
|
}
|
|
499
500
|
return r;
|
|
500
501
|
}
|
|
501
|
-
function
|
|
502
|
+
function zt(r) {
|
|
502
503
|
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
503
504
|
return r;
|
|
504
505
|
}
|
|
505
|
-
function
|
|
506
|
+
function Ut(r) {
|
|
506
507
|
return r;
|
|
507
508
|
}
|
|
508
|
-
const
|
|
509
|
-
St = [
|
|
509
|
+
const gt = F("WsxLink");
|
|
510
|
+
St = [ot({
|
|
510
511
|
tagName: "wsx-link"
|
|
511
512
|
})];
|
|
512
|
-
let
|
|
513
|
-
new (
|
|
514
|
-
constructor(
|
|
515
|
-
super(
|
|
516
|
-
if (
|
|
517
|
-
|
|
513
|
+
let bt;
|
|
514
|
+
new (vt = (it = class extends st {
|
|
515
|
+
constructor() {
|
|
516
|
+
super(), M(this, "_autoStyles", Pt), M(this, "to", void 0), M(this, "replace", void 0), M(this, "activeClass", void 0), M(this, "exact", void 0), M(this, "handleClick", ($) => {
|
|
517
|
+
if ($.preventDefault(), !this.to) {
|
|
518
|
+
gt.warn("No 'to' attribute specified");
|
|
518
519
|
return;
|
|
519
520
|
}
|
|
520
521
|
if (this.isExternalLink(this.to)) {
|
|
521
522
|
window.open(this.to, "_blank");
|
|
522
523
|
return;
|
|
523
524
|
}
|
|
524
|
-
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")),
|
|
525
|
-
}),
|
|
526
|
-
var
|
|
527
|
-
const
|
|
528
|
-
|
|
525
|
+
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")), gt.debug(`Navigated to: ${this.to}`);
|
|
526
|
+
}), M(this, "updateActiveState", () => {
|
|
527
|
+
var A;
|
|
528
|
+
const $ = window.location.pathname, P = this.exact ? $ === this.to : $.startsWith(this.to) && this.to !== "/", U = (A = this.shadowRoot) == null ? void 0 : A.querySelector("a");
|
|
529
|
+
U && (P ? (U.classList.add(this.activeClass), this.setAttribute("active", "")) : (U.classList.remove(this.activeClass), this.removeAttribute("active")));
|
|
530
|
+
});
|
|
531
|
+
const [t, e] = this.useState("to", "");
|
|
532
|
+
Object.defineProperty(this, "to", {
|
|
533
|
+
get: t,
|
|
534
|
+
set: e,
|
|
535
|
+
enumerable: !0,
|
|
536
|
+
configurable: !0
|
|
537
|
+
});
|
|
538
|
+
const [n, g] = this.useState("replace", !1);
|
|
539
|
+
Object.defineProperty(this, "replace", {
|
|
540
|
+
get: n,
|
|
541
|
+
set: g,
|
|
542
|
+
enumerable: !0,
|
|
543
|
+
configurable: !0
|
|
544
|
+
});
|
|
545
|
+
const [C, S] = this.useState("activeClass", "active");
|
|
546
|
+
Object.defineProperty(this, "activeClass", {
|
|
547
|
+
get: C,
|
|
548
|
+
set: S,
|
|
549
|
+
enumerable: !0,
|
|
550
|
+
configurable: !0
|
|
551
|
+
});
|
|
552
|
+
const [T, b] = this.useState("exact", !1);
|
|
553
|
+
Object.defineProperty(this, "exact", {
|
|
554
|
+
get: T,
|
|
555
|
+
set: b,
|
|
556
|
+
enumerable: !0,
|
|
557
|
+
configurable: !0
|
|
529
558
|
});
|
|
530
559
|
}
|
|
531
560
|
render() {
|
|
@@ -542,7 +571,7 @@ new (dt = (it = class extends at {
|
|
|
542
571
|
onAttributeChanged(t, e, n) {
|
|
543
572
|
switch (t) {
|
|
544
573
|
case "to":
|
|
545
|
-
this.to = n || "", this.
|
|
574
|
+
this.to = n || "", this.updateActiveState();
|
|
546
575
|
break;
|
|
547
576
|
case "replace":
|
|
548
577
|
this.replace = n !== null && n !== "false";
|
|
@@ -567,18 +596,18 @@ new (dt = (it = class extends at {
|
|
|
567
596
|
cancelable: !0
|
|
568
597
|
}));
|
|
569
598
|
}
|
|
570
|
-
}, [
|
|
599
|
+
}, [bt, pt] = Dt(it, [], St, 0, void 0, st).c, it), nt = class extends Ut {
|
|
571
600
|
constructor() {
|
|
572
|
-
super(
|
|
601
|
+
super(bt), M(this, "observedAttributes", ["to", "replace", "active-class", "exact"]), pt();
|
|
573
602
|
}
|
|
574
|
-
},
|
|
575
|
-
const
|
|
576
|
-
class
|
|
603
|
+
}, M(nt, vt, void 0), nt)();
|
|
604
|
+
const Vt = F("RouterUtils");
|
|
605
|
+
class Kt {
|
|
577
606
|
/**
|
|
578
607
|
* 编程式导航
|
|
579
608
|
*/
|
|
580
609
|
static navigate(t, e = !1) {
|
|
581
|
-
e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")),
|
|
610
|
+
e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), Vt.debug(`Navigated to: ${t} (replace: ${e})`);
|
|
582
611
|
}
|
|
583
612
|
/**
|
|
584
613
|
* 获取当前路由信息
|
|
@@ -612,14 +641,14 @@ class qt {
|
|
|
612
641
|
exact: !1
|
|
613
642
|
};
|
|
614
643
|
if (t.includes(":")) {
|
|
615
|
-
const g = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((
|
|
616
|
-
if (
|
|
617
|
-
const
|
|
618
|
-
return g.forEach((
|
|
619
|
-
|
|
644
|
+
const g = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((b) => b.slice(1))) || [], C = t.replace(/:[^/]+/g, "([^/]+)"), S = new RegExp(`^${C}$`), T = e.match(S);
|
|
645
|
+
if (T && g.length > 0) {
|
|
646
|
+
const b = {};
|
|
647
|
+
return g.forEach(($, P) => {
|
|
648
|
+
b[$] = T[P + 1];
|
|
620
649
|
}), {
|
|
621
650
|
route: t,
|
|
622
|
-
params:
|
|
651
|
+
params: b,
|
|
623
652
|
exact: !0
|
|
624
653
|
};
|
|
625
654
|
}
|
|
@@ -738,8 +767,8 @@ class qt {
|
|
|
738
767
|
}
|
|
739
768
|
}
|
|
740
769
|
export {
|
|
741
|
-
|
|
742
|
-
|
|
770
|
+
Kt as RouterUtils,
|
|
771
|
+
bt as WsxLink,
|
|
743
772
|
At as WsxRouter,
|
|
744
|
-
|
|
773
|
+
dt as WsxView
|
|
745
774
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsxjs/wsx-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "WSX Router - Native History API-based routing for WSX Framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"!**/test"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@wsxjs/wsx-core": "0.0.
|
|
21
|
+
"@wsxjs/wsx-core": "0.0.16"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"typescript": "^5.0.0",
|
|
31
31
|
"vite": "^5.4.19",
|
|
32
32
|
"vitest": "^2.1.8",
|
|
33
|
-
"@wsxjs/
|
|
34
|
-
"@wsxjs/
|
|
33
|
+
"@wsxjs/eslint-plugin-wsx": "0.0.16",
|
|
34
|
+
"@wsxjs/wsx-vite-plugin": "0.0.16"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"wsx",
|
package/src/WsxLink.wsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @wsxjs/wsx-core */
|
|
2
|
-
import { WebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
|
|
2
|
+
import { WebComponent, autoRegister, createLogger, state } from "@wsxjs/wsx-core";
|
|
3
3
|
|
|
4
4
|
const logger = createLogger("WsxLink");
|
|
5
5
|
|
|
@@ -23,10 +23,10 @@ const logger = createLogger("WsxLink");
|
|
|
23
23
|
export default class WsxLink extends WebComponent {
|
|
24
24
|
static observedAttributes = ["to", "replace", "active-class", "exact"];
|
|
25
25
|
|
|
26
|
-
private to: string = "";
|
|
27
|
-
private replace: boolean = false;
|
|
28
|
-
private activeClass: string = "active";
|
|
29
|
-
private exact: boolean = false;
|
|
26
|
+
@state private to: string = "";
|
|
27
|
+
@state private replace: boolean = false;
|
|
28
|
+
@state private activeClass: string = "active";
|
|
29
|
+
@state private exact: boolean = false;
|
|
30
30
|
|
|
31
31
|
render() {
|
|
32
32
|
return (
|
|
@@ -66,7 +66,6 @@ export default class WsxLink extends WebComponent {
|
|
|
66
66
|
switch (name) {
|
|
67
67
|
case "to":
|
|
68
68
|
this.to = newValue || "";
|
|
69
|
-
this.rerender(); // Re-render to update href in JSX
|
|
70
69
|
this.updateActiveState();
|
|
71
70
|
break;
|
|
72
71
|
case "replace":
|