@elurjs/core 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +5 -5
  2. package/dist/lib/component.cjs +1 -1
  3. package/dist/lib/component.js +1 -1
  4. package/dist/lib/devtools.cjs +1 -1
  5. package/dist/lib/devtools.js +1 -1
  6. package/dist/lib/elur/component.cjs +1 -1
  7. package/dist/lib/elur/component.cjs.map +1 -1
  8. package/dist/lib/elur/component.d.cts +1 -1
  9. package/dist/lib/elur/component.d.ts +1 -1
  10. package/dist/lib/elur/component.js +1 -1
  11. package/dist/lib/elur/component.js.map +1 -1
  12. package/dist/lib/elur/devtools.cjs +1 -1
  13. package/dist/lib/elur/devtools.cjs.map +1 -1
  14. package/dist/lib/elur/devtools.js +1 -1
  15. package/dist/lib/elur/devtools.js.map +1 -1
  16. package/dist/lib/elur/lifecycle.cjs +1 -1
  17. package/dist/lib/elur/lifecycle.cjs.map +1 -1
  18. package/dist/lib/elur/lifecycle.d.cts +6 -0
  19. package/dist/lib/elur/lifecycle.d.ts +6 -0
  20. package/dist/lib/elur/lifecycle.js +40 -7
  21. package/dist/lib/elur/lifecycle.js.map +1 -1
  22. package/dist/lib/elur/reactivity.cjs +1 -1
  23. package/dist/lib/elur/reactivity.cjs.map +1 -1
  24. package/dist/lib/elur/reactivity.d.cts +7 -0
  25. package/dist/lib/elur/reactivity.d.ts +7 -0
  26. package/dist/lib/elur/reactivity.js +53 -23
  27. package/dist/lib/elur/reactivity.js.map +1 -1
  28. package/dist/lib/elur/router-registry.cjs +2 -0
  29. package/dist/lib/elur/router-registry.cjs.map +1 -0
  30. package/dist/lib/elur/router-registry.d.cts +14 -0
  31. package/dist/lib/elur/router-registry.d.ts +14 -0
  32. package/dist/lib/elur/router-registry.js +15 -0
  33. package/dist/lib/elur/router-registry.js.map +1 -0
  34. package/dist/lib/elur/router.cjs +3 -3
  35. package/dist/lib/elur/router.cjs.map +1 -1
  36. package/dist/lib/elur/router.d.cts +2 -5
  37. package/dist/lib/elur/router.d.ts +2 -5
  38. package/dist/lib/elur/router.js +159 -166
  39. package/dist/lib/elur/router.js.map +1 -1
  40. package/dist/lib/elur/template/html.cjs +1 -1
  41. package/dist/lib/elur/template/html.cjs.map +1 -1
  42. package/dist/lib/elur/template/html.js +1 -1
  43. package/dist/lib/elur/template/html.js.map +1 -1
  44. package/dist/lib/elur/template/types.cjs +1 -1
  45. package/dist/lib/elur/template/types.cjs.map +1 -1
  46. package/dist/lib/elur/template/types.js +1 -1
  47. package/dist/lib/elur/template/types.js.map +1 -1
  48. package/dist/lib/elur.cjs +1 -1
  49. package/dist/lib/elur.js +6 -5
  50. package/dist/lib/index.cjs +1 -1
  51. package/dist/lib/index.js +6 -5
  52. package/dist/lib/lifecycle.cjs +1 -1
  53. package/dist/lib/lifecycle.js +40 -7
  54. package/dist/lib/router.cjs +3 -3
  55. package/dist/lib/router.js +159 -166
  56. package/dist/lib/signals.cjs +1 -1
  57. package/dist/lib/signals.js +53 -23
  58. package/package.json +1 -1
@@ -20,20 +20,53 @@ var e = class {
20
20
  function t(e) {
21
21
  return typeof e == "object" && !!e && e.__isElurComponent === !0;
22
22
  }
23
- var n = null;
24
- function r(e) {
25
- n = e;
23
+ var n = Symbol.for("@elurjs/core/reactivity-state");
24
+ function r() {
25
+ let e = globalThis, t = e[n];
26
+ return t || (t = {}, e[n] = t), t;
26
27
  }
27
28
  function i(e) {
28
- n?.onMountStart?.(e);
29
+ let t = e.componentDebugHookSet;
30
+ if (!t || t.size === 0) {
31
+ e.componentDebugHooks = null;
32
+ return;
33
+ }
34
+ if (t.size === 1) {
35
+ e.componentDebugHooks = t.values().next().value ?? null;
36
+ return;
37
+ }
38
+ e.componentDebugHooks = {
39
+ onMountStart(e) {
40
+ for (let n of t) n.onMountStart?.(e);
41
+ },
42
+ onMountEnd(e) {
43
+ for (let n of t) n.onMountEnd?.(e);
44
+ },
45
+ onUnmount(e) {
46
+ for (let n of t) n.onUnmount?.(e);
47
+ }
48
+ };
29
49
  }
30
50
  function a(e) {
31
- n?.onMountEnd?.(e);
51
+ let t = r(), n = /* @__PURE__ */ new Set();
52
+ e && n.add(e), t.componentDebugHookSet = n, i(t);
32
53
  }
33
54
  function o(e) {
34
- n?.onUnmount?.(e);
55
+ let t = r(), n = t.componentDebugHookSet;
56
+ return n || (n = /* @__PURE__ */ new Set(), t.componentDebugHooks && n.add(t.componentDebugHooks), t.componentDebugHookSet = n), n.add(e), i(t), () => {
57
+ n.delete(e), i(t);
58
+ };
59
+ }
60
+ function s(e) {
61
+ r().componentDebugHooks?.onMountStart?.(e);
62
+ }
63
+ function c(e) {
64
+ r().componentDebugHooks?.onMountEnd?.(e);
65
+ }
66
+ function l(e) {
67
+ r().componentDebugHooks?.onUnmount?.(e);
35
68
  }
36
69
  //#endregion
37
- export { e as ElurComponent, a as _debugComponentMountEnd, i as _debugComponentMountStart, o as _debugComponentUnmount, r as _setComponentDebugHooks, t as isElurComponent };
70
+ export { e as ElurComponent, o as _addComponentDebugHooks, c as _debugComponentMountEnd, s as _debugComponentMountStart, l as _debugComponentUnmount, a as _setComponentDebugHooks, t as isElurComponent };
38
71
 
39
72
  //# sourceMappingURL=lifecycle.js.map
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./signals.cjs`),t=require(`./lifecycle.cjs`),n=require(`./context.cjs`),r=require(`./elur/template/html.cjs`);var i=n.createInjectionKey(`elur:router`),a=null,o=null,s=[],c=`__elur_scroll`,l=`__elur_pos`;function u(){if(!a)throw Error(`[elur] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).`);return a}function d(){return a!==null}function f(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||typeof e!=`object`)return null;let t=e[c];if(!t||typeof t!=`object`)return null;let n=t.left,r=t.top;return typeof n!=`number`||typeof r!=`number`?null:{left:n,top:r}}function p(e){if(!e||typeof e!=`object`)return null;let t=e[l];return typeof t==`number`?t:null}function m(e,t,n){let r=e&&typeof e==`object`?{...e}:{};return r[c]={left:t.left,top:t.top},r[l]=n,r}function h(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function g(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!=null&&r!==!1&&t.set(n,String(r));let n=t.toString();return n?`?`+n:``}function _(e){return e===`*`?[{kind:`wildcard`}]:e.split(`/`).filter(Boolean).map(e=>e===`*`?{kind:`wildcard`}:e.startsWith(`:`)?{kind:`param`,name:e.slice(1)}:{kind:`literal`,value:e})}function v(e,t){return t===`*`?e===``?`*`:e+`/*`:(e+(t.startsWith(`/`)?t:`/`+t)).replace(/\/+/g,`/`)||`/`}function y(e,t=``,n=[]){let r=[];for(let i of e){let e=v(t,i.path),a=[...n,i.component],o=_(e);r.push({fullPath:e,segments:o,chain:a,name:i.name,meta:i.meta,beforeEnter:i.beforeEnter,record:i}),i.children?.length&&r.push(...y(i.children,e,a))}return r}function b(e,t){let n=e.split(`/`).filter(Boolean),r=t.segments;if(r.length===1&&r[0].kind===`wildcard`)return{};let i=r.length>0&&r[r.length-1].kind===`wildcard`,a=i?r.slice(0,-1):r;if(i){if(n.length<a.length)return null}else if(n.length!==a.length)return null;let o={};for(let e=0;e<a.length;e++){let t=a[e];if(t.kind===`literal`){if(n[e]!==t.value)return null}else if(t.kind===`param`)try{o[t.name]=decodeURIComponent(n[e]??``)}catch{o[t.name]=n[e]??``}}return o}function x(e){return e.segments.reduce((e,t)=>t.kind===`literal`?e+2:t.kind===`param`?e+1:e,0)}function S(e,t){let n,r={},i=-1;for(let a of t){let t=b(e,a);if(t===null)continue;let o=x(a);o>i&&(n=a,r=t,i=o)}return n?{route:n,params:r}:void 0}function C(e){let t=e.trim();return!t||t===`/`?``:(t.startsWith(`/`)||(t=`/`+t),t.endsWith(`/`)&&(t=t.slice(0,-1)),t)}function w(){if(typeof document>`u`)return``;let e=document.querySelector(`base`);if(!e)return``;let t=e.getAttribute(`href`)||``;try{return C(new URL(t,window.location.origin).pathname)}catch{return C(t)}}function te(e){return e===!1?{allow:!1}:e===!0||e==null?{allow:!0}:typeof e==`string`?{allow:!1,redirect:e}:typeof e==`object`&&`redirect`in e&&typeof e.redirect==`string`?{allow:!1,redirect:e.redirect}:{allow:!0}}function T(t,n){let r=n?.base==null?w():C(n.base),i=n?.mode??`history`,s=i===`hash`,c=n?.scrollBehavior,l=new Map,u=!1;function d(e){return e?e.startsWith(`/`)?e:`/`+e:`/`}function _(e){let t=d(e||`/`);if(r&&t.startsWith(r)){let e=t.slice(r.length);return e===``?`/`:d(e)}return t}function v(e){let t=d(e);return r?(r+t).replace(/\/+/g,`/`)||`/`:t}function b(){let e=window.location.hash||``;if(e.startsWith(`#`)&&(e=e.slice(1)),!e)return{pathname:`/`,search:``};e.startsWith(`/`)||(e=`/`+e);let t=e.indexOf(`?`),n=t===-1?e:e.slice(0,t),r=t===-1?``:e.slice(t);return{pathname:_(n),search:r}}function x(){return s?b():{pathname:_(window.location.pathname||`/`),search:window.location.search||``}}function T(e,t){let n=v(e)+g(t);return s?`#`+n:n}function E(e,t){return d(e)+g(t)}let D=x(),O=D.pathname,k=h(D.search),A=y(t),j=new Map;for(let e of A)e.name&&(j.has(e.name)&&console.warn(`[Elur Router] Duplicate route name: "${e.name}"`),j.set(e.name,e));let M=S(O,A),N=e.signal(O),P=e.signal(M?.params??{}),F=e.signal(k),I=p(history.state)??0,L=e.signal({action:`initial`,direction:`none`}),R=e.signal(I>0);s?l.set(E(O,k),f()):history.replaceState(m(history.state,f(),I),``);function z(e){window.scrollTo(e.left,e.top)}function B(e,t,n){if(c){let r=c(e,t,n);if(!r)return;z(r);return}z(n??{left:0,top:0})}function V(e,t){let n=f();if(s){l.set(E(e,t),n);return}history.replaceState(m(history.state,n,I),``)}let H=[],U=[],W=0;function G(e,t,n,r,i){let a=[...H];n&&a.push(n);let o=++W;if(a.length===0){r();return}let s=0;function c(n){if(o!==W)return;let l=te(n);if(!l.allow){if(l.redirect&&l.redirect!==e){Q(l.redirect);return}if(l.redirect===e){r();return}i?.();return}if(s>=a.length){r();return}let u=a[s++](e,t);if(u instanceof Promise){u.then(c);return}c(u)}c(void 0)}let K=!1;function q(e,t){let n=e.indexOf(`?`),r=d((n===-1?e:e.slice(0,n))||`/`),i=n===-1?{}:h(e.slice(n)),a=t?{...i,...t}:i,o={};for(let[e,t]of Object.entries(a))t!=null&&t!==!1&&(o[e]=String(t));return{pathname:r,stringQuery:o}}function ne(e){let t=j.get(e.name);if(!t)throw Error(`[Elur Router] No route with name "${e.name}"`);return`/`+t.segments.map(t=>{if(t.kind===`literal`)return t.value;if(t.kind===`wildcard`)return``;let n=e.params?.[t.name];if(n==null)throw Error(`[Elur Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(n))}).filter(Boolean).join(`/`)}function J(e,t){return typeof e==`string`?q(e,t?.query):q(ne(e),{...e.query??{},...t?.query??{}})}o&&=(o(),null);let Y=(e,t,n,r,i)=>{let a=N.value,o={...F.value},s=S(e,A),c=`none`;r!=null&&(r<I?c=`back`:r>I&&(c=`forward`)),G(e,a,s?.route.beforeEnter,()=>{r!=null&&(I=r);let i=Z;Z=void 0,L.value={action:`pop`,direction:c,animation:i},P.value=s?.params??{},F.value=t,N.value=e,R.value=I>0,B(e,a,n);for(let t of U)try{t(e,a)}catch{}},()=>i(a,o))};if(s){let e=()=>{if(u){u=!1;return}let e=x(),t=h(e.search),n=l.get(E(e.pathname,t))??null;Y(e.pathname,t,n,null,(e,t)=>{u=!0,window.location.hash=T(e,t).slice(1),queueMicrotask(()=>{u=!1})})};window.addEventListener(`hashchange`,e),o=()=>window.removeEventListener(`hashchange`,e)}else{let e=e=>{let t=x(),n=h(t.search),r=ee(e.state??history.state),i=p(e.state??history.state);Y(t.pathname,n,r,i,(e,t)=>{history.pushState(m({},f(),I),``,T(e,t))})};window.addEventListener(`popstate`,e),o=()=>window.removeEventListener(`popstate`,e)}function X(e,t,n,r,i,a,o){o||(V(n,r),I+=1),L.value=a,P.value=i?.params??{},F.value=t,N.value=e,R.value=I>0;let c=T(e,t);if(s)l.set(E(e,t),{left:0,top:0}),o?history.replaceState(history.state,``,c):(u=!0,window.location.hash=c.slice(1),queueMicrotask(()=>{u=!1}));else{let e=m({},{left:0,top:0},I);o?history.replaceState(e,``,c):history.pushState(e,``,c)}B(e,n,null);for(let t of U)try{t(e,n)}catch{}}let Z;function Q(e,t){K=!0;let{pathname:n,stringQuery:r}=J(e,t),i=N.value,a={...F.value},o=S(n,A),s={action:`push`,direction:t?.direction??`forward`,animation:t?.animation};G(n,i,o?.route.beforeEnter,()=>X(n,r,i,a,o,s,!1))}function re(e,t){K=!0;let{pathname:n,stringQuery:r}=J(e,t),i=N.value,a={...F.value},o=S(n,A),s={action:`replace`,direction:t?.direction??`root`,animation:t?.animation};G(n,i,o?.route.beforeEnter,()=>X(n,r,i,a,o,s,!0))}function ie(e){e!==void 0&&(Z=e),history.back()}function ae(e){e!==void 0&&(Z=e),history.forward()}function oe(e){history.go(e)}function se(e,t=!0){let n=N.value;return t?n===e:n===e||n.startsWith(e.endsWith(`/`)?e:e+`/`)}function ce(e){let t=S(e,A);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}}function le(e){return H.push(e),()=>{let t=H.indexOf(e);t!==-1&&H.splice(t,1)}}function ue(e){return U.push(e),()=>{let t=U.indexOf(e);t!==-1&&U.splice(t,1)}}let $={current:N,params:P,query:F,intent:L,canGoBack:R,base:r||`/`,navigate:Q,replace:re,back:ie,forward:ae,go:oe,isActive:se,resolve:ce,beforeEach:le,afterEach:ue,routes:t,_flat:A,_guards:H,_base:r,_mode:i};return a&&console.warn(`[elur] A router already exists. The previous router is being replaced. Only one router instance should be active at a time.`),a=$,queueMicrotask(()=>{K||G(O,``,S(O,A)?.route.beforeEnter,()=>{},()=>{let e=T(`/`,{});s?(l.set(E(`/`,{}),{left:0,top:0}),history.replaceState(history.state,``,e)):history.replaceState(m({},{left:0,top:0},I),``,e);let t=S(`/`,A);L.value={action:`replace`,direction:`root`},N.value=`/`,P.value=t?.params??{},F.value={},R.value=I>0,B(`/`,O,null)})}),$}function E(){return n.inject(i)||u()}function D(){o&&=(o(),null),a=null,s.length=0}var O=class extends t.ElurComponent{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,t=this._router;return r.html`<div class="router-view">${()=>{let n=t??E(),i=S(n.current.value,n._flat);if(!i)return r.html`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./signals.cjs`),t=require(`./lifecycle.cjs`),n=require(`./context.cjs`),r=require(`./elur/template/html.cjs`),i=require(`./elur/router-registry.cjs`);var a=null,o=null,s=`__elur_scroll`,c=`__elur_pos`;function l(){if(!a)throw Error(`[elur] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).`);return a}function u(){return a!==null}function d(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||typeof e!=`object`)return null;let t=e[s];if(!t||typeof t!=`object`)return null;let n=t.left,r=t.top;return typeof n!=`number`||typeof r!=`number`?null:{left:n,top:r}}function f(e){if(!e||typeof e!=`object`)return null;let t=e[c];return typeof t==`number`?t:null}function p(e,t,n){let r=e&&typeof e==`object`?{...e}:{};return r[s]={left:t.left,top:t.top},r[c]=n,r}function m(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function h(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!=null&&r!==!1&&t.set(n,String(r));let n=t.toString();return n?`?`+n:``}function g(e){return e===`*`?[{kind:`wildcard`}]:e.split(`/`).filter(Boolean).map(e=>e===`*`?{kind:`wildcard`}:e.startsWith(`:`)?{kind:`param`,name:e.slice(1)}:{kind:`literal`,value:e})}function _(e,t){return t===`*`?e===``?`*`:e+`/*`:(e+(t.startsWith(`/`)?t:`/`+t)).replace(/\/+/g,`/`)||`/`}function v(e,t=``,n=[]){let r=[];for(let i of e){let e=_(t,i.path),a=[...n,i.component],o=g(e);r.push({fullPath:e,segments:o,chain:a,name:i.name,meta:i.meta,beforeEnter:i.beforeEnter,record:i}),i.children?.length&&r.push(...v(i.children,e,a))}return r}function y(e,t){let n=e.split(`/`).filter(Boolean),r=t.segments;if(r.length===1&&r[0].kind===`wildcard`)return{};let i=r.length>0&&r[r.length-1].kind===`wildcard`,a=i?r.slice(0,-1):r;if(i){if(n.length<a.length)return null}else if(n.length!==a.length)return null;let o={};for(let e=0;e<a.length;e++){let t=a[e];if(t.kind===`literal`){if(n[e]!==t.value)return null}else if(t.kind===`param`)try{o[t.name]=decodeURIComponent(n[e]??``)}catch{o[t.name]=n[e]??``}}return o}function b(e){return e.segments.reduce((e,t)=>t.kind===`literal`?e+2:t.kind===`param`?e+1:e,0)}function x(e,t){let n,r={},i=-1;for(let a of t){let t=y(e,a);if(t===null)continue;let o=b(a);o>i&&(n=a,r=t,i=o)}return n?{route:n,params:r}:void 0}function S(e){let t=e.trim();return!t||t===`/`?``:(t.startsWith(`/`)||(t=`/`+t),t.endsWith(`/`)&&(t=t.slice(0,-1)),t)}function te(){if(typeof document>`u`)return``;let e=document.querySelector(`base`);if(!e)return``;let t=e.getAttribute(`href`)||``;try{return S(new URL(t,window.location.origin).pathname)}catch{return S(t)}}function C(e){return e===!1?{allow:!1}:e===!0||e==null?{allow:!0}:typeof e==`string`?{allow:!1,redirect:e}:typeof e==`object`&&`redirect`in e&&typeof e.redirect==`string`?{allow:!1,redirect:e.redirect}:{allow:!0}}function w(t,n){let r=n?.base==null?te():S(n.base),i=n?.mode??`history`,s=i===`hash`,c=n?.scrollBehavior,l=new Map,u=!1;function g(e){return e?e.startsWith(`/`)?e:`/`+e:`/`}function _(e){let t=g(e||`/`);if(r&&t.startsWith(r)){let e=t.slice(r.length);return e===``?`/`:g(e)}return t}function y(e){let t=g(e);return r?(r+t).replace(/\/+/g,`/`)||`/`:t}function b(){let e=window.location.hash||``;if(e.startsWith(`#`)&&(e=e.slice(1)),!e)return{pathname:`/`,search:``};e.startsWith(`/`)||(e=`/`+e);let t=e.indexOf(`?`),n=t===-1?e:e.slice(0,t),r=t===-1?``:e.slice(t);return{pathname:_(n),search:r}}function w(){return s?b():{pathname:_(window.location.pathname||`/`),search:window.location.search||``}}function T(e,t){let n=y(e)+h(t);return s?`#`+n:n}function E(e,t){return g(e)+h(t)}let D=w(),O=D.pathname,k=m(D.search),A=v(t),j=new Map;for(let e of A)e.name&&(j.has(e.name)&&console.warn(`[Elur Router] Duplicate route name: "${e.name}"`),j.set(e.name,e));let ne=x(O,A),M=e.signal(O),N=e.signal(ne?.params??{}),P=e.signal(k),F=f(history.state)??0,I=e.signal({action:`initial`,direction:`none`}),L=e.signal(F>0);s?l.set(E(O,k),d()):history.replaceState(p(history.state,d(),F),``);function R(e){window.scrollTo(e.left,e.top)}function z(e,t,n){if(c){let r=c(e,t,n);if(!r)return;R(r);return}R(n??{left:0,top:0})}function B(e,t){let n=d();if(s){l.set(E(e,t),n);return}history.replaceState(p(history.state,n,F),``)}let V=[],H=[],U=0;function W(e,t,n,r,i){let a=[...V];n&&a.push(n);let o=++U;if(a.length===0){r();return}let s=0;function c(n){if(o!==U)return;let l=C(n);if(!l.allow){if(l.redirect&&l.redirect!==e){Z(l.redirect);return}if(l.redirect===e){r();return}i?.();return}if(s>=a.length){r();return}let u=a[s++](e,t);if(u instanceof Promise){u.then(c);return}c(u)}c(void 0)}let G=!1;function K(e,t){let n=e.indexOf(`?`),r=g((n===-1?e:e.slice(0,n))||`/`),i=n===-1?{}:m(e.slice(n)),a=t?{...i,...t}:i,o={};for(let[e,t]of Object.entries(a))t!=null&&t!==!1&&(o[e]=String(t));return{pathname:r,stringQuery:o}}function re(e){let t=j.get(e.name);if(!t)throw Error(`[Elur Router] No route with name "${e.name}"`);return`/`+t.segments.map(t=>{if(t.kind===`literal`)return t.value;if(t.kind===`wildcard`)return``;let n=e.params?.[t.name];if(n==null)throw Error(`[Elur Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(n))}).filter(Boolean).join(`/`)}function q(e,t){return typeof e==`string`?K(e,t?.query):K(re(e),{...e.query??{},...t?.query??{}})}o&&=(o(),null);let J=(e,t,n,r,i)=>{let a=M.value,o={...P.value},s=x(e,A),c=`none`;r!=null&&(r<F?c=`back`:r>F&&(c=`forward`)),W(e,a,s?.route.beforeEnter,()=>{r!=null&&(F=r);let i=X;X=void 0,I.value={action:`pop`,direction:c,animation:i},N.value=s?.params??{},P.value=t,M.value=e,L.value=F>0,z(e,a,n);for(let t of H)try{t(e,a)}catch{}},()=>i(a,o))};if(s){let e=()=>{if(u){u=!1;return}let e=w(),t=m(e.search),n=l.get(E(e.pathname,t))??null;J(e.pathname,t,n,null,(e,t)=>{u=!0,window.location.hash=T(e,t).slice(1),queueMicrotask(()=>{u=!1})})};window.addEventListener(`hashchange`,e),o=()=>window.removeEventListener(`hashchange`,e)}else{let e=e=>{let t=w(),n=m(t.search),r=ee(e.state??history.state),i=f(e.state??history.state);J(t.pathname,n,r,i,(e,t)=>{history.pushState(p({},d(),F),``,T(e,t))})};window.addEventListener(`popstate`,e),o=()=>window.removeEventListener(`popstate`,e)}function Y(e,t,n,r,i,a,o){o||(B(n,r),F+=1),I.value=a,N.value=i?.params??{},P.value=t,M.value=e,L.value=F>0;let c=T(e,t);if(s)l.set(E(e,t),{left:0,top:0}),o?history.replaceState(history.state,``,c):(u=!0,window.location.hash=c.slice(1),queueMicrotask(()=>{u=!1}));else{let e=p({},{left:0,top:0},F);o?history.replaceState(e,``,c):history.pushState(e,``,c)}z(e,n,null);for(let t of H)try{t(e,n)}catch{}}let X;function Z(e,t){G=!0;let{pathname:n,stringQuery:r}=q(e,t),i=M.value,a={...P.value},o=x(n,A),s={action:`push`,direction:t?.direction??`forward`,animation:t?.animation};W(n,i,o?.route.beforeEnter,()=>Y(n,r,i,a,o,s,!1))}function ie(e,t){G=!0;let{pathname:n,stringQuery:r}=q(e,t),i=M.value,a={...P.value},o=x(n,A),s={action:`replace`,direction:t?.direction??`root`,animation:t?.animation};W(n,i,o?.route.beforeEnter,()=>Y(n,r,i,a,o,s,!0))}function ae(e){e!==void 0&&(X=e),history.back()}function oe(e){e!==void 0&&(X=e),history.forward()}function Q(e){history.go(e)}function se(e,t=!0){let n=M.value;return t?n===e:n===e||n.startsWith(e.endsWith(`/`)?e:e+`/`)}function ce(e){let t=x(e,A);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}}function le(e){return V.push(e),()=>{let t=V.indexOf(e);t!==-1&&V.splice(t,1)}}function ue(e){return H.push(e),()=>{let t=H.indexOf(e);t!==-1&&H.splice(t,1)}}let $={current:M,params:N,query:P,intent:I,canGoBack:L,base:r||`/`,navigate:Z,replace:ie,back:ae,forward:oe,go:Q,isActive:se,resolve:ce,beforeEach:le,afterEach:ue,routes:t,_flat:A,_guards:V,_base:r,_mode:i};return a&&console.warn(`[elur] A router already exists. The previous router is being replaced. Only one router instance should be active at a time.`),a=$,queueMicrotask(()=>{G||W(O,``,x(O,A)?.route.beforeEnter,()=>{},()=>{let e=T(`/`,{});s?(l.set(E(`/`,{}),{left:0,top:0}),history.replaceState(history.state,``,e)):history.replaceState(p({},{left:0,top:0},F),``,e);let t=x(`/`,A);I.value={action:`replace`,direction:`root`},M.value=`/`,N.value=t?.params??{},P.value={},L.value=F>0,z(`/`,O,null)})}),$}function T(){return n.inject(i.RouterKey)||l()}function E(){o&&=(o(),null),a=null,i._mountedRouters.length=0}var D=class extends t.ElurComponent{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,t=this._router;return r.html`<div class="router-view">${()=>{let n=t??T(),i=x(n.current.value,n._flat);if(!i)return r.html`
2
2
  <div style="color:#f87171;padding:16px 0">
3
3
  404 — Route not found: <strong>${n.current.value}</strong>
4
4
  </div>
@@ -6,7 +6,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
6
6
  <span></span>
7
7
  `;let a=i.route.chain[e];return a?a():r.html`
8
8
  <span></span>
9
- `}}</div>`}},k=class extends t.ElurComponent{_to;_label;_router;constructor(e,t,n){super(),this._to=e,this._label=t,this._router=n}render(){let e=this._to,t=this._label,n=this._router??E(),i=e.startsWith(`/`)?e:`/`+e,a=(n._base?n._base+i:i).replace(/\/+/g,`/`);return r.html`
9
+ `}}</div>`}},O=class extends t.ElurComponent{_to;_label;_router;constructor(e,t,n){super(),this._to=e,this._label=t,this._router=n}render(){let e=this._to,t=this._label,n=this._router??T(),i=e.startsWith(`/`)?e:`/`+e,a=(n._base?n._base+i:i).replace(/\/+/g,`/`);return r.html`
10
10
  <a href=${n._mode===`hash`?`#`+a:a} style=${()=>n.current.value===e?`color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a`:`color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px`} @click=${t=>{t.preventDefault(),n.navigate(e)}}>${t}</a>
11
- `}};function A(e){let t=s.indexOf(e);t>=0&&s.splice(t,1),s.push(e)}function j(e){let t=s.indexOf(e);t>=0&&s.splice(t,1)}function M(){let e=s.length?s[s.length-1]:a;if(!e)return null;let t=e,n=t.current.value,r=S(n,t._flat),i=r?.route.beforeEnter,o=t._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return i&&o.push(i.name||`beforeEnter`),{mode:t._mode,base:t._base||`/`,currentPath:n,params:{...t.params.value},query:{...t.query.value},matchedPath:r?.route.fullPath??null,activeGuards:{globalCount:t._guards.length,hasRouteGuard:!!i,names:o}}}exports.Link=k,exports.RouterKey=i,exports.RouterView=O,exports._debugGetRouterInternal=M,exports._debugRegisterRouter=A,exports._debugUnregisterRouter=j,exports._hasActiveRouter=d,exports._resetRouter=D,exports.createRouter=T,exports.elurRouter=E;
11
+ `}};function k(){let e=i._mountedRouters.length?i._mountedRouters[i._mountedRouters.length-1]:a;if(!e)return null;let t=e,n=t.current.value,r=x(n,t._flat),o=r?.route.beforeEnter,s=t._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return o&&s.push(o.name||`beforeEnter`),{mode:t._mode,base:t._base||`/`,currentPath:n,params:{...t.params.value},query:{...t.query.value},matchedPath:r?.route.fullPath??null,activeGuards:{globalCount:t._guards.length,hasRouteGuard:!!o,names:s}}}exports.Link=O,exports.RouterKey=i.RouterKey,exports.RouterView=D,exports._debugGetRouterInternal=k,exports._debugRegisterRouter=i._debugRegisterRouter,exports._debugUnregisterRouter=i._debugUnregisterRouter,exports._hasActiveRouter=u,exports._resetRouter=E,exports.createRouter=w,exports.elurRouter=T;
12
12
  //# sourceMappingURL=router.cjs.map