@wsxjs/wsx-router 0.0.7 → 0.0.8

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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@wsxjs/wsx-core"),G=":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";var K=Object.create,$=Object.defineProperty,X=Object.getOwnPropertyDescriptor,P=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),W=e=>{throw TypeError(e)},I=(e,t,r)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Y=(e,t)=>$(e,"name",{value:t,configurable:!0}),Z=e=>[,,,K((e==null?void 0:e[P("metadata")])??null)],tt=["class","method","getter","setter","accessor","field","value","get","set"],O=e=>e!==void 0&&typeof e!="function"?W("Function expected"):e,et=(e,t,r,i,o)=>({kind:tt[e],name:t,metadata:i,addInitializer:n=>r._?W("Already initialized"):o.push(O(n||null))}),rt=(e,t)=>I(t,P("metadata"),e[3]),it=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},ot=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&X(o,r));Y(o,r);for(var p=i.length-1;p>=0;p--)c=et(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,O(s)&&(o=s);return rt(e,o),u&&$(o,r,u),d?a^4?n:u:o},b=(e,t,r)=>I(e,typeof t!="symbol"?t+"":t,r),j,E,N;const m=h.createLogger("WsxRouter");j=[h.autoRegister({tagName:"wsx-router"})];class y extends(N=h.LightComponent){constructor(){super({styles:G,styleName:"wsx-router"}),b(this,"views",new Map),b(this,"currentView",null),b(this,"handleRouteChange",()=>{const t=window.location.pathname;m.debug(`Route changed to: ${t}`),this.currentView&&(this.currentView.style.display="none",m.debug("Hiding previous view"));const r=this.matchRoute(t);if(r){r.style.display="block",this.currentView=r,m.debug(`Showing view for route: ${r.getAttribute("route")}`);const i=this.extractParams(r.getAttribute("route")||"/",t);i&&r.setAttribute("params",JSON.stringify(i))}else m.warn(`No view found for path: ${t}`);this.dispatchEvent(new CustomEvent("route-changed",{detail:{path:t,view:r},bubbles:!0,composed:!0}))}),b(this,"interceptLinks",t=>{const r=t.target.closest("a");if(!r)return;const i=r.getAttribute("href");!i||i.startsWith("http")||i.startsWith("#")||(t.preventDefault(),this.navigate(i))})}render(){return h.jsx("div",{class:"router-outlet"})}onConnected(){m.debug("WsxRouter connected to DOM"),this.collectViews(),m.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(r=>r.tagName.toLowerCase()==="wsx-view");m.debug("WsxRouter found views:",t.length),t.forEach(r=>{const i=r.getAttribute("route")||"/";this.views.set(i,r),r.style.display="none",m.debug(`WsxRouter hiding view for route: ${i}`)})}matchRoute(t){if(this.views.has(t))return this.views.get(t);for(const[r,i]of this.views)if(r.includes(":")){const o=r.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${o}$`).test(t))return i}return this.views.get("*")||null}extractParams(t,r){var c;if(!t.includes(":"))return null;const i=((c=t.match(/:([^/]+)/g))==null?void 0:c.map(a=>a.slice(1)))||[],o=t.replace(/:[^/]+/g,"([^/]+)"),n=new RegExp(`^${o}$`),s=r.match(n);if(!s||!i.length)return null;const l={};return i.forEach((a,d)=>{l[a]=s[d+1]}),l}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}E=Z(N);y=ot(E,0,"WsxRouter",j,y);it(E,1,y);const nt=":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 at=Object.create,S=Object.defineProperty,st=Object.getOwnPropertyDescriptor,z=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),D=e=>{throw TypeError(e)},F=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ct=(e,t)=>S(e,"name",{value:t,configurable:!0}),lt=e=>[,,,at((e==null?void 0:e[z("metadata")])??null)],ht=["class","method","getter","setter","accessor","field","value","get","set"],U=e=>e!==void 0&&typeof e!="function"?D("Function expected"):e,dt=(e,t,r,i,o)=>({kind:ht[e],name:t,metadata:i,addInitializer:n=>r._?D("Already initialized"):o.push(U(n||null))}),ut=(e,t)=>F(t,z("metadata"),e[3]),pt=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},vt=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&st(o,r));ct(o,r);for(var p=i.length-1;p>=0;p--)c=dt(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,U(s)&&(o=s);return ut(e,o),u&&S(o,r,u),d?a^4?n:u:o},x=(e,t,r)=>F(e,typeof t!="symbol"?t+"":t,r),M,R,V;const k=h.createLogger("WsxView");M=[h.autoRegister({tagName:"wsx-view"})];class g extends(V=h.LightComponent){constructor(){super({styles:nt,styleName:"wsx-view"}),x(this,"component",null),x(this,"params",{}),x(this,"componentInstance",null)}render(){return h.jsx("div",{class:"route-view"})}onConnected(){const t=this.getAttribute("component");t&&!this.componentInstance&&this.loadComponent(t)}onAttributeChanged(t,r,i){if(t==="component"&&i&&!this.componentInstance)this.loadComponent(i);else if(t==="params"&&this.componentInstance)try{this.params=JSON.parse(i),Object.entries(this.params).forEach(([o,n])=>{this.componentInstance.setAttribute(o,n)})}catch(o){k.error("Failed to parse params:",o)}}async loadComponent(t){if(this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null),!customElements.get(t)){k.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(([o,n])=>{this.componentInstance.setAttribute(o,n)});const i=this.querySelector(".route-view");i?i.appendChild(this.componentInstance):k.error("Route view container not found")}onDisconnected(){this.componentInstance&&(this.componentInstance.remove(),this.componentInstance=null)}}R=lt(V);g=vt(R,0,"WsxView",M,g);x(g,"observedAttributes",["route","component","params"]);pt(R,1,g);const mt=':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 wt=Object.create,C=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,q=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),T=e=>{throw TypeError(e)},Q=(e,t,r)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,gt=(e,t)=>C(e,"name",{value:t,configurable:!0}),_t=e=>[,,,wt((e==null?void 0:e[q("metadata")])??null)],bt=["class","method","getter","setter","accessor","field","value","get","set"],H=e=>e!==void 0&&typeof e!="function"?T("Function expected"):e,xt=(e,t,r,i,o)=>({kind:bt[e],name:t,metadata:i,addInitializer:n=>r._?T("Already initialized"):o.push(H(n||null))}),yt=(e,t)=>Q(t,q("metadata"),e[3]),kt=(e,t,r,i)=>{for(var o=0,n=e[t>>1],s=n&&n.length;o<s;o++)n[o].call(r);return i},$t=(e,t,r,i,o,n)=>{var s,l,c,a=t&7,d=!1,v=0,f=e[v]||(e[v]=[]),u=a&&(o=o.prototype,a<5&&(a>3||!d)&&ft(o,r));gt(o,r);for(var p=i.length-1;p>=0;p--)c=xt(a,r,l={},e[3],f),s=(0,i[p])(o,c),l._=1,H(s)&&(o=s);return yt(e,o),u&&C(o,r,u),d?a^4?n:u:o},w=(e,t,r)=>Q(e,typeof t!="symbol"?t+"":t,r),J,L,B;const A=h.createLogger("WsxLink");J=[h.autoRegister({tagName:"wsx-link"})];class _ extends(B=h.WebComponent){constructor(){super({styles:mt,styleName:"wsx-link"}),w(this,"to",""),w(this,"replace",!1),w(this,"activeClass","active"),w(this,"exact",!1),w(this,"handleClick",t=>{if(t.preventDefault(),!this.to){A.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")),A.debug(`Navigated to: ${this.to}`)}),w(this,"updateActiveState",()=>{var o;const t=window.location.pathname,r=this.exact?t===this.to:t.startsWith(this.to)&&this.to!=="/",i=(o=this.shadowRoot)==null?void 0:o.querySelector("a");i&&(r?(i.classList.add(this.activeClass),this.setAttribute("active","")):(i.classList.remove(this.activeClass),this.removeAttribute("active")))})}render(){return h.jsx("a",{href:this.to,class:"wsx-link",onClick:this.handleClick,part:"link"},h.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,r,i){switch(t){case"to":this.to=i||"",this.rerender(),this.updateActiveState();break;case"replace":this.replace=i!==null&&i!=="false";break;case"active-class":this.activeClass=i||"active",this.updateActiveState();break;case"exact":this.exact=i!==null&&i!=="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}))}}L=_t(B);_=$t(L,0,"WsxLink",J,_);w(_,"observedAttributes",["to","replace","active-class","exact"]);kt(L,1,_);const Et=h.createLogger("RouterUtils");class St{static navigate(t,r=!1){r?window.history.replaceState(null,"",t):window.history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate")),Et.debug(`Navigated to: ${t} (replace: ${r})`)}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,r){var i;if(t===r)return{route:t,params:{},exact:!0};if(t==="*")return{route:t,params:{},exact:!1};if(t.includes(":")){const o=((i=t.match(/:([^/]+)/g))==null?void 0:i.map(c=>c.slice(1)))||[],n=t.replace(/:[^/]+/g,"([^/]+)"),s=new RegExp(`^${n}$`),l=r.match(s);if(l&&o.length>0){const c={};return o.forEach((a,d)=>{c[a]=l[d+1]}),{route:t,params:c,exact:!0}}}if(t.endsWith("/*")){const o=t.slice(0,-2);if(r.startsWith(o))return{route:t,params:{},exact:!1}}return null}static buildPath(t,r={}){let i=t;return Object.entries(r).forEach(([o,n])=>{i=i.replace(`:${o}`,encodeURIComponent(n))}),i}static isRouteActive(t,r=!1){const i=window.location.pathname;return r?i===t:t==="/"?i==="/":i.startsWith(t)}static getRouteDepth(t){return t.split("/").filter(r=>r.length>0).length}static getParentRoute(t){const r=t.split("/").filter(i=>i.length>0);return r.length<=1?"/":(r.pop(),"/"+r.join("/"))}static joinPaths(...t){return t.map(r=>r.replace(/^\/+|\/+$/g,"")).filter(r=>r.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,r,i=!1){const o=new URL(window.location.href);o.searchParams.set(t,r);const n=o.pathname+o.search+o.hash;this.navigate(n,i)}static removeQueryParam(t,r=!1){const i=new URL(window.location.href);i.searchParams.delete(t);const o=i.pathname+i.search+i.hash;this.navigate(o,r)}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 r=()=>{const i=this.getCurrentRoute();t(i)};return window.addEventListener("popstate",r),document.addEventListener("route-changed",r),()=>{window.removeEventListener("popstate",r),document.removeEventListener("route-changed",r)}}}exports.RouterUtils=St;exports.WsxLink=_;exports.WsxRouter=y;exports.WsxView=g;
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,vt;function Y(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 xt(r,t,e,n,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(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 T(i,c,u,s,a,$,L,j,N,y,m,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],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:it(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||it(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),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,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(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 U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return Et(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!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)}T(k?i:i.prototype,f,x,h?"#"+w:mt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function mt(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=I.createLogger("WsxRouter");vt=[I.autoRegister({tagName:"wsx-router"})];exports.WsxRouter=void 0;class St extends I.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 I.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 g=e.replace(/:[^/]+/g,"([^/]+)");if(new RegExp(`^${g}$`).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(T=>T.slice(1)))||[],g=t.replace(/:[^/]+/g,"([^/]+)"),R=new RegExp(`^${g}$`),C=e.match(R);if(!C||!n.length)return null;const O={};return n.forEach((T,U)=>{O[T]=C[U+1]}),O}navigate(t){window.history.pushState(null,"",t),this.handleRouteChange()}}ft=St;[exports.WsxRouter,pt]=xt(ft,[],vt,0,void 0,I.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,gt,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,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(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 T(i,c,u,s,a,$,L,j,N,y,m,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],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:ct(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||ct(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),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,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(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 U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return jt(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!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)}T(k?i:i.prototype,f,x,h?"#"+w:bt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.bind(null,i,r)]}}}function bt(r){var t=Rt(r,"string");return typeof t=="symbol"?t:t+""}function Rt(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 _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:ot,styleName:"wsx-view"}),G(this,"_autoStyles",ot),G(this,"component",null),G(this,"params",{}),G(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(([g,R])=>{this.componentInstance.setAttribute(g,R)})}catch(g){tt.error("Failed to parse params:",g)}}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(([g,R])=>{this.componentInstance.setAttribute(g,R)});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,[],gt,0,void 0,I.LightComponent).c,F),Z=class extends _t{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 M(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,g,R){function C(i,c,u){return function(s,a){return u&&u(s),i[c].call(s,a)}}function O(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 T(i,c,u,s,a,$,L,j,N,y,m,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],_=!j;if(!_){u||Array.isArray(x)||(x=[x]);var o={},E=[],v=a===3?"get":a===4||f?"set":"value";y?(m||f?o={get:ht(function(){return k(this)},s,"get"),set:function(l){c[4](this,l)}}:o[v]=k,m||ht(o[v],s,a===2?"":v)):m||(o=Object.getOwnPropertyDescriptor(i,s))}for(var d=i,P=x.length-1;P>=0;P-=u?2:1){var H=x[P],K=u?x[P-1]:void 0,Q={},W={kind:["field","accessor","method","getter","setter","class"][a],name:s,metadata:$,addInitializer:(function(l,S){if(l.v)throw Error("attempted to call addInitializer after decoration was finished");b(S,"An initializer","be",!0),L.push(S)}).bind(null,Q)};try{if(_)(h=b(H.call(K,d,W),"class decorators","return"))&&(d=h);else{var A,z;W.static=N,W.private=y,y?a===2?A=function(l){return w(l),o.value}:(a<4&&(A=C(o,"get",w)),a!==3&&(z=C(o,"set",w))):(A=function(l){return l[s]},(a<2||a===4)&&(z=function(l,S){l[s]=S}));var J=W.access={has:y?p.bind():function(l){return s in l}};if(A&&(J.get=A),z&&(J.set=z),d=H.call(K,f?{get:o.get,set:o.set}:o[v],W),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,(m?"field":"method")+" decorators","return")&&(m?E.push(d):o[v]=d)}}finally{Q.v=!0}}return(m||f)&&j.push(function(l,S){for(var V=E.length-1;V>=0;V--)S=E[V].call(l,S);return S}),m||_||(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 U(i,c){return Object.defineProperty(i,Symbol.metadata||Symbol.for("Symbol.metadata"),{configurable:!0,enumerable:!0,value:c})}if(arguments.length>=6)var q=R[Symbol.metadata||Symbol.for("Symbol.metadata")];var D=Object.create(q??null),X=function(i,c,u,s){var a,$,L=[],j=function(v){return At(v)===i},N=new Map;function y(v){v&&L.push(O.bind(null,v))}for(var m=0;m<c.length;m++){var f=c[m];if(Array.isArray(f)){var p=f[1],w=f[2],h=f.length>3,x=16&p,k=!!(8&p),_=(p&=7)==0,o=w+"/"+k;if(!_&&!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)}T(k?i:i.prototype,f,x,h?"#"+w:wt(w),p,s,k?$=$||[]:a=a||[],L,k,h,_,p===1,k&&h?j:u)}}return y(a),y($),L}(r,t,g,D);return e.length||U(r,D),{e:X,get c(){var i=[];return e.length&&[U(T(r,[e],n,r.name,5,D,i),D),O.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 It(r){return r}const dt=I.createLogger("WsxLink");yt=[I.autoRegister({tagName:"wsx-link"})];exports.WsxLink=void 0;new(ut=(rt=class extends I.WebComponent{constructor(...t){super(...t),M(this,"_autoStyles",$t),M(this,"to",""),M(this,"replace",!1),M(this,"activeClass","active"),M(this,"exact",!1),M(this,"handleClick",e=>{if(e.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}`)}),M(this,"updateActiveState",()=>{var R;const e=window.location.pathname,n=this.exact?e===this.to:e.startsWith(this.to)&&this.to!=="/",g=(R=this.shadowRoot)==null?void 0:R.querySelector("a");g&&(n?(g.classList.add(this.activeClass),this.setAttribute("active","")):(g.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,lt]=Lt(rt,[],yt,0,void 0,I.WebComponent).c,rt),et=class extends It{constructor(){super(exports.WsxLink),M(this,"observedAttributes",["to","replace","active-class","exact"]),lt()}},M(et,ut,void 0),et);const Ot=I.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")),Ot.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 g=((n=t.match(/:([^/]+)/g))==null?void 0:n.map(b=>b.slice(1)))||[],R=t.replace(/:[^/]+/g,"([^/]+)"),C=new RegExp(`^${R}$`),O=e.match(C);if(O&&g.length>0){const b={};return g.forEach((T,U)=>{b[T]=O[U+1]}),{route:t,params:b,exact:!0}}}if(t.endsWith("/*")){const g=t.slice(0,-2);if(e.startsWith(g))return{route:t,params:{},exact:!1}}return null}static buildPath(t,e={}){let n=t;return Object.entries(e).forEach(([g,R])=>{n=n.replace(`:${g}`,encodeURIComponent(R))}),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 g=new URL(window.location.href);g.searchParams.set(t,e);const R=g.pathname+g.search+g.hash;this.navigate(R,n)}static removeQueryParam(t,e=!1){const n=new URL(window.location.href);n.searchParams.delete(t);const g=n.pathname+n.search+n.hash;this.navigate(g,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,86 +1,198 @@
1
- import { createLogger as y, autoRegister as E, LightComponent as I, jsx as _, WebComponent as Y } from "@wsxjs/wsx-core";
2
- const Z = ":host{display:block;width:100%;height:100%}.router-outlet{width:100%;height:100%}";
3
- var tt = Object.create, S = Object.defineProperty, et = Object.getOwnPropertyDescriptor, O = (e, t) => (t = Symbol[e]) ? t : Symbol.for("Symbol." + e), N = (e) => {
4
- throw TypeError(e);
5
- }, j = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, rt = (e, t) => S(e, "name", { value: t, configurable: !0 }), it = (e) => [, , , tt((e == null ? void 0 : e[O("metadata")]) ?? null)], ot = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], z = (e) => e !== void 0 && typeof e != "function" ? N("Function expected") : e, nt = (e, t, r, i, o) => ({ kind: ot[e], name: t, metadata: i, addInitializer: (n) => r._ ? N("Already initialized") : o.push(z(n || null)) }), at = (e, t) => j(t, O("metadata"), e[3]), st = (e, t, r, i) => {
6
- for (var o = 0, n = e[t >> 1], s = n && n.length; o < s; o++) n[o].call(r);
7
- return i;
8
- }, ct = (e, t, r, i, o, n) => {
9
- var s, l, c, a = t & 7, h = !1, p = 0, w = e[p] || (e[p] = []), d = a && (o = o.prototype, a < 5 && (a > 3 || !h) && et(o, r));
10
- rt(o, r);
11
- for (var u = i.length - 1; u >= 0; u--)
12
- c = nt(a, r, l = {}, e[3], w), s = (0, i[u])(o, c), l._ = 1, z(s) && (o = s);
13
- return at(e, o), d && S(o, r, d), h ? a ^ 4 ? n : d : o;
14
- }, f = (e, t, r) => j(e, typeof t != "symbol" ? t + "" : t, r), D, C, F;
15
- const v = y("WsxRouter");
16
- D = [E({ tagName: "wsx-router" })];
17
- class $ extends (F = I) {
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
+ var yt;
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
+ }
8
+ function Ct(r, t, e, n, g, R) {
9
+ function _(i, c, u) {
10
+ return function(s, a) {
11
+ return u && u(s), i[c].call(s, a);
12
+ };
13
+ }
14
+ function I(i, c) {
15
+ for (var u = 0; u < i.length; u++) i[u].call(c);
16
+ return c;
17
+ }
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
+ return i;
21
+ }
22
+ function O(i, c, u, s, a, j, A, C, 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
+ }
26
+ var h, x = c[0], k = c[3], $ = !C;
27
+ if (!$) {
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
+ }
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 = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
38
+ if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
39
+ b(S, "An initializer", "be", !0), A.push(S);
40
+ }).bind(null, K) };
41
+ try {
42
+ if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
43
+ else {
44
+ var L, P;
45
+ W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
46
+ return w(l), o.value;
47
+ } : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
48
+ return l[s];
49
+ }, (a < 2 || a === 4) && (P = function(l, S) {
50
+ l[s] = S;
51
+ }));
52
+ var Q = W.access = { has: y ? p.bind() : function(l) {
53
+ return s in l;
54
+ } };
55
+ if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), 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
+ 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 b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
59
+ }
60
+ } finally {
61
+ K.v = !0;
62
+ }
63
+ }
64
+ return (m || d) && C.push(function(l, S) {
65
+ for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
66
+ return S;
67
+ }), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
68
+ }
69
+ function z(i, c) {
70
+ return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
71
+ }
72
+ if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
73
+ var T = Object.create(M ?? null), G = function(i, c, u, s) {
74
+ var a, j, A = [], C = function(v) {
75
+ return jt(v) === i;
76
+ }, D = /* @__PURE__ */ new Map();
77
+ function y(v) {
78
+ v && A.push(I.bind(null, v));
79
+ }
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), $ = (p &= 7) == 0, o = w + "/" + k;
84
+ if (!$ && !h) {
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
+ }
89
+ O(k ? i : i.prototype, d, x, h ? "#" + w : kt(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
90
+ }
91
+ }
92
+ return y(a), y(j), A;
93
+ }(r, t, g, T);
94
+ return e.length || z(r, T), { e: G, get c() {
95
+ var i = [];
96
+ return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
97
+ } };
98
+ }
99
+ function kt(r) {
100
+ var t = $t(r, "string");
101
+ return typeof t == "symbol" ? t : t + "";
102
+ }
103
+ function $t(r, t) {
104
+ if (typeof r != "object" || !r) return r;
105
+ var e = r[Symbol.toPrimitive];
106
+ if (e !== void 0) {
107
+ var n = e.call(r, t);
108
+ if (typeof n != "object") return n;
109
+ throw new TypeError("@@toPrimitive must return a primitive value.");
110
+ }
111
+ return String(r);
112
+ }
113
+ function ct(r, t, e) {
114
+ typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
115
+ try {
116
+ Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
117
+ } catch {
118
+ }
119
+ return r;
120
+ }
121
+ function jt(r) {
122
+ if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
123
+ return r;
124
+ }
125
+ const J = F("WsxRouter");
126
+ xt = [ot({
127
+ tagName: "wsx-router"
128
+ })];
129
+ let At;
130
+ class Wt extends Y {
18
131
  constructor() {
19
132
  super({
20
- styles: Z,
133
+ styles: at,
21
134
  styleName: "wsx-router"
22
- }), f(this, "views", /* @__PURE__ */ new Map()), f(this, "currentView", null), f(this, "handleRouteChange", () => {
135
+ }), X(this, "_autoStyles", at), X(this, "views", /* @__PURE__ */ new Map()), X(this, "currentView", null), X(this, "handleRouteChange", () => {
23
136
  const t = window.location.pathname;
24
- v.debug(`Route changed to: ${t}`), this.currentView && (this.currentView.style.display = "none", v.debug("Hiding previous view"));
25
- const r = this.matchRoute(t);
26
- if (r) {
27
- r.style.display = "block", this.currentView = r, v.debug(`Showing view for route: ${r.getAttribute("route")}`);
28
- const i = this.extractParams(r.getAttribute("route") || "/", t);
29
- i && r.setAttribute("params", JSON.stringify(i));
137
+ J.debug(`Route changed to: ${t}`), this.currentView && (this.currentView.style.display = "none", J.debug("Hiding previous view"));
138
+ const e = this.matchRoute(t);
139
+ if (e) {
140
+ e.style.display = "block", this.currentView = e, J.debug(`Showing view for route: ${e.getAttribute("route")}`);
141
+ const n = this.extractParams(e.getAttribute("route") || "/", t);
142
+ n && e.setAttribute("params", JSON.stringify(n));
30
143
  } else
31
- v.warn(`No view found for path: ${t}`);
32
- this.dispatchEvent(
33
- new CustomEvent("route-changed", {
34
- detail: { path: t, view: r },
35
- bubbles: !0,
36
- composed: !0
37
- })
38
- );
39
- }), f(this, "interceptLinks", (t) => {
40
- const r = t.target.closest("a");
41
- if (!r) return;
42
- const i = r.getAttribute("href");
43
- !i || i.startsWith("http") || i.startsWith("#") || (t.preventDefault(), this.navigate(i));
144
+ J.warn(`No view found for path: ${t}`);
145
+ this.dispatchEvent(new CustomEvent("route-changed", {
146
+ detail: {
147
+ path: t,
148
+ view: e
149
+ },
150
+ bubbles: !0,
151
+ composed: !0
152
+ }));
153
+ }), X(this, "interceptLinks", (t) => {
154
+ const e = t.target.closest("a");
155
+ if (!e) return;
156
+ const n = e.getAttribute("href");
157
+ !n || n.startsWith("http") || n.startsWith("#") || (t.preventDefault(), this.navigate(n));
44
158
  });
45
159
  }
46
160
  render() {
47
- return /* @__PURE__ */ _("div", { class: "router-outlet" });
161
+ return /* @__PURE__ */ Z("div", { class: "router-outlet" });
48
162
  }
49
163
  onConnected() {
50
- v.debug("WsxRouter connected to DOM"), this.collectViews(), v.debug("WsxRouter collected views:", this.views.size), window.addEventListener("popstate", this.handleRouteChange), this.addEventListener("click", this.interceptLinks), this.handleRouteChange();
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();
51
165
  }
52
166
  onDisconnected() {
53
167
  window.removeEventListener("popstate", this.handleRouteChange);
54
168
  }
55
169
  collectViews() {
56
- const t = Array.from(this.children).filter(
57
- (r) => r.tagName.toLowerCase() === "wsx-view"
58
- );
59
- v.debug("WsxRouter found views:", t.length), t.forEach((r) => {
60
- const i = r.getAttribute("route") || "/";
61
- this.views.set(i, r), r.style.display = "none", v.debug(`WsxRouter hiding view for route: ${i}`);
170
+ const t = Array.from(this.children).filter((e) => e.tagName.toLowerCase() === "wsx-view");
171
+ J.debug("WsxRouter found views:", t.length), t.forEach((e) => {
172
+ const n = e.getAttribute("route") || "/";
173
+ this.views.set(n, e), e.style.display = "none", J.debug(`WsxRouter hiding view for route: ${n}`);
62
174
  });
63
175
  }
64
176
  matchRoute(t) {
65
177
  if (this.views.has(t))
66
178
  return this.views.get(t);
67
- for (const [r, i] of this.views)
68
- if (r.includes(":")) {
69
- const o = r.replace(/:[^/]+/g, "([^/]+)");
70
- if (new RegExp(`^${o}$`).test(t))
71
- return i;
179
+ for (const [e, n] of this.views)
180
+ if (e.includes(":")) {
181
+ const g = e.replace(/:[^/]+/g, "([^/]+)");
182
+ if (new RegExp(`^${g}$`).test(t))
183
+ return n;
72
184
  }
73
185
  return this.views.get("*") || null;
74
186
  }
75
- extractParams(t, r) {
76
- var c;
187
+ extractParams(t, e) {
188
+ var b;
77
189
  if (!t.includes(":")) return null;
78
- const i = ((c = t.match(/:([^/]+)/g)) == null ? void 0 : c.map((a) => a.slice(1))) || [], o = t.replace(/:[^/]+/g, "([^/]+)"), n = new RegExp(`^${o}$`), s = r.match(n);
79
- if (!s || !i.length) return null;
80
- const l = {};
81
- return i.forEach((a, h) => {
82
- l[a] = s[h + 1];
83
- }), l;
190
+ const n = ((b = t.match(/:([^/]+)/g)) == null ? void 0 : b.map((O) => O.slice(1))) || [], g = t.replace(/:[^/]+/g, "([^/]+)"), R = new RegExp(`^${g}$`), _ = e.match(R);
191
+ if (!_ || !n.length) return null;
192
+ const I = {};
193
+ return n.forEach((O, z) => {
194
+ I[O] = _[z + 1];
195
+ }), I;
84
196
  }
85
197
  /**
86
198
  * 编程式导航 - 使用原生 History API
@@ -89,107 +201,336 @@ class $ extends (F = I) {
89
201
  window.history.pushState(null, "", t), this.handleRouteChange();
90
202
  }
91
203
  }
92
- C = it(F);
93
- $ = ct(C, 0, "WsxRouter", D, $);
94
- st(C, 1, $);
204
+ yt = Wt;
205
+ [At, wt] = Ct(yt, [], xt, 0, void 0, Y).c;
206
+ wt();
95
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}}";
96
- var ht = Object.create, R = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, U = (e, t) => (t = Symbol[e]) ? t : Symbol.for("Symbol." + e), M = (e) => {
97
- throw TypeError(e);
98
- }, V = (e, t, r) => t in e ? R(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, ut = (e, t) => R(e, "name", { value: t, configurable: !0 }), pt = (e) => [, , , ht((e == null ? void 0 : e[U("metadata")]) ?? null)], vt = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], q = (e) => e !== void 0 && typeof e != "function" ? M("Function expected") : e, mt = (e, t, r, i, o) => ({ kind: vt[e], name: t, metadata: i, addInitializer: (n) => r._ ? M("Already initialized") : o.push(q(n || null)) }), wt = (e, t) => V(t, U("metadata"), e[3]), ft = (e, t, r, i) => {
99
- for (var o = 0, n = e[t >> 1], s = n && n.length; o < s; o++) n[o].call(r);
100
- return i;
101
- }, gt = (e, t, r, i, o, n) => {
102
- var s, l, c, a = t & 7, h = !1, p = 0, w = e[p] || (e[p] = []), d = a && (o = o.prototype, a < 5 && (a > 3 || !h) && dt(o, r));
103
- ut(o, r);
104
- for (var u = i.length - 1; u >= 0; u--)
105
- c = mt(a, r, l = {}, e[3], w), s = (0, i[u])(o, c), l._ = 1, q(s) && (o = s);
106
- return wt(e, o), d && R(o, r, d), h ? a ^ 4 ? n : d : o;
107
- }, g = (e, t, r) => V(e, typeof t != "symbol" ? t + "" : t, r), Q, A, T;
108
- const k = y("WsxView");
109
- Q = [E({ tagName: "wsx-view" })];
110
- class b extends (T = I) {
208
+ var tt, et;
209
+ let ut, Et, ht;
210
+ function B(r, t, e) {
211
+ return (t = St(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
212
+ }
213
+ function Lt(r, t, e, n, g, R) {
214
+ function _(i, c, u) {
215
+ return function(s, a) {
216
+ return u && u(s), i[c].call(s, a);
217
+ };
218
+ }
219
+ function I(i, c) {
220
+ for (var u = 0; u < i.length; u++) i[u].call(c);
221
+ return c;
222
+ }
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
+ return i;
226
+ }
227
+ function O(i, c, u, s, a, j, A, C, 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
+ }
231
+ var h, x = c[0], k = c[3], $ = !C;
232
+ if (!$) {
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
+ }
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 = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
243
+ if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
244
+ b(S, "An initializer", "be", !0), A.push(S);
245
+ }).bind(null, K) };
246
+ try {
247
+ if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
248
+ else {
249
+ var L, P;
250
+ W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
251
+ return w(l), o.value;
252
+ } : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
253
+ return l[s];
254
+ }, (a < 2 || a === 4) && (P = function(l, S) {
255
+ l[s] = S;
256
+ }));
257
+ var Q = W.access = { has: y ? p.bind() : function(l) {
258
+ return s in l;
259
+ } };
260
+ if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), 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
+ 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 b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
264
+ }
265
+ } finally {
266
+ K.v = !0;
267
+ }
268
+ }
269
+ return (m || d) && C.push(function(l, S) {
270
+ for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
271
+ return S;
272
+ }), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
273
+ }
274
+ function z(i, c) {
275
+ return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
276
+ }
277
+ if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
278
+ var T = Object.create(M ?? null), G = function(i, c, u, s) {
279
+ var a, j, A = [], C = function(v) {
280
+ return Ot(v) === i;
281
+ }, D = /* @__PURE__ */ new Map();
282
+ function y(v) {
283
+ v && A.push(I.bind(null, v));
284
+ }
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), $ = (p &= 7) == 0, o = w + "/" + k;
289
+ if (!$ && !h) {
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
+ }
294
+ O(k ? i : i.prototype, d, x, h ? "#" + w : St(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
295
+ }
296
+ }
297
+ return y(a), y(j), A;
298
+ }(r, t, g, T);
299
+ return e.length || z(r, T), { e: G, get c() {
300
+ var i = [];
301
+ return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
302
+ } };
303
+ }
304
+ function St(r) {
305
+ var t = It(r, "string");
306
+ return typeof t == "symbol" ? t : t + "";
307
+ }
308
+ function It(r, t) {
309
+ if (typeof r != "object" || !r) return r;
310
+ var e = r[Symbol.toPrimitive];
311
+ if (e !== void 0) {
312
+ var n = e.call(r, t);
313
+ if (typeof n != "object") return n;
314
+ throw new TypeError("@@toPrimitive must return a primitive value.");
315
+ }
316
+ return (t === "string" ? String : Number)(r);
317
+ }
318
+ function ft(r, t, e) {
319
+ typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
320
+ try {
321
+ Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
322
+ } catch {
323
+ }
324
+ return r;
325
+ }
326
+ function Ot(r) {
327
+ if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
328
+ return r;
329
+ }
330
+ function Tt(r) {
331
+ return r;
332
+ }
333
+ const rt = F("WsxView");
334
+ Et = [ot({
335
+ tagName: "wsx-view"
336
+ })];
337
+ let dt;
338
+ new (ht = (et = class extends Y {
111
339
  constructor() {
112
340
  super({
113
341
  styles: lt,
114
342
  styleName: "wsx-view"
115
- }), g(this, "component", null), g(this, "params", {}), g(this, "componentInstance", null);
343
+ }), B(this, "_autoStyles", lt), B(this, "component", null), B(this, "params", {}), B(this, "componentInstance", null);
116
344
  }
117
345
  render() {
118
- return /* @__PURE__ */ _("div", { class: "route-view" });
346
+ return /* @__PURE__ */ Z("div", { class: "route-view" });
119
347
  }
120
348
  onConnected() {
121
349
  const t = this.getAttribute("component");
122
350
  t && !this.componentInstance && this.loadComponent(t);
123
351
  }
124
- onAttributeChanged(t, r, i) {
125
- if (t === "component" && i && !this.componentInstance)
126
- this.loadComponent(i);
352
+ onAttributeChanged(t, e, n) {
353
+ if (t === "component" && n && !this.componentInstance)
354
+ this.loadComponent(n);
127
355
  else if (t === "params" && this.componentInstance)
128
356
  try {
129
- this.params = JSON.parse(i), Object.entries(this.params).forEach(([o, n]) => {
130
- this.componentInstance.setAttribute(o, n);
357
+ this.params = JSON.parse(n), Object.entries(this.params).forEach(([g, R]) => {
358
+ this.componentInstance.setAttribute(g, R);
131
359
  });
132
- } catch (o) {
133
- k.error("Failed to parse params:", o);
360
+ } catch (g) {
361
+ rt.error("Failed to parse params:", g);
134
362
  }
135
363
  }
136
364
  async loadComponent(t) {
137
365
  if (this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null), !customElements.get(t)) {
138
- k.warn(`Component ${t} not found in customElements registry`);
366
+ rt.warn(`Component ${t} not found in customElements registry`);
139
367
  return;
140
368
  }
141
- this.componentInstance = document.createElement(t), Object.keys(this.params).length > 0 && Object.entries(this.params).forEach(([o, n]) => {
142
- this.componentInstance.setAttribute(o, n);
369
+ this.componentInstance = document.createElement(t), Object.keys(this.params).length > 0 && Object.entries(this.params).forEach(([g, R]) => {
370
+ this.componentInstance.setAttribute(g, R);
143
371
  });
144
- const i = this.querySelector(".route-view");
145
- i ? i.appendChild(this.componentInstance) : k.error("Route view container not found");
372
+ const n = this.querySelector(".route-view");
373
+ n ? n.appendChild(this.componentInstance) : rt.error("Route view container not found");
146
374
  }
147
375
  onDisconnected() {
148
376
  this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null);
149
377
  }
150
- }
151
- A = pt(T);
152
- b = gt(A, 0, "WsxView", Q, b);
153
- g(b, "observedAttributes", ["route", "component", "params"]);
154
- ft(A, 1, b);
155
- 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)}';
156
- var bt = Object.create, P = Object.defineProperty, xt = Object.getOwnPropertyDescriptor, H = (e, t) => (t = Symbol[e]) ? t : Symbol.for("Symbol." + e), J = (e) => {
157
- throw TypeError(e);
158
- }, B = (e, t, r) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, yt = (e, t) => P(e, "name", { value: t, configurable: !0 }), kt = (e) => [, , , bt((e == null ? void 0 : e[H("metadata")]) ?? null)], $t = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], G = (e) => e !== void 0 && typeof e != "function" ? J("Function expected") : e, Et = (e, t, r, i, o) => ({ kind: $t[e], name: t, metadata: i, addInitializer: (n) => r._ ? J("Already initialized") : o.push(G(n || null)) }), St = (e, t) => B(t, H("metadata"), e[3]), Ct = (e, t, r, i) => {
159
- for (var o = 0, n = e[t >> 1], s = n && n.length; o < s; o++) n[o].call(r);
160
- return i;
161
- }, Rt = (e, t, r, i, o, n) => {
162
- var s, l, c, a = t & 7, h = !1, p = 0, w = e[p] || (e[p] = []), d = a && (o = o.prototype, a < 5 && (a > 3 || !h) && xt(o, r));
163
- yt(o, r);
164
- for (var u = i.length - 1; u >= 0; u--)
165
- c = Et(a, r, l = {}, e[3], w), s = (0, i[u])(o, c), l._ = 1, G(s) && (o = s);
166
- return St(e, o), d && P(o, r, d), h ? a ^ 4 ? n : d : o;
167
- }, m = (e, t, r) => B(e, typeof t != "symbol" ? t + "" : t, r), K, L, X;
168
- const W = y("WsxLink");
169
- K = [E({ tagName: "wsx-link" })];
170
- class x extends (X = Y) {
378
+ }, [dt, ut] = Lt(et, [], Et, 0, void 0, Y).c, et), tt = class extends Tt {
171
379
  constructor() {
172
- super({
173
- styles: _t,
174
- styleName: "wsx-link"
175
- }), m(this, "to", ""), m(this, "replace", !1), m(this, "activeClass", "active"), m(this, "exact", !1), m(this, "handleClick", (t) => {
176
- if (t.preventDefault(), !this.to) {
177
- W.warn("No 'to' attribute specified");
380
+ super(dt), B(this, "observedAttributes", ["route", "component", "params"]), ut();
381
+ }
382
+ }, B(tt, ht, void 0), tt)();
383
+ const Dt = ':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)}';
384
+ var nt, it;
385
+ let pt, _t, vt;
386
+ function V(r, t, e) {
387
+ return (t = Rt(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
388
+ }
389
+ function Nt(r, t, e, n, g, R) {
390
+ function _(i, c, u) {
391
+ return function(s, a) {
392
+ return u && u(s), i[c].call(s, a);
393
+ };
394
+ }
395
+ function I(i, c) {
396
+ for (var u = 0; u < i.length; u++) i[u].call(c);
397
+ return c;
398
+ }
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"));
401
+ return i;
402
+ }
403
+ function O(i, c, u, s, a, j, A, C, D, y, m, d, p) {
404
+ function w(l) {
405
+ if (!p(l)) throw new TypeError("Attempted to access private element on non-instance");
406
+ }
407
+ var h, x = c[0], k = c[3], $ = !C;
408
+ if (!$) {
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));
416
+ }
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 = {}, W = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: j, addInitializer: (function(l, S) {
419
+ if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
420
+ b(S, "An initializer", "be", !0), A.push(S);
421
+ }).bind(null, K) };
422
+ try {
423
+ if ($) (h = b(H.call(q, f, W), "class decorators", "return")) && (f = h);
424
+ else {
425
+ var L, P;
426
+ W.static = D, W.private = y, y ? a === 2 ? L = function(l) {
427
+ return w(l), o.value;
428
+ } : (a < 4 && (L = _(o, "get", w)), a !== 3 && (P = _(o, "set", w))) : (L = function(l) {
429
+ return l[s];
430
+ }, (a < 2 || a === 4) && (P = function(l, S) {
431
+ l[s] = S;
432
+ }));
433
+ var Q = W.access = { has: y ? p.bind() : function(l) {
434
+ return s in l;
435
+ } };
436
+ if (L && (Q.get = L), P && (Q.set = P), f = H.call(q, d ? { get: o.get, set: o.set } : o[v], W), 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);
438
+ else if (f !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
439
+ } else b(f, (m ? "field" : "method") + " decorators", "return") && (m ? E.push(f) : o[v] = f);
440
+ }
441
+ } finally {
442
+ K.v = !0;
443
+ }
444
+ }
445
+ return (m || d) && C.push(function(l, S) {
446
+ for (var U = E.length - 1; U >= 0; U--) S = E[U].call(l, S);
447
+ return S;
448
+ }), m || $ || (y ? d ? C.push(_(o, "get"), _(o, "set")) : C.push(a === 2 ? o[v] : _.call.bind(o[v])) : Object.defineProperty(i, s, o)), f;
449
+ }
450
+ function z(i, c) {
451
+ return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
452
+ }
453
+ if (arguments.length >= 6) var M = R[Symbol.metadata || Symbol.for("Symbol.metadata")];
454
+ var T = Object.create(M ?? null), G = function(i, c, u, s) {
455
+ var a, j, A = [], C = function(v) {
456
+ return zt(v) === i;
457
+ }, D = /* @__PURE__ */ new Map();
458
+ function y(v) {
459
+ v && A.push(I.bind(null, v));
460
+ }
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), $ = (p &= 7) == 0, o = w + "/" + k;
465
+ if (!$ && !h) {
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);
469
+ }
470
+ O(k ? i : i.prototype, d, x, h ? "#" + w : Rt(w), p, s, k ? j = j || [] : a = a || [], A, k, h, $, p === 1, k && h ? C : u);
471
+ }
472
+ }
473
+ return y(a), y(j), A;
474
+ }(r, t, g, T);
475
+ return e.length || z(r, T), { e: G, get c() {
476
+ var i = [];
477
+ return e.length && [z(O(r, [e], n, r.name, 5, T, i), T), I.bind(null, i, r)];
478
+ } };
479
+ }
480
+ function Rt(r) {
481
+ var t = Pt(r, "string");
482
+ return typeof t == "symbol" ? t : t + "";
483
+ }
484
+ function Pt(r, t) {
485
+ if (typeof r != "object" || !r) return r;
486
+ var e = r[Symbol.toPrimitive];
487
+ if (e !== void 0) {
488
+ var n = e.call(r, t);
489
+ if (typeof n != "object") return n;
490
+ throw new TypeError("@@toPrimitive must return a primitive value.");
491
+ }
492
+ return (t === "string" ? String : Number)(r);
493
+ }
494
+ function mt(r, t, e) {
495
+ typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
496
+ try {
497
+ Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
498
+ } catch {
499
+ }
500
+ return r;
501
+ }
502
+ function zt(r) {
503
+ if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
504
+ return r;
505
+ }
506
+ function Ut(r) {
507
+ return r;
508
+ }
509
+ const gt = F("WsxLink");
510
+ _t = [ot({
511
+ tagName: "wsx-link"
512
+ })];
513
+ let bt;
514
+ new (vt = (it = class extends st {
515
+ constructor(...t) {
516
+ super(...t), V(this, "_autoStyles", Dt), V(this, "to", ""), V(this, "replace", !1), V(this, "activeClass", "active"), V(this, "exact", !1), V(this, "handleClick", (e) => {
517
+ if (e.preventDefault(), !this.to) {
518
+ gt.warn("No 'to' attribute specified");
178
519
  return;
179
520
  }
180
521
  if (this.isExternalLink(this.to)) {
181
522
  window.open(this.to, "_blank");
182
523
  return;
183
524
  }
184
- this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")), W.debug(`Navigated to: ${this.to}`);
185
- }), m(this, "updateActiveState", () => {
186
- var o;
187
- const t = window.location.pathname, r = this.exact ? t === this.to : t.startsWith(this.to) && this.to !== "/", i = (o = this.shadowRoot) == null ? void 0 : o.querySelector("a");
188
- i && (r ? (i.classList.add(this.activeClass), this.setAttribute("active", "")) : (i.classList.remove(this.activeClass), this.removeAttribute("active")));
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
+ }), V(this, "updateActiveState", () => {
527
+ var R;
528
+ const e = window.location.pathname, n = this.exact ? e === this.to : e.startsWith(this.to) && this.to !== "/", g = (R = this.shadowRoot) == null ? void 0 : R.querySelector("a");
529
+ g && (n ? (g.classList.add(this.activeClass), this.setAttribute("active", "")) : (g.classList.remove(this.activeClass), this.removeAttribute("active")));
189
530
  });
190
531
  }
191
532
  render() {
192
- return /* @__PURE__ */ _("a", { href: this.to, class: "wsx-link", onClick: this.handleClick, part: "link" }, /* @__PURE__ */ _("slot", null));
533
+ return /* @__PURE__ */ Z("a", { href: this.to, class: "wsx-link", onClick: this.handleClick, part: "link" }, /* @__PURE__ */ Z("slot", null));
193
534
  }
194
535
  onConnected() {
195
536
  this.to = this.getAttribute("to") || "", this.replace = this.hasAttribute("replace"), this.activeClass = this.getAttribute("active-class") || "active", this.exact = this.hasAttribute("exact");
@@ -199,19 +540,19 @@ class x extends (X = Y) {
199
540
  onDisconnected() {
200
541
  window.removeEventListener("popstate", this.updateActiveState), document.removeEventListener("route-changed", this.updateActiveState);
201
542
  }
202
- onAttributeChanged(t, r, i) {
543
+ onAttributeChanged(t, e, n) {
203
544
  switch (t) {
204
545
  case "to":
205
- this.to = i || "", this.rerender(), this.updateActiveState();
546
+ this.to = n || "", this.rerender(), this.updateActiveState();
206
547
  break;
207
548
  case "replace":
208
- this.replace = i !== null && i !== "false";
549
+ this.replace = n !== null && n !== "false";
209
550
  break;
210
551
  case "active-class":
211
- this.activeClass = i || "active", this.updateActiveState();
552
+ this.activeClass = n || "active", this.updateActiveState();
212
553
  break;
213
554
  case "exact":
214
- this.exact = i !== null && i !== "false", this.updateActiveState();
555
+ this.exact = n !== null && n !== "false", this.updateActiveState();
215
556
  break;
216
557
  }
217
558
  }
@@ -222,25 +563,23 @@ class x extends (X = Y) {
222
563
  * 编程式导航
223
564
  */
224
565
  navigate() {
225
- this.to && this.handleClick(
226
- new MouseEvent("click", {
227
- bubbles: !0,
228
- cancelable: !0
229
- })
230
- );
566
+ this.to && this.handleClick(new MouseEvent("click", {
567
+ bubbles: !0,
568
+ cancelable: !0
569
+ }));
231
570
  }
232
- }
233
- L = kt(X);
234
- x = Rt(L, 0, "WsxLink", K, x);
235
- m(x, "observedAttributes", ["to", "replace", "active-class", "exact"]);
236
- Ct(L, 1, x);
237
- const At = y("RouterUtils");
238
- class Lt {
571
+ }, [bt, pt] = Nt(it, [], _t, 0, void 0, st).c, it), nt = class extends Ut {
572
+ constructor() {
573
+ super(bt), V(this, "observedAttributes", ["to", "replace", "active-class", "exact"]), pt();
574
+ }
575
+ }, V(nt, vt, void 0), nt)();
576
+ const Vt = F("RouterUtils");
577
+ class Kt {
239
578
  /**
240
579
  * 编程式导航
241
580
  */
242
- static navigate(t, r = !1) {
243
- r ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), At.debug(`Navigated to: ${t} (replace: ${r})`);
581
+ static navigate(t, e = !1) {
582
+ e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), Vt.debug(`Navigated to: ${t} (replace: ${e})`);
244
583
  }
245
584
  /**
246
585
  * 获取当前路由信息
@@ -259,9 +598,9 @@ class Lt {
259
598
  /**
260
599
  * 解析路由路径,提取参数
261
600
  */
262
- static parseRoute(t, r) {
263
- var i;
264
- if (t === r)
601
+ static parseRoute(t, e) {
602
+ var n;
603
+ if (t === e)
265
604
  return {
266
605
  route: t,
267
606
  params: {},
@@ -274,21 +613,21 @@ class Lt {
274
613
  exact: !1
275
614
  };
276
615
  if (t.includes(":")) {
277
- const o = ((i = t.match(/:([^/]+)/g)) == null ? void 0 : i.map((c) => c.slice(1))) || [], n = t.replace(/:[^/]+/g, "([^/]+)"), s = new RegExp(`^${n}$`), l = r.match(s);
278
- if (l && o.length > 0) {
279
- const c = {};
280
- return o.forEach((a, h) => {
281
- c[a] = l[h + 1];
616
+ const g = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((b) => b.slice(1))) || [], R = t.replace(/:[^/]+/g, "([^/]+)"), _ = new RegExp(`^${R}$`), I = e.match(_);
617
+ if (I && g.length > 0) {
618
+ const b = {};
619
+ return g.forEach((O, z) => {
620
+ b[O] = I[z + 1];
282
621
  }), {
283
622
  route: t,
284
- params: c,
623
+ params: b,
285
624
  exact: !0
286
625
  };
287
626
  }
288
627
  }
289
628
  if (t.endsWith("/*")) {
290
- const o = t.slice(0, -2);
291
- if (r.startsWith(o))
629
+ const g = t.slice(0, -2);
630
+ if (e.startsWith(g))
292
631
  return {
293
632
  route: t,
294
633
  params: {},
@@ -300,37 +639,37 @@ class Lt {
300
639
  /**
301
640
  * 构建路由路径,替换参数
302
641
  */
303
- static buildPath(t, r = {}) {
304
- let i = t;
305
- return Object.entries(r).forEach(([o, n]) => {
306
- i = i.replace(`:${o}`, encodeURIComponent(n));
307
- }), i;
642
+ static buildPath(t, e = {}) {
643
+ let n = t;
644
+ return Object.entries(e).forEach(([g, R]) => {
645
+ n = n.replace(`:${g}`, encodeURIComponent(R));
646
+ }), n;
308
647
  }
309
648
  /**
310
649
  * 检查路由是否匹配当前路径
311
650
  */
312
- static isRouteActive(t, r = !1) {
313
- const i = window.location.pathname;
314
- return r ? i === t : t === "/" ? i === "/" : i.startsWith(t);
651
+ static isRouteActive(t, e = !1) {
652
+ const n = window.location.pathname;
653
+ return e ? n === t : t === "/" ? n === "/" : n.startsWith(t);
315
654
  }
316
655
  /**
317
656
  * 获取路由层级
318
657
  */
319
658
  static getRouteDepth(t) {
320
- return t.split("/").filter((r) => r.length > 0).length;
659
+ return t.split("/").filter((e) => e.length > 0).length;
321
660
  }
322
661
  /**
323
662
  * 获取父级路由
324
663
  */
325
664
  static getParentRoute(t) {
326
- const r = t.split("/").filter((i) => i.length > 0);
327
- return r.length <= 1 ? "/" : (r.pop(), "/" + r.join("/"));
665
+ const e = t.split("/").filter((n) => n.length > 0);
666
+ return e.length <= 1 ? "/" : (e.pop(), "/" + e.join("/"));
328
667
  }
329
668
  /**
330
669
  * 合并路由路径
331
670
  */
332
671
  static joinPaths(...t) {
333
- return t.map((r) => r.replace(/^\/+|\/+$/g, "")).filter((r) => r.length > 0).join("/").replace(/^/, "/");
672
+ return t.map((e) => e.replace(/^\/+|\/+$/g, "")).filter((e) => e.length > 0).join("/").replace(/^/, "/");
334
673
  }
335
674
  /**
336
675
  * 检查是否为外部链接
@@ -347,20 +686,20 @@ class Lt {
347
686
  /**
348
687
  * 设置查询参数
349
688
  */
350
- static setQueryParam(t, r, i = !1) {
351
- const o = new URL(window.location.href);
352
- o.searchParams.set(t, r);
353
- const n = o.pathname + o.search + o.hash;
354
- this.navigate(n, i);
689
+ static setQueryParam(t, e, n = !1) {
690
+ const g = new URL(window.location.href);
691
+ g.searchParams.set(t, e);
692
+ const R = g.pathname + g.search + g.hash;
693
+ this.navigate(R, n);
355
694
  }
356
695
  /**
357
696
  * 删除查询参数
358
697
  */
359
- static removeQueryParam(t, r = !1) {
360
- const i = new URL(window.location.href);
361
- i.searchParams.delete(t);
362
- const o = i.pathname + i.search + i.hash;
363
- this.navigate(o, r);
698
+ static removeQueryParam(t, e = !1) {
699
+ const n = new URL(window.location.href);
700
+ n.searchParams.delete(t);
701
+ const g = n.pathname + n.search + n.hash;
702
+ this.navigate(g, e);
364
703
  }
365
704
  /**
366
705
  * 返回上一页
@@ -390,18 +729,18 @@ class Lt {
390
729
  * 监听路由变化
391
730
  */
392
731
  static onRouteChange(t) {
393
- const r = () => {
394
- const i = this.getCurrentRoute();
395
- t(i);
732
+ const e = () => {
733
+ const n = this.getCurrentRoute();
734
+ t(n);
396
735
  };
397
- return window.addEventListener("popstate", r), document.addEventListener("route-changed", r), () => {
398
- window.removeEventListener("popstate", r), document.removeEventListener("route-changed", r);
736
+ return window.addEventListener("popstate", e), document.addEventListener("route-changed", e), () => {
737
+ window.removeEventListener("popstate", e), document.removeEventListener("route-changed", e);
399
738
  };
400
739
  }
401
740
  }
402
741
  export {
403
- Lt as RouterUtils,
404
- x as WsxLink,
405
- $ as WsxRouter,
406
- b as WsxView
742
+ Kt as RouterUtils,
743
+ bt as WsxLink,
744
+ At as WsxRouter,
745
+ dt as WsxView
407
746
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wsxjs/wsx-router",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
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.7"
21
+ "@wsxjs/wsx-core": "0.0.8"
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/wsx-vite-plugin": "0.0.7",
34
- "@wsxjs/eslint-plugin-wsx": "0.0.7"
33
+ "@wsxjs/wsx-vite-plugin": "0.0.8",
34
+ "@wsxjs/eslint-plugin-wsx": "0.0.8"
35
35
  },
36
36
  "keywords": [
37
37
  "wsx",
package/src/WsxLink.wsx CHANGED
@@ -1,6 +1,5 @@
1
1
  /** @jsxImportSource @wsxjs/wsx-core */
2
2
  import { WebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
3
- import styles from "./WsxLink.css?inline";
4
3
 
5
4
  const logger = createLogger("WsxLink");
6
5
 
@@ -29,13 +28,6 @@ export default class WsxLink extends WebComponent {
29
28
  private activeClass: string = "active";
30
29
  private exact: boolean = false;
31
30
 
32
- constructor() {
33
- super({
34
- styles,
35
- styleName: "wsx-link",
36
- });
37
- }
38
-
39
31
  render() {
40
32
  return (
41
33
  <a href={this.to} class="wsx-link" onClick={this.handleClick} part="link">