what-router 0.8.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,74 @@
1
1
  // packages/router/src/index.js
2
2
  import { signal, effect, computed, batch, h, ErrorBoundary } from "what-core";
3
+
4
+ // packages/router/src/match.js
5
+ function compilePath(path) {
6
+ const normalized = path.replace(/\([\w-]+\)\//g, "").replace(/\[\.\.\.(\w+)\]/g, (_, name) => `*:${name}`).replace(/\[(\w+)\]/g, ":$1");
7
+ const paramNames = [];
8
+ let catchAll = null;
9
+ const regexStr = normalized.split("/").map((segment) => {
10
+ if (segment.startsWith("*:")) {
11
+ catchAll = segment.slice(2);
12
+ paramNames.push(catchAll);
13
+ return "(.+)";
14
+ }
15
+ if (segment === "*") {
16
+ catchAll = "rest";
17
+ paramNames.push("rest");
18
+ return "(.+)";
19
+ }
20
+ if (segment.startsWith(":")) {
21
+ paramNames.push(segment.slice(1));
22
+ return "([^/]+)";
23
+ }
24
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
+ }).join("/");
26
+ const regex = new RegExp(`^${regexStr}$`);
27
+ return { regex, paramNames, catchAll };
28
+ }
29
+ function matchRoute(path, routes) {
30
+ const routable = routes.filter((r) => r.path);
31
+ const sorted = routable.sort((a, b) => {
32
+ const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes("*") ? 100 : 0);
33
+ const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes("*") ? 100 : 0);
34
+ return aSpecific - bSpecific;
35
+ });
36
+ for (const route2 of sorted) {
37
+ const { regex, paramNames } = compilePath(route2.path);
38
+ const match = path.match(regex);
39
+ if (match) {
40
+ const params = {};
41
+ paramNames.forEach((name, i) => {
42
+ params[name] = decodeURIComponent(match[i + 1]);
43
+ });
44
+ return { route: route2, params };
45
+ }
46
+ }
47
+ return null;
48
+ }
49
+ function parseQuery(search) {
50
+ const params = {};
51
+ if (!search) return params;
52
+ const qs = search.startsWith("?") ? search.slice(1) : search;
53
+ for (const pair of qs.split("&")) {
54
+ const [key, val] = pair.split("=");
55
+ if (!key) continue;
56
+ const decodedKey = decodeURIComponent(key);
57
+ const decodedVal = val ? decodeURIComponent(val) : "";
58
+ if (decodedKey in params) {
59
+ if (Array.isArray(params[decodedKey])) {
60
+ params[decodedKey].push(decodedVal);
61
+ } else {
62
+ params[decodedKey] = [params[decodedKey], decodedVal];
63
+ }
64
+ } else {
65
+ params[decodedKey] = decodedVal;
66
+ }
67
+ }
68
+ return params;
69
+ }
70
+
71
+ // packages/router/src/index.js
3
72
  function isSafeUrl(url) {
4
73
  if (typeof url !== "string") return false;
5
74
  const trimmed = url.trim();
@@ -95,71 +164,6 @@ if (typeof window !== "undefined") {
95
164
  });
96
165
  });
97
166
  }
98
- function compilePath(path) {
99
- const normalized = path.replace(/\([\w-]+\)\//g, "").replace(/\[\.\.\.(\w+)\]/g, (_, name) => `*:${name}`).replace(/\[(\w+)\]/g, ":$1");
100
- const paramNames = [];
101
- let catchAll = null;
102
- const regexStr = normalized.split("/").map((segment) => {
103
- if (segment.startsWith("*:")) {
104
- catchAll = segment.slice(2);
105
- paramNames.push(catchAll);
106
- return "(.+)";
107
- }
108
- if (segment === "*") {
109
- catchAll = "rest";
110
- paramNames.push("rest");
111
- return "(.+)";
112
- }
113
- if (segment.startsWith(":")) {
114
- paramNames.push(segment.slice(1));
115
- return "([^/]+)";
116
- }
117
- return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
118
- }).join("/");
119
- const regex = new RegExp(`^${regexStr}$`);
120
- return { regex, paramNames, catchAll };
121
- }
122
- function matchRoute(path, routes) {
123
- const routable = routes.filter((r) => r.path);
124
- const sorted = routable.sort((a, b) => {
125
- const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes("*") ? 100 : 0);
126
- const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes("*") ? 100 : 0);
127
- return aSpecific - bSpecific;
128
- });
129
- for (const route2 of sorted) {
130
- const { regex, paramNames } = compilePath(route2.path);
131
- const match = path.match(regex);
132
- if (match) {
133
- const params = {};
134
- paramNames.forEach((name, i) => {
135
- params[name] = decodeURIComponent(match[i + 1]);
136
- });
137
- return { route: route2, params };
138
- }
139
- }
140
- return null;
141
- }
142
- function parseQuery(search) {
143
- const params = {};
144
- if (!search) return params;
145
- const qs = search.startsWith("?") ? search.slice(1) : search;
146
- for (const pair of qs.split("&")) {
147
- const [key, val] = pair.split("=");
148
- if (!key) continue;
149
- const decodedKey = decodeURIComponent(key);
150
- const decodedVal = val ? decodeURIComponent(val) : "";
151
- if (decodedKey in params) {
152
- if (Array.isArray(params[decodedKey])) {
153
- params[decodedKey].push(decodedVal);
154
- } else {
155
- params[decodedKey] = [params[decodedKey], decodedVal];
156
- }
157
- } else {
158
- params[decodedKey] = decodedVal;
159
- }
160
- }
161
- return params;
162
- }
163
167
  function buildLayoutChain(route2, routes) {
164
168
  const layouts = [];
165
169
  if (!route2.path) return layouts;
@@ -489,12 +493,15 @@ export {
489
493
  Redirect,
490
494
  Router,
491
495
  asyncGuard,
496
+ compilePath,
492
497
  defineRoutes,
493
498
  enableScrollRestoration,
494
499
  guard,
495
500
  isSafeUrl,
501
+ matchRoute,
496
502
  navigate,
497
503
  nestedRoutes,
504
+ parseQuery,
498
505
  prefetch,
499
506
  route,
500
507
  routeGroup,
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["// What Framework - Router\n// Production-grade file-based routing with nested layouts, loading states,\n// route groups, view transitions, and middleware.\n\nimport { signal, effect, computed, batch, h, ErrorBoundary } from 'what-core';\n\n// --- URL Sanitization ---\n// Rejects javascript:, data:, vbscript: protocols (case-insensitive, trimmed).\n\nexport function isSafeUrl(url) {\n if (typeof url !== 'string') return false;\n const trimmed = url.trim();\n // Check for dangerous protocols (case-insensitive, ignoring whitespace/control chars)\n const normalized = trimmed.replace(/[\\s\\x00-\\x1f]/g, '').toLowerCase();\n if (normalized.startsWith('javascript:')) return false;\n if (normalized.startsWith('data:')) return false;\n if (normalized.startsWith('vbscript:')) return false;\n return true;\n}\n\n// --- Route State (global singleton) ---\n\nconst _url = signal(typeof location !== 'undefined' ? location.pathname + location.search + location.hash : '/');\nconst _params = signal({});\nconst _query = signal({});\nconst _isNavigating = signal(false);\nconst _navigationError = signal(null);\n\nexport const route = {\n get url() { return _url(); },\n get path() { return _url().split('?')[0].split('#')[0]; },\n get params() { return _params(); },\n get query() { return _query(); },\n get hash() {\n const h = _url().split('#')[1];\n return h ? '#' + h : '';\n },\n get isNavigating() { return _isNavigating(); },\n get error() { return _navigationError(); },\n};\n\n// --- Navigation with View Transitions ---\n\nexport async function navigate(to, opts = {}) {\n const { replace = false, state = null, transition = true, _fromPopstate = false } = opts;\n\n // Reject unsafe URLs\n if (!isSafeUrl(to)) {\n if (typeof console !== 'undefined') {\n console.warn(`[what-router] Blocked navigation to unsafe URL: ${to}`);\n }\n return;\n }\n\n // Handle same-page hash links \u2014 use replaceState and scroll directly\n if (typeof window !== 'undefined' && to.startsWith('#')) {\n const currentUrl = _url();\n const basePath = currentUrl.split('#')[0];\n const newUrl = basePath + to;\n history.replaceState(state, '', newUrl);\n _url.set(newUrl);\n const el = document.querySelector(to);\n if (el) el.scrollIntoView({ behavior: 'smooth' });\n return;\n }\n\n // Don't navigate if already on the same URL\n if (to === _url()) return;\n\n // Prevent concurrent navigations \u2014 wait for current to finish\n if (_isNavigating.peek()) return;\n\n _isNavigating.set(true);\n _navigationError.set(null);\n\n const doNavigation = () => {\n // Skip history manipulation on popstate (browser already updated the URL)\n if (!_fromPopstate) {\n // Save scroll position for current URL before navigating away\n if (typeof window !== 'undefined') {\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n }\n if (replace) {\n history.replaceState(state, '', to);\n } else {\n history.pushState(state, '', to);\n }\n }\n _url.set(to);\n _isNavigating.set(false);\n };\n\n // Use View Transitions API if available and enabled\n if (transition && typeof document !== 'undefined' && document.startViewTransition) {\n try {\n await document.startViewTransition(doNavigation).finished;\n } catch (e) {\n // Transition failed, navigation still happened\n }\n } else {\n doNavigation();\n }\n}\n\n// Back/forward support \u2014 route through navigate() so middleware runs\nif (typeof window !== 'undefined') {\n window.addEventListener('popstate', () => {\n // Save scroll position for the URL we're leaving\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n\n const newUrl = location.pathname + location.search + location.hash;\n // Use _fromPopstate flag so navigate() skips pushState (browser already updated URL)\n navigate(newUrl, { replace: true, _fromPopstate: true, transition: false }).then(() => {\n // Restore saved scroll position for the URL we're arriving at\n const saved = scrollPositions.get(newUrl);\n if (saved) {\n requestAnimationFrame(() => window.scrollTo(saved.x, saved.y));\n }\n });\n });\n}\n\n// --- Route Matching ---\n\nfunction compilePath(path) {\n // /users/:id -> regex + param names\n // /posts/* -> catch-all\n // /[slug] -> dynamic (file-based syntax)\n // (group) -> route group (ignored in URL)\n\n // Remove route groups from path (they don't affect URL matching)\n const normalized = path\n .replace(/\\([\\w-]+\\)\\//g, '') // Remove (group)/ prefixes\n .replace(/\\[\\.\\.\\.(\\w+)\\]/g, (_, name) => `*:${name}`) // Preserve catch-all name\n .replace(/\\[(\\w+)\\]/g, ':$1'); // File-based [param] to :param\n\n const paramNames = [];\n let catchAll = null;\n\n const regexStr = normalized\n .split('/')\n .map(segment => {\n if (segment.startsWith('*:')) {\n catchAll = segment.slice(2);\n paramNames.push(catchAll);\n return '(.+)';\n }\n if (segment === '*') {\n catchAll = 'rest';\n paramNames.push('rest');\n return '(.+)';\n }\n if (segment.startsWith(':')) {\n paramNames.push(segment.slice(1));\n return '([^/]+)';\n }\n return segment.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n })\n .join('/');\n\n const regex = new RegExp(`^${regexStr}$`);\n return { regex, paramNames, catchAll };\n}\n\nfunction matchRoute(path, routes) {\n // Filter out routes without a path (layout-only routes, etc.)\n const routable = routes.filter(r => r.path);\n\n // Sort routes by specificity (more specific first)\n const sorted = routable.sort((a, b) => {\n const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);\n const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);\n return aSpecific - bSpecific;\n });\n\n for (const route of sorted) {\n const { regex, paramNames } = compilePath(route.path);\n const match = path.match(regex);\n if (match) {\n const params = {};\n paramNames.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1]);\n });\n return { route, params };\n }\n }\n return null;\n}\n\nfunction parseQuery(search) {\n const params = {};\n if (!search) return params;\n const qs = search.startsWith('?') ? search.slice(1) : search;\n for (const pair of qs.split('&')) {\n const [key, val] = pair.split('=');\n if (!key) continue;\n const decodedKey = decodeURIComponent(key);\n const decodedVal = val ? decodeURIComponent(val) : '';\n if (decodedKey in params) {\n // Collect repeated keys into arrays\n if (Array.isArray(params[decodedKey])) {\n params[decodedKey].push(decodedVal);\n } else {\n params[decodedKey] = [params[decodedKey], decodedVal];\n }\n } else {\n params[decodedKey] = decodedVal;\n }\n }\n return params;\n}\n\n// --- Nested Layouts ---\n\n// Build the layout chain for a route\nfunction buildLayoutChain(route, routes) {\n const layouts = [];\n if (!route.path) return layouts;\n\n // Check for nested layouts based on path segments\n const segments = route.path.split('/').filter(Boolean);\n let currentPath = '';\n\n for (const segment of segments) {\n currentPath += '/' + segment;\n\n // Find layout for this path level\n const layoutRoute = routes.find(r =>\n r.layout && r.path === currentPath + '/_layout'\n );\n if (layoutRoute) {\n layouts.push(layoutRoute.layout);\n }\n }\n\n // Add route's own layout if specified\n if (route.layout) {\n layouts.push(route.layout);\n }\n\n return layouts;\n}\n\n// --- Middleware redirect loop detection ---\nconst _redirectHistory = [];\nconst MAX_REDIRECTS = 10;\n\n// --- Router Component ---\n\nexport function Router({ routes, fallback, globalLayout }) {\n // Return a reactive function child. The Router component runs ONCE,\n // but the returned function re-evaluates whenever _url changes,\n // and the fine-grained runtime updates the DOM accordingly.\n return () => {\n const currentUrl = _url();\n const path = currentUrl.split('?')[0].split('#')[0];\n const search = currentUrl.split('?')[1]?.split('#')[0] || '';\n const isNavigating = _isNavigating();\n\n const matched = matchRoute(path, routes);\n\n if (matched) {\n batch(() => {\n _params.set(matched.params);\n _query.set(parseQuery(search));\n });\n\n const { route: r, params } = matched;\n const queryObj = parseQuery(search);\n\n // Run middleware (sync only \u2014 async middleware should use asyncGuard)\n if (r.middleware && r.middleware.length > 0) {\n for (const mw of r.middleware) {\n const result = mw({ path, params, query: queryObj, route: r });\n if (result === false) {\n // Middleware rejected \u2014 show fallback\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-403' }, h('h1', null, '403'), h('p', null, 'Access denied'));\n }\n if (typeof result === 'string') {\n // Redirect loop detection\n _redirectHistory.push(result);\n if (_redirectHistory.length > MAX_REDIRECTS) {\n const cycle = _redirectHistory.slice(-5).join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect loop detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Too many redirects. Check your middleware configuration.')\n );\n }\n // Check for direct cycle (A \u2192 B \u2192 A)\n const seen = new Set();\n let hasCycle = false;\n for (const url of _redirectHistory) {\n if (seen.has(url)) { hasCycle = true; break; }\n seen.add(url);\n }\n if (hasCycle) {\n const cycle = _redirectHistory.join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect cycle detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Circular redirect detected. Check your middleware configuration.')\n );\n }\n // Middleware returned a redirect path\n navigate(result, { replace: true });\n return null;\n }\n }\n }\n // Successful render \u2014 clear redirect history\n _redirectHistory.length = 0;\n\n // Build element with loading state support\n let element;\n\n if (r.loading && isNavigating) {\n element = h(r.loading, {});\n } else {\n element = h(r.component, {\n params,\n query: queryObj,\n route: r,\n });\n }\n\n // Wrap with per-route error boundary if specified\n if (r.error) {\n element = h(ErrorBoundary, { fallback: r.error }, element);\n }\n\n // Wrap with nested layouts (innermost to outermost)\n const layouts = buildLayoutChain(r, routes);\n for (const Layout of layouts.reverse()) {\n element = h(Layout, { params, query: queryObj }, element);\n }\n\n // Global layout wrapper\n if (globalLayout) {\n element = h(globalLayout, {}, element);\n }\n\n return element;\n }\n\n // 404\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-404' },\n h('h1', null, '404'),\n h('p', null, 'Page not found')\n );\n };\n}\n\n// --- Link Component ---\n\nexport function Link({\n href,\n class: cls,\n className,\n children,\n replace: rep,\n prefetch: shouldPrefetch = true,\n activeClass = 'active',\n exactActiveClass = 'exact-active',\n transition = true,\n ...rest\n}) {\n // Sanitize href \u2014 reject dangerous protocols\n const safeHref = isSafeUrl(href) ? href : 'about:blank';\n if (!isSafeUrl(href) && typeof console !== 'undefined') {\n console.warn(`[what-router] Link blocked unsafe href: ${href}`);\n }\n\n // Strip query string and hash from href for path comparison\n const hrefPath = safeHref.split('?')[0].split('#')[0];\n\n // Use a reactive function for class so active states update on navigation.\n // In the run-once model, reading route.path directly would snapshot it.\n const reactiveClass = () => {\n const currentPath = route.path;\n const isActive = hrefPath === '/'\n ? currentPath === '/'\n : currentPath === hrefPath || currentPath.startsWith(hrefPath + '/');\n const isExactActive = currentPath === hrefPath;\n\n return [\n cls || className,\n isActive && activeClass,\n isExactActive && exactActiveClass,\n ].filter(Boolean).join(' ') || undefined;\n };\n\n return h('a', {\n href: safeHref,\n class: reactiveClass,\n onclick: (e) => {\n // Only intercept left-clicks without modifiers\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n navigate(safeHref, { replace: rep, transition });\n },\n onmouseenter: shouldPrefetch ? () => prefetch(safeHref) : undefined,\n ...rest,\n }, ...(Array.isArray(children) ? children : [children]));\n}\n\n// --- NavLink with active states ---\n\nexport function NavLink(props) {\n return Link(props);\n}\n\n// --- Define Routes Helper ---\n// Creates route config from a flat object for convenience.\n\nexport function defineRoutes(config) {\n return Object.entries(config).map(([path, value]) => {\n if (typeof value === 'function') {\n return { path, component: value };\n }\n // Object form with layout, middleware, loading, error, etc.\n return { path, ...value };\n });\n}\n\n// --- Nested Route Helper ---\n\nexport function nestedRoutes(basePath, children, options = {}) {\n const { layout, loading, error } = options;\n\n return children.map(child => ({\n ...child,\n path: basePath + child.path,\n layout: child.layout || layout,\n loading: child.loading || loading,\n error: child.error || error,\n }));\n}\n\n// --- Route Groups ---\n// Group routes without affecting URL structure\n\nexport function routeGroup(name, routes, options = {}) {\n const { layout, middleware } = options;\n\n return routes.map(route => ({\n ...route,\n _group: name,\n layout: route.layout || layout,\n middleware: [...(route.middleware || []), ...(middleware || [])],\n }));\n}\n\n// --- Redirect ---\n\nexport function Redirect({ to }) {\n navigate(to, { replace: true });\n return null;\n}\n\n// --- Route Guards / Middleware ---\n\nexport function guard(check, fallback) {\n return (Component) => {\n return function GuardedRoute(props) {\n const result = check(props);\n\n // Support async guards\n if (result instanceof Promise) {\n // Return loading while checking\n return h('div', { class: 'what-guard-loading' }, 'Loading...');\n }\n\n if (result) {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n}\n\n// Async guard with suspense\nexport function asyncGuard(check, options = {}) {\n const { fallback = '/login', loading = null } = options;\n\n return (Component) => {\n return function AsyncGuardedRoute(props) {\n const status = signal('pending');\n const checkResult = signal(null);\n let cancelled = false;\n\n effect(() => {\n cancelled = false;\n Promise.resolve(check(props))\n .then(result => {\n if (cancelled) return;\n checkResult.set(result);\n status.set(result ? 'allowed' : 'denied');\n })\n .catch(() => {\n if (!cancelled) status.set('denied');\n });\n return () => { cancelled = true; };\n });\n\n // Return a reactive function child so status changes update the DOM.\n // Components run once, so reading status() outside a reactive wrapper\n // would snapshot the value and never update.\n return () => {\n const currentStatus = status();\n\n if (currentStatus === 'pending') {\n return loading ? h(loading, {}) : null;\n }\n\n if (currentStatus === 'allowed') {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n };\n}\n\n// --- Prefetch ---\n// Hint the browser to prefetch a route's assets.\n\nconst prefetchedUrls = new Set();\n\nexport function prefetch(href) {\n if (typeof document === 'undefined') return;\n if (prefetchedUrls.has(href)) return;\n prefetchedUrls.add(href);\n\n const link = document.createElement('link');\n link.rel = 'prefetch';\n link.href = href;\n document.head.appendChild(link);\n}\n\n// --- Scroll Restoration ---\n\nconst scrollPositions = new Map();\n\nexport function enableScrollRestoration() {\n if (typeof window === 'undefined') return;\n\n // Save scroll position before navigation\n window.addEventListener('beforeunload', () => {\n scrollPositions.set(location.pathname, window.scrollY);\n });\n\n // Restore scroll position after navigation\n effect(() => {\n const path = route.path;\n const savedPosition = scrollPositions.get(path);\n\n requestAnimationFrame(() => {\n if (savedPosition !== undefined) {\n window.scrollTo(0, savedPosition);\n } else if (route.hash) {\n const el = document.querySelector(route.hash);\n el?.scrollIntoView();\n } else {\n window.scrollTo(0, 0);\n }\n });\n });\n}\n\n// --- View Transition Helpers ---\n\nexport function viewTransitionName(name) {\n return { style: { viewTransitionName: name } };\n}\n\n// Configure view transition types\nexport function setViewTransition(type) {\n if (typeof document === 'undefined') return;\n document.documentElement.dataset.transition = type;\n}\n\n// --- useRoute Hook ---\n\nexport function useRoute() {\n return {\n path: computed(() => route.path),\n params: computed(() => route.params),\n query: computed(() => route.query),\n hash: computed(() => route.hash),\n isNavigating: computed(() => route.isNavigating),\n navigate,\n prefetch,\n };\n}\n\n// --- Outlet Component ---\n// For nested route rendering\n\nexport function Outlet({ children }) {\n // Children passed from parent layout\n return children || null;\n}\n\n// --- File-Based Router ---\n// Consumes routes generated by what-compiler's file router (virtual:what-routes).\n// Usage:\n// import { routes } from 'virtual:what-routes';\n// mount(<FileRouter routes={routes} />, '#app');\n\nexport function FileRouter({\n routes,\n layout: globalLayout,\n fallback,\n error: globalError,\n}) {\n // Convert file-router route format to Router's expected format\n const routerRoutes = routes.map(r => ({\n path: r.path,\n component: r.component,\n layout: r.layout || undefined,\n // Attach page mode as metadata for build system\n _mode: r.mode || 'client',\n }));\n\n // Router already returns a reactive function child \u2014 just delegate\n return Router({\n routes: routerRoutes,\n globalLayout,\n fallback: fallback || Default404,\n });\n}\n\nfunction Default404() {\n return h('div', { style: 'text-align:center;padding:60px 20px' },\n h('h1', { style: 'font-size:48px;margin-bottom:8px' }, '404'),\n h('p', { style: 'color:#64748b' }, 'Page not found'),\n );\n}\n"],
5
- "mappings": ";AAIA,SAAS,QAAQ,QAAQ,UAAU,OAAO,GAAG,qBAAqB;AAK3D,SAAS,UAAU,KAAK;AAC7B,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,UAAU,IAAI,KAAK;AAEzB,QAAM,aAAa,QAAQ,QAAQ,kBAAkB,EAAE,EAAE,YAAY;AACrE,MAAI,WAAW,WAAW,aAAa,EAAG,QAAO;AACjD,MAAI,WAAW,WAAW,OAAO,EAAG,QAAO;AAC3C,MAAI,WAAW,WAAW,WAAW,EAAG,QAAO;AAC/C,SAAO;AACT;AAIA,IAAM,OAAO,OAAO,OAAO,aAAa,cAAc,SAAS,WAAW,SAAS,SAAS,SAAS,OAAO,GAAG;AAC/G,IAAM,UAAU,OAAO,CAAC,CAAC;AACzB,IAAM,SAAS,OAAO,CAAC,CAAC;AACxB,IAAM,gBAAgB,OAAO,KAAK;AAClC,IAAM,mBAAmB,OAAO,IAAI;AAE7B,IAAM,QAAQ;AAAA,EACnB,IAAI,MAAM;AAAE,WAAO,KAAK;AAAA,EAAG;AAAA,EAC3B,IAAI,OAAO;AAAE,WAAO,KAAK,EAAE,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAAG;AAAA,EACxD,IAAI,SAAS;AAAE,WAAO,QAAQ;AAA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SAAS,aAAa;AACpB,SAAO;AAAA,IAAE;AAAA,IAAO,EAAE,OAAO,sCAAsC;AAAA,IAC7D,EAAE,MAAM,EAAE,OAAO,mCAAmC,GAAG,KAAK;AAAA,IAC5D,EAAE,KAAK,EAAE,OAAO,gBAAgB,GAAG,gBAAgB;AAAA,EACrD;AACF;",
6
- "names": ["h", "route"]
3
+ "sources": ["../src/index.js", "../src/match.js"],
4
+ "sourcesContent": ["// What Framework - Router\n// Production-grade file-based routing with nested layouts, loading states,\n// route groups, view transitions, and middleware.\n\nimport { signal, effect, computed, batch, h, ErrorBoundary } from 'what-core';\nimport { compilePath, matchRoute, parseQuery } from './match.js';\n\n// --- URL Sanitization ---\n// Rejects javascript:, data:, vbscript: protocols (case-insensitive, trimmed).\n\nexport function isSafeUrl(url) {\n if (typeof url !== 'string') return false;\n const trimmed = url.trim();\n // Check for dangerous protocols (case-insensitive, ignoring whitespace/control chars)\n const normalized = trimmed.replace(/[\\s\\x00-\\x1f]/g, '').toLowerCase();\n if (normalized.startsWith('javascript:')) return false;\n if (normalized.startsWith('data:')) return false;\n if (normalized.startsWith('vbscript:')) return false;\n return true;\n}\n\n// --- Route State (global singleton) ---\n\nconst _url = signal(typeof location !== 'undefined' ? location.pathname + location.search + location.hash : '/');\nconst _params = signal({});\nconst _query = signal({});\nconst _isNavigating = signal(false);\nconst _navigationError = signal(null);\n\nexport const route = {\n get url() { return _url(); },\n get path() { return _url().split('?')[0].split('#')[0]; },\n get params() { return _params(); },\n get query() { return _query(); },\n get hash() {\n const h = _url().split('#')[1];\n return h ? '#' + h : '';\n },\n get isNavigating() { return _isNavigating(); },\n get error() { return _navigationError(); },\n};\n\n// --- Navigation with View Transitions ---\n\nexport async function navigate(to, opts = {}) {\n const { replace = false, state = null, transition = true, _fromPopstate = false } = opts;\n\n // Reject unsafe URLs\n if (!isSafeUrl(to)) {\n if (typeof console !== 'undefined') {\n console.warn(`[what-router] Blocked navigation to unsafe URL: ${to}`);\n }\n return;\n }\n\n // Handle same-page hash links \u2014 use replaceState and scroll directly\n if (typeof window !== 'undefined' && to.startsWith('#')) {\n const currentUrl = _url();\n const basePath = currentUrl.split('#')[0];\n const newUrl = basePath + to;\n history.replaceState(state, '', newUrl);\n _url.set(newUrl);\n const el = document.querySelector(to);\n if (el) el.scrollIntoView({ behavior: 'smooth' });\n return;\n }\n\n // Don't navigate if already on the same URL\n if (to === _url()) return;\n\n // Prevent concurrent navigations \u2014 wait for current to finish\n if (_isNavigating.peek()) return;\n\n _isNavigating.set(true);\n _navigationError.set(null);\n\n const doNavigation = () => {\n // Skip history manipulation on popstate (browser already updated the URL)\n if (!_fromPopstate) {\n // Save scroll position for current URL before navigating away\n if (typeof window !== 'undefined') {\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n }\n if (replace) {\n history.replaceState(state, '', to);\n } else {\n history.pushState(state, '', to);\n }\n }\n _url.set(to);\n _isNavigating.set(false);\n };\n\n // Use View Transitions API if available and enabled\n if (transition && typeof document !== 'undefined' && document.startViewTransition) {\n try {\n await document.startViewTransition(doNavigation).finished;\n } catch (e) {\n // Transition failed, navigation still happened\n }\n } else {\n doNavigation();\n }\n}\n\n// Back/forward support \u2014 route through navigate() so middleware runs\nif (typeof window !== 'undefined') {\n window.addEventListener('popstate', () => {\n // Save scroll position for the URL we're leaving\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n\n const newUrl = location.pathname + location.search + location.hash;\n // Use _fromPopstate flag so navigate() skips pushState (browser already updated URL)\n navigate(newUrl, { replace: true, _fromPopstate: true, transition: false }).then(() => {\n // Restore saved scroll position for the URL we're arriving at\n const saved = scrollPositions.get(newUrl);\n if (saved) {\n requestAnimationFrame(() => window.scrollTo(saved.x, saved.y));\n }\n });\n });\n}\n\n// --- Route Matching ---\n// compilePath / matchRoute / parseQuery live in ./match.js (isomorphic, no DOM)\n// and are imported above so the server adapter can reuse them.\n\n// Re-export the matcher so `what-router` consumers (and the server adapter via\n// `what-router/match`) can import it from the package root too.\nexport { compilePath, matchRoute, parseQuery } from './match.js';\n\n// --- Nested Layouts ---\n\n// Build the layout chain for a route\nfunction buildLayoutChain(route, routes) {\n const layouts = [];\n if (!route.path) return layouts;\n\n // Check for nested layouts based on path segments\n const segments = route.path.split('/').filter(Boolean);\n let currentPath = '';\n\n for (const segment of segments) {\n currentPath += '/' + segment;\n\n // Find layout for this path level\n const layoutRoute = routes.find(r =>\n r.layout && r.path === currentPath + '/_layout'\n );\n if (layoutRoute) {\n layouts.push(layoutRoute.layout);\n }\n }\n\n // Add route's own layout if specified\n if (route.layout) {\n layouts.push(route.layout);\n }\n\n return layouts;\n}\n\n// --- Middleware redirect loop detection ---\nconst _redirectHistory = [];\nconst MAX_REDIRECTS = 10;\n\n// --- Router Component ---\n\nexport function Router({ routes, fallback, globalLayout }) {\n // Return a reactive function child. The Router component runs ONCE,\n // but the returned function re-evaluates whenever _url changes,\n // and the fine-grained runtime updates the DOM accordingly.\n return () => {\n const currentUrl = _url();\n const path = currentUrl.split('?')[0].split('#')[0];\n const search = currentUrl.split('?')[1]?.split('#')[0] || '';\n const isNavigating = _isNavigating();\n\n const matched = matchRoute(path, routes);\n\n if (matched) {\n batch(() => {\n _params.set(matched.params);\n _query.set(parseQuery(search));\n });\n\n const { route: r, params } = matched;\n const queryObj = parseQuery(search);\n\n // Run middleware (sync only \u2014 async middleware should use asyncGuard)\n if (r.middleware && r.middleware.length > 0) {\n for (const mw of r.middleware) {\n const result = mw({ path, params, query: queryObj, route: r });\n if (result === false) {\n // Middleware rejected \u2014 show fallback\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-403' }, h('h1', null, '403'), h('p', null, 'Access denied'));\n }\n if (typeof result === 'string') {\n // Redirect loop detection\n _redirectHistory.push(result);\n if (_redirectHistory.length > MAX_REDIRECTS) {\n const cycle = _redirectHistory.slice(-5).join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect loop detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Too many redirects. Check your middleware configuration.')\n );\n }\n // Check for direct cycle (A \u2192 B \u2192 A)\n const seen = new Set();\n let hasCycle = false;\n for (const url of _redirectHistory) {\n if (seen.has(url)) { hasCycle = true; break; }\n seen.add(url);\n }\n if (hasCycle) {\n const cycle = _redirectHistory.join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect cycle detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Circular redirect detected. Check your middleware configuration.')\n );\n }\n // Middleware returned a redirect path\n navigate(result, { replace: true });\n return null;\n }\n }\n }\n // Successful render \u2014 clear redirect history\n _redirectHistory.length = 0;\n\n // Build element with loading state support\n let element;\n\n if (r.loading && isNavigating) {\n element = h(r.loading, {});\n } else {\n element = h(r.component, {\n params,\n query: queryObj,\n route: r,\n });\n }\n\n // Wrap with per-route error boundary if specified\n if (r.error) {\n element = h(ErrorBoundary, { fallback: r.error }, element);\n }\n\n // Wrap with nested layouts (innermost to outermost)\n const layouts = buildLayoutChain(r, routes);\n for (const Layout of layouts.reverse()) {\n element = h(Layout, { params, query: queryObj }, element);\n }\n\n // Global layout wrapper\n if (globalLayout) {\n element = h(globalLayout, {}, element);\n }\n\n return element;\n }\n\n // 404\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-404' },\n h('h1', null, '404'),\n h('p', null, 'Page not found')\n );\n };\n}\n\n// --- Link Component ---\n\nexport function Link({\n href,\n class: cls,\n className,\n children,\n replace: rep,\n prefetch: shouldPrefetch = true,\n activeClass = 'active',\n exactActiveClass = 'exact-active',\n transition = true,\n ...rest\n}) {\n // Sanitize href \u2014 reject dangerous protocols\n const safeHref = isSafeUrl(href) ? href : 'about:blank';\n if (!isSafeUrl(href) && typeof console !== 'undefined') {\n console.warn(`[what-router] Link blocked unsafe href: ${href}`);\n }\n\n // Strip query string and hash from href for path comparison\n const hrefPath = safeHref.split('?')[0].split('#')[0];\n\n // Use a reactive function for class so active states update on navigation.\n // In the run-once model, reading route.path directly would snapshot it.\n const reactiveClass = () => {\n const currentPath = route.path;\n const isActive = hrefPath === '/'\n ? currentPath === '/'\n : currentPath === hrefPath || currentPath.startsWith(hrefPath + '/');\n const isExactActive = currentPath === hrefPath;\n\n return [\n cls || className,\n isActive && activeClass,\n isExactActive && exactActiveClass,\n ].filter(Boolean).join(' ') || undefined;\n };\n\n return h('a', {\n href: safeHref,\n class: reactiveClass,\n onclick: (e) => {\n // Only intercept left-clicks without modifiers\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n navigate(safeHref, { replace: rep, transition });\n },\n onmouseenter: shouldPrefetch ? () => prefetch(safeHref) : undefined,\n ...rest,\n }, ...(Array.isArray(children) ? children : [children]));\n}\n\n// --- NavLink with active states ---\n\nexport function NavLink(props) {\n return Link(props);\n}\n\n// --- Define Routes Helper ---\n// Creates route config from a flat object for convenience.\n\nexport function defineRoutes(config) {\n return Object.entries(config).map(([path, value]) => {\n if (typeof value === 'function') {\n return { path, component: value };\n }\n // Object form with layout, middleware, loading, error, etc.\n return { path, ...value };\n });\n}\n\n// --- Nested Route Helper ---\n\nexport function nestedRoutes(basePath, children, options = {}) {\n const { layout, loading, error } = options;\n\n return children.map(child => ({\n ...child,\n path: basePath + child.path,\n layout: child.layout || layout,\n loading: child.loading || loading,\n error: child.error || error,\n }));\n}\n\n// --- Route Groups ---\n// Group routes without affecting URL structure\n\nexport function routeGroup(name, routes, options = {}) {\n const { layout, middleware } = options;\n\n return routes.map(route => ({\n ...route,\n _group: name,\n layout: route.layout || layout,\n middleware: [...(route.middleware || []), ...(middleware || [])],\n }));\n}\n\n// --- Redirect ---\n\nexport function Redirect({ to }) {\n navigate(to, { replace: true });\n return null;\n}\n\n// --- Route Guards / Middleware ---\n\nexport function guard(check, fallback) {\n return (Component) => {\n return function GuardedRoute(props) {\n const result = check(props);\n\n // Support async guards\n if (result instanceof Promise) {\n // Return loading while checking\n return h('div', { class: 'what-guard-loading' }, 'Loading...');\n }\n\n if (result) {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n}\n\n// Async guard with suspense\nexport function asyncGuard(check, options = {}) {\n const { fallback = '/login', loading = null } = options;\n\n return (Component) => {\n return function AsyncGuardedRoute(props) {\n const status = signal('pending');\n const checkResult = signal(null);\n let cancelled = false;\n\n effect(() => {\n cancelled = false;\n Promise.resolve(check(props))\n .then(result => {\n if (cancelled) return;\n checkResult.set(result);\n status.set(result ? 'allowed' : 'denied');\n })\n .catch(() => {\n if (!cancelled) status.set('denied');\n });\n return () => { cancelled = true; };\n });\n\n // Return a reactive function child so status changes update the DOM.\n // Components run once, so reading status() outside a reactive wrapper\n // would snapshot the value and never update.\n return () => {\n const currentStatus = status();\n\n if (currentStatus === 'pending') {\n return loading ? h(loading, {}) : null;\n }\n\n if (currentStatus === 'allowed') {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n };\n}\n\n// --- Prefetch ---\n// Hint the browser to prefetch a route's assets.\n\nconst prefetchedUrls = new Set();\n\nexport function prefetch(href) {\n if (typeof document === 'undefined') return;\n if (prefetchedUrls.has(href)) return;\n prefetchedUrls.add(href);\n\n const link = document.createElement('link');\n link.rel = 'prefetch';\n link.href = href;\n document.head.appendChild(link);\n}\n\n// --- Scroll Restoration ---\n\nconst scrollPositions = new Map();\n\nexport function enableScrollRestoration() {\n if (typeof window === 'undefined') return;\n\n // Save scroll position before navigation\n window.addEventListener('beforeunload', () => {\n scrollPositions.set(location.pathname, window.scrollY);\n });\n\n // Restore scroll position after navigation\n effect(() => {\n const path = route.path;\n const savedPosition = scrollPositions.get(path);\n\n requestAnimationFrame(() => {\n if (savedPosition !== undefined) {\n window.scrollTo(0, savedPosition);\n } else if (route.hash) {\n const el = document.querySelector(route.hash);\n el?.scrollIntoView();\n } else {\n window.scrollTo(0, 0);\n }\n });\n });\n}\n\n// --- View Transition Helpers ---\n\nexport function viewTransitionName(name) {\n return { style: { viewTransitionName: name } };\n}\n\n// Configure view transition types\nexport function setViewTransition(type) {\n if (typeof document === 'undefined') return;\n document.documentElement.dataset.transition = type;\n}\n\n// --- useRoute Hook ---\n\nexport function useRoute() {\n return {\n path: computed(() => route.path),\n params: computed(() => route.params),\n query: computed(() => route.query),\n hash: computed(() => route.hash),\n isNavigating: computed(() => route.isNavigating),\n navigate,\n prefetch,\n };\n}\n\n// --- Outlet Component ---\n// For nested route rendering\n\nexport function Outlet({ children }) {\n // Children passed from parent layout\n return children || null;\n}\n\n// --- File-Based Router ---\n// Consumes routes generated by what-compiler's file router (virtual:what-routes).\n// Usage:\n// import { routes } from 'virtual:what-routes';\n// mount(<FileRouter routes={routes} />, '#app');\n\nexport function FileRouter({\n routes,\n layout: globalLayout,\n fallback,\n error: globalError,\n}) {\n // Convert file-router route format to Router's expected format\n const routerRoutes = routes.map(r => ({\n path: r.path,\n component: r.component,\n layout: r.layout || undefined,\n // Attach page mode as metadata for build system\n _mode: r.mode || 'client',\n }));\n\n // Router already returns a reactive function child \u2014 just delegate\n return Router({\n routes: routerRoutes,\n globalLayout,\n fallback: fallback || Default404,\n });\n}\n\nfunction Default404() {\n return h('div', { style: 'text-align:center;padding:60px 20px' },\n h('h1', { style: 'font-size:48px;margin-bottom:8px' }, '404'),\n h('p', { style: 'color:#64748b' }, 'Page not found'),\n );\n}\n", "// Isomorphic route matching \u2014 pure functions with no window/location/document\n// dependencies, so they are safe to import on the server (deploy adapter) as\n// well as in the client Router/FileRouter. Moved verbatim from index.js.\n\nexport function compilePath(path) {\n // /users/:id -> regex + param names\n // /posts/* -> catch-all\n // /[slug] -> dynamic (file-based syntax)\n // (group) -> route group (ignored in URL)\n\n // Remove route groups from path (they don't affect URL matching)\n const normalized = path\n .replace(/\\([\\w-]+\\)\\//g, '') // Remove (group)/ prefixes\n .replace(/\\[\\.\\.\\.(\\w+)\\]/g, (_, name) => `*:${name}`) // Preserve catch-all name\n .replace(/\\[(\\w+)\\]/g, ':$1'); // File-based [param] to :param\n\n const paramNames = [];\n let catchAll = null;\n\n const regexStr = normalized\n .split('/')\n .map(segment => {\n if (segment.startsWith('*:')) {\n catchAll = segment.slice(2);\n paramNames.push(catchAll);\n return '(.+)';\n }\n if (segment === '*') {\n catchAll = 'rest';\n paramNames.push('rest');\n return '(.+)';\n }\n if (segment.startsWith(':')) {\n paramNames.push(segment.slice(1));\n return '([^/]+)';\n }\n return segment.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n })\n .join('/');\n\n const regex = new RegExp(`^${regexStr}$`);\n return { regex, paramNames, catchAll };\n}\n\nexport function matchRoute(path, routes) {\n // Filter out routes without a path (layout-only routes, etc.)\n const routable = routes.filter(r => r.path);\n\n // Sort routes by specificity (more specific first)\n const sorted = routable.sort((a, b) => {\n const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);\n const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);\n return aSpecific - bSpecific;\n });\n\n for (const route of sorted) {\n const { regex, paramNames } = compilePath(route.path);\n const match = path.match(regex);\n if (match) {\n const params = {};\n paramNames.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1]);\n });\n return { route, params };\n }\n }\n return null;\n}\n\nexport function parseQuery(search) {\n const params = {};\n if (!search) return params;\n const qs = search.startsWith('?') ? search.slice(1) : search;\n for (const pair of qs.split('&')) {\n const [key, val] = pair.split('=');\n if (!key) continue;\n const decodedKey = decodeURIComponent(key);\n const decodedVal = val ? decodeURIComponent(val) : '';\n if (decodedKey in params) {\n // Collect repeated keys into arrays\n if (Array.isArray(params[decodedKey])) {\n params[decodedKey].push(decodedVal);\n } else {\n params[decodedKey] = [params[decodedKey], decodedVal];\n }\n } else {\n params[decodedKey] = decodedV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M;AACvC,SAAO,EAAE,OAAO,EAAE,oBAAoB,KAAK,EAAE;AAC/C;AAGO,SAAS,kBAAkB,MAAM;AACtC,MAAI,OAAO,aAAa,YAAa;AACrC,WAAS,gBAAgB,QAAQ,aAAa;AAChD;AAIO,SAAS,WAAW;AACzB,SAAO;AAAA,IACL,MAAM,SAAS,MAAM,MAAM,IAAI;AAAA,IAC/B,QAAQ,SAAS,MAAM,MAAM,MAAM;AAAA,IACnC,OAAO,SAAS,MAAM,MAAM,KAAK;AAAA,IACjC,MAAM,SAAS,MAAM,MAAM,IAAI;AAAA,IAC/B,cAAc,SAAS,MAAM,MAAM,YAAY;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,OAAO,EAAE,SAAS,GAAG;AAEnC,SAAO,YAAY;AACrB;AAQO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA,OAAO;AACT,GAAG;AAED,QAAM,eAAe,OAAO,IAAI,QAAM;AAAA,IACpC,MAAM,EAAE;AAAA,IACR,WAAW,EAAE;AAAA,IACb,QAAQ,EAAE,UAAU;AAAA;AAAA,IAEpB,OAAO,EAAE,QAAQ;AAAA,EACnB,EAAE;AAGF,SAAO,OAAO;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA,UAAU,YAAY;AAAA,EACxB,CAAC;AACH;AAEA,SAAS,aAAa;AACpB,SAAO;AAAA,IAAE;AAAA,IAAO,EAAE,OAAO,sCAAsC;AAAA,IAC7D,EAAE,MAAM,EAAE,OAAO,mCAAmC,GAAG,KAAK;AAAA,IAC5D,EAAE,KAAK,EAAE,OAAO,gBAAgB,GAAG,gBAAgB;AAAA,EACrD;AACF;",
6
+ "names": ["route", "h", "route"]
7
7
  }
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{signal as w,effect as _,computed as b,batch as $,h as a,ErrorBoundary as W}from"what-core";function k(e){if(typeof e!="string")return!1;let n=e.trim().replace(/[\s\x00-\x1f]/g,"").toLowerCase();return!(n.startsWith("javascript:")||n.startsWith("data:")||n.startsWith("vbscript:"))}var h=w(typeof location<"u"?location.pathname+location.search+location.hash:"/"),L=w({}),N=w({}),g=w(!1),U=w(null),m={get url(){return h()},get path(){return h().split("?")[0].split("#")[0]},get params(){return L()},get query(){return N()},get hash(){let e=h().split("#")[1];return e?"#"+e:""},get isNavigating(){return g()},get error(){return U()}};async function x(e,t={}){let{replace:n=!1,state:s=null,transition:o=!0,_fromPopstate:i=!1}=t;if(!k(e)){typeof console<"u"&&console.warn(`[what-router] Blocked navigation to unsafe URL: ${e}`);return}if(typeof window<"u"&&e.startsWith("#")){let f=h().split("#")[0]+e;history.replaceState(s,"",f),h.set(f);let l=document.querySelector(e);l&&l.scrollIntoView({behavior:"smooth"});return}if(e===h()||g.peek())return;g.set(!0),U.set(null);let r=()=>{i||(typeof window<"u"&&P.set(h(),{x:scrollX,y:scrollY}),n?history.replaceState(s,"",e):history.pushState(s,"",e)),h.set(e),g.set(!1)};if(o&&typeof document<"u"&&document.startViewTransition)try{await document.startViewTransition(r).finished}catch{}else r()}typeof window<"u"&&window.addEventListener("popstate",()=>{P.set(h(),{x:scrollX,y:scrollY});let e=location.pathname+location.search+location.hash;x(e,{replace:!0,_fromPopstate:!0,transition:!1}).then(()=>{let t=P.get(e);t&&requestAnimationFrame(()=>window.scrollTo(t.x,t.y))})});function j(e){let t=e.replace(/\([\w-]+\)\//g,"").replace(/\[\.\.\.(\w+)\]/g,(r,c)=>`*:${c}`).replace(/\[(\w+)\]/g,":$1"),n=[],s=null,o=t.split("/").map(r=>r.startsWith("*:")?(s=r.slice(2),n.push(s),"(.+)"):r==="*"?(s="rest",n.push("rest"),"(.+)"):r.startsWith(":")?(n.push(r.slice(1)),"([^/]+)"):r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("/");return{regex:new RegExp(`^${o}$`),paramNames:n,catchAll:s}}function I(e,t){let s=t.filter(o=>o.path).sort((o,i)=>{let r=(o.path.match(/:/g)||[]).length+(o.path.includes("*")?100:0),c=(i.path.match(/:/g)||[]).length+(i.path.includes("*")?100:0);return r-c});for(let o of s){let{regex:i,paramNames:r}=j(o.path),c=e.match(i);if(c){let u={};return r.forEach((f,l)=>{u[f]=decodeURIComponent(c[l+1])}),{route:o,params:u}}}return null}function C(e){let t={};if(!e)return t;let n=e.startsWith("?")?e.slice(1):e;for(let s of n.split("&")){let[o,i]=s.split("=");if(!o)continue;let r=decodeURIComponent(o),c=i?decodeURIComponent(i):"";r in t?Array.isArray(t[r])?t[r].push(c):t[r]=[t[r],c]:t[r]=c}return t}function V(e,t){let n=[];if(!e.path)return n;let s=e.path.split("/").filter(Boolean),o="";for(let i of s){o+="/"+i;let r=t.find(c=>c.layout&&c.path===o+"/_layout");r&&n.push(r.layout)}return e.layout&&n.push(e.layout),n}var y=[],K=10;function B({routes:e,fallback:t,globalLayout:n}){return()=>{let s=h(),o=s.split("?")[0].split("#")[0],i=s.split("?")[1]?.split("#")[0]||"",r=g(),c=I(o,e);if(c){$(()=>{L.set(c.params),N.set(C(i))});let{route:u,params:f}=c,l=C(i);if(u.middleware&&u.middleware.length>0)for(let d of u.middleware){let v=d({path:o,params:f,query:l,route:u});if(v===!1)return t?a(t,{}):a("div",{class:"what-403"},a("h1",null,"403"),a("p",null,"Access denied"));if(typeof v=="string"){if(y.push(v),y.length>K){let R=y.slice(-5).join(" \u2192 ");return y.length=0,console.error(`[what-router] Redirect loop detected: ${R}`),g.set(!1),a("div",{class:"what-redirect-loop"},a("h1",null,"Redirect Loop"),a("p",null,"Too many redirects. Check your middleware configuration."))}let S=new Set,A=!1;for(let R of y){if(S.has(R)){A=!0;break}S.add(R)}if(A){let R=y.join(" \u2192 ");return y.length=0,console.error(`[what-router] Redirect cycle detected: ${R}`),g.set(!1),a("div",{class:"what-redirect-loop"},a("h1",null,"Redirect Loop"),a("p",null,"Circular redirect detected. Check your middleware configuration."))}return x(v,{replace:!0}),null}}y.length=0;let p;u.loading&&r?p=a(u.loading,{}):p=a(u.component,{params:f,query:l,route:u}),u.error&&(p=a(W,{fallback:u.error},p));let q=V(u,e);for(let d of q.reverse())p=a(d,{params:f,query:l},p);return n&&(p=a(n,{},p)),p}return t?a(t,{}):a("div",{class:"what-404"},a("h1",null,"404"),a("p",null,"Page not found"))}}function G({href:e,class:t,className:n,children:s,replace:o,prefetch:i=!0,activeClass:r="active",exactActiveClass:c="exact-active",transition:u=!0,...f}){let l=k(e)?e:"about:blank";!k(e)&&typeof console<"u"&&console.warn(`[what-router] Link blocked unsafe href: ${e}`);let p=l.split("?")[0].split("#")[0];return a("a",{href:l,class:()=>{let d=m.path,v=p==="/"?d==="/":d===p||d.startsWith(p+"/");return[t||n,v&&r,d===p&&c].filter(Boolean).join(" ")||void 0},onclick:d=>{d.ctrlKey||d.metaKey||d.shiftKey||d.altKey||d.button!==0||(d.preventDefault(),x(l,{replace:o,transition:u}))},onmouseenter:i?()=>T(l):void 0,...f},...Array.isArray(s)?s:[s])}function F(e){return G(e)}function O(e){return Object.entries(e).map(([t,n])=>typeof n=="function"?{path:t,component:n}:{path:t,...n})}function X(e,t,n={}){let{layout:s,loading:o,error:i}=n;return t.map(r=>({...r,path:e+r.path,layout:r.layout||s,loading:r.loading||o,error:r.error||i}))}function Y(e,t,n={}){let{layout:s,middleware:o}=n;return t.map(i=>({...i,_group:e,layout:i.layout||s,middleware:[...i.middleware||[],...o||[]]}))}function H({to:e}){return x(e,{replace:!0}),null}function M(e,t){return n=>function(o){let i=e(o);return i instanceof Promise?a("div",{class:"what-guard-loading"},"Loading..."):i?a(n,o):typeof t=="string"?(x(t,{replace:!0}),null):a(t,o)}}function Q(e,t={}){let{fallback:n="/login",loading:s=null}=t;return o=>function(r){let c=w("pending"),u=w(null),f=!1;return _(()=>(f=!1,Promise.resolve(e(r)).then(l=>{f||(u.set(l),c.set(l?"allowed":"denied"))}).catch(()=>{f||c.set("denied")}),()=>{f=!0})),()=>{let l=c();return l==="pending"?s?a(s,{}):null:l==="allowed"?a(o,r):typeof n=="string"?(x(n,{replace:!0}),null):a(n,r)}}}var E=new Set;function T(e){if(typeof document>"u"||E.has(e))return;E.add(e);let t=document.createElement("link");t.rel="prefetch",t.href=e,document.head.appendChild(t)}var P=new Map;function J(){typeof window>"u"||(window.addEventListener("beforeunload",()=>{P.set(location.pathname,window.scrollY)}),_(()=>{let e=m.path,t=P.get(e);requestAnimationFrame(()=>{t!==void 0?window.scrollTo(0,t):m.hash?document.querySelector(m.hash)?.scrollIntoView():window.scrollTo(0,0)})}))}function Z(e){return{style:{viewTransitionName:e}}}function ee(e){typeof document>"u"||(document.documentElement.dataset.transition=e)}function te(){return{path:b(()=>m.path),params:b(()=>m.params),query:b(()=>m.query),hash:b(()=>m.hash),isNavigating:b(()=>m.isNavigating),navigate:x,prefetch:T}}function ne({children:e}){return e||null}function re({routes:e,layout:t,fallback:n,error:s}){let o=e.map(i=>({path:i.path,component:i.component,layout:i.layout||void 0,_mode:i.mode||"client"}));return B({routes:o,globalLayout:t,fallback:n||z})}function z(){return a("div",{style:"text-align:center;padding:60px 20px"},a("h1",{style:"font-size:48px;margin-bottom:8px"},"404"),a("p",{style:"color:#64748b"},"Page not found"))}export{re as FileRouter,G as Link,F as NavLink,ne as Outlet,H as Redirect,B as Router,Q as asyncGuard,O as defineRoutes,J as enableScrollRestoration,M as guard,k as isSafeUrl,x as navigate,X as nestedRoutes,T as prefetch,m as route,Y as routeGroup,ee as setViewTransition,te as useRoute,Z as viewTransitionName};
1
+ import{signal as w,effect as N,computed as b,batch as j,h as s,ErrorBoundary as I}from"what-core";function _(e){let t=e.replace(/\([\w-]+\)\//g,"").replace(/\[\.\.\.(\w+)\]/g,(r,c)=>`*:${c}`).replace(/\[(\w+)\]/g,":$1"),n=[],a=null,o=t.split("/").map(r=>r.startsWith("*:")?(a=r.slice(2),n.push(a),"(.+)"):r==="*"?(a="rest",n.push("rest"),"(.+)"):r.startsWith(":")?(n.push(r.slice(1)),"([^/]+)"):r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("/");return{regex:new RegExp(`^${o}$`),paramNames:n,catchAll:a}}function q(e,t){let a=t.filter(o=>o.path).sort((o,i)=>{let r=(o.path.match(/:/g)||[]).length+(o.path.includes("*")?100:0),c=(i.path.match(/:/g)||[]).length+(i.path.includes("*")?100:0);return r-c});for(let o of a){let{regex:i,paramNames:r}=_(o.path),c=e.match(i);if(c){let u={};return r.forEach((f,l)=>{u[f]=decodeURIComponent(c[l+1])}),{route:o,params:u}}}return null}function S(e){let t={};if(!e)return t;let n=e.startsWith("?")?e.slice(1):e;for(let a of n.split("&")){let[o,i]=a.split("=");if(!o)continue;let r=decodeURIComponent(o),c=i?decodeURIComponent(i):"";r in t?Array.isArray(t[r])?t[r].push(c):t[r]=[t[r],c]:t[r]=c}return t}function A(e){if(typeof e!="string")return!1;let n=e.trim().replace(/[\s\x00-\x1f]/g,"").toLowerCase();return!(n.startsWith("javascript:")||n.startsWith("data:")||n.startsWith("vbscript:"))}var h=w(typeof location<"u"?location.pathname+location.search+location.hash:"/"),U=w({}),T=w({}),g=w(!1),$=w(null),m={get url(){return h()},get path(){return h().split("?")[0].split("#")[0]},get params(){return U()},get query(){return T()},get hash(){let e=h().split("#")[1];return e?"#"+e:""},get isNavigating(){return g()},get error(){return $()}};async function x(e,t={}){let{replace:n=!1,state:a=null,transition:o=!0,_fromPopstate:i=!1}=t;if(!A(e)){typeof console<"u"&&console.warn(`[what-router] Blocked navigation to unsafe URL: ${e}`);return}if(typeof window<"u"&&e.startsWith("#")){let f=h().split("#")[0]+e;history.replaceState(a,"",f),h.set(f);let l=document.querySelector(e);l&&l.scrollIntoView({behavior:"smooth"});return}if(e===h()||g.peek())return;g.set(!0),$.set(null);let r=()=>{i||(typeof window<"u"&&P.set(h(),{x:scrollX,y:scrollY}),n?history.replaceState(a,"",e):history.pushState(a,"",e)),h.set(e),g.set(!1)};if(o&&typeof document<"u"&&document.startViewTransition)try{await document.startViewTransition(r).finished}catch{}else r()}typeof window<"u"&&window.addEventListener("popstate",()=>{P.set(h(),{x:scrollX,y:scrollY});let e=location.pathname+location.search+location.hash;x(e,{replace:!0,_fromPopstate:!0,transition:!1}).then(()=>{let t=P.get(e);t&&requestAnimationFrame(()=>window.scrollTo(t.x,t.y))})});function V(e,t){let n=[];if(!e.path)return n;let a=e.path.split("/").filter(Boolean),o="";for(let i of a){o+="/"+i;let r=t.find(c=>c.layout&&c.path===o+"/_layout");r&&n.push(r.layout)}return e.layout&&n.push(e.layout),n}var y=[],K=10;function B({routes:e,fallback:t,globalLayout:n}){return()=>{let a=h(),o=a.split("?")[0].split("#")[0],i=a.split("?")[1]?.split("#")[0]||"",r=g(),c=q(o,e);if(c){j(()=>{U.set(c.params),T.set(S(i))});let{route:u,params:f}=c,l=S(i);if(u.middleware&&u.middleware.length>0)for(let d of u.middleware){let v=d({path:o,params:f,query:l,route:u});if(v===!1)return t?s(t,{}):s("div",{class:"what-403"},s("h1",null,"403"),s("p",null,"Access denied"));if(typeof v=="string"){if(y.push(v),y.length>K){let R=y.slice(-5).join(" \u2192 ");return y.length=0,console.error(`[what-router] Redirect loop detected: ${R}`),g.set(!1),s("div",{class:"what-redirect-loop"},s("h1",null,"Redirect Loop"),s("p",null,"Too many redirects. Check your middleware configuration."))}let k=new Set,E=!1;for(let R of y){if(k.has(R)){E=!0;break}k.add(R)}if(E){let R=y.join(" \u2192 ");return y.length=0,console.error(`[what-router] Redirect cycle detected: ${R}`),g.set(!1),s("div",{class:"what-redirect-loop"},s("h1",null,"Redirect Loop"),s("p",null,"Circular redirect detected. Check your middleware configuration."))}return x(v,{replace:!0}),null}}y.length=0;let p;u.loading&&r?p=s(u.loading,{}):p=s(u.component,{params:f,query:l,route:u}),u.error&&(p=s(I,{fallback:u.error},p));let C=V(u,e);for(let d of C.reverse())p=s(d,{params:f,query:l},p);return n&&(p=s(n,{},p)),p}return t?s(t,{}):s("div",{class:"what-404"},s("h1",null,"404"),s("p",null,"Page not found"))}}function G({href:e,class:t,className:n,children:a,replace:o,prefetch:i=!0,activeClass:r="active",exactActiveClass:c="exact-active",transition:u=!0,...f}){let l=A(e)?e:"about:blank";!A(e)&&typeof console<"u"&&console.warn(`[what-router] Link blocked unsafe href: ${e}`);let p=l.split("?")[0].split("#")[0];return s("a",{href:l,class:()=>{let d=m.path,v=p==="/"?d==="/":d===p||d.startsWith(p+"/");return[t||n,v&&r,d===p&&c].filter(Boolean).join(" ")||void 0},onclick:d=>{d.ctrlKey||d.metaKey||d.shiftKey||d.altKey||d.button!==0||(d.preventDefault(),x(l,{replace:o,transition:u}))},onmouseenter:i?()=>W(l):void 0,...f},...Array.isArray(a)?a:[a])}function X(e){return G(e)}function Y(e){return Object.entries(e).map(([t,n])=>typeof n=="function"?{path:t,component:n}:{path:t,...n})}function H(e,t,n={}){let{layout:a,loading:o,error:i}=n;return t.map(r=>({...r,path:e+r.path,layout:r.layout||a,loading:r.loading||o,error:r.error||i}))}function M(e,t,n={}){let{layout:a,middleware:o}=n;return t.map(i=>({...i,_group:e,layout:i.layout||a,middleware:[...i.middleware||[],...o||[]]}))}function J({to:e}){return x(e,{replace:!0}),null}function Z(e,t){return n=>function(o){let i=e(o);return i instanceof Promise?s("div",{class:"what-guard-loading"},"Loading..."):i?s(n,o):typeof t=="string"?(x(t,{replace:!0}),null):s(t,o)}}function ee(e,t={}){let{fallback:n="/login",loading:a=null}=t;return o=>function(r){let c=w("pending"),u=w(null),f=!1;return N(()=>(f=!1,Promise.resolve(e(r)).then(l=>{f||(u.set(l),c.set(l?"allowed":"denied"))}).catch(()=>{f||c.set("denied")}),()=>{f=!0})),()=>{let l=c();return l==="pending"?a?s(a,{}):null:l==="allowed"?s(o,r):typeof n=="string"?(x(n,{replace:!0}),null):s(n,r)}}}var L=new Set;function W(e){if(typeof document>"u"||L.has(e))return;L.add(e);let t=document.createElement("link");t.rel="prefetch",t.href=e,document.head.appendChild(t)}var P=new Map;function te(){typeof window>"u"||(window.addEventListener("beforeunload",()=>{P.set(location.pathname,window.scrollY)}),N(()=>{let e=m.path,t=P.get(e);requestAnimationFrame(()=>{t!==void 0?window.scrollTo(0,t):m.hash?document.querySelector(m.hash)?.scrollIntoView():window.scrollTo(0,0)})}))}function ne(e){return{style:{viewTransitionName:e}}}function re(e){typeof document>"u"||(document.documentElement.dataset.transition=e)}function oe(){return{path:b(()=>m.path),params:b(()=>m.params),query:b(()=>m.query),hash:b(()=>m.hash),isNavigating:b(()=>m.isNavigating),navigate:x,prefetch:W}}function ie({children:e}){return e||null}function ae({routes:e,layout:t,fallback:n,error:a}){let o=e.map(i=>({path:i.path,component:i.component,layout:i.layout||void 0,_mode:i.mode||"client"}));return B({routes:o,globalLayout:t,fallback:n||z})}function z(){return s("div",{style:"text-align:center;padding:60px 20px"},s("h1",{style:"font-size:48px;margin-bottom:8px"},"404"),s("p",{style:"color:#64748b"},"Page not found"))}export{ae as FileRouter,G as Link,X as NavLink,ie as Outlet,J as Redirect,B as Router,ee as asyncGuard,_ as compilePath,Y as defineRoutes,te as enableScrollRestoration,Z as guard,A as isSafeUrl,q as matchRoute,x as navigate,H as nestedRoutes,S as parseQuery,W as prefetch,m as route,M as routeGroup,re as setViewTransition,oe as useRoute,ne as viewTransitionName};
2
2
  //# sourceMappingURL=index.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["// What Framework - Router\n// Production-grade file-based routing with nested layouts, loading states,\n// route groups, view transitions, and middleware.\n\nimport { signal, effect, computed, batch, h, ErrorBoundary } from 'what-core';\n\n// --- URL Sanitization ---\n// Rejects javascript:, data:, vbscript: protocols (case-insensitive, trimmed).\n\nexport function isSafeUrl(url) {\n if (typeof url !== 'string') return false;\n const trimmed = url.trim();\n // Check for dangerous protocols (case-insensitive, ignoring whitespace/control chars)\n const normalized = trimmed.replace(/[\\s\\x00-\\x1f]/g, '').toLowerCase();\n if (normalized.startsWith('javascript:')) return false;\n if (normalized.startsWith('data:')) return false;\n if (normalized.startsWith('vbscript:')) return false;\n return true;\n}\n\n// --- Route State (global singleton) ---\n\nconst _url = signal(typeof location !== 'undefined' ? location.pathname + location.search + location.hash : '/');\nconst _params = signal({});\nconst _query = signal({});\nconst _isNavigating = signal(false);\nconst _navigationError = signal(null);\n\nexport const route = {\n get url() { return _url(); },\n get path() { return _url().split('?')[0].split('#')[0]; },\n get params() { return _params(); },\n get query() { return _query(); },\n get hash() {\n const h = _url().split('#')[1];\n return h ? '#' + h : '';\n },\n get isNavigating() { return _isNavigating(); },\n get error() { return _navigationError(); },\n};\n\n// --- Navigation with View Transitions ---\n\nexport async function navigate(to, opts = {}) {\n const { replace = false, state = null, transition = true, _fromPopstate = false } = opts;\n\n // Reject unsafe URLs\n if (!isSafeUrl(to)) {\n if (typeof console !== 'undefined') {\n console.warn(`[what-router] Blocked navigation to unsafe URL: ${to}`);\n }\n return;\n }\n\n // Handle same-page hash links \u2014 use replaceState and scroll directly\n if (typeof window !== 'undefined' && to.startsWith('#')) {\n const currentUrl = _url();\n const basePath = currentUrl.split('#')[0];\n const newUrl = basePath + to;\n history.replaceState(state, '', newUrl);\n _url.set(newUrl);\n const el = document.querySelector(to);\n if (el) el.scrollIntoView({ behavior: 'smooth' });\n return;\n }\n\n // Don't navigate if already on the same URL\n if (to === _url()) return;\n\n // Prevent concurrent navigations \u2014 wait for current to finish\n if (_isNavigating.peek()) return;\n\n _isNavigating.set(true);\n _navigationError.set(null);\n\n const doNavigation = () => {\n // Skip history manipulation on popstate (browser already updated the URL)\n if (!_fromPopstate) {\n // Save scroll position for current URL before navigating away\n if (typeof window !== 'undefined') {\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n }\n if (replace) {\n history.replaceState(state, '', to);\n } else {\n history.pushState(state, '', to);\n }\n }\n _url.set(to);\n _isNavigating.set(false);\n };\n\n // Use View Transitions API if available and enabled\n if (transition && typeof document !== 'undefined' && document.startViewTransition) {\n try {\n await document.startViewTransition(doNavigation).finished;\n } catch (e) {\n // Transition failed, navigation still happened\n }\n } else {\n doNavigation();\n }\n}\n\n// Back/forward support \u2014 route through navigate() so middleware runs\nif (typeof window !== 'undefined') {\n window.addEventListener('popstate', () => {\n // Save scroll position for the URL we're leaving\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n\n const newUrl = location.pathname + location.search + location.hash;\n // Use _fromPopstate flag so navigate() skips pushState (browser already updated URL)\n navigate(newUrl, { replace: true, _fromPopstate: true, transition: false }).then(() => {\n // Restore saved scroll position for the URL we're arriving at\n const saved = scrollPositions.get(newUrl);\n if (saved) {\n requestAnimationFrame(() => window.scrollTo(saved.x, saved.y));\n }\n });\n });\n}\n\n// --- Route Matching ---\n\nfunction compilePath(path) {\n // /users/:id -> regex + param names\n // /posts/* -> catch-all\n // /[slug] -> dynamic (file-based syntax)\n // (group) -> route group (ignored in URL)\n\n // Remove route groups from path (they don't affect URL matching)\n const normalized = path\n .replace(/\\([\\w-]+\\)\\//g, '') // Remove (group)/ prefixes\n .replace(/\\[\\.\\.\\.(\\w+)\\]/g, (_, name) => `*:${name}`) // Preserve catch-all name\n .replace(/\\[(\\w+)\\]/g, ':$1'); // File-based [param] to :param\n\n const paramNames = [];\n let catchAll = null;\n\n const regexStr = normalized\n .split('/')\n .map(segment => {\n if (segment.startsWith('*:')) {\n catchAll = segment.slice(2);\n paramNames.push(catchAll);\n return '(.+)';\n }\n if (segment === '*') {\n catchAll = 'rest';\n paramNames.push('rest');\n return '(.+)';\n }\n if (segment.startsWith(':')) {\n paramNames.push(segment.slice(1));\n return '([^/]+)';\n }\n return segment.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n })\n .join('/');\n\n const regex = new RegExp(`^${regexStr}$`);\n return { regex, paramNames, catchAll };\n}\n\nfunction matchRoute(path, routes) {\n // Filter out routes without a path (layout-only routes, etc.)\n const routable = routes.filter(r => r.path);\n\n // Sort routes by specificity (more specific first)\n const sorted = routable.sort((a, b) => {\n const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);\n const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);\n return aSpecific - bSpecific;\n });\n\n for (const route of sorted) {\n const { regex, paramNames } = compilePath(route.path);\n const match = path.match(regex);\n if (match) {\n const params = {};\n paramNames.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1]);\n });\n return { route, params };\n }\n }\n return null;\n}\n\nfunction parseQuery(search) {\n const params = {};\n if (!search) return params;\n const qs = search.startsWith('?') ? search.slice(1) : search;\n for (const pair of qs.split('&')) {\n const [key, val] = pair.split('=');\n if (!key) continue;\n const decodedKey = decodeURIComponent(key);\n const decodedVal = val ? decodeURIComponent(val) : '';\n if (decodedKey in params) {\n // Collect repeated keys into arrays\n if (Array.isArray(params[decodedKey])) {\n params[decodedKey].push(decodedVal);\n } else {\n params[decodedKey] = [params[decodedKey], decodedVal];\n }\n } else {\n params[decodedKey] = decodedVal;\n }\n }\n return params;\n}\n\n// --- Nested Layouts ---\n\n// Build the layout chain for a route\nfunction buildLayoutChain(route, routes) {\n const layouts = [];\n if (!route.path) return layouts;\n\n // Check for nested layouts based on path segments\n const segments = route.path.split('/').filter(Boolean);\n let currentPath = '';\n\n for (const segment of segments) {\n currentPath += '/' + segment;\n\n // Find layout for this path level\n const layoutRoute = routes.find(r =>\n r.layout && r.path === currentPath + '/_layout'\n );\n if (layoutRoute) {\n layouts.push(layoutRoute.layout);\n }\n }\n\n // Add route's own layout if specified\n if (route.layout) {\n layouts.push(route.layout);\n }\n\n return layouts;\n}\n\n// --- Middleware redirect loop detection ---\nconst _redirectHistory = [];\nconst MAX_REDIRECTS = 10;\n\n// --- Router Component ---\n\nexport function Router({ routes, fallback, globalLayout }) {\n // Return a reactive function child. The Router component runs ONCE,\n // but the returned function re-evaluates whenever _url changes,\n // and the fine-grained runtime updates the DOM accordingly.\n return () => {\n const currentUrl = _url();\n const path = currentUrl.split('?')[0].split('#')[0];\n const search = currentUrl.split('?')[1]?.split('#')[0] || '';\n const isNavigating = _isNavigating();\n\n const matched = matchRoute(path, routes);\n\n if (matched) {\n batch(() => {\n _params.set(matched.params);\n _query.set(parseQuery(search));\n });\n\n const { route: r, params } = matched;\n const queryObj = parseQuery(search);\n\n // Run middleware (sync only \u2014 async middleware should use asyncGuard)\n if (r.middleware && r.middleware.length > 0) {\n for (const mw of r.middleware) {\n const result = mw({ path, params, query: queryObj, route: r });\n if (result === false) {\n // Middleware rejected \u2014 show fallback\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-403' }, h('h1', null, '403'), h('p', null, 'Access denied'));\n }\n if (typeof result === 'string') {\n // Redirect loop detection\n _redirectHistory.push(result);\n if (_redirectHistory.length > MAX_REDIRECTS) {\n const cycle = _redirectHistory.slice(-5).join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect loop detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Too many redirects. Check your middleware configuration.')\n );\n }\n // Check for direct cycle (A \u2192 B \u2192 A)\n const seen = new Set();\n let hasCycle = false;\n for (const url of _redirectHistory) {\n if (seen.has(url)) { hasCycle = true; break; }\n seen.add(url);\n }\n if (hasCycle) {\n const cycle = _redirectHistory.join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect cycle detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Circular redirect detected. Check your middleware configuration.')\n );\n }\n // Middleware returned a redirect path\n navigate(result, { replace: true });\n return null;\n }\n }\n }\n // Successful render \u2014 clear redirect history\n _redirectHistory.length = 0;\n\n // Build element with loading state support\n let element;\n\n if (r.loading && isNavigating) {\n element = h(r.loading, {});\n } else {\n element = h(r.component, {\n params,\n query: queryObj,\n route: r,\n });\n }\n\n // Wrap with per-route error boundary if specified\n if (r.error) {\n element = h(ErrorBoundary, { fallback: r.error }, element);\n }\n\n // Wrap with nested layouts (innermost to outermost)\n const layouts = buildLayoutChain(r, routes);\n for (const Layout of layouts.reverse()) {\n element = h(Layout, { params, query: queryObj }, element);\n }\n\n // Global layout wrapper\n if (globalLayout) {\n element = h(globalLayout, {}, element);\n }\n\n return element;\n }\n\n // 404\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-404' },\n h('h1', null, '404'),\n h('p', null, 'Page not found')\n );\n };\n}\n\n// --- Link Component ---\n\nexport function Link({\n href,\n class: cls,\n className,\n children,\n replace: rep,\n prefetch: shouldPrefetch = true,\n activeClass = 'active',\n exactActiveClass = 'exact-active',\n transition = true,\n ...rest\n}) {\n // Sanitize href \u2014 reject dangerous protocols\n const safeHref = isSafeUrl(href) ? href : 'about:blank';\n if (!isSafeUrl(href) && typeof console !== 'undefined') {\n console.warn(`[what-router] Link blocked unsafe href: ${href}`);\n }\n\n // Strip query string and hash from href for path comparison\n const hrefPath = safeHref.split('?')[0].split('#')[0];\n\n // Use a reactive function for class so active states update on navigation.\n // In the run-once model, reading route.path directly would snapshot it.\n const reactiveClass = () => {\n const currentPath = route.path;\n const isActive = hrefPath === '/'\n ? currentPath === '/'\n : currentPath === hrefPath || currentPath.startsWith(hrefPath + '/');\n const isExactActive = currentPath === hrefPath;\n\n return [\n cls || className,\n isActive && activeClass,\n isExactActive && exactActiveClass,\n ].filter(Boolean).join(' ') || undefined;\n };\n\n return h('a', {\n href: safeHref,\n class: reactiveClass,\n onclick: (e) => {\n // Only intercept left-clicks without modifiers\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n navigate(safeHref, { replace: rep, transition });\n },\n onmouseenter: shouldPrefetch ? () => prefetch(safeHref) : undefined,\n ...rest,\n }, ...(Array.isArray(children) ? children : [children]));\n}\n\n// --- NavLink with active states ---\n\nexport function NavLink(props) {\n return Link(props);\n}\n\n// --- Define Routes Helper ---\n// Creates route config from a flat object for convenience.\n\nexport function defineRoutes(config) {\n return Object.entries(config).map(([path, value]) => {\n if (typeof value === 'function') {\n return { path, component: value };\n }\n // Object form with layout, middleware, loading, error, etc.\n return { path, ...value };\n });\n}\n\n// --- Nested Route Helper ---\n\nexport function nestedRoutes(basePath, children, options = {}) {\n const { layout, loading, error } = options;\n\n return children.map(child => ({\n ...child,\n path: basePath + child.path,\n layout: child.layout || layout,\n loading: child.loading || loading,\n error: child.error || error,\n }));\n}\n\n// --- Route Groups ---\n// Group routes without affecting URL structure\n\nexport function routeGroup(name, routes, options = {}) {\n const { layout, middleware } = options;\n\n return routes.map(route => ({\n ...route,\n _group: name,\n layout: route.layout || layout,\n middleware: [...(route.middleware || []), ...(middleware || [])],\n }));\n}\n\n// --- Redirect ---\n\nexport function Redirect({ to }) {\n navigate(to, { replace: true });\n return null;\n}\n\n// --- Route Guards / Middleware ---\n\nexport function guard(check, fallback) {\n return (Component) => {\n return function GuardedRoute(props) {\n const result = check(props);\n\n // Support async guards\n if (result instanceof Promise) {\n // Return loading while checking\n return h('div', { class: 'what-guard-loading' }, 'Loading...');\n }\n\n if (result) {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n}\n\n// Async guard with suspense\nexport function asyncGuard(check, options = {}) {\n const { fallback = '/login', loading = null } = options;\n\n return (Component) => {\n return function AsyncGuardedRoute(props) {\n const status = signal('pending');\n const checkResult = signal(null);\n let cancelled = false;\n\n effect(() => {\n cancelled = false;\n Promise.resolve(check(props))\n .then(result => {\n if (cancelled) return;\n checkResult.set(result);\n status.set(result ? 'allowed' : 'denied');\n })\n .catch(() => {\n if (!cancelled) status.set('denied');\n });\n return () => { cancelled = true; };\n });\n\n // Return a reactive function child so status changes update the DOM.\n // Components run once, so reading status() outside a reactive wrapper\n // would snapshot the value and never update.\n return () => {\n const currentStatus = status();\n\n if (currentStatus === 'pending') {\n return loading ? h(loading, {}) : null;\n }\n\n if (currentStatus === 'allowed') {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n };\n}\n\n// --- Prefetch ---\n// Hint the browser to prefetch a route's assets.\n\nconst prefetchedUrls = new Set();\n\nexport function prefetch(href) {\n if (typeof document === 'undefined') return;\n if (prefetchedUrls.has(href)) return;\n prefetchedUrls.add(href);\n\n const link = document.createElement('link');\n link.rel = 'prefetch';\n link.href = href;\n document.head.appendChild(link);\n}\n\n// --- Scroll Restoration ---\n\nconst scrollPositions = new Map();\n\nexport function enableScrollRestoration() {\n if (typeof window === 'undefined') return;\n\n // Save scroll position before navigation\n window.addEventListener('beforeunload', () => {\n scrollPositions.set(location.pathname, window.scrollY);\n });\n\n // Restore scroll position after navigation\n effect(() => {\n const path = route.path;\n const savedPosition = scrollPositions.get(path);\n\n requestAnimationFrame(() => {\n if (savedPosition !== undefined) {\n window.scrollTo(0, savedPosition);\n } else if (route.hash) {\n const el = document.querySelector(route.hash);\n el?.scrollIntoView();\n } else {\n window.scrollTo(0, 0);\n }\n });\n });\n}\n\n// --- View Transition Helpers ---\n\nexport function viewTransitionName(name) {\n return { style: { viewTransitionName: name } };\n}\n\n// Configure view transition types\nexport function setViewTransition(type) {\n if (typeof document === 'undefined') return;\n document.documentElement.dataset.transition = type;\n}\n\n// --- useRoute Hook ---\n\nexport function useRoute() {\n return {\n path: computed(() => route.path),\n params: computed(() => route.params),\n query: computed(() => route.query),\n hash: computed(() => route.hash),\n isNavigating: computed(() => route.isNavigating),\n navigate,\n prefetch,\n };\n}\n\n// --- Outlet Component ---\n// For nested route rendering\n\nexport function Outlet({ children }) {\n // Children passed from parent layout\n return children || null;\n}\n\n// --- File-Based Router ---\n// Consumes routes generated by what-compiler's file router (virtual:what-routes).\n// Usage:\n// import { routes } from 'virtual:what-routes';\n// mount(<FileRouter routes={routes} />, '#app');\n\nexport function FileRouter({\n routes,\n layout: globalLayout,\n fallback,\n error: globalError,\n}) {\n // Convert file-router route format to Router's expected format\n const routerRoutes = routes.map(r => ({\n path: r.path,\n component: r.component,\n layout: r.layout || undefined,\n // Attach page mode as metadata for build system\n _mode: r.mode || 'client',\n }));\n\n // Router already returns a reactive function child \u2014 just delegate\n return Router({\n routes: routerRoutes,\n globalLayout,\n fallback: fallback || Default404,\n });\n}\n\nfunction Default404() {\n return h('div', { style: 'text-align:center;padding:60px 20px' },\n h('h1', { style: 'font-size:48px;margin-bottom:8px' }, '404'),\n h('p', { style: 'color:#64748b' }, 'Page not found'),\n );\n}\n"],
5
- "mappings": "AAIA,OAAS,UAAAA,EAAQ,UAAAC,EAAQ,YAAAC,EAAU,SAAAC,EAAO,KAAAC,EAAG,iBAAAC,MAAqB,YAK3D,SAASC,EAAUC,EAAK,CAC7B,GAAI,OAAOA,GAAQ,SAAU,MAAO,GAGpC,IAAMC,EAFUD,EAAI,KAAK,EAEE,QAAQ,iBAAkB,EAAE,EAAE,YAAY,EAGrE,MAFI,EAAAC,EAAW,WAAW,aAAa,GACnCA,EAAW,WAAW,OAAO,GAC7BA,EAAW,WAAW,WAAW,EAEvC,CAIA,IAAMC,EAAOT,EAAO,OAAO,SAAa,IAAc,SAAS,SAAW,SAAS,OAAS,SAAS,KAAO,GAAG,EACzGU,EAAUV,EAAO,CAAC,CAAC,EACnBW,EAASX,EAAO,CAAC,CAAC,EAClBY,EAAgBZ,EAAO,EAAK,EAC5Ba,EAAmBb,EAAO,IAAI,EAEvBc,EAAQ,CACnB,IAAI,KAAM,CAAE,OAAOL,EAAK,CAAG,EAC3B,IAAI,MAAO,CAAE,OAAOA,EAAK,EAAE,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,CAAG,EACxD,IAAI,QAAS,CAAE,OAAOC,EAAQ,CAAG,EACjC,IAAI,OAAQ,CAAE,OAAOC,EAAO,CAAG,EAC/B,IAAI,MAAO,CACT,IAAMP,EAAIK,EAAK,EAAE,MAAM,GAAG,EAAE,CAAC,EAC7B,OAAOL,EAAI,IAAMA,EAAI,EACvB,EACA,IA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E,MAAO,qCAAsC,EAC7DA,EAAE,KAAM,CAAE,MAAO,kCAAmC,EAAG,KAAK,EAC5DA,EAAE,IAAK,CAAE,MAAO,eAAgB,EAAG,gBAAgB,CACrD,CACF",
6
- "names": ["signal", "effect", "computed", "batch", "h", "ErrorBoundary", "isSafeUrl", "url", "normalized", "_url", "_params", "_query", "_isNavigating", "_navigationError", "route", "navigate", "to", "opts", "replace", "state", "transition", "_fromPopstate", "newUrl", "el", "doNavigation", "scrollPositions", "saved", "compilePath", "path", "_", "name", "paramNames", "catchAll", "regexStr", "segment", "matchRoute", "routes", "sorted", "r", "a", "b", "aSpecific", "bSpecific", "regex", "match", "params", "i", "parseQuery", "search", "qs", "pair", "key", "val", "decodedKey", "decodedVal", "buildLayoutChain", "layouts", "segments", "currentPath", "layoutRoute", "_redirectHistory", "MAX_REDIRECTS", "Router", "fallback", "globalLayout", "currentUrl", "isNavigating", "matched", "queryObj", "mw", "result", "cycle", "seen", "hasCycle", "element", "Layout", "Link", "href", "cls", "className", "children", "rep", "shouldPrefetch", "activeClass", "exactActiveClass", "rest", "safeHref", "hrefPath", "isActive", "e", "prefetch", "NavLink", "props", "defineRoutes", "config", "value", "nestedRoutes", "basePath", "options", "layout", "loading", "error", "child", "routeGroup", "middleware", "Redirect", "guard", "check", "Component", "asyncGuard", "status", "checkResult", "cancelled", "currentStatus", "prefetchedUrls", "link", "enableScrollRestoration", "savedPosition", "viewTransitionName", "setViewTransition", "type", "useRoute", "Outlet", "FileRouter", "globalError", "routerRoutes", "Default404"]
3
+ "sources": ["../src/index.js", "../src/match.js"],
4
+ "sourcesContent": ["// What Framework - Router\n// Production-grade file-based routing with nested layouts, loading states,\n// route groups, view transitions, and middleware.\n\nimport { signal, effect, computed, batch, h, ErrorBoundary } from 'what-core';\nimport { compilePath, matchRoute, parseQuery } from './match.js';\n\n// --- URL Sanitization ---\n// Rejects javascript:, data:, vbscript: protocols (case-insensitive, trimmed).\n\nexport function isSafeUrl(url) {\n if (typeof url !== 'string') return false;\n const trimmed = url.trim();\n // Check for dangerous protocols (case-insensitive, ignoring whitespace/control chars)\n const normalized = trimmed.replace(/[\\s\\x00-\\x1f]/g, '').toLowerCase();\n if (normalized.startsWith('javascript:')) return false;\n if (normalized.startsWith('data:')) return false;\n if (normalized.startsWith('vbscript:')) return false;\n return true;\n}\n\n// --- Route State (global singleton) ---\n\nconst _url = signal(typeof location !== 'undefined' ? location.pathname + location.search + location.hash : '/');\nconst _params = signal({});\nconst _query = signal({});\nconst _isNavigating = signal(false);\nconst _navigationError = signal(null);\n\nexport const route = {\n get url() { return _url(); },\n get path() { return _url().split('?')[0].split('#')[0]; },\n get params() { return _params(); },\n get query() { return _query(); },\n get hash() {\n const h = _url().split('#')[1];\n return h ? '#' + h : '';\n },\n get isNavigating() { return _isNavigating(); },\n get error() { return _navigationError(); },\n};\n\n// --- Navigation with View Transitions ---\n\nexport async function navigate(to, opts = {}) {\n const { replace = false, state = null, transition = true, _fromPopstate = false } = opts;\n\n // Reject unsafe URLs\n if (!isSafeUrl(to)) {\n if (typeof console !== 'undefined') {\n console.warn(`[what-router] Blocked navigation to unsafe URL: ${to}`);\n }\n return;\n }\n\n // Handle same-page hash links \u2014 use replaceState and scroll directly\n if (typeof window !== 'undefined' && to.startsWith('#')) {\n const currentUrl = _url();\n const basePath = currentUrl.split('#')[0];\n const newUrl = basePath + to;\n history.replaceState(state, '', newUrl);\n _url.set(newUrl);\n const el = document.querySelector(to);\n if (el) el.scrollIntoView({ behavior: 'smooth' });\n return;\n }\n\n // Don't navigate if already on the same URL\n if (to === _url()) return;\n\n // Prevent concurrent navigations \u2014 wait for current to finish\n if (_isNavigating.peek()) return;\n\n _isNavigating.set(true);\n _navigationError.set(null);\n\n const doNavigation = () => {\n // Skip history manipulation on popstate (browser already updated the URL)\n if (!_fromPopstate) {\n // Save scroll position for current URL before navigating away\n if (typeof window !== 'undefined') {\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n }\n if (replace) {\n history.replaceState(state, '', to);\n } else {\n history.pushState(state, '', to);\n }\n }\n _url.set(to);\n _isNavigating.set(false);\n };\n\n // Use View Transitions API if available and enabled\n if (transition && typeof document !== 'undefined' && document.startViewTransition) {\n try {\n await document.startViewTransition(doNavigation).finished;\n } catch (e) {\n // Transition failed, navigation still happened\n }\n } else {\n doNavigation();\n }\n}\n\n// Back/forward support \u2014 route through navigate() so middleware runs\nif (typeof window !== 'undefined') {\n window.addEventListener('popstate', () => {\n // Save scroll position for the URL we're leaving\n scrollPositions.set(_url(), { x: scrollX, y: scrollY });\n\n const newUrl = location.pathname + location.search + location.hash;\n // Use _fromPopstate flag so navigate() skips pushState (browser already updated URL)\n navigate(newUrl, { replace: true, _fromPopstate: true, transition: false }).then(() => {\n // Restore saved scroll position for the URL we're arriving at\n const saved = scrollPositions.get(newUrl);\n if (saved) {\n requestAnimationFrame(() => window.scrollTo(saved.x, saved.y));\n }\n });\n });\n}\n\n// --- Route Matching ---\n// compilePath / matchRoute / parseQuery live in ./match.js (isomorphic, no DOM)\n// and are imported above so the server adapter can reuse them.\n\n// Re-export the matcher so `what-router` consumers (and the server adapter via\n// `what-router/match`) can import it from the package root too.\nexport { compilePath, matchRoute, parseQuery } from './match.js';\n\n// --- Nested Layouts ---\n\n// Build the layout chain for a route\nfunction buildLayoutChain(route, routes) {\n const layouts = [];\n if (!route.path) return layouts;\n\n // Check for nested layouts based on path segments\n const segments = route.path.split('/').filter(Boolean);\n let currentPath = '';\n\n for (const segment of segments) {\n currentPath += '/' + segment;\n\n // Find layout for this path level\n const layoutRoute = routes.find(r =>\n r.layout && r.path === currentPath + '/_layout'\n );\n if (layoutRoute) {\n layouts.push(layoutRoute.layout);\n }\n }\n\n // Add route's own layout if specified\n if (route.layout) {\n layouts.push(route.layout);\n }\n\n return layouts;\n}\n\n// --- Middleware redirect loop detection ---\nconst _redirectHistory = [];\nconst MAX_REDIRECTS = 10;\n\n// --- Router Component ---\n\nexport function Router({ routes, fallback, globalLayout }) {\n // Return a reactive function child. The Router component runs ONCE,\n // but the returned function re-evaluates whenever _url changes,\n // and the fine-grained runtime updates the DOM accordingly.\n return () => {\n const currentUrl = _url();\n const path = currentUrl.split('?')[0].split('#')[0];\n const search = currentUrl.split('?')[1]?.split('#')[0] || '';\n const isNavigating = _isNavigating();\n\n const matched = matchRoute(path, routes);\n\n if (matched) {\n batch(() => {\n _params.set(matched.params);\n _query.set(parseQuery(search));\n });\n\n const { route: r, params } = matched;\n const queryObj = parseQuery(search);\n\n // Run middleware (sync only \u2014 async middleware should use asyncGuard)\n if (r.middleware && r.middleware.length > 0) {\n for (const mw of r.middleware) {\n const result = mw({ path, params, query: queryObj, route: r });\n if (result === false) {\n // Middleware rejected \u2014 show fallback\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-403' }, h('h1', null, '403'), h('p', null, 'Access denied'));\n }\n if (typeof result === 'string') {\n // Redirect loop detection\n _redirectHistory.push(result);\n if (_redirectHistory.length > MAX_REDIRECTS) {\n const cycle = _redirectHistory.slice(-5).join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect loop detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Too many redirects. Check your middleware configuration.')\n );\n }\n // Check for direct cycle (A \u2192 B \u2192 A)\n const seen = new Set();\n let hasCycle = false;\n for (const url of _redirectHistory) {\n if (seen.has(url)) { hasCycle = true; break; }\n seen.add(url);\n }\n if (hasCycle) {\n const cycle = _redirectHistory.join(' \u2192 ');\n _redirectHistory.length = 0;\n console.error(`[what-router] Redirect cycle detected: ${cycle}`);\n _isNavigating.set(false);\n return h('div', { class: 'what-redirect-loop' },\n h('h1', null, 'Redirect Loop'),\n h('p', null, 'Circular redirect detected. Check your middleware configuration.')\n );\n }\n // Middleware returned a redirect path\n navigate(result, { replace: true });\n return null;\n }\n }\n }\n // Successful render \u2014 clear redirect history\n _redirectHistory.length = 0;\n\n // Build element with loading state support\n let element;\n\n if (r.loading && isNavigating) {\n element = h(r.loading, {});\n } else {\n element = h(r.component, {\n params,\n query: queryObj,\n route: r,\n });\n }\n\n // Wrap with per-route error boundary if specified\n if (r.error) {\n element = h(ErrorBoundary, { fallback: r.error }, element);\n }\n\n // Wrap with nested layouts (innermost to outermost)\n const layouts = buildLayoutChain(r, routes);\n for (const Layout of layouts.reverse()) {\n element = h(Layout, { params, query: queryObj }, element);\n }\n\n // Global layout wrapper\n if (globalLayout) {\n element = h(globalLayout, {}, element);\n }\n\n return element;\n }\n\n // 404\n if (fallback) return h(fallback, {});\n return h('div', { class: 'what-404' },\n h('h1', null, '404'),\n h('p', null, 'Page not found')\n );\n };\n}\n\n// --- Link Component ---\n\nexport function Link({\n href,\n class: cls,\n className,\n children,\n replace: rep,\n prefetch: shouldPrefetch = true,\n activeClass = 'active',\n exactActiveClass = 'exact-active',\n transition = true,\n ...rest\n}) {\n // Sanitize href \u2014 reject dangerous protocols\n const safeHref = isSafeUrl(href) ? href : 'about:blank';\n if (!isSafeUrl(href) && typeof console !== 'undefined') {\n console.warn(`[what-router] Link blocked unsafe href: ${href}`);\n }\n\n // Strip query string and hash from href for path comparison\n const hrefPath = safeHref.split('?')[0].split('#')[0];\n\n // Use a reactive function for class so active states update on navigation.\n // In the run-once model, reading route.path directly would snapshot it.\n const reactiveClass = () => {\n const currentPath = route.path;\n const isActive = hrefPath === '/'\n ? currentPath === '/'\n : currentPath === hrefPath || currentPath.startsWith(hrefPath + '/');\n const isExactActive = currentPath === hrefPath;\n\n return [\n cls || className,\n isActive && activeClass,\n isExactActive && exactActiveClass,\n ].filter(Boolean).join(' ') || undefined;\n };\n\n return h('a', {\n href: safeHref,\n class: reactiveClass,\n onclick: (e) => {\n // Only intercept left-clicks without modifiers\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n navigate(safeHref, { replace: rep, transition });\n },\n onmouseenter: shouldPrefetch ? () => prefetch(safeHref) : undefined,\n ...rest,\n }, ...(Array.isArray(children) ? children : [children]));\n}\n\n// --- NavLink with active states ---\n\nexport function NavLink(props) {\n return Link(props);\n}\n\n// --- Define Routes Helper ---\n// Creates route config from a flat object for convenience.\n\nexport function defineRoutes(config) {\n return Object.entries(config).map(([path, value]) => {\n if (typeof value === 'function') {\n return { path, component: value };\n }\n // Object form with layout, middleware, loading, error, etc.\n return { path, ...value };\n });\n}\n\n// --- Nested Route Helper ---\n\nexport function nestedRoutes(basePath, children, options = {}) {\n const { layout, loading, error } = options;\n\n return children.map(child => ({\n ...child,\n path: basePath + child.path,\n layout: child.layout || layout,\n loading: child.loading || loading,\n error: child.error || error,\n }));\n}\n\n// --- Route Groups ---\n// Group routes without affecting URL structure\n\nexport function routeGroup(name, routes, options = {}) {\n const { layout, middleware } = options;\n\n return routes.map(route => ({\n ...route,\n _group: name,\n layout: route.layout || layout,\n middleware: [...(route.middleware || []), ...(middleware || [])],\n }));\n}\n\n// --- Redirect ---\n\nexport function Redirect({ to }) {\n navigate(to, { replace: true });\n return null;\n}\n\n// --- Route Guards / Middleware ---\n\nexport function guard(check, fallback) {\n return (Component) => {\n return function GuardedRoute(props) {\n const result = check(props);\n\n // Support async guards\n if (result instanceof Promise) {\n // Return loading while checking\n return h('div', { class: 'what-guard-loading' }, 'Loading...');\n }\n\n if (result) {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n}\n\n// Async guard with suspense\nexport function asyncGuard(check, options = {}) {\n const { fallback = '/login', loading = null } = options;\n\n return (Component) => {\n return function AsyncGuardedRoute(props) {\n const status = signal('pending');\n const checkResult = signal(null);\n let cancelled = false;\n\n effect(() => {\n cancelled = false;\n Promise.resolve(check(props))\n .then(result => {\n if (cancelled) return;\n checkResult.set(result);\n status.set(result ? 'allowed' : 'denied');\n })\n .catch(() => {\n if (!cancelled) status.set('denied');\n });\n return () => { cancelled = true; };\n });\n\n // Return a reactive function child so status changes update the DOM.\n // Components run once, so reading status() outside a reactive wrapper\n // would snapshot the value and never update.\n return () => {\n const currentStatus = status();\n\n if (currentStatus === 'pending') {\n return loading ? h(loading, {}) : null;\n }\n\n if (currentStatus === 'allowed') {\n return h(Component, props);\n }\n\n if (typeof fallback === 'string') {\n navigate(fallback, { replace: true });\n return null;\n }\n return h(fallback, props);\n };\n };\n };\n}\n\n// --- Prefetch ---\n// Hint the browser to prefetch a route's assets.\n\nconst prefetchedUrls = new Set();\n\nexport function prefetch(href) {\n if (typeof document === 'undefined') return;\n if (prefetchedUrls.has(href)) return;\n prefetchedUrls.add(href);\n\n const link = document.createElement('link');\n link.rel = 'prefetch';\n link.href = href;\n document.head.appendChild(link);\n}\n\n// --- Scroll Restoration ---\n\nconst scrollPositions = new Map();\n\nexport function enableScrollRestoration() {\n if (typeof window === 'undefined') return;\n\n // Save scroll position before navigation\n window.addEventListener('beforeunload', () => {\n scrollPositions.set(location.pathname, window.scrollY);\n });\n\n // Restore scroll position after navigation\n effect(() => {\n const path = route.path;\n const savedPosition = scrollPositions.get(path);\n\n requestAnimationFrame(() => {\n if (savedPosition !== undefined) {\n window.scrollTo(0, savedPosition);\n } else if (route.hash) {\n const el = document.querySelector(route.hash);\n el?.scrollIntoView();\n } else {\n window.scrollTo(0, 0);\n }\n });\n });\n}\n\n// --- View Transition Helpers ---\n\nexport function viewTransitionName(name) {\n return { style: { viewTransitionName: name } };\n}\n\n// Configure view transition types\nexport function setViewTransition(type) {\n if (typeof document === 'undefined') return;\n document.documentElement.dataset.transition = type;\n}\n\n// --- useRoute Hook ---\n\nexport function useRoute() {\n return {\n path: computed(() => route.path),\n params: computed(() => route.params),\n query: computed(() => route.query),\n hash: computed(() => route.hash),\n isNavigating: computed(() => route.isNavigating),\n navigate,\n prefetch,\n };\n}\n\n// --- Outlet Component ---\n// For nested route rendering\n\nexport function Outlet({ children }) {\n // Children passed from parent layout\n return children || null;\n}\n\n// --- File-Based Router ---\n// Consumes routes generated by what-compiler's file router (virtual:what-routes).\n// Usage:\n// import { routes } from 'virtual:what-routes';\n// mount(<FileRouter routes={routes} />, '#app');\n\nexport function FileRouter({\n routes,\n layout: globalLayout,\n fallback,\n error: globalError,\n}) {\n // Convert file-router route format to Router's expected format\n const routerRoutes = routes.map(r => ({\n path: r.path,\n component: r.component,\n layout: r.layout || undefined,\n // Attach page mode as metadata for build system\n _mode: r.mode || 'client',\n }));\n\n // Router already returns a reactive function child \u2014 just delegate\n return Router({\n routes: routerRoutes,\n globalLayout,\n fallback: fallback || Default404,\n });\n}\n\nfunction Default404() {\n return h('div', { style: 'text-align:center;padding:60px 20px' },\n h('h1', { style: 'font-size:48px;margin-bottom:8px' }, '404'),\n h('p', { style: 'color:#64748b' }, 'Page not found'),\n );\n}\n", "// Isomorphic route matching \u2014 pure functions with no window/location/document\n// dependencies, so they are safe to import on the server (deploy adapter) as\n// well as in the client Router/FileRouter. Moved verbatim from index.js.\n\nexport function compilePath(path) {\n // /users/:id -> regex + param names\n // /posts/* -> catch-all\n // /[slug] -> dynamic (file-based syntax)\n // (group) -> route group (ignored in URL)\n\n // Remove route groups from path (they don't affect URL matching)\n const normalized = path\n .replace(/\\([\\w-]+\\)\\//g, '') // Remove (group)/ prefixes\n .replace(/\\[\\.\\.\\.(\\w+)\\]/g, (_, name) => `*:${name}`) // Preserve catch-all name\n .replace(/\\[(\\w+)\\]/g, ':$1'); // File-based [param] to :param\n\n const paramNames = [];\n let catchAll = null;\n\n const regexStr = normalized\n .split('/')\n .map(segment => {\n if (segment.startsWith('*:')) {\n catchAll = segment.slice(2);\n paramNames.push(catchAll);\n return '(.+)';\n }\n if (segment === '*') {\n catchAll = 'rest';\n paramNames.push('rest');\n return '(.+)';\n }\n if (segment.startsWith(':')) {\n paramNames.push(segment.slice(1));\n return '([^/]+)';\n }\n return segment.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n })\n .join('/');\n\n const regex = new RegExp(`^${regexStr}$`);\n return { regex, paramNames, catchAll };\n}\n\nexport function matchRoute(path, routes) {\n // Filter out routes without a path (layout-only routes, etc.)\n const routable = routes.filter(r => r.path);\n\n // Sort routes by specificity (more specific first)\n const sorted = routable.sort((a, b) => {\n const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);\n const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);\n return aSpecific - bSpecific;\n });\n\n for (const route of sorted) {\n const { regex, paramNames } = compilePath(route.path);\n const match = path.match(regex);\n if (match) {\n const params = {};\n paramNames.forEach((name, i) => {\n params[name] = decodeURIComponent(match[i + 1]);\n });\n return { route, params };\n }\n }\n return null;\n}\n\nexport function parseQuery(search) {\n const params = {};\n if (!search) return params;\n const qs = search.startsWith('?') ? search.slice(1) : search;\n for (const pair of qs.split('&')) {\n const [key, val] = pair.split('=');\n if (!key) continue;\n const decodedKey = decodeURIComponent(key);\n const decodedVal = val ? decodeURIComponent(val) : '';\n if (decodedKey in params) {\n // Collect repeated keys into arrays\n if (Array.isArray(params[decodedKey])) {\n params[decodedKey].push(decodedVal);\n } else {\n params[decodedKey] = [params[decodedKey], decodedVal];\n }\n } else {\n params[decodedKey] = decodedVal;\n }\n }\n return params;\n}\n"],
5
+ "mappings": "AAIA,OAAS,UAAAA,EAAQ,UAAAC,EAAQ,YAAAC,EAAU,SAAAC,EAAO,KAAAC,EAAG,iBAAAC,MAAqB,YCA3D,SAASC,EAAYC,EAAM,CAOhC,IAAMC,EAAaD,EAChB,QAAQ,gBAAiB,EAAE,EAC3B,QAAQ,mBAAoB,CAACE,EAAGC,IAAS,KAAKA,CAAI,EAAE,EACpD,QAAQ,aAAc,KAAK,EAExBC,EAAa,CAAC,EAChBC,EAAW,KAETC,EAAWL,EACd,MAAM,GAAG,EACT,IAAIM,GACCA,EAAQ,WAAW,IAAI,GACzBF,EAAWE,EAAQ,MAAM,CAAC,EAC1BH,EAAW,KAAKC,CAAQ,EACjB,QAELE,IAAY,KACdF,EAAW,OACXD,EAAW,KAAK,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GAAO,CAAE,SAAA7C,CAAS,EAAG,CAEnC,OAAOA,GAAY,IACrB,CAQO,SAAS8C,GAAW,CACzB,OAAAhF,EACA,OAAQW,EACR,SAAAD,EACA,MAAOuE,CACT,EAAG,CAED,IAAMC,EAAelF,EAAO,IAAIM,IAAM,CACpC,KAAMA,EAAE,KACR,UAAWA,EAAE,UACb,OAAQA,EAAE,QAAU,OAEpB,MAAOA,EAAE,MAAQ,QACnB,EAAE,EAGF,OAAOG,EAAO,CACZ,OAAQyE,EACR,aAAAvE,EACA,SAAUD,GAAYyE,CACxB,CAAC,CACH,CAEA,SAASA,GAAa,CACpB,OAAOjG,EAAE,MAAO,CAAE,MAAO,qCAAsC,EAC7DA,EAAE,KAAM,CAAE,MAAO,kCAAmC,EAAG,KAAK,EAC5DA,EAAE,IAAK,CAAE,MAAO,eAAgB,EAAG,gBAAgB,CACrD,CACF",
6
+ "names": ["signal", "effect", "computed", "batch", "h", "ErrorBoundary", "compilePath", "path", "normalized", "_", "name", "paramNames", "catchAll", "regexStr", "segment", "matchRoute", "routes", "sorted", "r", "a", "b", "aSpecific", "bSpecific", "route", "regex", "match", "params", "i", "parseQuery", "search", "qs", "pair", "key", "val", "decodedKey", "decodedVal", "isSafeUrl", "url", "normalized", "_url", "signal", "_params", "_query", "_isNavigating", "_navigationError", "route", "h", "navigate", "to", "opts", "replace", "state", "transition", "_fromPopstate", "newUrl", "el", "doNavigation", "scrollPositions", "saved", "buildLayoutChain", "routes", "layouts", "segments", "currentPath", "segment", "layoutRoute", "r", "_redirectHistory", "MAX_REDIRECTS", "Router", "fallback", "globalLayout", "currentUrl", "path", "search", "isNavigating", "matched", "matchRoute", "batch", "parseQuery", "params", "queryObj", "mw", "result", "cycle", "seen", "hasCycle", "element", "ErrorBoundary", "Layout", "Link", "href", "cls", "className", "children", "rep", "shouldPrefetch", "activeClass", "exactActiveClass", "rest", "safeHref", "hrefPath", "isActive", "e", "prefetch", "NavLink", "props", "defineRoutes", "config", "value", "nestedRoutes", "basePath", "options", "layout", "loading", "error", "child", "routeGroup", "name", "middleware", "Redirect", "guard", "check", "Component", "asyncGuard", "status", "checkResult", "cancelled", "effect", "currentStatus", "prefetchedUrls", "link", "enableScrollRestoration", "savedPosition", "viewTransitionName", "setViewTransition", "type", "useRoute", "computed", "Outlet", "FileRouter", "globalError", "routerRoutes", "Default404"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-router",
3
- "version": "0.8.4",
3
+ "version": "0.10.0",
4
4
  "description": "What Framework - File-based & programmatic router with View Transitions",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -10,6 +10,10 @@
10
10
  "types": "./index.d.ts",
11
11
  "production": "./dist/index.min.js",
12
12
  "import": "./src/index.js"
13
+ },
14
+ "./match": {
15
+ "production": "./dist/match.min.js",
16
+ "import": "./src/match.js"
13
17
  }
14
18
  },
15
19
  "files": [
@@ -28,7 +32,7 @@
28
32
  "author": "ZVN DEV (https://zvndev.com)",
29
33
  "license": "MIT",
30
34
  "peerDependencies": {
31
- "what-core": "^0.8.4"
35
+ "what-core": "^0.10.0"
32
36
  },
33
37
  "repository": {
34
38
  "type": "git",
package/src/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // route groups, view transitions, and middleware.
4
4
 
5
5
  import { signal, effect, computed, batch, h, ErrorBoundary } from 'what-core';
6
+ import { compilePath, matchRoute, parseQuery } from './match.js';
6
7
 
7
8
  // --- URL Sanitization ---
8
9
  // Rejects javascript:, data:, vbscript: protocols (case-insensitive, trimmed).
@@ -121,94 +122,12 @@ if (typeof window !== 'undefined') {
121
122
  }
122
123
 
123
124
  // --- Route Matching ---
125
+ // compilePath / matchRoute / parseQuery live in ./match.js (isomorphic, no DOM)
126
+ // and are imported above so the server adapter can reuse them.
124
127
 
125
- function compilePath(path) {
126
- // /users/:id -> regex + param names
127
- // /posts/* -> catch-all
128
- // /[slug] -> dynamic (file-based syntax)
129
- // (group) -> route group (ignored in URL)
130
-
131
- // Remove route groups from path (they don't affect URL matching)
132
- const normalized = path
133
- .replace(/\([\w-]+\)\//g, '') // Remove (group)/ prefixes
134
- .replace(/\[\.\.\.(\w+)\]/g, (_, name) => `*:${name}`) // Preserve catch-all name
135
- .replace(/\[(\w+)\]/g, ':$1'); // File-based [param] to :param
136
-
137
- const paramNames = [];
138
- let catchAll = null;
139
-
140
- const regexStr = normalized
141
- .split('/')
142
- .map(segment => {
143
- if (segment.startsWith('*:')) {
144
- catchAll = segment.slice(2);
145
- paramNames.push(catchAll);
146
- return '(.+)';
147
- }
148
- if (segment === '*') {
149
- catchAll = 'rest';
150
- paramNames.push('rest');
151
- return '(.+)';
152
- }
153
- if (segment.startsWith(':')) {
154
- paramNames.push(segment.slice(1));
155
- return '([^/]+)';
156
- }
157
- return segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
158
- })
159
- .join('/');
160
-
161
- const regex = new RegExp(`^${regexStr}$`);
162
- return { regex, paramNames, catchAll };
163
- }
164
-
165
- function matchRoute(path, routes) {
166
- // Filter out routes without a path (layout-only routes, etc.)
167
- const routable = routes.filter(r => r.path);
168
-
169
- // Sort routes by specificity (more specific first)
170
- const sorted = routable.sort((a, b) => {
171
- const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);
172
- const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);
173
- return aSpecific - bSpecific;
174
- });
175
-
176
- for (const route of sorted) {
177
- const { regex, paramNames } = compilePath(route.path);
178
- const match = path.match(regex);
179
- if (match) {
180
- const params = {};
181
- paramNames.forEach((name, i) => {
182
- params[name] = decodeURIComponent(match[i + 1]);
183
- });
184
- return { route, params };
185
- }
186
- }
187
- return null;
188
- }
189
-
190
- function parseQuery(search) {
191
- const params = {};
192
- if (!search) return params;
193
- const qs = search.startsWith('?') ? search.slice(1) : search;
194
- for (const pair of qs.split('&')) {
195
- const [key, val] = pair.split('=');
196
- if (!key) continue;
197
- const decodedKey = decodeURIComponent(key);
198
- const decodedVal = val ? decodeURIComponent(val) : '';
199
- if (decodedKey in params) {
200
- // Collect repeated keys into arrays
201
- if (Array.isArray(params[decodedKey])) {
202
- params[decodedKey].push(decodedVal);
203
- } else {
204
- params[decodedKey] = [params[decodedKey], decodedVal];
205
- }
206
- } else {
207
- params[decodedKey] = decodedVal;
208
- }
209
- }
210
- return params;
211
- }
128
+ // Re-export the matcher so `what-router` consumers (and the server adapter via
129
+ // `what-router/match`) can import it from the package root too.
130
+ export { compilePath, matchRoute, parseQuery } from './match.js';
212
131
 
213
132
  // --- Nested Layouts ---
214
133
 
package/src/match.js ADDED
@@ -0,0 +1,91 @@
1
+ // Isomorphic route matching — pure functions with no window/location/document
2
+ // dependencies, so they are safe to import on the server (deploy adapter) as
3
+ // well as in the client Router/FileRouter. Moved verbatim from index.js.
4
+
5
+ export function compilePath(path) {
6
+ // /users/:id -> regex + param names
7
+ // /posts/* -> catch-all
8
+ // /[slug] -> dynamic (file-based syntax)
9
+ // (group) -> route group (ignored in URL)
10
+
11
+ // Remove route groups from path (they don't affect URL matching)
12
+ const normalized = path
13
+ .replace(/\([\w-]+\)\//g, '') // Remove (group)/ prefixes
14
+ .replace(/\[\.\.\.(\w+)\]/g, (_, name) => `*:${name}`) // Preserve catch-all name
15
+ .replace(/\[(\w+)\]/g, ':$1'); // File-based [param] to :param
16
+
17
+ const paramNames = [];
18
+ let catchAll = null;
19
+
20
+ const regexStr = normalized
21
+ .split('/')
22
+ .map(segment => {
23
+ if (segment.startsWith('*:')) {
24
+ catchAll = segment.slice(2);
25
+ paramNames.push(catchAll);
26
+ return '(.+)';
27
+ }
28
+ if (segment === '*') {
29
+ catchAll = 'rest';
30
+ paramNames.push('rest');
31
+ return '(.+)';
32
+ }
33
+ if (segment.startsWith(':')) {
34
+ paramNames.push(segment.slice(1));
35
+ return '([^/]+)';
36
+ }
37
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
+ })
39
+ .join('/');
40
+
41
+ const regex = new RegExp(`^${regexStr}$`);
42
+ return { regex, paramNames, catchAll };
43
+ }
44
+
45
+ export function matchRoute(path, routes) {
46
+ // Filter out routes without a path (layout-only routes, etc.)
47
+ const routable = routes.filter(r => r.path);
48
+
49
+ // Sort routes by specificity (more specific first)
50
+ const sorted = routable.sort((a, b) => {
51
+ const aSpecific = (a.path.match(/:/g) || []).length + (a.path.includes('*') ? 100 : 0);
52
+ const bSpecific = (b.path.match(/:/g) || []).length + (b.path.includes('*') ? 100 : 0);
53
+ return aSpecific - bSpecific;
54
+ });
55
+
56
+ for (const route of sorted) {
57
+ const { regex, paramNames } = compilePath(route.path);
58
+ const match = path.match(regex);
59
+ if (match) {
60
+ const params = {};
61
+ paramNames.forEach((name, i) => {
62
+ params[name] = decodeURIComponent(match[i + 1]);
63
+ });
64
+ return { route, params };
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+
70
+ export function parseQuery(search) {
71
+ const params = {};
72
+ if (!search) return params;
73
+ const qs = search.startsWith('?') ? search.slice(1) : search;
74
+ for (const pair of qs.split('&')) {
75
+ const [key, val] = pair.split('=');
76
+ if (!key) continue;
77
+ const decodedKey = decodeURIComponent(key);
78
+ const decodedVal = val ? decodeURIComponent(val) : '';
79
+ if (decodedKey in params) {
80
+ // Collect repeated keys into arrays
81
+ if (Array.isArray(params[decodedKey])) {
82
+ params[decodedKey].push(decodedVal);
83
+ } else {
84
+ params[decodedKey] = [params[decodedKey], decodedVal];
85
+ }
86
+ } else {
87
+ params[decodedKey] = decodedVal;
88
+ }
89
+ }
90
+ return params;
91
+ }