@jasonshimmy/custom-elements-runtime 2.3.1 → 2.4.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.
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
${
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./custom-elements-runtime.cjs.js"),b=require("./namespace-helpers-BsKQl3aH.cjs"),N=require("./custom-elements-runtime.store.cjs.js"),y=require("./logger-DiXdWaF-.cjs"),U=require("./custom-elements-runtime.directives.cjs.js"),j=n=>n?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(n)):{},T=new WeakMap;function F(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(n){if(!n)return"/";let r=n.replace(/\/+/g,"/");return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r}function I(n){const r=n.path||"/",t=q(r),h=t==="/"?[]:t.split("/").filter(Boolean),o=[],s=[];for(let l=0;l<h.length;l++){const d=h[l];if(d==="*"){if(l!==h.length-1)return y.devWarn(`Route '${n.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const p=`splat${o.length}`;o.push(p),s.push("__SPLAT__");continue}const R=d.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(R){const p=R[1],$=!!R[2];if($&&l!==h.length-1)return y.devWarn(`Route '${n.path}' contains a splat param ':${p}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};o.push(p),s.push($?"__SPLAT__":"([^/]+)");continue}s.push(F(d))}let c;if(s.length===0)c="^/$";else if(s[s.length-1]==="__SPLAT__"){const d=s.slice(0,-1).join("/");d?c=`^/${d}(?:/(.*))?(?:/)?$`:c="^(?:/(.*))?(?:/)?$"}else c=`^/${s.join("/")}(?:/)?$`;try{return{regex:new RegExp(c),paramNames:o}}catch(l){return y.devWarn(`Failed to compile route regex for '${n.path}': ${String(l)}`),{invalid:!0}}}const x=(n,r)=>{const t=q(r);for(const h of n){let o=T.get(h);if(o||(o=I(h),T.set(h,o)),o.invalid)continue;const{regex:s,paramNames:c}=o,l=s.exec(t);if(l){const d={},R=p=>{try{return decodeURIComponent(p)}catch{return p}};for(let p=0;p<c.length;p++){const $=l[p+1]||"";d[c[p]]=$?R($):""}return{route:h,params:d}}}return{route:null,params:{}}};function W(n,r){for(const t of n)if(x([t],r).route!==null)return t;return null}const A={};async function B(n){if(n.component)return n.component;if(n.load){if(A[n.path])return A[n.path];try{const r=await n.load();return A[n.path]=r.default,r.default}catch{throw new Error(`Failed to load component for route: ${n.path}`)}}throw new Error(`No component or loader defined for route: ${n.path}`)}function D(n){const{routes:r,base:t="",initialUrl:h}=n;let o,s,c,l,d,R,p;const $=async(f,i)=>{const e=W(r,f.path);if(!e||!e.beforeEnter)return!0;try{const a=await e.beforeEnter(f,i);return typeof a=="string"?(await E(a,!0),!1):a!==!1}catch(a){return y.devError("beforeEnter error",a),!1}},O=async(f,i)=>{const e=W(r,f.path);if(!e||!e.onEnter)return!0;try{const a=await e.onEnter(f,i);return typeof a=="string"?(await E(a,!0),!1):a!==!1}catch(a){return y.devError("onEnter error",a),!1}},_=(f,i)=>{const e=W(r,f.path);if(!(!e||!e.afterEnter))try{e.afterEnter(f,i)}catch(a){y.devError("afterEnter error",a)}},E=async(f,i=!1)=>{try{const e=f.indexOf("#"),a=e>=0?f.slice(e+1):"",u={path:(e>=0?f.slice(0,e):f).replace(t,"")||"/",query:{},fragment:a},m=x(r,u.path);if(!m.route)throw new Error(`No route found for ${u.path}`);const w=c.getState(),S={path:u.path,params:m.params,query:u.query,fragment:u.fragment};if(!await $(S,w)||!await O(S,w))return;typeof window<"u"&&typeof document<"u"&&(i?window.history.replaceState({},"",t+f):window.history.pushState({},"",t+f)),c.setState(S),_(S,w)}catch(e){y.devError("Navigation error:",e)}};if(typeof window<"u"&&typeof document<"u"&&typeof h>"u"){o=()=>{const i=new URL(window.location.href),e=i.pathname.replace(t,"")||"/",a=j(i.search),v=i.hash&&i.hash.length?i.hash.slice(1):"";return{path:e,query:a,fragment:v}},s=o();const f=x(r,s.path);c=N.createStore({path:s.path,params:f.params,query:s.query,fragment:s.fragment}),l=async(i=!1)=>{const e=o();await E(e.path,i)},window.addEventListener("popstate",()=>l(!0)),d=i=>E(i,!1),R=i=>E(i,!0),p=()=>window.history.back()}else{o=()=>{const e=new URL(h||"/","http://localhost"),a=e.pathname.replace(t,"")||"/",v=j(e.search),u=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:a,query:v,fragment:u}},s=o();const f=x(r,s.path);c=N.createStore({path:s.path,params:f.params,query:s.query,fragment:s.fragment}),l=async()=>{const e=o();await i(e.path)};const i=async e=>{try{const a=e.indexOf("#"),v=a>=0?e.slice(a+1):"",m={path:(a>=0?e.slice(0,a):e).replace(t,"")||"/",query:{},fragment:v},w=x(r,m.path);if(!w.route)throw new Error(`No route found for ${m.path}`);const S=c.getState(),k={path:m.path,params:w.params,query:m.query,fragment:m.fragment},P=W(r,k.path);if(P?.beforeEnter){const C=await P.beforeEnter(k,S);if(typeof C=="string"){await i(C);return}if(C===!1)return}if(P?.onEnter){const C=await P.onEnter(k,S);if(typeof C=="string"){await i(C);return}if(C===!1)return}c.setState(k),P?.afterEnter&&P.afterEnter(k,S)}catch(a){throw y.devError("SSR navigation error:",a),a}};d=async e=>i(e),R=async e=>i(e),p=()=>{}}return{store:c,push:d,replace:R,back:p,subscribe:c.subscribe,matchRoute:f=>x(r,f),getCurrent:()=>c.getState(),resolveRouteComponent:B}}function M(n,r){return x(n,r)}let L=null;function z(n){const r=D(n);return L=r,g.component("router-view",async()=>{const t=L||r;if(!t)return g.html`<div>Router not initialized.</div>`;const h=b.ref(t.getCurrent());let o;g.useOnConnected(()=>{try{t&&typeof t.subscribe=="function"&&(o=t.subscribe(c=>{try{h.value=c}catch(l){y.devWarn("router-view subscription update failed",l)}}))}catch(c){y.devWarn("router-view subscribe failed",c)}}),g.useOnDisconnected(()=>{if(typeof o=="function")try{o()}catch(c){y.devWarn("router-view unsubscribe failed",c)}});const s=t.matchRoute(h.value.path);if(!s||!s.route)return g.html`<div>Not found</div>`;try{const l=await t.resolveRouteComponent(s.route);if(typeof l=="string")return{tag:l,props:{},children:[]};if(typeof l=="function"){const d=l();return(d instanceof Promise?d:Promise.resolve(d)).then(p=>typeof p=="string"?{tag:p,props:{},children:[]}:p)}return g.html`<div>Invalid route component</div>`}catch{return g.html`<div>Invalid route component</div>`}}),g.component("router-link",()=>{const t=g.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),h=L||r,o=b.ref(h.getCurrent());let s;g.useStyle(()=>"a,button{display:inline-block;}");const c=b.ref(t.class||""),l=b.ref(t.style||"");g.useOnConnected(v=>{try{h&&typeof h.subscribe=="function"&&(s=h.subscribe(u=>{try{o.value=u}catch(m){y.devWarn("router-link subscription update failed",m)}}))}catch(u){y.devWarn("router-link subscribe failed",u)}try{const u=v?._host;if(u instanceof HTMLElement){const m=u.getAttribute("class"),w=u.getAttribute("style");m&&(c.value=m),w&&(l.value=w),m!==null&&u.removeAttribute("class"),w!==null&&u.removeAttribute("style")}}catch(u){y.devWarn("router-link host migration failed",u)}}),g.useOnDisconnected(()=>{if(typeof s=="function")try{s()}catch(v){y.devWarn("router-link unsubscribe failed",v)}});const d=b.computed(()=>{const u=(t.to||"").split("#")[0];try{return q(o.value.path)===q(u)}catch{return o.value.path===u}}),R=b.computed(()=>{const u=(t.to||"").split("#")[0];if(t.exact)return d.value;try{const m=q(o.value.path),w=q(u);return m.startsWith(w)}catch{return o.value&&typeof o.value.path=="string"&&o.value.path.startsWith(u)}}),p=b.computed(()=>{const u=(c&&c.value||t.class||"").split(/\s+/).filter(Boolean),m={};for(const w of u)m[w]=!0;return m}),$=b.computed(()=>({...p.value,[t.activeClass||"active"]:R.value,[t.exactActiveClass||"exact-active"]:d.value})),O=b.computed(()=>Object.keys($.value).filter(v=>$.value[v]).join(" ")),_=b.computed(()=>t.tag==="button"),E=b.computed(()=>d.value?t.ariaCurrentValue:""),f=b.computed(()=>!!t.disabled),i=b.computed(()=>!!t.external&&(t.tag==="a"||!t.tag)),e=b.computed(()=>l&&l.value||t.style||""),a=v=>{if(t.disabled){v.preventDefault();return}t.external&&(t.tag==="a"||!t.tag)||(v.preventDefault(),t.replace?h.replace(t.to):h.push(t.to))};return g.html`
|
|
2
|
+
${U.match().when(_.value,g.html`
|
|
3
3
|
<button
|
|
4
4
|
part="button"
|
|
5
|
-
class="${
|
|
6
|
-
style="${
|
|
5
|
+
class="${O.value}"
|
|
6
|
+
style="${e.value||null}"
|
|
7
7
|
aria-current="${E.value}"
|
|
8
|
-
disabled="${
|
|
9
|
-
aria-disabled="${
|
|
10
|
-
tabindex="${
|
|
8
|
+
disabled="${f.value?"":null}"
|
|
9
|
+
aria-disabled="${f.value?"true":null}"
|
|
10
|
+
tabindex="${f.value?"-1":null}"
|
|
11
11
|
@click="${a}"
|
|
12
12
|
>
|
|
13
13
|
<slot></slot>
|
|
14
14
|
</button>
|
|
15
|
-
`).otherwise(
|
|
15
|
+
`).otherwise(g.html`
|
|
16
16
|
<a
|
|
17
17
|
part="link"
|
|
18
|
-
href="${
|
|
19
|
-
class="${
|
|
20
|
-
style="${
|
|
18
|
+
href="${t.to}"
|
|
19
|
+
class="${O.value}"
|
|
20
|
+
style="${e.value||null}"
|
|
21
21
|
aria-current="${E.value}"
|
|
22
|
-
aria-disabled="${
|
|
23
|
-
tabindex="${
|
|
24
|
-
target="${
|
|
25
|
-
rel="${
|
|
22
|
+
aria-disabled="${f.value?"true":null}"
|
|
23
|
+
tabindex="${f.value?"-1":null}"
|
|
24
|
+
target="${i.value?"_blank":null}"
|
|
25
|
+
rel="${i.value?"noopener noreferrer":null}"
|
|
26
26
|
@click="${a}"
|
|
27
27
|
><slot></slot
|
|
28
28
|
></a>
|
|
29
29
|
`).done()}
|
|
30
|
-
`}),r}exports.initRouter=
|
|
30
|
+
`}),r}exports.initRouter=z;exports.matchRoute=x;exports.matchRouteSSR=M;exports.normalizePathForRoute=q;exports.parseQuery=j;exports.resolveRouteComponent=B;exports.useRouter=D;
|
|
31
31
|
//# sourceMappingURL=custom-elements-runtime.router.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.router.cjs.js","sources":["../src/lib/router.ts"],"sourcesContent":["import { html } from './runtime/template-compiler';\nimport { component } from './runtime/component';\nimport {\n useProps,\n useOnConnected,\n useOnDisconnected,\n useStyle,\n} from './runtime/hooks';\nimport { ref, computed } from './runtime/reactive';\nimport { createStore, type Store } from './store';\nimport { devError, devWarn } from './runtime/logger';\nimport { match } from './directives';\n\nexport type RouteComponent =\n | { new (...args: unknown[]): unknown } // class components\n | ((...args: unknown[]) => unknown); // functional components\n\nexport interface RouteState {\n path: string;\n params: Record<string, string>;\n query: Record<string, string>;\n}\n\nexport type GuardResult = boolean | string | Promise<boolean | string>;\n\nexport interface Route {\n path: string;\n\n /**\n * Statically available component (already imported)\n */\n component?: string | (() => unknown);\n\n /**\n * Lazy loader that resolves to something renderable\n */\n load?: () => Promise<{\n default: string | HTMLElement | ((...args: unknown[]) => unknown);\n }>;\n\n /**\n * Runs before matching — return false to cancel,\n * or a string to redirect\n */\n beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs right before navigation commits — can cancel or redirect\n */\n onEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs after navigation completes — cannot cancel\n */\n afterEnter?: (to: RouteState, from: RouteState) => void;\n}\n\nexport interface RouterLinkProps {\n to: string;\n tag: string;\n replace: boolean;\n exact: boolean;\n activeClass: string;\n exactActiveClass: string;\n ariaCurrentValue: string;\n disabled: boolean;\n external: boolean;\n class?: string;\n style?: string;\n}\n\nexport interface RouterLinkComputed {\n current: RouteState;\n isExactActive: boolean;\n isActive: boolean;\n className: string;\n ariaCurrent: string;\n isButton: boolean;\n disabledAttr: string;\n externalAttr: string;\n}\n\nexport interface RouterConfig {\n routes: Route[];\n base?: string;\n initialUrl?: string; // For SSR: explicitly pass the URL\n}\n\nexport const parseQuery = (search: string): Record<string, string> => {\n if (!search) return {};\n if (typeof URLSearchParams === 'undefined') return {};\n return Object.fromEntries(new URLSearchParams(search));\n};\n\n// Cache compiled route regexes to avoid rebuilding on every navigation.\ntype CompiledRoute =\n | { regex: RegExp; paramNames: string[] }\n | { invalid: true };\nconst compileCache: WeakMap<Route, CompiledRoute> = new WeakMap();\n\nfunction escapeSeg(seg: string) {\n return seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction normalizePathForRoute(p: string) {\n if (!p) return '/';\n // Collapse duplicate slashes, ensure leading slash, remove trailing slash\n let out = p.replace(/\\/+/g, '/');\n if (!out.startsWith('/')) out = '/' + out;\n if (out.length > 1 && out.endsWith('/')) out = out.slice(0, -1);\n return out;\n}\n\nfunction compileRoute(route: Route): CompiledRoute {\n const raw = route.path || '/';\n const routePath = normalizePathForRoute(raw);\n\n const segments =\n routePath === '/' ? [] : routePath.split('/').filter(Boolean);\n\n const paramNames: string[] = [];\n const regexParts: string[] = [];\n\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i];\n\n // Anonymous wildcard\n if (seg === '*') {\n // splat must be terminal\n if (i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n const name = `splat${paramNames.length}`;\n paramNames.push(name);\n // mark splat token; pattern will be built specially so the\n // preceding slash can be optional (allow empty splat)\n regexParts.push('__SPLAT__');\n continue;\n }\n\n const paramMatch = seg.match(/^:([A-Za-z0-9_-]+)(\\*)?$/);\n if (paramMatch) {\n const name = paramMatch[1];\n const isSplat = !!paramMatch[2];\n // If splat, ensure terminal\n if (isSplat && i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a splat param ':${name}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n paramNames.push(name);\n regexParts.push(isSplat ? '__SPLAT__' : '([^/]+)');\n continue;\n }\n\n // Static\n regexParts.push(escapeSeg(seg));\n }\n\n let pattern: string;\n if (regexParts.length === 0) {\n pattern = '^/$';\n } else {\n const last = regexParts[regexParts.length - 1];\n if (last === '__SPLAT__') {\n const prefix = regexParts.slice(0, -1).join('/');\n if (!prefix) {\n // route is like '/:rest*' or '/*' -> allow '/' or '/x' etc.\n pattern = '^(?:/(.*))?(?:/)?$';\n } else {\n pattern = `^/${prefix}(?:/(.*))?(?:/)?$`;\n }\n } else {\n pattern = `^/${regexParts.join('/')}(?:/)?$`;\n }\n }\n try {\n const regex = new RegExp(pattern);\n return { regex, paramNames };\n } catch (e) {\n devWarn(`Failed to compile route regex for '${route.path}': ${String(e)}`);\n return { invalid: true };\n }\n}\n\nexport const matchRoute = (\n routes: Route[],\n path: string,\n): { route: Route | null; params: Record<string, string> } => {\n const incoming = normalizePathForRoute(path);\n\n for (const route of routes) {\n let compiled = compileCache.get(route);\n if (!compiled) {\n compiled = compileRoute(route);\n compileCache.set(route, compiled);\n }\n\n if ((compiled as { invalid?: true }).invalid) continue;\n\n const { regex, paramNames } = compiled as {\n regex: RegExp;\n paramNames: string[];\n };\n const m = regex.exec(incoming);\n if (m) {\n const params: Record<string, string> = {};\n const safeDecode = (v: string) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n };\n\n for (let i = 0; i < paramNames.length; i++) {\n const raw = m[i + 1] || '';\n params[paramNames[i]] = raw ? safeDecode(raw) : '';\n }\n\n return { route, params };\n }\n }\n\n return { route: null, params: {} };\n};\n\n/**\n * Find the first route that matches the given path.\n * Consolidates repeated inline checks like `routes.find(r => matchRoute([r], path).route !== null)`\n */\nfunction findMatchedRoute(routes: Route[], path: string): Route | null {\n for (const r of routes) {\n if (matchRoute([r], path).route !== null) return r;\n }\n return null;\n}\n\n// Async component loader cache\nconst componentCache: Record<\n string,\n string | HTMLElement | ((...args: unknown[]) => unknown)\n> = {};\n\n/**\n * Loads a route's component, supporting both static and async.\n * @param route Route object\n * @returns Promise resolving to the component\n */\nexport async function resolveRouteComponent(\n route: Route,\n): Promise<string | HTMLElement | ((...args: unknown[]) => unknown)> {\n if (route.component) return route.component;\n if (route.load) {\n if (componentCache[route.path]) return componentCache[route.path];\n try {\n const mod = await route.load();\n componentCache[route.path] = mod.default;\n return mod.default;\n } catch {\n throw new Error(`Failed to load component for route: ${route.path}`);\n }\n }\n throw new Error(`No component or loader defined for route: ${route.path}`);\n}\n\nexport function useRouter(config: RouterConfig) {\n const { routes, base = '', initialUrl } = config;\n\n let getLocation: () => { path: string; query: Record<string, string> };\n let initial: { path: string; query: Record<string, string> };\n let store: Store<RouteState>;\n let update: (replace?: boolean) => Promise<void>;\n let push: (path: string) => Promise<void>;\n let replaceFn: (path: string) => Promise<void>;\n let back: () => void;\n\n // Run matching route guards/hooks\n const runBeforeEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.beforeEnter) return true;\n try {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('beforeEnter error', err);\n return false;\n }\n };\n\n const runOnEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.onEnter) return true;\n try {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('onEnter error', err);\n return false;\n }\n };\n\n const runAfterEnter = (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.afterEnter) return;\n try {\n matched.afterEnter(to, from);\n } catch (err) {\n devError('afterEnter error', err);\n }\n };\n\n const navigate = async (path: string, replace = false) => {\n try {\n const loc = {\n path: path.replace(base, '') || '/',\n query: {},\n };\n const match = matchRoute(routes, loc.path);\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n };\n\n // beforeEnter guard\n const allowedBefore = await runBeforeEnter(to, from);\n if (!allowedBefore) return;\n\n // onEnter guard (right before commit)\n const allowedOn = await runOnEnter(to, from);\n if (!allowedOn) return;\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (replace) {\n window.history.replaceState({}, '', base + path);\n } else {\n window.history.pushState({}, '', base + path);\n }\n }\n\n store.setState(to);\n\n // afterEnter hook (post commit)\n runAfterEnter(to, from);\n } catch (err) {\n devError('Navigation error:', err);\n }\n };\n\n // If an explicit `initialUrl` is provided we treat this as SSR/static rendering\n // even if a `window` exists (useful for hydration tests). Browser mode only\n // applies when `initialUrl` is undefined.\n if (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof initialUrl === 'undefined'\n ) {\n // Browser mode\n getLocation = () => {\n const url = new URL(window.location.href);\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n return { path, query };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n });\n\n update = async (replace = false) => {\n const loc = getLocation();\n await navigate(loc.path, replace);\n };\n\n window.addEventListener('popstate', () => update(true));\n\n push = (path: string) => navigate(path, false);\n replaceFn = (path: string) => navigate(path, true);\n back = () => window.history.back();\n } else {\n // SSR mode\n getLocation = () => {\n const url = new URL(initialUrl || '/', 'http://localhost');\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n return { path, query };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n });\n\n update = async () => {\n const loc = getLocation();\n await navigateSSR(loc.path);\n };\n\n // SSR navigation contract:\n // - `push` / `replace` call into `navigateSSR` and return a Promise.\n // - On the server we intentionally surface navigation failures so\n // server-side logic (or tests) can react: missing routes or thrown\n // errors from `beforeEnter`/`onEnter` will cause the Promise to\n // reject. This lets the server render 404s or abort builds.\n // - For valid routes the server-side navigation resolves and updates\n // the internal store state so rendered output matches the target\n // path. The `back()` operation is client-only and is a synchronous\n // no-op in SSR mode.\n const navigateSSR = async (path: string) => {\n try {\n const loc = {\n path: path.replace(base, '') || '/',\n query: {},\n };\n const match = matchRoute(routes, loc.path);\n // In SSR mode we intentionally surface navigation errors (missing\n // route) to the caller so server-side logic may handle them. If no\n // route matches, throw and let the caller observe the rejection.\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n };\n\n // beforeEnter guard\n const matched = findMatchedRoute(routes, to.path);\n if (matched?.beforeEnter) {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n // onEnter guard\n if (matched?.onEnter) {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n store.setState(to);\n\n // afterEnter hook\n if (matched?.afterEnter) {\n matched.afterEnter(to, from);\n }\n } catch (err) {\n // Surface SSR navigation errors so callers (and tests) can observe\n // failures during server-side resolution.\n devError('SSR navigation error:', err);\n throw err;\n }\n };\n\n push = async (path: string) => navigateSSR(path);\n replaceFn = async (path: string) => navigateSSR(path);\n back = () => {};\n }\n\n return {\n store,\n push,\n replace: replaceFn,\n back,\n subscribe: store.subscribe,\n matchRoute: (path: string) => matchRoute(routes, path),\n getCurrent: (): RouteState => store.getState(),\n resolveRouteComponent,\n };\n}\n\n// SSR/static site support: match route for a given path\nexport function matchRouteSSR(routes: Route[], path: string) {\n return matchRoute(routes, path);\n}\n\n// Module-level reference to the latest initialized router. Tests and\n// components may rely on re-initializing the router during their setup,\n// so exposing this lets components pick up the most recent instance.\nlet activeRouter: ReturnType<typeof useRouter> | null = null;\n\n/**\n * Singleton router instance for global access.\n *\n * Define here to prevent circular dependency\n * issue with component.\n */\n\nexport function initRouter(config: RouterConfig) {\n const router = useRouter(config);\n // Expose the most recently initialized router to components defined\n // earlier in the process (tests may call initRouter multiple times).\n // Components reference `activeRouter` so re-calling initRouter updates\n // the router instance they use.\n activeRouter = router;\n\n component('router-view', async () => {\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current route so the component re-renders when router updates\n if (!r) return html`<div>Router not initialized.</div>`;\n\n const current = ref(r.getCurrent());\n\n // We'll capture the unsubscribe function when the component connects\n // and register a disconnect cleanup during render-time (useOnDisconnected\n // must be called during the component render/execution).\n let unsubRouterView: (() => void) | undefined;\n\n useOnConnected(() => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterView = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-view subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-view subscribe failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterView === 'function') {\n try {\n unsubRouterView();\n } catch (e) {\n devWarn('router-view unsubscribe failed', e);\n }\n }\n });\n\n const match = r.matchRoute(current.value.path);\n if (!match || !match.route) return html`<div>Not found</div>`;\n\n // Resolve the component (supports cached async loaders)\n try {\n const compRaw = await r.resolveRouteComponent(match.route);\n const comp = compRaw as\n | string\n | HTMLElement\n | ((...args: unknown[]) => unknown)\n | undefined;\n // String tag (custom element) -> render as VNode\n if (typeof comp === 'string') {\n return { tag: comp, props: {}, children: [] };\n }\n\n // Function component (sync or async) -> call and return its VNode(s)\n if (typeof comp === 'function') {\n const out = comp();\n const resolved = out instanceof Promise ? out : Promise.resolve(out);\n return resolved.then((resolvedComp) => {\n if (typeof resolvedComp === 'string')\n return { tag: resolvedComp, props: {}, children: [] };\n return resolvedComp;\n });\n }\n\n return html`<div>Invalid route component</div>`;\n } catch {\n return html`<div>Invalid route component</div>`;\n }\n });\n\n component('router-link', () => {\n // Declare props via useProps so observedAttributes are correct\n const props = useProps<Partial<RouterLinkProps>>({\n to: '',\n tag: 'a',\n replace: false,\n exact: false,\n activeClass: 'active',\n exactActiveClass: 'exact-active',\n ariaCurrentValue: 'page',\n disabled: false,\n external: false,\n // allow host `class` and `style` attributes to be read via useProps\n class: '',\n style: '',\n });\n\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current state so link updates when route changes\n const current = ref(r.getCurrent());\n // Capture unsubscribe for link subscriptions and register disconnect\n // cleanup during render time.\n let unsubRouterLink: (() => void) | undefined;\n\n // Keep a minimal internal host-scoped style for element display.\n // Host `style` will be applied to the inner anchor/button element.\n useStyle(() => `a,button{display:inline-block;}`);\n\n // We capture host attributes at connection time and migrate them to\n // internal refs so we can remove them from the host. This prevents\n // global/author CSS targeting the host from styling the host element\n // itself while still allowing authors to use `class`/`style` on the\n // router-link to style the inner anchor/button.\n const hostClassRef = ref((props.class as string) || '');\n const hostStyleRef = ref((props.style as string) || '');\n\n useOnConnected((ctx?: unknown) => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterLink = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-link subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-link subscribe failed', e);\n }\n\n // Migrate host `class`/`style` into internal refs and remove them\n // from the host so only the inner element is styled.\n try {\n const host = (ctx as { _host?: HTMLElement } | undefined)?._host;\n if (host instanceof HTMLElement) {\n const hc = host.getAttribute('class');\n const hs = host.getAttribute('style');\n if (hc) hostClassRef.value = hc;\n if (hs) hostStyleRef.value = hs;\n // Remove attributes from host to avoid styling the host\n if (hc !== null) host.removeAttribute('class');\n if (hs !== null) host.removeAttribute('style');\n }\n } catch (e) {\n devWarn('router-link host migration failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterLink === 'function') {\n try {\n unsubRouterLink();\n } catch (e) {\n devWarn('router-link unsubscribe failed', e);\n }\n }\n });\n\n const isExactActive = computed(\n () => current.value.path === (props.to as string),\n );\n const isActive = computed(() =>\n props.exact\n ? isExactActive.value\n : current.value && typeof current.value.path === 'string'\n ? current.value.path.startsWith(props.to as string)\n : false,\n );\n\n // Build user classes reactively from the host `class` attribute prop.\n // We intentionally apply classes to the inner element so the consumer\n // can style the link via `class=\"...\"`.\n const userClasses = computed(() => {\n const rawHost =\n (hostClassRef && hostClassRef.value) || (props.class as string) || '';\n const list = rawHost.split(/\\s+/).filter(Boolean);\n const map: Record<string, boolean> = {};\n for (const c of list) map[c] = true;\n return map;\n });\n\n const classObject = computed(() => ({\n ...userClasses.value,\n [(props.activeClass as string) || 'active']: isActive.value,\n [(props.exactActiveClass as string) || 'exact-active']:\n isExactActive.value,\n }));\n\n // Compute a final class string (template accepts object or string; we\n // convert to string to safely include host classes and conditionals).\n const classString = computed(() =>\n Object.keys(classObject.value)\n .filter((k) => classObject.value[k])\n .join(' '),\n );\n\n const isButton = computed(() => (props.tag as string) === 'button');\n // Instead of pre-building attribute fragments as strings (which can\n // accidentally inject invalid attribute names into the template and\n // cause DOMExceptions), compute simple booleans/values and apply\n // attributes explicitly in the template below.\n const ariaCurrentValue = computed(() =>\n isExactActive.value ? (props.ariaCurrentValue as string) : '',\n );\n const isDisabled = computed(() => !!props.disabled);\n const isExternal = computed(\n () =>\n !!props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string)),\n );\n\n // Inline style from host `style` attribute.\n const inlineStyle = computed(\n () =>\n (hostStyleRef && hostStyleRef.value) || (props.style as string) || '',\n );\n\n const navigate = (e: MouseEvent) => {\n if (props.disabled) {\n e.preventDefault();\n return;\n }\n if (\n props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string))\n ) {\n return;\n }\n e.preventDefault();\n if (props.replace) {\n r.replace(props.to as string);\n } else {\n r.push(props.to as string);\n }\n };\n\n return html`\n ${match()\n .when(\n isButton.value,\n html`\n <button\n part=\"button\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n disabled=\"${isDisabled.value ? '' : null}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n @click=\"${navigate}\"\n >\n <slot></slot>\n </button>\n `,\n )\n .otherwise(html`\n <a\n part=\"link\"\n href=\"${props.to}\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n target=\"${isExternal.value ? '_blank' : null}\"\n rel=\"${isExternal.value ? 'noopener noreferrer' : null}\"\n @click=\"${navigate}\"\n ><slot></slot\n ></a>\n `)\n .done()}\n `;\n });\n\n return router;\n}\n"],"names":["parseQuery","search","compileCache","escapeSeg","seg","normalizePathForRoute","p","out","compileRoute","route","raw","routePath","segments","paramNames","regexParts","devWarn","name","paramMatch","isSplat","pattern","prefix","e","matchRoute","routes","path","incoming","compiled","regex","m","params","safeDecode","v","i","findMatchedRoute","r","componentCache","resolveRouteComponent","mod","useRouter","config","base","initialUrl","getLocation","initial","store","update","push","replaceFn","back","runBeforeEnter","to","from","matched","result","navigate","err","devError","runOnEnter","runAfterEnter","replace","loc","match","url","query","createStore","navigateSSR","matchRouteSSR","activeRouter","initRouter","router","component","html","current","ref","unsubRouterView","useOnConnected","s","useOnDisconnected","comp","resolvedComp","props","useProps","unsubRouterLink","useStyle","hostClassRef","hostStyleRef","ctx","host","hc","hs","isExactActive","computed","isActive","userClasses","list","map","c","classObject","classString","k","isButton","ariaCurrentValue","isDisabled","isExternal","inlineStyle"],"mappings":"kUAwFaA,EAAcC,GACpBA,EACD,OAA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AO,CAAEA,EAAM,IAAA,EAIxCwB,EAAcb,EAAAA,SAClB,IACGN,GAAgBA,EAAa,OAAWL,EAAM,OAAoB,EAAA,EAGjE1B,EAAYjC,GAAkB,CAClC,GAAI2D,EAAM,SAAU,CAClB3D,EAAE,eAAA,EACF,MACF,CAEE2D,EAAM,WACJA,EAAM,MAAmB,KAAO,CAAEA,EAAM,OAI5C3D,EAAE,eAAA,EACE2D,EAAM,QACR9C,EAAE,QAAQ8C,EAAM,EAAY,EAE5B9C,EAAE,KAAK8C,EAAM,EAAY,EAE7B,EAEA,OAAOT,EAAAA;AAAAA,QACHV,EAAAA,QACC,KACCuC,EAAS,MACT7B,EAAAA;AAAAA;AAAAA;AAAAA,uBAGa2B,EAAY,KAAK;AAAA,uBACjBM,EAAY,OAAS,IAAI;AAAA,8BAClBH,EAAiB,KAAK;AAAA,0BAC1BC,EAAW,MAAQ,GAAK,IAAI;AAAA,+BACvBA,EAAW,MAAQ,OAAS,IAAI;AAAA,0BACrCA,EAAW,MAAQ,KAAO,IAAI;AAAA,wBAChChD,CAAQ;AAAA;AAAA;AAAA;AAAA,WAAA,EAMvB,UAAUiB,EAAAA;AAAAA;AAAAA;AAAAA,oBAGCS,EAAM,EAAE;AAAA,qBACPkB,EAAY,KAAK;AAAA,qBACjBM,EAAY,OAAS,IAAI;AAAA,4BAClBH,EAAiB,KAAK;AAAA,6BACrBC,EAAW,MAAQ,OAAS,IAAI;AAAA,wBACrCA,EAAW,MAAQ,KAAO,IAAI;AAAA,sBAChCC,EAAW,MAAQ,SAAW,IAAI;AAAA,mBACrCA,EAAW,MAAQ,sBAAwB,IAAI;AAAA,sBAC5CjD,CAAQ;AAAA;AAAA;AAAA,SAGrB,EACA,MAAM;AAAA,KAEb,CAAC,EAEMe,CACT"}
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.router.cjs.js","sources":["../src/lib/router.ts"],"sourcesContent":["import { html } from './runtime/template-compiler';\nimport { component } from './runtime/component';\nimport {\n useProps,\n useOnConnected,\n useOnDisconnected,\n useStyle,\n} from './runtime/hooks';\nimport { ref, computed } from './runtime/reactive';\nimport { createStore, type Store } from './store';\nimport { devError, devWarn } from './runtime/logger';\nimport { match } from './directives';\n\nexport type RouteComponent =\n | { new (...args: unknown[]): unknown } // class components\n | ((...args: unknown[]) => unknown); // functional components\n\nexport interface RouteState {\n path: string;\n params: Record<string, string>;\n query: Record<string, string>;\n // Optional fragment (hash) portion of the URL, without the leading '#'\n fragment?: string;\n}\n\nexport type GuardResult = boolean | string | Promise<boolean | string>;\n\nexport interface Route {\n path: string;\n\n /**\n * Statically available component (already imported)\n */\n component?: string | (() => unknown);\n\n /**\n * Lazy loader that resolves to something renderable\n */\n load?: () => Promise<{\n default: string | HTMLElement | ((...args: unknown[]) => unknown);\n }>;\n\n /**\n * Runs before matching — return false to cancel,\n * or a string to redirect\n */\n beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs right before navigation commits — can cancel or redirect\n */\n onEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs after navigation completes — cannot cancel\n */\n afterEnter?: (to: RouteState, from: RouteState) => void;\n}\n\nexport interface RouterLinkProps {\n to: string;\n tag: string;\n replace: boolean;\n exact: boolean;\n activeClass: string;\n exactActiveClass: string;\n ariaCurrentValue: string;\n disabled: boolean;\n external: boolean;\n class?: string;\n style?: string;\n}\n\nexport interface RouterLinkComputed {\n current: RouteState;\n isExactActive: boolean;\n isActive: boolean;\n className: string;\n ariaCurrent: string;\n isButton: boolean;\n disabledAttr: string;\n externalAttr: string;\n}\n\nexport interface RouterConfig {\n routes: Route[];\n base?: string;\n initialUrl?: string; // For SSR: explicitly pass the URL\n}\n\nexport const parseQuery = (search: string): Record<string, string> => {\n if (!search) return {};\n if (typeof URLSearchParams === 'undefined') return {};\n return Object.fromEntries(new URLSearchParams(search));\n};\n\n// Cache compiled route regexes to avoid rebuilding on every navigation.\ntype CompiledRoute =\n | { regex: RegExp; paramNames: string[] }\n | { invalid: true };\nconst compileCache: WeakMap<Route, CompiledRoute> = new WeakMap();\n\nfunction escapeSeg(seg: string) {\n return seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function normalizePathForRoute(p: string) {\n if (!p) return '/';\n // Collapse duplicate slashes, ensure leading slash, remove trailing slash\n let out = p.replace(/\\/+/g, '/');\n if (!out.startsWith('/')) out = '/' + out;\n if (out.length > 1 && out.endsWith('/')) out = out.slice(0, -1);\n return out;\n}\n\nfunction compileRoute(route: Route): CompiledRoute {\n const raw = route.path || '/';\n const routePath = normalizePathForRoute(raw);\n\n const segments =\n routePath === '/' ? [] : routePath.split('/').filter(Boolean);\n\n const paramNames: string[] = [];\n const regexParts: string[] = [];\n\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i];\n\n // Anonymous wildcard\n if (seg === '*') {\n // splat must be terminal\n if (i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n const name = `splat${paramNames.length}`;\n paramNames.push(name);\n // mark splat token; pattern will be built specially so the\n // preceding slash can be optional (allow empty splat)\n regexParts.push('__SPLAT__');\n continue;\n }\n\n const paramMatch = seg.match(/^:([A-Za-z0-9_-]+)(\\*)?$/);\n if (paramMatch) {\n const name = paramMatch[1];\n const isSplat = !!paramMatch[2];\n // If splat, ensure terminal\n if (isSplat && i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a splat param ':${name}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n paramNames.push(name);\n regexParts.push(isSplat ? '__SPLAT__' : '([^/]+)');\n continue;\n }\n\n // Static\n regexParts.push(escapeSeg(seg));\n }\n\n let pattern: string;\n if (regexParts.length === 0) {\n pattern = '^/$';\n } else {\n const last = regexParts[regexParts.length - 1];\n if (last === '__SPLAT__') {\n const prefix = regexParts.slice(0, -1).join('/');\n if (!prefix) {\n // route is like '/:rest*' or '/*' -> allow '/' or '/x' etc.\n pattern = '^(?:/(.*))?(?:/)?$';\n } else {\n pattern = `^/${prefix}(?:/(.*))?(?:/)?$`;\n }\n } else {\n pattern = `^/${regexParts.join('/')}(?:/)?$`;\n }\n }\n try {\n const regex = new RegExp(pattern);\n return { regex, paramNames };\n } catch (e) {\n devWarn(`Failed to compile route regex for '${route.path}': ${String(e)}`);\n return { invalid: true };\n }\n}\n\nexport const matchRoute = (\n routes: Route[],\n path: string,\n): { route: Route | null; params: Record<string, string> } => {\n const incoming = normalizePathForRoute(path);\n\n for (const route of routes) {\n let compiled = compileCache.get(route);\n if (!compiled) {\n compiled = compileRoute(route);\n compileCache.set(route, compiled);\n }\n\n if ((compiled as { invalid?: true }).invalid) continue;\n\n const { regex, paramNames } = compiled as {\n regex: RegExp;\n paramNames: string[];\n };\n const m = regex.exec(incoming);\n if (m) {\n const params: Record<string, string> = {};\n const safeDecode = (v: string) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n };\n\n for (let i = 0; i < paramNames.length; i++) {\n const raw = m[i + 1] || '';\n params[paramNames[i]] = raw ? safeDecode(raw) : '';\n }\n\n return { route, params };\n }\n }\n\n return { route: null, params: {} };\n};\n\n/**\n * Find the first route that matches the given path.\n * Consolidates repeated inline checks like `routes.find(r => matchRoute([r], path).route !== null)`\n */\nfunction findMatchedRoute(routes: Route[], path: string): Route | null {\n for (const r of routes) {\n if (matchRoute([r], path).route !== null) return r;\n }\n return null;\n}\n\n// Async component loader cache\nconst componentCache: Record<\n string,\n string | HTMLElement | ((...args: unknown[]) => unknown)\n> = {};\n\n/**\n * Loads a route's component, supporting both static and async.\n * @param route Route object\n * @returns Promise resolving to the component\n */\nexport async function resolveRouteComponent(\n route: Route,\n): Promise<string | HTMLElement | ((...args: unknown[]) => unknown)> {\n if (route.component) return route.component;\n if (route.load) {\n if (componentCache[route.path]) return componentCache[route.path];\n try {\n const mod = await route.load();\n componentCache[route.path] = mod.default;\n return mod.default;\n } catch {\n throw new Error(`Failed to load component for route: ${route.path}`);\n }\n }\n throw new Error(`No component or loader defined for route: ${route.path}`);\n}\n\nexport function useRouter(config: RouterConfig) {\n const { routes, base = '', initialUrl } = config;\n\n let getLocation: () => { path: string; query: Record<string, string> };\n let initial: { path: string; query: Record<string, string> };\n let store: Store<RouteState>;\n let update: (replace?: boolean) => Promise<void>;\n let push: (path: string) => Promise<void>;\n let replaceFn: (path: string) => Promise<void>;\n let back: () => void;\n\n // Run matching route guards/hooks\n const runBeforeEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.beforeEnter) return true;\n try {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('beforeEnter error', err);\n return false;\n }\n };\n\n const runOnEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.onEnter) return true;\n try {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('onEnter error', err);\n return false;\n }\n };\n\n const runAfterEnter = (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.afterEnter) return;\n try {\n matched.afterEnter(to, from);\n } catch (err) {\n devError('afterEnter error', err);\n }\n };\n\n const navigate = async (path: string, replace = false) => {\n try {\n // Separate fragment (hash) from path so matching ignores it while\n // the fragment is preserved on the RouteState.\n const hashIndex = path.indexOf('#');\n const fragment = hashIndex >= 0 ? path.slice(hashIndex + 1) : '';\n const rawPath = hashIndex >= 0 ? path.slice(0, hashIndex) : path;\n const loc = {\n path: rawPath.replace(base, '') || '/',\n query: {},\n fragment,\n };\n const match = matchRoute(routes, loc.path);\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n fragment: (loc as { fragment?: string }).fragment,\n };\n\n // beforeEnter guard\n const allowedBefore = await runBeforeEnter(to, from);\n if (!allowedBefore) return;\n\n // onEnter guard (right before commit)\n const allowedOn = await runOnEnter(to, from);\n if (!allowedOn) return;\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (replace) {\n window.history.replaceState({}, '', base + path);\n } else {\n window.history.pushState({}, '', base + path);\n }\n }\n\n store.setState(to);\n\n // afterEnter hook (post commit)\n runAfterEnter(to, from);\n } catch (err) {\n devError('Navigation error:', err);\n }\n };\n\n // If an explicit `initialUrl` is provided we treat this as SSR/static rendering\n // even if a `window` exists (useful for hydration tests). Browser mode only\n // applies when `initialUrl` is undefined.\n if (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof initialUrl === 'undefined'\n ) {\n // Browser mode\n getLocation = () => {\n const url = new URL(window.location.href);\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n const fragment = url.hash && url.hash.length ? url.hash.slice(1) : '';\n return { path, query, fragment };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n fragment: (initial as { fragment?: string }).fragment,\n });\n\n update = async (replace = false) => {\n const loc = getLocation();\n await navigate(loc.path, replace);\n };\n\n window.addEventListener('popstate', () => update(true));\n\n push = (path: string) => navigate(path, false);\n replaceFn = (path: string) => navigate(path, true);\n back = () => window.history.back();\n } else {\n // SSR mode\n getLocation = () => {\n const url = new URL(initialUrl || '/', 'http://localhost');\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n const fragment = url.hash && url.hash.length ? url.hash.slice(1) : '';\n return { path, query, fragment };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n fragment: (initial as { fragment?: string }).fragment,\n });\n\n update = async () => {\n const loc = getLocation();\n await navigateSSR(loc.path);\n };\n\n // SSR navigation contract:\n // - `push` / `replace` call into `navigateSSR` and return a Promise.\n // - On the server we intentionally surface navigation failures so\n // server-side logic (or tests) can react: missing routes or thrown\n // errors from `beforeEnter`/`onEnter` will cause the Promise to\n // reject. This lets the server render 404s or abort builds.\n // - For valid routes the server-side navigation resolves and updates\n // the internal store state so rendered output matches the target\n // path. The `back()` operation is client-only and is a synchronous\n // no-op in SSR mode.\n const navigateSSR = async (path: string) => {\n try {\n const hashIndex = path.indexOf('#');\n const fragment = hashIndex >= 0 ? path.slice(hashIndex + 1) : '';\n const rawPath = hashIndex >= 0 ? path.slice(0, hashIndex) : path;\n const loc = {\n path: rawPath.replace(base, '') || '/',\n query: {},\n fragment,\n };\n const match = matchRoute(routes, loc.path);\n // In SSR mode we intentionally surface navigation errors (missing\n // route) to the caller so server-side logic may handle them. If no\n // route matches, throw and let the caller observe the rejection.\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n fragment: (loc as { fragment?: string }).fragment,\n };\n\n // beforeEnter guard\n const matched = findMatchedRoute(routes, to.path);\n if (matched?.beforeEnter) {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n // onEnter guard\n if (matched?.onEnter) {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n store.setState(to);\n\n // afterEnter hook\n if (matched?.afterEnter) {\n matched.afterEnter(to, from);\n }\n } catch (err) {\n // Surface SSR navigation errors so callers (and tests) can observe\n // failures during server-side resolution.\n devError('SSR navigation error:', err);\n throw err;\n }\n };\n\n push = async (path: string) => navigateSSR(path);\n replaceFn = async (path: string) => navigateSSR(path);\n back = () => {};\n }\n\n return {\n store,\n push,\n replace: replaceFn,\n back,\n subscribe: store.subscribe,\n matchRoute: (path: string) => matchRoute(routes, path),\n getCurrent: (): RouteState => store.getState(),\n resolveRouteComponent,\n };\n}\n\n// SSR/static site support: match route for a given path\nexport function matchRouteSSR(routes: Route[], path: string) {\n return matchRoute(routes, path);\n}\n\n// Module-level reference to the latest initialized router. Tests and\n// components may rely on re-initializing the router during their setup,\n// so exposing this lets components pick up the most recent instance.\nlet activeRouter: ReturnType<typeof useRouter> | null = null;\n\n/**\n * Singleton router instance for global access.\n *\n * Define here to prevent circular dependency\n * issue with component.\n */\n\nexport function initRouter(config: RouterConfig) {\n const router = useRouter(config);\n // Expose the most recently initialized router to components defined\n // earlier in the process (tests may call initRouter multiple times).\n // Components reference `activeRouter` so re-calling initRouter updates\n // the router instance they use.\n activeRouter = router;\n\n component('router-view', async () => {\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current route so the component re-renders when router updates\n if (!r) return html`<div>Router not initialized.</div>`;\n\n const current = ref(r.getCurrent());\n\n // We'll capture the unsubscribe function when the component connects\n // and register a disconnect cleanup during render-time (useOnDisconnected\n // must be called during the component render/execution).\n let unsubRouterView: (() => void) | undefined;\n\n useOnConnected(() => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterView = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-view subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-view subscribe failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterView === 'function') {\n try {\n unsubRouterView();\n } catch (e) {\n devWarn('router-view unsubscribe failed', e);\n }\n }\n });\n\n const match = r.matchRoute(current.value.path);\n if (!match || !match.route) return html`<div>Not found</div>`;\n\n // Resolve the component (supports cached async loaders)\n try {\n const compRaw = await r.resolveRouteComponent(match.route);\n const comp = compRaw as\n | string\n | HTMLElement\n | ((...args: unknown[]) => unknown)\n | undefined;\n // String tag (custom element) -> render as VNode\n if (typeof comp === 'string') {\n return { tag: comp, props: {}, children: [] };\n }\n\n // Function component (sync or async) -> call and return its VNode(s)\n if (typeof comp === 'function') {\n const out = comp();\n const resolved = out instanceof Promise ? out : Promise.resolve(out);\n return resolved.then((resolvedComp) => {\n if (typeof resolvedComp === 'string')\n return { tag: resolvedComp, props: {}, children: [] };\n return resolvedComp;\n });\n }\n\n return html`<div>Invalid route component</div>`;\n } catch {\n return html`<div>Invalid route component</div>`;\n }\n });\n\n component('router-link', () => {\n // Declare props via useProps so observedAttributes are correct\n const props = useProps<Partial<RouterLinkProps>>({\n to: '',\n tag: 'a',\n replace: false,\n exact: false,\n activeClass: 'active',\n exactActiveClass: 'exact-active',\n ariaCurrentValue: 'page',\n disabled: false,\n external: false,\n // allow host `class` and `style` attributes to be read via useProps\n class: '',\n style: '',\n });\n\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current state so link updates when route changes\n const current = ref(r.getCurrent());\n // Capture unsubscribe for link subscriptions and register disconnect\n // cleanup during render time.\n let unsubRouterLink: (() => void) | undefined;\n\n // Keep a minimal internal host-scoped style for element display.\n // Host `style` will be applied to the inner anchor/button element.\n useStyle(() => `a,button{display:inline-block;}`);\n\n // We capture host attributes at connection time and migrate them to\n // internal refs so we can remove them from the host. This prevents\n // global/author CSS targeting the host from styling the host element\n // itself while still allowing authors to use `class`/`style` on the\n // router-link to style the inner anchor/button.\n const hostClassRef = ref((props.class as string) || '');\n const hostStyleRef = ref((props.style as string) || '');\n\n useOnConnected((ctx?: unknown) => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterLink = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-link subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-link subscribe failed', e);\n }\n\n // Migrate host `class`/`style` into internal refs and remove them\n // from the host so only the inner element is styled.\n try {\n const host = (ctx as { _host?: HTMLElement } | undefined)?._host;\n if (host instanceof HTMLElement) {\n const hc = host.getAttribute('class');\n const hs = host.getAttribute('style');\n if (hc) hostClassRef.value = hc;\n if (hs) hostStyleRef.value = hs;\n // Remove attributes from host to avoid styling the host\n if (hc !== null) host.removeAttribute('class');\n if (hs !== null) host.removeAttribute('style');\n }\n } catch (e) {\n devWarn('router-link host migration failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterLink === 'function') {\n try {\n unsubRouterLink();\n } catch (e) {\n devWarn('router-link unsubscribe failed', e);\n }\n }\n });\n\n const isExactActive = computed(() => {\n const targetRaw = (props.to as string) || '';\n // strip fragment from target when comparing\n const targetPathOnly = targetRaw.split('#')[0];\n try {\n return (\n normalizePathForRoute(current.value.path) ===\n normalizePathForRoute(targetPathOnly)\n );\n } catch {\n return current.value.path === targetPathOnly;\n }\n });\n\n const isActive = computed(() => {\n const targetRaw = (props.to as string) || '';\n const targetPathOnly = targetRaw.split('#')[0];\n if (props.exact) return isExactActive.value;\n try {\n const cur = normalizePathForRoute(current.value.path);\n const tgt = normalizePathForRoute(targetPathOnly);\n return cur.startsWith(tgt);\n } catch {\n return (\n current.value &&\n typeof current.value.path === 'string' &&\n current.value.path.startsWith(targetPathOnly)\n );\n }\n });\n\n // Build user classes reactively from the host `class` attribute prop.\n // We intentionally apply classes to the inner element so the consumer\n // can style the link via `class=\"...\"`.\n const userClasses = computed(() => {\n const rawHost =\n (hostClassRef && hostClassRef.value) || (props.class as string) || '';\n const list = rawHost.split(/\\s+/).filter(Boolean);\n const map: Record<string, boolean> = {};\n for (const c of list) map[c] = true;\n return map;\n });\n\n const classObject = computed(() => ({\n ...userClasses.value,\n [(props.activeClass as string) || 'active']: isActive.value,\n [(props.exactActiveClass as string) || 'exact-active']:\n isExactActive.value,\n }));\n\n // Compute a final class string (template accepts object or string; we\n // convert to string to safely include host classes and conditionals).\n const classString = computed(() =>\n Object.keys(classObject.value)\n .filter((k) => classObject.value[k])\n .join(' '),\n );\n\n const isButton = computed(() => (props.tag as string) === 'button');\n // Instead of pre-building attribute fragments as strings (which can\n // accidentally inject invalid attribute names into the template and\n // cause DOMExceptions), compute simple booleans/values and apply\n // attributes explicitly in the template below.\n const ariaCurrentValue = computed(() =>\n isExactActive.value ? (props.ariaCurrentValue as string) : '',\n );\n const isDisabled = computed(() => !!props.disabled);\n const isExternal = computed(\n () =>\n !!props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string)),\n );\n\n // Inline style from host `style` attribute.\n const inlineStyle = computed(\n () =>\n (hostStyleRef && hostStyleRef.value) || (props.style as string) || '',\n );\n\n const navigate = (e: MouseEvent) => {\n if (props.disabled) {\n e.preventDefault();\n return;\n }\n if (\n props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string))\n ) {\n return;\n }\n e.preventDefault();\n if (props.replace) {\n r.replace(props.to as string);\n } else {\n r.push(props.to as string);\n }\n };\n\n return html`\n ${match()\n .when(\n isButton.value,\n html`\n <button\n part=\"button\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n disabled=\"${isDisabled.value ? '' : null}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n @click=\"${navigate}\"\n >\n <slot></slot>\n </button>\n `,\n )\n .otherwise(html`\n <a\n part=\"link\"\n href=\"${props.to}\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n target=\"${isExternal.value ? '_blank' : null}\"\n rel=\"${isExternal.value ? 'noopener noreferrer' : null}\"\n @click=\"${navigate}\"\n ><slot></slot\n ></a>\n `)\n .done()}\n `;\n });\n\n return router;\n}\n"],"names":["parseQuery","search","compileCache","escapeSeg","seg","normalizePathForRoute","p","out","compileRoute","route","raw","routePath","segments","paramNames","regexParts","i","devWarn","name","paramMatch","isSplat","pattern","prefix","e","matchRoute","routes","path","incoming","compiled","regex","m","params","safeDecode","v","findMatchedRoute","r","componentCache","resolveRouteComponent","mod","useRouter","config","base","initialUrl","getLocation","initial","store","update","push","replaceFn","back","runBeforeEnter","to","from","matched","result","navigate","err","devError","runOnEnter","runAfterEnter","replace","hashIndex","fragment","loc","match","url","query","createStore","navigateSSR","matchRouteSSR","activeRouter","initRouter","router","component","html","current","ref","unsubRouterView","useOnConnected","s","useOnDisconnected","comp","resolvedComp","props","useProps","unsubRouterLink","useStyle","hostClassRef","hostStyleRef","ctx","host","hc","hs","isExactActive","computed","targetPathOnly","isActive","cur","tgt","userClasses","list","map","c","classObject","classString","k","isButton","ariaCurrentValue","isDisabled","isExternal","inlineStyle"],"mappings":"kUA0FaA,EAAcC,GACpBA,EACD,OAAO,gBAAoB,IAAoB,CAAA,EAC5C,OAAO,YAAY,IAAI,gBAAgBA,CAAM,CAAC,EAFjC,CAAA,EAShBC,MAAkD,QAExD,SAASC,EAAUC,EAAa,CAC9B,OAAOA,EAAI,QAAQ,sBAAuB,MAAM,CAClD,CAEO,SAASC,EAAsBC,EAAW,CAC/C,GAAI,CAACA,EAAG,MAAO,IAEf,IAAIC,EAAMD,EAAE,QAAQ,OAAQ,GAAG,EAC/B,OAAKC,EAAI,WAAW,GAAG,MAAS,IAAMA,GAClCA,EAAI,OAAS,GAAKA,EAAI,SAAS,GAAG,IAAGA,EAAMA,EAAI,MAAM,EAAG,EAAE,GACvDA,CACT,CAEA,SAASC,EAAaC,EAA6B,CACjD,MAAMC,EAAMD,EAAM,MAAQ,IACpBE,EAAYN,EAAsBK,CAAG,EAErCE,EACJD,IAAc,IAAM,CAAA,EAAKA,EAAU,MAAM,GAAG,EAAE,OAAO,OAAO,EAExDE,EAAuB,CAAA,EACvBC,EAAuB,CAAA,EAE7B,QAASC,EAAI,EAAGA,EAAIH,EAAS,OAAQG,IAAK,CACxC,MAAMX,EAAMQ,EAASG,CAAC,EAGtB,GAAIX,IAAQ,IAAK,CAEf,GAAIW,IAAMH,EAAS,OAAS,EAC1BI,OAAAA,EAAAA,QACE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EACA,MAAM;AAAA,KAEb,CAAC,EAEMiB,CACT"}
|
|
@@ -1,267 +1,273 @@
|
|
|
1
|
-
import { component as
|
|
2
|
-
import { r as
|
|
3
|
-
import { createStore as
|
|
4
|
-
import { d as
|
|
5
|
-
import { match as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
1
|
+
import { component as T, html as P, useOnConnected as U, useOnDisconnected as W, useProps as M, useStyle as V } from "./custom-elements-runtime.es.js";
|
|
2
|
+
import { r as O, c as b } from "./namespace-helpers-Dw1mgQab.js";
|
|
3
|
+
import { createStore as D } from "./custom-elements-runtime.store.es.js";
|
|
4
|
+
import { d as A, a as $ } from "./logger-BuUYv7C_.js";
|
|
5
|
+
import { match as z } from "./custom-elements-runtime.directives.es.js";
|
|
6
|
+
const I = (n) => n ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(n)) : {}, F = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function H(n) {
|
|
8
8
|
return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function _(n) {
|
|
11
11
|
if (!n) return "/";
|
|
12
12
|
let r = n.replace(/\/+/g, "/");
|
|
13
13
|
return r.startsWith("/") || (r = "/" + r), r.length > 1 && r.endsWith("/") && (r = r.slice(0, -1)), r;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const r = n.path || "/", t =
|
|
17
|
-
for (let
|
|
18
|
-
const d =
|
|
15
|
+
function Q(n) {
|
|
16
|
+
const r = n.path || "/", t = _(r), h = t === "/" ? [] : t.split("/").filter(Boolean), o = [], s = [];
|
|
17
|
+
for (let u = 0; u < h.length; u++) {
|
|
18
|
+
const d = h[u];
|
|
19
19
|
if (d === "*") {
|
|
20
|
-
if (
|
|
20
|
+
if (u !== h.length - 1)
|
|
21
21
|
return $(
|
|
22
22
|
`Route '${n.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`
|
|
23
23
|
), { invalid: !0 };
|
|
24
|
-
const p = `splat${
|
|
25
|
-
|
|
24
|
+
const p = `splat${o.length}`;
|
|
25
|
+
o.push(p), s.push("__SPLAT__");
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const p =
|
|
31
|
-
if (
|
|
28
|
+
const y = d.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
|
|
29
|
+
if (y) {
|
|
30
|
+
const p = y[1], w = !!y[2];
|
|
31
|
+
if (w && u !== h.length - 1)
|
|
32
32
|
return $(
|
|
33
33
|
`Route '${n.path}' contains a splat param ':${p}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`
|
|
34
34
|
), { invalid: !0 };
|
|
35
|
-
|
|
35
|
+
o.push(p), s.push(w ? "__SPLAT__" : "([^/]+)");
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
s.push(H(d));
|
|
39
39
|
}
|
|
40
|
-
let
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
else if (
|
|
44
|
-
const d =
|
|
45
|
-
d ?
|
|
40
|
+
let c;
|
|
41
|
+
if (s.length === 0)
|
|
42
|
+
c = "^/$";
|
|
43
|
+
else if (s[s.length - 1] === "__SPLAT__") {
|
|
44
|
+
const d = s.slice(0, -1).join("/");
|
|
45
|
+
d ? c = `^/${d}(?:/(.*))?(?:/)?$` : c = "^(?:/(.*))?(?:/)?$";
|
|
46
46
|
} else
|
|
47
|
-
|
|
47
|
+
c = `^/${s.join("/")}(?:/)?$`;
|
|
48
48
|
try {
|
|
49
|
-
return { regex: new RegExp(
|
|
50
|
-
} catch (
|
|
51
|
-
return $(`Failed to compile route regex for '${n.path}': ${String(
|
|
49
|
+
return { regex: new RegExp(c), paramNames: o };
|
|
50
|
+
} catch (u) {
|
|
51
|
+
return $(`Failed to compile route regex for '${n.path}': ${String(u)}`), { invalid: !0 };
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const
|
|
55
|
-
const t =
|
|
56
|
-
for (const
|
|
57
|
-
let
|
|
58
|
-
if (
|
|
59
|
-
const { regex:
|
|
60
|
-
if (
|
|
61
|
-
const d = {},
|
|
54
|
+
const C = (n, r) => {
|
|
55
|
+
const t = _(r);
|
|
56
|
+
for (const h of n) {
|
|
57
|
+
let o = F.get(h);
|
|
58
|
+
if (o || (o = Q(h), F.set(h, o)), o.invalid) continue;
|
|
59
|
+
const { regex: s, paramNames: c } = o, u = s.exec(t);
|
|
60
|
+
if (u) {
|
|
61
|
+
const d = {}, y = (p) => {
|
|
62
62
|
try {
|
|
63
63
|
return decodeURIComponent(p);
|
|
64
64
|
} catch {
|
|
65
65
|
return p;
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
for (let p = 0; p <
|
|
69
|
-
const
|
|
70
|
-
d[
|
|
68
|
+
for (let p = 0; p < c.length; p++) {
|
|
69
|
+
const w = u[p + 1] || "";
|
|
70
|
+
d[c[p]] = w ? y(w) : "";
|
|
71
71
|
}
|
|
72
|
-
return { route:
|
|
72
|
+
return { route: h, params: d };
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return { route: null, params: {} };
|
|
76
76
|
};
|
|
77
|
-
function
|
|
77
|
+
function L(n, r) {
|
|
78
78
|
for (const t of n)
|
|
79
|
-
if (
|
|
79
|
+
if (C([t], r).route !== null) return t;
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
async function
|
|
82
|
+
const j = {};
|
|
83
|
+
async function Z(n) {
|
|
84
84
|
if (n.component) return n.component;
|
|
85
85
|
if (n.load) {
|
|
86
|
-
if (
|
|
86
|
+
if (j[n.path]) return j[n.path];
|
|
87
87
|
try {
|
|
88
88
|
const r = await n.load();
|
|
89
|
-
return
|
|
89
|
+
return j[n.path] = r.default, r.default;
|
|
90
90
|
} catch {
|
|
91
91
|
throw new Error(`Failed to load component for route: ${n.path}`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
throw new Error(`No component or loader defined for route: ${n.path}`);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const { routes: r, base: t = "", initialUrl:
|
|
98
|
-
let
|
|
99
|
-
const
|
|
100
|
-
const e =
|
|
96
|
+
function G(n) {
|
|
97
|
+
const { routes: r, base: t = "", initialUrl: h } = n;
|
|
98
|
+
let o, s, c, u, d, y, p;
|
|
99
|
+
const w = async (f, i) => {
|
|
100
|
+
const e = L(r, f.path);
|
|
101
101
|
if (!e || !e.beforeEnter) return !0;
|
|
102
102
|
try {
|
|
103
|
-
const a = await e.beforeEnter(
|
|
103
|
+
const a = await e.beforeEnter(f, i);
|
|
104
104
|
return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
|
|
105
105
|
} catch (a) {
|
|
106
|
-
return
|
|
106
|
+
return A("beforeEnter error", a), !1;
|
|
107
107
|
}
|
|
108
|
-
},
|
|
109
|
-
const e =
|
|
108
|
+
}, q = async (f, i) => {
|
|
109
|
+
const e = L(r, f.path);
|
|
110
110
|
if (!e || !e.onEnter) return !0;
|
|
111
111
|
try {
|
|
112
|
-
const a = await e.onEnter(
|
|
112
|
+
const a = await e.onEnter(f, i);
|
|
113
113
|
return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
|
|
114
114
|
} catch (a) {
|
|
115
|
-
return
|
|
115
|
+
return A("onEnter error", a), !1;
|
|
116
116
|
}
|
|
117
|
-
},
|
|
118
|
-
const e =
|
|
117
|
+
}, N = (f, i) => {
|
|
118
|
+
const e = L(r, f.path);
|
|
119
119
|
if (!(!e || !e.afterEnter))
|
|
120
120
|
try {
|
|
121
|
-
e.afterEnter(
|
|
121
|
+
e.afterEnter(f, i);
|
|
122
122
|
} catch (a) {
|
|
123
|
-
|
|
123
|
+
A("afterEnter error", a);
|
|
124
124
|
}
|
|
125
|
-
}, R = async (
|
|
125
|
+
}, R = async (f, i = !1) => {
|
|
126
126
|
try {
|
|
127
|
-
const e = {
|
|
128
|
-
path:
|
|
129
|
-
query: {}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
const e = f.indexOf("#"), a = e >= 0 ? f.slice(e + 1) : "", l = {
|
|
128
|
+
path: (e >= 0 ? f.slice(0, e) : f).replace(t, "") || "/",
|
|
129
|
+
query: {},
|
|
130
|
+
fragment: a
|
|
131
|
+
}, m = C(r, l.path);
|
|
132
|
+
if (!m.route) throw new Error(`No route found for ${l.path}`);
|
|
133
|
+
const v = c.getState(), E = {
|
|
134
|
+
path: l.path,
|
|
135
|
+
params: m.params,
|
|
136
|
+
query: l.query,
|
|
137
|
+
fragment: l.fragment
|
|
136
138
|
};
|
|
137
|
-
if (!await
|
|
138
|
-
typeof window < "u" && typeof document < "u" && (
|
|
139
|
+
if (!await w(E, v) || !await q(E, v)) return;
|
|
140
|
+
typeof window < "u" && typeof document < "u" && (i ? window.history.replaceState({}, "", t + f) : window.history.pushState({}, "", t + f)), c.setState(E), N(E, v);
|
|
139
141
|
} catch (e) {
|
|
140
|
-
|
|
142
|
+
A("Navigation error:", e);
|
|
141
143
|
}
|
|
142
144
|
};
|
|
143
|
-
if (typeof window < "u" && typeof document < "u" && typeof
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
return { path: e, query: a };
|
|
147
|
-
},
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
path:
|
|
151
|
-
params:
|
|
152
|
-
query:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
if (typeof window < "u" && typeof document < "u" && typeof h > "u") {
|
|
146
|
+
o = () => {
|
|
147
|
+
const i = new URL(window.location.href), e = i.pathname.replace(t, "") || "/", a = I(i.search), g = i.hash && i.hash.length ? i.hash.slice(1) : "";
|
|
148
|
+
return { path: e, query: a, fragment: g };
|
|
149
|
+
}, s = o();
|
|
150
|
+
const f = C(r, s.path);
|
|
151
|
+
c = D({
|
|
152
|
+
path: s.path,
|
|
153
|
+
params: f.params,
|
|
154
|
+
query: s.query,
|
|
155
|
+
fragment: s.fragment
|
|
156
|
+
}), u = async (i = !1) => {
|
|
157
|
+
const e = o();
|
|
158
|
+
await R(e.path, i);
|
|
159
|
+
}, window.addEventListener("popstate", () => u(!0)), d = (i) => R(i, !1), y = (i) => R(i, !0), p = () => window.history.back();
|
|
157
160
|
} else {
|
|
158
|
-
|
|
159
|
-
const e = new URL(
|
|
160
|
-
return { path: a, query:
|
|
161
|
-
},
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
path:
|
|
165
|
-
params:
|
|
166
|
-
query:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
161
|
+
o = () => {
|
|
162
|
+
const e = new URL(h || "/", "http://localhost"), a = e.pathname.replace(t, "") || "/", g = I(e.search), l = e.hash && e.hash.length ? e.hash.slice(1) : "";
|
|
163
|
+
return { path: a, query: g, fragment: l };
|
|
164
|
+
}, s = o();
|
|
165
|
+
const f = C(r, s.path);
|
|
166
|
+
c = D({
|
|
167
|
+
path: s.path,
|
|
168
|
+
params: f.params,
|
|
169
|
+
query: s.query,
|
|
170
|
+
fragment: s.fragment
|
|
171
|
+
}), u = async () => {
|
|
172
|
+
const e = o();
|
|
173
|
+
await i(e.path);
|
|
170
174
|
};
|
|
171
|
-
const
|
|
175
|
+
const i = async (e) => {
|
|
172
176
|
try {
|
|
173
|
-
const a = {
|
|
174
|
-
path: e.replace(t, "") || "/",
|
|
175
|
-
query: {}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
177
|
+
const a = e.indexOf("#"), g = a >= 0 ? e.slice(a + 1) : "", m = {
|
|
178
|
+
path: (a >= 0 ? e.slice(0, a) : e).replace(t, "") || "/",
|
|
179
|
+
query: {},
|
|
180
|
+
fragment: g
|
|
181
|
+
}, v = C(r, m.path);
|
|
182
|
+
if (!v.route) throw new Error(`No route found for ${m.path}`);
|
|
183
|
+
const E = c.getState(), k = {
|
|
184
|
+
path: m.path,
|
|
185
|
+
params: v.params,
|
|
186
|
+
query: m.query,
|
|
187
|
+
fragment: m.fragment
|
|
188
|
+
}, x = L(r, k.path);
|
|
189
|
+
if (x?.beforeEnter) {
|
|
190
|
+
const S = await x.beforeEnter(k, E);
|
|
191
|
+
if (typeof S == "string") {
|
|
192
|
+
await i(S);
|
|
187
193
|
return;
|
|
188
194
|
}
|
|
189
|
-
if (
|
|
195
|
+
if (S === !1) return;
|
|
190
196
|
}
|
|
191
|
-
if (
|
|
192
|
-
const
|
|
193
|
-
if (typeof
|
|
194
|
-
await
|
|
197
|
+
if (x?.onEnter) {
|
|
198
|
+
const S = await x.onEnter(k, E);
|
|
199
|
+
if (typeof S == "string") {
|
|
200
|
+
await i(S);
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
197
|
-
if (
|
|
203
|
+
if (S === !1) return;
|
|
198
204
|
}
|
|
199
|
-
|
|
205
|
+
c.setState(k), x?.afterEnter && x.afterEnter(k, E);
|
|
200
206
|
} catch (a) {
|
|
201
|
-
throw
|
|
207
|
+
throw A("SSR navigation error:", a), a;
|
|
202
208
|
}
|
|
203
209
|
};
|
|
204
|
-
d = async (e) =>
|
|
210
|
+
d = async (e) => i(e), y = async (e) => i(e), p = () => {
|
|
205
211
|
};
|
|
206
212
|
}
|
|
207
213
|
return {
|
|
208
|
-
store:
|
|
214
|
+
store: c,
|
|
209
215
|
push: d,
|
|
210
|
-
replace:
|
|
216
|
+
replace: y,
|
|
211
217
|
back: p,
|
|
212
|
-
subscribe:
|
|
213
|
-
matchRoute: (
|
|
214
|
-
getCurrent: () =>
|
|
215
|
-
resolveRouteComponent:
|
|
218
|
+
subscribe: c.subscribe,
|
|
219
|
+
matchRoute: (f) => C(r, f),
|
|
220
|
+
getCurrent: () => c.getState(),
|
|
221
|
+
resolveRouteComponent: Z
|
|
216
222
|
};
|
|
217
223
|
}
|
|
218
|
-
function
|
|
219
|
-
return
|
|
224
|
+
function et(n, r) {
|
|
225
|
+
return C(n, r);
|
|
220
226
|
}
|
|
221
|
-
let
|
|
222
|
-
function
|
|
223
|
-
const r =
|
|
224
|
-
return
|
|
225
|
-
const t =
|
|
226
|
-
if (!t) return
|
|
227
|
-
const
|
|
228
|
-
let
|
|
229
|
-
|
|
227
|
+
let B = null;
|
|
228
|
+
function rt(n) {
|
|
229
|
+
const r = G(n);
|
|
230
|
+
return B = r, T("router-view", async () => {
|
|
231
|
+
const t = B || r;
|
|
232
|
+
if (!t) return P`<div>Router not initialized.</div>`;
|
|
233
|
+
const h = O(t.getCurrent());
|
|
234
|
+
let o;
|
|
235
|
+
U(() => {
|
|
230
236
|
try {
|
|
231
|
-
t && typeof t.subscribe == "function" && (
|
|
237
|
+
t && typeof t.subscribe == "function" && (o = t.subscribe((c) => {
|
|
232
238
|
try {
|
|
233
|
-
|
|
234
|
-
} catch (
|
|
235
|
-
$("router-view subscription update failed",
|
|
239
|
+
h.value = c;
|
|
240
|
+
} catch (u) {
|
|
241
|
+
$("router-view subscription update failed", u);
|
|
236
242
|
}
|
|
237
243
|
}));
|
|
238
|
-
} catch (
|
|
239
|
-
$("router-view subscribe failed",
|
|
244
|
+
} catch (c) {
|
|
245
|
+
$("router-view subscribe failed", c);
|
|
240
246
|
}
|
|
241
|
-
}),
|
|
242
|
-
if (typeof
|
|
247
|
+
}), W(() => {
|
|
248
|
+
if (typeof o == "function")
|
|
243
249
|
try {
|
|
244
|
-
|
|
245
|
-
} catch (
|
|
246
|
-
$("router-view unsubscribe failed",
|
|
250
|
+
o();
|
|
251
|
+
} catch (c) {
|
|
252
|
+
$("router-view unsubscribe failed", c);
|
|
247
253
|
}
|
|
248
254
|
});
|
|
249
|
-
const
|
|
250
|
-
if (!
|
|
255
|
+
const s = t.matchRoute(h.value.path);
|
|
256
|
+
if (!s || !s.route) return P`<div>Not found</div>`;
|
|
251
257
|
try {
|
|
252
|
-
const
|
|
253
|
-
if (typeof
|
|
254
|
-
return { tag:
|
|
255
|
-
if (typeof
|
|
256
|
-
const d =
|
|
258
|
+
const u = await t.resolveRouteComponent(s.route);
|
|
259
|
+
if (typeof u == "string")
|
|
260
|
+
return { tag: u, props: {}, children: [] };
|
|
261
|
+
if (typeof u == "function") {
|
|
262
|
+
const d = u();
|
|
257
263
|
return (d instanceof Promise ? d : Promise.resolve(d)).then((p) => typeof p == "string" ? { tag: p, props: {}, children: [] } : p);
|
|
258
264
|
}
|
|
259
|
-
return
|
|
265
|
+
return P`<div>Invalid route component</div>`;
|
|
260
266
|
} catch {
|
|
261
|
-
return
|
|
267
|
+
return P`<div>Invalid route component</div>`;
|
|
262
268
|
}
|
|
263
|
-
}),
|
|
264
|
-
const t =
|
|
269
|
+
}), T("router-link", () => {
|
|
270
|
+
const t = M({
|
|
265
271
|
to: "",
|
|
266
272
|
tag: "a",
|
|
267
273
|
replace: !1,
|
|
@@ -274,94 +280,106 @@ function Y(n) {
|
|
|
274
280
|
// allow host `class` and `style` attributes to be read via useProps
|
|
275
281
|
class: "",
|
|
276
282
|
style: ""
|
|
277
|
-
}),
|
|
278
|
-
let
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
283
|
+
}), h = B || r, o = O(h.getCurrent());
|
|
284
|
+
let s;
|
|
285
|
+
V(() => "a,button{display:inline-block;}");
|
|
286
|
+
const c = O(t.class || ""), u = O(t.style || "");
|
|
287
|
+
U((g) => {
|
|
282
288
|
try {
|
|
283
|
-
|
|
289
|
+
h && typeof h.subscribe == "function" && (s = h.subscribe((l) => {
|
|
284
290
|
try {
|
|
285
|
-
|
|
286
|
-
} catch (
|
|
287
|
-
$("router-link subscription update failed",
|
|
291
|
+
o.value = l;
|
|
292
|
+
} catch (m) {
|
|
293
|
+
$("router-link subscription update failed", m);
|
|
288
294
|
}
|
|
289
295
|
}));
|
|
290
|
-
} catch (
|
|
291
|
-
$("router-link subscribe failed",
|
|
296
|
+
} catch (l) {
|
|
297
|
+
$("router-link subscribe failed", l);
|
|
292
298
|
}
|
|
293
299
|
try {
|
|
294
|
-
const
|
|
295
|
-
if (
|
|
296
|
-
const
|
|
297
|
-
|
|
300
|
+
const l = g?._host;
|
|
301
|
+
if (l instanceof HTMLElement) {
|
|
302
|
+
const m = l.getAttribute("class"), v = l.getAttribute("style");
|
|
303
|
+
m && (c.value = m), v && (u.value = v), m !== null && l.removeAttribute("class"), v !== null && l.removeAttribute("style");
|
|
298
304
|
}
|
|
299
|
-
} catch (
|
|
300
|
-
$("router-link host migration failed",
|
|
305
|
+
} catch (l) {
|
|
306
|
+
$("router-link host migration failed", l);
|
|
301
307
|
}
|
|
302
|
-
}),
|
|
303
|
-
if (typeof
|
|
308
|
+
}), W(() => {
|
|
309
|
+
if (typeof s == "function")
|
|
304
310
|
try {
|
|
305
|
-
|
|
306
|
-
} catch (
|
|
307
|
-
$("router-link unsubscribe failed",
|
|
311
|
+
s();
|
|
312
|
+
} catch (g) {
|
|
313
|
+
$("router-link unsubscribe failed", g);
|
|
308
314
|
}
|
|
309
315
|
});
|
|
310
|
-
const d =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
316
|
+
const d = b(() => {
|
|
317
|
+
const l = (t.to || "").split("#")[0];
|
|
318
|
+
try {
|
|
319
|
+
return _(o.value.path) === _(l);
|
|
320
|
+
} catch {
|
|
321
|
+
return o.value.path === l;
|
|
322
|
+
}
|
|
323
|
+
}), y = b(() => {
|
|
324
|
+
const l = (t.to || "").split("#")[0];
|
|
325
|
+
if (t.exact) return d.value;
|
|
326
|
+
try {
|
|
327
|
+
const m = _(o.value.path), v = _(l);
|
|
328
|
+
return m.startsWith(v);
|
|
329
|
+
} catch {
|
|
330
|
+
return o.value && typeof o.value.path == "string" && o.value.path.startsWith(l);
|
|
331
|
+
}
|
|
332
|
+
}), p = b(() => {
|
|
333
|
+
const l = (c && c.value || t.class || "").split(/\s+/).filter(Boolean), m = {};
|
|
334
|
+
for (const v of l) m[v] = !0;
|
|
335
|
+
return m;
|
|
336
|
+
}), w = b(() => ({
|
|
319
337
|
...p.value,
|
|
320
|
-
[t.activeClass || "active"]:
|
|
338
|
+
[t.activeClass || "active"]: y.value,
|
|
321
339
|
[t.exactActiveClass || "exact-active"]: d.value
|
|
322
|
-
})),
|
|
323
|
-
() => Object.keys(
|
|
324
|
-
),
|
|
340
|
+
})), q = b(
|
|
341
|
+
() => Object.keys(w.value).filter((g) => w.value[g]).join(" ")
|
|
342
|
+
), N = b(() => t.tag === "button"), R = b(
|
|
325
343
|
() => d.value ? t.ariaCurrentValue : ""
|
|
326
|
-
),
|
|
344
|
+
), f = b(() => !!t.disabled), i = b(
|
|
327
345
|
() => !!t.external && (t.tag === "a" || !t.tag)
|
|
328
|
-
), e =
|
|
329
|
-
() =>
|
|
330
|
-
), a = (
|
|
346
|
+
), e = b(
|
|
347
|
+
() => u && u.value || t.style || ""
|
|
348
|
+
), a = (g) => {
|
|
331
349
|
if (t.disabled) {
|
|
332
|
-
|
|
350
|
+
g.preventDefault();
|
|
333
351
|
return;
|
|
334
352
|
}
|
|
335
|
-
t.external && (t.tag === "a" || !t.tag) || (
|
|
353
|
+
t.external && (t.tag === "a" || !t.tag) || (g.preventDefault(), t.replace ? h.replace(t.to) : h.push(t.to));
|
|
336
354
|
};
|
|
337
|
-
return
|
|
338
|
-
${
|
|
339
|
-
|
|
340
|
-
|
|
355
|
+
return P`
|
|
356
|
+
${z().when(
|
|
357
|
+
N.value,
|
|
358
|
+
P`
|
|
341
359
|
<button
|
|
342
360
|
part="button"
|
|
343
|
-
class="${
|
|
361
|
+
class="${q.value}"
|
|
344
362
|
style="${e.value || null}"
|
|
345
363
|
aria-current="${R.value}"
|
|
346
|
-
disabled="${
|
|
347
|
-
aria-disabled="${
|
|
348
|
-
tabindex="${
|
|
364
|
+
disabled="${f.value ? "" : null}"
|
|
365
|
+
aria-disabled="${f.value ? "true" : null}"
|
|
366
|
+
tabindex="${f.value ? "-1" : null}"
|
|
349
367
|
@click="${a}"
|
|
350
368
|
>
|
|
351
369
|
<slot></slot>
|
|
352
370
|
</button>
|
|
353
371
|
`
|
|
354
|
-
).otherwise(
|
|
372
|
+
).otherwise(P`
|
|
355
373
|
<a
|
|
356
374
|
part="link"
|
|
357
375
|
href="${t.to}"
|
|
358
|
-
class="${
|
|
376
|
+
class="${q.value}"
|
|
359
377
|
style="${e.value || null}"
|
|
360
378
|
aria-current="${R.value}"
|
|
361
|
-
aria-disabled="${
|
|
362
|
-
tabindex="${
|
|
363
|
-
target="${
|
|
364
|
-
rel="${
|
|
379
|
+
aria-disabled="${f.value ? "true" : null}"
|
|
380
|
+
tabindex="${f.value ? "-1" : null}"
|
|
381
|
+
target="${i.value ? "_blank" : null}"
|
|
382
|
+
rel="${i.value ? "noopener noreferrer" : null}"
|
|
365
383
|
@click="${a}"
|
|
366
384
|
><slot></slot
|
|
367
385
|
></a>
|
|
@@ -370,11 +388,12 @@ function Y(n) {
|
|
|
370
388
|
}), r;
|
|
371
389
|
}
|
|
372
390
|
export {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
391
|
+
rt as initRouter,
|
|
392
|
+
C as matchRoute,
|
|
393
|
+
et as matchRouteSSR,
|
|
394
|
+
_ as normalizePathForRoute,
|
|
395
|
+
I as parseQuery,
|
|
396
|
+
Z as resolveRouteComponent,
|
|
397
|
+
G as useRouter
|
|
379
398
|
};
|
|
380
399
|
//# sourceMappingURL=custom-elements-runtime.router.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.router.es.js","sources":["../src/lib/router.ts"],"sourcesContent":["import { html } from './runtime/template-compiler';\nimport { component } from './runtime/component';\nimport {\n useProps,\n useOnConnected,\n useOnDisconnected,\n useStyle,\n} from './runtime/hooks';\nimport { ref, computed } from './runtime/reactive';\nimport { createStore, type Store } from './store';\nimport { devError, devWarn } from './runtime/logger';\nimport { match } from './directives';\n\nexport type RouteComponent =\n | { new (...args: unknown[]): unknown } // class components\n | ((...args: unknown[]) => unknown); // functional components\n\nexport interface RouteState {\n path: string;\n params: Record<string, string>;\n query: Record<string, string>;\n}\n\nexport type GuardResult = boolean | string | Promise<boolean | string>;\n\nexport interface Route {\n path: string;\n\n /**\n * Statically available component (already imported)\n */\n component?: string | (() => unknown);\n\n /**\n * Lazy loader that resolves to something renderable\n */\n load?: () => Promise<{\n default: string | HTMLElement | ((...args: unknown[]) => unknown);\n }>;\n\n /**\n * Runs before matching — return false to cancel,\n * or a string to redirect\n */\n beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs right before navigation commits — can cancel or redirect\n */\n onEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs after navigation completes — cannot cancel\n */\n afterEnter?: (to: RouteState, from: RouteState) => void;\n}\n\nexport interface RouterLinkProps {\n to: string;\n tag: string;\n replace: boolean;\n exact: boolean;\n activeClass: string;\n exactActiveClass: string;\n ariaCurrentValue: string;\n disabled: boolean;\n external: boolean;\n class?: string;\n style?: string;\n}\n\nexport interface RouterLinkComputed {\n current: RouteState;\n isExactActive: boolean;\n isActive: boolean;\n className: string;\n ariaCurrent: string;\n isButton: boolean;\n disabledAttr: string;\n externalAttr: string;\n}\n\nexport interface RouterConfig {\n routes: Route[];\n base?: string;\n initialUrl?: string; // For SSR: explicitly pass the URL\n}\n\nexport const parseQuery = (search: string): Record<string, string> => {\n if (!search) return {};\n if (typeof URLSearchParams === 'undefined') return {};\n return Object.fromEntries(new URLSearchParams(search));\n};\n\n// Cache compiled route regexes to avoid rebuilding on every navigation.\ntype CompiledRoute =\n | { regex: RegExp; paramNames: string[] }\n | { invalid: true };\nconst compileCache: WeakMap<Route, CompiledRoute> = new WeakMap();\n\nfunction escapeSeg(seg: string) {\n return seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction normalizePathForRoute(p: string) {\n if (!p) return '/';\n // Collapse duplicate slashes, ensure leading slash, remove trailing slash\n let out = p.replace(/\\/+/g, '/');\n if (!out.startsWith('/')) out = '/' + out;\n if (out.length > 1 && out.endsWith('/')) out = out.slice(0, -1);\n return out;\n}\n\nfunction compileRoute(route: Route): CompiledRoute {\n const raw = route.path || '/';\n const routePath = normalizePathForRoute(raw);\n\n const segments =\n routePath === '/' ? [] : routePath.split('/').filter(Boolean);\n\n const paramNames: string[] = [];\n const regexParts: string[] = [];\n\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i];\n\n // Anonymous wildcard\n if (seg === '*') {\n // splat must be terminal\n if (i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n const name = `splat${paramNames.length}`;\n paramNames.push(name);\n // mark splat token; pattern will be built specially so the\n // preceding slash can be optional (allow empty splat)\n regexParts.push('__SPLAT__');\n continue;\n }\n\n const paramMatch = seg.match(/^:([A-Za-z0-9_-]+)(\\*)?$/);\n if (paramMatch) {\n const name = paramMatch[1];\n const isSplat = !!paramMatch[2];\n // If splat, ensure terminal\n if (isSplat && i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a splat param ':${name}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n paramNames.push(name);\n regexParts.push(isSplat ? '__SPLAT__' : '([^/]+)');\n continue;\n }\n\n // Static\n regexParts.push(escapeSeg(seg));\n }\n\n let pattern: string;\n if (regexParts.length === 0) {\n pattern = '^/$';\n } else {\n const last = regexParts[regexParts.length - 1];\n if (last === '__SPLAT__') {\n const prefix = regexParts.slice(0, -1).join('/');\n if (!prefix) {\n // route is like '/:rest*' or '/*' -> allow '/' or '/x' etc.\n pattern = '^(?:/(.*))?(?:/)?$';\n } else {\n pattern = `^/${prefix}(?:/(.*))?(?:/)?$`;\n }\n } else {\n pattern = `^/${regexParts.join('/')}(?:/)?$`;\n }\n }\n try {\n const regex = new RegExp(pattern);\n return { regex, paramNames };\n } catch (e) {\n devWarn(`Failed to compile route regex for '${route.path}': ${String(e)}`);\n return { invalid: true };\n }\n}\n\nexport const matchRoute = (\n routes: Route[],\n path: string,\n): { route: Route | null; params: Record<string, string> } => {\n const incoming = normalizePathForRoute(path);\n\n for (const route of routes) {\n let compiled = compileCache.get(route);\n if (!compiled) {\n compiled = compileRoute(route);\n compileCache.set(route, compiled);\n }\n\n if ((compiled as { invalid?: true }).invalid) continue;\n\n const { regex, paramNames } = compiled as {\n regex: RegExp;\n paramNames: string[];\n };\n const m = regex.exec(incoming);\n if (m) {\n const params: Record<string, string> = {};\n const safeDecode = (v: string) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n };\n\n for (let i = 0; i < paramNames.length; i++) {\n const raw = m[i + 1] || '';\n params[paramNames[i]] = raw ? safeDecode(raw) : '';\n }\n\n return { route, params };\n }\n }\n\n return { route: null, params: {} };\n};\n\n/**\n * Find the first route that matches the given path.\n * Consolidates repeated inline checks like `routes.find(r => matchRoute([r], path).route !== null)`\n */\nfunction findMatchedRoute(routes: Route[], path: string): Route | null {\n for (const r of routes) {\n if (matchRoute([r], path).route !== null) return r;\n }\n return null;\n}\n\n// Async component loader cache\nconst componentCache: Record<\n string,\n string | HTMLElement | ((...args: unknown[]) => unknown)\n> = {};\n\n/**\n * Loads a route's component, supporting both static and async.\n * @param route Route object\n * @returns Promise resolving to the component\n */\nexport async function resolveRouteComponent(\n route: Route,\n): Promise<string | HTMLElement | ((...args: unknown[]) => unknown)> {\n if (route.component) return route.component;\n if (route.load) {\n if (componentCache[route.path]) return componentCache[route.path];\n try {\n const mod = await route.load();\n componentCache[route.path] = mod.default;\n return mod.default;\n } catch {\n throw new Error(`Failed to load component for route: ${route.path}`);\n }\n }\n throw new Error(`No component or loader defined for route: ${route.path}`);\n}\n\nexport function useRouter(config: RouterConfig) {\n const { routes, base = '', initialUrl } = config;\n\n let getLocation: () => { path: string; query: Record<string, string> };\n let initial: { path: string; query: Record<string, string> };\n let store: Store<RouteState>;\n let update: (replace?: boolean) => Promise<void>;\n let push: (path: string) => Promise<void>;\n let replaceFn: (path: string) => Promise<void>;\n let back: () => void;\n\n // Run matching route guards/hooks\n const runBeforeEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.beforeEnter) return true;\n try {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('beforeEnter error', err);\n return false;\n }\n };\n\n const runOnEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.onEnter) return true;\n try {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('onEnter error', err);\n return false;\n }\n };\n\n const runAfterEnter = (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.afterEnter) return;\n try {\n matched.afterEnter(to, from);\n } catch (err) {\n devError('afterEnter error', err);\n }\n };\n\n const navigate = async (path: string, replace = false) => {\n try {\n const loc = {\n path: path.replace(base, '') || '/',\n query: {},\n };\n const match = matchRoute(routes, loc.path);\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n };\n\n // beforeEnter guard\n const allowedBefore = await runBeforeEnter(to, from);\n if (!allowedBefore) return;\n\n // onEnter guard (right before commit)\n const allowedOn = await runOnEnter(to, from);\n if (!allowedOn) return;\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (replace) {\n window.history.replaceState({}, '', base + path);\n } else {\n window.history.pushState({}, '', base + path);\n }\n }\n\n store.setState(to);\n\n // afterEnter hook (post commit)\n runAfterEnter(to, from);\n } catch (err) {\n devError('Navigation error:', err);\n }\n };\n\n // If an explicit `initialUrl` is provided we treat this as SSR/static rendering\n // even if a `window` exists (useful for hydration tests). Browser mode only\n // applies when `initialUrl` is undefined.\n if (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof initialUrl === 'undefined'\n ) {\n // Browser mode\n getLocation = () => {\n const url = new URL(window.location.href);\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n return { path, query };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n });\n\n update = async (replace = false) => {\n const loc = getLocation();\n await navigate(loc.path, replace);\n };\n\n window.addEventListener('popstate', () => update(true));\n\n push = (path: string) => navigate(path, false);\n replaceFn = (path: string) => navigate(path, true);\n back = () => window.history.back();\n } else {\n // SSR mode\n getLocation = () => {\n const url = new URL(initialUrl || '/', 'http://localhost');\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n return { path, query };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n });\n\n update = async () => {\n const loc = getLocation();\n await navigateSSR(loc.path);\n };\n\n // SSR navigation contract:\n // - `push` / `replace` call into `navigateSSR` and return a Promise.\n // - On the server we intentionally surface navigation failures so\n // server-side logic (or tests) can react: missing routes or thrown\n // errors from `beforeEnter`/`onEnter` will cause the Promise to\n // reject. This lets the server render 404s or abort builds.\n // - For valid routes the server-side navigation resolves and updates\n // the internal store state so rendered output matches the target\n // path. The `back()` operation is client-only and is a synchronous\n // no-op in SSR mode.\n const navigateSSR = async (path: string) => {\n try {\n const loc = {\n path: path.replace(base, '') || '/',\n query: {},\n };\n const match = matchRoute(routes, loc.path);\n // In SSR mode we intentionally surface navigation errors (missing\n // route) to the caller so server-side logic may handle them. If no\n // route matches, throw and let the caller observe the rejection.\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n };\n\n // beforeEnter guard\n const matched = findMatchedRoute(routes, to.path);\n if (matched?.beforeEnter) {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n // onEnter guard\n if (matched?.onEnter) {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n store.setState(to);\n\n // afterEnter hook\n if (matched?.afterEnter) {\n matched.afterEnter(to, from);\n }\n } catch (err) {\n // Surface SSR navigation errors so callers (and tests) can observe\n // failures during server-side resolution.\n devError('SSR navigation error:', err);\n throw err;\n }\n };\n\n push = async (path: string) => navigateSSR(path);\n replaceFn = async (path: string) => navigateSSR(path);\n back = () => {};\n }\n\n return {\n store,\n push,\n replace: replaceFn,\n back,\n subscribe: store.subscribe,\n matchRoute: (path: string) => matchRoute(routes, path),\n getCurrent: (): RouteState => store.getState(),\n resolveRouteComponent,\n };\n}\n\n// SSR/static site support: match route for a given path\nexport function matchRouteSSR(routes: Route[], path: string) {\n return matchRoute(routes, path);\n}\n\n// Module-level reference to the latest initialized router. Tests and\n// components may rely on re-initializing the router during their setup,\n// so exposing this lets components pick up the most recent instance.\nlet activeRouter: ReturnType<typeof useRouter> | null = null;\n\n/**\n * Singleton router instance for global access.\n *\n * Define here to prevent circular dependency\n * issue with component.\n */\n\nexport function initRouter(config: RouterConfig) {\n const router = useRouter(config);\n // Expose the most recently initialized router to components defined\n // earlier in the process (tests may call initRouter multiple times).\n // Components reference `activeRouter` so re-calling initRouter updates\n // the router instance they use.\n activeRouter = router;\n\n component('router-view', async () => {\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current route so the component re-renders when router updates\n if (!r) return html`<div>Router not initialized.</div>`;\n\n const current = ref(r.getCurrent());\n\n // We'll capture the unsubscribe function when the component connects\n // and register a disconnect cleanup during render-time (useOnDisconnected\n // must be called during the component render/execution).\n let unsubRouterView: (() => void) | undefined;\n\n useOnConnected(() => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterView = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-view subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-view subscribe failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterView === 'function') {\n try {\n unsubRouterView();\n } catch (e) {\n devWarn('router-view unsubscribe failed', e);\n }\n }\n });\n\n const match = r.matchRoute(current.value.path);\n if (!match || !match.route) return html`<div>Not found</div>`;\n\n // Resolve the component (supports cached async loaders)\n try {\n const compRaw = await r.resolveRouteComponent(match.route);\n const comp = compRaw as\n | string\n | HTMLElement\n | ((...args: unknown[]) => unknown)\n | undefined;\n // String tag (custom element) -> render as VNode\n if (typeof comp === 'string') {\n return { tag: comp, props: {}, children: [] };\n }\n\n // Function component (sync or async) -> call and return its VNode(s)\n if (typeof comp === 'function') {\n const out = comp();\n const resolved = out instanceof Promise ? out : Promise.resolve(out);\n return resolved.then((resolvedComp) => {\n if (typeof resolvedComp === 'string')\n return { tag: resolvedComp, props: {}, children: [] };\n return resolvedComp;\n });\n }\n\n return html`<div>Invalid route component</div>`;\n } catch {\n return html`<div>Invalid route component</div>`;\n }\n });\n\n component('router-link', () => {\n // Declare props via useProps so observedAttributes are correct\n const props = useProps<Partial<RouterLinkProps>>({\n to: '',\n tag: 'a',\n replace: false,\n exact: false,\n activeClass: 'active',\n exactActiveClass: 'exact-active',\n ariaCurrentValue: 'page',\n disabled: false,\n external: false,\n // allow host `class` and `style` attributes to be read via useProps\n class: '',\n style: '',\n });\n\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current state so link updates when route changes\n const current = ref(r.getCurrent());\n // Capture unsubscribe for link subscriptions and register disconnect\n // cleanup during render time.\n let unsubRouterLink: (() => void) | undefined;\n\n // Keep a minimal internal host-scoped style for element display.\n // Host `style` will be applied to the inner anchor/button element.\n useStyle(() => `a,button{display:inline-block;}`);\n\n // We capture host attributes at connection time and migrate them to\n // internal refs so we can remove them from the host. This prevents\n // global/author CSS targeting the host from styling the host element\n // itself while still allowing authors to use `class`/`style` on the\n // router-link to style the inner anchor/button.\n const hostClassRef = ref((props.class as string) || '');\n const hostStyleRef = ref((props.style as string) || '');\n\n useOnConnected((ctx?: unknown) => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterLink = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-link subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-link subscribe failed', e);\n }\n\n // Migrate host `class`/`style` into internal refs and remove them\n // from the host so only the inner element is styled.\n try {\n const host = (ctx as { _host?: HTMLElement } | undefined)?._host;\n if (host instanceof HTMLElement) {\n const hc = host.getAttribute('class');\n const hs = host.getAttribute('style');\n if (hc) hostClassRef.value = hc;\n if (hs) hostStyleRef.value = hs;\n // Remove attributes from host to avoid styling the host\n if (hc !== null) host.removeAttribute('class');\n if (hs !== null) host.removeAttribute('style');\n }\n } catch (e) {\n devWarn('router-link host migration failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterLink === 'function') {\n try {\n unsubRouterLink();\n } catch (e) {\n devWarn('router-link unsubscribe failed', e);\n }\n }\n });\n\n const isExactActive = computed(\n () => current.value.path === (props.to as string),\n );\n const isActive = computed(() =>\n props.exact\n ? isExactActive.value\n : current.value && typeof current.value.path === 'string'\n ? current.value.path.startsWith(props.to as string)\n : false,\n );\n\n // Build user classes reactively from the host `class` attribute prop.\n // We intentionally apply classes to the inner element so the consumer\n // can style the link via `class=\"...\"`.\n const userClasses = computed(() => {\n const rawHost =\n (hostClassRef && hostClassRef.value) || (props.class as string) || '';\n const list = rawHost.split(/\\s+/).filter(Boolean);\n const map: Record<string, boolean> = {};\n for (const c of list) map[c] = true;\n return map;\n });\n\n const classObject = computed(() => ({\n ...userClasses.value,\n [(props.activeClass as string) || 'active']: isActive.value,\n [(props.exactActiveClass as string) || 'exact-active']:\n isExactActive.value,\n }));\n\n // Compute a final class string (template accepts object or string; we\n // convert to string to safely include host classes and conditionals).\n const classString = computed(() =>\n Object.keys(classObject.value)\n .filter((k) => classObject.value[k])\n .join(' '),\n );\n\n const isButton = computed(() => (props.tag as string) === 'button');\n // Instead of pre-building attribute fragments as strings (which can\n // accidentally inject invalid attribute names into the template and\n // cause DOMExceptions), compute simple booleans/values and apply\n // attributes explicitly in the template below.\n const ariaCurrentValue = computed(() =>\n isExactActive.value ? (props.ariaCurrentValue as string) : '',\n );\n const isDisabled = computed(() => !!props.disabled);\n const isExternal = computed(\n () =>\n !!props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string)),\n );\n\n // Inline style from host `style` attribute.\n const inlineStyle = computed(\n () =>\n (hostStyleRef && hostStyleRef.value) || (props.style as string) || '',\n );\n\n const navigate = (e: MouseEvent) => {\n if (props.disabled) {\n e.preventDefault();\n return;\n }\n if (\n props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string))\n ) {\n return;\n }\n e.preventDefault();\n if (props.replace) {\n r.replace(props.to as string);\n } else {\n r.push(props.to as string);\n }\n };\n\n return html`\n ${match()\n .when(\n isButton.value,\n html`\n <button\n part=\"button\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n disabled=\"${isDisabled.value ? '' : null}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n @click=\"${navigate}\"\n >\n <slot></slot>\n </button>\n `,\n )\n .otherwise(html`\n <a\n part=\"link\"\n href=\"${props.to}\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n target=\"${isExternal.value ? '_blank' : null}\"\n rel=\"${isExternal.value ? 'noopener noreferrer' : null}\"\n @click=\"${navigate}\"\n ><slot></slot\n ></a>\n `)\n .done()}\n `;\n });\n\n return router;\n}\n"],"names":["parseQuery","search","compileCache","escapeSeg","seg","normalizePathForRoute","p","out","compileRoute","route","raw","routePath","segments","paramNames","regexParts","i","devWarn","name","paramMatch","isSplat","pattern","prefix","e","matchRoute","routes","path","incoming","compiled","regex","m","params","safeDecode","v","findMatchedRoute","r","componentCache","resolveRouteComponent","mod","useRouter","config","base","initialUrl","getLocation","initial","store","update","push","replaceFn","back","runBeforeEnter","to","from","matched","result","navigate","err","devError","runOnEnter","runAfterEnter","replace","loc","match","url","query","createStore","navigateSSR","matchRouteSSR","activeRouter","initRouter","router","component","html","current","ref","unsubRouterView","useOnConnected","s","useOnDisconnected","comp","resolvedComp","props","useProps","unsubRouterLink","useStyle","hostClassRef","hostStyleRef","ctx","host","hc","hs","isExactActive","computed","isActive","userClasses","list","map","c","classObject","classString","k","isButton","ariaCurrentValue","isDisabled","isExternal","inlineStyle"],"mappings":";;;;;AAwFO,MAAMA,IAAa,CAACC,MACpBA,IACD,OAAO,kBAAoB,MAAoB,CAAA,IAC5C,OAAO,YAAY,IAAI,gBAAgBA,CAAM,CAAC,IAFjC,CAAA,GAShBC,wBAAkD,QAAA;AAExD,SAASC,EAAUC,GAAa;AAC9B,SAAOA,EAAI,QAAQ,uBAAuB,MAAM;AAClD;AAEA,SAASC,EAAsBC,GAAW;AACxC,MAAI,CAACA,EAAG,QAAO;AAEf,MAAIC,IAAMD,EAAE,QAAQ,QAAQ,GAAG;AAC/B,SAAKC,EAAI,WAAW,GAAG,UAAS,MAAMA,IAClCA,EAAI,SAAS,KAAKA,EAAI,SAAS,GAAG,MAAGA,IAAMA,EAAI,MAAM,GAAG,EAAE,IACvDA;AACT;AAEA,SAASC,EAAaC,GAA6B;AACjD,QAAMC,IAAMD,EAAM,QAAQ,KACp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AQ,WAAW,IAAI;AAAA,mBACrCA,EAAW,QAAQ,wBAAwB,IAAI;AAAA,sBAC5CjD,CAAQ;AAAA;AAAA;AAAA,SAGrB,EACA,MAAM;AAAA;AAAA,EAEb,CAAC,GAEMe;AACT;"}
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.router.es.js","sources":["../src/lib/router.ts"],"sourcesContent":["import { html } from './runtime/template-compiler';\nimport { component } from './runtime/component';\nimport {\n useProps,\n useOnConnected,\n useOnDisconnected,\n useStyle,\n} from './runtime/hooks';\nimport { ref, computed } from './runtime/reactive';\nimport { createStore, type Store } from './store';\nimport { devError, devWarn } from './runtime/logger';\nimport { match } from './directives';\n\nexport type RouteComponent =\n | { new (...args: unknown[]): unknown } // class components\n | ((...args: unknown[]) => unknown); // functional components\n\nexport interface RouteState {\n path: string;\n params: Record<string, string>;\n query: Record<string, string>;\n // Optional fragment (hash) portion of the URL, without the leading '#'\n fragment?: string;\n}\n\nexport type GuardResult = boolean | string | Promise<boolean | string>;\n\nexport interface Route {\n path: string;\n\n /**\n * Statically available component (already imported)\n */\n component?: string | (() => unknown);\n\n /**\n * Lazy loader that resolves to something renderable\n */\n load?: () => Promise<{\n default: string | HTMLElement | ((...args: unknown[]) => unknown);\n }>;\n\n /**\n * Runs before matching — return false to cancel,\n * or a string to redirect\n */\n beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs right before navigation commits — can cancel or redirect\n */\n onEnter?: (to: RouteState, from: RouteState) => GuardResult;\n\n /**\n * Runs after navigation completes — cannot cancel\n */\n afterEnter?: (to: RouteState, from: RouteState) => void;\n}\n\nexport interface RouterLinkProps {\n to: string;\n tag: string;\n replace: boolean;\n exact: boolean;\n activeClass: string;\n exactActiveClass: string;\n ariaCurrentValue: string;\n disabled: boolean;\n external: boolean;\n class?: string;\n style?: string;\n}\n\nexport interface RouterLinkComputed {\n current: RouteState;\n isExactActive: boolean;\n isActive: boolean;\n className: string;\n ariaCurrent: string;\n isButton: boolean;\n disabledAttr: string;\n externalAttr: string;\n}\n\nexport interface RouterConfig {\n routes: Route[];\n base?: string;\n initialUrl?: string; // For SSR: explicitly pass the URL\n}\n\nexport const parseQuery = (search: string): Record<string, string> => {\n if (!search) return {};\n if (typeof URLSearchParams === 'undefined') return {};\n return Object.fromEntries(new URLSearchParams(search));\n};\n\n// Cache compiled route regexes to avoid rebuilding on every navigation.\ntype CompiledRoute =\n | { regex: RegExp; paramNames: string[] }\n | { invalid: true };\nconst compileCache: WeakMap<Route, CompiledRoute> = new WeakMap();\n\nfunction escapeSeg(seg: string) {\n return seg.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function normalizePathForRoute(p: string) {\n if (!p) return '/';\n // Collapse duplicate slashes, ensure leading slash, remove trailing slash\n let out = p.replace(/\\/+/g, '/');\n if (!out.startsWith('/')) out = '/' + out;\n if (out.length > 1 && out.endsWith('/')) out = out.slice(0, -1);\n return out;\n}\n\nfunction compileRoute(route: Route): CompiledRoute {\n const raw = route.path || '/';\n const routePath = normalizePathForRoute(raw);\n\n const segments =\n routePath === '/' ? [] : routePath.split('/').filter(Boolean);\n\n const paramNames: string[] = [];\n const regexParts: string[] = [];\n\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i];\n\n // Anonymous wildcard\n if (seg === '*') {\n // splat must be terminal\n if (i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n const name = `splat${paramNames.length}`;\n paramNames.push(name);\n // mark splat token; pattern will be built specially so the\n // preceding slash can be optional (allow empty splat)\n regexParts.push('__SPLAT__');\n continue;\n }\n\n const paramMatch = seg.match(/^:([A-Za-z0-9_-]+)(\\*)?$/);\n if (paramMatch) {\n const name = paramMatch[1];\n const isSplat = !!paramMatch[2];\n // If splat, ensure terminal\n if (isSplat && i !== segments.length - 1) {\n devWarn(\n `Route '${route.path}' contains a splat param ':${name}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`,\n );\n return { invalid: true };\n }\n paramNames.push(name);\n regexParts.push(isSplat ? '__SPLAT__' : '([^/]+)');\n continue;\n }\n\n // Static\n regexParts.push(escapeSeg(seg));\n }\n\n let pattern: string;\n if (regexParts.length === 0) {\n pattern = '^/$';\n } else {\n const last = regexParts[regexParts.length - 1];\n if (last === '__SPLAT__') {\n const prefix = regexParts.slice(0, -1).join('/');\n if (!prefix) {\n // route is like '/:rest*' or '/*' -> allow '/' or '/x' etc.\n pattern = '^(?:/(.*))?(?:/)?$';\n } else {\n pattern = `^/${prefix}(?:/(.*))?(?:/)?$`;\n }\n } else {\n pattern = `^/${regexParts.join('/')}(?:/)?$`;\n }\n }\n try {\n const regex = new RegExp(pattern);\n return { regex, paramNames };\n } catch (e) {\n devWarn(`Failed to compile route regex for '${route.path}': ${String(e)}`);\n return { invalid: true };\n }\n}\n\nexport const matchRoute = (\n routes: Route[],\n path: string,\n): { route: Route | null; params: Record<string, string> } => {\n const incoming = normalizePathForRoute(path);\n\n for (const route of routes) {\n let compiled = compileCache.get(route);\n if (!compiled) {\n compiled = compileRoute(route);\n compileCache.set(route, compiled);\n }\n\n if ((compiled as { invalid?: true }).invalid) continue;\n\n const { regex, paramNames } = compiled as {\n regex: RegExp;\n paramNames: string[];\n };\n const m = regex.exec(incoming);\n if (m) {\n const params: Record<string, string> = {};\n const safeDecode = (v: string) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n };\n\n for (let i = 0; i < paramNames.length; i++) {\n const raw = m[i + 1] || '';\n params[paramNames[i]] = raw ? safeDecode(raw) : '';\n }\n\n return { route, params };\n }\n }\n\n return { route: null, params: {} };\n};\n\n/**\n * Find the first route that matches the given path.\n * Consolidates repeated inline checks like `routes.find(r => matchRoute([r], path).route !== null)`\n */\nfunction findMatchedRoute(routes: Route[], path: string): Route | null {\n for (const r of routes) {\n if (matchRoute([r], path).route !== null) return r;\n }\n return null;\n}\n\n// Async component loader cache\nconst componentCache: Record<\n string,\n string | HTMLElement | ((...args: unknown[]) => unknown)\n> = {};\n\n/**\n * Loads a route's component, supporting both static and async.\n * @param route Route object\n * @returns Promise resolving to the component\n */\nexport async function resolveRouteComponent(\n route: Route,\n): Promise<string | HTMLElement | ((...args: unknown[]) => unknown)> {\n if (route.component) return route.component;\n if (route.load) {\n if (componentCache[route.path]) return componentCache[route.path];\n try {\n const mod = await route.load();\n componentCache[route.path] = mod.default;\n return mod.default;\n } catch {\n throw new Error(`Failed to load component for route: ${route.path}`);\n }\n }\n throw new Error(`No component or loader defined for route: ${route.path}`);\n}\n\nexport function useRouter(config: RouterConfig) {\n const { routes, base = '', initialUrl } = config;\n\n let getLocation: () => { path: string; query: Record<string, string> };\n let initial: { path: string; query: Record<string, string> };\n let store: Store<RouteState>;\n let update: (replace?: boolean) => Promise<void>;\n let push: (path: string) => Promise<void>;\n let replaceFn: (path: string) => Promise<void>;\n let back: () => void;\n\n // Run matching route guards/hooks\n const runBeforeEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.beforeEnter) return true;\n try {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('beforeEnter error', err);\n return false;\n }\n };\n\n const runOnEnter = async (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.onEnter) return true;\n try {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigate(result, true);\n return false;\n }\n return result !== false;\n } catch (err) {\n devError('onEnter error', err);\n return false;\n }\n };\n\n const runAfterEnter = (to: RouteState, from: RouteState) => {\n const matched = findMatchedRoute(routes, to.path);\n if (!matched || !matched.afterEnter) return;\n try {\n matched.afterEnter(to, from);\n } catch (err) {\n devError('afterEnter error', err);\n }\n };\n\n const navigate = async (path: string, replace = false) => {\n try {\n // Separate fragment (hash) from path so matching ignores it while\n // the fragment is preserved on the RouteState.\n const hashIndex = path.indexOf('#');\n const fragment = hashIndex >= 0 ? path.slice(hashIndex + 1) : '';\n const rawPath = hashIndex >= 0 ? path.slice(0, hashIndex) : path;\n const loc = {\n path: rawPath.replace(base, '') || '/',\n query: {},\n fragment,\n };\n const match = matchRoute(routes, loc.path);\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n fragment: (loc as { fragment?: string }).fragment,\n };\n\n // beforeEnter guard\n const allowedBefore = await runBeforeEnter(to, from);\n if (!allowedBefore) return;\n\n // onEnter guard (right before commit)\n const allowedOn = await runOnEnter(to, from);\n if (!allowedOn) return;\n\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (replace) {\n window.history.replaceState({}, '', base + path);\n } else {\n window.history.pushState({}, '', base + path);\n }\n }\n\n store.setState(to);\n\n // afterEnter hook (post commit)\n runAfterEnter(to, from);\n } catch (err) {\n devError('Navigation error:', err);\n }\n };\n\n // If an explicit `initialUrl` is provided we treat this as SSR/static rendering\n // even if a `window` exists (useful for hydration tests). Browser mode only\n // applies when `initialUrl` is undefined.\n if (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof initialUrl === 'undefined'\n ) {\n // Browser mode\n getLocation = () => {\n const url = new URL(window.location.href);\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n const fragment = url.hash && url.hash.length ? url.hash.slice(1) : '';\n return { path, query, fragment };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n fragment: (initial as { fragment?: string }).fragment,\n });\n\n update = async (replace = false) => {\n const loc = getLocation();\n await navigate(loc.path, replace);\n };\n\n window.addEventListener('popstate', () => update(true));\n\n push = (path: string) => navigate(path, false);\n replaceFn = (path: string) => navigate(path, true);\n back = () => window.history.back();\n } else {\n // SSR mode\n getLocation = () => {\n const url = new URL(initialUrl || '/', 'http://localhost');\n const path = url.pathname.replace(base, '') || '/';\n const query = parseQuery(url.search);\n const fragment = url.hash && url.hash.length ? url.hash.slice(1) : '';\n return { path, query, fragment };\n };\n\n initial = getLocation();\n const match = matchRoute(routes, initial.path);\n store = createStore<RouteState>({\n path: initial.path,\n params: match.params,\n query: initial.query,\n fragment: (initial as { fragment?: string }).fragment,\n });\n\n update = async () => {\n const loc = getLocation();\n await navigateSSR(loc.path);\n };\n\n // SSR navigation contract:\n // - `push` / `replace` call into `navigateSSR` and return a Promise.\n // - On the server we intentionally surface navigation failures so\n // server-side logic (or tests) can react: missing routes or thrown\n // errors from `beforeEnter`/`onEnter` will cause the Promise to\n // reject. This lets the server render 404s or abort builds.\n // - For valid routes the server-side navigation resolves and updates\n // the internal store state so rendered output matches the target\n // path. The `back()` operation is client-only and is a synchronous\n // no-op in SSR mode.\n const navigateSSR = async (path: string) => {\n try {\n const hashIndex = path.indexOf('#');\n const fragment = hashIndex >= 0 ? path.slice(hashIndex + 1) : '';\n const rawPath = hashIndex >= 0 ? path.slice(0, hashIndex) : path;\n const loc = {\n path: rawPath.replace(base, '') || '/',\n query: {},\n fragment,\n };\n const match = matchRoute(routes, loc.path);\n // In SSR mode we intentionally surface navigation errors (missing\n // route) to the caller so server-side logic may handle them. If no\n // route matches, throw and let the caller observe the rejection.\n if (!match.route) throw new Error(`No route found for ${loc.path}`);\n\n const from = store.getState();\n const to: RouteState = {\n path: loc.path,\n params: match.params,\n query: loc.query,\n fragment: (loc as { fragment?: string }).fragment,\n };\n\n // beforeEnter guard\n const matched = findMatchedRoute(routes, to.path);\n if (matched?.beforeEnter) {\n const result = await matched.beforeEnter(to, from);\n if (typeof result === 'string') {\n // Redirect\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n // onEnter guard\n if (matched?.onEnter) {\n const result = await matched.onEnter(to, from);\n if (typeof result === 'string') {\n await navigateSSR(result);\n return;\n }\n if (result === false) return;\n }\n\n store.setState(to);\n\n // afterEnter hook\n if (matched?.afterEnter) {\n matched.afterEnter(to, from);\n }\n } catch (err) {\n // Surface SSR navigation errors so callers (and tests) can observe\n // failures during server-side resolution.\n devError('SSR navigation error:', err);\n throw err;\n }\n };\n\n push = async (path: string) => navigateSSR(path);\n replaceFn = async (path: string) => navigateSSR(path);\n back = () => {};\n }\n\n return {\n store,\n push,\n replace: replaceFn,\n back,\n subscribe: store.subscribe,\n matchRoute: (path: string) => matchRoute(routes, path),\n getCurrent: (): RouteState => store.getState(),\n resolveRouteComponent,\n };\n}\n\n// SSR/static site support: match route for a given path\nexport function matchRouteSSR(routes: Route[], path: string) {\n return matchRoute(routes, path);\n}\n\n// Module-level reference to the latest initialized router. Tests and\n// components may rely on re-initializing the router during their setup,\n// so exposing this lets components pick up the most recent instance.\nlet activeRouter: ReturnType<typeof useRouter> | null = null;\n\n/**\n * Singleton router instance for global access.\n *\n * Define here to prevent circular dependency\n * issue with component.\n */\n\nexport function initRouter(config: RouterConfig) {\n const router = useRouter(config);\n // Expose the most recently initialized router to components defined\n // earlier in the process (tests may call initRouter multiple times).\n // Components reference `activeRouter` so re-calling initRouter updates\n // the router instance they use.\n activeRouter = router;\n\n component('router-view', async () => {\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current route so the component re-renders when router updates\n if (!r) return html`<div>Router not initialized.</div>`;\n\n const current = ref(r.getCurrent());\n\n // We'll capture the unsubscribe function when the component connects\n // and register a disconnect cleanup during render-time (useOnDisconnected\n // must be called during the component render/execution).\n let unsubRouterView: (() => void) | undefined;\n\n useOnConnected(() => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterView = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-view subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-view subscribe failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterView === 'function') {\n try {\n unsubRouterView();\n } catch (e) {\n devWarn('router-view unsubscribe failed', e);\n }\n }\n });\n\n const match = r.matchRoute(current.value.path);\n if (!match || !match.route) return html`<div>Not found</div>`;\n\n // Resolve the component (supports cached async loaders)\n try {\n const compRaw = await r.resolveRouteComponent(match.route);\n const comp = compRaw as\n | string\n | HTMLElement\n | ((...args: unknown[]) => unknown)\n | undefined;\n // String tag (custom element) -> render as VNode\n if (typeof comp === 'string') {\n return { tag: comp, props: {}, children: [] };\n }\n\n // Function component (sync or async) -> call and return its VNode(s)\n if (typeof comp === 'function') {\n const out = comp();\n const resolved = out instanceof Promise ? out : Promise.resolve(out);\n return resolved.then((resolvedComp) => {\n if (typeof resolvedComp === 'string')\n return { tag: resolvedComp, props: {}, children: [] };\n return resolvedComp;\n });\n }\n\n return html`<div>Invalid route component</div>`;\n } catch {\n return html`<div>Invalid route component</div>`;\n }\n });\n\n component('router-link', () => {\n // Declare props via useProps so observedAttributes are correct\n const props = useProps<Partial<RouterLinkProps>>({\n to: '',\n tag: 'a',\n replace: false,\n exact: false,\n activeClass: 'active',\n exactActiveClass: 'exact-active',\n ariaCurrentValue: 'page',\n disabled: false,\n external: false,\n // allow host `class` and `style` attributes to be read via useProps\n class: '',\n style: '',\n });\n\n // Prefer the latest initialized router (tests may re-init). Fallback\n // to the router captured at init time.\n const r = activeRouter || router;\n // Reactive current state so link updates when route changes\n const current = ref(r.getCurrent());\n // Capture unsubscribe for link subscriptions and register disconnect\n // cleanup during render time.\n let unsubRouterLink: (() => void) | undefined;\n\n // Keep a minimal internal host-scoped style for element display.\n // Host `style` will be applied to the inner anchor/button element.\n useStyle(() => `a,button{display:inline-block;}`);\n\n // We capture host attributes at connection time and migrate them to\n // internal refs so we can remove them from the host. This prevents\n // global/author CSS targeting the host from styling the host element\n // itself while still allowing authors to use `class`/`style` on the\n // router-link to style the inner anchor/button.\n const hostClassRef = ref((props.class as string) || '');\n const hostStyleRef = ref((props.style as string) || '');\n\n useOnConnected((ctx?: unknown) => {\n try {\n if (r && typeof r.subscribe === 'function') {\n unsubRouterLink = r.subscribe((s) => {\n try {\n current.value = s;\n } catch (e) {\n devWarn('router-link subscription update failed', e);\n }\n });\n }\n } catch (e) {\n devWarn('router-link subscribe failed', e);\n }\n\n // Migrate host `class`/`style` into internal refs and remove them\n // from the host so only the inner element is styled.\n try {\n const host = (ctx as { _host?: HTMLElement } | undefined)?._host;\n if (host instanceof HTMLElement) {\n const hc = host.getAttribute('class');\n const hs = host.getAttribute('style');\n if (hc) hostClassRef.value = hc;\n if (hs) hostStyleRef.value = hs;\n // Remove attributes from host to avoid styling the host\n if (hc !== null) host.removeAttribute('class');\n if (hs !== null) host.removeAttribute('style');\n }\n } catch (e) {\n devWarn('router-link host migration failed', e);\n }\n });\n\n useOnDisconnected(() => {\n if (typeof unsubRouterLink === 'function') {\n try {\n unsubRouterLink();\n } catch (e) {\n devWarn('router-link unsubscribe failed', e);\n }\n }\n });\n\n const isExactActive = computed(() => {\n const targetRaw = (props.to as string) || '';\n // strip fragment from target when comparing\n const targetPathOnly = targetRaw.split('#')[0];\n try {\n return (\n normalizePathForRoute(current.value.path) ===\n normalizePathForRoute(targetPathOnly)\n );\n } catch {\n return current.value.path === targetPathOnly;\n }\n });\n\n const isActive = computed(() => {\n const targetRaw = (props.to as string) || '';\n const targetPathOnly = targetRaw.split('#')[0];\n if (props.exact) return isExactActive.value;\n try {\n const cur = normalizePathForRoute(current.value.path);\n const tgt = normalizePathForRoute(targetPathOnly);\n return cur.startsWith(tgt);\n } catch {\n return (\n current.value &&\n typeof current.value.path === 'string' &&\n current.value.path.startsWith(targetPathOnly)\n );\n }\n });\n\n // Build user classes reactively from the host `class` attribute prop.\n // We intentionally apply classes to the inner element so the consumer\n // can style the link via `class=\"...\"`.\n const userClasses = computed(() => {\n const rawHost =\n (hostClassRef && hostClassRef.value) || (props.class as string) || '';\n const list = rawHost.split(/\\s+/).filter(Boolean);\n const map: Record<string, boolean> = {};\n for (const c of list) map[c] = true;\n return map;\n });\n\n const classObject = computed(() => ({\n ...userClasses.value,\n [(props.activeClass as string) || 'active']: isActive.value,\n [(props.exactActiveClass as string) || 'exact-active']:\n isExactActive.value,\n }));\n\n // Compute a final class string (template accepts object or string; we\n // convert to string to safely include host classes and conditionals).\n const classString = computed(() =>\n Object.keys(classObject.value)\n .filter((k) => classObject.value[k])\n .join(' '),\n );\n\n const isButton = computed(() => (props.tag as string) === 'button');\n // Instead of pre-building attribute fragments as strings (which can\n // accidentally inject invalid attribute names into the template and\n // cause DOMExceptions), compute simple booleans/values and apply\n // attributes explicitly in the template below.\n const ariaCurrentValue = computed(() =>\n isExactActive.value ? (props.ariaCurrentValue as string) : '',\n );\n const isDisabled = computed(() => !!props.disabled);\n const isExternal = computed(\n () =>\n !!props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string)),\n );\n\n // Inline style from host `style` attribute.\n const inlineStyle = computed(\n () =>\n (hostStyleRef && hostStyleRef.value) || (props.style as string) || '',\n );\n\n const navigate = (e: MouseEvent) => {\n if (props.disabled) {\n e.preventDefault();\n return;\n }\n if (\n props.external &&\n ((props.tag as string) === 'a' || !(props.tag as string))\n ) {\n return;\n }\n e.preventDefault();\n if (props.replace) {\n r.replace(props.to as string);\n } else {\n r.push(props.to as string);\n }\n };\n\n return html`\n ${match()\n .when(\n isButton.value,\n html`\n <button\n part=\"button\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n disabled=\"${isDisabled.value ? '' : null}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n @click=\"${navigate}\"\n >\n <slot></slot>\n </button>\n `,\n )\n .otherwise(html`\n <a\n part=\"link\"\n href=\"${props.to}\"\n class=\"${classString.value}\"\n style=\"${inlineStyle.value || null}\"\n aria-current=\"${ariaCurrentValue.value}\"\n aria-disabled=\"${isDisabled.value ? 'true' : null}\"\n tabindex=\"${isDisabled.value ? '-1' : null}\"\n target=\"${isExternal.value ? '_blank' : null}\"\n rel=\"${isExternal.value ? 'noopener noreferrer' : null}\"\n @click=\"${navigate}\"\n ><slot></slot\n ></a>\n `)\n .done()}\n `;\n });\n\n return router;\n}\n"],"names":["parseQuery","search","compileCache","escapeSeg","seg","normalizePathForRoute","p","out","compileRoute","route","raw","routePath","segments","paramNames","regexParts","i","devWarn","name","paramMatch","isSplat","pattern","prefix","e","matchRoute","routes","path","incoming","compiled","regex","m","params","safeDecode","v","findMatchedRoute","r","componentCache","resolveRouteComponent","mod","useRouter","config","base","initialUrl","getLocation","initial","store","update","push","replaceFn","back","runBeforeEnter","to","from","matched","result","navigate","err","devError","runOnEnter","runAfterEnter","replace","hashIndex","fragment","loc","match","url","query","createStore","navigateSSR","matchRouteSSR","activeRouter","initRouter","router","component","html","current","ref","unsubRouterView","useOnConnected","s","useOnDisconnected","comp","resolvedComp","props","useProps","unsubRouterLink","useStyle","hostClassRef","hostStyleRef","ctx","host","hc","hs","isExactActive","computed","targetPathOnly","isActive","cur","tgt","userClasses","list","map","c","classObject","classString","k","isButton","ariaCurrentValue","isDisabled","isExternal","inlineStyle"],"mappings":";;;;;AA0FO,MAAMA,IAAa,CAACC,MACpBA,IACD,OAAO,kBAAoB,MAAoB,CAAA,IAC5C,OAAO,YAAY,IAAI,gBAAgBA,CAAM,CAAC,IAFjC,CAAA,GAShBC,wBAAkD,QAAA;AAExD,SAASC,EAAUC,GAAa;AAC9B,SAAOA,EAAI,QAAQ,uBAAuB,MAAM;AAClD;AAEO,SAASC,EAAsBC,GAAW;AAC/C,MAAI,CAACA,EAAG,QAAO;AAEf,MAAIC,IAAMD,EAAE,QAAQ,QAAQ,GAAG;AAC/B,SAAKC,EAAI,WAAW,GAAG,UAAS,MAAMA,IAClCA,EAAI,SAAS,KAAKA,EAAI,SAAS,GAAG,MAAGA,IAAMA,EAAI,MAAM,GAAG,EAAE,IACvDA;AACT;AAEA,SAASC,EAAaC,GAA6B;AACjD,QAAMC,IAAMD,EAAM,QAAQ,KACpBE,IA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|
|
6
6
|
path: string;
|
|
7
7
|
params: Record<string, string>;
|
|
8
8
|
query: Record<string, string>;
|
|
9
|
+
fragment?: string;
|
|
9
10
|
}
|
|
10
11
|
export type GuardResult = boolean | string | Promise<boolean | string>;
|
|
11
12
|
export interface Route {
|
|
@@ -63,6 +64,7 @@ export interface RouterConfig {
|
|
|
63
64
|
initialUrl?: string;
|
|
64
65
|
}
|
|
65
66
|
export declare const parseQuery: (search: string) => Record<string, string>;
|
|
67
|
+
export declare function normalizePathForRoute(p: string): string;
|
|
66
68
|
export declare const matchRoute: (routes: Route[], path: string) => {
|
|
67
69
|
route: Route | null;
|
|
68
70
|
params: Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jasonshimmy/custom-elements-runtime",
|
|
3
3
|
"description": "A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"web-components",
|